BackUpWordPress - Version 1.3.1

Version Description

Download this release

Release Info

Developer mattheu
Plugin Icon 128x128 BackUpWordPress
Version 1.3.1
Comparing to
See all releases

Code changes from version 1.3 to 1.3.1

.gitignore ADDED
@@ -0,0 +1 @@
 
1
+ .svn
admin.backups-table.php CHANGED
@@ -5,7 +5,7 @@ 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>
5
  hmbkp_delete_old_backups();
6
 
7
  $backup_archives = hmbkp_get_backups();
8
+ if ( $backup_archives && count( $backup_archives ) ) : ?>
9
 
10
  <table class="widefat" id="hmbkp_manage_backups_table">
11
  <thead>
backup.files.fallback.functions.php DELETED
@@ -1,51 +0,0 @@
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 DELETED
@@ -1,238 +0,0 @@
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 DELETED
@@ -1,225 +0,0 @@
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 DELETED
@@ -1,260 +0,0 @@
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 DELETED
@@ -1,92 +0,0 @@
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 DELETED
@@ -1,603 +0,0 @@
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.functions.php CHANGED
@@ -119,6 +119,9 @@ function hmbkp_get_backups() {
119
 
120
  krsort( $files );
121
 
 
 
 
122
  return $files;
123
  }
124
 
119
 
120
  krsort( $files );
121
 
122
+ if( empty($files) )
123
+ return false;
124
+
125
  return $files;
126
  }
127
 
hmbkp.css DELETED
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,53 +0,0 @@
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 DELETED
Binary file
icon_backupwordpress_16x16_hover.png DELETED
Binary file
icon_backupwordpress_32x32.png DELETED
Binary file
interface.functions.php DELETED
@@ -1,151 +0,0 @@
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.3
9
  Author URI: http://humanmade.co.uk/
10
  */
11
 
@@ -31,11 +31,22 @@ 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' ) )
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.1
9
  Author URI: http://humanmade.co.uk/
10
  */
11
 
31
  define( 'HMBKP_PLUGIN_URL', WP_PLUGIN_URL . '/' . HMBKP_PLUGIN_SLUG );
32
  define( 'HMBKP_REQUIRED_WP_VERSION', '3.1' );
33
 
34
+
35
+ // Don't activate on anything less than PHP5
36
+ if ( version_compare( phpversion(), '5.0', '<' ) ) {
37
+
38
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
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( __( 'BackUpWordPress requires PHP version 5.0.', 'hmbkp' ) );
43
+
44
+ }
45
+
46
  // Don't activate on old versions of WordPress
47
  if ( version_compare( get_bloginfo('version'), HMBKP_REQUIRED_WP_VERSION, '<' ) ) {
48
 
49
  require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
 
50
  deactivate_plugins( ABSPATH . 'wp-content/plugins/' . HMBKP_PLUGIN_SLUG . '/plugin.php' );
51
 
52
  if ( isset( $_GET['action'] ) && ( $_GET['action'] == 'activate' || $_GET['action'] == 'error_scrape' ) )
readme.txt CHANGED
@@ -3,7 +3,7 @@ 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
 
@@ -75,6 +75,10 @@ You can also twitter <a href="http://twitter.com/humanmadeltd">@humanmadeltd</a>
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.
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.1
7
 
8
  Simple automated back ups of your WordPress powered website.
9
 
75
 
76
  == Changelog ==
77
 
78
+ #### 1.3.1
79
+
80
+ * Check for PHP version. Deactivate plugin if running on PHP version 4.
81
+
82
  #### 1.3
83
 
84
  * Re-written back up engine, no longer copies everything to a tmp folder before zipping which should improve speed and reliability.