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

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