Backup and Restore WordPress – WPBackItUp Backup Plugin - Version 1.5.1

Version Description

Removed redundant code.

Download this release

Release Info

Developer jcpeden
Plugin Icon 128x128 Backup and Restore WordPress – WPBackItUp Backup Plugin
Version 1.5.1
Comparing to
See all releases

Code changes from version 1.5.0 to 1.5.1

index.php CHANGED
@@ -1,375 +1,375 @@
1
- <?php
2
- /**
3
- * WP Backitup
4
- *
5
- * @package WP Backitup
6
- *
7
- * @global object $wpdb
8
- *
9
- * @author jcpeden
10
- * @version 1.5.0
11
- */
12
- /*
13
- Plugin Name: WP Backitup
14
- Plugin URI: http://www.wpbackitup.com
15
- Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
16
- Version: 1.5.0
17
- Author: John Peden
18
- Author URI: http://www.johncpeden.com
19
- License: GPL3
20
-
21
- Copyright 2012-2013 John Peden (email : support@wpbackitup.com)
22
-
23
- This program is free software: you can redistribute it and/or modify
24
- it under the terms of the GNU General Public License as published by
25
- the Free Software Foundation, either version 3 of the License, or
26
- (at your option) any later version.
27
-
28
- This program is distributed in the hope that it will be useful,
29
- but WITHOUT ANY WARRANTY; without even the implied warranty of
30
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31
- GNU General Public License for more details.
32
-
33
- You should have received a copy of the GNU General Public License
34
- along with this program. If not, see <http://www.gnu.org/licenses/>.
35
- */
36
- // Include constants file
37
- include_once dirname( __FILE__ ) . '/lib/constants.php';
38
-
39
- class WPBackitup {
40
- var $namespace = "wp-backitup";
41
- var $friendly_name = WPBACKITUP_ITEM_NAME;
42
- var $version = WPBACKITUP_VERSION;
43
-
44
- // Default plugin options
45
- var $defaults = array(
46
- 'presstrends' => "enabled",
47
- 'license_key' => "",
48
- 'status' => "inactive"
49
- );
50
-
51
- /**
52
- * Instantiation construction
53
- *
54
- * @uses add_action()
55
- * @uses WPBackitup::wp_register_scripts()
56
- * @uses WPBackitup::wp_register_styles()
57
- */
58
- function __construct() {
59
- // Name of the option_value to store plugin options in
60
- $this->option_name = '_' . $this->namespace . '--options';
61
-
62
- // Load all library files used by this plugin
63
- $libs = glob( WPBACKITUP_DIRNAME . '/lib/*.php' );
64
- foreach( $libs as $lib ) {
65
- include_once $lib;
66
- }
67
-
68
- /**
69
- * Make this plugin available for translation.
70
- * Translations can be added to the /languages/ directory.
71
- */
72
- load_theme_textdomain( $this->namespace, WPBACKITUP_DIRNAME . '/languages' );
73
-
74
- // Add all action, filter and shortcode hooks
75
- $this->_add_hooks();
76
- }
77
-
78
- /**
79
- * Add in various hooks
80
- */
81
- private function _add_hooks() {
82
- // Options page for configuration
83
- add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
84
- // Route requests for form processing
85
- add_action( 'init', array( &$this, 'route' ) );
86
-
87
- // Add a settings link next to the "Deactivate" link on the plugin listing page
88
- add_filter( 'plugin_action_links', array( &$this, 'plugin_action_links' ), 10, 2 );
89
-
90
- // Register all JavaScripts for this plugin
91
- add_action( 'init', array( &$this, 'wp_register_scripts' ), 1 );
92
- // Register all Stylesheets for this plugin
93
- add_action( 'init', array( &$this, 'wp_register_styles' ), 1 );
94
- }
95
-
96
- /**
97
- * Process update page form submissions and validate license key
98
- *
99
- * @uses WPBackitup::sanitize()
100
- * @uses wp_redirect()
101
- * @uses wp_verify_nonce()
102
- * @uses wp_remote_get()
103
- * @uses add_query_arg()
104
- * @uses is_wp_error()
105
- * @uses wp_remote_retrieve_body()
106
- * @uses update_option()
107
- * @uses wp_safe_redirect()
108
- */
109
- private function _admin_options_update() {
110
-
111
- // Verify submission for processing using wp_nonce
112
- if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-update-options" ) ) {
113
- //create data array
114
- $data = array();
115
-
116
- /**
117
- * Loop through each POSTed value and sanitize it to protect against malicious code. Please
118
- * note that rich text (or full HTML fields) should not be processed by this function and
119
- * dealt with directly.
120
- */
121
- foreach( $_POST['data'] as $key => $val ) {
122
- $data[$key] = $this->_sanitize( $val );
123
- }
124
-
125
- //check license status and try to activate if invalid
126
- $license = trim ( $data['license_key'] );
127
-
128
- // Check license
129
- $api_params = array(
130
- 'edd_action' => 'check_license',
131
- 'license' => $license,
132
- 'item_name' => urlencode( WPBACKITUP_ITEM_NAME )
133
- );
134
-
135
- // Call the custom API
136
- $response = wp_remote_get( add_query_arg( $api_params, WPBACKITUP_SITE_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
137
-
138
- // make sure the response came back okay
139
- if ( is_wp_error( $response ) )
140
- return false;
141
-
142
- // decode the license data
143
- $license_data = json_decode( wp_remote_retrieve_body( $response ) );
144
-
145
- if( $license_data->license != 'valid' ) {
146
- // Try to activate license (process is almost identical to check_license)
147
- $api_params = array(
148
- 'edd_action'=> 'activate_license',
149
- 'license' => $license,
150
- 'item_name' => urlencode( WPBACKITUP_ITEM_NAME ) // the name of our product in EDD
151
- );
152
- $response = wp_remote_get( add_query_arg( $api_params, WPBACKITUP_SITE_URL ) );
153
- if ( is_wp_error( $response ) )
154
- return false;
155
- $license_data = json_decode( wp_remote_retrieve_body( $response ) );
156
- }
157
-
158
- /* Manually define status value */
159
- $data['status'] = $license_data->license;
160
-
161
- // Update the options value with the data submitted
162
- update_option( $this->option_name, $data );
163
-
164
- // Redirect back to the options page with the message flag to show the saved message
165
- wp_safe_redirect( $_REQUEST['_wp_http_referer'] . '&update=1' );
166
- exit;
167
- }
168
- }
169
-
170
- /**
171
- * Sanitize data
172
- *
173
- * @param mixed $str The data to be sanitized
174
- *
175
- * @uses wp_kses()
176
- *
177
- * @return mixed The sanitized version of the data
178
- */
179
- private function _sanitize( $str ) {
180
- if ( !function_exists( 'wp_kses' ) ) {
181
- include_once ABSPATH . 'wp-includes/kses.php';
182
- }
183
- global $allowedposttags;
184
- global $allowedprotocols;
185
-
186
- if ( is_string( $str ) ) {
187
- $str = wp_kses( $str, $allowedposttags, $allowedprotocols );
188
- } elseif( is_array( $str ) ) {
189
- $arr = array();
190
- foreach( (array) $str as $key => $val ) {
191
- $arr[$key] = $this->_sanitize( $val );
192
- }
193
- $str = $arr;
194
- }
195
-
196
- return $str;
197
- }
198
-
199
- /**
200
- * Hook into register_activation_hook action
201
- */
202
- static function activate() {
203
- // Do activation actions
204
- }
205
-
206
- /**
207
- * Define the admin menu options for this plugin
208
- *
209
- * @uses add_action()
210
- * @uses add_options_page()
211
- */
212
- function admin_menu() {
213
- $page_hook = add_menu_page( $this->friendly_name, $this->friendly_name, 'administrator', $this->namespace, array( &$this, 'admin_options_page' ), WPBACKITUP_URLPATH .'/images/icon.png', 77);
214
-
215
- // Add print scripts and styles action based off the option page hook
216
- add_action( 'admin_print_scripts-' . $page_hook, array( &$this, 'admin_print_scripts' ) );
217
- add_action( 'admin_print_styles-' . $page_hook, array( &$this, 'admin_print_styles' ) );
218
- }
219
-
220
-
221
- /**
222
- * The admin section options page rendering method
223
- *
224
- * @uses current_user_can()
225
- * @uses wp_die()
226
- */
227
- function admin_options_page() {
228
- if( !current_user_can( 'manage_options' ) ) {
229
- wp_die( 'You do not have sufficient permissions to access this page' );
230
- }
231
-
232
- $page_title = $this->friendly_name . ' Options';
233
- $namespace = $this->namespace;
234
-
235
- include WPBACKITUP_DIRNAME . "/views/options.php";
236
- }
237
-
238
- /**
239
- * Load JavaScript for the admin options page
240
- *
241
- * @uses wp_enqueue_script()
242
- */
243
- function admin_print_scripts() {
244
- wp_enqueue_script( "{$this->namespace}-admin" );
245
- wp_enqueue_script( "{$this->namespace}-ajaxfileupload" );
246
- }
247
-
248
- /**
249
- * Load Stylesheet for the admin options page
250
- *
251
- * @uses wp_enqueue_style()
252
- */
253
- function admin_print_styles() {
254
- wp_enqueue_style( "{$this->namespace}-admin" );
255
- }
256
-
257
- /**
258
- * Hook into register_deactivation_hook action
259
- *
260
- * Put code here that needs to happen when your plugin is deactivated
261
- */
262
- static function deactivate() {
263
- // Do deactivation actions
264
- }
265
-
266
- /**
267
- * Retrieve the stored plugin option or the default if no user specified value is defined
268
- *
269
- * @param string $option_name The name of the TrialAccount option you wish to retrieve
270
- *
271
- * @uses get_option()
272
- *
273
- * @return mixed Returns the option value or false(boolean) if the option is not found
274
- */
275
- function get_option( $option_name ) {
276
- // Load option values if they haven't been loaded already
277
- if( !isset( $this->options ) || empty( $this->options ) ) {
278
- $this->options = get_option( $this->option_name, $this->defaults );
279
- }
280
-
281
- if( isset( $this->options[$option_name] ) ) {
282
- return $this->options[$option_name]; // Return user's specified option value
283
- } elseif( isset( $this->defaults[$option_name] ) ) {
284
- return $this->defaults[$option_name]; // Return default option value
285
- }
286
- return false;
287
- }
288
-
289
- /**
290
- * Initialization function to hook into the WordPress init action
291
- *
292
- * Instantiates the class on a global variable and sets the class, actions
293
- * etc. up for use.
294
- */
295
- static function instance() {
296
- global $WPBackitup;
297
-
298
- // Only instantiate the Class if it hasn't been already
299
- if( !isset( $WPBackitup ) ) $WPBackitup = new WPBackitup();
300
- }
301
-
302
- /**
303
- * Hook into plugin_action_links filter
304
- *
305
- * @param object $links An array of the links to show, this will be the modified variable
306
- * @param string $file The name of the file being processed in the filter
307
- */
308
- function plugin_action_links( $links, $file ) {
309
- if( $file == plugin_basename( WPBACKITUP_DIRNAME . '/' . basename( __FILE__ ) ) ) {
310
- $old_links = $links;
311
- $new_links = array(
312
- "settings" => '<a href="admin.php?page=' . $this->namespace . '">' . __( 'Manage' ) . '</a>'
313
- );
314
- $links = array_merge( $new_links, $old_links );
315
- }
316
-
317
- return $links;
318
- }
319
-
320
- /**
321
- * Route the user based off of environment conditions
322
- *
323
- * @uses WPBackitup::_admin_options_update()
324
- */
325
- function route() {
326
- $uri = $_SERVER['REQUEST_URI'];
327
- $protocol = isset( $_SERVER['HTTPS'] ) ? 'https' : 'http';
328
- $hostname = $_SERVER['HTTP_HOST'];
329
- $url = "{$protocol}://{$hostname}{$uri}";
330
- $is_post = (bool) ( strtoupper( $_SERVER['REQUEST_METHOD'] ) == "POST" );
331
-
332
- // Check if a nonce was passed in the request
333
- if( isset( $_REQUEST['_wpnonce'] ) ) {
334
- $nonce = $_REQUEST['_wpnonce'];
335
-
336
- // Handle POST requests
337
- if( $is_post ) {
338
- if( wp_verify_nonce( $nonce, "{$this->namespace}-update-options" ) ) {
339
- $this->_admin_options_update();
340
- }
341
- }
342
- // Handle GET requests
343
- else {
344
-
345
- }
346
- }
347
- }
348
-
349
- /**
350
- * Register scripts used by this plugin for enqueuing elsewhere
351
- *
352
- * @uses wp_register_script()
353
- */
354
- function wp_register_scripts() {
355
- // Admin JavaScript
356
- wp_register_script( "{$this->namespace}-admin", WPBACKITUP_URLPATH . "/js/admin.js", array( 'jquery' ), $this->version, true );
357
- wp_register_script( "{$this->namespace}-ajaxfileupload", WPBACKITUP_URLPATH . "/js/ajaxfileupload.js", array( 'jquery' ), $this->version, true );
358
- }
359
-
360
- /**
361
- * Register styles used by this plugin for enqueuing elsewhere
362
- *
363
- * @uses wp_register_style()
364
- */
365
- function wp_register_styles() {
366
- // Admin Stylesheet
367
- wp_register_style( "{$this->namespace}-admin", WPBACKITUP_URLPATH . "/css/admin.css", array(), $this->version, 'screen' );
368
- }
369
- }
370
- if( !isset( $WPBackitup ) ) {
371
- WPBackitup::instance();
372
- }
373
-
374
- register_activation_hook( __FILE__, array( 'WPBackitup', 'activate' ) );
375
- register_deactivation_hook( __FILE__, array( 'WPBackitup', 'deactivate' ) );
1
+ <?php
2
+ /**
3
+ * WP Backitup
4
+ *
5
+ * @package WP Backitup
6
+ *
7
+ * @global object $wpdb
8
+ *
9
+ * @author jcpeden
10
+ * @version 1.5.1
11
+ */
12
+ /*
13
+ Plugin Name: WP Backitup
14
+ Plugin URI: http://www.wpbackitup.com
15
+ Description: Backup your content, settings, themes, plugins and media in just a few simple clicks.
16
+ Version: 1.5.1
17
+ Author: John Peden
18
+ Author URI: http://www.johncpeden.com
19
+ License: GPL3
20
+
21
+ Copyright 2012-2013 John Peden (email : support@wpbackitup.com)
22
+
23
+ This program is free software: you can redistribute it and/or modify
24
+ it under the terms of the GNU General Public License as published by
25
+ the Free Software Foundation, either version 3 of the License, or
26
+ (at your option) any later version.
27
+
28
+ This program is distributed in the hope that it will be useful,
29
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
30
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31
+ GNU General Public License for more details.
32
+
33
+ You should have received a copy of the GNU General Public License
34
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
35
+ */
36
+ // Include constants file
37
+ include_once dirname( __FILE__ ) . '/lib/constants.php';
38
+
39
+ class WPBackitup {
40
+ var $namespace = "wp-backitup";
41
+ var $friendly_name = WPBACKITUP_ITEM_NAME;
42
+ var $version = WPBACKITUP_VERSION;
43
+
44
+ // Default plugin options
45
+ var $defaults = array(
46
+ 'presstrends' => "enabled",
47
+ 'license_key' => "",
48
+ 'status' => "inactive"
49
+ );
50
+
51
+ /**
52
+ * Instantiation construction
53
+ *
54
+ * @uses add_action()
55
+ * @uses WPBackitup::wp_register_scripts()
56
+ * @uses WPBackitup::wp_register_styles()
57
+ */
58
+ function __construct() {
59
+ // Name of the option_value to store plugin options in
60
+ $this->option_name = '_' . $this->namespace . '--options';
61
+
62
+ // Load all library files used by this plugin
63
+ $libs = glob( WPBACKITUP_DIRNAME . '/lib/*.php' );
64
+ foreach( $libs as $lib ) {
65
+ include_once $lib;
66
+ }
67
+
68
+ /**
69
+ * Make this plugin available for translation.
70
+ * Translations can be added to the /languages/ directory.
71
+ */
72
+ load_theme_textdomain( $this->namespace, WPBACKITUP_DIRNAME . '/languages' );
73
+
74
+ // Add all action, filter and shortcode hooks
75
+ $this->_add_hooks();
76
+ }
77
+
78
+ /**
79
+ * Add in various hooks
80
+ */
81
+ private function _add_hooks() {
82
+ // Options page for configuration
83
+ add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
84
+ // Route requests for form processing
85
+ add_action( 'init', array( &$this, 'route' ) );
86
+
87
+ // Add a settings link next to the "Deactivate" link on the plugin listing page
88
+ add_filter( 'plugin_action_links', array( &$this, 'plugin_action_links' ), 10, 2 );
89
+
90
+ // Register all JavaScripts for this plugin
91
+ add_action( 'init', array( &$this, 'wp_register_scripts' ), 1 );
92
+ // Register all Stylesheets for this plugin
93
+ add_action( 'init', array( &$this, 'wp_register_styles' ), 1 );
94
+ }
95
+
96
+ /**
97
+ * Process update page form submissions and validate license key
98
+ *
99
+ * @uses WPBackitup::sanitize()
100
+ * @uses wp_redirect()
101
+ * @uses wp_verify_nonce()
102
+ * @uses wp_remote_get()
103
+ * @uses add_query_arg()
104
+ * @uses is_wp_error()
105
+ * @uses wp_remote_retrieve_body()
106
+ * @uses update_option()
107
+ * @uses wp_safe_redirect()
108
+ */
109
+ private function _admin_options_update() {
110
+
111
+ // Verify submission for processing using wp_nonce
112
+ if( wp_verify_nonce( $_REQUEST['_wpnonce'], "{$this->namespace}-update-options" ) ) {
113
+ //create data array
114
+ $data = array();
115
+
116
+ /**
117
+ * Loop through each POSTed value and sanitize it to protect against malicious code. Please
118
+ * note that rich text (or full HTML fields) should not be processed by this function and
119
+ * dealt with directly.
120
+ */
121
+ foreach( $_POST['data'] as $key => $val ) {
122
+ $data[$key] = $this->_sanitize( $val );
123
+ }
124
+
125
+ //check license status and try to activate if invalid
126
+ $license = trim ( $data['license_key'] );
127
+
128
+ // Check license
129
+ $api_params = array(
130
+ 'edd_action' => 'check_license',
131
+ 'license' => $license,
132
+ 'item_name' => urlencode( WPBACKITUP_ITEM_NAME )
133
+ );
134
+
135
+ // Call the custom API
136
+ $response = wp_remote_get( add_query_arg( $api_params, WPBACKITUP_SITE_URL ), array( 'timeout' => 15, 'sslverify' => false ) );
137
+
138
+ // make sure the response came back okay
139
+ if ( is_wp_error( $response ) )
140
+ return false;
141
+
142
+ // decode the license data
143
+ $license_data = json_decode( wp_remote_retrieve_body( $response ) );
144
+
145
+ if( $license_data->license != 'valid' ) {
146
+ // Try to activate license (process is almost identical to check_license)
147
+ $api_params = array(
148
+ 'edd_action'=> 'activate_license',
149
+ 'license' => $license,
150
+ 'item_name' => urlencode( WPBACKITUP_ITEM_NAME ) // the name of our product in EDD
151
+ );
152
+ $response = wp_remote_get( add_query_arg( $api_params, WPBACKITUP_SITE_URL ) );
153
+ if ( is_wp_error( $response ) )
154
+ return false;
155
+ $license_data = json_decode( wp_remote_retrieve_body( $response ) );
156
+ }
157
+
158
+ /* Manually define status value */
159
+ $data['status'] = $license_data->license;
160
+
161
+ // Update the options value with the data submitted
162
+ update_option( $this->option_name, $data );
163
+
164
+ // Redirect back to the options page with the message flag to show the saved message
165
+ wp_safe_redirect( $_REQUEST['_wp_http_referer'] . '&update=1' );
166
+ exit;
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Sanitize data
172
+ *
173
+ * @param mixed $str The data to be sanitized
174
+ *
175
+ * @uses wp_kses()
176
+ *
177
+ * @return mixed The sanitized version of the data
178
+ */
179
+ private function _sanitize( $str ) {
180
+ if ( !function_exists( 'wp_kses' ) ) {
181
+ include_once ABSPATH . 'wp-includes/kses.php';
182
+ }
183
+ global $allowedposttags;
184
+ global $allowedprotocols;
185
+
186
+ if ( is_string( $str ) ) {
187
+ $str = wp_kses( $str, $allowedposttags, $allowedprotocols );
188
+ } elseif( is_array( $str ) ) {
189
+ $arr = array();
190
+ foreach( (array) $str as $key => $val ) {
191
+ $arr[$key] = $this->_sanitize( $val );
192
+ }
193
+ $str = $arr;
194
+ }
195
+
196
+ return $str;
197
+ }
198
+
199
+ /**
200
+ * Hook into register_activation_hook action
201
+ */
202
+ static function activate() {
203
+ // Do activation actions
204
+ }
205
+
206
+ /**
207
+ * Define the admin menu options for this plugin
208
+ *
209
+ * @uses add_action()
210
+ * @uses add_options_page()
211
+ */
212
+ function admin_menu() {
213
+ $page_hook = add_menu_page( $this->friendly_name, $this->friendly_name, 'administrator', $this->namespace, array( &$this, 'admin_options_page' ), WPBACKITUP_URLPATH .'/images/icon.png', 77);
214
+
215
+ // Add print scripts and styles action based off the option page hook
216
+ add_action( 'admin_print_scripts-' . $page_hook, array( &$this, 'admin_print_scripts' ) );
217
+ add_action( 'admin_print_styles-' . $page_hook, array( &$this, 'admin_print_styles' ) );
218
+ }
219
+
220
+
221
+ /**
222
+ * The admin section options page rendering method
223
+ *
224
+ * @uses current_user_can()
225
+ * @uses wp_die()
226
+ */
227
+ function admin_options_page() {
228
+ if( !current_user_can( 'manage_options' ) ) {
229
+ wp_die( 'You do not have sufficient permissions to access this page' );
230
+ }
231
+
232
+ $page_title = $this->friendly_name . ' Options';
233
+ $namespace = $this->namespace;
234
+
235
+ include WPBACKITUP_DIRNAME . "/views/options.php";
236
+ }
237
+
238
+ /**
239
+ * Load JavaScript for the admin options page
240
+ *
241
+ * @uses wp_enqueue_script()
242
+ */
243
+ function admin_print_scripts() {
244
+ wp_enqueue_script( "{$this->namespace}-admin" );
245
+ wp_enqueue_script( "{$this->namespace}-ajaxfileupload" );
246
+ }
247
+
248
+ /**
249
+ * Load Stylesheet for the admin options page
250
+ *
251
+ * @uses wp_enqueue_style()
252
+ */
253
+ function admin_print_styles() {
254
+ wp_enqueue_style( "{$this->namespace}-admin" );
255
+ }
256
+
257
+ /**
258
+ * Hook into register_deactivation_hook action
259
+ *
260
+ * Put code here that needs to happen when your plugin is deactivated
261
+ */
262
+ static function deactivate() {
263
+ // Do deactivation actions
264
+ }
265
+
266
+ /**
267
+ * Retrieve the stored plugin option or the default if no user specified value is defined
268
+ *
269
+ * @param string $option_name The name of the TrialAccount option you wish to retrieve
270
+ *
271
+ * @uses get_option()
272
+ *
273
+ * @return mixed Returns the option value or false(boolean) if the option is not found
274
+ */
275
+ function get_option( $option_name ) {
276
+ // Load option values if they haven't been loaded already
277
+ if( !isset( $this->options ) || empty( $this->options ) ) {
278
+ $this->options = get_option( $this->option_name, $this->defaults );
279
+ }
280
+
281
+ if( isset( $this->options[$option_name] ) ) {
282
+ return $this->options[$option_name]; // Return user's specified option value
283
+ } elseif( isset( $this->defaults[$option_name] ) ) {
284
+ return $this->defaults[$option_name]; // Return default option value
285
+ }
286
+ return false;
287
+ }
288
+
289
+ /**
290
+ * Initialization function to hook into the WordPress init action
291
+ *
292
+ * Instantiates the class on a global variable and sets the class, actions
293
+ * etc. up for use.
294
+ */
295
+ static function instance() {
296
+ global $WPBackitup;
297
+
298
+ // Only instantiate the Class if it hasn't been already
299
+ if( !isset( $WPBackitup ) ) $WPBackitup = new WPBackitup();
300
+ }
301
+
302
+ /**
303
+ * Hook into plugin_action_links filter
304
+ *
305
+ * @param object $links An array of the links to show, this will be the modified variable
306
+ * @param string $file The name of the file being processed in the filter
307
+ */
308
+ function plugin_action_links( $links, $file ) {
309
+ if( $file == plugin_basename( WPBACKITUP_DIRNAME . '/' . basename( __FILE__ ) ) ) {
310
+ $old_links = $links;
311
+ $new_links = array(
312
+ "settings" => '<a href="admin.php?page=' . $this->namespace . '">' . __( 'Manage' ) . '</a>'
313
+ );
314
+ $links = array_merge( $new_links, $old_links );
315
+ }
316
+
317
+ return $links;
318
+ }
319
+
320
+ /**
321
+ * Route the user based off of environment conditions
322
+ *
323
+ * @uses WPBackitup::_admin_options_update()
324
+ */
325
+ function route() {
326
+ $uri = $_SERVER['REQUEST_URI'];
327
+ $protocol = isset( $_SERVER['HTTPS'] ) ? 'https' : 'http';
328
+ $hostname = $_SERVER['HTTP_HOST'];
329
+ $url = "{$protocol}://{$hostname}{$uri}";
330
+ $is_post = (bool) ( strtoupper( $_SERVER['REQUEST_METHOD'] ) == "POST" );
331
+
332
+ // Check if a nonce was passed in the request
333
+ if( isset( $_REQUEST['_wpnonce'] ) ) {
334
+ $nonce = $_REQUEST['_wpnonce'];
335
+
336
+ // Handle POST requests
337
+ if( $is_post ) {
338
+ if( wp_verify_nonce( $nonce, "{$this->namespace}-update-options" ) ) {
339
+ $this->_admin_options_update();
340
+ }
341
+ }
342
+ // Handle GET requests
343
+ else {
344
+
345
+ }
346
+ }
347
+ }
348
+
349
+ /**
350
+ * Register scripts used by this plugin for enqueuing elsewhere
351
+ *
352
+ * @uses wp_register_script()
353
+ */
354
+ function wp_register_scripts() {
355
+ // Admin JavaScript
356
+ wp_register_script( "{$this->namespace}-admin", WPBACKITUP_URLPATH . "/js/admin.js", array( 'jquery' ), $this->version, true );
357
+ wp_register_script( "{$this->namespace}-ajaxfileupload", WPBACKITUP_URLPATH . "/js/ajaxfileupload.js", array( 'jquery' ), $this->version, true );
358
+ }
359
+
360
+ /**
361
+ * Register styles used by this plugin for enqueuing elsewhere
362
+ *
363
+ * @uses wp_register_style()
364
+ */
365
+ function wp_register_styles() {
366
+ // Admin Stylesheet
367
+ wp_register_style( "{$this->namespace}-admin", WPBACKITUP_URLPATH . "/css/admin.css", array(), $this->version, 'screen' );
368
+ }
369
+ }
370
+ if( !isset( $WPBackitup ) ) {
371
+ WPBackitup::instance();
372
+ }
373
+
374
+ register_activation_hook( __FILE__, array( 'WPBackitup', 'activate' ) );
375
+ register_deactivation_hook( __FILE__, array( 'WPBackitup', 'deactivate' ) );
lib/constants.php CHANGED
@@ -5,11 +5,11 @@
5
  * @package WP Backitup
6
  *
7
  * @author jcpeden
8
- * @version 1.5.0
9
  * @since 1.0.1
10
  */
11
 
12
- if( !defined( 'WPBACKITUP_VERSION' ) ) define( 'WPBACKITUP_VERSION', '1.5.0' );
13
 
14
  if( !defined( 'WPBACKITUP_DIRNAME' ) ) define( 'WPBACKITUP_DIRNAME', dirname( dirname( __FILE__ ) ) );
15
 
5
  * @package WP Backitup
6
  *
7
  * @author jcpeden
8
+ * @version 1.5.1
9
  * @since 1.0.1
10
  */
11
 
12
+ if( !defined( 'WPBACKITUP_VERSION' ) ) define( 'WPBACKITUP_VERSION', '1.5.1' );
13
 
14
  if( !defined( 'WPBACKITUP_DIRNAME' ) ) define( 'WPBACKITUP_DIRNAME', dirname( dirname( __FILE__ ) ) );
15
 
lib/functions.php CHANGED
@@ -1,394 +1,389 @@
1
- <?php
2
- /**
3
- * WP Backitup Functions
4
- *
5
- * @package WP Backitup
6
- *
7
- * @author jcpeden
8
- * @version 1.4.2
9
- * @since 1.0.2
10
- */
11
-
12
- // localize the plugin
13
- function lang_setup() {
14
- global $WPBackitup;
15
- load_plugin_textdomain($WPBackitup->namespace, false, dirname(plugin_basename(__FILE__)) . '/lang/');
16
- }
17
- add_action('after_setup_theme', 'lang_setup');
18
-
19
- // include recurseZip class
20
- if( !class_exists( 'recurseZip' ) ) {
21
- include_once 'includes/recurse_zip.php';
22
- }
23
-
24
- // retrieve our license key from the DB
25
- $license_key = trim( $this->get_option( 'license_key' ) );
26
-
27
- //define dbSize function
28
- function dbSize($dbname) {
29
- mysqli_select_db($dbname);
30
- $result = mysqli_query("SHOW TABLE STATUS");
31
- $dbsize = 0;
32
- while($row = mysqli_fetch_array($result)) {
33
- $dbsize += $row["Data_length"] + $row["Index_length"];
34
- }
35
- return $dbsize;
36
- }
37
-
38
- //define formatFileSize function
39
- function formatFileSize($bytes)
40
- {
41
- if ($bytes >= 1073741824)
42
- {
43
- $bytes = number_format($bytes / 1073741824, 2) . ' GB';
44
- }
45
- elseif ($bytes >= 1048576)
46
- {
47
- $bytes = number_format($bytes / 1048576, 2) . ' MB';
48
- }
49
- elseif ($bytes >= 1024)
50
- {
51
- $bytes = number_format($bytes / 1024, 2) . ' KB';
52
- }
53
- elseif ($bytes > 1)
54
- {
55
- $bytes = $bytes . ' bytes';
56
- }
57
- elseif ($bytes == 1)
58
- {
59
- $bytes = $bytes . ' byte';
60
- }
61
- else
62
- {
63
- $bytes = '0 bytes';
64
- }
65
-
66
- return $bytes;
67
- }
68
-
69
- //define dirSize function
70
- function dirSize($directory) {
71
- $size = 0;
72
- foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
73
- $size+=$file->getSize();
74
- }
75
- return $size;
76
- }
77
-
78
- //load backup function
79
- function backup() {
80
- include_once 'includes/backup.php';
81
- }
82
- add_action('wp_ajax_backup', 'backup');
83
-
84
- //load restore_path function
85
- function restore_path() {
86
- include_once 'includes/restore_from_path.php';
87
- }
88
- add_action('wp_ajax_restore_path', 'restore_path');
89
-
90
- //load download function
91
- function download() {
92
- if(glob(WPBACKITUP_DIRNAME . "/backups/*.zip")) {
93
- foreach (glob(WPBACKITUP_DIRNAME . "/backups/*.zip") as $file) {
94
- $filename = basename($file);
95
- echo 'Download most recent export file: <a href="' .WPBACKITUP_URLPATH. '/backups/' .$filename .'">' .$filename .'</a>';
96
- }
97
- } else {
98
- echo 'No export file available for download. Please create one.';
99
- }
100
- die();
101
- }
102
- add_action('wp_ajax_download', 'download');
103
-
104
- //load logreader function
105
- function logreader() {
106
- $log = WPBACKITUP_DIRNAME .'/logs/status.log';
107
- if(file_exists($log) ) {
108
- readfile($log);
109
- }
110
- die();
111
- }
112
- add_action('wp_ajax_logreader', 'logreader');
113
-
114
- //define create_dir function
115
- if(!function_exists('create_dir')) {
116
- function create_dir($dir) {
117
- if( !is_dir($dir) ) {
118
- @mkdir($dir, 0755);
119
- }
120
- return true;
121
- }
122
- }
123
-
124
- //Define recusive_copy function
125
- if(!function_exists('recursive_copy')) {
126
- function recursive_copy($dir, $target_path, $ignore = array( 'cgi-bin','..','._' ) ) {
127
- if( is_dir($dir) ) { //If the directory exists
128
- if ($dh = opendir($dir) ) {
129
- while(($file = readdir($dh)) !== false) { //While there are files in the directory
130
- if ( !in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
131
- if (!is_dir( $dir.$file ) ) {
132
- //Copy files to destination directory
133
- $fsrc = fopen($dir .$file,'r');
134
- $fdest = fopen($target_path .$file,'w+');
135
- $len = stream_copy_to_stream($fsrc,$fdest);
136
- fclose($fsrc);
137
- fclose($fdest);
138
- } else { //If $file is a directory
139
- $destdir = $target_path .$file; //Modify the destination dir
140
- if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
141
- @mkdir($destdir, 0755);
142
- }
143
- recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
144
- }
145
- }
146
- }
147
- closedir($dh);
148
- }
149
- }
150
- return true;
151
- }
152
- }
153
-
154
- //Define DB backup function
155
- if(!function_exists('db_backup')) {
156
- function db_backup($user, $pass, $host, $db_name, $path) {
157
-
158
- //set fileName
159
- $fileName = 'db-backup.sql' ;
160
-
161
- // Check if directory is already created and has the proper permissions
162
- if (!file_exists($path)) {
163
- if(!mkdir($path , 0755) ){
164
- return false;
165
- }
166
- }
167
-
168
- if (!is_writable($path)) {
169
- if (!chmod($path , 0755) ) {
170
- return false;
171
- }
172
- }
173
-
174
- $mysqli = new mysqli($host , $user , $pass , $db_name) ;
175
- if (mysqli_connect_errno()) {
176
- return false;
177
- }
178
-
179
- // Introduction information
180
- $return = '';
181
- $return .= "--\n";
182
- $return .= "-- WP Backitup Database Backup \n";
183
- $return .= "--\n";
184
- $return .= '-- Created: ' . date("Y/m/d") . ' on ' . date("h:i") . "\n\n\n";
185
- $return = "--\n";
186
- $return .= "-- Database : " . $db_name . "\n";
187
- $return .= "--\n";
188
- $return .= "-- --------------------------------------------------\n";
189
- $return .= "-- ---------------------------------------------------\n";
190
- $return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ;
191
- $return .= 'SET FOREIGN_KEY_CHECKS=0 ;' ."\n" ;
192
- $tables = array() ;
193
-
194
- // Exploring what tables this database has
195
- $result = $mysqli->query('SHOW TABLES' ) ;
196
-
197
- // Cycle through "$result" and put content into an array
198
- while ($row = $result->fetch_row()) {
199
- $tables[] = $row[0] ;
200
- }
201
-
202
- // Cycle through each table
203
- foreach($tables as $table) {
204
- // Get content of each table
205
- $result = $mysqli->query('SELECT * FROM '. $table) ;
206
-
207
- // Get number of fields (columns) of each table
208
- $num_fields = $mysqli->field_count ;
209
-
210
- // Add table information
211
- $return .= "--\n" ;
212
- $return .= '-- Tabel structure for table `' . $table . '`' . "\n" ;
213
- $return .= "--\n" ;
214
- $return.= 'DROP TABLE IF EXISTS `'.$table.'`;' . "\n" ;
215
-
216
- // Get the table-shema
217
- $shema = $mysqli->query('SHOW CREATE TABLE '.$table) ;
218
-
219
- // Extract table shema
220
- $tableshema = $shema->fetch_row() ;
221
-
222
- // Append table-shema into code
223
- $return.= $tableshema[1].";" . "\n\n" ;
224
-
225
- // Cycle through each table-row
226
- while($rowdata = $result->fetch_row()) {
227
-
228
- // Prepare code that will insert data into table
229
- /* $return .= 'INSERT INTO `'.$table .'` VALUES ( ' ;
230
- // Extract data of each row
231
- for($i=0; $i<$num_fields; $i++) {
232
- $return .= '"'.$rowdata[$i] . "\"," ;
233
- }
234
- // Let's remove the last comma
235
- $return = substr("$return", 0, -1) ;
236
- $return .= ");" ."\n" ;*/
237
- $return.= 'INSERT INTO '.$table.' VALUES(';
238
- for($j=0; $j<$num_fields; $j++){
239
- $rowdata[$j] = addslashes($rowdata[$j]);
240
- $rowdata[$j] = ereg_replace("\n","\\n",$rowdata[$j]);
241
- if (isset($rowdata[$j])) {
242
- $return.= '"'.$rowdata[$j].'"' ;
243
- } else {
244
- $return.= '""';
245
- }
246
- if ($j<($num_fields-1)) { $return.= ','; }
247
- }
248
- $return.= ");\n";
249
- }
250
- $return .= "\n\n" ;
251
- }
252
-
253
- // Close the connection
254
- $mysqli->close() ;
255
- $return .= 'SET FOREIGN_KEY_CHECKS = 1 ; ' . "\n" ;
256
- $return .= 'COMMIT ; ' . "\n" ;
257
- $return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ;
258
-
259
- //save file
260
- $handle = fopen($path . $fileName,'w+');
261
- fwrite($handle,$return);
262
- fclose($handle);
263
- return true;
264
- }
265
- }
266
-
267
- //Define the create_siteinfo function
268
- if(!function_exists('create_siteinfo')) {
269
- function create_siteinfo($path, $table_prefix) {
270
- $siteinfo = $path ."backupsiteinfo.txt";
271
- $handle = fopen($siteinfo, 'w+');
272
- $entry = site_url( '/' ) ."\n$table_prefix";
273
- fwrite($handle, $entry);
274
- fclose($handle);
275
- return true;
276
- }
277
- }
278
-
279
- //Define recursive_delete function
280
- if(!function_exists('recursive_delete')){
281
- function recursive_delete($dir, $ignore = array('cgi-bin','.','..','._') ){
282
- if( is_dir($dir) ){
283
- if($dh = opendir($dir)) {
284
- while( ($file = readdir($dh)) !== false ) {
285
- if (!in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
286
- if(!is_dir($dir .'/'. $file)) {
287
- unlink($dir .'/'. $file);
288
- } else {
289
- recursive_delete($dir.'/'. $file, $ignore);
290
- }
291
- }
292
- }
293
- }
294
- @rmdir($dir);
295
- closedir($dh);
296
- }
297
- return true;
298
- }
299
- }
300
-
301
- //Define zip function
302
- function zip($source, $destination, $ignore) {
303
- if (is_string($source)) $source_arr = array($source); // convert it to array
304
- if (!extension_loaded('zip')) {
305
- return false;
306
- }
307
- $zip = new ZipArchive();
308
- if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
309
- return false;
310
- }
311
- foreach ($source_arr as $source) {
312
- if (!file_exists($source)) continue;
313
- $source = str_replace('\\', '/', realpath($source));
314
- if (is_dir($source) === true) {
315
- $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
316
- foreach ($files as $file) {
317
- if (!preg_match($ignore, $file)) {
318
- $file = str_replace('\\', '/', realpath($file));
319
- if (is_dir($file) === true) {
320
- $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
321
- } else if (is_file($file) === true) {
322
- $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
323
- }
324
- }
325
- }
326
- } else if (is_file($source) === true) {
327
- $zip->addFromString(basename($source), file_get_contents($source));
328
- }
329
- }
330
- return $zip->close();
331
- }
332
-
333
- //load presstrends
334
- function load_presstrends() {
335
- global $WPBackitup;
336
- if($WPBackitup->get_option( 'presstrends' ) == 'enabled') {
337
- // PressTrends Account API Key
338
- $api_key = 'rwiyhqfp7eioeh62h6t3ulvcghn2q8cr7j5x';
339
- $auth = 'lpa0nvlhyzbyikkwizk4navhtoaqujrbw';
340
-
341
- // Start of Metrics
342
- global $wpdb;
343
- $data = get_transient( 'presstrends_cache_data' );
344
- if ( !$data || $data == '' ) {
345
- $api_base = 'http://api.presstrends.io/index.php/api/pluginsites/update/auth/';
346
- $url = $api_base . $auth . '/api/' . $api_key . '/';
347
-
348
- $count_posts = wp_count_posts();
349
- $count_pages = wp_count_posts( 'page' );
350
- $comments_count = wp_count_comments();
351
-
352
- // wp_get_theme was introduced in 3.4, for compatibility with older versions, let's do a workaround for now.
353
- if ( function_exists( 'wp_get_theme' ) ) {
354
- $theme_data = wp_get_theme();
355
- $theme_name = urlencode( $theme_data->Name );
356
- } else {
357
- $theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
358
- $theme_name = $theme_data['Name'];
359
- }
360
-
361
- $plugin_name = '&';
362
- foreach ( get_plugins() as $plugin_info ) {
363
- $plugin_name .= $plugin_info['Name'] . '&';
364
- }
365
- // CHANGE __FILE__ PATH IF LOCATED OUTSIDE MAIN PLUGIN FILE
366
- $plugin_data = get_plugin_data( __FILE__ );
367
- $posts_with_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND comment_count > 0" );
368
- $data = array(
369
- 'url' => stripslashes( str_replace( array( 'http://', '/', ':' ), '', site_url() ) ),
370
- 'posts' => $count_posts->publish,
371
- 'pages' => $count_pages->publish,
372
- 'comments' => $comments_count->total_comments,
373
- 'approved' => $comments_count->approved,
374
- 'spam' => $comments_count->spam,
375
- 'pingbacks' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
376
- 'post_conversion' => ( $count_posts->publish > 0 && $posts_with_comments > 0 ) ? number_format( ( $posts_with_comments / $count_posts->publish ) * 100, 0, '.', '' ) : 0,
377
- 'theme_version' => $plugin_data['Version'],
378
- 'theme_name' => $theme_name,
379
- 'site_name' => str_replace( ' ', '', get_bloginfo( 'name' ) ),
380
- 'plugins' => count( get_option( 'active_plugins' ) ),
381
- 'plugin' => urlencode( $plugin_name ),
382
- 'wpversion' => get_bloginfo( 'version' ),
383
- );
384
-
385
- foreach ( $data as $k => $v ) {
386
- $url .= $k . '/' . $v . '/';
387
- }
388
- wp_remote_get( $url );
389
- set_transient( 'presstrends_cache_data', $data, 60 * 60 * 24 );
390
- }
391
- }
392
- }
393
- // PressTrends WordPress Action
394
- add_action('admin_init', 'load_presstrends');
1
+ <?php
2
+ /**
3
+ * WP Backitup Functions
4
+ *
5
+ * @package WP Backitup
6
+ *
7
+ * @author jcpeden
8
+ * @version 1.4.2
9
+ * @since 1.0.2
10
+ */
11
+
12
+ // localize the plugin
13
+ function lang_setup() {
14
+ global $WPBackitup;
15
+ load_plugin_textdomain($WPBackitup->namespace, false, dirname(plugin_basename(__FILE__)) . '/lang/');
16
+ }
17
+ add_action('after_setup_theme', 'lang_setup');
18
+
19
+ // include recurseZip class
20
+ if( !class_exists( 'recurseZip' ) ) {
21
+ include_once 'includes/recurse_zip.php';
22
+ }
23
+
24
+ // retrieve our license key from the DB
25
+ $license_key = trim( $this->get_option( 'license_key' ) );
26
+
27
+ //define dbSize function
28
+ function dbSize($dbname) {
29
+ mysqli_select_db($dbname);
30
+ $result = mysqli_query("SHOW TABLE STATUS");
31
+ $dbsize = 0;
32
+ while($row = mysqli_fetch_array($result)) {
33
+ $dbsize += $row["Data_length"] + $row["Index_length"];
34
+ }
35
+ return $dbsize;
36
+ }
37
+
38
+ //define formatFileSize function
39
+ function formatFileSize($bytes)
40
+ {
41
+ if ($bytes >= 1073741824)
42
+ {
43
+ $bytes = number_format($bytes / 1073741824, 2) . ' GB';
44
+ }
45
+ elseif ($bytes >= 1048576)
46
+ {
47
+ $bytes = number_format($bytes / 1048576, 2) . ' MB';
48
+ }
49
+ elseif ($bytes >= 1024)
50
+ {
51
+ $bytes = number_format($bytes / 1024, 2) . ' KB';
52
+ }
53
+ elseif ($bytes > 1)
54
+ {
55
+ $bytes = $bytes . ' bytes';
56
+ }
57
+ elseif ($bytes == 1)
58
+ {
59
+ $bytes = $bytes . ' byte';
60
+ }
61
+ else
62
+ {
63
+ $bytes = '0 bytes';
64
+ }
65
+
66
+ return $bytes;
67
+ }
68
+
69
+ //define dirSize function
70
+ function dirSize($directory) {
71
+ $size = 0;
72
+ foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $file){
73
+ $size+=$file->getSize();
74
+ }
75
+ return $size;
76
+ }
77
+
78
+ //load backup function
79
+ function backup() {
80
+ include_once 'includes/backup.php';
81
+ }
82
+ add_action('wp_ajax_backup', 'backup');
83
+
84
+ //load restore_path function
85
+ function restore_path() {
86
+ include_once 'includes/restore_from_path.php';
87
+ }
88
+ add_action('wp_ajax_restore_path', 'restore_path');
89
+
90
+ //load download function
91
+ function download() {
92
+ if(glob(WPBACKITUP_DIRNAME . "/backups/*.zip")) {
93
+ foreach (glob(WPBACKITUP_DIRNAME . "/backups/*.zip") as $file) {
94
+ $filename = basename($file);
95
+ echo 'Download most recent export file: <a href="' .WPBACKITUP_URLPATH. '/backups/' .$filename .'">' .$filename .'</a>';
96
+ }
97
+ } else {
98
+ echo 'No export file available for download. Please create one.';
99
+ }
100
+ die();
101
+ }
102
+ add_action('wp_ajax_download', 'download');
103
+
104
+ //load logreader function
105
+ function logreader() {
106
+ $log = WPBACKITUP_DIRNAME .'/logs/status.log';
107
+ if(file_exists($log) ) {
108
+ readfile($log);
109
+ }
110
+ die();
111
+ }
112
+ add_action('wp_ajax_logreader', 'logreader');
113
+
114
+ //define create_dir function
115
+ if(!function_exists('create_dir')) {
116
+ function create_dir($dir) {
117
+ if( !is_dir($dir) ) {
118
+ @mkdir($dir, 0755);
119
+ }
120
+ return true;
121
+ }
122
+ }
123
+
124
+ //Define recusive_copy function
125
+ if(!function_exists('recursive_copy')) {
126
+ function recursive_copy($dir, $target_path, $ignore = array( 'cgi-bin','..','._' ) ) {
127
+ if( is_dir($dir) ) { //If the directory exists
128
+ if ($dh = opendir($dir) ) {
129
+ while(($file = readdir($dh)) !== false) { //While there are files in the directory
130
+ if ( !in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
131
+ if (!is_dir( $dir.$file ) ) {
132
+ //Copy files to destination directory
133
+ $fsrc = fopen($dir .$file,'r');
134
+ $fdest = fopen($target_path .$file,'w+');
135
+ $len = stream_copy_to_stream($fsrc,$fdest);
136
+ fclose($fsrc);
137
+ fclose($fdest);
138
+ } else { //If $file is a directory
139
+ $destdir = $target_path .$file; //Modify the destination dir
140
+ if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
141
+ @mkdir($destdir, 0755);
142
+ }
143
+ recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
144
+ }
145
+ }
146
+ }
147
+ closedir($dh);
148
+ }
149
+ }
150
+ return true;
151
+ }
152
+ }
153
+
154
+ //Define DB backup function
155
+ if(!function_exists('db_backup')) {
156
+ function db_backup($user, $pass, $host, $db_name, $path) {
157
+
158
+ //set fileName
159
+ $fileName = 'db-backup.sql' ;
160
+
161
+ // Check if directory is already created and has the proper permissions
162
+ if (!file_exists($path)) {
163
+ if(!mkdir($path , 0755) ){
164
+ return false;
165
+ }
166
+ }
167
+
168
+ if (!is_writable($path)) {
169
+ if (!chmod($path , 0755) ) {
170
+ return false;
171
+ }
172
+ }
173
+
174
+ $mysqli = new mysqli($host , $user , $pass , $db_name) ;
175
+ if (mysqli_connect_errno()) {
176
+ return false;
177
+ }
178
+
179
+ // Introduction information
180
+ $return = '';
181
+ $return .= "--\n";
182
+ $return .= "-- WP Backitup Database Backup \n";
183
+ $return .= "--\n";
184
+ $return .= '-- Created: ' . date("Y/m/d") . ' on ' . date("h:i") . "\n\n\n";
185
+ $return = "--\n";
186
+ $return .= "-- Database : " . $db_name . "\n";
187
+ $return .= "--\n";
188
+ $return .= "-- --------------------------------------------------\n";
189
+ $return .= "-- ---------------------------------------------------\n";
190
+ $return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ;
191
+ $return .= 'SET FOREIGN_KEY_CHECKS=0 ;' ."\n" ;
192
+ $tables = array() ;
193
+
194
+ // Exploring what tables this database has
195
+ $result = $mysqli->query('SHOW TABLES' ) ;
196
+
197
+ // Cycle through "$result" and put content into an array
198
+ while ($row = $result->fetch_row()) {
199
+ $tables[] = $row[0] ;
200
+ }
201
+
202
+ // Cycle through each table
203
+ foreach($tables as $table) {
204
+ // Get content of each table
205
+ $result = $mysqli->query('SELECT * FROM '. $table) ;
206
+
207
+ // Get number of fields (columns) of each table
208
+ $num_fields = $mysqli->field_count ;
209
+
210
+ // Add table information
211
+ $return .= "--\n" ;
212
+ $return .= '-- Tabel structure for table `' . $table . '`' . "\n" ;
213
+ $return .= "--\n" ;
214
+ $return.= 'DROP TABLE IF EXISTS `'.$table.'`;' . "\n" ;
215
+
216
+ // Get the table-shema
217
+ $shema = $mysqli->query('SHOW CREATE TABLE '.$table) ;
218
+
219
+ // Extract table shema
220
+ $tableshema = $shema->fetch_row() ;
221
+
222
+ // Append table-shema into code
223
+ $return.= $tableshema[1].";" . "\n\n" ;
224
+
225
+ // Cycle through each table-row
226
+ while($rowdata = $result->fetch_row()) {
227
+
228
+ // Prepare code that will insert data into table
229
+ /*Script to take the backup of complete wordpress database tables with there strucutre and data
230
+ * @author - rajeev sharma @ matrix
231
+ */
232
+ $return.= 'INSERT INTO '.$table.' VALUES(';
233
+ for($j=0; $j<$num_fields; $j++){
234
+ $rowdata[$j] = addslashes($rowdata[$j]);
235
+ $rowdata[$j] = ereg_replace("\n","\\n",$rowdata[$j]);
236
+ if (isset($rowdata[$j])) {
237
+ $return.= '"'.$rowdata[$j].'"' ;
238
+ } else {
239
+ $return.= '""';
240
+ }
241
+ if ($j<($num_fields-1)) { $return.= ','; }
242
+ }
243
+ $return.= ");\n";
244
+ }
245
+ $return .= "\n\n" ;
246
+ }
247
+
248
+ // Close the connection
249
+ $mysqli->close() ;
250
+ $return .= 'SET FOREIGN_KEY_CHECKS = 1 ; ' . "\n" ;
251
+ $return .= 'COMMIT ; ' . "\n" ;
252
+ $return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ;
253
+
254
+ //save file
255
+ $handle = fopen($path . $fileName,'w+');
256
+ fwrite($handle,$return);
257
+ fclose($handle);
258
+ return true;
259
+ }
260
+ }
261
+
262
+ //Define the create_siteinfo function
263
+ if(!function_exists('create_siteinfo')) {
264
+ function create_siteinfo($path, $table_prefix) {
265
+ $siteinfo = $path ."backupsiteinfo.txt";
266
+ $handle = fopen($siteinfo, 'w+');
267
+ $entry = site_url( '/' ) ."\n$table_prefix";
268
+ fwrite($handle, $entry);
269
+ fclose($handle);
270
+ return true;
271
+ }
272
+ }
273
+
274
+ //Define recursive_delete function
275
+ if(!function_exists('recursive_delete')){
276
+ function recursive_delete($dir, $ignore = array('cgi-bin','.','..','._') ){
277
+ if( is_dir($dir) ){
278
+ if($dh = opendir($dir)) {
279
+ while( ($file = readdir($dh)) !== false ) {
280
+ if (!in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
281
+ if(!is_dir($dir .'/'. $file)) {
282
+ unlink($dir .'/'. $file);
283
+ } else {
284
+ recursive_delete($dir.'/'. $file, $ignore);
285
+ }
286
+ }
287
+ }
288
+ }
289
+ @rmdir($dir);
290
+ closedir($dh);
291
+ }
292
+ return true;
293
+ }
294
+ }
295
+
296
+ //Define zip function
297
+ function zip($source, $destination, $ignore) {
298
+ if (is_string($source)) $source_arr = array($source); // convert it to array
299
+ if (!extension_loaded('zip')) {
300
+ return false;
301
+ }
302
+ $zip = new ZipArchive();
303
+ if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
304
+ return false;
305
+ }
306
+ foreach ($source_arr as $source) {
307
+ if (!file_exists($source)) continue;
308
+ $source = str_replace('\\', '/', realpath($source));
309
+ if (is_dir($source) === true) {
310
+ $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);
311
+ foreach ($files as $file) {
312
+ if (!preg_match($ignore, $file)) {
313
+ $file = str_replace('\\', '/', realpath($file));
314
+ if (is_dir($file) === true) {
315
+ $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
316
+ } else if (is_file($file) === true) {
317
+ $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
318
+ }
319
+ }
320
+ }
321
+ } else if (is_file($source) === true) {
322
+ $zip->addFromString(basename($source), file_get_contents($source));
323
+ }
324
+ }
325
+ return $zip->close();
326
+ }
327
+
328
+ //load presstrends
329
+ function load_presstrends() {
330
+ global $WPBackitup;
331
+ if($WPBackitup->get_option( 'presstrends' ) == 'enabled') {
332
+ // PressTrends Account API Key
333
+ $api_key = 'rwiyhqfp7eioeh62h6t3ulvcghn2q8cr7j5x';
334
+ $auth = 'lpa0nvlhyzbyikkwizk4navhtoaqujrbw';
335
+
336
+ // Start of Metrics
337
+ global $wpdb;
338
+ $data = get_transient( 'presstrends_cache_data' );
339
+ if ( !$data || $data == '' ) {
340
+ $api_base = 'http://api.presstrends.io/index.php/api/pluginsites/update/auth/';
341
+ $url = $api_base . $auth . '/api/' . $api_key . '/';
342
+
343
+ $count_posts = wp_count_posts();
344
+ $count_pages = wp_count_posts( 'page' );
345
+ $comments_count = wp_count_comments();
346
+
347
+ // wp_get_theme was introduced in 3.4, for compatibility with older versions, let's do a workaround for now.
348
+ if ( function_exists( 'wp_get_theme' ) ) {
349
+ $theme_data = wp_get_theme();
350
+ $theme_name = urlencode( $theme_data->Name );
351
+ } else {
352
+ $theme_data = get_theme_data( get_stylesheet_directory() . '/style.css' );
353
+ $theme_name = $theme_data['Name'];
354
+ }
355
+
356
+ $plugin_name = '&';
357
+ foreach ( get_plugins() as $plugin_info ) {
358
+ $plugin_name .= $plugin_info['Name'] . '&';
359
+ }
360
+ // CHANGE __FILE__ PATH IF LOCATED OUTSIDE MAIN PLUGIN FILE
361
+ $plugin_data = get_plugin_data( __FILE__ );
362
+ $posts_with_comments = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE post_type='post' AND comment_count > 0" );
363
+ $data = array(
364
+ 'url' => stripslashes( str_replace( array( 'http://', '/', ':' ), '', site_url() ) ),
365
+ 'posts' => $count_posts->publish,
366
+ 'pages' => $count_pages->publish,
367
+ 'comments' => $comments_count->total_comments,
368
+ 'approved' => $comments_count->approved,
369
+ 'spam' => $comments_count->spam,
370
+ 'pingbacks' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
371
+ 'post_conversion' => ( $count_posts->publish > 0 && $posts_with_comments > 0 ) ? number_format( ( $posts_with_comments / $count_posts->publish ) * 100, 0, '.', '' ) : 0,
372
+ 'theme_version' => $plugin_data['Version'],
373
+ 'theme_name' => $theme_name,
374
+ 'site_name' => str_replace( ' ', '', get_bloginfo( 'name' ) ),
375
+ 'plugins' => count( get_option( 'active_plugins' ) ),
376
+ 'plugin' => urlencode( $plugin_name ),
377
+ 'wpversion' => get_bloginfo( 'version' ),
378
+ );
379
+
380
+ foreach ( $data as $k => $v ) {
381
+ $url .= $k . '/' . $v . '/';
382
+ }
383
+ wp_remote_get( $url );
384
+ set_transient( 'presstrends_cache_data', $data, 60 * 60 * 24 );
385
+ }
386
+ }
387
+ }
388
+ // PressTrends WordPress Action
389
+ add_action('admin_init', 'load_presstrends');
 
 
 
 
 
lib/includes/backup.php CHANGED
@@ -1,104 +1,104 @@
1
- <?php
2
-
3
- /**
4
- * WP Backitup Backup Functions
5
- *
6
- * @package WP Backitup Pro
7
- *
8
- * @author jcpeden
9
- * @version 1.4.2
10
- * @since 1.0.1
11
- */
12
-
13
- global $WPBackitup;
14
-
15
- //limit process to 15 minutes
16
- @set_time_limit(900);
17
-
18
- //Define variables
19
- $backup_project_dirname = get_bloginfo('name') .'-Export-' .date('Y-m-d-Hi');
20
- $backup_project_path = WPBACKITUP_DIRNAME ."/backups/". $backup_project_dirname .'/';
21
-
22
- //create log file
23
- $log = WPBACKITUP_DIRNAME ."/logs/status.log";
24
- unlink($log);
25
- $fh = fopen($log, 'w') or die("Can't open log file");
26
-
27
- //Delete the existing backup directory
28
- recursive_delete( WPBACKITUP_DIR_PATH .'/backups/' );
29
-
30
- //Re-create and empty backup dir
31
- if(!create_dir( WPBACKITUP_DIR_PATH .'/backups/' )) {
32
- fwrite($fh, '<div class="prerequsites">0</div>');
33
- fwrite($fh, '<div class="error101">1</div>');
34
- fclose($fh);
35
- die();
36
- }
37
-
38
- //Check to see if the directory is writeable
39
- if(!is_writeable(WPBACKITUP_DIRNAME ."/backups/")) {
40
- fwrite($fh, '<div class="prerequsites">0</div>');
41
- fwrite($fh, '<div class="error102">1</div>');
42
- die();
43
- } else {
44
- //If the directory is writeable, create the backup folder if it doesn't exist
45
- if( !is_dir($backup_project_path) ) {
46
- @mkdir($backup_project_path, 0755);
47
- }
48
- foreach(glob(WPBACKITUP_DIRNAME ."/backups/*.zip") as $zip) {
49
- unlink($zip);
50
- }
51
- fwrite($fh, '<div class="prerequisites">1</div>');
52
- }
53
-
54
- //Dump DB to project dir
55
- if( db_backup(DB_USER, DB_PASSWORD, DB_HOST, DB_NAME, $backup_project_path) ) {
56
- fwrite($fh, '<div class="backupdb">1</div>');
57
- } else {
58
- fwrite($fh, '<div class="backupdb">0</div>');
59
- fwrite($fh, '<div class="error104">1</div>');
60
- recursive_delete($backup_project_path);
61
- die();
62
- }
63
-
64
- //Backup with copy
65
- if(recursive_copy(WPBACKITUP_CONTENT_PATH, $backup_project_path, $ignore = array( 'cgi-bin','.','..','._',$backup_project_dirname,'backupbuddy_backups','*.zip','cache' ) ) ) {
66
- fwrite($fh, '<div class="backupfiles">1</div>');
67
- } else {
68
- fwrite($fh, '<div class="backupfiles">0</div>');
69
- fwrite($fh, '<div class="error103">1</div>');
70
- die();
71
- }
72
-
73
- //Create siteinfo in project dir
74
- global $wpdb;
75
-
76
- if (!create_siteinfo($backup_project_path, $wpdb->prefix) ) {
77
- fwrite($fh, '<div class="infofile">0</div>');
78
- fwrite($fh, '<div class="error105">1</div>');
79
- recursive_delete($backup_project_path);
80
- die();
81
- } else {
82
- fwrite($fh, '<div class="infofile">1</div>');
83
- }
84
-
85
- //Zip the project dir
86
- $z = new recurseZip();
87
- $src = rtrim($backup_project_path, '/');
88
- $z->compress($src, WPBACKITUP_DIRNAME ."/backups/");
89
- fwrite($fh, '<div class="zipfile">1</div>');
90
-
91
- //Delete backup dir
92
- if(!recursive_delete($backup_project_path)) {
93
- fwrite($fh, '<div class="cleanup">0</div>');
94
- fwrite($fh, '<div class="error106">1</div>');
95
- } else {
96
- fwrite($fh, '<div class="cleanup">1</div>');
97
- }
98
-
99
- //close log file
100
- fwrite($fh, '<div class="finalinfo">1</div>');
101
- fclose($fh);
102
-
103
- //End backup function
104
  die();
1
+ <?php
2
+
3
+ /**
4
+ * WP Backitup Backup Functions
5
+ *
6
+ * @package WP Backitup Pro
7
+ *
8
+ * @author jcpeden
9
+ * @version 1.4.2
10
+ * @since 1.0.1
11
+ */
12
+
13
+ global $WPBackitup;
14
+
15
+ //limit process to 15 minutes
16
+ @set_time_limit(900);
17
+
18
+ //Define variables
19
+ $backup_project_dirname = get_bloginfo('name') .'-Export-' .date('Y-m-d-Hi');
20
+ $backup_project_path = WPBACKITUP_DIRNAME ."/backups/". $backup_project_dirname .'/';
21
+
22
+ //create log file
23
+ $log = WPBACKITUP_DIRNAME ."/logs/status.log";
24
+ unlink($log);
25
+ $fh = fopen($log, 'w') or die("Can't open log file");
26
+
27
+ //Delete the existing backup directory
28
+ recursive_delete( WPBACKITUP_DIR_PATH .'/backups/' );
29
+
30
+ //Re-create and empty backup dir
31
+ if(!create_dir( WPBACKITUP_DIR_PATH .'/backups/' )) {
32
+ fwrite($fh, '<div class="prerequsites">0</div>');
33
+ fwrite($fh, '<div class="error101">1</div>');
34
+ fclose($fh);
35
+ die();
36
+ }
37
+
38
+ //Check to see if the directory is writeable
39
+ if(!is_writeable(WPBACKITUP_DIRNAME ."/backups/")) {
40
+ fwrite($fh, '<div class="prerequsites">0</div>');
41
+ fwrite($fh, '<div class="error102">1</div>');
42
+ die();
43
+ } else {
44
+ //If the directory is writeable, create the backup folder if it doesn't exist
45
+ if( !is_dir($backup_project_path) ) {
46
+ @mkdir($backup_project_path, 0755);
47
+ }
48
+ foreach(glob(WPBACKITUP_DIRNAME ."/backups/*.zip") as $zip) {
49
+ unlink($zip);
50
+ }
51
+ fwrite($fh, '<div class="prerequisites">1</div>');
52
+ }
53
+
54
+ //Dump DB to project dir
55
+ if( db_backup(DB_USER, DB_PASSWORD, DB_HOST, DB_NAME, $backup_project_path) ) {
56
+ fwrite($fh, '<div class="backupdb">1</div>');
57
+ } else {
58
+ fwrite($fh, '<div class="backupdb">0</div>');
59
+ fwrite($fh, '<div class="error104">1</div>');
60
+ recursive_delete($backup_project_path);
61
+ die();
62
+ }
63
+
64
+ //Backup with copy
65
+ if(recursive_copy(WPBACKITUP_CONTENT_PATH, $backup_project_path, $ignore = array( 'cgi-bin','.','..','._',$backup_project_dirname,'backupbuddy_backups','*.zip','cache' ) ) ) {
66
+ fwrite($fh, '<div class="backupfiles">1</div>');
67
+ } else {
68
+ fwrite($fh, '<div class="backupfiles">0</div>');
69
+ fwrite($fh, '<div class="error103">1</div>');
70
+ die();
71
+ }
72
+
73
+ //Create siteinfo in project dir
74
+ global $wpdb;
75
+
76
+ if (!create_siteinfo($backup_project_path, $wpdb->prefix) ) {
77
+ fwrite($fh, '<div class="infofile">0</div>');
78
+ fwrite($fh, '<div class="error105">1</div>');
79
+ recursive_delete($backup_project_path);
80
+ die();
81
+ } else {
82
+ fwrite($fh, '<div class="infofile">1</div>');
83
+ }
84
+
85
+ //Zip the project dir
86
+ $z = new recurseZip();
87
+ $src = rtrim($backup_project_path, '/');
88
+ $z->compress($src, WPBACKITUP_DIRNAME ."/backups/");
89
+ fwrite($fh, '<div class="zipfile">1</div>');
90
+
91
+ //Delete backup dir
92
+ if(!recursive_delete($backup_project_path)) {
93
+ fwrite($fh, '<div class="cleanup">0</div>');
94
+ fwrite($fh, '<div class="error106">1</div>');
95
+ } else {
96
+ fwrite($fh, '<div class="cleanup">1</div>');
97
+ }
98
+
99
+ //close log file
100
+ fwrite($fh, '<div class="finalinfo">1</div>');
101
+ fclose($fh);
102
+
103
+ //End backup function
104
  die();
lib/includes/recurse_zip.php CHANGED
@@ -1 +1 @@
1
- <?php
2
  * WP Backitup Recurse Zip Function
3
  *
4
  * @package WP Backitup
5
  *
6
  * @author jcpeden
7
  * @version 1.4.0
8
  * @since 1.0.1
9
  */
 
10
  * WP Backitup Recurse Zip Function
11
  *
12
  * @package WP Backitup
13
  *
14
  * @author jcpeden
15
  * @version 1.4.0
16
  * @since 1.0.1
17
  */
 
1
  * WP Backitup Recurse Zip Function
2
  *
3
  * @package WP Backitup
4
  *
5
  * @author jcpeden
6
  * @version 1.4.0
7
  * @since 1.0.1
8
  */
9
+ <?php
10
  * WP Backitup Recurse Zip Function
11
  *
12
  * @package WP Backitup
13
  *
14
  * @author jcpeden
15
  * @version 1.4.0
16
  * @since 1.0.1
17
  */
lib/includes/restore.php CHANGED
@@ -1,400 +1,400 @@
1
- <?php
2
-
3
- /**
4
- * WP Backitup Restore Functions
5
- *
6
- * @package WP Backitup Pro
7
- *
8
- * @author jcpeden
9
- * @version 1.4.0
10
- * @since 1.0.1
11
- */
12
-
13
- //define constants
14
- if( !defined( 'WP_DIR_PATH' ) ) define( 'WP_DIR_PATH', dirname ( dirname ( dirname ( dirname ( dirname ( dirname ( __FILE__ ) ) ) ) ) ) );
15
-
16
- if( !defined( 'WPBACKITUP_DIR_PATH' ) ) define( 'WPBACKITUP_DIR_PATH', dirname( dirname( dirname( __FILE__ ) ) ) );
17
-
18
- if( !defined( 'WPBACKITUP_DIRNAME' ) ) define( 'WPBACKITUP_DIRNAME', basename(WPBACKITUP_DIR_PATH) );
19
-
20
- if( !defined( 'WP_CONTENT_PATH' ) ) define( 'WP_CONTENT_PATH', dirname( dirname( WPBACKITUP_DIR_PATH ) ) ) ;
21
-
22
- // Include recurse_zip.php
23
- include_once 'recurse_zip.php';
24
-
25
- //define create_dir function
26
- if(!function_exists('create_dir')) {
27
- function create_dir($dir) {
28
- if( !is_dir($dir) ) {
29
- @mkdir($dir, 0755);
30
- }
31
- return true;
32
- }
33
- }
34
-
35
- if(!function_exists('redo_to_checkpoint')) {
36
- function redo_to_checkpoint($checkpoint) {
37
-
38
- if($checkpoint == "db")
39
- {
40
- if( glob($restoration_dir_path . "*.cur") ) {
41
- //collect connection information from form
42
- fwrite($fh, '<div class="database">In Progress</div>');
43
- include_once WP_DIR_PATH .'/wp-config.php';
44
- //Add user to DB in v1.0.5
45
- $user_id = $_POST['user_id'];
46
- //Connect to DB
47
- $output = db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc);
48
- }
49
-
50
- }
51
-
52
- }
53
- }
54
-
55
- if(!function_exists('db_backup')) {
56
- function db_backup($path) {
57
- $handle = fopen($path .'db-backup.cur', 'w+');
58
- $path_sql = $path .'db-backup.cur';
59
- $db_name = DB_NAME;
60
- $db_user = DB_USER;
61
- $db_pass = DB_PASSWORD;
62
- $db_host = DB_HOST;
63
- $output = shell_exec("mysqldump --user $db_user --password=$db_pass $db_name > '$path_sql'");
64
- fwrite($handle,$output);
65
- fclose($handle);
66
- return true;
67
- }
68
- }
69
-
70
- //Define recusive_copy function
71
- if(!function_exists('recursive_copy')) {
72
- function recursive_copy($dir, $target_path, $ignore = array( 'cgi-bin','..','._' ) ) {
73
- if( is_dir($dir) ) { //If the directory exists
74
- if ($dh = opendir($dir) ) {
75
- while(($file = readdir($dh)) !== false) { //While there are files in the directory
76
- if ( !in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
77
- if (!is_dir( $dir.$file ) ) {
78
- //Copy files to destination directory
79
- //echo 'Copying ' .$dir .$file . ' to ' .$target_path .$file .'<br />';
80
- $fsrc = fopen($dir .$file,'r');
81
- $fdest = fopen($target_path .$file,'w+');
82
- $len = stream_copy_to_stream($fsrc,$fdest);
83
- fclose($fsrc);
84
- fclose($fdest);
85
- } else { //If $file is a directory
86
- $destdir = $target_path .$file; //Modify the destination dir
87
- if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
88
- @mkdir($destdir, 0755);
89
- }
90
- recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
91
- }
92
- }
93
- }
94
- closedir($dh);
95
- }
96
- }
97
- return true;
98
- }
99
- }
100
-
101
- //Define recursive_delete function
102
- if(!function_exists('recursive_delete')){
103
- function recursive_delete($dir, $ignore = array('cgi-bin','.','..','._') ){
104
- if( is_dir($dir) ){
105
- if($dh = opendir($dir)) {
106
- while( ($file = readdir($dh)) !== false ) {
107
- if (!in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
108
- if(!is_dir($dir .'/' .$file)) {
109
- //echo 'Deleting ' .$dir .'/' .$file '<br />';
110
- unlink($dir .'/' .$file);
111
- } else {
112
- recursive_delete($dir .'/' .$file, $ignore);
113
- }
114
- }
115
- }
116
- }
117
- @rmdir($dir);
118
- closedir($dh);
119
- }
120
- return true;
121
- }
122
- }
123
-
124
- //define db_import function
125
- if(!function_exists('db_import')) {
126
- function db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc) {
127
- //13-4-13: John C Peden [mail@johncpeden.com] This was incomplete, I've updated to make it work
128
- foreach(glob($restoration_dir_path . "*.sql") as $sql_file) {
129
- $db_name = DB_NAME;
130
- $db_user = DB_USER;
131
- $db_pass = DB_PASSWORD;
132
- $db_host = DB_HOST;
133
- $command = "mysql --user='$db_user' --password='$db_pass' --host='$db_host' $db_name < '$sql_file'";
134
- $output = shell_exec(($command));
135
- }
136
- return true;
137
- }
138
- }
139
-
140
- //create log file
141
- $log = WPBACKITUP_DIR_PATH .'/logs/status.log';
142
- unlink($log);
143
- $fh = fopen($log, 'w') or die( "Can't write to log file" );
144
-
145
- // 15 minutes per image should be PLENTY
146
- @set_time_limit(900);
147
-
148
- //Delete the existing backup directory
149
- recursive_delete( WPBACKITUP_DIR_PATH .'/backups/' );
150
-
151
- //Re-create and empty backup dir
152
- if(!create_dir( WPBACKITUP_DIR_PATH .'/backups/' )) {
153
- fwrite($fh, '<div class="error201">1</div>');
154
- fclose($fh);
155
- die();
156
- }
157
-
158
- //Move the uploaded zip to the restoration directory
159
- $restore_file_name = basename( $_FILES['wpbackitup-zip']['name']);
160
- if( $restore_file_name == '') {
161
- fwrite($fh, '<div class="error201">1</div>');
162
- fclose($fh);
163
- die();
164
- }
165
-
166
- $restore_path = WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name;
167
- if(move_uploaded_file($_FILES['wpbackitup-zip']['tmp_name'], $restore_path)) {
168
- fwrite($fh, '<div class="upload">1</div>');
169
- } else {
170
- fwrite($fh, '<div class="error203">1</div>');
171
- fclose($fh);
172
- die();
173
- }
174
-
175
- //unzip the upload
176
- $zip = new ZipArchive;
177
- $res = $zip->open(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
178
- if ($res === TRUE) {
179
- $zip->extractTo(WPBACKITUP_DIR_PATH .'/backups/');
180
- $zip->close();
181
- fwrite($fh, '<div class="unzipping">1</div>');
182
- } else {
183
- fwrite($fh, '<div class="error204">1</div>');
184
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
185
- fclose($fh);
186
- die();
187
- }
188
-
189
- //Identify the restoration directory
190
- if ( count( glob( WPBACKITUP_DIR_PATH .'/backups/*', GLOB_ONLYDIR ) ) == 1 ) {
191
- foreach( glob(WPBACKITUP_DIR_PATH .'/backups/*', GLOB_ONLYDIR ) as $dir) {
192
- $restoration_dir_path = $dir .'/';
193
- }
194
- }
195
-
196
- //Validate the restoration
197
- if(glob($restoration_dir_path .'backupsiteinfo.txt') ){
198
- fwrite($fh, '<div class="validation">1</div>');
199
- } else {
200
- fwrite($fh, '<div class="error204">1</div>');
201
- recursive_delete($restoration_dir_path);
202
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
203
- fclose($fh);
204
- die();
205
- }
206
-
207
- // Backup the current database
208
- if( db_backup($restoration_dir_path) ) {
209
- fwrite($fh, '<div class="restore_point">1</div>');
210
- } else {
211
- fwrite($fh, '<div class="error205">1</div>');
212
- fclose($fh);
213
- die();
214
- }
215
-
216
- //if there is a database dump to restore
217
- if( glob($restoration_dir_path . "*.sql") ) {
218
-
219
- //Collect connection information from form
220
- include_once WP_DIR_PATH .'/wp-config.php';
221
-
222
- //Add user to DB in v1.0.5
223
- $user_id = $_POST['user_id'];
224
-
225
- //Connect to DB
226
- $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
227
- if ( !$dbc ) {
228
- fwrite($fh, '<div class="error206">1</div>');
229
-
230
- recursive_delete($restoration_dir_path);
231
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
232
- fclose($fh);
233
- die();
234
- }
235
-
236
- //get siteurl
237
- $q1 = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='siteurl';";
238
- if ($result = mysqli_query($dbc, $q1)) {
239
- while ($row = mysqli_fetch_row($result)) {
240
- $siteurl = $row[0];
241
- }
242
- mysqli_free_result($result);
243
- } else {
244
- fwrite($fh, '<div class="error207">1</div>');
245
- recursive_delete($restoration_dir_path);
246
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
247
- fclose($fh);
248
- die();
249
- }
250
-
251
- //get homeurl
252
- $q2 = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='home';";
253
- if ($result = mysqli_query($dbc, $q2)) {
254
- while ($row = mysqli_fetch_row($result)) {
255
- $homeurl = $row[0];
256
- }
257
- mysqli_free_result($result);
258
- } else {
259
- fwrite($fh, '<div class="error208">1</div>');
260
- recursive_delete($restoration_dir_path);
261
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
262
- fclose($fh);
263
- die();
264
- }
265
-
266
- //get user login
267
- $q3 = "SELECT user_login FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
268
- if ($result = mysqli_query($dbc, $q3)) {
269
- while ($row = mysqli_fetch_row($result)) {
270
- $user_login = $row[0];
271
- }
272
- mysqli_free_result($result);
273
- } else {
274
- fwrite($fh, '<div class="error209">1</div>');
275
- recursive_delete($restoration_dir_path);
276
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
277
- fclose($fh);
278
- die();
279
- }
280
-
281
- //get user pass
282
- $q4 = "SELECT user_pass FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
283
- if ($result = mysqli_query($dbc, $q4)) {
284
- while ($row = mysqli_fetch_row($result)) {
285
- $user_pass = $row[0];
286
- }
287
- mysqli_free_result($result);
288
- } else {
289
- fwrite($fh, '<div class="error210">1</div>');
290
- recursive_delete($restoration_dir_path);
291
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
292
- fclose($fh);
293
- die();
294
- }
295
-
296
- //get user email
297
- $q5 = "SELECT user_email FROM ". $table_prefix ."users WHERE ID=" .$user_id ."";
298
- if ($result = mysqli_query($dbc, $q5)) {
299
- while ($row = mysqli_fetch_row($result)) {
300
- $user_email = $row[0];
301
- }
302
- mysqli_free_result($result);
303
- } else {
304
- fwrite($fh, '<div class="error211">1</div>');
305
- recursive_delete($restoration_dir_path);
306
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
307
- fclose($fh);
308
- die();
309
- }
310
-
311
- //Collect previous backup site url start
312
- $import_siteinfo_lines = file($restoration_dir_path .'backupsiteinfo.txt');
313
- $import_siteurl = trim($import_siteinfo_lines[0]);
314
- $current_siteurl = trim($siteurl ,'/');
315
- $import_table_prefix = $import_siteinfo_lines[1];
316
-
317
- //import the database
318
- if(!db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc)) {
319
- fwrite($fh, '<div class="error212">1</div>');
320
- recursive_delete($restoration_dir_path);
321
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
322
- fclose($fh);
323
- die();
324
- }
325
-
326
- //update the database
327
- $q6 = "UPDATE ". $table_prefix ."options SET option_value='" .$current_siteurl ."' WHERE option_name='siteurl'";
328
- $q7 = "UPDATE ". $table_prefix ."options SET option_value='" .$homeurl ."' WHERE option_name='home'";
329
- $q8 = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
330
- if(!mysqli_query($dbc, $q6) ) {
331
- fwrite($fh, '<div class="error213">1</div>');
332
- recursive_delete($restoration_dir_path);
333
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
334
- fclose($fh);
335
- die();
336
- }
337
- if(!mysqli_query($dbc, $q7) ) {
338
- fwrite($fh, '<div class="error214">1</div>');
339
- recursive_delete($restoration_dir_path);
340
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
341
- fclose($fh);
342
- die();
343
- }
344
- if(!mysqli_query($dbc, $q8) ) {
345
- fwrite($fh, '<div class="error215">1</div>');
346
- recursive_delete($restoration_dir_path);
347
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
348
- fclose($fh);
349
- die();
350
- }
351
- fwrite($fh, '<div class="database">1</div>');
352
- } else {
353
- fwrite($fh, '<div class="error216">1</div>');
354
- }
355
-
356
- //Disconnect
357
- mysqli_close($dbc);
358
-
359
- //Restore wp-content directories
360
- if(!recursive_delete(WP_CONTENT_PATH, array( 'cgi-bin','.','..','._', WPBACKITUP_DIRNAME ))) {
361
- fwrite($fh, '<div class="error217">1</div>');
362
- recursive_delete($restoration_dir_path);
363
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
364
- fclose($fh);
365
- die();
366
- }
367
- if(!create_dir(WP_CONTENT_PATH)) {
368
- fwrite($fh, '<div class="error218">1</div>');
369
- recursive_delete($restoration_dir_path);
370
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
371
- fclose($fh);
372
- die();
373
- }
374
- if(recursive_copy($restoration_dir_path, WP_CONTENT_PATH .'/', array( 'cgi-bin', '.', '..','._', $restore_file_name, 'status.log', 'db-backup.sql', 'backupsiteinfo.txt')) ) {
375
- fwrite($fh, '<div class="wpcontent">1</div>');
376
- } else {
377
- fwrite($fh, '<div class="error219">1</div>');
378
- recursive_delete($restoration_dir_path);
379
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
380
- fclose($fh);
381
- die();
382
- }
383
-
384
- //Delete the restoration directory
385
- if(!recursive_delete($restoration_dir_path)) {
386
- fwrite($fh, '<div class="error220">1</div>');
387
- fclose($fh);
388
- } else {
389
- fwrite($fh, '<div class="cleanup">1</div>');
390
- }
391
-
392
- //Delete zip
393
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
394
-
395
- //close log file
396
- fwrite($fh, '<div class="finalinfo">1</div>');
397
- fclose($fh);
398
-
399
- //End backup function
400
  die();
1
+ <?php
2
+
3
+ /**
4
+ * WP Backitup Restore Functions
5
+ *
6
+ * @package WP Backitup Pro
7
+ *
8
+ * @author jcpeden
9
+ * @version 1.4.0
10
+ * @since 1.0.1
11
+ */
12
+
13
+ //define constants
14
+ if( !defined( 'WP_DIR_PATH' ) ) define( 'WP_DIR_PATH', dirname ( dirname ( dirname ( dirname ( dirname ( dirname ( __FILE__ ) ) ) ) ) ) );
15
+
16
+ if( !defined( 'WPBACKITUP_DIR_PATH' ) ) define( 'WPBACKITUP_DIR_PATH', dirname( dirname( dirname( __FILE__ ) ) ) );
17
+
18
+ if( !defined( 'WPBACKITUP_DIRNAME' ) ) define( 'WPBACKITUP_DIRNAME', basename(WPBACKITUP_DIR_PATH) );
19
+
20
+ if( !defined( 'WP_CONTENT_PATH' ) ) define( 'WP_CONTENT_PATH', dirname( dirname( WPBACKITUP_DIR_PATH ) ) ) ;
21
+
22
+ // Include recurse_zip.php
23
+ include_once 'recurse_zip.php';
24
+
25
+ //define create_dir function
26
+ if(!function_exists('create_dir')) {
27
+ function create_dir($dir) {
28
+ if( !is_dir($dir) ) {
29
+ @mkdir($dir, 0755);
30
+ }
31
+ return true;
32
+ }
33
+ }
34
+
35
+ if(!function_exists('redo_to_checkpoint')) {
36
+ function redo_to_checkpoint($checkpoint) {
37
+
38
+ if($checkpoint == "db")
39
+ {
40
+ if( glob($restoration_dir_path . "*.cur") ) {
41
+ //collect connection information from form
42
+ fwrite($fh, '<div class="database">In Progress</div>');
43
+ include_once WP_DIR_PATH .'/wp-config.php';
44
+ //Add user to DB in v1.0.5
45
+ $user_id = $_POST['user_id'];
46
+ //Connect to DB
47
+ $output = db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc);
48
+ }
49
+
50
+ }
51
+
52
+ }
53
+ }
54
+
55
+ if(!function_exists('db_backup')) {
56
+ function db_backup($path) {
57
+ $handle = fopen($path .'db-backup.cur', 'w+');
58
+ $path_sql = $path .'db-backup.cur';
59
+ $db_name = DB_NAME;
60
+ $db_user = DB_USER;
61
+ $db_pass = DB_PASSWORD;
62
+ $db_host = DB_HOST;
63
+ $output = shell_exec("mysqldump --user $db_user --password=$db_pass $db_name > '$path_sql'");
64
+ fwrite($handle,$output);
65
+ fclose($handle);
66
+ return true;
67
+ }
68
+ }
69
+
70
+ //Define recusive_copy function
71
+ if(!function_exists('recursive_copy')) {
72
+ function recursive_copy($dir, $target_path, $ignore = array( 'cgi-bin','..','._' ) ) {
73
+ if( is_dir($dir) ) { //If the directory exists
74
+ if ($dh = opendir($dir) ) {
75
+ while(($file = readdir($dh)) !== false) { //While there are files in the directory
76
+ if ( !in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
77
+ if (!is_dir( $dir.$file ) ) {
78
+ //Copy files to destination directory
79
+ //echo 'Copying ' .$dir .$file . ' to ' .$target_path .$file .'<br />';
80
+ $fsrc = fopen($dir .$file,'r');
81
+ $fdest = fopen($target_path .$file,'w+');
82
+ $len = stream_copy_to_stream($fsrc,$fdest);
83
+ fclose($fsrc);
84
+ fclose($fdest);
85
+ } else { //If $file is a directory
86
+ $destdir = $target_path .$file; //Modify the destination dir
87
+ if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
88
+ @mkdir($destdir, 0755);
89
+ }
90
+ recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
91
+ }
92
+ }
93
+ }
94
+ closedir($dh);
95
+ }
96
+ }
97
+ return true;
98
+ }
99
+ }
100
+
101
+ //Define recursive_delete function
102
+ if(!function_exists('recursive_delete')){
103
+ function recursive_delete($dir, $ignore = array('cgi-bin','.','..','._') ){
104
+ if( is_dir($dir) ){
105
+ if($dh = opendir($dir)) {
106
+ while( ($file = readdir($dh)) !== false ) {
107
+ if (!in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
108
+ if(!is_dir($dir .'/' .$file)) {
109
+ //echo 'Deleting ' .$dir .'/' .$file '<br />';
110
+ unlink($dir .'/' .$file);
111
+ } else {
112
+ recursive_delete($dir .'/' .$file, $ignore);
113
+ }
114
+ }
115
+ }
116
+ }
117
+ @rmdir($dir);
118
+ closedir($dh);
119
+ }
120
+ return true;
121
+ }
122
+ }
123
+
124
+ //define db_import function
125
+ if(!function_exists('db_import')) {
126
+ function db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc) {
127
+ //13-4-13: John C Peden [mail@johncpeden.com] This was incomplete, I've updated to make it work
128
+ foreach(glob($restoration_dir_path . "*.sql") as $sql_file) {
129
+ $db_name = DB_NAME;
130
+ $db_user = DB_USER;
131
+ $db_pass = DB_PASSWORD;
132
+ $db_host = DB_HOST;
133
+ $command = "mysql --user='$db_user' --password='$db_pass' --host='$db_host' $db_name < '$sql_file'";
134
+ $output = shell_exec(($command));
135
+ }
136
+ return true;
137
+ }
138
+ }
139
+
140
+ //create log file
141
+ $log = WPBACKITUP_DIR_PATH .'/logs/status.log';
142
+ unlink($log);
143
+ $fh = fopen($log, 'w') or die( "Can't write to log file" );
144
+
145
+ // 15 minutes per image should be PLENTY
146
+ @set_time_limit(900);
147
+
148
+ //Delete the existing backup directory
149
+ recursive_delete( WPBACKITUP_DIR_PATH .'/backups/' );
150
+
151
+ //Re-create and empty backup dir
152
+ if(!create_dir( WPBACKITUP_DIR_PATH .'/backups/' )) {
153
+ fwrite($fh, '<div class="error201">1</div>');
154
+ fclose($fh);
155
+ die();
156
+ }
157
+
158
+ //Move the uploaded zip to the restoration directory
159
+ $restore_file_name = basename( $_FILES['wpbackitup-zip']['name']);
160
+ if( $restore_file_name == '') {
161
+ fwrite($fh, '<div class="error201">1</div>');
162
+ fclose($fh);
163
+ die();
164
+ }
165
+
166
+ $restore_path = WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name;
167
+ if(move_uploaded_file($_FILES['wpbackitup-zip']['tmp_name'], $restore_path)) {
168
+ fwrite($fh, '<div class="upload">1</div>');
169
+ } else {
170
+ fwrite($fh, '<div class="error203">1</div>');
171
+ fclose($fh);
172
+ die();
173
+ }
174
+
175
+ //unzip the upload
176
+ $zip = new ZipArchive;
177
+ $res = $zip->open(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
178
+ if ($res === TRUE) {
179
+ $zip->extractTo(WPBACKITUP_DIR_PATH .'/backups/');
180
+ $zip->close();
181
+ fwrite($fh, '<div class="unzipping">1</div>');
182
+ } else {
183
+ fwrite($fh, '<div class="error204">1</div>');
184
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
185
+ fclose($fh);
186
+ die();
187
+ }
188
+
189
+ //Identify the restoration directory
190
+ if ( count( glob( WPBACKITUP_DIR_PATH .'/backups/*', GLOB_ONLYDIR ) ) == 1 ) {
191
+ foreach( glob(WPBACKITUP_DIR_PATH .'/backups/*', GLOB_ONLYDIR ) as $dir) {
192
+ $restoration_dir_path = $dir .'/';
193
+ }
194
+ }
195
+
196
+ //Validate the restoration
197
+ if(glob($restoration_dir_path .'backupsiteinfo.txt') ){
198
+ fwrite($fh, '<div class="validation">1</div>');
199
+ } else {
200
+ fwrite($fh, '<div class="error204">1</div>');
201
+ recursive_delete($restoration_dir_path);
202
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
203
+ fclose($fh);
204
+ die();
205
+ }
206
+
207
+ // Backup the current database
208
+ if( db_backup($restoration_dir_path) ) {
209
+ fwrite($fh, '<div class="restore_point">1</div>');
210
+ } else {
211
+ fwrite($fh, '<div class="error205">1</div>');
212
+ fclose($fh);
213
+ die();
214
+ }
215
+
216
+ //if there is a database dump to restore
217
+ if( glob($restoration_dir_path . "*.sql") ) {
218
+
219
+ //Collect connection information from form
220
+ include_once WP_DIR_PATH .'/wp-config.php';
221
+
222
+ //Add user to DB in v1.0.5
223
+ $user_id = $_POST['user_id'];
224
+
225
+ //Connect to DB
226
+ $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
227
+ if ( !$dbc ) {
228
+ fwrite($fh, '<div class="error206">1</div>');
229
+
230
+ recursive_delete($restoration_dir_path);
231
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
232
+ fclose($fh);
233
+ die();
234
+ }
235
+
236
+ //get siteurl
237
+ $q1 = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='siteurl';";
238
+ if ($result = mysqli_query($dbc, $q1)) {
239
+ while ($row = mysqli_fetch_row($result)) {
240
+ $siteurl = $row[0];
241
+ }
242
+ mysqli_free_result($result);
243
+ } else {
244
+ fwrite($fh, '<div class="error207">1</div>');
245
+ recursive_delete($restoration_dir_path);
246
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
247
+ fclose($fh);
248
+ die();
249
+ }
250
+
251
+ //get homeurl
252
+ $q2 = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='home';";
253
+ if ($result = mysqli_query($dbc, $q2)) {
254
+ while ($row = mysqli_fetch_row($result)) {
255
+ $homeurl = $row[0];
256
+ }
257
+ mysqli_free_result($result);
258
+ } else {
259
+ fwrite($fh, '<div class="error208">1</div>');
260
+ recursive_delete($restoration_dir_path);
261
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
262
+ fclose($fh);
263
+ die();
264
+ }
265
+
266
+ //get user login
267
+ $q3 = "SELECT user_login FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
268
+ if ($result = mysqli_query($dbc, $q3)) {
269
+ while ($row = mysqli_fetch_row($result)) {
270
+ $user_login = $row[0];
271
+ }
272
+ mysqli_free_result($result);
273
+ } else {
274
+ fwrite($fh, '<div class="error209">1</div>');
275
+ recursive_delete($restoration_dir_path);
276
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
277
+ fclose($fh);
278
+ die();
279
+ }
280
+
281
+ //get user pass
282
+ $q4 = "SELECT user_pass FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
283
+ if ($result = mysqli_query($dbc, $q4)) {
284
+ while ($row = mysqli_fetch_row($result)) {
285
+ $user_pass = $row[0];
286
+ }
287
+ mysqli_free_result($result);
288
+ } else {
289
+ fwrite($fh, '<div class="error210">1</div>');
290
+ recursive_delete($restoration_dir_path);
291
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
292
+ fclose($fh);
293
+ die();
294
+ }
295
+
296
+ //get user email
297
+ $q5 = "SELECT user_email FROM ". $table_prefix ."users WHERE ID=" .$user_id ."";
298
+ if ($result = mysqli_query($dbc, $q5)) {
299
+ while ($row = mysqli_fetch_row($result)) {
300
+ $user_email = $row[0];
301
+ }
302
+ mysqli_free_result($result);
303
+ } else {
304
+ fwrite($fh, '<div class="error211">1</div>');
305
+ recursive_delete($restoration_dir_path);
306
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
307
+ fclose($fh);
308
+ die();
309
+ }
310
+
311
+ //Collect previous backup site url start
312
+ $import_siteinfo_lines = file($restoration_dir_path .'backupsiteinfo.txt');
313
+ $import_siteurl = trim($import_siteinfo_lines[0]);
314
+ $current_siteurl = trim($siteurl ,'/');
315
+ $import_table_prefix = $import_siteinfo_lines[1];
316
+
317
+ //import the database
318
+ if(!db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc)) {
319
+ fwrite($fh, '<div class="error212">1</div>');
320
+ recursive_delete($restoration_dir_path);
321
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
322
+ fclose($fh);
323
+ die();
324
+ }
325
+
326
+ //update the database
327
+ $q6 = "UPDATE ". $table_prefix ."options SET option_value='" .$current_siteurl ."' WHERE option_name='siteurl'";
328
+ $q7 = "UPDATE ". $table_prefix ."options SET option_value='" .$homeurl ."' WHERE option_name='home'";
329
+ $q8 = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
330
+ if(!mysqli_query($dbc, $q6) ) {
331
+ fwrite($fh, '<div class="error213">1</div>');
332
+ recursive_delete($restoration_dir_path);
333
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
334
+ fclose($fh);
335
+ die();
336
+ }
337
+ if(!mysqli_query($dbc, $q7) ) {
338
+ fwrite($fh, '<div class="error214">1</div>');
339
+ recursive_delete($restoration_dir_path);
340
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
341
+ fclose($fh);
342
+ die();
343
+ }
344
+ if(!mysqli_query($dbc, $q8) ) {
345
+ fwrite($fh, '<div class="error215">1</div>');
346
+ recursive_delete($restoration_dir_path);
347
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
348
+ fclose($fh);
349
+ die();
350
+ }
351
+ fwrite($fh, '<div class="database">1</div>');
352
+ } else {
353
+ fwrite($fh, '<div class="error216">1</div>');
354
+ }
355
+
356
+ //Disconnect
357
+ mysqli_close($dbc);
358
+
359
+ //Restore wp-content directories
360
+ if(!recursive_delete(WP_CONTENT_PATH, array( 'cgi-bin','.','..','._', WPBACKITUP_DIRNAME ))) {
361
+ fwrite($fh, '<div class="error217">1</div>');
362
+ recursive_delete($restoration_dir_path);
363
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
364
+ fclose($fh);
365
+ die();
366
+ }
367
+ if(!create_dir(WP_CONTENT_PATH)) {
368
+ fwrite($fh, '<div class="error218">1</div>');
369
+ recursive_delete($restoration_dir_path);
370
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
371
+ fclose($fh);
372
+ die();
373
+ }
374
+ if(recursive_copy($restoration_dir_path, WP_CONTENT_PATH .'/', array( 'cgi-bin', '.', '..','._', $restore_file_name, 'status.log', 'db-backup.sql', 'backupsiteinfo.txt')) ) {
375
+ fwrite($fh, '<div class="wpcontent">1</div>');
376
+ } else {
377
+ fwrite($fh, '<div class="error219">1</div>');
378
+ recursive_delete($restoration_dir_path);
379
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
380
+ fclose($fh);
381
+ die();
382
+ }
383
+
384
+ //Delete the restoration directory
385
+ if(!recursive_delete($restoration_dir_path)) {
386
+ fwrite($fh, '<div class="error220">1</div>');
387
+ fclose($fh);
388
+ } else {
389
+ fwrite($fh, '<div class="cleanup">1</div>');
390
+ }
391
+
392
+ //Delete zip
393
+ unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
394
+
395
+ //close log file
396
+ fwrite($fh, '<div class="finalinfo">1</div>');
397
+ fclose($fh);
398
+
399
+ //End backup function
400
  die();
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.wpbackitup.com
4
  Tags: backup wordpress, database backup, backup database, download database, backup and restore, restoring wordpress, restore wordpress, restore wordpress backup,
5
  Requires at least: 3.4.2
6
  Tested up to: 3.6.1
7
- Stable tag: 1.5.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -93,6 +93,9 @@ Yes.
93
 
94
  == Changelog ==
95
 
 
 
 
96
  = 1.5.0 =
97
  Changed DB Export and import method to work on all hosting.
98
 
@@ -152,6 +155,9 @@ Initial version of the plugin released.
152
 
153
  == Upgrade Notice ==
154
 
 
 
 
155
  = 1.5.0 =
156
  Critical upgrade: Fixes to backup and import processes to work on a wider range of hosts.
157
 
4
  Tags: backup wordpress, database backup, backup database, download database, backup and restore, restoring wordpress, restore wordpress, restore wordpress backup,
5
  Requires at least: 3.4.2
6
  Tested up to: 3.6.1
7
+ Stable tag: 1.5.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
93
 
94
  == Changelog ==
95
 
96
+ = 1.5.1 =
97
+ Removed redundant code.
98
+
99
  = 1.5.0 =
100
  Changed DB Export and import method to work on all hosting.
101
 
155
 
156
  == Upgrade Notice ==
157
 
158
+ = 1.5.1 =
159
+ Optional upgrade: Redundant code was removed from plugin.
160
+
161
  = 1.5.0 =
162
  Critical upgrade: Fixes to backup and import processes to work on a wider range of hosts.
163
 
views/options.php CHANGED
@@ -1,156 +1,156 @@
1
- <script type="text/javascript">var __namespace = '<?php echo $namespace; ?>';</script>
2
- <div class="wrap">
3
- <div id="wp-backitup-icon" class="icon32"><img src="<?php echo plugin_dir_url(dirname(__FILE__) ); ?>images/icon32.png" alt="WP Backitup Icon" height="32" width="32" /></div>
4
- <h2><?php echo $page_title; ?></h2>
5
- <div id="content">
6
- <h3><?php _e('Backup', $namespace );?></h3>
7
- <p><?php _e('Create a backup file of this site\'s content and settings', $namespace ) ;?></p>
8
- <p><a href="#" class="backup-button button-primary"><?php _e( "Backup", $namespace ) ?></a><img class="backup-icon status-icon" src="<?php echo WPBACKITUP_URLPATH. "/images/loader.gif"; ?>" height="16" width="16" /></p>
9
- <h3><?php _e('Download', $namespace );?></h3>
10
- <p id="download-link"></p>
11
-
12
- <!--Disable restoration form if the user has not activated-->
13
- <?php $status = $this->get_option( 'status' );
14
- if( $status !== false && $status == 'valid' ) { ?>
15
- <h3><?php _e('Restore', $namespace );?></h3>
16
- <iframe id="upload_target" name="upload_target" src=""></iframe>
17
- <p><?php _e('Restore a WP Backitup zip file and overwrite this site\'s content, themes, plugins, uploads and settings', $namespace );?></p>
18
- <?php $max_upload = (int)(ini_get('upload_max_filesize'));
19
- $max_post = (int)(ini_get('post_max_size'));
20
- $memory_limit = (int)(ini_get('memory_limit'));
21
- $upload_mb = min($max_upload, $max_post, $memory_limit); ?>
22
- <p><?php _e( 'The maximum filesize you can upload is ', $namespace );
23
- echo $upload_mb .'MB.'; ?>
24
- </p>
25
- <form id="restore-form" method="post" enctype="multipart/form-data" action="<?php echo WPBACKITUP_URLPATH .'/lib/includes/restore.php'; ?>">
26
- <?php global $current_user; ?>
27
- <input type="hidden" name="user_id" value="<?php echo $current_user->ID; ?>" />
28
- <input type="hidden" name="maximum" id="maximum" value="<?php echo $upload_mb; ?>" />
29
- <p><input name="wpbackitup-zip" id="wpbackitup-zip" type="file" /></p>
30
- <p><input type="submit" class="restore-button button-primary" name="restore" value="<?php _e( "Restore", $namespace ) ?>" /><img class="restore-icon status-icon" src="<?php echo WPBACKITUP_URLPATH. "/images/loader.gif"; ?>" height="16" width="16" /></p>
31
- </form>
32
- <?php } ?>
33
- <!--End of restoration form-->
34
-
35
- <h3><?php _e('Status', $namespace );?></h3>
36
- <div id="status">
37
-
38
- <!--default status message-->
39
- <ul class="default-status">
40
- <li><?php _e('Nothing to report', $namespace );?></li>
41
- </ul>
42
-
43
- <!--backup status messages-->
44
- <ul class="backup-status">
45
- <li class='prerequisites'><?php _e('Preparing to backup', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
46
- <li class='backupdb'><?php _e('Backing-up database', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
47
- <li class='backupfiles'><?php _e('Backing-up /wp-content/', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
48
- <li class='infofile'><?php _e('Creating backup information file', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
49
- <li class='zipfile'><?php _e('Zipping backup directory', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
50
- <li class='cleanup'><?php _e('Cleaning up', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
51
- <li class='finalinfo'><span class='status'><?php _e('Backup file created successfully. You can download your backup file using the link above', $namespace ); ?></span></li>
52
- </ul>
53
-
54
- <!--backup error messages-->
55
- <ul class="backup-errors">
56
- <li class="error101"><span class='status error'><?php _e('Error: Unable to create new directory for backup. Please check your CHMOD settings of your wp-backitup plugin directory' , $namespace ); ?>.</span></li>
57
- <li class="error102"><span class='status error'><?php _e('Error: Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory', $namespace ); ?>.</span></li>
58
- <li class="error103"><span class='status error'><?php _e('Error: Unable to backup your files. Please try again', $namespace ); ?>.</span></li>
59
- <li class="error104"><span class='status error'><?php _e('Error: Unable to backup your database. Please try again', $namespace ); ?>.</span></li>
60
- <li class="error114"><span class='status error'><?php _e('Error: Your database was accesible but a dump could not be created. Please contact support by clicking the link on the right, stating your web host when you submit the form.', $namespace ); ?>.</span></li>
61
- <li class="error105"><span class='status error'><?php _e('Error: Unable to create site information file. Please try again', $namespace ); ?>.</span></li>
62
- <li class="error106"><span class='status error'><?php _e('Warning: Unable to cleanup your backup directory', $namespace ); ?>.</span></li>
63
- </ul>
64
-
65
- <!--restore status messages-->
66
- <ul class="restore-status">
67
- <li class="upload"><?php _e('Uploading restoration zip', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
68
- <li class="unzipping"><?php _e('Unzipping', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
69
- <li class="validation"><?php _e('Validating restoration zip', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
70
- <li class="restore_point"><?php _e('Setting checkpoint', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
71
- <li class="database"><?php _e('Importing database', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
72
- <li class="wpcontent"><?php _e('Importing /wp-content/ directory', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
73
- <li class="cleanup"><?php _e('Cleaning up', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
74
- <li class='finalinfo'><span class='status'><?php _e('Restoration completed successfully. Please refresh the page and login to the site again (with your current username and password)', $namespace ); ?></span></li>
75
- </ul>
76
-
77
- <!--restore error messages-->
78
- <ul class="restore-errors">
79
- <li class="error201"><span class='status error'><?php _e('Error: No file selected', $namespace ); ?>.</span></li>
80
- <li class="error202"><span class='status error'><?php _e('Error: Your file could not be uploaded', $namespace ); ?>.</span></li>
81
- <li class="error203"><span class='status error'><?php _e('Error: Your restoration file could not be unzipped', $namespace ); ?>.</span></li>
82
- <li class="error204"><span class='status error'><?php _e('Error: Your zip file appears to be invalid. Please ensure you chose the correct zip file', $namespace ); ?>.</span></li>
83
- <li class="error205"><span class='status error'><?php _e('Error: Cannot create restore point', $namespace ); ?>.</span></li>
84
- <li class="error206"><span class='status error'><?php _e('Error: Unable to connect to your database', $namespace ); ?>.</span></li>
85
- <li class="error207"><span class='status error'><?php _e('Error: Unable to get current site URL from database. Please try again', $namespace ); ?>.</span></li>
86
- <li class="error208"><span class='status error'><?php _e('Error: Unable to get current home URL from database. Please try again', $namespace ); ?>.</span></li>
87
- <li class="error209"><span class='status error'><?php _e('Error: Unable to get current user ID from database. Please try again', $namespace ); ?>.</span></li>
88
- <li class="error210"><span class='status error'><?php _e('Error: Unable to get current user password from database. Please try again', $namespace ); ?>.</span></li>
89
- <li class="error211"><span class='status error'><?php _e('Error: Unable to get current user email from database. Please try again', $namespace ); ?>.</span></li>
90
- <li class="error212"><span class='status error'><?php _e('Error: Unable to get import your database. This may require importing the file manually', $namespace ); ?>.</span></li>
91
- <li class="error213"><span class='status error'><?php _e('Error: Unable to update your current site URL value. This may require importing the file manually', $namespace ); ?>.</span></li>
92
- <li class="error214"><span class='status error'><?php _e('Error: Unable to update your current home URL value. This may require importing the file manually', $namespace ); ?>.</span></li>
93
- <li class="error215"><span class='status error'><?php _e('Error: Unable to update your user information. This may require importing the file manually', $namespace ); ?>.</span></li>
94
- <li class="error216"><span class='status error'><?php _e('Error: Warning: Database not detected in import file', $namespace ); ?>.</span></li>
95
- <li class="error217"><span class='status error'><?php _e('Error: Unable to remove existing wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace ); ?>.</span></li>
96
- <li class="error218"><span class='status error'><?php _e('Error: Unable to create new wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace ); ?>.</span></li>
97
- <li class="error219"><span class='status error'><?php _e('Error: Unable to import wp-content. Please try again', $namespace ); ?>.</span></li>
98
- <li class="error220"><span class='status error'><?php _e('Warning: Unable to cleanup import directory', $namespace ); ?>.</span></li>
99
- </ul>
100
- </div>
101
- <?php if (site_url() == 'http://localhost/wpbackitup') {
102
- echo '<p><div id="php">PHP messages here</p></div>';
103
- } ?>
104
- </div>
105
- <div id="sidebar">
106
- <form action="" method="post" id="<?php echo $namespace; ?>-form">
107
- <?php wp_nonce_field( $namespace . "-update-options" ); ?>
108
- <div class="widget">
109
- <h3 class="promo"><?php _e('License Key', $namespace ); ?></h3>
110
- <?php $license = $this->get_option( 'license_key' );
111
- $status = $this->get_option( 'status' );
112
- if( $status !== false && $status == 'valid' ) { ?>
113
- <p><?php _e('Pro features and auto-updates enabled', $namespace ); ?></p>
114
- <?php } else { ?>
115
- <p><?php _e('Activate auto-restore and auto-updates by entering your license key', $namespace ); ?></p>
116
- <?php } ?>
117
- <p><input type="text" name="data[license_key]" id="license_key" value="<?php echo $license; ?>" />
118
- <?php if( false !== $license ) {
119
- if( $status !== false && $status == 'valid' ) { ?>
120
- <span style="color:green;"><?php _e('Active', $namespace); ?></span></p>
121
- <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Update", $namespace ) ?>" /></p>
122
- <?php } else { ?>
123
- <span style="color:red;"><?php _e('Inactive', $namespace); ?></span></p>
124
- <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Activate", $namespace ) ?>" /></p>
125
- <p><a href="http://www.wpbackitup.com/wp-backitup-pro"><?php _e('Purchase a license key', $namespace); ?></a></p>
126
- <?php }
127
- } ?>
128
- </div>
129
-
130
- <div class="widget">
131
- <?php if( $status !== false && $status == 'valid' ) {
132
- $support_anchor = __('WP Backitup support system',$namespace);
133
- $support_url = 'http://www.wpbackitup.com/support/';
134
- } else {
135
- $support_anchor = __('support system',$namespace);
136
- $support_url = 'http://wordpress.org/support/plugin/wp-backitup';
137
- } ?>
138
- <h3 class="promo"><?php _e('Need Help?', $namespace ); ?></h3>
139
- <p><?php _e('Access the',$namespace); ?> <a href="<?php echo $support_url; ?>"><?php echo $support_anchor; ?></a>.</p>
140
- </div>
141
-
142
- <div class="widget">
143
- <h3 class="promo"><?php _e('Spread the Word', $namespace ); ?></h3>
144
- <p><a href="http://wordpress.org/extend/plugins/wp-backitup/"><?php _e('Rate WP Backitup', $namespace ); ?> 5&#9733;</a></p>
145
- </div>
146
-
147
- <div class="widget">
148
- <h3 class="promo">Presstrends</h3>
149
- <p><input type="radio" name="data[presstrends]" value="enabled" <?php if($this->get_option( 'presstrends' ) == 'enabled') echo 'checked'; ?>> <label><?php _e('Enable', $namespace ); ?></label></p>
150
- <p><input type="radio" name="data[presstrends]" value="disabled" <?php if($this->get_option( 'presstrends' ) == 'disabled') echo 'checked'; ?>> <label><?php _e('Disable', $namespace ); ?></label></p>
151
- <p><?php _e('Help to improve Easy Webtrends by enabling', $namespace ); ?> <a href="http://www.presstrends.io" target="_blank">Presstrends</a>.</p>
152
- <p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( "Save", $namespace ) ?>" /></p>
153
- </div>
154
- </form>
155
- </div>
156
- </div>
1
+ <script type="text/javascript">var __namespace = '<?php echo $namespace; ?>';</script>
2
+ <div class="wrap">
3
+ <div id="wp-backitup-icon" class="icon32"><img src="<?php echo plugin_dir_url(dirname(__FILE__) ); ?>images/icon32.png" alt="WP Backitup Icon" height="32" width="32" /></div>
4
+ <h2><?php echo $page_title; ?></h2>
5
+ <div id="content">
6
+ <h3><?php _e('Backup', $namespace );?></h3>
7
+ <p><?php _e('Create a backup file of this site\'s content and settings', $namespace ) ;?></p>
8
+ <p><a href="#" class="backup-button button-primary"><?php _e( "Backup", $namespace ) ?></a><img class="backup-icon status-icon" src="<?php echo WPBACKITUP_URLPATH. "/images/loader.gif"; ?>" height="16" width="16" /></p>
9
+ <h3><?php _e('Download', $namespace );?></h3>
10
+ <p id="download-link"></p>
11
+
12
+ <!--Disable restoration form if the user has not activated-->
13
+ <?php $status = $this->get_option( 'status' );
14
+ if( $status !== false && $status == 'valid' ) { ?>
15
+ <h3><?php _e('Restore', $namespace );?></h3>
16
+ <iframe id="upload_target" name="upload_target" src=""></iframe>
17
+ <p><?php _e('Restore a WP Backitup zip file and overwrite this site\'s content, themes, plugins, uploads and settings', $namespace );?></p>
18
+ <?php $max_upload = (int)(ini_get('upload_max_filesize'));
19
+ $max_post = (int)(ini_get('post_max_size'));
20
+ $memory_limit = (int)(ini_get('memory_limit'));
21
+ $upload_mb = min($max_upload, $max_post, $memory_limit); ?>
22
+ <p><?php _e( 'The maximum filesize you can upload is ', $namespace );
23
+ echo $upload_mb .'MB.'; ?>
24
+ </p>
25
+ <form id="restore-form" method="post" enctype="multipart/form-data" action="<?php echo WPBACKITUP_URLPATH .'/lib/includes/restore.php'; ?>">
26
+ <?php global $current_user; ?>
27
+ <input type="hidden" name="user_id" value="<?php echo $current_user->ID; ?>" />
28
+ <input type="hidden" name="maximum" id="maximum" value="<?php echo $upload_mb; ?>" />
29
+ <p><input name="wpbackitup-zip" id="wpbackitup-zip" type="file" /></p>
30
+ <p><input type="submit" class="restore-button button-primary" name="restore" value="<?php _e( "Restore", $namespace ) ?>" /><img class="restore-icon status-icon" src="<?php echo WPBACKITUP_URLPATH. "/images/loader.gif"; ?>" height="16" width="16" /></p>
31
+ </form>
32
+ <?php } ?>
33
+ <!--End of restoration form-->
34
+
35
+ <h3><?php _e('Status', $namespace );?></h3>
36
+ <div id="status">
37
+
38
+ <!--default status message-->
39
+ <ul class="default-status">
40
+ <li><?php _e('Nothing to report', $namespace );?></li>
41
+ </ul>
42
+
43
+ <!--backup status messages-->
44
+ <ul class="backup-status">
45
+ <li class='prerequisites'><?php _e('Preparing to backup', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
46
+ <li class='backupdb'><?php _e('Backing-up database', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
47
+ <li class='backupfiles'><?php _e('Backing-up /wp-content/', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
48
+ <li class='infofile'><?php _e('Creating backup information file', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
49
+ <li class='zipfile'><?php _e('Zipping backup directory', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
50
+ <li class='cleanup'><?php _e('Cleaning up', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
51
+ <li class='finalinfo'><span class='status'><?php _e('Backup file created successfully. You can download your backup file using the link above', $namespace ); ?></span></li>
52
+ </ul>
53
+
54
+ <!--backup error messages-->
55
+ <ul class="backup-errors">
56
+ <li class="error101"><span class='status error'><?php _e('Error: Unable to create new directory for backup. Please check your CHMOD settings of your wp-backitup plugin directory' , $namespace ); ?>.</span></li>
57
+ <li class="error102"><span class='status error'><?php _e('Error: Cannot create backup directory. Please check the CHMOD settings of your wp-backitup plugin directory', $namespace ); ?>.</span></li>
58
+ <li class="error103"><span class='status error'><?php _e('Error: Unable to backup your files. Please try again', $namespace ); ?>.</span></li>
59
+ <li class="error104"><span class='status error'><?php _e('Error: Unable to backup your database. Please try again', $namespace ); ?>.</span></li>
60
+ <li class="error114"><span class='status error'><?php _e('Error: Your database was accesible but a dump could not be created. Please contact support by clicking the link on the right, stating your web host when you submit the form.', $namespace ); ?>.</span></li>
61
+ <li class="error105"><span class='status error'><?php _e('Error: Unable to create site information file. Please try again', $namespace ); ?>.</span></li>
62
+ <li class="error106"><span class='status error'><?php _e('Warning: Unable to cleanup your backup directory', $namespace ); ?>.</span></li>
63
+ </ul>
64
+
65
+ <!--restore status messages-->
66
+ <ul class="restore-status">
67
+ <li class="upload"><?php _e('Uploading restoration zip', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
68
+ <li class="unzipping"><?php _e('Unzipping', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
69
+ <li class="validation"><?php _e('Validating restoration zip', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
70
+ <li class="restore_point"><?php _e('Setting checkpoint', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
71
+ <li class="database"><?php _e('Importing database', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
72
+ <li class="wpcontent"><?php _e('Importing /wp-content/ directory', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
73
+ <li class="cleanup"><?php _e('Cleaning up', $namespace );?>...<span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
74
+ <li class='finalinfo'><span class='status'><?php _e('Restoration completed successfully. Please refresh the page and login to the site again (with your current username and password)', $namespace ); ?></span></li>
75
+ </ul>
76
+
77
+ <!--restore error messages-->
78
+ <ul class="restore-errors">
79
+ <li class="error201"><span class='status error'><?php _e('Error: No file selected', $namespace ); ?>.</span></li>
80
+ <li class="error202"><span class='status error'><?php _e('Error: Your file could not be uploaded', $namespace ); ?>.</span></li>
81
+ <li class="error203"><span class='status error'><?php _e('Error: Your restoration file could not be unzipped', $namespace ); ?>.</span></li>
82
+ <li class="error204"><span class='status error'><?php _e('Error: Your zip file appears to be invalid. Please ensure you chose the correct zip file', $namespace ); ?>.</span></li>
83
+ <li class="error205"><span class='status error'><?php _e('Error: Cannot create restore point', $namespace ); ?>.</span></li>
84
+ <li class="error206"><span class='status error'><?php _e('Error: Unable to connect to your database', $namespace ); ?>.</span></li>
85
+ <li class="error207"><span class='status error'><?php _e('Error: Unable to get current site URL from database. Please try again', $namespace ); ?>.</span></li>
86
+ <li class="error208"><span class='status error'><?php _e('Error: Unable to get current home URL from database. Please try again', $namespace ); ?>.</span></li>
87
+ <li class="error209"><span class='status error'><?php _e('Error: Unable to get current user ID from database. Please try again', $namespace ); ?>.</span></li>
88
+ <li class="error210"><span class='status error'><?php _e('Error: Unable to get current user password from database. Please try again', $namespace ); ?>.</span></li>
89
+ <li class="error211"><span class='status error'><?php _e('Error: Unable to get current user email from database. Please try again', $namespace ); ?>.</span></li>
90
+ <li class="error212"><span class='status error'><?php _e('Error: Unable to get import your database. This may require importing the file manually', $namespace ); ?>.</span></li>
91
+ <li class="error213"><span class='status error'><?php _e('Error: Unable to update your current site URL value. This may require importing the file manually', $namespace ); ?>.</span></li>
92
+ <li class="error214"><span class='status error'><?php _e('Error: Unable to update your current home URL value. This may require importing the file manually', $namespace ); ?>.</span></li>
93
+ <li class="error215"><span class='status error'><?php _e('Error: Unable to update your user information. This may require importing the file manually', $namespace ); ?>.</span></li>
94
+ <li class="error216"><span class='status error'><?php _e('Error: Warning: Database not detected in import file', $namespace ); ?>.</span></li>
95
+ <li class="error217"><span class='status error'><?php _e('Error: Unable to remove existing wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace ); ?>.</span></li>
96
+ <li class="error218"><span class='status error'><?php _e('Error: Unable to create new wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace ); ?>.</span></li>
97
+ <li class="error219"><span class='status error'><?php _e('Error: Unable to import wp-content. Please try again', $namespace ); ?>.</span></li>
98
+ <li class="error220"><span class='status error'><?php _e('Warning: Unable to cleanup import directory', $namespace ); ?>.</span></li>
99
+ </ul>
100
+ </div>
101
+ <?php if (site_url() == 'http://localhost/wpbackitup') {
102
+ echo '<p><div id="php">PHP messages here</p></div>';
103
+ } ?>
104
+ </div>
105
+ <div id="sidebar">
106
+ <form action="" method="post" id="<?php echo $namespace; ?>-form">
107
+ <?php wp_nonce_field( $namespace . "-update-options" ); ?>
108
+ <div class="widget">
109
+ <h3 class="promo"><?php _e('License Key', $namespace ); ?></h3>
110
+ <?php $license = $this->get_option( 'license_key' );
111
+ $status = $this->get_option( 'status' );
112
+ if( $status !== false && $status == 'valid' ) { ?>
113
+ <p><?php _e('Pro features and auto-updates enabled', $namespace ); ?></p>
114
+ <?php } else { ?>
115
+ <p><?php _e('Activate auto-restore and auto-updates by entering your license key', $namespace ); ?></p>
116
+ <?php } ?>
117
+ <p><input type="text" name="data[license_key]" id="license_key" value="<?php echo $license; ?>" />
118
+ <?php if( false !== $license ) {
119
+ if( $status !== false && $status == 'valid' ) { ?>
120
+ <span style="color:green;"><?php _e('Active', $namespace); ?></span></p>
121
+ <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Update", $namespace ) ?>" /></p>
122
+ <?php } else { ?>
123
+ <span style="color:red;"><?php _e('Inactive', $namespace); ?></span></p>
124
+ <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Activate", $namespace ) ?>" /></p>
125
+ <p><a href="http://www.wpbackitup.com/wp-backitup-pro"><?php _e('Purchase a license key', $namespace); ?></a></p>
126
+ <?php }
127
+ } ?>
128
+ </div>
129
+
130
+ <div class="widget">
131
+ <?php if( $status !== false && $status == 'valid' ) {
132
+ $support_anchor = __('WP Backitup support system',$namespace);
133
+ $support_url = 'http://www.wpbackitup.com/support/';
134
+ } else {
135
+ $support_anchor = __('support system',$namespace);
136
+ $support_url = 'http://wordpress.org/support/plugin/wp-backitup';
137
+ } ?>
138
+ <h3 class="promo"><?php _e('Need Help?', $namespace ); ?></h3>
139
+ <p><?php _e('Access the',$namespace); ?> <a href="<?php echo $support_url; ?>"><?php echo $support_anchor; ?></a>.</p>
140
+ </div>
141
+
142
+ <div class="widget">
143
+ <h3 class="promo"><?php _e('Spread the Word', $namespace ); ?></h3>
144
+ <p><a href="http://wordpress.org/extend/plugins/wp-backitup/"><?php _e('Rate WP Backitup', $namespace ); ?> 5&#9733;</a></p>
145
+ </div>
146
+
147
+ <div class="widget">
148
+ <h3 class="promo">Presstrends</h3>
149
+ <p><input type="radio" name="data[presstrends]" value="enabled" <?php if($this->get_option( 'presstrends' ) == 'enabled') echo 'checked'; ?>> <label><?php _e('Enable', $namespace ); ?></label></p>
150
+ <p><input type="radio" name="data[presstrends]" value="disabled" <?php if($this->get_option( 'presstrends' ) == 'disabled') echo 'checked'; ?>> <label><?php _e('Disable', $namespace ); ?></label></p>
151
+ <p><?php _e('Help to improve Easy Webtrends by enabling', $namespace ); ?> <a href="http://www.presstrends.io" target="_blank">Presstrends</a>.</p>
152
+ <p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( "Save", $namespace ) ?>" /></p>
153
+ </div>
154
+ </form>
155
+ </div>
156
+ </div>