Version Description
- Sanitize user-supplied data
=
Download this release
Release Info
Developer | filosofo |
Plugin | ![]() |
Version | 2.3.3 |
Comparing to | |
See all releases |
Code changes from version 2.3.1 to 2.3.3
- README.markdown +16 -12
- readme.txt +10 -7
- wp-db-backup.php +247 -164
README.markdown
CHANGED
@@ -5,12 +5,12 @@ Contributors: filosofo
|
|
5 |
Donate link: http://austinmatzko.com/wordpress-plugins/wp-db-backup/
|
6 |
Tags: mysql, database, backup, cron
|
7 |
Requires at least: 3.6.0
|
8 |
-
Tested up to: 4.
|
9 |
-
Stable tag: 2.3.
|
10 |
|
11 |
On-demand backup of your WordPress database.
|
12 |
|
13 |
-
Description
|
14 |
-----------
|
15 |
|
16 |
WP-DB-Backup allows you easily to backup your core WordPress database tables. You may also backup other tables in the same database.
|
@@ -20,11 +20,11 @@ Released under the terms of the GNU GPL, version 2.
|
|
20 |
|
21 |
NO WARRANTY.
|
22 |
|
23 |
-
Copyright (c)
|
24 |
|
25 |
[Source Code on GitHub](https://github.com/matzko/wp-db-backup)
|
26 |
|
27 |
-
Installation
|
28 |
------------
|
29 |
|
30 |
1. Extract the wp-db-backup/ folder file to /wp-content/plugins/
|
@@ -104,7 +104,7 @@ date = CCYYmmdd_B format: 20050711_039
|
|
104 |
|
105 |
When having the database backup emailed or sent to your browser for immediate download, the backup file will be _deleted_ from the server when the transfer is finished.
|
106 |
|
107 |
-
Changelog
|
108 |
---------
|
109 |
|
110 |
2.3.0
|
@@ -116,27 +116,31 @@ Changelog
|
|
116 |
* Remove deprecated functionality
|
117 |
* Do not attempt to delete non-existent files
|
118 |
|
119 |
-
2.2.3
|
120 |
-----
|
121 |
* Nonce check fix for localized WP users from Sergey Biryukov
|
122 |
* Fix for gzipped files' incorrect size.
|
123 |
* Some styling improvements.
|
124 |
* Fix for JS multiple checkbox selection.
|
125 |
|
126 |
-
|
|
|
|
|
|
|
|
|
127 |
--------------
|
128 |
|
129 |
-
2.2.3
|
130 |
-----
|
131 |
* Fixes problems users had when using localized WordPress installations.
|
132 |
* Fixes a bug that caused the size of gzipped backup files to be reported incorrectly.
|
133 |
|
134 |
-
Advanced
|
135 |
--------
|
136 |
If you are using WordPress version 2.1 or newer, you can schedule automated backups to be sent to the email address
|
137 |
of your choice.
|
138 |
|
139 |
-
Translators
|
140 |
-----------
|
141 |
Thanks to following people for providing translation files for WP-DB-Backup:
|
142 |
|
@@ -173,6 +177,6 @@ Thanks to following people for providing translation files for WP-DB-Backup:
|
|
173 |
* Tzafrir Rehan
|
174 |
* 吴曦
|
175 |
|
176 |
-
Past Contributors
|
177 |
-----------------
|
178 |
skippy, Firas, LaughingLizard, MtDewVirus, Podz, Ringmaster
|
5 |
Donate link: http://austinmatzko.com/wordpress-plugins/wp-db-backup/
|
6 |
Tags: mysql, database, backup, cron
|
7 |
Requires at least: 3.6.0
|
8 |
+
Tested up to: 4.9.2
|
9 |
+
Stable tag: 2.3.3
|
10 |
|
11 |
On-demand backup of your WordPress database.
|
12 |
|
13 |
+
Description
|
14 |
-----------
|
15 |
|
16 |
WP-DB-Backup allows you easily to backup your core WordPress database tables. You may also backup other tables in the same database.
|
20 |
|
21 |
NO WARRANTY.
|
22 |
|
23 |
+
Copyright (c) 2018 Austin Matzko
|
24 |
|
25 |
[Source Code on GitHub](https://github.com/matzko/wp-db-backup)
|
26 |
|
27 |
+
Installation
|
28 |
------------
|
29 |
|
30 |
1. Extract the wp-db-backup/ folder file to /wp-content/plugins/
|
104 |
|
105 |
When having the database backup emailed or sent to your browser for immediate download, the backup file will be _deleted_ from the server when the transfer is finished.
|
106 |
|
107 |
+
Changelog
|
108 |
---------
|
109 |
|
110 |
2.3.0
|
116 |
* Remove deprecated functionality
|
117 |
* Do not attempt to delete non-existent files
|
118 |
|
119 |
+
2.2.3
|
120 |
-----
|
121 |
* Nonce check fix for localized WP users from Sergey Biryukov
|
122 |
* Fix for gzipped files' incorrect size.
|
123 |
* Some styling improvements.
|
124 |
* Fix for JS multiple checkbox selection.
|
125 |
|
126 |
+
2.3.3
|
127 |
+
-----
|
128 |
+
* Sanitize user-supplied data
|
129 |
+
|
130 |
+
Upgrade Notice
|
131 |
--------------
|
132 |
|
133 |
+
2.2.3
|
134 |
-----
|
135 |
* Fixes problems users had when using localized WordPress installations.
|
136 |
* Fixes a bug that caused the size of gzipped backup files to be reported incorrectly.
|
137 |
|
138 |
+
Advanced
|
139 |
--------
|
140 |
If you are using WordPress version 2.1 or newer, you can schedule automated backups to be sent to the email address
|
141 |
of your choice.
|
142 |
|
143 |
+
Translators
|
144 |
-----------
|
145 |
Thanks to following people for providing translation files for WP-DB-Backup:
|
146 |
|
177 |
* Tzafrir Rehan
|
178 |
* 吴曦
|
179 |
|
180 |
+
Past Contributors
|
181 |
-----------------
|
182 |
skippy, Firas, LaughingLizard, MtDewVirus, Podz, Ringmaster
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: filosofo
|
|
3 |
Donate link: http://austinmatzko.com/wordpress-plugins/wp-db-backup/
|
4 |
Tags: mysql, database, backup, cron
|
5 |
Requires at least: 3.6.0
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 2.3.
|
8 |
|
9 |
On-demand backup of your WordPress database.
|
10 |
|
@@ -17,7 +17,7 @@ Released under the terms of the GNU GPL, version 2.
|
|
17 |
|
18 |
NO WARRANTY.
|
19 |
|
20 |
-
Copyright (c)
|
21 |
|
22 |
[Source Code on GitHub](https://github.com/matzko/wp-db-backup)
|
23 |
|
@@ -25,7 +25,7 @@ Released under the terms of the GNU GPL, version 2.
|
|
25 |
1. Extract the wp-db-backup/ folder file to /wp-content/plugins/
|
26 |
1. Activate the plugin at your blog's Admin -> Plugins screen
|
27 |
1. The plugin will attempt to create a directory /wp-content/backup-*/ inside your WordPress directory.
|
28 |
-
1. You may need to make /wp-content writable (at least temporarily) for it to create this directory.
|
29 |
For example:
|
30 |
`$ cd /wordpress/`
|
31 |
`$ chgrp www-data wp-content` (where "`www-data`" is the group your FTP client uses)
|
@@ -87,7 +87,7 @@ The filename of the backup file will be of the form
|
|
87 |
DB = the name of your WordPress database, as defined in wp-config.php
|
88 |
prefix = the table prefix for this WordPress blog, as defined in wp-config.php
|
89 |
date = CCYYmmdd_B format: 20050711_039
|
90 |
-
the "B" is the internet "Swatch" time.
|
91 |
See the PHP date() function for details.
|
92 |
|
93 |
When having the database backup emailed or sent to your browser for immediate download, the backup file will be _deleted_ from the server when the transfer is finished.
|
@@ -101,7 +101,7 @@ When having the database backup emailed or sent to your browser for immediate do
|
|
101 |
* Remove deprecated functionality
|
102 |
* Do not attempt to delete non-existent files
|
103 |
|
104 |
-
= 2.2.3 =
|
105 |
* Nonce check fix for localized WP users from Sergey Biryukov
|
106 |
* Fix for gzipped files' incorrect size.
|
107 |
* Some styling improvements.
|
@@ -113,8 +113,11 @@ When having the database backup emailed or sent to your browser for immediate do
|
|
113 |
* Fixes problems users had when using localized WordPress installations.
|
114 |
* Fixes a bug that caused the size of gzipped backup files to be reported incorrectly.
|
115 |
|
|
|
|
|
|
|
116 |
== Advanced ==
|
117 |
-
If you are using WordPress version 2.1 or newer, you can schedule automated backups to be sent to the email address
|
118 |
of your choice.
|
119 |
|
120 |
== Translators ==
|
3 |
Donate link: http://austinmatzko.com/wordpress-plugins/wp-db-backup/
|
4 |
Tags: mysql, database, backup, cron
|
5 |
Requires at least: 3.6.0
|
6 |
+
Tested up to: 4.9.2
|
7 |
+
Stable tag: 2.3.3
|
8 |
|
9 |
On-demand backup of your WordPress database.
|
10 |
|
17 |
|
18 |
NO WARRANTY.
|
19 |
|
20 |
+
Copyright (c) 2018 Austin Matzko
|
21 |
|
22 |
[Source Code on GitHub](https://github.com/matzko/wp-db-backup)
|
23 |
|
25 |
1. Extract the wp-db-backup/ folder file to /wp-content/plugins/
|
26 |
1. Activate the plugin at your blog's Admin -> Plugins screen
|
27 |
1. The plugin will attempt to create a directory /wp-content/backup-*/ inside your WordPress directory.
|
28 |
+
1. You may need to make /wp-content writable (at least temporarily) for it to create this directory.
|
29 |
For example:
|
30 |
`$ cd /wordpress/`
|
31 |
`$ chgrp www-data wp-content` (where "`www-data`" is the group your FTP client uses)
|
87 |
DB = the name of your WordPress database, as defined in wp-config.php
|
88 |
prefix = the table prefix for this WordPress blog, as defined in wp-config.php
|
89 |
date = CCYYmmdd_B format: 20050711_039
|
90 |
+
the "B" is the internet "Swatch" time.
|
91 |
See the PHP date() function for details.
|
92 |
|
93 |
When having the database backup emailed or sent to your browser for immediate download, the backup file will be _deleted_ from the server when the transfer is finished.
|
101 |
* Remove deprecated functionality
|
102 |
* Do not attempt to delete non-existent files
|
103 |
|
104 |
+
= 2.2.3 =
|
105 |
* Nonce check fix for localized WP users from Sergey Biryukov
|
106 |
* Fix for gzipped files' incorrect size.
|
107 |
* Some styling improvements.
|
113 |
* Fixes problems users had when using localized WordPress installations.
|
114 |
* Fixes a bug that caused the size of gzipped backup files to be reported incorrectly.
|
115 |
|
116 |
+
= 2.3.3 =
|
117 |
+
* Sanitize user-supplied data
|
118 |
+
|
119 |
== Advanced ==
|
120 |
+
If you are using WordPress version 2.1 or newer, you can schedule automated backups to be sent to the email address
|
121 |
of your choice.
|
122 |
|
123 |
== Translators ==
|
wp-db-backup.php
CHANGED
@@ -3,11 +3,11 @@
|
|
3 |
Plugin Name: WordPress Database Backup
|
4 |
Plugin URI: https://github.com/matzko/wp-db-backup
|
5 |
Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup">Tools → Backup</a> to get started.
|
6 |
-
Author: Austin Matzko
|
7 |
Author URI: http://austinmatzko.com/
|
8 |
-
Version: 2.3.
|
9 |
|
10 |
-
Copyright
|
11 |
|
12 |
This program is free software; you can redistribute it and/or modify
|
13 |
it under the terms of the GNU General Public License as published by
|
@@ -37,9 +37,9 @@ if ( ! defined('ROWS_PER_SEGMENT') ) {
|
|
37 |
define('ROWS_PER_SEGMENT', 100);
|
38 |
}
|
39 |
|
40 |
-
/**
|
41 |
-
* Set MOD_EVASIVE_OVERRIDE to true
|
42 |
-
* and increase MOD_EVASIVE_DELAY
|
43 |
* if the backup stops prematurely.
|
44 |
*/
|
45 |
// define('MOD_EVASIVE_OVERRIDE', false);
|
@@ -57,20 +57,20 @@ class wpdbBackup {
|
|
57 |
var $basename;
|
58 |
var $page_url;
|
59 |
var $referer_check_key;
|
60 |
-
var $version = '2.
|
61 |
|
62 |
function module_check() {
|
63 |
$mod_evasive = false;
|
64 |
if ( defined( 'MOD_EVASIVE_OVERRIDE' ) && true === MOD_EVASIVE_OVERRIDE ) return true;
|
65 |
if ( ! defined( 'MOD_EVASIVE_OVERRIDE' ) || false === MOD_EVASIVE_OVERRIDE ) return false;
|
66 |
-
if ( function_exists('apache_get_modules') )
|
67 |
-
foreach( (array) apache_get_modules() as $mod )
|
68 |
if ( false !== strpos($mod,'mod_evasive') || false !== strpos($mod,'mod_dosevasive') )
|
69 |
return true;
|
70 |
return false;
|
71 |
}
|
72 |
|
73 |
-
function
|
74 |
global $table_prefix, $wpdb;
|
75 |
add_action('wp_ajax_save_backup_time', array(&$this, 'save_backup_time'));
|
76 |
add_action('init', array(&$this, 'init_textdomain'));
|
@@ -80,7 +80,7 @@ class wpdbBackup {
|
|
80 |
add_action('wp_cron_daily', array(&$this, 'wp_cron_daily'));
|
81 |
add_filter('cron_schedules', array(&$this, 'add_sched_options'));
|
82 |
add_filter('wp_db_b_schedule_choices', array(&$this, 'schedule_choices'));
|
83 |
-
|
84 |
$table_prefix = ( isset( $table_prefix ) ) ? $table_prefix : $wpdb->prefix;
|
85 |
$datum = date("Ymd_B");
|
86 |
$this->backup_filename = DB_NAME . "_$table_prefix$datum.sql";
|
@@ -108,27 +108,29 @@ class wpdbBackup {
|
|
108 |
$this->core_table_names[] = $wpdb->{$name};
|
109 |
}
|
110 |
}
|
111 |
-
|
112 |
-
$
|
|
|
113 |
$this->basename = 'wp-db-backup';
|
114 |
-
|
115 |
$this->referer_check_key = $this->basename . '-download_' . DB_NAME;
|
116 |
if (isset($_POST['do_backup'])) {
|
117 |
$this->wp_secure('fatal');
|
118 |
check_admin_referer($this->referer_check_key);
|
119 |
$this->can_user_backup('main');
|
120 |
-
// save exclude prefs
|
121 |
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
125 |
switch($_POST['do_backup']) {
|
126 |
case 'backup':
|
127 |
add_action('init', array(&$this, 'perform_backup'));
|
128 |
break;
|
129 |
case 'fragments':
|
130 |
add_action('admin_menu', array(&$this, 'fragment_menu'));
|
131 |
-
break;
|
132 |
}
|
133 |
} elseif (isset($_GET['fragment'] )) {
|
134 |
$this->can_user_backup('frame');
|
@@ -140,19 +142,19 @@ class wpdbBackup {
|
|
140 |
add_action('admin_menu', array(&$this, 'admin_menu'));
|
141 |
}
|
142 |
}
|
143 |
-
|
144 |
function init() {
|
145 |
$this->can_user_backup();
|
146 |
if (isset($_GET['backup'])) {
|
147 |
-
$via = isset($_GET['via']) ? $_GET['via'] : 'http';
|
148 |
-
|
149 |
-
$this->backup_file = $_GET['backup'];
|
150 |
$this->validate_file($this->backup_file);
|
151 |
|
152 |
switch($via) {
|
153 |
case 'smtp':
|
154 |
case 'email':
|
155 |
-
$success = $this->deliver_backup($this->backup_file, 'smtp', $_GET['recipient'], 'frame');
|
156 |
$this->error_display( 'frame' );
|
157 |
if ( $success ) {
|
158 |
echo '
|
@@ -161,7 +163,7 @@ class wpdbBackup {
|
|
161 |
';
|
162 |
echo '
|
163 |
alert("' . __('Backup Complete!','wp-db-backup') . '");
|
164 |
-
window.onbeforeunload = null;
|
165 |
</script>
|
166 |
';
|
167 |
}
|
@@ -169,7 +171,7 @@ class wpdbBackup {
|
|
169 |
default:
|
170 |
$success = $this->deliver_backup($this->backup_file, $via);
|
171 |
echo $this->error_display( 'frame', false );
|
172 |
-
|
173 |
if ( $success ) {
|
174 |
echo '
|
175 |
<script type="text/javascript">
|
@@ -181,7 +183,7 @@ class wpdbBackup {
|
|
181 |
exit;
|
182 |
}
|
183 |
if (isset($_GET['fragment'] )) {
|
184 |
-
list($table, $segment, $filename) = explode(':', $_GET['fragment']);
|
185 |
$this->validate_file($filename);
|
186 |
$this->backup_fragment($table, $segment, $filename);
|
187 |
}
|
@@ -206,7 +208,7 @@ class wpdbBackup {
|
|
206 |
*/
|
207 |
function update_notice_action() {
|
208 |
global $pagenow;
|
209 |
-
if (
|
210 |
(
|
211 |
isset($_REQUEST['action'])
|
212 |
&& ('upgrade-core' == $_REQUEST['action'])
|
@@ -219,19 +221,19 @@ class wpdbBackup {
|
|
219 |
add_action('admin_footer', create_function('', 'ob_end_flush();'));
|
220 |
endif;
|
221 |
}
|
222 |
-
|
223 |
function update_notice($text = '') {
|
224 |
$pattern = '#(<a href\="' . __('http://codex.wordpress.org/WordPress_Backups') . '">.*?</p>)#';
|
225 |
-
$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";
|
226 |
$text = preg_replace($pattern, $replace, $text);
|
227 |
return $text;
|
228 |
}
|
229 |
|
230 |
function build_backup_script() {
|
231 |
global $table_prefix, $wpdb;
|
232 |
-
|
233 |
echo "<div class='wrap'>";
|
234 |
-
echo
|
235 |
<p><strong>' .
|
236 |
__('DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:','wp-db-backup').
|
237 |
'</strong></p>
|
@@ -269,16 +271,16 @@ class wpdbBackup {
|
|
269 |
var fram = document.getElementById("backuploader");
|
270 |
fram.src = "' . $this->page_url . '&fragment=" + table + ":" + segment + ":' . $this->backup_filename . ':&wp_db_temp_dir=' . $this->backup_dir . '";
|
271 |
}
|
272 |
-
|
273 |
var curStep = 0;
|
274 |
-
|
275 |
function nextStep() {
|
276 |
backupStep(curStep);
|
277 |
curStep++;
|
278 |
}
|
279 |
-
|
280 |
function finishBackup() {
|
281 |
-
var fram = document.getElementById("backuploader");
|
282 |
setMeter(100);
|
283 |
';
|
284 |
|
@@ -287,11 +289,11 @@ class wpdbBackup {
|
|
287 |
case 'http':
|
288 |
echo '
|
289 |
setProgress("' . __('Preparing download.','wp-db-backup') . '");
|
290 |
-
window.onbeforeunload = null;
|
291 |
fram.src = "' . $download_uri . '";
|
292 |
-
|
293 |
setTimeout( function() {
|
294 |
-
var secondFrame = document.createElement("iframe");
|
295 |
fram.parentNode.insertBefore(secondFrame, fram);
|
296 |
secondFrame.src = "' . $download_uri . '&download-retry=1";
|
297 |
}, 30000 );
|
@@ -304,32 +306,27 @@ class wpdbBackup {
|
|
304 |
}
|
305 |
echo '
|
306 |
setProgress("' . sprintf(__('Your backup has been emailed to %s','wp-db-backup'), $email) . '");
|
307 |
-
window.onbeforeunload = null;
|
308 |
fram.src = "' . $download_uri . '&via=email&recipient=' . $email . '";
|
309 |
';
|
310 |
break;
|
311 |
default:
|
312 |
echo '
|
313 |
setProgress("' . __('Backup Complete!','wp-db-backup') . '");
|
314 |
-
window.onbeforeunload = null;
|
315 |
';
|
316 |
}
|
317 |
-
|
318 |
echo '
|
319 |
}
|
320 |
-
|
321 |
function backupStep(step) {
|
322 |
switch(step) {
|
323 |
case 0: backup("", 0); break;
|
324 |
';
|
325 |
-
|
326 |
-
$also_backup =
|
327 |
-
|
328 |
-
$also_backup = $_POST['other_tables'];
|
329 |
-
} else {
|
330 |
-
$also_backup = array();
|
331 |
-
}
|
332 |
-
$core_tables = $_POST['core_tables'];
|
333 |
$tables = array_merge($core_tables, $also_backup);
|
334 |
$step_count = 1;
|
335 |
foreach ($tables as $table) {
|
@@ -350,7 +347,7 @@ class wpdbBackup {
|
|
350 |
$step_count++;
|
351 |
}
|
352 |
echo "case {$step_count}: finishBackup(); break;";
|
353 |
-
|
354 |
echo '
|
355 |
}
|
356 |
if(step != 0) setMeter(100 * step / ' . $step_count . ');
|
@@ -366,9 +363,9 @@ class wpdbBackup {
|
|
366 |
|
367 |
function backup_fragment($table, $segment, $filename) {
|
368 |
global $table_prefix, $wpdb;
|
369 |
-
|
370 |
echo "$table:$segment:$filename";
|
371 |
-
|
372 |
if($table == '') {
|
373 |
$msg = __('Creating backup file...','wp-db-backup');
|
374 |
} else {
|
@@ -378,7 +375,7 @@ class wpdbBackup {
|
|
378 |
$msg = sprintf(__('Backing up table \\"%s\\"...','wp-db-backup'), $table);
|
379 |
}
|
380 |
}
|
381 |
-
|
382 |
if (is_writable($this->backup_dir)) {
|
383 |
$this->fp = $this->open($this->backup_dir . $filename, 'a');
|
384 |
if(!$this->fp) {
|
@@ -386,7 +383,7 @@ class wpdbBackup {
|
|
386 |
$this->error(array('loc' => 'frame', 'kind' => 'fatal', 'msg' => __('The backup file could not be saved. Please check the permissions for writing to your backup directory and try again.','wp-db-backup')));
|
387 |
}
|
388 |
else {
|
389 |
-
if($table == '') {
|
390 |
//Begin new backup of MySql
|
391 |
$this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n");
|
392 |
$this->stow("#\n");
|
@@ -402,7 +399,7 @@ class wpdbBackup {
|
|
402 |
$this->stow("# --------------------------------------------------------\n");
|
403 |
$this->stow("# " . sprintf(__('Table: %s','wp-db-backup'),$this->backquote($table)) . "\n");
|
404 |
$this->stow("# --------------------------------------------------------\n");
|
405 |
-
}
|
406 |
$this->backup_table($table, $segment);
|
407 |
}
|
408 |
}
|
@@ -411,7 +408,7 @@ class wpdbBackup {
|
|
411 |
}
|
412 |
|
413 |
if($this->fp) $this->close($this->fp);
|
414 |
-
|
415 |
$this->error_display('frame');
|
416 |
|
417 |
echo '<script type="text/javascript"><!--//
|
@@ -427,20 +424,20 @@ class wpdbBackup {
|
|
427 |
// are we backing up any other tables?
|
428 |
$also_backup = array();
|
429 |
if (isset($_POST['other_tables']))
|
430 |
-
$also_backup = $_POST['other_tables'];
|
431 |
-
$core_tables = $_POST['core_tables'];
|
432 |
$this->backup_file = $this->db_backup($core_tables, $also_backup);
|
433 |
if (false !== $this->backup_file) {
|
434 |
if ('smtp' == $_POST['deliver']) {
|
435 |
$email = sanitize_text_field(wp_unslash($_POST['backup_recipient']));
|
436 |
-
$this->deliver_backup($this->backup_file, $_POST['deliver'], $email, 'main');
|
437 |
if ( get_option('wpdb_backup_recip') != $email ) {
|
438 |
update_option('wpdb_backup_recip', $email );
|
439 |
}
|
440 |
wp_redirect($this->page_url);
|
441 |
} elseif ('http' == $_POST['deliver']) {
|
442 |
$download_uri = add_query_arg('backup',$this->backup_file,$this->page_url);
|
443 |
-
wp_redirect($download_uri);
|
444 |
exit;
|
445 |
}
|
446 |
// we do this to say we're done.
|
@@ -477,7 +474,7 @@ class wpdbBackup {
|
|
477 |
t[k].p[i].id = k + '-table-' + i;
|
478 |
t[k].p[i].onkeyup = t[k].p[i].onclick = function(e) {
|
479 |
e = e ? e : event;
|
480 |
-
if ( 16 == e.keyCode )
|
481 |
return;
|
482 |
var match = /([\w-]*)-table-(\d*)/.exec(this.id);
|
483 |
var listname = match[1];
|
@@ -497,7 +494,7 @@ class wpdbBackup {
|
|
497 |
}
|
498 |
|
499 |
<?php if ( function_exists('wp_schedule_event') ) : // needs to be at least WP 2.1 for ajax ?>
|
500 |
-
if ( 'undefined' == typeof XMLHttpRequest )
|
501 |
var xml = new ActiveXObject( navigator.userAgent.indexOf('MSIE 5') >= 0 ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP' );
|
502 |
else
|
503 |
var xml = new XMLHttpRequest();
|
@@ -506,7 +503,7 @@ class wpdbBackup {
|
|
506 |
var timeWrap = document.getElementById('backup-time-wrap');
|
507 |
var backupTime = document.getElementById('next-backup-time');
|
508 |
if ( !! timeWrap && !! backupTime && ( 1 == <?php
|
509 |
-
echo (int) ( 'en' == strtolower( substr( get_locale(), 0, 2 ) ) );
|
510 |
?> ) ) {
|
511 |
var span = document.createElement('span');
|
512 |
span.className = 'submit';
|
@@ -528,7 +525,7 @@ class wpdbBackup {
|
|
528 |
if ( !! saveTButton )
|
529 |
saveTButton.onclick = function(e) { saveTime(backupTime, mainText); return false; };
|
530 |
if ( !! mainText )
|
531 |
-
mainText.onkeydown = function(e) {
|
532 |
e = e || window.event;
|
533 |
if ( 13 == e.keyCode ) {
|
534 |
saveTime(backupTime, mainText);
|
@@ -590,7 +587,7 @@ class wpdbBackup {
|
|
590 |
margin-bottom: .5em;
|
591 |
padding: 1em;
|
592 |
}
|
593 |
-
|
594 |
fieldset.options .instructions {
|
595 |
font-size: smaller;
|
596 |
}
|
@@ -606,7 +603,7 @@ class wpdbBackup {
|
|
606 |
border-top: none;
|
607 |
}
|
608 |
</style>
|
609 |
-
<?php
|
610 |
}
|
611 |
|
612 |
function admin_load() {
|
@@ -636,7 +633,7 @@ class wpdbBackup {
|
|
636 |
add_action('load-' . $page_hook, array(&$this, 'admin_load'));
|
637 |
}
|
638 |
|
639 |
-
/**
|
640 |
* Add WP-DB-Backup-specific help options to the 2.7 =< WP contextual help menu
|
641 |
* @return string The text of the help menu.
|
642 |
*/
|
@@ -672,7 +669,7 @@ class wpdbBackup {
|
|
672 |
if ($is_like) $a_string = str_replace('\\', '\\\\\\\\', $a_string);
|
673 |
else $a_string = str_replace('\\', '\\\\', $a_string);
|
674 |
return str_replace('\'', '\\\'', $a_string);
|
675 |
-
}
|
676 |
|
677 |
/**
|
678 |
* Add backquotes to tables and db-names in
|
@@ -683,7 +680,7 @@ class wpdbBackup {
|
|
683 |
if (is_array($a_name)) {
|
684 |
$result = array();
|
685 |
reset($a_name);
|
686 |
-
while(list($key, $val) = each($a_name))
|
687 |
$result[$key] = '`' . $val . '`';
|
688 |
return $result;
|
689 |
} else {
|
@@ -692,7 +689,7 @@ class wpdbBackup {
|
|
692 |
} else {
|
693 |
return $a_name;
|
694 |
}
|
695 |
-
}
|
696 |
|
697 |
function open($filename = '', $mode = 'w') {
|
698 |
if ('' == $filename) return false;
|
@@ -713,14 +710,14 @@ class wpdbBackup {
|
|
713 |
if(false === @fwrite($this->fp, $query_line))
|
714 |
$this->error(__('There was an error writing a line to the backup script:','wp-db-backup') . ' ' . $query_line . ' ' . $php_errormsg);
|
715 |
}
|
716 |
-
|
717 |
/**
|
718 |
* Logs any error messages
|
719 |
* @param array $args
|
720 |
* @return bool
|
721 |
*/
|
722 |
function error($args = array()) {
|
723 |
-
if ( is_string( $args ) )
|
724 |
$args = array('msg' => $args);
|
725 |
$args = array_merge( array('loc' => 'main', 'kind' => 'warn', 'msg' => ''), $args);
|
726 |
$this->errors[$args['kind']][] = $args['msg'];
|
@@ -730,7 +727,7 @@ class wpdbBackup {
|
|
730 |
}
|
731 |
|
732 |
/**
|
733 |
-
* Displays error messages
|
734 |
* @param array $errs
|
735 |
* @param string $loc
|
736 |
* @return string
|
@@ -746,7 +743,7 @@ class wpdbBackup {
|
|
746 |
if ( 10 == count( $err_list ) )
|
747 |
$err_list[9] = __('Subsequent errors have been omitted from this log.','wp-db-backup');
|
748 |
$wrap = ( 'frame' == $loc ) ? "<script type=\"text/javascript\">\n var msgList = ''; \n %1\$s \n if ( msgList ) alert(msgList); \n </script>" : '%1$s';
|
749 |
-
$line = ( 'frame' == $loc ) ?
|
750 |
"try{ window.parent.addError('%1\$s'); } catch(e) { msgList += ' %1\$s';}\n" :
|
751 |
"%1\$s<br />\n";
|
752 |
foreach( (array) $err_list as $err )
|
@@ -766,8 +763,8 @@ class wpdbBackup {
|
|
766 |
* Taken partially from phpMyAdmin and partially from
|
767 |
* Alain Wolf, Zurich - Switzerland
|
768 |
* Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
|
769 |
-
|
770 |
-
* Modified by Scott Merrill (http://www.skippy.net/)
|
771 |
* to use the WordPress $wpdb object
|
772 |
* @param string $table
|
773 |
* @param string $segment
|
@@ -781,7 +778,7 @@ class wpdbBackup {
|
|
781 |
$this->error(__('Error getting table details','wp-db-backup') . ": $table");
|
782 |
return false;
|
783 |
}
|
784 |
-
|
785 |
if(($segment == 'none') || ($segment == 0)) {
|
786 |
// Add SQL statement to drop existing table
|
787 |
$this->stow("\n\n");
|
@@ -790,7 +787,7 @@ class wpdbBackup {
|
|
790 |
$this->stow("#\n");
|
791 |
$this->stow("\n");
|
792 |
$this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n");
|
793 |
-
|
794 |
// Table structure
|
795 |
// Comment in SQL-file
|
796 |
$this->stow("\n\n");
|
@@ -798,7 +795,7 @@ class wpdbBackup {
|
|
798 |
$this->stow("# " . sprintf(__('Table structure of table %s','wp-db-backup'),$this->backquote($table)) . "\n");
|
799 |
$this->stow("#\n");
|
800 |
$this->stow("\n");
|
801 |
-
|
802 |
$create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N);
|
803 |
if (false === $create_table) {
|
804 |
$err_msg = sprintf(__('Error with SHOW CREATE TABLE for %s.','wp-db-backup'), $table);
|
@@ -806,20 +803,20 @@ class wpdbBackup {
|
|
806 |
$this->stow("#\n# $err_msg\n#\n");
|
807 |
}
|
808 |
$this->stow($create_table[0][1] . ' ;');
|
809 |
-
|
810 |
if (false === $table_structure) {
|
811 |
$err_msg = sprintf(__('Error getting table structure of %s','wp-db-backup'), $table);
|
812 |
$this->error($err_msg);
|
813 |
$this->stow("#\n# $err_msg\n#\n");
|
814 |
}
|
815 |
-
|
816 |
// Comment in SQL-file
|
817 |
$this->stow("\n\n");
|
818 |
$this->stow("#\n");
|
819 |
$this->stow('# ' . sprintf(__('Data contents of table %s','wp-db-backup'),$this->backquote($table)) . "\n");
|
820 |
$this->stow("#\n");
|
821 |
}
|
822 |
-
|
823 |
if(($segment == 'none') || ($segment >= 0)) {
|
824 |
$defs = array();
|
825 |
$ints = array();
|
@@ -833,10 +830,10 @@ class wpdbBackup {
|
|
833 |
$ints[strtolower($struct->Field)] = "1";
|
834 |
}
|
835 |
}
|
836 |
-
|
837 |
-
|
838 |
// Batch by $row_inc
|
839 |
-
|
840 |
if($segment == 'none') {
|
841 |
$row_start = 0;
|
842 |
$row_inc = ROWS_PER_SEGMENT;
|
@@ -844,8 +841,8 @@ class wpdbBackup {
|
|
844 |
$row_start = $segment * ROWS_PER_SEGMENT;
|
845 |
$row_inc = ROWS_PER_SEGMENT;
|
846 |
}
|
847 |
-
|
848 |
-
do {
|
849 |
// don't include extra stuff, if so requested
|
850 |
$excs = (array) get_option('wp_db_backup_excs');
|
851 |
$where = '';
|
@@ -854,11 +851,11 @@ class wpdbBackup {
|
|
854 |
} elseif ( is_array($excs['revisions'] ) && in_array($table, $excs['revisions']) ) {
|
855 |
$where = ' WHERE post_type != "revision"';
|
856 |
}
|
857 |
-
|
858 |
if ( !ini_get('safe_mode')) @set_time_limit(15*60);
|
859 |
$table_data = $wpdb->get_results("SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A);
|
860 |
|
861 |
-
$entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES (';
|
862 |
// \x08\\x09, not required
|
863 |
$search = array("\x00", "\x0a", "\x0d", "\x1a");
|
864 |
$replace = array('\0', '\n', '\r', '\Z');
|
@@ -881,7 +878,7 @@ class wpdbBackup {
|
|
881 |
}
|
882 |
} while((count($table_data) > 0) and ($segment=='none'));
|
883 |
}
|
884 |
-
|
885 |
if(($segment == 'none') || ($segment < 0)) {
|
886 |
// Create footer/closing comment in SQL-file
|
887 |
$this->stow("\n");
|
@@ -891,10 +888,10 @@ class wpdbBackup {
|
|
891 |
$this->stow("\n");
|
892 |
}
|
893 |
} // end backup_table()
|
894 |
-
|
895 |
function db_backup($core_tables, $other_tables) {
|
896 |
global $table_prefix, $wpdb;
|
897 |
-
|
898 |
if (is_writable($this->backup_dir)) {
|
899 |
$this->fp = $this->open($this->backup_dir . $this->backup_filename);
|
900 |
if(!$this->fp) {
|
@@ -905,7 +902,7 @@ class wpdbBackup {
|
|
905 |
$this->error(__('The backup directory is not writeable!','wp-db-backup'));
|
906 |
return false;
|
907 |
}
|
908 |
-
|
909 |
//Begin new backup of MySql
|
910 |
$this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n");
|
911 |
$this->stow("#\n");
|
@@ -913,12 +910,12 @@ class wpdbBackup {
|
|
913 |
$this->stow("# " . sprintf(__('Hostname: %s','wp-db-backup'),DB_HOST) . "\n");
|
914 |
$this->stow("# " . sprintf(__('Database: %s','wp-db-backup'),$this->backquote(DB_NAME)) . "\n");
|
915 |
$this->stow("# --------------------------------------------------------\n");
|
916 |
-
|
917 |
if ( (is_array($other_tables)) && (count($other_tables) > 0) )
|
918 |
$tables = array_merge($core_tables, $other_tables);
|
919 |
else
|
920 |
$tables = $core_tables;
|
921 |
-
|
922 |
foreach ($tables as $table) {
|
923 |
// Increase script execution time-limit to 15 min for every table.
|
924 |
if ( !ini_get('safe_mode')) @set_time_limit(15*60);
|
@@ -928,15 +925,15 @@ class wpdbBackup {
|
|
928 |
$this->stow("# --------------------------------------------------------\n");
|
929 |
$this->backup_table($table);
|
930 |
}
|
931 |
-
|
932 |
$this->close($this->fp);
|
933 |
-
|
934 |
if (count($this->errors)) {
|
935 |
return false;
|
936 |
} else {
|
937 |
return $this->backup_filename;
|
938 |
}
|
939 |
-
|
940 |
} //wp_db_backup
|
941 |
|
942 |
/**
|
@@ -964,12 +961,9 @@ class wpdbBackup {
|
|
964 |
|
965 |
// try to use phpmailer directly (WP 2.2+)
|
966 |
if ( is_object( $phpmailer ) && ( strtolower(get_class( $phpmailer )) == 'phpmailer' ) ) {
|
967 |
-
|
968 |
// Get the site domain and get rid of www.
|
969 |
-
$sitename =
|
970 |
-
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
|
971 |
-
$sitename = substr( $sitename, 4 );
|
972 |
-
}
|
973 |
$from_email = 'wordpress@' . $sitename;
|
974 |
$from_name = 'WordPress';
|
975 |
|
@@ -992,7 +986,7 @@ class wpdbBackup {
|
|
992 |
$phpmailer->Subject = $subject;
|
993 |
|
994 |
do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
|
995 |
-
|
996 |
$result = @$phpmailer->Send();
|
997 |
|
998 |
// old-style: build the headers directly
|
@@ -1000,18 +994,18 @@ class wpdbBackup {
|
|
1000 |
$randomish = md5(time());
|
1001 |
$boundary = "==WPBACKUP-$randomish";
|
1002 |
$fp = fopen($diskfile,"rb");
|
1003 |
-
$file = fread($fp,filesize($diskfile));
|
1004 |
$this->close($fp);
|
1005 |
-
|
1006 |
$data = chunk_split(base64_encode($file));
|
1007 |
-
|
1008 |
$headers .= "MIME-Version: 1.0\n";
|
1009 |
-
$headers = 'From: wordpress@' . preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME'])) . "\n";
|
1010 |
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
|
1011 |
-
|
1012 |
// Add a multipart boundary above the plain message
|
1013 |
$message = "This is a multi-part message in MIME format.\n\n" .
|
1014 |
-
|
1015 |
"Content-Type: text/plain; charset=\"" . get_bloginfo('charset') . "\"\n" .
|
1016 |
"Content-Transfer-Encoding: 7bit\n\n" .
|
1017 |
$message . "\n\n";
|
@@ -1025,7 +1019,7 @@ class wpdbBackup {
|
|
1025 |
"Content-Transfer-Encoding: base64\n\n" .
|
1026 |
$data . "\n\n" .
|
1027 |
"--{$boundary}--\n";
|
1028 |
-
|
1029 |
$result = @wp_mail($to, $subject, $message, $headers);
|
1030 |
}
|
1031 |
return $result;
|
@@ -1034,7 +1028,7 @@ class wpdbBackup {
|
|
1034 |
|
1035 |
function deliver_backup($filename = '', $delivery = 'http', $recipient = '', $location = 'main') {
|
1036 |
if ('' == $filename) { return false; }
|
1037 |
-
|
1038 |
$diskfile = $this->backup_dir . $filename;
|
1039 |
$gz_diskfile = "{$diskfile}.gz";
|
1040 |
|
@@ -1059,9 +1053,9 @@ class wpdbBackup {
|
|
1059 |
}
|
1060 |
$diskfile = $gz_diskfile;
|
1061 |
$filename = "{$filename}.gz";
|
1062 |
-
|
1063 |
/**
|
1064 |
-
* Try to compress to gzip, if available
|
1065 |
*/
|
1066 |
} else {
|
1067 |
if ( function_exists('gzencode') ) {
|
@@ -1081,7 +1075,7 @@ class wpdbBackup {
|
|
1081 |
}
|
1082 |
}
|
1083 |
/*
|
1084 |
-
*
|
1085 |
*/
|
1086 |
} elseif ( file_exists( $gz_diskfile ) && empty( $_GET['download-retry'] ) ) {
|
1087 |
$diskfile = $gz_diskfile;
|
@@ -1090,7 +1084,7 @@ class wpdbBackup {
|
|
1090 |
|
1091 |
if ('http' == $delivery) {
|
1092 |
if ( ! file_exists( $diskfile ) ) {
|
1093 |
-
if ( empty( $_GET['download-retry'] ) ) {
|
1094 |
$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>'));
|
1095 |
} else {
|
1096 |
return true;
|
@@ -1123,7 +1117,7 @@ class wpdbBackup {
|
|
1123 |
$err = error_get_last();
|
1124 |
$msg .= $err['message'];
|
1125 |
} else {
|
1126 |
-
$msg .= __('ERROR: The mail application has failed to deliver the backup.','wp-db-backup');
|
1127 |
}
|
1128 |
$this->error(array('kind' => 'fatal', 'loc' => $location, 'msg' => $msg));
|
1129 |
} else {
|
@@ -1134,12 +1128,12 @@ class wpdbBackup {
|
|
1134 |
}
|
1135 |
return $success;
|
1136 |
}
|
1137 |
-
|
1138 |
function backup_menu() {
|
1139 |
global $table_prefix, $wpdb;
|
1140 |
$feedback = '';
|
1141 |
$whoops = false;
|
1142 |
-
|
1143 |
// did we just do a backup? If so, let's report the status
|
1144 |
if ( $this->backup_complete ) {
|
1145 |
$feedback = '<div class="updated wp-db-backup-updated"><p>' . __('Backup Successful','wp-db-backup') . '!';
|
@@ -1160,9 +1154,9 @@ class wpdbBackup {
|
|
1160 |
}
|
1161 |
$feedback .= '</p></div>';
|
1162 |
}
|
1163 |
-
|
1164 |
// security check
|
1165 |
-
$this->wp_secure();
|
1166 |
|
1167 |
if (count($this->errors)) {
|
1168 |
$feedback .= '<div class="updated wp-db-backup-updated error"><p><strong>' . __('The following errors were reported:','wp-db-backup') . '</strong></p>';
|
@@ -1171,14 +1165,14 @@ class wpdbBackup {
|
|
1171 |
}
|
1172 |
|
1173 |
// did we just save options for wp-cron?
|
1174 |
-
if ( (function_exists('wp_schedule_event') || function_exists('wp_cron_init'))
|
1175 |
&& isset($_POST['wp_cron_backup_options']) ) :
|
1176 |
do_action('wp_db_b_update_cron_options');
|
1177 |
if ( function_exists('wp_schedule_event') ) {
|
1178 |
wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous
|
1179 |
$scheds = (array) wp_get_schedules();
|
1180 |
-
$name = strval($_POST['wp_cron_schedule']);
|
1181 |
-
$interval = ( isset($scheds[$name]['interval']) ) ?
|
1182 |
(int) $scheds[$name]['interval'] : 0;
|
1183 |
update_option('wp_cron_backup_schedule', $name, false);
|
1184 |
if ( 0 !== $interval ) {
|
@@ -1188,28 +1182,28 @@ class wpdbBackup {
|
|
1188 |
else {
|
1189 |
update_option('wp_cron_backup_schedule', intval($_POST['cron_schedule']), false);
|
1190 |
}
|
1191 |
-
update_option('wp_cron_backup_tables',
|
1192 |
if (is_email($_POST['cron_backup_recipient'])) {
|
1193 |
-
update_option('wp_cron_backup_recipient', $_POST['cron_backup_recipient'], false);
|
1194 |
}
|
1195 |
$feedback .= '<div class="updated wp-db-backup-updated"><p>' . __('Scheduled Backup Options Saved!','wp-db-backup') . '</p></div>';
|
1196 |
endif;
|
1197 |
-
|
1198 |
$other_tables = array();
|
1199 |
$also_backup = array();
|
1200 |
-
|
1201 |
-
// Get complete db table list
|
1202 |
$all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
|
1203 |
$all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables);
|
1204 |
// Get list of WP tables that actually exist in this DB (for 1.6 compat!)
|
1205 |
$wp_backup_default_tables = array_intersect($all_tables, $this->core_table_names);
|
1206 |
// Get list of non-WP tables
|
1207 |
$other_tables = array_diff($all_tables, $wp_backup_default_tables);
|
1208 |
-
|
1209 |
if ('' != $feedback)
|
1210 |
echo $feedback;
|
1211 |
|
1212 |
-
if ( ! $this->wp_secure() )
|
1213 |
return;
|
1214 |
|
1215 |
// Give the new dirs the same perms as wp-content.
|
@@ -1226,26 +1220,26 @@ class wpdbBackup {
|
|
1226 |
} elseif ( !is_writable($this->backup_dir) && ! @chmod($this->backup_dir, $dir_perms) ) {
|
1227 |
?><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>
|
1228 |
<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>'); ?>
|
1229 |
-
</p></div><?php
|
1230 |
$whoops = true;
|
1231 |
} else {
|
1232 |
$this->fp = $this->open($this->backup_dir . 'test' );
|
1233 |
-
if( $this->fp ) {
|
1234 |
$this->close($this->fp);
|
1235 |
@unlink($this->backup_dir . 'test' );
|
1236 |
// the directory is not writable probably due to safe mode
|
1237 |
} else {
|
1238 |
-
?><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
|
1239 |
if( ini_get('safe_mode') ){
|
1240 |
-
?><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
|
1241 |
}
|
1242 |
?><?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>');
|
1243 |
-
?></div><?php
|
1244 |
$whoops = true;
|
1245 |
}
|
1246 |
}
|
1247 |
|
1248 |
-
|
1249 |
|
1250 |
if ( !file_exists($this->backup_dir . 'index.php') )
|
1251 |
@ touch($this->backup_dir . 'index.php');
|
@@ -1271,8 +1265,8 @@ class wpdbBackup {
|
|
1271 |
?></ul>
|
1272 |
</div>
|
1273 |
<div class="tables-list extra-tables" id="extra-tables-list">
|
1274 |
-
<?php
|
1275 |
-
if (count($other_tables) > 0) {
|
1276 |
?>
|
1277 |
<h4><?php _e('You may choose to include any of the following tables:','wp-db-backup'); ?></h4>
|
1278 |
<ul>
|
@@ -1280,13 +1274,13 @@ class wpdbBackup {
|
|
1280 |
foreach ($other_tables as $table) {
|
1281 |
?>
|
1282 |
<li><label><input type="checkbox" name="other_tables[]" value="<?php echo $table; ?>" /> <code><?php echo $table; ?></code></label>
|
1283 |
-
<?php
|
1284 |
}
|
1285 |
-
?></ul><?php
|
1286 |
}
|
1287 |
?></div>
|
1288 |
</fieldset>
|
1289 |
-
|
1290 |
<fieldset class="options">
|
1291 |
<legend><?php _e('Backup Options','wp-db-backup'); ?></legend>
|
1292 |
<p><?php _e('What to do with the backup file:','wp-db-backup'); ?></p>
|
@@ -1298,7 +1292,7 @@ class wpdbBackup {
|
|
1298 |
<li><label for="do_email">
|
1299 |
<input type="radio" name="deliver" id="do_email" value="smtp" style="border:none;" />
|
1300 |
<?php _e('Email backup to:','wp-db-backup'); ?>
|
1301 |
-
<input type="text" name="backup_recipient" size="20" value="<?php
|
1302 |
$backup_recip = get_option('wpdb_backup_recip');
|
1303 |
if ( empty( $backup_recip ) ) {
|
1304 |
$backup_recip = get_option('admin_email');
|
@@ -1308,7 +1302,7 @@ class wpdbBackup {
|
|
1308 |
</label></li>
|
1309 |
</ul>
|
1310 |
<?php if ( ! $whoops ) : ?>
|
1311 |
-
<input type="hidden" name="do_backup" id="do_backup" value="backup" />
|
1312 |
<p class="submit">
|
1313 |
<input type="submit" name="submit" onclick="document.getElementById('do_backup').value='fragments';" value="<?php _e('Backup now!','wp-db-backup'); ?>" />
|
1314 |
</p>
|
@@ -1318,9 +1312,9 @@ class wpdbBackup {
|
|
1318 |
</fieldset>
|
1319 |
<?php do_action('wp_db_b_backup_opts'); ?>
|
1320 |
</form>
|
1321 |
-
|
1322 |
<?php
|
1323 |
-
// this stuff only displays if some sort of wp-cron is available
|
1324 |
$cron = ( function_exists('wp_schedule_event') ) ? true : false; // wp-cron in WP 2.1+
|
1325 |
$cron_old = ( function_exists('wp_cron_init') && ! $cron ) ? true : false; // wp-cron plugin by Skippy
|
1326 |
if ( $cron_old || $cron ) :
|
@@ -1333,17 +1327,17 @@ class wpdbBackup {
|
|
1333 |
<p id="backup-time-wrap">
|
1334 |
<?php printf(__('Next Backup: %s','wp-db-backup'), '<span id="next-backup-time">' . gmdate($datetime, $next_cron + (get_option('gmt_offset') * 3600)) . '</span>'); ?>
|
1335 |
</p>
|
1336 |
-
<?php
|
1337 |
endif;
|
1338 |
elseif ( $cron_old ) :
|
1339 |
-
?><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
|
1340 |
-
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
|
1341 |
endif;
|
1342 |
?><form method="post" action="">
|
1343 |
<?php if ( function_exists('wp_nonce_field') ) wp_nonce_field($this->referer_check_key); ?>
|
1344 |
<div class="tables-list">
|
1345 |
<h4><?php _e('Schedule: ','wp-db-backup'); ?></h4>
|
1346 |
-
<?php
|
1347 |
if ( $cron_old ) :
|
1348 |
$wp_cron_backup_schedule = get_option('wp_cron_backup_schedule');
|
1349 |
$schedule = array(0 => __('None','wp-db-backup'), 1 => __('Daily','wp-db-backup'));
|
@@ -1384,14 +1378,14 @@ class wpdbBackup {
|
|
1384 |
echo '<input type="hidden" name="wp_cron_backup_options" value="SET" /></form>';
|
1385 |
echo '</fieldset>';
|
1386 |
endif; // end of wp_cron (legacy) section
|
1387 |
-
|
1388 |
echo '</div><!-- .wrap -->';
|
1389 |
-
|
1390 |
} // end wp_backup_menu()
|
1391 |
|
1392 |
function get_sched() {
|
1393 |
$options = array_keys( (array) wp_get_schedules() );
|
1394 |
-
$freq = get_option('wp_cron_backup_schedule');
|
1395 |
$freq = ( in_array( $freq , $options ) ) ? $freq : 'never';
|
1396 |
return $freq;
|
1397 |
}
|
@@ -1421,14 +1415,14 @@ class wpdbBackup {
|
|
1421 |
$menu .= '</ul>';
|
1422 |
return $menu;
|
1423 |
} // end schedule_choices()
|
1424 |
-
|
1425 |
function wp_cron_daily() { // for legacy cron plugin
|
1426 |
$schedule = intval(get_option('wp_cron_backup_schedule'));
|
1427 |
// If scheduled backup is disabled
|
1428 |
if (0 == $schedule)
|
1429 |
return;
|
1430 |
else return $this->cron_backup();
|
1431 |
-
}
|
1432 |
|
1433 |
function cron_backup() {
|
1434 |
global $table_prefix, $wpdb;
|
@@ -1438,7 +1432,7 @@ class wpdbBackup {
|
|
1438 |
$other_tables = get_option('wp_cron_backup_tables');
|
1439 |
$recipient = get_option('wp_cron_backup_recipient');
|
1440 |
$backup_file = $this->db_backup($core_tables, $other_tables);
|
1441 |
-
if (false !== $backup_file)
|
1442 |
return $this->deliver_backup($backup_file, 'smtp', $recipient, 'main');
|
1443 |
else return false;
|
1444 |
}
|
@@ -1449,7 +1443,7 @@ class wpdbBackup {
|
|
1449 |
}
|
1450 |
|
1451 |
/**
|
1452 |
-
* Checks that WordPress has sufficient security measures
|
1453 |
* @param string $kind
|
1454 |
* @return bool
|
1455 |
*/
|
@@ -1474,7 +1468,7 @@ class wpdbBackup {
|
|
1474 |
return false;
|
1475 |
if ( ( $this->wp_secure('fatal', $loc) ) && current_user_can('import') )
|
1476 |
$can = $this->verify_nonce($_REQUEST['_wpnonce'], $this->referer_check_key, $loc);
|
1477 |
-
if ( false == $can )
|
1478 |
$this->error(array('loc' => $loc, 'kind' => 'fatal', 'msg' => __('You are not allowed to perform backups.','wp-db-backup')));
|
1479 |
return $can;
|
1480 |
}
|
@@ -1489,26 +1483,115 @@ class wpdbBackup {
|
|
1489 |
function verify_nonce($rec = '', $nonce = 'X', $loc = 'main') {
|
1490 |
if ( wp_verify_nonce($rec, $nonce) )
|
1491 |
return true;
|
1492 |
-
else
|
1493 |
$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'))));
|
1494 |
}
|
1495 |
|
1496 |
/**
|
1497 |
-
* Check whether a file to be downloaded is
|
1498 |
* surreptitiously trying to download a non-backup file
|
1499 |
* @param string $file
|
1500 |
* @return null
|
1501 |
-
*/
|
1502 |
function validate_file($file) {
|
1503 |
if ( (false !== strpos($file, '..')) || (false !== strpos($file, './')) || (':' == substr($file, 1, 1)) )
|
1504 |
$this->error(array('kind' => 'fatal', 'loc' => 'frame', 'msg' => __("Cheatin' uh ?",'wp-db-backup')));
|
1505 |
}
|
1506 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1507 |
}
|
1508 |
|
1509 |
function wpdbBackup_init() {
|
1510 |
global $mywpdbbackup;
|
1511 |
-
$mywpdbbackup = new wpdbBackup();
|
1512 |
}
|
1513 |
|
1514 |
add_action('plugins_loaded', 'wpdbBackup_init');
|
3 |
Plugin Name: WordPress Database Backup
|
4 |
Plugin URI: https://github.com/matzko/wp-db-backup
|
5 |
Description: On-demand backup of your WordPress database. Navigate to <a href="edit.php?page=wp-db-backup">Tools → Backup</a> to get started.
|
6 |
+
Author: Austin Matzko
|
7 |
Author URI: http://austinmatzko.com/
|
8 |
+
Version: 2.3.3
|
9 |
|
10 |
+
Copyright 2018 Austin Matzko (email : austin at pressedcode.com)
|
11 |
|
12 |
This program is free software; you can redistribute it and/or modify
|
13 |
it under the terms of the GNU General Public License as published by
|
37 |
define('ROWS_PER_SEGMENT', 100);
|
38 |
}
|
39 |
|
40 |
+
/**
|
41 |
+
* Set MOD_EVASIVE_OVERRIDE to true
|
42 |
+
* and increase MOD_EVASIVE_DELAY
|
43 |
* if the backup stops prematurely.
|
44 |
*/
|
45 |
// define('MOD_EVASIVE_OVERRIDE', false);
|
57 |
var $basename;
|
58 |
var $page_url;
|
59 |
var $referer_check_key;
|
60 |
+
var $version = '2.3.3';
|
61 |
|
62 |
function module_check() {
|
63 |
$mod_evasive = false;
|
64 |
if ( defined( 'MOD_EVASIVE_OVERRIDE' ) && true === MOD_EVASIVE_OVERRIDE ) return true;
|
65 |
if ( ! defined( 'MOD_EVASIVE_OVERRIDE' ) || false === MOD_EVASIVE_OVERRIDE ) return false;
|
66 |
+
if ( function_exists('apache_get_modules') )
|
67 |
+
foreach( (array) apache_get_modules() as $mod )
|
68 |
if ( false !== strpos($mod,'mod_evasive') || false !== strpos($mod,'mod_dosevasive') )
|
69 |
return true;
|
70 |
return false;
|
71 |
}
|
72 |
|
73 |
+
function __construct() {
|
74 |
global $table_prefix, $wpdb;
|
75 |
add_action('wp_ajax_save_backup_time', array(&$this, 'save_backup_time'));
|
76 |
add_action('init', array(&$this, 'init_textdomain'));
|
80 |
add_action('wp_cron_daily', array(&$this, 'wp_cron_daily'));
|
81 |
add_filter('cron_schedules', array(&$this, 'add_sched_options'));
|
82 |
add_filter('wp_db_b_schedule_choices', array(&$this, 'schedule_choices'));
|
83 |
+
|
84 |
$table_prefix = ( isset( $table_prefix ) ) ? $table_prefix : $wpdb->prefix;
|
85 |
$datum = date("Ymd_B");
|
86 |
$this->backup_filename = DB_NAME . "_$table_prefix$datum.sql";
|
108 |
$this->core_table_names[] = $wpdb->{$name};
|
109 |
}
|
110 |
}
|
111 |
+
|
112 |
+
$requested_temp_dir = sanitize_text_field($_GET['wp_db_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()));
|
114 |
$this->basename = 'wp-db-backup';
|
115 |
+
|
116 |
$this->referer_check_key = $this->basename . '-download_' . DB_NAME;
|
117 |
if (isset($_POST['do_backup'])) {
|
118 |
$this->wp_secure('fatal');
|
119 |
check_admin_referer($this->referer_check_key);
|
120 |
$this->can_user_backup('main');
|
|
|
121 |
|
122 |
+
// save exclude prefs
|
123 |
+
update_option('wp_db_backup_excs', array(
|
124 |
+
'revisions' => $this->get_revisions_to_exclude(),
|
125 |
+
'spam' => $this->get_spam_to_exclude()
|
126 |
+
));
|
127 |
switch($_POST['do_backup']) {
|
128 |
case 'backup':
|
129 |
add_action('init', array(&$this, 'perform_backup'));
|
130 |
break;
|
131 |
case 'fragments':
|
132 |
add_action('admin_menu', array(&$this, 'fragment_menu'));
|
133 |
+
break;
|
134 |
}
|
135 |
} elseif (isset($_GET['fragment'] )) {
|
136 |
$this->can_user_backup('frame');
|
142 |
add_action('admin_menu', array(&$this, 'admin_menu'));
|
143 |
}
|
144 |
}
|
145 |
+
|
146 |
function init() {
|
147 |
$this->can_user_backup();
|
148 |
if (isset($_GET['backup'])) {
|
149 |
+
$via = isset($_GET['via']) ? sanitize_text_field($_GET['via']) : 'http';
|
150 |
+
|
151 |
+
$this->backup_file = sanitize_text_field($_GET['backup']);
|
152 |
$this->validate_file($this->backup_file);
|
153 |
|
154 |
switch($via) {
|
155 |
case 'smtp':
|
156 |
case 'email':
|
157 |
+
$success = $this->deliver_backup($this->backup_file, 'smtp', sanitize_text_field($_GET['recipient']), 'frame');
|
158 |
$this->error_display( 'frame' );
|
159 |
if ( $success ) {
|
160 |
echo '
|
163 |
';
|
164 |
echo '
|
165 |
alert("' . __('Backup Complete!','wp-db-backup') . '");
|
166 |
+
window.onbeforeunload = null;
|
167 |
</script>
|
168 |
';
|
169 |
}
|
171 |
default:
|
172 |
$success = $this->deliver_backup($this->backup_file, $via);
|
173 |
echo $this->error_display( 'frame', false );
|
174 |
+
|
175 |
if ( $success ) {
|
176 |
echo '
|
177 |
<script type="text/javascript">
|
183 |
exit;
|
184 |
}
|
185 |
if (isset($_GET['fragment'] )) {
|
186 |
+
list($table, $segment, $filename) = explode(':', sanitize_text_field($_GET['fragment']));
|
187 |
$this->validate_file($filename);
|
188 |
$this->backup_fragment($table, $segment, $filename);
|
189 |
}
|
208 |
*/
|
209 |
function update_notice_action() {
|
210 |
global $pagenow;
|
211 |
+
if (
|
212 |
(
|
213 |
isset($_REQUEST['action'])
|
214 |
&& ('upgrade-core' == $_REQUEST['action'])
|
221 |
add_action('admin_footer', create_function('', 'ob_end_flush();'));
|
222 |
endif;
|
223 |
}
|
224 |
+
|
225 |
function update_notice($text = '') {
|
226 |
$pattern = '#(<a href\="' . __('http://codex.wordpress.org/WordPress_Backups') . '">.*?</p>)#';
|
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 |
}
|
231 |
|
232 |
function build_backup_script() {
|
233 |
global $table_prefix, $wpdb;
|
234 |
+
|
235 |
echo "<div class='wrap'>";
|
236 |
+
echo '<fieldset class="options"><legend>' . __('Progress','wp-db-backup') . '</legend>
|
237 |
<p><strong>' .
|
238 |
__('DO NOT DO THE FOLLOWING AS IT WILL CAUSE YOUR BACKUP TO FAIL:','wp-db-backup').
|
239 |
'</strong></p>
|
271 |
var fram = document.getElementById("backuploader");
|
272 |
fram.src = "' . $this->page_url . '&fragment=" + table + ":" + segment + ":' . $this->backup_filename . ':&wp_db_temp_dir=' . $this->backup_dir . '";
|
273 |
}
|
274 |
+
|
275 |
var curStep = 0;
|
276 |
+
|
277 |
function nextStep() {
|
278 |
backupStep(curStep);
|
279 |
curStep++;
|
280 |
}
|
281 |
+
|
282 |
function finishBackup() {
|
283 |
+
var fram = document.getElementById("backuploader");
|
284 |
setMeter(100);
|
285 |
';
|
286 |
|
289 |
case 'http':
|
290 |
echo '
|
291 |
setProgress("' . __('Preparing download.','wp-db-backup') . '");
|
292 |
+
window.onbeforeunload = null;
|
293 |
fram.src = "' . $download_uri . '";
|
294 |
+
|
295 |
setTimeout( function() {
|
296 |
+
var secondFrame = document.createElement("iframe");
|
297 |
fram.parentNode.insertBefore(secondFrame, fram);
|
298 |
secondFrame.src = "' . $download_uri . '&download-retry=1";
|
299 |
}, 30000 );
|
306 |
}
|
307 |
echo '
|
308 |
setProgress("' . sprintf(__('Your backup has been emailed to %s','wp-db-backup'), $email) . '");
|
309 |
+
window.onbeforeunload = null;
|
310 |
fram.src = "' . $download_uri . '&via=email&recipient=' . $email . '";
|
311 |
';
|
312 |
break;
|
313 |
default:
|
314 |
echo '
|
315 |
setProgress("' . __('Backup Complete!','wp-db-backup') . '");
|
316 |
+
window.onbeforeunload = null;
|
317 |
';
|
318 |
}
|
319 |
+
|
320 |
echo '
|
321 |
}
|
322 |
+
|
323 |
function backupStep(step) {
|
324 |
switch(step) {
|
325 |
case 0: backup("", 0); break;
|
326 |
';
|
327 |
+
|
328 |
+
$also_backup = $this->get_post_data_array('other_tables');
|
329 |
+
$core_tables = $this->get_post_data_array('core_tables');
|
|
|
|
|
|
|
|
|
|
|
330 |
$tables = array_merge($core_tables, $also_backup);
|
331 |
$step_count = 1;
|
332 |
foreach ($tables as $table) {
|
347 |
$step_count++;
|
348 |
}
|
349 |
echo "case {$step_count}: finishBackup(); break;";
|
350 |
+
|
351 |
echo '
|
352 |
}
|
353 |
if(step != 0) setMeter(100 * step / ' . $step_count . ');
|
363 |
|
364 |
function backup_fragment($table, $segment, $filename) {
|
365 |
global $table_prefix, $wpdb;
|
366 |
+
|
367 |
echo "$table:$segment:$filename";
|
368 |
+
|
369 |
if($table == '') {
|
370 |
$msg = __('Creating backup file...','wp-db-backup');
|
371 |
} else {
|
375 |
$msg = sprintf(__('Backing up table \\"%s\\"...','wp-db-backup'), $table);
|
376 |
}
|
377 |
}
|
378 |
+
|
379 |
if (is_writable($this->backup_dir)) {
|
380 |
$this->fp = $this->open($this->backup_dir . $filename, 'a');
|
381 |
if(!$this->fp) {
|
383 |
$this->error(array('loc' => 'frame', 'kind' => 'fatal', 'msg' => __('The backup file could not be saved. Please check the permissions for writing to your backup directory and try again.','wp-db-backup')));
|
384 |
}
|
385 |
else {
|
386 |
+
if($table == '') {
|
387 |
//Begin new backup of MySql
|
388 |
$this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n");
|
389 |
$this->stow("#\n");
|
399 |
$this->stow("# --------------------------------------------------------\n");
|
400 |
$this->stow("# " . sprintf(__('Table: %s','wp-db-backup'),$this->backquote($table)) . "\n");
|
401 |
$this->stow("# --------------------------------------------------------\n");
|
402 |
+
}
|
403 |
$this->backup_table($table, $segment);
|
404 |
}
|
405 |
}
|
408 |
}
|
409 |
|
410 |
if($this->fp) $this->close($this->fp);
|
411 |
+
|
412 |
$this->error_display('frame');
|
413 |
|
414 |
echo '<script type="text/javascript"><!--//
|
424 |
// are we backing up any other tables?
|
425 |
$also_backup = array();
|
426 |
if (isset($_POST['other_tables']))
|
427 |
+
$also_backup = sanitize_text_field($_POST['other_tables']);
|
428 |
+
$core_tables = sanitize_text_field($_POST['core_tables']);
|
429 |
$this->backup_file = $this->db_backup($core_tables, $also_backup);
|
430 |
if (false !== $this->backup_file) {
|
431 |
if ('smtp' == $_POST['deliver']) {
|
432 |
$email = sanitize_text_field(wp_unslash($_POST['backup_recipient']));
|
433 |
+
$this->deliver_backup($this->backup_file, sanitize_text_field($_POST['deliver']), $email, 'main');
|
434 |
if ( get_option('wpdb_backup_recip') != $email ) {
|
435 |
update_option('wpdb_backup_recip', $email );
|
436 |
}
|
437 |
wp_redirect($this->page_url);
|
438 |
} elseif ('http' == $_POST['deliver']) {
|
439 |
$download_uri = add_query_arg('backup',$this->backup_file,$this->page_url);
|
440 |
+
wp_redirect($download_uri);
|
441 |
exit;
|
442 |
}
|
443 |
// we do this to say we're done.
|
474 |
t[k].p[i].id = k + '-table-' + i;
|
475 |
t[k].p[i].onkeyup = t[k].p[i].onclick = function(e) {
|
476 |
e = e ? e : event;
|
477 |
+
if ( 16 == e.keyCode )
|
478 |
return;
|
479 |
var match = /([\w-]*)-table-(\d*)/.exec(this.id);
|
480 |
var listname = match[1];
|
494 |
}
|
495 |
|
496 |
<?php if ( function_exists('wp_schedule_event') ) : // needs to be at least WP 2.1 for ajax ?>
|
497 |
+
if ( 'undefined' == typeof XMLHttpRequest )
|
498 |
var xml = new ActiveXObject( navigator.userAgent.indexOf('MSIE 5') >= 0 ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP' );
|
499 |
else
|
500 |
var xml = new XMLHttpRequest();
|
503 |
var timeWrap = document.getElementById('backup-time-wrap');
|
504 |
var backupTime = document.getElementById('next-backup-time');
|
505 |
if ( !! timeWrap && !! backupTime && ( 1 == <?php
|
506 |
+
echo (int) ( 'en' == strtolower( substr( get_locale(), 0, 2 ) ) );
|
507 |
?> ) ) {
|
508 |
var span = document.createElement('span');
|
509 |
span.className = 'submit';
|
525 |
if ( !! saveTButton )
|
526 |
saveTButton.onclick = function(e) { saveTime(backupTime, mainText); return false; };
|
527 |
if ( !! mainText )
|
528 |
+
mainText.onkeydown = function(e) {
|
529 |
e = e || window.event;
|
530 |
if ( 13 == e.keyCode ) {
|
531 |
saveTime(backupTime, mainText);
|
587 |
margin-bottom: .5em;
|
588 |
padding: 1em;
|
589 |
}
|
590 |
+
|
591 |
fieldset.options .instructions {
|
592 |
font-size: smaller;
|
593 |
}
|
603 |
border-top: none;
|
604 |
}
|
605 |
</style>
|
606 |
+
<?php
|
607 |
}
|
608 |
|
609 |
function admin_load() {
|
633 |
add_action('load-' . $page_hook, array(&$this, 'admin_load'));
|
634 |
}
|
635 |
|
636 |
+
/**
|
637 |
* Add WP-DB-Backup-specific help options to the 2.7 =< WP contextual help menu
|
638 |
* @return string The text of the help menu.
|
639 |
*/
|
669 |
if ($is_like) $a_string = str_replace('\\', '\\\\\\\\', $a_string);
|
670 |
else $a_string = str_replace('\\', '\\\\', $a_string);
|
671 |
return str_replace('\'', '\\\'', $a_string);
|
672 |
+
}
|
673 |
|
674 |
/**
|
675 |
* Add backquotes to tables and db-names in
|
680 |
if (is_array($a_name)) {
|
681 |
$result = array();
|
682 |
reset($a_name);
|
683 |
+
while(list($key, $val) = each($a_name))
|
684 |
$result[$key] = '`' . $val . '`';
|
685 |
return $result;
|
686 |
} else {
|
689 |
} else {
|
690 |
return $a_name;
|
691 |
}
|
692 |
+
}
|
693 |
|
694 |
function open($filename = '', $mode = 'w') {
|
695 |
if ('' == $filename) return false;
|
710 |
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);
|
712 |
}
|
713 |
+
|
714 |
/**
|
715 |
* Logs any error messages
|
716 |
* @param array $args
|
717 |
* @return bool
|
718 |
*/
|
719 |
function error($args = array()) {
|
720 |
+
if ( is_string( $args ) )
|
721 |
$args = array('msg' => $args);
|
722 |
$args = array_merge( array('loc' => 'main', 'kind' => 'warn', 'msg' => ''), $args);
|
723 |
$this->errors[$args['kind']][] = $args['msg'];
|
727 |
}
|
728 |
|
729 |
/**
|
730 |
+
* Displays error messages
|
731 |
* @param array $errs
|
732 |
* @param string $loc
|
733 |
* @return string
|
743 |
if ( 10 == count( $err_list ) )
|
744 |
$err_list[9] = __('Subsequent errors have been omitted from this log.','wp-db-backup');
|
745 |
$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 ) ?
|
747 |
"try{ window.parent.addError('%1\$s'); } catch(e) { msgList += ' %1\$s';}\n" :
|
748 |
"%1\$s<br />\n";
|
749 |
foreach( (array) $err_list as $err )
|
763 |
* Taken partially from phpMyAdmin and partially from
|
764 |
* Alain Wolf, Zurich - Switzerland
|
765 |
* Website: http://restkultur.ch/personal/wolf/scripts/db_backup/
|
766 |
+
|
767 |
+
* Modified by Scott Merrill (http://www.skippy.net/)
|
768 |
* to use the WordPress $wpdb object
|
769 |
* @param string $table
|
770 |
* @param string $segment
|
778 |
$this->error(__('Error getting table details','wp-db-backup') . ": $table");
|
779 |
return false;
|
780 |
}
|
781 |
+
|
782 |
if(($segment == 'none') || ($segment == 0)) {
|
783 |
// Add SQL statement to drop existing table
|
784 |
$this->stow("\n\n");
|
787 |
$this->stow("#\n");
|
788 |
$this->stow("\n");
|
789 |
$this->stow("DROP TABLE IF EXISTS " . $this->backquote($table) . ";\n");
|
790 |
+
|
791 |
// Table structure
|
792 |
// Comment in SQL-file
|
793 |
$this->stow("\n\n");
|
795 |
$this->stow("# " . sprintf(__('Table structure of table %s','wp-db-backup'),$this->backquote($table)) . "\n");
|
796 |
$this->stow("#\n");
|
797 |
$this->stow("\n");
|
798 |
+
|
799 |
$create_table = $wpdb->get_results("SHOW CREATE TABLE $table", ARRAY_N);
|
800 |
if (false === $create_table) {
|
801 |
$err_msg = sprintf(__('Error with SHOW CREATE TABLE for %s.','wp-db-backup'), $table);
|
803 |
$this->stow("#\n# $err_msg\n#\n");
|
804 |
}
|
805 |
$this->stow($create_table[0][1] . ' ;');
|
806 |
+
|
807 |
if (false === $table_structure) {
|
808 |
$err_msg = sprintf(__('Error getting table structure of %s','wp-db-backup'), $table);
|
809 |
$this->error($err_msg);
|
810 |
$this->stow("#\n# $err_msg\n#\n");
|
811 |
}
|
812 |
+
|
813 |
// Comment in SQL-file
|
814 |
$this->stow("\n\n");
|
815 |
$this->stow("#\n");
|
816 |
$this->stow('# ' . sprintf(__('Data contents of table %s','wp-db-backup'),$this->backquote($table)) . "\n");
|
817 |
$this->stow("#\n");
|
818 |
}
|
819 |
+
|
820 |
if(($segment == 'none') || ($segment >= 0)) {
|
821 |
$defs = array();
|
822 |
$ints = array();
|
830 |
$ints[strtolower($struct->Field)] = "1";
|
831 |
}
|
832 |
}
|
833 |
+
|
834 |
+
|
835 |
// Batch by $row_inc
|
836 |
+
|
837 |
if($segment == 'none') {
|
838 |
$row_start = 0;
|
839 |
$row_inc = ROWS_PER_SEGMENT;
|
841 |
$row_start = $segment * ROWS_PER_SEGMENT;
|
842 |
$row_inc = ROWS_PER_SEGMENT;
|
843 |
}
|
844 |
+
|
845 |
+
do {
|
846 |
// don't include extra stuff, if so requested
|
847 |
$excs = (array) get_option('wp_db_backup_excs');
|
848 |
$where = '';
|
851 |
} elseif ( is_array($excs['revisions'] ) && in_array($table, $excs['revisions']) ) {
|
852 |
$where = ' WHERE post_type != "revision"';
|
853 |
}
|
854 |
+
|
855 |
if ( !ini_get('safe_mode')) @set_time_limit(15*60);
|
856 |
$table_data = $wpdb->get_results("SELECT * FROM $table $where LIMIT {$row_start}, {$row_inc}", ARRAY_A);
|
857 |
|
858 |
+
$entries = 'INSERT INTO ' . $this->backquote($table) . ' VALUES (';
|
859 |
// \x08\\x09, not required
|
860 |
$search = array("\x00", "\x0a", "\x0d", "\x1a");
|
861 |
$replace = array('\0', '\n', '\r', '\Z');
|
878 |
}
|
879 |
} while((count($table_data) > 0) and ($segment=='none'));
|
880 |
}
|
881 |
+
|
882 |
if(($segment == 'none') || ($segment < 0)) {
|
883 |
// Create footer/closing comment in SQL-file
|
884 |
$this->stow("\n");
|
888 |
$this->stow("\n");
|
889 |
}
|
890 |
} // end backup_table()
|
891 |
+
|
892 |
function db_backup($core_tables, $other_tables) {
|
893 |
global $table_prefix, $wpdb;
|
894 |
+
|
895 |
if (is_writable($this->backup_dir)) {
|
896 |
$this->fp = $this->open($this->backup_dir . $this->backup_filename);
|
897 |
if(!$this->fp) {
|
902 |
$this->error(__('The backup directory is not writeable!','wp-db-backup'));
|
903 |
return false;
|
904 |
}
|
905 |
+
|
906 |
//Begin new backup of MySql
|
907 |
$this->stow("# " . __('WordPress MySQL database backup','wp-db-backup') . "\n");
|
908 |
$this->stow("#\n");
|
910 |
$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");
|
912 |
$this->stow("# --------------------------------------------------------\n");
|
913 |
+
|
914 |
if ( (is_array($other_tables)) && (count($other_tables) > 0) )
|
915 |
$tables = array_merge($core_tables, $other_tables);
|
916 |
else
|
917 |
$tables = $core_tables;
|
918 |
+
|
919 |
foreach ($tables as $table) {
|
920 |
// Increase script execution time-limit to 15 min for every table.
|
921 |
if ( !ini_get('safe_mode')) @set_time_limit(15*60);
|
925 |
$this->stow("# --------------------------------------------------------\n");
|
926 |
$this->backup_table($table);
|
927 |
}
|
928 |
+
|
929 |
$this->close($this->fp);
|
930 |
+
|
931 |
if (count($this->errors)) {
|
932 |
return false;
|
933 |
} else {
|
934 |
return $this->backup_filename;
|
935 |
}
|
936 |
+
|
937 |
} //wp_db_backup
|
938 |
|
939 |
/**
|
961 |
|
962 |
// try to use phpmailer directly (WP 2.2+)
|
963 |
if ( is_object( $phpmailer ) && ( strtolower(get_class( $phpmailer )) == 'phpmailer' ) ) {
|
964 |
+
|
965 |
// Get the site domain and get rid of www.
|
966 |
+
$sitename = $this->get_sitename();
|
|
|
|
|
|
|
967 |
$from_email = 'wordpress@' . $sitename;
|
968 |
$from_name = 'WordPress';
|
969 |
|
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
|
994 |
$randomish = md5(time());
|
995 |
$boundary = "==WPBACKUP-$randomish";
|
996 |
$fp = fopen($diskfile,"rb");
|
997 |
+
$file = fread($fp,filesize($diskfile));
|
998 |
$this->close($fp);
|
999 |
+
|
1000 |
$data = chunk_split(base64_encode($file));
|
1001 |
+
|
1002 |
$headers .= "MIME-Version: 1.0\n";
|
1003 |
+
$headers = 'From: wordpress@' . preg_replace('#^www\.#', '', sanitize_text_field(strtolower($_SERVER['SERVER_NAME']))) . "\n";
|
1004 |
$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
|
1005 |
+
|
1006 |
// Add a multipart boundary above the plain message
|
1007 |
$message = "This is a multi-part message in MIME format.\n\n" .
|
1008 |
+
"--{$boundary}\n" .
|
1009 |
"Content-Type: text/plain; charset=\"" . get_bloginfo('charset') . "\"\n" .
|
1010 |
"Content-Transfer-Encoding: 7bit\n\n" .
|
1011 |
$message . "\n\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;
|
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 |
|
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') ) {
|
1075 |
}
|
1076 |
}
|
1077 |
/*
|
1078 |
+
*
|
1079 |
*/
|
1080 |
} elseif ( file_exists( $gz_diskfile ) && empty( $_GET['download-retry'] ) ) {
|
1081 |
$diskfile = $gz_diskfile;
|
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 {
|
1090 |
return true;
|
1117 |
$err = error_get_last();
|
1118 |
$msg .= $err['message'];
|
1119 |
} else {
|
1120 |
+
$msg .= __('ERROR: The mail application has failed to deliver the backup.','wp-db-backup');
|
1121 |
}
|
1122 |
$this->error(array('kind' => 'fatal', 'loc' => $location, 'msg' => $msg));
|
1123 |
} else {
|
1128 |
}
|
1129 |
return $success;
|
1130 |
}
|
1131 |
+
|
1132 |
function backup_menu() {
|
1133 |
global $table_prefix, $wpdb;
|
1134 |
$feedback = '';
|
1135 |
$whoops = false;
|
1136 |
+
|
1137 |
// did we just do a backup? If so, let's report the status
|
1138 |
if ( $this->backup_complete ) {
|
1139 |
$feedback = '<div class="updated wp-db-backup-updated"><p>' . __('Backup Successful','wp-db-backup') . '!';
|
1154 |
}
|
1155 |
$feedback .= '</p></div>';
|
1156 |
}
|
1157 |
+
|
1158 |
// security check
|
1159 |
+
$this->wp_secure();
|
1160 |
|
1161 |
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>';
|
1165 |
}
|
1166 |
|
1167 |
// did we just save options for wp-cron?
|
1168 |
+
if ( (function_exists('wp_schedule_event') || function_exists('wp_cron_init'))
|
1169 |
&& isset($_POST['wp_cron_backup_options']) ) :
|
1170 |
do_action('wp_db_b_update_cron_options');
|
1171 |
if ( function_exists('wp_schedule_event') ) {
|
1172 |
wp_clear_scheduled_hook( 'wp_db_backup_cron' ); // unschedule previous
|
1173 |
$scheds = (array) wp_get_schedules();
|
1174 |
+
$name = sanitize_text_field(strval($_POST['wp_cron_schedule']));
|
1175 |
+
$interval = ( isset($scheds[$name]['interval']) ) ?
|
1176 |
(int) $scheds[$name]['interval'] : 0;
|
1177 |
update_option('wp_cron_backup_schedule', $name, false);
|
1178 |
if ( 0 !== $interval ) {
|
1182 |
else {
|
1183 |
update_option('wp_cron_backup_schedule', intval($_POST['cron_schedule']), false);
|
1184 |
}
|
1185 |
+
update_option('wp_cron_backup_tables', $this->get_submitted_tables_to_backup_in_cron());
|
1186 |
if (is_email($_POST['cron_backup_recipient'])) {
|
1187 |
+
update_option('wp_cron_backup_recipient', sanitize_text_field($_POST['cron_backup_recipient']), false);
|
1188 |
}
|
1189 |
$feedback .= '<div class="updated wp-db-backup-updated"><p>' . __('Scheduled Backup Options Saved!','wp-db-backup') . '</p></div>';
|
1190 |
endif;
|
1191 |
+
|
1192 |
$other_tables = array();
|
1193 |
$also_backup = array();
|
1194 |
+
|
1195 |
+
// Get complete db table list
|
1196 |
$all_tables = $wpdb->get_results("SHOW TABLES", ARRAY_N);
|
1197 |
$all_tables = array_map(create_function('$a', 'return $a[0];'), $all_tables);
|
1198 |
// 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);
|
1200 |
// Get list of non-WP tables
|
1201 |
$other_tables = array_diff($all_tables, $wp_backup_default_tables);
|
1202 |
+
|
1203 |
if ('' != $feedback)
|
1204 |
echo $feedback;
|
1205 |
|
1206 |
+
if ( ! $this->wp_secure() )
|
1207 |
return;
|
1208 |
|
1209 |
// Give the new dirs the same perms as wp-content.
|
1220 |
} elseif ( !is_writable($this->backup_dir) && ! @chmod($this->backup_dir, $dir_perms) ) {
|
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>
|
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>'); ?>
|
1223 |
+
</p></div><?php
|
1224 |
$whoops = true;
|
1225 |
} else {
|
1226 |
$this->fp = $this->open($this->backup_dir . 'test' );
|
1227 |
+
if( $this->fp ) {
|
1228 |
$this->close($this->fp);
|
1229 |
@unlink($this->backup_dir . 'test' );
|
1230 |
// the directory is not writable probably due to safe mode
|
1231 |
} 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
|
1233 |
if( ini_get('safe_mode') ){
|
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
|
1235 |
}
|
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>');
|
1237 |
+
?></div><?php
|
1238 |
$whoops = true;
|
1239 |
}
|
1240 |
}
|
1241 |
|
1242 |
+
|
1243 |
|
1244 |
if ( !file_exists($this->backup_dir . 'index.php') )
|
1245 |
@ touch($this->backup_dir . 'index.php');
|
1265 |
?></ul>
|
1266 |
</div>
|
1267 |
<div class="tables-list extra-tables" id="extra-tables-list">
|
1268 |
+
<?php
|
1269 |
+
if (count($other_tables) > 0) {
|
1270 |
?>
|
1271 |
<h4><?php _e('You may choose to include any of the following tables:','wp-db-backup'); ?></h4>
|
1272 |
<ul>
|
1274 |
foreach ($other_tables as $table) {
|
1275 |
?>
|
1276 |
<li><label><input type="checkbox" name="other_tables[]" value="<?php echo $table; ?>" /> <code><?php echo $table; ?></code></label>
|
1277 |
+
<?php
|
1278 |
}
|
1279 |
+
?></ul><?php
|
1280 |
}
|
1281 |
?></div>
|
1282 |
</fieldset>
|
1283 |
+
|
1284 |
<fieldset class="options">
|
1285 |
<legend><?php _e('Backup Options','wp-db-backup'); ?></legend>
|
1286 |
<p><?php _e('What to do with the backup file:','wp-db-backup'); ?></p>
|
1292 |
<li><label for="do_email">
|
1293 |
<input type="radio" name="deliver" id="do_email" value="smtp" style="border:none;" />
|
1294 |
<?php _e('Email backup to:','wp-db-backup'); ?>
|
1295 |
+
<input type="text" name="backup_recipient" size="20" value="<?php
|
1296 |
$backup_recip = get_option('wpdb_backup_recip');
|
1297 |
if ( empty( $backup_recip ) ) {
|
1298 |
$backup_recip = get_option('admin_email');
|
1302 |
</label></li>
|
1303 |
</ul>
|
1304 |
<?php if ( ! $whoops ) : ?>
|
1305 |
+
<input type="hidden" name="do_backup" id="do_backup" value="backup" />
|
1306 |
<p class="submit">
|
1307 |
<input type="submit" name="submit" onclick="document.getElementById('do_backup').value='fragments';" value="<?php _e('Backup now!','wp-db-backup'); ?>" />
|
1308 |
</p>
|
1312 |
</fieldset>
|
1313 |
<?php do_action('wp_db_b_backup_opts'); ?>
|
1314 |
</form>
|
1315 |
+
|
1316 |
<?php
|
1317 |
+
// 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+
|
1319 |
$cron_old = ( function_exists('wp_cron_init') && ! $cron ) ? true : false; // wp-cron plugin by Skippy
|
1320 |
if ( $cron_old || $cron ) :
|
1327 |
<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>'); ?>
|
1329 |
</p>
|
1330 |
+
<?php
|
1331 |
endif;
|
1332 |
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
|
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
|
1335 |
endif;
|
1336 |
?><form method="post" action="">
|
1337 |
<?php if ( function_exists('wp_nonce_field') ) wp_nonce_field($this->referer_check_key); ?>
|
1338 |
<div class="tables-list">
|
1339 |
<h4><?php _e('Schedule: ','wp-db-backup'); ?></h4>
|
1340 |
+
<?php
|
1341 |
if ( $cron_old ) :
|
1342 |
$wp_cron_backup_schedule = get_option('wp_cron_backup_schedule');
|
1343 |
$schedule = array(0 => __('None','wp-db-backup'), 1 => __('Daily','wp-db-backup'));
|
1378 |
echo '<input type="hidden" name="wp_cron_backup_options" value="SET" /></form>';
|
1379 |
echo '</fieldset>';
|
1380 |
endif; // end of wp_cron (legacy) section
|
1381 |
+
|
1382 |
echo '</div><!-- .wrap -->';
|
1383 |
+
|
1384 |
} // end wp_backup_menu()
|
1385 |
|
1386 |
function get_sched() {
|
1387 |
$options = array_keys( (array) wp_get_schedules() );
|
1388 |
+
$freq = get_option('wp_cron_backup_schedule');
|
1389 |
$freq = ( in_array( $freq , $options ) ) ? $freq : 'never';
|
1390 |
return $freq;
|
1391 |
}
|
1415 |
$menu .= '</ul>';
|
1416 |
return $menu;
|
1417 |
} // end schedule_choices()
|
1418 |
+
|
1419 |
function wp_cron_daily() { // for legacy cron plugin
|
1420 |
$schedule = intval(get_option('wp_cron_backup_schedule'));
|
1421 |
// If scheduled backup is disabled
|
1422 |
if (0 == $schedule)
|
1423 |
return;
|
1424 |
else return $this->cron_backup();
|
1425 |
+
}
|
1426 |
|
1427 |
function cron_backup() {
|
1428 |
global $table_prefix, $wpdb;
|
1432 |
$other_tables = get_option('wp_cron_backup_tables');
|
1433 |
$recipient = get_option('wp_cron_backup_recipient');
|
1434 |
$backup_file = $this->db_backup($core_tables, $other_tables);
|
1435 |
+
if (false !== $backup_file)
|
1436 |
return $this->deliver_backup($backup_file, 'smtp', $recipient, 'main');
|
1437 |
else return false;
|
1438 |
}
|
1443 |
}
|
1444 |
|
1445 |
/**
|
1446 |
+
* Checks that WordPress has sufficient security measures
|
1447 |
* @param string $kind
|
1448 |
* @return bool
|
1449 |
*/
|
1468 |
return false;
|
1469 |
if ( ( $this->wp_secure('fatal', $loc) ) && current_user_can('import') )
|
1470 |
$can = $this->verify_nonce($_REQUEST['_wpnonce'], $this->referer_check_key, $loc);
|
1471 |
+
if ( false == $can )
|
1472 |
$this->error(array('loc' => $loc, 'kind' => 'fatal', 'msg' => __('You are not allowed to perform backups.','wp-db-backup')));
|
1473 |
return $can;
|
1474 |
}
|
1483 |
function verify_nonce($rec = '', $nonce = 'X', $loc = 'main') {
|
1484 |
if ( wp_verify_nonce($rec, $nonce) )
|
1485 |
return true;
|
1486 |
+
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'))));
|
1488 |
}
|
1489 |
|
1490 |
/**
|
1491 |
+
* Check whether a file to be downloaded is
|
1492 |
* surreptitiously trying to download a non-backup file
|
1493 |
* @param string $file
|
1494 |
* @return null
|
1495 |
+
*/
|
1496 |
function validate_file($file) {
|
1497 |
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')));
|
1499 |
}
|
1500 |
|
1501 |
+
/**
|
1502 |
+
* Get the sitename by query $_SERVER['SERVER_NAME'].
|
1503 |
+
* If it is not set, then use site_url() instead
|
1504 |
+
* @return string
|
1505 |
+
*/
|
1506 |
+
function get_sitename() {
|
1507 |
+
$sitename='';
|
1508 |
+
if ( isset($_SERVER['SERVER_NAME']) ) {
|
1509 |
+
$sitename = strtolower( sanitize_text_field( $_SERVER['SERVER_NAME'] ) );
|
1510 |
+
} else {
|
1511 |
+
if ( function_exists('site_url') ) {
|
1512 |
+
// site_url() was added since 3.0.0
|
1513 |
+
// force http scheme so we can easily get rid of leading http://
|
1514 |
+
$sitename = strtolower( site_url( '', 'http' ) );
|
1515 |
+
$sitename = substr( $sitename, 7 );
|
1516 |
+
} else {
|
1517 |
+
// try to be compatible with versions < 3.0.0
|
1518 |
+
$sitename = strtolower( get_option( 'siteurl' ) );
|
1519 |
+
if ( substr( $sitename, 0, 7 ) == 'http://' ) {
|
1520 |
+
$sitename = substr( $sitename, 7 );
|
1521 |
+
} elseif ( substr( $sitename, 0, 8 ) == 'https://' ) {
|
1522 |
+
$sitename = substr( $sitename, 8 );
|
1523 |
+
}
|
1524 |
+
}
|
1525 |
+
}
|
1526 |
+
// get rid of www
|
1527 |
+
if ( substr( $sitename, 0, 4 ) == 'www.' ) {
|
1528 |
+
$sitename = substr( $sitename, 4 );
|
1529 |
+
}
|
1530 |
+
return $sitename;
|
1531 |
+
}
|
1532 |
+
|
1533 |
+
|
1534 |
+
/**
|
1535 |
+
* Sanitize an array of content.
|
1536 |
+
*
|
1537 |
+
* @param array $array_of_data
|
1538 |
+
*
|
1539 |
+
* @return array
|
1540 |
+
*/
|
1541 |
+
function sanitize_array($array_to_sanitize) {
|
1542 |
+
$sanitized = array();
|
1543 |
+
foreach ( $array_to_sanitize as $key => $value ) {
|
1544 |
+
$sanitized[$key] = sanitize_text_field($value);
|
1545 |
+
}
|
1546 |
+
return $sanitized;
|
1547 |
+
}
|
1548 |
+
|
1549 |
+
/**
|
1550 |
+
* Get a sanitized array of submitted $_POST values
|
1551 |
+
*
|
1552 |
+
* @param string $post_key The key of the $_POST array.
|
1553 |
+
*
|
1554 |
+
* @return array
|
1555 |
+
*/
|
1556 |
+
function get_post_data_array($post_key) {
|
1557 |
+
$sanitized_data = array();
|
1558 |
+
if (isset( $_POST[$post_key] )) {
|
1559 |
+
$sanitized_data = (array) $_POST[$post_key];
|
1560 |
+
}
|
1561 |
+
return $this->sanitize_array($sanitized_data);
|
1562 |
+
}
|
1563 |
+
|
1564 |
+
/**
|
1565 |
+
* Get the revisions to exclude.
|
1566 |
+
*
|
1567 |
+
* @return array
|
1568 |
+
*/
|
1569 |
+
function get_revisions_to_exclude() {
|
1570 |
+
return $this->get_post_data_array('exclude-revisions');
|
1571 |
+
}
|
1572 |
+
|
1573 |
+
/**
|
1574 |
+
* Get the spam to exclude.
|
1575 |
+
*
|
1576 |
+
* @return array
|
1577 |
+
*/
|
1578 |
+
function get_spam_to_exclude() {
|
1579 |
+
return $this->get_post_data_array('exclude-spam');
|
1580 |
+
}
|
1581 |
+
|
1582 |
+
/**
|
1583 |
+
* Get the submitted tables to backup.
|
1584 |
+
*
|
1585 |
+
* @return array
|
1586 |
+
*/
|
1587 |
+
function get_submitted_tables_to_backup_in_cron() {
|
1588 |
+
return $this->get_post_data_array('wp_cron_backup_tables');
|
1589 |
+
}
|
1590 |
}
|
1591 |
|
1592 |
function wpdbBackup_init() {
|
1593 |
global $mywpdbbackup;
|
1594 |
+
$mywpdbbackup = new wpdbBackup();
|
1595 |
}
|
1596 |
|
1597 |
add_action('plugins_loaded', 'wpdbBackup_init');
|