BackUpWordPress - Version 0.2.1

Version Description

Download this release

Release Info

Developer wpdprx
Plugin Icon 128x128 BackUpWordPress
Version 0.2.1
Comparing to
See all releases

Code changes from version 0.1.4 to 0.2.1

backupwordpress.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: BackUpWordPress
4
  Plugin URI: http://wordpress.designpraxis.at
5
  Description: Manage <a href="admin.php?page=backupwordpress/backupwordpress.php">WordPress Backups</a>. Beta Release. Please help testing and give me feedback under the comments section of <a href="http://wordpress.designpraxis.at/plugins/backupwordpress/">the Plugin page</a>. Backup DB, Files & Folders, use .tar.gz, .zip, Exclude List, etc.
6
  Author: Roland Rust
7
- Version: 0.1.4
8
  Author URI: http://wordpress.designpraxis.at
9
  */
10
 
@@ -13,7 +13,6 @@ Notes:
13
  backupwordpress\Archive\Writer\Tar.php has been debugged around line 80 to handle long filenames according to http://pear.php.net/bugs/bug.php?id=10144&edit=3
14
 
15
  Whishlist:
16
- - staggered export od files and sql.
17
  - custom schedules
18
  */
19
 
@@ -21,6 +20,11 @@ Whishlist:
21
 
22
  Changelog:
23
 
 
 
 
 
 
24
  Changes in 0.1.4:
25
  - @set_time_limit(0) in functions.php line 277 supresses the 'Cannot set time limit in safe mode' warning
26
  - dialoques streamlined: e.g. when you click "delete" on a backup archive, you just need to hit enter to delete it
@@ -75,11 +79,13 @@ add_action('deactivate_backupwordpress/backupwordpress.php', 'bkpwp_exit');
75
  add_action('init', 'bkpwp_download_files');
76
  add_action('init', 'bkpwp_setup');
77
  add_action('init', 'bkpwp_sajax_do');
 
78
 
79
  // cron jobs with wordpress' pseude-cron: add special reccurences
80
  add_filter('cron_schedules', 'bkpwp_more_reccurences');
81
 
82
  add_action('bkpwp_schedule_bkpwp_hook','bkpwp_schedule_bkpwp');
 
83
 
84
  if (eregi("backupwordpress",$_REQUEST['page']) || eregi("bkpwp",$_REQUEST['page'])) {
85
  add_action('admin_head', 'bkpwp_sajax_js');
4
  Plugin URI: http://wordpress.designpraxis.at
5
  Description: Manage <a href="admin.php?page=backupwordpress/backupwordpress.php">WordPress Backups</a>. Beta Release. Please help testing and give me feedback under the comments section of <a href="http://wordpress.designpraxis.at/plugins/backupwordpress/">the Plugin page</a>. Backup DB, Files & Folders, use .tar.gz, .zip, Exclude List, etc.
6
  Author: Roland Rust
7
+ Version: 0.2.1
8
  Author URI: http://wordpress.designpraxis.at
9
  */
10
 
13
  backupwordpress\Archive\Writer\Tar.php has been debugged around line 80 to handle long filenames according to http://pear.php.net/bugs/bug.php?id=10144&edit=3
14
 
15
  Whishlist:
 
16
  - custom schedules
17
  */
18
 
20
 
21
  Changelog:
22
 
23
+ Changes in 0.2.1:
24
+ - old Logfiles are deleted. 10 times the amount of the configured amount of backups to keep is kept.
25
+ - feature: backups are done in kind of a staggered process:
26
+ if BackUpWordPress runs into a server side time-out, BackUpWordPress tries to trigger an single scheduled event for finishing the task. Corresponding dialoques appear on the *Manage Backups* - screen.
27
+
28
  Changes in 0.1.4:
29
  - @set_time_limit(0) in functions.php line 277 supresses the 'Cannot set time limit in safe mode' warning
30
  - dialoques streamlined: e.g. when you click "delete" on a backup archive, you just need to hit enter to delete it
79
  add_action('init', 'bkpwp_download_files');
80
  add_action('init', 'bkpwp_setup');
81
  add_action('init', 'bkpwp_sajax_do');
82
+ add_action('init', 'bkpwp_proceed_unfinished');
83
 
84
  // cron jobs with wordpress' pseude-cron: add special reccurences
85
  add_filter('cron_schedules', 'bkpwp_more_reccurences');
86
 
87
  add_action('bkpwp_schedule_bkpwp_hook','bkpwp_schedule_bkpwp');
88
+ add_action('bkpwp_finish_bkpwp_hook','bkpwp_finish_bkpwp');
89
 
90
  if (eregi("backupwordpress",$_REQUEST['page']) || eregi("bkpwp",$_REQUEST['page'])) {
91
  add_action('admin_head', 'bkpwp_sajax_js');
bkpwp-classes/manage_backups.php CHANGED
@@ -50,7 +50,6 @@ class BKPWP_BACKUP_ARCHIVE {
50
  $backup->options = new BKPWP_OPTIONS();
51
  $info = new BKPWP_BACKUP_ARCHIVE();
52
  $info = $info->bkpwp_view_backup_info(base64_encode($f['file']),1);
53
- //if (!file_exists($f['file'])) { return; }
54
  $type = $backup->options->bkpwp_get_backup_type($f['filename']);
55
  if ($alternate != "new_row") {
56
  ?>
@@ -86,33 +85,37 @@ class BKPWP_BACKUP_ARCHIVE {
86
  echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_download=".base64_encode($f['file'])."\">".__("download","bkpwp")."</a>";
87
  ?>
88
  </td>
89
- <?php if (!$backup->options->bkpwp_easy_mode()) { ?>
90
  <td style="text-align: center;">
91
- <?php
92
- echo " <a href=\"javascript:void(0)\"
93
- onclick=\"bkpwp_js_loading('".__("View Backup Information","bkpwp")."');
94
- sajax_target_id = 'bkpwp_action_buffer';
95
- x_bkpwp_ajax_view_backup('".base64_encode($f['file'])."','');
96
- sajax_target_id = '';\">".__("view","bkpwp")."</a>";
97
- ?>
98
- </td>
99
- <td style="text-align: center;">
100
- <?php
101
- echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_mail=".base64_encode($f['file'])."\">".__("mail","bkpwp")."</a>";
102
- ?>
103
- </td>
104
- <?php } ?>
105
- <td style="text-align: center;">
106
- <?php
107
- echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_restore=".base64_encode($f['file'])."\">".__("restore","bkpwp")."</a>";
108
- ?>
109
- </td>
110
- <?php if (!$backup->options->bkpwp_easy_mode()) { ?>
111
- <td style="text-align: center;">
112
- <?php
113
- echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_delete=".base64_encode($f['file'])."\">".__("delete","bkpwp")."</a>";
114
- ?>
115
- </td>
 
 
 
 
 
116
  <?php } ?>
117
  <?php
118
  if ($alternate != "new_row") {
@@ -132,7 +135,7 @@ class BKPWP_BACKUP {
132
  function bkpwp_backquote($a_name)
133
  {
134
  /*
135
- Add backqouotes to tables and db-names in
136
  SQL queries. Taken from phpMyAdmin.
137
  */
138
  if (!empty($a_name) && $a_name != '*') {
@@ -151,7 +154,7 @@ class BKPWP_BACKUP {
151
  }
152
  } // function backquote($a_name, $do_it = TRUE)
153
 
154
- function bkpwp_make_sql($table,$log)
155
  {
156
  /*
157
  Reads the Database table in $table and creates
@@ -161,40 +164,40 @@ class BKPWP_BACKUP {
161
  Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
162
  */
163
 
164
- $sql_statements = "";
165
 
166
  // Add SQL statement to drop existing table
167
- $sql_statements .= "\n";
168
- $sql_statements .= "\n";
169
- $sql_statements .= "#\n";
170
- $sql_statements .= "# Delete any existing table " . $this->bkpwp_backquote($table) . "\n";
171
- $sql_statements .= "#\n";
172
- $sql_statements .= "\n";
173
- $sql_statements .= "DROP TABLE IF EXISTS " . $this->bkpwp_backquote($table) . ";\n";
174
 
175
  // Table structure
176
 
177
  // Comment in SQL-file
178
- $sql_statements .= "\n";
179
- $sql_statements .= "\n";
180
- $sql_statements .= "#\n";
181
- $sql_statements .= "# Table structure of table " . $this->bkpwp_backquote($table) . "\n";
182
- $sql_statements .= "#\n";
183
- $sql_statements .= "\n";
184
 
185
  // Get table structure
186
  $query = "SHOW CREATE TABLE " . $this->bkpwp_backquote($table);
187
  $result = mysql_query($query, $GLOBALS["db_connect"]);
188
  if ($result == FALSE) {
189
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Error getting table structure of ","bkpwp").$table."! ".mysql_errno() . ": " . mysql_error()." ".$this->bkpwp_logtimestamp();
190
- $this->bkpwp_write_log($log);
191
  } else {
192
  if (mysql_num_rows($result) > 0) {
193
  $sql_create_arr = mysql_fetch_array($result);
194
- $sql_statements .= $sql_create_arr[1];
195
  }
196
  mysql_free_result($result);
197
- $sql_statements .= " ;";
198
  } // ($result == FALSE)
199
 
200
  // Table data contents
@@ -204,18 +207,18 @@ class BKPWP_BACKUP {
204
  $result = mysql_query($query, $GLOBALS["db_connect"]);
205
  if ($result == FALSE) {
206
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Error getting records of ","bkpwp").$table."! ".mysql_errno() . ": " . mysql_error()." ".$this->bkpwp_logtimestamp();
207
- $this->bkpwp_write_log($log);
208
  } else {
209
  $fields_cnt = mysql_num_fields($result);
210
  $rows_cnt = mysql_num_rows($result);
211
  } // if ($result == FALSE)
212
 
213
  // Comment in SQL-file
214
- $sql_statements .= "\n";
215
- $sql_statements .= "\n";
216
- $sql_statements .= "#\n";
217
- $sql_statements .= "# Data contents of table " . $table . " (" . $rows_cnt . " records)\n";
218
- $sql_statements .= "#\n";
219
 
220
  // Checks whether the field is an integer or not
221
  for ($j = 0; $j < $fields_cnt; $j++) {
@@ -234,8 +237,29 @@ class BKPWP_BACKUP {
234
  $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
235
  $replace = array('\0', '\n', '\r', '\Z');
236
  $current_row = 0;
 
237
  while ($row = mysql_fetch_row($result)) {
238
  $current_row++;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  for ($j = 0; $j < $fields_cnt; $j++) {
240
  if (!isset($row[$j])) {
241
  $values[] = 'NULL';
@@ -251,18 +275,37 @@ class BKPWP_BACKUP {
251
  $values[] = "''";
252
  } // if (!isset($row[$j]))
253
  } // for ($j = 0; $j < $fields_cnt; $j++)
254
- $sql_statements .= " \n" . $entries . implode(', ', $values) . ') ;';
 
 
 
 
 
 
 
 
 
 
 
 
 
255
  unset($values);
256
  } // while ($row = mysql_fetch_row($result))
257
  mysql_free_result($result);
258
 
259
  // Create footer/closing comment in SQL-file
260
- $sql_statements .= "\n";
261
- $sql_statements .= "#\n";
262
- $sql_statements .= "# End of data contents of table " . $table . "\n";
263
- $sql_statements .= "# --------------------------------------------------------\n";
264
- $sql_statements .= "\n";
265
- return $sql_statements;
 
 
 
 
 
 
266
  } //function make_sql($table)
267
 
268
  function bkpwp_sql_addslashes($a_string = '', $is_like = FALSE)
@@ -281,20 +324,20 @@ class BKPWP_BACKUP {
281
  return $a_string;
282
  } // function sql_addslashes($a_string = '', $is_like = FALSE)
283
 
284
- function bkpwp_mysql($path,$log) {
285
  if (!$GLOBALS['db_connect'] = @mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD)) {
286
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Could not connect to MySQL server! ","bkpwp"). mysql_error()." ".$this->bkpwp_logtimestamp();
287
- $this->bkpwp_write_log($log);
288
  }
289
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("MySQL server connected successfully ","bkpwp")." ".$this->bkpwp_logtimestamp();
290
- $this->bkpwp_write_log($log);
291
  mysql_select_db(DB_NAME,$GLOBALS['db_connect']);
292
- $file_name = "wordpress.sql";
293
  //Begin new backup of MySql
294
  $tables = mysql_list_tables(DB_NAME);
295
  if (!isset($tables) > 0) {
296
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Could not select db ","bkpwp").DB_NAME." ".$this->bkpwp_logtimestamp();
297
- $this->bkpwp_write_log($log);
298
  }
299
  $sql_file = "# WordPress : ".get_bloginfo("url")." MySQL database backup\n";
300
  $sql_file .= "#\n";
@@ -302,27 +345,34 @@ class BKPWP_BACKUP {
302
  $sql_file .= "# Hostname: " . DB_HOST . "\n";
303
  $sql_file .= "# Database: " . $this->bkpwp_backquote(DB_NAME) . "\n";
304
  $sql_file .= "# --------------------------------------------------------\n";
 
 
 
 
305
  for ($i = 0; $i < mysql_num_rows($tables); $i++) {
306
  $curr_table = mysql_tablename($tables, $i);
307
- // Increase script execution time-limit to 15 min for every table.
308
- if ( !ini_get('safe_mode')) @set_time_limit(15*60);
309
- // Create the SQL statements
310
- $sql_file .= "# --------------------------------------------------------\n";
311
- $sql_file .= "# Table: " . $this->bkpwp_backquote($curr_table) . "\n";
312
- $sql_file .= "# --------------------------------------------------------\n";
313
- $sql_file .= $this->bkpwp_make_sql($curr_table,$log);
314
- }
315
- $cachefp = fopen($path."/".$file_name, "w");
316
- fwrite($cachefp, $sql_file);
317
- if (file_exists($path."/".$file_name)) {
318
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$path."/".$file_name." created ".$this->bkpwp_logtimestamp();
319
- $this->bkpwp_write_log($log);
320
- return true;
321
- } else {
322
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$path."/".$file_name." could not be created ".$this->bkpwp_logtimestamp();
323
- $this->bkpwp_write_log($log);
 
 
 
 
324
  }
325
- return false;
326
  }
327
 
328
  function bkpwp_calculate($preset) {
@@ -353,15 +403,38 @@ class BKPWP_BACKUP {
353
  return date(get_option('date_format'))." ".date("H:i:s");
354
  }
355
 
356
- function bkpwp_do_backup($preset) {
 
 
 
 
 
357
  $options = new BKPWP_OPTIONS();
358
  $log = array();
359
  // get the desired archive type from preset
 
 
 
 
 
 
 
 
 
 
360
  $type = $preset['bkpwp_preset_options']['bkpwp_archive_type'];
361
  $sqlonly = $preset['bkpwp_preset_options']['bkpwp_sql_only'];
362
  $options->excludelist = $preset['bkpwp_preset_options']['bkpwp_excludelist'];
 
363
 
364
  $datestamp = date("Y-m-d-H-i-s");
 
 
 
 
 
 
 
365
  // temporary directory name
366
  $backup_tmp_dir = get_option("bkpwppath")."/".$datestamp;
367
 
@@ -383,6 +456,7 @@ class BKPWP_BACKUP {
383
 
384
  // count milliseconds
385
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress starting at","bkpwp")." ".$this->bkpwp_logtimestamp();
 
386
 
387
  // create a temporary directory
388
  if (!is_dir($backup_tmp_dir)) {
@@ -391,8 +465,11 @@ class BKPWP_BACKUP {
391
  } else {
392
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$backup_tmp_dir."' ".__("created","bkpwp");
393
  }
 
 
394
  }
395
- $this->bkpwp_write_log($log);
 
396
  if ($sqlonly != 1) {
397
  // subdirectory of wordpress files
398
  $wordpress_files = $backup_tmp_dir."/wordpress_files";
@@ -402,38 +479,68 @@ class BKPWP_BACKUP {
402
  } else {
403
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$wordpress_files."' ".__("created","bkpwp");
404
  }
405
- $this->bkpwp_write_log($log);
406
  }
407
  }
408
 
409
- $db_dump = $this->bkpwp_mysql($backup_tmp_dir,$log);
410
 
411
- if(!$db_dump) {
412
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQL Dump could not be created.","bkpwp");
413
  } else {
414
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQL Dump created.","bkpwp");
415
  }
416
- $this->bkpwp_write_log($log);
417
  if ($sqlonly != 1) {
418
  // create a temporary directory of files to backup
419
  $dir = bkpwp_conform_dir(ABSPATH);
420
  $files = $options->bkpwp_ls($dir);
421
  $files_copied = 0;
 
422
  $subdirs_created = 0;
423
  $i=1; // the sql at least
424
  foreach ($files as $f) {
425
  if (is_dir($f)) {
426
  if (!mkdir($wordpress_files.bkpwp_conform_dir($f, true))) {
427
- return __("Failed to make directory","bkpwp");
 
 
428
  } else {
429
  $subdirs_created++;
430
  }
431
  } elseif(file_exists($f)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
432
  if (!copy($f,$wordpress_files.bkpwp_conform_dir($f, true))) {
433
- return __("Failed to copy","bkpwp");
434
- } else {
435
- $files_copied++;
 
 
 
 
436
  }
 
 
437
  }
438
  $i++;
439
  }
@@ -445,13 +552,14 @@ class BKPWP_BACKUP {
445
  $archive_backup->setOption("tmpDirectory",get_option("bkpwppath"));
446
  $archive_backup->extract($backup_tmp_dir,File_Archive::toArchive($backup_filename, File_Archive::toFiles()));
447
  if (!file_exists($backup_filename)) {
448
- return __("Failed to create backup archive","bkpwp");
449
  } else {
450
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Archive File created/compressed successfully:","bkpwp")." ".$backup_filename;
451
  }
452
 
453
  $deleted_files_count = $this->bkpwp_rmdirtree($backup_tmp_dir);
454
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".count($deleted_files_count)." ".__("Temporary Directories and Files deleted successfully","bkpwp");
 
455
  $deleted_oldarchives_count = $this->bkpwp_delete_old();
456
  if ($deleted_oldarchives_count > 0) {
457
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$deleted_oldarchives_count." ".__("Old BackUpWordPress Archives deleted successfully","bkpwp");
@@ -459,6 +567,13 @@ class BKPWP_BACKUP {
459
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("No old BackUpWordPress Archives to delete","bkpwp");
460
  }
461
 
 
 
 
 
 
 
 
462
 
463
  $time_end = microtime(true);
464
  $time = $time_end - $time_start;
@@ -466,7 +581,13 @@ class BKPWP_BACKUP {
466
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress was running for","bkpwp")." ".round($time,2)." ".__("Seconds","bkpwp");
467
 
468
  // write the log
469
- $this->bkpwp_write_log($log);
 
 
 
 
 
 
470
  $backup = array("file" => $backup_filename,
471
  "filename" => $backup_filename_short);
472
  // start the output
@@ -528,6 +649,30 @@ class BKPWP_BACKUP {
528
  return true;
529
  }
530
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
  function bkpwp_write_log($log,$return="") {
532
  if (!is_array($log)) { return; }
533
  $logdir = get_option("bkpwppath")."/logs";
@@ -536,9 +681,13 @@ class BKPWP_BACKUP {
536
  }
537
  $logname = $logdir."/".$log['filename'].".txt";
538
  $logfile = "";
539
- $logfile .= "Preset: ".$log['preset']."\n";
540
- if (!empty($log['schedule'])) {
541
- $logfile .= "Schedule: ".$log['schedule']."\n";
 
 
 
 
542
  }
543
  if (is_array($log['logfile'])) {
544
  foreach($log['logfile'] as $l) {
@@ -552,11 +701,9 @@ class BKPWP_BACKUP {
552
  if ($this->is__writable($logname)) {
553
  if (!$handle = fopen($logname, "a")) {
554
  return __("Logfile could not be opened for writing: ","bkpwp").$logname;
555
- exit;
556
  }
557
  if (!fwrite($handle, $logfile)) {
558
  return __("Logfile not writable: ","bkpwp").$logname;
559
- exit;
560
  }
561
  fclose($handle);
562
  return true;
@@ -615,6 +762,29 @@ class BKPWP_BACKUP {
615
  }
616
  return false;
617
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
618
 
619
  }
620
 
@@ -803,6 +973,29 @@ class BKPWP_MANAGE {
803
  array_multisort($filename, SORT_DESC, $files);
804
  return $files;
805
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
806
  }
807
 
808
 
50
  $backup->options = new BKPWP_OPTIONS();
51
  $info = new BKPWP_BACKUP_ARCHIVE();
52
  $info = $info->bkpwp_view_backup_info(base64_encode($f['file']),1);
 
53
  $type = $backup->options->bkpwp_get_backup_type($f['filename']);
54
  if ($alternate != "new_row") {
55
  ?>
85
  echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_download=".base64_encode($f['file'])."\">".__("download","bkpwp")."</a>";
86
  ?>
87
  </td>
 
88
  <td style="text-align: center;">
89
+ <?php if (!is_dir($f['file'])) { ?>
90
+ <?php if (!$backup->options->bkpwp_easy_mode()) { ?>
91
+ <?php
92
+ echo " <a href=\"javascript:void(0)\"
93
+ onclick=\"bkpwp_js_loading('".__("View Backup Information","bkpwp")."');
94
+ sajax_target_id = 'bkpwp_action_buffer';
95
+ x_bkpwp_ajax_view_backup('".base64_encode($f['file'])."','');
96
+ sajax_target_id = '';\">".__("view","bkpwp")."</a>";
97
+ ?>
98
+ </td>
99
+ <td style="text-align: center;">
100
+ <?php
101
+ echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_mail=".base64_encode($f['file'])."\">".__("mail","bkpwp")."</a>";
102
+ ?>
103
+ </td>
104
+ <?php } ?>
105
+ <td style="text-align: center;">
106
+ <?php
107
+ echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_restore=".base64_encode($f['file'])."\">".__("restore","bkpwp")."</a>";
108
+ ?>
109
+ </td>
110
+ <?php if (!$backup->options->bkpwp_easy_mode()) { ?>
111
+ <td style="text-align: center;">
112
+ <?php
113
+ echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_delete=".base64_encode($f['file'])."\">".__("delete","bkpwp")."</a>";
114
+ ?>
115
+ </td>
116
+ <?php } ?>
117
+ <?php } else { ?>
118
+ <?php echo "".__("Your Backup is bein processed.","bkpwp").""; ?>
119
  <?php } ?>
120
  <?php
121
  if ($alternate != "new_row") {
135
  function bkpwp_backquote($a_name)
136
  {
137
  /*
138
+ Add backquotes to tables and db-names in
139
  SQL queries. Taken from phpMyAdmin.
140
  */
141
  if (!empty($a_name) && $a_name != '*') {
154
  }
155
  } // function backquote($a_name, $do_it = TRUE)
156
 
157
+ function bkpwp_make_sql($path,$sql_file,$table,$status,$log)
158
  {
159
  /*
160
  Reads the Database table in $table and creates
164
  Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
165
  */
166
 
167
+ $sql_file = "";
168
 
169
  // Add SQL statement to drop existing table
170
+ $sql_file .= "\n";
171
+ $sql_file .= "\n";
172
+ $sql_file .= "#\n";
173
+ $sql_file .= "# Delete any existing table " . $this->bkpwp_backquote($table) . "\n";
174
+ $sql_file .= "#\n";
175
+ $sql_file .= "\n";
176
+ $sql_file .= "DROP TABLE IF EXISTS " . $this->bkpwp_backquote($table) . ";\n";
177
 
178
  // Table structure
179
 
180
  // Comment in SQL-file
181
+ $sql_file .= "\n";
182
+ $sql_file .= "\n";
183
+ $sql_file .= "#\n";
184
+ $sql_file .= "# Table structure of table " . $this->bkpwp_backquote($table) . "\n";
185
+ $sql_file .= "#\n";
186
+ $sql_file .= "\n";
187
 
188
  // Get table structure
189
  $query = "SHOW CREATE TABLE " . $this->bkpwp_backquote($table);
190
  $result = mysql_query($query, $GLOBALS["db_connect"]);
191
  if ($result == FALSE) {
192
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Error getting table structure of ","bkpwp").$table."! ".mysql_errno() . ": " . mysql_error()." ".$this->bkpwp_logtimestamp();
193
+ $this->bkpwp_write_log($log); unset($log['logfile']);
194
  } else {
195
  if (mysql_num_rows($result) > 0) {
196
  $sql_create_arr = mysql_fetch_array($result);
197
+ $sql_file .= $sql_create_arr[1];
198
  }
199
  mysql_free_result($result);
200
+ $sql_file .= " ;";
201
  } // ($result == FALSE)
202
 
203
  // Table data contents
207
  $result = mysql_query($query, $GLOBALS["db_connect"]);
208
  if ($result == FALSE) {
209
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Error getting records of ","bkpwp").$table."! ".mysql_errno() . ": " . mysql_error()." ".$this->bkpwp_logtimestamp();
210
+ $this->bkpwp_write_log($log); unset($log['logfile']);
211
  } else {
212
  $fields_cnt = mysql_num_fields($result);
213
  $rows_cnt = mysql_num_rows($result);
214
  } // if ($result == FALSE)
215
 
216
  // Comment in SQL-file
217
+ $sql_file .= "\n";
218
+ $sql_file .= "\n";
219
+ $sql_file .= "#\n";
220
+ $sql_file .= "# Data contents of table " . $table . " (" . $rows_cnt . " records)\n";
221
+ $sql_file .= "#\n";
222
 
223
  // Checks whether the field is an integer or not
224
  for ($j = 0; $j < $fields_cnt; $j++) {
237
  $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
238
  $replace = array('\0', '\n', '\r', '\Z');
239
  $current_row = 0;
240
+ $batch_write = 0;
241
  while ($row = mysql_fetch_row($result)) {
242
  $current_row++;
243
+
244
+ //test
245
+ // if (empty($status) && ($table == "crawlt_ip_data") && ($current_row == 287)) {
246
+ // sleep(200);
247
+ // }
248
+
249
+ // if we have to continue an unfinished backup
250
+ if (!empty($status) && empty($continue_backup)) {
251
+ $statusarr = get_option("bkpwp_status");
252
+ if ($statusarr['type'] == "sqltable_row") {
253
+ if ($statusarr['point'] == $table."-".$current_row) {
254
+ $continue_backup = 1;
255
+ continue;
256
+ } else {
257
+ continue;
258
+ }
259
+ }
260
+ }
261
+
262
+ // build the statement
263
  for ($j = 0; $j < $fields_cnt; $j++) {
264
  if (!isset($row[$j])) {
265
  $values[] = 'NULL';
275
  $values[] = "''";
276
  } // if (!isset($row[$j]))
277
  } // for ($j = 0; $j < $fields_cnt; $j++)
278
+ $sql_file .= " \n" . $entries . implode(', ', $values) . ') ;';
279
+
280
+
281
+ // write the rows in batches of 100
282
+ if ($batch_write == 100) {
283
+ $batch_write = 0;
284
+ $this->bkpwp_write_sql($path,$sql_file);
285
+ $sql_file = "";
286
+ $name = str_replace(get_option("bkpwppath")."/","",$path);
287
+ $this->bkpwp_set_status($name,'sqltable_row',$table."-".$current_row);
288
+ unset($status);
289
+ }
290
+ $batch_write++;
291
+
292
  unset($values);
293
  } // while ($row = mysql_fetch_row($result))
294
  mysql_free_result($result);
295
 
296
  // Create footer/closing comment in SQL-file
297
+ $sql_file .= "\n";
298
+ $sql_file .= "#\n";
299
+ $sql_file .= "# End of data contents of table " . $table . "\n";
300
+ $sql_file .= "# --------------------------------------------------------\n";
301
+ $sql_file .= "\n";
302
+
303
+ if (empty($status) || !empty($continue_backup)) {
304
+ $this->bkpwp_write_sql($path,$sql_file);
305
+ $sql_file = "";
306
+ $name = str_replace(get_option("bkpwppath")."/","",$path);
307
+ $this->bkpwp_set_status($name,'sqltable',$table);
308
+ }
309
  } //function make_sql($table)
310
 
311
  function bkpwp_sql_addslashes($a_string = '', $is_like = FALSE)
324
  return $a_string;
325
  } // function sql_addslashes($a_string = '', $is_like = FALSE)
326
 
327
+ function bkpwp_mysql($path,$status="",$log) {
328
  if (!$GLOBALS['db_connect'] = @mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD)) {
329
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Could not connect to MySQL server! ","bkpwp"). mysql_error()." ".$this->bkpwp_logtimestamp();
330
+ $this->bkpwp_write_log($log); unset($log['logfile']);
331
  }
332
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("MySQL server connected successfully ","bkpwp")." ".$this->bkpwp_logtimestamp();
333
+ $this->bkpwp_write_log($log); unset($log['logfile']);
334
  mysql_select_db(DB_NAME,$GLOBALS['db_connect']);
335
+
336
  //Begin new backup of MySql
337
  $tables = mysql_list_tables(DB_NAME);
338
  if (!isset($tables) > 0) {
339
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Could not select db ","bkpwp").DB_NAME." ".$this->bkpwp_logtimestamp();
340
+ $this->bkpwp_write_log($log); unset($log['logfile']);
341
  }
342
  $sql_file = "# WordPress : ".get_bloginfo("url")." MySQL database backup\n";
343
  $sql_file .= "#\n";
345
  $sql_file .= "# Hostname: " . DB_HOST . "\n";
346
  $sql_file .= "# Database: " . $this->bkpwp_backquote(DB_NAME) . "\n";
347
  $sql_file .= "# --------------------------------------------------------\n";
348
+ if (empty($status)) {
349
+ $this->bkpwp_write_sql($path,$sql_file);
350
+ $sql_file = "";
351
+ }
352
  for ($i = 0; $i < mysql_num_rows($tables); $i++) {
353
  $curr_table = mysql_tablename($tables, $i);
354
+ if (!empty($status) && empty($continue_backup)) {
355
+ $statusarr = get_option("bkpwp_status");
356
+ if ($statusarr['type'] == "sqltable_row") {
357
+ $continue_backup = 1;
358
+ } elseif ($statusarr['point'] == $curr_table) {
359
+ $continue_backup = 1;
360
+ continue;
361
+ } else {
362
+ continue;
363
+ }
364
+ }
365
+ // Increase script execution time-limit to 15 min for every table.
366
+ if ( !ini_get('safe_mode')) @set_time_limit(15*60);
367
+ // Create the SQL statements
368
+ $sql_file .= "# --------------------------------------------------------\n";
369
+ $sql_file .= "# Table: " . $this->bkpwp_backquote($curr_table) . "\n";
370
+ $sql_file .= "# --------------------------------------------------------\n";
371
+ $this->bkpwp_make_sql($path,$sql_file,$curr_table,$status,$log);
372
+
373
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": sql-dump for ".$curr_table." created ".$this->bkpwp_logtimestamp();
374
+ $this->bkpwp_write_log($log); unset($log['logfile']);
375
  }
 
376
  }
377
 
378
  function bkpwp_calculate($preset) {
403
  return date(get_option('date_format'))." ".date("H:i:s");
404
  }
405
 
406
+ function bkpwp_set_status($name,$type,$point) {
407
+ $new_backup_status = array("name" => $name, "time" => time(), "type" => $type, "point" => $point);
408
+ update_option("bkpwp_status",$new_backup_status);
409
+ }
410
+
411
+ function bkpwp_do_backup($preset,$status="") {
412
  $options = new BKPWP_OPTIONS();
413
  $log = array();
414
  // get the desired archive type from preset
415
+ if (!empty($status)) {
416
+ $preset = get_option("bkpwp_status_config");
417
+ }
418
+
419
+ // load the full backup preset if none is set
420
+ if (empty($preset)) {
421
+ $presets = new BKPWP_MANAGE();
422
+ $preset = $presets->bkpwp_get_preset("full backup");
423
+ }
424
+
425
  $type = $preset['bkpwp_preset_options']['bkpwp_archive_type'];
426
  $sqlonly = $preset['bkpwp_preset_options']['bkpwp_sql_only'];
427
  $options->excludelist = $preset['bkpwp_preset_options']['bkpwp_excludelist'];
428
+ update_option("bkpwp_status_config",$preset);
429
 
430
  $datestamp = date("Y-m-d-H-i-s");
431
+ // or: load the name of the unfinished backup's temporary directory
432
+ if (!empty($status)) {
433
+ $datestamp = $status;
434
+ if (!is_dir(get_option("bkpwppath")."/".$datestamp)) {
435
+ return;
436
+ }
437
+ }
438
  // temporary directory name
439
  $backup_tmp_dir = get_option("bkpwppath")."/".$datestamp;
440
 
456
 
457
  // count milliseconds
458
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress starting at","bkpwp")." ".$this->bkpwp_logtimestamp();
459
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress using Preset","bkpwp")." ".$log['preset'];
460
 
461
  // create a temporary directory
462
  if (!is_dir($backup_tmp_dir)) {
465
  } else {
466
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$backup_tmp_dir."' ".__("created","bkpwp");
467
  }
468
+ } else {
469
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$backup_tmp_dir."' ".__("exists. Proceeding with unfinished backup.","bkpwp");
470
  }
471
+ $this->bkpwp_write_log($log); unset($log['logfile']);
472
+
473
  if ($sqlonly != 1) {
474
  // subdirectory of wordpress files
475
  $wordpress_files = $backup_tmp_dir."/wordpress_files";
479
  } else {
480
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$wordpress_files."' ".__("created","bkpwp");
481
  }
482
+ $this->bkpwp_write_log($log); unset($log['logfile']);
483
  }
484
  }
485
 
486
+ $this->bkpwp_mysql($backup_tmp_dir,$status,$log);
487
 
488
+ if(!file_exists($backup_tmp_dir."/wordpress.sql")) {
489
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQL Dump could not be created.","bkpwp");
490
  } else {
491
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQL Dump created.","bkpwp");
492
  }
493
+ $this->bkpwp_write_log($log); unset($log['logfile']);
494
  if ($sqlonly != 1) {
495
  // create a temporary directory of files to backup
496
  $dir = bkpwp_conform_dir(ABSPATH);
497
  $files = $options->bkpwp_ls($dir);
498
  $files_copied = 0;
499
+ $batch = 0;
500
  $subdirs_created = 0;
501
  $i=1; // the sql at least
502
  foreach ($files as $f) {
503
  if (is_dir($f)) {
504
  if (!mkdir($wordpress_files.bkpwp_conform_dir($f, true))) {
505
+ if (!is_dir($wordpress_files.bkpwp_conform_dir($f, true))) {
506
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Failed to make directory","bkpwp").": ".$f;
507
+ }
508
  } else {
509
  $subdirs_created++;
510
  }
511
  } elseif(file_exists($f)) {
512
+ // where did we leave?
513
+ if (!empty($status) && empty($continue_backup)) {
514
+ $statusarr = get_option("bkpwp_status");
515
+ if ($statusarr['point'] == $f) {
516
+ $continue_backup = 1;
517
+ continue;
518
+ } else {
519
+ continue;
520
+ }
521
+ }
522
+
523
+ // set a marker ever 100
524
+ if ($batch == 100) {
525
+ $this->bkpwp_set_status($datestamp,'file',$f);
526
+ $batch = 0;
527
+ }
528
+ $files_copied++;
529
+ if (file_exists($wordpress_files.bkpwp_conform_dir($f, true))) {
530
+ unlink($wordpress_files.bkpwp_conform_dir($f, true));
531
+ }
532
+ // now copy...
533
  if (!copy($f,$wordpress_files.bkpwp_conform_dir($f, true))) {
534
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Failed to copy file","bkpwp").": ".$f;
535
+ }
536
+ $batch++;
537
+ //test
538
+ /*
539
+ if (empty($status) && ($files_copied == 135)) {
540
+ sleep(200);
541
  }
542
+ */
543
+
544
  }
545
  $i++;
546
  }
552
  $archive_backup->setOption("tmpDirectory",get_option("bkpwppath"));
553
  $archive_backup->extract($backup_tmp_dir,File_Archive::toArchive($backup_filename, File_Archive::toFiles()));
554
  if (!file_exists($backup_filename)) {
555
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Failed to create backup archive","bkpwp")." ".$backup_filename;
556
  } else {
557
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Archive File created/compressed successfully:","bkpwp")." ".$backup_filename;
558
  }
559
 
560
  $deleted_files_count = $this->bkpwp_rmdirtree($backup_tmp_dir);
561
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".count($deleted_files_count)." ".__("Temporary Directories and Files deleted successfully","bkpwp");
562
+
563
  $deleted_oldarchives_count = $this->bkpwp_delete_old();
564
  if ($deleted_oldarchives_count > 0) {
565
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$deleted_oldarchives_count." ".__("Old BackUpWordPress Archives deleted successfully","bkpwp");
567
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("No old BackUpWordPress Archives to delete","bkpwp");
568
  }
569
 
570
+ $deleted_oldlogfiles_count = $this->bkpwp_delete_oldlogs();
571
+ if ($deleted_oldlogfiles_count > 0) {
572
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$deleted_oldlogfiles_count." ".__("Old BackUpWordPress Log Files deleted successfully","bkpwp");
573
+ } else {
574
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("No old BackUpWordPress Log Files to delete","bkpwp");
575
+ }
576
+
577
 
578
  $time_end = microtime(true);
579
  $time = $time_end - $time_start;
581
  $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress was running for","bkpwp")." ".round($time,2)." ".__("Seconds","bkpwp");
582
 
583
  // write the log
584
+ $this->bkpwp_write_log($log); unset($log['logfile']);
585
+
586
+ // dont need the status anymore
587
+ delete_option("bkpwp_status");
588
+ delete_option("bkpwp_status_config");
589
+
590
+
591
  $backup = array("file" => $backup_filename,
592
  "filename" => $backup_filename_short);
593
  // start the output
649
  return true;
650
  }
651
 
652
+ function bkpwp_write_sql($sqldir,$sql) {
653
+ $sqlname = $sqldir."/wordpress.sql";
654
+ // actually write the sql file
655
+ if ($this->is__writable($sqlname)) {
656
+ if (!$handle = fopen($sqlname, "a")) {
657
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQLfile could not be opened for writing: ","bkpwp").$sqlname;
658
+ $this->bkpwp_write_log($log); unset($log['logfile']);
659
+ return;
660
+ }
661
+ if (!fwrite($handle, $sql)) {
662
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQLfile not writable: ","bkpwp").$sqlname;
663
+ $this->bkpwp_write_log($log); unset($log['logfile']);
664
+ return;
665
+ }
666
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("successfully written to SQLfile: ","bkpwp").$sqlname;
667
+ $this->bkpwp_write_log($log); unset($log['logfile']);
668
+ fclose($handle);
669
+ return true;
670
+ } else {
671
+ $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQLfile not writable: ","bkpwp").$sqlname;
672
+ $this->bkpwp_write_log($log); unset($log['logfile']);
673
+ }
674
+ }
675
+
676
  function bkpwp_write_log($log,$return="") {
677
  if (!is_array($log)) { return; }
678
  $logdir = get_option("bkpwppath")."/logs";
681
  }
682
  $logname = $logdir."/".$log['filename'].".txt";
683
  $logfile = "";
684
+ if (!file_exists($logname)) {
685
+ if (!empty($log['preset'])) {
686
+ $logfile .= "Preset: ".$log['preset']."\n";
687
+ }
688
+ if (!empty($log['schedule'])) {
689
+ $logfile .= "Schedule: ".$log['schedule']."\n";
690
+ }
691
  }
692
  if (is_array($log['logfile'])) {
693
  foreach($log['logfile'] as $l) {
701
  if ($this->is__writable($logname)) {
702
  if (!$handle = fopen($logname, "a")) {
703
  return __("Logfile could not be opened for writing: ","bkpwp").$logname;
 
704
  }
705
  if (!fwrite($handle, $logfile)) {
706
  return __("Logfile not writable: ","bkpwp").$logname;
 
707
  }
708
  fclose($handle);
709
  return true;
762
  }
763
  return false;
764
  }
765
+
766
+ function bkpwp_delete_oldlogs() {
767
+ $backups = new BKPWP_MANAGE();
768
+ $unlinkcount = 0;
769
+ $files = $backups->bkpwp_get_logs();
770
+ $num = get_option('bkpwp_max_backups')*10;
771
+ if (count($files) <= $num) {
772
+ return;
773
+ } else {
774
+ $i = 1;
775
+ foreach($files as $f) {
776
+ if ($i > $num) {
777
+ unlink($f['file']);
778
+ $unlinkcount++;
779
+ }
780
+ $i++;
781
+ }
782
+ }
783
+ if ($unlinkcount > 0) {
784
+ return $unlinkcount;
785
+ }
786
+ return false;
787
+ }
788
 
789
  }
790
 
973
  array_multisort($filename, SORT_DESC, $files);
974
  return $files;
975
  }
976
+
977
+ function bkpwp_get_logs() {
978
+ $files = array();
979
+ $bkpwppath = get_option("bkpwppath")."/logs";
980
+ if (!is_writable($bkpwppath)) {
981
+ return;
982
+ }
983
+ if ($handle = opendir($bkpwppath)) {
984
+ while (false !== ($file = readdir($handle))) {
985
+ if (($file != ".") && ($file != "..") && !is_dir($bkpwppath."/".$file)) {
986
+ $files[] = array("file" => $bkpwppath."/".$file,
987
+ "filename" => $file);
988
+ }
989
+ }
990
+ closedir($handle);
991
+ }
992
+ if (count($files) < 1) { return; }
993
+ foreach ($files as $key => $row) {
994
+ $filename[$key] = $row['filename'];
995
+ }
996
+ array_multisort($filename, SORT_DESC, $files);
997
+ return $files;
998
+ }
999
  }
1000
 
1001
 
bkpwp-classes/options.php CHANGED
@@ -73,7 +73,7 @@ class BKPWP_OPTIONS {
73
  } else {
74
  $this->bkpwp_update_option("bkpwppath",$_REQUEST['bkpwppath']);
75
  $msg = __("Directory did not exist but this script was able to create it.","bkpwp");
76
- bkpwp_display_message($msg);
77
  }
78
  } elseif (!is_writable($_REQUEST['bkpwppath'])) {
79
  $this->bkpwp_delete_option("bkpwppath");
73
  } else {
74
  $this->bkpwp_update_option("bkpwppath",$_REQUEST['bkpwppath']);
75
  $msg = __("Directory did not exist but this script was able to create it.","bkpwp");
76
+ bkpwp_display_message($msg." <a href=\"admin.php?page=".$_REQUEST['page']."\">".__("Continue","bkpwp")." &raquo;</a>");
77
  }
78
  } elseif (!is_writable($_REQUEST['bkpwppath'])) {
79
  $this->bkpwp_delete_option("bkpwppath");
bkpwp-classes/schedule.php CHANGED
@@ -104,8 +104,7 @@ class BKPWP_SCHEDULE {
104
  "created" => date("Y-m-d-H-i-s"));
105
  $schedules[] = $test;
106
  if (!wp_next_scheduled('bkpwp_schedule_bkpwp_hook', $test)) {
107
- //wp_schedule_single_event(time()+30, 'bkpwp_schedule_bkpwp_hook', $test);
108
- wp_schedule_event(time()+30, 'bkpwp_30secs', 'bkpwp_schedule_bkpwp_hook',$test);
109
  update_option("bkpwp_schedules",$schedules);
110
  return true;
111
  } else {
104
  "created" => date("Y-m-d-H-i-s"));
105
  $schedules[] = $test;
106
  if (!wp_next_scheduled('bkpwp_schedule_bkpwp_hook', $test)) {
107
+ wp_schedule_single_event(time()+30, 'bkpwp_schedule_bkpwp_hook', $test);
 
108
  update_option("bkpwp_schedules",$schedules);
109
  return true;
110
  } else {
bkpwp-pages/bkpwp_manage_backups.php CHANGED
@@ -248,7 +248,7 @@ if (count($backup_archives) < 1) {
248
  preset = "full backup";
249
  <?php } ?>
250
  document.getElementById('bkpwp_manage_backups_newrow').style.display="table-row";
251
- document.getElementById('bkpwp_manage_backups_newrow').innerHTML="<th scope=\"row\"><?php echo date(get_option('date_format'))." ".date("H:i"); ?></th><td colspan=\"<?php if (!$backups->options->bkpwp_easy_mode()) { echo "8"; } else { echo "3"; } ?>\"><img src='<?php bloginfo("url"); ?>/wp-content/plugins/backupwordpress/images/loading.gif' /> <?php _e("Creating backup. Please wait."); ?></td>";
252
  sajax_target_id = 'bkpwp_manage_backups_newrow';
253
  x_bkpwp_ajax_create(preset,'');
254
  }
@@ -272,6 +272,68 @@ if (count($backup_archives) < 1) {
272
  document.getElementById('bkpwp_action_title').innerHTML="<h4>" + str + "</h4>";
273
  }
274
  </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  <div id="bkpwp_actions" style="display:none;">
276
  <div id="bkpwp_action_title"></div>
277
  <div id="bkpwp_action_buffer"></div>
@@ -294,7 +356,8 @@ if (count($backup_archives) < 1) {
294
  <button class="button" onclick="do_create(); sajax_target_id = ''; return false;"><?php _e("BackUp WordPress Now","bkpwp"); ?> &raquo;</button>
295
  <?php if (!$backups->options->bkpwp_easy_mode()) { ?>
296
  <button class="button" onclick="bkpwp_js_loading('<?php _e("Calculating used disk space","bkpwp"); ?>'); calculate(); sajax_target_id = ''; return false;"><?php _e("Recalculate Used Disk Space","bkpwp"); ?> &raquo;</button>
297
- <?php } ?>
 
298
 
299
 
300
  <?php
@@ -309,6 +372,7 @@ if (count($backup_archives) < 1) {
309
  if (!empty($_REQUEST['bkpwp_restore'])) {
310
  bkpwp_restore();
311
  }
 
312
  ?>
313
 
314
  <br /><br />
248
  preset = "full backup";
249
  <?php } ?>
250
  document.getElementById('bkpwp_manage_backups_newrow').style.display="table-row";
251
+ document.getElementById('bkpwp_manage_backups_newrow').innerHTML="<th scope=\"row\"><?php echo date(get_option('date_format'))." ".date("H:i"); ?></th><td colspan=\"<?php if (!$backups->options->bkpwp_easy_mode()) { echo "8"; } else { echo "3"; } ?>\"><img src='<?php bloginfo("url"); ?>/wp-content/plugins/backupwordpress/images/loading.gif' /> <?php _e("Creating backup. Please wait."); ?> <?php _e("If nothing happens within 30 Seconds, reload this page manually."); ?></td>";
252
  sajax_target_id = 'bkpwp_manage_backups_newrow';
253
  x_bkpwp_ajax_create(preset,'');
254
  }
272
  document.getElementById('bkpwp_action_title').innerHTML="<h4>" + str + "</h4>";
273
  }
274
  </script>
275
+ <?php
276
+
277
+ if (bkpwp_check_unfinished_backup()) {
278
+ $status = get_option("bkpwp_status");
279
+ ?>
280
+ <div id="message" class="updated fade">
281
+ <p>
282
+ <?php
283
+ _e("Last Action of BackUpWordPress: ","bkpwp");
284
+ _e("Creating Backup Archive: ","bkpwp");
285
+ echo " ".$status['name'].". ";
286
+ if ($status['type'] == "sqltable") {
287
+ _e("Saving Database Table ","bkpwp");
288
+ echo $status['point']." ";
289
+ } elseif ($status['type'] == "sqltable_row") {
290
+ $d = explode("-",$status['point']);
291
+ _e("Saving data rows from table ","bkpwp");
292
+ echo $d[0].". ";
293
+ _e("Currently saving entries from row number","bkpwp");
294
+ echo " ".$d[1]." ";
295
+ } elseif ($status['type'] == "file") {
296
+ _e("Saving File ","bkpwp");
297
+ echo str_replace(get_option("bkpwp_path"),"",$status['point'])." ";
298
+ }
299
+ _e("at ","bkpwp");
300
+ echo date(get_option('date_format'),$status['time'])." ".date("H:i:s",$status['time'])."</p><p>";
301
+
302
+ $sincet = bkpwp_date_diff($status['time'],time());
303
+ $since .= $sincet['days']." ".__("days","bkpwp")." ";
304
+ $since .= $sincet['hours']." ".__("hours","bkpwp")." ";
305
+ $since .= $sincet['minutes']." ".__("minutes","bkpwp")." ";
306
+ $since .= $sincet['seconds']." ".__("seconds","bkpwp");
307
+ _e("BackUpWordPress did not proceed with the current task since","bkpwp");
308
+ echo " ".$since;
309
+ ?>
310
+ </p>
311
+ <p>
312
+ <?php
313
+ if (($status['time']+30) < time()) {
314
+ _e("BackUpWordPress tries to proceed with this unfinished backup.");
315
+ echo " ";
316
+ _e("On a WordPress website with low traffic, reload the page a few times, to trigger the action.");
317
+ echo "</p><p>";
318
+ _e("If nothing happens for more than 5 minutes, deaktivate the plugin, install the newest version and activate again.","bkpwp");
319
+ } else {
320
+ _e("Please be patient.","bkpwp");
321
+ }
322
+ ?>
323
+ </p>
324
+ <p>
325
+ <?php
326
+ /*
327
+ echo __("Your server's configuration allows scripts to run for a maximum of","bkpwp")." ";
328
+ echo ini_get("max_execution_time");
329
+ echo " ".__("seconds.","bkpwp");
330
+ */
331
+ ?>
332
+ </p>
333
+ </div>
334
+ <?php
335
+ } else {
336
+ ?>
337
  <div id="bkpwp_actions" style="display:none;">
338
  <div id="bkpwp_action_title"></div>
339
  <div id="bkpwp_action_buffer"></div>
356
  <button class="button" onclick="do_create(); sajax_target_id = ''; return false;"><?php _e("BackUp WordPress Now","bkpwp"); ?> &raquo;</button>
357
  <?php if (!$backups->options->bkpwp_easy_mode()) { ?>
358
  <button class="button" onclick="bkpwp_js_loading('<?php _e("Calculating used disk space","bkpwp"); ?>'); calculate(); sajax_target_id = ''; return false;"><?php _e("Recalculate Used Disk Space","bkpwp"); ?> &raquo;</button>
359
+ <?php }
360
+ } ?>
361
 
362
 
363
  <?php
372
  if (!empty($_REQUEST['bkpwp_restore'])) {
373
  bkpwp_restore();
374
  }
375
+
376
  ?>
377
 
378
  <br /><br />
functions.php CHANGED
@@ -30,6 +30,8 @@ function bkpwp_exit() {
30
  delete_option("bkpwp_automail_maxsize");
31
  delete_option("bkpwp_automail_address");
32
  delete_option("bkpwp_automail_receiver");
 
 
33
  }
34
 
35
  function bkpwp_setup() {
@@ -83,10 +85,70 @@ $options = new BKPWP_OPTIONS();
83
  </div>
84
  <?php
85
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  function bkpwp_latest_activity() {
88
  echo "<h3>".__("BackUpWordPress","bkpwp")." <a href=\"admin.php?page=backupwordpress/backupwordpress.php\">&raquo;</a></h3>";
89
  echo "<p><a href=\"http://wordpress.designpraxis.at/\">".__("Check for a new version of BackUpWordPress!","bkpwp")."</a></p>";
 
 
 
90
  echo "<p><b>".__("Latest Backups","bkpwp")."</b>:</p>";
91
  $backup = new BKPWP_MANAGE();
92
  $backups = $backup->bkpwp_get_backups();
@@ -249,6 +311,11 @@ function bkpwp_more_reccurences($recc) {
249
  return $recc;
250
  }
251
 
 
 
 
 
 
252
  function bkpwp_schedule_bkpwp($options) {
253
 
254
  $backup = new BKPWP_BACKUP();
30
  delete_option("bkpwp_automail_maxsize");
31
  delete_option("bkpwp_automail_address");
32
  delete_option("bkpwp_automail_receiver");
33
+ delete_option("bkpwp_status");
34
+ delete_option("bkpwp_status_config");
35
  }
36
 
37
  function bkpwp_setup() {
85
  </div>
86
  <?php
87
  }
88
+
89
+ function bkpwp_check_unfinished_backup() {
90
+ $status = get_option("bkpwp_status");
91
+ if (!empty($status)) {
92
+ if (!is_dir(get_option("bkpwppath")."/".$status['name'])) {
93
+ return false;
94
+ }
95
+ if (($status['time']-5) < time()) {
96
+ return true;
97
+ }
98
+ }
99
+ return false;
100
+ }
101
+
102
+ function bkpwp_proceed_unfinished() {
103
+ // no unfinished backup
104
+ if(!bkpwp_check_unfinished_backup()) {
105
+ return;
106
+ }
107
+
108
+ $status = get_option("bkpwp_status");
109
+
110
+ // no working directory
111
+ if (!is_dir(get_option("bkpwppath")."/".$status['name'])) {
112
+ return;
113
+ }
114
+ // wait a little
115
+ if (($status['time']+30) > time()) {
116
+ return;
117
+ }
118
+
119
+ // okay, schedule that one for finishing up
120
+ if (!wp_next_scheduled('bkpwp_finish_bkpwp_hook', $status)) {
121
+ wp_schedule_single_event(time(), 'bkpwp_finish_bkpwp_hook', $status);
122
+ return;
123
+ }
124
+ }
125
+
126
+ function bkpwp_date_diff($earlierDate, $laterDate) {
127
+ //returns an array of numeric values representing days, hours, minutes & seconds respectively
128
+ $ret=array('days'=>0,'hours'=>0,'minutes'=>0,'seconds'=>0);
129
+
130
+ $totalsec = $laterDate - $earlierDate;
131
+ if ($totalsec >= 86400) {
132
+ $ret['days'] = floor($totalsec/86400);
133
+ $totalsec = $totalsec % 86400;
134
+ }
135
+ if ($totalsec >= 3600) {
136
+ $ret['hours'] = floor($totalsec/3600);
137
+ $totalsec = $totalsec % 3600;
138
+ }
139
+ if ($totalsec >= 60) {
140
+ $ret['minutes'] = floor($totalsec/60);
141
+ }
142
+ $ret['seconds'] = $totalsec % 60;
143
+ return $ret;
144
+ }
145
 
146
  function bkpwp_latest_activity() {
147
  echo "<h3>".__("BackUpWordPress","bkpwp")." <a href=\"admin.php?page=backupwordpress/backupwordpress.php\">&raquo;</a></h3>";
148
  echo "<p><a href=\"http://wordpress.designpraxis.at/\">".__("Check for a new version of BackUpWordPress!","bkpwp")."</a></p>";
149
+ if (bkpwp_check_unfinished_backup()) {
150
+ echo "<span style=\"color:red\">".__("You have unfinished Backups!","bkpwp")." <a href=\"admin.php?page=backupwordpress/backupwordpress.php\">".__("Please finish them manually","bkpwp")." &raquo;</a></span>";
151
+ }
152
  echo "<p><b>".__("Latest Backups","bkpwp")."</b>:</p>";
153
  $backup = new BKPWP_MANAGE();
154
  $backups = $backup->bkpwp_get_backups();
311
  return $recc;
312
  }
313
 
314
+ function bkpwp_finish_bkpwp($status) {
315
+ $backup = new BKPWP_BACKUP();
316
+ $backup->bkpwp_do_backup("",$status);
317
+ }
318
+
319
  function bkpwp_schedule_bkpwp($options) {
320
 
321
  $backup = new BKPWP_BACKUP();
interface.php DELETED
@@ -1,49 +0,0 @@
1
- <?php
2
-
3
- class BKPWP_INIT {
4
-
5
- function BKPWP_INIT() {
6
- }
7
-
8
- function bkpwp_check_prerequisites() {
9
- if (!current_user_can('manage bkpwp')) {
10
- return false;
11
- }
12
-
13
- $bkpwppath = get_option("bkpwppath");
14
- if (!is_writable($bkpwppath)) {
15
- $notconfigured = 1;
16
- }
17
- if (!isset($notconfigured)) {
18
- return false;
19
- } else {
20
- return true;
21
- }
22
- }
23
- }
24
-
25
- class BKPWP_INTERFACE {
26
-
27
- function BKPWP_INTERFACE() {
28
- }
29
-
30
- function menu() {
31
- $init = new BKPWP_INIT();
32
- $options = new BKPWP_OPTIONS();
33
- if($init->bkpwp_check_prerequisites()) {
34
- add_menu_page(__("BackUpWordPress","bkpwp"), __("BackUpWordPress","bkpwp"), 9, 'backupwordpress/backupwordpress.php', 'bkpwp_load_menu_page');
35
- add_submenu_page('backupwordpress/backupwordpress.php', __("Options","bkpwp"), __("Options","bkpwp"), 9, 'bkpwp_options', 'bkpwp_load_menu_page' );
36
- add_submenu_page('backupwordpress/backupwordpress.php', __("Help","bkpwp"), __("Help","bkpwp"), 9, 'bkpwp_help', 'bkpwp_load_menu_page' );
37
- } else {
38
- add_menu_page(__("BackUpWordPress","bkpwp"), __("BackUpWordPress","bkpwp"), 9, 'backupwordpress/backupwordpress.php', 'bkpwp_load_menu_page');
39
- if(!$options->bkpwp_easy_mode()) {
40
- add_submenu_page('backupwordpress/backupwordpress.php', __("Backup Presets","bkpwp"), __("Backup Presets","bkpwp"), 9, 'bkpwp_manage_presets', 'bkpwp_load_menu_page');
41
- add_submenu_page('backupwordpress/backupwordpress.php', __("Scheduled Backups","bkpwp"), __("Scheduled Backups","bkpwp"), 9, 'bkpwp_schedule', 'bkpwp_load_menu_page');
42
- }
43
- add_submenu_page('backupwordpress/backupwordpress.php', __("Options","bkpwp"), __("Options","bkpwp"), 9, 'bkpwp_options', 'bkpwp_load_menu_page' );
44
- add_submenu_page('backupwordpress/backupwordpress.php', __("Help","bkpwp"), __("Help","bkpwp"), 9, 'bkpwp_help', 'bkpwp_load_menu_page' );
45
- }
46
- }
47
- }
48
-
49
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
manage_backups.php DELETED
@@ -1,870 +0,0 @@
1
- <?php
2
-
3
-
4
-
5
- class BKPWP_BACKUP_ARCHIVE {
6
-
7
- function BKPWP_BACKUP_ARCHIVE() {
8
- }
9
-
10
- function bkpwp_view_backup_info($backup,$values="") {
11
- $ret = "";
12
- $backup = base64_decode($backup);
13
- $ret .= "<h5>".__("BackUp Archive Path and Filename","bkpwp")."</h5>";
14
- $ret .= $backup;
15
- $ret .= "<h5>".__("BackUp Logfile","bkpwp")."</h5>";
16
- $backuplog = eregi_replace(get_option("bkpwppath"),get_option("bkpwppath")."/logs",$backup).".txt";
17
- if (!empty($values)) {
18
- $values = array();
19
- if(file_exists($backup)) {
20
- $values['filesize'] = bkpwp_size_readable(filesize($backup));
21
- } else {
22
- $values['filesize'] = $backup." ".__("does not exist.","bkpwp");
23
- }
24
- if(file_exists($backuplog)) {
25
- $lines = file($backuplog);
26
- foreach($lines as $line_num => $line) {
27
- if (eregi("Preset:",$line)) {
28
- $p=explode(":",$line);
29
- $values['preset'] = $p[1];
30
- }
31
- if (eregi("Schedule:",$line)) {
32
- $values['runby'] = __("scheduled","bkpwp");
33
- }
34
- }
35
- }
36
- return $values;
37
- }
38
- if(file_exists($backuplog)) {
39
- $lines = file($backuplog);
40
- foreach($lines as $line_num => $line) {
41
- $ret .= __("Line","bkpwp")."# ".sprintf("%02d",$line_num)." ".$line."<br />";
42
- }
43
- } else {
44
- $ret = __("BackUpWordPress Logfile does not exist:","bkpwp")." ".$backuplog;
45
- }
46
- return $ret;
47
- }
48
-
49
- function bkpwp_get_backup_row($f,$alternate) {
50
- $backup->options = new BKPWP_OPTIONS();
51
- $info = new BKPWP_BACKUP_ARCHIVE();
52
- $info = $info->bkpwp_view_backup_info(base64_encode($f['file']),1);
53
- //if (!file_exists($f['file'])) { return; }
54
- $type = $backup->options->bkpwp_get_backup_type($f['filename']);
55
- if ($alternate != "new_row") {
56
- ?>
57
- <tr id="bkpwp_manage_backups_row_<?php echo base64_encode($f['file']); ?>" class="bkpwp_manage_backups_row <?php echo $alternate; ?>">
58
- <?php
59
- }
60
- ?>
61
- <th scope="row"><?php
62
- echo date(get_option('date_format'),filemtime($f['file']))." ".date("H:i",filemtime($f['file']));
63
- ?></th>
64
- <?php if (!$backup->options->bkpwp_easy_mode()) { ?>
65
- <td>
66
- <?php
67
- echo " <b>".$type."</b>";
68
- ?>
69
- </td>
70
- <td>
71
- <?php
72
- echo " <b>".$info['preset']."</b>";
73
- if (!empty($info['runby'])) {
74
- echo " - ".$info['runby'];
75
- }
76
- ?>
77
- </td>
78
- <?php } ?>
79
- <td>
80
- <?php
81
- echo bkpwp_size_readable(filesize($f['file']))."";
82
- ?>
83
- </td>
84
- <td style="text-align: center;">
85
- <?php
86
- echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_download=".base64_encode($f['file'])."\">".__("download","bkpwp")."</a>";
87
- ?>
88
- </td>
89
- <?php if (!$backup->options->bkpwp_easy_mode()) { ?>
90
- <td style="text-align: center;">
91
- <?php
92
- echo " <a href=\"javascript:void(0)\"
93
- onclick=\"bkpwp_js_loading('".__("View Backup Information","bkpwp")."');
94
- sajax_target_id = 'bkpwp_action_buffer';
95
- x_bkpwp_ajax_view_backup('".base64_encode($f['file'])."','');
96
- sajax_target_id = '';\">".__("view","bkpwp")."</a>";
97
- ?>
98
- </td>
99
- <td style="text-align: center;">
100
- <?php
101
- echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_mail=".base64_encode($f['file'])."\">".__("mail","bkpwp")."</a>";
102
- ?>
103
- </td>
104
- <?php } ?>
105
- <td style="text-align: center;">
106
- <?php
107
- echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_restore=".base64_encode($f['file'])."\">".__("restore","bkpwp")."</a>";
108
- ?>
109
- </td>
110
- <?php if (!$backup->options->bkpwp_easy_mode()) { ?>
111
- <td style="text-align: center;">
112
- <?php
113
- echo " <a href=\"admin.php?page=backupwordpress/backupwordpress.php&amp;bkpwp_delete=".base64_encode($f['file'])."\">".__("delete","bkpwp")."</a>";
114
- ?>
115
- </td>
116
- <?php } ?>
117
- <?php
118
- if ($alternate != "new_row") {
119
- ?>
120
- </tr>
121
- <?php
122
- }
123
- }
124
-
125
- }
126
-
127
- class BKPWP_BACKUP {
128
-
129
- function BKPWP_BACKUP() {
130
- }
131
-
132
- function bkpwp_backquote($a_name)
133
- {
134
- /*
135
- Add backqouotes to tables and db-names in
136
- SQL queries. Taken from phpMyAdmin.
137
- */
138
- if (!empty($a_name) && $a_name != '*') {
139
- if (is_array($a_name)) {
140
- $result = array();
141
- reset($a_name);
142
- while(list($key, $val) = each($a_name)) {
143
- $result[$key] = '`' . $val . '`';
144
- }
145
- return $result;
146
- } else {
147
- return '`' . $a_name . '`';
148
- }
149
- } else {
150
- return $a_name;
151
- }
152
- } // function backquote($a_name, $do_it = TRUE)
153
-
154
- function bkpwp_make_sql($table,$log)
155
- {
156
- /*
157
- Reads the Database table in $table and creates
158
- SQL Statements for recreating structure and data
159
- Taken partially from phpMyAdmin and partially from
160
- Alain Wolf, Zurich - Switzerland
161
- Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
162
- */
163
-
164
- $sql_statements = "";
165
-
166
- // Add SQL statement to drop existing table
167
- $sql_statements .= "\n";
168
- $sql_statements .= "\n";
169
- $sql_statements .= "#\n";
170
- $sql_statements .= "# Delete any existing table " . $this->bkpwp_backquote($table) . "\n";
171
- $sql_statements .= "#\n";
172
- $sql_statements .= "\n";
173
- $sql_statements .= "DROP TABLE IF EXISTS " . $this->bkpwp_backquote($table) . ";\n";
174
-
175
- // Table structure
176
-
177
- // Comment in SQL-file
178
- $sql_statements .= "\n";
179
- $sql_statements .= "\n";
180
- $sql_statements .= "#\n";
181
- $sql_statements .= "# Table structure of table " . $this->bkpwp_backquote($table) . "\n";
182
- $sql_statements .= "#\n";
183
- $sql_statements .= "\n";
184
-
185
- // Get table structure
186
- $query = "SHOW CREATE TABLE " . $this->bkpwp_backquote($table);
187
- $result = mysql_query($query, $GLOBALS["db_connect"]);
188
- if ($result == FALSE) {
189
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Error getting table structure of ","bkpwp").$table."! ".mysql_errno() . ": " . mysql_error()." ".$this->bkpwp_logtimestamp();
190
- $this->bkpwp_write_log($log);
191
- } else {
192
- if (mysql_num_rows($result) > 0) {
193
- $sql_create_arr = mysql_fetch_array($result);
194
- $sql_statements .= $sql_create_arr[1];
195
- }
196
- mysql_free_result($result);
197
- $sql_statements .= " ;";
198
- } // ($result == FALSE)
199
-
200
- // Table data contents
201
-
202
- // Get table contents
203
- $query = "SELECT * FROM " . $this->bkpwp_backquote($table);
204
- $result = mysql_query($query, $GLOBALS["db_connect"]);
205
- if ($result == FALSE) {
206
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Error getting records of ","bkpwp").$table."! ".mysql_errno() . ": " . mysql_error()." ".$this->bkpwp_logtimestamp();
207
- $this->bkpwp_write_log($log);
208
- } else {
209
- $fields_cnt = mysql_num_fields($result);
210
- $rows_cnt = mysql_num_rows($result);
211
- } // if ($result == FALSE)
212
-
213
- // Comment in SQL-file
214
- $sql_statements .= "\n";
215
- $sql_statements .= "\n";
216
- $sql_statements .= "#\n";
217
- $sql_statements .= "# Data contents of table " . $table . " (" . $rows_cnt . " records)\n";
218
- $sql_statements .= "#\n";
219
-
220
- // Checks whether the field is an integer or not
221
- for ($j = 0; $j < $fields_cnt; $j++) {
222
- $field_set[$j] = $this->bkpwp_backquote(mysql_field_name($result, $j));
223
- $type = mysql_field_type($result, $j);
224
- if ($type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' ||
225
- $type == 'bigint' ||$type == 'timestamp') {
226
- $field_num[$j] = TRUE;
227
- } else {
228
- $field_num[$j] = FALSE;
229
- }
230
- } // end for
231
-
232
- // Sets the scheme
233
- $entries = 'INSERT INTO ' . $this->bkpwp_backquote($table) . ' VALUES (';
234
- $search = array("\x00", "\x0a", "\x0d", "\x1a"); //\x08\\x09, not required
235
- $replace = array('\0', '\n', '\r', '\Z');
236
- $current_row = 0;
237
- while ($row = mysql_fetch_row($result)) {
238
- $current_row++;
239
- for ($j = 0; $j < $fields_cnt; $j++) {
240
- if (!isset($row[$j])) {
241
- $values[] = 'NULL';
242
- } else if ($row[$j] == '0' || $row[$j] != '') {
243
- // a number
244
- if ($field_num[$j]) {
245
- $values[] = $row[$j];
246
- }
247
- else {
248
- $values[] = "'" . str_replace($search, $replace, $this->bkpwp_sql_addslashes($row[$j])) . "'";
249
- } //if ($field_num[$j])
250
- } else {
251
- $values[] = "''";
252
- } // if (!isset($row[$j]))
253
- } // for ($j = 0; $j < $fields_cnt; $j++)
254
- $sql_statements .= " \n" . $entries . implode(', ', $values) . ') ;';
255
- unset($values);
256
- } // while ($row = mysql_fetch_row($result))
257
- mysql_free_result($result);
258
-
259
- // Create footer/closing comment in SQL-file
260
- $sql_statements .= "\n";
261
- $sql_statements .= "#\n";
262
- $sql_statements .= "# End of data contents of table " . $table . "\n";
263
- $sql_statements .= "# --------------------------------------------------------\n";
264
- $sql_statements .= "\n";
265
- return $sql_statements;
266
- } //function make_sql($table)
267
-
268
- function bkpwp_sql_addslashes($a_string = '', $is_like = FALSE)
269
- {
270
- /*
271
- Better addslashes for SQL queries.
272
- Taken from phpMyAdmin.
273
- */
274
- if ($is_like) {
275
- $a_string = str_replace('\\', '\\\\\\\\', $a_string);
276
- } else {
277
- $a_string = str_replace('\\', '\\\\', $a_string);
278
- }
279
- $a_string = str_replace('\'', '\\\'', $a_string);
280
-
281
- return $a_string;
282
- } // function sql_addslashes($a_string = '', $is_like = FALSE)
283
-
284
- function bkpwp_mysql($path,$log) {
285
- if (!$GLOBALS['db_connect'] = @mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD)) {
286
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Could not connect to MySQL server! ","bkpwp"). mysql_error()." ".$this->bkpwp_logtimestamp();
287
- $this->bkpwp_write_log($log);
288
- }
289
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("MySQL server connected successfully ","bkpwp")." ".$this->bkpwp_logtimestamp();
290
- $this->bkpwp_write_log($log);
291
- mysql_select_db(DB_NAME,$GLOBALS['db_connect']);
292
- $file_name = "wordpress.sql";
293
- //Begin new backup of MySql
294
- $tables = mysql_list_tables(DB_NAME);
295
- if (!isset($tables) > 0) {
296
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Could not select db ","bkpwp").DB_NAME." ".$this->bkpwp_logtimestamp();
297
- $this->bkpwp_write_log($log);
298
- }
299
- $sql_file = "# WordPress : ".get_bloginfo("url")." MySQL database backup\n";
300
- $sql_file .= "#\n";
301
- $sql_file .= "# Generated: " . date("l j. F Y H:i T") . "\n";
302
- $sql_file .= "# Hostname: " . DB_HOST . "\n";
303
- $sql_file .= "# Database: " . $this->bkpwp_backquote(DB_NAME) . "\n";
304
- $sql_file .= "# --------------------------------------------------------\n";
305
- for ($i = 0; $i < mysql_num_rows($tables); $i++) {
306
- $curr_table = mysql_tablename($tables, $i);
307
- // Increase script execution time-limit to 15 min for every table.
308
- if ( !ini_get('safe_mode')) @set_time_limit(15*60);
309
- // Create the SQL statements
310
- $sql_file .= "# --------------------------------------------------------\n";
311
- $sql_file .= "# Table: " . $this->bkpwp_backquote($curr_table) . "\n";
312
- $sql_file .= "# --------------------------------------------------------\n";
313
- $sql_file .= $this->bkpwp_make_sql($curr_table,$log);
314
- }
315
- $cachefp = fopen($path."/".$file_name, "w");
316
- fwrite($cachefp, $sql_file);
317
- if (file_exists($path."/".$file_name)) {
318
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$path."/".$file_name." created ".$this->bkpwp_logtimestamp();
319
- $this->bkpwp_write_log($log);
320
- return true;
321
- } else {
322
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$path."/".$file_name." could not be created ".$this->bkpwp_logtimestamp();
323
- $this->bkpwp_write_log($log);
324
- }
325
- return false;
326
- }
327
-
328
- function bkpwp_calculate($preset) {
329
- if ($preset['bkpwp_preset_options']['bkpwp_sql_only'] == 1) {
330
- $ret = "<p>".__("Database Only Backup with this Preset. No Disk Files will be backed up.","bkpwp")."</p>";
331
- return $ret;
332
- }
333
- $options = new BKPWP_OPTIONS();
334
- clearstatcache(); //get rid of cached filesizes...
335
- $dir = bkpwp_conform_dir(ABSPATH);
336
- $options->excludelist = $preset['bkpwp_preset_options']['bkpwp_excludelist'];
337
- $files = $options->bkpwp_ls($dir);
338
- $filesize = 0;
339
- foreach($files as $f) {
340
- $str = bkpwp_conform_dir($f,true);
341
- $thisf = filesize($f);
342
- $filesize = $filesize+$thisf;
343
- //echo $str.": ".bkpwp_size_readable($thisf)." (".bkpwp_size_readable($filesize).")\\n";
344
- }
345
- update_option("bkpwp_calculation",bkpwp_size_readable($filesize));
346
- $ret = "<p>".__("Your Wordpress files backuped with preset","bkpwp")." <b>".$preset['bkpwp_preset_name']."</b> ".__(" use","bkpwp")." ";
347
- $ret .= "<b>".bkpwp_size_readable($filesize)."</b> ".__("of disk space.","bkpwp")."<br />";
348
- $ret .= "".__("Depending on the type of these files, the resulting Backup Archive filesize can be reduced by more than 70%.","bkpwp")."</p>";
349
- return $ret;
350
- }
351
-
352
- function bkpwp_logtimestamp() {
353
- return date(get_option('date_format'))." ".date("H:i:s");
354
- }
355
-
356
- function bkpwp_do_backup($preset) {
357
- $options = new BKPWP_OPTIONS();
358
- $log = array();
359
- // get the desired archive type from preset
360
- $type = $preset['bkpwp_preset_options']['bkpwp_archive_type'];
361
- $sqlonly = $preset['bkpwp_preset_options']['bkpwp_sql_only'];
362
- $options->excludelist = $preset['bkpwp_preset_options']['bkpwp_excludelist'];
363
-
364
- $datestamp = date("Y-m-d-H-i-s");
365
- // temporary directory name
366
- $backup_tmp_dir = get_option("bkpwppath")."/".$datestamp;
367
-
368
- // filename for the backup archive
369
- if ($sqlonly == 1) {
370
- $backup_filename .= "-sql";
371
- } else {
372
- $backup_filename .= "-full";
373
- }
374
-
375
- $backup_filename .= ".".$type;
376
- $backup_filename_short = $datestamp.$backup_filename;
377
- $backup_filename = $backup_tmp_dir.$backup_filename;
378
- $log['filename'] = $backup_filename_short;
379
- $log['logfile'] = array();
380
- $log['preset'] = $preset['bkpwp_preset_name'];
381
- $log['schedule'] = $preset['bkpwp_schedule'];
382
- $time_start = microtime(true);
383
-
384
- // count milliseconds
385
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress starting at","bkpwp")." ".$this->bkpwp_logtimestamp();
386
-
387
- // create a temporary directory
388
- if (!is_dir($backup_tmp_dir)) {
389
- if (!mkdir($backup_tmp_dir)) {
390
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$backup_tmp_dir."' ".__("could not be created","bkpwp");
391
- } else {
392
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$backup_tmp_dir."' ".__("created","bkpwp");
393
- }
394
- }
395
- $this->bkpwp_write_log($log);
396
- if ($sqlonly != 1) {
397
- // subdirectory of wordpress files
398
- $wordpress_files = $backup_tmp_dir."/wordpress_files";
399
- if (!is_dir($wordpress_files)) {
400
- if (!mkdir($wordpress_files)) {
401
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$wordpress_files."' ".__("could not be created","bkpwp");
402
- } else {
403
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress temporary Directory","bkpwp")." '".$wordpress_files."' ".__("created","bkpwp");
404
- }
405
- $this->bkpwp_write_log($log);
406
- }
407
- }
408
-
409
- $db_dump = $this->bkpwp_mysql($backup_tmp_dir,$log);
410
-
411
- if(!$db_dump) {
412
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQL Dump could not be created.","bkpwp");
413
- } else {
414
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("SQL Dump created.","bkpwp");
415
- }
416
- $this->bkpwp_write_log($log);
417
- if ($sqlonly != 1) {
418
- // create a temporary directory of files to backup
419
- $dir = bkpwp_conform_dir(ABSPATH);
420
- $files = $options->bkpwp_ls($dir);
421
- $files_copied = 0;
422
- $subdirs_created = 0;
423
- $i=1; // the sql at least
424
- foreach ($files as $f) {
425
- if (is_dir($f)) {
426
- if (!mkdir($wordpress_files.bkpwp_conform_dir($f, true))) {
427
- return __("Failed to make directory","bkpwp");
428
- } else {
429
- $subdirs_created++;
430
- }
431
- } elseif(file_exists($f)) {
432
- if (!copy($f,$wordpress_files.bkpwp_conform_dir($f, true))) {
433
- return __("Failed to copy","bkpwp");
434
- } else {
435
- $files_copied++;
436
- }
437
- }
438
- $i++;
439
- }
440
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$subdirs_created." ".__("Temporary Subdirectories copied sucessfully","bkpwp");
441
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$files_copied." ".__("Temporary Files copied sucessfully","bkpwp");
442
- }
443
- // create backup archive file
444
- $archive_backup = new File_Archive();
445
- $archive_backup->setOption("tmpDirectory",get_option("bkpwppath"));
446
- $archive_backup->extract($backup_tmp_dir,File_Archive::toArchive($backup_filename, File_Archive::toFiles()));
447
- if (!file_exists($backup_filename)) {
448
- return __("Failed to create backup archive","bkpwp");
449
- } else {
450
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("Archive File created/compressed successfully:","bkpwp")." ".$backup_filename;
451
- }
452
-
453
- $deleted_files_count = $this->bkpwp_rmdirtree($backup_tmp_dir);
454
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".count($deleted_files_count)." ".__("Temporary Directories and Files deleted successfully","bkpwp");
455
- $deleted_oldarchives_count = $this->bkpwp_delete_old();
456
- if ($deleted_oldarchives_count > 0) {
457
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".$deleted_oldarchives_count." ".__("Old BackUpWordPress Archives deleted successfully","bkpwp");
458
- } else {
459
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("No old BackUpWordPress Archives to delete","bkpwp");
460
- }
461
-
462
-
463
- $time_end = microtime(true);
464
- $time = $time_end - $time_start;
465
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress done at","bkpwp")." ".$this->bkpwp_logtimestamp();
466
- $log['logfile'][] = $this->bkpwp_logtimestamp().": ".__("BackUpWordPress was running for","bkpwp")." ".round($time,2)." ".__("Seconds","bkpwp");
467
-
468
- // write the log
469
- $this->bkpwp_write_log($log);
470
- $backup = array("file" => $backup_filename,
471
- "filename" => $backup_filename_short);
472
- // start the output
473
- $backuprow = new BKPWP_BACKUP_ARCHIVE();
474
- ob_start();
475
- $backuprow->bkpwp_get_backup_row($backup,"new_row");
476
- $out = ob_get_contents();
477
- ob_end_clean();
478
-
479
- // mail it if bkpwp_automail is set
480
- $bkpwp_automail = get_option("bkpwp_automail");
481
- $bkpwp_automail_maxsize = get_option("bkpwp_automail_maxsize");
482
- if (!empty($bkpwp_automail)) {
483
- $allowed_bytes = $bkpwp_automail_maxsize*1024*1024;
484
- $logdump = nl2br($this->bkpwp_write_log($log,1));
485
- $logdump .= $allowed_bytes.":".filesize($backup_filename)." - ".$backup_filename."<br />\n";
486
- if ($this->is_readable_for_mailout($backup_filename)) {
487
- $logdump .= "Backup file is readable.<br />\n";
488
- }
489
- if ($allowed_bytes >= filesize($backup_filename)) {
490
- bkpwp_mail_now(base64_encode($backup_filename), $logdump);
491
- } else {
492
- bkpwp_mail_now("", $logdump);
493
- }
494
- }
495
- // send autput
496
- return $out;
497
- }
498
-
499
- function is_readable_for_mailout($file,$count=0) {
500
- if ($count > 24) {
501
- return false;
502
- }
503
- if (!is_readable($file)) {
504
- $count++;
505
- sleep(2);
506
- is_readable_for_mailout($file,$count);
507
- }
508
- return true;
509
- }
510
-
511
- //Since looks like the Windows ACLs bug "wont fix" (see http://bugs.php.net/bug.php?id=27609)
512
- function is__writable($path) {
513
-
514
- if ($path{strlen($path)-1}=='/')
515
- return $this->is__writable($path.uniqid(mt_rand()).'.tmp');
516
-
517
- if (file_exists($path)) {
518
- if (!($f = @fopen($path, 'r+')))
519
- return false;
520
- fclose($f);
521
- return true;
522
- }
523
-
524
- if (!($f = @fopen($path, 'w')))
525
- return false;
526
- fclose($f);
527
- unlink($path);
528
- return true;
529
- }
530
-
531
- function bkpwp_write_log($log,$return="") {
532
- if (!is_array($log)) { return; }
533
- $logdir = get_option("bkpwppath")."/logs";
534
- if (!is_dir($logdir)) {
535
- mkdir($logdir);
536
- }
537
- $logname = $logdir."/".$log['filename'].".txt";
538
- $logfile = "";
539
- $logfile .= "Preset: ".$log['preset']."\n";
540
- if (!empty($log['schedule'])) {
541
- $logfile .= "Schedule: ".$log['schedule']."\n";
542
- }
543
- if (is_array($log['logfile'])) {
544
- foreach($log['logfile'] as $l) {
545
- if (is_array($l)) { $l = serialize($l);}
546
- $logfile .= "## ".$l."\n";
547
- }
548
- if (!empty($return)) {
549
- return $logfile;
550
- }
551
- // actually write the log
552
- if ($this->is__writable($logname)) {
553
- if (!$handle = fopen($logname, "a")) {
554
- return __("Logfile could not be opened for writing: ","bkpwp").$logname;
555
- exit;
556
- }
557
- if (!fwrite($handle, $logfile)) {
558
- return __("Logfile not writable: ","bkpwp").$logname;
559
- exit;
560
- }
561
- fclose($handle);
562
- return true;
563
- } else {
564
- return __("Logfile not writable: ","bkpwp").$logname;
565
- }
566
- }
567
- }
568
-
569
- function bkpwp_rmdirtree($dirname) {
570
- if (!eregi(bkpwp_conform_dir(ABSPATH),bkpwp_conform_dir($dirname))) {
571
- return;
572
- }
573
- if (is_dir($dirname)) { //Operate on dirs only
574
- $result=array();
575
- if (substr($dirname,-1)!='/') {$dirname.='/';} //Append slash if necessary
576
- $handle = opendir($dirname);
577
- while (false !== ($file = readdir($handle))) {
578
- if ($file!='.' && $file!= '..') { //Ignore . and ..
579
- $path = $dirname.$file;
580
- if (is_dir($path)) { //Recurse if subdir, Delete if file
581
- $result=array_merge($result,$this->bkpwp_rmdirtree($path));
582
- }else{
583
- unlink($path);
584
- $result[].=$path;
585
- }
586
- }
587
- }
588
- closedir($handle);
589
- rmdir($dirname); //Remove dir
590
- $result[] .= $dirname;
591
- return $result; //Return array of deleted items
592
- } else {
593
- return false; //Return false if attempting to operate on a file
594
- }
595
- }
596
-
597
- function bkpwp_delete_old() {
598
- $backups = new BKPWP_MANAGE();
599
- $unlinkcount = 0;
600
- $files = $backups->bkpwp_get_backups();
601
- if (count($files) <= get_option('bkpwp_max_backups')) {
602
- return;
603
- } else {
604
- $i = 1;
605
- foreach($files as $f) {
606
- if ($i > get_option('bkpwp_max_backups')) {
607
- unlink($f['file']);
608
- $unlinkcount++;
609
- }
610
- $i++;
611
- }
612
- }
613
- if ($unlinkcount > 0) {
614
- return $unlinkcount;
615
- }
616
- return false;
617
- }
618
-
619
- }
620
-
621
- class BKPWP_MANAGE {
622
-
623
- function BKPWP_MANAGE() {
624
- }
625
-
626
- function bkpwp_get_presets() {
627
- $user = $GLOBALS['userdata']->user_login;
628
- if(empty($user)) { $user = "admin"; }
629
- $presets = get_option("bkpwp_presets");
630
- if(!is_array($presets[$user]['bkpwp_presets'])) {
631
- return array();
632
- } else {
633
- return $presets[$user]['bkpwp_presets'];
634
- }
635
- }
636
-
637
- function bkpwp_update_presets($userpresets) {
638
- $presets = get_option("bkpwp_presets");
639
- $user = $GLOBALS['userdata']->user_login;
640
- if(empty($user)) { $user = "admin"; }
641
- $presets[$user]['bkpwp_presets'] = $userpresets;
642
- update_option("bkpwp_presets",$presets);
643
- }
644
-
645
- function bkpwp_load_preset($preset) {
646
- $options = new BKPWP_OPTIONS();
647
- $ret = "<div style=\"border: 1px solid #ccc; padding:10px; margin-bottom:20px;\">";
648
- /*if ($preset['bkpwp_preset_options']['default'] == 1) {
649
- $ret .= "<div id=\"message\" class=\"updated fade\"><p>".__("You can not overwrite this default preset. Please save changes with a new Preset Name.","bkpwp")."</p></div>";
650
- }
651
- */
652
- $ret .= "<h4>Configure or Create Backup Preset</h4><p>";
653
- $ret .= "<label for=\"mod_bkpwp_preset_name\">".__("Preset Name","bkpwp")." </label>";
654
- $ret .= "<input type=\"text\" name=\"mod_bkpwp_preset_name\" id=\"mod_bkpwp_preset_name\" value=\"".$preset['bkpwp_preset_name']."\" /></p>";
655
-
656
- $ret .= "<p><label for=\"mod_bkpwp_archive_type\">".__("Archive Type","bkpwp")." </label><select name=\"mod_bkpwp_archive_type\" id=\"mod_bkpwp_archive_type\">";
657
- $archive_types = get_option("bkpwp_archive_types");
658
- if (is_array($archive_types)) {
659
- foreach ($archive_types as $type) {
660
- $ret .= "<option value=\"".$type."\" ";
661
- if ($preset['bkpwp_preset_options']['bkpwp_archive_type'] == $type) {
662
- $ret .= " selected";
663
- }
664
- $ret .= ">".$type."</option>";
665
- }
666
- }
667
- $ret .= "</select></p>";
668
-
669
- if($preset['bkpwp_preset_options']['bkpwp_sql_only'] == 1) {
670
- $fullinit = " style=\"display: none;\"";
671
- }
672
- $ret .= "<div id=\"full_only\"".$fullinit.">";
673
- $lists = $options->bkpwp_get_excludelists();
674
- if (is_array($lists)) {
675
- $ret .= "<p>".__("Exclude List","bkpwp")." <select name=\"mod_bkpwp_excludelist\" id=\"mod_bkpwp_excludelist\">";
676
- $ret .= "<option value=\"\">".__("None","bkpwp")."</option>";
677
- foreach ($lists as $l) {
678
- $ret .= "<option value=\"".$l['listname']."\" ";
679
- if ($preset['bkpwp_preset_options']['bkpwp_excludelist'] == $l['listname']) {
680
- $ret .= " selected";
681
- }
682
- $ret .= ">".$l['listname']."</option>";
683
- }
684
- $ret .= "</select>";
685
- $ret .= " <a href=\"admin.php?page=bkpwp-backup-options&excludelistname=".$preset['bkpwp_preset_options']['bkpwp_excludelist']."#excludelist\">".__("Configure","bkpwp")." &raquo;</a>";
686
- $ret .= "</p>";
687
- }
688
- $ret .= "</div>";
689
-
690
- $ret .= "<p><label for=\"mod_bkpwp_sql_only\"><input type=\"checkbox\" name=\"mod_bkpwp_sql_only\" id=\"mod_bkpwp_sql_only\" value=\"1\"";
691
- if ($preset['bkpwp_preset_options']['bkpwp_sql_only'] == 1) {
692
- $ret .= " checked";
693
- }
694
- $ret .= " onclick=\"if (document.getElementById('mod_bkpwp_sql_only').checked == false) { document.getElementById('mod_bkpwp_sql_only').value=''; document.getElementById('full_only').style.display='block'; } else { document.getElementById('mod_bkpwp_sql_only').value=1; document.getElementById('full_only').style.display='none'; }\" /> ".__("SQL only","bkpwp")."</label></p>";
695
- $ret .= "<p><input type=\"button\" class=\"button\" value=\"".__("Save Preset","bkpwp")."\" onclick=\"bkpwp_js_loading('".__("Saving Preset","bkpwp")."'); sajax_target_id = 'bkpwp_action_buffer'; save_preset(); sajax_target_id = ''; return false;\" /></p>";
696
- $ret .= "</div>";
697
- return $ret;
698
- }
699
-
700
- function bkpwp_view_preset($preset) {
701
- $backup = new BKPWP_BACKUP();
702
- $options = new BKPWP_OPTIONS();
703
- $ret = "<div>";
704
- if (!empty($preset['bkpwp_preset_options']['bkpwp_excludelist'])) {
705
- $ret .= "<p>".__("Omitted Folders and Files when using","bkpwp")." <b>".$preset['bkpwp_preset_name']."</b></p>";
706
- $ret .= "<p>";
707
- $ret .= $options->bkpwp_ajax_shownobfiles($preset['bkpwp_preset_options']['bkpwp_excludelist']);
708
- $ret .= "</p>";
709
- }
710
- $ret .= $backup->bkpwp_calculate($preset);
711
- $ret .= "</div>";
712
- return $ret;
713
- }
714
-
715
- function bkpwp_delete_preset($name) {
716
- $apresets = $this->bkpwp_get_presets();
717
- $presets= array();
718
- foreach($apresets as $p) {
719
- if ($p['bkpwp_preset_name'] != $name) {
720
- $presets[] = $p;
721
- } else {
722
- if ($p['bkpwp_preset_options']['default'] == 1) {
723
- return __("You can not delete this default preset.","bkpwp");
724
- }
725
- }
726
- }
727
- $this->bkpwp_update_presets($presets);
728
- return "<div id=\"message\" class=\"updated fade\"><p>".__("Preset deleted.","bkpwp")."</p></div>";
729
- }
730
-
731
- function bkpwp_save_preset($name="",$archive_type="",$excludelist="",$sql_only="") {
732
- if (empty($name)) {
733
- $name = "Preset".date("Y-m-d-H-i-s");
734
- }
735
- $apresets = $this->bkpwp_get_presets();
736
- $presets= array();
737
- foreach($apresets as $p) {
738
- if ($p['bkpwp_preset_name'] != $name) {
739
- $presets[] = $p;
740
- } else {
741
- if ($p['bkpwp_preset_options']['default'] == 1) {
742
- return "<div id=\"message\" class=\"updated fade\"><p>".__("You can not overwrite this default preset. Please save changes with a new Preset Name.","bkpwp")."</p></div>";
743
- }
744
- }
745
- }
746
-
747
- $options = array("bkpwp_archive_type" => $archive_type,
748
- "bkpwp_sql_only" => $sql_only,
749
- "bkpwp_excludelist" => $excludelist);
750
- $presets[] = array("bkpwp_preset_name" => $name,
751
- "bkpwp_preset_options" => $options);
752
-
753
- $this->bkpwp_update_presets($presets);
754
- return "<div id=\"message\" class=\"updated fade\"><p>".__("Preset saved.","bkpwp")."</p></div>";
755
- }
756
-
757
- function bkpwp_get_preset($name="") {
758
- if (empty($name)) {
759
- $name = "full backup";
760
- }
761
- $user = $GLOBALS['userdata']->user_login;
762
- if(empty($user)) { $user = "admin"; }
763
- $presets = get_option("bkpwp_presets");
764
- $apresets = $presets[$user]['bkpwp_presets'];
765
- foreach($apresets as $p) {
766
- if ($p['bkpwp_preset_name'] == $name) {
767
- return $p;
768
- }
769
- }
770
- }
771
-
772
- function bkpwp_max_views() {
773
- $maxview = get_option('bkpwp_listmax_backups');
774
- if (!empty($_REQUEST['bkpwp_show_all'])) {
775
- $maxview = 999;
776
- }
777
- return $maxview;
778
- }
779
-
780
- function bkpwp_get_backups() {
781
- $files = array();
782
- $bkpwppath = get_option("bkpwppath");
783
- if (!is_writable($bkpwppath)) {
784
- return;
785
- }
786
- $restorefile = $bkpwppath."/bkpwp_restore.sql";
787
- if (file_exists($restorefile)) {
788
- unlink($restorefile);
789
- }
790
- if ($handle = opendir($bkpwppath)) {
791
- while (false !== ($file = readdir($handle))) {
792
- if (($file != ".") && ($file != "..") && !is_dir($bkpwppath."/".$file)) {
793
- $files[] = array("file" => $bkpwppath."/".$file,
794
- "filename" => $file);
795
- }
796
- }
797
- closedir($handle);
798
- }
799
- if (count($files) < 1) { return; }
800
- foreach ($files as $key => $row) {
801
- $filename[$key] = $row['filename'];
802
- }
803
- array_multisort($filename, SORT_DESC, $files);
804
- return $files;
805
- }
806
- }
807
-
808
-
809
- require(ABSPATH."wp-includes/class-phpmailer.php");
810
- class backupwordpressMailer extends PHPMailer {
811
- // Set default variables for all new objects
812
- //var $From = $GLOBALS['userdata']->user_email;
813
- var $FromName = "BackUpWordPress";
814
- /*
815
- var $Host = "";
816
- var $Username = ''; // SMTP username
817
- var $Password = ''; // SMTP password
818
- var $SMTPAuth = true; */
819
- var $Mailer = "mail";
820
- var $WordWrap = 75;
821
- }
822
-
823
- function bkpwp_mail_now($file="", $bkpwpinfo="") {
824
- ob_start();
825
- include_once($GLOBALS['bkpwp_plugin_path']."bkpwp-pages/bkpwp_footer.php");
826
- $text_html = ob_get_contents();
827
- ob_end_clean();
828
-
829
- ob_start();
830
- include_once($GLOBALS['bkpwp_plugin_path']."bkpwp-pages/bkpwp_mail_footer.php");
831
- $text_plain = ob_get_contents();
832
- ob_end_clean();
833
-
834
- // Instantiate your new class
835
- $mail = new backupwordpressMailer;
836
- $mail->IsHTML(true);
837
-
838
- // Now you only need to add the necessary stuff
839
-
840
- $email = get_option("bkpwp_automail_address");
841
- $name = get_option("bkpwp_automail_receiver");
842
-
843
- $mail->AddAddress($email, $name);
844
- $mail->From = $email;
845
- $mail->FromName = __("BackUpWordPress","bkpwp")." ".get_bloginfo("url");
846
- $mail->Subject = __("BackUpWordPress","bkpwp")." ".get_bloginfo("url");
847
- $mail->Body = "<html><body>";
848
- $mail->Body .= __("Your requested Backup","bkpwp");
849
- if (empty($file)) {
850
- $mail->Body .= __("This Backup exceeded","bkpwp")." ".get_option("bkpwp_automail_maxsize")." ".__("MB (megabytes)","bkpwp")."<br /><br />\n\n";
851
- $mail->Body .= __("Please download it from your WordPress administration backend.","bkpwp")."<br /><br />\n\n";
852
- }
853
-
854
- $mail->Body .= $bkpwpinfo;
855
- $mail->Body .= $text_html;
856
- $mail->Body .= "</body></html>";
857
- $mail->AltBody = strip_tags($text_plain);
858
-
859
- if (!empty($file)) {
860
- $mail->AddAttachment(base64_decode($file)); // optional name
861
- }
862
-
863
- if(!$mail->Send()){
864
- echo $mail->ErrorInfo;
865
- return false;
866
- } else {
867
- return true;
868
- }
869
- }
870
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
options.php DELETED
@@ -1,449 +0,0 @@
1
- <?php
2
-
3
- class BKPWP_OPTIONS {
4
-
5
- var $bkpwp_default_backup_path = '/wp-content/backup';
6
-
7
- function BKPWP_OPTIONS() {
8
- }
9
-
10
- function bkpwp_easy_mode() {
11
- $easy_mode = get_option("bkpwp_easy_mode");
12
- $user = $GLOBALS['userdata']->user_login;
13
- if(empty($user)) { $user = "admin"; }
14
- if ($easy_mode[$user] == 1) {
15
- return true;
16
- } else {
17
- return false;
18
- }
19
- }
20
-
21
- function bkpwp_handle_modeswitch() {
22
- if (!empty($_REQUEST['bkpwp_modeswitch'])) {
23
- $user = $GLOBALS['userdata']->user_login;
24
- if(empty($user)) { $user = "admin"; }
25
- if (!$this->bkpwp_easy_mode()) {
26
- $easy_mode[$user] = 1;
27
- } else {
28
- $easy_mode[$user] = "";
29
- }
30
-
31
- update_option("bkpwp_easy_mode",$easy_mode);
32
- }
33
- }
34
-
35
- function bkpwp_path() {
36
- return get_option("bkpwppath");
37
- }
38
-
39
- function bkpwp_options_edit() {
40
- if (!current_user_can('manage bkpwp')) {
41
- return false;
42
- }
43
- return true;
44
- }
45
-
46
- function bkpwp_delete_option($option) {
47
- delete_option($option);
48
- }
49
-
50
- function bkpwp_update_option($name,$value) {
51
- update_option($name,$value);
52
- }
53
-
54
- function bkpwp_handle_backup_path($suppress_msg=0) {
55
- if (!$this->bkpwp_options_edit()) {
56
- bkpwp_display_message(__("You do not have sufficent privileges to do Full Backups.","bkpwp"));
57
- return;
58
- }
59
- if (!empty($_REQUEST['bkpwppath'])) {
60
- if ($this->bkpwp_easy_mode()){
61
- $_REQUEST['bkpwppath'] = bkpwp_conform_dir(ABSPATH).$_REQUEST['bkpwppath'];
62
- }
63
- if (!eregi(bkpwp_conform_dir(ABSPATH),$_REQUEST['bkpwppath'])) {
64
- delete_option("bkpwppath");
65
- $msg = __("Path is not within your webroot. Please specify a writable directory inside ","bkpwp").bkpwp_conform_dir(ABSPATH).".";
66
- bkpwp_display_message($msg);
67
- } else {
68
- if (!is_dir($_REQUEST['bkpwppath'])) {
69
- if (!mkdir($_REQUEST['bkpwppath'])) {
70
- $this->bkpwp_delete_option("bkpwppath");
71
- $msg = __("Wrong Backup Path. Directory does not exist and this script was not able to create it.","bkpwp");
72
- bkpwp_display_message($msg);
73
- } else {
74
- $this->bkpwp_update_option("bkpwppath",$_REQUEST['bkpwppath']);
75
- $msg = __("Directory did not exist but this script was able to create it.","bkpwp");
76
- bkpwp_display_message($msg);
77
- }
78
- } elseif (!is_writable($_REQUEST['bkpwppath'])) {
79
- $this->bkpwp_delete_option("bkpwppath");
80
- $msg = __("Directory does exist but is not writable by the webserver. Check directory permissions (e.g.: chmod 777).","bkpwp");
81
- bkpwp_display_message($msg);
82
- } else {
83
- $this->bkpwp_update_option("bkpwppath",$_REQUEST['bkpwppath']);
84
- bkpwp_display_message(__("Backup Path saved.","bkpwp")." <a href=\"admin.php?page=".$_REQUEST['page']."\">".__("Continue","bkpwp")." &raquo;</a>");
85
-
86
- }
87
- }
88
- }
89
- if (!is_writable($this->bkpwp_path()) && empty($_REQUEST['bkpwppath'])) {
90
- $msg = __("Please configure the Backup path first. The field below should allready be filled with a recommendation for that option.","bkpwp");
91
- if ($suppress_msg == 0) {
92
- bkpwp_display_message($msg);
93
- }
94
- }
95
- }
96
-
97
- function bkpwp_check_path() {
98
- if (!$this->bkpwp_easy_mode()){
99
- echo $this->bkpwp_path();
100
- } else {
101
- if (!is_writable($this->bkpwp_path())) {
102
- echo $this->bkpwp_default_backup_path;
103
- } else {
104
- echo eregi_replace(bkpwp_conform_dir(ABSPATH),"",$this->bkpwp_path());
105
- }
106
- }
107
- }
108
-
109
- function bkpwp_handle_backup_settings() {
110
- if (!empty($_REQUEST['bkpwp_backup_options'])) {
111
- $this->bkpwp_update_option("bkpwp_max_backups",$_REQUEST['bkpwp_max_backups']);
112
- bkpwp_display_message(__("Settings saved.","bkpwp"));
113
- }
114
- }
115
-
116
- function bkpwp_handle_backup_automail() {
117
- if (!empty($_REQUEST['bkpwp_automailsettings'])) {
118
- if (!empty($_REQUEST['bkpwp_automail'])) {
119
- $this->bkpwp_update_option("bkpwp_automail",$_REQUEST['bkpwp_automail']);
120
- $this->bkpwp_update_option("bkpwp_automail_address",$GLOBALS['userdata']->user_email);
121
- $this->bkpwp_update_option("bkpwp_automail_receiver",$GLOBALS['userdata']->user_nicename);
122
- if (!empty($_REQUEST['bkpwp_automail_maxsize'])) {
123
- $this->bkpwp_update_option("bkpwp_automail_maxsize",$_REQUEST['bkpwp_automail_maxsize']);
124
- }
125
- bkpwp_display_message(__("Settings saved.","bkpwp"));
126
- } else {
127
- $this->bkpwp_delete_option("bkpwp_automail_maxsize");
128
- $this->bkpwp_delete_option("bkpwp_automail_address");
129
- $this->bkpwp_delete_option("bkpwp_automail_receiver");
130
- $this->bkpwp_delete_option("bkpwp_automail");
131
- }
132
- }
133
- }
134
-
135
- function bkpwp_handle_backup_excludelists() {
136
- if (!empty($_REQUEST['nobackup']) && !empty($_REQUEST['excludelist'])) {
137
- $this->bkpwp_excludelist();
138
- bkpwp_display_message(__("New Backup Exclude List saved:","bkpwp")." ".$_REQUEST['excludelistname']);
139
- } elseif (!empty($_REQUEST['nobackupchange']) && !empty($_REQUEST['excludelist'])) {
140
- $this->bkpwp_excludelist();
141
- bkpwp_display_message(__("Backup Exclude List saved:","bkpwp")." ".$_REQUEST['excludelistname']);
142
- } elseif (!empty($_REQUEST['nobackupdelete']) && !empty($_REQUEST['excludelist'])) {
143
- $this->bkpwp_delete_excludelist($_REQUEST['excludelistname']);
144
- bkpwp_display_message(__("Backup Exclude List deleted:","bkpwp")." ".$_REQUEST['excludelistname']);
145
- }
146
- }
147
-
148
- function bkpwp_ls_exclusions($dir,$files=array()) {
149
- $d = opendir($dir);
150
- while ($file = readdir($d)) {
151
- if ($file == '.' || $file == '..') { continue; }
152
- $getfile = $this->bkpwp_match_excludelist($dir,$file);
153
- if (!empty($getfile)) {
154
- $files[] = $getfile;
155
- }
156
- if (is_dir($dir.'/'.$file)) {
157
- if (!empty($getfile)) {
158
- continue;
159
- }
160
- $files = $this->bkpwp_ls_exclusions($dir.'/'.$file, $files);
161
- }
162
- }
163
- return $files;
164
- }
165
-
166
- function bkpwp_ajax_shownobfiles($listname,$dir="") {
167
- if (empty($dir)) {
168
- $dir = bkpwp_conform_dir(ABSPATH);
169
- }
170
- $this->excludelist = urldecode($listname);
171
- $ret = "";
172
- $files = $this->bkpwp_ls_exclusions($dir);
173
- $stringmatches = array();
174
-
175
-
176
- $ret .= "<p>";
177
- $ret .= __("Folders","bkpwp")."<br />";
178
- foreach($files as $f) {
179
- if (is_dir($f['file'])) {
180
- $ret .= "<b>".$f['file']."</b>: ".__("matched by","bkpwp")." ".$f['match']." -> ".$f['value']."<br />";
181
- } else {
182
- if ($f['match'] == "string") {
183
- $t = $f['value'];
184
- $stringmatches[$t]++;
185
- }
186
- }
187
- }
188
- $ret .= "</p>";
189
-
190
- if (count($stringmatches) > 0) {
191
- $ret .= "<p>";
192
- $ret .= __("Files","bkpwp")."<br />";
193
- foreach($stringmatches as $s=>$t) {
194
- $ret .= "<b>".$t."</b> ".__("files matched by","bkpwp")." ".$s."<br />";
195
- }
196
- $ret .= "</p>";
197
- }
198
-
199
- return $ret;
200
- }
201
-
202
- function bkpwp_ls($dir,$files=array()) {
203
- $d = opendir($dir);
204
- $j=0;
205
- while ($file = readdir($d)) {
206
- if ($file == '.' || $file == '..') { continue; }
207
- $getfile = $this->bkpwp_match_excludelist($dir,$file);
208
- if (!empty($getfile)) {
209
- continue;
210
- }
211
- $files[] = $dir.'/'.$file;
212
- if (is_dir($dir.'/'.$file)) {
213
- if (!empty($getfile)) {
214
- continue;
215
- }
216
- $files = $this->bkpwp_ls($dir.'/'.$file,$files); $j++;
217
- }
218
- }
219
- return $files;
220
- }
221
-
222
- function bkpwp_match_excludelist($dir,$file) {
223
- $nobfiles = $this->bkpwp_get_excludelist($this->excludelist);
224
- $nobfiles['list'][] = get_option("bkpwppath");
225
- if (is_array($nobfiles['list'])) {
226
- foreach($nobfiles['list'] as $n) {
227
- if (empty($n)) { continue; }
228
- $ifpath = str_replace("\\","/",$n);
229
- $absolutefilepath = str_replace("\\","/",$dir.'/'.$file);
230
- $relativefilepath = str_replace(ABSPATH,"",$absolutefilepath);
231
- if (($ifpath == $absolutefilepath) || ($ifpath == $relativefilepath)) {
232
- return array('file' => $dir.'/'.$file, 'match' => 'path', 'value' => $n);
233
- } elseif (!strpos("/",$ifpath) && stristr($file,$n)) {
234
- return array('file' => $dir.'/'.$file, 'match' => 'string', 'value' => $n);
235
- }
236
- }
237
- }
238
- return false;
239
- }
240
-
241
- function bkpwp_get_excludelists() {
242
- $allnobs = get_option("bkpwp_excludelists");
243
- $user = $GLOBALS['userdata']->user_login;
244
- if(empty($user)) { $user = "admin"; }
245
- return $allnobs[$user];
246
- }
247
-
248
- function bkpwp_get_excludelist($listname) {
249
- $usernoblists = $this->bkpwp_get_excludelists();
250
- foreach($usernoblists as $f) {
251
- if ($f['listname'] == $listname) {
252
- return $f;
253
- }
254
- }
255
- }
256
-
257
- function bkpwp_excludelist_tochange() {
258
- if (!empty($_REQUEST['excludelist_to_change'])) {
259
- return $this->bkpwp_get_excludelist($_REQUEST['excludelist_to_change']);
260
- }
261
-
262
- if (!empty($_REQUEST['excludelistname'])) {
263
- return $this->bkpwp_get_excludelist($_REQUEST['excludelistname']);
264
- }
265
- }
266
-
267
- function bkpwp_delete_excludelist($listname) {
268
- $allnobst = get_option("bkpwp_excludelists");
269
- $user = $GLOBALS['userdata']->user_login;
270
- if(empty($user)) { $user = "admin"; }
271
- $allnobs = array();
272
- if (!is_array($allnobst[$user])) {
273
- $allnobst[$user] = array();
274
- }
275
- foreach ($allnobst[$user] as $a) {
276
- if ($a['listname'] != $listname) {
277
- $allnobs[$user][] = $a;
278
- }
279
- }
280
-
281
- update_option("bkpwp_excludelists",$allnobs);
282
- }
283
-
284
- function bkpwp_save_excludelist($list,$listname,$listtype) {
285
- $allnobst = get_option("bkpwp_excludelists");
286
- $user = $GLOBALS['userdata']->user_login;
287
- if(empty($user)) { $user = "admin"; }
288
- $allnobs = array();
289
- if (!is_array($allnobst[$user])) {
290
- $allnobst[$user] = array();
291
- }
292
- foreach ($allnobst[$user] as $a) {
293
- if ($a['listname'] != $listname) {
294
- $allnobs[$user][] = $a;
295
- }
296
- }
297
- $allnobs[$user][] = array("listname" => $listname,
298
- "listtype" => $listtype,
299
- "list" => $list);
300
-
301
- update_option("bkpwp_excludelists",$allnobs);
302
- }
303
-
304
- function bkpwp_excludelist($excludelist="",$excludelistname="",$excludelisttype="") {
305
- $list = array();
306
- $list[] = $this->bkpwp_path();
307
- if (!empty($_REQUEST['excludelist'])) {
308
- $excludelist = $_REQUEST['excludelist'];
309
- }
310
- foreach($excludelist as $r) {
311
- if (eregi(",",$r)) {
312
- $re=explode(",",$r);
313
- foreach($re as $e) {
314
- if (!empty($e)) {
315
- $list[] = $e;
316
- }
317
- }
318
- } else {
319
- if (!empty($r)) {
320
- $list[] = $r;
321
- }
322
- }
323
- }
324
- $list = array_unique($list);
325
- if (!empty($_REQUEST['excludelistname'])) {
326
- $excludelistname = $_REQUEST['excludelistname'];
327
- }
328
- if (empty($excludelistname)) {
329
- $excludelistname = "excl_".date("Y-m-d-H-i-s");
330
- }
331
- $this->bkpwp_save_excludelist($list,$excludelistname,$excludelisttype);
332
- }
333
-
334
- function bkpwp_check_compression_type($archive_types_wishlist) {
335
- $a = array();
336
- foreach($archive_types_wishlist as $at) {
337
- if (function_exists($at['func']) || empty($at['func'])) {
338
- $a[] = $at['ext'];
339
- }
340
- }
341
- return $a;
342
- }
343
-
344
- function bkpwp_default_archive_types() {
345
- // a wishlist of compression types
346
- $archive_types_wishlist = array();
347
- $archive_types_wishlist[] = array("ext" => "zip", "func" => ""); // pear package file_archive's own
348
- $archive_types_wishlist[] = array("ext" => "tgz", "func" => "gzopen");
349
- $archive_types_wishlist[] = array("ext" => "tar.gz", "func" => "gzopen");
350
- $archive_types_wishlist[] = array("ext" => "tar", "func" => ""); // pear package file_archive's own
351
- $archive_types_wishlist[] = array("ext" => "tar.bz2", "func" => "bzopen");
352
-
353
- // run a check if the respective compression is supported by this php installation
354
- $archive_types = $this->bkpwp_check_compression_type($archive_types_wishlist);
355
- update_option("bkpwp_archive_types",$archive_types);
356
- }
357
-
358
- function bkpwp_get_backup_type($f) {
359
- $ex = explode(".",$f);
360
- $ex = explode("-",$ex[0]);
361
- $type = $ex[6];
362
- if (eregi("_adv",$type)) {
363
- $type = eregi_replace("_adv","",$type);
364
- $type .= " - advanced";
365
- }
366
- return $type;
367
- }
368
-
369
- function bkpwp_default_excludelists() {
370
- $defaults = new BKPWP_OPTIONS();
371
- $presetso = new BKPWP_MANAGE();
372
- // Excludelists Defaults
373
- $excludelist[] = ".tmp,~,.bak,#";
374
- $excludelistname = "temporary and autosave files";
375
- $excludelisttype = "default";
376
- $defaults->bkpwp_excludelist($excludelist,$excludelistname,$excludelisttype);
377
- }
378
-
379
- function bkpwp_default_presets() {
380
- // Preset defaults
381
- // is set for the current user.
382
- //update_option("bkpwp_presets","");
383
- $presetso = new BKPWP_MANAGE();
384
- $presets = $presetso->bkpwp_get_presets();
385
- if (count($presets) < 1) {
386
- $presets = array();
387
- // full backup
388
- $options = array("bkpwp_archive_type" => 'tar.gz',
389
- "default" => 1,
390
- "bkpwp_excludelist" => $excludelistname);
391
- $presets[] = array("bkpwp_preset_name" => "full backup",
392
- "bkpwp_preset_options" => $options);
393
- // sql only
394
- $options = array("bkpwp_sql_only" => 1,
395
- "bkpwp_archive_type" => 'tar.gz',
396
- "default" => 1);
397
- $presets[] = array("bkpwp_preset_name" => "sql only",
398
- "bkpwp_preset_options" => $options);
399
- $presetso->bkpwp_update_presets($presets);
400
- }
401
- }
402
-
403
- function bkpwp_default_schedules() {
404
-
405
- // scheduling defaults
406
- $schedules = get_option("bkpwp_schedules");
407
- if (!is_array($schedules)) {
408
- $schedules = array();
409
- $schedules[] = array("preset" => "full backup",
410
- "status" => "inactive",
411
- "reccurrence" => 'bkpwp_weekly',
412
- "info" => __("Full Backup Weekly","bkpwp"),
413
- "default" => 1,
414
- "created" => date("Y-m-d-H-i-s"));
415
- sleep(2);
416
- $schedules[] = array("preset" => "sql only",
417
- "status" => "inactive",
418
- "reccurrence" => 'bkpwp_daily',
419
- "info" => __("SQL Only Backup Daily","bkpwp"),
420
- "default" => 1,
421
- "created" => date("Y-m-d-H-i-s"));
422
- update_option("bkpwp_schedules",$schedules);
423
- }
424
- }
425
-
426
- function bkpwp_set_defaults() {
427
- // set a few options
428
- update_option('bkpwp_listmax_backups',15);
429
- update_option('bkpwp_max_backups',10);
430
- update_option("bkpwp_domain","bkpwp");
431
- update_option("bkpwp_domain_path","wp-content/plugins/bkpwp/locale");
432
-
433
- $user = $GLOBALS['userdata']->user_login;
434
- if(empty($user)) { $user = "admin"; }
435
- if (!$this->bkpwp_easy_mode()) {
436
- $easy_mode[$user] = 1;
437
- } else {
438
- $easy_mode[$user] = "";
439
- }
440
-
441
- update_option("bkpwp_easy_mode",$easy_mode);
442
-
443
- $this->bkpwp_default_archive_types();
444
- $this->bkpwp_default_excludelists();
445
- $this->bkpwp_default_presets();
446
- $this->bkpwp_default_schedules();
447
- }
448
- }
449
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -21,6 +21,8 @@ EasyMode:
21
  + Trigger backup manually
22
  + Set basic schedules for your backups
23
  + restore backups
 
 
24
  + download backups
25
  + Help page
26
  + Language Support for english and german(deutsch)
21
  + Trigger backup manually
22
  + Set basic schedules for your backups
23
  + restore backups
24
+ + staggered SQL import when restoring
25
+ + automatically continue unfinished backups in background
26
  + download backups
27
  + Help page
28
  + Language Support for english and german(deutsch)
schedule.php DELETED
@@ -1,117 +0,0 @@
1
- <?php
2
-
3
- class BKPWP_SCHEDULE {
4
-
5
- function BKPWP_SCHEDULE() {
6
- }
7
-
8
- function bkpwp_get_options_by_created($created) {
9
- $schedules = get_option("bkpwp_schedules");
10
- if (is_array($schedules)) {
11
- foreach($schedules as $s) {
12
- if ($s['created'] == $created) {
13
- return $s;
14
- }
15
- }
16
- }
17
- }
18
-
19
- function bkpwp_update_schedule($options) {
20
- $schedules = get_option("bkpwp_schedules");
21
- $newschedules = array();
22
- foreach($schedules as $s) {
23
- if ($s['created'] == $options['created']) {
24
- $s = $options;
25
- }
26
- $newschedules = $s;
27
- }
28
- update_option("bkpwp_schedules",$newschedules);
29
- }
30
-
31
- function bkpwp_delete_schedule_by_created($created) {
32
- $schedules = get_option("bkpwp_schedules");
33
- $newschedules = array();
34
- foreach($schedules as $s) {
35
- if ($s['created'] == $created) {
36
- $timestamp = wp_next_scheduled("bkpwp_schedule_bkpwp_hook",$s);
37
- if(!empty($timestamp)) {
38
- wp_unschedule_event($timestamp,"bkpwp_schedule_bkpwp_hook",$s);
39
- }
40
- $ret = 1;
41
- } else {
42
- $newschedules[] = $s;
43
- }
44
- }
45
- update_option("bkpwp_schedules",$newschedules);
46
- if (empty($ret)) { return false; }
47
- return $ret;
48
- }
49
-
50
-
51
- function bkpwp_unset_schedules() {
52
- $crons = get_option("cron");
53
- if (is_array($crons)) {
54
- foreach($crons as $timestamp => $cron) {
55
- if (!is_array($cron)) { continue; }
56
- foreach($cron as $hook => $options) {
57
- if($hook == "bkpwp_schedule_bkpwp_hook") {
58
- foreach ($options as $key=>$value) {
59
- wp_unschedule_event($timestamp,$hook,$value['args']);
60
- }
61
- }
62
- }
63
- }
64
- }
65
- }
66
-
67
-
68
- function bkpwp_toggle_schedule($created) {
69
- $schedules = get_option("bkpwp_schedules");
70
- $newschedules = array();
71
- $bkpwp_reccurrences = get_option("bkpwp_reccurrences");
72
- foreach($schedules as $s) {
73
- if ($s['created'] == $created) {
74
- if ($s['status'] == "active") {
75
- $timestamp = wp_next_scheduled("bkpwp_schedule_bkpwp_hook",$s);
76
- if(!empty($timestamp)) {
77
- wp_unschedule_event($timestamp,"bkpwp_schedule_bkpwp_hook",$s);
78
- $s['status'] = "inactive";
79
- $ret = "inactive";
80
- } else {
81
- return false;
82
- }
83
- } else {
84
- $recc = $s['reccurrence'];
85
- $s['status'] = "active";
86
- wp_schedule_event(time()+$bkpwp_reccurrences[$recc]['interval'], $s['reccurrence'], 'bkpwp_schedule_bkpwp_hook',$s);
87
- $ret = "active";
88
- }
89
- }
90
- $newschedules[] = $s;
91
- }
92
- update_option("bkpwp_schedules",$newschedules);
93
- if (empty($ret)) { return false; }
94
- return $ret;
95
- }
96
-
97
- function bkpwp_test_schedule() {
98
- $schedules = get_option("bkpwp_schedules");
99
- $test = array("preset" => "sql only",
100
- "status" => "active",
101
- "reccurrence" => '',
102
- "info" => __("Test schedule running in 30 seconds","bkpwp"),
103
- "default" => '',
104
- "created" => date("Y-m-d-H-i-s"));
105
- $schedules[] = $test;
106
- if (!wp_next_scheduled('bkpwp_schedule_bkpwp_hook', $test)) {
107
- //wp_schedule_single_event(time()+30, 'bkpwp_schedule_bkpwp_hook', $test);
108
- wp_schedule_event(time()+30, 'bkpwp_30secs', 'bkpwp_schedule_bkpwp_hook',$test);
109
- update_option("bkpwp_schedules",$schedules);
110
- return true;
111
- } else {
112
- return false;
113
- }
114
- }
115
- }
116
-
117
- ?>