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

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