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 +998 -601 6.117.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 }
@@ -213,8 +180,13 @@
213 180 update_option( 'wp_db_remove_local_backup', 1 , false);
214 181 } else {
215 182 update_option( 'wp_db_remove_local_backup', 0 , false);
216 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 + }
217 189 if ( isset( $_POST['wp_db_backup_enable_auto_upgrade'] ) ) {
218 190 update_option( 'wp_db_backup_enable_auto_upgrade', 1 , false);
219 191 } else {
220 192 update_option( 'wp_db_backup_enable_auto_upgrade', 0 , false);
@@ -219,18 +191,8 @@
219 191 } else {
220 192 update_option( 'wp_db_backup_enable_auto_upgrade', 0 , false);
221 193 }
222 194
223 - if ( isset( $_POST['wp_db_backup_enable_htaccess'] ) ) {
224 - update_option( 'wp_db_backup_enable_htaccess', 1 , false);
225 - } else {
226 - update_option( 'wp_db_backup_enable_htaccess', 0 , false);
227 - $path_info = wp_upload_dir();
228 - if ( file_exists( $path_info['basedir'] . '/db-backup/.htaccess' ) ) {
229 - unlink( $path_info['basedir'] . '/db-backup/.htaccess' );
230 - }
231 - }
232 -
233 195 if ( isset( $_POST['wp_db_exclude_table'] ) ) {
234 196 update_option( 'wp_db_exclude_table', $this->recursive_sanitize_text_field( wp_unslash( $_POST['wp_db_exclude_table'] ) ) , false); // phpcs:ignore
235 197 } else {
236 198 update_option( 'wp_db_exclude_table', '', false );
@@ -259,12 +221,71 @@
259 221 }
260 222 }
261 223
262 224 if ( isset( $_POST['wp_db_backup_options'] ) ) {
263 - 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 +
264 251 }
265 252
266 - 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 +
267 288 }
268 289 $wp_db_backup_destination_email = get_option( 'wp_db_backup_destination_Email' , false);
269 290
270 291 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && isset( $_GET['action'] ) && 'unlink' === $_GET['action'] ) {
@@ -277,9 +298,9 @@
277 298 $file = readdir( $dir_handle );
278 299 while ( $file ) {
279 300 // If $file is NOT a directory remove it.
280 301 if ( ! is_dir( $file ) ) {
281 - unlink( $dir . $file );
302 + wp_delete_file( $dir . $file );
282 303 }
283 304 }
284 305 // Close the directory.
285 306 closedir( $dir_handle );
@@ -298,14 +319,17 @@
298 319 $index = (int) $_GET['index'];
299 320 $options = get_option( 'wp_db_backup_backups' );
300 321 $newoptions = array();
301 322 $count = 0;
302 - foreach ( $options as $option ) {
303 - if ( $count !== $index ) {
304 - $newoptions[] = $option;
323 + if(!empty($options) && is_array($options)){
324 + foreach ( $options as $option ) {
325 + if ( $count !== $index ) {
326 + $newoptions[] = $option;
327 + }
328 + $count++;
305 329 }
306 - $count++;
307 330 }
331 +
308 332 $upload_dir = wp_upload_dir();
309 333 $actual_working_directory = getcwd();
310 334 $file_directory = $upload_dir['basedir'].'/db-backup/';
311 335 /*
@@ -311,16 +335,20 @@
311 335 /*
312 336 Fix for when you try to delete a file thats in a folder
313 337 higher in the hierarchy to your working directory */
314 338 chdir($file_directory);
315 - if ( file_exists( $options[ $index ]['filename'] ) ) {
316 - unlink( $options[ $index ]['filename'] );
339 + if ( isset($options[ $index ]['filename']) && file_exists( $options[ $index ]['filename'] ) ) {
340 + wp_delete_file( $options[ $index ]['filename'] );
317 341 }
318 - $file_sql = explode( '.', $options[ $index ]['filename'] );
319 - if ( file_exists( $file_sql[0] . '.sql' ) ) {
320 - 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 + }
321 347 }
348 +
322 349 chdir($actual_working_directory);
350 + $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
323 351 update_option( 'wp_db_backup_backups', $newoptions , false);
324 352 $nonce = wp_create_nonce( 'wp-database-backup' );
325 353 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=delete&_wpnonce=' . $nonce );
326 354 exit;
@@ -331,8 +359,9 @@
331 359
332 360 $upload_dir = wp_upload_dir();
333 361 $actual_working_directory = getcwd();
334 362 $file_directory = $upload_dir['basedir'];
363 + global $wpdb;
335 364 /*
336 365 Fix for when you try to delete a file thats in a folder
337 366 higher in the hierarchy to your working directory
338 367 */
@@ -339,16 +368,20 @@
339 368 chdir($file_directory);
340 369 $files = glob($file_directory.'/db-backup'.'/*');
341 370
342 371 // Deleting all the files in the list
343 - foreach($files as $file) {
344 - if(is_file($file)){
345 - unlink($file);
346 - }
347 - }
372 + if(!empty($files)){
373 + foreach($files as $file) {
374 + if(is_file($file)){
375 + wp_delete_file($file);
376 + }
377 + }
378 + }
348 379 chdir($actual_working_directory);
349 380 update_option( 'wp_db_backup_backups', array() , false);
350 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
351 384 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=deleteall&_wpnonce=' . $nonce );
352 385 exit;
353 386
354 387
@@ -357,10 +390,15 @@
357 390 $options = get_option( 'wp_db_backup_backups' );
358 391 $newoptions = array();
359 392 $backup_check_list = array( '.htaccess', 'index.php' );
360 393 $delete_message = 'WPDB : Deleted Files:';
361 - foreach ( $options as $option ) {
362 - $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 + }
363 401 }
364 402 $path_info = wp_upload_dir();
365 403 $wp_db_backup_path = $path_info['basedir'] . '/db-backup';
366 404
@@ -370,9 +408,9 @@
370 408 if ( $dh ) {
371 409 while ( false !== ($file = readdir( $dh )) ) {
372 410 if ( ! ( in_array( $file, $backup_check_list, true ) ) ) {
373 411 if ( file_exists( $wp_db_backup_path . '/' . $file ) ) {
374 - unlink( $wp_db_backup_path . '/' . $file );
412 + wp_delete_file( $wp_db_backup_path . '/' . $file );
375 413 }
376 414 $delete_message .= ' ' . $file;
377 415 }
378 416 }
@@ -382,18 +420,20 @@
382 420 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=clear_temp_db_backup_file&_wpnonce=' . $nonce );
383 421 exit;
384 422 break;
385 423 case 'restorebackup':
386 - $index = (int) $_GET['index'];
424 + $index = isset($_GET['index'])?(int) $_GET['index']:0;
387 425 $options = get_option( 'wp_db_backup_backups' );
388 426 $restore_limit = get_option( 'wp_db_restore_limit');
389 427 $newoptions = array();
390 428 $count = 0;
391 - foreach ( $options as $option ) {
392 - if ( $count !== $index ) {
393 - $newoptions[] = $option;
429 + if(!empty($options) && is_array($options)){
430 + foreach ( $options as $option ) {
431 + if ( $count !== $index ) {
432 + $newoptions[] = $option;
433 + }
434 + $count++;
394 435 }
395 - $count++;
396 436 }
397 437 if ( isset( $options[ $index ]['restore_limit'] ) && $options[ $index ]['restore_limit']==1) {
398 438 include_once ABSPATH . 'wp-admin/includes/plugin.php';
399 439 if ( !is_plugin_active( 'wp-database-backup-pro/wp-database-backup-pro.php' ) ) {
@@ -406,11 +446,14 @@
406 446
407 447 if ( isset( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
408 448 $database_file = ( $options[ $index ]['sqlfile'] );
409 449 } else {
410 - $database_file = ( $options[ $index ]['dir'] );
411 - $file_sql = explode( '.', $options[ $index ]['dir'] );
412 - $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 +
413 456 }
414 457 $database_name = $this->wp_backup_get_config_db_name();
415 458 $database_user = $this->wp_backup_get_config_data( 'DB_USER' );
416 459 $datadase_password = $this->wp_backup_get_config_data( 'DB_PASSWORD' );
@@ -436,71 +479,85 @@
436 479 }
437 480 }
438 481
439 482 // End for extract zip file V.3.3.0.
440 - set_time_limit( 0 );
483 + set_time_limit( 0 ); // phpcs:ignore -- needed for long running process
441 484 ignore_user_abort(true);
442 - if ( '' !== ( trim( (string) $database_name ) ) && '' !== ( trim( (string) $database_user ) ) && '' !== ( trim( (string) $database_host ) ) ) {
443 - $conn = mysqli_connect( (string) $database_host, (string) $database_user, (string) $datadase_password ); // phpcs:ignore
444 - if ( $conn ) {
445 - // Start Select the database.
446 - if ( ! mysqli_select_db( $conn, (string) $database_name) ) { // phpcs:ignore
447 - $sql = 'CREATE DATABASE IF NOT EXISTS `' . (string) $database_name . '`';
448 - mysqli_query($conn, $sql); // phpcs:ignore
449 - 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));
450 508 }
451 - /* END: Select the Database */
452 -
453 - /* BEGIN: Remove All Tables from the Database */
454 - $found_tables = null;
455 - $result = mysqli_query( $conn, 'SHOW TABLES FROM `' . (string) $database_name . '`' ); // phpcs:ignore
456 -
457 - if ( $result ) {
458 - while ($row = mysqli_fetch_row($result)) {
459 - $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';
460 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))) {
461 528
462 - if ( count( $found_tables ) > 0 ) {
463 - foreach ( $found_tables as $table_name ) {
464 - mysqli_query( $conn, "DROP TABLE " . (string) $database_name . ".".$table_name ); // phpcs:ignore
465 - }
466 - }
467 - }
468 -
469 - /* END: Remove All Tables from the Database */
470 -
471 - /* BEGIN: Restore Database Content */
472 - if ( isset( $database_file ) ) {
473 - if ( file_exists( $database_file ) ) {
474 - $sql_file = file_get_contents( $database_file, true );
475 - if($sql_file){
476 - $sql_queries = explode( ";\n", $sql_file );
477 - $sql_queries_count = count( $sql_queries );
478 -
479 - mysqli_query($conn, "SET sql_mode = ''");
480 -
481 - for ( $i = 0; $i < $sql_queries_count; $i++ ) {
482 - $sql_query_=apply_filters( 'wpdbbkp_sql_query_restore', $sql_queries[ $i ] );
483 - mysqli_query($conn, $sql_query_ ); // phpcs:ignore
484 - }
485 - }
486 -
487 - }
488 - }
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 + }
489 539 }
490 540 }
491 541
492 542 if ( isset( $options[ $index ]['sqlfile'] ) && file_exists( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
493 543 if ( file_exists( $options[ $index ]['sqlfile'] ) ) {
494 - unlink( $options[ $index ]['sqlfile'] );
544 + wp_delete_file( $options[ $index ]['sqlfile'] );
495 545 }
496 546 } else {
497 - $database_file = ( $options[ $index ]['dir'] );
498 - $file_sql = explode( '.', $options[ $index ]['dir'] );
499 - $database_file = ( $file_sql[0] . '.sql' );
500 - if ( file_exists( $database_file ) ) {
501 - 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 +
502 558 }
559 +
503 560 }
504 561 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
505 562 exit;
506 563 break;
@@ -506,18 +563,24 @@
506 563 break;
507 564
508 565 case 'wpdbbkrestorefullbackup':
509 566 $index = (int) $_GET['index'];
510 - require_once( 'class-restore.php' );
511 - $restore = new Wpbp_Restore();
567 + require_once( 'class-wpdbbkp-restore.php' );
568 + $restore = new Wpdbbkp_Restore();
512 569 $restore->start($index);
513 570 if (get_option('wp_db_log') == 1) {
514 571 $options = get_option('wp_db_backup_backups');
515 572 $path_info = wp_upload_dir();
516 - $logFileName = explode(".", $options[$index]['filename']);
517 - $logfile = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $logFileName[0] . '.txt';
518 - $message = "\n\n Restore Backup at " . date("Y-m-d h:i:sa");
519 - $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 +
520 583 }
521 584 $nonce = wp_create_nonce( 'wp-database-backup' );
522 585 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
523 586 exit;
@@ -548,12 +611,19 @@
548 611 /**
549 612 * Setting page.
550 613 */
551 614 public function wp_db_backup_settings_page() {
552 -
615 + global $wp_filesystem;
616 + if(!function_exists('WP_Filesystem')){
617 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
618 + }
619 + WP_Filesystem();
620 +
553 621 $options = get_option( 'wp_db_backup_backups' );
622 + $options = wpdbbkp_filter_unique_filenames( $options );
554 623 $settings = get_option( 'wp_db_backup_options' );
555 - $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); ?>
556 626 <div class="bootstrap-wrapper">
557 627 <?php
558 628 $wp_db_local_backup_path = get_option( 'wp_db_local_backup_path' );
559 629 if ( false === empty( $wp_db_local_backup_path ) && false === file_exists( $wp_db_local_backup_path ) ) {
@@ -559,10 +629,10 @@
559 629 if ( false === empty( $wp_db_local_backup_path ) && false === file_exists( $wp_db_local_backup_path ) ) {
560 630 echo '<div class="alert alert-warning alert-dismissible fade in" role="alert">
561 631 <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
562 632 <a href="#db_destination" data-toggle="tab">';
563 - esc_attr_e( 'Invalid Local Backup Path : ', 'wp-database-backup' );
564 - 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 );
565 635 echo '</a></div>';
566 636 }
567 637
568 638 $upload_dir = wp_upload_dir();
@@ -569,9 +639,9 @@
569 639 $dir = $upload_dir['basedir'] . '/db-backup';
570 640 if ( ! is_dir( $dir ) ) {
571 641 $dir = $upload_dir['basedir'];
572 642 }
573 - if ( is_dir( $dir ) && ! is_writable( $dir ) ) {
643 + if ( is_dir( $dir ) && !$wp_filesystem->is_writable( $dir )) {
574 644 ?>
575 645 <div class="row">
576 646 <div class="col-xs-12 col-sm-12 col-md-12">
577 647 <div class="alert alert-danger alert-dismissible fade in" role="alert">
@@ -576,11 +646,11 @@
576 646 <div class="col-xs-12 col-sm-12 col-md-12">
577 647 <div class="alert alert-danger alert-dismissible fade in" role="alert">
578 648 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
579 649 <span aria-hidden="true">×</span></button>
580 - <h4>WP Database Backup</h4>
581 - <p>Error: Permission denied, make sure you have write permission for <?php echo esc_attr( $dir ); ?>
582 - 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>
583 653 </div>
584 654 </button>
585 655 </div>
586 656 </div>
@@ -586,8 +656,10 @@
586 656 </div>
587 657 <?php
588 658 }
589 659 ?>
660 +
661 +
590 662
591 663 <div id="wpdbbkpModal" class="modal">
592 664 <div class="wpdbbkpmodal-content">
593 665 <div class="wpdbbkp-modal-header">
@@ -610,17 +682,18 @@
610 682 </div>
611 683 <div class="panel-body">
612 684 <ul class="nav nav-tabs wbdbbkp_has_nav">
613 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>
614 687 <li><a href="#db_schedul" data-toggle="tab"><?php echo esc_html__('Auto Scheduler', 'wpdbbkp') ?></a></li>
615 688 <li><a href="#db_destination" data-toggle="tab"><?php echo esc_html__('Save Backups to', 'wpdbbkp') ?></a></li>
616 689 <li><a href="#db_setting" data-toggle="tab"><?php echo esc_html__('Settings', 'wpdbbkp') ?></a></li>
617 - <li><a href="#searchreplace" data-toggle="tab"><?php echo esc_html__('Search and Replace', 'wpdbbkp') ?></a></li>
618 - <li style="display:none"><a href="#db_upgrade" data-toggle="tab"><?php echo esc_html__('Upgrade', 'wpdbbkp') ?></a></li>
619 - <?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>
620 693 <li><a href="#db_help" data-toggle="tab"><?php echo esc_html__('Help &amp; Support', 'wpdbbkp') ?></a></li>
621 - <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>
622 694
695 +
623 696 </ul>
624 697
625 698 <?php
626 699 echo '<div class="tab-content">';
@@ -639,9 +712,9 @@
639 712 }
640 713 include_once 'admin-header-notification.php'; ?>
641 714
642 715 <?php
643 - if ( $options ) {
716 + if ( !empty($options) ) {
644 717
645 718 echo ' <script>
646 719 var $j = jQuery.noConflict();
647 720 $j(document).ready(function () {
@@ -649,14 +722,8 @@
649 722 var table = $j("#wpdbbkp_table").DataTable({
650 723 order: [[0, "desc"]],
651 724 });
652 725 $j(".popoverid").popover();
653 - $j("#create_backup").click(function() {
654 - $j(".wpdbbkp_notification").hide();
655 - $j("#backup_process").show();
656 - $j("#create_backup").attr("disabled", true);
657 -
658 - });
659 726 });
660 727
661 728 function excludetableall(){
662 729 var checkboxes = document.getElementsByClassName("wp_db_exclude_table");
@@ -667,9 +734,8 @@
667 734 $j(".wp_db_exclude_table").each(function() {
668 735 this.checked = checked;
669 736 });
670 737 }
671 -
672 738 </script>';
673 739 echo ' <div class="table-responsive">
674 740 <div id="wpdbbkp_dataTables" class="dataTables_wrapper form-inline" role="grid">
675 741
@@ -700,72 +766,89 @@
700 766 'S3' => 'glyphicon glyphicon-cloud-upload',
701 767 'Drive' => 'glyphicon glyphicon-hdd',
702 768 'DropBox' => 'glyphicon glyphicon-inbox',
703 769 'Backblaze' => 'glyphicon glyphicon-cloud-upload',
770 + 'CloudDrive' => 'glyphicon glyphicon-cloud-upload'
704 771 );
705 - foreach ( $options as $option ) {
706 - $str_class = ( 0 === (int) $option['size'] ) ? 'text-danger' : 'wpdb_download';
707 - echo '<tr class="' . ( ( 0 === ( $count % 2 ) ) ? esc_attr( $str_class ) . ' alternate' : esc_attr( $str_class ) ) . '">';
708 - echo '<td style="text-align: center;">' . esc_attr( $count ) . '</td>';
709 - $curr_date = new DateTime(date( 'Y-m-d H:i:s', $option['date'] ));
710 - $curr_date->setTimezone(new DateTimeZone(wp_timezone_string()));
711 - 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>';
712 - echo '</td>';
713 - if($wp_db_log==1){
714 - echo '<td class="wpdb_log" align="center">';
715 - if (!empty($option['log'])) {
716 - if(isset($option['type']) && ($option['type'] == 'complete' || $option['type'] == 'database')){
717 - echo '<a href="' . $option['log'] . '" target="_blank" class="label label-warning" title="There might be partial backup. Please check Log File for verify backup.">';
718 - echo '<span class="glyphicon glyphicon-list-alt"></span>';
719 - echo '</a>';
720 - }else{
721 - 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;
722 776 }
723 - }
724 - echo '</td>';
725 - }
726 - echo '<td>';
727 - if ( ! empty( $option['destination'] ) ) {
728 - $destination = ( explode( ',', $option['destination'] ) );
729 - foreach ( $destination as $dest ) {
730 - $key = trim( $dest );
731 - if ( ! empty( $dest ) && array_key_exists( $key, $destination_icon ) ) {
732 - 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;
733 781 }
734 782 }
735 - }
736 - echo '</td>';
737 - if(isset($option['type']) && !empty($option['type'])){
738 - if($option['type'] == 'complete'){
739 - 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 + }
740 801 }
741 - if($option['type'] == 'database'){
742 - echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
802 + echo '</td>';
743 803 }
744 - }else{
745 - echo '<td>Database</td>';
746 - }
747 - echo '<td>';
748 - echo '<a class="btn btn-default" href="' . esc_url( $option['url'] ) . '" style="color: #21759B;border-color:#337ab7;">';
749 - echo '<span class="glyphicon glyphicon-download-alt"></span> Download</a></td>';
750 - echo '<td>' . esc_attr( $this->wp_db_backup_format_bytes( $option['size'] ) ) . '</td>';
751 - $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 ) );
752 - 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/> ';
753 - if ( isset( $option['search_replace'] ) && 1 === (int) $option['search_replace'] ) {
754 - echo '<span style="margin-left:15px" title="' . esc_html( $option['log'] ) . '" class="glyphicon glyphicon-search"></span>';
755 - } else {
756 - $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>';
757 818 if(isset($option['type']) && !empty($option['type'])){
758 819 if($option['type'] == 'complete'){
759 - $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>';
760 821 }
761 -
822 + if($option['type'] == 'database'){
823 + echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
824 + }
825 + }else{
826 + echo '<td>Database</td>';
762 827 }
763 - 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++;
764 848 }
765 - echo '</td></tr>';
766 - $count++;
767 849 }
850 +
768 851 echo '</tbody>';
769 852
770 853 echo ' </table>
771 854 </div>
@@ -832,164 +915,202 @@
832 915 echo '</p>';
833 916 echo '</form>';
834 917 echo '</div>';
835 918 echo '</div>';
919 +
836 920
921 +
837 922 do_action('wpdbbkp_pro_tab_content');
838 923
839 924 ?>
840 925
841 - <div class="tab-pane" id="db_upgrade">
842 - <div class="panel-group ">
843 - <div class="gn-flex-container row">
844 - <div class=" col-md-12">
845 - <div class="wpdbbkp-wrapper">
846 - <div class="wpdbbkp-wr">
847 - <div class="bkp-wpdbbkp-img">
848 - <span class="sp_ov"></span>
849 - </div>
850 - <div class="bkp-wpdbbkp-cnt">
851 - <h1><?php esc_html_e('UPGRADE to PRO Version','wpdbbkp');?></h1>
852 - <a class="buy" href="https://backupforwp.com/pricing/#pricings" target="_blank">Purchase Now</a>
853 - </div>
854 - <div class="pvf">
855 - <div class="pvf-cnt">
856 - <div class="pvf-tlt">
857 - <h2><?php esc_html_e('Compare Pro vs. Free Version','wpdbbkp');?></h2>
858 - <span><?php esc_html_e('See what you\'ll get with the professional version','wpdbbkp');?></span>
859 - </div>
860 - <div class="pvf-cmp">
861 - <div class="fr">
862 - <h1><?php esc_html_e('FREE','wpdbbkp');?></h1>
863 - <div class="fr-fe">
864 - <div class="fe-1">
865 - <h4><?php esc_html_e('Continious Development','wpdbbkp');?></h4>
866 - <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>
867 - </div>
868 - <div class="fe-1">
869 - <h4><?php esc_html_e('10+ Features','wpdbbkp');?></h4>
870 - <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>
871 - </div>
872 - </div><!-- /. fr-fe -->
873 - </div><!-- /. fr -->
874 - <div class="pr">
875 - <h1>PRO</h1>
876 - <div class="pr-fe">
877 - <span><?php esc_html_e('Everything in Free, and:','wpdbbkp');?></span>
878 - <div class="fet">
879 - <div class="fe-2">
880 - <div class="fe-t">
881 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
882 - <h4><?php esc_html_e('Anonymization Function','wpdbbkp');?></h4>
883 - </div>
884 - <p><?php esc_html_e('Anonymization you critical data during backup with three methods','wpdbbkp');?> </p>
885 - </div>
886 - <div class="fe-2">
887 - <div class="fe-t">
888 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
889 - <h4><?php esc_html_e('Pre-update backups','wpdbbkp');?></h4>
890 - </div>
891 - <p> <?php esc_html_e('Automatically backs up your website before any updates to plugins, themes and WordPress core.','wpdbbkp');?></p>
892 - </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">
893 966
894 - <div class="fe-2">
895 - <div class="fe-t">
896 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
897 - <h4><?php esc_html_e('Backup time and scheduling','wpdbbkp'); ?></h4>
898 - </div>
899 - <p><?php esc_html_e('Set exact times to create or delete backups.','wpdbbkp');?></p>
900 - </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>
901 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>
902 1019
903 - <div class="fe-2">
904 - <div class="fe-t">
905 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
906 - <h4><?php esc_html_e('Fast, personal support','wpdbbkp'); ?></h4>
907 - </div>
908 - <p><?php esc_html_e('Provides expert help and support from the developers whenever you need it.','wpdbbkp'); ?></p>
909 - </div>
910 - <div class="fe-2">
911 - <div class="fe-t">
912 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
913 - <h4><?php esc_html_e('Continuous Updates','wpdbbkp'); ?></h4>
914 - </div>
915 - <p><?php esc_html_e('We\'re continuously updating our premium features and releasing them.','wpdbbkp'); ?></p>
916 - </div>
917 - <div class="fe-2">
918 - <div class="fe-t">
919 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
920 - <h4><?php esc_html_e('Documentation','wpdbbkp'); ?></h4>
921 - </div>
922 - <p><?php esc_html_e('We create tutorials for every possible feature and keep it updated for you.','wpdbbkp'); ?></p>
923 - </div>
924 - </div><!-- /. fet -->
925 - <div class="pr-btn">
926 - <a href="https://backupforwp.com/pricing/#pricings" target="_blank"><?php esc_html_e('Upgrade to Pro','wpdbbkp'); ?></a>
927 - </div><!-- /. pr-btn -->
928 - </div><!-- /. pr-fe -->
929 - </div><!-- /.pr -->
930 - </div><!-- /. pvf-cmp -->
931 - </div><!-- /. pvf-cnt -->
932 -
933 - <div class="wpdbbkpfaq">
934 - <h2><?php esc_html_e('Frequently Asked Questions','wpdbbkp'); ?></h2>
935 - <div class="faq-lst">
936 - <div class="lt">
937 - <ul>
938 - <li>
939 - <span><?php esc_html_e('Is there a setup fee?','wpdbbkp'); ?></span>
940 - <p><?php esc_html_e('No. There are no setup fees on any of our plans','wpdbbkp'); ?></p>
941 - </li>
942 - <li>
943 - <span><?php esc_html_e('What\'s the time span for your contracts?','wpdbbkp'); ?></span>
944 - <p><?php esc_html_e('All the plans are year-to-year which are subscribed annually except for lifetime plan.','wpdbbkp'); ?></p>
945 - </li>
946 - <li>
947 - <span><?php esc_html_e('What payment methods are accepted?','wpdbbkp'); ?></span>
948 - <p><?php esc_html_e('We accepts PayPal and Credit Card payments.','wpdbbkp'); ?></p>
949 - </li>
950 - <li>
951 - <span><?php esc_html_e('Do you offer support if I need help?','wpdbbkp'); ?></span>
952 - <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>
953 - </li>
954 - <li>
955 - <span><?php esc_html_e('Can I use the plugins after my subscription is expired?','wpdbbkp'); ?></span>
956 - <p><?php esc_html_e('Yes, you can use the plugins, but you will not get future updates for those plugins.','wpdbbkp'); ?></p>
957 - </li>
958 - </ul>
959 - </div>
960 - <div class="rt">
961 - <ul>
962 - <li>
963 - <span><?php esc_html_e('Can I cancel my membership at any time?','wpdbbkp'); ?></span>
964 - <p><?php esc_html_e('Yes. You can cancel your membership by contacting us.','wpdbbkp'); ?></p>
965 - </li>
966 - <li>
967 - <span><?php esc_html_e('Can I change my plan later on?','wpdbbkp'); ?></span>
968 - <p><?php esc_html_e('Yes. You can upgrade your plan by contacting us.','wpdbbkp'); ?></p>
969 - </li>
970 - <li>
971 - <span><?php esc_html_e('Do you offer refunds?','wpdbbkp'); ?></span>
972 - <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>
973 - </li>
974 - <li>
975 - <span><?php esc_html_e('Do I get updates for the premium plugin?','wpdbbkp'); ?></span>
976 - <p><?php esc_html_e('Yes, you will get updates for all the premium plugins until your subscription is active.','wpdbbkp'); ?></p>
977 - </li>
978 - </ul>
979 - </div>
980 - </div><!-- /.faq-lst -->
981 - </div><!-- /.faq -->
982 - </div><!-- /. pvf -->
983 - </div>
984 - </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>
985 1091
986 - </div>
987 - </div>
988 - </div>
989 - </div>
990 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">
991 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>
992 1113 <div class="tab-pane" id="db_help">
993 1114 <div class="panel-group ">
994 1115 <div class="gn-flex-container row">
995 1116 <div class="wpdbbkp-left-side col-md-8">
@@ -999,9 +1120,9 @@
999 1120 <li>
1000 1121 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Email', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1001 1122 </label>
1002 1123 <div class="support-input">
1003 - <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="">
1004 1125 </div>
1005 1126 </li>
1006 1127 <li>
1007 1128 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
@@ -1006,9 +1127,9 @@
1006 1127 <li>
1007 1128 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1008 1129 </label>
1009 1130 <div class="support-input">
1010 - <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>
1011 1132 </div>
1012 1133 </li>
1013 1134 <li>
1014 1135 <button class="button button-primary wpdbbkp-send-query"> <?php echo esc_html__('Send Support Request', 'wpdbbkp') ?> </button>
@@ -1035,9 +1156,9 @@
1035 1156 <div class="panel panel-group panel-default">
1036 1157 <div class="panel-heading">
1037 1158 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedb">
1038 1159 <h4 class="panel-title">
1039 - <?php esc_attr_e( 'System Check', 'wpdbbk' ); ?>
1160 + <?php esc_attr_e( 'System Check', 'wpdbbkp' ); ?>
1040 1161 </h4>
1041 1162 </a>
1042 1163 </div>
1043 1164 <div id="collapsedb" class="panel-collapse collapse in">
@@ -1044,8 +1165,9 @@
1044 1165 <div class="panel-body list-group">
1045 1166
1046 1167 <div class="row list-group-item">
1047 1168 <?php
1169 + $df = $dt = $dp = $du = 'NA';
1048 1170 if(function_exists('disk_free_space')){
1049 1171 /* get disk space free (in bytes) */
1050 1172 $df = disk_free_space( WPDB_ROOTPATH );
1051 1173 /* and get disk space total (in bytes) */
@@ -1059,14 +1181,14 @@
1059 1181 $df = $this->wp_db_backup_format_bytes( $df );
1060 1182 $du = $this->wp_db_backup_format_bytes( $du );
1061 1183 $dt = $this->wp_db_backup_format_bytes( $dt );
1062 1184 }
1063 - $du=$dp=$df=$dt='NA';
1185 +
1064 1186 ?>
1065 1187 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1066 1188 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1067 1189 </div>
1068 - <div class="col-md-3">Disk Space</div>
1190 + <div class="col-md-12">Disk Space</div>
1069 1191 <div class="col-md-5">
1070 1192 <div class="progress">
1071 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 ); ?>%
1072 1194 </div>
@@ -1135,13 +1257,18 @@
1135 1257 <div class="row list-group-item">
1136 1258 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1137 1259 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1138 1260 </div>
1139 - <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>
1140 1262 <div class="col-md-5">
1141 1263 <?php
1142 1264 $upload_dir = wp_upload_dir();
1143 - 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();
1144 1271 ?>
1145 1272 </div>
1146 1273 <div class="col-md-3"></div>
1147 1274 </div>
@@ -1149,14 +1276,14 @@
1149 1276 <div class="row list-group-item">
1150 1277 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1151 1278 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1152 1279 </div>
1153 - <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>
1154 1281 <div class="col-md-5"><?php echo esc_attr( $upload_dir['basedir'] ); ?></div>
1155 1282 <div class="col-md-1">
1156 1283 <?php echo esc_attr( substr( sprintf( '%o', fileperms( $upload_dir['basedir'] ) ), -4 ) ); ?></div>
1157 1284 <div
1158 - 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>'; ?>
1159 1286 </div>
1160 1287 </div>
1161 1288
1162 1289 <div class="row list-group-item">
@@ -1174,10 +1301,9 @@
1174 1301 <div class="col-md-5">
1175 1302 <?php
1176 1303 echo esc_attr( WP_MEMORY_LIMIT );
1177 1304 echo '(Max &nbsp;' . esc_attr( WP_MAX_MEMORY_LIMIT );
1178 - ?>
1179 - )
1305 + ?> )
1180 1306 </div>
1181 1307 </div>
1182 1308
1183 1309
@@ -1184,9 +1310,9 @@
1184 1310 <div class="row list-group-item">
1185 1311 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1186 1312 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1187 1313 </div>
1188 - <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>
1189 1315 <div class="col-md-5"> <?php echo esc_attr( ini_get( 'max_execution_time' ) ); ?></div>
1190 1316 <div class="col-md-1"></div>
1191 1317 <div
1192 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>
@@ -1194,15 +1320,15 @@
1194 1320 <div class="row list-group-item">
1195 1321 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1196 1322 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1197 1323 </div>
1198 - <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>
1199 1325 <div
1200 1326 class="col-md-5"> <?php echo esc_attr( $upload_dir['basedir'] . '/db-backup' ); ?></div>
1201 1327 <div
1202 1328 class="col-md-1"><?php echo esc_attr( substr( sprintf( '%o', @fileperms( esc_attr( $upload_dir['basedir'] ) . '/db-backup' ) ), -4 ) ); ?></div>
1203 1329 <div
1204 - 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>
1205 1331 </div>
1206 1332
1207 1333 <div class="row list-group-item">
1208 1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
@@ -1207,9 +1333,9 @@
1207 1333 <div class="row list-group-item">
1208 1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1209 1335 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1210 1336 </div>
1211 - <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>
1212 1338 <div class="col-md-5">
1213 1339 <?php
1214 1340 echo ( class_exists( 'ZipArchive' ) ) ? 'Yes </p>' : '<p class="">No</p>';
1215 1341 ?>
@@ -1220,9 +1346,9 @@
1220 1346 <div class="row list-group-item">
1221 1347 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1222 1348 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1223 1349 </div>
1224 - <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>
1225 1351 <div class="col-md-5">
1226 1352 <?php
1227 1353 $wpdb_admin = new Wpdb_Admin();
1228 1354 echo ( $wpdb_admin->get_mysqldump_command_path() ) ? 'Yes </p>' : '<p class="">No</p>';
@@ -1399,14 +1525,17 @@
1399 1525 <th><?php echo esc_html__('Version', 'wpdbbkp') ?></th>
1400 1526 </tr>
1401 1527 <?php
1402 1528 $plugins = get_plugins();
1403 - foreach ( $plugins as $plugin ) {
1404 - echo '<tr>
1405 - <td>' . esc_attr( $plugin['Name'] ) . '</td>
1406 - <td>' . esc_attr( $plugin['Version'] ) . '</td>
1407 - </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 + }
1408 1536 }
1537 +
1409 1538 ?>
1410 1539 </table>
1411 1540 <table class="table table-condensed">
1412 1541 <tr class="success">
@@ -1491,8 +1620,10 @@
1491 1620 $checked = '';
1492 1621 }
1493 1622 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
1494 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);
1495 1626 if ( 1 === (int) $wp_db_remove_local_backup ) {
1496 1627 $remove_local_backup = 'checked';
1497 1628 } else {
1498 1629 $remove_local_backup = '';
@@ -1501,25 +1632,40 @@
1501 1632 $remove_on_uninstall = 'checked';
1502 1633 } else {
1503 1634 $remove_on_uninstall = '';
1504 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 + }
1505 1646 ?>
1506 1647 <form action="" method="post">
1507 1648 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1508 1649 <div class="input-group">
1509 1650 <span class="input-group-addon" id="sizing-addon2"><?php echo esc_html__('Maximum Local Backups', 'wpdbbkp') ?></span>
1510 - <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">
1511 1652
1512 - </div>
1513 - <div class="alert alert-default" role="alert">
1514 - <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
1515 1655 number of Local Database Backups that should be kept, regardless of their size.', 'wpdbbkp') ?></br>
1516 1656 <?php echo esc_html__('Leave blank for keep unlimited database backups.', 'wpdbbkp') ?>
1517 - </div>
1657 + </p>
1658 +
1518 1659 <hr>
1519 1660 <div class="input-group">
1520 1661 <label><input type="checkbox" <?php echo esc_attr( $checked ); ?> name="wp_db_log"> <?php echo esc_html__('Enable Log', 'wpdbbkp') ?></label>
1521 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 +
1522 1668 <hr>
1523 1669 <div class="input-group">
1524 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>
1525 1671 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
@@ -1531,14 +1677,21 @@
1531 1677 <div class="input-group">
1532 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>
1533 1679 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1534 1680 <?php echo esc_html__('If Checked then it will remove local backup.', 'wpdbbkp') ?>
1535 - <br><?php echo esc_html__('Use this option only when you have set any destination.', 'wpdbbkp') ?>
1536 - <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') ?>
1537 1683 </p>
1538 1684 </div>
1539 1685 <hr>
1540 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">
1541 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>
1542 1695 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1543 1696 <?php echo esc_html__('If Checked then it will delete all backup files and options when plugin is uninstalled', 'wpdbbkp') ?>
1544 1697
@@ -1543,15 +1696,18 @@
1543 1696 <?php echo esc_html__('If Checked then it will delete all backup files and options when plugin is uninstalled', 'wpdbbkp') ?>
1544 1697
1545 1698 </p>
1546 1699 </div>
1547 - <hr>
1700 +
1548 1701 <?php
1549 1702 $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removeallbackup&_wpnonce=' . esc_attr( $nonce ); ?>
1550 1703
1551 1704 <div class="input-group">
1552 - <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>
1553 - <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 +
1554 1710
1555 1711 </div>
1556 1712 <hr>
1557 1713 <div class="panel panel-default">
@@ -1635,15 +1791,15 @@
1635 1791 </p>
1636 1792 <br>
1637 1793 <div class="input-group">
1638 1794 <span class="input-group-addon" id="wp_db_backup_search_text"><?php echo esc_html__('Search For', 'wpdbbkp') ?></span>
1639 - <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">
1640 1796
1641 1797 </div>
1642 1798 <br>
1643 1799 <div class="input-group">
1644 1800 <span class="input-group-addon" id="wp_db_backup_replace_text"><?php echo esc_html__('Replace With', 'wpdbbkp') ?></span>
1645 - <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">
1646 1802
1647 1803 </div>
1648 1804
1649 1805 <div class="alert alert-default" role="alert">
@@ -1650,10 +1806,10 @@
1650 1806 <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1651 1807 <?php echo esc_html__("Leave blank those fields if you don't want use this feature and want only regular Database backup.", 'wpdbbkp') ?>
1652 1808 <br>
1653 1809 <?php echo esc_html__('Ex:', 'wpdbbkp') ?>
1654 - <br><?php echo esc_html__('Search For:', 'wpdbbkp') ?> http://localhost/wordpress/
1655 - <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') ?>
1656 1812
1657 1813 <br><br>
1658 1814 <?php echo esc_html__('Note - This is Search & Replace data in your WordPress Database Backup File not in current Database installation.', 'wpdbbkp') ?>
1659 1815
@@ -1717,63 +1873,79 @@
1717 1873 global $wpdb;
1718 1874 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1719 1875 $options_backup = get_option( 'wp_db_backup_backups' );
1720 1876 $settings_backup = get_option( 'wp_db_backup_options' );
1721 - delete_option( 'wp_db_backup_backups' );
1722 - 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 + }
1723 1882 /* END : Prevent saving backup plugin settings in the database dump */
1724 1883 $wp_db_exclude_table = array();
1725 1884 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
1726 1885 $tables = $wpdb->get_col( 'SHOW TABLES' ); // phpcs:ignore
1727 1886 $output = '';
1728 - foreach ( $tables as $table ) {
1729 - if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
1730 -
1731 - $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1732 - $check_count = intval($check_count);
1733 - $sub_limit =500;
1734 - if(isset($check_count) && $check_count>$sub_limit){
1735 - $result =array();
1736 - $t_sub_queries= ceil($check_count/$sub_limit);
1737 - for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1738 - {
1739 - $sub_offset = $sub_i*$sub_limit;
1740 - $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i LIMIT %d OFFSET %d",array($table,$sub_limit,$sub_offset)), ARRAY_A );
1741 - if($sub_result){
1742 - $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);
1743 1910 }
1744 - sleep(1);
1745 1911 }
1746 - }
1747 - else{
1748 - $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i",array($table)), ARRAY_A ); // phpcs:ignore
1749 - }
1750 -
1751 -
1752 - $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1753 - $output .= "\n\n" . $row2[1] . ";\n\n";
1754 - $result_count = count( $result );
1755 - for ( $i = 0; $i < $result_count; $i++ ) {
1756 - $row = $result[ $i ];
1757 - $output .= 'INSERT INTO ' . $table . ' VALUES(';
1758 - $result_o_index = count( $result[0] );
1759 - $j=0;
1760 - foreach ($row as $key => $value) {
1761 - $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1762 - $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
1763 - if ( $j < ( $result_o_index - 1 ) ) {
1764 - $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";
1765 1935 }
1766 - $j++;
1936 +
1767 1937 }
1768 - $output .= ");\n";
1938 + $output .= "\n";
1769 1939 }
1770 - $output .= "\n";
1940 + sleep(1);
1771 1941 }
1772 - sleep(1);
1942 +
1773 1943 }
1944 +
1774 1945 $wpdb->flush();
1775 1946 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1947 + $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
1776 1948 add_option( 'wp_db_backup_backups', $options_backup );
1777 1949 add_option( 'wp_db_backup_options', $settings_backup );
1778 1950 /* END : Prevent saving backup plugin settings in the database dump */
1779 1951 return $output;
@@ -1781,61 +1953,138 @@
1781 1953
1782 1954 /**
1783 1955 * Create database backup new function.
1784 1956 */
1785 - public function wp_db_backup_create_mysql_backup_new($table) {
1786 - global $wpdb;
1787 - $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
1788 1970
1789 - $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1790 - $check_count = intval($check_count);
1791 - $sub_limit =500;
1792 - if(isset($check_count) && $check_count>$sub_limit){
1793 - $result =array();
1794 - $t_sub_queries= ceil($check_count/$sub_limit);
1795 - for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1796 - {
1797 - $sub_offset = $sub_i*$sub_limit;
1798 - $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i LIMIT %d OFFSET %d",array($table,$sub_limit,$sub_offset)), ARRAY_A );
1799 - if($sub_result){
1800 - $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 );
1801 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 + }
1802 2056 sleep(1);
1803 2057 }
1804 - }
1805 - else{
1806 - $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i",array($table)), ARRAY_A ); // phpcs:ignore
1807 - }
1808 -
1809 -
1810 - $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1811 - $output .= "\n\n" . $row2[1] . ";\n\n";
1812 - $result_count = count( $result );
1813 - for ( $i = 0; $i < $result_count; $i++ ) {
1814 - $row = $result[ $i ];
1815 - $output .= 'INSERT INTO ' . $table . ' VALUES(';
1816 - $result_o_index = count( $result[0] );
1817 - $j=0;
1818 - if(!empty($row)){
1819 - foreach ($row as $key => $value) {
1820 - $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1821 - $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 ] . '"' : '""';
1822 2069 if ( $j < ( $result_o_index - 1 ) ) {
1823 2070 $output .= ',';
1824 2071 }
1825 2072 $j++;
1826 2073 }
2074 + $output .= ");\n";
1827 2075 }
1828 - $output .= ");\n";
2076 + // Append to the file
2077 + if ( ! $append_content( $output ) ) {
2078 + return false; // Handle error if appending content fails
1829 2079 }
1830 - $output .= "\n";
1831 -
1832 - sleep(1);
1833 -
2080 + }
2081 +
2082 + // Flush the database cache
1834 2083 $wpdb->flush();
1835 -
1836 - return $output;
2084 + return true;
1837 2085 }
2086 +
1838 2087
1839 2088 /**
1840 2089 * Mysql Dump set path.
1841 2090 *
@@ -2073,9 +2322,9 @@
2073 2322
2074 2323 // If there are mysqldump errors delete the database dump file as mysqldump will still have written one.
2075 2324 if ( $this->get_errors( $this->get_mysqldump_method() ) && file_exists( $sql_filename ) ) {
2076 2325 if ( file_exists( $sql_filename ) ) {
2077 - unlink( $sql_filename );
2326 + wp_delete_file( $sql_filename );
2078 2327 }
2079 2328 }
2080 2329
2081 2330 // If we have an empty file delete it.
@@ -2080,9 +2329,9 @@
2080 2329
2081 2330 // If we have an empty file delete it.
2082 2331 if ( 0 === filesize( $sql_filename ) ) {
2083 2332 if ( file_exists( $sql_filename ) ) {
2084 - unlink( $sql_filename );
2333 + wp_delete_file( $sql_filename );
2085 2334 }
2086 2335 }
2087 2336
2088 2337 // If the file still exists then it must be good.
@@ -2128,31 +2377,43 @@
2128 2377 $source_directory = $this->wp_db_backup_wp_config_path();
2129 2378
2130 2379 $path_info = wp_upload_dir();
2131 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 +
2132 2391 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR);
2133 2392 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log');
2134 - fclose(fopen($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/index.php', 'w'));
2135 - 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 +
2136 2400 // Added htaccess file 08-05-2015 for prevent directory listing.
2137 2401 // Fixed Vulnerability 22-06-2016 for prevent direct download.
2138 - if ( 1 === (int) get_option( 'wp_db_backup_enable_htaccess' ) ) {
2139 - $f = fopen( $path_info['basedir'] . '/db-backup/.htaccess', 'w' ); // phpcs:ignore
2140 - fwrite( // phpcs:ignore
2141 - $f,
2142 - '#These next two lines will already exist in your .htaccess file
2143 - RewriteEngine On
2144 - RewriteBase /
2145 - # Add these lines right after the preceding two
2146 - RewriteCond %{REQUEST_FILENAME} ^.*(.zip)$
2147 - RewriteCond %{HTTP_COOKIE} !^.*can_download.*$ [NC]
2148 - RewriteRule . - [R=403,L]'
2149 - ); // phpcs:ignore
2150 - fclose( $f ); // phpcs:ignore
2151 - }
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 +
2152 2413 // Begin : Generate SQL DUMP and save to file database.sql.
2153 2414 $wp_site_name = preg_replace('/[^\p{L}\p{M}]+/u', '_', get_bloginfo('name'));
2154 - $wp_db_file_name = $wp_site_name . '_' . date( 'Y_m_d' ) . '_' . time() . '_' . substr( md5( AUTH_KEY ), 0, 7 ) . '_wpdb';
2415 + $wp_db_file_name = $wp_site_name . '_' . gmdate( 'Y_m_d' ) . '_' . time() . '_' . substr( md5( wp_rand(100,9999999) ), 0, 9 ) . '_wpdb';
2155 2416 $sql_filename = $wp_db_file_name . '.sql';
2156 2417 $filename = $wp_db_file_name . '.zip';
2157 2418 $logname = $wp_db_file_name . '.txt';
2158 2419
@@ -2169,25 +2430,27 @@
2169 2430 if ( 1 === (int) $my_sql_dump ) {
2170 2431 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2171 2432 $options_backup = get_option( 'wp_db_backup_backups' );
2172 2433 $settings_backup = get_option( 'wp_db_backup_options' );
2173 - delete_option( 'wp_db_backup_backups' );
2174 - 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 + }
2175 2439 /* END : Prevent saving backup plugin settings in the database dump */
2176 - global $wpdb;
2440 + //phpcs:ignore -- using direct query get all tables name to be backedup.
2177 2441 $tables = $wpdb->get_col( 'SHOW TABLES' );
2178 2442 $wp_db_exclude_table = get_option( 'wp_db_exclude_table',array());
2179 2443 if(!empty($tables)){
2180 2444 foreach($tables as $table){
2181 2445 if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
2182 - $handle = fopen( $path_info['basedir'] . '/db-backup/' . $sql_filename, 'a' ); // phpcs:ignore
2183 - fwrite( $handle, $this->wp_db_backup_create_mysql_backup_new($table) ); // phpcs:ignore
2184 - fclose( $handle ); // phpcs:ignore
2185 -
2446 + $this->wp_db_backup_create_mysql_backup_new($table, $path_info['basedir'] . '/db-backup/' . $sql_filename );
2186 2447 }
2187 2448 }
2449 +
2188 2450 }
2189 2451 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2452 + $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
2190 2453 add_option( 'wp_db_backup_backups', $options_backup );
2191 2454 add_option( 'wp_db_backup_options', $settings_backup );
2192 2455 /* END : Prevent saving backup plugin settings in the database dump */
2193 2456 }
@@ -2197,10 +2460,10 @@
2197 2460 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
2198 2461 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
2199 2462 $filecontent = wp_remote_get( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2200 2463 if (! is_wp_error( $filecontent ) && isset($filecontent['body']) ) {
2201 - $backup_str = str_replace( $wp_db_backup_search_text, $wp_db_backup_replace_text, $filecontent['body'] ); // phpcs:ignore
2202 - 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 );
2203 2466 }
2204 2467 }
2205 2468
2206 2469 /* End : Generate SQL DUMP and save to file database.sql */
@@ -2226,9 +2489,9 @@
2226 2489 // Create the archive.
2227 2490 $v_list = $archive->create( $v_dir, PCLZIP_OPT_REMOVE_PATH, $v_remove );
2228 2491 }
2229 2492
2230 - global $wpdb;
2493 +
2231 2494 $mysqlversion = wp_cache_get( 'wpdb_mysqlversion' );
2232 2495 if ( true === empty( $mysqlversion ) ) {
2233 2496 $mysqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' ); // phpcs:ignore
2234 2497 wp_cache_set( 'wpdb_mysqlversion', $mysqlversion, '', 18000 );
@@ -2264,14 +2527,14 @@
2264 2527 if ( ! ( $number_of_existing_backups < $number_of_backups_from_user ) ) {
2265 2528 $diff = $number_of_existing_backups - $number_of_backups_from_user;
2266 2529 for ( $i = 0; $i <= $diff; $i++ ) {
2267 2530 $index = $i;
2268 - if ( file_exists( $options[ $index ]['dir'] ) ) {
2269 - unlink( $options[ $index ]['dir'] );
2531 + if ( isset($options[ $index ]['dir']) && file_exists( $options[ $index ]['dir'] ) ) {
2532 + wp_delete_file( $options[ $index ]['dir'] );
2270 2533 }
2271 2534 $file_sql = explode( '.', $options[ $index ]['dir'] );
2272 - if ( file_exists( $file_sql[0] . '.sql' ) ) {
2273 - 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' );
2274 2537 }
2275 2538 }
2276 2539 for ( $i = ( $diff + 1 ); $i < $number_of_existing_backups; $i++ ) {
2277 2540 $index = $i;
@@ -2277,8 +2540,9 @@
2277 2540 $index = $i;
2278 2541
2279 2542 $newoptions[] = $options[ $index ];
2280 2543 }
2544 + $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
2281 2545
2282 2546 update_option( 'wp_db_backup_backups', $newoptions , false);
2283 2547 }
2284 2548 }
@@ -2283,9 +2547,9 @@
2283 2547 }
2284 2548 }
2285 2549
2286 2550 if ( file_exists( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) {
2287 - unlink( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2551 + wp_delete_file( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2288 2552 }
2289 2553 return $upload_path;
2290 2554 }
2291 2555
@@ -2314,15 +2578,20 @@
2314 2578 * Backup Process.
2315 2579 */
2316 2580 public function wp_db_backup_event_process() {
2317 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();
2318 2587
2319 2588 $cron_condition = apply_filters('wpdbbkp_dbback_cron_condition',true );
2320 2589 if(wp_doing_cron() && !$cron_condition){
2321 - wp_die();
2590 + return false;
2322 2591 }
2323 2592
2324 - set_time_limit( 0 );
2593 + set_time_limit( 0 ); //phpcs:ignore -- increase time limit for backup process.
2325 2594 ignore_user_abort(true);
2326 2595
2327 2596 $details = $this->wp_db_backup_create_archive();
2328 2597 $options = get_option( 'wp_db_backup_backups' );
@@ -2361,22 +2630,15 @@
2361 2630 'type' =>'database',
2362 2631 'destination' => $args[4]
2363 2632 );
2364 2633 if ( 1 !== (int) $wp_db_remove_local_backup ) {
2634 + $options = wpdbbkp_filter_unique_filenames( $options );
2365 2635 update_option( 'wp_db_backup_backups', $options , false);
2366 2636 }
2367 2637 if(isset($details['log_dir']) && !empty($details['log_dir']))
2368 2638 {
2369 - if (is_writable($details['log_dir']) || !file_exists($details['log_dir'])) {
2370 -
2371 - if ($handle = @fopen($details['log_dir'], 'a'))
2372 - {
2373 - if (fwrite($handle, str_replace(array("<br>","<b>","</b>"), array("\n","",""), $args[2])))
2374 - {
2375 - fclose($handle);
2376 - }
2377 - }
2378 -
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 );
2379 2641 }
2380 2642 }
2381 2643 }
2382 2644
@@ -2413,11 +2675,22 @@
2413 2675 * Schedular activation.
2414 2676 */
2415 2677 public function wp_db_backup_scheduler_activation() {
2416 2678 $options = get_option( 'wp_db_backup_options' );
2417 - 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'] ) ) ) {
2418 2680 $cron_freq = apply_filters( 'wpdbbkp_dbback_cron_frequency',$options['autobackup_frequency']);
2419 - 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 +
2420 2693 }
2421 2694 }
2422 2695
2423 2696 /**
@@ -2426,9 +2699,9 @@
2426 2699 * @param string $key - key name.
2427 2700 */
2428 2701 public function wp_backup_get_config_data( $key ) {
2429 2702 $filepath = get_home_path() . '/wp-config.php';
2430 - $config_file = file_get_contents( "$filepath", true );
2703 + $config_file = @file_get_contents( "$filepath", true );
2431 2704 if($config_file){
2432 2705 switch ( $key ) {
2433 2706 case 'DB_NAME':
2434 2707 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
@@ -2454,9 +2727,9 @@
2454 2727 * Get db name from config.
2455 2728 */
2456 2729 public function wp_backup_get_config_db_name() {
2457 2730 $filepath = get_home_path() . '/wp-config.php';
2458 - $config_file = file_get_contents( "$filepath", true );
2731 + $config_file = @file_get_contents( "$filepath", true );
2459 2732 if($config_file){
2460 2733 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2461 2734 return $matches[1];
2462 2735 }
@@ -2470,8 +2743,11 @@
2470 2743 *
2471 2744 * @return mixed
2472 2745 */
2473 2746 public function recursive_sanitize_text_field( $array ) {
2747 + if( ! is_array( $array ) ) {
2748 + return sanitize_text_field( $array );
2749 + }
2474 2750 foreach ( $array as $key => &$value ) {
2475 2751 if ( is_array( $value ) ) {
2476 2752 $value = $this->recursive_sanitize_text_field( $value );
2477 2753 } else {
@@ -2529,8 +2805,11 @@
2529 2805 {
2530 2806 wp_register_script('wpdbbkp-admin-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin.js', array('jquery'), WPDB_VERSION, 'true' );
2531 2807 wp_localize_script('wpdbbkp-admin-script', 'wpdbbkp_script_vars', array(
2532 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(),
2533 2812 ));
2534 2813 wp_enqueue_script('wpdbbkp-admin-script');
2535 2814
2536 2815 // Adding custom js
@@ -2557,10 +2836,12 @@
2557 2836 $post_type = $current_screen->post_type;
2558 2837 }
2559 2838
2560 2839 $post_id = get_the_ID();
2840 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2561 2841 if(isset($_GET['tag_ID'])){
2562 - $post_id = intval($_GET['tag_ID']);
2842 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2843 + $post_id = intval($_GET['tag_ID']);
2563 2844 }
2564 2845
2565 2846
2566 2847
@@ -2621,9 +2902,9 @@
2621 2902
2622 2903 if ( ! isset( $_POST['wpdbbkp_security_nonce'] ) ){
2623 2904 return;
2624 2905 }
2625 - 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
2626 2907 return;
2627 2908 }
2628 2909
2629 2910 if( ! current_user_can( 'manage_options' ) ) {
@@ -2629,10 +2910,10 @@
2629 2910 if( ! current_user_can( 'manage_options' ) ) {
2630 2911 return;
2631 2912 }
2632 2913
2633 - $message = $this->wpdbbkp_sanitize_textarea_field($_POST['message']);
2634 - $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
2635 2916
2636 2917 if(function_exists('wp_get_current_user')){
2637 2918
2638 2919 $user = wp_get_current_user();
@@ -2671,9 +2952,9 @@
2671 2952 wp_die();
2672 2953 }
2673 2954 public function add_settings_plugin_action_wp( $actions, $plugin_file, $plugin_data, $context ) {
2674 2955 $plugin_actions['settings'] = sprintf(
2675 - '<a href="%s">' . _x( 'Settings', 'wpdbbkp' ) . '</a>',
2956 + '<a href="%s">' . _x( 'Settings', 'Content translation' ,'wpdbbkp' ) . '</a>',
2676 2957 admin_url( 'options-general.php?page=wp-database-backup' )
2677 2958 );
2678 2959 $actions = array_merge( $actions, $plugin_actions );
2679 2960 return $actions;
@@ -2682,10 +2963,10 @@
2682 2963 public function wpdbbkp_update_backup_info($FileName, $logFile, $logMessage = '') {
2683 2964 $path_info = wp_upload_dir();
2684 2965 $filename = $FileName . '.sql';
2685 2966 $WPDBFileName = $FileName . '.zip';
2686 - @unlink($this->wp_db_backup_wp_config_path() . '/' . $filename);
2687 - @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');
2688 2969 @$filesize = filesize($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName);
2689 2970
2690 2971 $upload_path = array(
2691 2972 'filename' => ($WPDBFileName),
@@ -2709,18 +2990,16 @@
2709 2990 }
2710 2991
2711 2992 private function write_log($logFile, $logMessage) {
2712 2993 // Actually write the log file
2713 - 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();
2714 2999
2715 - if (!$handle = @fopen($logFile, 'a'))
2716 - return;
2717 -
2718 - if (!fwrite($handle, $logMessage))
2719 - return;
2720 -
2721 - fclose($handle);
2722 -
3000 + if ($wp_filesystem && $wp_filesystem->is_writable($logFile) || !$wp_filesystem->exists($logFile)) {
3001 + $wp_filesystem->put_contents( $logFile, $logMessage, FS_CHMOD_FILE );
2723 3002 return true;
2724 3003 }
2725 3004 }
2726 3005
@@ -2781,12 +3060,11 @@
2781 3060 }
2782 3061
2783 3062 // Zip up $this->root without excludes
2784 3063 else {
2785 - // error_log('without exclude rule');
3064 +
2786 3065 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' 2>&1');
2787 3066 }
2788 - error_log($stderr);
2789 3067 if (!empty($stderr))
2790 3068 $this->warning($this->get_archive_method(), $stderr);
2791 3069
2792 3070 return $this->verify_archive($WPDBFileName);
@@ -2802,9 +3080,9 @@
2802 3080
2803 3081 public function set_root($path) {
2804 3082
2805 3083 if (empty($path) || !is_string($path) || !is_dir($path))
2806 - 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');
2807 3085
2808 3086 $this->root = self::conform_dir($path);
2809 3087 }
2810 3088
@@ -2853,56 +3131,59 @@
2853 3131 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
2854 3132 }
2855 3133
2856 3134 $excludes = explode("|", $excludes);
2857 - foreach ($excludes as $key => &$rule) {
3135 + if(!empty($excludes) && is_array($excludes)){
3136 + foreach ($excludes as $key => &$rule) {
2858 3137
2859 - $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 +
2860 3185
2861 - // Files don't end with /
2862 - if (!in_array(substr($rule, -1), array('\\', '/')))
2863 - $file = true;
2864 -
2865 - // If rule starts with a / then treat as absolute path
2866 - elseif (in_array(substr($rule, 0, 1), array('\\', '/')))
2867 - $absolute = true;
2868 -
2869 - // Otherwise treat as dir fragment
2870 - else
2871 - $fragment = true;
2872 -
2873 - // Strip $this->root and conform
2874 - $rule = str_ireplace($this->get_root(), '', untrailingslashit(self::conform_dir($rule)));
2875 -
2876 - // Strip the preceeding slash
2877 - if (in_array(substr($rule, 0, 1), array('\\', '/')))
2878 - $rule = substr($rule, 1);
2879 -
2880 - // Escape string for regex
2881 - if ($context === 'regex')
2882 - $rule = str_replace('.', '\.', $rule);
2883 -
2884 - // Convert any existing wildcards
2885 - if ($wildcard !== '*' && strpos($rule, '*') !== false)
2886 - $rule = str_replace('*', $wildcard, $rule);
2887 -
2888 - // Wrap directory fragments and files in wildcards for zip
2889 - if ($context === 'zip' && ( $fragment || $file ))
2890 - $rule = $wildcard . $rule . $wildcard;
2891 -
2892 - // Add a wildcard to the end of absolute url for zips
2893 - if ($context === 'zip' && $absolute)
2894 - $rule .= $wildcard;
2895 -
2896 - // Add and end carrot to files for pclzip but only if it doesn't end in a wildcard
2897 - if ($file && $context === 'regex')
2898 - $rule .= '$';
2899 -
2900 - // Add a start carrot to absolute urls for pclzip
2901 - if ($absolute && $context === 'regex')
2902 - $rule = '^' . $rule;
2903 - }
2904 -
2905 3186 // Escape shell args for zip command
2906 3187 if ($context === 'zip')
2907 3188 $excludes = array_map('escapeshellarg', array_unique($excludes));
2908 3189
@@ -2919,9 +3200,9 @@
2919 3200 return true;
2920 3201
2921 3202 // If there are errors delete the backup file.
2922 3203 if ($this->get_errors($this->get_archive_method()) && file_exists($WPDBFileName))
2923 - unlink($WPDBFileName);
3204 + wp_delete_file($WPDBFileName);
2924 3205
2925 3206 // If the archive file still exists assume it's good
2926 3207 if (file_exists($WPDBFileName))
2927 3208 return $this->archive_verified = true;
@@ -2956,8 +3237,10 @@
2956 3237 }
2957 3238
2958 3239 public function wpdbbkp_get_timeago( $time )
2959 3240 {
3241 + $time = intval($time) > 0 ? intval($time) : time();
3242 +
2960 3243 $time_difference = time() - $time;
2961 3244
2962 3245 if( $time_difference < 1 ) { return 'less than 1 second ago'; }
2963 3246 $condition = array( 12 * 30 * 24 * 60 * 60 => 'year',
@@ -2975,8 +3258,122 @@
2975 3258 if( $d >= 1 )
2976 3259 {
2977 3260 $t = floor( $d );
2978 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' ) );
2979 3376 }
2980 3377 }
2981 3378 }
2982 3379