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

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