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

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