Migration, Backup, Staging – WPvivid - Version 0.9.14

Version Description

  • Added free website transfer feature. We highly recommend all our users to update.
  • Added backup upload feature. Now you can upload a backup to restore or transfer.
Download this release

Release Info

Developer wpvivid
Plugin Icon 128x128 Migration, Backup, Staging – WPvivid
Version 0.9.14
Comparing to
See all releases

Code changes from version 0.9.13 to 0.9.14

Files changed (37) hide show
  1. admin/class-wpvivid-admin.php +52 -3
  2. admin/css/wpvivid-admin.css +6 -0
  3. admin/js/wpvivid-admin.js +530 -279
  4. admin/partials/wpvivid-admin-display.php +52 -12
  5. admin/partials/wpvivid-backup-restore-page-display.php +39 -12
  6. admin/partials/wpvivid-settings-page-display.php +1 -1
  7. admin/partials/wpvivid-website-info-page-display.php +2 -2
  8. includes/class-wpvivid-backup-database.php +30 -24
  9. includes/class-wpvivid-backup-site.php +34 -55
  10. includes/class-wpvivid-backup-uploader.php +559 -0
  11. includes/class-wpvivid-backup.php +1384 -468
  12. includes/class-wpvivid-backuplist.php +64 -6
  13. includes/class-wpvivid-backuptoremote.php +55 -0
  14. includes/class-wpvivid-compress-default.php +55 -0
  15. includes/class-wpvivid-crypt.php +62 -0
  16. includes/class-wpvivid-downloader.php +32 -24
  17. includes/class-wpvivid-log.php +2 -2
  18. includes/class-wpvivid-migrate.php +1179 -0
  19. includes/class-wpvivid-mysqldump.php +44 -13
  20. includes/class-wpvivid-remote-collection.php +2 -0
  21. includes/class-wpvivid-restore-data.php +122 -44
  22. includes/class-wpvivid-restore-database.php +974 -149
  23. includes/class-wpvivid-restore-site.php +149 -47
  24. includes/class-wpvivid-restore.php +74 -107
  25. includes/class-wpvivid-rollback.php +64 -4
  26. includes/class-wpvivid-setting.php +3 -0
  27. includes/class-wpvivid-taskmanager.php +27 -2
  28. includes/class-wpvivid-upload.php +28 -3
  29. includes/class-wpvivid-zipclass.php +281 -162
  30. includes/class-wpvivid.php +510 -581
  31. includes/customclass/class-wpvivid-dropbox.php +97 -87
  32. includes/customclass/class-wpvivid-google-drive.php +115 -79
  33. includes/customclass/class-wpvivid-one-drive.php +123 -115
  34. includes/customclass/class-wpvivid-send-to-site.php +752 -0
  35. readme.txt +40 -23
  36. uninstall.php +1 -1
  37. wpvivid-backuprestore.php +5 -4
admin/class-wpvivid-admin.php CHANGED
@@ -77,10 +77,12 @@ class WPvivid_Admin {
77
  * class.
78
  */
79
  if ('toplevel_page_'.$this->plugin_name == get_current_screen()->id ||
 
80
  'wpvivid_page_wpvivid-setting' == get_current_screen()->id ||
81
  'wpvivid_page_wpvivid-remote' == get_current_screen()->id ||
82
  'wpvivid_page_wpvivid-website' == get_current_screen()->id ||
83
- 'wpvivid_page_wpvivid-log' == get_current_screen()->id) {
 
84
  wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvivid-admin.css', array(), $this->version, 'all');
85
  }
86
  }
@@ -104,12 +106,16 @@ class WPvivid_Admin {
104
  * class.
105
  */
106
  if ('toplevel_page_'.$this->plugin_name == get_current_screen()->id ||
 
107
  'wpvivid_page_wpvivid-setting' == get_current_screen()->id ||
108
  'wpvivid_page_wpvivid-remote' == get_current_screen()->id ||
109
  'wpvivid_page_wpvivid-website' == get_current_screen()->id ||
110
- 'wpvivid_page_wpvivid-log' == get_current_screen()->id) {
 
111
  wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wpvivid-admin.js', array('jquery'), $this->version, false);
112
  wp_localize_script($this->plugin_name, 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php')));
 
 
113
  }
114
  }
115
 
@@ -130,10 +136,12 @@ class WPvivid_Admin {
130
  */
131
  add_menu_page(__('WPvivid'), __('WPvivid'), 'administrator', $this->plugin_name, array($this, 'display_plugin_backup_page'), false, 100);
132
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Backup / Restore', 'wpvivid'), 'administrator', $this->plugin_name, array($this, 'display_plugin_backup_page'), false, 100);
 
133
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Settings', 'wpvivid'), 'administrator', 'wpvivid-setting', array($this, 'display_plugin_setting_page'), false, 100);
134
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Remote Storage', 'wpvivid'), 'administrator', 'wpvivid-remote', array($this, 'display_plugin_remote_page'), false, 100);
135
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Website Info', 'wpvivid'), 'administrator', 'wpvivid-website', array($this, 'display_plugin_website_page'), false, 100);
136
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Logs', 'wpvivid'), 'administrator', 'wpvivid-log', array($this, 'display_plugin_log_page'), false, 100);
 
137
  }
138
 
139
  function add_toolbar_items($wp_admin_bar){
@@ -151,6 +159,12 @@ class WPvivid_Admin {
151
  'title' => 'Backup / Restore',
152
  'href' => $admin_url . 'admin.php?page=WPvivid&tab-backup'
153
  ));
 
 
 
 
 
 
154
  $wp_admin_bar->add_menu(array(
155
  'id' => 'wpvivid_admin_menu_settings',
156
  'parent' => 'wpvivid_admin_menu',
@@ -175,6 +189,12 @@ class WPvivid_Admin {
175
  'title' => 'Logs',
176
  'href' => $admin_url . 'admin.php?page=WPvivid&tab-logs'
177
  ));
 
 
 
 
 
 
178
  }
179
  }
180
 
@@ -202,6 +222,9 @@ class WPvivid_Admin {
202
  if(isset($_REQUEST['tab-backup'])){
203
  self::wpvivid_set_page_request('backup');
204
  }
 
 
 
205
  else if(isset($_REQUEST['tab-settings'])){
206
  self::wpvivid_set_page_request('settings');
207
  }
@@ -214,9 +237,23 @@ class WPvivid_Admin {
214
  else if(isset($_REQUEST['tab-logs'])){
215
  self::wpvivid_set_page_request('log');
216
  }
 
 
 
217
  global $wpvivid_pulgin;
218
  $wpvivid_pulgin->clean_cache();
219
 
 
 
 
 
 
 
 
 
 
 
 
220
  $restore = new WPvivid_restore_data();
221
  if ($restore->has_restore()) {
222
  $restore_status = $restore->get_restore_status();
@@ -230,7 +267,9 @@ class WPvivid_Admin {
230
  WPvivid_Setting::update_option('wpvivid_review_msg',$msg);
231
  }
232
  else{
233
- _e('<div class="notice notice-success is-dismissible"><p>Restore completed successfully.</p></div>');
 
 
234
  }
235
  }
236
  }
@@ -246,6 +285,11 @@ class WPvivid_Admin {
246
  $this->display_plugin_setup_page();
247
  }
248
 
 
 
 
 
 
249
  public function display_plugin_setting_page(){
250
  self::wpvivid_set_page_request('settings');
251
  $this->display_plugin_setup_page();
@@ -266,6 +310,11 @@ class WPvivid_Admin {
266
  $this->display_plugin_setup_page();
267
  }
268
 
 
 
 
 
 
269
  public function wpvivid_set_page_request($page){
270
  global $request_page;
271
  $request_page=$page;
77
  * class.
78
  */
79
  if ('toplevel_page_'.$this->plugin_name == get_current_screen()->id ||
80
+ 'wpvivid_page_wpvivid-transfer' == get_current_screen()->id ||
81
  'wpvivid_page_wpvivid-setting' == get_current_screen()->id ||
82
  'wpvivid_page_wpvivid-remote' == get_current_screen()->id ||
83
  'wpvivid_page_wpvivid-website' == get_current_screen()->id ||
84
+ 'wpvivid_page_wpvivid-log' == get_current_screen()->id ||
85
+ 'wpvivid_page_wpvivid-key' == get_current_screen()->id) {
86
  wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvivid-admin.css', array(), $this->version, 'all');
87
  }
88
  }
106
  * class.
107
  */
108
  if ('toplevel_page_'.$this->plugin_name == get_current_screen()->id ||
109
+ 'wpvivid_page_wpvivid-transfer' == get_current_screen()->id ||
110
  'wpvivid_page_wpvivid-setting' == get_current_screen()->id ||
111
  'wpvivid_page_wpvivid-remote' == get_current_screen()->id ||
112
  'wpvivid_page_wpvivid-website' == get_current_screen()->id ||
113
+ 'wpvivid_page_wpvivid-log' == get_current_screen()->id ||
114
+ 'wpvivid_page_wpvivid-key' == get_current_screen()->id) {
115
  wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wpvivid-admin.js', array('jquery'), $this->version, false);
116
  wp_localize_script($this->plugin_name, 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php')));
117
+
118
+ wp_enqueue_script('plupload-all');
119
  }
120
  }
121
 
136
  */
137
  add_menu_page(__('WPvivid'), __('WPvivid'), 'administrator', $this->plugin_name, array($this, 'display_plugin_backup_page'), false, 100);
138
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Backup / Restore', 'wpvivid'), 'administrator', $this->plugin_name, array($this, 'display_plugin_backup_page'), false, 100);
139
+ add_submenu_page($this->plugin_name, __('WPvivid'), __('Transfer / Migration', 'wpvivid'), 'administrator', 'wpvivid-transfer', array($this, 'display_plugin_transfer_page'), false, 100);
140
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Settings', 'wpvivid'), 'administrator', 'wpvivid-setting', array($this, 'display_plugin_setting_page'), false, 100);
141
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Remote Storage', 'wpvivid'), 'administrator', 'wpvivid-remote', array($this, 'display_plugin_remote_page'), false, 100);
142
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Website Info', 'wpvivid'), 'administrator', 'wpvivid-website', array($this, 'display_plugin_website_page'), false, 100);
143
  add_submenu_page($this->plugin_name, __('WPvivid'), __('Logs', 'wpvivid'), 'administrator', 'wpvivid-log', array($this, 'display_plugin_log_page'), false, 100);
144
+ add_submenu_page($this->plugin_name, __('WPvivid'), __('Generate Key', 'wpvivid'), 'administrator', 'wpvivid-key', array($this, 'display_plugin_key_page'), false, 100);
145
  }
146
 
147
  function add_toolbar_items($wp_admin_bar){
159
  'title' => 'Backup / Restore',
160
  'href' => $admin_url . 'admin.php?page=WPvivid&tab-backup'
161
  ));
162
+ $wp_admin_bar->add_menu(array(
163
+ 'id' => 'wpvivid_admin_menu_transfer',
164
+ 'parent' => 'wpvivid_admin_menu',
165
+ 'title' => 'Transfer / Migration',
166
+ 'href' => $admin_url . 'admin.php?page=WPvivid&tab-transfer'
167
+ ));
168
  $wp_admin_bar->add_menu(array(
169
  'id' => 'wpvivid_admin_menu_settings',
170
  'parent' => 'wpvivid_admin_menu',
189
  'title' => 'Logs',
190
  'href' => $admin_url . 'admin.php?page=WPvivid&tab-logs'
191
  ));
192
+ $wp_admin_bar->add_menu(array(
193
+ 'id' => 'wpvivid_admin_menu_key',
194
+ 'parent' => 'wpvivid_admin_menu',
195
+ 'title' => 'Generate Key',
196
+ 'href' => $admin_url . 'admin.php?page=WPvivid&tab-key'
197
+ ));
198
  }
199
  }
200
 
222
  if(isset($_REQUEST['tab-backup'])){
223
  self::wpvivid_set_page_request('backup');
224
  }
225
+ else if(isset($_REQUEST['tab-transfer'])){
226
+ self::wpvivid_set_page_request('transfer');
227
+ }
228
  else if(isset($_REQUEST['tab-settings'])){
229
  self::wpvivid_set_page_request('settings');
230
  }
237
  else if(isset($_REQUEST['tab-logs'])){
238
  self::wpvivid_set_page_request('log');
239
  }
240
+ else if(isset($_REQUEST['tab-key'])){
241
+ self::wpvivid_set_page_request('key');
242
+ }
243
  global $wpvivid_pulgin;
244
  $wpvivid_pulgin->clean_cache();
245
 
246
+
247
+ //
248
+ $migrate_notice=false;
249
+ $migrate_status=WPvivid_Setting::get_option('wpvivid_migrate_status');
250
+ if(!empty($migrate_status) && $migrate_status == 'completed'){
251
+ $migrate_notice=true;
252
+ _e('<div class="notice notice-warning is-dismissible"><p>Migration is complete and htaccess file is replaced. For website running properly, you\'d better reinstall 301 redirect plugin, firewall and security plugin, and caching plugin if they exist.</p></div>');
253
+ WPvivid_Setting::delete_option('wpvivid_migrate_status');
254
+ }
255
+
256
+
257
  $restore = new WPvivid_restore_data();
258
  if ($restore->has_restore()) {
259
  $restore_status = $restore->get_restore_status();
267
  WPvivid_Setting::update_option('wpvivid_review_msg',$msg);
268
  }
269
  else{
270
+ if(!$migrate_notice) {
271
+ _e('<div class="notice notice-success is-dismissible"><p>Restore completed successfully.</p></div>');
272
+ }
273
  }
274
  }
275
  }
285
  $this->display_plugin_setup_page();
286
  }
287
 
288
+ public function display_plugin_transfer_page(){
289
+ self::wpvivid_set_page_request('transfer');
290
+ $this->display_plugin_setup_page();
291
+ }
292
+
293
  public function display_plugin_setting_page(){
294
  self::wpvivid_set_page_request('settings');
295
  $this->display_plugin_setup_page();
310
  $this->display_plugin_setup_page();
311
  }
312
 
313
+ public function display_plugin_key_page(){
314
+ self::wpvivid_set_page_request('key');
315
+ $this->display_plugin_setup_page();
316
+ }
317
+
318
  public function wpvivid_set_page_request($page){
319
  global $request_page;
320
  $request_page=$page;
admin/css/wpvivid-admin.css CHANGED
@@ -15,6 +15,8 @@
15
  .quickstart-storage-block{width:33%;padding:10px; float:left; position:relative; box-sizing:border-box;}
16
  .quickstart-btn{width:33%;padding:10px; float:left; position:relative; box-sizing:border-box;}
17
  .quickbackup-btn{display:block !important; margin:0 auto !important;width:150px;height:50px !important; line-height:48px !important; font-size:20px !important;}
 
 
18
  .schedule-block{float:left;width:100%;padding:0 10px 10px 10px;box-sizing:border-box;}
19
  .postbox:after{content: ".";display: block;height: 0;clear: both;visibility: hidden;}
20
  .quickbackup-block .fieldset label{margin-bottom:5px;}
@@ -79,6 +81,10 @@
79
  .download-website-info{float:left;}
80
  .storage-account-form {padding-top: 1px; padding-bottom: 1px;}
81
 
 
 
 
 
82
  @media screen and (max-width:1650px) {
83
  .qucikbackup-schedule{
84
  float:none;
15
  .quickstart-storage-block{width:33%;padding:10px; float:left; position:relative; box-sizing:border-box;}
16
  .quickstart-btn{width:33%;padding:10px; float:left; position:relative; box-sizing:border-box;}
17
  .quickbackup-btn{display:block !important; margin:0 auto !important;width:150px;height:50px !important; line-height:48px !important; font-size:20px !important;}
18
+ .quickmigrate-btn{width:33%;padding:10px; float:left; position:relative; box-sizing:border-box;}
19
+ .migrate-btn{display:block !important; margin:0 auto !important;width:90px;height:50px !important; line-height:48px !important; font-size:20px !important;}
20
  .schedule-block{float:left;width:100%;padding:0 10px 10px 10px;box-sizing:border-box;}
21
  .postbox:after{content: ".";display: block;height: 0;clear: both;visibility: hidden;}
22
  .quickbackup-block .fieldset label{margin-bottom:5px;}
81
  .download-website-info{float:left;}
82
  .storage-account-form {padding-top: 1px; padding-bottom: 1px;}
83
 
84
+ .quicktransfer{width:100%; float:left; box-sizing:border-box;margin-right:10px; padding:10px;}
85
+ .quicktransfer label{display:inline-block;margin-bottom:10px;}
86
+ .quicktransfer-btn{display:block !important; margin:0 auto !important;width:220px;height:50px !important; line-height:48px !important; font-size:20px !important;}
87
+
88
  @media screen and (max-width:1650px) {
89
  .qucikbackup-schedule{
90
  float:none;
admin/js/wpvivid-admin.js CHANGED
@@ -17,6 +17,9 @@ var wpvivid_editing_storage_type = '';
17
  var wpvivid_restore_download_array;
18
  var wpvivid_restore_download_index = 0;
19
  var wpvivid_get_download_restore_progress_retry = 0;
 
 
 
20
 
21
  (function ($) {
22
  'use strict';
@@ -263,14 +266,16 @@ function wpvivid_check_runningtask(){
263
  }
264
  else if (value.status.str === 'running') {
265
  running_backup_taskid = index;
266
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
 
267
  jQuery('#wpvivid_postbox_backup_percent').show();
268
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
269
  m_need_update = true;
270
  }
271
  else if (value.status.str === 'wait_resume') {
272
  running_backup_taskid = index;
273
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
 
274
  jQuery('#wpvivid_postbox_backup_percent').show();
275
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
276
  if (value.data.next_resume_time !== 'get next resume time failed.') {
@@ -282,14 +287,16 @@ function wpvivid_check_runningtask(){
282
  }
283
  else if (value.status.str === 'no_responds') {
284
  running_backup_taskid = index;
285
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
 
286
  jQuery('#wpvivid_postbox_backup_percent').show();
287
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
288
  m_need_update = true;
289
  }
290
  else if (value.status.str === 'completed') {
291
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
292
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
 
293
  jQuery('#wpvivid_postbox_backup_percent').hide();
294
  jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
295
  jQuery('#wpvivid_loglist').html("");
@@ -302,7 +309,8 @@ function wpvivid_check_runningtask(){
302
  }
303
  else if (value.status.str === 'error') {
304
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
305
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
 
306
  jQuery('#wpvivid_postbox_backup_percent').hide();
307
  jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
308
  jQuery('#wpvivid_loglist').html("");
@@ -320,7 +328,8 @@ function wpvivid_check_runningtask(){
320
  {
321
  jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
322
  jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
323
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
 
324
  jQuery('#wpvivid_postbox_backup_percent').hide();
325
  wpvivid_retrieve_backup_list();
326
  wpvivid_retrieve_last_backup_message();
@@ -328,72 +337,70 @@ function wpvivid_check_runningtask(){
328
  running_backup_taskid='';
329
  }
330
  }
331
- if (jsonarray.download.data.length !== 0) {
332
  b_has_data = true;
333
  task_retry_times = 0;
334
  var i = 0;
335
- jQuery.each(jsonarray.download.data.type, function (index, value) {
336
  var file_name = '';
337
  jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).html("");
338
  var b_download_finish=false;
339
- jQuery.each(value.files, function (index1, value1) {
340
  i++;
341
- file_name = index1;
342
  var progress = '0%';
343
- if (value1.status === 'need_download') {
344
  if (m_downloading_file_name === file_name) {
345
  m_need_update = true;
346
  }
347
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value1.html);
348
- b_download_finish=true;
349
  }
350
- else if (value1.status === 'running') {
351
  if (m_downloading_file_name === file_name) {
352
  wpvivid_lock_download(tmp_current_click_backupid);
353
  }
354
  m_need_update = true;
355
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value1.html);
356
  b_download_finish=false;
357
  }
358
- else if (value1.status === 'completed') {
359
  if (m_downloading_file_name === file_name) {
360
  wpvivid_unlock_download(tmp_current_click_backupid);
361
  m_downloading_id = '';
362
  m_downloading_file_name = '';
363
  }
364
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value1.html);
365
  b_download_finish=true;
366
  }
367
- else if (value1.status === 'error') {
368
  if (m_downloading_file_name === file_name) {
369
  wpvivid_unlock_download(tmp_current_click_backupid);
370
  m_downloading_id = '';
371
  m_downloading_file_name = '';
372
  }
373
- alert(value1.error);
374
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value1.html);
375
  b_download_finish=true;
376
  }
377
- else if (value1.stauts === 'timeout') {
378
  if (m_downloading_file_name === file_name) {
379
  wpvivid_unlock_download(tmp_current_click_backupid);
380
  m_downloading_id = '';
381
  m_downloading_file_name = '';
382
  }
383
  alert('Download timeout, please retry.');
384
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value1.html);
385
  b_download_finish=true;
386
  }
387
  });
388
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.place_html);
389
  if(b_download_finish==true){
390
  tmp_current_click_backupid = '';
391
  }
392
- });
393
  }
394
  if (!b_has_data) {
395
  task_retry_times++;
396
- if (task_retry_times <= 5) {
397
  m_need_update = true;
398
  }
399
  }
@@ -529,6 +536,16 @@ function wpvivid_show_log(data, content_id){
529
  }
530
  }
531
 
 
 
 
 
 
 
 
 
 
 
532
  /**
533
  * Start backing up
534
  */
@@ -552,7 +569,8 @@ function wpvivid_start_backup(){
552
  'action': 'wpvivid_prepare_backup',
553
  'backup': backup_data
554
  };
555
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
 
556
  jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
557
  jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
558
  jQuery('#wpvivid_postbox_backup_percent').show();
@@ -595,7 +613,8 @@ function wpvivid_start_backup(){
595
  else {
596
  jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
597
  jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
598
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
 
599
  jQuery('#wpvivid_postbox_backup_percent').hide();
600
  }
601
  }
@@ -621,13 +640,15 @@ function wpvivid_delete_ready_task(error){
621
  var jsonarray = jQuery.parseJSON(data);
622
  if (jsonarray.result === 'success') {
623
  wpvivid_add_notice('Backup', 'Error', error);
624
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
 
625
  jQuery('#wpvivid_postbox_backup_percent').hide();
626
  }
627
  }
628
  catch(err){
629
  wpvivid_add_notice('Backup', 'Error', err);
630
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
 
631
  jQuery('#wpvivid_postbox_backup_percent').hide();
632
  }
633
  }, function (XMLHttpRequest, textStatus, errorThrown) {
@@ -724,6 +745,7 @@ function wpvivid_add_remote_storage(storage_type)
724
  {
725
  var error_message = wpvivid_output_ajaxerror('adding the remote storage', textStatus, errorThrown);
726
  alert(error_message);
 
727
  });
728
  }
729
 
@@ -1126,6 +1148,14 @@ function wpvivid_interface_flow_control(){
1126
  jQuery('#wpvivid_storage_account_block input[type=checkbox]').on("change", function(){
1127
  wpvivid_settings_changed = true;
1128
  });
 
 
 
 
 
 
 
 
1129
  }
1130
 
1131
  /**
@@ -1179,7 +1209,7 @@ function wpvivid_add_notice(notice_action, notice_type, notice_msg){
1179
  jQuery('#'+notice_id).show();
1180
  var div = '';
1181
  if(notice_type === "Warning"){
1182
- div = "<div class=\"notice notice-warning is-dismissible inline\"><p>Warning: " + notice_msg + "</p>" +
1183
  "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
1184
  "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1185
  "</button>" +
@@ -1192,7 +1222,7 @@ function wpvivid_add_notice(notice_action, notice_type, notice_msg){
1192
  wpvivid_clear_notice('wpvivid_backup_notice');
1193
  jQuery('#wpvivid_backup_notice').show();
1194
  var success_msg = wpvivid_completed_backup + " backup tasks have been completed. Please switch to <a href=\"#\" onclick=\"wpvivid_click_switch_page('wrap', 'wpvivid_tab_log', true);\">Log</a> page to check the details.\n";
1195
- div = "<div class=\"notice notice-success is-dismissible inline\"><p>" + success_msg + "</p>" +
1196
  "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
1197
  "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1198
  "</button>" +
@@ -1200,7 +1230,7 @@ function wpvivid_add_notice(notice_action, notice_type, notice_msg){
1200
  wpvivid_completed_backup++;
1201
  }
1202
  else if(notice_type === "Info"){
1203
- div = "<div class=\"notice notice-info is-dismissible inline\"><p>" + notice_msg + "</p>" +
1204
  "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
1205
  "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1206
  "</button>" +
@@ -1294,52 +1324,50 @@ function wpvivid_initialize_download(backup_id){
1294
  jQuery('#wpvivid_file_part_' + backup_id).html("");
1295
  var i = 0;
1296
  var file_not_found = false;
1297
- jQuery.each(jsonarray.data.type, function (index, value) {
1298
  var file_name = '';
1299
- jQuery.each(value.files, function (index1, value1) {
1300
  i++;
1301
- file_name = index1;
1302
- if (value1.status === 'need_download') {
1303
- jQuery('#wpvivid_file_part_' + backup_id).append(value1.html);
1304
- tmp_current_click_backupid = '';
1305
  }
1306
- else if (value1.status === 'running') {
1307
  if (m_downloading_file_name === file_name) {
1308
  wpvivid_lock_download(tmp_current_click_backupid);
1309
  }
1310
- jQuery('#wpvivid_file_part_' + backup_id).append(value1.html);
1311
  }
1312
- else if (value1.status === 'completed') {
1313
  if (m_downloading_file_name === file_name) {
1314
  wpvivid_unlock_download(tmp_current_click_backupid);
1315
  m_downloading_id = '';
1316
  m_downloading_file_name = '';
1317
  }
1318
- jQuery('#wpvivid_file_part_' + backup_id).append(value1.html);
1319
- tmp_current_click_backupid = '';
1320
  }
1321
- else if (value1.status === 'timeout') {
1322
  if (m_downloading_file_name === file_name) {
1323
  wpvivid_unlock_download(tmp_current_click_backupid);
1324
  m_downloading_id = '';
1325
  m_downloading_file_name = '';
1326
  }
1327
- jQuery('#wpvivid_file_part_' + backup_id).append(value1.html);
1328
- tmp_current_click_backupid = '';
1329
  }
1330
- else if (value1.status === 'file_not_found') {
1331
  wpvivid_unlock_download(tmp_current_click_backupid);
1332
  wpvivid_reset_backup_list();
1333
  file_not_found = true;
1334
  alert("Download failed, file not found. The file might has been moved, renamed or deleted. Please verify the file exists and try again.");
1335
- tmp_current_click_backupid = '';
1336
  return false;
1337
  }
1338
  });
1339
  if (file_not_found === false) {
1340
- jQuery('#wpvivid_file_part_' + backup_id).append(value.place_html);
1341
  }
1342
- });
1343
  }
1344
  }
1345
  catch(err){
@@ -1427,14 +1455,6 @@ function wpvivid_prepare_download(part_num, backup_id, file_name){
1427
  {
1428
  }, function(XMLHttpRequest, textStatus, errorThrown)
1429
  {
1430
- var error_message = wpvivid_output_ajaxerror('downloading a backup', textStatus, errorThrown);
1431
- alert(error_message);
1432
- wpvivid_unlock_download(backup_id);
1433
- jQuery("#"+backup_id+"-text-part-"+part_num).html("<a onclick=\"wpvivid_prepare_download('" + part_num + "', '" + backup_id + "', '" + file_name + "');\" style=\"cursor: pointer\">Prepare to Download</a>");
1434
- jQuery("#"+backup_id+"-progress-part-"+part_num).css('width', progress);
1435
- m_downloading_id = '';
1436
- m_downloading_file_name = '';
1437
- tmp_current_click_backupid = '';
1438
  }, 0);
1439
  }
1440
 
@@ -1490,6 +1510,9 @@ function wpvivid_getrequest() {
1490
  case "backup":
1491
  wpvivid_click_switch_page('wrap', 'wpvivid_tab_general', false);
1492
  break;
 
 
 
1493
  case "settings":
1494
  wpvivid_click_switch_page('wrap', 'wpvivid_tab_setting', false);
1495
  break;
@@ -1502,6 +1525,9 @@ function wpvivid_getrequest() {
1502
  case "log":
1503
  wpvivid_click_switch_page('wrap', 'wpvivid_tab_log', false);
1504
  break;
 
 
 
1505
  default:
1506
  wpvivid_click_switch_page('wrap', 'wpvivid_tab_general', false);
1507
  break;
@@ -1637,13 +1663,29 @@ function wpvivid_set_backup_lock(backup_id, lock_status){
1637
  });
1638
  }
1639
 
1640
- function wpvivid_initialize_restore(backup_id, backup_time){
1641
- jQuery('#wpvivid_restore_backup_time').html(backup_time);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1642
  m_restore_backup_id = backup_id;
1643
- jQuery('#wpvivid_restore_log').html("");
1644
- jQuery('#wpvivid_tab_restore').show();
1645
- wpvivid_click_switch_page('backup', 'wpvivid_tab_restore', true);
1646
- wpvivid_init_restore_data();
1647
  }
1648
 
1649
  /**
@@ -1651,13 +1693,22 @@ function wpvivid_initialize_restore(backup_id, backup_time){
1651
  *
1652
  * @param backup_id - The unique ID for the backup
1653
  */
1654
- function wpvivid_init_restore_data(){
1655
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1656
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1657
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1658
- jQuery('#wpvivid_restore_part').hide();
1659
- jQuery('#wpvivid_clean_part').hide();
1660
- jQuery('#wpvivid_rollback_part').hide();
 
 
 
 
 
 
 
 
 
1661
  var ajax_data = {
1662
  'action':'wpvivid_init_restore_page',
1663
  'backup_id':m_restore_backup_id
@@ -1665,19 +1716,84 @@ function wpvivid_init_restore_data(){
1665
  wpvivid_post_request(ajax_data, function(data){
1666
  try {
1667
  var jsonarray = jQuery.parseJSON(data);
1668
- if (jsonarray.has_exist_restore === 0) {
1669
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1670
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1671
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1672
- jQuery('#wpvivid_restore_part').show();
1673
  }
1674
- else {
1675
- if (jsonarray.has_exist_restore === 1) {
1676
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1677
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'auto', 'opacity': '1'});
1678
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1679
- jQuery('#wpvivid_clean_part').show();
1680
- wpvivid_display_restore_msg("Has old restore task, please delete first.");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1681
  }
1682
  }
1683
  }
@@ -1686,19 +1802,52 @@ function wpvivid_init_restore_data(){
1686
  }
1687
  }, function(XMLHttpRequest, textStatus, errorThrown) {
1688
  var error_message = wpvivid_output_ajaxerror('initializing restore information', textStatus, errorThrown);
1689
- wpvivid_display_restore_msg(error_message);
1690
  });
1691
  }
1692
 
1693
  /**
1694
  * This function will start the process of restoring a backup
1695
  */
1696
- function wpvivid_start_restore(){
1697
- jQuery('#wpvivid_restore_log').html("");
1698
- wpvivid_prepare_restore();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1699
  }
1700
 
1701
- function wpvivid_prepare_restore(){
 
 
 
 
 
 
 
1702
  var restore_options = {
1703
  0:'backup_db',
1704
  1:'backup_themes',
@@ -1714,12 +1863,12 @@ function wpvivid_prepare_restore(){
1714
  'backup_id':m_restore_backup_id,
1715
  'restore_options':json
1716
  };
1717
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1718
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1719
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1720
- jQuery('#wpvivid_restore_part').show();
1721
- jQuery('#wpvivid_clean_part').hide();
1722
- jQuery('#wpvivid_rollback_part').hide();
1723
  wpvivid_restoring = true;
1724
  wpvivid_post_request(ajax_data, function(data)
1725
  {
@@ -1728,17 +1877,17 @@ function wpvivid_prepare_restore(){
1728
  var jsonarray = jQuery.parseJSON(data);
1729
  if (jsonarray.result === "success")
1730
  {
1731
- wpvivid_display_restore_msg("Prepare to start restoring.");
1732
  wpvivid_restore_lock();
1733
- wpvivid_monitor_restore_task();
1734
- wpvivid_restore();
1735
  }
1736
  else if (jsonarray.result === "need_download")
1737
  {
1738
  wpvivid_restore_lock();
1739
  wpvivid_restore_download_array = new Array();
1740
  var download_num = 0;
1741
- wpvivid_display_restore_msg("Backup is not found on web server. Prepare to download it from remote storage.");
1742
  jQuery.each(jsonarray.files, function (index, value)
1743
  {
1744
  if (value.status === "need_download")
@@ -1751,45 +1900,54 @@ function wpvivid_prepare_restore(){
1751
  }
1752
  });
1753
  wpvivid_restore_download_index=0;
1754
- wpvivid_download_restore_file();
1755
  }
1756
- else if (jsonarray.result === "file_not_found")
1757
  {
1758
- wpvivid_display_restore_msg("Backup doesn't exist in both web server and remote storage. Restore failed.");
1759
  }
1760
  }
1761
  catch(err)
1762
  {
1763
  alert(err);
1764
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1765
  }
1766
  }, function(XMLHttpRequest, textStatus, errorThrown)
1767
  {
1768
  var error_message = wpvivid_output_ajaxerror('preparing to restore', textStatus, errorThrown);
1769
- wpvivid_display_restore_msg(error_message);
1770
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1771
  });
1772
  }
1773
 
1774
- function wpvivid_download_restore_file()
1775
  {
 
 
 
 
 
 
 
 
1776
  if(wpvivid_restore_download_array.length===0)
1777
  {
1778
- wpvivid_display_restore_msg("Downloading backup file failed. Backup file might be deleted or network doesn't work properly. Please verify the file and confirm the network connection and try again later.");
1779
  wpvivid_restore_unlock();
1780
  return false;
1781
  }
1782
 
1783
  if(wpvivid_restore_download_index+1>wpvivid_restore_download_array.length)
1784
  {
1785
- wpvivid_display_restore_msg("Download succeeded.");
1786
  //return true;
1787
- wpvivid_prepare_restore();
 
1788
  }
1789
  else
1790
  {
1791
- wpvivid_display_restore_msg("Downloading backup file " + wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name']);
1792
- wpvivid_display_restore_msg('', wpvivid_restore_download_index);
1793
  var ajax_data = {
1794
  'action': 'wpvivid_download_restore',
1795
  'backup_id': m_restore_backup_id,
@@ -1798,27 +1956,23 @@ function wpvivid_download_restore_file()
1798
  'md5': wpvivid_restore_download_array[wpvivid_restore_download_index]['md5']
1799
  }
1800
  wpvivid_get_download_restore_progress_retry=0;
1801
- wpvivid_monitor_download_restore_task();
1802
- wpvivid_post_request(ajax_data, function (data)
1803
- {
1804
- //wpvivid_monitor_download_restore_task();
1805
- }, function (XMLHttpRequest, textStatus, errorThrown)
1806
- {
1807
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1808
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1809
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1810
- jQuery('#wpvivid_restore_part').show();
1811
- jQuery('#wpvivid_clean_part').hide();
1812
- jQuery('#wpvivid_rollback_part').hide();
1813
- var error_message = wpvivid_output_ajaxerror('downloading backups', textStatus, errorThrown);
1814
- wpvivid_display_restore_msg(error_message);
1815
- wpvivid_restore_unlock();
1816
  }, 0);
1817
  }
1818
  }
1819
 
1820
- function wpvivid_monitor_download_restore_task()
1821
  {
 
 
 
 
 
 
 
 
1822
  var ajax_data={
1823
  'action':'wpvivid_get_download_restore_progress',
1824
  'file_name': wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],
@@ -1837,30 +1991,28 @@ function wpvivid_monitor_download_restore_task()
1837
  {
1838
  if(jsonarray.status==='completed')
1839
  {
1840
- wpvivid_display_restore_msg(wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'] + ' download succeeded.', wpvivid_restore_download_index, false);
1841
- //wpvivid_display_restore_msg(wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'] + ' download succeeded.');
1842
  wpvivid_restore_download_index++;
1843
- wpvivid_download_restore_file();
1844
  }
1845
  else if(jsonarray.status==='error')
1846
  {
1847
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1848
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1849
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1850
- jQuery('#wpvivid_restore_part').show();
1851
- jQuery('#wpvivid_clean_part').hide();
1852
- jQuery('#wpvivid_rollback_part').hide();
1853
  var error_message = jsonarray.error;
1854
- wpvivid_display_restore_msg(error_message,wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],false);
1855
  wpvivid_restore_unlock();
1856
  }
1857
  else if(jsonarray.status==='running')
1858
  {
1859
- wpvivid_display_restore_msg(jsonarray.log, wpvivid_restore_download_index, false);
1860
- //wpvivid_display_restore_msg(jsonarray.log);
1861
  setTimeout(function()
1862
  {
1863
- wpvivid_monitor_download_restore_task();
1864
  }, 3000);
1865
  }
1866
  else if(jsonarray.status==='timeout')
@@ -1868,21 +2020,21 @@ function wpvivid_monitor_download_restore_task()
1868
  wpvivid_get_download_restore_progress_retry++;
1869
  if(wpvivid_get_download_restore_progress_retry>10)
1870
  {
1871
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1872
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1873
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1874
- jQuery('#wpvivid_restore_part').show();
1875
- jQuery('#wpvivid_clean_part').hide();
1876
- jQuery('#wpvivid_rollback_part').hide();
1877
  var error_message = jsonarray.error;
1878
- wpvivid_display_restore_msg(error_message);
1879
  wpvivid_restore_unlock();
1880
  }
1881
  else
1882
  {
1883
  setTimeout(function()
1884
  {
1885
- wpvivid_monitor_download_restore_task();
1886
  }, 3000);
1887
  }
1888
  }
@@ -1890,7 +2042,7 @@ function wpvivid_monitor_download_restore_task()
1890
  {
1891
  setTimeout(function()
1892
  {
1893
- wpvivid_monitor_download_restore_task();
1894
  }, 3000);
1895
  }
1896
  }
@@ -1899,21 +2051,21 @@ function wpvivid_monitor_download_restore_task()
1899
  wpvivid_get_download_restore_progress_retry++;
1900
  if(wpvivid_get_download_restore_progress_retry>10)
1901
  {
1902
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1903
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1904
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1905
- jQuery('#wpvivid_restore_part').show();
1906
- jQuery('#wpvivid_clean_part').hide();
1907
- jQuery('#wpvivid_rollback_part').hide();
1908
  var error_message = jsonarray.error;
1909
- wpvivid_display_restore_msg(error_message);
1910
  wpvivid_restore_unlock();
1911
  }
1912
  else
1913
  {
1914
  setTimeout(function()
1915
  {
1916
- wpvivid_monitor_download_restore_task();
1917
  }, 3000);
1918
  }
1919
  }
@@ -1922,132 +2074,166 @@ function wpvivid_monitor_download_restore_task()
1922
  {
1923
  setTimeout(function()
1924
  {
1925
- wpvivid_monitor_download_restore_task();
1926
  }, 3000);
1927
  }
1928
  }
1929
  catch(err){
1930
  setTimeout(function()
1931
  {
1932
- wpvivid_monitor_download_restore_task();
1933
  }, 3000);
1934
  }
1935
  }, function(XMLHttpRequest, textStatus, errorThrown)
1936
  {
1937
  setTimeout(function()
1938
  {
1939
- wpvivid_monitor_download_restore_task();
1940
  }, 1000);
1941
  });
1942
  }
1943
 
1944
- function wpvivid_update_restore_msg(msg)
1945
- {
1946
- //jQuery('#wpvivid_restore_log:last-child').html(msg);
1947
- jQuery('#wpvivid_restore_log > div:last').append(msg);
1948
- }
1949
-
1950
  /**
1951
  * Monitor restore task.
1952
  */
1953
- function wpvivid_monitor_restore_task(){
 
 
 
 
 
 
 
 
1954
  var ajax_data={
1955
  'action':'wpvivid_get_restore_progress',
1956
  'wpvivid_restore' : '1',
1957
  };
1958
 
1959
- wpvivid_post_request(ajax_data, function(data)
1960
- {
1961
- try {
1962
- var jsonarray = jQuery.parseJSON(data);
 
 
 
 
 
 
 
 
 
 
 
1963
 
1964
- if(typeof jsonarray ==='object')
1965
- {
1966
- if(jsonarray.result === "success")
1967
- {
1968
- jQuery('#wpvivid_restore_log').html("");
1969
- while(jsonarray.log.indexOf('\n') >= 0){
1970
- var iLength = jsonarray.log.indexOf('\n');
1971
- var log = jsonarray.log.substring(0, iLength);
1972
- jsonarray.log = jsonarray.log.substring(iLength+1);
1973
- var insert_log = "<div style=\"clear:both;\">"+log+"</div>";
1974
- jQuery('#wpvivid_restore_log').append(insert_log);
1975
- }
1976
 
1977
- if(jsonarray.status==='wait')
1978
- {
1979
- wpvivid_restoring = true;
1980
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1981
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1982
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1983
- jQuery('#wpvivid_restore_part').show();
1984
- jQuery('#wpvivid_clean_part').hide();
1985
- jQuery('#wpvivid_rollback_part').hide();
1986
- wpvivid_restore();
1987
- setTimeout(function()
1988
- {
1989
- wpvivid_monitor_restore_task();
1990
- }, 1000);
1991
- }
1992
- else if(jsonarray.status==='completed')
1993
- {
1994
- wpvivid_restoring = false;
1995
- wpvivid_restore();
1996
- wpvivid_restore_unlock();
1997
- alert("Restore completed successfully.");
1998
- location.reload();
1999
- }
2000
- else if(jsonarray.status==='error')
2001
- {
2002
- wpvivid_restoring = false;
2003
- alert("Restore failed, click rollback button to rollback.");
2004
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2005
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2006
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2007
- jQuery('#wpvivid_restore_part').hide();
2008
- jQuery('#wpvivid_clean_part').hide();
2009
- jQuery('#wpvivid_rollback_part').show();
 
 
 
 
 
 
 
2010
  }
2011
- else
2012
- {
2013
- setTimeout(function()
2014
- {
2015
- wpvivid_monitor_restore_task();
2016
  }, 1000);
2017
  }
2018
  }
2019
- else
2020
- {
2021
- setTimeout(function()
2022
- {
2023
- wpvivid_monitor_restore_task();
2024
  }, 1000);
2025
  }
2026
  }
2027
- else
2028
- {
2029
- setTimeout(function()
2030
- {
2031
- wpvivid_monitor_restore_task();
2032
  }, 1000);
2033
  }
2034
- }
2035
- catch(err){
2036
- setTimeout(function()
2037
- {
2038
- wpvivid_monitor_restore_task();
2039
  }, 1000);
2040
- }
2041
- }, function(XMLHttpRequest, textStatus, errorThrown)
2042
- {
2043
- setTimeout(function()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2044
  {
2045
- wpvivid_monitor_restore_task();
2046
- }, 1000);
 
 
 
 
 
 
 
2047
  });
2048
- }
2049
 
2050
- function wpvivid_restore(){
2051
  var restore_options = {
2052
  0:'backup_db',
2053
  1:'backup_themes',
@@ -2056,6 +2242,7 @@ function wpvivid_restore(){
2056
  4:'backup_content',
2057
  5:'backup_core'
2058
  };
 
2059
  var json = JSON.stringify(restore_options);
2060
  var ajax_data={
2061
  'action':'wpvivid_restore',
@@ -2063,12 +2250,23 @@ function wpvivid_restore(){
2063
  'backup_id':m_restore_backup_id,
2064
  'restore_options':json
2065
  };
 
 
 
2066
  wpvivid_post_request(ajax_data, function(data) {
2067
  }, function(XMLHttpRequest, textStatus, errorThrown) {
2068
  });
2069
  }
2070
 
2071
- function wpvivid_display_restore_msg(msg, div_id, append = true){
 
 
 
 
 
 
 
 
2072
  if(typeof div_id == 'undefined') {
2073
  var restore_msg = "<div style=\"clear:both;\">" + msg + "</div>";
2074
  }
@@ -2076,7 +2274,7 @@ function wpvivid_display_restore_msg(msg, div_id, append = true){
2076
  var restore_msg = "<div id=\"restore_file_"+div_id+"\" style=\"clear:both;\">" + msg + "</div>";
2077
  }
2078
  if(append == true) {
2079
- jQuery('#wpvivid_restore_log').append(restore_msg);
2080
  }
2081
  else{
2082
  if(jQuery('#restore_file_'+div_id).length )
@@ -2085,30 +2283,40 @@ function wpvivid_display_restore_msg(msg, div_id, append = true){
2085
  }
2086
  else
2087
  {
2088
- jQuery('#wpvivid_restore_log').append(restore_msg);
2089
  }
2090
-
2091
  }
 
 
2092
  }
2093
 
2094
  /**
2095
  * Delete the last incomplete restore task.
2096
  */
2097
- function wpvivid_delete_incompleted_restore(){
 
 
 
 
 
 
 
 
2098
  var ajax_data={
2099
  'action': 'wpvivid_delete_last_restore_data'
2100
  };
2101
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2102
- jQuery('#wpvivid_clean_restore').css({'pointer-events': 'auto', 'opacity': '1'});
2103
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2104
- jQuery('#wpvivid_restore_part').hide();
2105
- jQuery('#wpvivid_clean_part').show();
2106
- jQuery('#wpvivid_rollback_part').hide();
2107
  wpvivid_post_request(ajax_data, function(data) {
2108
  try {
2109
  var jsonarray = jQuery.parseJSON(data);
2110
  if (jsonarray.result === "success") {
2111
- wpvivid_init_restore_data();
 
2112
  }
2113
  }
2114
  catch(err){
@@ -2116,20 +2324,36 @@ function wpvivid_delete_incompleted_restore(){
2116
  }
2117
  }, function(XMLHttpRequest, textStatus, errorThrown) {
2118
  var error_message = wpvivid_output_ajaxerror('deleting the last incomplete restore task', textStatus, errorThrown);
2119
- wpvivid_display_restore_msg(error_message);
2120
  });
2121
  }
2122
 
2123
  /**
2124
  * This function will start rollback task.
2125
  */
2126
- function wpvivid_start_rollback(){
2127
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2128
- wpvivid_monitor_rollback_task();
2129
- wpvivid_rollback();
 
 
 
 
 
 
 
 
2130
  }
2131
 
2132
- function wpvivid_rollback(){
 
 
 
 
 
 
 
 
2133
  var ajax_data={
2134
  'action': 'wpvivid_rollback'
2135
  };
@@ -2137,12 +2361,12 @@ function wpvivid_rollback(){
2137
  try {
2138
  var jsonarray = jQuery.parseJSON(data);
2139
  if (jsonarray.result === "success") {
2140
- wpvivid_display_restore_msg("Rollback completed.");
2141
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2142
  }
2143
  else if (jsonarray.result === "failed") {
2144
- wpvivid_display_restore_msg(jsonarray.error);
2145
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2146
  }
2147
  }
2148
  catch(err){
@@ -2150,14 +2374,22 @@ function wpvivid_rollback(){
2150
  }
2151
  }, function(XMLHttpRequest, textStatus, errorThrown) {
2152
  var error_message = wpvivid_output_ajaxerror('starting rollbacking', textStatus, errorThrown);
2153
- wpvivid_display_restore_msg(error_message);
2154
  });
2155
  }
2156
 
2157
  /**
2158
  * This function will monitor the rollback task.
2159
  */
2160
- function wpvivid_monitor_rollback_task(){
 
 
 
 
 
 
 
 
2161
  var ajax_data={
2162
  'action':'wpvivid_get_rollback_progress',
2163
  'wpvivid_restore':'1',
@@ -2170,41 +2402,41 @@ function wpvivid_monitor_rollback_task(){
2170
  {
2171
  if(jsonarray.result === "success")
2172
  {
2173
- jQuery('#wpvivid_restore_log').html("");
2174
  while(jsonarray.log.indexOf('\n') >= 0){
2175
  var iLength = jsonarray.log.indexOf('\n');
2176
  var log = jsonarray.log.substring(0, iLength);
2177
  jsonarray.log = jsonarray.log.substring(iLength+1);
2178
  var insert_log = "<div style=\"clear:both;\">"+log+"</div>";
2179
- jQuery('#wpvivid_restore_log').append(insert_log);
2180
  }
2181
 
2182
  if(jsonarray.status==='wait')
2183
  {
2184
  wpvivid_restoring = true;
2185
- wpvivid_rollback();
2186
  setTimeout(function()
2187
  {
2188
- wpvivid_monitor_rollback_task();
2189
  }, 1000);
2190
  }
2191
  else if(jsonarray.status==='completed')
2192
  {
2193
  wpvivid_restoring = false;
2194
- wpvivid_rollback();
2195
  wpvivid_restore_unlock();
2196
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2197
  }
2198
  else if(jsonarray.status==='error')
2199
  {
2200
  wpvivid_restoring = false;
2201
- jQuery('#wpvivid_rollback_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2202
  }
2203
  else
2204
  {
2205
  setTimeout(function()
2206
  {
2207
- wpvivid_monitor_rollback_task();
2208
  }, 1000);
2209
  }
2210
  }
@@ -2212,7 +2444,7 @@ function wpvivid_monitor_rollback_task(){
2212
  {
2213
  setTimeout(function()
2214
  {
2215
- wpvivid_monitor_rollback_task();
2216
  }, 1000);
2217
  }
2218
  }
@@ -2220,20 +2452,20 @@ function wpvivid_monitor_rollback_task(){
2220
  {
2221
  setTimeout(function()
2222
  {
2223
- wpvivid_monitor_rollback_task();
2224
  }, 1000);
2225
  }
2226
  }
2227
  catch(err){
2228
  setTimeout(function()
2229
  {
2230
- wpvivid_monitor_rollback_task();
2231
  }, 1000);
2232
  }
2233
  }, function(XMLHttpRequest, textStatus, errorThrown) {
2234
  setTimeout(function()
2235
  {
2236
- wpvivid_monitor_rollback_task();
2237
  }, 1000);
2238
  });
2239
  }
@@ -2254,6 +2486,15 @@ function wpvivid_restore_lock(){
2254
  jQuery('#settings-page').css({'pointer-events': 'none', 'opacity': '1'});
2255
  jQuery('#debug-page').css({'pointer-events': 'none', 'opacity': '1'});
2256
  jQuery('#logs-page').css({'pointer-events': 'none', 'opacity': '1'});
 
 
 
 
 
 
 
 
 
2257
  }
2258
 
2259
  /**
@@ -2272,6 +2513,15 @@ function wpvivid_restore_unlock(){
2272
  jQuery('#settings-page').css({'pointer-events': 'auto', 'opacity': '1'});
2273
  jQuery('#debug-page').css({'pointer-events': 'auto', 'opacity': '1'});
2274
  jQuery('#logs-page').css({'pointer-events': 'auto', 'opacity': '1'});
 
 
 
 
 
 
 
 
 
2275
  }
2276
 
2277
  /**
@@ -2288,6 +2538,7 @@ function wpvivid_delete_out_of_date_backups(){
2288
  var jsonarray = jQuery.parseJSON(data);
2289
  if (jsonarray.result === "success") {
2290
  alert("Out of date backups have been removed.");
 
2291
  }
2292
  }
2293
  catch(err){
17
  var wpvivid_restore_download_array;
18
  var wpvivid_restore_download_index = 0;
19
  var wpvivid_get_download_restore_progress_retry = 0;
20
+ var wpvivid_restore_timeout = false;
21
+ var wpvivid_restore_need_download = false;
22
+ var wpvivid_restore_backup_old_site = false;
23
 
24
  (function ($) {
25
  'use strict';
266
  }
267
  else if (value.status.str === 'running') {
268
  running_backup_taskid = index;
269
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
270
+ wpvivid_control_backup_lock();
271
  jQuery('#wpvivid_postbox_backup_percent').show();
272
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
273
  m_need_update = true;
274
  }
275
  else if (value.status.str === 'wait_resume') {
276
  running_backup_taskid = index;
277
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
278
+ wpvivid_control_backup_lock();
279
  jQuery('#wpvivid_postbox_backup_percent').show();
280
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
281
  if (value.data.next_resume_time !== 'get next resume time failed.') {
287
  }
288
  else if (value.status.str === 'no_responds') {
289
  running_backup_taskid = index;
290
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
291
+ wpvivid_control_backup_lock();
292
  jQuery('#wpvivid_postbox_backup_percent').show();
293
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
294
  m_need_update = true;
295
  }
296
  else if (value.status.str === 'completed') {
297
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
298
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
299
+ wpvivid_control_backup_unlock();
300
  jQuery('#wpvivid_postbox_backup_percent').hide();
301
  jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
302
  jQuery('#wpvivid_loglist').html("");
309
  }
310
  else if (value.status.str === 'error') {
311
  jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
312
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
313
+ wpvivid_control_backup_unlock();
314
  jQuery('#wpvivid_postbox_backup_percent').hide();
315
  jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
316
  jQuery('#wpvivid_loglist').html("");
328
  {
329
  jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
330
  jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
331
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
332
+ wpvivid_control_backup_unlock();
333
  jQuery('#wpvivid_postbox_backup_percent').hide();
334
  wpvivid_retrieve_backup_list();
335
  wpvivid_retrieve_last_backup_message();
337
  running_backup_taskid='';
338
  }
339
  }
340
+ if (jsonarray.download.length !== 0) {
341
  b_has_data = true;
342
  task_retry_times = 0;
343
  var i = 0;
 
344
  var file_name = '';
345
  jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).html("");
346
  var b_download_finish=false;
347
+ jQuery.each(jsonarray.download.files, function (index, value) {
348
  i++;
349
+ file_name = index;
350
  var progress = '0%';
351
+ if (value.status === 'need_download') {
352
  if (m_downloading_file_name === file_name) {
353
  m_need_update = true;
354
  }
355
+ jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
356
+ //b_download_finish=true;
357
  }
358
+ else if (value.status === 'running') {
359
  if (m_downloading_file_name === file_name) {
360
  wpvivid_lock_download(tmp_current_click_backupid);
361
  }
362
  m_need_update = true;
363
+ jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
364
  b_download_finish=false;
365
  }
366
+ else if (value.status === 'completed') {
367
  if (m_downloading_file_name === file_name) {
368
  wpvivid_unlock_download(tmp_current_click_backupid);
369
  m_downloading_id = '';
370
  m_downloading_file_name = '';
371
  }
372
+ jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
373
  b_download_finish=true;
374
  }
375
+ else if (value.status === 'error') {
376
  if (m_downloading_file_name === file_name) {
377
  wpvivid_unlock_download(tmp_current_click_backupid);
378
  m_downloading_id = '';
379
  m_downloading_file_name = '';
380
  }
381
+ alert(value.error);
382
+ jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
383
  b_download_finish=true;
384
  }
385
+ else if (value.status === 'timeout') {
386
  if (m_downloading_file_name === file_name) {
387
  wpvivid_unlock_download(tmp_current_click_backupid);
388
  m_downloading_id = '';
389
  m_downloading_file_name = '';
390
  }
391
  alert('Download timeout, please retry.');
392
+ jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
393
  b_download_finish=true;
394
  }
395
  });
396
+ jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(jsonarray.download.place_html);
397
  if(b_download_finish==true){
398
  tmp_current_click_backupid = '';
399
  }
 
400
  }
401
  if (!b_has_data) {
402
  task_retry_times++;
403
+ if (task_retry_times < 5) {
404
  m_need_update = true;
405
  }
406
  }
536
  }
537
  }
538
 
539
+ function wpvivid_control_backup_lock(){
540
+ jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
541
+ jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
542
+ }
543
+
544
+ function wpvivid_control_backup_unlock(){
545
+ jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
546
+ jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
547
+ }
548
+
549
  /**
550
  * Start backing up
551
  */
569
  'action': 'wpvivid_prepare_backup',
570
  'backup': backup_data
571
  };
572
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
573
+ wpvivid_control_backup_lock();
574
  jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
575
  jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
576
  jQuery('#wpvivid_postbox_backup_percent').show();
613
  else {
614
  jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
615
  jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
616
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
617
+ wpvivid_control_backup_unlock();
618
  jQuery('#wpvivid_postbox_backup_percent').hide();
619
  }
620
  }
640
  var jsonarray = jQuery.parseJSON(data);
641
  if (jsonarray.result === 'success') {
642
  wpvivid_add_notice('Backup', 'Error', error);
643
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
644
+ wpvivid_control_backup_unlock();
645
  jQuery('#wpvivid_postbox_backup_percent').hide();
646
  }
647
  }
648
  catch(err){
649
  wpvivid_add_notice('Backup', 'Error', err);
650
+ //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
651
+ wpvivid_control_backup_unlock();
652
  jQuery('#wpvivid_postbox_backup_percent').hide();
653
  }
654
  }, function (XMLHttpRequest, textStatus, errorThrown) {
745
  {
746
  var error_message = wpvivid_output_ajaxerror('adding the remote storage', textStatus, errorThrown);
747
  alert(error_message);
748
+ jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
749
  });
750
  }
751
 
1148
  jQuery('#wpvivid_storage_account_block input[type=checkbox]').on("change", function(){
1149
  wpvivid_settings_changed = true;
1150
  });
1151
+
1152
+ jQuery('input:radio[option=restore]').click(function() {
1153
+ jQuery('input:radio[option=restore]').each(function () {
1154
+ if (jQuery(this).prop('checked')) {
1155
+ jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1156
+ }
1157
+ });
1158
+ });
1159
  }
1160
 
1161
  /**
1209
  jQuery('#'+notice_id).show();
1210
  var div = '';
1211
  if(notice_type === "Warning"){
1212
+ div = "<div class='notice notice-warning is-dismissible inline'><p>Warning: " + notice_msg + "</p>" +
1213
  "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
1214
  "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1215
  "</button>" +
1222
  wpvivid_clear_notice('wpvivid_backup_notice');
1223
  jQuery('#wpvivid_backup_notice').show();
1224
  var success_msg = wpvivid_completed_backup + " backup tasks have been completed. Please switch to <a href=\"#\" onclick=\"wpvivid_click_switch_page('wrap', 'wpvivid_tab_log', true);\">Log</a> page to check the details.\n";
1225
+ div = "<div class='notice notice-success is-dismissible inline'><p>" + success_msg + "</p>" +
1226
  "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
1227
  "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1228
  "</button>" +
1230
  wpvivid_completed_backup++;
1231
  }
1232
  else if(notice_type === "Info"){
1233
+ div = "<div class='notice notice-info is-dismissible inline'><p>" + notice_msg + "</p>" +
1234
  "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
1235
  "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1236
  "</button>" +
1324
  jQuery('#wpvivid_file_part_' + backup_id).html("");
1325
  var i = 0;
1326
  var file_not_found = false;
 
1327
  var file_name = '';
1328
+ jQuery.each(jsonarray.files, function (index, value) {
1329
  i++;
1330
+ file_name = index;
1331
+ if (value.status === 'need_download') {
1332
+ jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
1333
+ //tmp_current_click_backupid = '';
1334
  }
1335
+ else if (value.status === 'running') {
1336
  if (m_downloading_file_name === file_name) {
1337
  wpvivid_lock_download(tmp_current_click_backupid);
1338
  }
1339
+ jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
1340
  }
1341
+ else if (value.status === 'completed') {
1342
  if (m_downloading_file_name === file_name) {
1343
  wpvivid_unlock_download(tmp_current_click_backupid);
1344
  m_downloading_id = '';
1345
  m_downloading_file_name = '';
1346
  }
1347
+ jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
1348
+ //tmp_current_click_backupid = '';
1349
  }
1350
+ else if (value.status === 'timeout') {
1351
  if (m_downloading_file_name === file_name) {
1352
  wpvivid_unlock_download(tmp_current_click_backupid);
1353
  m_downloading_id = '';
1354
  m_downloading_file_name = '';
1355
  }
1356
+ jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
1357
+ //tmp_current_click_backupid = '';
1358
  }
1359
+ else if (value.status === 'file_not_found') {
1360
  wpvivid_unlock_download(tmp_current_click_backupid);
1361
  wpvivid_reset_backup_list();
1362
  file_not_found = true;
1363
  alert("Download failed, file not found. The file might has been moved, renamed or deleted. Please verify the file exists and try again.");
1364
+ //tmp_current_click_backupid = '';
1365
  return false;
1366
  }
1367
  });
1368
  if (file_not_found === false) {
1369
+ jQuery('#wpvivid_file_part_' + backup_id).append(jsonarray.place_html);
1370
  }
 
1371
  }
1372
  }
1373
  catch(err){
1455
  {
1456
  }, function(XMLHttpRequest, textStatus, errorThrown)
1457
  {
 
 
 
 
 
 
 
 
1458
  }, 0);
1459
  }
1460
 
1510
  case "backup":
1511
  wpvivid_click_switch_page('wrap', 'wpvivid_tab_general', false);
1512
  break;
1513
+ case "transfer":
1514
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_migrate', false);
1515
+ break;
1516
  case "settings":
1517
  wpvivid_click_switch_page('wrap', 'wpvivid_tab_setting', false);
1518
  break;
1525
  case "log":
1526
  wpvivid_click_switch_page('wrap', 'wpvivid_tab_log', false);
1527
  break;
1528
+ case "key":
1529
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_key', false);
1530
+ break;
1531
  default:
1532
  wpvivid_click_switch_page('wrap', 'wpvivid_tab_general', false);
1533
  break;
1663
  });
1664
  }
1665
 
1666
+ function wpvivid_initialize_restore(backup_id, backup_time, restore_type='backup'){
1667
+ var time_type = 'backup';
1668
+ var log_type = '';
1669
+ var tab_type = '';
1670
+ var page_type = 'backup';
1671
+ if(restore_type == 'backup'){
1672
+ time_type = 'backup';
1673
+ log_type = '';
1674
+ tab_type = '';
1675
+ page_type = 'backup';
1676
+ }
1677
+ else if(restore_type == 'transfer'){
1678
+ time_type = 'transfer';
1679
+ log_type = 'transfer_';
1680
+ tab_type = 'add_';
1681
+ page_type = 'migrate';
1682
+ }
1683
+ jQuery('#wpvivid_restore_'+time_type+'_time').html(backup_time);
1684
  m_restore_backup_id = backup_id;
1685
+ jQuery('#wpvivid_restore_'+log_type+'log').html("");
1686
+ jQuery('#wpvivid_'+tab_type+'tab_restore').show();
1687
+ wpvivid_click_switch_page(page_type, 'wpvivid_'+tab_type+'tab_restore', true);
1688
+ wpvivid_init_restore_data(restore_type);
1689
  }
1690
 
1691
  /**
1693
  *
1694
  * @param backup_id - The unique ID for the backup
1695
  */
1696
+ function wpvivid_init_restore_data(restore_type){
1697
+ var restore_method = '';
1698
+ if(restore_type == 'backup'){
1699
+ restore_method = '';
1700
+ }
1701
+ else if(restore_type == 'transfer'){
1702
+ restore_method = 'transfer_';
1703
+ }
1704
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1705
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1706
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1707
+ jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1708
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1709
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1710
+ jQuery('#wpvivid_restore_is_migrate').hide();
1711
+ jQuery('#wpvivid_restore_backup_old_site').hide();
1712
  var ajax_data = {
1713
  'action':'wpvivid_init_restore_page',
1714
  'backup_id':m_restore_backup_id
1716
  wpvivid_post_request(ajax_data, function(data){
1717
  try {
1718
  var jsonarray = jQuery.parseJSON(data);
1719
+ var init_status = false;
1720
+ if(jsonarray.result === 'success') {
1721
+ init_status = true;
 
 
1722
  }
1723
+ else if (jsonarray.result === "need_download"){
1724
+ init_status = true;
1725
+ wpvivid_restore_download_array = new Array();
1726
+ var download_num = 0;
1727
+ wpvivid_display_restore_msg("Backup is not found on web server. Prepare to download it from remote storage.", restore_type);
1728
+ jQuery.each(jsonarray.files, function (index, value)
1729
+ {
1730
+ if (value.status === "need_download")
1731
+ {
1732
+ wpvivid_restore_download_array[download_num] = new Array('file_name', 'size', 'md5');
1733
+ wpvivid_restore_download_array[download_num]['file_name'] = index;
1734
+ wpvivid_restore_download_array[download_num]['size'] = value.size;
1735
+ wpvivid_restore_download_array[download_num]['md5'] = value.md5;
1736
+ download_num++;
1737
+ }
1738
+ });
1739
+ wpvivid_restore_download_index=0;
1740
+ wpvivid_restore_need_download = true;
1741
+ }
1742
+ else if (jsonarray.result === "failed") {
1743
+ wpvivid_display_restore_msg(jsonarray.error, restore_type);
1744
+ }
1745
+
1746
+ if(init_status){
1747
+ if (jsonarray.has_exist_restore === 0) {
1748
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({
1749
+ 'pointer-events': 'auto',
1750
+ 'opacity': '1'
1751
+ });
1752
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({
1753
+ 'pointer-events': 'none',
1754
+ 'opacity': '0.4'
1755
+ });
1756
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({
1757
+ 'pointer-events': 'none',
1758
+ 'opacity': '0.4'
1759
+ });
1760
+ jQuery('#wpvivid_restore_' + restore_method + 'part').show();
1761
+ jQuery('#wpvivid_restore_backup_old_site').show();
1762
+ if (jsonarray.is_migrate === 1) {
1763
+ jQuery('#wpvivid_restore_is_migrate').show();
1764
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1765
+ jQuery('#wpvivid_replace_domain').prop('checked', false);
1766
+ jQuery('#wpvivid_keep_domain').prop('checked', false);
1767
+ }
1768
+ else {
1769
+ jQuery('#wpvivid_restore_is_migrate').hide();
1770
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1771
+ }
1772
+ if (jsonarray.skip_backup_old_site === 1) {
1773
+ jQuery('#wpvivid_restore_backup_old_site input').prop('checked', false);
1774
+ }
1775
+ else {
1776
+ jQuery('#wpvivid_restore_backup_old_site input').prop('checked', true);
1777
+ }
1778
+ wpvivid_interface_flow_control();
1779
+ }
1780
+ else if (jsonarray.has_exist_restore === 1) {
1781
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({
1782
+ 'pointer-events': 'none',
1783
+ 'opacity': '0.4'
1784
+ });
1785
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({
1786
+ 'pointer-events': 'auto',
1787
+ 'opacity': '1'
1788
+ });
1789
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({
1790
+ 'pointer-events': 'none',
1791
+ 'opacity': '0.4'
1792
+ });
1793
+ jQuery('#wpvivid_clean_' + restore_method + 'part').show();
1794
+ jQuery('#wpvivid_restore_is_migrate').hide();
1795
+ jQuery('#wpvivid_restore_backup_old_site').hide();
1796
+ wpvivid_display_restore_msg("An uncompleted restore task exists, please delete it first.", restore_type);
1797
  }
1798
  }
1799
  }
1802
  }
1803
  }, function(XMLHttpRequest, textStatus, errorThrown) {
1804
  var error_message = wpvivid_output_ajaxerror('initializing restore information', textStatus, errorThrown);
1805
+ wpvivid_display_restore_msg(error_message, restore_type);
1806
  });
1807
  }
1808
 
1809
  /**
1810
  * This function will start the process of restoring a backup
1811
  */
1812
+ function wpvivid_start_restore(restore_type = 'backup'){
1813
+ var descript = 'Are you sure to continue?';
1814
+ var ret = confirm(descript);
1815
+ if (ret === true) {
1816
+
1817
+ var restore_method = '';
1818
+ if (restore_type == 'backup') {
1819
+ restore_method = '';
1820
+ }
1821
+ else if (restore_type == 'transfer') {
1822
+ restore_method = 'transfer_';
1823
+ }
1824
+ jQuery('#wpvivid_restore_' + restore_method + 'log').html("");
1825
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1826
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1827
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1828
+ jQuery('#wpvivid_restore_' + restore_method + 'part').show();
1829
+ jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
1830
+ jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
1831
+ wpvivid_restore_lock();
1832
+ wpvivid_restoring = true;
1833
+ if (wpvivid_restore_need_download) {
1834
+ wpvivid_download_restore_file(restore_type);
1835
+ }
1836
+ else {
1837
+ wpvivid_monitor_restore_task(restore_type);
1838
+ wpvivid_restore(restore_type);
1839
+ }
1840
+ }
1841
  }
1842
 
1843
+ function wpvivid_prepare_restore(restore_type){
1844
+ var restore_method = '';
1845
+ if(restore_type == 'backup'){
1846
+ restore_method = '';
1847
+ }
1848
+ else if(restore_type == 'transfer'){
1849
+ restore_method = 'transfer_';
1850
+ }
1851
  var restore_options = {
1852
  0:'backup_db',
1853
  1:'backup_themes',
1863
  'backup_id':m_restore_backup_id,
1864
  'restore_options':json
1865
  };
1866
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1867
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1868
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1869
+ jQuery('#wpvivid_restore_'+restore_method+'part').show();
1870
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1871
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1872
  wpvivid_restoring = true;
1873
  wpvivid_post_request(ajax_data, function(data)
1874
  {
1877
  var jsonarray = jQuery.parseJSON(data);
1878
  if (jsonarray.result === "success")
1879
  {
1880
+ wpvivid_display_restore_msg("Prepare to start restoring.", restore_type);
1881
  wpvivid_restore_lock();
1882
+ wpvivid_monitor_restore_task(restore_type);
1883
+ wpvivid_restore(restore_type);
1884
  }
1885
  else if (jsonarray.result === "need_download")
1886
  {
1887
  wpvivid_restore_lock();
1888
  wpvivid_restore_download_array = new Array();
1889
  var download_num = 0;
1890
+ wpvivid_display_restore_msg("Backup is not found on web server. Prepare to download it from remote storage.", restore_type);
1891
  jQuery.each(jsonarray.files, function (index, value)
1892
  {
1893
  if (value.status === "need_download")
1900
  }
1901
  });
1902
  wpvivid_restore_download_index=0;
1903
+ wpvivid_download_restore_file(restore_type);
1904
  }
1905
+ else if (jsonarray.result === "failed")
1906
  {
1907
+ wpvivid_display_restore_msg(jsonarray.error, restore_type);
1908
  }
1909
  }
1910
  catch(err)
1911
  {
1912
  alert(err);
1913
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1914
  }
1915
  }, function(XMLHttpRequest, textStatus, errorThrown)
1916
  {
1917
  var error_message = wpvivid_output_ajaxerror('preparing to restore', textStatus, errorThrown);
1918
+ wpvivid_display_restore_msg(error_message, restore_type);
1919
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1920
  });
1921
  }
1922
 
1923
+ function wpvivid_download_restore_file(restore_type)
1924
  {
1925
+ var restore_method = '';
1926
+ if(restore_type == 'backup'){
1927
+ restore_method = '';
1928
+ }
1929
+ else if(restore_type == 'transfer'){
1930
+ restore_method = 'transfer_';
1931
+ }
1932
+
1933
  if(wpvivid_restore_download_array.length===0)
1934
  {
1935
+ wpvivid_display_restore_msg("Downloading backup file failed. Backup file might be deleted or network doesn't work properly. Please verify the file and confirm the network connection and try again later.", restore_type);
1936
  wpvivid_restore_unlock();
1937
  return false;
1938
  }
1939
 
1940
  if(wpvivid_restore_download_index+1>wpvivid_restore_download_array.length)
1941
  {
1942
+ wpvivid_display_restore_msg("Download succeeded.", restore_type);
1943
  //return true;
1944
+ wpvivid_restore_need_download = false;
1945
+ wpvivid_start_restore(restore_type);
1946
  }
1947
  else
1948
  {
1949
+ wpvivid_display_restore_msg("Downloading backup file " + wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'], restore_type);
1950
+ wpvivid_display_restore_msg('', restore_type, wpvivid_restore_download_index);
1951
  var ajax_data = {
1952
  'action': 'wpvivid_download_restore',
1953
  'backup_id': m_restore_backup_id,
1956
  'md5': wpvivid_restore_download_array[wpvivid_restore_download_index]['md5']
1957
  }
1958
  wpvivid_get_download_restore_progress_retry=0;
1959
+ wpvivid_monitor_download_restore_task(restore_type);
1960
+ wpvivid_post_request(ajax_data, function (data) {
1961
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
 
 
 
 
 
 
 
 
 
 
 
 
1962
  }, 0);
1963
  }
1964
  }
1965
 
1966
+ function wpvivid_monitor_download_restore_task(restore_type)
1967
  {
1968
+ var restore_method = '';
1969
+ if(restore_type == 'backup'){
1970
+ restore_method = '';
1971
+ }
1972
+ else if(restore_type == 'transfer'){
1973
+ restore_method = 'transfer_';
1974
+ }
1975
+
1976
  var ajax_data={
1977
  'action':'wpvivid_get_download_restore_progress',
1978
  'file_name': wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],
1991
  {
1992
  if(jsonarray.status==='completed')
1993
  {
1994
+ wpvivid_display_restore_msg(wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'] + ' download succeeded.', restore_type, wpvivid_restore_download_index, false);
 
1995
  wpvivid_restore_download_index++;
1996
+ wpvivid_download_restore_file(restore_type);
1997
  }
1998
  else if(jsonarray.status==='error')
1999
  {
2000
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2001
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2002
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2003
+ jQuery('#wpvivid_restore_'+restore_method+'part').show();
2004
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
2005
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2006
  var error_message = jsonarray.error;
2007
+ wpvivid_display_restore_msg(error_message,restore_type,wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],false);
2008
  wpvivid_restore_unlock();
2009
  }
2010
  else if(jsonarray.status==='running')
2011
  {
2012
+ wpvivid_display_restore_msg(jsonarray.log, restore_type, wpvivid_restore_download_index, false);
 
2013
  setTimeout(function()
2014
  {
2015
+ wpvivid_monitor_download_restore_task(restore_type);
2016
  }, 3000);
2017
  }
2018
  else if(jsonarray.status==='timeout')
2020
  wpvivid_get_download_restore_progress_retry++;
2021
  if(wpvivid_get_download_restore_progress_retry>10)
2022
  {
2023
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2024
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2025
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2026
+ jQuery('#wpvivid_restore_'+restore_method+'part').show();
2027
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
2028
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2029
  var error_message = jsonarray.error;
2030
+ wpvivid_display_restore_msg(error_message, restore_type);
2031
  wpvivid_restore_unlock();
2032
  }
2033
  else
2034
  {
2035
  setTimeout(function()
2036
  {
2037
+ wpvivid_monitor_download_restore_task(restore_type);
2038
  }, 3000);
2039
  }
2040
  }
2042
  {
2043
  setTimeout(function()
2044
  {
2045
+ wpvivid_monitor_download_restore_task(restore_type);
2046
  }, 3000);
2047
  }
2048
  }
2051
  wpvivid_get_download_restore_progress_retry++;
2052
  if(wpvivid_get_download_restore_progress_retry>10)
2053
  {
2054
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2055
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2056
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2057
+ jQuery('#wpvivid_restore_'+restore_method+'part').show();
2058
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
2059
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2060
  var error_message = jsonarray.error;
2061
+ wpvivid_display_restore_msg(error_message, restore_type);
2062
  wpvivid_restore_unlock();
2063
  }
2064
  else
2065
  {
2066
  setTimeout(function()
2067
  {
2068
+ wpvivid_monitor_download_restore_task(restore_type);
2069
  }, 3000);
2070
  }
2071
  }
2074
  {
2075
  setTimeout(function()
2076
  {
2077
+ wpvivid_monitor_download_restore_task(restore_type);
2078
  }, 3000);
2079
  }
2080
  }
2081
  catch(err){
2082
  setTimeout(function()
2083
  {
2084
+ wpvivid_monitor_download_restore_task(restore_type);
2085
  }, 3000);
2086
  }
2087
  }, function(XMLHttpRequest, textStatus, errorThrown)
2088
  {
2089
  setTimeout(function()
2090
  {
2091
+ wpvivid_monitor_download_restore_task(restore_type);
2092
  }, 1000);
2093
  });
2094
  }
2095
 
 
 
 
 
 
 
2096
  /**
2097
  * Monitor restore task.
2098
  */
2099
+ function wpvivid_monitor_restore_task(restore_type){
2100
+ var restore_method = '';
2101
+ if(restore_type == 'backup'){
2102
+ restore_method = '';
2103
+ }
2104
+ else if(restore_type == 'transfer'){
2105
+ restore_method = 'transfer_';
2106
+ }
2107
+
2108
  var ajax_data={
2109
  'action':'wpvivid_get_restore_progress',
2110
  'wpvivid_restore' : '1',
2111
  };
2112
 
2113
+ if(wpvivid_restore_timeout){
2114
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2115
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2116
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2117
+ jQuery('#wpvivid_restore_'+restore_method+'part').show();
2118
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
2119
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2120
+ wpvivid_restore_unlock();
2121
+ wpvivid_restoring = false;
2122
+ wpvivid_display_restore_msg("Website restore times out.", restore_type);
2123
+ }
2124
+ else {
2125
+ wpvivid_post_request(ajax_data, function (data) {
2126
+ try {
2127
+ var jsonarray = jQuery.parseJSON(data);
2128
 
2129
+ if (typeof jsonarray === 'object') {
2130
+ if (jsonarray.result === "success") {
2131
+ jQuery('#wpvivid_restore_' + restore_method + 'log').html("");
2132
+ while (jsonarray.log.indexOf('\n') >= 0) {
2133
+ var iLength = jsonarray.log.indexOf('\n');
2134
+ var log = jsonarray.log.substring(0, iLength);
2135
+ jsonarray.log = jsonarray.log.substring(iLength + 1);
2136
+ var insert_log = "<div style=\"clear:both;\">" + log + "</div>";
2137
+ jQuery('#wpvivid_restore_' + restore_method + 'log').append(insert_log);
2138
+ var div = jQuery('#wpvivid_restore_' + restore_method + 'log');
2139
+ div[0].scrollTop = div[0].scrollHeight;
2140
+ }
2141
 
2142
+ if (jsonarray.status === 'wait') {
2143
+ wpvivid_restoring = true;
2144
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({
2145
+ 'pointer-events': 'none',
2146
+ 'opacity': '0.4'
2147
+ });
2148
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({
2149
+ 'pointer-events': 'none',
2150
+ 'opacity': '0.4'
2151
+ });
2152
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({
2153
+ 'pointer-events': 'none',
2154
+ 'opacity': '0.4'
2155
+ });
2156
+ jQuery('#wpvivid_restore_' + restore_method + 'part').show();
2157
+ jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
2158
+ jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
2159
+ wpvivid_restore(restore_type);
2160
+ setTimeout(function () {
2161
+ wpvivid_monitor_restore_task(restore_type);
2162
+ }, 1000);
2163
+ }
2164
+ else if (jsonarray.status === 'completed') {
2165
+ wpvivid_restoring = false;
2166
+ wpvivid_restore(restore_type);
2167
+ wpvivid_restore_unlock();
2168
+ alert("Restore completed successfully.");
2169
+ location.reload();
2170
+ }
2171
+ else if (jsonarray.status === 'error') {
2172
+ wpvivid_restore_unlock();
2173
+ wpvivid_restoring = false;
2174
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2175
+ alert("Restore failed.");
2176
+ }
2177
+ else {
2178
+ setTimeout(function () {
2179
+ wpvivid_monitor_restore_task(restore_type);
2180
+ }, 1000);
2181
+ }
2182
  }
2183
+ else {
2184
+ setTimeout(function () {
2185
+ wpvivid_monitor_restore_task(restore_type);
 
 
2186
  }, 1000);
2187
  }
2188
  }
2189
+ else {
2190
+ setTimeout(function () {
2191
+ wpvivid_monitor_restore_task(restore_type);
 
 
2192
  }, 1000);
2193
  }
2194
  }
2195
+ catch (err) {
2196
+ setTimeout(function () {
2197
+ wpvivid_monitor_restore_task(restore_type);
 
 
2198
  }, 1000);
2199
  }
2200
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
2201
+ setTimeout(function () {
2202
+ wpvivid_monitor_restore_task(restore_type);
 
 
2203
  }, 1000);
2204
+ });
2205
+ }
2206
+ }
2207
+
2208
+ function wpvivid_restore(restore_type){
2209
+ var restore_method = '';
2210
+ if(restore_type == 'backup'){
2211
+ restore_method = '';
2212
+ }
2213
+ else if(restore_type == 'transfer'){
2214
+ restore_method = 'transfer_';
2215
+ }
2216
+
2217
+ var skip_old_site = '1';
2218
+ var extend_option = {
2219
+ 'skip_backup_old_site':skip_old_site,
2220
+ 'skip_backup_old_database':skip_old_site
2221
+ };
2222
+
2223
+ jQuery('input:radio[option=restore]').each(function() {
2224
+ if(jQuery(this).prop('checked'))
2225
  {
2226
+ var value = jQuery(this).prop('value');
2227
+ if(value == '1'){
2228
+ var is_migrate = '1';
2229
+ var migrate_option = {
2230
+ 'is_migrate':is_migrate,
2231
+ };
2232
+ jQuery.extend(extend_option, migrate_option);
2233
+ }
2234
+ }
2235
  });
 
2236
 
 
2237
  var restore_options = {
2238
  0:'backup_db',
2239
  1:'backup_themes',
2242
  4:'backup_content',
2243
  5:'backup_core'
2244
  };
2245
+ jQuery.extend(restore_options, extend_option);
2246
  var json = JSON.stringify(restore_options);
2247
  var ajax_data={
2248
  'action':'wpvivid_restore',
2250
  'backup_id':m_restore_backup_id,
2251
  'restore_options':json
2252
  };
2253
+ setTimeout(function () {
2254
+ wpvivid_restore_timeout = true;
2255
+ }, 1800000);
2256
  wpvivid_post_request(ajax_data, function(data) {
2257
  }, function(XMLHttpRequest, textStatus, errorThrown) {
2258
  });
2259
  }
2260
 
2261
+ function wpvivid_display_restore_msg(msg, restore_type, div_id, append = true){
2262
+ var restore_method = '';
2263
+ if(restore_type == 'backup'){
2264
+ restore_method = '';
2265
+ }
2266
+ else if(restore_type == 'transfer'){
2267
+ restore_method = 'transfer_';
2268
+ }
2269
+
2270
  if(typeof div_id == 'undefined') {
2271
  var restore_msg = "<div style=\"clear:both;\">" + msg + "</div>";
2272
  }
2274
  var restore_msg = "<div id=\"restore_file_"+div_id+"\" style=\"clear:both;\">" + msg + "</div>";
2275
  }
2276
  if(append == true) {
2277
+ jQuery('#wpvivid_restore_'+restore_method+'log').append(restore_msg);
2278
  }
2279
  else{
2280
  if(jQuery('#restore_file_'+div_id).length )
2283
  }
2284
  else
2285
  {
2286
+ jQuery('#wpvivid_restore_'+restore_method+'log').append(restore_msg);
2287
  }
 
2288
  }
2289
+ var div = jQuery('#wpvivid_restore_' + restore_method + 'log');
2290
+ div[0].scrollTop = div[0].scrollHeight;
2291
  }
2292
 
2293
  /**
2294
  * Delete the last incomplete restore task.
2295
  */
2296
+ function wpvivid_delete_incompleted_restore(restore_type = 'backup'){
2297
+ var restore_method = '';
2298
+ if(restore_type == 'backup'){
2299
+ restore_method = '';
2300
+ }
2301
+ else if(restore_type == 'transfer'){
2302
+ restore_method = 'transfer_';
2303
+ }
2304
+
2305
  var ajax_data={
2306
  'action': 'wpvivid_delete_last_restore_data'
2307
  };
2308
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2309
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'auto', 'opacity': '1'});
2310
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2311
+ jQuery('#wpvivid_restore_'+restore_method+'part').hide();
2312
+ jQuery('#wpvivid_clean_'+restore_method+'part').show();
2313
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2314
  wpvivid_post_request(ajax_data, function(data) {
2315
  try {
2316
  var jsonarray = jQuery.parseJSON(data);
2317
  if (jsonarray.result === "success") {
2318
+ wpvivid_display_restore_msg("A restore task is removed.", restore_type);
2319
+ wpvivid_init_restore_data(restore_type);
2320
  }
2321
  }
2322
  catch(err){
2324
  }
2325
  }, function(XMLHttpRequest, textStatus, errorThrown) {
2326
  var error_message = wpvivid_output_ajaxerror('deleting the last incomplete restore task', textStatus, errorThrown);
2327
+ wpvivid_display_restore_msg(error_message, restore_type);
2328
  });
2329
  }
2330
 
2331
  /**
2332
  * This function will start rollback task.
2333
  */
2334
+ function wpvivid_start_rollback(restore_type = 'backup'){
2335
+ var restore_method = '';
2336
+ if(restore_type == 'backup'){
2337
+ restore_method = '';
2338
+ }
2339
+ else if(restore_type == 'transfer'){
2340
+ restore_method = 'transfer_';
2341
+ }
2342
+
2343
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2344
+ wpvivid_monitor_rollback_task(restore_type);
2345
+ wpvivid_rollback(restore_type);
2346
  }
2347
 
2348
+ function wpvivid_rollback(restore_type){
2349
+ var restore_method = '';
2350
+ if(restore_type == 'backup'){
2351
+ restore_method = '';
2352
+ }
2353
+ else if(restore_type == 'transfer'){
2354
+ restore_method = 'transfer_';
2355
+ }
2356
+
2357
  var ajax_data={
2358
  'action': 'wpvivid_rollback'
2359
  };
2361
  try {
2362
  var jsonarray = jQuery.parseJSON(data);
2363
  if (jsonarray.result === "success") {
2364
+ wpvivid_display_restore_msg("Rollback completed.", restore_type);
2365
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2366
  }
2367
  else if (jsonarray.result === "failed") {
2368
+ wpvivid_display_restore_msg(jsonarray.error, restore_type);
2369
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2370
  }
2371
  }
2372
  catch(err){
2374
  }
2375
  }, function(XMLHttpRequest, textStatus, errorThrown) {
2376
  var error_message = wpvivid_output_ajaxerror('starting rollbacking', textStatus, errorThrown);
2377
+ wpvivid_display_restore_msg(error_message, restore_type);
2378
  });
2379
  }
2380
 
2381
  /**
2382
  * This function will monitor the rollback task.
2383
  */
2384
+ function wpvivid_monitor_rollback_task(restore_type){
2385
+ var restore_method = '';
2386
+ if(restore_type == 'backup'){
2387
+ restore_method = '';
2388
+ }
2389
+ else if(restore_type == 'transfer'){
2390
+ restore_method = 'transfer_';
2391
+ }
2392
+
2393
  var ajax_data={
2394
  'action':'wpvivid_get_rollback_progress',
2395
  'wpvivid_restore':'1',
2402
  {
2403
  if(jsonarray.result === "success")
2404
  {
2405
+ jQuery('#wpvivid_restore_'+restore_method+'log').html("");
2406
  while(jsonarray.log.indexOf('\n') >= 0){
2407
  var iLength = jsonarray.log.indexOf('\n');
2408
  var log = jsonarray.log.substring(0, iLength);
2409
  jsonarray.log = jsonarray.log.substring(iLength+1);
2410
  var insert_log = "<div style=\"clear:both;\">"+log+"</div>";
2411
+ jQuery('#wpvivid_restore_'+restore_method+'log').append(insert_log);
2412
  }
2413
 
2414
  if(jsonarray.status==='wait')
2415
  {
2416
  wpvivid_restoring = true;
2417
+ wpvivid_rollback(restore_type);
2418
  setTimeout(function()
2419
  {
2420
+ wpvivid_monitor_rollback_task(restore_type);
2421
  }, 1000);
2422
  }
2423
  else if(jsonarray.status==='completed')
2424
  {
2425
  wpvivid_restoring = false;
2426
+ wpvivid_rollback(restore_type);
2427
  wpvivid_restore_unlock();
2428
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2429
  }
2430
  else if(jsonarray.status==='error')
2431
  {
2432
  wpvivid_restoring = false;
2433
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2434
  }
2435
  else
2436
  {
2437
  setTimeout(function()
2438
  {
2439
+ wpvivid_monitor_rollback_task(restore_type);
2440
  }, 1000);
2441
  }
2442
  }
2444
  {
2445
  setTimeout(function()
2446
  {
2447
+ wpvivid_monitor_rollback_task(restore_type);
2448
  }, 1000);
2449
  }
2450
  }
2452
  {
2453
  setTimeout(function()
2454
  {
2455
+ wpvivid_monitor_rollback_task(restore_type);
2456
  }, 1000);
2457
  }
2458
  }
2459
  catch(err){
2460
  setTimeout(function()
2461
  {
2462
+ wpvivid_monitor_rollback_task(restore_type);
2463
  }, 1000);
2464
  }
2465
  }, function(XMLHttpRequest, textStatus, errorThrown) {
2466
  setTimeout(function()
2467
  {
2468
+ wpvivid_monitor_rollback_task(restore_type);
2469
  }, 1000);
2470
  });
2471
  }
2486
  jQuery('#settings-page').css({'pointer-events': 'none', 'opacity': '1'});
2487
  jQuery('#debug-page').css({'pointer-events': 'none', 'opacity': '1'});
2488
  jQuery('#logs-page').css({'pointer-events': 'none', 'opacity': '1'});
2489
+ jQuery('#wpvivid_tab_migrate').css({'pointer-events': 'none', 'opacity': '1'});
2490
+ jQuery('#wpvivid_add_tab_migrate').css({'pointer-events': 'none', 'opacity': '1'});
2491
+ jQuery('#wpvivid_add_tab_import').css({'pointer-events': 'none', 'opacity': '1'});
2492
+ jQuery('#wpvivid_add_tab_key').css({'pointer-events': 'none', 'opacity': '1'});
2493
+ jQuery('#wpvivid_add_tab_log').css({'pointer-events': 'none', 'opacity': '1'});
2494
+ jQuery('#wpvivid_add_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
2495
+ jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'none', 'opacity': '1'});
2496
+ //jQuery('#wpvivid_replace_domain').css({'pointer-events': 'none', 'opacity': '1'});
2497
+ //jQuery('#wpvivid_keep_domain').css({'pointer-events': 'none', 'opacity': '1'});
2498
  }
2499
 
2500
  /**
2513
  jQuery('#settings-page').css({'pointer-events': 'auto', 'opacity': '1'});
2514
  jQuery('#debug-page').css({'pointer-events': 'auto', 'opacity': '1'});
2515
  jQuery('#logs-page').css({'pointer-events': 'auto', 'opacity': '1'});
2516
+ jQuery('#wpvivid_tab_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
2517
+ jQuery('#wpvivid_add_tab_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
2518
+ jQuery('#wpvivid_add_tab_import').css({'pointer-events': 'auto', 'opacity': '1'});
2519
+ jQuery('#wpvivid_add_tab_key').css({'pointer-events': 'auto', 'opacity': '1'});
2520
+ jQuery('#wpvivid_add_tab_log').css({'pointer-events': 'auto', 'opacity': '1'});
2521
+ jQuery('#wpvivid_add_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
2522
+ jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
2523
+ //jQuery('#wpvivid_replace_domain').css({'pointer-events': 'auto', 'opacity': '1'});
2524
+ //jQuery('#wpvivid_keep_domain').css({'pointer-events': 'auto', 'opacity': '1'});
2525
  }
2526
 
2527
  /**
2538
  var jsonarray = jQuery.parseJSON(data);
2539
  if (jsonarray.result === "success") {
2540
  alert("Out of date backups have been removed.");
2541
+ wpvivid_handle_backup_data(data);
2542
  }
2543
  }
2544
  catch(err){
admin/partials/wpvivid-admin-display.php CHANGED
@@ -21,6 +21,7 @@ $remoteslist=WPvivid_Setting::get_all_remote_options();
21
  $schedule=WPvivid_Schedule::get_schedule();
22
  $backupdir=WPvivid_Setting::get_backupdir();
23
  $general_setting=WPvivid_Setting::get_setting(true, "");
 
24
  $out_of_date=$wpvivid_pulgin->_get_out_of_date_info();
25
  $junk_file=$wpvivid_pulgin->_junk_files_info();
26
  $website_info=$wpvivid_pulgin->get_website_info();
@@ -37,8 +38,58 @@ $wpvivid_version=WPVIVID_PLUGIN_VERSION;
37
  do_action('show_notice');
38
  ?>
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  <div class="wrap">
41
- <h1><?php _e('Backup WordPress Site by WPvivid', 'wpvivid'); ?></h1>
42
  <div id="wpvivid_backup_notice">
43
  <?php
44
  if($schedule['enable'] == true) {
@@ -53,17 +104,6 @@ do_action('show_notice');
53
  </div>
54
  </div>
55
  <h2 class="nav-tab-wrapper">
56
- <a href="#" id="wpvivid_tab_general" class="nav-tab wrap-nav-tab nav-tab-active" onclick="switchTabs(event,'general-page')"><?php _e('Backup & Restore', 'wpvivid'); ?></a>
57
- <a href="#" id="wpvivid_tab_setting" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'settings-page')"><?php _e('Settings', 'wpvivid'); ?></a>
58
- <a href="#" id="wpvivid_tab_remote_storage" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'storage-page')"><?php _e('Remote Storage', 'wpvivid'); ?></a>
59
- <a href="#" id="wpvivid_tab_debug" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'debug-page')"><?php _e('Website Info', 'wpvivid'); ?></a>
60
- <a href="#" id="wpvivid_tab_log" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'logs-page')"><?php _e('Logs', 'wpvivid'); ?></a>
61
- <a href="#" id="wpvivid_tab_read_log" class="nav-tab wrap-nav-tab delete" onclick="switchTabs(event,'log-read-page')" style="display: none;">
62
- <div style="margin-right: 15px;"><?php _e('Log', 'wpvivid'); ?></div>
63
- <div class="nav-tab-delete-img">
64
- <img src="<?php echo esc_url(plugins_url( 'images/delete-tab.png', __FILE__ )); ?>" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, 'wpvivid_tab_read_log', 'wrap', 'wpvivid_tab_log');" />
65
- </div>
66
- </a>
67
  <?php do_action('wpvivid_backuprestore_add_tab');?>
68
  </h2>
69
  <div class="wrap" style="max-width:1720px;">
21
  $schedule=WPvivid_Schedule::get_schedule();
22
  $backupdir=WPvivid_Setting::get_backupdir();
23
  $general_setting=WPvivid_Setting::get_setting(true, "");
24
+ $last_msg=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg');
25
  $out_of_date=$wpvivid_pulgin->_get_out_of_date_info();
26
  $junk_file=$wpvivid_pulgin->_junk_files_info();
27
  $website_info=$wpvivid_pulgin->get_website_info();
38
  do_action('show_notice');
39
  ?>
40
 
41
+ <?php
42
+ function add_tab_general(){
43
+ ?>
44
+ <a href="#" id="wpvivid_tab_general" class="nav-tab wrap-nav-tab nav-tab-active" onclick="switchTabs(event,'general-page')"><?php _e('Backup & Restore', 'wpvivid'); ?></a>
45
+ <?php
46
+ }
47
+
48
+ function add_tab_setting(){
49
+ ?>
50
+ <a href="#" id="wpvivid_tab_setting" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'settings-page')"><?php _e('Settings', 'wpvivid'); ?></a>
51
+ <?php
52
+ }
53
+
54
+ function add_tab_remote_storage(){
55
+ ?>
56
+ <a href="#" id="wpvivid_tab_remote_storage" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'storage-page')"><?php _e('Remote Storage', 'wpvivid'); ?></a>
57
+ <?php
58
+ }
59
+
60
+ function add_tab_website_info(){
61
+ ?>
62
+ <a href="#" id="wpvivid_tab_debug" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'debug-page')"><?php _e('Website Info', 'wpvivid'); ?></a>
63
+ <?php
64
+ }
65
+
66
+ function add_tab_log(){
67
+ ?>
68
+ <a href="#" id="wpvivid_tab_log" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'logs-page')"><?php _e('Logs', 'wpvivid'); ?></a>
69
+ <?php
70
+ }
71
+
72
+ function add_tab_read_log(){
73
+ ?>
74
+ <a href="#" id="wpvivid_tab_read_log" class="nav-tab wrap-nav-tab delete" onclick="switchTabs(event,'log-read-page')" style="display: none;">
75
+ <div style="margin-right: 15px;"><?php _e('Log', 'wpvivid'); ?></div>
76
+ <div class="nav-tab-delete-img">
77
+ <img src="<?php echo esc_url(plugins_url( 'images/delete-tab.png', __FILE__ )); ?>" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, 'wpvivid_tab_read_log', 'wrap', 'wpvivid_tab_log');" />
78
+ </div>
79
+ </a>
80
+ <?php
81
+ }
82
+
83
+ add_action('wpvivid_backuprestore_add_tab', 'add_tab_general', 10);
84
+ add_action('wpvivid_backuprestore_add_tab', 'add_tab_setting', 12);
85
+ add_action('wpvivid_backuprestore_add_tab', 'add_tab_remote_storage', 13);
86
+ add_action('wpvivid_backuprestore_add_tab', 'add_tab_website_info', 14);
87
+ add_action('wpvivid_backuprestore_add_tab', 'add_tab_log', 15);
88
+ add_action('wpvivid_backuprestore_add_tab', 'add_tab_read_log', 17);
89
+ ?>
90
+
91
  <div class="wrap">
92
+ <h1><?php _e('WPvivid Backup Plugin', 'wpvivid'); ?></h1>
93
  <div id="wpvivid_backup_notice">
94
  <?php
95
  if($schedule['enable'] == true) {
104
  </div>
105
  </div>
106
  <h2 class="nav-tab-wrapper">
 
 
 
 
 
 
 
 
 
 
 
107
  <?php do_action('wpvivid_backuprestore_add_tab');?>
108
  </h2>
109
  <div class="wrap" style="max-width:1720px;">
admin/partials/wpvivid-backup-restore-page-display.php CHANGED
@@ -16,6 +16,9 @@ function wpvivid_backup_progress_rate(){
16
  <div class="backup-basic-info"><span><?php _e('Uploaded:', 'wpvivid'); ?></span><span>N/A</span></div>
17
  <div class="backup-basic-info"><span><?php _e('Speed:', 'wpvivid'); ?></span><span>N/A</span></div>
18
  </div>
 
 
 
19
  <div style="clear:both;"></div>
20
  <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing"></p></div>
21
  <div style="clear: both;"></div>
@@ -137,6 +140,10 @@ function wpvivid_add_tab_backup(){
137
  <?php
138
  }
139
 
 
 
 
 
140
  function wpvivid_add_tab_log(){
141
  ?>
142
  <a href="#" id="wpvivid_tab_backup_log" class="nav-tab backup-nav-tab delete" onclick="switchrestoreTabs(event,'page-log')" style="display: none;">
@@ -178,11 +185,14 @@ function wpvivid_add_page_backup(){
178
  ?>
179
  </div>
180
  <div style="clear:both;"></div>
181
- <table class="wp-list-table widefat plugins" id="wpvivid_backuplist_table">
 
 
 
182
  <thead>
183
- <tr class="backup-list-head">
184
- <td class=""></td>
185
- <th class=""><?php _e( 'Backup','wpvivid'); ?></th>
186
  <th><?php _e( 'Storage','wpvivid'); ?></th>
187
  <th><?php _e( 'Download','wpvivid'); ?></th>
188
  <th><?php _e( 'Delete','wpvivid'); ?></th>
@@ -198,7 +208,7 @@ function wpvivid_add_page_backup(){
198
  <tfoot>
199
  <tr>
200
  <th><input name="" type="checkbox" id="backup_list_all_check" value="1" /></th>
201
- <th class="row-title" colspan="6"><a onclick="wpvivid_delete_backups_inbatches();" style="cursor: pointer;"><?php _e('Delete the selected backups', 'wpvivid'); ?></a></th>
202
  </tr>
203
  </tfoot>
204
  </table>
@@ -301,6 +311,10 @@ function wpvivid_add_page_backup(){
301
  <?php
302
  }
303
 
 
 
 
 
304
  function wpvivid_add_page_log(){
305
  ?>
306
  <div class="backup-tab-content wpvivid_tab_backup_log" id="page-log" style="display:none;">
@@ -318,12 +332,25 @@ function wpvivid_add_page_restore(){
318
  <h3><?php _e('Restore backup from:', 'wpvivid'); ?><span id="wpvivid_restore_backup_time"></span></h3>
319
  <p><strong><?php _e('Please do not close the page or switch to other pages when a restore task is running, as it could trigger some unexpected errors.', 'wpvivid'); ?></strong></p>
320
  <p><?php _e('Restore function will replace the current site\'s themes, plugins, uploads, database and/or other content directories with the existing equivalents in the selected backup.', 'wpvivid'); ?></p>
 
 
 
 
 
 
 
 
 
 
 
 
 
321
  <div class="restore-button-position" id="wpvivid_restore_part"><input class="button-primary" id="wpvivid_restore_btn" type="submit" name="restore" value="<?php esc_attr_e( 'Restore', 'wpvivid' ); ?>" onclick="wpvivid_start_restore();" /></div>
322
  <div class="restore-button-position" id="wpvivid_clean_part"><input class="button-primary" id="wpvivid_clean_restore" type="submit" name="clear_restore" value="<?php esc_attr_e( 'Clean Restore', 'wpvivid' ); ?>" /></div>
323
  <div class="restore-button-position" id="wpvivid_rollback_part"><input class="button-primary" id="wpvivid_rollback_btn" type="submit" name="rollback" value="<?php esc_attr_e( 'Rollback', 'wpvivid' ); ?>" /></div>
324
  </div>
325
- <div class="postbox restore_log">
326
- <div id="wpvivid_restore_log"></div>
327
  </div>
328
  </div>
329
  <?php
@@ -366,7 +393,7 @@ function wpvivid_backup_do_js(){
366
  $descript = substr($descript, 0, $pos);
367
  }
368
  }
369
- $backup_running_time=$value['data']['running_time'];
370
  $output = '';
371
  foreach (array(86400 => 'day', 3600 => 'hour', 60 => 'min', 1 => 'second') as $key => $value) {
372
  if ($backup_running_time >= $key) $output .= floor($backup_running_time/$key) . $value;
@@ -411,11 +438,11 @@ add_action('wpvivid_backup_add_module', 'wpvivid_backup_progress_rate', 10);
411
  add_action('wpvivid_backup_add_module', 'wpvivid_backup_manual', 11);
412
  add_action('wpvivid_backup_add_module', 'wpvivid_backup_schedule', 12);
413
  add_action('wpvivid_backup_add_tab', 'wpvivid_add_tab_backup', 13);
414
- add_action('wpvivid_backup_add_tab', 'wpvivid_add_tab_log', 14);
415
- add_action('wpvivid_backup_add_tab', 'wpvivid_add_tab_restore', 15);
416
  add_action('wpvivid_backup_add_page', 'wpvivid_add_page_backup', 13);
417
- add_action('wpvivid_backup_add_page', 'wpvivid_add_page_log', 14);
418
- add_action('wpvivid_backup_add_page', 'wpvivid_add_page_restore', 15);
419
  add_action('wpvivid_backup_do_js', 'wpvivid_backup_do_js', 10);
420
  add_filter('wpvivid_download_backup_descript', 'wpvivid_download_backup_descript', 10);
421
  add_filter('wpvivid_restore_website_dexcript', 'wpvivid_restore_website_dexcript', 10);
16
  <div class="backup-basic-info"><span><?php _e('Uploaded:', 'wpvivid'); ?></span><span>N/A</span></div>
17
  <div class="backup-basic-info"><span><?php _e('Speed:', 'wpvivid'); ?></span><span>N/A</span></div>
18
  </div>
19
+ <div style="float: left;">
20
+ <div class="backup-basic-info"><span><?php _e('Network Connection:', 'wpvivid'); ?></span><span>N/A</span></div>
21
+ </div>
22
  <div style="clear:both;"></div>
23
  <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing"></p></div>
24
  <div style="clear: both;"></div>
140
  <?php
141
  }
142
 
143
+ function wpvivid_add_tab_upload(){
144
+ do_action('wpvivid_add_tab_upload');
145
+ }
146
+
147
  function wpvivid_add_tab_log(){
148
  ?>
149
  <a href="#" id="wpvivid_tab_backup_log" class="nav-tab backup-nav-tab delete" onclick="switchrestoreTabs(event,'page-log')" style="display: none;">
185
  ?>
186
  </div>
187
  <div style="clear:both;"></div>
188
+ <?php
189
+ do_action('wpvivid_rescan_backup_list');
190
+ ?>
191
+ <table class="wp-list-table widefat plugins" id="wpvivid_backuplist_table" style="border-collapse: collapse;">
192
  <thead>
193
+ <tr class="backup-list-head" style="border-bottom: 0;">
194
+ <td></td>
195
+ <th><?php _e( 'Backup','wpvivid'); ?></th>
196
  <th><?php _e( 'Storage','wpvivid'); ?></th>
197
  <th><?php _e( 'Download','wpvivid'); ?></th>
198
  <th><?php _e( 'Delete','wpvivid'); ?></th>
208
  <tfoot>
209
  <tr>
210
  <th><input name="" type="checkbox" id="backup_list_all_check" value="1" /></th>
211
+ <th class="row-title" colspan="4"><a onclick="wpvivid_delete_backups_inbatches();" style="cursor: pointer;"><?php _e('Delete the selected backups', 'wpvivid'); ?></a></th>
212
  </tr>
213
  </tfoot>
214
  </table>
311
  <?php
312
  }
313
 
314
+ function wpvivid_add_page_upload(){
315
+ do_action('wpvivid_add_page_upload');
316
+ }
317
+
318
  function wpvivid_add_page_log(){
319
  ?>
320
  <div class="backup-tab-content wpvivid_tab_backup_log" id="page-log" style="display:none;">
332
  <h3><?php _e('Restore backup from:', 'wpvivid'); ?><span id="wpvivid_restore_backup_time"></span></h3>
333
  <p><strong><?php _e('Please do not close the page or switch to other pages when a restore task is running, as it could trigger some unexpected errors.', 'wpvivid'); ?></strong></p>
334
  <p><?php _e('Restore function will replace the current site\'s themes, plugins, uploads, database and/or other content directories with the existing equivalents in the selected backup.', 'wpvivid'); ?></p>
335
+ <div id="wpvivid_restore_is_migrate" style="padding-bottom: 10px;">
336
+ <label >
337
+ <input type="radio" id="wpvivid_replace_domain" option="restore" name="restore_domain" value="1" /><?php _e('Complete migration (choose this one if the webhosting is changed or you need to replace old domain with new one)', 'wpvivid'); ?>
338
+ </label><br>
339
+ <label >
340
+ <input type="radio" id="wpvivid_keep_domain" option="restore" name="restore_domain" value="0" /><?php _e('Restore to the original webhosting and domain', 'wpvivid'); ?>
341
+ </label><br>
342
+ </div>
343
+ <div id="wpvivid_restore_backup_old_site">
344
+ <!--<label >
345
+ <input type="checkbox" option="restore" name="skip_backup_old_site" /><?php _e('Checking this option will create a backup for this site before website restoration, which will help you stand a chance to rollback your site', 'wpvivid'); ?>
346
+ </label><br>-->
347
+ </div>
348
  <div class="restore-button-position" id="wpvivid_restore_part"><input class="button-primary" id="wpvivid_restore_btn" type="submit" name="restore" value="<?php esc_attr_e( 'Restore', 'wpvivid' ); ?>" onclick="wpvivid_start_restore();" /></div>
349
  <div class="restore-button-position" id="wpvivid_clean_part"><input class="button-primary" id="wpvivid_clean_restore" type="submit" name="clear_restore" value="<?php esc_attr_e( 'Clean Restore', 'wpvivid' ); ?>" /></div>
350
  <div class="restore-button-position" id="wpvivid_rollback_part"><input class="button-primary" id="wpvivid_rollback_btn" type="submit" name="rollback" value="<?php esc_attr_e( 'Rollback', 'wpvivid' ); ?>" /></div>
351
  </div>
352
+ <div class="postbox restore_log" id="wpvivid_restore_log">
353
+ <!--<div id="wpvivid_restore_log" style="overflow-y: scroll;"></div>-->
354
  </div>
355
  </div>
356
  <?php
393
  $descript = substr($descript, 0, $pos);
394
  }
395
  }
396
+ $backup_running_time=$value['data']['running_stamp'];
397
  $output = '';
398
  foreach (array(86400 => 'day', 3600 => 'hour', 60 => 'min', 1 => 'second') as $key => $value) {
399
  if ($backup_running_time >= $key) $output .= floor($backup_running_time/$key) . $value;
438
  add_action('wpvivid_backup_add_module', 'wpvivid_backup_manual', 11);
439
  add_action('wpvivid_backup_add_module', 'wpvivid_backup_schedule', 12);
440
  add_action('wpvivid_backup_add_tab', 'wpvivid_add_tab_backup', 13);
441
+ add_action('wpvivid_backup_add_tab', 'wpvivid_add_tab_log', 15);
442
+ add_action('wpvivid_backup_add_tab', 'wpvivid_add_tab_restore', 16);
443
  add_action('wpvivid_backup_add_page', 'wpvivid_add_page_backup', 13);
444
+ add_action('wpvivid_backup_add_page', 'wpvivid_add_page_log', 15);
445
+ add_action('wpvivid_backup_add_page', 'wpvivid_add_page_restore', 16);
446
  add_action('wpvivid_backup_do_js', 'wpvivid_backup_do_js', 10);
447
  add_filter('wpvivid_download_backup_descript', 'wpvivid_download_backup_descript', 10);
448
  add_filter('wpvivid_restore_website_dexcript', 'wpvivid_restore_website_dexcript', 10);
admin/partials/wpvivid-settings-page-display.php CHANGED
@@ -170,7 +170,7 @@ function wpvivid_email_report()
170
  <td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell"><?php _e('Email Report', 'wpvivid'); ?></label></td>
171
  <td class="tablelistcolumn">
172
  <div class="postbox schedule-tab-block">
173
- <div><p><?php _e('In order to use this function, please install a ', 'wpvivid'); ?><strong><?php _e('WordPress SMTP plugin', 'wpvivid'); ?></strong><?php _e(' of your preference and configure your SMTP server first. This is because WordPress uses the PHP Mail function to send its emails by default, which is not supported by many hosts and can cause issues if it is not set properly.', 'wpvivid'); ?></p>
174
  </div>
175
  <div>
176
  <label for="wpvivid_general_email_enable">
170
  <td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell"><?php _e('Email Report', 'wpvivid'); ?></label></td>
171
  <td class="tablelistcolumn">
172
  <div class="postbox schedule-tab-block">
173
+ <div><p><?php _e('In order to use this function, please install a ', 'wpvivid'); ?><strong><a target="_blank" href="https://wpvivid.com/8-best-smtp-plugins-for-wordpress.html"><?php _e('WordPress SMTP plugin', 'wpvivid'); ?></a></strong><?php _e(' of your preference and configure your SMTP server first. This is because WordPress uses the PHP Mail function to send its emails by default, which is not supported by many hosts and can cause issues if it is not set properly.', 'wpvivid'); ?></p>
174
  </div>
175
  <div>
176
  <label for="wpvivid_general_email_enable">
admin/partials/wpvivid-website-info-page-display.php CHANGED
@@ -1,7 +1,7 @@
1
  <table class="widefat">
2
  <div style="padding: 0 0 20px 10px;">There are two ways available to send us the debug information. The first one is recommended.</div>
3
  <div style="padding-left: 10px;">
4
- <?php _e('Method 1. If you have configured SMTP on your site, enter your email address and click the button below to send us the relevant information (website info and errors logs) when you are encountering errors. This will help us figure out what happened. Once the issue is resolved, we will inform you by your email address.', 'wpvivid'); ?>
5
  </div>
6
  <div style="padding:10px 10px 0">
7
  <span>WPvivid support email:</span><input type="text" id="wpvivid_support_mail" value="support@wpvivid.com" readonly />
@@ -12,7 +12,7 @@
12
  </div>
13
  <div style="clear:both;"></div>
14
  <div style="padding-left: 10px;">
15
- <?php _e('Method 2. If you didn’t configure SMTP on your site, click the button below to download the relevant information (website info and error logs) to your PC when you are encountering some errors. Sending the files to us will help us diagnose what happened.', 'wpvivid'); ?>
16
  </div>
17
  <div class="schedule-tab-block">
18
  <input class="button-primary" id="wpvivid_download_website_info" type="submit" name="download-website-info" value="<?php esc_attr_e( 'Download', 'wpvivid' ); ?>" />
1
  <table class="widefat">
2
  <div style="padding: 0 0 20px 10px;">There are two ways available to send us the debug information. The first one is recommended.</div>
3
  <div style="padding-left: 10px;">
4
+ <strong><?php _e('Method 1.'); ?></strong> <?php _e('If you have configured SMTP on your site, enter your email address and click the button below to send us the relevant information (website info and errors logs) when you are encountering errors. This will help us figure out what happened. Once the issue is resolved, we will inform you by your email address.', 'wpvivid'); ?>
5
  </div>
6
  <div style="padding:10px 10px 0">
7
  <span>WPvivid support email:</span><input type="text" id="wpvivid_support_mail" value="support@wpvivid.com" readonly />
12
  </div>
13
  <div style="clear:both;"></div>
14
  <div style="padding-left: 10px;">
15
+ <strong><?php _e('Method 2.'); ?></strong> <?php _e('If you didn’t configure SMTP on your site, click the button below to download the relevant information (website info and error logs) to your PC when you are encountering some errors. Sending the files to us will help us diagnose what happened.', 'wpvivid'); ?>
16
  </div>
17
  <div class="schedule-tab-block">
18
  <input class="button-primary" id="wpvivid_download_website_info" type="submit" name="download-website-info" value="<?php esc_attr_e( 'Download', 'wpvivid' ); ?>" />
includes/class-wpvivid-backup-database.php CHANGED
@@ -3,6 +3,7 @@
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
 
6
  define('OPTION','0');
7
  class WPvivid_Backup_Database
8
  {
@@ -21,6 +22,9 @@ class WPvivid_Backup_Database
21
  private $task_id;
22
  public $must_privilege = array(
23
  'backup' => array(
 
 
 
24
  'SHOW VIEW' => OPTION,
25
  'LOCK TABLES' => OPTION,
26
  'EVENT' => OPTION,
@@ -28,6 +32,11 @@ class WPvivid_Backup_Database
28
  'CREATE ROUTINE' => OPTION,
29
  ),
30
  'restore' => array(
 
 
 
 
 
31
  'SHOW VIEW' => OPTION,
32
  'EVENT' => OPTION,
33
  'TRIGGER' => OPTION,
@@ -44,7 +53,9 @@ class WPvivid_Backup_Database
44
 
45
  public function backup_database($data,$task_id = '')
46
  {
 
47
  $dump=null;
 
48
  try
49
  {
50
  $this->task_id=$task_id;
@@ -66,9 +77,7 @@ class WPvivid_Backup_Database
66
  $this->HOST = DB_HOST;
67
  $this->DOMAIN = filter_input(INPUT_SERVER, 'HTTP_HOST');
68
 
69
- $basename = basename($data['path'],$data['compress']['compress_type']).'sql';
70
-
71
- $backup_file = dirname($data['path']).DIRECTORY_SEPARATOR.$basename;
72
 
73
  $privileges = array();
74
  require_once 'class-wpvivid-mysqldump.php';
@@ -87,10 +96,10 @@ class WPvivid_Backup_Database
87
  $db_host = $res[0];
88
  $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
89
  if(empty($pdo) || !$pdo){
90
- return array('result' => 'WPVIVID_FAILED','error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
91
  }
92
  }else{
93
- return array('result' => 'WPVIVID_FAILED','error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
94
  }
95
  }
96
 
@@ -102,51 +111,46 @@ class WPvivid_Backup_Database
102
  $version = $datas[0][0];
103
  }
104
  else{
105
- return array('result'=>'failed','error'=>'MySQL version is not obtained. Please check if MySQL is installed or not.');
106
  }
107
 
108
  if(version_compare('5.3.0',phpversion()) > 0){
109
- return array('result'=>'failed','error'=>'Your PHP version is too old. Please upgrade at least to PHP 5.3.0.');
110
  }
111
  if(version_compare('4.1.0',$version) > 0){
112
- return array('result'=>'failed','error'=>'Your MySQL version is too old. Please upgrade at least to MySQL 4.1.0.');
113
  }
114
 
115
  $result = $this -> check_privilege('backup',$pdo);
116
- if($result['result'] === WPVIVID_FAILED){
 
117
  return $result;
118
  }else{
119
  $privileges = $result['data'];
120
  }
121
 
122
- $this->check_big_db($pdo,$data);
123
  $this->check_max_allowed_packet($pdo);
124
 
125
  unset($pdo);
126
  }else{
127
- return array('result'=>'failed','error'=>'PDO extension not found. Please check if PDO extension is installed or not.');
128
  }
129
 
130
  $exclude = array('/^(?!'.$prefix.')/');
131
  $dsn = 'mysql:host=' . $db_host . ';dbname=' . DB_NAME;
132
- if(!empty($data['meta']))
133
- {
134
- $dump = new WPvivid_Mysqldump($dsn, DB_USER, DB_PASSWORD , array('include-tables'=>$data['meta'],'exclude-tables'=>$exclude,'add-drop-table' => true,'extended-insert'=>false));
135
- $dump -> set_privilege($privileges);
136
- }else{
137
- $dump = new WPvivid_Mysqldump($dsn, DB_USER, DB_PASSWORD , array('exclude-tables'=>$exclude,'add-drop-table' => true,'extended-insert'=>false));
138
- $dump -> set_privilege($privileges);
139
- }
140
 
141
  if(file_exists($backup_file))
142
  @unlink($backup_file);
143
- $dump->log=$data['log'];
 
144
  $dump->task_id=$task_id;
145
  $dump->start($backup_file);
146
  unset($pdo);
147
  }catch (Exception $e)
148
  {
149
- global $wpvivid_pulgin;
150
  $str_last_query_string='';
151
  if(!is_null($dump))
152
  {
@@ -157,7 +161,7 @@ class WPvivid_Backup_Database
157
  $wpvivid_pulgin->wpvivid_log->WriteLog('last query string:'.$str_last_query_string,'error');
158
  }
159
  $message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
160
- return array('result'=>'failed','error'=>$message);
161
  }
162
 
163
  $files = array();
@@ -249,8 +253,10 @@ class WPvivid_Backup_Database
249
  return array('result' => WPVIVID_SUCCESS,'data' => $temp_privileges);
250
  }
251
 
252
- public function check_big_db($pdo,$data)
253
  {
 
 
254
  $sth = $pdo->query('SHOW TABLE STATUS');
255
 
256
  $dbSize = 0;
@@ -266,7 +272,7 @@ class WPvivid_Backup_Database
266
  if($max_rows>7000000)
267
  {
268
  $message='Exporting a large database with more than '.$max_rows.' rows may cause an error when performing dump action.';
269
- $data['log']->WriteLog($message,'notice');
270
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
271
  }
272
  }
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
+ define('NECESSARY','1');
7
  define('OPTION','0');
8
  class WPvivid_Backup_Database
9
  {
22
  private $task_id;
23
  public $must_privilege = array(
24
  'backup' => array(
25
+ 'SELECT' => NECESSARY,
26
+ 'INSERT' => NECESSARY,
27
+ 'UPDATE' => NECESSARY,
28
  'SHOW VIEW' => OPTION,
29
  'LOCK TABLES' => OPTION,
30
  'EVENT' => OPTION,
32
  'CREATE ROUTINE' => OPTION,
33
  ),
34
  'restore' => array(
35
+ 'SELECT' => NECESSARY,
36
+ 'INSERT' => NECESSARY,
37
+ 'UPDATE' => NECESSARY,
38
+ 'DROP' => NECESSARY,
39
+ 'CREATE' => NECESSARY,
40
  'SHOW VIEW' => OPTION,
41
  'EVENT' => OPTION,
42
  'TRIGGER' => OPTION,
53
 
54
  public function backup_database($data,$task_id = '')
55
  {
56
+ global $wpvivid_pulgin;
57
  $dump=null;
58
+
59
  try
60
  {
61
  $this->task_id=$task_id;
77
  $this->HOST = DB_HOST;
78
  $this->DOMAIN = filter_input(INPUT_SERVER, 'HTTP_HOST');
79
 
80
+ $backup_file =$data['sql_file_name'];
 
 
81
 
82
  $privileges = array();
83
  require_once 'class-wpvivid-mysqldump.php';
96
  $db_host = $res[0];
97
  $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
98
  if(empty($pdo) || !$pdo){
99
+ return array('result' => WPVIVID_FAILED,'error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
100
  }
101
  }else{
102
+ return array('result' => WPVIVID_FAILED,'error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
103
  }
104
  }
105
 
111
  $version = $datas[0][0];
112
  }
113
  else{
114
+ return array('result'=>WPVIVID_FAILED,'error'=>'MySQL version is not obtained. Please check if MySQL is installed or not.');
115
  }
116
 
117
  if(version_compare('5.3.0',phpversion()) > 0){
118
+ return array('result'=>WPVIVID_FAILED,'error'=>'Your PHP version is too old. Please upgrade at least to PHP 5.3.0.');
119
  }
120
  if(version_compare('4.1.0',$version) > 0){
121
+ return array('result'=>WPVIVID_FAILED,'error'=>'Your MySQL version is too old. Please upgrade at least to MySQL 4.1.0.');
122
  }
123
 
124
  $result = $this -> check_privilege('backup',$pdo);
125
+ if($result['result'] === WPVIVID_FAILED)
126
+ {
127
  return $result;
128
  }else{
129
  $privileges = $result['data'];
130
  }
131
 
132
+ $this->check_big_db($pdo);
133
  $this->check_max_allowed_packet($pdo);
134
 
135
  unset($pdo);
136
  }else{
137
+ return array('result'=>WPVIVID_FAILED,'error'=>'PDO extension not found. Please check if PDO extension is installed or not.');
138
  }
139
 
140
  $exclude = array('/^(?!'.$prefix.')/');
141
  $dsn = 'mysql:host=' . $db_host . ';dbname=' . DB_NAME;
142
+ $dump = new WPvivid_Mysqldump($dsn, DB_USER, DB_PASSWORD , array('exclude-tables'=>$exclude,'add-drop-table' => true,'extended-insert'=>false));
143
+ $dump -> set_privilege($privileges);
 
 
 
 
 
 
144
 
145
  if(file_exists($backup_file))
146
  @unlink($backup_file);
147
+
148
+ $dump->log=$wpvivid_pulgin->wpvivid_log;
149
  $dump->task_id=$task_id;
150
  $dump->start($backup_file);
151
  unset($pdo);
152
  }catch (Exception $e)
153
  {
 
154
  $str_last_query_string='';
155
  if(!is_null($dump))
156
  {
161
  $wpvivid_pulgin->wpvivid_log->WriteLog('last query string:'.$str_last_query_string,'error');
162
  }
163
  $message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
164
+ return array('result'=>WPVIVID_FAILED,'error'=>$message);
165
  }
166
 
167
  $files = array();
253
  return array('result' => WPVIVID_SUCCESS,'data' => $temp_privileges);
254
  }
255
 
256
+ public function check_big_db($pdo)
257
  {
258
+ global $wpvivid_pulgin;
259
+
260
  $sth = $pdo->query('SHOW TABLE STATUS');
261
 
262
  $dbSize = 0;
272
  if($max_rows>7000000)
273
  {
274
  $message='Exporting a large database with more than '.$max_rows.' rows may cause an error when performing dump action.';
275
+ $wpvivid_pulgin->wpvivid_log->WriteLog($message);
276
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
277
  }
278
  }
includes/class-wpvivid-backup-site.php CHANGED
@@ -3,71 +3,50 @@
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
 
6
  class WPvivid_Backup_Site
7
  {
8
- private $RootDir;
9
- private $TartgetFile;
10
- private $TargetFileTmp;
11
- private $ExcludePath;
12
 
13
- public function init($rootdir, $targetfile, $tmpfile, $exclude)
14
  {
15
- $this->RootDir = $rootdir;
16
- $this->TartgetFile = $targetfile;
17
- $this->ExcludePath = $exclude;
18
- $this->TargetFileTmp = $tmpfile;
19
  }
20
 
21
- public function backup_files($data,$files,$task_id)
22
- {
23
- $data['log']->WriteLog('Start compressing '.$data['type'],'notice');
24
- $flag=array('result'=>'failed','error'=>'suffix is incorrect ');
25
- $suffix = $this->getSuffix(basename($data['path']));
26
- switch($suffix)
27
- {
28
- case 'zip':
29
- $flag = $this->compress2zip($data,$files);
30
- break;
31
-
32
- }
33
- $data['log']-> WriteLog('Compressing '.$data['type'].' completed','notice');
34
- return $flag;
35
  }
36
 
37
- public function compress2zip($data,$files)
38
- {
39
- //$type,$path,$size,$no_compress,$use_temp_file,$use_temp_size
40
- require_once 'class-wpvivid-zipclass.php';
41
- $zipclass = new WPvivid_ZipClass();
42
- $error=$zipclass->getLastError();
43
- if(!empty($error))
44
- {
45
- return array('result'=>'failed','error'=>$error);
46
- }
47
- switch ($data['type'])
48
  {
49
- case WPVIVID_BACKUP_TYPE_CORE:
50
- $replace_path = ABSPATH;
51
- break;
52
- case WPVIVID_BACKUP_TYPE_CONTENT:
53
- $replace_path = ABSPATH;
54
- break;
55
- case WPVIVID_BACKUP_TYPE_OTHERS:
56
- $replace_path = ABSPATH;
57
- break;
58
- case WPVIVID_BACKUP_TYPE_DB:
59
- $replace_path = dirname($data['path']);
60
- break;
61
- default:
62
- $replace_path = WP_CONTENT_DIR;
63
- break;
64
- }
65
- $data['replace_path']=$replace_path;
66
- return $zipclass ->zipsplit($data,$files);
67
  }
68
 
69
- public function getSuffix($basename){
70
- $arr = explode('.',$basename);
71
- return array_pop($arr);
 
 
 
72
  }
73
  }
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
+ require_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-zipclass.php';
7
  class WPvivid_Backup_Site
8
  {
9
+ private $tools_collection=array();
 
 
 
10
 
11
+ public function __construct()
12
  {
13
+ add_filter('wpvivid_tools_register', array($this, 'init_tools'),10);
14
+ $this->tools_collection=apply_filters('wpvivid_tools_register',$this->tools_collection);
15
+ $this->load_hooks();
 
16
  }
17
 
18
+ public function init_tools($tools_collection){
19
+ $tools_collection['zip'][WPVIVID_COMPRESS_ZIPCLASS] = 'WPvivid_ZipClass';
20
+ return $tools_collection;
 
 
 
 
 
 
 
 
 
 
 
21
  }
22
 
23
+ public function get_tools($type){
24
+ if(array_key_exists($type,$this->tools_collection))
 
 
 
 
 
 
 
 
 
25
  {
26
+ foreach ($this -> tools_collection[$type] as $class_name){
27
+ if(class_exists($class_name)){
28
+ $object = new $class_name();
29
+ $last_error = $object -> getLastError();
30
+ if(empty($last_error))
31
+ return $object;
32
+ }
33
+ }
34
+ }
35
+ $class_name = $this -> tools_collection['zip'][WPVIVID_COMPRESS_ZIPCLASS];
36
+ $object = new $class_name();
37
+ $last_error = $object -> getLastError();
38
+ if(empty($last_error)){
39
+ return $object;
40
+ }else{
41
+ return array('result' => WPVIVID_FAILED,'error' => $last_error);
42
+ }
 
43
  }
44
 
45
+ public function load_hooks(){
46
+ foreach ($this -> tools_collection as $compressType){
47
+ foreach ($compressType as $className){
48
+ $object = new $className();
49
+ }
50
+ }
51
  }
52
  }
includes/class-wpvivid-backup-uploader.php ADDED
@@ -0,0 +1,559 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPVIVID_PLUGIN_DIR'))
4
+ {
5
+ die;
6
+ }
7
+
8
+ class Wpvivid_BackupUploader
9
+ {
10
+ public function __construct()
11
+ {
12
+ add_action('wp_ajax_wpvivid_get_file_id',array($this,'get_file_id'));
13
+ add_action('wp_ajax_wpvivid_upload_files',array($this,'upload_files'));
14
+ add_action('wp_ajax_wpvivid_upload_files_finish',array($this,'upload_files_finish'));
15
+
16
+ add_action('wp_ajax_wpvivid_rescan_local_folder',array($this,'rescan_local_folder_set_backup'));
17
+ add_action('wp_ajax_wpvivid_get_backup_count',array($this,'get_backup_count'));
18
+ }
19
+
20
+ function get_file_id()
21
+ {
22
+ if(isset($_POST['file_name']))
23
+ {
24
+ if(preg_match('/^wpvivid-.*_.*_.*\.zip$/',$_POST['file_name']))
25
+ {
26
+ if(preg_match('/^wpvivid-(.*?)_/',$_POST['file_name'],$matches))
27
+ {
28
+ $id= $matches[0];
29
+ $id=substr($id,0,strlen($id)-1);
30
+ if(WPvivid_Backuplist::get_backuplist_by_key($id)===false)
31
+ {
32
+ $ret['result']=WPVIVID_SUCCESS;
33
+ $ret['id']=$id;
34
+ }
35
+ else
36
+ {
37
+ $ret['result']=WPVIVID_FAILED;
38
+ $ret['error']='The uploading backup already exists in Backups list.';
39
+ }
40
+ }
41
+ else
42
+ {
43
+ $ret['result']=WPVIVID_FAILED;
44
+ $ret['error']='The backup is not created by WPvivid backup plugin.';
45
+ }
46
+ }
47
+ else
48
+ {
49
+ $ret['result']=WPVIVID_FAILED;
50
+ $ret['error']='The backup is not created by WPvivid backup plugin.';
51
+ }
52
+ }
53
+ else
54
+ {
55
+ $ret['result']=WPVIVID_FAILED;
56
+ $ret['error']='The backup is not created by WPvivid backup plugin.';
57
+ }
58
+
59
+ echo json_encode($ret);
60
+ die();
61
+ }
62
+
63
+ function check_file_is_a_wpvivid_backup($file_name,&$backup_id)
64
+ {
65
+ if(preg_match('/^wpvivid-.*_.*_.*\.zip$/',$file_name))
66
+ {
67
+ if(preg_match('/^wpvivid-(.*?)_/',$file_name,$matches))
68
+ {
69
+ $id= $matches[0];
70
+ $id=substr($id,0,strlen($id)-1);
71
+ if(WPvivid_Backuplist::get_backuplist_by_key($id)===false)
72
+ {
73
+ $backup_id=$id;
74
+ return true;
75
+ }
76
+ else
77
+ {
78
+ return false;
79
+ }
80
+ }
81
+ else
82
+ {
83
+ return false;
84
+ }
85
+ }
86
+ else
87
+ {
88
+ return false;
89
+ }
90
+ }
91
+
92
+ function upload_files()
93
+ {
94
+ $options['test_form'] =true;
95
+ $options['action'] ='wpvivid_upload_files';
96
+ $options['test_type'] = false;
97
+ $options['ext'] = 'zip';
98
+ $options['type'] = 'application/zip';
99
+
100
+ add_filter('upload_dir', array($this, 'upload_dir'));
101
+
102
+ $status = wp_handle_upload($_FILES['async-upload'],$options);
103
+
104
+ remove_filter('upload_dir', array($this, 'upload_dir'));
105
+
106
+ if (isset($status['error']))
107
+ {
108
+ echo json_encode(array('e' => $status['error']));
109
+ exit;
110
+ }
111
+
112
+ $file_name=basename($_POST['name']);
113
+
114
+ if (isset($_POST['chunks']) && isset($_POST['chunk']))
115
+ {
116
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
117
+ rename($status['file'],$path.$file_name.'_'.$_POST['chunk'].'.tmp');
118
+ $status['file'] = $path.$file_name.'_'.$_POST['chunk'].'.tmp';
119
+ if($_POST['chunk'] == $_POST['chunks']-1)
120
+ {
121
+ $file_handle = fopen($path.$file_name, 'wb');
122
+ if ($file_handle)
123
+ {
124
+ for ($i=0; $i<$_POST['chunks']; $i++)
125
+ {
126
+ $chunks_handle=fopen($path.$file_name.'_'.$i.'.tmp','rb');
127
+ if($chunks_handle)
128
+ {
129
+ while ($line = fread($chunks_handle, 1048576*2))
130
+ {
131
+ fwrite($file_handle, $line);
132
+ }
133
+ fclose($chunks_handle);
134
+ @unlink($path.$file_name.'_'.$i.'.tmp');
135
+ }
136
+ }
137
+ fclose($file_handle);
138
+ }
139
+ }
140
+ }
141
+
142
+ die();
143
+ }
144
+
145
+ function upload_files_finish()
146
+ {
147
+ $ret['html']=false;
148
+ if(isset($_POST['files']))
149
+ {
150
+ $files =stripslashes($_POST['files']);
151
+ $files =json_decode($files,true);
152
+ if(is_null($files))
153
+ {
154
+ die();
155
+ }
156
+
157
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
158
+
159
+ $backup_data['result']='success';
160
+ $backup_data['files']=array();
161
+ $first_file_name=$files[0]['name'];
162
+ $i=strpos($first_file_name,'_');
163
+ $id=substr($first_file_name,0,$i);
164
+ foreach ($files as $file)
165
+ {
166
+ if($this->check_is_a_wpvivid_backup($path.$file['name']))
167
+ {
168
+ $add_file['file_name']=$file['name'];
169
+ $add_file['size']=filesize($path.$file['name']);
170
+ $add_file['md5']=md5_file($path.$file['name']);
171
+ $backup_data['files'][]=$add_file;
172
+ }
173
+ else
174
+ {
175
+ @unlink($path.$file['name']);
176
+ }
177
+ }
178
+ if(!empty($backup_data['files']))
179
+ {
180
+ global $wpvivid_pulgin;
181
+ $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
182
+ $wpvivid_pulgin->wpvivid_log->CreateLogFile($id.'_backup','no_folder','backup');
183
+ $wpvivid_pulgin->wpvivid_log->WriteLogHander();
184
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Upload finished.','notice');
185
+ WPvivid_Backuplist::add_new_upload_backup($id,$backup_data,$wpvivid_pulgin->wpvivid_log->log_file);
186
+ $html = '';
187
+ $html = apply_filters('wpvivid_add_backup_list', $html);
188
+ $ret['html'] = $html;
189
+ }
190
+ }
191
+ echo json_encode($ret);
192
+ die();
193
+ }
194
+
195
+ function rescan_local_folder_set_backup()
196
+ {
197
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
198
+
199
+ $backups=array();
200
+ $count = 0;
201
+ if(is_dir($path))
202
+ {
203
+ $handler = opendir($path);
204
+ while (($filename = readdir($handler)) !== false)
205
+ {
206
+ if ($filename != "." && $filename != "..")
207
+ {
208
+ $count++;
209
+
210
+ if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
211
+ {
212
+ continue;
213
+ } else {
214
+
215
+ if($this->check_file_is_a_wpvivid_backup($filename,$backup_id))
216
+ {
217
+ if($this->check_is_a_wpvivid_backup($path.$filename))
218
+ $backups[$backup_id]['files'][]=$filename;
219
+ }
220
+ }
221
+ }
222
+ }
223
+ if($handler)
224
+ @closedir($handler);
225
+ }
226
+
227
+ if(!empty($backups))
228
+ {
229
+ foreach ($backups as $backup_id =>$backup)
230
+ {
231
+ $backup_data['result']='success';
232
+ $backup_data['files']=array();
233
+ foreach ($backup['files'] as $file)
234
+ {
235
+ $add_file['file_name']=$file;
236
+ $add_file['size']=filesize($path.$file);
237
+ $add_file['md5']=md5_file($path.$file);
238
+ $backup_data['files'][]=$add_file;
239
+ }
240
+ global $wpvivid_pulgin;
241
+ $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
242
+ $wpvivid_pulgin->wpvivid_log->CreateLogFile($backup_id.'_backup','no_folder','backup');
243
+ $wpvivid_pulgin->wpvivid_log->WriteLogHander();
244
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Upload finished.','notice');
245
+ WPvivid_Backuplist::add_new_upload_backup($backup_id,$backup_data,$wpvivid_pulgin->wpvivid_log->log_file);
246
+ }
247
+ }
248
+ $ret['result']='success';
249
+ $html = '';
250
+ $html = apply_filters('wpvivid_add_backup_list', $html);
251
+ $ret['html'] = $html;
252
+ echo json_encode($ret);
253
+ die();
254
+ }
255
+
256
+ static function rescan_local_folder()
257
+ {
258
+ ?>
259
+ <div style="padding-top: 10px;">
260
+ <span>Note: To rescan backups list is available for the backups created by 0.9.14 or higher version, but not including backups stored in remote storage.</span>
261
+ </div>
262
+ <div style="padding-top: 10px;">
263
+ <input type="submit" class="button-primary" value="Rescan backups list" onclick="wpvivid_rescan_local_folder();" />
264
+ </div>
265
+ <script type="text/javascript">
266
+ function wpvivid_rescan_local_folder()
267
+ {
268
+ var ajax_data = {
269
+ 'action': 'wpvivid_rescan_local_folder'
270
+ };
271
+ wpvivid_post_request(ajax_data, function (data)
272
+ {
273
+ try {
274
+ var jsonarray = jQuery.parseJSON(data);
275
+ if(jsonarray.html !== false){
276
+ jQuery('#wpvivid_backuplist').html('');
277
+ jQuery('#wpvivid_backuplist').append(jsonarray.html);
278
+ wpvivid_click_switch_page('backup', 'wpvivid_tab_backup', true);
279
+ }
280
+ }
281
+ catch(err) {
282
+ alert(err);
283
+ }
284
+ }, function (XMLHttpRequest, textStatus, errorThrown)
285
+ {
286
+ var error_message = wpvivid_output_ajaxerror('scanning backup list', textStatus, errorThrown);
287
+ alert(error_message);
288
+ });
289
+ }
290
+ </script>
291
+ <?php
292
+ }
293
+
294
+ function get_backup_count()
295
+ {
296
+ $backuplist=WPvivid_Backuplist::get_backuplist();
297
+ echo sizeof($backuplist);
298
+ die();
299
+ }
300
+
301
+ static function upload_meta_box()
302
+ {
303
+ ?>
304
+ <div id="wpvivid_plupload-upload-ui" class="hide-if-no-js">
305
+ <div id="drag-drop-area">
306
+ <div class="drag-drop-inside">
307
+ <p class="drag-drop-info"><?php _e('Drop files here'); ?></p>
308
+ <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p>
309
+ <p class="drag-drop-buttons"><input id="wpvivid_select_file_button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p>
310
+ </div>
311
+ </div>
312
+ </div>
313
+ <div id="wpvivid_upload_file_list" class="hide-if-no-js" style="padding-top: 10px; padding-bottom: 10px;"></div>
314
+ <input type="submit" class="button-primary" id="wpvivid_upload_submit_btn" value="Upload" onclick="wpvivid_submit_upload();" />
315
+ <?php
316
+ $chunk_size = min(wp_max_upload_size()-1024, 1048576*2);
317
+ $plupload_init = array(
318
+ 'runtimes' => 'html5,silverlight,flash,html4',
319
+ 'browse_button' => 'wpvivid_select_file_button',
320
+ 'container' => 'wpvivid_plupload-upload-ui',
321
+ 'drop_element' => 'drag-drop-area',
322
+ 'file_data_name' => 'async-upload',
323
+ 'multiple_queues' => true,
324
+ 'max_file_size' => '10Gb',
325
+ 'chunk_size' => $chunk_size.'b',
326
+ 'url' => admin_url('admin-ajax.php'),
327
+ 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
328
+ 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
329
+ //'filters' => array(array('title' => __('Allowed Files'), 'extensions' => '*')),
330
+ 'multipart' => true,
331
+ 'urlstream_upload' => true,
332
+
333
+ // additional post data to send to our ajax hook
334
+ 'multipart_params' => array(
335
+ 'action' => 'wpvivid_upload_files', // the ajax action name
336
+ ),
337
+ );
338
+
339
+ if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.swf')) {
340
+ $plupload_init['flash_swf_url'] = includes_url('js/plupload/Moxie.swf');
341
+ } else {
342
+ $plupload_init['flash_swf_url'] = includes_url('js/plupload/plupload.flash.swf');
343
+ }
344
+
345
+ if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.xap')) {
346
+ $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/Moxie.xap');
347
+ } else {
348
+ $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/plupload.silverlight.swf');
349
+ }
350
+
351
+ // we should probably not apply this filter, plugins may expect wp's media uploader...
352
+ $plupload_init = apply_filters('plupload_init', $plupload_init);
353
+ $upload_file_image = includes_url( '/images/media/archive.png' );
354
+ ?>
355
+
356
+
357
+ <script type="text/javascript">
358
+
359
+ var uploader;
360
+ jQuery(document).ready(function($)
361
+ {
362
+ // create the uploader and pass the config from above
363
+ jQuery('#wpvivid_upload_submit_btn').hide();
364
+ uploader = new plupload.Uploader(<?php echo json_encode($plupload_init); ?>);
365
+
366
+ // checks if browser supports drag and drop upload, makes some css adjustments if necessary
367
+ uploader.bind('Init', function(up)
368
+ {
369
+ var uploaddiv = $('#wpvivid_plupload-upload-ui');
370
+
371
+ if(up.features.dragdrop){
372
+ uploaddiv.addClass('drag-drop');
373
+ $('#drag-drop-area')
374
+ .bind('dragover.wp-uploader', function(){ uploaddiv.addClass('drag-over'); })
375
+ .bind('dragleave.wp-uploader, drop.wp-uploader', function(){ uploaddiv.removeClass('drag-over'); });
376
+
377
+ }else{
378
+ uploaddiv.removeClass('drag-drop');
379
+ $('#drag-drop-area').unbind('.wp-uploader');
380
+ }
381
+ });
382
+ uploader.init();
383
+ // a file was added in the queue
384
+ var wpvivid_upload_id='';
385
+
386
+ function wpvivid_check_plupload_added_files(up,files)
387
+ {
388
+ if(wpvivid_upload_id==='')
389
+ {
390
+ var file=files[0];
391
+
392
+ var ajax_data = {
393
+ 'action': 'wpvivid_get_file_id',
394
+ 'file_name':file.name
395
+ };
396
+ wpvivid_post_request(ajax_data, function (data)
397
+ {
398
+ var jsonarray = jQuery.parseJSON(data);
399
+ if (jsonarray.result === "success")
400
+ {
401
+ wpvivid_upload_id=jsonarray.id;
402
+ wpvivid_check_plupload_added_files(up,files);
403
+ }
404
+ else if(jsonarray.result === "failed") {
405
+ alert(jsonarray.error);
406
+ }
407
+ }, function (XMLHttpRequest, textStatus, errorThrown)
408
+ {
409
+ var error_message = wpvivid_output_ajaxerror('uploading backups', textStatus, errorThrown);
410
+ alert(error_message);
411
+ });
412
+ }
413
+ else
414
+ {
415
+ plupload.each(files, function(file)
416
+ {
417
+ var brepeat=false;
418
+ var file_list = jQuery('#wpvivid_upload_file_list span');
419
+ file_list.each(function (index, value) {
420
+ if (value.innerHTML === file.name) {
421
+ brepeat=true;
422
+ }
423
+ });
424
+ if(!brepeat) {
425
+ var wpvivid_file_regex = new RegExp('^' + wpvivid_upload_id + '_.*_.*\\.zip$');
426
+ if (wpvivid_file_regex.test(file.name)) {
427
+ jQuery('#wpvivid_upload_file_list').append(
428
+ '<div id="' + file.id + '" style="width: 100%; height: 36px; background: #fff; margin-bottom: 1px;">' +
429
+ '<img src=" <?php echo $upload_file_image; ?> " alt="" style="float: left; margin: 2px 10px 0 3px; max-width: 40px; max-height: 32px;">' +
430
+ '<div style="line-height: 36px; float: left; margin-left: 5px;"><span>' + file.name + '</span></div>' +
431
+ '<div class="fileprogress" style="line-height: 36px; float: right; margin-right: 5px;"></div>' +
432
+ '</div>' +
433
+ '<div style="clear: both;"></div>'
434
+ );
435
+ jQuery('#wpvivid_upload_submit_btn').show();
436
+ jQuery("#wpvivid_upload_submit_btn").prop('disabled', false);
437
+ }
438
+ else {
439
+ alert(file.name + " is not belong to the backup package uploaded.");
440
+ uploader.removeFile(file);
441
+ }
442
+ }
443
+ else{
444
+ alert("The backup file already exists in upload list.");
445
+ }
446
+ });
447
+ }
448
+ }
449
+
450
+ uploader.bind('FilesAdded', wpvivid_check_plupload_added_files);
451
+
452
+ uploader.bind('Error', function(up, error)
453
+ {
454
+ console.log(error);
455
+ });
456
+
457
+ uploader.bind('FileUploaded', function(up, file, response)
458
+ {
459
+ });
460
+
461
+ uploader.bind('UploadProgress', function(up, file)
462
+ {
463
+ jQuery('#' + file.id + " .fileprogress").html(file.percent + "%");
464
+ });
465
+
466
+ uploader.bind('UploadComplete',function(up, files)
467
+ {
468
+ jQuery('#wpvivid_upload_file_list').html("");
469
+ wpvivid_upload_id='';
470
+ jQuery('#wpvivid_upload_submit_btn').hide();
471
+ jQuery("#wpvivid_select_file_button").prop('disabled', false);
472
+ var ajax_data = {
473
+ 'action': 'wpvivid_upload_files_finish',
474
+ 'files':JSON.stringify(files)
475
+ };
476
+ wpvivid_post_request(ajax_data, function (data)
477
+ {
478
+ try {
479
+ var jsonarray = jQuery.parseJSON(data);
480
+ if(jsonarray.html !== false){
481
+ jQuery('#wpvivid_backuplist').html('');
482
+ jQuery('#wpvivid_backuplist').append(jsonarray.html);
483
+ wpvivid_click_switch_page('backup', 'wpvivid_tab_backup', true);
484
+ }
485
+ }
486
+ catch(err) {
487
+ alert(err);
488
+ }
489
+ }, function (XMLHttpRequest, textStatus, errorThrown)
490
+ {
491
+ var error_message = wpvivid_output_ajaxerror('refreshing backup list', textStatus, errorThrown);
492
+ alert(error_message);
493
+ });
494
+ plupload.each(files, function(file)
495
+ {
496
+ if(typeof file === 'undefined')
497
+ {
498
+
499
+ }
500
+ else
501
+ {
502
+ uploader.removeFile(file.id);
503
+ }
504
+ });
505
+ })
506
+ });
507
+
508
+ function wpvivid_submit_upload()
509
+ {
510
+ var backup_max_count='<?php
511
+ $general_setting=WPvivid_Setting::get_setting(true, "");
512
+ $display_backup_count = $general_setting['options']['wpvivid_common_setting']['max_backup_count'];
513
+ echo intval($display_backup_count);
514
+ ?>';
515
+ var ajax_data = {
516
+ 'action': 'wpvivid_get_backup_count'
517
+ };
518
+ wpvivid_post_request(ajax_data, function (data)
519
+ {
520
+ var backuplist_count = data;
521
+ if(backuplist_count >= backup_max_count){
522
+ alert("The maximum number for listing backups is reached, please manually remove a backup from backups list to start uploading.");
523
+ }
524
+ else {
525
+ jQuery("#wpvivid_upload_submit_btn").prop('disabled', true);
526
+ jQuery("#wpvivid_select_file_button").prop('disabled', true);
527
+ uploader.refresh();
528
+ uploader.start();
529
+ }
530
+
531
+ }, function (XMLHttpRequest, textStatus, errorThrown)
532
+ {
533
+ var error_message = wpvivid_output_ajaxerror('uploading backups', textStatus, errorThrown);
534
+ alert(error_message);
535
+ });
536
+ }
537
+ </script>
538
+ <?php
539
+ }
540
+
541
+ public function upload_dir($uploads)
542
+ {
543
+ $uploads['path'] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
544
+ return $uploads;
545
+ }
546
+
547
+ private function check_is_a_wpvivid_backup($file_name)
548
+ {
549
+ $info=WPvivid_Backup_Item::get_backup_file_info($file_name);
550
+ if($info===false)
551
+ {
552
+ return false;
553
+ }
554
+ else
555
+ {
556
+ return true;
557
+ }
558
+ }
559
+ }
includes/class-wpvivid-backup.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
 
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
 
4
  die;
5
  }
6
 
@@ -13,380 +14,1464 @@ define('WPVIVID_BACKUP_TYPE_CORE','backup_core');
13
  define('WPVIVID_BACKUP_TYPE_OTHERS','backup_others');
14
  define('WPVIVID_BACKUP_TYPE_MERGE','backup_merge');
15
 
16
- include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-rollback.php';
17
- class WPvivid_Backup{
18
- private $i_progress;
19
- private $i_step;
20
- private $options;
21
- public $log;
22
- public $task_id;
23
 
24
- public function get_default_exclude_regex($type_name = '')
25
  {
26
- $options = WPvivid_Setting::get_option('wpvivid_common_setting');
27
- if(!isset($options['log_save_location']))
28
  {
29
- WPvivid_Setting::set_default_common_option();
30
- $options = WPvivid_Setting::get_option('wpvivid_common_setting');
31
  }
32
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'updraft', '/').'#'; // Updraft Plus backup directory
33
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_UPLOADS).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
34
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_UPLOADS).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
35
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'ai1wm-backups', '/').'#'; // All-in-one WP migration backup directory
36
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'backups', '/').'#'; // Xcloner backup directory
37
 
38
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'upgrade', '/').'#';
39
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'wpvivid', '/').'#';
40
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(), '/').'#';
41
- $regex['directory'][]='#^'.preg_quote(WPVIVID_PLUGIN_DIR, '/').'#';
42
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.$options['log_save_location'], '/').'#';
43
- switch ($type_name)
44
  {
45
- case WPVIVID_BACKUP_TYPE_CONTENT:
46
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_PLUGIN), '/').'#';
47
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_THEMES), '/').'#';
48
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_UPLOADS), '/').'#';
49
- break;
50
- case WPVIVID_BACKUP_TYPE_CORE:
51
- $abs_path = $this ->get_default_directory(WPVIVID_BACKUP_TYPE_CORE).DIRECTORY_SEPARATOR;
52
- $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT), '/').'#';
53
- $regex['directory'][]='#^'.preg_quote($abs_path.'wp-snapshots', '/').'#'; // Duplicator backup directory
54
- $regex['file'][]='#^'.preg_quote($abs_path.'.maintenance', '/').'#';
55
- break;
56
  }
57
- return $regex;
58
  }
59
 
60
- public function get_default_directory($type_name = ''){
61
- $upload_dir = wp_upload_dir();
62
- $paths = array(
63
- WPVIVID_BACKUP_TYPE_CORE => $this -> transfer_path(dirname(WP_CONTENT_DIR)),
64
- WPVIVID_BACKUP_TYPE_CONTENT => $this -> transfer_path(WP_CONTENT_DIR),
65
- WPVIVID_BACKUP_TYPE_PLUGIN => $this -> transfer_path(WP_PLUGIN_DIR),
66
- WPVIVID_BACKUP_TYPE_THEMES => $this -> transfer_path(get_theme_root()),
67
- WPVIVID_BACKUP_TYPE_UPLOADS => $this -> transfer_path($upload_dir['basedir']),
68
- );
69
 
70
- if(empty($type_name) || empty($paths[$type_name])){
71
- return '';
72
- }else{
73
- return $paths[$type_name];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
- private function transfer_path($path){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  $path = str_replace('\\','/',$path);
78
  $values = explode('/',$path);
79
  return implode(DIRECTORY_SEPARATOR,$values);
80
  }
81
 
82
- public function init_options($task_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  {
84
- $this->task_id=$task_id;
85
- $options_name[]='backup_options';
86
- $options_name[]='ismerge';
87
- $options_name[]='file_prefix';
88
- $options_name[]='log_file_name';
89
- $this->options=WPvivid_taskmanager::get_task_options($task_id,$options_name);
90
-
91
- $this->log=new WPvivid_Log();
92
- $this->log->OpenLogFile($this->options['log_file_name']);
93
- }
94
 
95
- public function backup($task_id)
96
- {
97
- add_filter('wpvivid_backup_get_files_list', array($this, 'get_files_list'),10,2);
98
- $this->init_options($task_id);
99
- WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'backup',0,0);
100
- $flag = true;
101
- $error = '';
102
- $type=array();
103
- $this->i_progress=0;
104
- if($this->options['ismerge'])
105
  {
106
- $this->i_step=intval(1/(sizeof( $this->options['backup_options']['backup']['backup_type'])+1)*100);
107
  }
108
  else
109
  {
110
- $this->i_step=intval(1/sizeof($this->options['backup_options']['backup']['backup_type'])*100);
111
  }
 
112
 
113
- foreach ($this->options['backup_options']['backup']['backup_type'] as $type_name=>$extra_data)
114
- {
115
- global $wpvivid_pulgin;
116
- $wpvivid_pulgin->check_cancel_backup($this->task_id);
 
 
 
117
 
118
- $backup_job=WPvivid_taskmanager::get_backup_sub_task_progress($this->task_id,'backup',$type_name);
119
- if($backup_job&&$backup_job['finished']==1)
120
- {
121
- $wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$type_name.' completed','notice');
122
- $result =$backup_job['job_data'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  }
124
- else
 
 
 
 
 
 
 
 
125
  {
126
- global $wpvivid_pulgin;
127
- $wpvivid_pulgin->set_time_limit($this->task_id);
128
- $wpvivid_pulgin->wpvivid_log->WriteLog('Getting '.$type_name.' data.','notice');
129
- $data=$this->get_backup_needed_data($type_name,$extra_data);
130
- $result = $this->backup_loop_ex($data);
131
- }
132
-
133
- if($result['result'] == WPVIVID_SUCCESS)
134
- {
135
- if($this->i_progress<100)
136
- $this->i_progress+=$this->i_step;
137
- WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'backup',$this->i_progress,0);
138
- $type[] = array(
139
- 'type_name' => $type_name,
140
- 'files' => $result['files'],
141
- );
142
- }else{
143
- $wpvivid_pulgin->wpvivid_log->WriteLog('Failed to backup '.$type_name.', error: '.$result['error'],'notice');
144
- $flag = false;
145
- $error =$result['error'];
146
- break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
147
  }
148
- }
149
-
150
- if($flag)
151
- {
152
- $zip_result = array
153
- (
154
- 'result' => WPVIVID_SUCCESS,
155
- 'ismerge' => $this->options['ismerge'] ,
156
- 'data' => array
157
- (
158
- 'type' => $type ,
159
- 'meta' => array()
160
- )
161
- );
162
- if($this->options['ismerge'])
163
- {
164
- global $wpvivid_pulgin;
165
- $wpvivid_pulgin->set_time_limit($this->task_id);
166
-
167
- $wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to compress backup_merge.','notice');
168
- $res =$this->Merge_backup($type);
169
-
170
- if($res['result'] == WPVIVID_SUCCESS)
171
- {
172
- $wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.WPVIVID_BACKUP_TYPE_MERGE.' succeeded.','notice');
173
- $zip_result['data']['meta']=array('type_name' => WPVIVID_BACKUP_TYPE_MERGE , 'files' => $res['files']);
174
  }
175
- else
176
- {
177
- $wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.WPVIVID_BACKUP_TYPE_MERGE.' failed, error: '.$error,'notice');
178
- $zip_result =array(
179
- 'result' => WPVIVID_FAILED,
180
- 'error' => $error,
181
- );
182
  }
 
 
 
 
 
 
 
 
 
183
  }
184
- }else {
185
- $zip_result= array
186
- (
187
- 'result' => WPVIVID_FAILED,
188
- 'error' => $error,
189
- );
190
- }
191
 
192
- if($zip_result['result']==WPVIVID_SUCCESS)
 
 
 
193
  {
194
- WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'backup',100,1,$zip_result);
195
  }
196
  else
197
  {
198
- $file_prefix =WPvivid_taskmanager::get_task_options($this->task_id,'file_prefix');
199
- $backup_options=WPvivid_taskmanager::get_task_options($this->task_id,'backup_options');
200
- $this->clean_backup($file_prefix,$backup_options['dir']);
201
- WPvivid_taskmanager::update_backup_task_status($this->task_id,false,'error',false,false,$zip_result['error']);
202
  }
 
 
203
 
204
- return $zip_result;
205
- }
 
 
206
 
207
- private function get_backup_needed_data($type_name,$extra_data)
208
  {
209
- $data = array();
210
- $data['compress']=$this->options['backup_options']['compress'];
211
- $data['path'] = $this->createCompressPath(WP_CONTENT_DIR.'/'. $this->options['backup_options']['dir'],$this->options['file_prefix'],$type_name,$this->options['backup_options']['compress']['compress_type']);
212
- $data['type'] = $type_name;
213
-
214
- $data['log'] = $this->log;
215
- $data=apply_filters('wpvivid_backup_set_exart_data',$data,$extra_data,$type_name);
 
 
 
 
 
 
 
216
 
217
- return $data;
 
 
218
  }
219
 
220
- private function backup_loop_ex($data)
221
  {
222
- include_once 'class-wpvivid-backup-database.php';
223
- include_once 'class-wpvivid-backup-site.php';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
 
225
- $backup_database = new WPvivid_Backup_Database();
226
- $backup_site = new WPvivid_Backup_Site();
227
 
228
- WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',$data['type'],0,'Start backing up '.$data['type'].'.');
 
 
229
 
230
- if($data['type'] === WPVIVID_BACKUP_TYPE_DB)
 
 
 
 
 
231
  {
232
- $this->log->WriteLog('Start exporting database.','notice');
233
- $result = $backup_database -> backup_database($data,$this->task_id);
234
- $this->log->WriteLog('Exporting database finished.','notice');
 
 
235
  if($result['result']==WPVIVID_SUCCESS)
236
  {
237
- $files=$result['files'];
238
- //$files[]=$this->create_backup_json('db');
239
- $this->log->WriteLog('Prepare to backup '.$data['type'].' files.','notice');
240
- $result = $backup_site -> backup_files($data,$files,$this->task_id);
241
- $this->log->WriteLog('Backing up '.$data['type'].' completed.','notice');
242
- foreach ($files as $sql_file)
243
- {
244
- @unlink($sql_file);
245
- }
246
  }
247
  }
248
- else
 
 
 
249
  {
250
- $files=array();
251
- $files=apply_filters('wpvivid_backup_get_files_list',$files,$data);
252
- //$files[]=$this->create_backup_json('file');
253
- $this->log->WriteLog('Prepare to backup '.$data['type'].' files.','notice');
254
- $result = $backup_site -> backup_files($data,$files,$this->task_id);
255
- $this->log->WriteLog('Backing up '.$data['type'].' completed.','notice');
256
  }
257
- $res = array();
258
-
259
- if($result['result'] == WPVIVID_FAILED)
 
260
  {
261
- $res = $result;
262
- }else{
263
- $res['result'] = WPVIVID_SUCCESS;
264
- $res['files'] = $result['meta'];
265
- WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',$data['type'],1,'Backing up '.$data['type'].' finished.',$res);
266
  }
267
- return $res;
 
268
  }
269
 
270
- private function Merge_backup($type)
271
  {
272
- include_once 'class-wpvivid-backup-site.php';
273
- $backup_site = new WPvivid_Backup_Site();
274
- $file_list = array();
275
- foreach ($type as $item)
276
- {
277
- foreach ($item['files'] as $file){
278
- $file_list[] = WP_CONTENT_DIR.'/'. $this->options['backup_options']['dir'].DIRECTORY_SEPARATOR.$file['file_name'];
279
- }
280
- }
281
- $data=array();
282
- $data['path'] = $this->createCompressPath(WP_CONTENT_DIR.'/'. $this->options['backup_options']['dir'],$this->options['file_prefix'],'all',$this->options['backup_options']['compress']['compress_type']);
283
- $data['type']=WPVIVID_BACKUP_TYPE_MERGE;
284
- $data['compress']=$this->options['backup_options']['compress'];
285
- $data['log'] = $this->log;
286
-
287
- $this->log->WriteLog('Start compressing backup packages for a complete backup.','notice');
288
- WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_MERGE,0,'Start compressing backup packages for a complete backup.');
289
- $result = $backup_site -> backup_files($data,$file_list,$this->task_id);
290
- $res = array();
291
- if($result['result'] == WPVIVID_FAILED)
292
- {
293
- $this->log->WriteLog('File compression failed, error: '.$result['error'],'notice');
294
- $res['result'] = WPVIVID_FAILED;
295
- $res['error'] = $result['error'];
296
- }else{
297
- $this->log->WriteLog('File compression finished.','notice');
298
- $res['result'] = WPVIVID_SUCCESS;
299
- $res['files'] = $result['meta'];
300
- WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_MERGE,1,'File compression finished.',$res);
301
- }
302
- foreach ($type as $item)
303
  {
304
- foreach ($item['files'] as $file)
305
- {
306
- $this->log->WriteLog('Cleaned up file, filename: '.WP_CONTENT_DIR.'/'. $this->options['backup_options']['dir'].DIRECTORY_SEPARATOR.$file['file_name'],'notice');
307
- @unlink(WP_CONTENT_DIR.'/'. $this->options['backup_options']['dir'].DIRECTORY_SEPARATOR.$file['file_name']);
308
  }
309
  }
310
- return $res;
311
  }
312
 
313
- public function upload($task_id,$files)
314
  {
315
- $this->task_id=$task_id;
316
- WPvivid_taskmanager::update_backup_main_task_progress($task_id,'upload',0,0);
317
- $remote_options=WPvivid_taskmanager::get_task_options($task_id,'remote_options');
318
-
319
- $remote_option=array_shift($remote_options);
320
-
321
- if(is_null($remote_option))
322
  {
323
- return array('result' => WPVIVID_FAILED , 'error' => 'not select remote storage');
 
324
  }
 
 
325
 
326
- global $wpvivid_pulgin;
327
-
328
- $remote=$wpvivid_pulgin->remote_collection->get_remote($remote_option);
329
-
330
- $result=$remote->upload($task_id,$files,array($this,'upload_callback'));
331
-
332
- if($result['result']==WPVIVID_SUCCESS)
333
  {
334
- WPvivid_taskmanager::update_backup_main_task_progress($task_id,'upload',100,1);
335
-
336
- return array('result' => WPVIVID_SUCCESS);
337
  }
338
- else
 
 
 
 
 
 
 
 
 
 
 
339
  {
340
- $remote ->cleanup($files);
341
- return array('result' => WPVIVID_FAILED , 'error' => $result['error']);
 
 
 
 
 
 
 
 
 
342
  }
 
343
  }
344
 
345
- public function upload_callback($offset,$current_name,$current_size,$last_time,$last_size)
346
- {
347
- $v =( $offset - $last_size ) / (time() - $last_time);
348
- $v /= 1000;
349
- $v=round($v,2);
 
 
 
 
350
 
351
- global $wpvivid_pulgin;
352
- $wpvivid_pulgin->check_cancel_backup($this->task_id);
353
-
354
- $message='Uploading '.$current_name.' Total size: '.size_format($current_size,2).' Uploaded: '.size_format($offset,2).' speed:'.$v.'kb/s';
355
-
356
- $progress=intval(($offset/$current_size)*100);
357
- WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'upload',$progress,0);
358
- WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'upload',WPVIVID_REMOTE_SFTP,'0',$message);
359
- }
360
-
361
- public function delete($path,$result,$ismerge){
362
- $flag = true;
363
- if($ismerge){
364
- foreach ($result['meta']['files'] as $file)
365
- {
366
- if(!unlink($path.DIRECTORY_SEPARATOR.$file['file_name'])){
367
- $flag = false;
368
- break;
369
- }
370
- if(!unlink($path.DIRECTORY_SEPARATOR.$file['file_name'].'.txt')){
371
- $flag = false;
372
- break;
373
- }
374
- }
375
- }else{
376
- foreach ($result['type'] as $item) {
377
- foreach ($item['files'] as $file){
378
- if(!unlink($path.DIRECTORY_SEPARATOR.$file['file_name'])){
379
- $flag = false;
380
- break 2;
381
- }
382
- if(!unlink($path.DIRECTORY_SEPARATOR.$file['file_name'].'.txt')){
383
- $flag = false;
384
- break 2;
385
- }
386
- }
387
- }
388
- }
389
- return $flag;
390
  }
391
 
392
  public function getFile($path ,$exclude_regex,$include_regex,$exclude_file_size,$log)
@@ -433,7 +1518,6 @@ class WPvivid_Backup{
433
  }
434
  }
435
 
436
-
437
  private function regex_match($regex_array,$string,$mode)
438
  {
439
  if(empty($regex_array))
@@ -470,27 +1554,6 @@ class WPvivid_Backup{
470
  return true;
471
  }
472
 
473
- public function createCompressPath($path,$file_prefix,$type,$compress_type){
474
- return $path.DIRECTORY_SEPARATOR.$file_prefix.'_'.$type.'.'.$compress_type;
475
- }
476
-
477
- public function writetotxt($path,$message){
478
- file_put_contents($path.'.txt', print_r($message, true));
479
- }
480
-
481
- public function clean_backup($file_prefix,$backup_dir)
482
- {
483
- $backup_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_dir;
484
- $temp_files = array();
485
- $this -> getFileLoop($temp_files,$backup_path,array(),array(),false);
486
- foreach ($temp_files as $file){
487
- if(preg_match('&'.$file_prefix.'&',$file)){
488
- @unlink($file);
489
- }
490
- }
491
- WPvivid_tools::clearcache($file_prefix);
492
- }
493
-
494
  public function clean_remote_backup($remotes,$files)
495
  {
496
  $remote_option=array_shift($remotes);
@@ -540,151 +1603,4 @@ class WPvivid_Backup{
540
 
541
  return $files;
542
  }
543
-
544
- public function create_backup_json($type,$file_info=array(),$db_info=array())
545
- {
546
- $json['plugin_name']=WPVIVID_PLUGIN_SLUG;
547
- $json['plugin_version']=WPVIVID_PLUGIN_VERSION;
548
- $json['wordpress_version']=get_bloginfo( 'version' );;
549
- $json['type']=$type;
550
-
551
- $path=WP_CONTENT_DIR.'/'. $this->options['backup_options']['dir'].DIRECTORY_SEPARATOR.'wpvivid_backup.json';
552
- file_put_contents($path,json_encode($json));
553
- return $path;
554
- //$path.DIRECTORY_SEPARATOR.$file_prefix.'_'.$type.'.'.$compress_type
555
- }
556
-
557
- public static function check_backup_options($backup_options)
558
- {
559
- $ret['result']=WPVIVID_FAILED;
560
-
561
- if(isset($backup_options['backup_files']))
562
- {
563
- $backup_options['backup_files']=sanitize_text_field($backup_options['backup_files']);
564
-
565
- if(empty($backup_options['backup_files']))
566
- {
567
- $ret['error']=__('A backup type is required.', 'wpvivid');
568
- return $ret;
569
- }
570
-
571
- if($backup_options['backup_files']=='files+db')
572
- {
573
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_DB]=0;
574
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_THEMES]=0;
575
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_PLUGIN]=0;
576
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_UPLOADS]=0;
577
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_CONTENT]=0;
578
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_CORE]=0;
579
- }
580
- else if($backup_options['backup_files']=='files')
581
- {
582
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_THEMES]=0;
583
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_PLUGIN]=0;
584
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_UPLOADS]=0;
585
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_CONTENT]=0;
586
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_CORE]=0;
587
- }
588
- else if($backup_options['backup_files']=='db')
589
- {
590
- $task_options['backup_options']['backup']['backup_type'][WPVIVID_BACKUP_TYPE_DB]=0;
591
- }
592
- else
593
- {
594
- $ret['error']=__('A backup type is required.', 'wpvivid');
595
- return $ret;
596
- }
597
- }
598
- else
599
- {
600
- if(isset($backup_options['backup_type'])&&is_array($backup_options['backup_type'])&&!empty($backup_options['backup_type']))
601
- {
602
- foreach ($backup_options['backup_type'] as $type=>$check)
603
- {
604
- if($check)
605
- $task_options['backup_options']['backup']['backup_type'][$type]=0;
606
- }
607
- }
608
- else
609
- {
610
- $ret['error']=__('A backup type is required.', 'wpvivid');
611
- return $ret;
612
- }
613
- }
614
- $task_options['backup_options']['compress']=WPvivid_Setting::get_option('wpvivid_compress_setting');
615
- $task_options['backup_options']['dir']=WPvivid_Setting::get_backupdir();
616
-
617
- if(isset($backup_options['local']) || isset($backup_options['remote']))
618
- {
619
- $backup_options['local']=sanitize_text_field($backup_options['local']);
620
- $backup_options['remote']=sanitize_text_field($backup_options['remote']);
621
-
622
- if(isset($backup_options['remote']))
623
- {
624
- if($backup_options['remote'] === '1')
625
- {
626
- $task_options['remote_options']=WPvivid_Setting::get_remote_options();
627
- if( $task_options['remote_options'] == false)
628
- {
629
- $ret['error']=__('There is no default remote storage configured. Please set it up first.', 'wpvivid');
630
- return $ret;
631
- }
632
- }
633
- else
634
- {
635
- $task_options['remote_options']=false;
636
- }
637
- }
638
- else
639
- {
640
- $task_options['remote_options']=false;
641
- }
642
-
643
- if(isset($backup_options['local']))
644
- {
645
- if($backup_options['local']=='1')
646
- {
647
- $task_options['save_local']=1;
648
- }
649
- else
650
- {
651
- $task_options['save_local']=0;
652
- }
653
- }
654
- else
655
- {
656
- $task_options['save_local']=0;
657
- }
658
- }
659
- else
660
- {
661
- $ret['error']=__('Choose at least one storage location for backups.', 'wpvivid');
662
- return $ret;
663
- }
664
-
665
- if($backup_options['ismerge']=='1')
666
- {
667
- $task_options['ismerge']=1;
668
- }
669
- else
670
- {
671
- $task_options['ismerge']=0;
672
- }
673
-
674
- $options=WPvivid_Setting::get_option('wpvivid_common_setting');
675
- if(isset($options['max_execution_time']))
676
- {
677
- $task_options['max_execution_time']=$options['max_execution_time'];
678
- }
679
- else
680
- {
681
- $task_options['max_execution_time']=WPVIVID_MAX_EXECUTION_TIME;
682
- }
683
-
684
- $task_options['lock']=$backup_options['lock'];
685
-
686
- $ret['result']=WPVIVID_SUCCESS;
687
- $ret['options']=$task_options;
688
- return $ret;
689
- }
690
  }
1
  <?php
2
 
3
+ if (!defined('WPVIVID_PLUGIN_DIR'))
4
+ {
5
  die;
6
  }
7
 
14
  define('WPVIVID_BACKUP_TYPE_OTHERS','backup_others');
15
  define('WPVIVID_BACKUP_TYPE_MERGE','backup_merge');
16
 
17
+ class WPvivid_Backup_Task
18
+ {
19
+ private $task;
 
 
 
 
20
 
21
+ public function __construct($task_id=false,$task=false)
22
  {
23
+ if($task_id!==false)
 
24
  {
25
+ $this->task=WPvivid_taskmanager::get_task($task_id);
 
26
  }
 
 
 
 
 
27
 
28
+ if($task!==false)
 
 
 
 
 
29
  {
30
+ $this->task=$task;
 
 
 
 
 
 
 
 
 
 
31
  }
 
32
  }
33
 
34
+ public function get_id()
35
+ {
36
+ return $this->task['id'];
37
+ }
 
 
 
 
 
38
 
39
+ public function new_backup_task($options,$type,$action='backup')
40
+ {
41
+ $id=uniqid('wpvivid-');
42
+ $this->task=false;
43
+ $this->task['id']=$id;
44
+ $this->task['action']=$action;
45
+ $this->task['type']=$type;
46
+
47
+ $this->task['status']['start_time']=time();
48
+ $this->task['status']['run_time']=time();
49
+ $this->task['status']['timeout']=time();
50
+ $this->task['status']['str']='ready';
51
+ $this->task['status']['resume_count']=0;
52
+
53
+ if(isset($options['remote']))
54
+ {
55
+ if($options['remote']=='1')
56
+ {
57
+ if(isset($options['remote_options']))
58
+ {
59
+ $this->task['options']['remote_options']=$options['remote_options'];
60
+ }
61
+ else
62
+ {
63
+ $this->task['options']['remote_options']=WPvivid_Setting::get_remote_options();
64
+ }
65
+
66
+ }
67
+ else {
68
+ $this->task['options']['remote_options']=false;
69
+ }
70
+ }
71
+ else
72
+ {
73
+ $this->task['options']['remote_options']=false;
74
+ }
75
+
76
+ if(isset($options['local']))
77
+ {
78
+ if($options['local']=='1')
79
+ {
80
+ $this->task['options']['save_local']=1;
81
+ }
82
+ else
83
+ {
84
+ $this->task['options']['save_local']=0;
85
+ }
86
+ }
87
+ else
88
+ {
89
+ $this->task['options']['save_local']=1;
90
+ }
91
+
92
+ if(isset($options['lock']))
93
+ {
94
+ $this->task['options']['lock']=$options['lock'];
95
+ }
96
+ else
97
+ {
98
+ $this->task['options']['lock']=0;
99
+ }
100
+
101
+ if(isset($options['ismerge']))
102
+ {
103
+ if($options['ismerge']=='1')
104
+ {
105
+ $this->task['options']['backup_options']['ismerge']=1;
106
+ }
107
+ else {
108
+ $this->task['options']['backup_options']['ismerge']=0;
109
+ }
110
+ }
111
+ else {
112
+ $this->task['options']['backup_options']['ismerge']=1;
113
+ }
114
+
115
+ $this->task['options']['file_prefix']=$this->task['id'].'_'.date('Y-m-d-H-i',$this->task['status']['start_time']);
116
+ $this->task['options']['log_file_name']=$id.'_backup';
117
+ $log=new WPvivid_Log();
118
+ $log->CreateLogFile($this->task['options']['log_file_name'],'no_folder','backup');
119
+ $log->CloseFile();
120
+
121
+ $this->task['options']['backup_options']['prefix']=$this->task['options']['file_prefix'];
122
+ $this->task['options']['backup_options']['compress']=WPvivid_Setting::get_option('wpvivid_compress_setting');
123
+ $this->task['options']['backup_options']['dir']=WPvivid_Setting::get_backupdir();
124
+ $this->task['options']['backup_options']['backup']=array();
125
+
126
+ if(isset($options['backup_files']))
127
+ {
128
+ if($options['backup_files']=='files+db')
129
+ {
130
+ $this->set_backup(WPVIVID_BACKUP_TYPE_DB);
131
+ $this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
132
+ $this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
133
+ $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
134
+ $this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
135
+ $this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
136
+ }
137
+ else if($options['backup_files']=='files')
138
+ {
139
+ $this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
140
+ $this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
141
+ $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
142
+ $this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
143
+ $this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
144
+ }
145
+ else if($options['backup_files']=='db')
146
+ {
147
+ $this->set_backup(WPVIVID_BACKUP_TYPE_DB);
148
+ }
149
+ else{
150
+ if($options['backup_files']['backup_db'] == '1'){
151
+ $this->set_backup(WPVIVID_BACKUP_TYPE_DB);
152
+ }
153
+ if($options['backup_files']['backup_themes'] == '1'){
154
+ $this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
155
+ }
156
+ if($options['backup_files']['backup_plugin'] == '1'){
157
+ $this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
158
+ }
159
+ if($options['backup_files']['backup_uploads'] == '1'){
160
+ $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
161
+ }
162
+ if($options['backup_files']['backup_content'] == '1'){
163
+ $this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
164
+ }
165
+ if($options['backup_files']['backup_core'] == '1'){
166
+ $this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
167
+ }
168
+ }
169
  }
170
+
171
+ $this->task['data']['doing']='backup';
172
+ $this->task['data']['backup']['doing']='';
173
+ $this->task['data']['backup']['finished']=0;
174
+ $this->task['data']['backup']['progress']=0;
175
+ $this->task['data']['backup']['job_data']=array();
176
+ $this->task['data']['backup']['sub_job']=array();
177
+ $this->task['data']['backup']['db_size']='0';
178
+ $this->task['data']['backup']['files_size']['sum']='0';
179
+ $this->task['data']['upload']['doing']='';
180
+ $this->task['data']['upload']['finished']=0;
181
+ $this->task['data']['upload']['progress']=0;
182
+ $this->task['data']['upload']['job_data']=array();
183
+ $this->task['data']['upload']['sub_job']=array();
184
+ WPvivid_Setting::update_task($id,$this->task);
185
+ $ret['result']='success';
186
+ $ret['task_id']=$this->task['id'];
187
+
188
+ return $ret;
189
  }
190
+
191
+ public function set_backup($backup)
192
+ {
193
+ if(is_string($backup))
194
+ {
195
+ $backup_data['key']=$backup;
196
+ $backup_data['result']=false;
197
+ $backup_data['compress']=$this->task['options']['backup_options']['compress'];
198
+ $backup_data['finished']=0;
199
+ $backup_data['path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR. $this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR;
200
+ if($backup==WPVIVID_BACKUP_TYPE_DB)
201
+ {
202
+ $backup_data['root_path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'];
203
+ $backup_data['dump_db']=1;
204
+ $backup_data['sql_file_name']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$this->get_prefix().'_backup_db.sql';
205
+ $backup_data['json_info']['dump_db']=1;
206
+ $backup_data['prefix']=$this->get_prefix().'_backup_db';
207
+ $this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
208
+ }
209
+ else if($backup==WPVIVID_BACKUP_TYPE_THEMES)
210
+ {
211
+ $backup_data['root_path']=WP_CONTENT_DIR;
212
+ $backup_data['prefix']=$this->get_prefix().'_backup_themes';
213
+ $backup_data['files_root']=$this->transfer_path(get_theme_root());
214
+ $backup_data['exclude_regex']=array();
215
+ $backup_data['include_regex']=array();
216
+ $this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
217
+ }
218
+ else if($backup==WPVIVID_BACKUP_TYPE_PLUGIN)
219
+ {
220
+ $backup_data['root_path']=WP_CONTENT_DIR;
221
+ $backup_data['prefix']=$this->get_prefix().'_backup_plugin';
222
+ $backup_data['files_root']=$this->transfer_path(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.'plugins');
223
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'wpvivid-backuprestore'), '/').'#';
224
+ $backup_data['exclude_regex']=$exclude_regex;
225
+ $backup_data['include_regex']=array();
226
+ }
227
+ else if($backup==WPVIVID_BACKUP_TYPE_UPLOADS)
228
+ {
229
+ $backup_data['root_path']=WP_CONTENT_DIR;
230
+ $backup_data['prefix']=$this->get_prefix().'_backup_uploads';
231
+ $upload_dir = wp_upload_dir();
232
+ $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
233
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
234
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
235
+ $backup_data['exclude_regex']=$exclude_regex;
236
+ $backup_data['include_regex']=array();
237
+ }
238
+ else if($backup==WPVIVID_BACKUP_TYPE_CONTENT)
239
+ {
240
+ $backup_data['root_path']=get_home_path();
241
+ $backup_data['prefix']=$this->get_prefix().'_backup_content';
242
+ $backup_data['files_root']=$this -> transfer_path(WP_CONTENT_DIR);
243
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'updraft', '/').'#'; // Updraft Plus backup directory
244
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'ai1wm-backups', '/').'#'; // All-in-one WP migration backup directory
245
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'backups', '/').'#'; // Xcloner backup directory
246
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'upgrade', '/').'#';
247
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'wpvivid', '/').'#';
248
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(), '/').'#';
249
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.'plugins'), '/').'#';
250
+ $upload_dir = wp_upload_dir();
251
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';
252
+ $exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
253
+ $backup_data['exclude_regex']=$exclude_regex;
254
+ $backup_data['include_regex']=array();
255
+ }
256
+ else if($backup==WPVIVID_BACKUP_TYPE_CORE)
257
+ {
258
+ $backup_data['root_path']=get_home_path();
259
+ $backup_data['prefix']=$this->get_prefix().'_backup_core';
260
+ $backup_data['files_root']=$this -> transfer_path(get_home_path());
261
+ $backup_data['json_info']['include_path'][]='wp-includes';
262
+ $backup_data['json_info']['include_path'][]='wp-admin';
263
+ $backup_data['json_info']['wp_core']=1;
264
+ $include_regex[]='#^'.preg_quote($this -> transfer_path(get_home_path().DIRECTORY_SEPARATOR.'wp-admin'), '/').'#';
265
+ $include_regex[]='#^'.preg_quote($this->transfer_path(get_home_path().DIRECTORY_SEPARATOR.'wp-includes'), '/').'#';
266
+ $backup_data['exclude_regex']=array();
267
+ $backup_data['include_regex']=$include_regex;
268
+ }
269
+ else if($backup==WPVIVID_BACKUP_TYPE_MERGE)
270
+ {
271
+ $backup_data['root_path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'];
272
+ $backup_data['prefix']=$this->get_prefix().'_backup_all';
273
+
274
+ $backup_data['files']=array();
275
+ foreach ($this->task['options']['backup_options']['backup'] as $backup_finished_data)
276
+ {
277
+ $backup_data['files']=array_merge($backup_data['files'],$this->get_backup_file($backup_finished_data['key']));
278
+ }
279
+ $backup_data['json_info']['has_child']=1;
280
+ }
281
+ else
282
+ {
283
+ $backup_data=false;
284
+ }
285
+ if($backup_data!==false)
286
+ {
287
+ $this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
288
+ }
289
+ }
290
+ }
291
+
292
+ public function get_need_backup_files($backup_data)
293
+ {
294
+ if(isset($backup_data['files'])&&empty($backup_data['files']))
295
+ {
296
+ return $backup_data['files'];
297
+ }
298
+ else
299
+ {
300
+ return $this->get_file_list($backup_data['files_root'],$backup_data['exclude_regex'],$backup_data['include_regex'],$this->task['options']['backup_options']['compress']['exclude_file_size']);
301
+ }
302
+ }
303
+
304
+ public function get_backup_file($key)
305
+ {
306
+ $files=array();
307
+ if(array_key_exists($key,$this->task['options']['backup_options']['backup']))
308
+ {
309
+ $backup=$this->task['options']['backup_options']['backup'][$key];
310
+ if($backup['finished'])
311
+ {
312
+ if($backup['result']!=false)
313
+ {
314
+ foreach ($backup['result']['files'] as $file_data)
315
+ {
316
+ $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$file_data['file_name'];
317
+ }
318
+ }
319
+ }
320
+ }
321
+ return $files;
322
+ }
323
+
324
+ public function get_need_backup()
325
+ {
326
+ $backup=false;
327
+ $i_finished_backup_count=0;
328
+ $i_count_of_backup=sizeof($this->task['options']['backup_options']['backup']);
329
+ foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
330
+ {
331
+ if($backup_data['result']!==false)
332
+ {
333
+ $ret=$backup_data['result'];
334
+ if($ret['result']!==WPVIVID_SUCCESS)
335
+ {
336
+ return false;
337
+ }
338
+ }
339
+
340
+ if( $backup_data['finished']==0)
341
+ {
342
+ if($backup===false)
343
+ {
344
+ if(!isset($backup_data['dump_db']))
345
+ {
346
+ $backup_data['files']=$this->get_need_backup_files($backup_data);
347
+ }
348
+ $backup=$backup_data;
349
+ }
350
+ }
351
+ else {
352
+ $i_finished_backup_count++;
353
+ }
354
+ }
355
+
356
+ if($i_count_of_backup>0)
357
+ {
358
+ $i_progress=intval(1/$i_count_of_backup*100);
359
+ WPvivid_taskmanager::update_backup_main_task_progress($this->task['id'],'backup',$i_progress*$i_finished_backup_count,0);
360
+
361
+ if($i_finished_backup_count>=$i_count_of_backup)
362
+ {
363
+ if($this->task['options']['backup_options']['ismerge']==1)
364
+ {
365
+ if(!array_key_exists(WPVIVID_BACKUP_TYPE_MERGE,$this->task['options']['backup_options']['backup']))
366
+ {
367
+ $this->set_backup(WPVIVID_BACKUP_TYPE_MERGE);
368
+ $backup=$this->task['options']['backup_options']['backup'][WPVIVID_BACKUP_TYPE_MERGE];
369
+ }
370
+ }
371
+ }
372
+ }
373
+ return $backup;
374
+ }
375
+
376
+ public function update_backup_result($backup_data,$result)
377
+ {
378
+ if(array_key_exists($backup_data['key'],$this->task['options']['backup_options']['backup']))
379
+ {
380
+ $this->task['options']['backup_options']['backup'][$backup_data['key']]['finished']=1;
381
+ $this->task['options']['backup_options']['backup'][$backup_data['key']]['result']=$result;
382
+ WPvivid_taskmanager::update_task_options($this->task['id'],'backup_options', $this->task['options']['backup_options']);
383
+
384
+ if($result['result']==WPVIVID_FAILED)
385
+ {
386
+ WPvivid_taskmanager::update_backup_task_status($this->task['id'],false,'error',false,false,$result['error']);
387
+ }
388
+ }
389
+
390
+ $i_finished_backup_count=0;
391
+ $i_count_of_backup=sizeof($this->task['options']['backup_options']['backup']);
392
+
393
+ foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
394
+ {
395
+ if( $backup_data['finished']==1)
396
+ {
397
+ $i_finished_backup_count++;
398
+ }
399
+ }
400
+
401
+ if($i_finished_backup_count>=$i_count_of_backup)
402
+ {
403
+ WPvivid_taskmanager::update_backup_main_task_progress($this->task['id'],'backup',100,1);
404
+ }
405
+ }
406
+
407
+ public function get_backup_result()
408
+ {
409
+ $ret['result']=WPVIVID_SUCCESS;
410
+ foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
411
+ {
412
+ if($backup_data['result']!==false)
413
+ {
414
+ $ret=$backup_data['result'];
415
+ if($ret['result']!==WPVIVID_SUCCESS)
416
+ {
417
+ return $ret;
418
+ }
419
+ }
420
+ }
421
+ return $ret;
422
+ }
423
+
424
+ private function transfer_path($path)
425
+ {
426
  $path = str_replace('\\','/',$path);
427
  $values = explode('/',$path);
428
  return implode(DIRECTORY_SEPARATOR,$values);
429
  }
430
 
431
+ public function get_file_list($root,$exclude_regex,$include_regex,$exclude_file_size)
432
+ {
433
+ $files=array();
434
+ $this->getFileLoop($files,$root,$exclude_regex,$include_regex,$exclude_file_size);
435
+ return $files;
436
+ }
437
+
438
+ public function getFileLoop(&$files,$path,$exclude_regex=array(),$include_regex=array(),$exclude_file_size=array(),$include_dir = true)
439
+ {
440
+ $count = 0;
441
+ if(is_dir($path)) {
442
+ $handler = opendir($path);
443
+ while (($filename = readdir($handler)) !== false) {
444
+ if ($filename != "." && $filename != "..") {
445
+ $count++;
446
+
447
+ if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
448
+ {
449
+ if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)) {
450
+ if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1)) {
451
+ $this->getFileLoop($files, $path . DIRECTORY_SEPARATOR . $filename, $exclude_regex, $include_regex, $include_dir);
452
+ }
453
+ }
454
+ } else {
455
+ if($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)){
456
+ if ($exclude_file_size == 0) {
457
+ $files[] = $path . DIRECTORY_SEPARATOR . $filename;
458
+ } else {
459
+ if (filesize($path . DIRECTORY_SEPARATOR . $filename) < $exclude_file_size * 1024 * 1024) {
460
+ $files[] = $path . DIRECTORY_SEPARATOR . $filename;
461
+ }
462
+ }
463
+ }
464
+ }
465
+ }
466
+ }
467
+ if($handler)
468
+ @closedir($handler);
469
+ }
470
+ if($include_dir && $count == 0){
471
+ $files[] = $path;
472
+ }
473
+ }
474
+
475
+ private function regex_match($regex_array,$string,$mode)
476
+ {
477
+ if(empty($regex_array))
478
+ {
479
+ return true;
480
+ }
481
+
482
+ if($mode==0)
483
+ {
484
+ foreach ($regex_array as $regex)
485
+ {
486
+ if(preg_match($regex,$string))
487
+ {
488
+ return false;
489
+ }
490
+ }
491
+
492
+ return true;
493
+ }
494
+
495
+ if($mode==1)
496
+ {
497
+ foreach ($regex_array as $regex)
498
+ {
499
+ if(preg_match($regex,$string))
500
+ {
501
+ return true;
502
+ }
503
+ }
504
+
505
+ return false;
506
+ }
507
+
508
+ return true;
509
+ }
510
+
511
+ public function get_need_cleanup_files($all=false)
512
+ {
513
+ $files=array();
514
+ if($this->task['options']['backup_options']['ismerge']==1)
515
+ {
516
+ foreach ($this->task['options']['backup_options']['backup'] as $backup_finished_data)
517
+ {
518
+ if($all===false)
519
+ {
520
+ if(WPVIVID_BACKUP_TYPE_MERGE==$backup_finished_data['key'])
521
+ continue;
522
+ }
523
+
524
+ $files=array_merge($files,$this->get_backup_file($backup_finished_data['key']));
525
+ }
526
+ }
527
+ return $files;
528
+ }
529
+
530
+ public function get_prefix()
531
+ {
532
+ return $this->task['options']['backup_options']['prefix'];
533
+ }
534
+
535
+ public function set_file_and_db_info($db_size,$file_size)
536
+ {
537
+ $this->task['data']['backup']['db_size']=$db_size;
538
+ $this->task['data']['backup']['files_size']=$file_size;
539
+
540
+ WPvivid_Setting::update_task($this->task['id'],$this->task);
541
+ }
542
+
543
+ public function get_file_info()
544
+ {
545
+ $file_size['sum_size']=0;
546
+ $file_size['sum_count']=0;
547
+
548
+ $memory_limit = ini_get('memory_limit');
549
+ $ret['memory_limit']=$memory_limit;
550
+ $memory_limit = trim($memory_limit);
551
+ $memory_limit_int = (int) $memory_limit;
552
+ $last = strtolower(substr($memory_limit, -1));
553
+
554
+ if($last == 'g')
555
+ $memory_limit_int = $memory_limit_int*1024*1024*1024;
556
+ if($last == 'm')
557
+ $memory_limit_int = $memory_limit_int*1024*1024;
558
+ if($last == 'k')
559
+ $memory_limit_int = $memory_limit_int*1024;
560
+
561
+ $files=array();
562
+
563
+ $exclude_size= $this->task['options']['backup_options']['compress']['exclude_file_size'];
564
+
565
+ foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
566
+ {
567
+ if(!isset($backup_data['dump_db']))
568
+ {
569
+ $backup_files=$this->get_need_backup_files($backup_data);
570
+ $files=array_merge($backup_files,$files);
571
+ }
572
+ }
573
+
574
+ foreach ($files as $file)
575
+ {
576
+ $size=0;
577
+ $_file_size=filesize($file);
578
+ if($_file_size>($memory_limit_int*0.9))
579
+ {
580
+ $ret['alter_big_file']=true;
581
+ $ret['alter_files']=true;
582
+ }
583
+ $size+=$_file_size;
584
+ $file_size['sum_count']++;
585
+ $file_size['sum_size']+=$size;
586
+ }
587
+ return $file_size;
588
+ }
589
+
590
+ public function is_cancel_file_exist()
591
+ {
592
+ $file_name=$this->task['options']['file_prefix'];
593
+
594
+ $file=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$file_name.'_cancel';
595
+
596
+ if(file_exists($file))
597
+ {
598
+ return true;
599
+ }
600
+ else
601
+ {
602
+ return false;
603
+ }
604
+ }
605
+
606
+ public function update_status($status)
607
+ {
608
+ $this->task['status']['str']=$status;
609
+ WPvivid_Setting::update_task($this->task['id'],$this->task);
610
+ }
611
+
612
+ public function get_backup_task_info($task_id){
613
+ $list_tasks['status']=WPvivid_taskmanager::get_backup_tasks_status($task_id);
614
+ $list_tasks['is_canceled']=WPvivid_taskmanager::is_task_canceled($task_id);
615
+ $list_tasks['size']=WPvivid_taskmanager::get_backup_size($task_id);
616
+ $list_tasks['data']=WPvivid_taskmanager::get_backup_tasks_progress($task_id);
617
+ //
618
+ $list_tasks['task_info']['need_next_schedule']=false;
619
+ if($list_tasks['status']['str']=='running'||$list_tasks['status']['str']=='no_responds')
620
+ {
621
+ if($list_tasks['data']['running_time']>180) {
622
+ $list_tasks['task_info']['need_next_schedule'] = true;
623
+ }
624
+ else{
625
+ $list_tasks['task_info']['need_next_schedule'] = false;
626
+ }
627
+ }
628
+ //
629
+ $general_setting=WPvivid_Setting::get_setting(true, "");
630
+ if($general_setting['options']['wpvivid_common_setting']['estimate_backup'] == 0){
631
+ $list_tasks['task_info']['display_estimate_backup'] = 'display: none';
632
+ }
633
+ else{
634
+ $list_tasks['task_info']['display_estimate_backup'] = '';
635
+ }
636
+ //
637
+ $list_tasks['task_info']['backup_percent']=$list_tasks['data']['progress'].'%';
638
+ //
639
+ if($list_tasks['size']['db_size'] == false){
640
+ $list_tasks['task_info']['db_size']=0;
641
+ }
642
+ else{
643
+ $list_tasks['task_info']['db_size']=$list_tasks['size']['db_size'];
644
+ }
645
+ if($list_tasks['size']['files_size'] == false){
646
+ $list_tasks['task_info']['file_size']=0;
647
+ }
648
+ else{
649
+ $list_tasks['task_info']['file_size']=$list_tasks['size']['files_size']['sum'];
650
+ }
651
+ //
652
+ $list_tasks['task_info']['descript']='';
653
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
654
+ $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
655
+ $list_tasks['task_info']['total'] = 'N/A';
656
+ $list_tasks['task_info']['upload'] = 'N/A';
657
+ $list_tasks['task_info']['speed'] = 'N/A';
658
+ $list_tasks['task_info']['network_connection'] = 'N/A';
659
+
660
+ $list_tasks['task_info']['need_update_last_task']=false;
661
+ if($list_tasks['status']['str']=='ready')
662
+ {
663
+ $list_tasks['task_info']['descript']=__('Ready to backup. Progress: 0%, running time: 0second.','wpvivid');
664
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: none; opacity: 0.4;';
665
+ $list_tasks['task_info']['css_btn_log']='pointer-events: none; opacity: 0.4;';
666
+ }
667
+ else if($list_tasks['status']['str']=='running')
668
+ {
669
+ if($list_tasks['is_canceled'] == false)
670
+ {
671
+ if($list_tasks['data']['type'] == 'upload')
672
+ {
673
+ $descript=$list_tasks['data']['upload_data']['descript'];
674
+ $offset=$list_tasks['data']['upload_data']['offset'];
675
+ $current_size=$list_tasks['data']['upload_data']['current_size'];
676
+ $last_time=$list_tasks['data']['upload_data']['last_time'];
677
+ $last_size=$list_tasks['data']['upload_data']['last_size'];
678
+ $speed =( $offset - $last_size ) / (time() - $last_time);
679
+ $speed /= 1000;
680
+ $speed=round($speed,2);
681
+ $speed.='kb/s';
682
+
683
+ if(!empty($current_size)) {
684
+ $list_tasks['task_info']['total'] = size_format($current_size,2);
685
+ }
686
+ if(!empty($offset)) {
687
+ $list_tasks['task_info']['upload'] = size_format($offset, 2);
688
+ }
689
+ $list_tasks['task_info']['speed'] = $speed;
690
+ $list_tasks['task_info']['descript'] = $descript.__(' Progress: ', 'wpvivid') . $list_tasks['task_info']['backup_percent'] . __(', running time: ', 'wpvivid') . $list_tasks['data']['running_time'];
691
+
692
+ $time_spend=time()-$list_tasks['status']['run_time'];
693
+ if($time_spend>30)
694
+ {
695
+ $list_tasks['task_info']['network_connection']='Retrying';
696
+ }
697
+ else
698
+ {
699
+ $list_tasks['task_info']['network_connection']='OK';
700
+ }
701
+ }
702
+ else {
703
+ $list_tasks['task_info']['descript'] = $list_tasks['data']['descript'] . __(' Progress: ', 'wpvivid') . $list_tasks['task_info']['backup_percent'] . __(', running time: ', 'wpvivid') . $list_tasks['data']['running_time'];
704
+ }
705
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
706
+ $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
707
+ }
708
+ else{
709
+ $list_tasks['task_info']['descript']=__('The backup will be canceled after backing up the current chunk ends.','wpvivid');
710
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: none; opacity: 0.4;';
711
+ $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
712
+ }
713
+ }
714
+ else if($list_tasks['status']['str']=='wait_resume'){
715
+ $list_tasks['task_info']['descript']='Task '.$task_id.' timed out, backup task will retry in '.$list_tasks['data']['next_resume_time'].' seconds, retry times: '.$list_tasks['status']['resume_count'].'.';
716
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
717
+ $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
718
+ }
719
+ else if($list_tasks['status']['str']=='no_responds'){
720
+ if($list_tasks['is_canceled'] == false){
721
+ $list_tasks['task_info']['descript']='Task , '.$list_tasks['data']['doing'].' is not responding. Progress: '.$list_tasks['task_info']['backup_percent'].', running time: '.$list_tasks['data']['running_time'];
722
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
723
+ $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
724
+ }
725
+ else{
726
+ $list_tasks['task_info']['descript']=__('The backup will be canceled after backing up the current chunk ends.','wpvivid');
727
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: none; opacity: 0.4;';
728
+ $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
729
+ }
730
+ }
731
+ else if($list_tasks['status']['str']=='completed'){
732
+ $list_tasks['task_info']['descript']='Task '.$task_id.' completed.';
733
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
734
+ $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
735
+ $list_tasks['task_info']['need_update_last_task']=true;
736
+ }
737
+ else if($list_tasks['status']['str']=='error'){
738
+ $list_tasks['task_info']['descript']='Backup error: '.$list_tasks['status']['error'];
739
+ $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
740
+ $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
741
+ $list_tasks['task_info']['need_update_last_task']=true;
742
+ }
743
+
744
+ return $list_tasks;
745
+ }
746
+ }
747
+
748
+ class WPvivid_Backup_Item
749
+ {
750
+ private $config;
751
+
752
+ public function __construct($options)
753
+ {
754
+ $this->config=$options;
755
+ }
756
+
757
+ public function get_backup_type()
758
+ {
759
+ return $this->config['type'];
760
+ }
761
+
762
+ public function get_files($has_dir=true)
763
+ {
764
+ $files=array();
765
+ if(isset($this->config['backup']['files']))
766
+ {
767
+ //file_name
768
+ foreach ($this->config['backup']['files'] as $file)
769
+ {
770
+ if($has_dir)
771
+ $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
772
+ else
773
+ $files[]=$file['file_name'];
774
+ }
775
+ }
776
+ else{
777
+ if(isset($this->config['backup']['data']['meta']['files']))
778
+ {
779
+ foreach ($this->config['backup']['data']['meta']['files'] as $file)
780
+ {
781
+ if($has_dir)
782
+ $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
783
+ else
784
+ $files[]=$file['file_name'];
785
+ }
786
+ }
787
+ }
788
+ return $files;
789
+ }
790
+
791
+ public function is_lock()
792
+ {
793
+ if(isset($this->config['lock']))
794
+ {
795
+ return $this->config['lock'];
796
+ }
797
+ else{
798
+ return false;
799
+ }
800
+ }
801
+
802
+ public function check_backup_files()
803
+ {
804
+ $ret['result']=WPVIVID_FAILED;
805
+
806
+ $b_has_data=false;
807
+ $tmp_data=array();
808
+ if(isset($this->config['backup']['files']))
809
+ {
810
+ $b_has_data = true;
811
+ $tmp_data = $this->config['backup']['files'];
812
+ }
813
+ else if(isset($this->config['backup']['data']['meta']['files'])){
814
+ $b_has_data = true;
815
+ $tmp_data = $this->config['backup']['data']['meta']['files'];
816
+ }
817
+
818
+ if($b_has_data){
819
+ $b_need_download=false;
820
+ $b_not_found=false;
821
+
822
+ foreach ($tmp_data as $file)
823
+ {
824
+ $need_download=false;
825
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
826
+ if(file_exists($path))
827
+ {
828
+ $new_md5=md5_file($path);
829
+ if($file['md5']!=$new_md5)
830
+ {
831
+ $need_download=true;
832
+ //@unlink($path);
833
+ }
834
+ }
835
+ else
836
+ {
837
+ $need_download=true;
838
+ }
839
+
840
+ if($need_download)
841
+ {
842
+ if(empty($this->config['remote']))
843
+ {
844
+ $b_not_found=true;
845
+ $ret['files'][$file['file_name']]['status']='file_not_found';
846
+ $ret['files'][$file['file_name']]['size']=$file['size'];
847
+ $ret['files'][$file['file_name']]['md5']=$file['md5'];
848
+ }
849
+ else
850
+ {
851
+ $b_need_download=true;
852
+ WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
853
+ $ret['files'][$file['file_name']]['status']='need_download';
854
+ $ret['files'][$file['file_name']]['size']=$file['size'];
855
+ $ret['files'][$file['file_name']]['md5']=$file['md5'];
856
+ }
857
+ }
858
+ }
859
+
860
+ if($b_not_found)
861
+ {
862
+ $ret['result']=WPVIVID_FAILED;
863
+ $ret['error']='Backup doesn\'t exist in both web server and remote storage. Restore failed.';
864
+ }
865
+ else if($b_need_download)
866
+ {
867
+ $ret['result']='need_download';
868
+ }
869
+ else
870
+ {
871
+ $ret['result']=WPVIVID_SUCCESS;
872
+ }
873
+ }
874
+
875
+ return $ret;
876
+ }
877
+
878
+ public function get_file_md5($file_name)
879
+ {
880
+ $zip=new WPvivid_ZipClass();
881
+ $json=$zip->get_json_data($file_name);
882
+
883
+ if(!$json)
884
+ {
885
+ return '';
886
+ }
887
+ else
888
+ {
889
+
890
+ $data=json_decode($json,1);
891
+ if(!is_null($data))
892
+ {
893
+ if(isset($data['md5']))
894
+ return $data['md5'];
895
+ else
896
+ return '';
897
+ }
898
+ else
899
+ {
900
+ return '';
901
+ }
902
+ }
903
+ }
904
+
905
+ public function get_local_path()
906
+ {
907
+ return $this->config['local']['path'];
908
+ }
909
+
910
+ public function get_remote()
911
+ {
912
+ $remote_option=array_shift($this->config['remote']);
913
+
914
+ if(is_null($remote_option))
915
+ {
916
+ return false;
917
+ }
918
+ else
919
+ {
920
+ return $remote_option;
921
+ }
922
+ }
923
+
924
+ public function get_backup_packages()
925
+ {
926
+ $packages=array();
927
+ $index=0;
928
+
929
+ if(isset($this->config['backup']['files']))
930
+ {
931
+ $file_added=array();
932
+ //file_name
933
+ foreach ($this->config['backup']['files'] as $file)
934
+ {
935
+ if(isset($file_added[$file['file_name']]))
936
+ {
937
+ continue;
938
+ }
939
+
940
+ if(strpos($file['file_name'],'part')!==false)
941
+ {
942
+ $this->get_all_part_files($file['file_name'],$this->config['backup']['files'],$packages[$index],$file_added);
943
+ }
944
+ else
945
+ {
946
+ $packages[$index]['files'][]=$file['file_name'];
947
+ $file_added[$file['file_name']]=1;
948
+ }
949
+ $index++;
950
+ }
951
+
952
+ $file_added=array();
953
+ $child_packages=array();
954
+ foreach ($packages as $package)
955
+ {
956
+ $files=array();
957
+
958
+ foreach ($package['files'] as $package_files)
959
+ {
960
+ $files=array_merge($files,$this->get_child_files($package_files));
961
+ }
962
+
963
+ if(empty($files))
964
+ {
965
+ continue;
966
+ }
967
+
968
+ foreach ($files as $file)
969
+ {
970
+ if(isset($file_added[$file['file_name']]))
971
+ {
972
+ continue;
973
+ }
974
+
975
+ if(strpos($file['file_name'],'part')!==false)
976
+ {
977
+ $this->get_all_part_files($file['file_name'],$files,$child_packages[$index],$file_added);
978
+ }
979
+ else
980
+ {
981
+ $child_packages[$index]['files'][]=$file['file_name'];
982
+ $file_added[$file['file_name']]=1;
983
+ }
984
+ $index++;
985
+ }
986
+ }
987
+
988
+ $packages=array_merge($packages,$child_packages);
989
+ }
990
+ else if(isset($this->config['backup']['data']))
991
+ {
992
+ if(isset($this->config['backup']['ismerge'])&&$this->config['backup']['ismerge']==1)
993
+ {
994
+ $packages[$index]['option']['has_child']=1;
995
+ $packages[$index]['option']['root']='wp-content';
996
+ foreach ($this->config['backup']['data']['meta']['files'] as $file)
997
+ {
998
+ $packages[$index]['files'][]=$file['file_name'];
999
+ }
1000
+ $index++;
1001
+ }
1002
+
1003
+ foreach ($this->config['backup']['data']['type'] as $type)
1004
+ {
1005
+ if($type['type_name']=='backup_db')
1006
+ {
1007
+ $packages[$index]['option']['dump_db']=1;
1008
+ $packages[$index]['option']['root']='wp-content\\'.$this->config['local']['path'];
1009
+ }
1010
+ else if($type['type_name']=='backup_themes')
1011
+ {
1012
+ $packages[$index]['option']['root']='wp-content';
1013
+ }
1014
+ else if($type['type_name']=='backup_plugin')
1015
+ {
1016
+ $packages[$index]['option']['root']='wp-content';
1017
+ }
1018
+ else if($type['type_name']=='backup_uploads')
1019
+ {
1020
+ $packages[$index]['option']['root']='wp-content';
1021
+ }
1022
+ else if($type['type_name']=='backup_content')
1023
+ {
1024
+ $packages[$index]['option']['root']='';
1025
+ }
1026
+ else if($type['type_name']=='backup_core')
1027
+ {
1028
+ $packages[$index]['option']['root']='';
1029
+ $packages[$index]['option']['include_path'][]='wp-includes';
1030
+ $packages[$index]['option']['include_path'][]='wp-admin';
1031
+ }
1032
+
1033
+ foreach ($type['files'] as $file)
1034
+ {
1035
+ $packages[$index]['files'][]=$file['file_name'];
1036
+ }
1037
+ $index++;
1038
+ }
1039
+ }
1040
+
1041
+ return $packages;
1042
+ }
1043
+
1044
+ public function get_all_part_files($file_name,$files,&$package,&$file_added)
1045
+ {
1046
+ $i=strpos($file_name,'part');
1047
+
1048
+ $file_prefix=substr($file_name,0,$i);
1049
+
1050
+ foreach ($files as $file)
1051
+ {
1052
+ if(isset($file_added[$file['file_name']]))
1053
+ {
1054
+ continue;
1055
+ }
1056
+
1057
+ if (strpos($file['file_name'], $file_prefix) !== false)
1058
+ {
1059
+ $package['files'][]=$file['file_name'];
1060
+ $file_added[$file['file_name']]=1;
1061
+ }
1062
+ }
1063
+ }
1064
+
1065
+ public function get_child_files($file_name)
1066
+ {
1067
+ $zip=new WPvivid_ZipClass();
1068
+
1069
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file_name;
1070
+
1071
+ $json=$zip->get_json_data($path);
1072
+
1073
+ $json=json_decode($json,1);
1074
+
1075
+ $files=array();
1076
+
1077
+ if(isset($json['has_child']))
1078
+ {
1079
+ $files=$zip->list_file($path);
1080
+ }
1081
+
1082
+ return $files;
1083
+ }
1084
+
1085
+ public function get_file_info($file_name)
1086
+ {
1087
+ $zip=new WPvivid_ZipClass();
1088
+
1089
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file_name;
1090
+
1091
+ $json=$zip->get_json_data($path);
1092
+
1093
+ $json=json_decode($json,1);
1094
+ if(is_null($json))
1095
+ {
1096
+ return false;
1097
+ }
1098
+ else
1099
+ {
1100
+ return $json;
1101
+ }
1102
+ }
1103
+
1104
+ static public function get_backup_file_info($file_name)
1105
  {
1106
+ $zip=new WPvivid_ZipClass();
1107
+ $json=$zip->get_json_data($file_name);
 
 
 
 
 
 
 
 
1108
 
1109
+ $json=json_decode($json,1);
1110
+ if(is_null($json))
 
 
 
 
 
 
 
 
1111
  {
1112
+ return false;
1113
  }
1114
  else
1115
  {
1116
+ return $json;
1117
  }
1118
+ }
1119
 
1120
+ public function get_sql_file($file_name)
1121
+ {
1122
+ $zip=new WPvivid_ZipClass();
1123
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file_name;
1124
+ $files=$zip->list_file($path);
1125
+ return $files[0]['file_name'];
1126
+ }
1127
 
1128
+ public function get_download_backup_files($backup_id){
1129
+ $ret['result']=WPVIVID_FAILED;
1130
+ $data=array();
1131
+ $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
1132
+ if(!$backup)
1133
+ {
1134
+ return $ret;
1135
+ }
1136
+ $b_data_type_true=false;
1137
+ $files=array();
1138
+ if(isset($backup['backup']['files'])){
1139
+ $b_data_type_true=true;
1140
+ $files=$backup['backup']['files'];
1141
+ }
1142
+ else{
1143
+ if(isset($backup['backup']['ismerge'])) {
1144
+ if ($backup['backup']['ismerge'] == 1) {
1145
+ if(isset($backup['backup']['data']['meta']['files'])){
1146
+ $b_data_type_true=true;
1147
+ $files=$backup['backup']['data']['meta']['files'];
1148
+ }
1149
+ }
1150
  }
1151
+ }
1152
+ if($b_data_type_true){
1153
+ global $wpvivid_pulgin;
1154
+ $b_need_download=false;
1155
+ $b_not_found=false;
1156
+ $file_count=0;
1157
+ $file_part_num=1;
1158
+ $check_type='';
1159
+ foreach ($files as $file)
1160
  {
1161
+ $need_download=false;
1162
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1163
+ if(file_exists($path)) {
1164
+ $new_md5=md5_file($path);
1165
+ if($file['md5']!=$new_md5) {
1166
+ $need_download=true;
1167
+ }
1168
+ }
1169
+ else {
1170
+ $need_download=true;
1171
+ }
1172
+ if($file_part_num < 10){
1173
+ $format_part=sprintf("%02d", $file_part_num);
1174
+ }
1175
+ else{
1176
+ $format_part=$file_part_num;
1177
+ }
1178
+ if($need_download) {
1179
+ if(empty($backup['remote'])) {
1180
+ $b_not_found=true;
1181
+ $ret['result'] = WPVIVID_SUCCESS;
1182
+ $ret['files'][$file['file_name']]['status']='file_not_found';
1183
+ }
1184
+ else{
1185
+ $task = WPvivid_taskmanager::get_download_task_v2($file['file_name']);
1186
+ if ($task === false) {
1187
+ $ret['result'] = WPVIVID_SUCCESS;
1188
+ $ret['files'][$file['file_name']]['status']='need_download';
1189
+ $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:290px;">
1190
+ <span>Part'.$format_part.'</span></br>
1191
+ <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a onclick="wpvivid_prepare_download(\''.$file_part_num.'\', \''.$backup_id.'\', \''.$file['file_name'].'\');" style="cursor: pointer;">Prepare to Download</a></span></br>
1192
+ <div style="width:100%;height:5px; background-color:#dcdcdc;"><div id=\''.$backup_id.'-progress-part-'.$file_part_num.'\' style="background-color:#0085ba; float:left;width:0;height:5px;"></div></div>
1193
+ <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1194
+ </div>';
1195
+ } else {
1196
+ $ret['result'] = WPVIVID_SUCCESS;
1197
+ if($task['status'] === 'running'){
1198
+ $ret['files'][$file['file_name']]['status'] = 'running';
1199
+ $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:290px;">
1200
+ <span>Part'.$format_part.'</span></br>
1201
+ <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a >Retriving(remote storage to web server)</a></span></br>
1202
+ <div style="width:100%;height:5px; background-color:#dcdcdc;"><div id=\''.$backup_id.'-progress-part-'.$file_part_num.'\' style="background-color:#0085ba; float:left;width:'.$task['progress_text'].'%;height:5px;"></div></div>
1203
+ <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1204
+ </div>';
1205
+ $ret['files'][$file['file_name']]['progress_text']=$task['progress_text'];
1206
+ }
1207
+ elseif($task['status'] === 'timeout'){
1208
+ $ret['files'][$file['file_name']]['status']='timeout';
1209
+ $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:290px;">
1210
+ <span>Part'.$format_part.'</span></br>
1211
+ <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a onclick="wpvivid_prepare_download(\''.$file_part_num.'\', \''.$backup_id.'\', \''.$file['file_name'].'\');" style="cursor: pointer;">Prepare to Download</a></span></br>
1212
+ <div style="width:100%;height:5px; background-color:#dcdcdc;"><div id=\''.$backup_id.'-progress-part-'.$file_part_num.'\' style="background-color:#0085ba; float:left;width:'.$task['progress_text'].'%;height:5px;"></div></div>
1213
+ <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1214
+ </div>';
1215
+ $ret['files'][$file['file_name']]['progress_text']=$task['progress_text'];
1216
+ }
1217
+ elseif($task['status'] === 'completed'){
1218
+ $ret['files'][$file['file_name']]['status']='completed';
1219
+ $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:290px;">
1220
+ <span>Part'.$format_part.'</span></br>
1221
+ <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a onclick="wpvivid_download(\''.$backup_id.'\', \''.$check_type.'\', \''.$file['file_name'].'\');" style="cursor: pointer;">Download</a></span></br>
1222
+ <div style="width:100%;height:5px; background-color:#dcdcdc;"><div id=\''.$backup_id.'-progress-part-'.$file_part_num.'\' style="background-color:#0085ba; float:left;width:100%;height:5px;"></div></div>
1223
+ <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1224
+ </div>';
1225
+ WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1226
+ }
1227
+ elseif($task['status'] === 'error'){
1228
+ $ret['files'][$file['file_name']]['status']='error';
1229
+ $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:290px;">
1230
+ <span>Part'.$format_part.'</span></br>
1231
+ <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a onclick="wpvivid_prepare_download(\''.$file_part_num.'\', \''.$backup_id.'\', \''.$file['file_name'].'\');" style="cursor: pointer;">Prepare to Download</a></span></br>
1232
+ <div style="width:100%;height:5px; background-color:#dcdcdc;"><div id=\''.$backup_id.'-progress-part-'.$file_part_num.'\' style="background-color:#0085ba; float:left;width:0;height:5px;"></div></div>
1233
+ <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1234
+ </div>';
1235
+ $ret['files'][$file['file_name']]['error'] = $task['error'];
1236
+ WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1237
+ }
1238
+ }
1239
+ }
1240
+ }
1241
+ else{
1242
+ $ret['result'] = WPVIVID_SUCCESS;
1243
+ if(WPvivid_taskmanager::get_download_task_v2($file['file_name']))
1244
+ WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1245
+ $ret['files'][$file['file_name']]['status']='completed';
1246
+ $ret['files'][$file['file_name']]['download_path']=$path;
1247
+ $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:290px;">
1248
+ <span>Part'.$format_part.'</span></br>
1249
+ <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a onclick="wpvivid_download(\''.$backup_id.'\', \''.$check_type.'\', \''.$file['file_name'].'\');" style="cursor: pointer;">Download</a></span></br>
1250
+ <div style="width:100%;height:5px; background-color:#dcdcdc;"><div id=\''.$backup_id.'-progress-part-'.$file_part_num.'\' style="background-color:#0085ba; float:left;width:100%;height:5px;"></div></div>
1251
+ <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1252
+ </div>';
1253
+ }
1254
+ $ret['files'][$file['file_name']]['size']=$wpvivid_pulgin->formatBytes($file['size']);
1255
+ $file_count++;
1256
+ $file_part_num++;
1257
  }
1258
+ if ($file_count % 2 != 0) {
1259
+ $file_count++;
1260
+ if($file_count < 10){
1261
+ $format_part=sprintf("%02d", $file_count);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1262
  }
1263
+ else{
1264
+ $format_part=$file_count;
 
 
 
 
 
1265
  }
1266
+ $ret['place_html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:290px; color:#cccccc;">
1267
+ <span>Part'.$format_part.'</span></br>
1268
+ <span>Download</span></br>
1269
+ <div style="width:100%;height:5px; background-color:#dcdcdc;"><div style="background-color:#0085ba; float:left;width:0;height:5px;"></div></div>
1270
+ <span>size:</span><span>0</span>
1271
+ </div>';
1272
+ }
1273
+ else{
1274
+ $ret['place_html']='';
1275
  }
1276
+ return $ret;
1277
+ }
1278
+ return false;
1279
+ }
 
 
 
1280
 
1281
+ public function update_download_page($backup_id){
1282
+ global $wpvivid_pulgin;
1283
+ $cache=WPvivid_taskmanager::get_download_cache($backup_id);
1284
+ if($cache===false)
1285
  {
1286
+ return $wpvivid_pulgin->init_download($backup_id);
1287
  }
1288
  else
1289
  {
1290
+ $ret=$cache;
1291
+ $ret=$this->get_download_backup_files($backup_id);
1292
+ WPvivid_taskmanager::update_download_cache($backup_id,$ret);
1293
+ return $ret;
1294
  }
1295
+ }
1296
+ }
1297
 
1298
+ class WPvivid_Backup
1299
+ {
1300
+ public $task;
1301
+ //public $config;
1302
 
1303
+ public function __construct($task_id=false,$task=false)
1304
  {
1305
+ if($task_id!==false)
1306
+ {
1307
+ $this->task=new WPvivid_Backup_Task($task_id);
1308
+ }
1309
+ else if($task!==false)
1310
+ {
1311
+ $this->task=new WPvivid_Backup_Task(false,$task);
1312
+ }
1313
+ else
1314
+ {
1315
+ $this->task=new WPvivid_Backup_Task();
1316
+ }
1317
+ //$this->config=$config;
1318
+ }
1319
 
1320
+ public function init_options($task_id)
1321
+ {
1322
+ $this->task=new WPvivid_Backup_Task($task_id);
1323
  }
1324
 
1325
+ public function backup($task_id)
1326
  {
1327
+ $this->init_options($task_id);
1328
+ $next_backup=$this->task->get_need_backup();
1329
+
1330
+ while($next_backup!==false)
1331
+ {
1332
+ global $wpvivid_pulgin;
1333
+ $wpvivid_pulgin->set_time_limit($this->task->get_id());
1334
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'backup', $next_backup['key'],0,'Start backing up '.$next_backup['key'].'.');
1335
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to backup '.$next_backup['key'].' files.','notice');
1336
+ if(isset($next_backup['files'])) {
1337
+ $wpvivid_pulgin->wpvivid_log->WriteLog('File number: ' . sizeof($next_backup['files']), 'notice');
1338
+ }
1339
+ $result = $this->_backup($next_backup);
1340
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Backing up '.$next_backup['key'].' completed.','notice');
1341
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'backup', $next_backup['key'],1,'Backing up '.$next_backup['key'].' finished.',$result);
1342
+ $this->task->update_backup_result($next_backup,$result);
1343
+ $next_backup=$this->task->get_need_backup();
1344
+ }
1345
 
1346
+ $this->cleanup();
 
1347
 
1348
+ $ret=$this->task->get_backup_result();
1349
+ return $ret;
1350
+ }
1351
 
1352
+ private function _backup($data)
1353
+ {
1354
+ global $wpvivid_pulgin;
1355
+ $result['result']=WPVIVID_FAILED;
1356
+ $result['error']='test error';
1357
+ if(isset($data['dump_db']))
1358
  {
1359
+ include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-backup-database.php';
1360
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Start exporting database.','notice');
1361
+ $backup_database = new WPvivid_Backup_Database();
1362
+ $result = $backup_database -> backup_database($data,$this->task->get_id());
1363
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Exporting database finished.','notice');
1364
  if($result['result']==WPVIVID_SUCCESS)
1365
  {
1366
+ $data['files']=$result['files'];
1367
+ }
1368
+ else
1369
+ {
1370
+ return $result;
 
 
 
 
1371
  }
1372
  }
1373
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-zipclass.php';
1374
+
1375
+ $zip = new WPvivid_ZipClass();
1376
+ if(is_array($zip->last_error))
1377
  {
1378
+ return $zip->last_error;
 
 
 
 
 
1379
  }
1380
+
1381
+ $result =$zip->compress($data);
1382
+
1383
+ if(isset($data['dump_db']))
1384
  {
1385
+ foreach ($data['files'] as $sql_file)
1386
+ {
1387
+ @unlink($sql_file);
1388
+ }
 
1389
  }
1390
+
1391
+ return $result;
1392
  }
1393
 
1394
+ public function cleanup()
1395
  {
1396
+ $files=$this->task->get_need_cleanup_files();
1397
+
1398
+ foreach ($files as $file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1399
  {
1400
+ if(file_exists($file)) {
1401
+ global $wpvivid_pulgin;
1402
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Cleaned up file, filename: '.$file,'notice');
1403
+ @unlink($file);
1404
  }
1405
  }
 
1406
  }
1407
 
1408
+ public function clean_backup()
1409
  {
1410
+ $files=$this->task->get_need_cleanup_files(true);
1411
+ foreach ($files as $file)
 
 
 
 
 
1412
  {
1413
+ if(file_exists($file))
1414
+ @unlink($file);
1415
  }
1416
+ WPvivid_tools::clearcache($this->task->get_prefix());
1417
+ }
1418
 
1419
+ public function get_default_exclude_regex($type_name = '')
1420
+ {
1421
+ $options = WPvivid_Setting::get_option('wpvivid_common_setting');
1422
+ if(!isset($options['log_save_location']))
 
 
 
1423
  {
1424
+ WPvivid_Setting::set_default_common_option();
1425
+ $options = WPvivid_Setting::get_option('wpvivid_common_setting');
 
1426
  }
1427
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'updraft', '/').'#'; // Updraft Plus backup directory
1428
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_UPLOADS).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
1429
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_UPLOADS).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
1430
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'ai1wm-backups', '/').'#'; // All-in-one WP migration backup directory
1431
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'backups', '/').'#'; // Xcloner backup directory
1432
+
1433
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'upgrade', '/').'#';
1434
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.'wpvivid', '/').'#';
1435
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(), '/').'#';
1436
+ $regex['directory'][]='#^'.preg_quote(WPVIVID_PLUGIN_DIR, '/').'#';
1437
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT).DIRECTORY_SEPARATOR.$options['log_save_location'], '/').'#';
1438
+ switch ($type_name)
1439
  {
1440
+ case WPVIVID_BACKUP_TYPE_CONTENT:
1441
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_PLUGIN), '/').'#';
1442
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_THEMES), '/').'#';
1443
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_UPLOADS), '/').'#';
1444
+ break;
1445
+ case WPVIVID_BACKUP_TYPE_CORE:
1446
+ $abs_path = $this ->get_default_directory(WPVIVID_BACKUP_TYPE_CORE).DIRECTORY_SEPARATOR;
1447
+ $regex['directory'][]='#^'.preg_quote($this->get_default_directory(WPVIVID_BACKUP_TYPE_CONTENT), '/').'#';
1448
+ $regex['directory'][]='#^'.preg_quote($abs_path.'wp-snapshots', '/').'#'; // Duplicator backup directory
1449
+ $regex['file'][]='#^'.preg_quote($abs_path.'.maintenance', '/').'#';
1450
+ break;
1451
  }
1452
+ return $regex;
1453
  }
1454
 
1455
+ public function get_default_directory($type_name = ''){
1456
+ $upload_dir = wp_upload_dir();
1457
+ $paths = array(
1458
+ WPVIVID_BACKUP_TYPE_CORE => $this -> transfer_path(dirname(WP_CONTENT_DIR)),
1459
+ WPVIVID_BACKUP_TYPE_CONTENT => $this -> transfer_path(WP_CONTENT_DIR),
1460
+ WPVIVID_BACKUP_TYPE_PLUGIN => $this -> transfer_path(WP_PLUGIN_DIR),
1461
+ WPVIVID_BACKUP_TYPE_THEMES => $this -> transfer_path(get_theme_root()),
1462
+ WPVIVID_BACKUP_TYPE_UPLOADS => $this -> transfer_path($upload_dir['basedir']),
1463
+ );
1464
 
1465
+ if(empty($type_name) || empty($paths[$type_name])){
1466
+ return '';
1467
+ }else{
1468
+ return $paths[$type_name];
1469
+ }
1470
+ }
1471
+ private function transfer_path($path){
1472
+ $path = str_replace('\\','/',$path);
1473
+ $values = explode('/',$path);
1474
+ return implode(DIRECTORY_SEPARATOR,$values);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1475
  }
1476
 
1477
  public function getFile($path ,$exclude_regex,$include_regex,$exclude_file_size,$log)
1518
  }
1519
  }
1520
 
 
1521
  private function regex_match($regex_array,$string,$mode)
1522
  {
1523
  if(empty($regex_array))
1554
  return true;
1555
  }
1556
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1557
  public function clean_remote_backup($remotes,$files)
1558
  {
1559
  $remote_option=array_shift($remotes);
1603
 
1604
  return $files;
1605
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1606
  }
includes/class-wpvivid-backuplist.php CHANGED
@@ -14,6 +14,15 @@ class WPvivid_Backuplist
14
  return $list;
15
  }
16
 
 
 
 
 
 
 
 
 
 
17
  public static function get_backuplist_by_key($key)
18
  {
19
  $list = self::get_backuplist();
@@ -24,6 +33,14 @@ class WPvivid_Backuplist
24
  return $backup;
25
  }
26
  }
 
 
 
 
 
 
 
 
27
  return false;
28
  }
29
 
@@ -56,6 +73,25 @@ class WPvivid_Backuplist
56
  }
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  public static function update_backup($id,$key,$data)
60
  {
61
  $list = WPvivid_Setting::get_option('wpvivid_backup_list');
@@ -81,8 +117,23 @@ class WPvivid_Backuplist
81
  public static function delete_backup($key)
82
  {
83
  $list = self::get_backuplist();
84
- unset($list[$key]);
85
- WPvivid_Setting::update_option('wpvivid_backup_list',$list);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
87
 
88
  public static function sort_list($list)
@@ -258,13 +309,20 @@ class WPvivid_Backuplist
258
  $size=0;
259
  $list = WPvivid_Setting::get_option('wpvivid_backup_list');
260
  $backup=$list[$backup_id];
261
- foreach ($backup['backup']['data']['type'] as $type)
262
- {
263
- foreach ($type['files'] as $file)
264
- {
265
  $size+=$file['size'];
266
  }
267
  }
 
 
 
 
 
 
 
 
 
268
 
269
  return $size;
270
  }
14
  return $list;
15
  }
16
 
17
+ public static function get_transferlist()
18
+ {
19
+ $list = WPvivid_Setting::get_option('wpvivid_transfer_list');
20
+
21
+ $list =self::sort_list($list);
22
+
23
+ return $list;
24
+ }
25
+
26
  public static function get_backuplist_by_key($key)
27
  {
28
  $list = self::get_backuplist();
33
  return $backup;
34
  }
35
  }
36
+ $list = self::get_transferlist();
37
+ foreach ($list as $k=>$backup)
38
+ {
39
+ if($key == $k)
40
+ {
41
+ return $backup;
42
+ }
43
+ }
44
  return false;
45
  }
46
 
73
  }
74
  }
75
 
76
+ public static function add_new_upload_backup($task_id,$backup,$log='')
77
+ {
78
+ $backup_data=array();
79
+ $backup_data['type']='Upload';
80
+ $backup_data['create_time']=time();
81
+ $backup_data['manual_delete']=0;
82
+ $backup_data['local']['path']=WPvivid_Setting::get_backupdir();
83
+ $backup_data['compress']['compress_type']='zip';
84
+ $backup_data['save_local']=1;
85
+ $backup_data['log']=$log;
86
+
87
+ $backup_data['backup']=$backup;
88
+ $backup_data['remote']=array();
89
+ $backup_data['lock']=0;
90
+ $list = WPvivid_Setting::get_option('wpvivid_backup_list');
91
+ $list[$task_id]=$backup_data;
92
+ WPvivid_Setting::update_option('wpvivid_backup_list',$list);
93
+ }
94
+
95
  public static function update_backup($id,$key,$data)
96
  {
97
  $list = WPvivid_Setting::get_option('wpvivid_backup_list');
117
  public static function delete_backup($key)
118
  {
119
  $list = self::get_backuplist();
120
+ foreach ($list as $k=>$backup)
121
+ {
122
+ if ($key == $k)
123
+ {
124
+ unset($list[$key]);
125
+ WPvivid_Setting::update_option('wpvivid_backup_list',$list);
126
+ }
127
+ }
128
+ $list = self::get_transferlist();
129
+ foreach ($list as $k=>$backup)
130
+ {
131
+ if($key == $k)
132
+ {
133
+ unset($list[$key]);
134
+ WPvivid_Setting::update_option('wpvivid_transfer_list',$list);
135
+ }
136
+ }
137
  }
138
 
139
  public static function sort_list($list)
309
  $size=0;
310
  $list = WPvivid_Setting::get_option('wpvivid_backup_list');
311
  $backup=$list[$backup_id];
312
+ if(isset($backup['backup']['files'])){
313
+ foreach ($backup['backup']['files'] as $file) {
 
 
314
  $size+=$file['size'];
315
  }
316
  }
317
+ else{
318
+ if(isset($backup['backup']['data']['type'])){
319
+ foreach ($backup['backup']['data']['type'] as $type) {
320
+ foreach ($type['files'] as $file) {
321
+ $size+=$file['size'];
322
+ }
323
+ }
324
+ }
325
+ }
326
 
327
  return $size;
328
  }
includes/class-wpvivid-backuptoremote.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPVIVID_PLUGIN_DIR')){
4
+ die;
5
+ }
6
+ require_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-tools.php';
7
+ require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-ftpclass.php';
8
+ require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-sftpclass.php';
9
+ require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-amazons3-plus.php';
10
+ class WPvivid_Backup_Remote
11
+ {
12
+
13
+ public function backup_with_ftp($data = array())
14
+ {
15
+ $host = $data['options']['host'];
16
+ $username = $data['options']['username'];
17
+ $password = $data['options']['password'];
18
+ $path = $data['options']['path'];
19
+ $passive = $data['options']['passive'];
20
+ $port = empty($data['options']['port'])?21:$data['options']['port'];
21
+
22
+ $ftpclass = new WPvivid_FTPClass();
23
+ $res = $ftpclass -> upload($host,$username,$password,$path,$data['files'],$data['task_id'],$passive,$port,$data['log']);
24
+ return $res;
25
+ }
26
+
27
+ public function backup_with_sftp($data)
28
+ {
29
+ if(empty($data['port']))
30
+ $data['options']['port'] = 22;
31
+ $host = $data['options']['host'];
32
+ $username = $data['options']['username'];
33
+ $password = $data['options']['password'];
34
+ $path = $data['options']['path'];
35
+ $port = $data['options']['port'];
36
+ $scp = $data['options']['scp'];
37
+
38
+ $sftpclass = new WPvivid_SFTPClass();
39
+ $result = $sftpclass -> upload($host,$username,$password,$path,$data['files'],$data['task_id'],$port,$scp,$data['log']);
40
+ return $result;
41
+ }
42
+
43
+ public function backup_with_amazonS3($data = array())
44
+ {
45
+ $files = $data['files'];
46
+ $access = $data['options']['access'];
47
+ $secret = $data['options']['secret'];
48
+ $s3Path = $data['options']['s3Path'];
49
+ $region = $data['options']['region'];
50
+ $amazonS3 = new WPvivid_AMAZONS3Class();
51
+ $amazonS3 ->init($access,$secret,$region);
52
+ $res = $amazonS3 -> upload($files,$s3Path,$data['task_id'],$data['log']);
53
+ return $res;
54
+ }
55
+ }
includes/class-wpvivid-compress-default.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ abstract class Wpvivid_Compress_Default{
3
+ public $last_error = '';
4
+
5
+ abstract public function compress($data);
6
+ abstract public function extract($files,$path = '');
7
+ abstract public function extract_by_files($files,$zip,$path = '');
8
+ abstract public function get_include_zip($files,$allpackages);
9
+ abstract public function listcontent($path);
10
+ abstract public function listnum($path , $includeFolder = false);
11
+
12
+ public function getLastError(){
13
+ return $this -> last_error;
14
+ }
15
+ public function getBasename($basename){
16
+ $basename = basename($basename);
17
+ $arr = explode('.',$basename);
18
+ return $arr[0];
19
+ }
20
+ public function _in_array($file,$lists){
21
+ foreach ($lists as $item){
22
+ if(strstr($file,$item)){
23
+ return true;
24
+ }
25
+ }
26
+ return false;
27
+ }
28
+ public function filesplit($max_size,$files){
29
+ $packages = array();
30
+ if($max_size == 0 || empty($max_size)){
31
+ $packages[] = $files;
32
+ }else{
33
+ $sizenum = 0;
34
+ $size = $max_size * 1024 * 1024;
35
+ $package = array();
36
+ $flag = false;
37
+ foreach ($files as $file){
38
+ $sizenum += filesize($file);
39
+ if($sizenum > $size){
40
+ $package[] = $file;
41
+ $sizenum = 0;
42
+ $packages[] = $package;
43
+ $package = array();
44
+ $flag = true;
45
+ }else{
46
+ $package[] = $file;
47
+ $flag = false;
48
+ }
49
+ }
50
+ if(!$flag)
51
+ $packages[] = $package;
52
+ }
53
+ return $packages;
54
+ }
55
+ }
includes/class-wpvivid-crypt.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPVIVID_PLUGIN_DIR')){
4
+ die;
5
+ }
6
+
7
+ class WPvivid_crypt
8
+ {
9
+ private $public_key;
10
+ private $sym_key;
11
+
12
+ private $rij;
13
+ private $rsa;
14
+
15
+ public function __construct($public_key)
16
+ {
17
+ $this->public_key=$public_key;
18
+ include_once WPVIVID_PLUGIN_DIR . '/vendor/autoload.php';
19
+ $this->rij= new Crypt_Rijndael();
20
+ $this->rsa= new Crypt_RSA();
21
+ }
22
+
23
+ public function generate_key()
24
+ {
25
+ $this->sym_key = crypt_random_string(32);
26
+ $this->rij->setKey($this->sym_key);
27
+ }
28
+
29
+ public function encrypt_message($message)
30
+ {
31
+ $this->generate_key();
32
+ $key=$this->encrypt_key();
33
+ $len=str_pad(dechex(strlen($key)),3,'0', STR_PAD_LEFT);
34
+ $message=$this->rij->encrypt($message);
35
+ $message_len = str_pad(dechex(strlen($message)), 16, '0', STR_PAD_LEFT);
36
+ return $len.$key.$message_len.$message;;
37
+ }
38
+
39
+ public function encrypt_key()
40
+ {
41
+ $this->rsa->loadKey($this->public_key);
42
+ return $this->rsa->encrypt($this->sym_key);
43
+ }
44
+
45
+ public function decrypt_message($message)
46
+ {
47
+ $len = substr($message, 0, 3);
48
+ $len = hexdec($len);
49
+ $key = substr($message, 3, $len);
50
+
51
+ $cipherlen = substr($message, ($len + 3), 16);
52
+ $cipherlen = hexdec($cipherlen);
53
+
54
+ $data = substr($message, ($len + 19), $cipherlen);
55
+ $rsa = new Crypt_RSA();
56
+ $rsa->loadKey($this->public_key);
57
+ $key=$rsa->decrypt($key);
58
+ $rij = new Crypt_Rijndael();
59
+ $rij->setKey($key);
60
+ return $rij->decrypt($data);
61
+ }
62
+ }
includes/class-wpvivid-downloader.php CHANGED
@@ -30,14 +30,16 @@ class WPvivid_downloader
30
  if($ret['result']==WPVIVID_SUCCESS)
31
  {
32
  $progress=100;
33
- WPvivid_taskmanager::update_download_task( $task,$progress,$file['file_name'],'completed');
 
34
  return $ret;
35
  }
36
  else
37
  {
38
  $progress=0;
39
  $message=$ret['error'];
40
- WPvivid_taskmanager::update_download_task($task,$progress,$file['file_name'],'error',$message);
 
41
  return $ret;
42
  }
43
  }
@@ -45,7 +47,8 @@ class WPvivid_downloader
45
  public function download_callback($offset,$current_name,$current_size,$last_time,$last_size)
46
  {
47
  $progress= floor(($offset/$current_size)* 100) ;
48
- WPvivid_taskmanager::update_download_task( $this->task,$progress,$current_name,'running');
 
49
  }
50
 
51
  public function ready_download($download_info)
@@ -57,30 +60,31 @@ class WPvivid_downloader
57
  return false;
58
  }
59
  $download_option='';
60
- if($backup['backup']['ismerge']==1)
61
- {
62
- $backup_files=$backup['backup']['data']['meta']['files'];
63
- foreach ($backup_files as $file)
64
- {
65
- if($file['file_name']==$download_info['file_name'])
66
- {
67
- $download_option='all';
68
- $files[]=$file;
69
  break;
70
  }
71
  }
72
  }
73
- else
74
- {
75
- foreach ($backup['backup']['data']['type'] as $type)
76
- {
77
- $backup_files=$type['files'];
78
- foreach ($backup_files as $file)
79
- {
80
- if($file['file_name']==$download_info['file_name'])
81
- {
82
- $download_option=$type['type_name'];
83
- $files[]=$file;
 
 
 
 
 
84
  break;
85
  }
86
  }
@@ -135,7 +139,11 @@ class WPvivid_downloader
135
  }
136
  else
137
  {
138
- $task=WPvivid_taskmanager::new_download_task($download_info['backup_id'],$download_option,$need_download_files);
 
 
 
 
139
  }
140
  }
141
 
30
  if($ret['result']==WPVIVID_SUCCESS)
31
  {
32
  $progress=100;
33
+ //WPvivid_taskmanager::update_download_task( $task,$progress,$file['file_name'],'completed');
34
+ WPvivid_taskmanager::update_download_task_v2( $task,$progress,'completed');
35
  return $ret;
36
  }
37
  else
38
  {
39
  $progress=0;
40
  $message=$ret['error'];
41
+ //WPvivid_taskmanager::update_download_task($task,$progress,$file['file_name'],'error',$message);
42
+ WPvivid_taskmanager::update_download_task_v2($task,$progress,'error',$message);
43
  return $ret;
44
  }
45
  }
47
  public function download_callback($offset,$current_name,$current_size,$last_time,$last_size)
48
  {
49
  $progress= floor(($offset/$current_size)* 100) ;
50
+ //WPvivid_taskmanager::update_download_task( $this->task,$progress,$current_name,'running');
51
+ WPvivid_taskmanager::update_download_task_v2($this->task,$progress,'running');
52
  }
53
 
54
  public function ready_download($download_info)
60
  return false;
61
  }
62
  $download_option='';
63
+ if(isset($backup['backup']['files'])){
64
+ foreach ($backup['backup']['files'] as $file){
65
+ if ($file['file_name'] == $download_info['file_name']) {
66
+ $download_option = 'all';
67
+ $files[] = $file;
 
 
 
 
68
  break;
69
  }
70
  }
71
  }
72
+ else if ($backup['backup']['ismerge'] == 1) {
73
+ $backup_files = $backup['backup']['data']['meta']['files'];
74
+ foreach ($backup_files as $file) {
75
+ if ($file['file_name'] == $download_info['file_name']) {
76
+ $download_option = 'all';
77
+ $files[] = $file;
78
+ break;
79
+ }
80
+ }
81
+ } else {
82
+ foreach ($backup['backup']['data']['type'] as $type) {
83
+ $backup_files = $type['files'];
84
+ foreach ($backup_files as $file) {
85
+ if ($file['file_name'] == $download_info['file_name']) {
86
+ $download_option = $type['type_name'];
87
+ $files[] = $file;
88
  break;
89
  }
90
  }
139
  }
140
  else
141
  {
142
+ //$task=WPvivid_taskmanager::new_download_task($download_info['backup_id'],$download_option,$need_download_files);
143
+ foreach ($need_download_files as $file){
144
+ $filename=$file['file_name'];
145
+ }
146
+ $task=WPvivid_taskmanager::new_download_task_v2($filename);
147
  }
148
  }
149
 
includes/class-wpvivid-log.php CHANGED
@@ -29,8 +29,8 @@ class WPvivid_Log
29
  }
30
  $this->log_file_handle = fopen($this->log_file, 'a');
31
  $time =date("Y-m-d H:i:s",time());
32
- $text='log created: '.$time."\n";
33
- $text.='type: '.$describe."\n";
34
  fwrite($this->log_file_handle,$text);
35
 
36
  return $this->log_file;
29
  }
30
  $this->log_file_handle = fopen($this->log_file, 'a');
31
  $time =date("Y-m-d H:i:s",time());
32
+ $text='Log created: '.$time."\n";
33
+ $text.='Type: '.$describe."\n";
34
  fwrite($this->log_file_handle,$text);
35
 
36
  return $this->log_file;
includes/class-wpvivid-migrate.php ADDED
@@ -0,0 +1,1179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPVIVID_PLUGIN_DIR'))
4
+ {
5
+ die;
6
+ }
7
+
8
+ class WPvivid_Migrate
9
+ {
10
+ public function __construct()
11
+ {
12
+ add_action('wpvivid_backuprestore_add_tab',array($this,'add_addon_tab_transfer'), 11);
13
+ add_action('wpvivid_backuprestore_add_tab',array($this,'add_addon_tab_key'), 16);
14
+ add_action('wpvivid_backuprestore_add_page',array($this,'add_addon_page_transfer'));
15
+ add_action('wpvivid_backuprestore_add_page',array($this,'add_addon_page_key'));
16
+ add_action('wp_ajax_wpvivid_generate_url',array( $this,'generate_url'));
17
+ add_action('wp_ajax_wpvivid_send_backup_to_site',array( $this,'send_backup_to_site'));
18
+ add_action('wp_ajax_wpvivid_migrate_now',array( $this,'migrate_now'));
19
+
20
+ add_action('wp_ajax_wpvivid_export_download_backup',array( $this,'export_download_backup'));
21
+ add_action('wp_ajax_wpvivid_list_upload_tasks',array( $this,'list_tasks'));
22
+ add_action('wp_ajax_wpvivid_test_connect_site',array( $this,'test_connect_site'));
23
+ add_action('wp_ajax_wpvivid_delete_transfer_key',array($this, 'delete_transfer_key'));
24
+ add_action('wp_ajax_wpvivid_delete_transfer_backup', array($this, 'delete_transfer_backup'));
25
+ add_action('wp_ajax_wpvivid_delete_transfer_backup_array', array($this, 'delete_transfer_backup_array'));
26
+
27
+ add_filter('wpvivid_put_transfer_key', array($this, 'wpvivid_put_transfer_key'));
28
+ add_action('wpvivid_handle_backup_failed',array($this,'wpvivid_handle_backup_failed'),9);
29
+
30
+ add_action('wpvivid_backup_add_tab', array($this, 'wpvivid_add_tab_upload'), 14);
31
+ add_action('wpvivid_backup_add_page', array($this, 'wpvivid_add_page_upload'), 14);
32
+ add_action('wpvivid_rescan_backup_list', array($this, 'wpvivid_rescan_backup_list'));
33
+ add_action('wpvivid_handle_upload_succeed',array($this,'wpvivid_deal_upload_succeed'),11);
34
+ }
35
+
36
+ public function test_connect_site()
37
+ {
38
+ if(isset($_POST['url']))
39
+ {
40
+ $url=strtok($_POST['url'],'?');
41
+
42
+ if (filter_var($url, FILTER_VALIDATE_URL) === FALSE)
43
+ {
44
+ $ret['result']=WPVIVID_FAILED;
45
+ $ret['error']='The key is invalid.';
46
+ echo json_encode($ret);
47
+ die();
48
+ }
49
+
50
+ if($url==admin_url('admin-ajax.php'))
51
+ {
52
+ $ret['result']=WPVIVID_FAILED;
53
+ $ret['error']='The key generated by this site cannot be added into this site.';
54
+ echo json_encode($ret);
55
+ die();
56
+ }
57
+ $query=parse_url ($_POST['url'],PHP_URL_QUERY);
58
+ parse_str($query,$query_arr);
59
+ $token=$query_arr['token'];
60
+ $expires=$query_arr['expires'];
61
+ $domain=$query_arr['domain'];
62
+
63
+ if ($expires != 0 && time() > $expires) {
64
+ $ret['result'] = 'failed';
65
+ $ret['error'] = 'The key has expired.';
66
+ echo json_encode($ret);
67
+ die();
68
+ }
69
+
70
+ $json['test_connect']=1;
71
+ $json=json_encode($json);
72
+ $crypt=new WPvivid_crypt(base64_decode($token));
73
+ $data=$crypt->encrypt_message($json);
74
+
75
+ $data=base64_encode($data);
76
+
77
+ $args['body']=array('data'=>$data,'action'=>'wpvivid_send_to_site_connect');
78
+ $response=wp_remote_post($url,$args);
79
+
80
+ if ( is_wp_error( $response ) )
81
+ {
82
+ $ret['result']=WPVIVID_FAILED;
83
+ $ret['error']= $response->get_error_message();
84
+ }
85
+ else
86
+ {
87
+ if($response['response']['code']==200)
88
+ {
89
+ $res=json_decode($response['body'],1);
90
+ if($res!=null)
91
+ {
92
+ if($res['result']==WPVIVID_SUCCESS)
93
+ {
94
+ $ret['result']=WPVIVID_SUCCESS;
95
+
96
+ $options=WPvivid_Setting::get_option('wpvivid_saved_api_token');
97
+
98
+ $options[$url]['token']=$token;
99
+ $options[$url]['url']=$url;
100
+ $options[$url]['expires']=$expires;
101
+ $options[$url]['domain']=$domain;
102
+
103
+ delete_option('wpvivid_saved_api_token');
104
+ update_option('wpvivid_saved_api_token',$options);
105
+
106
+ $html='';
107
+ $i=0;
108
+ foreach ($options as $key=>$site)
109
+ {
110
+ $check_status='';
111
+ if($key==$url)
112
+ {
113
+ $check_status='checked';
114
+ }
115
+
116
+ if($site['expires']>time())
117
+ {
118
+ $date=date("l, F d, Y H:i", $site['expires']);
119
+ }
120
+ else
121
+ {
122
+ $date='Token has expired';
123
+ }
124
+
125
+ $i++;
126
+ $html = apply_filters('wpvivid_put_transfer_key', $html);
127
+ }
128
+ $ret['html']= $html;
129
+
130
+ }
131
+ else
132
+ {
133
+ $ret['result']=WPVIVID_FAILED;
134
+ $ret['error']= $res['error'];
135
+ }
136
+ }
137
+ else
138
+ {
139
+ $ret['result']=WPVIVID_FAILED;
140
+ $ret['error']= 'bad request. '.$response['body'];
141
+ }
142
+ }
143
+ else
144
+ {
145
+ $ret['result']=WPVIVID_FAILED;
146
+ $ret['error']= 'upload error '.$response['response']['code'].' '.$response['body'];
147
+ }
148
+ }
149
+
150
+ echo json_encode($ret);
151
+ }
152
+ die();
153
+ }
154
+
155
+ public function delete_transfer_key(){
156
+ $ret['result']=WPVIVID_SUCCESS;
157
+ delete_option('wpvivid_saved_api_token');
158
+ $html='';
159
+ $html = apply_filters('wpvivid_put_transfer_key', $html);
160
+ $ret['html']=$html;
161
+ echo json_encode($ret);
162
+ die();
163
+ }
164
+
165
+ public function delete_transfer_backup(){
166
+ global $wpvivid_pulgin;
167
+ $wpvivid_pulgin->ajax_check_security();
168
+ if(isset($_POST['backup_id'])&&!empty($_POST['backup_id'])&&is_string($_POST['backup_id'])&&isset($_POST['force']))
169
+ {
170
+ if($_POST['force']==0||$_POST['force']==1)
171
+ {
172
+ $force_del=$_POST['force'];
173
+ }
174
+ else
175
+ {
176
+ $force_del=0;
177
+ }
178
+ $backup_id=sanitize_key($_POST['backup_id']);
179
+
180
+ $ret=$wpvivid_pulgin->delete_backup_by_id($backup_id, $force_del);
181
+ $html = '';
182
+ $html = apply_filters('wpvivid_add_backup_list', $html);
183
+ $ret['html'] = $html;
184
+ echo json_encode($ret);
185
+ }
186
+
187
+ die();
188
+ }
189
+
190
+ public function delete_transfer_backup_array(){
191
+ global $wpvivid_pulgin;
192
+ $wpvivid_pulgin->ajax_check_security();
193
+ if(isset($_POST['backup_id'])&&!empty($_POST['backup_id'])&&is_array($_POST['backup_id']))
194
+ {
195
+ $backup_ids=$_POST['backup_id'];
196
+ $ret=array();
197
+ foreach($backup_ids as $backup_id)
198
+ {
199
+ $backup_id=sanitize_key($backup_id);
200
+ $ret=$wpvivid_pulgin->delete_backup_by_id($backup_id);
201
+ }
202
+ $html = '';
203
+ $html = apply_filters('wpvivid_add_backup_list', $html);
204
+ $ret['html'] = $html;
205
+ echo json_encode($ret);
206
+ }
207
+
208
+ die();
209
+ }
210
+
211
+ public function upload($task_id)
212
+ {
213
+ $task=WPvivid_taskmanager::get_task($task_id);
214
+
215
+ if($task===false)
216
+ {
217
+ $ret['result']=WPVIVID_FAILED;
218
+ $ret['error']='Task id not found';
219
+ echo json_encode($ret);
220
+ die();
221
+ }
222
+
223
+ global $wpvivid_pulgin;
224
+ $log_file_name=uniqid('test-');
225
+ $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
226
+ $wpvivid_pulgin->wpvivid_log->CreateLogFile($log_file_name,'no_folder','test');
227
+
228
+ $ret['result']='success';
229
+ $ret['task_id']=$task_id;
230
+ $json=json_encode($ret);
231
+ header('Content-Length: '.strlen($json));
232
+ header('Connection: close');
233
+ header('Content-Encoding: none');
234
+
235
+ if (session_id())
236
+ session_write_close();
237
+ echo $json;
238
+
239
+ if(function_exists('fastcgi_finish_request'))
240
+ {
241
+ fastcgi_finish_request();
242
+ }
243
+ else
244
+ {
245
+ ob_flush();
246
+ flush();
247
+ }
248
+
249
+ include_once WPVIVID_PLUGIN_DIR . '/addons/class-wpvivid-upload.php';
250
+
251
+ $upload=new WPvivid_Upload();
252
+
253
+ set_time_limit(900);
254
+
255
+ $backup=WPvivid_taskmanager::get_task_options($task_id,'backup');
256
+ $remote_options=WPvivid_taskmanager::get_task_options($task_id,'remote_options');
257
+ $remote_option=array_shift($remote_options);
258
+ $this->add_monitor_event($task_id);
259
+
260
+ $ret=$upload->upload($task_id,$backup,$remote_option);
261
+ if($ret['result']==WPVIVID_SUCCESS)
262
+ {
263
+ $timestamp =wp_next_scheduled(WPVIVID_UPLOAD_TASK_MONITOR_EVENT,array($task_id));
264
+ if($timestamp!==false)
265
+ {
266
+ wp_unschedule_event($timestamp,WPVIVID_UPLOAD_TASK_MONITOR_EVENT,array($task_id));
267
+ }
268
+
269
+ if(!array_key_exists('temp',$remote_options))
270
+ {
271
+ WPvivid_Backuplist::update_backup($_POST['backup_id'],'remote',$remote_options);
272
+ }
273
+ }
274
+ }
275
+
276
+ public function send_backup_to_site()
277
+ {
278
+ //if(isset($_POST['url']))
279
+ //{
280
+ $options=WPvivid_Setting::get_option('wpvivid_saved_api_token');
281
+
282
+ if(empty($options))
283
+ {
284
+ $ret['result'] = 'failed';
285
+ $ret['error'] = 'A key is required.';
286
+ echo json_encode($ret);
287
+ die();
288
+ }
289
+ //$options[$url]['url']=$url;
290
+
291
+ $url = '';
292
+ foreach ($options as $key => $value) {
293
+ $url = $value['url'];
294
+ }
295
+
296
+ if($url === '')
297
+ {
298
+ $ret['result'] = 'failed';
299
+ $ret['error'] = 'The key is invalid.';
300
+ echo json_encode($ret);
301
+ die();
302
+ }
303
+
304
+ if($options[$url]['expires'] !=0 && $options[$url]['expires']<time())
305
+ {
306
+ $ret['result'] = 'failed';
307
+ $ret['error'] = 'The key has expired.';
308
+ echo json_encode($ret);
309
+ die();
310
+ }
311
+
312
+ if(WPvivid_taskmanager::is_tasks_backup_running())
313
+ {
314
+ $ret['result']='failed';
315
+ $ret['error']=__('A task is already running. Please wait until the running task is complete, and try again.', 'wpvivid');
316
+ return $ret;
317
+ }
318
+
319
+ $remote_option['url']=$options[$url]['url'];
320
+ $remote_option['token']=$options[$url]['token'];
321
+ $remote_option['type']=WPVIVID_REMOTE_SEND_TO_SITE;
322
+ $remote_options['temp']=$remote_option;
323
+
324
+ $backup_options = stripslashes($_POST['backup_options']);
325
+ $backup_options = json_decode($backup_options, true);
326
+ $backup['backup_files']= $backup_options['backup_type'];
327
+ $backup['local']=0;
328
+ $backup['remote']=1;
329
+ $backup['ismerge']=1;
330
+ $backup['lock']=0;
331
+ $backup['remote_options']=$remote_options;
332
+
333
+ $backup_task=new WPvivid_Backup_Task();
334
+ $ret=$backup_task->new_backup_task($backup,'Manual', 'transfer');
335
+
336
+ $task_id=$ret['task_id'];
337
+
338
+ global $wpvivid_pulgin;
339
+
340
+ $wpvivid_pulgin->check_backup($task_id,$backup['backup_files']);
341
+ //$wpvivid_pulgin->backup($task_id);
342
+ //}
343
+ echo json_encode($ret);
344
+ die();
345
+ }
346
+
347
+ public function migrate_now()
348
+ {
349
+ if (!isset($_POST['task_id'])||empty($_POST['task_id'])||!is_string($_POST['task_id']))
350
+ {
351
+ $ret['result']='failed';
352
+ $ret['error']=__('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid');
353
+ echo json_encode($ret);
354
+ die();
355
+ }
356
+ $task_id=sanitize_key($_POST['task_id']);
357
+
358
+ //Start backup site
359
+ global $wpvivid_pulgin;
360
+ $wpvivid_pulgin->backup($task_id);
361
+ die();
362
+ }
363
+
364
+ function export_download_backup()
365
+ {
366
+ $schedule_options=WPvivid_Schedule::get_schedule();
367
+ if(empty($schedule_options))
368
+ {
369
+ die();
370
+ }
371
+ $backup_options = stripslashes($_POST['backup_options']);
372
+ $backup_options = json_decode($backup_options, true);
373
+ $backup['backup_files']= $backup_options['backup_type'];
374
+ $backup['local']=1;
375
+ $backup['remote']=0;
376
+ $backup['ismerge']=1;
377
+ $backup['lock']=0;
378
+ //$backup['remote_options']='';
379
+
380
+ $backup_task=new WPvivid_Backup_Task();
381
+ $task=$backup_task->new_backup_task($backup,'Manual', 'export');
382
+
383
+ $task_id=$task['task_id'];
384
+ global $wpvivid_pulgin;
385
+ //add_action('wpvivid_handle_upload_succeed',array($this,'wpvivid_deal_upload_succeed'),11);
386
+ $wpvivid_pulgin->check_backup($task_id,$backup['backup_files']);
387
+ $wpvivid_pulgin->backup($task_id);
388
+ //}
389
+ die();
390
+ }
391
+
392
+ function wpvivid_handle_backup_failed($task)
393
+ {
394
+ global $wpvivid_pulgin;
395
+ if($task['action'] === 'transfer') {
396
+ $backup_error_array = WPvivid_Setting::get_option('wpvivid_transfer_error_array');
397
+ if (empty($backup_error_array)) {
398
+ $backup_error_array = array();
399
+ }
400
+ if (!array_key_exists($task['id'], $backup_error_array['bu_error'])) {
401
+ $backup_error_array['bu_error']['task_id'] = $task['id'];
402
+ $backup_error_array['bu_error']['error_msg'] = $task['status']['error'];
403
+ WPvivid_Setting::update_option('wpvivid_transfer_error_array', $backup_error_array);
404
+ }
405
+ $backup=new WPvivid_Backup($task['id']);
406
+ $backup->clean_backup();
407
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Upload failed. Delete task '.$task['id'], 'notice');
408
+ WPvivid_Backuplist::delete_backup($task['id']);
409
+ }
410
+ }
411
+
412
+ public function wpvivid_deal_upload_succeed($task)
413
+ {
414
+ global $wpvivid_pulgin;
415
+ if($task['action'] === 'transfer')
416
+ {
417
+ $backup_success_count = WPvivid_Setting::get_option('wpvivid_transfer_success_count');
418
+ if (empty($backup_success_count))
419
+ {
420
+ $backup_success_count = 0;
421
+ }
422
+ $backup_success_count++;
423
+ WPvivid_Setting::update_option('wpvivid_transfer_success_count', $backup_success_count);
424
+
425
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Upload finished. Delete task '.$task['id'], 'notice');
426
+ WPvivid_Backuplist::delete_backup($task['id']);
427
+ }
428
+ }
429
+
430
+ public function generate_url()
431
+ {
432
+ include_once WPVIVID_PLUGIN_DIR . '/vendor/autoload.php';
433
+
434
+ $expires=time()+3600;
435
+
436
+ if(isset($_POST['expires']))
437
+ {
438
+ if($_POST['expires']=='1 month')
439
+ {
440
+ $expires=time()+2592000;
441
+ }
442
+ else if($_POST['expires']=='1 day')
443
+ {
444
+ $expires=time()+86400;
445
+ }
446
+ else if($_POST['expires']=='2 hour')
447
+ {
448
+ $expires=time()+7200;
449
+ }
450
+ else if($_POST['expires']=='8 hour')
451
+ {
452
+ $expires=time()+28800;
453
+ }
454
+ else if($_POST['expires']=='24 hour')
455
+ {
456
+ $expires=time()+86400;
457
+ }
458
+ else if($_POST['expires']=='Never')
459
+ {
460
+ $expires=0;
461
+ }
462
+ }
463
+
464
+ $key_size = 2048;
465
+ $rsa = new Crypt_RSA();
466
+ $keys = $rsa->createKey($key_size);
467
+ $options['public_key']=base64_encode($keys['publickey']);
468
+ $options['private_key']=base64_encode($keys['privatekey']);
469
+ $options['expires']=$expires;
470
+ $options['domain']=home_url();
471
+
472
+ update_option('wpvivid_api_token',$options);
473
+
474
+ $url=admin_url('admin-ajax.php');
475
+ $url=$url.'?domain='.$options['domain'].'&token='.$options['public_key'].'&expires='.$expires;
476
+ echo $url;
477
+ die();
478
+ }
479
+
480
+ public function add_addon_tab_transfer()
481
+ {
482
+ $html=' <a href="#" id="wpvivid_tab_migrate" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,\'migrate-page\')">Transfer/Migration</a>';
483
+ echo $html;
484
+ }
485
+
486
+ public function add_addon_tab_key(){
487
+ $html='<a href="#" id="wpvivid_tab_key" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,\'key-page\')">Generate Key</a>';
488
+ echo $html;
489
+ }
490
+
491
+ public function wpvivid_put_transfer_key($html){
492
+ $html='';
493
+ $options=WPvivid_Setting::get_option('wpvivid_saved_api_token');
494
+ if(empty($options)){
495
+ $html .= '<div style="padding: 0 0 10px 0;"><strong>'.__('Please paste the key below.', 'wpvivid').'</strong><a href="#" style="margin-left: 5px;" onclick="wpvivid_click_how_to_get_key();">How to get a site key?</a></div>
496
+ <div id="wpvivid_how_to_get_key"></div>
497
+ <div><textarea type="text" id="wpvivid_transfer_key_text" onKeyUp="wpvivid_check_key(this.value)" style="width: 100%; height: 140px;"/></textarea></div>
498
+ <div><input class="button-primary" id="wpvivid_save_url_button" type="submit" value="'.esc_attr( 'Save', 'wpvivid' ).'" onclick="wpvivid_click_save_site_url();" /></div>';
499
+ }
500
+ else{
501
+ foreach ($options as $key => $value)
502
+ {
503
+ $token = $value['token'];
504
+ $source_dir=home_url();
505
+ $target_dir=$value['domain'];
506
+ $expires=$value['expires'];
507
+
508
+ if ($expires != 0 && time() > $expires) {
509
+ $key_status='The key has expired.';
510
+ }
511
+ else{
512
+ $time_diff = $expires - time();
513
+ $key_status = date("H:i:s",$time_diff);
514
+ }
515
+ }
516
+ $html .= '<div style="padding: 10px 0 10px 0;">
517
+ <span>Key:</span>
518
+ <input type="text" id="wpvivid_send_remote_site_url_text" value="'.$token.'" readonly="readonly" />
519
+ <input class="button-primary" id="wpvivid_delete_key_button" type="submit" value="'.esc_attr( 'Delete', 'wpvivid' ).'" onclick="wpvivid_click_delete_transfer_key();" />
520
+ </div>
521
+ <p>'.__('Time remaining:', 'wpvivid').$key_status.'</p>
522
+ <p>The connection is ok. Now you can transfer the site <strong>'.$source_dir.'</strong> to the site <strong>'.$target_dir.'</strong></p>';
523
+ }
524
+ return $html;
525
+ }
526
+
527
+ public function add_addon_page_transfer()
528
+ {
529
+ $backupdir=WPvivid_Setting::get_backupdir();
530
+ ?>
531
+ <div id="migrate-page" class="wrap-tab-content wpvivid_tab_migrate" name="tab-migrate" style="display: none;">
532
+ <div style="padding: 0 0 10px 0;">
533
+ <?php
534
+ _e('The feature can help you transfer a Wordpress site to a new domain. It would be useful to migrate your WP site from dev environment to live server or from old server to the new.', 'wpvivid');
535
+ ?>
536
+ </div>
537
+
538
+ <div id="wpvivid_transfer_key">
539
+ <?php
540
+ $html = '';
541
+ $html = apply_filters('wpvivid_put_transfer_key', $html);
542
+ echo $html;
543
+ ?>
544
+ </div>
545
+ <div style="clear: both;"></div>
546
+
547
+ <div style="padding: 0 0 10px 0;">
548
+ <div class="postbox" id="wpvivid_upload_backup_percent" >
549
+ <div class="action-progress-bar" id="wpvivid_upload_progress_bar">
550
+ <div class="action-progress-bar-percent" id="wpvivid_upload_progress_bar_percent" style="height:24px;width:0"></div>
551
+ </div>
552
+ <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing"></p></div>
553
+ <div style="clear: both;"></div>
554
+ </div>
555
+ </div>
556
+
557
+ <div style="padding: 0 0 10px 0;">
558
+ <div class="postbox quicktransfer">
559
+ <h2><span><?php _e( 'Choose the content you want to transfer','wpvivid'); ?></span></h2>
560
+ <div class="quickstart-archive-block">
561
+ <fieldset>
562
+ <legend class="screen-reader-text"><span>input type="radio"</span></legend>
563
+ <label>
564
+ <input type="radio" option="migrate" name="backup_type" value="files+db" checked />
565
+ <span><?php _e( 'Database + Files (Entire website)', 'wpvivid' ); ?></span>
566
+ </label><br>
567
+ <label>
568
+ <input type="radio" option="migrate" name="backup_type" value="files" />
569
+ <span><?php _e( 'All Files (Exclude Database)', 'wpvivid' ); ?></span>
570
+ </label><br>
571
+ <label>
572
+ <input type="radio" option="migrate" name="backup_type" value="db" />
573
+ <span><?php _e( 'Only Database', 'wpvivid' ); ?></span>
574
+ </label><br>
575
+ </fieldset>
576
+ </div>
577
+ </div>
578
+
579
+ <div style="padding: 0 0 10px 0;">
580
+ <div id="wpvivid_transfer_btn" style="float: left;">
581
+ <input class="button-primary quicktransfer-btn" type="submit" value="<?php esc_attr_e( 'Transfer', 'wpvivid'); ?>" onclick="wpvivid_click_send_backup();" />
582
+ </div>
583
+ </div>
584
+ <div style="clear: both;"></div>
585
+ <div style="padding: 10px 0 10px 0;">
586
+ <p><strong>Tips: </strong>If the network connection between servers is unstable, this could cause a failure of files transfer. In this case, uploading backups to destination site is a good alternative to the automatic website migration.</p>
587
+ <p><strong>How to migrate Wordpress site manually to a new domain with WPvivid backup plugin?</strong></p>
588
+ <p>1. Download the backup in backups list to your computer.</p>
589
+ <p>2. Upload backup to destination site. There are two ways available to use:</p>
590
+ <p style="margin-left: 20px;">2.1 Upload backup to the upload section of WPvivid backup plugin in destination site.</p>
591
+ <p style="margin-left: 20px;">2.2 Upload backup with FTP client to backup directory <?php echo WP_CONTENT_DIR.'/'.$backupdir; ?> in destination site and <strong>rescan backups list</strong>.</p>
592
+ <p>3. Once done, the backup shows in backups list. Then, restore the backup.</p>
593
+ </div>
594
+ </div>
595
+ </div>
596
+ <script>
597
+ var wpvivid_home_url = '<?php
598
+ $wpvivid_siteurl = array();
599
+ $wpvivid_siteurl=WPvivid_Admin::wpvivid_get_siteurl();
600
+ echo esc_url($wpvivid_siteurl['home_url']);
601
+ ?>';
602
+ var source_site = '<?php echo admin_url('admin-ajax.php'); ?>';
603
+ jQuery('input:radio[option=migrate][name=transfer]').click(function(){
604
+ var value = jQuery(this).prop('value');
605
+ if(value === 'transfer'){
606
+ jQuery('#wpvivid_transfer_btn').show();
607
+ jQuery('#wpvivid_export_download_btn').hide();
608
+ }
609
+ else if(value === 'export'){
610
+ jQuery('#wpvivid_transfer_btn').hide();
611
+ jQuery('#wpvivid_export_download_btn').show();
612
+ }
613
+ });
614
+ //wpvivid_edit_url_button
615
+ jQuery('#wpvivid_add_remote_site_url').show();
616
+ jQuery('#wpvivid_upload_backup_percent').hide();
617
+ //
618
+ function wpvivid_check_key(value){
619
+ var pos = value.indexOf('?');
620
+ var site_url = value.substring(0, pos);
621
+ if(site_url == source_site){
622
+ alert('The key generated by this site cannot be added into this site.');
623
+ jQuery('#wpvivid_save_url_button').prop('disabled', true);
624
+ }
625
+ else{
626
+ jQuery("#wpvivid_save_url_button").prop('disabled', false);
627
+ }
628
+ }
629
+
630
+ function wpvivid_click_save_site_url()
631
+ {
632
+ var url= jQuery('#wpvivid_transfer_key_text').val();
633
+ var ajax_data = {
634
+ 'action': 'wpvivid_test_connect_site',
635
+ 'url':url
636
+ };
637
+
638
+ jQuery("#wpvivid_save_url_button").prop('disabled', true);
639
+ wpvivid_post_request(ajax_data, function (data)
640
+ {
641
+ jQuery("#wpvivid_save_url_button").prop('disabled', false);
642
+ try
643
+ {
644
+ var jsonarray = jQuery.parseJSON(data);
645
+ if(jsonarray.result==='success')
646
+ {
647
+ jQuery('#wpvivid_transfer_key').html(jsonarray.html);
648
+ }
649
+ else
650
+ {
651
+ alert(jsonarray.error);
652
+ }
653
+ }
654
+ catch(err)
655
+ {
656
+ alert(err);
657
+ }
658
+ }, function (XMLHttpRequest, textStatus, errorThrown)
659
+ {
660
+ jQuery("#wpvivid_save_url_button").prop('disabled', false);
661
+ var error_message = wpvivid_output_ajaxerror('saving key', textStatus, errorThrown);
662
+ alert(error_message);
663
+ });
664
+ }
665
+
666
+ function wpvivid_click_delete_transfer_key()
667
+ {
668
+ var ajax_data = {
669
+ 'action': 'wpvivid_delete_transfer_key'
670
+ };
671
+
672
+ jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'none', 'opacity': '0.4'});
673
+ wpvivid_post_request(ajax_data, function (data)
674
+ {
675
+ jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'none', 'opacity': '0.4'});
676
+ try
677
+ {
678
+ var jsonarray = jQuery.parseJSON(data);
679
+ if(jsonarray.result==='success')
680
+ {
681
+ jQuery('#wpvivid_transfer_key').html(jsonarray.html);
682
+ }
683
+ }
684
+ catch(err)
685
+ {
686
+ alert(err);
687
+ }
688
+ }, function (XMLHttpRequest, textStatus, errorThrown)
689
+ {
690
+ jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'auto', 'opacity': '1'});
691
+ var error_message = wpvivid_output_ajaxerror('deleting key', textStatus, errorThrown);
692
+ alert(error_message);
693
+ });
694
+ }
695
+
696
+ function wpvivid_click_generate_url()
697
+ {
698
+ //
699
+ var expires=jQuery('#wpvivid_generate_url_expires').val();
700
+ var ajax_data = {
701
+ 'action': 'wpvivid_generate_url',
702
+ 'expires':expires
703
+ };
704
+ wpvivid_post_request(ajax_data, function (data)
705
+ {
706
+ jQuery('#wpvivid_test_remote_site_url_text').val(data);
707
+ }, function (XMLHttpRequest, textStatus, errorThrown)
708
+ {
709
+ var error_message = wpvivid_output_ajaxerror('generating key', textStatus, errorThrown);
710
+ alert(error_message);
711
+ });
712
+ }
713
+
714
+ function wpvivid_control_transfer_lock(){
715
+ jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
716
+ jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
717
+ jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'none', 'opacity': '0.4'});
718
+ }
719
+
720
+ function wpvivid_control_transfer_unlock(){
721
+ jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
722
+ jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
723
+ jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'auto', 'opacity': '1'});
724
+ }
725
+
726
+ function wpvivid_click_send_backup()
727
+ {
728
+ //send_to_remote
729
+ var option_data = wpvivid_ajax_data_transfer('migrate');
730
+ var ajax_data = {
731
+ 'action': 'wpvivid_send_backup_to_site',
732
+ 'backup_options':option_data
733
+ };
734
+ migrate_task_need_update=true;
735
+ wpvivid_clear_notice('wpvivid_backup_notice');
736
+ //jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
737
+ wpvivid_control_transfer_lock();
738
+ wpvivid_post_request(ajax_data, function (data)
739
+ {
740
+ try
741
+ {
742
+ var jsonarray = jQuery.parseJSON(data);
743
+ if(jsonarray.result==='failed')
744
+ {
745
+ wpvivid_delete_transfer_ready_task(jsonarray.error);
746
+ }
747
+ else{
748
+ wpvivid_migrate_now(jsonarray.task_id);
749
+ }
750
+ }
751
+ catch(err)
752
+ {
753
+ wpvivid_delete_transfer_ready_task(err);
754
+ }
755
+ }, function (XMLHttpRequest, textStatus, errorThrown)
756
+ {
757
+ var error_message = wpvivid_output_ajaxerror('transferring website', textStatus, errorThrown);
758
+ wpvivid_delete_transfer_ready_task(error_message);
759
+ });
760
+ }
761
+
762
+ function wpvivid_migrate_now(task_id){
763
+ var ajax_data = {
764
+ 'action': 'wpvivid_migrate_now',
765
+ 'task_id': task_id
766
+ };
767
+ task_recheck_times = 0;
768
+ migrate_task_need_update=true;
769
+ wpvivid_post_request(ajax_data, function(data){
770
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
771
+ });
772
+ }
773
+
774
+ function wpvivid_delete_transfer_ready_task(error){
775
+ var ajax_data={
776
+ 'action': 'wpvivid_delete_ready_task'
777
+ };
778
+ wpvivid_post_request(ajax_data, function (data) {
779
+ try {
780
+ var jsonarray = jQuery.parseJSON(data);
781
+ if (jsonarray.result === 'success') {
782
+ wpvivid_add_notice('Backup', 'Error', error);
783
+ //jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
784
+ wpvivid_control_transfer_unlock();
785
+ jQuery('#wpvivid_upload_backup_percent').hide();
786
+ }
787
+ }
788
+ catch(err){
789
+ wpvivid_add_notice('Backup', 'Error', err);
790
+ //jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
791
+ wpvivid_control_transfer_unlock();
792
+ jQuery('#wpvivid_upload_backup_percent').hide();
793
+ }
794
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
795
+ setTimeout(function () {
796
+ wpvivid_delete_transfer_ready_task(error);
797
+ }, 3000);
798
+ });
799
+ }
800
+
801
+ function wpvivid_click_export_backup()
802
+ {
803
+ //alert("Export and Download Backup.");
804
+ var option_data = wpvivid_ajax_data_transfer('migrate');
805
+ var ajax_data = {
806
+ 'action': 'wpvivid_export_download_backup',
807
+ 'backup_options':option_data
808
+ };
809
+ migrate_task_need_update=true;
810
+ jQuery('#wpvivid_export_download_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
811
+ wpvivid_post_request(ajax_data, function (data)
812
+ {
813
+ }, function (XMLHttpRequest, textStatus, errorThrown)
814
+ {
815
+ var error_message = wpvivid_output_ajaxerror('test generate url', textStatus, errorThrown);
816
+ alert(error_message);
817
+ });
818
+ }
819
+
820
+ function click_dismiss_key_notice(obj){
821
+ jQuery(obj).parent().remove();
822
+ }
823
+
824
+ function wpvivid_click_how_to_get_key(){
825
+ var div = "<div class='notice notice-info is-dismissible inline'>" +
826
+ "<p>1. Visit Generate Key tab page of WPvivid backup plugin of destination site.</p>" +
827
+ "<p>2. Generate a key by clicking Generate button and copy it.</p>" +
828
+ "<p>3. Go back to this page and paste the key in key box below. Lastly, click Save button.</p>" +
829
+ "<button type='button' class='notice-dismiss' onclick='click_dismiss_key_notice(this);'>" +
830
+ "<span class='screen-reader-text'>Dismiss this notice.</span>" +
831
+ "</button>" +
832
+ "</div>";
833
+ jQuery('#wpvivid_how_to_get_key').append(div);
834
+ }
835
+
836
+ var migrate_task_need_update=true;
837
+ var task_recheck_times=0;
838
+ function wpvivid_check_upload_runningtask()
839
+ {
840
+ var ajax_data = {
841
+ 'action': 'wpvivid_list_upload_tasks',
842
+ };
843
+ if(wpvivid_restoring === false) {
844
+ wpvivid_post_request(ajax_data, function (data) {
845
+ setTimeout(function () {
846
+ wpvivid_manage_upload_task();
847
+ }, 3000);
848
+ try {
849
+ var jsonarray = jQuery.parseJSON(data);
850
+ if (jsonarray.transfer_succeed_notice != false) {
851
+ jQuery('#wpvivid_backup_notice').show();
852
+ jQuery('#wpvivid_backup_notice').append(jsonarray.transfer_succeed_notice);
853
+ }
854
+ if (jsonarray.transfer_error_notice != false) {
855
+ jQuery('#wpvivid_backup_notice').show();
856
+ jQuery.each(jsonarray.transfer_error_notice, function (index, value) {
857
+ jQuery('#wpvivid_backup_notice').append(value.error_msg);
858
+ });
859
+ }
860
+ var b_need_show = false;
861
+ if (jsonarray.transfer.data.length !== 0) {
862
+ b_need_show = true;
863
+ task_recheck_times = 0;
864
+ if (jsonarray.transfer.result === 'success') {
865
+ jQuery.each(jsonarray.transfer.data, function (index, value) {
866
+ if (value.status.str === 'ready') {
867
+ /*jQuery('#wpvivid_transfer_btn').css({
868
+ 'pointer-events': 'none',
869
+ 'opacity': '0.4'
870
+ });*/
871
+ wpvivid_control_transfer_lock();
872
+ jQuery('#wpvivid_upload_backup_percent').show();
873
+ jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
874
+ migrate_task_need_update = true;
875
+ }
876
+ else if (value.status.str === 'running') {
877
+ /*jQuery('#wpvivid_transfer_btn').css({
878
+ 'pointer-events': 'none',
879
+ 'opacity': '0.4'
880
+ });*/
881
+ wpvivid_control_transfer_lock();
882
+ jQuery('#wpvivid_upload_backup_percent').show();
883
+ jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
884
+ migrate_task_need_update = true;
885
+ }
886
+ else if (value.status.str === 'wait_resume') {
887
+ /*jQuery('#wpvivid_transfer_btn').css({
888
+ 'pointer-events': 'none',
889
+ 'opacity': '0.4'
890
+ });*/
891
+ wpvivid_control_transfer_lock();
892
+ jQuery('#wpvivid_upload_backup_percent').show();
893
+ jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
894
+ if (value.data.next_resume_time !== 'get next resume time failed.') {
895
+ wpvivid_resume_transfer(index, value.data.next_resume_time);
896
+ }
897
+ else {
898
+ wpvivid_delete_backup_task(index);
899
+ }
900
+ }
901
+ else if (value.status.str === 'no_responds') {
902
+ /*jQuery('#wpvivid_transfer_btn').css({
903
+ 'pointer-events': 'none',
904
+ 'opacity': '0.4'
905
+ });*/
906
+ wpvivid_control_transfer_lock();
907
+ jQuery('#wpvivid_upload_backup_percent').show();
908
+ jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
909
+ migrate_task_need_update = true;
910
+ }
911
+ else if (value.status.str === 'completed') {
912
+ /*jQuery('#wpvivid_transfer_btn').css({
913
+ 'pointer-events': 'auto',
914
+ 'opacity': '1'
915
+ });*/
916
+ wpvivid_control_transfer_unlock();
917
+ jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
918
+ jQuery('#wpvivid_upload_backup_percent').hide();
919
+ migrate_task_need_update = true;
920
+ }
921
+ else if (value.status.str === 'error') {
922
+ /*jQuery('#wpvivid_transfer_btn').css({
923
+ 'pointer-events': 'auto',
924
+ 'opacity': '1'
925
+ });*/
926
+ wpvivid_control_transfer_unlock();
927
+ jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
928
+ jQuery('#wpvivid_upload_backup_percent').hide();
929
+ migrate_task_need_update = true;
930
+ }
931
+ });
932
+ }
933
+ }
934
+ }
935
+ catch (err) {
936
+ alert(err);
937
+ }
938
+ if (!b_need_show) {
939
+ task_recheck_times++;
940
+ if (task_recheck_times < 5) {
941
+ migrate_task_need_update = true;
942
+ }
943
+ }
944
+
945
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
946
+ migrate_task_need_update = true;
947
+ setTimeout(function () {
948
+ wpvivid_manage_upload_task();
949
+ }, 3000);
950
+ });
951
+ }
952
+ }
953
+
954
+ function wpvivid_resume_transfer(backup_id, next_resume_time){
955
+ if(next_resume_time < 0){
956
+ next_resume_time = 0;
957
+ }
958
+ next_resume_time = next_resume_time * 1000;
959
+ setTimeout("wpvivid_activate_migrate_cron()", next_resume_time);
960
+ setTimeout(function(){
961
+ task_recheck_times = 0;
962
+ migrate_task_need_update=true;
963
+ }, next_resume_time);
964
+ }
965
+
966
+ function wpvivid_manage_upload_task()
967
+ {
968
+ if(migrate_task_need_update){
969
+ migrate_task_need_update=false;
970
+ wpvivid_check_upload_runningtask();
971
+ }
972
+ else {
973
+ setTimeout(function () {
974
+ wpvivid_manage_upload_task();
975
+ }, 3000);
976
+ }
977
+ }
978
+
979
+ wpvivid_manage_upload_task();
980
+
981
+ function wpvivid_activate_migrate_cron(){
982
+ var next_get_time = 3 * 60 * 1000;
983
+ jQuery.get(wpvivid_home_url+'/wp-cron.php');
984
+ setTimeout("wpvivid_activate_migrate_cron()", next_get_time);
985
+ setTimeout(function(){
986
+ migrate_task_need_update=true;
987
+ }, 10000);
988
+ }
989
+
990
+ wpvivid_activate_migrate_cron();
991
+
992
+ function switchmigrateTabs(evt,contentName,storage_page_id) {
993
+ // Declare all variables
994
+ var i, tabcontent, tablinks;
995
+
996
+ // Get all elements with class="table-list-content" and hide them
997
+ tabcontent = document.getElementsByClassName("migrate-tab-content");
998
+ for (i = 0; i < tabcontent.length; i++) {
999
+ tabcontent[i].style.display = "none";
1000
+ }
1001
+
1002
+ // Get all elements with class="table-nav-tab" and remove the class "nav-tab-active"
1003
+ tablinks = document.getElementsByClassName("migrate-nav-tab");
1004
+ for (i = 0; i < tablinks.length; i++) {
1005
+ tablinks[i].className = tablinks[i].className.replace(" nav-tab-active", "");
1006
+ }
1007
+
1008
+ // Show the current tab, and add an "storage-menu-active" class to the button that opened the tab
1009
+ document.getElementById(contentName).style.display = "block";
1010
+ evt.currentTarget.className += " nav-tab-active";
1011
+
1012
+ var top = jQuery('#'+storage_page_id).offset().top-jQuery('#'+storage_page_id).height();
1013
+ jQuery('html, body').animate({scrollTop:top}, 'slow');
1014
+ }
1015
+
1016
+ </script>
1017
+ <?php
1018
+ }
1019
+
1020
+ public function add_addon_page_key(){
1021
+ ?>
1022
+ <div id="key-page" class="wrap-tab-content wpvivid_tab_key" name="tab-key" style="display: none;">
1023
+ <div style="padding: 0 0 0 10px">
1024
+ <div style="padding: 0 0 10px 0">
1025
+ <span>In order to allow another site to send a backup to this site, please generate a key below. Once the key is generated, this site is ready to receive a backup from another site. Then, please copy and paste the key in sending site and save it.</span>
1026
+ </div>
1027
+ <strong><?php _e('The key will expire in ', 'wpvivid'); ?></strong>
1028
+ <select id="wpvivid_generate_url_expires" style="margin-bottom: 2px;">
1029
+ <option value="2 hour">2 hours</option>
1030
+ <option selected="selected" value="8 hour">8 hours</option>
1031
+ <option value="24 hour">24 hours</option>
1032
+ <!--<option value="Never">Never</option>-->
1033
+ </select>
1034
+ <div>
1035
+ <input class="button-primary" id="wpvivid_generate_url" type="submit" value="<?php esc_attr_e( 'Generate', 'wpvivid' ); ?>" onclick="wpvivid_click_generate_url();" />
1036
+ </div>
1037
+ <div id="wpvivid_test_generate_url" style="padding-top: 10px;">
1038
+ <textarea id="wpvivid_test_remote_site_url_text" style="width: 100%; height: 140px;"></textarea>
1039
+ </div>
1040
+ </div>
1041
+ </div>
1042
+ <script>
1043
+ jQuery("#wpvivid_test_remote_site_url_text").focus(function() {
1044
+ jQuery(this).select();
1045
+ jQuery(this).mouseup(function() {
1046
+ jQuery(this).unbind("mouseup");
1047
+ return false;
1048
+ });
1049
+ });
1050
+ </script>
1051
+ <?php
1052
+ }
1053
+
1054
+ public function list_tasks()
1055
+ {
1056
+ global $wpvivid_pulgin;
1057
+ $tasks=WPvivid_Setting::get_tasks();
1058
+ $ret=array();
1059
+ $list_tasks=array();
1060
+ foreach ($tasks as $task)
1061
+ {
1062
+ if($task['action']=='transfer')
1063
+ {
1064
+ $backup=new WPvivid_Backup_Task($task['id']);
1065
+ $list_tasks[$task['id']]=$backup->get_backup_task_info($task['id']);
1066
+ if($list_tasks[$task['id']]['task_info']['need_next_schedule']===true){
1067
+ $timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT,array($task['id']));
1068
+
1069
+ if($timestamp===false)
1070
+ {
1071
+ $wpvivid_pulgin->add_monitor_event($task['id'],20);
1072
+ }
1073
+ }
1074
+ if($list_tasks[$task['id']]['task_info']['need_update_last_task']===true){
1075
+ $task_msg = WPvivid_taskmanager::get_task($task['id']);
1076
+ $wpvivid_pulgin->update_last_backup_task($task_msg);
1077
+ }
1078
+ $list_tasks[$task['id']]['progress_html'] = '<div class="action-progress-bar" id="wpvivid_upload_progress_bar">
1079
+ <div class="action-progress-bar-percent" id="wpvivid_upload_progress_bar_percent" style="height:24px;width:' . $list_tasks[$task['id']]['task_info']['backup_percent'] . '"></div>
1080
+ </div>
1081
+ <div id="wpvivid_estimate_backup_info" style="float:left;">
1082
+ <div class="backup-basic-info"><span>' . __('Database Size:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['db_size'] . '</span></div>
1083
+ <div class="backup-basic-info"><span>' . __('File Size:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['file_size'] . '</span></div>
1084
+ </div>
1085
+ <div id="wpvivid_estimate_upload_info" style="float: left;">
1086
+ <div class="backup-basic-info"><span>' . __('Total Size:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['total'] . '</span></div>
1087
+ <div class="backup-basic-info"><span>' . __('Uploaded:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['upload'] . '</span></div>
1088
+ <div class="backup-basic-info"><span>' . __('Speed:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['speed'] . '</span></div>
1089
+ </div>
1090
+ <div style="float: left;">
1091
+ <div class="backup-basic-info"><span>' . __('Network Connection:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['network_connection'] . '</span></div>
1092
+ </div>
1093
+ <div style="clear:both;"></div>
1094
+ <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing">' . $list_tasks[$task['id']]['task_info']['descript'] . '</p></div>
1095
+ <div style="clear: both;"></div>';
1096
+ }
1097
+ }
1098
+ WPvivid_taskmanager::delete_marked_task();
1099
+
1100
+ $backup_success_count=WPvivid_Setting::get_option('wpvivid_transfer_success_count');
1101
+ if(!empty($backup_success_count)){
1102
+ $notice_msg = 'Transfer succeed, you have to refresh the backup list of target site in wpvivid plugin.';
1103
+ $success_notice_html=__('<div class="notice notice-success is-dismissible inline"><p>'.$notice_msg.'</p>
1104
+ <button type="button" class="notice-dismiss" onclick="click_dismiss_notice(this);">
1105
+ <span class="screen-reader-text">Dismiss this notice.</span>
1106
+ </button>
1107
+ </div>');
1108
+ WPvivid_Setting::delete_option('wpvivid_transfer_success_count');
1109
+ }
1110
+ else {
1111
+ $success_notice_html = false;
1112
+ }
1113
+ $ret['transfer_succeed_notice'] = $success_notice_html;
1114
+
1115
+ $backup_error_array=WPvivid_Setting::get_option('wpvivid_transfer_error_array');
1116
+ if(!empty($backup_error_array)){
1117
+ $error_notice_html = array();
1118
+ foreach ($backup_error_array as $key => $value){
1119
+ $notice_msg = 'Transfer failed, '.$value['error_msg'];
1120
+ $error_notice_html['bu_error']['task_id']=$value['task_id'];
1121
+ $error_notice_html['bu_error']['error_msg']=__('<div class="notice notice-error inline"><p>'.$notice_msg.'</p></div>');
1122
+ }
1123
+ WPvivid_Setting::delete_option('wpvivid_transfer_error_array');
1124
+ }
1125
+ else{
1126
+ $error_notice_html = false;
1127
+ }
1128
+ $ret['transfer_error_notice'] = $error_notice_html;
1129
+
1130
+ $ret['transfer']['result']='success';
1131
+ $ret['transfer']['data']=$list_tasks;
1132
+
1133
+ if(!empty($task_ids))
1134
+ {
1135
+ foreach ($task_ids as $id)
1136
+ {
1137
+ WPvivid_Setting::delete_task($id);
1138
+ }
1139
+ }
1140
+
1141
+ echo json_encode($ret);
1142
+ die();
1143
+ }
1144
+
1145
+ function wpvivid_add_tab_upload(){
1146
+ ?>
1147
+ <a href="#" id="wpvivid_tab_upload" class="nav-tab backup-nav-tab" onclick="switchrestoreTabs(event,'page-upload')"><?php _e('Upload', 'wpvivid'); ?></a>
1148
+ <?php
1149
+ }
1150
+
1151
+ function wpvivid_add_page_upload(){
1152
+ $backupdir=WPvivid_Setting::get_backupdir();
1153
+ ?>
1154
+ <div class="backup-tab-content wpvivid_tab_upload" id="page-upload" style="display:none;">
1155
+ <div style="padding: 10px 0 10px 0;">
1156
+ <div style="padding-bottom: 10px;">
1157
+ <span>The backups will be uploaded to <?php echo WP_CONTENT_DIR.'/'.$backupdir; ?> directory.</span>
1158
+ </div>
1159
+ <div style="padding-bottom: 10px;">
1160
+ <span>Note: The files you want to upload must be a backup created by WPvivid backup plugin. Make sure that uploading every part of a backup to the directory if the backup is split into many parts</span>
1161
+ </div>
1162
+ <?php
1163
+ Wpvivid_BackupUploader::upload_meta_box();
1164
+ ?>
1165
+ </div>
1166
+ </div>
1167
+ <?php
1168
+ }
1169
+
1170
+ function wpvivid_rescan_backup_list(){
1171
+ ?>
1172
+ <div style="padding: 0 0 10px 0;">
1173
+ <?php
1174
+ Wpvivid_BackupUploader::rescan_local_folder();
1175
+ ?>
1176
+ </div>
1177
+ <?php
1178
+ }
1179
+ }
includes/class-wpvivid-mysqldump.php CHANGED
@@ -153,7 +153,7 @@ class WPvivid_Mysqldump
153
 
154
  $pdoSettingsDefault = array(
155
  PDO::ATTR_PERSISTENT => true,
156
- PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
157
  PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
158
  );
159
 
@@ -338,6 +338,20 @@ class WPvivid_Mysqldump
338
  // Write some basic info to output file
339
  $this->compressManager->write($this->getDumpFileHeader());
340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  // Store server settings and use sanner defaults to dump
342
  $this->compressManager->write(
343
  $this->typeAdapter->backup_parameters($this->dumpSettings)
@@ -556,7 +570,6 @@ class WPvivid_Mysqldump
556
  // Exporting tables one by one
557
  $i=0;
558
  $i_step=0;
559
-
560
  if($this->task_id!=='')
561
  {
562
  $options_name[]='backup_options';
@@ -564,11 +577,21 @@ class WPvivid_Mysqldump
564
  $options=WPvivid_taskmanager::get_task_options($this->task_id,$options_name);
565
  if($options['ismerge'])
566
  {
567
- $i_step=intval(1/(sizeof($options['backup_options']['backup']['backup_type'])+1)*100);
 
 
 
 
 
568
  }
569
  else
570
  {
571
- $i_step=intval(1/sizeof($options['backup_options']['backup']['backup_type'])*100);
 
 
 
 
 
572
  }
573
  }
574
 
@@ -582,7 +605,8 @@ class WPvivid_Mysqldump
582
  if($this->task_id!=='')
583
  {
584
  $message='Preparing to dump table '.$table;
585
- $this->log->WriteLog($message,'notice');
 
586
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
587
  }
588
 
@@ -695,6 +719,7 @@ class WPvivid_Mysqldump
695
  $this->typeAdapter->drop_table($tableName)
696
  );
697
  }
 
698
  $this->compressManager->write(
699
  $this->typeAdapter->create_table($r, $this->dumpSettings)
700
  );
@@ -931,7 +956,19 @@ class WPvivid_Mysqldump
931
 
932
  $colStmt = $this->getColumnStmt($tableName);
933
 
934
- $stmt = "SELECT " . implode(",", $colStmt) . " FROM `$tableName`";
 
 
 
 
 
 
 
 
 
 
 
 
935
 
936
  if ($this->dumpSettings['where']) {
937
  $stmt .= " WHERE {$this->dumpSettings['where']}";
@@ -940,12 +977,6 @@ class WPvivid_Mysqldump
940
  $resultSet = $this->query($stmt);
941
  $resultSet->setFetchMode(PDO::FETCH_ASSOC);
942
 
943
- if($this->task_id!=='')
944
- {
945
- $backup_db=WPvivid_taskmanager::get_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB);
946
- $sum=$backup_db['db_info'][$tableName]['Rows'];
947
- }
948
-
949
  $i=0;
950
  $i_check_cancel=0;
951
  $count=0;
@@ -996,7 +1027,7 @@ class WPvivid_Mysqldump
996
  global $wpvivid_pulgin;
997
  $wpvivid_pulgin->check_cancel_backup($this->task_id);
998
  }
999
- $message='Dumping table '.$tableName.', rows dumped: '.$count.' of '.$sum.' rows.';
1000
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
1001
  }
1002
  }
153
 
154
  $pdoSettingsDefault = array(
155
  PDO::ATTR_PERSISTENT => true,
156
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
157
  PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
158
  );
159
 
338
  // Write some basic info to output file
339
  $this->compressManager->write($this->getDumpFileHeader());
340
 
341
+ $this->compressManager->write('/* # site_url: '.site_url().' */;'.PHP_EOL);
342
+ $this->compressManager->write('/* # home_url: '.home_url().' */;'.PHP_EOL);
343
+ $this->compressManager->write('/* # content_url: '.content_url().' */;'.PHP_EOL);
344
+ $upload_dir = wp_upload_dir();
345
+ $this->compressManager->write('/* # upload_url: '.$upload_dir['baseurl'].' */;'.PHP_EOL);
346
+ global $wpdb;
347
+ if (is_multisite() && !defined('MULTISITE'))
348
+ {
349
+ $prefix = $wpdb->base_prefix;
350
+ } else {
351
+ $prefix = $wpdb->get_blog_prefix(0);
352
+ }
353
+ $this->compressManager->write('/* # table_prefix: '.$prefix.' */;'.PHP_EOL.PHP_EOL.PHP_EOL);
354
+
355
  // Store server settings and use sanner defaults to dump
356
  $this->compressManager->write(
357
  $this->typeAdapter->backup_parameters($this->dumpSettings)
570
  // Exporting tables one by one
571
  $i=0;
572
  $i_step=0;
 
573
  if($this->task_id!=='')
574
  {
575
  $options_name[]='backup_options';
577
  $options=WPvivid_taskmanager::get_task_options($this->task_id,$options_name);
578
  if($options['ismerge'])
579
  {
580
+ if(isset($options['backup_options']['backup']['backup_type'])) {
581
+ $i_step = intval(1 / (sizeof($options['backup_options']['backup']['backup_type']) + 1) * 100);
582
+ }
583
+ else{
584
+ $i_step = intval(1 / (sizeof($options['backup_options']['backup']) + 1) * 100);
585
+ }
586
  }
587
  else
588
  {
589
+ if(isset($options['backup_options']['backup']['backup_type'])) {
590
+ $i_step = intval(1 / sizeof($options['backup_options']['backup']['backup_type']) * 100);
591
+ }
592
+ else{
593
+ $i_step = intval(1 / sizeof($options['backup_options']['backup']) * 100);
594
+ }
595
  }
596
  }
597
 
605
  if($this->task_id!=='')
606
  {
607
  $message='Preparing to dump table '.$table;
608
+ global $wpvivid_pulgin;
609
+ $wpvivid_pulgin->wpvivid_log->WriteLog($message,'notice');
610
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
611
  }
612
 
719
  $this->typeAdapter->drop_table($tableName)
720
  );
721
  }
722
+
723
  $this->compressManager->write(
724
  $this->typeAdapter->create_table($r, $this->dumpSettings)
725
  );
956
 
957
  $colStmt = $this->getColumnStmt($tableName);
958
 
959
+ global $wpdb;
960
+ $prefix=$wpdb->base_prefix;
961
+
962
+ if(substr($tableName, strlen($prefix))=='options')
963
+ {
964
+ $stmt = "SELECT " . implode(",", $colStmt) . " FROM `$tableName` WHERE option_name !='wpvivid_task_list'";
965
+ }
966
+ else
967
+ {
968
+ $stmt = "SELECT " . implode(",", $colStmt) . " FROM `$tableName`";
969
+ }
970
+
971
+
972
 
973
  if ($this->dumpSettings['where']) {
974
  $stmt .= " WHERE {$this->dumpSettings['where']}";
977
  $resultSet = $this->query($stmt);
978
  $resultSet->setFetchMode(PDO::FETCH_ASSOC);
979
 
 
 
 
 
 
 
980
  $i=0;
981
  $i_check_cancel=0;
982
  $count=0;
1027
  global $wpvivid_pulgin;
1028
  $wpvivid_pulgin->check_cancel_backup($this->task_id);
1029
  }
1030
+ $message='Dumping table '.$tableName.', rows dumped: '.$count.' rows.';
1031
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
1032
  }
1033
  }
includes/class-wpvivid-remote-collection.php CHANGED
@@ -14,6 +14,7 @@ require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-google-dr
14
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-dropbox.php';
15
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-one-drive.php';
16
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-s3compat.php';
 
17
 
18
  class WPvivid_Remote_collection
19
  {
@@ -109,6 +110,7 @@ class WPvivid_Remote_collection
109
  $remote_collection['dropbox']='WPvivid_Dropbox';
110
  $remote_collection[WPVIVID_REMOTE_ONEDRIVE] = 'Wpvivid_one_drive';
111
  $remote_collection[WPVIVID_REMOTE_S3COMPAT] = 'Wpvivid_S3Compat';
 
112
  return $remote_collection;
113
  }
114
 
14
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-dropbox.php';
15
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-one-drive.php';
16
  require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-s3compat.php';
17
+ require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-send-to-site.php';
18
 
19
  class WPvivid_Remote_collection
20
  {
110
  $remote_collection['dropbox']='WPvivid_Dropbox';
111
  $remote_collection[WPVIVID_REMOTE_ONEDRIVE] = 'Wpvivid_one_drive';
112
  $remote_collection[WPVIVID_REMOTE_S3COMPAT] = 'Wpvivid_S3Compat';
113
+ $remote_collection[WPVIVID_REMOTE_SEND_TO_SITE] = 'WPvivid_Send_to_site';
114
  return $remote_collection;
115
  }
116
 
includes/class-wpvivid-restore-data.php CHANGED
@@ -67,30 +67,84 @@ class WPvivid_restore_data
67
  WPvivid_tools::deldir(dirname($this -> rollback_file),'',true);
68
  }
69
 
70
- public function init_restore_data($backup_id)
71
  {
72
- $data = require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-restore-template.php';
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  $this->restore_log=new WPvivid_Log();
75
  $this->restore_log->CreateLogFile($this->restore_log_file,'has_folder','restore');
76
 
77
  $data['task_id'] = $backup_id;
 
 
 
 
 
 
 
 
78
  $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
79
  $data['backup_data'] = $backup;
80
 
81
- $types = array();
82
- foreach ($backup['backup']['data']['type'] as $item){
83
- $types[] = $item['type_name'];
84
- }
85
- foreach ($data['data'] as $key => $value){
86
- if(!in_array($key,$types)){
87
- WPvivid_tools::delValueByKey($key,$data['data']);
 
 
 
 
 
 
88
  }
 
89
  }
90
 
91
  WPvivid_tools::file_put_array($data,$this->restore_data_file);
92
  $this->restore_cache=$data;
93
-
94
  $rollback_data = require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback-template.php';
95
  $rollback_data['task_id'] = $backup_id;
96
  WPvivid_tools::deldir(dirname($this -> rollback_file));
@@ -98,6 +152,15 @@ class WPvivid_restore_data
98
  WPvivid_tools::file_put_array($rollback_data,$this->rollback_file);
99
  }
100
 
 
 
 
 
 
 
 
 
 
101
  public function init_rollback_data()
102
  {
103
  $this->rollback_log=new WPvivid_Log();
@@ -119,7 +182,7 @@ class WPvivid_restore_data
119
  }
120
  else
121
  {
122
- return $this->restore_cache['state'];
123
  }
124
  }
125
 
@@ -135,7 +198,7 @@ class WPvivid_restore_data
135
  }
136
  else
137
  {
138
- return $this->rollback_cache['state'];
139
  }
140
  }
141
 
@@ -190,6 +253,15 @@ class WPvivid_restore_data
190
  $this->restore_log->OpenLogFile($this->restore_log_file,'has_folder');
191
  }
192
 
 
 
 
 
 
 
 
 
 
193
  $this->restore_log->WriteLog($message,$type);
194
  }
195
 
@@ -286,31 +358,24 @@ class WPvivid_restore_data
286
  $this->restore_cache=WPvivid_tools::file_get_array($this->restore_data_file);
287
  }
288
 
289
- foreach($this->restore_cache['data'] as $task_type => $task)
290
  {
291
- if($task['state'] === WPVIVID_RESTORE_WAIT)
292
  {
293
- foreach ($this->restore_cache['backup_data']['backup']['data']['type'] as $backup_type)
294
- {
295
- if ($backup_type['type_name'] == $task_type)
296
- {
297
- $next_task=$backup_type;
298
- break;
299
- }
300
- }
301
-
302
- $this->restore_cache['state'] = WPVIVID_RESTORE_RUNNING;
303
- $this->restore_cache['data'][$task_type]['state'] = WPVIVID_RESTORE_RUNNING;
304
- $this->restore_cache['data'][$task_type]['time']['start'] = time();
305
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
306
  break;
307
  }
308
- else if($task['state'] === WPVIVID_RESTORE_RUNNING)
309
  {
310
  $next_task=WPVIVID_RESTORE_RUNNING;
311
  break;
312
  }
313
- else if($task['state'] === WPVIVID_RESTORE_COMPLETED)
314
  {
315
  continue;
316
  }
@@ -329,21 +394,21 @@ class WPvivid_restore_data
329
 
330
  foreach($this->rollback_cache['data'] as $task_type => $task)
331
  {
332
- if($task['state'] === WPVIVID_RESTORE_READY)
333
  {
334
  $next_task=$task;
335
- $this->rollback_cache['state'] = WPVIVID_RESTORE_RUNNING;
336
- $this->rollback_cache['data'][$task_type]['state'] = WPVIVID_RESTORE_RUNNING;
337
  $this->rollback_cache['data'][$task_type]['time']['start'] = time();
338
  WPvivid_tools::file_put_array($this->rollback_cache,$this->rollback_data_file);
339
  break;
340
  }
341
- else if($task['state'] === WPVIVID_RESTORE_RUNNING)
342
  {
343
  $next_task=WPVIVID_RESTORE_RUNNING;
344
  break;
345
  }
346
- else if($task['state'] === WPVIVID_RESTORE_COMPLETED)
347
  {
348
  continue;
349
  }
@@ -358,12 +423,12 @@ class WPvivid_restore_data
358
  {
359
  $this->restore_cache=WPvivid_tools::file_get_array($this->restore_data_file);
360
  }
361
- $this->restore_cache['state'] = WPVIVID_RESTORE_ERROR;
362
  $this->restore_cache['error'] = $error;
363
  if($error_task!='')
364
  {
365
  $this->restore_cache['data'][$error_task]['time']['end'] = time();
366
- $this->restore_cache['data'][$error_task]['state'] = WPVIVID_RESTORE_ERROR;
367
  $this->restore_cache['data'][$error_task]['return'] = $error;
368
  $this->restore_cache['error_task'] = $error_task;
369
  if(!empty($table))
@@ -382,12 +447,12 @@ class WPvivid_restore_data
382
  {
383
  $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
384
  }
385
- $this->rollback_cache['state'] = WPVIVID_RESTORE_ERROR;
386
  $this->rollback_cache['error'] = $error;
387
  if($error_task!='')
388
  {
389
  $this->rollback_cache['data'][$error_task]['time']['end'] = time();
390
- $this->rollback_cache['data'][$error_task]['state'] = WPVIVID_RESTORE_ERROR;
391
  $this->rollback_cache['data'][$error_task]['return'] = $error;
392
  $this->rollback_cache['error_task'] = $error_task;
393
  if(!empty($table))
@@ -407,7 +472,7 @@ class WPvivid_restore_data
407
  $this->restore_cache=WPvivid_tools::file_get_array($this->restore_data_file);
408
  }
409
 
410
- $this->restore_cache['state'] = $status;
411
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
412
  }
413
 
@@ -418,10 +483,23 @@ class WPvivid_restore_data
418
  $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
419
  }
420
 
421
- $this->rollback_cache['state'] = $status;
422
  WPvivid_tools::file_put_array($this->rollback_cache,$this->rollback_data_file);
423
  }
424
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  public function update_sub_task_completed($task_type,$return,$table=array())
426
  {
427
  if($this->restore_cache===false)
@@ -430,9 +508,9 @@ class WPvivid_restore_data
430
  }
431
 
432
  $this->restore_cache['data'][$task_type]['time']['end'] = time();
433
- $this->restore_cache['data'][$task_type]['state'] = WPVIVID_RESTORE_COMPLETED;
434
  $this->restore_cache['data'][$task_type]['return'] = $return;
435
- $this->restore_cache['state'] = WPVIVID_RESTORE_RUNNING;
436
  if(!empty($table)){
437
  $this->restore_cache['data'][$task_type]['table']['succeed'] = empty($table['succeed'])?0:$table['succeed'];
438
  $this->restore_cache['data'][$task_type]['table']['failed'] = empty($table['failed'])?0:$table['failed'];
@@ -449,9 +527,9 @@ class WPvivid_restore_data
449
  }
450
 
451
  $this->rollback_cache['data'][$task_type]['time']['end'] = time();
452
- $this->rollback_cache['data'][$task_type]['state'] = WPVIVID_RESTORE_COMPLETED;
453
  $this->rollback_cache['data'][$task_type]['return'] = $return;
454
- $this->rollback_cache['state'] = WPVIVID_RESTORE_RUNNING;
455
  if(!empty($table)){
456
  $this->rollback_cache['data'][$task_type]['table']['succeed'] = empty($table['succeed'])?0:$table['succeed'];
457
  $this->rollback_cache['data'][$task_type]['table']['failed'] = empty($table['failed'])?0:$table['failed'];
@@ -464,7 +542,7 @@ class WPvivid_restore_data
464
  {
465
  $rollback_data=WPvivid_tools::file_get_array($this->rollback_file);
466
 
467
- $rollback_data['data'][$type_name]['state'] = WPVIVID_RESTORE_READY;
468
  $rollback_data['data'][$type_name]['task_id'] = $task_id;
469
  $rollback_data['data'][$type_name]['type_name'] = $type_name;
470
  $rollback_data['data'][$type_name]['data'] = $data;
67
  WPvivid_tools::deldir(dirname($this -> rollback_file),'',true);
68
  }
69
 
70
+ public function delete_temp_files()
71
  {
72
+ $backup=WPvivid_Backuplist::get_backuplist_by_key($this->restore_cache['task_id']);
73
+ $backup_item=new WPvivid_Backup_Item($backup);
74
 
75
+ foreach($this->restore_cache['restore_tasks'] as $index => $task)
76
+ {
77
+ if(isset($task['option'])&&isset($task['option']['has_child']))
78
+ {
79
+ $has_child=1;
80
+ }
81
+ else
82
+ {
83
+ $option=$backup_item->get_file_info($task['files'][0]);
84
+ if(isset($option['has_child']))
85
+ {
86
+ $has_child=1;
87
+ }
88
+ else
89
+ {
90
+ $has_child=0;
91
+ }
92
+ }
93
+
94
+ if($has_child)
95
+ {
96
+ foreach ($task['files'] as $file)
97
+ {
98
+ $temp_files=$backup_item->get_child_files($file);
99
+ foreach ($temp_files as $delete_file)
100
+ {
101
+ $path= WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$delete_file['file_name'];
102
+ $this->write_log('clean file:'.$path,'notice');
103
+ @unlink($path);
104
+ }
105
+ }
106
+ break;
107
+ }
108
+ }
109
+ }
110
+
111
+ public function init_restore_data($backup_id,$restore_options=array())
112
+ {
113
+ //$data = require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-restore-template.php';
114
  $this->restore_log=new WPvivid_Log();
115
  $this->restore_log->CreateLogFile($this->restore_log_file,'has_folder','restore');
116
 
117
  $data['task_id'] = $backup_id;
118
+ $data['status']= WPVIVID_RESTORE_INIT;
119
+ $data['error']='';
120
+ $data['error_task']='';
121
+
122
+ $data['restore_options']=$restore_options;
123
+ //$data['restore_options']['skip_backup_old_site']=1;
124
+ //$data['restore_options']['skip_backup_old_database']=1;
125
+ //$data['restore_options']['is_migrate']=1;
126
  $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
127
  $data['backup_data'] = $backup;
128
 
129
+ $backup_item=new WPvivid_Backup_Item($backup);
130
+
131
+ $packages=$backup_item->get_backup_packages();
132
+
133
+ foreach ($packages as $index=>$package)
134
+ {
135
+ $data['restore_tasks'][$index]['files']=$package['files'];
136
+ $data['restore_tasks'][$index]['status']=WPVIVID_RESTORE_WAIT;
137
+ $data['restore_tasks'][$index]['result']=array();
138
+ $data['restore_tasks'][$index]['option']=array();
139
+ if(isset($package['option']))
140
+ {
141
+ $data['restore_tasks'][$index]['option']=$package['option'];
142
  }
143
+ $data['restore_tasks'][$index]['option']=array_merge($restore_options, $data['restore_tasks'][$index]['option']);
144
  }
145
 
146
  WPvivid_tools::file_put_array($data,$this->restore_data_file);
147
  $this->restore_cache=$data;
 
148
  $rollback_data = require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback-template.php';
149
  $rollback_data['task_id'] = $backup_id;
150
  WPvivid_tools::deldir(dirname($this -> rollback_file));
152
  WPvivid_tools::file_put_array($rollback_data,$this->rollback_file);
153
  }
154
 
155
+ public function get_restore_option()
156
+ {
157
+ if($this->restore_cache===false)
158
+ {
159
+ $this->restore_cache=WPvivid_tools::file_get_array($this->restore_data_file);
160
+ }
161
+ return $this->restore_cache['restore_options'];
162
+ }
163
+
164
  public function init_rollback_data()
165
  {
166
  $this->rollback_log=new WPvivid_Log();
182
  }
183
  else
184
  {
185
+ return $this->restore_cache['status'];
186
  }
187
  }
188
 
198
  }
199
  else
200
  {
201
+ return $this->rollback_cache['status'];
202
  }
203
  }
204
 
253
  $this->restore_log->OpenLogFile($this->restore_log_file,'has_folder');
254
  }
255
 
256
+ clearstatcache();
257
+ if(filesize($this->restore_log_file)>4*1024*1024)
258
+ {
259
+ $this->restore_log->CloseFile();
260
+ unlink($this->restore_log_file);
261
+ $this->restore_log=null;
262
+ $this->restore_log=new WPvivid_Log();
263
+ $this->restore_log->OpenLogFile($this->restore_log_file,'has_folder');
264
+ }
265
  $this->restore_log->WriteLog($message,$type);
266
  }
267
 
358
  $this->restore_cache=WPvivid_tools::file_get_array($this->restore_data_file);
359
  }
360
 
361
+ foreach($this->restore_cache['restore_tasks'] as $index => $task)
362
  {
363
+ if($task['status'] === WPVIVID_RESTORE_WAIT)
364
  {
365
+ $next_task=$task;
366
+ $next_task['index']=$index;
367
+ $this->restore_cache['status'] = WPVIVID_RESTORE_RUNNING;
368
+ $this->restore_cache['restore_tasks'][$index]['status'] = WPVIVID_RESTORE_RUNNING;
369
+ $this->restore_cache['restore_tasks'][$index]['time']['start'] = time();
 
 
 
 
 
 
 
370
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
371
  break;
372
  }
373
+ else if($task['status'] === WPVIVID_RESTORE_RUNNING)
374
  {
375
  $next_task=WPVIVID_RESTORE_RUNNING;
376
  break;
377
  }
378
+ else if($task['status'] === WPVIVID_RESTORE_COMPLETED)
379
  {
380
  continue;
381
  }
394
 
395
  foreach($this->rollback_cache['data'] as $task_type => $task)
396
  {
397
+ if($task['status'] === WPVIVID_RESTORE_READY)
398
  {
399
  $next_task=$task;
400
+ $this->rollback_cache['status'] = WPVIVID_RESTORE_RUNNING;
401
+ $this->rollback_cache['data'][$task_type]['status'] = WPVIVID_RESTORE_RUNNING;
402
  $this->rollback_cache['data'][$task_type]['time']['start'] = time();
403
  WPvivid_tools::file_put_array($this->rollback_cache,$this->rollback_data_file);
404
  break;
405
  }
406
+ else if($task['status'] === WPVIVID_RESTORE_RUNNING)
407
  {
408
  $next_task=WPVIVID_RESTORE_RUNNING;
409
  break;
410
  }
411
+ else if($task['status'] === WPVIVID_RESTORE_COMPLETED)
412
  {
413
  continue;
414
  }
423
  {
424
  $this->restore_cache=WPvivid_tools::file_get_array($this->restore_data_file);
425
  }
426
+ $this->restore_cache['status'] = WPVIVID_RESTORE_ERROR;
427
  $this->restore_cache['error'] = $error;
428
  if($error_task!='')
429
  {
430
  $this->restore_cache['data'][$error_task]['time']['end'] = time();
431
+ $this->restore_cache['data'][$error_task]['status'] = WPVIVID_RESTORE_ERROR;
432
  $this->restore_cache['data'][$error_task]['return'] = $error;
433
  $this->restore_cache['error_task'] = $error_task;
434
  if(!empty($table))
447
  {
448
  $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
449
  }
450
+ $this->rollback_cache['status'] = WPVIVID_RESTORE_ERROR;
451
  $this->rollback_cache['error'] = $error;
452
  if($error_task!='')
453
  {
454
  $this->rollback_cache['data'][$error_task]['time']['end'] = time();
455
+ $this->rollback_cache['data'][$error_task]['status'] = WPVIVID_RESTORE_ERROR;
456
  $this->rollback_cache['data'][$error_task]['return'] = $error;
457
  $this->rollback_cache['error_task'] = $error_task;
458
  if(!empty($table))
472
  $this->restore_cache=WPvivid_tools::file_get_array($this->restore_data_file);
473
  }
474
 
475
+ $this->restore_cache['status'] = $status;
476
  WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
477
  }
478
 
483
  $this->rollback_cache=WPvivid_tools::file_get_array($this->rollback_data_file);
484
  }
485
 
486
+ $this->rollback_cache['status'] = $status;
487
  WPvivid_tools::file_put_array($this->rollback_cache,$this->rollback_data_file);
488
  }
489
 
490
+ public function update_sub_task($task_index,$result)
491
+ {
492
+ if($this->restore_cache===false)
493
+ {
494
+ $this->restore_cache=WPvivid_tools::file_get_array($this->restore_data_file);
495
+ }
496
+
497
+ $this->restore_cache['restore_tasks'][$task_index]['result']=$result;
498
+ $this->restore_cache['restore_tasks'][$task_index]['status']=$result['result'];
499
+ $this->restore_cache['data'][$task_index]['time']['end'] = time();
500
+ WPvivid_tools::file_put_array($this->restore_cache,$this->restore_data_file);
501
+ }
502
+
503
  public function update_sub_task_completed($task_type,$return,$table=array())
504
  {
505
  if($this->restore_cache===false)
508
  }
509
 
510
  $this->restore_cache['data'][$task_type]['time']['end'] = time();
511
+ $this->restore_cache['data'][$task_type]['status'] = WPVIVID_RESTORE_COMPLETED;
512
  $this->restore_cache['data'][$task_type]['return'] = $return;
513
+ $this->restore_cache['status'] = WPVIVID_RESTORE_RUNNING;
514
  if(!empty($table)){
515
  $this->restore_cache['data'][$task_type]['table']['succeed'] = empty($table['succeed'])?0:$table['succeed'];
516
  $this->restore_cache['data'][$task_type]['table']['failed'] = empty($table['failed'])?0:$table['failed'];
527
  }
528
 
529
  $this->rollback_cache['data'][$task_type]['time']['end'] = time();
530
+ $this->rollback_cache['data'][$task_type]['status'] = WPVIVID_RESTORE_COMPLETED;
531
  $this->rollback_cache['data'][$task_type]['return'] = $return;
532
+ $this->rollback_cache['status'] = WPVIVID_RESTORE_RUNNING;
533
  if(!empty($table)){
534
  $this->rollback_cache['data'][$task_type]['table']['succeed'] = empty($table['succeed'])?0:$table['succeed'];
535
  $this->rollback_cache['data'][$task_type]['table']['failed'] = empty($table['failed'])?0:$table['failed'];
542
  {
543
  $rollback_data=WPvivid_tools::file_get_array($this->rollback_file);
544
 
545
+ $rollback_data['data'][$type_name]['status'] = WPVIVID_RESTORE_READY;
546
  $rollback_data['data'][$type_name]['task_id'] = $task_id;
547
  $rollback_data['data'][$type_name]['type_name'] = $type_name;
548
  $rollback_data['data'][$type_name]['data'] = $data;
includes/class-wpvivid-restore-database.php CHANGED
@@ -5,206 +5,1031 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
5
  }
6
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-zipclass.php';
7
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup-database.php';
 
8
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-setting.php';
9
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback.php';
10
  class WPvivid_RestoreDB
11
  {
12
- private $restore_data;
13
- private $type_name;
14
  private $privileges;
 
15
 
16
- public function restore($type_name,$path,$files)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  {
18
- $this->restore_data=new WPvivid_restore_data();
19
- $this -> type_name = $type_name;
20
- $zip = new WPvivid_ZipClass();
21
- $basename = $zip -> getBasename($files[0]['file_name']);
22
- $task_id = explode('_',$basename);
23
- $task_id = $task_id[0];
24
- $expath = $path.DIRECTORY_SEPARATOR.'temp-'.$basename;
25
- $databases = array();
26
 
27
- foreach ($files as $file){
28
- $databases[] = $path.DIRECTORY_SEPARATOR.$file['file_name'];
29
- }
30
- $this->restore_data->write_log('Unzip sql file.','notice');
31
- $result = $zip -> zipextract($expath,$databases);
32
- if($result['result'] !== WPVIVID_SUCCESS){
33
- return $result;
34
- }
35
- $file_path = $expath.DIRECTORY_SEPARATOR.$basename.'.sql';
36
- if(file_exists($file_path))
37
  {
38
- $this->restore_data->write_log('Backing up current site\'s database.','notice');
39
- $temp_sql = WPvivid_Setting::export_setting_to_json();
40
- $temp_sql_file = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.$type_name.DIRECTORY_SEPARATOR.$basename.'.';
41
- @mkdir(dirname($temp_sql_file));
42
- $backup_database = new WPvivid_Backup_Database();
 
 
 
 
 
 
 
43
 
44
- $res = explode(':',DB_HOST);
45
- $db_host = $res[0];
46
- $db_port = empty($res[1])?'':$res[1];
47
- if(!empty($db_port))
48
- $db_host = $db_host.':'.$db_port;
49
- try{
50
- $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
51
- }catch (Exception $e)
52
- {
53
- if(!empty($db_port)){
54
- $db_host = $res[0];
55
- $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
56
- }
57
- if(empty($pdo) || !$pdo){
58
- return array('result' => 'WPVIVID_FAILED','error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
59
- }
60
- }
61
-
62
- $privileges = $backup_database -> check_privilege('restore',$pdo);
63
- if($privileges['result'] == WPVIVID_FAILED){
64
- return $privileges;
65
- }else{
66
- $privileges = $privileges['data'];
67
- $this -> privileges = $privileges;
68
- }
69
- $options = array();
70
- foreach ($privileges as $key => $value){
71
- if($value == 0){
72
- $options[] = $key;
73
- }
74
- }
75
- if(!empty($options))
76
- $this->restore_data->write_log('The lack of optional database privileges including '.implode(',',$options),'notice');
77
-
78
- $result = $backup_database ->backup_database(array('path'=>$temp_sql_file,'log'=>$this->restore_data->get_log_handle()));
79
- if($result['result'] != WPVIVID_SUCCESS)
80
- {
81
- return array('result' => 'failed','error' => $result['error']);
82
- }else{
83
- $data = array();
84
- $data['file'] = $temp_sql_file.'sql';
85
- $this->restore_data->set_rollback_data($type_name,$task_id,$data);
86
- }
87
- $data = array();
88
- $data['data']['file'] = $file_path;
89
- $str = $this ->restore_db($data);
90
- if($str['result'] == WPVIVID_SUCCESS)
91
- {
92
- WPvivid_Setting::import_json_to_setting($temp_sql);
93
- return $str;
94
- }else {
95
- return $str;
96
- }
97
- }else{
98
  return array('result'=>'failed','error'=>'Database\'s .sql file not found. Please try again.');
99
  }
100
  }
101
 
102
- public function restore_db($data)
103
  {
104
- $this->restore_data->write_log('Start restoring database.','notice');
105
- $File = $data['data']['file'];
106
- if(!file_exists($File)){
107
- return array('result'=>'failed','error'=>'Database\'s .sql file not found. Please try again.');
108
- }
109
-
110
  $res = explode(':',DB_HOST);
111
  $db_host = $res[0];
112
  $db_port = empty($res[1])?'':$res[1];
113
  if(!empty($db_port))
114
  $db_host = $db_host.':'.$db_port;
115
- try{
116
- $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
117
- }catch (Exception $e)
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  {
119
- if(!empty($db_port)){
 
120
  $db_host = $res[0];
121
- $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
 
122
  }
123
- if(empty($pdo) || !$pdo){
124
- return array('result' => 'WPVIVID_FAILED','error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
 
 
 
 
 
 
125
  }
126
  }
 
 
 
 
 
 
 
 
 
127
 
128
- $pdo -> query('SET NAMES utf8');
129
- $result = $this->restore_db_file($pdo,$File);
130
- unset($pdo);
131
- return $result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  }
133
 
134
- public function restore_db_file($pdo,$File){
135
- global $wpdb;
136
- $prefix = $wpdb->base_prefix;
137
- $query = '';
138
- $tables = array();
139
- $errortables = array();
140
- $sqlhandle = fopen($File,'r');
141
 
 
142
 
143
- $success_num = 0;
144
- $error_num = 0;
145
- $line_num = 0;
146
- $error_info = array();
 
 
147
 
148
- $res = $pdo -> query('SELECT @@SESSION.sql_mode') -> fetchAll();
149
- $sql_mod = $res[0][0];
150
- $temp_sql_mode = str_replace('NO_ENGINE_SUBSTITUTION','',$sql_mod);
151
- $temp_sql_mode = 'NO_AUTO_VALUE_ON_ZERO,'.$temp_sql_mode;
152
- $pdo -> query('SET SESSION sql_mode = "'.$temp_sql_mode.'"');
 
 
 
153
 
154
- $data = $pdo -> query('select * from information_schema.tables WHERE table_schema = "'.DB_NAME.'"') -> fetchAll();
155
- foreach ($data as $item){
156
- if(preg_match('#'.$prefix.'#i',$item['TABLE_NAME'])){
157
- $tables[] = $item['TABLE_NAME'];
158
- }
 
 
159
  }
160
 
161
- if($tables){
162
- foreach ($tables as $table){
163
- if(!$pdo -> query('DROP TABLE '.$table))
164
- return array('result'=>'failed','error' =>$pdo ->errorInfo());
165
- }
166
- }else{
167
- return array('result'=>'failed','error'=>$pdo->errorInfo());
168
  }
169
 
170
- while(!feof($sqlhandle)) {
171
- $line = fgets($sqlhandle);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  $line_num ++;
173
  $startWith = substr(trim($line), 0 ,2);
174
  $endWith = substr(trim($line), -1 ,1);
175
-
176
- if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//') {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  continue;
178
  }
179
 
180
  $query = $query . $line;
181
- if ($endWith == ';') {
182
- if(preg_match('#^\\s*LOCK TABLES#',$query) && $this -> privileges['LOCK TABLES'] == 0){
183
- $this->restore_data->write_log('The lack of LOCK TABLES privilege, the backup will skip LOCK TABLES to continue.Notice at Line:'.$line_num,'notice');
184
- }else{
185
- if(!$result = $pdo -> query($query)){
186
- $error_num ++;
187
- $data = array('line'=>$line_num,'sql'=>$query,'error'=>$pdo->errorInfo());
188
- $this->restore_data->write_log('Restore '.basename($File).' error at line '.$line_num.','.PHP_EOL.'errorinfo: ['.implode('][',$pdo->errorInfo()).']','Warning');
189
- $error_info[] = $data;
190
- $query= '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
  continue;
192
  }
193
- $success_num ++;
194
  }
195
- $query= '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  }
197
  }
198
- fclose($sqlhandle);
199
- $pdo -> query('SET SESSION sql_mode = "'.$sql_mod.'"');
200
 
201
- if($error_num > 0)
 
 
 
 
 
 
 
 
 
 
202
  {
203
- $this->restore_data->write_log('Database restore error, '.$success_num.' succeeded, '.$error_num.' failed.','Warning');
204
- }else{
205
- $this->restore_data->write_log('Restore database successfully.','notice');
 
 
206
  }
207
 
208
- return array('result'=>WPVIVID_SUCCESS,'meta'=>$error_info,'table'=>array('succeed'=>$success_num,'failed'=>$error_num));
209
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  }
5
  }
6
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-zipclass.php';
7
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup-database.php';
8
+ require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-backup-site.php';
9
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-setting.php';
10
  require_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback.php';
11
  class WPvivid_RestoreDB
12
  {
 
 
13
  private $privileges;
14
+ private $max_allow_packet;
15
 
16
+ private $support_engines;
17
+ private $support_charsets;
18
+ private $support_collates;
19
+
20
+ private $default_engines;
21
+ private $default_charsets;
22
+ private $default_collates;
23
+ private $old_prefix;
24
+ private $new_prefix;
25
+
26
+ private $old_site_url;
27
+ private $old_home_url;
28
+ private $old_content_url;
29
+ private $old_upload_url;
30
+
31
+ private $new_site_url;
32
+ private $new_home_url;
33
+ private $new_content_url;
34
+ private $new_upload_url;
35
+
36
+ private $current_setting;
37
+
38
+ private $db;
39
+
40
+ private $skip_query;
41
+
42
+ private $replacing_table;
43
+
44
+ public function restore($path,$sql_file,$options)
45
  {
46
+ add_filter('wpvivid_restore_db_skip_replace_tables', array($this, 'skip_tables'),10,2);
47
+ add_filter('wpvivid_restore_db_skip_replace_rows', array($this, 'skip_rows'),10,3);
 
 
 
 
 
 
48
 
49
+ $this->skip_query=0;
50
+
51
+ global $wpvivid_pulgin;
52
+
53
+ if(file_exists($path.$sql_file))
 
 
 
 
 
54
  {
55
+ if(!isset($options['skip_backup_old_database']))
56
+ {
57
+ $wpvivid_pulgin->restore_data->write_log('Backing up current site\'s database.','notice');
58
+ $backup_database = new WPvivid_Backup_Database();
59
+ $old_sql_file=$path.'old_database.sql';
60
+ $data['sql_file_name']=$old_sql_file;
61
+ $result = $backup_database ->backup_database($data);
62
+ if($result['result'] == WPVIVID_FAILED)
63
+ {
64
+ $wpvivid_pulgin->restore_data->write_log('Backing up current site\'s database failed.error:'.$result['error'],'warning');
65
+ }
66
+ }
67
 
68
+ $this->current_setting = WPvivid_Setting::export_setting_to_json();
69
+ $ret=$this->connect_db();
70
+ if($ret['result']==WPVIVID_FAILED)
71
+ {
72
+ return $ret;
73
+ }
74
+
75
+ $this->test_db();
76
+ $this->check_max_allow_packet();
77
+
78
+ $res = $this->db->query('SELECT @@SESSION.sql_mode') -> fetchAll();
79
+ $sql_mod = $res[0][0];
80
+ $temp_sql_mode = str_replace('NO_ENGINE_SUBSTITUTION','',$sql_mod);
81
+ $temp_sql_mode = 'NO_AUTO_VALUE_ON_ZERO,'.$temp_sql_mode;
82
+ $this->db->query('SET SESSION sql_mode = "'.$temp_sql_mode.'"');
83
+ $result=$this->execute_sql_file($path.$sql_file,$options);
84
+ unset($this->db);
85
+ return $result;
86
+ }else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  return array('result'=>'failed','error'=>'Database\'s .sql file not found. Please try again.');
88
  }
89
  }
90
 
91
+ private function connect_db()
92
  {
 
 
 
 
 
 
93
  $res = explode(':',DB_HOST);
94
  $db_host = $res[0];
95
  $db_port = empty($res[1])?'':$res[1];
96
  if(!empty($db_port))
97
  $db_host = $db_host.':'.$db_port;
98
+ try
99
+ {
100
+ $this->db = null;
101
+ $this->db=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
102
+ $this->db->exec('SET NAMES utf8');
103
+ if(empty($this->db) || !$this->db)
104
+ {
105
+ $ret['result']=WPVIVID_FAILED;
106
+ $ret['error']='The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
107
+ }
108
+ else
109
+ {
110
+ $ret['result']=WPVIVID_SUCCESS;
111
+ }
112
+ }
113
+ catch (Exception $e)
114
  {
115
+ if(!empty($db_port))
116
+ {
117
  $db_host = $res[0];
118
+ $this->db=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
119
+ $this->db->exec('SET NAMES utf8');
120
  }
121
+ if(empty($this->db) || !$this->db)
122
+ {
123
+ $ret['result']=WPVIVID_FAILED;
124
+ $ret['error']='The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.';
125
+ }
126
+ else
127
+ {
128
+ $ret['result']=WPVIVID_SUCCESS;
129
  }
130
  }
131
+ return $ret;
132
+ }
133
+
134
+ private function test_db()
135
+ {
136
+ global $wpvivid_pulgin;
137
+ $test_table_new=uniqid('wpvivid_test_tables_');
138
+ $columns='(test_id int)';
139
+ $test_table = $this->db->exec("CREATE TABLE IF NOT EXISTS $test_table_new $columns");
140
 
141
+ if ($test_table!==false)
142
+ {
143
+ $wpvivid_pulgin->restore_data->write_log('The test to create table succeeds.','notice');
144
+ $test_table = $this->db->exec("INSERT INTO $test_table_new (`test_id`) VALUES ('123')");
145
+ if($test_table!==false)
146
+ {
147
+ $wpvivid_pulgin->restore_data->write_log('The test to insert into table succeeds.','notice');
148
+ $test_table = $this->db->exec("DROP TABLE IF EXISTS $test_table_new");
149
+ if($test_table!==false)
150
+ {
151
+ $wpvivid_pulgin->restore_data->write_log('The test to drop table succeeds.','notice');
152
+ return true;
153
+ }
154
+ else
155
+ {
156
+ $error=$this->db->errorInfo();
157
+ $wpvivid_pulgin->restore_data->write_log('Unable to drop table. The reason is '.$error[2],'warning');
158
+ return false;
159
+ }
160
+ }
161
+ else
162
+ {
163
+ $error=$this->db->errorInfo();
164
+ $wpvivid_pulgin->restore_data->write_log('Unable to insert into table. The reason is '.$error[2],'warning');
165
+ return false;
166
+ }
167
+ }
168
+ else {
169
+ $error=$this->db->errorInfo();
170
+ $wpvivid_pulgin->restore_data->write_log('Unable to create table. The reason is '.$error[2],'warning');
171
+ return false;
172
+ }
173
  }
174
 
175
+ private function execute_sql_file($file,$option)
176
+ {
177
+ global $wpdb,$wpvivid_pulgin;
 
 
 
 
178
 
179
+ $wpvivid_pulgin->restore_data->write_log('Start import sql file.','notice');
180
 
181
+ $this->support_engines=array();
182
+ $this->support_charsets=array();
183
+ $this->support_collates=array();
184
+ $this->default_engines=array();
185
+ $this->default_charsets=array();
186
+ $this->default_collates=array();
187
 
188
+ if(isset($option['default_engine']))
189
+ {
190
+ $this->default_engines=$option['default_engine'];
191
+ }
192
+ else
193
+ {
194
+ $this->default_engines[]='MyISAM';
195
+ }
196
 
197
+ if(isset($option['default_charsets']))
198
+ {
199
+ $this->default_charsets=$option['default_charsets'];
200
+ }
201
+ else
202
+ {
203
+ $this->default_charsets[]='utf8';
204
  }
205
 
206
+ if(isset($option['default_collations']))
207
+ {
208
+ $this->default_collates=$option['default_collations'];
209
+ }
210
+ else
211
+ {
212
+ $this->default_collates[]='utf8_general_ci';
213
  }
214
 
215
+ $this->old_prefix='';
216
+ $this->new_prefix=$wpdb->base_prefix;
217
+
218
+ $this->old_site_url='';
219
+ $this->old_home_url='';
220
+ $this->old_content_url='';
221
+ $this->old_upload_url='';
222
+
223
+ $this->new_site_url= untrailingslashit(site_url());
224
+
225
+ $this->new_home_url=untrailingslashit(home_url());
226
+
227
+ $this->new_content_url=untrailingslashit(content_url());
228
+
229
+ $upload_dir = wp_upload_dir();
230
+ $this->new_upload_url=untrailingslashit($upload_dir['baseurl']);
231
+
232
+ $result = $wpdb->get_results("SHOW ENGINES", OBJECT_K);
233
+ foreach ($result as $key=>$value)
234
+ {
235
+ $this->support_engines[]=$key;
236
+ }
237
+
238
+ $result = $wpdb->get_results("SHOW CHARACTER SET", OBJECT_K);
239
+ foreach ($result as $key=>$value)
240
+ {
241
+ $this->support_charsets[]=$key;
242
+ }
243
+
244
+ $result = $wpdb->get_results("SHOW COLLATION", OBJECT_K);
245
+ foreach ($result as $key=>$value)
246
+ {
247
+ $this->support_collates[]=$key;
248
+ }
249
+
250
+ $sql_handle = fopen($file,'r');
251
+ if($sql_handle===false)
252
+ {
253
+ $ret['result']=WPVIVID_FAILED;
254
+ $ret['error']='file not found. file name:'.$file;
255
+ return $ret;
256
+ }
257
+ $line_num = 0;
258
+ $query='';
259
+
260
+ $current_table='';
261
+ while(!feof($sql_handle))
262
+ {
263
+ $line = fgets($sql_handle);
264
  $line_num ++;
265
  $startWith = substr(trim($line), 0 ,2);
266
  $endWith = substr(trim($line), -1 ,1);
267
+ $line = rtrim($line);
268
+ if (empty($line) || $startWith == '--' || $startWith == '/*' || $startWith == '//')
269
+ {
270
+ if ($endWith == ';' && preg_match('- # -',$line))
271
+ {
272
+ $matcher = array();
273
+ if(empty($this -> site_url) && preg_match('# site_url: (.*?) #',$line,$matcher))
274
+ {
275
+ $this->old_site_url = $matcher[1];
276
+ $wpvivid_pulgin->restore_data->write_log('old site url:'.$this->old_site_url,'notice');
277
+ }
278
+ if(empty($this -> home_url) && preg_match('# home_url: (.*?) #',$line,$matcher))
279
+ {
280
+ $this->old_home_url = $matcher[1];
281
+ $wpvivid_pulgin->restore_data->write_log('old home url:'.$this->old_home_url,'notice');
282
+ }
283
+ if(empty($this -> content_url) && preg_match('# content_url: (.*?) #',$line,$matcher))
284
+ {
285
+ $this->old_content_url = $matcher[1];
286
+ $wpvivid_pulgin->restore_data->write_log('old content url:'.$this->old_content_url,'notice');
287
+ }
288
+ if(empty($this -> upload_url) && preg_match('# upload_url: (.*?) #',$line,$matcher))
289
+ {
290
+ $this->old_upload_url = $matcher[1];
291
+ $wpvivid_pulgin->restore_data->write_log('old upload url:'.$this->old_upload_url,'notice');
292
+ }
293
+ if(empty($this -> table_prefix) && preg_match('# table_prefix: (.*?) #',$line,$matcher))
294
+ {
295
+ $this->old_prefix = $matcher[1];
296
+ $wpvivid_pulgin->restore_data->write_log('old site prefix:'.$this->old_prefix,'notice');
297
+ }
298
+ }
299
  continue;
300
  }
301
 
302
  $query = $query . $line;
303
+ if ($endWith == ';')
304
+ {
305
+ if (preg_match('#^\\s*CREATE TABLE#', $query))
306
+ {
307
+ $current_table=$this->create_table($query);
308
+ }else if(preg_match('#^\\s*LOCK TABLES#',$query))
309
+ {
310
+ $this->lock_table($query);
311
+ }
312
+ else if(preg_match('#^\\s*INSERT INTO#', $query))
313
+ {
314
+ $this->insert($query);
315
+ }
316
+ else if(preg_match('#^\\s*DROP TABLE #', $query))
317
+ {
318
+ if(!empty($this->old_site_url)&&$this->old_site_url!=$this->new_site_url)
319
+ {
320
+ if(isset($option['is_migrate']))
321
+ {
322
+ if(!empty($current_table))
323
+ {
324
+ $this->replace_row($current_table);
325
+ }
326
+ }
327
+ }
328
+ $this->drop_table($query);
329
+ }
330
+ else
331
+ {
332
+ if ($this->db->exec($query)===false)
333
+ {
334
+ $wpvivid_pulgin->restore_data->write_log('Restore ' . basename($file) . ' error at line ' . $line_num . ',' . PHP_EOL . 'errorinfo: [' . implode('][', $this->db->errorInfo()) . ']', 'Warning');
335
+ $query = '';
336
  continue;
337
  }
 
338
  }
339
+ $query = '';
340
+ }
341
+ }
342
+
343
+ if(!empty($this->old_site_url)&&$this->old_site_url!=$this->new_site_url)
344
+ {
345
+ if(isset($option['is_migrate']))
346
+ {
347
+ if(!empty($current_table))
348
+ {
349
+ $this->replace_row($current_table);
350
+ }
351
+ }
352
+ }
353
+ else
354
+ {
355
+ WPvivid_Setting::import_json_to_setting($this->current_setting);
356
+ WPvivid_Schedule::reset_schedule();
357
+ }
358
+
359
+ fclose($sql_handle);
360
+ $ret['result']=WPVIVID_SUCCESS;
361
+ return $ret;
362
+ }
363
+
364
+ private function lock_table($query)
365
+ {
366
+ global $wpvivid_pulgin;
367
+ if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
368
+ {
369
+ if (preg_match('/^\s*LOCK TABLES +\`?([^\`]*)\`?/i', $query, $matches))
370
+ {
371
+ $table_name = $matches[1];
372
+ $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
373
+ //$this->restore_data->write_log('lock replace table:'.$table_name.' to :'.$new_table_name,'notice');
374
+ $query=str_replace($table_name,$new_table_name,$query);
375
+ }
376
+ }
377
+
378
+ $this->execute_sql($query);
379
+ }
380
+
381
+ private function create_table($query)
382
+ {
383
+ global $wpvivid_pulgin;
384
+ $table_name='';
385
+ if (preg_match('/^\s*CREATE TABLE +\`?([^\`]*)\`?/i', $query, $matches))
386
+ {
387
+ $table_name = $matches[1];
388
+ }
389
+
390
+ if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
391
+ {
392
+ //$this->restore_data->write_log('create table','notice');
393
+ $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
394
+ //$this->restore_data->write_log('create table replace table:'.$table_name.' to :'.$new_table_name,'notice');
395
+ $query=str_replace($table_name,$new_table_name,$query);
396
+ $wpvivid_pulgin->restore_data->write_log('Create table '.$new_table_name,'notice');
397
+ $table_name=$new_table_name;
398
+ }
399
+ else
400
+ {
401
+ $wpvivid_pulgin->restore_data->write_log('Create table '.$table_name,'notice');
402
+ }
403
+
404
+ if (preg_match('/ENGINE=([^\s;]+)/', $query, $matches))
405
+ {
406
+ $engine = $matches[1];
407
+ $replace_engine=true;
408
+ foreach ($this->support_engines as $support_engine)
409
+ {
410
+ if(strtolower($engine)==strtolower($support_engine))
411
+ {
412
+ $replace_engine=false;
413
+ break;
414
+ }
415
+ }
416
+
417
+ if($replace_engine!==false)
418
+ {
419
+ if(!empty($this->default_engines))
420
+ $replace_engine=$this->default_engines[0];
421
+ }
422
+
423
+ if($replace_engine!==false)
424
+ {
425
+ $wpvivid_pulgin->restore_data->write_log('create table replace engine:'.$engine.' to :'.$replace_engine,'notice');
426
+ $query=str_replace("ENGINE=$engine", "ENGINE=$replace_engine", $query);
427
+ }
428
+ }
429
+
430
+ if (preg_match('/CHARSET=([^\s;]+)/', $query, $matches))
431
+ {
432
+ $charset = $matches[1];
433
+ $replace_charset=true;
434
+ foreach ($this->support_charsets as $support_charset)
435
+ {
436
+ if(strtolower($charset)==strtolower($support_charset))
437
+ {
438
+ $replace_charset=false;
439
+ break;
440
+ }
441
+ }
442
+
443
+ if($replace_charset!==false)
444
+ {
445
+ if(!empty($this->default_charsets))
446
+ $replace_charset=$this->default_charsets[0];
447
+ }
448
+
449
+ if($replace_charset!==false)
450
+ {
451
+ $wpvivid_pulgin->restore_data->write_log('create table replace charset:'.$charset.' to :'.$replace_charset,'notice');
452
+ $query=str_replace("CHARSET=$charset", "CHARSET=$replace_charset", $query);
453
+ }
454
+ }
455
+
456
+ if (preg_match('/ COLLATE ([a-zA-Z0-9._-]+)/i', $query, $matches))
457
+ {
458
+ $collate = $matches[1];
459
+ $replace_collate=true;
460
+ foreach ($this->support_collates as $support_collate)
461
+ {
462
+ if(strtolower($collate)==strtolower($support_collate))
463
+ {
464
+ $replace_collate=false;
465
+ break;
466
+ }
467
+ }
468
+
469
+ if($replace_collate!==false)
470
+ {
471
+ if(!empty($this->default_collates))
472
+ $replace_collate=$this->default_collates[0];
473
+ }
474
+
475
+ if($replace_collate!==false)
476
+ {
477
+ $wpvivid_pulgin->restore_data->write_log('create table replace collate:'.$collate.' to :'.$replace_collate,'notice');
478
+ $query=str_replace("COLLATE $collate", "COLLATE $replace_collate", $query);
479
+ }
480
+ }
481
+
482
+ $this->execute_sql($query);
483
+
484
+ return $table_name;
485
+ }
486
+
487
+ private function insert($query)
488
+ {
489
+ global $wpvivid_pulgin;
490
+ if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
491
+ {
492
+ if (preg_match('/^\s*INSERT INTO +\`?([^\`]*)\`?/i', $query, $matches))
493
+ {
494
+ $table_name = $matches[1];
495
+ $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
496
+ //$this->restore_data->write_log('insert into replace table:'.$table_name.' to :'.$new_table_name,'notice');
497
+ $query=str_replace($table_name,$new_table_name,$query);
498
+ }
499
+ }
500
+
501
+ $this->execute_sql($query);
502
+ }
503
+
504
+ private function drop_table($query)
505
+ {
506
+ global $wpvivid_pulgin;
507
+ if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
508
+ {
509
+ if (preg_match('/^\s*DROP TABLE IF EXISTS +\`?([^\`]*)\`?\s*;/i', $query, $matches))
510
+ {
511
+ $table_name = $matches[1];
512
+ $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
513
+ $wpvivid_pulgin->restore_data->write_log('drop replace table:'.$table_name.' to :'.$new_table_name,'notice');
514
+ $query=str_replace($table_name,$new_table_name,$query);
515
+ }
516
+ }
517
+
518
+ $this->execute_sql($query);
519
+ }
520
+
521
+ private function replace_row($table_name)
522
+ {
523
+ global $wpdb,$wpvivid_pulgin;
524
+
525
+ $this->replacing_table=$table_name;
526
+
527
+ $wpvivid_pulgin->restore_data->write_log('Dumping table '.$table_name.' is complete. Start replacing row(s).', 'notice');
528
+
529
+ if(substr($table_name, strlen($this->new_prefix))=='options')
530
+ {
531
+ WPvivid_Setting::import_json_to_setting($this->current_setting);
532
+ WPvivid_Schedule::reset_schedule();
533
+ if($this->old_prefix!=$this->new_prefix)
534
+ {
535
+ $update_query ='UPDATE '.$table_name.' SET option_name="'.$this->new_prefix.'user_roles" WHERE option_name="'.$this->old_prefix.'user_roles";';
536
+
537
+ $wpvivid_pulgin->restore_data->write_log($update_query, 'notice');
538
+ $wpvivid_pulgin->restore_data->write_log('update query len:'.strlen($update_query), 'notice');
539
+ $this->execute_sql($update_query);
540
+ }
541
+ }
542
+
543
+ if(substr($table_name, strlen($this->new_prefix))=='usermeta')
544
+ {
545
+ if($this->old_prefix!=$this->new_prefix)
546
+ {
547
+ $update_query ='UPDATE '.$table_name.' SET meta_key=REPLACE(meta_key,"'.$this->old_prefix.'","'.$this->new_prefix.'") WHERE meta_key LIKE "'.str_replace('_','\_',$this->old_prefix).'%";';
548
+
549
+ $wpvivid_pulgin->restore_data->write_log($update_query, 'notice');
550
+ $wpvivid_pulgin->restore_data->write_log('update query len:'.strlen($update_query), 'notice');
551
+ $this->execute_sql($update_query);
552
+ return ;
553
+ }
554
+ }
555
+
556
+ $skip_table=false;
557
+ if(apply_filters('wpvivid_restore_db_skip_replace_tables',$skip_table,$table_name))
558
+ {
559
+ $wpvivid_pulgin->restore_data->write_log('Skip table '.$table_name, 'Warning');
560
+ return ;
561
+ }
562
+
563
+ $query = 'SELECT COUNT(*) FROM `'.$table_name.'`';
564
+
565
+ /*if(substr($this->replacing_table, strlen($this->new_prefix))=='postmeta')
566
+ {
567
+ if($this->get_remove_http_slash_link($this->old_site_url)!=false)
568
+ {
569
+ $query = 'SELECT COUNT(*) FROM `'.$table_name.'` WHERE meta_value LIKE "%'.$this->get_remove_http_slash_link($this->old_site_url).'%"';
570
+ }
571
+ }*/
572
+
573
+ $result=$this->db->query($query);
574
+
575
+ if($result && $result->rowCount()>0)
576
+ {
577
+ $count = $result -> fetchAll();
578
+ $wpvivid_pulgin->restore_data->write_log('Count of rows in '.$table_name.': '.$count[0][0], 'notice');
579
+ if($count[0][0]==0)
580
+ {
581
+ return ;
582
+ }
583
+
584
+ $query='DESCRIBE `'.$table_name.'`';
585
+ $result=$this->db->query($query);
586
+ $result=$result -> fetchAll(PDO::FETCH_ASSOC);
587
+ $columns=array();
588
+ foreach ($result as $data)
589
+ {
590
+ $column['Field']=$data['Field'];
591
+ if($data['Key']=='PRI')
592
+ $column['PRI']=1;
593
+ else
594
+ $column['PRI']=0;
595
+ $columns[]=$column;
596
+ }
597
+
598
+ $count=$count[0][0];
599
+ $page=5000;
600
+
601
+ $update_query='';
602
+
603
+ $start_row=0;
604
+ for ($current_row = $start_row; $current_row <= $count; $current_row += $page)
605
+ {
606
+ $wpvivid_pulgin->restore_data->write_log('Replace the row in '.$current_row. ' line.', 'notice');
607
+ $end_row=$current_row+$page;
608
+ $query = 'SELECT * FROM `'.$table_name.'` LIMIT '.$current_row.', '.$end_row;
609
+ /*if(substr($this->replacing_table, strlen($this->new_prefix))=='postmeta')
610
+ {
611
+ if($this->get_remove_http_slash_link($this->old_site_url)!=false)
612
+ {
613
+ $query = 'SELECT * FROM `'.$table_name.'` WHERE meta_value LIKE "%'.$this->get_remove_http_slash_link($this->old_site_url).'%" LIMIT '.$current_row.', '.$end_row;
614
+ $wpvivid_pulgin->restore_data->write_log($query, 'notice');
615
+ }
616
+ }*/
617
+ $result=$this->db->query($query);
618
+
619
+ if($result && $result->rowCount()>0)
620
+ {
621
+ $rows = $result -> fetchAll(PDO::FETCH_ASSOC);
622
+ foreach ($rows as $row)
623
+ {
624
+ $update=array();
625
+ $where=array();
626
+
627
+ foreach ($columns as $column)
628
+ {
629
+ $old_data = $row[$column['Field']];
630
+ if($column['PRI']==1)
631
+ {
632
+ $wpdb->escape_by_ref($old_data);
633
+ $temp_where='`'.$column['Field'].'` = "' . $old_data . '"';
634
+ if (is_callable(array($wpdb, 'remove_placeholder_escape')))
635
+ $temp_where = $wpdb->remove_placeholder_escape($temp_where);
636
+ $where[] = $temp_where;
637
+ }
638
+
639
+ $skip_row=false;
640
+ if(apply_filters('wpvivid_restore_db_skip_replace_rows',$skip_row,$table_name,$column['Field']))
641
+ {
642
+ continue;
643
+ }
644
+
645
+ $new_data=$this->replace_row_data($old_data);
646
+ if($new_data==$old_data)
647
+ continue;
648
+
649
+ $wpdb->escape_by_ref($new_data);
650
+ if (is_callable(array($wpdb, 'remove_placeholder_escape')))
651
+ $new_data = $wpdb->remove_placeholder_escape($new_data);
652
+ $update[] = '`'.$column['Field'].'` = "' . $new_data . '"';
653
+ }
654
+
655
+ if(!empty($update)&&!empty($where))
656
+ {
657
+ $temp_query = 'UPDATE `'.$table_name.'` SET '.implode(', ', $update).' WHERE '.implode(' AND ', array_filter($where)).';';
658
+ if(strlen($temp_query)+strlen($update_query)>$this->max_allow_packet)
659
+ {
660
+ $wpvivid_pulgin->restore_data->write_log('update replace rows', 'notice');
661
+ $this->execute_sql($update_query);
662
+
663
+ $update_query='';
664
+ }
665
+ else
666
+ {
667
+ $update_query.=$temp_query;
668
+ }
669
+ }
670
+ //return;
671
+ }
672
+ }
673
+ }
674
+
675
+ if(!empty($update_query))
676
+ {
677
+ $wpvivid_pulgin->restore_data->write_log('update replace rows', 'notice');
678
+
679
+ $this->execute_sql($update_query);
680
+ }
681
+ }
682
+ $wpvivid_pulgin->restore_data->write_log('finish replace rows', 'notice');
683
+ }
684
+
685
+ private function replace_row_data($old_data)
686
+ {
687
+ $unserialize_data = @unserialize($old_data);
688
+ if($unserialize_data===false)
689
+ {
690
+ $old_data=$this->replace_string($old_data);
691
+ }
692
+ else
693
+ {
694
+ $old_data=$this->replace_serialize_data($unserialize_data);
695
+ $old_data=serialize($old_data);
696
+ /*if(is_array($unserialize_data))
697
+ {
698
+ $temp_data = array();
699
+ foreach ($unserialize_data as $key => $value)
700
+ {
701
+ $temp_data[$key]=$this->replace_string($value);
702
+ }
703
+
704
+ $old_data = $temp_data;
705
+ unset($temp_data);
706
+ $old_data=$this->replace_serialize_data($unserialize_data);
707
+ $old_data=serialize($old_data);
708
+ }
709
+ else if(is_object($unserialize_data))
710
+ {
711
+ $temp_data = $unserialize_data;
712
+ $props = get_object_vars($unserialize_data);
713
+ foreach ($props as $key => $value)
714
+ {
715
+ $temp_data->$key =$this->replace_string($value);
716
+ }
717
+ $old_data = $temp_data;
718
+ unset($temp_data);
719
+ $old_data=serialize($old_data);
720
+ }*/
721
+ }
722
+
723
+ return $old_data;
724
+ }
725
+
726
+ private function replace_serialize_data($data)
727
+ {
728
+ if(is_string($data))
729
+ {
730
+ $serialize_data =@unserialize($data);
731
+ if($serialize_data===false)
732
+ {
733
+ $data=$this->replace_string($data);
734
+ }
735
+ else
736
+ {
737
+ $data=serialize($this->replace_serialize_data($serialize_data));
738
+ }
739
+ }
740
+ else if(is_array($data))
741
+ {
742
+ foreach ($data as $key => $value)
743
+ {
744
+ if(is_string($value))
745
+ {
746
+ $data[$key]=$this->replace_string($value);
747
+ }
748
+ else if(is_array($value))
749
+ {
750
+ $data[$key]=$this->replace_serialize_data($value);
751
+ }
752
+ else if(is_object($value))
753
+ {
754
+ $data[$key]=$this->replace_serialize_data($value);
755
+ }
756
+ }
757
+ }
758
+ else if(is_object($data))
759
+ {
760
+ $props = get_object_vars($data);
761
+ foreach ($props as $key => $value)
762
+ {
763
+ if(is_string($value))
764
+ {
765
+ $data->$key =$this->replace_string($value);
766
+ }
767
+ else if(is_array($value))
768
+ {
769
+ $data->$key=$this->replace_serialize_data($value);
770
+ }
771
+ else if(is_object($value))
772
+ {
773
+ $data->$key=$this->replace_serialize_data($value);
774
+ }
775
+ }
776
+ }
777
+
778
+ return $data;
779
+ }
780
+
781
+ private function get_mix_link($url)
782
+ {
783
+ if (0 === stripos($url, 'https://'))
784
+ {
785
+ $mix_link = 'http://'.substr($url, 8);
786
+ } elseif (0 === stripos($url, 'http://')) {
787
+ $mix_link = 'https://'.substr($url, 7);
788
+ }
789
+ else
790
+ {
791
+ $mix_link=false;
792
+ }
793
+ return $mix_link;
794
+ }
795
+
796
+ private function get_remove_http_slash_link($url)
797
+ {
798
+ if (0 === stripos($url, 'https://'))
799
+ {
800
+ $mix_link = substr($url, 8);
801
+ } elseif (0 === stripos($url, 'http://')) {
802
+ $mix_link = substr($url, 7);
803
+ }
804
+ else
805
+ {
806
+ $mix_link=false;
807
+ }
808
+ return $mix_link;
809
+ }
810
+
811
+ private function get_remove_http_link($url)
812
+ {
813
+ if (0 === stripos($url, 'https://'))
814
+ {
815
+ $mix_link = '//'.substr($url, 8);
816
+ } elseif (0 === stripos($url, 'http://')) {
817
+ $mix_link = '//'.substr($url, 7);
818
+ }
819
+ else
820
+ {
821
+ $mix_link=false;
822
+ }
823
+ return $mix_link;
824
+ }
825
+
826
+ private function get_remove_http_link_ex($url)
827
+ {
828
+ if (0 === stripos($url, 'https://'))
829
+ {
830
+ $mix_link = '\/\/'.substr($url, 8);
831
+ } elseif (0 === stripos($url, 'http://')) {
832
+ $mix_link = '\/\/'.substr($url, 7);
833
+ }
834
+ else
835
+ {
836
+ $mix_link=false;
837
+ }
838
+ return $mix_link;
839
+ }
840
+
841
+ private function replace_string($old_string)
842
+ {
843
+ if(!is_string($old_string))
844
+ {
845
+ return $old_string;
846
+ }
847
+ if($this->old_site_url!=$this->new_site_url)
848
+ {
849
+ $old_string=str_replace($this->old_site_url,$this->new_site_url,$old_string);
850
+ $old_mix_link=$this->get_mix_link($this->old_site_url);
851
+ if($old_mix_link!==false)
852
+ {
853
+ $old_string=str_replace($old_mix_link,$this->new_site_url,$old_string);
854
+ }
855
+ if(substr($this->replacing_table, strlen($this->new_prefix))=='posts'||substr($this->replacing_table, strlen($this->new_prefix))=='postmeta'||substr($this->replacing_table, strlen($this->new_prefix))=='options')
856
+ {
857
+ $remove_http_link=$this->get_remove_http_link($this->old_site_url);
858
+ if($remove_http_link!==false)
859
+ {
860
+ $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
861
+ $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
862
+ }
863
+
864
+ $remove_http_link=$this->get_remove_http_link_ex($this->old_site_url);
865
+ if($remove_http_link!==false)
866
+ {
867
+ $new_remove_http_link=$this->get_remove_http_link_ex($this->new_site_url);
868
+ $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
869
+ }
870
  }
871
  }
 
 
872
 
873
+ if($this->old_home_url!=$this->new_home_url)
874
+ {
875
+ $old_string=str_replace($this->old_home_url,$this->new_home_url,$old_string);
876
+
877
+ $old_mix_link=$this->get_mix_link($this->old_home_url);
878
+ if($old_mix_link!==false)
879
+ {
880
+ $old_string=str_replace($old_mix_link,$this->new_home_url,$old_string);
881
+ }
882
+ }
883
+ if($this->old_content_url!=$this->new_content_url)
884
  {
885
+ $old_string=str_replace($this->old_content_url,$this->new_content_url,$old_string);
886
+ }
887
+ if($this->old_upload_url!=$this->new_upload_url)
888
+ {
889
+ $old_string = str_replace($this->old_upload_url, $this->new_upload_url, $old_string);
890
  }
891
 
892
+ return $old_string;
893
  }
894
+
895
+ private function skip_tables($skip_table,$table_name)
896
+ {
897
+ $skip_tables[]='adrotate_stats';
898
+ $skip_tables[]='login_security_solution_fail';
899
+ $skip_tables[]='icl_strings';
900
+ $skip_tables[]='icl_string_positions';
901
+ $skip_tables[]='icl_string_translations';
902
+ $skip_tables[]='icl_languages_translations';
903
+ $skip_tables[]='slim_stats';
904
+ $skip_tables[]='slim_stats_archive';
905
+ $skip_tables[]='es_online';
906
+ $skip_tables[]='ahm_download_stats';
907
+ $skip_tables[]='woocommerce_order_items';
908
+ $skip_tables[]='woocommerce_sessions';
909
+ $skip_tables[]='redirection_404';
910
+ $skip_tables[]='redirection_logs';
911
+ $skip_tables[]='wbz404_logs';
912
+ $skip_tables[]='wbz404_redirects';
913
+ $skip_tables[]='Counterize';
914
+ $skip_tables[]='Counterize_UserAgents';
915
+ $skip_tables[]='Counterize_Referers';
916
+ $skip_tables[]='et_bloom_stats';
917
+ $skip_tables[]='term_relationships';
918
+ $skip_tables[]='lbakut_activity_log';
919
+ $skip_tables[]='simple_feed_stats';
920
+ $skip_tables[]='svisitor_stat';
921
+ $skip_tables[]='itsec_log';
922
+ $skip_tables[]='relevanssi_log';
923
+ $skip_tables[]='wysija_email_user_stat';
924
+ $skip_tables[]='wponlinebackup_generations';
925
+ $skip_tables[]='blc_instances';
926
+ $skip_tables[]='wp_rp_tags';
927
+ $skip_tables[]='statpress';
928
+ $skip_tables[]='wfHits';
929
+ $skip_tables[]='wp_wfFileMods';
930
+ $skip_tables[]='tts_trafficstats';
931
+ $skip_tables[]='tts_referrer_stats';
932
+ $skip_tables[]='dmsguestbook';
933
+ $skip_tables[]='relevanssi';
934
+ $skip_tables[]='wfFileMods';
935
+ if(in_array(substr($table_name, strlen($this->new_prefix)),$skip_tables))
936
+ {
937
+ $skip_table=true;
938
+ }
939
+ else
940
+ {
941
+ $skip_table=false;
942
+ }
943
+
944
+ return $skip_table;
945
+ }
946
+
947
+ private function skip_rows($skip_rows,$table_name,$column_name)
948
+ {
949
+ $row['table_name']='posts';
950
+ $row['column_name']='guid';
951
+ $rows[]=$row;
952
+
953
+ foreach ($rows as $row)
954
+ {
955
+ if($column_name==$row['column_name']&&$table_name==$this->new_prefix.$row['table_name'])
956
+ {
957
+ $skip_rows=true;
958
+ break;
959
+ }
960
+ }
961
+
962
+ return $skip_rows;
963
+ }
964
+
965
+ private function check_max_allow_packet()
966
+ {
967
+ //$max_allow_packet
968
+ global $wpvivid_pulgin;
969
+ $max_allowed_packet = $this->db->query("SELECT @@session.max_allowed_packet;");
970
+ if($max_allowed_packet)
971
+ {
972
+ $max_allowed_packet = $max_allowed_packet -> fetchAll();
973
+ if(is_array($max_allowed_packet)&&isset($max_allowed_packet[0])&&isset($max_allowed_packet[0][0]))
974
+ {
975
+ if($max_allowed_packet[0][0]<1048576)
976
+ {
977
+ $wpvivid_pulgin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet[0][0],2),'notice');
978
+ }
979
+ else if($max_allowed_packet[0][0]<33554432)
980
+ {
981
+ $wpvivid_pulgin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet[0][0],2),'notice');
982
+ }
983
+ $this->max_allow_packet=$max_allowed_packet[0][0];
984
+ }
985
+ else
986
+ {
987
+ $wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed ','notice');
988
+ $this->max_allow_packet=1048576;
989
+ }
990
+ }
991
+ else
992
+ {
993
+ $wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed ','notice');
994
+ $this->max_allow_packet=1048576;
995
+ }
996
+ }
997
+
998
+ private function execute_sql($query)
999
+ {
1000
+ global $wpvivid_pulgin;
1001
+
1002
+ if($this->skip_query>10)
1003
+ {
1004
+ if(strlen($query)>$this->max_allow_packet)
1005
+ {
1006
+ $wpvivid_pulgin->restore_data->write_log('skip query size:'.size_format(strlen($query)), 'Warning');
1007
+ return ;
1008
+ }
1009
+ }
1010
+
1011
+ if ($this->db->exec($query)===false)
1012
+ {
1013
+ $info=$this->db->errorInfo();
1014
+ $wpvivid_pulgin->restore_data->write_log('query: [' . implode('][', $info) . ']', 'Warning');
1015
+
1016
+ if($info[1] == 2006)
1017
+ {
1018
+ if(strlen($query)>$this->max_allow_packet)
1019
+ {
1020
+ $this->skip_query++;
1021
+ $wpvivid_pulgin->restore_data->write_log('max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query)), 'Warning');
1022
+ }
1023
+ $ret=$this->connect_db();
1024
+ if($ret['result']==WPVIVID_FAILED)
1025
+ {
1026
+ $wpvivid_pulgin->restore_data->write_log('reconnect failed', 'Warning');
1027
+ }
1028
+ else{
1029
+ $wpvivid_pulgin->restore_data->write_log('reconnect succeed', 'Warning');
1030
+ }
1031
+ }
1032
+ }
1033
+ }
1034
+
1035
  }
includes/class-wpvivid-restore-site.php CHANGED
@@ -8,68 +8,150 @@ include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-bac
8
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback.php';
9
  class WPvivid_RestoreSite
10
  {
11
- private $restore_data;
12
 
13
- public function restore($type_name,$restorePath,$path,$files){
14
- $this->restore_data=new WPvivid_restore_data();
15
- $zip = new WPvivid_ZipClass();
16
- $basename = $zip -> getBasename($files[0]['file_name']);
17
- $task_id = explode('_',$basename);
18
- $task_id = $task_id[0];
19
-
20
- $temp_path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.$type_name;
21
- $backup = new WPvivid_Backup();
22
- $except_path = $backup -> get_default_exclude_regex($type_name);
23
- $src_path = $backup->get_default_directory($type_name);
24
- $result = $this -> pre_restore($src_path,$temp_path,$except_path);
25
- if($result['result'] != WPVIVID_SUCCESS)
26
- return $result;
27
-
28
- $data= array(
29
- 'src'=>$temp_path,
30
- 'dst'=>$src_path,
31
- 'replace'=>$temp_path,
32
- );
33
- $this->restore_data->set_rollback_data($type_name,$task_id,$data);
34
-
35
- WPvivid_tools::deldir($src_path,$except_path,false);
36
- $result = $this -> _restore($restorePath,$path , $files);
37
 
38
- return $result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  }
40
 
41
- public function pre_restore($path,$temp_path,$except_path){
42
- @mkdir($temp_path);
43
- return $this -> _pre_restore_loop($path,$temp_path,$except_path,$path);
 
 
44
  }
45
- private function _pre_restore_loop($path,$temp_path,$except_path,$replace_path){
 
 
46
  $result = array('result'=>WPVIVID_SUCCESS);
47
 
48
- if(empty($path)) {
49
- return array('result'=>'failed','error'=>'Failed to retrieve website\'s folder path. Please reinstall the plugin and try again.');
50
- }
51
  $handler=opendir($path);
52
  while(($filename=readdir($handler))!==false)
53
  {
54
  if($filename != "." && $filename != "..")
55
  {
56
- if(empty($except_path))
57
- continue;
58
-
59
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename)){
60
- if(WPvivid_tools::regex_match($except_path['directory'],$path.DIRECTORY_SEPARATOR.$filename,0)){
61
- @mkdir(str_replace($replace_path,$temp_path,$path.DIRECTORY_SEPARATOR.$filename));
62
- $result = $this->_pre_restore_loop($path.DIRECTORY_SEPARATOR.$filename,$temp_path,$except_path,$replace_path);
63
- if($result['result'] != WPVIVID_SUCCESS)
64
- break;
 
 
 
 
 
 
65
  }
66
- }else{
67
- if(file_exists($path.DIRECTORY_SEPARATOR.$filename) && WPvivid_tools::regex_match($except_path['file'],$path.DIRECTORY_SEPARATOR.$filename,0)){
68
- if(!copy($path.DIRECTORY_SEPARATOR.$filename,str_replace($replace_path,$temp_path,$path.DIRECTORY_SEPARATOR.$filename))){
69
- $result = array('result'=>'failed','error'=>'Copying '.$path.DIRECTORY_SEPARATOR.$filename.' into '.$temp_path.DIRECTORY_SEPARATOR.$filename.' failed. Make sure the file isn\'t occupied, or the folder is writable.');
70
- break;
 
 
71
  }
72
  }
 
 
 
 
 
 
 
 
 
73
  }
74
  }
75
  }
@@ -78,6 +160,26 @@ class WPvivid_RestoreSite
78
  return $result;
79
  }
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
  private function _restore($restorePath,$path , $files){
83
  $zip = new WPvivid_ZipClass();
8
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-rollback.php';
9
  class WPvivid_RestoreSite
10
  {
 
11
 
12
+ public function restore($option,$files)
13
+ {
14
+ global $wpvivid_pulgin;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
+ if(isset($option['has_child']))
17
+ {
18
+ $root_path=$this->transfer_path(get_home_path().$option['root']);
19
+
20
+ $wpvivid_pulgin->restore_data->write_log('extract root:'.$root_path,'notice');
21
+ $zip = new WPvivid_ZipClass();
22
+ $all_files = array();
23
+ foreach ($files as $file)
24
+ {
25
+ $all_files[] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$file;
26
+ }
27
+
28
+ return $zip -> extract($all_files,$root_path);
29
+ }
30
+ else if(isset($option['dump_db']))
31
+ {
32
+ $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_database';
33
+ if(file_exists($path))
34
+ {
35
+ @mkdir($path);
36
+ }
37
+
38
+ $zip = new WPvivid_ZipClass();
39
+ $all_files = array();
40
+ foreach ($files as $file)
41
+ {
42
+ $all_files[] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$file;
43
+ }
44
+
45
+ $ret= $zip -> extract($all_files,$path);
46
+
47
+ unset($zip);
48
+
49
+ return $ret;
50
+ }
51
+ else
52
+ {
53
+ $root_path=$this->transfer_path(get_home_path().$option['root']);
54
+
55
+ $root_path = rtrim($root_path, '/');
56
+ $root_path = rtrim($root_path, DIRECTORY_SEPARATOR);
57
+
58
+ $old_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_site'.DIRECTORY_SEPARATOR.$option['root'];
59
+
60
+ $exclude_path[]=$this->transfer_path(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir());
61
+
62
+ if(isset($option['include_path']))
63
+ {
64
+ $include_path=$option['include_path'];
65
+ }
66
+ else
67
+ {
68
+ $include_path=array();
69
+ }
70
+
71
+ $wpvivid_pulgin->restore_data->write_log('backup old file site','notice');
72
+
73
+ if(!isset($option['skip_backup_old_site']))
74
+ {
75
+ $this->pre_restore($root_path,$old_path,$include_path,$exclude_path);
76
+ }
77
+
78
+
79
+ $zip = new WPvivid_ZipClass();
80
+ $all_files = array();
81
+ foreach ($files as $file)
82
+ {
83
+ $all_files[] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$file;
84
+ }
85
+
86
+ $wpvivid_pulgin->restore_data->write_log('restore from files:'.json_encode($all_files),'notice');
87
+
88
+ $ret= $zip->extract($all_files,$root_path);
89
+
90
+ unset($zip);
91
+
92
+ if(isset($option['wp_core'])&&isset($option['is_migrate']))
93
+ {
94
+ @rename(get_home_path().'.htaccess',get_home_path().'.htaccess_old');
95
+ if ( function_exists( 'save_mod_rewrite_rules' ) )
96
+ {
97
+ save_mod_rewrite_rules();
98
+ }
99
+ WPvivid_Setting::update_option('wpvivid_migrate_status', 'completed');
100
+ }
101
+ return $ret;
102
+ }
103
  }
104
 
105
+ public function pre_restore($path,$save_old_path,$include_path,$exclude_path)
106
+ {
107
+ if(!file_exists($save_old_path))
108
+ @mkdir($save_old_path);
109
+ return $this->copy_old_files($path,$save_old_path,$path,$include_path,$exclude_path);
110
  }
111
+
112
+ private function copy_old_files($path,$save_old_path,$root_path,$include_path,$exclude_path)
113
+ {
114
  $result = array('result'=>WPVIVID_SUCCESS);
115
 
 
 
 
116
  $handler=opendir($path);
117
  while(($filename=readdir($handler))!==false)
118
  {
119
  if($filename != "." && $filename != "..")
120
  {
121
+ $new_dir=$save_old_path.str_replace($root_path,'',$path.DIRECTORY_SEPARATOR.$filename);
122
+ if(is_dir($path.DIRECTORY_SEPARATOR.$filename))
123
+ {
124
+ if(!empty($include_path))
125
+ {
126
+ if( $this->has_include_dir($path.DIRECTORY_SEPARATOR.$filename,$include_path,$root_path))
127
+ {
128
+ if(!file_exists($new_dir))
129
+ @mkdir($new_dir);
130
+ $this->copy_old_files($path.DIRECTORY_SEPARATOR.$filename,$save_old_path,$root_path,$include_path,$exclude_path);
131
+ }
132
+ else
133
+ {
134
+ continue;
135
+ }
136
  }
137
+
138
+ if(!empty($exclude_path))
139
+ {
140
+ $check_path=$this->transfer_path($path.DIRECTORY_SEPARATOR.$filename);
141
+ if(in_array($check_path,$exclude_path))
142
+ {
143
+ continue;
144
  }
145
  }
146
+
147
+ if(!file_exists($new_dir))
148
+ @mkdir($new_dir);
149
+ $this->copy_old_files($path.DIRECTORY_SEPARATOR.$filename,$save_old_path,$root_path,$include_path,$exclude_path);
150
+ }else {
151
+ if(!file_exists($new_dir))
152
+ {
153
+ @copy($path.DIRECTORY_SEPARATOR.$filename,$new_dir);
154
+ }
155
  }
156
  }
157
  }
160
  return $result;
161
  }
162
 
163
+ private function transfer_path($path)
164
+ {
165
+ $path = str_replace('\\','/',$path);
166
+ $values = explode('/',$path);
167
+ return implode(DIRECTORY_SEPARATOR,$values);
168
+ }
169
+
170
+ private function has_include_dir($path,$include_path,$root)
171
+ {
172
+ $path=$this->transfer_path($path);
173
+ foreach ($include_path as $needed_path)
174
+ {
175
+ $needed_path=$this->transfer_path($root.DIRECTORY_SEPARATOR.$needed_path);
176
+ if(strpos($path,$needed_path)!==false)
177
+ {
178
+ return true;
179
+ }
180
+ }
181
+ return false;
182
+ }
183
 
184
  private function _restore($restorePath,$path , $files){
185
  $zip = new WPvivid_ZipClass();
includes/class-wpvivid-restore.php CHANGED
@@ -3,134 +3,101 @@
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
- include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-restore-site.php';
7
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-restore-database.php';
 
8
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-log.php';
9
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-zipclass.php';
10
- class WPvivid_Restore{
11
-
12
- private $restore_data;
13
 
 
 
14
  public function restore()
15
  {
16
- @set_time_limit(600);
17
 
18
- $this->restore_data=new WPvivid_restore_data();
19
- $next_task=$this->restore_data->get_next_restore_task();
20
 
21
- $table = array();
22
 
23
- $backup = $this->restore_data->get_backup_data();
24
-
25
- $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup['local']['path'];
26
-
27
- if($backup['backup']['result'] == WPVIVID_SUCCESS)
 
 
28
  {
29
- if($next_task===false)
 
 
 
 
 
 
 
 
 
 
 
30
  {
31
- $this->restore_data->write_log('Restore task completed.','notice');
32
- $this->restore_data->update_status(WPVIVID_RESTORE_COMPLETED);
33
- return array('result'=>WPVIVID_RESTORE_COMPLETED);
34
  }
35
- else if($next_task===WPVIVID_RESTORE_RUNNING)
36
- {
37
- $this->restore_data->write_log('A restore task is already running.','error');
38
- return array('result'=>WPVIVID_RESTORE_RUNNING);
39
  }
40
- else
41
- {
42
- @set_time_limit(600);
43
- if($backup['backup']['ismerge'])
44
- {
45
- $zip = new WPvivid_ZipClass();
46
- $basename = $zip -> getBasename($backup['backup']['data']['meta']['files'][0]['file_name']);
47
- $temp_expath = $path.DIRECTORY_SEPARATOR.'temp-'.$basename;
48
- $allpackages = array();
49
- foreach ($backup['backup']['data']['meta']['files'] as $file)
50
- {
51
- $allpackages[] = $path.DIRECTORY_SEPARATOR.$file['file_name'];
52
- }
53
 
54
- $files = array();
55
- foreach($next_task['files'] as $file){
56
- $files[] = $file['file_name'];
57
- }
58
- $res = $zip -> get_include_zip($files,$allpackages);
59
- foreach ($res as $key => $value){
60
- $result = $zip -> zipextract_by_files($temp_expath,$value,$key);
61
- if($result['result'] !== WPVIVID_SUCCESS)
62
- return $result;
63
- }
64
- $temp_expath .= DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
65
- }
66
- else
67
- {
68
- $temp_expath = $path;
69
- }
70
 
71
- $this->restore_data->write_log('Start restoring '.$next_task['type_name'],'notice');
72
- $result = $this -> single_restore($next_task['type_name'],$temp_expath,$next_task['files']);
 
 
 
 
 
 
 
73
 
74
- WPvivid_tools::clearcache($this -> restore_data -> get_restore_data_id());
 
 
 
 
 
 
 
 
 
 
75
 
76
- if(!empty($result['table']))
77
- $table = $result['table'];
78
- if($result['result'] != WPVIVID_SUCCESS)
79
- {
80
- $this->restore_data->write_log($result['error'],'error');
81
- $this->restore_data->update_error($result,$next_task['type_name'],$table);
82
- return array('result'=>WPVIVID_RESTORE_ERROR,'error'=>array('task_name'=>$next_task['type_name'],'error'=>$result['error']));
83
- }
84
- else
85
- {
86
- $this->restore_data->write_log('Finished restoring '.$next_task['type_name'],'notice');
87
- if(!empty($table))
88
- $this->restore_data->write_log($next_task['type_name'].' restore completed: '.$table['succeed'].' succeeded, '.$table['failed'].' failed.','notice');
89
- $this->restore_data->update_sub_task_completed($next_task['type_name'],$result,$table);
90
- $this->restore_data->update_status(WPVIVID_RESTORE_WAIT);
91
- return array('result'=> WPVIVID_SUCCESS);
92
- }
93
  }
94
- }else{
95
- $error = 'Backup package is not complete.';
96
- $this->restore_data->update_error($error);
97
- $this->restore_data->write_log($error,'error');
98
- return array('result'=>WPVIVID_RESTORE_ERROR,'error'=>$error);
99
  }
100
- }
101
-
102
- function single_restore($type_name,$path,$files)
103
- {
104
- switch($type_name)
105
  {
106
- case WPVIVID_BACKUP_TYPE_DB:
107
- case WPVIVID_BACKUP_TYPE_OPTIONS:
108
- $database = new WPvivid_RestoreDB();
109
- return $database ->restore($type_name,$path,$files);
110
- case WPVIVID_BACKUP_TYPE_THEMES:
111
- $expath = WP_CONTENT_DIR;
112
- break;
113
- case WPVIVID_BACKUP_TYPE_PLUGIN:
114
- $expath = WP_CONTENT_DIR;
115
- break;
116
- case WPVIVID_BACKUP_TYPE_UPLOADS:
117
- $expath = WP_CONTENT_DIR;
118
- break;
119
- case WPVIVID_BACKUP_TYPE_CONTENT:
120
- $expath = dirname(WP_CONTENT_DIR);
121
- break;
122
- case WPVIVID_BACKUP_TYPE_CORE:
123
- $expath = dirname(WP_CONTENT_DIR);
124
- break;
125
- case WPVIVID_BACKUP_TYPE_OTHERS:
126
- $expath = dirname(WP_CONTENT_DIR);
127
- break;
128
- default:
129
- return array('result'=>'failed','error'=>'type is incorrect.');
130
- }
131
 
132
- $restore_site = new WPvivid_RestoreSite();
133
- return $restore_site -> restore($type_name,$expath,$path,$files);
 
134
 
 
 
 
 
 
135
  }
136
  }
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
+
7
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-restore-database.php';
8
+ include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-restore-site.php';
9
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-log.php';
10
  include_once plugin_dir_path( dirname( __FILE__ ) ) .'includes/class-wpvivid-zipclass.php';
 
 
 
11
 
12
+ class WPvivid_Restore
13
+ {
14
  public function restore()
15
  {
16
+ @set_time_limit(1800);
17
 
18
+ global $wpvivid_pulgin;
 
19
 
20
+ $next_task=$wpvivid_pulgin->restore_data->get_next_restore_task();
21
 
22
+ if($next_task===false)
23
+ {
24
+ $wpvivid_pulgin->restore_data->write_log('Restore task completed.','notice');
25
+ $wpvivid_pulgin->restore_data->update_status(WPVIVID_RESTORE_COMPLETED);
26
+ return array('result'=>WPVIVID_SUCCESS);
27
+ }
28
+ else if($next_task===WPVIVID_RESTORE_RUNNING)
29
  {
30
+ $wpvivid_pulgin->restore_data->update_error('A restore task is already running.');
31
+ $wpvivid_pulgin->restore_data->write_log('A restore task is already running.','error');
32
+ return array('result'=>WPVIVID_FAILED,'error'=> 'A restore task is already running.');
33
+ }
34
+ else
35
+ {
36
+ $wpvivid_pulgin->restore_data->write_log('Start restoring '.$next_task['files'][0],'notice');
37
+ $result = $this -> execute_restore($next_task);
38
+ $wpvivid_pulgin->restore_data->update_sub_task($next_task['index'],$result);
39
+ //WPvivid_tools::clearcache($this -> restore_data -> get_restore_data_id());
40
+
41
+ if($result['result'] != WPVIVID_SUCCESS)
42
  {
43
+ $wpvivid_pulgin->restore_data->update_error($result['error']);
44
+ $wpvivid_pulgin->restore_data->write_log($result['error'],'error');
45
+ return array('result'=>WPVIVID_FAILED,'error'=>$result['error']);
46
  }
47
+ else {
48
+ $wpvivid_pulgin->restore_data->write_log('Finished restoring ','notice');
49
+ $wpvivid_pulgin->restore_data->update_status(WPVIVID_RESTORE_WAIT);
50
+ return array('result'=> WPVIVID_SUCCESS);
51
  }
52
+ }
53
+ }
 
 
 
 
 
 
 
 
 
 
 
54
 
55
+ function execute_restore($restore_task)
56
+ {
57
+ global $wpvivid_pulgin;
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
+ $backup=$wpvivid_pulgin->restore_data->get_backup_data();
60
+ $backup_item=new WPvivid_Backup_Item($backup);
61
+ $json=$backup_item->get_file_info($restore_task['files'][0]);
62
+ $option=array();
63
+ if($json!==false)
64
+ {
65
+ $option=$json;
66
+ }
67
+ $option=array_merge($option,$restore_task['option']);
68
 
69
+ if(isset($option['dump_db']))
70
+ {
71
+ $restore_site = new WPvivid_RestoreSite();
72
+ $ret= $restore_site -> restore($option,$restore_task['files']);
73
+ if($ret['result']==WPVIVID_SUCCESS)
74
+ {
75
+ $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR;
76
+ $sql_file = $backup_item->get_sql_file($restore_task['files'][0]);
77
+ $wpvivid_pulgin->restore_data->write_log('sql file: '.$sql_file,'notice');
78
+ $restore_db=new WPvivid_RestoreDB();
79
+ $restore_db->restore($path,$sql_file,$option);
80
 
81
+ return array('result'=>WPVIVID_SUCCESS);
82
+ }
83
+ else
84
+ {
85
+ return $ret;
 
 
 
 
 
 
 
 
 
 
 
 
86
  }
 
 
 
 
 
87
  }
88
+ else
 
 
 
 
89
  {
90
+ $restore_site = new WPvivid_RestoreSite();
91
+ $ret= $restore_site -> restore($option,$restore_task['files']);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
+ return $ret;
94
+ }
95
+ }
96
 
97
+ private function transfer_path($path)
98
+ {
99
+ $path = str_replace('\\','/',$path);
100
+ $values = explode('/',$path);
101
+ return implode(DIRECTORY_SEPARATOR,$values);
102
  }
103
  }
includes/class-wpvivid-rollback.php CHANGED
@@ -12,7 +12,33 @@ class WPvivid_RollBack
12
 
13
  public function rollback()
14
  {
15
- @set_time_limit(600);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  $this->restore_data=new WPvivid_restore_data();
18
 
@@ -63,7 +89,39 @@ class WPvivid_RollBack
63
  return $result;
64
  }
65
 
66
- private function rollback_db($data){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
  $this->restore_data->write_rollback_log('Start rollbacking database.','notice');
68
  $File = $data['data']['file'];
69
  if(!file_exists($File)){
@@ -84,7 +142,7 @@ class WPvivid_RollBack
84
  $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
85
  }
86
  if(empty($pdo) || !$pdo){
87
- return array('result' => 'WPVIVID_FAILED','error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
88
  }
89
  }
90
 
@@ -201,7 +259,8 @@ class WPvivid_RollBack
201
  {
202
  if($filename != "." && $filename != "..")
203
  {
204
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename)){
 
205
  @mkdir(str_replace($replace_path,$temp_path,$path.DIRECTORY_SEPARATOR.$filename));
206
  $result = $this->_rollback_copy_loop($path.DIRECTORY_SEPARATOR.$filename,$temp_path,$replace_path);
207
  if($result['result'] != WPVIVID_SUCCESS)
@@ -218,4 +277,5 @@ class WPvivid_RollBack
218
  @closedir($handler);
219
  return $result;
220
  }
 
221
  }
12
 
13
  public function rollback()
14
  {
15
+ @set_time_limit(1800);
16
+
17
+ $old_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR;
18
+
19
+ if(!file_exists($old_path))
20
+ {
21
+ return array('result'=>WPVIVID_RESTORE_COMPLETED);
22
+ }
23
+
24
+ $old_db_path=$old_path.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR.'old_database.sql';
25
+
26
+ if(file_exists($old_db_path))
27
+ {
28
+ $rollback_db=new WPvivid_RestoreDB();
29
+ $options['skip_backup_old_site']=1;
30
+ $options['skip_backup_old_database']=1;
31
+ $rollback_db->restore($old_path.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR,'old_database.sql',$options);
32
+ }
33
+
34
+ $old_site_path=$old_path.DIRECTORY_SEPARATOR.'wpvivid_old_site';
35
+
36
+ if(file_exists($old_site_path))
37
+ {
38
+ $this->rollback_old_site($old_site_path);
39
+ }
40
+
41
+ return array('result'=>WPVIVID_RESTORE_COMPLETED);
42
 
43
  $this->restore_data=new WPvivid_restore_data();
44
 
89
  return $result;
90
  }
91
 
92
+ private function rollback_old_site($old_site_path)
93
+ {
94
+ $replace_path=$old_site_path;
95
+ $this->move_restore_file($old_site_path, get_home_path(),$replace_path);
96
+ }
97
+
98
+ private function move_restore_file($source_path,$destination,$replace_path)
99
+ {
100
+ $result = array('result'=>WPVIVID_SUCCESS);
101
+
102
+ $handler=opendir($source_path);
103
+ while(($filename=readdir($handler))!==false)
104
+ {
105
+ if($filename != "." && $filename != "..")
106
+ {
107
+ if(is_dir($source_path.DIRECTORY_SEPARATOR.$filename))
108
+ {
109
+ $this->move_restore_file($source_path.DIRECTORY_SEPARATOR.$filename,$destination,$replace_path);
110
+ }else {
111
+ $path=str_replace($replace_path,$destination,$source_path.DIRECTORY_SEPARATOR);
112
+ if(file_exists($path))
113
+ {
114
+ @mkdir($path);
115
+ }
116
+ @copy($source_path.DIRECTORY_SEPARATOR.$filename,$path.DIRECTORY_SEPARATOR.$filename);
117
+ }
118
+ }
119
+ }
120
+ if($handler)
121
+ @closedir($handler);
122
+ return $result;
123
+ }
124
+ /*private function rollback_db($data){
125
  $this->restore_data->write_rollback_log('Start rollbacking database.','notice');
126
  $File = $data['data']['file'];
127
  if(!file_exists($File)){
142
  $pdo=new PDO('mysql:host=' . $db_host . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD );
143
  }
144
  if(empty($pdo) || !$pdo){
145
+ return array('result' => WPVIVID_FAILED,'error' =>'The error establishing a database connection. Please check wp-config.php file and make sure the information is correct.');
146
  }
147
  }
148
 
259
  {
260
  if($filename != "." && $filename != "..")
261
  {
262
+ if(is_dir($path.DIRECTORY_SEPARATOR.$filename))
263
+ {
264
  @mkdir(str_replace($replace_path,$temp_path,$path.DIRECTORY_SEPARATOR.$filename));
265
  $result = $this->_rollback_copy_loop($path.DIRECTORY_SEPARATOR.$filename,$temp_path,$replace_path);
266
  if($result['result'] != WPVIVID_SUCCESS)
277
  @closedir($handler);
278
  return $result;
279
  }
280
+ */
281
  }
includes/class-wpvivid-setting.php CHANGED
@@ -475,6 +475,7 @@ class WPvivid_Setting
475
  $json['data']['wpvivid_upload_setting']=self::get_option('wpvivid_upload_setting');
476
  $json['data']['wpvivid_common_setting']=self::get_option('wpvivid_common_setting');
477
  $json['data']['wpvivid_email_setting']=self::get_option('wpvivid_email_setting');
 
478
  }
479
 
480
  if($history)
@@ -501,6 +502,8 @@ class WPvivid_Setting
501
  {
502
  self::update_option($option_name,$option);
503
  }
 
 
504
  }
505
 
506
  public static function set_max_backup_count($count)
475
  $json['data']['wpvivid_upload_setting']=self::get_option('wpvivid_upload_setting');
476
  $json['data']['wpvivid_common_setting']=self::get_option('wpvivid_common_setting');
477
  $json['data']['wpvivid_email_setting']=self::get_option('wpvivid_email_setting');
478
+ $json['data']['wpvivid_saved_api_token']=self::get_option('wpvivid_saved_api_token');
479
  }
480
 
481
  if($history)
502
  {
503
  self::update_option($option_name,$option);
504
  }
505
+
506
+
507
  }
508
 
509
  public static function set_max_backup_count($count)
includes/class-wpvivid-taskmanager.php CHANGED
@@ -44,6 +44,20 @@ class WPvivid_taskmanager
44
  return $ret;
45
  }
46
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  public static function new_upload_task($option,$type)
48
  {
49
  $id=uniqid('wpvivid-');
@@ -199,7 +213,9 @@ class WPvivid_taskmanager
199
  $ret['progress']=$task['data'][$ret['type']]['progress'];
200
  $ret['doing']=$task['data'][$ret['type']]['doing'];
201
  $ret['descript']=__($task['data'][$ret['type']]['sub_job'][$ret['doing']]['progress'], 'wpvivid');
 
202
  $ret['running_time']=$running_time;
 
203
  $ret['next_resume_time']=$next_resume_time;
204
  return $ret;
205
  }
@@ -327,7 +343,7 @@ class WPvivid_taskmanager
327
  }
328
  }
329
 
330
- public static function update_backup_sub_task_progress($task_id,$job_name,$sub_job_name,$finished,$progress,$job_data=array())
331
  {
332
  $task=self::get_task($task_id);
333
  if($task!==false)
@@ -341,7 +357,8 @@ class WPvivid_taskmanager
341
  }
342
  $task['data'][$job_name]['doing']=$sub_job_name;
343
  $task['data'][$job_name]['sub_job'][$sub_job_name]['finished']=$finished;
344
- $task['data'][$job_name]['sub_job'][$sub_job_name]['progress']=$progress;
 
345
  if(!empty($job_data))
346
  {
347
  $task['data'][$job_name]['sub_job'][$sub_job_name]['job_data']=$job_data;
@@ -353,6 +370,14 @@ class WPvivid_taskmanager
353
  $task['data'][$job_name]['sub_job'][$sub_job_name]['job_data']=array();
354
  }
355
  }
 
 
 
 
 
 
 
 
356
  WPvivid_Setting::update_task($task_id,$task);
357
  }
358
  }
44
  return $ret;
45
  }
46
 
47
+ public static function get_backup_task_prefix($task_id)
48
+ {
49
+ $tasks=WPvivid_Setting::get_tasks();
50
+ if(array_key_exists ($task_id,$tasks))
51
+ {
52
+ $task = $tasks[$task_id];
53
+ return $task['options']['file_prefix'];
54
+ }
55
+ else
56
+ {
57
+ return false;
58
+ }
59
+ }
60
+
61
  public static function new_upload_task($option,$type)
62
  {
63
  $id=uniqid('wpvivid-');
213
  $ret['progress']=$task['data'][$ret['type']]['progress'];
214
  $ret['doing']=$task['data'][$ret['type']]['doing'];
215
  $ret['descript']=__($task['data'][$ret['type']]['sub_job'][$ret['doing']]['progress'], 'wpvivid');
216
+ $ret['upload_data']=$task['data'][$ret['type']]['sub_job'][$ret['doing']]['upload_data'];
217
  $ret['running_time']=$running_time;
218
+ $ret['running_stamp']=$time_diff;
219
  $ret['next_resume_time']=$next_resume_time;
220
  return $ret;
221
  }
343
  }
344
  }
345
 
346
+ public static function update_backup_sub_task_progress($task_id,$job_name,$sub_job_name,$finished,$progress,$job_data=array(),$upload_data=array())
347
  {
348
  $task=self::get_task($task_id);
349
  if($task!==false)
357
  }
358
  $task['data'][$job_name]['doing']=$sub_job_name;
359
  $task['data'][$job_name]['sub_job'][$sub_job_name]['finished']=$finished;
360
+ if(!empty($progress))
361
+ $task['data'][$job_name]['sub_job'][$sub_job_name]['progress']=$progress;
362
  if(!empty($job_data))
363
  {
364
  $task['data'][$job_name]['sub_job'][$sub_job_name]['job_data']=$job_data;
370
  $task['data'][$job_name]['sub_job'][$sub_job_name]['job_data']=array();
371
  }
372
  }
373
+ if(!empty($upload_data)){
374
+ $task['data'][$job_name]['sub_job'][$sub_job_name]['upload_data']=$upload_data;
375
+ }
376
+ else{
377
+ if(!isset($task['data'][$job_name]['sub_job'][$sub_job_name]['upload_data'])){
378
+ $task['data'][$job_name]['sub_job'][$sub_job_name]['upload_data']=array();
379
+ }
380
+ }
381
  WPvivid_Setting::update_task($task_id,$task);
382
  }
383
  }
includes/class-wpvivid-upload.php CHANGED
@@ -49,6 +49,14 @@ class WPvivid_Upload
49
 
50
  public function upload_callback($offset,$current_name,$current_size,$last_time,$last_size)
51
  {
 
 
 
 
 
 
 
 
52
  $v =( $offset - $last_size ) / (time() - $last_time);
53
  $v /= 1000;
54
  $v=round($v,2);
@@ -60,12 +68,16 @@ class WPvivid_Upload
60
  $wpvivid_pulgin->wpvivid_log->WriteLog($message,'notice');
61
  $progress=intval(($offset/$current_size)*100);
62
  WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'upload',$progress,0);
63
- WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'upload','','0',$message);
64
  }
65
 
66
  public function get_backup_files($backup)
67
  {
68
- $path=WP_CONTENT_DIR.'/'.$backup['local']['path'];
 
 
 
 
69
  $files=array();
70
  $files_list=array();
71
 
@@ -89,6 +101,19 @@ class WPvivid_Upload
89
  $files_list[] = $path . DIRECTORY_SEPARATOR . $file['file_name'];
90
  }
91
 
92
- return $files_list;
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
  }
49
 
50
  public function upload_callback($offset,$current_name,$current_size,$last_time,$last_size)
51
  {
52
+ $job_data=array();
53
+ $upload_data=array();
54
+ $upload_data['offset']=$offset;
55
+ $upload_data['current_name']=$current_name;
56
+ $upload_data['current_size']=$current_size;
57
+ $upload_data['last_time']=$last_time;
58
+ $upload_data['last_size']=$last_size;
59
+ $upload_data['descript']='Uploading '.$current_name;
60
  $v =( $offset - $last_size ) / (time() - $last_time);
61
  $v /= 1000;
62
  $v=round($v,2);
68
  $wpvivid_pulgin->wpvivid_log->WriteLog($message,'notice');
69
  $progress=intval(($offset/$current_size)*100);
70
  WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'upload',$progress,0);
71
+ WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'upload','','0',$message, $job_data, $upload_data);
72
  }
73
 
74
  public function get_backup_files($backup)
75
  {
76
+ $backup_item=new WPvivid_Backup_Item($backup);
77
+
78
+ return $backup_item->get_files();
79
+
80
+ /*$path=WP_CONTENT_DIR.'/'.$backup['local']['path'];
81
  $files=array();
82
  $files_list=array();
83
 
101
  $files_list[] = $path . DIRECTORY_SEPARATOR . $file['file_name'];
102
  }
103
 
104
+ return $files_list;*/
105
+ }
106
+
107
+ public function clean_remote_backup($remotes,$files)
108
+ {
109
+ $remote_option=array_shift($remotes);
110
+
111
+ if(!is_null($remote_option))
112
+ {
113
+ global $wpvivid_pulgin;
114
+
115
+ $remote=$wpvivid_pulgin->remote_collection->get_remote($remote_option);
116
+ $remote ->cleanup($files);
117
+ }
118
  }
119
  }
includes/class-wpvivid-zipclass.php CHANGED
@@ -3,118 +3,143 @@
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
- class WPvivid_ZipClass {
 
 
 
 
 
7
  public $last_error = '';
8
-
9
  public $path_filter=array();
10
 
11
  public function __construct() {
12
  if (!class_exists('PclZip')) include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
13
  if (!class_exists('PclZip')) {
14
- $this->last_error = array('result'=>'failed','error'=>"Class PclZip is not detected. Please update or reinstall your WordPress.");
15
  }
16
  }
17
 
18
- public function zipsplit($zip_data,$files)
19
  {
20
- $filesmeta = array();
21
- $backupdata = array();
 
 
 
 
 
22
  $packages = array();
23
- $size = $zip_data['compress']['max_file_size'];
24
-
25
- if(empty($size) || $size == 0){
26
- $data = array(
27
- 'path' => $zip_data['path'],
28
- 'files' => $files,
29
- );
30
- $backupdata[] = $data;
31
- }else {
32
- $floder = dirname($zip_data['path']);
33
- $filename = basename($zip_data['path'], '.zip');
34
- $sizenum = 0;
35
- $flag = 0;
36
- $pack_num = 1;
37
- $size = $size * 1024 * 1024;
38
-
39
- foreach ($files as $file) {
40
- if (!file_exists($file))
41
- return array('result' => 'failed', 'error' => $file . ' is not found when being split. Please verify the the file exists.');
42
- $sizenum += filesize($file);
43
- if ($sizenum > $size) {
44
- if(empty($packages[$flag])){
45
- $packages[$flag][] = $file;
46
- $sizenum = filesize($file);
47
- continue;
48
- }else{
49
- $flag++;
50
- $sizenum = filesize($file);
51
- }
52
  }
53
- $packages[$flag][] = $file;
 
 
 
 
 
54
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
- if (sizeof($packages) == 1) {
57
- $backupdata[] = array(
58
- 'path' => $zip_data['path'],
59
- 'files' => $packages[0],
60
- );
61
- } else {
62
- foreach ($packages as $item){
63
- $backupdata[] = array(
64
- 'path' => $floder.DIRECTORY_SEPARATOR.$filename.'.part'.sprintf('%03d',$pack_num).'.zip',
65
- 'files' => $item,
66
- );
67
- $pack_num ++;
68
  }
 
 
 
 
 
 
 
69
  }
70
  }
71
- $dir=WPvivid_Setting::get_backupdir();
72
- $temp_dir = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.'temp-'.basename($zip_data['path'], '.zip').DIRECTORY_SEPARATOR;
73
- @mkdir($temp_dir);
74
- return $this->zip($temp_dir,$backupdata,$zip_data['replace_path'],$zip_data['compress']['no_compress'],$zip_data['compress']['use_temp_file'],$zip_data['compress']['use_temp_size']);
75
  }
76
 
77
- public function zipextract($path,$files){
78
- define(PCLZIP_TEMPORARY_DIR,$path);
79
- $flag = true;
80
- $error = '';
81
- $table = array();
82
- foreach ($files as $file){
83
- $archive = new PclZip($file);
84
- $str = $archive->extract(PCLZIP_OPT_PATH, $path,PCLZIP_OPT_REPLACE_NEWER,PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
85
- if(!$str){
86
- $flag = false;
87
- $error = $archive->errorInfo(true);
88
- break;
89
- }else{
90
- $success_num = 0;
91
- $error_num = 0;
92
- $last_error = '';
93
- foreach ($str as $item){
94
- if($item['status'] === 'ok'){
95
- $success_num ++;
96
- }else{
97
- $error_num ++;
98
- $last_error = 'restore '.$item['filename'].' failed status:'.$item['status'];
99
- }
100
- }
101
- $table['succeed'] = $success_num;
102
- $table['failed'] = $error_num;
103
- $error = $last_error;
104
  }
105
- }
106
- if($flag){
107
- return array('result'=>WPVIVID_SUCCESS,'table'=>$table,'error' => $error);
108
- }else{
109
- return array('result'=>WPVIVID_FAILED,'error'=>$error);
110
  }
111
- }
 
 
 
112
 
113
- public function zipextract_by_files($path,$files,$zip){
114
  define(PCLZIP_TEMPORARY_DIR,$path);
115
  $flag = true;
116
  $table = array();
117
  $archive = new PclZip($zip);
 
 
 
 
 
 
 
 
 
 
 
118
  $str = $archive->extract(PCLZIP_OPT_PATH, $path, PCLZIP_OPT_BY_NAME, $files, PCLZIP_OPT_REPLACE_NEWER,PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
119
  if(!$str){
120
  $flag = false;
@@ -143,10 +168,10 @@ class WPvivid_ZipClass {
143
  }
144
  }
145
 
146
- public function get_include_zip($files,$allpackages){
147
- $i = sizeof($files);
148
- $zips = array();
149
- foreach ( $allpackages as $item){
150
  $archive = new PclZip($item);
151
  $lists = $archive -> listContent();
152
  foreach ($lists as $file){
@@ -159,31 +184,124 @@ class WPvivid_ZipClass {
159
  }
160
  return $zips;
161
  }
162
- private function _in_array($file,$lists){
163
- foreach ($lists as $item){
164
- if(strstr($file,$item)){
165
- return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  }
167
  }
168
- return false;
169
- }
170
 
171
- public function getLastError(){
172
- return $this -> last_error;
173
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
174
 
175
- public function getBasename($basename){
176
- $basename = basename($basename);
177
- $arr = explode('.',$basename);
178
- return $arr[0];
 
 
 
 
 
 
 
 
 
179
  }
180
 
181
  public function listcontent($path){
182
- $zip = new PclZip($path);
183
- $list = $zip->listContent();
184
- return $list;
185
  }
186
-
187
  public function listnum($path , $includeFolder = false){
188
  $zip = new PclZip($path);
189
  $list = $zip->listContent();
@@ -196,74 +314,55 @@ class WPvivid_ZipClass {
196
  return $index;
197
  }
198
 
199
- public function zip($temp_dir,$packages,$replace_path,$no_compress=false,$use_temp_file=1,$use_temp_size=16)
200
  {
201
- define(PCLZIP_TEMPORARY_DIR,$temp_dir);
202
- $files_meta=array();
203
- global $wpvivid_pulgin;
204
- foreach ($packages as $data)
205
- {
206
- if(!empty($data['files']))
207
- {
208
- if(file_exists($data['path']))
209
- @unlink($data['path']);
210
- $archive = new PclZip($data['path']);
211
- }else{
212
- continue;
213
- }
214
 
215
- $wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to zip files. Is compress: '.$no_compress,'notice');
216
- if($no_compress)
217
- {
218
- if($use_temp_file==1)
219
- {
220
- if($use_temp_size!=0)
221
- {
222
- $str = $archive -> add($data['files'],PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_NO_COMPRESSION,PCLZIP_OPT_TEMP_FILE_THRESHOLD,$use_temp_size);
223
- }
224
- else
225
- {
226
- $str = $archive -> add($data['files'],PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_NO_COMPRESSION,PCLZIP_OPT_TEMP_FILE_ON);
227
- }
228
- }
229
- else
230
- {
231
- $str = $archive -> add($data['files'],PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_NO_COMPRESSION,PCLZIP_OPT_TEMP_FILE_OFF);
232
- }
233
- }
234
- else
235
  {
236
- if($use_temp_file==1)
 
237
  {
238
- if($use_temp_size!=0)
239
- {
240
- $str = $archive -> add($data['files'],PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_TEMP_FILE_THRESHOLD,$use_temp_size);
241
- }
242
- else
243
- {
244
- $str = $archive -> add($data['files'],PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_TEMP_FILE_ON);
245
- }
246
  }
247
  else
248
  {
249
- $str = $archive -> add($data['files'],PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_TEMP_FILE_OFF);
250
  }
251
  }
 
 
 
 
252
 
253
- if(!$str)
 
 
 
 
 
 
 
 
254
  {
255
- $wpvivid_pulgin->wpvivid_log->WriteLog('Failed to add zip files, error: '.$archive->errorInfo(true),'notice');
256
- return array('result'=>'failed','error'=>$archive->errorInfo(true));
257
  }
258
- $file_data = array();
259
- $file_data['file_name'] = basename($data['path']);
260
- $file_data['size'] = filesize($data['path']);
261
- $file_data['md5'] = md5_file($data['path']);
262
- $wpvivid_pulgin->wpvivid_log->WriteLog('Adding zip files, filename: '.$file_data['file_name'].', filesize: '.size_format($file_data['size'],2),'notice');
263
- $files_meta[] = $file_data;
264
  }
265
- $wpvivid_pulgin->wpvivid_log->WriteLog('Adding zip files completed.','notice');
266
- return array('result'=>WPVIVID_SUCCESS,'meta'=>$files_meta);
267
  }
268
  }
269
 
@@ -280,5 +379,25 @@ function wpvivid_function_per_add_callback($p_event, &$p_header)
280
  WPvivid_taskmanager::update_backup_task_status($wpvivid_pulgin->current_task['id']);
281
  }
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  return 1;
284
  }
3
  if (!defined('WPVIVID_PLUGIN_DIR')){
4
  die;
5
  }
6
+ if(!defined('WPVIVID_COMPRESS_ZIPCLASS')){
7
+ define('WPVIVID_COMPRESS_ZIPCLASS','zipclass');
8
+ }
9
+ define('WPVIVID_ZIPCLASS_JSONFILE_NAME','wpvivid_zipclass.json');
10
+ require_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-compress-default.php';
11
+ class WPvivid_ZipClass extends Wpvivid_Compress_Default{
12
  public $last_error = '';
 
13
  public $path_filter=array();
14
 
15
  public function __construct() {
16
  if (!class_exists('PclZip')) include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
17
  if (!class_exists('PclZip')) {
18
+ $this->last_error = array('result'=>WPVIVID_FAILED,'error'=>"Class PclZip is not detected. Please update or reinstall your WordPress.");
19
  }
20
  }
21
 
22
+ public function compress($data)
23
  {
24
+ global $wpvivid_pulgin;
25
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
26
+ $files = $this -> filesplit($data['compress']['max_file_size'],$data['files']);
27
+
28
+ $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR;
29
+ if(!file_exists($temp_dir))
30
+ @mkdir($temp_dir);
31
  $packages = array();
32
+ if(sizeof($files) > 1)
33
+ {
34
+ for($i =0;$i <sizeof($files);$i ++)
35
+ {
36
+ $package = array();
37
+ $path = $data['path'].$data['prefix'].'.part'.sprintf('%03d',($i +1)).'.zip';
38
+
39
+ $remove_path_size = strlen( $this -> transfer_path(get_home_path()));
40
+
41
+ if(isset($data['json_info']))
42
+ {
43
+ $package['json']=$data['json_info'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
+
46
+ $package['json']['root'] = substr($data['root_path'], $remove_path_size);
47
+ $package['json']['file']=basename($path);
48
+ $package['path'] = $path;
49
+ $package['files'] = $files[$i];
50
+ $packages[] = $package;
51
  }
52
+ }else {
53
+ $package = array();
54
+ $path = $data['path'].$data['prefix'].'.zip';
55
+
56
+ $remove_path_size = strlen( $this -> transfer_path(get_home_path()));
57
+
58
+ if(isset($data['json_info']))
59
+ {
60
+ $package['json']=$data['json_info'];
61
+ }
62
+
63
+ $package['json']['root'] = substr($data['root_path'], $remove_path_size);
64
+ $package['json']['file']=basename($path);
65
+ $package['path'] = $path;
66
+ $package['files'] = $files[0];
67
+ $packages[] = $package;
68
+ }
69
+
70
+
71
+ define(PCLZIP_TEMPORARY_DIR,$temp_dir);
72
+
73
+ $ret['result']=WPVIVID_SUCCESS;
74
+ $ret['files']=array();
75
 
76
+ foreach ($packages as $package)
77
+ {
78
+ if(!empty($package['files']))
79
+ {
80
+ $zip_ret=$this -> _zip($package['path'],$package['files'], $data,$package['json']);
81
+ if($zip_ret['result']==WPVIVID_SUCCESS)
82
+ {
83
+ $ret['files'][] = $zip_ret['file_data'];
 
 
 
 
84
  }
85
+ else
86
+ {
87
+ $ret=$zip_ret;
88
+ break;
89
+ }
90
+ }else {
91
+ continue;
92
  }
93
  }
94
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
95
+ return $ret;
 
 
96
  }
97
 
98
+ public function extract($files,$path = '')
99
+ {
100
+ global $wpvivid_pulgin;
101
+ $wpvivid_pulgin->restore_data->write_log('start prepare extract','notice');
102
+ define(PCLZIP_TEMPORARY_DIR,dirname($path));
103
+
104
+ $ret['result']=WPVIVID_SUCCESS;
105
+ foreach ($files as $file)
106
+ {
107
+ $wpvivid_pulgin->restore_data->write_log('start extract file:'.$file,'notice');
108
+ $archive = new PclZip($file);
109
+ $zip_ret = $archive->extract(PCLZIP_OPT_PATH, $path,PCLZIP_OPT_REPLACE_NEWER,PCLZIP_CB_PRE_EXTRACT,'wpvivid_function_pre_extract_callback',PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
110
+ if(!$zip_ret)
111
+ {
112
+ $ret['result']=WPVIVID_FAILED;
113
+ $ret['error'] = $archive->errorInfo(true);
114
+ $wpvivid_pulgin->restore_data->write_log('extract finished:'.json_encode($ret),'notice');
115
+ break;
116
+ }
117
+ else
118
+ {
119
+ $wpvivid_pulgin->restore_data->write_log('extract finished file:'.$file,'notice');
 
 
 
 
 
120
  }
 
 
 
 
 
121
  }
122
+ //$this->restore_data->write_log('extract finished files:'.json_encode($all_files),'notice');
123
+
124
+ return $ret;
125
+ }
126
 
127
+ public function extract_by_files($files,$zip,$path = ''){
128
  define(PCLZIP_TEMPORARY_DIR,$path);
129
  $flag = true;
130
  $table = array();
131
  $archive = new PclZip($zip);
132
+ $list = $archive -> listContent();
133
+ foreach ($list as $item){
134
+ if(strstr($item['filename'],WPVIVID_ZIPCLASS_JSONFILE_NAME)){
135
+ $result = $archive->extract(PCLZIP_OPT_BY_NAME, WPVIVID_ZIPCLASS_JSONFILE_NAME);
136
+ if($result){
137
+ $json = json_decode(file_get_contents(dirname($zip).WPVIVID_ZIPCLASS_JSONFILE_NAME),true);
138
+ $path = $json['root_path'];
139
+ }
140
+ }
141
+ }
142
+
143
  $str = $archive->extract(PCLZIP_OPT_PATH, $path, PCLZIP_OPT_BY_NAME, $files, PCLZIP_OPT_REPLACE_NEWER,PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
144
  if(!$str){
145
  $flag = false;
168
  }
169
  }
170
 
171
+ public function get_include_zip($files,$allpackages){
172
+ $i = sizeof($files);
173
+ $zips = array();
174
+ foreach ( $allpackages as $item){
175
  $archive = new PclZip($item);
176
  $lists = $archive -> listContent();
177
  foreach ($lists as $file){
184
  }
185
  return $zips;
186
  }
187
+
188
+ private function _zip($name,$files,$options,$json_info=false)
189
+ {
190
+ if(file_exists($name))
191
+ @unlink($name);
192
+ $archive = new PclZip($name);
193
+
194
+ if(isset($options['compress']['no_compress']))
195
+ {
196
+ $no_compress=1;
197
+ }
198
+ else
199
+ {
200
+ $no_compress=0;
201
+ }
202
+
203
+ if(isset($options['compress']['use_temp_file']))
204
+ {
205
+ $use_temp_file=1;
206
+ }
207
+ else
208
+ {
209
+ $use_temp_file=0;
210
+ }
211
+
212
+ if(isset($options['compress']['use_temp_size']))
213
+ {
214
+ $use_temp_size=$options['compress']['use_temp_size'];
215
+ }
216
+ else
217
+ {
218
+ $use_temp_size=16;
219
+ }
220
+
221
+ if(isset($options['root_path']))
222
+ {
223
+ $replace_path=$options['root_path'];
224
+ }
225
+ else
226
+ {
227
+ $replace_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
228
+ }
229
+ global $wpvivid_pulgin;
230
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to zip files. Is compress: '.$no_compress,'notice');
231
+ if($no_compress)
232
+ {
233
+ if($use_temp_file==1)
234
+ {
235
+ if($use_temp_size!=0)
236
+ {
237
+ $ret = $archive -> add($files,PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_NO_COMPRESSION,PCLZIP_OPT_TEMP_FILE_THRESHOLD,$use_temp_size);
238
+ }
239
+ else
240
+ {
241
+ $ret = $archive -> add($files,PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_NO_COMPRESSION,PCLZIP_OPT_TEMP_FILE_ON);
242
+ }
243
+ }
244
+ else
245
+ {
246
+ $ret = $archive -> add($files,PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_NO_COMPRESSION,PCLZIP_OPT_TEMP_FILE_OFF);
247
+ }
248
+ }
249
+ else
250
+ {
251
+ if($use_temp_file==1)
252
+ {
253
+ if($use_temp_size!=0)
254
+ {
255
+ $ret = $archive -> add($files,PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_TEMP_FILE_THRESHOLD,$use_temp_size);
256
+ }
257
+ else
258
+ {
259
+ $ret = $archive -> add($files,PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_TEMP_FILE_ON);
260
+ }
261
+ }
262
+ else
263
+ {
264
+ $ret = $archive -> add($files,PCLZIP_OPT_REMOVE_PATH,$replace_path,PCLZIP_CB_PRE_ADD,'wpvivid_function_per_add_callback',PCLZIP_OPT_TEMP_FILE_OFF);
265
  }
266
  }
 
 
267
 
268
+ if(!$ret)
269
+ {
270
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Failed to add zip files, error: '.$archive->errorInfo(true),'notice');
271
+ return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true));
272
+ }
273
+
274
+ if($json_info!==false)
275
+ {
276
+ $json_info['md5']=md5_file($name);
277
+
278
+ $temp_path = dirname($name).DIRECTORY_SEPARATOR.'wpvivid_package_info.json';
279
+
280
+ if(file_exists($temp_path))
281
+ {
282
+ @unlink($temp_path);
283
+ }
284
 
285
+ file_put_contents($temp_path,print_r(json_encode($json_info),true));
286
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Adding zip files, filename: '.basename($name).', filesize: '.size_format(filesize($name),2),'notice');
287
+ $archive -> add($temp_path,PCLZIP_OPT_REMOVE_PATH,dirname($temp_path));
288
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Adding zip files completed.','notice');
289
+ @unlink($temp_path);
290
+ }
291
+
292
+ $file_data = array();
293
+ $file_data['file_name'] = basename($name);
294
+ $file_data['size'] = filesize($name);
295
+ $file_data['md5'] = md5_file($name);
296
+
297
+ return array('result'=>WPVIVID_SUCCESS,'file_data'=>$file_data);
298
  }
299
 
300
  public function listcontent($path){
301
+ $zip = new PclZip($path);
302
+ $list = $zip->listContent();
303
+ return $list;
304
  }
 
305
  public function listnum($path , $includeFolder = false){
306
  $zip = new PclZip($path);
307
  $list = $zip->listContent();
314
  return $index;
315
  }
316
 
317
+ private function transfer_path($path)
318
  {
319
+ $path = str_replace('\\','/',$path);
320
+ $values = explode('/',$path);
321
+ return implode(DIRECTORY_SEPARATOR,$values);
322
+ }
 
 
 
 
 
 
 
 
 
323
 
324
+ public function get_json_data($path)
325
+ {
326
+ $archive = new PclZip($path);
327
+ $list = $archive->listContent();
328
+
329
+ foreach ($list as $item)
330
+ {
331
+ //index
332
+ if(basename($item['filename'])==='wpvivid_package_info.json')
 
 
 
 
 
 
 
 
 
 
 
333
  {
334
+ $result = $archive->extract(PCLZIP_OPT_BY_NAME, 'wpvivid_package_info.json',PCLZIP_OPT_EXTRACT_AS_STRING);
335
+ if($result != 0)
336
  {
337
+ return $result[0]['content'];
 
 
 
 
 
 
 
338
  }
339
  else
340
  {
341
+ return false;
342
  }
343
  }
344
+ }
345
+
346
+ return false;
347
+ }
348
 
349
+ public function list_file($path)
350
+ {
351
+ $archive = new PclZip($path);
352
+ $list = $archive->listContent();
353
+
354
+ $files=array();
355
+ foreach ($list as $item)
356
+ {
357
+ if(basename($item['filename'])==='wpvivid_package_info.json')
358
  {
359
+ continue;
 
360
  }
361
+ $file['file_name']=$item['filename'];
362
+ $files[]=$file;
 
 
 
 
363
  }
364
+
365
+ return $files;
366
  }
367
  }
368
 
379
  WPvivid_taskmanager::update_backup_task_status($wpvivid_pulgin->current_task['id']);
380
  }
381
 
382
+ return 1;
383
+ }
384
+
385
+ function wpvivid_function_pre_extract_callback($p_event, &$p_header)
386
+ {
387
+ if(strpos($p_header['filename'],'wp-content/plugins/wpvivid-backuprestore')!==false)
388
+ {
389
+ return 0;
390
+ }
391
+
392
+ if(strpos($p_header['filename'],'wp-config.php')!==false)
393
+ {
394
+ return 0;
395
+ }
396
+
397
+ if(strpos($p_header['filename'],'wpvivid_package_info.json')!==false)
398
+ {
399
+ return 0;
400
+ }
401
+
402
  return 1;
403
  }
includes/class-wpvivid.php CHANGED
@@ -47,6 +47,11 @@ class WPvivid {
47
 
48
  public $end_shutdown_function;
49
 
 
 
 
 
 
50
  public function __construct()
51
  {
52
  $this->version = WPVIVID_PLUGIN_VERSION;
@@ -55,6 +60,8 @@ class WPvivid {
55
 
56
  $this->end_shutdown_function = false;
57
 
 
 
58
  //Load dependent files
59
  $this->load_dependencies();
60
 
@@ -145,7 +152,15 @@ class WPvivid {
145
 
146
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-remote-collection.php';
147
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-upload.php';
 
 
 
 
 
 
148
  $this->remote_collection=new WPvivid_Remote_collection();
 
 
149
  }
150
 
151
  private function set_locale()
@@ -159,6 +174,7 @@ class WPvivid {
159
  $plugin_admin = new WPvivid_Admin($this->get_plugin_name(), $this->get_version());
160
 
161
  add_action('admin_enqueue_scripts',array( $plugin_admin,'enqueue_styles'));
 
162
  add_action('admin_enqueue_scripts',array( $plugin_admin,'enqueue_scripts'));
163
 
164
  // Add menu item
@@ -305,34 +321,6 @@ class WPvivid {
305
  return $this->version;
306
  }
307
 
308
- public function check_backup_options_valid($backup_options)
309
- {
310
- if (!isset($backup_options['backup_files']) || !isset($backup_options['local'])||!isset($backup_options['remote']) || !isset($backup_options['ismerge'])||!isset($backup_options['lock']))
311
- {
312
- return false;
313
- }
314
-
315
- if(!is_string($backup_options['backup_files'])||!is_string($backup_options['local'])||!is_string($backup_options['remote'])||!is_string($backup_options['ismerge'])||!is_string($backup_options['lock']))
316
- {
317
- return false;
318
- }
319
-
320
- $backup_type= array('files+db','files', 'db');
321
- if(!in_array($backup_options['backup_files'],$backup_type))
322
- {
323
- return false;
324
- }
325
-
326
- if($backup_options['remote']=='1')
327
- {
328
- if(WPvivid_Setting::get_remote_options()===false)
329
- {
330
- return false;
331
- }
332
- }
333
-
334
- return $backup_options;
335
- }
336
  /**
337
  * Prepare backup include what you want to backup,where you want to store.
338
  *
@@ -360,22 +348,14 @@ class WPvivid {
360
  echo json_encode($ret);
361
  die();
362
  }
363
- add_filter('wpvivid_check_backup_options_valid',array($this,'check_backup_options_valid'),10);
364
- $backup_options=apply_filters('wpvivid_check_backup_options_valid',$backup_options);
365
 
366
- if($backup_options===false)
367
- {
368
- $ret['result']='failed';
369
- $ret['error']=__('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid');
370
- echo json_encode($ret);
371
- die();
372
- }
373
  $ret=$this->pre_backup($backup_options,'Manual');
374
  if($ret['result']=='success')
375
  {
376
  //Check the website data to be backed up
377
  $ret['check']=$this->check_backup($ret['task_id'],$backup_options['backup_files']);
378
- if(isset($ret['check']['result']) && $ret['check']['result'] == WPVIVID_FAILED){
 
379
  echo json_encode(array('result' => WPVIVID_FAILED,'error' => $ret['check']['error']));
380
  die();
381
  }
@@ -429,8 +409,8 @@ class WPvivid {
429
  return $ret;
430
  }
431
  }
432
-
433
  $ret['result']=WPVIVID_SUCCESS;
 
434
  return $ret;
435
  }
436
  /**
@@ -687,12 +667,11 @@ class WPvivid {
687
  $schedule_options['backup']['remote']=strval($schedule_options['backup']['remote']);
688
  $schedule_options['backup']['ismerge']=strval($schedule_options['backup']['ismerge']);
689
  $schedule_options['backup']['lock']=strval($schedule_options['backup']['lock']);
690
- //Initialization backup task.
691
- add_filter('wpvivid_check_backup_options_valid',array($this,'check_backup_options_valid'),10);
692
- $schedule_options['backup']=apply_filters('wpvivid_check_backup_options_valid',$schedule_options['backup']);
693
 
694
- if($schedule_options['backup']===false)
 
695
  {
 
696
  die();
697
  }
698
 
@@ -760,42 +739,21 @@ class WPvivid {
760
 
761
  if(!empty($task))
762
  {
763
- if($task['data']['backup']['finished']==0)
764
- {
765
- $backup=new WPvivid_Backup();
766
- $backup->clean_backup($task['options']['file_prefix'],$task['options']['backup_options']['dir']);
767
- }
768
 
769
  $files=array();
770
 
771
  if($task['options']['remote_options']!==false)
772
  {
773
- if(array_key_exists('backup',$task['data']))
 
774
  {
775
- if($task['data']['backup']['finished']==1)
776
- {
777
- $backup_ret=$task['data']['backup']['job_data'];
778
- if ($backup_ret['ismerge'])
779
- {
780
- foreach ($backup_ret['data']['meta']['files'] as $file)
781
- {
782
- $files[] = $file['file_name'];
783
- }
784
- } else {
785
- foreach ($backup_ret['data']['type'] as $type)
786
- {
787
- foreach ($type['files'] as $file)
788
- {
789
- $files[] =$file['file_name'];
790
- }
791
- }
792
- }
793
- }
794
  }
795
-
796
  if(!empty($files))
797
  {
798
- $upload=new WPvivid_Backup();
799
  $upload->clean_remote_backup($task['options']['remote_options'],$files);
800
  }
801
  }
@@ -818,7 +776,17 @@ class WPvivid {
818
 
819
  if(!empty($backup))
820
  {
821
- $files=array();
 
 
 
 
 
 
 
 
 
 
822
  $download_dir=$backup['local']['path'];
823
  if($backup['backup']['ismerge'])
824
  {
@@ -854,10 +822,12 @@ class WPvivid {
854
  {
855
  unlink($download_path);
856
  }
857
- }
858
 
859
  if(!empty($backup['remote']))
860
  {
 
 
861
  foreach($backup['remote'] as $remote)
862
  {
863
  WPvivid_downloader::delete($remote,$files);
@@ -874,6 +844,11 @@ class WPvivid {
874
  */
875
  public function clean_oldest_backup()
876
  {
 
 
 
 
 
877
  $count=WPvivid_Setting::get_max_backup_count();
878
  $ret=WPvivid_Backuplist::check_backuplist_limit($count);
879
  if($ret['result']=='need_delete')
@@ -908,53 +883,9 @@ class WPvivid {
908
  return $ret;
909
  }
910
 
911
- $task_options = array();
912
- add_filter('wpvivid_set_backup_task_options',array($this,'set_backup_task_options'),10, 2);
913
- $task_options=apply_filters('wpvivid_set_backup_task_options',$task_options, $backup_options);
914
- return WPvivid_taskmanager::new_backup_task($task_options,$type);
915
- }
916
- public function set_backup_task_options($task_options, $backup_options)
917
- {
918
- $task_options['backup_options']=WPvivid_Setting::get_backup_options($backup_options['backup_files']);
919
- if($backup_options['ismerge']=='1')
920
- {
921
- $task_options['ismerge']=1;
922
- }
923
- else
924
- {
925
- $task_options['ismerge']=0;
926
- }
927
-
928
- $options=WPvivid_Setting::get_option('wpvivid_common_setting');
929
- if(isset($options['max_execution_time']))
930
- {
931
- $task_options['max_execution_time']=$options['max_execution_time'];
932
- }
933
- else
934
- {
935
- $task_options['max_execution_time']=WPVIVID_MAX_EXECUTION_TIME;
936
- }
937
-
938
- if($backup_options['remote']=='1')
939
- {
940
- $task_options['remote_options']=WPvivid_Setting::get_remote_options();
941
- }
942
- else {
943
- $task_options['remote_options']=false;
944
- }
945
-
946
- //set from backup post
947
- if($backup_options['local']=='1')
948
- {
949
- $task_options['save_local']=1;
950
- }
951
- else
952
- {
953
- $task_options['save_local']=0;
954
- }
955
-
956
- $task_options['lock']=$backup_options['lock'];
957
- return $task_options;
958
  }
959
 
960
  /**
@@ -1066,7 +997,8 @@ class WPvivid {
1066
  }
1067
  }
1068
 
1069
- public function wpvivid_analysis_backup($task){
 
1070
  if($task['type'] == 'Cron')
1071
  {
1072
  $cron_backup_count = WPvivid_Setting::get_option('cron_backup_count');
@@ -1118,7 +1050,6 @@ class WPvivid {
1118
  {
1119
  $task=WPvivid_taskmanager::update_backup_task_status($task_id,false,'completed');
1120
  do_action('wpvivid_handle_upload_succeed',$task);
1121
-
1122
  }
1123
  else
1124
  {
@@ -1139,10 +1070,8 @@ class WPvivid {
1139
  if($save_local==0)
1140
  {
1141
  $this->wpvivid_log->WriteLog('Cleaned up local files after uploading to remote storages.','notice');
1142
- $file_prefix=$task['options']['file_prefix'];
1143
- $backup_options=$task['options']['backup_options'];
1144
- $backup=new WPvivid_Backup();
1145
- $backup->clean_backup($file_prefix,$backup_options['dir']);
1146
  }
1147
  $this->wpvivid_log->WriteLog('Upload succeeded.','notice');
1148
  $remote_options=$task['options']['remote_options'];
@@ -1151,16 +1080,19 @@ class WPvivid {
1151
 
1152
  function wpvivid_handle_backup_succeed($task)
1153
  {
1154
- $backup_success_count=WPvivid_Setting::get_option('wpvivid_backup_success_count');
1155
- if(empty($backup_success_count)){
1156
- $backup_success_count=0;
 
 
 
 
 
 
 
1157
  }
1158
- $backup_success_count++;
1159
- WPvivid_Setting::update_option('wpvivid_backup_success_count', $backup_success_count);
1160
- $this->wpvivid_analysis_backup($task);
1161
  WPvivid_Schedule::clear_monitor_schedule($task['id']);
1162
  WPvivid_mail_report::send_report_mail($task);
1163
- $this->wpvivid_log->CloseFile();
1164
  }
1165
 
1166
  function wpvivid_mark_task($task)
@@ -1170,15 +1102,21 @@ class WPvivid {
1170
 
1171
  function wpvivid_handle_backup_failed($task)
1172
  {
1173
- $backup_error_array=WPvivid_Setting::get_option('wpvivid_backup_error_array');
1174
- if(empty($backup_error_array)){
1175
- $backup_error_array=array();
1176
- }
1177
- if(!array_key_exists($task['id'], $backup_error_array['bu_error'])){
1178
- $backup_error_array['bu_error']['task_id'] = $task['id'];
1179
- $backup_error_array['bu_error']['error_msg'] = $task['status']['error'];
1180
- WPvivid_Setting::update_option('wpvivid_backup_error_array', $backup_error_array);
 
 
 
 
 
1181
  }
 
1182
  WPvivid_error_log::create_error_log($this->wpvivid_log->log_file);
1183
  $this->wpvivid_log->CloseFile();
1184
  WPvivid_Schedule::clear_monitor_schedule($task['id']);
@@ -1188,36 +1126,53 @@ class WPvivid {
1188
 
1189
  public function deal_shutdown_error($task_id)
1190
  {
1191
- if($this->end_shutdown_function===false) {
 
1192
  $last_error = error_get_last();
1193
- if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE), true)) {
 
1194
  $error = $last_error;
1195
  } else {
1196
  $error = false;
1197
  }
1198
  //$this->task_monitor($task_id,$error);
1199
- if (WPvivid_taskmanager::get_task($task_id) !== false) {
1200
- if ($this->wpvivid_log->log_file_handle == false) {
 
 
1201
  $this->wpvivid_log->OpenLogFile(WPvivid_taskmanager::get_task_options($task_id, 'log_file_name'));
1202
  }
1203
 
1204
  $status = WPvivid_taskmanager::get_backup_task_status($task_id);
1205
 
1206
- if ($status['str'] == 'running' || $status['str'] == 'error' || $status['str'] == 'no_responds') {
1207
- $limit = WPvivid_taskmanager::get_task_options($task_id, 'max_execution_time');
 
 
 
 
 
 
 
 
 
 
1208
  $time_spend = time() - $status['timeout'];
1209
 
1210
- if ($time_spend >= $limit) {
 
1211
  //time out
1212
  $status['resume_count']++;
1213
- if ($status['resume_count'] > WPVIVID_RESUME_RETRY_TIMES) {
 
1214
  $message = __('Too many resumption attempts.', 'wpvivid');
1215
  $task = WPvivid_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
1216
  do_action('wpvivid_handle_backup_failed', $task);
1217
  } else {
1218
  $this->check_cancel_backup($task_id);
1219
  $message = 'Task timed out.';
1220
- if ($this->add_resume_event($task_id)) {
 
1221
  WPvivid_taskmanager::update_backup_task_status($task_id, false, 'wait_resume', false, $status['resume_count']);
1222
  } else {
1223
  $task = WPvivid_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
@@ -1227,8 +1182,10 @@ class WPvivid {
1227
  if ($this->wpvivid_log)
1228
  $this->wpvivid_log->WriteLog($message, 'error');
1229
  } else {
1230
- if ($status['str'] != 'error') {
1231
- if ($error !== false) {
 
 
1232
  $message = $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
1233
  } else {
1234
  $message = __('backup failed error unknown', 'wpvivid');
@@ -1265,7 +1222,15 @@ class WPvivid {
1265
  {
1266
  if($second==0)
1267
  {
1268
- $second=WPvivid_taskmanager::get_task_options($task_id,'max_execution_time');
 
 
 
 
 
 
 
 
1269
  }
1270
  WPvivid_taskmanager::update_backup_task_status($task_id,false,'',true);
1271
  @set_time_limit($second);
@@ -1292,7 +1257,15 @@ class WPvivid {
1292
 
1293
  if($status['str']=='running'||$status['str']=='error'||$status['str']=='no_responds')
1294
  {
1295
- $limit=WPvivid_taskmanager::get_task_options($task_id,'max_execution_time');
 
 
 
 
 
 
 
 
1296
  $time_spend=time()-$status['timeout'];
1297
 
1298
  if($time_spend>=$limit)
@@ -1361,7 +1334,7 @@ class WPvivid {
1361
  *
1362
  * @since 0.9.1
1363
  */
1364
- public function check_backup($task_id,$backup_files,$backup_option=array())
1365
  {
1366
  $ret['alert_db']=false;
1367
  $ret['alter_files']=false;
@@ -1381,19 +1354,6 @@ class WPvivid {
1381
  }
1382
  }
1383
 
1384
- $memory_limit = ini_get('memory_limit');
1385
- $ret['memory_limit']=$memory_limit;
1386
- $memory_limit = trim($memory_limit);
1387
- $memory_limit_int = (int) $memory_limit;
1388
- $last = strtolower(substr($memory_limit, -1));
1389
-
1390
- if($last == 'g')
1391
- $memory_limit_int = $memory_limit_int*1024*1024*1024;
1392
- if($last == 'm')
1393
- $memory_limit_int = $memory_limit_int*1024*1024;
1394
- if($last == 'k')
1395
- $memory_limit_int = $memory_limit_int*1024;
1396
-
1397
  $db_size=false;
1398
  $file_size=false;
1399
  $check_file=false;
@@ -1482,6 +1442,20 @@ class WPvivid {
1482
  {
1483
  $alter_sum_rows=4000000*3;
1484
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1485
  if($dbSize>($memory_limit_int*0.9))
1486
  {
1487
  $max_rows=0;
@@ -1503,63 +1477,16 @@ class WPvivid {
1503
  $ret['alter_fcgi']=true;
1504
  }
1505
 
1506
- if($task_id!==false)
1507
- WPvivid_taskmanager::update_backup_db_task_info($task_id,$db_info);
1508
-
1509
  $db_size=$this->formatBytes($dbSize);
1510
  }
1511
  if($check_file)
1512
  {
1513
  include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-backup.php';
1514
- $backup = new WPvivid_Backup();
1515
-
1516
- $files=array();
1517
- if($task_id!==false)
1518
- {
1519
- $backup_option=WPvivid_taskmanager::get_task_options($task_id,'backup_options');
1520
- }
1521
- $exclude_size=$backup_option['compress']['exclude_file_size'];
1522
- foreach ( $backup_option['backup']['backup_type'] as $type_name=>$data)
1523
- {
1524
- $path=false;
1525
- $options = WPvivid_Setting::get_option('wpvivid_common_setting');
1526
- if(!isset($options['log_save_location']))
1527
- {
1528
- WPvivid_Setting::set_default_common_option();
1529
- $options = WPvivid_Setting::get_option('wpvivid_common_setting');
1530
- }
1531
- $path = $backup->get_default_directory($type_name);
1532
- $exclude_regex = $backup -> get_default_exclude_regex($type_name);
1533
-
1534
- if(!empty($path))
1535
- {
1536
- $this->get_dir_files($files[$type_name],$temp,$path,$exclude_regex,array(),array(),$exclude_size);
1537
- }
1538
- }
1539
-
1540
- $sum_size=0;
1541
- $sum_count=0;
1542
- foreach ($files as $type_name=>$type_files)
1543
- {
1544
- $size=0;
1545
- if(is_array($type_files))
1546
- {
1547
- foreach ($type_files as $file)
1548
- {
1549
- $_file_size=filesize($file);
1550
- if($_file_size>($memory_limit_int*0.9))
1551
- {
1552
- $ret['alter_big_file']=true;
1553
- $ret['alter_files']=true;
1554
- }
1555
- $size+=$_file_size;
1556
- $sum_count++;
1557
- }
1558
- $file_size[$type_name]=$this->formatBytes($size);
1559
- $sum_size+=$size;
1560
- }
1561
- }
1562
 
 
 
 
1563
  if($alter_fcgi)
1564
  {
1565
  $alter_sum_size=1024*1024*1024;
@@ -1575,7 +1502,7 @@ class WPvivid {
1575
  {
1576
  $ret['alter_files']=true;
1577
  $ret['sum_size']=$this->formatBytes($sum_size);
1578
- $ret['sum_count']=$this->formatBytes($sum_size);
1579
  $ret['file_size']=$file_size;
1580
  if($alter_fcgi)
1581
  $ret['alter_fcgi']=true;
@@ -1589,7 +1516,10 @@ class WPvivid {
1589
  $ret['db_size']=$db_size;
1590
  $ret['file_size']=$file_size;
1591
  if($task_id!==false)
1592
- WPvivid_taskmanager::update_file_and_db_info($task_id,$db_size,$file_size);
 
 
 
1593
  return $ret;
1594
  }
1595
  /**
@@ -1770,20 +1700,18 @@ class WPvivid {
1770
  {
1771
  if(WPvivid_taskmanager::get_task($task_id)!==false)
1772
  {
1773
- $file_name=WPvivid_taskmanager::get_task_options($task_id,'file_prefix');
1774
- $backup_options=WPvivid_taskmanager::get_task_options($task_id,'backup_options');
1775
-
1776
- $file=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_options['dir'].DIRECTORY_SEPARATOR.$file_name.'_cancel';
1777
 
1778
- if(file_exists($file))
1779
  {
1780
  if($this->wpvivid_log->log_file_handle==false)
1781
  {
1782
  $this->wpvivid_log->OpenLogFile(WPvivid_taskmanager::get_task_options($task_id,'log_file_name'));
1783
  }
1784
-
1785
  $this->wpvivid_log->WriteLog('Backup cancelled.','notice');
1786
- WPvivid_taskmanager::update_backup_task_status($task_id,false,'cancel',false);
 
 
1787
  $this->add_clean_backing_up_data_event($task_id);
1788
  WPvivid_Schedule::clear_monitor_schedule($task_id);
1789
  WPvivid_taskmanager::delete_task($task_id);
@@ -1930,7 +1858,13 @@ class WPvivid {
1930
  return $ret;
1931
  }
1932
 
1933
- if($backup['backup']['ismerge']==1)
 
 
 
 
 
 
1934
  {
1935
  $type_list[]='all';
1936
 
@@ -1941,14 +1875,14 @@ class WPvivid {
1941
  {
1942
  $type_list[]=$type['type_name'];
1943
  }
1944
- }
1945
- $ret['data']=array();
1946
  foreach ($type_list as $type_name)
1947
  {
1948
- $ret['data']['type'][$type_name]=$this->check_backup_download($backup_id,$type_name);
1949
- }
1950
 
1951
- WPvivid_taskmanager::update_download_cache($backup_id,$ret['data']);
1952
  return $ret;
1953
  }
1954
  public function check_backup_download($backup_id,$check_type)
@@ -2334,7 +2268,7 @@ class WPvivid {
2334
  {
2335
  $this->ajax_check_security();
2336
 
2337
- if(isset($_REQUEST['backup_id'])&&isset($_REQUEST['download_type'])&&isset($_REQUEST['file_name']))
2338
  {
2339
  if(!empty($_REQUEST['backup_id'])&&is_string($_REQUEST['backup_id']))
2340
  {
@@ -2354,15 +2288,6 @@ class WPvivid {
2354
  die();
2355
  }
2356
 
2357
- if(!empty($_REQUEST['download_type'])&&is_string($_REQUEST['download_type']))
2358
- {
2359
- $download_type=sanitize_text_field($_REQUEST['download_type']);
2360
- }
2361
- else
2362
- {
2363
- die();
2364
- }
2365
-
2366
  $cache=WPvivid_taskmanager::get_download_cache($backup_id);
2367
  if($cache===false)
2368
  {
@@ -2370,15 +2295,12 @@ class WPvivid {
2370
  $cache=WPvivid_taskmanager::get_download_cache($backup_id);
2371
  }
2372
  $path=false;
2373
- if(array_key_exists($download_type,$cache['type']))
2374
  {
2375
- if(array_key_exists($file_name,$cache['type'][$download_type]['files']))
2376
- {
2377
- if($cache['type'][$download_type]['files'][$file_name]['status']=='completed')
2378
- {
2379
- $path=$cache['type'][$download_type]['files'][$file_name]['download_path'];
2380
- }
2381
- }
2382
  }
2383
  if($path!==false)
2384
  {
@@ -2514,7 +2436,9 @@ class WPvivid {
2514
  return $ret;
2515
  }
2516
 
2517
- if(array_key_exists('lock',$backup))
 
 
2518
  {
2519
  if($force==0)
2520
  {
@@ -2524,47 +2448,19 @@ class WPvivid {
2524
  }
2525
  }
2526
 
2527
- $files=array();
2528
- $download_dir=$backup['local']['path'];
2529
- if($backup['backup']['ismerge'])
2530
- {
2531
- foreach ($backup['backup']['data']['meta']['files'] as $file)
2532
- {
2533
- $files[]=$file['file_name'];
2534
- // $files[]=$file['file_name'].'.txt';
2535
- }
2536
-
2537
- // foreach ($backup['backup']['data']['type'] as $type)
2538
- // {
2539
- // foreach ($type['files'] as $file)
2540
- // {
2541
- // $files[]=$file['file_name'].'.txt';
2542
- // }
2543
- // }
2544
- }
2545
- else
2546
- {
2547
- foreach ($backup['backup']['data']['type'] as $type)
2548
- {
2549
- foreach ($type['files'] as $file)
2550
- {
2551
- $files[]=$file['file_name'];
2552
- }
2553
- }
2554
- }
2555
 
2556
  foreach ($files as $file)
2557
  {
2558
- $download_path = WP_CONTENT_DIR .DIRECTORY_SEPARATOR . $download_dir . DIRECTORY_SEPARATOR . $file;
2559
- if (file_exists($download_path))
2560
  {
2561
- unlink($download_path);
2562
  }
2563
-
2564
  }
2565
 
2566
  if(!empty($backup['remote']))
2567
  {
 
2568
  foreach($backup['remote'] as $remote)
2569
  {
2570
  WPvivid_downloader::delete($remote,$files);
@@ -2594,7 +2490,19 @@ class WPvivid {
2594
 
2595
  $files=array();
2596
  $download_dir=$backup['local']['path'];
2597
- if($backup['backup']['ismerge'])
 
 
 
 
 
 
 
 
 
 
 
 
2598
  {
2599
  foreach ($backup['backup']['data']['meta']['files'] as $file)
2600
  {
@@ -2619,7 +2527,7 @@ class WPvivid {
2619
  $files[]=$file['file_name'];
2620
  }
2621
  }
2622
- }
2623
 
2624
  foreach ($files as $file)
2625
  {
@@ -2888,39 +2796,78 @@ class WPvivid {
2888
 
2889
  public function scan_last_restore()
2890
  {
2891
- $restore_data=new WPvivid_restore_data();
2892
-
2893
- if($restore_data->has_restore())
2894
  {
2895
- $ret['has_exist_restore']=1;
2896
- $status=$restore_data->get_rollback_status();
2897
- $ret['restore_status']=$status;
2898
- if($status === WPVIVID_RESTORE_ERROR)
2899
  {
2900
- $ret['restore_error']=$restore_data->get_rollback_error();
 
 
 
 
2901
  }
2902
- $ret['restore_log']=$restore_data->get_log_content();
2903
- }
2904
- else
2905
- {
2906
- $ret['has_exist_restore']=0;
2907
- }
2908
 
2909
- if($restore_data->has_old_files())
2910
- {
2911
- $ret['has_old_files']=1;
 
 
 
 
 
2912
  }
2913
- else
2914
  {
2915
- $ret['has_old_files']=0;
 
 
 
2916
  }
 
 
2917
  return $ret;
2918
  }
2919
  public function init_restore_page()
2920
  {
2921
  $this->ajax_check_security();
2922
 
2923
- echo json_encode($this->scan_last_restore());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2924
  die();
2925
  }
2926
 
@@ -2928,8 +2875,8 @@ class WPvivid {
2928
  {
2929
  $this->ajax_check_security();
2930
 
2931
- $restore_data=new WPvivid_restore_data();
2932
- $restore_data->clean_restore_data();
2933
  $ret['result']='success';
2934
  echo json_encode($ret);
2935
  die();
@@ -2937,8 +2884,8 @@ class WPvivid {
2937
 
2938
  public function delete_old_files()
2939
  {
2940
- $restore_data=new WPvivid_restore_data();
2941
- $restore_data->delete_old_files();
2942
  $ret['result']='success';
2943
  echo json_encode($ret);
2944
  die();
@@ -2952,56 +2899,34 @@ class WPvivid {
2952
  {
2953
  $this->ajax_check_security();
2954
 
2955
- if(!isset($_POST['backup_id'])||empty($_POST['backup_id'])||!is_string($_POST['backup_id'])||!isset($_POST['restore_options'])||empty($_POST['restore_options'])||!is_string($_POST['restore_options']))
2956
  {
2957
  die();
2958
  }
2959
 
2960
  $backup_id =sanitize_key($_POST['backup_id']);
2961
- $json = $_POST['restore_options'];
2962
- $json = stripslashes($json);
2963
- $restore_options = json_decode($json, 1);
2964
- if(is_null($restore_options))
2965
- {
2966
- die();
2967
- }
2968
  $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2969
 
2970
- $download_dir = $backup['local']['path'];
2971
- $file_path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $download_dir . DIRECTORY_SEPARATOR;
2972
- $remotes = $backup['remote'];
2973
- $files = array();
2974
 
2975
- if ($backup['backup']['ismerge'] == 1) {
2976
- $files = $backup['backup']['data']['meta']['files'];
2977
- } else {
2978
- foreach ($restore_options as $option)
2979
- {
2980
- foreach ($backup['backup']['data']['type'] as $backup_type)
2981
- {
2982
- if ($backup_type['type_name'] == $option)
2983
- {
2984
- foreach ($backup_type['files'] as $file)
2985
- {
2986
- $files[] = $file;
2987
- }
2988
- break;
2989
- }
2990
- }
2991
- }
2992
- }
2993
 
2994
- if (empty($remotes))
2995
  {
2996
- $remote=false;
2997
  }
2998
  else
2999
  {
3000
- $remote=true;
3001
  }
3002
 
3003
- $ret=WPvivid_downloader::check_restore_files_status($files,$file_path,$remote);
3004
-
3005
  echo json_encode($ret);
3006
  die();
3007
  }
@@ -3034,11 +2959,13 @@ class WPvivid {
3034
  echo json_encode(array('result' => WPVIVID_FAILED ,'error'=>'backup not found'));
3035
  die();
3036
  }
3037
- $local_path=$backup['local']['path'];
3038
- $remotes=$backup['remote'];
3039
- $remote_option=array_shift($remotes);
3040
 
3041
- if(is_null($remote_option))
 
 
 
 
 
3042
  {
3043
  echo json_encode(array('result' => WPVIVID_FAILED ,'error'=>'Retrieving the cloud storage information failed while downloading backups. Please try again later.'));
3044
  die();
@@ -3050,6 +2977,33 @@ class WPvivid {
3050
  echo json_encode($ret);
3051
  die();
3052
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3053
  /**
3054
  * Start restore
3055
  *
@@ -3057,86 +3011,152 @@ class WPvivid {
3057
  */
3058
  public function restore()
3059
  {
 
 
3060
  if(!isset($_POST['backup_id'])||empty($_POST['backup_id'])||!is_string($_POST['backup_id']))
3061
  {
 
3062
  die();
3063
  }
3064
 
3065
  $backup_id=sanitize_key($_POST['backup_id']);
3066
 
3067
- $restore_data=new WPvivid_restore_data();
3068
 
3069
- try {
3070
- if ($restore_data->has_restore()) {
3071
- $status = $restore_data->get_restore_status();
 
 
 
 
 
 
 
 
 
 
 
 
 
3072
 
3073
- if ($status === WPVIVID_RESTORE_ERROR) {
3074
- $ret['result'] = 'failed';
3075
- $ret['error'] = $restore_data->get_restore_error();
 
 
 
3076
  echo json_encode($ret);
 
3077
  die();
3078
- } else if ($status === WPVIVID_RESTORE_COMPLETED) {
3079
- $restore_data->write_log('disable maintenance mode', 'notice');
 
 
 
3080
  $this->_disable_maintenance_mode();
3081
  echo json_encode(array('result' => 'finished'));
 
3082
  die();
3083
  }
3084
- } else {
3085
- $restore_data->init_restore_data($backup_id);
3086
- $restore_data->write_log('init restore data', 'notice');
3087
- $this->_enable_maintenance_mode();
3088
- $restore_data->write_log('enable maintenance mode', 'notice');
3089
  }
3090
  }
3091
  catch (Exception $error)
3092
  {
3093
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3094
  echo $message;
 
3095
  die();
3096
  }
3097
  catch (Error $error)
3098
  {
3099
  $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3100
  echo $message;
 
3101
  die();
3102
  }
3103
 
3104
  try
3105
  {
 
3106
  $restore=new WPvivid_Restore();
3107
  $ret=$restore->restore();
 
3108
  }
3109
  catch (Exception $error)
3110
  {
3111
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3112
  error_log($message);
3113
- $restore_data=new WPvivid_restore_data();
3114
- $restore_data->update_error($message);
3115
- $restore_data->write_log($message,'error');
3116
  $this->_disable_maintenance_mode();
3117
- echo json_encode(array('result'=>'failed','error'=>$message));
 
3118
  die();
3119
  }
3120
  catch (Error $error)
3121
  {
3122
  $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3123
  error_log($message);
3124
- $restore_data=new WPvivid_restore_data();
3125
- $restore_data->update_error($message);
3126
- $restore_data->write_log($message,'error');
3127
  $this->_disable_maintenance_mode();
3128
- echo json_encode(array('result'=>'failed','error'=>$message));
 
3129
  die();
3130
  }
3131
 
3132
- if($ret['result']==WPVIVID_RESTORE_ERROR)
3133
  {
 
3134
  $this->_disable_maintenance_mode();
3135
  }
3136
 
3137
  echo json_encode($ret);
 
3138
  die();
3139
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3140
  /**
3141
  * Start rollback
3142
  *
@@ -3144,21 +3164,48 @@ class WPvivid {
3144
  */
3145
  public function rollback()
3146
  {
3147
- $restore_data=new WPvivid_restore_data();
3148
- if($restore_data->has_rollback())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3149
  {
3150
- $status=$restore_data->get_rollback_status();
3151
 
3152
  if($status === WPVIVID_RESTORE_ERROR)
3153
  {
3154
  $ret['result']='failed';
3155
- $ret['error']=$restore_data->get_rollback_error();
3156
  echo json_encode($ret);
3157
  die();
3158
  }
3159
  else if($status === WPVIVID_RESTORE_COMPLETED)
3160
  {
3161
- $restore_data->write_rollback_log('disable maintenance mode','notice');
3162
  $this->_disable_maintenance_mode();
3163
  echo json_encode(array('result'=>'finished'));
3164
  die();
@@ -3166,10 +3213,10 @@ class WPvivid {
3166
  }
3167
  else
3168
  {
3169
- $restore_data->init_rollback_data();
3170
- $restore_data->write_rollback_log('init restore data','notice');
3171
  $this->_enable_maintenance_mode();
3172
- $restore_data->write_rollback_log('enable maintenance mode','notice');
3173
  }
3174
 
3175
  try
@@ -3182,9 +3229,9 @@ class WPvivid {
3182
  {
3183
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3184
  error_log($message);
3185
- $restore_data=new WPvivid_restore_data();
3186
- $restore_data->update_rollback_error($message);
3187
- $restore_data->write_rollback_log($message,'error');
3188
  $this->_disable_maintenance_mode();
3189
  echo json_encode(array('result'=>'failed','error'=>$message));
3190
  die();
@@ -3193,9 +3240,9 @@ class WPvivid {
3193
  {
3194
  $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3195
  error_log($message);
3196
- $restore_data=new WPvivid_restore_data();
3197
- $restore_data->update_rollback_error($message);
3198
- $restore_data->write_rollback_log($message,'error');
3199
  $this->_disable_maintenance_mode();
3200
  echo json_encode(array('result'=>'failed','error'=>$message));
3201
  die();
@@ -3211,13 +3258,13 @@ class WPvivid {
3211
  */
3212
  public function get_restore_progress()
3213
  {
3214
- $restore_data=new WPvivid_restore_data();
3215
 
3216
- if($restore_data->has_restore())
3217
  {
3218
  $ret['result']='success';
3219
- $ret['status']= $restore_data->get_restore_status();
3220
- $ret['log']=$restore_data->get_log_content();
3221
  echo json_encode($ret);
3222
  die();
3223
  }
@@ -3236,13 +3283,13 @@ class WPvivid {
3236
  */
3237
  public function get_rollback_progress()
3238
  {
3239
- $restore_data=new WPvivid_restore_data();
3240
 
3241
- if($restore_data->has_rollback())
3242
  {
3243
  $ret['result']='success';
3244
- $ret['status']= $restore_data->get_rollback_status();
3245
- $ret['log']=$restore_data->get_rollback_log_content();
3246
  echo json_encode($ret);
3247
  die();
3248
  }
@@ -3255,32 +3302,6 @@ class WPvivid {
3255
  }
3256
  }
3257
 
3258
- public function download_restore_progress()
3259
- {
3260
- if(!isset($_POST['file_name']))
3261
- {
3262
- die();
3263
- }
3264
-
3265
- $task=WPvivid_taskmanager::get_download_task_v2($_POST['file_name']);
3266
-
3267
- if($task===false)
3268
- {
3269
- $ret['result']=WPVIVID_FAILED;
3270
- $ret['error']='not found download file';
3271
- echo json_encode($ret);
3272
- }
3273
- else
3274
- {
3275
- $ret['result']=WPVIVID_SUCCESS;
3276
- $ret['status']=$task['status'];
3277
- $ret['log']=$task['progress_text'];
3278
- $ret['error']=$task['error'];
3279
- echo json_encode($ret);
3280
- }
3281
- die();
3282
- }
3283
-
3284
  public function init_filesystem()
3285
  {
3286
  $credentials = request_filesystem_credentials(wp_nonce_url(admin_url('admin.php')."?page=WPvivid", 'wpvivid-nonce'));
@@ -3299,7 +3320,7 @@ class WPvivid {
3299
  $this->init_filesystem();
3300
  global $wp_filesystem;
3301
  $file = $wp_filesystem->abspath() . '.maintenance';
3302
- $maintenance_string = '<?php $upgrading = ' . time() . ';';
3303
  $maintenance_string.='global $wp_version;';
3304
  $maintenance_string.='$version_check=version_compare($wp_version,4.6,\'>\' );';
3305
  $maintenance_string.='if($version_check)';
@@ -3423,7 +3444,6 @@ class WPvivid {
3423
  }
3424
 
3425
  public function _list_tasks($backup_id){
3426
-
3427
  $tasks=WPvivid_Setting::get_tasks();
3428
  $ret=array();
3429
  $list_tasks=array();
@@ -3431,147 +3451,41 @@ class WPvivid {
3431
  {
3432
  if($task['action']=='backup')
3433
  {
3434
- $list_tasks[$task['id']]['status']=WPvivid_taskmanager::get_backup_tasks_status($task['id']);
3435
- $list_tasks[$task['id']]['is_canceled']=WPvivid_taskmanager::is_task_canceled($task['id']);
3436
- $list_tasks[$task['id']]['size']=WPvivid_taskmanager::get_backup_size($task['id']);
3437
- $list_tasks[$task['id']]['data']=WPvivid_taskmanager::get_backup_tasks_progress($task['id']);
3438
 
3439
- if($list_tasks[$task['id']]['status']['str']=='running'||$list_tasks[$task['id']]['status']['str']=='no_responds')
3440
- {
3441
- if($list_tasks[$task['id']]['data']['running_time']>180)
3442
  {
3443
- $timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT,array($task['id']));
3444
-
3445
- if($timestamp===false)
3446
- {
3447
- $this->add_monitor_event($task['id'],20);
3448
- }
3449
- }
3450
- }
3451
-
3452
- $general_setting=WPvivid_Setting::get_setting(true, "");
3453
- if($general_setting['options']['wpvivid_common_setting']['estimate_backup'] == 0){
3454
- $estimate_backup='display: none';
3455
- }
3456
- else{
3457
- $estimate_backup='';
3458
- }
3459
- $backup_percent=$list_tasks[$task['id']]['data']['progress'].'%';
3460
- if($list_tasks[$task['id']]['size']['db_size'] == false){
3461
- $db_size=0;
3462
- }
3463
- else{
3464
- $db_size=$list_tasks[$task['id']]['size']['db_size'];
3465
- }
3466
- if($list_tasks[$task['id']]['size']['files_size'] == false){
3467
- $file_size=0;
3468
- }
3469
- else{
3470
- $file_size=$list_tasks[$task['id']]['size']['files_size']['sum'];
3471
- }
3472
- $descript='';
3473
- $css_btn_cancel='pointer-events: auto; opacity: 1;';
3474
- $css_btn_log='pointer-events: auto; opacity: 1;';
3475
- $total = 'N/A';
3476
- $upload = 'N/A';
3477
- $speed = 'N/A';
3478
- if($list_tasks[$task['id']]['status']['str']=='ready'){
3479
- $descript=__('Ready to backup. Progress: 0%, running time: 0second.','wpvivid');
3480
- $css_btn_cancel='pointer-events: none; opacity: 0.4;';
3481
- $css_btn_log='pointer-events: none; opacity: 0.4;';
3482
- }
3483
- else if($list_tasks[$task['id']]['status']['str']=='running'){
3484
- if($list_tasks[$task['id']]['is_canceled'] == false){
3485
- if($list_tasks[$task['id']]['data']['type'] == 'upload'){
3486
- $descript = $list_tasks[$task['id']]['data']['descript'];
3487
- $find_str = 'Total size: ';
3488
- if(stripos($descript, $find_str) != false) {
3489
- $pos = stripos($descript, $find_str);
3490
- $rest = substr($descript, $pos);
3491
- $descript = substr($descript, 0, $pos);
3492
-
3493
- $find_str = 'Uploaded: ';
3494
- if(stripos($rest, $find_str) != false) {
3495
- $pos = stripos($rest, $find_str);
3496
- $total = substr($rest, 0, $pos);
3497
- $rest = substr($rest, $pos);
3498
-
3499
- $find_str = 'speed';
3500
- if(stripos($rest, $find_str) != false) {
3501
- $pos = stripos($rest, $find_str);
3502
- $upload = substr($rest, 0, $pos);
3503
- $speed = substr($rest, $pos);
3504
-
3505
- $total = str_replace('Total size:', '', $total);
3506
- $upload = str_replace('Uploaded:', '', $upload);
3507
- $speed = str_replace('speed:', '', $speed);
3508
- }
3509
- }
3510
- }
3511
- $descript = $descript.__(' Progress: ', 'wpvivid') . $backup_percent . __(', running time: ', 'wpvivid') . $list_tasks[$task['id']]['data']['running_time'];
3512
- }
3513
- else {
3514
- $descript = $list_tasks[$task['id']]['data']['descript'] . __(' Progress: ', 'wpvivid') . $backup_percent . __(', running time: ', 'wpvivid') . $list_tasks[$task['id']]['data']['running_time'];
3515
- }
3516
- $css_btn_cancel='pointer-events: auto; opacity: 1;';
3517
- $css_btn_log='pointer-events: auto; opacity: 1;';
3518
- }
3519
- else{
3520
- $descript=__('The backup will be canceled after backing up the current chunk ends.','wpvivid');
3521
- $css_btn_cancel='pointer-events: none; opacity: 0.4;';
3522
- $css_btn_log='pointer-events: auto; opacity: 1;';
3523
  }
3524
  }
3525
- else if($list_tasks[$task['id']]['status']['str']=='wait_resume'){
3526
- $descript='Task '.$task['id'].' timed out, backup task will retry in '.$list_tasks[$task['id']]['data']['next_resume_time'].' seconds, retry times: '.$list_tasks[$task['id']]['status']['resume_count'].'.';
3527
- $css_btn_cancel='pointer-events: auto; opacity: 1;';
3528
- $css_btn_log='pointer-events: auto; opacity: 1;';
3529
- }
3530
- else if($list_tasks[$task['id']]['status']['str']=='no_responds'){
3531
- if($list_tasks[$task['id']]['is_canceled'] == false){
3532
- $descript='Task , '.$list_tasks[$task['id']]['data']['doing'].' is not responding. Progress: '.$backup_percent.', running time: '.$list_tasks[$task['id']]['data']['running_time'];
3533
- $css_btn_cancel='pointer-events: auto; opacity: 1;';
3534
- $css_btn_log='pointer-events: auto; opacity: 1;';
3535
- }
3536
- else{
3537
- $descript=__('The backup will be canceled after backing up the current chunk ends.','wpvivid');
3538
- $css_btn_cancel='pointer-events: none; opacity: 0.4;';
3539
- $css_btn_log='pointer-events: auto; opacity: 1;';
3540
- }
3541
- }
3542
- else if($list_tasks[$task['id']]['status']['str']=='completed'){
3543
- $descript='Task '.$task['id'].' completed.';
3544
- $css_btn_cancel='pointer-events: auto; opacity: 1;';
3545
- $css_btn_log='pointer-events: auto; opacity: 1;';
3546
  $task_msg = WPvivid_taskmanager::get_task($task['id']);
3547
  $this->update_last_backup_task($task_msg);
3548
  }
3549
- else if($list_tasks[$task['id']]['status']['str']=='error'){
3550
- $descript='Backup error: '.$list_tasks[$task['id']]['status']['error'];
3551
- $css_btn_cancel='pointer-events: auto; opacity: 1;';
3552
- $css_btn_log='pointer-events: auto; opacity: 1;';
3553
- $task_msg = WPvivid_taskmanager::get_task($task['id']);
3554
- $this->update_last_backup_task($task_msg);
3555
- }
3556
-
3557
  $list_tasks[$task['id']]['progress_html'] = '<div class="action-progress-bar" id="wpvivid_action_progress_bar">
3558
- <div class="action-progress-bar-percent" id="wpvivid_action_progress_bar_percent" style="height:24px;width:' . $backup_percent . '"></div>
3559
  </div>
3560
- <div id="wpvivid_estimate_backup_info" style="float:left; ' . $estimate_backup . '">
3561
- <div class="backup-basic-info"><span>' . __('Database Size:', 'wpvivid') . '</span><span id="wpvivid_backup_database_size">' . $db_size . '</span></div>
3562
- <div class="backup-basic-info"><span>' . __('File Size:', 'wpvivid') . '</span><span id="wpvivid_backup_file_size">' . $file_size . '</span></div>
3563
  </div>
3564
  <div id="wpvivid_estimate_upload_info" style="float: left;">
3565
- <div class="backup-basic-info"><span>' . __('Total Size:', 'wpvivid') . '</span><span>' . $total . '</span></div>
3566
- <div class="backup-basic-info"><span>' . __('Uploaded:', 'wpvivid') . '</span><span>' . $upload . '</span></div>
3567
- <div class="backup-basic-info"><span>' . __('Speed:', 'wpvivid') . '</span><span>' . $speed . '</span></div>
 
 
 
3568
  </div>
3569
  <div style="clear:both;"></div>
3570
- <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing">' . $descript . '</p></div>
3571
  <div style="clear: both;"></div>
3572
  <div>
3573
- <div id="wpvivid_backup_cancel" class="backup-log-btn"><input class="button-primary" id="wpvivid_backup_cancel_btn" type="submit" value="' . esc_attr('Cancel', 'wpvivid') . '" onclick="wpvivid_cancel_backup();" style="' . $css_btn_cancel . '" /></div>
3574
- <div id="wpvivid_backup_log" class="backup-log-btn"><input class="button-primary backup-log-btn" id="wpvivid_backup_log_btn" type="submit" value="' . esc_attr('Log', 'wpvivid') . '" onclick="wpvivid_read_log(\'' . __('wpvivid_view_backup_task_log') . '\');" style="' . $css_btn_log . '" /></div>
3575
  </div>
3576
  <div style="clear: both;"></div>';
3577
  }
@@ -3618,9 +3532,19 @@ class WPvivid {
3618
  $ret['backup']['result']='success';
3619
  $ret['backup']['data']=$list_tasks;
3620
 
3621
- $ret['download']['data']=array();
3622
- if($backup_id !== false) {
3623
- $ret['download'] = self::update_download_page($backup_id);
 
 
 
 
 
 
 
 
 
 
3624
  }
3625
 
3626
  $html='';
@@ -3835,8 +3759,10 @@ class WPvivid {
3835
  {
3836
  $this->delete_backup_by_id($backup_id);
3837
  }
3838
-
3839
  $ret['result']='success';
 
 
 
3840
  echo json_encode($ret);
3841
  die();
3842
  }
@@ -3907,24 +3833,17 @@ class WPvivid {
3907
  {
3908
  $list=WPvivid_Backuplist::get_backuplist();
3909
  $files=array();
3910
- foreach ($list as $backup)
3911
  {
3912
- if($backup['backup']['ismerge'])
 
3913
  {
3914
- foreach ($backup['backup']['data']['meta']['files'] as $file)
3915
- {
3916
- $files[]=$file['file_name'];
3917
- }
3918
  }
3919
- else
3920
- {
3921
- foreach ($backup['backup']['data']['type'] as $type)
3922
- {
3923
- foreach ($type['files'] as $file)
3924
- {
3925
- $files[]=$file['file_name'];
3926
- }
3927
- }
3928
  }
3929
  }
3930
 
@@ -3935,14 +3854,15 @@ class WPvivid {
3935
  $path = substr($path, 0, -1);
3936
  }
3937
  $folder[]= $path;
3938
-
3939
- $this -> get_dir_files($delete_files,$delete_folder,$dir,array('file' => '&wpvivid-&'),$files,$folder,0,false);
 
3940
  }
3941
 
3942
  if($options['old_files']=='1')
3943
  {
3944
- $restore_data=new WPvivid_restore_data();
3945
- $restore_data->delete_old_files();
3946
  }
3947
 
3948
  foreach ($delete_files as $file)
@@ -4664,19 +4584,19 @@ class WPvivid {
4664
  $line = fgets($handle);
4665
  if($line!==false)
4666
  {
4667
- $pos=strpos($line,'log created: ');
4668
  if($pos!==false)
4669
  {
4670
- $log_file['time']=substr ($line,$pos+strlen('log created: '));
4671
  }
4672
  }
4673
  $line = fgets($handle);
4674
  if($line!==false)
4675
  {
4676
- $pos=strpos($line,'type: ');
4677
  if($pos!==false)
4678
  {
4679
- $log_file['des']=substr ($line,$pos+strlen('type: '));
4680
  }
4681
  }
4682
 
@@ -4938,6 +4858,14 @@ class WPvivid {
4938
  $remote=apply_filters('wpvivid_remote_pic', $remote);
4939
 
4940
  foreach ($backuplist as $key=>$value) {
 
 
 
 
 
 
 
 
4941
  if(empty($value['lock'])){
4942
  $backup_lock='/admin/partials/images/unlocked.png';
4943
  $lock_status='unlock';
@@ -4957,7 +4885,7 @@ class WPvivid {
4957
  $save_local_pic_y = '/admin/partials/images/storage-local.png';
4958
  $save_local_pic_n = '/admin/partials/images/storage-local(gray).png';
4959
  $local_title = 'Localhost';
4960
- if($value['save_local'] == 1){
4961
  $remote_pic_html .= '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $save_local_pic_y) . '" style="vertical-align:middle; " title="' . $local_title . '"/>';
4962
  }
4963
  else{
@@ -4981,7 +4909,8 @@ class WPvivid {
4981
  $remote_pic_html .= '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $pic) . '" style="vertical-align:middle; " title="' . $title . '"/>';
4982
  }
4983
  }
4984
- $html .= '<tr>
 
4985
  <th class="check-column"><input name="check_backup" type="checkbox" id="'.esc_attr($key, 'wpvivid').'" value="'.esc_attr($key, 'wpvivid').'" onclick="wpvivid_click_check_backup(\''.__($key, 'wpvivid').'\');" /></th>
4986
  <td class="tablelistcolumn">
4987
  <div style="float:left;padding:0 10px 10px 0;">
@@ -4990,9 +4919,9 @@ class WPvivid {
4990
  <span title="To lock the backup, the backup can only be deleted manually" id="wpvivid_lock_'.$key.'">
4991
  <img src="'.esc_url(WPVIVID_PLUGIN_URL.$backup_lock).'" name="'.esc_attr($lock_status, 'wpvivid').'" onclick="wpvivid_set_backup_lock(\''.__($key, 'wpvivid').'\', \''.__($lock_status, 'wpvivid').'\');" style="vertical-align:middle; cursor:pointer;"/>
4992
  </span>
4993
- | <span>'.__('Type:', 'wpvivid').'</span><span>'.__($value['type'], 'wpvivid').'</span>
4994
- |<span title="Backup log"><a href="#" onclick="wpvivid_read_log(\''.__('wpvivid_view_backup_log').'\', \''.__($key).'\');"><img src="'.esc_url(WPVIVID_PLUGIN_URL.'/admin/partials/images/Log.png').'" style="vertical-align:middle;cursor:pointer;"/>'.__('Log', 'wpvivid').'</a></span>
4995
- |<span title="Restore Website from The Backup"><a href="#" onclick="wpvivid_initialize_restore(\''.__($key, 'wpvivid').'\',\''.__(date('M d, Y H:i',$value['create_time']), 'wpvivid').'\');"><img src="'.esc_url(WPVIVID_PLUGIN_URL. '/admin/partials/images/Restore.png').'" style="vertical-align:middle;cursor:pointer;"/>'.__('Restore', 'wpvivid').'</a></span>
4996
  </div>
4997
  </div>
4998
  </td>
@@ -5002,7 +4931,7 @@ class WPvivid {
5002
  <td class="tablelistcolumn">
5003
  <div id="wpvivid_file_part_'.__($key, 'wpvivid').'" style="float:left;padding:10px 10px 10px 0;">
5004
  <div style="cursor:pointer;" onclick="wpvivid_initialize_download(\''.__($key, 'wpvivid').'\');" title="Prepare to download the backup">
5005
- <img id="wpvivid_download_btn_'.__($key, 'wpvivid').'" src="'.esc_url(WPVIVID_PLUGIN_URL.'/admin/partials/images/download.png').'" style="vertical-align:middle;" />'.__('Download', 'wpvivid').'
5006
  <div class="spinner" id="wpvivid_download_loading_'.__($key, 'wpvivid').'" style="float:right;width:auto;height:auto;padding:10px 180px 10px 0;background-position:0 0;"></div>
5007
  </div>
5008
  </div>
47
 
48
  public $end_shutdown_function;
49
 
50
+ public $restore_data;
51
+
52
+ public $migrate;
53
+ public $backup_uploader;
54
+
55
  public function __construct()
56
  {
57
  $this->version = WPVIVID_PLUGIN_VERSION;
60
 
61
  $this->end_shutdown_function = false;
62
 
63
+ $this->restore_data=false;
64
+
65
  //Load dependent files
66
  $this->load_dependencies();
67
 
152
 
153
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-remote-collection.php';
154
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-upload.php';
155
+
156
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-backup-uploader.php';
157
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
158
+ include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-migrate.php';
159
+
160
+
161
  $this->remote_collection=new WPvivid_Remote_collection();
162
+ $this->migrate=new WPvivid_Migrate();
163
+ $this->backup_uploader=new Wpvivid_BackupUploader();
164
  }
165
 
166
  private function set_locale()
174
  $plugin_admin = new WPvivid_Admin($this->get_plugin_name(), $this->get_version());
175
 
176
  add_action('admin_enqueue_scripts',array( $plugin_admin,'enqueue_styles'));
177
+
178
  add_action('admin_enqueue_scripts',array( $plugin_admin,'enqueue_scripts'));
179
 
180
  // Add menu item
321
  return $this->version;
322
  }
323
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  /**
325
  * Prepare backup include what you want to backup,where you want to store.
326
  *
348
  echo json_encode($ret);
349
  die();
350
  }
 
 
351
 
 
 
 
 
 
 
 
352
  $ret=$this->pre_backup($backup_options,'Manual');
353
  if($ret['result']=='success')
354
  {
355
  //Check the website data to be backed up
356
  $ret['check']=$this->check_backup($ret['task_id'],$backup_options['backup_files']);
357
+ if(isset($ret['check']['result']) && $ret['check']['result'] == WPVIVID_FAILED)
358
+ {
359
  echo json_encode(array('result' => WPVIVID_FAILED,'error' => $ret['check']['error']));
360
  die();
361
  }
409
  return $ret;
410
  }
411
  }
 
412
  $ret['result']=WPVIVID_SUCCESS;
413
+ $ret=apply_filters('wpvivid_check_backup_options_valid',$ret,$data);
414
  return $ret;
415
  }
416
  /**
667
  $schedule_options['backup']['remote']=strval($schedule_options['backup']['remote']);
668
  $schedule_options['backup']['ismerge']=strval($schedule_options['backup']['ismerge']);
669
  $schedule_options['backup']['lock']=strval($schedule_options['backup']['lock']);
 
 
 
670
 
671
+ $ret = $this->check_backup_option($schedule_options['backup']);
672
+ if($ret['result']!=WPVIVID_SUCCESS)
673
  {
674
+ echo json_encode($ret);
675
  die();
676
  }
677
 
739
 
740
  if(!empty($task))
741
  {
742
+ $backup=new WPvivid_Backup(false,$task);
743
+ $backup->clean_backup();
 
 
 
744
 
745
  $files=array();
746
 
747
  if($task['options']['remote_options']!==false)
748
  {
749
+ $backup_files=$backup->task->get_need_cleanup_files(true);
750
+ foreach ($backup_files as $file)
751
  {
752
+ $files[]=basename($file);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
753
  }
 
754
  if(!empty($files))
755
  {
756
+ $upload=new WPvivid_Upload();
757
  $upload->clean_remote_backup($task['options']['remote_options'],$files);
758
  }
759
  }
776
 
777
  if(!empty($backup))
778
  {
779
+
780
+ $backup_item=new WPvivid_Backup_Item($backup);
781
+ $files=$backup_item->get_files();
782
+ foreach ($files as $file)
783
+ {
784
+ if (file_exists($file))
785
+ {
786
+ @unlink($file);
787
+ }
788
+ }
789
+ /*$files=array();
790
  $download_dir=$backup['local']['path'];
791
  if($backup['backup']['ismerge'])
792
  {
822
  {
823
  unlink($download_path);
824
  }
825
+ }*/
826
 
827
  if(!empty($backup['remote']))
828
  {
829
+ $files=$backup_item->get_files(false);
830
+
831
  foreach($backup['remote'] as $remote)
832
  {
833
  WPvivid_downloader::delete($remote,$files);
844
  */
845
  public function clean_oldest_backup()
846
  {
847
+ $backup_ids=WPvivid_Backuplist::get_out_of_date_backuplist(WPvivid_Setting::get_max_backup_count());
848
+ foreach($backup_ids as $backup_id)
849
+ {
850
+ $this->delete_backup_by_id($backup_id);
851
+ }
852
  $count=WPvivid_Setting::get_max_backup_count();
853
  $ret=WPvivid_Backuplist::check_backuplist_limit($count);
854
  if($ret['result']=='need_delete')
883
  return $ret;
884
  }
885
 
886
+ $backup=new WPvivid_Backup_Task();
887
+ $ret=$backup->new_backup_task($backup_options,$type);
888
+ return $ret;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
889
  }
890
 
891
  /**
997
  }
998
  }
999
 
1000
+ public function wpvivid_analysis_backup($task)
1001
+ {
1002
  if($task['type'] == 'Cron')
1003
  {
1004
  $cron_backup_count = WPvivid_Setting::get_option('cron_backup_count');
1050
  {
1051
  $task=WPvivid_taskmanager::update_backup_task_status($task_id,false,'completed');
1052
  do_action('wpvivid_handle_upload_succeed',$task);
 
1053
  }
1054
  else
1055
  {
1070
  if($save_local==0)
1071
  {
1072
  $this->wpvivid_log->WriteLog('Cleaned up local files after uploading to remote storages.','notice');
1073
+ $backup=new WPvivid_Backup($task['id']);
1074
+ $backup->clean_backup();
 
 
1075
  }
1076
  $this->wpvivid_log->WriteLog('Upload succeeded.','notice');
1077
  $remote_options=$task['options']['remote_options'];
1080
 
1081
  function wpvivid_handle_backup_succeed($task)
1082
  {
1083
+ if($task['action'] === 'backup')
1084
+ {
1085
+ $backup_success_count = WPvivid_Setting::get_option('wpvivid_backup_success_count');
1086
+ if (empty($backup_success_count))
1087
+ {
1088
+ $backup_success_count = 0;
1089
+ }
1090
+ $backup_success_count++;
1091
+ WPvivid_Setting::update_option('wpvivid_backup_success_count', $backup_success_count);
1092
+ $this->wpvivid_analysis_backup($task);
1093
  }
 
 
 
1094
  WPvivid_Schedule::clear_monitor_schedule($task['id']);
1095
  WPvivid_mail_report::send_report_mail($task);
 
1096
  }
1097
 
1098
  function wpvivid_mark_task($task)
1102
 
1103
  function wpvivid_handle_backup_failed($task)
1104
  {
1105
+ if($task['action'] === 'backup')
1106
+ {
1107
+ $backup_error_array = WPvivid_Setting::get_option('wpvivid_backup_error_array');
1108
+ if (empty($backup_error_array))
1109
+ {
1110
+ $backup_error_array = array();
1111
+ }
1112
+ if (!array_key_exists($task['id'], $backup_error_array['bu_error']))
1113
+ {
1114
+ $backup_error_array['bu_error']['task_id'] = $task['id'];
1115
+ $backup_error_array['bu_error']['error_msg'] = $task['status']['error'];
1116
+ WPvivid_Setting::update_option('wpvivid_backup_error_array', $backup_error_array);
1117
+ }
1118
  }
1119
+ $this->wpvivid_log->WriteLog($task['status']['error'],'error');
1120
  WPvivid_error_log::create_error_log($this->wpvivid_log->log_file);
1121
  $this->wpvivid_log->CloseFile();
1122
  WPvivid_Schedule::clear_monitor_schedule($task['id']);
1126
 
1127
  public function deal_shutdown_error($task_id)
1128
  {
1129
+ if($this->end_shutdown_function===false)
1130
+ {
1131
  $last_error = error_get_last();
1132
+ if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE), true))
1133
+ {
1134
  $error = $last_error;
1135
  } else {
1136
  $error = false;
1137
  }
1138
  //$this->task_monitor($task_id,$error);
1139
+ if (WPvivid_taskmanager::get_task($task_id) !== false)
1140
+ {
1141
+ if ($this->wpvivid_log->log_file_handle == false)
1142
+ {
1143
  $this->wpvivid_log->OpenLogFile(WPvivid_taskmanager::get_task_options($task_id, 'log_file_name'));
1144
  }
1145
 
1146
  $status = WPvivid_taskmanager::get_backup_task_status($task_id);
1147
 
1148
+ if ($status['str'] == 'running' || $status['str'] == 'error' || $status['str'] == 'no_responds')
1149
+ {
1150
+ $options=WPvivid_Setting::get_option('wpvivid_common_setting');
1151
+ if(isset($options['max_execution_time']))
1152
+ {
1153
+ $limit=$options['max_execution_time'];
1154
+ }
1155
+ else
1156
+ {
1157
+ $limit=WPVIVID_MAX_EXECUTION_TIME;
1158
+ }
1159
+
1160
  $time_spend = time() - $status['timeout'];
1161
 
1162
+ if ($time_spend >= $limit)
1163
+ {
1164
  //time out
1165
  $status['resume_count']++;
1166
+ if ($status['resume_count'] > WPVIVID_RESUME_RETRY_TIMES)
1167
+ {
1168
  $message = __('Too many resumption attempts.', 'wpvivid');
1169
  $task = WPvivid_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
1170
  do_action('wpvivid_handle_backup_failed', $task);
1171
  } else {
1172
  $this->check_cancel_backup($task_id);
1173
  $message = 'Task timed out.';
1174
+ if ($this->add_resume_event($task_id))
1175
+ {
1176
  WPvivid_taskmanager::update_backup_task_status($task_id, false, 'wait_resume', false, $status['resume_count']);
1177
  } else {
1178
  $task = WPvivid_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
1182
  if ($this->wpvivid_log)
1183
  $this->wpvivid_log->WriteLog($message, 'error');
1184
  } else {
1185
+ if ($status['str'] != 'error')
1186
+ {
1187
+ if ($error !== false)
1188
+ {
1189
  $message = $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
1190
  } else {
1191
  $message = __('backup failed error unknown', 'wpvivid');
1222
  {
1223
  if($second==0)
1224
  {
1225
+ $options=WPvivid_Setting::get_option('wpvivid_common_setting');
1226
+ if(isset($options['max_execution_time']))
1227
+ {
1228
+ $second=$options['max_execution_time'];
1229
+ }
1230
+ else
1231
+ {
1232
+ $second=WPVIVID_MAX_EXECUTION_TIME;
1233
+ }
1234
  }
1235
  WPvivid_taskmanager::update_backup_task_status($task_id,false,'',true);
1236
  @set_time_limit($second);
1257
 
1258
  if($status['str']=='running'||$status['str']=='error'||$status['str']=='no_responds')
1259
  {
1260
+ $options=WPvivid_Setting::get_option('wpvivid_common_setting');
1261
+ if(isset($options['max_execution_time']))
1262
+ {
1263
+ $limit=$options['max_execution_time'];
1264
+ }
1265
+ else
1266
+ {
1267
+ $limit=WPVIVID_MAX_EXECUTION_TIME;
1268
+ }
1269
  $time_spend=time()-$status['timeout'];
1270
 
1271
  if($time_spend>=$limit)
1334
  *
1335
  * @since 0.9.1
1336
  */
1337
+ public function check_backup($task_id,$backup_files)
1338
  {
1339
  $ret['alert_db']=false;
1340
  $ret['alter_files']=false;
1354
  }
1355
  }
1356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1357
  $db_size=false;
1358
  $file_size=false;
1359
  $check_file=false;
1442
  {
1443
  $alter_sum_rows=4000000*3;
1444
  }
1445
+
1446
+ $memory_limit = ini_get('memory_limit');
1447
+ $ret['memory_limit']=$memory_limit;
1448
+ $memory_limit = trim($memory_limit);
1449
+ $memory_limit_int = (int) $memory_limit;
1450
+ $last = strtolower(substr($memory_limit, -1));
1451
+
1452
+ if($last == 'g')
1453
+ $memory_limit_int = $memory_limit_int*1024*1024*1024;
1454
+ if($last == 'm')
1455
+ $memory_limit_int = $memory_limit_int*1024*1024;
1456
+ if($last == 'k')
1457
+ $memory_limit_int = $memory_limit_int*1024;
1458
+
1459
  if($dbSize>($memory_limit_int*0.9))
1460
  {
1461
  $max_rows=0;
1477
  $ret['alter_fcgi']=true;
1478
  }
1479
 
 
 
 
1480
  $db_size=$this->formatBytes($dbSize);
1481
  }
1482
  if($check_file)
1483
  {
1484
  include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-backup.php';
1485
+ $task=new WPvivid_Backup_Task($task_id);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1486
 
1487
+ $file_size=$task->get_file_info();
1488
+ $sum_size=$file_size['sum_size'];
1489
+ $sum_count=$file_size['sum_count'];
1490
  if($alter_fcgi)
1491
  {
1492
  $alter_sum_size=1024*1024*1024;
1502
  {
1503
  $ret['alter_files']=true;
1504
  $ret['sum_size']=$this->formatBytes($sum_size);
1505
+ $ret['sum_count']=$sum_count;
1506
  $ret['file_size']=$file_size;
1507
  if($alter_fcgi)
1508
  $ret['alter_fcgi']=true;
1516
  $ret['db_size']=$db_size;
1517
  $ret['file_size']=$file_size;
1518
  if($task_id!==false)
1519
+ {
1520
+ $task=new WPvivid_Backup_Task($task_id);
1521
+ $task->set_file_and_db_info($db_size,$file_size);
1522
+ }
1523
  return $ret;
1524
  }
1525
  /**
1700
  {
1701
  if(WPvivid_taskmanager::get_task($task_id)!==false)
1702
  {
1703
+ $task=new WPvivid_Backup_Task($task_id);
 
 
 
1704
 
1705
+ if($task->is_cancel_file_exist())
1706
  {
1707
  if($this->wpvivid_log->log_file_handle==false)
1708
  {
1709
  $this->wpvivid_log->OpenLogFile(WPvivid_taskmanager::get_task_options($task_id,'log_file_name'));
1710
  }
 
1711
  $this->wpvivid_log->WriteLog('Backup cancelled.','notice');
1712
+
1713
+ $task->update_status('cancel');
1714
+ //WPvivid_taskmanager::update_backup_task_status($task_id,false,'cancel',false);
1715
  $this->add_clean_backing_up_data_event($task_id);
1716
  WPvivid_Schedule::clear_monitor_schedule($task_id);
1717
  WPvivid_taskmanager::delete_task($task_id);
1858
  return $ret;
1859
  }
1860
 
1861
+ $backup_item=new WPvivid_Backup_Item($backup);
1862
+ $ret=$backup_item->get_download_backup_files($backup_id);
1863
+
1864
+ //echo json_encode($ret);
1865
+
1866
+ //$type_list = $backup_item->get_download_type();
1867
+ /*if($backup['backup']['ismerge']==1)
1868
  {
1869
  $type_list[]='all';
1870
 
1875
  {
1876
  $type_list[]=$type['type_name'];
1877
  }
1878
+ }*/
1879
+ /*$ret['data']=array();
1880
  foreach ($type_list as $type_name)
1881
  {
1882
+ $ret['data']['type'][$type_name]=$download_item->check_backup_download($backup_id,$type_name);
1883
+ }*/
1884
 
1885
+ WPvivid_taskmanager::update_download_cache($backup_id,$ret);
1886
  return $ret;
1887
  }
1888
  public function check_backup_download($backup_id,$check_type)
2268
  {
2269
  $this->ajax_check_security();
2270
 
2271
+ if(isset($_REQUEST['backup_id'])&&isset($_REQUEST['file_name']))
2272
  {
2273
  if(!empty($_REQUEST['backup_id'])&&is_string($_REQUEST['backup_id']))
2274
  {
2288
  die();
2289
  }
2290
 
 
 
 
 
 
 
 
 
 
2291
  $cache=WPvivid_taskmanager::get_download_cache($backup_id);
2292
  if($cache===false)
2293
  {
2295
  $cache=WPvivid_taskmanager::get_download_cache($backup_id);
2296
  }
2297
  $path=false;
2298
+ if(array_key_exists($file_name,$cache['files']))
2299
  {
2300
+ if($cache['files'][$file_name]['status']=='completed')
2301
+ {
2302
+ $path=$cache['files'][$file_name]['download_path'];
2303
+ }
 
 
 
2304
  }
2305
  if($path!==false)
2306
  {
2436
  return $ret;
2437
  }
2438
 
2439
+ $backup_item=new WPvivid_Backup_Item($backup);
2440
+
2441
+ if($backup_item->is_lock())
2442
  {
2443
  if($force==0)
2444
  {
2448
  }
2449
  }
2450
 
2451
+ $files=$backup_item->get_files();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2452
 
2453
  foreach ($files as $file)
2454
  {
2455
+ if (file_exists($file))
 
2456
  {
2457
+ @unlink($file);
2458
  }
 
2459
  }
2460
 
2461
  if(!empty($backup['remote']))
2462
  {
2463
+ $files=$backup_item->get_files(false);
2464
  foreach($backup['remote'] as $remote)
2465
  {
2466
  WPvivid_downloader::delete($remote,$files);
2490
 
2491
  $files=array();
2492
  $download_dir=$backup['local']['path'];
2493
+
2494
+ $backup_item = new WPvivid_Backup_Item($backup);
2495
+ $file=$backup_item->get_files(false);
2496
+ foreach ($file as $filename) {
2497
+ $files[] = $filename;
2498
+ }
2499
+
2500
+ /*if(isset($backup['backup']['files'])){
2501
+ foreach ($backup['backup']['files'] as $file) {
2502
+ $files[] = $file['file_name'];
2503
+ }
2504
+ }
2505
+ else if($backup['backup']['ismerge'])
2506
  {
2507
  foreach ($backup['backup']['data']['meta']['files'] as $file)
2508
  {
2527
  $files[]=$file['file_name'];
2528
  }
2529
  }
2530
+ }*/
2531
 
2532
  foreach ($files as $file)
2533
  {
2796
 
2797
  public function scan_last_restore()
2798
  {
2799
+ try
 
 
2800
  {
2801
+ if($this->restore_data->has_restore())
 
 
 
2802
  {
2803
+ $ret['has_exist_restore']=1;
2804
+ }
2805
+ else
2806
+ {
2807
+ $ret['has_exist_restore']=0;
2808
  }
 
 
 
 
 
 
2809
 
2810
+ if($this->restore_data->has_old_files())
2811
+ {
2812
+ $ret['has_old_files']=1;
2813
+ }
2814
+ else
2815
+ {
2816
+ $ret['has_old_files']=0;
2817
+ }
2818
  }
2819
+ catch (Exception $error)
2820
  {
2821
+ $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
2822
+
2823
+ $ret['has_exist_restore']=1;
2824
+ $ret['restore_error']=$message;
2825
  }
2826
+
2827
+
2828
  return $ret;
2829
  }
2830
  public function init_restore_page()
2831
  {
2832
  $this->ajax_check_security();
2833
 
2834
+ if(!isset($_POST['backup_id'])||empty($_POST['backup_id'])||!is_string($_POST['backup_id']))
2835
+ {
2836
+ die();
2837
+ }
2838
+
2839
+ $this->restore_data=new WPvivid_restore_data();
2840
+ $ret_scan_last_restore=$this->scan_last_restore();
2841
+
2842
+ $backup_id =sanitize_key($_POST['backup_id']);
2843
+ //$json = $_POST['restore_options'];
2844
+ //$json = stripslashes($json);
2845
+ //$restore_options = json_decode($json, 1);
2846
+ //if(is_null($restore_options))
2847
+ //{
2848
+ // die();
2849
+ //}
2850
+ $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2851
+
2852
+ $backup_item=new WPvivid_Backup_Item($backup);
2853
+
2854
+ $ret=$backup_item->check_backup_files();
2855
+
2856
+ if($backup_item->get_backup_type()=='Upload' || $backup_item->get_backup_type()=='Migration')
2857
+ {
2858
+ $ret['is_migrate']=1;
2859
+ }
2860
+ else
2861
+ {
2862
+ $ret['is_migrate']=0;
2863
+ }
2864
+
2865
+ $ret['skip_backup_old_site']=1;
2866
+ $ret['skip_backup_old_database']=1;
2867
+
2868
+ $ret=array_merge($ret,$ret_scan_last_restore);
2869
+
2870
+ echo json_encode($ret);
2871
  die();
2872
  }
2873
 
2875
  {
2876
  $this->ajax_check_security();
2877
 
2878
+ $this->restore_data=new WPvivid_restore_data();
2879
+ $this->restore_data->clean_restore_data();
2880
  $ret['result']='success';
2881
  echo json_encode($ret);
2882
  die();
2884
 
2885
  public function delete_old_files()
2886
  {
2887
+ $this->restore_data=new WPvivid_restore_data();
2888
+ $this->restore_data->delete_old_files();
2889
  $ret['result']='success';
2890
  echo json_encode($ret);
2891
  die();
2899
  {
2900
  $this->ajax_check_security();
2901
 
2902
+ if(!isset($_POST['backup_id'])||empty($_POST['backup_id'])||!is_string($_POST['backup_id']))
2903
  {
2904
  die();
2905
  }
2906
 
2907
  $backup_id =sanitize_key($_POST['backup_id']);
2908
+ //$json = $_POST['restore_options'];
2909
+ //$json = stripslashes($json);
2910
+ //$restore_options = json_decode($json, 1);
2911
+ //if(is_null($restore_options))
2912
+ //{
2913
+ // die();
2914
+ //}
2915
  $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2916
 
2917
+ $backup_item=new WPvivid_Backup_Item($backup);
 
 
 
2918
 
2919
+ $ret=$backup_item->check_backup_files();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2920
 
2921
+ if($backup_item->get_backup_type()=='Upload')
2922
  {
2923
+ $ret['is_migrate']=1;
2924
  }
2925
  else
2926
  {
2927
+ $ret['is_migrate']=0;
2928
  }
2929
 
 
 
2930
  echo json_encode($ret);
2931
  die();
2932
  }
2959
  echo json_encode(array('result' => WPVIVID_FAILED ,'error'=>'backup not found'));
2960
  die();
2961
  }
 
 
 
2962
 
2963
+ $backup_item=new WPvivid_Backup_Item($backup);
2964
+
2965
+ $local_path=$backup_item->get_local_path();
2966
+ $remote_option=$backup_item->get_remote();
2967
+
2968
+ if($remote_option===false)
2969
  {
2970
  echo json_encode(array('result' => WPVIVID_FAILED ,'error'=>'Retrieving the cloud storage information failed while downloading backups. Please try again later.'));
2971
  die();
2977
  echo json_encode($ret);
2978
  die();
2979
  }
2980
+
2981
+ public function download_restore_progress()
2982
+ {
2983
+ if(!isset($_POST['file_name']))
2984
+ {
2985
+ die();
2986
+ }
2987
+
2988
+ $task=WPvivid_taskmanager::get_download_task_v2($_POST['file_name']);
2989
+
2990
+ if($task===false)
2991
+ {
2992
+ $ret['result']=WPVIVID_FAILED;
2993
+ $ret['error']='not found download file';
2994
+ echo json_encode($ret);
2995
+ }
2996
+ else
2997
+ {
2998
+ $ret['result']=WPVIVID_SUCCESS;
2999
+ $ret['status']=$task['status'];
3000
+ $ret['log']=$task['progress_text'];
3001
+ $ret['error']=$task['error'];
3002
+ echo json_encode($ret);
3003
+ }
3004
+ die();
3005
+ }
3006
+
3007
  /**
3008
  * Start restore
3009
  *
3011
  */
3012
  public function restore()
3013
  {
3014
+ $this->end_shutdown_function=false;
3015
+ register_shutdown_function(array($this,'deal_restore_shutdown_error'));
3016
  if(!isset($_POST['backup_id'])||empty($_POST['backup_id'])||!is_string($_POST['backup_id']))
3017
  {
3018
+ $this->end_shutdown_function=true;
3019
  die();
3020
  }
3021
 
3022
  $backup_id=sanitize_key($_POST['backup_id']);
3023
 
3024
+ $this->restore_data=new WPvivid_restore_data();
3025
 
3026
+ $restore_options=array();
3027
+ if(isset($_POST['restore_options']))
3028
+ {
3029
+ $json = stripslashes($_POST['restore_options']);
3030
+ $restore_options = json_decode($json, 1);
3031
+ if(is_null($restore_options))
3032
+ {
3033
+ $restore_options=array();
3034
+ }
3035
+ }
3036
+
3037
+ try
3038
+ {
3039
+ if ($this->restore_data->has_restore())
3040
+ {
3041
+ $status = $this->restore_data->get_restore_status();
3042
 
3043
+ if ($status === WPVIVID_RESTORE_ERROR)
3044
+ {
3045
+ $ret['result'] =WPVIVID_FAILED;
3046
+ $ret['error'] = $this->restore_data->get_restore_error();
3047
+ $this->restore_data->delete_temp_files();
3048
+ $this->_disable_maintenance_mode();
3049
  echo json_encode($ret);
3050
+ $this->end_shutdown_function=true;
3051
  die();
3052
+ }
3053
+ else if ($status === WPVIVID_RESTORE_COMPLETED)
3054
+ {
3055
+ $this->restore_data->write_log('disable maintenance mode', 'notice');
3056
+ $this->restore_data->delete_temp_files();
3057
  $this->_disable_maintenance_mode();
3058
  echo json_encode(array('result' => 'finished'));
3059
+ $this->end_shutdown_function=true;
3060
  die();
3061
  }
3062
+ }
3063
+ else {
3064
+ $this->restore_data->init_restore_data($backup_id,$restore_options);
3065
+ $this->restore_data->write_log('init restore data', 'notice');
 
3066
  }
3067
  }
3068
  catch (Exception $error)
3069
  {
3070
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3071
  echo $message;
3072
+ $this->end_shutdown_function=true;
3073
  die();
3074
  }
3075
  catch (Error $error)
3076
  {
3077
  $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3078
  echo $message;
3079
+ $this->end_shutdown_function=true;
3080
  die();
3081
  }
3082
 
3083
  try
3084
  {
3085
+ $this->_enable_maintenance_mode();
3086
  $restore=new WPvivid_Restore();
3087
  $ret=$restore->restore();
3088
+ $this->_disable_maintenance_mode();
3089
  }
3090
  catch (Exception $error)
3091
  {
3092
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3093
  error_log($message);
3094
+ $this->restore_data->delete_temp_files();
3095
+ $this->restore_data->update_error($message);
3096
+ $this->restore_data->write_log($message,'error');
3097
  $this->_disable_maintenance_mode();
3098
+ echo json_encode(array('result'=>WPVIVID_FAILED,'error'=>$message));
3099
+ $this->end_shutdown_function=true;
3100
  die();
3101
  }
3102
  catch (Error $error)
3103
  {
3104
  $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3105
  error_log($message);
3106
+ $this->restore_data->delete_temp_files();
3107
+ $this->restore_data->update_error($message);
3108
+ $this->restore_data->write_log($message,'error');
3109
  $this->_disable_maintenance_mode();
3110
+ echo json_encode(array('result'=>WPVIVID_FAILED,'error'=>$message));
3111
+ $this->end_shutdown_function=true;
3112
  die();
3113
  }
3114
 
3115
+ if($ret['result']==WPVIVID_FAILED)
3116
  {
3117
+ $this->restore_data->delete_temp_files();
3118
  $this->_disable_maintenance_mode();
3119
  }
3120
 
3121
  echo json_encode($ret);
3122
+ $this->end_shutdown_function=true;
3123
  die();
3124
  }
3125
+
3126
+ public function deal_restore_shutdown_error()
3127
+ {
3128
+ if($this->end_shutdown_function===false)
3129
+ {
3130
+ $last_error = error_get_last();
3131
+ if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE), true))
3132
+ {
3133
+ $error = $last_error;
3134
+ } else {
3135
+ $error = false;
3136
+ }
3137
+ //$this->task_monitor($task_id,$error);
3138
+
3139
+ if ($error !== false)
3140
+ {
3141
+ $message = $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
3142
+ $this->restore_data->delete_temp_files();
3143
+ $this->restore_data->update_error($message);
3144
+ $this->restore_data->write_log($message,'error');
3145
+ $this->_disable_maintenance_mode();
3146
+ echo json_encode(array('result'=>WPVIVID_FAILED,'error'=>$message));
3147
+ }
3148
+ else {
3149
+ $message = __('backup failed error unknown', 'wpvivid');
3150
+ $this->restore_data->delete_temp_files();
3151
+ $this->restore_data->update_error($message);
3152
+ $this->restore_data->write_log($message,'error');
3153
+ $this->_disable_maintenance_mode();
3154
+ echo json_encode(array('result'=>WPVIVID_FAILED,'error'=>$message));
3155
+ }
3156
+
3157
+ die();
3158
+ }
3159
+ }
3160
  /**
3161
  * Start rollback
3162
  *
3164
  */
3165
  public function rollback()
3166
  {
3167
+ $this->_enable_maintenance_mode();
3168
+ try
3169
+ {
3170
+ $rollback=new WPvivid_RollBack();
3171
+ $rollback->rollback();
3172
+ }
3173
+ catch (Exception $error)
3174
+ {
3175
+ $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3176
+ error_log($message);
3177
+ $this->_disable_maintenance_mode();
3178
+ echo json_encode(array('result'=>'failed','error'=>$message));
3179
+ die();
3180
+ }
3181
+ catch (Error $error)
3182
+ {
3183
+ $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3184
+ error_log($message);
3185
+ $this->_disable_maintenance_mode();
3186
+ echo json_encode(array('result'=>'failed','error'=>$message));
3187
+ die();
3188
+ }
3189
+ $this->_disable_maintenance_mode();
3190
+ echo json_encode(array('result'=>'finished'));
3191
+ die();
3192
+
3193
+
3194
+ $this->restore_data=new WPvivid_restore_data();
3195
+ if($this->restore_data->has_rollback())
3196
  {
3197
+ $status=$this->restore_data->get_rollback_status();
3198
 
3199
  if($status === WPVIVID_RESTORE_ERROR)
3200
  {
3201
  $ret['result']='failed';
3202
+ $ret['error']=$this->restore_data->get_rollback_error();
3203
  echo json_encode($ret);
3204
  die();
3205
  }
3206
  else if($status === WPVIVID_RESTORE_COMPLETED)
3207
  {
3208
+ $this->restore_data->write_rollback_log('disable maintenance mode','notice');
3209
  $this->_disable_maintenance_mode();
3210
  echo json_encode(array('result'=>'finished'));
3211
  die();
3213
  }
3214
  else
3215
  {
3216
+ $this->restore_data->init_rollback_data();
3217
+ $this->restore_data->write_rollback_log('init restore data','notice');
3218
  $this->_enable_maintenance_mode();
3219
+ $this->restore_data->write_rollback_log('enable maintenance mode','notice');
3220
  }
3221
 
3222
  try
3229
  {
3230
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3231
  error_log($message);
3232
+
3233
+ $this->restore_data->update_rollback_error($message);
3234
+ $this->restore_data->write_rollback_log($message,'error');
3235
  $this->_disable_maintenance_mode();
3236
  echo json_encode(array('result'=>'failed','error'=>$message));
3237
  die();
3240
  {
3241
  $message = 'An error has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
3242
  error_log($message);
3243
+
3244
+ $this->restore_data->update_rollback_error($message);
3245
+ $this->restore_data->write_rollback_log($message,'error');
3246
  $this->_disable_maintenance_mode();
3247
  echo json_encode(array('result'=>'failed','error'=>$message));
3248
  die();
3258
  */
3259
  public function get_restore_progress()
3260
  {
3261
+ $this->restore_data=new WPvivid_restore_data();
3262
 
3263
+ if($this->restore_data->has_restore())
3264
  {
3265
  $ret['result']='success';
3266
+ $ret['status']= $this->restore_data->get_restore_status();
3267
+ $ret['log']=$this->restore_data->get_log_content();
3268
  echo json_encode($ret);
3269
  die();
3270
  }
3283
  */
3284
  public function get_rollback_progress()
3285
  {
3286
+ $this->restore_data=new WPvivid_restore_data();
3287
 
3288
+ if($this->restore_data->has_rollback())
3289
  {
3290
  $ret['result']='success';
3291
+ $ret['status']= $this->restore_data->get_rollback_status();
3292
+ $ret['log']=$this->restore_data->get_rollback_log_content();
3293
  echo json_encode($ret);
3294
  die();
3295
  }
3302
  }
3303
  }
3304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3305
  public function init_filesystem()
3306
  {
3307
  $credentials = request_filesystem_credentials(wp_nonce_url(admin_url('admin.php')."?page=WPvivid", 'wpvivid-nonce'));
3320
  $this->init_filesystem();
3321
  global $wp_filesystem;
3322
  $file = $wp_filesystem->abspath() . '.maintenance';
3323
+ $maintenance_string = '<?php $upgrading = ' . (time()+1200) . ';';
3324
  $maintenance_string.='global $wp_version;';
3325
  $maintenance_string.='$version_check=version_compare($wp_version,4.6,\'>\' );';
3326
  $maintenance_string.='if($version_check)';
3444
  }
3445
 
3446
  public function _list_tasks($backup_id){
 
3447
  $tasks=WPvivid_Setting::get_tasks();
3448
  $ret=array();
3449
  $list_tasks=array();
3451
  {
3452
  if($task['action']=='backup')
3453
  {
3454
+ $backup=new WPvivid_Backup_Task($task['id']);
3455
+ $list_tasks[$task['id']]=$backup->get_backup_task_info($task['id']);
3456
+ if($list_tasks[$task['id']]['task_info']['need_next_schedule']===true){
3457
+ $timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT,array($task['id']));
3458
 
3459
+ if($timestamp===false)
 
 
3460
  {
3461
+ $this->add_monitor_event($task['id'],20);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3462
  }
3463
  }
3464
+ if($list_tasks[$task['id']]['task_info']['need_update_last_task']===true){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3465
  $task_msg = WPvivid_taskmanager::get_task($task['id']);
3466
  $this->update_last_backup_task($task_msg);
3467
  }
 
 
 
 
 
 
 
 
3468
  $list_tasks[$task['id']]['progress_html'] = '<div class="action-progress-bar" id="wpvivid_action_progress_bar">
3469
+ <div class="action-progress-bar-percent" id="wpvivid_action_progress_bar_percent" style="height:24px;width:' . $list_tasks[$task['id']]['task_info']['backup_percent'] . '"></div>
3470
  </div>
3471
+ <div id="wpvivid_estimate_backup_info" style="float:left; ' . $list_tasks[$task['id']]['task_info']['display_estimate_backup'] . '">
3472
+ <div class="backup-basic-info"><span>' . __('Database Size:', 'wpvivid') . '</span><span id="wpvivid_backup_database_size">' . $list_tasks[$task['id']]['task_info']['db_size'] . '</span></div>
3473
+ <div class="backup-basic-info"><span>' . __('File Size:', 'wpvivid') . '</span><span id="wpvivid_backup_file_size">' . $list_tasks[$task['id']]['task_info']['file_size'] . '</span></div>
3474
  </div>
3475
  <div id="wpvivid_estimate_upload_info" style="float: left;">
3476
+ <div class="backup-basic-info"><span>' . __('Total Size:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['total'] . '</span></div>
3477
+ <div class="backup-basic-info"><span>' . __('Uploaded:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['upload'] . '</span></div>
3478
+ <div class="backup-basic-info"><span>' . __('Speed:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['speed'] . '</span></div>
3479
+ </div>
3480
+ <div style="float: left;">
3481
+ <div class="backup-basic-info"><span>' . __('Network Connection:', 'wpvivid') . '</span><span>' . $list_tasks[$task['id']]['task_info']['network_connection'] . '</span></div>
3482
  </div>
3483
  <div style="clear:both;"></div>
3484
+ <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing">' . $list_tasks[$task['id']]['task_info']['descript'] . '</p></div>
3485
  <div style="clear: both;"></div>
3486
  <div>
3487
+ <div id="wpvivid_backup_cancel" class="backup-log-btn"><input class="button-primary" id="wpvivid_backup_cancel_btn" type="submit" value="' . esc_attr('Cancel', 'wpvivid') . '" onclick="wpvivid_cancel_backup();" style="' . $list_tasks[$task['id']]['task_info']['css_btn_cancel'] . '" /></div>
3488
+ <div id="wpvivid_backup_log" class="backup-log-btn"><input class="button-primary backup-log-btn" id="wpvivid_backup_log_btn" type="submit" value="' . esc_attr('Log', 'wpvivid') . '" onclick="wpvivid_read_log(\'' . __('wpvivid_view_backup_task_log') . '\');" style="' . $list_tasks[$task['id']]['task_info']['css_btn_log'] . '" /></div>
3489
  </div>
3490
  <div style="clear: both;"></div>';
3491
  }
3532
  $ret['backup']['result']='success';
3533
  $ret['backup']['data']=$list_tasks;
3534
 
3535
+ $ret['download']=array();
3536
+ if($backup_id !== false && !empty($backup_id)) {
3537
+ $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
3538
+ if($backup===false)
3539
+ {
3540
+ $ret['result']=WPVIVID_FAILED;
3541
+ $ret['error']='backup id not found';
3542
+ return $ret;
3543
+ }
3544
+ $backup_item=new WPvivid_Backup_Item($backup);
3545
+ $ret['download']=$backup_item->update_download_page($backup_id);
3546
+ //$ret=$backup_item->get_download_backup_files($backup_id);
3547
+ //$ret['download'] = self::update_download_page($backup_id);
3548
  }
3549
 
3550
  $html='';
3759
  {
3760
  $this->delete_backup_by_id($backup_id);
3761
  }
 
3762
  $ret['result']='success';
3763
+ $html = '';
3764
+ $html = apply_filters('wpvivid_add_backup_list', $html);
3765
+ $ret['html'] = $html;
3766
  echo json_encode($ret);
3767
  die();
3768
  }
3833
  {
3834
  $list=WPvivid_Backuplist::get_backuplist();
3835
  $files=array();
3836
+ foreach ($list as $backup_id => $backup_value)
3837
  {
3838
+ $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
3839
+ if($backup===false)
3840
  {
3841
+ continue;
 
 
 
3842
  }
3843
+ $backup_item = new WPvivid_Backup_Item($backup);
3844
+ $file=$backup_item->get_files(false);
3845
+ foreach ($file as $filename){
3846
+ $files[]=$filename;
 
 
 
 
 
3847
  }
3848
  }
3849
 
3854
  $path = substr($path, 0, -1);
3855
  }
3856
  $folder[]= $path;
3857
+ $except_regex['file'][]='&wpvivid-&';
3858
+ $except_regex['file'][]='&wpvivid_temp-&';
3859
+ $this -> get_dir_files($delete_files,$delete_folder,$dir,$except_regex,$files,$folder,0,false);
3860
  }
3861
 
3862
  if($options['old_files']=='1')
3863
  {
3864
+ $this->restore_data=new WPvivid_restore_data();
3865
+ $this->restore_data->delete_old_files();
3866
  }
3867
 
3868
  foreach ($delete_files as $file)
4584
  $line = fgets($handle);
4585
  if($line!==false)
4586
  {
4587
+ $pos=strpos($line,'Log created: ');
4588
  if($pos!==false)
4589
  {
4590
+ $log_file['time']=substr ($line,$pos+strlen('Log created: '));
4591
  }
4592
  }
4593
  $line = fgets($handle);
4594
  if($line!==false)
4595
  {
4596
+ $pos=strpos($line,'Type: ');
4597
  if($pos!==false)
4598
  {
4599
+ $log_file['des']=substr ($line,$pos+strlen('Type: '));
4600
  }
4601
  }
4602
 
4858
  $remote=apply_filters('wpvivid_remote_pic', $remote);
4859
 
4860
  foreach ($backuplist as $key=>$value) {
4861
+ $row_style = '';
4862
+ if($value['type'] == 'Migration' || $value['type'] == 'Upload'){
4863
+ $row_style = 'border: 2px solid #006799; box-sizing:border-box; -moz-box-sizing:border-box; -webkit-box-sizing:border-box;';
4864
+ }
4865
+ else if($value['type'] == 'Manual' || $value['type'] == 'Cron'){
4866
+ $row_style = '';
4867
+ }
4868
+
4869
  if(empty($value['lock'])){
4870
  $backup_lock='/admin/partials/images/unlocked.png';
4871
  $lock_status='unlock';
4885
  $save_local_pic_y = '/admin/partials/images/storage-local.png';
4886
  $save_local_pic_n = '/admin/partials/images/storage-local(gray).png';
4887
  $local_title = 'Localhost';
4888
+ if($value['save_local'] == 1 || $value['type'] == 'Migration'){
4889
  $remote_pic_html .= '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $save_local_pic_y) . '" style="vertical-align:middle; " title="' . $local_title . '"/>';
4890
  }
4891
  else{
4909
  $remote_pic_html .= '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $pic) . '" style="vertical-align:middle; " title="' . $title . '"/>';
4910
  }
4911
  }
4912
+ //<tr style="'.$row_style.'">
4913
+ $html .= '<tr style="'.$row_style.'">
4914
  <th class="check-column"><input name="check_backup" type="checkbox" id="'.esc_attr($key, 'wpvivid').'" value="'.esc_attr($key, 'wpvivid').'" onclick="wpvivid_click_check_backup(\''.__($key, 'wpvivid').'\');" /></th>
4915
  <td class="tablelistcolumn">
4916
  <div style="float:left;padding:0 10px 10px 0;">
4919
  <span title="To lock the backup, the backup can only be deleted manually" id="wpvivid_lock_'.$key.'">
4920
  <img src="'.esc_url(WPVIVID_PLUGIN_URL.$backup_lock).'" name="'.esc_attr($lock_status, 'wpvivid').'" onclick="wpvivid_set_backup_lock(\''.__($key, 'wpvivid').'\', \''.__($lock_status, 'wpvivid').'\');" style="vertical-align:middle; cursor:pointer;"/>
4921
  </span>
4922
+ <span style="margin:0;">|</span> <span>'.__('Type:', 'wpvivid').'</span><span>'.__($value['type'], 'wpvivid').'</span>
4923
+ <span style="margin:0;">|</span> <span title="Backup log"><a href="#" onclick="wpvivid_read_log(\''.__('wpvivid_view_backup_log').'\', \''.__($key).'\');"><img src="'.esc_url(WPVIVID_PLUGIN_URL.'/admin/partials/images/Log.png').'" style="vertical-align:middle;cursor:pointer;"/><span style="margin:0;">'.__('Log', 'wpvivid').'</span></a></span>
4924
+ <span style="margin:0;">|</span> <span title="Restore Website from The Backup"><a href="#" onclick="wpvivid_initialize_restore(\''.__($key, 'wpvivid').'\',\''.__(date('M d, Y H:i',$value['create_time']), 'wpvivid').'\');"><img src="'.esc_url(WPVIVID_PLUGIN_URL. '/admin/partials/images/Restore.png').'" style="vertical-align:middle;cursor:pointer;"/><span style="margin:0;">'.__('Restore', 'wpvivid').'</span></a></span>
4925
  </div>
4926
  </div>
4927
  </td>
4931
  <td class="tablelistcolumn">
4932
  <div id="wpvivid_file_part_'.__($key, 'wpvivid').'" style="float:left;padding:10px 10px 10px 0;">
4933
  <div style="cursor:pointer;" onclick="wpvivid_initialize_download(\''.__($key, 'wpvivid').'\');" title="Prepare to download the backup">
4934
+ <img id="wpvivid_download_btn_'.__($key, 'wpvivid').'" src="'.esc_url(WPVIVID_PLUGIN_URL.'/admin/partials/images/download.png').'" style="vertical-align:middle;" /><span>'.__('Download', 'wpvivid').'</span>
4935
  <div class="spinner" id="wpvivid_download_loading_'.__($key, 'wpvivid').'" style="float:right;width:auto;height:auto;padding:10px 180px 10px 0;background-position:0 0;"></div>
4936
  </div>
4937
  </div>
includes/customclass/class-wpvivid-dropbox.php CHANGED
@@ -259,124 +259,134 @@ class WPvivid_Dropbox extends WPvivid_Remote {
259
  {
260
  if($_GET['action'] === 'wpvivid_dropbox_auth')
261
  {
262
- if(!isset($_GET['name'])||empty($_GET['name']))
263
- {
264
- _e('<div class="notice notice-warning is-dismissible"><p>Warning: An alias for remote storage is required.</p></div>');
265
- return;
266
- }
267
 
268
- $_GET['name']=sanitize_text_field($_GET['name']);
269
 
270
- $remoteslist=WPvivid_Setting::get_all_remote_options();
271
- foreach ($remoteslist as $key=>$value)
272
- {
273
- if(isset($value['name'])&&$value['name'] == $_GET['name'])
274
- {
275
- _e('<div class="notice notice-warning is-dismissible"><p>Warning: The alias already exists in storage list.</p></div>');
276
- return;
277
  }
 
 
 
 
 
 
278
  }
279
- $state = admin_url().'admin.php?page=WPvivid'.'&action=wpvivid_dropbox_finish_auth&name='.$_GET['name'].'&bdefault='.$_GET['bdefault'];
280
- $url = Dropbox_Base::getUrl($this -> redirect_url,$state);
281
- header('Location: ' . filter_var($url, FILTER_SANITIZE_URL));
282
  }
283
  else if($_GET['action'] === 'wpvivid_dropbox_finish_auth')
284
  {
285
- if(!isset($_GET['code'])){
286
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_dropbox_drive&result=error&resp_msg='.'Get Dropbox token failed.');
287
- }else{
288
- global $wpvivid_pulgin;
289
- $remote_options['type']=WPVIVID_REMOTE_DROPBOX;
290
- $remote_options['token']= $_GET['code'];
291
- $remote_options['name']=$_GET['name'];
292
- $remote_options['path'] =WPVIVID_DROPBOX_DEFAULT_FOLDER;
293
- $remote_options['default']=$_GET['bdefault'];
294
- $ret=$wpvivid_pulgin->remote_collection->add_remote($remote_options);
295
- if($ret['result']=='success')
296
- {
297
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_dropbox_drive&result=success');
298
- return;
299
- }
300
- else
301
- {
302
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_dropbox_drive&result=error&resp_msg='.$ret['error']);
303
- return;
304
  }
305
  }
 
 
 
306
  }
307
  else if($_GET['action']=='wpvivid_dropbox_drive')
308
  {
309
- if(isset($_GET['result']))
310
- {
311
- if($_GET['result']=='success')
312
- {
313
- add_action('show_notice', array($this, 'wpvivid_show_notice_add_dropbox_success'));
314
- }
315
- else if($_GET['result']=='error')
316
- {
317
- add_action('show_notice', array($this, 'wpvivid_show_notice_add_dropbox_error'));
318
  }
319
  }
 
 
 
320
  }
321
  else if($_GET['action'] === 'wpvivid_dropbox_update_auth')
322
  {
323
- if(!isset($_GET['name'])||empty($_GET['name']))
324
- {
325
- _e('<div class="notice notice-warning is-dismissible"><p>Warning: An alias for remote storage is required.</p></div>');
326
- return;
327
- }
328
 
329
- $_GET['name']=sanitize_text_field($_GET['name']);
330
 
331
- $remoteslist=WPvivid_Setting::get_all_remote_options();
332
- foreach ($remoteslist as $key=>$value)
333
- {
334
- if(isset($value['name'])&&$value['name'] == $_GET['name']&&$key!=$_GET['id'])
335
- {
336
- _e('<div class="notice notice-warning is-dismissible"><p>Warning: The alias already exists in storage list.</p></div>');
337
- return;
338
  }
 
 
 
 
 
 
339
  }
340
- $state = admin_url().'admin.php?page=WPvivid'.'&action=wpvivid_dropbox_finish_update_auth&name='.$_GET['name'].'&id='.$_GET['id'];
341
- $url = Dropbox_Base::getUrl($this -> redirect_url,$state);
342
- header('Location: ' . filter_var($url, FILTER_SANITIZE_URL));
343
  }
344
  else if($_GET['action'] === 'wpvivid_dropbox_finish_update_auth')
345
  {
346
- if(!isset($_GET['code'])){
347
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_dropbox_drive_update&result=error&resp_msg='.'Get Dropbox token failed.');
348
- }else{
349
- global $wpvivid_pulgin;
350
- $remote_options['type']=WPVIVID_REMOTE_DROPBOX;
351
- $remote_options['token']= $_GET['code'];
352
- $remote_options['name']=$_GET['name'];
353
- $remote_options['path'] =WPVIVID_DROPBOX_DEFAULT_FOLDER;
354
- $ret=$wpvivid_pulgin->remote_collection->update_remote($_GET['id'],$remote_options);
355
- if($ret['result']=='success')
356
- {
357
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_dropbox_drive_update&result=success');
358
- return;
359
- }
360
- else
361
- {
362
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_dropbox_drive_update&result=error&resp_msg='.$ret['error']);
363
- return;
364
  }
365
  }
 
 
 
366
  }
367
  else if($_GET['action']=='wpvivid_dropbox_drive_update')
368
  {
369
- if(isset($_GET['result']))
370
- {
371
- if($_GET['result']=='success')
372
- {
373
- add_action('show_notice', array($this, 'wpvivid_show_notice_edit_dropbox_success'));
374
- }
375
- else if($_GET['result']=='error')
376
- {
377
- add_action('show_notice', array($this, 'wpvivid_show_notice_edit_dropbox_error'));
378
  }
379
  }
 
 
 
380
  }
381
  }
382
  }
259
  {
260
  if($_GET['action'] === 'wpvivid_dropbox_auth')
261
  {
262
+ try {
263
+ if (!isset($_GET['name']) || empty($_GET['name'])) {
264
+ _e('<div class="notice notice-warning is-dismissible"><p>Warning: An alias for remote storage is required.</p></div>');
265
+ return;
266
+ }
267
 
268
+ $_GET['name'] = sanitize_text_field($_GET['name']);
269
 
270
+ $remoteslist = WPvivid_Setting::get_all_remote_options();
271
+ foreach ($remoteslist as $key => $value) {
272
+ if (isset($value['name']) && $value['name'] == $_GET['name']) {
273
+ _e('<div class="notice notice-warning is-dismissible"><p>Warning: The alias already exists in storage list.</p></div>');
274
+ return;
275
+ }
 
276
  }
277
+ $state = admin_url() . 'admin.php?page=WPvivid' . '&action=wpvivid_dropbox_finish_auth&name=' . $_GET['name'] . '&bdefault=' . $_GET['bdefault'];
278
+ $url = Dropbox_Base::getUrl($this->redirect_url, $state);
279
+ header('Location: ' . filter_var($url, FILTER_SANITIZE_URL));
280
+ }
281
+ catch (Exception $e){
282
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
283
  }
 
 
 
284
  }
285
  else if($_GET['action'] === 'wpvivid_dropbox_finish_auth')
286
  {
287
+ try {
288
+ if (!isset($_GET['code'])) {
289
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=error&resp_msg=' . 'Get Dropbox token failed.');
290
+ } else {
291
+ global $wpvivid_pulgin;
292
+ $remote_options['type'] = WPVIVID_REMOTE_DROPBOX;
293
+ $remote_options['token'] = $_GET['code'];
294
+ $remote_options['name'] = $_GET['name'];
295
+ $remote_options['path'] = WPVIVID_DROPBOX_DEFAULT_FOLDER;
296
+ $remote_options['default'] = $_GET['bdefault'];
297
+ $ret = $wpvivid_pulgin->remote_collection->add_remote($remote_options);
298
+ if ($ret['result'] == 'success') {
299
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=success');
300
+ return;
301
+ } else {
302
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=error&resp_msg=' . $ret['error']);
303
+ return;
304
+ }
 
305
  }
306
  }
307
+ catch (Exception $e){
308
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
309
+ }
310
  }
311
  else if($_GET['action']=='wpvivid_dropbox_drive')
312
  {
313
+ try {
314
+ if (isset($_GET['result'])) {
315
+ if ($_GET['result'] == 'success') {
316
+ add_action('show_notice', array($this, 'wpvivid_show_notice_add_dropbox_success'));
317
+ } else if ($_GET['result'] == 'error') {
318
+ add_action('show_notice', array($this, 'wpvivid_show_notice_add_dropbox_error'));
319
+ }
 
 
320
  }
321
  }
322
+ catch (Exception $e){
323
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
324
+ }
325
  }
326
  else if($_GET['action'] === 'wpvivid_dropbox_update_auth')
327
  {
328
+ try {
329
+ if (!isset($_GET['name']) || empty($_GET['name'])) {
330
+ _e('<div class="notice notice-warning is-dismissible"><p>Warning: An alias for remote storage is required.</p></div>');
331
+ return;
332
+ }
333
 
334
+ $_GET['name'] = sanitize_text_field($_GET['name']);
335
 
336
+ $remoteslist = WPvivid_Setting::get_all_remote_options();
337
+ foreach ($remoteslist as $key => $value) {
338
+ if (isset($value['name']) && $value['name'] == $_GET['name'] && $key != $_GET['id']) {
339
+ _e('<div class="notice notice-warning is-dismissible"><p>Warning: The alias already exists in storage list.</p></div>');
340
+ return;
341
+ }
 
342
  }
343
+ $state = admin_url() . 'admin.php?page=WPvivid' . '&action=wpvivid_dropbox_finish_update_auth&name=' . $_GET['name'] . '&id=' . $_GET['id'];
344
+ $url = Dropbox_Base::getUrl($this->redirect_url, $state);
345
+ header('Location: ' . filter_var($url, FILTER_SANITIZE_URL));
346
+ }
347
+ catch (Exception $e){
348
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
349
  }
 
 
 
350
  }
351
  else if($_GET['action'] === 'wpvivid_dropbox_finish_update_auth')
352
  {
353
+ try {
354
+ if (!isset($_GET['code'])) {
355
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive_update&result=error&resp_msg=' . 'Get Dropbox token failed.');
356
+ } else {
357
+ global $wpvivid_pulgin;
358
+ $remote_options['type'] = WPVIVID_REMOTE_DROPBOX;
359
+ $remote_options['token'] = $_GET['code'];
360
+ $remote_options['name'] = $_GET['name'];
361
+ $remote_options['path'] = WPVIVID_DROPBOX_DEFAULT_FOLDER;
362
+ $ret = $wpvivid_pulgin->remote_collection->update_remote($_GET['id'], $remote_options);
363
+ if ($ret['result'] == 'success') {
364
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive_update&result=success');
365
+ return;
366
+ } else {
367
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive_update&result=error&resp_msg=' . $ret['error']);
368
+ return;
369
+ }
 
370
  }
371
  }
372
+ catch (Exception $e){
373
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
374
+ }
375
  }
376
  else if($_GET['action']=='wpvivid_dropbox_drive_update')
377
  {
378
+ try {
379
+ if (isset($_GET['result'])) {
380
+ if ($_GET['result'] == 'success') {
381
+ add_action('show_notice', array($this, 'wpvivid_show_notice_edit_dropbox_success'));
382
+ } else if ($_GET['result'] == 'error') {
383
+ add_action('show_notice', array($this, 'wpvivid_show_notice_edit_dropbox_error'));
384
+ }
 
 
385
  }
386
  }
387
+ catch (Exception $e){
388
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
389
+ }
390
  }
391
  }
392
  }
includes/customclass/class-wpvivid-google-drive.php CHANGED
@@ -78,60 +78,78 @@ class Wpvivid_Google_drive extends WPvivid_Remote
78
  _e('<div class="notice notice-warning is-dismissible"><p>'.$res['error'].'</p></div>');
79
  return ;
80
  }
81
- include_once WPVIVID_PLUGIN_DIR.'/vendor/autoload.php';
82
- $client = new Google_Client();
83
- $client->setAuthConfig(WPVIVID_GOOGLEDRIVE_SECRETS);
84
- $client->setApprovalPrompt('force');
85
- $client->addScope(Google_Service_Drive::DRIVE_FILE);
86
- $client->setAccessType('offline');
87
- $client->setState(admin_url().'admin.php?page=WPvivid'.'&action=wpvivid_google_drive_finish_auth&name='.$_GET['name'].'&default='.$_GET['default']);
88
- $auth_url = $client->createAuthUrl();
89
- header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  }
91
  else if($_GET['action']=='wpvivid_google_drive_finish_auth')
92
  {
93
- if(isset($_GET['error']))
94
- {
95
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_google_drive&result=error&resp_msg='.$_GET['error']);
 
96
 
97
- return;
98
- }
99
 
100
- global $wpvivid_pulgin;
101
 
102
- $remote_options['type']=WPVIVID_REMOTE_GOOGLEDRIVE;
103
- $token=$_GET['token'];
104
- $token = stripslashes($token);
105
- $remote_options['token']=json_decode($token,1);
106
- $remote_options['name']=$_GET['name'];
107
- $remote_options['default']=$_GET['default'];
108
- $remote_options['path']=WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER;
109
- $ret=$wpvivid_pulgin->remote_collection->add_remote($remote_options);
110
 
111
- if($ret['result']=='success')
112
- {
113
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_google_drive&result=success');
114
- return;
 
 
 
115
  }
116
- else
117
- {
118
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_google_drive&result=error&resp_msg='.$ret['error']);
119
- return;
120
  }
121
  }
122
  else if($_GET['action']=='wpvivid_google_drive')
123
  {
124
- if(isset($_GET['result']))
125
- {
126
- if($_GET['result']=='success')
127
- {
128
- add_action('show_notice', array($this, 'wpvivid_show_notice_add_google_drive_success'));
129
- }
130
- else if($_GET['result']=='error')
131
- {
132
- add_action('show_notice', array($this, 'wpvivid_show_notice_add_google_drive_error'));
133
  }
134
  }
 
 
 
135
  }
136
  else if($_GET['action']=='wpvivid_google_drive_update_auth')
137
  {
@@ -153,59 +171,77 @@ class Wpvivid_Google_drive extends WPvivid_Remote
153
  }
154
  }
155
 
156
- include_once WPVIVID_PLUGIN_DIR.'/vendor/autoload.php';
157
- $client = new Google_Client();
158
- $client->setAuthConfig(WPVIVID_GOOGLEDRIVE_SECRETS);
159
- $client->setApprovalPrompt('force');
160
- $client->addScope(Google_Service_Drive::DRIVE_FILE);
161
- $client->setAccessType('offline');
162
- $client->setState(admin_url().'admin.php?page=WPvivid'.'&action=wpvivid_google_drive_finish_update_auth&name='.$_GET['name'].'&id='.$_GET['id']);
163
- $auth_url = $client->createAuthUrl();
164
- header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  }
166
  else if($_GET['action']=='wpvivid_google_drive_finish_update_auth')
167
  {
168
- if(isset($_GET['error']))
169
- {
170
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_google_drive_update&result=error&resp_msg='.$_GET['error']);
 
171
 
172
- return;
173
- }
174
 
175
- global $wpvivid_pulgin;
176
 
177
- $remote_options['type']=WPVIVID_REMOTE_GOOGLEDRIVE;
178
- $token=$_GET['token'];
179
- $token = stripslashes($token);
180
- $remote_options['token']=json_decode($token,1);
181
- $remote_options['name']=$_GET['name'];
182
- $remote_options['path']=WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER;
183
- $ret=$wpvivid_pulgin->remote_collection->update_remote($_GET['id'],$remote_options);
184
 
185
- if($ret['result']=='success')
186
- {
187
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_google_drive_update&result=success');
188
- return;
 
 
 
189
  }
190
- else
191
- {
192
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_google_drive_update&result=error&resp_msg='.$ret['error']);
193
- return;
194
  }
195
  }
196
  else if($_GET['action']=='wpvivid_google_drive_update')
197
  {
198
- if(isset($_GET['result']))
199
- {
200
- if($_GET['result']=='success')
201
- {
202
- add_action('show_notice', array($this, 'wpvivid_show_notice_edit_google_drive_success'));
203
- }
204
- else if($_GET['result']=='error')
205
- {
206
- add_action('show_notice', array($this, 'wpvivid_show_notice_edit_google_drive_error'));
207
  }
208
  }
 
 
 
209
  }
210
  }
211
  }
78
  _e('<div class="notice notice-warning is-dismissible"><p>'.$res['error'].'</p></div>');
79
  return ;
80
  }
81
+ try {
82
+ include_once WPVIVID_PLUGIN_DIR . '/vendor/autoload.php';
83
+ $client = new Google_Client();
84
+ $client->setAuthConfig(WPVIVID_GOOGLEDRIVE_SECRETS);
85
+ $client->setApprovalPrompt('force');
86
+ $client->addScope(Google_Service_Drive::DRIVE_FILE);
87
+ $client->setAccessType('offline');
88
+ $client->setState(admin_url() . 'admin.php?page=WPvivid' . '&action=wpvivid_google_drive_finish_auth&name=' . $_GET['name'] . '&default=' . $_GET['default']);
89
+ $auth_url = $client->createAuthUrl();
90
+ header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
91
+ }
92
+ catch (Exception $e){
93
+ if($e->getMessage() === 'file does not exist'){
94
+ $error_msg = 'Authentication failed, the client_secrets.json file is missing. Please make sure the client_secrets.json file is in wpvivid-backuprestore\includes\customclass directory.';
95
+ _e('<div class="notice notice-error"><p>'.$error_msg.'</p></div>');
96
+ }
97
+ else if($e->getMessage() === 'invalid json for auth config'){
98
+ $error_msg = 'Authentication failed, the format of the client_secrets.json file is incorrect. Please delete and re-install the plugin to recreate the file.';
99
+ _e('<div class="notice notice-error"><p>'.$error_msg.'</p></div>');
100
+ }
101
+ else{
102
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
103
+ }
104
+ }
105
  }
106
  else if($_GET['action']=='wpvivid_google_drive_finish_auth')
107
  {
108
+ try {
109
+ if(isset($_GET['error']))
110
+ {
111
+ header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_google_drive&result=error&resp_msg='.$_GET['error']);
112
 
113
+ return;
114
+ }
115
 
116
+ global $wpvivid_pulgin;
117
 
118
+ $remote_options['type'] = WPVIVID_REMOTE_GOOGLEDRIVE;
119
+ $token = $_GET['token'];
120
+ $token = stripslashes($token);
121
+ $remote_options['token'] = json_decode($token, 1);
122
+ $remote_options['name'] = $_GET['name'];
123
+ $remote_options['default'] = $_GET['default'];
124
+ $remote_options['path'] = WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER;
125
+ $ret = $wpvivid_pulgin->remote_collection->add_remote($remote_options);
126
 
127
+ if ($ret['result'] == 'success') {
128
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_google_drive&result=success');
129
+ return;
130
+ } else {
131
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_google_drive&result=error&resp_msg=' . $ret['error']);
132
+ return;
133
+ }
134
  }
135
+ catch (Exception $e){
136
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
 
 
137
  }
138
  }
139
  else if($_GET['action']=='wpvivid_google_drive')
140
  {
141
+ try {
142
+ if (isset($_GET['result'])) {
143
+ if ($_GET['result'] == 'success') {
144
+ add_action('show_notice', array($this, 'wpvivid_show_notice_add_google_drive_success'));
145
+ } else if ($_GET['result'] == 'error') {
146
+ add_action('show_notice', array($this, 'wpvivid_show_notice_add_google_drive_error'));
147
+ }
 
 
148
  }
149
  }
150
+ catch (Exception $e){
151
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
152
+ }
153
  }
154
  else if($_GET['action']=='wpvivid_google_drive_update_auth')
155
  {
171
  }
172
  }
173
 
174
+ try {
175
+ include_once WPVIVID_PLUGIN_DIR . '/vendor/autoload.php';
176
+ $client = new Google_Client();
177
+ $client->setAuthConfig(WPVIVID_GOOGLEDRIVE_SECRETS);
178
+ $client->setApprovalPrompt('force');
179
+ $client->addScope(Google_Service_Drive::DRIVE_FILE);
180
+ $client->setAccessType('offline');
181
+ $client->setState(admin_url() . 'admin.php?page=WPvivid' . '&action=wpvivid_google_drive_finish_update_auth&name=' . $_GET['name'] . '&id=' . $_GET['id']);
182
+ $auth_url = $client->createAuthUrl();
183
+ header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
184
+ }
185
+ catch (Exception $e){
186
+ if($e->getMessage() === 'file does not exist'){
187
+ $error_msg = 'Authentication failed, the client_secrets.json file is missing. Please make sure the client_secrets.json file is in wpvivid-backuprestore\includes\customclass directory.';
188
+ _e('<div class="notice notice-error"><p>'.$error_msg.'</p></div>');
189
+ }
190
+ else if($e->getMessage() === 'invalid json for auth config'){
191
+ $error_msg = 'Authentication failed, the format of the client_secrets.json file is incorrect. Please delete and re-install the plugin to recreate the file.';
192
+ _e('<div class="notice notice-error"><p>'.$error_msg.'</p></div>');
193
+ }
194
+ else{
195
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
196
+ }
197
+ }
198
  }
199
  else if($_GET['action']=='wpvivid_google_drive_finish_update_auth')
200
  {
201
+ try {
202
+ if(isset($_GET['error']))
203
+ {
204
+ header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_google_drive_update&result=error&resp_msg='.$_GET['error']);
205
 
206
+ return;
207
+ }
208
 
209
+ global $wpvivid_pulgin;
210
 
211
+ $remote_options['type'] = WPVIVID_REMOTE_GOOGLEDRIVE;
212
+ $token = $_GET['token'];
213
+ $token = stripslashes($token);
214
+ $remote_options['token'] = json_decode($token, 1);
215
+ $remote_options['name'] = $_GET['name'];
216
+ $remote_options['path'] = WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER;
217
+ $ret = $wpvivid_pulgin->remote_collection->update_remote($_GET['id'], $remote_options);
218
 
219
+ if ($ret['result'] == 'success') {
220
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_google_drive_update&result=success');
221
+ return;
222
+ } else {
223
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_google_drive_update&result=error&resp_msg=' . $ret['error']);
224
+ return;
225
+ }
226
  }
227
+ catch (Exception $e){
228
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
 
 
229
  }
230
  }
231
  else if($_GET['action']=='wpvivid_google_drive_update')
232
  {
233
+ try {
234
+ if (isset($_GET['result'])) {
235
+ if ($_GET['result'] == 'success') {
236
+ add_action('show_notice', array($this, 'wpvivid_show_notice_edit_google_drive_success'));
237
+ } else if ($_GET['result'] == 'error') {
238
+ add_action('show_notice', array($this, 'wpvivid_show_notice_edit_google_drive_error'));
239
+ }
 
 
240
  }
241
  }
242
+ catch (Exception $e){
243
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
244
+ }
245
  }
246
  }
247
  }
includes/customclass/class-wpvivid-one-drive.php CHANGED
@@ -62,158 +62,166 @@ class WPvivid_one_drive extends WPvivid_Remote
62
  {
63
  if($_GET['action']=='wpvivid_one_drive_auth')
64
  {
65
- if(!isset($_GET['name'])||empty($_GET['name']))
66
- {
67
- _e('<div class="notice notice-warning is-dismissible"><p>Warning: An alias for remote storage is required.</p></div>');
68
- return;
69
- }
70
 
71
- $_GET['name']=sanitize_text_field($_GET['name']);
72
 
73
- $remoteslist=WPvivid_Setting::get_all_remote_options();
74
- foreach ($remoteslist as $key=>$value)
75
- {
76
- if(isset($value['name'])&&$value['name'] == $_GET['name'])
77
- {
78
- _e('<div class="notice notice-warning is-dismissible"><p>Warning: The alias already exists in storage list.</p></div>');
79
- return;
80
  }
81
- }
82
 
83
- $url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
84
- . '?client_id=' . urlencode('37668be9-b55f-458f-b6a3-97e6f8aa10c9')
85
- . '&scope=' . urlencode('offline_access files.readwrite')
86
- . '&response_type=code'
87
- . '&redirect_uri=' . urlencode('https://auth.wpvivid.com/onedrive')
88
- . '&state=' . urlencode(admin_url().'admin.php?page=WPvivid'.'&action=wpvivid_one_drive_finish_auth&name='.$_GET['name'].'&default='.$_GET['default'])
89
- . '&display=popup'
90
- . '&locale=en';
91
- header('Location: '.esc_url_raw($url));
 
 
 
 
92
  }
93
  else if($_GET['action']=='wpvivid_one_drive_finish_auth')
94
  {
95
- if(isset($_GET['auth_error']))
96
- {
97
- $error=urldecode($_GET['auth_error']);
98
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_one_drive&result=error&resp_msg='.$error);
99
-
100
- return;
101
- }
102
 
103
- global $wpvivid_pulgin;
104
-
105
- $remote_options['type']=WPVIVID_REMOTE_ONEDRIVE;
106
- $token=$_GET['token'];
107
- $token = stripslashes($token);
108
- $remote_options['token']=json_decode($token,1);
109
- $remote_options['token']['expires']=time()+ $remote_options['token']['expires_in'];
110
- //
111
- $remote_options['name']=$_GET['name'];
112
- $remote_options['default']=$_GET['default'];
113
- $remote_options['path']=WPVIVID_ONEDRIVE_DEFAULT_FOLDER;
114
- $ret=$wpvivid_pulgin->remote_collection->add_remote($remote_options);
115
 
116
- if($ret['result']=='success')
117
- {
118
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_one_drive&result=success');
119
- return;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
- else
122
- {
123
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_one_drive&result=error&resp_msg='.$ret['error']);
124
- return;
125
  }
126
  }
127
  else if($_GET['action']=='wpvivid_one_drive')
128
  {
129
- if(isset($_GET['result']))
130
- {
131
- if($_GET['result']=='success')
132
- {
133
- add_action('show_notice', array($this, 'wpvivid_show_notice_add_onedrive_success'));
134
- }
135
- else if($_GET['result']=='error')
136
- {
137
- add_action('show_notice', array($this, 'wpvivid_show_notice_add_onedrive_error'));
138
  }
139
  }
 
 
 
140
  }
141
  else if($_GET['action']=='wpvivid_one_drive_update_auth')
142
  {
143
- if(!isset($_GET['name'])||empty($_GET['name']))
144
- {
145
- _e('<div class="notice notice-warning is-dismissible"><p>Warning: An alias for remote storage is required.</p></div>');
146
- return;
147
- }
148
 
149
- $_GET['name']=sanitize_text_field($_GET['name']);
150
 
151
- $remoteslist=WPvivid_Setting::get_all_remote_options();
152
- foreach ($remoteslist as $key=>$value)
153
- {
154
- if(isset($value['name'])&&$value['name'] == $_GET['name']&&$key!=$_GET['id'])
155
- {
156
- _e('<div class="notice notice-warning is-dismissible"><p>Warning: The alias already exists in storage list.</p></div>');
157
- return;
158
  }
159
- }
160
 
161
- $url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
162
- . '?client_id=' . urlencode('37668be9-b55f-458f-b6a3-97e6f8aa10c9')
163
- . '&scope=' . urlencode('offline_access files.readwrite')
164
- . '&response_type=code'
165
- . '&redirect_uri=' . urlencode('https://auth.wpvivid.com/onedrive')
166
- . '&state=' . urlencode(admin_url().'admin.php?page=WPvivid'.'&action=wpvivid_one_drive_update_finish_auth&name='.$_GET['name'].'&id='.$_GET['id'])
167
- . '&display=popup'
168
- . '&locale=en';
169
- header('Location: '.esc_url_raw($url));
 
 
 
 
170
  }
171
  else if($_GET['action']=='wpvivid_one_drive_update_finish_auth')
172
  {
173
- if(isset($_GET['auth_error']))
174
- {
175
- $error=urldecode($_GET['auth_error']);
176
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_one_drive_update&result=error&resp_msg='.$error);
177
 
178
- return;
179
- }
180
 
181
- global $wpvivid_pulgin;
182
 
183
- $remote_options['type']=WPVIVID_REMOTE_ONEDRIVE;
184
- $token=$_GET['token'];
185
- $token = stripslashes($token);
186
- $remote_options['token']=json_decode($token,1);
187
- $remote_options['token']['expires']=time()+ $remote_options['token']['expires_in'];
188
- //
189
- $remote_options['name']=$_GET['name'];
190
- $remote_options['path']=WPVIVID_ONEDRIVE_DEFAULT_FOLDER;
191
- $ret=$wpvivid_pulgin->remote_collection->update_remote($_GET['id'],$remote_options);
192
 
193
- if($ret['result']=='success')
194
- {
195
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_one_drive_update&result=success');
196
- return;
 
 
 
197
  }
198
- else
199
- {
200
- header('Location: '.admin_url().'admin.php?page='.WPVIVID_PLUGIN_SLUG.'&action=wpvivid_one_drive_update&result=error&resp_msg='.$ret['error']);
201
- return;
202
  }
203
  }
204
  else if($_GET['action']=='wpvivid_one_drive_update')
205
  {
206
- if(isset($_GET['result']))
207
- {
208
- if($_GET['result']=='success')
209
- {
210
- add_action('show_notice', array($this, 'wpvivid_show_notice_edit_onedrive_success'));
211
- }
212
- else if($_GET['result']=='error')
213
- {
214
- add_action('show_notice', array($this, 'wpvivid_show_notice_edit_onedrive_error'));
215
  }
216
  }
 
 
 
217
  }
218
  }
219
  }
62
  {
63
  if($_GET['action']=='wpvivid_one_drive_auth')
64
  {
65
+ try {
66
+ if (!isset($_GET['name']) || empty($_GET['name'])) {
67
+ _e('<div class="notice notice-warning is-dismissible"><p>Warning: An alias for remote storage is required.</p></div>');
68
+ return;
69
+ }
70
 
71
+ $_GET['name'] = sanitize_text_field($_GET['name']);
72
 
73
+ $remoteslist = WPvivid_Setting::get_all_remote_options();
74
+ foreach ($remoteslist as $key => $value) {
75
+ if (isset($value['name']) && $value['name'] == $_GET['name']) {
76
+ _e('<div class="notice notice-warning is-dismissible"><p>Warning: The alias already exists in storage list.</p></div>');
77
+ return;
78
+ }
 
79
  }
 
80
 
81
+ $url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
82
+ . '?client_id=' . urlencode('37668be9-b55f-458f-b6a3-97e6f8aa10c9')
83
+ . '&scope=' . urlencode('offline_access files.readwrite')
84
+ . '&response_type=code'
85
+ . '&redirect_uri=' . urlencode('https://auth.wpvivid.com/onedrive')
86
+ . '&state=' . urlencode(admin_url() . 'admin.php?page=WPvivid' . '&action=wpvivid_one_drive_finish_auth&name=' . $_GET['name'] . '&default=' . $_GET['default'])
87
+ . '&display=popup'
88
+ . '&locale=en';
89
+ header('Location: ' . esc_url_raw($url));
90
+ }
91
+ catch (Exception $e){
92
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
93
+ }
94
  }
95
  else if($_GET['action']=='wpvivid_one_drive_finish_auth')
96
  {
97
+ try {
98
+ if (isset($_GET['auth_error'])) {
99
+ $error = urldecode($_GET['auth_error']);
100
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive&result=error&resp_msg=' . $error);
 
 
 
101
 
102
+ return;
103
+ }
 
 
 
 
 
 
 
 
 
 
104
 
105
+ global $wpvivid_pulgin;
106
+
107
+ $remote_options['type'] = WPVIVID_REMOTE_ONEDRIVE;
108
+ $token = $_GET['token'];
109
+ $token = stripslashes($token);
110
+ $remote_options['token'] = json_decode($token, 1);
111
+ $remote_options['token']['expires'] = time() + $remote_options['token']['expires_in'];
112
+ //
113
+ $remote_options['name'] = $_GET['name'];
114
+ $remote_options['default'] = $_GET['default'];
115
+ $remote_options['path'] = WPVIVID_ONEDRIVE_DEFAULT_FOLDER;
116
+ $ret = $wpvivid_pulgin->remote_collection->add_remote($remote_options);
117
+
118
+ if ($ret['result'] == 'success') {
119
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive&result=success');
120
+ return;
121
+ } else {
122
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive&result=error&resp_msg=' . $ret['error']);
123
+ return;
124
+ }
125
  }
126
+ catch (Exception $e){
127
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
 
 
128
  }
129
  }
130
  else if($_GET['action']=='wpvivid_one_drive')
131
  {
132
+ try {
133
+ if (isset($_GET['result'])) {
134
+ if ($_GET['result'] == 'success') {
135
+ add_action('show_notice', array($this, 'wpvivid_show_notice_add_onedrive_success'));
136
+ } else if ($_GET['result'] == 'error') {
137
+ add_action('show_notice', array($this, 'wpvivid_show_notice_add_onedrive_error'));
138
+ }
 
 
139
  }
140
  }
141
+ catch (Exception $e){
142
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
143
+ }
144
  }
145
  else if($_GET['action']=='wpvivid_one_drive_update_auth')
146
  {
147
+ try {
148
+ if (!isset($_GET['name']) || empty($_GET['name'])) {
149
+ _e('<div class="notice notice-warning is-dismissible"><p>Warning: An alias for remote storage is required.</p></div>');
150
+ return;
151
+ }
152
 
153
+ $_GET['name'] = sanitize_text_field($_GET['name']);
154
 
155
+ $remoteslist = WPvivid_Setting::get_all_remote_options();
156
+ foreach ($remoteslist as $key => $value) {
157
+ if (isset($value['name']) && $value['name'] == $_GET['name'] && $key != $_GET['id']) {
158
+ _e('<div class="notice notice-warning is-dismissible"><p>Warning: The alias already exists in storage list.</p></div>');
159
+ return;
160
+ }
 
161
  }
 
162
 
163
+ $url = 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize'
164
+ . '?client_id=' . urlencode('37668be9-b55f-458f-b6a3-97e6f8aa10c9')
165
+ . '&scope=' . urlencode('offline_access files.readwrite')
166
+ . '&response_type=code'
167
+ . '&redirect_uri=' . urlencode('https://auth.wpvivid.com/onedrive')
168
+ . '&state=' . urlencode(admin_url() . 'admin.php?page=WPvivid' . '&action=wpvivid_one_drive_update_finish_auth&name=' . $_GET['name'] . '&id=' . $_GET['id'])
169
+ . '&display=popup'
170
+ . '&locale=en';
171
+ header('Location: ' . esc_url_raw($url));
172
+ }
173
+ catch (Exception $e){
174
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
175
+ }
176
  }
177
  else if($_GET['action']=='wpvivid_one_drive_update_finish_auth')
178
  {
179
+ try {
180
+ if (isset($_GET['auth_error'])) {
181
+ $error = urldecode($_GET['auth_error']);
182
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive_update&result=error&resp_msg=' . $error);
183
 
184
+ return;
185
+ }
186
 
187
+ global $wpvivid_pulgin;
188
 
189
+ $remote_options['type'] = WPVIVID_REMOTE_ONEDRIVE;
190
+ $token = $_GET['token'];
191
+ $token = stripslashes($token);
192
+ $remote_options['token'] = json_decode($token, 1);
193
+ $remote_options['token']['expires'] = time() + $remote_options['token']['expires_in'];
194
+ //
195
+ $remote_options['name'] = $_GET['name'];
196
+ $remote_options['path'] = WPVIVID_ONEDRIVE_DEFAULT_FOLDER;
197
+ $ret = $wpvivid_pulgin->remote_collection->update_remote($_GET['id'], $remote_options);
198
 
199
+ if ($ret['result'] == 'success') {
200
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive_update&result=success');
201
+ return;
202
+ } else {
203
+ header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive_update&result=error&resp_msg=' . $ret['error']);
204
+ return;
205
+ }
206
  }
207
+ catch (Exception $e){
208
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
 
 
209
  }
210
  }
211
  else if($_GET['action']=='wpvivid_one_drive_update')
212
  {
213
+ try {
214
+ if (isset($_GET['result'])) {
215
+ if ($_GET['result'] == 'success') {
216
+ add_action('show_notice', array($this, 'wpvivid_show_notice_edit_onedrive_success'));
217
+ } else if ($_GET['result'] == 'error') {
218
+ add_action('show_notice', array($this, 'wpvivid_show_notice_edit_onedrive_error'));
219
+ }
 
 
220
  }
221
  }
222
+ catch (Exception $e){
223
+ _e('<div class="notice notice-error"><p>'.$e->getMessage().'</p></div>');
224
+ }
225
  }
226
  }
227
  }
includes/customclass/class-wpvivid-send-to-site.php ADDED
@@ -0,0 +1,752 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if (!defined('WPVIVID_PLUGIN_DIR'))
4
+ {
5
+ die;
6
+ }
7
+
8
+ define('WPVIVID_REMOTE_SEND_TO_SITE','send_to_site');
9
+ require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-remote.php';
10
+
11
+ define('WPVIVID_SEND_TO_SITE_UPLOAD_SIZE',1024*1024*2);
12
+
13
+ class WPvivid_Send_to_site extends WPvivid_Remote
14
+ {
15
+ public $options;
16
+
17
+ public function __construct($options=array())
18
+ {
19
+ if(empty($options))
20
+ {
21
+ if(!defined('WPVIVID_INIT_SEND_TO_SITE'))
22
+ {
23
+ add_action('wp_ajax_wpvivid_send_to_site_connect',array( $this,'send_to_site_connect'));
24
+ add_action('wp_ajax_nopriv_wpvivid_send_to_site_finish',array( $this,'send_to_site_finish'));
25
+ add_action('wp_ajax_wpvivid_send_to_site_finish',array( $this,'send_to_site_finish'));
26
+ add_action('wp_ajax_nopriv_wpvivid_send_to_site_connect',array( $this,'send_to_site_connect'));
27
+ add_action('wp_ajax_nopriv_wpvivid_send_to_site',array( $this,'send_to_site'));
28
+ add_action('wp_ajax_wpvivid_send_to_site',array( $this,'send_to_site'));
29
+ add_action('wp_ajax_nopriv_wpvivid_send_to_site_file_status',array( $this,'send_to_site_file_status'));
30
+ add_action('wp_ajax_wpvivid_send_to_site_file_status',array( $this,'send_to_site_file_status'));
31
+ //add_filter('wpvivid_remote_register', array($this, 'init_remotes'),11);
32
+
33
+ define('WPVIVID_INIT_SEND_TO_SITE',1);
34
+ }
35
+ }
36
+ else
37
+ {
38
+ $this->options=$options;
39
+ }
40
+ }
41
+
42
+ public function init_remotes($remote_collection)
43
+ {
44
+ $remote_collection[WPVIVID_REMOTE_SEND_TO_SITE] = 'WPvivid_Send_to_site';
45
+ return $remote_collection;
46
+ }
47
+
48
+ public function test_connect()
49
+ {
50
+ return array('result' => WPVIVID_SUCCESS,'test'=>$this->options['url']);
51
+ }
52
+
53
+ public function upload($task_id, $files, $callback = '')
54
+ {
55
+ include_once WPVIVID_PLUGIN_DIR . '/addons/class-wpvivid-crypt.php';
56
+
57
+ global $wpvivid_pulgin;
58
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Connect site ','notice');
59
+ $ret=$this->connect_site($task_id);
60
+ if($ret['result']==WPVIVID_FAILED)
61
+ {
62
+ if($ret['error']=='The uploading backup already exists in Backups list.')
63
+ {
64
+ return array('result' =>WPVIVID_SUCCESS);
65
+ }
66
+ else
67
+ {
68
+ return $ret;
69
+ }
70
+ }
71
+
72
+ $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE);
73
+ if(empty($upload_job))
74
+ {
75
+ $job_data=array();
76
+ foreach ($files as $file)
77
+ {
78
+ $file_data['size']=filesize($file);
79
+ $file_data['uploaded']=0;
80
+ $job_data[basename($file)]=$file_data;
81
+ }
82
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,'0','Start uploading',$job_data);
83
+ }
84
+
85
+ foreach ($files as $file)
86
+ {
87
+ if(array_key_exists(basename($file),$upload_job['job_data']))
88
+ {
89
+ if($upload_job['job_data'][basename($file)]['uploaded']==1)
90
+ continue;
91
+ }
92
+
93
+ $this -> last_time = time();
94
+ $this -> last_size = 0;
95
+
96
+ if(!file_exists($file))
97
+ return array('result' =>WPVIVID_FAILED,'error' =>$file.' not found. The file might has been moved, renamed or deleted. Please reload the list and verify the file exists.');
98
+ $result=$this->_upload($task_id, $file,$callback);
99
+ if($result['result'] !==WPVIVID_SUCCESS)
100
+ {
101
+ return $result;
102
+ }
103
+ }
104
+ $this->upload_finish($task_id);
105
+ return array('result' =>WPVIVID_SUCCESS);
106
+ }
107
+
108
+ public function _upload($task_id, $file,$callback)
109
+ {
110
+ $this -> current_file_size = filesize($file);
111
+ $this -> current_file_name = basename($file);
112
+
113
+ $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE);
114
+
115
+ global $wpvivid_pulgin;
116
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
117
+
118
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,'0','Start uploading '.basename($file).'.',$upload_job['job_data']);
119
+
120
+ $file_size=filesize($file);
121
+ $md5=md5_file($file);
122
+ $handle=fopen($file,'rb');
123
+
124
+ $ret=$this->get_file_status($task_id,basename($file),$file_size,$md5);
125
+
126
+ $wpvivid_pulgin->wpvivid_log->WriteLog(json_encode($ret),'notice');
127
+
128
+ if($ret['result']==WPVIVID_SUCCESS)
129
+ {
130
+ if($ret['file_status']['status']=='finished')
131
+ {
132
+ $wpvivid_pulgin->wpvivid_log->WriteLog('upload finished','notice');
133
+ fclose($handle);
134
+ $upload_job['job_data'][basename($file)]['uploaded']=1;
135
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,'0','Uploading '.basename($file).' completed.',$upload_job['job_data']);
136
+ return array('result' =>WPVIVID_SUCCESS);
137
+ }
138
+ else if($ret['file_status']['status']=='continue')
139
+ {
140
+ $offset=$ret['file_status']['offset'];
141
+ }
142
+ else
143
+ {
144
+ $offset=0;
145
+ }
146
+ }
147
+ else
148
+ {
149
+ return $ret;
150
+ }
151
+
152
+ $retry_count=0;
153
+ while (!feof($handle))
154
+ {
155
+ $ret=$this->send_chunk($task_id,$handle,basename($file),$offset,WPVIVID_SEND_TO_SITE_UPLOAD_SIZE,$file_size,$md5);
156
+ if($ret['result']==WPVIVID_SUCCESS)
157
+ {
158
+ $status = WPvivid_taskmanager::get_backup_task_status($task_id);
159
+ $status['resume_count']=0;
160
+ WPvivid_taskmanager::update_backup_task_status($task_id, false, 'running', false, $status['resume_count']);
161
+ if((time() - $this -> last_time) >3)
162
+ {
163
+ if(is_callable($callback))
164
+ {
165
+ call_user_func_array($callback,array($offset,$this -> current_file_name,
166
+ $this->current_file_size,$this -> last_time,$this -> last_size));
167
+ }
168
+ $this -> last_size = $offset;
169
+ $this -> last_time = time();
170
+ }
171
+
172
+ if($ret['op']=='continue')
173
+ {
174
+ continue;
175
+ }
176
+ else
177
+ {
178
+ break;
179
+ }
180
+ }
181
+ else
182
+ {
183
+ if($retry_count>3)
184
+ {
185
+ return $ret;
186
+ }
187
+ else
188
+ {
189
+ if(isset($ret['http_code']))
190
+ {
191
+ if($ret['http_code']==413)
192
+ {
193
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Upload chunk too Large:'.size_format($offset),'warning');
194
+ }
195
+ else
196
+ {
197
+ $wpvivid_pulgin->wpvivid_log->WriteLog('upload file error offset:'.size_format($offset).' http error:'.$ret['http_code'],'warning');
198
+ }
199
+ }
200
+ else
201
+ {
202
+ $wpvivid_pulgin->wpvivid_log->WriteLog('upload file error offset:'.size_format($offset).' error:'.$ret['error'],'warning');
203
+ }
204
+ $retry_count++;
205
+ }
206
+ }
207
+ }
208
+ $wpvivid_pulgin->wpvivid_log->WriteLog('upload finished','notice');
209
+ fclose($handle);
210
+ $upload_job['job_data'][basename($file)]['uploaded']=1;
211
+ WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,'0','Uploading '.basename($file).' completed.',$upload_job['job_data']);
212
+ return array('result' =>WPVIVID_SUCCESS);
213
+ }
214
+
215
+ public function connect_site($task_id)
216
+ {
217
+ $json=array();
218
+
219
+ $json['backup_id']=$task_id;
220
+ $json=json_encode($json);
221
+ $crypt=new WPvivid_crypt(base64_decode($this->options['token']));
222
+ $data=$crypt->encrypt_message($json);
223
+
224
+ $data=base64_encode($data);
225
+
226
+ $args['body']=array('data'=>$data,'action'=>'wpvivid_send_to_site_connect');
227
+ $args['timeout']=30;
228
+ $response=wp_remote_post($this->options['url'],$args);
229
+
230
+ if ( is_wp_error( $response ) )
231
+ {
232
+ $ret['result']=WPVIVID_FAILED;
233
+ $ret['error']= $response->get_error_message();
234
+ }
235
+ else
236
+ {
237
+ if($response['response']['code']==200)
238
+ {
239
+ global $wpvivid_pulgin;
240
+
241
+ $res=json_decode($response['body'],1);
242
+ if($res!=null)
243
+ {
244
+ if($res['result']==WPVIVID_SUCCESS)
245
+ {
246
+ $ret['result']=WPVIVID_SUCCESS;
247
+ }
248
+ else
249
+ {
250
+ $ret['result']=WPVIVID_FAILED;
251
+ $ret['error']= $res['error'];
252
+ }
253
+ }
254
+ else
255
+ {
256
+ $ret['result']=WPVIVID_FAILED;
257
+ $ret['error']= 'Bad request. '.$response['body'];
258
+ }
259
+ }
260
+ else
261
+ {
262
+ $ret['result']=WPVIVID_FAILED;
263
+ $ret['error']= 'Upload error '.$response['response']['code'].' '.$response['body'];
264
+ }
265
+ }
266
+
267
+ return $ret;
268
+ }
269
+
270
+ public function send_chunk($task_id,$file_handle,$file_name,&$offset,$size,$file_size,$md5)
271
+ {
272
+ $upload_size=min($size,$file_size-$offset);
273
+
274
+ if ($offset)
275
+ fseek($file_handle, $offset);
276
+
277
+ $data=fread($file_handle,$upload_size);
278
+
279
+ if($data===false)
280
+ {
281
+ $ret['result']=WPVIVID_FAILED;
282
+ $ret['error']='Read file error at:'.$offset;
283
+ return $ret;
284
+ }
285
+
286
+ $json['backup_id']=$task_id;
287
+ $json['name']=$file_name;
288
+ $json['offset']=$offset;
289
+ $json['size']=$upload_size;
290
+ $json['file_size']=$file_size;
291
+ $json['md5']=$md5;
292
+ $json['data']=base64_encode($data);
293
+ $json=json_encode($json);
294
+
295
+ $crypt=new WPvivid_crypt(base64_decode($this->options['token']));
296
+ $data=$crypt->encrypt_message($json);
297
+
298
+ $data=base64_encode($data);
299
+
300
+ $args['body']=array('data'=>$data,'action'=>'wpvivid_send_to_site');
301
+ $args['timeout']=30;
302
+
303
+ global $wpvivid_pulgin;
304
+ $wpvivid_pulgin->wpvivid_log->WriteLog('send chunk '.basename($file_name).' offset '.$offset,'notice');
305
+
306
+ $response=wp_remote_post($this->options['url'],$args);
307
+
308
+ $wpvivid_pulgin->wpvivid_log->WriteLog('finished send chunk','notice');
309
+
310
+ if ( is_wp_error( $response ) )
311
+ {
312
+ $ret['result']=WPVIVID_FAILED;
313
+ $ret['error']= $response->get_error_message();
314
+ }
315
+ else
316
+ {
317
+ if($response['response']['code']==200)
318
+ {
319
+ $offset=$offset+$upload_size;
320
+ $ret['result']=WPVIVID_SUCCESS;
321
+ $res=json_decode($response['body'],1);
322
+ $ret['op']=$res['op'];
323
+ }
324
+ else
325
+ {
326
+ $ret['result']=WPVIVID_FAILED;
327
+ $ret['http_code']=$response['response']['code'];
328
+ $ret['error']= $response['body'];
329
+ }
330
+ }
331
+ return $ret;
332
+ }
333
+
334
+ public function upload_finish($task_id)
335
+ {
336
+ $task=WPvivid_taskmanager::get_task($task_id);
337
+ $json=array();
338
+
339
+ $json['backup']=$task['options']['backup'];
340
+ $json['backup_id']=$task_id;
341
+ $json=json_encode($json);
342
+
343
+ $crypt=new WPvivid_crypt(base64_decode($this->options['token']));
344
+ $data=$crypt->encrypt_message($json);
345
+
346
+ $data=base64_encode($data);
347
+
348
+ $args['body']=array('data'=>$data,'action'=>'wpvivid_send_to_site_finish');
349
+ $args['timeout']=30;
350
+ $response=wp_remote_post($this->options['url'],$args);
351
+
352
+ if ( is_wp_error( $response ) )
353
+ {
354
+ $ret['result']=WPVIVID_FAILED;
355
+ $ret['error']= $response->get_error_message();
356
+ }
357
+ else
358
+ {
359
+ if($response['response']['code']==200)
360
+ {
361
+ $ret['result']=WPVIVID_SUCCESS;
362
+ }
363
+ else
364
+ {
365
+ $ret['result']=WPVIVID_FAILED;
366
+ $ret['error']= 'Upload error '.$response['response']['code'].' '.$response['body'];
367
+ }
368
+ }
369
+
370
+ return $ret;
371
+ }
372
+
373
+ public function send_to_site_connect()
374
+ {
375
+ include_once WPVIVID_PLUGIN_DIR . '/addons/class-wpvivid-crypt.php';
376
+ if(isset($_POST['data']))
377
+ {
378
+ $default=array();
379
+ $option=get_option('wpvivid_api_token',$default);
380
+ if(empty($option))
381
+ {
382
+ die();
383
+ }
384
+ if($option['expires'] !=0 && $option['expires']<time())
385
+ {
386
+ die();
387
+ }
388
+
389
+ $crypt=new WPvivid_crypt(base64_decode($option['private_key']));
390
+ $body=base64_decode($_POST['data']);
391
+ $data=$crypt->decrypt_message($body);
392
+ if (!is_string($data))
393
+ {
394
+ $ret['result']=WPVIVID_FAILED;
395
+ $ret['error']='The key is invalid.';
396
+ echo json_encode($ret);
397
+ die();
398
+ }
399
+
400
+ $params=json_decode($data,1);
401
+ if(is_null($params))
402
+ {
403
+ $ret['result']=WPVIVID_FAILED;
404
+ $ret['error']='The key is invalid.';
405
+ echo json_encode($ret);
406
+ die();
407
+ }
408
+
409
+ if(isset($params['backup_id']))
410
+ {
411
+ if(WPvivid_Backuplist::get_backuplist_by_key($params['backup_id'])!==false)
412
+ {
413
+ $ret['result']=WPVIVID_FAILED;
414
+ $ret['error']='The uploading backup already exists in Backups list.';
415
+ echo json_encode($ret);
416
+ }
417
+ else
418
+ {
419
+ global $wpvivid_pulgin;
420
+ $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
421
+ if(!file_exists($wpvivid_pulgin->wpvivid_log->GetSaveLogFolder().$params['backup_id'].'_backup_log.txt'))
422
+ {
423
+ $wpvivid_pulgin->wpvivid_log->CreateLogFile($params['backup_id'].'_backup','no_folder','transfer');
424
+ $wpvivid_pulgin->wpvivid_log->WriteLogHander();
425
+ }
426
+ else
427
+ {
428
+ $wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'].'_backup','no_folder');
429
+ }
430
+
431
+
432
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Connect site success','notice');
433
+ $ret['result']=WPVIVID_SUCCESS;
434
+ echo json_encode($ret);
435
+ }
436
+ }
437
+ else
438
+ {
439
+ $ret['result']=WPVIVID_SUCCESS;
440
+ echo json_encode($ret);
441
+ }
442
+ }
443
+ die();
444
+ }
445
+
446
+ public function send_to_site()
447
+ {
448
+ include_once WPVIVID_PLUGIN_DIR . '/addons/class-wpvivid-crypt.php';
449
+ if(isset($_POST['data']))
450
+ {
451
+ global $wpvivid_pulgin;
452
+ $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
453
+
454
+ $default=array();
455
+ $option=get_option('wpvivid_api_token',$default);
456
+ if(empty($option))
457
+ {
458
+ die();
459
+ }
460
+ if($option['expires'] !=0 && $option['expires']<time())
461
+ {
462
+ die();
463
+ }
464
+ $crypt=new WPvivid_crypt(base64_decode($option['private_key']));
465
+ $body=base64_decode($_POST['data']);
466
+ $data=$crypt->decrypt_message($body);
467
+ if (!is_string($data))
468
+ {
469
+ $ret['result']=WPVIVID_FAILED;
470
+ $ret['error']='The key is invalid.';
471
+ echo json_encode($ret);
472
+ die();
473
+ }
474
+
475
+ $params=json_decode($data,1);
476
+ if(is_null($params))
477
+ {
478
+ $ret['result']=WPVIVID_FAILED;
479
+ $ret['error']='The key is invalid.';
480
+ echo json_encode($ret);
481
+ die();
482
+ }
483
+
484
+ $wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'].'_backup','no_folder','backup');
485
+
486
+ $dir=WPvivid_Setting::get_backupdir();
487
+
488
+ $file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.str_replace('wpvivid','wpvivid_temp',$params['name']);
489
+
490
+ if(!file_exists($file_path))
491
+ {
492
+ $handle=fopen($file_path,'w');
493
+ fclose($handle);
494
+ }
495
+
496
+ $handle=fopen($file_path,'rb+');
497
+ $offset=$params['offset'];
498
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Write file:'.$file_path.' offset:'.size_format($offset),'notice');
499
+ if($offset)
500
+ {
501
+ if(fseek($handle, $offset)===-1)
502
+ {
503
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Seek file offset failed:'.size_format($offset),'notice');
504
+ }
505
+ }
506
+
507
+ if (fwrite($handle,base64_decode($params['data'])) === FALSE)
508
+ {
509
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Write file :'.$file_path.' failed size:'.filesize($file_path),'notice');
510
+ }
511
+ else
512
+ {
513
+ $wpvivid_pulgin->wpvivid_log->WriteLog('Write file:'.$file_path.' success size:'.filesize($file_path),'notice');
514
+ }
515
+
516
+ fclose($handle);
517
+
518
+
519
+ if(filesize($file_path)>=$params['file_size'])
520
+ {
521
+ if (md5_file($file_path) == $params['md5'])
522
+ {
523
+ $wpvivid_pulgin->wpvivid_log->WriteLog('rename temp file:'.$file_path.' to new name:'.WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name'],'notice');
524
+ rename($file_path,WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name']);
525
+
526
+ $ret['result']=WPVIVID_SUCCESS;
527
+ $ret['op']='finished';
528
+ } else {
529
+ $wpvivid_pulgin->wpvivid_log->WriteLog('file md5 not match','notice');
530
+ $ret['result']=WPVIVID_FAILED;
531
+ $ret['error']='File md5 is not matched.';
532
+ }
533
+ }
534
+ else
535
+ {
536
+ $wpvivid_pulgin->wpvivid_log->WriteLog('continue size:'.filesize($file_path).' size1:'.$params['file_size'],'notice');
537
+ $ret['result']=WPVIVID_SUCCESS;
538
+ $ret['op']='continue';
539
+ //
540
+ }
541
+
542
+ echo json_encode($ret);
543
+ }
544
+ die();
545
+ }
546
+
547
+ public function send_to_site_finish()
548
+ {
549
+ include_once WPVIVID_PLUGIN_DIR . '/addons/class-wpvivid-crypt.php';
550
+ if(isset($_POST['data']))
551
+ {
552
+ $default=array();
553
+ $option=get_option('wpvivid_api_token',$default);
554
+ if(empty($option))
555
+ {
556
+ die();
557
+ }
558
+ if($option['expires'] !=0 && $option['expires']<time())
559
+ {
560
+ die();
561
+ }
562
+
563
+ $crypt=new WPvivid_crypt(base64_decode($option['private_key']));
564
+ $body=base64_decode($_POST['data']);
565
+ $data=$crypt->decrypt_message($body);
566
+ if (!is_string($data))
567
+ {
568
+ $ret['result']=WPVIVID_FAILED;
569
+ $ret['error']='The key is invalid.';
570
+ echo json_encode($ret);
571
+ die();
572
+ }
573
+
574
+ $params=json_decode($data,1);
575
+ if(is_null($params))
576
+ {
577
+ $ret['result']=WPVIVID_FAILED;
578
+ $ret['error']='The key is invalid.';
579
+ echo json_encode($ret);
580
+ die();
581
+ }
582
+
583
+ global $wpvivid_pulgin;
584
+ $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
585
+ $wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'].'_backup','no_folder','backup');
586
+ $wpvivid_pulgin->wpvivid_log->WriteLog('upload finished','notice');
587
+
588
+ if(isset($params['backup'])&&isset($params['backup_id']))
589
+ {
590
+ $params['backup']['type']='Migration';
591
+ $list = WPvivid_Setting::get_option('wpvivid_backup_list');
592
+ $list[$params['backup_id']]=$params['backup'];
593
+ $list[$params['backup_id']]['log']=$wpvivid_pulgin->wpvivid_log->log_file;
594
+ WPvivid_Setting::update_option('wpvivid_backup_list',$list);
595
+ }
596
+
597
+ $ret['result']=WPVIVID_SUCCESS;
598
+ echo json_encode($ret);
599
+ }
600
+ die();
601
+ }
602
+
603
+ public function cleanup($files)
604
+ {
605
+ return array('result' => WPVIVID_SUCCESS);
606
+ }
607
+
608
+ public function download($file, $local_path, $callback = '')
609
+ {
610
+ return array('result' => WPVIVID_SUCCESS);
611
+ }
612
+
613
+ public function get_file_status($task_id,$file,$file_size,$md5)
614
+ {
615
+ $json=array();
616
+
617
+ $json['backup_id']=$task_id;
618
+ $json['name']=$file;
619
+ $json['file_size']=$file_size;
620
+ $json['md5']=$md5;
621
+ $json=json_encode($json);
622
+ $crypt=new WPvivid_crypt(base64_decode($this->options['token']));
623
+ $data=$crypt->encrypt_message($json);
624
+
625
+ $data=base64_encode($data);
626
+
627
+ $args['body']=array('data'=>$data,'action'=>'wpvivid_send_to_site_file_status');
628
+ $args['timeout']=30;
629
+ $response=wp_remote_post($this->options['url'],$args);
630
+
631
+ if ( is_wp_error( $response ) )
632
+ {
633
+ $ret['result']=WPVIVID_FAILED;
634
+ $ret['error']= $response->get_error_message();
635
+ }
636
+ else
637
+ {
638
+ if($response['response']['code']==200)
639
+ {
640
+ global $wpvivid_pulgin;
641
+
642
+ $res=json_decode($response['body'],1);
643
+ if($res!=null)
644
+ {
645
+ if($res['result']==WPVIVID_SUCCESS)
646
+ {
647
+ $ret['result']=WPVIVID_SUCCESS;
648
+ $ret['file_status']=$res['file_status'];
649
+ }
650
+ else
651
+ {
652
+ $ret['result']=WPVIVID_FAILED;
653
+ $ret['error']= $res['error'];
654
+ }
655
+ }
656
+ else
657
+ {
658
+ $ret['result']=WPVIVID_FAILED;
659
+ $ret['error']= 'Bad request. '.$response['body'];
660
+ }
661
+ }
662
+ else
663
+ {
664
+ $ret['result']=WPVIVID_FAILED;
665
+ $ret['error']= 'Upload error '.$response['response']['code'].' '.$response['body'];
666
+ }
667
+ }
668
+
669
+ return $ret;
670
+ }
671
+
672
+ public function send_to_site_file_status()
673
+ {
674
+ include_once WPVIVID_PLUGIN_DIR . '/addons/class-wpvivid-crypt.php';
675
+ if(isset($_POST['data']))
676
+ {
677
+ $default=array();
678
+ $option=get_option('wpvivid_api_token',$default);
679
+ if(empty($option))
680
+ {
681
+ die();
682
+ }
683
+ if($option['expires'] !=0 && $option['expires']<time())
684
+ {
685
+ die();
686
+ }
687
+
688
+ $crypt=new WPvivid_crypt(base64_decode($option['private_key']));
689
+ $body=base64_decode($_POST['data']);
690
+ $data=$crypt->decrypt_message($body);
691
+ if (!is_string($data))
692
+ {
693
+ $ret['result']=WPVIVID_FAILED;
694
+ $ret['error']='The key is invalid.';
695
+ echo json_encode($ret);
696
+ die();
697
+ }
698
+
699
+ $params=json_decode($data,1);
700
+ if(is_null($params))
701
+ {
702
+ $ret['result']=WPVIVID_FAILED;
703
+ $ret['error']='The key is invalid.';
704
+ echo json_encode($ret);
705
+ die();
706
+ }
707
+
708
+ $dir=WPvivid_Setting::get_backupdir();
709
+ $file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.str_replace('wpvivid','wpvivid_temp',$params['name']);
710
+
711
+ $rename=true;
712
+
713
+ if(!file_exists($file_path))
714
+ {
715
+ $file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name'];
716
+ $rename=false;
717
+ }
718
+
719
+ $offset=filesize($file_path);
720
+
721
+ if(!$offset)
722
+ {
723
+ $ret['result']=WPVIVID_SUCCESS;
724
+ $ret['file_status']['status']='start';
725
+ echo json_encode($ret);
726
+ die();
727
+ }
728
+
729
+ if(filesize($file_path)>=$params['file_size'])
730
+ {
731
+ if (md5_file($file_path) == $params['md5'])
732
+ {
733
+ if($rename)
734
+ rename($file_path,WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name']);
735
+ $ret['result']=WPVIVID_SUCCESS;
736
+ $ret['file_status']['status']='finished';
737
+ } else {
738
+ $ret['result']=WPVIVID_FAILED;
739
+ $ret['error']='File md5 is not matched.';
740
+ }
741
+ }
742
+ else
743
+ {
744
+ $ret['result']=WPVIVID_SUCCESS;
745
+ $ret['file_status']['status']='continue';
746
+ $ret['file_status']['offset']=filesize($file_path);
747
+ }
748
+ echo json_encode($ret);
749
+ }
750
+ die();
751
+ }
752
+ }
readme.txt CHANGED
@@ -1,37 +1,51 @@
1
- === Backup WordPress Site by WPvivid ===
2
  Contributors: wpvivid
3
- Tags: backup, cloud backup, automatic backup, restore, database backup, wordpress backup, backups, custom backups, s3, Dropbox, OneDrive, Google Drive, FTP, SFTP
4
  Requires at least: 4.5
5
  Tested up to: 5.1
6
  Requires PHP: 5.3
7
- Stable tag: 0.9.13
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
11
- Automatically back up WordPress to Cloud Storage (Dropbox, Amazon S3, Microsoft OneDrive, Google Drive etc), one-click restore. All free.
12
 
13
  == Description ==
14
- Automatically back up WordPress to Cloud Storage (Dropbox, Amazon S3, Microsoft OneDrive, Google Drive etc), one-click restore. All free.
15
 
16
  == Core Features ==
17
 
18
- = 1. Automatic Backup =
 
 
 
 
 
 
 
 
 
19
  Setup and forget, the plugin will do the rest automatically backing up your website.
20
- = 2. One-Click Restore =
21
  Restore your WordPress site from a backup with a single click.
22
- = 3. Easy Site Migration =
23
- Coming soon...
24
 
25
- == Free Cloud Backup ==
26
 
27
  Dropbox, Google Drive, Microsoft OneDrive, Amazon S3, DigitalOcean Spaces, SFTP, FTP and more are coming soon.
28
 
 
 
 
 
 
 
29
  == Features Spotlight ==
 
30
  * Manual Backup
31
  * Filter Large Files
32
  * Large Database Support
33
  * Optimized for any host
34
- * Backup Limits
35
  * Backup Splitting
36
  * No Limit of Backup Size
37
  * Backup to Localhost
@@ -42,7 +56,6 @@ Dropbox, Google Drive, Microsoft OneDrive, Amazon S3, DigitalOcean Spaces, SFTP,
42
  * Instant Email Report
43
  * Log Files
44
  * Responsive Design
45
- * WordPress MU Support
46
 
47
  == Other Amazing Features ==
48
  * Rename local backup directory
@@ -51,10 +64,10 @@ Dropbox, Google Drive, Microsoft OneDrive, Amazon S3, DigitalOcean Spaces, SFTP,
51
  * More basic features will be continuously added
52
 
53
  == Minimum Requirements ==
 
54
  * PHP version 5.3
55
  * MySQL version 4.1
56
  * WordPress 4.5
57
- * Character Encoding UTF-8
58
 
59
  == Support ==
60
  We offer free support in 3 channels:
@@ -74,18 +87,18 @@ We offer free support in 3 channels:
74
  2.Click Delete.
75
 
76
  == Privacy Policy and GDPR Compliance ==
77
- Backup WordPress Site by WPvivid is created and operated with full respect and protection of users personal information, and is in full compliance with General Data Protection Regulation(GDPR). Check out the following content to know the details:
78
- = What personal data can Backup WordPress Site by WPvivid access and how is the data processed? =
79
  The plugin currently only has a free version and is available to download from WordPress plugin repository. Thus, all the data related to the updates of the versions as well as the support forum for the plugin on WordPress.org is held by WordPress.org.
80
- In addition, the implementations of all backups and restores of your site happen completely on your website server, there are no data come across any of our servers in the whole process.
81
  The only personal data currently we can access are the contact data when you contact us by email, which may include your name, email address and other contact details. The data will only be used for the purposes of handling and resolving your enquiry.
82
- = How does Backup WordPress Site by WPvivid help users create a GDPR compliant backup? =
83
  In order to help users create a GDPR compliant backup, the plugin comes with multiple features including selection for backup content, backup and restore logs, and email report. Moreover, as the plugin itself does not collect any personal data, you do not need to sign a Data Processing Agreement (DPA) with us.
84
- However, if you upload your backups to cloud storage with Backup WordPress Site by WPvivid, the personal data is transferred to that storage provider. You'll need to sign a Data Processing Agreement with that provider.
85
  Check out the [privacy policy](https://wpvivid.com/privacy-policy) involving the use of Google Drive, Dropbox and Microsoft OneDrive.
86
 
87
  == License ==
88
- Backup WordPress Site by WPvivid is licensed under GPL version 3 or later.
89
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details:[https://www.gnu.org/licenses/gpl-3.0.en.html](https://www.gnu.org/licenses/gpl-3.0.en.html).
90
 
91
  == Screenshots ==
@@ -95,8 +108,11 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY
95
  4. Configure remote storage
96
 
97
  == Frequently Asked Questions ==
98
- = What does Backup WordPress Site by WPvivid do? =
99
- It enables you to perform manual and scheduled backups of your WordPress site, back up to cloud storage and restore backups directly from the site’s admin dashboard.
 
 
 
100
  = How many cloud options does it support? Are they free to access? =
101
  Out of the box we support Dropbox, Google Drive, Amazon S3, Microsoft OneDrive, DigitalOcean Spaces, we also support FTP, SFTP methods which you can use on any other remote storage provider supporting these methods. We are working hard to add more soon.
102
 
@@ -105,8 +121,6 @@ Yes, all the cloud access is free.
105
  Yes, absolutely. With no limits, no strings attached.
106
  = Will there be updates, will they be free and how can I update to the latest version? =
107
  Yes, we are dedicated to creating a secure and robust solution and will regularly update the plugin. These will be available totally free and can be easily applied through your WP admin area once they are available.
108
- = Does the plugin also migrate my site? =
109
- Unfortunately NO. But we are tirelessly working to add this feature soon. You will be notified when it is released.
110
  = Do you provide support for the free version? Where? =
111
  Yes, absolutely. Whenever you need it, help can be found from the plugin [support forum](https://wordpress.org/support/plugin/wpvivid-backuprestore/) on WordPress.org, by [email](https://wpvivid.com/contact-us), on [Twitter](https://twitter.com/WPvividcom).
112
  = Will the plugin work on my host? =
@@ -126,6 +140,9 @@ Please try to contact your web hosting provider for changing PHP memory limit, o
126
  Feel free to let us know how we can help using the [support forum](https://wordpress.org/support/plugin/wpvivid-backuprestore) for the plugin on WordPress.org or our [contact form](https://wpvivid.com/contact-us). You can also reach us with a direct message on [Twitter](https://twitter.com/WPvividcom).
127
 
128
  == Changelog ==
 
 
 
129
  = 0.9.13 =
130
  - Fixed: Sometimes could not correctly determine database privileges when backing up.
131
  = 0.9.12 =
1
+ === Transfer-Backup WordPress Site - WPvivid Backup Plugin ===
2
  Contributors: wpvivid
3
+ Tags: transfer, move, duplicate, clone, backup, migrate, restore, auto backup, cloud backup
4
  Requires at least: 4.5
5
  Tested up to: 5.1
6
  Requires PHP: 5.3
7
+ Stable tag: 0.9.14
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
11
+ Transfer site to a new domain. Off-site backup schedule, transfer backups to leading remote storage (dropbox, onedrive, google drive etc). All in one.
12
 
13
  == Description ==
14
+ Transfer a WordPress site to a new domain (especially useful for developers). Off-site backup schedules, transfer backups to leading remote storage (dropbox, onedrive, google drive etc), 1-click restore. All in one.
15
 
16
  == Core Features ==
17
 
18
+ = 1. Easy Site Transfer (New Feature) =
19
+ Transfer your WordPress site to a new domain with a single click. The plugin supports site transfer from dev environment to a new server, from dev environment to a new domain or from a live server to another.
20
+
21
+ You can also transfer a site to a subdirectory, from a.com to b.com, from a.com to a.com/directory and from a.com to b.com/directory.
22
+
23
+ You are free to choose what to transfer: the entire site, files or just the database only.
24
+ = 2. Upload Backups (New Feature) =
25
+ Upload a backup to restore or transfer.
26
+ You can transfer or restore backups created with 0.9.14 or higher version, and restore a backup created with prior versions.
27
+ = 3. Automatic Backup =
28
  Setup and forget, the plugin will do the rest automatically backing up your website.
29
+ = 4. One-Click Restore =
30
  Restore your WordPress site from a backup with a single click.
 
 
31
 
32
+ == Cloud Storage Supported ==
33
 
34
  Dropbox, Google Drive, Microsoft OneDrive, Amazon S3, DigitalOcean Spaces, SFTP, FTP and more are coming soon.
35
 
36
+ == Site Transfer Process ==
37
+ 1. Install the WPvivid Backup plugin on both the destination site and the sending site.
38
+ 2. Generate a site key on the destination site with one click.
39
+ 3. Paste the key in the sending site and save it.
40
+ 4. Transfer the site with one-click.
41
+
42
  == Features Spotlight ==
43
+ * One-Click Site Transfer
44
  * Manual Backup
45
  * Filter Large Files
46
  * Large Database Support
47
  * Optimized for any host
48
+ * Backup Retention Limits
49
  * Backup Splitting
50
  * No Limit of Backup Size
51
  * Backup to Localhost
56
  * Instant Email Report
57
  * Log Files
58
  * Responsive Design
 
59
 
60
  == Other Amazing Features ==
61
  * Rename local backup directory
64
  * More basic features will be continuously added
65
 
66
  == Minimum Requirements ==
67
+ * Character Encoding UTF-8
68
  * PHP version 5.3
69
  * MySQL version 4.1
70
  * WordPress 4.5
 
71
 
72
  == Support ==
73
  We offer free support in 3 channels:
87
  2.Click Delete.
88
 
89
  == Privacy Policy and GDPR Compliance ==
90
+ WPvivid Backup plugin is created and operated with full respect and protection of users personal information, and is in full compliance with General Data Protection Regulation(GDPR). Check out the following content to know the details:
91
+ = What personal data can WPvivid Backup plugin access and how is the data processed? =
92
  The plugin currently only has a free version and is available to download from WordPress plugin repository. Thus, all the data related to the updates of the versions as well as the support forum for the plugin on WordPress.org is held by WordPress.org.
93
+ In addition, the implementations of all transfers, backups and restores of your site happen completely on your website server, there are no data come across any of our servers in the whole process.
94
  The only personal data currently we can access are the contact data when you contact us by email, which may include your name, email address and other contact details. The data will only be used for the purposes of handling and resolving your enquiry.
95
+ = How does WPvivid Backup plugin help users create a GDPR compliant backup? =
96
  In order to help users create a GDPR compliant backup, the plugin comes with multiple features including selection for backup content, backup and restore logs, and email report. Moreover, as the plugin itself does not collect any personal data, you do not need to sign a Data Processing Agreement (DPA) with us.
97
+ However, if you upload your backups to cloud storage with Transfer-Backup WordPress Site - WPvivid Backup Plugin, the personal data is transferred to that storage provider. You'll need to sign a Data Processing Agreement with that provider.
98
  Check out the [privacy policy](https://wpvivid.com/privacy-policy) involving the use of Google Drive, Dropbox and Microsoft OneDrive.
99
 
100
  == License ==
101
+ WPvivid Backup plugin is licensed under GPL version 3 or later.
102
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details:[https://www.gnu.org/licenses/gpl-3.0.en.html](https://www.gnu.org/licenses/gpl-3.0.en.html).
103
 
104
  == Screenshots ==
108
  4. Configure remote storage
109
 
110
  == Frequently Asked Questions ==
111
+ = What does WPvivid Backup plugin do? =
112
+ As its name says, it enables you to easily transfer a WordPress site to a new domain, to perform manual and scheduled backups of your WordPress site, to back up to cloud storage and restore backups directly from the site’s admin dashboard.
113
+ = Does the plugin also transfer my site? Is it a free feature? =
114
+ Yes, we have added website transfer feature since version 0.9.14.
115
+ Yes, it's a completely free feature.
116
  = How many cloud options does it support? Are they free to access? =
117
  Out of the box we support Dropbox, Google Drive, Amazon S3, Microsoft OneDrive, DigitalOcean Spaces, we also support FTP, SFTP methods which you can use on any other remote storage provider supporting these methods. We are working hard to add more soon.
118
 
121
  Yes, absolutely. With no limits, no strings attached.
122
  = Will there be updates, will they be free and how can I update to the latest version? =
123
  Yes, we are dedicated to creating a secure and robust solution and will regularly update the plugin. These will be available totally free and can be easily applied through your WP admin area once they are available.
 
 
124
  = Do you provide support for the free version? Where? =
125
  Yes, absolutely. Whenever you need it, help can be found from the plugin [support forum](https://wordpress.org/support/plugin/wpvivid-backuprestore/) on WordPress.org, by [email](https://wpvivid.com/contact-us), on [Twitter](https://twitter.com/WPvividcom).
126
  = Will the plugin work on my host? =
140
  Feel free to let us know how we can help using the [support forum](https://wordpress.org/support/plugin/wpvivid-backuprestore) for the plugin on WordPress.org or our [contact form](https://wpvivid.com/contact-us). You can also reach us with a direct message on [Twitter](https://twitter.com/WPvividcom).
141
 
142
  == Changelog ==
143
+ = 0.9.14 =
144
+ - Added free website transfer feature. We highly recommend all our users to update.
145
+ - Added backup upload feature. Now you can upload a backup to restore or transfer.
146
  = 0.9.13 =
147
  - Fixed: Sometimes could not correctly determine database privileges when backing up.
148
  = 0.9.12 =
uninstall.php CHANGED
@@ -19,7 +19,7 @@ delete_option('wpvivid_last_msg');
19
  delete_option('wpvivid_download_cache');
20
  delete_option('wpvivid_download_task');
21
  delete_option('wpvivid_user_history');
22
-
23
  define('WPVIVID_MAIN_SCHEDULE_EVENT','wpvivid_main_schedule_event');
24
 
25
  if(wp_get_schedule(WPVIVID_MAIN_SCHEDULE_EVENT))
19
  delete_option('wpvivid_download_cache');
20
  delete_option('wpvivid_download_task');
21
  delete_option('wpvivid_user_history');
22
+ delete_option('wpvivid_saved_api_token');
23
  define('WPVIVID_MAIN_SCHEDULE_EVENT','wpvivid_main_schedule_event');
24
 
25
  if(wp_get_schedule(WPVIVID_MAIN_SCHEDULE_EVENT))
wpvivid-backuprestore.php CHANGED
@@ -5,9 +5,9 @@
5
  * @package wpvivid
6
  *
7
  * @wordpress-plugin
8
- * Plugin Name: Backup WordPress Site by WPvivid
9
- * Description: Automatically back up WordPress to Cloud Storage (Dropbox, Amazon S3, Microsoft OneDrive, Google Drive etc), one-click restore. All free.
10
- * Version: 0.9.13
11
  * Author: wpvivid.com
12
  * Author URI: https://wpvivid.com
13
  * License: GPL-3.0+
@@ -21,7 +21,7 @@ if ( ! defined( 'WPINC' ) ) {
21
  die;
22
  }
23
 
24
- define( 'WPVIVID_PLUGIN_VERSION', '0.9.13' );
25
  //
26
  define('WPVIVID_RESTORE_INIT','init');
27
  define('WPVIVID_RESTORE_READY','ready');
@@ -89,6 +89,7 @@ define('WPVIVID_FAILED','failed');
89
  */
90
  //when active plugin redirect plugin page.
91
 
 
92
  function wpvivid_plugin_activate()
93
  {
94
  add_option('wpvivid_do_activation_redirect', true);
5
  * @package wpvivid
6
  *
7
  * @wordpress-plugin
8
+ * Plugin Name: WPvivid Backup Plugin
9
+ * Description: Transfer site to a new domain. Off-site backup schedule, transfer backups to leading remote storage (dropbox, onedrive, google drive etc). All in one.
10
+ * Version: 0.9.14
11
  * Author: wpvivid.com
12
  * Author URI: https://wpvivid.com
13
  * License: GPL-3.0+
21
  die;
22
  }
23
 
24
+ define( 'WPVIVID_PLUGIN_VERSION', '0.9.14' );
25
  //
26
  define('WPVIVID_RESTORE_INIT','init');
27
  define('WPVIVID_RESTORE_READY','ready');
89
  */
90
  //when active plugin redirect plugin page.
91
 
92
+
93
  function wpvivid_plugin_activate()
94
  {
95
  add_option('wpvivid_do_activation_redirect', true);