PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 6.5.1
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v6.5.1
7.13 7.12 trunk 1.1 2.1.1 5.9 6.0 6.1 6.10 6.11 6.12 6.12.1 6.2 6.3 6.4 6.5 6.5.1 6.6 6.7 6.8 6.9 7.0 7.0.1 7.1 7.10 All 34 releases
wp-database-backup / includes / admin / class-wpdb-admin.php

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

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