Backup and Restore WordPress – WPBackItUp Backup Plugin - Version 1.6.0

Version Description

  • Significant performance improvements.
  • Many improvements to user interface.
  • Support for multiple backups.
  • Added interface for large file uploads via FTP.
  • Added restore point and database recovery when fatal errors are encountered.
  • Added configurable debug logging.
Download this release

Release Info

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

Code changes from version 1.5.5 to 1.6.0

css/admin.css CHANGED
@@ -1,63 +1,101 @@
1
- /**
2
- * WP Backitup Admin Control Panel Stylesheets
3
- *
4
- * @version 1.4.0
5
- * @since 1.0.1
6
- */
7
-
8
- /* Global */
9
-
10
- .error { color: #ff0000;}
11
-
12
- p {line-height: 1.4em;}
13
-
14
- td {padding: 0;}
15
-
16
- h3 {
17
- margin: 0;
18
- padding: 1em 0 0 0;
19
- }
20
-
21
- iframe {
22
- height: 0;
23
- margin: 0;
24
- padding: 0;
25
- position: absolute;
26
- top: 0;
27
- right: 0;
28
- width: 0;
29
- z-index: -1;
30
- }
31
-
32
- .submit { padding: 0; }
33
-
34
- /* Content */
35
- #content {
36
- float: left;
37
- width: 65%;
38
- }
39
-
40
- #content input[type="text"], #content input[type="file"] {padding: 0;}
41
-
42
- .status-icon {
43
- display: inline;
44
- height: 16px;
45
- position: relative;
46
- top: 3px;
47
- left: 5px;
48
- visibility: hidden;
49
- width: 16px;
50
- }
51
-
52
- /** Status Reporting **/
53
- .backup-status, .backup-status span, .backup-errors, .backup-errors span, .restore-status, .restore-status span, .restore-errors, .restore-errors span {
54
- display: none;
55
- }
56
-
57
- /* Sidebar */
58
- #sidebar {
59
- float: right;
60
- width: 30%;
61
- }
62
-
63
- .widget {padding: 1em;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * WP Backitup Admin Control Panel Stylesheets
3
+ *
4
+ * @version 1.4.0
5
+ * @since 1.0.1
6
+ */
7
+
8
+ /* Global */
9
+
10
+ .error { color: #ff0000;}
11
+ .warning { color: #FEEFB3;}
12
+
13
+ .isa_info, .isa_success, .isa_warning, .isa_error {
14
+ border: 1px solid;
15
+ margin: 10px 0px;
16
+ padding:15px 10px 15px 50px;
17
+ background-repeat: no-repeat;
18
+ background-position: 10px center;-moz-border-radius:.5em;
19
+ -webkit-border-radius:.5em;
20
+ border-radius:.5em;
21
+
22
+ }
23
+ .isa_info {
24
+ color: #00529B;
25
+ background-color: #BDE5F8;
26
+ background-image: url('../images/info.png');
27
+ }
28
+ .isa_success {
29
+ color: #4F8A10;
30
+ background-color: #DFF2BF;
31
+ background-image:url('../images/success.png');
32
+ }
33
+ .isa_warning {
34
+ color: #9F6000;
35
+ background-color: #FEEFB3;
36
+ background-image: url('../images/warning.png');
37
+ }
38
+ .isa_error {
39
+ color: #D8000C;
40
+ background-color: #FFBABA;
41
+ background-image: url('../images/error.png');
42
+ }
43
+
44
+ p {line-height: 1.4em;}
45
+
46
+ td {padding: 0;}
47
+
48
+ h3 {
49
+ margin: 0;
50
+ padding: 0 0 0 0;
51
+ border-bottom: 1px solid #eee;
52
+ }
53
+
54
+ iframe {
55
+ height: 0;
56
+ margin: 0;
57
+ padding: 0;
58
+ position: absolute;
59
+ top: 0;
60
+ right: 0;
61
+ width: 0;
62
+ z-index: -1;
63
+ }
64
+
65
+ .submit { padding: 0; }
66
+
67
+
68
+ /* Content */
69
+ #content {
70
+ float: left;
71
+ width: 65%;
72
+ }
73
+
74
+ #content input[type="text"], #content input[type="file"] {padding: 0;}
75
+
76
+ .status-icon {
77
+ display: inline;
78
+ height: 16px;
79
+ position: relative;
80
+ top: 3px;
81
+ left: 5px;
82
+ visibility: hidden;
83
+ width: 16px;
84
+ }
85
+
86
+ /** Status Reporting **/
87
+ .backup-status, .backup-status span, .backup-errors, .backup-errors span, .restore-status, .restore-status span, .restore-errors, .restore-errors div, .restore-success, .restore-success div, .upload-status, .upload-status span {
88
+ display: none;
89
+ }
90
+
91
+ /* Sidebar */
92
+ #sidebar {
93
+ float: right;
94
+ width: 30%;
95
+ }
96
+
97
+ .widget {
98
+ padding: 1em;
99
+ background-color: white;
100
+ margin: 20px;
101
+ }
images/error.png ADDED
Binary file
images/info.png ADDED
Binary file
images/success.png ADDED
Binary file
images/warning.png ADDED
Binary file
index.php CHANGED
@@ -6,19 +6,19 @@
6
  *
7
  * @global object $wpdb
8
  *
9
- * @author jcpeden
10
- * @version 1.5.5
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.5
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
@@ -242,7 +242,7 @@ class WPBackitup {
242
  */
243
  function admin_print_scripts() {
244
  wp_enqueue_script( "{$this->namespace}-admin" );
245
- wp_enqueue_script( "{$this->namespace}-ajaxfileupload" );
246
  }
247
 
248
  /**
@@ -354,7 +354,7 @@ class WPBackitup {
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
  /**
6
  *
7
  * @global object $wpdb
8
  *
9
+ * @author cssimmon
10
+ * @version 1.6.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.6.0
17
+ Author: Chris Simmons
18
+ Author URI: http://www.wpbackitup.com
19
  License: GPL3
20
 
21
+ Copyright 2012-2014 WPBackItUp (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
242
  */
243
  function admin_print_scripts() {
244
  wp_enqueue_script( "{$this->namespace}-admin" );
245
+ //wp_enqueue_script( "{$this->namespace}-ajaxfileupload" );
246
  }
247
 
248
  /**
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
  /**
js/admin.js CHANGED
@@ -1,125 +1,325 @@
1
- /**
2
- * WP Backitup Admin Control Panel JavaScripts
3
- *
4
- * @version 1.4.0
5
- * @since 1.0.1
6
- */
7
-
8
- (function($){
9
- /* define backup variables */
10
- var backup = {
11
- action: 'backup',
12
- beforeSend: function() {
13
- /* display processing icon */
14
- $('.backup-icon').css('visibility','visible');
15
-
16
- /* hide default message, restore status and restore errors */
17
- $('.default-status, .restore-status, .restore-errors').hide();
18
-
19
- /* show backup status, backup errors */
20
- $('.backup-status, .backup-errors').toggle();
21
-
22
- window.intervalDefine = setInterval(display_log, 1000);
23
- }
24
- };
25
-
26
- /* define download variables */
27
- var download = {
28
- action: 'download'
29
- };
30
-
31
- /* define logreader variables */
32
- var logreader = {
33
- action: 'logreader'
34
- };
35
-
36
- /* define logreader function */
37
- function display_log() {
38
- $.post(ajaxurl, logreader, function(response) {
39
-
40
- /* Get response from log reader */
41
- var xmlObj = $(response);
42
-
43
- /* For each response */
44
- xmlObj.each(function() {
45
-
46
- /* Select correct status */
47
- var attributename = "." + $(this).attr('class');
48
-
49
- if ( $(this).html() == 0 ) {
50
-
51
- /* If status returns 0, display 'Failed' */
52
- $(attributename).find(".fail").fadeIn(500);
53
-
54
- } else {
55
-
56
- /* If status returns 1, display 'Done' or show detailed message */
57
- $(attributename).find(".status").fadeIn(500);
58
-
59
- }
60
-
61
- /* If is final or error */
62
- if($(this).attr('code') == "finalinfo") {
63
-
64
- /* Stop logreader */
65
- clearInterval(window.intervalDefine);
66
- }
67
- });
68
- });
69
- }
70
-
71
- /* define download function */
72
- function download_link() {
73
- $.post(ajaxurl, download, function(response) {
74
- $("#download-link").html(response);
75
- });
76
- }
77
-
78
- /* execute download (on page load/refresh) */
79
- download_link();
80
-
81
- /* execute backup on button click */
82
- $(".backup-button").click( function() {
83
- $.post(ajaxurl, backup, function(response) {
84
- download_link();
85
- clearInterval(display_log);
86
-
87
- /* fade out status icon */
88
- $('.backup-icon').fadeOut(1000);
89
-
90
- /* Return PHP messages, used for development */
91
- $("#php").html(response);
92
- });
93
- })
94
-
95
- /* execute restore on button click */
96
- $("#restore-form").submit(function() {
97
-
98
- /* display processing icon */
99
- $('.restore-icon').css('visibility','visible');
100
-
101
- /* hide default message, backup status and backup errors */
102
- $('.default-status, .backup-status, .backup-errors').hide();
103
-
104
- /* show restore status messages */
105
- $('.restore-status, .restore-errors').toggle();
106
-
107
- window.intervalDefine = setInterval(display_log, 1000);
108
- $("#restore-form").attr("target","upload_target");
109
- $("#upload_target").load(function (){
110
- importRestore();
111
- });
112
- });
113
-
114
- /* define importRestore function */
115
- function importRestore() {
116
-
117
- /* process upload */
118
- var ret = frames['upload_target'].document.getElementsByTagName("body")[0].innerHTML;
119
-
120
- /* Return PHP messages, used for development */
121
- $("#php").html(ret);
122
- clearInterval(display_log);
123
- $('.restore-icon').fadeOut(1000);
124
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  })(jQuery);
1
+ /**
2
+ * WP Backitup Admin Control Panel JavaScripts
3
+ *
4
+ * @version 1.4.0
5
+ * @since 1.0.1
6
+ */
7
+
8
+ (function($){
9
+ /* define backup variables */
10
+ var backup = {
11
+ action: 'backup',
12
+ beforeSend: function () {
13
+
14
+ /* display processing icon */
15
+ $('.backup-icon').css('visibility', 'visible');
16
+ $('.backup-icon').show();
17
+
18
+ /* hide default message, restore status and restore errors */
19
+ $('.default-status, .restore-status, .restore-errors, .restore-success').hide();
20
+
21
+ /* hide the status just incase this is the second run */
22
+ $("ul.backup-status").children().children().hide();
23
+ $("ul.backup-errors").children().children().hide();
24
+
25
+ /* show backup status, backup errors */
26
+ $('.backup-status, .backup-errors').show();
27
+ window.intervalDefine = setInterval(display_log, 3000);
28
+
29
+ }
30
+ };
31
+
32
+ /* define logreader variables */
33
+ var logreader = {
34
+ action: 'logreader'
35
+ };
36
+
37
+ /* define logreader variables */
38
+ var statusreader = {
39
+ action: 'statusreader'
40
+ };
41
+
42
+ /* define logreader function */
43
+ function display_log() {
44
+ $.post(ajaxurl, logreader, function(response) {
45
+
46
+ /* Get response from log reader */
47
+ var xmlObj = $(response);
48
+
49
+ /* For each response */
50
+ xmlObj.each(function() {
51
+
52
+ /* Select correct status */
53
+ var attributename = "." + $(this).attr('class');
54
+
55
+ /* Select correct status */
56
+ if ($(this).html() == 0) {
57
+
58
+ /* If status returns 0, display 'Failed' */
59
+ $('.backup-icon').fadeOut(200);
60
+ $(attributename).find(".fail").fadeIn(1500);
61
+ clearInterval(window.intervalDefine);
62
+
63
+ } else {
64
+
65
+ /* If status returns 1, display 'Done' or show detailed message */
66
+ $(attributename).find(".status").fadeIn(500);
67
+
68
+ }
69
+
70
+ /* If is final or error */
71
+ if (attributename == ".finalinfo") {
72
+ /* Stop logreader */
73
+ clearInterval(window.intervalDefine);
74
+ }
75
+
76
+ });
77
+ });
78
+ }
79
+
80
+ /* define display status function */
81
+ function display_status() {
82
+ $.post(ajaxurl, statusreader, function(response) {
83
+
84
+ /* Get response from log reader */
85
+ var xmlObj = $(response);
86
+
87
+ /* For each response */
88
+ xmlObj.each(function() {
89
+
90
+ /* Select correct status */
91
+ var attributename = "." + $(this).attr('class');
92
+ var icon_attributename = "." + $(this).attr('class') + '-icon';
93
+
94
+
95
+ //Hide all
96
+ if ( $(this).html() == 0 ) {
97
+
98
+ $(attributename).find(".status").hide();
99
+ $(attributename).find(".status-icon").hide();
100
+
101
+ }
102
+
103
+ //Processing
104
+ if ( $(this).html() == 1 ) {
105
+
106
+ $(icon_attributename).css('visibility', 'visible');
107
+ $(attributename).find(".status").fadeOut(200);
108
+ $(attributename).find(".status-icon").fadeIn(1500);
109
+
110
+ }
111
+
112
+ //Done
113
+ if ( $(this).html() == 2 ) {
114
+
115
+ /* If status returns 1, display 'Done' or show detailed message */
116
+ $(attributename).find(".status-icon").fadeOut(200);
117
+ $(attributename).find(".status").fadeIn(1500);
118
+
119
+ }
120
+
121
+ //Fatal Error
122
+ if ( $(this).html() == -1 ) {
123
+
124
+ $(attributename).find(".status-icon").fadeOut(200);
125
+ $(attributename).find(".fail").fadeIn(1500);
126
+ $(attributename).find(".isa_error").fadeIn(1500);
127
+
128
+ /* Stop status reader */
129
+ clearInterval(window.intervalDefine);
130
+
131
+ }
132
+
133
+ //Warning
134
+ if ( $(this).html() == -2 ) {
135
+
136
+ $(attributename).find(".isa_warning").fadeIn(1500);
137
+
138
+ }
139
+
140
+ //success
141
+ if ( $(this).html() == 99 ) {
142
+
143
+ $(attributename).find(".isa_success").fadeIn(1500);
144
+
145
+ /* Stop statusreader */
146
+ clearInterval(window.intervalDefine);
147
+
148
+ }
149
+
150
+ });
151
+ });
152
+ }
153
+
154
+ /* execute backup on button click */
155
+ $(".backup-button").click(function(e) {
156
+ e.preventDefault();
157
+
158
+ $("#backup-button").attr('disabled', 'disabled'); //Disable button
159
+
160
+ $.post(ajaxurl, backup, function(response) {
161
+
162
+ /* Return PHP messages, used for development */
163
+ $("#php").html(response);
164
+
165
+ //clearInterval(window.intervalDefine);
166
+ var data = $.parseJSON(response);
167
+ processRow(data);
168
+ /* fade out status icon */
169
+ $('.backup-icon').fadeOut(1000);
170
+ $("#backup-button").removeAttr("disabled"); //enable button
171
+
172
+ });
173
+ });
174
+
175
+
176
+ //Restore file action
177
+ $('#datatable').on('click', 'a.restoreRow', function(e) {
178
+ e.preventDefault();
179
+ if (confirm('Are you sure you want to restore your site?'))
180
+ {
181
+ var filename = this.title;
182
+ var row = this.id.replace('restoreRow', 'row');
183
+ $('#is_selected').val(1);
184
+ $('#selected_file').val(filename);
185
+
186
+ //Submit the restore
187
+ $('#restore-form').submit();
188
+ }
189
+ });
190
+
191
+ // Delete file action
192
+ $('#datatable').on('click', 'a.deleteRow', function(e) {
193
+
194
+ e.preventDefault();
195
+ if (confirm('Are you sure ?'))
196
+ {
197
+ var filename = this.title;
198
+ var row = this.id.replace('deleteRow', 'row');
199
+ $.ajax({
200
+ url: ajaxurl,
201
+ type: 'post',
202
+ data: {action: "deletefile", filed: filename},
203
+ success: function(data) {
204
+ if (data === 'deleted')
205
+ {
206
+ $('#' + row).remove();
207
+ }
208
+ else
209
+ {
210
+ alert('This file cannot be delete!');
211
+ }
212
+ }
213
+ });
214
+ }
215
+ else
216
+ {
217
+ return;
218
+ }
219
+ });
220
+
221
+ function processRow(data)
222
+ {
223
+ // decide class of row to be inserted dynamically
224
+ var css_class;
225
+ css_class = '';
226
+
227
+ if (!$('#datatable tr').first().hasClass('alternate'))
228
+ css_class = 'class="alternate"';
229
+ // decided class of row to be inserted dynamically
230
+
231
+ // build id of the row to be inserted dynamically
232
+ var cur_row = ($('#datatable tr:last')[0].id.replace('row', ''));
233
+ cur_row++;
234
+
235
+ // built id of the row to be inserted dynamically
236
+ if (data != undefined)
237
+ {
238
+ var newRow = '<tr ' + css_class + ' id="row' + cur_row + '">\n\
239
+ <td>' + data.file +'</td>\n\
240
+ <td><a href="' + data.link + '">Download</a></td>\n\
241
+ <td><a href="#" title="' + data.file + '" class="deleteRow" id="deleteRow' + cur_row + '">Delete</a></td>\n\
242
+ <td><a href="#" title="' + data.file + '" class="restoreRow" id="restoreRow' + cur_row + '">Restore</a></td>\n\
243
+ </tr>';
244
+
245
+ if ($('#nofiles'))
246
+ $('#nofiles').remove();
247
+
248
+ $('#datatable').prepend(newRow);
249
+ $('#datatable tr:last').hide().show('slow'); // just an animation to show newly added row
250
+ }
251
+ }
252
+
253
+ /* execute restore on button click */
254
+ $("#restore-form").submit(function() {
255
+ /* display processing icon */
256
+ $('.restore-icon').css('visibility', 'visible');
257
+
258
+ /* hide default message, backup status and backup errors */
259
+ $('.default-status, .backup-status, .backup-errors').hide();
260
+
261
+ /* show restore status messages */
262
+ $('.restore-status, .restore-errors, .restore-success').show();
263
+ $('.preparing-icon').css('visibility', 'visible');
264
+ $('.preparing').find(".status-icon").fadeIn(1500);
265
+
266
+
267
+ window.intervalDefine = setInterval(display_status, 3000);
268
+ $("#restore-form").attr("target", "upload_target");
269
+ $("#upload_target").load(function() {
270
+ upload_file();
271
+ });
272
+ });
273
+
274
+ /* define upload function */
275
+ function upload_file() {
276
+
277
+ /* process upload */
278
+ var ret = frames['upload_target'].document.getElementsByTagName("body")[0].innerHTML;
279
+
280
+ /* Return PHP messages, used for development */
281
+ $("#php").html(ret);
282
+ clearInterval(display_log);
283
+ $('.upload-icon').fadeOut(1000);
284
+ return ret;
285
+ }
286
+
287
+
288
+ /*Upload form button*/
289
+ $("#upload-form").submit(function() {
290
+
291
+ /* display processing icon */
292
+ $('.upload-icon').css('visibility', 'visible');
293
+
294
+ /* hide default message, backup status and backup errors */
295
+ $('.default-status, .backup-status, .backup-errors').hide();
296
+
297
+ /* show restore status messages */
298
+ $('.upload-status, .upload-errors').toggle();
299
+
300
+ window.intervalDefine = setInterval(display_log, 3000);
301
+ $("#upload-form").attr("target", "upload_target");
302
+ $("#upload_target").load(function() {
303
+ var response = upload_file();
304
+
305
+ var status_message;
306
+ try{
307
+ var data = $.parseJSON(response);
308
+ processRow(data);
309
+ status_message=data.file + ' was uploaded successfully...';
310
+ }
311
+ catch(err)
312
+ {
313
+ status_message=response;
314
+ }
315
+
316
+ //Update the status and disable the button
317
+ $("#wpbackitup-zip").attr("disabled", "disabled"); //Disable upload
318
+ $("#upload-button").attr("disabled", "disabled"); //Disable upload
319
+ $('.upload-status').show();
320
+ $('.upload-status').html(status_message);
321
+
322
+ });
323
+ });
324
+
325
  })(jQuery);
lib/constants.php CHANGED
@@ -9,7 +9,7 @@
9
  * @since 1.0.1
10
  */
11
 
12
- if( !defined( 'WPBACKITUP_VERSION' ) ) define( 'WPBACKITUP_VERSION', '1.5.5' );
13
 
14
  if( !defined( 'WPBACKITUP_DIRNAME' ) ) define( 'WPBACKITUP_DIRNAME', dirname( dirname( __FILE__ ) ) );
15
 
@@ -17,10 +17,30 @@ if( !defined( 'WPBACKITUP_DIR_PATH' ) ) define( 'WPBACKITUP_DIR_PATH', dirname(
17
 
18
  if( !defined( 'WPBACKITUP_CONTENT_PATH' ) ) define( 'WPBACKITUP_CONTENT_PATH', dirname(dirname(dirname(dirname(__FILE__)))) .'/' );
19
 
 
 
 
 
20
  if( !defined( 'WPBACKITUP_URLPATH' ) ) define( 'WPBACKITUP_URLPATH', WP_PLUGIN_URL . "/" . plugin_basename( WPBACKITUP_DIRNAME ) );
21
 
 
 
22
  if( !defined( 'IS_AJAX_REQUEST' ) ) define( 'IS_AJAX_REQUEST', ( !empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) );
23
 
24
  if( !defined( 'WPBACKITUP_SITE_URL' ) ) define( 'WPBACKITUP_SITE_URL', 'http://www.wpbackitup.com' );
 
 
 
 
25
 
26
- if( !defined( 'WPBACKITUP_ITEM_NAME' ) ) define( 'WPBACKITUP_ITEM_NAME', 'WP Backitup' );
 
 
 
 
 
 
 
 
 
 
9
  * @since 1.0.1
10
  */
11
 
12
+ if( !defined( 'WPBACKITUP_VERSION' ) ) define( 'WPBACKITUP_VERSION', '1.6.0' );
13
 
14
  if( !defined( 'WPBACKITUP_DIRNAME' ) ) define( 'WPBACKITUP_DIRNAME', dirname( dirname( __FILE__ ) ) );
15
 
17
 
18
  if( !defined( 'WPBACKITUP_CONTENT_PATH' ) ) define( 'WPBACKITUP_CONTENT_PATH', dirname(dirname(dirname(dirname(__FILE__)))) .'/' );
19
 
20
+ if( !defined( 'WPBACKITUP_BACKUP_FOLDER' ) ) define( 'WPBACKITUP_BACKUP_FOLDER', 'wpbackitup_backups' );
21
+
22
+ if( !defined( 'WPBACKITUP_RESTORE_FOLDER' ) ) define( 'WPBACKITUP_RESTORE_FOLDER', 'wpbackitup_restore' );
23
+
24
  if( !defined( 'WPBACKITUP_URLPATH' ) ) define( 'WPBACKITUP_URLPATH', WP_PLUGIN_URL . "/" . plugin_basename( WPBACKITUP_DIRNAME ) );
25
 
26
+ if( !defined( 'WPBACKITUP_BACKUPFILE_URLPATH' ) ) define( 'WPBACKITUP_BACKUPFILE_URLPATH', content_url() . "/" .WPBACKITUP_BACKUP_FOLDER);
27
+
28
  if( !defined( 'IS_AJAX_REQUEST' ) ) define( 'IS_AJAX_REQUEST', ( !empty( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) );
29
 
30
  if( !defined( 'WPBACKITUP_SITE_URL' ) ) define( 'WPBACKITUP_SITE_URL', 'http://www.wpbackitup.com' );
31
+
32
+ if( !defined( 'WPBACKITUP_ITEM_NAME' ) ) define( 'WPBACKITUP_ITEM_NAME', 'WP Backitup' );
33
+
34
+ if( !defined( 'WPBACKITUP_PLUGIN_FOLDER' ) ) define( 'WPBACKITUP_PLUGIN_FOLDER', plugin_basename( WPBACKITUP_DIRNAME ));
35
 
36
+ if( !defined( 'WPBACKITUP_SQL_DBBACKUP_FILENAME' ) ) define( 'WPBACKITUP_SQL_DBBACKUP_FILENAME', 'db-backup.sql');
37
+
38
+ if( !defined( 'WPBACKITUP_SQL_TABLE_RENAME_FILENAME' ) ) define( 'WPBACKITUP_SQL_TABLE_RENAME_FILENAME', 'db-rename-tables.sql');
39
+
40
+ if( !defined( 'WPBACKITUP_PLUGINS_PATH' ) ) define( 'WPBACKITUP_PLUGINS_PATH', dirname(dirname(__DIR__)));
41
+
42
+ if( !defined( 'WPBACKITUP_PLUGINS_FOLDER' ) ) define( 'WPBACKITUP_PLUGINS_FOLDER', basename(WPBACKITUP_PLUGINS_PATH));
43
+
44
+ if( !defined( 'WPBACKITUP_THEMES_PATH' ) ) define( 'WPBACKITUP_THEMES_PATH', dirname(get_bloginfo('template_directory')));
45
+
46
+ if( !defined( 'WPBACKITUP_THEMES_FOLDER' ) ) define( 'WPBACKITUP_THEMES_FOLDER', basename(WPBACKITUP_THEMES_PATH));
lib/functions.php CHANGED
@@ -21,6 +21,10 @@ 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
 
@@ -81,6 +85,21 @@ function backup() {
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';
@@ -88,18 +107,28 @@ function restore_path() {
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() {
@@ -111,12 +140,23 @@ function logreader() {
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
  }
@@ -124,12 +164,13 @@ if(!function_exists('create_dir')) {
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);
@@ -138,40 +179,116 @@ if(!function_exists('recursive_copy')) {
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
  }
@@ -232,7 +349,7 @@ if(!function_exists('db_backup')) {
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 {
@@ -252,13 +369,124 @@ if(!function_exists('db_backup')) {
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) {
@@ -266,11 +494,70 @@ if(!function_exists('create_siteinfo')) {
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','.','..','._') ){
@@ -286,6 +573,7 @@ if(!function_exists('recursive_delete')){
286
  }
287
  }
288
  }
 
289
  @rmdir($dir);
290
  closedir($dh);
291
  }
@@ -330,8 +618,8 @@ 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;
@@ -385,5 +673,129 @@ function load_presstrends() {
385
  }
386
  }
387
  }
 
388
  // PressTrends WordPress Action
389
  add_action('admin_init', 'load_presstrends');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  include_once 'includes/recurse_zip.php';
22
  }
23
 
24
+ // include recursive iterator
25
+ if( !class_exists( 'RecursiveFilter_Iterator' ) ) {
26
+ include_once 'includes/RecursiveFilter_Iterator.php';
27
+ }
28
  // retrieve our license key from the DB
29
  $license_key = trim( $this->get_option( 'license_key' ) );
30
 
85
  }
86
  add_action('wp_ajax_backup', 'backup');
87
 
88
+ function deletefile()
89
+ {
90
+ $fileToDel = str_replace('deleteRow', '', $_POST['filed']);
91
+ $restore_path = WPBACKITUP_CONTENT_PATH .WPBACKITUP_BACKUP_FOLDER .'/' . $fileToDel;
92
+ _log('(functions.deletefile) Delete File:' . $restore_path);
93
+ if (unlink($restore_path))
94
+ echo 'deleted';
95
+ else
96
+ echo 'problem';
97
+ exit(0);
98
+ }
99
+
100
+ add_action('wp_ajax_deletefile', 'deletefile');
101
+
102
+
103
  //load restore_path function
104
  function restore_path() {
105
  include_once 'includes/restore_from_path.php';
107
  add_action('wp_ajax_restore_path', 'restore_path');
108
 
109
  //load download function
110
+ //function download() {
111
+ // if(glob(WPBACKITUP_DIRNAME . "/backups/*.zip")) {
112
+ // foreach (glob(WPBACKITUP_DIRNAME . "/backups/*.zip") as $file) {
113
+ // $filename = basename($file);
114
+ // echo 'Download your last backup:</br><a href="' .WPBACKITUP_URLPATH. '/backups/' .$filename .'">' .$filename .'</a>';
115
+ // }
116
+ // } else {
117
+ // echo 'No export file available for download. Please create one.';
118
+ // }
119
+ // die();
120
+ //}
121
+ //add_action('wp_ajax_download', 'download');
122
+
123
+ //Get Status Log
124
+ function getStatusLog() {
125
+ $log = WPBACKITUP_DIRNAME .'/logs/status.log';
126
+ if (file_exists($log)){
127
+ unlink($log);
128
  }
129
+ $fh = fopen($log, 'w') or die( "Can't write to log file" );
130
+ return $fh;
131
  }
 
132
 
133
  //load logreader function
134
  function logreader() {
140
  }
141
  add_action('wp_ajax_logreader', 'logreader');
142
 
143
+ //load status check function
144
+ function statusreader() {
145
+ $log = WPBACKITUP_DIRNAME .'/logs/restore_status.log';
146
+ if(file_exists($log) ) {
147
+ readfile($log);
148
+ }
149
+ die();
150
+ }
151
+ add_action('wp_ajax_statusreader', 'statusreader');
152
+
153
  //define create_dir function
154
  if(!function_exists('create_dir')) {
155
  function create_dir($dir) {
156
  if( !is_dir($dir) ) {
157
  @mkdir($dir, 0755);
158
  }
159
+ _log('(functions.create_dir) Directory created: ' .$dir);
160
  return true;
161
  }
162
  }
164
  //Define recusive_copy function
165
  if(!function_exists('recursive_copy')) {
166
  function recursive_copy($dir, $target_path, $ignore = array( 'cgi-bin','..','._' ) ) {
167
+ _log('(functions.recursive_copy) IGNORE:');
168
+ _log($ignore);
169
  if( is_dir($dir) ) { //If the directory exists
170
  if ($dh = opendir($dir) ) {
171
  while(($file = readdir($dh)) !== false) { //While there are files in the directory
172
  if ( !in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
173
+ if (!is_dir( $dir.$file ) ) {
 
174
  $fsrc = fopen($dir .$file,'r');
175
  $fdest = fopen($target_path .$file,'w+');
176
  $len = stream_copy_to_stream($fsrc,$fdest);
179
  } else { //If $file is a directory
180
  $destdir = $target_path .$file; //Modify the destination dir
181
  if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
182
+ _log('(functions.recursive_copy) Create Folder: ' .$destdir);
183
  @mkdir($destdir, 0755);
184
+ }
185
  recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
186
  }
187
  }
188
  }
189
  closedir($dh);
190
  }
191
+ }
192
+ _log('(functions.recursive_copy) Recursive FROM: ' .$dir);
193
+ _log('(functions.recursive_copy) Recursive Copy TO: '.$target_path);
194
  return true;
195
  }
196
  }
197
 
198
+ //Generate SQL to rename existing WP tables.
199
+ if(!function_exists('db_rename_wptables')) {
200
+ function db_rename_wptables($sql_file_path,$table_prefix) {
201
+ _log('(db_rename_wptables)Manually Create SQL Backup File:'.$sql_file_path);
202
 
203
+ $db_name = DB_NAME;
204
+ $db_user = DB_USER;
205
+ $db_pass = DB_PASSWORD;
206
+ $db_host = DB_HOST;
207
 
208
+ //Get a connection to the DB
209
+ $mysqli = new mysqli($db_host , $db_user , $db_pass , $db_name) ;
210
+ if (mysqli_connect_errno()) {
211
+ return false;
212
+ }
213
+
214
+ $tables = array() ;
215
+
216
+ // Exploring what tables this database has
217
+ $sql = "SHOW TABLES WHERE `Tables_in_" .DB_NAME ."` NOT LIKE 'save_%'";
218
+ $result = $mysqli->query($sql);
219
+
220
+ // Cycle through "$result" and put content into an array
221
+ while ($row = $result->fetch_row()) {
222
+ $tables[] = $row[0] ;
223
+ }
224
+
225
+ // Close the connection
226
+ $mysqli->close() ;
227
 
228
+ // Cycle through each table
229
+ $firstPass=true;
230
+ foreach($tables as $table) {
231
+ $source_table=$table;
232
+ $target_table='save_'. $source_table;
233
+
234
+ if($firstPass){
235
+ $firstPass=false;
236
+
237
+ // Script Header Information
238
+ $return = '';
239
+ $return .= "--\n";
240
+ $return .= "-- WP Backitup Rename WP Tables \n";
241
+ $return .= "--\n";
242
+ $return .= '-- Created: ' . date("Y/m/d") . "\n";
243
+ $return .= "--\n";
244
+ $return .= "-- Database : " . $db_name . "\n";
245
+ $return .= "--\n";
246
+ $return .= "-- --------------------------------------------------\n";
247
+ $return .= "-- ---------------------------------------------------\n";
248
+ $return .= 'SET AUTOCOMMIT = 0 ;' ."\n" ;
249
+ $return .= "--\n" ;
250
+ $return .= 'RENAME TABLE '. "\n";
251
  }
252
+ else{
253
+ $return .= "\n" . ',';
254
+ }
255
+
256
+ $return .= '`'.$source_table.'` TO `' . $target_table . '` ';
257
+ }
258
+
259
+ $return .=';' . "\n" ;
260
+ $return .= 'COMMIT ; ' . "\n" ;
261
+ $return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ;
262
+
263
+ //save file if there were any tables in the database
264
+ if (count($tables)>0){
265
+ $handle = fopen($sql_file_path,'w+');
266
+ fwrite($handle,$return);
267
+ fclose($handle);
268
+ _log('(db_rename_wptables)SQL Backup File Created:' .$sql_file_path);
269
+ }
270
+
271
+ if (!file_exists($sql_file_path)){
272
+ _log('(db_rename_wptables) SQL file doesnt exist: ' .$sql_file_path);
273
+ return false;
274
  }
275
 
276
+ return true;
277
+ }
278
+ }
279
+
280
+
281
+ //Define DB backup function
282
+ if(!function_exists('db_backup')) {
283
+ function db_backup($sql_file_path) {
284
+ _log('(functions.db_backup)Manually Create SQL Backup File:'.$sql_file_path);
285
+
286
+ $db_name = DB_NAME;
287
+ $db_user = DB_USER;
288
+ $db_pass = DB_PASSWORD;
289
+ $db_host = DB_HOST;
290
+
291
+ $mysqli = new mysqli($db_host , $db_user , $db_pass , $db_name) ;
292
  if (mysqli_connect_errno()) {
293
  return false;
294
  }
349
  $return.= 'INSERT INTO '.$table.' VALUES(';
350
  for($j=0; $j<$num_fields; $j++){
351
  $rowdata[$j] = addslashes($rowdata[$j]);
352
+ $rowdata[$j] = str_replace("\n","\\n",$rowdata[$j]);
353
  if (isset($rowdata[$j])) {
354
  $return.= '"'.$rowdata[$j].'"' ;
355
  } else {
369
  $return .= 'SET AUTOCOMMIT = 1 ; ' . "\n" ;
370
 
371
  //save file
372
+ $handle = fopen($sql_file_path,'w+');
373
  fwrite($handle,$return);
374
  fclose($handle);
375
+
376
+ //Did the export work
377
+ $file_size = filesize($sql_file_path);
378
+ if(empty($file_size)) {
379
+ _log('(functions.db_backup) Failure: SQL Export file was empty.');
380
+ return false;
381
+ }
382
+
383
+ _log('(functions.db_backup)SQL Backup File Created:'.$sql_file_path);
384
  return true;
385
  }
386
  }
387
 
388
+ if(!function_exists('db_SQLDump')) {
389
+ function db_SQLDump($sql_file_path) {
390
+
391
+ _log('(functions.db_SQLDump) SQL Dump: ' .$sql_file_path);
392
+
393
+ $db_name = DB_NAME;
394
+ $db_user = DB_USER;
395
+ $db_pass = DB_PASSWORD;
396
+ $db_host = DB_HOST;
397
+
398
+ //This is to ensure that exec() is enabled on the server
399
+ if(exec('echo EXEC') == 'EXEC') {
400
+ try {
401
+ $process = 'mysqldump';
402
+ //exec($process.' --user='.$db_user.' --password='.$db_pass.' --host='.$db_host.' '.$db_name.' > "'.$path_sql .'"');
403
+ $command = $process
404
+ . ' --host=' . $db_host
405
+ . ' --user=' . $db_user
406
+ . ' --password=' . $db_pass
407
+ . ' ' . $db_name
408
+ . ' > "' . $sql_file_path .'"';
409
+
410
+ $output = shell_exec($command);
411
+ _log('(functions.db_SQLDump) shell execute output:');
412
+ _log($output);
413
+
414
+ //Did the export work
415
+ $file_size = filesize($sql_file_path);
416
+ if(empty($file_size)) {
417
+ _log('(functions.db_SQLDump) Failure: Dump was empty.');
418
+ return false;
419
+ }
420
+ } catch(Exception $e) {
421
+ _log('(functions.db_SQLDump) Exception: ' .$e);
422
+ return false;
423
+ }
424
+ }
425
+ else
426
+ {
427
+ _log('(functions.db_SQLDump) Failure: Exec() disabled.');
428
+ return false;
429
+ }
430
+
431
+ _log('(functions.db_SQLDump) SQL Dump completed.');
432
+ return true;
433
+ }
434
+ }
435
+ //define db_import function
436
+ if(!function_exists('db_run_sql')) {
437
+ function db_run_sql($sql_file) {
438
+ $file_size = filesize($sql_file);
439
+ _log('(functions.db_import)SQL Execute:' .$sql_file);
440
+
441
+ //Is the backup sql file empty
442
+ if(empty($file_size)) {
443
+ _log('(functions.db_import) Failure: SQL File was empty:' .$sql_file);
444
+ return false;
445
+ }
446
+
447
+ //This is to ensure that exec() is enabled on the server
448
+ if(exec('echo EXEC') != 'EXEC') {
449
+ _log('(functions.db_SQLDump) Failure: Exec() disabled.');
450
+ return false;
451
+ }
452
+
453
+ try {
454
+
455
+ $db_name = DB_NAME;
456
+ $db_user = DB_USER;
457
+ $db_pass = DB_PASSWORD;
458
+ $db_host = DB_HOST;
459
+
460
+ //Are you in test mode - this should be in the wp-config
461
+ // if(!defined('DB_NAME_TESTDB' ) ) define( 'DB_NAME_TESTDB', '' );
462
+ // if(!empty(DB_NAME_TESTDB)) {
463
+ // $db_name=DB_NAME_TESTDB;
464
+ // _log('(functions.db_import) Test Database:' .$db_name);
465
+ // }
466
+
467
+ $process = 'mysql';
468
+ $command = $process
469
+ . ' --host=' . $db_host
470
+ . ' --user=' . $db_user
471
+ . ' --password=' . $db_pass
472
+ . ' --database=' . $db_name
473
+ . ' --execute="SOURCE ' . $sql_file .'"';
474
+
475
+ $output = shell_exec($command);
476
+ _log('(functions.db_import) shell execute output:');
477
+ _log($output);
478
+
479
+ }catch(Exception $e) {
480
+ _log('(functions.db_import) Exception: ' .$e);
481
+ return false;
482
+ }
483
+
484
+ //Success
485
+ _log('(functions.db_import)SQL Executed successfully:' .$sql_file);
486
+ return true;
487
+ }
488
+ }
489
+
490
  //Define the create_siteinfo function
491
  if(!function_exists('create_siteinfo')) {
492
  function create_siteinfo($path, $table_prefix) {
494
  $handle = fopen($siteinfo, 'w+');
495
  $entry = site_url( '/' ) ."\n$table_prefix";
496
  fwrite($handle, $entry);
497
+ fclose($handle);
498
+ _log('(funtions.create_siteinfo) Site Info created:'.$siteinfo);
499
  return true;
500
  }
501
  }
502
 
503
+ if(!function_exists('delete_allbutzips')){
504
+ function delete_allbutzips($dir){
505
+ $ignore = array('cgi-bin','.','..','._');
506
+ if( is_dir($dir) ){
507
+ if($dh = opendir($dir)) {
508
+ while( ($file = readdir($dh)) !== false ) {
509
+ $ext = pathinfo($file, PATHINFO_EXTENSION);
510
+ if (!in_array($file, $ignore) && substr($file, 0, 1) != '.' && $ext!="zip") { //Check the file is not in the ignore array
511
+ if(!is_dir($dir .'/'. $file)) {
512
+ unlink($dir .'/'. $file);
513
+ } else {
514
+ recursive_delete($dir.'/'. $file, $ignore);
515
+ }
516
+ }
517
+ }
518
+ }
519
+ @rmdir($dir);
520
+ closedir($dh);
521
+ }
522
+ _log('(funtions.delete_allbutzips) Delete all but zips completed:'.$dir);
523
+ return true;
524
+ }
525
+ }
526
+
527
+
528
+ //Recursively delete all children
529
+ if(!function_exists('delete_children_recursive')){
530
+ function delete_children_recursive($path, $ignore = array('cgi-bin','._'))
531
+ {
532
+ if (is_dir($path))
533
+ {
534
+ _log('(delete_children_recursive) Ignore:');
535
+ _log($ignore);
536
+ $iterator = new RecursiveDirectoryIterator($path);
537
+ $iterator->setFlags(RecursiveDirectoryIterator::SKIP_DOTS);
538
+ $filter = new RecursiveFilter_Iterator($iterator);
539
+ $filter->set_filter($ignore);
540
+
541
+ $all_files = new RecursiveIteratorIterator($filter,RecursiveIteratorIterator::CHILD_FIRST);
542
+
543
+ foreach ($all_files as $file)
544
+ {
545
+ if ($file->isDir())
546
+ {
547
+ _log('(delete_recursive_new) delete folder:'.$file);
548
+ rmdir($file->getPathname());
549
+ }
550
+ else
551
+ {
552
+ _log('(delete_recursive_new) delete file:'.$file);
553
+ unlink($file->getPathname());
554
+ }
555
+ }
556
+ }
557
+ return true;
558
+ }
559
+ }
560
+
561
  //Define recursive_delete function
562
  if(!function_exists('recursive_delete')){
563
  function recursive_delete($dir, $ignore = array('cgi-bin','.','..','._') ){
573
  }
574
  }
575
  }
576
+ _log('(functions.recursive_delete) Folder Deleted:' .$dir);
577
  @rmdir($dir);
578
  closedir($dh);
579
  }
618
  global $WPBackitup;
619
  if($WPBackitup->get_option( 'presstrends' ) == 'enabled') {
620
  // PressTrends Account API Key
621
+ $api_key = '7s4lfc8du5we4cjcdcw7wv3bedn596gjxmgy';
622
+ $auth = 'uu8dz66bqreltwdq66hjculnyqkkwofy5';
623
 
624
  // Start of Metrics
625
  global $wpdb;
673
  }
674
  }
675
  }
676
+
677
  // PressTrends WordPress Action
678
  add_action('admin_init', 'load_presstrends');
679
+
680
+ //Get Status Log
681
+ if(!function_exists('deleteDebugLog')){
682
+ function deleteDebugLog() {
683
+ $debugLog = WPBACKITUP_DIRNAME ."/logs/debug_" .$date .".log";
684
+ if (file_exists($debugLog)){
685
+ try{
686
+ unlink($debugLog);
687
+ } catch(Exception $e) {
688
+ //Dont do anything
689
+ }
690
+ }
691
+ }
692
+ }
693
+
694
+ //Get debug Log
695
+ if(!function_exists('getDebugLogFile')){
696
+ function getDebugLogFile() {
697
+ try {
698
+ if (WPBACKITUP_DEBUG===true){
699
+ //Check to see if File exists
700
+ $date = date_i18n('Y-m-d',current_time( 'timestamp' ));
701
+ $debugLog = WPBACKITUP_DIRNAME ."/logs/debug_" .$date .".log";
702
+ $dfh = fopen($debugLog, 'a');
703
+ return $dfh;
704
+ }
705
+ } catch(Exception $e) {
706
+ //Dont do anything
707
+ }
708
+ }
709
+ }
710
+
711
+ // //load logWriter function
712
+ if(!function_exists('_log')){
713
+ function _log($message) {
714
+ //Is debug ON
715
+ try{
716
+ if (WPBACKITUP_DEBUG===true){
717
+ $dfh = getDebugLogFile("upload"); //Get File
718
+ if (!is_null($dfh)){
719
+ $date = date_i18n('Y-m-d Hi:i:s',current_time( 'timestamp' ));
720
+ if( is_array( $message ) || is_object( $message ) ){
721
+ fwrite($dfh, $date ." " .print_r( $message, true ) . PHP_EOL);
722
+ } else {
723
+ fwrite($dfh, $date ." " .$message . PHP_EOL);
724
+ }
725
+ fclose($dfh);
726
+ }
727
+ }
728
+ } catch(Exception $e) {
729
+ //Dont do anything
730
+ }
731
+ }
732
+ }
733
+
734
+ // if(!function_exists('_log')){
735
+ // function _log( $message ) {
736
+ // $debuglog = WPBACKITUP_CONTENT_PATH .'debug.log';
737
+ // if( WPBACKITUP_DEBUG === true ){
738
+ // try{
739
+ // $dfh = fopen($debuglog,'w+');
740
+ // if( is_array( $message ) || is_object( $message ) ){
741
+ // //error_log( print_r( $message, true ) );
742
+ // fwrite($dfh,print_r( $message, true ));
743
+ // } else {
744
+ // fwrite($dfh,$message);
745
+ // }
746
+
747
+ // fclose($dfh);
748
+
749
+ // } catch(Exception $e) {
750
+ // //Dont do anything
751
+ // fclose($dfh);
752
+ // }
753
+ // }
754
+ // }
755
+ // }
756
+
757
+ //Log all the constants
758
+ if(!function_exists('_log_constants')){
759
+ function _log_constants() {
760
+ _log("**CONSTANTS**");
761
+ _log("WPBACKITUP_VERSION:" . WPBACKITUP_VERSION);
762
+ _log("WPBACKITUP_DIRNAME:" . WPBACKITUP_DIRNAME);
763
+ _log("WPBACKITUP_DIR_PATH:" . WPBACKITUP_DIRNAME);
764
+ _log("WPBACKITUP_CONTENT_PATH:" . WPBACKITUP_CONTENT_PATH);
765
+ _log("WPBACKITUP_BACKUP_FOLDER:" . WPBACKITUP_BACKUP_FOLDER);
766
+ _log("WPBACKITUP_RESTORE_FOLDER:" . WPBACKITUP_RESTORE_FOLDER);
767
+ _log("WPBACKITUP_URLPATH:" . WPBACKITUP_URLPATH);
768
+ _log("WPBACKITUP_BACKUPFILE_URLPATH:" . WPBACKITUP_BACKUPFILE_URLPATH );
769
+ _log("IS_AJAX_REQUEST:" . IS_AJAX_REQUEST );
770
+ _log("WPBACKITUP_SITE_URL:" . WPBACKITUP_SITE_URL );
771
+ _log("WPBACKITUP_ITEM_NAME:" . WPBACKITUP_ITEM_NAME );
772
+ _log("WPBACKITUP_PLUGIN_FOLDER:" . WPBACKITUP_PLUGIN_FOLDER );
773
+ _log("WPBACKITUP_SQL_DBBACKUP_FILENAME:" . WPBACKITUP_SQL_DBBACKUP_FILENAME);
774
+ _log("WPBACKITUP_SQL_TABLE_RENAME_FILENAME:" . WPBACKITUP_SQL_TABLE_RENAME_FILENAME);
775
+ _log("WPBACKITUP_PLUGINS_PATH:" . WPBACKITUP_PLUGINS_PATH);
776
+ _log("WPBACKITUP_PLUGINS_FOLDER:" . WPBACKITUP_PLUGINS_FOLDER);
777
+ _log("WPBACKITUP_THEMES_PATH:" . WPBACKITUP_THEMES_PATH);
778
+ _log("WPBACKITUP_THEMES_FOLDER:" . WPBACKITUP_THEMES_FOLDER);
779
+ _log("** END CONSTANTS**");
780
+ }
781
+ }
782
+
783
+ // if(!function_exists('redo_to_checkpoint')) {
784
+ // function redo_to_checkpoint($checkpoint) {
785
+
786
+ // if($checkpoint == "db")
787
+ // {
788
+ // if( glob($restoration_dir_path . "*.cur") ) {
789
+ // //collect connection information from form
790
+ // fwrite($fh, '<div class="database">In Progress</div>');
791
+ // include_once WP_DIR_PATH .'/wp-config.php';
792
+ // //Add user to DB in v1.0.5
793
+ // $user_id = $_POST['user_id'];
794
+ // //Connect to DB
795
+ // $output = db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc);
796
+ // }
797
+
798
+ // }
799
+
800
+ // }
801
+ // }
lib/includes/RecursiveFilter_Iterator.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * WP Backitup Recurse Iterator
4
+ *
5
+ * @package WP Backitup
6
+ *
7
+ * @author cssimmon
8
+ * @version 1.4.0
9
+ * @since 1.0.1
10
+ */
11
+
12
+
13
+ class RecursiveFilter_Iterator extends RecursiveFilterIterator {
14
+
15
+ private $filters=array();
16
+
17
+ //Set the ignore list
18
+ function set_filter ($ignore) {
19
+ $this->filters = $ignore;
20
+ }
21
+
22
+ public function accept() {
23
+ return !in_array(
24
+ $this->current()->getFilename(),
25
+ $this->filters,
26
+ true
27
+ );
28
+ }
29
+
30
+ }
lib/includes/backup.php CHANGED
@@ -1,104 +1,151 @@
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
+ //limit process to 15 minutes
3
+ @set_time_limit(900);
4
+
5
+ /**
6
+ * WP Backitup Backup Functions
7
+ *
8
+ * @package WP Backitup Pro
9
+ *
10
+ * @author cssimmon
11
+ * @version 1.4.2
12
+ * @since 1.0.1
13
+ */
14
+ /*** Includes ***/
15
+ // Define WP_DIR_PATH - required for constants include
16
+ if (!defined('WP_DIR_PATH')) define('WP_DIR_PATH',dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))));
17
+ include_once WP_DIR_PATH . '/wp-config.php';
18
+ include_once dirname(dirname( __FILE__ )) . '/constants.php';
19
+
20
+ /*** Globals ***/
21
+ global $WPBackitup;
22
+ $fileUTCDateTime=current_time( 'timestamp' );
23
+ $localDateTime = date_i18n('Y-m-d-Hi',$fileUTCDateTime);
24
+ $backup_project_dirname = get_bloginfo('name') .'-Export-' .$localDateTime;
25
+ $backup_project_path = WPBACKITUP_CONTENT_PATH .WPBACKITUP_BACKUP_FOLDER .'/'. $backup_project_dirname .'/';
26
+ $backup_folder_root = WPBACKITUP_CONTENT_PATH .WPBACKITUP_BACKUP_FOLDER .'/';
27
+ $restore_folder_root = WPBACKITUP_RESTORE_FOLDER;
28
+
29
+ //*****************//
30
+ //*** MAIN CODE ***//
31
+ //*****************//
32
+ deleteDebugLog();
33
+ _log('***BEGIN BACKUP.PHP***');
34
+ _log_constants();
35
+
36
+ //create status log file that is used in the UI
37
+ $fh = getStatusLog();
38
+
39
+ //Delete the contents of the existing backup directory
40
+ _log("Delete all files BUT zips: " .$backup_folder_root);
41
+ delete_allbutzips($backup_folder_root); //delete everything but old zips
42
+
43
+ //Re-create and empty backup dir
44
+ _log("Call Create Directory: " .$backup_folder_root);
45
+ if(!create_dir($backup_folder_root)) {
46
+ fwrite($fh, '<div class="prerequsites">0</div>');
47
+ fwrite($fh, '<div class="error101">1</div>');
48
+ fclose($fh);
49
+ die();
50
+ }
51
+
52
+ //Check to see if the directory is writeable
53
+ _log("Is folder writeable: " .$backup_folder_root);
54
+ if(!is_writeable($backup_folder_root)) {
55
+ fwrite($fh, '<div class="prerequsites">0</div>');
56
+ fwrite($fh, '<div class="error102">1</div>');
57
+ die();
58
+ } else {
59
+ //If the directory is writeable, create the backup folder if it doesn't exist
60
+ _log("Folder IS writeable: " .$backup_folder_root);
61
+ if( !is_dir($backup_project_path) ) {
62
+ _log("Create Backup Content Folder: " .$backup_project_path);
63
+ @mkdir($backup_project_path, 0755);
64
+ _log('Backup Content Folder Created:'.$backup_project_path);
65
+ }
66
+ //Why do we need to do this? - delete all zip files in backup folder
67
+ //foreach(glob($backup_folder_root ."*.zip") as $zip) {
68
+ // unlink($zip);
69
+ // _log('Zip file removed:'.$zip);
70
+ //}
71
+ fwrite($fh, '<div class="prerequisites">1</div>');
72
+ }
73
+
74
+ //Try MySQLDump First
75
+ _log('Create the SQL Backup File:'.$backup_project_path);
76
+ $sqlFileName=$backup_project_path . WPBACKITUP_SQL_DBBACKUP_FILENAME;
77
+ if(db_SQLDump($sqlFileName) ) {
78
+ fwrite($fh, '<div class="backupdb">1</div>');
79
+ } else {
80
+ //Try manual extract if mysqldump isnt working
81
+ if(db_backup($sqlFileName) ) {
82
+ fwrite($fh, '<div class="backupdb">1</div>');
83
+ } else {
84
+ fwrite($fh, '<div class="backupdb">0</div>');
85
+ fwrite($fh, '<div class="error104">1</div>');
86
+ recursive_delete($backup_project_path);
87
+ die();
88
+ }
89
+ }
90
+ _log('Created the SQL Backup File:'.$backup_project_path);
91
+
92
+ //Backup with copy
93
+ _log('Recursive Copy FROM:'.WPBACKITUP_CONTENT_PATH);
94
+ _log('Recursive Copy TO:'.$backup_project_path);
95
+ _log('Ignore:'.$backup_project_dirname);
96
+ _log('Ignore:'.$backup_folder_root);
97
+ _log('Ignore:'.$restore_folder_root);
98
+
99
+ if(recursive_copy(WPBACKITUP_CONTENT_PATH, $backup_project_path, $ignore = array( 'cgi-bin','.','..','._',WPBACKITUP_BACKUP_FOLDER,$backup_project_dirname,$restore_folder_root,'backupbuddy_backups','*.zip','cache' ) ) ) {
100
+ fwrite($fh, '<div class="backupfiles">1</div>');
101
+ } else {
102
+ fwrite($fh, '<div class="backupfiles">0</div>');
103
+ fwrite($fh, '<div class="error103">1</div>');
104
+ die();
105
+ }
106
+
107
+ //Create siteinfo in project dir
108
+ global $wpdb;
109
+ _log('Create Site Info:'.$backup_project_path);
110
+ if (!create_siteinfo($backup_project_path, $wpdb->prefix) ) {
111
+ fwrite($fh, '<div class="infofile">0</div>');
112
+ fwrite($fh, '<div class="error105">1</div>');
113
+ recursive_delete($backup_project_path);
114
+ die();
115
+ } else {
116
+ fwrite($fh, '<div class="infofile">1</div>');
117
+ }
118
+
119
+ //Zip the project dir
120
+ _log('Zip Up the Backup Folder:'.$backup_project_path);
121
+ $z = new recurseZip();
122
+ $src = rtrim($backup_project_path, '/');
123
+ $z->compress($src, $backup_folder_root);
124
+ fwrite($fh, '<div class="zipfile">1</div>');
125
+
126
+
127
+ //Delete backup dir
128
+ _log('Delete Backup Folder:'.$backup_project_path);
129
+ if(!recursive_delete($backup_project_path)) {
130
+ fwrite($fh, '<div class="cleanup">0</div>');
131
+ fwrite($fh, '<div class="error106">1</div>');
132
+ } else {
133
+ fwrite($fh, '<div class="cleanup">1</div>');
134
+ }
135
+
136
+ //close log file
137
+ fwrite($fh, '<div class="finalinfo">1</div>');
138
+ fclose($fh);
139
+
140
+ $response['file'] = basename($src) . '.zip';
141
+ //$response['CreateDate'] = date('F j, Y g:i a',strtotime($localDateTime));
142
+ $response['link'] = WPBACKITUP_BACKUPFILE_URLPATH . '/' . $backup_project_dirname . '.zip';
143
+
144
+ _log('Jason Response Values:');
145
+ _log(json_encode($response));
146
+
147
+ echo json_encode($response);
148
+
149
+ _log("*** END BACKUP.PHP ***");
150
+ die();
151
+ //End backup function
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,593 @@
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
+ @set_time_limit(900);// 15 minutes per image should be PLENTY
3
 
4
  /**
5
  * WP Backitup Restore Functions
6
  *
7
  * @package WP Backitup Pro
8
  *
9
+ * @author cssimmon
10
  * @version 1.4.0
11
  * @since 1.0.1
12
  */
13
 
14
+ /*** Includes ***/
15
+ // Define WP_DIR_PATH - required for constants include
16
+ if (!defined('WP_DIR_PATH')) define('WP_DIR_PATH',dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))));
17
+ include_once WP_DIR_PATH . '/wp-config.php';
18
+ include_once dirname(dirname( __FILE__ )) . '/constants.php';
19
+
20
+ /*** Globals ***/
21
+ $backup_folder_root = WPBACKITUP_CONTENT_PATH .WPBACKITUP_BACKUP_FOLDER .'/'; //wpbackitup_backups
22
+ $restore_folder_root = WPBACKITUP_CONTENT_PATH .WPBACKITUP_RESTORE_FOLDER .'/';//wpbackitup_restore
23
+ $backup_file_name; //name of the backup file
24
+ $backup_file_path; //full path to zip file on server
25
+
26
+ $inactive=0;
27
+ $active=1;
28
+ $complete=2;
29
+ $failure=-1;
30
+ $warning=-2;
31
+ $success=99;
32
+
33
+ //setup the status array
34
+ $status_array = array(
35
+ 'preparing' =>$inactive ,
36
+ 'unzipping' =>$inactive ,
37
+ 'validation'=>$inactive,
38
+ 'restore_point'=>$inactive,
39
+ 'database'=>$inactive,
40
+ 'wpcontent'=>$inactive,
41
+ 'cleanup'=>$inactive
42
+ );
43
+
44
+
45
+ //*****************//
46
+ //*** MAIN CODE ***//
47
+ //*****************//
48
+ deleteDebugLog();
49
+ _log('***BEGIN RESTORE.PHP***');
50
+ _log_constants();
51
+
52
+ //--Get form post values
53
+ $backup_file_name = $_POST['selected_file'];//Get the backup file name
54
+ if( $backup_file_name == '') {
55
+ write_fatal_error_status('error201');
56
+ die();
57
+ }
58
 
59
+ //Get user ID
60
+ $user_id = $_POST['user_id'];
61
+ if( $user_id == '') {
62
+ write_fatal_error_status('error201');
63
+ die();
64
+ }
65
 
66
+ set_status('preparing',$active,true);
67
 
68
+ //set path to backup file
69
+ $backup_file_path = $backup_folder_root .$backup_file_name ;
70
 
71
+ delete_restore_folder();
 
72
 
73
+ create_restore_folder($restore_folder_root);
74
+ set_status('preparing',$complete,false);
 
 
 
 
 
 
 
75
 
76
+ set_status('unzipping',$active,true);
77
+ unzip_backup($backup_file_path,$restore_folder_root);
78
+ set_status('unzipping',$complete,false);
79
 
80
+ set_status('validation',$active,true);
81
+ $restoration_dir_path=validate_restore_folder($restore_folder_root);
 
 
 
 
 
 
 
 
 
82
 
83
+ $backupSQLFile = $restoration_dir_path . WPBACKITUP_SQL_DBBACKUP_FILENAME;
84
+
85
+ validate_SQL_exists($restore_folder_root,$backupSQLFile);
86
+
87
+ $dbc = get_sql_connection($restoration_dir_path);
88
+
89
+ $siteurl = get_siteurl($dbc,$restoration_dir_path);
90
+
91
+ $homeurl = get_homeurl($dbc,$restoration_dir_path);
92
+
93
+ $user_login = get_user_login($dbc,$restoration_dir_path,$user_id );
94
+
95
+ $user_pass = get_user_pass($dbc,$restoration_dir_path,$user_id );
96
+
97
+ $user_email = get_user_email($dbc,$restoration_dir_path,$user_id);
98
+
99
+ //Collect previous backup site url start
100
+ _log('Get backupsiteinfo.txt values...');
101
+ $import_siteinfo_lines = file($restoration_dir_path .'backupsiteinfo.txt');
102
+ $import_siteurl = trim($import_siteinfo_lines[0]);
103
+ $current_siteurl = trim($siteurl ,'/');
104
+ $import_table_prefix = $import_siteinfo_lines[1];
105
+ _log($import_siteinfo_lines);
106
+
107
+ //Check table prefix values FATAL
108
+ if($table_prefix !=$import_table_prefix) {
109
+ _log('Error: Table prefix different from restore.');
110
+ write_warning_status('error221');
111
  }
112
 
113
+
114
+ //Create restore point for DB
115
+ set_status('validation',$complete,false);
116
+ set_status('restore_point',$active,true);
117
+ $RestorePoint_SQL = backup_database($backup_folder_root); //Save in backup folder
118
+
119
+ //create_table_rename_sql($restore_folder_root,$table_prefix);
120
+ //Rename the old tables - not sure i want to do this anymore
121
+ //$renameSQLFile = $restore_folder_root.WPBACKITUP_SQL_TABLE_RENAME_FILENAME;
122
+ //rename_SQL_tables($renameSQLFile);
123
+
124
+ set_status('restore_point',$complete,false);
125
+
126
+ //Import the backed up database
127
+ set_status('database',$active,true);
128
+ import_backedup_database($backupSQLFile);
129
+
130
+ //FAILURES AFTER THIS POINT SHOULD REQUIRE ROLLBACK OF DB
131
+ update_user_credentials($dbc,$restoration_dir_path,$import_table_prefix,$user_login,$user_pass,$user_email,$user_id);
132
+
133
+ update_siteurl($dbc,$restoration_dir_path,$import_table_prefix,$current_siteurl);
134
+
135
+ update_homeurl($dbc,$restoration_dir_path,$import_table_prefix,$homeurl);
136
+
137
+ //Done with DB restore
138
+ set_status('database',$complete,false);
139
+
140
+ //Disconnect database
141
+ mysqli_close($dbc);
142
+
143
+ //***DEAL WITH WPCONTENT NOW ***
144
+ set_status('wpcontent',$active,true);
145
+ delete_plugins_content(WPBACKITUP_PLUGINS_PATH,$restoration_dir_path);
146
+
147
+ delete_themes_content(WPBACKITUP_THEMES_PATH,$restoration_dir_path);
148
+
149
+ //delete whatever is left
150
+ $wpcontent_folder=WP_CONTENT_DIR;
151
+ delete_wpcontent_content($wpcontent_folder,$restoration_dir_path);
152
+
153
+ restore_wpcontent($restoration_dir_path);
154
+ set_status('wpcontent',$complete,false);
155
+
156
+ set_status('cleanup',$active,true);
157
+ cleanup_restore_folder($restoration_dir_path);
158
+ set_status('cleanup',$complete,false);
159
+ set_status_success();
160
+
161
+ _log('***END RESTORE.PHP***');
162
+ die();
163
+
164
+ /******************/
165
+ /*** Functions ***/
166
+ /******************/
167
+
168
+ //Get Status Log
169
+ function get_restore_Log() {
170
+ $log = WPBACKITUP_DIRNAME .'/logs/restore_status.log';
171
+ if (file_exists($log)){
172
+ unlink($log);
173
  }
174
+ $fh = fopen($log, 'w+') or die( "Can't write to log file" );
175
+ return $fh;
176
  }
177
 
178
+ function write_fatal_error_status($status_code) {
179
+ global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
180
+
181
+ //Find the active status and set to failure
182
+ foreach ($status_array as $key => $value) {
183
+ if ($value==$active){
184
+ $status_array[$key]=$failure;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  }
186
+ }
187
+
188
+ //Add failure to array
189
+ $status_array[$status_code]=$failure;
190
+ write_restore_status();
191
  }
192
 
193
+ function write_warning_status($status_code) {
194
+ global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
195
+
196
+ //Add warning to array
197
+ $status_array[$status_code]=$warning;
198
+ write_restore_status();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  }
200
 
201
+ function write_restore_status() {
202
+ global $status_array;
203
+ $fh=get_restore_Log();
204
+
205
+ foreach ($status_array as $key => $value) {
206
+ fwrite($fh, '<div class="' . $key . '">' . $value .'</div>');
 
 
 
 
 
 
 
207
  }
208
+ fclose($fh);
209
  }
210
 
211
+ function set_status($process,$status,$flush){
212
+ global $status_array;
213
+ $status_array[$process]=$status;
214
+
215
+ if ($flush) write_restore_status();
216
+ }
217
 
218
+ function set_status_success(){
219
+ global $status_array,$inactive,$active,$complete,$failure,$warning,$success;
220
+ global $active;
221
 
222
+ $status_array['finalinfo']=$success;
223
+ write_restore_status();
224
+ }
225
 
226
+ //Create an empty restore folder
227
+ function create_restore_folder($path) {
228
+ _log('Create restore folder:' .$path);
229
+ if(!create_dir($path)) {
230
+ _log('Error: Cant create restore folder :'. $path);
231
+ write_fatal_error_status('error222');
232
+ die();
233
+ }
234
+ _log('Restore folder created:' .$path);
235
  }
236
+
237
+ //Delete restore folder and contents
238
+ function delete_restore_folder() {
239
+ global $restore_folder_root;
240
+ //Delete the existing restore directory
241
+ _log('Delete existing restore folder:' .$restore_folder_root);
242
+ return recursive_delete($restore_folder_root);
243
+ _log('Existing restore folder deleted:' .$restore_folder_root);
244
  }
245
 
246
+ //Unzip the backup to the restore folder
247
+ function unzip_backup($backup_file_path,$restore_folder_root){
248
+ //unzip the upload
249
+ _log('Unzip the backup file source:' .$backup_file_path);
250
+ _log('Unzip the backup file target:' .$restore_folder_root);
251
+ $zip = new ZipArchive;
252
+ $res = $zip->open($backup_file_path);
253
+ if ($res === TRUE) {
254
+ $zip->extractTo($restore_folder_root);
255
+ $zip->close();
256
+ } else {
257
+ _log('Error: Cant unzip backup:'.$backup_file_path);
258
+ write_fatal_error_status('error203');
259
+ delete_restore_folder();
260
+ die();
261
+ }
262
+ _log('Backup file unzipped: ' .$restore_folder_root);
263
  }
264
 
265
+ //Validate the restore folder
266
+ function validate_restore_folder($restore_folder_root){
267
+ $restoration_dir_path='';
268
+
269
+ _log('Identify the restoration directory in restore folder: ' .$restore_folder_root.'*');
270
+ if ( count( glob( $restore_folder_root.'*', GLOB_ONLYDIR ) ) == 1 ) {
271
+ foreach( glob($restore_folder_root .'*', GLOB_ONLYDIR ) as $dir) {
272
+ $restoration_dir_path = $dir .'/';
273
+ }
274
+ }
275
+ _log('Restoration directory: ' .$restoration_dir_path);
276
+
277
+ //Validate the restoration
278
+ _log('Validate restoration directory: ' . $restoration_dir_path .'backupsiteinfo.txt');
279
+ if(!glob($restoration_dir_path .'backupsiteinfo.txt') ){
280
+ _log('Error: Restore directory INVALID: ' .$restoration_dir_path);
281
+ write_fatal_error_status('error204');
282
+ delete_restore_folder(); //delete the restore folder if bad
283
+ die();
284
+ }
285
+ _log('Restoration directory validated: ' .$restoration_dir_path);
286
+ return $restoration_dir_path;
287
  }
288
 
289
+ // Backup the current database try dump first
290
+ function backup_database($restore_folder_root){
291
+ $backup_file = $restore_folder_root . 'db-backup.cur';
292
+ _log('Backup the current database: ' .$backup_file);
293
+ if(!db_SQLDump($backup_file)) {
294
+ //Try a manual restore since dump didnt work
295
+ if(!db_backup($backup_file)) {
296
+ _log('Error: Cant backup database:'.$backup_file);
297
+ write_fatal_error_status('error205');
298
+ delete_restore_folder();
299
+ die();
300
+ }
301
  }
302
+ _log('Current database backed up: ' .$backup_file);
303
+ return $backup_file;
304
  }
305
 
306
+ //Generate a script to rename the tables
307
+ function create_table_rename_sql($restore_folder_root,$table_prefix){
308
+ $sql_file_path= $restore_folder_root .'db-rename-tables.sql';
309
+ _log('Generate a script to rename the tables.' .$sql_file_path);
310
+ if(!db_rename_wptables($sql_file_path,$table_prefix)) {
311
+ _log('Error: Cant generate rename script:'.$sql_file_path);
312
+ write_fatal_error_status('error205');
313
+ delete_restore_folder();
314
+ die();
315
+ }
316
+ _log('SQL Script to rename tables generated.' .$sql_file_path);
317
  }
318
 
319
+ //Make sure there IS a backup to restore
320
+ function validate_SQL_exists($restore_folder_root,$backupSQLFile){
321
+ _log('Check for database backup file:' . $backupSQLFile);
322
+
323
+ if(!file_exists($backupSQLFile) && !empty($backupSQLFile)) {
324
+ _log('Error: NO Database backups in backup.');
325
+ write_fatal_error_status('error216');
326
+ delete_restore_folder();
327
+ die();
328
+ }
329
+ _log('Database backup file exist:' . $backupSQLFile);
330
  }
331
 
332
+ //Get SQL Connection
333
+ function get_sql_connection($restoration_dir_path){
 
 
 
 
 
 
 
334
  //Connect to DB
335
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
336
  if ( !$dbc ) {
337
+ _log('Error: Cant connect to database.');
338
+ write_fatal_error_status('error206');
339
+ delete_restore_folder();
 
 
340
  die();
341
  }
342
+ return $dbc;
343
+ }
344
 
345
+ //Get SQL scalar value
346
+ function get_sql_scalar($dbc,$sql){
347
+ $value='';
348
+ if ($result = mysqli_query($dbc, $sql)) {
349
  while ($row = mysqli_fetch_row($result)) {
350
+ $value = $row[0];
351
  }
352
  mysqli_free_result($result);
353
+ }
354
+ return $value;
355
+ }
356
+
357
+ //Run SQL command
358
+ function run_SQL_command($dbc, $sql){
359
+ if(!mysqli_query($dbc, $sql) ) {
360
+ _log('Error:SQL Command Failed:' .$sql);
361
+ return false;
362
+ }
363
+ return true;
364
+ }
365
+
366
+ //Rename the existing tables to have the save_ prefix
367
+ function rename_SQL_tables($renameSQLFile){
368
+ _log('Rename existing tables to contain save_ prefix:' .$renameSQLFile);
369
+ if(!db_run_sql($renameSQLFile)) {
370
+ _log('Error: Table rename error.');
371
+ write_fatal_error_status('error205');
372
+ delete_restore_folder();
373
+ die();
374
  }
375
+ _log('Tables renamed to contain save_ prefix.');
376
+ }
377
 
378
+ //Restore DB
379
+ function restore_database(){
380
+ global $RestorePoint_SQL;
381
+ _log('Restore the DB to previous state.' . $RestorePoint_SQL);
382
+ if(!db_run_sql($RestorePoint_SQL)) {
383
+ _log('Error: Database could not be restored.' .$RestorePoint_SQL);
384
+ write_fatal_error_status('error223');
385
+ delete_restore_folder();
386
+ die();
387
+ }
388
+ write_fatal_error_status('error224');
389
+ _log('Database restored to previous state.');
390
+ }
391
+
392
+ //Run DB restore
393
+ function import_backedup_database($backupSQLFile){
394
+ _log('Import the backed up database.');
395
+ if(!db_run_sql($backupSQLFile)) {
396
+ _log('Error: Database import error.');
397
+ write_fatal_error_status('error212');
398
+ delete_restore_folder();
399
+ die();
400
+ }
401
+ _log('Backed up database imported.');
402
+ }
403
+
404
+ //get siteurl
405
+ function get_siteurl($dbc,$restoration_dir_path){
406
+ global $table_prefix;
407
+ $sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='siteurl';";
408
+ $siteurl = get_sql_scalar($dbc,$sql);
409
+ if (empty($siteurl)) {
410
+ _log('Error: Siteurl not found.');
411
+ write_fatal_error_status('error207');
412
+ mysqli_close($dbc);
413
+ delete_restore_folder();
414
  die();
415
  }
416
+ _log('Siteurl found.');
417
+ return $siteurl;
418
+ }
419
 
420
+ //get homeurl
421
+ function get_homeurl($dbc,$restoration_dir_path){
422
+ global $table_prefix;
423
+ $sql = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='home';";
424
+ $homeurl = get_sql_scalar($dbc,$sql);
425
+ if (empty($homeurl)) {
426
+ _log('Error: Homeurl not found.');
427
+ write_fatal_error_status('error208');
428
+ mysqli_close($dbc);
429
+ delete_restore_folder();
430
+ die();
431
+ }
432
+ _log('homeurl found.');
433
+ return $homeurl;
434
+ }
435
+
436
+ //get user login
437
+ function get_user_login($dbc,$restoration_dir_path,$user_id ){
438
+ global $table_prefix;
439
+ $sql = "SELECT user_login FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
440
+ $user_login = get_sql_scalar($dbc,$sql);
441
+ if (empty($user_login)) {
442
+ _log('Error: user_login not found.');
443
+ write_fatal_error_status('error209');
444
+ mysqli_close($dbc);
445
+ delete_restore_folder();
446
  die();
447
  }
448
+ _log('user_login found.');
449
+ return $user_login;
450
+ }
451
 
452
+ //get user pass
453
+ function get_user_pass($dbc,$restoration_dir_path,$user_id ){
454
+ global $table_prefix;
455
+ $sql = "SELECT user_pass FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
456
+ $user_pass = get_sql_scalar($dbc,$sql);
457
+ if (empty($user_pass)) {
458
+ _log('Error: user_pass not found.');
459
+ write_fatal_error_status('error210');
460
+ mysqli_close($dbc);
461
+ delete_restore_folder();
 
 
462
  die();
463
  }
464
+ _log('user_pass found.');
465
+ return $user_pass;
466
+ }
467
 
468
+ //get user email
469
+ function get_user_email($dbc,$restoration_dir_path,$user_id ){
470
+ global $table_prefix;
471
+ $sql = "SELECT user_email FROM ". $table_prefix ."users WHERE ID=" .$user_id ."";
472
+ $user_email = get_sql_scalar($dbc,$sql);
473
+ if (empty($user_email)) {
474
+ _log('Error: user_email not found.');
475
+ write_fatal_error_status('error211');
476
+ mysqli_close($dbc);
477
+ delete_restore_folder();
 
 
478
  die();
479
  }
480
+ _log('user_email found.');
481
+ return $user_email;
482
+ }
483
 
484
+ //Update user crentials
485
+ function update_user_credentials($dbc,$restoration_dir_path,$table_prefix,$user_login,$user_pass,$user_email,$user_id){
486
+ $sql = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
487
+ if (!run_SQL_command($dbc, $sql)){
488
+ _log('Error: User Credential database update failed..');
489
+ write_warning_status('error215');
490
+ mysqli_close($dbc);
491
+ restore_database();
492
+ delete_restore_folder();
 
 
 
493
  die();
494
  }
495
+ _log('User Credential updated in database.');
496
+ }
497
 
498
+ //update the site URL in the restored database
499
+ function update_siteurl($dbc,$restoration_dir_path,$table_prefix,$current_siteurl){
500
+ $sql = "UPDATE ". $table_prefix ."options SET option_value='" .$current_siteurl ."' WHERE option_name='siteurl'";
501
+ if (!run_SQL_command($dbc, $sql)){
502
+ _log('Error: SiteURL updated failed.');
503
+ write_warning_status('error213');
504
+ mysqli_close($dbc);
505
+ restore_database();
506
+ delete_restore_folder();
507
  die();
508
  }
509
+ _log('SiteURL updated in database.');
510
+ }
511
+
512
+ //Update homeURL
513
+ function update_homeurl($dbc,$restoration_dir_path,$table_prefix,$homeurl){
514
+ $sql = "UPDATE ". $table_prefix ."options SET option_value='" .$homeurl ."' WHERE option_name='home'";
515
+ if (!run_SQL_command($dbc, $sql)){
516
+ _log('Error: HomeURL database update failed..');
517
+ write_warning_status('error214');
518
+ mysqli_close($dbc);
519
+ restore_database();
520
+ delete_restore_folder();
521
  die();
522
  }
523
+ _log('HomeURL updated in database.');
524
+ }
525
+
526
+ //Delete wp-content content
527
+ function delete_wpcontent_content($root_folder,$restoration_dir_path){
528
+ _log('Delete the wp_content contents:' .$root_folder);
529
+ $ignore = array( 'cgi-bin','._', WPBACKITUP_PLUGIN_FOLDER,WPBACKITUP_RESTORE_FOLDER,WPBACKITUP_BACKUP_FOLDER,WPBACKITUP_THEMES_FOLDER, WPBACKITUP_PLUGINS_FOLDER,'debug.log');
530
+ if(!delete_children_recursive($root_folder,$ignore)) {
531
+ _log('Error: Cant delete WPContent:' .$root_folder);
532
+ write_warning_status('error217');
533
+ restore_database();
534
+ delete_restore_folder();
535
  die();
536
  }
537
+ _log('wp-content has been deleted:' .$root_folder);
 
 
538
  }
539
 
540
+ //Delete plugins content
541
+ function delete_plugins_content($plugins_folder,$restoration_dir_path){
542
+ _log('Delete the plugins contents:' .$plugins_folder);
543
+ $ignore = array( 'cgi-bin','._', WPBACKITUP_PLUGIN_FOLDER,WPBACKITUP_RESTORE_FOLDER,WPBACKITUP_BACKUP_FOLDER);
544
+ if(!delete_children_recursive($plugins_folder,$ignore)) {
545
+ _log('Error: Cant delete old WPContent:' .$plugins_folder );
546
+ write_warning_status('error217');
547
+ restore_database();
548
+ delete_restore_folder();
549
+ die();
550
+ }
551
+ _log('Plugins content deleted:' .$plugins_folder);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
552
  }
553
 
 
 
 
 
 
 
 
554
 
555
+ //Delete themes content
556
+ function delete_themes_content($themes_folder,$restoration_dir_path){
557
+ _log('Delete the themes contents:' .$themes_folder);
558
+ $ignore=array( 'cgi-bin','._', WPBACKITUP_PLUGIN_FOLDER,WPBACKITUP_RESTORE_FOLDER,WPBACKITUP_BACKUP_FOLDER,'debug.log' );
559
+ if(!delete_children_recursive($themes_folder , $ignore)) {
560
+ _log('Error: Cant delete old WPContent:' .$themes_folder );
561
+ write_warning_status('error217');
562
+ restore_database();
563
+ delete_restore_folder();
564
+ die();
565
+ }
566
+ _log('Themes content deleted:' .$themes_folder);
567
+ }
568
 
569
+ //Restore all wp content from zip
570
+ function restore_wpcontent($restoration_dir_path){
571
+ _log('Copy content folder from:' .$restoration_dir_path);
572
+ _log('Copy content folder to:' .WP_CONTENT_DIR);
573
+ $ignore = array( 'cgi-bin', '.', '..','._', WPBACKITUP_PLUGIN_FOLDER, 'status.log','debug.log', WPBACKITUP_SQL_DBBACKUP_FILENAME, 'backupsiteinfo.txt');
574
+ if(!recursive_copy($restoration_dir_path,WP_CONTENT_DIR. '/',$ignore)) {
575
+ _log('Error: Content folder was not copied successfully');
576
+ write_warning_status('error219');
577
+ restore_database();
578
+ delete_restore_folder();
579
+ die();
580
+ }
581
+ _log('Content folder copied successfully');
582
+ }
583
 
584
+ //Delete the restoration directory
585
+ function cleanup_restore_folder($restoration_dir_path){
586
+ _log('Cleanup the restore folder: ' .$restoration_dir_path);
587
+ if(!delete_restore_folder()) {
588
+ _log('Error: Cleanup restore folder failed: ' .$restoration_dir_path);
589
+ write_warning_status('error220'); //NOT fatal
590
+ } else {
591
+ _log('Restore folder cleaned successfully: ' .$restoration_dir_path);
592
+ }
593
+ }
lib/includes/restore_from_path.php DELETED
@@ -1,360 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * WP Backitup Restore Functions
5
- *
6
- * @package WP Backitup
7
- *
8
- * @author jcpeden
9
- * @version 1.4.0
10
- * @since 1.0.1
11
- */
12
-
13
-
14
- //define constants
15
- if( !defined( 'WP_DIR_PATH' ) ) define( 'WP_DIR_PATH', dirname ( dirname ( dirname ( dirname ( dirname ( dirname ( __FILE__ ) ) ) ) ) ) );
16
-
17
- if( !defined( 'WPBACKITUP_DIR_PATH' ) ) define( 'WPBACKITUP_DIR_PATH', dirname( dirname( dirname( __FILE__ ) ) ) );
18
-
19
- if( !defined( 'WPBACKITUP_DIRNAME' ) ) define( 'WPBACKITUP_DIRNAME', basename(WPBACKITUP_DIR_PATH) );
20
-
21
- if( !defined( 'WP_CONTENT_PATH' ) ) define( 'WP_CONTENT_PATH', dirname( dirname( WPBACKITUP_DIR_PATH ) ) ) ;
22
-
23
-
24
- //create log file
25
- $log = WPBACKITUP_DIR_PATH .'/backups/status.log';
26
- $fh = fopen($log, 'w') or die( "Can't open file" );
27
- echo '<ul>';
28
-
29
- // 15 minutes per image should be PLENTY
30
- @set_time_limit(900);
31
-
32
- //define create_dir function
33
- if(!function_exists('create_dir')) {
34
- function create_dir($dir) {
35
- if( !is_dir($dir) ) {
36
- @mkdir($dir, 0755);
37
- }
38
- return true;
39
- }
40
- }
41
-
42
- //Define recusive_copy function
43
- if(!function_exists('recursive_copy')) {
44
- function recursive_copy($dir, $target_path, $ignore = array( 'cgi-bin','..','._' ) ) {
45
- if( is_dir($dir) ) { //If the directory exists
46
- if ($dh = opendir($dir) ) {
47
- while(($file = readdir($dh)) !== false) { //While there are files in the directory
48
- if ( !in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
49
- if (!is_dir( $dir.$file ) ) {
50
- //Copy files to destination directory
51
- //echo 'Copying ' .$dir .$file . ' to ' .$target_path .$file .'<br />';
52
- $fsrc = fopen($dir .$file,'r');
53
- $fdest = fopen($target_path .$file,'w+');
54
- $len = stream_copy_to_stream($fsrc,$fdest);
55
- fclose($fsrc);
56
- fclose($fdest);
57
- } else { //If $file is a directory
58
- $destdir = $target_path .$file; //Modify the destination dir
59
- if(!is_dir($destdir)) { //Create the destdir if it doesn't exist
60
- @mkdir($destdir, 0755);
61
- }
62
- recursive_copy($dir .$file .'/', $target_path .$file .'/', $ignore);
63
- }
64
- }
65
- }
66
- closedir($dh);
67
- }
68
- }
69
- return true;
70
- }
71
- }
72
-
73
- //Define recursive_delete function
74
- if(!function_exists('recursive_delete')){
75
- function recursive_delete($dir, $ignore = array('cgi-bin','.','..','._') ){
76
- if( is_dir($dir) ){
77
- if($dh = opendir($dir)) {
78
- while( ($file = readdir($dh)) !== false ) {
79
- if (!in_array($file, $ignore) && substr($file, 0, 1) != '.') { //Check the file is not in the ignore array
80
- if(!is_dir($dir .'/' .$file)) {
81
- //echo 'Deleting ' .$dir .'/' .$file '<br />';
82
- unlink($dir .'/' .$file);
83
- } else {
84
- recursive_delete($dir .'/' .$file, $ignore);
85
- }
86
- }
87
- }
88
- }
89
- @rmdir($dir);
90
- closedir($dh);
91
- }
92
- return true;
93
- }
94
- }
95
-
96
- //define db_import function
97
- if(!function_exists('db_import')) {
98
- function db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc) {
99
- global $wpdb;
100
- $sql_files = glob($restoration_dir_path . "*.sql");
101
- foreach($sql_files as $sql_file) {
102
- $templine = ''; // Temporary variable, used to store current query
103
- $lines = file($sql_file); // Read in entire file
104
- foreach ($lines as $line) { // Loop through each line
105
- if (substr($line, 0, 2) == '--' || $line == '') continue; // Skip it if it's a comment
106
- $templine .= $line; // Add this line to the current segment
107
- if (substr(trim($line), -1, 1) == ';') { // If it has a semicolon at the end, it's the end of the query
108
- //replace imported site url with current site url
109
- if( strstr( trim($templine), trim($import_siteurl) ) == TRUE ) //If import site url is found
110
- $templine = str_replace( trim($import_siteurl), trim($current_siteurl), $templine ); // Replace import site url with current site url
111
- //if the table prefixes are different, replace the imported site prefixes with the current prefixes
112
- if ($table_prefix != $import_table_prefix) {
113
- if( strstr( trim($templine), trim($import_table_prefix) ) == TRUE ) //If import table prefix is found
114
- $templine = str_replace( trim($import_table_prefix), trim($table_prefix), $templine ); // Replace import site table prefix with current site table prefix
115
- }
116
- // Perform the query
117
- if( mysqli_query($dbc, $templine) === FALSE)
118
- print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
119
- $templine = ''; // Reset temp variable to empty
120
- }
121
- }
122
- }
123
- return true;
124
- }
125
- }
126
-
127
- //Delete any zips in the upload directory first
128
- foreach (glob(WPBACKITUP_DIR_PATH .'/backups/' .'*.zip') as $file) {
129
- unlink($file);
130
- }
131
-
132
- //Move the uploaded zip to the restoration directory
133
- $restore_file_name = $_GET['name'];
134
-
135
- $orig_file_name = WP_DIR_PATH . "/wp-content/uploads/" . $_GET['name'];
136
- if( $restore_file_name == '') {
137
- echo '<li class="error">No file selected<li></ul>' ;
138
- fclose($fh);
139
- die();
140
- } else {
141
- echo '<li>Uploading restoration file...' ;
142
- }
143
-
144
- $restore_path = WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name;
145
- if(copy($orig_file_name, $restore_path)) {
146
- echo "Done!</li>";
147
- } else {
148
- echo '</li><li class="error">Your file could not be uploaded</li></ul>';
149
- fclose($fh);
150
- die();
151
- }
152
-
153
- //Unzip the uploaded restore file
154
- echo "<li>Unzipping...";
155
- //include recurse_zip.php
156
- include_once 'recurse_zip.php';
157
- //unzip the upload
158
- $zip = new ZipArchive;
159
- $res = $zip->open(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
160
- if ($res === TRUE) {
161
- $zip->extractTo(WPBACKITUP_DIR_PATH .'/backups/');
162
- $zip->close();
163
- echo 'Done!</li>';
164
- } else {
165
- echo '</li><li class="error">Your restoration file could not be unzipped.</li></ul>';
166
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
167
- fclose($fh);
168
- die();
169
- }
170
-
171
- //Identify the restoration directory
172
- echo '<li>Validating zip...' ;
173
- if ( count( glob( WPBACKITUP_DIR_PATH .'/backups/*', GLOB_ONLYDIR ) ) == 1 ) {
174
- foreach( glob(WPBACKITUP_DIR_PATH .'/backups/*', GLOB_ONLYDIR ) as $dir) {
175
- $restoration_dir_path = $dir .'/';
176
- }
177
- }
178
-
179
- //Validate the restoration
180
- if(glob($restoration_dir_path .'backupsiteinfo.txt') ){
181
- echo 'Done!</li>';
182
- } else {
183
- echo '</li><li class="error">Your zip file appears to be invalid. Please ensure you chose the correct zip file.</li></ul>';
184
- recursive_delete($restoration_dir_path);
185
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
186
- fclose($fh);
187
- die();
188
- }
189
-
190
- //Restore wp-content directories
191
- echo "<li>Restoring wp-content directory..." ;
192
- if(!recursive_delete(WP_CONTENT_PATH, array( 'cgi-bin','.','..','._', WPBACKITUP_DIRNAME ))) {
193
- echo '</li><li class="error">Unable to remove existing wp-content directory for import. Please check your CHMOD settings in /wp-content/.</li></ul>';
194
- recursive_delete($restoration_dir_path);
195
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
196
- fclose($fh);
197
- die();
198
- }
199
- if(!create_dir(WP_CONTENT_PATH)) {
200
- echo '</li><li class="error">Unable to create new wp-content directory for import. Please check your CHMOD settings in /wp-content/.</li></ul>';
201
- recursive_delete($restoration_dir_path);
202
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
203
- fclose($fh);
204
- die();
205
- }
206
- if(recursive_copy($restoration_dir_path, WP_CONTENT_PATH .'/', array( 'cgi-bin', '.', '..','._', $restore_file_name, 'status.log', 'db-backup.sql', 'backupsiteinfo.txt')) ) {
207
- echo 'Done!</li>';
208
- } else {
209
- echo '</li><li class="error">Unable to import wp-content. Please try again.</li></ul>';
210
- recursive_delete($restoration_dir_path);
211
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
212
- fclose($fh);
213
- die();
214
- }
215
-
216
- //if there is a database dump to restore
217
- if( glob($restoration_dir_path . "*.sql") ) {
218
- //collect connection information from form
219
- echo "<li>Restoring database..." ;
220
- include_once WP_DIR_PATH .'/wp-config.php';
221
- //Add user to DB in v1.0.5
222
- $user_id = $_GET['userid'];
223
- //Connect to DB
224
- $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
225
- if ( !$dbc ) {
226
- echo '</li><li class="error">Unable to connect to your current database: " .mysqli_connect_error() ."</li></ul>';
227
- recursive_delete($restoration_dir_path);
228
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
229
- fclose($fh);
230
- die();
231
- }
232
- //get siteurl
233
- $q1 = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='siteurl';";
234
- if ($result = mysqli_query($dbc, $q1)) {
235
- while ($row = mysqli_fetch_row($result)) {
236
- $siteurl = $row[0];
237
- }
238
- mysqli_free_result($result);
239
- } else {
240
- echo '</li><li class="error">Unable to get current site URL from database. Please try again.</li></ul>';
241
- recursive_delete($restoration_dir_path);
242
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
243
- fclose($fh);
244
- die();
245
- }
246
- //get homeurl
247
- $q2 = "SELECT option_value FROM " .$table_prefix ."options WHERE option_name ='home';";
248
- if ($result = mysqli_query($dbc, $q2)) {
249
- while ($row = mysqli_fetch_row($result)) {
250
- $homeurl = $row[0];
251
- }
252
- mysqli_free_result($result);
253
- } else {
254
- echo '</li><li class="error">Unable to get current home URL from database. Please try again.</li></ul>';
255
- recursive_delete($restoration_dir_path);
256
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
257
- fclose($fh);
258
- die();
259
- }
260
- //get user login
261
- $q3 = "SELECT user_login FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
262
- if ($result = mysqli_query($dbc, $q3)) {
263
- while ($row = mysqli_fetch_row($result)) {
264
- $user_login = $row[0];
265
- }
266
- mysqli_free_result($result);
267
- } else {
268
- echo '</li><li class="error">Unable to get current user ID from database. Please try again.</li></ul>';
269
- recursive_delete($restoration_dir_path);
270
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
271
- fclose($fh);
272
- die();
273
- }
274
- //get user pass
275
- $q4 = "SELECT user_pass FROM ". $table_prefix ."users WHERE ID=" .$user_id .";";
276
- if ($result = mysqli_query($dbc, $q4)) {
277
- while ($row = mysqli_fetch_row($result)) {
278
- $user_pass = $row[0];
279
- }
280
- mysqli_free_result($result);
281
- } else {
282
- echo '</li><li class="error">Unable to get current user password from database. Please try again.</li></ul>';
283
- recursive_delete($restoration_dir_path);
284
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
285
- fclose($fh);
286
- die();
287
- }
288
- //get user email
289
- $q5 = "SELECT user_email FROM ". $table_prefix ."users WHERE ID=" .$user_id ."";
290
- if ($result = mysqli_query($dbc, $q5)) {
291
- while ($row = mysqli_fetch_row($result)) {
292
- $user_email = $row[0];
293
- }
294
- mysqli_free_result($result);
295
- } else {
296
- echo '</li><li class="error">Unable to get current user email from database. Please try again.</li></ul>';
297
- recursive_delete($restoration_dir_path);
298
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
299
- fclose($fh);
300
- die();
301
- }
302
- //Collect previous backup site url start
303
- $import_siteinfo_lines = file($restoration_dir_path .'backupsiteinfo.txt');
304
- $import_siteurl = trim($import_siteinfo_lines[0]);
305
- $current_siteurl = trim($siteurl ,'/');
306
- $import_table_prefix = $import_siteinfo_lines[1];
307
- //import the database
308
- if(!db_import($restoration_dir_path, $import_siteurl, $current_siteurl, $table_prefix, $import_table_prefix, $dbc)) {
309
- echo '</li><li class="error">Unable to get import your database. This may require importing the file manually.</li></ul>';
310
- recursive_delete($restoration_dir_path);
311
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
312
- fclose($fh);
313
- die();
314
- }
315
- //update the database
316
- $q6 = "UPDATE ". $table_prefix ."options SET option_value='" .$current_siteurl ."' WHERE option_name='siteurl'";
317
- $q7 = "UPDATE ". $table_prefix ."options SET option_value='" .$homeurl ."' WHERE option_name='home'";
318
- $q8 = "UPDATE ". $table_prefix ."users SET user_login='" .$user_login ."', user_pass='" .$user_pass ."', user_email='" .$user_email ."' WHERE ID='" .$user_id ."'";
319
- if(!mysqli_query($dbc, $q6) ) {
320
- echo '</li><li class="error">Unable to update your current site URL value. This may require importing the file manually.</li></ul>';
321
- recursive_delete($restoration_dir_path);
322
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
323
- fclose($fh);
324
- die();
325
- }
326
- if(!mysqli_query($dbc, $q7) ) {
327
- echo '</li><li class="error">Unable to update your current home URL value. This may require importing the file manually.</li></ul>';
328
- recursive_delete($restoration_dir_path);
329
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
330
- fclose($fh);
331
- die();
332
- }
333
- if(!mysqli_query($dbc, $q8) ) {
334
- echo '</li><li class="error">Unable to update your user information. This may require importing the file manually.</li></ul>';
335
- recursive_delete($restoration_dir_path);
336
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
337
- fclose($fh);
338
- die();
339
- }
340
- echo 'Done!</li>';
341
- } else {
342
- echo '<li class="error">Warning: Database not detected in import file.</li>';
343
- }
344
-
345
- //Disconnect
346
- mysqli_close($dbc);
347
-
348
- //Delete the restoration directory
349
- recursive_delete($restoration_dir_path);
350
-
351
- //Delete zip
352
- unlink(WPBACKITUP_DIR_PATH .'/backups/' . $restore_file_name);
353
-
354
- //close log file
355
- echo '<li>Restoration complete. Please refresh the page.</li>';
356
- echo '</ul>';
357
- fclose($fh);
358
-
359
- //End backup function
360
- die();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lib/includes/upload.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * WP BackItUp File Upload Handler
5
+ *
6
+ * @package WP BackItUp Pro
7
+ *
8
+ * @author cssimmon
9
+ * @version 1.0.0
10
+ * @since 1.0.1
11
+ *
12
+ */
13
+
14
+ /*** Includes ***/
15
+ // Define WP_DIR_PATH - required for constants include
16
+ if (!defined('WP_DIR_PATH')) define('WP_DIR_PATH',dirname(dirname(dirname(dirname(dirname(dirname(__FILE__)))))));
17
+ include_once WP_DIR_PATH . '/wp-config.php';
18
+ include_once dirname(dirname( __FILE__ )) . '/constants.php';
19
+
20
+
21
+ /*** Globals ***/
22
+ $backup_folder_root = WPBACKITUP_CONTENT_PATH .WPBACKITUP_BACKUP_FOLDER .'/';
23
+
24
+
25
+ //*****************//
26
+ //*** MAIN CODE ***//
27
+ //*****************//
28
+
29
+ //Handle the file upload
30
+ if (!empty($_FILES['uploaded-zip']) && is_uploaded_file($_FILES['uploaded-zip']['tmp_name']))
31
+ {
32
+ $restore_file_name = $_FILES['uploaded-zip']['name'];
33
+ _log("File Uploaded: " .$restore_file_name);
34
+
35
+ $destination = $backup_folder_root . $restore_file_name;
36
+ _log("Destination: " .$destination);
37
+ if (move_uploaded_file($_FILES['uploaded-zip']['tmp_name'], $destination))
38
+ {
39
+ $response['file'] = $restore_file_name;
40
+ $response['link'] = WPBACKITUP_BACKUPFILE_URLPATH . '/' . $restore_file_name;
41
+
42
+ echo json_encode($response);
43
+ die();
44
+ }
45
+ }
license.txt CHANGED
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
671
  may consider it more useful to permit linking proprietary applications with
672
  the library. If this is what you want to do, use the GNU Lesser General
673
  Public License instead of this License. But first, please read
674
- <http://www.gnu.org/philosophy/why-not-lgpl.html>.
671
  may consider it more useful to permit linking proprietary applications with
672
  the library. If this is what you want to do, use the GNU Lesser General
673
  Public License instead of this License. But first, please read
674
+ <http://www.gnu.org/philosophy/why-not-lgpl.html>.
logs/status.log DELETED
@@ -1 +0,0 @@
1
- <div class="upload">1</div><div class="unzipping">1</div><div class="validation">1</div><div class="restore_point">1</div><div class="database">1</div><div class="wpcontent">1</div><div class="cleanup">1</div><div class="finalinfo">1</div>
 
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === WP Backitup ===
2
- Contributors: jcpeden, cssimmon
3
  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.8
7
- Stable tag: 1.5.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -52,10 +52,7 @@ Yes.
52
  = Will WP Backitup work on Windows hosting? =
53
  Yes.
54
 
55
- = Are you going to be makinggress bars both for backing up and restoring with this plugin? =
56
- It is likely this will feature in a new version of WP Backitup.
57
-
58
- = Can this plugin back to Amazon S3? =
59
  This will feature in an upcoming version of WP Backitup.
60
 
61
  = Is there an auto back up schedule feature? =
@@ -85,7 +82,7 @@ WP Backitup creates a database dump and a backup of all your themes, plugins and
85
  = Do you have any ideas about how large a blog is too big for WP Backitup to handle? =
86
  I`ve tested up to 5 themes, 20 plugins and 100 posts/pages without any issues.
87
 
88
- = Do you do regularly update thisduct to match with WP version updates? =
89
  Yes.
90
 
91
  == Screenshots ==
@@ -94,6 +91,13 @@ Yes.
94
  3. When the backup has been created, click the download link to access a zipped backup of your site.
95
 
96
  == Changelog ==
 
 
 
 
 
 
 
97
 
98
  = 1.5.4 =
99
  Enabled plugin to work with version 3.8
1
  === WP Backitup ===
2
+ Contributors: cssimmon,jcpeden
3
  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.8
7
+ Stable tag: 1.6.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
52
  = Will WP Backitup work on Windows hosting? =
53
  Yes.
54
 
55
+ = Can this plugin backup to Amazon S3, dropbox or google drive? =
 
 
 
56
  This will feature in an upcoming version of WP Backitup.
57
 
58
  = Is there an auto back up schedule feature? =
82
  = Do you have any ideas about how large a blog is too big for WP Backitup to handle? =
83
  I`ve tested up to 5 themes, 20 plugins and 100 posts/pages without any issues.
84
 
85
+ = Do you do regularly update this product to match with WP version updates? =
86
  Yes.
87
 
88
  == Screenshots ==
91
  3. When the backup has been created, click the download link to access a zipped backup of your site.
92
 
93
  == Changelog ==
94
+ = 1.6.0 =
95
+ * Significant performance improvements.
96
+ * Many improvements to user interface.
97
+ * Support for multiple backups.
98
+ * Added interface for large file uploads via FTP.
99
+ * Added restore point and database recovery when fatal errors are encountered.
100
+ * Added configurable debug logging.
101
 
102
  = 1.5.4 =
103
  Enabled plugin to work with version 3.8
views/options.php CHANGED
@@ -1,172 +1,269 @@
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
-
106
- <div id="sidebar">
107
-
108
- <!-- Display opt-in form if the user is unregistered -->
109
- <?php $license = $this->get_option( 'license_key' );
110
- $status = $this->get_option( 'status' );
111
- if( $status != 'valid' ) { ?>
112
- <div class="widget">
113
- <h3 class="promo"><?php _e('Get a license key', $namespace ); ?></h3>
114
- <p><?php _e('Restore your backups from Wordpress in minutes or your money back', $namespace ); ?>.</p>
115
- <a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/"><?php _e('Purchase a license key for WP Backitup', $namespace ); ?></a>
116
- </div>
117
- <?php } ?>
118
-
119
- <?php /*<div class="widget">
120
- <h3 class="promo"><?php _e('Site Information', $namespace ); ?></h3>
121
- <p>Backup Size: <?php echo formatFileSize(totalSize(WPBACKITUP_CONTENT_PATH) ); ?></p>
122
- <p>WP Backitup is not recommended for sites larger than 50MB. Why not try <a href="http://ithemes.com/purchase/backupbuddy/">Backup Buddy</a>?</p>
123
- </div> */ ?>
124
-
125
- <!-- Display license key widget -->
126
- <form action="" method="post" id="<?php echo $namespace; ?>-form">
127
- <?php wp_nonce_field( $namespace . "-update-options" ); ?>
128
- <div class="widget">
129
- <h3 class="promo"><?php _e('License Key', $namespace ); ?></h3>
130
- <?php $license = $this->get_option( 'license_key' );
131
- $status = $this->get_option( 'status' );
132
- if( $status != 'valid' ) { ?>
133
- <p><?php _e('Enter your license key to activate restoration functionality', $namespace ); ?>.</p>
134
- <?php } ?>
135
- <p><input type="text" name="data[license_key]" id="license_key" value="<?php echo $license; ?>" />
136
- <?php if( false !== $license ) {
137
- if( $status !== false && $status == 'valid' ) { ?>
138
- <span style="color:green;"><?php _e('Active', $namespace); ?></span></p>
139
- <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Update", $namespace ) ?>" /></p>
140
- <p><a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/"><?php _e('Upgrade your license',$namespace); ?></a></p>
141
- <?php } else { ?>
142
- <span style="color:red;"><?php _e('Inactive', $namespace); ?></span></p>
143
- <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Activate", $namespace ) ?>" /></p>
144
- <p><?php _e('Purchase a no-risk license using the link above',$namespace); ?>.</p>
145
- <?php }
146
- } ?>
147
- </div>
148
-
149
- <!-- Display links widget -->
150
- <div class="widget">
151
- <h3 class="promo"><?php _e('Useful Links', $namespace ); ?></h3>
152
- <ul>
153
- <?php if( false !== $license ) {
154
- if( $status !== false && $status == 'valid' ) { ?>
155
- <li><a href="http://www.wpbackitup.com/your-account/"><?php _e('Your account',$namespace); ?></a></li>
156
- <li><a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/"><?php _e('Upgrade your license',$namespace); ?></a></li>
157
- <?php }
158
- } ?>
159
- <li><a href="http://wordpress.org/support/plugin/wp-backitup"><?php _e('Get support',$namespace); ?></a></li>
160
- </ul>
161
- </div>
162
-
163
- <div class="widget">
164
- <h3 class="promo">Presstrends</h3>
165
- <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>
166
- <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>
167
- <p><?php _e('Help to improve Easy Webtrends by enabling', $namespace ); ?> <a href="http://www.presstrends.io" target="_blank">Presstrends</a>.</p>
168
- <p class="submit"><input type="submit" name="Submit" class="button-primary" value="<?php _e( "Save", $namespace ) ?>" /></p>
169
- </div>
170
- </form>
171
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  </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>WPBackItUp Options</h2>
5
+ <div id="content">
6
+
7
+ <!--Backup section-->
8
+ <div class="widget">
9
+ <h3><?php _e('Backup', $namespace );?></h3>
10
+ <p><?php _e('Click the backup button to create a zipped backup file of this site\'s database, plugins, themes and settings.', $namespace ) ;?></p>
11
+ <p>
12
+ Once your backup file has been created it will appear in the available backups section below. This file can remain on your hosting providers server but we recommend that you download and save it somewhere safe.
13
+ </p>
14
+ <p> WPBackitUp Pro users can use these backup files to perform an automated restore of their site.</p>
15
+ <p><input type="submit" id="backup-button" class="backup-button button-primary" value="<?php _e( "Backup", $namespace ) ?>"</><img class="backup-icon status-icon" src="<?php echo WPBACKITUP_URLPATH. "/images/loader.gif"; ?>" height="16" width="16" /></p>
16
+
17
+ <?php
18
+ //Display a note for lite customers
19
+ $status = $this->get_option( 'status' );
20
+ if($status != 'valid' )
21
+ {
22
+ echo '<p> * WPBackItUp Lite customers may use these backup files to manually restore their site. Please visit <a href="http://www.wpbackitup.com/wp-backitup-pro/" target="_blank">www.wpbackitup.com</a> for manual restore instructions.</p>';
23
+ }
24
+ ?>
25
+ </div>
26
+
27
+ <!--Available Backups section-->
28
+ <div class="widget">
29
+ <h3><?php _e('Available Backups', $namespace); ?></h3>
30
+ <table class="widefat" id="datatable">
31
+ <?php
32
+
33
+ //Get Zip File List
34
+ $backup_folder_root = WPBACKITUP_CONTENT_PATH .WPBACKITUP_BACKUP_FOLDER .'/';
35
+ $zipFileList = glob($backup_folder_root ."*.zip");
36
+
37
+ //Sort by Date Time
38
+ usort($zipFileList, create_function('$a,$b', 'return filemtime($b) - filemtime($a);'));
39
+
40
+ if (glob($backup_folder_root ."*.zip"))
41
+ {
42
+ $i = 0;
43
+ foreach ($zipFileList as $file)
44
+ {
45
+ $filename = basename($file);
46
+ $fileDateTime=get_date_from_gmt(date( 'Y-m-d H:i:s', filemtime($file)), 'Y-m-d g:i a' ); //Local Date Time
47
+ $class = $i % 2 == 0 ? 'class="alternate"' : '';
48
+ ?>
49
+ <tr <?php echo $class ?> id="row<?php echo $i; ?>">
50
+ <td><?php echo $filename?></td>
51
+ <td><a href="<?php echo WPBACKITUP_BACKUPFILE_URLPATH ?>/<?php echo $filename; ?>">Download</a></td>
52
+ <td><a href="#" title="<?php echo $filename; ?>" class="deleteRow" id="deleteRow<?php echo $i; ?>">Delete</a></td>
53
+ <td><a href="#" title="<?php echo $filename; ?>" class="restoreRow" id="restoreRow<?php echo $i; ?>">Restore</a></td>
54
+ </tr>
55
+ <?php
56
+ $i++;
57
+ }
58
+ }
59
+ else
60
+ {
61
+ echo '<tr id="nofiles"><td colspan="3">No export file available for download. Please create one.</td></tr>';
62
+ }
63
+ ?>
64
+ </table>
65
+
66
+ <form id="restore-form" method="post" action="<?php echo WPBACKITUP_URLPATH . '/lib/includes/restore.php'; ?>">
67
+ <?php global $current_user; ?>
68
+ <input type="hidden" name="user_id" value="<?php echo $current_user->ID; ?>" />
69
+ <input type="hidden" name="is_selected" id="is_selected" value="0" />
70
+ <input type="hidden" name="selected_file" id="selected_file" value="" />
71
+ </form>
72
+
73
+ <?php
74
+ //Display restore note for lite customers
75
+ $status = $this->get_option( 'status' );
76
+ if($status != 'valid' )
77
+ {
78
+ echo '<p>* The automated restore feature is only available to Pro customers. Please visit <a href="http://www.wpbackitup.com/wp-backitup-pro/" target="_blank">www.wpbackitup.com</a> to get WPBackItUp Pro risk free for 30 days.</p>' ;
79
+ }
80
+ ?>
81
+ </div>
82
+
83
+ <!--Disable upload form if the user has not activated-->
84
+ <?php
85
+ $status = $this->get_option( 'status' );
86
+ if( $status !== false && $status == 'valid' )
87
+ { ?>
88
+ <div class="widget">
89
+ <h3>
90
+ <?php _e('Upload', $namespace );?>
91
+ </h3>
92
+ <iframe id="upload_target" name="upload_target" src=""></iframe>
93
+ <p>
94
+ <?php _e('Upload a WP BackItUp zip file to add it to your list of available backups.', $namespace );?>
95
+ </p>
96
+ <?php
97
+ $max_upload = (int)(ini_get('upload_max_filesize'));
98
+ $max_post = (int)(ini_get('post_max_size'));
99
+ $memory_limit = (int)(ini_get('memory_limit'));
100
+ $upload_mb = min($max_upload, $max_post, $memory_limit);
101
+ ?>
102
+ <p>
103
+ <?php _e( 'The maximum file size your hosting provider allows you to upload is ', $namespace );
104
+ echo $upload_mb .'MB.'; ?>
105
+ </p>
106
+ <form id="upload-form" method="post" enctype="multipart/form-data" action="<?php echo WPBACKITUP_URLPATH . '/lib/includes/upload.php'; ?>">
107
+ <p><input name="uploaded-zip" id="wpbackitup-zip" type="file" /></p>
108
+ <p><input type="submit" class="restore-button button-primary" name="Upload" id="upload-button" value="<?php _e("Upload", $namespace) ?>" /><img class="upload-icon status-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></p>
109
+ </form>
110
+ </div>
111
+ <?php } ?>
112
+ <!--End of Upload form-->
113
+
114
+
115
+ <div id="status" class="widget">
116
+ <h3><?php _e('Status', $namespace );?></h3>
117
+
118
+ <!--default status message-->
119
+ <ul class="default-status">
120
+ <li><?php _e('Nothing to report', $namespace );?></li>
121
+ </ul>
122
+
123
+
124
+ <!--backup status messages-->
125
+ <ul class="backup-status">
126
+ <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>
127
+ <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>
128
+ <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>
129
+ <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>
130
+ <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>
131
+ <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>
132
+ <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>
133
+ </ul>
134
+
135
+ <!--backup error messages-->
136
+ <ul class="backup-errors">
137
+ <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>
138
+ <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>
139
+ <li class="error103"><span class='status error'><?php _e('Error: Unable to backup your files. Please try again', $namespace ); ?>.</span></li>
140
+ <li class="error104"><span class='status error'><?php _e('Error: Unable to backup your database. Please try again', $namespace ); ?>.</span></li>
141
+ <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>
142
+ <li class="error105"><span class='status error'><?php _e('Error: Unable to create site information file. Please try again', $namespace ); ?>.</span></li>
143
+ <li class="error106"><span class='status error'><?php _e('Warning: Unable to cleanup your backup directory', $namespace ); ?>.</span></li>
144
+ </ul>
145
+
146
+ <!--Upload status messages-->
147
+ <ul class="upload-status">
148
+ <li><span class='upload-status'></span></li>
149
+ </ul>
150
+
151
+ <!--restore status messages-->
152
+ <ul class="restore-status">
153
+ <li class="preparing"><?php _e('Preparing for restore', $namespace );?>...<span class='status-icon'><img class="preparing-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
154
+ <li class="unzipping"><?php _e('Unzipping backup file', $namespace );?>...<span class='status-icon'><img class="unzipping-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
155
+ <li class="validation"><?php _e('Validating backup file', $namespace );?>...<span class='status-icon'><img class="validation-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
156
+ <li class="restore_point"><?php _e('Creating checkpoint', $namespace );?>...<span class='status-icon'><img class="restore_point-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
157
+ <li class="database"><?php _e('Restoring database', $namespace );?>...<span class='status-icon'><img class="database-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
158
+ <li class="wpcontent"><?php _e('Restoring /wp-content/ directory', $namespace );?>...<span class='status-icon'><img class="wpcontent-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
159
+ <li class="cleanup"><?php _e('Cleaning up restore files', $namespace );?>...<span class='status-icon'><img class="cleanup-icon" src="<?php echo WPBACKITUP_URLPATH . "/images/loader.gif"; ?>" height="16" width="16" /></span><span class='status'><?php _e('Done', $namespace );?></span><span class='fail error'><?php _e('Failed', $namespace );?></span></li>
160
+ </ul>
161
+ <p>
162
+
163
+ <!--restore error messages-->
164
+ <div class="restore-errors">
165
+ <span class="error201"><div class='isa_error'><?php _e('Error: No file selected', $namespace ); ?>.</div></span>
166
+ <span class="error202"><div class='isa_error'><?php _e('Error: Your file could not be uploaded', $namespace ); ?>.</div></span>
167
+ <span class="error203"><div class='isa_error'><?php _e('Error: Your backup zip file could not be unzipped', $namespace ); ?>.</div></span>
168
+ <span class="error204"><div class='isa_error'><?php _e('Error: Your backup zip file appears to be invalid. Please ensure you selected a valid backup zip file', $namespace ); ?>.</div></span>
169
+ <span class="error205"><div class='isa_error'><?php _e('Error: Cannot create restore point', $namespace ); ?>.</div></span>
170
+ <span class="error206"><div class='isa_error'><?php _e('Error: Unable to connect to your database', $namespace ); ?>.</div></span>
171
+ <span class="error207"><div class='isa_error'><?php _e('Error: Unable to get current site URL from database. Please try again', $namespace ); ?>.</div></span>
172
+ <span class="error208"><div class='isa_error'><?php _e('Error: Unable to get current home URL from database. Please try again', $namespace ); ?>.</div></span>
173
+ <span class="error209"><div class='isa_error'><?php _e('Error: Unable to get current user ID from database. Please try again', $namespace ); ?>.</div></span>
174
+ <span class="error210"><div class='isa_error'><?php _e('Error: Unable to get current user password from database. Please try again', $namespace ); ?>.</div></span>
175
+ <span class="error211"><div class='isa_error'><?php _e('Error: Unable to get current user email from database. Please try again', $namespace ); ?>.</div></span>
176
+ <span class="error212"><div class='isa_error'><?php _e('Error: Unable to import your database. This may require importing the file manually', $namespace ); ?>.</div></span>
177
+ <span class="error213"><div class='isa_warning'><?php _e('Error: Unable to update your current site URL value. This may require importing the file manually', $namespace ); ?>.</div></span>
178
+ <span class="error214"><div class='isa_warning'><?php _e('Error: Unable to update your current home URL value. This may require importing the file manually', $namespace ); ?>.</div></span>
179
+ <span class="error215"><div class='isa_warning'><?php _e('Error: Unable to update your user information. This may require importing the file manually', $namespace ); ?>.</div></span>
180
+ <span class="error216"><div class='isa_error'><?php _e('Error: Database not detected in import file', $namespace ); ?>.</div></span>
181
+ <span class="error217"><div class='isa_warning'><?php _e('Error: Unable to remove existing wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace ); ?>.</div></span>
182
+ <span class="error218"><div class='isa_error'><?php _e('Error: Unable to create new wp-content directory for import. Please check your CHMOD settings in /wp-content/', $namespace ); ?>.</div></span>
183
+ <span class="error219"><div class='isa_warning'><?php _e('Error: Unable to import wp-content. Please try again', $namespace ); ?>.</div></span>
184
+ <span class="error220"><div class='isa_warning'><?php _e('Warning: Unable to cleanup import directory. No action is required.', $namespace ); ?>.</div></span>
185
+ <span class="error221"><div class='isa_warning'><?php _e('Warning: Table prefix value in wp-config.php is different from backup. This MUST be corrected in your wp-config.php file before your site will function', $namespace ); ?>.</div></span>
186
+ <span class='error222'><div class='isa_error'><?php _e('Error: Unable to create restore folder', $namespace ); ?>.</div></span>
187
+ <span class='error223'><div class='isa_error'><?php _e('Error: An error occurred during the restore. We attempted to restore the database to its previous state but were unsuccessful. Please contact wpbackitup customer support and do not attempt to perform any further restores', $namespace ); ?>.</div></span>
188
+ <span class='error224'><div class='isa_error'><?php _e('Error: An error occurred during the restore, however, we have successfully restored your database to the previous state', $namespace ); ?>.</div></span>
189
+ </div>
190
+
191
+ <!--restore success messages-->
192
+ <div class="restore-success">
193
+ <span class='finalinfo'><div class='isa_success'><?php _e('Restore completed successfully. Please refresh the page and login to the site again (with your current username and password)', $namespace ); ?></div></span>
194
+ </div>
195
+
196
+ </div>
197
+ <?php if (WPBACKITUP_DEBUG===true) {
198
+ echo '<p><div id="php">Debug messages</p></div>';
199
+ } ?>
200
+ </div>
201
+
202
+ <div id="sidebar">
203
+
204
+ <!-- Display opt-in form if the user is unregistered -->
205
+ <?php $license = $this->get_option( 'license_key' );
206
+ $status = $this->get_option( 'status' );
207
+ if( $status != 'valid' ) { ?>
208
+ <div class="widget">
209
+ <h3 class="promo"><?php _e('Get a license key', $namespace ); ?></h3>
210
+ <p><?php _e('Tired of messing with FTP, MySQL and PHPMyAdmin? Restore your backups from this page in minutes or your money back', $namespace ); ?>.</p>
211
+ <a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/" target="blank"><?php _e('Purchase a license key for WP Backitup Pro', $namespace ); ?></a>
212
+ </div>
213
+ <?php } ?>
214
+
215
+ <?php /*<div class="widget">
216
+ <h3 class="promo"><?php _e('Site Information', $namespace ); ?></h3>
217
+ <p>Backup Size: <?php echo formatFileSize(totalSize(WPBACKITUP_CONTENT_PATH) ); ?></p>
218
+ <p>WP Backitup is not recommended for sites larger than 50MB.</p>
219
+ </div> */ ?>
220
+
221
+ <!-- Display license key widget -->
222
+ <form action="" method="post" id="<?php echo $namespace; ?>-form">
223
+ <?php wp_nonce_field( $namespace . "-update-options" ); ?>
224
+ <div class="widget">
225
+ <h3 class="promo"><?php _e('License Key v '.WPBACKITUP_VERSION, $namespace); ?></h3>
226
+ <?php $license = $this->get_option( 'license_key' );
227
+ $status = $this->get_option( 'status' );
228
+ if( $status != 'valid' ) { ?>
229
+ <p><?php _e('Enter your license key to activate Pro features.', $namespace ); ?>.</p>
230
+ <?php } ?>
231
+ <p><input type="text" name="data[license_key]" id="license_key" value="<?php echo $license; ?>" />
232
+ <?php if( false !== $license ) {
233
+ if( $status !== false && $status == 'valid' ) { ?>
234
+ <span style="color:green;"><?php _e('Pro License Active', $namespace); ?></span></p>
235
+ <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Update", $namespace ) ?>" /></p>
236
+ <?php } else { ?>
237
+ <span style="color:red;"><?php _e('Pro License Inactive', $namespace); ?></span></p>
238
+ <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Activate", $namespace ) ?>" /></p>
239
+ <p><?php _e('Purchase a <a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/" target="blank">no-risk </a>license using the purchase link above',$namespace); ?>.</p>
240
+ <?php }
241
+ } ?>
242
+ </div>
243
+
244
+ <!-- Display links widget -->
245
+ <div class="widget">
246
+ <h3 class="promo"><?php _e('Useful Links', $namespace ); ?></h3>
247
+ <ul>
248
+ <?php if( false !== $license ) {
249
+ if( $status !== false && $status == 'valid' ) { ?>
250
+ <li><a href="http://www.wpbackitup.com/your-account/" target="_blank"><?php _e('Your account',$namespace); ?></a></li>
251
+ <li><a href="http://www.wpbackitup.com/plugins/wp-backitup-pro/" target="_blank"><?php _e('Upgrade your license',$namespace); ?></a></li>
252
+ <?php }
253
+ } ?>
254
+ <li><a href="http://www.wpbackitup.com/support" target="_blank"><?php _e('Get support',$namespace); ?></a></li>
255
+ <li><a href="http://www.wpbackitup.com/feature-request" target="_blank"><?php _e('Feature Request',$namespace); ?></a></li>
256
+ <li>Have a suggestion? Why not submit a feature request.</li>
257
+ </ul>
258
+ </div>
259
+
260
+ <div class="widget">
261
+ <h3 class="promo">Allow Usage Tracking?</h3>
262
+ <p><input type="radio" name="data[presstrends]" value="enabled" <?php if($this->get_option( 'presstrends' ) == 'enabled') echo 'checked'; ?>> <label><?php _e('Yes', $namespace ); ?></label></p>
263
+ <p><input type="radio" name="data[presstrends]" value="disabled" <?php if($this->get_option( 'presstrends' ) == 'disabled') echo 'checked'; ?>> <label><?php _e('No', $namespace ); ?></label></p>
264
+ <p><?php _e('Allow WPBackItUp to track how this plugin is used so we can make it better. We only track usage data related to this plugin and will never share this data.', $namespace ); ?></p>
265
+ <p class="submit"><input type="submit" name="Submit" class="button-secondary" value="<?php _e( "Save", $namespace ) ?>" /></p>
266
+ </div>
267
+ </form>
268
+ </div>
269
  </div>