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

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