diff -r 34716fd837a4 -r be944660c56a wp/wp-content/plugins/wp-db-backup/wp-db-backup.php --- a/wp/wp-content/plugins/wp-db-backup/wp-db-backup.php Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-content/plugins/wp-db-backup/wp-db-backup.php Wed Sep 21 18:19:35 2022 +0200 @@ -1,88 +1,96 @@ Tools → Backup to get started. -Author: Austin Matzko -Author URI: http://austinmatzko.com/ -Version: 2.3.3 +Author: Delicious Brains +Author URI: https://deliciousbrains.com +Version: 2.4 +Domain Path: /languages Copyright 2018 Austin Matzko (email : austin at pressedcode.com) - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA */ -if ( ! defined('ABSPATH') ) { - die('Please do not load this file directly.'); +if ( ! defined( 'ABSPATH' ) ) { + die( 'Please do not load this file directly.' ); } -$rand = substr( md5( md5( DB_PASSWORD ) ), -5 ); -global $wpdbb_content_dir, $wpdbb_content_url; -$wpdbb_content_dir = ( defined('WP_CONTENT_DIR') ) ? WP_CONTENT_DIR : ABSPATH . 'wp-content'; -$wpdbb_content_url = ( defined('WP_CONTENT_URL') ) ? WP_CONTENT_URL : get_option('siteurl') . '/wp-content'; - -if ( ! defined('ROWS_PER_SEGMENT') ) { - define('ROWS_PER_SEGMENT', 100); +if ( ! defined( 'DBBWP_ROWS_PER_SEGMENT' ) ) { + define( 'DBBWP_ROWS_PER_SEGMENT', 100 ); } /** - * Set MOD_EVASIVE_OVERRIDE to true - * and increase MOD_EVASIVE_DELAY + * Set DBBWP_MOD_EVASIVE_OVERRIDE to true + * and increase DBBWP_MOD_EVASIVE_DELAY * if the backup stops prematurely. */ -// define('MOD_EVASIVE_OVERRIDE', false); -if ( ! defined('MOD_EVASIVE_DELAY') ) { - define('MOD_EVASIVE_DELAY', '500'); +// define('DBBWP_MOD_EVASIVE_OVERRIDE', false); +if ( ! defined( 'DBBWP_MOD_EVASIVE_DELAY' ) ) { + define( 'DBBWP_MOD_EVASIVE_DELAY', '500' ); } class wpdbBackup { var $backup_complete = false; - var $backup_file = ''; + var $backup_file = ''; var $backup_filename; var $core_table_names = array(); - var $errors = array(); + var $errors = array(); var $basename; var $page_url; var $referer_check_key; - var $version = '2.3.3'; + var $version = '2.4'; function module_check() { $mod_evasive = false; - if ( defined( 'MOD_EVASIVE_OVERRIDE' ) && true === MOD_EVASIVE_OVERRIDE ) return true; - if ( ! defined( 'MOD_EVASIVE_OVERRIDE' ) || false === MOD_EVASIVE_OVERRIDE ) return false; - if ( function_exists('apache_get_modules') ) - foreach( (array) apache_get_modules() as $mod ) - if ( false !== strpos($mod,'mod_evasive') || false !== strpos($mod,'mod_dosevasive') ) + + if ( defined( 'DBBWP_MOD_EVASIVE_OVERRIDE' ) && true === DBBWP_MOD_EVASIVE_OVERRIDE ) { + return true; + } + + if ( ! defined( 'DBBWP_MOD_EVASIVE_OVERRIDE' ) || false === DBBWP_MOD_EVASIVE_OVERRIDE ) { + return false; + } + + if ( function_exists( 'apache_get_modules' ) ) { + foreach ( (array) apache_get_modules() as $mod ) { + if ( false !== strpos( $mod, 'mod_evasive' ) || false !== strpos( $mod, 'mod_dosevasive' ) ) { return true; + } + } + } + return false; } function __construct() { global $table_prefix, $wpdb; - add_action('wp_ajax_save_backup_time', array(&$this, 'save_backup_time')); - add_action('init', array(&$this, 'init_textdomain')); - add_action('init', array(&$this, 'set_page_url')); - add_action('admin_init', array(&$this, 'update_notice_action')); - add_action('wp_db_backup_cron', array(&$this, 'cron_backup')); - add_action('wp_cron_daily', array(&$this, 'wp_cron_daily')); - add_filter('cron_schedules', array(&$this, 'add_sched_options')); - add_filter('wp_db_b_schedule_choices', array(&$this, 'schedule_choices')); - $table_prefix = ( isset( $table_prefix ) ) ? $table_prefix : $wpdb->prefix; - $datum = date("Ymd_B"); + add_action( 'wp_ajax_save_backup_time', array( &$this, 'save_backup_time' ) ); + add_action( 'init', array( &$this, 'init_textdomain' ) ); + add_action( 'init', array( &$this, 'set_page_url' ) ); + add_action( 'admin_notices', array( &$this, 'update_notice' ) ); + add_action( 'wp_db_backup_cron', array( &$this, 'cron_backup' ) ); + add_action( 'wp_cron_daily', array( &$this, 'wp_cron_daily' ) ); + add_filter( 'cron_schedules', array( &$this, 'add_sched_options' ) ); + add_filter( 'wp_db_b_schedule_choices', array( &$this, 'schedule_choices' ) ); + + $table_prefix = ( isset( $table_prefix ) ) ? $table_prefix : $wpdb->prefix; + $datum = date( 'Ymd_B' ); $this->backup_filename = DB_NAME . "_$table_prefix$datum.sql"; $possible_names = array( @@ -99,150 +107,167 @@ 'terms', 'term_taxonomy', 'term_relationships', + 'termmeta', 'users', 'usermeta', ); - foreach( $possible_names as $name ) { + foreach ( $possible_names as $name ) { if ( isset( $wpdb->{$name} ) ) { $this->core_table_names[] = $wpdb->{$name}; } } - $requested_temp_dir = sanitize_text_field($_GET['wp_db_temp_dir']); - $this->backup_dir = trailingslashit(apply_filters('wp_db_b_backup_dir', (isset($requested_temp_dir) && is_writable($requested_temp_dir)) ? $requested_temp_dir : get_temp_dir())); - $this->basename = 'wp-db-backup'; + $tmp_dir = get_temp_dir(); + + if ( isset( $_GET['wp_db_temp_dir'] ) ) { + $requested_dir = sanitize_text_field( $_GET['wp_db_temp_dir'] ); + if ( is_writeable( $requested_dir ) ) { + $tmp_dir = $requested_dir; + } + } + + $this->backup_dir = trailingslashit( apply_filters( 'wp_db_b_backup_dir', $tmp_dir ) ); + $this->basename = 'wp-db-backup'; $this->referer_check_key = $this->basename . '-download_' . DB_NAME; - if (isset($_POST['do_backup'])) { - $this->wp_secure('fatal'); - check_admin_referer($this->referer_check_key); - $this->can_user_backup('main'); + if ( isset( $_POST['do_backup'] ) ) { + $this->wp_secure( 'fatal' ); + check_admin_referer( $this->referer_check_key ); + $this->can_user_backup( 'main' ); // save exclude prefs - update_option('wp_db_backup_excs', array( - 'revisions' => $this->get_revisions_to_exclude(), - 'spam' => $this->get_spam_to_exclude() - )); - switch($_POST['do_backup']) { - case 'backup': - add_action('init', array(&$this, 'perform_backup')); - break; - case 'fragments': - add_action('admin_menu', array(&$this, 'fragment_menu')); - break; + update_option( + 'wp_db_backup_excs', + array( + 'revisions' => $this->get_revisions_to_exclude(), + 'spam' => $this->get_spam_to_exclude(), + ) + ); + switch ( $_POST['do_backup'] ) { + case 'backup': + add_action( 'init', array( &$this, 'perform_backup' ) ); + break; + case 'fragments': + add_action( 'admin_menu', array( &$this, 'fragment_menu' ) ); + break; } - } elseif (isset($_GET['fragment'] )) { - $this->can_user_backup('frame'); - add_action('init', array(&$this, 'init')); - } elseif (isset($_GET['backup'] )) { + } elseif ( isset( $_GET['fragment'] ) ) { + $this->can_user_backup( 'frame' ); + add_action( 'init', array( &$this, 'init' ) ); + } elseif ( isset( $_GET['backup'] ) ) { $this->can_user_backup(); - add_action('init', array(&$this, 'init')); + add_action( 'init', array( &$this, 'init' ) ); } else { - add_action('admin_menu', array(&$this, 'admin_menu')); + add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); } } function init() { $this->can_user_backup(); - if (isset($_GET['backup'])) { - $via = isset($_GET['via']) ? sanitize_text_field($_GET['via']) : 'http'; + if ( isset( $_GET['backup'] ) ) { + $via = isset( $_GET['via'] ) ? sanitize_text_field( $_GET['via'] ) : 'http'; - $this->backup_file = sanitize_text_field($_GET['backup']); - $this->validate_file($this->backup_file); + $this->backup_file = sanitize_text_field( $_GET['backup'] ); + $this->validate_file( $this->backup_file ); - switch($via) { - case 'smtp': - case 'email': - $success = $this->deliver_backup($this->backup_file, 'smtp', sanitize_text_field($_GET['recipient']), 'frame'); - $this->error_display( 'frame' ); - if ( $success ) { - echo ' + switch ( $via ) { + case 'smtp': + case 'email': + $success = $this->deliver_backup( $this->backup_file, 'smtp', sanitize_text_field( $_GET['recipient'] ), 'frame' ); + $this->error_display( 'frame' ); + if ( $success ) { + echo ' '; - } - break; - default: - $success = $this->deliver_backup($this->backup_file, $via); - echo $this->error_display( 'frame', false ); + } + break; + default: + $success = $this->deliver_backup( $this->backup_file, $via ); + echo $this->error_display( 'frame', false ); - if ( $success ) { - echo ' + if ( $success ) { + echo ' '; - } + } } exit; } - if (isset($_GET['fragment'] )) { - list($table, $segment, $filename) = explode(':', sanitize_text_field($_GET['fragment'])); - $this->validate_file($filename); - $this->backup_fragment($table, $segment, $filename); + + if ( isset( $_GET['fragment'] ) ) { + list($table, $segment, $filename) = explode( ':', sanitize_text_field( $_GET['fragment'] ) ); + $this->validate_file( $filename ); + $this->backup_fragment( $table, $segment, $filename ); } die(); } function init_textdomain() { - load_plugin_textdomain('wp-db-backup', str_replace(ABSPATH, '', dirname(__FILE__)), dirname(plugin_basename(__FILE__))); + load_plugin_textdomain( + 'wp-db-backup', + false, + dirname( plugin_basename( __FILE__ ) ) . '/languages' + ); } function set_page_url() { $query_args = array( 'page' => $this->basename ); - if ( function_exists('wp_create_nonce') ) - $query_args = array_merge( $query_args, array('_wpnonce' => wp_create_nonce($this->referer_check_key)) ); - $base = ( function_exists('site_url') ) ? site_url('', 'admin') : get_option('siteurl'); - $this->page_url = add_query_arg( $query_args, $base . '/wp-admin/edit.php'); + + if ( function_exists( 'wp_create_nonce' ) ) { + $query_args = array_merge( $query_args, array( '_wpnonce' => wp_create_nonce( $this->referer_check_key ) ) ); + } + + $base = ( function_exists( 'site_url' ) ) ? site_url( '', 'admin' ) : get_option( 'siteurl' ); + $this->page_url = add_query_arg( $query_args, $base . '/wp-admin/edit.php' ); } /* * Add a link to back up your database when doing a core upgrade. */ - function update_notice_action() { + function update_notice() { global $pagenow; - if ( - ( - isset($_REQUEST['action']) - && ('upgrade-core' == $_REQUEST['action']) - ) - || ( - !empty($pagenow) && ('update-core.php' == $pagenow) - ) - ) : - ob_start(array(&$this, 'update_notice')); - add_action('admin_footer', create_function('', 'ob_end_flush();')); - endif; - } - function update_notice($text = '') { - $pattern = '#(.*?

)#'; - $replace = '$1' . "\n

" . sprintf(__('Click here to back up your database using the WordPress Database Backup plugin. Note: WordPress Database Backup does not back up your files, just your database.', 'wp-db-backup'), 'tools.php?page=wp-db-backup') . "

\n"; - $text = preg_replace($pattern, $replace, $text); - return $text; + if ( empty( $pagenow ) || 'update-core.php' !== $pagenow ) { + return false; + } + ?> +
+

+ here to back up your database using the WordPress Database Backup plugin. Note: WordPress Database Backup does not back up your files, just your database.', 'wp-db-backup' ), + esc_url( get_admin_url( null, 'tools.php?page=wp-db-backup' ) ) + ); + ?> +

+
+ "; - echo '
' . __('Progress','wp-db-backup') . ' + echo '
' . __( 'Progress', 'wp-db-backup' ) . '

' . - __('DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:','wp-db-backup'). + __( 'DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:', 'wp-db-backup' ) . '

    -
  1. '.__('Close this browser','wp-db-backup').'
  2. -
  3. '.__('Reload this page','wp-db-backup').'
  4. -
  5. '.__('Click the Stop or Back buttons in your browser','wp-db-backup').'
  6. +
  7. ' . __( 'Close this browser', 'wp-db-backup' ) . '
  8. +
  9. ' . __( 'Reload this page', 'wp-db-backup' ) . '
  10. +
  11. ' . __( 'Click the Stop or Back buttons in your browser', 'wp-db-backup' ) . '
-

' . __('Progress:','wp-db-backup') . '

+

' . __( 'Progress:', 'wp-db-backup' ) . '

 
@@ -251,7 +276,7 @@ - basename, array(&$this, 'backup_menu')); - add_action('load-' . $_page_hook, array(&$this, 'admin_load')); - if (function_exists('get_current_screen')) { - $screen = convert_to_screen($_page_hook); - if (method_exists($screen,'add_help_tab')) { - $screen->add_help_tab(array( - 'title' => __('Backup','wp-db-backup'), - 'id' => $_page_hook, - 'content' => $this->help_menu(), - )); + $_page_hook = add_management_page( __( 'Backup', 'wp-db-backup' ), __( 'Backup', 'wp-db-backup' ), 'import', $this->basename, array( &$this, 'backup_menu' ) ); + add_action( 'load-' . $_page_hook, array( &$this, 'admin_load' ) ); + if ( function_exists( 'get_current_screen' ) ) { + $screen = convert_to_screen( $_page_hook ); + if ( method_exists( $screen, 'add_help_tab' ) ) { + $screen->add_help_tab( + array( + 'title' => __( 'Backup', 'wp-db-backup' ), + 'id' => $_page_hook, + 'content' => $this->help_menu(), + ) + ); } - } elseif ( function_exists('add_contextual_help') ) { + } elseif ( function_exists( 'add_contextual_help' ) ) { $text = $this->help_menu(); - add_contextual_help($_page_hook, $text); + add_contextual_help( $_page_hook, $text ); } } function fragment_menu() { - $page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', $this->basename, array(&$this, 'build_backup_script')); - add_action('load-' . $page_hook, array(&$this, 'admin_load')); + $page_hook = add_management_page( __( 'Backup', 'wp-db-backup' ), __( 'Backup', 'wp-db-backup' ), 'import', $this->basename, array( &$this, 'build_backup_script' ) ); + add_action( 'load-' . $page_hook, array( &$this, 'admin_load' ) ); } /** @@ -638,26 +647,26 @@ * @return string The text of the help menu. */ function help_menu() { - $text = "\n" . __('FAQ', 'wp-db-backup') . ''; + $text = "\n" . __( 'FAQ', 'wp-db-backup' ) . ''; return $text; } function save_backup_time() { if ( $this->can_user_backup() ) { // try to get a time from the input string - $time = strtotime(strval($_POST['backup-time'])); + $time = strtotime( strval( $_POST['backup-time'] ) ); if ( ! empty( $time ) && time() < $time ) { wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous $scheds = (array) wp_get_schedules(); - $name = get_option('wp_cron_backup_schedule'); + $name = get_option( 'wp_cron_backup_schedule' ); if ( 0 != $time ) { - wp_schedule_event($time, $name, 'wp_db_backup_cron'); - echo gmdate(get_option('date_format') . ' ' . get_option('time_format'), $time + (get_option('gmt_offset') * 3600)); + wp_schedule_event( $time, $name, 'wp_db_backup_cron' ); + echo gmdate( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time + ( get_option( 'gmt_offset' ) * 3600 ) ); exit; } } } else { - die(0); + die( 0 ); } } @@ -665,23 +674,28 @@ * Better addslashes for SQL queries. * Taken from phpMyAdmin. */ - function sql_addslashes($a_string = '', $is_like = false) { - if ($is_like) $a_string = str_replace('\\', '\\\\\\\\', $a_string); - else $a_string = str_replace('\\', '\\\\', $a_string); - return str_replace('\'', '\\\'', $a_string); + function sql_addslashes( $a_string = '', $is_like = false ) { + if ( $is_like ) { + $a_string = str_replace( '\\', '\\\\\\\\', $a_string ); + } else { + $a_string = str_replace( '\\', '\\\\', $a_string ); + } + + return str_replace( '\'', '\\\'', $a_string ); } /** * Add backquotes to tables and db-names in * SQL queries. Taken from phpMyAdmin. */ - function backquote($a_name) { - if (!empty($a_name) && $a_name != '*') { - if (is_array($a_name)) { + function backquote( $a_name ) { + if ( ! empty( $a_name ) && $a_name != '*' ) { + if ( is_array( $a_name ) ) { $result = array(); - reset($a_name); - while(list($key, $val) = each($a_name)) - $result[$key] = '`' . $val . '`'; + reset( $a_name ); + while ( list($key, $val) = each( $a_name ) ) { + $result[ $key ] = '`' . $val . '`'; + } return $result; } else { return '`' . $a_name . '`'; @@ -691,14 +705,16 @@ } } - function open($filename = '', $mode = 'w') { - if ('' == $filename) return false; - $fp = @fopen($filename, $mode); + function open( $filename = '', $mode = 'w' ) { + if ( '' == $filename ) { + return false; + } + $fp = @fopen( $filename, $mode ); return $fp; } - function close($fp) { - fclose($fp); + function close( $fp ) { + fclose( $fp ); } /** @@ -706,9 +722,10 @@ * @param string $query_line the line to write * @return null */ - function stow($query_line) { - if(false === @fwrite($this->fp, $query_line)) - $this->error(__('There was an error writing a line to the backup script:','wp-db-backup') . ' ' . $query_line . ' ' . $php_errormsg); + function stow( $query_line ) { + if ( false === @fwrite( $this->fp, $query_line ) ) { + $this->error( __( 'There was an error writing a line to the backup script:', 'wp-db-backup' ) . ' ' . $query_line . ' ' . $php_errormsg ); + } } /** @@ -716,13 +733,26 @@ * @param array $args * @return bool */ - function error($args = array()) { - if ( is_string( $args ) ) - $args = array('msg' => $args); - $args = array_merge( array('loc' => 'main', 'kind' => 'warn', 'msg' => ''), $args); - $this->errors[$args['kind']][] = $args['msg']; - if ( 'fatal' == $args['kind'] || 'frame' == $args['loc']) - $this->error_display($args['loc']); + function error( $args = array() ) { + if ( is_string( $args ) ) { + $args = array( 'msg' => $args ); + } + + $args = array_merge( + array( + 'loc' => 'main', + 'kind' => 'warn', + 'msg' => '', + ), + $args + ); + + $this->errors[ $args['kind'] ][] = $args['msg']; + + if ( 'fatal' == $args['kind'] || 'frame' == $args['loc'] ) { + $this->error_display( $args['loc'] ); + } + return true; } @@ -732,30 +762,46 @@ * @param string $loc * @return string */ - function error_display($loc = 'main', $echo = true) { + function error_display( $loc = 'main', $echo = true ) { $errs = $this->errors; unset( $this->errors ); - if ( ! count($errs) ) return; - $msg = ''; + + if ( ! count( $errs ) ) { + return; + } + + $msg = ''; $errs['fatal'] = isset( $errs['fatal'] ) ? (array) $errs['fatal'] : array(); - $errs['warn'] = isset( $errs['warn'] ) ? (array) $errs['warn'] : array(); - $err_list = array_slice( array_merge( $errs['fatal'], $errs['warn'] ), 0, 10); - if ( 10 == count( $err_list ) ) - $err_list[9] = __('Subsequent errors have been omitted from this log.','wp-db-backup'); + $errs['warn'] = isset( $errs['warn'] ) ? (array) $errs['warn'] : array(); + $err_list = array_slice( array_merge( $errs['fatal'], $errs['warn'] ), 0, 10 ); + + if ( 10 == count( $err_list ) ) { + $err_list[9] = __( 'Subsequent errors have been omitted from this log.', 'wp-db-backup' ); + } + $wrap = ( 'frame' == $loc ) ? "" : '%1$s'; $line = ( 'frame' == $loc ) ? "try{ window.parent.addError('%1\$s'); } catch(e) { msgList += ' %1\$s';}\n" : "%1\$s
\n"; - foreach( (array) $err_list as $err ) - $msg .= sprintf($line,str_replace(array("\n","\r"), '', addslashes($err))); - $msg = sprintf($wrap,$msg); - if ( count($errs['fatal'] ) ) { - if ( function_exists('wp_die') && 'frame' != $loc ) wp_die(stripslashes($msg)); - else die($msg); + + foreach ( (array) $err_list as $err ) { + $msg .= sprintf( $line, str_replace( array( "\n", "\r" ), '', addslashes( $err ) ) ); } - else { - if ( $echo ) echo $msg; - else return $msg; + + $msg = sprintf( $wrap, $msg ); + + if ( count( $errs['fatal'] ) ) { + if ( function_exists( 'wp_die' ) && 'frame' != $loc ) { + wp_die( stripslashes( $msg ) ); + } else { + die( $msg ); + } + } else { + if ( $echo ) { + echo $msg; + } else { + return $msg; + } } } @@ -770,165 +816,171 @@ * @param string $segment * @return void */ - function backup_table($table, $segment = 'none') { + function backup_table( $table, $segment = 'none' ) { global $wpdb; - $table_structure = $wpdb->get_results("DESCRIBE $table"); - if (! $table_structure) { - $this->error(__('Error getting table details','wp-db-backup') . ": $table"); + $table_structure = $wpdb->get_results( "DESCRIBE $table" ); + if ( ! $table_structure ) { + $this->error( __( 'Error getting table details', 'wp-db-backup' ) . ": $table" ); return false; } - if(($segment == 'none') || ($segment == 0)) { + if ( ( $segment == 'none' ) || ( $segment == 0 ) ) { // Add SQL statement to drop existing table - $this->stow("\n\n"); - $this->stow("#\n"); - $this->stow("# " . sprintf(__('Delete any existing table %s','wp-db-backup'),$this->backquote($table)) . "\n"); - $this->stow("#\n"); - $this->stow("\n"); - $this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n"); + $this->stow( "\n\n" ); + $this->stow( "#\n" ); + $this->stow( '# ' . sprintf( __( 'Delete any existing table %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "#\n" ); + $this->stow( "\n" ); + $this->stow( 'DROP TABLE IF EXISTS ' . $this->backquote( $table ) . ";\n" ); // Table structure // Comment in SQL-file - $this->stow("\n\n"); - $this->stow("#\n"); - $this->stow("# " . sprintf(__('Table structure of table %s','wp-db-backup'),$this->backquote($table)) . "\n"); - $this->stow("#\n"); - $this->stow("\n"); + $this->stow( "\n\n" ); + $this->stow( "#\n" ); + $this->stow( '# ' . sprintf( __( 'Table structure of table %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "#\n" ); + $this->stow( "\n" ); - $create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N); - if (false === $create_table) { - $err_msg = sprintf(__('Error with SHOW CREATE TABLE for %s.','wp-db-backup'), $table); - $this->error($err_msg); - $this->stow("#\n# $err_msg\n#\n"); + $create_table = $wpdb->get_results( "SHOW CREATE TABLE $table", ARRAY_N ); + if ( false === $create_table ) { + $err_msg = sprintf( __( 'Error with SHOW CREATE TABLE for %s.', 'wp-db-backup' ), $table ); + $this->error( $err_msg ); + $this->stow( "#\n# $err_msg\n#\n" ); } - $this->stow($create_table[0][1] . ' ;'); + $this->stow( $create_table[0][1] . ' ;' ); - if (false === $table_structure) { - $err_msg = sprintf(__('Error getting table structure of %s','wp-db-backup'), $table); - $this->error($err_msg); - $this->stow("#\n# $err_msg\n#\n"); + if ( false === $table_structure ) { + $err_msg = sprintf( __( 'Error getting table structure of %s', 'wp-db-backup' ), $table ); + $this->error( $err_msg ); + $this->stow( "#\n# $err_msg\n#\n" ); } // Comment in SQL-file - $this->stow("\n\n"); - $this->stow("#\n"); - $this->stow('# ' . sprintf(__('Data contents of table %s','wp-db-backup'),$this->backquote($table)) . "\n"); - $this->stow("#\n"); + $this->stow( "\n\n" ); + $this->stow( "#\n" ); + $this->stow( '# ' . sprintf( __( 'Data contents of table %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "#\n" ); } - if(($segment == 'none') || ($segment >= 0)) { + if ( ( $segment == 'none' ) || ( $segment >= 0 ) ) { $defs = array(); $ints = array(); - foreach ($table_structure as $struct) { - if ( (0 === strpos($struct->Type, 'tinyint')) || - (0 === strpos(strtolower($struct->Type), 'smallint')) || - (0 === strpos(strtolower($struct->Type), 'mediumint')) || - (0 === strpos(strtolower($struct->Type), 'int')) || - (0 === strpos(strtolower($struct->Type), 'bigint')) ) { - $defs[strtolower($struct->Field)] = ( null === $struct->Default ) ? 'NULL' : $struct->Default; - $ints[strtolower($struct->Field)] = "1"; + foreach ( $table_structure as $struct ) { + if ( ( 0 === strpos( $struct->Type, 'tinyint' ) ) || + ( 0 === strpos( strtolower( $struct->Type ), 'smallint' ) ) || + ( 0 === strpos( strtolower( $struct->Type ), 'mediumint' ) ) || + ( 0 === strpos( strtolower( $struct->Type ), 'int' ) ) || + ( 0 === strpos( strtolower( $struct->Type ), 'bigint' ) ) ) { + $defs[ strtolower( $struct->Field ) ] = ( null === $struct->Default ) ? 'NULL' : $struct->Default; + $ints[ strtolower( $struct->Field ) ] = '1'; } } - // Batch by $row_inc - if($segment == 'none') { + if ( $segment == 'none' ) { $row_start = 0; - $row_inc = ROWS_PER_SEGMENT; + $row_inc = DBBWP_ROWS_PER_SEGMENT; } else { - $row_start = $segment * ROWS_PER_SEGMENT; - $row_inc = ROWS_PER_SEGMENT; + $row_start = $segment * DBBWP_ROWS_PER_SEGMENT; + $row_inc = DBBWP_ROWS_PER_SEGMENT; } do { // don't include extra stuff, if so requested - $excs = (array) get_option('wp_db_backup_excs'); + $excs = (array) get_option( 'wp_db_backup_excs' ); $where = ''; - if ( is_array($excs['spam'] ) && in_array($table, $excs['spam']) ) { - $where = ' WHERE comment_approved != "spam"'; - } elseif ( is_array($excs['revisions'] ) && in_array($table, $excs['revisions']) ) { - $where = ' WHERE post_type != "revision"'; + + if ( is_array( $excs['spam'] ) && in_array( $table, $excs['spam'] ) ) { + $where = " WHERE comment_approved != 'spam'"; + } elseif ( is_array( $excs['revisions'] ) && in_array( $table, $excs['revisions'] ) ) { + $where = " WHERE post_type != 'revision'"; } - if ( !ini_get('safe_mode')) @set_time_limit(15*60); - $table_data = $wpdb->get_results("SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A); + if ( ! ini_get( 'safe_mode' ) ) { + @set_time_limit( 15 * 60 ); + } + $table_data = $wpdb->get_results( "SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A ); - $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES ('; + $entries = 'INSERT INTO ' . $this->backquote( $table ) . ' VALUES ('; // \x08\\x09, not required - $search = array("\x00", "\x0a", "\x0d", "\x1a"); - $replace = array('\0', '\n', '\r', '\Z'); - if($table_data) { - foreach ($table_data as $row) { + $search = array( "\x00", "\x0a", "\x0d", "\x1a" ); + $replace = array( '\0', '\n', '\r', '\Z' ); + + if ( $table_data ) { + foreach ( $table_data as $row ) { $values = array(); - foreach ($row as $key => $value) { - if ( !empty($ints[strtolower($key)]) ) { + foreach ( $row as $key => $value ) { + if ( ! empty( $ints[ strtolower( $key ) ] ) ) { // make sure there are no blank spots in the insert syntax, // yet try to avoid quotation marks around integers - $value = ( null === $value || '' === $value) ? $defs[strtolower($key)] : $value; + $value = ( null === $value || '' === $value ) ? $defs[ strtolower( $key ) ] : $value; $values[] = ( '' === $value ) ? "''" : $value; } else { - $values[] = "'" . str_replace($search, $replace, $this->sql_addslashes($value)) . "'"; + $values[] = "'" . str_replace( $search, $replace, $this->sql_addslashes( $value ) ) . "'"; } } - $this->stow(" \n" . $entries . implode(', ', $values) . ');'); + $this->stow( " \n" . $entries . implode( ', ', $values ) . ');' ); } $row_start += $row_inc; } - } while((count($table_data) > 0) and ($segment=='none')); + } while ( ( count( $table_data ) > 0 ) and ( $segment == 'none' ) ); } - if(($segment == 'none') || ($segment < 0)) { + if ( ( $segment == 'none' ) || ( $segment < 0 ) ) { // Create footer/closing comment in SQL-file - $this->stow("\n"); - $this->stow("#\n"); - $this->stow("# " . sprintf(__('End of data contents of table %s','wp-db-backup'),$this->backquote($table)) . "\n"); - $this->stow("# --------------------------------------------------------\n"); - $this->stow("\n"); + $this->stow( "\n" ); + $this->stow( "#\n" ); + $this->stow( '# ' . sprintf( __( 'End of data contents of table %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "# --------------------------------------------------------\n" ); + $this->stow( "\n" ); } } // end backup_table() - function db_backup($core_tables, $other_tables) { + function db_backup( $core_tables, $other_tables ) { global $table_prefix, $wpdb; - if (is_writable($this->backup_dir)) { - $this->fp = $this->open($this->backup_dir . $this->backup_filename); - if(!$this->fp) { - $this->error(__('Could not open the backup file for writing!','wp-db-backup')); + if ( is_writable( $this->backup_dir ) ) { + $this->fp = $this->open( $this->backup_dir . $this->backup_filename ); + if ( ! $this->fp ) { + $this->error( __( 'Could not open the backup file for writing!', 'wp-db-backup' ) ); return false; } } else { - $this->error(__('The backup directory is not writeable!','wp-db-backup')); + $this->error( __( 'The backup directory is not writeable!', 'wp-db-backup' ) ); return false; } //Begin new backup of MySql - $this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n"); - $this->stow("#\n"); - $this->stow("# " . sprintf(__('Generated: %s','wp-db-backup'),date("l j. F Y H:i T")) . "\n"); - $this->stow("# " . sprintf(__('Hostname: %s','wp-db-backup'),DB_HOST) . "\n"); - $this->stow("# " . sprintf(__('Database: %s','wp-db-backup'),$this->backquote(DB_NAME)) . "\n"); - $this->stow("# --------------------------------------------------------\n"); + $this->stow( '# ' . __( 'WordPress MySQL database backup', 'wp-db-backup' ) . "\n" ); + $this->stow( "#\n" ); + $this->stow( '# ' . sprintf( __( 'Generated: %s', 'wp-db-backup' ), date( 'l j. F Y H:i T' ) ) . "\n" ); + $this->stow( '# ' . sprintf( __( 'Hostname: %s', 'wp-db-backup' ), DB_HOST ) . "\n" ); + $this->stow( '# ' . sprintf( __( 'Database: %s', 'wp-db-backup' ), $this->backquote( DB_NAME ) ) . "\n" ); + $this->stow( "# --------------------------------------------------------\n" ); - if ( (is_array($other_tables)) && (count($other_tables) > 0) ) - $tables = array_merge($core_tables, $other_tables); - else + if ( ( is_array( $other_tables ) ) && ( count( $other_tables ) > 0 ) ) { + $tables = array_merge( $core_tables, $other_tables ); + } else { $tables = $core_tables; - - foreach ($tables as $table) { - // Increase script execution time-limit to 15 min for every table. - if ( !ini_get('safe_mode')) @set_time_limit(15*60); - // Create the SQL statements - $this->stow("# --------------------------------------------------------\n"); - $this->stow("# " . sprintf(__('Table: %s','wp-db-backup'),$this->backquote($table)) . "\n"); - $this->stow("# --------------------------------------------------------\n"); - $this->backup_table($table); } - $this->close($this->fp); + foreach ( $tables as $table ) { + // Increase script execution time-limit to 15 min for every table. + if ( ! ini_get( 'safe_mode' ) ) { + @set_time_limit( 15 * 60 ); + } + // Create the SQL statements + $this->stow( "# --------------------------------------------------------\n" ); + $this->stow( '# ' . sprintf( __( 'Table: %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); + $this->stow( "# --------------------------------------------------------\n" ); + $this->backup_table( $table ); + } - if (count($this->errors)) { + $this->close( $this->fp ); + + if ( count( $this->errors ) ) { return false; } else { return $this->backup_filename; @@ -938,443 +990,426 @@ /** * Sends the backed-up file via email + * * @param string $to * @param string $subject * @param string $message + * @param string $diskfile + * * @return bool */ - function send_mail( $to, $subject, $message, $diskfile) { - global $phpmailer; + function send_mail( $to, $subject, $message, $diskfile ) { + return wp_mail( $to, $subject, $message, array(), array( $diskfile ) ); + } - $filename = basename($diskfile); + function deliver_backup( $filename = '', $delivery = 'http', $recipient = '', $location = 'main' ) { + if ( '' == $filename ) { + return false; } - extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message' ) ) ); + $diskfile = $this->backup_dir . $filename; + $gz_diskfile = "{$diskfile}.gz"; + $retry = isset( $_GET['download-retry'] ); + $success = false; - if ( !is_object( $phpmailer ) || ( strtolower(get_class( $phpmailer )) != 'phpmailer' ) ) { - if ( file_exists( ABSPATH . WPINC . '/class-phpmailer.php' ) ) - require_once ABSPATH . WPINC . '/class-phpmailer.php'; - if ( file_exists( ABSPATH . WPINC . '/class-smtp.php' ) ) - require_once ABSPATH . WPINC . '/class-smtp.php'; - if ( class_exists( 'PHPMailer') ) - $phpmailer = new PHPMailer(); + // Try to gzip the file if we can. + if ( file_exists( $diskfile ) && ! file_exists( $gz_diskfile ) && ! $retry ) { + if ( function_exists( 'gzencode' ) && function_exists( 'file_get_contents' ) ) { + // Try upping the memory limit before gzipping + if ( function_exists( 'memory_get_usage' ) && ( (int) @ini_get( 'memory_limit' ) < 64 ) ) { + @ini_set( 'memory_limit', '64M' ); + } + + $contents = file_get_contents( $diskfile ); + $gzipped = gzencode( $contents, 9 ); + $fp = fopen( $gz_diskfile, 'w' ); + + fwrite( $fp, $gzipped ); + + if ( fclose( $fp ) ) { + unlink( $diskfile ); + } + } } - // try to use phpmailer directly (WP 2.2+) - if ( is_object( $phpmailer ) && ( strtolower(get_class( $phpmailer )) == 'phpmailer' ) ) { - - // Get the site domain and get rid of www. - $sitename = $this->get_sitename(); - $from_email = 'wordpress@' . $sitename; - $from_name = 'WordPress'; - - // Empty out the values that may be set - $phpmailer->ClearAddresses(); - $phpmailer->ClearAllRecipients(); - $phpmailer->ClearAttachments(); - $phpmailer->ClearBCCs(); - $phpmailer->ClearCCs(); - $phpmailer->ClearCustomHeaders(); - $phpmailer->ClearReplyTos(); - - $phpmailer->AddAddress( $to ); - $phpmailer->AddAttachment($diskfile, $filename); - $phpmailer->Body = $message; - $phpmailer->CharSet = apply_filters( 'wp_mail_charset', get_bloginfo('charset') ); - $phpmailer->From = apply_filters( 'wp_mail_from', $from_email ); - $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name ); - $phpmailer->IsMail(); - $phpmailer->Subject = $subject; - - do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); - - $result = @$phpmailer->Send(); - - // old-style: build the headers directly + if ( file_exists( $gz_diskfile ) ) { + $filename = $filename . '.gz'; + $file_to_deliver = $gz_diskfile; } else { - $randomish = md5(time()); - $boundary = "==WPBACKUP-$randomish"; - $fp = fopen($diskfile,"rb"); - $file = fread($fp,filesize($diskfile)); - $this->close($fp); - - $data = chunk_split(base64_encode($file)); - - $headers .= "MIME-Version: 1.0\n"; - $headers = 'From: wordpress@' . preg_replace('#^www\.#', '', sanitize_text_field(strtolower($_SERVER['SERVER_NAME']))) . "\n"; - $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n"; - - // Add a multipart boundary above the plain message - $message = "This is a multi-part message in MIME format.\n\n" . - "--{$boundary}\n" . - "Content-Type: text/plain; charset=\"" . get_bloginfo('charset') . "\"\n" . - "Content-Transfer-Encoding: 7bit\n\n" . - $message . "\n\n"; - - // Add file attachment to the message - $message .= "--{$boundary}\n" . - "Content-Type: application/octet-stream;\n" . - " name=\"{$filename}\"\n" . - "Content-Disposition: attachment;\n" . - " filename=\"{$filename}\"\n" . - "Content-Transfer-Encoding: base64\n\n" . - $data . "\n\n" . - "--{$boundary}--\n"; - - $result = @wp_mail($to, $subject, $message, $headers); - } - return $result; - - } - - function deliver_backup($filename = '', $delivery = 'http', $recipient = '', $location = 'main') { - if ('' == $filename) { return false; } - - $diskfile = $this->backup_dir . $filename; - $gz_diskfile = "{$diskfile}.gz"; - - /** - * Try upping the memory limit before gzipping - */ - if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < 64 ) ) { - @ini_set('memory_limit', '64M' ); + $file_to_deliver = $diskfile; } - if ( file_exists( $diskfile ) && empty( $_GET['download-retry'] ) ) { - /** - * Try gzipping with an external application - */ - if ( file_exists( $diskfile ) && ! file_exists( $gz_diskfile ) ) { - @exec( "gzip $diskfile" ); - } - - if ( file_exists( $gz_diskfile ) ) { - if ( file_exists( $diskfile ) ) { - unlink($diskfile); - } - $diskfile = $gz_diskfile; - $filename = "{$filename}.gz"; - - /** - * Try to compress to gzip, if available - */ - } else { - if ( function_exists('gzencode') ) { - if ( function_exists('file_get_contents') ) { - $text = file_get_contents($diskfile); - } else { - $text = implode("", file($diskfile)); - } - $gz_text = gzencode($text, 9); - $fp = fopen($gz_diskfile, "w"); - fwrite($fp, $gz_text); - if ( fclose($fp) ) { - unlink($diskfile); - $diskfile = $gz_diskfile; - $filename = "{$filename}.gz"; - } - } - } - /* - * - */ - } elseif ( file_exists( $gz_diskfile ) && empty( $_GET['download-retry'] ) ) { - $diskfile = $gz_diskfile; - $filename = "{$filename}.gz"; - } - - if ('http' == $delivery) { - if ( ! file_exists( $diskfile ) ) { - if ( empty( $_GET['download-retry'] ) ) { - $this->error(array('kind' => 'fatal', 'msg' => sprintf(__('File not found:%s','wp-db-backup'), " $filename
") . '
' . __('Return to Backup','wp-db-backup') . '')); + if ( 'http' == $delivery ) { + if ( ! file_exists( $file_to_deliver ) ) { + if ( ! $retry ) { + $this->error( + array( + 'kind' => 'fatal', + 'msg' => sprintf( + __( + 'File not found:%s', + 'wp-db-backup' + ), + " $filename
" + ) . '
' . __( + 'Return to Backup', + 'wp-db-backup' + ) . '', + ) + ); } else { return true; } - } elseif ( file_exists( $diskfile ) ) { - header('Content-Description: File Transfer'); - header('Content-Type: application/octet-stream'); - header('Content-Length: ' . filesize($diskfile)); - header("Content-Disposition: attachment; filename=$filename"); - $success = readfile($diskfile); + } else { + header( 'Content-Description: File Transfer' ); + header( 'Content-Type: application/octet-stream' ); + header( 'Content-Length: ' . filesize( $file_to_deliver ) ); + header( "Content-Disposition: attachment; filename=$filename" ); + $success = readfile( $file_to_deliver ); if ( $success ) { - unlink($diskfile); + unlink( $file_to_deliver ); } } - } elseif ('smtp' == $delivery) { - if (! file_exists($diskfile)) { - $msg = sprintf(__('File %s does not exist!','wp-db-backup'), $diskfile); - $this->error($msg); + } elseif ( 'smtp' == $delivery ) { + if ( ! file_exists( $file_to_deliver ) ) { + $msg = sprintf( __( 'File %s does not exist!', 'wp-db-backup' ), $file_to_deliver ); + $this->error( $msg ); return false; } - if (! is_email($recipient)) { - $recipient = get_option('admin_email'); + + if ( ! is_email( $recipient ) ) { + $recipient = get_option( 'admin_email' ); } - $message = sprintf(__("Attached to this email is\n %1s\n Size:%2s kilobytes\n",'wp-db-backup'), $filename, round(filesize($diskfile)/1024)); - $success = $this->send_mail($recipient, get_bloginfo('name') . ' ' . __('Database Backup','wp-db-backup'), $message, $diskfile); + + $message = sprintf( __( "Attached to this email is\n %1\$1s\n Size:%2\$2s kilobytes\n", 'wp-db-backup' ), $filename, round( filesize( $file_to_deliver ) / 1024 ) ); + $success = $this->send_mail( $recipient, get_bloginfo( 'name' ) . ' ' . __( 'Database Backup', 'wp-db-backup' ), $message, $file_to_deliver ); if ( false === $success ) { - $msg = __('The following errors were reported:','wp-db-backup') . "\n "; - if ( function_exists('error_get_last') ) { - $err = error_get_last(); + $msg = __( 'The following errors were reported:', 'wp-db-backup' ) . "\n "; + if ( function_exists( 'error_get_last' ) ) { + $err = error_get_last(); $msg .= $err['message']; } else { - $msg .= __('ERROR: The mail application has failed to deliver the backup.','wp-db-backup'); + $msg .= __( 'ERROR: The mail application has failed to deliver the backup.', 'wp-db-backup' ); } - $this->error(array('kind' => 'fatal', 'loc' => $location, 'msg' => $msg)); + $this->error( + array( + 'kind' => 'fatal', + 'loc' => $location, + 'msg' => $msg, + ) + ); } else { - if ( file_exists( $diskfile ) ) { - unlink($diskfile); + if ( file_exists( $file_to_deliver ) ) { + unlink( $file_to_deliver ); } } } + return $success; } function backup_menu() { global $table_prefix, $wpdb; $feedback = ''; - $whoops = false; + $whoops = false; // did we just do a backup? If so, let's report the status if ( $this->backup_complete ) { - $feedback = '

' . __('Backup Successful','wp-db-backup') . '!'; - $file = $this->backup_file; - switch($_POST['deliver']) { - case 'http': - $feedback .= '
' . sprintf(__('Your backup file: %2s should begin downloading shortly.','wp-db-backup'), "{$this->backup_file}", $this->backup_file); - break; - case 'smtp': - $email = sanitize_text_field(wp_unslash($_POST['backup_recipient'])); - if (! is_email($email)) { - $feedback .= get_option('admin_email'); - } else { - $feedback .= $email; - } - $feedback = '
' . sprintf(__('Your backup has been emailed to %s','wp-db-backup'), $feedback); - break; + $feedback = '

' . __( 'Backup Successful', 'wp-db-backup' ) . '!'; + $file = $this->backup_file; + switch ( $_POST['deliver'] ) { + case 'http': + $feedback .= '
' . sprintf( __( 'Your backup file: %2s should begin downloading shortly.', 'wp-db-backup' ), "{$this->backup_file}", $this->backup_file ); + break; + case 'smtp': + $email = sanitize_text_field( wp_unslash( $_POST['backup_recipient'] ) ); + if ( ! is_email( $email ) ) { + $feedback .= get_option( 'admin_email' ); + } else { + $feedback .= $email; + } + $feedback = '
' . sprintf( __( 'Your backup has been emailed to %s', 'wp-db-backup' ), $feedback ); + break; } + $feedback .= '

'; } // security check $this->wp_secure(); - if (count($this->errors)) { - $feedback .= '

' . __('The following errors were reported:','wp-db-backup') . '

'; + if ( count( $this->errors ) ) { + $feedback .= '

' . __( 'The following errors were reported:', 'wp-db-backup' ) . '

'; $feedback .= '

' . $this->error_display( 'main', false ) . '

'; - $feedback .= "

"; + $feedback .= '

'; } // did we just save options for wp-cron? - if ( (function_exists('wp_schedule_event') || function_exists('wp_cron_init')) - && isset($_POST['wp_cron_backup_options']) ) : - do_action('wp_db_b_update_cron_options'); - if ( function_exists('wp_schedule_event') ) { + if ( ( function_exists( 'wp_schedule_event' ) || function_exists( 'wp_cron_init' ) ) && isset( $_POST['wp_cron_backup_options'] ) ) : + do_action( 'wp_db_b_update_cron_options' ); + + if ( function_exists( 'wp_schedule_event' ) ) { wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous - $scheds = (array) wp_get_schedules(); - $name = sanitize_text_field(strval($_POST['wp_cron_schedule'])); - $interval = ( isset($scheds[$name]['interval']) ) ? - (int) $scheds[$name]['interval'] : 0; - update_option('wp_cron_backup_schedule', $name, false); + $scheds = (array) wp_get_schedules(); + $name = sanitize_text_field( strval( $_POST['wp_cron_schedule'] ) ); + $interval = ( isset( $scheds[ $name ]['interval'] ) ) ? (int) $scheds[ $name ]['interval'] : 0; + update_option( 'wp_cron_backup_schedule', $name, false ); + if ( 0 !== $interval ) { - wp_schedule_event(time() + $interval, $name, 'wp_db_backup_cron'); + wp_schedule_event( time() + $interval, $name, 'wp_db_backup_cron' ); } - } - else { - update_option('wp_cron_backup_schedule', intval($_POST['cron_schedule']), false); + } else { + update_option( 'wp_cron_backup_schedule', intval( $_POST['cron_schedule'] ), false ); } - update_option('wp_cron_backup_tables', $this->get_submitted_tables_to_backup_in_cron()); - if (is_email($_POST['cron_backup_recipient'])) { - update_option('wp_cron_backup_recipient', sanitize_text_field($_POST['cron_backup_recipient']), false); + + update_option( 'wp_cron_backup_tables', $this->get_submitted_tables_to_backup_in_cron() ); + + if ( is_email( $_POST['cron_backup_recipient'] ) ) { + update_option( 'wp_cron_backup_recipient', sanitize_text_field( $_POST['cron_backup_recipient'] ), false ); } - $feedback .= '

' . __('Scheduled Backup Options Saved!','wp-db-backup') . '

'; + + $feedback .= '

' . __( 'Scheduled Backup Options Saved!', 'wp-db-backup' ) . '

'; endif; $other_tables = array(); - $also_backup = array(); + $also_backup = array(); // Get complete db table list - $all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N); - $all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables); + $all_tables = $wpdb->get_results( 'SHOW TABLES', ARRAY_N ); + $all_tables = array_map( + function( $a ) { + return $a[0]; + }, + $all_tables + ); + // Get list of WP tables that actually exist in this DB (for 1.6 compat!) - $wp_backup_default_tables = array_intersect($all_tables, $this->core_table_names); + $wp_backup_default_tables = array_intersect( $all_tables, $this->core_table_names ); // Get list of non-WP tables - $other_tables = array_diff($all_tables, $wp_backup_default_tables); + $other_tables = array_diff( $all_tables, $wp_backup_default_tables ); - if ('' != $feedback) + if ( '' != $feedback ) { echo $feedback; + } - if ( ! $this->wp_secure() ) + if ( ! $this->wp_secure() ) { return; + } // Give the new dirs the same perms as wp-content. -// $stat = stat( ABSPATH . 'wp-content' ); -// $dir_perms = $stat['mode'] & 0000777; // Get the permission bits. + // $stat = stat( ABSPATH . 'wp-content' ); + // $dir_perms = $stat['mode'] & 0000777; // Get the permission bits. $dir_perms = '0777'; // the file doesn't exist and can't create it - if ( ! file_exists($this->backup_dir) && ! @mkdir($this->backup_dir) ) { - ?>

NOT exist, and we cannot create it.','wp-db-backup'); ?>

-

' . $this->backup_dir . ''); ?>

backup_dir ) && ! @mkdir( $this->backup_dir ) ) { + ?> +
+

NOT exist, and we cannot create it.', 'wp-db-backup' ); ?>

+

' . $this->backup_dir . '' ); ?>

+
+ backup_dir) && ! @chmod($this->backup_dir, $dir_perms) ) { - ?>

NOT writable! We cannot create the backup files.','wp-db-backup'); ?>

-

777', 'a+w', '' . $this->backup_dir . ''); ?> -

backup_dir ) && ! @chmod( $this->backup_dir, $dir_perms ) ) { + ?> +
+

NOT writable! We cannot create the backup files.', 'wp-db-backup' ); ?>

+

777', 'a+w', '' . $this->backup_dir . '' ); ?>

+
+ fp = $this->open($this->backup_dir . 'test' ); - if( $this->fp ) { - $this->close($this->fp); - @unlink($this->backup_dir . 'test' ); - // the directory is not writable probably due to safe mode + $this->fp = $this->open( $this->backup_dir . 'test' ); + + if ( $this->fp ) { + $this->close( $this->fp ); + @unlink( $this->backup_dir . 'test' ); + // the directory is not writable probably due to safe mode } else { - ?>

NOT writable! We cannot create the backup files.','wp-db-backup'); ?>

safe_mode file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup'); ?>

' . $this->backup_dir . ''); - ?>
+
+

NOT writable! We cannot create the backup files.', 'wp-db-backup' ); ?>

+ +

safe_mode file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup' ); ?>

+ ' . $this->backup_dir . '' ); + ?> +
+ backup_dir . 'index.php') ) - @ touch($this->backup_dir . 'index.php'); - ?>
-

-
- referer_check_key); ?> -
-
-

    comments ) { - $checked = ( isset($excs['spam']) && is_array($excs['spam'] ) && in_array($table, $excs['spam']) ) ? ' checked=\'checked\'' : ''; - echo "
  • $table " . __('Exclude spam comments', 'wp-db-backup') . '
  • '; - } elseif ( function_exists('wp_get_post_revisions') && $table == $wpdb->posts ) { - $checked = ( isset($excs['revisions']) && is_array($excs['revisions'] ) && in_array($table, $excs['revisions']) ) ? ' checked=\'checked\'' : ''; - echo "
  • $table " . __('Exclude post revisions', 'wp-db-backup') . '
  • '; - } else { - echo "
  • $table
  • "; + if ( ! file_exists( $this->backup_dir . 'index.php' ) ) { + @touch( $this->backup_dir . 'index.php' ); + } + ?> +
    +

    + + referer_check_key ); } - } - ?>
-
-
- 0) { ?> -

-
    +
    +
    +

    +
      + comments ) { + $checked = ( isset( $excs['spam'] ) && is_array( $excs['spam'] ) && in_array( $table, $excs['spam'] ) ) ? ' checked=\'checked\'' : ''; + echo "
    • $table " . __( 'Exclude spam comments', 'wp-db-backup' ) . '
    • '; + } elseif ( function_exists( 'wp_get_post_revisions' ) && $table == $wpdb->posts ) { + $checked = ( isset( $excs['revisions'] ) && is_array( $excs['revisions'] ) && in_array( $table, $excs['revisions'] ) ) ? ' checked=\'checked\'' : ''; + echo "
    • $table " . __( 'Exclude post revisions', 'wp-db-backup' ) . '
    • '; + } else { + echo "
    • $table
    • "; + } + } + ?> +
    +
    +
    0 ) { ?> -
  • +

    +
      + +
    • + +
+ ?> +
- -

+ +

- +

-

NOT writable!','wp-db-backup'); ?>

+

NOT writable!', 'wp-db-backup' ); ?>

- + ' . __('Scheduled Backup','wp-db-backup') . ''; - $datetime = get_option('date_format') . ' ' . get_option('time_format'); + echo '
' . __( 'Scheduled Backup', 'wp-db-backup' ) . ''; + $datetime = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); if ( $cron ) : - $next_cron = wp_next_scheduled('wp_db_backup_cron'); + $next_cron = wp_next_scheduled( 'wp_db_backup_cron' ); if ( ! empty( $next_cron ) ) : ?>

- ' . gmdate($datetime, $next_cron + (get_option('gmt_offset') * 3600)) . ''); ?> + ' . gmdate( $datetime, $next_cron + ( get_option( 'gmt_offset' ) * 3600 ) ) . '' ); ?>


+


+ +

+
- referer_check_key); ?> + ?> + + referer_check_key );} + ?>
-

+

__('None','wp-db-backup'), 1 => __('Daily','wp-db-backup')); - foreach ($schedule as $value => $name) { + $wp_cron_backup_schedule = get_option( 'wp_cron_backup_schedule' ); + $schedule = array( + 0 => __( 'None', 'wp-db-backup' ), + 1 => __( 'Daily', 'wp-db-backup' ), + ); + foreach ( $schedule as $value => $name ) { echo ' ' . $name; } elseif ( $cron ) : - echo apply_filters('wp_db_b_schedule_choices', wp_get_schedules() ); + echo apply_filters( 'wp_db_b_schedule_choices', wp_get_schedules() ); endif; - $cron_recipient = get_option('wp_cron_backup_recipient'); - if (! is_email($cron_recipient)) { - $cron_recipient = get_option('admin_email'); + + $cron_recipient = get_option( 'wp_cron_backup_recipient' ); + + if ( ! is_email( $cron_recipient ) ) { + $cron_recipient = get_option( 'admin_email' ); } - $cron_recipient_input = '

'; - echo apply_filters('wp_db_b_cron_recipient_input', $cron_recipient_input); - echo '

'; + + $cron_recipient_input = '

'; + echo apply_filters( 'wp_db_b_cron_recipient_input', $cron_recipient_input ); + echo '

'; echo '
'; - $cron_tables = get_option('wp_cron_backup_tables'); - if (! is_array($cron_tables)) { + $cron_tables = get_option( 'wp_cron_backup_tables' ); + + if ( ! is_array( $cron_tables ) ) { $cron_tables = array(); } - if (count($other_tables) > 0) { + + if ( count( $other_tables ) > 0 ) { echo '
'; - echo '

' . __('Tables to include in the scheduled backup:','wp-db-backup') . '

    '; - foreach ($other_tables as $table) { + echo '

    ' . __( 'Tables to include in the scheduled backup:', 'wp-db-backup' ) . '

      '; + foreach ( $other_tables as $table ) { echo '
    • {$table}
    • "; } echo '
'; } + echo '
'; echo '
'; endif; // end of wp_cron (legacy) section @@ -1385,60 +1420,98 @@ function get_sched() { $options = array_keys( (array) wp_get_schedules() ); - $freq = get_option('wp_cron_backup_schedule'); - $freq = ( in_array( $freq , $options ) ) ? $freq : 'never'; + $freq = get_option( 'wp_cron_backup_schedule' ); + $freq = ( in_array( $freq, $options ) ) ? $freq : 'never'; + return $freq; } - function schedule_choices($schedule) { // create the cron menu based on the schedule + function schedule_choices( $schedule ) { + // create the cron menu based on the schedule $wp_cron_backup_schedule = $this->get_sched(); - $next_cron = wp_next_scheduled('wp_db_backup_cron'); + $next_cron = wp_next_scheduled( 'wp_db_backup_cron' ); $wp_cron_backup_schedule = ( empty( $next_cron ) ) ? 'never' : $wp_cron_backup_schedule; - $sort = array(); - foreach ( (array) $schedule as $key => $value ) $sort[$key] = $value['interval']; + $sort = array(); + + foreach ( (array) $schedule as $key => $value ) { + $sort[ $key ] = $value['interval']; + } asort( $sort ); + $schedule_sorted = array(); - foreach ( (array) $sort as $key => $value ) $schedule_sorted[$key] = $schedule[$key]; - $menu = '