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