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

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