97 'postmeta', |
105 'postmeta', |
98 'posts', |
106 'posts', |
99 'terms', |
107 'terms', |
100 'term_taxonomy', |
108 'term_taxonomy', |
101 'term_relationships', |
109 'term_relationships', |
|
110 'termmeta', |
102 'users', |
111 'users', |
103 'usermeta', |
112 'usermeta', |
104 ); |
113 ); |
105 |
114 |
106 foreach( $possible_names as $name ) { |
115 foreach ( $possible_names as $name ) { |
107 if ( isset( $wpdb->{$name} ) ) { |
116 if ( isset( $wpdb->{$name} ) ) { |
108 $this->core_table_names[] = $wpdb->{$name}; |
117 $this->core_table_names[] = $wpdb->{$name}; |
109 } |
118 } |
110 } |
119 } |
111 |
120 |
112 $requested_temp_dir = sanitize_text_field($_GET['wp_db_temp_dir']); |
121 $tmp_dir = get_temp_dir(); |
113 $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())); |
122 |
114 $this->basename = 'wp-db-backup'; |
123 if ( isset( $_GET['wp_db_temp_dir'] ) ) { |
|
124 $requested_dir = sanitize_text_field( $_GET['wp_db_temp_dir'] ); |
|
125 if ( is_writeable( $requested_dir ) ) { |
|
126 $tmp_dir = $requested_dir; |
|
127 } |
|
128 } |
|
129 |
|
130 $this->backup_dir = trailingslashit( apply_filters( 'wp_db_b_backup_dir', $tmp_dir ) ); |
|
131 $this->basename = 'wp-db-backup'; |
115 |
132 |
116 $this->referer_check_key = $this->basename . '-download_' . DB_NAME; |
133 $this->referer_check_key = $this->basename . '-download_' . DB_NAME; |
117 if (isset($_POST['do_backup'])) { |
134 if ( isset( $_POST['do_backup'] ) ) { |
118 $this->wp_secure('fatal'); |
135 $this->wp_secure( 'fatal' ); |
119 check_admin_referer($this->referer_check_key); |
136 check_admin_referer( $this->referer_check_key ); |
120 $this->can_user_backup('main'); |
137 $this->can_user_backup( 'main' ); |
121 |
138 |
122 // save exclude prefs |
139 // save exclude prefs |
123 update_option('wp_db_backup_excs', array( |
140 update_option( |
124 'revisions' => $this->get_revisions_to_exclude(), |
141 'wp_db_backup_excs', |
125 'spam' => $this->get_spam_to_exclude() |
142 array( |
126 )); |
143 'revisions' => $this->get_revisions_to_exclude(), |
127 switch($_POST['do_backup']) { |
144 'spam' => $this->get_spam_to_exclude(), |
128 case 'backup': |
145 ) |
129 add_action('init', array(&$this, 'perform_backup')); |
146 ); |
130 break; |
147 switch ( $_POST['do_backup'] ) { |
131 case 'fragments': |
148 case 'backup': |
132 add_action('admin_menu', array(&$this, 'fragment_menu')); |
149 add_action( 'init', array( &$this, 'perform_backup' ) ); |
133 break; |
150 break; |
134 } |
151 case 'fragments': |
135 } elseif (isset($_GET['fragment'] )) { |
152 add_action( 'admin_menu', array( &$this, 'fragment_menu' ) ); |
136 $this->can_user_backup('frame'); |
153 break; |
137 add_action('init', array(&$this, 'init')); |
154 } |
138 } elseif (isset($_GET['backup'] )) { |
155 } elseif ( isset( $_GET['fragment'] ) ) { |
|
156 $this->can_user_backup( 'frame' ); |
|
157 add_action( 'init', array( &$this, 'init' ) ); |
|
158 } elseif ( isset( $_GET['backup'] ) ) { |
139 $this->can_user_backup(); |
159 $this->can_user_backup(); |
140 add_action('init', array(&$this, 'init')); |
160 add_action( 'init', array( &$this, 'init' ) ); |
141 } else { |
161 } else { |
142 add_action('admin_menu', array(&$this, 'admin_menu')); |
162 add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); |
143 } |
163 } |
144 } |
164 } |
145 |
165 |
146 function init() { |
166 function init() { |
147 $this->can_user_backup(); |
167 $this->can_user_backup(); |
148 if (isset($_GET['backup'])) { |
168 if ( isset( $_GET['backup'] ) ) { |
149 $via = isset($_GET['via']) ? sanitize_text_field($_GET['via']) : 'http'; |
169 $via = isset( $_GET['via'] ) ? sanitize_text_field( $_GET['via'] ) : 'http'; |
150 |
170 |
151 $this->backup_file = sanitize_text_field($_GET['backup']); |
171 $this->backup_file = sanitize_text_field( $_GET['backup'] ); |
152 $this->validate_file($this->backup_file); |
172 $this->validate_file( $this->backup_file ); |
153 |
173 |
154 switch($via) { |
174 switch ( $via ) { |
155 case 'smtp': |
175 case 'smtp': |
156 case 'email': |
176 case 'email': |
157 $success = $this->deliver_backup($this->backup_file, 'smtp', sanitize_text_field($_GET['recipient']), 'frame'); |
177 $success = $this->deliver_backup( $this->backup_file, 'smtp', sanitize_text_field( $_GET['recipient'] ), 'frame' ); |
158 $this->error_display( 'frame' ); |
178 $this->error_display( 'frame' ); |
159 if ( $success ) { |
179 if ( $success ) { |
160 echo ' |
180 echo ' |
161 <!-- ' . $via . ' --> |
181 <!-- ' . $via . ' --> |
162 <script type="text/javascript"><!--\\ |
182 <script type="text/javascript"><!--\\ |
163 '; |
183 '; |
164 echo ' |
184 echo ' |
165 alert("' . __('Backup Complete!','wp-db-backup') . '"); |
185 alert("' . __( 'Backup Complete!', 'wp-db-backup' ) . '"); |
166 window.onbeforeunload = null; |
186 window.onbeforeunload = null; |
167 </script> |
187 </script> |
168 '; |
188 '; |
169 } |
189 } |
170 break; |
190 break; |
171 default: |
191 default: |
172 $success = $this->deliver_backup($this->backup_file, $via); |
192 $success = $this->deliver_backup( $this->backup_file, $via ); |
173 echo $this->error_display( 'frame', false ); |
193 echo $this->error_display( 'frame', false ); |
174 |
194 |
175 if ( $success ) { |
195 if ( $success ) { |
176 echo ' |
196 echo ' |
177 <script type="text/javascript"> |
197 <script type="text/javascript"> |
178 window.parent.setProgress("' . __('Backup Complete!','wp-db-backup') . '"); |
198 window.parent.setProgress("' . __( 'Backup Complete!', 'wp-db-backup' ) . '"); |
179 </script> |
199 </script> |
180 '; |
200 '; |
181 } |
201 } |
182 } |
202 } |
183 exit; |
203 exit; |
184 } |
204 } |
185 if (isset($_GET['fragment'] )) { |
205 |
186 list($table, $segment, $filename) = explode(':', sanitize_text_field($_GET['fragment'])); |
206 if ( isset( $_GET['fragment'] ) ) { |
187 $this->validate_file($filename); |
207 list($table, $segment, $filename) = explode( ':', sanitize_text_field( $_GET['fragment'] ) ); |
188 $this->backup_fragment($table, $segment, $filename); |
208 $this->validate_file( $filename ); |
|
209 $this->backup_fragment( $table, $segment, $filename ); |
189 } |
210 } |
190 |
211 |
191 die(); |
212 die(); |
192 } |
213 } |
193 |
214 |
194 function init_textdomain() { |
215 function init_textdomain() { |
195 load_plugin_textdomain('wp-db-backup', str_replace(ABSPATH, '', dirname(__FILE__)), dirname(plugin_basename(__FILE__))); |
216 load_plugin_textdomain( |
|
217 'wp-db-backup', |
|
218 false, |
|
219 dirname( plugin_basename( __FILE__ ) ) . '/languages' |
|
220 ); |
196 } |
221 } |
197 |
222 |
198 function set_page_url() { |
223 function set_page_url() { |
199 $query_args = array( 'page' => $this->basename ); |
224 $query_args = array( 'page' => $this->basename ); |
200 if ( function_exists('wp_create_nonce') ) |
225 |
201 $query_args = array_merge( $query_args, array('_wpnonce' => wp_create_nonce($this->referer_check_key)) ); |
226 if ( function_exists( 'wp_create_nonce' ) ) { |
202 $base = ( function_exists('site_url') ) ? site_url('', 'admin') : get_option('siteurl'); |
227 $query_args = array_merge( $query_args, array( '_wpnonce' => wp_create_nonce( $this->referer_check_key ) ) ); |
203 $this->page_url = add_query_arg( $query_args, $base . '/wp-admin/edit.php'); |
228 } |
|
229 |
|
230 $base = ( function_exists( 'site_url' ) ) ? site_url( '', 'admin' ) : get_option( 'siteurl' ); |
|
231 $this->page_url = add_query_arg( $query_args, $base . '/wp-admin/edit.php' ); |
204 } |
232 } |
205 |
233 |
206 /* |
234 /* |
207 * Add a link to back up your database when doing a core upgrade. |
235 * Add a link to back up your database when doing a core upgrade. |
208 */ |
236 */ |
209 function update_notice_action() { |
237 function update_notice() { |
210 global $pagenow; |
238 global $pagenow; |
211 if ( |
239 |
212 ( |
240 if ( empty( $pagenow ) || 'update-core.php' !== $pagenow ) { |
213 isset($_REQUEST['action']) |
241 return false; |
214 && ('upgrade-core' == $_REQUEST['action']) |
242 } |
215 ) |
243 ?> |
216 || ( |
244 <div class="notice notice-warning"> |
217 !empty($pagenow) && ('update-core.php' == $pagenow) |
245 <p> |
218 ) |
246 <?php |
219 ) : |
247 printf( |
220 ob_start(array(&$this, 'update_notice')); |
248 __( 'Click <a href="%s">here</a> to back up your database using the WordPress Database Backup plugin. <strong>Note:</strong> WordPress Database Backup does <em>not</em> back up your files, just your database.', 'wp-db-backup' ), |
221 add_action('admin_footer', create_function('', 'ob_end_flush();')); |
249 esc_url( get_admin_url( null, 'tools.php?page=wp-db-backup' ) ) |
222 endif; |
250 ); |
223 } |
251 ?> |
224 |
252 </p> |
225 function update_notice($text = '') { |
253 </div> |
226 $pattern = '#(<a href\="' . __('http://codex.wordpress.org/WordPress_Backups') . '">.*?</p>)#'; |
254 <?php |
227 $replace = '$1' . "\n<p>" . sprintf(__('Click <a href="%s" target="_blank">here</a> to back up your database using the WordPress Database Backup plugin. <strong>Note:</strong> WordPress Database Backup does <em>not</em> back up your files, just your database.', 'wp-db-backup'), 'tools.php?page=wp-db-backup') . "</p>\n"; |
|
228 $text = preg_replace($pattern, $replace, $text); |
|
229 return $text; |
|
230 } |
255 } |
231 |
256 |
232 function build_backup_script() { |
257 function build_backup_script() { |
233 global $table_prefix, $wpdb; |
258 global $table_prefix, $wpdb; |
234 |
259 |
235 echo "<div class='wrap'>"; |
260 echo "<div class='wrap'>"; |
236 echo '<fieldset class="options"><legend>' . __('Progress','wp-db-backup') . '</legend> |
261 echo '<fieldset class="options"><legend>' . __( 'Progress', 'wp-db-backup' ) . '</legend> |
237 <p><strong>' . |
262 <p><strong>' . |
238 __('DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:','wp-db-backup'). |
263 __( 'DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:', 'wp-db-backup' ) . |
239 '</strong></p> |
264 '</strong></p> |
240 <ol> |
265 <ol> |
241 <li>'.__('Close this browser','wp-db-backup').'</li> |
266 <li>' . __( 'Close this browser', 'wp-db-backup' ) . '</li> |
242 <li>'.__('Reload this page','wp-db-backup').'</li> |
267 <li>' . __( 'Reload this page', 'wp-db-backup' ) . '</li> |
243 <li>'.__('Click the Stop or Back buttons in your browser','wp-db-backup').'</li> |
268 <li>' . __( 'Click the Stop or Back buttons in your browser', 'wp-db-backup' ) . '</li> |
244 </ol> |
269 </ol> |
245 <p><strong>' . __('Progress:','wp-db-backup') . '</strong></p> |
270 <p><strong>' . __( 'Progress:', 'wp-db-backup' ) . '</strong></p> |
246 <div id="meterbox" style="height:11px;width:80%;padding:3px;border:1px solid #659fff;"><div id="meter" style="color:#fff;height:11px;line-height:11px;background-color:#659fff;width:0%;text-align:center;font-size:6pt;"> </div></div> |
271 <div id="meterbox" style="height:11px;width:80%;padding:3px;border:1px solid #659fff;"><div id="meter" style="color:#fff;height:11px;line-height:11px;background-color:#659fff;width:0%;text-align:center;font-size:6pt;"> </div></div> |
247 <div id="progress_message"></div> |
272 <div id="progress_message"></div> |
248 <div id="errors"></div> |
273 <div id="errors"></div> |
249 </fieldset> |
274 </fieldset> |
250 <iframe id="backuploader" src="about:blank" style="visibility:hidden;border:none;height:1em;width:1px;"></iframe> |
275 <iframe id="backuploader" src="about:blank" style="visibility:hidden;border:none;height:1em;width:1px;"></iframe> |
251 <script type="text/javascript"> |
276 <script type="text/javascript"> |
252 //<![CDATA[ |
277 //<![CDATA[ |
253 window.onbeforeunload = function() { |
278 window.onbeforeunload = function() { |
254 return "' . __('Navigating away from this page will cause your backup to fail.', 'wp-db-backup') . '"; |
279 return "' . __( 'Navigating away from this page will cause your backup to fail.', 'wp-db-backup' ) . '"; |
255 } |
280 } |
256 function setMeter(pct) { |
281 function setMeter(pct) { |
257 var meter = document.getElementById("meter"); |
282 var meter = document.getElementById("meter"); |
258 meter.style.width = pct + "%"; |
283 meter.style.width = pct + "%"; |
259 meter.innerHTML = Math.floor(pct) + "%"; |
284 meter.innerHTML = Math.floor(pct) + "%"; |
554 <?php endif; // wp_schedule_event exists ?> |
607 <?php endif; // wp_schedule_event exists ?> |
555 }); |
608 }); |
556 } |
609 } |
557 //]]> |
610 //]]> |
558 </script> |
611 </script> |
559 <style type="text/css"> |
|
560 .wp-db-backup-updated { |
|
561 margin-top: 1em; |
|
562 } |
|
563 |
|
564 fieldset.options { |
|
565 border: 1px solid; |
|
566 margin-top: 1em; |
|
567 padding: 1em; |
|
568 -moz-border-radius: 8px; |
|
569 -khtml-border-radius: 8px; |
|
570 -webkit-border-top-left-radius: 8px; |
|
571 -webkit-border-top-right-radius: 8px; |
|
572 -webkit-border-bottom-left-radius: 8px; |
|
573 -webkit-border-bottom-right-radius: 8px; |
|
574 border-radius: 8px; |
|
575 } |
|
576 fieldset.options div.tables-list { |
|
577 float: left; |
|
578 padding: 1em; |
|
579 } |
|
580 |
|
581 fieldset.options input { |
|
582 } |
|
583 |
|
584 fieldset.options legend { |
|
585 font-size: larger; |
|
586 font-weight: bold; |
|
587 margin-bottom: .5em; |
|
588 padding: 1em; |
|
589 } |
|
590 |
|
591 fieldset.options .instructions { |
|
592 font-size: smaller; |
|
593 } |
|
594 |
|
595 fieldset.options ul { |
|
596 list-style-type: none; |
|
597 } |
|
598 fieldset.options li { |
|
599 text-align: left; |
|
600 } |
|
601 |
|
602 fieldset.options .submit { |
|
603 border-top: none; |
|
604 } |
|
605 </style> |
|
606 <?php |
612 <?php |
607 } |
613 } |
608 |
614 |
609 function admin_load() { |
615 function admin_load() { |
610 add_action('admin_head', array(&$this, 'admin_header')); |
616 add_action( 'admin_head', array( &$this, 'admin_header' ) ); |
|
617 wp_enqueue_style( 'wp-db-backup-styles', plugin_dir_url( __FILE__ ) . 'assets/css/style.css' ); |
611 } |
618 } |
612 |
619 |
613 function admin_menu() { |
620 function admin_menu() { |
614 $_page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', $this->basename, array(&$this, 'backup_menu')); |
621 $_page_hook = add_management_page( __( 'Backup', 'wp-db-backup' ), __( 'Backup', 'wp-db-backup' ), 'import', $this->basename, array( &$this, 'backup_menu' ) ); |
615 add_action('load-' . $_page_hook, array(&$this, 'admin_load')); |
622 add_action( 'load-' . $_page_hook, array( &$this, 'admin_load' ) ); |
616 if (function_exists('get_current_screen')) { |
623 if ( function_exists( 'get_current_screen' ) ) { |
617 $screen = convert_to_screen($_page_hook); |
624 $screen = convert_to_screen( $_page_hook ); |
618 if (method_exists($screen,'add_help_tab')) { |
625 if ( method_exists( $screen, 'add_help_tab' ) ) { |
619 $screen->add_help_tab(array( |
626 $screen->add_help_tab( |
620 'title' => __('Backup','wp-db-backup'), |
627 array( |
621 'id' => $_page_hook, |
628 'title' => __( 'Backup', 'wp-db-backup' ), |
622 'content' => $this->help_menu(), |
629 'id' => $_page_hook, |
623 )); |
630 'content' => $this->help_menu(), |
624 } |
631 ) |
625 } elseif ( function_exists('add_contextual_help') ) { |
632 ); |
|
633 } |
|
634 } elseif ( function_exists( 'add_contextual_help' ) ) { |
626 $text = $this->help_menu(); |
635 $text = $this->help_menu(); |
627 add_contextual_help($_page_hook, $text); |
636 add_contextual_help( $_page_hook, $text ); |
628 } |
637 } |
629 } |
638 } |
630 |
639 |
631 function fragment_menu() { |
640 function fragment_menu() { |
632 $page_hook = add_management_page(__('Backup','wp-db-backup'), __('Backup','wp-db-backup'), 'import', $this->basename, array(&$this, 'build_backup_script')); |
641 $page_hook = add_management_page( __( 'Backup', 'wp-db-backup' ), __( 'Backup', 'wp-db-backup' ), 'import', $this->basename, array( &$this, 'build_backup_script' ) ); |
633 add_action('load-' . $page_hook, array(&$this, 'admin_load')); |
642 add_action( 'load-' . $page_hook, array( &$this, 'admin_load' ) ); |
634 } |
643 } |
635 |
644 |
636 /** |
645 /** |
637 * Add WP-DB-Backup-specific help options to the 2.7 =< WP contextual help menu |
646 * Add WP-DB-Backup-specific help options to the 2.7 =< WP contextual help menu |
638 * @return string The text of the help menu. |
647 * @return string The text of the help menu. |
639 */ |
648 */ |
640 function help_menu() { |
649 function help_menu() { |
641 $text = "\n<a href=\"http://wordpress.org/extend/plugins/wp-db-backup/faq/\" target=\"_blank\">" . __('FAQ', 'wp-db-backup') . '</a>'; |
650 $text = "\n<a href=\"http://wordpress.org/extend/plugins/wp-db-backup/faq/\" target=\"_blank\">" . __( 'FAQ', 'wp-db-backup' ) . '</a>'; |
642 return $text; |
651 return $text; |
643 } |
652 } |
644 |
653 |
645 function save_backup_time() { |
654 function save_backup_time() { |
646 if ( $this->can_user_backup() ) { |
655 if ( $this->can_user_backup() ) { |
647 // try to get a time from the input string |
656 // try to get a time from the input string |
648 $time = strtotime(strval($_POST['backup-time'])); |
657 $time = strtotime( strval( $_POST['backup-time'] ) ); |
649 if ( ! empty( $time ) && time() < $time ) { |
658 if ( ! empty( $time ) && time() < $time ) { |
650 wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous |
659 wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous |
651 $scheds = (array) wp_get_schedules(); |
660 $scheds = (array) wp_get_schedules(); |
652 $name = get_option('wp_cron_backup_schedule'); |
661 $name = get_option( 'wp_cron_backup_schedule' ); |
653 if ( 0 != $time ) { |
662 if ( 0 != $time ) { |
654 wp_schedule_event($time, $name, 'wp_db_backup_cron'); |
663 wp_schedule_event( $time, $name, 'wp_db_backup_cron' ); |
655 echo gmdate(get_option('date_format') . ' ' . get_option('time_format'), $time + (get_option('gmt_offset') * 3600)); |
664 echo gmdate( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time + ( get_option( 'gmt_offset' ) * 3600 ) ); |
656 exit; |
665 exit; |
657 } |
666 } |
658 } |
667 } |
659 } else { |
668 } else { |
660 die(0); |
669 die( 0 ); |
661 } |
670 } |
662 } |
671 } |
663 |
672 |
664 /** |
673 /** |
665 * Better addslashes for SQL queries. |
674 * Better addslashes for SQL queries. |
666 * Taken from phpMyAdmin. |
675 * Taken from phpMyAdmin. |
667 */ |
676 */ |
668 function sql_addslashes($a_string = '', $is_like = false) { |
677 function sql_addslashes( $a_string = '', $is_like = false ) { |
669 if ($is_like) $a_string = str_replace('\\', '\\\\\\\\', $a_string); |
678 if ( $is_like ) { |
670 else $a_string = str_replace('\\', '\\\\', $a_string); |
679 $a_string = str_replace( '\\', '\\\\\\\\', $a_string ); |
671 return str_replace('\'', '\\\'', $a_string); |
680 } else { |
|
681 $a_string = str_replace( '\\', '\\\\', $a_string ); |
|
682 } |
|
683 |
|
684 return str_replace( '\'', '\\\'', $a_string ); |
672 } |
685 } |
673 |
686 |
674 /** |
687 /** |
675 * Add backquotes to tables and db-names in |
688 * Add backquotes to tables and db-names in |
676 * SQL queries. Taken from phpMyAdmin. |
689 * SQL queries. Taken from phpMyAdmin. |
677 */ |
690 */ |
678 function backquote($a_name) { |
691 function backquote( $a_name ) { |
679 if (!empty($a_name) && $a_name != '*') { |
692 if ( ! empty( $a_name ) && $a_name != '*' ) { |
680 if (is_array($a_name)) { |
693 if ( is_array( $a_name ) ) { |
681 $result = array(); |
694 $result = array(); |
682 reset($a_name); |
695 reset( $a_name ); |
683 while(list($key, $val) = each($a_name)) |
696 while ( list($key, $val) = each( $a_name ) ) { |
684 $result[$key] = '`' . $val . '`'; |
697 $result[ $key ] = '`' . $val . '`'; |
|
698 } |
685 return $result; |
699 return $result; |
686 } else { |
700 } else { |
687 return '`' . $a_name . '`'; |
701 return '`' . $a_name . '`'; |
688 } |
702 } |
689 } else { |
703 } else { |
690 return $a_name; |
704 return $a_name; |
691 } |
705 } |
692 } |
706 } |
693 |
707 |
694 function open($filename = '', $mode = 'w') { |
708 function open( $filename = '', $mode = 'w' ) { |
695 if ('' == $filename) return false; |
709 if ( '' == $filename ) { |
696 $fp = @fopen($filename, $mode); |
710 return false; |
|
711 } |
|
712 $fp = @fopen( $filename, $mode ); |
697 return $fp; |
713 return $fp; |
698 } |
714 } |
699 |
715 |
700 function close($fp) { |
716 function close( $fp ) { |
701 fclose($fp); |
717 fclose( $fp ); |
702 } |
718 } |
703 |
719 |
704 /** |
720 /** |
705 * Write to the backup file |
721 * Write to the backup file |
706 * @param string $query_line the line to write |
722 * @param string $query_line the line to write |
707 * @return null |
723 * @return null |
708 */ |
724 */ |
709 function stow($query_line) { |
725 function stow( $query_line ) { |
710 if(false === @fwrite($this->fp, $query_line)) |
726 if ( false === @fwrite( $this->fp, $query_line ) ) { |
711 $this->error(__('There was an error writing a line to the backup script:','wp-db-backup') . ' ' . $query_line . ' ' . $php_errormsg); |
727 $this->error( __( 'There was an error writing a line to the backup script:', 'wp-db-backup' ) . ' ' . $query_line . ' ' . $php_errormsg ); |
|
728 } |
712 } |
729 } |
713 |
730 |
714 /** |
731 /** |
715 * Logs any error messages |
732 * Logs any error messages |
716 * @param array $args |
733 * @param array $args |
717 * @return bool |
734 * @return bool |
718 */ |
735 */ |
719 function error($args = array()) { |
736 function error( $args = array() ) { |
720 if ( is_string( $args ) ) |
737 if ( is_string( $args ) ) { |
721 $args = array('msg' => $args); |
738 $args = array( 'msg' => $args ); |
722 $args = array_merge( array('loc' => 'main', 'kind' => 'warn', 'msg' => ''), $args); |
739 } |
723 $this->errors[$args['kind']][] = $args['msg']; |
740 |
724 if ( 'fatal' == $args['kind'] || 'frame' == $args['loc']) |
741 $args = array_merge( |
725 $this->error_display($args['loc']); |
742 array( |
|
743 'loc' => 'main', |
|
744 'kind' => 'warn', |
|
745 'msg' => '', |
|
746 ), |
|
747 $args |
|
748 ); |
|
749 |
|
750 $this->errors[ $args['kind'] ][] = $args['msg']; |
|
751 |
|
752 if ( 'fatal' == $args['kind'] || 'frame' == $args['loc'] ) { |
|
753 $this->error_display( $args['loc'] ); |
|
754 } |
|
755 |
726 return true; |
756 return true; |
727 } |
757 } |
728 |
758 |
729 /** |
759 /** |
730 * Displays error messages |
760 * Displays error messages |
731 * @param array $errs |
761 * @param array $errs |
732 * @param string $loc |
762 * @param string $loc |
733 * @return string |
763 * @return string |
734 */ |
764 */ |
735 function error_display($loc = 'main', $echo = true) { |
765 function error_display( $loc = 'main', $echo = true ) { |
736 $errs = $this->errors; |
766 $errs = $this->errors; |
737 unset( $this->errors ); |
767 unset( $this->errors ); |
738 if ( ! count($errs) ) return; |
768 |
739 $msg = ''; |
769 if ( ! count( $errs ) ) { |
|
770 return; |
|
771 } |
|
772 |
|
773 $msg = ''; |
740 $errs['fatal'] = isset( $errs['fatal'] ) ? (array) $errs['fatal'] : array(); |
774 $errs['fatal'] = isset( $errs['fatal'] ) ? (array) $errs['fatal'] : array(); |
741 $errs['warn'] = isset( $errs['warn'] ) ? (array) $errs['warn'] : array(); |
775 $errs['warn'] = isset( $errs['warn'] ) ? (array) $errs['warn'] : array(); |
742 $err_list = array_slice( array_merge( $errs['fatal'], $errs['warn'] ), 0, 10); |
776 $err_list = array_slice( array_merge( $errs['fatal'], $errs['warn'] ), 0, 10 ); |
743 if ( 10 == count( $err_list ) ) |
777 |
744 $err_list[9] = __('Subsequent errors have been omitted from this log.','wp-db-backup'); |
778 if ( 10 == count( $err_list ) ) { |
|
779 $err_list[9] = __( 'Subsequent errors have been omitted from this log.', 'wp-db-backup' ); |
|
780 } |
|
781 |
745 $wrap = ( 'frame' == $loc ) ? "<script type=\"text/javascript\">\n var msgList = ''; \n %1\$s \n if ( msgList ) alert(msgList); \n </script>" : '%1$s'; |
782 $wrap = ( 'frame' == $loc ) ? "<script type=\"text/javascript\">\n var msgList = ''; \n %1\$s \n if ( msgList ) alert(msgList); \n </script>" : '%1$s'; |
746 $line = ( 'frame' == $loc ) ? |
783 $line = ( 'frame' == $loc ) ? |
747 "try{ window.parent.addError('%1\$s'); } catch(e) { msgList += ' %1\$s';}\n" : |
784 "try{ window.parent.addError('%1\$s'); } catch(e) { msgList += ' %1\$s';}\n" : |
748 "%1\$s<br />\n"; |
785 "%1\$s<br />\n"; |
749 foreach( (array) $err_list as $err ) |
786 |
750 $msg .= sprintf($line,str_replace(array("\n","\r"), '', addslashes($err))); |
787 foreach ( (array) $err_list as $err ) { |
751 $msg = sprintf($wrap,$msg); |
788 $msg .= sprintf( $line, str_replace( array( "\n", "\r" ), '', addslashes( $err ) ) ); |
752 if ( count($errs['fatal'] ) ) { |
789 } |
753 if ( function_exists('wp_die') && 'frame' != $loc ) wp_die(stripslashes($msg)); |
790 |
754 else die($msg); |
791 $msg = sprintf( $wrap, $msg ); |
755 } |
792 |
756 else { |
793 if ( count( $errs['fatal'] ) ) { |
757 if ( $echo ) echo $msg; |
794 if ( function_exists( 'wp_die' ) && 'frame' != $loc ) { |
758 else return $msg; |
795 wp_die( stripslashes( $msg ) ); |
|
796 } else { |
|
797 die( $msg ); |
|
798 } |
|
799 } else { |
|
800 if ( $echo ) { |
|
801 echo $msg; |
|
802 } else { |
|
803 return $msg; |
|
804 } |
759 } |
805 } |
760 } |
806 } |
761 |
807 |
762 /** |
808 /** |
763 * Taken partially from phpMyAdmin and partially from |
809 * Taken partially from phpMyAdmin and partially from |
768 * to use the WordPress $wpdb object |
814 * to use the WordPress $wpdb object |
769 * @param string $table |
815 * @param string $table |
770 * @param string $segment |
816 * @param string $segment |
771 * @return void |
817 * @return void |
772 */ |
818 */ |
773 function backup_table($table, $segment = 'none') { |
819 function backup_table( $table, $segment = 'none' ) { |
774 global $wpdb; |
820 global $wpdb; |
775 |
821 |
776 $table_structure = $wpdb->get_results("DESCRIBE $table"); |
822 $table_structure = $wpdb->get_results( "DESCRIBE $table" ); |
777 if (! $table_structure) { |
823 if ( ! $table_structure ) { |
778 $this->error(__('Error getting table details','wp-db-backup') . ": $table"); |
824 $this->error( __( 'Error getting table details', 'wp-db-backup' ) . ": $table" ); |
779 return false; |
825 return false; |
780 } |
826 } |
781 |
827 |
782 if(($segment == 'none') || ($segment == 0)) { |
828 if ( ( $segment == 'none' ) || ( $segment == 0 ) ) { |
783 // Add SQL statement to drop existing table |
829 // Add SQL statement to drop existing table |
784 $this->stow("\n\n"); |
830 $this->stow( "\n\n" ); |
785 $this->stow("#\n"); |
831 $this->stow( "#\n" ); |
786 $this->stow("# " . sprintf(__('Delete any existing table %s','wp-db-backup'),$this->backquote($table)) . "\n"); |
832 $this->stow( '# ' . sprintf( __( 'Delete any existing table %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); |
787 $this->stow("#\n"); |
833 $this->stow( "#\n" ); |
788 $this->stow("\n"); |
834 $this->stow( "\n" ); |
789 $this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n"); |
835 $this->stow( 'DROP TABLE IF EXISTS ' . $this->backquote( $table ) . ";\n" ); |
790 |
836 |
791 // Table structure |
837 // Table structure |
792 // Comment in SQL-file |
838 // Comment in SQL-file |
793 $this->stow("\n\n"); |
839 $this->stow( "\n\n" ); |
794 $this->stow("#\n"); |
840 $this->stow( "#\n" ); |
795 $this->stow("# " . sprintf(__('Table structure of table %s','wp-db-backup'),$this->backquote($table)) . "\n"); |
841 $this->stow( '# ' . sprintf( __( 'Table structure of table %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); |
796 $this->stow("#\n"); |
842 $this->stow( "#\n" ); |
797 $this->stow("\n"); |
843 $this->stow( "\n" ); |
798 |
844 |
799 $create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N); |
845 $create_table = $wpdb->get_results( "SHOW CREATE TABLE $table", ARRAY_N ); |
800 if (false === $create_table) { |
846 if ( false === $create_table ) { |
801 $err_msg = sprintf(__('Error with SHOW CREATE TABLE for %s.','wp-db-backup'), $table); |
847 $err_msg = sprintf( __( 'Error with SHOW CREATE TABLE for %s.', 'wp-db-backup' ), $table ); |
802 $this->error($err_msg); |
848 $this->error( $err_msg ); |
803 $this->stow("#\n# $err_msg\n#\n"); |
849 $this->stow( "#\n# $err_msg\n#\n" ); |
804 } |
850 } |
805 $this->stow($create_table[0][1] . ' ;'); |
851 $this->stow( $create_table[0][1] . ' ;' ); |
806 |
852 |
807 if (false === $table_structure) { |
853 if ( false === $table_structure ) { |
808 $err_msg = sprintf(__('Error getting table structure of %s','wp-db-backup'), $table); |
854 $err_msg = sprintf( __( 'Error getting table structure of %s', 'wp-db-backup' ), $table ); |
809 $this->error($err_msg); |
855 $this->error( $err_msg ); |
810 $this->stow("#\n# $err_msg\n#\n"); |
856 $this->stow( "#\n# $err_msg\n#\n" ); |
811 } |
857 } |
812 |
858 |
813 // Comment in SQL-file |
859 // Comment in SQL-file |
814 $this->stow("\n\n"); |
860 $this->stow( "\n\n" ); |
815 $this->stow("#\n"); |
861 $this->stow( "#\n" ); |
816 $this->stow('# ' . sprintf(__('Data contents of table %s','wp-db-backup'),$this->backquote($table)) . "\n"); |
862 $this->stow( '# ' . sprintf( __( 'Data contents of table %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); |
817 $this->stow("#\n"); |
863 $this->stow( "#\n" ); |
818 } |
864 } |
819 |
865 |
820 if(($segment == 'none') || ($segment >= 0)) { |
866 if ( ( $segment == 'none' ) || ( $segment >= 0 ) ) { |
821 $defs = array(); |
867 $defs = array(); |
822 $ints = array(); |
868 $ints = array(); |
823 foreach ($table_structure as $struct) { |
869 foreach ( $table_structure as $struct ) { |
824 if ( (0 === strpos($struct->Type, 'tinyint')) || |
870 if ( ( 0 === strpos( $struct->Type, 'tinyint' ) ) || |
825 (0 === strpos(strtolower($struct->Type), 'smallint')) || |
871 ( 0 === strpos( strtolower( $struct->Type ), 'smallint' ) ) || |
826 (0 === strpos(strtolower($struct->Type), 'mediumint')) || |
872 ( 0 === strpos( strtolower( $struct->Type ), 'mediumint' ) ) || |
827 (0 === strpos(strtolower($struct->Type), 'int')) || |
873 ( 0 === strpos( strtolower( $struct->Type ), 'int' ) ) || |
828 (0 === strpos(strtolower($struct->Type), 'bigint')) ) { |
874 ( 0 === strpos( strtolower( $struct->Type ), 'bigint' ) ) ) { |
829 $defs[strtolower($struct->Field)] = ( null === $struct->Default ) ? 'NULL' : $struct->Default; |
875 $defs[ strtolower( $struct->Field ) ] = ( null === $struct->Default ) ? 'NULL' : $struct->Default; |
830 $ints[strtolower($struct->Field)] = "1"; |
876 $ints[ strtolower( $struct->Field ) ] = '1'; |
831 } |
877 } |
832 } |
878 } |
833 |
|
834 |
879 |
835 // Batch by $row_inc |
880 // Batch by $row_inc |
836 |
881 |
837 if($segment == 'none') { |
882 if ( $segment == 'none' ) { |
838 $row_start = 0; |
883 $row_start = 0; |
839 $row_inc = ROWS_PER_SEGMENT; |
884 $row_inc = DBBWP_ROWS_PER_SEGMENT; |
840 } else { |
885 } else { |
841 $row_start = $segment * ROWS_PER_SEGMENT; |
886 $row_start = $segment * DBBWP_ROWS_PER_SEGMENT; |
842 $row_inc = ROWS_PER_SEGMENT; |
887 $row_inc = DBBWP_ROWS_PER_SEGMENT; |
843 } |
888 } |
844 |
889 |
845 do { |
890 do { |
846 // don't include extra stuff, if so requested |
891 // don't include extra stuff, if so requested |
847 $excs = (array) get_option('wp_db_backup_excs'); |
892 $excs = (array) get_option( 'wp_db_backup_excs' ); |
848 $where = ''; |
893 $where = ''; |
849 if ( is_array($excs['spam'] ) && in_array($table, $excs['spam']) ) { |
894 |
850 $where = ' WHERE comment_approved != "spam"'; |
895 if ( is_array( $excs['spam'] ) && in_array( $table, $excs['spam'] ) ) { |
851 } elseif ( is_array($excs['revisions'] ) && in_array($table, $excs['revisions']) ) { |
896 $where = " WHERE comment_approved != 'spam'"; |
852 $where = ' WHERE post_type != "revision"'; |
897 } elseif ( is_array( $excs['revisions'] ) && in_array( $table, $excs['revisions'] ) ) { |
853 } |
898 $where = " WHERE post_type != 'revision'"; |
854 |
899 } |
855 if ( !ini_get('safe_mode')) @set_time_limit(15*60); |
900 |
856 $table_data = $wpdb->get_results("SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A); |
901 if ( ! ini_get( 'safe_mode' ) ) { |
857 |
902 @set_time_limit( 15 * 60 ); |
858 $entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES ('; |
903 } |
|
904 $table_data = $wpdb->get_results( "SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A ); |
|
905 |
|
906 $entries = 'INSERT INTO ' . $this->backquote( $table ) . ' VALUES ('; |
859 // \x08\\x09, not required |
907 // \x08\\x09, not required |
860 $search = array("\x00", "\x0a", "\x0d", "\x1a"); |
908 $search = array( "\x00", "\x0a", "\x0d", "\x1a" ); |
861 $replace = array('\0', '\n', '\r', '\Z'); |
909 $replace = array( '\0', '\n', '\r', '\Z' ); |
862 if($table_data) { |
910 |
863 foreach ($table_data as $row) { |
911 if ( $table_data ) { |
|
912 foreach ( $table_data as $row ) { |
864 $values = array(); |
913 $values = array(); |
865 foreach ($row as $key => $value) { |
914 foreach ( $row as $key => $value ) { |
866 if ( !empty($ints[strtolower($key)]) ) { |
915 if ( ! empty( $ints[ strtolower( $key ) ] ) ) { |
867 // make sure there are no blank spots in the insert syntax, |
916 // make sure there are no blank spots in the insert syntax, |
868 // yet try to avoid quotation marks around integers |
917 // yet try to avoid quotation marks around integers |
869 $value = ( null === $value || '' === $value) ? $defs[strtolower($key)] : $value; |
918 $value = ( null === $value || '' === $value ) ? $defs[ strtolower( $key ) ] : $value; |
870 $values[] = ( '' === $value ) ? "''" : $value; |
919 $values[] = ( '' === $value ) ? "''" : $value; |
871 } else { |
920 } else { |
872 $values[] = "'" . str_replace($search, $replace, $this->sql_addslashes($value)) . "'"; |
921 $values[] = "'" . str_replace( $search, $replace, $this->sql_addslashes( $value ) ) . "'"; |
873 } |
922 } |
874 } |
923 } |
875 $this->stow(" \n" . $entries . implode(', ', $values) . ');'); |
924 $this->stow( " \n" . $entries . implode( ', ', $values ) . ');' ); |
876 } |
925 } |
877 $row_start += $row_inc; |
926 $row_start += $row_inc; |
878 } |
927 } |
879 } while((count($table_data) > 0) and ($segment=='none')); |
928 } while ( ( count( $table_data ) > 0 ) and ( $segment == 'none' ) ); |
880 } |
929 } |
881 |
930 |
882 if(($segment == 'none') || ($segment < 0)) { |
931 if ( ( $segment == 'none' ) || ( $segment < 0 ) ) { |
883 // Create footer/closing comment in SQL-file |
932 // Create footer/closing comment in SQL-file |
884 $this->stow("\n"); |
933 $this->stow( "\n" ); |
885 $this->stow("#\n"); |
934 $this->stow( "#\n" ); |
886 $this->stow("# " . sprintf(__('End of data contents of table %s','wp-db-backup'),$this->backquote($table)) . "\n"); |
935 $this->stow( '# ' . sprintf( __( 'End of data contents of table %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); |
887 $this->stow("# --------------------------------------------------------\n"); |
936 $this->stow( "# --------------------------------------------------------\n" ); |
888 $this->stow("\n"); |
937 $this->stow( "\n" ); |
889 } |
938 } |
890 } // end backup_table() |
939 } // end backup_table() |
891 |
940 |
892 function db_backup($core_tables, $other_tables) { |
941 function db_backup( $core_tables, $other_tables ) { |
893 global $table_prefix, $wpdb; |
942 global $table_prefix, $wpdb; |
894 |
943 |
895 if (is_writable($this->backup_dir)) { |
944 if ( is_writable( $this->backup_dir ) ) { |
896 $this->fp = $this->open($this->backup_dir . $this->backup_filename); |
945 $this->fp = $this->open( $this->backup_dir . $this->backup_filename ); |
897 if(!$this->fp) { |
946 if ( ! $this->fp ) { |
898 $this->error(__('Could not open the backup file for writing!','wp-db-backup')); |
947 $this->error( __( 'Could not open the backup file for writing!', 'wp-db-backup' ) ); |
899 return false; |
948 return false; |
900 } |
949 } |
901 } else { |
950 } else { |
902 $this->error(__('The backup directory is not writeable!','wp-db-backup')); |
951 $this->error( __( 'The backup directory is not writeable!', 'wp-db-backup' ) ); |
903 return false; |
952 return false; |
904 } |
953 } |
905 |
954 |
906 //Begin new backup of MySql |
955 //Begin new backup of MySql |
907 $this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n"); |
956 $this->stow( '# ' . __( 'WordPress MySQL database backup', 'wp-db-backup' ) . "\n" ); |
908 $this->stow("#\n"); |
957 $this->stow( "#\n" ); |
909 $this->stow("# " . sprintf(__('Generated: %s','wp-db-backup'),date("l j. F Y H:i T")) . "\n"); |
958 $this->stow( '# ' . sprintf( __( 'Generated: %s', 'wp-db-backup' ), date( 'l j. F Y H:i T' ) ) . "\n" ); |
910 $this->stow("# " . sprintf(__('Hostname: %s','wp-db-backup'),DB_HOST) . "\n"); |
959 $this->stow( '# ' . sprintf( __( 'Hostname: %s', 'wp-db-backup' ), DB_HOST ) . "\n" ); |
911 $this->stow("# " . sprintf(__('Database: %s','wp-db-backup'),$this->backquote(DB_NAME)) . "\n"); |
960 $this->stow( '# ' . sprintf( __( 'Database: %s', 'wp-db-backup' ), $this->backquote( DB_NAME ) ) . "\n" ); |
912 $this->stow("# --------------------------------------------------------\n"); |
961 $this->stow( "# --------------------------------------------------------\n" ); |
913 |
962 |
914 if ( (is_array($other_tables)) && (count($other_tables) > 0) ) |
963 if ( ( is_array( $other_tables ) ) && ( count( $other_tables ) > 0 ) ) { |
915 $tables = array_merge($core_tables, $other_tables); |
964 $tables = array_merge( $core_tables, $other_tables ); |
916 else |
965 } else { |
917 $tables = $core_tables; |
966 $tables = $core_tables; |
918 |
967 } |
919 foreach ($tables as $table) { |
968 |
|
969 foreach ( $tables as $table ) { |
920 // Increase script execution time-limit to 15 min for every table. |
970 // Increase script execution time-limit to 15 min for every table. |
921 if ( !ini_get('safe_mode')) @set_time_limit(15*60); |
971 if ( ! ini_get( 'safe_mode' ) ) { |
|
972 @set_time_limit( 15 * 60 ); |
|
973 } |
922 // Create the SQL statements |
974 // Create the SQL statements |
923 $this->stow("# --------------------------------------------------------\n"); |
975 $this->stow( "# --------------------------------------------------------\n" ); |
924 $this->stow("# " . sprintf(__('Table: %s','wp-db-backup'),$this->backquote($table)) . "\n"); |
976 $this->stow( '# ' . sprintf( __( 'Table: %s', 'wp-db-backup' ), $this->backquote( $table ) ) . "\n" ); |
925 $this->stow("# --------------------------------------------------------\n"); |
977 $this->stow( "# --------------------------------------------------------\n" ); |
926 $this->backup_table($table); |
978 $this->backup_table( $table ); |
927 } |
979 } |
928 |
980 |
929 $this->close($this->fp); |
981 $this->close( $this->fp ); |
930 |
982 |
931 if (count($this->errors)) { |
983 if ( count( $this->errors ) ) { |
932 return false; |
984 return false; |
933 } else { |
985 } else { |
934 return $this->backup_filename; |
986 return $this->backup_filename; |
935 } |
987 } |
936 |
988 |
937 } //wp_db_backup |
989 } //wp_db_backup |
938 |
990 |
939 /** |
991 /** |
940 * Sends the backed-up file via email |
992 * Sends the backed-up file via email |
|
993 * |
941 * @param string $to |
994 * @param string $to |
942 * @param string $subject |
995 * @param string $subject |
943 * @param string $message |
996 * @param string $message |
|
997 * @param string $diskfile |
|
998 * |
944 * @return bool |
999 * @return bool |
945 */ |
1000 */ |
946 function send_mail( $to, $subject, $message, $diskfile) { |
1001 function send_mail( $to, $subject, $message, $diskfile ) { |
947 global $phpmailer; |
1002 return wp_mail( $to, $subject, $message, array(), array( $diskfile ) ); |
948 |
1003 } |
949 $filename = basename($diskfile); |
1004 |
950 |
1005 function deliver_backup( $filename = '', $delivery = 'http', $recipient = '', $location = 'main' ) { |
951 extract( apply_filters( 'wp_mail', compact( 'to', 'subject', 'message' ) ) ); |
1006 if ( '' == $filename ) { |
952 |
1007 return false; } |
953 if ( !is_object( $phpmailer ) || ( strtolower(get_class( $phpmailer )) != 'phpmailer' ) ) { |
1008 |
954 if ( file_exists( ABSPATH . WPINC . '/class-phpmailer.php' ) ) |
1009 $diskfile = $this->backup_dir . $filename; |
955 require_once ABSPATH . WPINC . '/class-phpmailer.php'; |
1010 $gz_diskfile = "{$diskfile}.gz"; |
956 if ( file_exists( ABSPATH . WPINC . '/class-smtp.php' ) ) |
1011 $retry = isset( $_GET['download-retry'] ); |
957 require_once ABSPATH . WPINC . '/class-smtp.php'; |
1012 $success = false; |
958 if ( class_exists( 'PHPMailer') ) |
1013 |
959 $phpmailer = new PHPMailer(); |
1014 // Try to gzip the file if we can. |
960 } |
1015 if ( file_exists( $diskfile ) && ! file_exists( $gz_diskfile ) && ! $retry ) { |
961 |
1016 if ( function_exists( 'gzencode' ) && function_exists( 'file_get_contents' ) ) { |
962 // try to use phpmailer directly (WP 2.2+) |
1017 // Try upping the memory limit before gzipping |
963 if ( is_object( $phpmailer ) && ( strtolower(get_class( $phpmailer )) == 'phpmailer' ) ) { |
1018 if ( function_exists( 'memory_get_usage' ) && ( (int) @ini_get( 'memory_limit' ) < 64 ) ) { |
964 |
1019 @ini_set( 'memory_limit', '64M' ); |
965 // Get the site domain and get rid of www. |
1020 } |
966 $sitename = $this->get_sitename(); |
1021 |
967 $from_email = 'wordpress@' . $sitename; |
1022 $contents = file_get_contents( $diskfile ); |
968 $from_name = 'WordPress'; |
1023 $gzipped = gzencode( $contents, 9 ); |
969 |
1024 $fp = fopen( $gz_diskfile, 'w' ); |
970 // Empty out the values that may be set |
1025 |
971 $phpmailer->ClearAddresses(); |
1026 fwrite( $fp, $gzipped ); |
972 $phpmailer->ClearAllRecipients(); |
1027 |
973 $phpmailer->ClearAttachments(); |
1028 if ( fclose( $fp ) ) { |
974 $phpmailer->ClearBCCs(); |
1029 unlink( $diskfile ); |
975 $phpmailer->ClearCCs(); |
1030 } |
976 $phpmailer->ClearCustomHeaders(); |
1031 } |
977 $phpmailer->ClearReplyTos(); |
1032 } |
978 |
1033 |
979 $phpmailer->AddAddress( $to ); |
1034 if ( file_exists( $gz_diskfile ) ) { |
980 $phpmailer->AddAttachment($diskfile, $filename); |
1035 $filename = $filename . '.gz'; |
981 $phpmailer->Body = $message; |
1036 $file_to_deliver = $gz_diskfile; |
982 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', get_bloginfo('charset') ); |
|
983 $phpmailer->From = apply_filters( 'wp_mail_from', $from_email ); |
|
984 $phpmailer->FromName = apply_filters( 'wp_mail_from_name', $from_name ); |
|
985 $phpmailer->IsMail(); |
|
986 $phpmailer->Subject = $subject; |
|
987 |
|
988 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) ); |
|
989 |
|
990 $result = @$phpmailer->Send(); |
|
991 |
|
992 // old-style: build the headers directly |
|
993 } else { |
1037 } else { |
994 $randomish = md5(time()); |
1038 $file_to_deliver = $diskfile; |
995 $boundary = "==WPBACKUP-$randomish"; |
1039 } |
996 $fp = fopen($diskfile,"rb"); |
1040 |
997 $file = fread($fp,filesize($diskfile)); |
1041 if ( 'http' == $delivery ) { |
998 $this->close($fp); |
1042 if ( ! file_exists( $file_to_deliver ) ) { |
999 |
1043 if ( ! $retry ) { |
1000 $data = chunk_split(base64_encode($file)); |
1044 $this->error( |
1001 |
1045 array( |
1002 $headers .= "MIME-Version: 1.0\n"; |
1046 'kind' => 'fatal', |
1003 $headers = 'From: wordpress@' . preg_replace('#^www\.#', '', sanitize_text_field(strtolower($_SERVER['SERVER_NAME']))) . "\n"; |
1047 'msg' => sprintf( |
1004 $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n"; |
1048 __( |
1005 |
1049 'File not found:%s', |
1006 // Add a multipart boundary above the plain message |
1050 'wp-db-backup' |
1007 $message = "This is a multi-part message in MIME format.\n\n" . |
1051 ), |
1008 "--{$boundary}\n" . |
1052 " <strong>$filename</strong><br />" |
1009 "Content-Type: text/plain; charset=\"" . get_bloginfo('charset') . "\"\n" . |
1053 ) . '<br /><a href="' . $this->page_url . '">' . __( |
1010 "Content-Transfer-Encoding: 7bit\n\n" . |
1054 'Return to Backup', |
1011 $message . "\n\n"; |
1055 'wp-db-backup' |
1012 |
1056 ) . '</a>', |
1013 // Add file attachment to the message |
1057 ) |
1014 $message .= "--{$boundary}\n" . |
1058 ); |
1015 "Content-Type: application/octet-stream;\n" . |
|
1016 " name=\"{$filename}\"\n" . |
|
1017 "Content-Disposition: attachment;\n" . |
|
1018 " filename=\"{$filename}\"\n" . |
|
1019 "Content-Transfer-Encoding: base64\n\n" . |
|
1020 $data . "\n\n" . |
|
1021 "--{$boundary}--\n"; |
|
1022 |
|
1023 $result = @wp_mail($to, $subject, $message, $headers); |
|
1024 } |
|
1025 return $result; |
|
1026 |
|
1027 } |
|
1028 |
|
1029 function deliver_backup($filename = '', $delivery = 'http', $recipient = '', $location = 'main') { |
|
1030 if ('' == $filename) { return false; } |
|
1031 |
|
1032 $diskfile = $this->backup_dir . $filename; |
|
1033 $gz_diskfile = "{$diskfile}.gz"; |
|
1034 |
|
1035 /** |
|
1036 * Try upping the memory limit before gzipping |
|
1037 */ |
|
1038 if ( function_exists('memory_get_usage') && ( (int) @ini_get('memory_limit') < 64 ) ) { |
|
1039 @ini_set('memory_limit', '64M' ); |
|
1040 } |
|
1041 |
|
1042 if ( file_exists( $diskfile ) && empty( $_GET['download-retry'] ) ) { |
|
1043 /** |
|
1044 * Try gzipping with an external application |
|
1045 */ |
|
1046 if ( file_exists( $diskfile ) && ! file_exists( $gz_diskfile ) ) { |
|
1047 @exec( "gzip $diskfile" ); |
|
1048 } |
|
1049 |
|
1050 if ( file_exists( $gz_diskfile ) ) { |
|
1051 if ( file_exists( $diskfile ) ) { |
|
1052 unlink($diskfile); |
|
1053 } |
|
1054 $diskfile = $gz_diskfile; |
|
1055 $filename = "{$filename}.gz"; |
|
1056 |
|
1057 /** |
|
1058 * Try to compress to gzip, if available |
|
1059 */ |
|
1060 } else { |
|
1061 if ( function_exists('gzencode') ) { |
|
1062 if ( function_exists('file_get_contents') ) { |
|
1063 $text = file_get_contents($diskfile); |
|
1064 } else { |
|
1065 $text = implode("", file($diskfile)); |
|
1066 } |
|
1067 $gz_text = gzencode($text, 9); |
|
1068 $fp = fopen($gz_diskfile, "w"); |
|
1069 fwrite($fp, $gz_text); |
|
1070 if ( fclose($fp) ) { |
|
1071 unlink($diskfile); |
|
1072 $diskfile = $gz_diskfile; |
|
1073 $filename = "{$filename}.gz"; |
|
1074 } |
|
1075 } |
|
1076 } |
|
1077 /* |
|
1078 * |
|
1079 */ |
|
1080 } elseif ( file_exists( $gz_diskfile ) && empty( $_GET['download-retry'] ) ) { |
|
1081 $diskfile = $gz_diskfile; |
|
1082 $filename = "{$filename}.gz"; |
|
1083 } |
|
1084 |
|
1085 if ('http' == $delivery) { |
|
1086 if ( ! file_exists( $diskfile ) ) { |
|
1087 if ( empty( $_GET['download-retry'] ) ) { |
|
1088 $this->error(array('kind' => 'fatal', 'msg' => sprintf(__('File not found:%s','wp-db-backup'), " <strong>$filename</strong><br />") . '<br /><a href="' . $this->page_url . '">' . __('Return to Backup','wp-db-backup') . '</a>')); |
|
1089 } else { |
1059 } else { |
1090 return true; |
1060 return true; |
1091 } |
1061 } |
1092 } elseif ( file_exists( $diskfile ) ) { |
1062 } else { |
1093 header('Content-Description: File Transfer'); |
1063 header( 'Content-Description: File Transfer' ); |
1094 header('Content-Type: application/octet-stream'); |
1064 header( 'Content-Type: application/octet-stream' ); |
1095 header('Content-Length: ' . filesize($diskfile)); |
1065 header( 'Content-Length: ' . filesize( $file_to_deliver ) ); |
1096 header("Content-Disposition: attachment; filename=$filename"); |
1066 header( "Content-Disposition: attachment; filename=$filename" ); |
1097 $success = readfile($diskfile); |
1067 $success = readfile( $file_to_deliver ); |
1098 if ( $success ) { |
1068 if ( $success ) { |
1099 unlink($diskfile); |
1069 unlink( $file_to_deliver ); |
1100 } |
1070 } |
1101 } |
1071 } |
1102 } elseif ('smtp' == $delivery) { |
1072 } elseif ( 'smtp' == $delivery ) { |
1103 if (! file_exists($diskfile)) { |
1073 if ( ! file_exists( $file_to_deliver ) ) { |
1104 $msg = sprintf(__('File %s does not exist!','wp-db-backup'), $diskfile); |
1074 $msg = sprintf( __( 'File %s does not exist!', 'wp-db-backup' ), $file_to_deliver ); |
1105 $this->error($msg); |
1075 $this->error( $msg ); |
1106 return false; |
1076 return false; |
1107 } |
1077 } |
1108 if (! is_email($recipient)) { |
1078 |
1109 $recipient = get_option('admin_email'); |
1079 if ( ! is_email( $recipient ) ) { |
1110 } |
1080 $recipient = get_option( 'admin_email' ); |
1111 $message = sprintf(__("Attached to this email is\n %1s\n Size:%2s kilobytes\n",'wp-db-backup'), $filename, round(filesize($diskfile)/1024)); |
1081 } |
1112 $success = $this->send_mail($recipient, get_bloginfo('name') . ' ' . __('Database Backup','wp-db-backup'), $message, $diskfile); |
1082 |
|
1083 $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 ) ); |
|
1084 $success = $this->send_mail( $recipient, get_bloginfo( 'name' ) . ' ' . __( 'Database Backup', 'wp-db-backup' ), $message, $file_to_deliver ); |
1113 |
1085 |
1114 if ( false === $success ) { |
1086 if ( false === $success ) { |
1115 $msg = __('The following errors were reported:','wp-db-backup') . "\n "; |
1087 $msg = __( 'The following errors were reported:', 'wp-db-backup' ) . "\n "; |
1116 if ( function_exists('error_get_last') ) { |
1088 if ( function_exists( 'error_get_last' ) ) { |
1117 $err = error_get_last(); |
1089 $err = error_get_last(); |
1118 $msg .= $err['message']; |
1090 $msg .= $err['message']; |
1119 } else { |
1091 } else { |
1120 $msg .= __('ERROR: The mail application has failed to deliver the backup.','wp-db-backup'); |
1092 $msg .= __( 'ERROR: The mail application has failed to deliver the backup.', 'wp-db-backup' ); |
1121 } |
1093 } |
1122 $this->error(array('kind' => 'fatal', 'loc' => $location, 'msg' => $msg)); |
1094 $this->error( |
|
1095 array( |
|
1096 'kind' => 'fatal', |
|
1097 'loc' => $location, |
|
1098 'msg' => $msg, |
|
1099 ) |
|
1100 ); |
1123 } else { |
1101 } else { |
1124 if ( file_exists( $diskfile ) ) { |
1102 if ( file_exists( $file_to_deliver ) ) { |
1125 unlink($diskfile); |
1103 unlink( $file_to_deliver ); |
1126 } |
1104 } |
1127 } |
1105 } |
1128 } |
1106 } |
|
1107 |
1129 return $success; |
1108 return $success; |
1130 } |
1109 } |
1131 |
1110 |
1132 function backup_menu() { |
1111 function backup_menu() { |
1133 global $table_prefix, $wpdb; |
1112 global $table_prefix, $wpdb; |
1134 $feedback = ''; |
1113 $feedback = ''; |
1135 $whoops = false; |
1114 $whoops = false; |
1136 |
1115 |
1137 // did we just do a backup? If so, let's report the status |
1116 // did we just do a backup? If so, let's report the status |
1138 if ( $this->backup_complete ) { |
1117 if ( $this->backup_complete ) { |
1139 $feedback = '<div class="updated wp-db-backup-updated"><p>' . __('Backup Successful','wp-db-backup') . '!'; |
1118 $feedback = '<div class="updated wp-db-backup-updated"><p>' . __( 'Backup Successful', 'wp-db-backup' ) . '!'; |
1140 $file = $this->backup_file; |
1119 $file = $this->backup_file; |
1141 switch($_POST['deliver']) { |
1120 switch ( $_POST['deliver'] ) { |
1142 case 'http': |
1121 case 'http': |
1143 $feedback .= '<br />' . sprintf(__('Your backup file: %2s should begin downloading shortly.','wp-db-backup'), "{$this->backup_file}", $this->backup_file); |
1122 $feedback .= '<br />' . sprintf( __( 'Your backup file: %2s should begin downloading shortly.', 'wp-db-backup' ), "{$this->backup_file}", $this->backup_file ); |
1144 break; |
1123 break; |
1145 case 'smtp': |
1124 case 'smtp': |
1146 $email = sanitize_text_field(wp_unslash($_POST['backup_recipient'])); |
1125 $email = sanitize_text_field( wp_unslash( $_POST['backup_recipient'] ) ); |
1147 if (! is_email($email)) { |
1126 if ( ! is_email( $email ) ) { |
1148 $feedback .= get_option('admin_email'); |
1127 $feedback .= get_option( 'admin_email' ); |
1149 } else { |
1128 } else { |
1150 $feedback .= $email; |
1129 $feedback .= $email; |
1151 } |
1130 } |
1152 $feedback = '<br />' . sprintf(__('Your backup has been emailed to %s','wp-db-backup'), $feedback); |
1131 $feedback = '<br />' . sprintf( __( 'Your backup has been emailed to %s', 'wp-db-backup' ), $feedback ); |
1153 break; |
1132 break; |
1154 } |
1133 } |
|
1134 |
1155 $feedback .= '</p></div>'; |
1135 $feedback .= '</p></div>'; |
1156 } |
1136 } |
1157 |
1137 |
1158 // security check |
1138 // security check |
1159 $this->wp_secure(); |
1139 $this->wp_secure(); |
1160 |
1140 |
1161 if (count($this->errors)) { |
1141 if ( count( $this->errors ) ) { |
1162 $feedback .= '<div class="updated wp-db-backup-updated error"><p><strong>' . __('The following errors were reported:','wp-db-backup') . '</strong></p>'; |
1142 $feedback .= '<div class="updated wp-db-backup-updated error"><p><strong>' . __( 'The following errors were reported:', 'wp-db-backup' ) . '</strong></p>'; |
1163 $feedback .= '<p>' . $this->error_display( 'main', false ) . '</p>'; |
1143 $feedback .= '<p>' . $this->error_display( 'main', false ) . '</p>'; |
1164 $feedback .= "</p></div>"; |
1144 $feedback .= '</p></div>'; |
1165 } |
1145 } |
1166 |
1146 |
1167 // did we just save options for wp-cron? |
1147 // did we just save options for wp-cron? |
1168 if ( (function_exists('wp_schedule_event') || function_exists('wp_cron_init')) |
1148 if ( ( function_exists( 'wp_schedule_event' ) || function_exists( 'wp_cron_init' ) ) && isset( $_POST['wp_cron_backup_options'] ) ) : |
1169 && isset($_POST['wp_cron_backup_options']) ) : |
1149 do_action( 'wp_db_b_update_cron_options' ); |
1170 do_action('wp_db_b_update_cron_options'); |
1150 |
1171 if ( function_exists('wp_schedule_event') ) { |
1151 if ( function_exists( 'wp_schedule_event' ) ) { |
1172 wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous |
1152 wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous |
1173 $scheds = (array) wp_get_schedules(); |
1153 $scheds = (array) wp_get_schedules(); |
1174 $name = sanitize_text_field(strval($_POST['wp_cron_schedule'])); |
1154 $name = sanitize_text_field( strval( $_POST['wp_cron_schedule'] ) ); |
1175 $interval = ( isset($scheds[$name]['interval']) ) ? |
1155 $interval = ( isset( $scheds[ $name ]['interval'] ) ) ? (int) $scheds[ $name ]['interval'] : 0; |
1176 (int) $scheds[$name]['interval'] : 0; |
1156 update_option( 'wp_cron_backup_schedule', $name, false ); |
1177 update_option('wp_cron_backup_schedule', $name, false); |
1157 |
1178 if ( 0 !== $interval ) { |
1158 if ( 0 !== $interval ) { |
1179 wp_schedule_event(time() + $interval, $name, 'wp_db_backup_cron'); |
1159 wp_schedule_event( time() + $interval, $name, 'wp_db_backup_cron' ); |
1180 } |
1160 } |
1181 } |
1161 } else { |
1182 else { |
1162 update_option( 'wp_cron_backup_schedule', intval( $_POST['cron_schedule'] ), false ); |
1183 update_option('wp_cron_backup_schedule', intval($_POST['cron_schedule']), false); |
1163 } |
1184 } |
1164 |
1185 update_option('wp_cron_backup_tables', $this->get_submitted_tables_to_backup_in_cron()); |
1165 update_option( 'wp_cron_backup_tables', $this->get_submitted_tables_to_backup_in_cron() ); |
1186 if (is_email($_POST['cron_backup_recipient'])) { |
1166 |
1187 update_option('wp_cron_backup_recipient', sanitize_text_field($_POST['cron_backup_recipient']), false); |
1167 if ( is_email( $_POST['cron_backup_recipient'] ) ) { |
1188 } |
1168 update_option( 'wp_cron_backup_recipient', sanitize_text_field( $_POST['cron_backup_recipient'] ), false ); |
1189 $feedback .= '<div class="updated wp-db-backup-updated"><p>' . __('Scheduled Backup Options Saved!','wp-db-backup') . '</p></div>'; |
1169 } |
|
1170 |
|
1171 $feedback .= '<div class="updated wp-db-backup-updated"><p>' . __( 'Scheduled Backup Options Saved!', 'wp-db-backup' ) . '</p></div>'; |
1190 endif; |
1172 endif; |
1191 |
1173 |
1192 $other_tables = array(); |
1174 $other_tables = array(); |
1193 $also_backup = array(); |
1175 $also_backup = array(); |
1194 |
1176 |
1195 // Get complete db table list |
1177 // Get complete db table list |
1196 $all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N); |
1178 $all_tables = $wpdb->get_results( 'SHOW TABLES', ARRAY_N ); |
1197 $all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables); |
1179 $all_tables = array_map( |
|
1180 function( $a ) { |
|
1181 return $a[0]; |
|
1182 }, |
|
1183 $all_tables |
|
1184 ); |
|
1185 |
1198 // Get list of WP tables that actually exist in this DB (for 1.6 compat!) |
1186 // Get list of WP tables that actually exist in this DB (for 1.6 compat!) |
1199 $wp_backup_default_tables = array_intersect($all_tables, $this->core_table_names); |
1187 $wp_backup_default_tables = array_intersect( $all_tables, $this->core_table_names ); |
1200 // Get list of non-WP tables |
1188 // Get list of non-WP tables |
1201 $other_tables = array_diff($all_tables, $wp_backup_default_tables); |
1189 $other_tables = array_diff( $all_tables, $wp_backup_default_tables ); |
1202 |
1190 |
1203 if ('' != $feedback) |
1191 if ( '' != $feedback ) { |
1204 echo $feedback; |
1192 echo $feedback; |
1205 |
1193 } |
1206 if ( ! $this->wp_secure() ) |
1194 |
|
1195 if ( ! $this->wp_secure() ) { |
1207 return; |
1196 return; |
|
1197 } |
1208 |
1198 |
1209 // Give the new dirs the same perms as wp-content. |
1199 // Give the new dirs the same perms as wp-content. |
1210 // $stat = stat( ABSPATH . 'wp-content' ); |
1200 // $stat = stat( ABSPATH . 'wp-content' ); |
1211 // $dir_perms = $stat['mode'] & 0000777; // Get the permission bits. |
1201 // $dir_perms = $stat['mode'] & 0000777; // Get the permission bits. |
1212 $dir_perms = '0777'; |
1202 $dir_perms = '0777'; |
1213 |
1203 |
1214 // the file doesn't exist and can't create it |
1204 // the file doesn't exist and can't create it |
1215 if ( ! file_exists($this->backup_dir) && ! @mkdir($this->backup_dir) ) { |
1205 if ( ! file_exists( $this->backup_dir ) && ! @mkdir( $this->backup_dir ) ) { |
1216 ?><div class="updated wp-db-backup-updated error"><p><?php _e('WARNING: Your backup directory does <strong>NOT</strong> exist, and we cannot create it.','wp-db-backup'); ?></p> |
1206 ?> |
1217 <p><?php printf(__('Using your FTP client, try to create the backup directory yourself: %s', 'wp-db-backup'), '<code>' . $this->backup_dir . '</code>'); ?></p></div><?php |
1207 <div class="updated wp-db-backup-updated error"> |
|
1208 <p><?php _e( 'WARNING: Your backup directory does <strong>NOT</strong> exist, and we cannot create it.', 'wp-db-backup' ); ?></p> |
|
1209 <p><?php printf( __( 'Using your FTP client, try to create the backup directory yourself: %s', 'wp-db-backup' ), '<code>' . $this->backup_dir . '</code>' ); ?></p> |
|
1210 </div> |
|
1211 <?php |
|
1212 // not writable due to write permissions |
1218 $whoops = true; |
1213 $whoops = true; |
1219 // not writable due to write permissions |
1214 } elseif ( ! is_writable( $this->backup_dir ) && ! @chmod( $this->backup_dir, $dir_perms ) ) { |
1220 } elseif ( !is_writable($this->backup_dir) && ! @chmod($this->backup_dir, $dir_perms) ) { |
1215 ?> |
1221 ?><div class="updated wp-db-backup-updated error"><p><?php _e('WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.','wp-db-backup'); ?></p> |
1216 <div class="updated wp-db-backup-updated error"> |
1222 <p><?php printf(__('Using your FTP client, try to set the backup directory’s write permission to %1$s or %2$s: %3$s', 'wp-db-backup'), '<code>777</code>', '<code>a+w</code>', '<code>' . $this->backup_dir . '</code>'); ?> |
1217 <p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.', 'wp-db-backup' ); ?></p> |
1223 </p></div><?php |
1218 <p><?php printf( __( 'Using your FTP client, try to set the backup directory’s write permission to %1$s or %2$s: %3$s', 'wp-db-backup' ), '<code>777</code>', '<code>a+w</code>', '<code>' . $this->backup_dir . '</code>' ); ?></p> |
|
1219 </div> |
|
1220 <?php |
1224 $whoops = true; |
1221 $whoops = true; |
1225 } else { |
1222 } else { |
1226 $this->fp = $this->open($this->backup_dir . 'test' ); |
1223 $this->fp = $this->open( $this->backup_dir . 'test' ); |
1227 if( $this->fp ) { |
1224 |
1228 $this->close($this->fp); |
1225 if ( $this->fp ) { |
1229 @unlink($this->backup_dir . 'test' ); |
1226 $this->close( $this->fp ); |
1230 // the directory is not writable probably due to safe mode |
1227 @unlink( $this->backup_dir . 'test' ); |
|
1228 // the directory is not writable probably due to safe mode |
1231 } else { |
1229 } else { |
1232 ?><div class="updated wp-db-backup-updated error"><p><?php _e('WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.','wp-db-backup'); ?></p><?php |
1230 ?> |
1233 if( ini_get('safe_mode') ){ |
1231 <div class="updated wp-db-backup-updated error"> |
1234 ?><p><?php _e('This problem seems to be caused by your server’s <code>safe_mode</code> file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup'); ?></p><?php |
1232 <p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable! We cannot create the backup files.', 'wp-db-backup' ); ?></p> |
1235 } |
1233 <?php |
1236 ?><?php printf(__('You can try to correct this problem by using your FTP client to delete and then re-create the backup directory: %s', 'wp-db-backup'), '<code>' . $this->backup_dir . '</code>'); |
1234 if ( ini_get( 'safe_mode' ) ) { |
1237 ?></div><?php |
1235 ?> |
|
1236 <p><?php _e( 'This problem seems to be caused by your server’s <code>safe_mode</code> file ownership restrictions, which limit what files web applications like WordPress can create.', 'wp-db-backup' ); ?></p> |
|
1237 <?php |
|
1238 } |
|
1239 |
|
1240 printf( __( 'You can try to correct this problem by using your FTP client to delete and then re-create the backup directory: %s', 'wp-db-backup' ), '<code>' . $this->backup_dir . '</code>' ); |
|
1241 ?> |
|
1242 </div> |
|
1243 <?php |
1238 $whoops = true; |
1244 $whoops = true; |
1239 } |
1245 } |
1240 } |
1246 } |
1241 |
1247 |
1242 |
1248 if ( ! file_exists( $this->backup_dir . 'index.php' ) ) { |
1243 |
1249 @touch( $this->backup_dir . 'index.php' ); |
1244 if ( !file_exists($this->backup_dir . 'index.php') ) |
1250 } |
1245 @ touch($this->backup_dir . 'index.php'); |
1251 ?> |
1246 ?><div class='wrap'> |
1252 <div class='wrap'> |
1247 <h2><?php _e('Backup','wp-db-backup') ?></h2> |
1253 <h2><?php _e( 'Backup', 'wp-db-backup' ); ?></h2> |
1248 <form method="post" action=""> |
1254 <form method="post" action=""> |
1249 <?php if ( function_exists('wp_nonce_field') ) wp_nonce_field($this->referer_check_key); ?> |
1255 <?php |
1250 <fieldset class="options"><legend><?php _e('Tables','wp-db-backup') ?></legend> |
1256 if ( function_exists( 'wp_nonce_field' ) ) { |
1251 <div class="tables-list core-tables alternate"> |
1257 wp_nonce_field( $this->referer_check_key ); |
1252 <h4><?php _e('These core WordPress tables will always be backed up:','wp-db-backup') ?></h4><ul><?php |
1258 } |
1253 $excs = (array) get_option('wp_db_backup_excs'); |
|
1254 foreach ($wp_backup_default_tables as $table) { |
|
1255 if ( $table == $wpdb->comments ) { |
|
1256 $checked = ( isset($excs['spam']) && is_array($excs['spam'] ) && in_array($table, $excs['spam']) ) ? ' checked=\'checked\'' : ''; |
|
1257 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code> <span class='instructions'> <input type='checkbox' name='exclude-spam[]' value='$table' $checked /> " . __('Exclude spam comments', 'wp-db-backup') . '</span></li>'; |
|
1258 } elseif ( function_exists('wp_get_post_revisions') && $table == $wpdb->posts ) { |
|
1259 $checked = ( isset($excs['revisions']) && is_array($excs['revisions'] ) && in_array($table, $excs['revisions']) ) ? ' checked=\'checked\'' : ''; |
|
1260 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code> <span class='instructions'> <input type='checkbox' name='exclude-revisions[]' value='$table' $checked /> " . __('Exclude post revisions', 'wp-db-backup') . '</span></li>'; |
|
1261 } else { |
|
1262 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code></li>"; |
|
1263 } |
|
1264 } |
|
1265 ?></ul> |
|
1266 </div> |
|
1267 <div class="tables-list extra-tables" id="extra-tables-list"> |
|
1268 <?php |
|
1269 if (count($other_tables) > 0) { |
|
1270 ?> |
1259 ?> |
1271 <h4><?php _e('You may choose to include any of the following tables:','wp-db-backup'); ?></h4> |
1260 <fieldset class="options"><legend><?php _e( 'Tables', 'wp-db-backup' ); ?></legend> |
1272 <ul> |
1261 <div class="tables-list core-tables alternate"> |
|
1262 <h4><?php _e( 'These core WordPress tables will always be backed up:', 'wp-db-backup' ); ?></h4> |
|
1263 <ul> |
|
1264 <?php |
|
1265 $excs = (array) get_option( 'wp_db_backup_excs' ); |
|
1266 foreach ( $wp_backup_default_tables as $table ) { |
|
1267 if ( $table == $wpdb->comments ) { |
|
1268 $checked = ( isset( $excs['spam'] ) && is_array( $excs['spam'] ) && in_array( $table, $excs['spam'] ) ) ? ' checked=\'checked\'' : ''; |
|
1269 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code> <span class='instructions'> <input type='checkbox' name='exclude-spam[]' value='$table' $checked /> " . __( 'Exclude spam comments', 'wp-db-backup' ) . '</span></li>'; |
|
1270 } elseif ( function_exists( 'wp_get_post_revisions' ) && $table == $wpdb->posts ) { |
|
1271 $checked = ( isset( $excs['revisions'] ) && is_array( $excs['revisions'] ) && in_array( $table, $excs['revisions'] ) ) ? ' checked=\'checked\'' : ''; |
|
1272 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code> <span class='instructions'> <input type='checkbox' name='exclude-revisions[]' value='$table' $checked /> " . __( 'Exclude post revisions', 'wp-db-backup' ) . '</span></li>'; |
|
1273 } else { |
|
1274 echo "<li><input type='hidden' name='core_tables[]' value='$table' /><code>$table</code></li>"; |
|
1275 } |
|
1276 } |
|
1277 ?> |
|
1278 </ul> |
|
1279 </div> |
|
1280 <div class="tables-list extra-tables" id="extra-tables-list"> |
1273 <?php |
1281 <?php |
1274 foreach ($other_tables as $table) { |
1282 if ( count( $other_tables ) > 0 ) { |
1275 ?> |
1283 ?> |
1276 <li><label><input type="checkbox" name="other_tables[]" value="<?php echo $table; ?>" /> <code><?php echo $table; ?></code></label> |
1284 <h4><?php _e( 'You may choose to include any of the following tables:', 'wp-db-backup' ); ?></h4> |
|
1285 <ul> |
|
1286 <?php |
|
1287 foreach ( $other_tables as $table ) { |
|
1288 ?> |
|
1289 <li><label><input type="checkbox" name="other_tables[]" value="<?php echo $table; ?>" /> <code><?php echo $table; ?></code></label> |
|
1290 <?php |
|
1291 } |
|
1292 ?> |
|
1293 </ul> |
1277 <?php |
1294 <?php |
1278 } |
1295 } |
1279 ?></ul><?php |
1296 ?> |
1280 } |
1297 </div> |
1281 ?></div> |
|
1282 </fieldset> |
1298 </fieldset> |
1283 |
1299 |
1284 <fieldset class="options"> |
1300 <fieldset class="options"> |
1285 <legend><?php _e('Backup Options','wp-db-backup'); ?></legend> |
1301 <legend><?php _e( 'Backup Options', 'wp-db-backup' ); ?></legend> |
1286 <p><?php _e('What to do with the backup file:','wp-db-backup'); ?></p> |
1302 <p><?php _e( 'What to do with the backup file:', 'wp-db-backup' ); ?></p> |
1287 <ul> |
1303 <ul> |
1288 <li><label for="do_download"> |
1304 <li><label for="do_download"> |
1289 <input type="radio" checked="checked" id="do_download" name="deliver" value="http" style="border:none;" /> |
1305 <input type="radio" checked="checked" id="do_download" name="deliver" value="http" style="border:none;" /> |
1290 <?php _e('Download to your computer','wp-db-backup'); ?> |
1306 <?php _e( 'Download to your computer', 'wp-db-backup' ); ?> |
1291 </label></li> |
1307 </label></li> |
1292 <li><label for="do_email"> |
1308 <li><label for="do_email"> |
1293 <input type="radio" name="deliver" id="do_email" value="smtp" style="border:none;" /> |
1309 <input type="radio" name="deliver" id="do_email" value="smtp" style="border:none;" /> |
1294 <?php _e('Email backup to:','wp-db-backup'); ?> |
1310 <?php |
1295 <input type="text" name="backup_recipient" size="20" value="<?php |
1311 $backup_recip = get_option( 'wpdb_backup_recip' ); |
1296 $backup_recip = get_option('wpdb_backup_recip'); |
1312 if ( empty( $backup_recip ) ) { |
1297 if ( empty( $backup_recip ) ) { |
1313 $backup_recip = get_option( 'admin_email' ); |
1298 $backup_recip = get_option('admin_email'); |
1314 } |
1299 } |
1315 _e( 'Email backup to:', 'wp-db-backup' ); |
1300 |
1316 ?> |
1301 echo $backup_recip; ?>" /> |
1317 <input type="text" name="backup_recipient" size="20" value="<?php echo esc_attr( $backup_recip ); ?>" /> |
1302 </label></li> |
1318 </label></li> |
1303 </ul> |
1319 </ul> |
1304 <?php if ( ! $whoops ) : ?> |
1320 <?php if ( ! $whoops ) : ?> |
1305 <input type="hidden" name="do_backup" id="do_backup" value="backup" /> |
1321 <input type="hidden" name="do_backup" id="do_backup" value="backup" /> |
1306 <p class="submit"> |
1322 <p class="submit"> |
1307 <input type="submit" name="submit" onclick="document.getElementById('do_backup').value='fragments';" value="<?php _e('Backup now!','wp-db-backup'); ?>" /> |
1323 <input type="submit" name="submit" onclick="document.getElementById('do_backup').value='fragments';" value="<?php _e( 'Backup now!', 'wp-db-backup' ); ?>" /> |
1308 </p> |
1324 </p> |
1309 <?php else : ?> |
1325 <?php else : ?> |
1310 <div class="updated wp-db-backup-updated error"><p><?php _e('WARNING: Your backup directory is <strong>NOT</strong> writable!','wp-db-backup'); ?></p></div> |
1326 <div class="updated wp-db-backup-updated error"><p><?php _e( 'WARNING: Your backup directory is <strong>NOT</strong> writable!', 'wp-db-backup' ); ?></p></div> |
1311 <?php endif; // ! whoops ?> |
1327 <?php endif; // ! whoops ?> |
1312 </fieldset> |
1328 </fieldset> |
1313 <?php do_action('wp_db_b_backup_opts'); ?> |
1329 <?php do_action( 'wp_db_b_backup_opts' ); ?> |
1314 </form> |
1330 </form> |
1315 |
1331 |
1316 <?php |
1332 <?php |
1317 // this stuff only displays if some sort of wp-cron is available |
1333 // this stuff only displays if some sort of wp-cron is available |
1318 $cron = ( function_exists('wp_schedule_event') ) ? true : false; // wp-cron in WP 2.1+ |
1334 $cron = ( function_exists( 'wp_schedule_event' ) ) ? true : false; // wp-cron in WP 2.1+ |
1319 $cron_old = ( function_exists('wp_cron_init') && ! $cron ) ? true : false; // wp-cron plugin by Skippy |
1335 $cron_old = ( function_exists( 'wp_cron_init' ) && ! $cron ) ? true : false; // wp-cron plugin by Skippy |
|
1336 |
1320 if ( $cron_old || $cron ) : |
1337 if ( $cron_old || $cron ) : |
1321 echo '<fieldset class="options"><legend>' . __('Scheduled Backup','wp-db-backup') . '</legend>'; |
1338 echo '<fieldset class="options"><legend>' . __( 'Scheduled Backup', 'wp-db-backup' ) . '</legend>'; |
1322 $datetime = get_option('date_format') . ' ' . get_option('time_format'); |
1339 $datetime = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); |
1323 if ( $cron ) : |
1340 if ( $cron ) : |
1324 $next_cron = wp_next_scheduled('wp_db_backup_cron'); |
1341 $next_cron = wp_next_scheduled( 'wp_db_backup_cron' ); |
1325 if ( ! empty( $next_cron ) ) : |
1342 if ( ! empty( $next_cron ) ) : |
1326 ?> |
1343 ?> |
1327 <p id="backup-time-wrap"> |
1344 <p id="backup-time-wrap"> |
1328 <?php printf(__('Next Backup: %s','wp-db-backup'), '<span id="next-backup-time">' . gmdate($datetime, $next_cron + (get_option('gmt_offset') * 3600)) . '</span>'); ?> |
1345 <?php printf( __( 'Next Backup: %s', 'wp-db-backup' ), '<span id="next-backup-time">' . gmdate( $datetime, $next_cron + ( get_option( 'gmt_offset' ) * 3600 ) ) . '</span>' ); ?> |
1329 </p> |
1346 </p> |
1330 <?php |
1347 <?php |
1331 endif; |
1348 endif; |
1332 elseif ( $cron_old ) : |
1349 elseif ( $cron_old ) : |
1333 ?><p><?php printf(__('Last WP-Cron Daily Execution: %s','wp-db-backup'), gmdate($datetime, get_option('wp_cron_daily_lastrun') + (get_option('gmt_offset') * 3600))); ?><br /><?php |
1350 ?> |
1334 printf(__('Next WP-Cron Daily Execution: %s','wp-db-backup'), gmdate($datetime, (get_option('wp_cron_daily_lastrun') + (get_option('gmt_offset') * 3600) + 86400))); ?></p><?php |
1351 <p><?php printf( __( 'Last WP-Cron Daily Execution: %s', 'wp-db-backup' ), gmdate( $datetime, get_option( 'wp_cron_daily_lastrun' ) + ( get_option( 'gmt_offset' ) * 3600 ) ) ); ?><br /> |
|
1352 <?php |
|
1353 printf( __( 'Next WP-Cron Daily Execution: %s', 'wp-db-backup' ), gmdate( $datetime, ( get_option( 'wp_cron_daily_lastrun' ) + ( get_option( 'gmt_offset' ) * 3600 ) + 86400 ) ) ); |
|
1354 ?> |
|
1355 </p> |
|
1356 <?php |
1335 endif; |
1357 endif; |
1336 ?><form method="post" action=""> |
1358 ?> |
1337 <?php if ( function_exists('wp_nonce_field') ) wp_nonce_field($this->referer_check_key); ?> |
1359 <form method="post" action=""> |
|
1360 <?php |
|
1361 if ( function_exists( 'wp_nonce_field' ) ) { |
|
1362 wp_nonce_field( $this->referer_check_key );} |
|
1363 ?> |
1338 <div class="tables-list"> |
1364 <div class="tables-list"> |
1339 <h4><?php _e('Schedule: ','wp-db-backup'); ?></h4> |
1365 <h4><?php _e( 'Schedule: ', 'wp-db-backup' ); ?></h4> |
1340 <?php |
1366 <?php |
1341 if ( $cron_old ) : |
1367 if ( $cron_old ) : |
1342 $wp_cron_backup_schedule = get_option('wp_cron_backup_schedule'); |
1368 $wp_cron_backup_schedule = get_option( 'wp_cron_backup_schedule' ); |
1343 $schedule = array(0 => __('None','wp-db-backup'), 1 => __('Daily','wp-db-backup')); |
1369 $schedule = array( |
1344 foreach ($schedule as $value => $name) { |
1370 0 => __( 'None', 'wp-db-backup' ), |
|
1371 1 => __( 'Daily', 'wp-db-backup' ), |
|
1372 ); |
|
1373 foreach ( $schedule as $value => $name ) { |
1345 echo ' <input type="radio" style="border:none;" name="cron_schedule"'; |
1374 echo ' <input type="radio" style="border:none;" name="cron_schedule"'; |
1346 if ($wp_cron_backup_schedule == $value) { |
1375 if ( $wp_cron_backup_schedule == $value ) { |
1347 echo ' checked="checked" '; |
1376 echo ' checked="checked" '; |
1348 } |
1377 } |
1349 echo 'value="' . $value . '" /> ' . $name; |
1378 echo 'value="' . $value . '" /> ' . $name; |
1350 } |
1379 } |
1351 elseif ( $cron ) : |
1380 elseif ( $cron ) : |
1352 echo apply_filters('wp_db_b_schedule_choices', wp_get_schedules() ); |
1381 echo apply_filters( 'wp_db_b_schedule_choices', wp_get_schedules() ); |
1353 endif; |
1382 endif; |
1354 $cron_recipient = get_option('wp_cron_backup_recipient'); |
1383 |
1355 if (! is_email($cron_recipient)) { |
1384 $cron_recipient = get_option( 'wp_cron_backup_recipient' ); |
1356 $cron_recipient = get_option('admin_email'); |
1385 |
1357 } |
1386 if ( ! is_email( $cron_recipient ) ) { |
1358 $cron_recipient_input = '<p><label for="cron_backup_recipient">' . __('Email backup to:','wp-db-backup') . ' <input type="text" name="cron_backup_recipient" id="cron_backup_recipient" size="20" value="' . $cron_recipient . '" /></label></p>'; |
1387 $cron_recipient = get_option( 'admin_email' ); |
1359 echo apply_filters('wp_db_b_cron_recipient_input', $cron_recipient_input); |
1388 } |
1360 echo '<p class="submit"><input type="submit" name="submit" value="' . __('Schedule backup','wp-db-backup') . '" /></p>'; |
1389 |
|
1390 $cron_recipient_input = '<p><label for="cron_backup_recipient">' . __( 'Email backup to:', 'wp-db-backup' ) . ' <input type="text" name="cron_backup_recipient" id="cron_backup_recipient" size="20" value="' . $cron_recipient . '" /></label></p>'; |
|
1391 echo apply_filters( 'wp_db_b_cron_recipient_input', $cron_recipient_input ); |
|
1392 echo '<p class="submit"><input type="submit" name="submit" value="' . __( 'Schedule backup', 'wp-db-backup' ) . '" /></p>'; |
1361 echo '</div>'; |
1393 echo '</div>'; |
1362 $cron_tables = get_option('wp_cron_backup_tables'); |
1394 $cron_tables = get_option( 'wp_cron_backup_tables' ); |
1363 if (! is_array($cron_tables)) { |
1395 |
|
1396 if ( ! is_array( $cron_tables ) ) { |
1364 $cron_tables = array(); |
1397 $cron_tables = array(); |
1365 } |
1398 } |
1366 if (count($other_tables) > 0) { |
1399 |
|
1400 if ( count( $other_tables ) > 0 ) { |
1367 echo '<div class="tables-list alternate" id="include-tables-list">'; |
1401 echo '<div class="tables-list alternate" id="include-tables-list">'; |
1368 echo '<h4>' . __('Tables to include in the scheduled backup:','wp-db-backup') . '</h4><ul>'; |
1402 echo '<h4>' . __( 'Tables to include in the scheduled backup:', 'wp-db-backup' ) . '</h4><ul>'; |
1369 foreach ($other_tables as $table) { |
1403 foreach ( $other_tables as $table ) { |
1370 echo '<li><input type="checkbox" '; |
1404 echo '<li><input type="checkbox" '; |
1371 if (in_array($table, $cron_tables)) { |
1405 if ( in_array( $table, $cron_tables ) ) { |
1372 echo 'checked="checked" '; |
1406 echo 'checked="checked" '; |
1373 } |
1407 } |
1374 echo "name='wp_cron_backup_tables[]' value='{$table}' /> <code>{$table}</code></li>"; |
1408 echo "name='wp_cron_backup_tables[]' value='{$table}' /> <code>{$table}</code></li>"; |
1375 } |
1409 } |
1376 echo '</ul></div>'; |
1410 echo '</ul></div>'; |
1377 } |
1411 } |
|
1412 |
1378 echo '<input type="hidden" name="wp_cron_backup_options" value="SET" /></form>'; |
1413 echo '<input type="hidden" name="wp_cron_backup_options" value="SET" /></form>'; |
1379 echo '</fieldset>'; |
1414 echo '</fieldset>'; |
1380 endif; // end of wp_cron (legacy) section |
1415 endif; // end of wp_cron (legacy) section |
1381 |
1416 |
1382 echo '</div><!-- .wrap -->'; |
1417 echo '</div><!-- .wrap -->'; |
1383 |
1418 |
1384 } // end wp_backup_menu() |
1419 } // end wp_backup_menu() |
1385 |
1420 |
1386 function get_sched() { |
1421 function get_sched() { |
1387 $options = array_keys( (array) wp_get_schedules() ); |
1422 $options = array_keys( (array) wp_get_schedules() ); |
1388 $freq = get_option('wp_cron_backup_schedule'); |
1423 $freq = get_option( 'wp_cron_backup_schedule' ); |
1389 $freq = ( in_array( $freq , $options ) ) ? $freq : 'never'; |
1424 $freq = ( in_array( $freq, $options ) ) ? $freq : 'never'; |
|
1425 |
1390 return $freq; |
1426 return $freq; |
1391 } |
1427 } |
1392 |
1428 |
1393 function schedule_choices($schedule) { // create the cron menu based on the schedule |
1429 function schedule_choices( $schedule ) { |
|
1430 // create the cron menu based on the schedule |
1394 $wp_cron_backup_schedule = $this->get_sched(); |
1431 $wp_cron_backup_schedule = $this->get_sched(); |
1395 $next_cron = wp_next_scheduled('wp_db_backup_cron'); |
1432 $next_cron = wp_next_scheduled( 'wp_db_backup_cron' ); |
1396 $wp_cron_backup_schedule = ( empty( $next_cron ) ) ? 'never' : $wp_cron_backup_schedule; |
1433 $wp_cron_backup_schedule = ( empty( $next_cron ) ) ? 'never' : $wp_cron_backup_schedule; |
1397 $sort = array(); |
1434 $sort = array(); |
1398 foreach ( (array) $schedule as $key => $value ) $sort[$key] = $value['interval']; |
1435 |
|
1436 foreach ( (array) $schedule as $key => $value ) { |
|
1437 $sort[ $key ] = $value['interval']; |
|
1438 } |
1399 asort( $sort ); |
1439 asort( $sort ); |
|
1440 |
1400 $schedule_sorted = array(); |
1441 $schedule_sorted = array(); |
1401 foreach ( (array) $sort as $key => $value ) $schedule_sorted[$key] = $schedule[$key]; |
1442 foreach ( (array) $sort as $key => $value ) { |
1402 $menu = '<ul>'; |
1443 $schedule_sorted[ $key ] = $schedule[ $key ]; |
1403 $schedule = array_merge( array( 'never' => array( 'interval' => 0, 'display' => __('Never','wp-db-backup') ) ), |
1444 } |
1404 (array) $schedule_sorted ); |
1445 |
1405 foreach ( $schedule as $name => $settings) { |
1446 $menu = '<ul>'; |
|
1447 $schedule = array_merge( |
|
1448 array( |
|
1449 'never' => array( |
|
1450 'interval' => 0, |
|
1451 'display' => __( 'Never', 'wp-db-backup' ), |
|
1452 ), |
|
1453 ), |
|
1454 (array) $schedule_sorted |
|
1455 ); |
|
1456 |
|
1457 foreach ( $schedule as $name => $settings ) { |
1406 $interval = (int) $settings['interval']; |
1458 $interval = (int) $settings['interval']; |
1407 if ( 0 == $interval && ! 'never' == $name ) continue; |
1459 if ( 0 == $interval && ! 'never' == $name ) { |
1408 $display = ( ! '' == $settings['display'] ) ? $settings['display'] : sprintf(__('%s seconds','wp-db-backup'),$interval); |
1460 continue; |
1409 $menu .= "<li><input type='radio' name='wp_cron_schedule' style='border:none;' "; |
1461 } |
1410 if ($wp_cron_backup_schedule == $name) { |
1462 $display = ( ! '' == $settings['display'] ) ? $settings['display'] : sprintf( __( '%s seconds', 'wp-db-backup' ), $interval ); |
|
1463 $menu .= "<li><input type='radio' name='wp_cron_schedule' style='border:none;' "; |
|
1464 if ( $wp_cron_backup_schedule == $name ) { |
1411 $menu .= " checked='checked' "; |
1465 $menu .= " checked='checked' "; |
1412 } |
1466 } |
1413 $menu .= "value='$name' /> $display</li>"; |
1467 $menu .= "value='$name' /> $display</li>"; |
1414 } |
1468 } |
|
1469 |
1415 $menu .= '</ul>'; |
1470 $menu .= '</ul>'; |
|
1471 |
1416 return $menu; |
1472 return $menu; |
1417 } // end schedule_choices() |
1473 } // end schedule_choices() |
1418 |
1474 |
1419 function wp_cron_daily() { // for legacy cron plugin |
1475 function wp_cron_daily() { |
1420 $schedule = intval(get_option('wp_cron_backup_schedule')); |
1476 // for legacy cron plugin |
|
1477 $schedule = intval( get_option( 'wp_cron_backup_schedule' ) ); |
|
1478 |
1421 // If scheduled backup is disabled |
1479 // If scheduled backup is disabled |
1422 if (0 == $schedule) |
1480 if ( 0 == $schedule ) { |
1423 return; |
1481 return; |
1424 else return $this->cron_backup(); |
1482 } else { |
|
1483 return $this->cron_backup(); |
|
1484 } |
1425 } |
1485 } |
1426 |
1486 |
1427 function cron_backup() { |
1487 function cron_backup() { |
1428 global $table_prefix, $wpdb; |
1488 global $table_prefix, $wpdb; |
1429 $all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N); |
1489 |
1430 $all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables); |
1490 $all_tables = $wpdb->get_results( 'SHOW TABLES', ARRAY_N ); |
1431 $core_tables = array_intersect($all_tables, $this->core_table_names); |
1491 $all_tables = array_map( |
1432 $other_tables = get_option('wp_cron_backup_tables'); |
1492 function( $a ) { |
1433 $recipient = get_option('wp_cron_backup_recipient'); |
1493 return $a[0]; |
1434 $backup_file = $this->db_backup($core_tables, $other_tables); |
1494 }, |
1435 if (false !== $backup_file) |
1495 $all_tables |
1436 return $this->deliver_backup($backup_file, 'smtp', $recipient, 'main'); |
1496 ); |
1437 else return false; |
1497 $core_tables = array_intersect( $all_tables, $this->core_table_names ); |
1438 } |
1498 $other_tables = get_option( 'wp_cron_backup_tables' ); |
1439 |
1499 $recipient = get_option( 'wp_cron_backup_recipient' ); |
1440 function add_sched_options($sched) { |
1500 $backup_file = $this->db_backup( $core_tables, $other_tables ); |
1441 $sched['weekly'] = array('interval' => 604800, 'display' => __('Once Weekly','wp-db-backup')); |
1501 |
|
1502 if ( false !== $backup_file ) { |
|
1503 return $this->deliver_backup( $backup_file, 'smtp', $recipient, 'main' ); |
|
1504 } else { |
|
1505 return false; |
|
1506 } |
|
1507 } |
|
1508 |
|
1509 function add_sched_options( $sched ) { |
|
1510 $sched['weekly'] = array( |
|
1511 'interval' => 604800, |
|
1512 'display' => __( 'Once Weekly', 'wp-db-backup' ), |
|
1513 ); |
|
1514 |
1442 return $sched; |
1515 return $sched; |
1443 } |
1516 } |
1444 |
1517 |
1445 /** |
1518 /** |
1446 * Checks that WordPress has sufficient security measures |
1519 * Checks that WordPress has sufficient security measures |
1447 * @param string $kind |
1520 * @param string $kind |
1448 * @return bool |
1521 * @return bool |
1449 */ |
1522 */ |
1450 function wp_secure($kind = 'warn', $loc = 'main') { |
1523 function wp_secure( $kind = 'warn', $loc = 'main' ) { |
1451 global $wp_version; |
1524 global $wp_version; |
1452 if ( function_exists('wp_verify_nonce') ) return true; |
1525 |
1453 else { |
1526 if ( function_exists( 'wp_verify_nonce' ) ) { |
1454 $this->error(array('kind' => $kind, 'loc' => $loc, 'msg' => sprintf(__('Your WordPress version, %1s, lacks important security features without which it is unsafe to use the WP-DB-Backup plugin. Hence, this plugin is automatically disabled. Please consider <a href="%2s">upgrading WordPress</a> to a more recent version.','wp-db-backup'),$wp_version,'http://wordpress.org/download/'))); |
1527 return true; |
|
1528 } else { |
|
1529 $this->error( |
|
1530 array( |
|
1531 'kind' => $kind, |
|
1532 'loc' => $loc, |
|
1533 'msg' => sprintf( |
|
1534 __( |
|
1535 'Your WordPress version, %1$1s, lacks important security features without which it is unsafe to use the WP-DB-Backup plugin. Hence, this plugin is automatically disabled. Please consider <a href="%2$2s">upgrading WordPress</a> to a more recent version.', |
|
1536 'wp-db-backup' |
|
1537 ), |
|
1538 $wp_version, |
|
1539 'http://wordpress.org/download/' |
|
1540 ), |
|
1541 ) |
|
1542 ); |
|
1543 |
1455 return false; |
1544 return false; |
1456 } |
1545 } |
1457 } |
1546 } |
1458 |
1547 |
1459 /** |
1548 /** |
1460 * Checks that the user has sufficient permission to backup |
1549 * Checks that the user has sufficient permission to backup |
1461 * @param string $loc |
1550 * @param string $loc |
1462 * @return bool |
1551 * @return bool |
1463 */ |
1552 */ |
1464 function can_user_backup($loc = 'main') { |
1553 function can_user_backup( $loc = 'main' ) { |
1465 $can = false; |
1554 $can = false; |
|
1555 |
1466 // make sure WPMU users are site admins, not ordinary admins |
1556 // make sure WPMU users are site admins, not ordinary admins |
1467 if ( function_exists('is_site_admin') && ! is_site_admin() ) |
1557 if ( function_exists( 'is_site_admin' ) && ! is_site_admin() ) { |
1468 return false; |
1558 return false; |
1469 if ( ( $this->wp_secure('fatal', $loc) ) && current_user_can('import') ) |
1559 } |
1470 $can = $this->verify_nonce($_REQUEST['_wpnonce'], $this->referer_check_key, $loc); |
1560 |
1471 if ( false == $can ) |
1561 if ( ( $this->wp_secure( 'fatal', $loc ) ) && current_user_can( 'import' ) ) { |
1472 $this->error(array('loc' => $loc, 'kind' => 'fatal', 'msg' => __('You are not allowed to perform backups.','wp-db-backup'))); |
1562 $can = $this->verify_nonce( $_REQUEST['_wpnonce'], $this->referer_check_key, $loc ); |
|
1563 } |
|
1564 |
|
1565 if ( false == $can ) { |
|
1566 $this->error( |
|
1567 array( |
|
1568 'loc' => $loc, |
|
1569 'kind' => 'fatal', |
|
1570 'msg' => __( |
|
1571 'You are not allowed to perform backups.', |
|
1572 'wp-db-backup' |
|
1573 ), |
|
1574 ) |
|
1575 ); |
|
1576 } |
|
1577 |
1473 return $can; |
1578 return $can; |
1474 } |
1579 } |
1475 |
1580 |
1476 /** |
1581 /** |
1477 * Verify that the nonce is legitimate |
1582 * Verify that the nonce is legitimate |
1478 * @param string $rec the nonce received |
1583 * @param string $rec the nonce received |
1479 * @param string $nonce what the nonce should be |
1584 * @param string $nonce what the nonce should be |
1480 * @param string $loc the location of the check |
1585 * @param string $loc the location of the check |
1481 * @return bool |
1586 * @return bool |
1482 */ |
1587 */ |
1483 function verify_nonce($rec = '', $nonce = 'X', $loc = 'main') { |
1588 function verify_nonce( $rec = '', $nonce = 'X', $loc = 'main' ) { |
1484 if ( wp_verify_nonce($rec, $nonce) ) |
1589 if ( wp_verify_nonce( $rec, $nonce ) ) { |
1485 return true; |
1590 return true; |
1486 else |
1591 } else { |
1487 $this->error(array('loc' => $loc, 'kind' => 'fatal', 'msg' => sprintf(__('There appears to be an unauthorized attempt from this site to access your database located at %1s. The attempt has been halted.','wp-db-backup'),get_option('home')))); |
1592 $this->error( |
|
1593 array( |
|
1594 'loc' => $loc, |
|
1595 'kind' => 'fatal', |
|
1596 'msg' => sprintf( |
|
1597 __( |
|
1598 'There appears to be an unauthorized attempt from this site to access your database located at %1s. The attempt has been halted.', |
|
1599 'wp-db-backup' |
|
1600 ), |
|
1601 get_option( 'home' ) |
|
1602 ), |
|
1603 ) |
|
1604 ); |
|
1605 } |
1488 } |
1606 } |
1489 |
1607 |
1490 /** |
1608 /** |
1491 * Check whether a file to be downloaded is |
1609 * Check whether a file to be downloaded is |
1492 * surreptitiously trying to download a non-backup file |
1610 * surreptitiously trying to download a non-backup file |
1493 * @param string $file |
1611 * @param string $file |
1494 * @return null |
1612 * @return null |
1495 */ |
1613 */ |
1496 function validate_file($file) { |
1614 function validate_file( $file ) { |
1497 if ( (false !== strpos($file, '..')) || (false !== strpos($file, './')) || (':' == substr($file, 1, 1)) ) |
1615 if ( ( false !== strpos( $file, '..' ) ) || ( false !== strpos( $file, './' ) ) || ( ':' == substr( $file, 1, 1 ) ) ) { |
1498 $this->error(array('kind' => 'fatal', 'loc' => 'frame', 'msg' => __("Cheatin' uh ?",'wp-db-backup'))); |
1616 $this->error( |
|
1617 array( |
|
1618 'kind' => 'fatal', |
|
1619 'loc' => 'frame', |
|
1620 'msg' => __( |
|
1621 "Cheatin' uh ?", |
|
1622 'wp-db-backup' |
|
1623 ), |
|
1624 ) |
|
1625 ); |
|
1626 } |
1499 } |
1627 } |
1500 |
1628 |
1501 /** |
1629 /** |
1502 * Get the sitename by query $_SERVER['SERVER_NAME']. |
1630 * Get the sitename by query $_SERVER['SERVER_NAME']. |
1503 * If it is not set, then use site_url() instead |
1631 * If it is not set, then use site_url() instead |
1504 * @return string |
1632 * @return string |
1505 */ |
1633 */ |
1506 function get_sitename() { |
1634 function get_sitename() { |
1507 $sitename=''; |
1635 $sitename = ''; |
1508 if ( isset($_SERVER['SERVER_NAME']) ) { |
1636 |
|
1637 if ( isset( $_SERVER['SERVER_NAME'] ) ) { |
1509 $sitename = strtolower( sanitize_text_field( $_SERVER['SERVER_NAME'] ) ); |
1638 $sitename = strtolower( sanitize_text_field( $_SERVER['SERVER_NAME'] ) ); |
1510 } else { |
1639 } else { |
1511 if ( function_exists('site_url') ) { |
1640 if ( function_exists( 'site_url' ) ) { |
1512 // site_url() was added since 3.0.0 |
1641 // site_url() was added since 3.0.0 |
1513 // force http scheme so we can easily get rid of leading http:// |
1642 // force http scheme so we can easily get rid of leading http:// |
1514 $sitename = strtolower( site_url( '', 'http' ) ); |
1643 $sitename = strtolower( site_url( '', 'http' ) ); |
1515 $sitename = substr( $sitename, 7 ); |
1644 $sitename = substr( $sitename, 7 ); |
1516 } else { |
1645 } else { |