BackUpWordPress - Version 1.3

Version Description

Download this release

Release Info

Developer willmot
Plugin Icon 128x128 BackUpWordPress
Version 1.3
Comparing to
See all releases

Code changes from version 1.2 to 1.3

admin.actions.php CHANGED
@@ -24,15 +24,15 @@ add_action( 'load-tools_page_' . HMBKP_PLUGIN_SLUG, 'hmbkp_request_delete_backup
24
  function hmbkp_request_do_backup() {
25
 
26
  // Are we sure
27
- if ( !isset( $_GET['action'] ) || $_GET['action'] !== 'hmbkp_backup_now' || hmbkp_is_in_progress() || !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) || ini_get( 'safe_mode' ) )
28
  return false;
29
 
30
  // Schedule a single backup
31
  wp_schedule_single_event( time(), 'hmbkp_schedule_single_backup_hook' );
32
-
33
  // Remove the once every 60 seconds limitation
34
  delete_transient( 'doing_cron' );
35
-
36
  // Fire the cron now
37
  spawn_cron();
38
 
@@ -57,13 +57,18 @@ function hmbkp_request_download_backup() {
57
  }
58
  add_action( 'load-tools_page_' . HMBKP_PLUGIN_SLUG, 'hmbkp_request_download_backup' );
59
 
 
 
 
 
 
60
  function hmbkp_ajax_is_backup_in_progress() {
61
 
62
  if ( !hmbkp_is_in_progress() )
63
  echo 0;
64
 
65
- elseif ( get_option( 'hmbkp_status' ) )
66
- echo get_option( 'hmbkp_status' );
67
 
68
  else
69
  echo 1;
@@ -72,21 +77,70 @@ function hmbkp_ajax_is_backup_in_progress() {
72
  }
73
  add_action( 'wp_ajax_hmbkp_is_in_progress', 'hmbkp_ajax_is_backup_in_progress' );
74
 
 
 
 
 
 
75
  function hmbkp_ajax_calculate_backup_size() {
76
  echo hmbkp_calculate();
77
  exit;
78
  }
79
  add_action( 'wp_ajax_hmbkp_calculate', 'hmbkp_ajax_calculate_backup_size' );
80
 
 
 
 
 
 
81
  function hmbkp_ajax_cron_test() {
82
-
83
  $response = wp_remote_get( site_url( 'wp-cron.php' ) );
84
-
85
  if ( !is_wp_error( $response ) && $response['response']['code'] != '200' )
86
  echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( '%s is returning a %s response which could mean cron jobs aren\'t getting fired properly. BackUpWordPress relies on wp-cron to run back ups in a separate process.', 'hmbkp' ), '<code>wp-cron.php</code>', '<code>' . $response['response']['code'] . '</code>' ) . '</p></div>';
87
  else
88
  echo 1;
89
-
90
  exit;
91
  }
92
- add_action( 'wp_ajax_hmbkp_cron_test', 'hmbkp_ajax_cron_test' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  function hmbkp_request_do_backup() {
25
 
26
  // Are we sure
27
+ if ( !isset( $_GET['action'] ) || $_GET['action'] !== 'hmbkp_backup_now' || hmbkp_is_in_progress() || !hmbkp_possible() )
28
  return false;
29
 
30
  // Schedule a single backup
31
  wp_schedule_single_event( time(), 'hmbkp_schedule_single_backup_hook' );
32
+
33
  // Remove the once every 60 seconds limitation
34
  delete_transient( 'doing_cron' );
35
+
36
  // Fire the cron now
37
  spawn_cron();
38
 
57
  }
58
  add_action( 'load-tools_page_' . HMBKP_PLUGIN_SLUG, 'hmbkp_request_download_backup' );
59
 
60
+ /**
61
+ * Display the running status via ajax
62
+ *
63
+ * @return void
64
+ */
65
  function hmbkp_ajax_is_backup_in_progress() {
66
 
67
  if ( !hmbkp_is_in_progress() )
68
  echo 0;
69
 
70
+ elseif ( $status = hmbkp_get_status() )
71
+ echo $status;
72
 
73
  else
74
  echo 1;
77
  }
78
  add_action( 'wp_ajax_hmbkp_is_in_progress', 'hmbkp_ajax_is_backup_in_progress' );
79
 
80
+ /**
81
+ * Display the calculated size via ajax
82
+ *
83
+ * @return void
84
+ */
85
  function hmbkp_ajax_calculate_backup_size() {
86
  echo hmbkp_calculate();
87
  exit;
88
  }
89
  add_action( 'wp_ajax_hmbkp_calculate', 'hmbkp_ajax_calculate_backup_size' );
90
 
91
+ /**
92
+ * Test the cron response and if it's not 200 show a warning message
93
+ *
94
+ * @return void
95
+ */
96
  function hmbkp_ajax_cron_test() {
97
+
98
  $response = wp_remote_get( site_url( 'wp-cron.php' ) );
99
+
100
  if ( !is_wp_error( $response ) && $response['response']['code'] != '200' )
101
  echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( '%s is returning a %s response which could mean cron jobs aren\'t getting fired properly. BackUpWordPress relies on wp-cron to run back ups in a separate process.', 'hmbkp' ), '<code>wp-cron.php</code>', '<code>' . $response['response']['code'] . '</code>' ) . '</p></div>';
102
  else
103
  echo 1;
104
+
105
  exit;
106
  }
107
+ add_action( 'wp_ajax_hmbkp_cron_test', 'hmbkp_ajax_cron_test' );
108
+
109
+ /**
110
+ * Handles changes in the defined Constants
111
+ * that users can define to control advanced
112
+ * settings
113
+ *
114
+ * @return void
115
+ */
116
+ function hmbkp_constant_changes() {
117
+
118
+ // Check whether we need to disable the cron
119
+ if ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) && HMBKP_DISABLE_AUTOMATIC_BACKUP && wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) )
120
+ wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
121
+
122
+ // Or whether we need to re-enable it
123
+ if ( ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) && !HMBKP_DISABLE_AUTOMATIC_BACKUP || !defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) ) && !wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) )
124
+ hmbkp_setup_daily_schedule();
125
+
126
+ // Allow the time of the daily backup to be changed
127
+ if ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) && HMBKP_DAILY_SCHEDULE_TIME && wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) != strtotime( HMBKP_DAILY_SCHEDULE_TIME ) && wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) )
128
+ hmbkp_setup_daily_schedule();
129
+
130
+ // Reset if custom time is removed
131
+ if ( ( ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) && !HMBKP_DAILY_SCHEDULE_TIME ) || !defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) ) && date( 'H:i', wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) ) != '23:00' && ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) && !HMBKP_DISABLE_AUTOMATIC_BACKUP || !defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) ) )
132
+ hmbkp_setup_daily_schedule();
133
+
134
+ // If a custom backup path has been set or changed
135
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH && hmbkp_conform_dir( HMBKP_PATH ) != ( $from = hmbkp_conform_dir( get_option( 'hmbkp_path' ) ) ) )
136
+ hmbkp_path_move( $from, HMBKP_PATH );
137
+
138
+ // If a custom backup path has been removed
139
+ if ( ( ( defined( 'HMBKP_PATH' ) && !HMBKP_PATH ) || !defined( 'HMBKP_PATH' ) && hmbkp_conform_dir( hmbkp_path_default() ) != ( $from = hmbkp_conform_dir( get_option( 'hmbkp_path' ) ) ) ) )
140
+ hmbkp_path_move( $from, hmbkp_path_default() );
141
+
142
+ // If the custom path has changed and the new directory isn't writable
143
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH && hmbkp_conform_dir( HMBKP_PATH ) != ( $from = hmbkp_conform_dir( get_option( 'hmbkp_path' ) ) ) && $from != hmbkp_path_default() && !is_writable( HMBKP_PATH ) && is_dir( $from ) )
144
+ hmbkp_path_move( $from, hmbkp_path_default() );
145
+
146
+ }
admin.advanced-options.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div id="hmbkp_advanced-options">
2
+
3
+ <h4><?php _e( 'Advanced Options', 'hmbkp' ); ?></h4>
4
+
5
+ <p><?php printf( __( 'You can %s any of the following %s in your %s to control advanced options. %s. Defined %s will be highlighted.', 'hmbkp' ), '<code>define</code>', '<code>Constants</code>', '<code>wp-config.php</code>', '<a href="http://codex.wordpress.org/Editing_wp-config.php">' . __( 'The Codex can help', 'hmbkp' ) . '</a>', '<code>Constants</code>' ); ?></p>
6
+
7
+ <dl>
8
+
9
+ <dt<?php if ( defined( 'HMBKP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_PATH</code></dt>
10
+ <dd><p><?php printf( __( 'The path to folder you would like to store your backup files in, defaults to %s.', 'hmbkp' ), '<code>' . hmbkp_path_default() . '</code>' ); ?></p><p class="example">e.g. <code>define( 'HMBKP_PATH', '/home/willmot/backups' );</code></p></dd>
11
+
12
+ <dt<?php if ( defined( 'HMBKP_MYSQLDUMP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_MYSQLDUMP_PATH</code></dt>
13
+ <dd><p><?php printf( __( 'The path to your %s executable. Will be used for the %s part of the back up if available.', 'hmbkp' ), '<code>mysqldump</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>' ); ?></p><p class="example">e.g. <code>define( 'HMBKP_MYSQLDUMP_PATH', '/opt/local/bin/mysqldump' );</code></p></dd>
14
+
15
+ <dt<?php if ( defined( 'HMBKP_ZIP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_ZIP_PATH</code></dt>
16
+ <dd><p><?php printf( __( 'The path to your %s executable. Will be used to zip up your %s and %s if available.', 'hmbkp' ), '<code>zip</code>', '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>' ); ?><p class="example">e.g. <code>define( 'HMBKP_ZIP_PATH', '/opt/local/bin/zip' );</code></p></dd>
17
+
18
+ <dt<?php if ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DISABLE_AUTOMATIC_BACKUP</code></dt>
19
+ <dd><p><?php printf( __( 'Completely disables the automatic back up. You can still back up using the "Back Up Now" button. Defaults to %s.', 'hmbkp' ), '<code>(bool) false</code>' ); ?><p class="example">e.g. <code>define( 'HMBKP_DISABLE_AUTOMATIC_BACKUP', true );</code></p></dd>
20
+
21
+ <dt<?php if ( defined( 'HMBKP_MAX_BACKUPS' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_MAX_BACKUPS</code></dt>
22
+ <dd><p><?php printf( __( 'Number of backups to keep, older backups will be deleted automatically when a new backup is completed. Detaults to %s.', 'hmbkp' ), '<code>(int) 10</code>' ); ?><p class="example">e.g. <code>define( 'HMBKP_MAX_BACKUPS', 5 );</code></p></dd>
23
+
24
+ <dt<?php if ( defined( 'HMBKP_FILES_ONLY' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_FILES_ONLY</code></dt>
25
+ <dd><p><?php printf( __( 'Backup %s only, your %s will %s be backed up. Defaults to %s.', 'hmbkp' ), '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<strong>' . __( 'not', 'hmbkp' ) . '</strong>', '<code>(bool) false</code>' ); ?><p class="example">e.g. <code>define( 'HMBKP_FILES_ONLY', true );</code></p></dd>
26
+
27
+ <dt<?php if ( defined( 'HMBKP_DATABASE_ONLY' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DATABASE_ONLY</code></dt>
28
+ <dd><p><?php printf( __( 'Backup %s only, your %s will %s be backed up. Defaults to %s.', 'hmbkp' ), '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<strong>' . __( 'not', 'hmbkp' ) . '</strong>', '<code>(bool) false</code>' ); ?><p class="example">e.g. <code>define( 'HMBKP_DATABASE_ONLY', true );</code></p></dd>
29
+
30
+ <dt<?php if ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DAILY_SCHEDULE_TIME</code></dt>
31
+ <dd><p><?php printf( __( 'The time that the daily back up should run. Defaults to %s.', 'hmbkp' ), '<code>23:00</code>' ); ?><p class="example">e.g. <code>define( 'HMBKP_DAILY_SCHEDULE_TIME', '07:30' );</code></p></dd>
32
+
33
+ <dt<?php if ( defined( 'HMBKP_EMAIL' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_EMAIL</code></dt>
34
+ <dd><p><?php printf( __( 'Attempt to email a copy of your backups. Value should be email address to send backups to. Defaults to %s.', 'hmbkp' ), '<code>(bool) false</code>' ); ?><p class="example">e.g. <code>define( 'HMBKP_EMAIL', 'email@example.com' );</code></p></dd>
35
+
36
+ <dt<?php if ( defined( 'HMBKP_EXCLUDE' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_EXCLUDE</code></dt>
37
+ <dd><p><?php _e( 'Comma separated list of files or directories to exclude, the backups directory is automatically excluded.', 'hmbkp' ); ?><p class="example">e.g. <code>define( 'HMBKP_EXCLUDE', '/wp-content/uploads/, /stats/, .svn/, *.txt' );</code></p></dd>
38
+
39
+ </dl>
40
+
41
+ </div>
admin.backups-table.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // If max backups has changed
4
+ if ( !hmbkp_is_in_progress() )
5
+ hmbkp_delete_old_backups();
6
+
7
+ $backup_archives = hmbkp_get_backups();
8
+ if ( count( $backup_archives ) ) : ?>
9
+
10
+ <table class="widefat" id="hmbkp_manage_backups_table">
11
+ <thead>
12
+ <tr>
13
+ <th scope="col"><?php printf( _n( '1 backup completed', '%d backups completed', count( $backup_archives ), 'hmbkp' ), count( $backup_archives ) ); ?></th>
14
+ <th scope="col"><?php _e( 'Size', 'hmbkp' ); ?></th>
15
+ <th scope="col"><?php _e( 'Actions', 'hmbkp' ); ?></th>
16
+ </tr>
17
+ </thead>
18
+
19
+ <tfoot>
20
+ <tr>
21
+ <th><?php printf( _n( 'Only the most recent backup will be saved', 'The %d most recent backups will be saved', hmbkp_max_backups(), 'hmbkp' ), hmbkp_max_backups() ); ?></th>
22
+ <th><?php printf( __( 'Total %s', 'hmbkp' ), hmbkp_total_filesize() ); ?></th>
23
+ <th></th>
24
+ </tr>
25
+ </tfoot>
26
+
27
+ <tbody id="the-list">
28
+
29
+ <?php foreach ( (array) $backup_archives as $file ) :
30
+
31
+ if ( !file_exists( $file ) )
32
+ continue;
33
+
34
+ hmbkp_get_backup_row( $file );
35
+
36
+ endforeach; ?>
37
+
38
+ </tbody>
39
+ </table>
40
+
41
+ <?php endif; ?>
admin.menus.php CHANGED
@@ -25,11 +25,38 @@ function hmbkp_manage_backups() {
25
  * @return Array $links
26
  */
27
  function hmbkp_plugin_action_link( $links, $file ) {
28
-
29
  if ( strpos( $file, HMBKP_PLUGIN_SLUG ) !== false )
30
  array_push( $links, '<a href="tools.php?page=' . HMBKP_PLUGIN_SLUG . '">' . __( 'Backups', 'hmbkp' ) . '</a>' );
31
-
32
  return $links;
33
 
34
  }
35
- add_filter('plugin_action_links', 'hmbkp_plugin_action_link', 10, 2 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  * @return Array $links
26
  */
27
  function hmbkp_plugin_action_link( $links, $file ) {
28
+
29
  if ( strpos( $file, HMBKP_PLUGIN_SLUG ) !== false )
30
  array_push( $links, '<a href="tools.php?page=' . HMBKP_PLUGIN_SLUG . '">' . __( 'Backups', 'hmbkp' ) . '</a>' );
31
+
32
  return $links;
33
 
34
  }
35
+ add_filter('plugin_action_links', 'hmbkp_plugin_action_link', 10, 2 );
36
+
37
+ /**
38
+ * Add Contextual Help to Backups tools page.
39
+ *
40
+ * Help is pulled from the readme FAQ.
41
+ * NOTE: FAQ used is from the wordpress repo, and might not be up to date for development versions.
42
+ *
43
+ */
44
+ function hmbkp_contextual_help( $contextual_help, $screen_id, $screen ) {
45
+
46
+ if ( isset( $_GET['page'] ) && $_GET['page'] == HMBKP_PLUGIN_SLUG ) :
47
+
48
+ require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
49
+ $plugin = plugins_api( 'plugin_information', array( 'slug' => 'backupwordpress' ) );
50
+
51
+ // Check if help is for the right version.
52
+ if ( version_compare( HMBKP_VERSION, $plugin->version, '!=' ) )
53
+ $contextual_help = sprintf( '<p><strong>' . __( 'You are not using the latest stable version of BackUpWordPress', 'hmbkp' ) . '</strong>' . __( ' &mdash; The information below is for version %s. View the readme.txt file for help specific to version %s.', 'hmbkp' ) . '</p>', '<code>' . $plugin->version . '</code>', '<code>' . HMBKP_VERSION . '</code>' );
54
+
55
+ $contextual_help .= $plugin->sections['faq'];
56
+
57
+ endif;
58
+
59
+ return $contextual_help;
60
+
61
+ }
62
+ add_filter( 'contextual_help', 'hmbkp_contextual_help', 10, 3 );
admin.page.php CHANGED
@@ -7,9 +7,9 @@
7
  <?php _e( 'Manage Backups', 'hmbkp' ); ?>
8
 
9
  <?php if ( hmbkp_is_in_progress() ) : ?>
10
- <a class="button add-new-h2" <?php disabled( true ); ?>><img src="<?php echo site_url( 'wp-admin/images/wpspin_light.gif' ); ?>" width="16" height="16" /><?php echo get_option( 'hmbkp_status' ); ?></a>
11
 
12
- <?php elseif ( !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) || ini_get( 'safe_mode' ) ) : ?>
13
  <a class="button add-new-h2" <?php disabled( true ); ?>><?php _e( 'Back Up Now', 'hmbkp' ); ?></a>
14
 
15
  <?php else : ?>
@@ -21,143 +21,20 @@
21
 
22
  </h2>
23
 
24
- <?php if ( is_dir( hmbkp_path() ) && is_writable( hmbkp_path() ) && !ini_get( 'safe_mode' ) ) : ?>
25
 
26
- <p>
27
 
28
- <?php if ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) && HMBKP_DISABLE_AUTOMATIC_BACKUP && !wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) ) : ?>
29
-
30
- <?php printf( __( 'Automatic backups are %s.', 'hmbkp' ), '<strong>' . __( 'disabled', 'hmbkp' ) . '</strong>' ); ?>
31
-
32
- <?php else :
33
-
34
- if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY || !defined( 'HMBKP_FILES_ONLY' ) ) && ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY || !defined( 'HMBKP_DATABASE_ONLY' ) ) )
35
- $what_to_backup = '<code>' . __( 'database', 'hmbkp' ) . '</code> ' . __( '&amp;', 'hmbkp' ) . ' <code>' . __( 'files', 'hmbkp' ) . '</code>';
36
-
37
- elseif( defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY )
38
- $what_to_backup = '<code>' . __( 'database', 'hmbkp' ) . '</code>';
39
-
40
- else
41
- $what_to_backup = '<code>' . __( 'files', 'hmbkp' ) . '</code>'; ?>
42
-
43
- <?php printf( __( 'Your %s will be automatically backed up every day at %s into %s.', 'hmbkp' ), $what_to_backup , '<code title="' . sprintf( __( 'It\'s currently %s on the server.', 'hmbkp' ), date( 'H:i' ) ) . '">' . date( 'H:i', wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) ) . '</code>', '<code>' . hmbkp_path() . '</code>' ); ?>
44
-
45
- <?php endif; ?>
46
-
47
- <span class="hmbkp_estimated-size"><?php printf( __( 'Each backup will be roughly %s.', 'hmbkp' ), get_transient( 'hmbkp_estimated_filesize' ) ? '<code>' . hmbkp_calculate() . '</code>' : '<code class="calculate">' . __( 'Calculating Size...', 'hmbkp' ) . '</code>' ); ?></span>
48
-
49
- </p>
50
-
51
- <?php if ( !hmbkp_shell_exec_available() ) : ?>
52
- <p>&#10007; <?php printf( __( '%s is disabled which means we have to use the slower PHP fallbacks, you could try contacting your host and asking them to enable it.', 'hmbkp' ), '<code>shell_exec</code>' ); ?>
53
- <?php endif; ?>
54
-
55
- <?php if ( hmbkp_shell_exec_available() ) : ?>
56
-
57
- <?php if ( hmbkp_zip_path() && ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY || !defined( 'HMBKP_DATABASE_ONLY' ) ) ) : ?>
58
- <p>&#10003; <?php printf( __( 'Your %s will be backed up using the %s command.', 'hmbkp' ), '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . hmbkp_zip_path() . '</code>' ); ?></p>
59
- <?php endif; ?>
60
-
61
- <?php if ( hmbkp_mysqldump_path() && ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY || !defined( 'HMBKP_FILES_ONLY' ) ) ) : ?>
62
- <p>&#10003; <?php printf( __( 'Your %s will be backed up using the %s command.', 'hmbkp' ), '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<code>' . hmbkp_mysqldump_path() . '</code>' ); ?></p>
63
- <?php endif; ?>
64
-
65
- <?php endif; ?>
66
-
67
- <?php if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH ) :
68
- if ( !is_dir( HMBKP_PATH ) || !is_writable( HMBKP_PATH ) ) : ?>
69
- <p>&#10007; <code><?php echo HMBKP_PATH; ?></code><?php printf( __( 'doesn\'t exist or isn\'t writable. your backups will be saved to %s.', 'hmbkp' ), '<code>' . hmbkp_path() . '</code>' ); ?>.</p>
70
-
71
- <?php else : ?>
72
- <p>&#10003; <?php printf( __( 'Your backups will be saved to %s.', 'hmbkp' ), '<code>' . hmbkp_path() . '</code>' ); ?></p>
73
-
74
- <?php endif; ?>
75
- <?php endif ; ?>
76
-
77
- <?php if ( defined( 'HMBKP_EMAIL' ) && HMBKP_EMAIL && is_email( HMBKP_EMAIL ) ) : ?>
78
- <p>&#10003; <?php printf( __( 'A copy of each backup will be emailed to %s.', 'hmbkp' ), '<code>' . HMBKP_EMAIL . '</code>' ); ?></p>
79
- <?php endif; ?>
80
-
81
- <?php $backup_archives = hmbkp_get_backups();
82
- if ( count( $backup_archives ) ) : ?>
83
-
84
- <table class="widefat" id="hmbkp_manage_backups_table">
85
- <thead>
86
- <tr>
87
- <th scope="col"><?php printf( __( '%d Completed backups', 'hmbkp' ), count( $backup_archives ) ); ?></th>
88
- <th scope="col"><?php _e( 'Size', 'hmbkp' ); ?></th>
89
- <th scope="col"><?php _e( 'Actions', 'hmbkp' ); ?></th>
90
- </tr>
91
- </thead>
92
-
93
- <tfoot>
94
- <tr>
95
- <th><?php printf( _n( 'Only the most recent backup will be saved', 'The %d most recent backups will be saved', hmbkp_max_backups(), 'hmbkp' ), hmbkp_max_backups() ); ?></th>
96
- <th><?php printf( __( 'Total %s, %s available', 'hmbkp' ), hmbkp_total_filesize(), hmbkp_size_readable( disk_free_space( ABSPATH ), null, '%01u %s' ) ); ?></th>
97
- <th></th>
98
- </tr>
99
- </tfoot>
100
-
101
- <tbody id="the-list">
102
-
103
- <?php foreach ( (array) $backup_archives as $file ) :
104
-
105
- if ( !file_exists( $file['file'] ) )
106
- continue;
107
-
108
- hmbkp_get_backup_row( $file );
109
-
110
- endforeach; ?>
111
-
112
- </tbody>
113
- </table>
114
-
115
- <?php endif; ?>
116
 
117
  <?php else : ?>
118
 
119
  <p><strong><?php _e( 'You need to fix the issues detailed above before BackUpWordPress can start.', 'hmbkp' ); ?></strong></p>
120
- <?php endif; ?>
121
-
122
- <div id="hmbkp_advanced-options">
123
-
124
- <h4><?php _e( 'Advanced Options', 'hmbkp' ); ?></h4>
125
-
126
- <p><?php printf( __( 'You can %s any of the following %s in your %s to control advanced options. %s. Defined %s will be highlighted.', 'hmbkp' ), '<code>define</code>', '<code>Constants</code>', '<code>wp-config.php</code>', '<a href="http://codex.wordpress.org/Editing_wp-config.php">' . __( 'The Codex can help', 'hmbkp' ) . '</a>', '<code>Constants</code>' ); ?></p>
127
-
128
- <dl>
129
 
130
- <dt<?php if ( defined( 'HMBKP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_PATH</code></dt>
131
- <dd><?php printf( __( 'The path to folder you would like to store your backup files in, defaults to %s.', 'hmbkp' ), '<code>' . hmbkp_path() . '</code>' ); ?></dd>
132
-
133
- <dt<?php if ( defined( 'HMBKP_MYSQLDUMP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_MYSQLDUMP_PATH</code></dt>
134
- <dd><?php printf( __( 'The path to your %s executable. Will be used for the %s part of the back up if available.', 'hmbkp' ), '<code>mysqldump</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>' ); ?></dd>
135
-
136
- <dt<?php if ( defined( 'HMBKP_ZIP_PATH' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_ZIP_PATH</code></dt>
137
- <dd><?php printf( __( 'The path to your %s executable. Will be used to zip up your %s and %s if available.', 'hmbkp' ), '<code>zip</code>', '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>' ); ?></dd>
138
-
139
- <dt<?php if ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DISABLE_AUTOMATIC_BACKUP</code></dt>
140
- <dd><?php printf( __( 'Completely disables the automatic back up. You can still back up using the "Back Up Now" button. Defaults to %s.', 'hmbkp' ), '<code>(bool) false</code>' ); ?></dd>
141
-
142
- <dt<?php if ( defined( 'HMBKP_MAX_BACKUPS' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_MAX_BACKUPS</code></dt>
143
- <dd><?php printf( __( 'Number of backups to keep, older backups will be deleted automatically when a new backup is completed. Detaults to %s.', 'hmbkp' ), '<code>(int) 10</code>' ); ?></dd>
144
-
145
- <dt<?php if ( defined( 'HMBKP_FILES_ONLY' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_FILES_ONLY</code></dt>
146
- <dd><?php printf( __( 'Backup %s only, your %s will %s be backed up. Defaults to %s.', 'hmbkp' ), '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<strong>' . __( 'not', 'hmbkp' ) . '</strong>', '<code>(bool) false</code>' ); ?></dd>
147
-
148
- <dt<?php if ( defined( 'HMBKP_DATABASE_ONLY' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DATABASE_ONLY</code></dt>
149
- <dd><?php printf( __( 'Backup %s only, your %s will %s be backed up. Defaults to %s.', 'hmbkp' ), '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<strong>' . __( 'not', 'hmbkp' ) . '</strong>', '<code>(bool) false</code>' ); ?></dd>
150
-
151
- <dt<?php if ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_DAILY_SCHEDULE_TIME</code></dt>
152
- <dd><?php printf( __( 'The time that the daily back up should run. Defaults to %s.', 'hmbkp' ), '<code>23:00</code>' ); ?></dd>
153
-
154
- <dt<?php if ( defined( 'HMBKP_EMAIL' ) ) { ?> class="hmbkp_active"<?php } ?>><code>HMBKP_EMAIL</code></dt>
155
- <dd><?php printf( __( 'Attempt to email a copy of your backups. Value should be email address to send backups to. Defaults to %s.', 'hmbkp' ), '<code>(bool) false</code>' ); ?></dd>
156
-
157
- </dl>
158
-
159
- </div>
160
 
 
 
161
  <p class="howto"><?php printf( __( 'If you need help getting things working you are more than welcome to email us at %s and we\'ll do what we can to help.', 'hmbkp' ), '<a href="mailto:support@humanmade.co.uk">support@humanmade.co.uk</a>' ); ?></p>
162
 
163
  </div>
7
  <?php _e( 'Manage Backups', 'hmbkp' ); ?>
8
 
9
  <?php if ( hmbkp_is_in_progress() ) : ?>
10
+ <a class="button add-new-h2" <?php disabled( true ); ?>><img src="<?php echo site_url( 'wp-admin/images/wpspin_light.gif' ); ?>" width="16" height="16" /><?php echo hmbkp_get_status(); ?></a>
11
 
12
+ <?php elseif ( !hmbkp_possible() ) : ?>
13
  <a class="button add-new-h2" <?php disabled( true ); ?>><?php _e( 'Back Up Now', 'hmbkp' ); ?></a>
14
 
15
  <?php else : ?>
21
 
22
  </h2>
23
 
24
+ <?php if ( hmbkp_possible() ) : ?>
25
 
26
+ <?php include_once( HMBKP_PLUGIN_PATH . '/admin.status.php' ); ?>
27
 
28
+ <?php include_once( HMBKP_PLUGIN_PATH . '/admin.backups-table.php' ); ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  <?php else : ?>
31
 
32
  <p><strong><?php _e( 'You need to fix the issues detailed above before BackUpWordPress can start.', 'hmbkp' ); ?></strong></p>
 
 
 
 
 
 
 
 
 
33
 
34
+ <?php endif; ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ <?php include_once( HMBKP_PLUGIN_PATH . '/admin.advanced-options.php' ); ?>
37
+
38
  <p class="howto"><?php printf( __( 'If you need help getting things working you are more than welcome to email us at %s and we\'ll do what we can to help.', 'hmbkp' ), '<a href="mailto:support@humanmade.co.uk">support@humanmade.co.uk</a>' ); ?></p>
39
 
40
  </div>
admin.status.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <p>&#10003;
2
+
3
+ <?php if ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) && HMBKP_DISABLE_AUTOMATIC_BACKUP && !wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) ) : ?>
4
+
5
+ <?php printf( __( 'Automatic backups are %s.', 'hmbkp' ), '<strong>' . __( 'disabled', 'hmbkp' ) . '</strong>' ); ?>
6
+
7
+ <?php else :
8
+
9
+ if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY || !defined( 'HMBKP_FILES_ONLY' ) ) && ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY || !defined( 'HMBKP_DATABASE_ONLY' ) ) )
10
+ $what_to_backup = '<code>' . __( 'database', 'hmbkp' ) . '</code> ' . __( '&amp;', 'hmbkp' ) . ' <code>' . __( 'files', 'hmbkp' ) . '</code>';
11
+
12
+ elseif( defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY )
13
+ $what_to_backup = '<code>' . __( 'database', 'hmbkp' ) . '</code>';
14
+
15
+ else
16
+ $what_to_backup = '<code>' . __( 'files', 'hmbkp' ) . '</code>'; ?>
17
+
18
+ <?php printf( __( 'Your %s will be automatically backed up every day at %s to %s.', 'hmbkp' ), $what_to_backup , '<code title="' . sprintf( __( 'It\'s currently %s on the server.', 'hmbkp' ), date( 'H:i' ) ) . '">' . date( 'H:i', wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) ) . '</code>', '<code>' . hmbkp_path() . '</code>' ); ?>
19
+
20
+ <?php endif; ?>
21
+
22
+ <p>&#10003; <span class="hmbkp_estimated-size"><?php printf( __( 'Your site is %s. Backups will be compressed and should be smaller than this.', 'hmbkp' ), get_transient( 'hmbkp_estimated_filesize' ) ? '<code>' . hmbkp_calculate() . '</code>' : '<code class="calculate">' . __( 'Calculating Size...', 'hmbkp' ) . '</code>' ); ?></span></p>
23
+
24
+ <?php if ( !hmbkp_shell_exec_available() ) : ?>
25
+ <p>&#10007; <?php printf( __( '%s is disabled which means we have to use the slower PHP fallbacks, you could try contacting your host and asking them to enable it.', 'hmbkp' ), '<code>shell_exec</code>' ); ?>
26
+ <?php endif; ?>
27
+
28
+ <?php if ( hmbkp_shell_exec_available() ) : ?>
29
+
30
+ <?php if ( hmbkp_zip_path() && ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY || !defined( 'HMBKP_DATABASE_ONLY' ) ) ) : ?>
31
+ <p>&#10003; <?php printf( __( 'Your %s will be backed up using %s.', 'hmbkp' ), '<code>' . __( 'files', 'hmbkp' ) . '</code>', '<code>' . hmbkp_zip_path() . '</code>' ); ?></p>
32
+ <?php endif; ?>
33
+
34
+ <?php if ( hmbkp_mysqldump_path() && ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY || !defined( 'HMBKP_FILES_ONLY' ) ) ) : ?>
35
+ <p>&#10003; <?php printf( __( 'Your %s will be backed up using %s.', 'hmbkp' ), '<code>' . __( 'database', 'hmbkp' ) . '</code>', '<code>' . hmbkp_mysqldump_path() . '</code>' ); ?></p>
36
+ <?php endif; ?>
37
+
38
+ <?php endif; ?>
39
+
40
+ <?php if ( defined( 'HMBKP_EMAIL' ) && HMBKP_EMAIL && is_email( HMBKP_EMAIL ) ) : ?>
41
+ <p>&#10003; <?php printf( __( 'A copy of each backup will be emailed to %s.', 'hmbkp' ), '<code>' . HMBKP_EMAIL . '</code>' ); ?></p>
42
+ <?php endif; ?>
43
+
44
+ <?php if ( ( $valid_excludes = hmbkp_valid_custom_excludes() ) && ( !defined( 'HMBKP_DATABASE_ONLY' ) || ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) ) ) : ?>
45
+ <p>&#10003; <?php printf( __( 'The following paths will be excluded from your backups %s.', 'hmbkp' ), '<code>' . implode( '</code>, <code>', $valid_excludes ) . '</code>' ); ?></p>
46
+ <?php endif; ?>
assets/hmbkp.css CHANGED
@@ -5,12 +5,17 @@
5
  tfoot p { margin: 0; font-weight: normal; }
6
  #hmbkp_advanced-options { display: none; }
7
  #hmbkp_advanced-options dl { overflow: hidden; margin: 20px 0; }
8
- #hmbkp_advanced-options dt { float: left; width: 250px; clear: both; padding: 6px 0; margin: 1px 0; }
9
- #hmbkp_advanced-options dd { color: #666; padding: 7px 0 7px 250px; border-top: 1px solid #DFDFDF; margin: 0; }
10
  #hmbkp_advanced-options dd:last-child { border-bottom: 1px solid #DFDFDF; }
 
 
 
 
 
 
11
  .hmbkp_manage_backups_row .delete { color: #BC0B0B; }
12
  .hmbkp_manage_backups_row .delete:hover { color: red; }
13
  .completed th, .completed td { background-color: #FFFFE0; }
14
  .hmbkp_active:before { content: "\00a0 \2713 "; font-size: 11px; }
15
- .hmbkp_active, .hmbkp_active code, #hmbkp_advanced-options .hmbkp_active + dd { background: #E5F7E8; }
16
- #hmbkp_advanced-options dt:not(.hmbkp_active) + dd { background: #F9F9F9; }
5
  tfoot p { margin: 0; font-weight: normal; }
6
  #hmbkp_advanced-options { display: none; }
7
  #hmbkp_advanced-options dl { overflow: hidden; margin: 20px 0; }
8
+ #hmbkp_advanced-options dt { float: left; min-width: 250px; clear: both; padding: 6px; margin: 1px 0; cursor: pointer; }
9
+ #hmbkp_advanced-options dd { color: #666; padding: 7px 0 7px 250px; border-top: 1px solid #DFDFDF; margin: 0; cursor: pointer; min-height: 34px; }
10
  #hmbkp_advanced-options dd:last-child { border-bottom: 1px solid #DFDFDF; }
11
+ #hmbkp_advanced-options dt:not(.hmbkp_active) + dd { background: #F9F9F9; }
12
+ #hmbkp_advanced-options dd .example { white-space: nowrap; display: none; }
13
+ #hmbkp_advanced-options dd p { margin: 0; }
14
+ #hmbkp_advanced-options dt:not(.hmbkp_active):hover + dd, #hmbkp_advanced-options dt:not(.hmbkp_active) + dd:hover { background-color: #FFF; }
15
+ #hmbkp_advanced-options dd:hover p, #hmbkp_advanced-options dt:hover + dd p { display: none; }
16
+ #hmbkp_advanced-options dd:hover .example, #hmbkp_advanced-options dt:hover + dd .example { display: inline; }
17
  .hmbkp_manage_backups_row .delete { color: #BC0B0B; }
18
  .hmbkp_manage_backups_row .delete:hover { color: red; }
19
  .completed th, .completed td { background-color: #FFFFE0; }
20
  .hmbkp_active:before { content: "\00a0 \2713 "; font-size: 11px; }
21
+ .hmbkp_active, .hmbkp_active code, #hmbkp_advanced-options .hmbkp_active + dd { background: #E5F7E8; }
 
assets/hmbkp.js CHANGED
@@ -4,15 +4,16 @@ jQuery( document ).ready( function( $ ) {
4
  hmbkpRedirectOnBackupComplete();
5
  }
6
 
7
- $.get( ajaxurl, { 'action' : 'hmbkp_calculate' },
8
- function( data ) {
9
- $( '.hmbkp_estimated-size .calculate' ).removeClass( 'calculating' );
10
- $( '.hmbkp_estimated-size .calculate' ).fadeOut( function() {
11
- $( this ).empty().append( data );
12
- } ).fadeIn();
13
- }
14
- );
15
-
 
16
  $.get( ajaxurl, { 'action' : 'hmbkp_cron_test' },
17
  function( data ) {
18
  if ( data != 1 ) {
4
  hmbkpRedirectOnBackupComplete();
5
  }
6
 
7
+ if ( $( '.hmbkp_estimated-size .calculate' ).size() ) {
8
+ $.get( ajaxurl, { 'action' : 'hmbkp_calculate' },
9
+ function( data ) {
10
+ $( '.hmbkp_estimated-size .calculate' ).fadeOut( function() {
11
+ $( this ).empty().append( data );
12
+ } ).fadeIn();
13
+ }
14
+ );
15
+ }
16
+
17
  $.get( ajaxurl, { 'action' : 'hmbkp_cron_test' },
18
  function( data ) {
19
  if ( data != 1 ) {
backup.files.fallback.functions.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Fallback for creating zip archive if zip command is
5
+ * unnavailable.
6
+ *
7
+ * Uses the PCLZIP library that ships with WordPress
8
+ *
9
+ * @todo support zipArchive
10
+ * @param string $path
11
+ */
12
+ function hmbkp_archive_files_fallback( $path ) {
13
+
14
+ require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
15
+
16
+ $archive = new PclZip( $path );
17
+
18
+ // Zip up everything
19
+ if ( ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) || !defined( 'HMBKP_DATABASE_ONLY' ) )
20
+ $archive->create( ABSPATH, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_CB_PRE_ADD, 'hmbkp_pclzip_exclude' );
21
+
22
+ // Only zip up the database
23
+ if ( defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY )
24
+ $archive->create( hmbkp_path() . '/database_' . DB_NAME . '.sql', PCLZIP_OPT_REMOVE_PATH, hmbkp_path() );
25
+
26
+ }
27
+
28
+ /**
29
+ * Add file callback, excludes files in the backups directory
30
+ * and sets the database dump to be stored in the root
31
+ * of the zip
32
+ *
33
+ * @param string $event
34
+ * @param array &$file
35
+ * @return bool
36
+ */
37
+ function hmbkp_pclzip_exclude( $event, &$file ) {
38
+
39
+ $excludes = hmbkp_exclude_string( 'pclzip' );
40
+
41
+ // Include the database file
42
+ if ( strpos( $file['filename'], 'database_' . DB_NAME . '.sql' ) !== false )
43
+ $file['stored_filename'] = 'database_' . DB_NAME . '.sql';
44
+
45
+ // Match everything else past the exclude list
46
+ elseif ( preg_match( '(' . $excludes . ')', $file['stored_filename'] ) )
47
+ return false;
48
+
49
+ return true;
50
+
51
+ }
backup.files.functions.php ADDED
@@ -0,0 +1,238 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Zip up all the wordpress files.
5
+ *
6
+ * Attempts to use the shell zip command, if
7
+ * thats not available then it fallsback on
8
+ * PHP zip classes.
9
+ *
10
+ * @param string $path
11
+ */
12
+ function hmbkp_archive_files( $path ) {
13
+
14
+ // Do we have the path to the zip command
15
+ if ( hmbkp_zip_path() ) :
16
+
17
+ // Zip up ABSPATH
18
+ if ( ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) || !defined( 'HMBKP_DATABASE_ONLY' ) ) :
19
+
20
+ $excludes = ' -x ' . hmbkp_exclude_string( 'zip' );
21
+
22
+ shell_exec( 'cd ' . escapeshellarg( ABSPATH ) . ' && ' . escapeshellarg( hmbkp_zip_path() ) . ' -rq ' . escapeshellarg( $path ) . ' ./' . $excludes );
23
+
24
+ endif;
25
+
26
+ // Add the database dump to the archive
27
+ if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) ) :
28
+ shell_exec( 'cd ' . escapeshellarg( hmbkp_path() ) . ' && ' . escapeshellarg( hmbkp_zip_path() ) . ' -uq ' . escapeshellarg( $path ) . ' ' . escapeshellarg( 'database_' . DB_NAME . '.sql' ) );
29
+ endif;
30
+
31
+ // If not use the fallback
32
+ else :
33
+ hmbkp_archive_files_fallback( $path );
34
+
35
+ endif;
36
+
37
+ }
38
+
39
+ /**
40
+ * Attempt to work out the path to the zip command
41
+ *
42
+ * Can be overridden by defining HMBKP_ZIP_PATH in
43
+ * wp-config.php.
44
+ *
45
+ * @return string $path on success, empty string on failure
46
+ */
47
+ function hmbkp_zip_path() {
48
+
49
+ if ( !hmbkp_shell_exec_available() || ( defined( 'HMBKP_ZIP_PATH' ) && !HMBKP_ZIP_PATH ) )
50
+ return false;
51
+
52
+ $path = '';
53
+
54
+ // List of possible zip locations
55
+ $zip_locations = array(
56
+ 'zip',
57
+ '/usr/bin/zip'
58
+ );
59
+
60
+ // Allow the path to be overridden
61
+ if ( defined( 'HMBKP_ZIP_PATH' ) && HMBKP_ZIP_PATH )
62
+ array_unshift( $zip_locations, HMBKP_ZIP_PATH );
63
+
64
+ // If we don't have a path set
65
+ if ( !$path = get_option( 'hmbkp_zip_path' ) ) :
66
+
67
+ // Try to find out where zip is
68
+ foreach ( $zip_locations as $location )
69
+ if ( shell_exec( 'which ' . $location ) )
70
+ $path = $location;
71
+
72
+ // Save it for later
73
+ if ( $path )
74
+ update_option( 'hmbkp_zip_path', $path );
75
+
76
+ endif;
77
+
78
+ // Check again in-case the saved path has stopped working for some reason
79
+ if ( $path && !shell_exec( 'which ' . $path ) ) :
80
+ delete_option( 'hmbkp_zip_path' );
81
+ return hmbkp_zip_path();
82
+
83
+ endif;
84
+
85
+ return $path;
86
+
87
+ }
88
+
89
+ /**
90
+ * Returns an array of default exclude paths
91
+ *
92
+ * @access public
93
+ * @return array
94
+ */
95
+ function hmbkp_excludes() {
96
+
97
+ // Exclude the back up path
98
+ $excludes[] = hmbkp_path();
99
+
100
+ // Exclude the default back up path
101
+ $excludes[] = hmbkp_path_default();
102
+
103
+ // Exclude the custom path if one is defined
104
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH )
105
+ $excludes[] = hmbkp_conform_dir( HMBKP_PATH );
106
+
107
+ return array_map( 'trailingslashit', array_unique( $excludes ) );
108
+
109
+ }
110
+
111
+ /**
112
+ * Generate the exclude param string for the zip backup
113
+ *
114
+ * Takes the exclude rules and formats them for use with either
115
+ * the shell zip command or pclzip
116
+ *
117
+ * @param string $context. (default: 'zip')
118
+ * @return string
119
+ */
120
+ function hmbkp_exclude_string( $context = 'zip' ) {
121
+
122
+ // Return a comma separated list by default
123
+ $separator = ', ';
124
+ $wildcard = '';
125
+
126
+ // The zip command
127
+ if ( $context == 'zip' ) :
128
+ $wildcard = '*';
129
+ $separator = ' -x ';
130
+
131
+ // The PCLZIP fallback library
132
+ elseif ( $context == 'pclzip' ) :
133
+ $wildcard = '([.]*?)';
134
+ $separator = '|';
135
+
136
+ endif;
137
+
138
+ // Get the excludes
139
+ $excludes = hmbkp_excludes();
140
+
141
+ // Add any defined excludes
142
+ if ( defined( 'HMBKP_EXCLUDE' ) && HMBKP_EXCLUDE )
143
+ $excludes = array_merge( explode( ',', HMBKP_EXCLUDE ), $excludes );
144
+
145
+ $excludes = array_map( 'trim', $excludes );
146
+
147
+ // Add wildcards to the directories
148
+ foreach( $excludes as $key => &$rule ) :
149
+
150
+ $file = $absolute = $fragment = false;
151
+
152
+ // Files don't end with /
153
+ if ( !in_array( substr( $rule, -1 ), array( '\\', '/' ) ) )
154
+ $file = true;
155
+
156
+ // If rule starts with a / then treat as absolute path
157
+ elseif ( in_array( substr( $rule, 0, 1 ), array( '\\', '/' ) ) )
158
+ $absolute = true;
159
+
160
+ // Otherwise treat as dir fragment
161
+ else
162
+ $fragment = true;
163
+
164
+ // Strip ABSPATH and conform
165
+ $rule = str_replace( hmbkp_conform_dir( ABSPATH ), '', untrailingslashit( hmbkp_conform_dir( $rule ) ) );
166
+
167
+ if ( in_array( substr( $rule, 0, 1 ), array( '\\', '/' ) ) )
168
+ $rule = substr( $rule, 1 );
169
+
170
+ // Escape string for regex
171
+ if ( $context == 'pclzip' )
172
+ //$rule = preg_quote( $rule );
173
+ $rule = str_replace( '.', '\.', $rule );
174
+
175
+ // Convert any existing wildcards
176
+ if ( $wildcard != '*' && strpos( $rule, '*' ) !== false )
177
+ $rule = str_replace( '*', $wildcard, $rule );
178
+
179
+ // Wrap directory fragments in wildcards for zip
180
+ if ( $context == 'zip' && $fragment )
181
+ $rule = $wildcard . $rule . $wildcard;
182
+
183
+ // Add a wildcard to the end of absolute url for zips
184
+ if ( $context == 'zip' && $absolute )
185
+ $rule .= $wildcard;
186
+
187
+ // Add and end carrot to files for pclzip
188
+ if ( $file && $context == 'pclzip' )
189
+ $rule .= '$';
190
+
191
+ // Add a start carrot to absolute urls for pclzip
192
+ if ( $absolute && $context == 'pclzip' )
193
+ $rule = '^' . $rule;
194
+
195
+ endforeach;
196
+
197
+ // Escape shell args for zip command
198
+ if ( $context == 'zip' )
199
+ $excludes = array_map( 'escapeshellarg', $excludes );
200
+
201
+ return implode( $separator, $excludes );
202
+
203
+ }
204
+
205
+ /**
206
+ * Return an array of invalid custom exclude rules
207
+ *
208
+ * @return array
209
+ */
210
+ function hmbkp_invalid_custom_excludes() {
211
+
212
+ $invalid_rules = array();
213
+
214
+ // Check if any absolute path excludes actually exist
215
+ if ( defined( 'HMBKP_EXCLUDE' ) && HMBKP_EXCLUDE )
216
+ foreach ( explode( ',', HMBKP_EXCLUDE ) as $rule )
217
+ if ( ( $rule = trim( $rule ) ) && in_array( substr( $rule, 0, 1 ), array( '/', '\\' ) ) && !file_exists( $rule ) && !file_exists( ABSPATH . $rule ) && !file_exists( trailingslashit( ABSPATH ) . $rule ) )
218
+ $invalid_rules[] = $rule;
219
+
220
+ return $invalid_rules;
221
+
222
+ }
223
+
224
+ /**
225
+ * Return an array of valid custom exclude rules
226
+ *
227
+ * @return array
228
+ */
229
+ function hmbkp_valid_custom_excludes() {
230
+
231
+ $valid_rules = array();
232
+
233
+ if ( defined( 'HMBKP_EXCLUDE' ) && HMBKP_EXCLUDE )
234
+ $valid_rules = array_diff( explode( ',', HMBKP_EXCLUDE ), hmbkp_invalid_custom_excludes() );
235
+
236
+ return array_map( 'trim', $valid_rules );
237
+
238
+ }
backup.functions.php ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Backup database and files
5
+ *
6
+ * Creates a temporary directory containing a copy of all files
7
+ * and a dump of the database. Then zip that up and delete the temporary files
8
+ *
9
+ * @uses hmbkp_backup_mysql
10
+ * @uses hmbkp_backup_files
11
+ * @uses hmbkp_delete_old_backups
12
+ */
13
+ function hmbkp_do_backup() {
14
+
15
+ // Make sure it's possible to do a backup
16
+ if ( !hmbkp_possible() )
17
+ return false;
18
+
19
+ // Clean up any mess left by the last backup
20
+ hmbkp_cleanup();
21
+
22
+ $time_start = date( 'Y-m-d-H-i-s' );
23
+
24
+ $filename = sanitize_file_name( get_bloginfo( 'name' ) . '.backup.' . $time_start . '.zip' );
25
+ $filepath = trailingslashit( hmbkp_path() ) . $filename;
26
+
27
+ // Set as running for a max of 1 hour
28
+ hmbkp_set_status();
29
+
30
+ // Raise the memory limit
31
+ @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
32
+ @set_time_limit( 0 );
33
+
34
+ hmbkp_set_status( __( 'Dumping database', 'hmbkp' ) );
35
+
36
+ // Backup database
37
+ if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) )
38
+ hmbkp_backup_mysql();
39
+
40
+ hmbkp_set_status( __( 'Creating zip archive', 'hmbkp' ) );
41
+
42
+ // Zip everything up
43
+ hmbkp_archive_files( $filepath );
44
+
45
+ // Delete the database dump file
46
+ if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) )
47
+ unlink( hmbkp_path() . '/database_' . DB_NAME . '.sql' );
48
+
49
+ // Email Backup
50
+ hmbkp_email_backup( $filepath );
51
+
52
+ hmbkp_set_status( __( 'Removing old backups', 'hmbkp' ) );
53
+
54
+ // Delete any old backup files
55
+ hmbkp_delete_old_backups();
56
+
57
+ unlink( hmbkp_path() . '/.backup_running' );
58
+
59
+ $file = hmbkp_path() . '/.backup_complete';
60
+
61
+ if ( !$handle = @fopen( $file, 'w' ) )
62
+ return false;
63
+
64
+ fwrite( $handle );
65
+
66
+ fclose( $handle );
67
+
68
+
69
+ }
70
+
71
+ /**
72
+ * Deletes old backup files
73
+ */
74
+ function hmbkp_delete_old_backups() {
75
+
76
+ $files = hmbkp_get_backups();
77
+
78
+ if ( count( $files ) <= hmbkp_max_backups() )
79
+ return;
80
+
81
+ foreach( array_slice( $files, hmbkp_max_backups() ) as $file )
82
+ hmbkp_delete_backup( base64_encode( $file ) );
83
+
84
+ }
85
+
86
+ /**
87
+ * Returns an array of backup files
88
+ */
89
+ function hmbkp_get_backups() {
90
+
91
+ $files = array();
92
+
93
+ $hmbkp_path = hmbkp_path();
94
+
95
+ if ( $handle = opendir( $hmbkp_path ) ) :
96
+
97
+ while ( false !== ( $file = readdir( $handle ) ) )
98
+ if ( strpos( $file, '.zip' ) !== false )
99
+ $files[filemtime( trailingslashit( $hmbkp_path ) . $file )] = trailingslashit( $hmbkp_path ) . $file;
100
+
101
+ closedir( $handle );
102
+
103
+ endif;
104
+
105
+ // If there is a custom backups directory and it's not writable then include those backups as well
106
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH && is_dir( HMBKP_PATH ) && !is_writable( HMBKP_PATH ) ) :
107
+
108
+ if ( $handle = opendir( HMBKP_PATH ) ) :
109
+
110
+ while ( false !== ( $file = readdir( $handle ) ) )
111
+ if ( strpos( $file, '.zip' ) !== false )
112
+ $files[filemtime( trailingslashit( HMBKP_PATH ) . $file )] = trailingslashit( HMBKP_PATH ) . $file;
113
+
114
+ closedir( $handle );
115
+
116
+ endif;
117
+
118
+ endif;
119
+
120
+ krsort( $files );
121
+
122
+ return $files;
123
+ }
124
+
125
+ /**
126
+ * Delete a backup file
127
+ *
128
+ * @param $file base64 encoded filename
129
+ */
130
+ function hmbkp_delete_backup( $file ) {
131
+
132
+ $file = base64_decode( $file );
133
+
134
+ // Delete the file
135
+ if ( strpos( $file, hmbkp_path() ) !== false || strpos( $file, WP_CONTENT_DIR . '/backups' ) !== false )
136
+ unlink( $file );
137
+
138
+ }
139
+
140
+ /**
141
+ * Check if a backup is running
142
+ *
143
+ * @return bool
144
+ */
145
+ function hmbkp_is_in_progress() {
146
+ return file_exists( hmbkp_path() . '/.backup_running' );
147
+ }
148
+
149
+ /**
150
+ * Email backup.
151
+ *
152
+ * @param $file
153
+ * @return bool
154
+ */
155
+ function hmbkp_email_backup( $file ) {
156
+
157
+ if ( !defined('HMBKP_EMAIL' ) || !HMBKP_EMAIL || !is_email( HMBKP_EMAIL ) )
158
+ return;
159
+
160
+ // Raise the memory and time limit
161
+ @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
162
+ @set_time_limit( 0 );
163
+
164
+ $download = get_bloginfo( 'wpurl' ) . '/wp-admin/tools.php?page=' . HMBKP_PLUGIN_SLUG . '&hmbkp_download=' . base64_encode( $file );
165
+ $domain = parse_url( get_bloginfo( 'url' ), PHP_URL_HOST ) . parse_url( get_bloginfo( 'url' ), PHP_URL_PATH );
166
+
167
+ $subject = sprintf( __( 'Backup of %s', 'hmbkp' ), $domain );
168
+ $message = sprintf( __( "BackUpWordPress has completed a backup of your site %s.\n\nThe backup file should be attached to this email.\n\nYou can also download the backup file by clicking the link below:\n\n%s\n\nKind Regards\n\n The Happy BackUpWordPress Backup Emailing Robot", 'hmbkp' ), get_bloginfo( 'url' ), $download );
169
+ $headers = 'From: BackUpWordPress <' . get_bloginfo( 'admin_email' ) . '>' . "\r\n";
170
+
171
+ // Try to send the email
172
+ $sent = wp_mail( HMBKP_EMAIL, $subject, $message, $headers, $file );
173
+
174
+ // If it failed- Try to send a download link - The file was probably too large.
175
+ if ( !$sent ) :
176
+
177
+ $subject = sprintf( __( 'Backup of %s', 'hmbkp' ), $domain );
178
+ $message = sprintf( __( "BackUpWordPress has completed a backup of your site %s.\n\nUnfortunately the backup file was too large to attach to this email.\n\nYou can download the backup file by clicking the link below:\n\n%s\n\nKind Regards\n\n The Happy BackUpWordPress Backup Emailing Robot", 'hmbkp' ), get_bloginfo( 'url' ), $download );
179
+
180
+ $sent = wp_mail( HMBKP_EMAIL, $subject, $message, $headers );
181
+
182
+ endif;
183
+
184
+ // Set option for email not sent error
185
+ if ( !$sent )
186
+ update_option( 'hmbkp_email_error', 'hmbkp_email_failed' );
187
+ else
188
+ delete_option( 'hmbkp_email_error' );
189
+
190
+ return true;
191
+
192
+ }
193
+
194
+ /**
195
+ * Set the status of the running backup
196
+ *
197
+ * @param string $message. (default: '')
198
+ * @return void
199
+ */
200
+ function hmbkp_set_status( $message = '' ) {
201
+
202
+ $file = hmbkp_path() . '/.backup_running';
203
+
204
+ if ( !$handle = @fopen( $file, 'w' ) )
205
+ return false;
206
+
207
+ fwrite( $handle, $message );
208
+
209
+ fclose( $handle );
210
+
211
+ }
212
+
213
+ /**
214
+ * Get the status of the running backup
215
+ *
216
+ * @return string
217
+ */
218
+ function hmbkp_get_status() {
219
+
220
+ if ( !file_exists( hmbkp_path() . '/.backup_running' ) )
221
+ return false;
222
+
223
+ return file_get_contents( hmbkp_path() .'/.backup_running' );
224
+
225
+ }
backup.mysql.fallback.functions.php ADDED
@@ -0,0 +1,260 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * hmbkp_backquote function.
5
+ *
6
+ * Add backquotes to tables and db-names inSQL queries. Taken from phpMyAdmin.
7
+ *
8
+ * @access public
9
+ * @param mixed $a_name
10
+ */
11
+ function hmbkp_backquote( $a_name ) {
12
+
13
+ if ( !empty( $a_name ) && $a_name != '*' ) :
14
+
15
+ if ( is_array( $a_name ) ) :
16
+ $result = array();
17
+ reset( $a_name );
18
+
19
+ while ( list( $key, $val ) = each( $a_name ) )
20
+ $result[$key] = '`' . $val . '`';
21
+
22
+ return $result;
23
+
24
+ else :
25
+ return '`' . $a_name . '`';
26
+
27
+ endif;
28
+
29
+ else :
30
+ return $a_name;
31
+ endif;
32
+ }
33
+
34
+ /**
35
+ * hmbkp_make_sql function.
36
+ *
37
+ * Reads the Database table in $table and creates
38
+ * SQL Statements for recreating structure and data
39
+ * Taken partially from phpMyAdmin and partially from
40
+ * Alain Wolf, Zurich - Switzerland
41
+ * Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
42
+ *
43
+ * @access public
44
+ * @param mixed $sql_file
45
+ * @param mixed $table
46
+ */
47
+ function hmbkp_make_sql( $sql_file, $table ) {
48
+
49
+ global $hmbkp_db_connect;
50
+
51
+ // Add SQL statement to drop existing table
52
+ $sql_file = "\n";
53
+ $sql_file .= "\n";
54
+ $sql_file .= "#\n";
55
+ $sql_file .= "# Delete any existing table " . hmbkp_backquote( $table ) . "\n";
56
+ $sql_file .= "#\n";
57
+ $sql_file .= "\n";
58
+ $sql_file .= "DROP TABLE IF EXISTS " . hmbkp_backquote( $table ) . ";\n";
59
+
60
+ /* Table Structure */
61
+
62
+ // Comment in SQL-file
63
+ $sql_file .= "\n";
64
+ $sql_file .= "\n";
65
+ $sql_file .= "#\n";
66
+ $sql_file .= "# Table structure of table " . hmbkp_backquote( $table ) . "\n";
67
+ $sql_file .= "#\n";
68
+ $sql_file .= "\n";
69
+
70
+ // Get table structure
71
+ $query = 'SHOW CREATE TABLE ' . hmbkp_backquote( $table );
72
+ $result = mysql_query( $query, $hmbkp_db_connect );
73
+
74
+ if ( $result ) :
75
+
76
+ if ( mysql_num_rows( $result ) > 0 ) :
77
+ $sql_create_arr = mysql_fetch_array( $result );
78
+ $sql_file .= $sql_create_arr[1];
79
+ endif;
80
+
81
+ mysql_free_result( $result );
82
+ $sql_file .= ' ;';
83
+
84
+ endif;
85
+
86
+ /* Table Contents */
87
+
88
+ // Get table contents
89
+ $query = 'SELECT * FROM ' . hmbkp_backquote( $table );
90
+ $result = mysql_query( $query, $hmbkp_db_connect );
91
+
92
+ if ( $result ) :
93
+ $fields_cnt = mysql_num_fields( $result );
94
+ $rows_cnt = mysql_num_rows( $result );
95
+ endif;
96
+
97
+ // Comment in SQL-file
98
+ $sql_file .= "\n";
99
+ $sql_file .= "\n";
100
+ $sql_file .= "#\n";
101
+ $sql_file .= "# Data contents of table " . $table . " (" . $rows_cnt . " records)\n";
102
+ $sql_file .= "#\n";
103
+
104
+ // Checks whether the field is an integer or not
105
+ for ( $j = 0; $j < $fields_cnt; $j++ ) :
106
+ $field_set[$j] = hmbkp_backquote( mysql_field_name( $result, $j ) );
107
+ $type = mysql_field_type( $result, $j );
108
+
109
+ if ( $type == 'tinyint' || $type == 'smallint' || $type == 'mediumint' || $type == 'int' || $type == 'bigint' ||$type == 'timestamp')
110
+ $field_num[$j] = true;
111
+ else
112
+ $field_num[$j] = false;
113
+
114
+ endfor;
115
+
116
+ // Sets the scheme
117
+ $entries = 'INSERT INTO ' . hmbkp_backquote($table) . ' VALUES (';
118
+ $search = array( '\x00', '\x0a', '\x0d', '\x1a' ); //\x08\\x09, not required
119
+ $replace = array( '\0', '\n', '\r', '\Z' );
120
+ $current_row = 0;
121
+ $batch_write = 0;
122
+
123
+ while ( $row = mysql_fetch_row( $result ) ) :
124
+ $current_row++;
125
+
126
+ // build the statement
127
+ for ( $j = 0; $j < $fields_cnt; $j++ ) :
128
+
129
+ if ( !isset($row[$j] ) ) :
130
+ $values[] = 'NULL';
131
+
132
+ elseif ( $row[$j] == '0' || $row[$j] != '' ) :
133
+
134
+ // a number
135
+ if ( $field_num[$j] )
136
+ $values[] = $row[$j];
137
+
138
+ else
139
+ $values[] = "'" . str_replace( $search, $replace, hmbkp_sql_addslashes( $row[$j] ) ) . "'";
140
+
141
+ else :
142
+ $values[] = "''";
143
+ endif;
144
+
145
+ endfor;
146
+
147
+ $sql_file .= " \n" . $entries . implode( ', ', $values ) . ") ;";
148
+
149
+ // write the rows in batches of 100
150
+ if ( $batch_write == 100 ) :
151
+ $batch_write = 0;
152
+ hmbkp_write_sql( $sql_file );
153
+ $sql_file = '';
154
+ endif;
155
+
156
+ $batch_write++;
157
+
158
+ unset( $values );
159
+
160
+ endwhile;
161
+
162
+ mysql_free_result( $result );
163
+
164
+ // Create footer/closing comment in SQL-file
165
+ $sql_file .= "\n";
166
+ $sql_file .= "#\n";
167
+ $sql_file .= "# End of data contents of table " . $table . "\n";
168
+ $sql_file .= "# --------------------------------------------------------\n";
169
+ $sql_file .= "\n";
170
+
171
+ hmbkp_write_sql( $sql_file );
172
+
173
+ }
174
+
175
+ /**
176
+ * hmbkp_sql_addslashes function.
177
+ *
178
+ * Better addslashes for SQL queries.
179
+ * Taken from phpMyAdmin.
180
+ *
181
+ * @access public
182
+ * @param string $a_string. (default: '')
183
+ * @param bool $is_like. (default: false)
184
+ */
185
+ function hmbkp_sql_addslashes( $a_string = '', $is_like = false ) {
186
+
187
+ if ( $is_like )
188
+ $a_string = str_replace( '\\', '\\\\\\\\', $a_string );
189
+
190
+ else
191
+ $a_string = str_replace( '\\', '\\\\', $a_string );
192
+
193
+ $a_string = str_replace( '\'', '\\\'', $a_string );
194
+
195
+ return $a_string;
196
+ }
197
+
198
+ /**
199
+ * hmbkp_mysql function.
200
+ *
201
+ * @access public
202
+ */
203
+ function hmbkp_backup_mysql_fallback() {
204
+
205
+ global $hmbkp_db_connect;
206
+
207
+ $hmbkp_db_connect = mysql_pconnect( DB_HOST, DB_USER, DB_PASSWORD );
208
+
209
+ mysql_select_db( DB_NAME, $hmbkp_db_connect );
210
+
211
+ // Begin new backup of MySql
212
+ $tables = mysql_list_tables( DB_NAME );
213
+
214
+ $sql_file = "# WordPress : " . get_bloginfo( 'url' ) . " MySQL database backup\n";
215
+ $sql_file .= "#\n";
216
+ $sql_file .= "# Generated: " . date( 'l j. F Y H:i T' ) . "\n";
217
+ $sql_file .= "# Hostname: " . DB_HOST . "\n";
218
+ $sql_file .= "# Database: " . hmbkp_backquote( DB_NAME ) . "\n";
219
+ $sql_file .= "# --------------------------------------------------------\n";
220
+
221
+ for ( $i = 0; $i < mysql_num_rows( $tables ); $i++ ) :
222
+
223
+ $curr_table = mysql_tablename( $tables, $i );
224
+
225
+ @set_time_limit( 0 );
226
+
227
+ // Create the SQL statements
228
+ $sql_file .= "# --------------------------------------------------------\n";
229
+ $sql_file .= "# Table: " . hmbkp_backquote( $curr_table ) . "\n";
230
+ $sql_file .= "# --------------------------------------------------------\n";
231
+ hmbkp_make_sql( $sql_file, $curr_table );
232
+
233
+ endfor;
234
+
235
+ }
236
+
237
+ /**
238
+ * hmbkp_write_sql function.
239
+ *
240
+ * @param mixed $sql
241
+ */
242
+ function hmbkp_write_sql( $sql ) {
243
+
244
+ $sqlname = hmbkp_path() . '/database_' . DB_NAME . '.sql';
245
+
246
+ // Actually write the sql file
247
+ if ( is_writable( $sqlname ) || !file_exists( $sqlname ) ) :
248
+
249
+ if ( !$handle = fopen( $sqlname, 'a' ) )
250
+ return;
251
+
252
+ if ( !fwrite( $handle, $sql ) )
253
+ return;
254
+
255
+ fclose( $handle );
256
+
257
+ return true;
258
+
259
+ endif;
260
+ }
backup.mysql.functions.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Create the mysql backup
5
+ *
6
+ * Uses mysqldump if available, fallsback to PHP
7
+ * if not.
8
+ */
9
+ function hmbkp_backup_mysql() {
10
+
11
+ // Use mysqldump if we can
12
+ if ( hmbkp_mysqldump_path() )
13
+
14
+ // Backup everything except whats in the exclude file
15
+ shell_exec(
16
+ escapeshellarg( hmbkp_mysqldump_path() )
17
+ . ' --no-create-db '
18
+ . ' -u ' . escapeshellarg( DB_USER )
19
+ . ' -p' . escapeshellarg( DB_PASSWORD )
20
+ . ' -h ' . escapeshellarg( DB_HOST )
21
+ . ' -r ' . escapeshellarg( hmbkp_path() . '/database_' . DB_NAME . '.sql' ) . ' ' . escapeshellarg( DB_NAME )
22
+ );
23
+
24
+ // Fallback to using PHP if not
25
+ else
26
+ hmbkp_backup_mysql_fallback();
27
+
28
+ }
29
+
30
+ /**
31
+ * Attempt to work out the path to mysqldump
32
+ *
33
+ * Can be overridden by defining HMBKP_MYSQLDUMP_PATH in
34
+ * wp-config.php.
35
+ *
36
+ * @return string $path on success, empty string on failure
37
+ */
38
+ function hmbkp_mysqldump_path() {
39
+
40
+ if ( !hmbkp_shell_exec_available() || ( defined( 'HMBKP_MYSQLDUMP_PATH' ) && !HMBKP_MYSQLDUMP_PATH ) )
41
+ return false;
42
+
43
+ $path = '';
44
+
45
+ // List of possible mysqldump locations
46
+ $mysqldump_locations = array(
47
+ 'mysqldump',
48
+ '/usr/local/bin/mysqldump',
49
+ '/usr/local/mysql/bin/mysqldump',
50
+ '/usr/mysql/bin/mysqldump',
51
+ '/usr/bin/mysqldump',
52
+ '/opt/local/lib/mysql6/bin/mysqldump',
53
+ '/opt/local/lib/mysql5/bin/mysqldump',
54
+ '/opt/local/lib/mysql4/bin/mysqldump',
55
+ '\xampp\mysql\bin\mysqldump',
56
+ '\Program Files\xampp\mysql\bin\mysqldump',
57
+ '\Program Files\MySQL\MySQL Server 6.0\bin\mysqldump',
58
+ '\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump',
59
+ '\Program Files\MySQL\MySQL Server 5.4\bin\mysqldump',
60
+ '\Program Files\MySQL\MySQL Server 5.1\bin\mysqldump',
61
+ '\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump',
62
+ '\Program Files\MySQL\MySQL Server 4.1\bin\mysqldump'
63
+ );
64
+
65
+ // Allow the path to be overridden
66
+ if ( defined( 'HMBKP_MYSQLDUMP_PATH' ) && HMBKP_MYSQLDUMP_PATH )
67
+ array_unshift( $mysqldump_locations, HMBKP_MYSQLDUMP_PATH );
68
+
69
+ // If we don't have a path set
70
+ if ( !$path = get_option( 'hmbkp_mysqldump_path' ) ) :
71
+
72
+ // Try to find out where mysqldump is
73
+ foreach ( $mysqldump_locations as $location )
74
+ if ( shell_exec( $location ) )
75
+ $path = $location;
76
+
77
+ // Save it for later
78
+ if ( $path )
79
+ update_option( 'hmbkp_mysqldump_path', $path );
80
+
81
+ endif;
82
+
83
+ // Check again in-case the saved path has stopped working for some reason
84
+ if ( $path && !shell_exec( $path ) ) :
85
+ delete_option( 'hmbkp_mysqldump_path' );
86
+ return hmbkp_mysqldump_path();
87
+
88
+ endif;
89
+
90
+ return $path;
91
+
92
+ }
core.functions.php ADDED
@@ -0,0 +1,603 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Setup the default options on plugin activation
5
+ */
6
+ function hmbkp_activate() {
7
+ hmbkp_setup_daily_schedule();
8
+ }
9
+
10
+ /**
11
+ * Cleanup on plugin deactivation
12
+ *
13
+ * Removes options and clears all cron schedules
14
+ */
15
+ function hmbkp_deactivate() {
16
+
17
+ // Options to delete
18
+ $options = array(
19
+ 'hmbkp_zip_path',
20
+ 'hmbkp_mysqldump_path',
21
+ 'hmbkp_path',
22
+ 'hmbkp_max_backups',
23
+ 'hmbkp_running',
24
+ 'hmbkp_status',
25
+ 'hmbkp_complete',
26
+ 'hmbkp_email_error'
27
+ );
28
+
29
+ foreach ( $options as $option )
30
+ delete_option( $option );
31
+
32
+ delete_transient( 'hmbkp_running' );
33
+ delete_transient( 'hmbkp_estimated_filesize' );
34
+
35
+ // Clear cron
36
+ wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
37
+ wp_clear_scheduled_hook( 'hmbkp_schedule_single_backup_hook' );
38
+
39
+ hmbkp_cleanup();
40
+
41
+ }
42
+
43
+ /**
44
+ * Handles anything that needs to be
45
+ * done when the plugin is updated
46
+ */
47
+ function hmbkp_update() {
48
+
49
+ // Every update
50
+ if ( version_compare( HMBKP_VERSION, get_option( 'hmbkp_plugin_version' ), '>' ) ) :
51
+
52
+ hmbkp_cleanup();
53
+
54
+ delete_transient( 'hmbkp_estimated_filesize' );
55
+ delete_option( 'hmbkp_running' );
56
+ delete_option( 'hmbkp_complete' );
57
+ delete_option( 'hmbkp_status' );
58
+ delete_transient( 'hmbkp_running' );
59
+
60
+ // Check whether we have a logs directory to delete
61
+ if ( is_dir( hmbkp_path() . '/logs' ) )
62
+ hmbkp_rmdirtree( hmbkp_path() . '/logs' );
63
+
64
+ endif;
65
+
66
+ // Pre 1.1
67
+ if ( !get_option( 'hmbkp_plugin_version' ) ) :
68
+
69
+ // Delete the obsolete max backups option
70
+ delete_option( 'hmbkp_max_backups' );
71
+
72
+ endif;
73
+
74
+ // Update from backUpWordPress
75
+ if ( get_option( 'bkpwp_max_backups' ) ) :
76
+
77
+ // Carry over the custom path
78
+ if ( $legacy_path = get_option( 'bkpwppath' ) )
79
+ update_option( 'hmbkp_path', $legacy_path );
80
+
81
+ // Options to remove
82
+ $legacy_options = array(
83
+ 'bkpwp_archive_types',
84
+ 'bkpwp_automail_from',
85
+ 'bkpwp_domain',
86
+ 'bkpwp_domain_path',
87
+ 'bkpwp_easy_mode',
88
+ 'bkpwp_excludelists',
89
+ 'bkpwp_install_user',
90
+ 'bkpwp_listmax_backups',
91
+ 'bkpwp_max_backups',
92
+ 'bkpwp_presets',
93
+ 'bkpwp_reccurrences',
94
+ 'bkpwp_schedules',
95
+ 'bkpwp_calculation',
96
+ 'bkpwppath',
97
+ 'bkpwp_status_config',
98
+ 'bkpwp_status'
99
+ );
100
+
101
+ foreach ( $legacy_options as $option )
102
+ delete_option( $option );
103
+
104
+ global $wp_roles;
105
+
106
+ $wp_roles->remove_cap( 'administrator','manage_backups' );
107
+ $wp_roles->remove_cap( 'administrator','download_backups' );
108
+
109
+ wp_clear_scheduled_hook( 'bkpwp_schedule_bkpwp_hook' );
110
+
111
+ endif;
112
+
113
+ // Update the stored version
114
+ if ( get_option( 'hmbkp_plugin_version' ) !== HMBKP_VERSION )
115
+ update_option( 'hmbkp_plugin_version', HMBKP_VERSION );
116
+
117
+ }
118
+
119
+ /**
120
+ * Simply wrapper function for creating timestamps
121
+ *
122
+ * @return timestamp
123
+ */
124
+ function hmbkp_timestamp() {
125
+ return date( get_option( 'date_format' ) ) . ' ' . date( 'H:i:s' );
126
+ }
127
+
128
+ /**
129
+ * Sanitize a directory path
130
+ *
131
+ * @param string $dir
132
+ * @param bool $rel. (default: false)
133
+ * @return string $dir
134
+ */
135
+ function hmbkp_conform_dir( $dir, $rel = false ) {
136
+
137
+ // Normalise slashes
138
+ $dir = str_replace( '\\', '/', $dir );
139
+ $dir = str_replace( '//', '/', $dir );
140
+
141
+ // Remove the trailingslash
142
+ $dir = untrailingslashit( $dir );
143
+
144
+ // If we're on Windows
145
+ if ( strpos( ABSPATH, '\\' ) !== false )
146
+ $dir = str_replace( '\\', '/', $dir );
147
+
148
+ if ( $rel == true )
149
+ $dir = str_replace( hmbkp_conform_dir( ABSPATH ), '', $dir );
150
+
151
+ return $dir;
152
+ }
153
+ /**
154
+ * Take a file size and return a human readable
155
+ * version
156
+ *
157
+ * @param int $size
158
+ * @param string $unit. (default: null)
159
+ * @param string $retstring. (default: null)
160
+ * @param bool $si. (default: true)
161
+ * @return int
162
+ */
163
+ function hmbkp_size_readable( $size, $unit = null, $retstring = '%01.2f %s', $si = true ) {
164
+
165
+ // Units
166
+ if ( $si === true ) :
167
+ $sizes = array( 'B', 'kB', 'MB', 'GB', 'TB', 'PB' );
168
+ $mod = 1000;
169
+
170
+ else :
171
+ $sizes = array('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB');
172
+ $mod = 1024;
173
+
174
+ endif;
175
+
176
+ $ii = count( $sizes ) - 1;
177
+
178
+ // Max unit
179
+ $unit = array_search( (string) $unit, $sizes );
180
+
181
+ if ( is_null( $unit ) || $unit === false )
182
+ $unit = $ii;
183
+
184
+ // Loop
185
+ $i = 0;
186
+
187
+ while ( $unit != $i && $size >= 1024 && $i < $ii ) {
188
+ $size /= $mod;
189
+ $i++;
190
+ }
191
+
192
+ return sprintf( $retstring, $size, $sizes[$i] );
193
+ }
194
+
195
+ /**
196
+ * Add daily as a cron schedule choice
197
+ *
198
+ * @param array $recc
199
+ * @return array $recc
200
+ */
201
+ function hmbkp_more_reccurences( $recc ) {
202
+
203
+ $hmbkp_reccurrences = array(
204
+ 'hmbkp_daily' => array( 'interval' => 86400, 'display' => 'every day' )
205
+ );
206
+
207
+ return array_merge( $recc, $hmbkp_reccurrences );
208
+ }
209
+
210
+ /**
211
+ * Send a flie to the browser for download
212
+ *
213
+ * @param string $path
214
+ */
215
+ function hmbkp_send_file( $path ) {
216
+
217
+ session_write_close();
218
+
219
+ ob_end_clean();
220
+
221
+ if ( !is_file( $path ) || connection_status() != 0 )
222
+ return false;
223
+
224
+ // Overide max_execution_time
225
+ @set_time_limit( 0 );
226
+
227
+ $name = basename( $path );
228
+
229
+ // Filenames in IE containing dots will screw up the filename unless we add this
230
+ if ( strstr( $_SERVER['HTTP_USER_AGENT'], 'MSIE' ) )
231
+ $name = preg_replace( '/\./', '%2e', $name, substr_count( $name, '.' ) - 1 );
232
+
233
+ // Force
234
+ header( 'Cache-Control: ' );
235
+ header( 'Pragma: ' );
236
+ header( 'Content-Type: application/octet-stream' );
237
+ header( 'Content-Length: ' . (string) ( filesize( $path ) ) );
238
+ header( 'Content-Disposition: attachment; filename=" ' . $name . '"' );
239
+ header( 'Content-Transfer-Encoding: binary\n' );
240
+
241
+ if ( $file = fopen( $path, 'rb' ) ) :
242
+
243
+ while ( ( !feof( $file ) ) && ( connection_status() == 0) ) :
244
+
245
+ print( fread( $file, 1024 * 8 ) );
246
+ flush();
247
+
248
+ endwhile;
249
+
250
+ fclose( $file );
251
+
252
+ endif;
253
+
254
+ return ( connection_status() == 0 ) and !connection_aborted();
255
+ }
256
+
257
+ /**
258
+ * Takes a directory and returns an array of files.
259
+ * Does traverse sub-directories
260
+ *
261
+ * @param string $dir
262
+ * @param array $files. (default: array())
263
+ * @return arrat $files
264
+ */
265
+ function hmbkp_ls( $dir, $files = array() ) {
266
+
267
+ if ( !is_readable( $dir ) )
268
+ return $files;
269
+
270
+ $d = opendir( $dir );
271
+
272
+ // Get excluded files & directories.
273
+ $excludes = hmbkp_exclude_string( 'pclzip' );
274
+
275
+ while ( $file = readdir( $d ) ) :
276
+
277
+ // Ignore current dir and containing dir and any unreadable files or directories
278
+ if ( $file == '.' || $file == '..' )
279
+ continue;
280
+
281
+ $file = hmbkp_conform_dir( trailingslashit( $dir ) . $file );
282
+
283
+ // Skip the backups dir and any excluded paths
284
+ if ( ( $file == hmbkp_path() || preg_match( '(' . $excludes . ')', $file ) || !is_readable( $file ) ) )
285
+ continue;
286
+
287
+ $files[] = $file;
288
+
289
+ if ( is_dir( $file ) )
290
+ $files = hmbkp_ls( $file, $files );
291
+
292
+ endwhile;
293
+
294
+ return $files;
295
+ }
296
+
297
+ /**
298
+ * Recursively delete a directory including
299
+ * all the files and sub-directories.
300
+ *
301
+ * @param string $dir
302
+ */
303
+ function hmbkp_rmdirtree( $dir ) {
304
+
305
+ if ( is_file( $dir ) )
306
+ unlink( $dir );
307
+
308
+ if ( !is_dir( $dir ) )
309
+ return false;
310
+
311
+ $result = array();
312
+
313
+ $dir = trailingslashit( $dir );
314
+
315
+ $handle = opendir( $dir );
316
+
317
+ while ( false !== ( $file = readdir( $handle ) ) ) :
318
+
319
+ // Ignore . and ..
320
+ if ( $file != '.' && $file != '..' ) :
321
+
322
+ $path = $dir . $file;
323
+
324
+ // Recurse if subdir, Delete if file
325
+ if ( is_dir( $path ) ) :
326
+ $result = array_merge( $result, hmbkp_rmdirtree( $path ) );
327
+
328
+ else :
329
+ unlink( $path );
330
+ $result[] .= $path;
331
+
332
+ endif;
333
+
334
+ endif;
335
+
336
+ endwhile;
337
+
338
+ closedir( $handle );
339
+
340
+ rmdir( $dir );
341
+
342
+ $result[] .= $dir;
343
+
344
+ return $result;
345
+
346
+ }
347
+
348
+ /**
349
+ * Calculate the size of the backup
350
+ *
351
+ * Doesn't currently take into account for
352
+ * compression
353
+ *
354
+ * @return string
355
+ */
356
+ function hmbkp_calculate() {
357
+
358
+ @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
359
+
360
+ // Check cache
361
+ if ( $filesize = get_transient( 'hmbkp_estimated_filesize' ) )
362
+ return hmbkp_size_readable( $filesize, null, '%01u %s' );
363
+
364
+ $filesize = 0;
365
+
366
+ // Don't include database if files only
367
+ if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) ) :
368
+
369
+ global $wpdb;
370
+
371
+ $res = $wpdb->get_results( 'SHOW TABLE STATUS FROM ' . DB_NAME, ARRAY_A );
372
+
373
+ foreach ( $res as $r )
374
+ $filesize += (float) $r['Data_length'];
375
+
376
+ endif;
377
+
378
+ if ( ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) || !defined( 'HMBKP_DATABASE_ONLY' ) ) :
379
+
380
+ // Get rid of any cached filesizes
381
+ clearstatcache();
382
+
383
+ foreach ( hmbkp_ls( ABSPATH ) as $f )
384
+ $filesize += (float) @filesize( $f );
385
+
386
+ endif;
387
+
388
+ // Cache in a transient for a week
389
+ set_transient( 'hmbkp_estimated_filesize', $filesize, 604800 );
390
+
391
+ return hmbkp_size_readable( $filesize, null, '%01u %s' );
392
+
393
+ }
394
+
395
+ /**
396
+ * Check whether shell_exec has been disabled.
397
+ *
398
+ * @return bool
399
+ */
400
+ function hmbkp_shell_exec_available() {
401
+
402
+ $disable_functions = ini_get( 'disable_functions' );
403
+
404
+ // Is shell_exec disabled?
405
+ if ( strpos( $disable_functions, 'shell_exec' ) !== false )
406
+ return false;
407
+
408
+ // Are we in Safe Mode
409
+ if ( hmbkp_is_safe_mode_active() )
410
+ return false;
411
+
412
+ return true;
413
+
414
+ }
415
+
416
+ /**
417
+ * Check whether safe mode if active or not
418
+ *
419
+ * @return bool
420
+ */
421
+ function hmbkp_is_safe_mode_active() {
422
+
423
+ $safe_mode = ini_get( 'safe_mode' );
424
+
425
+ if ( $safe_mode && $safe_mode != 'off' && $safe_mode != 'Off' )
426
+ return true;
427
+
428
+ return false;
429
+
430
+ }
431
+
432
+ /**
433
+ * Calculate the total filesize of all backups
434
+ *
435
+ * @return string
436
+ */
437
+ function hmbkp_total_filesize() {
438
+
439
+ $files = hmbkp_get_backups();
440
+ $filesize = 0;
441
+
442
+ clearstatcache();
443
+
444
+ foreach ( $files as $f )
445
+ $filesize += @filesize( $f );
446
+
447
+ return hmbkp_size_readable( $filesize );
448
+
449
+ }
450
+
451
+ /**
452
+ * Setup the daily backup schedule
453
+ */
454
+ function hmbkp_setup_daily_schedule() {
455
+
456
+ // Clear any old schedules
457
+ wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
458
+
459
+ // Default to 11 in the evening
460
+ $time = '23:00';
461
+
462
+ // Allow it to be overridden
463
+ if ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) && HMBKP_DAILY_SCHEDULE_TIME )
464
+ $time = HMBKP_DAILY_SCHEDULE_TIME;
465
+
466
+ if ( time() > strtotime( $time ) )
467
+ $time = 'tomorrow ' . $time;
468
+
469
+ wp_schedule_event( strtotime( $time ), 'hmbkp_daily', 'hmbkp_schedule_backup_hook' );
470
+ }
471
+
472
+ /**
473
+ * Get the path to the backups directory
474
+ *
475
+ * Will try to create it if it doesn't exist
476
+ * and will fallback to default if a custom dir
477
+ * isn't writable.
478
+ */
479
+ function hmbkp_path() {
480
+
481
+ $path = get_option( 'hmbkp_path' );
482
+
483
+ // Allow the backups path to be defined
484
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH )
485
+ $path = HMBKP_PATH;
486
+
487
+ // If the dir doesn't exist or isn't writable then use wp-content/backups instead
488
+ if ( ( !$path || !is_writable( $path ) ) && hmbkp_conform_dir( $path ) != hmbkp_path_default() )
489
+ $path = hmbkp_path_default();
490
+
491
+ // Create the backups directory if it doesn't exist
492
+ if ( is_writable( dirname( $path ) ) && !is_dir( $path ) )
493
+ mkdir( $path, 0755 );
494
+
495
+ if ( get_option( 'hmbkp_path' ) != $path )
496
+ update_option( 'hmbkp_path', $path );
497
+
498
+ // Secure the directory with a .htaccess file
499
+ $htaccess = $path . '/.htaccess';
500
+
501
+ if ( !file_exists( $htaccess ) && is_writable( $path ) && require_once( ABSPATH . '/wp-admin/includes/misc.php' ) )
502
+ insert_with_markers( $htaccess, 'BackUpWordPress', array( 'deny from all' ) );
503
+
504
+ return hmbkp_conform_dir( $path );
505
+ }
506
+
507
+ /**
508
+ * Return the default backup path
509
+ *
510
+ * @return string path
511
+ */
512
+ function hmbkp_path_default() {
513
+ return hmbkp_conform_dir( WP_CONTENT_DIR . '/backups' );
514
+ }
515
+
516
+ /**
517
+ * Move the backup directory and all existing backup files to a new
518
+ * location
519
+ *
520
+ * @param string $from path to move the backups dir from
521
+ * @param string $to path to move the backups dir to
522
+ * @return void
523
+ */
524
+ function hmbkp_path_move( $from, $to ) {
525
+
526
+ // Create the custom backups directory if it doesn't exist
527
+ if ( is_writable( dirname( $to ) ) && !is_dir( $to ) )
528
+ mkdir( $to, 0755 );
529
+
530
+ if ( !is_dir( $to ) || !is_writable( $to ) || !is_dir( $from ) )
531
+ return false;
532
+
533
+ hmbkp_cleanup();
534
+
535
+ if ( $handle = opendir( $from ) ) :
536
+
537
+ while ( false !== ( $file = readdir( $handle ) ) )
538
+ if ( $file != '.' && $file != '..' )
539
+ rename( trailingslashit( $from ) . $file, trailingslashit( $to ) . $file );
540
+
541
+ closedir( $handle );
542
+
543
+ endif;
544
+
545
+ hmbkp_rmdirtree( $from );
546
+
547
+ }
548
+
549
+ /**
550
+ * The maximum number of backups to keep
551
+ * defaults to 10
552
+ *
553
+ * @return int
554
+ */
555
+ function hmbkp_max_backups() {
556
+
557
+ if ( defined( 'HMBKP_MAX_BACKUPS' ) && is_numeric( HMBKP_MAX_BACKUPS ) )
558
+ return (int) HMBKP_MAX_BACKUPS;
559
+
560
+ return 10;
561
+
562
+ }
563
+
564
+ /**
565
+ * Check if a backup is possible with regards to file
566
+ * permissions etc.
567
+ *
568
+ * @return bool
569
+ */
570
+ function hmbkp_possible() {
571
+
572
+ if ( !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) || hmbkp_is_safe_mode_active() )
573
+ return false;
574
+
575
+ if ( defined( 'HMBKP_FILES_ONLY' ) && HMBKP_FILES_ONLY && defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY )
576
+ return false;
577
+
578
+ return true;
579
+ }
580
+
581
+ /**
582
+ * Remove any non backup.zip files from the backups dir.
583
+ *
584
+ * @return void
585
+ */
586
+ function hmbkp_cleanup() {
587
+
588
+ $hmbkp_path = hmbkp_path();
589
+
590
+ if ( !is_dir( $hmbkp_path ) )
591
+ return;
592
+
593
+ if ( $handle = opendir( $hmbkp_path ) ) :
594
+
595
+ while ( false !== ( $file = readdir( $handle ) ) )
596
+ if ( $file != '.' && $file != '..' && $file != '.htaccess' && strpos( $file, '.zip' ) === false )
597
+ hmbkp_rmdirtree( trailingslashit( $hmbkp_path ) . $file );
598
+
599
+ closedir( $handle );
600
+
601
+ endif;
602
+
603
+ }
functions/backup.files.fallback.functions.php CHANGED
@@ -7,15 +7,45 @@
7
  * Uses the PCLZIP library that ships with WordPress
8
  *
9
  * @todo support zipArchive
10
- * @param string $backup_tmp_dir
11
- * @param string $backup_filepath
12
  */
13
- function hmbkp_archive_files_fallback( $backup_tmp_dir, $backup_filepath ) {
14
 
15
- // Try PCLZIP
16
  require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
17
 
18
- $archive = new PclZip( $backup_filepath );
19
- $archive->create( $backup_tmp_dir, PCLZIP_OPT_REMOVE_PATH, $backup_tmp_dir );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  }
7
  * Uses the PCLZIP library that ships with WordPress
8
  *
9
  * @todo support zipArchive
10
+ * @param string $path
 
11
  */
12
+ function hmbkp_archive_files_fallback( $path ) {
13
 
 
14
  require_once( ABSPATH . 'wp-admin/includes/class-pclzip.php' );
15
 
16
+ $archive = new PclZip( $path );
17
+
18
+ // Zip up everything
19
+ if ( ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) || !defined( 'HMBKP_DATABASE_ONLY' ) )
20
+ $archive->create( ABSPATH, PCLZIP_OPT_REMOVE_PATH, ABSPATH, PCLZIP_CB_PRE_ADD, 'hmbkp_pclzip_exclude' );
21
+
22
+ // Only zip up the database
23
+ if ( defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY )
24
+ $archive->create( hmbkp_path() . '/database_' . DB_NAME . '.sql', PCLZIP_OPT_REMOVE_PATH, hmbkp_path() );
25
+
26
+ }
27
+
28
+ /**
29
+ * Add file callback, excludes files in the backups directory
30
+ * and sets the database dump to be stored in the root
31
+ * of the zip
32
+ *
33
+ * @param string $event
34
+ * @param array &$file
35
+ * @return bool
36
+ */
37
+ function hmbkp_pclzip_exclude( $event, &$file ) {
38
+
39
+ $excludes = hmbkp_exclude_string( 'pclzip' );
40
+
41
+ // Include the database file
42
+ if ( strpos( $file['filename'], 'database_' . DB_NAME . '.sql' ) !== false )
43
+ $file['stored_filename'] = 'database_' . DB_NAME . '.sql';
44
+
45
+ // Match everything else past the exclude list
46
+ elseif ( preg_match( '(' . $excludes . ')', $file['stored_filename'] ) )
47
+ return false;
48
+
49
+ return true;
50
 
51
  }
functions/backup.files.functions.php CHANGED
@@ -1,73 +1,38 @@
1
  <?php
2
 
3
  /**
4
- * Copy the whole site to the temporary directory and
5
- * then zip it all up
6
  *
7
- * @param string $backup_tmp_dir
 
 
 
 
8
  */
9
- function hmbkp_backup_files( $backup_tmp_dir ) {
10
-
11
- $wordpress_files = $backup_tmp_dir . '/wordpress_files';
12
-
13
- if ( !is_dir( $wordpress_files ) )
14
- mkdir( $wordpress_files, 0755 );
15
-
16
- // Copy the whole site to the temporary directory
17
- $files = hmbkp_ls( hmbkp_conform_dir( ABSPATH ) );
18
-
19
- $files_copied = $subdirs_created = 0;
20
- $i = 1;
21
-
22
- foreach ( (array) $files as $f ) :
23
-
24
- if ( is_dir( $f ) ) :
25
-
26
- if ( mkdir( $wordpress_files . hmbkp_conform_dir( $f, true ), 0755 ) ) :
27
- $subdirs_created++;
28
 
29
- endif;
30
-
31
- elseif ( file_exists( $f ) ) :
32
-
33
- $files_copied++;
34
 
35
- if ( file_exists( $wordpress_files . hmbkp_conform_dir( $f, true ) ) )
36
- unlink( $wordpress_files . hmbkp_conform_dir( $f, true ) );
37
 
38
- // Copy the file
39
- copy( $f, $wordpress_files . hmbkp_conform_dir( $f, true ) );
40
-
41
- // Attempt to chown the file so we can delete it
42
- @chmod( $f, 0644 );
43
 
44
- endif;
45
 
46
- $i++;
47
-
48
- endforeach;
49
 
50
- }
 
 
 
51
 
52
- /**
53
- * Zip up all the files in the tmp directory.
54
- *
55
- * Attempts to use the shell zip command, if
56
- * thats not available then it fallsback on
57
- * PHP zip classes.
58
- *
59
- * @param string $backup_tmp_dir
60
- * @param string $backup_filepath
61
- */
62
- function hmbkp_archive_files( $backup_tmp_dir, $backup_filepath ) {
63
-
64
- // Do we have the path to the zip command
65
- if ( hmbkp_zip_path() )
66
- shell_exec( 'cd ' . escapeshellarg( $backup_tmp_dir ) . ' && zip -r ' . escapeshellarg( $backup_filepath ) . ' ./' );
67
-
68
  // If not use the fallback
69
- else
70
- hmbkp_archive_files_fallback( $backup_tmp_dir, $backup_filepath );
 
 
71
 
72
  }
73
 
@@ -119,4 +84,155 @@ function hmbkp_zip_path() {
119
 
120
  return $path;
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  }
1
  <?php
2
 
3
  /**
4
+ * Zip up all the wordpress files.
 
5
  *
6
+ * Attempts to use the shell zip command, if
7
+ * thats not available then it fallsback on
8
+ * PHP zip classes.
9
+ *
10
+ * @param string $path
11
  */
12
+ function hmbkp_archive_files( $path ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
+ // Do we have the path to the zip command
15
+ if ( hmbkp_zip_path() ) :
 
 
 
16
 
17
+ // Zip up ABSPATH
18
+ if ( ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) || !defined( 'HMBKP_DATABASE_ONLY' ) ) :
19
 
20
+ $excludes = ' -x ' . hmbkp_exclude_string( 'zip' );
 
 
 
 
21
 
22
+ shell_exec( 'cd ' . escapeshellarg( ABSPATH ) . ' && ' . escapeshellarg( hmbkp_zip_path() ) . ' -rq ' . escapeshellarg( $path ) . ' ./' . $excludes );
23
 
24
+ endif;
 
 
25
 
26
+ // Add the database dump to the archive
27
+ if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) ) :
28
+ shell_exec( 'cd ' . escapeshellarg( hmbkp_path() ) . ' && ' . escapeshellarg( hmbkp_zip_path() ) . ' -uq ' . escapeshellarg( $path ) . ' ' . escapeshellarg( 'database_' . DB_NAME . '.sql' ) );
29
+ endif;
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  // If not use the fallback
32
+ else :
33
+ hmbkp_archive_files_fallback( $path );
34
+
35
+ endif;
36
 
37
  }
38
 
84
 
85
  return $path;
86
 
87
+ }
88
+
89
+ /**
90
+ * Returns an array of default exclude paths
91
+ *
92
+ * @access public
93
+ * @return array
94
+ */
95
+ function hmbkp_excludes() {
96
+
97
+ // Exclude the back up path
98
+ $excludes[] = hmbkp_path();
99
+
100
+ // Exclude the default back up path
101
+ $excludes[] = hmbkp_path_default();
102
+
103
+ // Exclude the custom path if one is defined
104
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH )
105
+ $excludes[] = hmbkp_conform_dir( HMBKP_PATH );
106
+
107
+ return array_map( 'trailingslashit', array_unique( $excludes ) );
108
+
109
+ }
110
+
111
+ /**
112
+ * Generate the exclude param string for the zip backup
113
+ *
114
+ * Takes the exclude rules and formats them for use with either
115
+ * the shell zip command or pclzip
116
+ *
117
+ * @param string $context. (default: 'zip')
118
+ * @return string
119
+ */
120
+ function hmbkp_exclude_string( $context = 'zip' ) {
121
+
122
+ // Return a comma separated list by default
123
+ $separator = ', ';
124
+ $wildcard = '';
125
+
126
+ // The zip command
127
+ if ( $context == 'zip' ) :
128
+ $wildcard = '*';
129
+ $separator = ' -x ';
130
+
131
+ // The PCLZIP fallback library
132
+ elseif ( $context == 'pclzip' ) :
133
+ $wildcard = '([.]*?)';
134
+ $separator = '|';
135
+
136
+ endif;
137
+
138
+ // Get the excludes
139
+ $excludes = hmbkp_excludes();
140
+
141
+ // Add any defined excludes
142
+ if ( defined( 'HMBKP_EXCLUDE' ) && HMBKP_EXCLUDE )
143
+ $excludes = array_merge( explode( ',', HMBKP_EXCLUDE ), $excludes );
144
+
145
+ $excludes = array_map( 'trim', $excludes );
146
+
147
+ // Add wildcards to the directories
148
+ foreach( $excludes as $key => &$rule ) :
149
+
150
+ $file = $absolute = $fragment = false;
151
+
152
+ // Files don't end with /
153
+ if ( !in_array( substr( $rule, -1 ), array( '\\', '/' ) ) )
154
+ $file = true;
155
+
156
+ // If rule starts with a / then treat as absolute path
157
+ elseif ( in_array( substr( $rule, 0, 1 ), array( '\\', '/' ) ) )
158
+ $absolute = true;
159
+
160
+ // Otherwise treat as dir fragment
161
+ else
162
+ $fragment = true;
163
+
164
+ // Strip ABSPATH and conform
165
+ $rule = str_replace( hmbkp_conform_dir( ABSPATH ), '', untrailingslashit( hmbkp_conform_dir( $rule ) ) );
166
+
167
+ if ( in_array( substr( $rule, 0, 1 ), array( '\\', '/' ) ) )
168
+ $rule = substr( $rule, 1 );
169
+
170
+ // Escape string for regex
171
+ if ( $context == 'pclzip' )
172
+ //$rule = preg_quote( $rule );
173
+ $rule = str_replace( '.', '\.', $rule );
174
+
175
+ // Convert any existing wildcards
176
+ if ( $wildcard != '*' && strpos( $rule, '*' ) !== false )
177
+ $rule = str_replace( '*', $wildcard, $rule );
178
+
179
+ // Wrap directory fragments in wildcards for zip
180
+ if ( $context == 'zip' && $fragment )
181
+ $rule = $wildcard . $rule . $wildcard;
182
+
183
+ // Add a wildcard to the end of absolute url for zips
184
+ if ( $context == 'zip' && $absolute )
185
+ $rule .= $wildcard;
186
+
187
+ // Add and end carrot to files for pclzip
188
+ if ( $file && $context == 'pclzip' )
189
+ $rule .= '$';
190
+
191
+ // Add a start carrot to absolute urls for pclzip
192
+ if ( $absolute && $context == 'pclzip' )
193
+ $rule = '^' . $rule;
194
+
195
+ endforeach;
196
+
197
+ // Escape shell args for zip command
198
+ if ( $context == 'zip' )
199
+ $excludes = array_map( 'escapeshellarg', $excludes );
200
+
201
+ return implode( $separator, $excludes );
202
+
203
+ }
204
+
205
+ /**
206
+ * Return an array of invalid custom exclude rules
207
+ *
208
+ * @return array
209
+ */
210
+ function hmbkp_invalid_custom_excludes() {
211
+
212
+ $invalid_rules = array();
213
+
214
+ // Check if any absolute path excludes actually exist
215
+ if ( defined( 'HMBKP_EXCLUDE' ) && HMBKP_EXCLUDE )
216
+ foreach ( explode( ',', HMBKP_EXCLUDE ) as $rule )
217
+ if ( ( $rule = trim( $rule ) ) && in_array( substr( $rule, 0, 1 ), array( '/', '\\' ) ) && !file_exists( $rule ) && !file_exists( ABSPATH . $rule ) && !file_exists( trailingslashit( ABSPATH ) . $rule ) )
218
+ $invalid_rules[] = $rule;
219
+
220
+ return $invalid_rules;
221
+
222
+ }
223
+
224
+ /**
225
+ * Return an array of valid custom exclude rules
226
+ *
227
+ * @return array
228
+ */
229
+ function hmbkp_valid_custom_excludes() {
230
+
231
+ $valid_rules = array();
232
+
233
+ if ( defined( 'HMBKP_EXCLUDE' ) && HMBKP_EXCLUDE )
234
+ $valid_rules = array_diff( explode( ',', HMBKP_EXCLUDE ), hmbkp_invalid_custom_excludes() );
235
+
236
+ return array_map( 'trim', $valid_rules );
237
+
238
  }
functions/backup.functions.php CHANGED
@@ -12,61 +12,59 @@
12
  */
13
  function hmbkp_do_backup() {
14
 
15
- // Make sure it's safe to do a backup
16
- if ( !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) || ini_get( 'safe_mode' ) )
17
  return false;
18
 
 
 
 
19
  $time_start = date( 'Y-m-d-H-i-s' );
20
 
21
- $filename = $time_start . '.zip';
22
  $filepath = trailingslashit( hmbkp_path() ) . $filename;
23
 
24
- // Set as running for a max of 2 hours
25
- set_transient( 'hmbkp_running', $time_start, 7200 );
26
 
27
  // Raise the memory limit
28
- ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
29
- set_time_limit( 0 );
30
-
31
- update_option( 'hmbkp_status', __( 'Creating tmp directory', 'hmbkp' ) );
32
 
33
- // Create a temporary directory for this backup
34
- $backup_tmp_dir = hmbkp_create_tmp_dir( $time_start );
35
-
36
- update_option( 'hmbkp_status', __( 'Dumping database to tmp directory', 'hmbkp' ) );
37
 
38
  // Backup database
39
  if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) )
40
- hmbkp_backup_mysql( $backup_tmp_dir );
41
-
42
- update_option( 'hmbkp_status', __( 'Copying files to tmp directory', 'hmbkp' ) );
43
 
44
- // Backup files
45
- if ( ( defined( 'HMBKP_DATABASE_ONLY' ) && !HMBKP_DATABASE_ONLY ) || !defined( 'HMBKP_DATABASE_ONLY' ) )
46
- hmbkp_backup_files( $backup_tmp_dir );
47
 
48
- update_option( 'hmbkp_status', __( 'Zipping up tmp directory', 'hmbkp' ) );
 
49
 
50
- // Zip up the files
51
- hmbkp_archive_files( $backup_tmp_dir, $filepath );
52
-
53
- update_option( 'hmbkp_status', __( 'Removing tmp directory', 'hmbkp' ) );
54
-
55
- // Remove the temporary directory
56
- hmbkp_rmdirtree( $backup_tmp_dir );
57
 
58
  // Email Backup
59
  hmbkp_email_backup( $filepath );
60
 
61
- update_option( 'hmbkp_status', __( 'Removing old backups', 'hmbkp' ) );
62
 
63
  // Delete any old backup files
64
  hmbkp_delete_old_backups();
 
 
 
 
 
 
 
 
 
 
 
65
 
66
- delete_transient( 'hmbkp_running' );
67
- delete_option( 'hmbkp_status' );
68
-
69
- update_option( 'hmbkp_complete', true );
70
 
71
  }
72
 
@@ -80,9 +78,8 @@ function hmbkp_delete_old_backups() {
80
  if ( count( $files ) <= hmbkp_max_backups() )
81
  return;
82
 
83
- foreach ( $files as $key => $f )
84
- if ( ( $key + 1 ) > hmbkp_max_backups() )
85
- hmbkp_delete_backup( base64_encode( $f['file'] ) );
86
 
87
  }
88
 
@@ -95,26 +92,32 @@ function hmbkp_get_backups() {
95
 
96
  $hmbkp_path = hmbkp_path();
97
 
98
- if ( !is_writable( $hmbkp_path ) )
99
- return;
100
-
101
  if ( $handle = opendir( $hmbkp_path ) ) :
102
 
103
  while ( false !== ( $file = readdir( $handle ) ) )
104
- if ( ( substr( $file, 0, 1 ) != '.' ) && !is_dir( trailingslashit( $hmbkp_path ) . $file ) && strpos( $file, '.zip' ) !== false )
105
- $files[] = array( 'file' => trailingslashit( $hmbkp_path ) . $file, 'filename' => $file );
106
 
107
  closedir( $handle );
108
 
109
  endif;
110
 
111
- if ( count( $files ) < 1 )
112
- return;
 
 
 
 
 
 
 
 
 
 
113
 
114
- foreach ( $files as $key => $row )
115
- $filename[$key] = $row['filename'];
116
 
117
- array_multisort( $filename, SORT_DESC, $files );
118
 
119
  return $files;
120
  }
@@ -134,30 +137,13 @@ function hmbkp_delete_backup( $file ) {
134
 
135
  }
136
 
137
- /**
138
- * Create and return the path to the tmp directory
139
- *
140
- * @param string $date
141
- * @return string
142
- */
143
- function hmbkp_create_tmp_dir( $date ) {
144
-
145
- $backup_tmp_dir = trailingslashit( hmbkp_path() ) . $date;
146
-
147
- if ( !is_dir( $backup_tmp_dir ) )
148
- mkdir( $backup_tmp_dir );
149
-
150
- return $backup_tmp_dir;
151
-
152
- }
153
-
154
  /**
155
  * Check if a backup is running
156
  *
157
  * @return bool
158
  */
159
  function hmbkp_is_in_progress() {
160
- return (bool) get_transient( 'hmbkp_running' );
161
  }
162
 
163
  /**
@@ -172,9 +158,9 @@ function hmbkp_email_backup( $file ) {
172
  return;
173
 
174
  // Raise the memory and time limit
175
- ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
176
- set_time_limit( 0 );
177
-
178
  $download = get_bloginfo( 'wpurl' ) . '/wp-admin/tools.php?page=' . HMBKP_PLUGIN_SLUG . '&hmbkp_download=' . base64_encode( $file );
179
  $domain = parse_url( get_bloginfo( 'url' ), PHP_URL_HOST ) . parse_url( get_bloginfo( 'url' ), PHP_URL_PATH );
180
 
@@ -203,4 +189,37 @@ function hmbkp_email_backup( $file ) {
203
 
204
  return true;
205
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  }
12
  */
13
  function hmbkp_do_backup() {
14
 
15
+ // Make sure it's possible to do a backup
16
+ if ( !hmbkp_possible() )
17
  return false;
18
 
19
+ // Clean up any mess left by the last backup
20
+ hmbkp_cleanup();
21
+
22
  $time_start = date( 'Y-m-d-H-i-s' );
23
 
24
+ $filename = sanitize_file_name( get_bloginfo( 'name' ) . '.backup.' . $time_start . '.zip' );
25
  $filepath = trailingslashit( hmbkp_path() ) . $filename;
26
 
27
+ // Set as running for a max of 1 hour
28
+ hmbkp_set_status();
29
 
30
  // Raise the memory limit
31
+ @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
32
+ @set_time_limit( 0 );
 
 
33
 
34
+ hmbkp_set_status( __( 'Dumping database', 'hmbkp' ) );
 
 
 
35
 
36
  // Backup database
37
  if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) )
38
+ hmbkp_backup_mysql();
 
 
39
 
40
+ hmbkp_set_status( __( 'Creating zip archive', 'hmbkp' ) );
 
 
41
 
42
+ // Zip everything up
43
+ hmbkp_archive_files( $filepath );
44
 
45
+ // Delete the database dump file
46
+ if ( ( defined( 'HMBKP_FILES_ONLY' ) && !HMBKP_FILES_ONLY ) || !defined( 'HMBKP_FILES_ONLY' ) )
47
+ unlink( hmbkp_path() . '/database_' . DB_NAME . '.sql' );
 
 
 
 
48
 
49
  // Email Backup
50
  hmbkp_email_backup( $filepath );
51
 
52
+ hmbkp_set_status( __( 'Removing old backups', 'hmbkp' ) );
53
 
54
  // Delete any old backup files
55
  hmbkp_delete_old_backups();
56
+
57
+ unlink( hmbkp_path() . '/.backup_running' );
58
+
59
+ $file = hmbkp_path() . '/.backup_complete';
60
+
61
+ if ( !$handle = @fopen( $file, 'w' ) )
62
+ return false;
63
+
64
+ fwrite( $handle );
65
+
66
+ fclose( $handle );
67
 
 
 
 
 
68
 
69
  }
70
 
78
  if ( count( $files ) <= hmbkp_max_backups() )
79
  return;
80
 
81
+ foreach( array_slice( $files, hmbkp_max_backups() ) as $file )
82
+ hmbkp_delete_backup( base64_encode( $file ) );
 
83
 
84
  }
85
 
92
 
93
  $hmbkp_path = hmbkp_path();
94
 
 
 
 
95
  if ( $handle = opendir( $hmbkp_path ) ) :
96
 
97
  while ( false !== ( $file = readdir( $handle ) ) )
98
+ if ( strpos( $file, '.zip' ) !== false )
99
+ $files[filemtime( trailingslashit( $hmbkp_path ) . $file )] = trailingslashit( $hmbkp_path ) . $file;
100
 
101
  closedir( $handle );
102
 
103
  endif;
104
 
105
+ // If there is a custom backups directory and it's not writable then include those backups as well
106
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH && is_dir( HMBKP_PATH ) && !is_writable( HMBKP_PATH ) ) :
107
+
108
+ if ( $handle = opendir( HMBKP_PATH ) ) :
109
+
110
+ while ( false !== ( $file = readdir( $handle ) ) )
111
+ if ( strpos( $file, '.zip' ) !== false )
112
+ $files[filemtime( trailingslashit( HMBKP_PATH ) . $file )] = trailingslashit( HMBKP_PATH ) . $file;
113
+
114
+ closedir( $handle );
115
+
116
+ endif;
117
 
118
+ endif;
 
119
 
120
+ krsort( $files );
121
 
122
  return $files;
123
  }
137
 
138
  }
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  /**
141
  * Check if a backup is running
142
  *
143
  * @return bool
144
  */
145
  function hmbkp_is_in_progress() {
146
+ return file_exists( hmbkp_path() . '/.backup_running' );
147
  }
148
 
149
  /**
158
  return;
159
 
160
  // Raise the memory and time limit
161
+ @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
162
+ @set_time_limit( 0 );
163
+
164
  $download = get_bloginfo( 'wpurl' ) . '/wp-admin/tools.php?page=' . HMBKP_PLUGIN_SLUG . '&hmbkp_download=' . base64_encode( $file );
165
  $domain = parse_url( get_bloginfo( 'url' ), PHP_URL_HOST ) . parse_url( get_bloginfo( 'url' ), PHP_URL_PATH );
166
 
189
 
190
  return true;
191
 
192
+ }
193
+
194
+ /**
195
+ * Set the status of the running backup
196
+ *
197
+ * @param string $message. (default: '')
198
+ * @return void
199
+ */
200
+ function hmbkp_set_status( $message = '' ) {
201
+
202
+ $file = hmbkp_path() . '/.backup_running';
203
+
204
+ if ( !$handle = @fopen( $file, 'w' ) )
205
+ return false;
206
+
207
+ fwrite( $handle, $message );
208
+
209
+ fclose( $handle );
210
+
211
+ }
212
+
213
+ /**
214
+ * Get the status of the running backup
215
+ *
216
+ * @return string
217
+ */
218
+ function hmbkp_get_status() {
219
+
220
+ if ( !file_exists( hmbkp_path() . '/.backup_running' ) )
221
+ return false;
222
+
223
+ return file_get_contents( hmbkp_path() .'/.backup_running' );
224
+
225
  }
functions/backup.mysql.fallback.functions.php CHANGED
@@ -41,11 +41,10 @@ function hmbkp_backquote( $a_name ) {
41
  * Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
42
  *
43
  * @access public
44
- * @param string $path
45
  * @param mixed $sql_file
46
  * @param mixed $table
47
  */
48
- function hmbkp_make_sql( $path, $sql_file, $table ) {
49
 
50
  global $hmbkp_db_connect;
51
 
@@ -150,7 +149,7 @@ function hmbkp_make_sql( $path, $sql_file, $table ) {
150
  // write the rows in batches of 100
151
  if ( $batch_write == 100 ) :
152
  $batch_write = 0;
153
- hmbkp_write_sql( $path, $sql_file );
154
  $sql_file = '';
155
  endif;
156
 
@@ -169,7 +168,7 @@ function hmbkp_make_sql( $path, $sql_file, $table ) {
169
  $sql_file .= "# --------------------------------------------------------\n";
170
  $sql_file .= "\n";
171
 
172
- hmbkp_write_sql( $path, $sql_file );
173
 
174
  }
175
 
@@ -200,9 +199,8 @@ function hmbkp_sql_addslashes( $a_string = '', $is_like = false ) {
200
  * hmbkp_mysql function.
201
  *
202
  * @access public
203
- * @param mixed $path
204
  */
205
- function hmbkp_backup_mysql_fallback( $path ) {
206
 
207
  global $hmbkp_db_connect;
208
 
@@ -224,14 +222,13 @@ function hmbkp_backup_mysql_fallback( $path ) {
224
 
225
  $curr_table = mysql_tablename( $tables, $i );
226
 
227
- // Increase script execution time-limit to 15 min for every table.
228
- set_time_limit( 0 );
229
 
230
  // Create the SQL statements
231
  $sql_file .= "# --------------------------------------------------------\n";
232
  $sql_file .= "# Table: " . hmbkp_backquote( $curr_table ) . "\n";
233
  $sql_file .= "# --------------------------------------------------------\n";
234
- hmbkp_make_sql( $path, $sql_file, $curr_table );
235
 
236
  endfor;
237
 
@@ -240,12 +237,11 @@ function hmbkp_backup_mysql_fallback( $path ) {
240
  /**
241
  * hmbkp_write_sql function.
242
  *
243
- * @param mixed $sqldir
244
  * @param mixed $sql
245
  */
246
- function hmbkp_write_sql( $sqldir, $sql ) {
247
 
248
- $sqlname = $sqldir . '/wordpress.sql';
249
 
250
  // Actually write the sql file
251
  if ( is_writable( $sqlname ) || !file_exists( $sqlname ) ) :
41
  * Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
42
  *
43
  * @access public
 
44
  * @param mixed $sql_file
45
  * @param mixed $table
46
  */
47
+ function hmbkp_make_sql( $sql_file, $table ) {
48
 
49
  global $hmbkp_db_connect;
50
 
149
  // write the rows in batches of 100
150
  if ( $batch_write == 100 ) :
151
  $batch_write = 0;
152
+ hmbkp_write_sql( $sql_file );
153
  $sql_file = '';
154
  endif;
155
 
168
  $sql_file .= "# --------------------------------------------------------\n";
169
  $sql_file .= "\n";
170
 
171
+ hmbkp_write_sql( $sql_file );
172
 
173
  }
174
 
199
  * hmbkp_mysql function.
200
  *
201
  * @access public
 
202
  */
203
+ function hmbkp_backup_mysql_fallback() {
204
 
205
  global $hmbkp_db_connect;
206
 
222
 
223
  $curr_table = mysql_tablename( $tables, $i );
224
 
225
+ @set_time_limit( 0 );
 
226
 
227
  // Create the SQL statements
228
  $sql_file .= "# --------------------------------------------------------\n";
229
  $sql_file .= "# Table: " . hmbkp_backquote( $curr_table ) . "\n";
230
  $sql_file .= "# --------------------------------------------------------\n";
231
+ hmbkp_make_sql( $sql_file, $curr_table );
232
 
233
  endfor;
234
 
237
  /**
238
  * hmbkp_write_sql function.
239
  *
 
240
  * @param mixed $sql
241
  */
242
+ function hmbkp_write_sql( $sql ) {
243
 
244
+ $sqlname = hmbkp_path() . '/database_' . DB_NAME . '.sql';
245
 
246
  // Actually write the sql file
247
  if ( is_writable( $sqlname ) || !file_exists( $sqlname ) ) :
functions/backup.mysql.functions.php CHANGED
@@ -5,25 +5,25 @@
5
  *
6
  * Uses mysqldump if available, fallsback to PHP
7
  * if not.
8
- *
9
- * @param string $backup_tmp_dir
10
  */
11
- function hmbkp_backup_mysql( $backup_tmp_dir ) {
12
 
13
  // Use mysqldump if we can
14
  if ( hmbkp_mysqldump_path() )
 
 
15
  shell_exec(
16
  escapeshellarg( hmbkp_mysqldump_path() )
17
  . ' --no-create-db '
18
  . ' -u ' . escapeshellarg( DB_USER )
19
  . ' -p' . escapeshellarg( DB_PASSWORD )
20
  . ' -h ' . escapeshellarg( DB_HOST )
21
- . ' -r ' . escapeshellarg( $backup_tmp_dir . '/wordpress.sql' ) . ' ' . escapeshellarg( DB_NAME )
22
  );
23
 
24
  // Fallback to using PHP if not
25
  else
26
- hmbkp_backup_mysql_fallback( $backup_tmp_dir );
27
 
28
  }
29
 
5
  *
6
  * Uses mysqldump if available, fallsback to PHP
7
  * if not.
 
 
8
  */
9
+ function hmbkp_backup_mysql() {
10
 
11
  // Use mysqldump if we can
12
  if ( hmbkp_mysqldump_path() )
13
+
14
+ // Backup everything except whats in the exclude file
15
  shell_exec(
16
  escapeshellarg( hmbkp_mysqldump_path() )
17
  . ' --no-create-db '
18
  . ' -u ' . escapeshellarg( DB_USER )
19
  . ' -p' . escapeshellarg( DB_PASSWORD )
20
  . ' -h ' . escapeshellarg( DB_HOST )
21
+ . ' -r ' . escapeshellarg( hmbkp_path() . '/database_' . DB_NAME . '.sql' ) . ' ' . escapeshellarg( DB_NAME )
22
  );
23
 
24
  // Fallback to using PHP if not
25
  else
26
+ hmbkp_backup_mysql_fallback();
27
 
28
  }
29
 
functions/core.functions.php CHANGED
@@ -36,6 +36,8 @@ function hmbkp_deactivate() {
36
  wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
37
  wp_clear_scheduled_hook( 'hmbkp_schedule_single_backup_hook' );
38
 
 
 
39
  }
40
 
41
  /**
@@ -46,7 +48,9 @@ function hmbkp_update() {
46
 
47
  // Every update
48
  if ( version_compare( HMBKP_VERSION, get_option( 'hmbkp_plugin_version' ), '>' ) ) :
49
-
 
 
50
  delete_transient( 'hmbkp_estimated_filesize' );
51
  delete_option( 'hmbkp_running' );
52
  delete_option( 'hmbkp_complete' );
@@ -61,7 +65,7 @@ function hmbkp_update() {
61
 
62
  // Pre 1.1
63
  if ( !get_option( 'hmbkp_plugin_version' ) ) :
64
-
65
  // Delete the obsolete max backups option
66
  delete_option( 'hmbkp_max_backups' );
67
 
@@ -107,7 +111,8 @@ function hmbkp_update() {
107
  endif;
108
 
109
  // Update the stored version
110
- update_option( 'hmbkp_plugin_version', HMBKP_VERSION );
 
111
 
112
  }
113
 
@@ -138,7 +143,7 @@ function hmbkp_conform_dir( $dir, $rel = false ) {
138
 
139
  // If we're on Windows
140
  if ( strpos( ABSPATH, '\\' ) !== false )
141
- $dir = str_replace( '/', '\\', $dir );
142
 
143
  if ( $rel == true )
144
  $dir = str_replace( hmbkp_conform_dir( ABSPATH ), '', $dir );
@@ -217,7 +222,7 @@ function hmbkp_send_file( $path ) {
217
  return false;
218
 
219
  // Overide max_execution_time
220
- set_time_limit( 0 );
221
 
222
  $name = basename( $path );
223
 
@@ -259,17 +264,24 @@ function hmbkp_send_file( $path ) {
259
  */
260
  function hmbkp_ls( $dir, $files = array() ) {
261
 
 
 
 
262
  $d = opendir( $dir );
263
 
 
 
 
264
  while ( $file = readdir( $d ) ) :
265
 
266
- // Ignore current dir and containing dir as well the backups dir
267
  if ( $file == '.' || $file == '..' )
268
  continue;
269
 
270
  $file = hmbkp_conform_dir( trailingslashit( $dir ) . $file );
271
 
272
- if ( $file == hmbkp_path() )
 
273
  continue;
274
 
275
  $files[] = $file;
@@ -286,25 +298,28 @@ function hmbkp_ls( $dir, $files = array() ) {
286
  * Recursively delete a directory including
287
  * all the files and sub-directories.
288
  *
289
- * @param string $dirname
290
  */
291
- function hmbkp_rmdirtree( $dirname ) {
 
 
 
292
 
293
- if ( !is_dir( $dirname ) )
294
  return false;
295
 
296
  $result = array();
297
 
298
- $dirname = trailingslashit( $dirname );
299
 
300
- $handle = opendir( $dirname );
301
 
302
  while ( false !== ( $file = readdir( $handle ) ) ) :
303
 
304
  // Ignore . and ..
305
  if ( $file != '.' && $file != '..' ) :
306
 
307
- $path = $dirname . $file;
308
 
309
  // Recurse if subdir, Delete if file
310
  if ( is_dir( $path ) ) :
@@ -322,9 +337,9 @@ function hmbkp_rmdirtree( $dirname ) {
322
 
323
  closedir( $handle );
324
 
325
- rmdir( $dirname );
326
 
327
- $result[] .= $dirname;
328
 
329
  return $result;
330
 
@@ -340,7 +355,7 @@ function hmbkp_rmdirtree( $dirname ) {
340
  */
341
  function hmbkp_calculate() {
342
 
343
- ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
344
 
345
  // Check cache
346
  if ( $filesize = get_transient( 'hmbkp_estimated_filesize' ) )
@@ -370,9 +385,6 @@ function hmbkp_calculate() {
370
 
371
  endif;
372
 
373
- // Account for compression
374
- $filesize /= 1.9;
375
-
376
  // Cache in a transient for a week
377
  set_transient( 'hmbkp_estimated_filesize', $filesize, 604800 );
378
 
@@ -394,13 +406,29 @@ function hmbkp_shell_exec_available() {
394
  return false;
395
 
396
  // Are we in Safe Mode
397
- if ( ini_get( 'safe_mode' ) )
398
  return false;
399
 
400
  return true;
401
 
402
  }
403
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
404
  /**
405
  * Calculate the total filesize of all backups
406
  *
@@ -414,7 +442,7 @@ function hmbkp_total_filesize() {
414
  clearstatcache();
415
 
416
  foreach ( $files as $f )
417
- $filesize += @filesize( $f['file'] );
418
 
419
  return hmbkp_size_readable( $filesize );
420
 
@@ -441,7 +469,6 @@ function hmbkp_setup_daily_schedule() {
441
  wp_schedule_event( strtotime( $time ), 'hmbkp_daily', 'hmbkp_schedule_backup_hook' );
442
  }
443
 
444
-
445
  /**
446
  * Get the path to the backups directory
447
  *
@@ -458,26 +485,67 @@ function hmbkp_path() {
458
  $path = HMBKP_PATH;
459
 
460
  // If the dir doesn't exist or isn't writable then use wp-content/backups instead
461
- if ( ( !$path || !is_writable( $path ) ) && $path != WP_CONTENT_DIR . '/backups' ) :
462
- $path = WP_CONTENT_DIR . '/backups';
463
- update_option( 'hmbkp_path', $path );
464
- endif;
465
 
466
  // Create the backups directory if it doesn't exist
467
- if ( is_writable( WP_CONTENT_DIR ) && !is_dir( $path ) )
468
  mkdir( $path, 0755 );
469
 
 
 
 
470
  // Secure the directory with a .htaccess file
471
  $htaccess = $path . '/.htaccess';
472
 
473
- if ( !file_exists( $htaccess ) && is_writable( $path ) ) :
474
- require_once( ABSPATH . '/wp-admin/includes/misc.php' );
475
  insert_with_markers( $htaccess, 'BackUpWordPress', array( 'deny from all' ) );
476
- endif;
477
 
478
  return hmbkp_conform_dir( $path );
479
  }
480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  /**
482
  * The maximum number of backups to keep
483
  * defaults to 10
@@ -491,4 +559,45 @@ function hmbkp_max_backups() {
491
 
492
  return 10;
493
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
494
  }
36
  wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
37
  wp_clear_scheduled_hook( 'hmbkp_schedule_single_backup_hook' );
38
 
39
+ hmbkp_cleanup();
40
+
41
  }
42
 
43
  /**
48
 
49
  // Every update
50
  if ( version_compare( HMBKP_VERSION, get_option( 'hmbkp_plugin_version' ), '>' ) ) :
51
+
52
+ hmbkp_cleanup();
53
+
54
  delete_transient( 'hmbkp_estimated_filesize' );
55
  delete_option( 'hmbkp_running' );
56
  delete_option( 'hmbkp_complete' );
65
 
66
  // Pre 1.1
67
  if ( !get_option( 'hmbkp_plugin_version' ) ) :
68
+
69
  // Delete the obsolete max backups option
70
  delete_option( 'hmbkp_max_backups' );
71
 
111
  endif;
112
 
113
  // Update the stored version
114
+ if ( get_option( 'hmbkp_plugin_version' ) !== HMBKP_VERSION )
115
+ update_option( 'hmbkp_plugin_version', HMBKP_VERSION );
116
 
117
  }
118
 
143
 
144
  // If we're on Windows
145
  if ( strpos( ABSPATH, '\\' ) !== false )
146
+ $dir = str_replace( '\\', '/', $dir );
147
 
148
  if ( $rel == true )
149
  $dir = str_replace( hmbkp_conform_dir( ABSPATH ), '', $dir );
222
  return false;
223
 
224
  // Overide max_execution_time
225
+ @set_time_limit( 0 );
226
 
227
  $name = basename( $path );
228
 
264
  */
265
  function hmbkp_ls( $dir, $files = array() ) {
266
 
267
+ if ( !is_readable( $dir ) )
268
+ return $files;
269
+
270
  $d = opendir( $dir );
271
 
272
+ // Get excluded files & directories.
273
+ $excludes = hmbkp_exclude_string( 'pclzip' );
274
+
275
  while ( $file = readdir( $d ) ) :
276
 
277
+ // Ignore current dir and containing dir and any unreadable files or directories
278
  if ( $file == '.' || $file == '..' )
279
  continue;
280
 
281
  $file = hmbkp_conform_dir( trailingslashit( $dir ) . $file );
282
 
283
+ // Skip the backups dir and any excluded paths
284
+ if ( ( $file == hmbkp_path() || preg_match( '(' . $excludes . ')', $file ) || !is_readable( $file ) ) )
285
  continue;
286
 
287
  $files[] = $file;
298
  * Recursively delete a directory including
299
  * all the files and sub-directories.
300
  *
301
+ * @param string $dir
302
  */
303
+ function hmbkp_rmdirtree( $dir ) {
304
+
305
+ if ( is_file( $dir ) )
306
+ unlink( $dir );
307
 
308
+ if ( !is_dir( $dir ) )
309
  return false;
310
 
311
  $result = array();
312
 
313
+ $dir = trailingslashit( $dir );
314
 
315
+ $handle = opendir( $dir );
316
 
317
  while ( false !== ( $file = readdir( $handle ) ) ) :
318
 
319
  // Ignore . and ..
320
  if ( $file != '.' && $file != '..' ) :
321
 
322
+ $path = $dir . $file;
323
 
324
  // Recurse if subdir, Delete if file
325
  if ( is_dir( $path ) ) :
337
 
338
  closedir( $handle );
339
 
340
+ rmdir( $dir );
341
 
342
+ $result[] .= $dir;
343
 
344
  return $result;
345
 
355
  */
356
  function hmbkp_calculate() {
357
 
358
+ @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', '256M' ) );
359
 
360
  // Check cache
361
  if ( $filesize = get_transient( 'hmbkp_estimated_filesize' ) )
385
 
386
  endif;
387
 
 
 
 
388
  // Cache in a transient for a week
389
  set_transient( 'hmbkp_estimated_filesize', $filesize, 604800 );
390
 
406
  return false;
407
 
408
  // Are we in Safe Mode
409
+ if ( hmbkp_is_safe_mode_active() )
410
  return false;
411
 
412
  return true;
413
 
414
  }
415
 
416
+ /**
417
+ * Check whether safe mode if active or not
418
+ *
419
+ * @return bool
420
+ */
421
+ function hmbkp_is_safe_mode_active() {
422
+
423
+ $safe_mode = ini_get( 'safe_mode' );
424
+
425
+ if ( $safe_mode && $safe_mode != 'off' && $safe_mode != 'Off' )
426
+ return true;
427
+
428
+ return false;
429
+
430
+ }
431
+
432
  /**
433
  * Calculate the total filesize of all backups
434
  *
442
  clearstatcache();
443
 
444
  foreach ( $files as $f )
445
+ $filesize += @filesize( $f );
446
 
447
  return hmbkp_size_readable( $filesize );
448
 
469
  wp_schedule_event( strtotime( $time ), 'hmbkp_daily', 'hmbkp_schedule_backup_hook' );
470
  }
471
 
 
472
  /**
473
  * Get the path to the backups directory
474
  *
485
  $path = HMBKP_PATH;
486
 
487
  // If the dir doesn't exist or isn't writable then use wp-content/backups instead
488
+ if ( ( !$path || !is_writable( $path ) ) && hmbkp_conform_dir( $path ) != hmbkp_path_default() )
489
+ $path = hmbkp_path_default();
 
 
490
 
491
  // Create the backups directory if it doesn't exist
492
+ if ( is_writable( dirname( $path ) ) && !is_dir( $path ) )
493
  mkdir( $path, 0755 );
494
 
495
+ if ( get_option( 'hmbkp_path' ) != $path )
496
+ update_option( 'hmbkp_path', $path );
497
+
498
  // Secure the directory with a .htaccess file
499
  $htaccess = $path . '/.htaccess';
500
 
501
+ if ( !file_exists( $htaccess ) && is_writable( $path ) && require_once( ABSPATH . '/wp-admin/includes/misc.php' ) )
 
502
  insert_with_markers( $htaccess, 'BackUpWordPress', array( 'deny from all' ) );
 
503
 
504
  return hmbkp_conform_dir( $path );
505
  }
506
 
507
+ /**
508
+ * Return the default backup path
509
+ *
510
+ * @return string path
511
+ */
512
+ function hmbkp_path_default() {
513
+ return hmbkp_conform_dir( WP_CONTENT_DIR . '/backups' );
514
+ }
515
+
516
+ /**
517
+ * Move the backup directory and all existing backup files to a new
518
+ * location
519
+ *
520
+ * @param string $from path to move the backups dir from
521
+ * @param string $to path to move the backups dir to
522
+ * @return void
523
+ */
524
+ function hmbkp_path_move( $from, $to ) {
525
+
526
+ // Create the custom backups directory if it doesn't exist
527
+ if ( is_writable( dirname( $to ) ) && !is_dir( $to ) )
528
+ mkdir( $to, 0755 );
529
+
530
+ if ( !is_dir( $to ) || !is_writable( $to ) || !is_dir( $from ) )
531
+ return false;
532
+
533
+ hmbkp_cleanup();
534
+
535
+ if ( $handle = opendir( $from ) ) :
536
+
537
+ while ( false !== ( $file = readdir( $handle ) ) )
538
+ if ( $file != '.' && $file != '..' )
539
+ rename( trailingslashit( $from ) . $file, trailingslashit( $to ) . $file );
540
+
541
+ closedir( $handle );
542
+
543
+ endif;
544
+
545
+ hmbkp_rmdirtree( $from );
546
+
547
+ }
548
+
549
  /**
550
  * The maximum number of backups to keep
551
  * defaults to 10
559
 
560
  return 10;
561
 
562
+ }
563
+
564
+ /**
565
+ * Check if a backup is possible with regards to file
566
+ * permissions etc.
567
+ *
568
+ * @return bool
569
+ */
570
+ function hmbkp_possible() {
571
+
572
+ if ( !is_writable( hmbkp_path() ) || !is_dir( hmbkp_path() ) || hmbkp_is_safe_mode_active() )
573
+ return false;
574
+
575
+ if ( defined( 'HMBKP_FILES_ONLY' ) && HMBKP_FILES_ONLY && defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY )
576
+ return false;
577
+
578
+ return true;
579
+ }
580
+
581
+ /**
582
+ * Remove any non backup.zip files from the backups dir.
583
+ *
584
+ * @return void
585
+ */
586
+ function hmbkp_cleanup() {
587
+
588
+ $hmbkp_path = hmbkp_path();
589
+
590
+ if ( !is_dir( $hmbkp_path ) )
591
+ return;
592
+
593
+ if ( $handle = opendir( $hmbkp_path ) ) :
594
+
595
+ while ( false !== ( $file = readdir( $handle ) ) )
596
+ if ( $file != '.' && $file != '..' && $file != '.htaccess' && strpos( $file, '.zip' ) === false )
597
+ hmbkp_rmdirtree( trailingslashit( $hmbkp_path ) . $file );
598
+
599
+ closedir( $handle );
600
+
601
+ endif;
602
+
603
  }
functions/interface.functions.php CHANGED
@@ -6,16 +6,16 @@
6
  */
7
  function hmbkp_get_backup_row( $file ) {
8
 
9
- $encode = base64_encode( $file['file'] ); ?>
10
 
11
- <tr class="hmbkp_manage_backups_row<?php if ( get_option( 'hmbkp_complete' ) ) : ?> completed<?php delete_option( 'hmbkp_complete' ); endif; ?>">
12
 
13
  <th scope="row">
14
- <?php echo date( get_option('date_format'), filemtime( $file['file'] ) ) . ' ' . date( 'H:i', filemtime($file['file'] ) ); ?>
15
  </th>
16
 
17
  <td>
18
- <?php echo hmbkp_size_readable( filesize( $file['file'] ) ); ?>
19
  </td>
20
 
21
  <td>
@@ -27,4 +27,125 @@ function hmbkp_get_backup_row( $file ) {
27
 
28
  </tr>
29
 
30
- <?php }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  */
7
  function hmbkp_get_backup_row( $file ) {
8
 
9
+ $encode = base64_encode( $file ); ?>
10
 
11
+ <tr class="hmbkp_manage_backups_row<?php if ( file_exists( hmbkp_path() . '/.backup_complete' ) ) : ?> completed<?php unlink( hmbkp_path() . '/.backup_complete' ); endif; ?>">
12
 
13
  <th scope="row">
14
+ <?php echo date( get_option('date_format'), filemtime( $file ) ) . ' ' . date( 'H:i', filemtime($file ) ); ?>
15
  </th>
16
 
17
  <td>
18
+ <?php echo hmbkp_size_readable( filesize( $file ) ); ?>
19
  </td>
20
 
21
  <td>
27
 
28
  </tr>
29
 
30
+ <?php }
31
+
32
+ /**
33
+ * Displays admin notices for various error / warning
34
+ * conditions
35
+ *
36
+ * @return void
37
+ */
38
+ function hmbkp_admin_notices() {
39
+
40
+ // If the backups directory doesn't exist and can't be automatically created
41
+ if ( !is_dir( hmbkp_path() ) ) :
42
+
43
+ function hmbkp_path_exists_warning() {
44
+ $php_user = exec( 'whoami' );
45
+ $php_group = reset( explode( ' ', exec( 'groups' ) ) );
46
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress is almost ready.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'The backups directory can\'t be created because your %s directory isn\'t writable, run %s or %s or create the folder yourself.', 'hmbkp' ), '<code>wp-content</code>', '<code>chown ' . $php_user . ':' . $php_group . ' ' . WP_CONTENT_DIR . '</code>', '<code>chmod 777 ' . WP_CONTENT_DIR . '</code>' ) . '</p></div>';
47
+ }
48
+ add_action( 'admin_notices', 'hmbkp_path_exists_warning' );
49
+
50
+ endif;
51
+
52
+ // If the backups directory exists but isn't writable
53
+ if ( is_dir( hmbkp_path() ) && !is_writable( hmbkp_path() ) ) :
54
+
55
+ function hmbkp_writable_path_warning() {
56
+ $php_user = exec( 'whoami' );
57
+ $php_group = reset( explode( ' ', exec( 'groups' ) ) );
58
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress is almost ready.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'Your backups directory isn\'t writable. run %s or %s or set the permissions yourself.', 'hmbkp' ), '<code>chown -R ' . $php_user . ':' . $php_group . ' ' . hmbkp_path() . '</code>', '<code>chmod -R 777 ' . hmbkp_path() . '</code>' ) . '</p></div>';
59
+ }
60
+ add_action( 'admin_notices', 'hmbkp_writable_path_warning' );
61
+
62
+ endif;
63
+
64
+ // If safe mode is active
65
+ if ( hmbkp_is_safe_mode_active() ) :
66
+
67
+ function hmbkp_safe_mode_warning() {
68
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( ' %s is running in %s. Please contact your host and ask them to disable %s.', 'hmbkp' ), '<code>PHP</code>', '<a href="http://php.net/manual/en/features.safe-mode.php"><code>Safe Mode</code></a>', '<code>Safe Mode</code>' ) . '</p></div>';
69
+ }
70
+ add_action( 'admin_notices', 'hmbkp_safe_mode_warning' );
71
+
72
+ endif;
73
+
74
+ // If both HMBKP_FILES_ONLY & HMBKP_DATABASE_ONLY are defined at the same time
75
+ if ( defined( 'HMBKP_FILES_ONLY' ) && HMBKP_FILES_ONLY && defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY ) :
76
+
77
+ function hmbkp_nothing_to_backup_warning() {
78
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'You have both %s and %s defined so there isn\'t anything to back up.', 'hmbkp' ), '<code>HMBKP_DATABASE_ONLY</code>', '<code>HMBKP_FILES_ONLY</code>' ) . '</p></div>';
79
+ }
80
+ add_action( 'admin_notices', 'hmbkp_nothing_to_backup_warning' );
81
+
82
+ endif;
83
+
84
+ // If the email address is invalid
85
+ if ( defined( 'HMBKP_EMAIL' ) && !is_email( HMBKP_EMAIL ) ) :
86
+
87
+ function hmbkp_email_invalid_warning() {
88
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( '%s is not a valid email address.', 'hmbkp' ), '<code>' . HMBKP_EMAIL . '</code>' ) . '</p></div>';
89
+ }
90
+ add_action( 'admin_notices', 'hmbkp_email_invalid_warning' );
91
+
92
+ endif;
93
+
94
+ // If the email failed to send
95
+ if ( defined( 'HMBKP_EMAIL' ) && get_option( 'hmbkp_email_error' ) ) :
96
+
97
+ function hmbkp_email_failed_warning() {
98
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . __( 'The last backup email failed to send.', 'hmbkp' ) . '</p></div>';
99
+ }
100
+ add_action( 'admin_notices', 'hmbkp_email_failed_warning' );
101
+
102
+ endif;
103
+
104
+ // If a custom backups directory is defined and it doesn't exist and can't be created
105
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH && !is_dir( HMBKP_PATH ) ) :
106
+
107
+ function hmbkp_custom_path_exists_warning() {
108
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'Your custom backups directory %s doesn\'t exist and can\'t be created, your backups will be saved to %s instead.', 'hmbkp' ), '<code>' . HMBKP_PATH . '</code>', '<code>' . hmbkp_path() . '</code>' ) . '</p></div>';
109
+ }
110
+ add_action( 'admin_notices', 'hmbkp_custom_path_exists_warning' );
111
+
112
+ endif;
113
+
114
+ // If a custom backups directory is defined and exists but isn't writable
115
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH && is_dir( HMBKP_PATH ) && !is_writable( HMBKP_PATH ) ) :
116
+
117
+ function hmbkp_custom_path_writable_notice() {
118
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'Your custom backups directory %s isn\'t writable, new backups will be saved to %s instead.', 'hmbkp' ), '<code>' . HMBKP_PATH . '</code>', '<code>' . hmbkp_path() . '</code>' ) . '</p></div>';
119
+ }
120
+ add_action( 'admin_notices', 'hmbkp_custom_path_writable_notice' );
121
+
122
+ endif;
123
+
124
+ // If there are custom excludes defined and any of the files or directories don't exist
125
+ if ( hmbkp_invalid_custom_excludes() ) :
126
+
127
+ function hmbkp_invalid_exclude_notice() {
128
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'You have defined a custom exclude list but the following paths don\'t exist %s, are you sure you entered them correctly?', 'hmbkp' ), '<code>' . implode( '</code>, <code>', (array) hmbkp_invalid_custom_excludes() ) . '</code>' ) . '</p></div>';
129
+ }
130
+ add_action( 'admin_notices', 'hmbkp_invalid_exclude_notice' );
131
+
132
+ endif;
133
+
134
+ }
135
+ add_action( 'admin_head', 'hmbkp_admin_notices' );
136
+
137
+ /**
138
+ * Hook in an change the plugin description when BackUpWordPress is activated
139
+ *
140
+ * @param array $plugins
141
+ * @return $plugins
142
+ */
143
+ function hmbkp_plugin_row( $plugins ) {
144
+
145
+ if ( isset( $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php'] ) )
146
+ $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php']['Description'] = str_replace( 'Once activated you\'ll find me under <strong>Tools &rarr; Backups</strong>', 'Find me under <strong><a href="' . admin_url( 'tools.php?page=' . HMBKP_PLUGIN_SLUG ) . '">Tools &rarr; Backups</a></strong>', $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php']['Description'] );
147
+
148
+ return $plugins;
149
+
150
+ }
151
+ add_filter( 'all_plugins', 'hmbkp_plugin_row', 10 );
functions/mysql-ping.php DELETED
@@ -1,85 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * "MySQL Ping" Keeps mysql connections alive
5
- *
6
- * Extend the default {@link wpdb} class by
7
- * adding {@link mysql_ping()} capabilities
8
- *
9
- * @author Kaloyan K. Tsvetkov <kaloyan@kaloyan.info>
10
- * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11
- */
12
- Class wpdb2 Extends wpdb {
13
-
14
- /**
15
- * Attemp to ping the MySQL server
16
- */
17
- function _ping() {
18
-
19
- $retry = 5;
20
- $failed = 1;
21
-
22
- // probe w\ a ping
23
- $ping = mysql_ping( $this->dbh ) ;
24
-
25
- while( !$ping && $failed < $retry ) :
26
-
27
- // Reconnect
28
- $this->dbh = mysql_connect( DB_HOST, DB_USER, DB_PASSWORD, 1 );
29
- $this->select( DB_NAME );
30
-
31
- if ( !DB_CHARSET && version_compare( mysql_get_server_info( $this->dbh ), '4.1.0', '>=' ) )
32
- $this->query( "SET NAMES '" . DB_CHARSET . "'" );
33
-
34
- // Ping again to check the result
35
- $ping = mysql_ping( $this->dbh ) ;
36
-
37
- if ( !$ping ) {
38
- sleep(2);
39
- $failed+=1;
40
- }
41
-
42
- endwhile;
43
-
44
- // Ping failed
45
- if ( !$ping )
46
- $this->print_error( 'Attempted to connect for ' . $retry . ' but failed...' );
47
-
48
- }
49
-
50
- /**
51
- * Override the original {@link wpdb::query()} method in
52
- * order to ping the server before executing every query
53
- *
54
- * @param string $query
55
- * @return mixed
56
- */
57
- function query( $query ) {
58
-
59
- $this->_ping();
60
-
61
- return parent::query( $query );
62
-
63
- }
64
-
65
- }
66
-
67
- /**
68
- * If mysql.max_links is 2 or less and we're using the mysqldump fallback
69
- * then we need the second link for the backup so we can't include
70
- * mysql_ping.
71
- */
72
- if ( ini_get( 'mysql.max_links' > 2 ) && !hmbkp_mysqldump_path() ) :
73
-
74
- // Setup the wpdb2 class
75
- $wpdb2 = new wpdb2( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST );
76
-
77
- // Copy over the $wpdb vars
78
- global $wpdb;
79
- foreach( get_object_vars( $wpdb ) as $k => $v )
80
- if ( is_scalar( $v ) )
81
- $wpdb2->$k = $v;
82
-
83
- $wpdb =& $wpdb2;
84
-
85
- endif;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
hmbkp.css ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #icon-backupwordpress.icon32 { background: url(icon_backupwordpress_32x32.png); }
2
+ .hmbkp_running .add-new-h2 img { margin: 0 3px -4px -9px; opacity: 0.3; }
3
+ .button.disabled, .button[disabled], .button[disabled="disabled"] { cursor: default; }
4
+ .button.disabled:active, .button[disabled]:active, .button[disabled="disabled"]:active { background: #F2F2F2 url(../../../../wp-admin/images/white-grad.png) repeat-x; }
5
+ tfoot p { margin: 0; font-weight: normal; }
6
+ #hmbkp_advanced-options { display: none; }
7
+ #hmbkp_advanced-options dl { overflow: hidden; margin: 20px 0; }
8
+ #hmbkp_advanced-options dt { float: left; min-width: 250px; clear: both; padding: 6px; margin: 1px 0; cursor: pointer; }
9
+ #hmbkp_advanced-options dd { color: #666; padding: 7px 0 7px 250px; border-top: 1px solid #DFDFDF; margin: 0; cursor: pointer; min-height: 34px; }
10
+ #hmbkp_advanced-options dd:last-child { border-bottom: 1px solid #DFDFDF; }
11
+ #hmbkp_advanced-options dt:not(.hmbkp_active) + dd { background: #F9F9F9; }
12
+ #hmbkp_advanced-options dd .example { white-space: nowrap; display: none; }
13
+ #hmbkp_advanced-options dd p { margin: 0; }
14
+ #hmbkp_advanced-options dt:not(.hmbkp_active):hover + dd, #hmbkp_advanced-options dt:not(.hmbkp_active) + dd:hover { background-color: #FFF; }
15
+ #hmbkp_advanced-options dd:hover p, #hmbkp_advanced-options dt:hover + dd p { display: none; }
16
+ #hmbkp_advanced-options dd:hover .example, #hmbkp_advanced-options dt:hover + dd .example { display: inline; }
17
+ .hmbkp_manage_backups_row .delete { color: #BC0B0B; }
18
+ .hmbkp_manage_backups_row .delete:hover { color: red; }
19
+ .completed th, .completed td { background-color: #FFFFE0; }
20
+ .hmbkp_active:before { content: "\00a0 \2713 "; font-size: 11px; }
21
+ .hmbkp_active, .hmbkp_active code, #hmbkp_advanced-options .hmbkp_active + dd { background: #E5F7E8; }
hmbkp.js ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery( document ).ready( function( $ ) {
2
+
3
+ if ( $( '.hmbkp_running' ).size() ) {
4
+ hmbkpRedirectOnBackupComplete();
5
+ }
6
+
7
+ if ( $( '.hmbkp_estimated-size .calculate' ).size() ) {
8
+ $.get( ajaxurl, { 'action' : 'hmbkp_calculate' },
9
+ function( data ) {
10
+ $( '.hmbkp_estimated-size .calculate' ).fadeOut( function() {
11
+ $( this ).empty().append( data );
12
+ } ).fadeIn();
13
+ }
14
+ );
15
+ }
16
+
17
+ $.get( ajaxurl, { 'action' : 'hmbkp_cron_test' },
18
+ function( data ) {
19
+ if ( data != 1 ) {
20
+ $( '.wrap > h2' ).after( data );
21
+ }
22
+ }
23
+ );
24
+
25
+ $( '.hmbkp_advanced-options-toggle' ).click( function() {
26
+ $( '#hmbkp_advanced-options' ).toggle();
27
+ } );
28
+
29
+ } );
30
+
31
+ function hmbkpRedirectOnBackupComplete() {
32
+
33
+ img = jQuery( '<div>' ).append( jQuery( '.hmbkp_running a.button[disabled]:first img' ).clone() ).remove().html();
34
+
35
+ jQuery.get( ajaxurl, { 'action' : 'hmbkp_is_in_progress' },
36
+
37
+ function( data ) {
38
+
39
+ if ( data == 0 ) {
40
+
41
+ location.reload( true );
42
+
43
+ } else {
44
+
45
+ setTimeout( 'hmbkpRedirectOnBackupComplete();', 5000 );
46
+
47
+ jQuery( '.hmbkp_running a.button[disabled]:first' ).html( img + data );
48
+
49
+ }
50
+ }
51
+ );
52
+
53
+ }
icon_backupwordpress_16x16.png ADDED
Binary file
icon_backupwordpress_16x16_hover.png ADDED
Binary file
icon_backupwordpress_32x32.png ADDED
Binary file
interface.functions.php ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Displays a row in the manage backups table
4
+ *
5
+ * @param string $file
6
+ */
7
+ function hmbkp_get_backup_row( $file ) {
8
+
9
+ $encode = base64_encode( $file ); ?>
10
+
11
+ <tr class="hmbkp_manage_backups_row<?php if ( file_exists( hmbkp_path() . '/.backup_complete' ) ) : ?> completed<?php unlink( hmbkp_path() . '/.backup_complete' ); endif; ?>">
12
+
13
+ <th scope="row">
14
+ <?php echo date( get_option('date_format'), filemtime( $file ) ) . ' ' . date( 'H:i', filemtime($file ) ); ?>
15
+ </th>
16
+
17
+ <td>
18
+ <?php echo hmbkp_size_readable( filesize( $file ) ); ?>
19
+ </td>
20
+
21
+ <td>
22
+
23
+ <a href="tools.php?page=<?php echo HMBKP_PLUGIN_SLUG; ?>&amp;hmbkp_download=<?php echo $encode; ?>"><?php _e( 'Download', 'hmbkp' ); ?></a> |
24
+ <a href="tools.php?page=<?php echo HMBKP_PLUGIN_SLUG; ?>&amp;hmbkp_delete=<?php echo $encode ?>" class="delete"><?php _e( 'Delete', 'hmbkp' ); ?></a>
25
+
26
+ </td>
27
+
28
+ </tr>
29
+
30
+ <?php }
31
+
32
+ /**
33
+ * Displays admin notices for various error / warning
34
+ * conditions
35
+ *
36
+ * @return void
37
+ */
38
+ function hmbkp_admin_notices() {
39
+
40
+ // If the backups directory doesn't exist and can't be automatically created
41
+ if ( !is_dir( hmbkp_path() ) ) :
42
+
43
+ function hmbkp_path_exists_warning() {
44
+ $php_user = exec( 'whoami' );
45
+ $php_group = reset( explode( ' ', exec( 'groups' ) ) );
46
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress is almost ready.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'The backups directory can\'t be created because your %s directory isn\'t writable, run %s or %s or create the folder yourself.', 'hmbkp' ), '<code>wp-content</code>', '<code>chown ' . $php_user . ':' . $php_group . ' ' . WP_CONTENT_DIR . '</code>', '<code>chmod 777 ' . WP_CONTENT_DIR . '</code>' ) . '</p></div>';
47
+ }
48
+ add_action( 'admin_notices', 'hmbkp_path_exists_warning' );
49
+
50
+ endif;
51
+
52
+ // If the backups directory exists but isn't writable
53
+ if ( is_dir( hmbkp_path() ) && !is_writable( hmbkp_path() ) ) :
54
+
55
+ function hmbkp_writable_path_warning() {
56
+ $php_user = exec( 'whoami' );
57
+ $php_group = reset( explode( ' ', exec( 'groups' ) ) );
58
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress is almost ready.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'Your backups directory isn\'t writable. run %s or %s or set the permissions yourself.', 'hmbkp' ), '<code>chown -R ' . $php_user . ':' . $php_group . ' ' . hmbkp_path() . '</code>', '<code>chmod -R 777 ' . hmbkp_path() . '</code>' ) . '</p></div>';
59
+ }
60
+ add_action( 'admin_notices', 'hmbkp_writable_path_warning' );
61
+
62
+ endif;
63
+
64
+ // If safe mode is active
65
+ if ( hmbkp_is_safe_mode_active() ) :
66
+
67
+ function hmbkp_safe_mode_warning() {
68
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( ' %s is running in %s. Please contact your host and ask them to disable %s.', 'hmbkp' ), '<code>PHP</code>', '<a href="http://php.net/manual/en/features.safe-mode.php"><code>Safe Mode</code></a>', '<code>Safe Mode</code>' ) . '</p></div>';
69
+ }
70
+ add_action( 'admin_notices', 'hmbkp_safe_mode_warning' );
71
+
72
+ endif;
73
+
74
+ // If both HMBKP_FILES_ONLY & HMBKP_DATABASE_ONLY are defined at the same time
75
+ if ( defined( 'HMBKP_FILES_ONLY' ) && HMBKP_FILES_ONLY && defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY ) :
76
+
77
+ function hmbkp_nothing_to_backup_warning() {
78
+ echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'You have both %s and %s defined so there isn\'t anything to back up.', 'hmbkp' ), '<code>HMBKP_DATABASE_ONLY</code>', '<code>HMBKP_FILES_ONLY</code>' ) . '</p></div>';
79
+ }
80
+ add_action( 'admin_notices', 'hmbkp_nothing_to_backup_warning' );
81
+
82
+ endif;
83
+
84
+ // If the email address is invalid
85
+ if ( defined( 'HMBKP_EMAIL' ) && !is_email( HMBKP_EMAIL ) ) :
86
+
87
+ function hmbkp_email_invalid_warning() {
88
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( '%s is not a valid email address.', 'hmbkp' ), '<code>' . HMBKP_EMAIL . '</code>' ) . '</p></div>';
89
+ }
90
+ add_action( 'admin_notices', 'hmbkp_email_invalid_warning' );
91
+
92
+ endif;
93
+
94
+ // If the email failed to send
95
+ if ( defined( 'HMBKP_EMAIL' ) && get_option( 'hmbkp_email_error' ) ) :
96
+
97
+ function hmbkp_email_failed_warning() {
98
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . __( 'The last backup email failed to send.', 'hmbkp' ) . '</p></div>';
99
+ }
100
+ add_action( 'admin_notices', 'hmbkp_email_failed_warning' );
101
+
102
+ endif;
103
+
104
+ // If a custom backups directory is defined and it doesn't exist and can't be created
105
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH && !is_dir( HMBKP_PATH ) ) :
106
+
107
+ function hmbkp_custom_path_exists_warning() {
108
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'Your custom backups directory %s doesn\'t exist and can\'t be created, your backups will be saved to %s instead.', 'hmbkp' ), '<code>' . HMBKP_PATH . '</code>', '<code>' . hmbkp_path() . '</code>' ) . '</p></div>';
109
+ }
110
+ add_action( 'admin_notices', 'hmbkp_custom_path_exists_warning' );
111
+
112
+ endif;
113
+
114
+ // If a custom backups directory is defined and exists but isn't writable
115
+ if ( defined( 'HMBKP_PATH' ) && HMBKP_PATH && is_dir( HMBKP_PATH ) && !is_writable( HMBKP_PATH ) ) :
116
+
117
+ function hmbkp_custom_path_writable_notice() {
118
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'Your custom backups directory %s isn\'t writable, new backups will be saved to %s instead.', 'hmbkp' ), '<code>' . HMBKP_PATH . '</code>', '<code>' . hmbkp_path() . '</code>' ) . '</p></div>';
119
+ }
120
+ add_action( 'admin_notices', 'hmbkp_custom_path_writable_notice' );
121
+
122
+ endif;
123
+
124
+ // If there are custom excludes defined and any of the files or directories don't exist
125
+ if ( hmbkp_invalid_custom_excludes() ) :
126
+
127
+ function hmbkp_invalid_exclude_notice() {
128
+ echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'You have defined a custom exclude list but the following paths don\'t exist %s, are you sure you entered them correctly?', 'hmbkp' ), '<code>' . implode( '</code>, <code>', (array) hmbkp_invalid_custom_excludes() ) . '</code>' ) . '</p></div>';
129
+ }
130
+ add_action( 'admin_notices', 'hmbkp_invalid_exclude_notice' );
131
+
132
+ endif;
133
+
134
+ }
135
+ add_action( 'admin_head', 'hmbkp_admin_notices' );
136
+
137
+ /**
138
+ * Hook in an change the plugin description when BackUpWordPress is activated
139
+ *
140
+ * @param array $plugins
141
+ * @return $plugins
142
+ */
143
+ function hmbkp_plugin_row( $plugins ) {
144
+
145
+ if ( isset( $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php'] ) )
146
+ $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php']['Description'] = str_replace( 'Once activated you\'ll find me under <strong>Tools &rarr; Backups</strong>', 'Find me under <strong><a href="' . admin_url( 'tools.php?page=' . HMBKP_PLUGIN_SLUG ) . '">Tools &rarr; Backups</a></strong>', $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php']['Description'] );
147
+
148
+ return $plugins;
149
+
150
+ }
151
+ add_filter( 'all_plugins', 'hmbkp_plugin_row', 10 );
plugin.php CHANGED
@@ -5,7 +5,7 @@ Plugin Name: BackUpWordPress
5
  Plugin URI: http://humanmade.co.uk/
6
  Description: Simple automated backups of your WordPress powered website. Once activated you'll find me under <strong>Tools &rarr; Backups</strong>.
7
  Author: Human Made Limited
8
- Version: 1.2
9
  Author URI: http://humanmade.co.uk/
10
  */
11
 
@@ -29,6 +29,19 @@ Author URI: http://humanmade.co.uk/
29
  define( 'HMBKP_PLUGIN_SLUG', 'backupwordpress' );
30
  define( 'HMBKP_PLUGIN_PATH', WP_PLUGIN_DIR . '/' . HMBKP_PLUGIN_SLUG );
31
  define( 'HMBKP_PLUGIN_URL', WP_PLUGIN_URL . '/' . HMBKP_PLUGIN_SLUG );
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  // Load the admin actions file
34
  function hmbkp_actions() {
@@ -49,41 +62,12 @@ function hmbkp_actions() {
49
  wp_enqueue_style( 'hmbkp', HMBKP_PLUGIN_URL . '/assets/hmbkp.css' );
50
  endif;
51
 
52
- // Check whether we need to disable the cron
53
- if ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) && HMBKP_DISABLE_AUTOMATIC_BACKUP && wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) )
54
- wp_clear_scheduled_hook( 'hmbkp_schedule_backup_hook' );
55
-
56
- // Or whether we need to re-enable it
57
- elseif( ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) && !HMBKP_DISABLE_AUTOMATIC_BACKUP || !defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) ) && !wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) )
58
- hmbkp_setup_daily_schedule();
59
-
60
- // Allow the time of the daily backup to be changed
61
- if ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) && HMBKP_DAILY_SCHEDULE_TIME && wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) != strtotime( HMBKP_DAILY_SCHEDULE_TIME ) && wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) )
62
- hmbkp_setup_daily_schedule();
63
-
64
- // Reset if custom time is removed
65
- elseif( ( ( defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) && !HMBKP_DAILY_SCHEDULE_TIME ) || !defined( 'HMBKP_DAILY_SCHEDULE_TIME' ) ) && date( 'H:i', wp_next_scheduled( 'hmbkp_schedule_backup_hook' ) ) != '23:00' && ( defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) && !HMBKP_DISABLE_AUTOMATIC_BACKUP || !defined( 'HMBKP_DISABLE_AUTOMATIC_BACKUP' ) ) )
66
- hmbkp_setup_daily_schedule();
67
 
68
  }
69
  add_action( 'admin_init', 'hmbkp_actions' );
70
 
71
- /**
72
- * Hook in an change the plugin description when BackUpWordPress is activated
73
- *
74
- * @param array $plugins
75
- * @return $plugins
76
- */
77
- function hmbkp_plugin_row( $plugins ) {
78
-
79
- if ( isset( $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php'] ) )
80
- $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php']['Description'] = str_replace( 'Once activated you\'ll find me under <strong>Tools &rarr; Backups</strong>', 'Find me under <strong><a href="' . admin_url( 'tools.php?page=' . HMBKP_PLUGIN_SLUG ) . '">Tools &rarr; Backups</a></strong>', $plugins[HMBKP_PLUGIN_SLUG . '/plugin.php']['Description'] );
81
-
82
- return $plugins;
83
-
84
- }
85
- add_filter( 'all_plugins', 'hmbkp_plugin_row', 10 );
86
-
87
  // Load the admin menu
88
  require_once( HMBKP_PLUGIN_PATH . '/admin.menus.php' );
89
 
@@ -95,7 +79,6 @@ require_once( HMBKP_PLUGIN_PATH . '/functions/backup.mysql.functions.php' );
95
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.files.functions.php' );
96
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.mysql.fallback.functions.php' );
97
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.files.fallback.functions.php' );
98
- require_once( HMBKP_PLUGIN_PATH . '/functions/mysql-ping.php' );
99
 
100
  // Plugin activation and deactivation
101
  add_action( 'activate_' . HMBKP_PLUGIN_SLUG . '/plugin.php', 'hmbkp_activate' );
@@ -106,69 +89,4 @@ add_filter( 'cron_schedules', 'hmbkp_more_reccurences' );
106
 
107
  // Cron hook for backups
108
  add_action( 'hmbkp_schedule_backup_hook', 'hmbkp_do_backup' );
109
- add_action( 'hmbkp_schedule_single_backup_hook', 'hmbkp_do_backup' );
110
-
111
- // Make sure backups dir exists and is writable
112
- if ( !is_dir( hmbkp_path() ) ) :
113
-
114
- function hmbkp_path_exists_warning() {
115
- $php_user = exec( 'whoami' );
116
- $php_group = reset( explode( ' ', exec( 'groups' ) ) );
117
- echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress is almost ready.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'The backups directory can\'t be created because your %s directory isn\'t writable, run %s or %s or create the folder yourself.', 'hmbkp' ), '<code>wp-content</code>', '<code>chown ' . $php_user . ':' . $php_group . ' ' . WP_CONTENT_DIR . '</code>', '<code>chmod 777 ' . WP_CONTENT_DIR . '</code>' ) . '</p></div>';
118
- }
119
- add_action( 'admin_notices', 'hmbkp_path_exists_warning' );
120
-
121
- endif;
122
-
123
- if ( is_dir( hmbkp_path() ) && !is_writable( hmbkp_path() ) ) :
124
-
125
- function hmbkp_writable_path_warning() {
126
- $php_user = exec( 'whoami' );
127
- $php_group = reset( explode( ' ', exec( 'groups' ) ) );
128
- echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress is almost ready.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'Your backups directory isn\'t writable. run %s or %s or set the permissions yourself.', 'hmbkp' ), '<code>chown -R ' . $php_user . ':' . $php_group . ' ' . hmbkp_path() . '</code>', '<code>chmod -R 777 ' . hmbkp_path() . '</code>' ) . '</p></div>';
129
- }
130
- add_action( 'admin_notices', 'hmbkp_writable_path_warning' );
131
-
132
- endif;
133
-
134
- if ( ini_get( 'safe_mode' ) ) :
135
-
136
- function hmbkp_safe_mode_warning() {
137
- echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( ' %s is running in %s. Please contact your host and ask them to disable %s.', 'hmbkp' ), '<code>PHP</code>', '<a href="http://php.net/manual/en/features.safe-mode.php"><code>Safe Mode</code></a>', '<code>Safe Mode</code>' ) . '</p></div>';
138
- }
139
- add_action( 'admin_notices', 'hmbkp_safe_mode_warning' );
140
-
141
- endif;
142
-
143
- if ( defined( 'HMBKP_FILES_ONLY' ) && HMBKP_FILES_ONLY && defined( 'HMBKP_DATABASE_ONLY' ) && HMBKP_DATABASE_ONLY ) :
144
-
145
- function hmbkp_nothing_to_backup_warning() {
146
- echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'You have both %s and %s defined so there isn\'t anything to back up.', 'hmbkp' ), '<code>HMBKP_DATABASE_ONLY</code>', '<code>HMBKP_FILES_ONLY</code>' ) . '</p></div>';
147
- }
148
- add_action( 'admin_notices', 'hmbkp_nothing_to_backup_warning' );
149
-
150
- endif;
151
-
152
- if ( get_transient( 'hmbkp_estimated_filesize' ) && disk_free_space( ABSPATH ) <= ( 2 * get_transient( 'hmbkp_estimated_filesize' ) ) ) :
153
-
154
- function hmbkp_low_space_warning() {
155
- echo '<div id="hmbkp-warning" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( 'You only have %s of free space left on your server.', 'hmbkp' ), '<code>' . hmbkp_size_readable( disk_free_space( ABSPATH ), null, '%01u %s' ) . '</code>' ) . '</p></div>';
156
- }
157
- add_action( 'admin_notices', 'hmbkp_low_space_warning' );
158
-
159
- endif;
160
-
161
- if( defined( 'HMBKP_EMAIL' ) && !is_email( HMBKP_EMAIL ) ) :
162
- function hmbkp_email_invalid(){
163
- echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . sprintf( __( '%s is not a valid email address.', 'hmbkp' ), '<code>' . HMBKP_EMAIL . '</code>' ) . '</p></div>';
164
- }
165
- add_action( 'admin_notices', 'hmbkp_email_invalid' );
166
- endif;
167
-
168
-
169
- if ( defined( 'HMBKP_EMAIL' ) && get_option( 'hmbkp_email_error' ) ) :
170
- function hmbkp_email_error(){
171
- echo '<div id="hmbkp-email_invalid" class="updated fade"><p><strong>' . __( 'BackUpWordPress has detected a problem.', 'hmbkp' ) . '</strong> ' . __( 'The last backup email failed to send.', 'hmbkp' ) . '</p></div>';
172
- }
173
- add_action( 'admin_notices', 'hmbkp_email_error' );
174
- endif;
5
  Plugin URI: http://humanmade.co.uk/
6
  Description: Simple automated backups of your WordPress powered website. Once activated you'll find me under <strong>Tools &rarr; Backups</strong>.
7
  Author: Human Made Limited
8
+ Version: 1.3
9
  Author URI: http://humanmade.co.uk/
10
  */
11
 
29
  define( 'HMBKP_PLUGIN_SLUG', 'backupwordpress' );
30
  define( 'HMBKP_PLUGIN_PATH', WP_PLUGIN_DIR . '/' . HMBKP_PLUGIN_SLUG );
31
  define( 'HMBKP_PLUGIN_URL', WP_PLUGIN_URL . '/' . HMBKP_PLUGIN_SLUG );
32
+ define( 'HMBKP_REQUIRED_WP_VERSION', '3.1' );
33
+
34
+ // Don't activate on old versions of WordPress
35
+ if ( version_compare( get_bloginfo('version'), HMBKP_REQUIRED_WP_VERSION, '<' ) ) {
36
+
37
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
38
+
39
+ deactivate_plugins( ABSPATH . 'wp-content/plugins/' . HMBKP_PLUGIN_SLUG . '/plugin.php' );
40
+
41
+ if ( isset( $_GET['action'] ) && ( $_GET['action'] == 'activate' || $_GET['action'] == 'error_scrape' ) )
42
+ die( sprintf( __( 'BackUpWordPress requires WordPress version %s.', 'hmbkp' ), HMBKP_REQUIRED_WP_VERSION ) );
43
+
44
+ }
45
 
46
  // Load the admin actions file
47
  function hmbkp_actions() {
62
  wp_enqueue_style( 'hmbkp', HMBKP_PLUGIN_URL . '/assets/hmbkp.css' );
63
  endif;
64
 
65
+ // Handle any advanced option changes
66
+ hmbkp_constant_changes();
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
  }
69
  add_action( 'admin_init', 'hmbkp_actions' );
70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  // Load the admin menu
72
  require_once( HMBKP_PLUGIN_PATH . '/admin.menus.php' );
73
 
79
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.files.functions.php' );
80
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.mysql.fallback.functions.php' );
81
  require_once( HMBKP_PLUGIN_PATH . '/functions/backup.files.fallback.functions.php' );
 
82
 
83
  // Plugin activation and deactivation
84
  add_action( 'activate_' . HMBKP_PLUGIN_SLUG . '/plugin.php', 'hmbkp_activate' );
89
 
90
  // Cron hook for backups
91
  add_action( 'hmbkp_schedule_backup_hook', 'hmbkp_do_backup' );
92
+ add_action( 'hmbkp_schedule_single_backup_hook', 'hmbkp_do_backup' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -1,26 +1,27 @@
1
  === BackUpWordPress ===
2
- Contributors: willmot, matheu, joehoyle, humanmade
3
- Tags: back up, back up, backup, backups, database, zip, db, files, archive
4
- Requires at least: 3.0
5
  Tested up to: 3.1.2
6
- Stable tag: 1.2
7
 
8
- Simple automated backups of your WordPress powered website.
9
 
10
  == Description ==
11
 
12
  BackUpWordPress will back up your entire site including your database and all your files once every day. It has several advanced options for power users.
13
 
14
- Features include:
15
 
16
  * Super simple to use, no setup required.
17
- * Uses `zip` and `mysqldump` for faster backups if they are available.
 
18
  * Option to have each backup file emailed to you.
19
  * Works on Linux & Windows Server.
20
  * Control advanced options by defining any of the optional `Constants`.
 
21
  * Good support should you need help.
22
 
23
-
24
  == Installation ==
25
 
26
  1. Install BackUpWordPress either via the WordPress.org plugin directory, or by uploading the files to your server.
@@ -31,7 +32,42 @@ The plugin will try to use the `mysqldump` and `zip` commands via shell if they
31
 
32
  == Frequently Asked Questions ==
33
 
34
- Contact support@humanmade.co.uk for help/support.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  == Screenshots ==
37
 
@@ -39,6 +75,24 @@ Contact support@humanmade.co.uk for help/support.
39
 
40
  == Changelog ==
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  #### 1.2
43
 
44
  * Show live backup status in the back up now button when a back up is running.
1
  === BackUpWordPress ===
2
+ Contributors: willmot, mattheu, joehoyle, humanmade
3
+ Tags: back up, back up, backup, backups, database, zip, db, files, archive, humanmade
4
+ Requires at least: 3.1
5
  Tested up to: 3.1.2
6
+ Stable tag: 1.3
7
 
8
+ Simple automated back ups of your WordPress powered website.
9
 
10
  == Description ==
11
 
12
  BackUpWordPress will back up your entire site including your database and all your files once every day. It has several advanced options for power users.
13
 
14
+ = Features =
15
 
16
  * Super simple to use, no setup required.
17
+ * Uses `zip` and `mysqldump` for faster back ups if they are available.
18
+ * Works in low memory, "shared host" environments.
19
  * Option to have each backup file emailed to you.
20
  * Works on Linux & Windows Server.
21
  * Control advanced options by defining any of the optional `Constants`.
22
+ * Exclude files and folders from your back ups.
23
  * Good support should you need help.
24
 
 
25
  == Installation ==
26
 
27
  1. Install BackUpWordPress either via the WordPress.org plugin directory, or by uploading the files to your server.
32
 
33
  == Frequently Asked Questions ==
34
 
35
+ **Where does BackUpWordPress store the backup files?**
36
+
37
+ Backups are stored on your server in `wp-content/backups`, you can change the directory.
38
+
39
+ **Important:** By default BackUpWordPress backs up everything in your site root as well as your database, this includes any non WordPress folders that happen to be in your site root. This does means that your backup directory can get quite large.
40
+
41
+ **How do I restore my site from a backup?**
42
+
43
+ You need to download the latest backup file either by clicking download on the backups page or via `FTP`. `Unzip` the files and upload all the files to your server overwriting your site. You can then import the database using your hosts database management tool (likely `phpMyAdmin`).
44
+
45
+ **How do I change BackUpWordPress options?**
46
+
47
+ A list of available options can be found on the Backups page in the admin. Click the Advanced Options button to see all the options.
48
+
49
+ To set an option you define a `Constant` in your `wp-config.php` file see the following links for help defining `Constants` and editing your `wp-config.php` file:
50
+
51
+ * http://php.net/manual/en/language.constants.php
52
+ * http://codex.wordpress.org/Editing_wp-config.php
53
+
54
+ For example: to set the number of backups stored to 3 add `define( 'HMBKP_MAX_BACKUPS', 3 );` to your `wp-config.php` file.
55
+
56
+ **Does BackUpWordPress back up the backups directory?**
57
+
58
+ No.
59
+
60
+ **How many backups are stored by default**
61
+
62
+ BackUpWordPress stores the last 10 backups by default.
63
+
64
+ **Further Support & Feedbask**
65
+
66
+ General support questions should be posted in the <a href="http://wordpress.org/tags/backupwordpress?forum_id=10">WordPress support forums, tagged with backupwordpress.</a>
67
+
68
+ For development issues, feature requests or anybody wishing to help out with development checkout <a href="https://github.com/humanmade/HM-Portfolio">BackUpWordPress on GitHub.</a>
69
+
70
+ You can also twitter <a href="http://twitter.com/humanmadeltd">@humanmadeltd</a> or email support@humanmade.co.uk for further help/support.
71
 
72
  == Screenshots ==
73
 
75
 
76
  == Changelog ==
77
 
78
+ #### 1.3
79
+
80
+ * Re-written back up engine, no longer copies everything to a tmp folder before zipping which should improve speed and reliability.
81
+ * Support for excluding files and folders, define `HMBKP_EXCLUDE` with a comma separated list of files and folders to exclude, supports wildcards `*`, path fragments and absolute paths.
82
+ * Full support for moving the backups directory, if you define a new backups directory then your existing backups will be moved to it.
83
+ * Work around issues caused by low MySQL `wait_timeout` setting.
84
+ * Add FAQ to readme.txt.
85
+ * Pull FAQ into the contextual help tab on the backups page.
86
+ * Block activation on old versions of WordPress.
87
+ * Stop guessing compressed backup file size, instead just show size of site uncompressed.
88
+ * Fix bug in `safe_mode` detection which could cause `Off` to act like `On`.
89
+ * Better name for the database dump file.
90
+ * Better name for the backup files.
91
+ * Improve styling for advanced options.
92
+ * Show examples for all advanced options.
93
+ * Language improvements.
94
+ * Layout tweaks.
95
+
96
  #### 1.2
97
 
98
  * Show live backup status in the back up now button when a back up is running.