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

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