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 +999 -601 6.107.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
@@ -699,72 +765,90 @@
699 765 'SFTP' => 'glyphicon glyphicon-tasks',
700 766 'S3' => 'glyphicon glyphicon-cloud-upload',
701 767 'Drive' => 'glyphicon glyphicon-hdd',
702 768 'DropBox' => 'glyphicon glyphicon-inbox',
769 + 'Backblaze' => 'glyphicon glyphicon-cloud-upload',
770 + 'CloudDrive' => 'glyphicon glyphicon-cloud-upload'
703 771 );
704 - foreach ( $options as $option ) {
705 - $str_class = ( 0 === (int) $option['size'] ) ? 'text-danger' : 'wpdb_download';
706 - echo '<tr class="' . ( ( 0 === ( $count % 2 ) ) ? esc_attr( $str_class ) . ' alternate' : esc_attr( $str_class ) ) . '">';
707 - echo '<td style="text-align: center;">' . esc_attr( $count ) . '</td>';
708 - $curr_date = new DateTime(date( 'Y-m-d H:i:s', $option['date'] ));
709 - $curr_date->setTimezone(new DateTimeZone(wp_timezone_string()));
710 - 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>';
711 - echo '</td>';
712 - if($wp_db_log==1){
713 - echo '<td class="wpdb_log" align="center">';
714 - if (!empty($option['log'])) {
715 - if(isset($option['type']) && ($option['type'] == 'complete' || $option['type'] == 'database')){
716 - echo '<a href="' . $option['log'] . '" target="_blank" class="label label-warning" title="There might be partial backup. Please check Log File for verify backup.">';
717 - echo '<span class="glyphicon glyphicon-list-alt"></span>';
718 - echo '</a>';
719 - }else{
720 - 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;
721 776 }
722 - }
723 - echo '</td>';
724 - }
725 - echo '<td>';
726 - if ( ! empty( $option['destination'] ) ) {
727 - $destination = ( explode( ',', $option['destination'] ) );
728 - foreach ( $destination as $dest ) {
729 - $key = trim( $dest );
730 - if ( ! empty( $dest ) && array_key_exists( $key, $destination_icon ) ) {
731 - 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;
732 781 }
733 782 }
734 - }
735 - echo '</td>';
736 - if(isset($option['type']) && !empty($option['type'])){
737 - if($option['type'] == 'complete'){
738 - 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 + }
739 801 }
740 - if($option['type'] == 'database'){
741 - echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
802 + echo '</td>';
742 803 }
743 - }else{
744 - echo '<td>Database</td>';
745 - }
746 - echo '<td>';
747 - echo '<a class="btn btn-default" href="' . esc_url( $option['url'] ) . '" style="color: #21759B;border-color:#337ab7;">';
748 - echo '<span class="glyphicon glyphicon-download-alt"></span> Download</a></td>';
749 - echo '<td>' . esc_attr( $this->wp_db_backup_format_bytes( $option['size'] ) ) . '</td>';
750 - $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 ) );
751 - 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/> ';
752 - if ( isset( $option['search_replace'] ) && 1 === (int) $option['search_replace'] ) {
753 - echo '<span style="margin-left:15px" title="' . esc_html( $option['log'] ) . '" class="glyphicon glyphicon-search"></span>';
754 - } else {
755 - $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>';
756 818 if(isset($option['type']) && !empty($option['type'])){
757 819 if($option['type'] == 'complete'){
758 - $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>';
759 821 }
760 -
822 + if($option['type'] == 'database'){
823 + echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
824 + }
825 + }else{
826 + echo '<td>Database</td>';
761 827 }
762 - 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++;
763 848 }
764 - echo '</td></tr>';
765 - $count++;
766 849 }
850 +
767 851 echo '</tbody>';
768 852
769 853 echo ' </table>
770 854 </div>
@@ -831,164 +915,202 @@
831 915 echo '</p>';
832 916 echo '</form>';
833 917 echo '</div>';
834 918 echo '</div>';
919 +
835 920
921 +
836 922 do_action('wpdbbkp_pro_tab_content');
837 923
838 924 ?>
839 925
840 - <div class="tab-pane" id="db_upgrade">
841 - <div class="panel-group ">
842 - <div class="gn-flex-container row">
843 - <div class=" col-md-12">
844 - <div class="wpdbbkp-wrapper">
845 - <div class="wpdbbkp-wr">
846 - <div class="bkp-wpdbbkp-img">
847 - <span class="sp_ov"></span>
848 - </div>
849 - <div class="bkp-wpdbbkp-cnt">
850 - <h1><?php esc_html_e('UPGRADE to PRO Version','wpdbbkp');?></h1>
851 - <a class="buy" href="https://backupforwp.com/pricing/#pricings" target="_blank">Purchase Now</a>
852 - </div>
853 - <div class="pvf">
854 - <div class="pvf-cnt">
855 - <div class="pvf-tlt">
856 - <h2><?php esc_html_e('Compare Pro vs. Free Version','wpdbbkp');?></h2>
857 - <span><?php esc_html_e('See what you\'ll get with the professional version','wpdbbkp');?></span>
858 - </div>
859 - <div class="pvf-cmp">
860 - <div class="fr">
861 - <h1><?php esc_html_e('FREE','wpdbbkp');?></h1>
862 - <div class="fr-fe">
863 - <div class="fe-1">
864 - <h4><?php esc_html_e('Continious Development','wpdbbkp');?></h4>
865 - <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>
866 - </div>
867 - <div class="fe-1">
868 - <h4><?php esc_html_e('10+ Features','wpdbbkp');?></h4>
869 - <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>
870 - </div>
871 - </div><!-- /. fr-fe -->
872 - </div><!-- /. fr -->
873 - <div class="pr">
874 - <h1>PRO</h1>
875 - <div class="pr-fe">
876 - <span><?php esc_html_e('Everything in Free, and:','wpdbbkp');?></span>
877 - <div class="fet">
878 - <div class="fe-2">
879 - <div class="fe-t">
880 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
881 - <h4><?php esc_html_e('Anonymization Function','wpdbbkp');?></h4>
882 - </div>
883 - <p><?php esc_html_e('Anonymization you critical data during backup with three methods','wpdbbkp');?> </p>
884 - </div>
885 - <div class="fe-2">
886 - <div class="fe-t">
887 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
888 - <h4><?php esc_html_e('Pre-update backups','wpdbbkp');?></h4>
889 - </div>
890 - <p> <?php esc_html_e('Automatically backs up your website before any updates to plugins, themes and WordPress core.','wpdbbkp');?></p>
891 - </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">
892 966
893 - <div class="fe-2">
894 - <div class="fe-t">
895 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
896 - <h4><?php esc_html_e('Backup time and scheduling','wpdbbkp'); ?></h4>
897 - </div>
898 - <p><?php esc_html_e('Set exact times to create or delete backups.','wpdbbkp');?></p>
899 - </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>
900 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>
901 1019
902 - <div class="fe-2">
903 - <div class="fe-t">
904 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
905 - <h4><?php esc_html_e('Fast, personal support','wpdbbkp'); ?></h4>
906 - </div>
907 - <p><?php esc_html_e('Provides expert help and support from the developers whenever you need it.','wpdbbkp'); ?></p>
908 - </div>
909 - <div class="fe-2">
910 - <div class="fe-t">
911 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
912 - <h4><?php esc_html_e('Continuous Updates','wpdbbkp'); ?></h4>
913 - </div>
914 - <p><?php esc_html_e('We\'re continuously updating our premium features and releasing them.','wpdbbkp'); ?></p>
915 - </div>
916 - <div class="fe-2">
917 - <div class="fe-t">
918 - <img src="<?php echo WPDB_PLUGIN_URL;?>/assets/images/right-tick.png" alt="right-tick">
919 - <h4><?php esc_html_e('Documentation','wpdbbkp'); ?></h4>
920 - </div>
921 - <p><?php esc_html_e('We create tutorials for every possible feature and keep it updated for you.','wpdbbkp'); ?></p>
922 - </div>
923 - </div><!-- /. fet -->
924 - <div class="pr-btn">
925 - <a href="https://backupforwp.com/pricing/#pricings" target="_blank"><?php esc_html_e('Upgrade to Pro','wpdbbkp'); ?></a>
926 - </div><!-- /. pr-btn -->
927 - </div><!-- /. pr-fe -->
928 - </div><!-- /.pr -->
929 - </div><!-- /. pvf-cmp -->
930 - </div><!-- /. pvf-cnt -->
931 -
932 - <div class="wpdbbkpfaq">
933 - <h2><?php esc_html_e('Frequently Asked Questions','wpdbbkp'); ?></h2>
934 - <div class="faq-lst">
935 - <div class="lt">
936 - <ul>
937 - <li>
938 - <span><?php esc_html_e('Is there a setup fee?','wpdbbkp'); ?></span>
939 - <p><?php esc_html_e('No. There are no setup fees on any of our plans','wpdbbkp'); ?></p>
940 - </li>
941 - <li>
942 - <span><?php esc_html_e('What\'s the time span for your contracts?','wpdbbkp'); ?></span>
943 - <p><?php esc_html_e('All the plans are year-to-year which are subscribed annually except for lifetime plan.','wpdbbkp'); ?></p>
944 - </li>
945 - <li>
946 - <span><?php esc_html_e('What payment methods are accepted?','wpdbbkp'); ?></span>
947 - <p><?php esc_html_e('We accepts PayPal and Credit Card payments.','wpdbbkp'); ?></p>
948 - </li>
949 - <li>
950 - <span><?php esc_html_e('Do you offer support if I need help?','wpdbbkp'); ?></span>
951 - <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>
952 - </li>
953 - <li>
954 - <span><?php esc_html_e('Can I use the plugins after my subscription is expired?','wpdbbkp'); ?></span>
955 - <p><?php esc_html_e('Yes, you can use the plugins, but you will not get future updates for those plugins.','wpdbbkp'); ?></p>
956 - </li>
957 - </ul>
958 - </div>
959 - <div class="rt">
960 - <ul>
961 - <li>
962 - <span><?php esc_html_e('Can I cancel my membership at any time?','wpdbbkp'); ?></span>
963 - <p><?php esc_html_e('Yes. You can cancel your membership by contacting us.','wpdbbkp'); ?></p>
964 - </li>
965 - <li>
966 - <span><?php esc_html_e('Can I change my plan later on?','wpdbbkp'); ?></span>
967 - <p><?php esc_html_e('Yes. You can upgrade your plan by contacting us.','wpdbbkp'); ?></p>
968 - </li>
969 - <li>
970 - <span><?php esc_html_e('Do you offer refunds?','wpdbbkp'); ?></span>
971 - <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>
972 - </li>
973 - <li>
974 - <span><?php esc_html_e('Do I get updates for the premium plugin?','wpdbbkp'); ?></span>
975 - <p><?php esc_html_e('Yes, you will get updates for all the premium plugins until your subscription is active.','wpdbbkp'); ?></p>
976 - </li>
977 - </ul>
978 - </div>
979 - </div><!-- /.faq-lst -->
980 - </div><!-- /.faq -->
981 - </div><!-- /. pvf -->
982 - </div>
983 - </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>
984 1091
985 - </div>
986 - </div>
987 - </div>
988 - </div>
989 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">
990 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>
991 1113 <div class="tab-pane" id="db_help">
992 1114 <div class="panel-group ">
993 1115 <div class="gn-flex-container row">
994 1116 <div class="wpdbbkp-left-side col-md-8">
@@ -998,9 +1120,9 @@
998 1120 <li>
999 1121 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Email', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1000 1122 </label>
1001 1123 <div class="support-input">
1002 - <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="">
1003 1125 </div>
1004 1126 </li>
1005 1127 <li>
1006 1128 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
@@ -1005,9 +1127,9 @@
1005 1127 <li>
1006 1128 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1007 1129 </label>
1008 1130 <div class="support-input">
1009 - <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>
1010 1132 </div>
1011 1133 </li>
1012 1134 <li>
1013 1135 <button class="button button-primary wpdbbkp-send-query"> <?php echo esc_html__('Send Support Request', 'wpdbbkp') ?> </button>
@@ -1034,9 +1156,9 @@
1034 1156 <div class="panel panel-group panel-default">
1035 1157 <div class="panel-heading">
1036 1158 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedb">
1037 1159 <h4 class="panel-title">
1038 - <?php esc_attr_e( 'System Check', 'wpdbbk' ); ?>
1160 + <?php esc_attr_e( 'System Check', 'wpdbbkp' ); ?>
1039 1161 </h4>
1040 1162 </a>
1041 1163 </div>
1042 1164 <div id="collapsedb" class="panel-collapse collapse in">
@@ -1043,8 +1165,9 @@
1043 1165 <div class="panel-body list-group">
1044 1166
1045 1167 <div class="row list-group-item">
1046 1168 <?php
1169 + $df = $dt = $dp = $du = 'NA';
1047 1170 if(function_exists('disk_free_space')){
1048 1171 /* get disk space free (in bytes) */
1049 1172 $df = disk_free_space( WPDB_ROOTPATH );
1050 1173 /* and get disk space total (in bytes) */
@@ -1058,14 +1181,14 @@
1058 1181 $df = $this->wp_db_backup_format_bytes( $df );
1059 1182 $du = $this->wp_db_backup_format_bytes( $du );
1060 1183 $dt = $this->wp_db_backup_format_bytes( $dt );
1061 1184 }
1062 - $du=$dp=$df=$dt='NA';
1185 +
1063 1186 ?>
1064 1187 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1065 1188 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1066 1189 </div>
1067 - <div class="col-md-3">Disk Space</div>
1190 + <div class="col-md-12">Disk Space</div>
1068 1191 <div class="col-md-5">
1069 1192 <div class="progress">
1070 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 ); ?>%
1071 1194 </div>
@@ -1134,13 +1257,18 @@
1134 1257 <div class="row list-group-item">
1135 1258 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1136 1259 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1137 1260 </div>
1138 - <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>
1139 1262 <div class="col-md-5">
1140 1263 <?php
1141 1264 $upload_dir = wp_upload_dir();
1142 - 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();
1143 1271 ?>
1144 1272 </div>
1145 1273 <div class="col-md-3"></div>
1146 1274 </div>
@@ -1148,14 +1276,14 @@
1148 1276 <div class="row list-group-item">
1149 1277 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1150 1278 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1151 1279 </div>
1152 - <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>
1153 1281 <div class="col-md-5"><?php echo esc_attr( $upload_dir['basedir'] ); ?></div>
1154 1282 <div class="col-md-1">
1155 1283 <?php echo esc_attr( substr( sprintf( '%o', fileperms( $upload_dir['basedir'] ) ), -4 ) ); ?></div>
1156 1284 <div
1157 - 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>'; ?>
1158 1286 </div>
1159 1287 </div>
1160 1288
1161 1289 <div class="row list-group-item">
@@ -1173,10 +1301,9 @@
1173 1301 <div class="col-md-5">
1174 1302 <?php
1175 1303 echo esc_attr( WP_MEMORY_LIMIT );
1176 1304 echo '(Max &nbsp;' . esc_attr( WP_MAX_MEMORY_LIMIT );
1177 - ?>
1178 - )
1305 + ?> )
1179 1306 </div>
1180 1307 </div>
1181 1308
1182 1309
@@ -1183,9 +1310,9 @@
1183 1310 <div class="row list-group-item">
1184 1311 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1185 1312 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1186 1313 </div>
1187 - <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>
1188 1315 <div class="col-md-5"> <?php echo esc_attr( ini_get( 'max_execution_time' ) ); ?></div>
1189 1316 <div class="col-md-1"></div>
1190 1317 <div
1191 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>
@@ -1193,15 +1320,15 @@
1193 1320 <div class="row list-group-item">
1194 1321 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1195 1322 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1196 1323 </div>
1197 - <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>
1198 1325 <div
1199 1326 class="col-md-5"> <?php echo esc_attr( $upload_dir['basedir'] . '/db-backup' ); ?></div>
1200 1327 <div
1201 1328 class="col-md-1"><?php echo esc_attr( substr( sprintf( '%o', @fileperms( esc_attr( $upload_dir['basedir'] ) . '/db-backup' ) ), -4 ) ); ?></div>
1202 1329 <div
1203 - 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>
1204 1331 </div>
1205 1332
1206 1333 <div class="row list-group-item">
1207 1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
@@ -1206,9 +1333,9 @@
1206 1333 <div class="row list-group-item">
1207 1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1208 1335 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1209 1336 </div>
1210 - <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>
1211 1338 <div class="col-md-5">
1212 1339 <?php
1213 1340 echo ( class_exists( 'ZipArchive' ) ) ? 'Yes </p>' : '<p class="">No</p>';
1214 1341 ?>
@@ -1219,9 +1346,9 @@
1219 1346 <div class="row list-group-item">
1220 1347 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1221 1348 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1222 1349 </div>
1223 - <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>
1224 1351 <div class="col-md-5">
1225 1352 <?php
1226 1353 $wpdb_admin = new Wpdb_Admin();
1227 1354 echo ( $wpdb_admin->get_mysqldump_command_path() ) ? 'Yes </p>' : '<p class="">No</p>';
@@ -1398,14 +1525,17 @@
1398 1525 <th><?php echo esc_html__('Version', 'wpdbbkp') ?></th>
1399 1526 </tr>
1400 1527 <?php
1401 1528 $plugins = get_plugins();
1402 - foreach ( $plugins as $plugin ) {
1403 - echo '<tr>
1404 - <td>' . esc_attr( $plugin['Name'] ) . '</td>
1405 - <td>' . esc_attr( $plugin['Version'] ) . '</td>
1406 - </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 + }
1407 1536 }
1537 +
1408 1538 ?>
1409 1539 </table>
1410 1540 <table class="table table-condensed">
1411 1541 <tr class="success">
@@ -1490,8 +1620,10 @@
1490 1620 $checked = '';
1491 1621 }
1492 1622 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
1493 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);
1494 1626 if ( 1 === (int) $wp_db_remove_local_backup ) {
1495 1627 $remove_local_backup = 'checked';
1496 1628 } else {
1497 1629 $remove_local_backup = '';
@@ -1500,25 +1632,40 @@
1500 1632 $remove_on_uninstall = 'checked';
1501 1633 } else {
1502 1634 $remove_on_uninstall = '';
1503 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 + }
1504 1646 ?>
1505 1647 <form action="" method="post">
1506 1648 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1507 1649 <div class="input-group">
1508 1650 <span class="input-group-addon" id="sizing-addon2"><?php echo esc_html__('Maximum Local Backups', 'wpdbbkp') ?></span>
1509 - <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">
1510 1652
1511 - </div>
1512 - <div class="alert alert-default" role="alert">
1513 - <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
1514 1655 number of Local Database Backups that should be kept, regardless of their size.', 'wpdbbkp') ?></br>
1515 1656 <?php echo esc_html__('Leave blank for keep unlimited database backups.', 'wpdbbkp') ?>
1516 - </div>
1657 + </p>
1658 +
1517 1659 <hr>
1518 1660 <div class="input-group">
1519 1661 <label><input type="checkbox" <?php echo esc_attr( $checked ); ?> name="wp_db_log"> <?php echo esc_html__('Enable Log', 'wpdbbkp') ?></label>
1520 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 +
1521 1668 <hr>
1522 1669 <div class="input-group">
1523 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>
1524 1671 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
@@ -1530,14 +1677,21 @@
1530 1677 <div class="input-group">
1531 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>
1532 1679 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1533 1680 <?php echo esc_html__('If Checked then it will remove local backup.', 'wpdbbkp') ?>
1534 - <br><?php echo esc_html__('Use this option only when you have set any destination.', 'wpdbbkp') ?>
1535 - <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') ?>
1536 1683 </p>
1537 1684 </div>
1538 1685 <hr>
1539 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">
1540 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>
1541 1695 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1542 1696 <?php echo esc_html__('If Checked then it will delete all backup files and options when plugin is uninstalled', 'wpdbbkp') ?>
1543 1697
@@ -1542,15 +1696,18 @@
1542 1696 <?php echo esc_html__('If Checked then it will delete all backup files and options when plugin is uninstalled', 'wpdbbkp') ?>
1543 1697
1544 1698 </p>
1545 1699 </div>
1546 - <hr>
1700 +
1547 1701 <?php
1548 1702 $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removeallbackup&_wpnonce=' . esc_attr( $nonce ); ?>
1549 1703
1550 1704 <div class="input-group">
1551 - <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>
1552 - <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 +
1553 1710
1554 1711 </div>
1555 1712 <hr>
1556 1713 <div class="panel panel-default">
@@ -1634,15 +1791,15 @@
1634 1791 </p>
1635 1792 <br>
1636 1793 <div class="input-group">
1637 1794 <span class="input-group-addon" id="wp_db_backup_search_text"><?php echo esc_html__('Search For', 'wpdbbkp') ?></span>
1638 - <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">
1639 1796
1640 1797 </div>
1641 1798 <br>
1642 1799 <div class="input-group">
1643 1800 <span class="input-group-addon" id="wp_db_backup_replace_text"><?php echo esc_html__('Replace With', 'wpdbbkp') ?></span>
1644 - <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">
1645 1802
1646 1803 </div>
1647 1804
1648 1805 <div class="alert alert-default" role="alert">
@@ -1649,10 +1806,10 @@
1649 1806 <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1650 1807 <?php echo esc_html__("Leave blank those fields if you don't want use this feature and want only regular Database backup.", 'wpdbbkp') ?>
1651 1808 <br>
1652 1809 <?php echo esc_html__('Ex:', 'wpdbbkp') ?>
1653 - <br><?php echo esc_html__('Search For:', 'wpdbbkp') ?> http://localhost/wordpress/
1654 - <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') ?>
1655 1812
1656 1813 <br><br>
1657 1814 <?php echo esc_html__('Note - This is Search & Replace data in your WordPress Database Backup File not in current Database installation.', 'wpdbbkp') ?>
1658 1815
@@ -1716,63 +1873,79 @@
1716 1873 global $wpdb;
1717 1874 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1718 1875 $options_backup = get_option( 'wp_db_backup_backups' );
1719 1876 $settings_backup = get_option( 'wp_db_backup_options' );
1720 - delete_option( 'wp_db_backup_backups' );
1721 - 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 + }
1722 1882 /* END : Prevent saving backup plugin settings in the database dump */
1723 1883 $wp_db_exclude_table = array();
1724 1884 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
1725 1885 $tables = $wpdb->get_col( 'SHOW TABLES' ); // phpcs:ignore
1726 1886 $output = '';
1727 - foreach ( $tables as $table ) {
1728 - if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
1729 -
1730 - $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1731 - $check_count = intval($check_count);
1732 - $sub_limit =500;
1733 - if(isset($check_count) && $check_count>$sub_limit){
1734 - $result =array();
1735 - $t_sub_queries= ceil($check_count/$sub_limit);
1736 - for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1737 - {
1738 - $sub_offset = $sub_i*$sub_limit;
1739 - $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i LIMIT %d OFFSET %d",array($table,$sub_limit,$sub_offset)), ARRAY_A );
1740 - if($sub_result){
1741 - $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);
1742 1910 }
1743 - sleep(1);
1744 1911 }
1745 - }
1746 - else{
1747 - $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i",array($table)), ARRAY_A ); // phpcs:ignore
1748 - }
1749 -
1750 -
1751 - $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1752 - $output .= "\n\n" . $row2[1] . ";\n\n";
1753 - $result_count = count( $result );
1754 - for ( $i = 0; $i < $result_count; $i++ ) {
1755 - $row = $result[ $i ];
1756 - $output .= 'INSERT INTO ' . $table . ' VALUES(';
1757 - $result_o_index = count( $result[0] );
1758 - $j=0;
1759 - foreach ($row as $key => $value) {
1760 - $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1761 - $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
1762 - if ( $j < ( $result_o_index - 1 ) ) {
1763 - $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";
1764 1935 }
1765 - $j++;
1936 +
1766 1937 }
1767 - $output .= ");\n";
1938 + $output .= "\n";
1768 1939 }
1769 - $output .= "\n";
1940 + sleep(1);
1770 1941 }
1771 - sleep(1);
1942 +
1772 1943 }
1944 +
1773 1945 $wpdb->flush();
1774 1946 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1947 + $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
1775 1948 add_option( 'wp_db_backup_backups', $options_backup );
1776 1949 add_option( 'wp_db_backup_options', $settings_backup );
1777 1950 /* END : Prevent saving backup plugin settings in the database dump */
1778 1951 return $output;
@@ -1780,61 +1953,138 @@
1780 1953
1781 1954 /**
1782 1955 * Create database backup new function.
1783 1956 */
1784 - public function wp_db_backup_create_mysql_backup_new($table) {
1785 - global $wpdb;
1786 - $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
1787 1970
1788 - $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1789 - $check_count = intval($check_count);
1790 - $sub_limit =500;
1791 - if(isset($check_count) && $check_count>$sub_limit){
1792 - $result =array();
1793 - $t_sub_queries= ceil($check_count/$sub_limit);
1794 - for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1795 - {
1796 - $sub_offset = $sub_i*$sub_limit;
1797 - $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i LIMIT %d OFFSET %d",array($table,$sub_limit,$sub_offset)), ARRAY_A );
1798 - if($sub_result){
1799 - $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 );
1800 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 + }
1801 2056 sleep(1);
1802 2057 }
1803 - }
1804 - else{
1805 - $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM %i",array($table)), ARRAY_A ); // phpcs:ignore
1806 - }
1807 -
1808 -
1809 - $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1810 - $output .= "\n\n" . $row2[1] . ";\n\n";
1811 - $result_count = count( $result );
1812 - for ( $i = 0; $i < $result_count; $i++ ) {
1813 - $row = $result[ $i ];
1814 - $output .= 'INSERT INTO ' . $table . ' VALUES(';
1815 - $result_o_index = count( $result[0] );
1816 - $j=0;
1817 - if(!empty($row)){
1818 - foreach ($row as $key => $value) {
1819 - $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1820 - $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 ] . '"' : '""';
1821 2069 if ( $j < ( $result_o_index - 1 ) ) {
1822 2070 $output .= ',';
1823 2071 }
1824 2072 $j++;
1825 2073 }
2074 + $output .= ");\n";
1826 2075 }
1827 - $output .= ");\n";
2076 + // Append to the file
2077 + if ( ! $append_content( $output ) ) {
2078 + return false; // Handle error if appending content fails
1828 2079 }
1829 - $output .= "\n";
1830 -
1831 - sleep(1);
1832 -
2080 + }
2081 +
2082 + // Flush the database cache
1833 2083 $wpdb->flush();
1834 -
1835 - return $output;
2084 + return true;
1836 2085 }
2086 +
1837 2087
1838 2088 /**
1839 2089 * Mysql Dump set path.
1840 2090 *
@@ -2072,9 +2322,9 @@
2072 2322
2073 2323 // If there are mysqldump errors delete the database dump file as mysqldump will still have written one.
2074 2324 if ( $this->get_errors( $this->get_mysqldump_method() ) && file_exists( $sql_filename ) ) {
2075 2325 if ( file_exists( $sql_filename ) ) {
2076 - unlink( $sql_filename );
2326 + wp_delete_file( $sql_filename );
2077 2327 }
2078 2328 }
2079 2329
2080 2330 // If we have an empty file delete it.
@@ -2079,9 +2329,9 @@
2079 2329
2080 2330 // If we have an empty file delete it.
2081 2331 if ( 0 === filesize( $sql_filename ) ) {
2082 2332 if ( file_exists( $sql_filename ) ) {
2083 - unlink( $sql_filename );
2333 + wp_delete_file( $sql_filename );
2084 2334 }
2085 2335 }
2086 2336
2087 2337 // If the file still exists then it must be good.
@@ -2127,31 +2377,43 @@
2127 2377 $source_directory = $this->wp_db_backup_wp_config_path();
2128 2378
2129 2379 $path_info = wp_upload_dir();
2130 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 +
2131 2391 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR);
2132 2392 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log');
2133 - fclose(fopen($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/index.php', 'w'));
2134 - 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 +
2135 2400 // Added htaccess file 08-05-2015 for prevent directory listing.
2136 2401 // Fixed Vulnerability 22-06-2016 for prevent direct download.
2137 - if ( 1 === (int) get_option( 'wp_db_backup_enable_htaccess' ) ) {
2138 - $f = fopen( $path_info['basedir'] . '/db-backup/.htaccess', 'w' ); // phpcs:ignore
2139 - fwrite( // phpcs:ignore
2140 - $f,
2141 - '#These next two lines will already exist in your .htaccess file
2142 - RewriteEngine On
2143 - RewriteBase /
2144 - # Add these lines right after the preceding two
2145 - RewriteCond %{REQUEST_FILENAME} ^.*(.zip)$
2146 - RewriteCond %{HTTP_COOKIE} !^.*can_download.*$ [NC]
2147 - RewriteRule . - [R=403,L]'
2148 - ); // phpcs:ignore
2149 - fclose( $f ); // phpcs:ignore
2150 - }
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 +
2151 2413 // Begin : Generate SQL DUMP and save to file database.sql.
2152 2414 $wp_site_name = preg_replace('/[^\p{L}\p{M}]+/u', '_', get_bloginfo('name'));
2153 - $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';
2154 2416 $sql_filename = $wp_db_file_name . '.sql';
2155 2417 $filename = $wp_db_file_name . '.zip';
2156 2418 $logname = $wp_db_file_name . '.txt';
2157 2419
@@ -2168,25 +2430,27 @@
2168 2430 if ( 1 === (int) $my_sql_dump ) {
2169 2431 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2170 2432 $options_backup = get_option( 'wp_db_backup_backups' );
2171 2433 $settings_backup = get_option( 'wp_db_backup_options' );
2172 - delete_option( 'wp_db_backup_backups' );
2173 - 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 + }
2174 2439 /* END : Prevent saving backup plugin settings in the database dump */
2175 - global $wpdb;
2440 + //phpcs:ignore -- using direct query get all tables name to be backedup.
2176 2441 $tables = $wpdb->get_col( 'SHOW TABLES' );
2177 2442 $wp_db_exclude_table = get_option( 'wp_db_exclude_table',array());
2178 2443 if(!empty($tables)){
2179 2444 foreach($tables as $table){
2180 2445 if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
2181 - $handle = fopen( $path_info['basedir'] . '/db-backup/' . $sql_filename, 'a' ); // phpcs:ignore
2182 - fwrite( $handle, $this->wp_db_backup_create_mysql_backup_new($table) ); // phpcs:ignore
2183 - fclose( $handle ); // phpcs:ignore
2184 -
2446 + $this->wp_db_backup_create_mysql_backup_new($table, $path_info['basedir'] . '/db-backup/' . $sql_filename );
2185 2447 }
2186 2448 }
2449 +
2187 2450 }
2188 2451 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2452 + $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
2189 2453 add_option( 'wp_db_backup_backups', $options_backup );
2190 2454 add_option( 'wp_db_backup_options', $settings_backup );
2191 2455 /* END : Prevent saving backup plugin settings in the database dump */
2192 2456 }
@@ -2196,10 +2460,10 @@
2196 2460 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
2197 2461 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
2198 2462 $filecontent = wp_remote_get( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2199 2463 if (! is_wp_error( $filecontent ) && isset($filecontent['body']) ) {
2200 - $backup_str = str_replace( $wp_db_backup_search_text, $wp_db_backup_replace_text, $filecontent['body'] ); // phpcs:ignore
2201 - 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 );
2202 2466 }
2203 2467 }
2204 2468
2205 2469 /* End : Generate SQL DUMP and save to file database.sql */
@@ -2225,9 +2489,9 @@
2225 2489 // Create the archive.
2226 2490 $v_list = $archive->create( $v_dir, PCLZIP_OPT_REMOVE_PATH, $v_remove );
2227 2491 }
2228 2492
2229 - global $wpdb;
2493 +
2230 2494 $mysqlversion = wp_cache_get( 'wpdb_mysqlversion' );
2231 2495 if ( true === empty( $mysqlversion ) ) {
2232 2496 $mysqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' ); // phpcs:ignore
2233 2497 wp_cache_set( 'wpdb_mysqlversion', $mysqlversion, '', 18000 );
@@ -2263,14 +2527,14 @@
2263 2527 if ( ! ( $number_of_existing_backups < $number_of_backups_from_user ) ) {
2264 2528 $diff = $number_of_existing_backups - $number_of_backups_from_user;
2265 2529 for ( $i = 0; $i <= $diff; $i++ ) {
2266 2530 $index = $i;
2267 - if ( file_exists( $options[ $index ]['dir'] ) ) {
2268 - unlink( $options[ $index ]['dir'] );
2531 + if ( isset($options[ $index ]['dir']) && file_exists( $options[ $index ]['dir'] ) ) {
2532 + wp_delete_file( $options[ $index ]['dir'] );
2269 2533 }
2270 2534 $file_sql = explode( '.', $options[ $index ]['dir'] );
2271 - if ( file_exists( $file_sql[0] . '.sql' ) ) {
2272 - 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' );
2273 2537 }
2274 2538 }
2275 2539 for ( $i = ( $diff + 1 ); $i < $number_of_existing_backups; $i++ ) {
2276 2540 $index = $i;
@@ -2276,8 +2540,9 @@
2276 2540 $index = $i;
2277 2541
2278 2542 $newoptions[] = $options[ $index ];
2279 2543 }
2544 + $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
2280 2545
2281 2546 update_option( 'wp_db_backup_backups', $newoptions , false);
2282 2547 }
2283 2548 }
@@ -2282,9 +2547,9 @@
2282 2547 }
2283 2548 }
2284 2549
2285 2550 if ( file_exists( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) {
2286 - unlink( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2551 + wp_delete_file( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2287 2552 }
2288 2553 return $upload_path;
2289 2554 }
2290 2555
@@ -2313,15 +2578,20 @@
2313 2578 * Backup Process.
2314 2579 */
2315 2580 public function wp_db_backup_event_process() {
2316 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();
2317 2587
2318 2588 $cron_condition = apply_filters('wpdbbkp_dbback_cron_condition',true );
2319 2589 if(wp_doing_cron() && !$cron_condition){
2320 - wp_die();
2590 + return false;
2321 2591 }
2322 2592
2323 - set_time_limit( 0 );
2593 + set_time_limit( 0 ); //phpcs:ignore -- increase time limit for backup process.
2324 2594 ignore_user_abort(true);
2325 2595
2326 2596 $details = $this->wp_db_backup_create_archive();
2327 2597 $options = get_option( 'wp_db_backup_backups' );
@@ -2360,22 +2630,15 @@
2360 2630 'type' =>'database',
2361 2631 'destination' => $args[4]
2362 2632 );
2363 2633 if ( 1 !== (int) $wp_db_remove_local_backup ) {
2634 + $options = wpdbbkp_filter_unique_filenames( $options );
2364 2635 update_option( 'wp_db_backup_backups', $options , false);
2365 2636 }
2366 2637 if(isset($details['log_dir']) && !empty($details['log_dir']))
2367 2638 {
2368 - if (is_writable($details['log_dir']) || !file_exists($details['log_dir'])) {
2369 -
2370 - if ($handle = @fopen($details['log_dir'], 'a'))
2371 - {
2372 - if (fwrite($handle, str_replace(array("<br>","<b>","</b>"), array("\n","",""), $args[2])))
2373 - {
2374 - fclose($handle);
2375 - }
2376 - }
2377 -
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 );
2378 2641 }
2379 2642 }
2380 2643 }
2381 2644
@@ -2412,11 +2675,22 @@
2412 2675 * Schedular activation.
2413 2676 */
2414 2677 public function wp_db_backup_scheduler_activation() {
2415 2678 $options = get_option( 'wp_db_backup_options' );
2416 - 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'] ) ) ) {
2417 2680 $cron_freq = apply_filters( 'wpdbbkp_dbback_cron_frequency',$options['autobackup_frequency']);
2418 - 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 +
2419 2693 }
2420 2694 }
2421 2695
2422 2696 /**
@@ -2425,9 +2699,9 @@
2425 2699 * @param string $key - key name.
2426 2700 */
2427 2701 public function wp_backup_get_config_data( $key ) {
2428 2702 $filepath = get_home_path() . '/wp-config.php';
2429 - $config_file = file_get_contents( "$filepath", true );
2703 + $config_file = @file_get_contents( "$filepath", true );
2430 2704 if($config_file){
2431 2705 switch ( $key ) {
2432 2706 case 'DB_NAME':
2433 2707 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
@@ -2453,9 +2727,9 @@
2453 2727 * Get db name from config.
2454 2728 */
2455 2729 public function wp_backup_get_config_db_name() {
2456 2730 $filepath = get_home_path() . '/wp-config.php';
2457 - $config_file = file_get_contents( "$filepath", true );
2731 + $config_file = @file_get_contents( "$filepath", true );
2458 2732 if($config_file){
2459 2733 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2460 2734 return $matches[1];
2461 2735 }
@@ -2469,8 +2743,11 @@
2469 2743 *
2470 2744 * @return mixed
2471 2745 */
2472 2746 public function recursive_sanitize_text_field( $array ) {
2747 + if( ! is_array( $array ) ) {
2748 + return sanitize_text_field( $array );
2749 + }
2473 2750 foreach ( $array as $key => &$value ) {
2474 2751 if ( is_array( $value ) ) {
2475 2752 $value = $this->recursive_sanitize_text_field( $value );
2476 2753 } else {
@@ -2528,8 +2805,11 @@
2528 2805 {
2529 2806 wp_register_script('wpdbbkp-admin-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin.js', array('jquery'), WPDB_VERSION, 'true' );
2530 2807 wp_localize_script('wpdbbkp-admin-script', 'wpdbbkp_script_vars', array(
2531 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(),
2532 2812 ));
2533 2813 wp_enqueue_script('wpdbbkp-admin-script');
2534 2814
2535 2815 // Adding custom js
@@ -2556,10 +2836,12 @@
2556 2836 $post_type = $current_screen->post_type;
2557 2837 }
2558 2838
2559 2839 $post_id = get_the_ID();
2840 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2560 2841 if(isset($_GET['tag_ID'])){
2561 - $post_id = intval($_GET['tag_ID']);
2842 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2843 + $post_id = intval($_GET['tag_ID']);
2562 2844 }
2563 2845
2564 2846
2565 2847
@@ -2620,9 +2902,9 @@
2620 2902
2621 2903 if ( ! isset( $_POST['wpdbbkp_security_nonce'] ) ){
2622 2904 return;
2623 2905 }
2624 - 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
2625 2907 return;
2626 2908 }
2627 2909
2628 2910 if( ! current_user_can( 'manage_options' ) ) {
@@ -2628,10 +2910,10 @@
2628 2910 if( ! current_user_can( 'manage_options' ) ) {
2629 2911 return;
2630 2912 }
2631 2913
2632 - $message = $this->wpdbbkp_sanitize_textarea_field($_POST['message']);
2633 - $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
2634 2916
2635 2917 if(function_exists('wp_get_current_user')){
2636 2918
2637 2919 $user = wp_get_current_user();
@@ -2670,9 +2952,9 @@
2670 2952 wp_die();
2671 2953 }
2672 2954 public function add_settings_plugin_action_wp( $actions, $plugin_file, $plugin_data, $context ) {
2673 2955 $plugin_actions['settings'] = sprintf(
2674 - '<a href="%s">' . _x( 'Settings', 'wpdbbkp' ) . '</a>',
2956 + '<a href="%s">' . _x( 'Settings', 'Content translation' ,'wpdbbkp' ) . '</a>',
2675 2957 admin_url( 'options-general.php?page=wp-database-backup' )
2676 2958 );
2677 2959 $actions = array_merge( $actions, $plugin_actions );
2678 2960 return $actions;
@@ -2681,10 +2963,10 @@
2681 2963 public function wpdbbkp_update_backup_info($FileName, $logFile, $logMessage = '') {
2682 2964 $path_info = wp_upload_dir();
2683 2965 $filename = $FileName . '.sql';
2684 2966 $WPDBFileName = $FileName . '.zip';
2685 - @unlink($this->wp_db_backup_wp_config_path() . '/' . $filename);
2686 - @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');
2687 2969 @$filesize = filesize($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName);
2688 2970
2689 2971 $upload_path = array(
2690 2972 'filename' => ($WPDBFileName),
@@ -2708,18 +2990,16 @@
2708 2990 }
2709 2991
2710 2992 private function write_log($logFile, $logMessage) {
2711 2993 // Actually write the log file
2712 - 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();
2713 2999
2714 - if (!$handle = @fopen($logFile, 'a'))
2715 - return;
2716 -
2717 - if (!fwrite($handle, $logMessage))
2718 - return;
2719 -
2720 - fclose($handle);
2721 -
3000 + if ($wp_filesystem && $wp_filesystem->is_writable($logFile) || !$wp_filesystem->exists($logFile)) {
3001 + $wp_filesystem->put_contents( $logFile, $logMessage, FS_CHMOD_FILE );
2722 3002 return true;
2723 3003 }
2724 3004 }
2725 3005
@@ -2780,12 +3060,11 @@
2780 3060 }
2781 3061
2782 3062 // Zip up $this->root without excludes
2783 3063 else {
2784 - // error_log('without exclude rule');
3064 +
2785 3065 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' 2>&1');
2786 3066 }
2787 - error_log($stderr);
2788 3067 if (!empty($stderr))
2789 3068 $this->warning($this->get_archive_method(), $stderr);
2790 3069
2791 3070 return $this->verify_archive($WPDBFileName);
@@ -2801,9 +3080,9 @@
2801 3080
2802 3081 public function set_root($path) {
2803 3082
2804 3083 if (empty($path) || !is_string($path) || !is_dir($path))
2805 - 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');
2806 3085
2807 3086 $this->root = self::conform_dir($path);
2808 3087 }
2809 3088
@@ -2852,56 +3131,59 @@
2852 3131 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
2853 3132 }
2854 3133
2855 3134 $excludes = explode("|", $excludes);
2856 - foreach ($excludes as $key => &$rule) {
3135 + if(!empty($excludes) && is_array($excludes)){
3136 + foreach ($excludes as $key => &$rule) {
2857 3137
2858 - $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 +
2859 3185
2860 - // Files don't end with /
2861 - if (!in_array(substr($rule, -1), array('\\', '/')))
2862 - $file = true;
2863 -
2864 - // If rule starts with a / then treat as absolute path
2865 - elseif (in_array(substr($rule, 0, 1), array('\\', '/')))
2866 - $absolute = true;
2867 -
2868 - // Otherwise treat as dir fragment
2869 - else
2870 - $fragment = true;
2871 -
2872 - // Strip $this->root and conform
2873 - $rule = str_ireplace($this->get_root(), '', untrailingslashit(self::conform_dir($rule)));
2874 -
2875 - // Strip the preceeding slash
2876 - if (in_array(substr($rule, 0, 1), array('\\', '/')))
2877 - $rule = substr($rule, 1);
2878 -
2879 - // Escape string for regex
2880 - if ($context === 'regex')
2881 - $rule = str_replace('.', '\.', $rule);
2882 -
2883 - // Convert any existing wildcards
2884 - if ($wildcard !== '*' && strpos($rule, '*') !== false)
2885 - $rule = str_replace('*', $wildcard, $rule);
2886 -
2887 - // Wrap directory fragments and files in wildcards for zip
2888 - if ($context === 'zip' && ( $fragment || $file ))
2889 - $rule = $wildcard . $rule . $wildcard;
2890 -
2891 - // Add a wildcard to the end of absolute url for zips
2892 - if ($context === 'zip' && $absolute)
2893 - $rule .= $wildcard;
2894 -
2895 - // Add and end carrot to files for pclzip but only if it doesn't end in a wildcard
2896 - if ($file && $context === 'regex')
2897 - $rule .= '$';
2898 -
2899 - // Add a start carrot to absolute urls for pclzip
2900 - if ($absolute && $context === 'regex')
2901 - $rule = '^' . $rule;
2902 - }
2903 -
2904 3186 // Escape shell args for zip command
2905 3187 if ($context === 'zip')
2906 3188 $excludes = array_map('escapeshellarg', array_unique($excludes));
2907 3189
@@ -2918,9 +3200,9 @@
2918 3200 return true;
2919 3201
2920 3202 // If there are errors delete the backup file.
2921 3203 if ($this->get_errors($this->get_archive_method()) && file_exists($WPDBFileName))
2922 - unlink($WPDBFileName);
3204 + wp_delete_file($WPDBFileName);
2923 3205
2924 3206 // If the archive file still exists assume it's good
2925 3207 if (file_exists($WPDBFileName))
2926 3208 return $this->archive_verified = true;
@@ -2955,8 +3237,10 @@
2955 3237 }
2956 3238
2957 3239 public function wpdbbkp_get_timeago( $time )
2958 3240 {
3241 + $time = intval($time) > 0 ? intval($time) : time();
3242 +
2959 3243 $time_difference = time() - $time;
2960 3244
2961 3245 if( $time_difference < 1 ) { return 'less than 1 second ago'; }
2962 3246 $condition = array( 12 * 30 * 24 * 60 * 60 => 'year',
@@ -2974,8 +3258,122 @@
2974 3258 if( $d >= 1 )
2975 3259 {
2976 3260 $t = floor( $d );
2977 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' ) );
2978 3376 }
2979 3377 }
2980 3378 }
2981 3379