PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.4
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.4
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
← All changes | includes/admin/class-wpdb-admin.php +1020 -603 6.77.4 View file →
@@ -16,8 +16,10 @@
16 16 */
17 17 class Wpdb_Admin {
18 18
19 19 public $mysqldump_command_path;
20 + public $root;
21 + public $files;
20 22
21 23 /**
22 24 * Construct.
23 25 */
@@ -25,11 +27,10 @@
25 27 add_action( 'admin_init', array( $this, 'wp_db_backup_admin_init' ) );
26 28 add_action( 'admin_init', array( $this, 'admin_scripts_style' ) );
27 29 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
28 30 add_filter( 'cron_schedules', array( $this, 'wp_db_backup_cron_schedules' ) );
29 - add_action( 'wp_db_backup_event', array( $this, 'wp_db_backup_event_process' ) );
31 + add_action( 'wpdbbkp_db_backup_event', array( $this, 'wp_db_backup_event_process' ) );
30 32 add_action( 'init', array( $this, 'wp_db_backup_scheduler_activation' ) );
31 - add_action( 'wp_logout', array( $this, 'wp_db_cookie_expiration' ) ); // Fixed Vulnerability 22-06-2016 for prevent direct download.
32 33 add_action( 'wp_db_backup_completed', array( $this, 'wp_db_backup_completed_local' ), 12 );
33 34 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_style'));
34 35 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_newsletter_script'));
35 36 add_action('wp_ajax_wpdbbkp_send_query_message', array( $this, 'wpdbbkp_send_query_message'));
@@ -34,8 +35,11 @@
34 35 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_newsletter_script'));
35 36 add_action('wp_ajax_wpdbbkp_send_query_message', array( $this, 'wpdbbkp_send_query_message'));
36 37 add_filter( 'plugin_action_links_' . plugin_basename( WP_BACKUP_PLUGIN_FILE ), array( $this, 'add_settings_plugin_action_wp' ), 10, 4 );
37 38 add_action( 'admin_notices', array($this, 'check_ziparchive_avalable_admin_notice' ));
39 + add_action( 'admin_notices', array($this, 'wpdbbkp_cloudbackup_notice' ) );
40 + add_action( 'wp_ajax_wpdbbkp_cloudbackup_dismiss_notice', array($this, 'wpdbbkp_cloudbackup_dismiss_notice' ) );
41 + add_action( 'admin_init', array($this, 'admin_backup_file_download' ));
38 42
39 43 }
40 44
41 45 /**
@@ -76,8 +80,16 @@
76 80 'manage_options',
77 81 'wp-database-backup#tab_db_destination',
78 82 array($this, 'wp_db_backup_settings_page' ));
79 83
84 + add_submenu_page(
85 + 'wp-database-backup',
86 + 'Cloud Backup',
87 + 'Cloud Backup',
88 + 'manage_options',
89 + 'wp-database-backup#tab_db_remotebackups',
90 + array($this, 'wp_db_backup_settings_page' ));
91 +
80 92 add_submenu_page(
81 93 'wp-database-backup',
82 94 'Settings',
83 95 'Settings',
@@ -83,11 +95,17 @@
83 95 'Settings',
84 96 'manage_options',
85 97 'wp-database-backup#tab_db_setting',
86 98 array($this, 'wp_db_backup_settings_page' ));
99 + add_submenu_page(
100 + 'wp-database-backup',
101 + 'Search and Replace',
102 + 'Search and Replace',
103 + 'manage_options',
104 + 'wp-database-backup#searchreplace',
105 + array($this, 'wp_db_backup_settings_page' ));
87 106
88 107
89 -
90 108 add_submenu_page(
91 109 'wp-database-backup',
92 110 'Help & Support',
93 111 'Help & Support',
@@ -94,49 +112,11 @@
94 112 'manage_options',
95 113 'wp-database-backup#tab_db_help',
96 114 array($this, 'wp_db_backup_settings_page' ));
97 115
98 - if(!defined('BKPFORWP_VERSION')){
99 - add_submenu_page(
100 - 'wp-database-backup',
101 - 'Upgrade to Premium',
102 - 'Upgrade to Premium',
103 - 'manage_options',
104 - 'wp-database-backup#tab_db_upgrade',
105 - array($this, 'wp_db_backup_settings_page' ));
106 - }
107 - else{
108 - add_submenu_page(
109 - 'wp-database-backup',
110 - 'Modules',
111 - 'Modules',
112 - 'manage_options',
113 - 'wp-database-backup#tab_db_features',
114 - array($this, 'wp_db_backup_settings_page' ));
115 - add_submenu_page(
116 - 'wp-database-backup',
117 - 'Licence',
118 - 'Licence',
119 - 'manage_options',
120 - 'wp-database-backup#tab_db_licence',
121 - array($this, 'wp_db_backup_settings_page' ));
122 - }
123 -
124 -
125 -
126 116 }
127 117
128 118 /**
129 - * Start Fixed Vulnerability 22-06-2016 for prevent direct download.
130 - */
131 - public function wp_db_cookie_expiration() {
132 - setcookie( 'can_download', 0, time() - 300, COOKIEPATH, COOKIE_DOMAIN );
133 - if ( SITECOOKIEPATH !== COOKIEPATH ) {
134 - setcookie( 'can_download', 0, time() - 300, SITECOOKIEPATH, COOKIE_DOMAIN );
135 - }
136 - }
137 -
138 - /**
139 119 * If Checked then it will remove local backup after uploading to destination.
140 120 *
141 121 * @param array $args - backup details.
142 122 */
@@ -143,9 +123,9 @@
143 123 public function wp_db_backup_completed_local( &$args ) {
144 124 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
145 125 if ( 1 === $wp_db_remove_local_backup ) {
146 126 if ( file_exists( $args[1] ) ) {
147 - unlink( $args[1] );// File path.
127 + wp_delete_file( $args[1] );// File path.
148 128 }
149 129 }
150 130 }
151 131
@@ -164,28 +144,15 @@
164 144
165 145 // Start Fixed Vulnerability 04-08-2016 for data save in options.
166 146 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] ) {
167 147 if ( ! empty( $_POST ) && ! ( isset( $_POST['option_page'] ) && 'wp_db_backup_options' === $_POST['option_page'] ) ) {
168 - if ( false === isset( $_REQUEST['_wpnonce'] ) || false === wp_verify_nonce( $_REQUEST['_wpnonce'] , 'wp-database-backup' ) ) {
148 + if ( false === isset( $_REQUEST['_wpnonce'] ) || false === wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ) , 'wp-database-backup' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- using as nonce
169 149 wp_die( esc_html__('WPDB :: Invalid Access', 'wpdbbkp' ) );
170 150 }
171 151 }
172 -
173 - // End Fixed Vulnerability 04-08-2016 for data save in options.
174 - if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && current_user_can( 'manage_options' ) ) {
175 - setcookie( 'can_download', 1, 0, COOKIEPATH, COOKIE_DOMAIN );
176 - if ( SITECOOKIEPATH !== COOKIEPATH ) {
177 - setcookie( 'can_download', 1, 0, SITECOOKIEPATH, COOKIE_DOMAIN );
178 - }
179 - } else {
180 - setcookie( 'can_download', 0, time() - 300, COOKIEPATH, COOKIE_DOMAIN );
181 - if ( SITECOOKIEPATH !== COOKIEPATH ) {
182 - setcookie( 'can_download', 0, time() - 300, SITECOOKIEPATH, COOKIE_DOMAIN );
183 - }
184 - }
185 152 // End Fixed Vulnerability 22-06-2016 for prevent direct download.
186 153 if ( is_admin() && current_user_can( 'manage_options' ) ) {
187 - if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , 'wp-database-backup' ) ) {
154 + if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ) , 'wp-database-backup' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- using as nonce
188 155 if ( isset( $_POST['wpsetting_search'] ) ) {
189 156 if ( isset( $_POST['wp_db_backup_search_text'] ) ) {
190 157 update_option( 'wp_db_backup_search_text', sanitize_text_field( wp_unslash( $_POST['wp_db_backup_search_text'] ) ), false );
191 158 }
@@ -203,13 +170,23 @@
203 170 update_option( 'wp_db_log', 1 , false);
204 171 } else {
205 172 update_option( 'wp_db_log', 0 , false);
206 173 }
174 + if ( isset( $_POST['wp_db_remove_on_uninstall'] ) ) {
175 + update_option( 'wp_db_remove_on_uninstall', 1 , false);
176 + } else {
177 + update_option( 'wp_db_remove_on_uninstall', 0 , false);
178 + }
207 179 if ( isset( $_POST['wp_db_remove_local_backup'] ) ) {
208 180 update_option( 'wp_db_remove_local_backup', 1 , false);
209 181 } else {
210 182 update_option( 'wp_db_remove_local_backup', 0 , false);
211 183 }
184 + if ( isset( $_POST['wp_db_save_settings_in_backup'] ) ) {
185 + update_option( 'wp_db_save_settings_in_backup', 1 , false);
186 + } else {
187 + update_option( 'wp_db_save_settings_in_backup', 0 , false);
188 + }
212 189 if ( isset( $_POST['wp_db_backup_enable_auto_upgrade'] ) ) {
213 190 update_option( 'wp_db_backup_enable_auto_upgrade', 1 , false);
214 191 } else {
215 192 update_option( 'wp_db_backup_enable_auto_upgrade', 0 , false);
@@ -214,18 +191,8 @@
214 191 } else {
215 192 update_option( 'wp_db_backup_enable_auto_upgrade', 0 , false);
216 193 }
217 194
218 - if ( isset( $_POST['wp_db_backup_enable_htaccess'] ) ) {
219 - update_option( 'wp_db_backup_enable_htaccess', 1 , false);
220 - } else {
221 - update_option( 'wp_db_backup_enable_htaccess', 0 , false);
222 - $path_info = wp_upload_dir();
223 - if ( file_exists( $path_info['basedir'] . '/db-backup/.htaccess' ) ) {
224 - unlink( $path_info['basedir'] . '/db-backup/.htaccess' );
225 - }
226 - }
227 -
228 195 if ( isset( $_POST['wp_db_exclude_table'] ) ) {
229 196 update_option( 'wp_db_exclude_table', $this->recursive_sanitize_text_field( wp_unslash( $_POST['wp_db_exclude_table'] ) ) , false); // phpcs:ignore
230 197 } else {
231 198 update_option( 'wp_db_exclude_table', '', false );
@@ -254,12 +221,71 @@
254 221 }
255 222 }
256 223
257 224 if ( isset( $_POST['wp_db_backup_options'] ) ) {
258 - update_option( 'wp_db_backup_options', $_POST['wp_db_backup_options'], false);
225 + $option_to_save = [];
226 + if ( isset( $_POST['wp_db_backup_options']['enable_autobackups'] ) ) {
227 + $option_to_save['enable_autobackups'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['enable_autobackups'] ) );
228 + }
229 + if ( isset( $_POST['wp_db_backup_options']['autobackup_type'] ) ) {
230 + $option_to_save['autobackup_type'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_type'] ) );
231 + }
232 + if ( isset( $_POST['wp_db_backup_options']['autobackup_frequency'] ) ) {
233 + $option_to_save['autobackup_frequency'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_frequency'] ) );
234 + }
235 + if ( isset( $_POST['wp_db_backup_options']['autobackup_full_days'] ) ) {
236 + $option_to_save['autobackup_full_days'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_days'] ) );
237 + }
238 + if ( isset( $_POST['wp_db_backup_options']['autobackup_full_time'] ) ) {
239 + $option_to_save['autobackup_full_time'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_time'] ) );
240 + }
241 + if ( isset( $_POST['wp_db_backup_options']['autobackup_full_date'] ) ) {
242 + $option_to_save['autobackup_full_date'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_date'] ) );
243 + }
244 + if(!empty($option_to_save)) {
245 + if(update_option( 'wp_db_backup_options', $option_to_save, false)){
246 + wp_clear_scheduled_hook( 'wpdbbkp_db_backup_event' );
247 + wp_clear_scheduled_hook( 'wpdbkup_event_fullbackup' );
248 + }
249 + }
250 +
259 251 }
260 252
261 - do_action('wpdbbkp_save_pro_options');
253 +
254 + if ( isset( $_POST['featureSubmit'] ) && 'Save Settings' === $_POST['featureSubmit'] ) {
255 + if ( isset( $_POST['enable_anonymization'] ) ) {
256 + update_option( 'bkpforwp_enable_anonymization', 1 );
257 + } else {
258 + update_option( 'bkpforwp_enable_anonymization', 0 );
259 + }
260 +
261 + if ( isset( $_POST['enable_backup_encryption'] ) ) {
262 + update_option( 'bkpforwp_enable_backup_encryption', 1 );
263 + } else {
264 + update_option( 'bkpforwp_enable_backup_encryption', 0 );
265 + }
266 + if ( isset( $_POST['enable_exact_backup_time'] ) ) {
267 + update_option( 'bkpforwp_enable_exact_backup_time', 1 );
268 + } else {
269 + update_option( 'bkpforwp_enable_exact_backup_time', 0 );
270 + }
271 +
272 + if ( isset( $_POST['anonymization_type'] ) ) {
273 + update_option( 'bkpforwp_anonymization_type', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['anonymization_type'] ) ) ) );
274 +
275 + }
276 +
277 + if ( isset( $_POST['anonymization_pass'] )) {
278 + update_option( 'bkpforwp_anonymization_pass', wp_db_filter_data( sanitize_text_field( wp_unslash($_POST['anonymization_pass'] ) ) ) );
279 +
280 + }
281 +
282 + if ( isset( $_POST['backup_encryption_pass'] )) {
283 + update_option( 'bkpforwp_backup_encryption_pass', wp_db_filter_data( sanitize_text_field( wp_unslash($_POST['backup_encryption_pass'] ) ) ) );
284 +
285 + }
286 + }
287 +
262 288 }
263 289 $wp_db_backup_destination_email = get_option( 'wp_db_backup_destination_Email' , false);
264 290
265 291 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && isset( $_GET['action'] ) && 'unlink' === $_GET['action'] ) {
@@ -272,9 +298,9 @@
272 298 $file = readdir( $dir_handle );
273 299 while ( $file ) {
274 300 // If $file is NOT a directory remove it.
275 301 if ( ! is_dir( $file ) ) {
276 - unlink( $dir . $file );
302 + wp_delete_file( $dir . $file );
277 303 }
278 304 }
279 305 // Close the directory.
280 306 closedir( $dir_handle );
@@ -293,14 +319,17 @@
293 319 $index = (int) $_GET['index'];
294 320 $options = get_option( 'wp_db_backup_backups' );
295 321 $newoptions = array();
296 322 $count = 0;
297 - foreach ( $options as $option ) {
298 - if ( $count !== $index ) {
299 - $newoptions[] = $option;
323 + if(!empty($options) && is_array($options)){
324 + foreach ( $options as $option ) {
325 + if ( $count !== $index ) {
326 + $newoptions[] = $option;
327 + }
328 + $count++;
300 329 }
301 - $count++;
302 330 }
331 +
303 332 $upload_dir = wp_upload_dir();
304 333 $actual_working_directory = getcwd();
305 334 $file_directory = $upload_dir['basedir'].'/db-backup/';
306 335 /*
@@ -306,16 +335,20 @@
306 335 /*
307 336 Fix for when you try to delete a file thats in a folder
308 337 higher in the hierarchy to your working directory */
309 338 chdir($file_directory);
310 - if ( file_exists( $options[ $index ]['filename'] ) ) {
311 - unlink( $options[ $index ]['filename'] );
339 + if ( isset($options[ $index ]['filename']) && file_exists( $options[ $index ]['filename'] ) ) {
340 + wp_delete_file( $options[ $index ]['filename'] );
312 341 }
313 - $file_sql = explode( '.', $options[ $index ]['filename'] );
314 - if ( file_exists( $file_sql[0] . '.sql' ) ) {
315 - unlink( $file_sql[0] . '.sql' );
342 + if(isset($options[ $index ]['filename'])){
343 + $file_sql = explode( '.', $options[ $index ]['filename'] );
344 + if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) {
345 + wp_delete_file( $file_sql[0] . '.sql' );
346 + }
316 347 }
348 +
317 349 chdir($actual_working_directory);
350 + $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
318 351 update_option( 'wp_db_backup_backups', $newoptions , false);
319 352 $nonce = wp_create_nonce( 'wp-database-backup' );
320 353 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=delete&_wpnonce=' . $nonce );
321 354 exit;
@@ -326,8 +359,9 @@
326 359
327 360 $upload_dir = wp_upload_dir();
328 361 $actual_working_directory = getcwd();
329 362 $file_directory = $upload_dir['basedir'];
363 + global $wpdb;
330 364 /*
331 365 Fix for when you try to delete a file thats in a folder
332 366 higher in the hierarchy to your working directory
333 367 */
@@ -334,16 +368,20 @@
334 368 chdir($file_directory);
335 369 $files = glob($file_directory.'/db-backup'.'/*');
336 370
337 371 // Deleting all the files in the list
338 - foreach($files as $file) {
339 - if(is_file($file)){
340 - unlink($file);
341 - }
342 - }
372 + if(!empty($files)){
373 + foreach($files as $file) {
374 + if(is_file($file)){
375 + wp_delete_file($file);
376 + }
377 + }
378 + }
343 379 chdir($actual_working_directory);
344 380 update_option( 'wp_db_backup_backups', array() , false);
345 381 $nonce = wp_create_nonce( 'wp-database-backup' );
382 + $table_name = $wpdb->prefix . 'wpdbbkp_processed_files';
383 + $wpdb->query( "TRUNCATE TABLE $table_name" ); // phpcs:ignore
346 384 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=deleteall&_wpnonce=' . $nonce );
347 385 exit;
348 386
349 387
@@ -352,10 +390,15 @@
352 390 $options = get_option( 'wp_db_backup_backups' );
353 391 $newoptions = array();
354 392 $backup_check_list = array( '.htaccess', 'index.php' );
355 393 $delete_message = 'WPDB : Deleted Files:';
356 - foreach ( $options as $option ) {
357 - $backup_check_list[] = $option['filename'];
394 + if(!empty($options) && is_array($options)){
395 + foreach ( $options as $option ) {
396 + if(!is_array($option)){
397 + continue;
398 + }
399 + $backup_check_list[] = $option['filename'];
400 + }
358 401 }
359 402 $path_info = wp_upload_dir();
360 403 $wp_db_backup_path = $path_info['basedir'] . '/db-backup';
361 404
@@ -365,9 +408,9 @@
365 408 if ( $dh ) {
366 409 while ( false !== ($file = readdir( $dh )) ) {
367 410 if ( ! ( in_array( $file, $backup_check_list, true ) ) ) {
368 411 if ( file_exists( $wp_db_backup_path . '/' . $file ) ) {
369 - unlink( $wp_db_backup_path . '/' . $file );
412 + wp_delete_file( $wp_db_backup_path . '/' . $file );
370 413 }
371 414 $delete_message .= ' ' . $file;
372 415 }
373 416 }
@@ -377,18 +420,20 @@
377 420 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=clear_temp_db_backup_file&_wpnonce=' . $nonce );
378 421 exit;
379 422 break;
380 423 case 'restorebackup':
381 - $index = (int) $_GET['index'];
424 + $index = isset($_GET['index'])?(int) $_GET['index']:0;
382 425 $options = get_option( 'wp_db_backup_backups' );
383 426 $restore_limit = get_option( 'wp_db_restore_limit');
384 427 $newoptions = array();
385 428 $count = 0;
386 - foreach ( $options as $option ) {
387 - if ( $count !== $index ) {
388 - $newoptions[] = $option;
429 + if(!empty($options) && is_array($options)){
430 + foreach ( $options as $option ) {
431 + if ( $count !== $index ) {
432 + $newoptions[] = $option;
433 + }
434 + $count++;
389 435 }
390 - $count++;
391 436 }
392 437 if ( isset( $options[ $index ]['restore_limit'] ) && $options[ $index ]['restore_limit']==1) {
393 438 include_once ABSPATH . 'wp-admin/includes/plugin.php';
394 439 if ( !is_plugin_active( 'wp-database-backup-pro/wp-database-backup-pro.php' ) ) {
@@ -401,11 +446,14 @@
401 446
402 447 if ( isset( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
403 448 $database_file = ( $options[ $index ]['sqlfile'] );
404 449 } else {
405 - $database_file = ( $options[ $index ]['dir'] );
406 - $file_sql = explode( '.', $options[ $index ]['dir'] );
407 - $database_file = ( $file_sql[0] . '.sql' );
450 + $database_file = isset($options[ $index ]['dir']) ? $options[ $index ]['dir'] : '';
451 + $file_sql = explode( '.', $database_file );
452 + if(isset($file_sql[0])){
453 + $database_file = ( $file_sql[0] . '.sql' );
454 + }
455 +
408 456 }
409 457 $database_name = $this->wp_backup_get_config_db_name();
410 458 $database_user = $this->wp_backup_get_config_data( 'DB_USER' );
411 459 $datadase_password = $this->wp_backup_get_config_data( 'DB_PASSWORD' );
@@ -431,71 +479,85 @@
431 479 }
432 480 }
433 481
434 482 // End for extract zip file V.3.3.0.
435 - set_time_limit( 0 );
483 + set_time_limit( 0 ); // phpcs:ignore -- needed for long running process
436 484 ignore_user_abort(true);
437 - if ( '' !== ( trim( (string) $database_name ) ) && '' !== ( trim( (string) $database_user ) ) && '' !== ( trim( (string) $database_host ) ) ) {
438 - $conn = mysqli_connect( (string) $database_host, (string) $database_user, (string) $datadase_password ); // phpcs:ignore
439 - if ( $conn ) {
440 - // Start Select the database.
441 - if ( ! mysqli_select_db( $conn, (string) $database_name) ) { // phpcs:ignore
442 - $sql = 'CREATE DATABASE IF NOT EXISTS `' . (string) $database_name . '`';
443 - mysqli_query($conn, $sql); // phpcs:ignore
444 - mysqli_select_db($conn, (string) $database_name ); // phpcs:ignore
485 + if ('' !== trim($database_name) && '' !== trim($database_user) && '' !== trim($database_host)) {
486 + $wpdb->db_connect();
487 + $wpdb->select($database_name);
488 +
489 + //phpcs:ignore -- Check if database exists
490 + $db_exists = $wpdb->get_var($wpdb->prepare(
491 + "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = %s",
492 + $database_name
493 + ));
494 +
495 + if (!$db_exists) {
496 + //phpcs:ignore -- Create DB if it doesn't exist
497 + $wpdb->query($wpdb->prepare("CREATE DATABASE IF NOT EXISTS `%s`", $database_name));
498 + $wpdb->select($database_name);
499 + }
500 + //phpcs:ignore -- Show tables from database
501 + $tables = $wpdb->get_col($wpdb->prepare("SHOW TABLES FROM `%s`", $database_name));
502 +
503 +
504 + if (!empty($tables)) {
505 + foreach ($tables as $table_name) {
506 + //phpcs:ignore -- delete tables before restore
507 + $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS `%s`", $table_name));
445 508 }
446 - /* END: Select the Database */
447 -
448 - /* BEGIN: Remove All Tables from the Database */
449 - $found_tables = null;
450 - $result = mysqli_query( $conn, 'SHOW TABLES FROM `' . (string) $database_name . '`' ); // phpcs:ignore
451 -
452 - if ( $result ) {
453 - while ($row = mysqli_fetch_row($result)) {
454 - $found_tables[] = $row[0];
509 + }
510 +
511 + // Restore database content
512 + if (file_exists($database_file)) {
513 + if ( ! function_exists( 'WP_Filesystem' ) ) {
514 + require_once ABSPATH . '/wp-admin/includes/file.php';
455 515 }
516 +
517 + WP_Filesystem();
518 + if ( $wp_filesystem ) {
519 + $sql_file = $wp_filesystem->get_contents( $database_file );
520 + if ( $sql_file !== false ) {
521 + $sql_queries = explode(";\n", $sql_file);
522 + //phpcs:ignore -- Set sql_mode to empty
523 + $wpdb->query("SET sql_mode = ''");
524 +
525 + foreach ($sql_queries as $query) {
526 + $query = apply_filters('wpdbbkp_sql_query_restore', $query);
527 + if (!empty(trim($query))) {
456 528
457 - if ( count( $found_tables ) > 0 ) {
458 - foreach ( $found_tables as $table_name ) {
459 - mysqli_query( $conn, "DROP TABLE " . (string) $database_name . ".".$table_name ); // phpcs:ignore
460 - }
461 - }
462 - }
463 -
464 - /* END: Remove All Tables from the Database */
465 -
466 - /* BEGIN: Restore Database Content */
467 - if ( isset( $database_file ) ) {
468 - if ( file_exists( $database_file ) ) {
469 - $sql_file = file_get_contents( $database_file, true );
470 - if($sql_file){
471 - $sql_queries = explode( ";\n", $sql_file );
472 - $sql_queries_count = count( $sql_queries );
473 -
474 - mysqli_query($conn, "SET sql_mode = ''");
475 -
476 - for ( $i = 0; $i < $sql_queries_count; $i++ ) {
477 - $sql_query_=apply_filters( 'wpdbbkp_sql_query_restore', $sql_queries[ $i ] );
478 - mysqli_query($conn, $sql_query_ ); // phpcs:ignore
479 - }
480 - }
481 -
482 - }
483 - }
529 + /* Since $query is a dynqmic sql query from the backup file, we can't use $wpdb->prepare
530 + * as we don't know the number / types of arguments in the query. So, we are using $wpdb->query
531 + * directly to execute the query.*/
532 + //phpcs:ignore
533 + $wpdb->query($query);
534 + }
535 + }
536 +
537 + }
538 + }
484 539 }
485 540 }
486 541
487 542 if ( isset( $options[ $index ]['sqlfile'] ) && file_exists( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
488 543 if ( file_exists( $options[ $index ]['sqlfile'] ) ) {
489 - unlink( $options[ $index ]['sqlfile'] );
544 + wp_delete_file( $options[ $index ]['sqlfile'] );
490 545 }
491 546 } else {
492 - $database_file = ( $options[ $index ]['dir'] );
493 - $file_sql = explode( '.', $options[ $index ]['dir'] );
494 - $database_file = ( $file_sql[0] . '.sql' );
495 - if ( file_exists( $database_file ) ) {
496 - unlink( $database_file );
547 + $database_file = isset($options[ $index ]['dir'] )?$options[ $index ]['dir']:'';
548 + if(!empty($database_file)){
549 + $file_sql = explode( '.', $database_file );
550 + if(isset($file_sql[0])){
551 + $database_file = ( $file_sql[0] . '.sql' );
552 + if ( file_exists( $database_file ) ) {
553 + wp_delete_file( $database_file );
554 + }
555 +
556 + }
557 +
497 558 }
559 +
498 560 }
499 561 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
500 562 exit;
501 563 break;
@@ -501,18 +563,24 @@
501 563 break;
502 564
503 565 case 'wpdbbkrestorefullbackup':
504 566 $index = (int) $_GET['index'];
505 - require_once( 'class-restore.php' );
506 - $restore = new Wpbp_Restore();
567 + require_once( 'class-wpdbbkp-restore.php' );
568 + $restore = new Wpdbbkp_Restore();
507 569 $restore->start($index);
508 570 if (get_option('wp_db_log') == 1) {
509 571 $options = get_option('wp_db_backup_backups');
510 572 $path_info = wp_upload_dir();
511 - $logFileName = explode(".", $options[$index]['filename']);
512 - $logfile = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $logFileName[0] . '.txt';
513 - $message = "\n\n Restore Backup at " . date("Y-m-d h:i:sa");
514 - $this->write_log($logfile, $message);
573 + if(isset($options[$index]['filename'])){
574 + $logFileName = explode(".", $options[$index]['filename']);
575 + if(isset($logFileName[0])){
576 + $logfile = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $logFileName[0] . '.txt';
577 + $message = "\n\n Restore Backup at " . gmdate("Y-m-d h:i:sa");
578 + $this->write_log($logfile, $message);
579 + }
580 +
581 + }
582 +
515 583 }
516 584 $nonce = wp_create_nonce( 'wp-database-backup' );
517 585 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
518 586 exit;
@@ -543,12 +611,19 @@
543 611 /**
544 612 * Setting page.
545 613 */
546 614 public function wp_db_backup_settings_page() {
547 -
615 + global $wp_filesystem;
616 + if(!function_exists('WP_Filesystem')){
617 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
618 + }
619 + WP_Filesystem();
620 +
548 621 $options = get_option( 'wp_db_backup_backups' );
622 + $options = wpdbbkp_filter_unique_filenames( $options );
549 623 $settings = get_option( 'wp_db_backup_options' );
550 - $wp_db_log = get_option( 'wp_db_log' ); ?>
624 + $wp_db_log = get_option( 'wp_db_log' );
625 + $incremental_backup = get_option( 'wp_db_incremental_backup' ,false); ?>
551 626 <div class="bootstrap-wrapper">
552 627 <?php
553 628 $wp_db_local_backup_path = get_option( 'wp_db_local_backup_path' );
554 629 if ( false === empty( $wp_db_local_backup_path ) && false === file_exists( $wp_db_local_backup_path ) ) {
@@ -554,10 +629,10 @@
554 629 if ( false === empty( $wp_db_local_backup_path ) && false === file_exists( $wp_db_local_backup_path ) ) {
555 630 echo '<div class="alert alert-warning alert-dismissible fade in" role="alert">
556 631 <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
557 632 <a href="#db_destination" data-toggle="tab">';
558 - esc_attr_e( 'Invalid Local Backup Path : ', 'wp-database-backup' );
559 - echo esc_attr( $wp_db_local_backup_path );
633 + esc_html_e( 'Invalid Local Backup Path : ', 'wpdbbkp' );
634 + echo esc_html( $wp_db_local_backup_path );
560 635 echo '</a></div>';
561 636 }
562 637
563 638 $upload_dir = wp_upload_dir();
@@ -564,9 +639,9 @@
564 639 $dir = $upload_dir['basedir'] . '/db-backup';
565 640 if ( ! is_dir( $dir ) ) {
566 641 $dir = $upload_dir['basedir'];
567 642 }
568 - if ( is_dir( $dir ) && ! is_writable( $dir ) ) {
643 + if ( is_dir( $dir ) && !$wp_filesystem->is_writable( $dir )) {
569 644 ?>
570 645 <div class="row">
571 646 <div class="col-xs-12 col-sm-12 col-md-12">
572 647 <div class="alert alert-danger alert-dismissible fade in" role="alert">
@@ -571,11 +646,11 @@
571 646 <div class="col-xs-12 col-sm-12 col-md-12">
572 647 <div class="alert alert-danger alert-dismissible fade in" role="alert">
573 648 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
574 649 <span aria-hidden="true">×</span></button>
575 - <h4>WP Database Backup</h4>
576 - <p>Error: Permission denied, make sure you have write permission for <?php echo esc_attr( $dir ); ?>
577 - folder</p>
650 + <h4><?php esc_html_e( 'WP Database Backup', 'wpdbbkp' ); ?></h4>
651 + <p><?php esc_html_e( 'Error: Permission denied, make sure you have write permission for', 'wpdbbkp' ); ?> <?php echo esc_attr( $dir ); ?>
652 + <?php esc_html_e( 'folder', 'wpdbbkp' ); ?></p>
578 653 </div>
579 654 </button>
580 655 </div>
581 656 </div>
@@ -581,8 +656,10 @@
581 656 </div>
582 657 <?php
583 658 }
584 659 ?>
660 +
661 +
585 662
586 663 <div id="wpdbbkpModal" class="modal">
587 664 <div class="wpdbbkpmodal-content">
588 665 <div class="wpdbbkp-modal-header">
@@ -605,17 +682,18 @@
605 682 </div>
606 683 <div class="panel-body">
607 684 <ul class="nav nav-tabs wbdbbkp_has_nav">
608 685 <li class="active"><a href="#db_home" data-toggle="tab"><?php echo esc_html__('Backups', 'wpdbbkp') ?></a></li>
686 + <li><a href="#db_remotebackups" data-toggle="tab"><?php echo esc_html__('Cloud Backup', 'wpdbbkp') ?></a></li>
609 687 <li><a href="#db_schedul" data-toggle="tab"><?php echo esc_html__('Auto Scheduler', 'wpdbbkp') ?></a></li>
610 688 <li><a href="#db_destination" data-toggle="tab"><?php echo esc_html__('Save Backups to', 'wpdbbkp') ?></a></li>
611 689 <li><a href="#db_setting" data-toggle="tab"><?php echo esc_html__('Settings', 'wpdbbkp') ?></a></li>
612 - <li><a href="#searchreplace" data-toggle="tab"><?php echo esc_html__('Search and Replace', 'wpdbbkp') ?></a></li>
613 - <li style="display:none"><a href="#db_upgrade" data-toggle="tab"><?php echo esc_html__('Upgrade', 'wpdbbkp') ?></a></li>
614 - <?php do_action( 'wpdbbkp_pro_tab_links' ); ?>
690 + <li><a href="#searchreplace" style="display:none" data-toggle="tab"><?php echo esc_html__('Search and Replace', 'wpdbbkp') ?></a></li>
691 + <li><a href="#db_features" data-toggle="tab"><?php echo esc_html__('Modules', 'wpdbbkp') ?></a></li>
692 + <li title="System Info"><a href="#db_info" data-toggle="tab"><?php echo esc_html__('Usage', 'wpdbbkp') ?></a></li>
615 693 <li><a href="#db_help" data-toggle="tab"><?php echo esc_html__('Help &amp; Support', 'wpdbbkp') ?></a></li>
616 - <li id="db_info_link" title="System Info"><a href="#db_info" data-toggle="tab"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a></li>
617 694
695 +
618 696 </ul>
619 697
620 698 <?php
621 699 echo '<div class="tab-content">';
@@ -634,9 +712,9 @@
634 712 }
635 713 include_once 'admin-header-notification.php'; ?>
636 714
637 715 <?php
638 - if ( $options ) {
716 + if ( !empty($options) ) {
639 717
640 718 echo ' <script>
641 719 var $j = jQuery.noConflict();
642 720 $j(document).ready(function () {
@@ -644,14 +722,8 @@
644 722 var table = $j("#wpdbbkp_table").DataTable({
645 723 order: [[0, "desc"]],
646 724 });
647 725 $j(".popoverid").popover();
648 - $j("#create_backup").click(function() {
649 - $j(".wpdbbkp_notification").hide();
650 - $j("#backup_process").show();
651 - $j("#create_backup").attr("disabled", true);
652 -
653 - });
654 726 });
655 727
656 728 function excludetableall(){
657 729 var checkboxes = document.getElementsByClassName("wp_db_exclude_table");
@@ -662,9 +734,8 @@
662 734 $j(".wp_db_exclude_table").each(function() {
663 735 this.checked = checked;
664 736 });
665 737 }
666 -
667 738 </script>';
668 739 echo ' <div class="table-responsive">
669 740 <div id="wpdbbkp_dataTables" class="dataTables_wrapper form-inline" role="grid">
670 741
@@ -694,72 +765,90 @@
694 765 'SFTP' => 'glyphicon glyphicon-tasks',
695 766 'S3' => 'glyphicon glyphicon-cloud-upload',
696 767 'Drive' => 'glyphicon glyphicon-hdd',
697 768 'DropBox' => 'glyphicon glyphicon-inbox',
769 + 'Backblaze' => 'glyphicon glyphicon-cloud-upload',
770 + 'CloudDrive' => 'glyphicon glyphicon-cloud-upload'
698 771 );
699 - foreach ( $options as $option ) {
700 - $str_class = ( 0 === (int) $option['size'] ) ? 'text-danger' : 'wpdb_download';
701 - echo '<tr class="' . ( ( 0 === ( $count % 2 ) ) ? esc_attr( $str_class ) . ' alternate' : esc_attr( $str_class ) ) . '">';
702 - echo '<td style="text-align: center;">' . esc_attr( $count ) . '</td>';
703 - $curr_date = new DateTime(date( 'Y-m-d H:i:s', $option['date'] ));
704 - $curr_date->setTimezone(new DateTimeZone(wp_timezone_string()));
705 - echo '<td><span style="display:none">' . esc_attr( $curr_date->format('Y-m-d H:i:s') ) . '</span><span title="'.esc_attr( $curr_date->format('jS, F Y h:i:s A') ) .'">' .$this->wpdbbkp_get_timeago($option['date']).'</span>';
706 - echo '</td>';
707 - if($wp_db_log==1){
708 - echo '<td class="wpdb_log" align="center">';
709 - if (!empty($option['log'])) {
710 - if(isset($option['type']) && ($option['type'] == 'complete' || $option['type'] == 'database')){
711 - echo '<a href="' . $option['log'] . '" target="_blank" class="label label-warning" title="There might be partial backup. Please check Log File for verify backup.">';
712 - echo '<span class="glyphicon glyphicon-list-alt"></span>';
713 - echo '</a>';
714 - }else{
715 - echo '<a class="popoverid btn" role="button" data-toggle="popover" data-html="true" title="There might be partial backup. Please check Log file to verify backup." data-content="' . wp_kses_post( $option['log'] ) . '"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></a>';
772 + if(!empty($options) && is_array($options)){
773 + foreach ( $options as $option ) {
774 + if (!is_array($option)) {
775 + continue;
716 776 }
717 - }
718 - echo '</td>';
719 - }
720 - echo '<td>';
721 - if ( ! empty( $option['destination'] ) ) {
722 - $destination = ( explode( ',', $option['destination'] ) );
723 - foreach ( $destination as $dest ) {
724 - $key = trim( $dest );
725 - if ( ! empty( $dest ) && array_key_exists( $key, $destination_icon ) ) {
726 - echo '<span class="' . esc_attr( $destination_icon[ $key ] ) . '" title="' . esc_attr( $dest ) . '"></span> ';
777 +
778 + if (!empty($option['destination'])) {
779 + if (strpos($option['destination'], 'CloudDrive') !== false) {
780 + continue;
727 781 }
728 782 }
729 - }
730 - echo '</td>';
731 - if(isset($option['type']) && !empty($option['type'])){
732 - if($option['type'] == 'complete'){
733 - echo '<td>'.esc_html__('Full Backup', 'wpdbbkp').'</td>';
783 + $size = isset( $option['size'])? $option['size'] : 0;
784 + $str_class = ( 0 === (int) $size ) ? 'text-danger' : 'wpdb_download';
785 + echo '<tr class="' . ( ( 0 === ( $count % 2 ) ) ? esc_attr( $str_class ) . ' alternate' : esc_attr( $str_class ) ) . '">';
786 + echo '<td style="text-align: center;">' . esc_attr( $count ) . '</td>';
787 + $curr_date = new DateTime(gmdate( 'Y-m-d H:i:s', $option['date'] ));
788 + $curr_date->setTimezone(new DateTimeZone(wp_timezone_string()));
789 + echo '<td><span style="display:none">' . esc_attr( $curr_date->format('Y-m-d H:i:s') ) . '</span><span title="'.esc_attr( $curr_date->format('jS, F Y h:i:s A') ) .'">' .esc_html($this->wpdbbkp_get_timeago($option['date'])).'</span>';
790 + echo '</td>';
791 + if($wp_db_log==1){
792 + echo '<td class="wpdb_log" align="center">';
793 + if (!empty($option['log'])) {
794 + if(isset($option['type']) && ($option['type'] == 'complete' || $option['type'] == 'database')){
795 + echo '<a href="' . esc_url($option['log']) . '" target="_blank" class="label label-warning" title="There might be partial backup. Please check Log File for verify backup.">';
796 + echo '<span class="glyphicon glyphicon-list-alt"></span>';
797 + echo '</a>';
798 + }else{
799 + echo '<a class="popoverid btn" role="button" data-toggle="popover" data-html="true" title="There might be partial backup. Please check Log file to verify backup." data-content="' . wp_kses_post( $option['log'] ) . '"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></a>';
800 + }
734 801 }
735 - if($option['type'] == 'database'){
736 - echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
802 + echo '</td>';
737 803 }
738 - }else{
739 - echo '<td>Database</td>';
740 - }
741 - echo '<td>';
742 - echo '<a class="btn btn-default" href="' . esc_url( $option['url'] ) . '" style="color: #21759B;border-color:#337ab7;">';
743 - echo '<span class="glyphicon glyphicon-download-alt"></span> Download</a></td>';
744 - echo '<td>' . esc_attr( $this->wp_db_backup_format_bytes( $option['size'] ) ) . '</td>';
745 - $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removebackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
746 - echo '<td><a title="Remove Database Backup" onclick="return confirm(\'Are you sure you want to delete database backup?\')" href="' . $remove_backup_href . '" class="btn btn-default"><span style="color:red" class="glyphicon glyphicon-trash"></span> Remove <a/> ';
747 - if ( isset( $option['search_replace'] ) && 1 === (int) $option['search_replace'] ) {
748 - echo '<span style="margin-left:15px" title="' . esc_html( $option['log'] ) . '" class="glyphicon glyphicon-search"></span>';
749 - } else {
750 - $restore_url_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=restorebackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
804 + echo '<td>';
805 + if ( ! empty( $option['destination'] ) ) {
806 + $destination = ( explode( ',', $option['destination'] ) );
807 + if(!empty($destination) && is_array($destination)){
808 + foreach ( $destination as $dest ) {
809 + $key = trim( $dest );
810 + if ( ! empty( $dest ) && array_key_exists( $key, $destination_icon ) ) {
811 + echo '<span class="' . esc_attr( $destination_icon[ $key ] ) . '" title="' . esc_attr( $dest ) . '"></span> ';
812 + }
813 + }
814 + }
815 +
816 + }
817 + echo '</td>';
751 818 if(isset($option['type']) && !empty($option['type'])){
752 819 if($option['type'] == 'complete'){
753 - $restore_url_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=wpdbbkrestorefullbackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
820 + echo '<td>'.esc_html__('Full Backup', 'wpdbbkp').'</td>';
754 821 }
755 -
822 + if($option['type'] == 'database'){
823 + echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
824 + }
825 + }else{
826 + echo '<td>Database</td>';
756 827 }
757 - echo '<a title="Restore Database Backup" onclick="wpdbbkp_restore_backup(this);" href="javascript:void(0);" data-msg="Are you sure you want to restore database backup? It will overwrite all data /files with the respective backup and all recent changes would be lost. Are you sure you want to continue?" data-title="Restore Backup" data-href="'.$restore_url_href.'" class="btn btn-default"><span class="glyphicon glyphicon-refresh" style="color:blue"></span> Restore <a/>';
828 + echo '<td>';
829 + echo '<a class="btn btn-default" href="' . esc_url( admin_url('?wpdbbkp_download='.basename($option['url'])) ) . '" style="color: #21759B;border-color:#337ab7;">';
830 + echo '<span class="glyphicon glyphicon-download-alt"></span> Download</a></td>';
831 + echo '<td>' . esc_attr( $this->wp_db_backup_format_bytes( $option['size'] ) ) . '</td>';
832 + $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removebackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
833 + echo '<td><a title="Remove Database Backup" onclick="return confirm(\'Are you sure you want to delete database backup?\')" href="' . esc_url($remove_backup_href) . '" class="btn btn-default"><span style="color:red" class="glyphicon glyphicon-trash"></span> Remove <a/> ';
834 + if ( isset( $option['search_replace'] ) && 1 === (int) $option['search_replace'] ) {
835 + echo '<span style="margin-left:15px" title="' . esc_html( $option['log'] ) . '" class="glyphicon glyphicon-search"></span>';
836 + } else {
837 + $restore_url_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=restorebackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
838 + if(isset($option['type']) && !empty($option['type'])){
839 + if($option['type'] == 'complete'){
840 + $restore_url_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=wpdbbkrestorefullbackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
841 + }
842 +
843 + }
844 + echo '<a title="Restore Database Backup" onclick="wpdbbkp_restore_backup(this);" href="javascript:void(0);" data-msg="Are you sure you want to restore database backup? It will overwrite all data /files with the respective backup and all recent changes would be lost. Are you sure you want to continue?" data-title="Restore Backup" data-href="'.esc_url($restore_url_href).'" class="btn btn-default"><span class="glyphicon glyphicon-refresh" style="color:blue"></span> Restore <a/>';
845 + }
846 + echo '</td></tr>';
847 + $count++;
758 848 }
759 - echo '</td></tr>';
760 - $count++;
761 849 }
850 +
762 851 echo '</tbody>';
763 852
764 853 echo ' </table>
765 854 </div>
@@ -826,164 +915,202 @@
826 915 echo '</p>';
827 916 echo '</form>';
828 917 echo '</div>';
829 918 echo '</div>';
919 +
830 920
921 +
831 922 do_action('wpdbbkp_pro_tab_content');
832 923
833 924 ?>
834 925
835 - <div class="tab-pane" id="db_upgrade">
836 - <div class="panel-group ">
837 - <div class="gn-flex-container row">
838 - <div class=" col-md-12">
839 - <div class="wpdbbkp-wrapper">
840 - <div class="wpdbbkp-wr">
841 - <div class="bkp-wpdbbkp-img">
842 - <span class="sp_ov"></span>
843 - </div>
844 - <div class="bkp-wpdbbkp-cnt">
845 - <h1><?php esc_html_e('UPGRADE to PRO Version','wpdbbkp');?></h1>
846 - <a class="buy" href="https://backupforwp.com/pricing/#pricings" target="_blank">Purchase Now</a>
847 - </div>
848 - <div class="pvf">
849 - <div class="pvf-cnt">
850 - <div class="pvf-tlt">
851 - <h2><?php esc_html_e('Compare Pro vs. Free Version','wpdbbkp');?></h2>
852 - <span><?php esc_html_e('See what you\'ll get with the professional version','wpdbbkp');?></span>
853 - </div>
854 - <div class="pvf-cmp">
855 - <div class="fr">
856 - <h1><?php esc_html_e('FREE','wpdbbkp');?></h1>
857 - <div class="fr-fe">
858 - <div class="fe-1">
859 - <h4><?php esc_html_e('Continious Development','wpdbbkp');?></h4>
860 - <p><?php esc_html_e('We take bug reports and feature requests seriously. We\'re continiously developing &amp; improve this product for last 2 years with passion and love.','wpdbbkp');?></p>
861 - </div>
862 - <div class="fe-1">
863 - <h4><?php esc_html_e('10+ Features','wpdbbkp');?></h4>
864 - <p><?php esc_html_e('We\'re constantly expanding the plugin and make it more useful. We have wide variety of features which will fit any use-case.','wpdbbkp');?></p>
865 - </div>
866 - </div><!-- /. fr-fe -->
867 - </div><!-- /. fr -->
868 - <div class="pr">
869 - <h1>PRO</h1>
870 - <div class="pr-fe">
871 - <span><?php esc_html_e('Everything in Free, and:','wpdbbkp');?></span>
872 - <div class="fet">
873 - <div class="fe-2">
874 - <div class="fe-t">
875 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
876 - <h4><?php esc_html_e('Anonymization Function','wpdbbkp');?></h4>
877 - </div>
878 - <p><?php esc_html_e('Anonymization you critical data during backup with three methods','wpdbbkp');?> </p>
879 - </div>
880 - <div class="fe-2">
881 - <div class="fe-t">
882 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
883 - <h4><?php esc_html_e('Pre-update backups','wpdbbkp');?></h4>
884 - </div>
885 - <p> <?php esc_html_e('Automatically backs up your website before any updates to plugins, themes and WordPress core.','wpdbbkp');?></p>
886 - </div>
926 +<!-- Modal Structure -->
927 +<div class="modal" id="wpdbbkp_offer_modal" data-dismiss="modal" tabindex="-1" aria-labelledby="wpdbbkp_offer_modalLabel" aria-hidden="true">
928 + <div class="modal-dialog">
929 + <div class="modal-content">
930 + <div class="modal-body">
931 + <button type="button" id="offer_close" class="close" data-dismiss="modal" aria-label="Close">
932 + <span aria-hidden="true">&times;</span>
933 + </button>
934 + <h3 class="modal-title" id="wpdbbkp_offer_modalLabel"><img src="<?php echo esc_attr( WPDB_PLUGIN_URL ); /* phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage */ ?>/assets/images/wp-database-backup.png" width="230px"></h3>
935 + <p style="padding:0 50px;"><?php echo esc_html__('Cloud Backup offers a secure, reliable and affordable solution to backup your WP site to the cloud.','wpdbbkp');?></p>
936 + <div class="wpdbbkp_offer_container">
937 + <div class="wpdbbkp_server">
938 + <h4><?php echo esc_html__('Server Backup','wpdbbkp');?></h4>
939 + <p><?php echo esc_html__('Backup your site to server','wpdbbkp');?></p>
940 + <ul>
941 + <li>&#10004; <?php echo esc_html__('Easy to setup','wpdbbkp');?></li>
942 + <li>&#10004; <?php echo esc_html__('Takes storage on your server','wpdbbkp');?></li>
943 + <li>&#10004; <?php echo esc_html__('Availability subject to server','wpdbbkp');?></li>
944 + </ul>
945 + <h4><?php echo esc_html__('Free','wpdbbkp');?></h4>
946 + <button id="wpdbbkp_server_backup" class="btn btn-secondary"><?php echo esc_html__('Create a Backup on this Server','wpdbbkp');?></button>
947 + </div>
948 + <div class="wpdbbkp_remote">
949 + <h4><?php echo esc_html__('Cloud Backup','wpdbbkp');?></h4>
950 + <p><?php echo esc_html__('Backup your site in the cloud','wpdbbkp');?></p>
951 + <ul>
952 + <li>&#10004; <?php echo esc_html__('Secure and reliable','wpdbbkp');?></li>
953 + <li>&#10004; <?php echo esc_html__('Only pay for what you use','wpdbbkp');?></li>
954 + <li>&#10004; <?php echo esc_html__('High availability','wpdbbkp');?></li>
955 + </ul>
956 + <h4><?php echo esc_html__('$1 per 50GB','wpdbbkp');?> <small><?php echo esc_html__('per month','wpdbbkp');?></small></h4>
957 + <button id="wpdbbkp_remote_backup" class="btn btn-primary"><?php echo esc_html__('Create a Backup on Cloud Server','wpdbbkp');?></button>
958 + </div>
959 +
960 + </div>
961 + </div>
962 + </div>
963 + </div>
964 +</div>
965 +<div class="tab-pane" id="db_features">
887 966
888 - <div class="fe-2">
889 - <div class="fe-t">
890 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
891 - <h4><?php esc_html_e('Backup time and scheduling','wpdbbkp'); ?></h4>
892 - </div>
893 - <p><?php esc_html_e('Set exact times to create or delete backups.','wpdbbkp');?></p>
894 - </div>
967 + <div class="panel-group">
968 + <form method="post" action="" name="db_features_form">
969 + <?php wp_nonce_field('wp-database-backup');
970 + $enable_anonymization = get_option('bkpforwp_enable_anonymization',false);
971 + $anonymization_type = get_option('bkpforwp_anonymization_type',false);
972 + $enable_backup_encryption = get_option('bkpforwp_enable_backup_encryption',false);
973 + $anonymization_pass = get_option('bkpforwp_anonymization_pass','');
974 + $backup_encryption_pass = get_option('bkpforwp_encryption_pass','');
975 + $enable_exact_backup_time = get_option('bkpforwp_enable_exact_backup_time',false);
976 + ?>
977 + <div class="row form-group"><label class="col-sm-3" for="enable_anonymization"><?php esc_html_e('Data Anonymization','wpdbbkp'); ?></label>
978 + <div class="col-sm-9"><input type="checkbox" id="enable_anonymization"
979 + name="enable_anonymization" value="1" <?php checked($enable_anonymization,1,1); ?> />
980 +
981 + <div class="alert alert-default" role="alert">
982 + <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <?php esc_html_e('Data anonymization is protecting private or sensitive information by erasing or encrypting identifiers that connect an individual to stored data.','wpdbbkp'); ?><a href="https://backupforwp.com/" target="_blank">Learn More</a></div>
983 + </div>
984 + </div>
985 + <div class="row form-group" id="anonymization_type_div" style="display:none">
986 + <label class="col-sm-3" for="anonymization_type"><?php esc_html_e('Data Anonymization Type','wpdbbkp'); ?> </label>
987 + <div class="col-sm-9"><select id="anonymization_type" class="form-control"
988 + name="anonymization_type">
989 + <option value="masked_data" <?php selected('masked_data', $anonymization_type, true) ?>> <?php esc_html_e('Masked Data','wpdbbkp'); ?>
990 + </option>
991 + <option value="fake_data" <?php selected('fake_data', $anonymization_type, true) ?>> <?php esc_html_e('Fake Data','wpdbbkp'); ?>
992 + </option>
993 + <option value="encrypted_data" <?php selected('encrypted_data', $anonymization_type, true) ?>> <?php esc_html_e('Encrypted Data','wpdbbkp'); ?>
994 + </option>
995 + </select>
996 + <?php echo wp_kses_post('<table class="bkpforwp-infotable">
997 + <tr><th>Masked Data </th><td>Data is masked with * character and <strong class="bkpforwp-red">data can not be recovered</strong> while restore.</td></tr>
998 + <tr><th>Fake Data </th><td>Data is replaced with fake data and <strong class="bkpforwp-red">data can not be recovered</strong> while restore.</td></tr>
999 + <tr><th>Encrypted Data </th><td>Data is encrypted with a password and <strong class="bkpforwp-green">data can be recovered</strong> while restore by using the same password used to backup the data.You just have to add the encryption password in Data Anonymization setting before restoring backup.</td></tr>
1000 + </table>');?>
1001 +
1002 + </div>
1003 + </div>
1004 +
1005 + <div class="row form-group" id="anonymization_enc_ip" style="display:none">
1006 + <label class="col-sm-3" for="anonymization_pass"><?php esc_html_e('Encrypted Data','wpdbbkp'); ?> <?php esc_html_e('Anonymization Password','wpdbbkp'); ?></label>
1007 + <div class="col-sm-9">
1008 + <input type="password" name="anonymization_pass" id="anonymization_pass" class="form-control" value="<?php esc_attr($anonymization_pass);?>">
1009 + <div class="alert alert-default" role="alert">
1010 + <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <?php esc_html_e('Please enter the encryption password. If you lose this pass then you can not recover the encrypted data','wpdbbkp'); ?></div>
1011 + </div>
1012 +
1013 + </div>
895 1014
1015 + <div class="row form-group" style="display:none"><label class="col-sm-3" for="enable_backup_encryption"><?php esc_html_e('Backup File Encrpytion','wpdbbkp'); ?></label>
1016 + <div class="col-sm-9"><input type="checkbox" id="enable_backup_encryption"
1017 + name="enable_backup_encryption" value="1" <?php checked($enable_backup_encryption,1,1); ?> /></div>
1018 + </div>
896 1019
897 - <div class="fe-2">
898 - <div class="fe-t">
899 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
900 - <h4><?php esc_html_e('Fast, personal support','wpdbbkp'); ?></h4>
901 - </div>
902 - <p><?php esc_html_e('Provides expert help and support from the developers whenever you need it.','wpdbbkp'); ?></p>
903 - </div>
904 - <div class="fe-2">
905 - <div class="fe-t">
906 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
907 - <h4><?php esc_html_e('Continuous Updates','wpdbbkp'); ?></h4>
908 - </div>
909 - <p><?php esc_html_e('We\'re continuously updating our premium features and releasing them.','wpdbbkp'); ?></p>
910 - </div>
911 - <div class="fe-2">
912 - <div class="fe-t">
913 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
914 - <h4><?php esc_html_e('Documentation','wpdbbkp'); ?></h4>
915 - </div>
916 - <p><?php esc_html_e('We create tutorials for every possible feature and keep it updated for you.','wpdbbkp'); ?></p>
917 - </div>
918 - </div><!-- /. fet -->
919 - <div class="pr-btn">
920 - <a href="https://backupforwp.com/pricing/#pricings" target="_blank"><?php esc_html_e('Upgrade to Pro','wpdbbkp'); ?></a>
921 - </div><!-- /. pr-btn -->
922 - </div><!-- /. pr-fe -->
923 - </div><!-- /.pr -->
924 - </div><!-- /. pvf-cmp -->
925 - </div><!-- /. pvf-cnt -->
926 -
927 - <div class="wpdbbkpfaq">
928 - <h2><?php esc_html_e('Frequently Asked Questions','wpdbbkp'); ?></h2>
929 - <div class="faq-lst">
930 - <div class="lt">
931 - <ul>
932 - <li>
933 - <span><?php esc_html_e('Is there a setup fee?','wpdbbkp'); ?></span>
934 - <p><?php esc_html_e('No. There are no setup fees on any of our plans','wpdbbkp'); ?></p>
935 - </li>
936 - <li>
937 - <span><?php esc_html_e('What\'s the time span for your contracts?','wpdbbkp'); ?></span>
938 - <p><?php esc_html_e('All the plans are year-to-year which are subscribed annually except for lifetime plan.','wpdbbkp'); ?></p>
939 - </li>
940 - <li>
941 - <span><?php esc_html_e('What payment methods are accepted?','wpdbbkp'); ?></span>
942 - <p><?php esc_html_e('We accepts PayPal and Credit Card payments.','wpdbbkp'); ?></p>
943 - </li>
944 - <li>
945 - <span><?php esc_html_e('Do you offer support if I need help?','wpdbbkp'); ?></span>
946 - <p><?php esc_html_e('Yes! Top-notch customer support for our paid customers is key for a quality product, so we\'ll do our very best to resolve any issues you encounter via our support page.','wpdbbkp'); ?></p>
947 - </li>
948 - <li>
949 - <span><?php esc_html_e('Can I use the plugins after my subscription is expired?','wpdbbkp'); ?></span>
950 - <p><?php esc_html_e('Yes, you can use the plugins, but you will not get future updates for those plugins.','wpdbbkp'); ?></p>
951 - </li>
952 - </ul>
953 - </div>
954 - <div class="rt">
955 - <ul>
956 - <li>
957 - <span><?php esc_html_e('Can I cancel my membership at any time?','wpdbbkp'); ?></span>
958 - <p><?php esc_html_e('Yes. You can cancel your membership by contacting us.','wpdbbkp'); ?></p>
959 - </li>
960 - <li>
961 - <span><?php esc_html_e('Can I change my plan later on?','wpdbbkp'); ?></span>
962 - <p><?php esc_html_e('Yes. You can upgrade your plan by contacting us.','wpdbbkp'); ?></p>
963 - </li>
964 - <li>
965 - <span><?php esc_html_e('Do you offer refunds?','wpdbbkp'); ?></span>
966 - <p><?php esc_html_e('You are fully protected by our 100% Money-Back Guarantee Unconditional. If during the next 14 days you experience an issue that makes the plugin unusable, and we are unable to resolve it, we\'ll happily offer a full refund.','wpdbbkp'); ?></p>
967 - </li>
968 - <li>
969 - <span><?php esc_html_e('Do I get updates for the premium plugin?','wpdbbkp'); ?></span>
970 - <p><?php esc_html_e('Yes, you will get updates for all the premium plugins until your subscription is active.','wpdbbkp'); ?></p>
971 - </li>
972 - </ul>
973 - </div>
974 - </div><!-- /.faq-lst -->
975 - </div><!-- /.faq -->
976 - </div><!-- /. pvf -->
977 - </div>
978 - </div>
1020 + <div class="row form-group" id="encryption_pass_div" style="display:none">
1021 + <label class="col-sm-3" for="backup_encryption_pass"><?php esc_html_e('Backup Password','wpdbbkp'); ?></label>
1022 + <div class="col-sm-9">
1023 + <input type="password" name="backup_encryption_pass" id="backup_encryption_pass" class="form-control" value="<?php esc_attr($backup_encryption_pass);?>">
1024 + </div>
1025 + </div>
1026 +
1027 + <p class="submit">
1028 + <input type="submit" name="featureSubmit" class="btn btn-primary" value="Save Settings" />
1029 + </p>
1030 + </form>
1031 + </div>
1032 + </div>
1033 +<div class="tab-pane" id="db_remotebackups">
1034 +<?php
1035 +$update_msg = '';
1036 +if ( true === isset( $_POST['wpdb_cd_s3'] ) && 'Y' === $_POST['wpdb_cd_s3'] ) {
1037 + // Validate that the contents of the form request came from the current site and not somewhere else added 21-08-15 V.3.4.
1038 + if ( ! isset( $_POST['wpdbbackup_update_cd_setting'] ) ) {
1039 + wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') );
1040 + }
1041 + if ( ! wp_verify_nonce( wp_unslash( $_POST['wpdbbackup_update_cd_setting'] ) , 'wpdbbackup-update-cd-setting' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1042 + wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') );
1043 + }
1044 +
1045 + if ( true === isset( $_POST['wpdb_clouddrive_token'] ) ) {
1046 + update_option( 'wpdb_clouddrive_token', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_clouddrive_token'] ) ) ), false );
1047 + }
1048 +
1049 + // Put a "settings updated" message on the screen.
1050 + $update_msg = esc_html__('Your BackupforWP Cloud Backup setting has been saved.' , 'wpdbbkp');
1051 +}
1052 +
1053 +$wpdb_clouddrive_token = get_option( 'wpdb_clouddrive_token',null);
1054 +
1055 +$wpdbbkp_bb_s3_status = '<small><b>'.esc_html__('Status', 'wpdbbkp').'</b>: '.esc_html__('Not Configured', 'wpdbbkp').' </small> ';
1056 +
1057 +if($wpdb_clouddrive_token && !empty($wpdb_clouddrive_token))
1058 +{
1059 + $wpdbbkp_bb_s3_status ='<small>'.esc_html__('Status', 'wpdbbkp').'</b>: <span class="dashicons dashicons-yes-alt" style="color:green;font-size:16px" title="'.esc_attr__('Destination enabled', 'wpdbbkp').'"></span><span class="configured">'.esc_html__('Configured', 'wpdbbkp').' </span> </small> ';
1060 +}
1061 +
1062 +?>
1063 +<h2 align="center"><strong><?php echo esc_html__('Cloud Backup by BackupforWP', 'wpdbbkp') ?></strong></h2>
1064 +<div class="panel panel-default">
1065 + <div class="panel-heading">
1066 + <h4 class="panel-title">
1067 + <a data-toggle="collapse" data-parent="#accordion" href="#collapsebb">
1068 + <?php echo '<b>'.esc_html__('Cloud Backup', 'wpdbbkp').'</b>'; ?> <?php echo wp_kses_post($wpdbbkp_bb_s3_status);?>
1069 +
1070 + </a>
1071 + </h4>
1072 + </div>
1073 + <div class="panel-body">
1074 + <?php
1075 + if($update_msg){
1076 + echo '<div class="updated"><p><strong>'.esc_html( $update_msg ).'</strong></p></div>';
1077 + }
1078 + ?>
1079 + <form class="form-group" name="Clouddrive3" method="post" action="">
1080 +
1081 + <p style="padding:0 20px;">
1082 + <?php echo '<h2 style="padding:0 20px;">'.esc_html__('Getting started with our Cloud Backup service is simple.', 'wpdbbkp').'</h2>'; ?>
1083 +
1084 + <ul style="list-style-type: style;">
1085 + <li style="margin-left: 30px;"><?php echo esc_html__('Sign up for a free account at', 'wpdbbkp'); ?> <a href="https://backupforwp.com/register" target="_blank"><?php echo esc_html__(' Cloud Backup ', 'wpdbbkp');?> </a><?php echo esc_html__('by Backup for WP', 'wpdbbkp');?></li>
1086 + <li style="margin-left: 30px;"><?php echo esc_html__('Add the website url', 'wpdbbkp'); ?> <a href="https://app.backupforwp.com/websites" target="_blank"><?php echo esc_html__('Add Website here', 'wpdbbkp');?> </a></li>
1087 + <li style="margin-left: 30px;"><?php echo esc_html__('API token will be generated on adding website.', 'wpdbbkp'); ?></li>
1088 + <li style="margin-left: 30px;"><?php echo esc_html__('Copy the token here and Click Save.', 'wpdbbkp'); ?></li>
1089 + <li style="margin-left: 30px;"><b><?php echo esc_html__('You can see your backup files from ', 'wpdbbkp'); ?><a href="https://app.backupforwp.com/dashboard/" target="_blank"><?php echo esc_html__('here', 'wpdbbkp');?> </a></b></li>
1090 + </ul>
979 1091
980 - </div>
981 - </div>
982 - </div>
983 - </div>
984 1092
1093 + <input type="hidden" name="wpdb_cd_s3" value="Y">
1094 + <input name="wpdbbackup_update_cd_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-cd-setting' ) ); ?>" />
1095 + <?php wp_nonce_field( 'wp-database-backup' ); ?>
1096 + <div class="row form-group">
1097 + <label class="col-sm-3" for="wpdb_clouddrive_token"><?php echo esc_html__('BackforWP API Token', 'wpdbbkp') ?></label>
1098 + <div class="col-sm-6">
985 1099
1100 + <input type="text" id="wpdb_clouddrive_token" class="form-control" name="wpdb_clouddrive_token" value="<?php echo esc_html( get_option( 'wpdb_clouddrive_token' ) ); ?>" size="25" placeholder="<?php esc_attr_e('26b18a624d2f5e01324bc81f90cfff63ba493bc15f00d790729fb437e90f54ea','wpdbbkp');?>">
1101 + <a href="https://app.backupforwp.com/websites" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1102 + </div>
1103 + </div>
1104 +
1105 + <p style="padding-left:20px"><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Save' , 'wpdbbkp' ); ?>" />&nbsp;
1106 + </p>
1107 + </form>
1108 + </div>
1109 +</div>
1110 +
1111 +
1112 +</div>
986 1113 <div class="tab-pane" id="db_help">
987 1114 <div class="panel-group ">
988 1115 <div class="gn-flex-container row">
989 1116 <div class="wpdbbkp-left-side col-md-8">
@@ -993,9 +1120,9 @@
993 1120 <li>
994 1121 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Email', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
995 1122 </label>
996 1123 <div class="support-input">
997 - <input type="text" id="wpdbbkp_query_email" name="wpdbbkp_query_email" size="47" placeholder="Enter your Email" required="">
1124 + <input type="text" id="wpdbbkp_query_email" name="wpdbbkp_query_email" size="47" placeholder="<?php esc_attr_e('Enter your Email','wpdbbkp');?>" required="">
998 1125 </div>
999 1126 </li>
1000 1127 <li>
1001 1128 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
@@ -1000,9 +1127,9 @@
1000 1127 <li>
1001 1128 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1002 1129 </label>
1003 1130 <div class="support-input">
1004 - <textarea rows="5" cols="50" id="wpdbbkp_query_message" name="wpdbbkp_query_message" placeholder="Write your query"></textarea>
1131 + <textarea rows="5" cols="50" id="wpdbbkp_query_message" name="wpdbbkp_query_message" placeholder="<?php esc_attr_e('Write your query','wpdbbkp');?>"></textarea>
1005 1132 </div>
1006 1133 </li>
1007 1134 <li>
1008 1135 <button class="button button-primary wpdbbkp-send-query"> <?php echo esc_html__('Send Support Request', 'wpdbbkp') ?> </button>
@@ -1029,9 +1156,9 @@
1029 1156 <div class="panel panel-group panel-default">
1030 1157 <div class="panel-heading">
1031 1158 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedb">
1032 1159 <h4 class="panel-title">
1033 - <?php esc_attr_e( 'System Check', 'wpdbbk' ); ?>
1160 + <?php esc_attr_e( 'System Check', 'wpdbbkp' ); ?>
1034 1161 </h4>
1035 1162 </a>
1036 1163 </div>
1037 1164 <div id="collapsedb" class="panel-collapse collapse in">
@@ -1038,8 +1165,9 @@
1038 1165 <div class="panel-body list-group">
1039 1166
1040 1167 <div class="row list-group-item">
1041 1168 <?php
1169 + $df = $dt = $dp = $du = 'NA';
1042 1170 if(function_exists('disk_free_space')){
1043 1171 /* get disk space free (in bytes) */
1044 1172 $df = disk_free_space( WPDB_ROOTPATH );
1045 1173 /* and get disk space total (in bytes) */
@@ -1053,14 +1181,14 @@
1053 1181 $df = $this->wp_db_backup_format_bytes( $df );
1054 1182 $du = $this->wp_db_backup_format_bytes( $du );
1055 1183 $dt = $this->wp_db_backup_format_bytes( $dt );
1056 1184 }
1057 - $du=$dp=$df=$dt='NA';
1185 +
1058 1186 ?>
1059 1187 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1060 1188 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1061 1189 </div>
1062 - <div class="col-md-3">Disk Space</div>
1190 + <div class="col-md-12">Disk Space</div>
1063 1191 <div class="col-md-5">
1064 1192 <div class="progress">
1065 1193 <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<?php echo esc_attr( trim( $dp ) ); ?>" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo esc_attr( trim( $dp ) ); ?>%"> <?php echo esc_attr( $dp ); ?>%
1066 1194 </div>
@@ -1129,13 +1257,18 @@
1129 1257 <div class="row list-group-item">
1130 1258 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1131 1259 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1132 1260 </div>
1133 - <div class="col-md-3"><?php esc_attr_e( 'Upload directory URL', 'wpdbbk' ); ?></div>
1261 + <div class="col-md-3"><?php esc_attr_e( 'Upload directory URL', 'wpdbbkp' ); ?></div>
1134 1262 <div class="col-md-5">
1135 1263 <?php
1136 1264 $upload_dir = wp_upload_dir();
1137 - echo esc_url( $upload_dir['baseurl'] )
1265 + echo esc_url( $upload_dir['baseurl'] );
1266 + global $wp_filesystem;
1267 + if(!function_exists('WP_Filesystem')){
1268 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
1269 + }
1270 + WP_Filesystem();
1138 1271 ?>
1139 1272 </div>
1140 1273 <div class="col-md-3"></div>
1141 1274 </div>
@@ -1143,14 +1276,14 @@
1143 1276 <div class="row list-group-item">
1144 1277 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1145 1278 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1146 1279 </div>
1147 - <div class="col-md-3"><?php esc_attr_e( 'Upload directory', 'wpdbbk' ); ?></div>
1280 + <div class="col-md-3"><?php esc_attr_e( 'Upload directory', 'wpdbbkp' ); ?></div>
1148 1281 <div class="col-md-5"><?php echo esc_attr( $upload_dir['basedir'] ); ?></div>
1149 1282 <div class="col-md-1">
1150 1283 <?php echo esc_attr( substr( sprintf( '%o', fileperms( $upload_dir['basedir'] ) ), -4 ) ); ?></div>
1151 1284 <div
1152 - class="col-md-2"><?php echo ( ! is_writable( $upload_dir['basedir'] ) ) ? '<p class="text-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Not writable </p>' : '<p class="text-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> writable</p>'; ?>
1285 + class="col-md-2"><?php echo ( ! $wp_filesystem->is_writable( $upload_dir['basedir']) ) ? '<p class="text-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Not writable </p>' : '<p class="text-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> writable</p>'; ?>
1153 1286 </div>
1154 1287 </div>
1155 1288
1156 1289 <div class="row list-group-item">
@@ -1168,10 +1301,9 @@
1168 1301 <div class="col-md-5">
1169 1302 <?php
1170 1303 echo esc_attr( WP_MEMORY_LIMIT );
1171 1304 echo '(Max &nbsp;' . esc_attr( WP_MAX_MEMORY_LIMIT );
1172 - ?>
1173 - )
1305 + ?> )
1174 1306 </div>
1175 1307 </div>
1176 1308
1177 1309
@@ -1178,9 +1310,9 @@
1178 1310 <div class="row list-group-item">
1179 1311 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1180 1312 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1181 1313 </div>
1182 - <div class="col-md-3"><?php esc_attr_e( 'Max Execution Time', 'wpdbbk' ); ?></div>
1314 + <div class="col-md-3"><?php esc_attr_e( 'Max Execution Time', 'wpdbbkp' ); ?></div>
1183 1315 <div class="col-md-5"> <?php echo esc_attr( ini_get( 'max_execution_time' ) ); ?></div>
1184 1316 <div class="col-md-1"></div>
1185 1317 <div
1186 1318 class="col-md-2"><?php echo esc_attr( ini_get( 'max_execution_time' ) ) < 60 ? '<p class="text-danger" data-toggle="tooltip" data-placement="left" title="For large site set high"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Low </p>' : ''; ?></div>
@@ -1188,15 +1320,15 @@
1188 1320 <div class="row list-group-item">
1189 1321 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1190 1322 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1191 1323 </div>
1192 - <div class="col-md-3"><?php esc_attr_e( 'Database backup directory', 'wpdbbk' ); ?></div>
1324 + <div class="col-md-3"><?php esc_attr_e( 'Database backup directory', 'wpdbbkp' ); ?></div>
1193 1325 <div
1194 1326 class="col-md-5"> <?php echo esc_attr( $upload_dir['basedir'] . '/db-backup' ); ?></div>
1195 1327 <div
1196 1328 class="col-md-1"><?php echo esc_attr( substr( sprintf( '%o', @fileperms( esc_attr( $upload_dir['basedir'] ) . '/db-backup' ) ), -4 ) ); ?></div>
1197 1329 <div
1198 - class="col-md-2"><?php echo ( ! is_writable( $upload_dir['basedir'] . '/db-backup' ) ) ? '<p class="text-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Not writable </p>' : '<p class="text-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> writable</p>'; ?></div>
1330 + class="col-md-2"><?php echo ( ! $wp_filesystem->is_writable( $upload_dir['basedir'] . '/db-backup' ) ) ? '<p class="text-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Not writable </p>' : '<p class="text-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> writable</p>'; ?></div>
1199 1331 </div>
1200 1332
1201 1333 <div class="row list-group-item">
1202 1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
@@ -1201,9 +1333,9 @@
1201 1333 <div class="row list-group-item">
1202 1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1203 1335 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1204 1336 </div>
1205 - <div class="col-md-3"><?php esc_attr_e( 'Class ZipArchive Present : ', 'wpdbbk' ); ?></div>
1337 + <div class="col-md-3"><?php esc_attr_e( 'Class ZipArchive Present : ', 'wpdbbkp' ); ?></div>
1206 1338 <div class="col-md-5">
1207 1339 <?php
1208 1340 echo ( class_exists( 'ZipArchive' ) ) ? 'Yes </p>' : '<p class="">No</p>';
1209 1341 ?>
@@ -1214,9 +1346,9 @@
1214 1346 <div class="row list-group-item">
1215 1347 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1216 1348 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1217 1349 </div>
1218 - <div class="col-md-3"><?php esc_attr_e( 'mysqldump (cmd) Present : ', 'wpdbbk' ); ?></div>
1350 + <div class="col-md-3"><?php esc_attr_e( 'mysqldump (cmd) Present : ', 'wpdbbkp' ); ?></div>
1219 1351 <div class="col-md-5">
1220 1352 <?php
1221 1353 $wpdb_admin = new Wpdb_Admin();
1222 1354 echo ( $wpdb_admin->get_mysqldump_command_path() ) ? 'Yes </p>' : '<p class="">No</p>';
@@ -1314,9 +1446,9 @@
1314 1446 $no++;
1315 1447 echo '<tr' . esc_attr( $style ) . '>';
1316 1448 echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1317 1449 echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1318 - echo '<td>' . esc_attr( number_format_i18n( $tablestatus_arr['Rows'] ) ) . '</td>';
1450 + echo '<td>' . esc_attr( number_format_i18n( isset($tablestatus_arr['Rows'])?$tablestatus_arr['Rows']:0 ) ) . '</td>';
1319 1451
1320 1452 $row_usage += $tablestatus_arr['Rows'];
1321 1453
1322 1454 echo '</tr>';
@@ -1393,14 +1525,17 @@
1393 1525 <th><?php echo esc_html__('Version', 'wpdbbkp') ?></th>
1394 1526 </tr>
1395 1527 <?php
1396 1528 $plugins = get_plugins();
1397 - foreach ( $plugins as $plugin ) {
1398 - echo '<tr>
1399 - <td>' . esc_attr( $plugin['Name'] ) . '</td>
1400 - <td>' . esc_attr( $plugin['Version'] ) . '</td>
1401 - </tr>';
1529 + if(!empty($plugins) && is_array($plugins)){
1530 + foreach ( $plugins as $plugin ) {
1531 + echo '<tr>
1532 + <td>' . esc_attr( $plugin['Name'] ) . '</td>
1533 + <td>' . esc_attr( $plugin['Version'] ) . '</td>
1534 + </tr>';
1535 + }
1402 1536 }
1537 +
1403 1538 ?>
1404 1539 </table>
1405 1540 <table class="table table-condensed">
1406 1541 <tr class="success">
@@ -1484,30 +1619,53 @@
1484 1619 } else {
1485 1620 $checked = '';
1486 1621 }
1487 1622 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
1623 + $wp_db_remove_on_uninstall = get_option( 'wp_db_remove_on_uninstall');
1624 + $wp_db_incremental_backup = get_option( 'wp_db_incremental_backup');
1625 + $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
1488 1626 if ( 1 === (int) $wp_db_remove_local_backup ) {
1489 1627 $remove_local_backup = 'checked';
1490 1628 } else {
1491 1629 $remove_local_backup = '';
1492 1630 }
1631 + if ( 1 === (int) $wp_db_remove_on_uninstall ) {
1632 + $remove_on_uninstall = 'checked';
1633 + } else {
1634 + $remove_on_uninstall = '';
1635 + }
1636 + if ( 1 === (int) $wp_db_incremental_backup ) {
1637 + $incremental_backup = 'checked';
1638 + } else {
1639 + $incremental_backup = '';
1640 + }
1641 + if ( 1 === (int) $wp_db_save_settings_in_backup ) {
1642 + $save_on_backup = 'checked';
1643 + } else {
1644 + $save_on_backup = '';
1645 + }
1493 1646 ?>
1494 1647 <form action="" method="post">
1495 1648 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1496 1649 <div class="input-group">
1497 1650 <span class="input-group-addon" id="sizing-addon2"><?php echo esc_html__('Maximum Local Backups', 'wpdbbkp') ?></span>
1498 - <input type="number" name="wp_local_db_backup_count" value="<?php echo esc_html( $wp_local_db_backup_count ); ?>" class="form-control" placeholder="Maximum Local Backups" aria-describedby="sizing-addon2">
1651 + <input type="number" name="wp_local_db_backup_count" value="<?php echo esc_html( $wp_local_db_backup_count ); ?>" class="form-control" placeholder="<?php esc_attr_e('Maximum Local Backups','wpdbbkp');?>" aria-describedby="sizing-addon2">
1499 1652
1500 - </div>
1501 - <div class="alert alert-default" role="alert">
1502 - <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span><?php echo esc_html__(' The maximum
1653 + </div><br>
1654 + <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span><?php echo esc_html__(' The maximum
1503 1655 number of Local Database Backups that should be kept, regardless of their size.', 'wpdbbkp') ?></br>
1504 1656 <?php echo esc_html__('Leave blank for keep unlimited database backups.', 'wpdbbkp') ?>
1505 - </div>
1657 + </p>
1658 +
1506 1659 <hr>
1507 1660 <div class="input-group">
1508 1661 <label><input type="checkbox" <?php echo esc_attr( $checked ); ?> name="wp_db_log"> <?php echo esc_html__('Enable Log', 'wpdbbkp') ?></label>
1509 1662 </div>
1663 + <br>
1664 + <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1665 + <?php echo esc_html__(' Create a log file to record details of each backup operation. ', 'wpdbbkp') ?>
1666 + </p>
1667 +
1510 1668 <hr>
1511 1669 <div class="input-group">
1512 1670 <label><input type="checkbox" <?php echo esc_attr( $wp_db_backup_enable_auto_upgrade_checked ); ?> name="wp_db_backup_enable_auto_upgrade"> <?php echo esc_html__('Enable Auto Backups Before Upgrade', 'wpdbbkp') ?></label>
1513 1671 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
@@ -1519,19 +1677,37 @@
1519 1677 <div class="input-group">
1520 1678 <label><input type="checkbox" <?php echo esc_attr( $remove_local_backup ); ?> name="wp_db_remove_local_backup"> <?php echo esc_html__('Remove local backup', 'wpdbbkp') ?></label>
1521 1679 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1522 1680 <?php echo esc_html__('If Checked then it will remove local backup.', 'wpdbbkp') ?>
1523 - <br><?php echo esc_html__('Use this option only when you have set any destination.', 'wpdbbkp') ?>
1524 - <br><?php echo esc_html__('If somesites you need only external backup.', 'wpdbbkp') ?>
1681 + <?php echo esc_html__('Use this option only when you have set any destination.', 'wpdbbkp') ?>
1682 + <?php echo esc_html__('If somesites you need only external backup.', 'wpdbbkp') ?>
1525 1683 </p>
1526 1684 </div>
1527 1685 <hr>
1686 + <div class="input-group">
1687 + <label><input type="checkbox" <?php echo esc_attr( $save_on_backup ); ?> name="wp_db_save_settings_in_backup"> <?php echo esc_html__('Skip plugin settings from database backup', 'wpdbbkp') ?></label>
1688 + <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1689 + <?php echo esc_html__('If Checked then it will skip Backup for WP plugin settings from the DB backup file .', 'wpdbbkp') ?>
1690 + </p>
1691 + </div>
1692 + <hr>
1693 + <div class="input-group">
1694 + <label><input type="checkbox" <?php echo esc_attr( $remove_on_uninstall ); ?> name="wp_db_remove_on_uninstall"> <?php echo esc_html__('Delete Data and options on uninstall', 'wpdbbkp') ?></label>
1695 + <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1696 + <?php echo esc_html__('If Checked then it will delete all backup files and options when plugin is uninstalled', 'wpdbbkp') ?>
1697 +
1698 + </p>
1699 + </div>
1700 +
1528 1701 <?php
1529 1702 $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removeallbackup&_wpnonce=' . esc_attr( $nonce ); ?>
1530 1703
1531 1704 <div class="input-group">
1532 - <a title="Remove Database Backup" onclick="return confirm('Are you sure you want to delete all the backups? Deleted backups can not be recovered.')" href="<?php echo esc_url($remove_backup_href)?>" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span> <?php esc_html_e('Delete all Backups', 'wpdbbkp')?></a>
1533 - <br><?php echo esc_html__('Warning :This is will delete all the backups on the website. Once deleted backups can not be recovered.', 'wpdbbkp') ?>
1705 + <a title="Remove Database Backup" onclick="return confirm('Are you sure you want to delete all the backups? Deleted backups can not be recovered.')" href="<?php echo esc_url($remove_backup_href)?>" class="btn btn-danger" style="margin-bottom:10px;"><span class="glyphicon glyphicon-trash"></span> <?php esc_html_e('Delete all Backups', 'wpdbbkp')?></a>
1706 + <p> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1707 + <?php echo esc_html__('Warning :This is will delete all the backups on the website. Once deleted backups can not be recovered.', 'wpdbbkp') ?>
1708 + </p>
1709 +
1534 1710
1535 1711 </div>
1536 1712 <hr>
1537 1713 <div class="panel panel-default">
@@ -1567,9 +1743,9 @@
1567 1743 $no++;
1568 1744 echo '<tr' . esc_attr( $style ) . '>';
1569 1745 echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1570 1746 echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1571 - echo '<td>' . esc_attr( number_format_i18n( $tablestatus_arr['Rows'] ) ) . '</td>';
1747 + echo '<td>' . esc_attr( number_format_i18n( isset($tablestatus_arr['Rows'])?$tablestatus_arr['Rows']:0 ) ) . '</td>';
1572 1748 if ( false === empty( $wp_db_exclude_table ) && in_array( $tablestatus_arr['Name'], $wp_db_exclude_table, true ) ) {
1573 1749 $checked = 'checked';
1574 1750 } else {
1575 1751 $checked = '';
@@ -1615,15 +1791,15 @@
1615 1791 </p>
1616 1792 <br>
1617 1793 <div class="input-group">
1618 1794 <span class="input-group-addon" id="wp_db_backup_search_text"><?php echo esc_html__('Search For', 'wpdbbkp') ?></span>
1619 - <input type="text" name="wp_db_backup_search_text" value="<?php echo esc_html( $wp_db_backup_search_text ); ?>" class="form-control" placeholder="http://localhost/wordpress" aria-describedby="wp_db_backup_search_text">
1795 + <input type="text" name="wp_db_backup_search_text" value="<?php echo esc_html( $wp_db_backup_search_text ); ?>" class="form-control" placeholder="<?php esc_attr_e('https://example.com/wordpress','wpdbbkp'); ?>" aria-describedby="wp_db_backup_search_text">
1620 1796
1621 1797 </div>
1622 1798 <br>
1623 1799 <div class="input-group">
1624 1800 <span class="input-group-addon" id="wp_db_backup_replace_text"><?php echo esc_html__('Replace With', 'wpdbbkp') ?></span>
1625 - <input type="text" name="wp_db_backup_replace_text" value="<?php echo esc_html( $wp_db_backup_replace_text ); ?>" class="form-control" placeholder="http://site.com" aria-describedby="wp_db_backup_replace_text">
1801 + <input type="text" name="wp_db_backup_replace_text" value="<?php echo esc_html( $wp_db_backup_replace_text ); ?>" class="form-control" placeholder="<?php esc_attr_e('http://site.com','wpdbbkp');?>" aria-describedby="wp_db_backup_replace_text">
1626 1802
1627 1803 </div>
1628 1804
1629 1805 <div class="alert alert-default" role="alert">
@@ -1630,10 +1806,10 @@
1630 1806 <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1631 1807 <?php echo esc_html__("Leave blank those fields if you don't want use this feature and want only regular Database backup.", 'wpdbbkp') ?>
1632 1808 <br>
1633 1809 <?php echo esc_html__('Ex:', 'wpdbbkp') ?>
1634 - <br><?php echo esc_html__('Search For:', 'wpdbbkp') ?> http://localhost/wordpress/
1635 - <br><?php echo esc_html__('Replace With:', 'wpdbbkp') ?> http://domain.com/
1810 + <br><?php echo esc_html__('Search For:', 'wpdbbkp') ?> <?php echo esc_url('http://example.com/wordpress/', 'wpdbbkp'); ?>
1811 + <br><?php echo esc_html__('Replace With:', 'wpdbbkp') ?> <?php echo esc_url('http://domain.com/', 'wpdbbkp') ?>
1636 1812
1637 1813 <br><br>
1638 1814 <?php echo esc_html__('Note - This is Search & Replace data in your WordPress Database Backup File not in current Database installation.', 'wpdbbkp') ?>
1639 1815
@@ -1697,63 +1873,79 @@
1697 1873 global $wpdb;
1698 1874 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1699 1875 $options_backup = get_option( 'wp_db_backup_backups' );
1700 1876 $settings_backup = get_option( 'wp_db_backup_options' );
1701 - delete_option( 'wp_db_backup_backups' );
1702 - delete_option( 'wp_db_backup_options' );
1877 + $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
1878 + if($wp_db_save_settings_in_backup){
1879 + delete_option( 'wp_db_backup_backups' );
1880 + delete_option( 'wp_db_backup_options' );
1881 + }
1703 1882 /* END : Prevent saving backup plugin settings in the database dump */
1704 1883 $wp_db_exclude_table = array();
1705 1884 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
1706 1885 $tables = $wpdb->get_col( 'SHOW TABLES' ); // phpcs:ignore
1707 1886 $output = '';
1708 - foreach ( $tables as $table ) {
1709 - if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
1710 -
1711 - $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1712 - $check_count = intval($check_count);
1713 - $sub_limit =500;
1714 - if(isset($check_count) && $check_count>$sub_limit){
1715 - $result =array();
1716 - $t_sub_queries= ceil($check_count/$sub_limit);
1717 - for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1718 - {
1719 - $sub_offset = $sub_i*$sub_limit;
1720 - $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i LIMIT %d OFFSET %d",array($table,$sub_limit,$sub_offset)), ARRAY_A );
1721 - if($sub_result){
1722 - $result = array_merge($result,$sub_result);
1887 + if(!empty($tables) && !is_array($tables)){
1888 + foreach ( $tables as $table ) {
1889 + if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
1890 +
1891 + $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1892 + $check_count = intval($check_count);
1893 + $sub_limit =500;
1894 + if(isset($check_count) && $check_count>$sub_limit){
1895 + $result =array();
1896 + $t_sub_queries= ceil($check_count/$sub_limit);
1897 + for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1898 + {
1899 + $sub_offset = $sub_i*$sub_limit;
1900 + $sub_result = false;
1901 + if ( false === $sub_result ) {
1902 + // phpcs:ignore -- using direct query to get the data of table in chunks.
1903 + $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table} LIMIT %d OFFSET %d",array($sub_limit,$sub_offset)), ARRAY_A );
1904 + }
1905 +
1906 + if($sub_result){
1907 + $result = array_merge($result,$sub_result);
1908 + }
1909 + sleep(1);
1723 1910 }
1724 - sleep(1);
1725 1911 }
1726 - }
1727 - else{
1728 - $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i",array($table)), ARRAY_A ); // phpcs:ignore
1729 - }
1730 -
1731 -
1732 - $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1733 - $output .= "\n\n" . $row2[1] . ";\n\n";
1734 - $result_count = count( $result );
1735 - for ( $i = 0; $i < $result_count; $i++ ) {
1736 - $row = $result[ $i ];
1737 - $output .= 'INSERT INTO ' . $table . ' VALUES(';
1738 - $result_o_index = count( $result[0] );
1739 - $j=0;
1740 - foreach ($row as $key => $value) {
1741 - $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1742 - $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
1743 - if ( $j < ( $result_o_index - 1 ) ) {
1744 - $output .= ',';
1912 + else{
1913 + $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table}"), ARRAY_A ); // phpcs:ignore
1914 + }
1915 +
1916 +
1917 + $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1918 + $output .= "\n\n" . $row2[1] . ";\n\n";
1919 + $result_count = count( $result );
1920 + for ( $i = 0; $i < $result_count; $i++ ) {
1921 + if(isset($result[ $i ])){
1922 + $row = $result[ $i ];
1923 + $output .= 'INSERT INTO ' . $table . ' VALUES(';
1924 + $result_o_index = count( $result[0] );
1925 + $j=0;
1926 + foreach ($row as $key => $value) {
1927 + $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1928 + $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
1929 + if ( $j < ( $result_o_index - 1 ) ) {
1930 + $output .= ',';
1931 + }
1932 + $j++;
1933 + }
1934 + $output .= ");\n";
1745 1935 }
1746 - $j++;
1936 +
1747 1937 }
1748 - $output .= ");\n";
1938 + $output .= "\n";
1749 1939 }
1750 - $output .= "\n";
1940 + sleep(1);
1751 1941 }
1752 - sleep(1);
1942 +
1753 1943 }
1944 +
1754 1945 $wpdb->flush();
1755 1946 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1947 + $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
1756 1948 add_option( 'wp_db_backup_backups', $options_backup );
1757 1949 add_option( 'wp_db_backup_options', $settings_backup );
1758 1950 /* END : Prevent saving backup plugin settings in the database dump */
1759 1951 return $output;
@@ -1761,61 +1953,138 @@
1761 1953
1762 1954 /**
1763 1955 * Create database backup new function.
1764 1956 */
1765 - public function wp_db_backup_create_mysql_backup_new($table) {
1766 - global $wpdb;
1767 - $output = '';
1957 + public function wp_db_backup_create_mysql_backup_new( $table, $file_path ) {
1958 + global $wpdb, $wp_filesystem;
1959 +
1960 + // Ensure WP Filesystem is loaded
1961 + if ( ! function_exists( 'WP_Filesystem' ) ) {
1962 + require_once ABSPATH . 'wp-admin/includes/file.php';
1963 + }
1964 + WP_Filesystem();
1965 +
1966 + // Define file size threshold (e.g., 10MB)
1967 + $file_size_threshold = 10 * 1024 * 1024; // 10MB
1968 +
1969 + // Initialize the file with table creation statement if it doesn't exist
1768 1970
1769 - $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1770 - $check_count = intval($check_count);
1771 - $sub_limit =500;
1772 - if(isset($check_count) && $check_count>$sub_limit){
1773 - $result =array();
1774 - $t_sub_queries= ceil($check_count/$sub_limit);
1775 - for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1776 - {
1777 - $sub_offset = $sub_i*$sub_limit;
1778 - $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i LIMIT %d OFFSET %d",array($table,$sub_limit,$sub_offset)), ARRAY_A );
1779 - if($sub_result){
1780 - $result = array_merge($result,$sub_result);
1971 + $table = esc_sql( $table );
1972 + $row2 = $wpdb->get_row( "SHOW CREATE TABLE `{$table}`", ARRAY_N ); // phpcs:ignore
1973 + $initial_output = "\n\n" . $row2[1] . ";\n\n";
1974 +
1975 + $use_php_methods = false;
1976 + if ( $wp_filesystem->exists( $file_path ) ) {
1977 + // Check file size
1978 + $file_size = $wp_filesystem->size( $file_path );
1979 + if ( $file_size !== false && $file_size > $file_size_threshold ) {
1980 + $use_php_methods = true;
1981 + }
1982 + }
1983 +
1984 + // Function to append content
1985 + $append_content = function( $new_content ) use ( $file_path, $wp_filesystem, $use_php_methods ) {
1986 + if ( $use_php_methods ) {
1987 + // Using PHP methods to append
1988 + if ( ! $wp_filesystem->exists( $file_path ) ) {
1989 + // phpcs:ignore -- WP Filesystem fileing for large files
1990 + file_put_contents( $file_path, $new_content );
1991 + } else {
1992 + // phpcs:ignore -- WP Filesystem fileing for large files
1993 + file_put_contents( $file_path, $new_content, FILE_APPEND );
1781 1994 }
1995 + } else {
1996 + // Use WP Filesystem to append
1997 + if ( ! $wp_filesystem->exists( $file_path ) ) {
1998 + $wp_filesystem->put_contents( $file_path, $new_content, FS_CHMOD_FILE );
1999 + } else {
2000 + // Read current contents
2001 + $current_contents = $wp_filesystem->get_contents( $file_path );
2002 + if ( $current_contents === false ) {
2003 + // Handle error if reading fails
2004 + return false;
2005 + }
2006 + // Append new content
2007 + $updated_contents = $current_contents . $new_content;
2008 + // Write back updated contents
2009 + if ( ! $wp_filesystem->put_contents( $file_path, $updated_contents, FS_CHMOD_FILE ) ) {
2010 + // Handle error if writing fails
2011 + return false;
2012 + }
2013 + }
2014 + }
2015 + return true;
2016 + };
2017 +
2018 + // Write the initial output to the file
2019 + if ( ! $append_content( $initial_output ) ) {
2020 + return false; // Handle error if initial content writing fails
2021 + }
2022 +
2023 + $sub_limit = 500;
2024 + // phpcs:ignore
2025 + $check_count = $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" );
2026 + $check_count = intval( $check_count );
2027 +
2028 + if ( $check_count > $sub_limit ) {
2029 + $t_sub_queries = ceil( $check_count / $sub_limit );
2030 +
2031 + for ( $sub_i = 0; $sub_i < $t_sub_queries; $sub_i++ ) {
2032 + $sub_offset = $sub_i * $sub_limit;
2033 + $sub_result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$table}` LIMIT %d OFFSET %d", array( $sub_limit, $sub_offset ) ), ARRAY_A ); // phpcs:ignore
2034 +
2035 + if ( $sub_result ) {
2036 + $output = '';
2037 + foreach ( $sub_result as $row ) {
2038 + $output .= 'INSERT INTO ' . $table . ' VALUES(';
2039 + $result_o_index = count( $row );
2040 + $j = 0;
2041 + foreach ( $row as $key => $value ) {
2042 + $row[ $key ] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $value, $table, $key ) );
2043 + $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2044 + if ( $j < ( $result_o_index - 1 ) ) {
2045 + $output .= ',';
2046 + }
2047 + $j++;
2048 + }
2049 + $output .= ");\n";
2050 + }
2051 + // Append to the file
2052 + if ( ! $append_content( $output ) ) {
2053 + return false; // Handle error if appending content fails
2054 + }
2055 + }
1782 2056 sleep(1);
1783 2057 }
1784 - }
1785 - else{
1786 - $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i",array($table)), ARRAY_A ); // phpcs:ignore
1787 - }
1788 -
1789 -
1790 - $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1791 - $output .= "\n\n" . $row2[1] . ";\n\n";
1792 - $result_count = count( $result );
1793 - for ( $i = 0; $i < $result_count; $i++ ) {
1794 - $row = $result[ $i ];
1795 - $output .= 'INSERT INTO ' . $table . ' VALUES(';
1796 - $result_o_index = count( $result[0] );
1797 - $j=0;
1798 - if(!empty($row)){
1799 - foreach ($row as $key => $value) {
1800 - $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1801 - $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2058 + } else {
2059 + $result = $wpdb->get_results( "SELECT * FROM `{$table}`", ARRAY_A ); // phpcs:ignore
2060 +
2061 + $output = '';
2062 + foreach ( $result as $row ) {
2063 + $output .= 'INSERT INTO ' . $table . ' VALUES(';
2064 + $result_o_index = count( $row );
2065 + $j = 0;
2066 + foreach ( $row as $key => $value ) {
2067 + $row[ $key ] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $value, $table, $key ) );
2068 + $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
1802 2069 if ( $j < ( $result_o_index - 1 ) ) {
1803 2070 $output .= ',';
1804 2071 }
1805 2072 $j++;
1806 2073 }
2074 + $output .= ");\n";
1807 2075 }
1808 - $output .= ");\n";
2076 + // Append to the file
2077 + if ( ! $append_content( $output ) ) {
2078 + return false; // Handle error if appending content fails
1809 2079 }
1810 - $output .= "\n";
1811 -
1812 - sleep(1);
1813 -
2080 + }
2081 +
2082 + // Flush the database cache
1814 2083 $wpdb->flush();
1815 -
1816 - return $output;
2084 + return true;
1817 2085 }
2086 +
1818 2087
1819 2088 /**
1820 2089 * Mysql Dump set path.
1821 2090 *
@@ -2053,9 +2322,9 @@
2053 2322
2054 2323 // If there are mysqldump errors delete the database dump file as mysqldump will still have written one.
2055 2324 if ( $this->get_errors( $this->get_mysqldump_method() ) && file_exists( $sql_filename ) ) {
2056 2325 if ( file_exists( $sql_filename ) ) {
2057 - unlink( $sql_filename );
2326 + wp_delete_file( $sql_filename );
2058 2327 }
2059 2328 }
2060 2329
2061 2330 // If we have an empty file delete it.
@@ -2060,9 +2329,9 @@
2060 2329
2061 2330 // If we have an empty file delete it.
2062 2331 if ( 0 === filesize( $sql_filename ) ) {
2063 2332 if ( file_exists( $sql_filename ) ) {
2064 - unlink( $sql_filename );
2333 + wp_delete_file( $sql_filename );
2065 2334 }
2066 2335 }
2067 2336
2068 2337 // If the file still exists then it must be good.
@@ -2108,31 +2377,43 @@
2108 2377 $source_directory = $this->wp_db_backup_wp_config_path();
2109 2378
2110 2379 $path_info = wp_upload_dir();
2111 2380 $htasses_text = '';
2381 + global $wpdb,$wp_filesystem;
2382 + if ( ! function_exists( 'WP_Filesystem' ) ) {
2383 + require_once ABSPATH . '/wp-admin/includes/file.php';
2384 + }
2385 + WP_Filesystem();
2386 +
2387 + if(!$wp_filesystem){
2388 + return false;
2389 + }
2390 +
2112 2391 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR);
2113 2392 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log');
2114 - fclose(fopen($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/index.php', 'w'));
2115 - fclose(fopen($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/index.php', 'w'));
2393 + $file_contents = "<?php\n// Silence is golden.\n";
2394 +
2395 + // Create the file with the given contents
2396 + $wp_filesystem->put_contents( $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/index.php', $file_contents, FS_CHMOD_FILE );
2397 + $wp_filesystem->put_contents( $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/index.php', $file_contents, FS_CHMOD_FILE );
2398 +
2399 +
2116 2400 // Added htaccess file 08-05-2015 for prevent directory listing.
2117 2401 // Fixed Vulnerability 22-06-2016 for prevent direct download.
2118 - if ( 1 === (int) get_option( 'wp_db_backup_enable_htaccess' ) ) {
2119 - $f = fopen( $path_info['basedir'] . '/db-backup/.htaccess', 'w' ); // phpcs:ignore
2120 - fwrite( // phpcs:ignore
2121 - $f,
2122 - '#These next two lines will already exist in your .htaccess file
2123 - RewriteEngine On
2124 - RewriteBase /
2125 - # Add these lines right after the preceding two
2126 - RewriteCond %{REQUEST_FILENAME} ^.*(.zip)$
2127 - RewriteCond %{HTTP_COOKIE} !^.*can_download.*$ [NC]
2128 - RewriteRule . - [R=403,L]'
2129 - ); // phpcs:ignore
2130 - fclose( $f ); // phpcs:ignore
2131 - }
2402 +
2403 + $htaccess_content = '# Disable public access to this folder
2404 +<IfModule mod_authz_core.c>
2405 + Require all denied
2406 +</IfModule>
2407 +
2408 +<IfModule !mod_authz_core.c>
2409 + Deny from all
2410 +</IfModule>';
2411 + $wp_filesystem->put_contents( $path_info['basedir'] . '/db-backup/.htaccess', $htaccess_content, FS_CHMOD_FILE );
2412 +
2132 2413 // Begin : Generate SQL DUMP and save to file database.sql.
2133 - $wp_site_name = preg_replace( '/[^A-Za-z0-9\_]/', '_', get_bloginfo( 'name' ) );
2134 - $wp_db_file_name = $wp_site_name . '_' . date( 'Y_m_d' ) . '_' . time() . '_' . substr( md5( AUTH_KEY ), 0, 7 ) . '_wpdb';
2414 + $wp_site_name = preg_replace('/[^\p{L}\p{M}]+/u', '_', get_bloginfo('name'));
2415 + $wp_db_file_name = $wp_site_name . '_' . gmdate( 'Y_m_d' ) . '_' . time() . '_' . substr( md5( wp_rand(100,9999999) ), 0, 9 ) . '_wpdb';
2135 2416 $sql_filename = $wp_db_file_name . '.sql';
2136 2417 $filename = $wp_db_file_name . '.zip';
2137 2418 $logname = $wp_db_file_name . '.txt';
2138 2419
@@ -2149,25 +2430,27 @@
2149 2430 if ( 1 === (int) $my_sql_dump ) {
2150 2431 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2151 2432 $options_backup = get_option( 'wp_db_backup_backups' );
2152 2433 $settings_backup = get_option( 'wp_db_backup_options' );
2153 - delete_option( 'wp_db_backup_backups' );
2154 - delete_option( 'wp_db_backup_options' );
2434 + $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
2435 + if($wp_db_save_settings_in_backup){
2436 + delete_option( 'wp_db_backup_backups' );
2437 + delete_option( 'wp_db_backup_options' );
2438 + }
2155 2439 /* END : Prevent saving backup plugin settings in the database dump */
2156 - global $wpdb;
2440 + //phpcs:ignore -- using direct query get all tables name to be backedup.
2157 2441 $tables = $wpdb->get_col( 'SHOW TABLES' );
2158 2442 $wp_db_exclude_table = get_option( 'wp_db_exclude_table',array());
2159 2443 if(!empty($tables)){
2160 2444 foreach($tables as $table){
2161 2445 if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
2162 - $handle = fopen( $path_info['basedir'] . '/db-backup/' . $sql_filename, 'a' ); // phpcs:ignore
2163 - fwrite( $handle, $this->wp_db_backup_create_mysql_backup_new($table) ); // phpcs:ignore
2164 - fclose( $handle ); // phpcs:ignore
2165 -
2446 + $this->wp_db_backup_create_mysql_backup_new($table, $path_info['basedir'] . '/db-backup/' . $sql_filename );
2166 2447 }
2167 2448 }
2449 +
2168 2450 }
2169 2451 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2452 + $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
2170 2453 add_option( 'wp_db_backup_backups', $options_backup );
2171 2454 add_option( 'wp_db_backup_options', $settings_backup );
2172 2455 /* END : Prevent saving backup plugin settings in the database dump */
2173 2456 }
@@ -2177,10 +2460,10 @@
2177 2460 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
2178 2461 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
2179 2462 $filecontent = wp_remote_get( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2180 2463 if (! is_wp_error( $filecontent ) && isset($filecontent['body']) ) {
2181 - $backup_str = str_replace( $wp_db_backup_search_text, $wp_db_backup_replace_text, $filecontent['body'] ); // phpcs:ignore
2182 - file_put_contents( $path_info['basedir'] . '/db-backup/' . $sql_filename, $backup_str ); // phpcs:ignore
2464 + $backup_str = str_replace( $wp_db_backup_search_text, $wp_db_backup_replace_text, $filecontent['body'] );
2465 + $wp_filesystem->put_contents( $path_info['basedir'] . '/db-backup/' . $sql_filename, $backup_str, FS_CHMOD_FILE );
2183 2466 }
2184 2467 }
2185 2468
2186 2469 /* End : Generate SQL DUMP and save to file database.sql */
@@ -2206,9 +2489,9 @@
2206 2489 // Create the archive.
2207 2490 $v_list = $archive->create( $v_dir, PCLZIP_OPT_REMOVE_PATH, $v_remove );
2208 2491 }
2209 2492
2210 - global $wpdb;
2493 +
2211 2494 $mysqlversion = wp_cache_get( 'wpdb_mysqlversion' );
2212 2495 if ( true === empty( $mysqlversion ) ) {
2213 2496 $mysqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' ); // phpcs:ignore
2214 2497 wp_cache_set( 'wpdb_mysqlversion', $mysqlversion, '', 18000 );
@@ -2244,14 +2527,14 @@
2244 2527 if ( ! ( $number_of_existing_backups < $number_of_backups_from_user ) ) {
2245 2528 $diff = $number_of_existing_backups - $number_of_backups_from_user;
2246 2529 for ( $i = 0; $i <= $diff; $i++ ) {
2247 2530 $index = $i;
2248 - if ( file_exists( $options[ $index ]['dir'] ) ) {
2249 - unlink( $options[ $index ]['dir'] );
2531 + if ( isset($options[ $index ]['dir']) && file_exists( $options[ $index ]['dir'] ) ) {
2532 + wp_delete_file( $options[ $index ]['dir'] );
2250 2533 }
2251 2534 $file_sql = explode( '.', $options[ $index ]['dir'] );
2252 - if ( file_exists( $file_sql[0] . '.sql' ) ) {
2253 - unlink( $file_sql[0] . '.sql' );
2535 + if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) {
2536 + wp_delete_file( $file_sql[0] . '.sql' );
2254 2537 }
2255 2538 }
2256 2539 for ( $i = ( $diff + 1 ); $i < $number_of_existing_backups; $i++ ) {
2257 2540 $index = $i;
@@ -2257,8 +2540,9 @@
2257 2540 $index = $i;
2258 2541
2259 2542 $newoptions[] = $options[ $index ];
2260 2543 }
2544 + $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
2261 2545
2262 2546 update_option( 'wp_db_backup_backups', $newoptions , false);
2263 2547 }
2264 2548 }
@@ -2263,9 +2547,9 @@
2263 2547 }
2264 2548 }
2265 2549
2266 2550 if ( file_exists( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) {
2267 - unlink( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2551 + wp_delete_file( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2268 2552 }
2269 2553 return $upload_path;
2270 2554 }
2271 2555
@@ -2294,15 +2578,20 @@
2294 2578 * Backup Process.
2295 2579 */
2296 2580 public function wp_db_backup_event_process() {
2297 2581 // Added in v.3.9.5!
2582 + global $wp_filesystem;
2583 + if(!function_exists('WP_Filesystem')){
2584 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
2585 + }
2586 + WP_Filesystem();
2298 2587
2299 2588 $cron_condition = apply_filters('wpdbbkp_dbback_cron_condition',true );
2300 2589 if(wp_doing_cron() && !$cron_condition){
2301 - wp_die();
2590 + return false;
2302 2591 }
2303 2592
2304 - set_time_limit( 0 );
2593 + set_time_limit( 0 ); //phpcs:ignore -- increase time limit for backup process.
2305 2594 ignore_user_abort(true);
2306 2595
2307 2596 $details = $this->wp_db_backup_create_archive();
2308 2597 $options = get_option( 'wp_db_backup_backups' );
@@ -2341,22 +2630,15 @@
2341 2630 'type' =>'database',
2342 2631 'destination' => $args[4]
2343 2632 );
2344 2633 if ( 1 !== (int) $wp_db_remove_local_backup ) {
2634 + $options = wpdbbkp_filter_unique_filenames( $options );
2345 2635 update_option( 'wp_db_backup_backups', $options , false);
2346 2636 }
2347 2637 if(isset($details['log_dir']) && !empty($details['log_dir']))
2348 2638 {
2349 - if (is_writable($details['log_dir']) || !file_exists($details['log_dir'])) {
2350 -
2351 - if ($handle = @fopen($details['log_dir'], 'a'))
2352 - {
2353 - if (fwrite($handle, str_replace(array("<br>","<b>","</b>"), array("\n","",""), $args[2])))
2354 - {
2355 - fclose($handle);
2356 - }
2357 - }
2358 -
2639 + if ($wp_filesystem->is_writable($details['log_dir']) || file_exists($details['log_dir'])) {
2640 + $wp_filesystem->put_contents( $details['log_dir'], str_replace(array("<br>","<b>","</b>"), array("\n","",""), $args[2]), FS_CHMOD_FILE );
2359 2641 }
2360 2642 }
2361 2643 }
2362 2644
@@ -2393,11 +2675,22 @@
2393 2675 * Schedular activation.
2394 2676 */
2395 2677 public function wp_db_backup_scheduler_activation() {
2396 2678 $options = get_option( 'wp_db_backup_options' );
2397 - if ( ( ! wp_next_scheduled( 'wp_db_backup_event' ) ) && ( true === isset( $options['enable_autobackups'] ) ) ) {
2679 + if ( ( ! wp_next_scheduled( 'wpdbbkp_db_backup_event' ) ) && ( true === isset( $options['enable_autobackups'] ) ) ) {
2398 2680 $cron_freq = apply_filters( 'wpdbbkp_dbback_cron_frequency',$options['autobackup_frequency']);
2399 - wp_schedule_event( time(), $cron_freq, 'wp_db_backup_event' );
2681 + if(isset($options['autobackup_type']) && $options['autobackup_type'] == 'db')
2682 + {
2683 + $timestamp = strtotime('today 23:59'); // Start at the next midnight
2684 + wp_schedule_event( $timestamp , $cron_freq, 'wpdbbkp_db_backup_event' );
2685 +
2686 + }
2687 + }else{
2688 + if( !empty($options) && ( false === isset( $options['enable_autobackups'] ) ) || ( true === isset( $options['enable_autobackups'] ) ) && isset($options['autobackup_type']) && $options['autobackup_type'] != 'db')
2689 + {
2690 + wp_clear_scheduled_hook( 'wpdbbkp_db_backup_event' );
2691 + }
2692 +
2400 2693 }
2401 2694 }
2402 2695
2403 2696 /**
@@ -2406,9 +2699,9 @@
2406 2699 * @param string $key - key name.
2407 2700 */
2408 2701 public function wp_backup_get_config_data( $key ) {
2409 2702 $filepath = get_home_path() . '/wp-config.php';
2410 - $config_file = file_get_contents( "$filepath", true );
2703 + $config_file = @file_get_contents( "$filepath", true );
2411 2704 if($config_file){
2412 2705 switch ( $key ) {
2413 2706 case 'DB_NAME':
2414 2707 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
@@ -2434,9 +2727,9 @@
2434 2727 * Get db name from config.
2435 2728 */
2436 2729 public function wp_backup_get_config_db_name() {
2437 2730 $filepath = get_home_path() . '/wp-config.php';
2438 - $config_file = file_get_contents( "$filepath", true );
2731 + $config_file = @file_get_contents( "$filepath", true );
2439 2732 if($config_file){
2440 2733 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2441 2734 return $matches[1];
2442 2735 }
@@ -2450,8 +2743,11 @@
2450 2743 *
2451 2744 * @return mixed
2452 2745 */
2453 2746 public function recursive_sanitize_text_field( $array ) {
2747 + if( ! is_array( $array ) ) {
2748 + return sanitize_text_field( $array );
2749 + }
2454 2750 foreach ( $array as $key => &$value ) {
2455 2751 if ( is_array( $value ) ) {
2456 2752 $value = $this->recursive_sanitize_text_field( $value );
2457 2753 } else {
@@ -2509,8 +2805,11 @@
2509 2805 {
2510 2806 wp_register_script('wpdbbkp-admin-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin.js', array('jquery'), WPDB_VERSION, 'true' );
2511 2807 wp_localize_script('wpdbbkp-admin-script', 'wpdbbkp_script_vars', array(
2512 2808 'nonce' => wp_create_nonce( 'wpdbbkp-admin-nonce' ),
2809 + 'siteurl' => base64_encode(site_url( )),
2810 + 'ud'=>wpdbbkp_get_current_user_name_email(),
2811 + 'is_subscribed'=>wpdbbkp_if_remote_active(),
2513 2812 ));
2514 2813 wp_enqueue_script('wpdbbkp-admin-script');
2515 2814
2516 2815 // Adding custom js
@@ -2537,10 +2836,12 @@
2537 2836 $post_type = $current_screen->post_type;
2538 2837 }
2539 2838
2540 2839 $post_id = get_the_ID();
2840 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2541 2841 if(isset($_GET['tag_ID'])){
2542 - $post_id = intval($_GET['tag_ID']);
2842 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2843 + $post_id = intval($_GET['tag_ID']);
2543 2844 }
2544 2845
2545 2846
2546 2847
@@ -2601,9 +2902,9 @@
2601 2902
2602 2903 if ( ! isset( $_POST['wpdbbkp_security_nonce'] ) ){
2603 2904 return;
2604 2905 }
2605 - if ( !wp_verify_nonce( $_POST['wpdbbkp_security_nonce'], 'wpdbbkp-admin-nonce' ) ){
2906 + if ( !wp_verify_nonce( wp_unslash($_POST['wpdbbkp_security_nonce']), 'wpdbbkp-admin-nonce' ) ){ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- used as nonce
2606 2907 return;
2607 2908 }
2608 2909
2609 2910 if( ! current_user_can( 'manage_options' ) ) {
@@ -2609,10 +2910,10 @@
2609 2910 if( ! current_user_can( 'manage_options' ) ) {
2610 2911 return;
2611 2912 }
2612 2913
2613 - $message = $this->wpdbbkp_sanitize_textarea_field($_POST['message']);
2614 - $email = $this->wpdbbkp_sanitize_textarea_field($_POST['email']);
2914 + $message = isset($_POST['message']) ? $this->wpdbbkp_sanitize_textarea_field(wp_unslash($_POST['message'])) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized using custom function
2915 + $email = isset($_POST['email']) ? $this->wpdbbkp_sanitize_textarea_field(wp_unslash($_POST['email'])) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized using custom function
2615 2916
2616 2917 if(function_exists('wp_get_current_user')){
2617 2918
2618 2919 $user = wp_get_current_user();
@@ -2651,9 +2952,9 @@
2651 2952 wp_die();
2652 2953 }
2653 2954 public function add_settings_plugin_action_wp( $actions, $plugin_file, $plugin_data, $context ) {
2654 2955 $plugin_actions['settings'] = sprintf(
2655 - '<a href="%s">' . _x( 'Settings', 'wpdbbkp' ) . '</a>',
2956 + '<a href="%s">' . _x( 'Settings', 'Content translation' ,'wpdbbkp' ) . '</a>',
2656 2957 admin_url( 'options-general.php?page=wp-database-backup' )
2657 2958 );
2658 2959 $actions = array_merge( $actions, $plugin_actions );
2659 2960 return $actions;
@@ -2662,10 +2963,10 @@
2662 2963 public function wpdbbkp_update_backup_info($FileName, $logFile, $logMessage = '') {
2663 2964 $path_info = wp_upload_dir();
2664 2965 $filename = $FileName . '.sql';
2665 2966 $WPDBFileName = $FileName . '.zip';
2666 - @unlink($this->wp_db_backup_wp_config_path() . '/' . $filename);
2667 - @unlink($this->wp_db_backup_wp_config_path() . '/wp_installer.php');
2967 + wp_delete_file($this->wp_db_backup_wp_config_path() . '/' . $filename);
2968 + wp_delete_file($this->wp_db_backup_wp_config_path() . '/wp_installer.php');
2668 2969 @$filesize = filesize($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName);
2669 2970
2670 2971 $upload_path = array(
2671 2972 'filename' => ($WPDBFileName),
@@ -2689,18 +2990,16 @@
2689 2990 }
2690 2991
2691 2992 private function write_log($logFile, $logMessage) {
2692 2993 // Actually write the log file
2693 - if (is_writable($logFile) || !file_exists($logFile)) {
2994 + global $wp_filesystem;
2995 + if(!function_exists('WP_Filesystem')){
2996 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
2997 + }
2998 + WP_Filesystem();
2694 2999
2695 - if (!$handle = @fopen($logFile, 'a'))
2696 - return;
2697 -
2698 - if (!fwrite($handle, $logMessage))
2699 - return;
2700 -
2701 - fclose($handle);
2702 -
3000 + if ($wp_filesystem && $wp_filesystem->is_writable($logFile) || !$wp_filesystem->exists($logFile)) {
3001 + $wp_filesystem->put_contents( $logFile, $logMessage, FS_CHMOD_FILE );
2703 3002 return true;
2704 3003 }
2705 3004 }
2706 3005
@@ -2761,12 +3060,11 @@
2761 3060 }
2762 3061
2763 3062 // Zip up $this->root without excludes
2764 3063 else {
2765 - // error_log('without exclude rule');
3064 +
2766 3065 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' 2>&1');
2767 3066 }
2768 - error_log($stderr);
2769 3067 if (!empty($stderr))
2770 3068 $this->warning($this->get_archive_method(), $stderr);
2771 3069
2772 3070 return $this->verify_archive($WPDBFileName);
@@ -2782,9 +3080,9 @@
2782 3080
2783 3081 public function set_root($path) {
2784 3082
2785 3083 if (empty($path) || !is_string($path) || !is_dir($path))
2786 - throw new Exception('Invalid root path <code>' . $path . '</code> must be a valid directory path');
3084 + throw new Exception('Invalid root path <code>' . esc_html($path) . '</code> must be a valid directory path');
2787 3085
2788 3086 $this->root = self::conform_dir($path);
2789 3087 }
2790 3088
@@ -2833,56 +3131,59 @@
2833 3131 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
2834 3132 }
2835 3133
2836 3134 $excludes = explode("|", $excludes);
2837 - foreach ($excludes as $key => &$rule) {
3135 + if(!empty($excludes) && is_array($excludes)){
3136 + foreach ($excludes as $key => &$rule) {
2838 3137
2839 - $file = $absolute = $fragment = false;
3138 + $file = $absolute = $fragment = false;
3139 +
3140 + // Files don't end with /
3141 + if (!in_array(substr($rule, -1), array('\\', '/')))
3142 + $file = true;
3143 +
3144 + // If rule starts with a / then treat as absolute path
3145 + elseif (in_array(substr($rule, 0, 1), array('\\', '/')))
3146 + $absolute = true;
3147 +
3148 + // Otherwise treat as dir fragment
3149 + else
3150 + $fragment = true;
3151 +
3152 + // Strip $this->root and conform
3153 + $rule = str_ireplace($this->get_root(), '', untrailingslashit(self::conform_dir($rule)));
3154 +
3155 + // Strip the preceeding slash
3156 + if (in_array(substr($rule, 0, 1), array('\\', '/')))
3157 + $rule = substr($rule, 1);
3158 +
3159 + // Escape string for regex
3160 + if ($context === 'regex')
3161 + $rule = str_replace('.', '\.', $rule);
3162 +
3163 + // Convert any existing wildcards
3164 + if ($wildcard !== '*' && strpos($rule, '*') !== false)
3165 + $rule = str_replace('*', $wildcard, $rule);
3166 +
3167 + // Wrap directory fragments and files in wildcards for zip
3168 + if ($context === 'zip' && ( $fragment || $file ))
3169 + $rule = $wildcard . $rule . $wildcard;
3170 +
3171 + // Add a wildcard to the end of absolute url for zips
3172 + if ($context === 'zip' && $absolute)
3173 + $rule .= $wildcard;
3174 +
3175 + // Add and end carrot to files for pclzip but only if it doesn't end in a wildcard
3176 + if ($file && $context === 'regex')
3177 + $rule .= '$';
3178 +
3179 + // Add a start carrot to absolute urls for pclzip
3180 + if ($absolute && $context === 'regex')
3181 + $rule = '^' . $rule;
3182 + }
3183 + }
3184 +
2840 3185
2841 - // Files don't end with /
2842 - if (!in_array(substr($rule, -1), array('\\', '/')))
2843 - $file = true;
2844 -
2845 - // If rule starts with a / then treat as absolute path
2846 - elseif (in_array(substr($rule, 0, 1), array('\\', '/')))
2847 - $absolute = true;
2848 -
2849 - // Otherwise treat as dir fragment
2850 - else
2851 - $fragment = true;
2852 -
2853 - // Strip $this->root and conform
2854 - $rule = str_ireplace($this->get_root(), '', untrailingslashit(self::conform_dir($rule)));
2855 -
2856 - // Strip the preceeding slash
2857 - if (in_array(substr($rule, 0, 1), array('\\', '/')))
2858 - $rule = substr($rule, 1);
2859 -
2860 - // Escape string for regex
2861 - if ($context === 'regex')
2862 - $rule = str_replace('.', '\.', $rule);
2863 -
2864 - // Convert any existing wildcards
2865 - if ($wildcard !== '*' && strpos($rule, '*') !== false)
2866 - $rule = str_replace('*', $wildcard, $rule);
2867 -
2868 - // Wrap directory fragments and files in wildcards for zip
2869 - if ($context === 'zip' && ( $fragment || $file ))
2870 - $rule = $wildcard . $rule . $wildcard;
2871 -
2872 - // Add a wildcard to the end of absolute url for zips
2873 - if ($context === 'zip' && $absolute)
2874 - $rule .= $wildcard;
2875 -
2876 - // Add and end carrot to files for pclzip but only if it doesn't end in a wildcard
2877 - if ($file && $context === 'regex')
2878 - $rule .= '$';
2879 -
2880 - // Add a start carrot to absolute urls for pclzip
2881 - if ($absolute && $context === 'regex')
2882 - $rule = '^' . $rule;
2883 - }
2884 -
2885 3186 // Escape shell args for zip command
2886 3187 if ($context === 'zip')
2887 3188 $excludes = array_map('escapeshellarg', array_unique($excludes));
2888 3189
@@ -2899,9 +3200,9 @@
2899 3200 return true;
2900 3201
2901 3202 // If there are errors delete the backup file.
2902 3203 if ($this->get_errors($this->get_archive_method()) && file_exists($WPDBFileName))
2903 - unlink($WPDBFileName);
3204 + wp_delete_file($WPDBFileName);
2904 3205
2905 3206 // If the archive file still exists assume it's good
2906 3207 if (file_exists($WPDBFileName))
2907 3208 return $this->archive_verified = true;
@@ -2936,8 +3237,10 @@
2936 3237 }
2937 3238
2938 3239 public function wpdbbkp_get_timeago( $time )
2939 3240 {
3241 + $time = intval($time) > 0 ? intval($time) : time();
3242 +
2940 3243 $time_difference = time() - $time;
2941 3244
2942 3245 if( $time_difference < 1 ) { return 'less than 1 second ago'; }
2943 3246 $condition = array( 12 * 30 * 24 * 60 * 60 => 'year',
@@ -2955,8 +3258,122 @@
2955 3258 if( $d >= 1 )
2956 3259 {
2957 3260 $t = floor( $d );
2958 3261 return 'About ' . $t . ' ' . $str . ( $t > 1 ? 's' : '' ) . ' ago';
3262 + }
3263 + }
3264 + }
3265 +
3266 + private function wpdbbkp_append_to_file($file_path, $content_to_append){
3267 + global $wp_filesystem;
3268 +
3269 + if (!function_exists('WP_Filesystem')) {
3270 + require_once ABSPATH . 'wp-admin/includes/file.php';
3271 + }
3272 +
3273 +
3274 + if (empty($wp_filesystem)) {
3275 + WP_Filesystem();
3276 + }
3277 +
3278 + if (!$wp_filesystem) {
3279 + return false;
3280 + }
3281 +
3282 + // Check if the file exists
3283 + if ($wp_filesystem->exists($file_path)) {
3284 + // Open the file in append mode
3285 + $handle = $wp_filesystem->get_contents($file_path);
3286 +
3287 + if ($handle) {
3288 + // Append the new content
3289 + $result = $wp_filesystem->put_contents($file_path, $handle . $content_to_append, FS_CHMOD_FILE);
3290 + return $result !== false;
3291 + }
3292 + } else {
3293 + // If the file doesn't exist, create it with the initial content
3294 + $result = $wp_filesystem->put_contents($file_path, $content_to_append, FS_CHMOD_FILE);
3295 + return $result !== false;
3296 + }
3297 +
3298 + return false;
3299 + }
3300 +
3301 + public function wpdbbkp_cloudbackup_notice(){
3302 + $user_id = get_current_user_id();
3303 + $wpdbbkp_cloudbackup_notice = get_option( 'wpdb_clouddrive_token', false );
3304 +
3305 + if( $wpdbbkp_cloudbackup_notice ){
3306 + return;
3307 + }
3308 + if ( ! current_user_can( 'manage_options' ) ) {
3309 + return;
3310 + }
3311 +
3312 + if ( get_user_meta( $user_id, 'wpdbbkp_cloudbackup_notice_dismissed', true ) ) {
3313 + return;
3314 + }
3315 +
3316 + $nonce = wp_create_nonce( 'wpdbbkp_cloudbackup_notice_dismissed' )
3317 + ?>
3318 + <div class="notice notice-info is-dismissible" id="wpdbbkp_cloudbackup_dismiss">
3319 + <p><?php echo esc_html__('Take a free 14-day trial of BackupforWP Cloud Backup.', 'wpdbbkp').'<a href="'.esc_url('https://backupforwp.com/register?from=plugin_notice').'" target="_blank">'.esc_html__('Get Started in 2 Minutes.', 'wpdbbkp'). '</a>';?></p>
3320 + </div>
3321 + <script type="text/javascript">
3322 + jQuery(document).ready(function($) {
3323 + // Handle dismiss action
3324 + $(document).on('click', '#wpdbbkp_cloudbackup_dismiss .notice-dismiss', function() {
3325 + var ajaxurl = "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>";
3326 + $.post(ajaxurl, {
3327 + action: 'wpdbbkp_cloudbackup_dismiss_notice',
3328 + nonce: '<?php echo esc_js( $nonce ); ?>'
3329 + });
3330 + });
3331 + });
3332 + </script>
3333 + <?php
3334 + }
3335 + public function wpdbbkp_cloudbackup_dismiss_notice() {
3336 +
3337 +
3338 + if ( ! current_user_can( 'manage_options' ) ) {
3339 + wp_die( esc_html__( 'Permission denied', 'wpdbbkp' ), '', [ 'response' => 403 ] );
3340 + }
3341 +
3342 + // Verify the nonce
3343 + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['nonce'] ), 'wpdbbkp_cloudbackup_notice_dismissed' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- using as nonce
3344 + wp_die( esc_html__( 'Invalid nonce', 'wpdbbkp' ), '', [ 'response' => 403 ] );
3345 + }
3346 +
3347 + $user_id = get_current_user_id();
3348 + update_user_meta( $user_id, 'wpdbbkp_cloudbackup_notice_dismissed', 1 );
3349 + wp_die();
3350 + }
3351 +
3352 + public function admin_backup_file_download() {
3353 + if ( ! current_user_can( 'manage_options' ) ) {
3354 + return;
3355 + }
3356 +
3357 + // Check for a specific query parameter, e.g., ?download_backup=filename.zip
3358 + if ( isset( $_GET['wpdbbkp_download'] ) && ! empty( $_GET['wpdbbkp_download'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
3359 + $path_info = wp_upload_dir();
3360 + $backup_dir = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/';
3361 + $file_name = basename( sanitize_text_field( wp_unslash( $_GET['wpdbbkp_download'] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
3362 + $file_path = trailingslashit( $backup_dir ) . $file_name;
3363 +
3364 +
3365 + // Check if file exists
3366 + if ( file_exists( $file_path ) ) {
3367 + // Serve the file
3368 + header( 'Content-Description: File Transfer' );
3369 + header( 'Content-Type: application/octet-stream' );
3370 + header( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
3371 + header( 'Content-Length: ' . filesize( $file_path ) );
3372 + readfile( $file_path ); //phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- readfile is used to read the file with buffer
3373 + exit;
3374 + } else {
3375 + wp_die( esc_html__( 'Backup file not found.', 'wpdbbkp' ) );
2959 3376 }
2960 3377 }
2961 3378 }
2962 3379