Migration, Backup, Staging – WPvivid - Version 0.9.23

Version Description

  • Added an option to hide the plugin menu on the top admin bar.
  • Fixed: Always sent email notifications even the Only send an email notification when a backup fails option was selected.
  • Fixed: The plugin menu on the top admin bar is visible to all users.
  • Refined some error messages.
Download this release

Release Info

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

Code changes from version 0.9.22 to 0.9.23

Files changed (40) hide show
  1. admin/class-wpvivid-admin.php +338 -120
  2. admin/js/wpvivid-admin.js +45 -2188
  3. admin/partials/wpvivid-admin-display.php +59 -33
  4. admin/partials/wpvivid-backup-restore-page-display.php +1337 -147
  5. admin/partials/wpvivid-remote-storage-page-display.php +279 -10
  6. admin/partials/wpvivid-settings-page-display.php +238 -47
  7. includes/class-wpvivid-backup-database.php +2 -2
  8. includes/class-wpvivid-backup-uploader.php +31 -29
  9. includes/class-wpvivid-backup.php +178 -49
  10. includes/class-wpvivid-backuplist.php +132 -86
  11. includes/class-wpvivid-db-method.php +3 -3
  12. includes/class-wpvivid-downloader.php +14 -14
  13. includes/class-wpvivid-function-realize.php +6 -6
  14. includes/class-wpvivid-mail-report.php +3 -3
  15. includes/class-wpvivid-migrate.php +269 -244
  16. includes/class-wpvivid-mysqldump-wpdb.php +6 -6
  17. includes/class-wpvivid-mysqldump.php +35 -16
  18. includes/class-wpvivid-public-interface.php +27 -27
  19. includes/class-wpvivid-restore-data.php +2 -2
  20. includes/class-wpvivid-restore-database.php +106 -50
  21. includes/class-wpvivid-restore-db-method.php +3 -3
  22. includes/class-wpvivid-restore-db-pdo-mysql-method.php +19 -19
  23. includes/class-wpvivid-restore-db-wpdb-method.php +20 -20
  24. includes/class-wpvivid-restore-site.php +4 -4
  25. includes/class-wpvivid-restore.php +20 -20
  26. includes/class-wpvivid-setting.php +8 -3
  27. includes/class-wpvivid-tools.php +3 -3
  28. includes/class-wpvivid-upload.php +11 -11
  29. includes/class-wpvivid-zipclass.php +33 -15
  30. includes/class-wpvivid.php +162 -109
  31. includes/customclass/class-wpvivid-amazons3-plus.php +16 -11
  32. includes/customclass/class-wpvivid-dropbox.php +39 -35
  33. includes/customclass/class-wpvivid-ftpclass.php +22 -17
  34. includes/customclass/class-wpvivid-google-drive.php +39 -34
  35. includes/customclass/class-wpvivid-one-drive.php +48 -43
  36. includes/customclass/class-wpvivid-s3compat.php +21 -16
  37. includes/customclass/class-wpvivid-send-to-site.php +50 -43
  38. includes/customclass/class-wpvivid-sftpclass.php +22 -17
  39. readme.txt +6 -1
  40. wpvivid-backuprestore.php +6 -5
admin/class-wpvivid-admin.php CHANGED
@@ -43,6 +43,10 @@ class WPvivid_Admin {
43
  */
44
  private $version;
45
 
 
 
 
 
46
  /**
47
  * Initialize the class and set its properties.
48
  *
@@ -50,41 +54,92 @@ class WPvivid_Admin {
50
  * @param string $plugin_name The name of this plugin.
51
  * @param string $version The version of this plugin.
52
  */
53
- public function __construct($plugin_name, $version) {
54
-
55
  $this->plugin_name = $plugin_name;
56
  $this->version = $version;
57
-
58
-
59
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  }
61
  /**
62
  * Register the stylesheets for the admin area.
63
  *
64
  *
65
  */
66
- public function enqueue_styles() {
 
 
67
 
68
- /**
69
- * This function is provided for demonstration purposes only.
70
- *
71
- * An instance of this class should be passed to the run() function
72
- * defined in WPvivid_Loader as all of the hooks are defined
73
- * in that particular class.
74
- *
75
- * The WPvivid_Loader will then create the relationship
76
- * between the defined hooks and the functions defined in this
77
- * class.
78
- */
79
- if ('toplevel_page_'.$this->plugin_name == get_current_screen()->id ||
80
- 'wpvivid-backup_page_wpvivid-transfer' == get_current_screen()->id ||
81
- 'wpvivid-backup_page_wpvivid-setting' == get_current_screen()->id ||
82
- 'wpvivid-backup_page_wpvivid-schedule' == get_current_screen()->id ||
83
- 'wpvivid-backup_page_wpvivid-remote' == get_current_screen()->id ||
84
- 'wpvivid-backup_page_wpvivid-website' == get_current_screen()->id ||
85
- 'wpvivid-backup_page_wpvivid-log' == get_current_screen()->id ||
86
- 'wpvivid-backup_page_wpvivid-key' == get_current_screen()->id) {
87
- wp_enqueue_style($this->plugin_name, plugin_dir_url(__FILE__) . 'css/wpvivid-admin.css', array(), $this->version, 'all');
88
  }
89
  }
90
 
@@ -93,28 +148,13 @@ class WPvivid_Admin {
93
  *
94
  *
95
  */
96
- public function enqueue_scripts() {
 
 
97
 
98
- /**
99
- * This function is provided for demonstration purposes only.
100
- *
101
- * An instance of this class should be passed to the run() function
102
- * defined in WPvivid_Loader as all of the hooks are defined
103
- * in that particular class.
104
- *
105
- * The WPvivid_Loader will then create the relationship
106
- * between the defined hooks and the functions defined in this
107
- * class.
108
- */
109
- if ('toplevel_page_'.$this->plugin_name == get_current_screen()->id ||
110
- 'wpvivid-backup_page_wpvivid-transfer' == get_current_screen()->id ||
111
- 'wpvivid-backup_page_wpvivid-setting' == get_current_screen()->id ||
112
- 'wpvivid-backup_page_wpvivid-schedule' == get_current_screen()->id ||
113
- 'wpvivid-backup_page_wpvivid-remote' == get_current_screen()->id ||
114
- 'wpvivid-backup_page_wpvivid-website' == get_current_screen()->id ||
115
- 'wpvivid-backup_page_wpvivid-log' == get_current_screen()->id ||
116
- 'wpvivid-backup_page_wpvivid-key' == get_current_screen()->id) {
117
- wp_enqueue_script($this->plugin_name, plugin_dir_url(__FILE__) . 'js/wpvivid-admin.js', array('jquery'), $this->version, false);
118
  wp_localize_script($this->plugin_name, 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php')));
119
 
120
  wp_enqueue_script('plupload-all');
@@ -160,63 +200,30 @@ class WPvivid_Admin {
160
  }
161
  }
162
 
163
- function add_toolbar_items($wp_admin_bar){
164
- global $wpvivid_pulgin;
165
- $show_admin_bar = $wpvivid_pulgin->get_admin_bar_setting();
166
- if($show_admin_bar === true){
167
- $admin_url = admin_url();
168
- $wp_admin_bar->add_menu(array(
169
- 'id' => 'wpvivid_admin_menu',
170
- 'title' => 'WPvivid Backup'
171
- ));
172
- $wp_admin_bar->add_menu(array(
173
- 'id' => 'wpvivid_admin_menu_backup',
174
- 'parent' => 'wpvivid_admin_menu',
175
- 'title' => 'Backup & Restore',
176
- 'href' => $admin_url . 'admin.php?page=WPvivid&tab-backup'
177
- ));
178
- $wp_admin_bar->add_menu(array(
179
- 'id' => 'wpvivid_admin_menu_schedule',
180
- 'parent' => 'wpvivid_admin_menu',
181
- 'title' => 'Schedule',
182
- 'href' => $admin_url . 'admin.php?page=WPvivid&tab-schedule'
183
- ));
184
- $wp_admin_bar->add_menu(array(
185
- 'id' => 'wpvivid_admin_menu_transfer',
186
- 'parent' => 'wpvivid_admin_menu',
187
- 'title' => 'Auto-Migration',
188
- 'href' => $admin_url . 'admin.php?page=WPvivid&tab-transfer'
189
- ));
190
- $wp_admin_bar->add_menu(array(
191
- 'id' => 'wpvivid_admin_menu_addons',
192
- 'parent' => 'wpvivid_admin_menu',
193
- 'title' => 'Remote Storage',
194
- 'href' => $admin_url . 'admin.php?page=WPvivid&tab-remote-storage'
195
- ));
196
- $wp_admin_bar->add_menu(array(
197
- 'id' => 'wpvivid_admin_menu_settings',
198
- 'parent' => 'wpvivid_admin_menu',
199
- 'title' => 'Settings',
200
- 'href' => $admin_url . 'admin.php?page=WPvivid&tab-settings'
201
- ));
202
- $wp_admin_bar->add_menu(array(
203
- 'id' => 'wpvivid_admin_menu_debug',
204
- 'parent' => 'wpvivid_admin_menu',
205
- 'title' => 'Website Info',
206
- 'href' => $admin_url . 'admin.php?page=WPvivid&tab-website-info'
207
- ));
208
- $wp_admin_bar->add_menu(array(
209
- 'id' => 'wpvivid_admin_menu_logs',
210
- 'parent' => 'wpvivid_admin_menu',
211
- 'title' => 'Logs',
212
- 'href' => $admin_url . 'admin.php?page=WPvivid&tab-logs'
213
- ));
214
- $wp_admin_bar->add_menu(array(
215
- 'id' => 'wpvivid_admin_menu_key',
216
- 'parent' => 'wpvivid_admin_menu',
217
- 'title' => 'Key',
218
- 'href' => $admin_url . 'admin.php?page=WPvivid&tab-key'
219
- ));
220
  }
221
  }
222
 
@@ -265,8 +272,8 @@ class WPvivid_Admin {
265
  else if(isset($_REQUEST['tab-key'])){
266
  self::wpvivid_set_page_request('key');
267
  }
268
- global $wpvivid_pulgin;
269
- $wpvivid_pulgin->clean_cache();
270
 
271
 
272
  //
@@ -302,6 +309,39 @@ class WPvivid_Admin {
302
  $this->wpvivid_show_add_my_review();
303
  $this->wpvivid_check_extensions();
304
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  include_once('partials/wpvivid-admin-display.php');
306
  }
307
 
@@ -443,7 +483,7 @@ class WPvivid_Admin {
443
  }
444
 
445
  if(defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON){
446
- _e('<div class="notice notice-error"><p>In order to execute the scheduled backups properly, please set the DISABLE_WP_CRON constant to false.</p></div>');
447
  }
448
  }
449
 
@@ -513,9 +553,7 @@ class WPvivid_Admin {
513
  <div id="general-page" class="wrap-tab-content wpvivid_tab_general" name="tab-backup" style="width:100%;">
514
  <div class="meta-box-sortables ui-sortable">
515
  <?php
516
- echo apply_filters('wpvivid_backuppage_load_progress_module', $html_progress);
517
- echo apply_filters('wpvivid_backuppage_load_backup_module', $html_backup);
518
- echo apply_filters('wpvivid_backuppage_load_schedule_module', $html_schedule);
519
  ?>
520
  <h2 class="nav-tab-wrapper" id="wpvivid_backup_tab" style="padding-bottom:0!important;">
521
  <?php
@@ -554,6 +592,43 @@ class WPvivid_Admin {
554
  </table>
555
  </div>
556
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
  <?php
558
  }
559
 
@@ -568,14 +643,10 @@ class WPvivid_Admin {
568
  <div class="postbox storage-account-block" id="wpvivid_storage_account_block">
569
  <?php do_action('wpvivid_add_storage_page'); ?>
570
  </div>
571
- <?php
572
- $html = '';
573
- $html = apply_filters('wpvivid_storage_list', $html);
574
- echo $html;
575
- ?>
576
- <div class="storage-tab-content wpvivid_tab_storage_edit" id="page-storage_edit" style="display:none;">
577
- <div><?php do_action('wpvivid_edit_remote_page'); ?></div>
578
- </div>
579
  </div>
580
  </div>
581
  </div>
@@ -599,6 +670,43 @@ class WPvivid_Admin {
599
  </table>
600
  </div>
601
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
  <?php
603
  }
604
 
@@ -632,6 +740,8 @@ class WPvivid_Admin {
632
  </thead>
633
  <tbody class="wpvivid-websiteinfo-list" id="wpvivid_websiteinfo_list">
634
  <?php
 
 
635
  if(!empty($website_info['data'])){
636
  foreach ($website_info['data'] as $key=>$value) { ?>
637
  <?php
@@ -667,14 +777,52 @@ class WPvivid_Admin {
667
  </tbody>
668
  </table>
669
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
670
  <?php
671
  }
672
 
673
  public function wpvivid_add_page_log(){
674
- global $wpvivid_pulgin;
675
  $display_log_count=array(0=>"10",1=>"20",2=>"30",3=>"40",4=>"50");
676
  $max_log_diaplay=20;
677
- $loglist=$wpvivid_pulgin->get_log_list_ex();
678
  ?>
679
  <div id="logs-page" class="wrap-tab-content wpvivid_tab_log" name="tab-logs" style="display:none;">
680
  <div style="padding-bottom: 10px; float: right;">
@@ -723,6 +871,76 @@ class WPvivid_Admin {
723
  <input class="button-secondary log-page" id="wpvivid_next_log_page" type="submit" value="<?php esc_attr_e( ' Next page > ', 'wpvivid' ); ?>" />
724
  </div>
725
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
726
  <?php
727
  }
728
 
43
  */
44
  private $version;
45
 
46
+ private $screen_ids;
47
+
48
+ private $toolbar_menus;
49
+
50
  /**
51
  * Initialize the class and set its properties.
52
  *
54
  * @param string $plugin_name The name of this plugin.
55
  * @param string $version The version of this plugin.
56
  */
57
+ public function __construct($plugin_name, $version)
58
+ {
59
  $this->plugin_name = $plugin_name;
60
  $this->version = $version;
61
+ $this->screen_ids[]='toplevel_page_'.$this->plugin_name;
62
+ $this->screen_ids[]='wpvivid-backup_page_wpvivid-transfer';
63
+ $this->screen_ids[]='wpvivid-backup_page_wpvivid-setting';
64
+ $this->screen_ids[]='wpvivid-backup_page_wpvivid-schedule';
65
+ $this->screen_ids[]='wpvivid-backup_page_wpvivid-website';
66
+ $this->screen_ids[]='wpvivid-backup_page_wpvivid-log';
67
+ $this->screen_ids[]='wpvivid-backup_page_wpvivid-key';
68
+
69
+ $menu['id']='wpvivid_admin_menu';
70
+ $menu['title']='WPvivid Backup';
71
+ $this->toolbar_menus[$menu['id']]=$menu;
72
+
73
+ $admin_url = admin_url();
74
+
75
+ $menu['id']='wpvivid_admin_menu_backup';
76
+ $menu['parent']='wpvivid_admin_menu';
77
+ $menu['title']='Backup & Restore';
78
+ $menu['tab']='admin.php?page=WPvivid&tab-backup';
79
+ $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-backup';
80
+ $this->toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
81
+
82
+ $menu['id']='wpvivid_admin_menu_schedule';
83
+ $menu['parent']='wpvivid_admin_menu';
84
+ $menu['title']='Schedule';
85
+ $menu['tab']='admin.php?page=WPvivid&tab-schedule';
86
+ $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-schedule';
87
+ $this->toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
88
+
89
+ $menu['id']='wpvivid_admin_menu_transfer';
90
+ $menu['parent']='wpvivid_admin_menu';
91
+ $menu['title']='Auto-Migration';
92
+ $menu['tab']='admin.php?page=WPvivid&tab-transfer';
93
+ $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-transfer';
94
+ $this->toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
95
+
96
+ $menu['id']='wpvivid_admin_menu_addons';
97
+ $menu['parent']='wpvivid_admin_menu';
98
+ $menu['title']='Remote Storage';
99
+ $menu['tab']='admin.php?page=WPvivid&tab-remote-storage';
100
+ $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-remote-storage';
101
+ $this->toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
102
+
103
+ $menu['id']='wpvivid_admin_menu_settings';
104
+ $menu['parent']='wpvivid_admin_menu';
105
+ $menu['title']='Settings';
106
+ $menu['tab']= 'admin.php?page=WPvivid&tab-settings';
107
+ $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-settings';
108
+ $this->toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
109
+
110
+ $menu['id']='wpvivid_admin_menu_debug';
111
+ $menu['parent']='wpvivid_admin_menu';
112
+ $menu['title']='Website Info';
113
+ $menu['tab']= 'admin.php?page=WPvivid&tab-website-info';
114
+ $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-website-info';
115
+ $this->toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
116
+
117
+ $menu['id']='wpvivid_admin_menu_logs';
118
+ $menu['parent']='wpvivid_admin_menu';
119
+ $menu['title']='Logs';
120
+ $menu['tab']='admin.php?page=WPvivid&tab-logs';
121
+ $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-logs';
122
+ $this->toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
123
+
124
+ $menu['id']='wpvivid_admin_menu_key';
125
+ $menu['parent']='wpvivid_admin_menu';
126
+ $menu['title']='Key';
127
+ $menu['tab']= 'admin.php?page=WPvivid&tab-key';
128
+ $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-key';
129
+ $this->toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
130
  }
131
  /**
132
  * Register the stylesheets for the admin area.
133
  *
134
  *
135
  */
136
+ public function enqueue_styles()
137
+ {
138
+ $this->screen_ids=apply_filters('wpvivid_get_screen_ids',$this->screen_ids);
139
 
140
+ if(in_array(get_current_screen()->id,$this->screen_ids))
141
+ {
142
+ wp_enqueue_style($this->plugin_name, WPVIVID_PLUGIN_DIR_URL . 'css/wpvivid-admin.css', array(), $this->version, 'all');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
  }
145
 
148
  *
149
  *
150
  */
151
+ public function enqueue_scripts()
152
+ {
153
+ $this->screen_ids=apply_filters('wpvivid_get_screen_ids',$this->screen_ids);
154
 
155
+ if(in_array(get_current_screen()->id,$this->screen_ids))
156
+ {
157
+ wp_enqueue_script($this->plugin_name, WPVIVID_PLUGIN_DIR_URL . 'js/wpvivid-admin.js', array('jquery'), $this->version, false);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  wp_localize_script($this->plugin_name, 'ajax_object', array('ajax_url' => admin_url('admin-ajax.php')));
159
 
160
  wp_enqueue_script('plupload-all');
200
  }
201
  }
202
 
203
+ function add_toolbar_items($wp_admin_bar)
204
+ {
205
+ global $wpvivid_plugin;
206
+ if(is_admin() && current_user_can('administrator')) {
207
+ $show_admin_bar = $wpvivid_plugin->get_admin_bar_setting();
208
+ if ($show_admin_bar === true) {
209
+ $this->toolbar_menus = apply_filters('wpvivid_get_toolbar_menus', $this->toolbar_menus);
210
+ foreach ($this->toolbar_menus as $menu) {
211
+ $wp_admin_bar->add_menu(array(
212
+ 'id' => $menu['id'],
213
+ 'title' => $menu['title']
214
+ ));
215
+ if (isset($menu['child'])) {
216
+ foreach ($menu['child'] as $child_menu) {
217
+ $wp_admin_bar->add_menu(array(
218
+ 'id' => $child_menu['id'],
219
+ 'parent' => $menu['id'],
220
+ 'title' => $child_menu['title'],
221
+ 'href' => $child_menu['href']
222
+ ));
223
+ }
224
+ }
225
+ }
226
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
227
  }
228
  }
229
 
272
  else if(isset($_REQUEST['tab-key'])){
273
  self::wpvivid_set_page_request('key');
274
  }
275
+ global $wpvivid_plugin;
276
+ $wpvivid_plugin->clean_cache();
277
 
278
 
279
  //
309
  $this->wpvivid_show_add_my_review();
310
  $this->wpvivid_check_extensions();
311
 
312
+ $loglist=$wpvivid_plugin->get_log_list_ex();
313
+ $remoteslist=WPvivid_Setting::get_all_remote_options();
314
+ $default_remote_storage='';
315
+ foreach ($remoteslist['remote_selected'] as $value) {
316
+ $default_remote_storage=$value;
317
+ }
318
+ ?>
319
+ <script>
320
+ var wpvivid_siteurl = '<?php
321
+ $wpvivid_siteurl = array();
322
+ $wpvivid_siteurl=WPvivid_Admin::wpvivid_get_siteurl();
323
+ echo esc_url($wpvivid_siteurl['home_url']);
324
+ ?>';
325
+ var wpvivid_plugurl = '<?php
326
+ echo WPVIVID_PLUGIN_URL;
327
+ ?>';
328
+ var wpvivid_log_count = '<?php
329
+ _e(sizeof($loglist['log_list']['file']), 'wpvivid');
330
+ ?>';
331
+ var wpvivid_log_array = '<?php
332
+ _e(json_encode($loglist), 'wpvivid');
333
+ ?>';
334
+ var wpvivid_page_request = '<?php
335
+ $page_request = WPvivid_Admin::wpvivid_get_page_request();
336
+ _e($page_request, 'wpvivid');
337
+ ?>';
338
+ var wpvivid_default_remote_storage = '<?php
339
+ _e($default_remote_storage, 'wpvivid');
340
+ ?>';
341
+ </script>
342
+ <?php
343
+
344
+ do_action('wpvivid_before_setup_page');
345
  include_once('partials/wpvivid-admin-display.php');
346
  }
347
 
483
  }
484
 
485
  if(defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON){
486
+ _e('<div class="notice notice-error is-dismissible"><p>In order to execute the scheduled backups properly, please set the DISABLE_WP_CRON constant to false.</p></div>');
487
  }
488
  }
489
 
553
  <div id="general-page" class="wrap-tab-content wpvivid_tab_general" name="tab-backup" style="width:100%;">
554
  <div class="meta-box-sortables ui-sortable">
555
  <?php
556
+ do_action('wpvivid_backuppage_add_module');
 
 
557
  ?>
558
  <h2 class="nav-tab-wrapper" id="wpvivid_backup_tab" style="padding-bottom:0!important;">
559
  <?php
592
  </table>
593
  </div>
594
  </div>
595
+ <script>
596
+ jQuery('#wpvivid_schedule_save').click(function(){
597
+ wpvivid_set_schedule();
598
+ wpvivid_settings_changed = false;
599
+ });
600
+
601
+ function wpvivid_set_schedule()
602
+ {
603
+ var schedule_data = wpvivid_ajax_data_transfer('schedule');
604
+ var ajax_data = {
605
+ 'action': 'wpvivid_set_schedule',
606
+ 'schedule': schedule_data
607
+ };
608
+ jQuery('#wpvivid_schedule_save').css({'pointer-events': 'none', 'opacity': '0.4'});
609
+ wpvivid_post_request(ajax_data, function (data) {
610
+ try {
611
+ var jsonarray = jQuery.parseJSON(data);
612
+
613
+ jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
614
+ if (jsonarray.result === 'success') {
615
+ location.reload();
616
+ }
617
+ else {
618
+ alert(jsonarray.error);
619
+ }
620
+ }
621
+ catch (err) {
622
+ alert(err);
623
+ jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
624
+ }
625
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
626
+ jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
627
+ var error_message = wpvivid_output_ajaxerror('changing schedule', textStatus, errorThrown);
628
+ alert(error_message);
629
+ });
630
+ }
631
+ </script>
632
  <?php
633
  }
634
 
643
  <div class="postbox storage-account-block" id="wpvivid_storage_account_block">
644
  <?php do_action('wpvivid_add_storage_page'); ?>
645
  </div>
646
+ <h2 class="nav-tab-wrapper" style="padding-bottom:0!important;">
647
+ <?php do_action('wpvivid_storage_add_tab'); ?>
648
+ </h2>
649
+ <?php do_action('wpvivid_storage_add_page'); ?>
 
 
 
 
650
  </div>
651
  </div>
652
  </div>
670
  </table>
671
  </div>
672
  </div>
673
+ <script>
674
+ jQuery('#wpvivid_setting_general_save').click(function(){
675
+ wpvivid_set_general_settings();
676
+ wpvivid_settings_changed = false;
677
+ });
678
+
679
+ function wpvivid_set_general_settings()
680
+ {
681
+ var setting_data = wpvivid_ajax_data_transfer('setting');
682
+ var ajax_data = {
683
+ 'action': 'wpvivid_set_general_setting',
684
+ 'setting': setting_data
685
+ };
686
+ jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'none', 'opacity': '0.4'});
687
+ wpvivid_post_request(ajax_data, function (data) {
688
+ try {
689
+ var jsonarray = jQuery.parseJSON(data);
690
+
691
+ jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
692
+ if (jsonarray.result === 'success') {
693
+ location.reload();
694
+ }
695
+ else {
696
+ alert(jsonarray.error);
697
+ }
698
+ }
699
+ catch (err) {
700
+ alert(err);
701
+ jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
702
+ }
703
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
704
+ jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
705
+ var error_message = wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown);
706
+ alert(error_message);
707
+ });
708
+ }
709
+ </script>
710
  <?php
711
  }
712
 
740
  </thead>
741
  <tbody class="wpvivid-websiteinfo-list" id="wpvivid_websiteinfo_list">
742
  <?php
743
+ global $wpvivid_plugin;
744
+ $website_info=$wpvivid_plugin->get_website_info();
745
  if(!empty($website_info['data'])){
746
  foreach ($website_info['data'] as $key=>$value) { ?>
747
  <?php
777
  </tbody>
778
  </table>
779
  </div>
780
+ <script>
781
+ jQuery('#wpvivid_download_website_info').click(function(){
782
+ wpvivid_download_website_info();
783
+ });
784
+
785
+ /**
786
+ * Download the relevant website info and error logs to your PC for debugging purposes.
787
+ */
788
+ function wpvivid_download_website_info(){
789
+ wpvivid_location_href=true;
790
+ location.href =ajaxurl+'?action=wpvivid_create_debug_package';
791
+ }
792
+
793
+ function wpvivid_click_send_debug_info(){
794
+ var wpvivid_user_mail = jQuery('#wpvivid_user_mail').val();
795
+ var ajax_data = {
796
+ 'action': 'wpvivid_send_debug_info',
797
+ 'user_mail': wpvivid_user_mail
798
+ };
799
+ wpvivid_post_request(ajax_data, function (data) {
800
+ try {
801
+ var jsonarray = jQuery.parseJSON(data);
802
+ if (jsonarray.result === "success") {
803
+ alert("Send succeeded.");
804
+ }
805
+ else {
806
+ alert(jsonarray.error);
807
+ }
808
+ }
809
+ catch (err) {
810
+ alert(err);
811
+ }
812
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
813
+ var error_message = wpvivid_output_ajaxerror('sending debug information', textStatus, errorThrown);
814
+ alert(error_message);
815
+ });
816
+ }
817
+ </script>
818
  <?php
819
  }
820
 
821
  public function wpvivid_add_page_log(){
822
+ global $wpvivid_plugin;
823
  $display_log_count=array(0=>"10",1=>"20",2=>"30",3=>"40",4=>"50");
824
  $max_log_diaplay=20;
825
+ $loglist=$wpvivid_plugin->get_log_list_ex();
826
  ?>
827
  <div id="logs-page" class="wrap-tab-content wpvivid_tab_log" name="tab-logs" style="display:none;">
828
  <div style="padding-bottom: 10px; float: right;">
871
  <input class="button-secondary log-page" id="wpvivid_next_log_page" type="submit" value="<?php esc_attr_e( ' Next page > ', 'wpvivid' ); ?>" />
872
  </div>
873
  </div>
874
+ <script>
875
+ jQuery('#wpvivid_display_log_count').on("change", function(){
876
+ wpvivid_display_log_page();
877
+ });
878
+
879
+ jQuery('#wpvivid_pre_log_page').click(function(){
880
+ wpvivid_pre_log_page();
881
+ });
882
+
883
+ jQuery('#wpvivid_next_log_page').click(function(){
884
+ wpvivid_next_log_page();
885
+ });
886
+
887
+ function wpvivid_pre_log_page(){
888
+ if(wpvivid_cur_log_page > 1){
889
+ wpvivid_cur_log_page--;
890
+ }
891
+ wpvivid_display_log_page();
892
+ }
893
+
894
+ function wpvivid_next_log_page(){
895
+ var display_count = jQuery("#wpvivid_display_log_count option:selected").val();
896
+ var max_pages=Math.ceil(wpvivid_log_count/display_count);
897
+ if(wpvivid_cur_log_page < max_pages){
898
+ wpvivid_cur_log_page++;
899
+ }
900
+ wpvivid_display_log_page();
901
+ }
902
+
903
+ function wpvivid_display_log_page(){
904
+ var display_count = jQuery("#wpvivid_display_log_count option:selected").val();
905
+ var max_pages=Math.ceil(wpvivid_log_count/display_count);
906
+ if(max_pages == 0) max_pages = 1;
907
+ jQuery('#wpvivid_log_page_info').html(wpvivid_cur_log_page+ " / "+max_pages);
908
+
909
+ var begin = (wpvivid_cur_log_page - 1) * display_count;
910
+ var end = parseInt(begin) + parseInt(display_count);
911
+ jQuery("#wpvivid_loglist tr").hide();
912
+ jQuery('#wpvivid_loglist tr').each(function(i){
913
+ if (i >= begin && i < end)
914
+ {
915
+ jQuery(this).show();
916
+ }
917
+ });
918
+ }
919
+
920
+ function wpvivid_retrieve_log_list(){
921
+ var ajax_data = {
922
+ 'action': 'wpvivid_get_log_list'
923
+ };
924
+ wpvivid_post_request(ajax_data, function(data){
925
+ try {
926
+ var jsonarray = jQuery.parseJSON(data);
927
+ if (jsonarray.result === "success") {
928
+ jQuery('#wpvivid_loglist').html("");
929
+ jQuery('#wpvivid_loglist').append(jsonarray.html);
930
+ wpvivid_log_count = jsonarray.log_count;
931
+ wpvivid_display_log_page();
932
+ }
933
+ }
934
+ catch(err){
935
+ alert(err);
936
+ }
937
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
938
+ setTimeout(function () {
939
+ wpvivid_retrieve_log_list();
940
+ }, 3000);
941
+ });
942
+ }
943
+ </script>
944
  <?php
945
  }
946
 
admin/js/wpvivid-admin.js CHANGED
@@ -55,132 +55,12 @@ var wpvivid_resotre_is_migrate=0;
55
  * practising this, we should strive to set a better example in our own work.
56
  */
57
  $(document).ready(function () {
58
- wpvivid_getrequest();
59
 
60
  wpvivid_activate_cron();
61
 
62
- wpvivid_manage_task();
63
-
64
  wpvivid_interface_flow_control();
65
 
66
- $('#wpvivid_quickbackup_btn').click(function(){
67
- wpvivid_clear_notice('wpvivid_backup_notice');
68
- wpvivid_start_backup();
69
- });
70
-
71
- $('#wpvivid_setting_general_save').click(function(){
72
- wpvivid_set_general_settings();
73
- wpvivid_settings_changed = false;
74
- });
75
-
76
- $('#wpvivid_schedule_save').click(function(){
77
- wpvivid_set_schedule();
78
- wpvivid_settings_changed = false;
79
- });
80
-
81
- $('input[option=add-remote]').click(function(){
82
- var storage_type = $(".storage-providers-active").attr("remote_type");
83
- wpvivid_add_remote_storage(storage_type);
84
- wpvivid_settings_changed = false;
85
- });
86
-
87
- $('input[option=edit-remote]').click(function(){
88
- wpvivid_edit_remote_storage();
89
- });
90
-
91
- $('#backup_list_all_check').click(function(){
92
- var name = '';
93
- if($('#backup_list_all_check').prop('checked')) {
94
- $('#wpvivid_backuplist tr').each(function (i) {
95
- $(this).children('th').each(function (j) {
96
- if (j == 0) {
97
- name = jQuery(this).parent().children('td').eq(0).find("img").attr("name");
98
- if(name === 'unlock') {
99
- $(this).find("input[type=checkbox]").prop('checked', true);
100
- }
101
- else{
102
- $(this).find("input[type=checkbox]").prop('checked', false);
103
- }
104
- }
105
- });
106
- });
107
- }
108
- else{
109
- $('#wpvivid_backuplist tr').each(function (i) {
110
- $(this).children('th').each(function (j) {
111
- if (j == 0) {
112
- $(this).find("input[type=checkbox]").prop('checked', false);
113
- }
114
- });
115
- });
116
- }
117
- });
118
-
119
- $('#wpvivid_backup_cancel_btn').click(function(){
120
- wpvivid_cancel_backup();
121
- });
122
-
123
- $('#wpvivid_backup_log_btn').click(function(){
124
- wpvivid_read_log('wpvivid_view_backup_task_log');
125
- });
126
-
127
- $('#wpvivid_send_email_test').click(function(){
128
- wpvivid_email_test();
129
- });
130
-
131
- $('#wpvivid_setting_export').click(function(){
132
- wpvivid_export_settings();
133
- });
134
-
135
- $('#wpvivid_setting_import').click(function(){
136
- wpvivid_import_settings();
137
- });
138
-
139
- $('#wpvivid_set_default_remote_storage').click(function(){
140
- wpvivid_set_default_remote_storage();
141
- wpvivid_settings_changed = false;
142
- });
143
-
144
- $('#wpvivid_display_log_count').on("change", function(){
145
- wpvivid_display_log_page();
146
- });
147
-
148
- $('#wpvivid_pre_log_page').click(function(){
149
- wpvivid_pre_log_page();
150
- });
151
-
152
- $('#wpvivid_next_log_page').click(function(){
153
- wpvivid_next_log_page();
154
- });
155
-
156
- $('#wpvivid_clean_restore').click(function(){
157
- wpvivid_delete_incompleted_restore();
158
- });
159
-
160
- $('#wpvivid_download_btn').click(function(){
161
- wpvivid_download_restore_file('backup');
162
- });
163
-
164
- $('#wpvivid_rollback_btn').click(function(){
165
- wpvivid_start_rollback();
166
- });
167
-
168
- $('#wpvivid_delete_out_of_backup').click(function(){
169
- wpvivid_delete_out_of_date_backups();
170
- });
171
-
172
- $('#wpvivid_calculate_size').click(function(){
173
- wpvivid_calculate_diskspaceused();
174
- });
175
-
176
- $('#wpvivid_clean_junk_file').click(function(){
177
- wpvivid_clean_junk_files();
178
- });
179
-
180
- $('#wpvivid_download_website_info').click(function(){
181
- wpvivid_download_website_info();
182
- });
183
-
184
  $('input[option=review]').click(function(){
185
  var name = jQuery(this).prop('name');
186
  wpvivid_add_review_info(name);
@@ -291,8 +171,8 @@ function wpvivid_check_runningtask(){
291
  });
292
  }
293
  if(jsonarray.backuplist_html != false) {
294
- jQuery('#wpvivid_backuplist').html('');
295
- jQuery('#wpvivid_backuplist').append(jsonarray.backuplist_html);
296
  }
297
  var b_has_data = false;
298
  if (jsonarray.backup.data.length !== 0) {
@@ -458,30 +338,6 @@ function wpvivid_check_runningtask(){
458
  }
459
  }
460
 
461
- /**
462
- * This function will cancel a backup
463
- */
464
- function wpvivid_cancel_backup(){
465
- var ajax_data= {
466
- 'action': 'wpvivid_backup_cancel',
467
- 'task_id': running_backup_taskid
468
- };
469
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
470
- wpvivid_post_request(ajax_data, function(data){
471
- try {
472
- var jsonarray = jQuery.parseJSON(data);
473
- jQuery('#wpvivid_current_doing').html(jsonarray.msg);
474
- }
475
- catch(err){
476
- alert(err);
477
- }
478
- }, function(XMLHttpRequest, textStatus, errorThrown) {
479
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
480
- var error_message = wpvivid_output_ajaxerror('cancelling the backup', textStatus, errorThrown);
481
- wpvivid_add_notice('Backup', 'Error', error_message);
482
- });
483
- }
484
-
485
  function wpvivid_read_log(action, param){
486
  var tab_id = '';
487
  var content_id = '';
@@ -575,152 +431,6 @@ function wpvivid_show_log(data, content_id){
575
  }
576
  }
577
 
578
- function wpvivid_control_backup_lock(){
579
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
580
- jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
581
- }
582
-
583
- function wpvivid_control_backup_unlock(){
584
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
585
- jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
586
- }
587
-
588
- /**
589
- * Start backing up
590
- */
591
- function wpvivid_start_backup(){
592
- var bcheck=true;
593
- var bdownloading=false;
594
- if(m_downloading_id !== '') {
595
- var descript = 'This request might delete the backup being downloaded, are you sure you want to continue?';
596
- var ret = confirm(descript);
597
- if (ret === true) {
598
- bcheck=true;
599
- bdownloading=true;
600
- }
601
- else{
602
- bcheck=false;
603
- }
604
- }
605
- if(bcheck) {
606
- var backup_data = wpvivid_ajax_data_transfer('backup');
607
- backup_data = JSON.parse(backup_data);
608
- jQuery('input:radio[option=backup_ex]').each(function() {
609
- if(jQuery(this).prop('checked'))
610
- {
611
- var key = jQuery(this).prop('name');
612
- var value = jQuery(this).prop('value');
613
- var json = new Array();
614
- if(value == 'local'){
615
- json['local']='1';
616
- json['remote']='0';
617
- }
618
- else if(value == 'remote'){
619
- json['local']='0';
620
- json['remote']='1';
621
- }
622
- }
623
- jQuery.extend(backup_data, json);
624
- });
625
- backup_data = JSON.stringify(backup_data);
626
- var ajax_data = {
627
- 'action': 'wpvivid_prepare_backup',
628
- 'backup': backup_data
629
- };
630
- //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
631
- wpvivid_control_backup_lock();
632
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
633
- jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
634
- jQuery('#wpvivid_postbox_backup_percent').show();
635
- jQuery('#wpvivid_current_doing').html('Ready to backup. Progress: 0%, running time: 0second.');
636
- var percent = '0%';
637
- jQuery('#wpvivid_action_progress_bar_percent').css('width', percent);
638
- jQuery('#wpvivid_backup_database_size').html('N/A');
639
- jQuery('#wpvivid_backup_file_size').html('N/A');
640
- jQuery('#wpvivid_current_doing').html('');
641
- wpvivid_completed_backup = 1;
642
- wpvivid_prepare_backup = true;
643
- wpvivid_post_request(ajax_data, function (data) {
644
- try {
645
- var jsonarray = jQuery.parseJSON(data);
646
- if (jsonarray.result === 'failed') {
647
- wpvivid_delete_ready_task(jsonarray.error);
648
- }
649
- else if (jsonarray.result === 'success') {
650
- if(bdownloading) {
651
- m_downloading_id = '';
652
- }
653
- m_backup_task_id = jsonarray.task_id;
654
- /*if (jsonarray.check.alert_db === false && jsonarray.check.alter_files === false && jsonarray.check.alter_fcgi === false) {
655
- jQuery('#wpvivid_backuplist').html('');
656
- jQuery('#wpvivid_backuplist').append(jsonarray.html);
657
- wpvivid_backup_now(jsonarray.task_id);
658
- }
659
- else {*/
660
- var descript = '';
661
- if (jsonarray.check.alert_db === true || jsonarray.check.alter_files === true) {
662
- descript = 'The database (the dumping SQL file) might be too large, backing up the database may run out of server memory and result in a backup failure.\n' +
663
- 'One or more files might be too large, backing up the file(s) may run out of server memory and result in a backup failure.\n' +
664
- 'Click OK button and continue to back up.';
665
- var ret = confirm(descript);
666
- if (ret === true) {
667
- jQuery('#wpvivid_backuplist').html('');
668
- jQuery('#wpvivid_backuplist').append(jsonarray.html);
669
- wpvivid_backup_now(m_backup_task_id);
670
- }
671
- else {
672
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
673
- jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
674
- //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
675
- wpvivid_control_backup_unlock();
676
- jQuery('#wpvivid_postbox_backup_percent').hide();
677
- }
678
- }
679
- else{
680
- jQuery('#wpvivid_backuplist').html('');
681
- jQuery('#wpvivid_backuplist').append(jsonarray.html);
682
- wpvivid_backup_now(jsonarray.task_id);
683
- }
684
- //}
685
- }
686
- }
687
- catch (err) {
688
- wpvivid_delete_ready_task(err);
689
- }
690
- }, function (XMLHttpRequest, textStatus, errorThrown) {
691
- var error_message = wpvivid_output_ajaxerror('preparing the backup', textStatus, errorThrown);
692
- wpvivid_delete_ready_task(error_message);
693
- });
694
- }
695
- }
696
-
697
- function wpvivid_delete_ready_task(error){
698
- var ajax_data={
699
- 'action': 'wpvivid_delete_ready_task'
700
- };
701
- wpvivid_post_request(ajax_data, function (data) {
702
- try {
703
- var jsonarray = jQuery.parseJSON(data);
704
- if (jsonarray.result === 'success') {
705
- wpvivid_add_notice('Backup', 'Error', error);
706
- //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
707
- wpvivid_control_backup_unlock();
708
- jQuery('#wpvivid_postbox_backup_percent').hide();
709
- }
710
- }
711
- catch(err){
712
- wpvivid_add_notice('Backup', 'Error', err);
713
- //jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
714
- wpvivid_control_backup_unlock();
715
- jQuery('#wpvivid_postbox_backup_percent').hide();
716
- }
717
- }, function (XMLHttpRequest, textStatus, errorThrown) {
718
- setTimeout(function () {
719
- wpvivid_delete_ready_task(error);
720
- }, 3000);
721
- });
722
- }
723
-
724
  /**
725
  * Resume the backup task automatically in 1 minute in a timeout situation
726
  *
@@ -761,506 +471,77 @@ function wpvivid_retrieve_last_backup_message(){
761
  }
762
 
763
  /**
764
- * Add remote storages to the list
765
- *
766
- * @param action - The action to add or test a remote storage
767
- * @param storage_type - Remote storage types (Amazon S3, SFTP and FTP server)
768
  */
769
- function wpvivid_add_remote_storage(storage_type)
770
- {
771
- var remote_from = wpvivid_ajax_data_transfer(storage_type);
772
- var ajax_data;
773
- ajax_data = {
774
- 'action': 'wpvivid_add_remote',
775
- 'remote': remote_from,
776
- 'type': storage_type
777
- };
778
- jQuery('input[option=add-remote]').css({'pointer-events': 'nano', 'opacity': '0.4'});
779
- jQuery('#wpvivid_remote_notice').html('');
780
- wpvivid_post_request(ajax_data, function (data)
781
- {
782
- try
783
- {
784
- var jsonarray = jQuery.parseJSON(data);
785
- if (jsonarray.result === 'success')
786
- {
787
- jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
788
- jQuery('input:text[option='+storage_type+']').each(function(){
789
- jQuery(this).val('');
790
- });
791
- jQuery('input:password[option='+storage_type+']').each(function(){
792
- jQuery(this).val('');
793
- });
794
- wpvivid_handle_remote_storage_data(data);
795
- }
796
- else if (jsonarray.result === 'failed')
797
- {
798
- jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
799
- jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
800
- }
801
- }
802
- catch (err)
803
- {
804
- alert(err);
805
- jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
806
- }
807
 
808
- }, function (XMLHttpRequest, textStatus, errorThrown)
809
- {
810
- var error_message = wpvivid_output_ajaxerror('adding the remote storage', textStatus, errorThrown);
811
- alert(error_message);
812
- jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
813
- });
814
- }
815
 
816
- function wpvivid_handle_remote_storage_data(data){
817
- var i = 0;
818
- try {
819
- var jsonarray = jQuery.parseJSON(data);
820
- if (jsonarray.result === 'success') {
821
- jQuery('#wpvivid_remote_storage_list').html('');
822
- jQuery('#wpvivid_remote_storage_list').append(jsonarray.html);
823
- jQuery('#upload_storage').html(jsonarray.pic);
824
- jQuery('#schedule_upload_storage').html(jsonarray.pic);
825
- jQuery('#wpvivid_out_of_date_remote_path').html(jsonarray.dir);
826
- jQuery('#wpvivid_schedule_backup_local_remote').html(jsonarray.local_remote);
827
- wpvivid_control_remote_storage(jsonarray.remote_storage);
828
- wpvivid_interface_flow_control();
829
- jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
830
- }
831
- else if(jsonarray.result === 'failed'){
832
- jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
833
- }
834
- }
835
- catch(err){
836
- alert(err);
837
- }
838
- }
839
 
840
- function wpvivid_control_remote_storage(has_remote){
841
- jQuery("input:radio[name='save_local_remote'][value='remote']").click(function(){
842
- if(!has_remote){
843
- alert("There is no default remote storage configured. Please set it up first.");
844
- jQuery("input:radio[name='save_local_remote'][value='local']").prop('checked', true);
845
  }
846
  });
847
- }
848
-
849
- function click_retrieve_remote_storage(id,type,name)
850
- {
851
- wpvivid_editing_storage_id = id;
852
- jQuery('.remote-storage-edit').hide();
853
- jQuery('#wpvivid_tab_storage_edit').show();
854
- jQuery('#wpvivid_tab_storage_edit_text').html(name);
855
- wpvivid_editing_storage_type=type;
856
- jQuery('#remote_storage_edit_'+wpvivid_editing_storage_type).fadeIn();
857
- wpvivid_click_switch_page('storage', 'wpvivid_tab_storage_edit', true);
858
 
859
- var ajax_data = {
860
- 'action': 'wpvivid_retrieve_remote',
861
- 'remote_id': id
862
- };
863
- wpvivid_post_request(ajax_data, function(data)
864
- {
865
- try
866
- {
867
- var jsonarray = jQuery.parseJSON(data);
868
- if (jsonarray.result === 'success')
869
- {
870
- jQuery('input:text[option=edit-'+jsonarray.type+']').each(function(){
871
- var key = jQuery(this).prop('name');
872
- if(key == 's3Path' && jsonarray.type == 'amazons3'){
873
- var iLength = jsonarray[key].lastIndexOf('/wpvivid_backup');
874
- if(iLength != -1) {
875
- jsonarray[key] = jsonarray[key].substring(0, iLength);
876
- }
877
- jQuery(this).val(jsonarray[key]);
878
- }
879
- else {
880
- jQuery(this).val(jsonarray[key]);
881
- }
882
- });
883
- jQuery('input:password[option=edit-'+jsonarray.type+']').each(function(){
884
- var key = jQuery(this).prop('name');
885
- jQuery(this).val(jsonarray[key]);
886
- });
887
- jQuery('input:checkbox[option=edit-'+jsonarray.type+']').each(function() {
888
- var key = jQuery(this).prop('name');
889
- var value;
890
- if(jsonarray[key] == '0'){
891
- value = false;
892
- }
893
- else{
894
- value = true;
895
- }
896
- jQuery(this).prop('checked', value);
897
- });
898
- if(jsonarray.type == 'amazons3'){
899
- var amazons3_edit_value = jQuery('input:text[option=edit-'+jsonarray.type+'][name=s3Path]').val();
900
- if(amazons3_edit_value == ''){
901
- amazons3_edit_value = '*';
902
- }
903
- amazons3_edit_value = amazons3_edit_value + '/wpvivid_backup';
904
- jQuery('#wpvivid_edit_amazons3_root_path').html(amazons3_edit_value);
905
- }
906
- if(jsonarray.type == 's3compat'){
907
- var dos_edit_value = jQuery('input:text[option=edit-'+jsonarray.type+'][name=s3directory]').val();
908
- if(dos_edit_value == ''){
909
- dos_edit_value = '*';
910
- }
911
- dos_edit_value = dos_edit_value + '/wpvivid_backup';
912
- jQuery('#wpvivid_edit_dos_root_path').html(dos_edit_value);
913
- }
914
  }
915
- else
916
- {
917
- alert(jsonarray.error);
918
  }
919
  }
920
- catch(err)
921
- {
922
- alert(err);
923
  }
924
- },function(XMLHttpRequest, textStatus, errorThrown)
925
- {
926
- var error_message = wpvivid_output_ajaxerror('retrieving the remote storage', textStatus, errorThrown);
927
- alert(error_message);
928
  });
929
- }
930
 
931
- function wpvivid_edit_remote_storage() {
932
- var data_tran = 'edit-'+wpvivid_editing_storage_type;
933
- var remote_data = wpvivid_ajax_data_transfer(data_tran);
934
- var ajax_data;
935
- ajax_data = {
936
- 'action': 'wpvivid_edit_remote',
937
- 'remote': remote_data,
938
- 'id': wpvivid_editing_storage_id,
939
- 'type': wpvivid_editing_storage_type
940
- };
941
- jQuery('#wpvivid_remote_notice').html('');
942
- wpvivid_post_request(ajax_data, function(data){
943
- try {
944
- var jsonarray = jQuery.parseJSON(data);
945
- if (jsonarray.result === 'success') {
946
- jQuery('#wpvivid_tab_storage_edit').hide();
947
- wpvivid_click_switch_page('storage', 'wpvivid_tab_storage_list', true);
948
- wpvivid_handle_remote_storage_data(data);
949
- }
950
- else if (jsonarray.result === 'failed') {
951
- jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
952
- }
953
  }
954
- catch(err){
955
- alert(err);
956
  }
957
- },function(XMLHttpRequest, textStatus, errorThrown) {
958
- var error_message = wpvivid_output_ajaxerror('editing the remote storage', textStatus, errorThrown);
959
- alert(error_message);
960
  });
961
- }
962
-
963
- /*
964
- * Delete the selected remote storage from the list
965
- *
966
- * @param storage_id - A unique ID for a remote storage
967
- */
968
- function wpvivid_delete_remote_storage(storage_id){
969
- var descript = 'Deleting a remote storage will make it unavailable until it is added again. Are you sure to continue?';
970
- var ret = confirm(descript);
971
- if(ret === true){
972
- var ajax_data = {
973
- 'action': 'wpvivid_delete_remote',
974
- 'remote_id': storage_id
975
- };
976
- wpvivid_post_request(ajax_data, function(data){
977
- wpvivid_handle_remote_storage_data(data);
978
- },function(XMLHttpRequest, textStatus, errorThrown) {
979
- var error_message = wpvivid_output_ajaxerror('deleting the remote storage', textStatus, errorThrown);
980
- alert(error_message);
981
- });
982
- }
983
- }
984
 
985
- /*
986
- * Retrieve backup list once any changes happened.
987
- */
988
- function wpvivid_retrieve_backup_list(){
989
- var ajax_data = {
990
- 'action': 'wpvivid_get_backup_list'
991
- };
992
- wpvivid_post_request(ajax_data, function(data){
993
- try {
994
- var jsonarray = jQuery.parseJSON(data);
995
- if (jsonarray.result === 'success') {
996
- jQuery('#wpvivid_backuplist').html('');
997
- jQuery('#wpvivid_backuplist').append(jsonarray.html);
998
- }
999
- }
1000
- catch(err){
1001
- alert(err);
1002
- }
1003
- },function(XMLHttpRequest, textStatus, errorThrown) {
1004
- setTimeout(function () {
1005
- wpvivid_retrieve_backup_list();
1006
- }, 3000);
1007
  });
1008
- }
1009
 
1010
- function wpvivid_handle_backup_data(data){
1011
- try {
1012
- var jsonarray = jQuery.parseJSON(data);
1013
- if (jsonarray.result === 'success') {
1014
- jQuery('#wpvivid_backuplist').html('');
1015
- jQuery('#wpvivid_backuplist').append(jsonarray.html);
1016
- }
1017
- else if(jsonarray.result === 'failed'){
1018
- alert(jsonarray.error);
1019
- }
1020
- }
1021
- catch(err){
1022
- alert(err);
1023
- }
1024
- }
1025
 
1026
- /**
1027
- * Modify general settings
1028
- */
1029
- function wpvivid_set_general_settings()
1030
- {
1031
- var setting_data = wpvivid_ajax_data_transfer('setting');
1032
- var ajax_data = {
1033
- 'action': 'wpvivid_set_general_setting',
1034
- 'setting': setting_data
1035
- };
1036
- jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'none', 'opacity': '0.4'});
1037
- wpvivid_post_request(ajax_data, function (data) {
1038
- try {
1039
- var jsonarray = jQuery.parseJSON(data);
1040
 
1041
- jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
1042
- if (jsonarray.result === 'success') {
1043
- location.reload();
1044
- }
1045
- else {
1046
- alert(jsonarray.error);
1047
- }
1048
- }
1049
- catch (err) {
1050
- alert(err);
1051
- jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
1052
- }
1053
- }, function (XMLHttpRequest, textStatus, errorThrown) {
1054
- jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
1055
- var error_message = wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown);
1056
- alert(error_message);
1057
  });
1058
- }
1059
 
1060
- function wpvivid_set_schedule()
1061
- {
1062
- var schedule_data = wpvivid_ajax_data_transfer('schedule');
1063
- var ajax_data = {
1064
- 'action': 'wpvivid_set_schedule',
1065
- 'schedule': schedule_data
1066
- };
1067
- jQuery('#wpvivid_schedule_save').css({'pointer-events': 'none', 'opacity': '0.4'});
1068
- wpvivid_post_request(ajax_data, function (data) {
1069
- try {
1070
- var jsonarray = jQuery.parseJSON(data);
1071
 
1072
- jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
1073
- if (jsonarray.result === 'success') {
1074
- location.reload();
1075
- }
1076
- else {
1077
- alert(jsonarray.error);
1078
  }
1079
- }
1080
- catch (err) {
1081
- alert(err);
1082
- jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
1083
- }
1084
- }, function (XMLHttpRequest, textStatus, errorThrown) {
1085
- jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
1086
- var error_message = wpvivid_output_ajaxerror('changing schedule', textStatus, errorThrown);
1087
- alert(error_message);
1088
  });
1089
  }
1090
 
1091
  /**
1092
- * After enabling email report feature, and test if an email address works or not
1093
- */
1094
- function wpvivid_email_test(){
1095
- var mail = jQuery('#wpvivid_mail').val();
1096
- var ajax_data = {
1097
- 'action': 'wpvivid_test_send_mail',
1098
- 'send_to': mail
1099
- };
1100
- wpvivid_post_request(ajax_data, function(data){
1101
- try {
1102
- var jsonarray = jQuery.parseJSON(data);
1103
- if (jsonarray.result === 'success') {
1104
- jQuery('#wpvivid_send_email_res').html('Test succeeded.');
1105
- }
1106
- else {
1107
- jQuery('#wpvivid_send_email_res').html('Test failed, ' + jsonarray.error);
1108
- }
1109
- }
1110
- catch(err){
1111
- alert(err);
1112
- }
1113
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1114
- var error_message = wpvivid_output_ajaxerror('sending test mail', textStatus, errorThrown);
1115
- alert(error_message);
1116
- });
1117
- }
1118
-
1119
- /**
1120
- * This function will export settings to local folder
1121
- */
1122
- function wpvivid_export_settings() {
1123
- wpvivid_location_href=true;
1124
- location.href =ajaxurl+'?action=wpvivid_export_setting&setting=1&history=1&review=0';
1125
- }
1126
-
1127
- /**
1128
- * This function will import the previous exported settings
1129
- */
1130
- function wpvivid_import_settings(){
1131
- var files = jQuery('input[name="fileTrans"]').prop('files');
1132
-
1133
- if(files.length == 0){
1134
- alert('Choose a settings file and import it by clicking Import button.');
1135
- return;
1136
- }
1137
- else{
1138
- var reader = new FileReader();
1139
- reader.readAsText(files[0], "UTF-8");
1140
- reader.onload = function(evt){
1141
- var fileString = evt.target.result;
1142
- var ajax_data = {
1143
- 'action': 'wpvivid_import_setting',
1144
- 'data': fileString
1145
- };
1146
- wpvivid_post_request(ajax_data, function(data){
1147
- try {
1148
- var jsonarray = jQuery.parseJSON(data);
1149
- if (jsonarray.result === 'success') {
1150
- location.reload();
1151
- }
1152
- else {
1153
- alert('Error: ' + jsonarray.error);
1154
- }
1155
- }
1156
- catch(err){
1157
- alert(err);
1158
- }
1159
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1160
- var error_message = wpvivid_output_ajaxerror('importing the previously-exported settings', textStatus, errorThrown);
1161
- jQuery('#wpvivid_display_log_content').html(error_message);
1162
- });
1163
- }
1164
- }
1165
- }
1166
-
1167
- /**
1168
- * This function will control interface flow.
1169
- */
1170
- function wpvivid_interface_flow_control(){
1171
- jQuery('#quickstart_storage_setting').css({'pointer-events': 'none', 'opacity': '0.4'});
1172
- jQuery('#wpvivid_backup_remote').click(function(){
1173
- if(jQuery('#wpvivid_backup_remote').prop('checked') === true){
1174
- jQuery('#quickstart_storage_setting').css({'pointer-events': 'auto', 'opacity': '1'});
1175
- }
1176
- else{
1177
- jQuery('#quickstart_storage_setting').css({'pointer-events': 'none', 'opacity': '0.4'});
1178
- }
1179
- });
1180
-
1181
- jQuery('#wpvivid_general_email_enable').click(function(){
1182
- if(jQuery('#wpvivid_general_email_enable').prop('checked') === true){
1183
- jQuery('#wpvivid_general_email_setting').show();
1184
-
1185
- }
1186
- else{
1187
- jQuery('#wpvivid_general_email_setting').hide();
1188
- }
1189
- });
1190
-
1191
- /*jQuery('input[name="remote_storage"]').on("click", function(){
1192
- var check_status = true;
1193
- if(jQuery(this).prop('checked') === true){
1194
- check_status = true;
1195
- }
1196
- else {
1197
- check_status = false;
1198
- }
1199
- jQuery('input[name="remote_storage"]').prop('checked', false);
1200
- if(check_status === true){
1201
- jQuery(this).prop('checked', true);
1202
- }
1203
- else {
1204
- jQuery(this).prop('checked', false);
1205
- }
1206
- });*/
1207
-
1208
- jQuery("input[name='schedule-backup-files']").bind("click",function(){
1209
- if(jQuery(this).val() === "custom"){
1210
- jQuery('#wpvivid_choosed_folders').show();
1211
- if(jQuery("input[name='wpvivid-schedule-custom-folders'][value='other']").prop('checked')){
1212
- jQuery('#wpvivid_file_tree_browser').show();
1213
- }
1214
- else{
1215
- jQuery('#wpvivid_file_tree_browser').hide();
1216
- }
1217
- }
1218
- else{
1219
- jQuery('#wpvivid_choosed_folders').hide();
1220
- jQuery('#wpvivid_file_tree_browser').hide();
1221
- }
1222
- });
1223
-
1224
- jQuery("input[name='wpvivid-schedule-custom-folders']").bind("click",function(){
1225
- if(jQuery("input[name='wpvivid-schedule-custom-folders'][value='other']").prop('checked')){
1226
- jQuery('#wpvivid_file_tree_browser').show();
1227
- }
1228
- else{
1229
- jQuery('#wpvivid_file_tree_browser').hide();
1230
- }
1231
- });
1232
-
1233
- jQuery('#settings-page input[type=checkbox]:not([option=junk-files])').on("change", function(){
1234
- wpvivid_settings_changed = true;
1235
- });
1236
-
1237
- jQuery('#settings-page input[type=radio]').on("change", function(){
1238
- wpvivid_settings_changed = true;
1239
- });
1240
-
1241
- jQuery('#settings-page input[type=text]').on("keyup", function(){
1242
- wpvivid_settings_changed = true;
1243
- });
1244
-
1245
- jQuery("#wpvivid_storage_account_block input:not([type=checkbox])").on("keyup", function(){
1246
- wpvivid_settings_changed = true;
1247
- });
1248
-
1249
- jQuery('#wpvivid_storage_account_block input[type=checkbox]').on("change", function(){
1250
- wpvivid_settings_changed = true;
1251
- });
1252
-
1253
- jQuery('input:radio[option=restore]').click(function() {
1254
- jQuery('input:radio[option=restore]').each(function () {
1255
- if (jQuery(this).prop('checked')) {
1256
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1257
- }
1258
- });
1259
- });
1260
- }
1261
-
1262
- /**
1263
- * Manage backup and download tasks. Retrieve the data every 3 seconds for checking if the backup or download tasks exist or not.
1264
  */
1265
  function wpvivid_manage_task() {
1266
  if(m_need_update === true){
@@ -1346,179 +627,10 @@ function click_dismiss_notice(obj){
1346
  jQuery(obj).parent().remove();
1347
  }
1348
 
1349
- function wpvivid_backup_now(task_id){
1350
- var ajax_data = {
1351
- 'action': 'wpvivid_backup_now',
1352
- 'task_id': task_id
1353
- };
1354
- task_retry_times = 0;
1355
- m_need_update=true;
1356
- wpvivid_post_request(ajax_data, function(data){
1357
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1358
- });
1359
- }
1360
-
1361
- function wpvivid_delete_backup_task(task_id){
1362
- var ajax_data = {
1363
- 'action': 'wpvivid_delete_task',
1364
- 'task_id': task_id
1365
- };
1366
- wpvivid_post_request(ajax_data, function(data){}, function(XMLHttpRequest, textStatus, errorThrown) {
1367
- });
1368
- }
1369
-
1370
- /**
1371
- * Calculate elapsed time for backing up.
1372
- *
1373
- * @param carry_out_time - Elapsed time for backing up
1374
- *
1375
- * @returns {*}
1376
- */
1377
- function wpvivid_calc_backup_elapsed_time(carry_out_time){
1378
- var time = carry_out_time;
1379
- if (null != time && "" != time) {
1380
- if (time > 60 && time < 60 * 60) {
1381
- time = parseInt(time / 60.0) + 'min' + parseInt((parseFloat(time / 60.0) -
1382
- parseInt(time / 60.0)) * 60) + 'second';
1383
- }
1384
- else if (time >= 60 * 60 && time < 60 * 60 * 24) {
1385
- time = parseInt(time / 3600.0) + 'hour' + parseInt((parseFloat(time / 3600.0) -
1386
- parseInt(time / 3600.0)) * 60) + 'min' +
1387
- parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
1388
- parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + 'second';
1389
- } else if (time >= 60 * 60 * 24) {
1390
- time = parseInt(time / 3600.0/24) + 'day' +parseInt((parseFloat(time / 3600.0/24)-
1391
- parseInt(time / 3600.0/24))*24) + 'hour' + parseInt((parseFloat(time / 3600.0) -
1392
- parseInt(time / 3600.0)) * 60) + 'min' +
1393
- parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
1394
- parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + 'second';
1395
- }
1396
- else {
1397
- time = parseInt(time) + 'second';
1398
- }
1399
- }
1400
- return time;
1401
- }
1402
-
1403
  function wpvivid_cron_task(){
1404
  jQuery.get(wpvivid_siteurl+'/wp-cron.php');
1405
  }
1406
 
1407
- /**
1408
- * This function will initialize the download information.
1409
- *
1410
- * @param backup_id - The unique ID of the backup
1411
- */
1412
- function wpvivid_initialize_download(backup_id){
1413
- wpvivid_reset_backup_list();
1414
- jQuery('#wpvivid_download_loading_'+backup_id).addClass('is-active');
1415
- tmp_current_click_backupid = backup_id;
1416
- var ajax_data = {
1417
- 'action':'wpvivid_init_download_page',
1418
- 'backup_id':backup_id
1419
- };
1420
- wpvivid_post_request(ajax_data, function(data){
1421
- try {
1422
- var jsonarray = jQuery.parseJSON(data);
1423
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
1424
- if (jsonarray.result === 'success') {
1425
- jQuery('#wpvivid_file_part_' + backup_id).html("");
1426
- var i = 0;
1427
- var file_not_found = false;
1428
- var file_name = '';
1429
- jQuery.each(jsonarray.files, function (index, value) {
1430
- i++;
1431
- file_name = index;
1432
- if (value.status === 'need_download') {
1433
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
1434
- //tmp_current_click_backupid = '';
1435
- }
1436
- else if (value.status === 'running') {
1437
- if (m_downloading_file_name === file_name) {
1438
- wpvivid_lock_download(tmp_current_click_backupid);
1439
- }
1440
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
1441
- }
1442
- else if (value.status === 'completed') {
1443
- if (m_downloading_file_name === file_name) {
1444
- wpvivid_unlock_download(tmp_current_click_backupid);
1445
- m_downloading_id = '';
1446
- m_downloading_file_name = '';
1447
- }
1448
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
1449
- //tmp_current_click_backupid = '';
1450
- }
1451
- else if (value.status === 'timeout') {
1452
- if (m_downloading_file_name === file_name) {
1453
- wpvivid_unlock_download(tmp_current_click_backupid);
1454
- m_downloading_id = '';
1455
- m_downloading_file_name = '';
1456
- }
1457
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
1458
- //tmp_current_click_backupid = '';
1459
- }
1460
- else if (value.status === 'file_not_found') {
1461
- wpvivid_unlock_download(tmp_current_click_backupid);
1462
- wpvivid_reset_backup_list();
1463
- file_not_found = true;
1464
- alert("Download failed, file not found. The file might has been moved, renamed or deleted. Please verify the file exists and try again.");
1465
- //tmp_current_click_backupid = '';
1466
- return false;
1467
- }
1468
- });
1469
- if (file_not_found === false) {
1470
- jQuery('#wpvivid_file_part_' + backup_id).append(jsonarray.place_html);
1471
- }
1472
- }
1473
- }
1474
- catch(err){
1475
- alert(err);
1476
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
1477
- }
1478
- },function(XMLHttpRequest, textStatus, errorThrown){
1479
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
1480
- var error_message = wpvivid_output_ajaxerror('initializing download information', textStatus, errorThrown);
1481
- alert(error_message);
1482
- });
1483
- }
1484
-
1485
- function wpvivid_reset_backup_list(){
1486
- jQuery('#wpvivid_backuplist tr').each(function(i){
1487
- jQuery(this).children('td').each(function (j) {
1488
- if (j == 2) {
1489
- var backup_id = jQuery(this).parent().children('th').find("input[type=checkbox]").attr("id");
1490
- var download_btn = '<div id="wpvivid_file_part_' + backup_id + '" style="float:left;padding:10px 10px 10px 0px;">' +
1491
- '<div style="cursor:pointer;" onclick="wpvivid_initialize_download(\'' + backup_id + '\');" title="Prepare to download the backup">' +
1492
- '<img id="wpvivid_download_btn_' + backup_id + '" src="' + wpvivid_plugurl + '/images/download.png" style="vertical-align:middle;" />Download' +
1493
- '<div class="spinner" id="wpvivid_download_loading_' + backup_id + '" style="float:right;width:auto;height:auto;padding:10px 180px 10px 0;background-position:0 0;"></div>' +
1494
- '</div>' +
1495
- '</div>';
1496
- jQuery(this).html(download_btn);
1497
- }
1498
- });
1499
- });
1500
- }
1501
-
1502
- function wpvivid_lock_download(backup_id){
1503
- jQuery('#wpvivid_backuplist tr').each(function(i){
1504
- jQuery(this).children('td').each(function (j) {
1505
- if (j == 2) {
1506
- jQuery(this).css({'pointer-events': 'none', 'opacity': '0.4'});
1507
- }
1508
- });
1509
- });
1510
- }
1511
-
1512
- function wpvivid_unlock_download(backup_id){
1513
- jQuery('#wpvivid_backuplist tr').each(function(i){
1514
- jQuery(this).children('td').each(function (j) {
1515
- if (j == 2) {
1516
- jQuery(this).css({'pointer-events': 'auto', 'opacity': '1'});
1517
- }
1518
- });
1519
- });
1520
- }
1521
-
1522
  function wpvivid_clear_notice(notice_id){
1523
  var t = document.getElementById(notice_id);
1524
  var oDiv = t.getElementsByTagName("div");
@@ -1530,114 +642,6 @@ function wpvivid_clear_notice(notice_id){
1530
  jQuery('#'+notice_id).hide();
1531
  }
1532
 
1533
- /**
1534
- * Start downloading backup
1535
- *
1536
- * @param part_num - The part number for the download object
1537
- * @param backup_id - The unique ID for the backup
1538
- * @param file_name - File name
1539
- */
1540
- function wpvivid_prepare_download(part_num, backup_id, file_name){
1541
- var ajax_data = {
1542
- 'action': 'wpvivid_prepare_download_backup',
1543
- 'backup_id':backup_id,
1544
- 'file_name':file_name
1545
- };
1546
- var progress = '0%';
1547
- jQuery("#"+backup_id+"-text-part-"+part_num).html("<a>Retriving(remote storage to web server)</a>");
1548
- jQuery("#"+backup_id+"-progress-part-"+part_num).css('width', progress);
1549
- task_retry_times = 0;
1550
- m_need_update = true;
1551
- wpvivid_lock_download(backup_id);
1552
- m_downloading_id = backup_id;
1553
- tmp_current_click_backupid = backup_id;
1554
- m_downloading_file_name = file_name;
1555
- wpvivid_post_request(ajax_data, function(data)
1556
- {
1557
- }, function(XMLHttpRequest, textStatus, errorThrown)
1558
- {
1559
- }, 0);
1560
- }
1561
-
1562
- /**
1563
- * Download backups to user's computer.
1564
- *
1565
- * @param backup_id - The unique ID for the backup
1566
- * @param backup_type - The types of the backup
1567
- * @param file_name - File name
1568
- */
1569
- function wpvivid_download(backup_id, backup_type, file_name){
1570
- wpvivid_location_href=true;
1571
- location.href =ajaxurl+'?action=wpvivid_download_backup&backup_id='+backup_id+'&download_type='+backup_type+'&file_name='+file_name;
1572
- }
1573
-
1574
- function wpvivid_click_check_backup(backup_id){
1575
- var name = "";
1576
- var all_check = true;
1577
- jQuery('#wpvivid_backuplist tr').each(function (i) {
1578
- jQuery(this).children('th').each(function (j) {
1579
- if(j === 0) {
1580
- var id = jQuery(this).find("input[type=checkbox]").attr("id");
1581
- if (id === backup_id) {
1582
- name = jQuery(this).parent().children('td').eq(0).find("img").attr("name");
1583
- if (name === "unlock") {
1584
- if (jQuery(this).find("input[type=checkbox]").prop('checked') === false) {
1585
- all_check = false;
1586
- }
1587
- }
1588
- else {
1589
- jQuery(this).find("input[type=checkbox]").prop('checked', false);
1590
- all_check = false;
1591
- }
1592
- }
1593
- else {
1594
- if (jQuery(this).find("input[type=checkbox]").prop('checked') === false) {
1595
- all_check = false;
1596
- }
1597
- }
1598
- }
1599
- });
1600
- });
1601
- if(all_check === true){
1602
- jQuery('#backup_list_all_check').prop('checked', true);
1603
- }
1604
- else{
1605
- jQuery('#backup_list_all_check').prop('checked', false);
1606
- }
1607
- }
1608
-
1609
- function wpvivid_getrequest() {
1610
- switch(wpvivid_page_request){
1611
- case "backup":
1612
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_general', false);
1613
- break;
1614
- case "transfer":
1615
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_migrate', false);
1616
- break;
1617
- case "settings":
1618
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_setting', false);
1619
- break;
1620
- case "schedule":
1621
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_schedule', false);
1622
- break;
1623
- case "remote":
1624
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_remote_storage', false);
1625
- break;
1626
- case "website":
1627
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_debug', false);
1628
- break;
1629
- case "log":
1630
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_log', false);
1631
- break;
1632
- case "key":
1633
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_key', false);
1634
- break;
1635
- default:
1636
- wpvivid_click_switch_page('wrap', 'wpvivid_tab_general', false);
1637
- break;
1638
- }
1639
- }
1640
-
1641
  function wpvivid_click_switch_page(tab, type, scroll){
1642
  jQuery('.'+tab+'-tab-content:not(.' + type + ')').hide();
1643
  jQuery('.'+tab+'-tab-content.' + type).show();
@@ -1655,1153 +659,6 @@ function wpvivid_close_tab(event, hide_tab, type, show_tab){
1655
  wpvivid_click_switch_page(type, show_tab, true);
1656
  }
1657
 
1658
- /**
1659
- * Retrieve the list of logs from the Log tab.
1660
- */
1661
- function wpvivid_retrieve_log_list(){
1662
- var ajax_data = {
1663
- 'action': 'wpvivid_get_log_list'
1664
- };
1665
- wpvivid_post_request(ajax_data, function(data){
1666
- try {
1667
- var jsonarray = jQuery.parseJSON(data);
1668
- if (jsonarray.result === "success") {
1669
- jQuery('#wpvivid_loglist').html("");
1670
- jQuery('#wpvivid_loglist').append(jsonarray.html);
1671
- wpvivid_log_count = jsonarray.log_count;
1672
- wpvivid_display_log_page();
1673
- }
1674
- }
1675
- catch(err){
1676
- alert(err);
1677
- }
1678
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1679
- setTimeout(function () {
1680
- wpvivid_retrieve_log_list();
1681
- }, 3000);
1682
- });
1683
- }
1684
-
1685
- /**
1686
- * Set a default remote storage for backups.
1687
- */
1688
- function wpvivid_set_default_remote_storage(){
1689
- var remote_storage = new Array();
1690
- //remote_storage[0] = jQuery("input[name='remote_storage']:checked").val();
1691
- jQuery.each(jQuery("input[name='remote_storage']:checked"), function()
1692
- {
1693
- remote_storage.push(jQuery(this).val());
1694
- });
1695
-
1696
- var ajax_data = {
1697
- 'action': 'wpvivid_set_default_remote_storage',
1698
- 'remote_storage': remote_storage
1699
- };
1700
- jQuery('#wpvivid_remote_notice').html('');
1701
- wpvivid_post_request(ajax_data, function(data){
1702
- wpvivid_handle_remote_storage_data(data);
1703
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1704
- var error_message = wpvivid_output_ajaxerror('setting up the default remote storage', textStatus, errorThrown);
1705
- alert(error_message);
1706
- });
1707
- }
1708
-
1709
- function wpvivid_pre_log_page(){
1710
- if(wpvivid_cur_log_page > 1){
1711
- wpvivid_cur_log_page--;
1712
- }
1713
- wpvivid_display_log_page();
1714
- }
1715
-
1716
- function wpvivid_next_log_page(){
1717
- var display_count = jQuery("#wpvivid_display_log_count option:selected").val();
1718
- var max_pages=Math.ceil(wpvivid_log_count/display_count);
1719
- if(wpvivid_cur_log_page < max_pages){
1720
- wpvivid_cur_log_page++;
1721
- }
1722
- wpvivid_display_log_page();
1723
- }
1724
-
1725
- function wpvivid_display_log_page(){
1726
- var display_count = jQuery("#wpvivid_display_log_count option:selected").val();
1727
- var max_pages=Math.ceil(wpvivid_log_count/display_count);
1728
- if(max_pages == 0) max_pages = 1;
1729
- jQuery('#wpvivid_log_page_info').html(wpvivid_cur_log_page+ " / "+max_pages);
1730
-
1731
- var begin = (wpvivid_cur_log_page - 1) * display_count;
1732
- var end = parseInt(begin) + parseInt(display_count);
1733
- jQuery("#wpvivid_loglist tr").hide();
1734
- jQuery('#wpvivid_loglist tr').each(function(i){
1735
- if (i >= begin && i < end)
1736
- {
1737
- jQuery(this).show();
1738
- }
1739
- });
1740
- }
1741
-
1742
- /**
1743
- * Set a lock for backups.
1744
- *
1745
- * @param backup_id - An unique ID for the backup
1746
- * @param lock_status - Current lock status
1747
- */
1748
- function wpvivid_set_backup_lock(backup_id, lock_status){
1749
- if(lock_status === "lock"){
1750
- var lock=0;
1751
- }
1752
- else{
1753
- var lock=1;
1754
- }
1755
- var ajax_data={
1756
- 'action': 'wpvivid_set_security_lock',
1757
- 'backup_id': backup_id,
1758
- 'lock': lock
1759
- };
1760
- wpvivid_post_request(ajax_data, function(data) {
1761
- try {
1762
- var jsonarray = jQuery.parseJSON(data);
1763
- if (jsonarray.result === 'success') {
1764
- jQuery('#wpvivid_lock_'+backup_id).html(jsonarray.html);
1765
- }
1766
- }
1767
- catch(err){
1768
- alert(err);
1769
- }
1770
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1771
- var error_message = wpvivid_output_ajaxerror('setting up a lock for the backup', textStatus, errorThrown);
1772
- alert(error_message);
1773
- });
1774
- }
1775
-
1776
- function wpvivid_initialize_restore(backup_id, backup_time, backup_type, restore_type='backup'){
1777
- var time_type = 'backup';
1778
- var log_type = '';
1779
- var tab_type = '';
1780
- var page_type = 'backup';
1781
- if(restore_type == 'backup'){
1782
- time_type = 'backup';
1783
- log_type = '';
1784
- tab_type = '';
1785
- page_type = 'backup';
1786
- }
1787
- else if(restore_type == 'transfer'){
1788
- time_type = 'transfer';
1789
- log_type = 'transfer_';
1790
- tab_type = 'add_';
1791
- page_type = 'migrate';
1792
- }
1793
- wpvivid_restore_backup_type = backup_type;
1794
- jQuery('#wpvivid_restore_'+time_type+'_time').html(backup_time);
1795
- m_restore_backup_id = backup_id;
1796
- jQuery('#wpvivid_restore_'+log_type+'log').html("");
1797
- jQuery('#wpvivid_'+tab_type+'tab_restore').show();
1798
- wpvivid_click_switch_page(page_type, 'wpvivid_'+tab_type+'tab_restore', true);
1799
- wpvivid_init_restore_data(restore_type);
1800
- }
1801
-
1802
- function click_dismiss_restore_check_notice(obj){
1803
- wpvivid_display_restore_check = false;
1804
- jQuery(obj).parent().remove();
1805
- }
1806
-
1807
- /**
1808
- * This function will initialize restore information
1809
- *
1810
- * @param backup_id - The unique ID for the backup
1811
- */
1812
- function wpvivid_init_restore_data(restore_type)
1813
- {
1814
- wpvivid_resotre_is_migrate=0;
1815
- var restore_method = '';
1816
- if(restore_type == 'backup'){
1817
- restore_method = '';
1818
- }
1819
- else if(restore_type == 'transfer'){
1820
- restore_method = 'transfer_';
1821
- }
1822
- jQuery('#wpvivid_replace_domain').prop('checked', false);
1823
- jQuery('#wpvivid_keep_domain').prop('checked', false);
1824
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1825
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1826
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1827
- jQuery('#wpvivid_download_'+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
- jQuery('#wpvivid_download_'+restore_method+'part').hide();
1832
- /*if(wpvivid_restore_backup_type == 'Migration' || wpvivid_restore_backup_type == 'Upload') {
1833
- jQuery('#wpvivid_restore_is_migrate').show();
1834
- jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'none', 'opacity': '0.4'});
1835
- }
1836
- else{
1837
- jQuery('#wpvivid_restore_is_migrate').hide();
1838
- }*/
1839
- jQuery('#wpvivid_init_restore_data').addClass('is-active');
1840
- var ajax_data = {
1841
- 'action':'wpvivid_init_restore_page',
1842
- 'backup_id':m_restore_backup_id
1843
- };
1844
- wpvivid_post_request(ajax_data, function(data){
1845
- try {
1846
- var jsonarray = jQuery.parseJSON(data);
1847
- var init_status = false;
1848
- if(jsonarray.result === 'success') {
1849
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1850
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1851
- jQuery('#wpvivid_restore_'+restore_method+'part').show();
1852
- jQuery('#wpvivid_download_'+restore_method+'part').hide();
1853
- wpvivid_restore_need_download = false;
1854
- init_status = true;
1855
- }
1856
- else if (jsonarray.result === "need_download"){
1857
- init_status = true;
1858
- wpvivid_restore_download_array = new Array();
1859
- var download_num = 0;
1860
- jQuery.each(jsonarray.files, function (index, value)
1861
- {
1862
- if (value.status === "need_download")
1863
- {
1864
- wpvivid_restore_download_array[download_num] = new Array('file_name', 'size', 'md5');
1865
- wpvivid_restore_download_array[download_num]['file_name'] = index;
1866
- wpvivid_restore_download_array[download_num]['size'] = value.size;
1867
- wpvivid_restore_download_array[download_num]['md5'] = value.md5;
1868
- download_num++;
1869
- }
1870
- });
1871
- wpvivid_restore_download_index=0;
1872
- wpvivid_restore_need_download = true;
1873
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1874
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1875
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1876
- jQuery('#wpvivid_download_'+restore_method+'part').show();
1877
- }
1878
- else if (jsonarray.result === "failed") {
1879
- jQuery('#wpvivid_init_restore_data').removeClass('is-active');
1880
- wpvivid_display_restore_msg(jsonarray.error, restore_type);
1881
- }
1882
-
1883
- if(init_status){
1884
- if(jsonarray.max_allow_packet_warning != false || jsonarray.memory_limit_warning != false) {
1885
- if(!wpvivid_display_restore_check) {
1886
- wpvivid_display_restore_check = true;
1887
- var output = '';
1888
- if(jsonarray.max_allow_packet_warning != false){
1889
- output += "<p>" + jsonarray.max_allow_packet_warning + "</p>";
1890
- }
1891
- if(jsonarray.memory_limit != false){
1892
- output += "<p>" + jsonarray.memory_limit_warning + "</p>";
1893
- }
1894
- var div = "<div class='notice notice-warning is-dismissible inline'>" +
1895
- output +
1896
- "<button type='button' class='notice-dismiss' onclick='click_dismiss_restore_check_notice(this);'>" +
1897
- "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1898
- "</button>" +
1899
- "</div>";
1900
- jQuery('#wpvivid_restore_check').append(div);
1901
- }
1902
- }
1903
- jQuery('#wpvivid_init_restore_data').removeClass('is-active');
1904
- if (jsonarray.has_exist_restore === 0) {
1905
- if(wpvivid_restore_need_download == false) {
1906
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1907
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1908
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1909
- jQuery('#wpvivid_restore_' + restore_method + 'part').show();
1910
- jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
1911
- jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
1912
- jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
1913
-
1914
- jQuery('#wpvivid_restore_is_migrate').hide();
1915
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1916
-
1917
- wpvivid_resotre_is_migrate = jsonarray.is_migrate;
1918
-
1919
- if (jsonarray.is_migrate_ui === 1) {
1920
- jQuery('#wpvivid_restore_is_migrate').show()
1921
- jQuery('#wpvivid_replace_domain').prop('checked', false);
1922
- jQuery('#wpvivid_keep_domain').prop('checked', false);
1923
- }
1924
- else {
1925
- jQuery('#wpvivid_restore_is_migrate').hide();
1926
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1927
- }
1928
-
1929
- wpvivid_interface_flow_control();
1930
- }
1931
- }
1932
- else if (jsonarray.has_exist_restore === 1) {
1933
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1934
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'auto', 'opacity': '1'});
1935
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1936
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1937
- jQuery('#wpvivid_clean_'+restore_method+'part').show();
1938
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1939
- jQuery('#wpvivid_restore_is_migrate').hide();
1940
- wpvivid_display_restore_msg("An uncompleted restore task exists, please terminate it first.", restore_type);
1941
- }
1942
- }
1943
- }
1944
- catch(err){
1945
- alert(err);
1946
- }
1947
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1948
- jQuery('#wpvivid_init_restore_data').removeClass('is-active');
1949
- var error_message = wpvivid_output_ajaxerror('initializing restore information', textStatus, errorThrown);
1950
- wpvivid_display_restore_msg(error_message, restore_type);
1951
- });
1952
- }
1953
-
1954
- function wpvivid_restore_is_migrate(restore_type){
1955
- var ajax_data = {
1956
- 'action': 'wpvivid_get_restore_file_is_migrate',
1957
- 'backup_id': m_restore_backup_id
1958
- };
1959
- var restore_method = '';
1960
- wpvivid_post_request(ajax_data, function(data)
1961
- {
1962
- try
1963
- {
1964
- var jsonarray = jQuery.parseJSON(data);
1965
- if(jsonarray.result === "success")
1966
- {
1967
- if (jsonarray.is_migrate_ui === 1)
1968
- {
1969
- jQuery('#wpvivid_restore_is_migrate').show();
1970
- jQuery('#wpvivid_replace_domain').prop('checked', false);
1971
- jQuery('#wpvivid_keep_domain').prop('checked', false);
1972
- }
1973
- else {
1974
- jQuery('#wpvivid_restore_is_migrate').hide();
1975
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1976
- }
1977
- }
1978
- else if (jsonarray.result === "failed") {
1979
- jQuery('#wpvivid_init_restore_data').removeClass('is-active');
1980
- wpvivid_display_restore_msg(jsonarray.error, restore_type);
1981
- }
1982
- }
1983
- catch(err){
1984
- alert(err);
1985
- }
1986
- }, function(XMLHttpRequest, textStatus, errorThrown)
1987
- {
1988
- setTimeout(function()
1989
- {
1990
- wpvivid_restore_is_migrate(restore_type);
1991
- }, 3000);
1992
- });
1993
- }
1994
-
1995
- /**
1996
- * This function will start the process of restoring a backup
1997
- */
1998
- function wpvivid_start_restore(restore_type = 'backup'){
1999
- if(!wpvivid_restore_sure){
2000
- var descript = 'Are you sure to continue?';
2001
- var ret = confirm(descript);
2002
- }
2003
- else{
2004
- ret = true;
2005
- }
2006
- if (ret === true) {
2007
- wpvivid_restore_sure = true;
2008
- var restore_method = '';
2009
- if (restore_type == 'backup') {
2010
- restore_method = '';
2011
- }
2012
- else if (restore_type == 'transfer') {
2013
- restore_method = 'transfer_';
2014
- }
2015
- jQuery('#wpvivid_restore_' + restore_method + 'log').html("");
2016
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2017
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2018
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2019
- jQuery('#wpvivid_restore_' + restore_method + 'part').show();
2020
- jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
2021
- jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
2022
- wpvivid_restore_lock();
2023
- wpvivid_restoring = true;
2024
- if (wpvivid_restore_need_download) {
2025
- wpvivid_download_restore_file(restore_type);
2026
- }
2027
- else {
2028
- wpvivid_monitor_restore_task(restore_type);
2029
- if(wpvivid_resotre_is_migrate==0)
2030
- {
2031
- jQuery('input:radio[option=restore]').each(function()
2032
- {
2033
- if(jQuery(this).prop('checked'))
2034
- {
2035
- var value = jQuery(this).prop('value');
2036
- if(value == '1')
2037
- {
2038
- wpvivid_resotre_is_migrate = '1';
2039
- }
2040
- }
2041
- });
2042
- }
2043
-
2044
- wpvivid_restore(restore_type);
2045
- }
2046
- }
2047
- }
2048
-
2049
- function wpvivid_download_restore_file(restore_type)
2050
- {
2051
- var restore_method = '';
2052
- if(restore_type == 'backup'){
2053
- restore_method = '';
2054
- }
2055
- else if(restore_type == 'transfer'){
2056
- restore_method = 'transfer_';
2057
- }
2058
-
2059
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2060
- wpvivid_restore_lock();
2061
- if(wpvivid_restore_download_array.length===0)
2062
- {
2063
- 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);
2064
- wpvivid_restore_unlock();
2065
- return false;
2066
- }
2067
-
2068
- if(wpvivid_restore_download_index+1>wpvivid_restore_download_array.length)
2069
- {
2070
- wpvivid_display_restore_msg("Download succeeded.", restore_type);
2071
- wpvivid_restore_is_migrate(restore_type);
2072
- wpvivid_restore_need_download = false;
2073
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2074
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2075
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2076
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2077
- jQuery('#wpvivid_restore_' + restore_method + 'part').show();
2078
- jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
2079
- jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
2080
- jQuery('#wpvivid_download_'+restore_method+'part').hide();
2081
- //wpvivid_start_restore(restore_type);
2082
- }
2083
- else
2084
- {
2085
- wpvivid_display_restore_msg("Downloading backup file " + wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'], restore_type);
2086
- wpvivid_display_restore_msg('', restore_type, wpvivid_restore_download_index);
2087
- var ajax_data = {
2088
- 'action': 'wpvivid_download_restore',
2089
- 'backup_id': m_restore_backup_id,
2090
- 'file_name': wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],
2091
- 'size': wpvivid_restore_download_array[wpvivid_restore_download_index]['size'],
2092
- 'md5': wpvivid_restore_download_array[wpvivid_restore_download_index]['md5']
2093
- }
2094
- wpvivid_get_download_restore_progress_retry=0;
2095
- wpvivid_monitor_download_restore_task(restore_type);
2096
- wpvivid_post_request(ajax_data, function (data) {
2097
- }, function (XMLHttpRequest, textStatus, errorThrown) {
2098
- }, 0);
2099
- }
2100
- }
2101
-
2102
- function wpvivid_monitor_download_restore_task(restore_type)
2103
- {
2104
- var restore_method = '';
2105
- if(restore_type == 'backup'){
2106
- restore_method = '';
2107
- }
2108
- else if(restore_type == 'transfer'){
2109
- restore_method = 'transfer_';
2110
- }
2111
-
2112
- var ajax_data={
2113
- 'action':'wpvivid_get_download_restore_progress',
2114
- 'file_name': wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],
2115
- 'size': wpvivid_restore_download_array[wpvivid_restore_download_index]['size'],
2116
- 'md5': wpvivid_restore_download_array[wpvivid_restore_download_index]['md5']
2117
- };
2118
-
2119
- wpvivid_post_request(ajax_data, function(data)
2120
- {
2121
- try
2122
- {
2123
- var jsonarray = jQuery.parseJSON(data);
2124
- if(typeof jsonarray ==='object')
2125
- {
2126
- if(jsonarray.result === "success")
2127
- {
2128
- if(jsonarray.status==='completed')
2129
- {
2130
- wpvivid_display_restore_msg(wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'] + ' download succeeded.', restore_type, wpvivid_restore_download_index, false);
2131
- wpvivid_restore_download_index++;
2132
- wpvivid_download_restore_file(restore_type);
2133
- wpvivid_restore_unlock();
2134
- }
2135
- else if(jsonarray.status==='error')
2136
- {
2137
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2138
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2139
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2140
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2141
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
2142
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
2143
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2144
- jQuery('#wpvivid_download_'+restore_method+'part').show();
2145
- var error_message = jsonarray.error;
2146
- wpvivid_display_restore_msg(error_message,restore_type,wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],false);
2147
- wpvivid_restore_unlock();
2148
- }
2149
- else if(jsonarray.status==='running')
2150
- {
2151
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2152
- wpvivid_display_restore_msg(jsonarray.log, restore_type, wpvivid_restore_download_index, false);
2153
- setTimeout(function()
2154
- {
2155
- wpvivid_monitor_download_restore_task(restore_type);
2156
- }, 3000);
2157
- wpvivid_restore_lock();
2158
- }
2159
- else if(jsonarray.status==='timeout')
2160
- {
2161
- wpvivid_get_download_restore_progress_retry++;
2162
- if(wpvivid_get_download_restore_progress_retry>10)
2163
- {
2164
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2165
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2166
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2167
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2168
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
2169
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
2170
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2171
- jQuery('#wpvivid_download_'+restore_method+'part').show();
2172
- var error_message = jsonarray.error;
2173
- wpvivid_display_restore_msg(error_message, restore_type);
2174
- wpvivid_restore_unlock();
2175
- }
2176
- else
2177
- {
2178
- setTimeout(function()
2179
- {
2180
- wpvivid_monitor_download_restore_task(restore_type);
2181
- }, 3000);
2182
- }
2183
- }
2184
- else
2185
- {
2186
- setTimeout(function()
2187
- {
2188
- wpvivid_monitor_download_restore_task(restore_type);
2189
- }, 3000);
2190
- }
2191
- }
2192
- else
2193
- {
2194
- wpvivid_get_download_restore_progress_retry++;
2195
- if(wpvivid_get_download_restore_progress_retry>10)
2196
- {
2197
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2198
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2199
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2200
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2201
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
2202
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
2203
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2204
- jQuery('#wpvivid_download_'+restore_method+'part').show();
2205
- var error_message = jsonarray.error;
2206
- wpvivid_display_restore_msg(error_message, restore_type);
2207
- wpvivid_restore_unlock();
2208
- }
2209
- else
2210
- {
2211
- setTimeout(function()
2212
- {
2213
- wpvivid_monitor_download_restore_task(restore_type);
2214
- }, 3000);
2215
- }
2216
- }
2217
- }
2218
- else
2219
- {
2220
- setTimeout(function()
2221
- {
2222
- wpvivid_monitor_download_restore_task(restore_type);
2223
- }, 3000);
2224
- }
2225
- }
2226
- catch(err){
2227
- setTimeout(function()
2228
- {
2229
- wpvivid_monitor_download_restore_task(restore_type);
2230
- }, 3000);
2231
- }
2232
- }, function(XMLHttpRequest, textStatus, errorThrown)
2233
- {
2234
- setTimeout(function()
2235
- {
2236
- wpvivid_monitor_download_restore_task(restore_type);
2237
- }, 1000);
2238
- });
2239
- }
2240
-
2241
- /**
2242
- * Monitor restore task.
2243
- */
2244
- function wpvivid_monitor_restore_task(restore_type){
2245
- var restore_method = '';
2246
- if(restore_type == 'backup'){
2247
- restore_method = '';
2248
- }
2249
- else if(restore_type == 'transfer'){
2250
- restore_method = 'transfer_';
2251
- }
2252
-
2253
- var ajax_data={
2254
- 'action':'wpvivid_get_restore_progress',
2255
- 'wpvivid_restore' : '1',
2256
- };
2257
-
2258
- if(wpvivid_restore_timeout){
2259
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2260
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
2261
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2262
- jQuery('#wpvivid_restore_'+restore_method+'part').show();
2263
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
2264
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2265
- wpvivid_restore_unlock();
2266
- wpvivid_restoring = false;
2267
- wpvivid_display_restore_msg("Website restore times out.", restore_type);
2268
- }
2269
- else {
2270
- wpvivid_post_request(ajax_data, function (data) {
2271
- try {
2272
- var jsonarray = jQuery.parseJSON(data);
2273
- if (typeof jsonarray === 'object') {
2274
- if (jsonarray.result === "success") {
2275
- jQuery('#wpvivid_restore_' + restore_method + 'log').html("");
2276
- while (jsonarray.log.indexOf('\n') >= 0) {
2277
- var iLength = jsonarray.log.indexOf('\n');
2278
- var log = jsonarray.log.substring(0, iLength);
2279
- jsonarray.log = jsonarray.log.substring(iLength + 1);
2280
- var insert_log = "<div style=\"clear:both;\">" + log + "</div>";
2281
- jQuery('#wpvivid_restore_' + restore_method + 'log').append(insert_log);
2282
- var div = jQuery('#wpvivid_restore_' + restore_method + 'log');
2283
- div[0].scrollTop = div[0].scrollHeight;
2284
- }
2285
-
2286
- if (jsonarray.status === 'wait') {
2287
- wpvivid_restoring = true;
2288
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({
2289
- 'pointer-events': 'none',
2290
- 'opacity': '0.4'
2291
- });
2292
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({
2293
- 'pointer-events': 'none',
2294
- 'opacity': '0.4'
2295
- });
2296
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({
2297
- 'pointer-events': 'none',
2298
- 'opacity': '0.4'
2299
- });
2300
- jQuery('#wpvivid_restore_' + restore_method + 'part').show();
2301
- jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
2302
- jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
2303
- wpvivid_restore(restore_type);
2304
- setTimeout(function () {
2305
- wpvivid_monitor_restore_task(restore_type);
2306
- }, 1000);
2307
- }
2308
- else if (jsonarray.status === 'completed') {
2309
- wpvivid_restoring = false;
2310
- wpvivid_restore(restore_type);
2311
- wpvivid_restore_unlock();
2312
- alert("Restore completed successfully.");
2313
- location.reload();
2314
- }
2315
- else if (jsonarray.status === 'error') {
2316
- wpvivid_restore_unlock();
2317
- wpvivid_restoring = false;
2318
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2319
- alert("Restore failed.");
2320
- }
2321
- else {
2322
- setTimeout(function () {
2323
- wpvivid_monitor_restore_task(restore_type);
2324
- }, 1000);
2325
- }
2326
- }
2327
- else {
2328
- setTimeout(function () {
2329
- wpvivid_monitor_restore_task(restore_type);
2330
- }, 1000);
2331
- }
2332
- }
2333
- else {
2334
- setTimeout(function () {
2335
- wpvivid_monitor_restore_task(restore_type);
2336
- }, 1000);
2337
- }
2338
- }
2339
- catch (err) {
2340
- setTimeout(function () {
2341
- wpvivid_monitor_restore_task(restore_type);
2342
- }, 1000);
2343
- }
2344
- }, function (XMLHttpRequest, textStatus, errorThrown) {
2345
- setTimeout(function () {
2346
- wpvivid_monitor_restore_task(restore_type);
2347
- }, 1000);
2348
- });
2349
- }
2350
- }
2351
-
2352
- function wpvivid_restore(restore_type){
2353
- var restore_method = '';
2354
- if(restore_type == 'backup'){
2355
- restore_method = '';
2356
- }
2357
- else if(restore_type == 'transfer'){
2358
- restore_method = 'transfer_';
2359
- }
2360
-
2361
- var skip_old_site = '1';
2362
- var extend_option = {
2363
- 'skip_backup_old_site':skip_old_site,
2364
- 'skip_backup_old_database':skip_old_site
2365
- };
2366
-
2367
- var migrate_option = {
2368
- 'is_migrate':wpvivid_resotre_is_migrate,
2369
- };
2370
- jQuery.extend(extend_option, migrate_option);
2371
-
2372
- var restore_options = {
2373
- 0:'backup_db',
2374
- 1:'backup_themes',
2375
- 2:'backup_plugin',
2376
- 3:'backup_uploads',
2377
- 4:'backup_content',
2378
- 5:'backup_core'
2379
- };
2380
- jQuery.extend(restore_options, extend_option);
2381
- var json = JSON.stringify(restore_options);
2382
- var ajax_data={
2383
- 'action':'wpvivid_restore',
2384
- 'wpvivid_restore':'1',
2385
- 'backup_id':m_restore_backup_id,
2386
- 'restore_options':json
2387
- };
2388
- setTimeout(function () {
2389
- wpvivid_restore_timeout = true;
2390
- }, 1800000);
2391
- wpvivid_post_request(ajax_data, function(data) {
2392
- }, function(XMLHttpRequest, textStatus, errorThrown) {
2393
- });
2394
- }
2395
-
2396
- function wpvivid_display_restore_msg(msg, restore_type, div_id, append = true){
2397
- var restore_method = '';
2398
- if(restore_type == 'backup'){
2399
- restore_method = '';
2400
- }
2401
- else if(restore_type == 'transfer'){
2402
- restore_method = 'transfer_';
2403
- }
2404
-
2405
- if(typeof div_id == 'undefined') {
2406
- var restore_msg = "<div style=\"clear:both;\">" + msg + "</div>";
2407
- }
2408
- else{
2409
- var restore_msg = "<div id=\"restore_file_"+div_id+"\" style=\"clear:both;\">" + msg + "</div>";
2410
- }
2411
- if(append == true) {
2412
- jQuery('#wpvivid_restore_'+restore_method+'log').append(restore_msg);
2413
- }
2414
- else{
2415
- if(jQuery('#restore_file_'+div_id).length )
2416
- {
2417
- jQuery('#restore_file_'+div_id).html(msg);
2418
- }
2419
- else
2420
- {
2421
- jQuery('#wpvivid_restore_'+restore_method+'log').append(restore_msg);
2422
- }
2423
- }
2424
- var div = jQuery('#wpvivid_restore_' + restore_method + 'log');
2425
- div[0].scrollTop = div[0].scrollHeight;
2426
- }
2427
-
2428
- /**
2429
- * Delete the last incomplete restore task.
2430
- */
2431
- function wpvivid_delete_incompleted_restore(restore_type = 'backup'){
2432
- var restore_method = '';
2433
- if(restore_type == 'backup'){
2434
- restore_method = '';
2435
- }
2436
- else if(restore_type == 'transfer'){
2437
- restore_method = 'transfer_';
2438
- }
2439
-
2440
- var ajax_data={
2441
- 'action': 'wpvivid_delete_last_restore_data'
2442
- };
2443
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2444
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'auto', 'opacity': '1'});
2445
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2446
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
2447
- jQuery('#wpvivid_clean_'+restore_method+'part').show();
2448
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
2449
- wpvivid_post_request(ajax_data, function(data) {
2450
- try {
2451
- var jsonarray = jQuery.parseJSON(data);
2452
- if (jsonarray.result === "success") {
2453
- wpvivid_display_restore_msg("The restore task is terminated.", restore_type);
2454
- wpvivid_init_restore_data(restore_type);
2455
- }
2456
- }
2457
- catch(err){
2458
- alert(err);
2459
- }
2460
- }, function(XMLHttpRequest, textStatus, errorThrown) {
2461
- var error_message = wpvivid_output_ajaxerror('deleting the last incomplete restore task', textStatus, errorThrown);
2462
- wpvivid_display_restore_msg(error_message, restore_type);
2463
- });
2464
- }
2465
-
2466
- /**
2467
- * This function will start rollback task.
2468
- */
2469
- function wpvivid_start_rollback(restore_type = 'backup'){
2470
- var restore_method = '';
2471
- if(restore_type == 'backup'){
2472
- restore_method = '';
2473
- }
2474
- else if(restore_type == 'transfer'){
2475
- restore_method = 'transfer_';
2476
- }
2477
-
2478
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2479
- wpvivid_monitor_rollback_task(restore_type);
2480
- wpvivid_rollback(restore_type);
2481
- }
2482
-
2483
- function wpvivid_rollback(restore_type){
2484
- var restore_method = '';
2485
- if(restore_type == 'backup'){
2486
- restore_method = '';
2487
- }
2488
- else if(restore_type == 'transfer'){
2489
- restore_method = 'transfer_';
2490
- }
2491
-
2492
- var ajax_data={
2493
- 'action': 'wpvivid_rollback'
2494
- };
2495
- wpvivid_post_request(ajax_data, function(data) {
2496
- try {
2497
- var jsonarray = jQuery.parseJSON(data);
2498
- if (jsonarray.result === "success") {
2499
- wpvivid_display_restore_msg("Rollback completed.", restore_type);
2500
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2501
- }
2502
- else if (jsonarray.result === "failed") {
2503
- wpvivid_display_restore_msg(jsonarray.error, restore_type);
2504
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2505
- }
2506
- }
2507
- catch(err){
2508
- alert(err);
2509
- }
2510
- }, function(XMLHttpRequest, textStatus, errorThrown) {
2511
- var error_message = wpvivid_output_ajaxerror('starting rollbacking', textStatus, errorThrown);
2512
- wpvivid_display_restore_msg(error_message, restore_type);
2513
- });
2514
- }
2515
-
2516
- /**
2517
- * This function will monitor the rollback task.
2518
- */
2519
- function wpvivid_monitor_rollback_task(restore_type){
2520
- var restore_method = '';
2521
- if(restore_type == 'backup'){
2522
- restore_method = '';
2523
- }
2524
- else if(restore_type == 'transfer'){
2525
- restore_method = 'transfer_';
2526
- }
2527
-
2528
- var ajax_data={
2529
- 'action':'wpvivid_get_rollback_progress',
2530
- 'wpvivid_restore':'1',
2531
- };
2532
- wpvivid_post_request(ajax_data, function(data){
2533
- try {
2534
- var jsonarray = jQuery.parseJSON(data);
2535
-
2536
- if(typeof jsonarray ==='object')
2537
- {
2538
- if(jsonarray.result === "success")
2539
- {
2540
- jQuery('#wpvivid_restore_'+restore_method+'log').html("");
2541
- while(jsonarray.log.indexOf('\n') >= 0){
2542
- var iLength = jsonarray.log.indexOf('\n');
2543
- var log = jsonarray.log.substring(0, iLength);
2544
- jsonarray.log = jsonarray.log.substring(iLength+1);
2545
- var insert_log = "<div style=\"clear:both;\">"+log+"</div>";
2546
- jQuery('#wpvivid_restore_'+restore_method+'log').append(insert_log);
2547
- }
2548
-
2549
- if(jsonarray.status==='wait')
2550
- {
2551
- wpvivid_restoring = true;
2552
- wpvivid_rollback(restore_type);
2553
- setTimeout(function()
2554
- {
2555
- wpvivid_monitor_rollback_task(restore_type);
2556
- }, 1000);
2557
- }
2558
- else if(jsonarray.status==='completed')
2559
- {
2560
- wpvivid_restoring = false;
2561
- wpvivid_rollback(restore_type);
2562
- wpvivid_restore_unlock();
2563
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2564
- }
2565
- else if(jsonarray.status==='error')
2566
- {
2567
- wpvivid_restoring = false;
2568
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
2569
- }
2570
- else
2571
- {
2572
- setTimeout(function()
2573
- {
2574
- wpvivid_monitor_rollback_task(restore_type);
2575
- }, 1000);
2576
- }
2577
- }
2578
- else
2579
- {
2580
- setTimeout(function()
2581
- {
2582
- wpvivid_monitor_rollback_task(restore_type);
2583
- }, 1000);
2584
- }
2585
- }
2586
- else
2587
- {
2588
- setTimeout(function()
2589
- {
2590
- wpvivid_monitor_rollback_task(restore_type);
2591
- }, 1000);
2592
- }
2593
- }
2594
- catch(err){
2595
- setTimeout(function()
2596
- {
2597
- wpvivid_monitor_rollback_task(restore_type);
2598
- }, 1000);
2599
- }
2600
- }, function(XMLHttpRequest, textStatus, errorThrown) {
2601
- setTimeout(function()
2602
- {
2603
- wpvivid_monitor_rollback_task(restore_type);
2604
- }, 1000);
2605
- });
2606
- }
2607
-
2608
- /**
2609
- * Lock certain operations while a restore task is running.
2610
- */
2611
- function wpvivid_restore_lock(){
2612
- jQuery('#wpvivid_postbox_backup_percent').css({'pointer-events': 'none', 'opacity': '1'});
2613
- jQuery('#wpvivid_postbox_backup').css({'pointer-events': 'none', 'opacity': '1'});
2614
- jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'none', 'opacity': '1'});
2615
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '1'});
2616
- jQuery('#wpvivid_tab_backup').css({'pointer-events': 'none', 'opacity': '1'});
2617
- jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'none', 'opacity': '1'});
2618
- jQuery('#wpvivid_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
2619
- jQuery('#page-backups').css({'pointer-events': 'none', 'opacity': '1'});
2620
- jQuery('#storage-page').css({'pointer-events': 'none', 'opacity': '1'});
2621
- jQuery('#settings-page').css({'pointer-events': 'none', 'opacity': '1'});
2622
- jQuery('#debug-page').css({'pointer-events': 'none', 'opacity': '1'});
2623
- jQuery('#logs-page').css({'pointer-events': 'none', 'opacity': '1'});
2624
- jQuery('#wpvivid_tab_migrate').css({'pointer-events': 'none', 'opacity': '1'});
2625
- jQuery('#wpvivid_add_tab_migrate').css({'pointer-events': 'none', 'opacity': '1'});
2626
- jQuery('#wpvivid_add_tab_import').css({'pointer-events': 'none', 'opacity': '1'});
2627
- jQuery('#wpvivid_add_tab_key').css({'pointer-events': 'none', 'opacity': '1'});
2628
- jQuery('#wpvivid_add_tab_log').css({'pointer-events': 'none', 'opacity': '1'});
2629
- jQuery('#wpvivid_add_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
2630
- jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'none', 'opacity': '1'});
2631
- jQuery('#wpvivid_replace_domain').css({'pointer-events': 'none', 'opacity': '1'});
2632
- jQuery('#wpvivid_keep_domain').css({'pointer-events': 'none', 'opacity': '1'});
2633
- }
2634
-
2635
- /**
2636
- * Unlock the operations once restore task completed.
2637
- */
2638
- function wpvivid_restore_unlock(){
2639
- jQuery('#wpvivid_postbox_backup_percent').css({'pointer-events': 'auto', 'opacity': '1'});
2640
- jQuery('#wpvivid_postbox_backup').css({'pointer-events': 'auto', 'opacity': '1'});
2641
- jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'auto', 'opacity': '1'});
2642
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2643
- jQuery('#wpvivid_tab_backup').css({'pointer-events': 'auto', 'opacity': '1'});
2644
- jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'auto', 'opacity': '1'});
2645
- jQuery('#wpvivid_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
2646
- jQuery('#page-backups').css({'pointer-events': 'auto', 'opacity': '1'});
2647
- jQuery('#storage-page').css({'pointer-events': 'auto', 'opacity': '1'});
2648
- jQuery('#settings-page').css({'pointer-events': 'auto', 'opacity': '1'});
2649
- jQuery('#debug-page').css({'pointer-events': 'auto', 'opacity': '1'});
2650
- jQuery('#logs-page').css({'pointer-events': 'auto', 'opacity': '1'});
2651
- jQuery('#wpvivid_tab_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
2652
- jQuery('#wpvivid_add_tab_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
2653
- jQuery('#wpvivid_add_tab_import').css({'pointer-events': 'auto', 'opacity': '1'});
2654
- jQuery('#wpvivid_add_tab_key').css({'pointer-events': 'auto', 'opacity': '1'});
2655
- jQuery('#wpvivid_add_tab_log').css({'pointer-events': 'auto', 'opacity': '1'});
2656
- jQuery('#wpvivid_add_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
2657
- jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
2658
- jQuery('#wpvivid_replace_domain').css({'pointer-events': 'auto', 'opacity': '1'});
2659
- jQuery('#wpvivid_keep_domain').css({'pointer-events': 'auto', 'opacity': '1'});
2660
- }
2661
-
2662
- /**
2663
- * This function will delete out of date backups.
2664
- */
2665
- function wpvivid_delete_out_of_date_backups(){
2666
- var ajax_data={
2667
- 'action': 'wpvivid_clean_out_of_date_backup'
2668
- };
2669
- jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'none', 'opacity': '0.4'});
2670
- wpvivid_post_request(ajax_data, function(data){
2671
- jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
2672
- try {
2673
- var jsonarray = jQuery.parseJSON(data);
2674
- if (jsonarray.result === "success") {
2675
- alert("Out of date backups have been removed.");
2676
- wpvivid_handle_backup_data(data);
2677
- }
2678
- }
2679
- catch(err){
2680
- alert(err);
2681
- jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
2682
- }
2683
- }, function(XMLHttpRequest, textStatus, errorThrown) {
2684
- var error_message = wpvivid_output_ajaxerror('deleting out of date backups', textStatus, errorThrown);
2685
- alert(error_message);
2686
- jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
2687
- });
2688
- }
2689
-
2690
- /**
2691
- * Calculate the server disk space in use by WPvivid.
2692
- */
2693
- function wpvivid_calculate_diskspaceused(){
2694
- var ajax_data={
2695
- 'action': 'wpvivid_junk_files_info'
2696
- };
2697
- var current_size = jQuery('#wpvivid_junk_sum_size').html();
2698
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'none', 'opacity': '0.4'});
2699
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'none', 'opacity': '0.4'});
2700
- jQuery('#wpvivid_junk_sum_size').html("calculating...");
2701
- wpvivid_post_request(ajax_data, function(data){
2702
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
2703
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
2704
- try {
2705
- var jsonarray = jQuery.parseJSON(data);
2706
- if (jsonarray.result === "success") {
2707
- jQuery('#wpvivid_junk_sum_size').html(jsonarray.data.sum_size);
2708
- jQuery('#wpvivid_junk_log_path').html(jsonarray.data.log_path);
2709
- jQuery('#wpvivid_junk_file_path').html(jsonarray.data.junk_path);
2710
- jQuery('#wpvivid_restore_temp_file_path').html(jsonarray.data.old_files_path);
2711
- }
2712
- }
2713
- catch(err){
2714
- alert(err);
2715
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
2716
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
2717
- jQuery('#wpvivid_junk_sum_size').html(current_size);
2718
- }
2719
- }, function(XMLHttpRequest, textStatus, errorThrown) {
2720
- var error_message = wpvivid_output_ajaxerror('calculating server disk space in use by WPvivid', textStatus, errorThrown);
2721
- alert(error_message);
2722
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
2723
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
2724
- jQuery('#wpvivid_junk_sum_size').html(current_size);
2725
- });
2726
- }
2727
-
2728
- /**
2729
- * Clean junk files created during backups and restorations off your web server disk.
2730
- */
2731
- function wpvivid_clean_junk_files(){
2732
- var descript = 'The selected item(s) will be permanently deleted. Are you sure you want to continue?';
2733
- var ret = confirm(descript);
2734
- if(ret === true){
2735
- var option_data = wpvivid_ajax_data_transfer('junk-files');
2736
- var ajax_data = {
2737
- 'action': 'wpvivid_clean_local_storage',
2738
- 'options': option_data
2739
- };
2740
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'none', 'opacity': '0.4'});
2741
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'none', 'opacity': '0.4'});
2742
- wpvivid_post_request(ajax_data, function (data) {
2743
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
2744
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
2745
- jQuery('input[option="junk-files"]').prop('checked', false);
2746
- try {
2747
- var jsonarray = jQuery.parseJSON(data);
2748
- alert(jsonarray.msg);
2749
- if (jsonarray.result === "success") {
2750
- jQuery('#wpvivid_junk_sum_size').html(jsonarray.data.sum_size);
2751
- jQuery('#wpvivid_junk_log_path').html(jsonarray.data.log_path);
2752
- jQuery('#wpvivid_junk_file_path').html(jsonarray.data.junk_path);
2753
- jQuery('#wpvivid_restore_temp_file_path').html(jsonarray.data.old_files_path);
2754
- jQuery('#wpvivid_loglist').html("");
2755
- jQuery('#wpvivid_loglist').append(jsonarray.html);
2756
- wpvivid_log_count = jsonarray.log_count;
2757
- wpvivid_display_log_page();
2758
- }
2759
- }
2760
- catch(err){
2761
- alert(err);
2762
- }
2763
- }, function (XMLHttpRequest, textStatus, errorThrown) {
2764
- var error_message = wpvivid_output_ajaxerror('cleaning out junk files', textStatus, errorThrown);
2765
- alert(error_message);
2766
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
2767
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
2768
- });
2769
- }
2770
- }
2771
-
2772
- /**
2773
- * Download the relevant website info and error logs to your PC for debugging purposes.
2774
- */
2775
- function wpvivid_download_website_info(){
2776
- wpvivid_location_href=true;
2777
- location.href =ajaxurl+'?action=wpvivid_create_debug_package';
2778
- }
2779
-
2780
- function wpvivid_click_send_debug_info(){
2781
- var wpvivid_user_mail = jQuery('#wpvivid_user_mail').val();
2782
- var ajax_data = {
2783
- 'action': 'wpvivid_send_debug_info',
2784
- 'user_mail': wpvivid_user_mail
2785
- };
2786
- wpvivid_post_request(ajax_data, function (data) {
2787
- try {
2788
- var jsonarray = jQuery.parseJSON(data);
2789
- if (jsonarray.result === "success") {
2790
- alert("Send succeeded.");
2791
- }
2792
- else {
2793
- alert(jsonarray.error);
2794
- }
2795
- }
2796
- catch (err) {
2797
- alert(err);
2798
- }
2799
- }, function (XMLHttpRequest, textStatus, errorThrown) {
2800
- var error_message = wpvivid_output_ajaxerror('sending debug information', textStatus, errorThrown);
2801
- alert(error_message);
2802
- });
2803
- }
2804
-
2805
  /**
2806
  * Output ajax error in a standard format.
2807
  *
55
  * practising this, we should strive to set a better example in our own work.
56
  */
57
  $(document).ready(function () {
58
+ //wpvivid_getrequest();
59
 
60
  wpvivid_activate_cron();
61
 
 
 
62
  wpvivid_interface_flow_control();
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
  $('input[option=review]').click(function(){
65
  var name = jQuery(this).prop('name');
66
  wpvivid_add_review_info(name);
171
  });
172
  }
173
  if(jsonarray.backuplist_html != false) {
174
+ jQuery('#wpvivid_backup_list').html('');
175
+ jQuery('#wpvivid_backup_list').append(jsonarray.backuplist_html);
176
  }
177
  var b_has_data = false;
178
  if (jsonarray.backup.data.length !== 0) {
338
  }
339
  }
340
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
341
  function wpvivid_read_log(action, param){
342
  var tab_id = '';
343
  var content_id = '';
431
  }
432
  }
433
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
434
  /**
435
  * Resume the backup task automatically in 1 minute in a timeout situation
436
  *
471
  }
472
 
473
  /**
474
+ * This function will control interface flow.
 
 
 
475
  */
476
+ function wpvivid_interface_flow_control(){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
 
 
 
 
 
 
 
 
478
 
479
+ jQuery('#wpvivid_general_email_enable').click(function(){
480
+ if(jQuery('#wpvivid_general_email_enable').prop('checked') === true){
481
+ jQuery('#wpvivid_general_email_setting').show();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
482
 
483
+ }
484
+ else{
485
+ jQuery('#wpvivid_general_email_setting').hide();
 
 
486
  }
487
  });
 
 
 
 
 
 
 
 
 
 
 
488
 
489
+ jQuery("input[name='schedule-backup-files']").bind("click",function(){
490
+ if(jQuery(this).val() === "custom"){
491
+ jQuery('#wpvivid_choosed_folders').show();
492
+ if(jQuery("input[name='wpvivid-schedule-custom-folders'][value='other']").prop('checked')){
493
+ jQuery('#wpvivid_file_tree_browser').show();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
494
  }
495
+ else{
496
+ jQuery('#wpvivid_file_tree_browser').hide();
 
497
  }
498
  }
499
+ else{
500
+ jQuery('#wpvivid_choosed_folders').hide();
501
+ jQuery('#wpvivid_file_tree_browser').hide();
502
  }
 
 
 
 
503
  });
 
504
 
505
+ jQuery("input[name='wpvivid-schedule-custom-folders']").bind("click",function(){
506
+ if(jQuery("input[name='wpvivid-schedule-custom-folders'][value='other']").prop('checked')){
507
+ jQuery('#wpvivid_file_tree_browser').show();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
508
  }
509
+ else{
510
+ jQuery('#wpvivid_file_tree_browser').hide();
511
  }
 
 
 
512
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
 
514
+ jQuery('#settings-page input[type=checkbox]:not([option=junk-files])').on("change", function(){
515
+ wpvivid_settings_changed = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
516
  });
 
517
 
518
+ jQuery('#settings-page input[type=radio]').on("change", function(){
519
+ wpvivid_settings_changed = true;
520
+ });
 
 
 
 
 
 
 
 
 
 
 
 
521
 
522
+ jQuery('#settings-page input[type=text]').on("keyup", function(){
523
+ wpvivid_settings_changed = true;
524
+ });
 
 
 
 
 
 
 
 
 
 
 
525
 
526
+ jQuery("#wpvivid_storage_account_block input:not([type=checkbox])").on("keyup", function(){
527
+ wpvivid_settings_changed = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
  });
 
529
 
530
+ jQuery('#wpvivid_storage_account_block input[type=checkbox]').on("change", function(){
531
+ wpvivid_settings_changed = true;
532
+ });
 
 
 
 
 
 
 
 
533
 
534
+ jQuery('input:radio[option=restore]').click(function() {
535
+ jQuery('input:radio[option=restore]').each(function () {
536
+ if (jQuery(this).prop('checked')) {
537
+ jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
 
 
538
  }
539
+ });
 
 
 
 
 
 
 
 
540
  });
541
  }
542
 
543
  /**
544
+ * Manage backup and download tasks. Retrieve the data every 3 seconds for checking if the backup or download tasks exist or not.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
545
  */
546
  function wpvivid_manage_task() {
547
  if(m_need_update === true){
627
  jQuery(obj).parent().remove();
628
  }
629
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
630
  function wpvivid_cron_task(){
631
  jQuery.get(wpvivid_siteurl+'/wp-cron.php');
632
  }
633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634
  function wpvivid_clear_notice(notice_id){
635
  var t = document.getElementById(notice_id);
636
  var oDiv = t.getElementsByTagName("div");
642
  jQuery('#'+notice_id).hide();
643
  }
644
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
645
  function wpvivid_click_switch_page(tab, type, scroll){
646
  jQuery('.'+tab+'-tab-content:not(.' + type + ')').hide();
647
  jQuery('.'+tab+'-tab-content.' + type).show();
659
  wpvivid_click_switch_page(type, show_tab, true);
660
  }
661
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
662
  /**
663
  * Output ajax error in a standard format.
664
  *
admin/partials/wpvivid-admin-display.php CHANGED
@@ -24,23 +24,17 @@ if (!defined('WPVIVID_PLUGIN_DIR'))
24
  die;
25
  }
26
 
27
- global $wpvivid_pulgin;
28
- $backuplist=WPvivid_Backuplist::get_backuplist();
29
- $remoteslist=WPvivid_Setting::get_all_remote_options();
30
  $select=WPvivid_Setting::get_user_history('remote_selected');
31
  $schedule=WPvivid_Schedule::get_schedule();
32
  $backupdir=WPvivid_Setting::get_backupdir();
33
  $general_setting=WPvivid_Setting::get_setting(true, "");
34
  $last_msg=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg');
35
- $out_of_date=$wpvivid_pulgin->_get_out_of_date_info();
36
- $junk_file=$wpvivid_pulgin->_junk_files_info();
37
- $website_info=$wpvivid_pulgin->get_website_info();
38
- $loglist=$wpvivid_pulgin->get_log_list_ex();
39
- $default_remote_storage='';
40
- foreach ($remoteslist['remote_selected'] as $value) {
41
- $default_remote_storage=$value;
42
- }
43
- $backup_task=$wpvivid_pulgin->_list_tasks(false);
44
  $wpvivid_version=WPVIVID_PLUGIN_VERSION;
45
 
46
  do_action('show_notice');
@@ -109,6 +103,21 @@ foreach ($page_array as $page_name){
109
  echo apply_filters('wpvivid_schedule_module', $schedule_html);
110
  ?>
111
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  <div class="postbox">
113
  <h2><span>How-to</span></h2>
114
  <div class="inside">
@@ -170,27 +179,44 @@ foreach ($page_array as $page_name){
170
  document.getElementById(contentName).style.display = "block";
171
  evt.currentTarget.className += " nav-tab-active";
172
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
 
174
- var wpvivid_siteurl = '<?php
175
- $wpvivid_siteurl = array();
176
- $wpvivid_siteurl=WPvivid_Admin::wpvivid_get_siteurl();
177
- echo esc_url($wpvivid_siteurl['home_url']);
178
- ?>';
179
- var wpvivid_plugurl = '<?php
180
- echo plugins_url( '', __FILE__ );
181
- ?>';
182
- var wpvivid_log_count = '<?php
183
- _e(sizeof($loglist['log_list']['file']), 'wpvivid');
184
- ?>';
185
- var wpvivid_log_array = '<?php
186
- _e(json_encode($loglist), 'wpvivid');
187
- ?>';
188
- var wpvivid_page_request = '<?php
189
- $page_request = WPvivid_Admin::wpvivid_get_page_request();
190
- _e($page_request, 'wpvivid');
191
- ?>';
192
- var wpvivid_default_remote_storage = '<?php
193
- _e($default_remote_storage, 'wpvivid');
194
- ?>';
195
 
196
  </script>
24
  die;
25
  }
26
 
27
+ global $wpvivid_plugin;
 
 
28
  $select=WPvivid_Setting::get_user_history('remote_selected');
29
  $schedule=WPvivid_Schedule::get_schedule();
30
  $backupdir=WPvivid_Setting::get_backupdir();
31
  $general_setting=WPvivid_Setting::get_setting(true, "");
32
  $last_msg=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg');
33
+ $out_of_date=$wpvivid_plugin->_get_out_of_date_info();
34
+ $junk_file=$wpvivid_plugin->_junk_files_info();
35
+ $website_info=$wpvivid_plugin->get_website_info();
36
+
37
+ $backup_task=$wpvivid_plugin->_list_tasks(false);
 
 
 
 
38
  $wpvivid_version=WPVIVID_PLUGIN_VERSION;
39
 
40
  do_action('show_notice');
103
  echo apply_filters('wpvivid_schedule_module', $schedule_html);
104
  ?>
105
  </div>
106
+ <div class="postbox">
107
+ <h2><span>Troubleshooting</span></h2>
108
+ <div class="inside">
109
+ <table class="widefat" cellpadding="0">
110
+ <tbody>
111
+ <tr class="alternate">
112
+ <td class="row-title">Read <a href="https://wpvivid.com/troubleshooting-issues-wpvivid-backup-plugin" target="_blank">Troubleshooting page</a> for faster solutions.</td>
113
+ </tr>
114
+ <tr>
115
+ <td class="row-title">Adjust <a href="https://wpvivid.com/wpvivid-backup-plugin-advanced-settings.html" target="_blank">Advanced Settings</a> for higher task success rate.</td>
116
+ </tr>
117
+ </tbody>
118
+ </table>
119
+ </div>
120
+ </div>
121
  <div class="postbox">
122
  <h2><span>How-to</span></h2>
123
  <div class="inside">
179
  document.getElementById(contentName).style.display = "block";
180
  evt.currentTarget.className += " nav-tab-active";
181
  }
182
+ function wpvivid_getrequest()
183
+ {
184
+ switch(wpvivid_page_request)
185
+ {
186
+ case "backup":
187
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_general', false);
188
+ break;
189
+ case "transfer":
190
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_migrate', false);
191
+ break;
192
+ case "settings":
193
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_setting', false);
194
+ break;
195
+ case "schedule":
196
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_schedule', false);
197
+ break;
198
+ case "remote":
199
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_remote_storage', false);
200
+ break;
201
+ case "website":
202
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_debug', false);
203
+ break;
204
+ case "log":
205
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_log', false);
206
+ break;
207
+ case "key":
208
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_key', false);
209
+ break;
210
+ default:
211
+ wpvivid_click_switch_page('wrap', 'wpvivid_tab_general', false);
212
+ break;
213
+ }
214
+ }
215
 
216
+ jQuery(document).ready(function ()
217
+ {
218
+ wpvivid_getrequest();
219
+ wpvivid_manage_task();
220
+ });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
  </script>
admin/partials/wpvivid-backup-restore-page-display.php CHANGED
@@ -18,8 +18,8 @@ function wpvivid_add_backup_type($html, $type_name)
18
  }
19
 
20
  function wpvivid_backup_do_js(){
21
- global $wpvivid_pulgin;
22
- $backup_task=$wpvivid_pulgin->_list_tasks(false);
23
  $general_setting=WPvivid_Setting::get_setting(true, "");
24
  if($general_setting['options']['wpvivid_common_setting']['estimate_backup'] == 0){
25
  ?>
@@ -86,102 +86,12 @@ function wpvivid_download_backup_descript($html){
86
  return $html;
87
  }
88
 
89
- function wpvivid_restore_website_dexcript($html){
90
  $html = '<p><a href="#" id="wpvivid_how_to_restore_backup_describe" onclick="wpvivid_click_how_to_restore_backup();">'.__('How to restore your website from a backup(scheduled, manual, uploaded and received backup)', 'wpvivid').'</a></p>';
91
  $html .= '<div id="wpvivid_how_to_restore_backup"></div>';
92
  return $html;
93
  }
94
 
95
- function wpvivid_backup_module($html){
96
- $html = '';
97
- $backup_descript = '';
98
- $backup_part_type = '';
99
- $backup_part_pos = '';
100
- $backup_part_exec = '';
101
- $backup_part_tip = '';
102
- $html .= '
103
- <div class="postbox quickbackup" id="wpvivid_postbox_backup">
104
- '.apply_filters('wpvivid_backup_descript', $backup_descript).'
105
- '.apply_filters('wpvivid_backup_part_type', $backup_part_type).'
106
- '.apply_filters('wpvivid_backup_part_pos', $backup_part_pos).'
107
- '.apply_filters('wpvivid_backup_part_exec', $backup_part_exec).'
108
- '.apply_filters('wpvivid_backup_part_tip', $backup_part_tip).'
109
- </div>
110
- ';
111
- return $html;
112
- }
113
-
114
- function wpvivid_backup_descript($html){
115
- $backupdir=WPvivid_Setting::get_backupdir();
116
- $html .= '<h2><span>'.__( 'Back Up Manually','wpvivid').'</span></h2>
117
- <div class="quickstart-storage-setting">
118
- <span class="list-top-chip backup" name="ismerge" value="1">'.__('Local Storage Directory: ').'</span>
119
- <span class="list-top-chip" id="wpvivid_local_storage_path">'.WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backupdir.'</span>
120
- <span class="list-top-chip" id=""><a href="#" onclick="wpvivid_click_switch_page(\'wrap\', \'wpvivid_tab_setting\', true);">'.__(' rename directory', 'wpvivid').'</a></span>
121
- </div>';
122
- return $html;
123
- }
124
-
125
- function wpvivid_backup_part_type($html){
126
- $backup_type = '';
127
- $type_name = 'backup_files';
128
- $html .= '<div class="quickstart-archive-block">
129
- <fieldset>
130
- <legend class="screen-reader-text"><span>input type="radio"</span></legend>
131
- '.apply_filters('wpvivid_add_backup_type', $backup_type, $type_name).'
132
- <label style="display: none;">
133
- <input type="checkbox" option="backup" name="ismerge" value="1" checked />
134
- </label><br>
135
- </fieldset>
136
- </div>';
137
- return $html;
138
- }
139
-
140
- function wpvivid_backup_part_pos($html){
141
- $pic='';
142
- $html .= '<div class="quickstart-storage-block">
143
- <fieldset>
144
- <legend class="screen-reader-text"><span>input type="checkbox"</span></legend>
145
- <label>
146
- <input type="radio" id="wpvivid_backup_local" option="backup_ex" name="local_remote" value="local" checked />
147
- <span>'.__( 'Save Backups to Local', 'wpvivid' ).'</span>
148
- </label>
149
- <div style="clear:both;"></div>
150
- <label>
151
- <input type="radio" id="wpvivid_backup_remote" option="backup_ex" name="local_remote" value="remote" />
152
- <span>'.__( 'Send Backup to Remote Storage:', 'wpvivid' ).'</span>
153
- </label><br>
154
- <div id="upload_storage" style="cursor:pointer;" title="Highlighted icon illuminates that you have choosed a remote storage to store backups">
155
- '.apply_filters('wpvivid_schedule_add_remote_pic',$pic).'
156
- </div>
157
- </fieldset>
158
- </div>';
159
- return $html;
160
- }
161
-
162
- function wpvivid_backup_part_exec($html){
163
- $html .= '<div class="quickstart-btn" style="padding-top:20px;">
164
- <input class="button-primary quickbackup-btn" id="wpvivid_quickbackup_btn" type="submit" value="'.esc_attr( 'Backup Now', 'wpvivid').'" />
165
- <div class="schedule-tab-block" style="text-align:center;">
166
- <fieldset>
167
- <label>
168
- <input type="checkbox" id="wpvivid_backup_lock" option="backup" name="lock" value="" />
169
- <span>'.__( 'This backup can only be deleted manually', 'wpvivid' ).'</span>
170
- </label>
171
- </fieldset>
172
- </div>
173
- </div>';
174
- return $html;
175
- }
176
-
177
- function wpvivid_backup_part_tip($html){
178
- $html .= '<div class="custom-info" style="float:left; width:100%;">
179
- <strong>'.__('Tips', 'wpvivid').'</strong>'.__(': The settings are only for manual backup, which won\'t affect schedule settings.', 'wpvivid').'
180
- </div>';
181
- return $html;
182
- }
183
-
184
-
185
  function wpvivid_backuppage_load_backuplist($backuplist_array){
186
  $backuplist_array['list_backup'] = array('index' => '1', 'tab_func' => 'wpvivid_backuppage_add_tab_backup', 'page_func' => 'wpvivid_backuppage_add_page_backup');
187
  $backuplist_array['list_log'] = array('index' => '3', 'tab_func' => 'wpvivid_backuppage_add_tab_log', 'page_func' => 'wpvivid_backuppage_add_page_log');
@@ -231,7 +141,7 @@ function wpvivid_backuppage_add_page_backup(){
231
  <div style="margin-bottom:10px;">
232
  <?php
233
  $descript='';
234
- $descript= apply_filters('wpvivid_restore_website_dexcript',$descript);
235
  echo $descript;
236
  ?>
237
  </div>
@@ -250,7 +160,7 @@ function wpvivid_backuppage_add_page_backup(){
250
  <th><?php _e( 'Delete','wpvivid'); ?></th>
251
  </tr>
252
  </thead>
253
- <tbody class="wpvivid-backuplist" id="wpvivid_backuplist">
254
  <?php
255
  $html = '';
256
  $html = apply_filters('wpvivid_add_backup_list', $html);
@@ -266,9 +176,439 @@ function wpvivid_backuppage_add_page_backup(){
266
  </table>
267
  </div>
268
  <script>
269
- function wpvivid_delete_selected_backup(backup_id){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  var name = '';
271
- jQuery('#wpvivid_backuplist tr').each(function(i){
272
  jQuery(this).children('td').each(function (j) {
273
  if (j == 0) {
274
  var id = jQuery(this).parent().children('th').find("input[type=checkbox]").attr("id");
@@ -316,7 +656,7 @@ function wpvivid_backuppage_add_page_backup(){
316
  var delete_backup_array = new Array();
317
  var count = 0;
318
  var bdownloading = false;
319
- jQuery('#wpvivid_backuplist tr').each(function (i) {
320
  jQuery(this).children('th').each(function (j) {
321
  if (j == 0) {
322
  if(jQuery(this).find('input[type=checkbox]').prop('checked')){
@@ -359,6 +699,34 @@ function wpvivid_backuppage_add_page_backup(){
359
  }
360
  }
361
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
362
  </script>
363
  <?php
364
  }
@@ -403,66 +771,886 @@ function wpvivid_backuppage_add_page_restore(){
403
  </div>
404
  <div class="postbox restore_log" id="wpvivid_restore_log"></div>
405
  </div>
406
- <?php
407
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
408
 
 
 
 
 
409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
410
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
 
 
 
 
 
 
 
 
 
412
 
 
 
 
 
 
413
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
 
 
 
 
 
 
 
 
 
415
 
416
- function wpvivid_backuppage_load_progress_module($html){
417
- $html = '
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
418
  <div class="postbox" id="wpvivid_postbox_backup_percent" style="display: none;">
419
  <div class="action-progress-bar" id="wpvivid_action_progress_bar">
420
- <div class="action-progress-bar-percent" id="wpvivid_action_progress_bar_percent" style="height:24px;width:0"></div>
421
  </div>
422
  <div id="wpvivid_estimate_backup_info" style="float: left;">
423
- <div class="backup-basic-info"><span>'.__('Database Size:', 'wpvivid').'</span><span id="wpvivid_backup_database_size">N/A</span></div>
424
- <div class="backup-basic-info"><span>'.__('File Size:', 'wpvivid').'</span><span id="wpvivid_backup_file_size">N/A</span></div>
425
  </div>
426
  <div id="wpvivid_estimate_upload_info" style="float: left;">
427
- <div class="backup-basic-info"><span>'.__('Total Size:', 'wpvivid').'</span><span>N/A</span></div>
428
- <div class="backup-basic-info"><span>'.__('Uploaded:', 'wpvivid').'</span><span>N/A</span></div>
429
- <div class="backup-basic-info"><span>'.__('Speed:', 'wpvivid').'</span><span>N/A</span></div>
430
  </div>
431
  <div style="float: left;">
432
- <div class="backup-basic-info"><span>'.__('Network Connection:', 'wpvivid').'</span><span>N/A</span></div>
433
  </div>
434
  <div style="clear:both;"></div>
435
  <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing"></p></div>
436
  <div style="clear: both;"></div>
437
  <div>
438
- <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' ).'" /></div>
439
- <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' ).'" /></div>
440
  </div>
441
  <div style="clear: both;"></div>
442
- </div>';
443
- return $html;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
444
  }
445
 
446
- function wpvivid_backuppage_load_backup_module($html){
447
- $html = '';
448
- $backup_descript = '';
449
- $backup_part_type = '';
450
- $backup_part_pos = '';
451
- $backup_part_exec = '';
452
- $backup_part_tip = '';
453
- $html .= '
454
  <div class="postbox quickbackup" id="wpvivid_postbox_backup">
455
- '.apply_filters('wpvivid_backup_descript', $backup_descript).'
456
- '.apply_filters('wpvivid_backup_part_type', $backup_part_type).'
457
- '.apply_filters('wpvivid_backup_part_pos', $backup_part_pos).'
458
- '.apply_filters('wpvivid_backup_part_exec', $backup_part_exec).'
459
- '.apply_filters('wpvivid_backup_part_tip', $backup_part_tip).'
460
  </div>
461
- ';
462
- return $html;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
463
  }
464
 
465
- function wpvivid_backuppage_load_schedule_module($html){
466
  $schedule=WPvivid_Schedule::get_schedule();
467
  if($schedule['enable']){
468
  $schedule_status='Enabled';
@@ -474,36 +1662,38 @@ function wpvivid_backuppage_load_schedule_module($html){
474
  }
475
  $last_message = '';
476
  $last_message = apply_filters('wpvivid_get_last_backup_message', $last_message);
477
- $html = '
478
  <div class="postbox qucikbackup-schedule" id="wpvivid_postbox_backup_schedule">
479
- <h2><span>'.__( 'Backup Schedule','wpvivid').'</span></h2>
480
  <div class="schedule-block">
481
- <p id="wpvivid_schedule_status"><strong>'.__('Schedule Status: ', 'wpvivid').'</strong>'.$schedule_status.'</p>
482
  <div id="wpvivid_schedule_info">
483
- <p><strong>'.__('Server Time: ', 'wpvivid').'</strong>'.date("l, F d, Y H:i",time()).'</p>
484
- <p><span id="wpvivid_last_backup_msg">'.$last_message.'</span></p>
485
- <p id="wpvivid_next_backup"><strong>'.__('Next Backup: ', 'wpvivid').'</strong>'.$next_backup_time.'</p>
486
  </div>
487
  </div>
488
  </div>
489
  <div style="clear:both;"></div>
490
- ';
491
- return $html;
492
  }
493
 
 
494
  add_filter('wpvivid_add_backup_type', 'wpvivid_add_backup_type', 11, 2);
495
  add_action('wpvivid_backup_do_js', 'wpvivid_backup_do_js', 10);
496
  add_filter('wpvivid_download_backup_descript', 'wpvivid_download_backup_descript', 10);
497
- add_filter('wpvivid_restore_website_dexcript', 'wpvivid_restore_website_dexcript', 10);
498
- add_filter('wpvivid_backup_module', 'wpvivid_backup_module');
499
- add_filter('wpvivid_backup_descript', 'wpvivid_backup_descript');
500
- add_filter('wpvivid_backup_part_type', 'wpvivid_backup_part_type');
501
- add_filter('wpvivid_backup_part_pos', 'wpvivid_backup_part_pos');
502
- add_filter('wpvivid_backup_part_exec', 'wpvivid_backup_part_exec');
503
- add_filter('wpvivid_backup_part_tip', 'wpvivid_backup_part_tip');
504
- add_filter('wpvivid_backuppage_load_progress_module', 'wpvivid_backuppage_load_progress_module', 10);
505
- add_filter('wpvivid_backuppage_load_backup_module', 'wpvivid_backuppage_load_backup_module', 10);
506
- add_filter('wpvivid_backuppage_load_schedule_module', 'wpvivid_backuppage_load_schedule_module', 10);
507
  add_filter('wpvivid_backuppage_load_backuplist', 'wpvivid_backuppage_load_backuplist', 10);
508
 
 
 
 
 
 
 
 
 
 
 
509
  ?>
18
  }
19
 
20
  function wpvivid_backup_do_js(){
21
+ global $wpvivid_plugin;
22
+ $backup_task=$wpvivid_plugin->_list_tasks(false);
23
  $general_setting=WPvivid_Setting::get_setting(true, "");
24
  if($general_setting['options']['wpvivid_common_setting']['estimate_backup'] == 0){
25
  ?>
86
  return $html;
87
  }
88
 
89
+ function wpvivid_restore_website_descript($html){
90
  $html = '<p><a href="#" id="wpvivid_how_to_restore_backup_describe" onclick="wpvivid_click_how_to_restore_backup();">'.__('How to restore your website from a backup(scheduled, manual, uploaded and received backup)', 'wpvivid').'</a></p>';
91
  $html .= '<div id="wpvivid_how_to_restore_backup"></div>';
92
  return $html;
93
  }
94
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  function wpvivid_backuppage_load_backuplist($backuplist_array){
96
  $backuplist_array['list_backup'] = array('index' => '1', 'tab_func' => 'wpvivid_backuppage_add_tab_backup', 'page_func' => 'wpvivid_backuppage_add_page_backup');
97
  $backuplist_array['list_log'] = array('index' => '3', 'tab_func' => 'wpvivid_backuppage_add_tab_log', 'page_func' => 'wpvivid_backuppage_add_page_log');
141
  <div style="margin-bottom:10px;">
142
  <?php
143
  $descript='';
144
+ $descript= apply_filters('wpvivid_restore_website_descript',$descript);
145
  echo $descript;
146
  ?>
147
  </div>
160
  <th><?php _e( 'Delete','wpvivid'); ?></th>
161
  </tr>
162
  </thead>
163
+ <tbody class="wpvivid-backuplist" id="wpvivid_backup_list">
164
  <?php
165
  $html = '';
166
  $html = apply_filters('wpvivid_add_backup_list', $html);
176
  </table>
177
  </div>
178
  <script>
179
+ function wpvivid_retrieve_backup_list(){
180
+ var ajax_data = {
181
+ 'action': 'wpvivid_get_backup_list'
182
+ };
183
+ wpvivid_post_request(ajax_data, function(data){
184
+ try {
185
+ var jsonarray = jQuery.parseJSON(data);
186
+ if (jsonarray.result === 'success') {
187
+ jQuery('#wpvivid_backup_list').html('');
188
+ jQuery('#wpvivid_backup_list').append(jsonarray.html);
189
+ }
190
+ }
191
+ catch(err){
192
+ alert(err);
193
+ }
194
+ },function(XMLHttpRequest, textStatus, errorThrown) {
195
+ setTimeout(function () {
196
+ wpvivid_retrieve_backup_list();
197
+ }, 3000);
198
+ });
199
+ }
200
+
201
+ function wpvivid_handle_backup_data(data){
202
+ try {
203
+ var jsonarray = jQuery.parseJSON(data);
204
+ if (jsonarray.result === 'success') {
205
+ jQuery('#wpvivid_backup_list').html('');
206
+ jQuery('#wpvivid_backup_list').append(jsonarray.html);
207
+ }
208
+ else if(jsonarray.result === 'failed'){
209
+ alert(jsonarray.error);
210
+ }
211
+ }
212
+ catch(err){
213
+ alert(err);
214
+ }
215
+ }
216
+
217
+ function wpvivid_click_check_backup(backup_id, list_name){
218
+ var name = "";
219
+ var all_check = true;
220
+ jQuery('#'+list_name+' tr').each(function (i) {
221
+ jQuery(this).children('th').each(function (j) {
222
+ if(j === 0) {
223
+ var id = jQuery(this).find("input[type=checkbox]").attr("id");
224
+ if (id === backup_id) {
225
+ name = jQuery(this).parent().children('td').eq(0).find("img").attr("name");
226
+ if (name === "unlock") {
227
+ if (jQuery(this).find("input[type=checkbox]").prop('checked') === false) {
228
+ all_check = false;
229
+ }
230
+ }
231
+ else {
232
+ jQuery(this).find("input[type=checkbox]").prop('checked', false);
233
+ all_check = false;
234
+ }
235
+ }
236
+ else {
237
+ if (jQuery(this).find("input[type=checkbox]").prop('checked') === false) {
238
+ all_check = false;
239
+ }
240
+ }
241
+ }
242
+ });
243
+ });
244
+ if(all_check === true){
245
+ jQuery('#backup_list_all_check').prop('checked', true);
246
+ }
247
+ else{
248
+ jQuery('#backup_list_all_check').prop('checked', false);
249
+ }
250
+ }
251
+
252
+ function wpvivid_set_backup_lock(backup_id, lock_status){
253
+ if(lock_status === "lock"){
254
+ var lock=0;
255
+ }
256
+ else{
257
+ var lock=1;
258
+ }
259
+ var ajax_data={
260
+ 'action': 'wpvivid_set_security_lock',
261
+ 'backup_id': backup_id,
262
+ 'lock': lock
263
+ };
264
+ wpvivid_post_request(ajax_data, function(data) {
265
+ try {
266
+ var jsonarray = jQuery.parseJSON(data);
267
+ if (jsonarray.result === 'success') {
268
+ jQuery('#wpvivid_lock_'+backup_id).html(jsonarray.html);
269
+ }
270
+ }
271
+ catch(err){
272
+ alert(err);
273
+ }
274
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
275
+ var error_message = wpvivid_output_ajaxerror('setting up a lock for the backup', textStatus, errorThrown);
276
+ alert(error_message);
277
+ });
278
+ }
279
+
280
+ function wpvivid_initialize_download(backup_id, list_name){
281
+ wpvivid_reset_backup_list(list_name);
282
+ jQuery('#wpvivid_download_loading_'+backup_id).addClass('is-active');
283
+ tmp_current_click_backupid = backup_id;
284
+ var ajax_data = {
285
+ 'action':'wpvivid_init_download_page',
286
+ 'backup_id':backup_id
287
+ };
288
+ wpvivid_post_request(ajax_data, function(data){
289
+ try {
290
+ var jsonarray = jQuery.parseJSON(data);
291
+ jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
292
+ if (jsonarray.result === 'success') {
293
+ jQuery('#wpvivid_file_part_' + backup_id).html("");
294
+ var i = 0;
295
+ var file_not_found = false;
296
+ var file_name = '';
297
+ jQuery.each(jsonarray.files, function (index, value) {
298
+ i++;
299
+ file_name = index;
300
+ if (value.status === 'need_download') {
301
+ jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
302
+ //tmp_current_click_backupid = '';
303
+ }
304
+ else if (value.status === 'running') {
305
+ if (m_downloading_file_name === file_name) {
306
+ wpvivid_lock_download(tmp_current_click_backupid);
307
+ }
308
+ jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
309
+ }
310
+ else if (value.status === 'completed') {
311
+ if (m_downloading_file_name === file_name) {
312
+ wpvivid_unlock_download(tmp_current_click_backupid);
313
+ m_downloading_id = '';
314
+ m_downloading_file_name = '';
315
+ }
316
+ jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
317
+ //tmp_current_click_backupid = '';
318
+ }
319
+ else if (value.status === 'timeout') {
320
+ if (m_downloading_file_name === file_name) {
321
+ wpvivid_unlock_download(tmp_current_click_backupid);
322
+ m_downloading_id = '';
323
+ m_downloading_file_name = '';
324
+ }
325
+ jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
326
+ //tmp_current_click_backupid = '';
327
+ }
328
+ else if (value.status === 'file_not_found') {
329
+ wpvivid_unlock_download(tmp_current_click_backupid);
330
+ wpvivid_reset_backup_list(list_name);
331
+ file_not_found = true;
332
+ alert("Download failed, file not found. The file might has been moved, renamed or deleted. Please verify the file exists and try again.");
333
+ //tmp_current_click_backupid = '';
334
+ return false;
335
+ }
336
+ });
337
+ if (file_not_found === false) {
338
+ jQuery('#wpvivid_file_part_' + backup_id).append(jsonarray.place_html);
339
+ }
340
+ }
341
+ }
342
+ catch(err){
343
+ alert(err);
344
+ jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
345
+ }
346
+ },function(XMLHttpRequest, textStatus, errorThrown){
347
+ jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
348
+ var error_message = wpvivid_output_ajaxerror('initializing download information', textStatus, errorThrown);
349
+ alert(error_message);
350
+ });
351
+ }
352
+
353
+ function wpvivid_reset_backup_list(list_name){
354
+ jQuery('#'+list_name+' tr').each(function(i){
355
+ jQuery(this).children('td').each(function (j) {
356
+ if (j == 2) {
357
+ var backup_id = jQuery(this).parent().children('th').find("input[type=checkbox]").attr("id");
358
+ var download_btn = '<div id="wpvivid_file_part_' + backup_id + '" style="float:left;padding:10px 10px 10px 0px;">' +
359
+ '<div style="cursor:pointer;" onclick="wpvivid_initialize_download(\'' + backup_id + '\', \''+list_name+'\');" title="Prepare to download the backup">' +
360
+ '<img id="wpvivid_download_btn_' + backup_id + '" src="' + wpvivid_plugurl + '/admin/partials/images/download.png" style="vertical-align:middle;" />Download' +
361
+ '<div class="spinner" id="wpvivid_download_loading_' + backup_id + '" style="float:right;width:auto;height:auto;padding:10px 180px 10px 0;background-position:0 0;"></div>' +
362
+ '</div>' +
363
+ '</div>';
364
+ jQuery(this).html(download_btn);
365
+ }
366
+ });
367
+ });
368
+ }
369
+
370
+ function wpvivid_lock_download(backup_id){
371
+ jQuery('#wpvivid_backup_list tr').each(function(i){
372
+ jQuery(this).children('td').each(function (j) {
373
+ if (j == 2) {
374
+ jQuery(this).css({'pointer-events': 'none', 'opacity': '0.4'});
375
+ }
376
+ });
377
+ });
378
+ }
379
+
380
+ function wpvivid_unlock_download(backup_id){
381
+ jQuery('#wpvivid_backup_list tr').each(function(i){
382
+ jQuery(this).children('td').each(function (j) {
383
+ if (j == 2) {
384
+ jQuery(this).css({'pointer-events': 'auto', 'opacity': '1'});
385
+ }
386
+ });
387
+ });
388
+ }
389
+
390
+ /**
391
+ * Start downloading backup
392
+ *
393
+ * @param part_num - The part number for the download object
394
+ * @param backup_id - The unique ID for the backup
395
+ * @param file_name - File name
396
+ */
397
+ function wpvivid_prepare_download(part_num, backup_id, file_name){
398
+ var ajax_data = {
399
+ 'action': 'wpvivid_prepare_download_backup',
400
+ 'backup_id':backup_id,
401
+ 'file_name':file_name
402
+ };
403
+ var progress = '0%';
404
+ jQuery("#"+backup_id+"-text-part-"+part_num).html("<a>Retriving(remote storage to web server)</a>");
405
+ jQuery("#"+backup_id+"-progress-part-"+part_num).css('width', progress);
406
+ task_retry_times = 0;
407
+ m_need_update = true;
408
+ wpvivid_lock_download(backup_id);
409
+ m_downloading_id = backup_id;
410
+ tmp_current_click_backupid = backup_id;
411
+ m_downloading_file_name = file_name;
412
+ wpvivid_post_request(ajax_data, function(data)
413
+ {
414
+ }, function(XMLHttpRequest, textStatus, errorThrown)
415
+ {
416
+ }, 0);
417
+ }
418
+
419
+ /**
420
+ * Download backups to user's computer.
421
+ *
422
+ * @param backup_id - The unique ID for the backup
423
+ * @param backup_type - The types of the backup
424
+ * @param file_name - File name
425
+ */
426
+ function wpvivid_download(backup_id, backup_type, file_name){
427
+ wpvivid_location_href=true;
428
+ location.href =ajaxurl+'?action=wpvivid_download_backup&backup_id='+backup_id+'&download_type='+backup_type+'&file_name='+file_name;
429
+ }
430
+
431
+ function wpvivid_initialize_restore(backup_id, backup_time, backup_type, restore_type='backup'){
432
+ var time_type = 'backup';
433
+ var log_type = '';
434
+ var tab_type = '';
435
+ var page_type = 'backup';
436
+ if(restore_type == 'backup'){
437
+ time_type = 'backup';
438
+ log_type = '';
439
+ tab_type = '';
440
+ page_type = 'backup';
441
+ }
442
+ else if(restore_type == 'transfer'){
443
+ time_type = 'transfer';
444
+ log_type = 'transfer_';
445
+ tab_type = 'add_';
446
+ page_type = 'migrate';
447
+ }
448
+ wpvivid_restore_backup_type = backup_type;
449
+ jQuery('#wpvivid_restore_'+time_type+'_time').html(backup_time);
450
+ m_restore_backup_id = backup_id;
451
+ jQuery('#wpvivid_restore_'+log_type+'log').html("");
452
+ jQuery('#wpvivid_'+tab_type+'tab_restore').show();
453
+ wpvivid_click_switch_page(page_type, 'wpvivid_'+tab_type+'tab_restore', true);
454
+ wpvivid_init_restore_data(restore_type);
455
+ }
456
+
457
+ function click_dismiss_restore_check_notice(obj){
458
+ wpvivid_display_restore_check = false;
459
+ jQuery(obj).parent().remove();
460
+ }
461
+
462
+ /**
463
+ * This function will initialize restore information
464
+ *
465
+ * @param backup_id - The unique ID for the backup
466
+ */
467
+ function wpvivid_init_restore_data(restore_type)
468
+ {
469
+ wpvivid_resotre_is_migrate=0;
470
+ var restore_method = '';
471
+ if(restore_type == 'backup'){
472
+ restore_method = '';
473
+ }
474
+ else if(restore_type == 'transfer'){
475
+ restore_method = 'transfer_';
476
+ }
477
+ jQuery('#wpvivid_replace_domain').prop('checked', false);
478
+ jQuery('#wpvivid_keep_domain').prop('checked', false);
479
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
480
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
481
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
482
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
483
+ jQuery('#wpvivid_restore_'+restore_method+'part').show();
484
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
485
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
486
+ jQuery('#wpvivid_download_'+restore_method+'part').hide();
487
+ /*if(wpvivid_restore_backup_type == 'Migration' || wpvivid_restore_backup_type == 'Upload') {
488
+ jQuery('#wpvivid_restore_is_migrate').show();
489
+ jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'none', 'opacity': '0.4'});
490
+ }
491
+ else{
492
+ jQuery('#wpvivid_restore_is_migrate').hide();
493
+ }*/
494
+ jQuery('#wpvivid_init_restore_data').addClass('is-active');
495
+ var ajax_data = {
496
+ 'action':'wpvivid_init_restore_page',
497
+ 'backup_id':m_restore_backup_id
498
+ };
499
+ wpvivid_post_request(ajax_data, function(data){
500
+ try {
501
+ var jsonarray = jQuery.parseJSON(data);
502
+ var init_status = false;
503
+ if(jsonarray.result === 'success') {
504
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
505
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
506
+ jQuery('#wpvivid_restore_'+restore_method+'part').show();
507
+ jQuery('#wpvivid_download_'+restore_method+'part').hide();
508
+ wpvivid_restore_need_download = false;
509
+ init_status = true;
510
+ }
511
+ else if (jsonarray.result === "need_download"){
512
+ init_status = true;
513
+ wpvivid_restore_download_array = new Array();
514
+ var download_num = 0;
515
+ jQuery.each(jsonarray.files, function (index, value)
516
+ {
517
+ if (value.status === "need_download")
518
+ {
519
+ wpvivid_restore_download_array[download_num] = new Array('file_name', 'size', 'md5');
520
+ wpvivid_restore_download_array[download_num]['file_name'] = index;
521
+ wpvivid_restore_download_array[download_num]['size'] = value.size;
522
+ wpvivid_restore_download_array[download_num]['md5'] = value.md5;
523
+ download_num++;
524
+ }
525
+ });
526
+ wpvivid_restore_download_index=0;
527
+ wpvivid_restore_need_download = true;
528
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
529
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
530
+ jQuery('#wpvivid_restore_'+restore_method+'part').hide();
531
+ jQuery('#wpvivid_download_'+restore_method+'part').show();
532
+ }
533
+ else if (jsonarray.result === "failed") {
534
+ jQuery('#wpvivid_init_restore_data').removeClass('is-active');
535
+ wpvivid_display_restore_msg(jsonarray.error, restore_type);
536
+ }
537
+
538
+ if(init_status){
539
+ if(jsonarray.max_allow_packet_warning != false || jsonarray.memory_limit_warning != false) {
540
+ if(!wpvivid_display_restore_check) {
541
+ wpvivid_display_restore_check = true;
542
+ var output = '';
543
+ if(jsonarray.max_allow_packet_warning != false){
544
+ output += "<p>" + jsonarray.max_allow_packet_warning + "</p>";
545
+ }
546
+ if(jsonarray.memory_limit != false){
547
+ output += "<p>" + jsonarray.memory_limit_warning + "</p>";
548
+ }
549
+ var div = "<div class='notice notice-warning is-dismissible inline'>" +
550
+ output +
551
+ "<button type='button' class='notice-dismiss' onclick='click_dismiss_restore_check_notice(this);'>" +
552
+ "<span class='screen-reader-text'>Dismiss this notice.</span>" +
553
+ "</button>" +
554
+ "</div>";
555
+ jQuery('#wpvivid_restore_check').append(div);
556
+ }
557
+ }
558
+ jQuery('#wpvivid_init_restore_data').removeClass('is-active');
559
+ if (jsonarray.has_exist_restore === 0) {
560
+ if(wpvivid_restore_need_download == false) {
561
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
562
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
563
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
564
+ jQuery('#wpvivid_restore_' + restore_method + 'part').show();
565
+ jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
566
+ jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
567
+ jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
568
+
569
+ jQuery('#wpvivid_restore_is_migrate').hide();
570
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
571
+
572
+ wpvivid_resotre_is_migrate = jsonarray.is_migrate;
573
+
574
+ if (jsonarray.is_migrate_ui === 1) {
575
+ jQuery('#wpvivid_restore_is_migrate').show()
576
+ jQuery('#wpvivid_replace_domain').prop('checked', false);
577
+ jQuery('#wpvivid_keep_domain').prop('checked', false);
578
+ }
579
+ else {
580
+ jQuery('#wpvivid_restore_is_migrate').hide();
581
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
582
+ }
583
+
584
+ wpvivid_interface_flow_control();
585
+ }
586
+ }
587
+ else if (jsonarray.has_exist_restore === 1) {
588
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
589
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'auto', 'opacity': '1'});
590
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
591
+ jQuery('#wpvivid_restore_'+restore_method+'part').hide();
592
+ jQuery('#wpvivid_clean_'+restore_method+'part').show();
593
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
594
+ jQuery('#wpvivid_restore_is_migrate').hide();
595
+ wpvivid_display_restore_msg("An uncompleted restore task exists, please terminate it first.", restore_type);
596
+ }
597
+ }
598
+ }
599
+ catch(err){
600
+ alert(err);
601
+ }
602
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
603
+ jQuery('#wpvivid_init_restore_data').removeClass('is-active');
604
+ var error_message = wpvivid_output_ajaxerror('initializing restore information', textStatus, errorThrown);
605
+ wpvivid_display_restore_msg(error_message, restore_type);
606
+ });
607
+ }
608
+
609
+ function wpvivid_delete_selected_backup(backup_id, list_name){
610
  var name = '';
611
+ jQuery('#wpvivid_backup_list tr').each(function(i){
612
  jQuery(this).children('td').each(function (j) {
613
  if (j == 0) {
614
  var id = jQuery(this).parent().children('th').find("input[type=checkbox]").attr("id");
656
  var delete_backup_array = new Array();
657
  var count = 0;
658
  var bdownloading = false;
659
+ jQuery('#wpvivid_backup_list tr').each(function (i) {
660
  jQuery(this).children('th').each(function (j) {
661
  if (j == 0) {
662
  if(jQuery(this).find('input[type=checkbox]').prop('checked')){
699
  }
700
  }
701
  }
702
+
703
+ jQuery('#backup_list_all_check').click(function(){
704
+ var name = '';
705
+ if(jQuery('#backup_list_all_check').prop('checked')) {
706
+ jQuery('#wpvivid_backup_list tr').each(function (i) {
707
+ jQuery(this).children('th').each(function (j) {
708
+ if (j == 0) {
709
+ name = jQuery(this).parent().children('td').eq(0).find("img").attr("name");
710
+ if(name === 'unlock') {
711
+ jQuery(this).find("input[type=checkbox]").prop('checked', true);
712
+ }
713
+ else{
714
+ jQuery(this).find("input[type=checkbox]").prop('checked', false);
715
+ }
716
+ }
717
+ });
718
+ });
719
+ }
720
+ else{
721
+ jQuery('#wpvivid_backup_list tr').each(function (i) {
722
+ jQuery(this).children('th').each(function (j) {
723
+ if (j == 0) {
724
+ jQuery(this).find("input[type=checkbox]").prop('checked', false);
725
+ }
726
+ });
727
+ });
728
+ }
729
+ });
730
  </script>
731
  <?php
732
  }
771
  </div>
772
  <div class="postbox restore_log" id="wpvivid_restore_log"></div>
773
  </div>
774
+ <script>
775
+ jQuery('#wpvivid_clean_restore').click(function(){
776
+ wpvivid_delete_incompleted_restore();
777
+ });
778
+
779
+ jQuery('#wpvivid_download_btn').click(function(){
780
+ wpvivid_download_restore_file('backup');
781
+ });
782
+
783
+ function wpvivid_delete_incompleted_restore(restore_type = 'backup'){
784
+ var restore_method = '';
785
+ if(restore_type == 'backup'){
786
+ restore_method = '';
787
+ }
788
+ else if(restore_type == 'transfer'){
789
+ restore_method = 'transfer_';
790
+ }
791
+
792
+ var ajax_data={
793
+ 'action': 'wpvivid_delete_last_restore_data'
794
+ };
795
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
796
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'auto', 'opacity': '1'});
797
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
798
+ jQuery('#wpvivid_restore_'+restore_method+'part').hide();
799
+ jQuery('#wpvivid_clean_'+restore_method+'part').show();
800
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
801
+ wpvivid_post_request(ajax_data, function(data) {
802
+ try {
803
+ var jsonarray = jQuery.parseJSON(data);
804
+ if (jsonarray.result === "success") {
805
+ wpvivid_display_restore_msg("The restore task is terminated.", restore_type);
806
+ wpvivid_init_restore_data(restore_type);
807
+ }
808
+ }
809
+ catch(err){
810
+ alert(err);
811
+ }
812
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
813
+ var error_message = wpvivid_output_ajaxerror('deleting the last incomplete restore task', textStatus, errorThrown);
814
+ wpvivid_display_restore_msg(error_message, restore_type);
815
+ });
816
+ }
817
+
818
+ function wpvivid_restore_is_migrate(restore_type){
819
+ var ajax_data = {
820
+ 'action': 'wpvivid_get_restore_file_is_migrate',
821
+ 'backup_id': m_restore_backup_id
822
+ };
823
+ var restore_method = '';
824
+ wpvivid_post_request(ajax_data, function(data)
825
+ {
826
+ try
827
+ {
828
+ var jsonarray = jQuery.parseJSON(data);
829
+ if(jsonarray.result === "success")
830
+ {
831
+ if (jsonarray.is_migrate_ui === 1)
832
+ {
833
+ jQuery('#wpvivid_restore_is_migrate').show();
834
+ jQuery('#wpvivid_replace_domain').prop('checked', false);
835
+ jQuery('#wpvivid_keep_domain').prop('checked', false);
836
+ }
837
+ else {
838
+ jQuery('#wpvivid_restore_is_migrate').hide();
839
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
840
+ }
841
+ }
842
+ else if (jsonarray.result === "failed") {
843
+ jQuery('#wpvivid_init_restore_data').removeClass('is-active');
844
+ wpvivid_display_restore_msg(jsonarray.error, restore_type);
845
+ }
846
+ }
847
+ catch(err){
848
+ alert(err);
849
+ }
850
+ }, function(XMLHttpRequest, textStatus, errorThrown)
851
+ {
852
+ setTimeout(function()
853
+ {
854
+ wpvivid_restore_is_migrate(restore_type);
855
+ }, 3000);
856
+ });
857
+ }
858
+
859
+ /**
860
+ * This function will start the process of restoring a backup
861
+ */
862
+ function wpvivid_start_restore(restore_type = 'backup'){
863
+ if(!wpvivid_restore_sure){
864
+ var descript = 'Are you sure to continue?';
865
+ var ret = confirm(descript);
866
+ }
867
+ else{
868
+ ret = true;
869
+ }
870
+ if (ret === true) {
871
+ wpvivid_restore_sure = true;
872
+ var restore_method = '';
873
+ if (restore_type == 'backup') {
874
+ restore_method = '';
875
+ }
876
+ else if (restore_type == 'transfer') {
877
+ restore_method = 'transfer_';
878
+ }
879
+ jQuery('#wpvivid_restore_' + restore_method + 'log').html("");
880
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
881
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
882
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
883
+ jQuery('#wpvivid_restore_' + restore_method + 'part').show();
884
+ jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
885
+ jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
886
+ wpvivid_restore_lock();
887
+ wpvivid_restoring = true;
888
+ if (wpvivid_restore_need_download) {
889
+ wpvivid_download_restore_file(restore_type);
890
+ }
891
+ else {
892
+ wpvivid_monitor_restore_task(restore_type);
893
+ if(wpvivid_resotre_is_migrate==0)
894
+ {
895
+ jQuery('input:radio[option=restore]').each(function()
896
+ {
897
+ if(jQuery(this).prop('checked'))
898
+ {
899
+ var value = jQuery(this).prop('value');
900
+ if(value == '1')
901
+ {
902
+ wpvivid_resotre_is_migrate = '1';
903
+ }
904
+ }
905
+ });
906
+ }
907
+
908
+ wpvivid_restore(restore_type);
909
+ }
910
+ }
911
+ }
912
+
913
+ function wpvivid_download_restore_file(restore_type)
914
+ {
915
+ var restore_method = '';
916
+ if(restore_type == 'backup'){
917
+ restore_method = '';
918
+ }
919
+ else if(restore_type == 'transfer'){
920
+ restore_method = 'transfer_';
921
+ }
922
+
923
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
924
+ wpvivid_restore_lock();
925
+ if(wpvivid_restore_download_array.length===0)
926
+ {
927
+ 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);
928
+ wpvivid_restore_unlock();
929
+ return false;
930
+ }
931
+
932
+ if(wpvivid_restore_download_index+1>wpvivid_restore_download_array.length)
933
+ {
934
+ wpvivid_display_restore_msg("Download succeeded.", restore_type);
935
+ wpvivid_restore_is_migrate(restore_type);
936
+ wpvivid_restore_need_download = false;
937
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
938
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
939
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
940
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
941
+ jQuery('#wpvivid_restore_' + restore_method + 'part').show();
942
+ jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
943
+ jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
944
+ jQuery('#wpvivid_download_'+restore_method+'part').hide();
945
+ //wpvivid_start_restore(restore_type);
946
+ }
947
+ else
948
+ {
949
+ wpvivid_display_restore_msg("Downloading backup file " + wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'], restore_type);
950
+ wpvivid_display_restore_msg('', restore_type, wpvivid_restore_download_index);
951
+ var ajax_data = {
952
+ 'action': 'wpvivid_download_restore',
953
+ 'backup_id': m_restore_backup_id,
954
+ 'file_name': wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],
955
+ 'size': wpvivid_restore_download_array[wpvivid_restore_download_index]['size'],
956
+ 'md5': wpvivid_restore_download_array[wpvivid_restore_download_index]['md5']
957
+ }
958
+ wpvivid_get_download_restore_progress_retry=0;
959
+ wpvivid_monitor_download_restore_task(restore_type);
960
+ wpvivid_post_request(ajax_data, function (data) {
961
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
962
+ }, 0);
963
+ }
964
+ }
965
+
966
+ function wpvivid_monitor_download_restore_task(restore_type)
967
+ {
968
+ var restore_method = '';
969
+ if(restore_type == 'backup'){
970
+ restore_method = '';
971
+ }
972
+ else if(restore_type == 'transfer'){
973
+ restore_method = 'transfer_';
974
+ }
975
+
976
+ var ajax_data={
977
+ 'action':'wpvivid_get_download_restore_progress',
978
+ 'file_name': wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],
979
+ 'size': wpvivid_restore_download_array[wpvivid_restore_download_index]['size'],
980
+ 'md5': wpvivid_restore_download_array[wpvivid_restore_download_index]['md5']
981
+ };
982
+
983
+ wpvivid_post_request(ajax_data, function(data)
984
+ {
985
+ try
986
+ {
987
+ var jsonarray = jQuery.parseJSON(data);
988
+ if(typeof jsonarray ==='object')
989
+ {
990
+ if(jsonarray.result === "success")
991
+ {
992
+ if(jsonarray.status==='completed')
993
+ {
994
+ wpvivid_display_restore_msg(wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'] + ' download succeeded.', restore_type, wpvivid_restore_download_index, false);
995
+ wpvivid_restore_download_index++;
996
+ wpvivid_download_restore_file(restore_type);
997
+ wpvivid_restore_unlock();
998
+ }
999
+ else if(jsonarray.status==='error')
1000
+ {
1001
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1002
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1003
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1004
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1005
+ jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1006
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1007
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1008
+ jQuery('#wpvivid_download_'+restore_method+'part').show();
1009
+ var error_message = jsonarray.error;
1010
+ wpvivid_display_restore_msg(error_message,restore_type,wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],false);
1011
+ wpvivid_restore_unlock();
1012
+ }
1013
+ else if(jsonarray.status==='running')
1014
+ {
1015
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1016
+ wpvivid_display_restore_msg(jsonarray.log, restore_type, wpvivid_restore_download_index, false);
1017
+ setTimeout(function()
1018
+ {
1019
+ wpvivid_monitor_download_restore_task(restore_type);
1020
+ }, 3000);
1021
+ wpvivid_restore_lock();
1022
+ }
1023
+ else if(jsonarray.status==='timeout')
1024
+ {
1025
+ wpvivid_get_download_restore_progress_retry++;
1026
+ if(wpvivid_get_download_restore_progress_retry>10)
1027
+ {
1028
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1029
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1030
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1031
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1032
+ jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1033
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1034
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1035
+ jQuery('#wpvivid_download_'+restore_method+'part').show();
1036
+ var error_message = jsonarray.error;
1037
+ wpvivid_display_restore_msg(error_message, restore_type);
1038
+ wpvivid_restore_unlock();
1039
+ }
1040
+ else
1041
+ {
1042
+ setTimeout(function()
1043
+ {
1044
+ wpvivid_monitor_download_restore_task(restore_type);
1045
+ }, 3000);
1046
+ }
1047
+ }
1048
+ else
1049
+ {
1050
+ setTimeout(function()
1051
+ {
1052
+ wpvivid_monitor_download_restore_task(restore_type);
1053
+ }, 3000);
1054
+ }
1055
+ }
1056
+ else
1057
+ {
1058
+ wpvivid_get_download_restore_progress_retry++;
1059
+ if(wpvivid_get_download_restore_progress_retry>10)
1060
+ {
1061
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1062
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1063
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1064
+ jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1065
+ jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1066
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1067
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1068
+ jQuery('#wpvivid_download_'+restore_method+'part').show();
1069
+ var error_message = jsonarray.error;
1070
+ wpvivid_display_restore_msg(error_message, restore_type);
1071
+ wpvivid_restore_unlock();
1072
+ }
1073
+ else
1074
+ {
1075
+ setTimeout(function()
1076
+ {
1077
+ wpvivid_monitor_download_restore_task(restore_type);
1078
+ }, 3000);
1079
+ }
1080
+ }
1081
+ }
1082
+ else
1083
+ {
1084
+ setTimeout(function()
1085
+ {
1086
+ wpvivid_monitor_download_restore_task(restore_type);
1087
+ }, 3000);
1088
+ }
1089
+ }
1090
+ catch(err){
1091
+ setTimeout(function()
1092
+ {
1093
+ wpvivid_monitor_download_restore_task(restore_type);
1094
+ }, 3000);
1095
+ }
1096
+ }, function(XMLHttpRequest, textStatus, errorThrown)
1097
+ {
1098
+ setTimeout(function()
1099
+ {
1100
+ wpvivid_monitor_download_restore_task(restore_type);
1101
+ }, 1000);
1102
+ });
1103
+ }
1104
+
1105
+ /**
1106
+ * Monitor restore task.
1107
+ */
1108
+ function wpvivid_monitor_restore_task(restore_type){
1109
+ var restore_method = '';
1110
+ if(restore_type == 'backup'){
1111
+ restore_method = '';
1112
+ }
1113
+ else if(restore_type == 'transfer'){
1114
+ restore_method = 'transfer_';
1115
+ }
1116
 
1117
+ var ajax_data={
1118
+ 'action':'wpvivid_get_restore_progress',
1119
+ 'wpvivid_restore' : '1',
1120
+ };
1121
 
1122
+ if(wpvivid_restore_timeout){
1123
+ jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1124
+ jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1125
+ jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1126
+ jQuery('#wpvivid_restore_'+restore_method+'part').show();
1127
+ jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1128
+ jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1129
+ wpvivid_restore_unlock();
1130
+ wpvivid_restoring = false;
1131
+ wpvivid_display_restore_msg("Website restore times out.", restore_type);
1132
+ }
1133
+ else {
1134
+ wpvivid_post_request(ajax_data, function (data) {
1135
+ try {
1136
+ var jsonarray = jQuery.parseJSON(data);
1137
+ if (typeof jsonarray === 'object') {
1138
+ if (jsonarray.result === "success") {
1139
+ jQuery('#wpvivid_restore_' + restore_method + 'log').html("");
1140
+ while (jsonarray.log.indexOf('\n') >= 0) {
1141
+ var iLength = jsonarray.log.indexOf('\n');
1142
+ var log = jsonarray.log.substring(0, iLength);
1143
+ jsonarray.log = jsonarray.log.substring(iLength + 1);
1144
+ var insert_log = "<div style=\"clear:both;\">" + log + "</div>";
1145
+ jQuery('#wpvivid_restore_' + restore_method + 'log').append(insert_log);
1146
+ var div = jQuery('#wpvivid_restore_' + restore_method + 'log');
1147
+ div[0].scrollTop = div[0].scrollHeight;
1148
+ }
1149
 
1150
+ if (jsonarray.status === 'wait') {
1151
+ wpvivid_restoring = true;
1152
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({
1153
+ 'pointer-events': 'none',
1154
+ 'opacity': '0.4'
1155
+ });
1156
+ jQuery('#wpvivid_clean_' + restore_method + 'restore').css({
1157
+ 'pointer-events': 'none',
1158
+ 'opacity': '0.4'
1159
+ });
1160
+ jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({
1161
+ 'pointer-events': 'none',
1162
+ 'opacity': '0.4'
1163
+ });
1164
+ jQuery('#wpvivid_restore_' + restore_method + 'part').show();
1165
+ jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
1166
+ jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
1167
+ wpvivid_restore(restore_type);
1168
+ setTimeout(function () {
1169
+ wpvivid_monitor_restore_task(restore_type);
1170
+ }, 1000);
1171
+ }
1172
+ else if (jsonarray.status === 'completed') {
1173
+ wpvivid_restoring = false;
1174
+ wpvivid_restore(restore_type);
1175
+ wpvivid_restore_unlock();
1176
+ alert("Restore completed successfully.");
1177
+ location.reload();
1178
+ }
1179
+ else if (jsonarray.status === 'error') {
1180
+ wpvivid_restore_unlock();
1181
+ wpvivid_restoring = false;
1182
+ jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1183
+ alert("Restore failed.");
1184
+ }
1185
+ else {
1186
+ setTimeout(function () {
1187
+ wpvivid_monitor_restore_task(restore_type);
1188
+ }, 1000);
1189
+ }
1190
+ }
1191
+ else {
1192
+ setTimeout(function () {
1193
+ wpvivid_monitor_restore_task(restore_type);
1194
+ }, 1000);
1195
+ }
1196
+ }
1197
+ else {
1198
+ setTimeout(function () {
1199
+ wpvivid_monitor_restore_task(restore_type);
1200
+ }, 1000);
1201
+ }
1202
+ }
1203
+ catch (err) {
1204
+ setTimeout(function () {
1205
+ wpvivid_monitor_restore_task(restore_type);
1206
+ }, 1000);
1207
+ }
1208
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
1209
+ setTimeout(function () {
1210
+ wpvivid_monitor_restore_task(restore_type);
1211
+ }, 1000);
1212
+ });
1213
+ }
1214
+ }
1215
 
1216
+ function wpvivid_restore(restore_type){
1217
+ var restore_method = '';
1218
+ if(restore_type == 'backup'){
1219
+ restore_method = '';
1220
+ }
1221
+ else if(restore_type == 'transfer'){
1222
+ restore_method = 'transfer_';
1223
+ }
1224
 
1225
+ var skip_old_site = '1';
1226
+ var extend_option = {
1227
+ 'skip_backup_old_site':skip_old_site,
1228
+ 'skip_backup_old_database':skip_old_site
1229
+ };
1230
 
1231
+ var migrate_option = {
1232
+ 'is_migrate':wpvivid_resotre_is_migrate,
1233
+ };
1234
+ jQuery.extend(extend_option, migrate_option);
1235
+
1236
+ var restore_options = {
1237
+ 0:'backup_db',
1238
+ 1:'backup_themes',
1239
+ 2:'backup_plugin',
1240
+ 3:'backup_uploads',
1241
+ 4:'backup_content',
1242
+ 5:'backup_core'
1243
+ };
1244
+ jQuery.extend(restore_options, extend_option);
1245
+ var json = JSON.stringify(restore_options);
1246
+ var ajax_data={
1247
+ 'action':'wpvivid_restore',
1248
+ 'wpvivid_restore':'1',
1249
+ 'backup_id':m_restore_backup_id,
1250
+ 'restore_options':json
1251
+ };
1252
+ setTimeout(function () {
1253
+ wpvivid_restore_timeout = true;
1254
+ }, 1800000);
1255
+ wpvivid_post_request(ajax_data, function(data) {
1256
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
1257
+ });
1258
+ }
1259
 
1260
+ function wpvivid_display_restore_msg(msg, restore_type, div_id, append = true){
1261
+ var restore_method = '';
1262
+ if(restore_type == 'backup'){
1263
+ restore_method = '';
1264
+ }
1265
+ else if(restore_type == 'transfer'){
1266
+ restore_method = 'transfer_';
1267
+ }
1268
 
1269
+ if(typeof div_id == 'undefined') {
1270
+ var restore_msg = "<div style=\"clear:both;\">" + msg + "</div>";
1271
+ }
1272
+ else{
1273
+ var restore_msg = "<div id=\"restore_file_"+div_id+"\" style=\"clear:both;\">" + msg + "</div>";
1274
+ }
1275
+ if(append == true) {
1276
+ jQuery('#wpvivid_restore_'+restore_method+'log').append(restore_msg);
1277
+ }
1278
+ else{
1279
+ if(jQuery('#restore_file_'+div_id).length )
1280
+ {
1281
+ jQuery('#restore_file_'+div_id).html(msg);
1282
+ }
1283
+ else
1284
+ {
1285
+ jQuery('#wpvivid_restore_'+restore_method+'log').append(restore_msg);
1286
+ }
1287
+ }
1288
+ var div = jQuery('#wpvivid_restore_' + restore_method + 'log');
1289
+ div[0].scrollTop = div[0].scrollHeight;
1290
+ }
1291
+
1292
+ /**
1293
+ * Lock certain operations while a restore task is running.
1294
+ */
1295
+ function wpvivid_restore_lock(){
1296
+ jQuery('#wpvivid_postbox_backup_percent').css({'pointer-events': 'none', 'opacity': '1'});
1297
+ jQuery('#wpvivid_postbox_backup').css({'pointer-events': 'none', 'opacity': '1'});
1298
+ jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'none', 'opacity': '1'});
1299
+ jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '1'});
1300
+ jQuery('#wpvivid_tab_backup').css({'pointer-events': 'none', 'opacity': '1'});
1301
+ jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'none', 'opacity': '1'});
1302
+ jQuery('#wpvivid_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
1303
+ jQuery('#page-backups').css({'pointer-events': 'none', 'opacity': '1'});
1304
+ jQuery('#storage-page').css({'pointer-events': 'none', 'opacity': '1'});
1305
+ jQuery('#settings-page').css({'pointer-events': 'none', 'opacity': '1'});
1306
+ jQuery('#debug-page').css({'pointer-events': 'none', 'opacity': '1'});
1307
+ jQuery('#logs-page').css({'pointer-events': 'none', 'opacity': '1'});
1308
+ jQuery('#wpvivid_tab_migrate').css({'pointer-events': 'none', 'opacity': '1'});
1309
+ jQuery('#wpvivid_add_tab_migrate').css({'pointer-events': 'none', 'opacity': '1'});
1310
+ jQuery('#wpvivid_add_tab_import').css({'pointer-events': 'none', 'opacity': '1'});
1311
+ jQuery('#wpvivid_add_tab_key').css({'pointer-events': 'none', 'opacity': '1'});
1312
+ jQuery('#wpvivid_add_tab_log').css({'pointer-events': 'none', 'opacity': '1'});
1313
+ jQuery('#wpvivid_add_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
1314
+ jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'none', 'opacity': '1'});
1315
+ jQuery('#wpvivid_replace_domain').css({'pointer-events': 'none', 'opacity': '1'});
1316
+ jQuery('#wpvivid_keep_domain').css({'pointer-events': 'none', 'opacity': '1'});
1317
+ }
1318
+
1319
+ /**
1320
+ * Unlock the operations once restore task completed.
1321
+ */
1322
+ function wpvivid_restore_unlock(){
1323
+ jQuery('#wpvivid_postbox_backup_percent').css({'pointer-events': 'auto', 'opacity': '1'});
1324
+ jQuery('#wpvivid_postbox_backup').css({'pointer-events': 'auto', 'opacity': '1'});
1325
+ jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'auto', 'opacity': '1'});
1326
+ jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1327
+ jQuery('#wpvivid_tab_backup').css({'pointer-events': 'auto', 'opacity': '1'});
1328
+ jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'auto', 'opacity': '1'});
1329
+ jQuery('#wpvivid_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
1330
+ jQuery('#page-backups').css({'pointer-events': 'auto', 'opacity': '1'});
1331
+ jQuery('#storage-page').css({'pointer-events': 'auto', 'opacity': '1'});
1332
+ jQuery('#settings-page').css({'pointer-events': 'auto', 'opacity': '1'});
1333
+ jQuery('#debug-page').css({'pointer-events': 'auto', 'opacity': '1'});
1334
+ jQuery('#logs-page').css({'pointer-events': 'auto', 'opacity': '1'});
1335
+ jQuery('#wpvivid_tab_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
1336
+ jQuery('#wpvivid_add_tab_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
1337
+ jQuery('#wpvivid_add_tab_import').css({'pointer-events': 'auto', 'opacity': '1'});
1338
+ jQuery('#wpvivid_add_tab_key').css({'pointer-events': 'auto', 'opacity': '1'});
1339
+ jQuery('#wpvivid_add_tab_log').css({'pointer-events': 'auto', 'opacity': '1'});
1340
+ jQuery('#wpvivid_add_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
1341
+ jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
1342
+ jQuery('#wpvivid_replace_domain').css({'pointer-events': 'auto', 'opacity': '1'});
1343
+ jQuery('#wpvivid_keep_domain').css({'pointer-events': 'auto', 'opacity': '1'});
1344
+ }
1345
+ </script>
1346
+ <?php
1347
+ }
1348
+
1349
+ function wpvivid_backuppage_add_progress_module(){
1350
+ ?>
1351
  <div class="postbox" id="wpvivid_postbox_backup_percent" style="display: none;">
1352
  <div class="action-progress-bar" id="wpvivid_action_progress_bar">
1353
+ <div class="action-progress-bar-percent" id="wpvivid_action_progress_bar_percent" style="height:24px;width:0;"></div>
1354
  </div>
1355
  <div id="wpvivid_estimate_backup_info" style="float: left;">
1356
+ <div class="backup-basic-info"><span><?php _e('Database Size:', 'wpvivid'); ?></span><span id="wpvivid_backup_database_size">N/A</span></div>
1357
+ <div class="backup-basic-info"><span><?php _e('File Size:', 'wpvivid'); ?></span><span id="wpvivid_backup_file_size">N/A</span></div>
1358
  </div>
1359
  <div id="wpvivid_estimate_upload_info" style="float: left;">
1360
+ <div class="backup-basic-info"><span><?php _e('Total Size:', 'wpvivid'); ?></span><span>N/A</span></div>
1361
+ <div class="backup-basic-info"><span><?php _e('Uploaded:', 'wpvivid'); ?></span><span>N/A</span></div>
1362
+ <div class="backup-basic-info"><span><?php _e('Speed:', 'wpvivid'); ?></span><span>N/A</span></div>
1363
  </div>
1364
  <div style="float: left;">
1365
+ <div class="backup-basic-info"><span><?php _e('Network Connection:', 'wpvivid'); ?></span><span>N/A</span></div>
1366
  </div>
1367
  <div style="clear:both;"></div>
1368
  <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing"></p></div>
1369
  <div style="clear: both;"></div>
1370
  <div>
1371
+ <div id="wpvivid_backup_cancel" class="backup-log-btn"><input class="button-primary" id="wpvivid_backup_cancel_btn" type="submit" value="<?php esc_attr_e( 'Cancel', 'wpvivid' ); ?>" /></div>
1372
+ <div id="wpvivid_backup_log" class="backup-log-btn"><input class="button-primary backup-log-btn" id="wpvivid_backup_log_btn" type="submit" value="<?php esc_attr_e( 'Log', 'wpvivid' ); ?>" /></div>
1373
  </div>
1374
  <div style="clear: both;"></div>
1375
+ </div>
1376
+ <script>
1377
+ jQuery('#wpvivid_postbox_backup_percent').on("click", "input", function(){
1378
+ if(jQuery(this).attr('id') === 'wpvivid_backup_cancel_btn'){
1379
+ wpvivid_cancel_backup();
1380
+ }
1381
+ if(jQuery(this).attr('id') === 'wpvivid_backup_log_btn'){
1382
+ wpvivid_read_log('wpvivid_view_backup_task_log');
1383
+ }
1384
+ });
1385
+
1386
+ function wpvivid_cancel_backup(){
1387
+ var ajax_data= {
1388
+ 'action': 'wpvivid_backup_cancel',
1389
+ 'task_id': running_backup_taskid
1390
+ };
1391
+ jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1392
+ wpvivid_post_request(ajax_data, function(data){
1393
+ try {
1394
+ var jsonarray = jQuery.parseJSON(data);
1395
+ jQuery('#wpvivid_current_doing').html(jsonarray.msg);
1396
+ }
1397
+ catch(err){
1398
+ alert(err);
1399
+ }
1400
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
1401
+ jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1402
+ var error_message = wpvivid_output_ajaxerror('cancelling the backup', textStatus, errorThrown);
1403
+ wpvivid_add_notice('Backup', 'Error', error_message);
1404
+ });
1405
+ }
1406
+ </script>
1407
+ <?php
1408
  }
1409
 
1410
+ function wpvivid_backuppage_add_backup_module(){
1411
+ ?>
 
 
 
 
 
 
1412
  <div class="postbox quickbackup" id="wpvivid_postbox_backup">
1413
+ <?php
1414
+ do_action('wpvivid_backup_module_add_sub');
1415
+ ?>
 
 
1416
  </div>
1417
+ <?php
1418
+ }
1419
+
1420
+ function wpvivid_backup_module_add_descript(){
1421
+ $backupdir=WPvivid_Setting::get_backupdir();
1422
+ ?>
1423
+ <h2><span><?php _e( 'Back Up Manually','wpvivid'); ?></span></h2>
1424
+ <div class="quickstart-storage-setting">
1425
+ <span class="list-top-chip backup" name="ismerge" value="1"><?php _e('Local Storage Directory: '); ?></span>
1426
+ <span class="list-top-chip" id="wpvivid_local_storage_path"><?php _e(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backupdir); ?></span>
1427
+ <span class="list-top-chip" id=""><a href="#" onclick="wpvivid_click_switch_page('wrap', 'wpvivid_tab_setting', true);"><?php _e(' rename directory', 'wpvivid'); ?></a></span>
1428
+ </div>
1429
+ <?php
1430
+ }
1431
+
1432
+ function wpvivid_backup_module_add_backup_type(){
1433
+ $backup_type = '';
1434
+ $type_name = 'backup_files';
1435
+ ?>
1436
+ <div class="quickstart-archive-block">
1437
+ <fieldset>
1438
+ <legend class="screen-reader-text"><span>input type="radio"</span></legend>
1439
+ <?php echo apply_filters('wpvivid_add_backup_type', $backup_type, $type_name); ?>
1440
+ <label style="display: none;">
1441
+ <input type="checkbox" option="backup" name="ismerge" value="1" checked />
1442
+ </label><br>
1443
+ </fieldset>
1444
+ </div>
1445
+ <?php
1446
+ }
1447
+
1448
+ function wpvivid_backup_module_add_send_remote(){
1449
+ $pic='';
1450
+ ?>
1451
+ <div class="quickstart-storage-block">
1452
+ <fieldset>
1453
+ <legend class="screen-reader-text"><span>input type="checkbox"</span></legend>
1454
+ <label>
1455
+ <input type="radio" id="wpvivid_backup_local" option="backup_ex" name="local_remote" value="local" checked />
1456
+ <span><?php _e( 'Save Backups to Local', 'wpvivid' ); ?></span>
1457
+ </label><br>
1458
+ <label>
1459
+ <input type="radio" id="wpvivid_backup_remote" option="backup_ex" name="local_remote" value="remote" />
1460
+ <span><?php _e( 'Send Backup to Remote Storage:', 'wpvivid' ); ?></span>
1461
+ </label><br>
1462
+ <div id="upload_storage" style="cursor:pointer;" title="Highlighted icon illuminates that you have choosed a remote storage to store backups">
1463
+ <?php echo apply_filters('wpvivid_schedule_add_remote_pic',$pic); ?>
1464
+ </div>
1465
+ </fieldset>
1466
+ </div>
1467
+ <?php
1468
+ }
1469
+
1470
+ function wpvivid_backup_module_add_exec(){
1471
+ ?>
1472
+ <div class="quickstart-btn" style="padding-top:20px;">
1473
+ <input class="button-primary quickbackup-btn" id="wpvivid_quickbackup_btn" type="submit" value="<?php esc_attr_e( 'Backup Now', 'wpvivid'); ?>" />
1474
+ <div class="schedule-tab-block" style="text-align:center;">
1475
+ <fieldset>
1476
+ <label>
1477
+ <input type="checkbox" id="wpvivid_backup_lock" option="backup" name="lock" />
1478
+ <span><?php _e( 'This backup can only be deleted manually', 'wpvivid' ); ?></span>
1479
+ </label>
1480
+ </fieldset>
1481
+ </div>
1482
+ </div>
1483
+ <script>
1484
+ jQuery('#wpvivid_quickbackup_btn').click(function(){
1485
+ wpvivid_clear_notice('wpvivid_backup_notice');
1486
+ wpvivid_start_backup();
1487
+ });
1488
+
1489
+ function wpvivid_start_backup(){
1490
+ var bcheck=true;
1491
+ var bdownloading=false;
1492
+ if(m_downloading_id !== '') {
1493
+ var descript = 'This request might delete the backup being downloaded, are you sure you want to continue?';
1494
+ var ret = confirm(descript);
1495
+ if (ret === true) {
1496
+ bcheck=true;
1497
+ bdownloading=true;
1498
+ }
1499
+ else{
1500
+ bcheck=false;
1501
+ }
1502
+ }
1503
+ if(bcheck) {
1504
+ var backup_data = wpvivid_ajax_data_transfer('backup');
1505
+ backup_data = JSON.parse(backup_data);
1506
+ jQuery('input:radio[option=backup_ex]').each(function() {
1507
+ if(jQuery(this).prop('checked'))
1508
+ {
1509
+ var key = jQuery(this).prop('name');
1510
+ var value = jQuery(this).prop('value');
1511
+ var json = new Array();
1512
+ if(value == 'local'){
1513
+ json['local']='1';
1514
+ json['remote']='0';
1515
+ }
1516
+ else if(value == 'remote'){
1517
+ json['local']='0';
1518
+ json['remote']='1';
1519
+ }
1520
+ }
1521
+ jQuery.extend(backup_data, json);
1522
+ });
1523
+ backup_data = JSON.stringify(backup_data);
1524
+ var ajax_data = {
1525
+ 'action': 'wpvivid_prepare_backup',
1526
+ 'backup': backup_data
1527
+ };
1528
+ wpvivid_control_backup_lock();
1529
+ jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1530
+ jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1531
+ jQuery('#wpvivid_postbox_backup_percent').show();
1532
+ jQuery('#wpvivid_current_doing').html('Ready to backup. Progress: 0%, running time: 0second.');
1533
+ var percent = '0%';
1534
+ jQuery('#wpvivid_action_progress_bar_percent').css('width', percent);
1535
+ jQuery('#wpvivid_backup_database_size').html('N/A');
1536
+ jQuery('#wpvivid_backup_file_size').html('N/A');
1537
+ jQuery('#wpvivid_current_doing').html('');
1538
+ wpvivid_completed_backup = 1;
1539
+ wpvivid_prepare_backup = true;
1540
+ wpvivid_post_request(ajax_data, function (data) {
1541
+ try {
1542
+ var jsonarray = jQuery.parseJSON(data);
1543
+ if (jsonarray.result === 'failed') {
1544
+ wpvivid_delete_ready_task(jsonarray.error);
1545
+ }
1546
+ else if (jsonarray.result === 'success') {
1547
+ if(bdownloading) {
1548
+ m_downloading_id = '';
1549
+ }
1550
+ m_backup_task_id = jsonarray.task_id;
1551
+ var descript = '';
1552
+ if (jsonarray.check.alert_db === true || jsonarray.check.alter_files === true) {
1553
+ descript = 'The database (the dumping SQL file) might be too large, backing up the database may run out of server memory and result in a backup failure.\n' +
1554
+ 'One or more files might be too large, backing up the file(s) may run out of server memory and result in a backup failure.\n' +
1555
+ 'Click OK button and continue to back up.';
1556
+ var ret = confirm(descript);
1557
+ if (ret === true) {
1558
+ jQuery('#wpvivid_backup_list').html('');
1559
+ jQuery('#wpvivid_backup_list').append(jsonarray.html);
1560
+ wpvivid_backup_now(m_backup_task_id);
1561
+ }
1562
+ else {
1563
+ jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1564
+ jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1565
+ wpvivid_control_backup_unlock();
1566
+ jQuery('#wpvivid_postbox_backup_percent').hide();
1567
+ }
1568
+ }
1569
+ else{
1570
+ jQuery('#wpvivid_backup_list').html('');
1571
+ jQuery('#wpvivid_backup_list').append(jsonarray.html);
1572
+ wpvivid_backup_now(jsonarray.task_id);
1573
+ }
1574
+ }
1575
+ }
1576
+ catch (err) {
1577
+ wpvivid_delete_ready_task(err);
1578
+ }
1579
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
1580
+ var error_message = wpvivid_output_ajaxerror('preparing the backup', textStatus, errorThrown);
1581
+ wpvivid_delete_ready_task(error_message);
1582
+ });
1583
+ }
1584
+ }
1585
+
1586
+ function wpvivid_backup_now(task_id){
1587
+ var ajax_data = {
1588
+ 'action': 'wpvivid_backup_now',
1589
+ 'task_id': task_id
1590
+ };
1591
+ task_retry_times = 0;
1592
+ m_need_update=true;
1593
+ wpvivid_post_request(ajax_data, function(data){
1594
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
1595
+ });
1596
+ }
1597
+
1598
+ function wpvivid_delete_backup_task(task_id){
1599
+ var ajax_data = {
1600
+ 'action': 'wpvivid_delete_task',
1601
+ 'task_id': task_id
1602
+ };
1603
+ wpvivid_post_request(ajax_data, function(data){}, function(XMLHttpRequest, textStatus, errorThrown) {
1604
+ });
1605
+ }
1606
+
1607
+ function wpvivid_control_backup_lock(){
1608
+ jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1609
+ jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1610
+ }
1611
+
1612
+ function wpvivid_control_backup_unlock(){
1613
+ jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1614
+ jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1615
+ }
1616
+
1617
+ function wpvivid_delete_ready_task(error){
1618
+ var ajax_data={
1619
+ 'action': 'wpvivid_delete_ready_task'
1620
+ };
1621
+ wpvivid_post_request(ajax_data, function (data) {
1622
+ try {
1623
+ var jsonarray = jQuery.parseJSON(data);
1624
+ if (jsonarray.result === 'success') {
1625
+ wpvivid_add_notice('Backup', 'Error', error);
1626
+ wpvivid_control_backup_unlock();
1627
+ jQuery('#wpvivid_postbox_backup_percent').hide();
1628
+ }
1629
+ }
1630
+ catch(err){
1631
+ wpvivid_add_notice('Backup', 'Error', err);
1632
+ wpvivid_control_backup_unlock();
1633
+ jQuery('#wpvivid_postbox_backup_percent').hide();
1634
+ }
1635
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
1636
+ setTimeout(function () {
1637
+ wpvivid_delete_ready_task(error);
1638
+ }, 3000);
1639
+ });
1640
+ }
1641
+ </script>
1642
+ <?php
1643
+ }
1644
+
1645
+ function wpvivid_backup_module_add_tips(){
1646
+ ?>
1647
+ <div class="custom-info" style="float:left; width:100%;">
1648
+ <strong><?php _e('Tips', 'wpvivid'); ?></strong><?php _e(': The settings are only for manual backup, which won\'t affect schedule settings.', 'wpvivid'); ?>
1649
+ </div>
1650
+ <?php
1651
  }
1652
 
1653
+ function wpvivid_backuppage_add_schedule_module(){
1654
  $schedule=WPvivid_Schedule::get_schedule();
1655
  if($schedule['enable']){
1656
  $schedule_status='Enabled';
1662
  }
1663
  $last_message = '';
1664
  $last_message = apply_filters('wpvivid_get_last_backup_message', $last_message);
1665
+ ?>
1666
  <div class="postbox qucikbackup-schedule" id="wpvivid_postbox_backup_schedule">
1667
+ <h2><span><?php _e( 'Backup Schedule','wpvivid'); ?></span></h2>
1668
  <div class="schedule-block">
1669
+ <p id="wpvivid_schedule_status"><strong><?php _e('Schedule Status: ', 'wpvivid'); ?></strong><?php _e($schedule_status); ?></p>
1670
  <div id="wpvivid_schedule_info">
1671
+ <p><strong><?php _e('Server Time: ', 'wpvivid'); ?></strong><?php _e(date("l, F d, Y H:i",time())); ?></p>
1672
+ <p><span id="wpvivid_last_backup_msg"><?php _e($last_message); ?></span></p>
1673
+ <p id="wpvivid_next_backup"><strong><?php _e('Next Backup: ', 'wpvivid'); ?></strong><?php _e($next_backup_time); ?></p>
1674
  </div>
1675
  </div>
1676
  </div>
1677
  <div style="clear:both;"></div>
1678
+ <?php
 
1679
  }
1680
 
1681
+
1682
  add_filter('wpvivid_add_backup_type', 'wpvivid_add_backup_type', 11, 2);
1683
  add_action('wpvivid_backup_do_js', 'wpvivid_backup_do_js', 10);
1684
  add_filter('wpvivid_download_backup_descript', 'wpvivid_download_backup_descript', 10);
1685
+ add_filter('wpvivid_restore_website_descript', 'wpvivid_restore_website_descript', 10);
1686
+
 
 
 
 
 
 
 
 
1687
  add_filter('wpvivid_backuppage_load_backuplist', 'wpvivid_backuppage_load_backuplist', 10);
1688
 
1689
+ add_action('wpvivid_backuppage_add_module', 'wpvivid_backuppage_add_progress_module', 10);
1690
+ add_action('wpvivid_backuppage_add_module', 'wpvivid_backuppage_add_backup_module', 11);
1691
+ add_action('wpvivid_backuppage_add_module', 'wpvivid_backuppage_add_schedule_module', 12);
1692
+
1693
+ add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_descript');
1694
+ add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_backup_type');
1695
+ add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_send_remote');
1696
+ add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_exec');
1697
+ add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_tips');
1698
+
1699
  ?>
admin/partials/wpvivid-remote-storage-page-display.php CHANGED
@@ -51,6 +51,279 @@ function wpvivid_add_page_storage_list()
51
  </table>
52
  </div>
53
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  <?php
55
  }
56
 
@@ -116,16 +389,12 @@ function wpvivid_storage_list($html)
116
  </script>';
117
  return $html;
118
  }
119
- // <h2 class="nav-tab-wrapper" style="padding-bottom:0!important;">
120
- // <?php do_action('wpvivid_storage_add_tab');
121
- // </h2>
122
- // <?php do_action('wpvivid_storage_add_page');
123
-
124
- //add_action('wpvivid_storage_add_tab', 'wpvivid_add_tab_storage_list', 10);
125
- //add_action('wpvivid_storage_add_tab', 'wpvivid_add_tab_storage_edit', 11);
126
- //add_action('wpvivid_storage_add_page', 'wpvivid_add_page_storage_list', 10);
127
- //add_action('wpvivid_storage_add_page', 'wpvivid_add_page_storage_edit', 11);
128
- add_filter('wpvivid_storage_list','wpvivid_storage_list',10);
129
  ?>
130
 
131
 
51
  </table>
52
  </div>
53
  </div>
54
+ <script>
55
+ jQuery('input[option=add-remote]').click(function(){
56
+ var storage_type = jQuery(".storage-providers-active").attr("remote_type");
57
+ wpvivid_add_remote_storage(storage_type);
58
+ wpvivid_settings_changed = false;
59
+ });
60
+
61
+ jQuery('input[option=edit-remote]').click(function(){
62
+ wpvivid_edit_remote_storage();
63
+ });
64
+
65
+ jQuery('#wpvivid_set_default_remote_storage').click(function(){
66
+ wpvivid_set_default_remote_storage();
67
+ wpvivid_settings_changed = false;
68
+ });
69
+
70
+ /**
71
+ * Add remote storages to the list
72
+ *
73
+ * @param action - The action to add or test a remote storage
74
+ * @param storage_type - Remote storage types (Amazon S3, SFTP and FTP server)
75
+ */
76
+ function wpvivid_add_remote_storage(storage_type)
77
+ {
78
+ var remote_from = wpvivid_ajax_data_transfer(storage_type);
79
+ var ajax_data;
80
+ ajax_data = {
81
+ 'action': 'wpvivid_add_remote',
82
+ 'remote': remote_from,
83
+ 'type': storage_type
84
+ };
85
+ jQuery('input[option=add-remote]').css({'pointer-events': 'nano', 'opacity': '0.4'});
86
+ jQuery('#wpvivid_remote_notice').html('');
87
+ wpvivid_post_request(ajax_data, function (data)
88
+ {
89
+ try
90
+ {
91
+ var jsonarray = jQuery.parseJSON(data);
92
+ if (jsonarray.result === 'success')
93
+ {
94
+ jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
95
+ jQuery('input:text[option='+storage_type+']').each(function(){
96
+ jQuery(this).val('');
97
+ });
98
+ jQuery('input:password[option='+storage_type+']').each(function(){
99
+ jQuery(this).val('');
100
+ });
101
+ wpvivid_handle_remote_storage_data(data);
102
+ }
103
+ else if (jsonarray.result === 'failed')
104
+ {
105
+ jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
106
+ jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
107
+ }
108
+ }
109
+ catch (err)
110
+ {
111
+ alert(err);
112
+ jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
113
+ }
114
+
115
+ }, function (XMLHttpRequest, textStatus, errorThrown)
116
+ {
117
+ var error_message = wpvivid_output_ajaxerror('adding the remote storage', textStatus, errorThrown);
118
+ alert(error_message);
119
+ jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
120
+ });
121
+ }
122
+
123
+ function wpvivid_edit_remote_storage() {
124
+ var data_tran = 'edit-'+wpvivid_editing_storage_type;
125
+ var remote_data = wpvivid_ajax_data_transfer(data_tran);
126
+ var ajax_data;
127
+ ajax_data = {
128
+ 'action': 'wpvivid_edit_remote',
129
+ 'remote': remote_data,
130
+ 'id': wpvivid_editing_storage_id,
131
+ 'type': wpvivid_editing_storage_type
132
+ };
133
+ jQuery('#wpvivid_remote_notice').html('');
134
+ wpvivid_post_request(ajax_data, function(data){
135
+ try {
136
+ var jsonarray = jQuery.parseJSON(data);
137
+ if (jsonarray.result === 'success') {
138
+ jQuery('#wpvivid_tab_storage_edit').hide();
139
+ wpvivid_click_switch_page('storage', 'wpvivid_tab_storage_list', true);
140
+ wpvivid_handle_remote_storage_data(data);
141
+ }
142
+ else if (jsonarray.result === 'failed') {
143
+ jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
144
+ }
145
+ }
146
+ catch(err){
147
+ alert(err);
148
+ }
149
+ },function(XMLHttpRequest, textStatus, errorThrown) {
150
+ var error_message = wpvivid_output_ajaxerror('editing the remote storage', textStatus, errorThrown);
151
+ alert(error_message);
152
+ });
153
+ }
154
+
155
+ /**
156
+ * Set a default remote storage for backups.
157
+ */
158
+ function wpvivid_set_default_remote_storage(){
159
+ var remote_storage = new Array();
160
+ //remote_storage[0] = jQuery("input[name='remote_storage']:checked").val();
161
+ jQuery.each(jQuery("input[name='remote_storage']:checked"), function()
162
+ {
163
+ remote_storage.push(jQuery(this).val());
164
+ });
165
+
166
+ var ajax_data = {
167
+ 'action': 'wpvivid_set_default_remote_storage',
168
+ 'remote_storage': remote_storage
169
+ };
170
+ jQuery('#wpvivid_remote_notice').html('');
171
+ wpvivid_post_request(ajax_data, function(data){
172
+ wpvivid_handle_remote_storage_data(data);
173
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
174
+ var error_message = wpvivid_output_ajaxerror('setting up the default remote storage', textStatus, errorThrown);
175
+ alert(error_message);
176
+ });
177
+ }
178
+
179
+ jQuery('#wpvivid_remote_storage_list').on("click", "input", function(){
180
+ var check_status = true;
181
+ if(jQuery(this).prop('checked') === true){
182
+ check_status = true;
183
+ }
184
+ else {
185
+ check_status = false;
186
+ }
187
+ jQuery('input[name="remote_storage"]').prop('checked', false);
188
+ if(check_status === true){
189
+ jQuery(this).prop('checked', true);
190
+ }
191
+ else {
192
+ jQuery(this).prop('checked', false);
193
+ }
194
+ });
195
+
196
+ function wpvivid_delete_remote_storage(storage_id){
197
+ var descript = 'Deleting a remote storage will make it unavailable until it is added again. Are you sure to continue?';
198
+ var ret = confirm(descript);
199
+ if(ret === true){
200
+ var ajax_data = {
201
+ 'action': 'wpvivid_delete_remote',
202
+ 'remote_id': storage_id
203
+ };
204
+ wpvivid_post_request(ajax_data, function(data){
205
+ wpvivid_handle_remote_storage_data(data);
206
+ },function(XMLHttpRequest, textStatus, errorThrown) {
207
+ var error_message = wpvivid_output_ajaxerror('deleting the remote storage', textStatus, errorThrown);
208
+ alert(error_message);
209
+ });
210
+ }
211
+ }
212
+
213
+ function wpvivid_handle_remote_storage_data(data){
214
+ var i = 0;
215
+ try {
216
+ var jsonarray = jQuery.parseJSON(data);
217
+ if (jsonarray.result === 'success') {
218
+ jQuery('#wpvivid_remote_storage_list').html('');
219
+ jQuery('#wpvivid_remote_storage_list').append(jsonarray.html);
220
+ jQuery('#upload_storage').html(jsonarray.pic);
221
+ jQuery('#schedule_upload_storage').html(jsonarray.pic);
222
+ jQuery('#wpvivid_out_of_date_remote_path').html(jsonarray.dir);
223
+ jQuery('#wpvivid_schedule_backup_local_remote').html(jsonarray.local_remote);
224
+ wpvivid_control_remote_storage(jsonarray.remote_storage);
225
+ jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
226
+ }
227
+ else if(jsonarray.result === 'failed'){
228
+ alert(jsonarray.error);
229
+ }
230
+ }
231
+ catch(err){
232
+ alert(err);
233
+ }
234
+ }
235
+
236
+ function wpvivid_control_remote_storage(has_remote){
237
+ if(!has_remote){
238
+ if(jQuery("input:radio[name='save_local_remote'][value='remote']").prop('checked')) {
239
+ alert("There is no default remote storage configured. Please set it up first.");
240
+ jQuery("input:radio[name='save_local_remote'][value='local']").prop('checked', true);
241
+ }
242
+ }
243
+ }
244
+
245
+ function click_retrieve_remote_storage(id,type,name)
246
+ {
247
+ wpvivid_editing_storage_id = id;
248
+ jQuery('.remote-storage-edit').hide();
249
+ jQuery('#wpvivid_tab_storage_edit').show();
250
+ jQuery('#wpvivid_tab_storage_edit_text').html(name);
251
+ wpvivid_editing_storage_type=type;
252
+ jQuery('#remote_storage_edit_'+wpvivid_editing_storage_type).fadeIn();
253
+ wpvivid_click_switch_page('storage', 'wpvivid_tab_storage_edit', true);
254
+
255
+ var ajax_data = {
256
+ 'action': 'wpvivid_retrieve_remote',
257
+ 'remote_id': id
258
+ };
259
+ wpvivid_post_request(ajax_data, function(data)
260
+ {
261
+ try
262
+ {
263
+ var jsonarray = jQuery.parseJSON(data);
264
+ if (jsonarray.result === 'success')
265
+ {
266
+ jQuery('input:text[option=edit-'+jsonarray.type+']').each(function(){
267
+ var key = jQuery(this).prop('name');
268
+ if(key == 's3Path' && jsonarray.type == 'amazons3'){
269
+ var iLength = jsonarray[key].lastIndexOf('/wpvivid_backup');
270
+ if(iLength != -1) {
271
+ jsonarray[key] = jsonarray[key].substring(0, iLength);
272
+ }
273
+ jQuery(this).val(jsonarray[key]);
274
+ }
275
+ else {
276
+ jQuery(this).val(jsonarray[key]);
277
+ }
278
+ });
279
+ jQuery('input:password[option=edit-'+jsonarray.type+']').each(function(){
280
+ var key = jQuery(this).prop('name');
281
+ jQuery(this).val(jsonarray[key]);
282
+ });
283
+ jQuery('input:checkbox[option=edit-'+jsonarray.type+']').each(function() {
284
+ var key = jQuery(this).prop('name');
285
+ var value;
286
+ if(jsonarray[key] == '0'){
287
+ value = false;
288
+ }
289
+ else{
290
+ value = true;
291
+ }
292
+ jQuery(this).prop('checked', value);
293
+ });
294
+ if(jsonarray.type == 'amazons3'){
295
+ var amazons3_edit_value = jQuery('input:text[option=edit-'+jsonarray.type+'][name=s3Path]').val();
296
+ if(amazons3_edit_value == ''){
297
+ amazons3_edit_value = '*';
298
+ }
299
+ amazons3_edit_value = amazons3_edit_value + '/wpvivid_backup';
300
+ jQuery('#wpvivid_edit_amazons3_root_path').html(amazons3_edit_value);
301
+ }
302
+ if(jsonarray.type == 's3compat'){
303
+ var dos_edit_value = jQuery('input:text[option=edit-'+jsonarray.type+'][name=s3directory]').val();
304
+ if(dos_edit_value == ''){
305
+ dos_edit_value = '*';
306
+ }
307
+ dos_edit_value = dos_edit_value + '/wpvivid_backup';
308
+ jQuery('#wpvivid_edit_dos_root_path').html(dos_edit_value);
309
+ }
310
+ }
311
+ else
312
+ {
313
+ alert(jsonarray.error);
314
+ }
315
+ }
316
+ catch(err)
317
+ {
318
+ alert(err);
319
+ }
320
+ },function(XMLHttpRequest, textStatus, errorThrown)
321
+ {
322
+ var error_message = wpvivid_output_ajaxerror('retrieving the remote storage', textStatus, errorThrown);
323
+ alert(error_message);
324
+ });
325
+ }
326
+ </script>
327
  <?php
328
  }
329
 
389
  </script>';
390
  return $html;
391
  }
392
+
393
+ add_action('wpvivid_storage_add_tab', 'wpvivid_add_tab_storage_list', 10);
394
+ add_action('wpvivid_storage_add_tab', 'wpvivid_add_tab_storage_edit', 11);
395
+ add_action('wpvivid_storage_add_page', 'wpvivid_add_page_storage_list', 10);
396
+ add_action('wpvivid_storage_add_page', 'wpvivid_add_page_storage_edit', 11);
397
+ //add_filter('wpvivid_storage_list','wpvivid_storage_list',10);
 
 
 
 
398
  ?>
399
 
400
 
admin/partials/wpvivid-settings-page-display.php CHANGED
@@ -21,6 +21,17 @@ function wpvivid_general_settings()
21
  $wpvivid_show_tab_menu = '';
22
  }
23
  }
 
 
 
 
 
 
 
 
 
 
 
24
  if(!isset($general_setting['options']['wpvivid_common_setting']['domain_include'])){
25
  $wpvivid_domain_include = 'checked';
26
  }
@@ -32,8 +43,8 @@ function wpvivid_general_settings()
32
  $wpvivid_domain_include = '';
33
  }
34
  }
35
- global $wpvivid_pulgin;
36
- $out_of_date=$wpvivid_pulgin->_get_out_of_date_info();
37
  ?>
38
  <tr>
39
  <td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell"><?php _e('General Settings', 'wpvivid'); ?></label></td>
@@ -65,6 +76,12 @@ function wpvivid_general_settings()
65
  <span><?php _e('Display the tab pages in admin navigation menu', 'wpvivid'); ?></span>
66
  </label>
67
  </div>
 
 
 
 
 
 
68
  </div>
69
  <div class="postbox schedule-tab-block">
70
  <div><strong><?php _e('Backup Folder', 'wpvivid'); ?></strong></div>
@@ -103,45 +120,39 @@ function wpvivid_general_settings()
103
  </div>
104
  </td>
105
  </tr>
106
- <?php
107
- }
 
 
108
 
109
- function wpvivid_compressing()
110
- {
111
- $general_setting=WPvivid_Setting::get_setting(true, "");
112
- $wpvivid_setting_no_compress='';
113
- $wpvivid_setting_compress='';
114
- if($general_setting['options']['wpvivid_compress_setting']['no_compress']){
115
- $wpvivid_setting_no_compress='checked';
116
- }
117
- else{
118
- $wpvivid_setting_compress='checked';
119
- }
120
- ?>
121
- <tr>
122
- <td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell" id="wpvivid_archive_type_item"><?php _e('Choose How to Archive Your Backups', 'wpvivid'); ?></label></td>
123
- <td class="tablelistcolumn">
124
- <div class="postbox schedule-tab-block setting-page-content" id="wpvivid_archive_type">
125
- <fieldset>
126
- <label>
127
- <input type="radio" option="setting" name="no_compress" value="1" <?php esc_attr_e($wpvivid_setting_no_compress, 'wpvivid'); ?> />
128
- <span><?php _e( 'Only Archive without compressing', 'wpvivid' ); ?></span>
129
- <span><?php _e( 'It will cause a lower CPU Usage and is recommended in a web hosting/ shared hosting environment.', 'wpvivid' ); ?></span>
130
- </label><br>
131
- <label>
132
- <input type="radio" option="setting" name="no_compress" value="0" <?php esc_attr_e($wpvivid_setting_compress, 'wpvivid'); ?> />
133
- <span><?php _e( 'Compress and Archive', 'wpvivid' ); ?></span>
134
- <span><?php _e( 'It will cause a higher CPU Usage and is recommended in a VPS/ dedicated hosting environment.', 'wpvivid' ); ?></span>
135
- </label>
136
- <label style="display: none;">
137
- <input type="radio" option="setting" name="compress_type" value="zip" checked />
138
- <input type="radio" option="setting" name="use_temp_file" value="1" checked />
139
- <input type="radio" option="setting" name="use_temp_size" value="16" checked />
140
- </label>
141
- </fieldset>
142
- </div>
143
- </td>
144
- </tr>
145
  <?php
146
  }
147
 
@@ -200,13 +211,46 @@ function wpvivid_email_report()
200
  </div>
201
  </td>
202
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  <?php
204
  }
205
 
206
  function wpvivid_clean_junk()
207
  {
208
- global $wpvivid_pulgin;
209
- $junk_file=$wpvivid_pulgin->_junk_files_info();
210
  ?>
211
  <tr>
212
  <td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell" id="wpvivid_clean_junk_item"><?php _e('Clean Junk', 'wpvivid'); ?></label></td>
@@ -249,6 +293,97 @@ function wpvivid_clean_junk()
249
  </div>
250
  </td>
251
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  <?php
253
  }
254
 
@@ -272,6 +407,63 @@ function wpvivid_export_import_settings()
272
  </div>
273
  </td>
274
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  <?php
276
  }
277
 
@@ -352,7 +544,7 @@ function wpvivid_advanced_settings()
352
  <div><strong><?php _e('Compress Files Every', 'wpvivid'); ?></strong></div>
353
  <div class="schedule-tab-block setting-page-content">
354
  <input type="text" placeholder="400" option="setting" name="max_file_size" id="wpvivid_max_zip" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_compress_setting']['max_file_size']), 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
355
- <div><p><?php _e( 'Some web hosting providers limit large zip files (e.g. 200MB), and therefore splitting your backup into many parts is an ideal way to avoid to hit the limitation if you are running a big website. Please try to adjust the value if you are encountering backup errors. If you use a value of 0 MB, any backup files won\'t be split.', 'wpvivid' ); ?></div></p>
356
  </div>
357
  <div><strong><?php _e('Exclude the files which are larger than', 'wpvivid'); ?></strong></div>
358
  <div class="schedule-tab-block setting-page-content">
@@ -402,9 +594,8 @@ function wpvivid_advanced_settings()
402
  }
403
 
404
  add_action('wpvivid_setting_add_cell','wpvivid_general_settings',10);
405
- //add_action('wpvivid_setting_add_cell','wpvivid_compressing',12);
406
- add_action('wpvivid_setting_add_cell','wpvivid_email_report',13);
407
- add_action('wpvivid_setting_add_cell','wpvivid_clean_junk',14);
408
- add_action('wpvivid_setting_add_cell','wpvivid_advanced_settings',15);
409
  add_action('wpvivid_setting_add_cell','wpvivid_export_import_settings',16);
410
  ?>
21
  $wpvivid_show_tab_menu = '';
22
  }
23
  }
24
+ if(!isset($general_setting['options']['wpvivid_common_setting']['show_admin_bar'])){
25
+ $show_admin_bar = 'checked';
26
+ }
27
+ else{
28
+ if($general_setting['options']['wpvivid_common_setting']['show_admin_bar']){
29
+ $show_admin_bar = 'checked';
30
+ }
31
+ else{
32
+ $show_admin_bar = '';
33
+ }
34
+ }
35
  if(!isset($general_setting['options']['wpvivid_common_setting']['domain_include'])){
36
  $wpvivid_domain_include = 'checked';
37
  }
43
  $wpvivid_domain_include = '';
44
  }
45
  }
46
+ global $wpvivid_plugin;
47
+ $out_of_date=$wpvivid_plugin->_get_out_of_date_info();
48
  ?>
49
  <tr>
50
  <td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell"><?php _e('General Settings', 'wpvivid'); ?></label></td>
76
  <span><?php _e('Display the tab pages in admin navigation menu', 'wpvivid'); ?></span>
77
  </label>
78
  </div>
79
+ <div>
80
+ <label>
81
+ <input type="checkbox" option="setting" name="show_admin_bar" <?php esc_attr_e($show_admin_bar); ?> />
82
+ <span><?php _e('Show WPvivid backup plugin on top admin bar', 'wpvivid'); ?></span>
83
+ </label>
84
+ </div>
85
  </div>
86
  <div class="postbox schedule-tab-block">
87
  <div><strong><?php _e('Backup Folder', 'wpvivid'); ?></strong></div>
120
  </div>
121
  </td>
122
  </tr>
123
+ <script>
124
+ jQuery('#wpvivid_delete_out_of_backup').click(function(){
125
+ wpvivid_delete_out_of_date_backups();
126
+ });
127
 
128
+ /**
129
+ * This function will delete out of date backups.
130
+ */
131
+ function wpvivid_delete_out_of_date_backups(){
132
+ var ajax_data={
133
+ 'action': 'wpvivid_clean_out_of_date_backup'
134
+ };
135
+ jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'none', 'opacity': '0.4'});
136
+ wpvivid_post_request(ajax_data, function(data){
137
+ jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
138
+ try {
139
+ var jsonarray = jQuery.parseJSON(data);
140
+ if (jsonarray.result === "success") {
141
+ alert("Out of date backups have been removed.");
142
+ wpvivid_handle_backup_data(data);
143
+ }
144
+ }
145
+ catch(err){
146
+ alert(err);
147
+ jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
148
+ }
149
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
150
+ var error_message = wpvivid_output_ajaxerror('deleting out of date backups', textStatus, errorThrown);
151
+ alert(error_message);
152
+ jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
153
+ });
154
+ }
155
+ </script>
 
 
 
 
 
 
 
 
156
  <?php
157
  }
158
 
211
  </div>
212
  </td>
213
  </tr>
214
+ <script>
215
+ jQuery('#wpvivid_send_email_test').click(function(){
216
+ wpvivid_email_test();
217
+ });
218
+
219
+ /**
220
+ * After enabling email report feature, and test if an email address works or not
221
+ */
222
+ function wpvivid_email_test(){
223
+ var mail = jQuery('#wpvivid_mail').val();
224
+ var ajax_data = {
225
+ 'action': 'wpvivid_test_send_mail',
226
+ 'send_to': mail
227
+ };
228
+ wpvivid_post_request(ajax_data, function(data){
229
+ try {
230
+ var jsonarray = jQuery.parseJSON(data);
231
+ if (jsonarray.result === 'success') {
232
+ jQuery('#wpvivid_send_email_res').html('Test succeeded.');
233
+ }
234
+ else {
235
+ jQuery('#wpvivid_send_email_res').html('Test failed, ' + jsonarray.error);
236
+ }
237
+ }
238
+ catch(err){
239
+ alert(err);
240
+ }
241
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
242
+ var error_message = wpvivid_output_ajaxerror('sending test mail', textStatus, errorThrown);
243
+ alert(error_message);
244
+ });
245
+ }
246
+ </script>
247
  <?php
248
  }
249
 
250
  function wpvivid_clean_junk()
251
  {
252
+ global $wpvivid_plugin;
253
+ $junk_file=$wpvivid_plugin->_junk_files_info();
254
  ?>
255
  <tr>
256
  <td class="row-title wpvivid-backup-settings-table-left tablelistcolumn"><label for="tablecell" id="wpvivid_clean_junk_item"><?php _e('Clean Junk', 'wpvivid'); ?></label></td>
293
  </div>
294
  </td>
295
  </tr>
296
+ <script>
297
+ jQuery('#wpvivid_calculate_size').click(function(){
298
+ wpvivid_calculate_diskspaceused();
299
+ });
300
+
301
+ jQuery('#wpvivid_clean_junk_file').click(function(){
302
+ wpvivid_clean_junk_files();
303
+ });
304
+
305
+ /**
306
+ * Calculate the server disk space in use by WPvivid.
307
+ */
308
+ function wpvivid_calculate_diskspaceused(){
309
+ var ajax_data={
310
+ 'action': 'wpvivid_junk_files_info'
311
+ };
312
+ var current_size = jQuery('#wpvivid_junk_sum_size').html();
313
+ jQuery('#wpvivid_calculate_size').css({'pointer-events': 'none', 'opacity': '0.4'});
314
+ jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'none', 'opacity': '0.4'});
315
+ jQuery('#wpvivid_junk_sum_size').html("calculating...");
316
+ wpvivid_post_request(ajax_data, function(data){
317
+ jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
318
+ jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
319
+ try {
320
+ var jsonarray = jQuery.parseJSON(data);
321
+ if (jsonarray.result === "success") {
322
+ jQuery('#wpvivid_junk_sum_size').html(jsonarray.data.sum_size);
323
+ jQuery('#wpvivid_junk_log_path').html(jsonarray.data.log_path);
324
+ jQuery('#wpvivid_junk_file_path').html(jsonarray.data.junk_path);
325
+ jQuery('#wpvivid_restore_temp_file_path').html(jsonarray.data.old_files_path);
326
+ }
327
+ }
328
+ catch(err){
329
+ alert(err);
330
+ jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
331
+ jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
332
+ jQuery('#wpvivid_junk_sum_size').html(current_size);
333
+ }
334
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
335
+ var error_message = wpvivid_output_ajaxerror('calculating server disk space in use by WPvivid', textStatus, errorThrown);
336
+ alert(error_message);
337
+ jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
338
+ jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
339
+ jQuery('#wpvivid_junk_sum_size').html(current_size);
340
+ });
341
+ }
342
+
343
+ /**
344
+ * Clean junk files created during backups and restorations off your web server disk.
345
+ */
346
+ function wpvivid_clean_junk_files(){
347
+ var descript = 'The selected item(s) will be permanently deleted. Are you sure you want to continue?';
348
+ var ret = confirm(descript);
349
+ if(ret === true){
350
+ var option_data = wpvivid_ajax_data_transfer('junk-files');
351
+ var ajax_data = {
352
+ 'action': 'wpvivid_clean_local_storage',
353
+ 'options': option_data
354
+ };
355
+ jQuery('#wpvivid_calculate_size').css({'pointer-events': 'none', 'opacity': '0.4'});
356
+ jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'none', 'opacity': '0.4'});
357
+ wpvivid_post_request(ajax_data, function (data) {
358
+ jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
359
+ jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
360
+ jQuery('input[option="junk-files"]').prop('checked', false);
361
+ try {
362
+ var jsonarray = jQuery.parseJSON(data);
363
+ alert(jsonarray.msg);
364
+ if (jsonarray.result === "success") {
365
+ jQuery('#wpvivid_junk_sum_size').html(jsonarray.data.sum_size);
366
+ jQuery('#wpvivid_junk_log_path').html(jsonarray.data.log_path);
367
+ jQuery('#wpvivid_junk_file_path').html(jsonarray.data.junk_path);
368
+ jQuery('#wpvivid_restore_temp_file_path').html(jsonarray.data.old_files_path);
369
+ jQuery('#wpvivid_loglist').html("");
370
+ jQuery('#wpvivid_loglist').append(jsonarray.html);
371
+ wpvivid_log_count = jsonarray.log_count;
372
+ wpvivid_display_log_page();
373
+ }
374
+ }
375
+ catch(err){
376
+ alert(err);
377
+ }
378
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
379
+ var error_message = wpvivid_output_ajaxerror('cleaning out junk files', textStatus, errorThrown);
380
+ alert(error_message);
381
+ jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
382
+ jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
383
+ });
384
+ }
385
+ }
386
+ </script>
387
  <?php
388
  }
389
 
407
  </div>
408
  </td>
409
  </tr>
410
+ <script>
411
+ jQuery('#wpvivid_setting_export').click(function(){
412
+ wpvivid_export_settings();
413
+ });
414
+
415
+ jQuery('#wpvivid_setting_import').click(function(){
416
+ wpvivid_import_settings();
417
+ });
418
+
419
+ /**
420
+ * This function will export settings to local folder
421
+ */
422
+ function wpvivid_export_settings() {
423
+ wpvivid_location_href=true;
424
+ location.href =ajaxurl+'?action=wpvivid_export_setting&setting=1&history=1&review=0';
425
+ }
426
+
427
+ /**
428
+ * This function will import the previous exported settings
429
+ */
430
+ function wpvivid_import_settings(){
431
+ var files = jQuery('input[name="fileTrans"]').prop('files');
432
+
433
+ if(files.length == 0){
434
+ alert('Choose a settings file and import it by clicking Import button.');
435
+ return;
436
+ }
437
+ else{
438
+ var reader = new FileReader();
439
+ reader.readAsText(files[0], "UTF-8");
440
+ reader.onload = function(evt){
441
+ var fileString = evt.target.result;
442
+ var ajax_data = {
443
+ 'action': 'wpvivid_import_setting',
444
+ 'data': fileString
445
+ };
446
+ wpvivid_post_request(ajax_data, function(data){
447
+ try {
448
+ var jsonarray = jQuery.parseJSON(data);
449
+ if (jsonarray.result === 'success') {
450
+ location.reload();
451
+ }
452
+ else {
453
+ alert('Error: ' + jsonarray.error);
454
+ }
455
+ }
456
+ catch(err){
457
+ alert(err);
458
+ }
459
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
460
+ var error_message = wpvivid_output_ajaxerror('importing the previously-exported settings', textStatus, errorThrown);
461
+ jQuery('#wpvivid_display_log_content').html(error_message);
462
+ });
463
+ }
464
+ }
465
+ }
466
+ </script>
467
  <?php
468
  }
469
 
544
  <div><strong><?php _e('Compress Files Every', 'wpvivid'); ?></strong></div>
545
  <div class="schedule-tab-block setting-page-content">
546
  <input type="text" placeholder="400" option="setting" name="max_file_size" id="wpvivid_max_zip" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_compress_setting']['max_file_size']), 'wpvivid'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
547
+ <div><p><?php _e( 'Some web hosting providers limit large zip files (e.g. 200MB), and therefore splitting your backup into many parts is an ideal way to avoid hitting the limitation if you are running a big website. Please try to adjust the value if you are encountering backup errors. If you use a value of 0 MB, any backup files won\'t be split.', 'wpvivid' ); ?></div></p>
548
  </div>
549
  <div><strong><?php _e('Exclude the files which are larger than', 'wpvivid'); ?></strong></div>
550
  <div class="schedule-tab-block setting-page-content">
594
  }
595
 
596
  add_action('wpvivid_setting_add_cell','wpvivid_general_settings',10);
597
+ add_action('wpvivid_setting_add_cell','wpvivid_advanced_settings',13);
598
+ add_action('wpvivid_setting_add_cell','wpvivid_email_report',14);
599
+ add_action('wpvivid_setting_add_cell','wpvivid_clean_junk',15);
 
600
  add_action('wpvivid_setting_add_cell','wpvivid_export_import_settings',16);
601
  ?>
includes/class-wpvivid-backup-database.php CHANGED
@@ -15,7 +15,7 @@ class WPvivid_Backup_Database
15
 
16
  public function backup_database($data,$task_id = '')
17
  {
18
- global $wpvivid_pulgin;
19
  $dump=null;
20
 
21
  try
@@ -63,7 +63,7 @@ class WPvivid_Backup_Database
63
  }
64
  if(!empty($str_last_query_string))
65
  {
66
- $wpvivid_pulgin->wpvivid_log->WriteLog('last query string:'.$str_last_query_string,'error');
67
  }
68
  $message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
69
  return array('result'=>WPVIVID_FAILED,'error'=>$message);
15
 
16
  public function backup_database($data,$task_id = '')
17
  {
18
+ global $wpvivid_plugin;
19
  $dump=null;
20
 
21
  try
63
  }
64
  if(!empty($str_last_query_string))
65
  {
66
+ $wpvivid_plugin->wpvivid_log->WriteLog('last query string:'.$str_last_query_string,'error');
67
  }
68
  $message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
69
  return array('result'=>WPVIVID_FAILED,'error'=>$message);
includes/class-wpvivid-backup-uploader.php CHANGED
@@ -27,7 +27,7 @@ class Wpvivid_BackupUploader
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;
@@ -70,7 +70,7 @@ class Wpvivid_BackupUploader
70
  $id=substr($id,0,strlen($id)-1);
71
 
72
 
73
- if(WPvivid_Backuplist::get_backuplist_by_key($id)===false)
74
  {
75
  $backup_id=$id;
76
  return true;
@@ -148,11 +148,11 @@ class Wpvivid_BackupUploader
148
  if($id === ''){
149
  $id=uniqid('wpvivid-');
150
  }
151
- global $wpvivid_pulgin;
152
- $wpvivid_pulgin->upload_log=new WPvivid_Log();
153
- $wpvivid_pulgin->upload_log->CreateLogFile($id.'_upload','no_folder','upload');
154
- $wpvivid_pulgin->upload_log->WriteLogHander();
155
- $wpvivid_pulgin->upload_log->WriteLog($message,'notice');
156
  }
157
 
158
  function upload_files_finish()
@@ -197,12 +197,12 @@ class Wpvivid_BackupUploader
197
  }
198
  }
199
  if($check_result === true){
200
- global $wpvivid_pulgin;
201
- $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
202
- $wpvivid_pulgin->wpvivid_log->CreateLogFile($id.'_upload','no_folder','upload');
203
- $wpvivid_pulgin->wpvivid_log->WriteLogHander();
204
- $wpvivid_pulgin->wpvivid_log->WriteLog('Upload finished.','notice');
205
- WPvivid_Backuplist::add_new_upload_backup($id,$backup_data,$wpvivid_pulgin->wpvivid_log->log_file);
206
  $html = '';
207
  $html = apply_filters('wpvivid_add_backup_list', $html);
208
  $ret['result']=WPVIVID_SUCCESS;
@@ -294,12 +294,12 @@ class Wpvivid_BackupUploader
294
  @closedir($handler);
295
  }
296
  else{
297
- global $wpvivid_pulgin;
298
- $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
299
  $id=uniqid('wpvivid-');
300
- $wpvivid_pulgin->wpvivid_log->CreateLogFile($id.'_scan','no_folder','scan');
301
- $wpvivid_pulgin->wpvivid_log->WriteLogHander();
302
- $wpvivid_pulgin->wpvivid_log->WriteLog('Failed to get local storage directory.','notice');
303
  $ret['result']=WPVIVID_FAILED;
304
  $ret['error']='Failed to get local storage directory.';
305
  }
@@ -316,18 +316,18 @@ class Wpvivid_BackupUploader
316
  $add_file['size']=filesize($path.$file);
317
  $backup_data['files'][]=$add_file;
318
  }
319
- global $wpvivid_pulgin;
320
- $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
321
- $wpvivid_pulgin->wpvivid_log->CreateLogFile($backup_id.'_scan','no_folder','scan');
322
- $wpvivid_pulgin->wpvivid_log->WriteLogHander();
323
- $wpvivid_pulgin->wpvivid_log->WriteLog('Upload finished.','notice');
324
- WPvivid_Backuplist::add_new_upload_backup($backup_id,$backup_data,$wpvivid_pulgin->wpvivid_log->log_file);
325
  }
326
  }
327
  $ret['result']=WPVIVID_SUCCESS;
328
  $html = '';
329
  $tour = true;
330
- $html = apply_filters('wpvivid_add_backup_list', $html, $tour);
331
  $ret['html'] = $html;
332
  echo json_encode($ret);
333
  die();
@@ -354,8 +354,8 @@ class Wpvivid_BackupUploader
354
  try {
355
  var jsonarray = jQuery.parseJSON(data);
356
  if(jsonarray.html !== false){
357
- jQuery('#wpvivid_backuplist').html('');
358
- jQuery('#wpvivid_backuplist').append(jsonarray.html);
359
  wpvivid_popup_tour('show');
360
  }
361
  }
@@ -482,11 +482,13 @@ class Wpvivid_BackupUploader
482
  wpvivid_check_plupload_added_files(up,files);
483
  }
484
  else if(jsonarray.result === "failed") {
 
485
  alert(jsonarray.error);
486
  }
487
  }, function (XMLHttpRequest, textStatus, errorThrown)
488
  {
489
  var error_message = wpvivid_output_ajaxerror('uploading backups', textStatus, errorThrown);
 
490
  alert(error_message);
491
  });
492
  }
@@ -579,8 +581,8 @@ class Wpvivid_BackupUploader
579
  unlinked = jsonarray.unlinked;
580
  }
581
  alert('The upload has completed. ' + unlinked);
582
- jQuery('#wpvivid_backuplist').html('');
583
- jQuery('#wpvivid_backuplist').append(jsonarray.html);
584
  wpvivid_click_switch_page('backup', 'wpvivid_tab_backup', true);
585
  }
586
  }
27
  {
28
  $id= $matches[0];
29
  $id=substr($id,0,strlen($id)-1);
30
+ if(WPvivid_Backuplist::get_backup_by_id($id)===false)
31
  {
32
  $ret['result']=WPVIVID_SUCCESS;
33
  $ret['id']=$id;
70
  $id=substr($id,0,strlen($id)-1);
71
 
72
 
73
+ if(WPvivid_Backuplist::get_backup_by_id($id)===false)
74
  {
75
  $backup_id=$id;
76
  return true;
148
  if($id === ''){
149
  $id=uniqid('wpvivid-');
150
  }
151
+ global $wpvivid_plugin;
152
+ $wpvivid_plugin->upload_log=new WPvivid_Log();
153
+ $wpvivid_plugin->upload_log->CreateLogFile($id.'_upload','no_folder','upload');
154
+ $wpvivid_plugin->upload_log->WriteLogHander();
155
+ $wpvivid_plugin->upload_log->WriteLog($message,'notice');
156
  }
157
 
158
  function upload_files_finish()
197
  }
198
  }
199
  if($check_result === true){
200
+ global $wpvivid_plugin;
201
+ $wpvivid_plugin->wpvivid_log=new WPvivid_Log();
202
+ $wpvivid_plugin->wpvivid_log->CreateLogFile($id.'_upload','no_folder','upload');
203
+ $wpvivid_plugin->wpvivid_log->WriteLogHander();
204
+ $wpvivid_plugin->wpvivid_log->WriteLog('Upload finished.','notice');
205
+ WPvivid_Backuplist::add_new_upload_backup($id,$backup_data,$wpvivid_plugin->wpvivid_log->log_file);
206
  $html = '';
207
  $html = apply_filters('wpvivid_add_backup_list', $html);
208
  $ret['result']=WPVIVID_SUCCESS;
294
  @closedir($handler);
295
  }
296
  else{
297
+ global $wpvivid_plugin;
298
+ $wpvivid_plugin->wpvivid_log=new WPvivid_Log();
299
  $id=uniqid('wpvivid-');
300
+ $wpvivid_plugin->wpvivid_log->CreateLogFile($id.'_scan','no_folder','scan');
301
+ $wpvivid_plugin->wpvivid_log->WriteLogHander();
302
+ $wpvivid_plugin->wpvivid_log->WriteLog('Failed to get local storage directory.','notice');
303
  $ret['result']=WPVIVID_FAILED;
304
  $ret['error']='Failed to get local storage directory.';
305
  }
316
  $add_file['size']=filesize($path.$file);
317
  $backup_data['files'][]=$add_file;
318
  }
319
+ global $wpvivid_plugin;
320
+ $wpvivid_plugin->wpvivid_log=new WPvivid_Log();
321
+ $wpvivid_plugin->wpvivid_log->CreateLogFile($backup_id.'_scan','no_folder','scan');
322
+ $wpvivid_plugin->wpvivid_log->WriteLogHander();
323
+ $wpvivid_plugin->wpvivid_log->WriteLog('Upload finished.','notice');
324
+ WPvivid_Backuplist::add_new_upload_backup($backup_id,$backup_data,$wpvivid_plugin->wpvivid_log->log_file);
325
  }
326
  }
327
  $ret['result']=WPVIVID_SUCCESS;
328
  $html = '';
329
  $tour = true;
330
+ $html = apply_filters('wpvivid_add_backup_list', $html, 'wpvivid_backup_list', $tour);
331
  $ret['html'] = $html;
332
  echo json_encode($ret);
333
  die();
354
  try {
355
  var jsonarray = jQuery.parseJSON(data);
356
  if(jsonarray.html !== false){
357
+ jQuery('#wpvivid_backup_list').html('');
358
+ jQuery('#wpvivid_backup_list').append(jsonarray.html);
359
  wpvivid_popup_tour('show');
360
  }
361
  }
482
  wpvivid_check_plupload_added_files(up,files);
483
  }
484
  else if(jsonarray.result === "failed") {
485
+ uploader.removeFile(file);
486
  alert(jsonarray.error);
487
  }
488
  }, function (XMLHttpRequest, textStatus, errorThrown)
489
  {
490
  var error_message = wpvivid_output_ajaxerror('uploading backups', textStatus, errorThrown);
491
+ uploader.removeFile(file);
492
  alert(error_message);
493
  });
494
  }
581
  unlinked = jsonarray.unlinked;
582
  }
583
  alert('The upload has completed. ' + unlinked);
584
+ jQuery('#wpvivid_backup_list').html('');
585
+ jQuery('#wpvivid_backup_list').append(jsonarray.html);
586
  wpvivid_click_switch_page('backup', 'wpvivid_tab_backup', true);
587
  }
588
  }
includes/class-wpvivid-backup.php CHANGED
@@ -44,6 +44,8 @@ class WPvivid_Backup_Task
44
  $this->backup_type_collect[WPVIVID_BACKUP_TYPE_CORE]=1;
45
  $this->backup_type_collect[WPVIVID_BACKUP_TYPE_OTHERS]=1;
46
  $this->backup_type_collect[WPVIVID_BACKUP_TYPE_MERGE]=1;
 
 
47
  }
48
 
49
  public function get_id()
@@ -88,6 +90,8 @@ class WPvivid_Backup_Task
88
  $this->task['options']['remote_options']=false;
89
  }
90
 
 
 
91
  if(isset($options['local']))
92
  {
93
  if($options['local']=='1')
@@ -131,17 +135,23 @@ class WPvivid_Backup_Task
131
  $home_url_prefix=$this->parse_url_all($home_url_prefix);
132
 
133
  $general_setting=WPvivid_Setting::get_setting(true, "");
134
- if(!isset($general_setting['options']['wpvivid_common_setting']['domain_include'])){
 
 
135
  $this->task['options']['file_prefix']=$home_url_prefix.'_'.$this->task['id'].'_'.date('Y-m-d-H-i',$this->task['status']['start_time']);
136
  }
137
  else{
138
- if($general_setting['options']['wpvivid_common_setting']['domain_include']){
 
139
  $this->task['options']['file_prefix']=$home_url_prefix.'_'.$this->task['id'].'_'.date('Y-m-d-H-i',$this->task['status']['start_time']);
140
  }
141
  else{
142
  $this->task['options']['file_prefix']=$this->task['id'].'_'.date('Y-m-d-H-i',$this->task['status']['start_time']);
143
  }
144
  }
 
 
 
145
  $this->task['options']['log_file_name']=$id.'_backup';
146
  $log=new WPvivid_Log();
147
  $log->CreateLogFile($this->task['options']['log_file_name'],'no_folder','backup');
@@ -151,8 +161,6 @@ class WPvivid_Backup_Task
151
  $this->task['options']['backup_options']['dir']=WPvivid_Setting::get_backupdir();
152
  $this->task['options']['backup_options']['backup']=array();
153
 
154
- add_filter('wpvivid_set_backup', array($this, 'wpvivid_set_backup'),10);
155
-
156
  if(isset($options['backup_files']))
157
  {
158
  if($options['backup_files']=='files+db')
@@ -282,6 +290,7 @@ class WPvivid_Backup_Task
282
  $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
283
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
284
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
 
285
  $backup_data['exclude_regex']=$exclude_regex;
286
  $backup_data['include_regex']=array();
287
  }
@@ -294,7 +303,7 @@ class WPvivid_Backup_Task
294
  $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
295
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
296
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
297
- //$exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
298
  $backup_data['exclude_regex']=$exclude_regex;
299
  $backup_data['include_regex'][]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
300
  }
@@ -306,6 +315,7 @@ class WPvivid_Backup_Task
306
  $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
307
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
308
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
 
309
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
310
  $backup_data['exclude_regex']=$exclude_regex;
311
  $backup_data['include_regex']=array();
@@ -323,6 +333,7 @@ class WPvivid_Backup_Task
323
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(), '/').'#';
324
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'plugins', '/').'#';
325
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'cache', '/').'#';
 
326
  $upload_dir = wp_upload_dir();
327
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';
328
  $exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
@@ -587,15 +598,23 @@ class WPvivid_Backup_Task
587
  $ret['result']=WPVIVID_SUCCESS;
588
  foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
589
  {
590
- if($backup_data['result']!==false)
591
  {
592
- $ret=$backup_data['result'];
593
- if($ret['result']!==WPVIVID_SUCCESS)
594
  {
595
- return $ret;
 
 
 
 
596
  }
597
  }
 
 
 
 
598
  }
 
599
  return $ret;
600
  }
601
 
@@ -736,8 +755,8 @@ class WPvivid_Backup_Task
736
  if ($packages_files_info !== false) {
737
  foreach ($packages_files_info as $file_data) {
738
  $path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $this->task['options']['backup_options']['dir'] . DIRECTORY_SEPARATOR . $file_data['file_name'];
739
- global $wpvivid_pulgin;
740
- $wpvivid_pulgin->wpvivid_log->WriteLog('test:' . $path, 'notice');
741
  if (!in_array($path, $files))
742
  $files[] = $path;
743
  }
@@ -844,7 +863,7 @@ class WPvivid_Backup_Task
844
  $list_tasks['task_info']['need_next_schedule']=false;
845
  if($list_tasks['status']['str']=='running'||$list_tasks['status']['str']=='no_responds')
846
  {
847
- if($list_tasks['data']['running_time']>180) {
848
  $list_tasks['task_info']['need_next_schedule'] = true;
849
  }
850
  else{
@@ -1216,6 +1235,77 @@ class WPvivid_Backup_Task
1216
  $files[] = $path;
1217
  }
1218
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1219
  }
1220
 
1221
  class WPvivid_Backup_Item
@@ -1274,7 +1364,7 @@ class WPvivid_Backup_Item
1274
 
1275
  public function check_backup_files()
1276
  {
1277
- global $wpvivid_pulgin;
1278
  $ret['result']=WPVIVID_FAILED;
1279
  $ret['error']='Unknown error.';
1280
 
@@ -1301,7 +1391,7 @@ class WPvivid_Backup_Item
1301
  if(file_exists($path))
1302
  {
1303
  if(filesize($path) == $file['size']){
1304
- if($wpvivid_pulgin->wpvivid_check_zip_valid()) {
1305
  $res = TRUE;
1306
  }
1307
  else{
@@ -1381,7 +1471,7 @@ class WPvivid_Backup_Item
1381
  $json=$ret['json_data'];
1382
  $json = json_decode($json, 1);
1383
  if (!is_null($json)) {
1384
- if (isset($json['home_url'])) {
1385
  return 1;
1386
  }
1387
  }
@@ -1403,6 +1493,46 @@ class WPvivid_Backup_Item
1403
 
1404
  }
1405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1406
  public function get_local_path()
1407
  {
1408
  return $this->config['local']['path'];
@@ -1650,7 +1780,7 @@ class WPvivid_Backup_Item
1650
  public function get_download_backup_files($backup_id){
1651
  $ret['result']=WPVIVID_FAILED;
1652
  $data=array();
1653
- $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
1654
  if(!$backup)
1655
  {
1656
  $ret['error']='Backup id not found.';
@@ -1670,7 +1800,7 @@ class WPvivid_Backup_Item
1670
  }
1671
 
1672
  public function get_download_progress($backup_id, $files){
1673
- global $wpvivid_pulgin;
1674
  $b_need_download=false;
1675
  $b_not_found=false;
1676
  $file_count=0;
@@ -1683,7 +1813,7 @@ class WPvivid_Backup_Item
1683
  $download_url=content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1684
  if(file_exists($path)) {
1685
  if(filesize($path) == $file['size']){
1686
- if($wpvivid_pulgin->wpvivid_check_zip_valid()) {
1687
  $res = TRUE;
1688
  }
1689
  else{
@@ -1722,7 +1852,7 @@ class WPvivid_Backup_Item
1722
  <span>Part'.$format_part.'</span></br>
1723
  <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>
1724
  <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>
1725
- <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1726
  </div>';
1727
  } else {
1728
  $ret['result'] = WPVIVID_SUCCESS;
@@ -1732,7 +1862,7 @@ class WPvivid_Backup_Item
1732
  <span>Part'.$format_part.'</span></br>
1733
  <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a >Retriving(remote storage to web server)</a></span></br>
1734
  <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>
1735
- <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1736
  </div>';
1737
  $ret['files'][$file['file_name']]['progress_text']=$task['progress_text'];
1738
  }
@@ -1742,7 +1872,7 @@ class WPvivid_Backup_Item
1742
  <span>Part'.$format_part.'</span></br>
1743
  <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>
1744
  <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>
1745
- <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1746
  </div>';
1747
  $ret['files'][$file['file_name']]['progress_text']=$task['progress_text'];
1748
  WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
@@ -1753,7 +1883,7 @@ class WPvivid_Backup_Item
1753
  <span>Part'.$format_part.'</span></br>
1754
  <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>
1755
  <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>
1756
- <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1757
  </div>';
1758
  WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1759
  }
@@ -1763,7 +1893,7 @@ class WPvivid_Backup_Item
1763
  <span>Part'.$format_part.'</span></br>
1764
  <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>
1765
  <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>
1766
- <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1767
  </div>';
1768
  $ret['files'][$file['file_name']]['error'] = $task['error'];
1769
  WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
@@ -1782,10 +1912,10 @@ class WPvivid_Backup_Item
1782
  <span>Part'.$format_part.'</span></br>
1783
  <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>
1784
  <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>
1785
- <span>size:</span><span>'.$wpvivid_pulgin->formatBytes($file['size']).'</span>
1786
  </div>';
1787
  }
1788
- $ret['files'][$file['file_name']]['size']=$wpvivid_pulgin->formatBytes($file['size']);
1789
  $file_count++;
1790
  $file_part_num++;
1791
  }
@@ -1854,18 +1984,18 @@ class WPvivid_Backup
1854
 
1855
  while($next_backup!==false)
1856
  {
1857
- global $wpvivid_pulgin;
1858
- $wpvivid_pulgin->set_time_limit($this->task->get_id());
1859
  $this->task->update_sub_task_progress($next_backup['key'],0,'Start backing up '.$next_backup['key'].'.');
1860
- $wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to backup '.$next_backup['key'].' files.','notice');
1861
  if(isset($next_backup['files'])) {
1862
- $wpvivid_pulgin->wpvivid_log->WriteLog('File number: ' . sizeof($next_backup['files']), 'notice');
1863
  }
1864
  $result = $this->_backup($next_backup);
1865
- $wpvivid_pulgin->wpvivid_log->WriteLog('Backing up '.$next_backup['key'].' completed.','notice');
1866
  $this->task->update_sub_task_progress($next_backup['key'],1,'Backing up '.$next_backup['key'].' finished.');
1867
  $this->task->update_backup_result($next_backup,$result);
1868
- $wpvivid_pulgin->check_cancel_backup($task_id);
1869
  unset($next_backup);
1870
  $next_backup=$this->task->get_need_backup();
1871
  }
@@ -1878,16 +2008,16 @@ class WPvivid_Backup
1878
 
1879
  private function _backup($data)
1880
  {
1881
- global $wpvivid_pulgin;
1882
  $result['result']=WPVIVID_FAILED;
1883
  $result['error']='test error';
1884
  if(isset($data['dump_db']))
1885
  {
1886
  include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-backup-database.php';
1887
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start exporting database.','notice');
1888
  $backup_database = new WPvivid_Backup_Database();
1889
  $result = $backup_database -> backup_database($data,$this->task->get_id());
1890
- $wpvivid_pulgin->wpvivid_log->WriteLog('Exporting database finished.','notice');
1891
  if($result['result']==WPVIVID_SUCCESS)
1892
  {
1893
  $data['files']=$result['files'];
@@ -1908,9 +2038,8 @@ class WPvivid_Backup
1908
 
1909
  if(isset($data['resume_packages']))
1910
  {
1911
- global $wpvivid_pulgin;
1912
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
1913
-
1914
  if(isset($data['plugin_subpackage']))
1915
  {
1916
  $ret =$zip->get_plugin_packages($data);
@@ -1955,7 +2084,7 @@ class WPvivid_Backup
1955
  continue;
1956
  }
1957
  }
1958
- $wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
1959
  return $result;
1960
  }
1961
  else
@@ -1976,9 +2105,9 @@ class WPvivid_Backup
1976
  /*
1977
  if(isset($data['has_child']))
1978
  {
1979
- global $wpvivid_pulgin;
1980
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
1981
- $wpvivid_pulgin->wpvivid_log->WriteLog('has_child','notice');
1982
 
1983
  $ret =$zip->get_packages($data);
1984
 
@@ -2013,13 +2142,13 @@ class WPvivid_Backup
2013
  continue;
2014
  }
2015
  }
2016
- $wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
2017
  return $result;
2018
  }
2019
  else if(isset($data['wp_plugin']))
2020
  {
2021
- global $wpvivid_pulgin;
2022
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
2023
 
2024
  $ret =$zip->get_plugin_packages($data);
2025
 
@@ -2054,7 +2183,7 @@ class WPvivid_Backup
2054
  continue;
2055
  }
2056
  }
2057
- $wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
2058
  return $result;
2059
  }
2060
  else
@@ -2081,8 +2210,8 @@ class WPvivid_Backup
2081
  foreach ($files as $file)
2082
  {
2083
  if(file_exists($file)) {
2084
- global $wpvivid_pulgin;
2085
- $wpvivid_pulgin->wpvivid_log->WriteLog('Cleaned up file, filename: '.$file,'notice');
2086
  @unlink($file);
2087
  }
2088
  }
@@ -2109,9 +2238,9 @@ class WPvivid_Backup
2109
 
2110
  if(!is_null($remote_option))
2111
  {
2112
- global $wpvivid_pulgin;
2113
 
2114
- $remote=$wpvivid_pulgin->remote_collection->get_remote($remote_option);
2115
  $remote ->cleanup($files);
2116
  }
2117
  }
44
  $this->backup_type_collect[WPVIVID_BACKUP_TYPE_CORE]=1;
45
  $this->backup_type_collect[WPVIVID_BACKUP_TYPE_OTHERS]=1;
46
  $this->backup_type_collect[WPVIVID_BACKUP_TYPE_MERGE]=1;
47
+
48
+ add_filter('wpvivid_set_backup', array($this, 'wpvivid_set_backup'),10);
49
  }
50
 
51
  public function get_id()
90
  $this->task['options']['remote_options']=false;
91
  }
92
 
93
+ $this->task['options']['remote_options'] = apply_filters('wpvivid_set_remote_options', $this->task['options']['remote_options'],$options);
94
+
95
  if(isset($options['local']))
96
  {
97
  if($options['local']=='1')
135
  $home_url_prefix=$this->parse_url_all($home_url_prefix);
136
 
137
  $general_setting=WPvivid_Setting::get_setting(true, "");
138
+
139
+ if(!isset($general_setting['options']['wpvivid_common_setting']['domain_include']))
140
+ {
141
  $this->task['options']['file_prefix']=$home_url_prefix.'_'.$this->task['id'].'_'.date('Y-m-d-H-i',$this->task['status']['start_time']);
142
  }
143
  else{
144
+ if($general_setting['options']['wpvivid_common_setting']['domain_include'])
145
+ {
146
  $this->task['options']['file_prefix']=$home_url_prefix.'_'.$this->task['id'].'_'.date('Y-m-d-H-i',$this->task['status']['start_time']);
147
  }
148
  else{
149
  $this->task['options']['file_prefix']=$this->task['id'].'_'.date('Y-m-d-H-i',$this->task['status']['start_time']);
150
  }
151
  }
152
+
153
+
154
+
155
  $this->task['options']['log_file_name']=$id.'_backup';
156
  $log=new WPvivid_Log();
157
  $log->CreateLogFile($this->task['options']['log_file_name'],'no_folder','backup');
161
  $this->task['options']['backup_options']['dir']=WPvivid_Setting::get_backupdir();
162
  $this->task['options']['backup_options']['backup']=array();
163
 
 
 
164
  if(isset($options['backup_files']))
165
  {
166
  if($options['backup_files']=='files+db')
290
  $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
291
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
292
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
293
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'ShortpixelBackups', '/').'#';//ShortpixelBackups
294
  $backup_data['exclude_regex']=$exclude_regex;
295
  $backup_data['include_regex']=array();
296
  }
303
  $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
304
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
305
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
306
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'ShortpixelBackups', '/').'#';
307
  $backup_data['exclude_regex']=$exclude_regex;
308
  $backup_data['include_regex'][]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
309
  }
315
  $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
316
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
317
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
318
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'ShortpixelBackups', '/').'#';
319
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
320
  $backup_data['exclude_regex']=$exclude_regex;
321
  $backup_data['include_regex']=array();
333
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(), '/').'#';
334
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'plugins', '/').'#';
335
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'cache', '/').'#';
336
+ $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'Dropbox_Backup', '/').'#';
337
  $upload_dir = wp_upload_dir();
338
  $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'#';
339
  $exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
598
  $ret['result']=WPVIVID_SUCCESS;
599
  foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
600
  {
601
+ if($this->task['options']['backup_options']['ismerge']==1)
602
  {
603
+ if(WPVIVID_BACKUP_TYPE_MERGE==$backup_data['key'])
 
604
  {
605
+ $ret=$backup_data['result'];
606
+ if($ret['result']!==WPVIVID_SUCCESS)
607
+ {
608
+ return $ret;
609
+ }
610
  }
611
  }
612
+ else
613
+ {
614
+ //
615
+ }
616
  }
617
+
618
  return $ret;
619
  }
620
 
755
  if ($packages_files_info !== false) {
756
  foreach ($packages_files_info as $file_data) {
757
  $path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $this->task['options']['backup_options']['dir'] . DIRECTORY_SEPARATOR . $file_data['file_name'];
758
+ global $wpvivid_plugin;
759
+ $wpvivid_plugin->wpvivid_log->WriteLog('test:' . $path, 'notice');
760
  if (!in_array($path, $files))
761
  $files[] = $path;
762
  }
863
  $list_tasks['task_info']['need_next_schedule']=false;
864
  if($list_tasks['status']['str']=='running'||$list_tasks['status']['str']=='no_responds')
865
  {
866
+ if($list_tasks['data']['running_stamp']>180) {
867
  $list_tasks['task_info']['need_next_schedule'] = true;
868
  }
869
  else{
1235
  $files[] = $path;
1236
  }
1237
  }
1238
+
1239
+ public function add_new_backup()
1240
+ {
1241
+ $this->task=WPvivid_taskmanager::get_task($this->task['id']);
1242
+ $backup_data=array();
1243
+ $backup_data['type']=$this->task['type'];
1244
+ $status=WPvivid_taskmanager::get_backup_task_status($this->task['id']);
1245
+ $backup_data['create_time']=$status['start_time'];
1246
+ $backup_data['manual_delete']=0;
1247
+ $backup_options=WPvivid_taskmanager::get_task_options($this->task['id'],'backup_options');
1248
+ $lock=WPvivid_taskmanager::get_task_options($this->task['id'],'lock');
1249
+ $backup_data['local']['path']=$backup_options['dir'];
1250
+ $backup_data['compress']['compress_type']=$backup_options['compress']['compress_type'];
1251
+ $backup_data['save_local']=$this->task['options']['save_local'];
1252
+
1253
+ global $wpvivid_plugin;
1254
+ $backup_data['log']=$wpvivid_plugin->wpvivid_log->log_file;
1255
+ $backup_data['backup']=$this->get_backup_result();
1256
+ $backup_data['remote']=array();
1257
+ if($lock==1)
1258
+ $backup_data['lock']=1;
1259
+
1260
+ $backup_list='wpvivid_backup_list';
1261
+
1262
+ $backup_list=apply_filters('get_wpvivid_backup_list_name',$backup_list,$this->task['id']);
1263
+
1264
+ $list = WPvivid_Setting::get_option($backup_list);
1265
+ $list[$this->task['id']]=$backup_data;
1266
+ WPvivid_Setting::update_option($backup_list,$list);
1267
+ }
1268
+
1269
+ public function get_backup_files()
1270
+ {
1271
+ $files=array();
1272
+ foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
1273
+ {
1274
+ if($this->task['options']['backup_options']['ismerge']==1)
1275
+ {
1276
+ if(WPVIVID_BACKUP_TYPE_MERGE==$backup_data['key'])
1277
+ {
1278
+ if($backup_data['result']!==false)
1279
+ {
1280
+ $ret=$backup_data['result'];
1281
+ if($ret['result']===WPVIVID_SUCCESS)
1282
+ {
1283
+ foreach ($ret['files'] as $file)
1284
+ {
1285
+ $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$file['file_name'];
1286
+ }
1287
+ }
1288
+ }
1289
+ }
1290
+ }
1291
+ else
1292
+ {
1293
+ if($backup_data['result']!==false)
1294
+ {
1295
+ $ret=$backup_data['result'];
1296
+ if($ret['result']===WPVIVID_SUCCESS)
1297
+ {
1298
+ foreach ($ret['files'] as $file)
1299
+ {
1300
+ $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$file['file_name'];
1301
+ }
1302
+ }
1303
+ }
1304
+ }
1305
+ }
1306
+
1307
+ return $files;
1308
+ }
1309
  }
1310
 
1311
  class WPvivid_Backup_Item
1364
 
1365
  public function check_backup_files()
1366
  {
1367
+ global $wpvivid_plugin;
1368
  $ret['result']=WPVIVID_FAILED;
1369
  $ret['error']='Unknown error.';
1370
 
1391
  if(file_exists($path))
1392
  {
1393
  if(filesize($path) == $file['size']){
1394
+ if($wpvivid_plugin->wpvivid_check_zip_valid()) {
1395
  $res = TRUE;
1396
  }
1397
  else{
1471
  $json=$ret['json_data'];
1472
  $json = json_decode($json, 1);
1473
  if (!is_null($json)) {
1474
+ if (isset($json['home_url']) && home_url() != $json['home_url']) {
1475
  return 1;
1476
  }
1477
  }
1493
 
1494
  }
1495
 
1496
+ public function is_display_migrate_option(){
1497
+ if(isset($this->config['backup']['files']))
1498
+ {
1499
+ $tmp_data = $this->config['backup']['files'];
1500
+ $zip=new WPvivid_ZipClass();
1501
+
1502
+ foreach ($tmp_data as $file)
1503
+ {
1504
+ $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1505
+ if(file_exists($path))
1506
+ {
1507
+ $ret=$zip->get_json_data($path);
1508
+ if($ret['result'] === WPVIVID_SUCCESS) {
1509
+ $json=$ret['json_data'];
1510
+ $json = json_decode($json, 1);
1511
+ if (!is_null($json)) {
1512
+ if (isset($json['home_url'])){
1513
+ return false;
1514
+ }
1515
+ else{
1516
+ return true;
1517
+ }
1518
+ }
1519
+ else{
1520
+ return true;
1521
+ }
1522
+ }
1523
+ elseif($ret['result'] === WPVIVID_FAILED){
1524
+ return true;
1525
+ }
1526
+ }
1527
+ }
1528
+ return true;
1529
+ }
1530
+ else
1531
+ {
1532
+ return true;
1533
+ }
1534
+ }
1535
+
1536
  public function get_local_path()
1537
  {
1538
  return $this->config['local']['path'];
1780
  public function get_download_backup_files($backup_id){
1781
  $ret['result']=WPVIVID_FAILED;
1782
  $data=array();
1783
+ $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
1784
  if(!$backup)
1785
  {
1786
  $ret['error']='Backup id not found.';
1800
  }
1801
 
1802
  public function get_download_progress($backup_id, $files){
1803
+ global $wpvivid_plugin;
1804
  $b_need_download=false;
1805
  $b_not_found=false;
1806
  $file_count=0;
1813
  $download_url=content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
1814
  if(file_exists($path)) {
1815
  if(filesize($path) == $file['size']){
1816
+ if($wpvivid_plugin->wpvivid_check_zip_valid()) {
1817
  $res = TRUE;
1818
  }
1819
  else{
1852
  <span>Part'.$format_part.'</span></br>
1853
  <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>
1854
  <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>
1855
+ <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
1856
  </div>';
1857
  } else {
1858
  $ret['result'] = WPVIVID_SUCCESS;
1862
  <span>Part'.$format_part.'</span></br>
1863
  <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a >Retriving(remote storage to web server)</a></span></br>
1864
  <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>
1865
+ <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
1866
  </div>';
1867
  $ret['files'][$file['file_name']]['progress_text']=$task['progress_text'];
1868
  }
1872
  <span>Part'.$format_part.'</span></br>
1873
  <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>
1874
  <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>
1875
+ <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
1876
  </div>';
1877
  $ret['files'][$file['file_name']]['progress_text']=$task['progress_text'];
1878
  WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1883
  <span>Part'.$format_part.'</span></br>
1884
  <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>
1885
  <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>
1886
+ <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
1887
  </div>';
1888
  WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1889
  }
1893
  <span>Part'.$format_part.'</span></br>
1894
  <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>
1895
  <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>
1896
+ <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
1897
  </div>';
1898
  $ret['files'][$file['file_name']]['error'] = $task['error'];
1899
  WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1912
  <span>Part'.$format_part.'</span></br>
1913
  <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>
1914
  <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>
1915
+ <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
1916
  </div>';
1917
  }
1918
+ $ret['files'][$file['file_name']]['size']=$wpvivid_plugin->formatBytes($file['size']);
1919
  $file_count++;
1920
  $file_part_num++;
1921
  }
1984
 
1985
  while($next_backup!==false)
1986
  {
1987
+ global $wpvivid_plugin;
1988
+ $wpvivid_plugin->set_time_limit($this->task->get_id());
1989
  $this->task->update_sub_task_progress($next_backup['key'],0,'Start backing up '.$next_backup['key'].'.');
1990
+ $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to backup '.$next_backup['key'].' files.','notice');
1991
  if(isset($next_backup['files'])) {
1992
+ $wpvivid_plugin->wpvivid_log->WriteLog('File number: ' . sizeof($next_backup['files']), 'notice');
1993
  }
1994
  $result = $this->_backup($next_backup);
1995
+ $wpvivid_plugin->wpvivid_log->WriteLog('Backing up '.$next_backup['key'].' completed.','notice');
1996
  $this->task->update_sub_task_progress($next_backup['key'],1,'Backing up '.$next_backup['key'].' finished.');
1997
  $this->task->update_backup_result($next_backup,$result);
1998
+ $wpvivid_plugin->check_cancel_backup($task_id);
1999
  unset($next_backup);
2000
  $next_backup=$this->task->get_need_backup();
2001
  }
2008
 
2009
  private function _backup($data)
2010
  {
2011
+ global $wpvivid_plugin;
2012
  $result['result']=WPVIVID_FAILED;
2013
  $result['error']='test error';
2014
  if(isset($data['dump_db']))
2015
  {
2016
  include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-backup-database.php';
2017
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start exporting database.','notice');
2018
  $backup_database = new WPvivid_Backup_Database();
2019
  $result = $backup_database -> backup_database($data,$this->task->get_id());
2020
+ $wpvivid_plugin->wpvivid_log->WriteLog('Exporting database finished.','notice');
2021
  if($result['result']==WPVIVID_SUCCESS)
2022
  {
2023
  $data['files']=$result['files'];
2038
 
2039
  if(isset($data['resume_packages']))
2040
  {
2041
+ global $wpvivid_plugin;
2042
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
 
2043
  if(isset($data['plugin_subpackage']))
2044
  {
2045
  $ret =$zip->get_plugin_packages($data);
2084
  continue;
2085
  }
2086
  }
2087
+ $wpvivid_plugin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
2088
  return $result;
2089
  }
2090
  else
2105
  /*
2106
  if(isset($data['has_child']))
2107
  {
2108
+ global $wpvivid_plugin;
2109
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
2110
+ $wpvivid_plugin->wpvivid_log->WriteLog('has_child','notice');
2111
 
2112
  $ret =$zip->get_packages($data);
2113
 
2142
  continue;
2143
  }
2144
  }
2145
+ $wpvivid_plugin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
2146
  return $result;
2147
  }
2148
  else if(isset($data['wp_plugin']))
2149
  {
2150
+ global $wpvivid_plugin;
2151
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
2152
 
2153
  $ret =$zip->get_plugin_packages($data);
2154
 
2183
  continue;
2184
  }
2185
  }
2186
+ $wpvivid_plugin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
2187
  return $result;
2188
  }
2189
  else
2210
  foreach ($files as $file)
2211
  {
2212
  if(file_exists($file)) {
2213
+ global $wpvivid_plugin;
2214
+ $wpvivid_plugin->wpvivid_log->WriteLog('Cleaned up file, filename: '.$file,'notice');
2215
  @unlink($file);
2216
  }
2217
  }
2238
 
2239
  if(!is_null($remote_option))
2240
  {
2241
+ global $wpvivid_plugin;
2242
 
2243
+ $remote=$wpvivid_plugin->remote_collection->get_remote($remote_option);
2244
  $remote ->cleanup($files);
2245
  }
2246
  }
includes/class-wpvivid-backuplist.php CHANGED
@@ -5,38 +5,95 @@ if (!defined('WPVIVID_PLUGIN_DIR')){
5
  }
6
  class WPvivid_Backuplist
7
  {
8
- public static function get_backuplist()
9
  {
10
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
- $list =self::sort_list($list);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
 
 
 
 
 
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();
29
  foreach ($list as $k=>$backup)
30
  {
31
- if ($key == $k)
32
  {
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
  }
@@ -44,31 +101,18 @@ class WPvivid_Backuplist
44
  return false;
45
  }
46
 
47
- public static function add_new_backup($task_id,$backup_ret)
 
 
 
 
 
 
48
  {
49
- $task=WPvivid_taskmanager::get_task($task_id);
50
- if($task!=false)
51
  {
52
- $backup_data=array();
53
- $backup_data['type']=$task['type'];
54
- $status=WPvivid_taskmanager::get_backup_task_status($task_id);
55
- $backup_data['create_time']=$status['start_time'];
56
- $backup_data['manual_delete']=0;
57
- $backup_options=WPvivid_taskmanager::get_task_options($task_id,'backup_options');
58
- $lock=WPvivid_taskmanager::get_task_options($task_id,'lock');
59
- $backup_data['local']['path']=$backup_options['dir'];
60
- $backup_data['compress']['compress_type']=$backup_options['compress']['compress_type'];
61
- $backup_data['save_local']=$task['options']['save_local'];
62
-
63
- global $wpvivid_pulgin;
64
- $backup_data['log']=$wpvivid_pulgin->wpvivid_log->log_file;
65
-
66
- $backup_data['backup']=$backup_ret;
67
- $backup_data['remote']=array();
68
- if($lock==1)
69
- $backup_data['lock']=1;
70
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
71
- $list[$task_id]=$backup_data;
72
  WPvivid_Setting::update_option('wpvivid_backup_list',$list);
73
  }
74
  }
@@ -87,51 +131,30 @@ class WPvivid_Backuplist
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');
98
- $list[$id][$key]=$data;
99
- WPvivid_Setting::update_option('wpvivid_backup_list',$list);
100
- }
101
 
102
- public static function set_backup_file_data($file_data)
103
- {
104
- $ret=array();
105
- $i=0;
106
- foreach ($file_data as $file)
107
- {
108
- $ret[$i]['file_name']=$file['file_name'];
109
- $ret[$i]['size']=$file['size'];
110
- $ret[$i]['md5']=$file['md5'];
111
- $i++;
112
- }
113
-
114
- return $ret;
115
  }
116
 
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
  }
@@ -328,24 +351,47 @@ class WPvivid_Backuplist
328
  }
329
  public static function set_security_lock($backup_id,$lock)
330
  {
331
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
332
-
333
- if(array_key_exists($backup_id,$list))
334
- {
335
- if($lock==1)
336
- {
337
- $list[$backup_id]['lock']=1;
338
- }
339
- else
340
- {
341
- if(array_key_exists('lock',$list[$backup_id]))
342
- {
343
- unset($list[$backup_id]['lock']);
344
  }
345
  }
 
346
  }
347
 
348
- WPvivid_Setting::update_option('wpvivid_backup_list',$list);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
349
  }
350
 
351
  public static function get_has_remote_backuplist()
5
  }
6
  class WPvivid_Backuplist
7
  {
8
+ public static function get_backup_by_id($id)
9
  {
10
+ $lists[]='wpvivid_backup_list';
11
+ $lists=apply_filters('wpvivid_get_backuplist_name',$lists);
12
+ foreach ($lists as $list_name)
13
+ {
14
+ $list = WPvivid_Setting::get_option($list_name);
15
+ foreach ($list as $k=>$backup)
16
+ {
17
+ if ($id == $k)
18
+ {
19
+ return $backup;
20
+ }
21
+ }
22
+ }
23
+ return false;
24
+ }
25
 
26
+ public static function update_backup_option($backup_id,$backup_new)
27
+ {
28
+ $lists[]='wpvivid_backup_list';
29
+ $lists=apply_filters('wpvivid_get_backuplist_name',$lists);
30
+ foreach ($lists as $list_name)
31
+ {
32
+ $list = WPvivid_Setting::get_option($list_name);
33
+ foreach ($list as $k=>$backup)
34
+ {
35
+ if ($backup_id == $k)
36
+ {
37
+ $list[$backup_id]=$backup_new;
38
+ WPvivid_Setting::update_option($list_name,$list);
39
+ return ;
40
+ }
41
+ }
42
+ }
43
+ }
44
 
45
+ public static function get_backuplist($list_name='')
46
+ {
47
+ $list=array();
48
+ add_filter('wpvivid_get_backuplist',array('WPvivid_Backuplist','get_backup_list'),10,2);
49
+ $list=apply_filters('wpvivid_get_backuplist',$list,$list_name);
50
  return $list;
51
  }
52
 
53
+ public static function get_backup_list($list,$list_name)
54
  {
55
+ $list = WPvivid_Setting::get_option('wpvivid_backup_list');
 
56
  $list =self::sort_list($list);
57
 
58
  return $list;
59
  }
60
 
61
+ public static function get_backuplist_by_id($id){
62
+ $list = array();
63
+ add_filter('wpvivid_get_backuplist_by_id',array('WPvivid_Backuplist','get_backup_list_by_id'), 10 , 2);
64
+ $ret=apply_filters('wpvivid_get_backuplist_by_id',$list,$id);
65
+ return $ret;
66
+ }
67
+
68
+ public static function get_backup_list_by_id($list, $id)
69
  {
70
+ $list = WPvivid_Setting::get_option('wpvivid_backup_list');
71
  foreach ($list as $k=>$backup)
72
  {
73
+ if ($id == $k)
74
  {
75
+ $ret['list_name'] = 'wpvivid_backup_list';
76
+ $ret['list_data'] = $list;
77
+ return $ret;
78
  }
79
  }
80
+ return false;
81
+ }
82
+
83
+ public static function get_backuplist_by_key($key)
84
+ {
85
+ add_filter('wpvivid_get_backuplist_item',array('WPvivid_Backuplist','get_backuplist_item'),10,2);
86
+ $backup=false;
87
+ $backup=apply_filters('wpvivid_get_backuplist_item',$backup,$key);
88
+ return $backup;
89
+ }
90
+
91
+ public static function get_backuplist_item($backup,$key)
92
+ {
93
+ $list = WPvivid_Setting::get_option('wpvivid_backup_list');
94
  foreach ($list as $k=>$backup)
95
  {
96
+ if ($key == $k)
97
  {
98
  return $backup;
99
  }
101
  return false;
102
  }
103
 
104
+ public static function update_backup($id,$key,$data)
105
+ {
106
+ add_action('wpvivid_update_backup',array('WPvivid_Backuplist', 'update_backup_item'),10,3);
107
+ do_action('wpvivid_update_backup',$id,$key,$data);
108
+ }
109
+
110
+ public static function update_backup_item($id,$key,$data)
111
  {
112
+ $list = WPvivid_Setting::get_option('wpvivid_backup_list');
113
+ if(array_key_exists($id,$list))
114
  {
115
+ $list[$id][$key]=$data;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  WPvivid_Setting::update_option('wpvivid_backup_list',$list);
117
  }
118
  }
131
  $backup_data['backup']=$backup;
132
  $backup_data['remote']=array();
133
  $backup_data['lock']=0;
134
+ $backup_list='wpvivid_backup_list';
 
 
 
135
 
136
+ $backup_list=apply_filters('get_wpvivid_backup_list_name',$backup_list,$task_id,$backup_data);
 
 
 
 
 
137
 
138
+ $list = WPvivid_Setting::get_option($backup_list);
139
+ $list[$task_id]=$backup_data;
140
+ WPvivid_Setting::update_option($backup_list,$list);
 
 
 
 
 
 
 
 
 
 
141
  }
142
 
143
  public static function delete_backup($key)
144
  {
145
+ $lists[]='wpvivid_backup_list';
146
+ $lists=apply_filters('wpvivid_get_backuplist_name',$lists);
147
+ foreach ($lists as $list_name)
148
  {
149
+ $list = WPvivid_Setting::get_option($list_name);
150
+ foreach ($list as $k=>$backup)
 
 
 
 
 
 
 
 
151
  {
152
+ if ($key == $k)
153
+ {
154
+ unset($list[$key]);
155
+ WPvivid_Setting::update_option($list_name, $list);
156
+ return;
157
+ }
158
  }
159
  }
160
  }
351
  }
352
  public static function set_security_lock($backup_id,$lock)
353
  {
354
+ //$list = WPvivid_Setting::get_option('wpvivid_backup_list');
355
+ $ret = self::get_backuplist_by_id($backup_id);
356
+ if($ret !== false) {
357
+ $list = $ret['list_data'];
358
+ if (array_key_exists($backup_id, $list)) {
359
+ if ($lock == 1) {
360
+ $list[$backup_id]['lock'] = 1;
361
+ }
362
+ else {
363
+ if (array_key_exists('lock', $list[$backup_id])) {
364
+ unset($list[$backup_id]['lock']);
365
+ }
 
366
  }
367
  }
368
+ WPvivid_Setting::update_option($ret['list_name'], $list);
369
  }
370
 
371
+ $ret['result'] = 'success';
372
+ $list = WPvivid_Setting::get_option($ret['list_name']);
373
+ if (array_key_exists($backup_id, $list)) {
374
+ if (isset($list[$backup_id]['lock'])) {
375
+ if ($list[$backup_id]['lock'] == 1) {
376
+ $backup_lock = '/admin/partials/images/locked.png';
377
+ $lock_status = 'lock';
378
+ $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\''.$backup_id.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>';
379
+ } else {
380
+ $backup_lock = '/admin/partials/images/unlocked.png';
381
+ $lock_status = 'unlock';
382
+ $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\''.$backup_id.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>';
383
+ }
384
+ } else {
385
+ $backup_lock = '/admin/partials/images/unlocked.png';
386
+ $lock_status = 'unlock';
387
+ $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\''.$backup_id.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>';
388
+ }
389
+ } else {
390
+ $backup_lock = '/admin/partials/images/unlocked.png';
391
+ $lock_status = 'unlock';
392
+ $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\''.$backup_id.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>';
393
+ }
394
+ return $ret;
395
  }
396
 
397
  public static function get_has_remote_backuplist()
includes/class-wpvivid-db-method.php CHANGED
@@ -259,17 +259,17 @@ class WPvivid_DB_Method
259
 
260
  public function check_max_allowed_packet()
261
  {
262
- global $wpvivid_pulgin,$wpdb;
263
 
264
  $max_allowed_packet = (int) $wpdb->get_var("SELECT @@session.max_allowed_packet");
265
 
266
  if($max_allowed_packet<1048576)
267
  {
268
- $wpvivid_pulgin->wpvivid_log->WriteLog('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet,2),'notice');
269
  }
270
  else if($max_allowed_packet<33554432)
271
  {
272
- $wpvivid_pulgin->wpvivid_log->WriteLog('max_allowed_packet less than 32M :'.size_format($max_allowed_packet,2),'notice');
273
  }
274
  }
275
  }
259
 
260
  public function check_max_allowed_packet()
261
  {
262
+ global $wpvivid_plugin,$wpdb;
263
 
264
  $max_allowed_packet = (int) $wpdb->get_var("SELECT @@session.max_allowed_packet");
265
 
266
  if($max_allowed_packet<1048576)
267
  {
268
+ $wpvivid_plugin->wpvivid_log->WriteLog('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet,2),'notice');
269
  }
270
  else if($max_allowed_packet<33554432)
271
  {
272
+ $wpvivid_plugin->wpvivid_log->WriteLog('max_allowed_packet less than 32M :'.size_format($max_allowed_packet,2),'notice');
273
  }
274
  }
275
  }
includes/class-wpvivid-downloader.php CHANGED
@@ -13,7 +13,7 @@ class WPvivid_downloader
13
  public function ready_download($download_info)
14
  {
15
  $files=array();
16
- $backup=WPvivid_Backuplist::get_backuplist_by_key($download_info['backup_id']);
17
  if(!$backup)
18
  {
19
  return false;
@@ -98,8 +98,8 @@ class WPvivid_downloader
98
  {
99
  if(WPvivid_taskmanager::is_download_task_running_v2($download_info['file_name']))
100
  {
101
- global $wpvivid_pulgin;
102
- $wpvivid_pulgin->wpvivid_log->WriteLog('has a downloading task,exit download.','test');
103
  return false;
104
  }
105
  else
@@ -135,16 +135,16 @@ class WPvivid_downloader
135
  return array('result' => WPVIVID_FAILED ,'error'=>'Retrieving the cloud storage information failed while downloading backups. Please try again later.');
136
  }
137
 
138
- global $wpvivid_pulgin;
139
 
140
- $remote=$wpvivid_pulgin->remote_collection->get_remote($remote_option);
141
 
142
  $ret=$remote->download($file,$local_path,array($this,'download_callback_v2'));
143
 
144
  if($ret['result']==WPVIVID_SUCCESS)
145
  {
146
  $progress=100;
147
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Download completed.', 'notice');
148
  WPvivid_taskmanager::update_download_task_v2( $task,$progress,'completed');
149
  return $ret;
150
  }
@@ -152,10 +152,10 @@ class WPvivid_downloader
152
  {
153
  $progress=0;
154
  $message=$ret['error'];
155
- if($wpvivid_pulgin->wpvivid_download_log){
156
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Download failed, ' . $message ,'error');
157
- WPvivid_error_log::create_error_log($wpvivid_pulgin->wpvivid_download_log->log_file);
158
- $wpvivid_pulgin->wpvivid_download_log->CloseFile();
159
  }
160
  else {
161
  $id = uniqid('wpvivid-');
@@ -173,21 +173,21 @@ class WPvivid_downloader
173
 
174
  public function download_callback_v2($offset,$current_name,$current_size,$last_time,$last_size)
175
  {
176
- global $wpvivid_pulgin;
177
  $progress= floor(($offset/$current_size)* 100) ;
178
  $text='Total size:'.size_format($current_size,2).' downloaded:'.size_format($offset,2);
179
  $this->task['download_descript']=$text;
180
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Total Size: '.$current_size.', Downloaded Size: '.$offset ,'notice');
181
  WPvivid_taskmanager::update_download_task_v2( $this->task,$progress,'running');
182
  }
183
 
184
  public static function delete($remote , $files)
185
  {
186
- global $wpvivid_pulgin;
187
 
188
  set_time_limit(60);
189
 
190
- $remote=$wpvivid_pulgin->remote_collection->get_remote($remote);
191
 
192
  $result =$remote->cleanup($files);
193
 
13
  public function ready_download($download_info)
14
  {
15
  $files=array();
16
+ $backup=WPvivid_Backuplist::get_backup_by_id($download_info['backup_id']);
17
  if(!$backup)
18
  {
19
  return false;
98
  {
99
  if(WPvivid_taskmanager::is_download_task_running_v2($download_info['file_name']))
100
  {
101
+ global $wpvivid_plugin;
102
+ $wpvivid_plugin->wpvivid_log->WriteLog('has a downloading task,exit download.','test');
103
  return false;
104
  }
105
  else
135
  return array('result' => WPVIVID_FAILED ,'error'=>'Retrieving the cloud storage information failed while downloading backups. Please try again later.');
136
  }
137
 
138
+ global $wpvivid_plugin;
139
 
140
+ $remote=$wpvivid_plugin->remote_collection->get_remote($remote_option);
141
 
142
  $ret=$remote->download($file,$local_path,array($this,'download_callback_v2'));
143
 
144
  if($ret['result']==WPVIVID_SUCCESS)
145
  {
146
  $progress=100;
147
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Download completed.', 'notice');
148
  WPvivid_taskmanager::update_download_task_v2( $task,$progress,'completed');
149
  return $ret;
150
  }
152
  {
153
  $progress=0;
154
  $message=$ret['error'];
155
+ if($wpvivid_plugin->wpvivid_download_log){
156
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Download failed, ' . $message ,'error');
157
+ WPvivid_error_log::create_error_log($wpvivid_plugin->wpvivid_download_log->log_file);
158
+ $wpvivid_plugin->wpvivid_download_log->CloseFile();
159
  }
160
  else {
161
  $id = uniqid('wpvivid-');
173
 
174
  public function download_callback_v2($offset,$current_name,$current_size,$last_time,$last_size)
175
  {
176
+ global $wpvivid_plugin;
177
  $progress= floor(($offset/$current_size)* 100) ;
178
  $text='Total size:'.size_format($current_size,2).' downloaded:'.size_format($offset,2);
179
  $this->task['download_descript']=$text;
180
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Total Size: '.$current_size.', Downloaded Size: '.$offset ,'notice');
181
  WPvivid_taskmanager::update_download_task_v2( $this->task,$progress,'running');
182
  }
183
 
184
  public static function delete($remote , $files)
185
  {
186
+ global $wpvivid_plugin;
187
 
188
  set_time_limit(60);
189
 
190
+ $remote=$wpvivid_plugin->remote_collection->get_remote($remote);
191
 
192
  $result =$remote->cleanup($files);
193
 
includes/class-wpvivid-function-realize.php CHANGED
@@ -9,7 +9,7 @@ class WPvivid_Function_Realize
9
 
10
  public function _backup_cancel($task_id)
11
  {
12
- global $wpvivid_pulgin;
13
  if (WPvivid_taskmanager::get_task($task_id) !== false) {
14
  $file_name = WPvivid_taskmanager::get_task_options($task_id, 'file_prefix');
15
  $backup_options = WPvivid_taskmanager::get_task_options($task_id, 'backup_options');
@@ -20,7 +20,7 @@ class WPvivid_Function_Realize
20
  $timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT, array($task_id));
21
 
22
  if ($timestamp === false) {
23
- $wpvivid_pulgin->add_monitor_event($task_id, 10);
24
  }
25
  $ret['result'] = 'success';
26
  $ret['msg'] = __('The backup will be canceled after backing up the current chunk ends.', 'wpvivid');
@@ -28,11 +28,11 @@ class WPvivid_Function_Realize
28
  }
29
 
30
  public function _get_log_file($read_type, $param){
31
- global $wpvivid_pulgin;
32
  $ret['result']='failed';
33
  if($read_type == 'backuplist'){
34
  $backup_id = $param;
35
- $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
36
  if(!$backup) {
37
  $ret['result']='failed';
38
  $ret['error']=__('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
@@ -48,7 +48,7 @@ class WPvivid_Function_Realize
48
  }
49
  else if($read_type == 'lastlog'){
50
  $option = $param;
51
- $log_file_name= $wpvivid_pulgin->wpvivid_log->GetSaveLogFolder().$option.'_log.txt';
52
  if(!file_exists($log_file_name))
53
  {
54
  $information['result']='failed';
@@ -66,7 +66,7 @@ class WPvivid_Function_Realize
66
  $information['error']=__('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
67
  return $information;
68
  }
69
- $log_file_name= $wpvivid_pulgin->wpvivid_log->GetSaveLogFolder().$option.'_log.txt';
70
  if(!file_exists($log_file_name)) {
71
  $information['result']='failed';
72
  $information['error']=__('The log not found.', 'wpvivid');
9
 
10
  public function _backup_cancel($task_id)
11
  {
12
+ global $wpvivid_plugin;
13
  if (WPvivid_taskmanager::get_task($task_id) !== false) {
14
  $file_name = WPvivid_taskmanager::get_task_options($task_id, 'file_prefix');
15
  $backup_options = WPvivid_taskmanager::get_task_options($task_id, 'backup_options');
20
  $timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT, array($task_id));
21
 
22
  if ($timestamp === false) {
23
+ $wpvivid_plugin->add_monitor_event($task_id, 10);
24
  }
25
  $ret['result'] = 'success';
26
  $ret['msg'] = __('The backup will be canceled after backing up the current chunk ends.', 'wpvivid');
28
  }
29
 
30
  public function _get_log_file($read_type, $param){
31
+ global $wpvivid_plugin;
32
  $ret['result']='failed';
33
  if($read_type == 'backuplist'){
34
  $backup_id = $param;
35
+ $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
36
  if(!$backup) {
37
  $ret['result']='failed';
38
  $ret['error']=__('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
48
  }
49
  else if($read_type == 'lastlog'){
50
  $option = $param;
51
+ $log_file_name= $wpvivid_plugin->wpvivid_log->GetSaveLogFolder().$option.'_log.txt';
52
  if(!file_exists($log_file_name))
53
  {
54
  $information['result']='failed';
66
  $information['error']=__('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
67
  return $information;
68
  }
69
+ $log_file_name= $wpvivid_plugin->wpvivid_log->GetSaveLogFolder().$option.'_log.txt';
70
  if(!file_exists($log_file_name)) {
71
  $information['result']='failed';
72
  $information['error']=__('The log not found.', 'wpvivid');
includes/class-wpvivid-mail-report.php CHANGED
@@ -22,7 +22,7 @@ class WPvivid_mail_report
22
  return true;
23
  }
24
 
25
- if($task['status']['str']['str']=='completed'&&$option['always']==false)
26
  {
27
  return true;
28
  }
@@ -479,8 +479,8 @@ class WPvivid_mail_report
479
  }
480
  }
481
 
482
- global $wpvivid_pulgin;
483
- $server_info=json_encode($wpvivid_pulgin->get_website_info());
484
  $server_file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'wpvivid_server_info.json';
485
  if(file_exists($server_file_path))
486
  {
22
  return true;
23
  }
24
 
25
+ if($task['status']['str']=='completed'&&$option['always']==false)
26
  {
27
  return true;
28
  }
479
  }
480
  }
481
 
482
+ global $wpvivid_plugin;
483
+ $server_info=json_encode($wpvivid_plugin->get_website_info());
484
  $server_file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'wpvivid_server_info.json';
485
  if(file_exists($server_file_path))
486
  {
includes/class-wpvivid-migrate.php CHANGED
@@ -32,6 +32,9 @@ class WPvivid_Migrate
32
  add_filter('wpvivid_migrate_part_exec', array($this, 'wpvivid_migrate_part_exec'));
33
  add_filter('wpvivid_migrate_part_note', array($this, 'wpvivid_migrate_part_note'));
34
  add_filter('wpvivid_migrate_part_tip', array($this, 'wpvivid_migrate_part_tip'));
 
 
 
35
  }
36
 
37
  public function wpvivid_add_migrate_tab_page($page_array){
@@ -53,57 +56,20 @@ class WPvivid_Migrate
53
  <?php
54
  }
55
 
56
- public function wpvivid_add_page_migrate(){
57
- $migrate_descript = '';
58
- $migrate_key = '';
59
- $migrate_part_type = '';
60
- $migrate_part_exec = '';
61
- $migrate_part_note = '';
62
- $migrate_part_tip = '';
63
- ?>
64
- <div id="migrate-page" class="wrap-tab-content wpvivid_tab_migrate" name="tab-migrate" style="display: none;">
65
- <?php
66
- echo apply_filters('wpvivid_migrate_descript', $migrate_descript);
67
- echo apply_filters('wpvivid_put_transfer_key', $migrate_key);
68
- ?>
69
-
70
- <div style="clear: both;"></div>
71
-
72
- <div style="padding: 0 0 10px 0;">
73
- <div class="postbox" id="wpvivid_upload_backup_percent" style="display: none;">
74
- <div class="action-progress-bar" id="wpvivid_upload_progress_bar">
75
- <div class="action-progress-bar-percent" id="wpvivid_upload_progress_bar_percent" style="height:24px;width:0"></div>
76
- </div>
77
- <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing"></p></div>
78
- <div style="clear: both;"></div>
79
- <div>
80
- <div id="wpvivid_transfer_cancel" class="backup-log-btn"><input class="button-primary" id="wpvivid_transfer_cancel_btn" type="submit" value="<?php esc_attr_e( 'Cancel', 'wpvivid' ); ?>" /></div>
81
- </div>
82
- </div>
83
- </div>
84
-
85
- <div style="padding: 0 0 10px 0;">
86
-
87
- <?php echo apply_filters('wpvivid_migrate_part_type', $migrate_part_type); ?>
88
-
89
- <?php echo apply_filters('wpvivid_migrate_part_note', $migrate_part_note); ?>
90
 
91
- <div style="padding: 0 0 10px 0;">
92
- <?php echo apply_filters('wpvivid_migrate_part_exec', $migrate_part_exec); ?>
93
- </div>
94
- <div style="clear: both;"></div>
95
- <div style="padding: 10px 0 10px 0;">
96
- <?php echo apply_filters('wpvivid_migrate_part_tip', $migrate_part_tip); ?>
97
- </div>
98
- </div>
99
- </div>
100
  <script>
101
  var wpvivid_home_url = '<?php
102
  $wpvivid_siteurl = array();
103
  $wpvivid_siteurl=WPvivid_Admin::wpvivid_get_siteurl();
104
  echo esc_url($wpvivid_siteurl['home_url']);
105
  ?>';
106
- var source_site = '<?php echo admin_url('admin-ajax.php'); ?>';
107
  jQuery('input:radio[option=migrate][name=transfer]').click(function(){
108
  var value = jQuery(this).prop('value');
109
  if(value === 'transfer'){
@@ -121,101 +87,7 @@ class WPvivid_Migrate
121
 
122
  var wpvivid_transfer_id = '';
123
 
124
- function wpvivid_check_key(value){
125
- var pos = value.indexOf('?');
126
- var site_url = value.substring(0, pos);
127
- if(site_url == source_site){
128
- alert('The key generated by this site cannot be added into this site.');
129
- jQuery('#wpvivid_save_url_button').prop('disabled', true);
130
- }
131
- else{
132
- jQuery("#wpvivid_save_url_button").prop('disabled', false);
133
- }
134
- }
135
 
136
- function wpvivid_click_save_site_url()
137
- {
138
- var url= jQuery('#wpvivid_transfer_key_text').val();
139
- var ajax_data = {
140
- 'action': 'wpvivid_test_connect_site',
141
- 'url':url
142
- };
143
-
144
- jQuery("#wpvivid_save_url_button").prop('disabled', true);
145
- wpvivid_post_request(ajax_data, function (data)
146
- {
147
- jQuery("#wpvivid_save_url_button").prop('disabled', false);
148
- try
149
- {
150
- var jsonarray = jQuery.parseJSON(data);
151
- if(jsonarray.result==='success')
152
- {
153
- jQuery('#wpvivid_transfer_key').html(jsonarray.html);
154
- }
155
- else
156
- {
157
- alert(jsonarray.error);
158
- }
159
- }
160
- catch(err)
161
- {
162
- alert(err);
163
- }
164
- }, function (XMLHttpRequest, textStatus, errorThrown)
165
- {
166
- jQuery("#wpvivid_save_url_button").prop('disabled', false);
167
- var error_message = wpvivid_output_ajaxerror('saving key', textStatus, errorThrown);
168
- alert(error_message);
169
- });
170
- }
171
-
172
- function wpvivid_click_delete_transfer_key()
173
- {
174
- var ajax_data = {
175
- 'action': 'wpvivid_delete_transfer_key'
176
- };
177
-
178
- jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'none', 'opacity': '0.4'});
179
- wpvivid_post_request(ajax_data, function (data)
180
- {
181
- jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'none', 'opacity': '0.4'});
182
- try
183
- {
184
- var jsonarray = jQuery.parseJSON(data);
185
- if(jsonarray.result==='success')
186
- {
187
- jQuery('#wpvivid_transfer_key').html(jsonarray.html);
188
- }
189
- }
190
- catch(err)
191
- {
192
- alert(err);
193
- }
194
- }, function (XMLHttpRequest, textStatus, errorThrown)
195
- {
196
- jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'auto', 'opacity': '1'});
197
- var error_message = wpvivid_output_ajaxerror('deleting key', textStatus, errorThrown);
198
- alert(error_message);
199
- });
200
- }
201
-
202
- function wpvivid_click_generate_url()
203
- {
204
- //
205
- var expires=jQuery('#wpvivid_generate_url_expires').val();
206
- var ajax_data = {
207
- 'action': 'wpvivid_generate_url',
208
- 'expires':expires
209
- };
210
- wpvivid_post_request(ajax_data, function (data)
211
- {
212
- jQuery('#wpvivid_test_remote_site_url_text').val(data);
213
- }, function (XMLHttpRequest, textStatus, errorThrown)
214
- {
215
- var error_message = wpvivid_output_ajaxerror('generating key', textStatus, errorThrown);
216
- alert(error_message);
217
- });
218
- }
219
 
220
  function wpvivid_control_transfer_lock(){
221
  jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
@@ -229,78 +101,7 @@ class WPvivid_Migrate
229
  jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'auto', 'opacity': '1'});
230
  }
231
 
232
- function wpvivid_click_send_backup()
233
- {
234
- //send_to_remote
235
- var option_data = wpvivid_ajax_data_transfer('migrate');
236
- var ajax_data = {
237
- 'action': 'wpvivid_send_backup_to_site',
238
- 'backup_options':option_data
239
- };
240
- migrate_task_need_update=true;
241
- wpvivid_clear_notice('wpvivid_backup_notice');
242
- wpvivid_control_transfer_lock();
243
- wpvivid_post_request(ajax_data, function (data)
244
- {
245
- try
246
- {
247
- var jsonarray = jQuery.parseJSON(data);
248
- if(jsonarray.result==='failed')
249
- {
250
- wpvivid_delete_transfer_ready_task(jsonarray.error);
251
- }
252
- else{
253
- wpvivid_transfer_id = jsonarray.task_id;
254
- wpvivid_migrate_now(jsonarray.task_id);
255
- }
256
- }
257
- catch(err)
258
- {
259
- wpvivid_delete_transfer_ready_task(err);
260
- }
261
- }, function (XMLHttpRequest, textStatus, errorThrown)
262
- {
263
- var error_message = wpvivid_output_ajaxerror('trying to establish communication with your server', textStatus, errorThrown);
264
- wpvivid_delete_transfer_ready_task(error_message);
265
- });
266
- }
267
-
268
- function wpvivid_migrate_now(task_id){
269
- var ajax_data = {
270
- 'action': 'wpvivid_migrate_now',
271
- 'task_id': task_id
272
- };
273
- task_recheck_times = 0;
274
- migrate_task_need_update=true;
275
- wpvivid_post_request(ajax_data, function(data){
276
- }, function(XMLHttpRequest, textStatus, errorThrown) {
277
- });
278
- }
279
 
280
- function wpvivid_delete_transfer_ready_task(error){
281
- var ajax_data={
282
- 'action': 'wpvivid_delete_ready_task'
283
- };
284
- wpvivid_post_request(ajax_data, function (data) {
285
- try {
286
- var jsonarray = jQuery.parseJSON(data);
287
- if (jsonarray.result === 'success') {
288
- wpvivid_add_notice('Backup', 'Error', error);
289
- wpvivid_control_transfer_unlock();
290
- jQuery('#wpvivid_upload_backup_percent').hide();
291
- }
292
- }
293
- catch(err){
294
- wpvivid_add_notice('Backup', 'Error', err);
295
- wpvivid_control_transfer_unlock();
296
- jQuery('#wpvivid_upload_backup_percent').hide();
297
- }
298
- }, function (XMLHttpRequest, textStatus, errorThrown) {
299
- setTimeout(function () {
300
- wpvivid_delete_transfer_ready_task(error);
301
- }, 3000);
302
- });
303
- }
304
 
305
  function wpvivid_click_export_backup()
306
  {
@@ -322,25 +123,7 @@ class WPvivid_Migrate
322
 
323
  var wpvivid_display_get_key = false;
324
 
325
- function click_dismiss_key_notice(obj){
326
- wpvivid_display_get_key = false;
327
- jQuery(obj).parent().remove();
328
- }
329
 
330
- function wpvivid_click_how_to_get_key(){
331
- if(!wpvivid_display_get_key) {
332
- wpvivid_display_get_key = true;
333
- var div = "<div class='notice notice-info is-dismissible inline'>" +
334
- "<p>1. Visit Key tab page of WPvivid backup plugin of destination site.</p>" +
335
- "<p>2. Generate a key by clicking Generate button and copy it.</p>" +
336
- "<p>3. Go back to this page and paste the key in key box below. Lastly, click Save button.</p>" +
337
- "<button type='button' class='notice-dismiss' onclick='click_dismiss_key_notice(this);'>" +
338
- "<span class='screen-reader-text'>Dismiss this notice.</span>" +
339
- "</button>" +
340
- "</div>";
341
- jQuery('#wpvivid_how_to_get_key').append(div);
342
- }
343
- }
344
 
345
  function wpvivid_transfer_cancel_flow()
346
  {
@@ -535,11 +318,62 @@ class WPvivid_Migrate
535
  var top = jQuery('#'+storage_page_id).offset().top-jQuery('#'+storage_page_id).height();
536
  jQuery('html, body').animate({scrollTop:top}, 'slow');
537
  }
538
-
539
  </script>
540
  <?php
541
  }
542
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
543
  public function wpvivid_add_page_key(){
544
  ?>
545
  <div id="key-page" class="wrap-tab-content wpvivid_tab_key" name="tab-key" style="display: none;">
@@ -571,6 +405,23 @@ class WPvivid_Migrate
571
  return false;
572
  });
573
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
574
  </script>
575
  <?php
576
  }
@@ -820,8 +671,8 @@ class WPvivid_Migrate
820
 
821
  $task_id = $ret['task_id'];
822
 
823
- global $wpvivid_pulgin;
824
- $wpvivid_pulgin->check_backup($task_id, $backup['backup_files']);
825
  echo json_encode($ret);
826
  die();
827
  }
@@ -845,8 +696,8 @@ class WPvivid_Migrate
845
  $task_id=sanitize_key($_POST['task_id']);
846
 
847
  //Start backup site
848
- global $wpvivid_pulgin;
849
- $wpvivid_pulgin->backup($task_id);
850
  die();
851
  }
852
 
@@ -870,17 +721,17 @@ class WPvivid_Migrate
870
  $task=$backup_task->new_backup_task($backup,'Manual', 'export');
871
 
872
  $task_id=$task['task_id'];
873
- global $wpvivid_pulgin;
874
  //add_action('wpvivid_handle_upload_succeed',array($this,'wpvivid_deal_upload_succeed'),11);
875
- $wpvivid_pulgin->check_backup($task_id,$backup['backup_files']);
876
- $wpvivid_pulgin->backup($task_id);
877
  //}
878
  die();
879
  }
880
 
881
  function wpvivid_handle_backup_failed($task)
882
  {
883
- global $wpvivid_pulgin;
884
  if($task['action'] === 'transfer') {
885
  $backup_error_array = WPvivid_Setting::get_option('wpvivid_transfer_error_array');
886
  if (empty($backup_error_array)) {
@@ -893,14 +744,14 @@ class WPvivid_Migrate
893
  }
894
  $backup=new WPvivid_Backup($task['id']);
895
  $backup->clean_backup();
896
- $wpvivid_pulgin->wpvivid_log->WriteLog('Upload failed. Delete task '.$task['id'], 'notice');
897
  WPvivid_Backuplist::delete_backup($task['id']);
898
  }
899
  }
900
 
901
  public function wpvivid_deal_upload_succeed($task)
902
  {
903
- global $wpvivid_pulgin;
904
  if($task['action'] === 'transfer')
905
  {
906
  $backup_success_count = WPvivid_Setting::get_option('wpvivid_transfer_success_count');
@@ -911,7 +762,7 @@ class WPvivid_Migrate
911
  $backup_success_count++;
912
  WPvivid_Setting::update_option('wpvivid_transfer_success_count', $backup_success_count);
913
 
914
- $wpvivid_pulgin->wpvivid_log->WriteLog('Upload finished. Delete task '.$task['id'], 'notice');
915
  WPvivid_Backuplist::delete_backup($task['id']);
916
  }
917
  }
@@ -999,7 +850,107 @@ class WPvivid_Migrate
999
  <p>'.$key_status.'</p>
1000
  <p>The connection is ok. Now you can transfer the site <strong>'.$source_dir.'</strong> to the site <strong>'.$target_dir.'</strong></p>';
1001
  }
1002
- $html.='</div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1003
  return $html;
1004
  }
1005
 
@@ -1029,7 +980,81 @@ class WPvivid_Migrate
1029
  $html = '';
1030
  $html .= '<div id="wpvivid_transfer_btn" style="float: left;">
1031
  <input class="button-primary quicktransfer-btn" type="submit" value="'.esc_attr( 'Clone then Transfer', 'wpvivid').'" onclick="wpvivid_click_send_backup();" />
1032
- </div>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1033
  return $html;
1034
  }
1035
 
@@ -1070,7 +1095,7 @@ class WPvivid_Migrate
1070
 
1071
  public function list_tasks()
1072
  {
1073
- global $wpvivid_pulgin;
1074
  $tasks=WPvivid_Setting::get_tasks();
1075
  $ret=array();
1076
  $list_tasks=array();
@@ -1085,12 +1110,12 @@ class WPvivid_Migrate
1085
 
1086
  if($timestamp===false)
1087
  {
1088
- $wpvivid_pulgin->add_monitor_event($task['id'],20);
1089
  }
1090
  }
1091
  if($list_tasks[$task['id']]['task_info']['need_update_last_task']===true){
1092
  $task_msg = WPvivid_taskmanager::get_task($task['id']);
1093
- $wpvivid_pulgin->update_last_backup_task($task_msg);
1094
  }
1095
  $list_tasks[$task['id']]['progress_html'] = '<div class="action-progress-bar" id="wpvivid_upload_progress_bar">
1096
  <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>
32
  add_filter('wpvivid_migrate_part_exec', array($this, 'wpvivid_migrate_part_exec'));
33
  add_filter('wpvivid_migrate_part_note', array($this, 'wpvivid_migrate_part_note'));
34
  add_filter('wpvivid_migrate_part_tip', array($this, 'wpvivid_migrate_part_tip'));
35
+
36
+ add_filter('wpvivid_load_migrate_js', array($this, 'wpvivid_load_migrate_js'));
37
+ add_action('wpvivid_add_migrate_js', array($this, 'wpvivid_add_migrate_js'));
38
  }
39
 
40
  public function wpvivid_add_migrate_tab_page($page_array){
56
  <?php
57
  }
58
 
59
+ public function wpvivid_load_migrate_js($html){
60
+ do_action('wpvivid_add_migrate_js');
61
+ return $html;
62
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
 
64
+ public function wpvivid_add_migrate_js(){
65
+ ?>
 
 
 
 
 
 
 
66
  <script>
67
  var wpvivid_home_url = '<?php
68
  $wpvivid_siteurl = array();
69
  $wpvivid_siteurl=WPvivid_Admin::wpvivid_get_siteurl();
70
  echo esc_url($wpvivid_siteurl['home_url']);
71
  ?>';
72
+
73
  jQuery('input:radio[option=migrate][name=transfer]').click(function(){
74
  var value = jQuery(this).prop('value');
75
  if(value === 'transfer'){
87
 
88
  var wpvivid_transfer_id = '';
89
 
 
 
 
 
 
 
 
 
 
 
 
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
  function wpvivid_control_transfer_lock(){
93
  jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
101
  jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'auto', 'opacity': '1'});
102
  }
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  function wpvivid_click_export_backup()
107
  {
123
 
124
  var wpvivid_display_get_key = false;
125
 
 
 
 
 
126
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
 
128
  function wpvivid_transfer_cancel_flow()
129
  {
318
  var top = jQuery('#'+storage_page_id).offset().top-jQuery('#'+storage_page_id).height();
319
  jQuery('html, body').animate({scrollTop:top}, 'slow');
320
  }
 
321
  </script>
322
  <?php
323
  }
324
 
325
+
326
+ public function wpvivid_add_page_migrate(){
327
+ $migrate_descript = '';
328
+ $migrate_key = '';
329
+ $migrate_part_type = '';
330
+ $migrate_part_exec = '';
331
+ $migrate_part_note = '';
332
+ $migrate_part_tip = '';
333
+ ?>
334
+ <div id="migrate-page" class="wrap-tab-content wpvivid_tab_migrate" name="tab-migrate" style="display: none;">
335
+ <?php
336
+ echo apply_filters('wpvivid_migrate_descript', $migrate_descript);
337
+ echo apply_filters('wpvivid_put_transfer_key', $migrate_key);
338
+ ?>
339
+
340
+ <div style="clear: both;"></div>
341
+
342
+ <div style="padding: 0 0 10px 0;">
343
+ <div class="postbox" id="wpvivid_upload_backup_percent" style="display: none;">
344
+ <div class="action-progress-bar" id="wpvivid_upload_progress_bar">
345
+ <div class="action-progress-bar-percent" id="wpvivid_upload_progress_bar_percent" style="height:24px;width:0"></div>
346
+ </div>
347
+ <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing"></p></div>
348
+ <div style="clear: both;"></div>
349
+ <div>
350
+ <div id="wpvivid_transfer_cancel" class="backup-log-btn"><input class="button-primary" id="wpvivid_transfer_cancel_btn" type="submit" value="<?php esc_attr_e( 'Cancel', 'wpvivid' ); ?>" /></div>
351
+ </div>
352
+ </div>
353
+ </div>
354
+
355
+ <div style="padding: 0 0 10px 0;">
356
+
357
+ <?php echo apply_filters('wpvivid_migrate_part_type', $migrate_part_type); ?>
358
+
359
+ <?php echo apply_filters('wpvivid_migrate_part_note', $migrate_part_note); ?>
360
+
361
+ <div style="padding: 0 0 10px 0;">
362
+ <?php echo apply_filters('wpvivid_migrate_part_exec', $migrate_part_exec); ?>
363
+ </div>
364
+ <div style="clear: both;"></div>
365
+ <div style="padding: 10px 0 10px 0;">
366
+ <?php echo apply_filters('wpvivid_migrate_part_tip', $migrate_part_tip); ?>
367
+ </div>
368
+ </div>
369
+ </div>
370
+ <?php
371
+ $js = '';
372
+ apply_filters('wpvivid_load_migrate_js', $js);
373
+ ?>
374
+ <?php
375
+ }
376
+
377
  public function wpvivid_add_page_key(){
378
  ?>
379
  <div id="key-page" class="wrap-tab-content wpvivid_tab_key" name="tab-key" style="display: none;">
405
  return false;
406
  });
407
  });
408
+ function wpvivid_click_generate_url()
409
+ {
410
+ //
411
+ var expires=jQuery('#wpvivid_generate_url_expires').val();
412
+ var ajax_data = {
413
+ 'action': 'wpvivid_generate_url',
414
+ 'expires':expires
415
+ };
416
+ wpvivid_post_request(ajax_data, function (data)
417
+ {
418
+ jQuery('#wpvivid_test_remote_site_url_text').val(data);
419
+ }, function (XMLHttpRequest, textStatus, errorThrown)
420
+ {
421
+ var error_message = wpvivid_output_ajaxerror('generating key', textStatus, errorThrown);
422
+ alert(error_message);
423
+ });
424
+ }
425
  </script>
426
  <?php
427
  }
671
 
672
  $task_id = $ret['task_id'];
673
 
674
+ global $wpvivid_plugin;
675
+ $wpvivid_plugin->check_backup($task_id, $backup['backup_files']);
676
  echo json_encode($ret);
677
  die();
678
  }
696
  $task_id=sanitize_key($_POST['task_id']);
697
 
698
  //Start backup site
699
+ global $wpvivid_plugin;
700
+ $wpvivid_plugin->backup($task_id);
701
  die();
702
  }
703
 
721
  $task=$backup_task->new_backup_task($backup,'Manual', 'export');
722
 
723
  $task_id=$task['task_id'];
724
+ global $wpvivid_plugin;
725
  //add_action('wpvivid_handle_upload_succeed',array($this,'wpvivid_deal_upload_succeed'),11);
726
+ $wpvivid_plugin->check_backup($task_id,$backup['backup_files']);
727
+ $wpvivid_plugin->backup($task_id);
728
  //}
729
  die();
730
  }
731
 
732
  function wpvivid_handle_backup_failed($task)
733
  {
734
+ global $wpvivid_plugin;
735
  if($task['action'] === 'transfer') {
736
  $backup_error_array = WPvivid_Setting::get_option('wpvivid_transfer_error_array');
737
  if (empty($backup_error_array)) {
744
  }
745
  $backup=new WPvivid_Backup($task['id']);
746
  $backup->clean_backup();
747
+ $wpvivid_plugin->wpvivid_log->WriteLog('Upload failed. Delete task '.$task['id'], 'notice');
748
  WPvivid_Backuplist::delete_backup($task['id']);
749
  }
750
  }
751
 
752
  public function wpvivid_deal_upload_succeed($task)
753
  {
754
+ global $wpvivid_plugin;
755
  if($task['action'] === 'transfer')
756
  {
757
  $backup_success_count = WPvivid_Setting::get_option('wpvivid_transfer_success_count');
762
  $backup_success_count++;
763
  WPvivid_Setting::update_option('wpvivid_transfer_success_count', $backup_success_count);
764
 
765
+ $wpvivid_plugin->wpvivid_log->WriteLog('Upload finished. Delete task '.$task['id'], 'notice');
766
  WPvivid_Backuplist::delete_backup($task['id']);
767
  }
768
  }
850
  <p>'.$key_status.'</p>
851
  <p>The connection is ok. Now you can transfer the site <strong>'.$source_dir.'</strong> to the site <strong>'.$target_dir.'</strong></p>';
852
  }
853
+ $html.='</div>
854
+ <script>
855
+ var source_site = \''.admin_url('admin-ajax.php').'\';
856
+ function wpvivid_check_key(value){
857
+ var pos = value.indexOf(\'?\');
858
+ var site_url = value.substring(0, pos);
859
+ if(site_url == source_site){
860
+ alert(\'The key generated by this site cannot be added into this site.\');
861
+ jQuery(\'#wpvivid_save_url_button\').prop(\'disabled\', true);
862
+ }
863
+ else{
864
+ jQuery("#wpvivid_save_url_button").prop(\'disabled\', false);
865
+ }
866
+ }
867
+
868
+ function wpvivid_click_save_site_url()
869
+ {
870
+ var url= jQuery(\'#wpvivid_transfer_key_text\').val();
871
+ var ajax_data = {
872
+ \'action\': \'wpvivid_test_connect_site\',
873
+ \'url\':url
874
+ };
875
+
876
+ jQuery("#wpvivid_save_url_button").prop(\'disabled\', true);
877
+ wpvivid_post_request(ajax_data, function (data)
878
+ {
879
+ jQuery("#wpvivid_save_url_button").prop(\'disabled\', false);
880
+ try
881
+ {
882
+ var jsonarray = jQuery.parseJSON(data);
883
+ if(jsonarray.result===\'success\')
884
+ {
885
+ jQuery(\'#wpvivid_transfer_key\').html(jsonarray.html);
886
+ }
887
+ else
888
+ {
889
+ alert(jsonarray.error);
890
+ }
891
+ }
892
+ catch(err)
893
+ {
894
+ alert(err);
895
+ }
896
+ }, function (XMLHttpRequest, textStatus, errorThrown)
897
+ {
898
+ jQuery("#wpvivid_save_url_button").prop(\'disabled\', false);
899
+ var error_message = wpvivid_output_ajaxerror(\'saving key\', textStatus, errorThrown);
900
+ alert(error_message);
901
+ });
902
+ }
903
+
904
+ function wpvivid_click_delete_transfer_key()
905
+ {
906
+ var ajax_data = {
907
+ \'action\': \'wpvivid_delete_transfer_key\'
908
+ };
909
+
910
+ jQuery("#wpvivid_delete_key_button").css({\'pointer-events\': \'none\', \'opacity\': \'0.4\'});
911
+ wpvivid_post_request(ajax_data, function (data)
912
+ {
913
+ jQuery("#wpvivid_delete_key_button").css({\'pointer-events\': \'none\', \'opacity\': \'0.4\'});
914
+ try
915
+ {
916
+ var jsonarray = jQuery.parseJSON(data);
917
+ if(jsonarray.result===\'success\')
918
+ {
919
+ jQuery(\'#wpvivid_transfer_key\').html(jsonarray.html);
920
+ }
921
+ }
922
+ catch(err)
923
+ {
924
+ alert(err);
925
+ }
926
+ }, function (XMLHttpRequest, textStatus, errorThrown)
927
+ {
928
+ jQuery("#wpvivid_delete_key_button").css({\'pointer-events\': \'auto\', \'opacity\': \'1\'});
929
+ var error_message = wpvivid_output_ajaxerror(\'deleting key\', textStatus, errorThrown);
930
+ alert(error_message);
931
+ });
932
+ }
933
+
934
+ function click_dismiss_key_notice(obj){
935
+ wpvivid_display_get_key = false;
936
+ jQuery(obj).parent().remove();
937
+ }
938
+
939
+ function wpvivid_click_how_to_get_key(){
940
+ if(!wpvivid_display_get_key) {
941
+ wpvivid_display_get_key = true;
942
+ var div = "<div class=\'notice notice-info is-dismissible inline\'>" +
943
+ "<p>1. Visit Key tab page of WPvivid backup plugin of destination site.</p>" +
944
+ "<p>2. Generate a key by clicking Generate button and copy it.</p>" +
945
+ "<p>3. Go back to this page and paste the key in key box below. Lastly, click Save button.</p>" +
946
+ "<button type=\'button\' class=\'notice-dismiss\' onclick=\'click_dismiss_key_notice(this);\'>" +
947
+ "<span class=\'screen-reader-text\'>Dismiss this notice.</span>" +
948
+ "</button>" +
949
+ "</div>";
950
+ jQuery(\'#wpvivid_how_to_get_key\').append(div);
951
+ }
952
+ }
953
+ </script>';
954
  return $html;
955
  }
956
 
980
  $html = '';
981
  $html .= '<div id="wpvivid_transfer_btn" style="float: left;">
982
  <input class="button-primary quicktransfer-btn" type="submit" value="'.esc_attr( 'Clone then Transfer', 'wpvivid').'" onclick="wpvivid_click_send_backup();" />
983
+ </div>
984
+ <script>
985
+ function wpvivid_click_send_backup()
986
+ {
987
+ //send_to_remote
988
+ var option_data = wpvivid_ajax_data_transfer(\'migrate\');
989
+ var ajax_data = {
990
+ \'action\': \'wpvivid_send_backup_to_site\',
991
+ \'backup_options\':option_data
992
+ };
993
+ migrate_task_need_update=true;
994
+ wpvivid_clear_notice(\'wpvivid_backup_notice\');
995
+ wpvivid_control_transfer_lock();
996
+ wpvivid_post_request(ajax_data, function (data)
997
+ {
998
+ try
999
+ {
1000
+ var jsonarray = jQuery.parseJSON(data);
1001
+ if(jsonarray.result===\'failed\')
1002
+ {
1003
+ wpvivid_delete_transfer_ready_task(jsonarray.error);
1004
+ }
1005
+ else{
1006
+ wpvivid_transfer_id = jsonarray.task_id;
1007
+ wpvivid_migrate_now(jsonarray.task_id);
1008
+ }
1009
+ }
1010
+ catch(err)
1011
+ {
1012
+ wpvivid_delete_transfer_ready_task(err);
1013
+ }
1014
+ }, function (XMLHttpRequest, textStatus, errorThrown)
1015
+ {
1016
+ var error_message = wpvivid_output_ajaxerror(\'trying to establish communication with your server\', textStatus, errorThrown);
1017
+ wpvivid_delete_transfer_ready_task(error_message);
1018
+ });
1019
+ }
1020
+
1021
+ function wpvivid_migrate_now(task_id){
1022
+ var ajax_data = {
1023
+ \'action\': \'wpvivid_migrate_now\',
1024
+ \'task_id\': task_id
1025
+ };
1026
+ task_recheck_times = 0;
1027
+ migrate_task_need_update=true;
1028
+ wpvivid_post_request(ajax_data, function(data){
1029
+ }, function(XMLHttpRequest, textStatus, errorThrown) {
1030
+ });
1031
+ }
1032
+
1033
+ function wpvivid_delete_transfer_ready_task(error){
1034
+ var ajax_data={
1035
+ \'action\': \'wpvivid_delete_ready_task\'
1036
+ };
1037
+ wpvivid_post_request(ajax_data, function (data) {
1038
+ try {
1039
+ var jsonarray = jQuery.parseJSON(data);
1040
+ if (jsonarray.result === \'success\') {
1041
+ wpvivid_add_notice(\'Backup\', \'Error\', error);
1042
+ wpvivid_control_transfer_unlock();
1043
+ jQuery(\'#wpvivid_upload_backup_percent\').hide();
1044
+ }
1045
+ }
1046
+ catch(err){
1047
+ wpvivid_add_notice(\'Backup\', \'Error\', err);
1048
+ wpvivid_control_transfer_unlock();
1049
+ jQuery(\'#wpvivid_upload_backup_percent\').hide();
1050
+ }
1051
+ }, function (XMLHttpRequest, textStatus, errorThrown) {
1052
+ setTimeout(function () {
1053
+ wpvivid_delete_transfer_ready_task(error);
1054
+ }, 3000);
1055
+ });
1056
+ }
1057
+ </script>';
1058
  return $html;
1059
  }
1060
 
1095
 
1096
  public function list_tasks()
1097
  {
1098
+ global $wpvivid_plugin;
1099
  $tasks=WPvivid_Setting::get_tasks();
1100
  $ret=array();
1101
  $list_tasks=array();
1110
 
1111
  if($timestamp===false)
1112
  {
1113
+ $wpvivid_plugin->add_monitor_event($task['id'],20);
1114
  }
1115
  }
1116
  if($list_tasks[$task['id']]['task_info']['need_update_last_task']===true){
1117
  $task_msg = WPvivid_taskmanager::get_task($task['id']);
1118
+ $wpvivid_plugin->update_last_backup_task($task_msg);
1119
  }
1120
  $list_tasks[$task['id']]['progress_html'] = '<div class="action-progress-bar" id="wpvivid_upload_progress_bar">
1121
  <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>
includes/class-wpvivid-mysqldump-wpdb.php CHANGED
@@ -411,8 +411,8 @@ class WPvivid_Mysqldump_wpdb
411
  if($this->task_id!=='')
412
  {
413
  $message='Preparing to dump table '.$table;
414
- global $wpvivid_pulgin;
415
- $wpvivid_pulgin->wpvivid_log->WriteLog($message,'notice');
416
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
417
  }
418
 
@@ -584,8 +584,8 @@ class WPvivid_Mysqldump_wpdb
584
  if($i_check_cancel>5)
585
  {
586
  $i_check_cancel=0;
587
- global $wpvivid_pulgin;
588
- $wpvivid_pulgin->check_cancel_backup($this->task_id);
589
  }
590
  $message='Dumping table '.$tableName.', rows dumped: '.$count.' rows.';
591
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
@@ -627,8 +627,8 @@ class WPvivid_Mysqldump_wpdb
627
 
628
  if ($this->dumpSettings['lock-tables']) {
629
  if($this -> privileges['LOCK TABLES'] == 0){
630
- global $wpvivid_pulgin;
631
- $wpvivid_pulgin->wpvivid_log->WriteLog('The lack of LOCK TABLES privilege, the backup will skip lock_tables() to continue.','notice');
632
  }else{
633
  $this->typeAdapter->lock_table($tableName);
634
  }
411
  if($this->task_id!=='')
412
  {
413
  $message='Preparing to dump table '.$table;
414
+ global $wpvivid_plugin;
415
+ $wpvivid_plugin->wpvivid_log->WriteLog($message,'notice');
416
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
417
  }
418
 
584
  if($i_check_cancel>5)
585
  {
586
  $i_check_cancel=0;
587
+ global $wpvivid_plugin;
588
+ $wpvivid_plugin->check_cancel_backup($this->task_id);
589
  }
590
  $message='Dumping table '.$tableName.', rows dumped: '.$count.' rows.';
591
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
627
 
628
  if ($this->dumpSettings['lock-tables']) {
629
  if($this -> privileges['LOCK TABLES'] == 0){
630
+ global $wpvivid_plugin;
631
+ $wpvivid_plugin->wpvivid_log->WriteLog('The lack of LOCK TABLES privilege, the backup will skip lock_tables() to continue.','notice');
632
  }else{
633
  $this->typeAdapter->lock_table($tableName);
634
  }
includes/class-wpvivid-mysqldump.php CHANGED
@@ -374,29 +374,29 @@ class WPvivid_Mysqldump
374
  }
375
  $this->exportTables();
376
  /*
377
- global $wpvivid_pulgin;
378
 
379
  $this->exportTables();
380
  if($this -> privileges['SHOW VIEW'] == 0){
381
- $wpvivid_pulgin->wpvivid_log->WriteLog('The lack of SHOW VIEW privilege, the backup will skip exportViews() to continue.','notice');
382
  }else{
383
  $this->exportViews();
384
  }
385
 
386
  if($this -> privileges['TRIGGER'] == 0){
387
- $wpvivid_pulgin->wpvivid_log->WriteLog('The lack of TRIGGER privilege, the backup will skip exportTriggers() to continue.','notice');
388
  }else{
389
  $this->exportTriggers();
390
  }
391
 
392
  if($this -> privileges['CREATE ROUTINE'] == 0){
393
- $wpvivid_pulgin->wpvivid_log->WriteLog('The lack of CREATE ROUTINE privilege, the backup will skip exportProcedures() to continue.','notice');
394
  }else{
395
  $this->exportProcedures();
396
  }
397
 
398
  if($this -> privileges['EVENT'] == 0){
399
- $wpvivid_pulgin->wpvivid_log->WriteLog('The lack of EVENT privilege, the backup will skip exportEvents() to continue.','notice');
400
  }else{
401
  $this->exportEvents();
402
  }
@@ -594,17 +594,17 @@ class WPvivid_Mysqldump
594
  if($this->task_id!=='')
595
  {
596
  $message='Preparing to dump table '.$table;
597
- global $wpvivid_pulgin;
598
- $wpvivid_pulgin->wpvivid_log->WriteLog($message,'notice');
599
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
600
  }
601
 
602
  $this->getTableStructure($table);
603
  if($this->tableColumnTypes[$table]===false)
604
  {
605
- global $wpvivid_pulgin;
606
  $message='get Table Structure failed. table:'.$table;
607
- $wpvivid_pulgin->wpvivid_log->WriteLog($message,'notice');
608
  continue;
609
  }
610
  if ( false === $this->dumpSettings['no-data'] ) { // don't break compatibility with old trigger
@@ -740,7 +740,7 @@ class WPvivid_Mysqldump
740
  );
741
  if($columns===false)
742
  {
743
- global $wpvivid_pulgin;
744
  $error=$this->typeAdapter->errorInfo();
745
  if(isset($error[2])){
746
  $error = 'Error: '.$error[2];
@@ -749,7 +749,7 @@ class WPvivid_Mysqldump
749
  $error = '';
750
  }
751
  $message='Show columns failed. '.$error;
752
- $wpvivid_pulgin->wpvivid_log->WriteLog($message, 'warning');
753
  $columns = $this->query(
754
  'DESCRIBE '.$tableName
755
  );
@@ -763,7 +763,7 @@ class WPvivid_Mysqldump
763
  $error = '';
764
  }
765
  $message='DESCRIBE failed. '.$error;
766
- $wpvivid_pulgin->wpvivid_log->WriteLog($message, 'warning');
767
  return false;
768
  }
769
  }
@@ -999,6 +999,25 @@ class WPvivid_Mysqldump
999
  }
1000
 
1001
  $resultSet = $this->query($stmt);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1002
  $i=0;
1003
  $i_check_cancel=0;
1004
  $count=0;
@@ -1047,8 +1066,8 @@ class WPvivid_Mysqldump
1047
  if($i_check_cancel>5)
1048
  {
1049
  $i_check_cancel=0;
1050
- global $wpvivid_pulgin;
1051
- $wpvivid_pulgin->check_cancel_backup($this->task_id);
1052
  }
1053
  $message='Dumping table '.$tableName.', rows dumped: '.$count.' rows.';
1054
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
@@ -1095,8 +1114,8 @@ class WPvivid_Mysqldump
1095
  $this->typeAdapter->lock_table($tableName);
1096
  //if($this -> privileges['LOCK TABLES'] == 0)
1097
  //{
1098
- //global $wpvivid_pulgin;
1099
- // $wpvivid_pulgin->wpvivid_log->WriteLog('The lack of LOCK TABLES privilege, the backup will skip lock_tables() to continue.','notice');
1100
  //}else{
1101
  // $this->typeAdapter->lock_table($tableName);
1102
  //}
374
  }
375
  $this->exportTables();
376
  /*
377
+ global $wpvivid_plugin;
378
 
379
  $this->exportTables();
380
  if($this -> privileges['SHOW VIEW'] == 0){
381
+ $wpvivid_plugin->wpvivid_log->WriteLog('The lack of SHOW VIEW privilege, the backup will skip exportViews() to continue.','notice');
382
  }else{
383
  $this->exportViews();
384
  }
385
 
386
  if($this -> privileges['TRIGGER'] == 0){
387
+ $wpvivid_plugin->wpvivid_log->WriteLog('The lack of TRIGGER privilege, the backup will skip exportTriggers() to continue.','notice');
388
  }else{
389
  $this->exportTriggers();
390
  }
391
 
392
  if($this -> privileges['CREATE ROUTINE'] == 0){
393
+ $wpvivid_plugin->wpvivid_log->WriteLog('The lack of CREATE ROUTINE privilege, the backup will skip exportProcedures() to continue.','notice');
394
  }else{
395
  $this->exportProcedures();
396
  }
397
 
398
  if($this -> privileges['EVENT'] == 0){
399
+ $wpvivid_plugin->wpvivid_log->WriteLog('The lack of EVENT privilege, the backup will skip exportEvents() to continue.','notice');
400
  }else{
401
  $this->exportEvents();
402
  }
594
  if($this->task_id!=='')
595
  {
596
  $message='Preparing to dump table '.$table;
597
+ global $wpvivid_plugin;
598
+ $wpvivid_plugin->wpvivid_log->WriteLog($message,'notice');
599
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
600
  }
601
 
602
  $this->getTableStructure($table);
603
  if($this->tableColumnTypes[$table]===false)
604
  {
605
+ global $wpvivid_plugin;
606
  $message='get Table Structure failed. table:'.$table;
607
+ $wpvivid_plugin->wpvivid_log->WriteLog($message,'notice');
608
  continue;
609
  }
610
  if ( false === $this->dumpSettings['no-data'] ) { // don't break compatibility with old trigger
740
  );
741
  if($columns===false)
742
  {
743
+ global $wpvivid_plugin;
744
  $error=$this->typeAdapter->errorInfo();
745
  if(isset($error[2])){
746
  $error = 'Error: '.$error[2];
749
  $error = '';
750
  }
751
  $message='Show columns failed. '.$error;
752
+ $wpvivid_plugin->wpvivid_log->WriteLog($message, 'warning');
753
  $columns = $this->query(
754
  'DESCRIBE '.$tableName
755
  );
763
  $error = '';
764
  }
765
  $message='DESCRIBE failed. '.$error;
766
+ $wpvivid_plugin->wpvivid_log->WriteLog($message, 'warning');
767
  return false;
768
  }
769
  }
999
  }
1000
 
1001
  $resultSet = $this->query($stmt);
1002
+
1003
+ if($resultSet===false)
1004
+ {
1005
+ global $wpvivid_plugin;
1006
+ $error=$this->typeAdapter->errorInfo();
1007
+ if(isset($error[2])){
1008
+ $error = 'Error: '.$error[2];
1009
+ }
1010
+ else{
1011
+ $error = '';
1012
+ }
1013
+
1014
+ $message='listValues failed. '.$error;
1015
+ $wpvivid_plugin->wpvivid_log->WriteLog($message, 'warning');
1016
+
1017
+ $this->endListValues($tableName);
1018
+ return ;
1019
+ }
1020
+
1021
  $i=0;
1022
  $i_check_cancel=0;
1023
  $count=0;
1066
  if($i_check_cancel>5)
1067
  {
1068
  $i_check_cancel=0;
1069
+ global $wpvivid_plugin;
1070
+ $wpvivid_plugin->check_cancel_backup($this->task_id);
1071
  }
1072
  $message='Dumping table '.$tableName.', rows dumped: '.$count.' rows.';
1073
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'backup',WPVIVID_BACKUP_TYPE_DB,0,$message);
1114
  $this->typeAdapter->lock_table($tableName);
1115
  //if($this -> privileges['LOCK TABLES'] == 0)
1116
  //{
1117
+ //global $wpvivid_plugin;
1118
+ // $wpvivid_plugin->wpvivid_log->WriteLog('The lack of LOCK TABLES privilege, the backup will skip lock_tables() to continue.','notice');
1119
  //}else{
1120
  // $this->typeAdapter->lock_table($tableName);
1121
  //}
includes/class-wpvivid-public-interface.php CHANGED
@@ -8,20 +8,20 @@ class WPvivid_Public_Interface
8
  }
9
 
10
  public function prepare_backup($backup_options){
11
- global $wpvivid_pulgin;
12
  if(isset($backup_options)&&!empty($backup_options)){
13
  if (is_null($backup_options)) {
14
  $ret['error']='Invalid parameter param:'.$backup_options;
15
  return $ret;
16
  }
17
- $ret = $wpvivid_pulgin->check_backup_option($backup_options);
18
  if($ret['result']!='success') {
19
  return $ret;
20
  }
21
- $ret=$wpvivid_pulgin->pre_backup($backup_options,'Manual');
22
  if($ret['result']=='success') {
23
  //Check the website data to be backed up
24
- $ret['check']=$wpvivid_pulgin->check_backup($ret['task_id'],$backup_options['backup_files']);
25
  if(isset($ret['check']['result']) && $ret['check']['result'] == 'failed') {
26
  $ret['error']=$ret['check']['error'];
27
  return $ret;
@@ -36,7 +36,7 @@ class WPvivid_Public_Interface
36
  }
37
 
38
  public function backup_now($task_id){
39
- global $wpvivid_pulgin;
40
  if (!isset($task_id)||empty($task_id)||!is_string($task_id))
41
  {
42
  $ret['error']=__('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid');
@@ -60,7 +60,7 @@ class WPvivid_Public_Interface
60
  flush();
61
 
62
  //Start backup site
63
- $wpvivid_pulgin->backup($task_id);
64
  $ret['result']='success';
65
  }
66
 
@@ -103,14 +103,14 @@ class WPvivid_Public_Interface
103
  }
104
 
105
  public function get_default_remote(){
106
- global $wpvivid_pulgin;
107
  $ret['result']='success';
108
- $ret['remote_storage_type']=$wpvivid_pulgin->function_realize->_get_default_remote_storage();
109
  return $ret;
110
  }
111
 
112
  public function delete_backup($backup_id, $force_del){
113
- global $wpvivid_pulgin;
114
  if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
115
  $ret['error']='Invalid parameter param: backup_id.';
116
  return $ret;
@@ -125,14 +125,14 @@ class WPvivid_Public_Interface
125
  $force_del=0;
126
  }
127
  $backup_id=sanitize_key($backup_id);
128
- $ret=$wpvivid_pulgin->delete_backup_by_id($backup_id, $force_del);
129
  $backuplist=WPvivid_Backuplist::get_backuplist();
130
  $ret['wpvivid']['backup_list']=$backuplist;
131
  return $ret;
132
  }
133
 
134
  public function delete_backup_array($backup_id_array){
135
- global $wpvivid_pulgin;
136
  if(!isset($backup_id_array)||empty($backup_id_array)||!is_array($backup_id_array)) {
137
  $ret['error']='Invalid parameter param: backup_id';
138
  return $ret;
@@ -141,7 +141,7 @@ class WPvivid_Public_Interface
141
  foreach($backup_id_array as $backup_id)
142
  {
143
  $backup_id=sanitize_key($backup_id);
144
- $ret=$wpvivid_pulgin->delete_backup_by_id($backup_id);
145
  }
146
  $backuplist=WPvivid_Backuplist::get_backuplist();
147
  $ret['wpvivid']['backup_list']=$backuplist;
@@ -170,13 +170,13 @@ class WPvivid_Public_Interface
170
  }
171
 
172
  public function view_log($backup_id){
173
- global $wpvivid_pulgin;
174
  if (!isset($backup_id)||empty($backup_id)||!is_string($backup_id)){
175
  $ret['error']='Backup id not found';
176
  return $ret;
177
  }
178
  $backup_id=sanitize_key($backup_id);
179
- $ret=$wpvivid_pulgin->function_realize->_get_log_file('backuplist', $backup_id);
180
  if($ret['result'] == 'success') {
181
  $file = fopen($ret['log_file'], 'r');
182
  if (!$file) {
@@ -198,7 +198,7 @@ class WPvivid_Public_Interface
198
  }
199
 
200
  public function read_last_backup_log($log_file_name){
201
- global $wpvivid_pulgin;
202
  if(!isset($log_file_name)||empty($log_file_name)||!is_string($log_file_name))
203
  {
204
  $ret['result']='failed';
@@ -206,7 +206,7 @@ class WPvivid_Public_Interface
206
  return $ret;
207
  }
208
  $log_file_name=sanitize_text_field($log_file_name);
209
- $ret=$wpvivid_pulgin->function_realize->_get_log_file('lastlog', $log_file_name);
210
  if($ret['result'] == 'success') {
211
  $file = fopen($ret['log_file'], 'r');
212
  if (!$file) {
@@ -229,13 +229,13 @@ class WPvivid_Public_Interface
229
  }
230
 
231
  public function view_backup_task_log($backup_task_id){
232
- global $wpvivid_pulgin;
233
  if (!isset($backup_task_id)||empty($backup_task_id)||!is_string($backup_task_id)){
234
  $ret['error']='Reading the log failed. Please try again.';
235
  return $ret;
236
  }
237
  $backup_task_id = sanitize_key($backup_task_id);
238
- $ret=$wpvivid_pulgin->function_realize->_get_log_file('tasklog', $backup_task_id);
239
  if($ret['result'] == 'success') {
240
  $file = fopen($ret['log_file'], 'r');
241
  if (!$file) {
@@ -258,25 +258,25 @@ class WPvivid_Public_Interface
258
  }
259
 
260
  public function backup_cancel($task_id){
261
- global $wpvivid_pulgin;
262
  if (!isset($task_id)||empty($task_id)||!is_string($task_id)){
263
  $ret['error']='Backup id not found';
264
  return $ret;
265
  }
266
  $task_id=sanitize_key($task_id);
267
- $ret=$wpvivid_pulgin->function_realize->_backup_cancel($task_id);
268
  return $ret;
269
  }
270
 
271
  public function init_download_page($backup_id){
272
- global $wpvivid_pulgin;
273
  if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
274
  $ret['error']='Invalid parameter param:'.$backup_id;
275
  return $ret;
276
  }
277
  else {
278
  $backup_id=sanitize_key($backup_id);
279
- return $wpvivid_pulgin->init_download($backup_id);
280
  }
281
  }
282
 
@@ -326,7 +326,7 @@ class WPvivid_Public_Interface
326
  return $ret;
327
  }
328
  else {
329
- $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
330
  if ($backup === false) {
331
  $ret['result'] = WPVIVID_FAILED;
332
  $ret['error'] = 'backup id not found';
@@ -339,7 +339,7 @@ class WPvivid_Public_Interface
339
  }
340
 
341
  public function download_backup($backup_id, $file_name){
342
- global $wpvivid_pulgin;
343
  if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
344
  $ret['error']='Invalid parameter param: backup_id';
345
  return $ret;
@@ -351,7 +351,7 @@ class WPvivid_Public_Interface
351
  $backup_id=sanitize_key($backup_id);
352
  $cache=WPvivid_taskmanager::get_download_cache($backup_id);
353
  if($cache===false) {
354
- $wpvivid_pulgin->init_download($backup_id);
355
  $cache=WPvivid_taskmanager::get_download_cache($backup_id);
356
  }
357
  $path=false;
@@ -421,7 +421,7 @@ class WPvivid_Public_Interface
421
  }
422
 
423
  public function set_remote($remote){
424
- global $wpvivid_pulgin;
425
  $ret=array();
426
  try {
427
  if(isset($remote)&&!empty($remote)) {
@@ -432,7 +432,7 @@ class WPvivid_Public_Interface
432
  $ret['error']='bad parameter';
433
  return $ret;
434
  }
435
- $wpvivid_pulgin->function_realize->_set_remote($remote);
436
  }
437
  $ret['result']='success';
438
  }
8
  }
9
 
10
  public function prepare_backup($backup_options){
11
+ global $wpvivid_plugin;
12
  if(isset($backup_options)&&!empty($backup_options)){
13
  if (is_null($backup_options)) {
14
  $ret['error']='Invalid parameter param:'.$backup_options;
15
  return $ret;
16
  }
17
+ $ret = $wpvivid_plugin->check_backup_option($backup_options);
18
  if($ret['result']!='success') {
19
  return $ret;
20
  }
21
+ $ret=$wpvivid_plugin->pre_backup($backup_options,'Manual');
22
  if($ret['result']=='success') {
23
  //Check the website data to be backed up
24
+ $ret['check']=$wpvivid_plugin->check_backup($ret['task_id'],$backup_options['backup_files']);
25
  if(isset($ret['check']['result']) && $ret['check']['result'] == 'failed') {
26
  $ret['error']=$ret['check']['error'];
27
  return $ret;
36
  }
37
 
38
  public function backup_now($task_id){
39
+ global $wpvivid_plugin;
40
  if (!isset($task_id)||empty($task_id)||!is_string($task_id))
41
  {
42
  $ret['error']=__('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid');
60
  flush();
61
 
62
  //Start backup site
63
+ $wpvivid_plugin->backup($task_id);
64
  $ret['result']='success';
65
  }
66
 
103
  }
104
 
105
  public function get_default_remote(){
106
+ global $wpvivid_plugin;
107
  $ret['result']='success';
108
+ $ret['remote_storage_type']=$wpvivid_plugin->function_realize->_get_default_remote_storage();
109
  return $ret;
110
  }
111
 
112
  public function delete_backup($backup_id, $force_del){
113
+ global $wpvivid_plugin;
114
  if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
115
  $ret['error']='Invalid parameter param: backup_id.';
116
  return $ret;
125
  $force_del=0;
126
  }
127
  $backup_id=sanitize_key($backup_id);
128
+ $ret=$wpvivid_plugin->delete_backup_by_id($backup_id, $force_del);
129
  $backuplist=WPvivid_Backuplist::get_backuplist();
130
  $ret['wpvivid']['backup_list']=$backuplist;
131
  return $ret;
132
  }
133
 
134
  public function delete_backup_array($backup_id_array){
135
+ global $wpvivid_plugin;
136
  if(!isset($backup_id_array)||empty($backup_id_array)||!is_array($backup_id_array)) {
137
  $ret['error']='Invalid parameter param: backup_id';
138
  return $ret;
141
  foreach($backup_id_array as $backup_id)
142
  {
143
  $backup_id=sanitize_key($backup_id);
144
+ $ret=$wpvivid_plugin->delete_backup_by_id($backup_id);
145
  }
146
  $backuplist=WPvivid_Backuplist::get_backuplist();
147
  $ret['wpvivid']['backup_list']=$backuplist;
170
  }
171
 
172
  public function view_log($backup_id){
173
+ global $wpvivid_plugin;
174
  if (!isset($backup_id)||empty($backup_id)||!is_string($backup_id)){
175
  $ret['error']='Backup id not found';
176
  return $ret;
177
  }
178
  $backup_id=sanitize_key($backup_id);
179
+ $ret=$wpvivid_plugin->function_realize->_get_log_file('backuplist', $backup_id);
180
  if($ret['result'] == 'success') {
181
  $file = fopen($ret['log_file'], 'r');
182
  if (!$file) {
198
  }
199
 
200
  public function read_last_backup_log($log_file_name){
201
+ global $wpvivid_plugin;
202
  if(!isset($log_file_name)||empty($log_file_name)||!is_string($log_file_name))
203
  {
204
  $ret['result']='failed';
206
  return $ret;
207
  }
208
  $log_file_name=sanitize_text_field($log_file_name);
209
+ $ret=$wpvivid_plugin->function_realize->_get_log_file('lastlog', $log_file_name);
210
  if($ret['result'] == 'success') {
211
  $file = fopen($ret['log_file'], 'r');
212
  if (!$file) {
229
  }
230
 
231
  public function view_backup_task_log($backup_task_id){
232
+ global $wpvivid_plugin;
233
  if (!isset($backup_task_id)||empty($backup_task_id)||!is_string($backup_task_id)){
234
  $ret['error']='Reading the log failed. Please try again.';
235
  return $ret;
236
  }
237
  $backup_task_id = sanitize_key($backup_task_id);
238
+ $ret=$wpvivid_plugin->function_realize->_get_log_file('tasklog', $backup_task_id);
239
  if($ret['result'] == 'success') {
240
  $file = fopen($ret['log_file'], 'r');
241
  if (!$file) {
258
  }
259
 
260
  public function backup_cancel($task_id){
261
+ global $wpvivid_plugin;
262
  if (!isset($task_id)||empty($task_id)||!is_string($task_id)){
263
  $ret['error']='Backup id not found';
264
  return $ret;
265
  }
266
  $task_id=sanitize_key($task_id);
267
+ $ret=$wpvivid_plugin->function_realize->_backup_cancel($task_id);
268
  return $ret;
269
  }
270
 
271
  public function init_download_page($backup_id){
272
+ global $wpvivid_plugin;
273
  if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
274
  $ret['error']='Invalid parameter param:'.$backup_id;
275
  return $ret;
276
  }
277
  else {
278
  $backup_id=sanitize_key($backup_id);
279
+ return $wpvivid_plugin->init_download($backup_id);
280
  }
281
  }
282
 
326
  return $ret;
327
  }
328
  else {
329
+ $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
330
  if ($backup === false) {
331
  $ret['result'] = WPVIVID_FAILED;
332
  $ret['error'] = 'backup id not found';
339
  }
340
 
341
  public function download_backup($backup_id, $file_name){
342
+ global $wpvivid_plugin;
343
  if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
344
  $ret['error']='Invalid parameter param: backup_id';
345
  return $ret;
351
  $backup_id=sanitize_key($backup_id);
352
  $cache=WPvivid_taskmanager::get_download_cache($backup_id);
353
  if($cache===false) {
354
+ $wpvivid_plugin->init_download($backup_id);
355
  $cache=WPvivid_taskmanager::get_download_cache($backup_id);
356
  }
357
  $path=false;
421
  }
422
 
423
  public function set_remote($remote){
424
+ global $wpvivid_plugin;
425
  $ret=array();
426
  try {
427
  if(isset($remote)&&!empty($remote)) {
432
  $ret['error']='bad parameter';
433
  return $ret;
434
  }
435
+ $wpvivid_plugin->function_realize->_set_remote($remote);
436
  }
437
  $ret['result']='success';
438
  }
includes/class-wpvivid-restore-data.php CHANGED
@@ -69,7 +69,7 @@ class WPvivid_restore_data
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)
@@ -123,7 +123,7 @@ class WPvivid_restore_data
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);
69
 
70
  public function delete_temp_files()
71
  {
72
+ $backup=WPvivid_Backuplist::get_backup_by_id($this->restore_cache['task_id']);
73
  $backup_item=new WPvivid_Backup_Item($backup);
74
 
75
  foreach($this->restore_cache['restore_tasks'] as $index => $task)
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_backup_by_id($backup_id);
127
  $data['backup_data'] = $backup;
128
 
129
  $backup_item=new WPvivid_Backup_Item($backup);
includes/class-wpvivid-restore-database.php CHANGED
@@ -48,20 +48,20 @@ class WPvivid_RestoreDB
48
  $this->db_method=new WPvivid_Restore_DB_Method();
49
  $this->db_method->set_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
 
@@ -86,9 +86,9 @@ class WPvivid_RestoreDB
86
 
87
  private function execute_sql_file($file,$option)
88
  {
89
- global $wpdb,$wpvivid_pulgin;
90
 
91
- $wpvivid_pulgin->restore_data->write_log('Start import sql file.','notice');
92
 
93
  $this->support_engines=array();
94
  $this->support_charsets=array();
@@ -156,7 +156,7 @@ class WPvivid_RestoreDB
156
  $result = $wpdb->get_results("SHOW COLLATION", OBJECT_K);
157
  foreach ($result as $key=>$value)
158
  {
159
- $this->support_collates[]=$key;
160
  }
161
 
162
  $sql_handle = fopen($file,'r');
@@ -187,27 +187,27 @@ class WPvivid_RestoreDB
187
  if(empty($this -> site_url) && preg_match('# site_url: (.*?) #',$line,$matcher))
188
  {
189
  $this->old_site_url = $matcher[1];
190
- $wpvivid_pulgin->restore_data->write_log('old site url:'.$this->old_site_url,'notice');
191
  }
192
  if(empty($this -> home_url) && preg_match('# home_url: (.*?) #',$line,$matcher))
193
  {
194
  $this->old_home_url = $matcher[1];
195
- $wpvivid_pulgin->restore_data->write_log('old home url:'.$this->old_home_url,'notice');
196
  }
197
  if(empty($this -> content_url) && preg_match('# content_url: (.*?) #',$line,$matcher))
198
  {
199
  $this->old_content_url = $matcher[1];
200
- $wpvivid_pulgin->restore_data->write_log('old content url:'.$this->old_content_url,'notice');
201
  }
202
  if(empty($this -> upload_url) && preg_match('# upload_url: (.*?) #',$line,$matcher))
203
  {
204
  $this->old_upload_url = $matcher[1];
205
- $wpvivid_pulgin->restore_data->write_log('old upload url:'.$this->old_upload_url,'notice');
206
  }
207
  if(empty($this -> table_prefix) && preg_match('# table_prefix: (.*?) #',$line,$matcher))
208
  {
209
  $this->old_prefix = $matcher[1];
210
- $wpvivid_pulgin->restore_data->write_log('old site prefix:'.$this->old_prefix,'notice');
211
  }
212
  }
213
  continue;
@@ -245,7 +245,7 @@ class WPvivid_RestoreDB
245
  {
246
  if ($this->replace_table_execute_sql($query,$current_old_table)===false)
247
  {
248
- $wpvivid_pulgin->restore_data->write_log('Restore ' . basename($file) . ' error at line ' . $line_num . ',' . PHP_EOL . 'errorinfo: [' . implode('][', $this->db_method->errorInfo()) . ']', 'Warning');
249
  $query = '';
250
  continue;
251
  }
@@ -254,7 +254,7 @@ class WPvivid_RestoreDB
254
  {
255
  if ($this->db_method->execute_sql($query)===false)
256
  {
257
- $wpvivid_pulgin->restore_data->write_log('Restore ' . basename($file) . ' error at line ' . $line_num . ',' . PHP_EOL . 'errorinfo: [' . implode('][', $this->db_method->errorInfo()) . ']', 'Warning');
258
  $query = '';
259
  continue;
260
  }
@@ -286,14 +286,14 @@ class WPvivid_RestoreDB
286
 
287
  private function lock_table($query)
288
  {
289
- global $wpvivid_pulgin;
290
  if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
291
  {
292
  if (preg_match('/^\s*LOCK TABLES +\`?([^\`]*)\`?/i', $query, $matches))
293
  {
294
  $table_name = $matches[1];
295
  $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
296
- $wpvivid_pulgin->restore_data->write_log('lock replace table:'.$table_name.' to :'.$new_table_name,'notice');
297
  $query=str_replace($table_name,$new_table_name,$query);
298
  }
299
  }
@@ -302,7 +302,7 @@ class WPvivid_RestoreDB
302
 
303
  private function replace_table_execute_sql($query,$table_name)
304
  {
305
- global $wpvivid_pulgin;
306
  if(!empty($table_name))
307
  {
308
  $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
@@ -314,7 +314,7 @@ class WPvivid_RestoreDB
314
 
315
  private function create_table($query,&$current_old_table)
316
  {
317
- global $wpvivid_pulgin;
318
  $table_name='';
319
  if (preg_match('/^\s*CREATE TABLE +\`?([^\`]*)\`?/i', $query, $matches))
320
  {
@@ -326,12 +326,12 @@ class WPvivid_RestoreDB
326
  {
327
  $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
328
  $query=str_replace($table_name,$new_table_name,$query);
329
- $wpvivid_pulgin->restore_data->write_log('Create table '.$new_table_name,'notice');
330
  $table_name=$new_table_name;
331
  }
332
  else
333
  {
334
- $wpvivid_pulgin->restore_data->write_log('Create table '.$table_name,'notice');
335
  }
336
 
337
  if (preg_match('/ENGINE=([^\s;]+)/', $query, $matches))
@@ -355,11 +355,12 @@ class WPvivid_RestoreDB
355
 
356
  if($replace_engine!==false)
357
  {
358
- $wpvivid_pulgin->restore_data->write_log('create table replace engine:'.$engine.' to :'.$replace_engine,'notice');
359
  $query=str_replace("ENGINE=$engine", "ENGINE=$replace_engine", $query);
360
  }
361
  }
362
 
 
363
  if (preg_match('/CHARSET=([^\s;]+)/', $query, $matches))
364
  {
365
  $charset = $matches[1];
@@ -381,8 +382,9 @@ class WPvivid_RestoreDB
381
 
382
  if($replace_charset!==false)
383
  {
384
- $wpvivid_pulgin->restore_data->write_log('create table replace charset:'.$charset.' to :'.$replace_charset,'notice');
385
  $query=str_replace("CHARSET=$charset", "CHARSET=$replace_charset", $query);
 
386
  }
387
  }
388
 
@@ -390,9 +392,9 @@ class WPvivid_RestoreDB
390
  {
391
  $collate = $matches[1];
392
  $replace_collate=true;
393
- foreach ($this->support_collates as $support_collate)
394
  {
395
- if(strtolower($collate)==strtolower($support_collate))
396
  {
397
  $replace_collate=false;
398
  break;
@@ -401,17 +403,69 @@ class WPvivid_RestoreDB
401
 
402
  if($replace_collate!==false)
403
  {
404
- if(!empty($this->default_collates))
405
- $replace_collate=$this->default_collates[0];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  }
407
 
408
  if($replace_collate!==false)
409
  {
410
- $wpvivid_pulgin->restore_data->write_log('create table replace collate:'.$collate.' to :'.$replace_collate,'notice');
411
  $query=str_replace("COLLATE $collate", "COLLATE $replace_collate", $query);
412
  }
413
  }
 
 
 
 
 
 
 
 
 
 
 
 
414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  $this->execute_sql($query);
416
 
417
  return $table_name;
@@ -419,7 +473,7 @@ class WPvivid_RestoreDB
419
 
420
  private function insert($query)
421
  {
422
- global $wpvivid_pulgin;
423
  if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
424
  {
425
  if (preg_match('/^\s*INSERT INTO +\`?([^\`]*)\`?/i', $query, $matches))
@@ -435,28 +489,28 @@ class WPvivid_RestoreDB
435
 
436
  private function drop_table($query)
437
  {
438
- global $wpvivid_pulgin;
439
  if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
440
  {
441
  if (preg_match('/^\s*DROP TABLE IF EXISTS +\`?([^\`]*)\`?\s*;/i', $query, $matches))
442
  {
443
  $table_name = $matches[1];
444
  $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
445
- $wpvivid_pulgin->restore_data->write_log('drop replace table:'.$table_name.' to :'.$new_table_name,'notice');
446
  $query=str_replace($table_name,$new_table_name,$query);
447
  }
448
  }
449
- $wpvivid_pulgin->restore_data->write_log('Drop table if exist','notice');
450
  $this->execute_sql($query);
451
  }
452
 
453
  private function replace_row($table_name)
454
  {
455
- global $wpdb,$wpvivid_pulgin;
456
 
457
  $this->replacing_table=$table_name;
458
 
459
- $wpvivid_pulgin->restore_data->write_log('Dumping table '.$table_name.' is complete. Start replacing row(s).', 'notice');
460
 
461
  if(substr($table_name, strlen($this->new_prefix))=='options')
462
  {
@@ -466,8 +520,8 @@ class WPvivid_RestoreDB
466
  {
467
  $update_query ='UPDATE '.$table_name.' SET option_name="'.$this->new_prefix.'user_roles" WHERE option_name="'.$this->old_prefix.'user_roles";';
468
 
469
- $wpvivid_pulgin->restore_data->write_log($update_query, 'notice');
470
- $wpvivid_pulgin->restore_data->write_log('update query len:'.strlen($update_query), 'notice');
471
  $this->execute_sql($update_query);
472
  }
473
  }
@@ -478,8 +532,8 @@ class WPvivid_RestoreDB
478
  {
479
  $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).'%";';
480
 
481
- $wpvivid_pulgin->restore_data->write_log($update_query, 'notice');
482
- $wpvivid_pulgin->restore_data->write_log('update query len:'.strlen($update_query), 'notice');
483
  $this->execute_sql($update_query);
484
  return ;
485
  }
@@ -491,7 +545,7 @@ class WPvivid_RestoreDB
491
  $skip_table=false;
492
  if(apply_filters('wpvivid_restore_db_skip_replace_tables',$skip_table,$table_name))
493
  {
494
- $wpvivid_pulgin->restore_data->write_log('Skip table '.$table_name, 'Warning');
495
  return ;
496
  }
497
 
@@ -501,7 +555,7 @@ class WPvivid_RestoreDB
501
  if($result && sizeof($result)>0)
502
  {
503
  $count=$result[0][0];
504
- $wpvivid_pulgin->restore_data->write_log('Count of rows in '.$table_name.': '.$count, 'notice');
505
  if($count==0)
506
  {
507
  return ;
@@ -531,7 +585,7 @@ class WPvivid_RestoreDB
531
  $start_row=0;
532
  for ($current_row = $start_row; $current_row <= $count; $current_row += $page)
533
  {
534
- $wpvivid_pulgin->restore_data->write_log('Replace the row in '.$current_row. ' line.', 'notice');
535
  $end_row=$current_row+$page;
536
  $query = 'SELECT * FROM `'.$table_name.'` LIMIT '.$current_row.', '.$end_row;
537
 
@@ -547,7 +601,7 @@ class WPvivid_RestoreDB
547
  {
548
  if(isset($column['skip']))
549
  {
550
- $wpvivid_pulgin->restore_data->write_log('skip mediumblob type data', 'notice');
551
  continue;
552
  }
553
 
@@ -589,7 +643,7 @@ class WPvivid_RestoreDB
589
  $update_query=$temp_query;
590
  if(strlen($update_query)>$this->db_method->get_max_allow_packet())
591
  {
592
- $wpvivid_pulgin->restore_data->write_log('update replace rows', 'notice');
593
  $this->execute_sql($update_query);
594
 
595
  $update_query='';
@@ -597,7 +651,7 @@ class WPvivid_RestoreDB
597
  }
598
  else if(strlen($temp_query)+strlen($update_query)>$this->db_method->get_max_allow_packet())
599
  {
600
- $wpvivid_pulgin->restore_data->write_log('update replace rows', 'notice');
601
  $this->execute_sql($update_query);
602
 
603
  $update_query='';
@@ -622,12 +676,12 @@ class WPvivid_RestoreDB
622
 
623
  if(!empty($update_query))
624
  {
625
- $wpvivid_pulgin->restore_data->write_log('update replace rows', 'notice');
626
 
627
  $this->execute_sql($update_query);
628
  }
629
  }
630
- $wpvivid_pulgin->restore_data->write_log('finish replace rows', 'notice');
631
  }
632
 
633
  private function replace_row_data($old_data)
@@ -958,6 +1012,8 @@ class WPvivid_RestoreDB
958
  $skip_tables[]='icl_string_pages';
959
  $skip_tables[]='webarx_event_log';
960
  $skip_tables[]='duplicator_packages';
 
 
961
  if(in_array(substr($table_name, strlen($this->new_prefix)),$skip_tables))
962
  {
963
  $skip_table=true;
@@ -992,7 +1048,7 @@ class WPvivid_RestoreDB
992
  private function check_max_allow_packet()
993
  {
994
  //$max_allow_packet
995
- global $wpvivid_pulgin;
996
  $max_allowed_packet = $this->db->query("SELECT @@session.max_allowed_packet;");
997
  if($max_allowed_packet)
998
  {
@@ -1001,23 +1057,23 @@ class WPvivid_RestoreDB
1001
  {
1002
  if($max_allowed_packet[0][0]<1048576)
1003
  {
1004
- $wpvivid_pulgin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet[0][0],2),'notice');
1005
  }
1006
  else if($max_allowed_packet[0][0]<33554432)
1007
  {
1008
- $wpvivid_pulgin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet[0][0],2),'notice');
1009
  }
1010
  $this->max_allow_packet=$max_allowed_packet[0][0];
1011
  }
1012
  else
1013
  {
1014
- $wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed ','notice');
1015
  $this->max_allow_packet=1048576;
1016
  }
1017
  }
1018
  else
1019
  {
1020
- $wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed ','notice');
1021
  $this->max_allow_packet=1048576;
1022
  }
1023
  }
@@ -1048,7 +1104,7 @@ class WPvivid_RestoreDB
1048
 
1049
  private function execute_sql($query)
1050
  {
1051
- $this->db_method->execute_sql($query);
1052
  }
1053
 
1054
  }
48
  $this->db_method=new WPvivid_Restore_DB_Method();
49
  $this->db_method->set_skip_query(0);
50
 
51
+ global $wpvivid_plugin;
52
 
53
  if(file_exists($path.$sql_file))
54
  {
55
  if(!isset($options['skip_backup_old_database']))
56
  {
57
+ $wpvivid_plugin->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_plugin->restore_data->write_log('Backing up current site\'s database failed.error:'.$result['error'],'warning');
65
  }
66
  }
67
 
86
 
87
  private function execute_sql_file($file,$option)
88
  {
89
+ global $wpdb,$wpvivid_plugin;
90
 
91
+ $wpvivid_plugin->restore_data->write_log('Start import sql file.','notice');
92
 
93
  $this->support_engines=array();
94
  $this->support_charsets=array();
156
  $result = $wpdb->get_results("SHOW COLLATION", OBJECT_K);
157
  foreach ($result as $key=>$value)
158
  {
159
+ $this->support_collates[$key]=$value;
160
  }
161
 
162
  $sql_handle = fopen($file,'r');
187
  if(empty($this -> site_url) && preg_match('# site_url: (.*?) #',$line,$matcher))
188
  {
189
  $this->old_site_url = $matcher[1];
190
+ $wpvivid_plugin->restore_data->write_log('old site url:'.$this->old_site_url,'notice');
191
  }
192
  if(empty($this -> home_url) && preg_match('# home_url: (.*?) #',$line,$matcher))
193
  {
194
  $this->old_home_url = $matcher[1];
195
+ $wpvivid_plugin->restore_data->write_log('old home url:'.$this->old_home_url,'notice');
196
  }
197
  if(empty($this -> content_url) && preg_match('# content_url: (.*?) #',$line,$matcher))
198
  {
199
  $this->old_content_url = $matcher[1];
200
+ $wpvivid_plugin->restore_data->write_log('old content url:'.$this->old_content_url,'notice');
201
  }
202
  if(empty($this -> upload_url) && preg_match('# upload_url: (.*?) #',$line,$matcher))
203
  {
204
  $this->old_upload_url = $matcher[1];
205
+ $wpvivid_plugin->restore_data->write_log('old upload url:'.$this->old_upload_url,'notice');
206
  }
207
  if(empty($this -> table_prefix) && preg_match('# table_prefix: (.*?) #',$line,$matcher))
208
  {
209
  $this->old_prefix = $matcher[1];
210
+ $wpvivid_plugin->restore_data->write_log('old site prefix:'.$this->old_prefix,'notice');
211
  }
212
  }
213
  continue;
245
  {
246
  if ($this->replace_table_execute_sql($query,$current_old_table)===false)
247
  {
248
+ $wpvivid_plugin->restore_data->write_log('Restore ' . basename($file) . ' error at line ' . $line_num . ',' . PHP_EOL . 'errorinfo: [' . implode('][', $this->db_method->errorInfo()) . ']', 'Warning');
249
  $query = '';
250
  continue;
251
  }
254
  {
255
  if ($this->db_method->execute_sql($query)===false)
256
  {
257
+ $wpvivid_plugin->restore_data->write_log('Restore ' . basename($file) . ' error at line ' . $line_num . ',' . PHP_EOL . 'errorinfo: [' . implode('][', $this->db_method->errorInfo()) . ']', 'Warning');
258
  $query = '';
259
  continue;
260
  }
286
 
287
  private function lock_table($query)
288
  {
289
+ global $wpvivid_plugin;
290
  if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
291
  {
292
  if (preg_match('/^\s*LOCK TABLES +\`?([^\`]*)\`?/i', $query, $matches))
293
  {
294
  $table_name = $matches[1];
295
  $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
296
+ $wpvivid_plugin->restore_data->write_log('lock replace table:'.$table_name.' to :'.$new_table_name,'notice');
297
  $query=str_replace($table_name,$new_table_name,$query);
298
  }
299
  }
302
 
303
  private function replace_table_execute_sql($query,$table_name)
304
  {
305
+ global $wpvivid_plugin;
306
  if(!empty($table_name))
307
  {
308
  $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
314
 
315
  private function create_table($query,&$current_old_table)
316
  {
317
+ global $wpvivid_plugin;
318
  $table_name='';
319
  if (preg_match('/^\s*CREATE TABLE +\`?([^\`]*)\`?/i', $query, $matches))
320
  {
326
  {
327
  $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
328
  $query=str_replace($table_name,$new_table_name,$query);
329
+ $wpvivid_plugin->restore_data->write_log('Create table '.$new_table_name,'notice');
330
  $table_name=$new_table_name;
331
  }
332
  else
333
  {
334
+ $wpvivid_plugin->restore_data->write_log('Create table '.$table_name,'notice');
335
  }
336
 
337
  if (preg_match('/ENGINE=([^\s;]+)/', $query, $matches))
355
 
356
  if($replace_engine!==false)
357
  {
358
+ $wpvivid_plugin->restore_data->write_log('create table replace engine:'.$engine.' to :'.$replace_engine,'notice');
359
  $query=str_replace("ENGINE=$engine", "ENGINE=$replace_engine", $query);
360
  }
361
  }
362
 
363
+ $charset='';
364
  if (preg_match('/CHARSET=([^\s;]+)/', $query, $matches))
365
  {
366
  $charset = $matches[1];
382
 
383
  if($replace_charset!==false)
384
  {
385
+ $wpvivid_plugin->restore_data->write_log('create table replace charset:'.$charset.' to :'.$replace_charset,'notice');
386
  $query=str_replace("CHARSET=$charset", "CHARSET=$replace_charset", $query);
387
+ $charset=$replace_charset;
388
  }
389
  }
390
 
392
  {
393
  $collate = $matches[1];
394
  $replace_collate=true;
395
+ foreach ($this->support_collates as $key=>$support_collate)
396
  {
397
+ if(strtolower($collate)==strtolower($key))
398
  {
399
  $replace_collate=false;
400
  break;
403
 
404
  if($replace_collate!==false)
405
  {
406
+ if(!empty($charset))
407
+ {
408
+ foreach ($this->support_collates as $key=>$support_collate)
409
+ {
410
+ if(strtolower($charset)==strtolower($support_collate->Charset))
411
+ {
412
+ $replace_collate=$key;
413
+ break;
414
+ }
415
+ }
416
+ }
417
+ else
418
+ {
419
+ if(!empty($this->default_collates))
420
+ $replace_collate=$this->default_collates[0];
421
+ }
422
  }
423
 
424
  if($replace_collate!==false)
425
  {
426
+ $wpvivid_plugin->restore_data->write_log('create table replace collate:'.$collate.' to :'.$replace_collate,'notice');
427
  $query=str_replace("COLLATE $collate", "COLLATE $replace_collate", $query);
428
  }
429
  }
430
+ else if(preg_match('/ COLLATE=([a-zA-Z0-9._-]+)/i', $query, $matches))
431
+ {
432
+ $collate = $matches[1];
433
+ $replace_collate=true;
434
+ foreach ($this->support_collates as $key=>$support_collate)
435
+ {
436
+ if(strtolower($collate)==strtolower($key))
437
+ {
438
+ $replace_collate=false;
439
+ break;
440
+ }
441
+ }
442
 
443
+ if($replace_collate!==false)
444
+ {
445
+ if(!empty($charset))
446
+ {
447
+ foreach ($this->support_collates as $key=>$support_collate)
448
+ {
449
+ if(strtolower($charset)==strtolower($support_collate->Charset))
450
+ {
451
+ $replace_collate=$key;
452
+ break;
453
+ }
454
+ }
455
+ }
456
+ else
457
+ {
458
+ if(!empty($this->default_collates))
459
+ $replace_collate=$this->default_collates[0];
460
+ }
461
+ }
462
+
463
+ if($replace_collate!==false)
464
+ {
465
+ $wpvivid_plugin->restore_data->write_log('create table replace collate:'.$collate.' to :'.$replace_collate,'notice');
466
+ $query=str_replace("COLLATE=$collate", "COLLATE=$replace_collate", $query);
467
+ }
468
+ }
469
  $this->execute_sql($query);
470
 
471
  return $table_name;
473
 
474
  private function insert($query)
475
  {
476
+ global $wpvivid_plugin;
477
  if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
478
  {
479
  if (preg_match('/^\s*INSERT INTO +\`?([^\`]*)\`?/i', $query, $matches))
489
 
490
  private function drop_table($query)
491
  {
492
+ global $wpvivid_plugin;
493
  if(!empty($this->old_prefix)&&$this->old_prefix!=$this->new_prefix)
494
  {
495
  if (preg_match('/^\s*DROP TABLE IF EXISTS +\`?([^\`]*)\`?\s*;/i', $query, $matches))
496
  {
497
  $table_name = $matches[1];
498
  $new_table_name=$this->new_prefix.substr($table_name,strlen($this->old_prefix));
499
+ $wpvivid_plugin->restore_data->write_log('drop replace table:'.$table_name.' to :'.$new_table_name,'notice');
500
  $query=str_replace($table_name,$new_table_name,$query);
501
  }
502
  }
503
+ $wpvivid_plugin->restore_data->write_log('Drop table if exist','notice');
504
  $this->execute_sql($query);
505
  }
506
 
507
  private function replace_row($table_name)
508
  {
509
+ global $wpdb,$wpvivid_plugin;
510
 
511
  $this->replacing_table=$table_name;
512
 
513
+ $wpvivid_plugin->restore_data->write_log('Dumping table '.$table_name.' is complete. Start replacing row(s).', 'notice');
514
 
515
  if(substr($table_name, strlen($this->new_prefix))=='options')
516
  {
520
  {
521
  $update_query ='UPDATE '.$table_name.' SET option_name="'.$this->new_prefix.'user_roles" WHERE option_name="'.$this->old_prefix.'user_roles";';
522
 
523
+ $wpvivid_plugin->restore_data->write_log($update_query, 'notice');
524
+ $wpvivid_plugin->restore_data->write_log('update query len:'.strlen($update_query), 'notice');
525
  $this->execute_sql($update_query);
526
  }
527
  }
532
  {
533
  $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).'%";';
534
 
535
+ $wpvivid_plugin->restore_data->write_log($update_query, 'notice');
536
+ $wpvivid_plugin->restore_data->write_log('update query len:'.strlen($update_query), 'notice');
537
  $this->execute_sql($update_query);
538
  return ;
539
  }
545
  $skip_table=false;
546
  if(apply_filters('wpvivid_restore_db_skip_replace_tables',$skip_table,$table_name))
547
  {
548
+ $wpvivid_plugin->restore_data->write_log('Skip table '.$table_name, 'Warning');
549
  return ;
550
  }
551
 
555
  if($result && sizeof($result)>0)
556
  {
557
  $count=$result[0][0];
558
+ $wpvivid_plugin->restore_data->write_log('Count of rows in '.$table_name.': '.$count, 'notice');
559
  if($count==0)
560
  {
561
  return ;
585
  $start_row=0;
586
  for ($current_row = $start_row; $current_row <= $count; $current_row += $page)
587
  {
588
+ $wpvivid_plugin->restore_data->write_log('Replace the row in '.$current_row. ' line.', 'notice');
589
  $end_row=$current_row+$page;
590
  $query = 'SELECT * FROM `'.$table_name.'` LIMIT '.$current_row.', '.$end_row;
591
 
601
  {
602
  if(isset($column['skip']))
603
  {
604
+ $wpvivid_plugin->restore_data->write_log('skip mediumblob type data', 'notice');
605
  continue;
606
  }
607
 
643
  $update_query=$temp_query;
644
  if(strlen($update_query)>$this->db_method->get_max_allow_packet())
645
  {
646
+ $wpvivid_plugin->restore_data->write_log('update replace rows', 'notice');
647
  $this->execute_sql($update_query);
648
 
649
  $update_query='';
651
  }
652
  else if(strlen($temp_query)+strlen($update_query)>$this->db_method->get_max_allow_packet())
653
  {
654
+ $wpvivid_plugin->restore_data->write_log('update replace rows', 'notice');
655
  $this->execute_sql($update_query);
656
 
657
  $update_query='';
676
 
677
  if(!empty($update_query))
678
  {
679
+ $wpvivid_plugin->restore_data->write_log('update replace rows', 'notice');
680
 
681
  $this->execute_sql($update_query);
682
  }
683
  }
684
+ $wpvivid_plugin->restore_data->write_log('finish replace rows', 'notice');
685
  }
686
 
687
  private function replace_row_data($old_data)
1012
  $skip_tables[]='icl_string_pages';
1013
  $skip_tables[]='webarx_event_log';
1014
  $skip_tables[]='duplicator_packages';
1015
+ $skip_tables[]='wsal_metadata';
1016
+ $skip_tables[]='wsal_occurrences';
1017
  if(in_array(substr($table_name, strlen($this->new_prefix)),$skip_tables))
1018
  {
1019
  $skip_table=true;
1048
  private function check_max_allow_packet()
1049
  {
1050
  //$max_allow_packet
1051
+ global $wpvivid_plugin;
1052
  $max_allowed_packet = $this->db->query("SELECT @@session.max_allowed_packet;");
1053
  if($max_allowed_packet)
1054
  {
1057
  {
1058
  if($max_allowed_packet[0][0]<1048576)
1059
  {
1060
+ $wpvivid_plugin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet[0][0],2),'notice');
1061
  }
1062
  else if($max_allowed_packet[0][0]<33554432)
1063
  {
1064
+ $wpvivid_plugin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet[0][0],2),'notice');
1065
  }
1066
  $this->max_allow_packet=$max_allowed_packet[0][0];
1067
  }
1068
  else
1069
  {
1070
+ $wpvivid_plugin->restore_data->write_log('get max_allowed_packet failed ','notice');
1071
  $this->max_allow_packet=1048576;
1072
  }
1073
  }
1074
  else
1075
  {
1076
+ $wpvivid_plugin->restore_data->write_log('get max_allowed_packet failed ','notice');
1077
  $this->max_allow_packet=1048576;
1078
  }
1079
  }
1104
 
1105
  private function execute_sql($query)
1106
  {
1107
+ return $this->db_method->execute_sql($query);
1108
  }
1109
 
1110
  }
includes/class-wpvivid-restore-db-method.php CHANGED
@@ -16,19 +16,19 @@ class WPvivid_Restore_DB_Method
16
 
17
  public function __construct()
18
  {
19
- global $wpvivid_pulgin;
20
  if(class_exists('PDO'))
21
  {
22
  $extensions=get_loaded_extensions();
23
  if(array_search('pdo_mysql',$extensions))
24
  {
25
- $wpvivid_pulgin->restore_data->write_log('pdo_mysql', 'Warning');
26
  $this->db =new WPvivid_Restore_DB_PDO_Mysql_Method();
27
  $this->type='pdo_mysql';
28
  return;
29
  }
30
  }
31
- $wpvivid_pulgin->restore_data->write_log('wpdb', 'Warning');
32
  $this->db =new WPvivid_Restore_DB_WPDB_Method();
33
  $this->type='wpdb';
34
  }
16
 
17
  public function __construct()
18
  {
19
+ global $wpvivid_plugin;
20
  if(class_exists('PDO'))
21
  {
22
  $extensions=get_loaded_extensions();
23
  if(array_search('pdo_mysql',$extensions))
24
  {
25
+ $wpvivid_plugin->restore_data->write_log('pdo_mysql', 'Warning');
26
  $this->db =new WPvivid_Restore_DB_PDO_Mysql_Method();
27
  $this->type='pdo_mysql';
28
  return;
29
  }
30
  }
31
+ $wpvivid_plugin->restore_data->write_log('wpdb', 'Warning');
32
  $this->db =new WPvivid_Restore_DB_WPDB_Method();
33
  $this->type='wpdb';
34
  }
includes/class-wpvivid-restore-db-pdo-mysql-method.php CHANGED
@@ -58,48 +58,48 @@ class WPvivid_Restore_DB_PDO_Mysql_Method
58
 
59
  public function test_db()
60
  {
61
- global $wpvivid_pulgin;
62
  $test_table_new=uniqid('wpvivid_test_tables_');
63
  $columns='(test_id int)';
64
  $test_table = $this->db->exec("CREATE TABLE IF NOT EXISTS $test_table_new $columns");
65
 
66
  if ($test_table!==false)
67
  {
68
- $wpvivid_pulgin->restore_data->write_log('The test to create table succeeds.','notice');
69
  $test_table = $this->db->exec("INSERT INTO $test_table_new (`test_id`) VALUES ('123')");
70
  if($test_table!==false)
71
  {
72
- $wpvivid_pulgin->restore_data->write_log('The test to insert into table succeeds.','notice');
73
  $test_table = $this->db->exec("DROP TABLE IF EXISTS $test_table_new");
74
  if($test_table!==false)
75
  {
76
- $wpvivid_pulgin->restore_data->write_log('The test to drop table succeeds.','notice');
77
  return true;
78
  }
79
  else
80
  {
81
  $error=$this->db->errorInfo();
82
- $wpvivid_pulgin->restore_data->write_log('Unable to drop table. The reason is '.$error[2],'warning');
83
  return false;
84
  }
85
  }
86
  else
87
  {
88
  $error=$this->db->errorInfo();
89
- $wpvivid_pulgin->restore_data->write_log('Unable to insert into table. The reason is '.$error[2],'warning');
90
  return false;
91
  }
92
  }
93
  else {
94
  $error=$this->db->errorInfo();
95
- $wpvivid_pulgin->restore_data->write_log('Unable to create table. The reason is '.$error[2],'warning');
96
  return false;
97
  }
98
  }
99
 
100
  public function check_max_allow_packet()
101
  {
102
- global $wpvivid_pulgin;
103
 
104
  $max_allowed_packet = $this->db->query("SELECT @@session.max_allowed_packet;");
105
  if($max_allowed_packet)
@@ -110,24 +110,24 @@ class WPvivid_Restore_DB_PDO_Mysql_Method
110
  {
111
  if($max_allowed_packet[0][0]<1048576)
112
  {
113
- $wpvivid_pulgin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet[0][0],2),'notice');
114
  }
115
  else if($max_allowed_packet[0][0]<33554432)
116
  {
117
- $wpvivid_pulgin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet[0][0],2),'notice');
118
  }
119
  $this->max_allow_packet=$max_allowed_packet[0][0];
120
- $wpvivid_pulgin->restore_data->write_log( $this->max_allow_packet,'notice');
121
  }
122
  else
123
  {
124
- $wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed','notice');
125
  $this->max_allow_packet=1048576;
126
  }
127
  }
128
  else
129
  {
130
- $wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed','notice');
131
  $this->max_allow_packet=1048576;
132
  }
133
  }
@@ -153,13 +153,13 @@ class WPvivid_Restore_DB_PDO_Mysql_Method
153
 
154
  public function execute_sql($query)
155
  {
156
- global $wpvivid_pulgin;
157
 
158
  if($this->skip_query>10)
159
  {
160
  if(strlen($query)>$this->max_allow_packet)
161
  {
162
- $wpvivid_pulgin->restore_data->write_log('skip query size:'.size_format(strlen($query)), 'Warning');
163
  return ;
164
  }
165
  }
@@ -167,22 +167,22 @@ class WPvivid_Restore_DB_PDO_Mysql_Method
167
  if ($this->db->exec($query)===false)
168
  {
169
  $info=$this->db->errorInfo();
170
- $wpvivid_pulgin->restore_data->write_log($query.' query: [' . implode('][', $info) . ']', 'Warning');
171
 
172
  if($info[1] == 2006)
173
  {
174
  if(strlen($query)>$this->max_allow_packet)
175
  {
176
  $this->skip_query++;
177
- $wpvivid_pulgin->restore_data->write_log('max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query)), 'Warning');
178
  }
179
  $ret=$this->connect_db();
180
  if($ret['result']==WPVIVID_FAILED)
181
  {
182
- $wpvivid_pulgin->restore_data->write_log('reconnect failed', 'Warning');
183
  }
184
  else{
185
- $wpvivid_pulgin->restore_data->write_log('reconnect succeed', 'Warning');
186
  }
187
  }
188
  }
58
 
59
  public function test_db()
60
  {
61
+ global $wpvivid_plugin;
62
  $test_table_new=uniqid('wpvivid_test_tables_');
63
  $columns='(test_id int)';
64
  $test_table = $this->db->exec("CREATE TABLE IF NOT EXISTS $test_table_new $columns");
65
 
66
  if ($test_table!==false)
67
  {
68
+ $wpvivid_plugin->restore_data->write_log('The test to create table succeeds.','notice');
69
  $test_table = $this->db->exec("INSERT INTO $test_table_new (`test_id`) VALUES ('123')");
70
  if($test_table!==false)
71
  {
72
+ $wpvivid_plugin->restore_data->write_log('The test to insert into table succeeds.','notice');
73
  $test_table = $this->db->exec("DROP TABLE IF EXISTS $test_table_new");
74
  if($test_table!==false)
75
  {
76
+ $wpvivid_plugin->restore_data->write_log('The test to drop table succeeds.','notice');
77
  return true;
78
  }
79
  else
80
  {
81
  $error=$this->db->errorInfo();
82
+ $wpvivid_plugin->restore_data->write_log('Unable to drop table. The reason is '.$error[2],'warning');
83
  return false;
84
  }
85
  }
86
  else
87
  {
88
  $error=$this->db->errorInfo();
89
+ $wpvivid_plugin->restore_data->write_log('Unable to insert into table. The reason is '.$error[2],'warning');
90
  return false;
91
  }
92
  }
93
  else {
94
  $error=$this->db->errorInfo();
95
+ $wpvivid_plugin->restore_data->write_log('Unable to create table. The reason is '.$error[2],'warning');
96
  return false;
97
  }
98
  }
99
 
100
  public function check_max_allow_packet()
101
  {
102
+ global $wpvivid_plugin;
103
 
104
  $max_allowed_packet = $this->db->query("SELECT @@session.max_allowed_packet;");
105
  if($max_allowed_packet)
110
  {
111
  if($max_allowed_packet[0][0]<1048576)
112
  {
113
+ $wpvivid_plugin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet[0][0],2),'notice');
114
  }
115
  else if($max_allowed_packet[0][0]<33554432)
116
  {
117
+ $wpvivid_plugin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet[0][0],2),'notice');
118
  }
119
  $this->max_allow_packet=$max_allowed_packet[0][0];
120
+ $wpvivid_plugin->restore_data->write_log( $this->max_allow_packet,'notice');
121
  }
122
  else
123
  {
124
+ $wpvivid_plugin->restore_data->write_log('get max_allowed_packet failed','notice');
125
  $this->max_allow_packet=1048576;
126
  }
127
  }
128
  else
129
  {
130
+ $wpvivid_plugin->restore_data->write_log('get max_allowed_packet failed','notice');
131
  $this->max_allow_packet=1048576;
132
  }
133
  }
153
 
154
  public function execute_sql($query)
155
  {
156
+ global $wpvivid_plugin;
157
 
158
  if($this->skip_query>10)
159
  {
160
  if(strlen($query)>$this->max_allow_packet)
161
  {
162
+ $wpvivid_plugin->restore_data->write_log('skip query size:'.size_format(strlen($query)), 'Warning');
163
  return ;
164
  }
165
  }
167
  if ($this->db->exec($query)===false)
168
  {
169
  $info=$this->db->errorInfo();
170
+ $wpvivid_plugin->restore_data->write_log($query.' query: [' . implode('][', $info) . ']', 'Warning');
171
 
172
  if($info[1] == 2006)
173
  {
174
  if(strlen($query)>$this->max_allow_packet)
175
  {
176
  $this->skip_query++;
177
+ $wpvivid_plugin->restore_data->write_log('max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query)), 'Warning');
178
  }
179
  $ret=$this->connect_db();
180
  if($ret['result']==WPVIVID_FAILED)
181
  {
182
+ $wpvivid_plugin->restore_data->write_log('reconnect failed', 'Warning');
183
  }
184
  else{
185
+ $wpvivid_plugin->restore_data->write_log('reconnect succeed', 'Warning');
186
  }
187
  }
188
  }
includes/class-wpvivid-restore-db-wpdb-method.php CHANGED
@@ -21,7 +21,7 @@ class WPvivid_Restore_DB_WPDB_Method
21
 
22
  public function test_db()
23
  {
24
- global $wpvivid_pulgin;
25
  global $wpdb;
26
 
27
  $test_table_new=uniqid('wpvivid_test_tables_');
@@ -30,60 +30,60 @@ class WPvivid_Restore_DB_WPDB_Method
30
 
31
  if ($test_table!==false)
32
  {
33
- $wpvivid_pulgin->restore_data->write_log('The test to create table succeeds.','notice');
34
  $test_table = $wpdb->get_results("INSERT INTO $test_table_new (`test_id`) VALUES ('123')",ARRAY_A);
35
  if($test_table!==false)
36
  {
37
- $wpvivid_pulgin->restore_data->write_log('The test to insert into table succeeds.','notice');
38
  $test_table = $wpdb->get_results("DROP TABLE IF EXISTS $test_table_new",ARRAY_A);
39
  if($test_table!==false)
40
  {
41
- $wpvivid_pulgin->restore_data->write_log('The test to drop table succeeds.','notice');
42
  return true;
43
  }
44
  else
45
  {
46
  $error=$wpdb->last_error;
47
- $wpvivid_pulgin->restore_data->write_log('Unable to drop table. The reason is '.$error,'warning');
48
  return false;
49
  }
50
  }
51
  else
52
  {
53
  $error=$wpdb->last_error;
54
- $wpvivid_pulgin->restore_data->write_log('Unable to insert into table. The reason is '.$error,'warning');
55
  return false;
56
  }
57
  }
58
  else {
59
  $error=$wpdb->last_error;
60
- $wpvivid_pulgin->restore_data->write_log('Unable to create table. The reason is '.$error,'warning');
61
  return false;
62
  }
63
  }
64
 
65
  public function check_max_allow_packet()
66
  {
67
- global $wpvivid_pulgin;
68
 
69
- $wpvivid_pulgin->restore_data->write_log('get max_allowed_packet wpdb ','notice');
70
  global $wpdb;
71
  $max_allowed_packet =$wpdb->get_var("SELECT @@session.max_allowed_packet");
72
  if($max_allowed_packet!==null)
73
  {
74
  if($max_allowed_packet<1048576)
75
  {
76
- $wpvivid_pulgin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet,2),'notice');
77
  }
78
  else if($max_allowed_packet<33554432)
79
  {
80
- $wpvivid_pulgin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet,2),'notice');
81
  }
82
  $this->max_allow_packet=$max_allowed_packet;
83
  }
84
  else
85
  {
86
- $wpvivid_pulgin->restore_data->write_log('get max_allowed_packet failed ','notice');
87
  $this->max_allow_packet=1048576;
88
  }
89
  }
@@ -99,8 +99,8 @@ class WPvivid_Restore_DB_WPDB_Method
99
  $res = $wpdb->get_var('SELECT @@SESSION.sql_mode');
100
  if($res===null)
101
  {
102
- global $wpvivid_pulgin;
103
- $wpvivid_pulgin->restore_data->write_log('get sql_mode failed','notice');
104
  }
105
  else
106
  {
@@ -119,14 +119,14 @@ class WPvivid_Restore_DB_WPDB_Method
119
 
120
  public function execute_sql($query)
121
  {
122
- global $wpvivid_pulgin;
123
 
124
  global $wpdb;
125
- //$wpvivid_pulgin->restore_data->write_log('query:'.$query, 'notice');
126
  if ($wpdb->get_results($query)===false)
127
  {
128
  $error=$wpdb->last_error;
129
- $wpvivid_pulgin->restore_data->write_log($error, 'Warning');
130
 
131
  /*
132
  if($info[1] == 2006)
@@ -134,15 +134,15 @@ class WPvivid_Restore_DB_WPDB_Method
134
  if(strlen($query)>$this->max_allow_packet)
135
  {
136
  $this->skip_query++;
137
- $wpvivid_pulgin->restore_data->write_log('max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query)), 'Warning');
138
  }
139
  $ret=$this->connect_db();
140
  if($ret['result']==WPVIVID_FAILED)
141
  {
142
- $wpvivid_pulgin->restore_data->write_log('reconnect failed', 'Warning');
143
  }
144
  else{
145
- $wpvivid_pulgin->restore_data->write_log('reconnect succeed', 'Warning');
146
  }
147
  }
148
  */
21
 
22
  public function test_db()
23
  {
24
+ global $wpvivid_plugin;
25
  global $wpdb;
26
 
27
  $test_table_new=uniqid('wpvivid_test_tables_');
30
 
31
  if ($test_table!==false)
32
  {
33
+ $wpvivid_plugin->restore_data->write_log('The test to create table succeeds.','notice');
34
  $test_table = $wpdb->get_results("INSERT INTO $test_table_new (`test_id`) VALUES ('123')",ARRAY_A);
35
  if($test_table!==false)
36
  {
37
+ $wpvivid_plugin->restore_data->write_log('The test to insert into table succeeds.','notice');
38
  $test_table = $wpdb->get_results("DROP TABLE IF EXISTS $test_table_new",ARRAY_A);
39
  if($test_table!==false)
40
  {
41
+ $wpvivid_plugin->restore_data->write_log('The test to drop table succeeds.','notice');
42
  return true;
43
  }
44
  else
45
  {
46
  $error=$wpdb->last_error;
47
+ $wpvivid_plugin->restore_data->write_log('Unable to drop table. The reason is '.$error,'warning');
48
  return false;
49
  }
50
  }
51
  else
52
  {
53
  $error=$wpdb->last_error;
54
+ $wpvivid_plugin->restore_data->write_log('Unable to insert into table. The reason is '.$error,'warning');
55
  return false;
56
  }
57
  }
58
  else {
59
  $error=$wpdb->last_error;
60
+ $wpvivid_plugin->restore_data->write_log('Unable to create table. The reason is '.$error,'warning');
61
  return false;
62
  }
63
  }
64
 
65
  public function check_max_allow_packet()
66
  {
67
+ global $wpvivid_plugin;
68
 
69
+ $wpvivid_plugin->restore_data->write_log('get max_allowed_packet wpdb ','notice');
70
  global $wpdb;
71
  $max_allowed_packet =$wpdb->get_var("SELECT @@session.max_allowed_packet");
72
  if($max_allowed_packet!==null)
73
  {
74
  if($max_allowed_packet<1048576)
75
  {
76
+ $wpvivid_plugin->restore_data->write_log('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet,2),'notice');
77
  }
78
  else if($max_allowed_packet<33554432)
79
  {
80
+ $wpvivid_plugin->restore_data->write_log('max_allowed_packet less than 32M :'.size_format($max_allowed_packet,2),'notice');
81
  }
82
  $this->max_allow_packet=$max_allowed_packet;
83
  }
84
  else
85
  {
86
+ $wpvivid_plugin->restore_data->write_log('get max_allowed_packet failed ','notice');
87
  $this->max_allow_packet=1048576;
88
  }
89
  }
99
  $res = $wpdb->get_var('SELECT @@SESSION.sql_mode');
100
  if($res===null)
101
  {
102
+ global $wpvivid_plugin;
103
+ $wpvivid_plugin->restore_data->write_log('get sql_mode failed','notice');
104
  }
105
  else
106
  {
119
 
120
  public function execute_sql($query)
121
  {
122
+ global $wpvivid_plugin;
123
 
124
  global $wpdb;
125
+ //$wpvivid_plugin->restore_data->write_log('query:'.$query, 'notice');
126
  if ($wpdb->get_results($query)===false)
127
  {
128
  $error=$wpdb->last_error;
129
+ $wpvivid_plugin->restore_data->write_log($error, 'Warning');
130
 
131
  /*
132
  if($info[1] == 2006)
134
  if(strlen($query)>$this->max_allow_packet)
135
  {
136
  $this->skip_query++;
137
+ $wpvivid_plugin->restore_data->write_log('max_allow_packet too small:'.size_format($this->max_allow_packet).' query size:'.size_format(strlen($query)), 'Warning');
138
  }
139
  $ret=$this->connect_db();
140
  if($ret['result']==WPVIVID_FAILED)
141
  {
142
+ $wpvivid_plugin->restore_data->write_log('reconnect failed', 'Warning');
143
  }
144
  else{
145
+ $wpvivid_plugin->restore_data->write_log('reconnect succeed', 'Warning');
146
  }
147
  }
148
  */
includes/class-wpvivid-restore-site.php CHANGED
@@ -11,7 +11,7 @@ class WPvivid_RestoreSite
11
 
12
  public function restore($option,$files)
13
  {
14
- global $wpvivid_pulgin;
15
 
16
  if(isset($option['has_child']))
17
  {
@@ -21,7 +21,7 @@ class WPvivid_RestoreSite
21
  {
22
  @mkdir($root_path);
23
  }
24
- $wpvivid_pulgin->restore_data->write_log('extract root:'.$root_path,'notice');
25
  $zip = new WPvivid_ZipClass();
26
  $all_files = array();
27
  foreach ($files as $file)
@@ -74,7 +74,7 @@ class WPvivid_RestoreSite
74
 
75
  if(!isset($option['skip_backup_old_site']))
76
  {
77
- $wpvivid_pulgin->restore_data->write_log('backup old file site','notice');
78
  $this->pre_restore($root_path,$old_path,$include_path,$exclude_path);
79
  }
80
 
@@ -86,7 +86,7 @@ class WPvivid_RestoreSite
86
  $all_files[] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$file;
87
  }
88
 
89
- $wpvivid_pulgin->restore_data->write_log('restore from files:'.json_encode($all_files),'notice');
90
 
91
  $ret= $zip->extract($all_files,$root_path);
92
 
11
 
12
  public function restore($option,$files)
13
  {
14
+ global $wpvivid_plugin;
15
 
16
  if(isset($option['has_child']))
17
  {
21
  {
22
  @mkdir($root_path);
23
  }
24
+ $wpvivid_plugin->restore_data->write_log('extract root:'.$root_path,'notice');
25
  $zip = new WPvivid_ZipClass();
26
  $all_files = array();
27
  foreach ($files as $file)
74
 
75
  if(!isset($option['skip_backup_old_site']))
76
  {
77
+ $wpvivid_plugin->restore_data->write_log('backup old file site','notice');
78
  $this->pre_restore($root_path,$old_path,$include_path,$exclude_path);
79
  }
80
 
86
  $all_files[] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.$file;
87
  }
88
 
89
+ $wpvivid_plugin->restore_data->write_log('restore from files:'.json_encode($all_files),'notice');
90
 
91
  $ret= $zip->extract($all_files,$root_path);
92
 
includes/class-wpvivid-restore.php CHANGED
@@ -15,35 +15,35 @@ class WPvivid_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
  $result = $this -> execute_restore($next_task);
37
- $wpvivid_pulgin->restore_data->update_sub_task($next_task['index'],$result);
38
 
39
  if($result['result'] != WPVIVID_SUCCESS)
40
  {
41
- $wpvivid_pulgin->restore_data->update_error($result['error']);
42
- $wpvivid_pulgin->restore_data->write_log($result['error'],'error');
43
  return array('result'=>WPVIVID_FAILED,'error'=>$result['error']);
44
  }
45
  else {
46
- $wpvivid_pulgin->restore_data->update_status(WPVIVID_RESTORE_WAIT);
47
  return array('result'=> WPVIVID_SUCCESS);
48
  }
49
  }
@@ -51,9 +51,9 @@ class WPvivid_Restore
51
 
52
  function execute_restore($restore_task)
53
  {
54
- global $wpvivid_pulgin;
55
 
56
- $backup=$wpvivid_pulgin->restore_data->get_backup_data();
57
  $backup_item=new WPvivid_Backup_Item($backup);
58
  $json=$backup_item->get_file_info($restore_task['files'][0]);
59
  $option=array();
@@ -66,17 +66,17 @@ class WPvivid_Restore
66
  if(isset($option['dump_db']))
67
  {
68
  $restore_site = new WPvivid_RestoreSite();
69
- $wpvivid_pulgin->restore_data->write_log('Start restoring '.$restore_task['files'][0],'notice');
70
  $ret= $restore_site -> restore($option,$restore_task['files']);
71
  if($ret['result']==WPVIVID_SUCCESS)
72
  {
73
  $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR;
74
  $sql_file = $backup_item->get_sql_file($restore_task['files'][0]);
75
- $wpvivid_pulgin->restore_data->write_log('sql file: '.$sql_file,'notice');
76
  $restore_db=new WPvivid_RestoreDB();
77
  $restore_db->restore($path,$sql_file,$option);
78
- $wpvivid_pulgin->restore_data->write_log('Finished restoring '.$restore_task['files'][0],'notice');
79
- $wpvivid_pulgin->restore_data->update_need_unzip_file($restore_task['index'],$restore_task['files']);
80
  return array('result'=>WPVIVID_SUCCESS);
81
  }
82
  else
@@ -88,11 +88,11 @@ class WPvivid_Restore
88
  {
89
  $restore_site = new WPvivid_RestoreSite();
90
 
91
- $files=$wpvivid_pulgin->restore_data->get_need_unzip_file($restore_task);
92
- $wpvivid_pulgin->restore_data->write_log('Start restoring '.$files[0],'notice');
93
  $ret= $restore_site -> restore($option,$files);
94
- $wpvivid_pulgin->restore_data->update_need_unzip_file($restore_task['index'],$files);
95
- $wpvivid_pulgin->restore_data->write_log('Finished restoring '.$files[0],'notice');
96
  return $ret;
97
  }
98
  }
15
  {
16
  @set_time_limit(1800);
17
 
18
+ global $wpvivid_plugin;
19
 
20
+ $next_task=$wpvivid_plugin->restore_data->get_next_restore_task();
21
 
22
  if($next_task===false)
23
  {
24
+ $wpvivid_plugin->restore_data->write_log('Restore task completed.','notice');
25
+ $wpvivid_plugin->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_plugin->restore_data->update_error('A restore task is already running.');
31
+ $wpvivid_plugin->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
  $result = $this -> execute_restore($next_task);
37
+ $wpvivid_plugin->restore_data->update_sub_task($next_task['index'],$result);
38
 
39
  if($result['result'] != WPVIVID_SUCCESS)
40
  {
41
+ $wpvivid_plugin->restore_data->update_error($result['error']);
42
+ $wpvivid_plugin->restore_data->write_log($result['error'],'error');
43
  return array('result'=>WPVIVID_FAILED,'error'=>$result['error']);
44
  }
45
  else {
46
+ $wpvivid_plugin->restore_data->update_status(WPVIVID_RESTORE_WAIT);
47
  return array('result'=> WPVIVID_SUCCESS);
48
  }
49
  }
51
 
52
  function execute_restore($restore_task)
53
  {
54
+ global $wpvivid_plugin;
55
 
56
+ $backup=$wpvivid_plugin->restore_data->get_backup_data();
57
  $backup_item=new WPvivid_Backup_Item($backup);
58
  $json=$backup_item->get_file_info($restore_task['files'][0]);
59
  $option=array();
66
  if(isset($option['dump_db']))
67
  {
68
  $restore_site = new WPvivid_RestoreSite();
69
+ $wpvivid_plugin->restore_data->write_log('Start restoring '.$restore_task['files'][0],'notice');
70
  $ret= $restore_site -> restore($option,$restore_task['files']);
71
  if($ret['result']==WPVIVID_SUCCESS)
72
  {
73
  $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_DEFAULT_ROLLBACK_DIR.DIRECTORY_SEPARATOR.'wpvivid_old_database'.DIRECTORY_SEPARATOR;
74
  $sql_file = $backup_item->get_sql_file($restore_task['files'][0]);
75
+ $wpvivid_plugin->restore_data->write_log('sql file: '.$sql_file,'notice');
76
  $restore_db=new WPvivid_RestoreDB();
77
  $restore_db->restore($path,$sql_file,$option);
78
+ $wpvivid_plugin->restore_data->write_log('Finished restoring '.$restore_task['files'][0],'notice');
79
+ $wpvivid_plugin->restore_data->update_need_unzip_file($restore_task['index'],$restore_task['files']);
80
  return array('result'=>WPVIVID_SUCCESS);
81
  }
82
  else
88
  {
89
  $restore_site = new WPvivid_RestoreSite();
90
 
91
+ $files=$wpvivid_plugin->restore_data->get_need_unzip_file($restore_task);
92
+ $wpvivid_plugin->restore_data->write_log('Start restoring '.$files[0],'notice');
93
  $ret= $restore_site -> restore($option,$files);
94
+ $wpvivid_plugin->restore_data->update_need_unzip_file($restore_task['index'],$files);
95
+ $wpvivid_plugin->restore_data->write_log('Finished restoring '.$files[0],'notice');
96
  return $ret;
97
  }
98
  }
includes/class-wpvivid-setting.php CHANGED
@@ -452,8 +452,8 @@ class WPvivid_Setting
452
 
453
  public static function export_setting_to_json($setting=true,$history=true,$review=true)
454
  {
455
- global $wpvivid_pulgin;
456
- $json['plugin']=$wpvivid_pulgin->get_plugin_name();
457
  $json['version']=WPVIVID_PLUGIN_VERSION;
458
  $json['setting']=$setting;
459
  $json['history']=$history;
@@ -552,7 +552,12 @@ class WPvivid_Setting
552
  $options=self::get_option('wpvivid_common_setting');
553
  if(isset($options['show_admin_bar']))
554
  {
555
- return $options['show_admin_bar'];
 
 
 
 
 
556
  }
557
  else
558
  {
452
 
453
  public static function export_setting_to_json($setting=true,$history=true,$review=true)
454
  {
455
+ global $wpvivid_plugin;
456
+ $json['plugin']=$wpvivid_plugin->get_plugin_name();
457
  $json['version']=WPVIVID_PLUGIN_VERSION;
458
  $json['setting']=$setting;
459
  $json['history']=$history;
552
  $options=self::get_option('wpvivid_common_setting');
553
  if(isset($options['show_admin_bar']))
554
  {
555
+ if($options['show_admin_bar']){
556
+ return true;
557
+ }
558
+ else{
559
+ return false;
560
+ }
561
  }
562
  else
563
  {
includes/class-wpvivid-tools.php CHANGED
@@ -173,15 +173,15 @@ class WPvivid_tools
173
  file_put_contents($file,json_encode($json));
174
  }
175
  public static function file_get_array($file){
176
- global $wpvivid_pulgin;
177
  if(file_exists($file)){
178
  $get_file_ret = json_decode(file_get_contents($file),true);
179
  if(empty($get_file_ret)){
180
- $wpvivid_pulgin->restore_data->write_log('Failed to decode restore data file.', 'notice');
181
  }
182
  return $get_file_ret;
183
  }else{
184
- $wpvivid_pulgin->restore_data->write_log('Failed to open restore data file, the file may not exist.', 'notice');
185
  return array();
186
  }
187
  }
173
  file_put_contents($file,json_encode($json));
174
  }
175
  public static function file_get_array($file){
176
+ global $wpvivid_plugin;
177
  if(file_exists($file)){
178
  $get_file_ret = json_decode(file_get_contents($file),true);
179
  if(empty($get_file_ret)){
180
+ $wpvivid_plugin->restore_data->write_log('Failed to decode restore data file.', 'notice');
181
  }
182
  return $get_file_ret;
183
  }else{
184
+ $wpvivid_plugin->restore_data->write_log('Failed to open restore data file, the file may not exist.', 'notice');
185
  return array();
186
  }
187
  }
includes/class-wpvivid-upload.php CHANGED
@@ -9,12 +9,12 @@ class WPvivid_Upload
9
  {
10
  public $task_id;
11
 
12
- public function upload($task_id,$backup,$remote_option=null)
13
  {
14
- global $wpvivid_pulgin;
15
  $this->task_id=$task_id;
16
- $files=$this->get_backup_files($backup);
17
-
18
  WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'upload',0,0);
19
 
20
  if(is_null($remote_option))
@@ -47,7 +47,7 @@ class WPvivid_Upload
47
  return array('result' => WPVIVID_FAILED , 'error' => 'not select remote storage');
48
  }
49
 
50
- $remote=$wpvivid_pulgin->remote_collection->get_remote($remote_option);
51
 
52
  $result=$remote->upload($this->task_id,$files,array($this,'upload_callback'));
53
 
@@ -68,7 +68,7 @@ class WPvivid_Upload
68
  }
69
  else
70
  {
71
- $remote=$wpvivid_pulgin->remote_collection->get_remote($remote_option);
72
 
73
  $result=$remote->upload($this->task_id,$files,array($this,'upload_callback'));
74
 
@@ -102,11 +102,11 @@ class WPvivid_Upload
102
  $v /= 1000;
103
  $v=round($v,2);
104
 
105
- global $wpvivid_pulgin;
106
- $wpvivid_pulgin->check_cancel_backup($this->task_id);
107
 
108
  $message='Uploading '.$current_name.' Total size: '.size_format($current_size,2).' Uploaded: '.size_format($offset,2).' speed:'.$v.'kb/s';
109
- $wpvivid_pulgin->wpvivid_log->WriteLog($message,'notice');
110
  $progress=intval(($offset/$current_size)*100);
111
  WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'upload',$progress,0);
112
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'upload','',WPVIVID_UPLOAD_UNDO,$message, $job_data, $upload_data);
@@ -125,9 +125,9 @@ class WPvivid_Upload
125
 
126
  if(!is_null($remote_option))
127
  {
128
- global $wpvivid_pulgin;
129
 
130
- $remote=$wpvivid_pulgin->remote_collection->get_remote($remote_option);
131
  $remote ->cleanup($files);
132
  }
133
  }
9
  {
10
  public $task_id;
11
 
12
+ public function upload($task_id,$remote_option=null)
13
  {
14
+ global $wpvivid_plugin;
15
  $this->task_id=$task_id;
16
+ $task=new WPvivid_Backup_Task($task_id);
17
+ $files=$task->get_backup_files();
18
  WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'upload',0,0);
19
 
20
  if(is_null($remote_option))
47
  return array('result' => WPVIVID_FAILED , 'error' => 'not select remote storage');
48
  }
49
 
50
+ $remote=$wpvivid_plugin->remote_collection->get_remote($remote_option);
51
 
52
  $result=$remote->upload($this->task_id,$files,array($this,'upload_callback'));
53
 
68
  }
69
  else
70
  {
71
+ $remote=$wpvivid_plugin->remote_collection->get_remote($remote_option);
72
 
73
  $result=$remote->upload($this->task_id,$files,array($this,'upload_callback'));
74
 
102
  $v /= 1000;
103
  $v=round($v,2);
104
 
105
+ global $wpvivid_plugin;
106
+ $wpvivid_plugin->check_cancel_backup($this->task_id);
107
 
108
  $message='Uploading '.$current_name.' Total size: '.size_format($current_size,2).' Uploaded: '.size_format($offset,2).' speed:'.$v.'kb/s';
109
+ $wpvivid_plugin->wpvivid_log->WriteLog($message,'notice');
110
  $progress=intval(($offset/$current_size)*100);
111
  WPvivid_taskmanager::update_backup_main_task_progress($this->task_id,'upload',$progress,0);
112
  WPvivid_taskmanager::update_backup_sub_task_progress($this->task_id,'upload','',WPVIVID_UPLOAD_UNDO,$message, $job_data, $upload_data);
125
 
126
  if(!is_null($remote_option))
127
  {
128
+ global $wpvivid_plugin;
129
 
130
+ $remote=$wpvivid_plugin->remote_collection->get_remote($remote_option);
131
  $remote ->cleanup($files);
132
  }
133
  }
includes/class-wpvivid-zipclass.php CHANGED
@@ -191,8 +191,8 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
191
  {
192
  if(!function_exists('get_home_path'))
193
  require_once(ABSPATH . 'wp-admin/includes/file.php');
194
- global $wpvivid_pulgin;
195
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
196
  $files = $this -> filesplit($data['compress']['max_file_size'],$data['files']);
197
 
198
  $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR;
@@ -258,32 +258,32 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
258
  continue;
259
  }
260
  }
261
- $wpvivid_pulgin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
262
  return $ret;
263
  }
264
 
265
  public function extract($files,$path = '')
266
  {
267
- global $wpvivid_pulgin;
268
- //$wpvivid_pulgin->restore_data->write_log('start prepare extract','notice');
269
  define(PCLZIP_TEMPORARY_DIR,dirname($path));
270
 
271
  $ret['result']=WPVIVID_SUCCESS;
272
  foreach ($files as $file)
273
  {
274
- $wpvivid_pulgin->restore_data->write_log('start extract file:'.$file,'notice');
275
  $archive = new PclZip($file);
276
  $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);
277
  if(!$zip_ret)
278
  {
279
  $ret['result']=WPVIVID_FAILED;
280
  $ret['error'] = $archive->errorInfo(true);
281
- $wpvivid_pulgin->restore_data->write_log('extract finished:'.json_encode($ret),'notice');
282
  break;
283
  }
284
  else
285
  {
286
- $wpvivid_pulgin->restore_data->write_log('extract finished file:'.$file,'notice');
287
  }
288
  }
289
  //$this->restore_data->write_log('extract finished files:'.json_encode($all_files),'notice');
@@ -354,7 +354,7 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
354
 
355
  public function _zip($name,$files,$options,$json_info=false)
356
  {
357
- global $wpvivid_pulgin;
358
 
359
  if(file_exists($name))
360
  @unlink($name);
@@ -408,7 +408,7 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
408
  @unlink($temp_path);
409
  }
410
 
411
- $wpvivid_pulgin->wpvivid_log->WriteLog('Prepare to zip files. file: '.basename($name),'notice');
412
 
413
  if($no_compress)
414
  {
@@ -449,11 +449,29 @@ class WPvivid_ZipClass extends Wpvivid_Compress_Default
449
 
450
  if(!$ret)
451
  {
452
- $wpvivid_pulgin->wpvivid_log->WriteLog('Failed to add zip files, error: '.$archive->errorInfo(true),'notice');
 
 
453
  return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true));
454
  }
455
 
456
- $wpvivid_pulgin->wpvivid_log->WriteLog('Adding zip files completed.'.basename($name).', filesize: '.size_format(filesize($name),2),'notice');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  $file_data = array();
458
  $file_data['file_name'] = basename($name);
459
  $file_data['size'] = filesize($name);
@@ -657,9 +675,9 @@ function wpvivid_function_per_add_callback($p_event, &$p_header)
657
  if(time()-$wpvivid_old_time>30)
658
  {
659
  $wpvivid_old_time=time();
660
- global $wpvivid_pulgin;
661
- $wpvivid_pulgin->check_cancel_backup($wpvivid_pulgin->current_task['id']);
662
- WPvivid_taskmanager::update_backup_task_status($wpvivid_pulgin->current_task['id']);
663
  }
664
 
665
  return 1;
191
  {
192
  if(!function_exists('get_home_path'))
193
  require_once(ABSPATH . 'wp-admin/includes/file.php');
194
+ global $wpvivid_plugin;
195
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
196
  $files = $this -> filesplit($data['compress']['max_file_size'],$data['files']);
197
 
198
  $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR;
258
  continue;
259
  }
260
  }
261
+ $wpvivid_plugin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
262
  return $ret;
263
  }
264
 
265
  public function extract($files,$path = '')
266
  {
267
+ global $wpvivid_plugin;
268
+ //$wpvivid_plugin->restore_data->write_log('start prepare extract','notice');
269
  define(PCLZIP_TEMPORARY_DIR,dirname($path));
270
 
271
  $ret['result']=WPVIVID_SUCCESS;
272
  foreach ($files as $file)
273
  {
274
+ $wpvivid_plugin->restore_data->write_log('start extract file:'.$file,'notice');
275
  $archive = new PclZip($file);
276
  $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);
277
  if(!$zip_ret)
278
  {
279
  $ret['result']=WPVIVID_FAILED;
280
  $ret['error'] = $archive->errorInfo(true);
281
+ $wpvivid_plugin->restore_data->write_log('extract finished:'.json_encode($ret),'notice');
282
  break;
283
  }
284
  else
285
  {
286
+ $wpvivid_plugin->restore_data->write_log('extract finished file:'.$file,'notice');
287
  }
288
  }
289
  //$this->restore_data->write_log('extract finished files:'.json_encode($all_files),'notice');
354
 
355
  public function _zip($name,$files,$options,$json_info=false)
356
  {
357
+ global $wpvivid_plugin;
358
 
359
  if(file_exists($name))
360
  @unlink($name);
408
  @unlink($temp_path);
409
  }
410
 
411
+ $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to zip files. file: '.basename($name),'notice');
412
 
413
  if($no_compress)
414
  {
449
 
450
  if(!$ret)
451
  {
452
+ $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: '.$archive->errorInfo(true),'notice');
453
+ $size=size_format(disk_free_space(dirname($name)),2);
454
+ $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice');
455
  return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true));
456
  }
457
 
458
+ $size=filesize($name);
459
+ if($size===false)
460
+ {
461
+ $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: file not found after backup success','error');
462
+ $size=size_format(disk_free_space(dirname($name)),2);
463
+ $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice');
464
+ return array('result'=>WPVIVID_FAILED,'error'=>'The file compression failed while backing up becuase of '.$name.' file not found. Please try again. The available disk space: '.$size.'.');
465
+ }
466
+ else if($size==0)
467
+ {
468
+ $wpvivid_plugin->wpvivid_log->WriteLog('Failed to add zip files, error: file size 0B after backup success','error');
469
+ $size=size_format(disk_free_space(dirname($name)),2);
470
+ $wpvivid_plugin->wpvivid_log->WriteLog('disk_free_space : '.$size,'notice');
471
+ return array('result'=>WPVIVID_FAILED,'error'=>'The file compression failed while backing up. The size of '.$name.' file is 0. Please make sure there is an enough disk space to backup. Then try again. The available disk space: '.$size.'.');
472
+ }
473
+
474
+ $wpvivid_plugin->wpvivid_log->WriteLog('Adding zip files completed.'.basename($name).', filesize: '.size_format(filesize($name),2),'notice');
475
  $file_data = array();
476
  $file_data['file_name'] = basename($name);
477
  $file_data['size'] = filesize($name);
675
  if(time()-$wpvivid_old_time>30)
676
  {
677
  $wpvivid_old_time=time();
678
+ global $wpvivid_plugin;
679
+ $wpvivid_plugin->check_cancel_backup($wpvivid_plugin->current_task['id']);
680
+ WPvivid_taskmanager::update_backup_task_status($wpvivid_plugin->current_task['id']);
681
  }
682
 
683
  return 1;
includes/class-wpvivid.php CHANGED
@@ -95,7 +95,7 @@ class WPvivid {
95
 
96
  add_filter('pre_update_option',array( $this,'wpjam_pre_update_option_cache'),10,2);
97
 
98
- add_filter('wpvivid_add_backup_list', array( $this, 'wpvivid_add_backup_list' ), 10, 2);
99
  add_filter('wpvivid_add_remote_storage_list', array( $this, 'wpvivid_add_remote_storage_list' ), 10);
100
  add_filter('wpvivid_schedule_add_remote_pic', array( $this, 'wpvivid_schedule_add_remote_pic' ), 10);
101
  add_filter('wpvivid_get_remote_directory', array( $this, 'wpvivid_get_remote_directory' ), 10);
@@ -119,6 +119,8 @@ class WPvivid {
119
  add_action('wpvivid_handle_backup_failed',array($this,'wpvivid_mark_task'),20);
120
  add_action('init', array($this, 'init_pclzip_tmp_folder'));
121
 
 
 
122
  //Initialisation schedule hook
123
  $this->init_cron();
124
  //Initialisation log object
@@ -195,13 +197,20 @@ class WPvivid {
195
  $plugin_admin = new WPvivid_Admin($this->get_plugin_name(), $this->get_version());
196
 
197
  add_action('admin_enqueue_scripts',array( $plugin_admin,'enqueue_styles'));
198
-
199
  add_action('admin_enqueue_scripts',array( $plugin_admin,'enqueue_scripts'));
200
-
201
  // Add menu item
202
- add_action('admin_menu',array( $plugin_admin,'add_plugin_admin_menu'));
203
- //show admin bar
 
 
 
 
 
 
 
 
204
  add_action('admin_bar_menu',array( $plugin_admin,'add_toolbar_items'),100);
 
205
  add_action('admin_head',array( $plugin_admin,'wpvivid_get_siteurl'),100);
206
 
207
  // Add Settings link to the plugin
@@ -372,7 +381,15 @@ class WPvivid {
372
  die();
373
  }
374
 
375
- $ret = $this->check_backup_option($backup_options, 'Manual');
 
 
 
 
 
 
 
 
376
  if($ret['result']!=WPVIVID_SUCCESS)
377
  {
378
  $this->end_shutdown_function=true;
@@ -380,7 +397,7 @@ class WPvivid {
380
  die();
381
  }
382
 
383
- $ret=$this->pre_backup($backup_options,'Manual');
384
  if($ret['result']=='success')
385
  {
386
  //Check the website data to be backed up
@@ -570,18 +587,22 @@ class WPvivid {
570
  public function view_backup_log()
571
  {
572
  $this->ajax_check_security();
573
- try {
574
- if (isset($_POST['id']) && !empty($_POST['id']) && is_string($_POST['id'])) {
 
 
575
  $backup_id = sanitize_key($_POST['id']);
576
- $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
577
- if (!$backup) {
 
578
  $json['result'] = 'failed';
579
  $json['error'] = __('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
580
  echo json_encode($json);
581
  die();
582
  }
583
 
584
- if (!file_exists($backup['log'])) {
 
585
  $json['result'] = 'failed';
586
  $json['error'] = __('The log not found.', 'wpvivid');
587
  echo json_encode($json);
@@ -590,7 +611,8 @@ class WPvivid {
590
 
591
  $file = fopen($backup['log'], 'r');
592
 
593
- if (!$file) {
 
594
  $json['result'] = 'failed';
595
  $json['error'] = __('Unable to open the log file.', 'wpvivid');
596
  echo json_encode($json);
@@ -598,7 +620,8 @@ class WPvivid {
598
  }
599
 
600
  $buffer = '';
601
- while (!feof($file)) {
 
602
  $buffer .= fread($file, 1024);
603
  }
604
  fclose($file);
@@ -612,7 +635,8 @@ class WPvivid {
612
  echo json_encode($json);
613
  }
614
  }
615
- catch (Exception $error) {
 
616
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
617
  error_log($message);
618
  echo json_encode(array('result'=>'failed','error'=>$message));
@@ -778,7 +802,13 @@ class WPvivid {
778
  echo json_encode($ret);
779
  die();
780
  }
781
- file_put_contents('F:\wamp64_3.19\www\wordpress\test_premium\wp-content\wpvividbackups\test.txt','test2');
 
 
 
 
 
 
782
  $ret = $this->pre_backup($schedule_options['backup'], 'Cron');
783
  if ($ret['result'] == 'success') {
784
  //Check the website data to be backed up.
@@ -795,7 +825,6 @@ class WPvivid {
795
  $ret['result']='failed';
796
  $message = 'An exception has occurred. class:'.get_class($error).';msg:'.$error->getMessage().';code:'.$error->getCode().';line:'.$error->getLine().';in_file:'.$error->getFile().';';
797
  $ret['error'] = $message;
798
- file_put_contents('F:\wamp64_3.19\www\wordpress\test_premium\wp-content\wpvividbackups\test.txt',$message);
799
  $id=uniqid('wpvivid-');
800
  $log_file_name=$id.'_backup';
801
  $log=new WPvivid_Log();
@@ -965,7 +994,7 @@ class WPvivid {
965
  *
966
  * @since 0.9.1
967
  */
968
- public function pre_backup($backup_options,$type)
969
  {
970
  $this->clean_oldest_backup();
971
 
@@ -977,7 +1006,7 @@ class WPvivid {
977
  }
978
 
979
  $backup=new WPvivid_Backup_Task();
980
- $ret=$backup->new_backup_task($backup_options,$type);
981
  return $ret;
982
  }
983
 
@@ -1029,7 +1058,7 @@ class WPvivid {
1029
  $this->wpvivid_log->WriteLog('Backup completed.','notice');
1030
  }
1031
 
1032
- if(!$this->finish_backup_task($task_id,$backup_ret))
1033
  {
1034
  $this->end_shutdown_function=true;
1035
  die();
@@ -1071,13 +1100,12 @@ class WPvivid {
1071
  *
1072
  * @since 0.9.1
1073
  */
1074
- private function finish_backup_task($task_id,$backup_ret)
1075
  {
1076
  $status=WPvivid_taskmanager::get_backup_task_status($task_id);
1077
  if($status['str']=='running')
1078
  {
1079
  $this->wpvivid_log->WriteLog('Backup succeeded.','notice');
1080
- WPvivid_Backuplist::add_new_backup($task_id,$backup_ret);
1081
 
1082
  $remote_options=WPvivid_taskmanager::get_task_options($task_id,'remote_options');
1083
  if($remote_options===false)
@@ -1085,10 +1113,6 @@ class WPvivid {
1085
  $task=WPvivid_taskmanager::update_backup_task_status($task_id,false,'completed');
1086
  do_action('wpvivid_handle_backup_succeed',$task);
1087
  }
1088
- else
1089
- {
1090
- WPvivid_taskmanager::update_task_options($task_id,'backup',WPvivid_Backuplist::get_backuplist_by_key($task_id));
1091
- }
1092
  return true;
1093
  }
1094
  else
@@ -1146,8 +1170,7 @@ class WPvivid {
1146
  $this->set_time_limit($task_id);
1147
 
1148
  $upload=new WPvivid_Upload();
1149
- $backup=WPvivid_taskmanager::get_task_options($task_id,'backup');
1150
- $ret=$upload->upload($task_id,$backup);
1151
  if($ret['result'] == WPVIVID_SUCCESS)
1152
  {
1153
  $task=WPvivid_taskmanager::update_backup_task_status($task_id,false,'completed');
@@ -1155,9 +1178,13 @@ class WPvivid {
1155
  }
1156
  else
1157
  {
1158
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
1159
- $list[$task_id]['save_local']=1;
1160
- WPvivid_Setting::update_option('wpvivid_backup_list',$list);
 
 
 
 
1161
  $this->wpvivid_log->WriteLog('Uploading the file ends with an error '. $ret['error'], 'error');
1162
  $task=WPvivid_taskmanager::get_task($task_id);
1163
  do_action('wpvivid_handle_backup_failed',$task, false);
@@ -1185,6 +1212,14 @@ class WPvivid {
1185
  {
1186
  if($task['action'] === 'backup')
1187
  {
 
 
 
 
 
 
 
 
1188
  $backup_success_count = WPvivid_Setting::get_option('wpvivid_backup_success_count');
1189
  if (empty($backup_success_count))
1190
  {
@@ -1216,8 +1251,7 @@ class WPvivid {
1216
  {
1217
  $backup_error_array['bu_error']['task_id'] = $task['id'];
1218
  $backup_error_array['bu_error']['error_msg'] = 'Unknown error.';
1219
- //$backup_error_array['bu_error']['error_msg'] = $task['status']['error'];
1220
- //
1221
  $general_setting=WPvivid_Setting::get_setting(true, "");
1222
  $need_notice = false;
1223
  if(!isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
@@ -1253,7 +1287,6 @@ class WPvivid {
1253
  $backup_error_array['bu_error']['error_msg'] = __('<div class="notice notice-error inline"><p>' . $notice_msg . ', Please switch to <a href="#" onclick="wpvivid_click_switch_page(\'wrap\', \'wpvivid_tab_debug\', true);">Website Info</a> page to send us the debug information. </p></div>');
1254
  }
1255
  }
1256
- //
1257
  WPvivid_Setting::update_option('wpvivid_backup_error_array', $backup_error_array);
1258
  }
1259
  }
@@ -1270,7 +1303,7 @@ class WPvivid {
1270
  if($this->end_shutdown_function===false)
1271
  {
1272
  $last_error = error_get_last();
1273
- if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE,E_WARNING,E_USER_NOTICE,E_USER_WARNING), true))
1274
  {
1275
  $error = $last_error;
1276
  } else {
@@ -1308,7 +1341,7 @@ class WPvivid {
1308
  }
1309
  $time_spend = time() - $status['timeout'];
1310
  $time_start = time() - $status['start_time'];
1311
- $time_min=min($limit, 180);
1312
  if ($time_spend >= $limit)
1313
  {
1314
  //time out
@@ -1367,7 +1400,14 @@ class WPvivid {
1367
  {
1368
  $message = 'type: '. $error['type'] . ', ' . $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
1369
  } else {
1370
- $message = __('backup failed error unknown time spend:'.$time_start, 'wpvivid');
 
 
 
 
 
 
 
1371
  }
1372
  WPvivid_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
1373
  }
@@ -1531,6 +1571,7 @@ class WPvivid {
1531
  */
1532
  public function check_backup($task_id,$backup_option)
1533
  {
 
1534
  $options=WPvivid_Setting::get_option('wpvivid_common_setting');
1535
  if(isset($options['estimate_backup']))
1536
  {
@@ -1740,7 +1781,7 @@ class WPvivid {
1740
  */
1741
  private function add_clean_backup_record_event($backup_id)
1742
  {
1743
- $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
1744
  $tasks=WPvivid_Setting::get_option('clean_task');
1745
  $tasks[$backup_id]=$backup;
1746
  WPvivid_Setting::update_option('clean_task',$tasks);
@@ -2005,7 +2046,7 @@ class WPvivid {
2005
  }
2006
  $ret['result']=WPVIVID_SUCCESS;
2007
  $type_list=array();
2008
- $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2009
 
2010
  if($backup===false)
2011
  {
@@ -2042,7 +2083,7 @@ class WPvivid {
2042
  $download_info['file_name'] = $_POST['file_name'];
2043
 
2044
  $files = array();
2045
- $backup = WPvivid_Backuplist::get_backuplist_by_key($download_info['backup_id']);
2046
  if (!$backup) {
2047
  $json['result'] = 'failed';
2048
  $json['error'] = __('Retrieving the backup(s) information failed while deleting the selected backup(s). Please try again later.', 'wpvivid');
@@ -2168,7 +2209,7 @@ class WPvivid {
2168
  die();
2169
  }
2170
  $admin_url = admin_url();
2171
- echo __('file not found. please <a href="'.$admin_url.'admin.php?page=WPvivid">retry</a>.');
2172
  die();
2173
  }
2174
  /**
@@ -2179,14 +2220,16 @@ class WPvivid {
2179
  public function get_backup_list()
2180
  {
2181
  $this->ajax_check_security('manage_options');
2182
- try {
 
2183
  $json['result'] = 'success';
2184
  $html = '';
2185
  $html = apply_filters('wpvivid_add_backup_list', $html);
2186
  $json['html'] = $html;
2187
  echo json_encode($json);
2188
  }
2189
- catch (Exception $error) {
 
2190
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
2191
  error_log($message);
2192
  echo json_encode(array('result'=>'failed','error'=>$message));
@@ -2202,19 +2245,18 @@ class WPvivid {
2202
  public function delete_backup()
2203
  {
2204
  $this->ajax_check_security();
2205
- try {
2206
- if (isset($_POST['backup_id']) && !empty($_POST['backup_id']) && is_string($_POST['backup_id']) && isset($_POST['force'])) {
2207
- if ($_POST['force'] == 0 || $_POST['force'] == 1) {
 
 
 
2208
  $force_del = $_POST['force'];
2209
  } else {
2210
  $force_del = 0;
2211
  }
2212
  $backup_id = sanitize_key($_POST['backup_id']);
2213
-
2214
  $ret = $this->delete_backup_by_id($backup_id, $force_del);
2215
- $html = '';
2216
- $html = apply_filters('wpvivid_add_backup_list', $html);
2217
- $ret['html'] = $html;
2218
  echo json_encode($ret);
2219
  }
2220
  }
@@ -2234,11 +2276,14 @@ class WPvivid {
2234
  public function delete_backup_array()
2235
  {
2236
  $this->ajax_check_security();
2237
- try {
2238
- if (isset($_POST['backup_id']) && !empty($_POST['backup_id']) && is_array($_POST['backup_id'])) {
 
 
2239
  $backup_ids = $_POST['backup_id'];
2240
  $ret = array();
2241
- foreach ($backup_ids as $backup_id) {
 
2242
  $backup_id = sanitize_key($backup_id);
2243
  $ret = $this->delete_backup_by_id($backup_id);
2244
  }
@@ -2248,7 +2293,8 @@ class WPvivid {
2248
  echo json_encode($ret);
2249
  }
2250
  }
2251
- catch (Exception $error) {
 
2252
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
2253
  error_log($message);
2254
  echo json_encode(array('result'=>'failed','error'=>$message));
@@ -2259,7 +2305,7 @@ class WPvivid {
2259
 
2260
  public function delete_backup_by_id($backup_id,$force=0)
2261
  {
2262
- $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2263
  if(!$backup)
2264
  {
2265
  $ret['result']='failed';
@@ -2289,6 +2335,8 @@ class WPvivid {
2289
  }
2290
  }
2291
 
 
 
2292
  if(!empty($backup['remote']))
2293
  {
2294
  WPvivid_Backuplist::delete_backup($backup_id);
@@ -2303,6 +2351,9 @@ class WPvivid {
2303
  WPvivid_Backuplist::delete_backup($backup_id);
2304
  }
2305
 
 
 
 
2306
 
2307
  $ret['result']='success';
2308
  return $ret;
@@ -2312,7 +2363,7 @@ class WPvivid {
2312
  {
2313
  foreach ($backup_ids as $backup_id)
2314
  {
2315
- $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2316
  if(!$backup)
2317
  {
2318
  continue;
@@ -2699,20 +2750,23 @@ class WPvivid {
2699
 
2700
  $backup_id = sanitize_key($_POST['backup_id']);
2701
 
2702
- $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2703
 
2704
  $backup_item = new WPvivid_Backup_Item($backup);
2705
 
2706
  $ret = $backup_item->check_backup_files();
2707
 
2708
- $ret['is_migrate'] = $backup_item->check_migrate_file();
2709
 
2710
  if ($backup_item->get_backup_type() == 'Upload' || $backup_item->get_backup_type() == 'Migration')
2711
  {
2712
- if( $ret['is_migrate']==0)
 
2713
  $ret['is_migrate_ui'] = 1;
2714
- else
 
2715
  $ret['is_migrate_ui'] = 0;
 
2716
  } else {
2717
  $ret['is_migrate_ui'] = 0;
2718
  }
@@ -2767,7 +2821,7 @@ class WPvivid {
2767
 
2768
  $backup_id = sanitize_key($_POST['backup_id']);
2769
 
2770
- $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2771
 
2772
  $backup_item = new WPvivid_Backup_Item($backup);
2773
 
@@ -2777,10 +2831,17 @@ class WPvivid {
2777
 
2778
  if ($backup_item->get_backup_type() == 'Upload' || $backup_item->get_backup_type() == 'Migration')
2779
  {
2780
- if( $ret['is_migrate']==0)
 
2781
  $ret['is_migrate_ui'] = 1;
2782
- else
 
2783
  $ret['is_migrate_ui'] = 0;
 
 
 
 
 
2784
  } else {
2785
  $ret['is_migrate_ui'] = 0;
2786
  }
@@ -2849,7 +2910,7 @@ class WPvivid {
2849
 
2850
  $backup_id = sanitize_key($_POST['backup_id']);
2851
 
2852
- $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2853
 
2854
  $backup_item = new WPvivid_Backup_Item($backup);
2855
 
@@ -2895,7 +2956,7 @@ class WPvivid {
2895
  $file['file_name'] = $file_name;
2896
  $file['size'] = $_POST['size'];
2897
  $file['md5'] = $_POST['md5'];
2898
- $backup = WPvivid_Backuplist::get_backuplist_by_key($backup_id);
2899
  if (!$backup) {
2900
  echo json_encode(array('result' => WPVIVID_FAILED, 'error' => 'backup not found'));
2901
  die();
@@ -3078,6 +3139,11 @@ class WPvivid {
3078
  }
3079
  @ini_set('memory_limit', $memory_limit);
3080
  $ret=$restore->restore();
 
 
 
 
 
3081
  $this->_disable_maintenance_mode();
3082
  }
3083
  catch (Exception $error)
@@ -3442,7 +3508,20 @@ class WPvivid {
3442
  else{
3443
  $backup_id=false;
3444
  }
3445
- echo json_encode($this->_list_tasks($backup_id));
 
 
 
 
 
 
 
 
 
 
 
 
 
3446
  }
3447
  catch (Exception $error)
3448
  {
@@ -3461,7 +3540,7 @@ class WPvivid {
3461
  $list_tasks=array();
3462
  foreach ($tasks as $task)
3463
  {
3464
- if($task['action']=='backup')
3465
  {
3466
  $backup=new WPvivid_Backup_Task($task['id']);
3467
  $list_tasks[$task['id']]=$backup->get_backup_task_info($task['id']);
@@ -3496,8 +3575,8 @@ class WPvivid {
3496
  <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing">' . $list_tasks[$task['id']]['task_info']['descript'] . '</p></div>
3497
  <div style="clear: both;"></div>
3498
  <div>
3499
- <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>
3500
- <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>
3501
  </div>
3502
  <div style="clear: both;"></div>';
3503
  }
@@ -3513,7 +3592,7 @@ class WPvivid {
3513
  <span class="screen-reader-text">Dismiss this notice.</span>
3514
  </button>
3515
  </div>');
3516
- WPvivid_Setting::delete_option('wpvivid_backup_success_count');
3517
  $html = '';
3518
  $html = apply_filters('wpvivid_add_backup_list', $html);
3519
  $ret['backuplist_html'] = $html;
@@ -3530,7 +3609,7 @@ class WPvivid {
3530
  $error_notice_html['bu_error']['task_id']=$value['task_id'];
3531
  $error_notice_html['bu_error']['error_msg']=$value['error_msg'];
3532
  }
3533
- WPvivid_Setting::delete_option('wpvivid_backup_error_array');
3534
  $html = '';
3535
  $html = apply_filters('wpvivid_add_backup_list', $html);
3536
  $ret['backuplist_html'] = $html;
@@ -3545,7 +3624,7 @@ class WPvivid {
3545
 
3546
  $ret['download']=array();
3547
  if($backup_id !== false && !empty($backup_id)) {
3548
- $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
3549
  if($backup===false)
3550
  {
3551
  $ret['result']=WPVIVID_FAILED;
@@ -3634,30 +3713,7 @@ class WPvivid {
3634
  $lock = 0;
3635
  }
3636
 
3637
- WPvivid_Backuplist::set_security_lock($backup_id, $lock);
3638
- $ret['result'] = 'success';
3639
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
3640
- if (array_key_exists($backup_id, $list)) {
3641
- if (isset($list[$backup_id]['lock'])) {
3642
- if ($list[$backup_id]['lock'] == 1) {
3643
- $backup_lock = '/admin/partials/images/locked.png';
3644
- $lock_status = 'lock';
3645
- $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
3646
- } else {
3647
- $backup_lock = '/admin/partials/images/unlocked.png';
3648
- $lock_status = 'unlock';
3649
- $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
3650
- }
3651
- } else {
3652
- $backup_lock = '/admin/partials/images/unlocked.png';
3653
- $lock_status = 'unlock';
3654
- $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
3655
- }
3656
- } else {
3657
- $backup_lock = '/admin/partials/images/unlocked.png';
3658
- $lock_status = 'unlock';
3659
- $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid') . '" onclick="wpvivid_set_backup_lock(\'' . __($backup_id, 'wpvivid') . '\', \'' . __($lock_status, 'wpvivid') . '\');" style="vertical-align:middle; cursor:pointer;"/>';
3660
- }
3661
  echo json_encode($ret);
3662
  }
3663
  }
@@ -3840,7 +3896,7 @@ class WPvivid {
3840
  {
3841
  $file_name=basename($file);
3842
  $id=substr ($file_name,0,21);
3843
- if(WPvivid_Backuplist::get_backuplist_by_key($id)===false)
3844
  {
3845
  $delete_files[]=$file;
3846
  }
@@ -3860,7 +3916,7 @@ class WPvivid {
3860
  $files=array();
3861
  foreach ($list as $backup_id => $backup_value)
3862
  {
3863
- $backup=WPvivid_Backuplist::get_backuplist_by_key($backup_id);
3864
  if($backup===false)
3865
  {
3866
  continue;
@@ -4196,7 +4252,7 @@ class WPvivid {
4196
  $setting_data['wpvivid_common_setting']['max_execution_time'] = $setting['max_execution_time'];
4197
  $setting_data['wpvivid_common_setting']['log_save_location'] = $setting['path'].'/wpvivid_log';
4198
  $setting_data['wpvivid_common_setting']['max_backup_count'] = $setting['max_backup_count'];
4199
- $setting_data['wpvivid_common_setting']['show_admin_bar'] = $options['options']['wpvivid_common_setting']['show_admin_bar'];
4200
  $setting_data['wpvivid_common_setting']['show_tab_menu'] = $setting['show_tab_menu'];
4201
  $setting_data['wpvivid_common_setting']['domain_include'] = $setting['domain_include'];
4202
  $setting_data['wpvivid_common_setting']['estimate_backup'] = $setting['estimate_backup'];
@@ -4204,16 +4260,13 @@ class WPvivid {
4204
  $setting_data['wpvivid_common_setting']['memory_limit'] = $setting['memory_limit'].'M';
4205
  $setting_data['wpvivid_common_setting']['restore_memory_limit'] = $setting['restore_memory_limit'].'M';
4206
  $setting_data['wpvivid_common_setting']['migrate_size'] = $setting['migrate_size'];
4207
-
4208
  return $setting_data;
4209
  }
4210
 
4211
  public function set_general_setting()
4212
  {
4213
  $this->ajax_check_security('manage_options');
4214
-
4215
  $ret=array();
4216
-
4217
  try
4218
  {
4219
  if(isset($_POST['setting'])&&!empty($_POST['setting']))
@@ -4230,7 +4283,6 @@ class WPvivid {
4230
  echo json_encode($ret);
4231
  die();
4232
  }
4233
-
4234
  $options=WPvivid_Setting::get_setting(true, "");
4235
  $setting_data = array();
4236
  $setting_data= apply_filters('wpvivid_set_general_setting',$setting_data, $setting, $options);
@@ -4899,10 +4951,10 @@ class WPvivid {
4899
  die();
4900
  }
4901
 
4902
- public function wpvivid_add_backup_list($html, $tour = false)
4903
  {
4904
  $html = '';
4905
- $backuplist=WPvivid_Backuplist::get_backuplist();
4906
  $remote=array();
4907
  $remote=apply_filters('wpvivid_remote_pic', $remote);
4908
 
@@ -4978,15 +5030,16 @@ class WPvivid {
4978
  $tour_message = '';
4979
  $tour_class = '';
4980
  }
 
4981
  $hide = 'hide';
4982
  $html .= '<tr style="'.$row_style.'">
4983
- <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>
4984
  <td class="tablelistcolumn">
4985
  <div style="float:left;padding:0 10px 10px 0;">
4986
  <div class="backuptime"><strong>'.$upload_title.'</strong>'.__(date('M d, Y H:i',$value['create_time']), 'wpvivid').'</div>
4987
  <div class="common-table">
4988
  <span title="To lock the backup, the backup can only be deleted manually" id="wpvivid_lock_'.$key.'">
4989
- <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;"/>
4990
  </span>
4991
  <span style="margin:0;">|</span> <span>'.__('Type:', 'wpvivid').'</span><span>'.__($value['type'], 'wpvivid').'</span>
4992
  <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>
@@ -4998,7 +5051,7 @@ class WPvivid {
4998
  </td>
4999
  <td class="tablelistcolumn" style="min-width:100px;">
5000
  <div id="wpvivid_file_part_'.__($key, 'wpvivid').'" style="float:left;padding:10px 10px 10px 0;">
5001
- <div style="cursor:pointer;" onclick="wpvivid_initialize_download(\''.__($key, 'wpvivid').'\');" title="Prepare to download the backup">
5002
  <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>
5003
  <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>
5004
  </div>
@@ -5013,7 +5066,7 @@ class WPvivid {
5013
  </td>
5014
  <td class="tablelistcolumn">
5015
  <div class="backuplist-delete-backup" style="padding:10px 0 10px 0;">
5016
- <img src="'.esc_url(WPVIVID_PLUGIN_URL.'/admin/partials/images/Delete.png').'" style="vertical-align:middle; cursor:pointer;" title="Delete the backup" onclick="wpvivid_delete_selected_backup(\''.__($key, 'wpvivid').'\');"/>
5017
  </div>
5018
  </td>
5019
  </tr>';
95
 
96
  add_filter('pre_update_option',array( $this,'wpjam_pre_update_option_cache'),10,2);
97
 
98
+ add_filter('wpvivid_add_backup_list', array( $this, 'wpvivid_add_backup_list' ), 10, 3);
99
  add_filter('wpvivid_add_remote_storage_list', array( $this, 'wpvivid_add_remote_storage_list' ), 10);
100
  add_filter('wpvivid_schedule_add_remote_pic', array( $this, 'wpvivid_schedule_add_remote_pic' ), 10);
101
  add_filter('wpvivid_get_remote_directory', array( $this, 'wpvivid_get_remote_directory' ), 10);
119
  add_action('wpvivid_handle_backup_failed',array($this,'wpvivid_mark_task'),20);
120
  add_action('init', array($this, 'init_pclzip_tmp_folder'));
121
 
122
+ add_filter('wpvivid_list_task', array($this, '_list_tasks'), 10);
123
+
124
  //Initialisation schedule hook
125
  $this->init_cron();
126
  //Initialisation log object
197
  $plugin_admin = new WPvivid_Admin($this->get_plugin_name(), $this->get_version());
198
 
199
  add_action('admin_enqueue_scripts',array( $plugin_admin,'enqueue_styles'));
 
200
  add_action('admin_enqueue_scripts',array( $plugin_admin,'enqueue_scripts'));
 
201
  // Add menu item
202
+
203
+ if(is_multisite())
204
+ {
205
+ add_action('network_admin_menu',array( $plugin_admin,'add_plugin_admin_menu'));
206
+ }
207
+ else
208
+ {
209
+ add_action('admin_menu',array( $plugin_admin,'add_plugin_admin_menu'));
210
+ }
211
+
212
  add_action('admin_bar_menu',array( $plugin_admin,'add_toolbar_items'),100);
213
+ //show admin bar
214
  add_action('admin_head',array( $plugin_admin,'wpvivid_get_siteurl'),100);
215
 
216
  // Add Settings link to the plugin
381
  die();
382
  }
383
 
384
+ $backup_options = apply_filters('wpvivid_custom_backup_options', $backup_options);
385
+
386
+ if(!isset($backup_options['type']))
387
+ {
388
+ $backup_options['type']='Manual';
389
+ $backup_options['action']='backup';
390
+ }
391
+
392
+ $ret = $this->check_backup_option($backup_options, $backup_options['type']);
393
  if($ret['result']!=WPVIVID_SUCCESS)
394
  {
395
  $this->end_shutdown_function=true;
397
  die();
398
  }
399
 
400
+ $ret=$this->pre_backup($backup_options);
401
  if($ret['result']=='success')
402
  {
403
  //Check the website data to be backed up
587
  public function view_backup_log()
588
  {
589
  $this->ajax_check_security();
590
+ try
591
+ {
592
+ if (isset($_POST['id']) && !empty($_POST['id']) && is_string($_POST['id']))
593
+ {
594
  $backup_id = sanitize_key($_POST['id']);
595
+ $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
596
+ if (!$backup)
597
+ {
598
  $json['result'] = 'failed';
599
  $json['error'] = __('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid');
600
  echo json_encode($json);
601
  die();
602
  }
603
 
604
+ if (!file_exists($backup['log']))
605
+ {
606
  $json['result'] = 'failed';
607
  $json['error'] = __('The log not found.', 'wpvivid');
608
  echo json_encode($json);
611
 
612
  $file = fopen($backup['log'], 'r');
613
 
614
+ if (!$file)
615
+ {
616
  $json['result'] = 'failed';
617
  $json['error'] = __('Unable to open the log file.', 'wpvivid');
618
  echo json_encode($json);
620
  }
621
 
622
  $buffer = '';
623
+ while (!feof($file))
624
+ {
625
  $buffer .= fread($file, 1024);
626
  }
627
  fclose($file);
635
  echo json_encode($json);
636
  }
637
  }
638
+ catch (Exception $error)
639
+ {
640
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
641
  error_log($message);
642
  echo json_encode(array('result'=>'failed','error'=>$message));
802
  echo json_encode($ret);
803
  die();
804
  }
805
+
806
+ if(!isset($schedule_options['backup']['type']))
807
+ {
808
+ $schedule_options['backup']['type']='Cron';
809
+ $schedule_options['backup']['action']='backup';
810
+ }
811
+
812
  $ret = $this->pre_backup($schedule_options['backup'], 'Cron');
813
  if ($ret['result'] == 'success') {
814
  //Check the website data to be backed up.
825
  $ret['result']='failed';
826
  $message = 'An exception has occurred. class:'.get_class($error).';msg:'.$error->getMessage().';code:'.$error->getCode().';line:'.$error->getLine().';in_file:'.$error->getFile().';';
827
  $ret['error'] = $message;
 
828
  $id=uniqid('wpvivid-');
829
  $log_file_name=$id.'_backup';
830
  $log=new WPvivid_Log();
994
  *
995
  * @since 0.9.1
996
  */
997
+ public function pre_backup($backup_options)
998
  {
999
  $this->clean_oldest_backup();
1000
 
1006
  }
1007
 
1008
  $backup=new WPvivid_Backup_Task();
1009
+ $ret=$backup->new_backup_task($backup_options,$backup_options['type'],$backup_options['action']);
1010
  return $ret;
1011
  }
1012
 
1058
  $this->wpvivid_log->WriteLog('Backup completed.','notice');
1059
  }
1060
 
1061
+ if(!$this->finish_backup_task($task_id))
1062
  {
1063
  $this->end_shutdown_function=true;
1064
  die();
1100
  *
1101
  * @since 0.9.1
1102
  */
1103
+ private function finish_backup_task($task_id)
1104
  {
1105
  $status=WPvivid_taskmanager::get_backup_task_status($task_id);
1106
  if($status['str']=='running')
1107
  {
1108
  $this->wpvivid_log->WriteLog('Backup succeeded.','notice');
 
1109
 
1110
  $remote_options=WPvivid_taskmanager::get_task_options($task_id,'remote_options');
1111
  if($remote_options===false)
1113
  $task=WPvivid_taskmanager::update_backup_task_status($task_id,false,'completed');
1114
  do_action('wpvivid_handle_backup_succeed',$task);
1115
  }
 
 
 
 
1116
  return true;
1117
  }
1118
  else
1170
  $this->set_time_limit($task_id);
1171
 
1172
  $upload=new WPvivid_Upload();
1173
+ $ret=$upload->upload($task_id);
 
1174
  if($ret['result'] == WPVIVID_SUCCESS)
1175
  {
1176
  $task=WPvivid_taskmanager::update_backup_task_status($task_id,false,'completed');
1178
  }
1179
  else
1180
  {
1181
+ $backup = WPvivid_Backuplist::get_backup_by_id($task_id);
1182
+ if($backup!==false)
1183
+ {
1184
+ $backup['save_local']=1;
1185
+ WPvivid_Backuplist::update_backup_option($task_id, $backup);
1186
+ }
1187
+
1188
  $this->wpvivid_log->WriteLog('Uploading the file ends with an error '. $ret['error'], 'error');
1189
  $task=WPvivid_taskmanager::get_task($task_id);
1190
  do_action('wpvivid_handle_backup_failed',$task, false);
1212
  {
1213
  if($task['action'] === 'backup')
1214
  {
1215
+ $backup_task=new WPvivid_Backup_Task($task['id']);
1216
+ $backup_task->add_new_backup();
1217
+
1218
+ $remote_options = WPvivid_taskmanager::get_task_options($task['id'], 'remote_options');
1219
+ if($remote_options != false){
1220
+ WPvivid_Backuplist::update_backup($task['id'],'remote', $remote_options);
1221
+ }
1222
+
1223
  $backup_success_count = WPvivid_Setting::get_option('wpvivid_backup_success_count');
1224
  if (empty($backup_success_count))
1225
  {
1251
  {
1252
  $backup_error_array['bu_error']['task_id'] = $task['id'];
1253
  $backup_error_array['bu_error']['error_msg'] = 'Unknown error.';
1254
+
 
1255
  $general_setting=WPvivid_Setting::get_setting(true, "");
1256
  $need_notice = false;
1257
  if(!isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
1287
  $backup_error_array['bu_error']['error_msg'] = __('<div class="notice notice-error inline"><p>' . $notice_msg . ', Please switch to <a href="#" onclick="wpvivid_click_switch_page(\'wrap\', \'wpvivid_tab_debug\', true);">Website Info</a> page to send us the debug information. </p></div>');
1288
  }
1289
  }
 
1290
  WPvivid_Setting::update_option('wpvivid_backup_error_array', $backup_error_array);
1291
  }
1292
  }
1303
  if($this->end_shutdown_function===false)
1304
  {
1305
  $last_error = error_get_last();
1306
+ if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE,E_WARNING,E_USER_NOTICE,E_USER_WARNING,E_DEPRECATED), true))
1307
  {
1308
  $error = $last_error;
1309
  } else {
1341
  }
1342
  $time_spend = time() - $status['timeout'];
1343
  $time_start = time() - $status['start_time'];
1344
+ $time_min=min($limit, 120);
1345
  if ($time_spend >= $limit)
1346
  {
1347
  //time out
1400
  {
1401
  $message = 'type: '. $error['type'] . ', ' . $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
1402
  } else {
1403
+ if($time_start<30)
1404
+ {
1405
+ $message = __('Backup timed out since there may be no enough resource to complete the backup. Please contact your web hosting provider and ask for more server resource. Then try to backup again.', 'wpvivid');
1406
+ }
1407
+ else
1408
+ {
1409
+ $message = __('Backup timed out. Please set the value of PHP script execution timeout to '.$time_start.' in plugin settings.', 'wpvivid');
1410
+ }
1411
  }
1412
  WPvivid_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
1413
  }
1571
  */
1572
  public function check_backup($task_id,$backup_option)
1573
  {
1574
+ set_time_limit(180);
1575
  $options=WPvivid_Setting::get_option('wpvivid_common_setting');
1576
  if(isset($options['estimate_backup']))
1577
  {
1781
  */
1782
  private function add_clean_backup_record_event($backup_id)
1783
  {
1784
+ $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
1785
  $tasks=WPvivid_Setting::get_option('clean_task');
1786
  $tasks[$backup_id]=$backup;
1787
  WPvivid_Setting::update_option('clean_task',$tasks);
2046
  }
2047
  $ret['result']=WPVIVID_SUCCESS;
2048
  $type_list=array();
2049
+ $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
2050
 
2051
  if($backup===false)
2052
  {
2083
  $download_info['file_name'] = $_POST['file_name'];
2084
 
2085
  $files = array();
2086
+ $backup = WPvivid_Backuplist::get_backup_by_id($download_info['backup_id']);
2087
  if (!$backup) {
2088
  $json['result'] = 'failed';
2089
  $json['error'] = __('Retrieving the backup(s) information failed while deleting the selected backup(s). Please try again later.', 'wpvivid');
2209
  die();
2210
  }
2211
  $admin_url = admin_url();
2212
+ echo __('file not found. please <a href="'.$admin_url.'admin.php?page=WPvivid">retry</a> again.');
2213
  die();
2214
  }
2215
  /**
2220
  public function get_backup_list()
2221
  {
2222
  $this->ajax_check_security('manage_options');
2223
+ try
2224
+ {
2225
  $json['result'] = 'success';
2226
  $html = '';
2227
  $html = apply_filters('wpvivid_add_backup_list', $html);
2228
  $json['html'] = $html;
2229
  echo json_encode($json);
2230
  }
2231
+ catch (Exception $error)
2232
+ {
2233
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
2234
  error_log($message);
2235
  echo json_encode(array('result'=>'failed','error'=>$message));
2245
  public function delete_backup()
2246
  {
2247
  $this->ajax_check_security();
2248
+ try
2249
+ {
2250
+ if (isset($_POST['backup_id']) && !empty($_POST['backup_id']) && is_string($_POST['backup_id']) && isset($_POST['force']))
2251
+ {
2252
+ if ($_POST['force'] == 0 || $_POST['force'] == 1)
2253
+ {
2254
  $force_del = $_POST['force'];
2255
  } else {
2256
  $force_del = 0;
2257
  }
2258
  $backup_id = sanitize_key($_POST['backup_id']);
 
2259
  $ret = $this->delete_backup_by_id($backup_id, $force_del);
 
 
 
2260
  echo json_encode($ret);
2261
  }
2262
  }
2276
  public function delete_backup_array()
2277
  {
2278
  $this->ajax_check_security();
2279
+ try
2280
+ {
2281
+ if (isset($_POST['backup_id']) && !empty($_POST['backup_id']) && is_array($_POST['backup_id']))
2282
+ {
2283
  $backup_ids = $_POST['backup_id'];
2284
  $ret = array();
2285
+ foreach ($backup_ids as $backup_id)
2286
+ {
2287
  $backup_id = sanitize_key($backup_id);
2288
  $ret = $this->delete_backup_by_id($backup_id);
2289
  }
2293
  echo json_encode($ret);
2294
  }
2295
  }
2296
+ catch (Exception $error)
2297
+ {
2298
  $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
2299
  error_log($message);
2300
  echo json_encode(array('result'=>'failed','error'=>$message));
2305
 
2306
  public function delete_backup_by_id($backup_id,$force=0)
2307
  {
2308
+ $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
2309
  if(!$backup)
2310
  {
2311
  $ret['result']='failed';
2335
  }
2336
  }
2337
 
2338
+ $ret = WPvivid_Backuplist::get_backuplist_by_id($backup_id);
2339
+
2340
  if(!empty($backup['remote']))
2341
  {
2342
  WPvivid_Backuplist::delete_backup($backup_id);
2351
  WPvivid_Backuplist::delete_backup($backup_id);
2352
  }
2353
 
2354
+ $html = '';
2355
+ $html = apply_filters('wpvivid_add_backup_list', $html);
2356
+ $ret['html'] = $html;
2357
 
2358
  $ret['result']='success';
2359
  return $ret;
2363
  {
2364
  foreach ($backup_ids as $backup_id)
2365
  {
2366
+ $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
2367
  if(!$backup)
2368
  {
2369
  continue;
2750
 
2751
  $backup_id = sanitize_key($_POST['backup_id']);
2752
 
2753
+ $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
2754
 
2755
  $backup_item = new WPvivid_Backup_Item($backup);
2756
 
2757
  $ret = $backup_item->check_backup_files();
2758
 
2759
+ $ret['is_migrate'] = $backup_item->check_migrate_file();
2760
 
2761
  if ($backup_item->get_backup_type() == 'Upload' || $backup_item->get_backup_type() == 'Migration')
2762
  {
2763
+ $is_display = $backup_item->is_display_migrate_option();
2764
+ if($is_display === true){
2765
  $ret['is_migrate_ui'] = 1;
2766
+ }
2767
+ else{
2768
  $ret['is_migrate_ui'] = 0;
2769
+ }
2770
  } else {
2771
  $ret['is_migrate_ui'] = 0;
2772
  }
2821
 
2822
  $backup_id = sanitize_key($_POST['backup_id']);
2823
 
2824
+ $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
2825
 
2826
  $backup_item = new WPvivid_Backup_Item($backup);
2827
 
2831
 
2832
  if ($backup_item->get_backup_type() == 'Upload' || $backup_item->get_backup_type() == 'Migration')
2833
  {
2834
+ $is_display = $backup_item->is_display_migrate_option();
2835
+ if($is_display === true){
2836
  $ret['is_migrate_ui'] = 1;
2837
+ }
2838
+ else{
2839
  $ret['is_migrate_ui'] = 0;
2840
+ }
2841
+ /*if( $ret['is_migrate']==0)
2842
+ $ret['is_migrate_ui'] = 1;
2843
+ else
2844
+ $ret['is_migrate_ui'] = 0;*/
2845
  } else {
2846
  $ret['is_migrate_ui'] = 0;
2847
  }
2910
 
2911
  $backup_id = sanitize_key($_POST['backup_id']);
2912
 
2913
+ $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
2914
 
2915
  $backup_item = new WPvivid_Backup_Item($backup);
2916
 
2956
  $file['file_name'] = $file_name;
2957
  $file['size'] = $_POST['size'];
2958
  $file['md5'] = $_POST['md5'];
2959
+ $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
2960
  if (!$backup) {
2961
  echo json_encode(array('result' => WPVIVID_FAILED, 'error' => 'backup not found'));
2962
  die();
3139
  }
3140
  @ini_set('memory_limit', $memory_limit);
3141
  $ret=$restore->restore();
3142
+ if($ret['result']==WPVIVID_FAILED&&$ret['error']=='A restore task is already running.')
3143
+ {
3144
+ echo json_encode($ret);
3145
+ die();
3146
+ }
3147
  $this->_disable_maintenance_mode();
3148
  }
3149
  catch (Exception $error)
3508
  else{
3509
  $backup_id=false;
3510
  }
3511
+
3512
+ $ret = apply_filters('wpvivid_list_task', $backup_id);
3513
+
3514
+ $backup_success_count=WPvivid_Setting::get_option('wpvivid_backup_success_count');
3515
+ if(!empty($backup_success_count)){
3516
+ WPvivid_Setting::delete_option('wpvivid_backup_success_count');
3517
+ }
3518
+
3519
+ $backup_error_array=WPvivid_Setting::get_option('wpvivid_backup_error_array');
3520
+ if(!empty($backup_error_array)){
3521
+ WPvivid_Setting::delete_option('wpvivid_backup_error_array');
3522
+ }
3523
+
3524
+ echo json_encode($ret);
3525
  }
3526
  catch (Exception $error)
3527
  {
3540
  $list_tasks=array();
3541
  foreach ($tasks as $task)
3542
  {
3543
+ //if($task['action']=='backup')
3544
  {
3545
  $backup=new WPvivid_Backup_Task($task['id']);
3546
  $list_tasks[$task['id']]=$backup->get_backup_task_info($task['id']);
3575
  <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing">' . $list_tasks[$task['id']]['task_info']['descript'] . '</p></div>
3576
  <div style="clear: both;"></div>
3577
  <div>
3578
+ <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') . '" style="' . $list_tasks[$task['id']]['task_info']['css_btn_cancel'] . '" /></div>
3579
+ <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') . '" style="' . $list_tasks[$task['id']]['task_info']['css_btn_log'] . '" /></div>
3580
  </div>
3581
  <div style="clear: both;"></div>';
3582
  }
3592
  <span class="screen-reader-text">Dismiss this notice.</span>
3593
  </button>
3594
  </div>');
3595
+ //WPvivid_Setting::delete_option('wpvivid_backup_success_count');
3596
  $html = '';
3597
  $html = apply_filters('wpvivid_add_backup_list', $html);
3598
  $ret['backuplist_html'] = $html;
3609
  $error_notice_html['bu_error']['task_id']=$value['task_id'];
3610
  $error_notice_html['bu_error']['error_msg']=$value['error_msg'];
3611
  }
3612
+ //WPvivid_Setting::delete_option('wpvivid_backup_error_array');
3613
  $html = '';
3614
  $html = apply_filters('wpvivid_add_backup_list', $html);
3615
  $ret['backuplist_html'] = $html;
3624
 
3625
  $ret['download']=array();
3626
  if($backup_id !== false && !empty($backup_id)) {
3627
+ $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
3628
  if($backup===false)
3629
  {
3630
  $ret['result']=WPVIVID_FAILED;
3713
  $lock = 0;
3714
  }
3715
 
3716
+ $ret = WPvivid_Backuplist::set_security_lock($backup_id, $lock);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3717
  echo json_encode($ret);
3718
  }
3719
  }
3896
  {
3897
  $file_name=basename($file);
3898
  $id=substr ($file_name,0,21);
3899
+ if(WPvivid_Backuplist::get_backup_by_id($id)===false)
3900
  {
3901
  $delete_files[]=$file;
3902
  }
3916
  $files=array();
3917
  foreach ($list as $backup_id => $backup_value)
3918
  {
3919
+ $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
3920
  if($backup===false)
3921
  {
3922
  continue;
4252
  $setting_data['wpvivid_common_setting']['max_execution_time'] = $setting['max_execution_time'];
4253
  $setting_data['wpvivid_common_setting']['log_save_location'] = $setting['path'].'/wpvivid_log';
4254
  $setting_data['wpvivid_common_setting']['max_backup_count'] = $setting['max_backup_count'];
4255
+ $setting_data['wpvivid_common_setting']['show_admin_bar'] = $setting['show_admin_bar'];
4256
  $setting_data['wpvivid_common_setting']['show_tab_menu'] = $setting['show_tab_menu'];
4257
  $setting_data['wpvivid_common_setting']['domain_include'] = $setting['domain_include'];
4258
  $setting_data['wpvivid_common_setting']['estimate_backup'] = $setting['estimate_backup'];
4260
  $setting_data['wpvivid_common_setting']['memory_limit'] = $setting['memory_limit'].'M';
4261
  $setting_data['wpvivid_common_setting']['restore_memory_limit'] = $setting['restore_memory_limit'].'M';
4262
  $setting_data['wpvivid_common_setting']['migrate_size'] = $setting['migrate_size'];
 
4263
  return $setting_data;
4264
  }
4265
 
4266
  public function set_general_setting()
4267
  {
4268
  $this->ajax_check_security('manage_options');
 
4269
  $ret=array();
 
4270
  try
4271
  {
4272
  if(isset($_POST['setting'])&&!empty($_POST['setting']))
4283
  echo json_encode($ret);
4284
  die();
4285
  }
 
4286
  $options=WPvivid_Setting::get_setting(true, "");
4287
  $setting_data = array();
4288
  $setting_data= apply_filters('wpvivid_set_general_setting',$setting_data, $setting, $options);
4951
  die();
4952
  }
4953
 
4954
+ public function wpvivid_add_backup_list($html, $list_name = 'wpvivid_backup_list', $tour = false)
4955
  {
4956
  $html = '';
4957
+ $backuplist=WPvivid_Backuplist::get_backuplist($list_name);
4958
  $remote=array();
4959
  $remote=apply_filters('wpvivid_remote_pic', $remote);
4960
 
5030
  $tour_message = '';
5031
  $tour_class = '';
5032
  }
5033
+
5034
  $hide = 'hide';
5035
  $html .= '<tr style="'.$row_style.'">
5036
+ <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.'\', \''.$list_name.'\');" /></th>
5037
  <td class="tablelistcolumn">
5038
  <div style="float:left;padding:0 10px 10px 0;">
5039
  <div class="backuptime"><strong>'.$upload_title.'</strong>'.__(date('M d, Y H:i',$value['create_time']), 'wpvivid').'</div>
5040
  <div class="common-table">
5041
  <span title="To lock the backup, the backup can only be deleted manually" id="wpvivid_lock_'.$key.'">
5042
+ <img src="'.esc_url(WPVIVID_PLUGIN_URL.$backup_lock).'" name="'.esc_attr($lock_status, 'wpvivid').'" onclick="wpvivid_set_backup_lock(\''.$key.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>
5043
  </span>
5044
  <span style="margin:0;">|</span> <span>'.__('Type:', 'wpvivid').'</span><span>'.__($value['type'], 'wpvivid').'</span>
5045
  <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>
5051
  </td>
5052
  <td class="tablelistcolumn" style="min-width:100px;">
5053
  <div id="wpvivid_file_part_'.__($key, 'wpvivid').'" style="float:left;padding:10px 10px 10px 0;">
5054
+ <div style="cursor:pointer;" onclick="wpvivid_initialize_download(\''.$key.'\', \''.$list_name.'\');" title="Prepare to download the backup">
5055
  <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>
5056
  <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>
5057
  </div>
5066
  </td>
5067
  <td class="tablelistcolumn">
5068
  <div class="backuplist-delete-backup" style="padding:10px 0 10px 0;">
5069
+ <img src="'.esc_url(WPVIVID_PLUGIN_URL.'/admin/partials/images/Delete.png').'" style="vertical-align:middle; cursor:pointer;" title="Delete the backup" onclick="wpvivid_delete_selected_backup(\''.$key.'\', \''.$list_name.'\');"/>
5070
  </div>
5071
  </td>
5072
  </tr>';
includes/customclass/class-wpvivid-amazons3-plus.php CHANGED
@@ -21,12 +21,7 @@ class WPvivid_AMAZONS3Class extends WPvivid_Remote{
21
  {
22
  if(empty($options))
23
  {
24
- add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_amazons3'), 11);
25
- add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_amazons3'), 11);
26
- add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_amazons3'), 11);
27
- add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_amazons3'),11);
28
- add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_amazons3'),10,2);
29
- add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_amazons3'),10);
30
  }
31
  else
32
  {
@@ -34,6 +29,16 @@ class WPvivid_AMAZONS3Class extends WPvivid_Remote{
34
  }
35
  }
36
 
 
 
 
 
 
 
 
 
 
 
37
  public function wpvivid_add_storage_tab_amazons3()
38
  {
39
  ?>
@@ -393,11 +398,11 @@ class WPvivid_AMAZONS3Class extends WPvivid_Remote{
393
  public function download($file,$local_path,$callback = '')
394
  {
395
  try {
396
- global $wpvivid_pulgin;
397
  $this->current_file_name = $file['file_name'];
398
  $this->current_file_size = $file['size'];
399
  $file_md5 = $file['md5'];
400
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Get amazons3 client.','notice');
401
  $amazons3 = $this->getS3();
402
  if (is_array($amazons3) && $amazons3['result'] === WPVIVID_FAILED) {
403
  return $amazons3;
@@ -405,9 +410,9 @@ class WPvivid_AMAZONS3Class extends WPvivid_Remote{
405
 
406
  $file_path = trailingslashit($local_path) . $this->current_file_name;
407
  $start_offset = file_exists($file_path) ? filesize($file_path) : 0;
408
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Create local file.','notice');
409
  $fh = fopen($file_path, 'a');
410
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
411
  while ($start_offset < $this->current_file_size) {
412
  $last_byte = min($start_offset + $this->download_chunk_size - 1, $this->current_file_size - 1);
413
  $headers['Range'] = "bytes=$start_offset-$last_byte";
@@ -430,7 +435,7 @@ class WPvivid_AMAZONS3Class extends WPvivid_Remote{
430
  @fclose($fh);
431
 
432
  if(filesize($file_path) == $file['size']){
433
- if($wpvivid_pulgin->wpvivid_check_zip_valid()) {
434
  $res = TRUE;
435
  }
436
  else{
21
  {
22
  if(empty($options))
23
  {
24
+ add_action('plugins_loaded', array($this, 'plugins_loaded'));
 
 
 
 
 
25
  }
26
  else
27
  {
29
  }
30
  }
31
 
32
+ public function plugins_loaded()
33
+ {
34
+ add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_amazons3'), 11);
35
+ add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_amazons3'), 11);
36
+ add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_amazons3'), 11);
37
+ add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_amazons3'),11);
38
+ add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_amazons3'),10,2);
39
+ add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_amazons3'),10);
40
+ }
41
+
42
  public function wpvivid_add_storage_tab_amazons3()
43
  {
44
  ?>
398
  public function download($file,$local_path,$callback = '')
399
  {
400
  try {
401
+ global $wpvivid_plugin;
402
  $this->current_file_name = $file['file_name'];
403
  $this->current_file_size = $file['size'];
404
  $file_md5 = $file['md5'];
405
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Get amazons3 client.','notice');
406
  $amazons3 = $this->getS3();
407
  if (is_array($amazons3) && $amazons3['result'] === WPVIVID_FAILED) {
408
  return $amazons3;
410
 
411
  $file_path = trailingslashit($local_path) . $this->current_file_name;
412
  $start_offset = file_exists($file_path) ? filesize($file_path) : 0;
413
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Create local file.','notice');
414
  $fh = fopen($file_path, 'a');
415
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
416
  while ($start_offset < $this->current_file_size) {
417
  $last_byte = min($start_offset + $this->download_chunk_size - 1, $this->current_file_size - 1);
418
  $headers['Range'] = "bytes=$start_offset-$last_byte";
435
  @fclose($fh);
436
 
437
  if(filesize($file_path) == $file['size']){
438
+ if($wpvivid_plugin->wpvivid_check_zip_valid()) {
439
  $res = TRUE;
440
  }
441
  else{
includes/customclass/class-wpvivid-dropbox.php CHANGED
@@ -19,26 +19,30 @@ class WPvivid_Dropbox extends WPvivid_Remote {
19
  public function __construct($options = array())
20
  {
21
  if(empty($options)){
22
- if(!defined('WPVIVID_INIT_STORAGE_TAB_DROPBOX')){
23
- add_action('init', array($this, 'handle_auth_actions'));
24
- add_action('wpvivid_delete_remote_token',array($this,'revoke'));
25
-
26
- add_filter('wpvivid_remote_register', array($this, 'init_remotes'),10);
27
- add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_dropbox'), 10);
28
- add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_dropbox'), 10);
29
- add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_dropbox'), 10);
30
- add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_dropbox'),10);
31
- add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_dropbox'),10,2);
32
- add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_dropbox'),10);
33
- add_filter('wpvivid_get_root_path',array($this,'wpvivid_get_root_path_dropbox'),10);
34
-
35
- define('WPVIVID_INIT_STORAGE_TAB_DROPBOX',1);
36
- }
37
  }else{
38
  $this -> options = $options;
39
  }
40
  }
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  public function test_connect()
43
  {
44
  return array('result' => WPVIVID_SUCCESS);
@@ -78,7 +82,7 @@ class WPvivid_Dropbox extends WPvivid_Remote {
78
 
79
  public function upload($task_id, $files, $callback = '')
80
  {
81
- global $wpvivid_pulgin;
82
 
83
  $options = $this -> options;
84
  $dropbox = new Dropbox_Base($options);
@@ -105,20 +109,20 @@ class WPvivid_Dropbox extends WPvivid_Remote {
105
 
106
  $this -> last_time = time();
107
  $this -> last_size = 0;
108
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
109
  if(!file_exists($file))
110
  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.');
111
  $result = $this -> _put($task_id,$dropbox,$file,$callback);
112
  if($result['result'] !==WPVIVID_SUCCESS){
113
- $wpvivid_pulgin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
114
  return $result;
115
  }
116
- $wpvivid_pulgin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
117
  }
118
  return array('result' =>WPVIVID_SUCCESS);
119
  }
120
  private function _put($task_id,$dropbox,$file,$callback){
121
- global $wpvivid_pulgin;
122
  $options = $this -> options;
123
  $path = trailingslashit($options['path']).basename($file);
124
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_DROPBOX);
@@ -126,7 +130,7 @@ class WPvivid_Dropbox extends WPvivid_Remote {
126
  $this -> current_file_name = basename($file);
127
 
128
  if($this -> current_file_size > $this -> upload_chunk_size){
129
- $wpvivid_pulgin->wpvivid_log->WriteLog('Creating upload session.','notice');
130
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_DROPBOX,WPVIVID_UPLOAD_UNDO,'Start uploading '.basename($file).'.',$upload_job['job_data']);
131
  $result = $dropbox -> upload_session_start();
132
  if(isset($result['error_summary'])){
@@ -135,7 +139,7 @@ class WPvivid_Dropbox extends WPvivid_Remote {
135
  $build_id = $result['session_id'];
136
  $result = $this -> large_file_upload($build_id,$file,$dropbox,$callback);
137
  }else{
138
- $wpvivid_pulgin->wpvivid_log->WriteLog('Uploaded files are less than 2M.','notice');
139
  $result = $dropbox -> upload($path,$file);
140
  if(isset($result['error_summary'])){
141
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_DROPBOX,WPVIVID_UPLOAD_FAILED,'Uploading '.basename($file).' failed.',$upload_job['job_data']);
@@ -197,8 +201,8 @@ class WPvivid_Dropbox extends WPvivid_Remote {
197
  public function download($file, $local_path, $callback = '')
198
  {
199
  try {
200
- global $wpvivid_pulgin;
201
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Remote type: Dropbox.','notice');
202
  $this->current_file_name = $file['file_name'];
203
  $this->current_file_size = $file['size'];
204
  $file_md5 = $file['md5'];
@@ -207,9 +211,9 @@ class WPvivid_Dropbox extends WPvivid_Remote {
207
 
208
  $file_path = trailingslashit($local_path) . $this->current_file_name;
209
  $start_offset = file_exists($file_path) ? filesize($file_path) : 0;
210
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Create local file.','notice');
211
  $fh = fopen($file_path, 'a');
212
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
213
  while ($start_offset < $this->current_file_size) {
214
  $last_byte = min($start_offset + $this->download_chunk_size - 1, $this->current_file_size - 1);
215
  $headers = array("Range: bytes=$start_offset-$last_byte");
@@ -236,7 +240,7 @@ class WPvivid_Dropbox extends WPvivid_Remote {
236
  @fclose($fh);
237
 
238
  if(filesize($file_path) == $file['size']){
239
- if($wpvivid_pulgin->wpvivid_check_zip_valid()) {
240
  $res = TRUE;
241
  }
242
  else{
@@ -310,13 +314,13 @@ class WPvivid_Dropbox extends WPvivid_Remote {
310
  if (!isset($_POST['code'])) {
311
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=error&resp_msg=' . 'Get Dropbox token failed.');
312
  } else {
313
- global $wpvivid_pulgin;
314
  $remote_options['type'] = WPVIVID_REMOTE_DROPBOX;
315
  $remote_options['token'] = $_POST['code'];
316
  $remote_options['name'] = $_GET['name'];
317
  $remote_options['path'] = WPVIVID_DROPBOX_DEFAULT_FOLDER;
318
  $remote_options['default'] = $_GET['bdefault'];
319
- $ret = $wpvivid_pulgin->remote_collection->add_remote($remote_options);
320
  if ($ret['result'] == 'success') {
321
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=success');
322
  return;
@@ -376,12 +380,12 @@ class WPvivid_Dropbox extends WPvivid_Remote {
376
  if (!isset($_POST['code'])) {
377
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive_update&result=error&resp_msg=' . 'Get Dropbox token failed.');
378
  } else {
379
- global $wpvivid_pulgin;
380
  $remote_options['type'] = WPVIVID_REMOTE_DROPBOX;
381
  $remote_options['token'] = $_POST['code'];
382
  $remote_options['name'] = $_GET['name'];
383
  $remote_options['path'] = WPVIVID_DROPBOX_DEFAULT_FOLDER;
384
- $ret = $wpvivid_pulgin->remote_collection->update_remote($_GET['id'], $remote_options);
385
  if ($ret['result'] == 'success') {
386
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive_update&result=success');
387
  return;
@@ -416,16 +420,16 @@ class WPvivid_Dropbox extends WPvivid_Remote {
416
  _e('<div class="notice notice-success is-dismissible"><p>You have authenticated the Dropbox account as your remote storage.</p></div>');
417
  }
418
  public function wpvivid_show_notice_add_dropbox_error(){
419
- global $wpvivid_pulgin;
420
- $wpvivid_pulgin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Add Dropbox Remote');
421
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
422
  }
423
  public function wpvivid_show_notice_edit_dropbox_success(){
424
  _e('<div class="notice notice-success is-dismissible"><p>You have successfully updated the storage alias.</p></div>');
425
  }
426
  public function wpvivid_show_notice_edit_dropbox_error(){
427
- global $wpvivid_pulgin;
428
- $wpvivid_pulgin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Update Dropbox Remote');
429
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
430
  }
431
 
19
  public function __construct($options = array())
20
  {
21
  if(empty($options)){
22
+ add_action('plugins_loaded', array($this, 'plugins_loaded'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  }else{
24
  $this -> options = $options;
25
  }
26
  }
27
 
28
+ public function plugins_loaded(){
29
+ if(!defined('WPVIVID_INIT_STORAGE_TAB_DROPBOX')){
30
+ add_action('init', array($this, 'handle_auth_actions'));
31
+ add_action('wpvivid_delete_remote_token',array($this,'revoke'));
32
+
33
+ add_filter('wpvivid_remote_register', array($this, 'init_remotes'),10);
34
+ add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_dropbox'), 10);
35
+ add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_dropbox'), 10);
36
+ add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_dropbox'), 10);
37
+ add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_dropbox'),10);
38
+ add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_dropbox'),10,2);
39
+ add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_dropbox'),10);
40
+ add_filter('wpvivid_get_root_path',array($this,'wpvivid_get_root_path_dropbox'),10);
41
+
42
+ define('WPVIVID_INIT_STORAGE_TAB_DROPBOX',1);
43
+ }
44
+ }
45
+
46
  public function test_connect()
47
  {
48
  return array('result' => WPVIVID_SUCCESS);
82
 
83
  public function upload($task_id, $files, $callback = '')
84
  {
85
+ global $wpvivid_plugin;
86
 
87
  $options = $this -> options;
88
  $dropbox = new Dropbox_Base($options);
109
 
110
  $this -> last_time = time();
111
  $this -> last_size = 0;
112
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
113
  if(!file_exists($file))
114
  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.');
115
  $result = $this -> _put($task_id,$dropbox,$file,$callback);
116
  if($result['result'] !==WPVIVID_SUCCESS){
117
+ $wpvivid_plugin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
118
  return $result;
119
  }
120
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
121
  }
122
  return array('result' =>WPVIVID_SUCCESS);
123
  }
124
  private function _put($task_id,$dropbox,$file,$callback){
125
+ global $wpvivid_plugin;
126
  $options = $this -> options;
127
  $path = trailingslashit($options['path']).basename($file);
128
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_DROPBOX);
130
  $this -> current_file_name = basename($file);
131
 
132
  if($this -> current_file_size > $this -> upload_chunk_size){
133
+ $wpvivid_plugin->wpvivid_log->WriteLog('Creating upload session.','notice');
134
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_DROPBOX,WPVIVID_UPLOAD_UNDO,'Start uploading '.basename($file).'.',$upload_job['job_data']);
135
  $result = $dropbox -> upload_session_start();
136
  if(isset($result['error_summary'])){
139
  $build_id = $result['session_id'];
140
  $result = $this -> large_file_upload($build_id,$file,$dropbox,$callback);
141
  }else{
142
+ $wpvivid_plugin->wpvivid_log->WriteLog('Uploaded files are less than 2M.','notice');
143
  $result = $dropbox -> upload($path,$file);
144
  if(isset($result['error_summary'])){
145
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_DROPBOX,WPVIVID_UPLOAD_FAILED,'Uploading '.basename($file).' failed.',$upload_job['job_data']);
201
  public function download($file, $local_path, $callback = '')
202
  {
203
  try {
204
+ global $wpvivid_plugin;
205
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Remote type: Dropbox.','notice');
206
  $this->current_file_name = $file['file_name'];
207
  $this->current_file_size = $file['size'];
208
  $file_md5 = $file['md5'];
211
 
212
  $file_path = trailingslashit($local_path) . $this->current_file_name;
213
  $start_offset = file_exists($file_path) ? filesize($file_path) : 0;
214
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Create local file.','notice');
215
  $fh = fopen($file_path, 'a');
216
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
217
  while ($start_offset < $this->current_file_size) {
218
  $last_byte = min($start_offset + $this->download_chunk_size - 1, $this->current_file_size - 1);
219
  $headers = array("Range: bytes=$start_offset-$last_byte");
240
  @fclose($fh);
241
 
242
  if(filesize($file_path) == $file['size']){
243
+ if($wpvivid_plugin->wpvivid_check_zip_valid()) {
244
  $res = TRUE;
245
  }
246
  else{
314
  if (!isset($_POST['code'])) {
315
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=error&resp_msg=' . 'Get Dropbox token failed.');
316
  } else {
317
+ global $wpvivid_plugin;
318
  $remote_options['type'] = WPVIVID_REMOTE_DROPBOX;
319
  $remote_options['token'] = $_POST['code'];
320
  $remote_options['name'] = $_GET['name'];
321
  $remote_options['path'] = WPVIVID_DROPBOX_DEFAULT_FOLDER;
322
  $remote_options['default'] = $_GET['bdefault'];
323
+ $ret = $wpvivid_plugin->remote_collection->add_remote($remote_options);
324
  if ($ret['result'] == 'success') {
325
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive&result=success');
326
  return;
380
  if (!isset($_POST['code'])) {
381
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive_update&result=error&resp_msg=' . 'Get Dropbox token failed.');
382
  } else {
383
+ global $wpvivid_plugin;
384
  $remote_options['type'] = WPVIVID_REMOTE_DROPBOX;
385
  $remote_options['token'] = $_POST['code'];
386
  $remote_options['name'] = $_GET['name'];
387
  $remote_options['path'] = WPVIVID_DROPBOX_DEFAULT_FOLDER;
388
+ $ret = $wpvivid_plugin->remote_collection->update_remote($_GET['id'], $remote_options);
389
  if ($ret['result'] == 'success') {
390
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_dropbox_drive_update&result=success');
391
  return;
420
  _e('<div class="notice notice-success is-dismissible"><p>You have authenticated the Dropbox account as your remote storage.</p></div>');
421
  }
422
  public function wpvivid_show_notice_add_dropbox_error(){
423
+ global $wpvivid_plugin;
424
+ $wpvivid_plugin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Add Dropbox Remote');
425
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
426
  }
427
  public function wpvivid_show_notice_edit_dropbox_success(){
428
  _e('<div class="notice notice-success is-dismissible"><p>You have successfully updated the storage alias.</p></div>');
429
  }
430
  public function wpvivid_show_notice_edit_dropbox_error(){
431
+ global $wpvivid_plugin;
432
+ $wpvivid_plugin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Update Dropbox Remote');
433
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
434
  }
435
 
includes/customclass/class-wpvivid-ftpclass.php CHANGED
@@ -17,17 +17,22 @@ class WPvivid_FTPClass extends WPvivid_Remote{
17
  {
18
  if(empty($options))
19
  {
20
- add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_ftp'), 9);
21
- add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_ftp'), 9);
22
- add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_ftp'), 9);
23
- add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_ftp'),9);
24
- add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_ftp'),10,2);
25
- add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_ftp'),10);
26
  }else{
27
  $this->options = $options;
28
  }
29
  }
30
 
 
 
 
 
 
 
 
 
 
31
  public function wpvivid_add_storage_tab_ftp()
32
  {
33
  ?>
@@ -267,7 +272,7 @@ class WPvivid_FTPClass extends WPvivid_Remote{
267
 
268
  public function upload($task_id,$files,$callback = '')
269
  {
270
- global $wpvivid_pulgin;
271
  $this -> callback = $callback;
272
 
273
  $passive =$this->options['passive'];
@@ -292,12 +297,12 @@ class WPvivid_FTPClass extends WPvivid_Remote{
292
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_FTP,WPVIVID_UPLOAD_UNDO,'Start uploading.',$job_data);
293
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_FTP);
294
  }
295
- $wpvivid_pulgin->wpvivid_log->WriteLog('Connecting to server '.$host,'notice');
296
  $conn = $this -> do_connect($host,$username,$password,$port);
297
  if(is_array($conn) && array_key_exists('result',$conn))
298
  return $conn;
299
  ftp_pasv($conn,$passive);
300
- $wpvivid_pulgin->wpvivid_log->WriteLog('chdir '.$path,'notice');
301
  $str = $this -> do_chdir($conn , $path);
302
  if($str['result'] !== WPVIVID_SUCCESS)
303
  return $str;
@@ -313,12 +318,12 @@ class WPvivid_FTPClass extends WPvivid_Remote{
313
  }
314
  $this ->last_time = time();
315
  $this -> last_size = 0;
316
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
317
  $remote_file = trailingslashit($path).basename($file);
318
  if(!file_exists($file))
319
  return array('result'=>WPVIVID_FAILED,'error'=>$file.' not found. The file might has been moved, renamed or deleted. Please back it up again.');
320
 
321
- $wpvivid_pulgin->set_time_limit($task_id);
322
 
323
  for($i =0;$i <WPVIVID_REMOTE_CONNECT_RETRY_TIMES;$i ++)
324
  {
@@ -352,7 +357,7 @@ class WPvivid_FTPClass extends WPvivid_Remote{
352
 
353
  if($status == FTP_FINISHED)
354
  {
355
- $wpvivid_pulgin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
356
  $upload_job['job_data'][basename($file)]['uploaded']=1;
357
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_FTP,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
358
  break;
@@ -378,7 +383,7 @@ class WPvivid_FTPClass extends WPvivid_Remote{
378
  public function download($file,$local_path,$callback = '')
379
  {
380
  try {
381
- global $wpvivid_pulgin;
382
  $passive = $this->options['passive'];
383
  $host = $this->options['host'];
384
  $username = $this->options['username'];
@@ -393,14 +398,14 @@ class WPvivid_FTPClass extends WPvivid_Remote{
393
  $this->current_file_name = $file['file_name'];
394
  $this->current_file_size = $file['size'];
395
 
396
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Connecting FTP server.','notice');
397
  $conn = $this->do_connect($host, $username, $password, $port);
398
  if (is_array($conn) && array_key_exists('result', $conn)) {
399
  return $conn;
400
  }
401
 
402
  ftp_pasv($conn, $passive);
403
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Create local file.','notice');
404
  $local_handle = fopen($local_path, 'ab');
405
  if (!$local_handle) {
406
  return array('result' => WPVIVID_FAILED, 'error' => 'Unable to create the local file. Please make sure the folder is writable and try again.');
@@ -408,7 +413,7 @@ class WPvivid_FTPClass extends WPvivid_Remote{
408
 
409
  $stat = fstat($local_handle);
410
  $offset = $stat['size'];
411
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
412
  $status = ftp_nb_fget($conn, $local_handle, $remote_file, FTP_BINARY, $offset);
413
  while ($status == FTP_MOREDATA) {
414
  $status = ftp_nb_continue($conn);
@@ -423,7 +428,7 @@ class WPvivid_FTPClass extends WPvivid_Remote{
423
  }
424
 
425
  if(filesize($local_path) == $file['size']){
426
- if($wpvivid_pulgin->wpvivid_check_zip_valid()) {
427
  $res = TRUE;
428
  }
429
  else{
17
  {
18
  if(empty($options))
19
  {
20
+ add_action('plugins_loaded', array($this, 'plugins_loaded'));
21
+
 
 
 
 
22
  }else{
23
  $this->options = $options;
24
  }
25
  }
26
 
27
+ public function plugins_loaded(){
28
+ add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_ftp'), 9);
29
+ add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_ftp'), 9);
30
+ add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_ftp'), 9);
31
+ add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_ftp'),9);
32
+ add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_ftp'),10,2);
33
+ add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_ftp'),10);
34
+ }
35
+
36
  public function wpvivid_add_storage_tab_ftp()
37
  {
38
  ?>
272
 
273
  public function upload($task_id,$files,$callback = '')
274
  {
275
+ global $wpvivid_plugin;
276
  $this -> callback = $callback;
277
 
278
  $passive =$this->options['passive'];
297
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_FTP,WPVIVID_UPLOAD_UNDO,'Start uploading.',$job_data);
298
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_FTP);
299
  }
300
+ $wpvivid_plugin->wpvivid_log->WriteLog('Connecting to server '.$host,'notice');
301
  $conn = $this -> do_connect($host,$username,$password,$port);
302
  if(is_array($conn) && array_key_exists('result',$conn))
303
  return $conn;
304
  ftp_pasv($conn,$passive);
305
+ $wpvivid_plugin->wpvivid_log->WriteLog('chdir '.$path,'notice');
306
  $str = $this -> do_chdir($conn , $path);
307
  if($str['result'] !== WPVIVID_SUCCESS)
308
  return $str;
318
  }
319
  $this ->last_time = time();
320
  $this -> last_size = 0;
321
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
322
  $remote_file = trailingslashit($path).basename($file);
323
  if(!file_exists($file))
324
  return array('result'=>WPVIVID_FAILED,'error'=>$file.' not found. The file might has been moved, renamed or deleted. Please back it up again.');
325
 
326
+ $wpvivid_plugin->set_time_limit($task_id);
327
 
328
  for($i =0;$i <WPVIVID_REMOTE_CONNECT_RETRY_TIMES;$i ++)
329
  {
357
 
358
  if($status == FTP_FINISHED)
359
  {
360
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
361
  $upload_job['job_data'][basename($file)]['uploaded']=1;
362
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_FTP,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
363
  break;
383
  public function download($file,$local_path,$callback = '')
384
  {
385
  try {
386
+ global $wpvivid_plugin;
387
  $passive = $this->options['passive'];
388
  $host = $this->options['host'];
389
  $username = $this->options['username'];
398
  $this->current_file_name = $file['file_name'];
399
  $this->current_file_size = $file['size'];
400
 
401
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Connecting FTP server.','notice');
402
  $conn = $this->do_connect($host, $username, $password, $port);
403
  if (is_array($conn) && array_key_exists('result', $conn)) {
404
  return $conn;
405
  }
406
 
407
  ftp_pasv($conn, $passive);
408
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Create local file.','notice');
409
  $local_handle = fopen($local_path, 'ab');
410
  if (!$local_handle) {
411
  return array('result' => WPVIVID_FAILED, 'error' => 'Unable to create the local file. Please make sure the folder is writable and try again.');
413
 
414
  $stat = fstat($local_handle);
415
  $offset = $stat['size'];
416
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
417
  $status = ftp_nb_fget($conn, $local_handle, $remote_file, FTP_BINARY, $offset);
418
  while ($status == FTP_MOREDATA) {
419
  $status = ftp_nb_continue($conn);
428
  }
429
 
430
  if(filesize($local_path) == $file['size']){
431
+ if($wpvivid_plugin->wpvivid_check_zip_valid()) {
432
  $res = TRUE;
433
  }
434
  else{
includes/customclass/class-wpvivid-google-drive.php CHANGED
@@ -26,20 +26,8 @@ class Wpvivid_Google_drive extends WPvivid_Remote
26
  {
27
  if(empty($options))
28
  {
29
- if(!defined('WPVIVID_INIT_STORAGE_TAB_GOOGLE_DRIVE'))
30
- {
31
- add_action('init', array($this, 'handle_auth_actions'));
32
-
33
- add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_google_drive'), 10);
34
- add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_google_drive'), 10);
35
- add_filter('wpvivid_pre_add_remote',array($this, 'pre_add_remote'),10,2);
36
- add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_google_drive'), 10);
37
- add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_google_drive'),10);
38
- add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_google_drive'),10,2);
39
- add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_google_drive'),10);
40
- add_filter('wpvivid_get_root_path',array($this,'wpvivid_get_root_path_google_drive'),10);
41
- define('WPVIVID_INIT_STORAGE_TAB_GOOGLE_DRIVE',1);
42
- }
43
  }
44
  else
45
  {
@@ -56,6 +44,23 @@ class Wpvivid_Google_drive extends WPvivid_Remote
56
  ));
57
  }
58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  public function pre_add_remote($remote,$id)
60
  {
61
  if($remote['type']==WPVIVID_REMOTE_GOOGLEDRIVE)
@@ -129,7 +134,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
129
  return;
130
  }
131
 
132
- global $wpvivid_pulgin;
133
 
134
  $remote_options['type'] = WPVIVID_REMOTE_GOOGLEDRIVE;
135
  $remote_options['token']['access_token'] = $_POST['access_token'];
@@ -141,7 +146,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
141
  $remote_options['name'] = $_GET['name'];
142
  $remote_options['default'] = $_GET['default'];
143
  $remote_options['path'] = WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER;
144
- $ret = $wpvivid_pulgin->remote_collection->add_remote($remote_options);
145
 
146
  if ($ret['result'] == 'success') {
147
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_google_drive&result=success');
@@ -225,7 +230,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
225
  return;
226
  }
227
 
228
- global $wpvivid_pulgin;
229
 
230
  $remote_options['type'] = WPVIVID_REMOTE_GOOGLEDRIVE;
231
  $remote_options['token']['access_token'] = $_POST['access_token'];
@@ -236,7 +241,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
236
  $remote_options['token']['created'] = $_POST['created'];
237
  $remote_options['name'] = $_GET['name'];
238
  $remote_options['path'] = WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER;
239
- $ret = $wpvivid_pulgin->remote_collection->update_remote($_GET['id'], $remote_options);
240
 
241
  if ($ret['result'] == 'success') {
242
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_google_drive_update&result=success');
@@ -271,16 +276,16 @@ class Wpvivid_Google_drive extends WPvivid_Remote
271
  _e('<div class="notice notice-success is-dismissible"><p>You have authenticated the Google Drive account as your remote storage.</p></div>');
272
  }
273
  public function wpvivid_show_notice_add_google_drive_error(){
274
- global $wpvivid_pulgin;
275
- $wpvivid_pulgin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Add Google Drive Remote');
276
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
277
  }
278
  public function wpvivid_show_notice_edit_google_drive_success(){
279
  _e('<div class="notice notice-success is-dismissible"><p>You have successfully updated the storage alias.</p></div>');
280
  }
281
  public function wpvivid_show_notice_edit_google_drive_error(){
282
- global $wpvivid_pulgin;
283
- $wpvivid_pulgin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Update Google Drive Remote');
284
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
285
  }
286
 
@@ -459,7 +464,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
459
 
460
  public function upload($task_id, $files, $callback = '')
461
  {
462
- global $wpvivid_pulgin;
463
 
464
 
465
  $client=$this->get_client();
@@ -475,7 +480,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
475
 
476
  $service = new Google_Service_Drive($client);
477
  $path=$this->options['path'];
478
- $wpvivid_pulgin->wpvivid_log->WriteLog('Check upload folder '.$path,'notice');
479
  $folder_id=$this->get_folder($service,$path);
480
 
481
  if($folder_id==false)
@@ -510,7 +515,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
510
 
511
  if(!file_exists($file))
512
  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.');
513
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
514
  $result=$this->_upload($task_id, $file,$client,$service,$folder_id, $callback);
515
  if($result['result'] !==WPVIVID_SUCCESS){
516
  return $result;
@@ -521,8 +526,8 @@ class Wpvivid_Google_drive extends WPvivid_Remote
521
 
522
  public function _upload($task_id, $file,$client,$service,$folder_id, $callback = '')
523
  {
524
- global $wpvivid_pulgin;
525
- $wpvivid_pulgin->wpvivid_log->WriteLog('Check if the server already has the same name file.','notice');
526
  if(!$this->delete_exist_file($folder_id,$file,$service))
527
  {
528
  return array('result' =>WPVIVID_FAILED,'error'=>'Uploading '.$file.' to Google Drive server failed. '.$file.' might be deleted or network doesn\'t work properly . Please verify the file and confirm the network connection and try again later.');
@@ -532,7 +537,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
532
  $this -> current_file_size = filesize($file);
533
  $this -> current_file_name = basename($file);
534
 
535
- $wpvivid_pulgin->wpvivid_log->WriteLog('Initiate a resumable upload session.','notice');
536
  $fileMetadata = new Google_Service_Drive_DriveFile(array(
537
  'name' => basename($file),
538
  'parents' => array($folder_id)));
@@ -579,7 +584,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
579
  $client->setDefer(false);
580
  if ($status != false)
581
  {
582
- $wpvivid_pulgin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
583
  $upload_job['job_data'][basename($file)]['uploaded']=1;
584
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_GOOGLEDRIVE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
585
  return array('result' =>WPVIVID_SUCCESS);
@@ -657,10 +662,10 @@ class Wpvivid_Google_drive extends WPvivid_Remote
657
  {
658
  try
659
  {
660
- global $wpvivid_pulgin;
661
  $this -> current_file_name = $file['file_name'];
662
  $this -> current_file_size = $file['size'];
663
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Google Drive get client.','notice');
664
  $client=$this->get_client();
665
  if($client['result'] == WPVIVID_FAILED) {
666
  return $client;
@@ -675,7 +680,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
675
  $service = new Google_Service_Drive($client);
676
 
677
  $path=$this->options['path'];
678
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Create local file.','notice');
679
  $folder_id=$this->get_folder($service,$path);
680
 
681
  if($folder_id==false)
@@ -701,7 +706,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
701
  $file_id=$file->getId();
702
  break;
703
  }
704
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Get download url.','notice');
705
  $download_url=$this->get_download_url($client,$file_id);
706
 
707
  if(!empty($file_id)||!empty($download_url))
@@ -720,7 +725,7 @@ class Wpvivid_Google_drive extends WPvivid_Remote
720
  $fh = fopen($file_path, 'a');
721
  $upload_size = WPVIVID_GOOGLEDRIVE_UPLOAD_SIZE;
722
  $http = $client->authorize();
723
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
724
  while ($offset < $fileSize)
725
  {
726
  $upload_end=min($offset+$upload_size-1,$fileSize-1);
26
  {
27
  if(empty($options))
28
  {
29
+ add_action('plugins_loaded', array($this, 'plugins_loaded'));
30
+
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
32
  else
33
  {
44
  ));
45
  }
46
 
47
+ public function plugins_loaded(){
48
+ if(!defined('WPVIVID_INIT_STORAGE_TAB_GOOGLE_DRIVE'))
49
+ {
50
+ add_action('init', array($this, 'handle_auth_actions'));
51
+
52
+ add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_google_drive'), 10);
53
+ add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_google_drive'), 10);
54
+ add_filter('wpvivid_pre_add_remote',array($this, 'pre_add_remote'),10,2);
55
+ add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_google_drive'), 10);
56
+ add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_google_drive'),10);
57
+ add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_google_drive'),10,2);
58
+ add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_google_drive'),10);
59
+ add_filter('wpvivid_get_root_path',array($this,'wpvivid_get_root_path_google_drive'),10);
60
+ define('WPVIVID_INIT_STORAGE_TAB_GOOGLE_DRIVE',1);
61
+ }
62
+ }
63
+
64
  public function pre_add_remote($remote,$id)
65
  {
66
  if($remote['type']==WPVIVID_REMOTE_GOOGLEDRIVE)
134
  return;
135
  }
136
 
137
+ global $wpvivid_plugin;
138
 
139
  $remote_options['type'] = WPVIVID_REMOTE_GOOGLEDRIVE;
140
  $remote_options['token']['access_token'] = $_POST['access_token'];
146
  $remote_options['name'] = $_GET['name'];
147
  $remote_options['default'] = $_GET['default'];
148
  $remote_options['path'] = WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER;
149
+ $ret = $wpvivid_plugin->remote_collection->add_remote($remote_options);
150
 
151
  if ($ret['result'] == 'success') {
152
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_google_drive&result=success');
230
  return;
231
  }
232
 
233
+ global $wpvivid_plugin;
234
 
235
  $remote_options['type'] = WPVIVID_REMOTE_GOOGLEDRIVE;
236
  $remote_options['token']['access_token'] = $_POST['access_token'];
241
  $remote_options['token']['created'] = $_POST['created'];
242
  $remote_options['name'] = $_GET['name'];
243
  $remote_options['path'] = WPVIVID_GOOGLEDRIVE_DEFAULT_FOLDER;
244
+ $ret = $wpvivid_plugin->remote_collection->update_remote($_GET['id'], $remote_options);
245
 
246
  if ($ret['result'] == 'success') {
247
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_google_drive_update&result=success');
276
  _e('<div class="notice notice-success is-dismissible"><p>You have authenticated the Google Drive account as your remote storage.</p></div>');
277
  }
278
  public function wpvivid_show_notice_add_google_drive_error(){
279
+ global $wpvivid_plugin;
280
+ $wpvivid_plugin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Add Google Drive Remote');
281
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
282
  }
283
  public function wpvivid_show_notice_edit_google_drive_success(){
284
  _e('<div class="notice notice-success is-dismissible"><p>You have successfully updated the storage alias.</p></div>');
285
  }
286
  public function wpvivid_show_notice_edit_google_drive_error(){
287
+ global $wpvivid_plugin;
288
+ $wpvivid_plugin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Update Google Drive Remote');
289
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
290
  }
291
 
464
 
465
  public function upload($task_id, $files, $callback = '')
466
  {
467
+ global $wpvivid_plugin;
468
 
469
 
470
  $client=$this->get_client();
480
 
481
  $service = new Google_Service_Drive($client);
482
  $path=$this->options['path'];
483
+ $wpvivid_plugin->wpvivid_log->WriteLog('Check upload folder '.$path,'notice');
484
  $folder_id=$this->get_folder($service,$path);
485
 
486
  if($folder_id==false)
515
 
516
  if(!file_exists($file))
517
  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.');
518
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
519
  $result=$this->_upload($task_id, $file,$client,$service,$folder_id, $callback);
520
  if($result['result'] !==WPVIVID_SUCCESS){
521
  return $result;
526
 
527
  public function _upload($task_id, $file,$client,$service,$folder_id, $callback = '')
528
  {
529
+ global $wpvivid_plugin;
530
+ $wpvivid_plugin->wpvivid_log->WriteLog('Check if the server already has the same name file.','notice');
531
  if(!$this->delete_exist_file($folder_id,$file,$service))
532
  {
533
  return array('result' =>WPVIVID_FAILED,'error'=>'Uploading '.$file.' to Google Drive server failed. '.$file.' might be deleted or network doesn\'t work properly . Please verify the file and confirm the network connection and try again later.');
537
  $this -> current_file_size = filesize($file);
538
  $this -> current_file_name = basename($file);
539
 
540
+ $wpvivid_plugin->wpvivid_log->WriteLog('Initiate a resumable upload session.','notice');
541
  $fileMetadata = new Google_Service_Drive_DriveFile(array(
542
  'name' => basename($file),
543
  'parents' => array($folder_id)));
584
  $client->setDefer(false);
585
  if ($status != false)
586
  {
587
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
588
  $upload_job['job_data'][basename($file)]['uploaded']=1;
589
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_GOOGLEDRIVE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
590
  return array('result' =>WPVIVID_SUCCESS);
662
  {
663
  try
664
  {
665
+ global $wpvivid_plugin;
666
  $this -> current_file_name = $file['file_name'];
667
  $this -> current_file_size = $file['size'];
668
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Google Drive get client.','notice');
669
  $client=$this->get_client();
670
  if($client['result'] == WPVIVID_FAILED) {
671
  return $client;
680
  $service = new Google_Service_Drive($client);
681
 
682
  $path=$this->options['path'];
683
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Create local file.','notice');
684
  $folder_id=$this->get_folder($service,$path);
685
 
686
  if($folder_id==false)
706
  $file_id=$file->getId();
707
  break;
708
  }
709
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Get download url.','notice');
710
  $download_url=$this->get_download_url($client,$file_id);
711
 
712
  if(!empty($file_id)||!empty($download_url))
725
  $fh = fopen($file_path, 'a');
726
  $upload_size = WPVIVID_GOOGLEDRIVE_UPLOAD_SIZE;
727
  $http = $client->authorize();
728
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
729
  while ($offset < $fileSize)
730
  {
731
  $upload_end=min($offset+$upload_size-1,$fileSize-1);
includes/customclass/class-wpvivid-one-drive.php CHANGED
@@ -45,19 +45,7 @@ class WPvivid_one_drive extends WPvivid_Remote
45
  {
46
  if(empty($options))
47
  {
48
- if(!defined('WPVIVID_INIT_STORAGE_TAB_ONE_DRIVE'))
49
- {
50
- add_action('init', array($this, 'handle_auth_actions'));
51
- add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_one_drive'), 10);
52
- add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_one_drive'), 10);
53
- add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_one_drive'), 10);
54
- add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_one_drive'),10);
55
- add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_one_drive'),10,2);
56
- add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_one_drive'),10);
57
- add_filter('wpvivid_get_root_path',array($this,'wpvivid_get_root_path_one_drive'),10);
58
- add_filter('wpvivid_pre_add_remote',array($this, 'pre_add_remote'),10,2);
59
- define('WPVIVID_INIT_STORAGE_TAB_ONE_DRIVE',1);
60
- }
61
  }
62
  else
63
  {
@@ -65,6 +53,23 @@ class WPvivid_one_drive extends WPvivid_Remote
65
  }
66
  }
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  public function pre_add_remote($remote,$id)
69
  {
70
  if($remote['type']==WPVIVID_REMOTE_ONEDRIVE)
@@ -122,7 +127,7 @@ class WPvivid_one_drive extends WPvivid_Remote
122
  return;
123
  }
124
 
125
- global $wpvivid_pulgin;
126
 
127
  $remote_options['type'] = WPVIVID_REMOTE_ONEDRIVE;
128
  //$token = $_POST['token'];
@@ -137,7 +142,7 @@ class WPvivid_one_drive extends WPvivid_Remote
137
  $remote_options['name'] = $_GET['name'];
138
  $remote_options['default'] = $_GET['default'];
139
  $remote_options['path'] = WPVIVID_ONEDRIVE_DEFAULT_FOLDER;
140
- $ret = $wpvivid_pulgin->remote_collection->add_remote($remote_options);
141
 
142
  if ($ret['result'] == 'success') {
143
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive&result=success');
@@ -208,7 +213,7 @@ class WPvivid_one_drive extends WPvivid_Remote
208
  return;
209
  }
210
 
211
- global $wpvivid_pulgin;
212
 
213
  $remote_options['type'] = WPVIVID_REMOTE_ONEDRIVE;
214
  //$token = $_GET['token'];
@@ -221,7 +226,7 @@ class WPvivid_one_drive extends WPvivid_Remote
221
  $remote_options['token']['expires']=time()+$_POST['expires_in'];
222
  $remote_options['name'] = $_GET['name'];
223
  $remote_options['path'] = WPVIVID_ONEDRIVE_DEFAULT_FOLDER;
224
- $ret = $wpvivid_pulgin->remote_collection->update_remote($_GET['id'], $remote_options);
225
 
226
  if ($ret['result'] == 'success') {
227
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive_update&result=success');
@@ -256,16 +261,16 @@ class WPvivid_one_drive extends WPvivid_Remote
256
  _e('<div class="notice notice-success is-dismissible"><p>You have authenticated the Microsoft OneDrive account as your remote storage.</p></div>');
257
  }
258
  public function wpvivid_show_notice_add_onedrive_error(){
259
- global $wpvivid_pulgin;
260
- $wpvivid_pulgin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Add OneDrive Remote');
261
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
262
  }
263
  public function wpvivid_show_notice_edit_onedrive_success(){
264
  _e('<div class="notice notice-success is-dismissible"><p>You have successfully updated the storage alias.</p></div>');
265
  }
266
  public function wpvivid_show_notice_edit_onedrive_error(){
267
- global $wpvivid_pulgin;
268
- $wpvivid_pulgin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Update OneDrive Remote');
269
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
270
  }
271
 
@@ -417,11 +422,11 @@ class WPvivid_one_drive extends WPvivid_Remote
417
 
418
  public function upload($task_id, $files, $callback = '')
419
  {
420
- global $wpvivid_pulgin;
421
 
422
  if($this->need_refresh())
423
  {
424
- $wpvivid_pulgin->wpvivid_log->WriteLog('The token expired and will go to the server to refresh the token.','notice');
425
  $ret=$this->refresh_token();
426
  if($ret['result']===WPVIVID_FAILED)
427
  {
@@ -430,7 +435,7 @@ class WPvivid_one_drive extends WPvivid_Remote
430
  }
431
 
432
  $path=$this->options['path'];
433
- $wpvivid_pulgin->wpvivid_log->WriteLog('Check upload folder '.$path,'notice');
434
  $ret=$this->check_folder($path);
435
 
436
  if($ret['result']===WPVIVID_FAILED)
@@ -465,7 +470,7 @@ class WPvivid_one_drive extends WPvivid_Remote
465
 
466
  if(!file_exists($file))
467
  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.');
468
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
469
  $result=$this->_upload($task_id, $file,$callback);
470
  if($result['result'] !==WPVIVID_SUCCESS)
471
  {
@@ -512,8 +517,8 @@ class WPvivid_one_drive extends WPvivid_Remote
512
  $this->current_file_name = $file['file_name'];
513
  $this->current_file_size = $file['size'];
514
 
515
- global $wpvivid_pulgin;
516
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Remote type: OneDrive.','notice');
517
  if ($this->need_refresh()) {
518
  $ret = $this->refresh_token();
519
  if ($ret['result'] === WPVIVID_FAILED) {
@@ -529,9 +534,9 @@ class WPvivid_one_drive extends WPvivid_Remote
529
  }
530
 
531
  $file_path = $local_path . $file['file_name'];
532
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Create local file.','notice');
533
  $fh = fopen($file_path, 'a');
534
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
535
  $downloaded_start = filesize($file_path);
536
  $url = 'https://graph.microsoft.com/v1.0/me/drive/root:/' . $this->options['path'] . '/' . $file['file_name'] . ':/content';
537
  $download_size = WPVIVID_ONEDRIVE_DOWNLOAD_SIZE;
@@ -566,7 +571,7 @@ class WPvivid_one_drive extends WPvivid_Remote
566
 
567
  private function download_loop($url,&$downloaded_start,$download_size,$file_size,$retry_count=0)
568
  {
569
- global $wpvivid_pulgin;
570
 
571
  $downloaded_end=min($downloaded_start+$download_size-1,$file_size-1);
572
  $headers['Range']="bytes=$downloaded_start-$downloaded_end";
@@ -697,12 +702,12 @@ class WPvivid_one_drive extends WPvivid_Remote
697
 
698
  private function _upload($task_id,$local_file,$callback)
699
  {
700
- global $wpvivid_pulgin;
701
 
702
  $this -> current_file_size = filesize($local_file);
703
  $this -> current_file_name = basename($local_file);
704
 
705
- $wpvivid_pulgin->wpvivid_log->WriteLog('Check if the server already has the same name file.','notice');
706
 
707
  $this->delete_file_by_name($this->options['path'],basename($local_file));
708
 
@@ -711,13 +716,13 @@ class WPvivid_one_drive extends WPvivid_Remote
711
  //small file
712
  if($file_size<1024*1024*4)
713
  {
714
- $wpvivid_pulgin->wpvivid_log->WriteLog('Uploaded files are less than 4M.','notice');
715
  $ret=$this->upload_small_file($local_file,$task_id);
716
  return $ret;
717
  }
718
  else
719
  {
720
- $wpvivid_pulgin->wpvivid_log->WriteLog('Creating upload session.','notice');
721
  //big file
722
  $ret=$this->create_upload_session(basename($local_file));
723
 
@@ -725,7 +730,7 @@ class WPvivid_one_drive extends WPvivid_Remote
725
  {
726
  return $ret;
727
  }
728
- $wpvivid_pulgin->wpvivid_log->WriteLog('Ready to start uploading files.','notice');
729
  $ret=$this->upload_resume($ret['session_url'],$local_file,$task_id,$callback);
730
 
731
  return $ret;
@@ -734,7 +739,7 @@ class WPvivid_one_drive extends WPvivid_Remote
734
 
735
  private function upload_small_file($file,$task_id)
736
  {
737
- global $wpvivid_pulgin;
738
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_ONEDRIVE);
739
 
740
  $path=$this->options['path'].'/'.basename($file);
@@ -752,7 +757,7 @@ class WPvivid_one_drive extends WPvivid_Remote
752
  if(!is_wp_error($response) && ($response['response']['code'] == 200||$response['response']['code'] == 201))
753
  {
754
  $upload_job['job_data'][basename($file)]['uploaded']=1;
755
- $wpvivid_pulgin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
756
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_ONEDRIVE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
757
  return array('result' =>WPVIVID_SUCCESS);
758
  }
@@ -774,7 +779,7 @@ class WPvivid_one_drive extends WPvivid_Remote
774
 
775
  private function upload_resume($session_url,$file,$task_id,$callback)
776
  {
777
- global $wpvivid_pulgin;
778
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_ONEDRIVE);
779
 
780
  $offset=0;
@@ -819,7 +824,7 @@ class WPvivid_one_drive extends WPvivid_Remote
819
 
820
  fclose($handle);
821
  $upload_job['job_data'][basename($file)]['uploaded']=1;
822
- $wpvivid_pulgin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
823
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_ONEDRIVE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
824
  return array('result' =>WPVIVID_SUCCESS);
825
  }
@@ -872,7 +877,7 @@ class WPvivid_one_drive extends WPvivid_Remote
872
 
873
  curl_setopt_array($curl, $options);
874
 
875
- global $wpvivid_pulgin;
876
 
877
  $response=curl_exec($curl);
878
 
@@ -979,7 +984,7 @@ class WPvivid_one_drive extends WPvivid_Remote
979
  {
980
  $args['method']='DELETE';
981
  $args['headers']=array( 'Authorization' => 'bearer '.$this->options['token']['access_token']);
982
- $args['timeout']=10;
983
 
984
  $response = wp_remote_request( 'https://graph.microsoft.com/v1.0/me/drive/items/'.$id,$args);
985
 
@@ -1003,7 +1008,7 @@ class WPvivid_one_drive extends WPvivid_Remote
1003
  }
1004
  }
1005
 
1006
- private function remote_get($url,$header=array(),$decode=true,$timeout=10,$except_code=array())
1007
  {
1008
  if(empty($except_code))
1009
  {
@@ -1055,7 +1060,7 @@ class WPvivid_one_drive extends WPvivid_Remote
1055
  {
1056
  $args['body']=$body;
1057
  }
1058
- $args['timeout']=10;
1059
 
1060
  $response=wp_remote_post($url,$args);
1061
 
45
  {
46
  if(empty($options))
47
  {
48
+ add_action('plugins_loaded', array($this, 'plugins_loaded'));
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
  else
51
  {
53
  }
54
  }
55
 
56
+ public function plugins_loaded()
57
+ {
58
+ if(!defined('WPVIVID_INIT_STORAGE_TAB_ONE_DRIVE'))
59
+ {
60
+ add_action('init', array($this, 'handle_auth_actions'));
61
+ add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_one_drive'), 10);
62
+ add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_one_drive'), 10);
63
+ add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_one_drive'), 10);
64
+ add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_one_drive'),10);
65
+ add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_one_drive'),10,2);
66
+ add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_one_drive'),10);
67
+ add_filter('wpvivid_get_root_path',array($this,'wpvivid_get_root_path_one_drive'),10);
68
+ add_filter('wpvivid_pre_add_remote',array($this, 'pre_add_remote'),10,2);
69
+ define('WPVIVID_INIT_STORAGE_TAB_ONE_DRIVE',1);
70
+ }
71
+ }
72
+
73
  public function pre_add_remote($remote,$id)
74
  {
75
  if($remote['type']==WPVIVID_REMOTE_ONEDRIVE)
127
  return;
128
  }
129
 
130
+ global $wpvivid_plugin;
131
 
132
  $remote_options['type'] = WPVIVID_REMOTE_ONEDRIVE;
133
  //$token = $_POST['token'];
142
  $remote_options['name'] = $_GET['name'];
143
  $remote_options['default'] = $_GET['default'];
144
  $remote_options['path'] = WPVIVID_ONEDRIVE_DEFAULT_FOLDER;
145
+ $ret = $wpvivid_plugin->remote_collection->add_remote($remote_options);
146
 
147
  if ($ret['result'] == 'success') {
148
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive&result=success');
213
  return;
214
  }
215
 
216
+ global $wpvivid_plugin;
217
 
218
  $remote_options['type'] = WPVIVID_REMOTE_ONEDRIVE;
219
  //$token = $_GET['token'];
226
  $remote_options['token']['expires']=time()+$_POST['expires_in'];
227
  $remote_options['name'] = $_GET['name'];
228
  $remote_options['path'] = WPVIVID_ONEDRIVE_DEFAULT_FOLDER;
229
+ $ret = $wpvivid_plugin->remote_collection->update_remote($_GET['id'], $remote_options);
230
 
231
  if ($ret['result'] == 'success') {
232
  header('Location: ' . admin_url() . 'admin.php?page=' . WPVIVID_PLUGIN_SLUG . '&action=wpvivid_one_drive_update&result=success');
261
  _e('<div class="notice notice-success is-dismissible"><p>You have authenticated the Microsoft OneDrive account as your remote storage.</p></div>');
262
  }
263
  public function wpvivid_show_notice_add_onedrive_error(){
264
+ global $wpvivid_plugin;
265
+ $wpvivid_plugin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Add OneDrive Remote');
266
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
267
  }
268
  public function wpvivid_show_notice_edit_onedrive_success(){
269
  _e('<div class="notice notice-success is-dismissible"><p>You have successfully updated the storage alias.</p></div>');
270
  }
271
  public function wpvivid_show_notice_edit_onedrive_error(){
272
+ global $wpvivid_plugin;
273
+ $wpvivid_plugin->wpvivid_handle_remote_storage_error($_GET['resp_msg'], 'Update OneDrive Remote');
274
  _e('<div class="notice notice-error"><p>'.$_GET['resp_msg'].'</p></div>');
275
  }
276
 
422
 
423
  public function upload($task_id, $files, $callback = '')
424
  {
425
+ global $wpvivid_plugin;
426
 
427
  if($this->need_refresh())
428
  {
429
+ $wpvivid_plugin->wpvivid_log->WriteLog('The token expired and will go to the server to refresh the token.','notice');
430
  $ret=$this->refresh_token();
431
  if($ret['result']===WPVIVID_FAILED)
432
  {
435
  }
436
 
437
  $path=$this->options['path'];
438
+ $wpvivid_plugin->wpvivid_log->WriteLog('Check upload folder '.$path,'notice');
439
  $ret=$this->check_folder($path);
440
 
441
  if($ret['result']===WPVIVID_FAILED)
470
 
471
  if(!file_exists($file))
472
  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.');
473
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
474
  $result=$this->_upload($task_id, $file,$callback);
475
  if($result['result'] !==WPVIVID_SUCCESS)
476
  {
517
  $this->current_file_name = $file['file_name'];
518
  $this->current_file_size = $file['size'];
519
 
520
+ global $wpvivid_plugin;
521
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Remote type: OneDrive.','notice');
522
  if ($this->need_refresh()) {
523
  $ret = $this->refresh_token();
524
  if ($ret['result'] === WPVIVID_FAILED) {
534
  }
535
 
536
  $file_path = $local_path . $file['file_name'];
537
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Create local file.','notice');
538
  $fh = fopen($file_path, 'a');
539
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
540
  $downloaded_start = filesize($file_path);
541
  $url = 'https://graph.microsoft.com/v1.0/me/drive/root:/' . $this->options['path'] . '/' . $file['file_name'] . ':/content';
542
  $download_size = WPVIVID_ONEDRIVE_DOWNLOAD_SIZE;
571
 
572
  private function download_loop($url,&$downloaded_start,$download_size,$file_size,$retry_count=0)
573
  {
574
+ global $wpvivid_plugin;
575
 
576
  $downloaded_end=min($downloaded_start+$download_size-1,$file_size-1);
577
  $headers['Range']="bytes=$downloaded_start-$downloaded_end";
702
 
703
  private function _upload($task_id,$local_file,$callback)
704
  {
705
+ global $wpvivid_plugin;
706
 
707
  $this -> current_file_size = filesize($local_file);
708
  $this -> current_file_name = basename($local_file);
709
 
710
+ $wpvivid_plugin->wpvivid_log->WriteLog('Check if the server already has the same name file.','notice');
711
 
712
  $this->delete_file_by_name($this->options['path'],basename($local_file));
713
 
716
  //small file
717
  if($file_size<1024*1024*4)
718
  {
719
+ $wpvivid_plugin->wpvivid_log->WriteLog('Uploaded files are less than 4M.','notice');
720
  $ret=$this->upload_small_file($local_file,$task_id);
721
  return $ret;
722
  }
723
  else
724
  {
725
+ $wpvivid_plugin->wpvivid_log->WriteLog('Creating upload session.','notice');
726
  //big file
727
  $ret=$this->create_upload_session(basename($local_file));
728
 
730
  {
731
  return $ret;
732
  }
733
+ $wpvivid_plugin->wpvivid_log->WriteLog('Ready to start uploading files.','notice');
734
  $ret=$this->upload_resume($ret['session_url'],$local_file,$task_id,$callback);
735
 
736
  return $ret;
739
 
740
  private function upload_small_file($file,$task_id)
741
  {
742
+ global $wpvivid_plugin;
743
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_ONEDRIVE);
744
 
745
  $path=$this->options['path'].'/'.basename($file);
757
  if(!is_wp_error($response) && ($response['response']['code'] == 200||$response['response']['code'] == 201))
758
  {
759
  $upload_job['job_data'][basename($file)]['uploaded']=1;
760
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
761
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_ONEDRIVE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
762
  return array('result' =>WPVIVID_SUCCESS);
763
  }
779
 
780
  private function upload_resume($session_url,$file,$task_id,$callback)
781
  {
782
+ global $wpvivid_plugin;
783
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_ONEDRIVE);
784
 
785
  $offset=0;
824
 
825
  fclose($handle);
826
  $upload_job['job_data'][basename($file)]['uploaded']=1;
827
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
828
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_ONEDRIVE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
829
  return array('result' =>WPVIVID_SUCCESS);
830
  }
877
 
878
  curl_setopt_array($curl, $options);
879
 
880
+ global $wpvivid_plugin;
881
 
882
  $response=curl_exec($curl);
883
 
984
  {
985
  $args['method']='DELETE';
986
  $args['headers']=array( 'Authorization' => 'bearer '.$this->options['token']['access_token']);
987
+ $args['timeout']=15;
988
 
989
  $response = wp_remote_request( 'https://graph.microsoft.com/v1.0/me/drive/items/'.$id,$args);
990
 
1008
  }
1009
  }
1010
 
1011
+ private function remote_get($url,$header=array(),$decode=true,$timeout=15,$except_code=array())
1012
  {
1013
  if(empty($except_code))
1014
  {
1060
  {
1061
  $args['body']=$body;
1062
  }
1063
+ $args['timeout']=15;
1064
 
1065
  $response=wp_remote_post($url,$args);
1066
 
includes/customclass/class-wpvivid-s3compat.php CHANGED
@@ -23,17 +23,22 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
23
  public function __construct($options = array())
24
  {
25
  if(empty($options)){
26
- add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_s3compat'), 11);
27
- add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_s3compat'), 11);
28
- add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_s3compat'), 11);
29
- add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_s3compat'),11);
30
- add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_s3compat'),10,2);
31
- add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_s3compat'),10);
32
  }else{
33
  $this -> options = $options;
34
  }
35
  }
36
 
 
 
 
 
 
 
 
 
 
37
  public function getClient(){
38
  $res = $this -> compare_php_version();
39
  if($res['result'] == WPVIVID_FAILED)
@@ -117,7 +122,7 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
117
 
118
  public function upload($task_id, $files, $callback = '')
119
  {
120
- global $wpvivid_pulgin;
121
  $s3compat = $this -> getClient();
122
  if(is_array($s3compat) && $s3compat['result'] == WPVIVID_FAILED){
123
  return $s3compat;
@@ -145,17 +150,17 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
145
  }
146
  $this -> last_time = time();
147
  $this -> last_size = 0;
148
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
149
  if(!file_exists($file)){
150
- $wpvivid_pulgin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
151
  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.');
152
  }
153
  $result = $this -> _put($task_id,$s3compat,$file,$callback);
154
  if($result['result'] !==WPVIVID_SUCCESS){
155
- $wpvivid_pulgin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
156
  return $result;
157
  }
158
- $wpvivid_pulgin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
159
  }
160
  return array('result' => WPVIVID_SUCCESS);
161
  }
@@ -259,21 +264,21 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
259
  public function download($file, $local_path, $callback = '')
260
  {
261
  try {
262
- global $wpvivid_pulgin;
263
  $this->current_file_name = $file['file_name'];
264
  $this->current_file_size = $file['size'];
265
  $file_path = trailingslashit($local_path) . $this->current_file_name;
266
  $file_md5 = $file['md5'];
267
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Get s3compat client.','notice');
268
  $s3compat = $this->getClient();
269
  if (is_array($s3compat) && $s3compat['result'] == WPVIVID_FAILED) {
270
  return $s3compat;
271
  }
272
 
273
  $start_offset = file_exists($file_path) ? filesize($file_path) : 0;
274
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Create local file.','notice');
275
  $fh = fopen($file_path, 'a');
276
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
277
  while ($start_offset < $this->current_file_size) {
278
  $last_byte = min($start_offset + $this->download_chunk_size - 1, $this->current_file_size - 1);
279
  $range = "bytes=$start_offset-$last_byte";
@@ -297,7 +302,7 @@ class Wpvivid_S3Compat extends WPvivid_Remote{
297
  @fclose($fh);
298
 
299
  if(filesize($file_path) == $file['size']){
300
- if($wpvivid_pulgin->wpvivid_check_zip_valid()) {
301
  $res = TRUE;
302
  }
303
  else{
23
  public function __construct($options = array())
24
  {
25
  if(empty($options)){
26
+ add_action('plugins_loaded', array($this, 'plugins_loaded'));
27
+
 
 
 
 
28
  }else{
29
  $this -> options = $options;
30
  }
31
  }
32
 
33
+ public function plugins_loaded(){
34
+ add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_s3compat'), 11);
35
+ add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_s3compat'), 11);
36
+ add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_s3compat'), 11);
37
+ add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_s3compat'),11);
38
+ add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_s3compat'),10,2);
39
+ add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_s3compat'),10);
40
+ }
41
+
42
  public function getClient(){
43
  $res = $this -> compare_php_version();
44
  if($res['result'] == WPVIVID_FAILED)
122
 
123
  public function upload($task_id, $files, $callback = '')
124
  {
125
+ global $wpvivid_plugin;
126
  $s3compat = $this -> getClient();
127
  if(is_array($s3compat) && $s3compat['result'] == WPVIVID_FAILED){
128
  return $s3compat;
150
  }
151
  $this -> last_time = time();
152
  $this -> last_size = 0;
153
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
154
  if(!file_exists($file)){
155
+ $wpvivid_plugin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
156
  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.');
157
  }
158
  $result = $this -> _put($task_id,$s3compat,$file,$callback);
159
  if($result['result'] !==WPVIVID_SUCCESS){
160
+ $wpvivid_plugin->wpvivid_log->WriteLog('Uploading '.basename($file).' failed.','notice');
161
  return $result;
162
  }
163
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
164
  }
165
  return array('result' => WPVIVID_SUCCESS);
166
  }
264
  public function download($file, $local_path, $callback = '')
265
  {
266
  try {
267
+ global $wpvivid_plugin;
268
  $this->current_file_name = $file['file_name'];
269
  $this->current_file_size = $file['size'];
270
  $file_path = trailingslashit($local_path) . $this->current_file_name;
271
  $file_md5 = $file['md5'];
272
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Get s3compat client.','notice');
273
  $s3compat = $this->getClient();
274
  if (is_array($s3compat) && $s3compat['result'] == WPVIVID_FAILED) {
275
  return $s3compat;
276
  }
277
 
278
  $start_offset = file_exists($file_path) ? filesize($file_path) : 0;
279
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Create local file.','notice');
280
  $fh = fopen($file_path, 'a');
281
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
282
  while ($start_offset < $this->current_file_size) {
283
  $last_byte = min($start_offset + $this->download_chunk_size - 1, $this->current_file_size - 1);
284
  $range = "bytes=$start_offset-$last_byte";
302
  @fclose($fh);
303
 
304
  if(filesize($file_path) == $file['size']){
305
+ if($wpvivid_plugin->wpvivid_check_zip_valid()) {
306
  $res = TRUE;
307
  }
308
  else{
includes/customclass/class-wpvivid-send-to-site.php CHANGED
@@ -83,8 +83,8 @@ class WPvivid_Send_to_site extends WPvivid_Remote
83
  {
84
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
85
 
86
- global $wpvivid_pulgin;
87
- $wpvivid_pulgin->wpvivid_log->WriteLog('Connect site ','notice');
88
  $ret=$this->connect_site($task_id);
89
  if($ret['result']==WPVIVID_FAILED)
90
  {
@@ -97,7 +97,6 @@ class WPvivid_Send_to_site extends WPvivid_Remote
97
  return $ret;
98
  }
99
  }
100
-
101
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE);
102
  if(empty($upload_job))
103
  {
@@ -143,8 +142,8 @@ class WPvivid_Send_to_site extends WPvivid_Remote
143
 
144
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE);
145
 
146
- global $wpvivid_pulgin;
147
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
148
 
149
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,WPVIVID_UPLOAD_UNDO,'Start uploading '.basename($file).'.',$upload_job['job_data']);
150
 
@@ -154,13 +153,13 @@ class WPvivid_Send_to_site extends WPvivid_Remote
154
 
155
  $ret=$this->get_file_status($task_id,basename($file),$file_size,$md5);
156
 
157
- $wpvivid_pulgin->wpvivid_log->WriteLog(json_encode($ret),'notice');
158
 
159
  if($ret['result']==WPVIVID_SUCCESS)
160
  {
161
  if($ret['file_status']['status']=='finished')
162
  {
163
- $wpvivid_pulgin->wpvivid_log->WriteLog('upload finished','notice');
164
  fclose($handle);
165
  $upload_job['job_data'][basename($file)]['uploaded']=1;
166
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
@@ -220,6 +219,14 @@ class WPvivid_Send_to_site extends WPvivid_Remote
220
  {
221
  if($retry_count>3)
222
  {
 
 
 
 
 
 
 
 
223
  return $ret;
224
  }
225
  else
@@ -228,22 +235,22 @@ class WPvivid_Send_to_site extends WPvivid_Remote
228
  {
229
  if($ret['http_code']==413)
230
  {
231
- $wpvivid_pulgin->wpvivid_log->WriteLog('Upload chunk too Large:'.size_format($offset),'warning');
232
  }
233
  else
234
  {
235
- $wpvivid_pulgin->wpvivid_log->WriteLog('upload file error offset:'.size_format($offset).' http error:'.$ret['http_code'],'warning');
236
  }
237
  }
238
  else
239
  {
240
- $wpvivid_pulgin->wpvivid_log->WriteLog('upload file error offset:'.size_format($offset).' error:'.$ret['error'],'warning');
241
  }
242
  $retry_count++;
243
  }
244
  }
245
  }
246
- $wpvivid_pulgin->wpvivid_log->WriteLog('upload finished','notice');
247
  fclose($handle);
248
  $upload_job['job_data'][basename($file)]['uploaded']=1;
249
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
@@ -275,7 +282,7 @@ class WPvivid_Send_to_site extends WPvivid_Remote
275
  {
276
  if($response['response']['code']==200)
277
  {
278
- global $wpvivid_pulgin;
279
 
280
  $res=json_decode($response['body'],1);
281
  if($res!=null)
@@ -341,12 +348,12 @@ class WPvivid_Send_to_site extends WPvivid_Remote
341
  $args['body']=array('wpvivid_content'=>$data,'wpvivid_action'=>'send_to_site');
342
  $args['timeout']=30;
343
 
344
- global $wpvivid_pulgin;
345
- $wpvivid_pulgin->wpvivid_log->WriteLog('send chunk '.basename($file_name).' offset '.$offset,'notice');
346
 
347
  $response=wp_remote_post($this->options['url'],$args);
348
 
349
- $wpvivid_pulgin->wpvivid_log->WriteLog('finished send chunk','notice');
350
 
351
  if ( is_wp_error( $response ) )
352
  {
@@ -370,7 +377,7 @@ class WPvivid_Send_to_site extends WPvivid_Remote
370
  {
371
  $ret['result']=WPVIVID_FAILED;
372
  $ret['error']= $res['error'];
373
- $wpvivid_pulgin->wpvivid_log->WriteLog( $ret['error'],'notice');
374
  }
375
 
376
  }
@@ -378,7 +385,7 @@ class WPvivid_Send_to_site extends WPvivid_Remote
378
  {
379
  $ret['result']=WPVIVID_FAILED;
380
  $ret['error']= 'Failed to parse returned data, chunk transfer failed.';
381
- $wpvivid_pulgin->wpvivid_log->WriteLog('error send chunk failed','notice');
382
  }
383
  }
384
  else
@@ -480,22 +487,22 @@ class WPvivid_Send_to_site extends WPvivid_Remote
480
  }
481
 
482
  if (isset($params['backup_id'])) {
483
- if (WPvivid_Backuplist::get_backuplist_by_key($params['backup_id']) !== false) {
484
  $ret['result'] = WPVIVID_FAILED;
485
  $ret['error'] = 'The uploading backup already exists in Backups list.';
486
  echo json_encode($ret);
487
  } else {
488
- global $wpvivid_pulgin;
489
- $wpvivid_pulgin->wpvivid_log = new WPvivid_Log();
490
- if (!file_exists($wpvivid_pulgin->wpvivid_log->GetSaveLogFolder() . $params['backup_id'] . '_backup_log.txt')) {
491
- $wpvivid_pulgin->wpvivid_log->CreateLogFile($params['backup_id'] . '_backup', 'no_folder', 'transfer');
492
- $wpvivid_pulgin->wpvivid_log->WriteLogHander();
493
  } else {
494
- $wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'] . '_backup', 'no_folder');
495
  }
496
 
497
 
498
- $wpvivid_pulgin->wpvivid_log->WriteLog('Connect site success', 'notice');
499
  $ret['result'] = WPVIVID_SUCCESS;
500
  echo json_encode($ret);
501
  }
@@ -524,8 +531,8 @@ class WPvivid_Send_to_site extends WPvivid_Remote
524
  {
525
  if(isset($_POST['wpvivid_content']))
526
  {
527
- global $wpvivid_pulgin;
528
- $wpvivid_pulgin->wpvivid_log=new WPvivid_Log();
529
 
530
  $default=array();
531
  $option=get_option('wpvivid_api_token',$default);
@@ -557,8 +564,8 @@ class WPvivid_Send_to_site extends WPvivid_Remote
557
  die();
558
  }
559
 
560
- $wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'].'_backup','no_folder','backup');
561
- $wpvivid_pulgin->wpvivid_log->WriteLog('start upload.','notice');
562
  $dir=WPvivid_Setting::get_backupdir();
563
 
564
  $file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.str_replace('wpvivid','wpvivid_temp',$params['name']);
@@ -571,22 +578,22 @@ class WPvivid_Send_to_site extends WPvivid_Remote
571
 
572
  $handle=fopen($file_path,'rb+');
573
  $offset=$params['offset'];
574
- $wpvivid_pulgin->wpvivid_log->WriteLog('Write file:'.$file_path.' offset:'.size_format($offset),'notice');
575
  if($offset)
576
  {
577
  if(fseek($handle, $offset)===-1)
578
  {
579
- $wpvivid_pulgin->wpvivid_log->WriteLog('Seek file offset failed:'.size_format($offset),'notice');
580
  }
581
  }
582
 
583
  if (fwrite($handle,base64_decode($params['data'])) === FALSE)
584
  {
585
- $wpvivid_pulgin->wpvivid_log->WriteLog('Write file :'.$file_path.' failed size:'.filesize($file_path),'notice');
586
  }
587
  else
588
  {
589
- $wpvivid_pulgin->wpvivid_log->WriteLog('Write file:'.$file_path.' success size:'.filesize($file_path),'notice');
590
  }
591
 
592
  fclose($handle);
@@ -596,20 +603,20 @@ class WPvivid_Send_to_site extends WPvivid_Remote
596
  {
597
  if (md5_file($file_path) == $params['md5'])
598
  {
599
- $wpvivid_pulgin->wpvivid_log->WriteLog('rename temp file:'.$file_path.' to new name:'.WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name'],'notice');
600
  rename($file_path,WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name']);
601
 
602
  $ret['result']=WPVIVID_SUCCESS;
603
  $ret['op']='finished';
604
  } else {
605
- $wpvivid_pulgin->wpvivid_log->WriteLog('file md5 not match','notice');
606
  $ret['result']=WPVIVID_FAILED;
607
  $ret['error']='File md5 is not matched.';
608
  }
609
  }
610
  else
611
  {
612
- $wpvivid_pulgin->wpvivid_log->WriteLog('continue size:'.filesize($file_path).' size1:'.$params['file_size'],'notice');
613
  $ret['result']=WPVIVID_SUCCESS;
614
  $ret['op']='continue';
615
  //
@@ -622,7 +629,7 @@ class WPvivid_Send_to_site extends WPvivid_Remote
622
  {
623
  $ret['result']=WPVIVID_FAILED;
624
  $ret['error']=$e->getMessage();
625
- //$wpvivid_pulgin->wpvivid_log->WriteLog($e->getMessage(),'error');
626
  echo json_encode($ret);
627
  die();
628
  }
@@ -662,17 +669,17 @@ class WPvivid_Send_to_site extends WPvivid_Remote
662
  die();
663
  }
664
 
665
- global $wpvivid_pulgin;
666
- $wpvivid_pulgin->wpvivid_log = new WPvivid_Log();
667
- $wpvivid_pulgin->wpvivid_log->OpenLogFile($params['backup_id'] . '_backup', 'no_folder', 'backup');
668
- $wpvivid_pulgin->wpvivid_log->WriteLog('upload finished', 'notice');
669
 
670
  if (isset($params['backup']) && isset($params['backup_id'])) {
671
  $params['backup']['type'] = 'Migration';
672
  $params['backup']['local']['path']=WPvivid_Setting::get_backupdir();
673
  $list = WPvivid_Setting::get_option('wpvivid_backup_list');
674
  $list[$params['backup_id']] = $params['backup'];
675
- $list[$params['backup_id']]['log'] = $wpvivid_pulgin->wpvivid_log->log_file;
676
  WPvivid_Setting::update_option('wpvivid_backup_list', $list);
677
  }
678
 
@@ -725,7 +732,7 @@ class WPvivid_Send_to_site extends WPvivid_Remote
725
  {
726
  if($response['response']['code']==200)
727
  {
728
- global $wpvivid_pulgin;
729
 
730
  $res=json_decode($response['body'],1);
731
  if($res!=null)
83
  {
84
  include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-crypt.php';
85
 
86
+ global $wpvivid_plugin;
87
+ $wpvivid_plugin->wpvivid_log->WriteLog('Connect site ','notice');
88
  $ret=$this->connect_site($task_id);
89
  if($ret['result']==WPVIVID_FAILED)
90
  {
97
  return $ret;
98
  }
99
  }
 
100
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE);
101
  if(empty($upload_job))
102
  {
142
 
143
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE);
144
 
145
+ global $wpvivid_plugin;
146
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
147
 
148
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,WPVIVID_UPLOAD_UNDO,'Start uploading '.basename($file).'.',$upload_job['job_data']);
149
 
153
 
154
  $ret=$this->get_file_status($task_id,basename($file),$file_size,$md5);
155
 
156
+ $wpvivid_plugin->wpvivid_log->WriteLog(json_encode($ret),'notice');
157
 
158
  if($ret['result']==WPVIVID_SUCCESS)
159
  {
160
  if($ret['file_status']['status']=='finished')
161
  {
162
+ $wpvivid_plugin->wpvivid_log->WriteLog('upload finished','notice');
163
  fclose($handle);
164
  $upload_job['job_data'][basename($file)]['uploaded']=1;
165
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
219
  {
220
  if($retry_count>3)
221
  {
222
+ if(isset($ret['http_code']))
223
+ {
224
+ if($ret['http_code']==413)
225
+ {
226
+ $ret['error']='Site migration failed. The receiving site can\'t receive the oversized data chunk. Please set the value of Chunk size to 512 KB in plugin settings. Then try again.';
227
+ }
228
+ }
229
+
230
  return $ret;
231
  }
232
  else
235
  {
236
  if($ret['http_code']==413)
237
  {
238
+ $wpvivid_plugin->wpvivid_log->WriteLog('Site migration failed. The receiving site can\'t receive the oversized data chunk. Please set the value of Chunk size to 512 KB in plugin settings. Then try again. Chunk size: '.size_format($offset),'warning');
239
  }
240
  else
241
  {
242
+ $wpvivid_plugin->wpvivid_log->WriteLog('upload file error offset:'.size_format($offset).' http error:'.$ret['http_code'],'warning');
243
  }
244
  }
245
  else
246
  {
247
+ $wpvivid_plugin->wpvivid_log->WriteLog('upload file error offset:'.size_format($offset).' error:'.$ret['error'],'warning');
248
  }
249
  $retry_count++;
250
  }
251
  }
252
  }
253
+ $wpvivid_plugin->wpvivid_log->WriteLog('upload finished','notice');
254
  fclose($handle);
255
  $upload_job['job_data'][basename($file)]['uploaded']=1;
256
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SEND_TO_SITE,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
282
  {
283
  if($response['response']['code']==200)
284
  {
285
+ global $wpvivid_plugin;
286
 
287
  $res=json_decode($response['body'],1);
288
  if($res!=null)
348
  $args['body']=array('wpvivid_content'=>$data,'wpvivid_action'=>'send_to_site');
349
  $args['timeout']=30;
350
 
351
+ global $wpvivid_plugin;
352
+ $wpvivid_plugin->wpvivid_log->WriteLog('send chunk '.basename($file_name).' offset '.$offset,'notice');
353
 
354
  $response=wp_remote_post($this->options['url'],$args);
355
 
356
+ $wpvivid_plugin->wpvivid_log->WriteLog('finished send chunk','notice');
357
 
358
  if ( is_wp_error( $response ) )
359
  {
377
  {
378
  $ret['result']=WPVIVID_FAILED;
379
  $ret['error']= $res['error'];
380
+ $wpvivid_plugin->wpvivid_log->WriteLog( $ret['error'],'notice');
381
  }
382
 
383
  }
385
  {
386
  $ret['result']=WPVIVID_FAILED;
387
  $ret['error']= 'Failed to parse returned data, chunk transfer failed.';
388
+ $wpvivid_plugin->wpvivid_log->WriteLog('error send chunk failed','notice');
389
  }
390
  }
391
  else
487
  }
488
 
489
  if (isset($params['backup_id'])) {
490
+ if (WPvivid_Backuplist::get_backup_by_id($params['backup_id']) !== false) {
491
  $ret['result'] = WPVIVID_FAILED;
492
  $ret['error'] = 'The uploading backup already exists in Backups list.';
493
  echo json_encode($ret);
494
  } else {
495
+ global $wpvivid_plugin;
496
+ $wpvivid_plugin->wpvivid_log = new WPvivid_Log();
497
+ if (!file_exists($wpvivid_plugin->wpvivid_log->GetSaveLogFolder() . $params['backup_id'] . '_backup_log.txt')) {
498
+ $wpvivid_plugin->wpvivid_log->CreateLogFile($params['backup_id'] . '_backup', 'no_folder', 'transfer');
499
+ $wpvivid_plugin->wpvivid_log->WriteLogHander();
500
  } else {
501
+ $wpvivid_plugin->wpvivid_log->OpenLogFile($params['backup_id'] . '_backup', 'no_folder');
502
  }
503
 
504
 
505
+ $wpvivid_plugin->wpvivid_log->WriteLog('Connect site success', 'notice');
506
  $ret['result'] = WPVIVID_SUCCESS;
507
  echo json_encode($ret);
508
  }
531
  {
532
  if(isset($_POST['wpvivid_content']))
533
  {
534
+ global $wpvivid_plugin;
535
+ $wpvivid_plugin->wpvivid_log=new WPvivid_Log();
536
 
537
  $default=array();
538
  $option=get_option('wpvivid_api_token',$default);
564
  die();
565
  }
566
 
567
+ $wpvivid_plugin->wpvivid_log->OpenLogFile($params['backup_id'].'_backup','no_folder','backup');
568
+ $wpvivid_plugin->wpvivid_log->WriteLog('start upload.','notice');
569
  $dir=WPvivid_Setting::get_backupdir();
570
 
571
  $file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.str_replace('wpvivid','wpvivid_temp',$params['name']);
578
 
579
  $handle=fopen($file_path,'rb+');
580
  $offset=$params['offset'];
581
+ $wpvivid_plugin->wpvivid_log->WriteLog('Write file:'.$file_path.' offset:'.size_format($offset),'notice');
582
  if($offset)
583
  {
584
  if(fseek($handle, $offset)===-1)
585
  {
586
+ $wpvivid_plugin->wpvivid_log->WriteLog('Seek file offset failed:'.size_format($offset),'notice');
587
  }
588
  }
589
 
590
  if (fwrite($handle,base64_decode($params['data'])) === FALSE)
591
  {
592
+ $wpvivid_plugin->wpvivid_log->WriteLog('Write file :'.$file_path.' failed size:'.filesize($file_path),'notice');
593
  }
594
  else
595
  {
596
+ $wpvivid_plugin->wpvivid_log->WriteLog('Write file:'.$file_path.' success size:'.filesize($file_path),'notice');
597
  }
598
 
599
  fclose($handle);
603
  {
604
  if (md5_file($file_path) == $params['md5'])
605
  {
606
+ $wpvivid_plugin->wpvivid_log->WriteLog('rename temp file:'.$file_path.' to new name:'.WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name'],'notice');
607
  rename($file_path,WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$dir.DIRECTORY_SEPARATOR.$params['name']);
608
 
609
  $ret['result']=WPVIVID_SUCCESS;
610
  $ret['op']='finished';
611
  } else {
612
+ $wpvivid_plugin->wpvivid_log->WriteLog('file md5 not match','notice');
613
  $ret['result']=WPVIVID_FAILED;
614
  $ret['error']='File md5 is not matched.';
615
  }
616
  }
617
  else
618
  {
619
+ $wpvivid_plugin->wpvivid_log->WriteLog('continue size:'.filesize($file_path).' size1:'.$params['file_size'],'notice');
620
  $ret['result']=WPVIVID_SUCCESS;
621
  $ret['op']='continue';
622
  //
629
  {
630
  $ret['result']=WPVIVID_FAILED;
631
  $ret['error']=$e->getMessage();
632
+ //$wpvivid_plugin->wpvivid_log->WriteLog($e->getMessage(),'error');
633
  echo json_encode($ret);
634
  die();
635
  }
669
  die();
670
  }
671
 
672
+ global $wpvivid_plugin;
673
+ $wpvivid_plugin->wpvivid_log = new WPvivid_Log();
674
+ $wpvivid_plugin->wpvivid_log->OpenLogFile($params['backup_id'] . '_backup', 'no_folder', 'backup');
675
+ $wpvivid_plugin->wpvivid_log->WriteLog('upload finished', 'notice');
676
 
677
  if (isset($params['backup']) && isset($params['backup_id'])) {
678
  $params['backup']['type'] = 'Migration';
679
  $params['backup']['local']['path']=WPvivid_Setting::get_backupdir();
680
  $list = WPvivid_Setting::get_option('wpvivid_backup_list');
681
  $list[$params['backup_id']] = $params['backup'];
682
+ $list[$params['backup_id']]['log'] = $wpvivid_plugin->wpvivid_log->log_file;
683
  WPvivid_Setting::update_option('wpvivid_backup_list', $list);
684
  }
685
 
732
  {
733
  if($response['response']['code']==200)
734
  {
735
+ global $wpvivid_plugin;
736
 
737
  $res=json_decode($response['body'],1);
738
  if($res!=null)
includes/customclass/class-wpvivid-sftpclass.php CHANGED
@@ -18,12 +18,8 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
18
  {
19
  if(empty($options))
20
  {
21
- add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_sftp'), 10);
22
- add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_sftp'), 10);
23
- add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_sftp'), 10);
24
- add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_sftp'),10);
25
- add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_sftp'),10,2);
26
- add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_sftp'),10);
27
  }
28
  else
29
  {
@@ -31,6 +27,15 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
31
  }
32
  }
33
 
 
 
 
 
 
 
 
 
 
34
  public function wpvivid_add_storage_tab_sftp()
35
  {
36
  ?>
@@ -275,7 +280,7 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
275
 
276
  public function upload($task_id,$files,$callback='')
277
  {
278
- global $wpvivid_pulgin;
279
  $this -> callback = $callback;
280
  if(empty($this->options['port']))
281
  $this->options['port'] = 22;
@@ -300,14 +305,14 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
300
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SFTP);
301
  }
302
 
303
- $wpvivid_pulgin->wpvivid_log->WriteLog('Connecting to server '.$host,'notice');
304
  $conn = $this->do_connect($host,$username,$password,$port);
305
 
306
  if(is_array($conn) && $conn['result'] ==WPVIVID_FAILED)
307
  {
308
  return $conn;
309
  }
310
- $wpvivid_pulgin->wpvivid_log->WriteLog('chdir '.$path,'notice');
311
  $str = $this->do_chdir($conn,$path);
312
  if($str['result'] == WPVIVID_FAILED)
313
  return $str;
@@ -319,14 +324,14 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
319
  if($upload_job['job_data'][basename($file)]['uploaded']==1)
320
  continue;
321
  }
322
- $wpvivid_pulgin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
323
  $this -> last_time = time();
324
  $this -> last_size = 0;
325
 
326
  if(!file_exists($file))
327
  return array('result'=>WPVIVID_FAILED,'error'=>$file.' not found. The file might has been moved, renamed or deleted. Please back it up again.');
328
 
329
- $wpvivid_pulgin->set_time_limit($task_id);
330
 
331
  for($i =0;$i <WPVIVID_REMOTE_CONNECT_RETRY_TIMES;$i ++)
332
  {
@@ -340,7 +345,7 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
340
 
341
  if($result)
342
  {
343
- $wpvivid_pulgin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
344
  $upload_job['job_data'][basename($file)]['uploaded']=1;
345
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SFTP,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
346
  break;
@@ -361,7 +366,7 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
361
  public function download($file,$local_path,$callback = '')
362
  {
363
  try {
364
- global $wpvivid_pulgin;
365
  $this->callback = $callback;
366
  $this->current_file_name = $file['file_name'];
367
  $this->current_file_size = $file['size'];
@@ -376,13 +381,13 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
376
  $md5 = $file['md5'];
377
  $remote_file_name = trailingslashit($path) . $file['file_name'];
378
 
379
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Connecting SFTP server.','notice');
380
  $conn = $this->do_connect($host, $username, $password, $port);
381
  $progress = 0;
382
  if (!is_subclass_of($conn, 'Net_SSH2')) {
383
  return $conn;
384
  }
385
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Create local file.','notice');
386
  $local_file = fopen($local_path, 'ab');
387
  if (!$local_file) {
388
  return array('result' => WPVIVID_FAILED, 'error' => 'Unable to create the local file. Please make sure the folder is writable and try again.');
@@ -391,12 +396,12 @@ class WPvivid_SFTPClass extends WPvivid_Remote{
391
  $offset = $stat['size'];
392
  $progress = floor(($offset / $file_size) * 100);
393
 
394
- $wpvivid_pulgin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
395
  $result = $conn->get($remote_file_name, $local_file, $offset, -1, array($this, 'download_callback'));
396
  @fclose($local_file);
397
 
398
  if(filesize($local_path) == $file['size']){
399
- if($wpvivid_pulgin->wpvivid_check_zip_valid()) {
400
  $res = TRUE;
401
  }
402
  else{
18
  {
19
  if(empty($options))
20
  {
21
+ add_action('plugins_loaded', array($this, 'plugins_loaded'));
22
+
 
 
 
 
23
  }
24
  else
25
  {
27
  }
28
  }
29
 
30
+ public function plugins_loaded(){
31
+ add_action('wpvivid_add_storage_tab',array($this,'wpvivid_add_storage_tab_sftp'), 10);
32
+ add_action('wpvivid_add_storage_page',array($this,'wpvivid_add_storage_page_sftp'), 10);
33
+ add_action('wpvivid_edit_remote_page',array($this,'wpvivid_edit_storage_page_sftp'), 10);
34
+ add_filter('wpvivid_remote_pic',array($this,'wpvivid_remote_pic_sftp'),10);
35
+ add_filter('wpvivid_get_out_of_date_remote',array($this,'wpvivid_get_out_of_date_sftp'),10,2);
36
+ add_filter('wpvivid_storage_provider_tran',array($this,'wpvivid_storage_provider_sftp'),10);
37
+ }
38
+
39
  public function wpvivid_add_storage_tab_sftp()
40
  {
41
  ?>
280
 
281
  public function upload($task_id,$files,$callback='')
282
  {
283
+ global $wpvivid_plugin;
284
  $this -> callback = $callback;
285
  if(empty($this->options['port']))
286
  $this->options['port'] = 22;
305
  $upload_job=WPvivid_taskmanager::get_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SFTP);
306
  }
307
 
308
+ $wpvivid_plugin->wpvivid_log->WriteLog('Connecting to server '.$host,'notice');
309
  $conn = $this->do_connect($host,$username,$password,$port);
310
 
311
  if(is_array($conn) && $conn['result'] ==WPVIVID_FAILED)
312
  {
313
  return $conn;
314
  }
315
+ $wpvivid_plugin->wpvivid_log->WriteLog('chdir '.$path,'notice');
316
  $str = $this->do_chdir($conn,$path);
317
  if($str['result'] == WPVIVID_FAILED)
318
  return $str;
324
  if($upload_job['job_data'][basename($file)]['uploaded']==1)
325
  continue;
326
  }
327
+ $wpvivid_plugin->wpvivid_log->WriteLog('Start uploading '.basename($file),'notice');
328
  $this -> last_time = time();
329
  $this -> last_size = 0;
330
 
331
  if(!file_exists($file))
332
  return array('result'=>WPVIVID_FAILED,'error'=>$file.' not found. The file might has been moved, renamed or deleted. Please back it up again.');
333
 
334
+ $wpvivid_plugin->set_time_limit($task_id);
335
 
336
  for($i =0;$i <WPVIVID_REMOTE_CONNECT_RETRY_TIMES;$i ++)
337
  {
345
 
346
  if($result)
347
  {
348
+ $wpvivid_plugin->wpvivid_log->WriteLog('Finished uploading '.basename($file),'notice');
349
  $upload_job['job_data'][basename($file)]['uploaded']=1;
350
  WPvivid_taskmanager::update_backup_sub_task_progress($task_id,'upload',WPVIVID_REMOTE_SFTP,WPVIVID_UPLOAD_SUCCESS,'Uploading '.basename($file).' completed.',$upload_job['job_data']);
351
  break;
366
  public function download($file,$local_path,$callback = '')
367
  {
368
  try {
369
+ global $wpvivid_plugin;
370
  $this->callback = $callback;
371
  $this->current_file_name = $file['file_name'];
372
  $this->current_file_size = $file['size'];
381
  $md5 = $file['md5'];
382
  $remote_file_name = trailingslashit($path) . $file['file_name'];
383
 
384
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Connecting SFTP server.','notice');
385
  $conn = $this->do_connect($host, $username, $password, $port);
386
  $progress = 0;
387
  if (!is_subclass_of($conn, 'Net_SSH2')) {
388
  return $conn;
389
  }
390
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Create local file.','notice');
391
  $local_file = fopen($local_path, 'ab');
392
  if (!$local_file) {
393
  return array('result' => WPVIVID_FAILED, 'error' => 'Unable to create the local file. Please make sure the folder is writable and try again.');
396
  $offset = $stat['size'];
397
  $progress = floor(($offset / $file_size) * 100);
398
 
399
+ $wpvivid_plugin->wpvivid_download_log->WriteLog('Downloading file ' . $file['file_name'] . ', Size: ' . $file['size'] ,'notice');
400
  $result = $conn->get($remote_file_name, $local_file, $offset, -1, array($this, 'download_callback'));
401
  @fclose($local_file);
402
 
403
  if(filesize($local_path) == $file['size']){
404
+ if($wpvivid_plugin->wpvivid_check_zip_valid()) {
405
  $res = TRUE;
406
  }
407
  else{
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: move, clone, migrate, copy, backup, restore, auto backup, cloud backup
4
  Requires at least: 4.5
5
  Tested up to: 5.2
6
  Requires PHP: 5.3
7
- Stable tag: 0.9.22
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
@@ -146,6 +146,11 @@ Yes, we do. Here are the guides for [copying your site to a new host](https://wp
146
  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).
147
 
148
  == Changelog ==
 
 
 
 
 
149
  = 0.9.22 =
150
  - Fixed: Backup created in web hosting/shared hosting optimization mode was incomplete in some cases.
151
  - Fixed: Backup actually failed but was reported as a success in some cases.
4
  Requires at least: 4.5
5
  Tested up to: 5.2
6
  Requires PHP: 5.3
7
+ Stable tag: 0.9.23
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
146
  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).
147
 
148
  == Changelog ==
149
+ = 0.9.23 =
150
+ - Added an option to hide the plugin menu on the top admin bar.
151
+ - Fixed: Always sent email notifications even the Only send an email notification when a backup fails option was selected.
152
+ - Fixed: The plugin menu on the top admin bar is visible to all users.
153
+ - Refined some error messages.
154
  = 0.9.22 =
155
  - Fixed: Backup created in web hosting/shared hosting optimization mode was incomplete in some cases.
156
  - Fixed: Backup actually failed but was reported as a success in some cases.
wpvivid-backuprestore.php CHANGED
@@ -7,7 +7,7 @@
7
  * @wordpress-plugin
8
  * Plugin Name: WPvivid Backup Plugin
9
  * Description: Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one.
10
- * Version: 0.9.22
11
  * Author: WPvivid Team
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.22' );
25
  //
26
  define('WPVIVID_RESTORE_INIT','init');
27
  define('WPVIVID_RESTORE_READY','ready');
@@ -36,6 +36,7 @@ define('WPVIVID_PLUGIN_SLUG','WPvivid');
36
  define('WPVIVID_PLUGIN_NAME',plugin_basename(__FILE__));
37
  define('WPVIVID_PLUGIN_URL',plugins_url('',__FILE__));
38
  define('WPVIVID_PLUGIN_DIR',dirname(__FILE__));
 
39
  define('WPVIVID_PLUGIN_IMAGES_URL',WPVIVID_PLUGIN_URL.'/admin/partials/images/');
40
  //We set a long enough default execution time (10 min) to ensure that the backup process can be completed.
41
  define('WPVIVID_MAX_EXECUTION_TIME',900);
@@ -120,7 +121,7 @@ add_action('admin_init', 'wpvivid_init_plugin_redirect');
120
  *
121
  * @since 0.9.1
122
  */
123
- if(isset($wpvivid_pulgin)&&is_a($wpvivid_pulgin,'WPvivid'))
124
  {
125
  return ;
126
  }
@@ -129,7 +130,7 @@ require plugin_dir_path( __FILE__ ) . 'includes/class-wpvivid.php';
129
 
130
  function run_wpvivid()
131
  {
132
- $wpvivid_pulgin = new WPvivid();
133
- $GLOBALS['wpvivid_pulgin'] = $wpvivid_pulgin;
134
  }
135
  run_wpvivid();
7
  * @wordpress-plugin
8
  * Plugin Name: WPvivid Backup Plugin
9
  * Description: Clone or copy WP sites then move or migrate them to new host (new domain), schedule backups, transfer backups to leading remote storage. All in one.
10
+ * Version: 0.9.23
11
  * Author: WPvivid Team
12
  * Author URI: https://wpvivid.com
13
  * License: GPL-3.0+
21
  die;
22
  }
23
 
24
+ define( 'WPVIVID_PLUGIN_VERSION', '0.9.23' );
25
  //
26
  define('WPVIVID_RESTORE_INIT','init');
27
  define('WPVIVID_RESTORE_READY','ready');
36
  define('WPVIVID_PLUGIN_NAME',plugin_basename(__FILE__));
37
  define('WPVIVID_PLUGIN_URL',plugins_url('',__FILE__));
38
  define('WPVIVID_PLUGIN_DIR',dirname(__FILE__));
39
+ define('WPVIVID_PLUGIN_DIR_URL',plugin_dir_url(__FILE__).'admin/');
40
  define('WPVIVID_PLUGIN_IMAGES_URL',WPVIVID_PLUGIN_URL.'/admin/partials/images/');
41
  //We set a long enough default execution time (10 min) to ensure that the backup process can be completed.
42
  define('WPVIVID_MAX_EXECUTION_TIME',900);
121
  *
122
  * @since 0.9.1
123
  */
124
+ if(isset($wpvivid_plugin)&&is_a($wpvivid_plugin,'WPvivid'))
125
  {
126
  return ;
127
  }
130
 
131
  function run_wpvivid()
132
  {
133
+ $wpvivid_plugin = new WPvivid();
134
+ $GLOBALS['wpvivid_plugin'] = $wpvivid_plugin;
135
  }
136
  run_wpvivid();