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