PluginProbe
WP Database Backup – Unlimited Database & Files Backup by Backup for WP / 7.4
WP Database Backup – Unlimited Database & Files Backup by Backup for WP v7.4
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
← All changes | includes/admin/class-wpdb-admin.php +1381 -467 6.27.4 View file →
@@ -3,9 +3,8 @@
3 3 * Backup admin.
4 4 *
5 5 * @package wpdbbkp
6 6 */
7 -
8 7 ob_start();
9 8 if ( ! defined( 'ABSPATH' ) ) {
10 9 exit; // Exit if accessed directly.
11 10 }
@@ -16,8 +15,12 @@
16 15 * @class Wpdb_Admin
17 16 */
18 17 class Wpdb_Admin {
19 18
19 + public $mysqldump_command_path;
20 + public $root;
21 + public $files;
22 +
20 23 /**
21 24 * Construct.
22 25 */
23 26 public function __construct() {
@@ -24,11 +27,10 @@
24 27 add_action( 'admin_init', array( $this, 'wp_db_backup_admin_init' ) );
25 28 add_action( 'admin_init', array( $this, 'admin_scripts_style' ) );
26 29 add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
27 30 add_filter( 'cron_schedules', array( $this, 'wp_db_backup_cron_schedules' ) );
28 - add_action( 'wp_db_backup_event', array( $this, 'wp_db_backup_event_process' ) );
29 - add_action( 'wp', array( $this, 'wp_db_backup_scheduler_activation' ) );
30 - add_action( 'wp_logout', array( $this, 'wp_db_cookie_expiration' ) ); // Fixed Vulnerability 22-06-2016 for prevent direct download.
31 + add_action( 'wpdbbkp_db_backup_event', array( $this, 'wp_db_backup_event_process' ) );
32 + add_action( 'init', array( $this, 'wp_db_backup_scheduler_activation' ) );
31 33 add_action( 'wp_db_backup_completed', array( $this, 'wp_db_backup_completed_local' ), 12 );
32 34 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_style'));
33 35 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_newsletter_script'));
34 36 add_action('wp_ajax_wpdbbkp_send_query_message', array( $this, 'wpdbbkp_send_query_message'));
@@ -33,8 +35,11 @@
33 35 add_action('admin_enqueue_scripts', array( $this, 'wpdbbkp_admin_newsletter_script'));
34 36 add_action('wp_ajax_wpdbbkp_send_query_message', array( $this, 'wpdbbkp_send_query_message'));
35 37 add_filter( 'plugin_action_links_' . plugin_basename( WP_BACKUP_PLUGIN_FILE ), array( $this, 'add_settings_plugin_action_wp' ), 10, 4 );
36 38 add_action( 'admin_notices', array($this, 'check_ziparchive_avalable_admin_notice' ));
39 + add_action( 'admin_notices', array($this, 'wpdbbkp_cloudbackup_notice' ) );
40 + add_action( 'wp_ajax_wpdbbkp_cloudbackup_dismiss_notice', array($this, 'wpdbbkp_cloudbackup_dismiss_notice' ) );
41 + add_action( 'admin_init', array($this, 'admin_backup_file_download' ));
37 42
38 43 }
39 44
40 45 /**
@@ -49,9 +54,8 @@
49 54 /**
50 55 * Backup Menu.
51 56 */
52 57 public function admin_menu() {
53 - //$page = add_management_page( 'WP-DB Backup', 'WP-DB Backup ', 'manage_options', 'wp-database-backup', array( $this, 'wp_db_backup_settings_page' ));
54 58 add_menu_page(
55 59 'Backups',
56 60 'Backups',
57 61 'manage_options',
@@ -59,18 +63,57 @@
59 63 array( $this, 'wp_db_backup_settings_page' ),
60 64 'dashicons-database-view',
61 65 99
62 66 );
63 - }
64 67
65 - /**
66 - * Start Fixed Vulnerability 22-06-2016 for prevent direct download.
67 - */
68 - public function wp_db_cookie_expiration() {
69 - setcookie( 'can_download', 0, time() - 300, COOKIEPATH, COOKIE_DOMAIN );
70 - if ( SITECOOKIEPATH !== COOKIEPATH ) {
71 - setcookie( 'can_download', 0, time() - 300, SITECOOKIEPATH, COOKIE_DOMAIN );
72 - }
68 + add_submenu_page(
69 + 'wp-database-backup',
70 + 'Auto Scheduler',
71 + 'Auto Scheduler',
72 + 'manage_options',
73 + 'wp-database-backup#tab_db_schedul',
74 + array($this, 'wp_db_backup_settings_page' ));
75 +
76 + add_submenu_page(
77 + 'wp-database-backup',
78 + 'Save Backups to',
79 + 'Save Backups to',
80 + 'manage_options',
81 + 'wp-database-backup#tab_db_destination',
82 + array($this, 'wp_db_backup_settings_page' ));
83 +
84 + add_submenu_page(
85 + 'wp-database-backup',
86 + 'Cloud Backup',
87 + 'Cloud Backup',
88 + 'manage_options',
89 + 'wp-database-backup#tab_db_remotebackups',
90 + array($this, 'wp_db_backup_settings_page' ));
91 +
92 + add_submenu_page(
93 + 'wp-database-backup',
94 + 'Settings',
95 + 'Settings',
96 + 'manage_options',
97 + 'wp-database-backup#tab_db_setting',
98 + array($this, 'wp_db_backup_settings_page' ));
99 + add_submenu_page(
100 + 'wp-database-backup',
101 + 'Search and Replace',
102 + 'Search and Replace',
103 + 'manage_options',
104 + 'wp-database-backup#searchreplace',
105 + array($this, 'wp_db_backup_settings_page' ));
106 +
107 +
108 + add_submenu_page(
109 + 'wp-database-backup',
110 + 'Help & Support',
111 + 'Help & Support',
112 + 'manage_options',
113 + 'wp-database-backup#tab_db_help',
114 + array($this, 'wp_db_backup_settings_page' ));
115 +
73 116 }
74 117
75 118 /**
76 119 * If Checked then it will remove local backup after uploading to destination.
@@ -80,9 +123,9 @@
80 123 public function wp_db_backup_completed_local( &$args ) {
81 124 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
82 125 if ( 1 === $wp_db_remove_local_backup ) {
83 126 if ( file_exists( $args[1] ) ) {
84 - unlink( $args[1] );// File path.
127 + wp_delete_file( $args[1] );// File path.
85 128 }
86 129 }
87 130 }
88 131
@@ -101,35 +144,20 @@
101 144
102 145 // Start Fixed Vulnerability 04-08-2016 for data save in options.
103 146 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] ) {
104 147 if ( ! empty( $_POST ) && ! ( isset( $_POST['option_page'] ) && 'wp_db_backup_options' === $_POST['option_page'] ) ) {
105 - if ( false === isset( $_REQUEST['_wpnonce'] ) || false === wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'wp-database-backup' ) ) {
106 - die( 'WPDB :: Invalid Access' );
148 + if ( false === isset( $_REQUEST['_wpnonce'] ) || false === wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ) , 'wp-database-backup' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- using as nonce
149 + wp_die( esc_html__('WPDB :: Invalid Access', 'wpdbbkp' ) );
107 150 }
108 151 }
109 -
110 - // End Fixed Vulnerability 04-08-2016 for data save in options.
111 - if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && current_user_can( 'manage_options' ) ) {
112 - setcookie( 'can_download', 1, 0, COOKIEPATH, COOKIE_DOMAIN );
113 - if ( SITECOOKIEPATH !== COOKIEPATH ) {
114 - setcookie( 'can_download', 1, 0, SITECOOKIEPATH, COOKIE_DOMAIN );
115 - }
116 - } else {
117 - setcookie( 'can_download', 0, time() - 300, COOKIEPATH, COOKIE_DOMAIN );
118 - if ( SITECOOKIEPATH !== COOKIEPATH ) {
119 - setcookie( 'can_download', 0, time() - 300, SITECOOKIEPATH, COOKIE_DOMAIN );
120 - }
121 - }
122 152 // End Fixed Vulnerability 22-06-2016 for prevent direct download.
123 153 if ( is_admin() && current_user_can( 'manage_options' ) ) {
124 - if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'wp-database-backup' ) ) {
154 + if ( isset( $_REQUEST['_wpnonce'] ) && wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ) , 'wp-database-backup' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- using as nonce
125 155 if ( isset( $_POST['wpsetting_search'] ) ) {
126 156 if ( isset( $_POST['wp_db_backup_search_text'] ) ) {
127 - update_option( 'wp_db_backup_search_text', sanitize_text_field( wp_unslash( $_POST['wp_db_backup_search_text'] ) ) );
157 + update_option( 'wp_db_backup_search_text', sanitize_text_field( wp_unslash( $_POST['wp_db_backup_search_text'] ) ), false );
128 158 }
129 - if ( isset( $_POST['wp_db_backup_replace_text'] ) ) {
130 - update_option( 'wp_db_backup_replace_text', sanitize_text_field( wp_unslash( $_POST['wp_db_backup_replace_text'] ) ) );
131 - }
159 +
132 160 $nonce = wp_create_nonce( 'wp-database-backup' );
133 161 wp_safe_redirect( esc_url( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=save&tab=searchreplace&_wpnonce=' . $nonce ) );
134 162 }
135 163
@@ -134,42 +162,41 @@
134 162 }
135 163
136 164 if ( isset( $_POST['wpsetting'] ) ) {
137 165 if ( isset( $_POST['wp_local_db_backup_count'] ) ) {
138 - update_option( 'wp_local_db_backup_count', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wp_local_db_backup_count'] ) ) ) );
166 + update_option( 'wp_local_db_backup_count', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wp_local_db_backup_count'] ) ) ) , false);
139 167 }
140 168
141 169 if ( isset( $_POST['wp_db_log'] ) ) {
142 - update_option( 'wp_db_log', 1 );
170 + update_option( 'wp_db_log', 1 , false);
143 171 } else {
144 - update_option( 'wp_db_log', 0 );
172 + update_option( 'wp_db_log', 0 , false);
145 173 }
174 + if ( isset( $_POST['wp_db_remove_on_uninstall'] ) ) {
175 + update_option( 'wp_db_remove_on_uninstall', 1 , false);
176 + } else {
177 + update_option( 'wp_db_remove_on_uninstall', 0 , false);
178 + }
146 179 if ( isset( $_POST['wp_db_remove_local_backup'] ) ) {
147 - update_option( 'wp_db_remove_local_backup', 1 );
180 + update_option( 'wp_db_remove_local_backup', 1 , false);
148 181 } else {
149 - update_option( 'wp_db_remove_local_backup', 0 );
182 + update_option( 'wp_db_remove_local_backup', 0 , false);
150 183 }
151 -
152 - if ( isset( $_POST['wp_db_backup_enable_auto_upgrade'] ) ) {
153 - update_option( 'wp_db_backup_enable_auto_upgrade', 1 );
184 + if ( isset( $_POST['wp_db_save_settings_in_backup'] ) ) {
185 + update_option( 'wp_db_save_settings_in_backup', 1 , false);
154 186 } else {
155 - update_option( 'wp_db_backup_enable_auto_upgrade', 0 );
187 + update_option( 'wp_db_save_settings_in_backup', 0 , false);
156 188 }
157 -
158 - if ( isset( $_POST['wp_db_backup_enable_htaccess'] ) ) {
159 - update_option( 'wp_db_backup_enable_htaccess', 1 );
189 + if ( isset( $_POST['wp_db_backup_enable_auto_upgrade'] ) ) {
190 + update_option( 'wp_db_backup_enable_auto_upgrade', 1 , false);
160 191 } else {
161 - update_option( 'wp_db_backup_enable_htaccess', 0 );
162 - $path_info = wp_upload_dir();
163 - if ( file_exists( $path_info['basedir'] . '/db-backup/.htaccess' ) ) {
164 - unlink( $path_info['basedir'] . '/db-backup/.htaccess' );
165 - }
192 + update_option( 'wp_db_backup_enable_auto_upgrade', 0 , false);
166 193 }
167 194
168 195 if ( isset( $_POST['wp_db_exclude_table'] ) ) {
169 - update_option( 'wp_db_exclude_table', $this->recursive_sanitize_text_field( wp_unslash( $_POST['wp_db_exclude_table'] ) ) ); // phpcs:ignore
196 + update_option( 'wp_db_exclude_table', $this->recursive_sanitize_text_field( wp_unslash( $_POST['wp_db_exclude_table'] ) ) , false); // phpcs:ignore
170 197 } else {
171 - update_option( 'wp_db_exclude_table', '' );
198 + update_option( 'wp_db_exclude_table', '', false );
172 199 }
173 200 $nonce = wp_create_nonce( 'wp-database-backup' );
174 201 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=save&_wpnonce=' . $nonce );
175 202 }
@@ -178,32 +205,89 @@
178 205 update_option( 'wp_db_local_backup_path', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wp_db_local_backup_path'] ) ) ) );
179 206 }
180 207
181 208 if ( isset( $_POST['wp_db_backup_email_id'] ) ) {
182 - update_option( 'wp_db_backup_email_id', wp_db_filter_data( sanitize_email( wp_unslash( $_POST['wp_db_backup_email_id'] ) ) ) );
209 + update_option( 'wp_db_backup_email_id', wp_db_filter_data( sanitize_email( wp_unslash( $_POST['wp_db_backup_email_id'] ) ) ) , false);
183 210 }
184 211
185 212 if ( isset( $_POST['wp_db_backup_email_attachment'] ) ) {
186 - $email_attachment = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_email_attachment'] ) );
213 + $email_attachment = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_email_attachment'] ) , false);
187 214 update_option( 'wp_db_backup_email_attachment', $email_attachment );
188 215 }
189 216 if ( isset( $_POST['local_backup_submit'] ) && 'Save Settings' === $_POST['local_backup_submit'] ) {
190 217 if ( true === isset( $_POST['wp_db_local_backup'] ) ) {
191 - update_option( 'wp_db_local_backup', 1 );
218 + update_option( 'wp_db_local_backup', 1 , false);
192 219 } else {
193 - update_option( 'wp_db_local_backup', 0 );
220 + update_option( 'wp_db_local_backup', 0 , false);
194 221 }
195 222 }
196 223
197 - if ( isset( $_POST['email_notification_submit'] ) && 'Save Settings' === $_POST['email_notification_submit'] ) {
198 - if ( isset( $_POST['wp_db_backup_destination_Email'] ) ) {
199 - update_option( 'wp_db_backup_destination_Email', 1 );
224 + if ( isset( $_POST['wp_db_backup_options'] ) ) {
225 + $option_to_save = [];
226 + if ( isset( $_POST['wp_db_backup_options']['enable_autobackups'] ) ) {
227 + $option_to_save['enable_autobackups'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['enable_autobackups'] ) );
228 + }
229 + if ( isset( $_POST['wp_db_backup_options']['autobackup_type'] ) ) {
230 + $option_to_save['autobackup_type'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_type'] ) );
231 + }
232 + if ( isset( $_POST['wp_db_backup_options']['autobackup_frequency'] ) ) {
233 + $option_to_save['autobackup_frequency'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_frequency'] ) );
234 + }
235 + if ( isset( $_POST['wp_db_backup_options']['autobackup_full_days'] ) ) {
236 + $option_to_save['autobackup_full_days'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_days'] ) );
237 + }
238 + if ( isset( $_POST['wp_db_backup_options']['autobackup_full_time'] ) ) {
239 + $option_to_save['autobackup_full_time'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_time'] ) );
240 + }
241 + if ( isset( $_POST['wp_db_backup_options']['autobackup_full_date'] ) ) {
242 + $option_to_save['autobackup_full_date'] = sanitize_text_field( wp_unslash( $_POST['wp_db_backup_options']['autobackup_full_date'] ) );
243 + }
244 + if(!empty($option_to_save)) {
245 + if(update_option( 'wp_db_backup_options', $option_to_save, false)){
246 + wp_clear_scheduled_hook( 'wpdbbkp_db_backup_event' );
247 + wp_clear_scheduled_hook( 'wpdbkup_event_fullbackup' );
248 + }
249 + }
250 +
251 + }
252 +
253 +
254 + if ( isset( $_POST['featureSubmit'] ) && 'Save Settings' === $_POST['featureSubmit'] ) {
255 + if ( isset( $_POST['enable_anonymization'] ) ) {
256 + update_option( 'bkpforwp_enable_anonymization', 1 );
200 257 } else {
201 - update_option( 'wp_db_backup_destination_Email', 0 );
258 + update_option( 'bkpforwp_enable_anonymization', 0 );
202 259 }
203 - }
260 +
261 + if ( isset( $_POST['enable_backup_encryption'] ) ) {
262 + update_option( 'bkpforwp_enable_backup_encryption', 1 );
263 + } else {
264 + update_option( 'bkpforwp_enable_backup_encryption', 0 );
265 + }
266 + if ( isset( $_POST['enable_exact_backup_time'] ) ) {
267 + update_option( 'bkpforwp_enable_exact_backup_time', 1 );
268 + } else {
269 + update_option( 'bkpforwp_enable_exact_backup_time', 0 );
270 + }
271 +
272 + if ( isset( $_POST['anonymization_type'] ) ) {
273 + update_option( 'bkpforwp_anonymization_type', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['anonymization_type'] ) ) ) );
274 +
275 + }
276 +
277 + if ( isset( $_POST['anonymization_pass'] )) {
278 + update_option( 'bkpforwp_anonymization_pass', wp_db_filter_data( sanitize_text_field( wp_unslash($_POST['anonymization_pass'] ) ) ) );
279 +
280 + }
281 +
282 + if ( isset( $_POST['backup_encryption_pass'] )) {
283 + update_option( 'bkpforwp_backup_encryption_pass', wp_db_filter_data( sanitize_text_field( wp_unslash($_POST['backup_encryption_pass'] ) ) ) );
284 +
285 + }
286 + }
287 +
204 288 }
205 - $wp_db_backup_destination_email = get_option( 'wp_db_backup_destination_Email' );
289 + $wp_db_backup_destination_email = get_option( 'wp_db_backup_destination_Email' , false);
206 290
207 291 if ( isset( $_GET['page'] ) && 'wp-database-backup' === $_GET['page'] && isset( $_GET['action'] ) && 'unlink' === $_GET['action'] ) {
208 292 // Specify the target directory and add forward slash.
209 293 $dir = plugin_dir_path( __FILE__ ) . 'Destination/Dropbox/tokens/';
@@ -214,9 +298,9 @@
214 298 $file = readdir( $dir_handle );
215 299 while ( $file ) {
216 300 // If $file is NOT a directory remove it.
217 301 if ( ! is_dir( $file ) ) {
218 - unlink( $dir . $file );
302 + wp_delete_file( $dir . $file );
219 303 }
220 304 }
221 305 // Close the directory.
222 306 closedir( $dir_handle );
@@ -235,33 +319,86 @@
235 319 $index = (int) $_GET['index'];
236 320 $options = get_option( 'wp_db_backup_backups' );
237 321 $newoptions = array();
238 322 $count = 0;
239 - foreach ( $options as $option ) {
240 - if ( $count !== $index ) {
241 - $newoptions[] = $option;
323 + if(!empty($options) && is_array($options)){
324 + foreach ( $options as $option ) {
325 + if ( $count !== $index ) {
326 + $newoptions[] = $option;
327 + }
328 + $count++;
242 329 }
243 - $count++;
244 330 }
245 - if ( file_exists( $options[ $index ]['dir'] ) ) {
246 - unlink( $options[ $index ]['dir'] );
331 +
332 + $upload_dir = wp_upload_dir();
333 + $actual_working_directory = getcwd();
334 + $file_directory = $upload_dir['basedir'].'/db-backup/';
335 + /*
336 + Fix for when you try to delete a file thats in a folder
337 + higher in the hierarchy to your working directory */
338 + chdir($file_directory);
339 + if ( isset($options[ $index ]['filename']) && file_exists( $options[ $index ]['filename'] ) ) {
340 + wp_delete_file( $options[ $index ]['filename'] );
247 341 }
248 - $file_sql = explode( '.', $options[ $index ]['dir'] );
249 - if ( file_exists( $file_sql[0] . '.sql' ) ) {
250 - unlink( $file_sql[0] . '.sql' );
342 + if(isset($options[ $index ]['filename'])){
343 + $file_sql = explode( '.', $options[ $index ]['filename'] );
344 + if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) {
345 + wp_delete_file( $file_sql[0] . '.sql' );
346 + }
251 347 }
252 - update_option( 'wp_db_backup_backups', $newoptions );
348 +
349 + chdir($actual_working_directory);
350 + $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
351 + update_option( 'wp_db_backup_backups', $newoptions , false);
253 352 $nonce = wp_create_nonce( 'wp-database-backup' );
254 353 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=delete&_wpnonce=' . $nonce );
354 + exit;
355 +
255 356 }
256 357 break;
358 + case 'removeallbackup':
359 +
360 + $upload_dir = wp_upload_dir();
361 + $actual_working_directory = getcwd();
362 + $file_directory = $upload_dir['basedir'];
363 + global $wpdb;
364 + /*
365 + Fix for when you try to delete a file thats in a folder
366 + higher in the hierarchy to your working directory
367 + */
368 + chdir($file_directory);
369 + $files = glob($file_directory.'/db-backup'.'/*');
370 +
371 + // Deleting all the files in the list
372 + if(!empty($files)){
373 + foreach($files as $file) {
374 + if(is_file($file)){
375 + wp_delete_file($file);
376 + }
377 + }
378 + }
379 + chdir($actual_working_directory);
380 + update_option( 'wp_db_backup_backups', array() , false);
381 + $nonce = wp_create_nonce( 'wp-database-backup' );
382 + $table_name = $wpdb->prefix . 'wpdbbkp_processed_files';
383 + $wpdb->query( "TRUNCATE TABLE $table_name" ); // phpcs:ignore
384 + wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=deleteall&_wpnonce=' . $nonce );
385 + exit;
386 +
387 +
388 + break;
257 389 case 'clear_temp_db_backup_file':
258 390 $options = get_option( 'wp_db_backup_backups' );
259 391 $newoptions = array();
260 392 $backup_check_list = array( '.htaccess', 'index.php' );
261 393 $delete_message = 'WPDB : Deleted Files:';
262 - foreach ( $options as $option ) {
263 - $backup_check_list[] = $option['filename'];
394 + if(!empty($options) && is_array($options)){
395 + foreach ( $options as $option ) {
396 + if(!is_array($option)){
397 + continue;
398 + }
399 + $backup_check_list[] = $option['filename'];
400 + }
264 401 }
265 402 $path_info = wp_upload_dir();
266 403 $wp_db_backup_path = $path_info['basedir'] . '/db-backup';
267 404
@@ -271,9 +408,9 @@
271 408 if ( $dh ) {
272 409 while ( false !== ($file = readdir( $dh )) ) {
273 410 if ( ! ( in_array( $file, $backup_check_list, true ) ) ) {
274 411 if ( file_exists( $wp_db_backup_path . '/' . $file ) ) {
275 - unlink( $wp_db_backup_path . '/' . $file );
412 + wp_delete_file( $wp_db_backup_path . '/' . $file );
276 413 }
277 414 $delete_message .= ' ' . $file;
278 415 }
279 416 }
@@ -280,26 +417,43 @@
280 417 closedir( $dh );
281 418 }
282 419 }
283 420 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=clear_temp_db_backup_file&_wpnonce=' . $nonce );
421 + exit;
284 422 break;
285 423 case 'restorebackup':
286 - $index = (int) $_GET['index'];
424 + $index = isset($_GET['index'])?(int) $_GET['index']:0;
287 425 $options = get_option( 'wp_db_backup_backups' );
426 + $restore_limit = get_option( 'wp_db_restore_limit');
288 427 $newoptions = array();
289 428 $count = 0;
290 - foreach ( $options as $option ) {
291 - if ( $count !== $index ) {
292 - $newoptions[] = $option;
429 + if(!empty($options) && is_array($options)){
430 + foreach ( $options as $option ) {
431 + if ( $count !== $index ) {
432 + $newoptions[] = $option;
433 + }
434 + $count++;
293 435 }
294 - $count++;
295 436 }
437 + if ( isset( $options[ $index ]['restore_limit'] ) && $options[ $index ]['restore_limit']==1) {
438 + include_once ABSPATH . 'wp-admin/includes/plugin.php';
439 + if ( !is_plugin_active( 'wp-database-backup-pro/wp-database-backup-pro.php' ) ) {
440 + wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore_limit&_wpnonce=' . $nonce );
441 + }
442 + }
443 + if(!empty($options[ $index ]['restore_limit'])){
444 + $options[ $index ]['restore_limit']=1;
445 + }
446 +
296 447 if ( isset( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
297 448 $database_file = ( $options[ $index ]['sqlfile'] );
298 449 } else {
299 - $database_file = ( $options[ $index ]['dir'] );
300 - $file_sql = explode( '.', $options[ $index ]['dir'] );
301 - $database_file = ( $file_sql[0] . '.sql' );
450 + $database_file = isset($options[ $index ]['dir']) ? $options[ $index ]['dir'] : '';
451 + $file_sql = explode( '.', $database_file );
452 + if(isset($file_sql[0])){
453 + $database_file = ( $file_sql[0] . '.sql' );
454 + }
455 +
302 456 }
303 457 $database_name = $this->wp_backup_get_config_db_name();
304 458 $database_user = $this->wp_backup_get_config_data( 'DB_USER' );
305 459 $datadase_password = $this->wp_backup_get_config_data( 'DB_PASSWORD' );
@@ -320,93 +474,117 @@
320 474 $archive = new PclZip( $database_zip_file );
321 475 $dir = $path_info['basedir'] . '/db-backup/';
322 476
323 477 if ( ! $archive->extract( PCLZIP_OPT_PATH, $dir ) ) {
324 - wp_die( 'Unable to extract zip file. Please check that zlib php extension is enabled.', 'ZIP Error' );
478 + 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') );
325 479 }
326 480 }
327 481
328 482 // End for extract zip file V.3.3.0.
329 - set_time_limit( 0 );
330 - if ( '' !== ( trim( (string) $database_name ) ) && '' !== ( trim( (string) $database_user ) ) && '' !== ( trim( (string) $database_host ) ) ) {
331 - $conn = mysqli_connect( (string) $database_host, (string) $database_user, (string) $datadase_password ); // phpcs:ignore
332 - if ( $conn ) {
333 - // Start Select the database.
334 - if ( ! mysqli_select_db( $conn, (string) $database_name) ) { // phpcs:ignore
335 - $sql = 'CREATE DATABASE IF NOT EXISTS `' . (string) $database_name . '`';
336 - mysqli_query($conn, $sql); // phpcs:ignore
337 - mysqli_select_db($conn, (string) $database_name ); // phpcs:ignore
483 + set_time_limit( 0 ); // phpcs:ignore -- needed for long running process
484 + ignore_user_abort(true);
485 + if ('' !== trim($database_name) && '' !== trim($database_user) && '' !== trim($database_host)) {
486 + $wpdb->db_connect();
487 + $wpdb->select($database_name);
488 +
489 + //phpcs:ignore -- Check if database exists
490 + $db_exists = $wpdb->get_var($wpdb->prepare(
491 + "SELECT SCHEMA_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = %s",
492 + $database_name
493 + ));
494 +
495 + if (!$db_exists) {
496 + //phpcs:ignore -- Create DB if it doesn't exist
497 + $wpdb->query($wpdb->prepare("CREATE DATABASE IF NOT EXISTS `%s`", $database_name));
498 + $wpdb->select($database_name);
499 + }
500 + //phpcs:ignore -- Show tables from database
501 + $tables = $wpdb->get_col($wpdb->prepare("SHOW TABLES FROM `%s`", $database_name));
502 +
503 +
504 + if (!empty($tables)) {
505 + foreach ($tables as $table_name) {
506 + //phpcs:ignore -- delete tables before restore
507 + $wpdb->query($wpdb->prepare("DROP TABLE IF EXISTS `%s`", $table_name));
338 508 }
339 - /* END: Select the Database */
340 -
341 - /* BEGIN: Remove All Tables from the Database */
342 - $found_tables = null;
343 - $result = mysqli_query( $conn, 'SHOW TABLES FROM `' . (string) $database_name . '`' ); // phpcs:ignore
344 -
345 - if ( $result ) {
346 - // $row = mysqli_fetch_row( $result ); // phpcs:ignore
347 - while ($row = mysqli_fetch_row($result)) {
348 - $found_tables[] = $row[0];
509 + }
510 +
511 + // Restore database content
512 + if (file_exists($database_file)) {
513 + if ( ! function_exists( 'WP_Filesystem' ) ) {
514 + require_once ABSPATH . '/wp-admin/includes/file.php';
349 515 }
516 +
517 + WP_Filesystem();
518 + if ( $wp_filesystem ) {
519 + $sql_file = $wp_filesystem->get_contents( $database_file );
520 + if ( $sql_file !== false ) {
521 + $sql_queries = explode(";\n", $sql_file);
522 + //phpcs:ignore -- Set sql_mode to empty
523 + $wpdb->query("SET sql_mode = ''");
524 +
525 + foreach ($sql_queries as $query) {
526 + $query = apply_filters('wpdbbkp_sql_query_restore', $query);
527 + if (!empty(trim($query))) {
350 528
351 - if ( count( $found_tables ) > 0 ) {
352 - foreach ( $found_tables as $table_name ) {
353 - mysqli_query( $conn, "DROP TABLE " . (string) $database_name . ".".$table_name ); // phpcs:ignore
354 - }
355 - }
356 - }
357 -
358 - /* END: Remove All Tables from the Database */
359 -
360 - /* BEGIN: Restore Database Content */
361 - if ( isset( $database_file ) ) {
362 - $database_file = $database_file;
363 - if ( file_exists( $database_file ) ) {
364 - $sql_file = file_get_contents( $database_file, true );
365 -
366 - $sql_queries = explode( ";\n", $sql_file );
367 - $sql_queries_count = count( $sql_queries );
368 -
369 - mysqli_query($conn, "SET sql_mode = ''");
370 -
371 - for ( $i = 0; $i < $sql_queries_count; $i++ ) {
372 - mysqli_query($conn, $sql_queries[ $i ] ); // phpcs:ignore
373 - }
374 - }
375 - }
529 + /* Since $query is a dynqmic sql query from the backup file, we can't use $wpdb->prepare
530 + * as we don't know the number / types of arguments in the query. So, we are using $wpdb->query
531 + * directly to execute the query.*/
532 + //phpcs:ignore
533 + $wpdb->query($query);
534 + }
535 + }
536 +
537 + }
538 + }
376 539 }
377 540 }
378 541
379 542 if ( isset( $options[ $index ]['sqlfile'] ) && file_exists( $options[ $index ]['sqlfile'] ) ) { // Added for extract zip file V.3.3.0.
380 543 if ( file_exists( $options[ $index ]['sqlfile'] ) ) {
381 - unlink( $options[ $index ]['sqlfile'] );
544 + wp_delete_file( $options[ $index ]['sqlfile'] );
382 545 }
383 546 } else {
384 - $database_file = ( $options[ $index ]['dir'] );
385 - $file_sql = explode( '.', $options[ $index ]['dir'] );
386 - $database_file = ( $file_sql[0] . '.sql' );
387 - if ( file_exists( $database_file ) ) {
388 - unlink( $database_file );
547 + $database_file = isset($options[ $index ]['dir'] )?$options[ $index ]['dir']:'';
548 + if(!empty($database_file)){
549 + $file_sql = explode( '.', $database_file );
550 + if(isset($file_sql[0])){
551 + $database_file = ( $file_sql[0] . '.sql' );
552 + if ( file_exists( $database_file ) ) {
553 + wp_delete_file( $database_file );
554 + }
555 +
556 + }
557 +
389 558 }
559 +
390 560 }
391 561 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
562 + exit;
392 563 break;
393 564
394 565 case 'wpdbbkrestorefullbackup':
395 566 $index = (int) $_GET['index'];
396 - require_once( 'class-restore.php' );
397 - $restore = new Wpbp_Restore();
567 + require_once( 'class-wpdbbkp-restore.php' );
568 + $restore = new Wpdbbkp_Restore();
398 569 $restore->start($index);
399 570 if (get_option('wp_db_log') == 1) {
400 571 $options = get_option('wp_db_backup_backups');
401 572 $path_info = wp_upload_dir();
402 - $logFileName = explode(".", $options[$index]['filename']);
403 - $logfile = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $logFileName[0] . '.txt';
404 - $message = "\n\n Restore Backup at " . date("Y-m-d h:i:sa");
405 - $this->write_log($logfile, $message);
573 + if(isset($options[$index]['filename'])){
574 + $logFileName = explode(".", $options[$index]['filename']);
575 + if(isset($logFileName[0])){
576 + $logfile = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/' . $logFileName[0] . '.txt';
577 + $message = "\n\n Restore Backup at " . gmdate("Y-m-d h:i:sa");
578 + $this->write_log($logfile, $message);
579 + }
580 +
581 + }
582 +
406 583 }
407 584 $nonce = wp_create_nonce( 'wp-database-backup' );
408 585 wp_safe_redirect( site_url() . '/wp-admin/admin.php?page=wp-database-backup&notification=restore&_wpnonce=' . $nonce );
586 + exit;
409 587 break;
410 588
411 589 /* END: Restore Database Content */
412 590 }
@@ -433,20 +611,28 @@
433 611 /**
434 612 * Setting page.
435 613 */
436 614 public function wp_db_backup_settings_page() {
615 + global $wp_filesystem;
616 + if(!function_exists('WP_Filesystem')){
617 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
618 + }
619 + WP_Filesystem();
620 +
437 621 $options = get_option( 'wp_db_backup_backups' );
438 - $settings = get_option( 'wp_db_backup_options' ); ?>
622 + $options = wpdbbkp_filter_unique_filenames( $options );
623 + $settings = get_option( 'wp_db_backup_options' );
624 + $wp_db_log = get_option( 'wp_db_log' );
625 + $incremental_backup = get_option( 'wp_db_incremental_backup' ,false); ?>
439 626 <div class="bootstrap-wrapper">
440 627 <?php
441 - include_once 'admin-header-notification.php';
442 628 $wp_db_local_backup_path = get_option( 'wp_db_local_backup_path' );
443 629 if ( false === empty( $wp_db_local_backup_path ) && false === file_exists( $wp_db_local_backup_path ) ) {
444 630 echo '<div class="alert alert-warning alert-dismissible fade in" role="alert">
445 631 <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
446 632 <a href="#db_destination" data-toggle="tab">';
447 - esc_attr_e( 'Invalid Local Backup Path : ', 'wp-database-backup' );
448 - echo esc_attr( $wp_db_local_backup_path );
633 + esc_html_e( 'Invalid Local Backup Path : ', 'wpdbbkp' );
634 + echo esc_html( $wp_db_local_backup_path );
449 635 echo '</a></div>';
450 636 }
451 637
452 638 $upload_dir = wp_upload_dir();
@@ -453,9 +639,9 @@
453 639 $dir = $upload_dir['basedir'] . '/db-backup';
454 640 if ( ! is_dir( $dir ) ) {
455 641 $dir = $upload_dir['basedir'];
456 642 }
457 - if ( is_dir( $dir ) && ! is_writable( $dir ) ) {
643 + if ( is_dir( $dir ) && !$wp_filesystem->is_writable( $dir )) {
458 644 ?>
459 645 <div class="row">
460 646 <div class="col-xs-12 col-sm-12 col-md-12">
461 647 <div class="alert alert-danger alert-dismissible fade in" role="alert">
@@ -460,11 +646,11 @@
460 646 <div class="col-xs-12 col-sm-12 col-md-12">
461 647 <div class="alert alert-danger alert-dismissible fade in" role="alert">
462 648 <button type="button" class="close" data-dismiss="alert" aria-label="Close">
463 649 <span aria-hidden="true">×</span></button>
464 - <h4>WP Database Backup</h4>
465 - <p>Error: Permission denied, make sure you have write permission for <?php echo esc_attr( $dir ); ?>
466 - folder</p>
650 + <h4><?php esc_html_e( 'WP Database Backup', 'wpdbbkp' ); ?></h4>
651 + <p><?php esc_html_e( 'Error: Permission denied, make sure you have write permission for', 'wpdbbkp' ); ?> <?php echo esc_attr( $dir ); ?>
652 + <?php esc_html_e( 'folder', 'wpdbbkp' ); ?></p>
467 653 </div>
468 654 </button>
469 655 </div>
470 656 </div>
@@ -470,8 +656,26 @@
470 656 </div>
471 657 <?php
472 658 }
473 659 ?>
660 +
661 +
662 +
663 + <div id="wpdbbkpModal" class="modal">
664 + <div class="wpdbbkpmodal-content">
665 + <div class="wpdbbkp-modal-header">
666 + <span class="wpdbbkp-close">&times;</span>
667 + <h2><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>&nbsp;<span id="wpdbbkp-modal-header-title"></span></h2>
668 + </div>
669 + <div class="wpdbbkp-modal-body">
670 + <p id="wpdbbkp-modal-body-text"></p>
671 + </div>
672 + <div class="wpdbbkp-modal-footer">
673 + <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>
674 + </div>
675 + </div>
676 + </div>
677 +
474 678 <div class="panel panel-default">
475 679 <div class="panel-heading head-logo">
476 680 <a href="https://backupforwp.com/" target="blank"><img
477 681 src="<?php echo esc_attr( WPDB_PLUGIN_URL ); ?>/assets/images/wp-database-backup.png" width="230px"></a>
@@ -476,23 +680,24 @@
476 680 <a href="https://backupforwp.com/" target="blank"><img
477 681 src="<?php echo esc_attr( WPDB_PLUGIN_URL ); ?>/assets/images/wp-database-backup.png" width="230px"></a>
478 682 </div>
479 683 <div class="panel-body">
480 - <ul class="nav nav-tabs">
481 - <li class="active"><a href="#db_home" data-toggle="tab"><?php echo esc_html__('Database Backups', 'wpdbbkp') ?></a></li>
684 + <ul class="nav nav-tabs wbdbbkp_has_nav">
685 + <li class="active"><a href="#db_home" data-toggle="tab"><?php echo esc_html__('Backups', 'wpdbbkp') ?></a></li>
686 + <li><a href="#db_remotebackups" data-toggle="tab"><?php echo esc_html__('Cloud Backup', 'wpdbbkp') ?></a></li>
482 687 <li><a href="#db_schedul" data-toggle="tab"><?php echo esc_html__('Auto Scheduler', 'wpdbbkp') ?></a></li>
483 688 <li><a href="#db_destination" data-toggle="tab"><?php echo esc_html__('Save Backups to', 'wpdbbkp') ?></a></li>
484 689 <li><a href="#db_setting" data-toggle="tab"><?php echo esc_html__('Settings', 'wpdbbkp') ?></a></li>
485 - <li><a href="#searchreplace" data-toggle="tab"><?php echo esc_html__('Search and Replace', 'wpdbbkp') ?></a></li>
690 + <li><a href="#searchreplace" style="display:none" data-toggle="tab"><?php echo esc_html__('Search and Replace', 'wpdbbkp') ?></a></li>
691 + <li><a href="#db_features" data-toggle="tab"><?php echo esc_html__('Modules', 'wpdbbkp') ?></a></li>
692 + <li title="System Info"><a href="#db_info" data-toggle="tab"><?php echo esc_html__('Usage', 'wpdbbkp') ?></a></li>
486 693 <li><a href="#db_help" data-toggle="tab"><?php echo esc_html__('Help &amp; Support', 'wpdbbkp') ?></a></li>
487 - <li id="db_info_link" title="System Info"><a href="#db_info" data-toggle="tab"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a></li>
488 694
695 +
489 696 </ul>
490 697
491 698 <?php
492 - $loader_gif = esc_url( WPDB_PLUGIN_URL )."/assets/images/icon_loading.gif";
493 699 echo '<div class="tab-content">';
494 - echo '<div id="wpdb-backup-process" style="display:none"><div class="text-center"><img width="50" height="50" src="'.$loader_gif.'"><h5 class="text-success"><strong>Backup under process, it may take some time, please do not press back or refresh button</strong></h5></div></div>';
495 700 echo '<div class="tab-pane active" id="db_home">';
496 701
497 702 $nonce = wp_create_nonce( 'wp-database-backup' );
498 703 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
@@ -497,31 +702,28 @@
497 702 $nonce = wp_create_nonce( 'wp-database-backup' );
498 703 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
499 704 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
500 705 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
501 - echo '<a href="' . esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=createdbbackup&_wpnonce=' . esc_attr( $nonce ) . '" id="create_backup" class="btn btn-primary"> <span class="glyphicon glyphicon-plus-sign"></span> Create New Database Backup with Search/Replace</a>';
502 - echo '<p>Backup file will replace <b>' . esc_attr( $wp_db_backup_search_text ) . '</b> text with <b>' . esc_attr( $wp_db_backup_replace_text ) . '</b>. For Regular Database Backup without replace then Go to Dashboard=>Tool=>WP-DB Backup > Settings > Search and Replace - Set Blank Fields </p>';
706 + 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>';
707 + 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>';
503 708 } else {
504 - echo '<a href="' . esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=createdbbackup&_wpnonce=' . esc_attr( $nonce ) . '" id="create_backup" class="btn btn-primary"> <span class="glyphicon glyphicon-plus-sign"></span> Create New Database Backup</a>';
505 - echo '<a href="#" id="wpdbbkp-create-full-backup" class="btn btn-primary"> <span class="glyphicon glyphicon-plus-sign"></span> Create Full Backup</a>';
709 + 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>';
710 + 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>';
711 + 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>';
506 712 }
507 -
508 - ?>
713 + include_once 'admin-header-notification.php'; ?>
509 714
510 715 <?php
511 - if ( $options ) {
716 + if ( !empty($options) ) {
512 717
513 718 echo ' <script>
514 719 var $j = jQuery.noConflict();
515 720 $j(document).ready(function () {
516 - $j(".popoverid").popover();
517 - var table = $j("#example").DataTable({
721 +
722 + var table = $j("#wpdbbkp_table").DataTable({
518 723 order: [[0, "desc"]],
519 724 });
520 - $j("#create_backup").click(function() {
521 - $j("#backup_process").show();
522 - $j("#create_backup").attr("disabled", true);
523 - });
725 + $j(".popoverid").popover();
524 726 });
525 727
526 728 function excludetableall(){
527 729 var checkboxes = document.getElementsByClassName("wp_db_exclude_table");
@@ -532,19 +734,20 @@
532 734 $j(".wp_db_exclude_table").each(function() {
533 735 this.checked = checked;
534 736 });
535 737 }
536 -
537 738 </script>';
538 739 echo ' <div class="table-responsive">
539 - <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline" role="grid">
740 + <div id="wpdbbkp_dataTables" class="dataTables_wrapper form-inline" role="grid">
540 741
541 - <table class="table table-striped table-bordered table-hover display" id="example">
742 + <table class="table table-striped table-bordered table-hover display" id="wpdbbkp_table">
542 743 <thead>';
543 744 echo '<tr class="wpdb-header">';
544 - //echo '<th class="manage-column" scope="col" width="5%" style="text-align: center;">#</th>';
745 + echo '<th class="manage-column" scope="col" width="5%" style="text-align: center;">#</th>';
545 746 echo '<th class="manage-column" scope="col" width="25%">Date</th>';
546 - echo '<th class="manage-column" scope="col" width="5%">Log</th>';
747 + if($wp_db_log==1){
748 + echo '<th class="manage-column" scope="col" width="5%">Log</th>';
749 + }
547 750 echo '<th class="manage-column" scope="col" width="10%">Destination</th>';
548 751 echo '<th class="manage-column" scope="col" width="15%">Type</th>';
549 752 echo '<th class="manage-column" scope="col" width="10%">Backup File</th>';
550 753 echo '<th class="manage-column" scope="col" width="10%">Size</th>';
@@ -557,67 +760,95 @@
557 760 $destination_icon = array(
558 761 'Local' => 'glyphicon glyphicon-home',
559 762 'Local Path' => 'glyphicon glyphicon-folder-open',
560 763 'Email' => 'glyphicon glyphicon-envelope',
561 - 'FTP' => 'glyphicon glyphicon-folder-open',
764 + 'FTP' => 'glyphicon glyphicon-tasks',
765 + 'SFTP' => 'glyphicon glyphicon-tasks',
562 766 'S3' => 'glyphicon glyphicon-cloud-upload',
563 767 'Drive' => 'glyphicon glyphicon-hdd',
564 768 'DropBox' => 'glyphicon glyphicon-inbox',
769 + 'Backblaze' => 'glyphicon glyphicon-cloud-upload',
770 + 'CloudDrive' => 'glyphicon glyphicon-cloud-upload'
565 771 );
566 - foreach ( $options as $option ) {
567 - $str_class = ( 0 === (int) $option['size'] ) ? 'text-danger' : 'wpdb_download';
568 - echo '<tr class="' . ( ( 0 === ( $count % 2 ) ) ? esc_attr( $str_class ) . ' alternate' : esc_attr( $str_class ) ) . '">';
569 - //echo '<td style="text-align: center;">' . esc_attr( $count ) . '</td>';
570 - echo '<td><span style="display:none">' . esc_attr( gmdate( 'Y M jS h:i:s A', $option['date'] ) ) . '</span>' . esc_attr( gmdate( 'jS, F Y h:i:s A', $option['date'] ) ) . '</td>';
571 - echo '<td class="wpdb_log" align="center">';
572 - if (!empty($option['log'])) {
573 - // echo '<button id="popoverid" type="button" class="popoverid btn" data-toggle="popover" title="Log" data-content="' . wp_kses_post( $option['log'] ) . '"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span></button>';
574 - echo '<a href="' . $option['log'] . '" target="_blank" class="label label-warning" title="There might be partial backup. Please check Log File for verify backup.">';
575 - echo '<span class="glyphicon glyphicon-list-alt"></span>';
576 - echo '</a>';
577 - }else{
578 - echo '<span>-</span>';
579 - }
580 -
581 - echo '</td>';
582 - echo '<td>';
583 - if ( ! empty( $option['destination'] ) ) {
584 - $destination = ( explode( ',', $option['destination'] ) );
585 - foreach ( $destination as $dest ) {
586 - $key = trim( $dest );
587 - if ( ! empty( $dest ) && array_key_exists( $key, $destination_icon ) ) {
588 - echo '<span class="' . esc_attr( $destination_icon[ $key ] ) . '" title="' . esc_attr( $dest ) . '"></span> ';
772 + if(!empty($options) && is_array($options)){
773 + foreach ( $options as $option ) {
774 + if (!is_array($option)) {
775 + continue;
776 + }
777 +
778 + if (!empty($option['destination'])) {
779 + if (strpos($option['destination'], 'CloudDrive') !== false) {
780 + continue;
589 781 }
590 782 }
591 - }
592 - echo '</td>';
593 - if(isset($option['type']) && !empty($option['type'])){
594 - if($option['type'] == 'complete'){
595 - echo '<td>'.esc_html__('Full Backup', 'wpdbbkp').'</td>';
783 + $size = isset( $option['size'])? $option['size'] : 0;
784 + $str_class = ( 0 === (int) $size ) ? 'text-danger' : 'wpdb_download';
785 + echo '<tr class="' . ( ( 0 === ( $count % 2 ) ) ? esc_attr( $str_class ) . ' alternate' : esc_attr( $str_class ) ) . '">';
786 + echo '<td style="text-align: center;">' . esc_attr( $count ) . '</td>';
787 + $curr_date = new DateTime(gmdate( 'Y-m-d H:i:s', $option['date'] ));
788 + $curr_date->setTimezone(new DateTimeZone(wp_timezone_string()));
789 + 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>';
790 + echo '</td>';
791 + if($wp_db_log==1){
792 + echo '<td class="wpdb_log" align="center">';
793 + if (!empty($option['log'])) {
794 + if(isset($option['type']) && ($option['type'] == 'complete' || $option['type'] == 'database')){
795 + 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.">';
796 + echo '<span class="glyphicon glyphicon-list-alt"></span>';
797 + echo '</a>';
798 + }else{
799 + 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>';
800 + }
596 801 }
597 - }else{
598 - echo '<td>Database</td>';
599 - }
600 - echo '<td>';
601 - echo '<a class="btn btn-default" href="' . esc_url( $option['url'] ) . '" style="color: #21759B;border-color:#337ab7;">';
602 - echo '<span class="glyphicon glyphicon-download-alt"></span> Download</a></td>';
603 - echo '<td>' . esc_attr( $this->wp_db_backup_format_bytes( $option['size'] ) ) . '</td>';
604 - $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removebackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
605 - echo '<td><a title="Remove Database Backup" onclick="return confirm(\'Are you sure you want to delete database backup?\')" href="' . $remove_backup_href . '" class="btn btn-default"><span style="color:red" class="glyphicon glyphicon-trash"></span> Remove <a/> ';
606 - if ( isset( $option['search_replace'] ) && 1 === (int) $option['search_replace'] ) {
607 - echo '<span style="margin-left:15px" title="' . esc_html( $option['log'] ) . '" class="glyphicon glyphicon-search"></span>';
608 - } else {
609 - $restore_url_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=restorebackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
802 + echo '</td>';
803 + }
804 + echo '<td>';
805 + if ( ! empty( $option['destination'] ) ) {
806 + $destination = ( explode( ',', $option['destination'] ) );
807 + if(!empty($destination) && is_array($destination)){
808 + foreach ( $destination as $dest ) {
809 + $key = trim( $dest );
810 + if ( ! empty( $dest ) && array_key_exists( $key, $destination_icon ) ) {
811 + echo '<span class="' . esc_attr( $destination_icon[ $key ] ) . '" title="' . esc_attr( $dest ) . '"></span> ';
812 + }
813 + }
814 + }
815 +
816 + }
817 + echo '</td>';
610 818 if(isset($option['type']) && !empty($option['type'])){
611 819 if($option['type'] == 'complete'){
612 - $restore_url_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=wpdbbkrestorefullbackup&_wpnonce=' . esc_attr( $nonce ) . '&index=' . esc_attr( ( $count - 1 ) );
820 + echo '<td>'.esc_html__('Full Backup', 'wpdbbkp').'</td>';
613 821 }
822 + if($option['type'] == 'database'){
823 + echo '<td>'.esc_html__('Database', 'wpdbbkp').'</td>';
824 + }
825 + }else{
826 + echo '<td>Database</td>';
614 827 }
615 - echo '<a title="Restore Database Backup" onclick="return confirm(\'Are you sure you want to restore database backup?\')" href="' . $restore_url_href . '" class="btn btn-default"><span class="glyphicon glyphicon-refresh" style="color:blue"></span> Restore <a/>';
828 + echo '<td>';
829 + echo '<a class="btn btn-default" href="' . esc_url( admin_url('?wpdbbkp_download='.basename($option['url'])) ) . '" style="color: #21759B;border-color:#337ab7;">';
830 + echo '<span class="glyphicon glyphicon-download-alt"></span> Download</a></td>';
831 + echo '<td>' . esc_attr( $this->wp_db_backup_format_bytes( $option['size'] ) ) . '</td>';
832 + $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 ) );
833 + 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/> ';
834 + if ( isset( $option['search_replace'] ) && 1 === (int) $option['search_replace'] ) {
835 + echo '<span style="margin-left:15px" title="' . esc_html( $option['log'] ) . '" class="glyphicon glyphicon-search"></span>';
836 + } else {
837 + $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 ) );
838 + if(isset($option['type']) && !empty($option['type'])){
839 + if($option['type'] == 'complete'){
840 + $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 ) );
841 + }
842 +
843 + }
844 + 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/>';
845 + }
846 + echo '</td></tr>';
847 + $count++;
616 848 }
617 - echo '</td></tr>';
618 - $count++;
619 849 }
850 +
620 851 echo '</tbody>';
621 852
622 853 echo ' </table>
623 854 </div>
@@ -630,13 +861,10 @@
630 861 echo '</div>';
631 862
632 863 echo '<div class="tab-pane" id="db_schedul">';
633 864 echo '<div class="panel-group">';
634 - echo '<form method="post" action="options.php" name="wp_auto_commenter_form">';
865 + echo '<form method="post" action="" name="wp_auto_commenter_form">';
635 866 wp_nonce_field( 'wp-database-backup' );
636 - settings_fields( 'wp_db_backup_options' );
637 - do_settings_sections( 'wp-database-backup' );
638 -
639 867 $enable_autobackups = '0';
640 868 if ( isset( $settings['enable_autobackups'] ) ) {
641 869 $enable_autobackups = $settings['enable_autobackups'];
642 870 }
@@ -644,16 +872,34 @@
644 872 $autobackup_frequency = '0';
645 873 if ( isset( $settings['autobackup_frequency'] ) ) {
646 874 $autobackup_frequency = $settings['autobackup_frequency'];
647 875 }
876 + $full_autobackup_frequency = 'disabled';
877 + if ( isset( $settings['full_autobackup_frequency'] ) ) {
878 + $full_autobackup_frequency = $settings['full_autobackup_frequency'];
879 + }
880 + $autobackup_type = '';
881 + if ( isset( $settings['autobackup_type'] ) ) {
882 + $autobackup_type = $settings['autobackup_type'];
883 + }
648 884
649 - echo '<div class="row form-group"><label class="col-sm-2" for="enable_autobackups">Enable Auto Backups</label>';
650 - echo '<div class="col-sm-2"><input type="checkbox" id="enable_autobackups" name="wp_db_backup_options[enable_autobackups]" value="1" ' . checked( 1, $enable_autobackups, false ) . '/></div>';
885 + echo '<div class="row form-group"><label class="col-sm-3" for="enable_autobackups">Enable Auto Backups</label>';
886 + 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 ) . '/>';
887 + 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>';
651 888 echo '</div>';
652 - echo '<div class="row form-group"><label class="col-sm-2" for="wp_db_backup_options">Auto Database Backup Frequency</label>';
653 - echo '<div class="col-sm-2"><select id="wp_db_backup_options" class="form-control" name="wp_db_backup_options[autobackup_frequency]">';
654 - echo '<option value="hourly" ' . selected( 'hourly', $autobackup_frequency, false ) . '>Hourly</option>';
655 - echo '<option value="twicedaily" ' . selected( 'twicedaily', $autobackup_frequency, false ) . '>Twice Daily</option>';
889 + echo '</div>';
890 +
891 + 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>';
892 + echo '<div class="col-sm-9"><select id="autobackup_type" class="form-control" name="wp_db_backup_options[autobackup_type]">';
893 + echo '<option value="">Select Backup Type</option>';
894 + echo '<option value="full" ' . selected( 'full', $autobackup_type, false ) . '>Full(Files + DB)</option>';
895 + echo '<option value="files" ' . selected( 'files', $autobackup_type, false ) . '>Files Only</option>';
896 + echo '<option value="db" ' . selected( 'db', $autobackup_type, false ) . '>Database Only</option>';
897 + echo '</select>';
898 + echo '</div></div>';
899 +
900 + 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>';
901 + echo '<div class="col-sm-9"><select id="autobackup_frequency" class="form-control" name="wp_db_backup_options[autobackup_frequency]">';
656 902 echo '<option value="daily" ' . selected( 'daily', $autobackup_frequency, false ) . '>Daily</option>';
657 903 echo '<option value="weekly" ' . selected( 'weekly', $autobackup_frequency, false ) . '>Weekly</option>';
658 904 echo '<option value="monthly" ' . selected( 'monthly', $autobackup_frequency, false ) . '>Monthly</option>';
659 905 echo '</select>';
@@ -658,8 +904,13 @@
658 904 echo '<option value="monthly" ' . selected( 'monthly', $autobackup_frequency, false ) . '>Monthly</option>';
659 905 echo '</select>';
660 906 echo '</div></div>';
661 907
908 + 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>';
909 + 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>';
910 + 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>';
911 +
912 + do_action('wpdbbkp_database_backup_options');
662 913 echo '<p class="submit">';
663 914 echo '<input type="submit" name="Submit" class="btn btn-primary" value="Save Settings" />';
664 915 echo '</p>';
665 916 echo '</form>';
@@ -664,12 +915,203 @@
664 915 echo '</p>';
665 916 echo '</form>';
666 917 echo '</div>';
667 918 echo '</div>';
919 +
668 920
669 - echo '<div class="tab-pane" id="db_help">';
921 +
922 + do_action('wpdbbkp_pro_tab_content');
670 923
671 924 ?>
925 +
926 +<!-- Modal Structure -->
927 +<div class="modal" id="wpdbbkp_offer_modal" data-dismiss="modal" tabindex="-1" aria-labelledby="wpdbbkp_offer_modalLabel" aria-hidden="true">
928 + <div class="modal-dialog">
929 + <div class="modal-content">
930 + <div class="modal-body">
931 + <button type="button" id="offer_close" class="close" data-dismiss="modal" aria-label="Close">
932 + <span aria-hidden="true">&times;</span>
933 + </button>
934 + <h3 class="modal-title" id="wpdbbkp_offer_modalLabel"><img src="<?php echo esc_attr( WPDB_PLUGIN_URL ); /* phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage */ ?>/assets/images/wp-database-backup.png" width="230px"></h3>
935 + <p style="padding:0 50px;"><?php echo esc_html__('Cloud Backup offers a secure, reliable and affordable solution to backup your WP site to the cloud.','wpdbbkp');?></p>
936 + <div class="wpdbbkp_offer_container">
937 + <div class="wpdbbkp_server">
938 + <h4><?php echo esc_html__('Server Backup','wpdbbkp');?></h4>
939 + <p><?php echo esc_html__('Backup your site to server','wpdbbkp');?></p>
940 + <ul>
941 + <li>&#10004; <?php echo esc_html__('Easy to setup','wpdbbkp');?></li>
942 + <li>&#10004; <?php echo esc_html__('Takes storage on your server','wpdbbkp');?></li>
943 + <li>&#10004; <?php echo esc_html__('Availability subject to server','wpdbbkp');?></li>
944 + </ul>
945 + <h4><?php echo esc_html__('Free','wpdbbkp');?></h4>
946 + <button id="wpdbbkp_server_backup" class="btn btn-secondary"><?php echo esc_html__('Create a Backup on this Server','wpdbbkp');?></button>
947 + </div>
948 + <div class="wpdbbkp_remote">
949 + <h4><?php echo esc_html__('Cloud Backup','wpdbbkp');?></h4>
950 + <p><?php echo esc_html__('Backup your site in the cloud','wpdbbkp');?></p>
951 + <ul>
952 + <li>&#10004; <?php echo esc_html__('Secure and reliable','wpdbbkp');?></li>
953 + <li>&#10004; <?php echo esc_html__('Only pay for what you use','wpdbbkp');?></li>
954 + <li>&#10004; <?php echo esc_html__('High availability','wpdbbkp');?></li>
955 + </ul>
956 + <h4><?php echo esc_html__('$1 per 50GB','wpdbbkp');?> <small><?php echo esc_html__('per month','wpdbbkp');?></small></h4>
957 + <button id="wpdbbkp_remote_backup" class="btn btn-primary"><?php echo esc_html__('Create a Backup on Cloud Server','wpdbbkp');?></button>
958 + </div>
959 +
960 + </div>
961 + </div>
962 + </div>
963 + </div>
964 +</div>
965 +<div class="tab-pane" id="db_features">
966 +
967 + <div class="panel-group">
968 + <form method="post" action="" name="db_features_form">
969 + <?php wp_nonce_field('wp-database-backup');
970 + $enable_anonymization = get_option('bkpforwp_enable_anonymization',false);
971 + $anonymization_type = get_option('bkpforwp_anonymization_type',false);
972 + $enable_backup_encryption = get_option('bkpforwp_enable_backup_encryption',false);
973 + $anonymization_pass = get_option('bkpforwp_anonymization_pass','');
974 + $backup_encryption_pass = get_option('bkpforwp_encryption_pass','');
975 + $enable_exact_backup_time = get_option('bkpforwp_enable_exact_backup_time',false);
976 + ?>
977 + <div class="row form-group"><label class="col-sm-3" for="enable_anonymization"><?php esc_html_e('Data Anonymization','wpdbbkp'); ?></label>
978 + <div class="col-sm-9"><input type="checkbox" id="enable_anonymization"
979 + name="enable_anonymization" value="1" <?php checked($enable_anonymization,1,1); ?> />
980 +
981 + <div class="alert alert-default" role="alert">
982 + <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <?php esc_html_e('Data anonymization is protecting private or sensitive information by erasing or encrypting identifiers that connect an individual to stored data.','wpdbbkp'); ?><a href="https://backupforwp.com/" target="_blank">Learn More</a></div>
983 + </div>
984 + </div>
985 + <div class="row form-group" id="anonymization_type_div" style="display:none">
986 + <label class="col-sm-3" for="anonymization_type"><?php esc_html_e('Data Anonymization Type','wpdbbkp'); ?> </label>
987 + <div class="col-sm-9"><select id="anonymization_type" class="form-control"
988 + name="anonymization_type">
989 + <option value="masked_data" <?php selected('masked_data', $anonymization_type, true) ?>> <?php esc_html_e('Masked Data','wpdbbkp'); ?>
990 + </option>
991 + <option value="fake_data" <?php selected('fake_data', $anonymization_type, true) ?>> <?php esc_html_e('Fake Data','wpdbbkp'); ?>
992 + </option>
993 + <option value="encrypted_data" <?php selected('encrypted_data', $anonymization_type, true) ?>> <?php esc_html_e('Encrypted Data','wpdbbkp'); ?>
994 + </option>
995 + </select>
996 + <?php echo wp_kses_post('<table class="bkpforwp-infotable">
997 + <tr><th>Masked Data </th><td>Data is masked with * character and <strong class="bkpforwp-red">data can not be recovered</strong> while restore.</td></tr>
998 + <tr><th>Fake Data </th><td>Data is replaced with fake data and <strong class="bkpforwp-red">data can not be recovered</strong> while restore.</td></tr>
999 + <tr><th>Encrypted Data </th><td>Data is encrypted with a password and <strong class="bkpforwp-green">data can be recovered</strong> while restore by using the same password used to backup the data.You just have to add the encryption password in Data Anonymization setting before restoring backup.</td></tr>
1000 + </table>');?>
1001 +
1002 + </div>
1003 + </div>
1004 +
1005 + <div class="row form-group" id="anonymization_enc_ip" style="display:none">
1006 + <label class="col-sm-3" for="anonymization_pass"><?php esc_html_e('Encrypted Data','wpdbbkp'); ?> <?php esc_html_e('Anonymization Password','wpdbbkp'); ?></label>
1007 + <div class="col-sm-9">
1008 + <input type="password" name="anonymization_pass" id="anonymization_pass" class="form-control" value="<?php esc_attr($anonymization_pass);?>">
1009 + <div class="alert alert-default" role="alert">
1010 + <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span> <?php esc_html_e('Please enter the encryption password. If you lose this pass then you can not recover the encrypted data','wpdbbkp'); ?></div>
1011 + </div>
1012 +
1013 + </div>
1014 +
1015 + <div class="row form-group" style="display:none"><label class="col-sm-3" for="enable_backup_encryption"><?php esc_html_e('Backup File Encrpytion','wpdbbkp'); ?></label>
1016 + <div class="col-sm-9"><input type="checkbox" id="enable_backup_encryption"
1017 + name="enable_backup_encryption" value="1" <?php checked($enable_backup_encryption,1,1); ?> /></div>
1018 + </div>
1019 +
1020 + <div class="row form-group" id="encryption_pass_div" style="display:none">
1021 + <label class="col-sm-3" for="backup_encryption_pass"><?php esc_html_e('Backup Password','wpdbbkp'); ?></label>
1022 + <div class="col-sm-9">
1023 + <input type="password" name="backup_encryption_pass" id="backup_encryption_pass" class="form-control" value="<?php esc_attr($backup_encryption_pass);?>">
1024 + </div>
1025 + </div>
1026 +
1027 + <p class="submit">
1028 + <input type="submit" name="featureSubmit" class="btn btn-primary" value="Save Settings" />
1029 + </p>
1030 + </form>
1031 + </div>
1032 + </div>
1033 +<div class="tab-pane" id="db_remotebackups">
1034 +<?php
1035 +$update_msg = '';
1036 +if ( true === isset( $_POST['wpdb_cd_s3'] ) && 'Y' === $_POST['wpdb_cd_s3'] ) {
1037 + // Validate that the contents of the form request came from the current site and not somewhere else added 21-08-15 V.3.4.
1038 + if ( ! isset( $_POST['wpdbbackup_update_cd_setting'] ) ) {
1039 + wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') );
1040 + }
1041 + if ( ! wp_verify_nonce( wp_unslash( $_POST['wpdbbackup_update_cd_setting'] ) , 'wpdbbackup-update-cd-setting' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1042 + wp_die( esc_html__('Invalid form data. form request came from the somewhere else not current site!','wpdbbkp') );
1043 + }
1044 +
1045 + if ( true === isset( $_POST['wpdb_clouddrive_token'] ) ) {
1046 + update_option( 'wpdb_clouddrive_token', wp_db_filter_data( sanitize_text_field( wp_unslash( $_POST['wpdb_clouddrive_token'] ) ) ), false );
1047 + }
1048 +
1049 + // Put a "settings updated" message on the screen.
1050 + $update_msg = esc_html__('Your BackupforWP Cloud Backup setting has been saved.' , 'wpdbbkp');
1051 +}
1052 +
1053 +$wpdb_clouddrive_token = get_option( 'wpdb_clouddrive_token',null);
1054 +
1055 +$wpdbbkp_bb_s3_status = '<small><b>'.esc_html__('Status', 'wpdbbkp').'</b>: '.esc_html__('Not Configured', 'wpdbbkp').' </small> ';
1056 +
1057 +if($wpdb_clouddrive_token && !empty($wpdb_clouddrive_token))
1058 +{
1059 + $wpdbbkp_bb_s3_status ='<small>'.esc_html__('Status', 'wpdbbkp').'</b>: <span class="dashicons dashicons-yes-alt" style="color:green;font-size:16px" title="'.esc_attr__('Destination enabled', 'wpdbbkp').'"></span><span class="configured">'.esc_html__('Configured', 'wpdbbkp').' </span> </small> ';
1060 +}
1061 +
1062 +?>
1063 +<h2 align="center"><strong><?php echo esc_html__('Cloud Backup by BackupforWP', 'wpdbbkp') ?></strong></h2>
1064 +<div class="panel panel-default">
1065 + <div class="panel-heading">
1066 + <h4 class="panel-title">
1067 + <a data-toggle="collapse" data-parent="#accordion" href="#collapsebb">
1068 + <?php echo '<b>'.esc_html__('Cloud Backup', 'wpdbbkp').'</b>'; ?> <?php echo wp_kses_post($wpdbbkp_bb_s3_status);?>
1069 +
1070 + </a>
1071 + </h4>
1072 + </div>
1073 + <div class="panel-body">
1074 + <?php
1075 + if($update_msg){
1076 + echo '<div class="updated"><p><strong>'.esc_html( $update_msg ).'</strong></p></div>';
1077 + }
1078 + ?>
1079 + <form class="form-group" name="Clouddrive3" method="post" action="">
1080 +
1081 + <p style="padding:0 20px;">
1082 + <?php echo '<h2 style="padding:0 20px;">'.esc_html__('Getting started with our Cloud Backup service is simple.', 'wpdbbkp').'</h2>'; ?>
1083 +
1084 + <ul style="list-style-type: style;">
1085 + <li style="margin-left: 30px;"><?php echo esc_html__('Sign up for a free account at', 'wpdbbkp'); ?> <a href="https://backupforwp.com/register" target="_blank"><?php echo esc_html__(' Cloud Backup ', 'wpdbbkp');?> </a><?php echo esc_html__('by Backup for WP', 'wpdbbkp');?></li>
1086 + <li style="margin-left: 30px;"><?php echo esc_html__('Add the website url', 'wpdbbkp'); ?> <a href="https://app.backupforwp.com/websites" target="_blank"><?php echo esc_html__('Add Website here', 'wpdbbkp');?> </a></li>
1087 + <li style="margin-left: 30px;"><?php echo esc_html__('API token will be generated on adding website.', 'wpdbbkp'); ?></li>
1088 + <li style="margin-left: 30px;"><?php echo esc_html__('Copy the token here and Click Save.', 'wpdbbkp'); ?></li>
1089 + <li style="margin-left: 30px;"><b><?php echo esc_html__('You can see your backup files from ', 'wpdbbkp'); ?><a href="https://app.backupforwp.com/dashboard/" target="_blank"><?php echo esc_html__('here', 'wpdbbkp');?> </a></b></li>
1090 + </ul>
1091 +
1092 +
1093 + <input type="hidden" name="wpdb_cd_s3" value="Y">
1094 + <input name="wpdbbackup_update_cd_setting" type="hidden" value="<?php echo esc_attr( wp_create_nonce( 'wpdbbackup-update-cd-setting' ) ); ?>" />
1095 + <?php wp_nonce_field( 'wp-database-backup' ); ?>
1096 + <div class="row form-group">
1097 + <label class="col-sm-3" for="wpdb_clouddrive_token"><?php echo esc_html__('BackforWP API Token', 'wpdbbkp') ?></label>
1098 + <div class="col-sm-6">
1099 +
1100 + <input type="text" id="wpdb_clouddrive_token" class="form-control" name="wpdb_clouddrive_token" value="<?php echo esc_html( get_option( 'wpdb_clouddrive_token' ) ); ?>" size="25" placeholder="<?php esc_attr_e('26b18a624d2f5e01324bc81f90cfff63ba493bc15f00d790729fb437e90f54ea','wpdbbkp');?>">
1101 + <a href="https://app.backupforwp.com/websites" target="_blank"><span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
1102 + </div>
1103 + </div>
1104 +
1105 + <p style="padding-left:20px"><input type="submit" name="Submit" class="btn btn-primary" value="<?php esc_attr_e( 'Save' , 'wpdbbkp' ); ?>" />&nbsp;
1106 + </p>
1107 + </form>
1108 + </div>
1109 +</div>
1110 +
1111 +
1112 +</div>
1113 + <div class="tab-pane" id="db_help">
672 1114 <div class="panel-group ">
673 1115 <div class="gn-flex-container row">
674 1116 <div class="wpdbbkp-left-side col-md-8">
675 1117 <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>
@@ -678,9 +1120,9 @@
678 1120 <li>
679 1121 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Email', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
680 1122 </label>
681 1123 <div class="support-input">
682 - <input type="text" id="wpdbbkp_query_email" name="wpdbbkp_query_email" size="47" placeholder="Enter your Email" required="">
1124 + <input type="text" id="wpdbbkp_query_email" name="wpdbbkp_query_email" size="47" placeholder="<?php esc_attr_e('Enter your Email','wpdbbkp');?>" required="">
683 1125 </div>
684 1126 </li>
685 1127 <li>
686 1128 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
@@ -685,9 +1127,9 @@
685 1127 <li>
686 1128 <label class="wpdbbkp-support-label"> <?php echo esc_html__('Query', 'wpdbbkp') ?> <span class="wpdbbkp-star-mark">*</span>
687 1129 </label>
688 1130 <div class="support-input">
689 - <textarea rows="5" cols="50" id="wpdbbkp_query_message" name="wpdbbkp_query_message" placeholder="Write your query"></textarea>
1131 + <textarea rows="5" cols="50" id="wpdbbkp_query_message" name="wpdbbkp_query_message" placeholder="<?php esc_attr_e('Write your query','wpdbbkp');?>"></textarea>
690 1132 </div>
691 1133 </li>
692 1134 <li>
693 1135 <button class="button button-primary wpdbbkp-send-query"> <?php echo esc_html__('Send Support Request', 'wpdbbkp') ?> </button>
@@ -714,9 +1156,9 @@
714 1156 <div class="panel panel-group panel-default">
715 1157 <div class="panel-heading">
716 1158 <a class="toggle_anchor" data-toggle="collapse" data-parent="#accordion" href="#collapsedb">
717 1159 <h4 class="panel-title">
718 - <?php esc_attr_e( 'System Check', 'wpdbbk' ); ?>
1160 + <?php esc_attr_e( 'System Check', 'wpdbbkp' ); ?>
719 1161 </h4>
720 1162 </a>
721 1163 </div>
722 1164 <div id="collapsedb" class="panel-collapse collapse in">
@@ -723,8 +1165,10 @@
723 1165 <div class="panel-body list-group">
724 1166
725 1167 <div class="row list-group-item">
726 1168 <?php
1169 + $df = $dt = $dp = $du = 'NA';
1170 + if(function_exists('disk_free_space')){
727 1171 /* get disk space free (in bytes) */
728 1172 $df = disk_free_space( WPDB_ROOTPATH );
729 1173 /* and get disk space total (in bytes) */
730 1174 $dt = disk_total_space( WPDB_ROOTPATH );
@@ -731,18 +1175,20 @@
731 1175 /* now we calculate the disk space used (in bytes) */
732 1176 $du = $dt - $df;
733 1177 /* percentage of disk used - this will be used to also set the width % of the progress bar */
734 1178 $dp = sprintf( '%.2f', ( $du / $dt ) * 100 );
735 -
1179 + $dp = isset( $dp )? $dp : 'NA';
736 1180 /* and we formate the size from bytes to MB, GB, etc. */
737 1181 $df = $this->wp_db_backup_format_bytes( $df );
738 1182 $du = $this->wp_db_backup_format_bytes( $du );
739 1183 $dt = $this->wp_db_backup_format_bytes( $dt );
1184 + }
1185 +
740 1186 ?>
741 1187 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
742 1188 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
743 1189 </div>
744 - <div class="col-md-3">Disk Space</div>
1190 + <div class="col-md-12">Disk Space</div>
745 1191 <div class="col-md-5">
746 1192 <div class="progress">
747 1193 <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="<?php echo esc_attr( trim( $dp ) ); ?>" aria-valuemin="0" aria-valuemax="100" style="width:<?php echo esc_attr( trim( $dp ) ); ?>%"> <?php echo esc_attr( $dp ); ?>%
748 1194 </div>
@@ -811,13 +1257,18 @@
811 1257 <div class="row list-group-item">
812 1258 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
813 1259 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
814 1260 </div>
815 - <div class="col-md-3"><?php esc_attr_e( 'Upload directory URL', 'wpdbbk' ); ?></div>
1261 + <div class="col-md-3"><?php esc_attr_e( 'Upload directory URL', 'wpdbbkp' ); ?></div>
816 1262 <div class="col-md-5">
817 1263 <?php
818 1264 $upload_dir = wp_upload_dir();
819 - echo esc_url( $upload_dir['baseurl'] )
1265 + echo esc_url( $upload_dir['baseurl'] );
1266 + global $wp_filesystem;
1267 + if(!function_exists('WP_Filesystem')){
1268 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
1269 + }
1270 + WP_Filesystem();
820 1271 ?>
821 1272 </div>
822 1273 <div class="col-md-3"></div>
823 1274 </div>
@@ -825,14 +1276,14 @@
825 1276 <div class="row list-group-item">
826 1277 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
827 1278 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
828 1279 </div>
829 - <div class="col-md-3"><?php esc_attr_e( 'Upload directory', 'wpdbbk' ); ?></div>
1280 + <div class="col-md-3"><?php esc_attr_e( 'Upload directory', 'wpdbbkp' ); ?></div>
830 1281 <div class="col-md-5"><?php echo esc_attr( $upload_dir['basedir'] ); ?></div>
831 1282 <div class="col-md-1">
832 1283 <?php echo esc_attr( substr( sprintf( '%o', fileperms( $upload_dir['basedir'] ) ), -4 ) ); ?></div>
833 1284 <div
834 - class="col-md-2"><?php echo ( ! is_writable( $upload_dir['basedir'] ) ) ? '<p class="text-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Not writable </p>' : '<p class="text-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> writable</p>'; ?>
1285 + 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>'; ?>
835 1286 </div>
836 1287 </div>
837 1288
838 1289 <div class="row list-group-item">
@@ -850,10 +1301,9 @@
850 1301 <div class="col-md-5">
851 1302 <?php
852 1303 echo esc_attr( WP_MEMORY_LIMIT );
853 1304 echo '(Max &nbsp;' . esc_attr( WP_MAX_MEMORY_LIMIT );
854 - ?>
855 - )
1305 + ?> )
856 1306 </div>
857 1307 </div>
858 1308
859 1309
@@ -860,9 +1310,9 @@
860 1310 <div class="row list-group-item">
861 1311 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
862 1312 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
863 1313 </div>
864 - <div class="col-md-3"><?php esc_attr_e( 'Max Execution Time', 'wpdbbk' ); ?></div>
1314 + <div class="col-md-3"><?php esc_attr_e( 'Max Execution Time', 'wpdbbkp' ); ?></div>
865 1315 <div class="col-md-5"> <?php echo esc_attr( ini_get( 'max_execution_time' ) ); ?></div>
866 1316 <div class="col-md-1"></div>
867 1317 <div
868 1318 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>
@@ -870,15 +1320,15 @@
870 1320 <div class="row list-group-item">
871 1321 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
872 1322 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
873 1323 </div>
874 - <div class="col-md-3"><?php esc_attr_e( 'Database backup directory', 'wpdbbk' ); ?></div>
1324 + <div class="col-md-3"><?php esc_attr_e( 'Database backup directory', 'wpdbbkp' ); ?></div>
875 1325 <div
876 1326 class="col-md-5"> <?php echo esc_attr( $upload_dir['basedir'] . '/db-backup' ); ?></div>
877 1327 <div
878 - class="col-md-1"><?php echo esc_attr( substr( sprintf( '%o', fileperms( esc_attr( $upload_dir['basedir'] ) . '/db-backup' ) ), -4 ) ); ?></div>
1328 + class="col-md-1"><?php echo esc_attr( substr( sprintf( '%o', @fileperms( esc_attr( $upload_dir['basedir'] ) . '/db-backup' ) ), -4 ) ); ?></div>
879 1329 <div
880 - class="col-md-2"><?php echo ( ! is_writable( $upload_dir['basedir'] . '/db-backup' ) ) ? '<p class="text-danger"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Not writable </p>' : '<p class="text-success"><span class="glyphicon glyphicon-ok" aria-hidden="true"></span> writable</p>'; ?></div>
1330 + 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>
881 1331 </div>
882 1332
883 1333 <div class="row list-group-item">
884 1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
@@ -883,9 +1333,9 @@
883 1333 <div class="row list-group-item">
884 1334 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
885 1335 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
886 1336 </div>
887 - <div class="col-md-3"><?php esc_attr_e( 'Class ZipArchive Present : ', 'wpdbbk' ); ?></div>
1337 + <div class="col-md-3"><?php esc_attr_e( 'Class ZipArchive Present : ', 'wpdbbkp' ); ?></div>
888 1338 <div class="col-md-5">
889 1339 <?php
890 1340 echo ( class_exists( 'ZipArchive' ) ) ? 'Yes </p>' : '<p class="">No</p>';
891 1341 ?>
@@ -896,9 +1346,9 @@
896 1346 <div class="row list-group-item">
897 1347 <div class="col-md-1"><a href="" target="_blank" title="Help"><span
898 1348 class="glyphicon glyphicon-question-sign" aria-hidden="true"></span></a>
899 1349 </div>
900 - <div class="col-md-3"><?php esc_attr_e( 'mysqldump (cmd) Present : ', 'wpdbbk' ); ?></div>
1350 + <div class="col-md-3"><?php esc_attr_e( 'mysqldump (cmd) Present : ', 'wpdbbkp' ); ?></div>
901 1351 <div class="col-md-5">
902 1352 <?php
903 1353 $wpdb_admin = new Wpdb_Admin();
904 1354 echo ( $wpdb_admin->get_mysqldump_command_path() ) ? 'Yes </p>' : '<p class="">No</p>';
@@ -984,24 +1434,26 @@
984 1434 $no = 0;
985 1435 $row_usage = 0;
986 1436 $data_usage = 0;
987 1437 $tablesstatus = $wpdb->get_results( 'SHOW TABLE STATUS' ); // phpcs:ignore
988 - foreach ( $tablesstatus as $tablestatus ) {
989 - $tablestatus_arr = (array) $tablestatus;
990 - if ( 0 === ( $no % 2 ) ) {
991 - $style = '';
992 - } else {
993 - $style = ' class="alternate"';
994 - }
995 - $no++;
996 - echo '<tr' . esc_attr( $style ) . '>';
997 - echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
998 - echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
999 - echo '<td>' . esc_attr( number_format_i18n( $tablestatus_arr['Rows'] ) ) . '</td>';
1438 + if($tablesstatus != null && !empty($tablesstatus)){
1439 + foreach ( $tablesstatus as $tablestatus ) {
1440 + $tablestatus_arr = (array) $tablestatus;
1441 + if ( 0 === ( $no % 2 ) ) {
1442 + $style = '';
1443 + } else {
1444 + $style = ' class="alternate"';
1445 + }
1446 + $no++;
1447 + echo '<tr' . esc_attr( $style ) . '>';
1448 + echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1449 + echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1450 + echo '<td>' . esc_attr( number_format_i18n( isset($tablestatus_arr['Rows'])?$tablestatus_arr['Rows']:0 ) ) . '</td>';
1000 1451
1001 - $row_usage += $tablestatus_arr['Rows'];
1452 + $row_usage += $tablestatus_arr['Rows'];
1002 1453
1003 - echo '</tr>';
1454 + echo '</tr>';
1455 + }
1004 1456 }
1005 1457 echo '<tr class="thead">';
1006 1458 echo '<th> Total:</th>';
1007 1459 echo '<th>' . esc_attr( number_format_i18n( $no ) ) . ' Table </th>';
@@ -1073,14 +1525,17 @@
1073 1525 <th><?php echo esc_html__('Version', 'wpdbbkp') ?></th>
1074 1526 </tr>
1075 1527 <?php
1076 1528 $plugins = get_plugins();
1077 - foreach ( $plugins as $plugin ) {
1078 - echo '<tr>
1079 - <td>' . esc_attr( $plugin['Name'] ) . '</td>
1080 - <td>' . esc_attr( $plugin['Version'] ) . '</td>
1081 - </tr>';
1529 + if(!empty($plugins) && is_array($plugins)){
1530 + foreach ( $plugins as $plugin ) {
1531 + echo '<tr>
1532 + <td>' . esc_attr( $plugin['Name'] ) . '</td>
1533 + <td>' . esc_attr( $plugin['Version'] ) . '</td>
1534 + </tr>';
1535 + }
1082 1536 }
1537 +
1083 1538 ?>
1084 1539 </table>
1085 1540 <table class="table table-condensed">
1086 1541 <tr class="success">
@@ -1164,30 +1619,53 @@
1164 1619 } else {
1165 1620 $checked = '';
1166 1621 }
1167 1622 $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
1623 + $wp_db_remove_on_uninstall = get_option( 'wp_db_remove_on_uninstall');
1624 + $wp_db_incremental_backup = get_option( 'wp_db_incremental_backup');
1625 + $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
1168 1626 if ( 1 === (int) $wp_db_remove_local_backup ) {
1169 1627 $remove_local_backup = 'checked';
1170 1628 } else {
1171 1629 $remove_local_backup = '';
1172 1630 }
1631 + if ( 1 === (int) $wp_db_remove_on_uninstall ) {
1632 + $remove_on_uninstall = 'checked';
1633 + } else {
1634 + $remove_on_uninstall = '';
1635 + }
1636 + if ( 1 === (int) $wp_db_incremental_backup ) {
1637 + $incremental_backup = 'checked';
1638 + } else {
1639 + $incremental_backup = '';
1640 + }
1641 + if ( 1 === (int) $wp_db_save_settings_in_backup ) {
1642 + $save_on_backup = 'checked';
1643 + } else {
1644 + $save_on_backup = '';
1645 + }
1173 1646 ?>
1174 1647 <form action="" method="post">
1175 1648 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1176 1649 <div class="input-group">
1177 1650 <span class="input-group-addon" id="sizing-addon2"><?php echo esc_html__('Maximum Local Backups', 'wpdbbkp') ?></span>
1178 - <input type="number" name="wp_local_db_backup_count" value="<?php echo esc_html( $wp_local_db_backup_count ); ?>" class="form-control" placeholder="Maximum Local Backups" aria-describedby="sizing-addon2">
1651 + <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">
1179 1652
1180 - </div>
1181 - <div class="alert alert-default" role="alert">
1182 - <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span><?php echo esc_html__(' The maximum
1653 + </div><br>
1654 + <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span><?php echo esc_html__(' The maximum
1183 1655 number of Local Database Backups that should be kept, regardless of their size.', 'wpdbbkp') ?></br>
1184 1656 <?php echo esc_html__('Leave blank for keep unlimited database backups.', 'wpdbbkp') ?>
1185 - </div>
1657 + </p>
1658 +
1186 1659 <hr>
1187 1660 <div class="input-group">
1188 1661 <label><input type="checkbox" <?php echo esc_attr( $checked ); ?> name="wp_db_log"> <?php echo esc_html__('Enable Log', 'wpdbbkp') ?></label>
1189 1662 </div>
1663 + <br>
1664 + <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1665 + <?php echo esc_html__(' Create a log file to record details of each backup operation. ', 'wpdbbkp') ?>
1666 + </p>
1667 +
1190 1668 <hr>
1191 1669 <div class="input-group">
1192 1670 <label><input type="checkbox" <?php echo esc_attr( $wp_db_backup_enable_auto_upgrade_checked ); ?> name="wp_db_backup_enable_auto_upgrade"> <?php echo esc_html__('Enable Auto Backups Before Upgrade', 'wpdbbkp') ?></label>
1193 1671 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
@@ -1199,19 +1677,40 @@
1199 1677 <div class="input-group">
1200 1678 <label><input type="checkbox" <?php echo esc_attr( $remove_local_backup ); ?> name="wp_db_remove_local_backup"> <?php echo esc_html__('Remove local backup', 'wpdbbkp') ?></label>
1201 1679 <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1202 1680 <?php echo esc_html__('If Checked then it will remove local backup.', 'wpdbbkp') ?>
1203 - <br><?php echo esc_html__('Use this option only when you have set any destination.', 'wpdbbkp') ?>
1204 - <br><?php echo esc_html__('If somesites you need only external backup.', 'wpdbbkp') ?>
1681 + <?php echo esc_html__('Use this option only when you have set any destination.', 'wpdbbkp') ?>
1682 + <?php echo esc_html__('If somesites you need only external backup.', 'wpdbbkp') ?>
1205 1683 </p>
1206 1684 </div>
1207 1685 <hr>
1208 1686 <div class="input-group">
1209 - <label> <input type="checkbox" <?php checked( get_option( 'wp_db_backup_enable_htaccess' ), '1' ); ?> name="wp_db_backup_enable_htaccess"> <?php echo esc_html__('Enable .htaccess File In Storage Directory', 'wpdbbkp') ?></label>
1210 - <p><?php echo esc_html__('Disable if issues occur when downloading backup/archive files.', 'wpdbbkp') ?></p>
1687 + <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>
1688 + <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1689 + <?php echo esc_html__('If Checked then it will skip Backup for WP plugin settings from the DB backup file .', 'wpdbbkp') ?>
1690 + </p>
1211 1691 </div>
1212 1692 <hr>
1693 + <div class="input-group">
1694 + <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>
1695 + <p><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1696 + <?php echo esc_html__('If Checked then it will delete all backup files and options when plugin is uninstalled', 'wpdbbkp') ?>
1697 +
1698 + </p>
1699 + </div>
1700 +
1701 + <?php
1702 + $remove_backup_href = esc_url( site_url() ) . '/wp-admin/admin.php?page=wp-database-backup&action=removeallbackup&_wpnonce=' . esc_attr( $nonce ); ?>
1213 1703
1704 + <div class="input-group">
1705 + <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>
1706 + <p> <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1707 + <?php echo esc_html__('Warning :This is will delete all the backups on the website. Once deleted backups can not be recovered.', 'wpdbbkp') ?>
1708 + </p>
1709 +
1710 +
1711 + </div>
1712 + <hr>
1214 1713 <div class="panel panel-default">
1215 1714 <div class="panel-heading">
1216 1715 <a data-toggle="collapse" data-parent="#accordion" href="#collapseExclude">
1217 1716 <h4 class="panel-title">
@@ -1232,30 +1731,32 @@
1232 1731 $no = 0;
1233 1732 $row_usage = 0;
1234 1733 $data_usage = 0;
1235 1734 $tablesstatus = $wpdb->get_results( 'SHOW TABLE STATUS' ); // phpcs:ignore
1236 - foreach ( $tablesstatus as $tablestatus ) {
1237 - $tablestatus_arr = (array) $tablestatus;
1238 - if ( 0 === ( $no % 2 ) ) {
1239 - $style = '';
1240 - } else {
1241 - $style = ' class="alternate"';
1242 - }
1243 - $no++;
1244 - echo '<tr' . esc_attr( $style ) . '>';
1245 - echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1246 - echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1247 - echo '<td>' . esc_attr( number_format_i18n( $tablestatus_arr['Rows'] ) ) . '</td>';
1248 - if ( false === empty( $wp_db_exclude_table ) && in_array( $tablestatus_arr['Name'], $wp_db_exclude_table, true ) ) {
1249 - $checked = 'checked';
1250 - } else {
1251 - $checked = '';
1252 - }
1253 - echo '<td> <input class="wp_db_exclude_table" type="checkbox" ' . esc_attr( $checked ) . ' value="' . esc_attr( $tablestatus_arr['Name'] ) . '" name="wp_db_exclude_table[' . esc_attr( $tablestatus_arr['Name'] ) . ']"></td>';
1735 + if($tablesstatus != null && !empty($tablesstatus)){
1736 + foreach ( $tablesstatus as $tablestatus ) {
1737 + $tablestatus_arr = (array) $tablestatus;
1738 + if ( 0 === ( $no % 2 ) ) {
1739 + $style = '';
1740 + } else {
1741 + $style = ' class="alternate"';
1742 + }
1743 + $no++;
1744 + echo '<tr' . esc_attr( $style ) . '>';
1745 + echo '<td>' . esc_attr( number_format_i18n( $no ) ) . '</td>';
1746 + echo '<td>' . esc_attr( $tablestatus_arr['Name'] ) . '</td>';
1747 + echo '<td>' . esc_attr( number_format_i18n( isset($tablestatus_arr['Rows'])?$tablestatus_arr['Rows']:0 ) ) . '</td>';
1748 + if ( false === empty( $wp_db_exclude_table ) && in_array( $tablestatus_arr['Name'], $wp_db_exclude_table, true ) ) {
1749 + $checked = 'checked';
1750 + } else {
1751 + $checked = '';
1752 + }
1753 + echo '<td> <input class="wp_db_exclude_table" type="checkbox" ' . esc_attr( $checked ) . ' value="' . esc_attr( $tablestatus_arr['Name'] ) . '" name="wp_db_exclude_table[' . esc_attr( $tablestatus_arr['Name'] ) . ']"></td>';
1254 1754
1255 - $row_usage += $tablestatus_arr['Rows'];
1755 + $row_usage += $tablestatus_arr['Rows'];
1256 1756
1257 - echo '</tr>';
1757 + echo '</tr>';
1758 + }
1258 1759 }
1259 1760 echo '<tr class="thead">';
1260 1761 echo '<th>Total:</th>';
1261 1762 echo '<th>' . esc_attr( number_format_i18n( $no ) ) . ' Table</th>';
@@ -1271,8 +1772,9 @@
1271 1772 <input class="btn btn-primary" type="submit" name="wpsetting" value="Save">
1272 1773 </form>
1273 1774 </div>
1274 1775 </div>
1776 +
1275 1777 <div class="tab-pane" id="searchreplace">
1276 1778 <div class="panel-group">
1277 1779 <?php
1278 1780 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
@@ -1280,20 +1782,24 @@
1280 1782 ?>
1281 1783 <form action="" method="post">
1282 1784 <?php wp_nonce_field( 'wp-database-backup' ); ?>
1283 1785
1284 - <p><?php echo esc_html__('If you even need to migrate your WordPress site to a different domain name, or add an SSL certificate to it, you must update the URLs in your database backup file then you can use this feature. <br> This feature allow you to Search and Replace text in your database backup file. ', 'wpdbbkp') ?><br> <?php echo esc_html__('if you want only exclude tables from search and replace text then Go to Dashboard=>Tool=>WP-DB Backup > Setting > Exclude Table From Database Backup setting. The tables you selected will be skipped over for each backup you make.', 'wpdbbkp') ?>
1786 + <p><?php echo esc_html__('If you even need to migrate your WordPress site to a different domain name,
1787 + or add an SSL certificate to it, you must update the URLs in your database backup file
1788 + then you can use this feature.','wpdbbkp'); ?> <br>
1789 + <?php echo esc_html__(' This feature allow you to Search and Replace text in your database backup file. ','wpdbbkp'); ?>
1790 + <br> <?php echo esc_html__('if you want only exclude tables from search and replace text then Go to Dashboard=>Tool=>WP-DB Backup > Setting > Exclude Table From Database Backup setting. The tables you selected will be skipped over for each backup you make.', 'wpdbbkp') ?>
1285 1791 </p>
1286 1792 <br>
1287 1793 <div class="input-group">
1288 1794 <span class="input-group-addon" id="wp_db_backup_search_text"><?php echo esc_html__('Search For', 'wpdbbkp') ?></span>
1289 - <input type="text" name="wp_db_backup_search_text" value="<?php echo esc_html( $wp_db_backup_search_text ); ?>" class="form-control" placeholder="http://localhost/wordpress" aria-describedby="wp_db_backup_search_text">
1795 + <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('https://example.com/wordpress','wpdbbkp'); ?>" aria-describedby="wp_db_backup_search_text">
1290 1796
1291 1797 </div>
1292 1798 <br>
1293 1799 <div class="input-group">
1294 1800 <span class="input-group-addon" id="wp_db_backup_replace_text"><?php echo esc_html__('Replace With', 'wpdbbkp') ?></span>
1295 - <input type="text" name="wp_db_backup_replace_text" value="<?php echo esc_html( $wp_db_backup_replace_text ); ?>" class="form-control" placeholder="http://site.com" aria-describedby="wp_db_backup_replace_text">
1801 + <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">
1296 1802
1297 1803 </div>
1298 1804
1299 1805 <div class="alert alert-default" role="alert">
@@ -1300,10 +1806,10 @@
1300 1806 <span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span>
1301 1807 <?php echo esc_html__("Leave blank those fields if you don't want use this feature and want only regular Database backup.", 'wpdbbkp') ?>
1302 1808 <br>
1303 1809 <?php echo esc_html__('Ex:', 'wpdbbkp') ?>
1304 - <br><?php echo esc_html__('Search For:', 'wpdbbkp') ?> http://localhost/wordpress/
1305 - <br><?php echo esc_html__('Replace With:', 'wpdbbkp') ?> http://domain.com/
1810 + <br><?php echo esc_html__('Search For:', 'wpdbbkp') ?> <?php echo esc_url('http://example.com/wordpress/', 'wpdbbkp'); ?>
1811 + <br><?php echo esc_html__('Replace With:', 'wpdbbkp') ?> <?php echo esc_url('http://domain.com/', 'wpdbbkp') ?>
1306 1812
1307 1813 <br><br>
1308 1814 <?php echo esc_html__('Note - This is Search & Replace data in your WordPress Database Backup File not in current Database installation.', 'wpdbbkp') ?>
1309 1815
@@ -1367,39 +1873,79 @@
1367 1873 global $wpdb;
1368 1874 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1369 1875 $options_backup = get_option( 'wp_db_backup_backups' );
1370 1876 $settings_backup = get_option( 'wp_db_backup_options' );
1371 - delete_option( 'wp_db_backup_backups' );
1372 - delete_option( 'wp_db_backup_options' );
1877 + $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
1878 + if($wp_db_save_settings_in_backup){
1879 + delete_option( 'wp_db_backup_backups' );
1880 + delete_option( 'wp_db_backup_options' );
1881 + }
1373 1882 /* END : Prevent saving backup plugin settings in the database dump */
1374 1883 $wp_db_exclude_table = array();
1375 1884 $wp_db_exclude_table = get_option( 'wp_db_exclude_table' );
1376 1885 $tables = $wpdb->get_col( 'SHOW TABLES' ); // phpcs:ignore
1377 1886 $output = '';
1378 - foreach ( $tables as $table ) {
1379 - if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
1380 - $result = $wpdb->get_results( "SELECT * FROM {$table}", ARRAY_N ); // phpcs:ignore
1381 - $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1382 - $output .= "\n\n" . $row2[1] . ";\n\n";
1383 - $result_count = count( $result );
1384 - for ( $i = 0; $i < $result_count; $i++ ) {
1385 - $row = $result[ $i ];
1386 - $output .= 'INSERT INTO ' . $table . ' VALUES(';
1387 - $result_o_index = count( $result[0] );
1388 - for ( $j = 0; $j < $result_o_index; $j++ ) {
1389 - $row[ $j ] = $wpdb->_real_escape( $row[ $j ] );
1390 - $output .= ( isset( $row[ $j ] ) ) ? '"' . $row[ $j ] . '"' : '""';
1391 - if ( $j < ( $result_o_index - 1 ) ) {
1392 - $output .= ',';
1887 + if(!empty($tables) && !is_array($tables)){
1888 + foreach ( $tables as $table ) {
1889 + if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
1890 +
1891 + $check_count = $wpdb->get_var( "SELECT count(*) FROM {$table}"); // phpcs:ignore
1892 + $check_count = intval($check_count);
1893 + $sub_limit =500;
1894 + if(isset($check_count) && $check_count>$sub_limit){
1895 + $result =array();
1896 + $t_sub_queries= ceil($check_count/$sub_limit);
1897 + for($sub_i=0;$sub_i<$t_sub_queries;$sub_i++)
1898 + {
1899 + $sub_offset = $sub_i*$sub_limit;
1900 + $sub_result = false;
1901 + if ( false === $sub_result ) {
1902 + // phpcs:ignore -- using direct query to get the data of table in chunks.
1903 + $sub_result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table} LIMIT %d OFFSET %d",array($sub_limit,$sub_offset)), ARRAY_A );
1904 + }
1905 +
1906 + if($sub_result){
1907 + $result = array_merge($result,$sub_result);
1908 + }
1909 + sleep(1);
1393 1910 }
1394 1911 }
1395 - $output .= ");\n";
1912 + else{
1913 + $result = $wpdb->get_results( $wpdb->prepare("SELECT * FROM {$table}"), ARRAY_A ); // phpcs:ignore
1914 + }
1915 +
1916 +
1917 + $row2 = $wpdb->get_row( 'SHOW CREATE TABLE ' . $table, ARRAY_N ); // phpcs:ignore
1918 + $output .= "\n\n" . $row2[1] . ";\n\n";
1919 + $result_count = count( $result );
1920 + for ( $i = 0; $i < $result_count; $i++ ) {
1921 + if(isset($result[ $i ])){
1922 + $row = $result[ $i ];
1923 + $output .= 'INSERT INTO ' . $table . ' VALUES(';
1924 + $result_o_index = count( $result[0] );
1925 + $j=0;
1926 + foreach ($row as $key => $value) {
1927 + $row[ $key] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $row[$key],$table,$key) );
1928 + $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
1929 + if ( $j < ( $result_o_index - 1 ) ) {
1930 + $output .= ',';
1931 + }
1932 + $j++;
1933 + }
1934 + $output .= ");\n";
1935 + }
1936 +
1937 + }
1938 + $output .= "\n";
1396 1939 }
1397 - $output .= "\n";
1940 + sleep(1);
1398 1941 }
1942 +
1399 1943 }
1944 +
1400 1945 $wpdb->flush();
1401 1946 /* BEGIN : Prevent saving backup plugin settings in the database dump */
1947 + $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
1402 1948 add_option( 'wp_db_backup_backups', $options_backup );
1403 1949 add_option( 'wp_db_backup_options', $settings_backup );
1404 1950 /* END : Prevent saving backup plugin settings in the database dump */
1405 1951 return $output;
@@ -1404,8 +1950,142 @@
1404 1950 /* END : Prevent saving backup plugin settings in the database dump */
1405 1951 return $output;
1406 1952 }
1407 1953
1954 + /**
1955 + * Create database backup new function.
1956 + */
1957 + public function wp_db_backup_create_mysql_backup_new( $table, $file_path ) {
1958 + global $wpdb, $wp_filesystem;
1959 +
1960 + // Ensure WP Filesystem is loaded
1961 + if ( ! function_exists( 'WP_Filesystem' ) ) {
1962 + require_once ABSPATH . 'wp-admin/includes/file.php';
1963 + }
1964 + WP_Filesystem();
1965 +
1966 + // Define file size threshold (e.g., 10MB)
1967 + $file_size_threshold = 10 * 1024 * 1024; // 10MB
1968 +
1969 + // Initialize the file with table creation statement if it doesn't exist
1970 +
1971 + $table = esc_sql( $table );
1972 + $row2 = $wpdb->get_row( "SHOW CREATE TABLE `{$table}`", ARRAY_N ); // phpcs:ignore
1973 + $initial_output = "\n\n" . $row2[1] . ";\n\n";
1974 +
1975 + $use_php_methods = false;
1976 + if ( $wp_filesystem->exists( $file_path ) ) {
1977 + // Check file size
1978 + $file_size = $wp_filesystem->size( $file_path );
1979 + if ( $file_size !== false && $file_size > $file_size_threshold ) {
1980 + $use_php_methods = true;
1981 + }
1982 + }
1983 +
1984 + // Function to append content
1985 + $append_content = function( $new_content ) use ( $file_path, $wp_filesystem, $use_php_methods ) {
1986 + if ( $use_php_methods ) {
1987 + // Using PHP methods to append
1988 + if ( ! $wp_filesystem->exists( $file_path ) ) {
1989 + // phpcs:ignore -- WP Filesystem fileing for large files
1990 + file_put_contents( $file_path, $new_content );
1991 + } else {
1992 + // phpcs:ignore -- WP Filesystem fileing for large files
1993 + file_put_contents( $file_path, $new_content, FILE_APPEND );
1994 + }
1995 + } else {
1996 + // Use WP Filesystem to append
1997 + if ( ! $wp_filesystem->exists( $file_path ) ) {
1998 + $wp_filesystem->put_contents( $file_path, $new_content, FS_CHMOD_FILE );
1999 + } else {
2000 + // Read current contents
2001 + $current_contents = $wp_filesystem->get_contents( $file_path );
2002 + if ( $current_contents === false ) {
2003 + // Handle error if reading fails
2004 + return false;
2005 + }
2006 + // Append new content
2007 + $updated_contents = $current_contents . $new_content;
2008 + // Write back updated contents
2009 + if ( ! $wp_filesystem->put_contents( $file_path, $updated_contents, FS_CHMOD_FILE ) ) {
2010 + // Handle error if writing fails
2011 + return false;
2012 + }
2013 + }
2014 + }
2015 + return true;
2016 + };
2017 +
2018 + // Write the initial output to the file
2019 + if ( ! $append_content( $initial_output ) ) {
2020 + return false; // Handle error if initial content writing fails
2021 + }
2022 +
2023 + $sub_limit = 500;
2024 + // phpcs:ignore
2025 + $check_count = $wpdb->get_var( "SELECT COUNT(*) FROM `{$table}`" );
2026 + $check_count = intval( $check_count );
2027 +
2028 + if ( $check_count > $sub_limit ) {
2029 + $t_sub_queries = ceil( $check_count / $sub_limit );
2030 +
2031 + for ( $sub_i = 0; $sub_i < $t_sub_queries; $sub_i++ ) {
2032 + $sub_offset = $sub_i * $sub_limit;
2033 + $sub_result = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM `{$table}` LIMIT %d OFFSET %d", array( $sub_limit, $sub_offset ) ), ARRAY_A ); // phpcs:ignore
2034 +
2035 + if ( $sub_result ) {
2036 + $output = '';
2037 + foreach ( $sub_result as $row ) {
2038 + $output .= 'INSERT INTO ' . $table . ' VALUES(';
2039 + $result_o_index = count( $row );
2040 + $j = 0;
2041 + foreach ( $row as $key => $value ) {
2042 + $row[ $key ] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $value, $table, $key ) );
2043 + $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2044 + if ( $j < ( $result_o_index - 1 ) ) {
2045 + $output .= ',';
2046 + }
2047 + $j++;
2048 + }
2049 + $output .= ");\n";
2050 + }
2051 + // Append to the file
2052 + if ( ! $append_content( $output ) ) {
2053 + return false; // Handle error if appending content fails
2054 + }
2055 + }
2056 + sleep(1);
2057 + }
2058 + } else {
2059 + $result = $wpdb->get_results( "SELECT * FROM `{$table}`", ARRAY_A ); // phpcs:ignore
2060 +
2061 + $output = '';
2062 + foreach ( $result as $row ) {
2063 + $output .= 'INSERT INTO ' . $table . ' VALUES(';
2064 + $result_o_index = count( $row );
2065 + $j = 0;
2066 + foreach ( $row as $key => $value ) {
2067 + $row[ $key ] = $wpdb->_real_escape( apply_filters( 'wpdbbkp_process_db_fields', $value, $table, $key ) );
2068 + $output .= ( isset( $row[ $key ] ) ) ? '"' . $row[ $key ] . '"' : '""';
2069 + if ( $j < ( $result_o_index - 1 ) ) {
2070 + $output .= ',';
2071 + }
2072 + $j++;
2073 + }
2074 + $output .= ");\n";
2075 + }
2076 + // Append to the file
2077 + if ( ! $append_content( $output ) ) {
2078 + return false; // Handle error if appending content fails
2079 + }
2080 + }
2081 +
2082 + // Flush the database cache
2083 + $wpdb->flush();
2084 + return true;
2085 + }
2086 +
2087 +
1408 2088 /**
1409 2089 * Mysql Dump set path.
1410 2090 *
1411 2091 * @param string $path - Path.
@@ -1449,10 +2129,10 @@
1449 2129 '/usr/bin/mysqldump',
1450 2130 '/opt/local/lib/mysql6/bin/mysqldump',
1451 2131 '/opt/local/lib/mysql5/bin/mysqldump',
1452 2132 '/opt/local/lib/mysql4/bin/mysqldump',
1453 - '/xampp/mysql/bin/mysqldump',
1454 - '/Program Files/xampp/mysql/bin/mysqldump',
2133 + '/xwpdbbkpp/mysql/bin/mysqldump',
2134 + '/Program Files/xwpdbbkpp/mysql/bin/mysqldump',
1455 2135 '/Program Files/MySQL/MySQL Server 6.0/bin/mysqldump',
1456 2136 '/Program Files/MySQL/MySQL Server 5.5/bin/mysqldump',
1457 2137 '/Program Files/MySQL/MySQL Server 5.4/bin/mysqldump',
1458 2138 '/Program Files/MySQL/MySQL Server 5.1/bin/mysqldump',
@@ -1642,9 +2322,9 @@
1642 2322
1643 2323 // If there are mysqldump errors delete the database dump file as mysqldump will still have written one.
1644 2324 if ( $this->get_errors( $this->get_mysqldump_method() ) && file_exists( $sql_filename ) ) {
1645 2325 if ( file_exists( $sql_filename ) ) {
1646 - unlink( $sql_filename );
2326 + wp_delete_file( $sql_filename );
1647 2327 }
1648 2328 }
1649 2329
1650 2330 // If we have an empty file delete it.
@@ -1649,9 +2329,9 @@
1649 2329
1650 2330 // If we have an empty file delete it.
1651 2331 if ( 0 === filesize( $sql_filename ) ) {
1652 2332 if ( file_exists( $sql_filename ) ) {
1653 - unlink( $sql_filename );
2333 + wp_delete_file( $sql_filename );
1654 2334 }
1655 2335 }
1656 2336
1657 2337 // If the file still exists then it must be good.
@@ -1697,31 +2377,46 @@
1697 2377 $source_directory = $this->wp_db_backup_wp_config_path();
1698 2378
1699 2379 $path_info = wp_upload_dir();
1700 2380 $htasses_text = '';
1701 - wp_mkdir_p( $path_info['basedir'] . '/db-backup' );
1702 - fclose( fopen( $path_info['basedir'] . '/db-backup/index.php', 'w' ) ); // phpcs:ignore
2381 + global $wpdb,$wp_filesystem;
2382 + if ( ! function_exists( 'WP_Filesystem' ) ) {
2383 + require_once ABSPATH . '/wp-admin/includes/file.php';
2384 + }
2385 + WP_Filesystem();
2386 +
2387 + if(!$wp_filesystem){
2388 + return false;
2389 + }
2390 +
2391 + wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR);
2392 + wp_mkdir_p($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log');
2393 + $file_contents = "<?php\n// Silence is golden.\n";
2394 +
2395 + // Create the file with the given contents
2396 + $wp_filesystem->put_contents( $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/index.php', $file_contents, FS_CHMOD_FILE );
2397 + $wp_filesystem->put_contents( $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/log/index.php', $file_contents, FS_CHMOD_FILE );
2398 +
2399 +
1703 2400 // Added htaccess file 08-05-2015 for prevent directory listing.
1704 2401 // Fixed Vulnerability 22-06-2016 for prevent direct download.
1705 - if ( 1 === (int) get_option( 'wp_db_backup_enable_htaccess' ) ) {
1706 - $f = fopen( $path_info['basedir'] . '/db-backup/.htaccess', 'w' ); // phpcs:ignore
1707 - fwrite( // phpcs:ignore
1708 - $f,
1709 - '#These next two lines will already exist in your .htaccess file
1710 - RewriteEngine On
1711 - RewriteBase /
1712 - # Add these lines right after the preceding two
1713 - RewriteCond %{REQUEST_FILENAME} ^.*(.zip)$
1714 - RewriteCond %{HTTP_COOKIE} !^.*can_download.*$ [NC]
1715 - RewriteRule . - [R=403,L]'
1716 - ); // phpcs:ignore
1717 - fclose( $f ); // phpcs:ignore
1718 - }
2402 +
2403 + $htaccess_content = '# Disable public access to this folder
2404 +<IfModule mod_authz_core.c>
2405 + Require all denied
2406 +</IfModule>
2407 +
2408 +<IfModule !mod_authz_core.c>
2409 + Deny from all
2410 +</IfModule>';
2411 + $wp_filesystem->put_contents( $path_info['basedir'] . '/db-backup/.htaccess', $htaccess_content, FS_CHMOD_FILE );
2412 +
1719 2413 // Begin : Generate SQL DUMP and save to file database.sql.
1720 - $wp_site_name = preg_replace( '/[^A-Za-z0-9\_]/', '_', get_bloginfo( 'name' ) );
1721 - $wp_db_file_name = $wp_site_name . '_' . gmdate( 'Y_m_d' ) . '_' . time() . '_' . substr( md5( AUTH_KEY ), 0, 7 ) . '_wpdb';
2414 + $wp_site_name = preg_replace('/[^\p{L}\p{M}]+/u', '_', get_bloginfo('name'));
2415 + $wp_db_file_name = $wp_site_name . '_' . gmdate( 'Y_m_d' ) . '_' . time() . '_' . substr( md5( wp_rand(100,9999999) ), 0, 9 ) . '_wpdb';
1722 2416 $sql_filename = $wp_db_file_name . '.sql';
1723 2417 $filename = $wp_db_file_name . '.zip';
2418 + $logname = $wp_db_file_name . '.txt';
1724 2419
1725 2420 // Begin : Generate SQL DUMP using cmd 06-03-2016.
1726 2421 $my_sql_dump = 0;
1727 2422 if ( $this->get_mysqldump_command_path() ) {
@@ -1730,12 +2425,35 @@
1730 2425 }
1731 2426 } else {
1732 2427 $my_sql_dump = 1;
1733 2428 }
2429 +
1734 2430 if ( 1 === (int) $my_sql_dump ) {
1735 - $handle = fopen( $path_info['basedir'] . '/db-backup/' . $sql_filename, 'w+' ); // phpcs:ignore
1736 - fwrite( $handle, $this->wp_db_backup_create_mysql_backup() ); // phpcs:ignore
1737 - fclose( $handle ); // phpcs:ignore
2431 + /* BEGIN : Prevent saving backup plugin settings in the database dump */
2432 + $options_backup = get_option( 'wp_db_backup_backups' );
2433 + $settings_backup = get_option( 'wp_db_backup_options' );
2434 + $wp_db_save_settings_in_backup = get_option( 'wp_db_save_settings_in_backup',1);
2435 + if($wp_db_save_settings_in_backup){
2436 + delete_option( 'wp_db_backup_backups' );
2437 + delete_option( 'wp_db_backup_options' );
2438 + }
2439 + /* END : Prevent saving backup plugin settings in the database dump */
2440 + //phpcs:ignore -- using direct query get all tables name to be backedup.
2441 + $tables = $wpdb->get_col( 'SHOW TABLES' );
2442 + $wp_db_exclude_table = get_option( 'wp_db_exclude_table',array());
2443 + if(!empty($tables)){
2444 + foreach($tables as $table){
2445 + if ( empty( $wp_db_exclude_table ) || ( ! ( in_array( $table, $wp_db_exclude_table, true ) ) ) ) {
2446 + $this->wp_db_backup_create_mysql_backup_new($table, $path_info['basedir'] . '/db-backup/' . $sql_filename );
2447 + }
2448 + }
2449 +
2450 + }
2451 + /* BEGIN : Prevent saving backup plugin settings in the database dump */
2452 + $options_backup = wpdbbkp_filter_unique_filenames( $options_backup );
2453 + add_option( 'wp_db_backup_backups', $options_backup );
2454 + add_option( 'wp_db_backup_options', $settings_backup );
2455 + /* END : Prevent saving backup plugin settings in the database dump */
1738 2456 }
1739 2457 /* End : Generate SQL DUMP using cmd 06-03-2016 */
1740 2458
1741 2459 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
@@ -1740,12 +2458,13 @@
1740 2458
1741 2459 $wp_db_backup_search_text = get_option( 'wp_db_backup_search_text' );
1742 2460 $wp_db_backup_replace_text = get_option( 'wp_db_backup_replace_text' );
1743 2461 if ( ( false === empty( $wp_db_backup_search_text ) ) && ( false === empty( $wp_db_backup_replace_text ) ) ) {
1744 - $backup_str = file_get_contents( $path_info['basedir'] . '/db-backup/' . $sql_filename ); // phpcs:ignore
1745 2462 $filecontent = wp_remote_get( $path_info['basedir'] . '/db-backup/' . $sql_filename );
1746 - $backup_str = str_replace( $wp_db_backup_search_text, $wp_db_backup_replace_text, $backup_str ); // phpcs:ignore
1747 - file_put_contents( $path_info['basedir'] . '/db-backup/' . $sql_filename, $backup_str ); // phpcs:ignore
2463 + if (! is_wp_error( $filecontent ) && isset($filecontent['body']) ) {
2464 + $backup_str = str_replace( $wp_db_backup_search_text, $wp_db_backup_replace_text, $filecontent['body'] );
2465 + $wp_filesystem->put_contents( $path_info['basedir'] . '/db-backup/' . $sql_filename, $backup_str, FS_CHMOD_FILE );
2466 + }
1748 2467 }
1749 2468
1750 2469 /* End : Generate SQL DUMP and save to file database.sql */
1751 2470 $upload_path = array(
@@ -1751,8 +2470,10 @@
1751 2470 $upload_path = array(
1752 2471 'filename' => ( $filename ),
1753 2472 'dir' => ( $path_info['basedir'] . '/db-backup/' . $filename ),
1754 2473 'url' => ( $path_info['baseurl'] . '/db-backup/' . $filename ),
2474 + 'log_dir' => ( $path_info['basedir'] . '/db-backup/log/' . $logname ),
2475 + 'log_url' => ( $path_info['baseurl'] . '/db-backup/log/' . $logname ),
1755 2476 'size' => 0,
1756 2477 );
1757 2478 $arcname = $path_info['basedir'] . '/db-backup/' . $wp_db_file_name . '.zip';
1758 2479 if ( class_exists( 'ZipArchive' ) ) {
@@ -1768,14 +2489,17 @@
1768 2489 // Create the archive.
1769 2490 $v_list = $archive->create( $v_dir, PCLZIP_OPT_REMOVE_PATH, $v_remove );
1770 2491 }
1771 2492
1772 - global $wpdb;
2493 +
1773 2494 $mysqlversion = wp_cache_get( 'wpdb_mysqlversion' );
1774 2495 if ( true === empty( $mysqlversion ) ) {
1775 2496 $mysqlversion = $wpdb->get_var( 'SELECT VERSION() AS version' ); // phpcs:ignore
1776 2497 wp_cache_set( 'wpdb_mysqlversion', $mysqlversion, '', 18000 );
1777 2498 }
2499 + if ( ! function_exists( 'get_plugins' ) ) {
2500 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
2501 + }
1778 2502 $my_theme = wp_get_theme();
1779 2503 $active_plugin = count(get_option('active_plugins'));
1780 2504 $total_plugin = count(get_plugins());
1781 2505 $log_message = '<b>WordPress Version</b> : ' . get_bloginfo( 'version' );
@@ -1803,14 +2527,14 @@
1803 2527 if ( ! ( $number_of_existing_backups < $number_of_backups_from_user ) ) {
1804 2528 $diff = $number_of_existing_backups - $number_of_backups_from_user;
1805 2529 for ( $i = 0; $i <= $diff; $i++ ) {
1806 2530 $index = $i;
1807 - if ( file_exists( $options[ $index ]['dir'] ) ) {
1808 - unlink( $options[ $index ]['dir'] );
2531 + if ( isset($options[ $index ]['dir']) && file_exists( $options[ $index ]['dir'] ) ) {
2532 + wp_delete_file( $options[ $index ]['dir'] );
1809 2533 }
1810 2534 $file_sql = explode( '.', $options[ $index ]['dir'] );
1811 - if ( file_exists( $file_sql[0] . '.sql' ) ) {
1812 - unlink( $file_sql[0] . '.sql' );
2535 + if ( isset($file_sql[0]) && file_exists( $file_sql[0] . '.sql' ) ) {
2536 + wp_delete_file( $file_sql[0] . '.sql' );
1813 2537 }
1814 2538 }
1815 2539 for ( $i = ( $diff + 1 ); $i < $number_of_existing_backups; $i++ ) {
1816 2540 $index = $i;
@@ -1816,14 +2540,16 @@
1816 2540 $index = $i;
1817 2541
1818 2542 $newoptions[] = $options[ $index ];
1819 2543 }
2544 + $newoptions = wpdbbkp_filter_unique_filenames( $newoptions );
1820 2545
1821 - update_option( 'wp_db_backup_backups', $newoptions );
2546 + update_option( 'wp_db_backup_backups', $newoptions , false);
1822 2547 }
1823 2548 }
2549 +
1824 2550 if ( file_exists( $path_info['basedir'] . '/db-backup/' . $sql_filename ) ) {
1825 - unlink( $path_info['basedir'] . '/db-backup/' . $sql_filename );
2551 + wp_delete_file( $path_info['basedir'] . '/db-backup/' . $sql_filename );
1826 2552 }
1827 2553 return $upload_path;
1828 2554 }
1829 2555
@@ -1852,10 +2578,22 @@
1852 2578 * Backup Process.
1853 2579 */
1854 2580 public function wp_db_backup_event_process() {
1855 2581 // Added in v.3.9.5!
1856 - set_time_limit( 0 );
2582 + global $wp_filesystem;
2583 + if(!function_exists('WP_Filesystem')){
2584 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
2585 + }
2586 + WP_Filesystem();
1857 2587
2588 + $cron_condition = apply_filters('wpdbbkp_dbback_cron_condition',true );
2589 + if(wp_doing_cron() && !$cron_condition){
2590 + return false;
2591 + }
2592 +
2593 + set_time_limit( 0 ); //phpcs:ignore -- increase time limit for backup process.
2594 + ignore_user_abort(true);
2595 +
1858 2596 $details = $this->wp_db_backup_create_archive();
1859 2597 $options = get_option( 'wp_db_backup_backups' );
1860 2598
1861 2599 if ( ! $options ) {
@@ -1873,28 +2611,36 @@
1873 2611 }
1874 2612 } else {
1875 2613 $log_message = '';
1876 2614 }
2615 + $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
2616 + $destination = ( 1 === (int) $wp_db_remove_local_backup ) ? '' : 'Local, ';
1877 2617
2618 + $args = array( $details['filename'], $details['dir'], $log_message, $details['size'], $destination );
2619 + do_action_ref_array( 'wp_db_backup_completed', array( &$args ) );
2620 +
1878 2621 $options[] = array(
1879 2622 'date' => time(),
1880 2623 'filename' => $details['filename'],
1881 2624 'url' => $details['url'],
1882 2625 'dir' => $details['dir'],
1883 - 'log' => $log_message,
2626 + 'log' => $details['log_url'],
1884 2627 'search_replace' => $is_search_replace_flag,
1885 2628 'sqlfile' => $details['sqlfile'],
1886 2629 'size' => $details['size'],
2630 + 'type' =>'database',
2631 + 'destination' => $args[4]
1887 2632 );
1888 - $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
1889 2633 if ( 1 !== (int) $wp_db_remove_local_backup ) {
1890 - update_option( 'wp_db_backup_backups', $options );
2634 + $options = wpdbbkp_filter_unique_filenames( $options );
2635 + update_option( 'wp_db_backup_backups', $options , false);
1891 2636 }
1892 - $wp_db_remove_local_backup = get_option( 'wp_db_remove_local_backup' );
1893 - $destination = ( 1 === (int) $wp_db_remove_local_backup ) ? '' : 'Local, ';
1894 -
1895 - $args = array( $details['filename'], $details['dir'], $log_message, $details['size'], $destination );
1896 - do_action_ref_array( 'wp_db_backup_completed', array( &$args ) );
2637 + if(isset($details['log_dir']) && !empty($details['log_dir']))
2638 + {
2639 + if ($wp_filesystem->is_writable($details['log_dir']) || file_exists($details['log_dir'])) {
2640 + $wp_filesystem->put_contents( $details['log_dir'], str_replace(array("<br>","<b>","</b>"), array("\n","",""), $args[2]), FS_CHMOD_FILE );
2641 + }
2642 + }
1897 2643 }
1898 2644
1899 2645 /**
1900 2646 * Cron schedule.
@@ -1929,10 +2675,22 @@
1929 2675 * Schedular activation.
1930 2676 */
1931 2677 public function wp_db_backup_scheduler_activation() {
1932 2678 $options = get_option( 'wp_db_backup_options' );
1933 - if ( ( ! wp_next_scheduled( 'wp_db_backup_event' ) ) && ( true === isset( $options['enable_autobackups'] ) ) ) {
1934 - wp_schedule_event( time(), $options['autobackup_frequency'], 'wp_db_backup_event' );
2679 + if ( ( ! wp_next_scheduled( 'wpdbbkp_db_backup_event' ) ) && ( true === isset( $options['enable_autobackups'] ) ) ) {
2680 + $cron_freq = apply_filters( 'wpdbbkp_dbback_cron_frequency',$options['autobackup_frequency']);
2681 + if(isset($options['autobackup_type']) && $options['autobackup_type'] == 'db')
2682 + {
2683 + $timestamp = strtotime('today 23:59'); // Start at the next midnight
2684 + wp_schedule_event( $timestamp , $cron_freq, 'wpdbbkp_db_backup_event' );
2685 +
2686 + }
2687 + }else{
2688 + if( !empty($options) && ( false === isset( $options['enable_autobackups'] ) ) || ( true === isset( $options['enable_autobackups'] ) ) && isset($options['autobackup_type']) && $options['autobackup_type'] != 'db')
2689 + {
2690 + wp_clear_scheduled_hook( 'wpdbbkp_db_backup_event' );
2691 + }
2692 +
1935 2693 }
1936 2694 }
1937 2695
1938 2696 /**
@@ -1941,24 +2699,29 @@
1941 2699 * @param string $key - key name.
1942 2700 */
1943 2701 public function wp_backup_get_config_data( $key ) {
1944 2702 $filepath = get_home_path() . '/wp-config.php';
1945 - $config_file = file_get_contents( "$filepath", true );
1946 - switch ( $key ) {
1947 - case 'DB_NAME':
1948 - preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
1949 - break;
1950 - case 'DB_USER':
1951 - preg_match( "/'DB_USER',\s*'(.*)?'/", $config_file, $matches );
1952 - break;
1953 - case 'DB_PASSWORD':
1954 - preg_match( "/'DB_PASSWORD',\s*'(.*)?'/", $config_file, $matches );
1955 - break;
1956 - case 'DB_HOST':
1957 - preg_match( "/'DB_HOST',\s*'(.*)?'/", $config_file, $matches );
1958 - break;
2703 + $config_file = @file_get_contents( "$filepath", true );
2704 + if($config_file){
2705 + switch ( $key ) {
2706 + case 'DB_NAME':
2707 + preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2708 + break;
2709 + case 'DB_USER':
2710 + preg_match( "/'DB_USER',\s*'(.*)?'/", $config_file, $matches );
2711 + break;
2712 + case 'DB_PASSWORD':
2713 + preg_match( "/'DB_PASSWORD',\s*'(.*)?'/", $config_file, $matches );
2714 + break;
2715 + case 'DB_HOST':
2716 + preg_match( "/'DB_HOST',\s*'(.*)?'/", $config_file, $matches );
2717 + break;
2718 + }
2719 + return $matches[1];
1959 2720 }
1960 - return $matches[1];
2721 +
2722 + return '';
2723 +
1961 2724 }
1962 2725
1963 2726 /**
1964 2727 * Get db name from config.
@@ -1964,11 +2727,14 @@
1964 2727 * Get db name from config.
1965 2728 */
1966 2729 public function wp_backup_get_config_db_name() {
1967 2730 $filepath = get_home_path() . '/wp-config.php';
1968 - $config_file = file_get_contents( "$filepath", true );
1969 - preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
1970 - return $matches[1];
2731 + $config_file = @file_get_contents( "$filepath", true );
2732 + if($config_file){
2733 + preg_match( "/'DB_NAME',\s*'(.*)?'/", $config_file, $matches );
2734 + return $matches[1];
2735 + }
2736 + return '';
1971 2737 }
1972 2738
1973 2739 /**
1974 2740 * Recursive sanitation for an array
@@ -1977,8 +2743,11 @@
1977 2743 *
1978 2744 * @return mixed
1979 2745 */
1980 2746 public function recursive_sanitize_text_field( $array ) {
2747 + if( ! is_array( $array ) ) {
2748 + return sanitize_text_field( $array );
2749 + }
1981 2750 foreach ( $array as $key => &$value ) {
1982 2751 if ( is_array( $value ) ) {
1983 2752 $value = $this->recursive_sanitize_text_field( $value );
1984 2753 } else {
@@ -1995,16 +2764,16 @@
1995 2764 public function admin_scripts_style() {
1996 2765 if ( true === $this->is_wpdb_page() ) {
1997 2766 wp_enqueue_script( 'jquery' );
1998 2767
1999 - wp_register_script( 'bootstrapjs', WPDB_PLUGIN_URL . '/assets/js/bootstrap.min.js', array( 'jquery' ), WPDB_VERSION, true );
2768 + wp_register_script( 'bootstrapjs', WPDB_PLUGIN_URL . '/assets/js/bootstrap.min.js', array( 'jquery' ), WPDB_VERSION, false );
2000 2769 wp_enqueue_script( 'bootstrapjs' );
2001 2770
2002 2771 wp_register_style( 'bootstrapcss', WPDB_PLUGIN_URL . '/assets/css/bootstrap.min.css', array(), WPDB_VERSION );
2003 2772 wp_enqueue_style( 'bootstrapcss' );
2004 2773
2005 - wp_register_script( 'dataTables', WPDB_PLUGIN_URL . '/assets/js/jquery.dataTables.js', array( 'jquery' ), WPDB_VERSION, true );
2006 - wp_enqueue_script( 'dataTables' );
2774 + wp_register_script( 'dataTablesjs', WPDB_PLUGIN_URL . '/assets/js/jquery.dataTables.js', array( 'jquery' ), WPDB_VERSION, false );
2775 + wp_enqueue_script( 'dataTablesjs' );
2007 2776
2008 2777 wp_register_style( 'dataTablescss', WPDB_PLUGIN_URL . '/assets/css/jquery.dataTables.css', array(), WPDB_VERSION );
2009 2778 wp_enqueue_style( 'dataTablescss' );
2010 2779
@@ -2033,13 +2802,16 @@
2033 2802 public function wpdbbkp_admin_style($hook_suffix)
2034 2803 {
2035 2804 if($hook_suffix=="tools_page_wp-database-backup" || $hook_suffix=="toplevel_page_wp-database-backup")
2036 2805 {
2037 - wp_enqueue_script('wpdbbkp-admin-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin.js', array('jquery'), WPDB_VERSION, 'true' );
2806 + wp_register_script('wpdbbkp-admin-script', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin.js', array('jquery'), WPDB_VERSION, 'true' );
2038 2807 wp_localize_script('wpdbbkp-admin-script', 'wpdbbkp_script_vars', array(
2039 2808 'nonce' => wp_create_nonce( 'wpdbbkp-admin-nonce' ),
2040 - )
2041 - );
2809 + 'siteurl' => base64_encode(site_url( )),
2810 + 'ud'=>wpdbbkp_get_current_user_name_email(),
2811 + 'is_subscribed'=>wpdbbkp_if_remote_active(),
2812 + ));
2813 + wp_enqueue_script('wpdbbkp-admin-script');
2042 2814
2043 2815 // Adding custom js
2044 2816 $local = array(
2045 2817 'ajax_url' => admin_url( 'admin-ajax.php' ),
@@ -2044,9 +2816,9 @@
2044 2816 $local = array(
2045 2817 'ajax_url' => admin_url( 'admin-ajax.php' ),
2046 2818 'wpdbbkp_admin_security_nonce' => wp_create_nonce('wpdbbkp_ajax_check_nonce'),
2047 2819 );
2048 - wp_register_script('wpdbbkp-admin-fb', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin-full-backup.js', array(), WPDB_VERSION , true );
2820 + wp_register_script('wpdbbkp-admin-fb', WPDB_PLUGIN_URL . '/assets/js/wpdbbkp-admin-cron-backup.js', array(), WPDB_VERSION , true );
2049 2821
2050 2822 wp_localize_script('wpdbbkp-admin-fb', 'wpdbbkp_localize_admin_data', $local );
2051 2823 wp_enqueue_script('wpdbbkp-admin-fb');
2052 2824 // Custom Js ends
@@ -2064,10 +2836,12 @@
2064 2836 $post_type = $current_screen->post_type;
2065 2837 }
2066 2838
2067 2839 $post_id = get_the_ID();
2840 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2068 2841 if(isset($_GET['tag_ID'])){
2069 - $post_id = intval($_GET['tag_ID']);
2842 + //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
2843 + $post_id = intval($_GET['tag_ID']);
2070 2844 }
2071 2845
2072 2846
2073 2847
@@ -2128,13 +2902,18 @@
2128 2902
2129 2903 if ( ! isset( $_POST['wpdbbkp_security_nonce'] ) ){
2130 2904 return;
2131 2905 }
2132 - if ( !wp_verify_nonce( $_POST['wpdbbkp_security_nonce'], 'wpdbbkp-admin-nonce' ) ){
2906 + if ( !wp_verify_nonce( wp_unslash($_POST['wpdbbkp_security_nonce']), 'wpdbbkp-admin-nonce' ) ){ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- used as nonce
2133 2907 return;
2134 - }
2135 - $message = $this->wpdbbkp_sanitize_textarea_field($_POST['message']);
2136 - $email = $this->wpdbbkp_sanitize_textarea_field($_POST['email']);
2908 + }
2909 +
2910 + if( ! current_user_can( 'manage_options' ) ) {
2911 + return;
2912 + }
2913 +
2914 + $message = isset($_POST['message']) ? $this->wpdbbkp_sanitize_textarea_field(wp_unslash($_POST['message'])) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized using custom function
2915 + $email = isset($_POST['email']) ? $this->wpdbbkp_sanitize_textarea_field(wp_unslash($_POST['email'])) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized using custom function
2137 2916
2138 2917 if(function_exists('wp_get_current_user')){
2139 2918
2140 2919 $user = wp_get_current_user();
@@ -2159,13 +2938,13 @@
2159 2938 $sent = wp_mail($sendto, $subject, $message, $headers);
2160 2939
2161 2940 if($sent){
2162 2941
2163 - echo json_encode(array('status'=>'t'));
2942 + echo wp_json_encode(array('status'=>'t'));
2164 2943
2165 2944 }else{
2166 2945
2167 - echo json_encode(array('status'=>'f'));
2946 + echo wp_json_encode(array('status'=>'f'));
2168 2947
2169 2948 }
2170 2949
2171 2950 }
@@ -2173,9 +2952,9 @@
2173 2952 wp_die();
2174 2953 }
2175 2954 public function add_settings_plugin_action_wp( $actions, $plugin_file, $plugin_data, $context ) {
2176 2955 $plugin_actions['settings'] = sprintf(
2177 - '<a href="%s">' . _x( 'Settings', 'wpdbbkp' ) . '</a>',
2956 + '<a href="%s">' . _x( 'Settings', 'Content translation' ,'wpdbbkp' ) . '</a>',
2178 2957 admin_url( 'options-general.php?page=wp-database-backup' )
2179 2958 );
2180 2959 $actions = array_merge( $actions, $plugin_actions );
2181 2960 return $actions;
@@ -2184,10 +2963,10 @@
2184 2963 public function wpdbbkp_update_backup_info($FileName, $logFile, $logMessage = '') {
2185 2964 $path_info = wp_upload_dir();
2186 2965 $filename = $FileName . '.sql';
2187 2966 $WPDBFileName = $FileName . '.zip';
2188 - @unlink($this->wp_db_backup_wp_config_path() . '/' . $filename);
2189 - @unlink($this->wp_db_backup_wp_config_path() . '/wp_installer.php');
2967 + wp_delete_file($this->wp_db_backup_wp_config_path() . '/' . $filename);
2968 + wp_delete_file($this->wp_db_backup_wp_config_path() . '/wp_installer.php');
2190 2969 @$filesize = filesize($path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/' . $WPDBFileName);
2191 2970
2192 2971 $upload_path = array(
2193 2972 'filename' => ($WPDBFileName),
@@ -2211,18 +2990,16 @@
2211 2990 }
2212 2991
2213 2992 private function write_log($logFile, $logMessage) {
2214 2993 // Actually write the log file
2215 - if (is_writable($logFile) || !file_exists($logFile)) {
2994 + global $wp_filesystem;
2995 + if(!function_exists('WP_Filesystem')){
2996 + require_once ( ABSPATH . '/wp-admin/includes/file.php' );
2997 + }
2998 + WP_Filesystem();
2216 2999
2217 - if (!$handle = @fopen($logFile, 'a'))
2218 - return;
2219 -
2220 - if (!fwrite($handle, $logMessage))
2221 - return;
2222 -
2223 - fclose($handle);
2224 -
3000 + if ($wp_filesystem && $wp_filesystem->is_writable($logFile) || !$wp_filesystem->exists($logFile)) {
3001 + $wp_filesystem->put_contents( $logFile, $logMessage, FS_CHMOD_FILE );
2225 3002 return true;
2226 3003 }
2227 3004 }
2228 3005
@@ -2270,10 +3047,8 @@
2270 3047
2271 3048 public function zip($WPDBFileName) {
2272 3049
2273 3050 $this->archive_method = 'zip';
2274 - // var_dump( 'cd ' . escapeshellarg( $this->get_root() ) . ' && ' . escapeshellcmd( $this->get_zip_command_path() ) . ' -rq ' . escapeshellarg( $WPDBFileName ) . ' ./' . ' 2>&1');
2275 - //echo "hi";exit;
2276 3051 $wp_all_backup_exclude_dir = get_option('wp_db_backup_exclude_dir');
2277 3052 if (empty($wp_all_backup_exclude_dir)) {
2278 3053 $excludes = WPDB_BACKUPS_DIR;
2279 3054 } else {
@@ -2280,20 +3055,16 @@
2280 3055 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
2281 3056 }
2282 3057 // Zip up $this->root with excludes
2283 3058 if (!empty($excludes)) {
2284 - // error_log('in exclude rule' . $excludes);
2285 - // var_dump('cd ' . escapeshellarg( $this->get_root() ) . ' && ' . escapeshellcmd( $this->get_zip_command_path() ) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' -x ' . $this->exclude_string( 'zip' ) . ' 2>&1' );exit;
2286 3059 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' -x ' . $this->exclude_string('zip') . ' 2>&1');
2287 3060 }
2288 3061
2289 3062 // Zip up $this->root without excludes
2290 3063 else {
2291 - // error_log('without exclude rule');
3064 +
2292 3065 $stderr = shell_exec('cd ' . escapeshellarg($this->get_root()) . ' && ' . escapeshellcmd($this->get_zip_command_path()) . ' -rq ' . escapeshellarg($WPDBFileName) . ' ./' . ' 2>&1');
2293 3066 }
2294 - error_log($stderr);
2295 - // error_log('cd ' . escapeshellarg( $this->get_root() ) . ' && ' . escapeshellcmd( $this->get_zip_command_path() ) . ' -rq ' . escapeshellarg( $WPDBFileName ) . ' ./' . ' 2>&1');
2296 3067 if (!empty($stderr))
2297 3068 $this->warning($this->get_archive_method(), $stderr);
2298 3069
2299 3070 return $this->verify_archive($WPDBFileName);
@@ -2309,9 +3080,9 @@
2309 3080
2310 3081 public function set_root($path) {
2311 3082
2312 3083 if (empty($path) || !is_string($path) || !is_dir($path))
2313 - throw new Exception('Invalid root path <code>' . $path . '</code> must be a valid directory path');
3084 + throw new Exception('Invalid root path <code>' . esc_html($path) . '</code> must be a valid directory path');
2314 3085
2315 3086 $this->root = self::conform_dir($path);
2316 3087 }
2317 3088
@@ -2359,58 +3130,60 @@
2359 3130 } else {
2360 3131 $excludes = WPDB_BACKUPS_DIR . '|' . $wp_all_backup_exclude_dir;
2361 3132 }
2362 3133
2363 - //$excludes = $this->get_excludes();
2364 3134 $excludes = explode("|", $excludes);
2365 - foreach ($excludes as $key => &$rule) {
3135 + if(!empty($excludes) && is_array($excludes)){
3136 + foreach ($excludes as $key => &$rule) {
2366 3137
2367 - $file = $absolute = $fragment = false;
3138 + $file = $absolute = $fragment = false;
3139 +
3140 + // Files don't end with /
3141 + if (!in_array(substr($rule, -1), array('\\', '/')))
3142 + $file = true;
3143 +
3144 + // If rule starts with a / then treat as absolute path
3145 + elseif (in_array(substr($rule, 0, 1), array('\\', '/')))
3146 + $absolute = true;
3147 +
3148 + // Otherwise treat as dir fragment
3149 + else
3150 + $fragment = true;
3151 +
3152 + // Strip $this->root and conform
3153 + $rule = str_ireplace($this->get_root(), '', untrailingslashit(self::conform_dir($rule)));
3154 +
3155 + // Strip the preceeding slash
3156 + if (in_array(substr($rule, 0, 1), array('\\', '/')))
3157 + $rule = substr($rule, 1);
3158 +
3159 + // Escape string for regex
3160 + if ($context === 'regex')
3161 + $rule = str_replace('.', '\.', $rule);
3162 +
3163 + // Convert any existing wildcards
3164 + if ($wildcard !== '*' && strpos($rule, '*') !== false)
3165 + $rule = str_replace('*', $wildcard, $rule);
3166 +
3167 + // Wrap directory fragments and files in wildcards for zip
3168 + if ($context === 'zip' && ( $fragment || $file ))
3169 + $rule = $wildcard . $rule . $wildcard;
3170 +
3171 + // Add a wildcard to the end of absolute url for zips
3172 + if ($context === 'zip' && $absolute)
3173 + $rule .= $wildcard;
3174 +
3175 + // Add and end carrot to files for pclzip but only if it doesn't end in a wildcard
3176 + if ($file && $context === 'regex')
3177 + $rule .= '$';
3178 +
3179 + // Add a start carrot to absolute urls for pclzip
3180 + if ($absolute && $context === 'regex')
3181 + $rule = '^' . $rule;
3182 + }
3183 + }
3184 +
2368 3185
2369 - // Files don't end with /
2370 - if (!in_array(substr($rule, -1), array('\\', '/')))
2371 - $file = true;
2372 -
2373 - // If rule starts with a / then treat as absolute path
2374 - elseif (in_array(substr($rule, 0, 1), array('\\', '/')))
2375 - $absolute = true;
2376 -
2377 - // Otherwise treat as dir fragment
2378 - else
2379 - $fragment = true;
2380 -
2381 - // Strip $this->root and conform
2382 - $rule = str_ireplace($this->get_root(), '', untrailingslashit(self::conform_dir($rule)));
2383 -
2384 - // Strip the preceeding slash
2385 - if (in_array(substr($rule, 0, 1), array('\\', '/')))
2386 - $rule = substr($rule, 1);
2387 -
2388 - // Escape string for regex
2389 - if ($context === 'regex')
2390 - $rule = str_replace('.', '\.', $rule);
2391 -
2392 - // Convert any existing wildcards
2393 - if ($wildcard !== '*' && strpos($rule, '*') !== false)
2394 - $rule = str_replace('*', $wildcard, $rule);
2395 -
2396 - // Wrap directory fragments and files in wildcards for zip
2397 - if ($context === 'zip' && ( $fragment || $file ))
2398 - $rule = $wildcard . $rule . $wildcard;
2399 -
2400 - // Add a wildcard to the end of absolute url for zips
2401 - if ($context === 'zip' && $absolute)
2402 - $rule .= $wildcard;
2403 -
2404 - // Add and end carrot to files for pclzip but only if it doesn't end in a wildcard
2405 - if ($file && $context === 'regex')
2406 - $rule .= '$';
2407 -
2408 - // Add a start carrot to absolute urls for pclzip
2409 - if ($absolute && $context === 'regex')
2410 - $rule = '^' . $rule;
2411 - }
2412 -
2413 3186 // Escape shell args for zip command
2414 3187 if ($context === 'zip')
2415 3188 $excludes = array_map('escapeshellarg', array_unique($excludes));
2416 3189
@@ -2427,9 +3200,9 @@
2427 3200 return true;
2428 3201
2429 3202 // If there are errors delete the backup file.
2430 3203 if ($this->get_errors($this->get_archive_method()) && file_exists($WPDBFileName))
2431 - unlink($WPDBFileName);
3204 + wp_delete_file($WPDBFileName);
2432 3205
2433 3206 // If the archive file still exists assume it's good
2434 3207 if (file_exists($WPDBFileName))
2435 3208 return $this->archive_verified = true;
@@ -2461,8 +3234,149 @@
2461 3234 }
2462 3235
2463 3236 return $this->files;
2464 3237 }
3238 +
3239 + public function wpdbbkp_get_timeago( $time )
3240 + {
3241 + $time = intval($time) > 0 ? intval($time) : time();
3242 +
3243 + $time_difference = time() - $time;
3244 +
3245 + if( $time_difference < 1 ) { return 'less than 1 second ago'; }
3246 + $condition = array( 12 * 30 * 24 * 60 * 60 => 'year',
3247 + 30 * 24 * 60 * 60 => 'month',
3248 + 24 * 60 * 60 => 'day',
3249 + 60 * 60 => 'hour',
3250 + 60 => 'minute',
3251 + 1 => 'second'
3252 + );
3253 +
3254 + foreach( $condition as $secs => $str )
3255 + {
3256 + $d = $time_difference / $secs;
3257 +
3258 + if( $d >= 1 )
3259 + {
3260 + $t = floor( $d );
3261 + return 'About ' . $t . ' ' . $str . ( $t > 1 ? 's' : '' ) . ' ago';
3262 + }
3263 + }
3264 + }
3265 +
3266 + private function wpdbbkp_append_to_file($file_path, $content_to_append){
3267 + global $wp_filesystem;
3268 +
3269 + if (!function_exists('WP_Filesystem')) {
3270 + require_once ABSPATH . 'wp-admin/includes/file.php';
3271 + }
3272 +
3273 +
3274 + if (empty($wp_filesystem)) {
3275 + WP_Filesystem();
3276 + }
3277 +
3278 + if (!$wp_filesystem) {
3279 + return false;
3280 + }
3281 +
3282 + // Check if the file exists
3283 + if ($wp_filesystem->exists($file_path)) {
3284 + // Open the file in append mode
3285 + $handle = $wp_filesystem->get_contents($file_path);
3286 +
3287 + if ($handle) {
3288 + // Append the new content
3289 + $result = $wp_filesystem->put_contents($file_path, $handle . $content_to_append, FS_CHMOD_FILE);
3290 + return $result !== false;
3291 + }
3292 + } else {
3293 + // If the file doesn't exist, create it with the initial content
3294 + $result = $wp_filesystem->put_contents($file_path, $content_to_append, FS_CHMOD_FILE);
3295 + return $result !== false;
3296 + }
3297 +
3298 + return false;
3299 + }
3300 +
3301 + public function wpdbbkp_cloudbackup_notice(){
3302 + $user_id = get_current_user_id();
3303 + $wpdbbkp_cloudbackup_notice = get_option( 'wpdb_clouddrive_token', false );
3304 +
3305 + if( $wpdbbkp_cloudbackup_notice ){
3306 + return;
3307 + }
3308 + if ( ! current_user_can( 'manage_options' ) ) {
3309 + return;
3310 + }
3311 +
3312 + if ( get_user_meta( $user_id, 'wpdbbkp_cloudbackup_notice_dismissed', true ) ) {
3313 + return;
3314 + }
3315 +
3316 + $nonce = wp_create_nonce( 'wpdbbkp_cloudbackup_notice_dismissed' )
3317 + ?>
3318 + <div class="notice notice-info is-dismissible" id="wpdbbkp_cloudbackup_dismiss">
3319 + <p><?php echo esc_html__('Take a free 14-day trial of BackupforWP Cloud Backup.', 'wpdbbkp').'<a href="'.esc_url('https://backupforwp.com/register?from=plugin_notice').'" target="_blank">'.esc_html__('Get Started in 2 Minutes.', 'wpdbbkp'). '</a>';?></p>
3320 + </div>
3321 + <script type="text/javascript">
3322 + jQuery(document).ready(function($) {
3323 + // Handle dismiss action
3324 + $(document).on('click', '#wpdbbkp_cloudbackup_dismiss .notice-dismiss', function() {
3325 + var ajaxurl = "<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>";
3326 + $.post(ajaxurl, {
3327 + action: 'wpdbbkp_cloudbackup_dismiss_notice',
3328 + nonce: '<?php echo esc_js( $nonce ); ?>'
3329 + });
3330 + });
3331 + });
3332 + </script>
3333 + <?php
3334 + }
3335 + public function wpdbbkp_cloudbackup_dismiss_notice() {
3336 +
3337 +
3338 + if ( ! current_user_can( 'manage_options' ) ) {
3339 + wp_die( esc_html__( 'Permission denied', 'wpdbbkp' ), '', [ 'response' => 403 ] );
3340 + }
3341 +
3342 + // Verify the nonce
3343 + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( wp_unslash( $_POST['nonce'] ), 'wpdbbkp_cloudbackup_notice_dismissed' ) ) { //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- using as nonce
3344 + wp_die( esc_html__( 'Invalid nonce', 'wpdbbkp' ), '', [ 'response' => 403 ] );
3345 + }
3346 +
3347 + $user_id = get_current_user_id();
3348 + update_user_meta( $user_id, 'wpdbbkp_cloudbackup_notice_dismissed', 1 );
3349 + wp_die();
3350 + }
3351 +
3352 + public function admin_backup_file_download() {
3353 + if ( ! current_user_can( 'manage_options' ) ) {
3354 + return;
3355 + }
3356 +
3357 + // Check for a specific query parameter, e.g., ?download_backup=filename.zip
3358 + if ( isset( $_GET['wpdbbkp_download'] ) && ! empty( $_GET['wpdbbkp_download'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
3359 + $path_info = wp_upload_dir();
3360 + $backup_dir = $path_info['basedir'] . '/' . WPDB_BACKUPS_DIR . '/';
3361 + $file_name = basename( sanitize_text_field( wp_unslash( $_GET['wpdbbkp_download'] ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- no form submission
3362 + $file_path = trailingslashit( $backup_dir ) . $file_name;
3363 +
3364 +
3365 + // Check if file exists
3366 + if ( file_exists( $file_path ) ) {
3367 + // Serve the file
3368 + header( 'Content-Description: File Transfer' );
3369 + header( 'Content-Type: application/octet-stream' );
3370 + header( 'Content-Disposition: attachment; filename="' . $file_name . '"' );
3371 + header( 'Content-Length: ' . filesize( $file_path ) );
3372 + readfile( $file_path ); //phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_readfile -- readfile is used to read the file with buffer
3373 + exit;
3374 + } else {
3375 + wp_die( esc_html__( 'Backup file not found.', 'wpdbbkp' ) );
3376 + }
3377 + }
3378 + }
2465 3379
2466 3380 }
2467 3381
2468 3382 new Wpdb_Admin();