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

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

3,262 lines 135.7 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 ob_start();
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit; // Exit if accessed directly.
10 }
11
12 /**
13 * Main class wpdb_admin.
14 *
15 * @class Wpdb_Admin
16 */
17 class Wpdb_Admin {
18
19 public $mysqldump_command_path;
20 public $root;
21 public $files;
22
23 /**
24 * Construct.
25 */
26 public function __construct() {
27 add_action( 'admin_init', array( $this, 'wp_db_backup_admin_init' ) );
28 add_action( 'admin_init', array( $this, 'admin_scripts_style' ) );
29 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
30 add_filter( 'cron_schedules', array( $this, 'wp_db_backup_cron_schedules' ) );
31 add_action( 'wpdbbkp_db_backup_event', array( $this, 'wp_db_backup_event_process' ) );
32 add_action( 'init', array( $this, 'wp_db_backup_scheduler_activation' ) );
33 add_action( 'wp_logout', array( $this, 'wp_db_cookie_expiration' ) ); // Fixed Vulnerability 22-06-2016 for prevent direct download.
34 add_action( 'wp_db_backup_completed', array( $this, 'wp_db_backup_completed_local' ), 12 );
35 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_style'));
36 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_newsletter_script'));
37 add_action('wp_ajax_wpdbbkp_send_query_message', array( $this, 'wpdbbkp_send_query_message'));
38 add_filter( 'plugin_action_links_' . plugin_basename( WP_BACKUP_PLUGIN_FILE ), array( $this, 'add_settings_plugin_action_wp' ), 10, 4 );
39 add_action( 'admin_notices', array($this, 'check_ziparchive_avalable_admin_notice' ));
40
41 }
42
43 /**
44 * admin Notice.
45 */
46 public function check_ziparchive_avalable_admin_notice() {
47 if (!class_exists( 'ZipArchive' ) ) { ?>
48 <div class="notice notice-info is-dismissible"><p><strong><?php echo esc_html__('Info!', 'wpdbbkp') ?></strong> <?php echo esc_html__(' Enable Zip Extension in php.ini to work BackupForWP all functionality smoothly.', 'wpdbbkp') ?> </p></div>
49 <?php }
50 }
51
52 /**
53 * Backup Menu.
54 */
55 public function admin_menu() {
56 add_menu_page(
57 'Backups',
58 'Backups',
59 'manage_options',
60 'wp-database-backup',
61 array( $this, 'wp_db_backup_settings_page' ),
62 'dashicons-database-view',
63 99
64 );
65
66 add_submenu_page(
67 'wp-database-backup',
68 'Auto Scheduler',
69 'Auto Scheduler',
70 'manage_options',
71 'wp-database-backup#tab_db_schedul',
72 array($this, 'wp_db_backup_settings_page' ));
73
74 add_submenu_page(
75 'wp-database-backup',
76 'Save Backups to',
77 'Save Backups to',
78 'manage_options',
79 'wp-database-backup#tab_db_destination',
80 array($this, 'wp_db_backup_settings_page' ));
81
82 add_submenu_page(
83 'wp-database-backup',
84 'Settings',
85 'Settings',
86 'manage_options',
87 'wp-database-backup#tab_db_setting',
88 array($this, 'wp_db_backup_settings_page' ));
89
90
91
92 add_submenu_page(
93 'wp-database-backup',
94 'Help & Support',
95 'Help & Support',
96 'manage_options',
97 'wp-database-backup#tab_db_help',
98 array($this, 'wp_db_backup_settings_page' ));
99
100 if(!defined('BKPFORWP_VERSION')){
101 add_submenu_page(
102 'wp-database-backup',
103 'Upgrade to Premium',
104 'Upgrade to Premium',
105 'manage_options',
106 'wp-database-backup#tab_db_upgrade',
107 array($this, 'wp_db_backup_settings_page' ));
108 }
109 else{
110 add_submenu_page(
111 'wp-database-backup',
112 'Modules',
113 'Modules',
114 'manage_options',
115 'wp-database-backup#tab_db_features',
116 array($this, 'wp_db_backup_settings_page' ));
117 add_submenu_page(
118 'wp-database-backup',
119 'Licence',
120 'Licence',
121 'manage_options',
122 'wp-database-backup#tab_db_licence',
123 array($this, 'wp_db_backup_settings_page' ));
124 }
125
126
127
128 }
129
130 /**
131 * Start Fixed Vulnerability 22-06-2016 for prevent direct download.
132 */
133 public function wp_db_cookie_expiration() {
134 setcookie( 'can_download', 0, time() - 300, COOKIEPATH, COOKIE_DOMAIN );
135 if ( SITECOOKIEPATH !== COOKIEPATH ) {
136 setcookie( 'can_download', 0, time() - 300, SITECOOKIEPATH, COOKIE_DOMAIN );
137 }
138 }
139
140 /**
141 * If Checked then it will remove local backup after uploading to destination.
142 *
143 * @param array $args - backup details.
144 */
145 public function wp_db_backup_completed_local( &$args ) {
146 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
147 if ( 1 === $wp_db_remove_local_backup ) {
148 if ( file_exists( $args[1] ) ) {
149 wp_delete_file( $args[1] );// File path.
150 }
151 }
152 }
153
154 /**
155 * Admin init.
156 */
157 public function wp_db_backup_admin_init() {
158 //redirect to plugin page on activation
159 if (get_option('wpdbbkp_activation_redirect', false)) {
160 delete_option('wpdbbkp_activation_redirect');
161 if(!isset($_GET['activate-multi']))
162 {
163 wp_redirect("admin.php?page=wp-database-backup");
164 }
165 }
166
167 // Start Fixed Vulnerability 04-08-2016 for data save in options.
168 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] ) {
169 if ( ! empty( $_POST ) && ! ( isset( $_POST['option_page'] ) && 'wp_db_backup_options' === $_POST['option_page'] ) ) {
170 if ( false === isset( $_REQUEST['_wpnonce'] ) || false === wp_verify_nonce( $_REQUEST['_wpnonce'] , 'wp-database-backup' ) ) {
171 wp_die( esc_html__('WPDB :: Invalid Access', 'wpdbbkp' ) );
172 }
173 }
174
175 // End Fixed Vulnerability 04-08-2016 for data save in options.
176 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && current_user_can( 'manage_options' ) ) {
177 setcookie( 'can_download', 1, 0, COOKIEPATH, COOKIE_DOMAIN );
178 if ( SITECOOKIEPATH !== COOKIEPATH ) {
179 setcookie( 'can_download', 1, 0, SITECOOKIEPATH, COOKIE_DOMAIN );
180 }
181 } else {
182 setcookie( 'can_download', 0, time() - 300, COOKIEPATH, COOKIE_DOMAIN );
183 if ( SITECOOKIEPATH !== COOKIEPATH ) {
184 setcookie( 'can_download', 0, time() - 300, SITECOOKIEPATH, COOKIE_DOMAIN );
185 }
186 }
187 // End Fixed Vulnerability 22-06-2016 for prevent direct download.
188 if ( is_admin() && current_user_can( 'manage_options' ) ) {
189 if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'] , 'wp-database-backup' ) ) {
190 if ( isset( $_POST['wpsetting_search'] ) ) {
191 if ( isset( $_POST['wp_db_backup_search_text'] ) ) {
192 update_option( 'wp_db_backup_search_text', sanitize_text_field( wp_unslash( $_POST['wp_db_backup_search_text'] ) ), false );
193 }
194
195 $nonce = wp_create_nonce( 'wp-database-backup' );
196 wp_safe_redirect( esc_url( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=save&tab=searchreplace&_wpnonce=' . $nonce ) );
197 }
198
199 if ( isset( $_POST['wpsetting'] ) ) {
200 if ( isset( $_POST['wp_local_db_backup_count'] ) ) {
201 update_option( 'wp_local_db_backup_count', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wp_local_db_backup_count'] ) ) ) , false);
202 }
203
204 if ( isset( $_POST['wp_db_log'] ) ) {
205 update_option( 'wp_db_log', 1 , false);
206 } else {
207 update_option( 'wp_db_log', 0 , false);
208 }
209 if ( isset( $_POST['wp_db_remove_on_uninstall'] ) ) {
210 update_option( 'wp_db_remove_on_uninstall', 1 , false);
211 } else {
212 update_option( 'wp_db_remove_on_uninstall', 0 , false);
213 }
214 if ( isset( $_POST['wp_db_remove_local_backup'] ) ) {
215 update_option( 'wp_db_remove_local_backup', 1 , false);
216 } else {
217 update_option( 'wp_db_remove_local_backup', 0 , false);
218 }
219 if ( isset( $_POST['wp_db_save_settings_in_backup'] ) ) {
220 update_option( 'wp_db_save_settings_in_backup', 1 , false);
221 } else {
222 update_option( 'wp_db_save_settings_in_backup', 0 , false);
223 }
224 if ( isset( $_POST['wp_db_backup_enable_auto_upgrade'] ) ) {
225 update_option( 'wp_db_backup_enable_auto_upgrade', 1 , false);
226 } else {
227 update_option( 'wp_db_backup_enable_auto_upgrade', 0 , false);
228 }
229
230 if ( isset( $_POST['wp_db_backup_enable_htaccess'] ) ) {
231 update_option( 'wp_db_backup_enable_htaccess', 1 , false);
232 } else {
233 update_option( 'wp_db_backup_enable_htaccess', 0 , false);
234 $path_info = wp_upload_dir();
235 if ( file_exists( $path_info['basedir'] . '/db-backup/.htaccess' ) ) {
236 wp_delete_file( $path_info['basedir'] . '/db-backup/.htaccess' );
237 }
238 }
239
240 if ( isset( $_POST['wp_db_exclude_table'] ) ) {
241 update_option( 'wp_db_exclude_table', $this->recursive_sanitize_text_field( wp_unslash( $_POST['wp_db_exclude_table'] ) ) , false); // phpcs:ignore
242 } else {
243 update_option( 'wp_db_exclude_table', '', false );
244 }
245 $nonce = wp_create_nonce( 'wp-database-backup' );
246 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=save&_wpnonce=' . $nonce );
247 }
248
249 if ( true === isset( $_POST['wp_db_local_backup_path'] ) ) {
250 update_option( 'wp_db_local_backup_path', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wp_db_local_backup_path'] ) ) ) );
251 }
252
253 if ( isset( $_POST['wp_db_backup_email_id'] ) ) {
254 update_option( 'wp_db_backup_email_id', wp_db_filter_data( sanitize_email( wp_unslash( $_POST['wp_db_backup_email_id'] ) ) ) , false);
255 }
256
257 if ( isset( $_POST['wp_db_backup_email_attachment'] ) ) {
258 $email_attachment = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_email_attachment'] ) , false);
259 update_option( 'wp_db_backup_email_attachment', $email_attachment );
260 }
261 if ( isset( $_POST['local_backup_submit'] ) && 'Save Settings' === $_POST['local_backup_submit'] ) {
262 if ( true === isset( $_POST['wp_db_local_backup'] ) ) {
263 update_option( 'wp_db_local_backup', 1 , false);
264 } else {
265 update_option( 'wp_db_local_backup', 0 , false);
266 }
267 }
268
269 if ( isset( $_POST['wp_db_backup_options'] ) ) {
270 $option_to_save = [];
271 if ( isset( $_POST['wp_db_backup_options']['enable_autobackups'] ) ) {
272 $option_to_save['enable_autobackups'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['enable_autobackups'] ) );
273 }
274 if ( isset( $_POST['wp_db_backup_options']['autobackup_type'] ) ) {
275 $option_to_save['autobackup_type'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_type'] ) );
276 }
277 if ( isset( $_POST['wp_db_backup_options']['autobackup_frequency'] ) ) {
278 $option_to_save['autobackup_frequency'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_frequency'] ) );
279 }
280 if ( isset( $_POST['wp_db_backup_options']['autobackup_full_days'] ) ) {
281 $option_to_save['autobackup_full_days'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_days'] ) );
282 }
283 if ( isset( $_POST['wp_db_backup_options']['autobackup_full_time'] ) ) {
284 $option_to_save['autobackup_full_time'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_time'] ) );
285 }
286 if ( isset( $_POST['wp_db_backup_options']['autobackup_full_date'] ) ) {
287 $option_to_save['autobackup_full_date'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_date'] ) );
288 }
289 if(!empty($option_to_save)) {
290 if(update_option( 'wp_db_backup_options', $option_to_save, false)){
291 wp_clear_scheduled_hook( 'wpdbbkp_db_backup_event' );
292 wp_clear_scheduled_hook( 'wpdbkup_event_fullbackup' );
293 }
294 }
295
296 }
297
298 do_action('wpdbbkp_save_pro_options');
299 }
300 $wp_db_backup_destination_email = get_option( 'wp_db_backup_destination_Email' , false);
301
302 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && isset( $_GET['action'] ) && 'unlink' === $_GET['action'] ) {
303 // Specify the target directory and add forward slash.
304 $dir = plugin_dir_path( __FILE__ ) . 'Destination/Dropbox/tokens/';
305
306 // Open the directory.
307 $dir_handle = opendir( $dir );
308 // Loop over all of the files in the folder.
309 $file = readdir( $dir_handle );
310 while ( $file ) {
311 // If $file is NOT a directory remove it.
312 if ( ! is_dir( $file ) ) {
313 wp_delete_file( $dir . $file );
314 }
315 }
316 // Close the directory.
317 closedir( $dir_handle );
318 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup' );
319 }
320 $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
321 if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $nonce, 'wp-database-backup' ) ) {
322 if ( isset( $_GET['action'] ) && current_user_can( 'manage_options' ) ) {
323 switch ( (string) $_GET['action'] ) {
324 case 'createdbbackup':
325 $this->wp_db_backup_event_process();
326 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=create&_wpnonce=' . $nonce );
327 break;
328 case 'removebackup':
329 if ( true === isset( $_GET['index'] ) ) {
330 $index = (int) $_GET['index'];
331 $options = get_option( 'wp_db_backup_backups' );
332 $newoptions = array();
333 $count = 0;
334 if(!empty($options) && is_array($options)){
335 foreach ( $options as $option ) {
336 if ( $count !== $index ) {
337 $newoptions[] = $option;
338 }
339 $count++;
340 }
341 }
342
343 $upload_dir = wp_upload_dir();
344 $actual_working_directory = getcwd();
345 $file_directory = $upload_dir['basedir'].'/db-backup/';
346 /*
347 Fix for when you try to delete a file thats in a folder
348 higher in the hierarchy to your working directory */
349 chdir($file_directory);
350 if ( isset($options[ $index ]['filename']) && file_exists( $options[ $index ]['filename'] ) ) {
351 wp_delete_file( $options[ $index ]['filename'] );
352 }
353 if(isset($options[ $index ]['filename'])){
354 $file_sql = explode( '.', $options[ $index ]['filename'] );
355 if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) {
356 wp_delete_file( $file_sql[0] . '.sql' );
357 }
358 }
359
360 chdir($actual_working_directory);
361 $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
362 update_option( 'wp_db_backup_backups', $newoptions , false);
363 $nonce = wp_create_nonce( 'wp-database-backup' );
364 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=delete&_wpnonce=' . $nonce );
365 exit;
366
367 }
368 break;
369 case 'removeallbackup':
370
371 $upload_dir = wp_upload_dir();
372 $actual_working_directory = getcwd();
373 $file_directory = $upload_dir['basedir'];
374 /*
375 Fix for when you try to delete a file thats in a folder
376 higher in the hierarchy to your working directory
377 */
378 chdir($file_directory);
379 $files = glob($file_directory.'/db-backup'.'/*');
380
381 // Deleting all the files in the list
382 if(!empty($files)){
383 foreach($files as $file) {
384 if(is_file($file)){
385 wp_delete_file($file);
386 }
387 }
388 }
389 chdir($actual_working_directory);
390 update_option( 'wp_db_backup_backups', array() , false);
391 $nonce = wp_create_nonce( 'wp-database-backup' );
392 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=deleteall&_wpnonce=' . $nonce );
393 exit;
394
395
396 break;
397 case 'clear_temp_db_backup_file':
398 $options = get_option( 'wp_db_backup_backups' );
399 $newoptions = array();
400 $backup_check_list = array( '.htaccess', 'index.php' );
401 $delete_message = 'WPDB : Deleted Files:';
402 if(!empty($options) && is_array($options)){
403 foreach ( $options as $option ) {
404 if(!is_array($option)){
405 continue;
406 }
407 $backup_check_list[] = $option['filename'];
408 }
409 }
410 $path_info = wp_upload_dir();
411 $wp_db_backup_path = $path_info['basedir'] . '/db-backup';
412
413 // Open a directory, and read its contents.
414 if ( is_dir( $wp_db_backup_path ) ) {
415 $dh = opendir( $wp_db_backup_path );
416 if ( $dh ) {
417 while ( false !== ($file = readdir( $dh )) ) {
418 if ( ! ( in_array( $file, $backup_check_list, true ) ) ) {
419 if ( file_exists( $wp_db_backup_path . '/' . $file ) ) {
420 wp_delete_file( $wp_db_backup_path . '/' . $file );
421 }
422 $delete_message .= ' ' . $file;
423 }
424 }
425 closedir( $dh );
426 }
427 }
428 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=clear_temp_db_backup_file&_wpnonce=' . $nonce );
429 exit;
430 break;
431 case 'restorebackup':
432 $index = isset($_GET['index'])?(int) $_GET['index']:0;
433 $options = get_option( 'wp_db_backup_backups' );
434 $restore_limit = get_option( 'wp_db_restore_limit');
435 $newoptions = array();
436 $count = 0;
437 if(!empty($options) && is_array($options)){
438 foreach ( $options as $option ) {
439 if ( $count !== $index ) {
440 $newoptions[] = $option;
441 }
442 $count++;
443 }
444 }
445 if ( isset( $options[ $index ]['restore_limit'] ) && $options[ $index ]['restore_limit']==1) {
446 include_once ABSPATH . 'wp-admin/includes/plugin.php';
447 if ( !is_plugin_active( 'wp-database-backup-pro/wp-database-backup-pro.php' ) ) {
448 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore_limit&_wpnonce=' . $nonce );
449 }
450 }
451 if(!empty($options[ $index ]['restore_limit'])){
452 $options[ $index ]['restore_limit']=1;
453 }
454
455 if ( isset( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
456 $database_file = ( $options[ $index ]['sqlfile'] );
457 } else {
458 $database_file = isset($options[ $index ]['dir']) ? $options[ $index ]['dir'] : '';
459 $file_sql = explode( '.', $database_file );
460 if(isset($file_sql[0])){
461 $database_file = ( $file_sql[0] . '.sql' );
462 }
463
464 }
465 $database_name = $this->wp_backup_get_config_db_name();
466 $database_user = $this->wp_backup_get_config_data( 'DB_USER' );
467 $datadase_password = $this->wp_backup_get_config_data( 'DB_PASSWORD' );
468 $database_host = $this->wp_backup_get_config_data( 'DB_HOST' );
469 $path_info = wp_upload_dir();
470 // Added for extract zip file V.3.3.0.
471 $ext_path_info = $path_info['basedir'] . '/db-backup';
472 $database_zip_file = $options[ $index ]['dir'];
473
474 if ( class_exists( 'ZipArchive' ) ) {
475 $zip = new ZipArchive();
476 if ( $zip->open( $database_zip_file ) === true ) {
477 $zip->extractTo( $ext_path_info );
478 $zip->close();
479 }
480 } else {
481 require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
482 $archive = new PclZip( $database_zip_file );
483 $dir = $path_info['basedir'] . '/db-backup/';
484
485 if ( ! $archive->extract( PCLZIP_OPT_PATH, $dir ) ) {
486 wp_die( esc_html__('Unable to extract zip file. Please check that zlib php extension is enabled.','wpdbbkp').'<button onclick="history.go(-1);">'.esc_html__('Go Back','wpdbbkp').'</button>', esc_html__('ZIP Error','wpdbbkp') );
487 }
488 }
489
490 // End for extract zip file V.3.3.0.
491 set_time_limit( 0 );
492 ignore_user_abort(true);
493 if ('' !== trim($database_name) && '' !== trim($database_user) && '' !== trim($database_host)) {
494 $wpdb->db_connect();
495 $wpdb->select($database_name);
496
497 //phpcs:ignore -- Check if database exists
498 $db_exists = $wpdb->get_var($wpdb->prepare(
499 "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = %s",
500 $database_name
501 ));
502
503 if (!$db_exists) {
504 //phpcs:ignore -- Create DB if it doesn't exist
505 $wpdb->query($wpdb->prepare("CREATE DATABASE IF NOT EXISTS `%s`", $database_name));
506 $wpdb->select($database_name);
507 }
508 //phpcs:ignore -- Show tables from database
509 $tables = $wpdb->get_col($wpdb->prepare("SHOW TABLES FROM `%s`", $database_name));
510
511
512 if (!empty($tables)) {
513 foreach ($tables as $table_name) {
514 //phpcs:ignore -- delete tables before restore
515 $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS `%s`", $table_name));
516 }
517 }
518
519 // Restore database content
520 if (file_exists($database_file)) {
521 if ( ! function_exists( 'WP_Filesystem' ) ) {
522 require_once ABSPATH . '/wp-admin/includes/file.php';
523 }
524
525 WP_Filesystem();
526 if ( $wp_filesystem ) {
527 $sql_file = $wp_filesystem->get_contents( $database_file );
528 if ( $sql_file !== false ) {
529 $sql_queries = explode(";\n", $sql_file);
530 //phpcs:ignore -- Set sql_mode to empty
531 $wpdb->query("SET sql_mode = ''");
532
533 foreach ($sql_queries as $query) {
534 $query = apply_filters('wpdbbkp_sql_query_restore', $query);
535 if (!empty(trim($query))) {
536
537 /* Since $query is a dynqmic sql query from the backup file, we can't use $wpdb->prepare
538 * as we don't know the number / types of arguments in the query. So, we are using $wpdb->query
539 * directly to execute the query.*/
540 //phpcs:ignore
541 $wpdb->query($query);
542 }
543 }
544
545 } else {
546 error_log("Failed to Open file :".esc_html($database_file));
547 }
548 } else {
549 error_log("Failed to initialize WP_Filesystem");
550 }
551 }
552 }
553
554 if ( isset( $options[ $index ]['sqlfile'] ) && file_exists( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
555 if ( file_exists( $options[ $index ]['sqlfile'] ) ) {
556 wp_delete_file( $options[ $index ]['sqlfile'] );
557 }
558 } else {
559 $database_file = isset($options[ $index ]['dir'] )?$options[ $index ]['dir']:'';
560 if(!empty($database_file)){
561 $file_sql = explode( '.', $database_file );
562 if(isset($file_sql[0])){
563 $database_file = ( $file_sql[0] . '.sql' );
564 if ( file_exists( $database_file ) ) {
565 wp_delete_file( $database_file );
566 }
567
568 }
569
570 }
571
572 }
573 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
574 exit;
575 break;
576
577 case 'wpdbbkrestorefullbackup':
578 $index = (int) $_GET['index'];
579 require_once( 'class-wpdbbkp-restore.php' );
580 $restore = new Wpdbbkp_Restore();
581 $restore->start($index);
582 if (get_option('wp_db_log') == 1) {
583 $options = get_option('wp_db_backup_backups');
584 $path_info = wp_upload_dir();
585 if(isset($options[$index]['filename'])){
586 $logFileName = explode(".", $options[$index]['filename']);
587 if(isset($logFileName[0])){
588 $logfile = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $logFileName[0] . '.txt';
589 $message = "\n\n Restore Backup at " . gmdate("Y-m-d h:i:sa");
590 $this->write_log($logfile, $message);
591 }
592
593 }
594
595 }
596 $nonce = wp_create_nonce( 'wp-database-backup' );
597 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
598 exit;
599 break;
600
601 /* END: Restore Database Content */
602 }
603 }
604 }
605 }
606 }
607
608 if ( is_admin() && current_user_can( 'manage_options' ) ) {
609 register_setting( 'wp_db_backup_options', 'wp_db_backup_options', array( $this, 'wp_db_backup_validate' ) );
610 add_settings_section( 'wp_db_backup_main', 'WP-Database-Backup', array( $this, 'wp_db_backup_section_text' ), 'manage_options' );
611 }
612 }
613
614 /**
615 * Validate data.
616 *
617 * @param string $input - Input data.
618 */
619 public function wp_db_backup_validate( $input ) {
620 return $input;
621 }
622
623 /**
624 * Setting page.
625 */
626 public function wp_db_backup_settings_page() {
627 global $wp_filesystem;
628 if(!function_exists('WP_Filesystem')){
629 require_once ( ABSPATH . '/wp-admin/includes/file.php' );
630 }
631 WP_Filesystem();
632
633 $options = get_option( 'wp_db_backup_backups' );
634 $options = wpdbbkp_filter_unique_filenames( $options );
635 $settings = get_option( 'wp_db_backup_options' );
636 $wp_db_log = get_option( 'wp_db_log' ); ?>
637 <div class="bootstrap-wrapper">
638 <?php
639 $wp_db_local_backup_path = get_option( 'wp_db_local_backup_path' );
640 if ( false === empty( $wp_db_local_backup_path ) && false === file_exists( $wp_db_local_backup_path ) ) {
641 echo '<div class="alert alert-warning alert-dismissible fade in" role="alert">
642 <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
643 <a href="#db_destination" data-toggle="tab">';
644 esc_html_e( 'Invalid Local Backup Path : ', 'wpdbbkp' );
645 echo esc_html( $wp_db_local_backup_path );
646 echo '</a></div>';
647 }
648
649 $upload_dir = wp_upload_dir();
650 $dir = $upload_dir['basedir'] . '/db-backup';
651 if ( ! is_dir( $dir ) ) {
652 $dir = $upload_dir['basedir'];
653 }
654 if ( is_dir( $dir ) && !$wp_filesystem->is_writable( $dir )) {
655 ?>
656 <div class="row">
657 <div class="col-xs-12 col-sm-12 col-md-12">
658 <div class="alert alert-danger alert-dismissible fade in" role="alert">
659 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
660 <span aria-hidden="true">×</span></button>
661 <h4><?php esc_html_e( 'WP Database Backup', 'wpdbbkp' ); ?></h4>
662 <p><?php esc_html_e( 'Error: Permission denied, make sure you have write permission for', 'wpdbbkp' ); ?> <?php echo esc_attr( $dir ); ?>
663 <?php esc_html_e( 'folder', 'wpdbbkp' ); ?></p>
664 </div>
665 </button>
666 </div>
667 </div>
668 <?php
669 }
670 ?>
671
672 <div id="wpdbbkpModal" class="modal">
673 <div class="wpdbbkpmodal-content">
674 <div class="wpdbbkp-modal-header">
675 <span class="wpdbbkp-close">&times;</span>
676 <h2><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>&nbsp;<span id="wpdbbkp-modal-header-title"></span></h2>
677 </div>
678 <div class="wpdbbkp-modal-body">
679 <p id="wpdbbkp-modal-body-text"></p>
680 </div>
681 <div class="wpdbbkp-modal-footer">
682 <a class="btn btn-primary" onclick="return confirm('Are you sure you want to restore backup?')" id="wpdbbkp-proceed-btn">Continue Anyway</a>&nbsp;<a class="btn btn-default wpdbbkp-close">Close</a>
683 </div>
684 </div>
685 </div>
686
687 <div class="panel panel-default">
688 <div class="panel-heading head-logo">
689 <a href="https://backupforwp.com/" target="blank"><img
690 src="<?php echo esc_attr( WPDB_PLUGIN_URL ); ?>/assets/images/wp-database-backup.png" width="230px"></a>
691 </div>
692 <div class="panel-body">
693 <ul class="nav nav-tabs wbdbbkp_has_nav">
694 <li class="active"><a href="#db_home" data-toggle="tab"><?php echo esc_html__('Backups', 'wpdbbkp') ?></a></li>
695 <li><a href="#db_schedul" data-toggle="tab"><?php echo esc_html__('Auto Scheduler', 'wpdbbkp') ?></a></li>
696 <li><a href="#db_destination" data-toggle="tab"><?php echo esc_html__('Save Backups to', 'wpdbbkp') ?></a></li>
697 <li><a href="#db_setting" data-toggle="tab"><?php echo esc_html__('Settings', 'wpdbbkp') ?></a></li>
698 <li><a href="#searchreplace" data-toggle="tab"><?php echo esc_html__('Search and Replace', 'wpdbbkp') ?></a></li>
699 <li style="display:none"><a href="#db_upgrade" data-toggle="tab"><?php echo esc_html__('Upgrade', 'wpdbbkp') ?></a></li>
700 <?php do_action( 'wpdbbkp_pro_tab_links' ); ?>
701 <li><a href="#db_help" data-toggle="tab"><?php echo esc_html__('Help &amp; Support', 'wpdbbkp') ?></a></li>
702 <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>
703
704 </ul>
705
706 <?php
707 echo '<div class="tab-content">';
708 echo '<div class="tab-pane active" id="db_home">';
709
710 $nonce = wp_create_nonce( 'wp-database-backup' );
711 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
712 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
713 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
714 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> '.esc_html__('Create Database Backup with Search/Replace', 'wpdbbkp').'</a>';
715 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 > '.esc_html__('Search and Replace - Set Blank Fields', 'wpdbbkp').' </p>';
716 } else {
717 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> '.esc_html__('Create Database Backup', 'wpdbbkp').'</a>';
718 echo '<a href="#" id="wpdbbkp-create-full-backup" class="btn btn-primary"> <span class="glyphicon glyphicon-plus-sign"></span> '.esc_html__('Create Full Backup', 'wpdbbkp').'</a>';
719 echo '<a href="#" id="wpdbbkp-stop-full-backup" class="btn btn-danger wpdbbkp-cancel-btn" style="display:none;margin-bottom: 20px;margin-left: 10px;" > <span class="glyphicon glyphicon-ban"></span> '.esc_html__('Stop Backup Process', 'wpdbbkp').'</a>';
720 }
721 include_once 'admin-header-notification.php'; ?>
722
723 <?php
724 if ( !empty($options) ) {
725
726 echo ' <script>
727 var $j = jQuery.noConflict();
728 $j(document).ready(function () {
729
730 var table = $j("#wpdbbkp_table").DataTable({
731 order: [[0, "desc"]],
732 });
733 $j(".popoverid").popover();
734 });
735
736 function excludetableall(){
737 var checkboxes = document.getElementsByClassName("wp_db_exclude_table");
738 var checked = "";
739 if($j("#wp_db_exclude_table_all").prop("checked") == true){
740 checked = "checked";
741 }
742 $j(".wp_db_exclude_table").each(function() {
743 this.checked = checked;
744 });
745 }
746
747 </script>';
748 echo ' <div class="table-responsive">
749 <div id="wpdbbkp_dataTables" class="dataTables_wrapper form-inline" role="grid">
750
751 <table class="table table-striped table-bordered table-hover display" id="wpdbbkp_table">
752 <thead>';
753 echo '<tr class="wpdb-header">';
754 echo '<th class="manage-column" scope="col" width="5%" style="text-align: center;">#</th>';
755 echo '<th class="manage-column" scope="col" width="25%">Date</th>';
756 if($wp_db_log==1){
757 echo '<th class="manage-column" scope="col" width="5%">Log</th>';
758 }
759 echo '<th class="manage-column" scope="col" width="10%">Destination</th>';
760 echo '<th class="manage-column" scope="col" width="15%">Type</th>';
761 echo '<th class="manage-column" scope="col" width="10%">Backup File</th>';
762 echo '<th class="manage-column" scope="col" width="10%">Size</th>';
763 echo '<th class="manage-column" scope="col" width="20%">Action</th>';
764 echo '</tr>';
765 echo '</thead>';
766
767 echo '<tbody>';
768 $count = 1;
769 $destination_icon = array(
770 'Local' => 'glyphicon glyphicon-home',
771 'Local Path' => 'glyphicon glyphicon-folder-open',
772 'Email' => 'glyphicon glyphicon-envelope',
773 'FTP' => 'glyphicon glyphicon-tasks',
774 'SFTP' => 'glyphicon glyphicon-tasks',
775 'S3' => 'glyphicon glyphicon-cloud-upload',
776 'Drive' => 'glyphicon glyphicon-hdd',
777 'DropBox' => 'glyphicon glyphicon-inbox',
778 'Backblaze' => 'glyphicon glyphicon-cloud-upload'
779 );
780 if(!empty($options) && is_array($options)){
781 foreach ( $options as $option ) {
782 if(!is_array($option)){
783 continue;
784 }
785 $size = isset( $option['size'])? $option['size'] : 0;
786 $str_class = ( 0 === (int) $size ) ? 'text-danger' : 'wpdb_download';
787 echo '<tr class="' . ( ( 0 === ( $count % 2 ) ) ? esc_attr( $str_class ) . ' alternate' : esc_attr( $str_class ) ) . '">';
788 echo '<td style="text-align: center;">' . esc_attr( $count ) . '</td>';
789 $curr_date = new DateTime(gmdate( 'Y-m-d H:i:s', $option['date'] ));
790 $curr_date->setTimezone(new DateTimeZone(wp_timezone_string()));
791 echo '<td><span style="display:none">' . esc_attr( $curr_date->format('Y-m-d H:i:s') ) . '</span><span title="'.esc_attr( $curr_date->format('jS, F Y h:i:s A') ) .'">' .esc_html($this->wpdbbkp_get_timeago($option['date'])).'</span>';
792 echo '</td>';
793 if($wp_db_log==1){
794 echo '<td class="wpdb_log" align="center">';
795 if (!empty($option['log'])) {
796 if(isset($option['type']) && ($option['type'] == 'complete' || $option['type'] == 'database')){
797 echo '<a href="' . esc_url($option['log']) . '" target="_blank" class="label label-warning" title="There might be partial backup. Please check Log File for verify backup.">';
798 echo '<span class="glyphicon glyphicon-list-alt"></span>';
799 echo '</a>';
800 }else{
801 echo '<a class="popoverid btn" role="button" data-toggle="popover" data-html="true" title="There might be partial backup. Please check Log file to verify backup." data-content="' . wp_kses_post( $option['log'] ) . '"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></a>';
802 }
803 }
804 echo '</td>';
805 }
806 echo '<td>';
807 if ( ! empty( $option['destination'] ) ) {
808 $destination = ( explode( ',', $option['destination'] ) );
809 if(!empty($destination) && is_array($destination)){
810 foreach ( $destination as $dest ) {
811 $key = trim( $dest );
812 if ( ! empty( $dest ) && array_key_exists( $key, $destination_icon ) ) {
813 echo '<span class="' . esc_attr( $destination_icon[ $key ] ) . '" title="' . esc_attr( $dest ) . '"></span> ';
814 }
815 }
816 }
817
818 }
819 echo '</td>';
820 if(isset($option['type']) && !empty($option['type'])){
821 if($option['type'] == 'complete'){
822 echo '<td>'.esc_html__('Full Backup', 'wpdbbkp').'</td>';
823 }
824 if($option['type'] == 'database'){
825 echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
826 }
827 }else{
828 echo '<td>Database</td>';
829 }
830 echo '<td>';
831 echo '<a class="btn btn-default" href="' . esc_url( $option['url'] ) . '" style="color: #21759B;border-color:#337ab7;">';
832 echo '<span class="glyphicon glyphicon-download-alt"></span> Download</a></td>';
833 echo '<td>' . esc_attr( $this->wp_db_backup_format_bytes( $option['size'] ) ) . '</td>';
834 $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removebackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
835 echo '<td><a title="Remove Database Backup" onclick="return confirm(\'Are you sure you want to delete database backup?\')" href="' . esc_url($remove_backup_href) . '" class="btn btn-default"><span style="color:red" class="glyphicon glyphicon-trash"></span> Remove <a/> ';
836 if ( isset( $option['search_replace'] ) && 1 === (int) $option['search_replace'] ) {
837 echo '<span style="margin-left:15px" title="' . esc_html( $option['log'] ) . '" class="glyphicon glyphicon-search"></span>';
838 } else {
839 $restore_url_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=restorebackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
840 if(isset($option['type']) && !empty($option['type'])){
841 if($option['type'] == 'complete'){
842 $restore_url_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=wpdbbkrestorefullbackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
843 }
844
845 }
846 echo '<a title="Restore Database Backup" onclick="wpdbbkp_restore_backup(this);" href="javascript:void(0);" data-msg="Are you sure you want to restore database backup? It will overwrite all data /files with the respective backup and all recent changes would be lost. Are you sure you want to continue?" data-title="Restore Backup" data-href="'.esc_url($restore_url_href).'" class="btn btn-default"><span class="glyphicon glyphicon-refresh" style="color:blue"></span> Restore <a/>';
847 }
848 echo '</td></tr>';
849 $count++;
850 }
851 }
852
853 echo '</tbody>';
854
855 echo ' </table>
856 </div>
857 </div>';
858 } else {
859 echo '<p>No Database Backups Created!</p>';
860 }
861
862 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>';
863 echo '</div>';
864
865 echo '<div class="tab-pane" id="db_schedul">';
866 echo '<div class="panel-group">';
867 echo '<form method="post" action="" name="wp_auto_commenter_form">';
868 wp_nonce_field( 'wp-database-backup' );
869 $enable_autobackups = '0';
870 if ( isset( $settings['enable_autobackups'] ) ) {
871 $enable_autobackups = $settings['enable_autobackups'];
872 }
873
874 $autobackup_frequency = '0';
875 if ( isset( $settings['autobackup_frequency'] ) ) {
876 $autobackup_frequency = $settings['autobackup_frequency'];
877 }
878 $full_autobackup_frequency = 'disabled';
879 if ( isset( $settings['full_autobackup_frequency'] ) ) {
880 $full_autobackup_frequency = $settings['full_autobackup_frequency'];
881 }
882 $autobackup_type = '';
883 if ( isset( $settings['autobackup_type'] ) ) {
884 $autobackup_type = $settings['autobackup_type'];
885 }
886
887 echo '<div class="row form-group"><label class="col-sm-3" for="enable_autobackups">Enable Auto Backups</label>';
888 echo '<div class="col-sm-9"><input type="checkbox" id="enable_autobackups" name="wp_db_backup_options[enable_autobackups]" value="1" ' . checked( 1, $enable_autobackups, false ) . '/>';
889 echo '<div class="alert alert-default" role="alert"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> AutoBackups will be based on Wordpress Cron so it can have execution delay of +/- 30 mins . If you have disabled Wordpress Cron then autobackup will not work until you have set Server Cron for wordpress.</div>';
890 echo '</div>';
891 echo '</div>';
892
893 echo '<div class="row form-group autobackup_type" style="display:none"><label class="col-sm-3" for="autobackup_frequency">Which part should we backup for you ?</label>';
894 echo '<div class="col-sm-9"><select id="autobackup_type" class="form-control" name="wp_db_backup_options[autobackup_type]">';
895 echo '<option value="">Select Backup Type</option>';
896 echo '<option value="full" ' . selected( 'full', $autobackup_type, false ) . '>Full(Files + DB)</option>';
897 echo '<option value="files" ' . selected( 'files', $autobackup_type, false ) . '>Files Only</option>';
898 echo '<option value="db" ' . selected( 'db', $autobackup_type, false ) . '>Database Only</option>';
899 echo '</select>';
900 echo '</div></div>';
901
902 echo '<div class="row form-group autobackup_frequency" style="display:none"><label class="col-sm-3" for="autobackup_frequency">How often should we run Automatically?</label>';
903 echo '<div class="col-sm-9"><select id="autobackup_frequency" class="form-control" name="wp_db_backup_options[autobackup_frequency]">';
904 echo '<option value="daily" ' . selected( 'daily', $autobackup_frequency, false ) . '>Daily</option>';
905 echo '<option value="weekly" ' . selected( 'weekly', $autobackup_frequency, false ) . '>Weekly</option>';
906 echo '<option value="monthly" ' . selected( 'monthly', $autobackup_frequency, false ) . '>Monthly</option>';
907 echo '</select>';
908 echo '</div></div>';
909
910 echo '<div class="row form-group autobackup_frequency_lite" style="display:none"><label class="col-sm-12 autobackup_daily_lite" >We will automatically backup at 00:00 AM daily. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div>';
911 echo '<div class="row form-group autobackup_frequency_lite" style="display:none"><label class="col-sm-12 autobackup_weekly_lite" >We will automatically backup every Sunday on weekly basis. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div>';
912 echo '<div class="row form-group autobackup_frequency_lite" style="display:none"><label class="col-sm-12 autobackup_monthly_lite" >We will automatically backup on 1st on Monday on monthly basis. <b><a href="javascript:modify_backup_frequency();">Change Back Frequency Timings</a></b></label></div>';
913
914 do_action('wpdbbkp_database_backup_options');
915 echo '<p class="submit">';
916 echo '<input type="submit" name="Submit" class="btn btn-primary" value="Save Settings" />';
917 echo '</p>';
918 echo '</form>';
919 echo '</div>';
920 echo '</div>';
921
922 do_action('wpdbbkp_pro_tab_content');
923
924 ?>
925
926 <div class="tab-pane" id="db_upgrade">
927 <div class="panel-group ">
928 <div class="gn-flex-container row">
929 <div class=" col-md-12">
930 <div class="wpdbbkp-wrapper">
931 <div class="wpdbbkp-wr">
932 <div class="bkp-wpdbbkp-img">
933 <span class="sp_ov"></span>
934 </div>
935 <div class="bkp-wpdbbkp-cnt">
936 <h1><?php esc_html_e('UPGRADE to PRO Version','wpdbbkp');?></h1>
937 <a class="buy" href="https://backupforwp.com/pricing/#pricings" target="_blank">Purchase Now</a>
938 </div>
939 <div class="pvf">
940 <div class="pvf-cnt">
941 <div class="pvf-tlt">
942 <h2><?php esc_html_e('Compare Pro vs. Free Version','wpdbbkp');?></h2>
943 <span><?php esc_html_e('See what you\'ll get with the professional version','wpdbbkp');?></span>
944 </div>
945 <div class="pvf-cmp">
946 <div class="fr">
947 <h1><?php esc_html_e('FREE','wpdbbkp');?></h1>
948 <div class="fr-fe">
949 <div class="fe-1">
950 <h4><?php esc_html_e('Continious Development','wpdbbkp');?></h4>
951 <p><?php esc_html_e('We take bug reports and feature requests seriously. We\'re continiously developing &amp; improve this product for last 2 years with passion and love.','wpdbbkp');?></p>
952 </div>
953 <div class="fe-1">
954 <h4><?php esc_html_e('10+ Features','wpdbbkp');?></h4>
955 <p><?php esc_html_e('We\'re constantly expanding the plugin and make it more useful. We have wide variety of features which will fit any use-case.','wpdbbkp');?></p>
956 </div>
957 </div><!-- /. fr-fe -->
958 </div><!-- /. fr -->
959 <div class="pr">
960 <h1>PRO</h1>
961 <div class="pr-fe">
962 <span><?php esc_html_e('Everything in Free, and:','wpdbbkp');?></span>
963 <div class="fet">
964 <div class="fe-2">
965 <div class="fe-t">
966 <img src="<?php echo esc_url(WPDB_PLUGIN_URL.'/assets/images/right-tick.png');?>" alt="right-tick">
967 <h4><?php esc_html_e('Anonymization Function','wpdbbkp');?></h4>
968 </div>
969 <p><?php esc_html_e('Anonymization you critical data during backup with three methods','wpdbbkp');?> </p>
970 </div>
971 <div class="fe-2">
972 <div class="fe-t">
973 <img src="<?php echo esc_url(WPDB_PLUGIN_URL.'/assets/images/right-tick.png');?>" alt="right-tick">
974 <h4><?php esc_html_e('Pre-update backups','wpdbbkp');?></h4>
975 </div>
976 <p> <?php esc_html_e('Automatically backs up your website before any updates to plugins, themes and WordPress core.','wpdbbkp');?></p>
977 </div>
978
979 <div class="fe-2">
980 <div class="fe-t">
981 <img src="<?php echo esc_url(WPDB_PLUGIN_URL.'/assets/images/right-tick.png');?>" alt="right-tick">
982 <h4><?php esc_html_e('Backup time and scheduling','wpdbbkp'); ?></h4>
983 </div>
984 <p><?php esc_html_e('Set exact times to create or delete backups.','wpdbbkp');?></p>
985 </div>
986
987
988 <div class="fe-2">
989 <div class="fe-t">
990 <img src="<?php echo esc_url(WPDB_PLUGIN_URL.'/assets/images/right-tick.png');?>" alt="right-tick">
991 <h4><?php esc_html_e('Fast, personal support','wpdbbkp'); ?></h4>
992 </div>
993 <p><?php esc_html_e('Provides expert help and support from the developers whenever you need it.','wpdbbkp'); ?></p>
994 </div>
995 <div class="fe-2">
996 <div class="fe-t">
997 <img src="<?php echo esc_url(WPDB_PLUGIN_URL.'/assets/images/right-tick.png');?>" alt="right-tick">
998 <h4><?php esc_html_e('Continuous Updates','wpdbbkp'); ?></h4>
999 </div>
1000 <p><?php esc_html_e('We\'re continuously updating our premium features and releasing them.','wpdbbkp'); ?></p>
1001 </div>
1002 <div class="fe-2">
1003 <div class="fe-t">
1004 <img src="<?php echo esc_url(WPDB_PLUGIN_URL.'/assets/images/right-tick.png');?>" alt="right-tick">
1005 <h4><?php esc_html_e('Documentation','wpdbbkp'); ?></h4>
1006 </div>
1007 <p><?php esc_html_e('We create tutorials for every possible feature and keep it updated for you.','wpdbbkp'); ?></p>
1008 </div>
1009 </div><!-- /. fet -->
1010 <div class="pr-btn">
1011 <a href="https://backupforwp.com/pricing/#pricings" target="_blank"><?php esc_html_e('Upgrade to Pro','wpdbbkp'); ?></a>
1012 </div><!-- /. pr-btn -->
1013 </div><!-- /. pr-fe -->
1014 </div><!-- /.pr -->
1015 </div><!-- /. pvf-cmp -->
1016 </div><!-- /. pvf-cnt -->
1017
1018 <div class="wpdbbkpfaq">
1019 <h2><?php esc_html_e('Frequently Asked Questions','wpdbbkp'); ?></h2>
1020 <div class="faq-lst">
1021 <div class="lt">
1022 <ul>
1023 <li>
1024 <span><?php esc_html_e('Is there a setup fee?','wpdbbkp'); ?></span>
1025 <p><?php esc_html_e('No. There are no setup fees on any of our plans','wpdbbkp'); ?></p>
1026 </li>
1027 <li>
1028 <span><?php esc_html_e('What\'s the time span for your contracts?','wpdbbkp'); ?></span>
1029 <p><?php esc_html_e('All the plans are year-to-year which are subscribed annually except for lifetime plan.','wpdbbkp'); ?></p>
1030 </li>
1031 <li>
1032 <span><?php esc_html_e('What payment methods are accepted?','wpdbbkp'); ?></span>
1033 <p><?php esc_html_e('We accepts PayPal and Credit Card payments.','wpdbbkp'); ?></p>
1034 </li>
1035 <li>
1036 <span><?php esc_html_e('Do you offer support if I need help?','wpdbbkp'); ?></span>
1037 <p><?php esc_html_e('Yes! Top-notch customer support for our paid customers is key for a quality product, so we\'ll do our very best to resolve any issues you encounter via our support page.','wpdbbkp'); ?></p>
1038 </li>
1039 <li>
1040 <span><?php esc_html_e('Can I use the plugins after my subscription is expired?','wpdbbkp'); ?></span>
1041 <p><?php esc_html_e('Yes, you can use the plugins, but you will not get future updates for those plugins.','wpdbbkp'); ?></p>
1042 </li>
1043 </ul>
1044 </div>
1045 <div class="rt">
1046 <ul>
1047 <li>
1048 <span><?php esc_html_e('Can I cancel my membership at any time?','wpdbbkp'); ?></span>
1049 <p><?php esc_html_e('Yes. You can cancel your membership by contacting us.','wpdbbkp'); ?></p>
1050 </li>
1051 <li>
1052 <span><?php esc_html_e('Can I change my plan later on?','wpdbbkp'); ?></span>
1053 <p><?php esc_html_e('Yes. You can upgrade your plan by contacting us.','wpdbbkp'); ?></p>
1054 </li>
1055 <li>
1056 <span><?php esc_html_e('Do you offer refunds?','wpdbbkp'); ?></span>
1057 <p><?php esc_html_e('You are fully protected by our 100% Money-Back Guarantee Unconditional. If during the next 14 days you experience an issue that makes the plugin unusable, and we are unable to resolve it, we\'ll happily offer a full refund.','wpdbbkp'); ?></p>
1058 </li>
1059 <li>
1060 <span><?php esc_html_e('Do I get updates for the premium plugin?','wpdbbkp'); ?></span>
1061 <p><?php esc_html_e('Yes, you will get updates for all the premium plugins until your subscription is active.','wpdbbkp'); ?></p>
1062 </li>
1063 </ul>
1064 </div>
1065 </div><!-- /.faq-lst -->
1066 </div><!-- /.faq -->
1067 </div><!-- /. pvf -->
1068 </div>
1069 </div>
1070
1071 </div>
1072 </div>
1073 </div>
1074 </div>
1075
1076
1077 <div class="tab-pane" id="db_help">
1078 <div class="panel-group ">
1079 <div class="gn-flex-container row">
1080 <div class="wpdbbkp-left-side col-md-8">
1081 <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>
1082 <div class="wpdbbkp_support_div_form" id="technical-form">
1083 <ul>
1084 <li>
1085 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Email', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1086 </label>
1087 <div class="support-input">
1088 <input type="text" id="wpdbbkp_query_email" name="wpdbbkp_query_email" size="47" placeholder="<?php esc_attr_e('Enter your Email','wpdbbkp');?>" required="">
1089 </div>
1090 </li>
1091 <li>
1092 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
1093 </label>
1094 <div class="support-input">
1095 <textarea rows="5" cols="50" id="wpdbbkp_query_message" name="wpdbbkp_query_message" placeholder="<?php esc_attr_e('Write your query','wpdbbkp');?>"></textarea>
1096 </div>
1097 </li>
1098 <li>
1099 <button class="button button-primary wpdbbkp-send-query"> <?php echo esc_html__('Send Support Request', 'wpdbbkp') ?> </button>
1100 </li>
1101 </ul>
1102 <div class="clear"></div>
1103 <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>
1104 <span class="wpdbbkp-query-error wpdbbkp-result wpdbbkp-hide"> <?php echo esc_html__('Message not sent. please check your network connection', 'wpdbbkp') ?> </span>
1105 </div>
1106 </div>
1107 <div class="wpdbbkp-right-side col-md-4">
1108 <div class="wpdbbkp-bio-box" id="wpdbbkp_Bio">
1109 <h3><?php echo esc_html__('Vision &amp; Mission', 'wpdbbkp') ?></h3>
1110 <p class="wpdbbkp-p"><?php echo esc_html__('We strive to provide the best Backup Plugin in the world.', 'wpdbbkp') ?></p>
1111 <p class="wpdbbkp_boxdesk"> <?php echo esc_html__(' Delivering a good user experience means a lot to us, so we try our best to reply each and every question.', 'wpdbbkp') ?></p>
1112 </div>
1113 </div>
1114 </div>
1115 </div>
1116 </div>
1117
1118 <div class="tab-pane" id="db_info">
1119
1120 <div class="panel panel-group panel-default">
1121 <div class="panel-heading">
1122 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedb">
1123 <h4 class="panel-title">
1124 <?php esc_attr_e( 'System Check', 'wpdbbk' ); ?>
1125 </h4>
1126 </a>
1127 </div>
1128 <div id="collapsedb" class="panel-collapse collapse in">
1129 <div class="panel-body list-group">
1130
1131 <div class="row list-group-item">
1132 <?php
1133 $df = $dt = $dp = $du = 'NA';
1134 if(function_exists('disk_free_space')){
1135 /* get disk space free (in bytes) */
1136 $df = disk_free_space( WPDB_ROOTPATH );
1137 /* and get disk space total (in bytes) */
1138 $dt = disk_total_space( WPDB_ROOTPATH );
1139 /* now we calculate the disk space used (in bytes) */
1140 $du = $dt - $df;
1141 /* percentage of disk used - this will be used to also set the width % of the progress bar */
1142 $dp = sprintf( '%.2f', ( $du / $dt ) * 100 );
1143 $dp = isset( $dp )? $dp : 'NA';
1144 /* and we formate the size from bytes to MB, GB, etc. */
1145 $df = $this->wp_db_backup_format_bytes( $df );
1146 $du = $this->wp_db_backup_format_bytes( $du );
1147 $dt = $this->wp_db_backup_format_bytes( $dt );
1148 }
1149
1150 ?>
1151 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1152 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1153 </div>
1154 <div class="col-md-12">Disk Space</div>
1155 <div class="col-md-5">
1156 <div class="progress">
1157 <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 ); ?>%
1158 </div>
1159 </div>
1160 </div>
1161 <div class="col-md-1"></div>
1162 <div class="col-md-4"></div>
1163 <div class="col-md-5">
1164 <div class='prginfo'>
1165 <p><?php echo esc_attr( $du ) . ' of ' . esc_attr( $dt ) . ' used '; ?></p>
1166 <p><?php echo esc_attr( $df ) . ' of ' . esc_attr( $dt ) . ' free '; ?></p>
1167 <p>
1168 <small>
1169 <?php esc_attr_e( 'Note: This value is the physical servers hard-drive allocation.', 'wpdbbkp' ); ?>
1170 <br/>
1171 <?php esc_attr_e( "On shared hosts check your control panel for the 'TRUE' disk space quota value.", 'wpdbbkp' ); ?>
1172 </small>
1173 </p>
1174 </div>
1175
1176 </div>
1177 </div>
1178
1179 <div class=""><br>
1180 <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>
1181 <p><?php echo esc_html__("Click above button to clear all your old or temporary created database backup
1182 files.
1183 It only delete file from backup directory which is not in 'Database Backups'
1184 listing(all other file excluding backup files listed in 'Database Backups' ).
1185 Before
1186 using this option make sure that you have save your database backup on safe
1187 place.", 'wpdbbkp') ?></p>
1188 <p><?php echo esc_html__("The disk that your backup is saved on doesn't have enough free space? Backup disk
1189 is
1190 almost full? Low disk space for backup? Backup failed due to lack of space? As
1191 you
1192 may set up a schedule to automatically do backup daily or weekly, and the size
1193 of
1194 disk space is limited, so your backup disk will run out of space quickly or
1195 someday.
1196 It is a real pain to manually delete old backups. Don't worry about it. WP
1197 Database
1198 Backup makes it easy to delete old/temparary backup files using this option.", 'wpdbbkp') ?></p>
1199
1200 </div>
1201
1202 <div class="row list-group-item">
1203 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1204 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1205 </div>
1206 <?php if ( true === isset( $_SERVER['DOCUMENT_ROOT'] ) ) { ?>
1207 <div class="col-md-3"><?php echo esc_html__('Root Path', 'wpdbbkp') ?></div>
1208 <div class="col-md-5"><?php echo esc_attr( sanitize_text_field( wp_unslash( $_SERVER['DOCUMENT_ROOT'] ) ) ); ?></div>
1209 <?php } ?>
1210 </div>
1211
1212
1213 <div class="row list-group-item">
1214 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1215 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1216 </div>
1217 <div class="col-md-3"><?php echo esc_html__('ABSPATH', 'wpdbbkp') ?></div>
1218 <div class="col-md-5"><?php echo esc_attr( ABSPATH ); ?></div>
1219 </div>
1220
1221 <div class="row list-group-item">
1222 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1223 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1224 </div>
1225 <div class="col-md-3"><?php esc_attr_e( 'Upload directory URL', 'wpdbbk' ); ?></div>
1226 <div class="col-md-5">
1227 <?php
1228 $upload_dir = wp_upload_dir();
1229 echo esc_url( $upload_dir['baseurl'] );
1230 global $wp_filesystem;
1231 if(!function_exists('WP_Filesystem')){
1232 require_once ( ABSPATH . '/wp-admin/includes/file.php' );
1233 }
1234 WP_Filesystem();
1235 ?>
1236 </div>
1237 <div class="col-md-3"></div>
1238 </div>
1239
1240 <div class="row list-group-item">
1241 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1242 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1243 </div>
1244 <div class="col-md-3"><?php esc_attr_e( 'Upload directory', 'wpdbbk' ); ?></div>
1245 <div class="col-md-5"><?php echo esc_attr( $upload_dir['basedir'] ); ?></div>
1246 <div class="col-md-1">
1247 <?php echo esc_attr( substr( sprintf( '%o', fileperms( $upload_dir['basedir'] ) ), -4 ) ); ?></div>
1248 <div
1249 class="col-md-2"><?php echo ( ! $wp_filesystem->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>'; ?>
1250 </div>
1251 </div>
1252
1253 <div class="row list-group-item">
1254 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1255 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1256 </div>
1257 <div class="col-md-3"><?php echo esc_html__('Loaded PHP INI', 'wpdbbkp') ?></div>
1258 <div class="col-md-5"><?php echo esc_attr( php_ini_loaded_file() ); ?></div>
1259 </div>
1260 <div class="row list-group-item">
1261 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1262 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1263 </div>
1264 <div class="col-md-3"><?php echo esc_html__('Memory Limit', 'wpdbbkp') ?></div>
1265 <div class="col-md-5">
1266 <?php
1267 echo esc_attr( WP_MEMORY_LIMIT );
1268 echo '(Max &nbsp;' . esc_attr( WP_MAX_MEMORY_LIMIT );
1269 ?>
1270 )
1271 </div>
1272 </div>
1273
1274
1275 <div class="row list-group-item">
1276 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1277 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1278 </div>
1279 <div class="col-md-3"><?php esc_attr_e( 'Max Execution Time', 'wpdbbk' ); ?></div>
1280 <div class="col-md-5"> <?php echo esc_attr( ini_get( 'max_execution_time' ) ); ?></div>
1281 <div class="col-md-1"></div>
1282 <div
1283 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>
1284 </div>
1285 <div class="row list-group-item">
1286 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1287 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1288 </div>
1289 <div class="col-md-3"><?php esc_attr_e( 'Database backup directory', 'wpdbbk' ); ?></div>
1290 <div
1291 class="col-md-5"> <?php echo esc_attr( $upload_dir['basedir'] . '/db-backup' ); ?></div>
1292 <div
1293 class="col-md-1"><?php echo esc_attr( substr( sprintf( '%o', @fileperms( esc_attr( $upload_dir['basedir'] ) . '/db-backup' ) ), -4 ) ); ?></div>
1294 <div
1295 class="col-md-2"><?php echo ( ! $wp_filesystem->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>
1296 </div>
1297
1298 <div class="row list-group-item">
1299 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1300 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1301 </div>
1302 <div class="col-md-3"><?php esc_attr_e( 'Class ZipArchive Present : ', 'wpdbbk' ); ?></div>
1303 <div class="col-md-5">
1304 <?php
1305 echo ( class_exists( 'ZipArchive' ) ) ? 'Yes </p>' : '<p class="">No</p>';
1306 ?>
1307 </div>
1308 <div class="col-md-3"></div>
1309 </div>
1310
1311 <div class="row list-group-item">
1312 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
1313 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1314 </div>
1315 <div class="col-md-3"><?php esc_attr_e( 'mysqldump (cmd) Present : ', 'wpdbbk' ); ?></div>
1316 <div class="col-md-5">
1317 <?php
1318 $wpdb_admin = new Wpdb_Admin();
1319 echo ( $wpdb_admin->get_mysqldump_command_path() ) ? 'Yes </p>' : '<p class="">No</p>';
1320 ?>
1321 </div>
1322 <div class="col-md-3"></div>
1323 </div>
1324
1325 </div>
1326 </div>
1327 </div>
1328
1329 <div class="panel panel-default">
1330 <div class="panel-heading">
1331 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedbinfo">
1332 <h4 class="panel-title"><?php echo esc_html__('Database Information', 'wpdbbkp') ?></h4>
1333 </a>
1334 </div>
1335
1336 <div id="collapsedbinfo" class="panel-collapse collapse in">
1337 <div class="panel-body">
1338 <table class="table table-condensed">
1339 <tr class="success">
1340 <th><?php echo esc_html__('Setting', 'wpdbbkp') ?></th>
1341 <th><?php echo esc_html__('Value', 'wpdbbkp') ?></th>
1342 </tr>
1343 <tr>
1344 <td><?php echo esc_html__('Database Host', 'wpdbbkp') ?></td>
1345 <td><?php echo esc_attr( DB_HOST ); ?></td>
1346 </tr>
1347 <tr class="default">
1348 <td><?php echo esc_html__('Database Name', 'wpdbbkp') ?></td>
1349 <td> <?php echo esc_attr( DB_NAME ); ?></td>
1350 </tr>
1351 <tr>
1352 <td><?php echo esc_html__('Database User', 'wpdbbkp') ?></td>
1353 <td><?php echo esc_attr( DB_USER ); ?></td>
1354 </td>
1355 </tr>
1356 <tr>
1357 <td><?php echo esc_html__('Database Type', 'wpdbbkp') ?></td>
1358 <td><?php echo esc_html__('MYSQL', 'wpdbbkp') ?></td>
1359 </tr>
1360 <tr>
1361 <?php
1362 // Get MYSQL Version.
1363 global $wpdb;
1364 $mysqlversion = wp_cache_get( 'wpdb_mysqlversion' );
1365 if ( true === empty( $mysqlversion ) ) {
1366 $mysqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' ); // phpcs:ignore
1367 wp_cache_set( 'wpdb_mysqlversion', $mysqlversion, '', 18000 );
1368 }
1369 ?>
1370 <td><?php echo esc_html__('Database Version', 'wpdbbkp') ?></td>
1371 <td>v<?php echo esc_attr( $mysqlversion ); ?></td>
1372 </tr>
1373 </table>
1374
1375 </div>
1376 </div>
1377 </div>
1378
1379 <div class="panel panel-default">
1380 <div class="panel-heading">
1381
1382 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedbtable">
1383 <h4 class="panel-title">
1384 <?php echo esc_html__('Tables Information', 'wpdbbkp') ?>
1385 </h4>
1386 </a>
1387
1388 </div>
1389 <div id="collapsedbtable" class="panel-collapse collapse in">
1390 <div class="panel-body">
1391 <table class="table table-condensed">
1392 <tr class="success">
1393 <th><?php echo esc_html__('No.', 'wpdbbkp') ?></th>
1394 <th><?php echo esc_html__('Tables', 'wpdbbkp') ?></th>
1395 <th><?php echo esc_html__('Records', 'wpdbbkp') ?></th>
1396
1397 </tr>
1398 <?php
1399 $no = 0;
1400 $row_usage = 0;
1401 $data_usage = 0;
1402 $tablesstatus = $wpdb->get_results( 'SHOW TABLE STATUS' ); // phpcs:ignore
1403 if($tablesstatus != null && !empty($tablesstatus)){
1404 foreach ( $tablesstatus as $tablestatus ) {
1405 $tablestatus_arr = (array) $tablestatus;
1406 if ( 0 === ( $no % 2 ) ) {
1407 $style = '';
1408 } else {
1409 $style = ' class="alternate"';
1410 }
1411 $no++;
1412 echo '<tr' . esc_attr( $style ) . '>';
1413 echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1414 echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1415 echo '<td>' . esc_attr( number_format_i18n( isset($tablestatus_arr['Rows'])?$tablestatus_arr['Rows']:0 ) ) . '</td>';
1416
1417 $row_usage += $tablestatus_arr['Rows'];
1418
1419 echo '</tr>';
1420 }
1421 }
1422 echo '<tr class="thead">';
1423 echo '<th> Total:</th>';
1424 echo '<th>' . esc_attr( number_format_i18n( $no ) ) . ' Table </th>';
1425 echo '<th>' . esc_attr( number_format_i18n( $row_usage ) ) . ' Records</th>';
1426
1427 echo '</tr>';
1428 ?>
1429 </table>
1430
1431 </div>
1432 </div>
1433 </div>
1434 <div class="panel panel-default">
1435 <div class="panel-heading">
1436
1437 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsewp">
1438 <h4 class="panel-title">
1439 <?php echo esc_html__('WordPress Information', 'wpdbbkp') ?>
1440 </h4>
1441 </a>
1442
1443 </div>
1444 <div id="collapsewp" class="panel-collapse collapse in">
1445 <div class="panel-body">
1446 <table class="table table-condensed">
1447 <tr class="success">
1448 <th><?php echo esc_html__('Setting', 'wpdbbkp') ?></th>
1449 <th><?php echo esc_html__('Value', 'wpdbbkp') ?></th>
1450
1451 </tr>
1452 <tr>
1453 <td><?php echo esc_html__('WordPress Version', 'wpdbbkp') ?></td>
1454 <td><?php bloginfo( 'version' ); ?></td>
1455 </tr>
1456 <tr>
1457 <td><?php echo esc_html__('Home URL', 'wpdbbkp') ?></td>
1458 <td> <?php echo esc_url( home_url() ); ?></td>
1459 </tr>
1460 <tr>
1461 <td><?php echo esc_html__('Site URL', 'wpdbbkp') ?></td>
1462 <td><?php echo esc_url( site_url() ); ?></td>
1463 </tr>
1464 <tr>
1465 <td><?php echo esc_html__('Upload directory URL', 'wpdbbkp') ?></td>
1466 <td><?php $upload_dir = wp_upload_dir(); ?>
1467 <?php echo esc_url( $upload_dir['baseurl'] ); ?></td>
1468 </tr>
1469 </table>
1470
1471 </div>
1472 </div>
1473 </div>
1474
1475 <div class="panel panel-default">
1476 <div class="panel-heading">
1477
1478 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsewpsetting">
1479 <h4 class="panel-title">
1480 <?php echo esc_html__('WordPress Settings', 'wpdbbkp') ?>
1481 </h4>
1482 </a>
1483
1484 </div>
1485 <div id="collapsewpsetting" class="panel-collapse collapse in">
1486 <div class="panel-body">
1487 <table class="table table-condensed">
1488 <tr class="success">
1489 <th><?php echo esc_html__('Plugin Name', 'wpdbbkp') ?></th>
1490 <th><?php echo esc_html__('Version', 'wpdbbkp') ?></th>
1491 </tr>
1492 <?php
1493 $plugins = get_plugins();
1494 if(!empty($plugins) && is_array($plugins)){
1495 foreach ( $plugins as $plugin ) {
1496 echo '<tr>
1497 <td>' . esc_attr( $plugin['Name'] ) . '</td>
1498 <td>' . esc_attr( $plugin['Version'] ) . '</td>
1499 </tr>';
1500 }
1501 }
1502
1503 ?>
1504 </table>
1505 <table class="table table-condensed">
1506 <tr class="success">
1507 <th><?php echo esc_html__('Active Theme Name', 'wpdbbkp') ?></th>
1508 <th><?php echo esc_html__('Version', 'wpdbbkp') ?></th>
1509 </tr>
1510 <?php
1511 $my_theme = wp_get_theme();
1512
1513 echo '<tr>
1514 <td>' . esc_attr( $my_theme->get( 'Name' ) ) . '</td>
1515 <td>' . esc_attr( $my_theme->get( 'Version' ) ) . '</td>
1516 </tr>';
1517 ?>
1518 </table>
1519 <div class="row">
1520 <button class="btn btn-primary" type="button">
1521 <?php echo esc_html__('Drafts Post Count', 'wpdbbkp') ?> <span class="badge">
1522 <?php
1523 $count_posts = wp_count_posts();
1524 echo esc_attr( $count_posts->draft );
1525 ?>
1526 </span>
1527 </button>
1528 <button class="btn btn-primary" type="button">
1529 <?php echo esc_html__('Publish Post Count', 'wpdbbkp') ?> <span class="badge">
1530 <?php
1531
1532 echo esc_attr( $count_posts->publish );
1533 ?>
1534 </span>
1535 </button>
1536 <button class="btn btn-primary" type="button">
1537 <?php echo esc_html__('Drafts Pages Count', 'wpdbbkp') ?> <span class="badge">
1538 <?php
1539 $count_pages = wp_count_posts( 'page' );
1540 echo esc_attr( $count_pages->draft );
1541 ?>
1542 </span>
1543 </button>
1544 <button class="btn btn-primary" type="button">
1545 <?php echo esc_html__('Publish Pages Count', 'wpdbbkp') ?> <span class="badge">
1546 <?php
1547
1548 echo esc_attr( $count_pages->publish );
1549 ?>
1550 </span>
1551 </button>
1552 <button class="btn btn-primary" type="button">
1553 <?php echo esc_html__('Approved Comments Count', 'wpdbbkp') ?> <span class="badge">
1554 <?php
1555 $comments_count = wp_count_comments();
1556 echo esc_attr( $comments_count->approved );
1557 ?>
1558 </span>
1559 </button>
1560 </div>
1561 </div>
1562 </div>
1563 </div>
1564
1565
1566 </div>
1567
1568 <div class="tab-pane" id="db_setting">
1569
1570 <div class="panel-group">
1571 <?php
1572 $wp_local_db_backup_count = get_option( 'wp_local_db_backup_count' );
1573 $wp_db_log = get_option( 'wp_db_log' );
1574 $wp_db_exclude_table = array();
1575 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
1576 $wp_db_backup_enable_auto_upgrade = get_option( 'wp_db_backup_enable_auto_upgrade' );
1577 if ( 1 === (int) $wp_db_backup_enable_auto_upgrade ) {
1578 $wp_db_backup_enable_auto_upgrade_checked = 'checked';
1579 } else {
1580 $wp_db_backup_enable_auto_upgrade_checked = '';
1581 }
1582 if ( 1 === (int) $wp_db_log ) {
1583 $checked = 'checked';
1584 } else {
1585 $checked = '';
1586 }
1587 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
1588 $wp_db_remove_on_uninstall = get_option( 'wp_db_remove_on_uninstall');
1589 $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
1590 if ( 1 === (int) $wp_db_remove_local_backup ) {
1591 $remove_local_backup = 'checked';
1592 } else {
1593 $remove_local_backup = '';
1594 }
1595 if ( 1 === (int) $wp_db_remove_on_uninstall ) {
1596 $remove_on_uninstall = 'checked';
1597 } else {
1598 $remove_on_uninstall = '';
1599 }
1600 if ( 1 === (int) $wp_db_save_settings_in_backup ) {
1601 $save_on_backup = 'checked';
1602 } else {
1603 $save_on_backup = '';
1604 }
1605 ?>
1606 <form action="" method="post">
1607 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1608 <div class="input-group">
1609 <span class="input-group-addon" id="sizing-addon2"><?php echo esc_html__('Maximum Local Backups', 'wpdbbkp') ?></span>
1610 <input type="number" name="wp_local_db_backup_count" value="<?php echo esc_html( $wp_local_db_backup_count ); ?>" class="form-control" placeholder="<?php esc_attr_e('Maximum Local Backups','wpdbbkp');?>" aria-describedby="sizing-addon2">
1611
1612 </div><br>
1613 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span><?php echo esc_html__(' The maximum
1614 number of Local Database Backups that should be kept, regardless of their size.', 'wpdbbkp') ?></br>
1615 <?php echo esc_html__('Leave blank for keep unlimited database backups.', 'wpdbbkp') ?>
1616 </p>
1617
1618 <hr>
1619 <div class="input-group">
1620 <label><input type="checkbox" <?php echo esc_attr( $checked ); ?> name="wp_db_log"> <?php echo esc_html__('Enable Log', 'wpdbbkp') ?></label>
1621 </div>
1622 <br>
1623 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1624 <?php echo esc_html__(' Create a log file to record details of each backup operation. ', 'wpdbbkp') ?>
1625 </p>
1626
1627 <hr>
1628 <div class="input-group">
1629 <label><input type="checkbox" <?php echo esc_attr( $wp_db_backup_enable_auto_upgrade_checked ); ?> name="wp_db_backup_enable_auto_upgrade"> <?php echo esc_html__('Enable Auto Backups Before Upgrade', 'wpdbbkp') ?></label>
1630 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1631 <?php echo esc_html__('If checked then it will create database backup on(before) upgrade/update plugin, theme, WordPress.', 'wpdbbkp') ?>
1632 <br><?php echo esc_html__('Leave blank/un-checked for disable this feature.', 'wpdbbkp') ?>
1633 </p>
1634 </div>
1635 <hr>
1636 <div class="input-group">
1637 <label><input type="checkbox" <?php echo esc_attr( $remove_local_backup ); ?> name="wp_db_remove_local_backup"> <?php echo esc_html__('Remove local backup', 'wpdbbkp') ?></label>
1638 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1639 <?php echo esc_html__('If Checked then it will remove local backup.', 'wpdbbkp') ?>
1640 <?php echo esc_html__('Use this option only when you have set any destination.', 'wpdbbkp') ?>
1641 <?php echo esc_html__('If somesites you need only external backup.', 'wpdbbkp') ?>
1642 </p>
1643 </div>
1644 <hr>
1645 <div class="input-group">
1646 <label><input type="checkbox" <?php echo esc_attr( $save_on_backup ); ?> name="wp_db_save_settings_in_backup"> <?php echo esc_html__('Skip plugin settings from database backup', 'wpdbbkp') ?></label>
1647 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1648 <?php echo esc_html__('If Checked then it will skip Backup for WP plugin settings from the DB backup file .', 'wpdbbkp') ?>
1649 </p>
1650 </div>
1651 <hr>
1652 <div class="input-group">
1653 <label><input type="checkbox" <?php echo esc_attr( $remove_on_uninstall ); ?> name="wp_db_remove_on_uninstall"> <?php echo esc_html__('Delete Data and options on uninstall', 'wpdbbkp') ?></label>
1654 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1655 <?php echo esc_html__('If Checked then it will delete all backup files and options when plugin is uninstalled', 'wpdbbkp') ?>
1656
1657 </p>
1658 </div>
1659 <hr>
1660 <?php
1661 $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removeallbackup&_wpnonce=' . esc_attr( $nonce ); ?>
1662
1663 <div class="input-group">
1664 <a title="Remove Database Backup" onclick="return confirm('Are you sure you want to delete all the backups? Deleted backups can not be recovered.')" href="<?php echo esc_url($remove_backup_href)?>" class="btn btn-danger" style="margin-bottom:10px;"><span class="glyphicon glyphicon-trash"></span> <?php esc_html_e('Delete all Backups', 'wpdbbkp')?></a>
1665 <p> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1666 <?php echo esc_html__('Warning :This is will delete all the backups on the website. Once deleted backups can not be recovered.', 'wpdbbkp') ?>
1667 </p>
1668
1669
1670 </div>
1671 <hr>
1672 <div class="panel panel-default">
1673 <div class="panel-heading">
1674 <a data-toggle="collapse" data-parent="#accordion" href="#collapseExclude">
1675 <h4 class="panel-title">
1676 <?php echo esc_html__('Exclude Table From Database Backup', 'wpdbbkp') ?>
1677 </h4>
1678 </a>
1679 </div>
1680 <div id="collapseExclude" class="panel-collapse collapse in">
1681 <div class="panel-body">
1682 <table class="table table-condensed">
1683 <tr class="success">
1684 <th><?php echo esc_html__('No.', 'wpdbbkp') ?></th>
1685 <th><?php echo esc_html__('Tables', 'wpdbbkp') ?></th>
1686 <th><?php echo esc_html__('Records', 'wpdbbkp') ?></th>
1687 <th><?php echo esc_html__('Exclude Table', 'wpdbbkp') ?></th>
1688 </tr>
1689 <?php
1690 $no = 0;
1691 $row_usage = 0;
1692 $data_usage = 0;
1693 $tablesstatus = $wpdb->get_results( 'SHOW TABLE STATUS' ); // phpcs:ignore
1694 if($tablesstatus != null && !empty($tablesstatus)){
1695 foreach ( $tablesstatus as $tablestatus ) {
1696 $tablestatus_arr = (array) $tablestatus;
1697 if ( 0 === ( $no % 2 ) ) {
1698 $style = '';
1699 } else {
1700 $style = ' class="alternate"';
1701 }
1702 $no++;
1703 echo '<tr' . esc_attr( $style ) . '>';
1704 echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1705 echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1706 echo '<td>' . esc_attr( number_format_i18n( isset($tablestatus_arr['Rows'])?$tablestatus_arr['Rows']:0 ) ) . '</td>';
1707 if ( false === empty( $wp_db_exclude_table ) && in_array( $tablestatus_arr['Name'], $wp_db_exclude_table, true ) ) {
1708 $checked = 'checked';
1709 } else {
1710 $checked = '';
1711 }
1712 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>';
1713
1714 $row_usage += $tablestatus_arr['Rows'];
1715
1716 echo '</tr>';
1717 }
1718 }
1719 echo '<tr class="thead">';
1720 echo '<th>Total:</th>';
1721 echo '<th>' . esc_attr( number_format_i18n( $no ) ) . ' Table</th>';
1722 echo '<th>' . esc_attr( number_format_i18n( $row_usage ) ) . ' Records</th>';
1723 echo '<th></th>';
1724 echo '</tr>';
1725 ?>
1726 </table>
1727 </div>
1728 </div>
1729 </div>
1730 <hr>
1731 <input class="btn btn-primary" type="submit" name="wpsetting" value="Save">
1732 </form>
1733 </div>
1734 </div>
1735
1736 <div class="tab-pane" id="searchreplace">
1737 <div class="panel-group">
1738 <?php
1739 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
1740 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
1741 ?>
1742 <form action="" method="post">
1743 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1744
1745 <p><?php echo esc_html__('If you even need to migrate your WordPress site to a different domain name,
1746 or add an SSL certificate to it, you must update the URLs in your database backup file
1747 then you can use this feature.','wpdbbkp'); ?> <br>
1748 <?php echo esc_html__(' This feature allow you to Search and Replace text in your database backup file. ','wpdbbkp'); ?>
1749 <br> <?php echo esc_html__('if you want only exclude tables from search and replace text then Go to Dashboard=>Tool=>WP-DB Backup > Setting > Exclude Table From Database Backup setting. The tables you selected will be skipped over for each backup you make.', 'wpdbbkp') ?>
1750 </p>
1751 <br>
1752 <div class="input-group">
1753 <span class="input-group-addon" id="wp_db_backup_search_text"><?php echo esc_html__('Search For', 'wpdbbkp') ?></span>
1754 <input type="text" name="wp_db_backup_search_text" value="<?php echo esc_html( $wp_db_backup_search_text ); ?>" class="form-control" placeholder="<?php esc_attr_e('http://localhost/wordpress','wpdbbkp'); //phpcs:ignore ?>" aria-describedby="wp_db_backup_search_text">
1755
1756 </div>
1757 <br>
1758 <div class="input-group">
1759 <span class="input-group-addon" id="wp_db_backup_replace_text"><?php echo esc_html__('Replace With', 'wpdbbkp') ?></span>
1760 <input type="text" name="wp_db_backup_replace_text" value="<?php echo esc_html( $wp_db_backup_replace_text ); ?>" class="form-control" placeholder="<?php esc_attr_e('http://site.com','wpdbbkp');?>" aria-describedby="wp_db_backup_replace_text">
1761
1762 </div>
1763
1764 <div class="alert alert-default" role="alert">
1765 <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1766 <?php echo esc_html__("Leave blank those fields if you don't want use this feature and want only regular Database backup.", 'wpdbbkp') ?>
1767 <br>
1768 <?php echo esc_html__('Ex:', 'wpdbbkp') ?>
1769 <br><?php echo esc_html__('Search For:', 'wpdbbkp') ?> <?php echo esc_url('http://localhost/wordpress/', 'wpdbbkp'); //phpcs:ignore ?>
1770 <br><?php echo esc_html__('Replace With:', 'wpdbbkp') ?> <?php echo esc_url('http://domain.com/', 'wpdbbkp') ?>
1771
1772 <br><br>
1773 <?php echo esc_html__('Note - This is Search & Replace data in your WordPress Database Backup File not in current Database installation.', 'wpdbbkp') ?>
1774
1775 </div>
1776
1777 <input class="btn btn-primary" type="submit" name="wpsetting_search" value="Save">
1778 </form>
1779 </div>
1780
1781
1782
1783 </div>
1784 <div class="tab-pane panel-group" id="db_destination">
1785 <?php
1786 include plugin_dir_path( __FILE__ ) . 'Destination/wp-backup-destination.php';
1787 ?>
1788 </div>
1789
1790
1791 </div>
1792 </div>
1793
1794
1795 </div>
1796 <a aria-label="Open Support" aria-expanded="false" class="wpdbbkp-support-button" href="https://backupforwp.com/support/" target="_blank">
1797 <span class="wpdbbkp-support-icon">
1798 <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>
1799 </span>
1800 </a>
1801 <?php
1802 }
1803
1804 /**
1805 * Redirect to premium website
1806 */
1807 public function wp_db_backup_premium_interface_render()
1808 {
1809 wp_redirect("https://backupforwp.com/pricing/");
1810 exit;
1811 }
1812
1813 /**
1814 * Run after complete backup.
1815 *
1816 * @param bool $bytes - bytes details.
1817 * @param int $precision - precision details.
1818 */
1819 public function wp_db_backup_format_bytes( $bytes, $precision = 2 ) {
1820 $units = array( 'B', 'KB', 'MB', 'GB', 'TB' );
1821 $bytes = max( $bytes, 0 );
1822 $pow = floor( ( $bytes ? log( $bytes ) : 0 ) / log( 1024 ) );
1823 $pow = min( $pow, count( $units ) - 1 );
1824 $bytes /= pow( 1024, $pow );
1825 return round( $bytes, $precision ) . ' ' . $units[ $pow ];
1826 }
1827
1828 /**
1829 * Create database bakup function.
1830 */
1831 public function wp_db_backup_create_mysql_backup() {
1832 global $wpdb;
1833 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1834 $options_backup = get_option( 'wp_db_backup_backups' );
1835 $settings_backup = get_option( 'wp_db_backup_options' );
1836 $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
1837 if($wp_db_save_settings_in_backup){
1838 delete_option( 'wp_db_backup_backups' );
1839 delete_option( 'wp_db_backup_options' );
1840 }
1841 /* END : Prevent saving backup plugin settings in the database dump */
1842 $wp_db_exclude_table = array();
1843 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
1844 $tables = $wpdb->get_col( 'SHOW TABLES' ); // phpcs:ignore
1845 $output = '';
1846 if(!empty($tables) && !is_array($tables)){
1847 foreach ( $tables as $table ) {
1848 if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
1849
1850 $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1851 $check_count = intval($check_count);
1852 $sub_limit =500;
1853 if(isset($check_count) && $check_count>$sub_limit){
1854 $result =array();
1855 $t_sub_queries= ceil($check_count/$sub_limit);
1856 for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1857 {
1858 $sub_offset = $sub_i*$sub_limit;
1859 $sub_result = false;
1860 if ( false === $sub_result ) {
1861 // phpcs:ignore -- using direct query to get the data of table in chunks.
1862 $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table} LIMIT %d OFFSET %d",array($sub_limit,$sub_offset)), ARRAY_A );
1863 }
1864
1865 if($sub_result){
1866 $result = array_merge($result,$sub_result);
1867 }
1868 sleep(1);
1869 }
1870 }
1871 else{
1872 $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table}"), ARRAY_A ); // phpcs:ignore
1873 }
1874
1875
1876 $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1877 $output .= "\n\n" . $row2[1] . ";\n\n";
1878 $result_count = count( $result );
1879 for ( $i = 0; $i < $result_count; $i++ ) {
1880 if(isset($result[ $i ])){
1881 $row = $result[ $i ];
1882 $output .= 'INSERT INTO ' . $table . ' VALUES(';
1883 $result_o_index = count( $result[0] );
1884 $j=0;
1885 foreach ($row as $key => $value) {
1886 $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1887 $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
1888 if ( $j < ( $result_o_index - 1 ) ) {
1889 $output .= ',';
1890 }
1891 $j++;
1892 }
1893 $output .= ");\n";
1894 }
1895
1896 }
1897 $output .= "\n";
1898 }
1899 sleep(1);
1900 }
1901
1902 }
1903
1904 $wpdb->flush();
1905 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1906 $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
1907 add_option( 'wp_db_backup_backups', $options_backup );
1908 add_option( 'wp_db_backup_options', $settings_backup );
1909 /* END : Prevent saving backup plugin settings in the database dump */
1910 return $output;
1911 }
1912
1913 /**
1914 * Create database backup new function.
1915 */
1916 public function wp_db_backup_create_mysql_backup_new( $table, $file_path ) {
1917 global $wpdb, $wp_filesystem;
1918
1919 // Ensure WP Filesystem is loaded
1920 if ( ! function_exists( 'WP_Filesystem' ) ) {
1921 require_once ABSPATH . 'wp-admin/includes/file.php';
1922 }
1923 WP_Filesystem();
1924
1925 // Define file size threshold (e.g., 10MB)
1926 $file_size_threshold = 10 * 1024 * 1024; // 10MB
1927
1928 // Initialize the file with table creation statement if it doesn't exist
1929
1930 $table = esc_sql( $table );
1931 $row2 = $wpdb->get_row( "SHOW CREATE TABLE `{$table}`", ARRAY_N ); // phpcs:ignore
1932 $initial_output = "\n\n" . $row2[1] . ";\n\n";
1933
1934 $use_php_methods = false;
1935 if ( $wp_filesystem->exists( $file_path ) ) {
1936 // Check file size
1937 $file_size = $wp_filesystem->size( $file_path );
1938 if ( $file_size !== false && $file_size > $file_size_threshold ) {
1939 $use_php_methods = true;
1940 }
1941 }
1942
1943 // Function to append content
1944 $append_content = function( $new_content ) use ( $file_path, $wp_filesystem, $use_php_methods ) {
1945 if ( $use_php_methods ) {
1946 // Using PHP methods to append
1947 if ( ! $wp_filesystem->exists( $file_path ) ) {
1948 // phpcs:ignore -- WP Filesystem fileing for large files
1949 file_put_contents( $file_path, $new_content );
1950 } else {
1951 // phpcs:ignore -- WP Filesystem fileing for large files
1952 file_put_contents( $file_path, $new_content, FILE_APPEND );
1953 }
1954 } else {
1955 // Use WP Filesystem to append
1956 if ( ! $wp_filesystem->exists( $file_path ) ) {
1957 $wp_filesystem->put_contents( $file_path, $new_content, FS_CHMOD_FILE );
1958 } else {
1959 // Read current contents
1960 $current_contents = $wp_filesystem->get_contents( $file_path );
1961 if ( $current_contents === false ) {
1962 // Handle error if reading fails
1963 return false;
1964 }
1965 // Append new content
1966 $updated_contents = $current_contents . $new_content;
1967 // Write back updated contents
1968 if ( ! $wp_filesystem->put_contents( $file_path, $updated_contents, FS_CHMOD_FILE ) ) {
1969 // Handle error if writing fails
1970 return false;
1971 }
1972 }
1973 }
1974 return true;
1975 };
1976
1977 // Write the initial output to the file
1978 if ( ! $append_content( $initial_output ) ) {
1979 return false; // Handle error if initial content writing fails
1980 }
1981
1982 $sub_limit = 500;
1983 // phpcs:ignore
1984 $check_count = $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" );
1985 $check_count = intval( $check_count );
1986
1987 if ( $check_count > $sub_limit ) {
1988 $t_sub_queries = ceil( $check_count / $sub_limit );
1989
1990 for ( $sub_i = 0; $sub_i < $t_sub_queries; $sub_i++ ) {
1991 $sub_offset = $sub_i * $sub_limit;
1992 $sub_result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$table}` LIMIT %d OFFSET %d", array( $sub_limit, $sub_offset ) ), ARRAY_A ); // phpcs:ignore
1993
1994 if ( $sub_result ) {
1995 $output = '';
1996 foreach ( $sub_result as $row ) {
1997 $output .= 'INSERT INTO ' . $table . ' VALUES(';
1998 $result_o_index = count( $row );
1999 $j = 0;
2000 foreach ( $row as $key => $value ) {
2001 $row[ $key ] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $value, $table, $key ) );
2002 $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2003 if ( $j < ( $result_o_index - 1 ) ) {
2004 $output .= ',';
2005 }
2006 $j++;
2007 }
2008 $output .= ");\n";
2009 }
2010 // Append to the file
2011 if ( ! $append_content( $output ) ) {
2012 return false; // Handle error if appending content fails
2013 }
2014 }
2015 sleep(1);
2016 }
2017 } else {
2018 $result = $wpdb->get_results( "SELECT * FROM `{$table}`", ARRAY_A ); // phpcs:ignore
2019
2020 $output = '';
2021 foreach ( $result as $row ) {
2022 $output .= 'INSERT INTO ' . $table . ' VALUES(';
2023 $result_o_index = count( $row );
2024 $j = 0;
2025 foreach ( $row as $key => $value ) {
2026 $row[ $key ] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $value, $table, $key ) );
2027 $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2028 if ( $j < ( $result_o_index - 1 ) ) {
2029 $output .= ',';
2030 }
2031 $j++;
2032 }
2033 $output .= ");\n";
2034 }
2035 // Append to the file
2036 if ( ! $append_content( $output ) ) {
2037 return false; // Handle error if appending content fails
2038 }
2039 }
2040
2041 // Flush the database cache
2042 $wpdb->flush();
2043 return true;
2044 }
2045
2046
2047 /**
2048 * Mysql Dump set path.
2049 *
2050 * @param string $path - Path.
2051 */
2052 public function set_mysqldump_command_path( $path ) {
2053 $this->mysqldump_command_path = $path;
2054 }
2055
2056 /**
2057 * Mysql Dump get path.
2058 */
2059 public function get_mysqldump_command_path() {
2060
2061 // Check shell_exec is available.
2062 if ( ! self::is_shell_exec_available() ) {
2063 return '';
2064 }
2065
2066 // Return now if it's already been set.
2067 if ( isset( $this->mysqldump_command_path ) ) {
2068 return $this->mysqldump_command_path;
2069 }
2070
2071 $this->mysqldump_command_path = '';
2072
2073 // Does mysqldump work.
2074 if ( is_null( shell_exec( 'hash mysqldump 2>&1' ) ) ) { // phpcs:ignore
2075
2076 // If so store it for later.
2077 $this->set_mysqldump_command_path( 'mysqldump' );
2078
2079 // And return now.
2080 return $this->mysqldump_command_path;
2081 }
2082
2083 // List of possible mysqldump locations.
2084 $mysqldump_locations = array(
2085 '/usr/local/bin/mysqldump',
2086 '/usr/local/mysql/bin/mysqldump',
2087 '/usr/mysql/bin/mysqldump',
2088 '/usr/bin/mysqldump',
2089 '/opt/local/lib/mysql6/bin/mysqldump',
2090 '/opt/local/lib/mysql5/bin/mysqldump',
2091 '/opt/local/lib/mysql4/bin/mysqldump',
2092 '/xwpdbbkpp/mysql/bin/mysqldump',
2093 '/Program Files/xwpdbbkpp/mysql/bin/mysqldump',
2094 '/Program Files/MySQL/MySQL Server 6.0/bin/mysqldump',
2095 '/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump',
2096 '/Program Files/MySQL/MySQL Server 5.4/bin/mysqldump',
2097 '/Program Files/MySQL/MySQL Server 5.1/bin/mysqldump',
2098 '/Program Files/MySQL/MySQL Server 5.0/bin/mysqldump',
2099 '/Program Files/MySQL/MySQL Server 4.1/bin/mysqldump',
2100 );
2101
2102 // Find the one which works.
2103 foreach ( $mysqldump_locations as $location ) {
2104 if ( is_executable( self::conform_dir( $location ) ) ) {
2105 $this->set_mysqldump_command_path( $location );
2106 }
2107 }
2108
2109 return $this->mysqldump_command_path;
2110 }
2111
2112 /**
2113 * Check dir.
2114 *
2115 * @param string $dir - Dir Details.
2116 * @param bool $recursive - Recursive.
2117 */
2118 public static function conform_dir( $dir, $recursive = false ) {
2119
2120 // Assume empty dir is root.
2121 if ( ! $dir ) {
2122 $dir = '/';
2123 }
2124
2125 // Replace single forward slash (looks like double slash because we have to escape it).
2126 $dir = str_replace( '\\', '/', $dir );
2127 $dir = str_replace( '//', '/', $dir );
2128
2129 // Remove the trailing slash.
2130 if ( '/' !== $dir ) {
2131 $dir = untrailingslashit( $dir );
2132 }
2133
2134 // Carry on until completely normalized.
2135 if ( ! $recursive && self::conform_dir( $dir, true ) !== $dir ) {
2136 return self::conform_dir( $dir );
2137 }
2138
2139 return (string) $dir;
2140 }
2141
2142 /**
2143 * Check Shell.
2144 */
2145 public static function is_shell_exec_available() {
2146
2147 // Are we in Safe Mode.
2148 if ( self::is_safe_mode_active() ) {
2149 return false;
2150 }
2151
2152 // Is shell_exec or escapeshellcmd or escapeshellarg disabled?
2153 if ( array_intersect( array( 'shell_exec', 'escapeshellarg', 'escapeshellcmd' ), array_map( 'trim', explode( ',', ini_get( 'disable_functions' ) ) ) ) ) {
2154 return false;
2155 }
2156
2157 // Can we issue a simple echo command?
2158 if ( ! shell_exec( 'echo WP Backup' ) ) { // phpcs:ignore
2159 return false;
2160 }
2161
2162 return true;
2163 }
2164
2165 /**
2166 * Check Safe mode active.
2167 *
2168 * @param string $ini_get_callback - String cmd.
2169 * @return bool
2170 */
2171 public static function is_safe_mode_active( $ini_get_callback = 'ini_get' ) {
2172 $safe_mode = call_user_func( $ini_get_callback, 'safe_mode' );
2173 if ( ( $safe_mode ) && 'off' !== strtolower( $safe_mode ) ) {
2174 return true;
2175 }
2176
2177 return false;
2178 }
2179
2180 /**
2181 * Database dump.
2182 *
2183 * @param string $sql_filename - File name.
2184 */
2185 public function mysqldump( $sql_filename ) {
2186 $this->mysqldump_method = 'mysqldump';
2187
2188 $host = explode( ':', DB_HOST );
2189
2190 $host = reset( $host );
2191 $port = strpos( DB_HOST, ':' ) ? end( explode( ':', DB_HOST ) ) : '';
2192
2193 // Path to the mysqldump executable.
2194 $cmd = escapeshellarg( $this->get_mysqldump_command_path() );
2195
2196 // We don't want to create a new DB.
2197 $cmd .= ' --no-create-db';
2198
2199 // Allow lock-tables to be overridden.
2200 if ( ! defined( 'WPDB_MYSQLDUMP_SINGLE_TRANSACTION' ) || WPDB_MYSQLDUMP_SINGLE_TRANSACTION !== false ) {
2201 $cmd .= ' --single-transaction';
2202 }
2203
2204 // Make sure binary data is exported properly.
2205 $cmd .= ' --hex-blob';
2206
2207 // Username.
2208 $cmd .= ' -u ' . escapeshellarg( DB_USER );
2209
2210 // Don't pass the password if it's blank.
2211 if ( DB_PASSWORD ) {
2212 $cmd .= ' -p' . escapeshellarg( DB_PASSWORD );
2213 }
2214
2215 // Set the host.
2216 $cmd .= ' -h ' . escapeshellarg( $host );
2217
2218 // Set the port if it was set.
2219 if ( ! empty( $port ) && is_numeric( $port ) ) {
2220 $cmd .= ' -P ' . $port;
2221 }
2222
2223 // The file we're saving too.
2224 $cmd .= ' -r ' . escapeshellarg( $sql_filename );
2225
2226 $wp_db_exclude_table = array();
2227 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
2228 if ( ! empty( $wp_db_exclude_table ) ) {
2229 foreach ( $wp_db_exclude_table as $wp_db_exclude_table ) {
2230 $cmd .= ' --ignore-table=' . DB_NAME . '.' . $wp_db_exclude_table;
2231 }
2232 }
2233
2234 // The database we're dumping.
2235 $cmd .= ' ' . escapeshellarg( DB_NAME );
2236
2237 // Pipe STDERR to STDOUT.
2238 $cmd .= ' 2>&1';
2239 // Store any returned data in an error.
2240 $stderr = shell_exec( $cmd ); // phpcs:ignore
2241
2242 // Skip the new password warning that is output in mysql > 5.6.
2243 if ( trim( $stderr ) === 'Warning: Using a password on the command line interface can be insecure.' ) {
2244 $stderr = '';
2245 }
2246
2247 if ( $stderr ) {
2248 $this->error( $this->get_mysqldump_method(), $stderr );
2249 }
2250
2251 return $this->verify_mysqldump( $sql_filename );
2252 }
2253
2254 /**
2255 * Error.
2256 *
2257 * @param string $context - Data.
2258 * @param object $error - Error data.
2259 */
2260 public function error( $context, $error ) {
2261 if ( empty( $context ) || empty( $error ) ) {
2262 return;
2263 }
2264 $error_str = implode( ':', (array) $error );
2265 $_key = md5( $error_str );
2266 $this->errors[ $context ][ $_key ] = $error;
2267 }
2268
2269 /**
2270 * Verify Dump.
2271 *
2272 * @param string $sql_filename - Sql file.
2273 * @return bool
2274 */
2275 public function verify_mysqldump( $sql_filename ) {
2276
2277 // If we've already passed then no need to check again.
2278 if ( ! empty( $this->mysqldump_verified ) ) {
2279 return true;
2280 }
2281
2282 // If there are mysqldump errors delete the database dump file as mysqldump will still have written one.
2283 if ( $this->get_errors( $this->get_mysqldump_method() ) && file_exists( $sql_filename ) ) {
2284 if ( file_exists( $sql_filename ) ) {
2285 wp_delete_file( $sql_filename );
2286 }
2287 }
2288
2289 // If we have an empty file delete it.
2290 if ( 0 === filesize( $sql_filename ) ) {
2291 if ( file_exists( $sql_filename ) ) {
2292 wp_delete_file( $sql_filename );
2293 }
2294 }
2295
2296 // If the file still exists then it must be good.
2297 if ( file_exists( $sql_filename ) ) {
2298 $this->mysqldump_verified = true;
2299 return $this->mysqldump_verified;
2300 }
2301
2302 return false;
2303 }
2304
2305 /**
2306 * Get error.
2307 *
2308 * @param string $context - Data.
2309 * @return string
2310 */
2311 public function get_errors( $context = null ) {
2312 if ( ! empty( $context ) ) {
2313 return isset( $this->errors[ $context ] ) ? $this->errors[ $context ] : array();
2314 }
2315
2316 return $this->errors;
2317 }
2318
2319 /**
2320 * Get mysql dump method.
2321 *
2322 * @return string
2323 */
2324 public function get_mysqldump_method() {
2325 return $this->mysqldump_method;
2326 }
2327
2328 // End : Generate SQL DUMP using cmd 06-03-2016.
2329
2330 /**
2331 * Create zip.
2332 */
2333 public function wp_db_backup_create_archive() {
2334 // Begin : Setup Upload Directory, Secure it and generate a random file name.
2335
2336 $source_directory = $this->wp_db_backup_wp_config_path();
2337
2338 $path_info = wp_upload_dir();
2339 $htasses_text = '';
2340 global $wpdb,$wp_filesystem;
2341 if ( ! function_exists( 'WP_Filesystem' ) ) {
2342 require_once ABSPATH . '/wp-admin/includes/file.php';
2343 }
2344 WP_Filesystem();
2345
2346 if(!$wp_filesystem){
2347 error_log('Could not initialize WP_Filesystem');
2348 return false;
2349 }
2350
2351 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR);
2352 wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log');
2353 $file_contents = "<?php\n// Silence is golden.\n";
2354
2355 // Create the file with the given contents
2356 $wp_filesystem->put_contents( $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/index.php', $file_contents, FS_CHMOD_FILE );
2357 $wp_filesystem->put_contents( $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/index.php', $file_contents, FS_CHMOD_FILE );
2358
2359
2360 // Added htaccess file 08-05-2015 for prevent directory listing.
2361 // Fixed Vulnerability 22-06-2016 for prevent direct download.
2362 if ( 1 === (int) get_option( 'wp_db_backup_enable_htaccess' ) ) {
2363 $htaccess_content = '#These next two lines will already exist in your .htaccess file
2364 RewriteEngine On
2365 RewriteBase /
2366 # Add these lines right after the preceding two
2367 RewriteCond %{REQUEST_FILENAME} ^.*(.zip)$
2368 RewriteCond %{HTTP_COOKIE} !^.*can_download.*$ [NC]
2369 RewriteRule . - [R=403,L]';
2370 $wp_filesystem->put_contents( $path_info['basedir'] . '/db-backup/.htaccess', $htaccess_content, FS_CHMOD_FILE );
2371
2372 }
2373 // Begin : Generate SQL DUMP and save to file database.sql.
2374 $wp_site_name = preg_replace('/[^\p{L}\p{M}]+/u', '_', get_bloginfo('name'));
2375 $wp_db_file_name = $wp_site_name . '_' . gmdate( 'Y_m_d' ) . '_' . time() . '_' . substr( md5( AUTH_KEY ), 0, 7 ) . '_wpdb';
2376 $sql_filename = $wp_db_file_name . '.sql';
2377 $filename = $wp_db_file_name . '.zip';
2378 $logname = $wp_db_file_name . '.txt';
2379
2380 // Begin : Generate SQL DUMP using cmd 06-03-2016.
2381 $my_sql_dump = 0;
2382 if ( $this->get_mysqldump_command_path() ) {
2383 if ( ! $this->mysqldump( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) {
2384 $my_sql_dump = 1;
2385 }
2386 } else {
2387 $my_sql_dump = 1;
2388 }
2389
2390 if ( 1 === (int) $my_sql_dump ) {
2391 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2392 $options_backup = get_option( 'wp_db_backup_backups' );
2393 $settings_backup = get_option( 'wp_db_backup_options' );
2394 $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
2395 if($wp_db_save_settings_in_backup){
2396 delete_option( 'wp_db_backup_backups' );
2397 delete_option( 'wp_db_backup_options' );
2398 }
2399 /* END : Prevent saving backup plugin settings in the database dump */
2400 //phpcs:ignore -- using direct query get all tables name to be backedup.
2401 $tables = $wpdb->get_col( 'SHOW TABLES' );
2402 $wp_db_exclude_table = get_option( 'wp_db_exclude_table',array());
2403 if(!empty($tables)){
2404 foreach($tables as $table){
2405 if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
2406 $this->wp_db_backup_create_mysql_backup_new($table, $path_info['basedir'] . '/db-backup/' . $sql_filename );
2407 }
2408 }
2409
2410 }
2411 /* BEGIN : Prevent saving backup plugin settings in the database dump */
2412 $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
2413 add_option( 'wp_db_backup_backups', $options_backup );
2414 add_option( 'wp_db_backup_options', $settings_backup );
2415 /* END : Prevent saving backup plugin settings in the database dump */
2416 }
2417 /* End : Generate SQL DUMP using cmd 06-03-2016 */
2418
2419 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
2420 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
2421 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
2422 $filecontent = wp_remote_get( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2423 if (! is_wp_error( $filecontent ) && isset($filecontent['body']) ) {
2424 $backup_str = str_replace( $wp_db_backup_search_text, $wp_db_backup_replace_text, $filecontent['body'] );
2425 $wp_filesystem->put_contents( $path_info['basedir'] . '/db-backup/' . $sql_filename, $backup_str, FS_CHMOD_FILE );
2426 }
2427 }
2428
2429 /* End : Generate SQL DUMP and save to file database.sql */
2430 $upload_path = array(
2431 'filename' => ( $filename ),
2432 'dir' => ( $path_info['basedir'] . '/db-backup/' . $filename ),
2433 'url' => ( $path_info['baseurl'] . '/db-backup/' . $filename ),
2434 'log_dir' => ( $path_info['basedir'] . '/db-backup/log/' . $logname ),
2435 'log_url' => ( $path_info['baseurl'] . '/db-backup/log/' . $logname ),
2436 'size' => 0,
2437 );
2438 $arcname = $path_info['basedir'] . '/db-backup/' . $wp_db_file_name . '.zip';
2439 if ( class_exists( 'ZipArchive' ) ) {
2440 $zip = new ZipArchive();
2441 $zip->open( $arcname, ZipArchive::CREATE );
2442 $zip->addFile( $path_info['basedir'] . '/db-backup/' . $sql_filename, $sql_filename );
2443 $zip->close();
2444 } else {
2445 require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
2446 $archive = new PclZip( $arcname );
2447 $v_dir = $path_info['basedir'] . '/db-backup/' . $sql_filename;
2448 $v_remove = $path_info['basedir'] . '/db-backup';
2449 // Create the archive.
2450 $v_list = $archive->create( $v_dir, PCLZIP_OPT_REMOVE_PATH, $v_remove );
2451 }
2452
2453
2454 $mysqlversion = wp_cache_get( 'wpdb_mysqlversion' );
2455 if ( true === empty( $mysqlversion ) ) {
2456 $mysqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' ); // phpcs:ignore
2457 wp_cache_set( 'wpdb_mysqlversion', $mysqlversion, '', 18000 );
2458 }
2459 if ( ! function_exists( 'get_plugins' ) ) {
2460 require_once ABSPATH . 'wp-admin/includes/plugin.php';
2461 }
2462 $my_theme = wp_get_theme();
2463 $active_plugin = count(get_option('active_plugins'));
2464 $total_plugin = count(get_plugins());
2465 $log_message = '<b>WordPress Version</b> : ' . get_bloginfo( 'version' );
2466 $log_message .= '<br> <b>Database Version</b> : ' . $mysqlversion;
2467 $log_message .= '<br> <b>Active Theme Name</b> : ' . $my_theme->get( 'Name' );
2468 $log_message .= '<br> <b>Theme Version</b> : ' . $my_theme->get( 'Version' );
2469 $log_message .= '<br> <b>Plugin Count</b> : ' . $total_plugin;
2470 $log_message .= '<br> <b>Active Plugins</b> : ' . $active_plugin;
2471
2472 $upload_path['size'] = filesize( $upload_path['dir'] );
2473 $upload_path['sqlfile'] = $path_info['basedir'] . '/db-backup/' . $sql_filename;
2474 $wp_db_log = get_option( 'wp_db_log' );
2475 if ( 1 === (int) $wp_db_log ) {
2476 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
2477 if ( ! empty( $wp_db_exclude_table ) ) {
2478 $log_message .= '<br> <b>Exclude Table</b> : ' . implode( ', ', $wp_db_exclude_table );
2479 }
2480 $upload_path['log'] = $log_message;
2481 }
2482 $options = get_option( 'wp_db_backup_backups' );
2483 $newoptions = array();
2484 $number_of_existing_backups = count( (array) $options );
2485 $number_of_backups_from_user = get_option( 'wp_local_db_backup_count' );
2486 if ( ! empty( $number_of_backups_from_user ) ) {
2487 if ( ! ( $number_of_existing_backups < $number_of_backups_from_user ) ) {
2488 $diff = $number_of_existing_backups - $number_of_backups_from_user;
2489 for ( $i = 0; $i <= $diff; $i++ ) {
2490 $index = $i;
2491 if ( isset($options[ $index ]['dir']) && file_exists( $options[ $index ]['dir'] ) ) {
2492 wp_delete_file( $options[ $index ]['dir'] );
2493 }
2494 $file_sql = explode( '.', $options[ $index ]['dir'] );
2495 if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) {
2496 wp_delete_file( $file_sql[0] . '.sql' );
2497 }
2498 }
2499 for ( $i = ( $diff + 1 ); $i < $number_of_existing_backups; $i++ ) {
2500 $index = $i;
2501
2502 $newoptions[] = $options[ $index ];
2503 }
2504 $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
2505
2506 update_option( 'wp_db_backup_backups', $newoptions , false);
2507 }
2508 }
2509
2510 if ( file_exists( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) {
2511 wp_delete_file( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2512 }
2513 return $upload_path;
2514 }
2515
2516 /**
2517 * Config Path.
2518 */
2519 public function wp_db_backup_wp_config_path() {
2520 $base = dirname( __FILE__ );
2521 $path = false;
2522 if ( file_exists( dirname( dirname( $base ) ) . '/wp-config.php' ) ) {
2523 $path = dirname( dirname( $base ) );
2524 } else {
2525 if ( file_exists( dirname( dirname( dirname( $base ) ) ) . '/wp-config.php' ) ) {
2526 $path = dirname( dirname( dirname( $base ) ) );
2527 } else {
2528 $path = false;
2529 }
2530 }
2531 if ( false !== $path ) {
2532 $path = str_replace( '\\', '/', $path );
2533 }
2534 return $path;
2535 }
2536
2537 /**
2538 * Backup Process.
2539 */
2540 public function wp_db_backup_event_process() {
2541 // Added in v.3.9.5!
2542 global $wp_filesystem;
2543 if(!function_exists('WP_Filesystem')){
2544 require_once ( ABSPATH . '/wp-admin/includes/file.php' );
2545 }
2546 WP_Filesystem();
2547
2548 $cron_condition = apply_filters('wpdbbkp_dbback_cron_condition',true );
2549 if(wp_doing_cron() && !$cron_condition){
2550 return false;
2551 }
2552
2553 set_time_limit( 0 );
2554 ignore_user_abort(true);
2555
2556 $details = $this->wp_db_backup_create_archive();
2557 $options = get_option( 'wp_db_backup_backups' );
2558
2559 if ( ! $options ) {
2560 $options = array();
2561 }
2562 $is_search_replace_flag = 0;
2563 $wp_db_log = get_option( 'wp_db_log' );
2564 if ( 1 === (int) $wp_db_log ) {
2565 $log_message = $details['log'];
2566 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
2567 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
2568 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
2569 $log_message .= ' Replaced/Search text - ' . $wp_db_backup_search_text . ' With -' . $wp_db_backup_replace_text;
2570 $is_search_replace_flag = 1;
2571 }
2572 } else {
2573 $log_message = '';
2574 }
2575 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
2576 $destination = ( 1 === (int) $wp_db_remove_local_backup ) ? '' : 'Local, ';
2577
2578 $args = array( $details['filename'], $details['dir'], $log_message, $details['size'], $destination );
2579 do_action_ref_array( 'wp_db_backup_completed', array( &$args ) );
2580
2581 $options[] = array(
2582 'date' => time(),
2583 'filename' => $details['filename'],
2584 'url' => $details['url'],
2585 'dir' => $details['dir'],
2586 'log' => $details['log_url'],
2587 'search_replace' => $is_search_replace_flag,
2588 'sqlfile' => $details['sqlfile'],
2589 'size' => $details['size'],
2590 'type' =>'database',
2591 'destination' => $args[4]
2592 );
2593 if ( 1 !== (int) $wp_db_remove_local_backup ) {
2594 $options = wpdbbkp_filter_unique_filenames( $options );
2595 update_option( 'wp_db_backup_backups', $options , false);
2596 }
2597 if(isset($details['log_dir']) && !empty($details['log_dir']))
2598 {
2599 if ($wp_filesystem->is_writable($details['log_dir']) || file_exists($details['log_dir'])) {
2600 $wp_filesystem->put_contents( $details['log_dir'], str_replace(array("<br>","<b>","</b>"), array("\n","",""), $args[2]), FS_CHMOD_FILE );
2601 }
2602 }
2603 }
2604
2605 /**
2606 * Cron schedule.
2607 *
2608 * @param array $schedules - Schedules details.
2609 */
2610 public function wp_db_backup_cron_schedules( $schedules ) {
2611 $schedules['hourly'] = array(
2612 'interval' => 3600,
2613 'display' => 'hourly',
2614 );
2615 $schedules['twicedaily'] = array(
2616 'interval' => 43200,
2617 'display' => 'twicedaily',
2618 );
2619 $schedules['daily'] = array(
2620 'interval' => 86400,
2621 'display' => 'daily',
2622 );
2623 $schedules['weekly'] = array(
2624 'interval' => 604800,
2625 'display' => 'Once Weekly',
2626 );
2627 $schedules['monthly'] = array(
2628 'interval' => 2635200,
2629 'display' => 'Once a month',
2630 );
2631 return $schedules;
2632 }
2633
2634 /**
2635 * Schedular activation.
2636 */
2637 public function wp_db_backup_scheduler_activation() {
2638 $options = get_option( 'wp_db_backup_options' );
2639 if ( ( ! wp_next_scheduled( 'wpdbbkp_db_backup_event' ) ) && ( true === isset( $options['enable_autobackups'] ) ) ) {
2640 $cron_freq = apply_filters( 'wpdbbkp_dbback_cron_frequency',$options['autobackup_frequency']);
2641 if(isset($options['autobackup_type']) && $options['autobackup_type'] == 'db')
2642 {
2643 $timestamp = strtotime('today 23:59'); // Start at the next midnight
2644 wp_schedule_event( $timestamp , $cron_freq, 'wpdbbkp_db_backup_event' );
2645
2646 }
2647 }else{
2648 if( !empty($options) && ( false === isset( $options['enable_autobackups'] ) ) || ( true === isset( $options['enable_autobackups'] ) ) && isset($options['autobackup_type']) && $options['autobackup_type'] != 'db')
2649 {
2650 wp_clear_scheduled_hook( 'wpdbbkp_db_backup_event' );
2651 }
2652
2653 }
2654 }
2655
2656 /**
2657 * Config data.
2658 *
2659 * @param string $key - key name.
2660 */
2661 public function wp_backup_get_config_data( $key ) {
2662 $filepath = get_home_path() . '/wp-config.php';
2663 $config_file = @file_get_contents( "$filepath", true );
2664 if($config_file){
2665 switch ( $key ) {
2666 case 'DB_NAME':
2667 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2668 break;
2669 case 'DB_USER':
2670 preg_match( "/'DB_USER',\s*'(.*)?'/", $config_file, $matches );
2671 break;
2672 case 'DB_PASSWORD':
2673 preg_match( "/'DB_PASSWORD',\s*'(.*)?'/", $config_file, $matches );
2674 break;
2675 case 'DB_HOST':
2676 preg_match( "/'DB_HOST',\s*'(.*)?'/", $config_file, $matches );
2677 break;
2678 }
2679 return $matches[1];
2680 }
2681
2682 return '';
2683
2684 }
2685
2686 /**
2687 * Get db name from config.
2688 */
2689 public function wp_backup_get_config_db_name() {
2690 $filepath = get_home_path() . '/wp-config.php';
2691 $config_file = @file_get_contents( "$filepath", true );
2692 if($config_file){
2693 preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2694 return $matches[1];
2695 }
2696 return '';
2697 }
2698
2699 /**
2700 * Recursive sanitation for an array
2701 *
2702 * @param array $array - Array data to sanitize.
2703 *
2704 * @return mixed
2705 */
2706 public function recursive_sanitize_text_field( $array ) {
2707 if( ! is_array( $array ) ) {
2708 return sanitize_text_field( $array );
2709 }
2710 foreach ( $array as $key => &$value ) {
2711 if ( is_array( $value ) ) {
2712 $value = $this->recursive_sanitize_text_field( $value );
2713 } else {
2714 $value = sanitize_text_field( $value );
2715 }
2716 }
2717
2718 return $array;
2719 }
2720
2721 /**
2722 * Enqueue scripts and style
2723 */
2724 public function admin_scripts_style() {
2725 if ( true === $this->is_wpdb_page() ) {
2726 wp_enqueue_script( 'jquery' );
2727
2728 wp_register_script( 'bootstrapjs', WPDB_PLUGIN_URL . '/assets/js/bootstrap.min.js', array( 'jquery' ), WPDB_VERSION, false );
2729 wp_enqueue_script( 'bootstrapjs' );
2730
2731 wp_register_style( 'bootstrapcss', WPDB_PLUGIN_URL . '/assets/css/bootstrap.min.css', array(), WPDB_VERSION );
2732 wp_enqueue_style( 'bootstrapcss' );
2733
2734 wp_register_script( 'dataTablesjs', WPDB_PLUGIN_URL . '/assets/js/jquery.dataTables.js', array( 'jquery' ), WPDB_VERSION, false );
2735 wp_enqueue_script( 'dataTablesjs' );
2736
2737 wp_register_style( 'dataTablescss', WPDB_PLUGIN_URL . '/assets/css/jquery.dataTables.css', array(), WPDB_VERSION );
2738 wp_enqueue_style( 'dataTablescss' );
2739
2740 wp_register_style( 'wpdbcss', WPDB_PLUGIN_URL . '/assets/css/wpdb_admin.css', array(), WPDB_VERSION );
2741 wp_enqueue_style( 'wpdbcss' );
2742 }
2743 }
2744
2745 /**
2746 * Check is plugin page.
2747 */
2748 public function is_wpdb_page() {
2749
2750 if ( is_admin() ) {
2751
2752 return isset( $_REQUEST['page'] ) && preg_match( '/wp-database-backup/', $_REQUEST['page'] ) ? true : false; // phpcs:ignore
2753
2754 } else {
2755
2756 return true;
2757 }
2758 }
2759
2760 // loading admin scripts/styles on admin page only
2761
2762 public function wpdbbkp_admin_style($hook_suffix)
2763 {
2764 if($hook_suffix=="tools_page_wp-database-backup" || $hook_suffix=="toplevel_page_wp-database-backup")
2765 {
2766 wp_register_script('wpdbbkp-admin-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin.js', array('jquery'), WPDB_VERSION, 'true' );
2767 wp_localize_script('wpdbbkp-admin-script', 'wpdbbkp_script_vars', array(
2768 'nonce' => wp_create_nonce( 'wpdbbkp-admin-nonce' ),
2769 ));
2770 wp_enqueue_script('wpdbbkp-admin-script');
2771
2772 // Adding custom js
2773 $local = array(
2774 'ajax_url' => admin_url( 'admin-ajax.php' ),
2775 'wpdbbkp_admin_security_nonce' => wp_create_nonce('wpdbbkp_ajax_check_nonce'),
2776 );
2777 wp_register_script('wpdbbkp-admin-fb', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin-cron-backup.js', array(), WPDB_VERSION , true );
2778
2779 wp_localize_script('wpdbbkp-admin-fb', 'wpdbbkp_localize_admin_data', $local );
2780 wp_enqueue_script('wpdbbkp-admin-fb');
2781 // Custom Js ends
2782 }
2783 }
2784
2785 public function wpdbbkp_admin_newsletter_script($hook_suffix ) {
2786 if($hook_suffix=="tools_page_wp-database-backup" || $hook_suffix=="toplevel_page_wp-database-backup")
2787 {
2788 wp_enqueue_script('wpdbbkp-admin-newsletter-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin-newsletter.js', array('jquery'), WPDB_VERSION, 'true' );
2789
2790 $current_screen = get_current_screen();
2791
2792 if(isset($current_screen->post_type)){
2793 $post_type = $current_screen->post_type;
2794 }
2795
2796 $post_id = get_the_ID();
2797 //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2798 if(isset($_GET['tag_ID'])){
2799 //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2800 $post_id = intval($_GET['tag_ID']);
2801 }
2802
2803
2804
2805 $data = array(
2806 'current_url' => wpdbbkp_get_current_url(),
2807 'post_id' => $post_id,
2808 'ajax_url' => admin_url( 'admin-ajax.php' ),
2809 'post_type' => $post_type,
2810 'page_now' => $hook_suffix,
2811 'wpdbbkp_security_nonce' => wp_create_nonce('wpdbbkp_ajax_check_nonce'),
2812 );
2813
2814 $data = apply_filters('wpdbbkp_localize_filter',$data,'wpdbbkp_localize_data');
2815
2816 wp_localize_script( 'wpdbbkp-admin-newsletter-script', 'wpdbbkp_localize_data', $data );
2817
2818 }
2819
2820 }
2821
2822 public function wpdbbkp_sanitize_textarea_field( $str ) {
2823
2824 if ( is_object( $str ) || is_array( $str ) ) {
2825 return '';
2826 }
2827
2828 $str = (string) $str;
2829
2830 $filtered = wp_check_invalid_utf8( $str );
2831
2832 if ( strpos( $filtered, '<' ) !== false ) {
2833 $filtered = wp_pre_kses_less_than( $filtered );
2834 // This will strip extra whitespace for us.
2835 $filtered = wp_strip_all_tags( $filtered, false );
2836
2837 // Use HTML entities in a special case to make sure no later
2838 // newline stripping stage could lead to a functional tag.
2839 $filtered = str_replace( "<\n", "&lt;\n", $filtered );
2840 }
2841
2842 $filtered = trim( $filtered );
2843
2844 $found = false;
2845 while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
2846 $filtered = str_replace( $match[0], '', $filtered );
2847 $found = true;
2848 }
2849
2850 if ( $found ) {
2851 // Strip out the whitespace that may now exist after removing the octets.
2852 $filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
2853 }
2854
2855 return $filtered;
2856 }
2857
2858 public function wpdbbkp_send_query_message(){
2859
2860 if ( ! isset( $_POST['wpdbbkp_security_nonce'] ) ){
2861 return;
2862 }
2863 if ( !wp_verify_nonce( $_POST['wpdbbkp_security_nonce'], 'wpdbbkp-admin-nonce' ) ){
2864 return;
2865 }
2866
2867 if( ! current_user_can( 'manage_options' ) ) {
2868 return;
2869 }
2870
2871 $message = $this->wpdbbkp_sanitize_textarea_field($_POST['message']);
2872 $email = $this->wpdbbkp_sanitize_textarea_field($_POST['email']);
2873
2874 if(function_exists('wp_get_current_user')){
2875
2876 $user = wp_get_current_user();
2877
2878 $message = '<p>'.$message.'</p><br><br>'.'Query from BackupforWP plugin support tab';
2879
2880 $user_data = $user->data;
2881 $user_email = $user_data->user_email;
2882
2883 if($email){
2884 $user_email = $email;
2885 }
2886 //php mailer variables
2887 $sendto = 'team@magazine3.in';
2888 $subject = "BackupforWP Query";
2889
2890 $headers[] = 'Content-Type: text/html; charset=UTF-8';
2891 $headers[] = 'From: '. esc_attr($user_email);
2892 $headers[] = 'Reply-To: ' . esc_attr($user_email);
2893 // Load WP components, no themes.
2894
2895 $sent = wp_mail($sendto, $subject, $message, $headers);
2896
2897 if($sent){
2898
2899 echo wp_json_encode(array('status'=>'t'));
2900
2901 }else{
2902
2903 echo wp_json_encode(array('status'=>'f'));
2904
2905 }
2906
2907 }
2908
2909 wp_die();
2910 }
2911 public function add_settings_plugin_action_wp( $actions, $plugin_file, $plugin_data, $context ) {
2912 $plugin_actions['settings'] = sprintf(
2913 '<a href="%s">' . _x( 'Settings', 'wpdbbkp' ) . '</a>',
2914 admin_url( 'options-general.php?page=wp-database-backup' )
2915 );
2916 $actions = array_merge( $actions, $plugin_actions );
2917 return $actions;
2918 }
2919
2920 public function wpdbbkp_update_backup_info($FileName, $logFile, $logMessage = '') {
2921 $path_info = wp_upload_dir();
2922 $filename = $FileName . '.sql';
2923 $WPDBFileName = $FileName . '.zip';
2924 wp_delete_file($this->wp_db_backup_wp_config_path() . '/' . $filename);
2925 wp_delete_file($this->wp_db_backup_wp_config_path() . '/wp_installer.php');
2926 @$filesize = filesize($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName);
2927
2928 $upload_path = array(
2929 'filename' => ($WPDBFileName),
2930 'dir' => ($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName),
2931 'url' => ($path_info['baseurl'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName),
2932 'size' => ($filesize),
2933 'type' => get_option('wp_db_backup_backup_type')
2934 );
2935
2936
2937 if (get_option('wp_db_log') == 1) {
2938 $this->write_log($logFile, $logMessage);
2939 $upload_path['logfile'] = $path_info['baseurl'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $FileName . '.txt';
2940 $upload_path['logfileDir'] = $logFile;
2941 } else {
2942 $upload_path['logfile'] = "";
2943 }
2944 $args = array($FileName, $logFile, $logMessage);
2945 do_action_ref_array('wpdbbkp_backup_completed', array(&$args));
2946 return $upload_path;
2947 }
2948
2949 private function write_log($logFile, $logMessage) {
2950 // Actually write the log file
2951 global $wp_filesystem;
2952 if(!function_exists('WP_Filesystem')){
2953 require_once ( ABSPATH . '/wp-admin/includes/file.php' );
2954 }
2955 WP_Filesystem();
2956
2957 if ($wp_filesystem && $wp_filesystem->is_writable($logFile) || !$wp_filesystem->exists($logFile)) {
2958 $wp_filesystem->put_contents( $logFile, $logMessage, FS_CHMOD_FILE );
2959 return true;
2960 }
2961 }
2962
2963 public function get_zip_command_path() {
2964
2965 // Check shell_exec is available
2966 if (!self::is_shell_exec_available())
2967 return '';
2968
2969 // Return now if it's already been set
2970 if (isset($this->zip_command_path))
2971 return $this->zip_command_path;
2972
2973 $this->zip_command_path = '';
2974
2975 // Does zip work
2976 if (is_null(shell_exec('hash zip 2>&1'))) {
2977
2978 // If so store it for later
2979 $this->set_zip_command_path('zip');
2980
2981 // And return now
2982 return $this->zip_command_path;
2983 }
2984
2985 // List of possible zip locations
2986 $zip_locations = array(
2987 '/usr/bin/zip'
2988 );
2989
2990 // Find the one which works
2991 foreach ($zip_locations as $location)
2992 if (@is_executable(self::conform_dir($location)))
2993 $this->set_zip_command_path($location);
2994
2995 return $this->zip_command_path;
2996 }
2997
2998 public function set_zip_command_path($path) {
2999
3000 $this->zip_command_path = $path;
3001 }
3002
3003 /* Begin : Generate Zip using cmd 06-03-2016 V.3.9 */
3004
3005 public function zip($WPDBFileName) {
3006
3007 $this->archive_method = 'zip';
3008 $wp_all_backup_exclude_dir = get_option('wp_db_backup_exclude_dir');
3009 if (empty($wp_all_backup_exclude_dir)) {
3010 $excludes = WPDB_BACKUPS_DIR;
3011 } else {
3012 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
3013 }
3014 // Zip up $this->root with excludes
3015 if (!empty($excludes)) {
3016 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' -x ' . $this->exclude_string('zip') . ' 2>&1');
3017 }
3018
3019 // Zip up $this->root without excludes
3020 else {
3021 // error_log('without exclude rule');
3022 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' 2>&1');
3023 }
3024 error_log($stderr);
3025 if (!empty($stderr))
3026 $this->warning($this->get_archive_method(), $stderr);
3027
3028 return $this->verify_archive($WPDBFileName);
3029 }
3030
3031 public function get_root() {
3032
3033 if (empty($this->root))
3034 $this->set_root(self::conform_dir(self::get_home_path()));
3035
3036 return $this->root;
3037 }
3038
3039 public function set_root($path) {
3040
3041 if (empty($path) || !is_string($path) || !is_dir($path))
3042 throw new Exception('Invalid root path <code>' . esc_html($path) . '</code> must be a valid directory path');
3043
3044 $this->root = self::conform_dir($path);
3045 }
3046
3047 public static function get_home_path() {
3048
3049 $home_url = home_url();
3050 $site_url = site_url();
3051
3052 $home_path = ABSPATH;
3053
3054 // If site_url contains home_url and they differ then assume WordPress is installed in a sub directory
3055 if ($home_url !== $site_url && strpos($site_url, $home_url) === 0)
3056 $home_path = trailingslashit(substr(self::conform_dir(ABSPATH), 0, strrpos(self::conform_dir(ABSPATH), str_replace($home_url, '', $site_url))));
3057
3058 return self::conform_dir($home_path);
3059 }
3060
3061 private function warning($context, $warning) {
3062
3063 if (empty($context) || empty($warning))
3064 return;
3065 $this->warnings[$context][$_key = md5(implode(':', (array) $warning))] = $warning;
3066 }
3067
3068 public function exclude_string($context = 'zip') {
3069
3070 // Return a comma separated list by default
3071 $separator = ', ';
3072 $wildcard = '';
3073
3074 // The zip command
3075 if ($context === 'zip') {
3076 $wildcard = '*';
3077 $separator = ' -x ';
3078
3079 // The PclZip fallback library
3080 } elseif ($context === 'regex') {
3081 $wildcard = '([\s\S]*?)';
3082 $separator = '|';
3083 }
3084
3085 $wp_all_backup_exclude_dir = get_option('wp_db_backup_exclude_dir');
3086 if (empty($wp_all_backup_exclude_dir)) {
3087 $excludes = WPDB_BACKUPS_DIR;
3088 } else {
3089 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
3090 }
3091
3092 $excludes = explode("|", $excludes);
3093 if(!empty($excludes) && is_array($excludes)){
3094 foreach ($excludes as $key => &$rule) {
3095
3096 $file = $absolute = $fragment = false;
3097
3098 // Files don't end with /
3099 if (!in_array(substr($rule, -1), array('\\', '/')))
3100 $file = true;
3101
3102 // If rule starts with a / then treat as absolute path
3103 elseif (in_array(substr($rule, 0, 1), array('\\', '/')))
3104 $absolute = true;
3105
3106 // Otherwise treat as dir fragment
3107 else
3108 $fragment = true;
3109
3110 // Strip $this->root and conform
3111 $rule = str_ireplace($this->get_root(), '', untrailingslashit(self::conform_dir($rule)));
3112
3113 // Strip the preceeding slash
3114 if (in_array(substr($rule, 0, 1), array('\\', '/')))
3115 $rule = substr($rule, 1);
3116
3117 // Escape string for regex
3118 if ($context === 'regex')
3119 $rule = str_replace('.', '\.', $rule);
3120
3121 // Convert any existing wildcards
3122 if ($wildcard !== '*' && strpos($rule, '*') !== false)
3123 $rule = str_replace('*', $wildcard, $rule);
3124
3125 // Wrap directory fragments and files in wildcards for zip
3126 if ($context === 'zip' && ( $fragment || $file ))
3127 $rule = $wildcard . $rule . $wildcard;
3128
3129 // Add a wildcard to the end of absolute url for zips
3130 if ($context === 'zip' && $absolute)
3131 $rule .= $wildcard;
3132
3133 // Add and end carrot to files for pclzip but only if it doesn't end in a wildcard
3134 if ($file && $context === 'regex')
3135 $rule .= '$';
3136
3137 // Add a start carrot to absolute urls for pclzip
3138 if ($absolute && $context === 'regex')
3139 $rule = '^' . $rule;
3140 }
3141 }
3142
3143
3144 // Escape shell args for zip command
3145 if ($context === 'zip')
3146 $excludes = array_map('escapeshellarg', array_unique($excludes));
3147
3148 return implode($separator, $excludes);
3149 }
3150
3151 public function get_archive_method() {
3152 return $this->archive_method;
3153 }
3154
3155 public function verify_archive($WPDBFileName) {
3156 // If we've already passed then no need to check again
3157 if (!empty($this->archive_verified))
3158 return true;
3159
3160 // If there are errors delete the backup file.
3161 if ($this->get_errors($this->get_archive_method()) && file_exists($WPDBFileName))
3162 wp_delete_file($WPDBFileName);
3163
3164 // If the archive file still exists assume it's good
3165 if (file_exists($WPDBFileName))
3166 return $this->archive_verified = true;
3167
3168 return false;
3169 }
3170
3171 public function get_files() {
3172
3173 if (!empty($this->files))
3174 return $this->files;
3175
3176 $this->files = array();
3177
3178 // We only want to use the RecursiveDirectoryIterator if the FOLLOW_SYMLINKS flag is available
3179 if (defined('RecursiveDirectoryIterator::FOLLOW_SYMLINKS')) {
3180
3181 $this->files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->get_root(), RecursiveDirectoryIterator::FOLLOW_SYMLINKS), RecursiveIteratorIterator::SELF_FIRST, RecursiveIteratorIterator::CATCH_GET_CHILD);
3182
3183 // Skip dot files if the SKIP_Dots flag is available
3184 if (defined('RecursiveDirectoryIterator::SKIP_DOTS'))
3185 $this->files->setFlags(RecursiveDirectoryIterator::SKIP_DOTS + RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
3186
3187
3188 // If RecursiveDirectoryIterator::FOLLOW_SYMLINKS isn't available then fallback to a less memory efficient method
3189 } else {
3190
3191 $this->files = $this->get_files_fallback($this->get_root());
3192 }
3193
3194 return $this->files;
3195 }
3196
3197 public function wpdbbkp_get_timeago( $time )
3198 {
3199 $time = intval($time) > 0 ? intval($time) : time();
3200
3201 $time_difference = time() - $time;
3202
3203 if( $time_difference < 1 ) { return 'less than 1 second ago'; }
3204 $condition = array( 12 * 30 * 24 * 60 * 60 => 'year',
3205 30 * 24 * 60 * 60 => 'month',
3206 24 * 60 * 60 => 'day',
3207 60 * 60 => 'hour',
3208 60 => 'minute',
3209 1 => 'second'
3210 );
3211
3212 foreach( $condition as $secs => $str )
3213 {
3214 $d = $time_difference / $secs;
3215
3216 if( $d >= 1 )
3217 {
3218 $t = floor( $d );
3219 return 'About ' . $t . ' ' . $str . ( $t > 1 ? 's' : '' ) . ' ago';
3220 }
3221 }
3222 }
3223
3224 private function wpdbbkp_append_to_file($file_path, $content_to_append){
3225 global $wp_filesystem;
3226
3227 if (!function_exists('WP_Filesystem')) {
3228 require_once ABSPATH . 'wp-admin/includes/file.php';
3229 }
3230
3231
3232 if (empty($wp_filesystem)) {
3233 WP_Filesystem();
3234 }
3235
3236 if (!$wp_filesystem) {
3237 return false;
3238 }
3239
3240 // Check if the file exists
3241 if ($wp_filesystem->exists($file_path)) {
3242 // Open the file in append mode
3243 $handle = $wp_filesystem->get_contents($file_path);
3244
3245 if ($handle) {
3246 // Append the new content
3247 $result = $wp_filesystem->put_contents($file_path, $handle . $content_to_append, FS_CHMOD_FILE);
3248 return $result !== false;
3249 }
3250 } else {
3251 // If the file doesn't exist, create it with the initial content
3252 $result = $wp_filesystem->put_contents($file_path, $content_to_append, FS_CHMOD_FILE);
3253 return $result !== false;
3254 }
3255
3256 return false;
3257 }
3258
3259 }
3260
3261 new Wpdb_Admin();
3262