InfiniteWP Client - Version 0.1.4

Version Description

Download this release

Release Info

Developer infinitewp
Plugin Icon 128x128 InfiniteWP Client
Version 0.1.4
Comparing to
See all releases

Version 0.1.4

api.php ADDED
@@ -0,0 +1,47 @@
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * api.php
11
+ *
12
+ * InfiniteWP addons api
13
+ *
14
+ * Copyright (c) 2011 Prelovac Media
15
+ * www.prelovac.com
16
+ **************************************************************/
17
+ if( !function_exists('iwp_mmb_add_action')) :
18
+ function iwp_mmb_add_action($action = false, $callback = false)
19
+ {
20
+ if (!$action || !$callback)
21
+ return false;
22
+
23
+ global $iwp_mmb_actions;
24
+ iwp_mmb_function_exists($callback);
25
+
26
+ if (isset($iwp_mmb_actions[$action]))
27
+ wp_die('Cannot redeclare InfiniteWP action "' . $action . '".');
28
+
29
+ $iwp_mmb_actions[$action] = $callback;
30
+ }
31
+ endif;
32
+
33
+ if( !function_exists('iwp_mmb_function_exists') ) :
34
+ function iwp_mmb_function_exists($callback)
35
+ {
36
+ global $iwp_core;
37
+ if (count($callback) === 2) {
38
+ if (!method_exists($callback[0], $callback[1]))
39
+ wp_die($iwp_core->iwp_dashboard_widget('Information', '', '<p>Class ' . get_class($callback[0]) . ' does not contain <b>"' . $callback[1] . '"</b> function</p>', '', '50%'));
40
+ } else {
41
+ if (!function_exists($callback))
42
+ wp_die($iwp_core->iwp_dashboard_widget('Information', '', '<p>Function <b>"' . $callback . '"</b> does not exists.</p>', '', '50%'));
43
+ }
44
+ }
45
+ endif;
46
+
47
+ ?>
backup.class.php ADDED
@@ -0,0 +1,2060 @@
1
+ <?php
2
+ /************************************************************
3
+ * This plugin was modified by Revmakx *
4
+ * Copyright (c) 2012 Revmakx *
5
+ * www.revmakx.com *
6
+ * *
7
+ ************************************************************/
8
+ /*************************************************************
9
+ *
10
+ * backup.class.php
11
+ *
12
+ * Manage Backups
13
+ *
14
+ *
15
+ * Copyright (c) 2011 Prelovac Media
16
+ * www.prelovac.com
17
+ **************************************************************/
18
+ define('IWP_BACKUP_DIR', WP_CONTENT_DIR . '/infinitewp/backups');
19
+ define('IWP_DB_DIR', IWP_BACKUP_DIR . '/iwp_db');
20
+
21
+ $zip_errors = array(
22
+ 'No error',
23
+ 'No error',
24
+ 'Unexpected end of zip file',
25
+ 'A generic error in the zipfile format was detected.',
26
+ 'zip was unable to allocate itself memory',
27
+ 'A severe error in the zipfile format was detected',
28
+ 'Entry too large to be split with zipsplit',
29
+ 'Invalid comment format',
30
+ 'zip -T failed or out of memory',
31
+ 'The user aborted zip prematurely',
32
+ 'zip encountered an error while using a temp file',
33
+ 'Read or seek error',
34
+ 'zip has nothing to do',
35
+ 'Missing or empty zip file',
36
+ 'Error writing to a file',
37
+ 'zip was unable to create a file to write to',
38
+ 'bad command line parameters',
39
+ 'no error',
40
+ 'zip could not open a specified file to read'
41
+ );
42
+ $unzip_errors = array(
43
+ 'No error',
44
+ 'One or more warning errors were encountered, but processing completed successfully anyway',
45
+ 'A generic error in the zipfile format was detected',
46
+ 'A severe error in the zipfile format was detected.',
47
+ 'unzip was unable to allocate itself memory.',
48
+ 'unzip was unable to allocate memory, or encountered an encryption error',
49
+ 'unzip was unable to allocate memory during decompression to disk',
50
+ 'unzip was unable allocate memory during in-memory decompression',
51
+ 'unused',
52
+ 'The specified zipfiles were not found',
53
+ 'Bad command line parameters',
54
+ 'No matching files were found',
55
+ 50 => 'The disk is (or was) full during extraction',
56
+ 51 => 'The end of the ZIP archive was encountered prematurely.',
57
+ 80 => 'The user aborted unzip prematurely.',
58
+ 81 => 'Testing or extraction of one or more files failed due to unsupported compression methods or unsupported decryption.',
59
+ 82 => 'No files were found due to bad decryption password(s)'
60
+ );
61
+
62
+
63
+ class IWP_MMB_Backup extends IWP_MMB_Core
64
+ {
65
+ var $site_name;
66
+ var $statuses;
67
+ var $tasks;
68
+ var $s3;
69
+ var $ftp;
70
+ var $dropbox;
71
+ function __construct()
72
+ {
73
+ parent::__construct();
74
+ $this->site_name = str_replace(array(
75
+ "_",
76
+ "/"
77
+ ), array(
78
+ "",
79
+ "-"
80
+ ), rtrim($this->remove_http(get_bloginfo('url')), "/"));
81
+ $this->statuses = array(
82
+ 'db_dump' => 1,
83
+ 'db_zip' => 2,
84
+ 'files_zip' => 3,
85
+ /*
86
+ //IWP Remove starts here
87
+ 's3' => 4,
88
+ 'dropbox' => 5,
89
+ 'ftp' => 6,
90
+ 'email' => 7,
91
+ //IWP Remove ends here
92
+ */
93
+ 'finished' => 100
94
+ );
95
+ $this->tasks = get_option('iwp_client_backup_tasks');
96
+ }
97
+
98
+ function get_backup_settings()
99
+ {
100
+ $backup_settings = get_option('iwp_client_backup_tasks');
101
+ if (!empty($backup_settings))
102
+ return $backup_settings;
103
+ else
104
+ return false;
105
+ }
106
+
107
+ function set_backup_task($params)
108
+ {
109
+ //$params => [$task_name, $args, $error]
110
+ if (!empty($params)) {
111
+ extract($params);
112
+
113
+ //$before = $this->get_backup_settings();
114
+ $before = $this->tasks;
115
+ if (!$before || empty($before))
116
+ $before = array();
117
+
118
+ if (isset($args['remove'])) {
119
+ unset($before[$task_name]);
120
+ $return = array(
121
+ 'removed' => true
122
+ );
123
+ } else {
124
+ /*
125
+ //IWP Remove starts here
126
+ if (is_array($params['account_info'])) { //only if sends from IWP Admin Panel first time(secure data)
127
+ $args['account_info'] = $account_info;
128
+ }
129
+ //IWP Remove ends here
130
+ */
131
+ $before[$task_name]['task_args'] = $args;
132
+ /*
133
+ //IWP Remove starts here
134
+ if (strlen($args['schedule']))
135
+ $before[$task_name]['task_args']['next'] = $this->schedule_next($args['type'], $args['schedule']);
136
+ //IWP Remove ends here
137
+ */
138
+ $return = $before[$task_name];
139
+ }
140
+
141
+ //Update with error
142
+ if ($error) {
143
+ if (is_array($error)) {
144
+ $before[$task_name]['task_results'][count($before[$task_name]['task_results']) - 1]['error'] = $error['error'];
145
+ } else {
146
+ $before[$task_name]['task_results'][count($before[$task_name]['task_results'])]['error'] = $error;
147
+ }
148
+ }
149
+
150
+ if ($time) { //set next result time before backup
151
+ if (is_array($before[$task_name]['task_results'])) {
152
+ $before[$task_name]['task_results'] = array_values($before[$task_name]['task_results']);
153
+ }
154
+ $before[$task_name]['task_results'][count($before[$task_name]['task_results'])]['time'] = $time;
155
+ }
156
+
157
+ $this->update_tasks($before);
158
+ //update_option('iwp_client_backup_tasks', $before);
159
+
160
+ if ($task_name == 'Backup Now') {
161
+ $result = $this->backup($args, $task_name);
162
+ $backup_settings = $this->tasks;
163
+
164
+ if (is_array($result) && array_key_exists('error', $result)) {
165
+ $return = $result;
166
+ } else {
167
+ $return = $backup_settings[$task_name];
168
+ }
169
+ }
170
+ return $return;
171
+ }
172
+ return false;
173
+ }
174
+
175
+ //Cron check
176
+ function check_backup_tasks()
177
+ {
178
+ $settings = $this->tasks;
179
+ if (is_array($settings) && !empty($settings)) {
180
+ foreach ($settings as $task_name => $setting) {
181
+
182
+ if ($setting['task_args']['next'] && $setting['task_args']['next'] < time()) {
183
+ //if ($setting['task_args']['next'] && $_GET['force_backup']) {
184
+ if ($setting['task_args']['url'] && $setting['task_args']['task_id'] && $setting['task_args']['site_key']) {
185
+ //Check orphan task
186
+ $check_data = array(
187
+ 'task_name' => $task_name,
188
+ 'task_id' => $setting['task_args']['task_id'],
189
+ 'site_key' => $setting['task_args']['site_key']
190
+ );
191
+
192
+ $check = $this->validate_task($check_data, $setting['task_args']['url']);
193
+
194
+ }
195
+
196
+ $update = array(
197
+ 'task_name' => $task_name,
198
+ 'args' => $settings[$task_name]['task_args']
199
+ );
200
+
201
+
202
+ if($check != 'paused'){
203
+ $update['time'] = time();
204
+ }
205
+
206
+ //Update task with next schedule
207
+ $this->set_backup_task($update);
208
+
209
+ if($check == 'paused'){
210
+ continue;
211
+ }
212
+
213
+
214
+ $result = $this->backup($setting['task_args'], $task_name);
215
+ $error = '';
216
+ if (is_array($result) && array_key_exists('error', $result)) {
217
+ $error = $result;
218
+ $this->set_backup_task(array(
219
+ 'task_name' => $task_name,
220
+ 'args' => $settings[$task_name]['task_args'],
221
+ 'error' => $error
222
+ ));
223
+ } else {
224
+ $error = '';
225
+ }
226
+ break; //Only one backup per cron
227
+ }
228
+ }
229
+ }
230
+
231
+ }
232
+
233
+ /*
234
+ //IWP Remove starts here
235
+ function task_now($task_name){
236
+
237
+ $settings = $this->tasks;
238
+ if(!array_key_exists($task_name,$settings)){
239
+ return array('error' => $task_name." does not exist.");
240
+ } else {
241
+ $setting = $settings[$task_name];
242
+ }
243
+
244
+ $this->set_backup_task(array(
245
+ 'task_name' => $task_name,
246
+ 'args' => $settings[$task_name]['task_args'],
247
+ 'time' => time()
248
+ ));
249
+
250
+ //Run backup
251
+ $result = $this->backup($setting['task_args'], $task_name);
252
+
253
+ //Check for error
254
+ if (is_array($result) && array_key_exists('error', $result)) {
255
+ $this->set_backup_task(array(
256
+ 'task_name' => $task_name,
257
+ 'args' => $settings[$task_name]['task_args'],
258
+ 'error' => $result['error']
259
+ ));
260
+ return $result;
261
+ } else {
262
+ return $this->get_backup_stats();
263
+ }
264
+
265
+ }
266
+ //IWP Remove ends here
267
+ */
268
+
269
+
270
+
271
+ /*
272
+ * If Task Name not set then it's manual backup
273
+ * Backup args:
274
+ * type -> db, full
275
+ * what -> daily, weekly, monthly
276
+ * account_info -> ftp, amazons3, dropbox
277
+ * exclude-> array of paths to exclude from backup
278
+ */
279
+
280
+ function backup($args, $task_name = false)
281
+ {
282
+ if (!$args || empty($args))
283
+ return false;
284
+
285
+ extract($args); //extract settings
286
+
287
+ //Try increase memory limit and execution time
288
+ @ini_set('memory_limit', '256M');
289
+ @set_time_limit(600); //ten minutes
290
+
291
+ //Remove old backup(s)
292
+ $this->remove_old_backups($task_name);
293
+
294
+ $new_file_path = IWP_BACKUP_DIR;
295
+
296
+ if (!file_exists($new_file_path)) {
297
+ if (!mkdir($new_file_path, 0755, true))
298
+ return array(
299
+ 'error' => 'Permission denied, make sure you have write permission to wp-content folder.'
300
+ );
301
+ }
302
+
303
+ @file_put_contents($new_file_path . '/index.php', ''); //safe
304
+
305
+ //Prepare .zip file name
306
+ $hash = md5(time());
307
+ $label = $type ? $type : 'manual';
308
+ $backup_file = $new_file_path . '/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
309
+ $backup_url = WP_CONTENT_URL . '/infinitewp/backups/' . $this->site_name . '_' . $label . '_' . $what . '_' . date('Y-m-d') . '_' . $hash . '.zip';
310
+
311
+ //Optimize tables?
312
+ if (isset($optimize_tables) && !empty($optimize_tables)) {
313
+ $this->optimize_tables();
314
+ }
315
+
316
+ //What to backup - db or full?
317
+ if (trim($what) == 'db') {
318
+ //Take database backup
319
+ $this->update_status($task_name, $this->statuses['db_dump']);
320
+ $db_result = $this->backup_db();
321
+ if ($db_result == false) {
322
+ return array(
323
+ 'error' => 'Failed to backup database.'
324
+ );
325
+ } else if (is_array($db_result) && isset($db_result['error'])) {
326
+ return array(
327
+ 'error' => $db_result['error']
328
+ );
329
+ } else {
330
+ $this->update_status($task_name, $this->statuses['db_dump'], true);
331
+ $this->update_status($task_name, $this->statuses['db_zip']);
332
+
333
+ $disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
334
+ $comp_level = $disable_comp ? '-0' : '-1';
335
+
336
+ chdir(IWP_BACKUP_DIR);
337
+ $zip = $this->get_zip();
338
+ $command = "$zip -q -r $comp_level $backup_file 'iwp_db'";
339
+ ob_start();
340
+ $result = $this->iwp_mmb_exec($command);
341
+ ob_get_clean();
342
+ if (!$result) { // fallback to pclzip
343
+ define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
344
+ require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
345
+ $archive = new PclZip($backup_file);
346
+ if ($disable_comp) {
347
+ $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
348
+ } else {
349
+ $result = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
350
+ }
351
+ @unlink($db_result);
352
+ @rmdir(IWP_DB_DIR);
353
+ if (!$result) {
354
+ return array(
355
+ 'error' => 'Failed to zip database (pclZip - ' . $archive->error_code . '): .' . $archive->error_string
356
+ );
357
+ }
358
+ }
359
+
360
+ @unlink($db_result);
361
+ @rmdir(IWP_DB_DIR);
362
+ if (!$result) {
363
+ return array(
364
+ 'error' => 'Failed to zip database.'
365
+ );
366
+ }
367
+ $this->update_status($task_name, $this->statuses['db_zip'], true);
368
+ }
369
+ } elseif (trim($what) == 'full') {
370
+ $content_backup = $this->backup_full($task_name, $backup_file, $exclude, $include);
371
+ if (is_array($content_backup) && array_key_exists('error', $content_backup)) {
372
+ return array(
373
+ 'error' => $content_backup['error']
374
+ );
375
+ }
376
+ }
377
+
378
+ //Update backup info
379
+ if ($task_name) {
380
+ //backup task (scheduled)
381
+ $backup_settings = $this->tasks;
382
+ $paths = array();
383
+ $size = ceil(filesize($backup_file) / 1024);
384
+
385
+ if ($size > 1000) {
386
+ $paths['size'] = ceil($size / 1024) . "MB";//Modified by IWP //Mb => MB
387
+ } else {
388
+ $paths['size'] = $size . 'KB';//Modified by IWP //Kb => KB
389
+ }
390
+
391
+ $paths['backup_name'] = $backup_settings[$task_name]['task_args']['backup_name'];
392
+
393
+ if ($task_name != 'Backup Now') {
394
+ if (!$backup_settings[$task_name]['task_args']['del_host_file']) {
395
+ $paths['server'] = array(
396
+ 'file_path' => $backup_file,
397
+ 'file_url' => $backup_url
398
+ );
399
+ }
400
+ } else {
401
+ $paths['server'] = array(
402
+ 'file_path' => $backup_file,
403
+ 'file_url' => $backup_url
404
+ );
405
+ }
406
+
407
+ /*
408
+ //IWP Remove starts here
409
+ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_ftp'])) {
410
+ $paths['ftp'] = basename($backup_url);
411
+ }
412
+
413
+ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_amazon_s3'])) {
414
+ $paths['amazons3'] = basename($backup_url);
415
+ }
416
+
417
+ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_dropbox'])) {
418
+ $paths['dropbox'] = basename($backup_url);
419
+ }
420
+
421
+ if (isset($backup_settings[$task_name]['task_args']['account_info']['iwp_email'])) {
422
+ $paths['email'] = basename($backup_url);
423
+ }
424
+ //IWP Remove ends here
425
+ */
426
+
427
+ $temp = $backup_settings[$task_name]['task_results'];
428
+ $temp = array_values($temp);
429
+ $paths['time'] = time();
430
+
431
+
432
+ if ($task_name != 'Backup Now') {
433
+ $paths['status'] = $temp[count($temp) - 1]['status'];
434
+ $temp[count($temp) - 1] = $paths;
435
+
436
+ } else {
437
+ $temp[count($temp)] = $paths;
438
+ }
439
+
440
+ $backup_settings[$task_name]['task_results'] = $temp;
441
+ $this->update_tasks($backup_settings);
442
+ //update_option('iwp_client_backup_tasks', $backup_settings);
443
+ }
444
+
445
+
446
+ //Additional: Email, ftp, amazon_s3, dropbox...
447
+
448
+ if ($task_name != 'Backup Now') {
449
+ /*
450
+ //IWP Remove starts here
451
+ if (isset($account_info['iwp_ftp']) && !empty($account_info['iwp_ftp'])) {
452
+ $this->update_status($task_name, $this->statuses['ftp']);
453
+ $account_info['iwp_ftp']['backup_file'] = $backup_file;
454
+ $ftp_result = $this->ftp_backup($account_info['iwp_ftp']);
455
+
456
+ if ($ftp_result !== true && $del_host_file) {
457
+ @unlink($backup_file);
458
+ }
459
+
460
+ if (is_array($ftp_result) && isset($ftp_result['error'])) {
461
+ return $ftp_result;
462
+ }
463
+ $this->wpdb_reconnect();
464
+ $this->update_status($task_name, $this->statuses['ftp'], true);
465
+ }
466
+
467
+ if (isset($account_info['iwp_amazon_s3']) && !empty($account_info['iwp_amazon_s3'])) {
468
+ $this->update_status($task_name, $this->statuses['s3']);
469
+ $account_info['iwp_amazon_s3']['backup_file'] = $backup_file;
470
+ $amazons3_result = $this->amazons3_backup($account_info['iwp_amazon_s3']);
471
+ if ($amazons3_result !== true && $del_host_file) {
472
+ @unlink($backup_file);
473
+ }
474
+ if (is_array($amazons3_result) && isset($amazons3_result['error'])) {
475
+ return $amazons3_result;
476
+ }
477
+ $this->wpdb_reconnect();
478
+ $this->update_status($task_name, $this->statuses['s3'], true);
479
+ }
480
+
481
+ if (isset($account_info['iwp_dropbox']) && !empty($account_info['iwp_dropbox'])) {
482
+ $this->update_status($task_name, $this->statuses['dropbox']);
483
+ $account_info['iwp_dropbox']['backup_file'] = $backup_file;
484
+ $dropbox_result = $this->dropbox_backup($account_info['iwp_dropbox']);
485
+ if ($dropbox_result !== true && $del_host_file) {
486
+ @unlink($backup_file);
487
+ }
488
+
489
+ if (is_array($dropbox_result) && isset($dropbox_result['error'])) {
490
+ return $dropbox_result;
491
+ }
492
+ $this->wpdb_reconnect();
493
+ $this->update_status($task_name, $this->statuses['dropbox'], true);
494
+ }
495
+
496
+ if (isset($account_info['iwp_email']) && !empty($account_info['iwp_email'])) {
497
+ $this->update_status($task_name, $this->statuses['email']);
498
+ $account_info['iwp_email']['task_name'] = $task_name;
499
+ $account_info['iwp_email']['file_path'] = $backup_file;
500
+
501
+ $email_result = $this->email_backup($account_info['iwp_email']);
502
+ if (is_array($email_result) && isset($email_result['error'])) {
503
+ return $email_result;
504
+ }
505
+ $this->update_status($task_name, $this->statuses['email'], true);
506
+ }
507
+ //IWP Remove ends here
508
+ */
509
+
510
+ if ($del_host_file) {
511
+ @unlink($backup_file);
512
+ }
513
+
514
+ } //end additional
515
+
516
+ //$this->update_status($task_name,$this->statuses['finished'],true);
517
+ return $backup_url; //Return url to backup file
518
+ }
519
+
520
+ function backup_full($task_name, $backup_file, $exclude = array(), $include = array())
521
+ {
522
+ global $zip_errors;
523
+ $sys = substr(PHP_OS, 0, 3);
524
+
525
+ $this->update_status($task_name, $this->statuses['db_dump']);
526
+ $db_result = $this->backup_db();
527
+
528
+ if ($db_result == false) {
529
+ return array(
530
+ 'error' => 'Failed to backup database.'
531
+ );
532
+ } else if (is_array($db_result) && isset($db_result['error'])) {
533
+ return array(
534
+ 'error' => $db_result['error']
535
+ );
536
+ }
537
+
538
+ $this->update_status($task_name, $this->statuses['db_dump'], true);
539
+ $this->update_status($task_name, $this->statuses['db_zip']);
540
+ $disable_comp = $this->tasks[$task_name]['task_args']['disable_comp'];
541
+ $comp_level = $disable_comp ? '-0' : '-1';
542
+
543
+ $zip = $this->get_zip();
544
+ //Add database file
545
+ chdir(IWP_BACKUP_DIR);
546
+ $command = "$zip -q -r $comp_level $backup_file 'iwp_db'";
547
+ ob_start();
548
+ $result = $this->iwp_mmb_exec($command);
549
+ ob_get_clean();
550
+
551
+
552
+ if (!$result) {
553
+ define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
554
+ require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
555
+ $archive = new PclZip($backup_file);
556
+
557
+ if ($disable_comp) {
558
+ $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR, PCLZIP_OPT_NO_COMPRESSION);
559
+ } else {
560
+ $result_db = $archive->add($db_result, PCLZIP_OPT_REMOVE_PATH, IWP_BACKUP_DIR);
561
+ }
562
+
563
+ @unlink($db_result);
564
+ @rmdir(IWP_DB_DIR);
565
+
566
+ if (!$result_db) {
567
+ return array(
568
+ 'error' => 'Failed to zip database. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
569
+ );
570
+ }
571
+ }
572
+
573
+ @unlink($db_result);
574
+ @rmdir(IWP_DB_DIR);
575
+
576
+ $this->update_status($task_name, $this->statuses['db_zip'], true);
577
+
578
+
579
+ //Always remove backup folders
580
+ $remove = array(
581
+ trim(basename(WP_CONTENT_DIR)) . "/infinitewp/backups",
582
+ trim(basename(WP_CONTENT_DIR)) . "/" . md5('iwp_mmb-client') . "/iwp_backups"
583
+ );
584
+
585
+ //Exclude paths
586
+ $exclude_data = "-x";
587
+
588
+ if (!empty($exclude)) {
589
+ foreach ($exclude as $data) {
590
+ if (is_dir(ABSPATH . $data)) {
591
+ if ($sys == 'WIN')
592
+ $exclude_data .= " $data/*.*";
593
+ else
594
+ $exclude_data .= " '$data/*'";
595
+ } else {
596
+ if ($sys == 'WIN')
597
+ $exclude_data .= " $data";
598
+ else
599
+ $exclude_data .= " '$data'";
600
+ }
601
+ }
602
+ }
603
+
604
+ foreach ($remove as $data) {
605
+ if ($sys == 'WIN')
606
+ $exclude_data .= " $data/*.*";
607
+ else
608
+ $exclude_data .= " '$data/*'";
609
+ }
610
+
611
+ //Include paths by default
612
+ $add = array(
613
+ trim(WPINC),
614
+ trim(basename(WP_CONTENT_DIR)),
615
+ "wp-admin"
616
+ );
617
+
618
+ $include_data = ". -i";
619
+ foreach ($add as $data) {
620
+ if ($sys == 'WIN')
621
+ $include_data .= " $data/*.*";
622
+ else
623
+ $include_data .= " '$data/*'";
624
+ }
625
+
626
+ //Additional includes?
627
+ if (!empty($include)) {
628
+ foreach ($include as $data) {
629
+ if ($data) {
630
+ if ($sys == 'WIN')
631
+ $include_data .= " $data/*.*";
632
+ else
633
+ $include_data .= " '$data/*'";
634
+ }
635
+ }
636
+ }
637
+
638
+ $this->update_status($task_name, $this->statuses['files_zip']);
639
+ chdir(ABSPATH);
640
+ ob_start();
641
+ $command = "$zip -q -j $comp_level $backup_file .* * $exclude_data";
642
+ $result_f = $this->iwp_mmb_exec($command, false, true);
643
+ if (!$result_f || $result_f == 18) { // disregard permissions error, file can't be accessed
644
+ $command = "$zip -q -r $comp_level $backup_file $include_data $exclude_data";
645
+ $result_d = $this->iwp_mmb_exec($command, false, true);
646
+ if ($result_d && $result_d != 18) {
647
+ @unlink($backup_file);
648
+ if ($result_d > 0 && $result_d < 18)
649
+ return array(
650
+ 'error' => 'Failed to archive files (' . $zip_errors[$result_d] . ') .'
651
+ );
652
+ else
653
+ return array(
654
+ 'error' => 'Failed to archive files.'
655
+ );
656
+ }
657
+ }
658
+ ob_get_clean();
659
+
660
+ if ($result_f && $result_f != 18) { //Try pclZip
661
+
662
+ if (!isset($archive)) {
663
+ define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
664
+ require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
665
+ $archive = new PclZip($backup_file);
666
+ }
667
+
668
+ //Include paths
669
+ $include_data = array();
670
+ if (!empty($include)) {
671
+ foreach ($include as $data) {
672
+ if ($data && file_exists(ABSPATH . $data))
673
+ $include_data[] = ABSPATH . $data . '/';
674
+ }
675
+ }
676
+
677
+ foreach ($add as $data) {
678
+ if (file_exists(ABSPATH . $data))
679
+ $include_data[] = ABSPATH . $data . '/';
680
+ }
681
+
682
+ //Include root files
683
+ if ($handle = opendir(ABSPATH)) {
684
+ while (false !== ($file = readdir($handle))) {
685
+ if ($file != "." && $file != ".." && !is_dir($file) && file_exists(ABSPATH . $file)) {
686
+ $include_data[] = ABSPATH . $file;
687
+ }
688
+ }
689
+ closedir($handle);
690
+ }
691
+
692
+ if ($disable_comp) {
693
+ $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_OPT_NO_COMPRESSION);
694
+ } else {
695
+ $result = $archive->add($include_data, PCLZIP_OPT_REMOVE_PATH, ABSPATH);
696
+ }
697
+ if (!$result) {
698
+ @unlink($backup_file);
699
+ return array(
700
+ 'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
701
+ );
702
+ }
703
+
704
+ //Now exclude paths
705
+ $exclude_data = array();
706
+ if (!empty($exclude)) {
707
+ foreach ($exclude as $data) {
708
+ if (is_dir(ABSPATH . $data))
709
+ $exclude_data[] = $data . '/';
710
+ else
711
+ $exclude_data[] = $data;
712
+ }
713
+ }
714
+
715
+ foreach ($remove as $rem) {
716
+ $exclude_data[] = $rem . '/';
717
+ }
718
+
719
+ $result_excl = $archive->delete(PCLZIP_OPT_BY_NAME, $exclude_data);
720
+ if (!$result_excl) {
721
+ @unlink($backup_file);
722
+ return array(
723
+ 'error' => 'Failed to zip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
724
+ );
725
+ }
726
+
727
+ }
728
+
729
+ //Reconnect
730
+ $this->wpdb_reconnect();
731
+
732
+ $this->update_status($task_name, $this->statuses['files_zip'], true);
733
+ return true;
734
+ }
735
+
736
+
737
+ function backup_db()
738
+ {
739
+ $db_folder = IWP_DB_DIR . '/';
740
+ if (!file_exists($db_folder)) {
741
+ if (!mkdir($db_folder, 0755, true))
742
+ return array(
743
+ 'error' => 'Error creating database backup folder (' . $db_folder . '). Make sure you have corrrect write permissions.'
744
+ );
745
+ }
746
+
747
+ $file = $db_folder . DB_NAME . '.sql';
748
+ $result = $this->backup_db_dump($file); // try mysqldump always then fallback to php dump
749
+ return $result;
750
+ }
751
+
752
+ function backup_db_dump($file)
753
+ {
754
+ global $wpdb;
755
+ $paths = $this->check_mysql_paths();
756
+ $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
757
+ $command = $brace . $paths['mysqldump'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" --add-drop-table --skip-lock-tables "' . DB_NAME . '" > ' . $brace . $file . $brace;
758
+ ob_start();
759
+ $result = $this->iwp_mmb_exec($command);
760
+ ob_get_clean();
761
+
762
+ if (!$result) { // Fallback to php
763
+ $result = $this->backup_db_php($file);
764
+ return $result;
765
+ }
766
+
767
+ if (filesize($file) == 0 || !is_file($file) || !$result) {
768
+ @unlink($file);
769
+ return false;
770
+ } else {
771
+ return $file;
772
+ }
773
+ }
774
+
775
+ function backup_db_php($file)
776
+ {
777
+ global $wpdb;
778
+ $tables = $wpdb->get_results('SHOW TABLES', ARRAY_N);
779
+ foreach ($tables as $table) {
780
+ //drop existing table
781
+ $dump_data = "DROP TABLE IF EXISTS $table[0];";
782
+ //create table
783
+ $create_table = $wpdb->get_row("SHOW CREATE TABLE $table[0]", ARRAY_N);
784
+ $dump_data .= "\n\n" . $create_table[1] . ";\n\n";
785
+
786
+ $count = $wpdb->get_var("SELECT count(*) FROM $table[0]");
787
+ if ($count > 100)
788
+ $count = ceil($count / 100);
789
+ else if ($count > 0)
790
+ $count = 1;
791
+
792
+ for ($i = 0; $i < $count; $i++) {
793
+ $low_limit = $i * 100;
794
+ $qry = "SELECT * FROM $table[0] LIMIT $low_limit, 100";
795
+ $rows = $wpdb->get_results($qry, ARRAY_A);
796
+ if (is_array($rows)) {
797
+ foreach ($rows as $row) {
798
+ //insert single row
799
+ $dump_data .= "INSERT INTO $table[0] VALUES(";
800
+ $num_values = count($row);
801
+ $j = 1;
802
+ foreach ($row as $value) {
803
+ $value = addslashes($value);
804
+ $value = preg_replace("/\n/Ui", "\\n", $value);
805
+ $num_values == $j ? $dump_data .= "'" . $value . "'" : $dump_data .= "'" . $value . "', ";
806
+ $j++;
807
+ unset($value);
808
+ }
809
+ $dump_data .= ");\n";
810
+ }
811
+ }
812
+ }
813
+ $dump_data .= "\n\n\n";
814
+
815
+ unset($rows);
816
+ file_put_contents($file, $dump_data, FILE_APPEND);
817
+ unset($dump_data);
818
+ }
819
+
820
+ if (filesize($file) == 0 || !is_file($file)) {
821
+ @unlink($file);
822
+ return array(
823
+ 'error' => 'Database backup failed. Try to enable MySQL dump on your server.'
824
+ );
825
+ }
826
+
827
+ return $file;
828
+
829
+ }
830
+
831
+ function restore($args)
832
+ {
833
+ global $wpdb;
834
+ if (empty($args)) {
835
+ return false;
836
+ }
837
+
838
+ extract($args);
839
+ @ini_set('memory_limit', '256M');
840
+ @set_time_limit(600);
841
+
842
+ $unlink_file = true; //Delete file after restore
843
+
844
+ //Detect source
845
+ if ($backup_url) {
846
+ //This is for clone (overwrite)
847
+ include_once ABSPATH . 'wp-admin/includes/file.php';
848
+ $backup_file = download_url($backup_url);
849
+ if (is_wp_error($backup_file)) {
850
+ return array(
851
+ 'error' => 'Unable to download backup file ('.$backup_file->get_error_message().')'
852
+ );
853
+ }
854
+ $what = 'full';
855
+ } else {
856
+ $tasks = $this->tasks;
857
+ $task = $tasks[$task_name];
858
+ if (isset($task['task_results'][$result_id]['server'])) {
859
+ $backup_file = $task['task_results'][$result_id]['server']['file_path'];
860
+ $unlink_file = false; //Don't delete file if stored on server
861
+ } /*
862
+ //IWP Remove starts here
863
+ elseif (isset($task['task_results'][$result_id]['ftp'])) {
864
+ $ftp_file = $task['task_results'][$result_id]['ftp'];
865
+ $args = $task['task_args']['account_info']['iwp_ftp'];
866
+ $args['backup_file'] = $ftp_file;
867
+ $backup_file = $this->get_ftp_backup($args);
868
+ if ($backup_file == false) {
869
+ return array(
870
+ 'error' => 'Failed to download file from FTP.'
871
+ );
872
+ }
873
+ } elseif (isset($task['task_results'][$result_id]['amazons3'])) {
874
+ $amazons3_file = $task['task_results'][$result_id]['amazons3'];
875
+ $args = $task['task_args']['account_info']['iwp_amazon_s3'];
876
+ $args['backup_file'] = $ftp_file;
877
+ $backup_file = $this->get_amazons3_backup($args);
878
+ if ($backup_file == false) {
879
+ return array(
880
+ 'error' => 'Failed to download file from Amazon S3.'
881
+ );
882
+ }
883
+ }
884
+ //IWP Remove ends here
885
+ */
886
+
887
+ $what = $tasks[$task_name]['task_args']['what'];
888
+ }
889
+
890
+ if ($backup_file && file_exists($backup_file)) {
891
+ if ($overwrite) {
892
+ //Keep old db credentials before overwrite
893
+ if (!copy(ABSPATH . 'wp-config.php', ABSPATH . 'iwp-temp-wp-config.php')) {
894
+ @unlink($backup_file);
895
+ return array(
896
+ 'error' => 'Error creating wp-config. Please check your write permissions.'
897
+ );
898
+ }
899
+
900
+ $db_host = DB_HOST;
901
+ $db_user = DB_USER;
902
+ $db_password = DB_PASSWORD;
903
+ $home = rtrim(get_option('home'), "/");
904
+ $site_url = get_option('site_url');
905
+
906
+ $clone_options = array();
907
+ if (trim($clone_from_url) || trim($iwp_clone)) {
908
+
909
+ $clone_options['iwp_client_nossl_key'] = get_option('iwp_client_nossl_key');
910
+ $clone_options['iwp_client_public_key'] = get_option('iwp_client_public_key');
911
+ $clone_options['iwp_client_action_message_id'] = get_option('iwp_client_action_message_id');
912
+
913
+ }
914
+
915
+ $clone_options['iwp_client_backup_tasks'] = serialize(get_option('iwp_client_backup_tasks'));
916
+ $clone_options['iwp_client_notifications'] = serialize(get_option('iwp_client_notifications'));
917
+ $clone_options['iwp_client_pageview_alerts'] = serialize(get_option('iwp_client_pageview_alerts'));
918
+
919
+
920
+ } else {
921
+ $restore_options = array();
922
+ $restore_options['iwp_client_notifications'] = get_option('iwp_client_notifications');
923
+ $restore_options['iwp_client_pageview_alerts'] = get_option('iwp_client_pageview_alerts');
924
+ $restore_options['iwp_client_user_hit_count'] = get_option('iwp_client_user_hit_count');
925
+ }
926
+
927
+
928
+ chdir(ABSPATH);
929
+ $unzip = $this->get_unzip();
930
+ $command = "$unzip -o $backup_file";
931
+ ob_start();
932
+ $result = $this->iwp_mmb_exec($command);
933
+ ob_get_clean();
934
+
935
+ if (!$result) { //fallback to pclzip
936
+ define('PCLZIP_TEMPORARY_DIR', IWP_BACKUP_DIR . '/');
937
+ require_once ABSPATH . '/wp-admin/includes/class-pclzip.php';
938
+ $archive = new PclZip($backup_file);
939
+ $result = $archive->extract(PCLZIP_OPT_PATH, ABSPATH, PCLZIP_OPT_REPLACE_NEWER);
940
+ }
941
+
942
+ if ($unlink_file) {
943
+ @unlink($backup_file);
944
+ }
945
+
946
+ if (!$result) {
947
+ return array(
948
+ 'error' => 'Failed to unzip files. pclZip error (' . $archive->error_code . '): .' . $archive->error_string
949
+ );
950
+ }
951
+
952
+ $db_result = $this->restore_db();
953
+
954
+ if (!$db_result) {
955
+ return array(
956
+ 'error' => 'Error restoring database.'
957
+ );
958
+ } else if(is_array($db_result) && isset($db_result['error'])){
959
+ return array(
960
+ 'error' => $db_result['error']
961
+ );
962
+ }
963
+
964
+ } else {
965
+ return array(
966
+ 'error' => 'Error restoring. Cannot find backup file.'
967
+ );
968
+ }
969
+
970
+ //Replace options and content urls
971
+ if ($overwrite) {
972
+ //Get New Table prefix
973
+ $new_table_prefix = trim($this->get_table_prefix());
974
+ //Retrieve old wp_config
975
+ @unlink(ABSPATH . 'wp-config.php');
976
+ //Replace table prefix
977
+ $lines = file(ABSPATH . 'iwp-temp-wp-config.php');
978
+
979
+ foreach ($lines as $line) {
980
+ if (strstr($line, '$table_prefix')) {
981
+ $line = '$table_prefix = "' . $new_table_prefix . '";' . PHP_EOL;
982
+ }
983
+ file_put_contents(ABSPATH . 'wp-config.php', $line, FILE_APPEND);
984
+ }
985
+
986
+ @unlink(ABSPATH . 'iwp-temp-wp-config.php');
987
+
988
+ //Replace options
989
+ $query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = 'home'";
990
+ $old = $wpdb->get_var($wpdb->prepare($query));
991
+ $old = rtrim($old, "/");
992
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'home'";
993
+ $wpdb->query($wpdb->prepare($query));
994
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$home' WHERE option_name = 'siteurl'";
995
+ $wpdb->query($wpdb->prepare($query));
996
+ //Replace content urls
997
+ $query = "UPDATE " . $new_table_prefix . "posts SET post_content = REPLACE (post_content, '$old','$home') WHERE post_content REGEXP 'src=\"(.*)$old(.*)\"' OR post_content REGEXP 'href=\"(.*)$old(.*)\"'";
998
+ $wpdb->query($wpdb->prepare($query));
999
+
1000
+ if (trim($new_password)) {
1001
+ $new_password = wp_hash_password($new_password);
1002
+ }
1003
+ if (!trim($clone_from_url) && !trim($iwp_clone)) {
1004
+ if ($new_user && $new_password) {
1005
+ $query = "UPDATE " . $new_table_prefix . "users SET user_login = '$new_user', user_pass = '$new_password' WHERE user_login = '$old_user'";
1006
+ $wpdb->query($wpdb->prepare($query));
1007
+ }
1008
+ } else {
1009
+ if ($clone_from_url) {
1010
+ if ($new_user && $new_password) {
1011
+ $query = "UPDATE " . $new_table_prefix . "users SET user_pass = '$new_password' WHERE user_login = '$new_user'";
1012
+ $wpdb->query($wpdb->prepare($query));
1013
+ }
1014
+ }
1015
+
1016
+ if ($iwp_clone) {
1017
+ if ($admin_email) {
1018
+ //Clean Install
1019
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$admin_email' WHERE option_name = 'admin_email'";
1020
+ $wpdb->query($wpdb->prepare($query));
1021
+ $query = "SELECT * FROM " . $new_table_prefix . "users LIMIT 1";
1022
+ $temp_user = $wpdb->get_row($query);
1023
+ if (!empty($temp_user)) {
1024
+ $query = "UPDATE " . $new_table_prefix . "users SET user_email='$admin_email', user_login = '$new_user', user_pass = '$new_password' WHERE user_login = '$temp_user->user_login'";
1025
+ $wpdb->query($wpdb->prepare($query));
1026
+ }
1027
+
1028
+ }
1029
+ }
1030
+ }
1031
+
1032
+ if (is_array($clone_options) && !empty($clone_options)) {
1033
+ foreach ($clone_options as $key => $option) {
1034
+ if (!empty($key)) {
1035
+ $query = "SELECT option_value FROM " . $new_table_prefix . "options WHERE option_name = '$key'";
1036
+ $res = $wpdb->get_var($query);
1037
+ if ($res == false) {
1038
+ $query = "INSERT INTO " . $new_table_prefix . "options (option_value,option_name) VALUES('$option','$key')";
1039
+ $wpdb->query($wpdb->prepare($query));
1040
+ } else {
1041
+ $query = "UPDATE " . $new_table_prefix . "options SET option_value = '$option' WHERE option_name = '$key'";
1042
+ $wpdb->query($wpdb->prepare($query));
1043
+ }
1044
+ }
1045
+ }
1046
+ }
1047
+
1048
+ //Remove hit count
1049
+ $query = "DELETE FROM " . $new_table_prefix . "options WHERE option_name = 'iwp_client_user_hit_count'";
1050
+ $wpdb->query($wpdb->prepare($query));
1051
+
1052
+ //Check for .htaccess permalinks update
1053
+ $this->replace_htaccess($home);
1054
+ } else {
1055
+
1056
+ //restore client options
1057
+ if (is_array($restore_options) && !empty($restore_options)) {
1058
+ foreach ($restore_options as $key => $option) {
1059
+ update_option($key,$option);
1060
+ }
1061
+ }
1062
+
1063
+ }
1064
+
1065
+
1066
+
1067
+
1068
+ return true;
1069
+ }
1070
+
1071
+ function restore_db()
1072
+ {
1073
+ global $wpdb;
1074
+ $paths = $this->check_mysql_paths();
1075
+ $file_path = ABSPATH . 'iwp_db';
1076
+ @chmod($file_path,0755);
1077
+ $file_name = glob($file_path . '/*.sql');
1078
+ $file_name = $file_name[0];
1079
+
1080
+ if(!$file_name){
1081
+ return array('error' => 'Cannot access database file.');
1082
+ }
1083
+
1084
+ $brace = (substr(PHP_OS, 0, 3) == 'WIN') ? '"' : '';
1085
+ $command = $brace . $paths['mysql'] . $brace . ' --host="' . DB_HOST . '" --user="' . DB_USER . '" --password="' . DB_PASSWORD . '" ' . DB_NAME . ' < ' . $brace . $file_name . $brace;
1086
+
1087
+ ob_start();
1088
+ $result = $this->iwp_mmb_exec($command);
1089
+ ob_get_clean();
1090
+ if (!$result) {
1091
+ //try php
1092
+ $this->restore_db_php($file_name);
1093
+ }
1094
+
1095
+
1096
+ @unlink($file_name);
1097
+ return true;
1098
+ }
1099
+
1100
+ function restore_db_php($file_name)
1101
+ {
1102
+ global $wpdb;
1103
+ $current_query = '';
1104
+ // Read in entire file
1105
+ $lines = file($file_name);
1106
+ // Loop through each line
1107
+ foreach ($lines as $line) {
1108
+ // Skip it if it's a comment
1109
+ if (substr($line, 0, 2) == '--' || $line == '')
1110
+ continue;
1111
+
1112
+ // Add this line to the current query
1113
+ $current_query .= $line;
1114
+ // If it has a semicolon at the end, it's the end of the query
1115
+ if (substr(trim($line), -1, 1) == ';') {
1116
+ // Perform the query
1117
+ $result = $wpdb->query($current_query);
1118
+ if ($result === false)
1119
+ return false;
1120
+ // Reset temp variable to empty
1121
+ $current_query = '';
1122
+ }
1123
+ }
1124
+
1125
+ @unlink($file_name);
1126
+ return true;
1127
+ }
1128
+
1129
+ function get_table_prefix()
1130
+ {
1131
+ $lines = file(ABSPATH . 'wp-config.php');
1132
+ foreach ($lines as $line) {
1133
+ if (strstr($line, '$table_prefix')) {
1134
+ $pattern = "/(\'|\")[^(\'|\")]*/";
1135
+ preg_match($pattern, $line, $matches);
1136
+ $prefix = substr($matches[0], 1);
1137
+ return $prefix;
1138
+ break;
1139
+ }
1140
+ }
1141
+ return 'wp_'; //default
1142
+ }
1143
+
1144
+ function optimize_tables()
1145
+ {
1146
+ global $wpdb;
1147
+ $query = 'SHOW TABLE STATUS FROM ' . DB_NAME;
1148
+ $tables = $wpdb->get_results($wpdb->prepare($query), ARRAY_A);
1149
+ foreach ($tables as $table) {
1150
+ if (in_array($table['Engine'], array(
1151
+ 'MyISAM',
1152
+ 'ISAM',
1153
+ 'HEAP',
1154
+ 'MEMORY',
1155
+ 'ARCHIVE'
1156
+ )))
1157
+ $table_string .= $table['Name'] . ",";
1158
+ elseif ($table['Engine'] == 'InnoDB') {
1159
+ $optimize = $wpdb->query("ALTER TABLE {$table['Name']} ENGINE=InnoDB");
1160
+ }
1161
+ }
1162
+
1163
+ $table_string = rtrim($table_string);
1164
+ $optimize = $wpdb->query("OPTIMIZE TABLE $table_string");
1165
+
1166
+ return $optimize ? true : false;
1167
+ }
1168
+
1169
+ ### Function: Auto Detect MYSQL and MYSQL Dump Paths
1170
+ function check_mysql_paths()
1171
+ {
1172
+ global $wpdb;
1173
+ $paths = array(
1174
+ 'mysql' => '',
1175
+ 'mysqldump' => ''
1176
+ );
1177
+ if (substr(PHP_OS, 0, 3) == 'WIN') {
1178
+ $mysql_install = $wpdb->get_row("SHOW VARIABLES LIKE 'basedir'");
1179
+ if ($mysql_install) {
1180
+ $install_path = str_replace('\\', '/', $mysql_install->Value);
1181
+ $paths['mysql'] = $install_path . 'bin/mysql.exe';
1182
+ $paths['mysqldump'] = $install_path . 'bin/mysqldump.exe';
1183
+ } else {
1184
+ $paths['mysql'] = 'mysql.exe';
1185
+ $paths['mysqldump'] = 'mysqldump.exe';
1186
+ }
1187
+ } else {
1188
+ $paths['mysql'] = $this->iwp_mmb_exec('which mysql', true);
1189
+ if (empty($paths['mysql']))
1190
+ $paths['mysql'] = 'mysql'; // try anyway
1191
+
1192
+ $paths['mysqldump'] = $this->iwp_mmb_exec('which mysqldump', true);
1193
+ if (empty($paths['mysqldump']))
1194
+ $paths['mysqldump'] = 'mysqldump'; // try anyway
1195
+
1196
+ }
1197
+
1198
+
1199
+ return $paths;
1200
+ }
1201
+
1202
+ //Check if exec, system, passthru functions exist
1203
+ function check_sys()
1204
+ {
1205
+ if ($this->iwp_mmb_function_exists('exec'))
1206
+ return 'exec';
1207
+
1208
+ if ($this->iwp_mmb_function_exists('system'))
1209
+ return 'system';
1210
+
1211
+ if ($this->iwp_mmb_function_exists('passhtru'))
1212
+ return 'passthru';
1213
+
1214
+ return false;
1215
+
1216
+ }
1217
+
1218
+ function iwp_mmb_exec($command, $string = false, $rawreturn = false)
1219
+ {
1220
+ if ($command == '')
1221
+ return false;
1222
+
1223
+ if ($this->iwp_mmb_function_exists('exec')) {
1224
+ $log = @exec($command, $output, $return);
1225
+
1226
+ if ($string)
1227
+ return $log;
1228
+ if ($rawreturn)
1229
+ return $return;
1230
+
1231
+ return $return ? false : true;
1232
+ } elseif ($this->iwp_mmb_function_exists('system')) {
1233
+ $log = @system($command, $return);
1234
+
1235
+ if ($string)
1236
+ return $log;
1237
+
1238
+ if ($rawreturn)
1239
+ return $return;
1240
+
1241
+ return $return ? false : true;
1242
+ } elseif ($this->iwp_mmb_function_exists('passthru') && !$string) {
1243
+ $log = passthru($command, $return);
1244
+
1245
+ if ($rawreturn)
1246
+ return $return;
1247
+
1248
+ return $return ? false : true;
1249
+ }
1250
+
1251
+ if ($rawreturn)
1252
+ return -1;
1253
+
1254
+ return false;
1255
+ }
1256
+
1257
+ function get_zip()
1258
+ {
1259
+ $zip = $this->iwp_mmb_exec('which zip', true);
1260
+ if (!$zip)
1261
+ $zip = "zip";
1262
+ return $zip;
1263
+ }
1264
+
1265
+ function get_unzip()
1266
+ {
1267
+ $unzip = $this->iwp_mmb_exec('which unzip', true);
1268
+ if (!$unzip)
1269
+ $unzip = "unzip";
1270
+ return $unzip;
1271
+ }
1272
+
1273
+ function check_backup_compat()
1274
+ {
1275
+ $reqs = array();
1276
+ if (strpos($_SERVER['DOCUMENT_ROOT'], '/') === 0) {
1277
+ $reqs['Server OS']['status'] = 'Linux (or compatible)';
1278
+ $reqs['Server OS']['pass'] = true;
1279
+ } else {
1280
+ $reqs['Server OS']['status'] = 'Windows';
1281
+ $reqs['Server OS']['pass'] = true;
1282
+ $pass = false;
1283
+ }
1284
+ $reqs['PHP Version']['status'] = phpversion();
1285
+ if ((float) phpversion() >= 5.1) {
1286
+ $reqs['PHP Version']['pass'] = true;
1287
+ } else {
1288
+ $reqs['PHP Version']['pass'] = false;
1289
+ $pass = false;
1290
+ }
1291
+
1292
+
1293
+ if (is_writable(WP_CONTENT_DIR)) {
1294
+ $reqs['Backup Folder']['status'] = "writable";
1295
+ $reqs['Backup Folder']['pass'] = true;
1296
+ } else {
1297
+ $reqs['Backup Folder']['status'] = "not writable";
1298
+ $reqs['Backup Folder']['pass'] = false;
1299
+ }
1300
+
1301
+
1302
+ $file_path = IWP_BACKUP_DIR;
1303
+ $reqs['Backup Folder']['status'] .= ' (' . $file_path . ')';
1304
+
1305
+ if ($func = $this->check_sys()) {
1306
+ $reqs['Execute Function']['status'] = $func;
1307
+ $reqs['Execute Function']['pass'] = true;
1308
+ } else {
1309
+ $reqs['Execute Function']['status'] = "not found";
1310
+ $reqs['Execute Function']['info'] = "(will try PHP replacement)";
1311
+ $reqs['Execute Function']['pass'] = false;
1312
+ }
1313
+ $reqs['Zip']['status'] = $this->get_zip();
1314
+
1315
+ $reqs['Zip']['pass'] = true;
1316
+
1317
+
1318
+
1319
+ $reqs['Unzip']['status'] = $this->get_unzip();
1320
+
1321
+ $reqs['Unzip']['pass'] = true;
1322
+
1323
+ $paths = $this->check_mysql_paths();
1324
+
1325
+ if (!empty($paths['mysqldump'])) {
1326
+ $reqs['MySQL Dump']['status'] = $paths['mysqldump'];
1327
+ $reqs['MySQL Dump']['pass'] = true;
1328
+ } else {
1329
+ $reqs['MySQL Dump']['status'] = "not found";
1330
+ $reqs['MySQL Dump']['info'] = "(will try PHP replacement)";
1331
+ $reqs['MySQL Dump']['pass'] = false;
1332
+ }
1333
+
1334
+ $exec_time = ini_get('max_execution_time');
1335
+ $reqs['Execution time']['status'] = $exec_time ? $exec_time . "s" : 'unknown';
1336
+ $reqs['Execution time']['pass'] = true;
1337
+
1338
+ $mem_limit = ini_get('memory_limit');
1339
+ $reqs['Memory limit']['status'] = $mem_limit ? $mem_limit : 'unknown';
1340
+ $reqs['Memory limit']['pass'] = true;
1341
+
1342
+
1343
+ return $reqs;
1344
+ }
1345
+
1346
+ /*
1347
+ //IWP Remove starts here
1348
+ function email_backup($args)
1349
+ {
1350
+ $email = $args['email'];
1351
+
1352
+ if (!is_email($email)) {
1353
+ return array(
1354
+ 'error' => 'Your email (' . $email . ') is not correct'
1355
+ );
1356
+ }
1357
+ $backup_file = $args['file_path'];
1358
+ $task_name = isset($args['task_name']) ? $args['task_name'] : '';
1359
+ if (file_exists($backup_file) && $email) {
1360
+ $attachments = array(
1361
+ $backup_file
1362
+ );
1363
+ $headers = 'From: InfiniteWP <no-reply@infinitewp.com>' . "\r\n";
1364
+ $subject = "InfiniteWP - " . $task_name . " - " . $this->site_name;
1365
+ ob_start();
1366
+ $result = wp_mail($email, $subject, $subject, $headers, $attachments);
1367
+ ob_end_clean();
1368
+
1369
+ }
1370
+
1371
+ if (!$result) {
1372
+ return array(
1373
+ 'error' => 'Email not sent. Maybe your backup is too big for email or email server is not available on your website.'
1374
+ );
1375
+ }
1376
+ return true;
1377
+
1378
+ }
1379
+
1380
+ function ftp_backup($args)
1381
+ {
1382
+ extract($args);
1383
+ //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder, $ftp_site_folder
1384
+ $port = $ftp_port ? $ftp_port : 21; //default port is 21
1385
+ if ($ftp_ssl) {
1386
+ if (function_exists('ftp_ssl_connect')) {
1387
+ $conn_id = ftp_ssl_connect($ftp_hostname,$port);
1388
+ } else {
1389
+ return array(
1390
+ 'error' => 'Your server doesn\'t support SFTP',
1391
+ 'partial' => 1
1392
+ );
1393
+ }
1394
+ } else {
1395
+ if (function_exists('ftp_connect')) {
1396
+ $conn_id = ftp_connect($ftp_hostname,$port);
1397
+ if ($conn_id === false) {
1398
+ return array(
1399
+ 'error' => 'Failed to connect to ' . $ftp_hostname,
1400
+ 'partial' => 1
1401
+ );
1402
+ }
1403
+ } else {
1404
+ return array(
1405
+ 'error' => 'Your server doesn\'t support FTP',
1406
+ 'partial' => 1
1407
+ );
1408
+ }
1409
+ }
1410
+ $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
1411
+ if ($login === false) {
1412
+ return array(
1413
+ 'error' => 'FTP login failed for ' . $ftp_username . ', ' . $ftp_password,
1414
+ 'partial' => 1
1415
+ );
1416
+ }
1417
+
1418
+ if($ftp_passive){
1419
+ @ftp_pasv($conn_id,true);
1420
+ }
1421
+
1422
+ @ftp_mkdir($conn_id, $ftp_remote_folder);
1423
+ if ($ftp_site_folder) {
1424
+ $ftp_remote_folder .= '/' . $this->site_name;
1425
+ }
1426
+ @ftp_mkdir($conn_id, $ftp_remote_folder);
1427
+
1428
+ $upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_BINARY);
1429
+
1430
+ if ($upload === false) { //Try ascii
1431
+ $upload = @ftp_put($conn_id, $ftp_remote_folder . '/' . basename($backup_file), $backup_file, FTP_ASCII);
1432
+ }
1433
+ ftp_close($conn_id);
1434
+
1435
+ if ($upload === false) {
1436
+ return array(
1437
+ 'error' => 'Failed to upload file to FTP. Please check your specified path.',
1438
+ 'partial' => 1
1439
+ );
1440
+ }
1441
+
1442
+ return true;
1443
+ }
1444
+
1445
+ function remove_ftp_backup($args)
1446
+ {
1447
+ extract($args);
1448
+ //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
1449
+ $port = $ftp_port ? $ftp_port : 21; //default port is 21
1450
+ if ($ftp_ssl && function_exists('ftp_ssl_connect')) {
1451
+ $conn_id = ftp_ssl_connect($ftp_hostname,$port);
1452
+ } else if (function_exists('ftp_connect')) {
1453
+ $conn_id = ftp_connect($ftp_hostname,$port);
1454
+ }
1455
+
1456
+ if ($conn_id) {
1457
+ $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
1458
+ if ($ftp_site_folder)
1459
+ $ftp_remote_folder .= '/' . $this->site_name;
1460
+
1461
+ if($ftp_passive){
1462
+ @ftp_pasv($conn_id,true);
1463
+ }
1464
+
1465
+ $delete = ftp_delete($conn_id, $ftp_remote_folder . '/' . $backup_file);
1466
+
1467
+ ftp_close($conn_id);
1468
+ }
1469
+
1470
+ }
1471
+
1472
+ function get_ftp_backup($args)
1473
+ {
1474
+ extract($args);
1475
+ //Args: $ftp_username, $ftp_password, $ftp_hostname, $backup_file, $ftp_remote_folder
1476
+ $port = $ftp_port ? $ftp_port : 21; //default port is 21
1477
+ if ($ftp_ssl && function_exists('ftp_ssl_connect')) {
1478
+ $conn_id = ftp_ssl_connect($ftp_hostname,$port);
1479
+
1480
+ } else if (function_exists('ftp_connect')) {
1481
+ $conn_id = ftp_connect($ftp_hostname,$port);
1482
+ if ($conn_id === false) {
1483
+ return false;
1484
+ }
1485
+ }
1486
+ $login = @ftp_login($conn_id, $ftp_username, $ftp_password);
1487
+ if ($login === false) {
1488
+ return false;
1489
+ } else {
1490
+ }
1491
+
1492
+ if ($ftp_site_folder)
1493
+ $ftp_remote_folder .= '/' . $this->site_name;
1494
+
1495
+ if($ftp_passive){
1496
+ @ftp_pasv($conn_id,true);
1497
+ }
1498
+
1499
+ $temp = ABSPATH . 'iwp_temp_backup.zip';
1500
+ $get = ftp_get($conn_id, $temp, $ftp_remote_folder . '/' . $backup_file, FTP_BINARY);
1501
+ if ($get === false) {
1502
+ return false;
1503
+ } else {
1504
+ }
1505
+ ftp_close($conn_id);
1506
+
1507
+ return $temp;
1508
+ }
1509
+
1510
+ function dropbox_backup($args)
1511
+ {
1512
+ require_once('lib/dropbox.php');
1513
+ extract($args);
1514
+
1515
+ //$email, $password, $backup_file, $destination, $dropbox_site_folder
1516
+
1517
+ $size = ceil(filesize($backup_file) / 1024);
1518
+ if ($size > 300000) {
1519
+ return array(
1520
+ 'error' => 'Cannot upload file to Dropbox. Dropbox has upload limit of 300Mb per file.',
1521
+ 'partial' => 1
1522
+ );
1523
+ }
1524
+
1525
+ if ($dropbox_site_folder == true)
1526
+ $dropbox_destination .= '/' . $this->site_name;
1527
+
1528
+ try {
1529
+ $uploader = new DropboxUploader($dropbox_username, $dropbox_password);
1530
+ $uploader->upload($backup_file, $dropbox_destination);
1531
+ }
1532
+ catch (Exception $e) {
1533
+ return array(
1534
+ 'error' => $e->getMessage(),
1535
+ 'partial' => 1
1536
+ );
1537
+ }
1538
+
1539
+ return true;
1540
+
1541
+ }
1542
+
1543
+ function amazons3_backup($args)
1544
+ {
1545
+ if ($this->iwp_mmb_function_exists('curl_init')) {
1546
+ require_once('lib/s3.php');
1547
+ extract($args);
1548
+
1549
+ if ($as3_site_folder == true)
1550
+ $as3_directory .= '/' . $this->site_name;
1551
+
1552
+ $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1553
+
1554
+ $s3 = new S3(trim($as3_access_key), trim(str_replace(' ', '+', $as3_secure_key)), false, $endpoint);
1555
+
1556
+ $s3->putBucket($as3_bucket, S3::ACL_PUBLIC_READ);
1557
+
1558
+ if ($s3->putObjectFile($backup_file, $as3_bucket, $as3_directory . '/' . basename($backup_file), S3::ACL_PRIVATE)) {
1559
+ return true;
1560
+ } else {
1561
+ return array(
1562
+ 'error' => 'Failed to upload to Amazon S3. Please check your details and set upload/delete permissions on your bucket.',
1563
+ 'partial' => 1
1564
+ );
1565
+ }
1566
+ } else {
1567
+ return array(
1568
+ 'error' => 'You cannot use Amazon S3 on your server. Please enable curl first.',
1569
+ 'partial' => 1
1570
+ );
1571
+ }
1572
+ }
1573
+
1574
+ function remove_amazons3_backup($args)
1575
+ {
1576
+ require_once('lib/s3.php');
1577
+ extract($args);
1578
+ if ($as3_site_folder == true)
1579
+ $as3_directory .= '/' . $this->site_name;
1580
+ $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1581
+ $s3 = new S3($as3_access_key, str_replace(' ', '+', $as3_secure_key), false, $endpoint);
1582
+ $s3->deleteObject($as3_bucket, $as3_directory . '/' . $backup_file);
1583
+ }
1584
+
1585
+ function get_amazons3_backup($args)
1586
+ {
1587
+ require_once('lib/s3.php');
1588
+ extract($args);
1589
+ $endpoint = isset($as3_bucket_region) ? $as3_bucket_region : 's3.amazonaws.com';
1590
+ $s3 = new S3($as3_access_key, str_replace(' ', '+', $as3_secure_key), false, $endpoint);
1591
+ if ($as3_site_folder == true)
1592
+ $as3_directory .= '/' . $this->site_name;
1593
+
1594
+ $temp = ABSPATH . 'iwp_temp_backup.zip';
1595
+ $s3->getObject($as3_bucket, $as3_directory . '/' . $backup_file, $temp);
1596
+
1597
+ return $temp;
1598
+ }
1599
+
1600
+ function schedule_next($type, $schedule)
1601
+ {
1602
+ $schedule = explode("|", $schedule);
1603
+ if (empty($schedule))
1604
+ return false;
1605
+ switch ($type) {
1606
+
1607
+ case 'daily':
1608
+
1609
+ if ($schedule[1]) {
1610
+ $delay_time = $schedule[1] * 60;
1611
+ }
1612
+
1613
+ $current_hour = date("H");
1614
+ $schedule_hour = $schedule[0];
1615
+ if ($current_hour >= $schedule_hour){
1616
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d") + 1, date("Y"));
1617
+ //$time ='0001#'.$current_hour.'|'.$schedule_hour;
1618
+ }
1619
+ else{
1620
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d"), date("Y"));
1621
+ //$time ='0000#'.$current_hour.'|'.$schedule_hour;
1622
+ }
1623
+ $time = time() + 30;
1624
+ break;
1625
+
1626
+
1627
+ case 'weekly':
1628
+ if ($schedule[2]) {
1629
+ $delay_time = $schedule[2] * 60;
1630
+ }
1631
+ $current_weekday = date('w');
1632
+ $schedule_weekday = $schedule[1];
1633
+ $current_hour = date("H");
1634
+ $schedule_hour = $schedule[0];
1635
+
1636
+ if ($current_weekday > $schedule_weekday)
1637
+ $weekday_offset = 7 - ($week_day - $task_schedule[1]);
1638
+ else
1639
+ $weekday_offset = $schedule_weekday - $current_weekday;
1640
+
1641
+
1642
+ if (!$weekday_offset) { //today is scheduled weekday
1643
+ if ($current_hour >= $schedule_hour)
1644
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d") + 7, date("Y"));
1645
+ else
1646
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d"), date("Y"));
1647
+ } else {
1648
+ $time = mktime($schedule_hour, 0, 0, date("m"), date("d") + $weekday_offset, date("Y"));
1649
+ }
1650
+
1651
+ break;
1652
+
1653
+ case 'monthly':
1654
+ if ($schedule[2]) {
1655
+ $delay_time = $schedule[2] * 60;
1656
+ }
1657
+ $current_monthday = date('j');
1658
+ $schedule_monthday = $schedule[1];
1659
+ $current_hour = date("H");
1660
+ $schedule_hour = $schedule[0];
1661
+
1662
+ if ($current_monthday > $schedule_monthday) {
1663
+ $time = mktime($schedule_hour, 0, 0, date("m") + 1, $schedule_monthday, date("Y"));
1664
+ } else if ($current_monthday < $schedule_monthday) {
1665
+ $time = mktime($schedule_hour, 0, 0, date("m"), $schedule_monthday, date("Y"));
1666
+ } else if ($current_monthday == $schedule_monthday) {
1667
+ if ($current_hour >= $schedule_hour)
1668
+ $time = mktime($schedule_hour, 0, 0, date("m") + 1, $schedule_monthday, date("Y"));
1669
+ else
1670
+ $time = mktime($schedule_hour, 0, 0, date("m"), $schedule_monthday, date("Y"));
1671
+ break;
1672
+ }
1673
+
1674
+ break;
1675
+ default:
1676
+ break;
1677
+ }
1678
+
1679
+ if ($delay_time) {
1680
+ $time += $delay_time;
1681
+ }
1682
+
1683
+
1684
+ return $time;
1685
+
1686
+ }
1687
+ //IWP Remove ends here
1688
+ */
1689
+
1690
+ //Parse task arguments for info on IWP Admin Panel
1691
+ function get_backup_stats()
1692
+ {
1693
+ $stats = array();
1694
+ $tasks = $this->tasks;
1695
+ if (is_array($tasks) && !empty($tasks)) {
1696
+ foreach ($tasks as $task_name => $info) {
1697
+ if (is_array($info['task_results']) && !empty($info['task_results'])) {
1698
+ foreach ($info['task_results'] as $key => $result) {
1699
+ if (isset($result['server']) && !isset($result['error'])) {
1700
+ if (!file_exists($result['server']['file_path'])) {
1701
+ $info['task_results'][$key]['error'] = 'Backup created but manually removed from server.';
1702
+ }
1703
+ }
1704
+ }
1705
+ }
1706
+ if (is_array($info['task_results']))
1707
+ $stats[$task_name] = array_values($info['task_results']);
1708
+
1709
+ }
1710
+ }
1711
+ return $stats;
1712
+ }
1713
+
1714
+ /*
1715
+ //IWP Remove starts here
1716
+ function get_next_schedules()
1717
+ {
1718
+ $stats = array();
1719
+ $tasks = $this->tasks;
1720
+ if (is_array($tasks) && !empty($tasks)) {
1721
+ foreach ($tasks as $task_name => $info) {
1722
+ $stats[$task_name] = isset($info['task_args']['next']) ? $info['task_args']['next'] : array();
1723
+ }
1724
+ }
1725
+ return $stats;
1726
+ }
1727
+ //IWP Remove ends here
1728
+ */
1729
+
1730
+ function remove_old_backups($task_name)
1731
+ {
1732
+ //Check for previous failed backups first
1733
+ $this->cleanup();
1734
+
1735
+ //Remove by limit
1736
+ $backups = $this->tasks;
1737
+ if ($task_name == 'Backup Now') {
1738
+ $num = 0;
1739
+ } else {
1740
+ $num = 1;
1741
+ }
1742
+
1743
+
1744
+ if ((count($backups[$task_name]['task_results']) - $num) >= $backups[$task_name]['task_args']['limit']) {
1745
+ //how many to remove ?
1746
+ $remove_num = (count($backups[$task_name]['task_results']) - $num - $backups[$task_name]['task_args']['limit']) + 1;
1747
+ for ($i = 0; $i < $remove_num; $i++) {
1748
+ //Remove from the server
1749
+ if (isset($backups[$task_name]['task_results'][$i]['server'])) {
1750
+ @unlink($backups[$task_name]['task_results'][$i]['server']['file_path']);
1751
+ }
1752
+
1753
+ /*
1754
+ //IWP Remove starts here
1755
+ //Remove from ftp
1756
+ if (isset($backups[$task_name]['task_results'][$i]['ftp'])) {
1757
+ $ftp_file = $backups[$task_name]['task_results'][$i]['ftp'];
1758
+ $args = $backups[$task_name]['task_args']['account_info']['iwp_ftp'];
1759
+ $args['backup_file'] = $ftp_file;
1760
+ $this->remove_ftp_backup($args);
1761
+ }
1762
+
1763
+ if (isset($backups[$task_name]['task_results'][$i]['amazons3'])) {
1764
+ $amazons3_file = $backups[$task_name]['task_results'][$i]['amazons3'];
1765
+ $args = $backups[$task_name]['task_args']['account_info']['iwp_amazon_s3'];
1766
+ $args['backup_file'] = $amazons3_file;
1767
+ $this->remove_amazons3_backup($args);
1768
+ }
1769
+
1770
+ if (isset($backups[$task_name]['task_results'][$i]['dropbox'])) {
1771
+ //To do: dropbox remove
1772
+ }
1773
+ //IWP Remove ends here
1774
+ */
1775
+
1776
+ //Remove database backup info
1777
+ unset($backups[$task_name]['task_results'][$i]);
1778
+
1779
+ } //end foreach
1780
+
1781
+ if (is_array($backups[$task_name]['task_results']))
1782
+ $backups[$task_name]['task_results'] = array_values($backups[$task_name]['task_results']);
1783
+ else
1784
+ $backups[$task_name]['task_results']=array();
1785
+
1786
+ $this->update_tasks($backups);
1787
+ //update_option('iwp_client_backup_tasks', $backups);
1788
+ }
1789
+ }
1790
+
1791
+ /**
1792
+ * Delete specified backup
1793
+ * Args: $task_name, $result_id
1794
+ */
1795
+
1796
+ function delete_backup($args)
1797
+ {
1798
+ if (empty($args))
1799
+ return false;
1800
+ extract($args);
1801
+
1802
+ $tasks = $this->tasks;
1803
+ $task = $tasks[$task_name];
1804
+ $backups = $task['task_results'];
1805
+ $backup = $backups[$result_id];
1806
+
1807
+ if (isset($backup['server'])) {
1808
+ @unlink($backup['server']['file_path']);
1809
+ }
1810
+
1811
+ /*
1812
+ //IWP Remove starts here
1813
+ //Remove from ftp
1814
+ if (isset($backup['ftp'])) {
1815
+ $ftp_file = $backup['ftp'];
1816
+ $args = $tasks[$task_name]['task_args']['account_info']['iwp_ftp'];
1817
+ $args['backup_file'] = $ftp_file;
1818
+ $this->remove_ftp_backup($args);
1819
+ }
1820
+
1821
+ if (isset($backup['amazons3'])) {
1822
+ $amazons3_file = $backup['amazons3'];
1823
+ $args = $tasks[$task_name]['task_args']['account_info']['iwp_amazon_s3'];
1824
+ $args['backup_file'] = $amazons3_file;
1825
+ $this->remove_amazons3_backup($args);
1826
+ }
1827
+
1828
+ if (isset($backup['dropbox'])) {
1829
+ }
1830
+ //IWP Remove ends here
1831
+ */
1832
+
1833
+ unset($backups[$result_id]);