PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.0
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.0
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
wp-database-backup / includes / admin / class-wpdb-admin.php

class-wpdb-admin.php in WP Database Backup – Unlimited Database & Files Backup by Backup for WP 7.0, at includes/admin/class-wpdb-admin.php

3,382 lines 139.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Backup admin.
4 *
5 * @package wpdbbkp
6 */
7 ob_start();
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Main class wpdb_admin.
14 *
15 * @class Wpdb_Admin
16 */
17 class Wpdb_Admin {
18
19 public $mysqldump_command_path;
20 public $root;
21 public $files;
22
23 /**
24 * Construct.
25 */
26 public function __construct() {
27 add_action( 'admin_init', array( $this, 'wp_db_backup_admin_init' ) );
28 add_action( 'admin_init', array( $this, 'admin_scripts_style' ) );
29 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
30 add_filter( 'cron_schedules', array( $this, 'wp_db_backup_cron_schedules' ) );
31 add_action( 'wpdbbkp_db_backup_event', array( $this, 'wp_db_backup_event_process' ) );
32 add_action( 'init', array( $this, 'wp_db_backup_scheduler_activation' ) );
33 add_action( 'wp_logout', array( $this, 'wp_db_cookie_expiration' ) ); // Fixed Vulnerability 22-06-2016 for prevent direct download.
34 add_action( 'wp_db_backup_completed', array( $this, 'wp_db_backup_completed_local' ), 12 );
35 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_style'));
36 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_newsletter_script'));
37 add_action('wp_ajax_wpdbbkp_send_query_message', array( $this, 'wpdbbkp_send_query_message'));
38 add_filter( 'plugin_action_links_' . plugin_basename( WP_BACKUP_PLUGIN_FILE ), array( $this, 'add_settings_plugin_action_wp' ), 10, 4 );
39 add_action( 'admin_notices', array($this, 'check_ziparchive_avalable_admin_notice' ));
40
41 }
42
43 /**
44 * admin Notice.
45 */
46 public function check_ziparchive_avalable_admin_notice() {
47 if (!class_exists( 'ZipArchive' ) ) { ?>
48 <div class="notice notice-info is-dismissible"><p><strong><?php echo esc_html__('Info!', 'wpdbbkp') ?></strong> <?php echo esc_html__(' Enable Zip Extension in php.ini to work BackupForWP all functionality smoothly.', 'wpdbbkp') ?> </p></div>
49 <?php }
50 }
51
52 /**
53 * Backup Menu.
54 */
55 public function admin_menu() {
56 add_menu_page(
57 'Backups',
58 'Backups',
59 'manage_options',
60 'wp-database-backup',
61 array( $this, 'wp_db_backup_settings_page' ),
62 'dashicons-database-view',
63 99
64 );
65
66 add_submenu_page(
67 'wp-database-backup',
68 'Auto Scheduler',
69 'Auto Scheduler',
70 'manage_options',
71 'wp-database-backup#tab_db_schedul',
72 array($this, 'wp_db_backup_settings_page' ));
73
74 add_submenu_page(
75 'wp-database-backup',
76 'Save Backups to',
77 'Save Backups to',
78 'manage_options',
79 'wp-database-backup#tab_db_destination',
80 array($this, 'wp_db_backup_settings_page' ));
81
82 add_submenu_page(
83 'wp-database-backup',
84 'Remote Backups',
85 'Remote Backups',
86 'manage_options',
87 'wp-database-backup#tab_db_remotebackups',
88 array($this, 'wp_db_backup_settings_page' ));
89
90 add_submenu_page(
91 'wp-database-backup',
92 'Settings',
93 'Settings',
94 'manage_options',
95 'wp-database-backup#tab_db_setting',
96 array($this, 'wp_db_backup_settings_page' ));
97 add_submenu_page(
98 'wp-database-backup',
99 'Search and Replace',
100 'Search and Replace',
101 'manage_options',
102 'wp-database-backup#searchreplace',
103 array($this, 'wp_db_backup_settings_page' ));
104
105
106 add_submenu_page(
107 'wp-database-backup',
108 'Help & Support',
109 'Help & Support',
110 'manage_options',
111 'wp-database-backup#tab_db_help',
112 array($this, 'wp_db_backup_settings_page' ));
113
114 // if(!defined('BKPFORWP_VERSION')){
115 // add_submenu_page(
116 // 'wp-database-backup',
117 // 'Upgrade to Premium',
118 // 'Upgrade to Premium',
119 // 'manage_options',
120 // 'wp-database-backup#tab_db_upgrade',
121 // array($this, 'wp_db_backup_settings_page' ));
122 // }
123 // else{
124 // add_submenu_page(
125 // 'wp-database-backup',
126 // 'Modules',
127 // 'Modules',
128 // 'manage_options',
129 // 'wp-database-backup#tab_db_features',
130 // array($this, 'wp_db_backup_settings_page' ));
131 // add_submenu_page(
132 // 'wp-database-backup',
133 // 'Licence',
134 // 'Licence',
135 // 'manage_options',
136 // 'wp-database-backup#tab_db_licence',
137 // array($this, 'wp_db_backup_settings_page' ));
138 // }
139
140
141
142 }
143
144 /**
145 * Start Fixed Vulnerability 22-06-2016 for prevent direct download.
146 */
147 public function wp_db_cookie_expiration() {
148 setcookie( 'can_download', 0, time() - 300, COOKIEPATH, COOKIE_DOMAIN );
149 if ( SITECOOKIEPATH !== COOKIEPATH ) {
150 setcookie( 'can_download', 0, time() - 300, SITECOOKIEPATH, COOKIE_DOMAIN );
151 }
152 }
153
154 /**
155 * If Checked then it will remove local backup after uploading to destination.
156 *
157 * @param array $args - backup details.
158 */
159 public function wp_db_backup_completed_local( &$args ) {
160 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
161 if ( 1 === $wp_db_remove_local_backup ) {
162 if ( file_exists( $args[1] ) ) {
163 wp_delete_file( $args[1] );// File path.
164 }
165 }
166 }
167
168 /**
169 * Admin init.
170 */
171 public function wp_db_backup_admin_init() {
172 //redirect to plugin page on activation
173 if (get_option('wpdbbkp_activation_redirect', false)) {
174 delete_option('wpdbbkp_activation_redirect');
175 if(!isset($_GET['activate-multi']))
176 {
177 wp_redirect("admin.php?page=wp-database-backup");
178 }
179 }
180
181 // Start Fixed Vulnerability 04-08-2016 for data save in options.
182 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] ) {
183 if ( ! empty( $_POST ) && ! ( isset( $_POST['option_page'] ) && 'wp_db_backup_options' === $_POST['option_page'] ) ) {
184 if ( false === isset( $_REQUEST['_wpnonce'] ) || false === wp_verify_nonce( $_REQUEST['_wpnonce'] , 'wp-database-backup' ) ) {
185 wp_die( esc_html__('WPDB :: Invalid Access', 'wpdbbkp' ) );
186 }
187 }
188
189 // End Fixed Vulnerability 04-08-2016 for data save in options.
190 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && current_user_can( 'manage_options' ) ) {
191 setcookie( 'can_download', 1, 0, COOKIEPATH, COOKIE_DOMAIN );
192 if ( SITECOOKIEPATH !== COOKIEPATH ) {
193 setcookie( 'can_download', 1, 0, SITECOOKIEPATH, COOKIE_DOMAIN );
194 }
195 } else {
196 setcookie( 'can_download', 0, time() - 300, COOKIEPATH, COOKIE_DOMAIN );
197 if ( SITECOOKIEPATH !== COOKIEPATH ) {
198 setcookie( 'can_download', 0, time() - 300, SITECOOKIEPATH, COOKIE_DOMAIN );
199 }
200 }
201 // End Fixed Vulnerability 22-06-2016 for prevent direct download.
202 if ( is_admin() && current_user_can( 'manage_options' ) ) {
203 if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , 'wp-database-backup' ) ) {
204 if ( isset( $_POST['wpsetting_search'] ) ) {
205 if ( isset( $_POST['wp_db_backup_search_text'] ) ) {
206 update_option( 'wp_db_backup_search_text', sanitize_text_field( wp_unslash( $_POST['wp_db_backup_search_text'] ) ), false );
207 }
208
209 $nonce = wp_create_nonce( 'wp-database-backup' );
210 wp_safe_redirect( esc_url( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=save&tab=searchreplace&_wpnonce=' . $nonce ) );
211 }
212
213 if ( isset( $_POST['wpsetting'] ) ) {
214 if ( isset( $_POST['wp_local_db_backup_count'] ) ) {
215 update_option( 'wp_local_db_backup_count', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wp_local_db_backup_count'] ) ) ) , false);
216 }
217
218 if ( isset( $_POST['wp_db_log'] ) ) {
219 update_option( 'wp_db_log', 1 , false);
220 } else {
221 update_option( 'wp_db_log', 0 , false);
222 }
223 if ( isset( $_POST['wp_db_remove_on_uninstall'] ) ) {
224 update_option( 'wp_db_remove_on_uninstall', 1 , false);
225 } else {
226 update_option( 'wp_db_remove_on_uninstall', 0 , false);
227 }
228 if ( isset( $_POST['wp_db_incremental_backup'] ) ) {
229 update_option( 'wp_db_incremental_backup', 1 , false);
230 } else {
231 update_option( 'wp_db_incremental_backup', 0 , false);
232 }
233 if ( isset( $_POST['wp_db_remove_local_backup'] ) ) {
234 update_option( 'wp_db_remove_local_backup', 1 , false);
235 } else {
236 update_option( 'wp_db_remove_local_backup', 0 , false);
237 }
238 if ( isset( $_POST['wp_db_save_settings_in_backup'] ) ) {
239 update_option( 'wp_db_save_settings_in_backup', 1 , false);
240 } else {
241 update_option( 'wp_db_save_settings_in_backup', 0 , false);
242 }
243 if ( isset( $_POST['wp_db_backup_enable_auto_upgrade'] ) ) {
244 update_option( 'wp_db_backup_enable_auto_upgrade', 1 , false);
245 } else {
246 update_option( 'wp_db_backup_enable_auto_upgrade', 0 , false);
247 }
248
249 if ( isset( $_POST['wp_db_backup_enable_htaccess'] ) ) {
250 update_option( 'wp_db_backup_enable_htaccess', 1 , false);
251 } else {
252 update_option( 'wp_db_backup_enable_htaccess', 0 , false);
253 $path_info = wp_upload_dir();
254 if ( file_exists( $path_info['basedir'] . '/db-backup/.htaccess' ) ) {
255 wp_delete_file( $path_info['basedir'] . '/db-backup/.htaccess' );
256 }
257 }
258
259 if ( isset( $_POST['wp_db_exclude_table'] ) ) {
260 update_option( 'wp_db_exclude_table', $this->recursive_sanitize_text_field( wp_unslash( $_POST['wp_db_exclude_table'] ) ) , false); // phpcs:ignore
261 } else {
262 update_option( 'wp_db_exclude_table', '', false );
263 }
264 $nonce = wp_create_nonce( 'wp-database-backup' );
265 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=save&_wpnonce=' . $nonce );
266 }
267
268 if ( true === isset( $_POST['wp_db_local_backup_path'] ) ) {
269 update_option( 'wp_db_local_backup_path', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wp_db_local_backup_path'] ) ) ) );
270 }
271
272 if ( isset( $_POST['wp_db_backup_email_id'] ) ) {
273 update_option( 'wp_db_backup_email_id', wp_db_filter_data( sanitize_email( wp_unslash( $_POST['wp_db_backup_email_id'] ) ) ) , false);
274 }
275
276 if ( isset( $_POST['wp_db_backup_email_attachment'] ) ) {
277 $email_attachment = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_email_attachment'] ) , false);
278 update_option( 'wp_db_backup_email_attachment', $email_attachment );
279 }
280 if ( isset( $_POST['local_backup_submit'] ) && 'Save Settings' === $_POST['local_backup_submit'] ) {
281 if ( true === isset( $_POST['wp_db_local_backup'] ) ) {
282 update_option( 'wp_db_local_backup', 1 , false);
283 } else {
284 update_option( 'wp_db_local_backup', 0 , false);
285 }
286 }
287
288 if ( isset( $_POST['wp_db_backup_options'] ) ) {
289 $option_to_save = [];
290 if ( isset( $_POST['wp_db_backup_options']['enable_autobackups'] ) ) {
291 $option_to_save['enable_autobackups'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['enable_autobackups'] ) );
292 }
293 if ( isset( $_POST['wp_db_backup_options']['autobackup_type'] ) ) {
294 $option_to_save['autobackup_type'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_type'] ) );
295 }
296 if ( isset( $_POST['wp_db_backup_options']['autobackup_frequency'] ) ) {
297 $option_to_save['autobackup_frequency'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_frequency'] ) );
298 }
299 if ( isset( $_POST['wp_db_backup_options']['autobackup_full_days'] ) ) {
300 $option_to_save['autobackup_full_days'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_days'] ) );
301 }
302 if ( isset( $_POST['wp_db_backup_options']['autobackup_full_time'] ) ) {
303 $option_to_save['autobackup_full_time'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_time'] ) );
304 }
305 if ( isset( $_POST['wp_db_backup_options']['autobackup_full_date'] ) ) {
306 $option_to_save['autobackup_full_date'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_date'] ) );
307 }
308 if(!empty($option_to_save)) {
309 if(update_option( 'wp_db_backup_options', $option_to_save, false)){
310 wp_clear_scheduled_hook( 'wpdbbkp_db_backup_event' );
311 wp_clear_scheduled_hook( 'wpdbkup_event_fullbackup' );
312 }
313 }
314
315 }
316
317
318 if ( isset( $_POST['featureSubmit'] ) && 'Save Settings' === $_POST['featureSubmit'] ) {
319 if ( isset( $_POST['enable_anonymization'] ) ) {
320 update_option( 'bkpforwp_enable_anonymization', 1 );
321 } else {
322 update_option( 'bkpforwp_enable_anonymization', 0 );
323 }
324
325 if ( isset( $_POST['enable_backup_encryption'] ) ) {
326 update_option( 'bkpforwp_enable_backup_encryption', 1 );
327 } else {
328 update_option( 'bkpforwp_enable_backup_encryption', 0 );
329 }
330 if ( isset( $_POST['enable_exact_backup_time'] ) ) {
331 update_option( 'bkpforwp_enable_exact_backup_time', 1 );
332 } else {
333 update_option( 'bkpforwp_enable_exact_backup_time', 0 );
334 }
335
336 if ( isset( $_POST['anonymization_type'] ) ) {
337 update_option( 'bkpforwp_anonymization_type', wp_db_filter_data( sanitize_text_field( $_POST['anonymization_type'] ) ) );
338
339 }
340
341 if ( isset( $_POST['anonymization_pass'] )) {
342 update_option( 'bkpforwp_anonymization_pass', wp_db_filter_data( sanitize_text_field( $_POST['anonymization_pass'] ) ) );
343
344 }
345
346 if ( isset( $_POST['backup_encryption_pass'] )) {
347 update_option( 'bkpforwp_backup_encryption_pass', wp_db_filter_data( sanitize_text_field( $_POST['backup_encryption_pass'] ) ) );
348
349 }
350 }
351
352 }
353 $wp_db_backup_destination_email = get_option( 'wp_db_backup_destination_Email' , false);
354
355 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && isset( $_GET['action'] ) && 'unlink' === $_GET['action'] ) {
356 // Specify the target directory and add forward slash.
357 $dir = plugin_dir_path( __FILE__ ) . 'Destination/Dropbox/tokens/';
358
359 // Open the directory.
360 $dir_handle = opendir( $dir );
361 // Loop over all of the files in the folder.
362 $file = readdir( $dir_handle );
363 while ( $file ) {
364 // If $file is NOT a directory remove it.
365 if ( ! is_dir( $file ) ) {
366 wp_delete_file( $dir . $file );
367 }
368 }
369 // Close the directory.
370 closedir( $dir_handle );
371 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup' );
372 }
373 $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
374 if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $nonce, 'wp-database-backup' ) ) {
375 if ( isset( $_GET['action'] ) && current_user_can( 'manage_options' ) ) {
376 switch ( (string) $_GET['action'] ) {
377 case 'createdbbackup':
378 $this->wp_db_backup_event_process();
379 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=create&_wpnonce=' . $nonce );
380 break;
381 case 'removebackup':
382 if ( true === isset( $_GET['index'] ) ) {
383 $index = (int) $_GET['index'];
384 $options = get_option( 'wp_db_backup_backups' );
385 $newoptions = array();
386 $count = 0;
387 if(!empty($options) && is_array($options)){
388 foreach ( $options as $option ) {
389 if ( $count !== $index ) {
390 $newoptions[] = $option;
391 }
392 $count++;
393 }
394 }
395
396 $upload_dir = wp_upload_dir();
397 $actual_working_directory = getcwd();
398 $file_directory = $upload_dir['basedir'].'/db-backup/';
399 /*
400 Fix for when you try to delete a file thats in a folder
401 higher in the hierarchy to your working directory */
402 chdir($file_directory);
403 if ( isset($options[ $index ]['filename']) && file_exists( $options[ $index ]['filename'] ) ) {
404 wp_delete_file( $options[ $index ]['filename'] );
405 }
406 if(isset($options[ $index ]['filename'])){
407 $file_sql = explode( '.', $options[ $index ]['filename'] );
408 if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) {
409 wp_delete_file( $file_sql[0] . '.sql' );
410 }
411 }
412
413 chdir($actual_working_directory);
414 $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
415 update_option( 'wp_db_backup_backups', $newoptions , false);
416 $nonce = wp_create_nonce( 'wp-database-backup' );
417 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=delete&_wpnonce=' . $nonce );
418 exit;
419
420 }
421 break;
422 case 'removeallbackup':
423
424 $upload_dir = wp_upload_dir();
425 $actual_working_directory = getcwd();
426 $file_directory = $upload_dir['basedir'];
427 global $wpdb;
428 /*
429 Fix for when you try to delete a file thats in a folder
430 higher in the hierarchy to your working directory
431 */
432 chdir($file_directory);
433 $files = glob($file_directory.'/db-backup'.'/*');
434
435 // Deleting all the files in the list
436 if(!empty($files)){
437 foreach($files as $file) {
438 if(is_file($file)){
439 wp_delete_file($file);
440 }
441 }
442 }
443 chdir($actual_working_directory);
444 update_option( 'wp_db_backup_backups', array() , false);
445 $nonce = wp_create_nonce( 'wp-database-backup' );
446 $table_name = $wpdb->prefix . 'wpdbbkp_processed_files';
447 $wpdb->query( "TRUNCATE TABLE $table_name" ); // phpcs:ignore
448 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=deleteall&_wpnonce=' . $nonce );
449 exit;
450
451
452 break;
453 case 'clear_temp_db_backup_file':
454 $options = get_option( 'wp_db_backup_backups' );
455 $newoptions = array();
456 $backup_check_list = array( '.htaccess', 'index.php' );
457 $delete_message = 'WPDB : Deleted Files:';
458 if(!empty($options) && is_array($options)){
459 foreach ( $options as $option ) {
460 if(!is_array($option)){
461 continue;
462 }
463 $backup_check_list[] = $option['filename'];
464 }
465 }
466 $path_info = wp_upload_dir();
467 $wp_db_backup_path = $path_info['basedir'] . '/db-backup';
468
469 // Open a directory, and read its contents.
470 if ( is_dir( $wp_db_backup_path ) ) {
471 $dh = opendir( $wp_db_backup_path );
472 if ( $dh ) {
473 while ( false !== ($file = readdir( $dh )) ) {
474 if ( ! ( in_array( $file, $backup_check_list, true ) ) ) {
475 if ( file_exists( $wp_db_backup_path . '/' . $file ) ) {
476 wp_delete_file( $wp_db_backup_path . '/' . $file );
477 }
478 $delete_message .= ' ' . $file;
479 }
480 }
481 closedir( $dh );
482 }
483 }
484 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=clear_temp_db_backup_file&_wpnonce=' . $nonce );
485 exit;
486 break;
487 case 'restorebackup':
488 $index = isset($_GET['index'])?(int) $_GET['index']:0;
489 $options = get_option( 'wp_db_backup_backups' );
490 $restore_limit = get_option( 'wp_db_restore_limit');
491 $newoptions = array();
492 $count = 0;
493 if(!empty($options) && is_array($options)){
494 foreach ( $options as $option ) {
495 if ( $count !== $index ) {
496 $newoptions[] = $option;
497 }
498 $count++;
499 }
500 }
501 if ( isset( $options[ $index ]['restore_limit'] ) && $options[ $index ]['restore_limit']==1) {
502 include_once ABSPATH . 'wp-admin/includes/plugin.php';
503 if ( !is_plugin_active( 'wp-database-backup-pro/wp-database-backup-pro.php' ) ) {
504 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore_limit&_wpnonce=' . $nonce );
505 }
506 }
507 if(!empty($options[ $index ]['restore_limit'])){
508 $options[ $index ]['restore_limit']=1;
509 }
510
511 if ( isset( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
512 $database_file = ( $options[ $index ]['sqlfile'] );
513 } else {
514 $database_file = isset($options[ $index ]['dir']) ? $options[ $index ]['dir'] : '';
515 $file_sql = explode( '.', $database_file );
516 if(isset($file_sql[0])){
517 $database_file = ( $file_sql[0] . '.sql' );
518 }
519
520 }
521 $database_name = $this->wp_backup_get_config_db_name();
522 $database_user = $this->wp_backup_get_config_data( 'DB_USER' );
523 $datadase_password = $this->wp_backup_get_config_data( 'DB_PASSWORD' );
524 $database_host = $this->wp_backup_get_config_data( 'DB_HOST' );
525 $path_info = wp_upload_dir();
526 // Added for extract zip file V.3.3.0.
527 $ext_path_info = $path_info['basedir'] . '/db-backup';
528 $database_zip_file = $options[ $index ]['dir'];
529
530 if ( class_exists( 'ZipArchive' ) ) {
531 $zip = new ZipArchive();
532 if ( $zip->open( $database_zip_file ) === true ) {
533 $zip->extractTo( $ext_path_info );
534 $zip->close();
535 }
536 } else {
537 require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
538 $archive = new PclZip( $database_zip_file );
539 $dir = $path_info['basedir'] . '/db-backup/';
540
541 if ( ! $archive->extract( PCLZIP_OPT_PATH, $dir ) ) {
542 wp_die( esc_html__('Unable to extract zip file. Please check that zlib php extension is enabled.','wpdbbkp').'<button onclick="history.go(-1);">'.esc_html__('Go Back','wpdbbkp').'</button>', esc_html__('ZIP Error','wpdbbkp') );
543 }
544 }
545
546 // End for extract zip file V.3.3.0.
547 set_time_limit( 0 );
548 ignore_user_abort(true);
549 if ('' !== trim($database_name) && '' !== trim($database_user) && '' !== trim($database_host)) {
550 $wpdb->db_connect();
551 $wpdb->select($database_name);
552
553 //phpcs:ignore -- Check if database exists
554 $db_exists = $wpdb->get_var($wpdb->prepare(
555 "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = %s",
556 $database_name
557 ));
558
559 if (!$db_exists) {
560 //phpcs:ignore -- Create DB if it doesn't exist
561 $wpdb->query($wpdb->prepare("CREATE DATABASE IF NOT EXISTS `%s`", $database_name));
562 $wpdb->select($database_name);
563 }
564 //phpcs:ignore -- Show tables from database
565 $tables = $wpdb->get_col($wpdb->prepare("SHOW TABLES FROM `%s`", $database_name));
566
567
568 if (!empty($tables)) {
569 foreach ($tables as $table_name) {
570 //phpcs:ignore -- delete tables before restore
571 $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS `%s`", $table_name));
572 }
573 }
574
575 // Restore database content
576 if (file_exists($database_file)) {
577 if ( ! function_exists( 'WP_Filesystem' ) ) {
578 require_once ABSPATH . '/wp-admin/includes/file.php';
579 }
580
581 WP_Filesystem();
582 if ( $wp_filesystem ) {
583 $sql_file = $wp_filesystem->get_contents( $database_file );
584 if ( $sql_file !== false ) {
585 $sql_queries = explode(";\n", $sql_file);
586 //phpcs:ignore -- Set sql_mode to empty
587 $wpdb->query("SET sql_mode = ''");
588
589 foreach ($sql_queries as $query) {
590 $query = apply_filters('wpdbbkp_sql_query_restore', $query);
591 if (!empty(trim($query))) {
592
593 /* Since $query is a dynqmic sql query from the backup file, we can't use $wpdb->prepare
594 * as we don't know the number / types of arguments in the query. So, we are using $wpdb->query
595 * directly to execute the query.*/
596 //phpcs:ignore
597 $wpdb->query($query);
598 }
599 }
600
601 } else {
602 error_log("Failed to Open file :".esc_html($database_file));
603 }
604 } else {
605 error_log("Failed to initialize WP_Filesystem");
606 }
607 }
608 }
609
610 if ( isset( $options[ $index ]['sqlfile'] ) && file_exists( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
611 if ( file_exists( $options[ $index ]['sqlfile'] ) ) {
612 wp_delete_file( $options[ $index ]['sqlfile'] );
613 }
614 } else {
615 $database_file = isset($options[ $index ]['dir'] )?$options[ $index ]['dir']:'';
616 if(!empty($database_file)){
617 $file_sql = explode( '.', $database_file );
618 if(isset($file_sql[0])){
619 $database_file = ( $file_sql[0] . '.sql' );
620 if ( file_exists( $database_file ) ) {
621 wp_delete_file( $database_file );
622 }
623
624 }
625
626 }
627
628 }
629 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
630 exit;
631 break;
632
633 case 'wpdbbkrestorefullbackup':
634 $index = (int) $_GET['index'];
635 require_once( 'class-wpdbbkp-restore.php' );
636 $restore = new Wpdbbkp_Restore();
637 $restore->start($index);
638 if (get_option('wp_db_log') == 1) {
639 $options = get_option('wp_db_backup_backups');
640 $path_info = wp_upload_dir();
641 if(isset($options[$index]['filename'])){
642 $logFileName = explode(".", $options[$index]['filename']);
643 if(isset($logFileName[0])){
644 $logfile = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $logFileName[0] . '.txt';
645 $message = "\n\n Restore Backup at " . gmdate("Y-m-d h:i:sa");
646 $this->write_log($logfile, $message);
647 }
648
649 }
650
651 }
652 $nonce = wp_create_nonce( 'wp-database-backup' );
653 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
654 exit;
655 break;
656
657 /* END: Restore Database Content */
658 }
659 }
660 }
661 }
662 }
663
664 if ( is_admin() && current_user_can( 'manage_options' ) ) {
665 register_setting( 'wp_db_backup_options', 'wp_db_backup_options', array( $this, 'wp_db_backup_validate' ) );
666 add_settings_section( 'wp_db_backup_main', 'WP-Database-Backup', array( $this, 'wp_db_backup_section_text' ), 'manage_options' );
667 }
668 }
669
670 /**
671 * Validate data.
672 *
673 * @param string $input - Input data.
674 */
675 public function wp_db_backup_validate( $input ) {
676 return $input;
677 }
678
679 /**
680 * Setting page.
681 */
682 public function wp_db_backup_settings_page() {
683 global $wp_filesystem;
684 if(!function_exists('WP_Filesystem')){
685 require_once ( ABSPATH . '/wp-admin/includes/file.php' );
686 }
687 WP_Filesystem();
688
689 $options = get_option( 'wp_db_backup_backups' );
690 $options = wpdbbkp_filter_unique_filenames( $options );
691 $settings = get_option( 'wp_db_backup_options' );
692 $wp_db_log = get_option( 'wp_db_log' );
693 $incremental_backup = get_option( 'wp_db_incremental_backup' ,false); ?>
694 <div class="bootstrap-wrapper">
695 <?php
696 $wp_db_local_backup_path = get_option( 'wp_db_local_backup_path' );
697 if ( false === empty( $wp_db_local_backup_path ) && false === file_exists( $wp_db_local_backup_path ) ) {
698 echo '<div class="alert alert-warning alert-dismissible fade in" role="alert">
699 <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
700 <a href="#db_destination" data-toggle="tab">';
701 esc_html_e( 'Invalid Local Backup Path : ', 'wpdbbkp' );
702 echo esc_html( $wp_db_local_backup_path );
703 echo '</a></div>';
704 }
705
706 $upload_dir = wp_upload_dir();
707 $dir = $upload_dir['basedir'] . '/db-backup';
708 if ( ! is_dir( $dir ) ) {
709 $dir = $upload_dir['basedir'];
710 }
711 if ( is_dir( $dir ) && !$wp_filesystem->is_writable( $dir )) {
712 ?>
713 <div class="row">
714 <div class="col-xs-12 col-sm-12 col-md-12">
715 <div class="alert alert-danger alert-dismissible fade in" role="alert">
716 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
717 <span aria-hidden="true">×</span></button>
718 <h4><?php esc_html_e( 'WP Database Backup', 'wpdbbkp' ); ?></h4>
719 <p><?php esc_html_e( 'Error: Permission denied, make sure you have write permission for', 'wpdbbkp' ); ?> <?php echo esc_attr( $dir ); ?>
720 <?php esc_html_e( 'folder', 'wpdbbkp' ); ?></p>
721 </div>
722 </button>
723 </div>
724 </div>
725 <?php
726 }
727 $cloud_drive_flag = get_option( 'wp_db_backup_destination_cd', false );
728 if ( !$cloud_drive_flag ) {
729 ?><br>
730 <div class="alert alert-info " role="alert">
731 &nbsp;<span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
732 <?php esc_html_e( 'Try Backup for WP Cloud Storage free for 14 days', 'wpdbbkp' ); ?> <a href="https://app.backupforwp.com/register"><?php echo esc_html__( 'Try now for free' , 'wpdbbkp'); ?></a> </div>
733 <?php
734 }
735 ?>
736
737
738
739 <div id="wpdbbkpModal" class="modal">
740 <div class="wpdbbkpmodal-content">
741 <div class="wpdbbkp-modal-header">
742 <span class="wpdbbkp-close">&times;</span>
743 <h2><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>&nbsp;<span id="wpdbbkp-modal-header-title"></span></h2>
744 </div>
745 <div class="wpdbbkp-modal-body">
746 <p id="wpdbbkp-modal-body-text"></p>
747 </div>
748 <div class="wpdbbkp-modal-footer">
749 <a class="btn btn-primary" onclick="return confirm('Are you sure you want to restore backup?')" id="wpdbbkp-proceed-btn">Continue Anyway</a>&nbsp;<a class="btn btn-default wpdbbkp-close">Close</a>
750 </div>
751 </div>
752 </div>
753
754 <div class="panel panel-default">
755 <div class="panel-heading head-logo">
756 <a href="https://backupforwp.com/" target="blank"><img
757 src="<?php echo esc_attr( WPDB_PLUGIN_URL ); ?>/assets/images/wp-database-backup.png" width="230px"></a>
758 </div>
759 <div class="panel-body">
760 <ul class="nav nav-tabs wbdbbkp_has_nav">
761 <li class="active"><a href="#db_home" data-toggle="tab"><?php echo esc_html__('Backups', 'wpdbbkp') ?></a></li>
762 <li><a href="#db_remotebackups" data-toggle="tab"><?php echo esc_html__('Remote Backups', 'wpdbbkp') ?></a></li>
763 <li><a href="#db_schedul" data-toggle="tab"><?php echo esc_html__('Auto Scheduler', 'wpdbbkp') ?></a></li>
764 <li><a href="#db_destination" data-toggle="tab"><?php echo esc_html__('Save Backups to', 'wpdbbkp') ?></a></li>
765 <li><a href="#db_setting" data-toggle="tab"><?php echo esc_html__('Settings', 'wpdbbkp') ?></a></li>
766 <li><a href="#searchreplace" style="display:none" data-toggle="tab"><?php echo esc_html__('Search and Replace', 'wpdbbkp') ?></a></li>
767 <li><a href="#db_features" data-toggle="tab"><?php echo esc_html__('Modules', 'wpdbbkp') ?></a></li>
768 <li title="System Info"><a href="#db_info" data-toggle="tab"><?php echo esc_html__('Usage', 'wpdbbkp') ?></a></li>
769 <li><a href="#db_help" data-toggle="tab"><?php echo esc_html__('Help &amp; Support', 'wpdbbkp') ?></a></li>
770
771
772 </ul>
773
774 <?php
775 echo '<div class="tab-content">';
776 echo '<div class="tab-pane active" id="db_home">';
777
778 $nonce = wp_create_nonce( 'wp-database-backup' );
779 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
780 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
781 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
782 echo '<a href="' . esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=createdbbackup&_wpnonce=' . esc_attr( $nonce ) . '" id="create_backup" class="btn btn-primary"> <span class="glyphicon glyphicon-plus-sign"></span> '.esc_html__('Create Database Backup with Search/Replace', 'wpdbbkp').'</a>';
783 echo '<p>Backup file will replace <b>' . esc_attr( $wp_db_backup_search_text ) . '</b> text with <b>' . esc_attr( $wp_db_backup_replace_text ) . '</b>. For Regular Database Backup without replace then Go to Dashboard=>Tool=>WP-DB Backup > Settings > '.esc_html__('Search and Replace - Set Blank Fields', 'wpdbbkp').' </p>';
784 } else {
785 echo '<a href="' . esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=createdbbackup&_wpnonce=' . esc_attr( $nonce ) . '" id="create_backup" class="btn btn-primary"> <span class="glyphicon glyphicon-plus-sign"></span> '.esc_html__('Create Database Backup', 'wpdbbkp').'</a>';
786 echo '<a href="#" id="wpdbbkp-create-full-backup" class="btn btn-primary"> <span class="glyphicon glyphicon-plus-sign"></span> '.esc_html__('Create Full Backup', 'wpdbbkp').'</a>';
787 echo '<a href="#" id="wpdbbkp-stop-full-backup" class="btn btn-danger wpdbbkp-cancel-btn" style="display:none;margin-bottom: 20px;margin-left: 10px;" > <span class="glyphicon glyphicon-ban"></span> '.esc_html__('Stop Backup Process', 'wpdbbkp').'</a>';
788 }
789 include_once 'admin-header-notification.php'; ?>
790
791 <?php
792 if ( !empty($options) ) {
793
794 echo ' <script>
795 var $j = jQuery.noConflict();
796 $j(document).ready(function () {
797
798 var table = $j("#wpdbbkp_table").DataTable({
799 order: [[0, "desc"]],
800 });
801 $j(".popoverid").popover();
802 });
803
804 function excludetableall(){
805 var checkboxes = document.getElementsByClassName("wp_db_exclude_table");
806 var checked = "";
807 if($j("#wp_db_exclude_table_all").prop("checked") == true){
808 checked = "checked";
809 }
810 $j(".wp_db_exclude_table").each(function() {
811 this.checked = checked;
812 });
813 }
814 </script>';
815 echo ' <div class="table-responsive">
816 <div id="wpdbbkp_dataTables" class="dataTables_wrapper form-inline" role="grid">
817
818 <table class="table table-striped table-bordered table-hover display" id="wpdbbkp_table">
819 <thead>';
820 echo '<tr class="wpdb-header">';
821 echo '<th class="manage-column" scope="col" width="5%" style="text-align: center;">#</th>';
822 echo '<th class="manage-column" scope="col" width="25%">Date</th>';
823 if($wp_db_log==1){
824 echo '<th class="manage-column" scope="col" width="5%">Log</th>';
825 }
826 echo '<th class="manage-column" scope="col" width="10%">Destination</th>';
827 echo '<th class="manage-column" scope="col" width="15%">Type</th>';
828 echo '<th class="manage-column" scope="col" width="10%">Backup File</th>';
829 echo '<th class="manage-column" scope="col" width="10%">Size</th>';
830 echo '<th class="manage-column" scope="col" width="20%">Action</th>';
831 echo '</tr>';
832 echo '</thead>';
833
834 echo '<tbody>';
835 $count = 1;
836 $destination_icon = array(
837 'Local' => 'glyphicon glyphicon-home',
838 'Local Path' => 'glyphicon glyphicon-folder-open',
839 'Email' => 'glyphicon glyphicon-envelope',
840 'FTP' => 'glyphicon glyphicon-tasks',
841 'SFTP' => 'glyphicon glyphicon-tasks',
842 'S3' => 'glyphicon glyphicon-cloud-upload',
843 'Drive' => 'glyphicon glyphicon-hdd',
844 'DropBox' => 'glyphicon glyphicon-inbox',
845 'Backblaze' => 'glyphicon glyphicon-cloud-upload',
846 'CloudDrive' => 'glyphicon glyphicon-cloud-upload'
847 );
848 if(!empty($options) && is_array($options)){
849 foreach ( $options as $option ) {
850 if (!is_array($option)) {
851 continue;
852 }
853
854 if (!empty($option['destination'])) {
855 if (strpos($option['destination'], 'CloudDrive') !== false) {
856 continue;
857 }
858 }
859 $size = isset( $option['size'])? $option['size'] : 0;
860 $str_class = ( 0 === (int) $size ) ? 'text-danger' : 'wpdb_download';
861 echo '<tr class="' . ( ( 0 === ( $count % 2 ) ) ? esc_attr( $str_class ) . ' alternate' : esc_attr( $str_class ) ) . '">';
862 echo '<td style="text-align: center;">' . esc_attr( $count ) . '</td>';
863 $curr_date = new DateTime(gmdate( 'Y-m-d H:i:s', $option['date'] ));
864 $curr_date->setTimezone(new DateTimeZone(wp_timezone_string()));
865 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>';
866 echo '</td>';
867 if($wp_db_log==1){
868 echo '<td class="wpdb_log" align="center">';
869 if (!empty($option['log'])) {
870 if(isset($option['type']) && ($option['type'] == 'complete' || $option['type'] == 'database')){
871 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.">';
872 echo '<span class="glyphicon glyphicon-list-alt"></span>';
873 echo '</a>';
874 }else{
875 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>';
876 }
877 }
878 echo '</td>';
879 }
880 echo '<td>';
881 if ( ! empty( $option['destination'] ) ) {
882 $destination = ( explode( ',', $option['destination'] ) );
883 if(!empty($destination) && is_array($destination)){
884 foreach ( $destination as $dest ) {
885 $key = trim( $dest );
886 if ( ! empty( $dest ) && array_key_exists( $key, $destination_icon ) ) {
887 echo '<span class="' . esc_attr( $destination_icon[ $key ] ) . '" title="' . esc_attr( $dest ) . '"></span> ';
888 }
889 }
890 }
891
892 }
893 echo '</td>';
894 if(isset($option['type']) && !empty($option['type'])){
895 if($option['type'] == 'complete'){
896 echo '<td>'.esc_html__('Full Backup', 'wpdbbkp').'</td>';
897 }
898 if($option['type'] == 'database'){
899 echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
900 }
901 }else{
902 echo '<td>Database</td>';
903 }
904 echo '<td>';
905 echo '<a class="btn btn-default" href="' . esc_url( $option['url'] ) . '" style="color: #21759B;border-color:#337ab7;">';
906 echo '<span class="glyphicon glyphicon-download-alt"></span> Download</a></td>';
907 echo '<td>' . esc_attr( $this->wp_db_backup_format_bytes( $option['size'] ) ) . '</td>';
908 $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 ) );
909 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/> ';
910 if ( isset( $option['search_replace'] ) && 1 === (int) $option['search_replace'] ) {
911 echo '<span style="margin-left:15px" title="' . esc_html( $option['log'] ) . '" class="glyphicon glyphicon-search"></span>';
912 } else {
913 $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 ) );
914 if(isset($option['type']) && !empty($option['type'])){
915 if($option['type'] == 'complete'){
916 $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 ) );
917 }
918
919 }
920 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/>';
921 }
922 echo '</td></tr>';
923 $count++;
924 }
925 }
926
927 echo '</tbody>';
928
929 echo ' </table>
930 </div>
931 </div>';
932 } else {
933 echo '<p>No Database Backups Created!</p>';
934 }
935
936 echo '<p>If you like <b>WP Database Backup</b> please leave us a <a target="_blank" href="http://wordpress.org/support/view/plugin-reviews/wp-database-backup" title="Rating" sl-processed="1"> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> <span class="glyphicon glyphicon-star" aria-hidden="true"></span> rating </a>. Many thanks in advance!</p>';
937 echo '</div>';
938
939 echo '<div class="tab-pane" id="db_schedul">';
940 echo '<div class="panel-group">';
941 echo '<form method="post" action="" name="wp_auto_commenter_form">';
942 wp_nonce_field( 'wp-database-backup' );
943 $enable_autobackups = '0';
944 if ( isset( $settings['enable_autobackups'] ) ) {
945 $enable_autobackups = $settings['enable_autobackups'];
946 }
947
948 $autobackup_frequency = '0';
949 if ( isset( $settings['autobackup_frequency'] ) ) {
950 $autobackup_frequency = $settings['autobackup_frequency'];
951 }
952 $full_autobackup_frequency = 'disabled';
953 if ( isset( $settings['full_autobackup_frequency'] ) ) {
954 $full_autobackup_frequency = $settings['full_autobackup_frequency'];
955 }
956 $autobackup_type = '';
957 if ( isset( $settings['autobackup_type'] ) ) {
958 $autobackup_type = $settings['autobackup_type'];
959 }
960
961 echo '<div class="row form-group"><label class="col-sm-3" for="enable_autobackups">Enable Auto Backups</label>';
962 echo '<div class="col-sm-9"><input type="checkbox" id="enable_autobackups" name="wp_db_backup_options[enable_autobackups]" value="1" ' . checked( 1, $enable_autobackups, false ) . '/>';
963 echo '<div class="alert alert-default" role="alert"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> AutoBackups will be based on Wordpress Cron so it can have execution delay of +/- 30 mins . If you have disabled Wordpress Cron then autobackup will not work until you have set Server Cron for wordpress.</div>';
964 echo '</div>';
965 echo '</div>';
966
967 echo '<div class="row form-group autobackup_type" style="display:none"><label class="col-sm-3" for="autobackup_frequency">Which part should we backup for you ?</label>';
968 echo '<div class="col-sm-9"><select id="autobackup_type" class="form-control" name="wp_db_backup_options[autobackup_type]">';
969 echo '<option value="">Select Backup Type</option>';
970 echo '<option value="full" ' . selected( 'full', $autobackup_type, false ) . '>Full(Files + DB)</option>';
971 echo '<option value="files" ' . selected( 'files', $autobackup_type, false ) . '>Files Only</option>';
972 echo '<option value="db" ' . selected( 'db', $autobackup_type, false ) . '>Database Only</option>';
973 echo '</select>';
974 echo '</div></div>';
975
976 echo '<div class="row form-group autobackup_frequency" style="display:none"><label class="col-sm-3" for="autobackup_frequency">How often should we run Automatically?</label>';
977 echo '<div class="col-sm-9"><select id="autobackup_frequency" class="form-control" name="wp_db_backup_options[autobackup_frequency]">';
978 echo '<option value="daily" ' . selected( 'daily', $autobackup_frequency, false ) . '>Daily</option>';
979 echo '<option value="weekly" ' . selected( 'weekly', $autobackup_frequency, false ) . '>Weekly</option>';
980 echo '<option value="monthly" ' . selected( 'monthly', $autobackup_frequency, false ) . '>Monthly</option>';
981 echo '</select>';
982 echo '</div></div>';
983
984 echo '<div class="row form-group autobackup_frequency_lite" style="display:none"><label class="col-sm-12 autobackup_daily_lite" >We will automatically backup at 00:00 AM daily. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div>';
985 echo '<div class="row form-group autobackup_frequency_lite" style="display:none"><label class="col-sm-12 autobackup_weekly_lite" >We will automatically backup every Sunday on weekly basis. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div>';
986 echo '<div class="row form-group autobackup_frequency_lite" style="display:none"><label class="col-sm-12 autobackup_monthly_lite" >We will automatically backup on 1st on Monday on monthly basis. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div>';
987
988 do_action('wpdbbkp_database_backup_options');
989 echo '<p class="submit">';
990 echo '<input type="submit" name="Submit" class="btn btn-primary" value="Save Settings" />';
991 echo '</p>';
992 echo '</form>';
993 echo '</div>';
994 echo '</div>';
995
996
997
998 do_action('wpdbbkp_pro_tab_content');
999
1000 ?>
1001
1002 <!-- Modal Structure -->
1003 <div class="modal" id="wpdbbkp_offer_modal" data-dismiss="modal" tabindex="-1" aria-labelledby="wpdbbkp_offer_modalLabel" aria-hidden="true">
1004 <div class="modal-dialog">
1005 <div class="modal-content">
1006 <div class="modal-body">
1007 <button type="button" id="offer_close" class="close" data-dismiss="modal" aria-label="Close">
1008 <span aria-hidden="true">&times;</span>
1009 </button>
1010 <h3 class="modal-title" id="wpdbbkp_offer_modalLabel"><img src="<?php echo esc_attr( WPDB_PLUGIN_URL ); ?>/assets/images/wp-database-backup.png" width="230px"></h3>
1011 <p style="padding:0 50px;"><?php echo esc_html__('Remote Backups offers a secure, reliable and affordable solution to backup your WP site to the cloud.','wpdbbkp');?></p>
1012 <div class="wpdbbkp_offer_container">
1013 <div class="wpdbbkp_server">
1014 <h4><?php echo esc_html__('Server Backup','wpdbbkp');?></h4>
1015 <p><?php echo esc_html__('Backup your site to server','wpdbbkp');?></p>
1016 <ul>
1017 <li>&#10004; <?php echo esc_html__('Easy to setup','wpdbbkp');?></li>
1018 <li>&#10004; <?php echo esc_html__('Takes storage on your server','wpdbbkp');?></li>
1019 <li>&#10004; <?php echo esc_html__('Availability subject to server','wpdbbkp');?></li>
1020 </ul>
1021 <h4><?php echo esc_html__('Free','wpdbbkp');?></h4>
1022 <button id="wpdbbkp_server_backup" class="btn btn-secondary"><?php echo esc_html__('Create a Backup on this Server','wpdbbkp');?></button>
1023 </div>
1024 <div class="wpdbbkp_remote">
1025 <h4><?php echo esc_html__('Remote Backup','wpdbbkp');?></h4>
1026 <p><?php echo esc_html__('Backup your site in the cloud','wpdbbkp');?></p>
1027 <ul>
1028 <li>&#10004; <?php echo esc_html__('Secure and reliable','wpdbbkp');?></li>
1029 <li>&#10004; <?php echo esc_html__('Only pay for what you use','wpdbbkp');?></li>
1030 <li>&#10004; <?php echo esc_html__('High availability','wpdbbkp');?></li>
1031 </ul>
1032 <h4><?php echo esc_html__('$1 per 50GB','wpdbbkp');?> <small><?php echo esc_html__('per month','wpdbbkp');?></small></h4>
1033 <button id="wpdbbkp_remote_backup" class="btn btn-primary"><?php echo esc_html__('Create a Backup on Remote Server','wpdbbkp');?></button>
1034 </div>
1035
1036 </div>
1037 </div>
1038 </div>
1039 </div>
1040 </div>
1041 <div class="tab-pane" id="db_features">
1042
1043 <div class="panel-group">
1044 <form method="post" action="" name="db_features_form">
1045 <?php wp_nonce_field('wp-database-backup');
1046 $enable_anonymization = get_option('bkpforwp_enable_anonymization',false);
1047 $anonymization_type = get_option('bkpforwp_anonymization_type',false);
1048 $enable_backup_encryption = get_option('bkpforwp_enable_backup_encryption',false);
1049 $anonymization_pass = get_option('bkpforwp_anonymization_pass','');
1050 $backup_encryption_pass = get_option('bkpforwp_encryption_pass','');
1051 $enable_exact_backup_time = get_option('bkpforwp_enable_exact_backup_time',false);
1052 ?>
1053 <div class="row form-group"><label class="col-sm-3" for="enable_anonymization"><?php esc_html_e('Data Anonymization','backupforwp-pro'); ?></label>
1054 <div class="col-sm-9"><input type="checkbox" id="enable_anonymization"
1055 name="enable_anonymization" value="1" <?php checked($enable_anonymization,1,1); ?> />
1056
1057 <div class="alert alert-default" role="alert">
1058 <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.','backupforwp-pro'); ?><a href="https://backupforwp.com/" target="_blank">Learn More</a></div>
1059 </div>
1060 </div>
1061 <div class="row form-group" id="anonymization_type_div" style="display:none">
1062 <label class="col-sm-3" for="anonymization_type"><?php esc_html_e('Data Anonymization Type','backupforwp-pro'); ?> </label>
1063 <div class="col-sm-9"><select id="anonymization_type" class="form-control"
1064 name="anonymization_type">
1065 <option value="masked_data" <?php selected('masked_data', $anonymization_type, true) ?>> <?php esc_html_e('Masked Data','backupforwp-pro'); ?>
1066 </option>
1067 <option value="fake_data" <?php selected('fake_data', $anonymization_type, true) ?>> <?php esc_html_e('Fake Data','backupforwp-pro'); ?>
1068 </option>
1069 <option value="encrypted_data" <?php selected('encrypted_data', $anonymization_type, true) ?>> <?php esc_html_e('Encrypted Data','backupforwp-pro'); ?>
1070 </option>
1071 </select>
1072 <?php echo wp_kses_post('<table class="bkpforwp-infotable">
1073 <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>
1074 <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>
1075 <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>
1076 </table>');?>
1077
1078 </div>
1079 </div>
1080
1081 <div class="row form-group" id="anonymization_enc_ip" style="display:none">
1082 <label class="col-sm-3" for="anonymization_pass"><?php esc_html_e('Encrypted Data','backupforwp-pro'); ?> <?php esc_html_e('Anonymization Password','backupforwp-pro'); ?></label>
1083 <div class="col-sm-9">
1084 <input type="password" name="anonymization_pass" id="anonymization_pass" class="form-control" value="<?php esc_attr($anonymization_pass);?>">
1085 <div class="alert alert-default" role="alert">
1086 <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','backupforwp-pro'); ?></div>
1087 </div>
1088
1089 </div>
1090
1091 <div class="row form-group" style="display:none"><label class="col-sm-3" for="enable_backup_encryption"><?php esc_html_e('Backup File Encrpytion','backupforwp-pro'); ?></label>
1092 <div class="col-sm-9"><input type="checkbox" id="enable_backup_encryption"
1093 name="enable_backup_encryption" value="1" <?php checked($enable_backup_encryption,1,1); ?> /></div>
1094 </div>
1095
1096 <div class="row form-group" id="encryption_pass_div" style="display:none">
1097 <label class="col-sm-3" for="backup_encryption_pass"><?php esc_html_e('Backup Password','backupforwp-pro'); ?></label>
1098 <div class="col-sm-9">
1099 <input type="password" name="backup_encryption_pass" id="backup_encryption_pass" class="form-control" value="<?php esc_attr($backup_encryption_pass);?>">
1100 </div>
1101 </div>
1102
1103 <p class="submit">
1104 <input type="submit" name="featureSubmit" class="btn btn-primary" value="Save Settings" />
1105 </p>
1106 </form>
1107 </div>
1108 </div>
1109 <div class="tab-pane" id="db_remotebackups">
1110 <?php
1111 $update_msg = '';
1112 if ( true === isset( $_POST['wpdb_cd_s3'] ) && 'Y' === $_POST['wpdb_cd_s3'] ) {
1113 // Validate that the contents of the form request came from the current site and not somewhere else added 21-08-15 V.3.4.
1114 if ( ! isset( $_POST['wpdbbackup_update_cd_setting'] ) ) {
1115 wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') );
1116 }
1117 if ( ! wp_verify_nonce( $_POST['wpdbbackup_update_cd_setting'] , 'wpdbbackup-update-cd-setting' ) ) {
1118 wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') );
1119 }
1120
1121 if ( true === isset( $_POST['wpdb_clouddrive_token'] ) ) {
1122 update_option( 'wpdb_clouddrive_token', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_clouddrive_token'] ) ) ), false );
1123 }
1124
1125 // Put a "settings updated" message on the screen.
1126 $update_msg = esc_html__('Your BackupforWP CloudDrive setting has been saved.' , 'wpdbbkp');
1127 }
1128
1129 $wpdb_clouddrive_token = get_option( 'wpdb_clouddrive_token',null);
1130
1131 $wpdbbkp_bb_s3_status = '<small><b>'.esc_html__('Status', 'wpdbbkp').'</b>: '.esc_html__('Not Configured', 'wpdbbkp').' </small> ';
1132
1133 if($wpdb_clouddrive_token && !empty($wpdb_clouddrive_token))
1134 {
1135 $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> ';
1136 }
1137
1138 ?>
1139 <h2 align="center"><strong><?php echo esc_html__('Remote Cloud Backups by BackupforWP', 'wpdbbkp') ?></strong></h2>
1140 <div class="panel panel-default">
1141 <div class="panel-heading">
1142 <h4 class="panel-title">
1143 <a data-toggle="collapse" data-parent="#accordion" href="#collapsebb">
1144 <?php echo '<b>'.esc_html__('Remote Backups', 'wpdbbkp').'</b>'; ?> <?php echo wp_kses_post($wpdbbkp_bb_s3_status);?>
1145
1146 </a>
1147 </h4>
1148 </div>
1149 <div class="panel-body">
1150 <?php
1151 if($update_msg){
1152 echo '<div class="updated"><p><strong>'.esc_html( $update_msg ).'</strong></p></div>';
1153 }
1154 ?>
1155 <form class="form-group" name="Clouddrive3" method="post" action="">
1156
1157 <p style="padding:0 20px;">
1158 <?php echo '<h2 style="padding:0 20px;">'.esc_html__('Getting started with our Remote backup service is simple.', 'wpdbbkp').'</h2>'; ?>
1159
1160 <ul style="list-style-type: style;">
1161 <li style="margin-left: 30px;"><?php echo esc_html__('Sign up for a free account at', 'wpdbbkp'); ?> <a href="https://app.backupforwp.com/register" target="_blank"><?php echo esc_html__('Backup for WP CloudDrive', 'wpdbbkp');?> </a></li>
1162 <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>
1163 <li style="margin-left: 30px;"><?php echo esc_html__('API token will be generated on adding website.', 'wpdbbkp'); ?></li>
1164 <li style="margin-left: 30px;"><?php echo esc_html__('Copy the token here and Click Save.', 'wpdbbkp'); ?></li>
1165 </ul>
1166
1167
1168 <input type="hidden" name="wpdb_cd_s3" value="Y">
1169 <input name="wpdbbackup_update_cd_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-cd-setting' ) ); ?>" />
1170 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1171 <div class="row form-group">
1172 <label class="col-sm-3" for="wpdb_clouddrive_token"><?php echo esc_html__('BackforWP API Token', 'wpdbbkp') ?></label>
1173 <div class="col-sm-6">
1174
1175 <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');?>">
1176 <a href="https://app.backupforwp.com/websites" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1177 </div>
1178 </div>
1179
1180 <p style="padding-left:20px"><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Save' , 'wpdbbkp' ); ?>" />&nbsp;
1181 </p>
1182 </form>
1183 <h2 style="padding:20px;"><?php echo esc_html__('Access you backups', 'wpdbbkp'); ?> <a href="https://app.backupforwp.com/dashboard/" target="_blank"> <?php echo esc_html__('HERE', 'wpdbbkp'); ?> </a> </h2>
1184 </div>
1185 </div>
1186
1187
1188 </div>
1189 <div class="tab-pane" id="db_help">
1190 <div class="panel-group ">
1191 <div class="gn-flex-container row">
1192 <div class="wpdbbkp-left-side col-md-8">
1193 <p> <?php echo esc_html__('We are dedicated to provide Technical support &amp; Help to our users. Use the below form for sending your questions. ', 'wpdbbkp') ?> </p>
1194 <div class="wpdbbkp_support_div_form" id="technical-form">
1195 <ul>
1196 <li>
1197 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Email', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1198 </label>
1199 <div class="support-input">
1200 <input type="text" id="wpdbbkp_query_email" name="wpdbbkp_query_email" size="47" placeholder="<?php esc_attr_e('Enter your Email','wpdbbkp');?>" required="">
1201 </div>
1202 </li>
1203 <li>
1204 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1205 </label>
1206 <div class="support-input">
1207 <textarea rows="5" cols="50" id="wpdbbkp_query_message" name="wpdbbkp_query_message" placeholder="<?php esc_attr_e('Write your query','wpdbbkp');?>"></textarea>
1208 </div>
1209 </li>
1210 <li>
1211 <button class="button button-primary wpdbbkp-send-query"> <?php echo esc_html__('Send Support Request', 'wpdbbkp') ?> </button>
1212 </li>
1213 </ul>
1214 <div class="clear"></div>
1215 <span class="wpdbbkp-query-success wpdbbkp-result wpdbbkp-hide"> <?php echo esc_html__('Message sent successfully, Please wait we will get back to you shortly', 'wpdbbkp') ?> </span>
1216 <span class="wpdbbkp-query-error wpdbbkp-result wpdbbkp-hide"> <?php echo esc_html__('Message not sent. please check your network connection', 'wpdbbkp') ?> </span>
1217 </div>
1218 </div>
1219 <div class="wpdbbkp-right-side col-md-4">
1220 <div class="wpdbbkp-bio-box" id="wpdbbkp_Bio">
1221 <h3><?php echo esc_html__('Vision &amp; Mission', 'wpdbbkp') ?></h3>
1222 <p class="wpdbbkp-p"><?php echo esc_html__('We strive to provide the best Backup Plugin in the world.', 'wpdbbkp') ?></p>
1223 <p class="wpdbbkp_boxdesk"> <?php echo esc_html__(' Delivering a good user experience means a lot to us, so we try our best to reply each and every question.', 'wpdbbkp') ?></p>
1224 </div>
1225 </div>
1226 </div>
1227 </div>
1228 </div>
1229
1230 <div class="tab-pane" id="db_info">
1231
1232 <div class="panel panel-group panel-default">
1233 <div class="panel-heading">
1234 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedb">
1235 <h4 class="panel-title">
1236 <?php esc_attr_e( 'System Check', 'wpdbbk' ); ?>
1237 </h4>
1238 </a>
1239 </div>
1240 <div id="collapsedb" class="panel-collapse collapse in">
1241 <div class="panel-body list-group">
1242
1243 <div class="row list-group-item">
1244 <?php
1245 $df = $dt = $dp = $du = 'NA';
1246 if(function_exists('disk_free_space')){
1247 /* get disk space free (in bytes) */
1248 $df = disk_free_space( WPDB_ROOTPATH );
1249 /* and get disk space total (in bytes) */
1250 $dt = disk_total_space( WPDB_ROOTPATH );
1251 /* now we calculate the disk space used (in bytes) */
1252 $du = $dt - $df;
1253 /* percentage of disk used - this will be used to also set the width % of the progress bar */
1254 $dp = sprintf( '%.2f', ( $du / $dt ) * 100 );
1255 $dp = isset( $dp )? $dp : 'NA';
1256 /* and we formate the size from bytes to MB, GB, etc. */
1257 $df = $this->wp_db_backup_format_bytes( $df );
1258 $du = $this->wp_db_backup_format_bytes( $du );
1259 $dt = $this->wp_db_backup_format_bytes( $dt );
1260 }
1261
1262 ?>
1263 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1264 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1265 </div>
1266 <div class="col-md-12">Disk Space</div>
1267 <div class="col-md-5">
1268 <div class="progress">
1269 <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 ); ?>%
1270 </div>
1271 </div>
1272 </div>
1273 <div class="col-md-1"></div>
1274 <div class="col-md-4"></div>
1275 <div class="col-md-5">
1276 <div class='prginfo'>
1277 <p><?php echo esc_attr( $du ) . ' of ' . esc_attr( $dt ) . ' used '; ?></p>
1278 <p><?php echo esc_attr( $df ) . ' of ' . esc_attr( $dt ) . ' free '; ?></p>
1279 <p>
1280 <small>
1281 <?php esc_attr_e( 'Note: This value is the physical servers hard-drive allocation.', 'wpdbbkp' ); ?>
1282 <br/>
1283 <?php esc_attr_e( "On shared hosts check your control panel for the 'TRUE' disk space quota value.", 'wpdbbkp' ); ?>
1284 </small>
1285 </p>
1286 </div>
1287
1288 </div>
1289 </div>
1290
1291 <div class=""><br>
1292 <a type="button" href="<?php echo esc_url( site_url() ); ?>/wp-admin/admin.php?page=wp-database-backup&action=clear_temp_db_backup_file&_wpnonce=<?php echo esc_attr( $nonce ); ?>" class="btn btn-warning"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span> Clear all old/temp database backup files</a>
1293 <p><?php echo esc_html__("Click above button to clear all your old or temporary created database backup
1294 files.
1295 It only delete file from backup directory which is not in 'Database Backups'
1296 listing(all other file excluding backup files listed in 'Database Backups' ).
1297 Before
1298 using this option make sure that you have save your database backup on safe
1299 place.", 'wpdbbkp') ?></p>
1300 <p><?php echo esc_html__("The disk that your backup is saved on doesn't have enough free space? Backup disk
1301 is
1302 almost full? Low disk space for backup? Backup failed due to lack of space? As
1303 you
1304 may set up a schedule to automatically do backup daily or weekly, and the size
1305 of
1306 disk space is limited, so your backup disk will run out of space quickly or
1307 someday.
1308 It is a real pain to manually delete old backups. Don't worry about it. WP
1309 Database
1310 Backup makes it easy to delete old/temparary backup files using this option.", 'wpdbbkp') ?></p>
1311
1312 </div>
1313
1314 <div class="row list-group-item">
1315 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1316 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1317 </div>
1318 <?php if ( true === isset( $_SERVER['DOCUMENT_ROOT'] ) ) { ?>
1319 <div class="col-md-3"><?php echo esc_html__('Root Path', 'wpdbbkp') ?></div>
1320 <div class="col-md-5"><?php echo esc_attr( sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ) ); ?></div>
1321 <?php } ?>
1322 </div>
1323
1324
1325 <div class="row list-group-item">
1326 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1327 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1328 </div>
1329 <div class="col-md-3"><?php echo esc_html__('ABSPATH', 'wpdbbkp') ?></div>
1330 <div class="col-md-5"><?php echo esc_attr( ABSPATH ); ?></div>
1331 </div>
1332
1333 <div class="row list-group-item">
1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1335 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1336 </div>
1337 <div class="col-md-3"><?php esc_attr_e( 'Upload directory URL', 'wpdbbk' ); ?></div>
1338 <div class="col-md-5">
1339 <?php
1340 $upload_dir = wp_upload_dir();
1341 echo esc_url( $upload_dir['baseurl'] );
1342 global $wp_filesystem;
1343 if(!function_exists('WP_Filesystem')){
1344 require_once ( ABSPATH . '/wp-admin/includes/file.php' );
1345 }
1346 WP_Filesystem();
1347 ?>
1348 </div>
1349 <div class="col-md-3"></div>
1350 </div>
1351
1352 <div class="row list-group-item">
1353 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1354 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1355 </div>
1356 <div class="col-md-3"><?php esc_attr_e( 'Upload directory', 'wpdbbk' ); ?></div>
1357 <div class="col-md-5"><?php echo esc_attr( $upload_dir['basedir'] ); ?></div>
1358 <div class="col-md-1">
1359 <?php echo esc_attr( substr( sprintf( '%o', fileperms( $upload_dir['basedir'] ) ), -4 ) ); ?></div>
1360 <div
1361 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>'; ?>
1362 </div>
1363 </div>
1364
1365 <div class="row list-group-item">
1366 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1367 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1368 </div>
1369 <div class="col-md-3"><?php echo esc_html__('Loaded PHP INI', 'wpdbbkp') ?></div>
1370 <div class="col-md-5"><?php echo esc_attr( php_ini_loaded_file() ); ?></div>
1371 </div>
1372 <div class="row list-group-item">
1373 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1374 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1375 </div>
1376 <div class="col-md-3"><?php echo esc_html__('Memory Limit', 'wpdbbkp') ?></div>
1377 <div class="col-md-5">
1378 <?php
1379 echo esc_attr( WP_MEMORY_LIMIT );
1380 echo '(Max &nbsp;' . esc_attr( WP_MAX_MEMORY_LIMIT );
1381 ?> )
1382 </div>
1383 </div>
1384
1385
1386 <div class="row list-group-item">
1387 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1388 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1389 </div>
1390 <div class="col-md-3"><?php esc_attr_e( 'Max Execution Time', 'wpdbbk' ); ?></div>
1391 <div class="col-md-5"> <?php echo esc_attr( ini_get( 'max_execution_time' ) ); ?></div>
1392 <div class="col-md-1"></div>
1393 <div
1394 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>
1395 </div>
1396 <div class="row list-group-item">
1397 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1398 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1399 </div>
1400 <div class="col-md-3"><?php esc_attr_e( 'Database backup directory', 'wpdbbk' ); ?></div>
1401 <div
1402 class="col-md-5"> <?php echo esc_attr( $upload_dir['basedir'] . '/db-backup' ); ?></div>
1403 <div
1404 class="col-md-1"><?php echo esc_attr( substr( sprintf( '%o', @fileperms( esc_attr( $upload_dir['basedir'] ) . '/db-backup' ) ), -4 ) ); ?></div>
1405 <div
1406 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>
1407 </div>
1408
1409 <div class="row list-group-item">
1410 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1411 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1412 </div>
1413 <div class="col-md-3"><?php esc_attr_e( 'Class ZipArchive Present : ', 'wpdbbk' ); ?></div>
1414 <div class="col-md-5">
1415 <?php
1416 echo ( class_exists( 'ZipArchive' ) ) ? 'Yes </p>' : '<p class="">No</p>';
1417 ?>
1418 </div>
1419 <div class="col-md-3"></div>
1420 </div>
1421
1422 <div class="row list-group-item">
1423 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1424 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1425 </div>
1426 <div class="col-md-3"><?php esc_attr_e( 'mysqldump (cmd) Present : ', 'wpdbbk' ); ?></div>
1427 <div class="col-md-5">
1428 <?php
1429 $wpdb_admin = new Wpdb_Admin();
1430 echo ( $wpdb_admin->get_mysqldump_command_path() ) ? 'Yes </p>' : '<p class="">No</p>';
1431 ?>
1432 </div>
1433 <div class="col-md-3"></div>
1434 </div>
1435
1436 </div>
1437 </div>
1438 </div>
1439
1440 <div class="panel panel-default">
1441 <div class="panel-heading">
1442 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedbinfo">
1443 <h4 class="panel-title"><?php echo esc_html__('Database Information', 'wpdbbkp') ?></h4>
1444 </a>
1445 </div>
1446
1447 <div id="collapsedbinfo" class="panel-collapse collapse in">
1448 <div class="panel-body">
1449 <table class="table table-condensed">
1450 <tr class="success">
1451 <th><?php echo esc_html__('Setting', 'wpdbbkp') ?></th>
1452 <th><?php echo esc_html__('Value', 'wpdbbkp') ?></th>
1453 </tr>
1454 <tr>
1455 <td><?php echo esc_html__('Database Host', 'wpdbbkp') ?></td>
1456 <td><?php echo esc_attr( DB_HOST ); ?></td>
1457 </tr>
1458 <tr class="default">
1459 <td><?php echo esc_html__('Database Name', 'wpdbbkp') ?></td>
1460 <td> <?php echo esc_attr( DB_NAME ); ?></td>
1461 </tr>
1462 <tr>
1463 <td><?php echo esc_html__('Database User', 'wpdbbkp') ?></td>
1464 <td><?php echo esc_attr( DB_USER ); ?></td>
1465 </td>
1466 </tr>
1467 <tr>
1468 <td><?php echo esc_html__('Database Type', 'wpdbbkp') ?></td>
1469 <td><?php echo esc_html__('MYSQL', 'wpdbbkp') ?></td>
1470 </tr>
1471 <tr>
1472 <?php
1473 // Get MYSQL Version.
1474 global $wpdb;
1475 $mysqlversion = wp_cache_get( 'wpdb_mysqlversion' );
1476 if ( true === empty( $mysqlversion ) ) {
1477 $mysqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' ); // phpcs:ignore
1478 wp_cache_set( 'wpdb_mysqlversion', $mysqlversion, '', 18000 );
1479 }
1480 ?>
1481 <td><?php echo esc_html__('Database Version', 'wpdbbkp') ?></td>
1482 <td>v<?php echo esc_attr( $mysqlversion ); ?></td>
1483 </tr>
1484 </table>
1485
1486 </div>
1487 </div>
1488 </div>
1489
1490 <div class="panel panel-default">
1491 <div class="panel-heading">
1492
1493 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedbtable">
1494 <h4 class="panel-title">
1495 <?php echo esc_html__('Tables Information', 'wpdbbkp') ?>
1496 </h4>
1497 </a>
1498
1499 </div>
1500 <div id="collapsedbtable" class="panel-collapse collapse in">
1501 <div class="panel-body">
1502 <table class="table table-condensed">
1503 <tr class="success">
1504 <th><?php echo esc_html__('No.', 'wpdbbkp') ?></th>
1505 <th><?php echo esc_html__('Tables', 'wpdbbkp') ?></th>
1506 <th><?php echo esc_html__('Records', 'wpdbbkp') ?></th>
1507
1508 </tr>
1509 <?php
1510 $no = 0;
1511 $row_usage = 0;
1512 $data_usage = 0;
1513 $tablesstatus = $wpdb->get_results( 'SHOW TABLE STATUS' ); // phpcs:ignore
1514 if($tablesstatus != null && !empty($tablesstatus)){
1515 foreach ( $tablesstatus as $tablestatus ) {
1516 $tablestatus_arr = (array) $tablestatus;
1517 if ( 0 === ( $no % 2 ) ) {
1518 $style = '';
1519 } else {
1520 $style = ' class="alternate"';
1521 }
1522 $no++;
1523 echo '<tr' . esc_attr( $style ) . '>';
1524 echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1525 echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1526 echo '<td>' . esc_attr( number_format_i18n( isset($tablestatus_arr['Rows'])?$tablestatus_arr['Rows']:0 ) ) . '</td>';
1527
1528 $row_usage += $tablestatus_arr['Rows'];
1529
1530 echo '</tr>';
1531 }
1532 }
1533 echo '<tr class="thead">';
1534 echo '<th> Total:</th>';
1535 echo '<th>' . esc_attr( number_format_i18n( $no ) ) . ' Table </th>';
1536 echo '<th>' . esc_attr( number_format_i18n( $row_usage ) ) . ' Records</th>';
1537
1538 echo '</tr>';
1539 ?>
1540 </table>
1541
1542 </div>
1543 </div>
1544 </div>
1545 <div class="panel panel-default">
1546 <div class="panel-heading">
1547
1548 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsewp">
1549 <h4 class="panel-title">
1550 <?php echo esc_html__('WordPress Information', 'wpdbbkp') ?>
1551 </h4>
1552 </a>
1553
1554 </div>
1555 <div id="collapsewp" class="panel-collapse collapse in">
1556 <div class="panel-body">
1557 <table class="table table-condensed">
1558 <tr class="success">
1559 <th><?php echo esc_html__('Setting', 'wpdbbkp') ?></th>
1560 <th><?php echo esc_html__('Value', 'wpdbbkp') ?></th>
1561
1562 </tr>
1563 <tr>
1564 <td><?php echo esc_html__('WordPress Version', 'wpdbbkp') ?></td>
1565 <td><?php bloginfo( 'version' ); ?></td>
1566 </tr>
1567 <tr>
1568 <td><?php echo esc_html__('Home URL', 'wpdbbkp') ?></td>
1569 <td> <?php echo esc_url( home_url() ); ?></td>
1570 </tr>
1571 <tr>
1572 <td><?php echo esc_html__('Site URL', 'wpdbbkp') ?></td>
1573 <td><?php echo esc_url( site_url() ); ?></td>
1574 </tr>
1575 <tr>
1576 <td><?php echo esc_html__('Upload directory URL', 'wpdbbkp') ?></td>
1577 <td><?php $upload_dir = wp_upload_dir(); ?>
1578 <?php echo esc_url( $upload_dir['baseurl'] ); ?></td>
1579 </tr>
1580 </table>
1581
1582 </div>
1583 </div>
1584 </div>
1585
1586 <div class="panel panel-default">
1587 <div class="panel-heading">
1588
1589 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsewpsetting">
1590 <h4 class="panel-title">
1591 <?php echo esc_html__('WordPress Settings', 'wpdbbkp') ?>
1592 </h4>
1593 </a>
1594
1595 </div>
1596 <div id="collapsewpsetting" class="panel-collapse collapse in">
1597 <div class="panel-body">
1598 <table class="table table-condensed">
1599 <tr class="success">
1600 <th><?php echo esc_html__('Plugin Name', 'wpdbbkp') ?></th>
1601 <th><?php echo esc_html__('Version', 'wpdbbkp') ?></th>
1602 </tr>
1603 <?php
1604 $plugins = get_plugins();
1605 if(!empty($plugins) && is_array($plugins)){
1606 foreach ( $plugins as $plugin ) {
1607 echo '<tr>
1608 <td>' . esc_attr( $plugin['Name'] ) . '</td>
1609 <td>' . esc_attr( $plugin['Version'] ) . '</td>
1610 </tr>';
1611 }
1612 }
1613
1614 ?>
1615 </table>
1616 <table class="table table-condensed">
1617 <tr class="success">
1618 <th><?php echo esc_html__('Active Theme Name', 'wpdbbkp') ?></th>
1619 <th><?php echo esc_html__('Version', 'wpdbbkp') ?></th>
1620 </tr>
1621 <?php
1622 $my_theme = wp_get_theme();
1623
1624 echo '<tr>
1625 <td>' . esc_attr( $my_theme->get( 'Name' ) ) . '</td>
1626 <td>' . esc_attr( $my_theme->get( 'Version' ) ) . '</td>
1627 </tr>';
1628 ?>
1629 </table>
1630 <div class="row">
1631 <button class="btn btn-primary" type="button">
1632 <?php echo esc_html__('Drafts Post Count', 'wpdbbkp') ?> <span class="badge">
1633 <?php
1634 $count_posts = wp_count_posts();
1635 echo esc_attr( $count_posts->draft );
1636 ?>
1637 </span>
1638 </button>
1639 <button class="btn btn-primary" type="button">
1640 <?php echo esc_html__('Publish Post Count', 'wpdbbkp') ?> <span class="badge">
1641 <?php
1642
1643 echo esc_attr( $count_posts->publish );
1644 ?>
1645 </span>
1646 </button>
1647 <button class="btn btn-primary" type="button">
1648 <?php echo esc_html__('Drafts Pages Count', 'wpdbbkp') ?> <span class="badge">
1649 <?php
1650 $count_pages = wp_count_posts( 'page' );
1651 echo esc_attr( $count_pages->draft );
1652 ?>
1653 </span>
1654 </button>
1655 <button class="btn btn-primary" type="button">
1656 <?php echo esc_html__('Publish Pages Count', 'wpdbbkp') ?> <span class="badge">
1657 <?php
1658
1659 echo esc_attr( $count_pages->publish );
1660 ?>
1661 </span>
1662 </button>
1663 <button class="btn btn-primary" type="button">
1664 <?php echo esc_html__('Approved Comments Count', 'wpdbbkp') ?> <span class="badge">
1665 <?php
1666 $comments_count = wp_count_comments();
1667 echo esc_attr( $comments_count->approved );
1668 ?>
1669 </span>
1670 </button>
1671 </div>
1672 </div>
1673 </div>
1674 </div>
1675
1676
1677 </div>
1678
1679 <div class="tab-pane" id="db_setting">
1680
1681 <div class="panel-group">
1682 <?php
1683 $wp_local_db_backup_count = get_option( 'wp_local_db_backup_count' );
1684 $wp_db_log = get_option( 'wp_db_log' );
1685 $wp_db_exclude_table = array();
1686 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
1687 $wp_db_backup_enable_auto_upgrade = get_option( 'wp_db_backup_enable_auto_upgrade' );
1688 if ( 1 === (int) $wp_db_backup_enable_auto_upgrade ) {
1689 $wp_db_backup_enable_auto_upgrade_checked = 'checked';
1690 } else {
1691 $wp_db_backup_enable_auto_upgrade_checked = '';
1692 }
1693 if ( 1 === (int) $wp_db_log ) {
1694 $checked = 'checked';
1695 } else {
1696 $checked = '';
1697 }
1698 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
1699 $wp_db_remove_on_uninstall = get_option( 'wp_db_remove_on_uninstall');
1700 $wp_db_incremental_backup = get_option( 'wp_db_incremental_backup');
1701 $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
1702 if ( 1 === (int) $wp_db_remove_local_backup ) {
1703 $remove_local_backup = 'checked';
1704 } else {
1705 $remove_local_backup = '';
1706 }
1707 if ( 1 === (int) $wp_db_remove_on_uninstall ) {
1708 $remove_on_uninstall = 'checked';
1709 } else {
1710 $remove_on_uninstall = '';
1711 }
1712 if ( 1 === (int) $wp_db_incremental_backup ) {
1713 $incremental_backup = 'checked';
1714 } else {
1715 $incremental_backup = '';
1716 }
1717 if ( 1 === (int) $wp_db_save_settings_in_backup ) {
1718 $save_on_backup = 'checked';
1719 } else {
1720 $save_on_backup = '';
1721 }
1722 ?>
1723 <form action="" method="post">
1724 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1725 <div class="input-group">
1726 <span class="input-group-addon" id="sizing-addon2"><?php echo esc_html__('Maximum Local Backups', 'wpdbbkp') ?></span>
1727 <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">
1728
1729 </div><br>
1730 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span><?php echo esc_html__(' The maximum
1731 number of Local Database Backups that should be kept, regardless of their size.', 'wpdbbkp') ?></br>
1732 <?php echo esc_html__('Leave blank for keep unlimited database backups.', 'wpdbbkp') ?>
1733 </p>
1734
1735 <hr>
1736 <div class="input-group">
1737 <label><input type="checkbox" <?php echo esc_attr( $checked ); ?> name="wp_db_log"> <?php echo esc_html__('Enable Log', 'wpdbbkp') ?></label>
1738 </div>
1739 <br>
1740 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1741 <?php echo esc_html__(' Create a log file to record details of each backup operation. ', 'wpdbbkp') ?>
1742 </p>
1743
1744 <hr>
1745 <div class="input-group">
1746 <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>
1747 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1748 <?php echo esc_html__('If checked then it will create database backup on(before) upgrade/update plugin, theme, WordPress.', 'wpdbbkp') ?>
1749 <br><?php echo esc_html__('Leave blank/un-checked for disable this feature.', 'wpdbbkp') ?>
1750 </p>
1751 </div>
1752 <hr>
1753 <div class="input-group">
1754 <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>
1755 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1756 <?php echo esc_html__('If Checked then it will remove local backup.', 'wpdbbkp') ?>
1757 <?php echo esc_html__('Use this option only when you have set any destination.', 'wpdbbkp') ?>
1758 <?php echo esc_html__('If somesites you need only external backup.', 'wpdbbkp') ?>
1759 </p>
1760 </div>
1761 <hr>
1762 <div class="input-group">
1763 <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>
1764 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1765 <?php echo esc_html__('If Checked then it will skip Backup for WP plugin settings from the DB backup file .', 'wpdbbkp') ?>
1766 </p>
1767 </div>
1768 <hr>
1769 <div class="input-group">
1770 <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>
1771 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1772 <?php echo esc_html__('If Checked then it will delete all backup files and options when plugin is uninstalled', 'wpdbbkp') ?>
1773
1774 </p>
1775 </div>
1776
1777 <?php
1778 $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removeallbackup&_wpnonce=' . esc_attr( $nonce ); ?>
1779
1780 <div class="input-group">
1781 <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>
1782 <p> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1783 <?php echo esc_html__('Warning :This is will delete all the backups on the website. Once deleted backups can not be recovered.', 'wpdbbkp') ?>
1784 </p>
1785
1786
1787 </div>
1788 <hr>
1789 <div class="panel panel-default">
1790 <div class="panel-heading">
1791 <a data-toggle="collapse" data-parent="#accordion" href="#collapseExclude">
1792 <h4 class="panel-title">
1793 <?php echo esc_html__('Exclude Table From Database Backup', 'wpdbbkp') ?>
1794 </h4>
1795 </a>
1796 </div>
1797 <div id="collapseExclude" class="panel-collapse collapse in">
1798 <div class="panel-body">
1799 <table class="table table-condensed">
1800 <tr class="success">
1801 <th><?php echo esc_html__('No.', 'wpdbbkp') ?></th>
1802 <th><?php echo esc_html__('Tables', 'wpdbbkp') ?></th>
1803 <th><?php echo esc_html__('Records', 'wpdbbkp') ?></th>
1804 <th><?php echo esc_html__('Exclude Table', 'wpdbbkp') ?></th>
1805 </tr>
1806 <?php
1807 $no = 0;
1808 $row_usage = 0;
1809 $data_usage = 0;
1810 $tablesstatus = $wpdb->get_results( 'SHOW TABLE STATUS' ); // phpcs:ignore
1811 if($tablesstatus != null && !empty($tablesstatus)){
1812 foreach ( $tablesstatus as $tablestatus ) {
1813 $tablestatus_arr = (array) $tablestatus;
1814 if ( 0 === ( $no % 2 ) ) {
1815 $style = '';
1816 } else {
1817 $style = ' class="alternate"';
1818 }
1819 $no++;
1820 echo '<tr' . esc_attr( $style ) . '>';
1821 echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1822 echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1823 echo '<td>' . esc_attr( number_format_i18n( isset($tablestatus_arr['Rows'])?$tablestatus_arr['Rows']:0 ) ) . '</td>';
1824 if ( false === empty( $wp_db_exclude_table ) && in_array( $tablestatus_arr['Name'], $wp_db_exclude_table, true ) ) {
1825 $checked = 'checked';
1826 } else {
1827 $checked = '';
1828 }
1829 echo '<td> <input class="wp_db_exclude_table" type="checkbox" ' . esc_attr( $checked ) . ' value="' . esc_attr( $tablestatus_arr['Name'] ) . '" name="wp_db_exclude_table[' . esc_attr( $tablestatus_arr['Name'] ) . ']"></td>';
1830
1831 $row_usage += $tablestatus_arr['Rows'];
1832
1833 echo '</tr>';
1834 }
1835 }
1836 echo '<tr class="thead">';
1837 echo '<th>Total:</th>';
1838 echo '<th>' . esc_attr( number_format_i18n( $no ) ) . ' Table</th>';
1839 echo '<th>' . esc_attr( number_format_i18n( $row_usage ) ) . ' Records</th>';
1840 echo '<th></th>';
1841 echo '</tr>';
1842 ?>
1843 </table>
1844 </div>
1845 </div>
1846 </div>
1847 <hr>
1848 <input class="btn btn-primary" type="submit" name="wpsetting" value="Save">
1849 </form>
1850 </div>
1851 </div>
1852
1853 <div class="tab-pane" id="searchreplace">
1854 <div class="panel-group">
1855 <?php
1856 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
1857 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
1858 ?>
1859 <form action="" method="post">
1860 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1861
1862 <p><?php echo esc_html__('If you even need to migrate your WordPress site to a different domain name,
1863 or add an SSL certificate to it, you must update the URLs in your database backup file
1864 then you can use this feature.','wpdbbkp'); ?> <br>
1865 <?php echo esc_html__(' This feature allow you to Search and Replace text in your database backup file. ','wpdbbkp'); ?>
1866 <br> <?php echo esc_html__('if you want only exclude tables from search and replace text then Go to Dashboard=>Tool=>WP-DB Backup > Setting > Exclude Table From Database Backup setting. The tables you selected will be skipped over for each backup you make.', 'wpdbbkp') ?>
1867 </p>
1868 <br>
1869 <div class="input-group">
1870 <span class="input-group-addon" id="wp_db_backup_search_text"><?php echo esc_html__('Search For', 'wpdbbkp') ?></span>
1871 <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('http://localhost/wordpress','wpdbbkp'); //phpcs:ignore ?>" aria-describedby="wp_db_backup_search_text">
1872
1873 </div>
1874 <br>
1875 <div class="input-group">
1876 <span class="input-group-addon" id="wp_db_backup_replace_text"><?php echo esc_html__('Replace With', 'wpdbbkp') ?></span>
1877 <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">
1878
1879 </div>
1880
1881 <div class="alert alert-default" role="alert">
1882 <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1883 <?php echo esc_html__("Leave blank those fields if you don't want use this feature and want only regular Database backup.", 'wpdbbkp') ?>
1884 <br>
1885 <?php echo esc_html__('Ex:', 'wpdbbkp') ?>
1886 <br><?php echo esc_html__('Search For:', 'wpdbbkp') ?> <?php echo esc_url('http://localhost/wordpress/', 'wpdbbkp'); //phpcs:ignore ?>
1887 <br><?php echo esc_html__('Replace With:', 'wpdbbkp') ?> <?php echo esc_url('http://domain.com/', 'wpdbbkp') ?>
1888
1889 <br><br>
1890 <?php echo esc_html__('Note - This is Search & Replace data in your WordPress Database Backup File not in current Database installation.', 'wpdbbkp') ?>
1891
1892 </div>
1893
1894 <input class="btn btn-primary" type="submit" name="wpsetting_search" value="Save">
1895 </form>
1896 </div>
1897
1898
1899
1900 </div>
1901 <div class="tab-pane panel-group" id="db_destination">
1902 <?php
1903 include plugin_dir_path( __FILE__ ) . 'Destination/wp-backup-destination.php';
1904 ?>
1905 </div>
1906
1907
1908 </div>
1909 </div>
1910
1911
1912 </div>
1913 <a aria-label="Open Support" aria-expanded="false" class="wpdbbkp-support-button" href="https://backupforwp.com/support/" target="_blank">
1914 <span class="wpdbbkp-support-icon">
1915 <svg width="24" height="22" xmlns="http://www.w3.org/2000/svg"><path d="M20.347 20.871l-.003-.05c0 .017.001.034.003.05zm-.243-4.278a2 2 0 0 1 .513-1.455c1.11-1.226 1.383-2.212 1.383-4.74C22 5.782 18.046 2 13.125 2h-2.25C5.954 2 2 5.78 2 10.399c0 4.675 4.01 8.626 8.875 8.626h2.25c.834 0 1.606-.207 3.212-.798a2 2 0 0 1 1.575.083l2.355 1.161-.163-2.878zM10.875 0h2.25C19.13 0 24 4.656 24 10.399c0 2.6-.25 4.257-1.9 6.08l.243 4.279c.072.845-.807 1.471-1.633 1.162l-3.682-1.816c-1.212.446-2.527.921-3.903.921h-2.25C4.869 21.025 0 16.142 0 10.4 0 4.656 4.869 0 10.875 0z" fill="#FFF"></path></svg>
1916 </span>
1917 </a>
1918 <?php
1919 }
1920
1921 /**
1922 * Redirect to premium website
1923 */
1924 public function wp_db_backup_premium_interface_render()
1925 {
1926 wp_redirect("https://backupforwp.com/pricing/");
1927 exit;
1928 }
1929
1930 /**
1931 * Run after complete backup.
1932 *
1933 * @param bool $bytes - bytes details.
1934 * @param int $precision - precision details.
1935 */
1936 public function wp_db_backup_format_bytes( $bytes, $precision = 2 ) {
1937 $units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
1938 $bytes = max( $bytes, 0 );
1939 $pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
1940 $pow = min( $pow, count( $units ) - 1 );
1941 $bytes /= pow( 1024, $pow );
1942 return round( $bytes, $precision ) . ' ' . $units[ $pow ];
1943 }
1944
1945 /**
1946 * Create database bakup function.
1947 */
1948 public function wp_db_backup_create_mysql_backup() {
1949 global $wpdb;
1950 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1951 $options_backup = get_option( 'wp_db_backup_backups' );
1952 $settings_backup = get_option( 'wp_db_backup_options' );
1953 $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
1954 if($wp_db_save_settings_in_backup){
1955 delete_option( 'wp_db_backup_backups' );
1956 delete_option( 'wp_db_backup_options' );
1957 }
1958 /* END : Prevent saving backup plugin settings in the database dump */
1959 $wp_db_exclude_table = array();
1960 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
1961 $tables = $wpdb->get_col( 'SHOW TABLES' ); // phpcs:ignore
1962 $output = '';
1963 if(!empty($tables) && !is_array($tables)){
1964 foreach ( $tables as $table ) {
1965 if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
1966
1967 $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1968 $check_count = intval($check_count);
1969 $sub_limit =500;
1970 if(isset($check_count) && $check_count>$sub_limit){
1971 $result =array();
1972 $t_sub_queries= ceil($check_count/$sub_limit);
1973 for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1974 {
1975 $sub_offset = $sub_i*$sub_limit;
1976 $sub_result = false;
1977 if ( false === $sub_result ) {
1978 // phpcs:ignore -- using direct query to get the data of table in chunks.
1979 $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table} LIMIT %d OFFSET %d",array($sub_limit,$sub_offset)), ARRAY_A );
1980 }
1981
1982 if($sub_result){
1983 $result = array_merge($result,$sub_result);
1984 }
1985 sleep(1);
1986 }
1987 }
1988 else{
1989 $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table}"), ARRAY_A ); // phpcs:ignore
1990 }
1991
1992
1993 $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1994 $output .= "\n\n" . $row2[1] . ";\n\n";
1995 $result_count = count( $result );
1996 for ( $i = 0; $i < $result_count; $i++ ) {
1997 if(isset($result[ $i ])){
1998 $row = $result[ $i ];
1999 $output .= 'INSERT INTO ' . $table . ' VALUES(';
2000 $result_o_index = count( $result[0] );
2001 $j=0;
2002 foreach ($row as $key => $value) {
2003 $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
2004 $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2005 if ( $j < ( $result_o_index - 1 ) ) {
2006 $output .= ',';
2007 }
2008 $j++;
2009 }
2010 $output .= ");\n";
2011 }
2012
2013 }
2014 $output .= "\n";
2015 }
2016 sleep(1);
2017 }
2018
2019 }
2020
2021 $wpdb->flush();
2022 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2023 $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
2024 add_option( 'wp_db_backup_backups', $options_backup );
2025 add_option( 'wp_db_backup_options', $settings_backup );
2026 /* END : Prevent saving backup plugin settings in the database dump */
2027 return $output;
2028 }
2029
2030 /**
2031 * Create database backup new function.
2032 */
2033 public function wp_db_backup_create_mysql_backup_new( $table, $file_path ) {
2034 global $wpdb, $wp_filesystem;
2035
2036 // Ensure WP Filesystem is loaded
2037 if ( ! function_exists( 'WP_Filesystem' ) ) {
2038 require_once ABSPATH . 'wp-admin/includes/file.php';
2039 }
2040 WP_Filesystem();
2041
2042 // Define file size threshold (e.g., 10MB)
2043 $file_size_threshold = 10 * 1024 * 1024; // 10MB
2044
2045 // Initialize the file with table creation statement if it doesn't exist
2046
2047 $table = esc_sql( $table );
2048 $row2 = $wpdb->get_row( "SHOW CREATE TABLE `{$table}`", ARRAY_N ); // phpcs:ignore
2049 $initial_output = "\n\n" . $row2[1] . ";\n\n";
2050
2051 $use_php_methods = false;
2052 if ( $wp_filesystem->exists( $file_path ) ) {
2053 // Check file size
2054 $file_size = $wp_filesystem->size( $file_path );
2055 if ( $file_size !== false && $file_size > $file_size_threshold ) {
2056 $use_php_methods = true;
2057 }
2058 }
2059
2060 // Function to append content
2061 $append_content = function( $new_content ) use ( $file_path, $wp_filesystem, $use_php_methods ) {
2062 if ( $use_php_methods ) {
2063 // Using PHP methods to append
2064 if ( ! $wp_filesystem->exists( $file_path ) ) {
2065 // phpcs:ignore -- WP Filesystem fileing for large files
2066 file_put_contents( $file_path, $new_content );
2067 } else {
2068 // phpcs:ignore -- WP Filesystem fileing for large files
2069 file_put_contents( $file_path, $new_content, FILE_APPEND );
2070 }
2071 } else {
2072 // Use WP Filesystem to append
2073 if ( ! $wp_filesystem->exists( $file_path ) ) {
2074 $wp_filesystem->put_contents( $file_path, $new_content, FS_CHMOD_FILE );
2075 } else {
2076 // Read current contents
2077 $current_contents = $wp_filesystem->get_contents( $file_path );
2078 if ( $current_contents === false ) {
2079 // Handle error if reading fails
2080 return false;
2081 }
2082 // Append new content
2083 $updated_contents = $current_contents . $new_content;
2084 // Write back updated contents
2085 if ( ! $wp_filesystem->put_contents( $file_path, $updated_contents, FS_CHMOD_FILE ) ) {
2086 // Handle error if writing fails
2087 return false;
2088 }
2089 }
2090 }
2091 return true;
2092 };
2093
2094 // Write the initial output to the file
2095 if ( ! $append_content( $initial_output ) ) {
2096 return false; // Handle error if initial content writing fails
2097 }
2098
2099 $sub_limit = 500;
2100 // phpcs:ignore
2101 $check_count = $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" );
2102 $check_count = intval( $check_count );
2103
2104 if ( $check_count > $sub_limit ) {
2105 $t_sub_queries = ceil( $check_count / $sub_limit );
2106
2107 for ( $sub_i = 0; $sub_i < $t_sub_queries; $sub_i++ ) {
2108 $sub_offset = $sub_i * $sub_limit;
2109 $sub_result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$table}` LIMIT %d OFFSET %d", array( $sub_limit, $sub_offset ) ), ARRAY_A ); // phpcs:ignore
2110
2111 if ( $sub_result ) {
2112 $output = '';
2113 foreach ( $sub_result as $row ) {
2114 $output .= 'INSERT INTO ' . $table . ' VALUES(';
2115 $result_o_index = count( $row );
2116 $j = 0;
2117 foreach ( $row as $key => $value ) {
2118 $row[ $key ] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $value, $table, $key ) );
2119 $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2120 if ( $j < ( $result_o_index - 1 ) ) {
2121 $output .= ',';
2122 }
2123 $j++;
2124 }
2125 $output .= ");\n";
2126 }
2127 // Append to the file
2128 if ( ! $append_content( $output ) ) {
2129 return false; // Handle error if appending content fails
2130 }
2131 }
2132 sleep(1);
2133 }
2134 } else {
2135 $result = $wpdb->get_results( "SELECT * FROM `{$table}`", ARRAY_A ); // phpcs:ignore
2136
2137 $output = '';
2138 foreach ( $result as $row ) {
2139 $output .= 'INSERT INTO ' . $table . ' VALUES(';
2140 $result_o_index = count( $row );
2141 $j = 0;
2142 foreach ( $row as $key => $value ) {
2143 $row[ $key ] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $value, $table, $key ) );
2144 $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2145 if ( $j < ( $result_o_index - 1 ) ) {
2146 $output .= ',';
2147 }
2148 $j++;
2149 }
2150 $output .= ");\n";
2151 }
2152 // Append to the file
2153 if ( ! $append_content( $output ) ) {
2154 return false; // Handle error if appending content fails
2155 }
2156 }
2157
2158 // Flush the database cache
2159 $wpdb->flush();
2160 return true;
2161 }
2162
2163
2164 /**
2165 * Mysql Dump set path.
2166 *
2167 * @param string $path - Path.
2168 */
2169 public function set_mysqldump_command_path( $path ) {
2170 $this->mysqldump_command_path = $path;
2171 }
2172
2173 /**
2174 * Mysql Dump get path.
2175 */
2176 public function get_mysqldump_command_path() {
2177
2178 // Check shell_exec is available.
2179 if ( ! self::is_shell_exec_available() ) {
2180 return '';
2181 }
2182
2183 // Return now if it's already been set.
2184 if ( isset( $this->mysqldump_command_path ) ) {
2185 return $this->mysqldump_command_path;
2186 }
2187
2188 $this->mysqldump_command_path = '';
2189
2190 // Does mysqldump work.
2191 if ( is_null( shell_exec( 'hash mysqldump 2>&1' ) ) ) { // phpcs:ignore
2192
2193 // If so store it for later.
2194 $this->set_mysqldump_command_path( 'mysqldump' );
2195
2196 // And return now.
2197 return $this->mysqldump_command_path;
2198 }
2199
2200 // List of possible mysqldump locations.
2201 $mysqldump_locations = array(
2202 '/usr/local/bin/mysqldump',
2203 '/usr/local/mysql/bin/mysqldump',
2204 '/usr/mysql/bin/mysqldump',
2205 '/usr/bin/mysqldump',
2206 '/opt/local/lib/mysql6/bin/mysqldump',
2207 '/opt/local/lib/mysql5/bin/mysqldump',
2208 '/opt/local/lib/mysql4/bin/mysqldump',
2209 '/xwpdbbkpp/mysql/bin/mysqldump',
2210 '/Program Files/xwpdbbkpp/mysql/bin/mysqldump',
2211 '/Program Files/MySQL/MySQL Server 6.0/bin/mysqldump',
2212 '/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump',
2213 '/Program Files/MySQL/MySQL Server 5.4/bin/mysqldump',
2214 '/Program Files/MySQL/MySQL Server 5.1/bin/mysqldump',
2215 '/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump',
2216 '/Program Files/MySQL/MySQL Server 4.1/bin/mysqldump',
2217 );
2218
2219 // Find the one which works.
2220 foreach ( $mysqldump_locations as $location ) {
2221 if ( is_executable( self::conform_dir( $location ) ) ) {
2222 $this->set_mysqldump_command_path( $location );
2223 }
2224 }
2225
2226 return $this->mysqldump_command_path;
2227 }
2228
2229 /**
2230 * Check dir.
2231 *
2232 * @param string $dir - Dir Details.
2233 * @param bool $recursive - Recursive.
2234 */
2235 public static function conform_dir( $dir, $recursive = false ) {
2236
2237 // Assume empty dir is root.
2238 if ( ! $dir ) {
2239 $dir = '/';
2240 }
2241
2242 // Replace single forward slash (looks like double slash because we have to escape it).
2243 $dir = str_replace( '\\', '/', $dir );
2244 $dir = str_replace( '//', '/', $dir );
2245
2246 // Remove the trailing slash.
2247 if ( '/' !== $dir ) {
2248 $dir = untrailingslashit( $dir );
2249 }
2250
2251 // Carry on until completely normalized.
2252 if ( ! $recursive && self::conform_dir( $dir, true ) !== $dir ) {
2253 return self::conform_dir( $dir );
2254 }
2255
2256 return (string) $dir;
2257 }
2258
2259 /**
2260 * Check Shell.
2261 */
2262 public static function is_shell_exec_available() {
2263
2264 // Are we in Safe Mode.
2265 if ( self::is_safe_mode_active() ) {
2266 return false;
2267 }
2268
2269 // Is shell_exec or escapeshellcmd or escapeshellarg disabled?
2270 if ( array_intersect( array( 'shell_exec', 'escapeshellarg', 'escapeshellcmd' ), array_map( 'trim', explode( ',', ini_get( 'disable_functions' ) ) ) ) ) {
2271 return false;
2272 }
2273
2274 // Can we issue a simple echo command?
2275 if ( ! shell_exec( 'echo WP Backup' ) ) { // phpcs:ignore
2276 return false;
2277 }
2278
2279 return true;
2280 }
2281
2282 /**
2283 * Check Safe mode active.
2284 *
2285 * @param string $ini_get_callback - String cmd.
2286 * @return bool
2287 */
2288 public static function is_safe_mode_active( $ini_get_callback = 'ini_get' ) {
2289 $safe_mode = call_user_func( $ini_get_callback, 'safe_mode' );
2290 if ( ( $safe_mode ) && 'off' !== strtolower( $safe_mode ) ) {
2291 return true;
2292 }
2293
2294 return false;
2295 }
2296
2297 /**
2298 * Database dump.
2299 *
2300 * @param string $sql_filename - File name.
2301 */
2302 public function mysqldump( $sql_filename ) {
2303 $this->mysqldump_method = 'mysqldump';
2304
2305 $host = explode( ':', DB_HOST );
2306
2307 $host = reset( $host );
2308 $port = strpos( DB_HOST, ':' ) ? end( explode( ':', DB_HOST ) ) : '';
2309
2310 // Path to the mysqldump executable.
2311 $cmd = escapeshellarg( $this->get_mysqldump_command_path() );
2312
2313 // We don't want to create a new DB.
2314 $cmd .= ' --no-create-db';
2315
2316 // Allow lock-tables to be overridden.
2317 if ( ! defined( 'WPDB_MYSQLDUMP_SINGLE_TRANSACTION' ) || WPDB_MYSQLDUMP_SINGLE_TRANSACTION !== false ) {
2318 $cmd .= ' --single-transaction';
2319 }
2320
2321 // Make sure binary data is exported properly.
2322 $cmd .= ' --hex-blob';
2323
2324 // Username.
2325 $cmd .= ' -u ' . escapeshellarg( DB_USER );
2326
2327 // Don't pass the password if it's blank.
2328 if ( DB_PASSWORD ) {
2329 $cmd .= ' -p' . escapeshellarg( DB_PASSWORD );
2330 }
2331
2332 // Set the host.
2333 $cmd .= ' -h ' . escapeshellarg( $host );
2334
2335 // Set the port if it was set.
2336 if ( ! empty( $port ) && is_numeric( $port ) ) {
2337 $cmd .= ' -P ' . $port;
2338 }
2339
2340 // The file we're saving too.
2341 $cmd .= ' -r ' . escapeshellarg( $sql_filename );
2342
2343 $wp_db_exclude_table = array();
2344 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
2345 if ( ! empty( $wp_db_exclude_table ) ) {
2346 foreach ( $wp_db_exclude_table as $wp_db_exclude_table ) {
2347 $cmd .= ' --ignore-table=' . DB_NAME . '.' . $wp_db_exclude_table;
2348 }
2349 }
2350
2351 // The database we're dumping.
2352 $cmd .= ' ' . escapeshellarg( DB_NAME );
2353
2354 // Pipe STDERR to STDOUT.
2355 $cmd .= ' 2>&1';
2356 // Store any returned data in an error.
2357 $stderr = shell_exec( $cmd ); // phpcs:ignore
2358
2359 // Skip the new password warning that is output in mysql > 5.6.
2360 if ( trim( $stderr ) === 'Warning: Using a password on the command line interface can be insecure.' ) {
2361 $stderr = '';
2362 }
2363
2364 if ( $stderr ) {
2365 $this->error( $this->get_mysqldump_method(), $stderr );
2366 }
2367
2368 return $this->verify_mysqldump( $sql_filename );
2369 }
2370
2371 /**
2372 * Error.
2373 *
2374 * @param string $context - Data.
2375 * @param object $error - Error data.
2376 */
2377 public function error( $context, $error ) {
2378 if ( empty( $context ) || empty( $error ) ) {
2379 return;
2380 }
2381 $error_str = implode( ':', (array) $error );
2382 $_key = md5( $error_str );
2383 $this->errors[ $context ][ $_key ] = $error;
2384 }
2385
2386 /**
2387 * Verify Dump.
2388 *
2389 * @param string $sql_filename - Sql file.
2390 * @return bool
2391 */
2392 public function verify_mysqldump( $sql_filename ) {
2393
2394 // If we've already passed then no need to check again.
2395 if ( ! empty( $this->mysqldump_verified ) ) {
2396 return true;
2397 }
2398
2399 // If there are mysqldump errors delete the database dump file as mysqldump will still have written one.
2400 if ( $this->get_errors( $this->get_mysqldump_method() ) && file_exists( $sql_filename ) ) {
2401 if ( file_exists( $sql_filename ) ) {
2402 wp_delete_file( $sql_filename );
2403 }
2404 }
2405
2406 // If we have an empty file delete it.
2407 if ( 0 === filesize( $sql_filename ) ) {
2408 if ( file_exists( $sql_filename ) ) {
2409 wp_delete_file( $sql_filename );
2410 }
2411 }
2412
2413 // If the file still exists then it must be good.
2414 if ( file_exists( $sql_filename ) ) {
2415 $this->mysqldump_verified = true;
2416 return $this->mysqldump_verified;
2417 }
2418
2419 return false;
2420 }
2421
2422 /**
2423 * Get error.
2424 *
2425 * @param string $context - Data.
2426 * @return string
2427 */
2428 public function get_errors( $context = null ) {
2429 if ( ! empty( $context ) ) {
2430 return isset( $this->errors[ $context ] ) ? $this->errors[ $context ] : array();
2431 }
2432
2433 return $this->errors;
2434 }
2435
2436 /**
2437 * Get mysql dump method.
2438 *
2439 * @return string
2440 */
2441 public function get_mysqldump_method() {
2442 return $this->mysqldump_method;
2443 }
2444
2445 // End : Generate SQL DUMP using cmd 06-03-2016.
2446
2447 /**
2448 * Create zip.
2449 */
2450 public function wp_db_backup_create_archive() {
2451 // Begin : Setup Upload Directory, Secure it and generate a random file name.
2452
2453 $source_directory = $this->wp_db_backup_wp_config_path();
2454
2455 $path_info = wp_upload_dir();
2456 $htasses_text = '';
2457 global $wpdb,$wp_filesystem;
2458 if ( ! function_exists( 'WP_Filesystem' ) ) {
2459 require_once ABSPATH . '/wp-admin/includes/file.php';
2460 }
2461 WP_Filesystem();
2462
2463 if(!$wp_filesystem){
2464 error_log('Could not initialize WP_Filesystem');
2465 return false;
2466 }
2467
2468 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR);
2469 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log');
2470 $file_contents = "<?php\n// Silence is golden.\n";
2471
2472 // Create the file with the given contents
2473 $wp_filesystem->put_contents( $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/index.php', $file_contents, FS_CHMOD_FILE );
2474 $wp_filesystem->put_contents( $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/index.php', $file_contents, FS_CHMOD_FILE );
2475
2476
2477 // Added htaccess file 08-05-2015 for prevent directory listing.
2478 // Fixed Vulnerability 22-06-2016 for prevent direct download.
2479 if ( 1 === (int) get_option( 'wp_db_backup_enable_htaccess' ) ) {
2480 $htaccess_content = '#These next two lines will already exist in your .htaccess file
2481 RewriteEngine On
2482 RewriteBase /
2483 # Add these lines right after the preceding two
2484 RewriteCond %{REQUEST_FILENAME} ^.*(.zip)$
2485 RewriteCond %{HTTP_COOKIE} !^.*can_download.*$ [NC]
2486 RewriteRule . - [R=403,L]';
2487 $wp_filesystem->put_contents( $path_info['basedir'] . '/db-backup/.htaccess', $htaccess_content, FS_CHMOD_FILE );
2488
2489 }
2490 // Begin : Generate SQL DUMP and save to file database.sql.
2491 $wp_site_name = preg_replace('/[^\p{L}\p{M}]+/u', '_', get_bloginfo('name'));
2492 $wp_db_file_name = $wp_site_name . '_' . gmdate( 'Y_m_d' ) . '_' . time() . '_' . substr( md5( AUTH_KEY ), 0, 7 ) . '_wpdb';
2493 $sql_filename = $wp_db_file_name . '.sql';
2494 $filename = $wp_db_file_name . '.zip';
2495 $logname = $wp_db_file_name . '.txt';
2496
2497 // Begin : Generate SQL DUMP using cmd 06-03-2016.
2498 $my_sql_dump = 0;
2499 if ( $this->get_mysqldump_command_path() ) {
2500 if ( ! $this->mysqldump( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) {
2501 $my_sql_dump = 1;
2502 }
2503 } else {
2504 $my_sql_dump = 1;
2505 }
2506
2507 if ( 1 === (int) $my_sql_dump ) {
2508 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2509 $options_backup = get_option( 'wp_db_backup_backups' );
2510 $settings_backup = get_option( 'wp_db_backup_options' );
2511 $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
2512 if($wp_db_save_settings_in_backup){
2513 delete_option( 'wp_db_backup_backups' );
2514 delete_option( 'wp_db_backup_options' );
2515 }
2516 /* END : Prevent saving backup plugin settings in the database dump */
2517 //phpcs:ignore -- using direct query get all tables name to be backedup.
2518 $tables = $wpdb->get_col( 'SHOW TABLES' );
2519 $wp_db_exclude_table = get_option( 'wp_db_exclude_table',array());
2520 if(!empty($tables)){
2521 foreach($tables as $table){
2522 if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
2523 $this->wp_db_backup_create_mysql_backup_new($table, $path_info['basedir'] . '/db-backup/' . $sql_filename );
2524 }
2525 }
2526
2527 }
2528 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2529 $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
2530 add_option( 'wp_db_backup_backups', $options_backup );
2531 add_option( 'wp_db_backup_options', $settings_backup );
2532 /* END : Prevent saving backup plugin settings in the database dump */
2533 }
2534 /* End : Generate SQL DUMP using cmd 06-03-2016 */
2535
2536 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
2537 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
2538 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
2539 $filecontent = wp_remote_get( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2540 if (! is_wp_error( $filecontent ) && isset($filecontent['body']) ) {
2541 $backup_str = str_replace( $wp_db_backup_search_text, $wp_db_backup_replace_text, $filecontent['body'] );
2542 $wp_filesystem->put_contents( $path_info['basedir'] . '/db-backup/' . $sql_filename, $backup_str, FS_CHMOD_FILE );
2543 }
2544 }
2545
2546 /* End : Generate SQL DUMP and save to file database.sql */
2547 $upload_path = array(
2548 'filename' => ( $filename ),
2549 'dir' => ( $path_info['basedir'] . '/db-backup/' . $filename ),
2550 'url' => ( $path_info['baseurl'] . '/db-backup/' . $filename ),
2551 'log_dir' => ( $path_info['basedir'] . '/db-backup/log/' . $logname ),
2552 'log_url' => ( $path_info['baseurl'] . '/db-backup/log/' . $logname ),
2553 'size' => 0,
2554 );
2555 $arcname = $path_info['basedir'] . '/db-backup/' . $wp_db_file_name . '.zip';
2556 if ( class_exists( 'ZipArchive' ) ) {
2557 $zip = new ZipArchive();
2558 $zip->open( $arcname, ZipArchive::CREATE );
2559 $zip->addFile( $path_info['basedir'] . '/db-backup/' . $sql_filename, $sql_filename );
2560 $zip->close();
2561 } else {
2562 require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
2563 $archive = new PclZip( $arcname );
2564 $v_dir = $path_info['basedir'] . '/db-backup/' . $sql_filename;
2565 $v_remove = $path_info['basedir'] . '/db-backup';
2566 // Create the archive.
2567 $v_list = $archive->create( $v_dir, PCLZIP_OPT_REMOVE_PATH, $v_remove );
2568 }
2569
2570
2571 $mysqlversion = wp_cache_get( 'wpdb_mysqlversion' );
2572 if ( true === empty( $mysqlversion ) ) {
2573 $mysqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' ); // phpcs:ignore
2574 wp_cache_set( 'wpdb_mysqlversion', $mysqlversion, '', 18000 );
2575 }
2576 if ( ! function_exists( 'get_plugins' ) ) {
2577 require_once ABSPATH . 'wp-admin/includes/plugin.php';
2578 }
2579 $my_theme = wp_get_theme();
2580 $active_plugin = count(get_option('active_plugins'));
2581 $total_plugin = count(get_plugins());
2582 $log_message = '<b>WordPress Version</b> : ' . get_bloginfo( 'version' );
2583 $log_message .= '<br> <b>Database Version</b> : ' . $mysqlversion;
2584 $log_message .= '<br> <b>Active Theme Name</b> : ' . $my_theme->get( 'Name' );
2585 $log_message .= '<br> <b>Theme Version</b> : ' . $my_theme->get( 'Version' );
2586 $log_message .= '<br> <b>Plugin Count</b> : ' . $total_plugin;
2587 $log_message .= '<br> <b>Active Plugins</b> : ' . $active_plugin;
2588
2589 $upload_path['size'] = filesize( $upload_path['dir'] );
2590 $upload_path['sqlfile'] = $path_info['basedir'] . '/db-backup/' . $sql_filename;
2591 $wp_db_log = get_option( 'wp_db_log' );
2592 if ( 1 === (int) $wp_db_log ) {
2593 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
2594 if ( ! empty( $wp_db_exclude_table ) ) {
2595 $log_message .= '<br> <b>Exclude Table</b> : ' . implode( ', ', $wp_db_exclude_table );
2596 }
2597 $upload_path['log'] = $log_message;
2598 }
2599 $options = get_option( 'wp_db_backup_backups' );
2600 $newoptions = array();
2601 $number_of_existing_backups = count( (array) $options );
2602 $number_of_backups_from_user = get_option( 'wp_local_db_backup_count' );
2603 if ( ! empty( $number_of_backups_from_user ) ) {
2604 if ( ! ( $number_of_existing_backups < $number_of_backups_from_user ) ) {
2605 $diff = $number_of_existing_backups - $number_of_backups_from_user;
2606 for ( $i = 0; $i <= $diff; $i++ ) {
2607 $index = $i;
2608 if ( isset($options[ $index ]['dir']) && file_exists( $options[ $index ]['dir'] ) ) {
2609 wp_delete_file( $options[ $index ]['dir'] );
2610 }
2611 $file_sql = explode( '.', $options[ $index ]['dir'] );
2612 if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) {
2613 wp_delete_file( $file_sql[0] . '.sql' );
2614 }
2615 }
2616 for ( $i = ( $diff + 1 ); $i < $number_of_existing_backups; $i++ ) {
2617 $index = $i;
2618
2619 $newoptions[] = $options[ $index ];
2620 }
2621 $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
2622
2623 update_option( 'wp_db_backup_backups', $newoptions , false);
2624 }
2625 }
2626
2627 if ( file_exists( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) {
2628 wp_delete_file( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2629 }
2630 return $upload_path;
2631 }
2632
2633 /**
2634 * Config Path.
2635 */
2636 public function wp_db_backup_wp_config_path() {
2637 $base = dirname( __FILE__ );
2638 $path = false;
2639 if ( file_exists( dirname( dirname( $base ) ) . '/wp-config.php' ) ) {
2640 $path = dirname( dirname( $base ) );
2641 } else {
2642 if ( file_exists( dirname( dirname( dirname( $base ) ) ) . '/wp-config.php' ) ) {
2643 $path = dirname( dirname( dirname( $base ) ) );
2644 } else {
2645 $path = false;
2646 }
2647 }
2648 if ( false !== $path ) {
2649 $path = str_replace( '\\', '/', $path );
2650 }
2651 return $path;
2652 }
2653
2654 /**
2655 * Backup Process.
2656 */
2657 public function wp_db_backup_event_process() {
2658 // Added in v.3.9.5!
2659 global $wp_filesystem;
2660 if(!function_exists('WP_Filesystem')){
2661 require_once ( ABSPATH . '/wp-admin/includes/file.php' );
2662 }
2663 WP_Filesystem();
2664
2665 $cron_condition = apply_filters('wpdbbkp_dbback_cron_condition',true );
2666 if(wp_doing_cron() && !$cron_condition){
2667 return false;
2668 }
2669
2670 set_time_limit( 0 );
2671 ignore_user_abort(true);
2672
2673 $details = $this->wp_db_backup_create_archive();
2674 $options = get_option( 'wp_db_backup_backups' );
2675
2676 if ( ! $options ) {
2677 $options = array();
2678 }
2679 $is_search_replace_flag = 0;
2680 $wp_db_log = get_option( 'wp_db_log' );
2681 if ( 1 === (int) $wp_db_log ) {
2682 $log_message = $details['log'];
2683 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
2684 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
2685 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
2686 $log_message .= ' Replaced/Search text - ' . $wp_db_backup_search_text . ' With -' . $wp_db_backup_replace_text;
2687 $is_search_replace_flag = 1;
2688 }
2689 } else {
2690 $log_message = '';
2691 }
2692 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
2693 $destination = ( 1 === (int) $wp_db_remove_local_backup ) ? '' : 'Local, ';
2694
2695 $args = array( $details['filename'], $details['dir'], $log_message, $details['size'], $destination );
2696 do_action_ref_array( 'wp_db_backup_completed', array( &$args ) );
2697
2698 $options[] = array(
2699 'date' => time(),
2700 'filename' => $details['filename'],
2701 'url' => $details['url'],
2702 'dir' => $details['dir'],
2703 'log' => $details['log_url'],
2704 'search_replace' => $is_search_replace_flag,
2705 'sqlfile' => $details['sqlfile'],
2706 'size' => $details['size'],
2707 'type' =>'database',
2708 'destination' => $args[4]
2709 );
2710 if ( 1 !== (int) $wp_db_remove_local_backup ) {
2711 $options = wpdbbkp_filter_unique_filenames( $options );
2712 update_option( 'wp_db_backup_backups', $options , false);
2713 }
2714 if(isset($details['log_dir']) && !empty($details['log_dir']))
2715 {
2716 if ($wp_filesystem->is_writable($details['log_dir']) || file_exists($details['log_dir'])) {
2717 $wp_filesystem->put_contents( $details['log_dir'], str_replace(array("<br>","<b>","</b>"), array("\n","",""), $args[2]), FS_CHMOD_FILE );
2718 }
2719 }
2720 }
2721
2722 /**
2723 * Cron schedule.
2724 *
2725 * @param array $schedules - Schedules details.
2726 */
2727 public function wp_db_backup_cron_schedules( $schedules ) {
2728 $schedules['hourly'] = array(
2729 'interval' => 3600,
2730 'display' => 'hourly',
2731 );
2732 $schedules['twicedaily'] = array(
2733 'interval' => 43200,
2734 'display' => 'twicedaily',
2735 );
2736 $schedules['daily'] = array(
2737 'interval' => 86400,
2738 'display' => 'daily',
2739 );
2740 $schedules['weekly'] = array(
2741 'interval' => 604800,
2742 'display' => 'Once Weekly',
2743 );
2744 $schedules['monthly'] = array(
2745 'interval' => 2635200,
2746 'display' => 'Once a month',
2747 );
2748 return $schedules;
2749 }
2750
2751 /**
2752 * Schedular activation.
2753 */
2754 public function wp_db_backup_scheduler_activation() {
2755 $options = get_option( 'wp_db_backup_options' );
2756 if ( ( ! wp_next_scheduled( 'wpdbbkp_db_backup_event' ) ) && ( true === isset( $options['enable_autobackups'] ) ) ) {
2757 $cron_freq = apply_filters( 'wpdbbkp_dbback_cron_frequency',$options['autobackup_frequency']);
2758 if(isset($options['autobackup_type']) && $options['autobackup_type'] == 'db')
2759 {
2760 $timestamp = strtotime('today 23:59'); // Start at the next midnight
2761 wp_schedule_event( $timestamp , $cron_freq, 'wpdbbkp_db_backup_event' );
2762
2763 }
2764 }else{
2765 if( !empty($options) && ( false === isset( $options['enable_autobackups'] ) ) || ( true === isset( $options['enable_autobackups'] ) ) && isset($options['autobackup_type']) && $options['autobackup_type'] != 'db')
2766 {
2767 wp_clear_scheduled_hook( 'wpdbbkp_db_backup_event' );
2768 }
2769
2770 }
2771 }
2772
2773 /**
2774 * Config data.
2775 *
2776 * @param string $key - key name.
2777 */
2778 public function wp_backup_get_config_data( $key ) {
2779 $filepath = get_home_path() . '/wp-config.php';
2780 $config_file = @file_get_contents( "$filepath", true );
2781 if($config_file){
2782 switch ( $key ) {
2783 case 'DB_NAME':
2784 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2785 break;
2786 case 'DB_USER':
2787 preg_match( "/'DB_USER',\s*'(.*)?'/", $config_file, $matches );
2788 break;
2789 case 'DB_PASSWORD':
2790 preg_match( "/'DB_PASSWORD',\s*'(.*)?'/", $config_file, $matches );
2791 break;
2792 case 'DB_HOST':
2793 preg_match( "/'DB_HOST',\s*'(.*)?'/", $config_file, $matches );
2794 break;
2795 }
2796 return $matches[1];
2797 }
2798
2799 return '';
2800
2801 }
2802
2803 /**
2804 * Get db name from config.
2805 */
2806 public function wp_backup_get_config_db_name() {
2807 $filepath = get_home_path() . '/wp-config.php';
2808 $config_file = @file_get_contents( "$filepath", true );
2809 if($config_file){
2810 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2811 return $matches[1];
2812 }
2813 return '';
2814 }
2815
2816 /**
2817 * Recursive sanitation for an array
2818 *
2819 * @param array $array - Array data to sanitize.
2820 *
2821 * @return mixed
2822 */
2823 public function recursive_sanitize_text_field( $array ) {
2824 if( ! is_array( $array ) ) {
2825 return sanitize_text_field( $array );
2826 }
2827 foreach ( $array as $key => &$value ) {
2828 if ( is_array( $value ) ) {
2829 $value = $this->recursive_sanitize_text_field( $value );
2830 } else {
2831 $value = sanitize_text_field( $value );
2832 }
2833 }
2834
2835 return $array;
2836 }
2837
2838 /**
2839 * Enqueue scripts and style
2840 */
2841 public function admin_scripts_style() {
2842 if ( true === $this->is_wpdb_page() ) {
2843 wp_enqueue_script( 'jquery' );
2844
2845 wp_register_script( 'bootstrapjs', WPDB_PLUGIN_URL . '/assets/js/bootstrap.min.js', array( 'jquery' ), WPDB_VERSION, false );
2846 wp_enqueue_script( 'bootstrapjs' );
2847
2848 wp_register_style( 'bootstrapcss', WPDB_PLUGIN_URL . '/assets/css/bootstrap.min.css', array(), WPDB_VERSION );
2849 wp_enqueue_style( 'bootstrapcss' );
2850
2851 wp_register_script( 'dataTablesjs', WPDB_PLUGIN_URL . '/assets/js/jquery.dataTables.js', array( 'jquery' ), WPDB_VERSION, false );
2852 wp_enqueue_script( 'dataTablesjs' );
2853
2854 wp_register_style( 'dataTablescss', WPDB_PLUGIN_URL . '/assets/css/jquery.dataTables.css', array(), WPDB_VERSION );
2855 wp_enqueue_style( 'dataTablescss' );
2856
2857 wp_register_style( 'wpdbcss', WPDB_PLUGIN_URL . '/assets/css/wpdb_admin.css', array(), WPDB_VERSION );
2858 wp_enqueue_style( 'wpdbcss' );
2859 }
2860 }
2861
2862 /**
2863 * Check is plugin page.
2864 */
2865 public function is_wpdb_page() {
2866
2867 if ( is_admin() ) {
2868
2869 return isset( $_REQUEST['page'] ) && preg_match( '/wp-database-backup/', $_REQUEST['page'] ) ? true : false; // phpcs:ignore
2870
2871 } else {
2872
2873 return true;
2874 }
2875 }
2876
2877 // loading admin scripts/styles on admin page only
2878
2879 public function wpdbbkp_admin_style($hook_suffix)
2880 {
2881 if($hook_suffix=="tools_page_wp-database-backup" || $hook_suffix=="toplevel_page_wp-database-backup")
2882 {
2883 wp_register_script('wpdbbkp-admin-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin.js', array('jquery'), WPDB_VERSION, 'true' );
2884 wp_localize_script('wpdbbkp-admin-script', 'wpdbbkp_script_vars', array(
2885 'nonce' => wp_create_nonce( 'wpdbbkp-admin-nonce' ),
2886 'siteurl' => base64_encode(site_url( )),
2887 'ud'=>wpdbbkp_get_current_user_name_email(),
2888 'is_subscribed'=>wpdbbkp_if_remote_active(),
2889 ));
2890 wp_enqueue_script('wpdbbkp-admin-script');
2891
2892 // Adding custom js
2893 $local = array(
2894 'ajax_url' => admin_url( 'admin-ajax.php' ),
2895 'wpdbbkp_admin_security_nonce' => wp_create_nonce('wpdbbkp_ajax_check_nonce'),
2896 );
2897 wp_register_script('wpdbbkp-admin-fb', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin-cron-backup.js', array(), WPDB_VERSION , true );
2898
2899 wp_localize_script('wpdbbkp-admin-fb', 'wpdbbkp_localize_admin_data', $local );
2900 wp_enqueue_script('wpdbbkp-admin-fb');
2901 // Custom Js ends
2902 }
2903 }
2904
2905 public function wpdbbkp_admin_newsletter_script($hook_suffix ) {
2906 if($hook_suffix=="tools_page_wp-database-backup" || $hook_suffix=="toplevel_page_wp-database-backup")
2907 {
2908 wp_enqueue_script('wpdbbkp-admin-newsletter-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin-newsletter.js', array('jquery'), WPDB_VERSION, 'true' );
2909
2910 $current_screen = get_current_screen();
2911
2912 if(isset($current_screen->post_type)){
2913 $post_type = $current_screen->post_type;
2914 }
2915
2916 $post_id = get_the_ID();
2917 //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2918 if(isset($_GET['tag_ID'])){
2919 //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2920 $post_id = intval($_GET['tag_ID']);
2921 }
2922
2923
2924
2925 $data = array(
2926 'current_url' => wpdbbkp_get_current_url(),
2927 'post_id' => $post_id,
2928 'ajax_url' => admin_url( 'admin-ajax.php' ),
2929 'post_type' => $post_type,
2930 'page_now' => $hook_suffix,
2931 'wpdbbkp_security_nonce' => wp_create_nonce('wpdbbkp_ajax_check_nonce'),
2932 );
2933
2934 $data = apply_filters('wpdbbkp_localize_filter',$data,'wpdbbkp_localize_data');
2935
2936 wp_localize_script( 'wpdbbkp-admin-newsletter-script', 'wpdbbkp_localize_data', $data );
2937
2938 }
2939
2940 }
2941
2942 public function wpdbbkp_sanitize_textarea_field( $str ) {
2943
2944 if ( is_object( $str ) || is_array( $str ) ) {
2945 return '';
2946 }
2947
2948 $str = (string) $str;
2949
2950 $filtered = wp_check_invalid_utf8( $str );
2951
2952 if ( strpos( $filtered, '<' ) !== false ) {
2953 $filtered = wp_pre_kses_less_than( $filtered );
2954 // This will strip extra whitespace for us.
2955 $filtered = wp_strip_all_tags( $filtered, false );
2956
2957 // Use HTML entities in a special case to make sure no later
2958 // newline stripping stage could lead to a functional tag.
2959 $filtered = str_replace( "<\n", "&lt;\n", $filtered );
2960 }
2961
2962 $filtered = trim( $filtered );
2963
2964 $found = false;
2965 while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
2966 $filtered = str_replace( $match[0], '', $filtered );
2967 $found = true;
2968 }
2969
2970 if ( $found ) {
2971 // Strip out the whitespace that may now exist after removing the octets.
2972 $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
2973 }
2974
2975 return $filtered;
2976 }
2977
2978 public function wpdbbkp_send_query_message(){
2979
2980 if ( ! isset( $_POST['wpdbbkp_security_nonce'] ) ){
2981 return;
2982 }
2983 if ( !wp_verify_nonce( $_POST['wpdbbkp_security_nonce'], 'wpdbbkp-admin-nonce' ) ){
2984 return;
2985 }
2986
2987 if( ! current_user_can( 'manage_options' ) ) {
2988 return;
2989 }
2990
2991 $message = $this->wpdbbkp_sanitize_textarea_field($_POST['message']);
2992 $email = $this->wpdbbkp_sanitize_textarea_field($_POST['email']);
2993
2994 if(function_exists('wp_get_current_user')){
2995
2996 $user = wp_get_current_user();
2997
2998 $message = '<p>'.$message.'</p><br><br>'.'Query from BackupforWP plugin support tab';
2999
3000 $user_data = $user->data;
3001 $user_email = $user_data->user_email;
3002
3003 if($email){
3004 $user_email = $email;
3005 }
3006 //php mailer variables
3007 $sendto = 'team@magazine3.in';
3008 $subject = "BackupforWP Query";
3009
3010 $headers[] = 'Content-Type: text/html; charset=UTF-8';
3011 $headers[] = 'From: '. esc_attr($user_email);
3012 $headers[] = 'Reply-To: ' . esc_attr($user_email);
3013 // Load WP components, no themes.
3014
3015 $sent = wp_mail($sendto, $subject, $message, $headers);
3016
3017 if($sent){
3018
3019 echo wp_json_encode(array('status'=>'t'));
3020
3021 }else{
3022
3023 echo wp_json_encode(array('status'=>'f'));
3024
3025 }
3026
3027 }
3028
3029 wp_die();
3030 }
3031 public function add_settings_plugin_action_wp( $actions, $plugin_file, $plugin_data, $context ) {
3032 $plugin_actions['settings'] = sprintf(
3033 '<a href="%s">' . _x( 'Settings', 'wpdbbkp' ) . '</a>',
3034 admin_url( 'options-general.php?page=wp-database-backup' )
3035 );
3036 $actions = array_merge( $actions, $plugin_actions );
3037 return $actions;
3038 }
3039
3040 public function wpdbbkp_update_backup_info($FileName, $logFile, $logMessage = '') {
3041 $path_info = wp_upload_dir();
3042 $filename = $FileName . '.sql';
3043 $WPDBFileName = $FileName . '.zip';
3044 wp_delete_file($this->wp_db_backup_wp_config_path() . '/' . $filename);
3045 wp_delete_file($this->wp_db_backup_wp_config_path() . '/wp_installer.php');
3046 @$filesize = filesize($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName);
3047
3048 $upload_path = array(
3049 'filename' => ($WPDBFileName),
3050 'dir' => ($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName),
3051 'url' => ($path_info['baseurl'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName),
3052 'size' => ($filesize),
3053 'type' => get_option('wp_db_backup_backup_type')
3054 );
3055
3056
3057 if (get_option('wp_db_log') == 1) {
3058 $this->write_log($logFile, $logMessage);
3059 $upload_path['logfile'] = $path_info['baseurl'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $FileName . '.txt';
3060 $upload_path['logfileDir'] = $logFile;
3061 } else {
3062 $upload_path['logfile'] = "";
3063 }
3064 $args = array($FileName, $logFile, $logMessage);
3065 do_action_ref_array('wpdbbkp_backup_completed', array(&$args));
3066 return $upload_path;
3067 }
3068
3069 private function write_log($logFile, $logMessage) {
3070 // Actually write the log file
3071 global $wp_filesystem;
3072 if(!function_exists('WP_Filesystem')){
3073 require_once ( ABSPATH . '/wp-admin/includes/file.php' );
3074 }
3075 WP_Filesystem();
3076
3077 if ($wp_filesystem && $wp_filesystem->is_writable($logFile) || !$wp_filesystem->exists($logFile)) {
3078 $wp_filesystem->put_contents( $logFile, $logMessage, FS_CHMOD_FILE );
3079 return true;
3080 }
3081 }
3082
3083 public function get_zip_command_path() {
3084
3085 // Check shell_exec is available
3086 if (!self::is_shell_exec_available())
3087 return '';
3088
3089 // Return now if it's already been set
3090 if (isset($this->zip_command_path))
3091 return $this->zip_command_path;
3092
3093 $this->zip_command_path = '';
3094
3095 // Does zip work
3096 if (is_null(shell_exec('hash zip 2>&1'))) {
3097
3098 // If so store it for later
3099 $this->set_zip_command_path('zip');
3100
3101 // And return now
3102 return $this->zip_command_path;
3103 }
3104
3105 // List of possible zip locations
3106 $zip_locations = array(
3107 '/usr/bin/zip'
3108 );
3109
3110 // Find the one which works
3111 foreach ($zip_locations as $location)
3112 if (@is_executable(self::conform_dir($location)))
3113 $this->set_zip_command_path($location);
3114
3115 return $this->zip_command_path;
3116 }
3117
3118 public function set_zip_command_path($path) {
3119
3120 $this->zip_command_path = $path;
3121 }
3122
3123 /* Begin : Generate Zip using cmd 06-03-2016 V.3.9 */
3124
3125 public function zip($WPDBFileName) {
3126
3127 $this->archive_method = 'zip';
3128 $wp_all_backup_exclude_dir = get_option('wp_db_backup_exclude_dir');
3129 if (empty($wp_all_backup_exclude_dir)) {
3130 $excludes = WPDB_BACKUPS_DIR;
3131 } else {
3132 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
3133 }
3134 // Zip up $this->root with excludes
3135 if (!empty($excludes)) {
3136 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' -x ' . $this->exclude_string('zip') . ' 2>&1');
3137 }
3138
3139 // Zip up $this->root without excludes
3140 else {
3141 // error_log('without exclude rule');
3142 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' 2>&1');
3143 }
3144 error_log($stderr);
3145 if (!empty($stderr))
3146 $this->warning($this->get_archive_method(), $stderr);
3147
3148 return $this->verify_archive($WPDBFileName);
3149 }
3150
3151 public function get_root() {
3152
3153 if (empty($this->root))
3154 $this->set_root(self::conform_dir(self::get_home_path()));
3155
3156 return $this->root;
3157 }
3158
3159 public function set_root($path) {
3160
3161 if (empty($path) || !is_string($path) || !is_dir($path))
3162 throw new Exception('Invalid root path <code>' . esc_html($path) . '</code> must be a valid directory path');
3163
3164 $this->root = self::conform_dir($path);
3165 }
3166
3167 public static function get_home_path() {
3168
3169 $home_url = home_url();
3170 $site_url = site_url();
3171
3172 $home_path = ABSPATH;
3173
3174 // If site_url contains home_url and they differ then assume WordPress is installed in a sub directory
3175 if ($home_url !== $site_url && strpos($site_url, $home_url) === 0)
3176 $home_path = trailingslashit(substr(self::conform_dir(ABSPATH), 0, strrpos(self::conform_dir(ABSPATH), str_replace($home_url, '', $site_url))));
3177
3178 return self::conform_dir($home_path);
3179 }
3180
3181 private function warning($context, $warning) {
3182
3183 if (empty($context) || empty($warning))
3184 return;
3185 $this->warnings[$context][$_key = md5(implode(':', (array) $warning))] = $warning;
3186 }
3187
3188 public function exclude_string($context = 'zip') {
3189
3190 // Return a comma separated list by default
3191 $separator = ', ';
3192 $wildcard = '';
3193
3194 // The zip command
3195 if ($context === 'zip') {
3196 $wildcard = '*';
3197 $separator = ' -x ';
3198
3199 // The PclZip fallback library
3200 } elseif ($context === 'regex') {
3201 $wildcard = '([\s\S]*?)';
3202 $separator = '|';
3203 }
3204
3205 $wp_all_backup_exclude_dir = get_option('wp_db_backup_exclude_dir');
3206 if (empty($wp_all_backup_exclude_dir)) {
3207 $excludes = WPDB_BACKUPS_DIR;
3208 } else {
3209 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
3210 }
3211
3212 $excludes = explode("|", $excludes);
3213 if(!empty($excludes) && is_array($excludes)){
3214 foreach ($excludes as $key => &$rule) {
3215
3216 $file = $absolute = $fragment = false;
3217
3218 // Files don't end with /
3219 if (!in_array(substr($rule, -1), array('\\', '/')))
3220 $file = true;
3221
3222 // If rule starts with a / then treat as absolute path
3223 elseif (in_array(substr($rule, 0, 1), array('\\', '/')))
3224 $absolute = true;
3225
3226 // Otherwise treat as dir fragment
3227 else
3228 $fragment = true;
3229
3230 // Strip $this->root and conform
3231 $rule = str_ireplace($this->get_root(), '', untrailingslashit(self::conform_dir($rule)));
3232
3233 // Strip the preceeding slash
3234 if (in_array(substr($rule, 0, 1), array('\\', '/')))
3235 $rule = substr($rule, 1);
3236
3237 // Escape string for regex
3238 if ($context === 'regex')
3239 $rule = str_replace('.', '\.', $rule);
3240
3241 // Convert any existing wildcards
3242 if ($wildcard !== '*' && strpos($rule, '*') !== false)
3243 $rule = str_replace('*', $wildcard, $rule);
3244
3245 // Wrap directory fragments and files in wildcards for zip
3246 if ($context === 'zip' && ( $fragment || $file ))
3247 $rule = $wildcard . $rule . $wildcard;
3248
3249 // Add a wildcard to the end of absolute url for zips
3250 if ($context === 'zip' && $absolute)
3251 $rule .= $wildcard;
3252
3253 // Add and end carrot to files for pclzip but only if it doesn't end in a wildcard
3254 if ($file && $context === 'regex')
3255 $rule .= '$';
3256
3257 // Add a start carrot to absolute urls for pclzip
3258 if ($absolute && $context === 'regex')
3259 $rule = '^' . $rule;
3260 }
3261 }
3262
3263
3264 // Escape shell args for zip command
3265 if ($context === 'zip')
3266 $excludes = array_map('escapeshellarg', array_unique($excludes));
3267
3268 return implode($separator, $excludes);
3269 }
3270
3271 public function get_archive_method() {
3272 return $this->archive_method;
3273 }
3274
3275 public function verify_archive($WPDBFileName) {
3276 // If we've already passed then no need to check again
3277 if (!empty($this->archive_verified))
3278 return true;
3279
3280 // If there are errors delete the backup file.
3281 if ($this->get_errors($this->get_archive_method()) && file_exists($WPDBFileName))
3282 wp_delete_file($WPDBFileName);
3283
3284 // If the archive file still exists assume it's good
3285 if (file_exists($WPDBFileName))
3286 return $this->archive_verified = true;
3287
3288 return false;
3289 }
3290
3291 public function get_files() {
3292
3293 if (!empty($this->files))
3294 return $this->files;
3295
3296 $this->files = array();
3297
3298 // We only want to use the RecursiveDirectoryIterator if the FOLLOW_SYMLINKS flag is available
3299 if (defined('RecursiveDirectoryIterator::FOLLOW_SYMLINKS')) {
3300
3301 $this->files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->get_root(), RecursiveDirectoryIterator::FOLLOW_SYMLINKS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
3302
3303 // Skip dot files if the SKIP_Dots flag is available
3304 if (defined('RecursiveDirectoryIterator::SKIP_DOTS'))
3305 $this->files->setFlags(RecursiveDirectoryIterator::SKIP_DOTS + RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
3306
3307
3308 // If RecursiveDirectoryIterator::FOLLOW_SYMLINKS isn't available then fallback to a less memory efficient method
3309 } else {
3310
3311 $this->files = $this->get_files_fallback($this->get_root());
3312 }
3313
3314 return $this->files;
3315 }
3316
3317 public function wpdbbkp_get_timeago( $time )
3318 {
3319 $time = intval($time) > 0 ? intval($time) : time();
3320
3321 $time_difference = time() - $time;
3322
3323 if( $time_difference < 1 ) { return 'less than 1 second ago'; }
3324 $condition = array( 12 * 30 * 24 * 60 * 60 => 'year',
3325 30 * 24 * 60 * 60 => 'month',
3326 24 * 60 * 60 => 'day',
3327 60 * 60 => 'hour',
3328 60 => 'minute',
3329 1 => 'second'
3330 );
3331
3332 foreach( $condition as $secs => $str )
3333 {
3334 $d = $time_difference / $secs;
3335
3336 if( $d >= 1 )
3337 {
3338 $t = floor( $d );
3339 return 'About ' . $t . ' ' . $str . ( $t > 1 ? 's' : '' ) . ' ago';
3340 }
3341 }
3342 }
3343
3344 private function wpdbbkp_append_to_file($file_path, $content_to_append){
3345 global $wp_filesystem;
3346
3347 if (!function_exists('WP_Filesystem')) {
3348 require_once ABSPATH . 'wp-admin/includes/file.php';
3349 }
3350
3351
3352 if (empty($wp_filesystem)) {
3353 WP_Filesystem();
3354 }
3355
3356 if (!$wp_filesystem) {
3357 return false;
3358 }
3359
3360 // Check if the file exists
3361 if ($wp_filesystem->exists($file_path)) {
3362 // Open the file in append mode
3363 $handle = $wp_filesystem->get_contents($file_path);
3364
3365 if ($handle) {
3366 // Append the new content
3367 $result = $wp_filesystem->put_contents($file_path, $handle . $content_to_append, FS_CHMOD_FILE);
3368 return $result !== false;
3369 }
3370 } else {
3371 // If the file doesn't exist, create it with the initial content
3372 $result = $wp_filesystem->put_contents($file_path, $content_to_append, FS_CHMOD_FILE);
3373 return $result !== false;
3374 }
3375
3376 return false;
3377 }
3378
3379 }
3380
3381 new Wpdb_Admin();
3382