PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.1
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.1
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.1, at includes/admin/class-wpdb-admin.php

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