BackUpWordPress - Version 0.1.4

Version Description

Download this release

Release Info

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

Code changes from version 0.1.3 to 0.1.4

backupwordpress.php CHANGED
@@ -4,19 +4,27 @@ 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.3
8
  Author URI: http://wordpress.designpraxis.at
9
  */
10
 
11
  /*
12
  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
 
16
  /*
17
 
18
  Changelog:
19
 
 
 
 
 
20
  Changes in 0.1.3:
21
  - ajax problems fixed
22
  - schedules last run timestamp fixed
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
 
11
  /*
12
  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
 
20
  /*
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
27
+
28
  Changes in 0.1.3:
29
  - ajax problems fixed
30
  - schedules last run timestamp fixed
bkpwp-classes/manage_backups.php CHANGED
@@ -645,6 +645,10 @@ class BKPWP_MANAGE {
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
  $ret .= "<h4>Configure or Create Backup Preset</h4><p>";
649
  $ret .= "<label for=\"mod_bkpwp_preset_name\">".__("Preset Name","bkpwp")." </label>";
650
  $ret .= "<input type=\"text\" name=\"mod_bkpwp_preset_name\" id=\"mod_bkpwp_preset_name\" value=\"".$preset['bkpwp_preset_name']."\" /></p>";
@@ -689,9 +693,6 @@ class BKPWP_MANAGE {
689
  }
690
  $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>";
691
  $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>";
692
- if ($preset['bkpwp_preset_options']['default'] == 1) {
693
- $ret .= "<p>".__("You can not overwrite this default preset. Please save changes with a new Preset Name.","bkpwp")."</p>";
694
- }
695
  $ret .= "</div>";
696
  return $ret;
697
  }
@@ -738,7 +739,7 @@ class BKPWP_MANAGE {
738
  $presets[] = $p;
739
  } else {
740
  if ($p['bkpwp_preset_options']['default'] == 1) {
741
- return __("You can not overwrite this default preset. Please save changes with a new Preset Name.","bkpwp");
742
  }
743
  }
744
  }
@@ -749,13 +750,6 @@ class BKPWP_MANAGE {
749
  $presets[] = array("bkpwp_preset_name" => $name,
750
  "bkpwp_preset_options" => $options);
751
 
752
- /* ob_start();
753
- echo "<pre>";
754
- print_r($presets);
755
- echo "</pre>";
756
- $out = ob_get_contents();
757
- ob_end_clean(); */
758
- //return $out;
759
  $this->bkpwp_update_presets($presets);
760
  return "<div id=\"message\" class=\"updated fade\"><p>".__("Preset saved.","bkpwp")."</p></div>";
761
  }
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>";
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
  }
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
  }
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
  }
bkpwp-classes/schedule.php CHANGED
@@ -104,7 +104,8 @@ 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
  update_option("bkpwp_schedules",$schedules);
109
  return true;
110
  } 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
+ wp_schedule_event(time()+30, 'bkpwp_30secs', 'bkpwp_schedule_bkpwp_hook',$test);
109
  update_option("bkpwp_schedules",$schedules);
110
  return true;
111
  } else {
bkpwp-pages/bkpwp_manage_backups.php CHANGED
@@ -127,7 +127,10 @@ function bkpwp_delete() {
127
  <form name="form1" method="post" action="">
128
  <input type="hidden" name="bkpwp_delete" value="<?php echo $_REQUEST['bkpwp_delete']; ?>" />
129
  <p style="text-align:left" class="submit">
130
- <input type="submit" name="bkpwp_delete_now" value="<?php _e("delete","bkpwp"); ?> &raquo;" />
 
 
 
131
  </p>
132
  </form>
133
  </p><br />
127
  <form name="form1" method="post" action="">
128
  <input type="hidden" name="bkpwp_delete" value="<?php echo $_REQUEST['bkpwp_delete']; ?>" />
129
  <p style="text-align:left" class="submit">
130
+ <input type="submit" name="bkpwp_delete_now" id="bkpwp_delete_submit" value="<?php _e("delete","bkpwp"); ?> &raquo;" />
131
+ <script type="text/javascript">
132
+ document.getElementById('bkpwp_delete_submit').focus();
133
+ </script>
134
  </p>
135
  </form>
136
  </p><br />
bkpwp-pages/bkpwp_schedule.php CHANGED
@@ -50,7 +50,6 @@ function bkpwp_schedulelist($bkpwppath) {
50
  <td>
51
  <?php
52
  $now = time();
53
- echo $now+120;
54
  $d = $timestamp - $now;
55
  if (!empty($timestamp)) { ?>
56
  <div id="countdowncontainer<?php echo $timestamp; ?>"></div>
50
  <td>
51
  <?php
52
  $now = time();
 
53
  $d = $timestamp - $now;
54
  if (!empty($timestamp)) { ?>
55
  <div id="countdowncontainer<?php echo $timestamp; ?>"></div>
functions.php CHANGED
@@ -274,7 +274,7 @@ function bkpwp_send_file($path) {
274
 
275
  //to prevent long file from getting cut off from //max_execution_time
276
 
277
- set_time_limit(0);
278
 
279
  $name=basename($path);
280
 
274
 
275
  //to prevent long file from getting cut off from //max_execution_time
276
 
277
+ @set_time_limit(0);
278
 
279
  $name=basename($path);
280
 
interface.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,870 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 ADDED
@@ -0,0 +1,449 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ?>
schedule.php ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ ?>