Migration, Backup, Staging – WPvivid - Version 0.9.58

Version Description

  • Fixed a fatal error with the last update.
Download this release

Release Info

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

Code changes from version 0.9.57 to 0.9.58

Files changed (110) hide show
  1. {trunk/admin → admin}/css/wpvivid-admin-bar.css +0 -0
  2. {trunk/admin → admin}/css/wpvivid-staging-custom.css +0 -0
  3. {trunk/admin → admin}/js/jstree/dist/jstree.js +0 -0
  4. {trunk/admin → admin}/js/jstree/dist/jstree.min.js +0 -0
  5. {trunk/admin → admin}/js/jstree/dist/themes/default-dark/32px.png +0 -0
  6. {trunk/admin → admin}/js/jstree/dist/themes/default-dark/40px.png +0 -0
  7. {trunk/admin → admin}/js/jstree/dist/themes/default-dark/style.css +0 -0
  8. {trunk/admin → admin}/js/jstree/dist/themes/default-dark/style.min.css +0 -0
  9. {trunk/admin → admin}/js/jstree/dist/themes/default-dark/throbber.gif +0 -0
  10. {trunk/admin → admin}/js/jstree/dist/themes/default/32px.png +0 -0
  11. {trunk/admin → admin}/js/jstree/dist/themes/default/40px.png +0 -0
  12. {trunk/admin → admin}/js/jstree/dist/themes/default/style.css +0 -0
  13. {trunk/admin → admin}/js/jstree/dist/themes/default/style.min.css +0 -0
  14. {trunk/admin → admin}/js/jstree/dist/themes/default/throbber.gif +0 -0
  15. {trunk/admin → admin}/partials/images/staging/Fresh-list.png +0 -0
  16. {trunk/admin → admin}/partials/images/staging/Fresh-tab.png +0 -0
  17. {trunk/admin/partials/images → admin/partials/images/staging}/Log.png +0 -0
  18. {trunk/admin → admin}/partials/images/staging/backup-migration.png +0 -0
  19. {trunk/admin → admin}/partials/images/staging/backups-restore.png +0 -0
  20. {trunk/admin → admin}/partials/images/staging/debug.png +0 -0
  21. {trunk/admin/partials/images → admin/partials/images/staging}/delete-tab.png +0 -0
  22. {trunk/admin/partials/images → admin/partials/images/staging}/download.png +0 -0
  23. {trunk/admin → admin}/partials/images/staging/living-site.png +0 -0
  24. {trunk/admin → admin}/partials/images/staging/logs.png +0 -0
  25. {trunk/admin → admin}/partials/images/staging/pro.png +0 -0
  26. {trunk/admin → admin}/partials/images/staging/remote-storage.png +0 -0
  27. {trunk/admin → admin}/partials/images/staging/role-cap.png +0 -0
  28. {trunk/admin → admin}/partials/images/staging/schedule.png +0 -0
  29. {trunk/admin → admin}/partials/images/staging/settings.png +0 -0
  30. {trunk/admin → admin}/partials/images/staging/staging-site.png +0 -0
  31. {trunk/admin → admin}/partials/images/staging/staging.png +0 -0
  32. {trunk/admin → admin}/partials/images/staging/storage-pcloud(gray).png +0 -0
  33. {trunk/admin → admin}/partials/images/staging/storage-pcloud.png +0 -0
  34. {trunk/admin → admin}/partials/images/staging/storage-wasabi(gray).png +0 -0
  35. {trunk/admin → admin}/partials/images/staging/storage-wasabi.png +0 -0
  36. {trunk/includes → includes}/staging/class-wpvivid-fresh-install-create-ui-display.php +0 -0
  37. {trunk/includes → includes}/staging/class-wpvivid-staging-copy-db-ex.php +0 -0
  38. {trunk/includes → includes}/staging/class-wpvivid-staging-copy-files-ex.php +0 -0
  39. {trunk/includes → includes}/staging/class-wpvivid-staging-create-new-wp.php +0 -0
  40. {trunk/includes → includes}/staging/class-wpvivid-staging-create-ui-display.php +0 -0
  41. {trunk/includes → includes}/staging/class-wpvivid-staging-list-ui-display.php +0 -0
  42. {trunk/includes → includes}/staging/class-wpvivid-staging-log-page.php +0 -0
  43. {trunk/includes → includes}/staging/class-wpvivid-staging-log.php +0 -0
  44. {trunk/includes → includes}/staging/class-wpvivid-staging-setting.php +0 -0
  45. {trunk/includes → includes}/staging/class-wpvivid-staging-sites-list.php +0 -0
  46. {trunk/includes → includes}/staging/class-wpvivid-staging-task-ex.php +0 -0
  47. {trunk/includes → includes}/staging/class-wpvivid-staging-ui-display.php +0 -0
  48. {trunk/includes → includes}/staging/class-wpvivid-staging.php +0 -0
  49. readme.txt +3 -1
  50. trunk/admin/class-wpvivid-admin.php +0 -1323
  51. trunk/admin/css/wpvivid-admin.css +0 -266
  52. trunk/admin/index.php +0 -1
  53. trunk/admin/js/wpvivid-admin.js +0 -683
  54. trunk/admin/partials/images/Delete.png +0 -0
  55. trunk/admin/partials/images/Edit.png +0 -0
  56. trunk/admin/partials/images/Restore.png +0 -0
  57. trunk/admin/partials/images/add-storages.png +0 -0
  58. trunk/admin/partials/images/export-import.png +0 -0
  59. trunk/admin/partials/images/locked.png +0 -0
  60. trunk/admin/partials/images/staging/Log.png +0 -0
  61. trunk/admin/partials/images/staging/delete-tab.png +0 -0
  62. trunk/admin/partials/images/staging/download.png +0 -0
  63. trunk/admin/partials/images/storage-amazon-s3(gray).png +0 -0
  64. trunk/admin/partials/images/storage-amazon-s3.png +0 -0
  65. trunk/admin/partials/images/storage-digitalocean(gray).png +0 -0
  66. trunk/admin/partials/images/storage-digitalocean.png +0 -0
  67. trunk/admin/partials/images/storage-dropbox(gray).png +0 -0
  68. trunk/admin/partials/images/storage-dropbox.png +0 -0
  69. trunk/admin/partials/images/storage-ftp(gray).png +0 -0
  70. trunk/admin/partials/images/storage-ftp.png +0 -0
  71. trunk/admin/partials/images/storage-local(gray).png +0 -0
  72. trunk/admin/partials/images/storage-local.png +0 -0
  73. trunk/admin/partials/images/storage-microsoft-onedrive(gray).png +0 -0
  74. trunk/admin/partials/images/storage-microsoft-onedrive.png +0 -0
  75. trunk/admin/partials/images/storage-sftp(gray).png +0 -0
  76. trunk/admin/partials/images/storage-sftp.png +0 -0
  77. trunk/admin/partials/images/stroage-google-drive(gray).png +0 -0
  78. trunk/admin/partials/images/stroage-google-drive.png +0 -0
  79. trunk/admin/partials/images/unlocked.png +0 -0
  80. trunk/admin/partials/wpvivid-admin-display.php +0 -221
  81. trunk/admin/partials/wpvivid-backup-restore-page-display.php +0 -2551
  82. trunk/admin/partials/wpvivid-log-read-page-display.php +0 -0
  83. trunk/admin/partials/wpvivid-logs-page-display.php +0 -0
  84. trunk/admin/partials/wpvivid-remote-storage-page-display.php +0 -414
  85. trunk/admin/partials/wpvivid-schedule-page-display.php +0 -203
  86. trunk/admin/partials/wpvivid-settings-page-display.php +0 -710
  87. trunk/admin/partials/wpvivid-website-info-page-display.php +0 -35
  88. trunk/includes/class-wpvivid-additional-db-method.php +0 -255
  89. trunk/includes/class-wpvivid-backup-database.php +0 -149
  90. trunk/includes/class-wpvivid-backup-site.php +0 -52
  91. trunk/includes/class-wpvivid-backup-uploader.php +0 -792
  92. trunk/includes/class-wpvivid-backup.php +0 -2609
  93. trunk/includes/class-wpvivid-backuplist.php +0 -374
  94. trunk/includes/class-wpvivid-backuptoremote.php +0 -55
  95. trunk/includes/class-wpvivid-compress-default.php +0 -81
  96. trunk/includes/class-wpvivid-crypt.php +0 -234
  97. trunk/includes/class-wpvivid-db-method.php +0 -281
  98. trunk/includes/class-wpvivid-downloader.php +0 -184
  99. trunk/includes/class-wpvivid-error-log.php +0 -153
  100. trunk/includes/class-wpvivid-export-import.php +0 -2701
  101. trunk/includes/class-wpvivid-exporter.php +0 -1985
  102. trunk/includes/class-wpvivid-function-realize.php +0 -161
  103. trunk/includes/class-wpvivid-i18n.php +0 -49
  104. trunk/includes/class-wpvivid-importer.php +0 -2547
  105. trunk/includes/class-wpvivid-interface-mainwp.php +0 -547
  106. trunk/includes/class-wpvivid-log.php +0 -171
  107. trunk/includes/class-wpvivid-mail-report.php +0 -584
  108. trunk/includes/class-wpvivid-migrate.php +0 -1268
  109. trunk/includes/class-wpvivid-mysqldump-method.php +0 -1626
  110. trunk/includes/class-wpvivid-mysqldump.php +0 -257
{trunk/admin → admin}/css/wpvivid-admin-bar.css RENAMED
File without changes
{trunk/admin → admin}/css/wpvivid-staging-custom.css RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/jstree.js RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/jstree.min.js RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default-dark/32px.png RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default-dark/40px.png RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default-dark/style.css RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default-dark/style.min.css RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default-dark/throbber.gif RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default/32px.png RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default/40px.png RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default/style.css RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default/style.min.css RENAMED
File without changes
{trunk/admin → admin}/js/jstree/dist/themes/default/throbber.gif RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/Fresh-list.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/Fresh-tab.png RENAMED
File without changes
{trunk/admin/partials/images → admin/partials/images/staging}/Log.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/backup-migration.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/backups-restore.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/debug.png RENAMED
File without changes
{trunk/admin/partials/images → admin/partials/images/staging}/delete-tab.png RENAMED
File without changes
{trunk/admin/partials/images → admin/partials/images/staging}/download.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/living-site.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/logs.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/pro.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/remote-storage.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/role-cap.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/schedule.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/settings.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/staging-site.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/staging.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/storage-pcloud(gray).png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/storage-pcloud.png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/storage-wasabi(gray).png RENAMED
File without changes
{trunk/admin → admin}/partials/images/staging/storage-wasabi.png RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-fresh-install-create-ui-display.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-copy-db-ex.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-copy-files-ex.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-create-new-wp.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-create-ui-display.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-list-ui-display.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-log-page.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-log.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-setting.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-sites-list.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-task-ex.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging-ui-display.php RENAMED
File without changes
{trunk/includes → includes}/staging/class-wpvivid-staging.php RENAMED
File without changes
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: move, clone, migrate, staging, backup, restore, auto backup, cloud backup
4
  Requires at least: 4.5
5
  Tested up to: 5.8
6
  Requires PHP: 5.3
7
- Stable tag: 0.9.57
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
@@ -192,6 +192,8 @@ Thank you for translating WPvivid Backup Plugin to your languages!
192
  * [Nima](https://profiles.wordpress.org/nima78600/) (Persian)
193
 
194
  == Changelog ==
 
 
195
  = 0.9.57 =
196
  - Added a new feature of creating a staging site.
197
  - Fixed some bugs in the plugin code.
4
  Requires at least: 4.5
5
  Tested up to: 5.8
6
  Requires PHP: 5.3
7
+ Stable tag: 0.9.58
8
  License: GPLv3 or later
9
  License URI: https://www.gnu.org/licenses/gpl-3.0.en.html
10
 
192
  * [Nima](https://profiles.wordpress.org/nima78600/) (Persian)
193
 
194
  == Changelog ==
195
+ = 0.9.58 =
196
+ - Fixed a fatal error with the last update.
197
  = 0.9.57 =
198
  - Added a new feature of creating a staging site.
199
  - Fixed some bugs in the plugin code.
trunk/admin/class-wpvivid-admin.php DELETED
@@ -1,1323 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * The admin-specific functionality of the plugin.
5
- *
6
- * @link https://wpvivid.com
7
- * @since 0.9.1
8
- *
9
- * @package WPvivid
10
- * @subpackage WPvivid/admin
11
- */
12
-
13
- /**
14
- * The admin-specific functionality of the plugin.
15
- *
16
- * Defines the plugin name, version, and two examples hooks for how to
17
- * enqueue the admin-specific stylesheet and JavaScript.
18
- *
19
- * @package WPvivid
20
- * @subpackage WPvivid/admin
21
- * @author wpvivid team
22
- */
23
- if (!defined('WPVIVID_PLUGIN_DIR')){
24
- die;
25
- }
26
- class WPvivid_Admin {
27
-
28
- /**
29
- * The ID of this plugin.
30
- *
31
- *
32
- * @access private
33
- * @var string $plugin_name The ID of this plugin.
34
- */
35
- private $plugin_name;
36
-
37
- /**
38
- * The version of this plugin.
39
- *
40
- *
41
- * @access private
42
- * @var string $version The current version of this plugin.
43
- */
44
- private $version;
45
-
46
- private $screen_ids;
47
-
48
- private $toolbar_menus;
49
-
50
- private $submenus;
51
- /**
52
- * Initialize the class and set its properties.
53
- *
54
- *
55
- * @param string $plugin_name The name of this plugin.
56
- * @param string $version The version of this plugin.
57
- */
58
- public function __construct($plugin_name, $version)
59
- {
60
- add_filter('wpvivid_get_screen_ids',array($this,'get_screen_ids'),10);
61
- add_filter('wpvivid_get_toolbar_menus',array($this,'get_toolbar_menus'),10);
62
- add_filter('wpvivid_get_admin_menus',array($this,'get_admin_menus'),10);
63
- add_filter('wpvivid_add_side_bar', array($this, 'wpvivid_add_side_bar'), 10, 2);
64
-
65
- add_action('wpvivid_before_setup_page',array($this,'migrate_notice'));
66
- add_action('wpvivid_before_setup_page',array($this,'show_add_my_review'));
67
- add_action('wpvivid_before_setup_page',array($this,'check_extensions'));
68
- add_action('wpvivid_before_setup_page',array($this,'check_amazons3'));
69
- add_action('wpvivid_before_setup_page',array($this,'init_js_var'));
70
-
71
- add_filter('wpvivid_add_log_tab_page', array($this, 'add_log_tab_page'), 10);
72
-
73
- $this->plugin_name = $plugin_name;
74
- $this->version = $version;
75
- }
76
-
77
- public function add_log_tab_page($setting_array)
78
- {
79
- $setting_array['backup_log_page'] = array('index' => '1', 'tab_func' => array($this, 'wpvivid_add_tab_log'), 'page_func' => array($this, 'wpvivid_add_page_log'));
80
- //$setting_array['read_log_page'] = array('index' => '2', 'tab_func' => array($this, 'wpvivid_add_tab_read_log'), 'page_func' => array($this, 'wpvivid_add_page_read_log'));
81
- return $setting_array;
82
- }
83
-
84
- public function get_screen_ids($screen_ids)
85
- {
86
- $screen_ids[]='toplevel_page_'.$this->plugin_name;
87
- $screen_ids[]='wpvivid-backup_page_wpvivid-transfer';
88
- $screen_ids[]='wpvivid-backup_page_wpvivid-setting';
89
- $screen_ids[]='wpvivid-backup_page_wpvivid-schedule';
90
- $screen_ids[]='wpvivid-backup_page_wpvivid-remote';
91
- $screen_ids[]='wpvivid-backup_page_wpvivid-website';
92
- $screen_ids[]='wpvivid-backup_page_wpvivid-log';
93
- $screen_ids[]='wpvivid-backup_page_wpvivid-key';
94
- $screen_ids[]='wpvivid-backup_page_wpvivid-mainwp';
95
- $screen_ids[]='wpvivid-backup_page_wpvivid_premium';
96
- return $screen_ids;
97
- }
98
-
99
- public function get_toolbar_menus($toolbar_menus)
100
- {
101
- $menu['id']='wpvivid_admin_menu';
102
- $menu['title']='WPvivid Backup';
103
- $toolbar_menus[$menu['id']]=$menu;
104
-
105
- $admin_url = admin_url();
106
-
107
- $menu['id']='wpvivid_admin_menu_backup';
108
- $menu['parent']='wpvivid_admin_menu';
109
- $menu['title']=__('Backup & Restore', 'wpvivid-backuprestore');
110
- $menu['tab']='admin.php?page=WPvivid&tab-backup';
111
- $menu['href']=$admin_url . 'admin.php?page=WPvivid&tab-backup';
112
- $menu['capability']='administrator';
113
- $menu['index']=1;
114
- $toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
115
-
116
- return $toolbar_menus;
117
- }
118
-
119
- public function get_admin_menus($submenus)
120
- {
121
- $submenu['parent_slug']=$this->plugin_name;
122
- $submenu['page_title']='WPvivid Backup';
123
- $submenu['menu_title']=__('Backup & Restore', 'wpvivid-backuprestore');
124
- $submenu['capability']='administrator';
125
- $submenu['menu_slug']=$this->plugin_name;
126
- $submenu['function']=array($this, 'display_plugin_setup_page');
127
- $submenu['index']=1;
128
- $submenus[$submenu['menu_slug']]=$submenu;
129
-
130
- $submenu['parent_slug']=$this->plugin_name;
131
- $submenu['page_title']='WPvivid Backup';
132
- $submenu['menu_title']=__('Settings', 'wpvivid-backuprestore');
133
- $submenu['capability']='administrator';
134
- $submenu['menu_slug']='wpvivid-setting';
135
- $submenu['function']=array($this, 'display_plugin_setup_page');
136
- $submenu['index']=5;
137
- $submenus[$submenu['menu_slug']]=$submenu;
138
-
139
- return $submenus;
140
- }
141
-
142
- public function wpvivid_add_side_bar($html, $show_schedule = false){
143
- $wpvivid_version = WPVIVID_PLUGIN_VERSION;
144
- $wpvivid_version = apply_filters('wpvivid_display_pro_version', $wpvivid_version);
145
-
146
- $html = '<div class="postbox">
147
- <h2>
148
- <div style="float: left; margin-right: 5px;"><span style="margin: 0; padding: 0">'.__('Current Version:', 'wpvivid-backuprestore').' '.$wpvivid_version.'</span></div>
149
- <div style="float: left; margin-right: 5px;"><span style="margin: 0; padding: 0">|</span></div>
150
- <div style="float: left; margin-left: 0;">
151
- <span style="margin: 0; padding: 0"><a href="https://wordpress.org/plugins/wpvivid-backuprestore/#developers" target="_blank" style="text-decoration: none;">'.__('ChangeLog', 'wpvivid-backuprestore').'</a></span>
152
- </div>
153
- <div style="clear: both;"></div>
154
- </h2>
155
- </div>
156
- <div id="wpvivid_backup_schedule_part"></div>
157
- <div class="postbox">
158
- <h2><span>'.__('Troubleshooting', 'wpvivid-backuprestore').'</span></h2>
159
- <div class="inside">
160
- <table class="widefat" cellpadding="0">
161
- <tbody>
162
- <tr class="alternate">
163
- <td class="row-title">'.__('Read <a href="https://docs.wpvivid.com/troubleshooting-issues-wpvivid-backup-plugin.html" target="_blank">Troubleshooting page</a> for faster solutions.', 'wpvivid-backuprestore').'</td>
164
- </tr>
165
- <tr>
166
- <td class="row-title">'.__('Adjust <a href="https://docs.wpvivid.com/wpvivid-backup-free-advanced-settings.html" target="_blank">Advanced Settings</a> for higher task success rate.', 'wpvivid-backuprestore').'</td>
167
- </tr>
168
- </tbody>
169
- </table>
170
- </div>
171
- </div>
172
- <div class="postbox">
173
- <h2><span>'.__('How-to', 'wpvivid-backuprestore').'</span></h2>
174
- <div class="inside">
175
- <table class="widefat" cellpadding="0">
176
- <tbody>
177
- <tr class="alternate"><td class="row-title"><a href="https://docs.wpvivid.com/wpvivid-backup-free-general-settings.html" target="_blank">'.__('WPvivid Backup Settings', 'wpvivid-backuprestore').'</a></td></tr>
178
- <tr><td class="row-title"><a href="https://docs.wpvivid.com/get-started-create-manual-backup.html" target="_blank">'.__('Create a Manual Backup', 'wpvivid-backuprestore').'</a></td></tr>
179
- <tr class="alternate"><td class="row-title"><a href="https://docs.wpvivid.com/get-started-restore-site.html" target="_blank">'.__('Restore Your Site from a Backup', 'wpvivid-backuprestore').'</a></td></tr>
180
- <tr><td class="row-title"><a href="https://docs.wpvivid.com/get-started-transfer-site.html" target="_blank">'.__('Migrate WordPress', 'wpvivid-backuprestore').'</a></td></tr>
181
- </tbody>
182
- </table>
183
- </div>
184
- </div>';
185
- return $html;
186
- }
187
-
188
- /**
189
- * Register the stylesheets for the admin area.
190
- *
191
- *
192
- */
193
- public function enqueue_styles()
194
- {
195
- $this->screen_ids=apply_filters('wpvivid_get_screen_ids',$this->screen_ids);
196
- if(in_array(get_current_screen()->id,$this->screen_ids))
197
- {
198
- wp_enqueue_style($this->plugin_name, WPVIVID_PLUGIN_DIR_URL . 'css/wpvivid-admin.css', array(), $this->version, 'all');
199
- do_action('wpvivid_do_enqueue_styles');
200
- }
201
- }
202
-
203
- /**
204
- * Register the JavaScript for the admin area.
205
- *
206
- *
207
- */
208
- public function enqueue_scripts()
209
- {
210
- $this->screen_ids=apply_filters('wpvivid_get_screen_ids',$this->screen_ids);
211
-
212
- if(in_array(get_current_screen()->id,$this->screen_ids))
213
- {
214
- wp_enqueue_script($this->plugin_name, WPVIVID_PLUGIN_DIR_URL . 'js/wpvivid-admin.js', array('jquery'), $this->version, false);
215
- wp_localize_script($this->plugin_name, 'wpvivid_ajax_object', array('ajax_url' => admin_url('admin-ajax.php'),'ajax_nonce'=>wp_create_nonce('wpvivid_ajax')));
216
-
217
- wp_localize_script($this->plugin_name, 'wpvividlion', array(
218
- 'warning' => __('Warning:', 'wpvivid-backuprestore'),
219
- 'error' => __('Error:', 'wpvivid-backuprestore'),
220
- 'remotealias' => __('Warning: An alias for remote storage is required.', 'wpvivid-backuprestore'),
221
- 'remoteexist' => __('Warning: The alias already exists in storage list.', 'wpvivid-backuprestore'),
222
- 'backup_calc_timeout' => __('Calculating the size of files, folder and database timed out. If you continue to receive this error, please go to the plugin settings, uncheck \'Calculate the size of files, folder and database before backing up\', save changes, then try again.', 'wpvivid-backuprestore'),
223
- 'restore_step1' => __('Step One: In the backup list, click the \'Restore\' button on the backup you want to restore. This will bring up the restore tab', 'wpvivid-backuprestore'),
224
- 'restore_step2' => __('Step Two: Choose an option to complete restore, if any', 'wpvivid-backuprestore'),
225
- 'restore_step3' => __('Step Three: Click \'Restore\' button', 'wpvivid-backuprestore'),
226
- 'get_key_step1' => __('1. Visit Key tab page of WPvivid backup plugin of destination site.', 'wpvivid-backuprestore'),
227
- 'get_key_step2' => __('2. Generate a key by clicking Generate button and copy it.', 'wpvivid-backuprestore'),
228
- 'get_key_step3' => __('3. Go back to this page and paste the key in key box below. Lastly, click Save button.', 'wpvivid-backuprestore'),
229
- ));
230
-
231
- wp_enqueue_script('plupload-all');
232
- do_action('wpvivid_do_enqueue_scripts');
233
- }
234
- }
235
-
236
- /**
237
- * Register the administration menu for this plugin into the WordPress Dashboard menu.
238
- *
239
- *
240
- */
241
- public function add_plugin_admin_menu()
242
- {
243
-
244
- /*
245
- * Add a settings page for this plugin to the Settings menu.
246
- *
247
- * NOTE: Alternative menu locations are available via WordPress administration menu functions.
248
- *
249
- * Administration Menus: http://codex.wordpress.org/Administration_Menus
250
- *
251
- */
252
- $menu['page_title']= 'WPvivid Backup';
253
- $menu['menu_title']= 'WPvivid Backup';
254
- $menu['capability']='administrator';
255
- $menu['menu_slug']= $this->plugin_name;
256
- $menu['function']=array($this, 'display_plugin_setup_page');
257
- $menu['icon_url']='dashicons-cloud';
258
- $menu['position']=100;
259
- $menu = apply_filters('wpvivid_get_main_admin_menus', $menu);
260
- add_menu_page( $menu['page_title'],$menu['menu_title'], $menu['capability'], $menu['menu_slug'], $menu['function'], $menu['icon_url'], $menu['position']);
261
- $this->submenus = apply_filters('wpvivid_get_admin_menus', $this->submenus);
262
- usort($this->submenus, function ($a, $b) {
263
- if ($a['index'] == $b['index'])
264
- return 0;
265
-
266
- if ($a['index'] > $b['index'])
267
- return 1;
268
- else
269
- return -1;
270
- });
271
- foreach ($this->submenus as $submenu) {
272
- add_submenu_page(
273
- $submenu['parent_slug'],
274
- $submenu['page_title'],
275
- $submenu['menu_title'],
276
- $submenu['capability'],
277
- $submenu['menu_slug'],
278
- $submenu['function']);
279
- }
280
- }
281
-
282
- function add_toolbar_items($wp_admin_bar)
283
- {
284
- global $wpvivid_plugin;
285
- if(is_admin())
286
- {
287
- $show_admin_bar = $wpvivid_plugin->get_admin_bar_setting();
288
- if ($show_admin_bar === true)
289
- {
290
- $this->toolbar_menus = apply_filters('wpvivid_get_toolbar_menus', $this->toolbar_menus);
291
- foreach ($this->toolbar_menus as $menu)
292
- {
293
- $wp_admin_bar->add_menu(array(
294
- 'id' => $menu['id'],
295
- 'title' => $menu['title']
296
- ));
297
- if (isset($menu['child']))
298
- {
299
- usort($menu['child'], function ($a, $b)
300
- {
301
- if($a['index']==$b['index'])
302
- return 0;
303
-
304
- if($a['index']>$b['index'])
305
- return 1;
306
- else
307
- return -1;
308
- });
309
- foreach ($menu['child'] as $child_menu) {
310
- if(isset($child_menu['capability']) && current_user_can($child_menu['capability'])) {
311
- $wp_admin_bar->add_menu(array(
312
- 'id' => $child_menu['id'],
313
- 'parent' => $menu['id'],
314
- 'title' => $child_menu['title'],
315
- 'href' => $child_menu['href']
316
- ));
317
- }
318
- }
319
- }
320
- }
321
- }
322
- }
323
- }
324
-
325
- public function add_action_links( $links )
326
- {
327
- $settings_link = array(
328
- '<a href="' . admin_url( 'admin.php?page=' . apply_filters('wpvivid_white_label_slug', $this->plugin_name) ) . '">' . __('Settings', $this->plugin_name) . '</a>',
329
- );
330
- return array_merge( $settings_link, $links );
331
- }
332
-
333
- public static function wpvivid_get_siteurl(){
334
- $wpvivid_siteurl = array();
335
- $wpvivid_siteurl['home_url'] = home_url();
336
- $wpvivid_siteurl['plug_url'] = plugins_url();
337
- $wpvivid_siteurl['site_url'] = get_option( 'siteurl' );
338
- return $wpvivid_siteurl;
339
- }
340
-
341
- /**
342
- * Render the settings page for this plugin.
343
- *
344
- *
345
- */
346
- public function display_plugin_setup_page()
347
- {
348
- do_action('wpvivid_before_setup_page');
349
-
350
- add_action('wpvivid_display_page',array($this,'display'));
351
-
352
- do_action('wpvivid_display_page');
353
- }
354
-
355
- public function migrate_notice()
356
- {
357
- $migrate_notice=false;
358
- $migrate_status=WPvivid_Setting::get_option('wpvivid_migrate_status');
359
- if(!empty($migrate_status) && $migrate_status == 'completed')
360
- {
361
- $migrate_notice=true;
362
- echo '<div class="notice notice-warning is-dismissible"><p>'.__('Migration is complete and htaccess file is replaced. In order to successfully complete the migration, you\'d better reinstall 301 redirect plugin, firewall and security plugin, and caching plugin if they exist.').'</p></div>';
363
- WPvivid_Setting::delete_option('wpvivid_migrate_status');
364
- }
365
- $restore = new WPvivid_restore_data();
366
- if ($restore->has_restore())
367
- {
368
- $restore_status = $restore->get_restore_status();
369
- if ($restore_status === WPVIVID_RESTORE_COMPLETED)
370
- {
371
- $restore->clean_restore_data();
372
- do_action('wpvivid_rebuild_backup_list');
373
- $need_review=WPvivid_Setting::get_option('wpvivid_need_review');
374
- if($need_review=='not')
375
- {
376
- WPvivid_Setting::update_option('wpvivid_need_review','show');
377
- $msg = __('Cheers! WPvivid Backup plugin has restored successfully your website. If you found WPvivid Backup plugin helpful, a 5-star rating would be highly appreciated, which motivates us to keep providing new features.', 'wpvivid-backuprestore');
378
- WPvivid_Setting::update_option('wpvivid_review_msg',$msg);
379
- }
380
- else{
381
- if(!$migrate_notice)
382
- {
383
- echo '<div class="notice notice-success is-dismissible"><p>'.__('Restore completed successfully.').'</p></div>';
384
- }
385
- }
386
- }
387
- }
388
- }
389
-
390
- public function display()
391
- {
392
- include_once('partials/wpvivid-admin-display.php');
393
- }
394
-
395
- public static function wpvivid_get_page_request()
396
- {
397
- $request_page='wpvivid_tab_general';
398
-
399
- if(isset($_REQUEST['wpvivid-remote-page-mainwp'])){
400
- $request_page='wpvivid_tab_remote_storage';
401
- }
402
- if(isset($_REQUEST['tab-backup']))
403
- {
404
- $request_page='wpvivid_tab_general';
405
- }
406
- else if(isset($_REQUEST['tab-schedule']))
407
- {
408
- $request_page='wpvivid_tab_schedule';
409
- }
410
- else if(isset($_REQUEST['tab-transfer']))
411
- {
412
- $request_page='wpvivid_tab_migrate';
413
- }
414
- else if(isset($_REQUEST['tab-remote-storage']))
415
- {
416
- $request_page='wpvivid_tab_remote_storage';
417
- }
418
- else if(isset($_REQUEST['tab-settings']))
419
- {
420
- $request_page='wpvivid_tab_setting';
421
- }
422
- else if(isset($_REQUEST['tab-website-info']))
423
- {
424
- $request_page='wpvivid_tab_debug';
425
- }
426
- else if(isset($_REQUEST['tab-logs']))
427
- {
428
- $request_page='wpvivid_tab_log';
429
- }
430
- else if(isset($_REQUEST['tab-key']))
431
- {
432
- $request_page='wpvivid_tab_key';
433
- }
434
- else if(isset($_REQUEST['tab-mainwp']))
435
- {
436
- $request_page='wpvivid_tab_mainwp';
437
- }
438
- else if(isset($_REQUEST['page'])&&$_REQUEST['page']=='wpvivid-pro')
439
- {
440
- $request_page='wpvivid_tab_pro';
441
- }
442
- else if(isset($_REQUEST['page'])&&$_REQUEST['page']=='wpvivid-setting')
443
- {
444
- $request_page='wpvivid_tab_setting';
445
- }
446
-
447
- $request_page=apply_filters('wpvivid_set_page_request',$request_page);
448
-
449
- return $request_page;
450
- }
451
-
452
- public static function show_add_my_review()
453
- {
454
- $review = WPvivid_Setting::get_option('wpvivid_need_review');
455
- $review_msg = WPvivid_Setting::get_option('wpvivid_review_msg');
456
- if (empty($review))
457
- {
458
- WPvivid_Setting::update_option('wpvivid_need_review', 'not');
459
- } else {
460
- if ($review == 'not')
461
- {
462
- }
463
- else if ($review == 'show')
464
- {
465
- if(!empty($review_msg))
466
- {
467
- echo '<div class="notice notice-info is-dismissible" id="wpvivid_notice_rate">
468
- <p>' . $review_msg . '</p>
469
- <div style="padding-bottom: 10px;">
470
- <span><input type="button" class="button-primary" option="review" name="rate-now" value="'.esc_attr('Rate Us', 'wpvivid-backuprestore').'" /></span>
471
- <span><input type="button" class="button-secondary" option="review" name="ask-later" value="'.esc_attr('Maybe Later', 'wpvivid-backuprestore').'" /></span>
472
- <span><input type="button" class="button-secondary" option="review" name="never-ask" value="'.esc_attr('Never', 'wpvivid-backuprestore').'" /></span>
473
- <span><input type="button" class="button-secondary" option="review" name="already-done" value="'.esc_attr('Already Done', 'wpvivid-backuprestore').'" /></span>
474
- </div>
475
- </div>';
476
- }
477
- } else if ($review == 'do_not_ask')
478
- {
479
- } else
480
- {
481
- if (time() > $review)
482
- {
483
- if(!empty($review_msg))
484
- {
485
- echo '<div class="notice notice-info is-dismissible" id="wpvivid_notice_rate">
486
- <p>' . $review_msg . '</p>
487
- <div style="padding-bottom: 10px;">
488
- <span><input type="button" class="button-primary" option="review" name="rate-now" value="'.esc_attr('Rate Us', 'wpvivid-backuprestore').'" /></span>
489
- <span><input type="button" class="button-secondary" option="review" name="ask-later" value="'.esc_attr('Maybe Later', 'wpvivid-backuprestore').'" /></span>
490
- <span><input type="button" class="button-secondary" option="review" name="never-ask" value="'.esc_attr('Never', 'wpvivid-backuprestore').'" /></span>
491
- <span><input type="button" class="button-secondary" option="review" name="already-done" value="'.esc_attr('Already Done', 'wpvivid-backuprestore').'" /></span>
492
- </div>
493
- </div>';
494
- }
495
- }
496
- }
497
- }
498
- }
499
-
500
- public function check_amazons3()
501
- {
502
- $remoteslist=WPvivid_Setting::get_all_remote_options();
503
- $need_amazons3_notice = false;
504
- if(isset($remoteslist) && !empty($remoteslist))
505
- {
506
- foreach ($remoteslist as $remote_id => $value)
507
- {
508
- if($remote_id === 'remote_selected')
509
- {
510
- continue;
511
- }
512
- if($value['type'] == 'amazons3' && isset($value['s3Path']))
513
- {
514
- $need_amazons3_notice = true;
515
- }
516
- if($value['type'] == 's3compat' && isset($value['s3directory']))
517
- {
518
- $need_amazons3_notice = true;
519
- }
520
- }
521
- }
522
- if($need_amazons3_notice)
523
- {
524
- $amazons3_notice = WPvivid_Setting::get_option('wpvivid_amazons3_notice', 'not init');
525
- if($amazons3_notice === 'not init')
526
- {
527
- $notice_message = __('As Amazon S3 and DigitalOcean Space have upgraded their connection methods, please delete the previous connections and re-add your Amazon S3/DigitalOcean Space accounts to make sure the connections work.', 'wpvivid-backuprestore');
528
- echo '<div class="notice notice-warning" id="wpvivid_amazons3_notice">
529
- <p>' . $notice_message . '</p>
530
- <div style="padding-bottom: 10px;">
531
- <span><input type="button" class="button-secondary" value="I Understand" onclick="wpvivid_click_amazons3_notice();" /></span>
532
- </div>
533
- </div>';
534
- }
535
- }
536
- }
537
-
538
- public function check_extensions()
539
- {
540
- $common_setting = WPvivid_Setting::get_setting(false, 'wpvivid_common_setting');
541
- $db_connect_method = isset($common_setting['options']['wpvivid_common_setting']['db_connect_method']) ? $common_setting['options']['wpvivid_common_setting']['db_connect_method'] : 'wpdb';
542
- $need_php_extensions = array();
543
- $need_extensions_count = 0;
544
- $extensions=get_loaded_extensions();
545
- if(!function_exists("curl_init")){
546
- $need_php_extensions[$need_extensions_count] = 'curl';
547
- $need_extensions_count++;
548
- }
549
- if(!class_exists('PDO')){
550
- $need_php_extensions[$need_extensions_count] = 'PDO';
551
- $need_extensions_count++;
552
- }
553
- if(!function_exists("gzopen"))
554
- {
555
- $need_php_extensions[$need_extensions_count] = 'zlib';
556
- $need_extensions_count++;
557
- }
558
- if(!array_search('pdo_mysql',$extensions) && $db_connect_method === 'pdo')
559
- {
560
- $need_php_extensions[$need_extensions_count] = 'pdo_mysql';
561
- $need_extensions_count++;
562
- }
563
- if(!empty($need_php_extensions)){
564
- $msg = '';
565
- $figure = 0;
566
- foreach ($need_php_extensions as $extension){
567
- $figure++;
568
- if($figure == 1){
569
- $msg .= $extension;
570
- }
571
- else if($figure < $need_extensions_count) {
572
- $msg .= ', '.$extension;
573
- }
574
- else if($figure == $need_extensions_count){
575
- $msg .= ' and '.$extension;
576
- }
577
- }
578
- if($figure == 1){
579
- echo '<div class="notice notice-error"><p>'.sprintf(__('The %s extension is not detected. Please install the extension first.', 'wpvivid-backuprestore'), $msg).'</p></div>';
580
- }
581
- else{
582
- echo '<div class="notice notice-error"><p>'.sprintf(__('The %s extensions are not detected. Please install the extensions first.', 'wpvivid-backuprestore'), $msg).'</p></div>';
583
- }
584
- }
585
-
586
- if (!class_exists('PclZip')) include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
587
- if (!class_exists('PclZip')) {
588
- echo '<div class="notice notice-error"><p>'.__('Class PclZip is not detected. Please update or reinstall your WordPress.', 'wpvivid-backuprestore').'</p></div>';
589
- }
590
-
591
- $hide_notice = get_option('wpvivid_hide_wp_cron_notice', false);
592
- if(defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && $hide_notice === false){
593
- echo '<div class="notice notice-error notice-wp-cron is-dismissible"><p>'.__('In order to execute the scheduled backups properly, please set the DISABLE_WP_CRON constant to false.', 'wpvivid-backuprestore').'</p></div>';
594
- }
595
- }
596
-
597
- public function init_js_var()
598
- {
599
- global $wpvivid_plugin;
600
-
601
- $loglist=$wpvivid_plugin->get_log_list_ex();
602
- $remoteslist=WPvivid_Setting::get_all_remote_options();
603
- $default_remote_storage='';
604
- foreach ($remoteslist['remote_selected'] as $value)
605
- {
606
- $default_remote_storage=$value;
607
- }
608
- ?>
609
- <script>
610
- var wpvivid_siteurl = '<?php
611
- $wpvivid_siteurl = array();
612
- $wpvivid_siteurl=WPvivid_Admin::wpvivid_get_siteurl();
613
- echo esc_url($wpvivid_siteurl['site_url']);
614
- ?>';
615
- var wpvivid_plugurl = '<?php
616
- echo WPVIVID_PLUGIN_URL;
617
- ?>';
618
- var wpvivid_log_count = '<?php
619
- _e(sizeof($loglist['log_list']['file']), 'wpvivid-backuprestore');
620
- ?>';
621
- var wpvivid_log_array = '<?php
622
- _e(json_encode($loglist), 'wpvivid-backuprestore');
623
- ?>';
624
- var wpvivid_page_request = '<?php
625
- $page_request = WPvivid_Admin::wpvivid_get_page_request();
626
- _e($page_request, 'wpvivid-backuprestore');
627
- ?>';
628
- var wpvivid_default_remote_storage = '<?php
629
- _e($default_remote_storage, 'wpvivid-backuprestore');
630
- ?>';
631
- </script>
632
- <?php
633
- }
634
-
635
- public function wpvivid_add_default_tab_page($page_array){
636
- $page_array['backup_restore'] = array('index' => '1', 'tab_func' => array($this, 'wpvivid_add_tab_backup_restore'), 'page_func' => array($this, 'wpvivid_add_page_backup'));
637
- $page_array['schedule'] = array('index' => '2', 'tab_func' => array($this, 'wpvivid_add_tab_schedule'), 'page_func' => array($this, 'wpvivid_add_page_schedule'));
638
- $page_array['remote_storage'] = array('index' => '4', 'tab_func' => array($this, 'wpvivid_add_tab_remote_storage'), 'page_func' => array($this, 'wpvivid_add_page_remote_storage'));
639
- $page_array['setting'] = array('index' => '5', 'tab_func' => array($this, 'wpvivid_add_tab_setting'), 'page_func' => array($this, 'wpvivid_add_page_setting'));
640
- $page_array['website_info'] = array('index' => '6', 'tab_func' => array($this, 'wpvivid_add_tab_website_info'), 'page_func' => array($this, 'wpvivid_add_page_website_info'));
641
- $page_array['log'] = array('index' => '7', 'tab_func' => array($this, 'wpvivid_add_tab_log_ex'), 'page_func' => array($this, 'wpvivid_add_page_log_ex'));
642
- $page_array['read_log'] = array('index' => '29', 'tab_func' => array($this, 'wpvivid_add_tab_read_log'), 'page_func' => array($this, 'wpvivid_add_page_read_log'));
643
- $page_array['premium'] = array('index' => '10', 'tab_func' => array($this, 'wpvivid_add_tab_premium'), 'page_func' => array($this, 'wpvivid_add_page_premium'));
644
- $hide_mwp_tab_page = get_option('wpvivid_hide_mwp_tab_page_v1', false);
645
- if($hide_mwp_tab_page === false) {
646
- $page_array['mwp'] = array('index' => '30', 'tab_func' => array($this, 'wpvivid_add_tab_mwp'), 'page_func' => array($this, 'wpvivid_add_page_mwp'));
647
- }
648
- return $page_array;
649
- }
650
-
651
- public function wpvivid_add_tab_backup_restore(){
652
- ?>
653
- <a href="#" id="wpvivid_tab_general" class="nav-tab wrap-nav-tab nav-tab-active" onclick="switchTabs(event,'general-page')"><?php _e('Backup & Restore', 'wpvivid-backuprestore'); ?></a>
654
- <?php
655
- }
656
-
657
- public function wpvivid_add_tab_schedule(){
658
- ?>
659
- <a href="#" id="wpvivid_tab_schedule" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'schedule-page')"><?php _e('Schedule', 'wpvivid-backuprestore'); ?></a>
660
- <?php
661
- }
662
-
663
- public function wpvivid_add_tab_remote_storage(){
664
- ?>
665
- <a href="#" id="wpvivid_tab_remote_storage" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'storage-page')"><?php _e('Remote Storage', 'wpvivid-backuprestore'); ?></a>
666
- <?php
667
- }
668
-
669
- public function wpvivid_add_tab_setting(){
670
- ?>
671
- <a href="#" id="wpvivid_tab_setting" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'settings-page')"><?php _e('Settings', 'wpvivid-backuprestore'); ?></a>
672
- <?php
673
- }
674
-
675
- public function wpvivid_add_tab_website_info(){
676
- ?>
677
- <a href="#" id="wpvivid_tab_debug" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'debug-page')"><?php _e('Debug', 'wpvivid-backuprestore'); ?></a>
678
- <?php
679
- }
680
-
681
- public function wpvivid_add_tab_log(){
682
- ?>
683
- <a href="#" id="wpvivid_tab_log" class="nav-tab log-nav-tab nav-tab-active" onclick="switchlogTabs(event,'logs-page')"><?php _e('Backup Logs', 'wpvivid-backuprestore'); ?></a>
684
- <?php
685
- }
686
-
687
- public function wpvivid_add_tab_read_log(){
688
- ?>
689
- <a href="#" id="wpvivid_tab_read_log" class="nav-tab wrap-nav-tab delete" onclick="switchTabs(event,'log-read-page')" style="display: none;">
690
- <div style="margin-right: 15px;"><?php _e('Log', 'wpvivid-backuprestore'); ?></div>
691
- <div class="nav-tab-delete-img">
692
- <img src="<?php echo esc_url( WPVIVID_PLUGIN_URL.'/admin/partials/images/delete-tab.png' ); ?>" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, 'wpvivid_tab_read_log', 'wrap', 'wpvivid_tab_log');" />
693
- </div>
694
- </a>
695
- <?php
696
- }
697
-
698
- public function wpvivid_add_tab_mwp(){
699
- ?>
700
- <a href="#" id="wpvivid_tab_mainwp" class="nav-tab wrap-nav-tab delete" onclick="switchTabs(event, 'mwp-page')">
701
- <div style="margin-right: 15px;"><?php _e('MainWP', 'wpvivid-backuprestore'); ?></div>
702
- <div class="nav-tab-delete-img">
703
- <img src="<?php echo esc_url(WPVIVID_PLUGIN_URL.'/admin/partials/images/delete-tab.png'); ?>" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, 'wpvivid_tab_mainwp', 'wrap', 'wpvivid_tab_general');" />
704
- </div>
705
- </a>
706
- <?php
707
- }
708
-
709
- public function wpvivid_add_tab_premium(){
710
- ?>
711
- <a href="#" id="wpvivid_tab_premium" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'premium-page')"><?php _e('Premium', 'wpvivid-backuprestore'); ?></a>
712
- <?php
713
- }
714
-
715
- public function wpvivid_add_page_backup()
716
- {
717
- ?>
718
- <div id="general-page" class="wrap-tab-content wpvivid_tab_general" name="tab-backup" style="width:100%;">
719
- <div class="meta-box-sortables ui-sortable">
720
- <?php
721
- do_action('wpvivid_backuppage_add_module');
722
- ?>
723
- <h2 class="nav-tab-wrapper" id="wpvivid_backup_tab" style="padding-bottom:0!important;">
724
- <?php
725
- $backuplist_array = array();
726
- $backuplist_array = apply_filters('wpvivid_backuppage_load_backuplist', $backuplist_array);
727
- foreach ($backuplist_array as $list_name) {
728
- add_action('wpvivid_backuppage_add_tab', $list_name['tab_func'], $list_name['index']);
729
- add_action('wpvivid_backuppage_add_page', $list_name['page_func'], $list_name['index']);
730
- }
731
- do_action('wpvivid_backuppage_add_tab');
732
- ?>
733
- </h2>
734
- <?php do_action('wpvivid_backuppage_add_page'); ?>
735
- </div>
736
- </div>
737
- <script>
738
- <?php do_action('wpvivid_backup_do_js'); ?>
739
- </script>
740
- <?php
741
- }
742
-
743
- public function wpvivid_add_page_schedule()
744
- {
745
- ?>
746
- <div id="schedule-page" class="wrap-tab-content wpvivid_tab_schedule" name="tab-schedule" style="display: none;">
747
- <div>
748
- <table class="widefat">
749
- <tbody>
750
- <?php do_action('wpvivid_schedule_add_cell'); ?>
751
- <tfoot>
752
- <tr>
753
- <th class="row-title"><input class="button-primary storage-account-button" id="wpvivid_schedule_save" type="submit" name="" value="<?php esc_attr_e( 'Save Changes', 'wpvivid-backuprestore' ); ?>" /></th>
754
- <th></th>
755
- </tr>
756
- </tfoot>
757
- </tbody>
758
- </table>
759
- </div>
760
- </div>
761
- <script>
762
- jQuery('#wpvivid_schedule_save').click(function(){
763
- wpvivid_set_schedule();
764
- wpvivid_settings_changed = false;
765
- });
766
-
767
- function wpvivid_set_schedule()
768
- {
769
- var schedule_data = wpvivid_ajax_data_transfer('schedule');
770
- var ajax_data = {
771
- 'action': 'wpvivid_set_schedule',
772
- 'schedule': schedule_data
773
- };
774
- jQuery('#wpvivid_schedule_save').css({'pointer-events': 'none', 'opacity': '0.4'});
775
- wpvivid_post_request(ajax_data, function (data) {
776
- try {
777
- var jsonarray = jQuery.parseJSON(data);
778
-
779
- jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
780
- if (jsonarray.result === 'success') {
781
- location.reload();
782
- }
783
- else {
784
- alert(jsonarray.error);
785
- }
786
- }
787
- catch (err) {
788
- alert(err);
789
- jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
790
- }
791
- }, function (XMLHttpRequest, textStatus, errorThrown) {
792
- jQuery('#wpvivid_schedule_save').css({'pointer-events': 'auto', 'opacity': '1'});
793
- var error_message = wpvivid_output_ajaxerror('changing schedule', textStatus, errorThrown);
794
- alert(error_message);
795
- });
796
- }
797
- </script>
798
- <?php
799
- }
800
-
801
- public function wpvivid_add_page_remote_storage()
802
- {
803
- ?>
804
- <div id="storage-page" class="wrap-tab-content wpvivid_tab_remote_storage" name="tab-storage" style="display:none;">
805
- <div>
806
- <div class="storage-content" id="storage-brand-2" style="">
807
- <div class="postbox">
808
- <?php do_action('wpvivid_add_storage_tab'); ?>
809
- </div>
810
- <div class="postbox storage-account-block" id="wpvivid_storage_account_block">
811
- <?php do_action('wpvivid_add_storage_page'); ?>
812
- </div>
813
- <h2 class="nav-tab-wrapper" style="padding-bottom:0!important;">
814
- <?php do_action('wpvivid_storage_add_tab'); ?>
815
- </h2>
816
- <?php do_action('wpvivid_storage_add_page'); ?>
817
- </div>
818
- </div>
819
- </div>
820
- <?php
821
- }
822
-
823
- public function wpvivid_add_page_setting()
824
- {
825
- ?>
826
- <div id="settings-page" class="wrap-tab-content wpvivid_tab_setting" name="tab-setting" style="display:none;">
827
- <div>
828
- <h2 class="nav-tab-wrapper" style="padding-bottom:0!important;">
829
- <?php
830
- $setting_array = array();
831
- $setting_array = apply_filters('wpvivid_add_setting_tab_page', $setting_array);
832
- foreach ($setting_array as $setting_name) {
833
- add_action('wpvivid_settingpage_add_tab', $setting_name['tab_func'], $setting_name['index']);
834
- add_action('wpvivid_settingpage_add_page', $setting_name['page_func'], $setting_name['index']);
835
- }
836
- do_action('wpvivid_settingpage_add_tab');
837
- ?>
838
- </h2>
839
- <?php do_action('wpvivid_settingpage_add_page'); ?>
840
- <div><input class="button-primary" id="wpvivid_setting_general_save" type="submit" value="<?php esc_attr_e( 'Save Changes', 'wpvivid-backuprestore' ); ?>" /></div>
841
- </div>
842
- </div>
843
- <script>
844
- jQuery('#wpvivid_setting_general_save').click(function(){
845
- wpvivid_set_general_settings();
846
- wpvivid_settings_changed = false;
847
- });
848
-
849
- function wpvivid_set_general_settings()
850
- {
851
- var setting_data = wpvivid_ajax_data_transfer('setting');
852
- var ajax_data = {
853
- 'action': 'wpvivid_set_general_setting',
854
- 'setting': setting_data
855
- };
856
- jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'none', 'opacity': '0.4'});
857
- wpvivid_post_request(ajax_data, function (data) {
858
- try {
859
- var jsonarray = jQuery.parseJSON(data);
860
-
861
- jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
862
- if (jsonarray.result === 'success') {
863
- location.reload();
864
- }
865
- else {
866
- alert(jsonarray.error);
867
- }
868
- }
869
- catch (err) {
870
- alert(err);
871
- jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
872
- }
873
- }, function (XMLHttpRequest, textStatus, errorThrown) {
874
- jQuery('#wpvivid_setting_general_save').css({'pointer-events': 'auto', 'opacity': '1'});
875
- var error_message = wpvivid_output_ajaxerror('changing base settings', textStatus, errorThrown);
876
- alert(error_message);
877
- });
878
- }
879
- </script>
880
- <?php
881
- }
882
-
883
- public function wpvivid_add_tab_log_ex(){
884
- ?>
885
- <a href="#" id="wpvivid_tab_log_ex" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'logs-page-ex')"><?php _e('Logs', 'wpvivid-backuprestore'); ?></a>
886
- <?php
887
- }
888
-
889
- public function wpvivid_add_page_log_ex()
890
- {
891
- ?>
892
- <div id="logs-page-ex" class="wrap-tab-content wpvivid_tab_log" name="tab-logs" style="display:none;">
893
- <div>
894
- <h2 class="nav-tab-wrapper" style="padding-bottom:0!important;">
895
- <?php
896
- $setting_array = array();
897
- $setting_array = apply_filters('wpvivid_add_log_tab_page', $setting_array);
898
- foreach ($setting_array as $setting_name) {
899
- add_action('wpvivid_logpage_add_tab', $setting_name['tab_func'], $setting_name['index']);
900
- add_action('wpvivid_logpage_add_page', $setting_name['page_func'], $setting_name['index']);
901
- }
902
- do_action('wpvivid_logpage_add_tab');
903
- ?>
904
- </h2>
905
- <?php do_action('wpvivid_logpage_add_page'); ?>
906
- </div>
907
- </div>
908
- <?php
909
- }
910
-
911
- public function wpvivid_add_page_website_info()
912
- {
913
- ?>
914
- <div id="debug-page" class="wrap-tab-content wpvivid_tab_debug" name="tab-debug" style="display:none;">
915
- <table class="widefat">
916
- <div style="padding: 0 0 20px 10px;"><?php _e('There are two ways available to send us the debug information. The first one is recommended.', 'wpvivid-backuprestore'); ?></div>
917
- <div style="padding-left: 10px;">
918
- <strong><?php _e('Method 1.'); ?></strong> <?php _e('If you have configured SMTP on your site, enter your email address and click the button below to send us the relevant information (website info and errors logs) when you are encountering errors. This will help us figure out what happened. Once the issue is resolved, we will inform you by your email address.', 'wpvivid-backuprestore'); ?>
919
- </div>
920
- <div style="padding:10px 10px 0">
921
- <span class="wpvivid-element-space-right"><?php echo __('WPvivid support email:', 'wpvivid-backuprestore'); ?></span><input type="text" id="wpvivid_support_mail" value="support@wpvivid.com" readonly />
922
- <span class="wpvivid-element-space-right"><?php _e('Your email:', 'wpvivid-backuprestore'); ?></span><input type="text" id="wpvivid_user_mail" />
923
- </div>
924
- <div style="padding:10px 10px 0">
925
- <div style="float: left;">
926
- <div class="wpvivid-element-space-bottom wpvivid-text-space-right wpvivid-debug-text-fix" style="float: left;">
927
- <?php _e('I am using:', 'wpvivid-backuprestore'); ?>
928
- </div>
929
- <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left;">
930
- <select id="wpvivid_debug_type">
931
- <option selected="selected" value="sharehost">share hosting</option>
932
- <option value="vps">VPS hosting</option>
933
- </select>
934
- </div>
935
- <div style="clear: both;"></div>
936
- </div>
937
- <div id="wpvivid_debug_host" style="float: left;">
938
- <div class="wpvivid-element-space-bottom wpvivid-text-space-right wpvivid-debug-text-fix" style="float: left;">
939
- <?php _e('My web hosting provider is:', 'wpvivid-backuprestore'); ?>
940
- </div>
941
- <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left;">
942
- <input type="text" id="wpvivid_host_provider"/></div>
943
- <div style="clear: both;"></div>
944
- </div>
945
- <div style="clear: both;"></div>
946
- </div>
947
- <div style="padding:0 10px;">
948
- <textarea id="wpvivid_debug_comment" class="wp-editor-area" style="width:100%; height: 200px;" autocomplete="off" cols="60" placeholder="<?php esc_attr_e('Please describe your problem here.', 'wpvivid-backuprestore'); ?>" ></textarea>
949
- </div>
950
- <div class="schedule-tab-block">
951
- <input class="button-primary" type="submit" value="<?php esc_attr_e( 'Send Debug Information to Us', 'wpvivid-backuprestore' ); ?>" onclick="wpvivid_click_send_debug_info();" />
952
- </div>
953
- <div style="clear:both;"></div>
954
- <div style="padding-left: 10px;">
955
- <strong><?php _e('Method 2.'); ?></strong> <?php _e('If you didn’t configure SMTP on your site, click the button below to download the relevant information (website info and error logs) to your PC when you are encountering some errors. Sending the files to us will help us diagnose what happened.', 'wpvivid-backuprestore'); ?>
956
- </div>
957
- <div class="schedule-tab-block">
958
- <input class="button-primary" id="wpvivid_download_website_info" type="submit" name="download-website-info" value="<?php esc_attr_e( 'Download', 'wpvivid-backuprestore' ); ?>" />
959
- </div>
960
- <thead class="website-info-head">
961
- <tr>
962
- <th class="row-title" style="min-width: 260px;"><?php _e( 'Website Info Key', 'wpvivid-backuprestore' ); ?></th>
963
- <th><?php _e( 'Website Info Value', 'wpvivid-backuprestore' ); ?></th>
964
- </tr>
965
- </thead>
966
- <tbody class="wpvivid-websiteinfo-list" id="wpvivid_websiteinfo_list">
967
- <?php
968
- global $wpvivid_plugin;
969
- $website_info=$wpvivid_plugin->get_website_info();
970
- if(!empty($website_info['data'])){
971
- foreach ($website_info['data'] as $key=>$value) { ?>
972
- <?php
973
- $website_value='';
974
- if (is_array($value)) {
975
- foreach ($value as $arr_value) {
976
- if (empty($website_value)) {
977
- $website_value = $website_value . $arr_value;
978
- } else {
979
- $website_value = $website_value . ', ' . $arr_value;
980
- }
981
- }
982
- }
983
- else{
984
- if($value === true || $value === false){
985
- if($value === true) {
986
- $website_value = 'true';
987
- }
988
- else{
989
- $website_value = 'false';
990
- }
991
- }
992
- else {
993
- $website_value = $value;
994
- }
995
- }
996
- ?>
997
- <tr>
998
- <td class="row-title tablelistcolumn"><label for="tablecell"><?php _e($key, 'wpvivid-backuprestore'); ?></label></td>
999
- <td class="tablelistcolumn"><?php _e($website_value, 'wpvivid-backuprestore'); ?></td>
1000
- </tr>
1001
- <?php }} ?>
1002
- </tbody>
1003
- </table>
1004
- </div>
1005
- <script>
1006
- jQuery('#wpvivid_download_website_info').click(function(){
1007
- wpvivid_download_website_info();
1008
- });
1009
-
1010
- /**
1011
- * Download the relevant website info and error logs to your PC for debugging purposes.
1012
- */
1013
- function wpvivid_download_website_info(){
1014
- wpvivid_location_href=true;
1015
- location.href =ajaxurl+'?_wpnonce='+wpvivid_ajax_object.ajax_nonce+'&action=wpvivid_create_debug_package';
1016
- }
1017
-
1018
- jQuery("#wpvivid_debug_type").change(function()
1019
- {
1020
- if(jQuery(this).val()=='sharehost')
1021
- {
1022
- jQuery("#wpvivid_debug_host").show();
1023
- }
1024
- else
1025
- {
1026
- jQuery("#wpvivid_debug_host").hide();
1027
- }
1028
- });
1029
-
1030
- function wpvivid_click_send_debug_info(){
1031
- var wpvivid_user_mail = jQuery('#wpvivid_user_mail').val();
1032
- var server_type = jQuery('#wpvivid_debug_type').val();
1033
- var host_provider = jQuery('#wpvivid_host_provider').val();
1034
- var comment = jQuery('#wpvivid_debug_comment').val();
1035
-
1036
- var ajax_data = {
1037
- 'action': 'wpvivid_send_debug_info',
1038
- 'user_mail': wpvivid_user_mail,
1039
- 'server_type':server_type,
1040
- 'host_provider':host_provider,
1041
- 'comment':comment
1042
- };
1043
- wpvivid_post_request(ajax_data, function (data) {
1044
- try {
1045
- var jsonarray = jQuery.parseJSON(data);
1046
- if (jsonarray.result === "success") {
1047
- alert("Send succeeded.");
1048
- }
1049
- else {
1050
- alert(jsonarray.error);
1051
- }
1052
- }
1053
- catch (err) {
1054
- alert(err);
1055
- }
1056
- }, function (XMLHttpRequest, textStatus, errorThrown) {
1057
- var error_message = wpvivid_output_ajaxerror('sending debug information', textStatus, errorThrown);
1058
- alert(error_message);
1059
- });
1060
- }
1061
- </script>
1062
- <?php
1063
- }
1064
-
1065
- public function wpvivid_add_page_log()
1066
- {
1067
- global $wpvivid_plugin;
1068
- $display_log_count=array(0=>"10",1=>"20",2=>"30",3=>"40",4=>"50");
1069
- $max_log_diaplay=20;
1070
- $loglist=$wpvivid_plugin->get_log_list_ex();
1071
- ?>
1072
- <div id="logs-page" class="log-tab-content wpvivid_tab_log" name="tab-logs">
1073
- <table class="wp-list-table widefat plugins">
1074
- <thead class="log-head">
1075
- <tr>
1076
- <th class="row-title"><?php _e( 'Date', 'wpvivid-backuprestore' ); ?></th>
1077
- <th><?php _e( 'Log Type', 'wpvivid-backuprestore' ); ?></th>
1078
- <th><?php _e( 'Log File Name', 'wpvivid-backuprestore' ); ?></th>
1079
- <th><?php _e( 'Action', 'wpvivid-backuprestore' ); ?></th>
1080
- </tr>
1081
- </thead>
1082
- <tbody class="wpvivid-loglist" id="wpvivid_loglist">
1083
- <?php
1084
- $html = '';
1085
- $html = apply_filters('wpvivid_get_log_list', $html);
1086
- echo $html['html'];
1087
- ?>
1088
- </tbody>
1089
- </table>
1090
- <div style="padding-top: 10px; text-align: center;">
1091
- <input class="button-secondary log-page" id="wpvivid_pre_log_page" type="submit" value="<?php esc_attr_e( ' < Pre page ', 'wpvivid-backuprestore' ); ?>" />
1092
- <div style="font-size: 12px; display: inline-block; padding-left: 10px;">
1093
- <span id="wpvivid_log_page_info" style="line-height: 35px;">
1094
- <?php
1095
- $current_page=1;
1096
- $max_page=ceil(sizeof($loglist['log_list']['file'])/$max_log_diaplay);
1097
- if($max_page == 0) $max_page = 1;
1098
- echo $current_page.' / '.$max_page;
1099
- ?>
1100
- </span>
1101
- </div>
1102
- <input class="button-secondary log-page" id="wpvivid_next_log_page" type="submit" value="<?php esc_attr_e( ' Next page > ', 'wpvivid-backuprestore' ); ?>" />
1103
- <div style="float: right;">
1104
- <select name="" id="wpvivid_display_log_count">
1105
- <?php
1106
- foreach ($display_log_count as $value){
1107
- if($value == $max_log_diaplay){
1108
- echo '<option selected="selected" value="' . $value . '">' . $value . '</option>';
1109
- }
1110
- else {
1111
- echo '<option value="' . $value . '">' . $value . '</option>';
1112
- }
1113
- }
1114
- ?>
1115
- </select>
1116
- </div>
1117
- </div>
1118
- </div>
1119
- <script>
1120
- jQuery('#wpvivid_display_log_count').on("change", function(){
1121
- wpvivid_display_log_page();
1122
- });
1123
-
1124
- jQuery('#wpvivid_pre_log_page').click(function(){
1125
- wpvivid_pre_log_page();
1126
- });
1127
-
1128
- jQuery('#wpvivid_next_log_page').click(function(){
1129
- wpvivid_next_log_page();
1130
- });
1131
-
1132
- function wpvivid_pre_log_page(){
1133
- if(wpvivid_cur_log_page > 1){
1134
- wpvivid_cur_log_page--;
1135
- }
1136
- wpvivid_display_log_page();
1137
- }
1138
-
1139
- function wpvivid_next_log_page(){
1140
- var display_count = jQuery("#wpvivid_display_log_count option:selected").val();
1141
- var max_pages=Math.ceil(wpvivid_log_count/display_count);
1142
- if(wpvivid_cur_log_page < max_pages){
1143
- wpvivid_cur_log_page++;
1144
- }
1145
- wpvivid_display_log_page();
1146
- }
1147
-
1148
- function wpvivid_display_log_page(){
1149
- var display_count = jQuery("#wpvivid_display_log_count option:selected").val();
1150
- var max_pages=Math.ceil(wpvivid_log_count/display_count);
1151
- if(max_pages == 0) max_pages = 1;
1152
- jQuery('#wpvivid_log_page_info').html(wpvivid_cur_log_page+ " / "+max_pages);
1153
-
1154
- var begin = (wpvivid_cur_log_page - 1) * display_count;
1155
- var end = parseInt(begin) + parseInt(display_count);
1156
- jQuery("#wpvivid_loglist tr").hide();
1157
- jQuery('#wpvivid_loglist tr').each(function(i){
1158
- if (i >= begin && i < end)
1159
- {
1160
- jQuery(this).show();
1161
- }
1162
- });
1163
- }
1164
-
1165
- function wpvivid_retrieve_log_list()
1166
- {
1167
- var ajax_data = {
1168
- 'action': 'wpvivid_get_log_list'
1169
- };
1170
- wpvivid_post_request(ajax_data, function(data){
1171
- try {
1172
- var jsonarray = jQuery.parseJSON(data);
1173
- if (jsonarray.result === "success") {
1174
- jQuery('#wpvivid_loglist').html("");
1175
- jQuery('#wpvivid_loglist').append(jsonarray.html);
1176
- wpvivid_log_count = jsonarray.log_count;
1177
- wpvivid_display_log_page();
1178
- }
1179
- }
1180
- catch(err){
1181
- alert(err);
1182
- }
1183
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1184
- setTimeout(function () {
1185
- wpvivid_retrieve_log_list();
1186
- }, 3000);
1187
- });
1188
- }
1189
- </script>
1190
- <?php
1191
- }
1192
-
1193
- public function wpvivid_add_page_read_log()
1194
- {
1195
- ?>
1196
- <div id="log-read-page" class="wrap-tab-content wpvivid_tab_read_log" style="display:none;">
1197
- <div class="postbox restore_log" id="wpvivid_read_log_content">
1198
- <div></div>
1199
- </div>
1200
- </div>
1201
- <?php
1202
- }
1203
-
1204
- public function wpvivid_add_page_mwp()
1205
- {
1206
- ?>
1207
- <div id="mwp-page" class="wrap-tab-content wpvivid_tab_mainwp" name="tab-mwp" style="display:none;">
1208
- <div style="padding: 10px; background-color: #fff;">
1209
- <div style="margin-bottom: 10px;">
1210
- <?php echo __('If you are a MainWP user, you can set up and control WPvivid Backup Free and Pro for every child site directly from your MainWP dashboard, using our WPvivid Backup for MainWP extension.', 'wpvivid-backuprestore'); ?>
1211
- </div>
1212
- <div style="margin-bottom: 10px;">
1213
- <input type="button" class="button-primary" id="wpvivid_download_mainwp_extension" value="<?php esc_attr_e('Download WPvivid Backup for MainWP', 'wpvivid-backuprestore'); ?>" />
1214
- </div>
1215
- <div style="margin-bottom: 10px;">
1216
- <?php _e('1. Create and download backups for a specific child site', 'wpvivid-backuprestore'); ?>
1217
- </div>
1218
- <div style="margin-bottom: 10px;">
1219
- <?php _e('2. Set backup schedules for all child sites', 'wpvivid-backuprestore'); ?>
1220
- </div>
1221
- <div style="margin-bottom: 10px;">
1222
- <?php
1223
- echo __('3. Set WPvivid Backup Free and Pro settings for all child sites', 'wpvivid-backuprestore');
1224
- ?>
1225
- </div>
1226
- <div style="margin-bottom: 10px;">
1227
- <?php
1228
- echo __('4. Install, claim and update WPvivid Backup Pro for child sites in bulk', 'wpvivid-backuprestore');
1229
- ?>
1230
- </div>
1231
- <div>
1232
- <?php
1233
- echo __('5. Set up remote storage for child sites in bulk (for WPvivid Backup Pro only)', 'wpvivid-backuprestore');
1234
- ?>
1235
- </div>
1236
- </div>
1237
- </div>
1238
- <script>
1239
- jQuery('#wpvivid_download_mainwp_extension').click(function(){
1240
- var tempwindow=window.open('_blank');
1241
- tempwindow.location='https://wordpress.org/plugins/wpvivid-backup-mainwp';
1242
- });
1243
- jQuery('#wpvivid_ask_for_discount').click(function(){
1244
- var tempwindow=window.open('_blank');
1245
- tempwindow.location='https://wpvivid.com/wpvivid-backup-for-mainwp';
1246
- });
1247
- </script>
1248
- <?php
1249
- }
1250
-
1251
- public function wpvivid_add_page_premium(){
1252
- ?>
1253
- <div id="premium-page" class="wrap-tab-content wpvivid_tab_premium" name="tab-premium" style="display: none;">
1254
- <table class="wp-list-table widefat plugins" style="border-collapse: collapse;">
1255
- <thead>
1256
- <tr class="backup-list-head" style="border-bottom: 0;">
1257
- <th><?php _e('Features', 'wpvivid-backuprestore'); ?></th>
1258
- <th style="text-align:center;"><?php _e('Blogger', 'wpvivid-backuprestore'); ?></th>
1259
- <th style="text-align:center;"><?php _e('Freelancer', 'wpvivid-backuprestore'); ?></th>
1260
- <th style="text-align:center;"><?php _e('Small Business', 'wpvivid-backuprestore'); ?></th>
1261
- <th style="text-align:center;"><?php _e('Ultimate', 'wpvivid-backuprestore'); ?></th>
1262
- </tr>
1263
- </thead>
1264
- <tbody class="wpvivid-backuplist">
1265
- <tr style="">
1266
- <td>
1267
- <p><strong><?php _e('Domains', 'wpvivid-backuprestore'); ?></strong></p>
1268
- <p><strong><?php _e('Backup & Migration Pro', 'wpvivid-backuprestore'); ?></strong></p>
1269
- <p><strong><?php _e('Image Optimization Pro (Unlimited/domain)', 'wpvivid-backuprestore'); ?></strong></p>
1270
- <p><strong><?php _e('Mulitsite Support', 'wpvivid-backuprestore'); ?></strong></p>
1271
- <p><strong><?php _e('Staging Pro', 'wpvivid-backuprestore'); ?></strong></p>
1272
- <p><strong><?php _e('White Label', 'wpvivid-backuprestore'); ?></strong></p>
1273
- <p><strong><?php _e('Roles & Capabilities', 'wpvivid-backuprestore'); ?></strong></p>
1274
- </td>
1275
- <td style="text-align:center;">
1276
- <p><span style="color: #81d742;"><?php _e('2 domains', 'wpvivid-backuprestore'); ?></span></p>
1277
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1278
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1279
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1280
- <p><span style="height: 12px;width: 12px;background-color: #f1f1f1;border-radius: 50%;display: inline-block;"></span></p>
1281
- <p><span style="height: 12px;width: 12px;background-color: #f1f1f1;border-radius: 50%;display: inline-block;"></span></p>
1282
- <p><span style="height: 12px;width: 12px;background-color: #f1f1f1;border-radius: 50%;display: inline-block;"></span></p>
1283
- </td>
1284
- <td style="text-align:center;">
1285
- <p><span style="color: #81d742;"><?php _e('Up to 10 domains', 'wpvivid-backuprestore'); ?></span></p>
1286
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1287
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1288
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1289
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1290
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1291
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1292
- </td>
1293
- <td style="text-align:center;">
1294
- <p><span style="color: #81d742;"><?php _e('Up to 50 domains', 'wpvivid-backuprestore'); ?></span></p>
1295
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1296
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1297
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1298
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1299
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1300
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1301
- </td>
1302
- <td style="text-align:center;">
1303
- <p><span style="color: #81d742;"><?php _e('Unlimited', 'wpvivid-backuprestore'); ?></span></p>
1304
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1305
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1306
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1307
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1308
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1309
- <p><span style="height: 12px;width: 12px;background-color: #81d742;border-radius: 50%;display: inline-block;"></span></p>
1310
- </td>
1311
- </tr>
1312
- </tbody>
1313
- <tfoot>
1314
- <tr>
1315
- <th><?php _e('*No credit card needed. Trial starts with the Free Trial plan with 2 sites. You can choose a plan at the end of the trial.', 'wpvivid-backuprestore'); ?></th>
1316
- <th colspan="4" style="text-align:center;"><p style="margin-top: 6px;"><a href="https://wpvivid.com/pricing" class="page-title-action"><?php _e('START 14-DAY FREE TRIAL', 'wpvivid-backuprestore'); ?></a></p></th>
1317
- </tr>
1318
- </tfoot>
1319
- </table>
1320
- </div>
1321
- <?php
1322
- }
1323
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/admin/css/wpvivid-admin.css DELETED
@@ -1,266 +0,0 @@
1
- /**
2
- * All of the CSS for your admin-specific functionality should be
3
- * included in this file.
4
- */
5
-
6
- .list-top-chip{float:left;display:block; vertical-align:middle; }
7
- .list-top-chip::after{content:" "}
8
- .backup-basic-info{min-width:100px; margin:10px; float:left;}
9
- .quickbackup{width:calc(100% - 290px);float:left; box-sizing:border-box;margin-right:10px; padding:10px;}
10
- .quickbackup label{display:inline-block;margin-bottom:10px;}
11
- .qucikbackup-schedule{width:280px; float:left; box-sizing:border-box; min-width:280px;}
12
- .quickstart-archive-block{width:33%;float:left; position:relative; box-sizing:border-box; }
13
- .quickstart-storage-block{width:33%;padding:10px; float:left; position:relative; box-sizing:border-box;}
14
- .quickstart-btn{width:33%;padding:10px; float:left; position:relative; box-sizing:border-box;}
15
- .quickbackup-btn{display:block !important; margin:0 auto !important;width:150px;height:50px !important; line-height:48px !important; font-size:20px !important;}
16
- .schedule-block{float:left;width:100%;padding:0 10px 10px 10px;box-sizing:border-box;}
17
- .postbox:after{content: ".";display: block;height: 0;clear: both;visibility: hidden;}
18
- .quickbackup-block .fieldset label{margin-bottom:5px;}
19
- .custom-info{padding:10px;}
20
- .quickstart-storage-setting{width:100%;float:left; padding-left:10px; box-sizing:border-box;background-color:#f1f1f1; margin-bottom:10px;}
21
- .action-progress-bar{background-color:#f1f1f1 !important;margin:10px;color:#000;}
22
- .action-progress-bar-percent{background-color:#0085ba !important;color:#fff;}
23
- .storage-providers{float:left;padding:10px;cursor:pointer;}
24
- .storage-providers:hover{background-color:#f1f1f1 !important; color:#fff !important;}
25
- .storage-providers-active{background-color:#0085ba !important; color:#fff !important;}
26
- .storage-account-block{padding:10px;}
27
- .storage-account-button{margin:10px 10px 10px 0 !important;display:block !important; float:left;}
28
- .schedule-tab-block{padding:10px;}
29
- .schedule-tab-block input{display:line-block; margin-top:10px; margin-bottom:10px;margin-right:10px;}
30
- .setting-tab-block{padding: 10px 10px 10px 0;}
31
- .setting-tab-block input{display:line-block; margin-top:10px; margin-bottom:10px;margin-right:10px;}
32
- .setting-page-content{padding-left:10px;}
33
- .backup-log-btn{height:30px;float:left; margin-left:10px; margin-bottom:10px;}
34
- @keyframes rotate { 0% { transform: rotate(0); } 100% { transform: rotate(359.9deg); } }
35
- .wpvivid-backup-storage-list tr:hover,
36
- .wpvivid-websiteinfo-list tr:hover,
37
- .wpvivid-backuplist tr:hover,
38
- .wpvivid-loglist tr:hover,
39
- .wpvivid-remote-storage-list tr:hover {background-color: #f9f9f9;}
40
- .restore_log{padding:10px; width:100%; height:500px; overflow:auto; box-sizing:border-box;}
41
- .restore-button-position{margin:10px 10px 10px 0px; float:left;}
42
- .restore-button-position input{margin-right:10px;}
43
- .nav-tab.delete{display: block;overflow: hidden;position:relative;}
44
- .nav-tab-delete-img{position: absolute;top: 0px;right: 3px;}
45
- .button-secondary.log-page{background: #fff;color: #00a0d2;border: 1px solid #00a0d2;margin: 3px;}
46
- .button-secondary.log-page:hover{color: #0b82a7;border: 1px solid #0b82a7;}
47
- .button-secondary.log-page:focus{color: #00a0d2;border: 1px solid #00a0d2;}
48
- .remote-storage-set-default-block{padding-top:10px;padding-left:10px;padding-right:10px;}
49
- .remote-storage-set-default-block input{display:line-block; margin-top:10px; margin-bottom:10px;margin-right:10px;}
50
- .remote-storage-ftp-passive-block,
51
- .remote-storage-amazons3-storage-class,
52
- .remote-storage-amazons3-encryption{padding-left:10px;}
53
- .remote-storage-ftp-passive-block input,
54
- .remote-storage-amazons3-storage-class input,
55
- .remote-storage-amazons3-encryption input{display:line-block; margin-top:10px; margin-bottom:10px;margin-right:10px;}
56
- .backup-list-head{}
57
- .storage-account-form {padding-top: 1px; padding-bottom: 1px;}
58
- .quicktransfer{width:100%; float:left; box-sizing:border-box;margin-right:10px; padding:10px;}
59
- .quicktransfer label{display:inline-block;margin-bottom:10px;}
60
- .quicktransfer-btn{display:block !important; margin:0 auto !important;width:220px;height:50px !important; line-height:48px !important; font-size:20px !important;}
61
- .wpvivid-feature-pro{font-size:12px;border:1px solid #f1f1f1;padding:3px 5px;margin: 10px 10px 10px 0;border-radius:5px;}
62
- @media screen and (max-width:1650px) {
63
- .qucikbackup-schedule{
64
- float:none;
65
- width:100%;
66
- }
67
- .quickbackup{
68
- float:none;
69
- width:100%;
70
- }
71
- .export-import-block{
72
- float:none;
73
- width:100%;
74
- }
75
- }
76
- @media only screen and (max-width: 1350px){
77
- #poststuff #post-body.columns-2 {
78
- margin:0;
79
- }
80
- #wpbody-content #post-body.columns-2 #postbox-container-1 {
81
- margin-right: 0;
82
- width: 100%;
83
- }
84
-
85
- }
86
-
87
- @media screen and (max-width:1315px) {
88
- .quickstart-storage-block{
89
- width:50%;
90
- }
91
- .quickstart-archive-block{
92
- width:50%;
93
- }
94
- .quickstart-btn{
95
- clear:both;
96
- float:none;
97
- width:100%;
98
- }
99
- }
100
- @media screen and (max-width:800px){
101
- .tablelistcolumn{
102
- display:block;
103
- }
104
- .backup-list-head{
105
- display:none;
106
- }
107
- .backuptime{
108
- font-size:16px;
109
- }
110
- .backuplist-delete-backup{
111
- display:none;
112
- }
113
- .website-info-head{
114
- display:none;
115
- }
116
- .log-head{
117
- display:none;
118
- }
119
- .lafowef{
120
- display:none;
121
- }
122
- .storage-account-form input{
123
- width:360px;
124
- }
125
- }
126
- @media screen and (max-width:600px) {
127
- .quickstart-storage-block{
128
- float:none;
129
- width:100%;
130
- }
131
- .quickstart-archive-block{
132
- float:none;
133
- width:100%;
134
- }
135
- .quickstart-btn{
136
- float:none;
137
- width:100%;
138
- }
139
- }
140
-
141
- /* Popup container */
142
- .wpvivid-popup {
143
- position: relative;
144
- display: inline-block;
145
- cursor: pointer;
146
- }
147
-
148
- /* The actual popup (appears on top) */
149
- .wpvivid-popup .wpvivid-popuptext {
150
- visibility: hidden;
151
- width: 220px;
152
- background-color: #555;
153
- color: #fff;
154
- text-align: center;
155
- border-radius: 6px;
156
- padding: 8px 0;
157
- position: absolute;
158
- z-index: 1;
159
- bottom: 75%;
160
- margin-left: -80px;
161
- }
162
-
163
- /* Popup arrow */
164
- .wpvivid-popup .wpvivid-popuptext::after {
165
- content: "";
166
- position: absolute;
167
- top: 100%;
168
- left: 50%;
169
- margin-left: -5px;
170
- border-width: 5px;
171
- border-style: solid;
172
- border-color: #555 transparent transparent transparent;
173
- }
174
-
175
- /* Toggle this class when clicking on the popup container (hide and show the popup) */
176
- .wpvivid-popup .show {
177
- visibility: visible;
178
- -webkit-animation: fadeIn 1s;
179
- animation: fadeIn 1s
180
- }
181
-
182
- .wpvivid-popup .hide {
183
- visibility: hidden;
184
- -webkit-animation: fadeIn 1s;
185
- animation: fadeIn 1s
186
- }
187
-
188
- /* Add animation (fade in the popup) */
189
- @-webkit-keyframes fadeIn {
190
- from {opacity: 0;}
191
- to {opacity: 1;}
192
- }
193
-
194
- @keyframes fadeIn {
195
- from {opacity: 0;}
196
- to {opacity:1 ;}
197
- }
198
-
199
- .wpvivid-storage-form{
200
- margin-top:10px;
201
- margin-bottom:5px;
202
- }
203
-
204
- .wpvivid-storage-select{
205
- margin-top:10px;
206
- margin-bottom:5px;
207
- padding-bottom:8px;
208
- padding-left:2px;
209
- }
210
-
211
- .wpvivid-storage-form input[type=text],
212
- .wpvivid-storage-form input[type=password]{
213
- width: 350px;
214
- }
215
-
216
- .wpvivid-storage-form-desc{
217
- background-color:#f5f5f5;
218
- margin-top:10px;
219
- padding:4px 5px;
220
- }
221
-
222
- .wpvivid-debug-text-fix{
223
- height: 28px;
224
- line-height: 28px;
225
- }
226
-
227
- @media screen and (max-width: 782px) {
228
- .wpvivid-debug-text-fix{
229
- height: 36px;
230
- line-height: 36px;
231
- }
232
- }
233
-
234
- .wpvivid-text-space-bottom{margin-bottom: 5px;}
235
- .wpvivid-text-space-right{margin-right: 5px;}
236
- .wpvivid-element-space-bottom{margin-bottom: 10px;}
237
- .wpvivid-element-space-right{margin-right: 10px;}
238
- .wpvivid-export-type-provider{float: left; cursor: pointer; padding: 10px; height: 30px; line-height: 30px; border-right: 1px solid #e5e5e5;}
239
- .wpvivid-export-type-provider:hover{background-color:#f1f1f1 !important;}
240
- .wpvivid-export-type-provider-active{background-color:#0085ba !important;}
241
- .wpvivid-import-log{padding:10px; width:100%; height:500px; overflow:auto; box-sizing:border-box;}
242
- .import > tbody > :nth-child(odd) {background-color: #ffffff;}
243
- .import > tbody tr:hover {background-color: #f9f9f9;}
244
- .import .column-delete {width: 10%;}
245
- .wpvivid-export-import-block span{margin: 0;}
246
- .export-import-block{width:100%; box-sizing:border-box;margin-right:10px; padding:10px;}
247
- .export-import-block label{display:inline-block;}
248
- .export-import-block a{text-decoration: none;}
249
-
250
- .quickbackup-addon{width:100%; box-sizing:border-box;margin-right:10px; padding:10px;}
251
- .quickbackup-addon label{display:inline-block;}
252
- @media screen and (max-width:1650px) {
253
- .quickbackup-addon{
254
- float:none;
255
- width:100%;
256
- }
257
- }
258
- .quickbackup-addon a{
259
- text-decoration: none;
260
- }
261
-
262
- .wpvivid-backup-tips{
263
- float:left;
264
- width:100%;
265
- background-color:#f1f1f1;
266
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/admin/index.php DELETED
@@ -1 +0,0 @@
1
- <?php // Silence is golden
 
trunk/admin/js/wpvivid-admin.js DELETED
@@ -1,683 +0,0 @@
1
- var task_retry_times=0;
2
- var running_backup_taskid='';
3
- var tmp_current_click_backupid = '';
4
- var m_need_update=true;
5
- var m_restore_backup_id;
6
- var m_backup_task_id;
7
- var m_downloading_file_name = '';
8
- var m_downloading_id = '';
9
- var wpvivid_settings_changed = false;
10
- var wpvivid_cur_log_page = 1;
11
- var wpvivid_completed_backup = 1;
12
- var wpvivid_prepare_backup=false;
13
- var wpvivid_restoring=false;
14
- var wpvivid_location_href=false;
15
- var wpvivid_editing_storage_id = '';
16
- var wpvivid_editing_storage_type = '';
17
- var wpvivid_restore_download_array;
18
- var wpvivid_restore_download_index = 0;
19
- var wpvivid_get_download_restore_progress_retry = 0;
20
- var wpvivid_restore_timeout = false;
21
- var wpvivid_restore_need_download = false;
22
- var wpvivid_display_restore_backup = false;
23
- var wpvivid_restore_backup_type = '';
24
- var wpvivid_display_restore_check = false;
25
- var wpvivid_restore_sure = false;
26
- var wpvivid_resotre_is_migrate=0;
27
- (function ($) {
28
- 'use strict';
29
-
30
- /**
31
- * All of the code for your admin-facing JavaScript source
32
- * should reside in this file.
33
- *
34
- * Note: It has been assumed you will write jQuery code here, so the
35
- * $ function reference has been prepared for usage within the scope
36
- * of this function.
37
- *
38
- * This enables you to define handlers, for when the DOM is ready:
39
- *
40
- * $(function() {
41
- *
42
- * });
43
- *
44
- * When the window is loaded:
45
- *
46
- * $( window ).load(function() {
47
- *
48
- * });
49
- *
50
- * ...and/or other possibilities.
51
- *
52
- * Ideally, it is not considered best practise to attach more than a
53
- * single DOM-ready or window-load handler for a particular page.
54
- * Although scripts in the WordPress core, Plugins and Themes may be
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_interface_flow_control();
61
-
62
- $('input[option=review]').click(function(){
63
- var name = jQuery(this).prop('name');
64
- wpvivid_add_review_info(name);
65
- });
66
-
67
- $(document).on('click', '.notice-wp-cron .notice-dismiss', function(){
68
- var ajax_data = {
69
- 'action': 'wpvivid_hide_wp_cron_notice'
70
- };
71
- wpvivid_post_request(ajax_data, function(res){
72
- }, function(XMLHttpRequest, textStatus, errorThrown) {
73
- });
74
- });
75
- });
76
-
77
- })(jQuery);
78
-
79
- function wpvivid_popup_tour(style) {
80
- var popup = document.getElementById("wpvivid_popup_tour");
81
- if (popup != null) {
82
- popup.classList.add(style);
83
- }
84
- }
85
-
86
- window.onbeforeunload = function(e) {
87
- if (wpvivid_settings_changed) {
88
- if (wpvivid_location_href){
89
- wpvivid_location_href = false;
90
- }
91
- else {
92
- return 'You are leaving the page without saving your changes, any unsaved changes on the page will be lost, are you sure you want to continue?';
93
- }
94
- }
95
- }
96
-
97
- /**
98
- * Refresh the scheduled task list as regularly as a preset interval(3-minute), to retrieve and activate the scheduled cron jobs.
99
- */
100
- function wpvivid_activate_cron(){
101
- var next_get_time = 3 * 60 * 1000;
102
- wpvivid_cron_task();
103
- setTimeout("wpvivid_activate_cron()", next_get_time);
104
- setTimeout(function(){
105
- m_need_update=true;
106
- }, 10000);
107
- }
108
-
109
- /**
110
- * Send an Ajax request
111
- *
112
- * @param ajax_data - Data in Ajax request
113
- * @param callback - A callback function when the request is succeeded
114
- * @param error_callback - A callback function when the request is failed
115
- * @param time_out - The timeout for Ajax request
116
- */
117
- function wpvivid_post_request(ajax_data, callback, error_callback, time_out){
118
- if(typeof time_out === 'undefined') time_out = 30000;
119
- ajax_data.nonce=wpvivid_ajax_object.ajax_nonce;
120
- jQuery.ajax({
121
- type: "post",
122
- url: wpvivid_ajax_object.ajax_url,
123
- data: ajax_data,
124
- success: function (data) {
125
- callback(data);
126
- },
127
- error: function (XMLHttpRequest, textStatus, errorThrown) {
128
- error_callback(XMLHttpRequest, textStatus, errorThrown);
129
- },
130
- timeout: time_out
131
- });
132
- }
133
-
134
- /**
135
- * Check if there are running tasks (backup and download)
136
- */
137
- function wpvivid_check_runningtask(){
138
- var ajax_data = {
139
- 'action': 'wpvivid_list_tasks',
140
- 'backup_id': tmp_current_click_backupid
141
- };
142
- if(wpvivid_restoring === false) {
143
- wpvivid_post_request(ajax_data, function (data) {
144
- setTimeout(function () {
145
- wpvivid_manage_task();
146
- }, 3000);
147
- try {
148
- var jsonarray = jQuery.parseJSON(data);
149
- if (jsonarray.success_notice_html != false) {
150
- jQuery('#wpvivid_backup_notice').show();
151
- jQuery('#wpvivid_backup_notice').append(jsonarray.success_notice_html);
152
- }
153
- if(jsonarray.error_notice_html != false){
154
- jQuery('#wpvivid_backup_notice').show();
155
- jQuery.each(jsonarray.error_notice_html, function (index, value) {
156
- jQuery('#wpvivid_backup_notice').append(value.error_msg);
157
- });
158
- }
159
- if(jsonarray.backuplist_html != false) {
160
- jQuery('#wpvivid_backup_list').html('');
161
- jQuery('#wpvivid_backup_list').append(jsonarray.backuplist_html);
162
- }
163
- var b_has_data = false;
164
- if (jsonarray.backup.data.length !== 0) {
165
- b_has_data = true;
166
- task_retry_times = 0;
167
- if (jsonarray.backup.result === 'success') {
168
- wpvivid_prepare_backup = false;
169
- jQuery.each(jsonarray.backup.data, function (index, value) {
170
- if (value.status.str === 'ready') {
171
- jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
172
- m_need_update = true;
173
- }
174
- else if (value.status.str === 'running') {
175
- running_backup_taskid = index;
176
- wpvivid_control_backup_lock();
177
- jQuery('#wpvivid_postbox_backup_percent').show();
178
- jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
179
- m_need_update = true;
180
- }
181
- else if (value.status.str === 'wait_resume') {
182
- running_backup_taskid = index;
183
- wpvivid_control_backup_lock();
184
- jQuery('#wpvivid_postbox_backup_percent').show();
185
- jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
186
- if (value.data.next_resume_time !== 'get next resume time failed.') {
187
- wpvivid_resume_backup(index, value.data.next_resume_time);
188
- }
189
- else {
190
- wpvivid_delete_backup_task(index);
191
- }
192
- }
193
- else if (value.status.str === 'no_responds') {
194
- running_backup_taskid = index;
195
- wpvivid_control_backup_lock();
196
- jQuery('#wpvivid_postbox_backup_percent').show();
197
- jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
198
- m_need_update = true;
199
- }
200
- else if (value.status.str === 'completed') {
201
- jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
202
- wpvivid_control_backup_unlock();
203
- jQuery('#wpvivid_postbox_backup_percent').hide();
204
- jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
205
- jQuery('#wpvivid_loglist').html("");
206
- jQuery('#wpvivid_loglist').append(jsonarray.log_html);
207
- wpvivid_log_count = jsonarray.log_count;
208
- wpvivid_display_log_page();
209
- running_backup_taskid = '';
210
- m_backup_task_id = '';
211
- m_need_update = true;
212
- }
213
- else if (value.status.str === 'error') {
214
- jQuery('#wpvivid_postbox_backup_percent').html(value.progress_html);
215
- wpvivid_control_backup_unlock();
216
- jQuery('#wpvivid_postbox_backup_percent').hide();
217
- jQuery('#wpvivid_last_backup_msg').html(jsonarray.last_msg_html);
218
- jQuery('#wpvivid_loglist').html("");
219
- jQuery('#wpvivid_loglist').append(jsonarray.log_html);
220
- running_backup_taskid = '';
221
- m_backup_task_id = '';
222
- m_need_update = true;
223
- }
224
- });
225
- }
226
- }
227
- else
228
- {
229
- if(running_backup_taskid !== '')
230
- {
231
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
232
- jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
233
- wpvivid_control_backup_unlock();
234
- jQuery('#wpvivid_postbox_backup_percent').hide();
235
- wpvivid_retrieve_backup_list();
236
- wpvivid_retrieve_last_backup_message();
237
- wpvivid_retrieve_log_list();
238
- running_backup_taskid='';
239
- }
240
- }
241
- /*if (jsonarray.download.length !== 0) {
242
- if(jsonarray.download.result === 'success') {
243
- b_has_data = true;
244
- task_retry_times = 0;
245
- var i = 0;
246
- var file_name = '';
247
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).html("");
248
- var b_download_finish = false;
249
- jQuery.each(jsonarray.download.files, function (index, value) {
250
- i++;
251
- file_name = index;
252
- var progress = '0%';
253
- if (value.status === 'need_download') {
254
- if (m_downloading_file_name === file_name) {
255
- m_need_update = true;
256
- }
257
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
258
- //b_download_finish=true;
259
- }
260
- else if (value.status === 'running') {
261
- if (m_downloading_file_name === file_name) {
262
- wpvivid_lock_download(tmp_current_click_backupid);
263
- }
264
- m_need_update = true;
265
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
266
- b_download_finish = false;
267
- }
268
- else if (value.status === 'completed') {
269
- if (m_downloading_file_name === file_name) {
270
- wpvivid_unlock_download(tmp_current_click_backupid);
271
- m_downloading_id = '';
272
- m_downloading_file_name = '';
273
- }
274
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
275
- b_download_finish = true;
276
- }
277
- else if (value.status === 'error') {
278
- if (m_downloading_file_name === file_name) {
279
- wpvivid_unlock_download(tmp_current_click_backupid);
280
- m_downloading_id = '';
281
- m_downloading_file_name = '';
282
- }
283
- alert(value.error);
284
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
285
- b_download_finish = true;
286
- }
287
- else if (value.status === 'timeout') {
288
- if (m_downloading_file_name === file_name) {
289
- wpvivid_unlock_download(tmp_current_click_backupid);
290
- m_downloading_id = '';
291
- m_downloading_file_name = '';
292
- }
293
- alert('Download timeout, please retry.');
294
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(value.html);
295
- b_download_finish = true;
296
- }
297
- });
298
- jQuery('#wpvivid_file_part_' + tmp_current_click_backupid).append(jsonarray.download.place_html);
299
- if (b_download_finish == true) {
300
- tmp_current_click_backupid = '';
301
- }
302
- }
303
- else{
304
- b_has_data = true;
305
- alert(jsonarray.download.error);
306
- }
307
- }*/
308
- if (!b_has_data) {
309
- task_retry_times++;
310
- if (task_retry_times < 5) {
311
- m_need_update = true;
312
- }
313
- }
314
- }
315
- catch(err){
316
- alert(err);
317
- }
318
- }, function (XMLHttpRequest, textStatus, errorThrown)
319
- {
320
- task_retry_times++;
321
- if (task_retry_times < 5)
322
- {
323
- setTimeout(function () {
324
- m_need_update = true;
325
- wpvivid_manage_task();
326
- }, 3000);
327
- }
328
- });
329
- }
330
- }
331
-
332
- /**
333
- * This function will show the log on a text box.
334
- *
335
- * @param data - The log message returned by server
336
- */
337
- function wpvivid_show_log(data, content_id){
338
- jQuery('#'+content_id).html("");
339
- try {
340
- var jsonarray = jQuery.parseJSON(data);
341
- if (jsonarray.result === "success") {
342
- var log_data = jsonarray.data;
343
- while (log_data.indexOf('\n') >= 0) {
344
- var iLength = log_data.indexOf('\n');
345
- var log = log_data.substring(0, iLength);
346
- log_data = log_data.substring(iLength + 1);
347
- var insert_log = "<div style=\"clear:both;\">" + log + "</div>";
348
- jQuery('#'+content_id).append(insert_log);
349
- }
350
- }
351
- else if (jsonarray.result === "failed") {
352
- jQuery('#'+content_id).html(jsonarray.error);
353
- }
354
- }
355
- catch(err){
356
- alert(err);
357
- var div = "Reading the log failed. Please try again.";
358
- jQuery('#'+content_id).html(div);
359
- }
360
- }
361
-
362
- /**
363
- * Resume the backup task automatically in 1 minute in a timeout situation
364
- *
365
- * @param backup_id - A unique ID for a backup
366
- * @param next_resume_time - A time interval for resuming next timeout backup task
367
- */
368
- function wpvivid_resume_backup(backup_id, next_resume_time){
369
- if(next_resume_time < 0){
370
- next_resume_time = 0;
371
- }
372
- next_resume_time = next_resume_time * 1000;
373
- setTimeout("wpvivid_cron_task()", next_resume_time);
374
- setTimeout(function(){
375
- task_retry_times = 0;
376
- m_need_update=true;
377
- }, next_resume_time);
378
- }
379
-
380
- /**
381
- * This function will retrieve the last backup message
382
- */
383
- function wpvivid_retrieve_last_backup_message(){
384
- var ajax_data={
385
- 'action': 'wpvivid_get_last_backup'
386
- };
387
- wpvivid_post_request(ajax_data, function(data){
388
- try {
389
- var jsonarray = jQuery.parseJSON(data);
390
- jQuery('#wpvivid_last_backup_msg').html(jsonarray.data);
391
- }
392
- catch(err){
393
- alert(err);
394
- }
395
- }, function(XMLHttpRequest, textStatus, errorThrown) {
396
- var error_message = wpvivid_output_ajaxerror('retrieving the last backup log', textStatus, errorThrown);
397
- jQuery('#wpvivid_last_backup_msg').html(error_message);
398
- });
399
- }
400
-
401
- /**
402
- * This function will control interface flow.
403
- */
404
- function wpvivid_interface_flow_control(){
405
- jQuery('#wpvivid_general_email_enable').click(function(){
406
- if(jQuery('#wpvivid_general_email_enable').prop('checked') === true){
407
- jQuery('#wpvivid_general_email_setting').show();
408
-
409
- }
410
- else{
411
- jQuery('#wpvivid_general_email_setting').hide();
412
- }
413
- });
414
-
415
- jQuery("input[name='schedule-backup-files']").bind("click",function(){
416
- if(jQuery(this).val() === "custom"){
417
- jQuery('#wpvivid_choosed_folders').show();
418
- if(jQuery("input[name='wpvivid-schedule-custom-folders'][value='other']").prop('checked')){
419
- jQuery('#wpvivid_file_tree_browser').show();
420
- }
421
- else{
422
- jQuery('#wpvivid_file_tree_browser').hide();
423
- }
424
- }
425
- else{
426
- jQuery('#wpvivid_choosed_folders').hide();
427
- jQuery('#wpvivid_file_tree_browser').hide();
428
- }
429
- });
430
-
431
- jQuery("input[name='wpvivid-schedule-custom-folders']").bind("click",function(){
432
- if(jQuery("input[name='wpvivid-schedule-custom-folders'][value='other']").prop('checked')){
433
- jQuery('#wpvivid_file_tree_browser').show();
434
- }
435
- else{
436
- jQuery('#wpvivid_file_tree_browser').hide();
437
- }
438
- });
439
-
440
- jQuery('#settings-page input[type=checkbox]:not([option=junk-files])').on("change", function(){
441
- wpvivid_settings_changed = true;
442
- });
443
-
444
- jQuery('#settings-page input[type=radio]').on("change", function(){
445
- wpvivid_settings_changed = true;
446
- });
447
-
448
- jQuery('#settings-page input[type=text]').on("keyup", function(){
449
- wpvivid_settings_changed = true;
450
- });
451
-
452
- /*jQuery("#wpvivid_storage_account_block input:not([type=checkbox])").on("keyup", function(){
453
- wpvivid_settings_changed = true;
454
- });*/
455
-
456
- /*jQuery('#wpvivid_storage_account_block input[type=checkbox]').on("change", function(){
457
- wpvivid_settings_changed = true;
458
- });*/
459
-
460
- jQuery('input:radio[option=restore]').click(function() {
461
- jQuery('input:radio[option=restore]').each(function () {
462
- if (jQuery(this).prop('checked')) {
463
- jQuery('#wpvivid_restore_btn').css({'pointer-events': 'auto', 'opacity': '1'});
464
- }
465
- });
466
- });
467
- }
468
-
469
- /**
470
- * Manage backup and download tasks. Retrieve the data every 3 seconds for checking if the backup or download tasks exist or not.
471
- */
472
- function wpvivid_manage_task() {
473
- if(m_need_update === true){
474
- m_need_update = false;
475
- wpvivid_check_runningtask();
476
- }
477
- else{
478
- setTimeout(function(){
479
- wpvivid_manage_task();
480
- }, 3000);
481
- }
482
- }
483
-
484
- function wpvivid_add_notice(notice_action, notice_type, notice_msg){
485
- var notice_id="";
486
- var tmp_notice_msg = "";
487
- if(notice_type === "Warning"){
488
- tmp_notice_msg = "Warning: " + notice_msg;
489
- }
490
- else if(notice_type === "Error"){
491
- tmp_notice_msg = "Error: " + notice_msg;
492
- }
493
- else if(notice_type === "Success"){
494
- tmp_notice_msg = "Success: " + notice_msg;
495
- }
496
- else if(notice_type === "Info"){
497
- tmp_notice_msg = notice_msg;
498
- }
499
- switch(notice_action){
500
- case "Backup":
501
- notice_id="wpvivid_backup_notice";
502
- break;
503
- }
504
- var bfind = false;
505
- $div = jQuery('#'+notice_id).children('div').children('p');
506
- $div.each(function (index, value) {
507
- if(notice_action === "Backup" && notice_type === "Success"){
508
- bfind = false;
509
- return false;
510
- }
511
- if (value.innerHTML === tmp_notice_msg) {
512
- bfind = true;
513
- return false;
514
- }
515
- });
516
- if (bfind === false) {
517
- jQuery('#'+notice_id).show();
518
- var div = '';
519
- if(notice_type === "Warning"){
520
- div = "<div class='notice notice-warning is-dismissible inline'><p>" + wpvividlion.warning + notice_msg + "</p>" +
521
- "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
522
- "<span class='screen-reader-text'>Dismiss this notice.</span>" +
523
- "</button>" +
524
- "</div>";
525
- }
526
- else if(notice_type === "Error"){
527
- div = "<div class=\"notice notice-error inline\"><p>" + wpvividlion.error + notice_msg + "</p></div>";
528
- }
529
- else if(notice_type === "Success"){
530
- wpvivid_clear_notice('wpvivid_backup_notice');
531
- jQuery('#wpvivid_backup_notice').show();
532
- var success_msg = wpvivid_completed_backup + " backup tasks have been completed. Please switch to <a href=\"#\" onclick=\"wpvivid_click_switch_page('wrap', 'wpvivid_tab_log', true);\">Log</a> page to check the details.\n";
533
- div = "<div class='notice notice-success is-dismissible inline'><p>" + success_msg + "</p>" +
534
- "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
535
- "<span class='screen-reader-text'>Dismiss this notice.</span>" +
536
- "</button>" +
537
- "</div>";
538
- wpvivid_completed_backup++;
539
- }
540
- else if(notice_type === "Info"){
541
- div = "<div class='notice notice-info is-dismissible inline'><p>" + notice_msg + "</p>" +
542
- "<button type='button' class='notice-dismiss' onclick='click_dismiss_notice(this);'>" +
543
- "<span class='screen-reader-text'>Dismiss this notice.</span>" +
544
- "</button>" +
545
- "</div>";
546
- }
547
- jQuery('#'+notice_id).append(div);
548
- }
549
- }
550
-
551
- function click_dismiss_notice(obj){
552
- wpvivid_completed_backup = 1;
553
- jQuery(obj).parent().remove();
554
- }
555
-
556
- function wpvivid_cron_task(){
557
- jQuery.get(wpvivid_siteurl+'/wp-cron.php');
558
- }
559
-
560
- function wpvivid_clear_notice(notice_id){
561
- var t = document.getElementById(notice_id);
562
- var oDiv = t.getElementsByTagName("div");
563
- var count = oDiv.length;
564
- for (count; count > 0; count--) {
565
- var i = count - 1;
566
- oDiv[i].parentNode.removeChild(oDiv[i]);
567
- }
568
- jQuery('#'+notice_id).hide();
569
- }
570
-
571
- function wpvivid_click_switch_page(tab, type, scroll)
572
- {
573
- jQuery('.'+tab+'-tab-content:not(.' + type + ')').hide();
574
- jQuery('.'+tab+'-tab-content.' + type).show();
575
- jQuery('.'+tab+'-nav-tab:not(#' + type + ')').removeClass('nav-tab-active');
576
- jQuery('.'+tab+'-nav-tab#' + type).addClass('nav-tab-active');
577
- if(scroll == true){
578
- var top = jQuery('#'+type).offset().top-jQuery('#'+type).height();
579
- jQuery('html, body').animate({scrollTop:top}, 'slow');
580
- }
581
- }
582
-
583
- function wpvivid_close_tab(event, hide_tab, type, show_tab){
584
- event.stopPropagation();
585
- jQuery('#'+hide_tab).hide();
586
- if(hide_tab === 'wpvivid_tab_mainwp'){
587
- wpvivid_hide_mainwp_tab_page();
588
- }
589
- wpvivid_click_switch_page(type, show_tab, true);
590
- }
591
-
592
- function wpvivid_hide_mainwp_tab_page(){
593
- var ajax_data = {
594
- 'action': 'wpvivid_hide_mainwp_tab_page'
595
- };
596
- wpvivid_post_request(ajax_data, function(res){
597
- }, function(XMLHttpRequest, textStatus, errorThrown) {
598
- });
599
- }
600
-
601
- /**
602
- * Output ajax error in a standard format.
603
- *
604
- * @param action - The specific operation
605
- * @param textStatus - The textual status message returned by the server
606
- * @param errorThrown - The error message thrown by server
607
- *
608
- * @returns {string}
609
- */
610
- function wpvivid_output_ajaxerror(action, textStatus, errorThrown){
611
- action = 'trying to establish communication with your server';
612
- var error_msg = "wpvivid_request: "+ textStatus + "(" + errorThrown + "): an error occurred when " + action + ". " +
613
- "This error may be request not reaching or server not responding. Please try again later.";
614
- //"This error could be caused by an unstable internet connection. Please try again later.";
615
- return error_msg;
616
- }
617
-
618
- function wpvivid_add_review_info(review){
619
- var ajax_data={
620
- 'action': 'wpvivid_need_review',
621
- 'review': review
622
- };
623
- jQuery('#wpvivid_notice_rate').hide();
624
- wpvivid_post_request(ajax_data, function(res){
625
- if(typeof res != 'undefined' && res != ''){
626
- var tempwindow=window.open('_blank');
627
- tempwindow.location=res;
628
- }
629
- }, function(XMLHttpRequest, textStatus, errorThrown) {
630
- });
631
- }
632
-
633
- function wpvivid_click_amazons3_notice(){
634
- var ajax_data={
635
- 'action': 'wpvivid_amazons3_notice'
636
- };
637
- jQuery('#wpvivid_amazons3_notice').hide();
638
- wpvivid_post_request(ajax_data, function(res){
639
- }, function(XMLHttpRequest, textStatus, errorThrown) {
640
- });
641
- }
642
-
643
- function wpvivid_ajax_data_transfer(data_type){
644
- var json = {};
645
- jQuery('input:checkbox[option='+data_type+']').each(function() {
646
- var value = '0';
647
- var key = jQuery(this).prop('name');
648
- if(jQuery(this).prop('checked')) {
649
- value = '1';
650
- }
651
- else {
652
- value = '0';
653
- }
654
- json[key]=value;
655
- });
656
- jQuery('input:radio[option='+data_type+']').each(function() {
657
- if(jQuery(this).prop('checked'))
658
- {
659
- var key = jQuery(this).prop('name');
660
- var value = jQuery(this).prop('value');
661
- json[key]=value;
662
- }
663
- });
664
- jQuery('input:text[option='+data_type+']').each(function(){
665
- var obj = {};
666
- var key = jQuery(this).prop('name');
667
- var value = jQuery(this).val();
668
- json[key]=value;
669
- });
670
- jQuery('input:password[option='+data_type+']').each(function(){
671
- var obj = {};
672
- var key = jQuery(this).prop('name');
673
- var value = jQuery(this).val();
674
- json[key]=value;
675
- });
676
- jQuery('select[option='+data_type+']').each(function(){
677
- var obj = {};
678
- var key = jQuery(this).prop('name');
679
- var value = jQuery(this).val();
680
- json[key]=value;
681
- });
682
- return JSON.stringify(json);
683
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/admin/partials/images/Delete.png DELETED
Binary file
trunk/admin/partials/images/Edit.png DELETED
Binary file
trunk/admin/partials/images/Restore.png DELETED
Binary file
trunk/admin/partials/images/add-storages.png DELETED
Binary file
trunk/admin/partials/images/export-import.png DELETED
Binary file
trunk/admin/partials/images/locked.png DELETED
Binary file
trunk/admin/partials/images/staging/Log.png DELETED
Binary file
trunk/admin/partials/images/staging/delete-tab.png DELETED
Binary file
trunk/admin/partials/images/staging/download.png DELETED
Binary file
trunk/admin/partials/images/storage-amazon-s3(gray).png DELETED
Binary file
trunk/admin/partials/images/storage-amazon-s3.png DELETED
Binary file
trunk/admin/partials/images/storage-digitalocean(gray).png DELETED
Binary file
trunk/admin/partials/images/storage-digitalocean.png DELETED
Binary file
trunk/admin/partials/images/storage-dropbox(gray).png DELETED
Binary file
trunk/admin/partials/images/storage-dropbox.png DELETED
Binary file
trunk/admin/partials/images/storage-ftp(gray).png DELETED
Binary file
trunk/admin/partials/images/storage-ftp.png DELETED
Binary file
trunk/admin/partials/images/storage-local(gray).png DELETED
Binary file
trunk/admin/partials/images/storage-local.png DELETED
Binary file
trunk/admin/partials/images/storage-microsoft-onedrive(gray).png DELETED
Binary file
trunk/admin/partials/images/storage-microsoft-onedrive.png DELETED
Binary file
trunk/admin/partials/images/storage-sftp(gray).png DELETED
Binary file
trunk/admin/partials/images/storage-sftp.png DELETED
Binary file
trunk/admin/partials/images/stroage-google-drive(gray).png DELETED
Binary file
trunk/admin/partials/images/stroage-google-drive.png DELETED
Binary file
trunk/admin/partials/images/unlocked.png DELETED
Binary file
trunk/admin/partials/wpvivid-admin-display.php DELETED
@@ -1,221 +0,0 @@
1
- <?php
2
- /**
3
- * Provide a admin area view for the plugin
4
- *
5
- * This file is used to markup the admin-facing aspects of the plugin.
6
- *
7
- * @link https://wpvivid.com
8
- * @since 0.9.1
9
- *
10
- * @package WPvivid
11
- * @subpackage WPvivid/admin/partials
12
- */
13
-
14
- include_once WPVIVID_PLUGIN_DIR .'/admin/partials/wpvivid-backup-restore-page-display.php';
15
- include_once WPVIVID_PLUGIN_DIR .'/admin/partials/wpvivid-remote-storage-page-display.php';
16
- include_once WPVIVID_PLUGIN_DIR .'/admin/partials/wpvivid-settings-page-display.php';
17
- include_once WPVIVID_PLUGIN_DIR .'/admin/partials/wpvivid-schedule-page-display.php';
18
- include_once WPVIVID_PLUGIN_DIR .'/admin/partials/wpvivid-website-info-page-display.php';
19
- include_once WPVIVID_PLUGIN_DIR .'/admin/partials/wpvivid-logs-page-display.php';
20
- include_once WPVIVID_PLUGIN_DIR .'/admin/partials/wpvivid-log-read-page-display.php';
21
-
22
- if (!defined('WPVIVID_PLUGIN_DIR'))
23
- {
24
- die;
25
- }
26
-
27
- global $wpvivid_plugin;
28
- $schedule=WPvivid_Schedule::get_schedule();
29
-
30
- do_action('show_notice');
31
-
32
- ?>
33
-
34
- <?php
35
-
36
- $page_array = array();
37
- $page_array = apply_filters('wpvivid_add_tab_page', $page_array);
38
- foreach ($page_array as $page_name){
39
- add_action('wpvivid_backuprestore_add_tab', $page_name['tab_func'], $page_name['index']);
40
- add_action('wpvivid_backuprestore_add_page', $page_name['page_func'], $page_name['index']);
41
- }
42
-
43
- ?>
44
-
45
- <div class="wrap">
46
- <h1><?php
47
- $plugin_display_name = 'WPvivid Backup Plugin';
48
- $plugin_display_name = apply_filters('wpvivid_display_pro_name', $plugin_display_name);
49
- echo __('WPvivid Backup Plugin', 'wpvivid-backuprestore');
50
- ?></h1>
51
- <div id="wpvivid_backup_notice">
52
- <?php
53
- if($schedule['enable'] == true) {
54
- if($schedule['backup']['remote'] === 1)
55
- {
56
- $remoteslist=WPvivid_Setting::get_all_remote_options();
57
- $default_remote_storage='';
58
- foreach ($remoteslist['remote_selected'] as $value)
59
- {
60
- $default_remote_storage=$value;
61
- }
62
- if($default_remote_storage == ''){
63
- echo '<div class="notice notice-warning is-dismissible"><p>'.__('Warning: There is no default remote storage available for the scheduled backups, please set up it first.', 'wpvivid-backuprestore').'</p></div>';
64
- }
65
- }
66
- }
67
- ?>
68
- </div>
69
- <?php do_action('wpvivid_add_schedule_notice'); ?>
70
- <div id="wpvivid_remote_notice"></div>
71
- </div>
72
- <h2 class="nav-tab-wrapper">
73
- <?php
74
- do_action('wpvivid_backuprestore_add_tab');
75
- ?>
76
- </h2>
77
- <div class="wrap" style="max-width:1720px;">
78
- <div id="poststuff" style="padding-top: 0;">
79
- <div id="post-body" class="metabox-holder columns-2">
80
- <div id="post-body-content">
81
- <div class="inside" style="margin-top:0;">
82
- <?php
83
- do_action('wpvivid_backuprestore_add_page');
84
- ?>
85
- </div>
86
- </div>
87
-
88
- <div id="postbox-container-1" class="postbox-container">
89
- <div class="meta-box-sortables">
90
- <?php
91
- $html = '';
92
- echo apply_filters('wpvivid_add_side_bar' ,$html, true);
93
- ?>
94
- </div>
95
- </div>
96
- </div>
97
- <br class="clear">
98
- </div>
99
- </div>
100
-
101
- <script>
102
- function switchTabs(evt,contentName) {
103
- // Declare all variables
104
- var i, tabcontent, tablinks;
105
-
106
- // Get all elements with class="tabcontent" and hide them
107
- tabcontent = document.getElementsByClassName("wrap-tab-content");
108
- for (i = 0; i < tabcontent.length; i++) {
109
- tabcontent[i].style.display = "none";
110
- }
111
-
112
- // Get all elements with class="wrap-nav-tab" and remove the class "active"
113
- tablinks = document.getElementsByClassName("wrap-nav-tab");
114
- for (i = 0; i < tablinks.length; i++) {
115
- tablinks[i].className = tablinks[i].className.replace(" nav-tab-active", "");
116
- }
117
-
118
- // Show the current tab, and add an "nav-tab-active" class to the button that opened the tab
119
- document.getElementById(contentName).style.display = "block";
120
- evt.currentTarget.className += " nav-tab-active";
121
- jQuery( document ).trigger( 'wpvivid-switch-tabs', contentName );
122
- }
123
- function switchrestoreTabs(evt,contentName) {
124
- // Declare all variables
125
- var i, tabcontent, tablinks;
126
-
127
- // Get all elements with class="table-list-content" and hide them
128
- tabcontent = document.getElementsByClassName("backup-tab-content");
129
- for (i = 0; i < tabcontent.length; i++) {
130
- tabcontent[i].style.display = "none";
131
- }
132
-
133
- // Get all elements with class="table-nav-tab" and remove the class "nav-tab-active"
134
- tablinks = document.getElementsByClassName("backup-nav-tab");
135
- for (i = 0; i < tablinks.length; i++) {
136
- tablinks[i].className = tablinks[i].className.replace(" nav-tab-active", "");
137
- }
138
-
139
- // Show the current tab, and add an "storage-menu-active" class to the button that opened the tab
140
- document.getElementById(contentName).style.display = "block";
141
- evt.currentTarget.className += " nav-tab-active";
142
- }
143
- function switchlogTabs(evt,contentName) {
144
- // Declare all variables
145
- var i, tabcontent, tablinks;
146
-
147
- // Get all elements with class="table-list-content" and hide them
148
- tabcontent = document.getElementsByClassName("log-tab-content");
149
- for (i = 0; i < tabcontent.length; i++) {
150
- tabcontent[i].style.display = "none";
151
- }
152
-
153
- // Get all elements with class="table-nav-tab" and remove the class "nav-tab-active"
154
- tablinks = document.getElementsByClassName("log-nav-tab");
155
- for (i = 0; i < tablinks.length; i++) {
156
- tablinks[i].className = tablinks[i].className.replace(" nav-tab-active", "");
157
- }
158
-
159
- // Show the current tab, and add an "storage-menu-active" class to the button that opened the tab
160
- document.getElementById(contentName).style.display = "block";
161
- evt.currentTarget.className += " nav-tab-active";
162
- }
163
- function switchsettingTabs(evt,contentName) {
164
- // Declare all variables
165
- var i, tabcontent, tablinks;
166
-
167
- // Get all elements with class="table-list-content" and hide them
168
- tabcontent = document.getElementsByClassName("setting-tab-content");
169
- for (i = 0; i < tabcontent.length; i++) {
170
- tabcontent[i].style.display = "none";
171
- }
172
-
173
- // Get all elements with class="table-nav-tab" and remove the class "nav-tab-active"
174
- tablinks = document.getElementsByClassName("setting-nav-tab");
175
- for (i = 0; i < tablinks.length; i++) {
176
- tablinks[i].className = tablinks[i].className.replace(" nav-tab-active", "");
177
- }
178
-
179
- // Show the current tab, and add an "storage-menu-active" class to the button that opened the tab
180
- document.getElementById(contentName).style.display = "block";
181
- evt.currentTarget.className += " nav-tab-active";
182
- }
183
- function wpvivid_getrequest()
184
- {
185
- wpvivid_click_switch_page('wrap', wpvivid_page_request, false);
186
- }
187
-
188
- function wpvivid_task_monitor()
189
- {
190
- setTimeout(function () {
191
- wpvivid_task_monitor();
192
- }, 120000);
193
-
194
- var ajax_data = {
195
- 'action': 'wpvivid_task_monitor'
196
- };
197
-
198
- wpvivid_post_request(ajax_data, function (data)
199
- {
200
- },function (XMLHttpRequest, textStatus, errorThrown)
201
- {
202
- });
203
- }
204
-
205
- jQuery(document).ready(function ()
206
- {
207
- wpvivid_getrequest();
208
- wpvivid_task_monitor();
209
- <?php
210
- $default_task_type = array();
211
- $default_task_type = apply_filters('wpvivid_get_task_type', $default_task_type);
212
- if(empty($default_task_type)){
213
- ?>
214
- wpvivid_activate_cron();
215
- wpvivid_manage_task();
216
- <?php
217
- }
218
- ?>
219
- });
220
-
221
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/admin/partials/wpvivid-backup-restore-page-display.php DELETED
@@ -1,2551 +0,0 @@
1
- <?php
2
-
3
- if ( ! class_exists( 'WP_List_Table' ) )
4
- {
5
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
6
- }
7
-
8
- class WPvivid_Files_List extends WP_List_Table
9
- {
10
- public $page_num;
11
- public $file_list;
12
- public $backup_id;
13
-
14
- public function __construct( $args = array() )
15
- {
16
- parent::__construct(
17
- array(
18
- 'plural' => 'files',
19
- 'screen' => 'files'
20
- )
21
- );
22
- }
23
-
24
- protected function get_table_classes()
25
- {
26
- return array( 'widefat striped' );
27
- }
28
-
29
- public function print_column_headers( $with_id = true )
30
- {
31
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
32
-
33
- if (!empty($columns['cb'])) {
34
- static $cb_counter = 1;
35
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
36
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>';
37
- $cb_counter++;
38
- }
39
-
40
- foreach ( $columns as $column_key => $column_display_name )
41
- {
42
- $class = array( 'manage-column', "column-$column_key" );
43
-
44
- if ( in_array( $column_key, $hidden ) )
45
- {
46
- $class[] = 'hidden';
47
- }
48
-
49
- if ( $column_key === $primary )
50
- {
51
- $class[] = 'column-primary';
52
- }
53
-
54
- if ( $column_key === 'cb' )
55
- {
56
- $class[] = 'check-column';
57
- }
58
-
59
- $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
60
- $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
61
- $id = $with_id ? "id='$column_key'" : '';
62
-
63
- if ( ! empty( $class ) )
64
- {
65
- $class = "class='" . join( ' ', $class ) . "'";
66
- }
67
-
68
- echo "<$tag $scope $id $class>$column_display_name</$tag>";
69
- }
70
- }
71
-
72
- public function get_columns()
73
- {
74
- $columns = array();
75
- $columns['wpvivid_file'] = __( 'File', 'wpvivid' );
76
- return $columns;
77
- }
78
-
79
- public function _column_wpvivid_file( $file )
80
- {
81
- $html='<td class="tablelistcolumn">
82
- <div style="padding:0 0 10px 0;">
83
- <span>'. $file['key'].'</span>
84
- </div>
85
- <div class="wpvivid-download-status" style="padding:0;">';
86
- if($file['status']=='completed')
87
- {
88
- $html.='<span>'.__('File Size: ', 'wpvivid').'</span><span class="wpvivid-element-space-right wpvivid-download-file-size">'.$file['size'].'</span><span class="wpvivid-element-space-right">|</span><span class=" wpvivid-element-space-right wpvivid-ready-download"><a style="cursor: pointer;">Download</a></span>';
89
- }
90
- else if($file['status']=='file_not_found')
91
- {
92
- $html.='<span>' . __('File not found', 'wpvivid') . '</span>';
93
- }
94
- else if($file['status']=='need_download')
95
- {
96
- $html.='<span>'.__('File Size: ', 'wpvivid').'</span><span class="wpvivid-element-space-right wpvivid-download-file-size">'.$file['size'].'</span><span class="wpvivid-element-space-right">|</span><span class="wpvivid-element-space-right"><a class="wpvivid-download" style="cursor: pointer;">Prepare to Download</a></span>';
97
- }
98
- else if($file['status']=='running')
99
- {
100
- $html.='<div class="wpvivid-element-space-bottom">
101
- <span class="wpvivid-element-space-right">Retriving (remote storage to web server)</span><span class="wpvivid-element-space-right">|</span><span>File Size: </span><span class="wpvivid-element-space-right wpvivid-download-file-size">'.$file['size'].'</span><span class="wpvivid-element-space-right">|</span><span>Downloaded Size: </span><span>'.$file['downloaded_size'].'</span>
102
- </div>
103
- <div style="width:100%;height:10px; background-color:#dcdcdc;">
104
- <div style="background-color:#0085ba; float:left;width:'.$file['progress_text'].'%;height:10px;"></div>
105
- </div>';
106
- }
107
- else if($file['status']=='timeout')
108
- {
109
- $html.='<div class="wpvivid-element-space-bottom">
110
- <span>Download timeout, please retry.</span>
111
- </div>
112
- <div>
113
- <span>'.__('File Size: ', 'wpvivid').'</span><span class="wpvivid-element-space-right wpvivid-download-file-size">'.$file['size'].'</span><span class="wpvivid-element-space-right">|</span><span class="wpvivid-element-space-right"><a class="wpvivid-download" style="cursor: pointer;">Prepare to Download</a></span>
114
- </div>';
115
- }
116
- else if($file['status']=='error')
117
- {
118
- $html.='<div class="wpvivid-element-space-bottom">
119
- <span>'.$file['error'].'</span>
120
- </div>
121
- <div>
122
- <span>'.__('File Size: ', 'wpvivid').'</span><span class="wpvivid-element-space-right wpvivid-download-file-size">'.$file['size'].'</span><span class="wpvivid-element-space-right">|</span><span class="wpvivid-element-space-right"><a class="wpvivid-download" style="cursor: pointer;">Prepare to Download</a></span>
123
- </div>';
124
- }
125
-
126
- $html.='</div></td>';
127
- echo $html;
128
- //size
129
- }
130
-
131
- public function set_files_list($file_list,$backup_id,$page_num=1)
132
- {
133
- $this->file_list=$file_list;
134
- $this->backup_id=$backup_id;
135
- $this->page_num=$page_num;
136
- }
137
-
138
- public function get_pagenum()
139
- {
140
- if($this->page_num=='first')
141
- {
142
- $this->page_num=1;
143
- }
144
- else if($this->page_num=='last')
145
- {
146
- $this->page_num=$this->_pagination_args['total_pages'];
147
- }
148
- $pagenum = $this->page_num ? $this->page_num : 0;
149
-
150
- if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
151
- {
152
- $pagenum = $this->_pagination_args['total_pages'];
153
- }
154
-
155
- return max( 1, $pagenum );
156
- }
157
-
158
- public function prepare_items()
159
- {
160
- $columns = $this->get_columns();
161
- $hidden = array();
162
- $sortable = array();
163
- $this->_column_headers = array($columns, $hidden, $sortable);
164
-
165
- $total_items =sizeof($this->file_list);
166
-
167
- $this->set_pagination_args(
168
- array(
169
- 'total_items' => $total_items,
170
- 'per_page' => 10,
171
- )
172
- );
173
- }
174
-
175
- public function has_items()
176
- {
177
- return !empty($this->file_list);
178
- }
179
-
180
- public function display_rows()
181
- {
182
- $this->_display_rows($this->file_list);
183
- }
184
-
185
- private function _display_rows($file_list)
186
- {
187
- $page=$this->get_pagenum();
188
-
189
- $page_file_list=array();
190
- $count=0;
191
- while ( $count<$page )
192
- {
193
- $page_file_list = array_splice( $file_list, 0, 10);
194
- $count++;
195
- }
196
- foreach ( $page_file_list as $key=>$file)
197
- {
198
- $file['key']=$key;
199
- $this->single_row($file);
200
- }
201
- }
202
-
203
- public function single_row($file)
204
- {
205
- ?>
206
- <tr slug="<?php echo $file['key']?>">
207
- <?php $this->single_row_columns( $file ); ?>
208
- </tr>
209
- <?php
210
- }
211
-
212
- protected function pagination( $which )
213
- {
214
- if ( empty( $this->_pagination_args ) )
215
- {
216
- return;
217
- }
218
-
219
- $total_items = $this->_pagination_args['total_items'];
220
- $total_pages = $this->_pagination_args['total_pages'];
221
- $infinite_scroll = false;
222
- if ( isset( $this->_pagination_args['infinite_scroll'] ) )
223
- {
224
- $infinite_scroll = $this->_pagination_args['infinite_scroll'];
225
- }
226
-
227
- if ( 'top' === $which && $total_pages > 1 )
228
- {
229
- $this->screen->render_screen_reader_content( 'heading_pagination' );
230
- }
231
-
232
- $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
233
-
234
- $current = $this->get_pagenum();
235
-
236
- $page_links = array();
237
-
238
- $total_pages_before = '<span class="paging-input">';
239
- $total_pages_after = '</span></span>';
240
-
241
- $disable_first = $disable_last = $disable_prev = $disable_next = false;
242
-
243
- if ( $current == 1 ) {
244
- $disable_first = true;
245
- $disable_prev = true;
246
- }
247
- if ( $current == 2 ) {
248
- $disable_first = true;
249
- }
250
- if ( $current == $total_pages ) {
251
- $disable_last = true;
252
- $disable_next = true;
253
- }
254
- if ( $current == $total_pages - 1 ) {
255
- $disable_last = true;
256
- }
257
-
258
- if ( $disable_first ) {
259
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
260
- } else {
261
- $page_links[] = sprintf(
262
- "<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
263
- __( 'First page' ),
264
- '&laquo;'
265
- );
266
- }
267
-
268
- if ( $disable_prev ) {
269
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
270
- } else {
271
- $page_links[] = sprintf(
272
- "<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
273
- $current,
274
- __( 'Previous page' ),
275
- '&lsaquo;'
276
- );
277
- }
278
-
279
- if ( 'bottom' === $which ) {
280
- $html_current_page = $current;
281
- $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
282
- } else {
283
- $html_current_page = sprintf(
284
- "%s<input class='current-page' id='current-page-selector-filelist' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
285
- '<label for="current-page-selector-filelist" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
286
- $current,
287
- strlen( $total_pages )
288
- );
289
- }
290
- $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
291
- $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
292
-
293
- if ( $disable_next ) {
294
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
295
- } else {
296
- $page_links[] = sprintf(
297
- "<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
298
- $current,
299
- __( 'Next page' ),
300
- '&rsaquo;'
301
- );
302
- }
303
-
304
- if ( $disable_last ) {
305
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
306
- } else {
307
- $page_links[] = sprintf(
308
- "<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
309
- __( 'Last page' ),
310
- '&raquo;'
311
- );
312
- }
313
-
314
- $pagination_links_class = 'pagination-links';
315
- if ( ! empty( $infinite_scroll ) ) {
316
- $pagination_links_class .= ' hide-if-js';
317
- }
318
- $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
319
-
320
- if ( $total_pages ) {
321
- $page_class = $total_pages < 2 ? ' one-page' : '';
322
- } else {
323
- $page_class = ' no-pages';
324
- }
325
- $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
326
-
327
- echo $this->_pagination;
328
- }
329
-
330
- protected function display_tablenav( $which ) {
331
- $css_type = '';
332
- if ( 'top' === $which ) {
333
- wp_nonce_field( 'bulk-' . $this->_args['plural'] );
334
- $css_type = 'margin: 0 0 10px 0';
335
- }
336
- else if( 'bottom' === $which ) {
337
- $css_type = 'margin: 10px 0 0 0';
338
- }
339
-
340
- $total_pages = $this->_pagination_args['total_pages'];
341
- if ( $total_pages >1)
342
- {
343
- ?>
344
- <div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
345
- <?php
346
- $this->extra_tablenav( $which );
347
- $this->pagination( $which );
348
- ?>
349
-
350
- <br class="clear" />
351
- </div>
352
- <?php
353
- }
354
- }
355
-
356
- public function display()
357
- {
358
- $singular = $this->_args['singular'];
359
-
360
- $this->display_tablenav( 'top' );
361
-
362
- $this->screen->render_screen_reader_content( 'heading_list' );
363
- ?>
364
- <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
365
- <thead>
366
- <tr>
367
- <?php $this->print_column_headers(); ?>
368
- </tr>
369
- </thead>
370
-
371
- <tbody id="the-list"
372
- <?php
373
- if ( $singular ) {
374
- echo " data-wp-lists='list:$singular'";
375
- }
376
- ?>
377
- >
378
- <?php $this->display_rows_or_placeholder(); ?>
379
- </tbody>
380
-
381
- </table>
382
- <?php
383
- $this->display_tablenav( 'bottom' );
384
- }
385
- }
386
-
387
-
388
- function wpvivid_add_backup_type($html, $type_name)
389
- {
390
- $html .= '<label>
391
- <input type="radio" option="backup" name="'.$type_name.'" value="files+db" checked />
392
- <span>'.__( 'Database + Files (WordPress Files)', 'wpvivid-backuprestore' ).'</span>
393
- </label><br>
394
- <label>
395
- <input type="radio" option="backup" name="'.$type_name.'" value="files" />
396
- <span>'.__( 'WordPress Files (Exclude Database)', 'wpvivid-backuprestore' ).'</span>
397
- </label><br>
398
- <label>
399
- <input type="radio" option="backup" name="'.$type_name.'" value="db" />
400
- <span>'.__( 'Only Database', 'wpvivid-backuprestore' ).'</span>
401
- </label><br>
402
- <label>
403
- <div style="float: left;">
404
- <input type="radio" disabled />
405
- <span class="wpvivid-element-space-right" style="color: #ddd;">'.__('Create a staging site', 'wpvivid-backuprestore').'</span>
406
- </div>
407
- <span class="wpvivid-feature-pro">
408
- <a href="https://docs.wpvivid.com/wpvivid-backup-pro-create-staging-site.html" style="text-decoration: none;">'.__('Pro feature: learn more', 'wpvivid-backuprestore').'</a>
409
- </span>
410
- </label><br>
411
- <label>
412
- <div style="float: left;">
413
- <input type="radio" disabled />
414
- <span class="wpvivid-element-space-right" style="color: #ddd;">'.__('Custom', 'wpvivid-backuprestore').'</span>
415
- </div>
416
- <span class="wpvivid-feature-pro">
417
- <a href="https://docs.wpvivid.com/wpvivid-backup-pro-overview.html" style="text-decoration: none;">'.__('Pro feature: learn more', 'wpvivid-backuprestore').'</a>
418
- </span>
419
- </label><br>';
420
- return $html;
421
- }
422
-
423
- function wpvivid_backup_do_js(){
424
- global $wpvivid_plugin;
425
- $backup_task = array();
426
- $backup_task=$wpvivid_plugin->_list_tasks($backup_task, false);
427
- $general_setting=WPvivid_Setting::get_setting(true, "");
428
- if($general_setting['options']['wpvivid_common_setting']['estimate_backup'] == 0){
429
- ?>
430
- jQuery('#wpvivid_estimate_backup_info').hide();
431
- <?php
432
- }
433
- if(empty($backup_task['backup']['data'])){
434
- ?>
435
- jQuery('#wpvivid_postbox_backup_percent').hide();
436
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
437
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
438
- <?php
439
- }
440
- else{
441
- foreach($backup_task['backup']['data'] as $key=>$value){
442
- if($value['status']['str'] === 'running'){
443
- $percent=$value['data']['progress'];
444
- ?>
445
- jQuery('#wpvivid_postbox_backup_percent').show();
446
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
447
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
448
- jQuery('#wpvivid_action_progress_bar_percent').css('width', <?php echo $percent; ?>+'%');
449
- jQuery('#wpvivid_backup_database_size').html('<?php echo $value['size']['db_size']; ?>');
450
- jQuery('#wpvivid_backup_file_size').html('<?php echo $value['size']['files_size']['sum']; ?>');
451
- <?php
452
- if($value['is_canceled'] == false){
453
- $descript=$value['data']['descript'];
454
- if($value['data']['type']){
455
- $find_str = 'Total size: ';
456
- if(stripos($descript, $find_str) != false) {
457
- $pos = stripos($descript, $find_str);
458
- $descript = substr($descript, 0, $pos);
459
- }
460
- }
461
- $backup_running_time=$value['data']['running_stamp'];
462
- $output = '';
463
- foreach (array(86400 => 'day', 3600 => 'hour', 60 => 'min', 1 => 'second') as $key => $value) {
464
- if ($backup_running_time >= $key) $output .= floor($backup_running_time/$key) . $value;
465
- $backup_running_time %= $key;
466
- }
467
- if($output==''){
468
- $output=0;
469
- }
470
- ?>
471
- jQuery('#wpvivid_current_doing').html('<?php echo $descript; ?> Progress: <?php echo $percent; ?>%, running time: <?php echo $output; ?>');
472
- <?php
473
- }
474
- else{
475
- ?>
476
- jQuery('#wpvivid_current_doing').html('The backup will be canceled after backing up the current chunk ends.');
477
- <?php
478
- }
479
- }
480
- }
481
- }
482
- }
483
-
484
- function wpvivid_download_backup_descript($html){
485
- $html = '<p><strong>'.__('About backup download', 'wpvivid-backuprestore').'</strong></p>';
486
- $html .= '<ul>';
487
- $html .= '<li>'.__('->If backups are stored in remote storage, our plugin will retrieve the backup to your web server first. This may take a little time depending on the size of backup files. Please be patient. Then you can download them to your PC.', 'wpvivid-backuprestore').'</li>';
488
- $html .= '<li>'.__('->If backups are stored in web server, the plugin will list all relevant files immediately.', 'wpvivid-backuprestore').'</li>';
489
- $html .= '</ul>';
490
- return $html;
491
- }
492
-
493
- function wpvivid_restore_website_descript($html){
494
- $html = '<p><a href="#" id="wpvivid_how_to_restore_backup_describe" onclick="wpvivid_click_how_to_restore_backup();" style="text-decoration: none;">'.__('How to restore your website from a backup(scheduled, manual, uploaded and received backup)', 'wpvivid-backuprestore').'</a></p>';
495
- $html .= '<div id="wpvivid_how_to_restore_backup"></div>';
496
- return $html;
497
- }
498
-
499
- function wpvivid_backuppage_load_backuplist($backuplist_array){
500
- $backuplist_array['list_backup'] = array('index' => '1', 'tab_func' => 'wpvivid_backuppage_add_tab_backup', 'page_func' => 'wpvivid_backuppage_add_page_backup');
501
- $backuplist_array['list_log'] = array('index' => '3', 'tab_func' => 'wpvivid_backuppage_add_tab_log', 'page_func' => 'wpvivid_backuppage_add_page_log');
502
- $backuplist_array['list_restore'] = array('index' => '4', 'tab_func' => 'wpvivid_backuppage_add_tab_restore', 'page_func' => 'wpvivid_backuppage_add_page_restore');
503
- $backuplist_array['list_download'] = array('index' => '5', 'tab_func' => 'wpvivid_backuppage_add_tab_downlaod', 'page_func' => 'wpvivid_backuppage_add_page_downlaod');
504
- return $backuplist_array;
505
- }
506
-
507
- function wpvivid_backuppage_add_tab_backup(){
508
- ?>
509
- <a href="#" id="wpvivid_tab_backup" class="nav-tab backup-nav-tab nav-tab-active" onclick="switchrestoreTabs(event,'page-backups')"><?php _e('Backups', 'wpvivid-backuprestore'); ?></a>
510
- <?php
511
- }
512
-
513
- function wpvivid_backuppage_add_tab_log(){
514
- ?>
515
- <a href="#" id="wpvivid_tab_backup_log" class="nav-tab backup-nav-tab delete" onclick="switchrestoreTabs(event,'page-log')" style="display: none;">
516
- <div style="margin-right: 15px;"><?php _e('Log', 'wpvivid-backuprestore'); ?></div>
517
- <div class="nav-tab-delete-img">
518
- <img src="<?php echo esc_url(plugins_url( 'images/delete-tab.png', __FILE__ )); ?>" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, 'wpvivid_tab_backup_log', 'backup', 'wpvivid_tab_backup');" />
519
- </div>
520
- </a>
521
- <?php
522
- }
523
-
524
- function wpvivid_backuppage_add_tab_restore(){
525
- ?>
526
- <a href="#" id="wpvivid_tab_restore" class="nav-tab backup-nav-tab delete" onclick="switchrestoreTabs(event,'page-restore')" style="display: none;">
527
- <div style="margin-right: 15px;"><?php _e('Restore', 'wpvivid-backuprestore'); ?></div>
528
- <div class="nav-tab-delete-img">
529
- <img src="<?php echo esc_url(plugins_url( 'images/delete-tab.png', __FILE__ )); ?>" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, 'wpvivid_tab_restore', 'backup', 'wpvivid_tab_backup');" />
530
- </div>
531
- </a>
532
- <?php
533
- }
534
-
535
- function wpvivid_backuppage_add_tab_downlaod(){
536
- ?>
537
- <a href="#" id="wpvivid_tab_download" class="nav-tab backup-nav-tab delete" onclick="switchrestoreTabs(event,'page-download')" style="display: none;">
538
- <div style="margin-right: 15px;"><?php _e('Download', 'wpvivid-backuprestore'); ?></div>
539
- <div class="nav-tab-delete-img">
540
- <img src="<?php echo esc_url(plugins_url( 'images/delete-tab.png', __FILE__ )); ?>" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, 'wpvivid_tab_download', 'backup', 'wpvivid_tab_backup');" />
541
- </div>
542
- </a>
543
- <?php
544
- }
545
-
546
- function wpvivid_backuppage_add_page_backup(){
547
- $backuplist=WPvivid_Backuplist::get_backuplist();
548
- $display_backup_count = WPvivid_Setting::get_max_backup_count();
549
- ?>
550
- <div class="backup-tab-content wpvivid_tab_backup" id="page-backups">
551
- <div style="margin-top:10px; margin-bottom:10px;">
552
- <?php
553
- $descript='';
554
- $descript= apply_filters('wpvivid_download_backup_descript',$descript);
555
- echo $descript;
556
- ?>
557
- </div>
558
- <div style="margin-bottom:10px;">
559
- <?php
560
- $descript='';
561
- $descript= apply_filters('wpvivid_restore_website_descript',$descript);
562
- echo $descript;
563
- ?>
564
- </div>
565
- <div style="clear:both;"></div>
566
- <?php
567
- do_action('wpvivid_rescan_backup_list');
568
- ?>
569
- <table class="wp-list-table widefat plugins" id="wpvivid_backuplist_table" style="border-collapse: collapse;">
570
- <thead>
571
- <tr class="backup-list-head" style="border-bottom: 0;">
572
- <td></td>
573
- <th><?php _e( 'Backup','wpvivid-backuprestore'); ?></th>
574
- <th><?php _e( 'Storage','wpvivid-backuprestore'); ?></th>
575
- <th><?php _e( 'Download','wpvivid-backuprestore'); ?></th>
576
- <th><?php _e( 'Restore', 'wpvivid-backuprestore'); ?></th>
577
- <th><?php _e( 'Delete','wpvivid-backuprestore'); ?></th>
578
- </tr>
579
- </thead>
580
- <tbody class="wpvivid-backuplist" id="wpvivid_backup_list">
581
- <?php
582
- $html = '';
583
- $html = apply_filters('wpvivid_add_backup_list', $html);
584
- echo $html;
585
- ?>
586
- </tbody>
587
- <tfoot>
588
- <tr>
589
- <th><input name="" type="checkbox" id="backup_list_all_check" value="1" /></th>
590
- <th class="row-title" colspan="5"><a onclick="wpvivid_delete_backups_inbatches();" style="cursor: pointer;"><?php _e('Delete the selected backups', 'wpvivid-backuprestore'); ?></a></th>
591
- </tr>
592
- </tfoot>
593
- </table>
594
- </div>
595
- <script>
596
- function wpvivid_retrieve_backup_list(){
597
- var ajax_data = {
598
- 'action': 'wpvivid_get_backup_list'
599
- };
600
- wpvivid_post_request(ajax_data, function(data){
601
- try {
602
- var jsonarray = jQuery.parseJSON(data);
603
- if (jsonarray.result === 'success') {
604
- jQuery('#wpvivid_backup_list').html('');
605
- jQuery('#wpvivid_backup_list').append(jsonarray.html);
606
- }
607
- }
608
- catch(err){
609
- alert(err);
610
- }
611
- },function(XMLHttpRequest, textStatus, errorThrown) {
612
- setTimeout(function () {
613
- wpvivid_retrieve_backup_list();
614
- }, 3000);
615
- });
616
- }
617
-
618
- function wpvivid_handle_backup_data(data){
619
- try {
620
- var jsonarray = jQuery.parseJSON(data);
621
- if (jsonarray.result === 'success') {
622
- jQuery('#wpvivid_backup_list').html('');
623
- jQuery('#wpvivid_backup_list').append(jsonarray.html);
624
- }
625
- else if(jsonarray.result === 'failed'){
626
- alert(jsonarray.error);
627
- }
628
- }
629
- catch(err){
630
- alert(err);
631
- }
632
- }
633
-
634
- function wpvivid_click_check_backup(backup_id, list_name){
635
- var name = "";
636
- var all_check = true;
637
- jQuery('#'+list_name+' tr').each(function (i) {
638
- jQuery(this).children('th').each(function (j) {
639
- if(j === 0) {
640
- var id = jQuery(this).find("input[type=checkbox]").attr("id");
641
- if (id === backup_id) {
642
- name = jQuery(this).parent().children('td').eq(0).find("img").attr("name");
643
- if (name === "unlock") {
644
- if (jQuery(this).find("input[type=checkbox]").prop('checked') === false) {
645
- all_check = false;
646
- }
647
- }
648
- else {
649
- jQuery(this).find("input[type=checkbox]").prop('checked', false);
650
- all_check = false;
651
- }
652
- }
653
- else {
654
- if (jQuery(this).find("input[type=checkbox]").prop('checked') === false) {
655
- all_check = false;
656
- }
657
- }
658
- }
659
- });
660
- });
661
- if(all_check === true){
662
- jQuery('#backup_list_all_check').prop('checked', true);
663
- }
664
- else{
665
- jQuery('#backup_list_all_check').prop('checked', false);
666
- }
667
- }
668
-
669
- function wpvivid_set_backup_lock(backup_id, lock_status){
670
- var max_count_limit = '<?php echo $display_backup_count; ?>';
671
- var check_status = true;
672
- if(lock_status === "lock"){
673
- var lock=0;
674
- }
675
- else{
676
- var lock=1;
677
- var check_can_lock=false;
678
- var baackup_list_count = jQuery('#wpvivid_backup_list').find('tr').length;
679
- if(baackup_list_count >= max_count_limit) {
680
- jQuery('#wpvivid_backup_list').find('tr').find('td:eq(0)').find('span:eq(0)').each(function () {
681
- var span_id = jQuery(this).attr('id');
682
- span_id = span_id.replace('wpvivid_lock_', '');
683
- if (span_id !== backup_id) {
684
- var name = jQuery(this).find('img:eq(0)').attr('name');
685
- if (name === 'unlock') {
686
- check_can_lock = true;
687
- return false;
688
- }
689
- }
690
- });
691
- if (!check_can_lock) {
692
- check_status = false;
693
- alert('The locked backups will reach the maximum limits of retained backups, which causes being unable to create a new backup. So, please unlock one of them and continue.');
694
- }
695
- }
696
- }
697
- if(check_status) {
698
- var ajax_data = {
699
- 'action': 'wpvivid_set_security_lock',
700
- 'backup_id': backup_id,
701
- 'lock': lock
702
- };
703
- wpvivid_post_request(ajax_data, function (data) {
704
- try {
705
- var jsonarray = jQuery.parseJSON(data);
706
- if (jsonarray.result === 'success') {
707
- jQuery('#wpvivid_lock_' + backup_id).html(jsonarray.html);
708
- }
709
- }
710
- catch (err) {
711
- alert(err);
712
- }
713
- }, function (XMLHttpRequest, textStatus, errorThrown) {
714
- var error_message = wpvivid_output_ajaxerror('setting up a lock for the backup', textStatus, errorThrown);
715
- alert(error_message);
716
- });
717
- }
718
- }
719
-
720
- function wpvivid_read_log(action, param){
721
- var tab_id = '';
722
- var content_id = '';
723
- var ajax_data = '';
724
- var show_page = '';
725
- if(typeof param === 'undefined') param = '';
726
- switch(action){
727
- case 'wpvivid_view_backup_task_log':
728
- ajax_data = {
729
- 'action':action,
730
- 'id':running_backup_taskid
731
- };
732
- tab_id = 'wpvivid_tab_backup_log';
733
- content_id = 'wpvivid_display_log_content';
734
- show_page = 'backup_page';
735
- break;
736
- case 'wpvivid_read_last_backup_log':
737
- var ajax_data = {
738
- 'action': action,
739
- 'log_file_name': param
740
- };
741
- tab_id = 'wpvivid_tab_backup_log';
742
- content_id = 'wpvivid_display_log_content';
743
- show_page = 'backup_page';
744
- break;
745
- case 'wpvivid_view_backup_log':
746
- var ajax_data={
747
- 'action':action,
748
- 'id':param
749
- };
750
- tab_id = 'wpvivid_tab_backup_log';
751
- content_id = 'wpvivid_display_log_content';
752
- show_page = 'backup_page';
753
- break;
754
- case 'wpvivid_view_log':
755
- var ajax_data={
756
- 'action':action,
757
- 'path':param
758
- };
759
- tab_id = 'wpvivid_tab_read_log';
760
- content_id = 'wpvivid_read_log_content';
761
- show_page = 'log_page';
762
- break;
763
- default:
764
- break;
765
- }
766
- jQuery('#'+tab_id).show();
767
- jQuery('#'+content_id).html("");
768
- if(show_page === 'backup_page'){
769
- //wpvivid_click_switch_backup_page(tab_id);
770
- wpvivid_click_switch_page('backup', tab_id, true);
771
- }
772
- else if(show_page === 'log_page') {
773
- wpvivid_click_switch_page('wrap', tab_id, true);
774
- }
775
- wpvivid_post_request(ajax_data, function(data){
776
- wpvivid_show_log(data, content_id);
777
- }, function(XMLHttpRequest, textStatus, errorThrown) {
778
- var div = 'Reading the log failed. Please try again.';
779
- jQuery('#wpvivid_display_log_content').html(div);
780
- });
781
- }
782
-
783
- /*function wpvivid_initialize_download(backup_id, list_name){
784
- wpvivid_reset_backup_list(list_name);
785
- jQuery('#wpvivid_download_loading_'+backup_id).addClass('is-active');
786
- tmp_current_click_backupid = backup_id;
787
- var ajax_data = {
788
- 'action':'wpvivid_init_download_page',
789
- 'backup_id':backup_id
790
- };
791
- wpvivid_post_request(ajax_data, function(data){
792
- try {
793
- var jsonarray = jQuery.parseJSON(data);
794
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
795
- if (jsonarray.result === 'success') {
796
- jQuery('#wpvivid_file_part_' + backup_id).html("");
797
- var i = 0;
798
- var file_not_found = false;
799
- var file_name = '';
800
- jQuery.each(jsonarray.files, function (index, value) {
801
- i++;
802
- file_name = index;
803
- if (value.status === 'need_download') {
804
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
805
- //tmp_current_click_backupid = '';
806
- }
807
- else if (value.status === 'running') {
808
- if (m_downloading_file_name === file_name) {
809
- wpvivid_lock_download(tmp_current_click_backupid);
810
- }
811
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
812
- }
813
- else if (value.status === 'completed') {
814
- if (m_downloading_file_name === file_name) {
815
- wpvivid_unlock_download(tmp_current_click_backupid);
816
- m_downloading_id = '';
817
- m_downloading_file_name = '';
818
- }
819
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
820
- //tmp_current_click_backupid = '';
821
- }
822
- else if (value.status === 'timeout') {
823
- if (m_downloading_file_name === file_name) {
824
- wpvivid_unlock_download(tmp_current_click_backupid);
825
- m_downloading_id = '';
826
- m_downloading_file_name = '';
827
- }
828
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
829
- //tmp_current_click_backupid = '';
830
- }
831
- else if (value.status === 'file_not_found') {
832
- wpvivid_unlock_download(tmp_current_click_backupid);
833
- wpvivid_reset_backup_list(list_name);
834
- file_not_found = true;
835
- alert("Download failed, file not found. The file might has been moved, renamed or deleted. Please verify the file exists and try again.");
836
- //tmp_current_click_backupid = '';
837
- return false;
838
- }
839
- });
840
- if (file_not_found === false) {
841
- jQuery('#wpvivid_file_part_' + backup_id).append(jsonarray.place_html);
842
- }
843
- }
844
- }
845
- catch(err){
846
- alert(err);
847
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
848
- }
849
- },function(XMLHttpRequest, textStatus, errorThrown){
850
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
851
- var error_message = wpvivid_output_ajaxerror('initializing download information', textStatus, errorThrown);
852
- alert(error_message);
853
- });
854
- }*/
855
-
856
- function wpvivid_reset_backup_list(list_name){
857
- jQuery('#'+list_name+' tr').each(function(i){
858
- jQuery(this).children('td').each(function (j) {
859
- if (j == 2) {
860
- var backup_id = jQuery(this).parent().children('th').find("input[type=checkbox]").attr("id");
861
- var download_btn = '<div id="wpvivid_file_part_' + backup_id + '" style="float:left;padding:10px 10px 10px 0px;">' +
862
- '<div style="cursor:pointer;" onclick="wpvivid_initialize_download(\'' + backup_id + '\', \''+list_name+'\');" title="Prepare to download the backup">' +
863
- '<img id="wpvivid_download_btn_' + backup_id + '" src="' + wpvivid_plugurl + '/admin/partials/images/download.png" style="vertical-align:middle;" />Download' +
864
- '<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>' +
865
- '</div>' +
866
- '</div>';
867
- jQuery(this).html(download_btn);
868
- }
869
- });
870
- });
871
- }
872
-
873
- function wpvivid_lock_download(backup_id){
874
- jQuery('#wpvivid_backup_list tr').each(function(i){
875
- jQuery(this).children('td').each(function (j) {
876
- if (j == 2) {
877
- jQuery(this).css({'pointer-events': 'none', 'opacity': '0.4'});
878
- }
879
- });
880
- });
881
- }
882
-
883
- function wpvivid_unlock_download(backup_id){
884
- jQuery('#wpvivid_backup_list tr').each(function(i){
885
- jQuery(this).children('td').each(function (j) {
886
- if (j == 2) {
887
- jQuery(this).css({'pointer-events': 'auto', 'opacity': '1'});
888
- }
889
- });
890
- });
891
- }
892
-
893
- /**
894
- * Start downloading backup
895
- *
896
- * @param part_num - The part number for the download object
897
- * @param backup_id - The unique ID for the backup
898
- * @param file_name - File name
899
- */
900
- function wpvivid_prepare_download(part_num, backup_id, file_name){
901
- var ajax_data = {
902
- 'action': 'wpvivid_prepare_download_backup',
903
- 'backup_id':backup_id,
904
- 'file_name':file_name
905
- };
906
- var progress = '0%';
907
- jQuery("#"+backup_id+"-text-part-"+part_num).html("<a>Retriving(remote storage to web server)</a>");
908
- jQuery("#"+backup_id+"-progress-part-"+part_num).css('width', progress);
909
- task_retry_times = 0;
910
- m_need_update = true;
911
- wpvivid_lock_download(backup_id);
912
- m_downloading_id = backup_id;
913
- tmp_current_click_backupid = backup_id;
914
- m_downloading_file_name = file_name;
915
- wpvivid_post_request(ajax_data, function(data)
916
- {
917
- }, function(XMLHttpRequest, textStatus, errorThrown)
918
- {
919
- }, 0);
920
- }
921
-
922
- /**
923
- * Download backups to user's computer.
924
- *
925
- * @param backup_id - The unique ID for the backup
926
- * @param backup_type - The types of the backup
927
- * @param file_name - File name
928
- */
929
- function wpvivid_download(backup_id, backup_type, file_name){
930
- wpvivid_location_href=true;
931
- location.href =ajaxurl+'?_wpnonce='+wpvivid_ajax_object.ajax_nonce+'&action=wpvivid_download_backup&backup_id='+backup_id+'&download_type='+backup_type+'&file_name='+file_name;
932
- }
933
-
934
- function wpvivid_initialize_restore(backup_id, backup_time, backup_type, restore_type='backup'){
935
- var time_type = 'backup';
936
- var log_type = '';
937
- var tab_type = '';
938
- var page_type = 'backup';
939
- if(restore_type == 'backup'){
940
- time_type = 'backup';
941
- log_type = '';
942
- tab_type = '';
943
- page_type = 'backup';
944
- }
945
- else if(restore_type == 'transfer'){
946
- time_type = 'transfer';
947
- log_type = 'transfer_';
948
- tab_type = 'add_';
949
- page_type = 'migrate';
950
- }
951
- wpvivid_restore_backup_type = backup_type;
952
- jQuery('#wpvivid_restore_'+time_type+'_time').html(backup_time);
953
- m_restore_backup_id = backup_id;
954
- jQuery('#wpvivid_restore_'+log_type+'log').html("");
955
- jQuery('#wpvivid_'+tab_type+'tab_restore').show();
956
- wpvivid_click_switch_page(page_type, 'wpvivid_'+tab_type+'tab_restore', true);
957
- wpvivid_init_restore_data(restore_type);
958
- }
959
-
960
- function click_dismiss_restore_check_notice(obj){
961
- wpvivid_display_restore_check = false;
962
- jQuery(obj).parent().remove();
963
- }
964
-
965
- /**
966
- * This function will initialize restore information
967
- *
968
- * @param backup_id - The unique ID for the backup
969
- */
970
- function wpvivid_init_restore_data(restore_type)
971
- {
972
- wpvivid_resotre_is_migrate=0;
973
- var restore_method = '';
974
- if(restore_type == 'backup'){
975
- restore_method = '';
976
- }
977
- else if(restore_type == 'transfer'){
978
- restore_method = 'transfer_';
979
- }
980
- jQuery('#wpvivid_replace_domain').prop('checked', false);
981
- jQuery('#wpvivid_keep_domain').prop('checked', false);
982
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
983
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
984
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
985
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
986
- jQuery('#wpvivid_restore_'+restore_method+'part').show();
987
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
988
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
989
- jQuery('#wpvivid_download_'+restore_method+'part').hide();
990
-
991
- jQuery('#wpvivid_init_restore_data').addClass('is-active');
992
- var ajax_data = {
993
- 'action':'wpvivid_init_restore_page',
994
- 'backup_id':m_restore_backup_id
995
- };
996
- wpvivid_post_request(ajax_data, function(data){
997
- try {
998
- var jsonarray = jQuery.parseJSON(data);
999
- var init_status = false;
1000
- if(jsonarray.result === 'success') {
1001
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1002
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1003
- jQuery('#wpvivid_restore_'+restore_method+'part').show();
1004
- jQuery('#wpvivid_download_'+restore_method+'part').hide();
1005
- wpvivid_restore_need_download = false;
1006
- init_status = true;
1007
- }
1008
- else if (jsonarray.result === "need_download"){
1009
- init_status = true;
1010
- wpvivid_restore_download_array = new Array();
1011
- var download_num = 0;
1012
- jQuery.each(jsonarray.files, function (index, value)
1013
- {
1014
- if (value.status === "need_download")
1015
- {
1016
- wpvivid_restore_download_array[download_num] = new Array('file_name', 'size', 'md5');
1017
- wpvivid_restore_download_array[download_num]['file_name'] = index;
1018
- wpvivid_restore_download_array[download_num]['size'] = value.size;
1019
- wpvivid_restore_download_array[download_num]['md5'] = value.md5;
1020
- download_num++;
1021
- }
1022
- });
1023
- wpvivid_restore_download_index=0;
1024
- wpvivid_restore_need_download = true;
1025
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1026
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1027
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1028
- jQuery('#wpvivid_download_'+restore_method+'part').show();
1029
- }
1030
- else if (jsonarray.result === "failed") {
1031
- jQuery('#wpvivid_init_restore_data').removeClass('is-active');
1032
- wpvivid_display_restore_msg(jsonarray.error, restore_type);
1033
- }
1034
-
1035
- if(init_status){
1036
- if(jsonarray.max_allow_packet_warning != false || jsonarray.memory_limit_warning != false) {
1037
- if(!wpvivid_display_restore_check) {
1038
- wpvivid_display_restore_check = true;
1039
- var output = '';
1040
- if(jsonarray.max_allow_packet_warning != false){
1041
- output += "<p>" + jsonarray.max_allow_packet_warning + "</p>";
1042
- }
1043
- if(jsonarray.memory_limit_warning != false){
1044
- output += "<p>" + jsonarray.memory_limit_warning + "</p>";
1045
- }
1046
- var div = "<div class='notice notice-warning is-dismissible inline'>" +
1047
- output +
1048
- "<button type='button' class='notice-dismiss' onclick='click_dismiss_restore_check_notice(this);'>" +
1049
- "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1050
- "</button>" +
1051
- "</div>";
1052
- jQuery('#wpvivid_restore_check').append(div);
1053
- }
1054
- }
1055
- jQuery('#wpvivid_init_restore_data').removeClass('is-active');
1056
- if (jsonarray.has_exist_restore === 0) {
1057
- if(wpvivid_restore_need_download == false) {
1058
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1059
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1060
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1061
- jQuery('#wpvivid_restore_' + restore_method + 'part').show();
1062
- jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
1063
- jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
1064
- jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
1065
-
1066
- jQuery('#wpvivid_restore_is_migrate').hide();
1067
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1068
-
1069
- wpvivid_resotre_is_migrate = jsonarray.is_migrate;
1070
-
1071
- if (jsonarray.is_migrate_ui === 1) {
1072
- jQuery('#wpvivid_restore_is_migrate').show()
1073
- jQuery('#wpvivid_replace_domain').prop('checked', false);
1074
- jQuery('#wpvivid_keep_domain').prop('checked', false);
1075
- }
1076
- else {
1077
- jQuery('#wpvivid_restore_is_migrate').hide();
1078
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1079
- }
1080
-
1081
- wpvivid_interface_flow_control();
1082
- }
1083
- }
1084
- else if (jsonarray.has_exist_restore === 1) {
1085
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1086
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'auto', 'opacity': '1'});
1087
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1088
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1089
- jQuery('#wpvivid_clean_'+restore_method+'part').show();
1090
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1091
- jQuery('#wpvivid_restore_is_migrate').hide();
1092
- wpvivid_display_restore_msg("An uncompleted restore task exists, please terminate it first.", restore_type);
1093
- }
1094
- }
1095
- }
1096
- catch(err){
1097
- alert(err);
1098
- }
1099
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1100
- jQuery('#wpvivid_init_restore_data').removeClass('is-active');
1101
- var error_message = wpvivid_output_ajaxerror('initializing restore information', textStatus, errorThrown);
1102
- wpvivid_display_restore_msg(error_message, restore_type);
1103
- });
1104
- }
1105
-
1106
- function wpvivid_delete_selected_backup(backup_id, list_name){
1107
- var name = '';
1108
- jQuery('#wpvivid_backup_list tr').each(function(i){
1109
- jQuery(this).children('td').each(function (j) {
1110
- if (j == 0) {
1111
- var id = jQuery(this).parent().children('th').find("input[type=checkbox]").attr("id");
1112
- if(id === backup_id){
1113
- name = jQuery(this).parent().children('td').eq(0).find('img').attr('name');
1114
- }
1115
- }
1116
- });
1117
- });
1118
- var descript = '';
1119
- var force_del = 0;
1120
- var bdownloading = false;
1121
- if(name === 'lock') {
1122
- descript = '<?php _e('This backup is locked, are you sure to remove it? This backup will be deleted permanently from your hosting (localhost) and remote storages.', 'wpvivid-backuprestore'); ?>';
1123
- force_del = 1;
1124
- }
1125
- else{
1126
- descript = '<?php _e('Are you sure to remove this backup? This backup will be deleted permanently from your hosting (localhost) and remote storages.', 'wpvivid-backuprestore'); ?>';
1127
- force_del = 0;
1128
- }
1129
- if(m_downloading_id === backup_id){
1130
- bdownloading = true;
1131
- descript = '<?php _e('This request will delete the backup being downloaded, are you sure you want to continue?', 'wpvivid-backuprestore'); ?>';
1132
- force_del = 1;
1133
- }
1134
- var ret = confirm(descript);
1135
- if(ret === true){
1136
- var ajax_data={
1137
- 'action': 'wpvivid_delete_backup',
1138
- 'backup_id': backup_id,
1139
- 'force': force_del
1140
- };
1141
- wpvivid_post_request(ajax_data, function(data){
1142
- wpvivid_handle_backup_data(data);
1143
- if(bdownloading){
1144
- m_downloading_id = '';
1145
- }
1146
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1147
- var error_message = wpvivid_output_ajaxerror('deleting the backup', textStatus, errorThrown);
1148
- alert(error_message);
1149
- });
1150
- }
1151
- }
1152
- function wpvivid_delete_backups_inbatches(){
1153
- var delete_backup_array = new Array();
1154
- var count = 0;
1155
- var bdownloading = false;
1156
- jQuery('#wpvivid_backup_list tr').each(function (i) {
1157
- jQuery(this).children('th').each(function (j) {
1158
- if (j == 0) {
1159
- if(jQuery(this).find('input[type=checkbox]').prop('checked')){
1160
- delete_backup_array[count] = jQuery(this).find('input[type=checkbox]').attr('id');
1161
- if(m_downloading_id === jQuery(this).find('input[type=checkbox]').attr('id')){
1162
- bdownloading = true;
1163
- }
1164
- count++;
1165
- }
1166
- }
1167
- });
1168
- });
1169
- if( count === 0 ){
1170
- alert('<?php _e('Please select at least one item.','wpvivid-backuprestore'); ?>');
1171
- }
1172
- else {
1173
- var descript = '';
1174
- if(bdownloading) {
1175
- descript = '<?php _e('This request might delete the backup being downloaded, are you sure you want to continue?', 'wpvivid-backuprestore'); ?>';
1176
- }
1177
- else{
1178
- descript = '<?php _e('Are you sure to remove the selected backups? These backups will be deleted permanently from your hosting (localhost).', 'wpvivid-backuprestore'); ?>';
1179
- }
1180
- var ret = confirm(descript);
1181
- if (ret === true) {
1182
- var ajax_data = {
1183
- 'action': 'wpvivid_delete_backup_array',
1184
- 'backup_id': delete_backup_array
1185
- };
1186
- wpvivid_post_request(ajax_data, function (data) {
1187
- wpvivid_handle_backup_data(data);
1188
- jQuery('#backup_list_all_check').prop('checked', false);
1189
- if(bdownloading){
1190
- m_downloading_id = '';
1191
- }
1192
- }, function (XMLHttpRequest, textStatus, errorThrown) {
1193
- var error_message = wpvivid_output_ajaxerror('deleting the backup', textStatus, errorThrown);
1194
- alert(error_message);
1195
- });
1196
- }
1197
- }
1198
- }
1199
-
1200
- jQuery('#backup_list_all_check').click(function(){
1201
- var name = '';
1202
- if(jQuery('#backup_list_all_check').prop('checked')) {
1203
- jQuery('#wpvivid_backup_list tr').each(function (i) {
1204
- jQuery(this).children('th').each(function (j) {
1205
- if (j == 0) {
1206
- name = jQuery(this).parent().children('td').eq(0).find("img").attr("name");
1207
- if(name === 'unlock') {
1208
- jQuery(this).find("input[type=checkbox]").prop('checked', true);
1209
- }
1210
- else{
1211
- jQuery(this).find("input[type=checkbox]").prop('checked', false);
1212
- }
1213
- }
1214
- });
1215
- });
1216
- }
1217
- else{
1218
- jQuery('#wpvivid_backup_list tr').each(function (i) {
1219
- jQuery(this).children('th').each(function (j) {
1220
- if (j == 0) {
1221
- jQuery(this).find("input[type=checkbox]").prop('checked', false);
1222
- }
1223
- });
1224
- });
1225
- }
1226
- });
1227
-
1228
- function click_dismiss_restore_notice(obj){
1229
- wpvivid_display_restore_backup = false;
1230
- jQuery(obj).parent().remove();
1231
- }
1232
-
1233
- function wpvivid_click_how_to_restore_backup(){
1234
- if(!wpvivid_display_restore_backup){
1235
- wpvivid_display_restore_backup = true;
1236
- var top = jQuery('#wpvivid_how_to_restore_backup_describe').offset().top-jQuery('#wpvivid_how_to_restore_backup_describe').height();
1237
- jQuery('html, body').animate({scrollTop:top}, 'slow');
1238
- var div = "<div class='notice notice-info is-dismissible inline'>" +
1239
- "<p>" + wpvividlion.restore_step1 + "</p>" +
1240
- "<p>" + wpvividlion.restore_step2 + "</p>" +
1241
- "<p>" + wpvividlion.restore_step3 + "</p>" +
1242
- "<button type='button' class='notice-dismiss' onclick='click_dismiss_restore_notice(this);'>" +
1243
- "<span class='screen-reader-text'>Dismiss this notice.</span>" +
1244
- "</button>" +
1245
- "</div>";
1246
- jQuery('#wpvivid_how_to_restore_backup').append(div);
1247
- }
1248
- }
1249
- </script>
1250
- <?php
1251
- }
1252
-
1253
- function wpvivid_backuppage_add_page_log(){
1254
- ?>
1255
- <div class="backup-tab-content wpvivid_tab_backup_log" id="page-log" style="display:none;">
1256
- <div class="postbox restore_log" id="wpvivid_display_log_content">
1257
- <div></div>
1258
- </div>
1259
- </div>
1260
- <?php
1261
- }
1262
-
1263
- function wpvivid_backuppage_add_page_restore(){
1264
- $general_setting=WPvivid_Setting::get_setting(true, "");
1265
- if(isset($general_setting['options']['wpvivid_common_setting']['restore_max_execution_time'])){
1266
- $restore_max_execution_time = intval($general_setting['options']['wpvivid_common_setting']['restore_max_execution_time']);
1267
- }
1268
- else{
1269
- $restore_max_execution_time = WPVIVID_RESTORE_MAX_EXECUTION_TIME;
1270
- }
1271
- ?>
1272
- <div class="backup-tab-content wpvivid_tab_restore" id="page-restore" style="display:none;">
1273
- <div>
1274
- <h3><?php _e('Restore backup from:', 'wpvivid-backuprestore'); ?><span id="wpvivid_restore_backup_time"></span></h3>
1275
- <p><strong><?php _e('Please do not close the page or switch to other pages when a restore task is running, as it could trigger some unexpected errors.', 'wpvivid-backuprestore'); ?></strong></p>
1276
- <p><?php _e('Restore function will replace the current site\'s themes, plugins, uploads, database and/or other content directories with the existing equivalents in the selected backup.', 'wpvivid-backuprestore'); ?></p>
1277
- <div id="wpvivid_restore_is_migrate" style="padding-bottom: 10px; display: none;">
1278
- <label >
1279
- <input type="radio" id="wpvivid_replace_domain" option="restore" name="restore_domain" value="1" /><?php echo sprintf(__('Restore and replace the original domain (URL) with %s (migration)', 'wpvivid-backuprestore'), home_url()); ?>
1280
- </label><br>
1281
- <label >
1282
- <input type="radio" id="wpvivid_keep_domain" option="restore" name="restore_domain" value="0" /><?php _e('Restore and keep the original domain (URL) unchanged', 'wpvivid-backuprestore'); ?>
1283
- </label><br>
1284
- </div>
1285
- <div>
1286
- <p><strong><?php _e('Tips:', 'wpvivid-backuprestore'); ?></strong>&nbsp<?php _e('If you are migrating a website, the source domain will be replaced with the target domain automatically. For example, if you are migrating a.com to b.com, then a.com will be replaced with b.com during the restore.', 'wpvivid-backuprestore'); ?></p>
1287
- </div>
1288
- <div id="wpvivid_restore_check"></div>
1289
- <div class="restore-button-position" id="wpvivid_restore_part"><input class="button-primary" id="wpvivid_restore_btn" type="submit" name="restore" value="<?php esc_attr_e( 'Restore', 'wpvivid-backuprestore' ); ?>" onclick="wpvivid_start_restore();" /></div>
1290
- <div class="restore-button-position" id="wpvivid_clean_part"><input class="button-primary" id="wpvivid_clean_restore" type="submit" name="clear_restore" value="<?php esc_attr_e( 'Terminate', 'wpvivid-backuprestore' ); ?>" /></div>
1291
- <div class="restore-button-position" id="wpvivid_rollback_part"><input class="button-primary" id="wpvivid_rollback_btn" type="submit" name="rollback" value="<?php esc_attr_e( 'Rollback', 'wpvivid-backuprestore' ); ?>" /></div>
1292
- <div class="restore-button-position" id="wpvivid_download_part">
1293
- <input class="button-primary" id="wpvivid_download_btn" type="submit" name="download" value="<?php esc_attr_e( 'Retrieve the backup to localhost', 'wpvivid-backuprestore' ); ?>" />
1294
- <span><?php _e('The backup is stored on the remote storage, click on the button to download it to localhost.', 'wpvivid-backuprestore'); ?></span>
1295
- </div>
1296
- <div class="spinner" id="wpvivid_init_restore_data" style="float:left;width:auto;height:auto;padding:10px 20px 20px 0;background-position:0 10px;"></div>
1297
- </div>
1298
- <div class="postbox restore_log" id="wpvivid_restore_log"></div>
1299
- </div>
1300
- <script>
1301
- var restore_max_exection_time = '<?php echo $restore_max_execution_time; ?>';
1302
- restore_max_exection_time = restore_max_exection_time * 1000;
1303
- jQuery('#wpvivid_clean_restore').click(function(){
1304
- wpvivid_delete_incompleted_restore();
1305
- });
1306
-
1307
- jQuery('#wpvivid_download_btn').click(function(){
1308
- wpvivid_download_restore_file('backup');
1309
- });
1310
-
1311
- function wpvivid_delete_incompleted_restore(restore_type = 'backup'){
1312
- var restore_method = '';
1313
- if(restore_type == 'backup'){
1314
- restore_method = '';
1315
- }
1316
- else if(restore_type == 'transfer'){
1317
- restore_method = 'transfer_';
1318
- }
1319
-
1320
- var ajax_data={
1321
- 'action': 'wpvivid_delete_last_restore_data'
1322
- };
1323
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1324
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'auto', 'opacity': '1'});
1325
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1326
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1327
- jQuery('#wpvivid_clean_'+restore_method+'part').show();
1328
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1329
- wpvivid_post_request(ajax_data, function(data) {
1330
- try {
1331
- var jsonarray = jQuery.parseJSON(data);
1332
- if (jsonarray.result === "success") {
1333
- wpvivid_display_restore_msg("The restore task is terminated.", restore_type);
1334
- wpvivid_init_restore_data(restore_type);
1335
- }
1336
- }
1337
- catch(err){
1338
- alert(err);
1339
- }
1340
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1341
- var error_message = wpvivid_output_ajaxerror('deleting the last incomplete restore task', textStatus, errorThrown);
1342
- wpvivid_display_restore_msg(error_message, restore_type);
1343
- });
1344
- }
1345
-
1346
- function wpvivid_restore_is_migrate(restore_type){
1347
- var ajax_data = {
1348
- 'action': 'wpvivid_get_restore_file_is_migrate',
1349
- 'backup_id': m_restore_backup_id
1350
- };
1351
- var restore_method = '';
1352
- wpvivid_post_request(ajax_data, function(data)
1353
- {
1354
- try
1355
- {
1356
- var jsonarray = jQuery.parseJSON(data);
1357
- if(jsonarray.result === "success")
1358
- {
1359
- if (jsonarray.is_migrate_ui === 1)
1360
- {
1361
- jQuery('#wpvivid_restore_is_migrate').show();
1362
- jQuery('#wpvivid_replace_domain').prop('checked', false);
1363
- jQuery('#wpvivid_keep_domain').prop('checked', false);
1364
- }
1365
- else {
1366
- jQuery('#wpvivid_restore_is_migrate').hide();
1367
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1368
- }
1369
- }
1370
- else if (jsonarray.result === "failed") {
1371
- jQuery('#wpvivid_init_restore_data').removeClass('is-active');
1372
- wpvivid_display_restore_msg(jsonarray.error, restore_type);
1373
- }
1374
- }
1375
- catch(err){
1376
- alert(err);
1377
- }
1378
- }, function(XMLHttpRequest, textStatus, errorThrown)
1379
- {
1380
- setTimeout(function()
1381
- {
1382
- wpvivid_restore_is_migrate(restore_type);
1383
- }, 3000);
1384
- });
1385
- }
1386
-
1387
- /**
1388
- * This function will start the process of restoring a backup
1389
- */
1390
- function wpvivid_start_restore(restore_type = 'backup'){
1391
- if(!wpvivid_restore_sure){
1392
- var descript = 'Are you sure to continue?';
1393
- var ret = confirm(descript);
1394
- }
1395
- else{
1396
- ret = true;
1397
- }
1398
- if (ret === true) {
1399
- wpvivid_restore_sure = true;
1400
- var restore_method = '';
1401
- if (restore_type == 'backup') {
1402
- restore_method = '';
1403
- }
1404
- else if (restore_type == 'transfer') {
1405
- restore_method = 'transfer_';
1406
- }
1407
- jQuery('#wpvivid_restore_' + restore_method + 'log').html("");
1408
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1409
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1410
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1411
- jQuery('#wpvivid_restore_' + restore_method + 'part').show();
1412
- jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
1413
- jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
1414
- wpvivid_restore_lock();
1415
- wpvivid_restoring = true;
1416
- if (wpvivid_restore_need_download) {
1417
- wpvivid_download_restore_file(restore_type);
1418
- }
1419
- else {
1420
- wpvivid_monitor_restore_task(restore_type);
1421
- if(wpvivid_resotre_is_migrate==0)
1422
- {
1423
- jQuery('input:radio[option=restore]').each(function()
1424
- {
1425
- if(jQuery(this).prop('checked'))
1426
- {
1427
- var value = jQuery(this).prop('value');
1428
- if(value == '1')
1429
- {
1430
- wpvivid_resotre_is_migrate = '1';
1431
- }
1432
- }
1433
- });
1434
- }
1435
-
1436
- wpvivid_restore(restore_type);
1437
- }
1438
- }
1439
- }
1440
-
1441
- function wpvivid_download_restore_file(restore_type)
1442
- {
1443
- var restore_method = '';
1444
- if(restore_type == 'backup'){
1445
- restore_method = '';
1446
- }
1447
- else if(restore_type == 'transfer'){
1448
- restore_method = 'transfer_';
1449
- }
1450
-
1451
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1452
- wpvivid_restore_lock();
1453
- if(wpvivid_restore_download_array.length===0)
1454
- {
1455
- 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);
1456
- wpvivid_restore_unlock();
1457
- return false;
1458
- }
1459
-
1460
- if(wpvivid_restore_download_index+1>wpvivid_restore_download_array.length)
1461
- {
1462
- wpvivid_display_restore_msg("Download succeeded.", restore_type);
1463
- wpvivid_restore_is_migrate(restore_type);
1464
- wpvivid_restore_need_download = false;
1465
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1466
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1467
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1468
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1469
- jQuery('#wpvivid_restore_' + restore_method + 'part').show();
1470
- jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
1471
- jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
1472
- jQuery('#wpvivid_download_'+restore_method+'part').hide();
1473
- //wpvivid_start_restore(restore_type);
1474
- }
1475
- else
1476
- {
1477
- wpvivid_display_restore_msg("Downloading backup file " + wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'], restore_type);
1478
- wpvivid_display_restore_msg('', restore_type, wpvivid_restore_download_index);
1479
- var ajax_data = {
1480
- 'action': 'wpvivid_download_restore',
1481
- 'backup_id': m_restore_backup_id,
1482
- 'file_name': wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],
1483
- 'size': wpvivid_restore_download_array[wpvivid_restore_download_index]['size'],
1484
- 'md5': wpvivid_restore_download_array[wpvivid_restore_download_index]['md5']
1485
- }
1486
- wpvivid_get_download_restore_progress_retry=0;
1487
- wpvivid_monitor_download_restore_task(restore_type);
1488
- wpvivid_post_request(ajax_data, function (data) {
1489
- }, function (XMLHttpRequest, textStatus, errorThrown) {
1490
- }, 0);
1491
- }
1492
- }
1493
-
1494
- function wpvivid_monitor_download_restore_task(restore_type)
1495
- {
1496
- var restore_method = '';
1497
- if(restore_type == 'backup'){
1498
- restore_method = '';
1499
- }
1500
- else if(restore_type == 'transfer'){
1501
- restore_method = 'transfer_';
1502
- }
1503
-
1504
- var ajax_data={
1505
- 'action':'wpvivid_get_download_restore_progress',
1506
- 'file_name': wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],
1507
- 'size': wpvivid_restore_download_array[wpvivid_restore_download_index]['size'],
1508
- 'md5': wpvivid_restore_download_array[wpvivid_restore_download_index]['md5']
1509
- };
1510
-
1511
- wpvivid_post_request(ajax_data, function(data)
1512
- {
1513
- try
1514
- {
1515
- var jsonarray = jQuery.parseJSON(data);
1516
- if(typeof jsonarray ==='object')
1517
- {
1518
- if(jsonarray.result === "success")
1519
- {
1520
- if(jsonarray.status==='completed')
1521
- {
1522
- wpvivid_display_restore_msg(wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'] + ' download succeeded.', restore_type, wpvivid_restore_download_index, false);
1523
- wpvivid_restore_download_index++;
1524
- wpvivid_download_restore_file(restore_type);
1525
- wpvivid_restore_unlock();
1526
- }
1527
- else if(jsonarray.status==='error')
1528
- {
1529
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1530
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1531
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1532
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1533
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1534
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1535
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1536
- jQuery('#wpvivid_download_'+restore_method+'part').show();
1537
- var error_message = jsonarray.error;
1538
- wpvivid_display_restore_msg(error_message,restore_type,wpvivid_restore_download_array[wpvivid_restore_download_index]['file_name'],false);
1539
- wpvivid_restore_unlock();
1540
- }
1541
- else if(jsonarray.status==='running')
1542
- {
1543
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1544
- wpvivid_display_restore_msg(jsonarray.log, restore_type, wpvivid_restore_download_index, false);
1545
- setTimeout(function()
1546
- {
1547
- wpvivid_monitor_download_restore_task(restore_type);
1548
- }, 3000);
1549
- wpvivid_restore_lock();
1550
- }
1551
- else if(jsonarray.status==='timeout')
1552
- {
1553
- wpvivid_get_download_restore_progress_retry++;
1554
- if(wpvivid_get_download_restore_progress_retry>10)
1555
- {
1556
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1557
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1558
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1559
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1560
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1561
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1562
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1563
- jQuery('#wpvivid_download_'+restore_method+'part').show();
1564
- var error_message = jsonarray.error;
1565
- wpvivid_display_restore_msg(error_message, restore_type);
1566
- wpvivid_restore_unlock();
1567
- }
1568
- else
1569
- {
1570
- setTimeout(function()
1571
- {
1572
- wpvivid_monitor_download_restore_task(restore_type);
1573
- }, 3000);
1574
- }
1575
- }
1576
- else
1577
- {
1578
- setTimeout(function()
1579
- {
1580
- wpvivid_monitor_download_restore_task(restore_type);
1581
- }, 3000);
1582
- }
1583
- }
1584
- else
1585
- {
1586
- wpvivid_get_download_restore_progress_retry++;
1587
- if(wpvivid_get_download_restore_progress_retry>10)
1588
- {
1589
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1590
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1591
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1592
- jQuery('#wpvivid_download_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1593
- jQuery('#wpvivid_restore_'+restore_method+'part').hide();
1594
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1595
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1596
- jQuery('#wpvivid_download_'+restore_method+'part').show();
1597
- var error_message = jsonarray.error;
1598
- wpvivid_display_restore_msg(error_message, restore_type);
1599
- wpvivid_restore_unlock();
1600
- }
1601
- else
1602
- {
1603
- setTimeout(function()
1604
- {
1605
- wpvivid_monitor_download_restore_task(restore_type);
1606
- }, 3000);
1607
- }
1608
- }
1609
- }
1610
- else
1611
- {
1612
- setTimeout(function()
1613
- {
1614
- wpvivid_monitor_download_restore_task(restore_type);
1615
- }, 3000);
1616
- }
1617
- }
1618
- catch(err){
1619
- setTimeout(function()
1620
- {
1621
- wpvivid_monitor_download_restore_task(restore_type);
1622
- }, 3000);
1623
- }
1624
- }, function(XMLHttpRequest, textStatus, errorThrown)
1625
- {
1626
- setTimeout(function()
1627
- {
1628
- wpvivid_monitor_download_restore_task(restore_type);
1629
- }, 1000);
1630
- });
1631
- }
1632
-
1633
- /**
1634
- * Monitor restore task.
1635
- */
1636
- function wpvivid_monitor_restore_task(restore_type){
1637
- var restore_method = '';
1638
- if(restore_type == 'backup'){
1639
- restore_method = '';
1640
- }
1641
- else if(restore_type == 'transfer'){
1642
- restore_method = 'transfer_';
1643
- }
1644
-
1645
- var ajax_data={
1646
- 'action':'wpvivid_get_restore_progress',
1647
- 'wpvivid_restore' : '1',
1648
- };
1649
-
1650
- if(wpvivid_restore_timeout){
1651
- jQuery('#wpvivid_restore_'+restore_method+'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1652
- jQuery('#wpvivid_clean_'+restore_method+'restore').css({'pointer-events': 'none', 'opacity': '0.4'});
1653
- jQuery('#wpvivid_rollback_'+restore_method+'btn').css({'pointer-events': 'none', 'opacity': '0.4'});
1654
- jQuery('#wpvivid_restore_'+restore_method+'part').show();
1655
- jQuery('#wpvivid_clean_'+restore_method+'part').hide();
1656
- jQuery('#wpvivid_rollback_'+restore_method+'part').hide();
1657
- wpvivid_restore_unlock();
1658
- wpvivid_restoring = false;
1659
- wpvivid_display_restore_msg("Website restore times out.", restore_type);
1660
- }
1661
- else {
1662
- wpvivid_post_request(ajax_data, function (data) {
1663
- try {
1664
- var jsonarray = jQuery.parseJSON(data);
1665
- if (typeof jsonarray === 'object') {
1666
- if (jsonarray.result === "success") {
1667
- jQuery('#wpvivid_restore_' + restore_method + 'log').html("");
1668
- while (jsonarray.log.indexOf('\n') >= 0) {
1669
- var iLength = jsonarray.log.indexOf('\n');
1670
- var log = jsonarray.log.substring(0, iLength);
1671
- jsonarray.log = jsonarray.log.substring(iLength + 1);
1672
- var insert_log = "<div style=\"clear:both;\">" + log + "</div>";
1673
- jQuery('#wpvivid_restore_' + restore_method + 'log').append(insert_log);
1674
- var div = jQuery('#wpvivid_restore_' + restore_method + 'log');
1675
- div[0].scrollTop = div[0].scrollHeight;
1676
- }
1677
-
1678
- if (jsonarray.status === 'wait') {
1679
- wpvivid_restoring = true;
1680
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({
1681
- 'pointer-events': 'none',
1682
- 'opacity': '0.4'
1683
- });
1684
- jQuery('#wpvivid_clean_' + restore_method + 'restore').css({
1685
- 'pointer-events': 'none',
1686
- 'opacity': '0.4'
1687
- });
1688
- jQuery('#wpvivid_rollback_' + restore_method + 'btn').css({
1689
- 'pointer-events': 'none',
1690
- 'opacity': '0.4'
1691
- });
1692
- jQuery('#wpvivid_restore_' + restore_method + 'part').show();
1693
- jQuery('#wpvivid_clean_' + restore_method + 'part').hide();
1694
- jQuery('#wpvivid_rollback_' + restore_method + 'part').hide();
1695
- wpvivid_restore(restore_type);
1696
- setTimeout(function () {
1697
- wpvivid_monitor_restore_task(restore_type);
1698
- }, 1000);
1699
- }
1700
- else if (jsonarray.status === 'completed') {
1701
- wpvivid_restoring = false;
1702
- wpvivid_restore(restore_type);
1703
- wpvivid_restore_unlock();
1704
- alert("Restore completed successfully.");
1705
- location.reload();
1706
- }
1707
- else if (jsonarray.status === 'error') {
1708
- wpvivid_restore_unlock();
1709
- wpvivid_restoring = false;
1710
- jQuery('#wpvivid_restore_' + restore_method + 'btn').css({'pointer-events': 'auto', 'opacity': '1'});
1711
- alert("Restore failed.");
1712
- }
1713
- else {
1714
- setTimeout(function () {
1715
- wpvivid_monitor_restore_task(restore_type);
1716
- }, 1000);
1717
- }
1718
- }
1719
- else {
1720
- setTimeout(function () {
1721
- wpvivid_monitor_restore_task(restore_type);
1722
- }, 1000);
1723
- }
1724
- }
1725
- else {
1726
- setTimeout(function () {
1727
- wpvivid_monitor_restore_task(restore_type);
1728
- }, 1000);
1729
- }
1730
- }
1731
- catch (err) {
1732
- setTimeout(function () {
1733
- wpvivid_monitor_restore_task(restore_type);
1734
- }, 1000);
1735
- }
1736
- }, function (XMLHttpRequest, textStatus, errorThrown) {
1737
- setTimeout(function () {
1738
- wpvivid_monitor_restore_task(restore_type);
1739
- }, 1000);
1740
- });
1741
- }
1742
- }
1743
-
1744
- function wpvivid_restore(restore_type){
1745
- var restore_method = '';
1746
- if(restore_type == 'backup'){
1747
- restore_method = '';
1748
- }
1749
- else if(restore_type == 'transfer'){
1750
- restore_method = 'transfer_';
1751
- }
1752
-
1753
- var skip_old_site = '1';
1754
- var extend_option = {
1755
- 'skip_backup_old_site':skip_old_site,
1756
- 'skip_backup_old_database':skip_old_site
1757
- };
1758
-
1759
- var migrate_option = {
1760
- 'is_migrate':wpvivid_resotre_is_migrate,
1761
- };
1762
- jQuery.extend(extend_option, migrate_option);
1763
-
1764
- var restore_options = {
1765
- 0:'backup_db',
1766
- 1:'backup_themes',
1767
- 2:'backup_plugin',
1768
- 3:'backup_uploads',
1769
- 4:'backup_content',
1770
- 5:'backup_core'
1771
- };
1772
- jQuery.extend(restore_options, extend_option);
1773
- var json = JSON.stringify(restore_options);
1774
- var ajax_data={
1775
- 'action':'wpvivid_restore',
1776
- 'wpvivid_restore':'1',
1777
- 'backup_id':m_restore_backup_id,
1778
- 'restore_options':json
1779
- };
1780
- setTimeout(function () {
1781
- wpvivid_restore_timeout = true;
1782
- }, restore_max_exection_time);
1783
- wpvivid_post_request(ajax_data, function(data) {
1784
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1785
- });
1786
- }
1787
-
1788
- function wpvivid_display_restore_msg(msg, restore_type, div_id, append = true){
1789
- var restore_method = '';
1790
- if(restore_type == 'backup'){
1791
- restore_method = '';
1792
- }
1793
- else if(restore_type == 'transfer'){
1794
- restore_method = 'transfer_';
1795
- }
1796
-
1797
- if(typeof div_id == 'undefined') {
1798
- var restore_msg = "<div style=\"clear:both;\">" + msg + "</div>";
1799
- }
1800
- else{
1801
- var restore_msg = "<div id=\"restore_file_"+div_id+"\" style=\"clear:both;\">" + msg + "</div>";
1802
- }
1803
- if(append == true) {
1804
- jQuery('#wpvivid_restore_'+restore_method+'log').append(restore_msg);
1805
- }
1806
- else{
1807
- if(jQuery('#restore_file_'+div_id).length )
1808
- {
1809
- jQuery('#restore_file_'+div_id).html(msg);
1810
- }
1811
- else
1812
- {
1813
- jQuery('#wpvivid_restore_'+restore_method+'log').append(restore_msg);
1814
- }
1815
- }
1816
- var div = jQuery('#wpvivid_restore_' + restore_method + 'log');
1817
- div[0].scrollTop = div[0].scrollHeight;
1818
- }
1819
-
1820
- /**
1821
- * Lock certain operations while a restore task is running.
1822
- */
1823
- function wpvivid_restore_lock(){
1824
- jQuery('#wpvivid_postbox_backup_percent').css({'pointer-events': 'none', 'opacity': '1'});
1825
- jQuery('#wpvivid_postbox_backup').css({'pointer-events': 'none', 'opacity': '1'});
1826
- jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'none', 'opacity': '1'});
1827
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '1'});
1828
- jQuery('#wpvivid_tab_backup').css({'pointer-events': 'none', 'opacity': '1'});
1829
- jQuery('#wpvivid_tab_upload').css({'pointer-events': 'none', 'opacity': '1'});
1830
- jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'none', 'opacity': '1'});
1831
- jQuery('#wpvivid_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
1832
- jQuery('#page-backups').css({'pointer-events': 'none', 'opacity': '1'});
1833
- jQuery('#storage-page').css({'pointer-events': 'none', 'opacity': '1'});
1834
- jQuery('#settings-page').css({'pointer-events': 'none', 'opacity': '1'});
1835
- jQuery('#debug-page').css({'pointer-events': 'none', 'opacity': '1'});
1836
- jQuery('#logs-page').css({'pointer-events': 'none', 'opacity': '1'});
1837
- jQuery('#wpvivid_tab_migrate').css({'pointer-events': 'none', 'opacity': '1'});
1838
- jQuery('#wpvivid_add_tab_migrate').css({'pointer-events': 'none', 'opacity': '1'});
1839
- jQuery('#wpvivid_add_tab_import').css({'pointer-events': 'none', 'opacity': '1'});
1840
- jQuery('#wpvivid_add_tab_key').css({'pointer-events': 'none', 'opacity': '1'});
1841
- jQuery('#wpvivid_add_tab_log').css({'pointer-events': 'none', 'opacity': '1'});
1842
- jQuery('#wpvivid_add_tab_restore').css({'pointer-events': 'none', 'opacity': '1'});
1843
- jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'none', 'opacity': '1'});
1844
- jQuery('#wpvivid_replace_domain').css({'pointer-events': 'none', 'opacity': '1'});
1845
- jQuery('#wpvivid_keep_domain').css({'pointer-events': 'none', 'opacity': '1'});
1846
- }
1847
-
1848
- /**
1849
- * Unlock the operations once restore task completed.
1850
- */
1851
- function wpvivid_restore_unlock(){
1852
- jQuery('#wpvivid_postbox_backup_percent').css({'pointer-events': 'auto', 'opacity': '1'});
1853
- jQuery('#wpvivid_postbox_backup').css({'pointer-events': 'auto', 'opacity': '1'});
1854
- jQuery('#wpvivid_postbox_backup_schedule').css({'pointer-events': 'auto', 'opacity': '1'});
1855
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
1856
- jQuery('#wpvivid_tab_backup').css({'pointer-events': 'auto', 'opacity': '1'});
1857
- jQuery('#wpvivid_tab_upload').css({'pointer-events': 'auto', 'opacity': '1'});
1858
- jQuery('#wpvivid_tab_backup_log').css({'pointer-events': 'auto', 'opacity': '1'});
1859
- jQuery('#wpvivid_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
1860
- jQuery('#page-backups').css({'pointer-events': 'auto', 'opacity': '1'});
1861
- jQuery('#storage-page').css({'pointer-events': 'auto', 'opacity': '1'});
1862
- jQuery('#settings-page').css({'pointer-events': 'auto', 'opacity': '1'});
1863
- jQuery('#debug-page').css({'pointer-events': 'auto', 'opacity': '1'});
1864
- jQuery('#logs-page').css({'pointer-events': 'auto', 'opacity': '1'});
1865
- jQuery('#wpvivid_tab_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
1866
- jQuery('#wpvivid_add_tab_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
1867
- jQuery('#wpvivid_add_tab_import').css({'pointer-events': 'auto', 'opacity': '1'});
1868
- jQuery('#wpvivid_add_tab_key').css({'pointer-events': 'auto', 'opacity': '1'});
1869
- jQuery('#wpvivid_add_tab_log').css({'pointer-events': 'auto', 'opacity': '1'});
1870
- jQuery('#wpvivid_add_tab_restore').css({'pointer-events': 'auto', 'opacity': '1'});
1871
- jQuery('#wpvivid_restore_is_migrate').css({'pointer-events': 'auto', 'opacity': '1'});
1872
- jQuery('#wpvivid_replace_domain').css({'pointer-events': 'auto', 'opacity': '1'});
1873
- jQuery('#wpvivid_keep_domain').css({'pointer-events': 'auto', 'opacity': '1'});
1874
- }
1875
- </script>
1876
- <?php
1877
- }
1878
-
1879
- function wpvivid_backuppage_add_page_downlaod(){
1880
- ?>
1881
- <div class="backup-tab-content wpvivid_tab_download" id="page-download" style="padding-top: 1em; display:none;">
1882
- <div id="wpvivid_init_download_info">
1883
- <div style="float: left; height: 20px; line-height: 20px; margin-top: 4px;">Initializing the download info</div>
1884
- <div class="spinner" style="float: left;"></div>
1885
- <div style="clear: both;"></div>
1886
- </div>
1887
- <div class="wpvivid-element-space-bottom" id="wpvivid_files_list">
1888
- </div>
1889
- </div>
1890
-
1891
- <script>
1892
- var wpvivid_download_files_list = wpvivid_download_files_list || {};
1893
- wpvivid_download_files_list.backup_id='';
1894
- wpvivid_download_files_list.wpvivid_download_file_array = Array();
1895
- wpvivid_download_files_list.wpvivid_download_lock_array = Array();
1896
- wpvivid_download_files_list.init=function(backup_id) {
1897
- wpvivid_download_files_list.backup_id=backup_id;
1898
- wpvivid_download_files_list.wpvivid_download_file_array.splice(0, wpvivid_download_files_list.wpvivid_download_file_array.length);
1899
- };
1900
-
1901
- wpvivid_download_files_list.add_download_queue=function(filename) {
1902
- var download_file_size = jQuery("[slug='"+filename+"']").find('.wpvivid-download-status').find('.wpvivid-download-file-size').html();
1903
- var tmp_html = '<div class="wpvivid-element-space-bottom">' +
1904
- '<span class="wpvivid-element-space-right">Retriving (remote storage to web server)</span><span class="wpvivid-element-space-right">|</span><span>File Size: </span><span class="wpvivid-element-space-right">'+download_file_size+'</span><span class="wpvivid-element-space-right">|</span><span>Downloaded Size: </span><span>0</span>' +
1905
- '</div>' +
1906
- '<div style="width:100%;height:10px; background-color:#dcdcdc;">' +
1907
- '<div style="background-color:#0085ba; float:left;width:0%;height:10px;"></div>' +
1908
- '</div>';
1909
- jQuery("[slug='"+filename+"']").find('.wpvivid-download-status').html(tmp_html);
1910
- if(jQuery.inArray(filename, wpvivid_download_files_list.wpvivid_download_file_array) === -1) {
1911
- wpvivid_download_files_list.wpvivid_download_file_array.push(filename);
1912
- }
1913
- var ajax_data = {
1914
- 'action': 'wpvivid_prepare_download_backup',
1915
- 'backup_id':wpvivid_download_files_list.backup_id,
1916
- 'file_name':filename
1917
- };
1918
- wpvivid_post_request(ajax_data, function(data)
1919
- {
1920
- }, function(XMLHttpRequest, textStatus, errorThrown)
1921
- {
1922
- }, 0);
1923
-
1924
- wpvivid_download_files_list.check_queue();
1925
- };
1926
-
1927
- wpvivid_download_files_list.check_queue=function() {
1928
- if(jQuery.inArray(wpvivid_download_files_list.backup_id, wpvivid_download_files_list.wpvivid_download_lock_array) !== -1){
1929
- return;
1930
- }
1931
- var ajax_data = {
1932
- 'action': 'wpvivid_get_download_progress',
1933
- 'backup_id':wpvivid_download_files_list.backup_id,
1934
- };
1935
- wpvivid_download_files_list.wpvivid_download_lock_array.push(wpvivid_download_files_list.backup_id);
1936
- wpvivid_post_request(ajax_data, function(data)
1937
- {
1938
- wpvivid_download_files_list.wpvivid_download_lock_array.splice(jQuery.inArray(wpvivid_download_files_list.backup_id, wpvivid_download_files_list.wpvivid_download_file_array),1);
1939
- var jsonarray = jQuery.parseJSON(data);
1940
- if (jsonarray.result === 'success')
1941
- {
1942
- jQuery.each(jsonarray.files,function (index, value)
1943
- {
1944
- if(jQuery.inArray(index, wpvivid_download_files_list.wpvivid_download_file_array) !== -1) {
1945
- if(value.status === 'timeout' || value.status === 'completed' || value.status === 'error'){
1946
- wpvivid_download_files_list.wpvivid_download_file_array.splice(jQuery.inArray(index, wpvivid_download_files_list.wpvivid_download_file_array),1);
1947
- }
1948
- wpvivid_download_files_list.update_item(index, value);
1949
- }
1950
- });
1951
-
1952
- //if(jsonarray.need_update)
1953
- if(wpvivid_download_files_list.wpvivid_download_file_array.length > 0)
1954
- {
1955
- setTimeout(function()
1956
- {
1957
- wpvivid_download_files_list.check_queue();
1958
- }, 3000);
1959
- }
1960
- }
1961
- }, function(XMLHttpRequest, textStatus, errorThrown)
1962
- {
1963
- wpvivid_download_files_list.wpvivid_download_lock_array.splice(jQuery.inArray(wpvivid_download_files_list.backup_id, wpvivid_download_files_list.wpvivid_download_file_array),1);
1964
- setTimeout(function()
1965
- {
1966
- wpvivid_download_files_list.check_queue();
1967
- }, 3000);
1968
- }, 0);
1969
- };
1970
-
1971
- wpvivid_download_files_list.update_item=function(index,file) {
1972
- jQuery("[slug='"+index+"']").find('.wpvivid-download-status').html(file.html);
1973
- };
1974
-
1975
- wpvivid_download_files_list.download_now=function(filename) {
1976
- wpvivid_location_href=true;
1977
- location.href =ajaxurl+'?_wpnonce='+wpvivid_ajax_object.ajax_nonce+'&action=wpvivid_download_backup&backup_id='+wpvivid_download_files_list.backup_id+'&file_name='+filename;
1978
- };
1979
-
1980
- function wpvivid_initialize_download(backup_id, list_name){
1981
- jQuery('#wpvivid_tab_download').show();
1982
- wpvivid_click_switch_page('backup', 'wpvivid_tab_download', true);
1983
- wpvivid_init_download_page(backup_id);
1984
-
1985
-
1986
- /*wpvivid_reset_backup_list(list_name);
1987
- jQuery('#wpvivid_download_loading_'+backup_id).addClass('is-active');
1988
- tmp_current_click_backupid = backup_id;
1989
- var ajax_data = {
1990
- 'action':'wpvivid_init_download_page',
1991
- 'backup_id':backup_id
1992
- };
1993
- wpvivid_post_request(ajax_data, function(data){
1994
- try {
1995
- var jsonarray = jQuery.parseJSON(data);
1996
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
1997
- if (jsonarray.result === 'success') {
1998
- jQuery('#wpvivid_file_part_' + backup_id).html("");
1999
- var i = 0;
2000
- var file_not_found = false;
2001
- var file_name = '';
2002
- jQuery.each(jsonarray.files, function (index, value) {
2003
- i++;
2004
- file_name = index;
2005
- if (value.status === 'need_download') {
2006
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
2007
- //tmp_current_click_backupid = '';
2008
- }
2009
- else if (value.status === 'running') {
2010
- if (m_downloading_file_name === file_name) {
2011
- wpvivid_lock_download(tmp_current_click_backupid);
2012
- }
2013
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
2014
- }
2015
- else if (value.status === 'completed') {
2016
- if (m_downloading_file_name === file_name) {
2017
- wpvivid_unlock_download(tmp_current_click_backupid);
2018
- m_downloading_id = '';
2019
- m_downloading_file_name = '';
2020
- }
2021
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
2022
- //tmp_current_click_backupid = '';
2023
- }
2024
- else if (value.status === 'timeout') {
2025
- if (m_downloading_file_name === file_name) {
2026
- wpvivid_unlock_download(tmp_current_click_backupid);
2027
- m_downloading_id = '';
2028
- m_downloading_file_name = '';
2029
- }
2030
- jQuery('#wpvivid_file_part_' + backup_id).append(value.html);
2031
- //tmp_current_click_backupid = '';
2032
- }
2033
- else if (value.status === 'file_not_found') {
2034
- wpvivid_unlock_download(tmp_current_click_backupid);
2035
- wpvivid_reset_backup_list(list_name);
2036
- file_not_found = true;
2037
- alert("Download failed, file not found. The file might has been moved, renamed or deleted. Please verify the file exists and try again.");
2038
- //tmp_current_click_backupid = '';
2039
- return false;
2040
- }
2041
- });
2042
- if (file_not_found === false) {
2043
- jQuery('#wpvivid_file_part_' + backup_id).append(jsonarray.place_html);
2044
- }
2045
- }
2046
- }
2047
- catch(err){
2048
- alert(err);
2049
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
2050
- }
2051
- },function(XMLHttpRequest, textStatus, errorThrown){
2052
- jQuery('#wpvivid_download_loading_'+backup_id).removeClass('is-active');
2053
- var error_message = wpvivid_output_ajaxerror('initializing download information', textStatus, errorThrown);
2054
- alert(error_message);
2055
- });*/
2056
- }
2057
-
2058
- function wpvivid_init_download_page(backup_id){
2059
- jQuery('#wpvivid_files_list').html('');
2060
- jQuery('#wpvivid_init_download_info').show();
2061
- jQuery('#wpvivid_init_download_info').find('.spinner').addClass('is-active');
2062
- var ajax_data = {
2063
- 'action':'wpvivid_init_download_page',
2064
- 'backup_id':backup_id
2065
- };
2066
- var retry = '<input type="button" class="button button-primary" value="Retry the initialization" onclick="wpvivid_init_download_page(\''+backup_id+'\');" />';
2067
-
2068
- wpvivid_post_request(ajax_data, function(data)
2069
- {
2070
- jQuery('#wpvivid_init_download_info').hide();
2071
- jQuery('#wpvivid_init_download_info').find('.spinner').removeClass('is-active');
2072
- try
2073
- {
2074
- var jsonarray = jQuery.parseJSON(data);
2075
- if (jsonarray.result === 'success')
2076
- {
2077
- wpvivid_download_files_list.init(backup_id);
2078
- var need_check_queue = false;
2079
- jQuery.each(jsonarray.files,function (index, value)
2080
- {
2081
- if(value.status === 'running'){
2082
- if(jQuery.inArray(index, wpvivid_download_files_list.wpvivid_download_file_array) === -1) {
2083
- wpvivid_download_files_list.wpvivid_download_file_array.push(index);
2084
- need_check_queue = true;
2085
- }
2086
- }
2087
- });
2088
- if(need_check_queue) {
2089
- wpvivid_download_files_list.check_queue();
2090
- }
2091
- jQuery('#wpvivid_files_list').html(jsonarray.html);
2092
- }
2093
- else{
2094
- alert(jsonarray.error);
2095
- jQuery('#wpvivid_files_list').html(retry);
2096
- }
2097
- }
2098
- catch(err)
2099
- {
2100
- alert(err);
2101
- jQuery('#wpvivid_files_list').html(retry);
2102
- }
2103
- },function(XMLHttpRequest, textStatus, errorThrown)
2104
- {
2105
- jQuery('#wpvivid_init_download_info').hide();
2106
- jQuery('#wpvivid_init_download_info').find('.spinner').removeClass('is-active');
2107
- var error_message = wpvivid_output_ajaxerror('initializing download information', textStatus, errorThrown);
2108
- alert(error_message);
2109
- jQuery('#wpvivid_files_list').html(retry);
2110
- });
2111
- }
2112
-
2113
- function wpvivid_download_change_page(page)
2114
- {
2115
- var backup_id=wpvivid_download_files_list.backup_id;
2116
-
2117
- var ajax_data = {
2118
- 'action':'wpvivid_get_download_page_ex',
2119
- 'backup_id':backup_id,
2120
- 'page':page
2121
- };
2122
-
2123
- jQuery('#wpvivid_files_list').html('');
2124
- jQuery('#wpvivid_init_download_info').show();
2125
- jQuery('#wpvivid_init_download_info').find('.spinner').addClass('is-active');
2126
-
2127
- wpvivid_post_request(ajax_data, function(data)
2128
- {
2129
- jQuery('#wpvivid_init_download_info').hide();
2130
- jQuery('#wpvivid_init_download_info').find('.spinner').removeClass('is-active');
2131
- try
2132
- {
2133
- var jsonarray = jQuery.parseJSON(data);
2134
- if (jsonarray.result === 'success')
2135
- {
2136
- jQuery('#wpvivid_files_list').html(jsonarray.html);
2137
- }
2138
- else{
2139
- alert(jsonarray.error);
2140
- }
2141
- }
2142
- catch(err)
2143
- {
2144
- alert(err);
2145
- }
2146
- },function(XMLHttpRequest, textStatus, errorThrown)
2147
- {
2148
- jQuery('#wpvivid_init_download_info').hide();
2149
- jQuery('#wpvivid_init_download_info').find('.spinner').removeClass('is-active');
2150
- var error_message = wpvivid_output_ajaxerror('initializing download information', textStatus, errorThrown);
2151
- alert(error_message);
2152
- });
2153
- }
2154
-
2155
- jQuery('#wpvivid_files_list').on("click",'.wpvivid-download',function()
2156
- {
2157
- var Obj=jQuery(this);
2158
- var file_name=Obj.closest('tr').attr('slug');
2159
- wpvivid_download_files_list.add_download_queue(file_name);
2160
- });
2161
- jQuery('#wpvivid_files_list').on("click",'.wpvivid-ready-download',function()
2162
- {
2163
- var Obj=jQuery(this);
2164
- var file_name=Obj.closest('tr').attr('slug');
2165
- wpvivid_download_files_list.download_now(file_name);
2166
- });
2167
-
2168
- jQuery('#wpvivid_files_list').on("click",'.first-page',function() {
2169
- wpvivid_download_change_page('first');
2170
- });
2171
-
2172
- jQuery('#wpvivid_files_list').on("click",'.prev-page',function() {
2173
- var page=parseInt(jQuery(this).attr('value'));
2174
- wpvivid_download_change_page(page-1);
2175
- });
2176
-
2177
- jQuery('#wpvivid_files_list').on("click",'.next-page',function() {
2178
- var page=parseInt(jQuery(this).attr('value'));
2179
- wpvivid_download_change_page(page+1);
2180
- });
2181
-
2182
- jQuery('#wpvivid_files_list').on("click",'.last-page',function() {
2183
- wpvivid_download_change_page('last');
2184
- });
2185
-
2186
- jQuery('#wpvivid_files_list').on("keypress", '.current-page', function(){
2187
- if(event.keyCode === 13){
2188
- var page = jQuery(this).val();
2189
- wpvivid_download_change_page(page);
2190
- }
2191
- });
2192
- </script>
2193
- <?php
2194
- }
2195
-
2196
- function wpvivid_backuppage_add_progress_module(){
2197
- ?>
2198
- <div class="postbox" id="wpvivid_postbox_backup_percent" style="display: none;">
2199
- <div class="action-progress-bar" id="wpvivid_action_progress_bar">
2200
- <div class="action-progress-bar-percent" id="wpvivid_action_progress_bar_percent" style="height:24px;width:0;"></div>
2201
- </div>
2202
- <div id="wpvivid_estimate_backup_info" style="float: left;">
2203
- <div class="backup-basic-info"><span class="wpvivid-element-space-right"><?php _e('Database Size:', 'wpvivid-backuprestore'); ?></span><span id="wpvivid_backup_database_size">N/A</span></div>
2204
- <div class="backup-basic-info"><span class="wpvivid-element-space-right"><?php _e('File Size:', 'wpvivid-backuprestore'); ?></span><span id="wpvivid_backup_file_size">N/A</span></div>
2205
- </div>
2206
- <div id="wpvivid_estimate_upload_info" style="float: left;">
2207
- <div class="backup-basic-info"><span class="wpvivid-element-space-right"><?php _e('Total Size:', 'wpvivid-backuprestore'); ?></span><span>N/A</span></div>
2208
- <div class="backup-basic-info"><span class="wpvivid-element-space-right"><?php _e('Uploaded:', 'wpvivid-backuprestore'); ?></span><span>N/A</span></div>
2209
- <div class="backup-basic-info"><span class="wpvivid-element-space-right"><?php _e('Speed:', 'wpvivid-backuprestore'); ?></span><span>N/A</span></div>
2210
- </div>
2211
- <div style="float: left;">
2212
- <div class="backup-basic-info"><span class="wpvivid-element-space-right"><?php _e('Network Connection:', 'wpvivid-backuprestore'); ?></span><span>N/A</span></div>
2213
- </div>
2214
- <div style="clear:both;"></div>
2215
- <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_current_doing"></p></div>
2216
- <div style="clear: both;"></div>
2217
- <div>
2218
- <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-backuprestore' ); ?>" /></div>
2219
- <div id="wpvivid_backup_log" class="backup-log-btn"><input class="button-primary" id="wpvivid_backup_log_btn" type="submit" value="<?php esc_attr_e( 'Log', 'wpvivid-backuprestore' ); ?>" /></div>
2220
- </div>
2221
- <div style="clear: both;"></div>
2222
- </div>
2223
- <script>
2224
- jQuery('#wpvivid_postbox_backup_percent').on("click", "input", function(){
2225
- if(jQuery(this).attr('id') === 'wpvivid_backup_cancel_btn'){
2226
- wpvivid_cancel_backup();
2227
- }
2228
- if(jQuery(this).attr('id') === 'wpvivid_backup_log_btn'){
2229
- wpvivid_read_log('wpvivid_view_backup_task_log');
2230
- }
2231
- });
2232
-
2233
- function wpvivid_cancel_backup(){
2234
- var ajax_data= {
2235
- 'action': 'wpvivid_backup_cancel'
2236
- //'task_id': running_backup_taskid
2237
- };
2238
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2239
- wpvivid_post_request(ajax_data, function(data){
2240
- try {
2241
- var jsonarray = jQuery.parseJSON(data);
2242
- jQuery('#wpvivid_current_doing').html(jsonarray.msg);
2243
- }
2244
- catch(err){
2245
- alert(err);
2246
- }
2247
- }, function(XMLHttpRequest, textStatus, errorThrown) {
2248
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2249
- var error_message = wpvivid_output_ajaxerror('cancelling the backup', textStatus, errorThrown);
2250
- wpvivid_add_notice('Backup', 'Error', error_message);
2251
- });
2252
- }
2253
- </script>
2254
- <?php
2255
- }
2256
-
2257
- function wpvivid_backuppage_add_backup_module(){
2258
- ?>
2259
- <div class="postbox quickbackup" id="wpvivid_postbox_backup">
2260
- <?php
2261
- do_action('wpvivid_backup_module_add_sub');
2262
- ?>
2263
- </div>
2264
- <?php
2265
- }
2266
-
2267
- function wpvivid_backup_module_add_descript(){
2268
- $backupdir=WPvivid_Setting::get_backupdir();
2269
- ?>
2270
- <div style="font-size: 14px; padding: 8px 12px; margin: 0; line-height: 1.4; font-weight: 600;">
2271
- <span style="margin-right: 5px;"><?php _e( 'Back Up Manually','wpvivid-backuprestore'); ?></span>
2272
- <span style="margin-right: 5px;">|</span>
2273
- <span style="margin-right: 0;"><a href="<?php echo esc_url('https://wordpress.org/plugins/wpvivid-imgoptim/'); ?>" style="text-decoration: none;"><?php _e('Compress images with our image optimization plugin, it\'s free', 'wpvivid-backuprestore'); ?></a></span>
2274
- </div>
2275
- <div class="quickstart-storage-setting">
2276
- <span class="list-top-chip backup" name="ismerge" value="1" style="margin: 10px 10px 10px 0;"><?php _e('Local Storage Directory:', 'wpvivid-backuprestore'); ?></span>
2277
- <span class="list-top-chip" id="wpvivid_local_storage_path" style="margin: 10px 10px 10px 0;"><?php _e(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backupdir); ?></span>
2278
- <span class="list-top-chip" style="margin: 10px 10px 10px 0;"><a href="#" onclick="wpvivid_click_switch_page('wrap', 'wpvivid_tab_setting', true);" style="text-decoration: none;"><?php _e('rename directory', 'wpvivid-backuprestore'); ?></a></span>
2279
- </div>
2280
- <?php
2281
- }
2282
-
2283
- function wpvivid_backup_module_add_backup_type(){
2284
- $backup_type = '';
2285
- $type_name = 'backup_files';
2286
- ?>
2287
- <div class="quickstart-archive-block">
2288
- <fieldset>
2289
- <legend class="screen-reader-text"><span>input type="radio"</span></legend>
2290
- <?php echo apply_filters('wpvivid_add_backup_type', $backup_type, $type_name); ?>
2291
- <label style="display: none;">
2292
- <input type="checkbox" option="backup" name="ismerge" value="1" checked />
2293
- </label><br>
2294
- </fieldset>
2295
- </div>
2296
- <?php
2297
- }
2298
-
2299
- function wpvivid_backup_module_add_send_remote(){
2300
- $pic='';
2301
- ?>
2302
- <div class="quickstart-storage-block">
2303
- <fieldset>
2304
- <legend class="screen-reader-text"><span>input type="checkbox"</span></legend>
2305
- <label>
2306
- <input type="radio" id="wpvivid_backup_local" option="backup_ex" name="local_remote" value="local" checked />
2307
- <span><?php _e( 'Save Backups to Local', 'wpvivid-backuprestore' ); ?></span>
2308
- </label><br>
2309
- <label>
2310
- <input type="radio" id="wpvivid_backup_remote" option="backup_ex" name="local_remote" value="remote" />
2311
- <span><?php _e( 'Send Backup to Remote Storage:', 'wpvivid-backuprestore' ); ?></span>
2312
- </label><br>
2313
- <div id="upload_storage" style="cursor:pointer;" title="Highlighted icon illuminates that you have choosed a remote storage to store backups">
2314
- <?php echo apply_filters('wpvivid_schedule_add_remote_pic',$pic); ?>
2315
- </div>
2316
- </fieldset>
2317
- </div>
2318
- <?php
2319
- }
2320
-
2321
- function wpvivid_backup_module_add_exec(){
2322
- ?>
2323
- <div class="quickstart-btn" style="padding-top:20px;">
2324
- <input class="button-primary quickbackup-btn" id="wpvivid_quickbackup_btn" type="submit" value="<?php esc_attr_e( 'Backup Now', 'wpvivid-backuprestore'); ?>" />
2325
- <div class="schedule-tab-block" style="text-align:center;">
2326
- <fieldset>
2327
- <label>
2328
- <input type="checkbox" id="wpvivid_backup_lock" option="backup" name="lock" />
2329
- <span><?php _e( 'This backup can only be deleted manually', 'wpvivid-backuprestore' ); ?></span>
2330
- </label>
2331
- </fieldset>
2332
- </div>
2333
- </div>
2334
- <script>
2335
- jQuery('#wpvivid_quickbackup_btn').click(function(){
2336
- wpvivid_clear_notice('wpvivid_backup_notice');
2337
- wpvivid_start_backup();
2338
- });
2339
-
2340
- function wpvivid_start_backup(){
2341
- var bcheck=true;
2342
- var bdownloading=false;
2343
- if(m_downloading_id !== '') {
2344
- var descript = 'This request might delete the backup being downloaded, are you sure you want to continue?';
2345
- var ret = confirm(descript);
2346
- if (ret === true) {
2347
- bcheck=true;
2348
- bdownloading=true;
2349
- }
2350
- else{
2351
- bcheck=false;
2352
- }
2353
- }
2354
- if(bcheck) {
2355
- var backup_data = wpvivid_ajax_data_transfer('backup');
2356
- backup_data = JSON.parse(backup_data);
2357
- jQuery('input:radio[option=backup_ex]').each(function() {
2358
- if(jQuery(this).prop('checked'))
2359
- {
2360
- var key = jQuery(this).prop('name');
2361
- var value = jQuery(this).prop('value');
2362
- var json = new Array();
2363
- if(value == 'local'){
2364
- json['local']='1';
2365
- json['remote']='0';
2366
- }
2367
- else if(value == 'remote'){
2368
- json['local']='0';
2369
- json['remote']='1';
2370
- }
2371
- }
2372
- jQuery.extend(backup_data, json);
2373
- });
2374
- backup_data = JSON.stringify(backup_data);
2375
- var ajax_data = {
2376
- 'action': 'wpvivid_prepare_backup',
2377
- 'backup': backup_data
2378
- };
2379
- wpvivid_control_backup_lock();
2380
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2381
- jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2382
- jQuery('#wpvivid_postbox_backup_percent').show();
2383
- jQuery('#wpvivid_current_doing').html('Ready to backup. Progress: 0%, running time: 0second.');
2384
- var percent = '0%';
2385
- jQuery('#wpvivid_action_progress_bar_percent').css('width', percent);
2386
- jQuery('#wpvivid_backup_database_size').html('N/A');
2387
- jQuery('#wpvivid_backup_file_size').html('N/A');
2388
- jQuery('#wpvivid_current_doing').html('');
2389
- wpvivid_completed_backup = 1;
2390
- wpvivid_prepare_backup = true;
2391
- wpvivid_post_request(ajax_data, function (data) {
2392
- try {
2393
- var jsonarray = jQuery.parseJSON(data);
2394
- if (jsonarray.result === 'failed') {
2395
- wpvivid_delete_ready_task(jsonarray.error);
2396
- }
2397
- else if (jsonarray.result === 'success') {
2398
- if(bdownloading) {
2399
- m_downloading_id = '';
2400
- }
2401
- m_backup_task_id = jsonarray.task_id;
2402
- var descript = '';
2403
- if (jsonarray.check.alert_db === true || jsonarray.check.alter_files === true) {
2404
- 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' +
2405
- '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' +
2406
- 'Click OK button and continue to back up.';
2407
- var ret = confirm(descript);
2408
- if (ret === true) {
2409
- jQuery('#wpvivid_backup_list').html('');
2410
- jQuery('#wpvivid_backup_list').append(jsonarray.html);
2411
- wpvivid_backup_now(m_backup_task_id);
2412
- }
2413
- else {
2414
- jQuery('#wpvivid_backup_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2415
- jQuery('#wpvivid_backup_log_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2416
- wpvivid_control_backup_unlock();
2417
- jQuery('#wpvivid_postbox_backup_percent').hide();
2418
- }
2419
- }
2420
- else{
2421
- jQuery('#wpvivid_backup_list').html('');
2422
- jQuery('#wpvivid_backup_list').append(jsonarray.html);
2423
- wpvivid_backup_now(jsonarray.task_id);
2424
- }
2425
- }
2426
- }
2427
- catch (err) {
2428
- wpvivid_delete_ready_task(err);
2429
- }
2430
- }, function (XMLHttpRequest, textStatus, errorThrown) {
2431
- //var error_message = wpvivid_output_ajaxerror('preparing the backup', textStatus, errorThrown);
2432
- var error_message=wpvividlion.backup_calc_timeout;//'Calculating the size of files, folder and database timed out. If you continue to receive this error, please go to the plugin settings, uncheck \'Calculate the size of files, folder and database before backing up\', save changes, then try again.';
2433
- wpvivid_delete_ready_task(error_message);
2434
- });
2435
- }
2436
- }
2437
-
2438
- function wpvivid_backup_now(task_id){
2439
- var ajax_data = {
2440
- 'action': 'wpvivid_backup_now',
2441
- 'task_id': task_id
2442
- };
2443
- task_retry_times = 0;
2444
- m_need_update=true;
2445
- wpvivid_post_request(ajax_data, function(data){
2446
- }, function(XMLHttpRequest, textStatus, errorThrown) {
2447
- });
2448
- }
2449
-
2450
- function wpvivid_delete_backup_task(task_id){
2451
- var ajax_data = {
2452
- 'action': 'wpvivid_delete_task',
2453
- 'task_id': task_id
2454
- };
2455
- wpvivid_post_request(ajax_data, function(data){}, function(XMLHttpRequest, textStatus, errorThrown) {
2456
- });
2457
- }
2458
-
2459
- function wpvivid_control_backup_lock(){
2460
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2461
- jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
2462
- }
2463
-
2464
- function wpvivid_control_backup_unlock(){
2465
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2466
- jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
2467
- }
2468
-
2469
- function wpvivid_delete_ready_task(error){
2470
- var ajax_data={
2471
- 'action': 'wpvivid_delete_ready_task'
2472
- };
2473
- wpvivid_post_request(ajax_data, function (data) {
2474
- try {
2475
- var jsonarray = jQuery.parseJSON(data);
2476
- if (jsonarray.result === 'success') {
2477
- wpvivid_add_notice('Backup', 'Error', error);
2478
- wpvivid_control_backup_unlock();
2479
- jQuery('#wpvivid_postbox_backup_percent').hide();
2480
- }
2481
- }
2482
- catch(err){
2483
- wpvivid_add_notice('Backup', 'Error', err);
2484
- wpvivid_control_backup_unlock();
2485
- jQuery('#wpvivid_postbox_backup_percent').hide();
2486
- }
2487
- }, function (XMLHttpRequest, textStatus, errorThrown) {
2488
- setTimeout(function () {
2489
- wpvivid_delete_ready_task(error);
2490
- }, 3000);
2491
- });
2492
- }
2493
- </script>
2494
- <?php
2495
- }
2496
-
2497
- function wpvivid_backup_module_add_tips(){
2498
- ?>
2499
- <div class="custom-info" style="float:left; width:100%;">
2500
- <strong><?php _e('Tip:', 'wpvivid-backuprestore'); ?></strong>&nbsp<?php _e('The settings are only for manual backup, which won\'t affect schedule settings.', 'wpvivid-backuprestore'); ?>
2501
- </div>
2502
- <?php
2503
- }
2504
-
2505
- function wpvivid_backuppage_add_schedule_module(){
2506
- $schedule=WPvivid_Schedule::get_schedule();
2507
- if($schedule['enable']){
2508
- $schedule_status='Enabled';
2509
- $next_backup_time=date("l, F d, Y H:i", $schedule['next_start']);
2510
- }
2511
- else{
2512
- $schedule_status='Disabled';
2513
- $next_backup_time='N/A';
2514
- }
2515
- $last_message = '';
2516
- $last_message = apply_filters('wpvivid_get_last_backup_message', $last_message);
2517
- ?>
2518
- <div class="postbox qucikbackup-schedule" id="wpvivid_postbox_backup_schedule">
2519
- <h2><span><?php _e( 'Backup Schedule','wpvivid-backuprestore'); ?></span></h2>
2520
- <div class="schedule-block">
2521
- <p id="wpvivid_schedule_status"><strong><?php _e('Schedule Status: ', 'wpvivid-backuprestore'); ?></strong><?php _e($schedule_status); ?></p>
2522
- <div id="wpvivid_schedule_info">
2523
- <p><strong><?php _e('Server Time: ', 'wpvivid-backuprestore'); ?></strong><?php _e(date("l, F d, Y H:i",time())); ?></p>
2524
- <p><span id="wpvivid_last_backup_msg"><?php _e($last_message); ?></span></p>
2525
- <p id="wpvivid_next_backup"><strong><?php _e('Next Backup: ', 'wpvivid-backuprestore'); ?></strong><?php _e($next_backup_time); ?></p>
2526
- </div>
2527
- </div>
2528
- </div>
2529
- <div style="clear:both;"></div>
2530
- <?php
2531
- }
2532
-
2533
-
2534
- add_filter('wpvivid_add_backup_type', 'wpvivid_add_backup_type', 11, 2);
2535
- add_action('wpvivid_backup_do_js', 'wpvivid_backup_do_js', 10);
2536
- add_filter('wpvivid_download_backup_descript', 'wpvivid_download_backup_descript', 10);
2537
- add_filter('wpvivid_restore_website_descript', 'wpvivid_restore_website_descript', 10);
2538
-
2539
- add_filter('wpvivid_backuppage_load_backuplist', 'wpvivid_backuppage_load_backuplist', 10);
2540
-
2541
- add_action('wpvivid_backuppage_add_module', 'wpvivid_backuppage_add_progress_module', 10);
2542
- add_action('wpvivid_backuppage_add_module', 'wpvivid_backuppage_add_backup_module', 11);
2543
- add_action('wpvivid_backuppage_add_module', 'wpvivid_backuppage_add_schedule_module', 12);
2544
-
2545
- add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_descript');
2546
- add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_backup_type');
2547
- add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_send_remote');
2548
- add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_exec');
2549
- add_action('wpvivid_backup_module_add_sub', 'wpvivid_backup_module_add_tips');
2550
-
2551
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/admin/partials/wpvivid-log-read-page-display.php DELETED
File without changes
trunk/admin/partials/wpvivid-logs-page-display.php DELETED
File without changes
trunk/admin/partials/wpvivid-remote-storage-page-display.php DELETED
@@ -1,414 +0,0 @@
1
- <?php
2
-
3
- function wpvivid_add_tab_storage_list()
4
- {
5
- ?>
6
- <a href="#" id="wpvivid_tab_storage_list" class="nav-tab storage-nav-tab nav-tab-active" onclick="switchstorageTabs(event,'page-storage-list','page-storage-list')"><?php _e('Storages', 'wpvivid-backuprestore'); ?></a>
7
- <?php
8
- }
9
-
10
- function wpvivid_add_tab_storage_edit()
11
- {
12
- ?>
13
- <a href="#" id="wpvivid_tab_storage_edit" class="nav-tab storage-nav-tab delete" onclick="switchstorageTabs(event,'page-storage_edit','page-storage_edit')" style="display: none;">
14
- <div id="wpvivid_tab_storage_edit_text" style="margin-right: 15px;"><?php _e('Storage Edit', 'wpvivid-backuprestore'); ?></div>
15
- <div class="nav-tab-delete-img">
16
- <img src="<?php echo esc_url(plugins_url( 'images/delete-tab.png', __FILE__ )); ?>" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, 'wpvivid_tab_storage_edit', 'storage', 'wpvivid_tab_storage_list');" />
17
- </div>
18
- </a>
19
- <?php
20
- }
21
-
22
- function wpvivid_add_page_storage_list()
23
- {
24
- ?>
25
- <div class="storage-tab-content wpvivid_tab_storage_list" id="page-storage-list">
26
- <div style="margin-top:10px;"><p><strong><?php _e('Please choose one storage to save your backups (remote storage)', 'wpvivid-backuprestore'); ?></strong></p></div>
27
- <div class="schedule-tab-block"></div>
28
- <div class="">
29
- <table class="widefat">
30
- <thead>
31
- <tr>
32
- <th></th>
33
- <th></th>
34
- <th><?php _e( 'Storage Provider', 'wpvivid-backuprestore' ); ?></th>
35
- <th class="row-title"><?php _e( 'Remote Storage Alias', 'wpvivid-backuprestore' ); ?></th>
36
- <th><?php _e( 'Actions', 'wpvivid-backuprestore' ); ?></th>
37
- </tr>
38
- </thead>
39
- <tbody class="wpvivid-remote-storage-list" id="wpvivid_remote_storage_list">
40
- <?php
41
- $html = '';
42
- $html = apply_filters('wpvivid_add_remote_storage_list', $html);
43
- echo $html;
44
- ?>
45
- </tbody>
46
- <tfoot>
47
- <tr>
48
- <th colspan="5" class="row-title"><input class="button-primary" id="wpvivid_set_default_remote_storage" type="submit" name="choose-remote-storage" value="<?php esc_attr_e( 'Save Changes', 'wpvivid-backuprestore' ); ?>" /></th>
49
- </tr>
50
- </tfoot>
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('#wpvivid_set_default_remote_storage').click(function(){
62
- wpvivid_set_default_remote_storage();
63
- wpvivid_settings_changed = false;
64
- });
65
-
66
- /**
67
- * Add remote storages to the list
68
- *
69
- * @param action - The action to add or test a remote storage
70
- * @param storage_type - Remote storage types (Amazon S3, SFTP and FTP server)
71
- */
72
- function wpvivid_add_remote_storage(storage_type)
73
- {
74
- var remote_from = wpvivid_ajax_data_transfer(storage_type);
75
- var ajax_data;
76
- ajax_data = {
77
- 'action': 'wpvivid_add_remote',
78
- 'remote': remote_from,
79
- 'type': storage_type
80
- };
81
- jQuery('input[option=add-remote]').css({'pointer-events': 'none', 'opacity': '0.4'});
82
- jQuery('#wpvivid_remote_notice').html('');
83
- wpvivid_post_request(ajax_data, function (data)
84
- {
85
- try
86
- {
87
- var jsonarray = jQuery.parseJSON(data);
88
- if (jsonarray.result === 'success')
89
- {
90
- jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
91
- jQuery('input:text[option='+storage_type+']').each(function(){
92
- jQuery(this).val('');
93
- });
94
- jQuery('input:password[option='+storage_type+']').each(function(){
95
- jQuery(this).val('');
96
- });
97
- wpvivid_handle_remote_storage_data(data);
98
- }
99
- else if (jsonarray.result === 'failed')
100
- {
101
- jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
102
- jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
103
- }
104
- }
105
- catch (err)
106
- {
107
- alert(err);
108
- jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
109
- }
110
-
111
- }, function (XMLHttpRequest, textStatus, errorThrown)
112
- {
113
- var error_message = wpvivid_output_ajaxerror('adding the remote storage', textStatus, errorThrown);
114
- alert(error_message);
115
- jQuery('input[option=add-remote]').css({'pointer-events': 'auto', 'opacity': '1'});
116
- });
117
- }
118
-
119
- function wpvivid_edit_remote_storage() {
120
- var data_tran = 'edit-'+wpvivid_editing_storage_type;
121
- var remote_data = wpvivid_ajax_data_transfer(data_tran);
122
- var ajax_data;
123
- ajax_data = {
124
- 'action': 'wpvivid_edit_remote',
125
- 'remote': remote_data,
126
- 'id': wpvivid_editing_storage_id,
127
- 'type': wpvivid_editing_storage_type
128
- };
129
- jQuery('#wpvivid_remote_notice').html('');
130
- wpvivid_post_request(ajax_data, function(data){
131
- try {
132
- var jsonarray = jQuery.parseJSON(data);
133
- if (jsonarray.result === 'success') {
134
- jQuery('#wpvivid_tab_storage_edit').hide();
135
- wpvivid_click_switch_page('storage', 'wpvivid_tab_storage_list', true);
136
- wpvivid_handle_remote_storage_data(data);
137
- }
138
- else if (jsonarray.result === 'failed') {
139
- jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
140
- }
141
- }
142
- catch(err){
143
- alert(err);
144
- }
145
- },function(XMLHttpRequest, textStatus, errorThrown) {
146
- var error_message = wpvivid_output_ajaxerror('editing the remote storage', textStatus, errorThrown);
147
- alert(error_message);
148
- });
149
- }
150
-
151
- /**
152
- * Set a default remote storage for backups.
153
- */
154
- function wpvivid_set_default_remote_storage(){
155
- var remote_storage = new Array();
156
- //remote_storage[0] = jQuery("input[name='remote_storage']:checked").val();
157
- jQuery.each(jQuery("input[name='remote_storage']:checked"), function()
158
- {
159
- remote_storage.push(jQuery(this).val());
160
- });
161
-
162
- var ajax_data = {
163
- 'action': 'wpvivid_set_default_remote_storage',
164
- 'remote_storage': remote_storage
165
- };
166
- jQuery('#wpvivid_remote_notice').html('');
167
- wpvivid_post_request(ajax_data, function(data){
168
- wpvivid_handle_remote_storage_data(data);
169
- }, function(XMLHttpRequest, textStatus, errorThrown) {
170
- var error_message = wpvivid_output_ajaxerror('setting up the default remote storage', textStatus, errorThrown);
171
- alert(error_message);
172
- });
173
- }
174
-
175
- jQuery('#wpvivid_remote_storage_list').on("click", "input", function(){
176
- var check_status = true;
177
- if(jQuery(this).prop('checked') === true){
178
- check_status = true;
179
- }
180
- else {
181
- check_status = false;
182
- }
183
- jQuery('input[name="remote_storage"]').prop('checked', false);
184
- if(check_status === true){
185
- jQuery(this).prop('checked', true);
186
- }
187
- else {
188
- jQuery(this).prop('checked', false);
189
- }
190
- });
191
-
192
- function wpvivid_delete_remote_storage(storage_id){
193
- var descript = 'Deleting a remote storage will make it unavailable until it is added again. Are you sure to continue?';
194
- var ret = confirm(descript);
195
- if(ret === true){
196
- var ajax_data = {
197
- 'action': 'wpvivid_delete_remote',
198
- 'remote_id': storage_id
199
- };
200
- wpvivid_post_request(ajax_data, function(data){
201
- wpvivid_handle_remote_storage_data(data);
202
- },function(XMLHttpRequest, textStatus, errorThrown) {
203
- var error_message = wpvivid_output_ajaxerror('deleting the remote storage', textStatus, errorThrown);
204
- alert(error_message);
205
- });
206
- }
207
- }
208
-
209
- function wpvivid_handle_remote_storage_data(data){
210
- var i = 0;
211
- try {
212
- var jsonarray = jQuery.parseJSON(data);
213
- if (jsonarray.result === 'success') {
214
- jQuery('#wpvivid_remote_storage_list').html('');
215
- jQuery('#wpvivid_remote_storage_list').append(jsonarray.html);
216
- jQuery('#upload_storage').html(jsonarray.pic);
217
- jQuery('#schedule_upload_storage').html(jsonarray.pic);
218
- jQuery('#wpvivid_out_of_date_remote_path').html(jsonarray.dir);
219
- jQuery('#wpvivid_schedule_backup_local_remote').html(jsonarray.local_remote);
220
- wpvivid_control_remote_storage(jsonarray.remote_storage);
221
- jQuery('#wpvivid_remote_notice').html(jsonarray.notice);
222
- }
223
- else if(jsonarray.result === 'failed'){
224
- alert(jsonarray.error);
225
- }
226
- }
227
- catch(err){
228
- alert(err);
229
- }
230
- }
231
-
232
- function wpvivid_control_remote_storage(has_remote){
233
- if(!has_remote){
234
- if(jQuery("input:radio[name='save_local_remote'][value='remote']").prop('checked')) {
235
- alert("There is no default remote storage configured. Please set it up first.");
236
- jQuery("input:radio[name='save_local_remote'][value='local']").prop('checked', true);
237
- }
238
- }
239
- }
240
-
241
- function click_retrieve_remote_storage(id,type,name)
242
- {
243
- wpvivid_editing_storage_id = id;
244
- jQuery('.remote-storage-edit').hide();
245
- jQuery('#wpvivid_tab_storage_edit').show();
246
- jQuery('#wpvivid_tab_storage_edit_text').html(name);
247
- wpvivid_editing_storage_type=type;
248
- jQuery('#remote_storage_edit_'+wpvivid_editing_storage_type).fadeIn();
249
- wpvivid_click_switch_page('storage', 'wpvivid_tab_storage_edit', true);
250
-
251
- var ajax_data = {
252
- 'action': 'wpvivid_retrieve_remote',
253
- 'remote_id': id
254
- };
255
- wpvivid_post_request(ajax_data, function(data)
256
- {
257
- try
258
- {
259
- var jsonarray = jQuery.parseJSON(data);
260
- if (jsonarray.result === 'success')
261
- {
262
- jQuery('input:text[option=edit-'+jsonarray.type+']').each(function(){
263
- var key = jQuery(this).prop('name');
264
- jQuery(this).val(jsonarray[key]);
265
- });
266
- jQuery('input:password[option=edit-'+jsonarray.type+']').each(function(){
267
- var key = jQuery(this).prop('name');
268
- jQuery(this).val(jsonarray[key]);
269
- });
270
- jQuery('input:checkbox[option=edit-'+jsonarray.type+']').each(function() {
271
- var key = jQuery(this).prop('name');
272
- var value;
273
- if(jsonarray[key] == '0'){
274
- value = false;
275
- }
276
- else{
277
- value = true;
278
- }
279
- jQuery(this).prop('checked', value);
280
- });
281
- }
282
- else
283
- {
284
- alert(jsonarray.error);
285
- }
286
- }
287
- catch(err)
288
- {
289
- alert(err);
290
- }
291
- },function(XMLHttpRequest, textStatus, errorThrown)
292
- {
293
- var error_message = wpvivid_output_ajaxerror('retrieving the remote storage', textStatus, errorThrown);
294
- alert(error_message);
295
- });
296
- }
297
- </script>
298
- <?php
299
- }
300
-
301
- function wpvivid_add_page_storage_edit()
302
- {
303
- ?>
304
- <div class="storage-tab-content wpvivid_tab_storage_edit" id="page-storage_edit" style="display:none;">
305
- <div><?php do_action('wpvivid_edit_remote_page'); ?></div>
306
- </div>
307
- <script>
308
- jQuery('input[option=edit-remote]').click(function(){
309
- wpvivid_edit_remote_storage();
310
- });
311
- </script>
312
- <?php
313
- }
314
-
315
- function wpvivid_storage_list($html)
316
- {
317
- $html='<h2 class="nav-tab-wrapper" style="padding-bottom:0!important;">';
318
- $html.='<a href="#" id="wpvivid_tab_storage_list" class="nav-tab storage-nav-tab nav-tab-active" onclick="switchstorageTabs(event,\'page-storage-list\',\'page-storage-list\')">'. __('Storages', 'wpvivid-backuprestore').'</a>';
319
- $html.='<a href="#" id="wpvivid_tab_storage_edit" class="nav-tab storage-nav-tab delete" onclick="switchstorageTabs(event,\'page-storage_edit\',\'page-storage_edit\')" style="display: none;">
320
- <div id="wpvivid_tab_storage_edit_text" style="margin-right: 15px;">'.__('Storage Edit', 'wpvivid-backuprestore').'</div>
321
- <div class="nav-tab-delete-img">
322
- <img src="'.esc_url(plugins_url( 'images/delete-tab.png', __FILE__ )).'" style="vertical-align:middle; cursor:pointer;" onclick="wpvivid_close_tab(event, \'wpvivid_tab_storage_edit\', \'storage\', \'wpvivid_tab_storage_list\');" />
323
- </div>
324
- </a>';
325
- $html.='</h2>';
326
- $html.='<div class="storage-tab-content wpvivid_tab_storage_list" id="page-storage-list">
327
- <div style="margin-top:10px;"><p><strong>'.__('Please choose one storage to save your backups (remote storage)', 'wpvivid-backuprestore').'</strong></p></div>
328
- <div class="schedule-tab-block"></div>
329
- <div class="">
330
- <table class="widefat">
331
- <thead>
332
- <tr>
333
- <th></th>
334
- <th></th>
335
- <th>'. __( 'Storage Provider', 'wpvivid-backuprestore' ).'</th>
336
- <th class="row-title">'. __( 'Remote Storage Alias', 'wpvivid-backuprestore' ).'</th>
337
- <th>'. __( 'Actions', 'wpvivid-backuprestore' ).'</th>
338
- </tr>
339
- </thead>
340
- <tbody class="wpvivid-remote-storage-list" id="wpvivid_remote_storage_list">
341
- ';
342
- $html_list='';
343
- $html.= apply_filters('wpvivid_add_remote_storage_list', $html_list);
344
- $html.='</tbody><tfoot><tr>
345
- <th colspan="5" class="row-title"><input class="button-primary" id="wpvivid_set_default_remote_storage" type="submit" name="choose-remote-storage" value="'.esc_attr__( 'Save Changes', 'wpvivid-backuprestore' ).'" /></th>
346
- </tr></tfoot></table></div></div>';
347
-
348
- $html .= '<script>
349
- jQuery(\'#wpvivid_remote_storage_list\').on("click", "input", function(){
350
- var check_status = true;
351
- if(jQuery(this).prop(\'checked\') === true){
352
- check_status = true;
353
- }
354
- else {
355
- check_status = false;
356
- }
357
- jQuery(\'input[name = "remote_storage"]\').prop(\'checked\', false);
358
- if(check_status === true){
359
- jQuery(this).prop(\'checked\', true);
360
- }
361
- else {
362
- jQuery(this).prop(\'checked\', false);
363
- }
364
- });
365
- </script>';
366
- return $html;
367
- }
368
-
369
- add_action('wpvivid_storage_add_tab', 'wpvivid_add_tab_storage_list', 10);
370
- add_action('wpvivid_storage_add_tab', 'wpvivid_add_tab_storage_edit', 11);
371
- add_action('wpvivid_storage_add_page', 'wpvivid_add_page_storage_list', 10);
372
- add_action('wpvivid_storage_add_page', 'wpvivid_add_page_storage_edit', 11);
373
- //add_filter('wpvivid_storage_list','wpvivid_storage_list',10);
374
- ?>
375
-
376
-
377
-
378
- <script>
379
- function select_remote_storage(evt, storage_page_id)
380
- {
381
- var i, tablecontent, tablinks;
382
- tablinks = document.getElementsByClassName("storage-providers");
383
- for (i = 0; i < tablinks.length; i++) {
384
- tablinks[i].className = tablinks[i].className.replace("storage-providers-active", "");
385
- }
386
- evt.currentTarget.className += " storage-providers-active";
387
-
388
- jQuery(".storage-account-page").hide();
389
- jQuery("#"+storage_page_id).show();
390
- }
391
- function switchstorageTabs(evt,contentName,storage_page_id) {
392
- // Declare all variables
393
- var i, tabcontent, tablinks;
394
-
395
- // Get all elements with class="table-list-content" and hide them
396
- tabcontent = document.getElementsByClassName("storage-tab-content");
397
- for (i = 0; i < tabcontent.length; i++) {
398
- tabcontent[i].style.display = "none";
399
- }
400
-
401
- // Get all elements with class="table-nav-tab" and remove the class "nav-tab-active"
402
- tablinks = document.getElementsByClassName("storage-nav-tab");
403
- for (i = 0; i < tablinks.length; i++) {
404
- tablinks[i].className = tablinks[i].className.replace(" nav-tab-active", "");
405
- }
406
-
407
- // Show the current tab, and add an "storage-menu-active" class to the button that opened the tab
408
- document.getElementById(contentName).style.display = "block";
409
- evt.currentTarget.className += " nav-tab-active";
410
-
411
- var top = jQuery('#'+storage_page_id).offset().top-jQuery('#'+storage_page_id).height();
412
- jQuery('html, body').animate({scrollTop:top}, 'slow');
413
- }
414
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/admin/partials/wpvivid-schedule-page-display.php DELETED
@@ -1,203 +0,0 @@
1
- <?php
2
-
3
- function wpvivid_schedule_settings()
4
- {
5
- ?>
6
- <tr>
7
- <td class="row-title wpvivid-backup-settings-table tablelistcolumn"><label for="tablecell"><?php _e('Schedule Settings', 'wpvivid-backuprestore'); ?></label></td>
8
- <td class="tablelistcolumn">
9
- <div id="storage-brand-3">
10
- <div>
11
- <div>
12
- <div class="postbox schedule-tab-block">
13
- <label for="wpvivid_schedule_enable">
14
- <input option="schedule" name="enable" type="checkbox" id="wpvivid_schedule_enable" />
15
- <span><?php _e( 'Enable backup schedule', 'wpvivid-backuprestore' ); ?></span>
16
- </label><br>
17
- <label>
18
- <div style="float: left;">
19
- <input type="checkbox" disabled />
20
- <span class="wpvivid-element-space-right" style="color: #ddd;"><?php _e('Enable Incremental Backup', 'wpvivid-backuprestore'); ?></span>
21
- </div>
22
- <div style="float: left; height: 32px; line-height: 32px;">
23
- <span class="wpvivid-feature-pro">
24
- <a href="https://docs.wpvivid.com/wpvivid-backup-pro-incremental-backups.html"><?php _e('Pro feature: learn more', 'wpvivid-backuprestore'); ?></a>
25
- </span>
26
- </div>
27
- <div style="clear: both;"></div>
28
- </label>
29
- <label>
30
- <div style="float: left;">
31
- <input type="checkbox" disabled />
32
- <span class="wpvivid-element-space-right" style="color: #ddd;"><?php _e('Advanced Schedule', 'wpvivid-backuprestore'); ?></span>
33
- </div>
34
- <div style="float: left; height: 32px; line-height: 32px;">
35
- <span class="wpvivid-feature-pro">
36
- <a href="https://docs.wpvivid.com/wpvivid-backup-pro-schedule-overview.html"><?php _e('Pro feature: learn more', 'wpvivid-backuprestore'); ?></a>
37
- </span>
38
- </div>
39
- <div style="clear: both;"></div>
40
- </label>
41
- <div style="clear: both;"></div>
42
- <div>
43
- <?php
44
- $notice='';
45
- $notice= apply_filters('wpvivid_schedule_notice',$notice);
46
- echo $notice;
47
- ?>
48
- </div>
49
- </div>
50
- <div class="postbox schedule-tab-block">
51
- <fieldset>
52
- <legend class="screen-reader-text"><span>input type="radio"</span></legend>
53
- <?php
54
- $time='';
55
- $time= apply_filters('wpvivid_schedule_time',$time);
56
- echo $time;
57
- ?>
58
- </fieldset>
59
- </div>
60
- </div>
61
- </div>
62
- <div class="postbox schedule-tab-block" id="wpvivid_schedule_backup_type">
63
- <div>
64
- <div>
65
- <fieldset>
66
- <legend class="screen-reader-text"><span>input type="radio"</span></legend>
67
- <?php
68
- $backup_type='';
69
- $backup_type= apply_filters('wpvivid_schedule_backup_type',$backup_type);
70
- echo $backup_type;
71
- ?>
72
- </fieldset>
73
- </div>
74
- <div style="clear:both;"></div>
75
- </div>
76
- </div>
77
- <div class="postbox schedule-tab-block" id="wpvivid_schedule_remote_storage">
78
- <div id="wpvivid_schedule_backup_local_remote">
79
- <?php
80
- $html='';
81
- $html= apply_filters('wpvivid_schedule_local_remote',$html);
82
- echo $html;
83
- ?>
84
- </div>
85
- <div id="schedule_upload_storage" style="cursor:pointer;" title="<?php _e('Highlighted icon illuminates that you have choosed a remote storage to store backups', 'wpvivid-backuprestore'); ?>">
86
- <?php
87
- $pic='';
88
- $pic= apply_filters('wpvivid_schedule_add_remote_pic',$pic);
89
- echo $pic;
90
- ?>
91
- </div>
92
- </div>
93
- <div class="postbox schedule-tab-block">
94
- <div style="float:left; color: #ddd; margin-right: 10px;">
95
- <?php _e('+ Add another schedule', 'wpvivid-backuprestore'); ?>
96
- </div>
97
- <span class="wpvivid-feature-pro">
98
- <a href="https://docs.wpvivid.com/wpvivid-backup-pro-creating-schedules.html"><?php _e('Pro feature: learn more', 'wpvivid-backuprestore'); ?></a>
99
- </span>
100
- </div>
101
- </div>
102
- </td>
103
- </tr>
104
- <script>
105
- <?php
106
- do_action('wpvivid_schedule_do_js');
107
- ?>
108
- </script>
109
- <?php
110
- }
111
-
112
- function wpvivid_schedule_notice($html)
113
- {
114
- $offset=get_option('gmt_offset');
115
- $time = '00:00:00';
116
- $utime = strtotime($time) + $offset * 60 * 60;
117
- $html='<p>1) '.__('Scheduled job will start at <strong>UTC</strong> time:', 'wpvivid-backuprestore').'&nbsp'.date('H:i:s', $utime).'</p>';
118
- $html.='<p>2) '.__('Being subjected to mechanisms of PHP, a scheduled backup task for your site will be triggered only when the site receives at least a visit at any page.', 'wpvivid-backuprestore').'</p>';
119
- return $html;
120
- }
121
-
122
- function wpvivid_schedule_backup_type($html)
123
- {
124
- $html='<label>';
125
- $html.='<input type="radio" option="schedule" name="backup_type" value="files+db"/>';
126
- $html.='<span>'.__('Database + Files (WordPress Files)', 'wpvivid-backuprestore').'</span>';
127
- $html.='</label><br>';
128
-
129
- $html.='<label>';
130
- $html.='<input type="radio" option="schedule" name="backup_type" value="files"/>';
131
- $html.='<span>'.__('WordPress Files (Exclude Database)', 'wpvivid-backuprestore').'</span>';
132
- $html.='</label><br>';
133
-
134
- $html.='<label>';
135
- $html.='<input type="radio" option="schedule" name="backup_type" value="db"/>';
136
- $html.='<span>'.__('Only Database', 'wpvivid-backuprestore').'</span>';
137
- $html.='</label><br>';
138
-
139
- $html.='<label>';
140
- $html.='<div style="float: left;">';
141
- $html.='<input type="radio" disabled />';
142
- $html.='<span class="wpvivid-element-space-right" style="color: #ddd;">'.__('Custom', 'wpvivid-backuprestore').'</span>';
143
- $html.='</div>';
144
- $html.='<div style="float: left; height: 32px; line-height: 32px;">';
145
- $html.='<span class="wpvivid-feature-pro">';
146
- $html.='<a href="https://docs.wpvivid.com/wpvivid-backup-pro-customize-what-to-backup-for-schedule.html" style="text-decoration: none;">'.__('Pro feature: learn more', 'wpvivid-backuprestore').'</a>';
147
- $html.='</span>';
148
- $html.='</div>';
149
- $html.='</label><br>';
150
- return $html;
151
- }
152
-
153
- function wpvivid_schedule_do_js()
154
- {
155
- $schedule=WPvivid_Schedule::get_schedule();
156
- if($schedule['enable'] == true)
157
- {
158
- ?>
159
- jQuery("#wpvivid_schedule_enable").prop('checked', true);
160
- <?php
161
- if($schedule['backup']['remote'] === 1)
162
- {
163
- $schedule_remote='remote';
164
- }
165
- else{
166
- $schedule_remote='local';
167
- }
168
- }
169
- else{
170
- $schedule['recurrence']='wpvivid_daily';
171
- $schedule['backup']['backup_files']='files+db';
172
- $schedule_remote='local';
173
- }
174
- ?>
175
- jQuery("input:radio[value='<?php echo $schedule['recurrence']?>']").prop('checked', true);
176
- jQuery("input:radio[value='<?php echo $schedule['backup']['backup_files']?>']").prop('checked', true);
177
- jQuery("input:radio[name='save_local_remote'][value='remote']").click(function()
178
- {
179
- <?php
180
- $remote_id_array = WPvivid_Setting::get_user_history('remote_selected');
181
- $remote_id = '';
182
- foreach ($remote_id_array as $value)
183
- {
184
- $remote_id = $value;
185
- }
186
- if(empty($remote_id))
187
- {
188
- ?>
189
- alert("There is no default remote storage configured. Please set it up first.");
190
- jQuery("input:radio[name='save_local_remote'][value='local']").prop('checked', true);
191
- <?php
192
- }
193
- ?>
194
- });
195
- <?php
196
- }
197
-
198
- add_action('wpvivid_schedule_add_cell','wpvivid_schedule_settings',11);
199
- add_action('wpvivid_schedule_do_js','wpvivid_schedule_do_js',10);
200
- add_filter('wpvivid_schedule_backup_type','wpvivid_schedule_backup_type');
201
- add_filter('wpvivid_schedule_notice','wpvivid_schedule_notice',10);
202
- ?>
203
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/admin/partials/wpvivid-settings-page-display.php DELETED
@@ -1,710 +0,0 @@
1
- <?php
2
-
3
- function wpvivid_general_settings()
4
- {
5
- $general_setting=WPvivid_Setting::get_setting(true, "");
6
- $display_backup_count = $general_setting['options']['wpvivid_common_setting']['max_backup_count'];
7
- $display_backup_count=intval($display_backup_count);
8
- if($display_backup_count > 7){
9
- $display_backup_count = 7;
10
- }
11
- if($general_setting['options']['wpvivid_common_setting']['estimate_backup']){
12
- $wpvivid_setting_estimate_backup='checked';
13
- }
14
- else{
15
- $wpvivid_setting_estimate_backup='';
16
- }
17
- /*if(!isset($general_setting['options']['wpvivid_common_setting']['show_tab_menu'])){
18
- $wpvivid_show_tab_menu='checked';
19
- }
20
- else {
21
- if ($general_setting['options']['wpvivid_common_setting']['show_tab_menu']) {
22
- $wpvivid_show_tab_menu = 'checked';
23
- } else {
24
- $wpvivid_show_tab_menu = '';
25
- }
26
- }*/
27
- if(!isset($general_setting['options']['wpvivid_common_setting']['show_admin_bar'])){
28
- $show_admin_bar = 'checked';
29
- }
30
- else{
31
- if($general_setting['options']['wpvivid_common_setting']['show_admin_bar']){
32
- $show_admin_bar = 'checked';
33
- }
34
- else{
35
- $show_admin_bar = '';
36
- }
37
- }
38
- if(!isset($general_setting['options']['wpvivid_common_setting']['domain_include'])){
39
- $wpvivid_domain_include = 'checked';
40
- }
41
- else{
42
- if($general_setting['options']['wpvivid_common_setting']['domain_include']){
43
- $wpvivid_domain_include = 'checked';
44
- }
45
- else{
46
- $wpvivid_domain_include = '';
47
- }
48
- }
49
- if(!isset($general_setting['options']['wpvivid_common_setting']['ismerge'])){
50
- $wpvivid_ismerge = 'checked';
51
- }
52
- else{
53
- if($general_setting['options']['wpvivid_common_setting']['ismerge'] == '1'){
54
- $wpvivid_ismerge = 'checked';
55
- }
56
- else{
57
- $wpvivid_ismerge = '';
58
- }
59
- }
60
- if(!isset($general_setting['options']['wpvivid_common_setting']['retain_local'])){
61
- $wpvivid_retain_local = '';
62
- }
63
- else{
64
- if($general_setting['options']['wpvivid_common_setting']['retain_local'] == '1'){
65
- $wpvivid_retain_local = 'checked';
66
- }
67
- else{
68
- $wpvivid_retain_local = '';
69
- }
70
- }
71
-
72
- if(!isset($general_setting['options']['wpvivid_common_setting']['uninstall_clear_folder'])){
73
- $uninstall_clear_folder = '';
74
- }
75
- else{
76
- if($general_setting['options']['wpvivid_common_setting']['uninstall_clear_folder'] == '1'){
77
- $uninstall_clear_folder = 'checked';
78
- }
79
- else{
80
- $uninstall_clear_folder = '';
81
- }
82
- }
83
-
84
- global $wpvivid_plugin;
85
- $out_of_date=$wpvivid_plugin->_get_out_of_date_info();
86
- ?>
87
- <div class="postbox schedule-tab-block">
88
- <div>
89
- <select option="setting" name="max_backup_count" id="wpvivid_max_backup_count">
90
- <?php
91
- for($i=1; $i<8;$i++){
92
- if($i === $display_backup_count){
93
- echo '<option selected="selected" value="' . $i . '">' . $i . '</option>';
94
- }
95
- else {
96
- echo '<option value="' . $i . '">' . $i . '</option>';
97
- }
98
- }
99
- ?>
100
- </select><strong style="margin-right: 10px;"><?php _e('backups retained', 'wpvivid-backuprestore'); ?></strong><a href="https://docs.wpvivid.com/wpvivid-backup-pro-backup-retention.html" style="text-decoration: none;"><?php _e('Pro feature: Retain more backups', 'wpvivid-backuprestore'); ?></a>
101
- </div>
102
- <div>
103
- <label for="wpvivid_estimate_backup">
104
- <input type="checkbox" option="setting" name="estimate_backup" id="wpvivid_estimate_backup" value="1" <?php esc_attr_e($wpvivid_setting_estimate_backup); ?> />
105
- <span><?php _e('Calculate the size of files, folder and database before backing up', 'wpvivid-backuprestore' ); ?></span>
106
- </label>
107
- </div>
108
- <div>
109
- <label>
110
- <input type="checkbox" option="setting" name="show_admin_bar" <?php esc_attr_e($show_admin_bar); ?> />
111
- <span><?php _e('Show WPvivid backup plugin on top admin bar', 'wpvivid-backuprestore'); ?></span>
112
- </label>
113
- </div>
114
- <div>
115
- <label>
116
- <input type="checkbox" option="setting" name="ismerge" <?php esc_attr_e($wpvivid_ismerge); ?> />
117
- <span><?php _e('Merge all the backup files into single package when a backup completes. This will save great disk spaces, though takes longer time. We recommended you check the option especially on sites with insufficient server resources.', 'wpvivid-backuprestore'); ?></span>
118
- </label>
119
- </div>
120
- <div>
121
- <label>
122
- <input type="checkbox" option="setting" name="retain_local" <?php esc_attr_e($wpvivid_retain_local); ?> />
123
- <span><?php _e('Keep storing the backups in localhost after uploading to remote storage', 'wpvivid-backuprestore'); ?></span>
124
- </label>
125
- </div>
126
- <div>
127
- <label>
128
- <input type="checkbox" option="setting" name="uninstall_clear_folder" <?php esc_attr_e($uninstall_clear_folder); ?> />
129
- <span><?php _e(sprintf('Delete the /%s folder and all backups in it when deleting WPvivid Backup plugin.', $general_setting['options']['wpvivid_local_setting']['path']), 'wpvivid-backuprestore'); ?></span>
130
- </label>
131
- </div>
132
- </div>
133
- <div class="postbox schedule-tab-block">
134
- <div><strong><?php _e('Backup Folder', 'wpvivid-backuprestore'); ?></strong></div>
135
- <div class="setting-tab-block">
136
- <div><p><?php _e('Name your folder, this folder must be writable for creating backup files.', 'wpvivid-backuprestore' ); ?><p> </div>
137
- <input type="text" placeholder="wpvividbackups" option="setting" name="path" id="wpvivid_option_backup_dir" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_local_setting']['path'], 'wpvivid-backuprestore'); ?>" onkeyup="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" />
138
- <p><span class="wpvivid-element-space-right"><?php _e('Local storage directory:', 'wpvivid-backuprestore'); ?></span><span><?php echo WP_CONTENT_DIR.'/'; ?><span id="wpvivid_setting_local_storage_path"><?php _e($general_setting['options']['wpvivid_local_setting']['path'], 'wpvivid-backuprestore'); ?></span></span></p>
139
- </div>
140
- <div>
141
- <label>
142
- <input type="checkbox" option="setting" name="domain_include" <?php esc_attr_e($wpvivid_domain_include); ?> />
143
- <span><?php _e('Display domain(url) of current site in backup name. (e.g. domain_wpvivid-5ceb938b6dca9_2019-05-27-07-36_backup_all.zip)', 'wpvivid-backuprestore'); ?></span>
144
- </label>
145
- </div>
146
- </div>
147
- <div class="postbox schedule-tab-block">
148
- <div><strong><?php _e('Remove out-of-date backups', 'wpvivid-backuprestore'); ?></strong></div>
149
- <div class="setting-tab-block" style="padding-bottom: 0;">
150
- <fieldset>
151
- <label for="users_can_register">
152
- <p><span class="wpvivid-element-space-right"><?php _e('Web Server Directory:', 'wpvivid-backuprestore'); ?></span><span id="wpvivid_out_of_date_local_path"><?php _e($out_of_date['web_server'], 'wpvivid-backuprestore'); ?></span></p>
153
- <p><span style="margin-right: 2px;"><?php _e('Remote Storage Directory:', 'wpvivid-backuprestore'); ?></span><span id="wpvivid_out_of_date_remote_path">
154
- <?php
155
- $wpvivid_get_remote_directory = '';
156
- $wpvivid_get_remote_directory = apply_filters('wpvivid_get_remote_directory', $wpvivid_get_remote_directory);
157
- echo $wpvivid_get_remote_directory;
158
- ?>
159
- </span>
160
- </p>
161
- </label>
162
- </fieldset>
163
- </div>
164
- <div class="setting-tab-block" style="padding: 10px 10px 0 0;">
165
- <input class="button-primary" id="wpvivid_delete_out_of_backup" style="margin-right:10px;" type="submit" name="delete-out-of-backup" value="<?php esc_attr_e( 'Remove', 'wpvivid-backuprestore' ); ?>" />
166
- <p><?php _e('The action is irreversible! It will remove all backups are out-of-date (including local web server and remote storage) if they exist.', 'wpvivid-backuprestore'); ?> </p>
167
- </div>
168
- </div>
169
- <script>
170
- jQuery('#wpvivid_delete_out_of_backup').click(function(){
171
- wpvivid_delete_out_of_date_backups();
172
- });
173
-
174
- /**
175
- * This function will delete out of date backups.
176
- */
177
- function wpvivid_delete_out_of_date_backups(){
178
- var ajax_data={
179
- 'action': 'wpvivid_clean_out_of_date_backup'
180
- };
181
- jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'none', 'opacity': '0.4'});
182
- wpvivid_post_request(ajax_data, function(data){
183
- jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
184
- try {
185
- var jsonarray = jQuery.parseJSON(data);
186
- if (jsonarray.result === "success") {
187
- alert("Out of date backups have been removed.");
188
- wpvivid_handle_backup_data(data);
189
- }
190
- }
191
- catch(err){
192
- alert(err);
193
- jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
194
- }
195
- }, function(XMLHttpRequest, textStatus, errorThrown) {
196
- var error_message = wpvivid_output_ajaxerror('deleting out of date backups', textStatus, errorThrown);
197
- alert(error_message);
198
- jQuery('#wpvivid_delete_out_of_backup').css({'pointer-events': 'auto', 'opacity': '1'});
199
- });
200
- }
201
- </script>
202
- <?php
203
- }
204
-
205
- function wpvivid_email_report()
206
- {
207
- $general_setting=WPvivid_Setting::get_setting(true, "");
208
- $setting_email_enable='';
209
- $setting_email_display = 'display: none;';
210
- if(isset($general_setting['options']['wpvivid_email_setting']['email_enable'])){
211
- if($general_setting['options']['wpvivid_email_setting']['email_enable']){
212
- $setting_email_enable='checked';
213
- $setting_email_display = '';
214
- }
215
- }
216
- $wpvivid_setting_email_always='';
217
- $wpvivid_setting_email_failed='';
218
- if(isset($general_setting['options']['wpvivid_email_setting']['always'])&&$general_setting['options']['wpvivid_email_setting']['always']) {
219
- $wpvivid_setting_email_always='checked';
220
- }
221
- else{
222
- $wpvivid_setting_email_failed='checked';
223
- }
224
- ?>
225
- <div class="postbox schedule-tab-block" id="wpvivid_email_report">
226
- <div><p><?php _e('In order to use this function, please install a <strong><a target="_blank" href="https://wpvivid.com/8-best-smtp-plugins-for-wordpress.html" style="text-decoration: none;">WordPress SMTP plugin</a></strong> of your preference and configure your SMTP server first. This is because WordPress uses the PHP Mail function to send its emails by default, which is not supported by many hosts and can cause issues if it is not set properly.', 'wpvivid-backuprestore'); ?></p>
227
- </div>
228
- <div>
229
- <label for="wpvivid_general_email_enable">
230
- <input type="checkbox" option="setting" name="email_enable" id="wpvivid_general_email_enable" value="1" <?php esc_attr_e($setting_email_enable, 'wpvivid-backuprestore'); ?> />
231
- <span><strong><?php _e( 'Enable email report', 'wpvivid-backuprestore' ); ?></strong></span>
232
- </label>
233
- </div>
234
- <div id="wpvivid_general_email_setting" style="<?php esc_attr_e($setting_email_display, 'wpvivid-backuprestore'); ?>" >
235
- <input type="text" placeholder="example@yourdomain.com" option="setting" name="send_to" class="regular-text" id="wpvivid_mail" value="<?php
236
- if(!empty($general_setting['options']['wpvivid_email_setting']['send_to'])) {
237
- foreach ($general_setting['options']['wpvivid_email_setting']['send_to'] as $mail) {
238
- if(!empty($mail) && !is_array($mail)) {
239
- _e($mail, 'wpvivid-backuprestore');
240
- break;
241
- }
242
- }
243
- }
244
- ?>" />
245
- <input class="button-secondary" id="wpvivid_send_email_test" style="margin-top:10px;" type="submit" name="" value="<?php esc_attr_e( 'Test Email', 'wpvivid-backuprestore' ); ?>" title="Send an email for testing mail function"/>
246
- <div id="wpvivid_send_email_res"></div>
247
- <fieldset class="setting-tab-block">
248
- <label >
249
- <input type="radio" option="setting" name="always" value="1" <?php esc_attr_e($wpvivid_setting_email_always, 'wpvivid-backuprestore'); ?> />
250
- <span><?php _e( 'Always send an email notification when a backup is complete', 'wpvivid-backuprestore' ); ?></span>
251
- </label><br>
252
- <label >
253
- <input type="radio" option="setting" name="always" value="0" <?php esc_attr_e($wpvivid_setting_email_failed, 'wpvivid-backuprestore'); ?> />
254
- <span><?php _e( 'Only send an email notification when a backup fails', 'wpvivid-backuprestore' ); ?></span>
255
- </label><br>
256
- </fieldset>
257
- <div style="margin-bottom: 10px;">
258
- <a href="https://wpvivid.com/wpvivid-backup-pro-email-report?utm_source=client_email_report&utm_medium=inner_link&utm_campaign=access" style="text-decoration: none;"><?php _e('Pro feature: Add another email address to get report', 'wpvivid-backuprestore'); ?></a>
259
- </div>
260
- </div>
261
- </div>
262
- <script>
263
- jQuery('#wpvivid_send_email_test').click(function(){
264
- wpvivid_email_test();
265
- });
266
-
267
- /**
268
- * After enabling email report feature, and test if an email address works or not
269
- */
270
- function wpvivid_email_test(){
271
- var mail = jQuery('#wpvivid_mail').val();
272
- var ajax_data = {
273
- 'action': 'wpvivid_test_send_mail',
274
- 'send_to': mail
275
- };
276
- wpvivid_post_request(ajax_data, function(data){
277
- try {
278
- var jsonarray = jQuery.parseJSON(data);
279
- if (jsonarray.result === 'success') {
280
- jQuery('#wpvivid_send_email_res').html('Test succeeded.');
281
- }
282
- else {
283
- jQuery('#wpvivid_send_email_res').html('Test failed, ' + jsonarray.error);
284
- }
285
- }
286
- catch(err){
287
- alert(err);
288
- }
289
- }, function(XMLHttpRequest, textStatus, errorThrown) {
290
- var error_message = wpvivid_output_ajaxerror('sending test mail', textStatus, errorThrown);
291
- alert(error_message);
292
- });
293
- }
294
- </script>
295
- <?php
296
- }
297
-
298
- function wpvivid_clean_junk()
299
- {
300
- global $wpvivid_plugin;
301
- $junk_file=$wpvivid_plugin->_junk_files_info();
302
- ?>
303
- <div class="postbox schedule-tab-block" id="wpvivid_clean_junk">
304
- <div>
305
- <strong><?php _e('Web-server disk space in use by WPvivid', 'wpvivid-backuprestore'); ?></strong>
306
- </div>
307
- <div class="setting-tab-block">
308
- <div class="setting-tab-block">
309
- <span class="wpvivid-element-space-right"><?php _e('Total Size:', 'wpvivid-backuprestore'); ?></span>
310
- <span id="wpvivid_junk_sum_size"><?php _e($junk_file['sum_size'], 'wpvivid-backuprestore'); ?></span>
311
- <input class="button-secondary" id="wpvivid_calculate_size" style="margin-left:10px;" type="submit" name="Calculate-Sizes" value="<?php esc_attr_e( 'Calculate Sizes', 'wpvivid-backuprestore' ); ?>" />
312
- </div>
313
- <fieldset>
314
- <label for="wpvivid_junk_log">
315
- <input type="checkbox" id="wpvivid_junk_log" option="junk-files" name="log" value="junk-log" />
316
- <span class="wpvivid-element-space-right"><?php _e( 'logs', 'wpvivid-backuprestore' ); ?></span>
317
- <span style="margin-right: 2px;"><?php _e('Path:', 'wpvivid-backuprestore' ); ?></span><span id="wpvivid_junk_log_path"><?php _e($junk_file['log_path'], 'wpvivid-backuprestore'); ?></span>
318
- </label>
319
- </fieldset>
320
- <fieldset>
321
- <label for="wpvivid_junk_backup_cache">
322
- <input type="checkbox" id="wpvivid_junk_backup_cache" option="junk-files" name="backup_cache" value="junk-backup-cache" />
323
- <span class="wpvivid-element-space-right"><?php _e( 'Backup Cache', 'wpvivid-backuprestore' ); ?></span>
324
- </label>
325
- <label for="wpvivid_junk_file">
326
- <input type="checkbox" id="wpvivid_junk_file" option="junk-files" name="junk_files" value="junk-files" />
327
- <span class="wpvivid-element-space-right"><?php _e( 'Junk', 'wpvivid-backuprestore' ); ?></span>
328
- <span style="margin-right: 2px;"><?php _e('Path:', 'wpvivid-backuprestore' ); ?></span><span id="wpvivid_junk_file_path"><?php _e($junk_file['junk_path'], 'wpvivid-backuprestore'); ?></span>
329
- </label>
330
- </fieldset>
331
- <fieldset>
332
- <label for="wpvivid_junk_temporary_file">
333
- <input type="checkbox" id="wpvivid_junk_temporary_file" option="junk-files" name="old_files" value="junk-temporary-files" />
334
- <span class="wpvivid-element-space-right"><?php _e( 'Temporary Files', 'wpvivid-backuprestore' ); ?></span>
335
- <span style="margin-right: 2px;"><?php _e('Path:', 'wpvivid-backuprestore'); ?></span><span id="wpvivid_restore_temp_file_path"><?php _e($junk_file['old_files_path'], 'wpvivid-backuprestore'); ?></span>
336
- <p><?php echo __('Temporary Files are created by wpvivid when restoring a website.', 'wpvivid-backuprestore'); ?></p>
337
- </label>
338
- </fieldset>
339
- </div>
340
- <div><input class="button-primary" id="wpvivid_clean_junk_file" type="submit" name="Empty-all-files" value="<?php esc_attr_e( 'Empty', 'wpvivid-backuprestore' ); ?>" /></div>
341
- <div style="clear:both;"></div>
342
- </div>
343
- <script>
344
- jQuery('#wpvivid_calculate_size').click(function(){
345
- wpvivid_calculate_diskspaceused();
346
- });
347
-
348
- jQuery('#wpvivid_clean_junk_file').click(function(){
349
- wpvivid_clean_junk_files();
350
- });
351
-
352
- /**
353
- * Calculate the server disk space in use by WPvivid.
354
- */
355
- function wpvivid_calculate_diskspaceused(){
356
- var ajax_data={
357
- 'action': 'wpvivid_junk_files_info'
358
- };
359
- var current_size = jQuery('#wpvivid_junk_sum_size').html();
360
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'none', 'opacity': '0.4'});
361
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'none', 'opacity': '0.4'});
362
- jQuery('#wpvivid_junk_sum_size').html("calculating...");
363
- wpvivid_post_request(ajax_data, function(data){
364
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
365
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
366
- try {
367
- var jsonarray = jQuery.parseJSON(data);
368
- if (jsonarray.result === "success") {
369
- jQuery('#wpvivid_junk_sum_size').html(jsonarray.data.sum_size);
370
- jQuery('#wpvivid_junk_log_path').html(jsonarray.data.log_path);
371
- jQuery('#wpvivid_junk_file_path').html(jsonarray.data.junk_path);
372
- jQuery('#wpvivid_restore_temp_file_path').html(jsonarray.data.old_files_path);
373
- }
374
- }
375
- catch(err){
376
- alert(err);
377
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
378
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
379
- jQuery('#wpvivid_junk_sum_size').html(current_size);
380
- }
381
- }, function(XMLHttpRequest, textStatus, errorThrown) {
382
- var error_message = wpvivid_output_ajaxerror('calculating server disk space in use by WPvivid', textStatus, errorThrown);
383
- alert(error_message);
384
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
385
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
386
- jQuery('#wpvivid_junk_sum_size').html(current_size);
387
- });
388
- }
389
-
390
- /**
391
- * Clean junk files created during backups and restorations off your web server disk.
392
- */
393
- function wpvivid_clean_junk_files(){
394
- var descript = 'The selected item(s) will be permanently deleted. Are you sure you want to continue?';
395
- var ret = confirm(descript);
396
- if(ret === true){
397
- var option_data = wpvivid_ajax_data_transfer('junk-files');
398
- var ajax_data = {
399
- 'action': 'wpvivid_clean_local_storage',
400
- 'options': option_data
401
- };
402
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'none', 'opacity': '0.4'});
403
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'none', 'opacity': '0.4'});
404
- wpvivid_post_request(ajax_data, function (data) {
405
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
406
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
407
- jQuery('input[option="junk-files"]').prop('checked', false);
408
- try {
409
- var jsonarray = jQuery.parseJSON(data);
410
- alert(jsonarray.msg);
411
- if (jsonarray.result === "success") {
412
- jQuery('#wpvivid_junk_sum_size').html(jsonarray.data.sum_size);
413
- jQuery('#wpvivid_junk_log_path').html(jsonarray.data.log_path);
414
- jQuery('#wpvivid_junk_file_path').html(jsonarray.data.junk_path);
415
- jQuery('#wpvivid_restore_temp_file_path').html(jsonarray.data.old_files_path);
416
- jQuery('#wpvivid_loglist').html("");
417
- jQuery('#wpvivid_loglist').append(jsonarray.html);
418
- wpvivid_log_count = jsonarray.log_count;
419
- wpvivid_display_log_page();
420
- }
421
- }
422
- catch(err){
423
- alert(err);
424
- }
425
- }, function (XMLHttpRequest, textStatus, errorThrown) {
426
- var error_message = wpvivid_output_ajaxerror('cleaning out junk files', textStatus, errorThrown);
427
- alert(error_message);
428
- jQuery('#wpvivid_calculate_size').css({'pointer-events': 'auto', 'opacity': '1'});
429
- jQuery('#wpvivid_clean_junk_file').css({'pointer-events': 'auto', 'opacity': '1'});
430
- });
431
- }
432
- }
433
- </script>
434
- <?php
435
- }
436
-
437
- function wpvivid_export_import_settings()
438
- {
439
- ?>
440
- <div class="postbox schedule-tab-block" id="wpvivid_export_import">
441
- <div class="setting-tab-block" style="padding-bottom: 0;">
442
- <input class="button-primary" id="wpvivid_setting_export" type="button" name="" value="<?php esc_attr_e( 'Export', 'wpvivid-backuprestore' ); ?>" />
443
- <p><?php echo __('Click \'Export\' button to save WPvivid settings on your local computer.', 'wpvivid-backuprestore'); ?> </p>
444
- </div>
445
- <div class="setting-tab-block" style="padding: 0 10px 0 0;">
446
- <input type="file" name="fileTrans" id="wpvivid_select_import_file"></br>
447
- <input class="button-primary" id="wpvivid_setting_import" type="button" name="" value="<?php esc_attr_e( 'Import', 'wpvivid-backuprestore' ); ?>" />
448
- <p><?php echo __('Importing the json file can help you set WPvivid\'s configuration on another wordpress site quickly.', 'wpvivid-backuprestore'); ?></p>
449
- </div>
450
- <div style="clear:both;"></div>
451
- </div>
452
- <script>
453
- jQuery('#wpvivid_setting_export').click(function(){
454
- wpvivid_export_settings();
455
- });
456
-
457
- jQuery('#wpvivid_setting_import').click(function(){
458
- wpvivid_import_settings();
459
- });
460
-
461
- function wpvivid_export_settings() {
462
- wpvivid_location_href=true;
463
- location.href =ajaxurl+'?_wpnonce='+wpvivid_ajax_object.ajax_nonce+'&action=wpvivid_export_setting&setting=1&history=1&review=0';
464
- }
465
-
466
- function wpvivid_import_settings(){
467
- var files = jQuery('input[name="fileTrans"]').prop('files');
468
-
469
- if(files.length == 0){
470
- alert('Choose a settings file and import it by clicking Import button.');
471
- return;
472
- }
473
- else{
474
- var reader = new FileReader();
475
- reader.readAsText(files[0], "UTF-8");
476
- reader.onload = function(evt){
477
- var fileString = evt.target.result;
478
- var ajax_data = {
479
- 'action': 'wpvivid_import_setting',
480
- 'data': fileString
481
- };
482
- wpvivid_post_request(ajax_data, function(data){
483
- try {
484
- var jsonarray = jQuery.parseJSON(data);
485
- if (jsonarray.result === 'success') {
486
- alert('The plugin settings is imported successfully.');
487
- location.reload();
488
- }
489
- else {
490
- alert('Error: ' + jsonarray.error);
491
- }
492
- }
493
- catch(err){
494
- alert(err);
495
- }
496
- }, function(XMLHttpRequest, textStatus, errorThrown) {
497
- var error_message = wpvivid_output_ajaxerror('importing the previously-exported settings', textStatus, errorThrown);
498
- jQuery('#wpvivid_display_log_content').html(error_message);
499
- });
500
- }
501
- }
502
- }
503
- </script>
504
- <?php
505
- }
506
-
507
- function wpvivid_advanced_settings()
508
- {
509
- $general_setting=WPvivid_Setting::get_setting(true, "");
510
- $wpvivid_setting_no_compress='';
511
- $wpvivid_setting_compress='';
512
- if($general_setting['options']['wpvivid_compress_setting']['no_compress']){
513
- $wpvivid_setting_no_compress='checked';
514
- }
515
- else{
516
- $wpvivid_setting_compress='checked';
517
- }
518
-
519
- if(!isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
520
- $subpackage_plugin_upload = '';
521
- }
522
- else{
523
- if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
524
- $subpackage_plugin_upload = 'checked';
525
- }
526
- else{
527
- $subpackage_plugin_upload = '';
528
- }
529
- }
530
- if(!isset($general_setting['options']['wpvivid_common_setting']['max_resume_count'])){
531
- $wpvivid_max_resume_count = WPVIVID_RESUME_RETRY_TIMES;
532
- }
533
- else{
534
- $wpvivid_max_resume_count = intval($general_setting['options']['wpvivid_common_setting']['max_resume_count']);
535
- }
536
- if(!isset($general_setting['options']['wpvivid_common_setting']['memory_limit'])){
537
- $general_setting['options']['wpvivid_common_setting']['memory_limit']=WPVIVID_MEMORY_LIMIT;
538
- }
539
- if(!isset($general_setting['options']['wpvivid_common_setting']['restore_memory_limit'])){
540
- $general_setting['options']['wpvivid_common_setting']['restore_memory_limit']=WPVIVID_RESTORE_MEMORY_LIMIT;
541
- }
542
- if(!isset($general_setting['options']['wpvivid_common_setting']['migrate_size'])){
543
- $general_setting['options']['wpvivid_common_setting']['migrate_size']=WPVIVID_MIGRATE_SIZE;
544
- }
545
- if(isset($general_setting['options']['wpvivid_common_setting']['db_connect_method'])){
546
- if($general_setting['options']['wpvivid_common_setting']['db_connect_method'] === 'wpdb'){
547
- $db_method_wpdb = 'checked';
548
- $db_method_pdo = '';
549
- }
550
- else{
551
- $db_method_wpdb = '';
552
- $db_method_pdo = 'checked';
553
- }
554
- }
555
- else{
556
- $db_method_wpdb = 'checked';
557
- $db_method_pdo = '';
558
- }
559
- if(isset($general_setting['options']['wpvivid_common_setting']['restore_max_execution_time'])){
560
- $restore_max_execution_time = intval($general_setting['options']['wpvivid_common_setting']['restore_max_execution_time']);
561
- }
562
- else{
563
- $restore_max_execution_time = WPVIVID_RESTORE_MAX_EXECUTION_TIME;
564
- }
565
- ?>
566
- <div class="postbox schedule-tab-block setting-page-content">
567
- <div>
568
- <p><strong><?php _e('Enable the option when backup failed.', 'wpvivid-backuprestore'); ?></strong>&nbsp<?php _e('Special optimization for web hosting/shared hosting', 'wpvivid-backuprestore'); ?></p>
569
- <div>
570
- <label>
571
- <input type="checkbox" option="setting" name="subpackage_plugin_upload" <?php esc_attr_e($subpackage_plugin_upload); ?> />
572
- <span><strong><?php _e('Enable optimization mode for web hosting/shared hosting', 'wpvivid-backuprestore'); ?></strong></span>
573
- </label>
574
- <div>
575
- <p><?php _e('Enabling this option can improve the backup success rate, but it will take more time for backup.', 'wpvivid-backuprestore'); ?></p>
576
- </div>
577
- </div>
578
- </div>
579
- </div>
580
- <div class="postbox schedule-tab-block wpvivid-setting-addon" style="margin-bottom: 10px; padding-bottom: 0;">
581
- <div class="wpvivid-element-space-bottom">
582
- <strong><?php _e('Database access method.', 'wpvivid-backuprestore'); ?></strong>
583
- </div>
584
- <div class="wpvivid-element-space-bottom">
585
- <label>
586
- <input type="radio" option="setting" name="db_connect_method" value="wpdb" <?php esc_attr_e($db_method_wpdb); ?> />
587
- <span class="wpvivid-element-space-right"><strong>WPDB</strong></span><span><?php _e('WPDB option has a better compatibility, but the speed of backup and restore is slower.', 'wpvivid-backuprestore'); ?></span>
588
- </label>
589
- </div>
590
- <div class="wpvivid-element-space-bottom">
591
- <label>
592
- <input type="radio" option="setting" name="db_connect_method" value="pdo" <?php esc_attr_e($db_method_pdo); ?> />
593
- <span class="wpvivid-element-space-right"><strong>PDO</strong></span><span><?php _e('It is recommended to choose PDO option if pdo_mysql extension is installed on your server, which lets you backup and restore your site faster.', 'wpvivid-backuprestore'); ?></span>
594
- </label>
595
- </div>
596
- </div>
597
- <div class="postbox schedule-tab-block setting-page-content">
598
- <fieldset>
599
- <label>
600
- <input type="radio" option="setting" name="no_compress" value="1" <?php esc_attr_e($wpvivid_setting_no_compress, 'wpvivid-backuprestore'); ?> />
601
- <span class="wpvivid-element-space-right" title="<?php _e( 'It will cause a lower CPU Usage and is recommended in a web hosting/ shared hosting environment.', 'wpvivid-backuprestore' ); ?>"><?php _e( 'Only Archive without compressing', 'wpvivid-backuprestore' ); ?></span>
602
- </label>
603
- <label>
604
- <input type="radio" option="setting" name="no_compress" value="0" <?php esc_attr_e($wpvivid_setting_compress, 'wpvivid-backuprestore'); ?> />
605
- <span class="wpvivid-element-space-right" title="<?php _e( 'It will cause a higher CPU Usage and is recommended in a VPS/ dedicated hosting environment.', 'wpvivid-backuprestore' ); ?>"><?php _e( 'Compress and Archive', 'wpvivid-backuprestore' ); ?></span>
606
- </label>
607
- <label style="display: none;">
608
- <input type="radio" option="setting" name="compress_type" value="zip" checked />
609
- <input type="radio" option="setting" name="use_temp_file" value="1" checked />
610
- <input type="radio" option="setting" name="use_temp_size" value="16" checked />
611
- </label>
612
- </fieldset>
613
- <div style="padding-top: 10px;">
614
- <div><strong><?php _e('Compress Files Every', 'wpvivid-backuprestore'); ?></strong></div>
615
- <div class="setting-tab-block">
616
- <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-backuprestore'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
617
- <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-backuprestore' ); ?></div></p>
618
- </div>
619
- <div><strong><?php _e('Exclude the files which are larger than', 'wpvivid-backuprestore'); ?></strong></div>
620
- <div class="setting-tab-block">
621
- <input type="text" placeholder="400" option="setting" name="exclude_file_size" id="wpvivid_ignore_large" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_compress_setting']['exclude_file_size'], 'wpvivid-backuprestore'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
622
- <div><p><?php _e( 'Using the option will ignore the file larger than the certain size in MB when backing up, \'0\' (zero) means unlimited.', 'wpvivid-backuprestore' ); ?></p></div>
623
- </div>
624
- <div><strong><?php _e('PHP script execution timeout for backup', 'wpvivid-backuprestore'); ?></strong></div>
625
- <div class="setting-tab-block">
626
- <input type="text" placeholder="600" option="setting" name="max_execution_time" id="wpvivid_option_timeout" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_common_setting']['max_execution_time'], 'wpvivid-backuprestore'); ?>" onkeyup="value=value.replace(/\D/g,'')" />Seconds
627
- <div><p><?php _e( 'The time-out is not your server PHP time-out. With the execution time exhausted, our plugin will shut the process of backup down. If the progress of backup encounters a time-out, that means you have a medium or large sized website, please try to scale the value bigger.', 'wpvivid-backuprestore' ); ?></p></div>
628
- </div>
629
- <div><strong><?php _e('PHP script execution timeout for restore', 'wpvivid-backuprestore'); ?></strong></div>
630
- <div class="setting-tab-block">
631
- <input type="text" placeholder="1800" option="setting" name="restore_max_execution_time" class="all-options" value="<?php esc_attr_e($restore_max_execution_time); ?>" onkeyup="value=value.replace(/\D/g,'')" />Seconds
632
- <div><p><?php _e( 'The time-out is not your server PHP time-out. With the execution time exhausted, our plugin will shut the process of restore down. If the progress of restore encounters a time-out, that means you have a medium or large sized website, please try to scale the value bigger.', 'wpvivid-backuprestore' ); ?></p></div>
633
- </div>
634
- <div><strong><?php _e('PHP Memory Limit for backup', 'wpvivid-backuprestore'); ?></strong></div>
635
- <div class="setting-tab-block">
636
- <input type="text" placeholder="256" option="setting" name="memory_limit" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_common_setting']['memory_limit']), 'wpvivid-backuprestore'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
637
- <div><p><?php _e('Adjust this value to apply for a temporary PHP memory limit for WPvivid backup plugin to run a backup. We set this value to 256M by default. Increase the value if you encounter a memory exhausted error. Note: some web hosting providers may not support this.', 'wpvivid-backuprestore'); ?></p></div>
638
- </div>
639
- <div><strong><?php _e('PHP Memory Limit for restoration', 'wpvivid-backuprestore'); ?></strong></div>
640
- <div class="setting-tab-block">
641
- <input type="text" placeholder="256" option="setting" name="restore_memory_limit" class="all-options" value="<?php esc_attr_e(str_replace('M', '', $general_setting['options']['wpvivid_common_setting']['restore_memory_limit']), 'wpvivid-backuprestore'); ?>" onkeyup="value=value.replace(/\D/g,'')" />MB
642
- <div><p><?php _e('Adjust this value to apply for a temporary PHP memory limit for WPvivid backup plugin in restore process. We set this value to 256M by default. Increase the value if you encounter a memory exhausted error. Note: some web hosting providers may not support this.', 'wpvivid-backuprestore'); ?></p></div>
643
- </div>
644
- <div><strong><?php _e('Chunk Size', 'wpvivid-backuprestore'); ?></strong></div>
645
- <div class="setting-tab-block">
646
- <input type="text" placeholder="2" option="setting" name="migrate_size" class="all-options" value="<?php esc_attr_e($general_setting['options']['wpvivid_common_setting']['migrate_size']); ?>" onkeyup="value=value.replace(/\D/g,'')" />KB
647
- <div><p><?php _e('e.g.  if you choose a chunk size of 2MB, a 8MB file will use 4 chunks. Decreasing this value will break the ISP\'s transmission limit, for example:512KB', 'wpvivid-backuprestore'); ?></p></div>
648
- </div>
649
- <div>
650
- <?php
651
- $max_count_option = '';
652
- for($resume_count=3; $resume_count<10; $resume_count++){
653
- if($resume_count === $wpvivid_max_resume_count){
654
- $max_count_option .= '<option selected="selected" value="'.$resume_count.'">'.$resume_count.'</option>';
655
- }
656
- else{
657
- $max_count_option .= '<option value="'.$resume_count.'">'.$resume_count.'</option>';
658
- }
659
- }
660
- $max_count_select = '<select option="setting" name="max_resume_count">'.$max_count_option.'</select>';
661
- echo sprintf(__('<strong>Retrying </strong>%s<strong> times when encountering a time-out error</strong>', 'wpvivid-backuprestore'), $max_count_select);
662
- ?>
663
- </div>
664
- </div>
665
- </div>
666
- <?php
667
- }
668
-
669
- function wpvivid_add_setting_tab_page($setting_array){
670
- $setting_array['general_setting'] = array('index' => '1', 'tab_func' => 'wpvivid_settingpage_add_tab_general', 'page_func' => 'wpvivid_settingpage_add_page_general');
671
- $setting_array['advance_setting'] = array('index' => '2', 'tab_func' => 'wpvivid_settingpage_add_tab_advance', 'page_func' => 'wpvivid_settingpage_add_page_advance');
672
- return $setting_array;
673
- }
674
-
675
- function wpvivid_settingpage_add_tab_general(){
676
- ?>
677
- <a href="#" id="wpvivid_tab_general_setting" class="nav-tab setting-nav-tab nav-tab-active" onclick="switchsettingTabs(event,'page-general-setting')"><?php _e('General Settings', 'wpvivid-backuprestore'); ?></a>
678
- <?php
679
- }
680
-
681
- function wpvivid_settingpage_add_tab_advance(){
682
- ?>
683
- <a href="#" id="wpvivid_tab_advance_setting" class="nav-tab setting-nav-tab" onclick="switchsettingTabs(event,'page-advance-setting')"><?php _e('Advanced Settings', 'wpvivid-backuprestore'); ?></a>
684
- <?php
685
- }
686
-
687
- function wpvivid_settingpage_add_page_general(){
688
- ?>
689
- <div class="setting-tab-content wpvivid_tab_general_setting" id="page-general-setting" style="margin-top: 10px;">
690
- <?php do_action('wpvivid_setting_add_general_cell'); ?>
691
- </div>
692
- <?php
693
- }
694
-
695
- function wpvivid_settingpage_add_page_advance(){
696
- ?>
697
- <div class="setting-tab-content wpvivid_tab_advance_setting" id="page-advance-setting" style="margin-top: 10px; display: none;">
698
- <?php do_action('wpvivid_setting_add_advance_cell'); ?>
699
- </div>
700
- <?php
701
- }
702
-
703
- add_filter('wpvivid_add_setting_tab_page', 'wpvivid_add_setting_tab_page', 10);
704
-
705
- add_action('wpvivid_setting_add_general_cell','wpvivid_general_settings',10);
706
- add_action('wpvivid_setting_add_advance_cell','wpvivid_advanced_settings',13);
707
- add_action('wpvivid_setting_add_general_cell','wpvivid_email_report',14);
708
- add_action('wpvivid_setting_add_general_cell','wpvivid_clean_junk',15);
709
- add_action('wpvivid_setting_add_general_cell','wpvivid_export_import_settings',16);
710
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/admin/partials/wpvivid-website-info-page-display.php DELETED
@@ -1,35 +0,0 @@
1
- <script>
2
- function wpvivid_get_ini_memory_limit() {
3
- var ajax_data = {
4
- 'action': 'wpvivid_get_ini_memory_limit'
5
- };
6
- wpvivid_post_request(ajax_data, function (data) {
7
- try {
8
- jQuery('#wpvivid_websiteinfo_list tr').each(function (i) {
9
- jQuery(this).children('td').each(function (j) {
10
- if (j == 0) {
11
- if (jQuery(this).html().indexOf('memory_limit') >= 0) {
12
- jQuery(this).next().html(data);
13
- }
14
- }
15
- });
16
- });
17
- }
18
- catch (err) {
19
- setTimeout(function ()
20
- {
21
- wpvivid_get_ini_memory_limit();
22
- }, 3000);
23
- }
24
- }, function (XMLHttpRequest, textStatus, errorThrown) {
25
- setTimeout(function ()
26
- {
27
- wpvivid_get_ini_memory_limit();
28
- }, 3000);
29
- });
30
- }
31
- jQuery(document).ready(function ()
32
- {
33
- wpvivid_get_ini_memory_limit();
34
- });
35
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-additional-db-method.php DELETED
@@ -1,255 +0,0 @@
1
- <?php
2
-
3
- class WPvivid_Additional_DB_Method
4
- {
5
- private $dbuser;
6
- private $dbpass;
7
- private $dbhost;
8
- private $use_mysqli = false;
9
- private $dbh;
10
- private $has_connected = false;
11
- public $charset;
12
- public $collate;
13
-
14
- public function __construct($dbuser, $dbpass, $dbhost){
15
- $this->dbuser = $dbuser;
16
- $this->dbpass = $dbpass;
17
- $this->dbhost = $dbhost;
18
-
19
- if ( function_exists( 'mysqli_connect' ) ) {
20
- $this->use_mysqli = true;
21
-
22
- if ( defined( 'WP_USE_EXT_MYSQL' ) ) {
23
- $this->use_mysqli = ! WP_USE_EXT_MYSQL;
24
- }
25
- }
26
- }
27
-
28
- public function wpvivid_parse_db_host( $host ) {
29
- $port = null;
30
- $socket = null;
31
- $is_ipv6 = false;
32
-
33
- // First peel off the socket parameter from the right, if it exists.
34
- $socket_pos = strpos( $host, ':/' );
35
- if ( $socket_pos !== false ) {
36
- $socket = substr( $host, $socket_pos + 1 );
37
- $host = substr( $host, 0, $socket_pos );
38
- }
39
-
40
- // We need to check for an IPv6 address first.
41
- // An IPv6 address will always contain at least two colons.
42
- if ( substr_count( $host, ':' ) > 1 ) {
43
- $pattern = '#^(?:\[)?(?P<host>[0-9a-fA-F:]+)(?:\]:(?P<port>[\d]+))?#';
44
- $is_ipv6 = true;
45
- } else {
46
- // We seem to be dealing with an IPv4 address.
47
- $pattern = '#^(?P<host>[^:/]*)(?::(?P<port>[\d]+))?#';
48
- }
49
-
50
- $matches = array();
51
- $result = preg_match( $pattern, $host, $matches );
52
-
53
- if ( 1 !== $result ) {
54
- // Couldn't parse the address, bail.
55
- return false;
56
- }
57
-
58
- $host = '';
59
- foreach ( array( 'host', 'port' ) as $component ) {
60
- if ( ! empty( $matches[ $component ] ) ) {
61
- $$component = $matches[ $component ];
62
- }
63
- }
64
-
65
- return array( $host, $port, $socket, $is_ipv6 );
66
- }
67
-
68
- public function db_version() {
69
- if ( $this->use_mysqli ) {
70
- $server_info = mysqli_get_server_info( $this->dbh );
71
- } else {
72
- $server_info = mysql_get_server_info( $this->dbh );
73
- }
74
- return preg_replace( '/[^0-9.].*/', '', $server_info );
75
- }
76
-
77
- public function has_cap( $db_cap ) {
78
- $version = $this->db_version();
79
-
80
- switch ( strtolower( $db_cap ) ) {
81
- case 'collation': // @since 2.5.0
82
- case 'group_concat': // @since 2.7.0
83
- case 'subqueries': // @since 2.7.0
84
- return version_compare( $version, '4.1', '>=' );
85
- case 'set_charset':
86
- return version_compare( $version, '5.0.7', '>=' );
87
- case 'utf8mb4': // @since 4.1.0
88
- if ( version_compare( $version, '5.5.3', '<' ) ) {
89
- return false;
90
- }
91
- if ( $this->use_mysqli ) {
92
- $client_version = mysqli_get_client_info();
93
- } else {
94
- $client_version = mysql_get_client_info();
95
- }
96
-
97
- /*
98
- * libmysql has supported utf8mb4 since 5.5.3, same as the MySQL server.
99
- * mysqlnd has supported utf8mb4 since 5.0.9.
100
- */
101
- if ( false !== strpos( $client_version, 'mysqlnd' ) ) {
102
- $client_version = preg_replace( '/^\D+([\d.]+).*/', '$1', $client_version );
103
- return version_compare( $client_version, '5.0.9', '>=' );
104
- } else {
105
- return version_compare( $client_version, '5.5.3', '>=' );
106
- }
107
- case 'utf8mb4_520': // @since 4.6.0
108
- return version_compare( $version, '5.6', '>=' );
109
- }
110
-
111
- return false;
112
- }
113
-
114
- public function determine_charset( $charset, $collate ) {
115
- if ( ( $this->use_mysqli && ! ( $this->dbh instanceof mysqli ) ) || empty( $this->dbh ) ) {
116
- return compact( 'charset', 'collate' );
117
- }
118
-
119
- if ( 'utf8' === $charset && $this->has_cap( 'utf8mb4' ) ) {
120
- $charset = 'utf8mb4';
121
- }
122
-
123
- if ( 'utf8mb4' === $charset && ! $this->has_cap( 'utf8mb4' ) ) {
124
- $charset = 'utf8';
125
- $collate = str_replace( 'utf8mb4_', 'utf8_', $collate );
126
- }
127
-
128
- if ( 'utf8mb4' === $charset ) {
129
- // _general_ is outdated, so we can upgrade it to _unicode_, instead.
130
- if ( ! $collate || 'utf8_general_ci' === $collate ) {
131
- $collate = 'utf8mb4_unicode_ci';
132
- } else {
133
- $collate = str_replace( 'utf8_', 'utf8mb4_', $collate );
134
- }
135
- }
136
-
137
- // _unicode_520_ is a better collation, we should use that when it's available.
138
- if ( $this->has_cap( 'utf8mb4_520' ) && 'utf8mb4_unicode_ci' === $collate ) {
139
- $collate = 'utf8mb4_unicode_520_ci';
140
- }
141
-
142
- return compact( 'charset', 'collate' );
143
- }
144
-
145
- public function init_charset() {
146
- $charset = '';
147
- $collate = '';
148
-
149
- if ( function_exists( 'is_multisite' ) && is_multisite() ) {
150
- $charset = 'utf8';
151
- if ( defined( 'DB_COLLATE' ) && DB_COLLATE ) {
152
- $collate = DB_COLLATE;
153
- } else {
154
- $collate = 'utf8_general_ci';
155
- }
156
- } elseif ( defined( 'DB_COLLATE' ) ) {
157
- $collate = DB_COLLATE;
158
- }
159
-
160
- if ( defined( 'DB_CHARSET' ) ) {
161
- $charset = DB_CHARSET;
162
- }
163
-
164
- $charset_collate = $this->determine_charset( $charset, $collate );
165
-
166
- $this->charset = $charset_collate['charset'];
167
- $this->collate = $charset_collate['collate'];
168
- }
169
-
170
- public function wpvivid_do_connect($allow_bail = true){
171
- $new_link = defined( 'MYSQL_NEW_LINK' ) ? MYSQL_NEW_LINK : true;
172
- $client_flags = defined( 'MYSQL_CLIENT_FLAGS' ) ? MYSQL_CLIENT_FLAGS : 0;
173
-
174
- $error_code = '';
175
- $error = 'Unknown Error.';
176
-
177
- if ( $this->use_mysqli ) {
178
- $this->dbh = mysqli_init();
179
-
180
- $host = $this->dbhost;
181
- $port = null;
182
- $socket = null;
183
- $is_ipv6 = false;
184
-
185
- if ( $host_data = $this->wpvivid_parse_db_host( $this->dbhost ) ) {
186
- list( $host, $port, $socket, $is_ipv6 ) = $host_data;
187
- }
188
-
189
- if ( $is_ipv6 && extension_loaded( 'mysqlnd' ) ) {
190
- $host = "[$host]";
191
- }
192
-
193
- @mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpass, null, $port, $socket, $client_flags );
194
-
195
- if ( $this->dbh->connect_errno ) {
196
- $error_code = $this->dbh->connect_errno;
197
- $error = $this->dbh->connect_error;
198
- $this->dbh = null;
199
- $attempt_fallback = true;
200
-
201
- if ( $this->has_connected ) {
202
- $attempt_fallback = false;
203
- } elseif ( defined( 'WP_USE_EXT_MYSQL' ) && ! WP_USE_EXT_MYSQL ) {
204
- $attempt_fallback = false;
205
- } elseif ( ! function_exists( 'mysql_connect' ) ) {
206
- $attempt_fallback = false;
207
- }
208
-
209
- if ( $attempt_fallback ) {
210
- $this->use_mysqli = false;
211
- return $this->wpvivid_do_connect( $allow_bail );
212
- }
213
- }
214
- }
215
- else{
216
- $this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpass, $new_link, $client_flags );
217
- }
218
-
219
- if($this->dbh){
220
- $this->has_connected = true;
221
- $ret['result'] = WPVIVID_SUCCESS;
222
- }
223
- else{
224
- $ret['result'] = WPVIVID_FAILED;
225
- $ret['error'] = $error_code.': '.$error;
226
- }
227
-
228
- return $ret;
229
- }
230
-
231
- public function wpvivid_show_additional_databases(){
232
- $query = 'SHOW DATABASES;';
233
- $result = '';
234
- if ( ! empty( $this->dbh ) && $this->use_mysqli ) {
235
- $result = mysqli_query( $this->dbh, $query );
236
- } elseif ( ! empty( $this->dbh ) ) {
237
- $result = mysql_query( $query, $this->dbh );
238
- }
239
- if ( $this->use_mysqli && $result instanceof mysqli_result ) {
240
- while ( $row = mysqli_fetch_object( $result ) ) {
241
- $database_array[] = $row;
242
- }
243
- } elseif ( is_resource( $result ) ) {
244
- while ( $row = mysql_fetch_object( $result ) ) {
245
- $database_array[] = $row;
246
- }
247
- }
248
- if(!empty($database_array)){
249
- foreach ($database_array as $key => $value){
250
- $last_result[] = $value->Database;
251
- }
252
- }
253
- return $last_result;
254
- }
255
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-backup-database.php DELETED
@@ -1,149 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
- define('NECESSARY','1');
7
- define('OPTION','0');
8
- class WPvivid_Backup_Database
9
- {
10
- private $task_id;
11
-
12
- public function __construct()
13
- {
14
- }
15
-
16
- public function wpvivid_archieve_database_info($databases, $data)
17
- {
18
- if(isset($data['dump_db']))
19
- {
20
- $sql_info['file_name'] =$data['sql_file_name'];
21
- $sql_info['database'] = DB_NAME;
22
- $sql_info['host'] = DB_HOST;
23
- $sql_info['user'] = DB_USER;
24
- $sql_info['pass'] = DB_PASSWORD;
25
- $databases[] = $sql_info;
26
- }
27
- return $databases;
28
- }
29
-
30
- public function backup_database($data,$task_id = '')
31
- {
32
- global $wpvivid_plugin;
33
- $dump=null;
34
-
35
- try
36
- {
37
- $this->task_id=$task_id;
38
-
39
- //$backup_file =$data['sql_file_name'];
40
-
41
- require_once 'class-wpvivid-mysqldump-method.php';
42
- require_once 'class-wpvivid-mysqldump.php';
43
-
44
- $db_method=new WPvivid_DB_Method();
45
- $version =$db_method->get_mysql_version();
46
-
47
- if(version_compare('4.1.0',$version) > 0)
48
- {
49
- return array('result'=>WPVIVID_FAILED,'error'=>'Your MySQL version is too old. Please upgrade at least to MySQL 4.1.0.');
50
- }
51
-
52
- if(version_compare('5.3.0',phpversion()) > 0){
53
- return array('result'=>WPVIVID_FAILED,'error'=>'Your PHP version is too old. Please upgrade at least to PHP 5.3.0.');
54
- }
55
-
56
- $db_method->check_max_allowed_packet();
57
- add_filter('wpvivid_exclude_db_table', array($this, 'exclude_table'),10,2);
58
- $exclude=array();
59
- $exclude = apply_filters('wpvivid_exclude_db_table',$exclude, $data);
60
- $include=array();
61
- $include = apply_filters('wpvivid_include_db_table',$include, $data);
62
-
63
- $site_url = apply_filters('wpvivid_dump_set_site_url',get_site_url(), $data);
64
- $home_url = apply_filters('wpvivid_dump_set_home_url',get_home_url(), $data);
65
- $content_url=apply_filters('wpvivid_dump_set_content_url',content_url(), $data);
66
-
67
- global $wpdb;
68
- if (is_multisite() && !defined('MULTISITE'))
69
- {
70
- $prefix = $wpdb->base_prefix;
71
- } else {
72
- $prefix = $wpdb->get_blog_prefix(0);
73
- }
74
- $prefix=apply_filters('wpvivid_dump_set_prefix',$prefix, $data);
75
-
76
- add_filter('wpvivid_archieve_database_info', array($this, 'wpvivid_archieve_database_info'), 10, 2);
77
- $databases=array();
78
- $databases = apply_filters('wpvivid_archieve_database_info', $databases, $data);
79
- $is_additional_db = false;
80
- if($data['key'] === 'backup_additional_db')
81
- {
82
- $is_additional_db = true;
83
- }
84
-
85
- $backup_files = array();
86
- foreach ($databases as $sql_info)
87
- {
88
- $database_name = $sql_info['database'];
89
- $backup_file = $sql_info['file_name'];
90
- $backup_files[] = $backup_file;
91
- $host = $sql_info['host'];
92
- $user = $sql_info['user'];
93
- $pass = $sql_info['pass'];
94
-
95
- $dumpSettings=array();
96
- $dumpSettings['exclude-tables']=$exclude;
97
- $dumpSettings['include-tables']=$include;
98
- $dumpSettings['add-drop-table']=true;
99
- $dumpSettings['extended-insert']=false;
100
-
101
- $dumpSettings['site_url']=$site_url;
102
- $dumpSettings['home_url']=$home_url;
103
- $dumpSettings['content_url']=$content_url;
104
- $dumpSettings['prefix']=$prefix;
105
-
106
- $dump = new WPvivid_Mysqldump($host, $database_name, $user, $pass, $is_additional_db, $dumpSettings);
107
-
108
- if (file_exists($backup_file))
109
- @unlink($backup_file);
110
-
111
- $dump->task_id=$task_id;
112
- $dump->start($backup_file);
113
- }
114
-
115
- unset($pdo);
116
- }
117
- catch (Exception $e)
118
- {
119
- $str_last_query_string='';
120
- if(!is_null($dump))
121
- {
122
- $str_last_query_string=$dump->last_query_string;
123
- }
124
- if(!empty($str_last_query_string))
125
- {
126
- $wpvivid_plugin->wpvivid_log->WriteLog('last query string:'.$str_last_query_string,'error');
127
- }
128
- $message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
129
- return array('result'=>WPVIVID_FAILED,'error'=>$message);
130
- }
131
-
132
- $files = array();
133
- $files = $backup_files;
134
- return array('result'=>WPVIVID_SUCCESS,'files'=>$files);
135
- }
136
-
137
- public function exclude_table($exclude,$data)
138
- {
139
- global $wpdb;
140
- if (is_multisite() && !defined('MULTISITE'))
141
- {
142
- $prefix = $wpdb->base_prefix;
143
- } else {
144
- $prefix = $wpdb->get_blog_prefix(0);
145
- }
146
- $exclude = array('/^(?!' . $prefix . ')/i');
147
- return $exclude;
148
- }
149
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-backup-site.php DELETED
@@ -1,52 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
- require_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-zipclass.php';
7
- class WPvivid_Backup_Site
8
- {
9
- private $tools_collection=array();
10
-
11
- public function __construct()
12
- {
13
- add_filter('wpvivid_tools_register', array($this, 'init_tools'),10);
14
- $this->tools_collection=apply_filters('wpvivid_tools_register',$this->tools_collection);
15
- $this->load_hooks();
16
- }
17
-
18
- public function init_tools($tools_collection){
19
- $tools_collection['zip'][WPVIVID_COMPRESS_ZIPCLASS] = 'WPvivid_ZipClass';
20
- return $tools_collection;
21
- }
22
-
23
- public function get_tools($type){
24
- if(array_key_exists($type,$this->tools_collection))
25
- {
26
- foreach ($this -> tools_collection[$type] as $class_name){
27
- if(class_exists($class_name)){
28
- $object = new $class_name();
29
- $last_error = $object -> getLastError();
30
- if(empty($last_error))
31
- return $object;
32
- }
33
- }
34
- }
35
- $class_name = $this -> tools_collection['zip'][WPVIVID_COMPRESS_ZIPCLASS];
36
- $object = new $class_name();
37
- $last_error = $object -> getLastError();
38
- if(empty($last_error)){
39
- return $object;
40
- }else{
41
- return array('result' => WPVIVID_FAILED,'error' => $last_error);
42
- }
43
- }
44
-
45
- public function load_hooks(){
46
- foreach ($this -> tools_collection as $compressType){
47
- foreach ($compressType as $className){
48
- $object = new $className();
49
- }
50
- }
51
- }
52
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-backup-uploader.php DELETED
@@ -1,792 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR'))
4
- {
5
- die;
6
- }
7
-
8
- class Wpvivid_BackupUploader
9
- {
10
- public function __construct()
11
- {
12
- add_action('wp_ajax_wpvivid_get_file_id',array($this,'get_file_id'));
13
- add_action('wp_ajax_wpvivid_upload_files',array($this,'upload_files'));
14
- add_action('wp_ajax_wpvivid_upload_files_finish',array($this,'upload_files_finish'));
15
-
16
- add_action('wp_ajax_wpvivid_rescan_local_folder',array($this,'rescan_local_folder_set_backup'));
17
- add_action('wp_ajax_wpvivid_get_backup_count',array($this,'get_backup_count'));
18
- add_action('wpvivid_rebuild_backup_list', array($this, 'wpvivid_rebuild_backup_list'), 10);
19
- }
20
-
21
- function get_file_id()
22
- {
23
- global $wpvivid_plugin;
24
- $wpvivid_plugin->ajax_check_security();
25
- if(isset($_POST['file_name']))
26
- {
27
- if(preg_match('/wpvivid-.*_.*_.*\.zip$/',$_POST['file_name']))
28
- {
29
- if(preg_match('/wpvivid-(.*?)_/',$_POST['file_name'],$matches))
30
- {
31
- $id= $matches[0];
32
- $id=substr($id,0,strlen($id)-1);
33
- if(WPvivid_Backuplist::get_backup_by_id($id)===false)
34
- {
35
- $ret['result']=WPVIVID_SUCCESS;
36
- $ret['id']=$id;
37
- }
38
- else
39
- {
40
- $ret['result']=WPVIVID_FAILED;
41
- $ret['error']='The uploading backup already exists in Backups list.';
42
- }
43
- }
44
- else
45
- {
46
- $ret['result']=WPVIVID_FAILED;
47
- $ret['error']=$_POST['file_name'] . ' is not created by WPvivid backup plugin.';
48
- }
49
- }
50
- else
51
- {
52
- $ret['result']=WPVIVID_FAILED;
53
- $ret['error']=$_POST['file_name'] . ' is not created by WPvivid backup plugin.';
54
- }
55
- }
56
- else
57
- {
58
- $ret['result']=WPVIVID_FAILED;
59
- $ret['error']='Failed to post file name.';
60
- }
61
-
62
- echo json_encode($ret);
63
- die();
64
- }
65
-
66
- function check_file_is_a_wpvivid_backup($file_name,&$backup_id)
67
- {
68
- if(preg_match('/wpvivid-.*_.*_.*\.zip$/',$file_name))
69
- {
70
- if(preg_match('/wpvivid-(.*?)_/',$file_name,$matches))
71
- {
72
- $id= $matches[0];
73
- $id=substr($id,0,strlen($id)-1);
74
-
75
-
76
- if(WPvivid_Backuplist::get_backup_by_id($id)===false)
77
- {
78
- $backup_id=$id;
79
- return true;
80
- }
81
- else
82
- {
83
- return false;
84
- }
85
- }
86
- else
87
- {
88
- return false;
89
- }
90
- }
91
- else
92
- {
93
- return false;
94
- }
95
- }
96
-
97
- function upload_files()
98
- {
99
- global $wpvivid_plugin;
100
- $wpvivid_plugin->ajax_check_security();
101
- $options['test_form'] =true;
102
- $options['action'] ='wpvivid_upload_files';
103
- $options['test_type'] = false;
104
- $options['ext'] = 'zip';
105
- $options['type'] = 'application/zip';
106
-
107
- add_filter('upload_dir', array($this, 'upload_dir'));
108
-
109
- $status = wp_handle_upload($_FILES['async-upload'],$options);
110
-
111
- remove_filter('upload_dir', array($this, 'upload_dir'));
112
-
113
- if (isset($status['error']))
114
- {
115
- echo json_encode(array('result'=>WPVIVID_FAILED, 'error' => $status['error']));
116
- exit;
117
- }
118
-
119
- $file_name=basename($_POST['name']);
120
-
121
- if (isset($_POST['chunks']) && isset($_POST['chunk']))
122
- {
123
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
124
- rename($status['file'],$path.$file_name.'_'.$_POST['chunk'].'.tmp');
125
- $status['file'] = $path.$file_name.'_'.$_POST['chunk'].'.tmp';
126
- if($_POST['chunk'] == $_POST['chunks']-1)
127
- {
128
- $file_handle = fopen($path.$file_name, 'wb');
129
- if ($file_handle)
130
- {
131
- for ($i=0; $i<$_POST['chunks']; $i++)
132
- {
133
- $chunks_handle=fopen($path.$file_name.'_'.$i.'.tmp','rb');
134
- if($chunks_handle)
135
- {
136
- while ($line = fread($chunks_handle, 1048576*2))
137
- {
138
- fwrite($file_handle, $line);
139
- }
140
- fclose($chunks_handle);
141
- @unlink($path.$file_name.'_'.$i.'.tmp');
142
- }
143
- }
144
- fclose($file_handle);
145
- }
146
- }
147
- }
148
- echo json_encode(array('result'=>WPVIVID_SUCCESS));
149
- die();
150
- }
151
-
152
- function upload_files_finish()
153
- {
154
- global $wpvivid_plugin;
155
- $wpvivid_plugin->ajax_check_security();
156
-
157
- $ret['html']=false;
158
- if(isset($_POST['files']))
159
- {
160
- $files =stripslashes($_POST['files']);
161
- $files =json_decode($files,true);
162
- if(is_null($files))
163
- {
164
- die();
165
- }
166
-
167
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
168
-
169
- $backup_data['result']='success';
170
- $backup_data['files']=array();
171
- if(preg_match('/wpvivid-.*_.*_.*\.zip$/',$files[0]['name']))
172
- {
173
- if(preg_match('/wpvivid-(.*?)_/',$files[0]['name'],$matches_id))
174
- {
175
- if(preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}/',$files[0]['name'],$matches))
176
- {
177
- $backup_time=$matches[0];
178
- $time_array=explode('-',$backup_time);
179
- if(sizeof($time_array)>4)
180
- $time=$time_array[0].'-'.$time_array[1].'-'.$time_array[2].' '.$time_array[3].':'.$time_array[4];
181
- else
182
- $time=$backup_time;
183
- $time=strtotime($time);
184
- }
185
- else
186
- {
187
- $time=time();
188
- }
189
- $id= $matches_id[0];
190
- $id=substr($id,0,strlen($id)-1);
191
- $unlinked_file = '';
192
- $check_result=true;
193
- foreach ($files as $file)
194
- {
195
- $res=$this->check_is_a_wpvivid_backup($path.$file['name']);
196
- if($res === true)
197
- {
198
- $add_file['file_name']=$file['name'];
199
- $add_file['size']=filesize($path.$file['name']);
200
- $backup_data['files'][]=$add_file;
201
- }
202
- else
203
- {
204
- $check_result=false;
205
- $unlinked_file .= 'file name: '.$file['name'].', error: '.$res;
206
- }
207
- }
208
- if($check_result === true){
209
- WPvivid_Backuplist::add_new_upload_backup($id,$backup_data,$time,'');
210
- $html = '';
211
- $html = apply_filters('wpvivid_add_backup_list', $html);
212
- $ret['result']=WPVIVID_SUCCESS;
213
- $ret['html'] = $html;
214
- }
215
- else{
216
- foreach ($files as $file) {
217
- $this->clean_tmp_files($path, $file['name']);
218
- @unlink($path . $file['name']);
219
- }
220
- $ret['result']=WPVIVID_FAILED;
221
- $ret['error']='Upload file failed.';
222
- $ret['unlinked']=$unlinked_file;
223
- }
224
- }
225
- else
226
- {
227
- $ret['result']=WPVIVID_FAILED;
228
- $ret['error']='The backup is not created by WPvivid backup plugin.';
229
- }
230
- }
231
- else
232
- {
233
- $ret['result']=WPVIVID_FAILED;
234
- $ret['error']='The backup is not created by WPvivid backup plugin.';
235
- }
236
- }
237
- else{
238
- $ret['result']=WPVIVID_FAILED;
239
- $ret['error']='Failed to post file name.';
240
- }
241
- echo json_encode($ret);
242
- die();
243
- }
244
-
245
- function clean_tmp_files($path, $filename){
246
- $handler=opendir($path);
247
- if($handler===false)
248
- return;
249
- while(($file=readdir($handler))!==false) {
250
- if (!is_dir($path.$file) && preg_match('/wpvivid-.*_.*_.*\.tmp$/', $file)) {
251
- $iPos = strrpos($file, '_');
252
- $file_temp = substr($file, 0, $iPos);
253
- if($file_temp === $filename) {
254
- @unlink($path.$file);
255
- }
256
- }
257
- }
258
- @closedir($handler);
259
- }
260
-
261
- function wpvivid_check_remove_update_backup($path){
262
- $backup_list = WPvivid_Setting::get_option('wpvivid_backup_list');
263
- $remove_backup_array = array();
264
- $update_backup_array = array();
265
- $tmp_file_array = array();
266
- $remote_backup_list=WPvivid_Backuplist::get_has_remote_backuplist();
267
- foreach ($backup_list as $key => $value){
268
- if(!in_array($key, $remote_backup_list)) {
269
- $need_remove = true;
270
- $need_update = false;
271
- if (is_dir($path)) {
272
- $handler = opendir($path);
273
- if($handler===false)
274
- return true;
275
- while (($filename = readdir($handler)) !== false) {
276
- if ($filename != "." && $filename != "..") {
277
- if (!is_dir($path . $filename)) {
278
- if ($this->check_wpvivid_file_info($filename, $backup_id, $need_update)) {
279
- if ($key === $backup_id) {
280
- $need_remove = false;
281
- }
282
- if ($need_update) {
283
- if ($this->check_is_a_wpvivid_backup($path . $filename) === true) {
284
- if (!in_array($filename, $tmp_file_array)) {
285
- $add_file['file_name'] = $filename;
286
- $add_file['size'] = filesize($path . $filename);
287
- $tmp_file_array[] = $filename;
288
- $update_backup_array[$backup_id]['files'][] = $add_file;
289
- }
290
- }
291
- }
292
- }
293
- }
294
- }
295
- }
296
- if ($handler) {
297
- @closedir($handler);
298
- }
299
- }
300
- if ($need_remove) {
301
- $remove_backup_array[] = $key;
302
- }
303
- }
304
- }
305
- $this->wpvivid_remove_update_local_backup_list($remove_backup_array, $update_backup_array);
306
- return true;
307
- }
308
-
309
- function check_wpvivid_file_info($file_name, &$backup_id, &$need_update=false){
310
- if(preg_match('/wpvivid-.*_.*_.*\.zip$/',$file_name))
311
- {
312
- if(preg_match('/wpvivid-(.*?)_/',$file_name,$matches))
313
- {
314
- $id= $matches[0];
315
- $id=substr($id,0,strlen($id)-1);
316
- $backup_id=$id;
317
-
318
- if(WPvivid_Backuplist::get_backup_by_id($id)===false)
319
- {
320
- $need_update = false;
321
- return true;
322
- }
323
- else
324
- {
325
- $need_update = true;
326
- return true;
327
- }
328
- }
329
- else
330
- {
331
- return false;
332
- }
333
- }
334
- else
335
- {
336
- return false;
337
- }
338
- }
339
-
340
- function wpvivid_remove_update_local_backup_list($remove_backup_array, $update_backup_array){
341
- $backup_list = WPvivid_Setting::get_option('wpvivid_backup_list');
342
- foreach ($remove_backup_array as $remove_backup_id){
343
- unset($backup_list[$remove_backup_id]);
344
- }
345
- foreach ($update_backup_array as $update_backup_id => $data){
346
- $backup_list[$update_backup_id]['backup']['files'] = $data['files'];
347
- }
348
- WPvivid_Setting::update_option('wpvivid_backup_list', $backup_list);
349
- }
350
-
351
- function _rescan_local_folder_set_backup(){
352
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR;
353
-
354
- $this->wpvivid_check_remove_update_backup($path);
355
-
356
- $backups=array();
357
- $count = 0;
358
- if(is_dir($path))
359
- {
360
- $handler = opendir($path);
361
- if($handler!==false)
362
- {
363
- while (($filename = readdir($handler)) !== false)
364
- {
365
- if ($filename != "." && $filename != "..")
366
- {
367
- $count++;
368
-
369
- if (is_dir($path . $filename))
370
- {
371
- continue;
372
- } else {
373
- if($this->check_file_is_a_wpvivid_backup($filename,$backup_id))
374
- {
375
- if($this->zip_check_sum($path . $filename))
376
- {
377
- if($this->check_is_a_wpvivid_backup($path.$filename) === true)
378
- $backups[$backup_id]['files'][]=$filename;
379
- }
380
- }
381
- }
382
- }
383
- }
384
- if($handler)
385
- @closedir($handler);
386
- }
387
- }
388
- else{
389
- $ret['result']=WPVIVID_FAILED;
390
- $ret['error']='Failed to get local storage directory.';
391
- }
392
- if(!empty($backups))
393
- {
394
- foreach ($backups as $backup_id =>$backup)
395
- {
396
- $backup_data['result']='success';
397
- $backup_data['files']=array();
398
- if(empty($backup['files']))
399
- continue;
400
- $time=false;
401
- foreach ($backup['files'] as $file)
402
- {
403
- if($time===false)
404
- {
405
- if(preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}-[0-9]{2}-[0-9]{2}/',$file,$matches))
406
- {
407
- $backup_time=$matches[0];
408
- $time_array=explode('-',$backup_time);
409
- if(sizeof($time_array)>4)
410
- $time=$time_array[0].'-'.$time_array[1].'-'.$time_array[2].' '.$time_array[3].':'.$time_array[4];
411
- else
412
- $time=$backup_time;
413
- $time=strtotime($time);
414
- }
415
- else
416
- {
417
- $time=time();
418
- }
419
- }
420
-
421
- $add_file['file_name']=$file;
422
- $add_file['size']=filesize($path.$file);
423
- $backup_data['files'][]=$add_file;
424
- }
425
-
426
- WPvivid_Backuplist::add_new_upload_backup($backup_id,$backup_data,$time,'');
427
- }
428
- }
429
- $ret['result']=WPVIVID_SUCCESS;
430
- $html = '';
431
- $tour = true;
432
- $html = apply_filters('wpvivid_add_backup_list', $html, 'wpvivid_backup_list', $tour);
433
- $ret['html'] = $html;
434
- return $ret;
435
- }
436
-
437
- function rescan_local_folder_set_backup()
438
- {
439
- global $wpvivid_plugin;
440
- $wpvivid_plugin->ajax_check_security();
441
-
442
- $ret = $this->_rescan_local_folder_set_backup();
443
- echo json_encode($ret);
444
- die();
445
- }
446
-
447
- public function wpvivid_rebuild_backup_list(){
448
- $this->_rescan_local_folder_set_backup();
449
- }
450
-
451
- static function rescan_local_folder()
452
- {
453
- $backupdir=WPvivid_Setting::get_backupdir();
454
- ?>
455
- <div style="padding-top: 10px;">
456
- <span><?php _e('Tips: Click the button below to scan all uploaded or received backups in directory', 'wpvivid-backuprestore'); ?>&nbsp<?php echo WP_CONTENT_DIR.'/'.$backupdir; ?></span>
457
- </div>
458
- <div style="padding-top: 10px;">
459
- <input type="submit" class="button-primary" value="<?php esc_attr_e('Scan uploaded backup or received backup', 'wpvivid-backuprestore'); ?>" onclick="wpvivid_rescan_local_folder();" />
460
- </div>
461
- <script type="text/javascript">
462
- function wpvivid_rescan_local_folder()
463
- {
464
- var ajax_data = {
465
- 'action': 'wpvivid_rescan_local_folder'
466
- };
467
- wpvivid_post_request(ajax_data, function (data)
468
- {
469
- try {
470
- var jsonarray = jQuery.parseJSON(data);
471
- if(jsonarray.html !== false){
472
- jQuery('#wpvivid_backup_list').html('');
473
- jQuery('#wpvivid_backup_list').append(jsonarray.html);
474
- wpvivid_popup_tour('show');
475
- }
476
- }
477
- catch(err) {
478
- alert(err);
479
- }
480
- }, function (XMLHttpRequest, textStatus, errorThrown)
481
- {
482
- var error_message = wpvivid_output_ajaxerror('scanning backup list', textStatus, errorThrown);
483
- alert(error_message);
484
- });
485
- }
486
- </script>
487
- <?php
488
- }
489
-
490
- function get_backup_count()
491
- {
492
- global $wpvivid_plugin;
493
- $wpvivid_plugin->ajax_check_security();
494
-
495
- $backuplist=WPvivid_Backuplist::get_backuplist();
496
- echo sizeof($backuplist);
497
- die();
498
- }
499
-
500
- static function upload_meta_box()
501
- {
502
- ?>
503
- <div id="wpvivid_plupload-upload-ui" class="hide-if-no-js">
504
- <div id="drag-drop-area">
505
- <div class="drag-drop-inside">
506
- <p class="drag-drop-info"><?php _e('Drop files here', 'wpvivid-backuprestore'); ?></p>
507
- <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p>
508
- <p class="drag-drop-buttons"><input id="wpvivid_select_file_button" type="button" value="<?php esc_attr_e('Select Files', 'wpvivid-backuprestore'); ?>" class="button" /></p>
509
- </div>
510
- </div>
511
- </div>
512
- <div id="wpvivid_upload_file_list" class="hide-if-no-js" style="padding-top: 10px; padding-bottom: 10px;"></div>
513
- <input type="submit" class="button-primary" id="wpvivid_upload_submit_btn" value="Upload" onclick="wpvivid_submit_upload();" />
514
- <?php
515
- $chunk_size = min(wp_max_upload_size()-1024, 1048576*2);
516
- $plupload_init = array(
517
- 'runtimes' => 'html5,silverlight,flash,html4',
518
- 'browse_button' => 'wpvivid_select_file_button',
519
- 'container' => 'wpvivid_plupload-upload-ui',
520
- 'drop_element' => 'drag-drop-area',
521
- 'file_data_name' => 'async-upload',
522
- 'max_retries' => 3,
523
- 'multiple_queues' => true,
524
- 'max_file_size' => '10Gb',
525
- 'chunk_size' => $chunk_size.'b',
526
- 'url' => admin_url('admin-ajax.php'),
527
- 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
528
- 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
529
- 'multipart' => true,
530
- 'urlstream_upload' => true,
531
- // additional post data to send to our ajax hook
532
- 'multipart_params' => array(
533
- '_ajax_nonce' => wp_create_nonce('wpvivid_ajax'),
534
- 'action' => 'wpvivid_upload_files', // the ajax action name
535
- ),
536
- );
537
-
538
- if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.swf')) {
539
- $plupload_init['flash_swf_url'] = includes_url('js/plupload/Moxie.swf');
540
- } else {
541
- $plupload_init['flash_swf_url'] = includes_url('js/plupload/plupload.flash.swf');
542
- }
543
-
544
- if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.xap')) {
545
- $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/Moxie.xap');
546
- } else {
547
- $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/plupload.silverlight.swf');
548
- }
549
-
550
- // we should probably not apply this filter, plugins may expect wp's media uploader...
551
- $plupload_init = apply_filters('plupload_init', $plupload_init);
552
- $upload_file_image = includes_url( '/images/media/archive.png' );
553
- ?>
554
-
555
-
556
- <script type="text/javascript">
557
-
558
- var uploader;
559
- jQuery(document).ready(function($)
560
- {
561
- // create the uploader and pass the config from above
562
- jQuery('#wpvivid_upload_submit_btn').hide();
563
- uploader = new plupload.Uploader(<?php echo json_encode($plupload_init); ?>);
564
-
565
- // checks if browser supports drag and drop upload, makes some css adjustments if necessary
566
- uploader.bind('Init', function(up)
567
- {
568
- var uploaddiv = $('#wpvivid_plupload-upload-ui');
569
-
570
- if(up.features.dragdrop){
571
- uploaddiv.addClass('drag-drop');
572
- $('#drag-drop-area')
573
- .bind('dragover.wp-uploader', function(){ uploaddiv.addClass('drag-over'); })
574
- .bind('dragleave.wp-uploader, drop.wp-uploader', function(){ uploaddiv.removeClass('drag-over'); });
575
-
576
- }else{
577
- uploaddiv.removeClass('drag-drop');
578
- $('#drag-drop-area').unbind('.wp-uploader');
579
- }
580
- });
581
- uploader.init();
582
- // a file was added in the queue
583
- var wpvivid_upload_id='';
584
-
585
- function wpvivid_check_plupload_added_files(up,files)
586
- {
587
- if(wpvivid_upload_id==='')
588
- {
589
- var file=files[0];
590
-
591
- var ajax_data = {
592
- 'action': 'wpvivid_get_file_id',
593
- 'file_name':file.name
594
- };
595
- wpvivid_post_request(ajax_data, function (data)
596
- {
597
- var jsonarray = jQuery.parseJSON(data);
598
- if (jsonarray.result === "success")
599
- {
600
- wpvivid_upload_id=jsonarray.id;
601
- wpvivid_check_plupload_added_files(up,files);
602
- }
603
- else if(jsonarray.result === "failed") {
604
- uploader.removeFile(file);
605
- alert(jsonarray.error);
606
- }
607
- }, function (XMLHttpRequest, textStatus, errorThrown)
608
- {
609
- var error_message = wpvivid_output_ajaxerror('uploading backups', textStatus, errorThrown);
610
- uploader.removeFile(file);
611
- alert(error_message);
612
- });
613
- }
614
- else
615
- {
616
- var repeat_files = '';
617
- plupload.each(files, function(file)
618
- {
619
- var brepeat=false;
620
- var file_list = jQuery('#wpvivid_upload_file_list span');
621
- file_list.each(function (index, value) {
622
- if (value.innerHTML === file.name) {
623
- brepeat=true;
624
- }
625
- });
626
- if(!brepeat) {
627
- var wpvivid_file_regex = new RegExp(wpvivid_upload_id + '_.*_.*\\.zip$');
628
- if (wpvivid_file_regex.test(file.name)) {
629
- jQuery('#wpvivid_upload_file_list').append(
630
- '<div id="' + file.id + '" style="width: 100%; height: 36px; background: #fff; margin-bottom: 1px;">' +
631
- '<img src=" <?php echo $upload_file_image; ?> " alt="" style="float: left; margin: 2px 10px 0 3px; max-width: 40px; max-height: 32px;">' +
632
- '<div style="line-height: 36px; float: left; margin-left: 5px;"><span>' + file.name + '</span></div>' +
633
- '<div class="fileprogress" style="line-height: 36px; float: right; margin-right: 5px;"></div>' +
634
- '</div>' +
635
- '<div style="clear: both;"></div>'
636
- );
637
- jQuery('#wpvivid_upload_submit_btn').show();
638
- jQuery("#wpvivid_upload_submit_btn").prop('disabled', false);
639
- }
640
- else {
641
- alert(file.name + " is not belong to the backup package uploaded.");
642
- uploader.removeFile(file);
643
- }
644
- }
645
- else{
646
- if(repeat_files === ''){
647
- repeat_files += file.name;
648
- }
649
- else{
650
- repeat_files += ', ' + file.name;
651
- }
652
- }
653
- });
654
- if(repeat_files !== ''){
655
- alert(repeat_files + " already exists in upload list.");
656
- repeat_files = '';
657
- }
658
- }
659
- }
660
-
661
- uploader.bind('FilesAdded', wpvivid_check_plupload_added_files);
662
-
663
- uploader.bind('Error', function(up, error)
664
- {
665
- alert('Upload ' + error.file.name +' error, error code: ' + error.code + ', ' + error.message);
666
- console.log(error);
667
- });
668
-
669
- uploader.bind('FileUploaded', function(up, file, response)
670
- {
671
- var jsonarray = jQuery.parseJSON(response.response);
672
- if(jsonarray.result == 'failed'){
673
- alert('upload ' + file.name + ' failed, ' + jsonarray.error);
674
- }
675
- });
676
-
677
- uploader.bind('UploadProgress', function(up, file)
678
- {
679
- jQuery('#' + file.id + " .fileprogress").html(file.percent + "%");
680
- });
681
-
682
- uploader.bind('UploadComplete',function(up, files)
683
- {
684
- jQuery('#wpvivid_upload_file_list').html("");
685
- wpvivid_upload_id='';
686
- jQuery('#wpvivid_upload_submit_btn').hide();
687
- jQuery("#wpvivid_select_file_button").prop('disabled', false);
688
- var ajax_data = {
689
- 'action': 'wpvivid_upload_files_finish',
690
- 'files':JSON.stringify(files)
691
- };
692
- wpvivid_post_request(ajax_data, function (data)
693
- {
694
- try {
695
- var jsonarray = jQuery.parseJSON(data);
696
- if(jsonarray.result === 'success') {
697
- if (jsonarray.html !== false) {
698
- var unlinked = '';
699
- if(typeof jsonarray.unlinked !== 'undefined'){
700
- unlinked = jsonarray.unlinked;
701
- }
702
- alert('The upload has completed. ' + unlinked);
703
- jQuery('#wpvivid_backup_list').html('');
704
- jQuery('#wpvivid_backup_list').append(jsonarray.html);
705
- wpvivid_click_switch_page('backup', 'wpvivid_tab_backup', true);
706
- }
707
- }
708
- else if(jsonarray.result === 'failed'){
709
- var unlinked = '';
710
- if(typeof jsonarray.unlinked !== 'undefined'){
711
- unlinked = jsonarray.unlinked;
712
- }
713
- alert(jsonarray.error + ' ' + unlinked);
714
- }
715
- }
716
- catch(err) {
717
- alert(err);
718
- }
719
- }, function (XMLHttpRequest, textStatus, errorThrown)
720
- {
721
- var error_message = wpvivid_output_ajaxerror('refreshing backup list', textStatus, errorThrown);
722
- alert(error_message);
723
- });
724
- plupload.each(files, function(file)
725
- {
726
- if(typeof file === 'undefined')
727
- {
728
-
729
- }
730
- else
731
- {
732
- uploader.removeFile(file.id);
733
- }
734
- });
735
- })
736
- });
737
-
738
- function wpvivid_submit_upload()
739
- {
740
- var backup_max_count='<?php
741
- $general_setting=WPvivid_Setting::get_setting(true, "");
742
- $display_backup_count = $general_setting['options']['wpvivid_common_setting']['max_backup_count'];
743
- echo intval($display_backup_count);
744
- ?>';
745
- var ajax_data = {
746
- 'action': 'wpvivid_get_backup_count'
747
- };
748
- wpvivid_post_request(ajax_data, function (data)
749
- {
750
- var backuplist_count = data;
751
- if(backuplist_count >= backup_max_count){
752
- alert("The backup retention limit for localhost(web server) is reached, please either increase the retention from WPvivid General Settings, or manually delete some old backups.");
753
- }
754
- else {
755
- jQuery("#wpvivid_upload_submit_btn").prop('disabled', true);
756
- jQuery("#wpvivid_select_file_button").prop('disabled', true);
757
- uploader.refresh();
758
- uploader.start();
759
- }
760
-
761
- }, function (XMLHttpRequest, textStatus, errorThrown)
762
- {
763
- var error_message = wpvivid_output_ajaxerror('uploading backups', textStatus, errorThrown);
764
- alert(error_message);
765
- });
766
- }
767
- </script>
768
- <?php
769
- }
770
-
771
- public function upload_dir($uploads)
772
- {
773
- $uploads['path'] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
774
- return $uploads;
775
- }
776
-
777
- private function check_is_a_wpvivid_backup($file_name)
778
- {
779
- $ret=WPvivid_Backup_Item::get_backup_file_info($file_name);
780
- if($ret['result'] === WPVIVID_SUCCESS){
781
- return true;
782
- }
783
- elseif($ret['result'] === WPVIVID_FAILED){
784
- return $ret['error'];
785
- }
786
- }
787
-
788
- private function zip_check_sum($file_name)
789
- {
790
- return true;
791
- }
792
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-backup.php DELETED
@@ -1,2609 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR'))
4
- {
5
- die;
6
- }
7
-
8
- define('WPVIVID_BACKUP_TYPE_DB','backup_db');
9
- define('WPVIVID_BACKUP_TYPE_THEMES','backup_themes');
10
- define('WPVIVID_BACKUP_TYPE_PLUGIN','backup_plugin');
11
- define('WPVIVID_BACKUP_TYPE_UPLOADS','backup_uploads');
12
- define('WPVIVID_BACKUP_TYPE_UPLOADS_FILES','backup_uploads_files');
13
- //define('WPVIVID_BACKUP_TYPE_UPLOADS_FILES_OTHER','backup_uploads_files_other');
14
- define('WPVIVID_BACKUP_TYPE_CONTENT','backup_content');
15
- define('WPVIVID_BACKUP_TYPE_CORE','backup_core');
16
- define('WPVIVID_BACKUP_TYPE_OTHERS','backup_others');
17
- define('WPVIVID_BACKUP_TYPE_MERGE','backup_merge');
18
-
19
- define('WPVIVID_BACKUP_ROOT_WP_CONTENT','wp-content');
20
- define('WPVIVID_BACKUP_ROOT_CUSTOM','custom');
21
- define('WPVIVID_BACKUP_ROOT_WP_ROOT','root');
22
- define('WPVIVID_BACKUP_ROOT_WP_UPLOADS','uploads');
23
- class WPvivid_Backup_Task
24
- {
25
- protected $task;
26
-
27
- public $backup_type_collect;
28
-
29
- public function __construct($task_id=false,$task=false)
30
- {
31
- if($task_id!==false)
32
- {
33
- $this->task=WPvivid_taskmanager::get_task($task_id);
34
- }
35
-
36
- if($task!==false)
37
- {
38
- $this->task=$task;
39
- }
40
-
41
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_DB]=1;
42
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_THEMES]=1;
43
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_PLUGIN]=1;
44
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_UPLOADS]=1;
45
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_UPLOADS_FILES]=1;
46
- //$this->backup_type_collect[WPVIVID_BACKUP_TYPE_UPLOADS_FILES_OTHER]=1;
47
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_CONTENT]=1;
48
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_CORE]=1;
49
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_OTHERS]=1;
50
- $this->backup_type_collect[WPVIVID_BACKUP_TYPE_MERGE]=1;
51
-
52
- add_filter('wpvivid_set_backup', array($this, 'wpvivid_set_backup'),10);
53
- add_filter('wpvivid_exclude_plugins',array($this,'exclude_plugins'),20);
54
- add_filter('wpvivid_get_backup_exclude_regex',array($this, 'get_backup_exclude_regex'),10,2);
55
- }
56
-
57
- public function get_backup_exclude_regex($exclude_regex,$backup_type)
58
- {
59
- if($backup_type==WPVIVID_BACKUP_TYPE_UPLOADS||$backup_type==WPVIVID_BACKUP_TYPE_UPLOADS_FILES)
60
- {
61
- $upload_dir = wp_upload_dir();
62
- $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
63
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
64
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'ShortpixelBackups', '/').'#';//ShortpixelBackups
65
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup', '/').'#';
66
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backwpup', '/').'#'; // BackWPup backup directory
67
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR.'backup-guard', '/').'#'; // Wordpress Backup and Migrate Plugin backup directory
68
- }
69
- else if($backup_type==WPVIVID_BACKUP_TYPE_CONTENT)
70
- {
71
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'updraft', '/').'#'; // Updraft Plus backup directory
72
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'ai1wm-backups', '/').'#'; // All-in-one WP migration backup directory
73
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'backups', '/').'#'; // Xcloner backup directory
74
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'upgrade', '/').'#';
75
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'wpvivid', '/').'#';
76
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir(), '/').'#';
77
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'plugins', '/').'#';
78
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'cache', '/').'#';
79
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'wphb-cache', '/').'#';
80
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'backup', '/').'#';
81
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'Dropbox_Backup', '/').'#';
82
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.'mysql.sql', '/').'#';//mysql
83
- if(defined('WPVIVID_UPLOADS_ISO_DIR'))
84
- {
85
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_CONTENT_DIR).DIRECTORY_SEPARATOR.WPVIVID_UPLOADS_ISO_DIR, '/').'#';
86
- }
87
- $upload_dir = wp_upload_dir();
88
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']), '/').'$#';
89
- $exclude_regex[]='#^'.preg_quote($this->transfer_path(get_theme_root()), '/').'#';
90
- }
91
-
92
- return $exclude_regex;
93
- }
94
-
95
- public function exclude_plugins($exclude_plugins)
96
- {
97
- if(in_array('wpvivid-backuprestore',$exclude_plugins))
98
- {
99
- $exclude_plugins[]='wpvivid-backuprestore';
100
- }
101
-
102
- if(in_array('wp-cerber',$exclude_plugins))
103
- {
104
- $exclude_plugins[]='wp-cerber';
105
- }
106
-
107
- if(in_array('.',$exclude_plugins))
108
- {
109
- $exclude_plugins[]='.';
110
- }
111
-
112
- if(in_array('wpvivid-backup-pro',$exclude_plugins))
113
- {
114
- $exclude_plugins[]='wpvivid-backup-pro';
115
- }
116
-
117
- return $exclude_plugins;
118
- }
119
-
120
- public function get_id()
121
- {
122
- return $this->task['id'];
123
- }
124
-
125
- public function new_backup_task($options,$type,$action='backup')
126
- {
127
- $id=uniqid('wpvivid-');
128
- $this->task=false;
129
- $this->task['id']=$id;
130
- $this->task['action']=$action;
131
- $this->task['type']=$type;
132
-
133
- $this->task['status']['start_time']=time();
134
- $this->task['status']['run_time']=time();
135
- $this->task['status']['timeout']=time();
136
- $this->task['status']['str']='ready';
137
- $this->task['status']['resume_count']=0;
138
-
139
- if(isset($options['remote']))
140
- {
141
- if($options['remote']=='1')
142
- {
143
- if(isset($options['remote_options']))
144
- {
145
- $this->task['options']['remote_options']=$options['remote_options'];
146
- }
147
- else
148
- {
149
- $this->task['options']['remote_options']=WPvivid_Setting::get_remote_options();
150
- }
151
-
152
- }
153
- else {
154
- $this->task['options']['remote_options']=false;
155
- }
156
- }
157
- else
158
- {
159
- $this->task['options']['remote_options']=false;
160
- }
161
-
162
- $this->task['options']['remote_options'] = apply_filters('wpvivid_set_remote_options', $this->task['options']['remote_options'],$options);
163
-
164
- if(isset($options['local']))
165
- {
166
- if($options['local']=='1')
167
- {
168
- $this->task['options']['save_local']=1;
169
- }
170
- else
171
- {
172
- $this->task['options']['save_local']=0;
173
- }
174
- }
175
- else
176
- {
177
- $this->task['options']['save_local']=1;
178
- }
179
-
180
- if(isset($options['lock']))
181
- {
182
- $this->task['options']['lock']=$options['lock'];
183
- }
184
- else
185
- {
186
- $this->task['options']['lock']=0;
187
- }
188
-
189
- $general_setting=WPvivid_Setting::get_setting(true, "");
190
-
191
- if(isset($options['backup_prefix']) && !empty($options['backup_prefix']))
192
- {
193
- $backup_prefix=$options['backup_prefix'];
194
- }
195
- else
196
- {
197
- if(isset($general_setting['options']['wpvivid_common_setting']['domain_include'])&&$general_setting['options']['wpvivid_common_setting']['domain_include'])
198
- {
199
- $check_addon = apply_filters('wpvivid_check_setting_addon', 'not_addon');
200
- if (isset($general_setting['options']['wpvivid_common_setting']['backup_prefix']) && $check_addon == 'addon')
201
- {
202
- $backup_prefix = $general_setting['options']['wpvivid_common_setting']['backup_prefix'];
203
- }
204
- else {
205
- $home_url_prefix = get_home_url();
206
- $home_url_prefix = $this->parse_url_all($home_url_prefix);
207
- $backup_prefix = $home_url_prefix;
208
- }
209
- }
210
- else
211
- {
212
- $backup_prefix='';
213
- }
214
- }
215
- $this->task['options']['backup_prefix']=$backup_prefix;
216
- $offset=get_option('gmt_offset');
217
- if(empty($backup_prefix))
218
- $this->task['options']['file_prefix'] = $this->task['id'] . '_' . date('Y-m-d-H-i', $this->task['status']['start_time']+$offset*60*60);
219
- else
220
- $this->task['options']['file_prefix'] = $backup_prefix . '_' . $this->task['id'] . '_' . date('Y-m-d-H-i', $this->task['status']['start_time']+$offset*60*60);
221
-
222
- $this->task['options']['file_prefix'] = apply_filters('wpvivid_backup_file_prefix',$this->task['options']['file_prefix'],$backup_prefix,$this->task['id'],$this->task['status']['start_time']);
223
-
224
- if(isset($general_setting['options']['wpvivid_common_setting']['ismerge']))
225
- {
226
- if($general_setting['options']['wpvivid_common_setting']['ismerge']==1)
227
- {
228
- $this->task['options']['backup_options']['ismerge']=1;
229
- }
230
- else {
231
- $this->task['options']['backup_options']['ismerge']=0;
232
- }
233
- }
234
- else {
235
- $this->task['options']['backup_options']['ismerge']=1;
236
- }
237
- $this->task['options']['backup_options']['ismerge']=apply_filters('wpvivid_set_backup_ismerge',$this->task['options']['backup_options']['ismerge'],$options);
238
-
239
- $this->task['options']['log_file_name']=$id.'_backup';
240
- $log=new WPvivid_Log();
241
- $log->CreateLogFile($this->task['options']['log_file_name'],'no_folder','backup');
242
- //$log->WriteLog(get_home_path(),'test');
243
- $this->task['options']['backup_options']['prefix']=$this->task['options']['file_prefix'];
244
- $this->task['options']['backup_options']['compress']=WPvivid_Setting::get_option('wpvivid_compress_setting');
245
- $this->task['options']['backup_options']['dir']=WPvivid_Setting::get_backupdir();
246
- $this->task['options']['backup_options']['backup']=array();
247
-
248
- if(isset($options['backup_files']))
249
- {
250
- if($options['backup_files']=='files+db')
251
- {
252
- $this->set_backup(WPVIVID_BACKUP_TYPE_DB);
253
- $this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
254
- $this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
255
- $general_setting=WPvivid_Setting::get_setting(true, "");
256
- if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
257
- if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
258
- $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS_FILES);
259
- //$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS_FILES_OTHER);
260
- }
261
- else{
262
- $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
263
- }
264
- }
265
- else{
266
- $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
267
- }
268
- $this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
269
- $this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
270
- }
271
- else if($options['backup_files']=='files')
272
- {
273
- $this->set_backup(WPVIVID_BACKUP_TYPE_THEMES);
274
- $this->set_backup(WPVIVID_BACKUP_TYPE_PLUGIN);
275
- $general_setting=WPvivid_Setting::get_setting(true, "");
276
- if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
277
- if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
278
- $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS_FILES);
279
- //$this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS_FILES_OTHER);
280
- }
281
- else{
282
- $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
283
- }
284
- }
285
- else{
286
- $this->set_backup(WPVIVID_BACKUP_TYPE_UPLOADS);
287
- }
288
- $this->set_backup(WPVIVID_BACKUP_TYPE_CONTENT);
289
- $this->set_backup(WPVIVID_BACKUP_TYPE_CORE);
290
- }
291
- else if($options['backup_files']=='db')
292
- {
293
- $this->set_backup(WPVIVID_BACKUP_TYPE_DB);
294
- }
295
- }
296
- else
297
- {
298
- $this->task['options']['backup_options'] = apply_filters('wpvivid_set_backup_type', $this->task['options']['backup_options'],$options);
299
- }
300
-
301
- $this->task['data']['doing']='backup';
302
- $this->task['data']['backup']['doing']='';
303
- $this->task['data']['backup']['finished']=0;
304
- $this->task['data']['backup']['progress']=0;
305
- $this->task['data']['backup']['job_data']=array();
306
- $this->task['data']['backup']['sub_job']=array();
307
- $this->task['data']['backup']['db_size']='0';
308
- $this->task['data']['backup']['files_size']['sum']='0';
309
- $this->task['data']['upload']['doing']='';
310
- $this->task['data']['upload']['finished']=0;
311
- $this->task['data']['upload']['progress']=0;
312
- $this->task['data']['upload']['job_data']=array();
313
- $this->task['data']['upload']['sub_job']=array();
314
- WPvivid_Setting::update_task($id,$this->task);
315
- $ret['result']='success';
316
- $ret['task_id']=$this->task['id'];
317
- $log->CloseFile();
318
- return $ret;
319
- }
320
-
321
- protected function parse_url_all($url)
322
- {
323
- $parse = parse_url($url);
324
- $path=str_replace('/','_',$parse['path']);
325
- return $parse['host'].$path;
326
- }
327
-
328
- public function set_backup($backup, $task_type='')
329
- {
330
- if(is_string($backup))
331
- {
332
- if(!function_exists('get_home_path'))
333
- require_once(ABSPATH . 'wp-admin/includes/file.php');
334
- $backup_data['key']=$backup;
335
- $backup_data['result']=false;
336
- $backup_data['compress']=$this->task['options']['backup_options']['compress'];
337
- $backup_data['finished']=0;
338
- $backup_data['path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR. $this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR;
339
- if($backup==WPVIVID_BACKUP_TYPE_DB)
340
- {
341
- //$backup_data['root_path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'];
342
- $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_CUSTOM;
343
- $backup_data['dump_db']=1;
344
- $backup_data['sql_file_name']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$this->get_prefix().'_backup_db.sql';
345
- $backup_data['json_info']['dump_db']=1;
346
- $backup_data['json_info']['home_url']=home_url();
347
- $backup_data['json_info']['file_type']='databases';
348
- if(is_multisite())
349
- {
350
- $backup_data['json_info']['is_mu']=1;
351
- }
352
- $backup_data['prefix']=$this->get_prefix().'_backup_db';
353
- }
354
- else if($backup==WPVIVID_BACKUP_TYPE_THEMES)
355
- {
356
- //$backup_data['root_path']=WP_CONTENT_DIR;
357
- $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
358
- $backup_data['prefix']=$this->get_prefix().'_backup_themes';
359
- $backup_data['files_root']=$this->transfer_path(get_theme_root());
360
- $backup_data['exclude_regex']=array();
361
- $backup_data['include_regex']=array();
362
- $backup_data['json_info']['file_type']='themes';
363
- $backup_data['json_info']['themes']=$this->get_themes_list();
364
- $this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
365
- }
366
- else if($backup==WPVIVID_BACKUP_TYPE_PLUGIN)
367
- {
368
- //$backup_data['root_path']=WP_CONTENT_DIR;
369
- $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
370
- $backup_data['prefix']=$this->get_prefix().'_backup_plugin';
371
- if(isset($backup_data['compress']['subpackage_plugin_upload'])&&$backup_data['compress']['subpackage_plugin_upload'])
372
- {
373
- $backup_data['plugin_subpackage']=1;
374
- }
375
- $backup_data['files_root']=$this->transfer_path(WP_PLUGIN_DIR);
376
-
377
- $exclude_plugins=array();
378
- $exclude_plugins=apply_filters('wpvivid_exclude_plugins',$exclude_plugins);
379
- $exclude_regex=array();
380
- foreach ($exclude_plugins as $exclude_plugin)
381
- {
382
- $exclude_regex[]='#^'.preg_quote($this -> transfer_path(WP_PLUGIN_DIR.DIRECTORY_SEPARATOR.$exclude_plugin), '/').'#';
383
- }
384
- $backup_data['exclude_regex']=$exclude_regex;
385
- $backup_data['include_regex']=array();
386
- $backup_data['json_info']['file_type']='plugin';
387
- $backup_data['json_info']['plugin']=$this->get_plugins_list();
388
- }
389
- else if($backup==WPVIVID_BACKUP_TYPE_UPLOADS)
390
- {
391
- //$backup_data['root_path']=WP_CONTENT_DIR;
392
- $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
393
- $backup_data['prefix']=$this->get_prefix().'_backup_uploads';
394
- $upload_dir = wp_upload_dir();
395
- $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
396
-
397
- $exclude_regex=array();
398
- $exclude_regex=apply_filters('wpvivid_get_backup_exclude_regex',$exclude_regex,WPVIVID_BACKUP_TYPE_UPLOADS);
399
- $backup_data['exclude_regex']=$exclude_regex;
400
- $backup_data['include_regex']=array();
401
- $backup_data['json_info']['file_type']='upload';
402
- }
403
- else if($backup==WPVIVID_BACKUP_TYPE_UPLOADS_FILES)
404
- {
405
- //$backup_data['root_path']=WP_CONTENT_DIR;
406
- $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
407
- $backup_data['prefix']=$this->get_prefix().'_backup_uploads';
408
- $backup_data['uploads_subpackage']=1;
409
- $upload_dir = wp_upload_dir();
410
- $backup_data['files_root']=$this -> transfer_path($upload_dir['basedir']);
411
- $exclude_regex=array();
412
- $exclude_regex=apply_filters('wpvivid_get_backup_exclude_regex',$exclude_regex,WPVIVID_BACKUP_TYPE_UPLOADS_FILES);
413
- $backup_data['include_regex']=array();
414
- $backup_data['exclude_regex']=$exclude_regex;
415
- //$backup_data['include_regex'][]='#^'.preg_quote($this -> transfer_path($upload_dir['basedir']).DIRECTORY_SEPARATOR, '/').'[0-9]{4}#';
416
- $backup_data['json_info']['file_type']='upload';
417
- }
418
- else if($backup==WPVIVID_BACKUP_TYPE_CONTENT)
419
- {
420
- //$backup_data['root_path']=get_home_path();
421
- $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_WP_ROOT;
422
- $backup_data['prefix']=$this->get_prefix().'_backup_content';
423
- $backup_data['files_root']=$this -> transfer_path(WP_CONTENT_DIR);
424
- $exclude_regex=array();
425
- $exclude_regex=apply_filters('wpvivid_get_backup_exclude_regex',$exclude_regex,WPVIVID_BACKUP_TYPE_CONTENT);
426
- $backup_data['exclude_regex']=$exclude_regex;
427
- $backup_data['include_regex']=array();
428
- $backup_data['json_info']['file_type']='wp-content';
429
- }
430
- else if($backup==WPVIVID_BACKUP_TYPE_CORE)
431
- {
432
- //$backup_data['root_path']=ABSPATH;
433
- $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_WP_ROOT;
434
- $backup_data['prefix']=$this->get_prefix().'_backup_core';
435
- $backup_data['files_root']=$this -> transfer_path(ABSPATH);
436
- $backup_data['json_info']['include_path'][]='wp-includes';
437
- $backup_data['json_info']['include_path'][]='wp-admin';
438
- $backup_data['json_info']['wp_core']=1;
439
- $backup_data['json_info']['home_url']=home_url();
440
- $include_regex[]='#^'.preg_quote($this -> transfer_path(ABSPATH.DIRECTORY_SEPARATOR.'wp-admin'), '/').'#';
441
- $include_regex[]='#^'.preg_quote($this->transfer_path(ABSPATH.DIRECTORY_SEPARATOR.'wp-includes'), '/').'#';
442
- $exclude_regex[]='#^'.preg_quote($this->transfer_path(ABSPATH.DIRECTORY_SEPARATOR.'wp-admin'.DIRECTORY_SEPARATOR), '/').'pclzip-.*\.tmp#';
443
- $exclude_regex[]='#^'.preg_quote($this->transfer_path(ABSPATH.DIRECTORY_SEPARATOR.'wp-admin'.DIRECTORY_SEPARATOR), '/').'pclzip-.*\.gz#';
444
- $exclude_regex[]='#session_mm_cgi-fcgi#';
445
- $exclude_regex=apply_filters('wpvivid_get_backup_exclude_regex',$exclude_regex,WPVIVID_BACKUP_TYPE_CORE);
446
- $backup_data['exclude_regex']=$exclude_regex;
447
- $backup_data['include_regex']=$include_regex;
448
- $backup_data['json_info']['file_type']='wp-core';
449
- }
450
- else if($backup==WPVIVID_BACKUP_TYPE_MERGE)
451
- {
452
- //$backup_data['root_path']=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'];
453
- $backup_data['root_flag']=WPVIVID_BACKUP_ROOT_CUSTOM;
454
- $file_name = $this->get_prefix().'_backup_all';
455
- $file_name = apply_filters('wpvivid_set_incremental_backup_file_name', $file_name, $this->get_prefix(), $task_type);
456
- $backup_data['prefix']=$file_name;
457
- $backup_data['files']=array();
458
- $backup_data['json_info']['has_child']=1;
459
- foreach ($this->task['options']['backup_options']['backup'] as $backup_finished_data)
460
- {
461
- $backup_data['files']=array_merge($backup_data['files'],$this->get_backup_file($backup_finished_data['key']));
462
- }
463
- $backup_data['json_info']['home_url']=home_url();
464
- }
465
- else
466
- {
467
- $backup_data=false;
468
- }
469
- if($backup_data!==false)
470
- {
471
- $backup_data=apply_filters('wpvivid_set_backup',$backup_data);
472
- $this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
473
- }
474
- }
475
- }
476
-
477
- public function get_themes_list()
478
- {
479
- $themes_list=array();
480
- $list=wp_get_themes();
481
- foreach ($list as $key=>$item)
482
- {
483
- $themes_list[$key]['slug']=$key;
484
- $themes_list[$key]['size']=$this->get_folder_size(get_theme_root().DIRECTORY_SEPARATOR.$key,0);
485
- }
486
- return $themes_list;
487
- }
488
-
489
- public function get_plugins_list()
490
- {
491
- $plugins_list=array();
492
-
493
- if(!function_exists('get_plugins'))
494
- require_once(ABSPATH . 'wp-admin/includes/plugin.php');
495
-
496
- $list=get_plugins();
497
-
498
- $exclude_plugins[]='wpvivid-backuprestore';
499
- $exclude_plugins[]='wp-cerber';
500
- $exclude_plugins[]='.';
501
- $exclude_plugins=apply_filters('wpvivid_exclude_plugins',$exclude_plugins);
502
-
503
- foreach ($list as $key=>$item)
504
- {
505
- if(in_array(dirname($key),$exclude_plugins))
506
- {
507
- continue;
508
- }
509
-
510
- $plugins_list[dirname($key)]['slug']=dirname($key);
511
- $plugins_list[dirname($key)]['size']=$this->get_folder_size(WP_PLUGIN_DIR.DIRECTORY_SEPARATOR.dirname($key),0);
512
- //
513
- }
514
- return $plugins_list;
515
- }
516
-
517
- public function get_folder_size($root,$size)
518
- {
519
- $count = 0;
520
- if(is_dir($root))
521
- {
522
- $handler = opendir($root);
523
- if($handler!==false)
524
- {
525
- while (($filename = readdir($handler)) !== false)
526
- {
527
- if ($filename != "." && $filename != "..") {
528
- $count++;
529
-
530
- if (is_dir($root . DIRECTORY_SEPARATOR . $filename))
531
- {
532
- $size=$this->get_folder_size($root . DIRECTORY_SEPARATOR . $filename,$size);
533
- } else {
534
- $size+=filesize($root . DIRECTORY_SEPARATOR . $filename);
535
- }
536
- }
537
- }
538
- if($handler)
539
- @closedir($handler);
540
- }
541
-
542
- }
543
- return $size;
544
- }
545
-
546
- public function wpvivid_set_backup($backup_data)
547
- {
548
- if(isset($backup_data['uploads_subpackage'])||isset($backup_data['plugin_subpackage']))
549
- {
550
- $backup_data['resume_packages'] = 1;
551
- }
552
- else if($backup_data['key']==WPVIVID_BACKUP_TYPE_MERGE)
553
- {
554
- $backup_data['resume_packages'] = 1;
555
- }
556
-
557
- return $backup_data;
558
- }
559
-
560
- public function get_need_backup_files($backup_data)
561
- {
562
- if(isset($backup_data['uploads_subpackage']))
563
- {
564
- return $backup_data['files']=$this->get_need_uploads_backup_folder($backup_data);
565
- }
566
-
567
- if(isset($backup_data['plugin_subpackage']))
568
- {
569
- return $backup_data['files']=$this->get_need_backup_folder($backup_data);
570
- }
571
-
572
- if(isset($backup_data['files'])&&!empty($backup_data['files']))
573
- {
574
- return $backup_data['files'];
575
- }
576
- else
577
- {
578
- return $this->get_file_list($backup_data['files_root'],$backup_data['exclude_regex'],$backup_data['include_regex'],$this->task['options']['backup_options']['compress']['exclude_file_size']);
579
- }
580
- }
581
-
582
- public function get_backup_file($key)
583
- {
584
- $files=array();
585
- if(array_key_exists($key,$this->task['options']['backup_options']['backup']))
586
- {
587
- $backup=$this->task['options']['backup_options']['backup'][$key];
588
- if($backup['finished'])
589
- {
590
- if($backup['result']!=false)
591
- {
592
- foreach ($backup['result']['files'] as $file_data)
593
- {
594
- $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$file_data['file_name'];
595
- }
596
- }
597
- }
598
- }
599
- return $files;
600
- }
601
-
602
- public function get_need_backup()
603
- {
604
- $this->task=WPvivid_taskmanager::get_task($this->task['id']);
605
- $backup=false;
606
- $i_finished_backup_count=0;
607
- $i_count_of_backup=sizeof($this->task['options']['backup_options']['backup']);
608
- foreach ($this->task['options']['backup_options']['backup'] as $key=>$backup_data)
609
- {
610
- if($backup_data['result']!==false)
611
- {
612
- $ret=$backup_data['result'];
613
- if($ret['result']!==WPVIVID_SUCCESS)
614
- {
615
- return false;
616
- }
617
- }
618
-
619
- if( $backup_data['finished']==0)
620
- {
621
- if($backup===false)
622
- {
623
- add_filter('wpvivid_get_need_backup_files', array($this, 'wpvivid_get_need_backup_files'),10);
624
- $backup_data=apply_filters('wpvivid_get_need_backup_files',$backup_data);
625
-
626
- $backup=$backup_data;
627
- }
628
- }
629
- else {
630
- $i_finished_backup_count++;
631
- }
632
- }
633
-
634
- if($i_count_of_backup>0)
635
- {
636
- $i_progress=intval(1/$i_count_of_backup*100);
637
- WPvivid_taskmanager::update_backup_main_task_progress($this->task['id'],'backup',$i_progress*$i_finished_backup_count,0);
638
-
639
- if($i_finished_backup_count>=$i_count_of_backup)
640
- {
641
- if($this->task['options']['backup_options']['ismerge']==1)
642
- {
643
- if(!array_key_exists(WPVIVID_BACKUP_TYPE_MERGE,$this->task['options']['backup_options']['backup']))
644
- {
645
- $this->set_backup(WPVIVID_BACKUP_TYPE_MERGE, $this->task['type']);
646
- WPvivid_Setting::update_task($this->task['id'],$this->task);
647
- $backup=$this->task['options']['backup_options']['backup'][WPVIVID_BACKUP_TYPE_MERGE];
648
- }
649
- }
650
- }
651
- }
652
- return $backup;
653
- }
654
-
655
- public function get_need_backup_files_size($backup_data)
656
- {
657
- if(isset($backup_data['files'])&&!empty($backup_data['files']))
658
- {
659
- return $backup_data['files'];
660
- }
661
- else
662
- {
663
- return $this->get_file_list($backup_data['files_root'],$backup_data['exclude_regex'],$backup_data['include_regex'],$this->task['options']['backup_options']['compress']['exclude_file_size']);
664
- }
665
- }
666
-
667
- public function wpvivid_get_need_backup_files($backup_data)
668
- {
669
- if(!isset($backup_data['dump_db']))
670
- {
671
- if(array_key_exists($backup_data['key'],$this->backup_type_collect))
672
- {
673
- $backup_data['files'] = $this->get_need_backup_files($backup_data);
674
- }
675
- else
676
- {
677
- if(!isset($backup_data['files']))
678
- {
679
- $backup_data['files']=array();
680
- }
681
- $backup_data['files'] =apply_filters('wpvivid_get_custom_need_backup_files', $backup_data['files'],$backup_data,$this->task['options']['backup_options']['compress']);
682
- }
683
-
684
- $need=false;
685
- add_filter('wpvivid_need_backup_files_update', array($this, 'need_backup_files_update'), 10, 2);
686
- if(apply_filters('wpvivid_need_backup_files_update',$need,$backup_data))
687
- {
688
- $this->task['options']['backup_options']['backup'][$backup_data['key']]=$backup_data;
689
- WPvivid_Setting::update_task($this->task['id'],$this->task);
690
- }
691
- }
692
- return $backup_data;
693
- }
694
-
695
- public function need_backup_files_update($need,$backup_data)
696
- {
697
- if(isset($backup_data['uploads_subpackage'])||isset($backup_data['plugin_subpackage']))
698
- {
699
- return true;
700
- }
701
- else
702
- {
703
- return $need;
704
- }
705
- }
706
-
707
- public function update_backup_result($backup_data,$result)
708
- {
709
- $this->task=WPvivid_taskmanager::get_task($this->task['id']);
710
-
711
- if(array_key_exists($backup_data['key'],$this->task['options']['backup_options']['backup']))
712
- {
713
- $this->task['options']['backup_options']['backup'][$backup_data['key']]['finished']=1;
714
-
715
- add_filter('wpvivid_backup_update_result', array($this, 'wpvivid_backup_update_result'),10,2);
716
- $result=apply_filters('wpvivid_backup_update_result',$result,$backup_data);
717
- $this->task['options']['backup_options']['backup'][$backup_data['key']]['result']=$result;
718
-
719
- WPvivid_taskmanager::update_task_options($this->task['id'],'backup_options', $this->task['options']['backup_options']);
720
-
721
- if($result['result']==WPVIVID_FAILED)
722
- {
723
- WPvivid_taskmanager::update_backup_task_status($this->task['id'],false,'error',false,false,$result['error']);
724
- return ;
725
- }
726
- }
727
-
728
- $i_finished_backup_count=0;
729
- $i_count_of_backup=sizeof($this->task['options']['backup_options']['backup']);
730
-
731
- foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
732
- {
733
- if( $backup_data['finished']==1)
734
- {
735
- $i_finished_backup_count++;
736
- }
737
- }
738
-
739
- if($i_finished_backup_count>=$i_count_of_backup)
740
- {
741
- WPvivid_taskmanager::update_backup_main_task_progress($this->task['id'],'backup',100,1);
742
- }
743
- //WPvivid_Setting::update_task($this->task['id'],$this->task);
744
- }
745
-
746
- public function wpvivid_backup_update_result($result,$backup_data)
747
- {
748
- if($result['result']==WPVIVID_SUCCESS)
749
- {
750
- $exist_files_name=array();
751
- foreach ($result['files'] as $temp_file_data)
752
- {
753
- $exist_files_name[$temp_file_data['file_name']]=$temp_file_data['file_name'];
754
- }
755
-
756
- if(isset($backup_data['resume_packages'])&&$backup_data['resume_packages'])
757
- {
758
- $packages_files_info = $this->get_packages_files_info($backup_data['key']);
759
- if ($packages_files_info !== false)
760
- {
761
- foreach ($packages_files_info as $file_data)
762
- {
763
- if(!array_key_exists($file_data['file_name'],$exist_files_name))
764
- {
765
- $result['files'][]=$file_data;
766
- }
767
- }
768
- }
769
- }
770
- }
771
-
772
- return $result;
773
- }
774
-
775
- public function get_backup_result()
776
- {
777
- $ret['result']=WPVIVID_SUCCESS;
778
- $ret['files']=array();
779
- foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
780
- {
781
- if($this->task['options']['backup_options']['ismerge']==1)
782
- {
783
- if(WPVIVID_BACKUP_TYPE_MERGE==$backup_data['key'])
784
- {
785
- $ret=$backup_data['result'];
786
- if($ret['result']!==WPVIVID_SUCCESS)
787
- {
788
- return $ret;
789
- }
790
- }
791
- }
792
- else
793
- {
794
- $ret['files']=array_merge($ret['files'],$backup_data['result']['files']);
795
- }
796
- }
797
-
798
- return $ret;
799
- }
800
-
801
- private function transfer_path($path)
802
- {
803
- $path = str_replace('\\','/',$path);
804
- $values = explode('/',$path);
805
- return implode(DIRECTORY_SEPARATOR,$values);
806
- }
807
-
808
- public function get_file_list($root,$exclude_regex,$include_regex,$exclude_file_size)
809
- {
810
- $files=array();
811
- $this->getFileLoop($files,$root,$exclude_regex,$include_regex,$exclude_file_size);
812
- return $files;
813
- }
814
-
815
- public function getFileLoop(&$files,$path,$exclude_regex=array(),$include_regex=array(),$exclude_file_size=0,$include_dir = true)
816
- {
817
- $count = 0;
818
- if(is_dir($path))
819
- {
820
- $handler = opendir($path);
821
- if($handler!==false)
822
- {
823
- while (($filename = readdir($handler)) !== false)
824
- {
825
- if ($filename != "." && $filename != "..") {
826
- $count++;
827
-
828
- if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
829
- {
830
- if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)) {
831
- if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1)) {
832
- $this->getFileLoop($files, $path . DIRECTORY_SEPARATOR . $filename, $exclude_regex, $include_regex, $exclude_file_size, $include_dir);
833
- }
834
- }
835
- } else {
836
- if($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)){
837
- if ($exclude_file_size == 0)
838
- {
839
- if(is_readable($path . DIRECTORY_SEPARATOR . $filename))
840
- {
841
- $files[] = $path . DIRECTORY_SEPARATOR . $filename;
842
- }
843
- } else {
844
- if(is_readable($path . DIRECTORY_SEPARATOR . $filename))
845
- {
846
- if (filesize($path . DIRECTORY_SEPARATOR . $filename) < $exclude_file_size * 1024 * 1024) {
847
- $files[] = $path . DIRECTORY_SEPARATOR . $filename;
848
- }
849
- }
850
- }
851
- }
852
- }
853
- }
854
- }
855
- if($handler)
856
- @closedir($handler);
857
- }
858
-
859
- }
860
- if($include_dir && $count == 0){
861
- $files[] = $path;
862
- }
863
- }
864
-
865
- private function regex_match($regex_array,$string,$mode)
866
- {
867
- if(empty($regex_array))
868
- {
869
- return true;
870
- }
871
-
872
- if($mode==0)
873
- {
874
- foreach ($regex_array as $regex)
875
- {
876
- if(preg_match($regex,$string))
877
- {
878
- return false;
879
- }
880
- }
881
-
882
- return true;
883
- }
884
-
885
- if($mode==1)
886
- {
887
- foreach ($regex_array as $regex)
888
- {
889
- if(preg_match($regex,$string))
890
- {
891
- return true;
892
- }
893
- }
894
-
895
- return false;
896
- }
897
-
898
- return true;
899
- }
900
-
901
- public function get_need_cleanup_files($all=false)
902
- {
903
- $files=array();
904
- if($this->task['options']['backup_options']['ismerge']==1)
905
- {
906
- foreach ($this->task['options']['backup_options']['backup'] as $backup_finished_data)
907
- {
908
- if($all===false)
909
- {
910
- if(WPVIVID_BACKUP_TYPE_MERGE==$backup_finished_data['key'])
911
- continue;
912
- }
913
-
914
- $files=array_merge($files,$this->get_backup_file($backup_finished_data['key']));
915
- add_filter('wpvivid_get_need_cleanup_files', array($this, 'wpvivid_get_need_cleanup_files'),10,2);
916
- $files=apply_filters('wpvivid_get_need_cleanup_files',$files,$backup_finished_data);
917
- }
918
- }
919
-
920
- return $files;
921
- }
922
-
923
- public function wpvivid_get_need_cleanup_files($files,$backup_finished_data)
924
- {
925
- if(WPVIVID_BACKUP_TYPE_PLUGIN==$backup_finished_data['key'])
926
- {
927
- $general_setting=WPvivid_Setting::get_setting(true, "");
928
- if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
929
- if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
930
- $packages_files_info = $this->get_packages_files_info(WPVIVID_BACKUP_TYPE_PLUGIN);
931
- if ($packages_files_info !== false) {
932
- foreach ($packages_files_info as $file_data) {
933
- $path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $this->task['options']['backup_options']['dir'] . DIRECTORY_SEPARATOR . $file_data['file_name'];
934
- if (!in_array($path, $files))
935
- $files[] = $path;
936
- }
937
- }
938
- }
939
- }
940
- }
941
- else if(WPVIVID_BACKUP_TYPE_UPLOADS_FILES==$backup_finished_data['key'])
942
- {
943
- $general_setting=WPvivid_Setting::get_setting(true, "");
944
- if(isset($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']) && !empty($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload'])){
945
- if($general_setting['options']['wpvivid_compress_setting']['subpackage_plugin_upload']){
946
- $packages_files_info = $this->get_packages_files_info(WPVIVID_BACKUP_TYPE_UPLOADS_FILES);
947
- if ($packages_files_info !== false) {
948
- foreach ($packages_files_info as $file_data) {
949
- $path = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $this->task['options']['backup_options']['dir'] . DIRECTORY_SEPARATOR . $file_data['file_name'];
950
- global $wpvivid_plugin;
951
- $wpvivid_plugin->wpvivid_log->WriteLog('test:' . $path, 'notice');
952
- if (!in_array($path, $files))
953
- $files[] = $path;
954
- }
955
- }
956
- }
957
- }
958
- }
959
- return $files;
960
- }
961
-
962
- public function get_prefix()
963
- {
964
- return $this->task['options']['backup_options']['prefix'];
965
- }
966
-
967
- public function set_file_and_db_info($db_size,$file_size)
968
- {
969
- $this->task['data']['backup']['db_size']=$db_size;
970
- $this->task['data']['backup']['files_size']=$file_size;
971
-
972
- WPvivid_Setting::update_task($this->task['id'],$this->task);
973
- }
974
-
975
- public function get_file_info()
976
- {
977
- $file_size['sum_size']=0;
978
- $file_size['sum_count']=0;
979
-
980
- $memory_limit = ini_get('memory_limit');
981
- $ret['memory_limit']=$memory_limit;
982
- $memory_limit = trim($memory_limit);
983
- $memory_limit_int = (int) $memory_limit;
984
- $last = strtolower(substr($memory_limit, -1));
985
-
986
- if($last == 'g')
987
- $memory_limit_int = $memory_limit_int*1024*1024*1024;
988
- if($last == 'm')
989
- $memory_limit_int = $memory_limit_int*1024*1024;
990
- if($last == 'k')
991
- $memory_limit_int = $memory_limit_int*1024;
992
-
993
- $files=array();
994
-
995
- foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
996
- {
997
- if(!isset($backup_data['dump_db']))
998
- {
999
- if(array_key_exists($backup_data['key'],$this->backup_type_collect))
1000
- {
1001
- $backup_files = $this->get_need_backup_files_size($backup_data);
1002
- }
1003
- else
1004
- {
1005
- $backup_data['files']=array();
1006
- $backup_files =apply_filters('wpvivid_get_custom_need_backup_files_size', $backup_data['files'],$backup_data,$this->task['options']['backup_options']['compress']);
1007
- }
1008
- $files=array_merge($backup_files,$files);
1009
- }
1010
- }
1011
-
1012
- foreach ($files as $file)
1013
- {
1014
- $size=0;
1015
- $_file_size=filesize($file);
1016
- if($_file_size>($memory_limit_int*0.9))
1017
- {
1018
- $ret['alter_big_file']=true;
1019
- $ret['alter_files']=true;
1020
- }
1021
- $size+=$_file_size;
1022
- $file_size['sum_count']++;
1023
- $file_size['sum_size']+=$size;
1024
- }
1025
- return $file_size;
1026
- }
1027
-
1028
- public function is_cancel_file_exist()
1029
- {
1030
- $file_name=$this->task['options']['file_prefix'];
1031
-
1032
- $file=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$file_name.'_cancel';
1033
-
1034
- if(file_exists($file))
1035
- {
1036
- return true;
1037
- }
1038
- else
1039
- {
1040
- return false;
1041
- }
1042
- }
1043
-
1044
- public function update_status($status)
1045
- {
1046
- $this->task['status']['str']=$status;
1047
- WPvivid_Setting::update_task($this->task['id'],$this->task);
1048
- }
1049
-
1050
- public function get_backup_task_info($task_id){
1051
- $list_tasks['status']=WPvivid_taskmanager::get_backup_tasks_status($task_id);
1052
- $list_tasks['is_canceled']=WPvivid_taskmanager::is_task_canceled($task_id);
1053
- $list_tasks['size']=WPvivid_taskmanager::get_backup_size($task_id);
1054
- $list_tasks['data']=WPvivid_taskmanager::get_backup_tasks_progress($task_id);
1055
- //
1056
- $list_tasks['task_info']['need_next_schedule']=false;
1057
- if($list_tasks['status']['str']=='running'||$list_tasks['status']['str']=='no_responds')
1058
- {
1059
- if($list_tasks['data']['running_stamp']>180) {
1060
- $list_tasks['task_info']['need_next_schedule'] = true;
1061
- }
1062
- else{
1063
- $list_tasks['task_info']['need_next_schedule'] = false;
1064
- }
1065
- }
1066
- //
1067
- $general_setting=WPvivid_Setting::get_setting(true, "");
1068
- if($general_setting['options']['wpvivid_common_setting']['estimate_backup'] == 0){
1069
- $list_tasks['task_info']['display_estimate_backup'] = 'display: none';
1070
- }
1071
- else{
1072
- $list_tasks['task_info']['display_estimate_backup'] = '';
1073
- }
1074
- //
1075
- $list_tasks['task_info']['backup_percent']=$list_tasks['data']['progress'].'%';
1076
- //
1077
- if($list_tasks['size']['db_size'] == false){
1078
- $list_tasks['task_info']['db_size']=0;
1079
- }
1080
- else{
1081
- $list_tasks['task_info']['db_size']=$list_tasks['size']['db_size'];
1082
- }
1083
- if($list_tasks['size']['files_size'] == false){
1084
- $list_tasks['task_info']['file_size']=0;
1085
- }
1086
- else{
1087
- $list_tasks['task_info']['file_size']=$list_tasks['size']['files_size']['sum'];
1088
- }
1089
- //
1090
- $list_tasks['task_info']['descript']='';
1091
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
1092
- $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
1093
- $list_tasks['task_info']['total'] = 'N/A';
1094
- $list_tasks['task_info']['upload'] = 'N/A';
1095
- $list_tasks['task_info']['speed'] = 'N/A';
1096
- $list_tasks['task_info']['network_connection'] = 'N/A';
1097
-
1098
- $list_tasks['task_info']['need_update_last_task']=false;
1099
- if($list_tasks['status']['str']=='ready')
1100
- {
1101
- $list_tasks['task_info']['descript']=__('Ready to backup. Progress: 0%, running time: 0second.','wpvivid-backuprestore');
1102
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: none; opacity: 0.4;';
1103
- $list_tasks['task_info']['css_btn_log']='pointer-events: none; opacity: 0.4;';
1104
- }
1105
- else if($list_tasks['status']['str']=='running')
1106
- {
1107
- if($list_tasks['is_canceled'] == false)
1108
- {
1109
- if($list_tasks['data']['type'] == 'upload')
1110
- {
1111
- if(isset($list_tasks['data']['upload_data']) && !empty($list_tasks['data']['upload_data'])) {
1112
- $descript = $list_tasks['data']['upload_data']['descript'];
1113
- $offset = $list_tasks['data']['upload_data']['offset'];
1114
- $current_size = $list_tasks['data']['upload_data']['current_size'];
1115
- $last_time = $list_tasks['data']['upload_data']['last_time'];
1116
- $last_size = $list_tasks['data']['upload_data']['last_size'];
1117
- $speed = ($offset - $last_size) / (time() - $last_time);
1118
- $speed /= 1000;
1119
- $speed = round($speed, 2);
1120
- $speed .= 'kb/s';
1121
- if(!empty($current_size)) {
1122
- $list_tasks['task_info']['total'] = size_format($current_size,2);
1123
- }
1124
- if(!empty($offset)) {
1125
- $list_tasks['task_info']['upload'] = size_format($offset, 2);
1126
- }
1127
- }
1128
- else{
1129
- $descript = 'Start uploading.';
1130
- $speed = '0kb/s';
1131
- $list_tasks['task_info']['total'] = 'N/A';
1132
- $list_tasks['task_info']['upload'] = 'N/A';
1133
- }
1134
-
1135
- $list_tasks['task_info']['speed'] = $speed;
1136
- $list_tasks['task_info']['descript'] = $descript.' '.__('Progress: ', 'wpvivid-backuprestore') . $list_tasks['task_info']['backup_percent'] . ', ' . __('running time: ', 'wpvivid-backuprestore') . $list_tasks['data']['running_time'];
1137
-
1138
- $time_spend=time()-$list_tasks['status']['run_time'];
1139
- if($time_spend>30)
1140
- {
1141
- $list_tasks['task_info']['network_connection']='Retrying';
1142
- }
1143
- else
1144
- {
1145
- $list_tasks['task_info']['network_connection']='OK';
1146
- }
1147
- }
1148
- else {
1149
- $list_tasks['task_info']['descript'] = $list_tasks['data']['descript'] . ' '. __('Progress: ', 'wpvivid-backuprestore') . $list_tasks['task_info']['backup_percent'] . ', '. __('running time: ', 'wpvivid-backuprestore') . $list_tasks['data']['running_time'];
1150
- }
1151
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
1152
- $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
1153
- }
1154
- else{
1155
- $list_tasks['task_info']['descript']=__('The backup will be canceled after backing up the current chunk ends.','wpvivid-backuprestore');
1156
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: none; opacity: 0.4;';
1157
- $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
1158
- }
1159
- }
1160
- else if($list_tasks['status']['str']=='wait_resume'){
1161
- $list_tasks['task_info']['descript']='Task '.$task_id.' timed out, backup task will retry in '.$list_tasks['data']['next_resume_time'].' seconds, retry times: '.$list_tasks['status']['resume_count'].'.';
1162
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
1163
- $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
1164
- }
1165
- else if($list_tasks['status']['str']=='no_responds'){
1166
- if($list_tasks['is_canceled'] == false){
1167
- $list_tasks['task_info']['descript']='Task , '.$list_tasks['data']['doing'].' is not responding. Progress: '.$list_tasks['task_info']['backup_percent'].', running time: '.$list_tasks['data']['running_time'];
1168
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
1169
- $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
1170
- }
1171
- else{
1172
- $list_tasks['task_info']['descript']=__('The backup will be canceled after backing up the current chunk ends.','wpvivid-backuprestore');
1173
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: none; opacity: 0.4;';
1174
- $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
1175
- }
1176
- }
1177
- else if($list_tasks['status']['str']=='completed'){
1178
- $list_tasks['task_info']['descript']='Task '.$task_id.' completed.';
1179
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
1180
- $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
1181
- $list_tasks['task_info']['need_update_last_task']=true;
1182
- }
1183
- else if($list_tasks['status']['str']=='error'){
1184
- $list_tasks['task_info']['descript']='Backup error: '.$list_tasks['status']['error'];
1185
- $list_tasks['task_info']['css_btn_cancel']='pointer-events: auto; opacity: 1;';
1186
- $list_tasks['task_info']['css_btn_log']='pointer-events: auto; opacity: 1;';
1187
- $list_tasks['task_info']['need_update_last_task']=true;
1188
- }
1189
-
1190
- return $list_tasks;
1191
- }
1192
-
1193
- public function get_packages_info($key)
1194
- {
1195
- if(isset($this->task['data']['backup']['sub_job'][$key]))
1196
- {
1197
- if(empty($this->task['data']['backup']['sub_job'][$key]['job_data']))
1198
- {
1199
- return false;
1200
- }
1201
- else
1202
- {
1203
- $packages=array();
1204
- foreach ($this->task['data']['backup']['sub_job'][$key]['job_data'] as $key=>$package)
1205
- {
1206
- if($key=='files')
1207
- {
1208
- continue;
1209
- }
1210
-
1211
- $packages[]=$package;
1212
- }
1213
- if(empty($packages))
1214
- {
1215
- return false;
1216
- }
1217
- else
1218
- {
1219
- return $packages;
1220
- }
1221
- }
1222
- }
1223
- else
1224
- {
1225
- return false;
1226
- }
1227
- }
1228
-
1229
- public function get_packages_files_info($key)
1230
- {
1231
- if(isset($this->task['data']['backup']['sub_job'][$key]))
1232
- {
1233
- if(empty($this->task['data']['backup']['sub_job'][$key]['job_data']))
1234
- {
1235
- return false;
1236
- }
1237
- else
1238
- {
1239
- if(isset($this->task['data']['backup']['sub_job'][$key]['job_data']['files']))
1240
- {
1241
- return $this->task['data']['backup']['sub_job'][$key]['job_data']['files'];
1242
- }
1243
- else
1244
- {
1245
- return false;
1246
- }
1247
- }
1248
- }
1249
- else
1250
- {
1251
- return false;
1252
- }
1253
- }
1254
-
1255
- public function set_packages_info($key,$packages)
1256
- {
1257
- $this->task=WPvivid_taskmanager::get_task($this->task['id']);
1258
- $job_data=array();
1259
- foreach ($packages as $package)
1260
- {
1261
- $package['backup']=false;
1262
- $job_data[basename($package['path'])]=$package;
1263
- }
1264
- $this->task['data']['backup']['sub_job'][$key]['job_data']=$job_data;
1265
- WPvivid_Setting::update_task($this->task['id'],$this->task);
1266
- return $job_data;
1267
- }
1268
-
1269
- public function update_packages_info($key,$package,$file_data=false)
1270
- {
1271
- $this->task=WPvivid_taskmanager::get_task($this->task['id']);
1272
- $this->task['data']['backup']['sub_job'][$key]['job_data'][basename($package['path'])]=$package;
1273
- if($file_data!==false)
1274
- {
1275
- $this->task['data']['backup']['sub_job'][$key]['job_data']['files'][]=$file_data;
1276
- }
1277
- WPvivid_Setting::update_task($this->task['id'],$this->task);
1278
- }
1279
-
1280
- public function update_sub_task_progress($key,$finished,$progress)
1281
- {
1282
- $this->task=WPvivid_taskmanager::get_task($this->task['id']);
1283
- $this->task['status']['run_time']=time();
1284
- $this->task['status']['str']='running';
1285
- $this->task['data']['doing']='backup';
1286
- $sub_job_name=$key;
1287
- $this->task['data']['backup']['doing']=$key;
1288
- $this->task['data']['backup']['sub_job'][$sub_job_name]['finished']=$finished;
1289
- $this->task['data']['backup']['sub_job'][$sub_job_name]['progress']=$progress;
1290
- if(!isset( $this->task['data']['backup']['sub_job'][$sub_job_name]['job_data']))
1291
- {
1292
- $this->task['data']['backup']['sub_job'][$sub_job_name]['job_data']=array();
1293
- }
1294
- WPvivid_Setting::update_task($this->task['id'],$this->task);
1295
- }
1296
-
1297
- public function get_need_backup_folder($backup_data)
1298
- {
1299
- if(isset($backup_data['files'])&&empty($backup_data['files']))
1300
- {
1301
- return $backup_data['files'];
1302
- }
1303
- else
1304
- {
1305
- return $this->get_folder_list($backup_data['files_root'],$backup_data['exclude_regex'],$backup_data['include_regex'],$this->task['options']['backup_options']['compress']['exclude_file_size']);
1306
- }
1307
- }
1308
-
1309
- public function get_folder_list($root,$exclude_regex,$include_regex,$exclude_file_size)
1310
- {
1311
- $files=array();
1312
- $this->getFolder($files,$root,$exclude_regex,$include_regex,$exclude_file_size);
1313
- return $files;
1314
- }
1315
-
1316
- public function getFolder(&$files,$path,$exclude_regex=array(),$include_regex=array(),$exclude_file_size=0,$include_dir = true)
1317
- {
1318
- $count = 0;
1319
- if(is_dir($path))
1320
- {
1321
- $handler = opendir($path);
1322
- if($handler!==false)
1323
- {
1324
- while (($filename = readdir($handler)) !== false)
1325
- {
1326
- if ($filename != "." && $filename != "..")
1327
- {
1328
- $count++;
1329
-
1330
- if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
1331
- {
1332
- if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0))
1333
- {
1334
- if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1))
1335
- {
1336
- $files[] = $path . DIRECTORY_SEPARATOR . $filename;
1337
- }
1338
- }
1339
- } else {
1340
- if($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0)){
1341
- if ($exclude_file_size == 0)
1342
- {
1343
- if(is_readable($path . DIRECTORY_SEPARATOR . $filename))
1344
- {
1345
- $files[] = $path . DIRECTORY_SEPARATOR . $filename;
1346
- }
1347
- } else {
1348
- if(is_readable($path . DIRECTORY_SEPARATOR . $filename))
1349
- {
1350
- if (filesize($path . DIRECTORY_SEPARATOR . $filename) < $exclude_file_size * 1024 * 1024)
1351
- {
1352
- $files[] = $path . DIRECTORY_SEPARATOR . $filename;
1353
- }
1354
- }
1355
- }
1356
- }
1357
- }
1358
- }
1359
- }
1360
- if($handler)
1361
- @closedir($handler);
1362
- }
1363
- }
1364
- if($include_dir && $count == 0)
1365
- {
1366
- $files[] = $path;
1367
- }
1368
- }
1369
-
1370
- public function get_need_uploads_backup_folder($backup_data)
1371
- {
1372
- if(isset($backup_data['files'])&&empty($backup_data['files']))
1373
- {
1374
- return $backup_data['files'];
1375
- }
1376
- else
1377
- {
1378
- return $this->get_uploads_folder_list($backup_data['files_root'],$backup_data['exclude_regex'],$backup_data['include_regex'],$this->task['options']['backup_options']['compress']['exclude_file_size']);
1379
- }
1380
- }
1381
-
1382
- public function get_uploads_folder_list($root,$exclude_regex,$include_regex,$exclude_file_size)
1383
- {
1384
- $files=array();
1385
- $files[] = $root;
1386
- $this->getUploadsFolder($files,$root,$exclude_regex,$include_regex,$exclude_file_size);
1387
- return $files;
1388
- }
1389
-
1390
- public function getUploadsFolder(&$files,$path,$exclude_regex=array(),$include_regex=array(),$exclude_file_size=array(),$include_dir = true)
1391
- {
1392
- $count = 0;
1393
- if(is_dir($path))
1394
- {
1395
- $handler = opendir($path);
1396
- if($handler===false)
1397
- return;
1398
- while (($filename = readdir($handler)) !== false)
1399
- {
1400
- if ($filename != "." && $filename != "..")
1401
- {
1402
- $count++;
1403
-
1404
- if (is_dir($path . DIRECTORY_SEPARATOR . $filename))
1405
- {
1406
- if ($this->regex_match($exclude_regex, $path . DIRECTORY_SEPARATOR . $filename, 0))
1407
- {
1408
- if ($this->regex_match($include_regex, $path . DIRECTORY_SEPARATOR . $filename, 1))
1409
- {
1410
- $this->getUploadsFolder($files,$path . DIRECTORY_SEPARATOR . $filename,$exclude_regex,$include_regex,$exclude_file_size,$include_dir);
1411
- }
1412
- }
1413
- }
1414
- }
1415
- }
1416
- if($handler)
1417
- @closedir($handler);
1418
- }
1419
- if($include_dir && $count == 0)
1420
- {
1421
- $files[] = $path;
1422
- }
1423
- }
1424
-
1425
- public function add_new_backup()
1426
- {
1427
- $this->task=WPvivid_taskmanager::get_task($this->task['id']);
1428
- $backup_data=array();
1429
- $backup_data['type']=$this->task['type'];
1430
- $status=WPvivid_taskmanager::get_backup_task_status($this->task['id']);
1431
- $backup_data['create_time']=$status['start_time'];
1432
- $backup_data['manual_delete']=0;
1433
- $backup_options=WPvivid_taskmanager::get_task_options($this->task['id'],'backup_options');
1434
- $lock=WPvivid_taskmanager::get_task_options($this->task['id'],'lock');
1435
- $backup_data['local']['path']=$backup_options['dir'];
1436
- $backup_data['compress']['compress_type']=$backup_options['compress']['compress_type'];
1437
- $backup_data['save_local']=$this->task['options']['save_local'];
1438
- if(isset($this->task['options']['backup_prefix']))
1439
- {
1440
- $backup_data['backup_prefix'] = $this->task['options']['backup_prefix'];
1441
- }
1442
-
1443
- global $wpvivid_plugin;
1444
- $backup_data['log']=$wpvivid_plugin->wpvivid_log->log_file;
1445
- $backup_data['backup']=$this->get_backup_result();
1446
- $backup_data['remote']=array();
1447
- if($lock==1)
1448
- $backup_data['lock']=1;
1449
-
1450
- $backup_list='wpvivid_backup_list';
1451
-
1452
- $backup_list=apply_filters('get_wpvivid_backup_list_name',$backup_list,$this->task['id']);
1453
-
1454
- $list = WPvivid_Setting::get_option($backup_list);
1455
- $list[$this->task['id']]=$backup_data;
1456
- WPvivid_Setting::update_option($backup_list,$list);
1457
- }
1458
-
1459
- public function get_backup_files()
1460
- {
1461
- $files=array();
1462
- foreach ($this->task['options']['backup_options']['backup'] as $backup_data)
1463
- {
1464
- if($this->task['options']['backup_options']['ismerge']==1)
1465
- {
1466
- if(WPVIVID_BACKUP_TYPE_MERGE==$backup_data['key'])
1467
- {
1468
- if($backup_data['result']!==false)
1469
- {
1470
- $ret=$backup_data['result'];
1471
- if($ret['result']===WPVIVID_SUCCESS)
1472
- {
1473
- foreach ($ret['files'] as $file)
1474
- {
1475
- $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$file['file_name'];
1476
- }
1477
- }
1478
- }
1479
- }
1480
- }
1481
- else
1482
- {
1483
- if($backup_data['result']!==false)
1484
- {
1485
- $ret=$backup_data['result'];
1486
- if($ret['result']===WPVIVID_SUCCESS)
1487
- {
1488
- foreach ($ret['files'] as $file)
1489
- {
1490
- $files[]=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->task['options']['backup_options']['dir'].DIRECTORY_SEPARATOR.$file['file_name'];
1491
- }
1492
- }
1493
- }
1494
- }
1495
- }
1496
-
1497
- return $files;
1498
- }
1499
- }
1500
-
1501
- class WPvivid_Backup_Item
1502
- {
1503
- private $config;
1504
-
1505
- public function __construct($options)
1506
- {
1507
- $this->config=$options;
1508
- }
1509
-
1510
- public function get_backup_type()
1511
- {
1512
- return $this->config['type'];
1513
- }
1514
-
1515
- public function get_files($has_dir=true)
1516
- {
1517
- $files=array();
1518
- if(isset($this->config['backup']['files']))
1519
- {
1520
- //file_name
1521
- foreach ($this->config['backup']['files'] as $file)
1522
- {
1523
- if($has_dir)
1524
- $files[]=$this->get_local_path().$file['file_name'];
1525
- else
1526
- $files[]=$file['file_name'];
1527
- }
1528
- }
1529
- else{
1530
- if(isset($this->config['backup']['data']['meta']['files']))
1531
- {
1532
- foreach ($this->config['backup']['data']['meta']['files'] as $file)
1533
- {
1534
- if($has_dir)
1535
- $files[]=$this->get_local_path().$file['file_name'];
1536
- else
1537
- $files[]=$file['file_name'];
1538
- }
1539
- }
1540
- }
1541
- return $files;
1542
- }
1543
-
1544
- public function is_lock()
1545
- {
1546
- if(isset($this->config['lock']))
1547
- {
1548
- return $this->config['lock'];
1549
- }
1550
- else{
1551
- return false;
1552
- }
1553
- }
1554
-
1555
- public function check_backup_files()
1556
- {
1557
- global $wpvivid_plugin;
1558
-
1559
- $b_has_data=false;
1560
- $tmp_data=array();
1561
- if(isset($this->config['backup']['files']))
1562
- {
1563
- $b_has_data = true;
1564
- $tmp_data = $this->config['backup']['files'];
1565
- }
1566
- else if(isset($this->config['backup']['data']['meta']['files'])){
1567
- $b_has_data = true;
1568
- $tmp_data = $this->config['backup']['data']['meta']['files'];
1569
- }
1570
-
1571
- if($b_has_data)
1572
- {
1573
- $b_need_download=false;
1574
- $b_not_found=false;
1575
- $b_test=false;
1576
- foreach ($tmp_data as $file)
1577
- {
1578
- $need_download=false;
1579
- $path=$this->get_local_path().$file['file_name'];
1580
- if(file_exists($path))
1581
- {
1582
- if(filesize($path) == $file['size'])
1583
- {
1584
- if($wpvivid_plugin->wpvivid_check_zip_valid())
1585
- {
1586
- $res = TRUE;
1587
- }
1588
- else{
1589
- $res = FALSE;
1590
- }
1591
- }
1592
- else {
1593
- $res = FALSE;
1594
- }
1595
- if ($res !== TRUE)
1596
- {
1597
- $need_download=true;
1598
- }
1599
- }
1600
- else
1601
- {
1602
- $b_test=true;
1603
- $need_download=true;
1604
- }
1605
-
1606
- if($need_download)
1607
- {
1608
- if(empty($this->config['remote']))
1609
- {
1610
- $b_not_found=true;
1611
- $ret['files'][$file['file_name']]['status']='file_not_found';
1612
- $ret['files'][$file['file_name']]['size']=$file['size'];
1613
- //$ret['files'][$file['file_name']]['md5']=$file['md5'];
1614
- }
1615
- else
1616
- {
1617
- $b_need_download=true;
1618
- WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
1619
- $ret['files'][$file['file_name']]['status']='need_download';
1620
- $ret['files'][$file['file_name']]['size']=$file['size'];
1621
- //$ret['files'][$file['file_name']]['md5']=$file['md5'];
1622
- }
1623
- }
1624
- }
1625
-
1626
- if($b_not_found)
1627
- {
1628
- $ret['result']=WPVIVID_FAILED;
1629
- if($b_test)
1630
- $ret['error']='Backup files doesn\'t exist. Restore failed.';
1631
- else
1632
- $ret['error']='Backup doesn\'t exist in both web server and remote storage. Restore failed.';
1633
- }
1634
- else if($b_need_download)
1635
- {
1636
- $ret['result']='need_download';
1637
- }
1638
- else
1639
- {
1640
- $ret['result']=WPVIVID_SUCCESS;
1641
- }
1642
- }
1643
- else
1644
- {
1645
- $ret['result']=WPVIVID_FAILED;
1646
- $ret['error']='Unknown error.';
1647
- }
1648
-
1649
- return $ret;
1650
- }
1651
-
1652
- public function check_migrate_file()
1653
- {
1654
- if(isset($this->config['backup']['files']))
1655
- {
1656
- $tmp_data = $this->config['backup']['files'];
1657
- $zip=new WPvivid_ZipClass();
1658
-
1659
- foreach ($tmp_data as $file)
1660
- {
1661
- $path=$this->get_local_path().$file['file_name'];
1662
- if(file_exists($path))
1663
- {
1664
- $ret=$zip->get_json_data($path);
1665
- if($ret['result'] === WPVIVID_SUCCESS) {
1666
- $json=$ret['json_data'];
1667
- $json = json_decode($json, 1);
1668
- if (!is_null($json)) {
1669
- if (isset($json['home_url']) && home_url() != $json['home_url']) {
1670
- return 1;
1671
- }
1672
- }
1673
- else{
1674
- return 0;
1675
- }
1676
- }
1677
- elseif($ret['result'] === WPVIVID_FAILED){
1678
- return 0;
1679
- }
1680
- }
1681
- }
1682
- return 0;
1683
- }
1684
- else
1685
- {
1686
- return 0;
1687
- }
1688
-
1689
- }
1690
-
1691
- public function is_display_migrate_option(){
1692
- if(isset($this->config['backup']['files']))
1693
- {
1694
- $tmp_data = $this->config['backup']['files'];
1695
- $zip=new WPvivid_ZipClass();
1696
-
1697
- foreach ($tmp_data as $file)
1698
- {
1699
- $path=$this->get_local_path().$file['file_name'];
1700
- if(file_exists($path))
1701
- {
1702
- $ret=$zip->get_json_data($path);
1703
- if($ret['result'] === WPVIVID_SUCCESS) {
1704
- $json=$ret['json_data'];
1705
- $json = json_decode($json, 1);
1706
- if (!is_null($json)) {
1707
- if (isset($json['home_url'])){
1708
- return false;
1709
- }
1710
- else{
1711
- return true;
1712
- }
1713
- }
1714
- else{
1715
- return true;
1716
- }
1717
- }
1718
- elseif($ret['result'] === WPVIVID_FAILED){
1719
- return true;
1720
- }
1721
- }
1722
- }
1723
- return true;
1724
- }
1725
- else
1726
- {
1727
- return true;
1728
- }
1729
- }
1730
-
1731
- public function get_local_path()
1732
- {
1733
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR;
1734
- $path=apply_filters('wpvivid_get_site_wpvivid_path',$path,$this->config['local']['path']);
1735
- return $path;
1736
- }
1737
-
1738
- public function get_local_url()
1739
- {
1740
- $url=content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR;
1741
- $url=apply_filters('wpvivid_get_site_wpvivid_url',$url,$this->config['local']['path']);
1742
- return $url;
1743
- }
1744
-
1745
- public function get_remote()
1746
- {
1747
- $remote_option=array_shift($this->config['remote']);
1748
-
1749
- if(is_null($remote_option))
1750
- {
1751
- return false;
1752
- }
1753
- else
1754
- {
1755
- return $remote_option;
1756
- }
1757
- }
1758
-
1759
- public function get_backup_packages()
1760
- {
1761
- $packages=array();
1762
- $index=0;
1763
-
1764
- if(isset($this->config['backup']['files']))
1765
- {
1766
- $db_package=array();
1767
- $file_added=array();
1768
- //file_name
1769
- foreach ($this->config['backup']['files'] as $file)
1770
- {
1771
- if(isset($file_added[$file['file_name']]))
1772
- {
1773
- continue;
1774
- }
1775
-
1776
- if (preg_match('/wpvivid-.*_.*_.*\.part[0-9]+\.zip$/', $file['file_name'],$matches))
1777
- {
1778
- $this->get_all_part_files($file['file_name'],$this->config['backup']['files'],$packages[$index],$file_added);
1779
- }
1780
- else
1781
- {
1782
- if($this->check_file_is_a_db_package($file['file_name']))
1783
- {
1784
- $db_package['files'][]=$file['file_name'];
1785
- }
1786
- else
1787
- {
1788
- $packages[$index]['files'][]=$file['file_name'];
1789
- }
1790
- $file_added[$file['file_name']]=1;
1791
- }
1792
- $index++;
1793
- }
1794
-
1795
- $file_added=array();
1796
- $child_packages=array();
1797
-
1798
- foreach ($packages as $key=>$package)
1799
- {
1800
- $files=array();
1801
-
1802
- foreach ($package['files'] as $package_files)
1803
- {
1804
- $files=array_merge($files,$this->get_child_files($package_files));
1805
- }
1806
-
1807
- if(empty($files))
1808
- {
1809
- continue;
1810
- }
1811
-
1812
- foreach ($files as $file)
1813
- {
1814
- if (isset($file_added[$file['file_name']]))
1815
- {
1816
- continue;
1817
- }
1818
-
1819
- if (preg_match('/wpvivid-.*_.*_.*\.part[0-9]+\.zip$/', $file['file_name'],$matches))
1820
- {
1821
- $this->get_all_part_files($file['file_name'],$files,$child_packages[$index],$file_added);
1822
- }
1823
- else
1824
- {
1825
- if($this->check_file_is_a_db_package($file['file_name']))
1826
- {
1827
- $db_package['files'][]=$file['file_name'];
1828
- }
1829
- else
1830
- {
1831
- $child_packages[$index]['files'][]=$file['file_name'];
1832
- }
1833
- $file_added[$file['file_name']]=1;
1834
- }
1835
- $index++;
1836
- }
1837
- }
1838
-
1839
- $packages=array_merge($packages,$child_packages);
1840
- if(!empty($db_package))
1841
- {
1842
- $packages[$index]=$db_package;
1843
- }
1844
- }
1845
- else if(isset($this->config['backup']['data']))
1846
- {
1847
- if(isset($this->config['backup']['ismerge'])&&$this->config['backup']['ismerge']==1)
1848
- {
1849
- $packages[$index]['option']['has_child']=1;
1850
- //$packages[$index]['option']['root']='wp-content';
1851
- $packages[$index]['option']['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
1852
- foreach ($this->config['backup']['data']['meta']['files'] as $file)
1853
- {
1854
- $packages[$index]['files'][]=$file['file_name'];
1855
- }
1856
- $index++;
1857
- }
1858
-
1859
- foreach ($this->config['backup']['data']['type'] as $type)
1860
- {
1861
- if($type['type_name']=='backup_db')
1862
- {
1863
- $packages[$index]['option']['dump_db']=1;
1864
- //$packages[$index]['option']['root']='wp-content\\'.$this->config['local']['path'];
1865
- $packages[$index]['option']['root_flag']=WPVIVID_BACKUP_ROOT_CUSTOM;
1866
- }
1867
- else if($type['type_name']=='backup_themes')
1868
- {
1869
- //$packages[$index]['option']['root']='wp-content';
1870
- $packages[$index]['option']['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
1871
- }
1872
- else if($type['type_name']=='backup_plugin')
1873
- {
1874
- //$packages[$index]['option']['root']='wp-content';
1875
- $packages[$index]['option']['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
1876
- }
1877
- else if($type['type_name']=='backup_uploads')
1878
- {
1879
- //$packages[$index]['option']['root']='wp-content';
1880
- $packages[$index]['option']['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
1881
- }
1882
- else if($type['type_name']=='backup_content')
1883
- {
1884
- //$packages[$index]['option']['root']='';
1885
- $packages[$index]['option']['root_flag']=WPVIVID_BACKUP_ROOT_WP_ROOT;
1886
- }
1887
- else if($type['type_name']=='backup_core')
1888
- {
1889
- //$packages[$index]['option']['root']='';
1890
- $packages[$index]['option']['root_flag']=WPVIVID_BACKUP_ROOT_WP_ROOT;
1891
- $packages[$index]['option']['include_path'][]='wp-includes';
1892
- $packages[$index]['option']['include_path'][]='wp-admin';
1893
- }
1894
-
1895
- foreach ($type['files'] as $file)
1896
- {
1897
- $packages[$index]['files'][]=$file['file_name'];
1898
- }
1899
- $index++;
1900
- }
1901
- }
1902
- return $packages;
1903
- }
1904
-
1905
- public function check_file_is_a_db_package($file_name)
1906
- {
1907
- //backup_db.zip
1908
- if (preg_match('#.*_backup_db.zip?#', $file_name, $matches))
1909
- {
1910
- return true;
1911
- }
1912
- else
1913
- {
1914
- return false;
1915
- }
1916
- }
1917
-
1918
- public function get_all_part_files($file_name,$files,&$package,&$file_added)
1919
- {
1920
- if (preg_match('#\.part[0-9]+\.zip$#',$file_name,$matches))
1921
- {
1922
- $prefix=$matches[0];
1923
- $file_prefix=substr($file_name,0,strlen($file_name)-strlen($prefix));
1924
- foreach ($files as $file)
1925
- {
1926
- if(isset($file_added[$file['file_name']]))
1927
- {
1928
- continue;
1929
- }
1930
-
1931
- if (strpos($file['file_name'], $file_prefix) !== false)
1932
- {
1933
- $package['files'][]=$file['file_name'];
1934
- $file_added[$file['file_name']]=1;
1935
- }
1936
- }
1937
- }
1938
- }
1939
-
1940
- public function get_child_files($file_name)
1941
- {
1942
- $zip=new WPvivid_ZipClass();
1943
-
1944
- $path=$this->get_local_path().$file_name;
1945
-
1946
- $files = array();
1947
-
1948
- $ret=$zip->get_json_data($path);
1949
-
1950
- if($ret['result'] === WPVIVID_SUCCESS) {
1951
- $json=$ret['json_data'];
1952
- $json = json_decode($json, 1);
1953
- if (isset($json['has_child'])) {
1954
- $files = $zip->list_file($path);
1955
- }
1956
- }
1957
- return $files;
1958
- }
1959
-
1960
- public function get_file_info($file_name)
1961
- {
1962
- $zip=new WPvivid_ZipClass();
1963
-
1964
- $path=$this->get_local_path().$file_name;
1965
-
1966
- $ret=$zip->get_json_data($path);
1967
- if($ret['result'] === WPVIVID_SUCCESS) {
1968
- $json=$ret['json_data'];
1969
- $json = json_decode($json, 1);
1970
- if (is_null($json)) {
1971
- return false;
1972
- } else {
1973
- return $json;
1974
- }
1975
- }
1976
- elseif($ret['result'] === WPVIVID_FAILED){
1977
- return false;
1978
- }
1979
- }
1980
-
1981
- static public function get_backup_file_info($file_name)
1982
- {
1983
- $zip=new WPvivid_ZipClass();
1984
- $ret=$zip->get_json_data($file_name);
1985
- if($ret['result'] === WPVIVID_SUCCESS)
1986
- {
1987
- $json=$ret['json_data'];
1988
- $json = json_decode($json, 1);
1989
- if (is_null($json)) {
1990
- return array('result'=>WPVIVID_FAILED,'error'=>'Failed to decode json');
1991
- } else {
1992
- return array('result'=>WPVIVID_SUCCESS,'json_data'=>$json);
1993
- }
1994
- }
1995
- elseif($ret['result'] === WPVIVID_FAILED){
1996
- return $ret;
1997
- }
1998
- }
1999
-
2000
- public function get_sql_file($file_name)
2001
- {
2002
- $zip=new WPvivid_ZipClass();
2003
- $path=$this->get_local_path().$file_name;
2004
- $files=$zip->list_file($path);
2005
- return $files[0]['file_name'];
2006
- }
2007
-
2008
- public static function get_backup_files($backup){
2009
- $files=array();
2010
- if(isset($backup['backup']['files'])){
2011
- $files=$backup['backup']['files'];
2012
- }
2013
- else{
2014
- if(isset($backup['backup']['ismerge'])) {
2015
- if ($backup['backup']['ismerge'] == 1) {
2016
- if(isset($backup['backup']['data']['meta']['files'])){
2017
- $files=$backup['backup']['data']['meta']['files'];
2018
- }
2019
- }
2020
- }
2021
- }
2022
- asort($files);
2023
- uasort($files, function ($a, $b) {
2024
- $file_name_1 = $a['file_name'];
2025
- $file_name_2 = $b['file_name'];
2026
- $index_1 = 0;
2027
- if(preg_match('/wpvivid-.*_.*_.*\.part.*\.zip$/', $file_name_1)) {
2028
- if (preg_match('/part.*$/', $file_name_1, $matches)) {
2029
- $index_1 = $matches[0];
2030
- $index_1 = preg_replace("/part/","", $index_1);
2031
- $index_1 = preg_replace("/.zip/","", $index_1);
2032
- }
2033
- }
2034
- $index_2 = 0;
2035
- if(preg_match('/wpvivid-.*_.*_.*\.part.*\.zip$/', $file_name_2)) {
2036
- if (preg_match('/part.*$/', $file_name_2, $matches)) {
2037
- $index_2 = $matches[0];
2038
- $index_2 = preg_replace("/part/", "", $index_2);
2039
- $index_2 = preg_replace("/.zip/", "", $index_2);
2040
- }
2041
- }
2042
- if($index_1 !== 0 && $index_2 === 0){
2043
- return -1;
2044
- }
2045
- if($index_1 === 0 && $index_2 !== 0){
2046
- return 1;
2047
- }
2048
- });
2049
- return $files;
2050
- }
2051
-
2052
- public function get_download_backup_files($backup_id){
2053
- $ret['result']=WPVIVID_FAILED;
2054
- $data=array();
2055
- $backup=WPvivid_Backuplist::get_backup_by_id($backup_id);
2056
- if(!$backup)
2057
- {
2058
- $ret['error']='Backup id not found.';
2059
- return $ret;
2060
- }
2061
-
2062
- $files=array();
2063
- $files = self::get_backup_files($backup);
2064
- if(empty($files)){
2065
- $ret['error']='Failed to get backup files.';
2066
- }
2067
- else{
2068
- $ret['result']=WPVIVID_SUCCESS;
2069
- $ret['files']=$files;
2070
- }
2071
- return $ret;
2072
- }
2073
-
2074
- public function get_download_progress($backup_id, $files){
2075
- global $wpvivid_plugin;
2076
- $b_need_download=false;
2077
- $b_not_found=false;
2078
- $file_count=0;
2079
- $file_part_num=1;
2080
- $check_type='';
2081
- foreach ($files as $file)
2082
- {
2083
- $need_download=false;
2084
- $path=$this->get_local_path().$file['file_name'];
2085
- $download_url=content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file['file_name'];
2086
- if(file_exists($path)) {
2087
- if(filesize($path) == $file['size']){
2088
- if($wpvivid_plugin->wpvivid_check_zip_valid()) {
2089
- $res = TRUE;
2090
- }
2091
- else{
2092
- $res = FALSE;
2093
- }
2094
- }
2095
- else{
2096
- $res = FALSE;
2097
- }
2098
- if ($res !== TRUE)
2099
- {
2100
- $need_download=true;
2101
- }
2102
- }
2103
- else {
2104
- $need_download=true;
2105
- }
2106
- if($file_part_num < 10){
2107
- $format_part=sprintf("%02d", $file_part_num);
2108
- }
2109
- else{
2110
- $format_part=$file_part_num;
2111
- }
2112
- if($need_download) {
2113
- if(empty($this->config['remote'])) {
2114
- $b_not_found=true;
2115
- $ret['result'] = WPVIVID_SUCCESS;
2116
- $ret['files'][$file['file_name']]['status']='file_not_found';
2117
- }
2118
- else{
2119
- $task = WPvivid_taskmanager::get_download_task_v2($file['file_name']);
2120
- $ret['task']=$task;
2121
- if ($task === false) {
2122
- $ret['result'] = WPVIVID_SUCCESS;
2123
- $ret['files'][$file['file_name']]['status']='need_download';
2124
- $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;">
2125
- <span>Part'.$format_part.'</span></br>
2126
- <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>
2127
- <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>
2128
- <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
2129
- </div>';
2130
- } else {
2131
- $ret['result'] = WPVIVID_SUCCESS;
2132
- if($task['status'] === 'running'){
2133
- $ret['files'][$file['file_name']]['status'] = 'running';
2134
- $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;">
2135
- <span>Part'.$format_part.'</span></br>
2136
- <span id=\''.$backup_id.'-text-part-'.$file_part_num.'\'><a >Retriving(remote storage to web server)</a></span></br>
2137
- <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>
2138
- <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
2139
- </div>';
2140
- $ret['files'][$file['file_name']]['progress_text']=$task['progress_text'];
2141
- }
2142
- elseif($task['status'] === 'timeout'){
2143
- $ret['files'][$file['file_name']]['status']='timeout';
2144
- $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;">
2145
- <span>Part'.$format_part.'</span></br>
2146
- <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>
2147
- <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>
2148
- <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
2149
- </div>';
2150
- $ret['files'][$file['file_name']]['progress_text']=$task['progress_text'];
2151
- WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
2152
- }
2153
- elseif($task['status'] === 'completed'){
2154
- $ret['files'][$file['file_name']]['status']='completed';
2155
- $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;">
2156
- <span>Part'.$format_part.'</span></br>
2157
- <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>
2158
- <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>
2159
- <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
2160
- </div>';
2161
- WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
2162
- }
2163
- elseif($task['status'] === 'error'){
2164
- $ret['files'][$file['file_name']]['status']='error';
2165
- $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;">
2166
- <span>Part'.$format_part.'</span></br>
2167
- <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>
2168
- <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>
2169
- <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
2170
- </div>';
2171
- $ret['files'][$file['file_name']]['error'] = $task['error'];
2172
- WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
2173
- }
2174
- }
2175
- }
2176
- }
2177
- else{
2178
- $ret['result'] = WPVIVID_SUCCESS;
2179
- if(WPvivid_taskmanager::get_download_task_v2($file['file_name']))
2180
- WPvivid_taskmanager::delete_download_task_v2($file['file_name']);
2181
- $ret['files'][$file['file_name']]['status']='completed';
2182
- $ret['files'][$file['file_name']]['download_path']=$path;
2183
- $ret['files'][$file['file_name']]['download_url']=$download_url;
2184
- $ret['files'][$file['file_name']]['html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;">
2185
- <span>Part'.$format_part.'</span></br>
2186
- <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>
2187
- <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>
2188
- <span>size:</span><span>'.$wpvivid_plugin->formatBytes($file['size']).'</span>
2189
- </div>';
2190
- }
2191
- $ret['files'][$file['file_name']]['size']=$wpvivid_plugin->formatBytes($file['size']);
2192
- $file_count++;
2193
- $file_part_num++;
2194
- }
2195
- if ($file_count % 2 != 0) {
2196
- $file_count++;
2197
- if($file_count < 10){
2198
- $format_part=sprintf("%02d", $file_count);
2199
- }
2200
- else{
2201
- $format_part=$file_count;
2202
- }
2203
- $ret['place_html']='<div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px; color:#cccccc;">
2204
- <span>Part'.$format_part.'</span></br>
2205
- <span>Download</span></br>
2206
- <div style="width:100%;height:5px; background-color:#dcdcdc;"><div style="background-color:#0085ba; float:left;width:0;height:5px;"></div></div>
2207
- <span>size:</span><span>0</span>
2208
- </div>';
2209
- }
2210
- else{
2211
- $ret['place_html']='';
2212
- }
2213
- return $ret;
2214
- }
2215
-
2216
- public function update_download_page($backup_id){
2217
- $ret=$this->get_download_backup_files($backup_id);
2218
- if($ret['result']==WPVIVID_SUCCESS){
2219
- $ret=$this->get_download_progress($backup_id, $ret['files']);
2220
- WPvivid_taskmanager::update_download_cache($backup_id,$ret);
2221
- }
2222
- return $ret;
2223
- }
2224
-
2225
- public function cleanup_local_backup()
2226
- {
2227
- $files=array();
2228
- $download_dir=$this->config['local']['path'];
2229
- $file=$this->get_files(false);
2230
-
2231
- foreach ($file as $filename)
2232
- {
2233
- $files[] = $filename;
2234
- }
2235
-
2236
- foreach ($files as $file)
2237
- {
2238
- $download_path = WP_CONTENT_DIR .DIRECTORY_SEPARATOR . $download_dir . DIRECTORY_SEPARATOR . $file;
2239
- if (file_exists($download_path))
2240
- {
2241
- @unlink($download_path);
2242
- }
2243
- }
2244
- }
2245
-
2246
- public function cleanup_remote_backup()
2247
- {
2248
- if(!empty($this->config['remote']))
2249
- {
2250
- $files=$this->get_files(false);
2251
-
2252
- foreach($this->config['remote'] as $remote)
2253
- {
2254
- WPvivid_downloader::delete($remote,$files);
2255
- }
2256
- }
2257
- }
2258
- }
2259
-
2260
- class WPvivid_Backup
2261
- {
2262
- public $task;
2263
- public $backup_type_report = '';
2264
- //public $config;
2265
-
2266
- public function __construct($task_id=false,$task=false)
2267
- {
2268
- if($task_id!==false)
2269
- {
2270
- $this->task=new WPvivid_Backup_Task($task_id);
2271
- }
2272
- else if($task!==false)
2273
- {
2274
- $this->task=new WPvivid_Backup_Task(false,$task);
2275
- }
2276
- else
2277
- {
2278
- $this->task=new WPvivid_Backup_Task();
2279
- }
2280
- //$this->config=$config;
2281
- }
2282
-
2283
- public function init_options($task_id)
2284
- {
2285
- $this->task=new WPvivid_Backup_Task($task_id);
2286
- }
2287
-
2288
- public function backup($task_id)
2289
- {
2290
- $this->init_options($task_id);
2291
- $next_backup=$this->task->get_need_backup();
2292
-
2293
- $this->backup_type_report = '';
2294
-
2295
- while($next_backup!==false)
2296
- {
2297
- global $wpvivid_plugin;
2298
- $wpvivid_plugin->set_time_limit($this->task->get_id());
2299
- $this->task->update_sub_task_progress($next_backup['key'],0, sprintf(__('Start backing up %s.', 'wpvivid-backuprestore'), $next_backup['key']));
2300
- $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to backup '.$next_backup['key'].' files.','notice');
2301
- $this->backup_type_report .= $next_backup['key'].',';
2302
- if(isset($next_backup['files'])) {
2303
- $wpvivid_plugin->wpvivid_log->WriteLog('File number: ' . sizeof($next_backup['files']), 'notice');
2304
- }
2305
- $result = $this->_backup($next_backup);
2306
- $wpvivid_plugin->wpvivid_log->WriteLog('Backing up '.$next_backup['key'].' completed.','notice');
2307
- $this->task->update_sub_task_progress($next_backup['key'],1, sprintf(__('Backing up %s finished.', 'wpvivid-backuprestore'), $next_backup['key']));
2308
- $this->task->update_backup_result($next_backup,$result);
2309
- $wpvivid_plugin->check_cancel_backup($task_id);
2310
- unset($next_backup);
2311
- $next_backup=$this->task->get_need_backup();
2312
- }
2313
-
2314
- WPvivid_Setting::update_option('wpvivid_backup_report', $this->backup_type_report);
2315
- $this->cleanup();
2316
-
2317
- $ret=$this->task->get_backup_result();
2318
- return $ret;
2319
- }
2320
-
2321
- private function _backup($data)
2322
- {
2323
- global $wpvivid_plugin;
2324
- $result['result']=WPVIVID_FAILED;
2325
- $result['error']='test error';
2326
-
2327
- $is_type_db = false;
2328
- $is_type_db = apply_filters('wpvivid_check_type_database', $is_type_db, $data);
2329
- if($is_type_db)
2330
- {
2331
- include_once WPVIVID_PLUGIN_DIR .'/includes/class-wpvivid-backup-database.php';
2332
- $wpvivid_plugin->wpvivid_log->WriteLog('Start exporting database.','notice');
2333
- $backup_database = new WPvivid_Backup_Database();
2334
- $result = $backup_database -> backup_database($data,$this->task->get_id());
2335
- $wpvivid_plugin->wpvivid_log->WriteLog('Exporting database finished.','notice');
2336
- if($result['result']==WPVIVID_SUCCESS)
2337
- {
2338
- $data['files']=$result['files'];
2339
- }
2340
- else
2341
- {
2342
- return $result;
2343
- }
2344
- }
2345
-
2346
- include_once WPVIVID_PLUGIN_DIR . '/includes/class-wpvivid-zipclass.php';
2347
-
2348
- $zip = new WPvivid_ZipClass();
2349
- if(is_array($zip->last_error))
2350
- {
2351
- return $zip->last_error;
2352
- }
2353
-
2354
- if(isset($data['resume_packages']))
2355
- {
2356
- global $wpvivid_plugin;
2357
- $wpvivid_plugin->wpvivid_log->WriteLog('Start compressing '.$data['key'],'notice');
2358
-
2359
- $packages=$this->task->get_packages_info($data['key']);
2360
- if($packages===false)
2361
- {
2362
- if(isset($data['plugin_subpackage']))
2363
- {
2364
- $ret =$zip->get_plugin_packages($data);
2365
- }
2366
- else if(isset($data['uploads_subpackage']))
2367
- {
2368
- $ret =$zip->get_upload_packages($data);
2369
- }
2370
- else
2371
- {
2372
- if($data['key']==WPVIVID_BACKUP_TYPE_MERGE)
2373
- $ret =$zip->get_packages($data,true);
2374
- else
2375
- $ret =$zip->get_packages($data);
2376
- }
2377
-
2378
- $packages=$this->task->set_packages_info($data['key'],$ret['packages']);
2379
- }
2380
-
2381
- $temp_dir = $data['path'].'temp-'.$data['prefix'].DIRECTORY_SEPARATOR;
2382
- define(PCLZIP_TEMPORARY_DIR,$temp_dir);
2383
-
2384
- $result['result']=WPVIVID_SUCCESS;
2385
- $result['files']=array();
2386
- foreach ($packages as $package)
2387
- {
2388
- $wpvivid_plugin->set_time_limit($this->task->get_id());
2389
- if(!empty($package['files'])&&$package['backup']==false)
2390
- {
2391
- if(isset($data['uploads_subpackage']))
2392
- {
2393
- $files=$zip->get_upload_files_from_cache($package['files']);
2394
- }
2395
- else
2396
- {
2397
- $files=$package['files'];
2398
- }
2399
-
2400
- if(empty($files))
2401
- continue;
2402
-
2403
- $zip_ret=$zip->_zip($package['path'],$files, $data,$package['json']);
2404
- if($zip_ret['result']==WPVIVID_SUCCESS)
2405
- {
2406
- if(isset($data['uploads_subpackage']))
2407
- {
2408
- if(file_exists($package['files']))
2409
- {
2410
- @unlink($package['files']);
2411
- }
2412
- }
2413
-
2414
- $result['files'][] = $zip_ret['file_data'];
2415
- $package['backup']=true;
2416
- $this->task->update_packages_info($data['key'],$package,$zip_ret['file_data']);
2417
- if($data['key']==WPVIVID_BACKUP_TYPE_MERGE)
2418
- {
2419
- $this->cleanup_finished_package($package['files']);
2420
- }
2421
- }
2422
- else
2423
- {
2424
- $result=$zip_ret;
2425
- break;
2426
- }
2427
- }else {
2428
- continue;
2429
- }
2430
- }
2431
- $wpvivid_plugin->wpvivid_log->WriteLog('Compressing '.$data['key'].' completed','notice');
2432
- return $result;
2433
- }
2434
- else
2435
- {
2436
- $is_additional_db = false;
2437
- $is_additional_db = apply_filters('wpvivid_check_additional_database', $is_additional_db, $data);
2438
- if($is_additional_db){
2439
- $result =$zip->compress_additional_database($data);
2440
- }
2441
- else {
2442
- $result =$zip->compress($data);
2443
- }
2444
-
2445
- if($is_type_db)
2446
- {
2447
- foreach ($data['files'] as $sql_file)
2448
- {
2449
- @unlink($sql_file);
2450
- }
2451
- }
2452
- }
2453
-
2454
- return $result;
2455
- }
2456
-
2457
- public function cleanup()
2458
- {
2459
- $files=$this->task->get_need_cleanup_files();
2460
-
2461
- foreach ($files as $file)
2462
- {
2463
- if(file_exists($file)) {
2464
- global $wpvivid_plugin;
2465
- $wpvivid_plugin->wpvivid_log->WriteLog('Cleaned up file, filename: '.$file,'notice');
2466
- @unlink($file);
2467
- }
2468
- }
2469
- }
2470
-
2471
- public function cleanup_finished_package($files)
2472
- {
2473
- foreach ($files as $file)
2474
- {
2475
- if(file_exists($file))
2476
- {
2477
- global $wpvivid_plugin;
2478
- $wpvivid_plugin->wpvivid_log->WriteLog('Cleaned up file, filename: '.$file,'notice');
2479
- @unlink($file);
2480
- }
2481
- }
2482
- }
2483
-
2484
- public function clean_backup()
2485
- {
2486
- $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
2487
- $handler=opendir($path);
2488
- if($handler!==false)
2489
- {
2490
- while(($filename=readdir($handler))!==false)
2491
- {
2492
- if(preg_match('#'.$this->task->get_id().'#',$filename) || preg_match('#'.apply_filters('wpvivid_fix_wpvivid_free', $this->task->get_id()).'#',$filename))
2493
- {
2494
- @unlink($path.DIRECTORY_SEPARATOR.$filename);
2495
- }
2496
- }
2497
- @closedir($handler);
2498
- }
2499
- }
2500
-
2501
- public function clearcache()
2502
- {
2503
- $task_id=$this->task->get_prefix();
2504
- $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir();
2505
- $handler=opendir($path);
2506
- if($handler!==false)
2507
- {
2508
- while(($filename=readdir($handler))!==false)
2509
- {
2510
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename) && preg_match('#temp-'.$task_id.'#',$filename))
2511
- {
2512
- $this->deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
2513
- }
2514
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename) && preg_match('#temp-'.$task_id.'#',$filename))
2515
- {
2516
- $this->deldir($path.DIRECTORY_SEPARATOR.$filename,'',true);
2517
- }
2518
- if(preg_match('#pclzip-.*\.tmp#', $filename)){
2519
- @unlink($path.DIRECTORY_SEPARATOR.$filename);
2520
- }
2521
- if(preg_match('#pclzip-.*\.gz#', $filename)){
2522
- @unlink($path.DIRECTORY_SEPARATOR.$filename);
2523
- }
2524
- }
2525
- @closedir($handler);
2526
- }
2527
-
2528
- }
2529
-
2530
- public function deldir($path,$exclude=array(),$flag = false)
2531
- {
2532
- if(!is_dir($path))
2533
- {
2534
- return ;
2535
- }
2536
- $handler=opendir($path);
2537
- if(empty($handler))
2538
- return ;
2539
- while(($filename=readdir($handler))!==false)
2540
- {
2541
- if($filename != "." && $filename != "..")
2542
- {
2543
- if(is_dir($path.DIRECTORY_SEPARATOR.$filename)){
2544
- if(empty($exclude)||$this->regex_match($exclude['directory'],$path.DIRECTORY_SEPARATOR.$filename ,0)){
2545
- $this->deldir( $path.DIRECTORY_SEPARATOR.$filename ,$exclude, $flag);
2546
- @rmdir( $path.DIRECTORY_SEPARATOR.$filename );
2547
- }
2548
- }else{
2549
- if(empty($exclude)||$this->regex_match($exclude['file'],$path.DIRECTORY_SEPARATOR.$filename ,0)){
2550
- @unlink($path.DIRECTORY_SEPARATOR.$filename);
2551
- }
2552
- }
2553
- }
2554
- }
2555
- if($handler)
2556
- @closedir($handler);
2557
- if($flag)
2558
- @rmdir($path);
2559
- }
2560
-
2561
- public function regex_match($regex_array,$string,$mode)
2562
- {
2563
- if(empty($regex_array))
2564
- {
2565
- return true;
2566
- }
2567
-
2568
- if($mode==0)
2569
- {
2570
- foreach ($regex_array as $regex)
2571
- {
2572
- if(preg_match($regex,$string))
2573
- {
2574
- return false;
2575
- }
2576
- }
2577
-
2578
- return true;
2579
- }
2580
-
2581
- if($mode==1)
2582
- {
2583
- foreach ($regex_array as $regex)
2584
- {
2585
- if(preg_match($regex,$string))
2586
- {
2587
- return true;
2588
- }
2589
- }
2590
-
2591
- return false;
2592
- }
2593
-
2594
- return true;
2595
- }
2596
-
2597
- public function clean_remote_backup($remotes,$files)
2598
- {
2599
- $remote_option=array_shift($remotes);
2600
-
2601
- if(!is_null($remote_option))
2602
- {
2603
- global $wpvivid_plugin;
2604
-
2605
- $remote=$wpvivid_plugin->remote_collection->get_remote($remote_option);
2606
- $remote ->cleanup($files);
2607
- }
2608
- }
2609
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-backuplist.php DELETED
@@ -1,374 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
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
- }
100
- }
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
- }
119
-
120
- public static function add_new_upload_backup($task_id,$backup,$time,$log='')
121
- {
122
- $backup_data=array();
123
- $backup_data['type']='Upload';
124
- $backup_data['create_time']=$time;
125
- $backup_data['manual_delete']=0;
126
- $backup_data['local']['path']=WPvivid_Setting::get_backupdir();
127
- $backup_data['compress']['compress_type']='zip';
128
- $backup_data['save_local']=1;
129
- $backup_data['log']=$log;
130
-
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
- }
161
-
162
- public static function sort_list($list)
163
- {
164
- uasort ($list,function($a, $b)
165
- {
166
- if($a['create_time']>$b['create_time'])
167
- {
168
- return -1;
169
- }
170
- else if($a['create_time']===$b['create_time'])
171
- {
172
- return 0;
173
- }
174
- else
175
- {
176
- return 1;
177
- }
178
- });
179
-
180
- return $list;
181
- }
182
-
183
- public static function get_oldest_backup_id($list)
184
- {
185
- $oldest_id='';
186
- $oldest=0;
187
- foreach ($list as $k=>$backup)
188
- {
189
- if(!array_key_exists('lock',$backup))
190
- {
191
- if ($oldest == 0)
192
- {
193
- $oldest = $backup['create_time'];
194
- $oldest_id = $k;
195
- } else {
196
- if ($oldest > $backup['create_time'])
197
- {
198
- $oldest_id = $k;
199
- }
200
- }
201
- }
202
- }
203
- return $oldest_id;
204
- }
205
-
206
- public static function check_backuplist_limit($max_count)
207
- {
208
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
209
- $size=sizeof($list);
210
- if($size>=$max_count)
211
- {
212
- $oldest_id=self::get_oldest_backup_id($list);
213
- if(empty($oldest_id))
214
- {
215
- return false;
216
- }
217
- else
218
- {
219
- return $oldest_id;
220
- }
221
- }
222
- else
223
- {
224
- return false;
225
- }
226
- }
227
-
228
- public static function get_out_of_date_backuplist($max_count)
229
- {
230
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
231
- $size=sizeof($list);
232
- $out_of_date_list=array();
233
-
234
- if($max_count==0)
235
- return $out_of_date_list;
236
-
237
- while($size>$max_count)
238
- {
239
- $oldest_id=self::get_oldest_backup_id($list);
240
-
241
- if(!empty($oldest_id))
242
- {
243
- $out_of_date_list[]=$oldest_id;
244
- unset($list[$oldest_id]);
245
- }
246
- $new_size=sizeof($list);
247
- if($new_size==$size)
248
- {
249
- break;
250
- }
251
- else
252
- {
253
- $size=$new_size;
254
- }
255
- }
256
-
257
- return $out_of_date_list;
258
- }
259
-
260
- public static function get_out_of_date_backuplist_info($max_count)
261
- {
262
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
263
- $size=sizeof($list);
264
- $out_of_date_list['size']=0;
265
- $out_of_date_list['count']=0;
266
-
267
- if($max_count==0)
268
- return $out_of_date_list;
269
-
270
- while($size>$max_count)
271
- {
272
- $oldest_id=self::get_oldest_backup_id($list);
273
-
274
- if(!empty($oldest_id))
275
- {
276
- $out_of_date_list['size']+=self::get_size($oldest_id);
277
- $out_of_date_list['count']++;
278
- unset($list[$oldest_id]);
279
- }
280
- $new_size=sizeof($list);
281
- if($new_size==$size)
282
- {
283
- break;
284
- }
285
- else
286
- {
287
- $size=$new_size;
288
- }
289
- }
290
-
291
- return $out_of_date_list;
292
- }
293
-
294
- public static function get_size($backup_id)
295
- {
296
- $size=0;
297
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
298
- $backup=$list[$backup_id];
299
- if(isset($backup['backup']['files'])){
300
- foreach ($backup['backup']['files'] as $file) {
301
- $size+=$file['size'];
302
- }
303
- }
304
- else{
305
- if(isset($backup['backup']['data']['type'])){
306
- foreach ($backup['backup']['data']['type'] as $type) {
307
- foreach ($type['files'] as $file) {
308
- $size+=$file['size'];
309
- }
310
- }
311
- }
312
- }
313
-
314
- return $size;
315
- }
316
- public static function set_security_lock($backup_id,$lock)
317
- {
318
- //$list = WPvivid_Setting::get_option('wpvivid_backup_list');
319
- $ret = self::get_backuplist_by_id($backup_id);
320
- if($ret !== false) {
321
- $list = $ret['list_data'];
322
- if (array_key_exists($backup_id, $list)) {
323
- if ($lock == 1) {
324
- $list[$backup_id]['lock'] = 1;
325
- }
326
- else {
327
- if (array_key_exists('lock', $list[$backup_id])) {
328
- unset($list[$backup_id]['lock']);
329
- }
330
- }
331
- }
332
- WPvivid_Setting::update_option($ret['list_name'], $list);
333
- }
334
-
335
- $ret['result'] = 'success';
336
- $list = WPvivid_Setting::get_option($ret['list_name']);
337
- if (array_key_exists($backup_id, $list)) {
338
- if (isset($list[$backup_id]['lock'])) {
339
- if ($list[$backup_id]['lock'] == 1) {
340
- $backup_lock = '/admin/partials/images/locked.png';
341
- $lock_status = 'lock';
342
- $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid-backuprestore') . '" onclick="wpvivid_set_backup_lock(\''.$backup_id.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>';
343
- } else {
344
- $backup_lock = '/admin/partials/images/unlocked.png';
345
- $lock_status = 'unlock';
346
- $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid-backuprestore') . '" onclick="wpvivid_set_backup_lock(\''.$backup_id.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>';
347
- }
348
- } else {
349
- $backup_lock = '/admin/partials/images/unlocked.png';
350
- $lock_status = 'unlock';
351
- $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid-backuprestore') . '" onclick="wpvivid_set_backup_lock(\''.$backup_id.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>';
352
- }
353
- } else {
354
- $backup_lock = '/admin/partials/images/unlocked.png';
355
- $lock_status = 'unlock';
356
- $ret['html'] = '<img src="' . esc_url(WPVIVID_PLUGIN_URL . $backup_lock) . '" name="' . esc_attr($lock_status, 'wpvivid-backuprestore') . '" onclick="wpvivid_set_backup_lock(\''.$backup_id.'\', \''.$lock_status.'\');" style="vertical-align:middle; cursor:pointer;"/>';
357
- }
358
- return $ret;
359
- }
360
-
361
- public static function get_has_remote_backuplist()
362
- {
363
- $backup_id_list=array();
364
- $list = WPvivid_Setting::get_option('wpvivid_backup_list');
365
- foreach ($list as $k=>$backup)
366
- {
367
- if(!empty($backup['remote']))
368
- {
369
- $backup_id_list[]=$k;
370
- }
371
- }
372
- return $backup_id_list;
373
- }
374
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-backuptoremote.php DELETED
@@ -1,55 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
-
7
- require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-ftpclass.php';
8
- require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-sftpclass.php';
9
- require_once WPVIVID_PLUGIN_DIR . '/includes/customclass/class-wpvivid-amazons3-plus.php';
10
- class WPvivid_Backup_Remote
11
- {
12
-
13
- public function backup_with_ftp($data = array())
14
- {
15
- $host = $data['options']['host'];
16
- $username = $data['options']['username'];
17
- $password = $data['options']['password'];
18
- $path = $data['options']['path'];
19
- $passive = $data['options']['passive'];
20
- $port = empty($data['options']['port'])?21:$data['options']['port'];
21
-
22
- $ftpclass = new WPvivid_FTPClass();
23
- $res = $ftpclass -> upload($host,$username,$password,$path,$data['files'],$data['task_id'],$passive,$port,$data['log']);
24
- return $res;
25
- }
26
-
27
- public function backup_with_sftp($data)
28
- {
29
- if(empty($data['port']))
30
- $data['options']['port'] = 22;
31
- $host = $data['options']['host'];
32
- $username = $data['options']['username'];
33
- $password = $data['options']['password'];
34
- $path = $data['options']['path'];
35
- $port = $data['options']['port'];
36
- $scp = $data['options']['scp'];
37
-
38
- $sftpclass = new WPvivid_SFTPClass();
39
- $result = $sftpclass -> upload($host,$username,$password,$path,$data['files'],$data['task_id'],$port,$scp,$data['log']);
40
- return $result;
41
- }
42
-
43
- public function backup_with_amazonS3($data = array())
44
- {
45
- $files = $data['files'];
46
- $access = $data['options']['access'];
47
- $secret = $data['options']['secret'];
48
- $s3Path = $data['options']['s3Path'];
49
- $region = $data['options']['region'];
50
- $amazonS3 = new WPvivid_AMAZONS3Class();
51
- $amazonS3 ->init($access,$secret,$region);
52
- $res = $amazonS3 -> upload($files,$s3Path,$data['task_id'],$data['log']);
53
- return $res;
54
- }
55
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-compress-default.php DELETED
@@ -1,81 +0,0 @@
1
- <?php
2
- abstract class Wpvivid_Compress_Default{
3
- public $last_error = '';
4
-
5
- abstract public function compress($data);
6
- abstract public function extract($files,$path = '');
7
- abstract public function extract_by_files($files,$zip,$path = '');
8
- abstract public function get_include_zip($files,$allpackages);
9
- abstract public function listcontent($path);
10
- abstract public function listnum($path , $includeFolder = false);
11
-
12
- public function getLastError(){
13
- return $this -> last_error;
14
- }
15
- public function getBasename($basename){
16
- $basename = basename($basename);
17
- $arr = explode('.',$basename);
18
- return $arr[0];
19
- }
20
- public function _in_array($file,$lists){
21
- foreach ($lists as $item){
22
- if(strstr($file,$item)){
23
- return true;
24
- }
25
- }
26
- return false;
27
- }
28
- public function filesplit($max_size,$files){
29
- $packages = array();
30
- if($max_size == 0 || empty($max_size)){
31
- $packages[] = $files;
32
- }else{
33
- $sizenum = 0;
34
- $max_size = str_replace('M', '', $max_size);
35
- $size = $max_size * 1024 * 1024;
36
- $package = array();
37
- $flag = false;
38
-
39
- usort($files, function ($a, $b)
40
- {
41
- $a_size=filesize($a);
42
- $b_size=filesize($b);
43
- if ($a_size == $b_size)
44
- return 0;
45
-
46
- if ($a_size < $b_size)
47
- return 1;
48
- else
49
- return -1;
50
- });
51
-
52
- foreach ($files as $file)
53
- {
54
- $sizenum += filesize($file);
55
- if($sizenum > $size)
56
- {
57
- if(empty($package))
58
- {
59
- $package[] = $file;
60
- $packages[] = $package;
61
- $package = array();
62
- $sizenum = 0;
63
- }
64
- else
65
- {
66
- $packages[] = $package;
67
- $package = array();
68
- $package[] = $file;
69
- $sizenum = filesize($file);
70
- }
71
-
72
- }else{
73
- $package[] = $file;
74
- }
75
- }
76
- if(!empty($package))
77
- $packages[] = $package;
78
- }
79
- return $packages;
80
- }
81
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-crypt.php DELETED
@@ -1,234 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
-
7
- class WPvivid_crypt
8
- {
9
- private $public_key;
10
- private $sym_key;
11
-
12
- private $rij;
13
- private $rsa;
14
-
15
- public function __construct($public_key)
16
- {
17
- $this->public_key=$public_key;
18
- include_once WPVIVID_PLUGIN_DIR . '/vendor/autoload.php';
19
- $this->rij= new Crypt_Rijndael();
20
- $this->rsa= new Crypt_RSA();
21
- }
22
-
23
- public function generate_key()
24
- {
25
- $this->sym_key = crypt_random_string(32);
26
- $this->rij->setKey($this->sym_key);
27
- }
28
-
29
- public function encrypt_message($message)
30
- {
31
- $this->generate_key();
32
- $key=$this->encrypt_key();
33
- $len=str_pad(dechex(strlen($key)),3,'0', STR_PAD_LEFT);
34
- $message=$this->rij->encrypt($message);
35
- if($message===false)
36
- return false;
37
- $message_len = str_pad(dechex(strlen($message)), 16, '0', STR_PAD_LEFT);
38
- return $len.$key.$message_len.$message;
39
- }
40
-
41
- public function encrypt_key()
42
- {
43
- $this->rsa->loadKey($this->public_key);
44
- return $this->rsa->encrypt($this->sym_key);
45
- }
46
-
47
- public function decrypt_message($message)
48
- {
49
- $len = substr($message, 0, 3);
50
- $len = hexdec($len);
51
- $key = substr($message, 3, $len);
52
-
53
- $cipherlen = substr($message, ($len + 3), 16);
54
- $cipherlen = hexdec($cipherlen);
55
-
56
- $data = substr($message, ($len + 19), $cipherlen);
57
- $rsa = new Crypt_RSA();
58
- $rsa->loadKey($this->public_key);
59
- $key=$rsa->decrypt($key);
60
- $rij = new Crypt_Rijndael();
61
- $rij->setKey($key);
62
- return $rij->decrypt($data);
63
- }
64
-
65
- public function encrypt_user_info($user,$pw)
66
- {
67
- $user_info['user']=$user;
68
- $user_info['pw']=$pw;
69
- $info=json_encode($user_info);
70
- $this->rsa->loadKey($this->public_key);
71
- return $this->rsa->encrypt($info);
72
- }
73
-
74
- public function encrypt_user_token($user,$token)
75
- {
76
- $user_info['user']=$user;
77
- $user_info['token']=$token;
78
- $info=json_encode($user_info);
79
- $this->rsa->loadKey($this->public_key);
80
- return $this->rsa->encrypt($info);
81
- }
82
-
83
- public function encrypt_token($token)
84
- {
85
- $this->rsa->loadKey($this->public_key);
86
- return $this->rsa->encrypt($token);
87
- }
88
- }
89
-
90
- class WPvivid_Crypt_File
91
- {
92
- private $key;
93
- private $rij;
94
-
95
- public function __construct($key)
96
- {
97
- include_once WPVIVID_PLUGIN_DIR . '/vendor/autoload.php';
98
- $this->rij= new Crypt_Rijndael();
99
- $this->key=$key;
100
- }
101
-
102
- public function encrypt($file)
103
- {
104
- $encrypted_path = dirname($file).'/encrypt_'.basename($file).'.tmp';
105
-
106
- $data_encrypted = 0;
107
- $buffer_size = 2097152;
108
-
109
- $file_size = filesize($file);
110
-
111
- $this->rij->setKey($this->key);
112
- $this->rij->disablePadding();
113
- $this->rij->enableContinuousBuffer();
114
-
115
- if (file_exists($encrypted_path))
116
- {
117
- @unlink($encrypted_path);
118
- }
119
- $encrypted_handle = fopen($encrypted_path, 'wb+');
120
-
121
- $file_handle = fopen($file, 'rb');
122
-
123
- if($file_handle===false)
124
- {
125
- $ret['result']='failed';
126
- $ret['error']=$file.' file not found';
127
- return $ret;
128
- }
129
-
130
- while ($data_encrypted < $file_size)
131
- {
132
- $file_part = fread($file_handle, $buffer_size);
133
-
134
- $length = strlen($file_part);
135
- if (0 != $length % 16)
136
- {
137
- $pad = 16 - ($length % 16);
138
- $file_part = str_pad($file_part, $length + $pad, chr($pad));
139
- }
140
-
141
- $encrypted_data = $this->rij->encrypt($file_part);
142
-
143
- fwrite($encrypted_handle, $encrypted_data);
144
-
145
- $data_encrypted += $buffer_size;
146
- }
147
-
148
- fclose($encrypted_handle);
149
- fclose($file_handle);
150
-
151
- $result_path = $file.'.crypt';
152
-
153
- @rename($encrypted_path, $result_path);
154
-
155
- $ret['result']='success';
156
- $ret['file_path']=$result_path;
157
- return $ret;
158
- }
159
-
160
- public function decrypt($file)
161
- {
162
- $file_handle = fopen($file, 'rb');
163
-
164
- if($file_handle===false)
165
- {
166
- $ret['result']='failed';
167
- $ret['error']=$file.' file not found';
168
- return $ret;
169
- }
170
-
171
- $decrypted_path = dirname($file).'/decrypt_'.basename($file).'.tmp';
172
-
173
- $decrypted_handle = fopen($decrypted_path, 'wb+');
174
-
175
- $this->rij->setKey($this->key);
176
- $this->rij->disablePadding();
177
- $this->rij->enableContinuousBuffer();
178
-
179
- $file_size = filesize($file);
180
- $bytes_decrypted = 0;
181
- $buffer_size =2097152;
182
-
183
- while ($bytes_decrypted < $file_size)
184
- {
185
- $file_part = fread($file_handle, $buffer_size);
186
-
187
- $length = strlen($file_part);
188
- if (0 != $length % 16) {
189
- $pad = 16 - ($length % 16);
190
- $file_part = str_pad($file_part, $length + $pad, chr($pad));
191
- }
192
-
193
- $decrypted_data = $this->rij->decrypt($file_part);
194
-
195
- $is_last_block = ($bytes_decrypted + strlen($decrypted_data) >= $file_size);
196
-
197
- $write_bytes = min($file_size - $bytes_decrypted, strlen($decrypted_data));
198
- if ($is_last_block)
199
- {
200
- $is_padding = false;
201
- $last_byte = ord(substr($decrypted_data, -1, 1));
202
- if ($last_byte < 16)
203
- {
204
- $is_padding = true;
205
- for ($j = 1; $j<=$last_byte; $j++)
206
- {
207
- if (substr($decrypted_data, -$j, 1) != chr($last_byte))
208
- $is_padding = false;
209
- }
210
- }
211
- if ($is_padding)
212
- {
213
- $write_bytes -= $last_byte;
214
- }
215
- }
216
-
217
- fwrite($decrypted_handle, $decrypted_data, $write_bytes);
218
- $bytes_decrypted += $buffer_size;
219
- }
220
-
221
- // close the main file handle
222
- fclose($decrypted_handle);
223
- // close original file
224
- fclose($file_handle);
225
-
226
- $fullpath_new = preg_replace('/\.crypt$/', '', $file, 1).'.decrypted.zip';
227
-
228
- @rename($decrypted_path, $fullpath_new);
229
- $ret['result']='success';
230
- $ret['file_path']=$fullpath_new;
231
-
232
- return $ret;
233
- }
234
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-db-method.php DELETED
@@ -1,281 +0,0 @@
1
- <?php
2
-
3
- class WPvivid_DB_Method
4
- {
5
- public $db_handle;
6
- public $type;
7
-
8
- public function connect_db()
9
- {
10
- $common_setting = WPvivid_Setting::get_setting(false, 'wpvivid_common_setting');
11
- $db_connect_method = isset($common_setting['options']['wpvivid_common_setting']['db_connect_method']) ? $common_setting['options']['wpvivid_common_setting']['db_connect_method'] : 'wpdb';
12
- if($db_connect_method === 'wpdb'){
13
- global $wpdb;
14
- $this->db_handle=$wpdb;
15
- $this->type='wpdb';
16
- return array('result'=>WPVIVID_SUCCESS);
17
- }
18
- else{
19
- if(class_exists('PDO')) {
20
- $extensions=get_loaded_extensions();
21
- if(array_search('pdo_mysql',$extensions)) {
22
- $res = explode(':',DB_HOST);
23
- $db_host = $res[0];
24
- $db_port = empty($res[1])?'':$res[1];
25
-
26
- if(!empty($db_port)) {
27
- $dsn='mysql:host=' . $db_host . ';port=' . $db_port . ';dbname=' . DB_NAME;
28
- }
29
- else{
30
- $dsn='mysql:host=' . $db_host . ';dbname=' . DB_NAME;
31
- }
32
-
33
- $this->db_handle=new PDO($dsn, DB_USER, DB_PASSWORD);
34
-
35
- $this->type='pdo_mysql';
36
- return array('result'=>WPVIVID_SUCCESS);
37
- }
38
- else{
39
- return array('result'=>WPVIVID_FAILED, 'error'=>'The pdo_mysql extension is not detected. Please install the extension first or choose wpdb option for Database connection method.');
40
- }
41
- }
42
- else{
43
- return array('result'=>WPVIVID_FAILED, 'error'=>'The pdo_mysql extension is not detected. Please install the extension first or choose wpdb option for Database connection method.');
44
- }
45
- }
46
- }
47
-
48
- public function check_db($fcgi)
49
- {
50
- $ret=$this->connect_db();
51
-
52
- if($ret['result']==WPVIVID_FAILED)
53
- {
54
- return $ret;
55
- }
56
-
57
- if($this->type=='pdo_mysql')
58
- {
59
- return $this->check_db_pdo($fcgi);
60
- }
61
- else if($this->type=='wpdb')
62
- {
63
- return $this->check_db_wpdb($fcgi);
64
- }
65
-
66
- return array('result' => WPVIVID_FAILED,'error' => 'db handle type not found.');
67
- }
68
-
69
- public function check_db_pdo($fcgi)
70
- {
71
- $ret['alert_db']=false;
72
- $ret['result']=WPVIVID_SUCCESS;
73
- $ret['big_tables']=array();
74
- $db_info=array();
75
-
76
- $sth = $this->db_handle->query('SHOW TABLE STATUS');
77
- $dbSize = 0;
78
- $sum_rows=0;
79
- $rows = $sth->fetchAll();
80
- foreach ($rows as $row)
81
- {
82
- global $wpdb;
83
- if (is_multisite() && !defined('MULTISITE'))
84
- {
85
- $prefix = $wpdb->base_prefix;
86
- } else {
87
- $prefix = $wpdb->get_blog_prefix(0);
88
- }
89
- if(preg_match('/^(?!'.$prefix.')/', $row["Name"]) == 1){
90
- continue;
91
- }
92
-
93
- $db_info[$row["Name"]]["Rows"]=$row["Rows"];
94
- $db_info[$row["Name"]]["Data_length"]=size_format($row["Data_length"]+$row["Index_length"],2);
95
- if($row["Rows"]>1000000)
96
- {
97
- $ret['big_tables'][$row["Name"]]['Rows']=$row["Rows"];
98
- $ret['big_tables'][$row["Name"]]['Data_length']=size_format($row["Data_length"]+$row["Index_length"],2);
99
- }
100
-
101
- $sum_rows+=$row["Rows"];
102
- $dbSize+=$row["Data_length"]+$row["Index_length"];
103
- }
104
- if($fcgi)
105
- {
106
- $alter_sum_rows=4000000;
107
- }
108
- else
109
- {
110
- $alter_sum_rows=4000000*3;
111
- }
112
-
113
- $memory_limit = ini_get('memory_limit');
114
- $ret['memory_limit']=$memory_limit;
115
- $memory_limit = trim($memory_limit);
116
- $memory_limit_int = (int) $memory_limit;
117
- $last = strtolower(substr($memory_limit, -1));
118
-
119
- if($last == 'g')
120
- $memory_limit_int = $memory_limit_int*1024*1024*1024;
121
- if($last == 'm')
122
- $memory_limit_int = $memory_limit_int*1024*1024;
123
- if($last == 'k')
124
- $memory_limit_int = $memory_limit_int*1024;
125
-
126
- if($dbSize>($memory_limit_int*0.9))
127
- {
128
- $max_rows=0;
129
- }
130
- else
131
- {
132
- $max_rows=(($memory_limit_int*0.9)-$dbSize)/49;
133
- }
134
-
135
- $max_rows=max($max_rows,1048576);
136
-
137
- if($sum_rows>$alter_sum_rows||$sum_rows>$max_rows)
138
- {
139
- //big db alert
140
- $ret['alert_db']=true;
141
- $ret['sum_rows']=$sum_rows;
142
- $ret['db_size']=size_format($dbSize,2);
143
- if($fcgi)
144
- $ret['alter_fcgi']=true;
145
- }
146
-
147
- $ret['db_size']=size_format($dbSize,2);
148
- return $ret;
149
- }
150
-
151
- public function check_db_wpdb($fcgi)
152
- {
153
- $ret['alert_db']=false;
154
- $ret['result']=WPVIVID_SUCCESS;
155
- $ret['big_tables']=array();
156
- $db_info=array();
157
-
158
- global $wpdb;
159
- $result=$wpdb->get_results('SHOW TABLE STATUS',ARRAY_A);
160
-
161
- //$sth = $this->db_handle->query('SHOW TABLE STATUS');
162
- $dbSize = 0;
163
- $sum_rows=0;
164
- //$rows = $sth->fetchAll();
165
- foreach ($result as $row)
166
- {
167
- global $wpdb;
168
- if (is_multisite() && !defined('MULTISITE'))
169
- {
170
- $prefix = $wpdb->base_prefix;
171
- } else {
172
- $prefix = $wpdb->get_blog_prefix(0);
173
- }
174
- if(preg_match('/^(?!'.$prefix.')/', $row["Name"]) == 1){
175
- continue;
176
- }
177
-
178
- $db_info[$row["Name"]]["Rows"]=$row["Rows"];
179
- $db_info[$row["Name"]]["Data_length"]=size_format($row["Data_length"]+$row["Index_length"],2);
180
- if($row["Rows"]>1000000)
181
- {
182
- $ret['big_tables'][$row["Name"]]['Rows']=$row["Rows"];
183
- $ret['big_tables'][$row["Name"]]['Data_length']=size_format($row["Data_length"]+$row["Index_length"],2);
184
- }
185
-
186
- $sum_rows+=$row["Rows"];
187
- $dbSize+=$row["Data_length"]+$row["Index_length"];
188
- }
189
- if($fcgi)
190
- {
191
- $alter_sum_rows=4000000;
192
- }
193
- else
194
- {
195
- $alter_sum_rows=4000000*3;
196
- }
197
-
198
- $memory_limit = ini_get('memory_limit');
199
- $ret['memory_limit']=$memory_limit;
200
- $memory_limit = trim($memory_limit);
201
- $memory_limit_int = (int) $memory_limit;
202
- $last = strtolower(substr($memory_limit, -1));
203
-
204
- if($last == 'g')
205
- $memory_limit_int = $memory_limit_int*1024*1024*1024;
206
- if($last == 'm')
207
- $memory_limit_int = $memory_limit_int*1024*1024;
208
- if($last == 'k')
209
- $memory_limit_int = $memory_limit_int*1024;
210
-
211
- if($dbSize>($memory_limit_int*0.9))
212
- {
213
- $max_rows=0;
214
- }
215
- else
216
- {
217
- $max_rows=(($memory_limit_int*0.9)-$dbSize)/49;
218
- }
219
-
220
- $max_rows=max($max_rows,1048576);
221
-
222
- if($sum_rows>$alter_sum_rows||$sum_rows>$max_rows)
223
- {
224
- //big db alert
225
- $ret['alert_db']=true;
226
- $ret['sum_rows']=$sum_rows;
227
- $ret['db_size']=size_format($dbSize,2);
228
- if($fcgi)
229
- $ret['alter_fcgi']=true;
230
- }
231
-
232
- $ret['db_size']=size_format($dbSize,2);
233
- return $ret;
234
- }
235
-
236
- public function get_sql_mode()
237
- {
238
- try {
239
- $ret['result'] = WPVIVID_SUCCESS;
240
- $ret['mysql_mode'] = '';
241
-
242
- global $wpdb;
243
- $result = $wpdb->get_results('SELECT @@SESSION.sql_mode', ARRAY_A);
244
- foreach ($result as $row) {
245
- $ret['mysql_mode'] = $row["@@SESSION.sql_mode"];
246
- }
247
- }
248
- catch (Exception $error) {
249
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
250
- error_log($message);
251
- return array('result'=>'failed','error'=>$message);
252
- }
253
-
254
- return $ret;
255
- }
256
-
257
- public function get_mysql_version()
258
- {
259
- global $wpdb;
260
-
261
- $mysql_version = $wpdb->db_version();
262
-
263
- return $mysql_version;
264
- }
265
-
266
- public function check_max_allowed_packet()
267
- {
268
- global $wpvivid_plugin,$wpdb;
269
-
270
- $max_allowed_packet = (int) $wpdb->get_var("SELECT @@session.max_allowed_packet");
271
-
272
- if($max_allowed_packet<1048576)
273
- {
274
- $wpvivid_plugin->wpvivid_log->WriteLog('warning: max_allowed_packet less than 1M :'.size_format($max_allowed_packet,2),'notice');
275
- }
276
- else if($max_allowed_packet<33554432)
277
- {
278
- $wpvivid_plugin->wpvivid_log->WriteLog('max_allowed_packet less than 32M :'.size_format($max_allowed_packet,2),'notice');
279
- }
280
- }
281
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-downloader.php DELETED
@@ -1,184 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
-
7
- class WPvivid_downloader
8
- {
9
- private $task;
10
-
11
- public function ready_download($download_info)
12
- {
13
- $backup=WPvivid_Backuplist::get_backup_by_id($download_info['backup_id']);
14
- if(!$backup)
15
- {
16
- return false;
17
- }
18
-
19
- $file_info=false;
20
-
21
- if(isset($backup['backup']['files']))
22
- {
23
- foreach ($backup['backup']['files'] as $file)
24
- {
25
- if ($file['file_name'] == $download_info['file_name'])
26
- {
27
- $file_info= $file;
28
- break;
29
- }
30
- }
31
- }
32
- else if ($backup['backup']['ismerge'] == 1)
33
- {
34
- $backup_files = $backup['backup']['data']['meta']['files'];
35
- foreach ($backup_files as $file)
36
- {
37
- if ($file['file_name'] == $download_info['file_name'])
38
- {
39
- $file_info = $file;
40
- break;
41
- }
42
- }
43
- } else {
44
- foreach ($backup['backup']['data']['type'] as $type)
45
- {
46
- $backup_files = $type['files'];
47
- foreach ($backup_files as $file) {
48
- if ($file['file_name'] == $download_info['file_name'])
49
- {
50
- $file_info = $file;
51
- break;
52
- }
53
- }
54
- }
55
- }
56
-
57
- if($file_info==false)
58
- {
59
- return false;
60
- }
61
-
62
-
63
- $local_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup['local']['path'].DIRECTORY_SEPARATOR;
64
- $need_download_files=array();
65
-
66
- $local_file=$local_path.$file_info['file_name'];
67
- if(file_exists($local_file))
68
- {
69
- if(filesize($local_file)!=$file_info['size'])
70
- {
71
- if(filesize($local_file)>$file_info['size'])
72
- {
73
- @unlink($local_file);
74
- }
75
- $need_download_files[$file_info['file_name']]=$file_info;
76
- }
77
- }
78
- else {
79
- $need_download_files[$file_info['file_name']]=$file_info;
80
- }
81
-
82
-
83
- if(empty($need_download_files))
84
- {
85
- delete_option('wpvivid_download_cache');
86
- }
87
- else
88
- {
89
- if(WPvivid_taskmanager::is_download_task_running_v2($download_info['file_name']))
90
- {
91
- global $wpvivid_plugin;
92
- $wpvivid_plugin->wpvivid_log->WriteLog('has a downloading task,exit download.','test');
93
- return false;
94
- }
95
- else
96
- {
97
- WPvivid_taskmanager::delete_download_task_v2($download_info['file_name']);
98
- $task=WPvivid_taskmanager::new_download_task_v2($download_info['file_name']);
99
- }
100
- }
101
-
102
- foreach ($need_download_files as $file)
103
- {
104
- $ret=$this->download_ex($task,$backup['remote'],$file,$local_path);
105
- if($ret['result']==WPVIVID_FAILED)
106
- {
107
- return false;
108
- }
109
- }
110
-
111
- return true;
112
- }
113
-
114
- public function download_ex(&$task,$remotes,$file,$local_path)
115
- {
116
- $this->task=$task;
117
-
118
- $remote_option=array_shift($remotes);
119
-
120
- if(is_null($remote_option))
121
- {
122
- return array('result' => WPVIVID_FAILED ,'error'=>'Retrieving the cloud storage information failed while downloading backups. Please try again later.');
123
- }
124
-
125
- global $wpvivid_plugin;
126
-
127
- $remote=$wpvivid_plugin->remote_collection->get_remote($remote_option);
128
-
129
- $ret=$remote->download($file,$local_path,array($this,'download_callback_v2'));
130
-
131
- if($ret['result']==WPVIVID_SUCCESS)
132
- {
133
- $progress=100;
134
- $wpvivid_plugin->wpvivid_download_log->WriteLog('Download completed.', 'notice');
135
- WPvivid_taskmanager::update_download_task_v2( $task,$progress,'completed');
136
- return $ret;
137
- }
138
- else
139
- {
140
- $progress=0;
141
- $message=$ret['error'];
142
- if($wpvivid_plugin->wpvivid_download_log)
143
- {
144
- $wpvivid_plugin->wpvivid_download_log->WriteLog('Download failed, ' . $message ,'error');
145
- $wpvivid_plugin->wpvivid_download_log->CloseFile();
146
- WPvivid_error_log::create_error_log($wpvivid_plugin->wpvivid_download_log->log_file);
147
- }
148
- else {
149
- $id = uniqid('wpvivid-');
150
- $log_file_name = $id . '_download';
151
- $log = new WPvivid_Log();
152
- $log->CreateLogFile($log_file_name, 'no_folder', 'download');
153
- $log->WriteLog($message, 'notice');
154
- $log->CloseFile();
155
- WPvivid_error_log::create_error_log($log->log_file);
156
- }
157
- WPvivid_taskmanager::update_download_task_v2($task,$progress,'error',$message);
158
- return $ret;
159
- }
160
- }
161
-
162
- public function download_callback_v2($offset,$current_name,$current_size,$last_time,$last_size)
163
- {
164
- global $wpvivid_plugin;
165
- $progress= floor(($offset/$current_size)* 100) ;
166
- $text='Total size:'.size_format($current_size,2).' downloaded:'.size_format($offset,2);
167
- $this->task['download_descript']=$text;
168
- $wpvivid_plugin->wpvivid_download_log->WriteLog('Total Size: '.$current_size.', Downloaded Size: '.$offset ,'notice');
169
- WPvivid_taskmanager::update_download_task_v2( $this->task,$progress,'running');
170
- }
171
-
172
- public static function delete($remote , $files)
173
- {
174
- global $wpvivid_plugin;
175
-
176
- @set_time_limit(60);
177
-
178
- $remote=$wpvivid_plugin->remote_collection->get_remote($remote);
179
-
180
- $result =$remote->cleanup($files);
181
-
182
- return $result;
183
- }
184
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-error-log.php DELETED
@@ -1,153 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
- class WPvivid_error_log
7
- {
8
- public static function create_error_log($log_file_name)
9
- {
10
- $dir=dirname($log_file_name);
11
- $file=basename($log_file_name);
12
- if(!is_dir($dir.DIRECTORY_SEPARATOR.'error'))
13
- {
14
- @mkdir($dir.DIRECTORY_SEPARATOR.'error',0777,true);
15
- @fopen($dir.DIRECTORY_SEPARATOR.'error'.'/index.html', 'x');
16
- $tempfile=@fopen($dir.DIRECTORY_SEPARATOR.'error'.'/.htaccess', 'x');
17
- if($tempfile)
18
- {
19
- $text="deny from all";
20
- fwrite($tempfile,$text );
21
- @fclose($tempfile);
22
- }
23
- }
24
-
25
- if(!file_exists($log_file_name))
26
- {
27
- return ;
28
- }
29
-
30
- if(file_exists($dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.$file))
31
- {
32
- @unlink($dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.$file);
33
- }
34
-
35
- @rename($log_file_name,$dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.$file);
36
-
37
- //self::delete_oldest_error_log();
38
- }
39
-
40
- public static function create_restore_error_log($log_file_name)
41
- {
42
- $dir=dirname($log_file_name);
43
- if(!is_dir($dir.DIRECTORY_SEPARATOR.'wpvivid_log'.DIRECTORY_SEPARATOR.'error'))
44
- {
45
- @mkdir($dir.DIRECTORY_SEPARATOR.'wpvivid_log'.DIRECTORY_SEPARATOR.'error',0777,true);
46
- @fopen($dir.DIRECTORY_SEPARATOR.'wpvivid_log'.DIRECTORY_SEPARATOR.'error'.'/index.html', 'x');
47
- $tempfile=@fopen($dir.DIRECTORY_SEPARATOR.'wpvivid_log'.DIRECTORY_SEPARATOR.'error'.'/.htaccess', 'x');
48
- if($tempfile)
49
- {
50
- $text="deny from all";
51
- fwrite($tempfile,$text );
52
- @fclose($tempfile);
53
- }
54
- }
55
- $id = uniqid('wpvivid-');
56
- $file=$id.'_restore_log.txt';
57
- if(file_exists($dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.$file))
58
- {
59
- @unlink($dir.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.$file);
60
- }
61
-
62
- @copy($log_file_name,$dir.DIRECTORY_SEPARATOR.'wpvivid_log'.DIRECTORY_SEPARATOR.'error'.DIRECTORY_SEPARATOR.$file);
63
- //self::delete_oldest_error_log();
64
- }
65
-
66
- public static function delete_oldest_error_log()
67
- {
68
- $files=array();
69
- $log=new WPvivid_Log();
70
- $dir=$log->GetSaveLogFolder();
71
- $dir=$dir.'error';
72
- @$handler=opendir($dir);
73
- if($handler===false)
74
- return;
75
- $regex='#^wpvivid.*_log.txt#';
76
- while(($filename=readdir($handler))!==false)
77
- {
78
- if($filename != "." && $filename != "..")
79
- {
80
- if(is_dir($dir.DIRECTORY_SEPARATOR.$filename))
81
- {
82
- continue;
83
- }else{
84
- if(preg_match($regex,$filename))
85
- {
86
- $files[$filename] = $dir.DIRECTORY_SEPARATOR.$filename;
87
- }
88
- }
89
- }
90
- }
91
- if($handler)
92
- @closedir($handler);
93
- $oldest=0;
94
- $oldest_filename='';
95
- $max_count=5;
96
- if(sizeof($files)>$max_count)
97
- {
98
- foreach ($files as $file)
99
- {
100
- if($oldest==0)
101
- {
102
- $oldest=filemtime($file);
103
- $oldest_filename=$file;
104
- }
105
- else
106
- {
107
- if($oldest>filemtime($file))
108
- {
109
- $oldest=filemtime($file);
110
- $oldest_filename=$file;
111
- }
112
- }
113
- }
114
-
115
- if($oldest_filename!='')
116
- {
117
- @unlink($oldest_filename);
118
- }
119
- }
120
- }
121
-
122
- public static function get_error_log()
123
- {
124
- $log=new WPvivid_Log();
125
- $dir=$log->GetSaveLogFolder();
126
- $dir=$dir.'error';
127
- $files=array();
128
- $handler=opendir($dir);
129
- if($handler === false){
130
- return $files;
131
- }
132
- $regex='#^wpvivid.*_log.txt#';
133
- while(($filename=readdir($handler))!==false)
134
- {
135
- if($filename != "." && $filename != "..")
136
- {
137
- if(is_dir($dir.$filename))
138
- {
139
- continue;
140
- }
141
- else{
142
- if(preg_match($regex,$filename))
143
- {
144
- $files[] = $dir.DIRECTORY_SEPARATOR.$filename;
145
- }
146
- }
147
- }
148
- }
149
- if($handler)
150
- @closedir($handler);
151
- return $files;
152
- }
153
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-export-import.php DELETED
@@ -1,2701 +0,0 @@
1
- <?php
2
-
3
- define('WPVIVID_IMPORT_EXPORT_DIR', 'ImportandExport');
4
-
5
- class WPvivid_Export_Import
6
- {
7
- public $main_tab;
8
- public $sub_tab;
9
-
10
- public $end_shutdown_function;
11
-
12
- public function __construct()
13
- {
14
- add_action('wp_ajax_wpvivid_export_post_step2', array($this, 'export_post_step2'));
15
- add_action('wp_ajax_wpvivid_export_post_step3', array($this, 'export_post_step3'));
16
-
17
- add_filter('wpvivid_get_toolbar_menus',array($this,'get_toolbar_menus'),21);
18
- add_filter('wpvivid_get_admin_menus',array($this,'get_admin_menus'),21);
19
-
20
- add_action('wp_ajax_wpvivid_export_now', array($this, 'export_now'));
21
- add_action('wp_ajax_wpvivid_prepare_export_post', array($this, 'prepare_export_post'));
22
- add_action('wp_ajax_wpvivid_export_list_tasks', array($this, 'list_tasks'));
23
-
24
- add_action('wp_ajax_wpvivid_get_post_list', array($this, 'get_list'));
25
- add_action('wp_ajax_wpvivid_get_post_list_page', array($this, 'get_list_page'));
26
- add_action('wp_ajax_wpvivid_get_import_list_page', array($this, 'get_import_list_page'));
27
-
28
- add_action('wp_ajax_wpvivid_get_export_list',array($this, 'get_export_list'));
29
-
30
- add_action('admin_head', array($this, 'my_admin_custom_styles'));
31
-
32
- add_action('wpvivid_handle_export_success',array($this,'handle_export_success'),10);
33
- add_action('wpvivid_handle_export_failed',array($this,'handle_export_failed'),10, 2);
34
-
35
- add_action('wp_ajax_wpvivid_delete_export_list',array($this,'delete_export_list'),10);
36
-
37
- add_filter('wpvivid_get_screen_ids',array($this,'get_screen_ids'),12);
38
-
39
- add_action('wp_ajax_wpvivid_start_import', array($this, 'start_import'));
40
-
41
- add_action('wp_ajax_wpvivid_download_export_backup', array($this, 'wpvivid_download_export_backup'));
42
- add_action('wp_ajax_wpvivid_check_import_file', array($this, 'check_import_file'));
43
- add_action('wp_ajax_wpvivid_upload_import_files',array($this,'upload_import_files'));
44
- add_action('wp_ajax_wpvivid_upload_import_file_complete', array($this, 'upload_import_file_complete'));
45
- add_action('wp_ajax_wpvivid_get_import_progress', array($this, 'get_import_progress'));
46
- add_action('wp_ajax_wpvivid_scan_import_folder', array($this, 'wpvivid_scan_import_folder'));
47
- add_action('wp_ajax_wpvivid_calc_import_folder_size', array($this, 'calc_import_folder_size'));
48
- add_action('wp_ajax_wpvivid_clean_import_folder', array($this, 'clean_import_folder'));
49
- //
50
- $this->end_shutdown_function = false;
51
- }
52
-
53
- public function get_screen_ids($screen_ids)
54
- {
55
- $screen_ids[]='wpvivid-backup_page_wpvivid-export-import';
56
- return $screen_ids;
57
- }
58
-
59
- public function get_toolbar_menus($toolbar_menus)
60
- {
61
- $admin_url = apply_filters('wpvivid_get_admin_url', '');
62
-
63
- $menu['id']='wpvivid_admin_menu_export_import';
64
- $menu['parent']='wpvivid_admin_menu';
65
- $menu['title']=__('Export & Import', 'wpvivid-backuprestore');
66
- $menu['tab']= 'admin.php?page=wpvivid-export-import';
67
- $menu['href']=$admin_url . 'admin.php?page=wpvivid-export-import';
68
- $menu['capability']='administrator';
69
- $menu['index']=3;
70
- $toolbar_menus[$menu['parent']]['child'][$menu['id']]=$menu;
71
- return $toolbar_menus;
72
- }
73
-
74
- public function get_admin_menus($submenus)
75
- {
76
- $submenu['parent_slug']=WPVIVID_PLUGIN_SLUG;
77
- $submenu['page_title']= 'WPvivid Backup';
78
- $submenu['menu_title']=__('Export & Import', 'wpvivid-backuprestore');
79
- $submenu['capability']='administrator';
80
- $submenu['menu_slug']='wpvivid-export-import';
81
- $submenu['index']=3;
82
- $submenu['function']=array($this, 'init_page');
83
- $submenus[$submenu['menu_slug']]=$submenu;
84
- return $submenus;
85
- }
86
-
87
- public function init_page()
88
- {
89
- ?>
90
- <div class="wrap" style="max-width:1720px;">
91
- <h1><?php
92
- $plugin_display_name = 'WPvivid Backup Plugin';
93
- $plugin_display_name = apply_filters('wpvivid_display_pro_name', $plugin_display_name);
94
- echo __('WPvivid Backup Plugin', 'wpvivid-backuprestore');
95
- ?></h1>
96
- <div id="wpvivid_export_notice"></div>
97
- <?php
98
- $args['is_parent_tab']=1;
99
- $this->main_tab=new WPvivid_Tab_Page_Container();
100
- $this->main_tab->add_tab('Export','export',array($this, 'output_export'), $args);
101
- $this->main_tab->add_tab('Import','import',array($this, 'output_import'), $args);
102
- $this->main_tab->display();
103
- ?>
104
- </div>
105
- <?php
106
- }
107
-
108
- //export
109
- public function output_export()
110
- {
111
- $export_dir = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
112
- ?>
113
- <div class="postbox export-import-block">
114
- <div>
115
- <div class="wpvivid-element-space-bottom wpvivid-element-space-right" style="float: left;">
116
- <img src="<?php echo esc_url(WPVIVID_PLUGIN_IMAGES_URL.'export-import.png'); ?>" style="width:50px;height:50px;">
117
- </div>
118
- <div style="box-sizing: border-box;">
119
- <div class="wpvivid-text-space-bottom"><?php _e('Export posts or pages with images in bulk.', 'wpvivid-backuprestore'); ?>
120
- <span class="wpvivid-feature-pro">
121
- <a href="https://docs.wpvivid.com/export-content.html" target="_blank" style="text-decoration: none;"><?php _e('Learn more', 'wpvivid-backuprestore'); ?></a>
122
- </span>
123
- </div>
124
- <div class="wpvivid-text-space-bottom"><?php _e('This will contain all of your posts, pages, comments, terms and images (original images, featured images and thumbnails).', 'wpvivid-backuprestore'); ?></div>
125
- <div class="wpvivid-text-space-bottom"><strong><?php _e('Note:', 'wpvivid-backuprestore'); ?></strong>&nbsp<?php _e('Try to select fewer items when you are facing a shortage of server resources (typically presented as a timeout error).', 'wpvivid-backuprestore'); ?></div>
126
- <div style="clear: both;"></div>
127
- </div>
128
- <div style="clear: both;"></div>
129
- </div>
130
- <div style="clear: both;"></div>
131
-
132
- <div style="background: #fff; border: 1px solid #e5e5e5; border-radius: 6px; margin-bottom: 10px; padding: 10px;">
133
- <div>
134
- <?php
135
- echo sprintf(__('Exported files will be temporarily stored in %s directory', 'wpvivid-backuprestore'), $export_dir);
136
- ?>
137
- </div>
138
- </div>
139
-
140
- <div style="width:100%; border:1px solid #f1f1f1; float:left; box-sizing: border-box;margin-bottom:10px;">
141
- <div style="box-sizing: border-box; margin: 1px; background-color: #f1f1f1;"><h2><?php _e('Choose post type', 'wpvivid-backuprestore'); ?></h2></div>
142
- </div>
143
- <div style="clear: both;"></div>
144
-
145
- <div class="postbox wpvivid-element-space-bottom">
146
- <div class="wpvivid-export-type-provider wpvivid-export-type-post wpvivid-export-type-provider-active" onclick="wpvivid_select_export_type('post');">
147
- <?php _e('Post', 'wpvivid-backuprestore'); ?>
148
- </div>
149
- <div class="wpvivid-export-type-provider wpvivid-export-type-page" onclick="wpvivid_select_export_type('page');">
150
- <?php _e('Page', 'wpvivid-backuprestore'); ?>
151
- </div>
152
- <div class="wpvivid-export-type-provider">
153
- <?php _e('More post types coming soon...', 'wpvivid-backuprestore'); ?>
154
- </div>
155
- </div>
156
-
157
- <div id="wpvivid_export_page">
158
- <input class="button-primary wpvivid-button-export-archieve" type="submit" name="post" value="<?php esc_attr_e('Next Step', 'wpvivid-backuprestore'); ?>" />
159
- </div>
160
- <div class="postbox" id="wpvivid_export_task_progress" style="display: none; margin-top: 10px; margin-bottom: 0;">
161
- <div class="action-progress-bar" id="wpvivid_export_bar_percent">
162
- <div class="action-progress-bar-percent" style="width:0; height:24px;"></div>
163
- </div>
164
- <div style="clear: both;"></div>
165
- <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_export_current_doing"></p></div>
166
- <div style="clear: both;"></div>
167
- </div>
168
- <div class="postbox" id="wpvivid_export_summary" style="display: none; margin-top: 10px; margin-bottom: 0; padding: 10px;"></div>
169
- </div>
170
-
171
- <script>
172
- var export_task_id='';
173
- var retry_count=0;
174
-
175
- var current_export_type = 'post';
176
- function wpvivid_select_export_type(export_type){
177
- jQuery('.wpvivid-export-type-provider').removeClass('wpvivid-export-type-provider-active');
178
- jQuery('.wpvivid-export-type-'+export_type).addClass('wpvivid-export-type-provider-active');
179
- if(current_export_type !== export_type){
180
- current_export_type = export_type;
181
- var button_html = '<input class="button-primary wpvivid-button-export-archieve" type="submit" name="'+export_type+'" value="<?php esc_attr_e('Next Step', 'wpvivid-backuprestore'); ?>" />';
182
- jQuery('#wpvivid_export_page').html(button_html);
183
- jQuery('#wpvivid_export_summary').hide();
184
- }
185
- }
186
-
187
- function wpvivid_archieve_export_info(post_type, is_running){
188
- var ajax_data = {
189
- 'action':'wpvivid_export_post_step2',
190
- 'post_type': post_type
191
- };
192
- wpvivid_post_request(ajax_data, function(data) {
193
- var jsonarray = jQuery.parseJSON(data);
194
- if (jsonarray.result === 'success') {
195
- jQuery('#wpvivid_export_page').html(jsonarray.html);
196
- if(is_running){
197
- jQuery('#wpvivid_export_custom').hide();
198
- }
199
- }
200
- else if (jsonarray.result === 'failed') {
201
- alert(jsonarray.error);
202
- }
203
- }, function(XMLHttpRequest, textStatus, errorThrown) {
204
- var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
205
- alert(error_message);
206
- });
207
- }
208
-
209
- function wpvivid_import_lock_unlock(action){
210
- var css_pointer_event = '';
211
- var css_opacity = '';
212
- if(action === 'lock'){
213
- css_pointer_event = 'none';
214
- css_opacity = '0.4';
215
- }
216
- else{
217
- css_pointer_event = 'auto';
218
- css_opacity = '1';
219
- }
220
- jQuery('.wpvivid-export-type-provider').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
221
- jQuery('#wpvivid_export_page .wpvivid-button-export-archieve').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
222
- jQuery('#wpvivid_export_page #wpvivid-post-query-submit').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
223
- jQuery('#wpvivid_export_page #wpvivid-post-research-submit').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
224
- jQuery('input:radio[name=contain]').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
225
- jQuery('#wpvivid_export_page #wpvivid_start_export').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
226
- jQuery('#wpvivid_tab_export').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
227
- jQuery('#wpvivid_tab_import').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
228
- jQuery('#wpvivid_empty_import_folder').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
229
- jQuery('#wpvivid_select_import_file_button').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
230
- jQuery('#wpvivid_upload_file_list').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
231
- jQuery('.export-list-import').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
232
- jQuery('#wpvivid_start_import').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
233
- jQuery('#wpvivid_rechoose_import_file').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
234
- }
235
-
236
- function wpvivid_export_lock_unlock(action){
237
- var css_pointer_event = '';
238
- var css_opacity = '';
239
- if(action === 'lock'){
240
- css_pointer_event = 'none';
241
- css_opacity = '0.4';
242
- }
243
- else{
244
- css_pointer_event = 'auto';
245
- css_opacity = '1';
246
- }
247
- jQuery('.wpvivid-export-type-provider').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
248
- jQuery('#wpvivid_export_page .wpvivid-button-export-archieve').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
249
- jQuery('#wpvivid_export_page #wpvivid-post-query-submit').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
250
- jQuery('#wpvivid_export_page #wpvivid-post-research-submit').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
251
- jQuery('input:radio[name=contain]').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
252
- jQuery('#wpvivid_export_page #wpvivid_start_export').css({'pointer-events': css_pointer_event, 'opacity': css_opacity});
253
- }
254
-
255
- jQuery('#wpvivid_export_page').on("click", ".wpvivid-button-export-archieve", function(){
256
- var post_type = jQuery(this).attr('name');
257
- wpvivid_archieve_export_info(post_type, false);
258
- });
259
-
260
- jQuery('#wpvivid_export_page').on("click", "#wpvivid-post-research-submit",function()
261
- {
262
- jQuery('#wpvivid_post_selector').show();
263
- jQuery('#wpvivid_post_list').hide();
264
- });
265
- jQuery('#wpvivid_export_page').on("click", "#wpvivid-post-query-submit",function()
266
- {
267
- var post_type = jQuery('#wpvivid-post-query-submit').attr('name');
268
- var cat=jQuery('select[name=cat]').val();
269
- var authors=jQuery('select[name=post_author]').val();
270
- var post_start_date=jQuery('select[name=post_start_date]').val();
271
- var post_end_date=jQuery('select[name=post_end_date]').val();
272
- var post_ids=jQuery('input[name=post-id]').val();
273
- var post_title=jQuery('input[name=post-title]').val();
274
- var ajax_data = {
275
- 'action':'wpvivid_get_post_list',
276
- 'post_type': post_type,
277
- 'cat':cat,
278
- 'authors':authors,
279
- 'post_start_date':post_start_date,
280
- 'post_end_date':post_end_date,
281
- 'post_ids':post_ids,
282
- 'post_title':post_title
283
- };
284
- wpvivid_post_request(ajax_data, function(data) {
285
- var jsonarray = jQuery.parseJSON(data);
286
- if (jsonarray.result === 'success') {
287
- jQuery('#wpvivid_post_selector').hide();
288
- jQuery('#wpvivid_bottom_step2').show();
289
- jQuery('#wpvivid_post_list').show();
290
- jQuery('#wpvivid_post_list').html(jsonarray.rows);
291
- }
292
- else if (jsonarray.result === 'failed') {
293
- alert(jsonarray.error);
294
- }
295
- }, function(XMLHttpRequest, textStatus, errorThrown) {
296
- var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
297
- alert(error_message);
298
- });
299
- });
300
-
301
- jQuery('#wpvivid_export_page').on("click", 'input:radio[name=contain]',function() {
302
- if(jQuery(this).val()==='list') {
303
- jQuery('#wpvivid_export_custom').show();
304
- }
305
- else {
306
- jQuery('#wpvivid_export_custom').hide();
307
- }
308
- });
309
-
310
- jQuery('#wpvivid_export_page').on("keyup", '#wpvivid_set_post_comment', function(){
311
- var post_comment = jQuery('#wpvivid_set_post_comment').val();
312
- if(post_comment === ''){
313
- post_comment = '*';
314
- jQuery('#wpvivid_post_comment').html(post_comment);
315
- }
316
- else{
317
- var reg = RegExp(/wpvivid/, 'i');
318
- if (post_comment.match(reg)) {
319
- jQuery('#wpvivid_set_post_comment').val('');
320
- jQuery('#wpvivid_post_comment').html('*');
321
- alert('You can not use word \'wpvivid\' to comment the post.');
322
- }
323
- else{
324
- jQuery('#wpvivid_post_comment').html(post_comment);
325
- }
326
- }
327
- });
328
-
329
- function wpvivid_check_export_status(){
330
- var check_status = false;
331
- jQuery('input[name="post[]"]').each(function (i) {
332
- var id=jQuery(this).val();
333
- if(jQuery(this).prop('checked')) {
334
- check_status = true;
335
- return;
336
- }
337
- });
338
- return check_status;
339
- }
340
-
341
- jQuery('#wpvivid_export_page').on("click", '#cb-select-all-1', function() {
342
- if(jQuery(this).prop('checked')) {
343
- jQuery('#wpvivid_start_export').css({'pointer-events': 'auto', 'opacity': '1'});
344
- }
345
- else{
346
- jQuery('#wpvivid_start_export').css({'pointer-events': 'none', 'opacity': '0.4'});
347
- }
348
- });
349
-
350
- jQuery('#wpvivid_export_page').on("click", '#cb-select-all-2', function() {
351
- if(jQuery(this).prop('checked')) {
352
- jQuery('#wpvivid_start_export').css({'pointer-events': 'auto', 'opacity': '1'});
353
- }
354
- else{
355
- jQuery('#wpvivid_start_export').css({'pointer-events': 'none', 'opacity': '0.4'});
356
- }
357
- });
358
-
359
- jQuery('#wpvivid_export_page').on("click", 'input[name="post[]"]', function() {
360
- var check_status = wpvivid_check_export_status();
361
- if(check_status){
362
- jQuery('#wpvivid_start_export').css({'pointer-events': 'auto', 'opacity': '1'});
363
- }
364
- else{
365
- jQuery('#wpvivid_start_export').css({'pointer-events': 'none', 'opacity': '0.4'});
366
- }
367
- });
368
-
369
- jQuery('#wpvivid_export_page').on("click", '#wpvivid_start_export', function(){
370
- wpvivid_clear_notice('wpvivid_export_notice');
371
- jQuery('#wpvivid_export_summary').hide();
372
- var post_type = jQuery('#wpvivid_start_export').attr('name');
373
-
374
- var select_type='all';
375
- jQuery('input:radio[name=contain]').each(function() {
376
- if(jQuery(this).prop('checked')) {
377
- select_type=jQuery(this).val();
378
- }
379
- });
380
-
381
- var has_item = false;
382
- var post_ids = {};
383
- jQuery('input[name="post[]"]').each(function (i) {
384
- var id=jQuery(this).val();
385
- if(jQuery(this).prop('checked')) {
386
- post_ids[id]=1;
387
- has_item = true;
388
- }
389
- else {
390
- post_ids[id]=0;
391
- }
392
- });
393
-
394
- if(select_type === 'list' && !has_item){
395
- alert('Please select at least one item.');
396
- }
397
- else{
398
- var post_ids_json = {
399
- 'post_ids': post_ids
400
- };
401
-
402
- jQuery('#wpvivid_export_custom').hide();
403
-
404
- var export_data = wpvivid_ajax_data_transfer('export');
405
- export_data = JSON.parse(export_data);
406
- jQuery.extend(export_data, post_ids_json);
407
- export_data = JSON.stringify(export_data);
408
-
409
- var ajax_data = {
410
- 'action': 'wpvivid_prepare_export_post',
411
- 'post_type': post_type,
412
- 'export_data': export_data
413
- };
414
- wpvivid_export_lock_unlock('lock');
415
- wpvivid_post_request(ajax_data, function(data)
416
- {
417
- var jsonarray = jQuery.parseJSON(data);
418
- if (jsonarray.result === 'success')
419
- {
420
- export_task_id=jsonarray.task_id;
421
-
422
- var ajax_data = {
423
- 'action':'wpvivid_export_now',
424
- 'task_id':export_task_id
425
- };
426
-
427
- wpvivid_export_progpress();
428
-
429
- wpvivid_post_request(ajax_data, function(data) {
430
- },function(XMLHttpRequest, textStatus, errorThrown) {
431
- });
432
- }
433
- else if (jsonarray.result === 'failed') {
434
- wpvivid_export_lock_unlock('unlock');
435
- alert(jsonarray.error);
436
- }
437
- }, function(XMLHttpRequest, textStatus, errorThrown) {
438
- wpvivid_export_lock_unlock('unlock');
439
- var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
440
- alert(error_message);
441
- });
442
- }
443
- });
444
-
445
- jQuery('#wpvivid_export_page').on("click",'.first-page',function() {
446
- wpvivid_change_page('first');
447
- });
448
-
449
- jQuery('#wpvivid_export_page').on("click",'.prev-page',function() {
450
- var page=parseInt(jQuery(this).attr('value'));
451
- wpvivid_change_page(page-1);
452
- });
453
-
454
- jQuery('#wpvivid_export_page').on("click",'.next-page',function() {
455
- var page=parseInt(jQuery(this).attr('value'));
456
- wpvivid_change_page(page+1);
457
- });
458
-
459
- jQuery('#wpvivid_export_page').on("click",'.last-page',function() {
460
- wpvivid_change_page('last');
461
- });
462
-
463
- jQuery('#wpvivid_export_page').on("keypress", '.current-page', function(){
464
- if(event.keyCode === 13){
465
- var page = jQuery(this).val();
466
- wpvivid_change_page(page);
467
- }
468
- });
469
-
470
- function wpvivid_change_page(page) {
471
- var post_type='post';
472
- jQuery('input:radio[name=post_type]').each(function() {
473
- if(jQuery(this).prop('checked'))
474
- {
475
- post_type=jQuery(this).val();
476
- }
477
- });
478
-
479
- var post_ids = {};
480
-
481
- jQuery('input[name="post[]"]').each(function (i) {
482
- var id=jQuery(this).val();
483
- if(jQuery(this).prop('checked'))
484
- {
485
- post_ids[id]=1;
486
- }
487
- else
488
- {
489
- post_ids[id]=0;
490
- }
491
- });
492
-
493
- var ajax_data = {
494
- 'action':'wpvivid_get_post_list_page',
495
- 'post_type': post_type,
496
- 'page': page,
497
- 'post_ids':post_ids
498
- };
499
-
500
- wpvivid_post_request(ajax_data, function(data) {
501
- var jsonarray = jQuery.parseJSON(data);
502
- if (jsonarray.result === 'success') {
503
- jQuery('#wpvivid_post_list').html(jsonarray.rows);
504
- }
505
- else if (jsonarray.result === 'failed') {
506
- alert(jsonarray.error);
507
- }
508
- }, function(XMLHttpRequest, textStatus, errorThrown) {
509
- var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
510
- alert(error_message);
511
- });
512
- }
513
-
514
- function wpvivid_export_progpress() {
515
- var ajax_data = {
516
- 'action': 'wpvivid_export_list_tasks',
517
- 'task_id': export_task_id
518
- };
519
-
520
- jQuery('#wpvivid_export_task_progress').show();
521
-
522
- wpvivid_post_request(ajax_data, function(data)
523
- {
524
- var jsonarray = jQuery.parseJSON(data);
525
- if (jsonarray.result === 'success')
526
- {
527
- retry_count=0;
528
- export_task_id=jsonarray.task_id;
529
- if(jsonarray.show)
530
- {
531
- jQuery('#wpvivid_export_task_progress').show();
532
- jQuery('#wpvivid_export_summary').hide();
533
- jQuery('#wpvivid_export_bar_percent').html(jsonarray.percent);
534
- jQuery('#wpvivid_export_current_doing').html(jsonarray.doing);
535
- }
536
- else
537
- {
538
- jQuery('#wpvivid_export_task_progress').hide();
539
- }
540
-
541
- if(jsonarray.completed)
542
- {
543
- wpvivid_export_lock_unlock('unlock');
544
- //jQuery('#wpvivid_export_notice').show();
545
- //jQuery('#wpvivid_export_notice').append(jsonarray.doing);
546
- jQuery('#wpvivid_export_summary').show();
547
- jQuery('#wpvivid_export_summary').html(jsonarray.doing);
548
- jQuery('html, body').animate({scrollTop: jQuery("#wpvivid_export_notice").offset().top}, 'slow');
549
- wpvivid_download_export(jsonarray.file_name, jsonarray.file_size);
550
- }
551
-
552
- if(jsonarray.continue)
553
- {
554
- wpvivid_export_lock_unlock('lock');
555
- setTimeout(function ()
556
- {
557
- wpvivid_export_progpress();
558
- }, 3000);
559
- }
560
-
561
- if(jsonarray.error){
562
- wpvivid_export_lock_unlock('unlock');
563
- jQuery('#wpvivid_export_notice').show();
564
- jQuery('#wpvivid_export_notice').append(jsonarray.doing);
565
- jQuery('html, body').animate({scrollTop: jQuery("#wpvivid_export_notice").offset().top}, 'slow');
566
- }
567
- }
568
- else
569
- {
570
- alert(jsonarray.error);
571
- }
572
- }, function(XMLHttpRequest, textStatus, errorThrown)
573
- {
574
- retry_count++;
575
- if(retry_count<3)
576
- {
577
- setTimeout(function () {
578
- wpvivid_export_progpress();
579
- }, 3000);
580
- }
581
- });
582
- }
583
-
584
- function wpvivid_download_export(file_name, file_size){
585
- location.href =ajaxurl+'?_wpnonce='+wpvivid_ajax_object.ajax_nonce+'&action=wpvivid_download_export_backup&file_name='+file_name+'&file_size='+file_size;
586
- }
587
-
588
- jQuery(document).ready(function (){
589
- <?php
590
- $task_id = false;
591
- $post_type = false;
592
- $tasks=WPvivid_Exporter_taskmanager::get_tasks();
593
- foreach ($tasks as $task){
594
- $task_id = $task['id'];
595
- $post_type = $task['options']['backup_options']['post_type'];
596
- break;
597
- }
598
- ?>
599
- var task_id = '<?php echo $task_id; ?>';
600
- if(task_id != false){
601
- export_task_id = task_id;
602
- wpvivid_export_lock_unlock('lock');
603
- wpvivid_export_progpress();
604
- }
605
- });
606
- </script>
607
- <?php
608
- }
609
-
610
- public function export_post_step2()
611
- {
612
- global $wpvivid_plugin;
613
- $wpvivid_plugin->ajax_check_security();
614
- if(isset($_POST['post_type']))
615
- {
616
- global $wpdb;
617
- $post_type = sanitize_text_field($_POST['post_type']);
618
- $descript_type = $post_type === 'post' ? 'posts' : 'pages';
619
- $btn_text = $post_type === 'post' ? 'Show Posts' : 'Show Pages';
620
-
621
- ob_start();
622
- ?>
623
- <div style="width:100%; border:1px solid #f1f1f1; float:left; box-sizing: border-box;margin-bottom:10px;">
624
- <div style="box-sizing: border-box; margin: 1px; background-color: #f1f1f1;"><h2><?php _e('Choose what to export', 'wpvivid-backuprestore'); ?></h2></div>
625
- </div>
626
- <div style="clear: both;"></div>
627
- <div style="width:100%; border:1px solid #f1f1f1; float:left; padding:10px 10px 0 10px;margin-bottom:10px; box-sizing: border-box;">
628
- <fieldset>
629
- <legend class="screen-reader-text"><span>input type="radio"</span></legend>
630
- <div class="wpvivid-element-space-bottom wpvivid-element-space-right" style="float: left;">
631
- <label>
632
- <input type="radio" option="export" name="contain" value="list" checked/><?php _e('Filter Posts/Pages', 'wpvivid-backuprestore'); ?>
633
- </label>
634
- </div>
635
- <div style="clear: both;"></div>
636
- </fieldset>
637
-
638
- <div id="wpvivid_export_custom" style="margin-bottom: 10px;">
639
- <table id="wpvivid_post_selector" class="wp-list-table widefat plugins" style="width:100%; border:1px solid #f1f1f1;">
640
- <tbody>
641
- <?php
642
- if($post_type !== 'page') {
643
- ?>
644
- <tr>
645
- <td class="plugin-title column-primary">
646
- <div class="wpvivid-storage-form regular-text">
647
- <?php
648
- wp_dropdown_categories(
649
- array(
650
- 'class' => 'regular-text',
651
- 'show_option_all' => __('All Categories', 'wpvivid-backuprestore')
652
- )
653
- );
654
- ?>
655
- </div>
656
- </td>
657
- <td class="column-description desc">
658
- <div class="wpvivid-storage-form-desc">
659
- <i>
660
- <?php
661
- echo sprintf(__('Export %s of all categories or a specific category.', 'wpvivid-backuprestore'), $descript_type);
662
- ?>
663
- </i>
664
- </div>
665
- </td>
666
- </tr>
667
- <?php
668
- }
669
- ?>
670
- <tr>
671
- <td class="plugin-title column-primary">
672
- <div class="wpvivid-storage-form regular-text">
673
- <?php
674
- $authors = $wpdb->get_col( "SELECT DISTINCT post_author FROM {$wpdb->posts} WHERE post_type = '$post_type'" );
675
- wp_dropdown_users(
676
- array(
677
- 'class' => 'regular-text',
678
- 'include' => $authors,
679
- 'name' => 'post_author',
680
- 'multi' => true,
681
- 'show_option_all' => __( 'All Authors', 'wpvivid-backuprestore' ),
682
- 'show' => 'display_name_with_login',
683
- )
684
- );
685
- ?>
686
- </div>
687
- </td>
688
- <td class="column-description desc">
689
- <div class="wpvivid-storage-form-desc">
690
- <i>
691
- <?php
692
- echo sprintf(__('Export %s of all authors or a specific author.', 'wpvivid-backuprestore'), $descript_type);
693
- ?>
694
- </i>
695
- </div>
696
- </td>
697
- </tr>
698
-
699
- <tr>
700
- <td class="plugin-title column-primary">
701
- <div class="wpvivid-storage-form regular-text">
702
- <label for="post-start-date" class="label-responsive" style="display: block;"></label>
703
- <select class="regular-text" name="post_start_date" id="post-start-date">
704
- <option value="0"><?php _e( '&mdash; Select &mdash;', 'wpvivid-backuprestore' ); ?></option>
705
- <?php $this->export_date_options($post_type); ?>
706
- </select>
707
- </div>
708
- </td>
709
- <td class="column-description desc">
710
- <div class="wpvivid-storage-form-desc">
711
- <i>
712
- <?php
713
- echo sprintf(__('Export %s published after this date.', 'wpvivid-backuprestore'), $descript_type);
714
- ?>
715
- </i>
716
- </div>
717
- </td>
718
- </tr>
719
-
720
- <tr>
721
- <td class="plugin-title column-primary">
722
- <div class="wpvivid-storage-form regular-text">
723
- <label for="post-end-date" class="label-responsive" style="display: block;"></label>
724
- <select class="regular-text" name="post_end_date" id="post-end-date">
725
- <option value="0"><?php _e( '&mdash; Select &mdash;', 'wpvivid-backuprestore' ); ?></option>
726
- <?php $this->export_date_options($post_type); ?>
727
- </select>
728
- </div>
729
- </td>
730
- <td class="column-description desc">
731
- <div class="wpvivid-storage-form-desc">
732
- <i>
733
- <?php
734
- echo sprintf(__('Export %s published before this date.', 'wpvivid-backuprestore'), $descript_type);
735
- ?>
736
- </i>
737
- </div>
738
- </td>
739
- </tr>
740
-
741
- <tr style="display: none;">
742
- <td class="plugin-title column-primary">
743
- <div class="wpvivid-storage-form">
744
- <input type="text" class="regular-text" id="post-search-id-input" name="post-id" autocomplete="off" value=""/>
745
- </div>
746
- </td>
747
- <td class="column-description desc">
748
- <div class="wpvivid-storage-form-desc">
749
- <i>Enter a <?php _e($post_type); ?> ID.(optional)</i>
750
- </div>
751
- </td>
752
- </tr>
753
-
754
- <tr style="display: none;">
755
- <td class="plugin-title column-primary">
756
- <div class="wpvivid-storage-form">
757
- <input type="text" class="regular-text" id="post-search-title-input" name="post-title" autocomplete="off" value=""/>
758
- </div>
759
- </td>
760
- <td class="column-description desc">
761
- <div class="wpvivid-storage-form-desc">
762
- <i>Enter a <?php _e($post_type); ?> title.(optional)</i>
763
- </div>
764
- </td>
765
- </tr>
766
-
767
- <tr>
768
- <td class="plugin-title column-primary">
769
- <div class="wpvivid-storage-form">
770
- <input class="button-primary" id="wpvivid-post-query-submit" type="submit" name="<?php echo $post_type; ?>" value="<?php echo $btn_text; ?>" />
771
- </div>
772
- </td>
773
- <td class="column-description desc">
774
- <div class="wpvivid-storage-form-desc">
775
- <i>
776
- <?php
777
- echo sprintf(__('Search for %s according to the above rules.', 'wpvivid-backuprestore'), $post_type);
778
- ?>
779
- </i>
780
- </div>
781
- </td>
782
- </tr>
783
- </tbody>
784
- </table>
785
- <div id="wpvivid_post_list"></div>
786
- </div>
787
- </div>
788
-
789
- <div style="width:100%; border:1px solid #f1f1f1; float:left; box-sizing: border-box;margin-bottom:10px;">
790
- <div style="box-sizing: border-box; margin: 1px; background-color: #f1f1f1;"><h2><?php _e('Comment the export (optional)', 'wpvivid-backuprestore'); ?></h2></div>
791
- </div>
792
- <div style="clear: both;"></div>
793
- <div style="width:100%; border:1px solid #f1f1f1; float:left; padding:10px 10px 0 10px;margin-bottom:10px; box-sizing: border-box;">
794
- <div>
795
- <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left; padding-top: 6px;"><?php _e('Comment the export: ', 'wpvivid-backuprestore'); ?></div>
796
- <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left;">
797
- <input type="text" option="export" name="post_comment" id="wpvivid_set_post_comment" onkeyup="value=value.replace(/[^a-zA-Z0-9]/g,'')" onpaste="value=value.replace(/[^\a-\z\A-\Z0-9]/g,'')" />
798
- </div>
799
- <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left; padding-top: 6px;"><?php _e('Only letters (except for wpvivid) and numbers are allowed.', 'wpvivid-backuprestore'); ?></div>
800
- <div style="clear: both;"></div>
801
- </div>
802
- <div>
803
- <div class="wpvivid-element-space-bottom wpvivid-text-space-right" style="float: left;"><?php _e('Sample:', 'wpvivid-backuprestore'); ?></div>
804
- <div class="wpvivid-element-space-bottom" style="float: left;">
805
- <div class="wpvivid-element-space-bottom" style="display: inline;" id="wpvivid_post_comment">*</div><div class="wpvivid-element-space-bottom" style="display: inline;">_wpvivid-5dbf8d6a5f133_2019-11-08-03-15_export_<?php _e($post_type, 'wpvivid-backuprestore'); ?>.zip</div>
806
- </div>
807
- <div style="clear: both;"></div>
808
- </div>
809
- </div>
810
-
811
- <div>
812
- <input class="button-primary" id="wpvivid_start_export" type="submit" name="<?php echo $post_type; ?>" value="<?php esc_attr_e('Export and Download', 'wpvivid-backuprestore'); ?>" style="pointer-events: none; opacity: 0.4;">
813
- </div>
814
- <?php
815
-
816
- $html = ob_get_clean();
817
- $ret['result']='success';
818
- $ret['html']=$html;
819
- }
820
- else
821
- {
822
- $ret['result']='failed';
823
- $ret['error']='not set post type';
824
- }
825
- echo json_encode($ret);
826
- die();
827
- }
828
-
829
- public function export_post_step3()
830
- {
831
- global $wpvivid_plugin;
832
- $wpvivid_plugin->ajax_check_security();
833
- if(isset($_POST['post_type'])&&isset($_POST['all']))
834
- {
835
- $post_type=$_POST['post_type'];
836
-
837
- $old_post_ids=array();
838
- if(isset($_POST['post_ids']))
839
- {
840
- $old_post_ids=$_POST['post_ids'];
841
- }
842
-
843
- $list_cache=get_option('wpvivid_list_cache',array());
844
-
845
- foreach ($old_post_ids as $id=>$checked)
846
- {
847
- if(isset($list_cache[$id]))
848
- {
849
- $list_cache[$id]['checked']=$checked;
850
- }
851
- }
852
- WPvivid_Setting::update_option('wpvivid_list_cache',$list_cache);
853
-
854
- $post_count=0;
855
-
856
- if($_POST['all']=='all')
857
- {
858
- global $wpdb;
859
-
860
- $where = $wpdb->prepare( "post_type ='%s'", $post_type);
861
- $posts_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} WHERE $where" );
862
- $post_count=sizeof($posts_ids);
863
- }
864
- else
865
- {
866
- foreach ($list_cache as $id=>$item)
867
- {
868
- if($item['checked'])
869
- $post_count++;
870
- }
871
- }
872
-
873
- ob_start();
874
- ?>
875
- <h2>Export post type:<strong><?php echo $post_type?></strong></h2>
876
- <p>
877
- Selected post(s):<?php echo $post_count?>
878
- </p>
879
- <p class="submit">
880
- <input type="button" class="button button-primary wpvivid-export-step3-prev" value="Prev step">
881
- <input type="button" class="button button-primary" id="wpvivid_start_export" value="Start Export">
882
- </p>
883
- <?php
884
-
885
- $html = ob_get_clean();
886
- $ret['result']='success';
887
- $ret['html']=$html;
888
- }
889
- else
890
- {
891
- $ret['result']='failed';
892
- $ret['error']='not set post type';
893
- }
894
- echo json_encode($ret);
895
- die();
896
- }
897
-
898
- public function my_admin_custom_styles()
899
- {
900
- $output_css = '<style type="text/css">
901
- .column-file_name { width:25% }
902
- .column-export_type { width:8% }
903
- .column-posts_count { width:8% }
904
- .column-media_size { width:8% }
905
- .column-import { width:8% }
906
- </style>';
907
- echo $output_css;
908
- }
909
-
910
- public function get_list()
911
- {
912
- global $wpvivid_plugin;
913
- $wpvivid_plugin->ajax_check_security();
914
-
915
- if(!isset($_POST['post_type'])&&!isset($_POST['cat'])&&!isset($_POST['authors'])&&!isset($_POST['post_start_date'])&&!isset($_POST['post_end_date']))
916
- {
917
- die();
918
- }
919
-
920
- if(isset($_POST['post_ids'])&&!empty($_POST['post_ids']))
921
- {
922
- $select_post_id=(int)$_POST['post_ids'];
923
- }
924
- else
925
- {
926
- $select_post_id=0;
927
- }
928
-
929
- if(isset($_POST['post_title'])&&!empty($_POST['post_title']))
930
- {
931
- $post_title=$_POST['post_title'];
932
- }
933
- else
934
- {
935
- $post_title='';
936
- }
937
- //
938
-
939
- $post_type=$_POST['post_type'];
940
- if(isset($_POST['cat'])) {
941
- $cat = (int)$_POST['cat'];
942
- }
943
- $author=(int)$_POST['authors'];
944
- $post_start_date=$_POST['post_start_date'];
945
- $post_end_date=$_POST['post_end_date'];
946
-
947
-
948
- global $wpdb;
949
-
950
- $where = $wpdb->prepare( "post_type ='%s'", $post_type);
951
- $join = '';
952
- if(isset($_POST['cat'])) {
953
- if ($term = term_exists($cat, 'category')) {
954
- $join = "INNER JOIN {$wpdb->term_relationships} ON ({$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id)";
955
- $where .= $wpdb->prepare(" AND {$wpdb->term_relationships}.term_taxonomy_id = %d", $term['term_taxonomy_id']);
956
- }
957
- }
958
- if ( $author )
959
- {
960
- $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_author = %d", $author );
961
- }
962
- if ( $post_start_date )
963
- {
964
- $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date >= %s", date( 'Y-m-d', strtotime( $post_start_date ) ) );
965
- }
966
- if ( $post_end_date )
967
- {
968
- $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_date < %s", date( 'Y-m-d', strtotime( '+1 month', strtotime( $post_end_date ) ) ) );
969
- }
970
- if($select_post_id)
971
- {
972
- $where .= $wpdb->prepare( " AND {$wpdb->posts}.ID = %d", $select_post_id );
973
- }
974
- if($post_title)
975
- {
976
- $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . $wpdb->esc_like($post_title) . '%' );
977
- }
978
-
979
- $posts_ids = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} $join WHERE $where" );
980
-
981
- asort($posts_ids);
982
-
983
- $list_cache=array();
984
- foreach ($posts_ids as $id)
985
- {
986
- $post_id['id']=$id;
987
- $post_id['checked']=0;
988
- $list_cache[$id]=$post_id;
989
- }
990
- WPvivid_Setting::update_option('wpvivid_list_cache',$list_cache);
991
- $page=1;
992
-
993
- $arg['screen']=$post_type;
994
- $myListTable = new WPvivid_Post_List($arg);
995
- $myListTable->set_post_ids($list_cache,$page);
996
- $myListTable->prepare_items();
997
- ob_start();
998
- $myListTable->display();
999
- $rows = ob_get_clean();
1000
- $ret['result']='success';
1001
- $ret['rows']=$rows;
1002
- echo json_encode($ret);
1003
-
1004
- die();
1005
- }
1006
-
1007
- public function get_export_list()
1008
- {
1009
- global $wpvivid_plugin;
1010
- $wpvivid_plugin->ajax_check_security();
1011
- $list = get_option('wpvivid_export_list',array());
1012
- $display_list=new WPvivid_Export_List();
1013
- $display_list->set_parent('wpvivid_import_list');
1014
- $display_list->set_list($list);
1015
- $display_list->prepare_items();
1016
- ob_start();
1017
- $display_list->display();
1018
- $html = ob_get_clean();
1019
- $ret['result']='success';
1020
- $ret['html']=$html;
1021
- echo json_encode($ret);
1022
-
1023
- die();
1024
- }
1025
-
1026
- public function get_list_page()
1027
- {
1028
- global $wpvivid_plugin;
1029
- $wpvivid_plugin->ajax_check_security();
1030
-
1031
- if(!isset($_POST['post_type'])&&!isset($_POST['page']))
1032
- {
1033
- die();
1034
- }
1035
-
1036
- $list_cache=get_option('wpvivid_list_cache',array());
1037
-
1038
- WPvivid_Setting::update_option('wpvivid_list_cache',$list_cache);
1039
-
1040
- $page=$_POST['page'];
1041
-
1042
- $post_type=$_POST['post_type'];
1043
- $arg['screen']=$post_type;
1044
-
1045
- $myListTable = new WPvivid_Post_List($arg);
1046
- $myListTable->set_post_ids($list_cache,$page);
1047
- $myListTable->prepare_items();
1048
- ob_start();
1049
- $myListTable->display();
1050
- $rows = ob_get_clean();
1051
-
1052
- $ret['result']='success';
1053
- $ret['rows']=$rows;
1054
- echo json_encode($ret);
1055
- die();
1056
- }
1057
-
1058
- public function export_date_options($post_type = 'post')
1059
- {
1060
- global $wpdb, $wp_locale;
1061
-
1062
- $months = $wpdb->get_results(
1063
- $wpdb->prepare(
1064
- "
1065
- SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
1066
- FROM $wpdb->posts
1067
- WHERE post_type = %s AND post_status != 'auto-draft'
1068
- ORDER BY post_date DESC
1069
- ",
1070
- $post_type
1071
- )
1072
- );
1073
-
1074
- $month_count = count( $months );
1075
- if ( ! $month_count || ( 1 == $month_count && 0 == $months[0]->month ) ) {
1076
- return;
1077
- }
1078
-
1079
- foreach ( $months as $date ) {
1080
- if ( 0 == $date->year ) {
1081
- continue;
1082
- }
1083
-
1084
- $month = zeroise( $date->month, 2 );
1085
- echo '<option value="' . $date->year . '-' . $month . '">' . $wp_locale->get_month( $month ) . ' ' . $date->year . '</option>';
1086
- }
1087
- }
1088
-
1089
- public function prepare_export_post()
1090
- {
1091
- global $wpvivid_plugin;
1092
- $wpvivid_plugin->ajax_check_security();
1093
- if(isset($_POST['post_type'])&&isset($_POST['export_data']))
1094
- {
1095
- $post_type = sanitize_text_field($_POST['post_type']);
1096
- $json_export = sanitize_text_field($_POST['export_data']);
1097
- $json_export = stripslashes($json_export);
1098
- $export_data = json_decode($json_export, true);
1099
-
1100
- $post_ids=array();
1101
- $posts_ids=array();
1102
- if(isset($export_data['post_ids']) && !empty($export_data['post_ids']))
1103
- {
1104
- $post_ids=$export_data['post_ids'];
1105
- }
1106
- foreach ($post_ids as $id=>$checked)
1107
- {
1108
- if($checked)
1109
- {
1110
- $posts_ids[]=$id;
1111
- }
1112
- }
1113
-
1114
- if(empty($posts_ids))
1115
- {
1116
- $ret['result']='failed';
1117
- $ret['error']=__('Empty post id', 'wpvivid-backuprestore');
1118
- echo json_encode($ret);
1119
- die();
1120
- }
1121
- if(WPvivid_Exporter_taskmanager::is_tasks_running())
1122
- {
1123
- $ret['result']='failed';
1124
- $ret['error']=__('A task is already running. Please wait until the running task is complete, and try again.', 'wpvivid-backuprestore');
1125
- echo json_encode($ret);
1126
- die();
1127
- }
1128
-
1129
- $export_task=new WPvivid_Exporter_task();
1130
-
1131
- $options['post_ids']=$posts_ids;
1132
- $options['post_type']=$post_type;
1133
- $options['post_comment']=$export_data['post_comment'];
1134
-
1135
- $ret=$export_task->new_backup_task($options);
1136
- echo json_encode($ret);
1137
- }
1138
- die();
1139
- }
1140
-
1141
- public function export_now()
1142
- {
1143
- global $wpvivid_plugin;
1144
- $wpvivid_plugin->ajax_check_security();
1145
- try
1146
- {
1147
- if (!isset($_POST['task_id']) || empty($_POST['task_id']) || !is_string($_POST['task_id']))
1148
- {
1149
- $ret['result'] = 'failed';
1150
- $ret['error'] = __('Error occurred while parsing the request data. Please try to run export task again.', 'wpvivid-backuprestore');
1151
- echo json_encode($ret);
1152
- die();
1153
- }
1154
-
1155
- $task_id = sanitize_key($_POST['task_id']);
1156
-
1157
- if(WPvivid_Exporter_taskmanager::is_tasks_running())
1158
- {
1159
- $ret['result'] = 'failed';
1160
- $ret['error'] = __('A task is already running. Please wait until the running task is complete, and try again.', 'wpvivid-backuprestore');
1161
- echo json_encode($ret);
1162
- die();
1163
- }
1164
-
1165
- $this->export_post($task_id);
1166
- }
1167
- catch (Exception $error)
1168
- {
1169
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
1170
- error_log($message);
1171
- echo json_encode(array('result'=>'failed','error'=>$message));
1172
- die();
1173
- }
1174
- die();
1175
- }
1176
-
1177
- public function export_post($task_id)
1178
- {
1179
- $this->end_shutdown_function = false;
1180
- register_shutdown_function(array($this,'deal_shutdown_error'),$task_id);
1181
- @ignore_user_abort(true);
1182
-
1183
- WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,true,'running');
1184
-
1185
- global $wpvivid_plugin;
1186
-
1187
- $wpvivid_plugin->wpvivid_log->OpenLogFile(WPvivid_Exporter_taskmanager::get_task_options($task_id,'log_file_name'));
1188
- $wpvivid_plugin->wpvivid_log->WriteLog('Start export posts.','notice');
1189
- $wpvivid_plugin->wpvivid_log->WriteLogHander();
1190
- $this->flush($task_id);
1191
-
1192
- $export=new WPvivid_Exporter();
1193
-
1194
- @set_time_limit(900);
1195
- try
1196
- {
1197
- $ret = $export->export($task_id);
1198
- if($ret['result']=='success')
1199
- {
1200
- do_action('wpvivid_handle_export_success', $task_id, true);
1201
- }
1202
- else
1203
- {
1204
- $wpvivid_plugin->wpvivid_log->WriteLog($ret['error'],'error');
1205
- WPvivid_Exporter_taskmanager::update_backup_task_status($task_id, false, 'error', false, false, $ret['error']);
1206
- do_action('wpvivid_handle_export_failed', $task_id, true);
1207
- }
1208
-
1209
- }
1210
- catch (Exception $error)
1211
- {
1212
- $message = 'An error has occurred. class:'.get_class($error).';msg:'.$error->getMessage().';code:'.$error->getCode().';line:'.$error->getLine().';in_file:'.$error->getFile().';';
1213
- error_log($message);
1214
- WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'error',false,false,$message);
1215
- $wpvivid_plugin->wpvivid_log->WriteLog($message,'error');
1216
- $this->end_shutdown_function=true;
1217
- die();
1218
- }
1219
-
1220
- echo json_encode($ret);
1221
- $this->end_shutdown_function=true;
1222
- die();
1223
- }
1224
-
1225
- public function deal_shutdown_error($task_id)
1226
- {
1227
- if($this->end_shutdown_function===false)
1228
- {
1229
- global $wpvivid_plugin;
1230
-
1231
- $last_error = error_get_last();
1232
- if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE,E_WARNING,E_USER_NOTICE,E_USER_WARNING,E_DEPRECATED), true))
1233
- {
1234
- $error = $last_error;
1235
- } else {
1236
- $error = false;
1237
- }
1238
- if (WPvivid_Exporter_taskmanager::get_task($task_id) !== false)
1239
- {
1240
- if ($wpvivid_plugin->wpvivid_log->log_file_handle == false)
1241
- {
1242
- $wpvivid_plugin->wpvivid_log->OpenLogFile(WPvivid_Exporter_taskmanager::get_task_options($task_id, 'log_file_name'));
1243
- }
1244
-
1245
- $status = WPvivid_Exporter_taskmanager::get_backup_task_status($task_id);
1246
-
1247
- $message='in shutdown';
1248
-
1249
- if ($error !== false)
1250
- {
1251
- $message= 'type: '. $error['type'] . ', ' . $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
1252
- }
1253
- WPvivid_Exporter_taskmanager::update_backup_task_status($task_id, false, 'error', false, $status['resume_count'], $message);
1254
- if ($wpvivid_plugin->wpvivid_log)
1255
- $wpvivid_plugin->wpvivid_log->WriteLog($message, 'error');
1256
- }
1257
- die();
1258
- }
1259
- }
1260
-
1261
- public function handle_export_success($task_id)
1262
- {
1263
- global $wpvivid_plugin;
1264
- WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'completed');
1265
-
1266
- $wpvivid_plugin->wpvivid_log->WriteLog('Finished to export post','notice');
1267
- }
1268
-
1269
- public function handle_export_failed($task_id)
1270
- {
1271
- }
1272
-
1273
- public function list_tasks()
1274
- {
1275
- global $wpvivid_plugin;
1276
- $wpvivid_plugin->ajax_check_security();
1277
-
1278
- $ret['result']='success';
1279
- $ret['show']=false;
1280
- $tasks=WPvivid_Exporter_taskmanager::get_tasks();
1281
- foreach ($tasks as $task)
1282
- {
1283
- $this->task_monitor($task['id']);
1284
- $task=WPvivid_Exporter_taskmanager::get_task($task['id']);
1285
- $status=WPvivid_Exporter_taskmanager::get_backup_task_status($task['id']);
1286
-
1287
- $ret['show']=true;
1288
- $ret['completed']=false;
1289
- $ret['error']=false;
1290
- if($status['str']=='running'||$status['str']=='no_responds'||$status['str']=='ready')
1291
- {
1292
- $ret['continue']=1;
1293
- }
1294
- else
1295
- {
1296
- $ret['continue']=0;
1297
- $ret['show']=false;
1298
- }
1299
-
1300
- $progress=WPvivid_Exporter_taskmanager::get_backup_tasks_progress($task['id']);
1301
- $ret['percent']='<div class="action-progress-bar-percent" style="height:24px;width:'.(int)$progress['progress'].'%;"></div>';
1302
- $ret['doing']=$task['data']['doing']='export';
1303
- if($status['str']=='ready')
1304
- {
1305
- $ret['doing']=__('Ready to export. Progress: 0%, running time: 0second.','wpvivid-backuprestore');
1306
- }
1307
- else if($status['str']=='running')
1308
- {
1309
- $ret['doing']= ' '.__('Progress: ', 'wpvivid-backuprestore') . $progress['descript'] . ', '.__('running time: ', 'wpvivid-backuprestore') . $progress['running_time'];
1310
- }
1311
- else if($status['str']=='wait_resume')
1312
- {
1313
- $ret['doing']='Task '.$task['id'].' timed out, the export task will retry in '.$task['data']['next_resume_time'].' seconds, retry times: '.$task['status']['resume_count'].'.';
1314
- }
1315
- else if($status['str']=='no_responds')
1316
- {
1317
- $ret['doing']=__('The export task is not responding.','wpvivid-backuprestore');
1318
- }
1319
- else if($status['str']=='completed')
1320
- {
1321
- $file_name = $task['data']['export']['export_info']['file_name'];
1322
- $file_size = $task['data']['export']['export_info']['size'];
1323
- if($task['options']['backup_options']['post_type'] === 'post'){
1324
- $post_type = 'posts';
1325
- }
1326
- else{
1327
- $post_type = 'pages';
1328
- }
1329
- $msg = '<div style="margin-bottom: 10px;">The export task is completed and the automatic download starts. If the automatic download didn\'t run, please click <a style="cursor:pointer;" onclick="wpvivid_download_export(\''.$file_name.'\', \''.$file_size.'\');">here</a> to download.</div>';
1330
- $msg .= '<div style="margin-bottom: 10px;">The count of exported '.$post_type.': '.$task['data']['export']['export_info']['post_count'].'.</div>';
1331
- $msg .= '<div style="margin-bottom: 10px;">File name: '.$file_name.'.</div>';
1332
- $msg .= '<div>File size: '.size_format($file_size, 2).'.</div>';
1333
-
1334
- $ret['completed']=true;
1335
- $ret['file_name'] = $file_name;
1336
- $ret['file_size'] = $file_size;
1337
- $ret['doing']=$msg;
1338
- }
1339
- else if($status['str']=='error')
1340
- {
1341
- $ret['doing']='Export error: '.$task['status']['error'];
1342
- $ret['doing']='<div class="notice notice-error is-dismissible inline"><p>'.__('Export error:', 'wpvivid-backuprestore').' '.$task['status']['error'].'</p></div>';
1343
- $ret['error']=true;
1344
- }
1345
-
1346
- if($ret['completed']||$ret['error'])
1347
- {
1348
- WPvivid_Exporter_taskmanager::delete_task($task['id']);
1349
- }
1350
- }
1351
- echo json_encode($ret);
1352
- die();
1353
- }
1354
-
1355
- public function task_monitor($task_id)
1356
- {
1357
- global $wpvivid_plugin;
1358
-
1359
- if(WPvivid_Exporter_taskmanager::get_task($task_id)!==false)
1360
- {
1361
- if($wpvivid_plugin->wpvivid_log->log_file_handle==false)
1362
- {
1363
- $wpvivid_plugin->wpvivid_log->OpenLogFile(WPvivid_Exporter_taskmanager::get_task_options($task_id,'log_file_name'));
1364
- }
1365
-
1366
- $status=WPvivid_Exporter_taskmanager::get_backup_task_status($task_id);
1367
-
1368
- if($status['str']=='running'||$status['str']=='error'||$status['str']=='no_responds')
1369
- {
1370
- $limit=900;
1371
- $time_spend=time()-$status['timeout'];
1372
-
1373
- if($time_spend>=$limit)
1374
- {
1375
- //time out
1376
- $message=__('Task time out.', 'wpvivid-backuprestore');
1377
- WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'error',false,$status['resume_count'],$message);
1378
- if($wpvivid_plugin->wpvivid_log)
1379
- $wpvivid_plugin->wpvivid_log->WriteLog($message,'error');
1380
- $wpvivid_plugin->wpvivid_log->CloseFile();
1381
- WPvivid_error_log::create_error_log($wpvivid_plugin->wpvivid_log->log_file);
1382
- }
1383
- else {
1384
- $time_spend=time()-$status['run_time'];
1385
- if($time_spend>180)
1386
- {
1387
- $wpvivid_plugin->wpvivid_log->WriteLog('Not responding for a long time.','notice');
1388
- WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'no_responds',false,$status['resume_count']);
1389
- }
1390
- }
1391
- }
1392
- }
1393
- }
1394
-
1395
- public function delete_export_list()
1396
- {
1397
- global $wpvivid_plugin;
1398
- $wpvivid_plugin->ajax_check_security();
1399
-
1400
- if(isset($_POST['export_id']))
1401
- {
1402
- $id=sanitize_key($_POST['export_id']);
1403
- $list = get_option('wpvivid_import_list_cache',array());
1404
- if(empty($list))
1405
- {
1406
- $ret['result']='success';
1407
- }
1408
- else
1409
- {
1410
- if(isset($list[$id]))
1411
- {
1412
- $item=$list[$id];
1413
- if(isset($item['export']))
1414
- {
1415
- foreach ($item['export'] as $file)
1416
- {
1417
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR.$file['file_name'];
1418
- @unlink($path);
1419
- }
1420
- }
1421
- unset($list[$id]);
1422
- WPvivid_Setting::update_option('wpvivid_import_list_cache',$list);
1423
- $ret['result']='success';
1424
- }
1425
- else
1426
- {
1427
- $ret['result']='success';
1428
- }
1429
- }
1430
- echo json_encode($ret);
1431
- }
1432
- die();
1433
- }
1434
-
1435
- public function wpvivid_download_export_backup()
1436
- {
1437
- global $wpvivid_plugin;
1438
- $wpvivid_plugin->ajax_check_security();
1439
- try{
1440
- if(isset($_REQUEST['file_name']) && !empty($_REQUEST['file_name']) && is_string($_REQUEST['file_name']) &&
1441
- isset($_REQUEST['file_size']) && !empty($_REQUEST['file_size']) && is_string($_REQUEST['file_size'])){
1442
- $file_name = $_REQUEST['file_name'];
1443
- $file_size = intval($_REQUEST['file_size']);
1444
-
1445
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR.$file_name;
1446
- if (file_exists($path)) {
1447
- if (session_id()) {
1448
- session_write_close();
1449
- }
1450
- $size = filesize($path);
1451
- if($size === $file_size) {
1452
- if (!headers_sent()) {
1453
- header('Content-Description: File Transfer');
1454
- header('Content-Type: application/zip');
1455
- header('Content-Disposition: attachment; filename="' . basename($path) . '"');
1456
- header('Cache-Control: must-revalidate');
1457
- header('Content-Length: ' . $size);
1458
- header('Content-Transfer-Encoding: binary');
1459
- }
1460
- if ($size < 1024 * 1024 * 60) {
1461
- ob_end_clean();
1462
- readfile($path);
1463
- exit;
1464
- } else {
1465
- ob_end_clean();
1466
- $download_rate = 1024 * 10;
1467
- $file = fopen($path, "r");
1468
- while (!feof($file)) {
1469
- @set_time_limit(20);
1470
- // send the current file part to the browser
1471
- print fread($file, round($download_rate * 1024));
1472
- // flush the content to the browser
1473
- flush();
1474
- // sleep one second
1475
- sleep(1);
1476
- }
1477
- fclose($file);
1478
- exit;
1479
- }
1480
- }
1481
- else{
1482
- $admin_url = admin_url();
1483
- echo '<a href="'.$admin_url.'admin.php?page=wpvivid-export-import">'.__('File size not match. please retry again.', 'wpvivid-backuprestore').'</a>';
1484
- die();
1485
- }
1486
- }
1487
-
1488
- $admin_url = admin_url();
1489
- echo '<a href="'.$admin_url.'admin.php?page=wpvivid-export-import">'.__('File not found. please retry again.', 'wpvivid-backuprestore').'</a>';
1490
- die();
1491
- }
1492
- }
1493
- catch (Exception $error) {
1494
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
1495
- error_log($message);
1496
- echo json_encode(array('result'=>'failed','error'=>$message));
1497
- die();
1498
- }
1499
- }
1500
-
1501
- //import
1502
- public function output_import()
1503
- {
1504
- $import_dir = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
1505
- WPvivid_Setting::update_option('wpvivid_import_list_cache',array());
1506
- WPvivid_Setting::update_option('wpvivid_importer_task_list', array());
1507
- ?>
1508
- <div class="postbox export-import-block">
1509
- <div>
1510
- <div class="wpvivid-element-space-bottom wpvivid-element-space-right" style="float: left;">
1511
- <img src="<?php echo esc_url(WPVIVID_PLUGIN_IMAGES_URL.'export-import.png'); ?>" style="width:50px;height:50px;">
1512
- </div>
1513
- <div style="box-sizing: border-box;">
1514
- <div class="wpvivid-element-space-bottom wpvivid-element-space-right"><?php _e('Import posts or pages with images in bulk.', 'wpvivid-backuprestore'); ?>
1515
- <span class="wpvivid-feature-pro">
1516
- <a href="https://wpvivid.com/import-content" target="_blank" style="text-decoration: none;"><?php _e('Learn more', 'wpvivid-backuprestore'); ?></a>
1517
- </span>
1518
- </div>
1519
- <div class="wpvivid-element-space-bottom wpvivid-element-space-right"><strong><?php _e('Note:', 'wpvivid-backuprestore'); ?></strong>
1520
- <?php _e('To properly display the imported content, please make sure that the importing and exporting sites have the same environment, for example, same theme or pages built with the same page builder.', 'wpvivid-backuprestore'); ?>
1521
- </div>
1522
- <div style="clear: both;"></div>
1523
- </div>
1524
- <div style="clear: both;"></div>
1525
- </div>
1526
- <div style="clear: both;"></div>
1527
-
1528
- <div style="background: #fff; border: 1px solid #e5e5e5; border-radius: 6px; margin-bottom: 10px; padding: 10px;">
1529
- <div style="margin-right: 10px; float: left; height: 28px; line-height: 28px;"><?php echo sprintf(__('Imported files will be temporarily stored in directory %s', 'wpvivid-backuprestore'), $import_dir) ?></div>
1530
- <div style="float: left;"><input class="button" type="submit" id="wpvivid_empty_import_folder" value="<?php esc_attr_e('Delete Exported Files In Folder', 'wpvivid-backuprestore'); ?>" onclick="wpvivid_clean_import_folder();" /></div>
1531
- <div style="clear: both;"></div>
1532
- </div>
1533
-
1534
- <div id="wpvivid_import_step1">
1535
- <p><?php _e('Choose an export from your computer to import: ', 'wpvivid-backuprestore'); ?></p>
1536
- <input class="button button-primary" type="button" id="wpvivid_select_import_file_button" value="<?php esc_attr_e('Upload and Import', 'wpvivid-backuprestore'); ?>" />
1537
- <div id="wpvivid_upload_file_list" class="hide-if-no-js" style="margin-top: 10px; display: none;"></div>
1538
- <br>
1539
- <p><?php echo sprintf(__('Or you can use ftp to upload the export to the directory %s. Then click the button below to scan the file to import.', 'wpvivid-backuprestore'), $import_dir); ?></p>
1540
- <input class="button button-primary" type="button" value="<?php esc_attr_e('Scan Uploaded Exports', 'wpvivid-backuprestore'); ?>" onclick="wpvivid_refresh_import_list();" />
1541
- <div class="wpvivid-export-import-block" id="wpvivid_import_list" style="margin-top: 10px; display: none;"></div>
1542
- </div>
1543
- <div id="wpvivid_import_step2" style="display: none;">
1544
- <h3><?php _e('The importing file info', 'wpvivid-backuprestore'); ?></h3>
1545
- <div id="wpvivid_import_file_data">
1546
- </div>
1547
- <h3><?php _e('Assign author', 'wpvivid-backuprestore'); ?></h3>
1548
- <div>
1549
- <?php _e('Select an existing author:', 'wpvivid-backuprestore'); ?>
1550
- <?php wp_dropdown_users( array( 'name' => "user_map", 'multi' => true, 'show_option_all' => __( '- Select -', 'wpvivid-backuprestore' ) ) );?>
1551
- </div>
1552
- <h3><?php _e('Import Setting', 'wpvivid-backuprestore'); ?></h3>
1553
- <div style="margin-bottom: 10px;">
1554
- <label>
1555
- <input type="checkbox" id="wpvivid_overwrite_existing" />
1556
- <span><strong><?php _e('Overwrite existing pages', 'wpvivid-backuprestore'); ?></strong></span>
1557
- </label>
1558
- </div>
1559
- <div style="margin-bottom: 10px;">
1560
- <span><?php _e('With this option checked, Pages/posts already existing will be overwritten with the updated ones in an import.', 'wpvivid-backuprestore'); ?></span>
1561
- </div>
1562
- <input class="button button-primary" type="button" id="wpvivid_start_import" value="<?php esc_attr_e('Start to Import', 'wpvivid-backuprestore'); ?>" />
1563
- <input class="button button-primary" type="button" id="wpvivid_rechoose_import_file" value="<?php esc_attr_e('Back to Import Page', 'wpvivid-backuprestore'); ?>" />
1564
- </div>
1565
- <div id="wpvivid_import_step3" style="display: none;">
1566
- <div class="postbox wpvivid-import-log" id="wpvivid_import_log" style="margin-top: 10px; margin-bottom: 0;"></div>
1567
- </div>
1568
- </div>
1569
- <?php
1570
- $chunk_size = min(wp_max_upload_size()-1024, 1048576*2);
1571
- $plupload_init = array(
1572
- 'runtimes' => 'html5,silverlight,flash,html4',
1573
- 'browse_button' => 'wpvivid_select_import_file_button',
1574
- 'file_data_name' => 'async-upload',
1575
- 'max_retries' => 3,
1576
- 'multiple_queues' => true,
1577
- 'max_file_size' => '10Gb',
1578
- 'chunk_size' => $chunk_size.'b',
1579
- 'url' => admin_url('admin-ajax.php'),
1580
- 'flash_swf_url' => includes_url('js/plupload/plupload.flash.swf'),
1581
- 'silverlight_xap_url' => includes_url('js/plupload/plupload.silverlight.xap'),
1582
- 'multipart' => true,
1583
- 'urlstream_upload' => true,
1584
- 'multi_selection' => false,
1585
- // additional post data to send to our ajax hook
1586
- 'multipart_params' => array(
1587
- '_ajax_nonce' => wp_create_nonce('wpvivid_ajax'),
1588
- 'action' => 'wpvivid_upload_import_files', // the ajax action name
1589
- ),
1590
- );
1591
- if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.swf')) {
1592
- $plupload_init['flash_swf_url'] = includes_url('js/plupload/Moxie.swf');
1593
- } else {
1594
- $plupload_init['flash_swf_url'] = includes_url('js/plupload/plupload.flash.swf');
1595
- }
1596
-
1597
- if (is_file(ABSPATH.WPINC.'/js/plupload/Moxie.xap')) {
1598
- $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/Moxie.xap');
1599
- } else {
1600
- $plupload_init['silverlight_xap_url'] = includes_url('js/plupload/plupload.silverlight.swf');
1601
- }
1602
-
1603
- // we should probably not apply this filter, plugins may expect wp's media uploader...
1604
- $plupload_init = apply_filters('plupload_init', $plupload_init);
1605
- $upload_file_image = includes_url( '/images/media/archive.png' );
1606
- ?>
1607
- <script type="text/javascript">
1608
- var uploader;
1609
- var import_file_name='';
1610
- jQuery(document).ready(function($)
1611
- {
1612
- // create the uploader and pass the config from above
1613
- jQuery('#wpvivid_upload_submit_btn').hide();
1614
- uploader = new plupload.Uploader(<?php echo json_encode($plupload_init); ?>);
1615
-
1616
- // checks if browser supports drag and drop upload, makes some css adjustments if necessary
1617
- uploader.bind('Init', function(up)
1618
- {
1619
- var uploaddiv = $('#wpvivid_plupload-upload-ui');
1620
-
1621
- if(up.features.dragdrop){
1622
- uploaddiv.addClass('drag-drop');
1623
- $('#drag-drop-area')
1624
- .bind('dragover.wp-uploader', function(){ uploaddiv.addClass('drag-over'); })
1625
- .bind('dragleave.wp-uploader, drop.wp-uploader', function(){ uploaddiv.removeClass('drag-over'); });
1626
-
1627
- }else{
1628
- uploaddiv.removeClass('drag-drop');
1629
- $('#drag-drop-area').unbind('.wp-uploader');
1630
- }
1631
- });
1632
- uploader.init();
1633
-
1634
- function wpvivid_check_plupload_added_files(up, files)
1635
- {
1636
- jQuery('#wpvivid_import_list').hide();
1637
- var file=files[0];
1638
-
1639
- var ajax_data = {
1640
- 'action': 'wpvivid_check_import_file',
1641
- 'file_name':file.name
1642
- };
1643
- wpvivid_post_request(ajax_data, function (data)
1644
- {
1645
- var jsonarray = jQuery.parseJSON(data);
1646
- if (jsonarray.result === "success")
1647
- {
1648
- jQuery('#wpvivid_select_import_file_button').css({'pointer-events': 'none', 'opacity': '0.4'});
1649
- var repeat_files = '';
1650
- plupload.each(files, function(file)
1651
- {
1652
- var brepeat=false;
1653
- var file_list = jQuery('#wpvivid_upload_file_list span');
1654
- file_list.each(function (index, value) {
1655
- if (value.innerHTML === file.name) {
1656
- brepeat=true;
1657
- }
1658
- });
1659
- if(!brepeat) {
1660
- jQuery('#wpvivid_upload_file_list').append(
1661
- '<div id="' + file.id + '" style="width: 100%; height: 36px; background: #f1f1f1; margin-bottom: 1px;">' +
1662
- '<img src=" <?php echo $upload_file_image; ?> " alt="" style="float: left; margin: 2px 10px 0 3px; max-width: 40px; max-height: 32px;">' +
1663
- '<div style="line-height: 36px; float: left; margin-left: 5px;"><span>' + file.name + '</span></div>' +
1664
- '<div class="fileprogress" style="line-height: 36px; float: right; margin-right: 5px;"></div>' +
1665
- '</div>' +
1666
- '<div style="clear: both;"></div>'
1667
- );
1668
- jQuery('#wpvivid_upload_file_list').show();
1669
-
1670
- uploader.refresh();
1671
- uploader.start();
1672
- }
1673
- else{
1674
- if(repeat_files === ''){
1675
- repeat_files += file.name;
1676
- }
1677
- else{
1678
- repeat_files += ', ' + file.name;
1679
- }
1680
- }
1681
- });
1682
- if(repeat_files !== ''){
1683
- alert(repeat_files + " already exists in upload list.");
1684
- repeat_files = '';
1685
- }
1686
- }
1687
- else if(jsonarray.result === "failed")
1688
- {
1689
- uploader.removeFile(file);
1690
- alert(jsonarray.error);
1691
- }
1692
- }, function (XMLHttpRequest, textStatus, errorThrown)
1693
- {
1694
- var error_message = wpvivid_output_ajaxerror('uploading backups', textStatus, errorThrown);
1695
- uploader.removeFile(file);
1696
- alert(error_message);
1697
- });
1698
- }
1699
-
1700
- uploader.bind('FilesAdded', wpvivid_check_plupload_added_files);
1701
-
1702
- uploader.bind('Error', function(up, error)
1703
- {
1704
- alert('Upload ' + error.file.name +' error, error code: ' + error.code + ', ' + error.message);
1705
- console.log(error);
1706
- });
1707
-
1708
- uploader.bind('FileUploaded', function(up, file, response)
1709
- {
1710
- var jsonarray = jQuery.parseJSON(response.response);
1711
- if(jsonarray.result == 'failed'){
1712
- alert('upload ' + file.name + ' failed, ' + jsonarray.error);
1713
- }
1714
- });
1715
-
1716
- uploader.bind('UploadProgress', function(up, file)
1717
- {
1718
- jQuery('#' + file.id + " .fileprogress").html(file.percent + "%");
1719
- });
1720
-
1721
- uploader.bind('UploadComplete',function(up, files)
1722
- {
1723
- jQuery('#wpvivid_select_import_file_button').css({'pointer-events': 'auto', 'opacity': '1'});
1724
- var ajax_data = {
1725
- 'action': 'wpvivid_upload_import_file_complete',
1726
- 'files':JSON.stringify(files)
1727
- };
1728
- wpvivid_post_request(ajax_data, function (data)
1729
- {
1730
- try
1731
- {
1732
- var jsonarray = jQuery.parseJSON(data);
1733
- if(jsonarray.result === 'success')
1734
- {
1735
- jQuery('#wpvivid_upload_file_list').html("");
1736
- jQuery('#wpvivid_upload_file_list').hide();
1737
- wpvivid_import_step2(jsonarray.data);
1738
- }
1739
- else if(jsonarray.result === 'failed')
1740
- {
1741
- jQuery('#wpvivid_upload_file_list').html("");
1742
- jQuery('#wpvivid_upload_file_list').hide();
1743
- alert(jsonarray.error);
1744
- }
1745
- }
1746
- catch(err)
1747
- {
1748
- alert(err);
1749
- }
1750
- }, function (XMLHttpRequest, textStatus, errorThrown)
1751
- {
1752
- var error_message = wpvivid_output_ajaxerror('refreshing backup list', textStatus, errorThrown);
1753
- alert(error_message);
1754
- });
1755
- plupload.each(files, function(file)
1756
- {
1757
- if(typeof file === 'undefined')
1758
- {
1759
-
1760
- }
1761
- else
1762
- {
1763
- uploader.removeFile(file.id);
1764
- }
1765
- });
1766
- })
1767
- });
1768
-
1769
- function wpvivid_clean_import_folder()
1770
- {
1771
- var descript = 'Are you sure you want to delete all the exported files in the /ImportandExport folder? All the export files in the folder will be permanently deleted.';
1772
- var ret = confirm(descript);
1773
- if(ret === true){
1774
- var ajax_data = {
1775
- 'action': 'wpvivid_clean_import_folder'
1776
- };
1777
- wpvivid_post_request(ajax_data, function (data)
1778
- {
1779
- try {
1780
- var jsonarray = jQuery.parseJSON(data);
1781
- if(jsonarray.html !== false) {
1782
- jQuery('#wpvivid_import_list').html(jsonarray.html);
1783
- jQuery('#wpvivid_empty_import_folder').val('Delete Exported Files In Folder ('+jsonarray.size+')');
1784
- }
1785
- }
1786
- catch(err) {
1787
- alert(err);
1788
- }
1789
- }, function (XMLHttpRequest, textStatus, errorThrown) {
1790
- var error_message = wpvivid_output_ajaxerror('scanning import folder', textStatus, errorThrown);
1791
- alert(error_message);
1792
- });
1793
- }
1794
- }
1795
-
1796
- function wpvivid_import_step2(data)
1797
- {
1798
- jQuery('#wpvivid_import_file_data').html('');
1799
- jQuery.each(data, function (index, value)
1800
- {
1801
- import_file_name=value['file_name'];
1802
- var list = "";
1803
- var myDate = new Date(value['time']*1000);
1804
- list += "<li>File name: " + value['file_name'] + "</li>";
1805
- list += "<li>Post type: " + value['export_type'] + "</li>";
1806
- list += "<li>Posts: " + value['posts_count'] + "</li>";
1807
- list += "<li>Media files size: " + value['media_size'] + "</li>";
1808
- list += "<li>Export time: " + myDate.toLocaleString('en-us') + "</li>";
1809
- jQuery("#wpvivid_import_file_data").append("<ul>"+ list +"</ul>");
1810
- });
1811
-
1812
- jQuery('#wpvivid_import_step1').hide();
1813
- jQuery('#wpvivid_import_step2').show();
1814
- jQuery('#wpvivid_import_step3').hide();
1815
- }
1816
-
1817
- function wpvivid_import_step3()
1818
- {
1819
- jQuery('#wpvivid_import_step1').hide();
1820
- jQuery('#wpvivid_import_step2').hide();
1821
- jQuery('#wpvivid_import_step3').show();
1822
- }
1823
-
1824
- function wpvivid_return_import_page(){
1825
- jQuery('#wpvivid_import_step1').show();
1826
- jQuery('#wpvivid_import_step2').hide();
1827
- jQuery('#wpvivid_import_step3').hide();
1828
- }
1829
-
1830
- function wpvivid_monitor_import_task()
1831
- {
1832
- var ajax_data = {
1833
- 'action': 'wpvivid_get_import_progress',
1834
- };
1835
- wpvivid_post_request(ajax_data, function(data)
1836
- {
1837
- try
1838
- {
1839
- var jsonarray = jQuery.parseJSON(data);
1840
- if (typeof jsonarray === 'object')
1841
- {
1842
- if (jsonarray.result === 'success')
1843
- {
1844
- jQuery('#wpvivid_import_log').html("");
1845
- while (jsonarray.log.indexOf('\n') >= 0)
1846
- {
1847
- var iLength = jsonarray.log.indexOf('\n');
1848
- var log = jsonarray.log.substring(0, iLength);
1849
- jsonarray.log = jsonarray.log.substring(iLength + 1);
1850
- var insert_log = "<div style=\"clear:both;\">" + log + "</div>";
1851
- jQuery('#wpvivid_import_log').append(insert_log);
1852
- var div = jQuery('#wpvivid_import_log');
1853
- div[0].scrollTop = div[0].scrollHeight;
1854
- }
1855
- if (jsonarray.status === 'wait')
1856
- {
1857
- setTimeout(function () {
1858
- wpvivid_monitor_import_task();
1859
- }, 1000);
1860
- }
1861
- else if (jsonarray.status === 'completed')
1862
- {
1863
- var insert_log = "<div style=\"clear:both;\"><a style='cursor: pointer;' onclick='wpvivid_return_import_page();'>Return import page</a></div>";
1864
- jQuery('#wpvivid_import_log').append(insert_log);
1865
- var div = jQuery('#wpvivid_import_log');
1866
- div[0].scrollTop = div[0].scrollHeight;
1867
- setTimeout(function () {
1868
- alert("Import completed successfully.");
1869
- }, 1000);
1870
- wpvivid_import_lock_unlock('unlock');
1871
- }
1872
- else if (jsonarray.status === 'error')
1873
- {
1874
- alert("Import failed.");
1875
- wpvivid_import_lock_unlock('unlock');
1876
- }
1877
- else
1878
- {
1879
- setTimeout(function ()
1880
- {
1881
- wpvivid_monitor_import_task();
1882
- }, 1000);
1883
- }
1884
- }
1885
- else {
1886
- setTimeout(function () {
1887
- wpvivid_monitor_import_task();
1888
- }, 1000);
1889
- }
1890
- }
1891
- else{
1892
- setTimeout(function () {
1893
- wpvivid_monitor_import_task();
1894
- }, 1000);
1895
- }
1896
- }
1897
- catch (err) {
1898
- setTimeout(function () {
1899
- wpvivid_monitor_import_task();
1900
- }, 1000);
1901
- }
1902
- },function(XMLHttpRequest, textStatus, errorThrown) {
1903
- setTimeout(function () {
1904
- wpvivid_monitor_import_task();
1905
- }, 1000);
1906
- });
1907
- }
1908
-
1909
- jQuery('#wpvivid_start_import').click(function()
1910
- {
1911
- if(import_file_name!=='')
1912
- {
1913
- var descript = '';
1914
- var user=jQuery('select[name="user_map"]').val();
1915
- if(user !== '0'){
1916
- wpvivid_start_import(import_file_name, user);
1917
- }
1918
- else{
1919
- alert('Please select an existing author to start importing.');
1920
- }
1921
- }
1922
- });
1923
-
1924
- jQuery('#wpvivid_rechoose_import_file').click(function(){
1925
- jQuery('#wpvivid_import_step1').show();
1926
- jQuery('#wpvivid_import_step2').hide();
1927
- jQuery('#wpvivid_import_step3').hide();
1928
- });
1929
-
1930
- function wpvivid_start_import (file_name, user)
1931
- {
1932
- if(jQuery('#wpvivid_overwrite_existing').prop('checked')){
1933
- var overwrite_existing = 1;
1934
- }
1935
- else{
1936
- var overwrite_existing = 0;
1937
- }
1938
-
1939
- wpvivid_import_lock_unlock('lock');
1940
- wpvivid_monitor_import_task();
1941
- wpvivid_import_step3();
1942
- var ajax_data = {
1943
- 'action':'wpvivid_start_import',
1944
- 'file_name':file_name,
1945
- 'user':user,
1946
- 'update_exist':overwrite_existing
1947
- };
1948
-
1949
- wpvivid_post_request(ajax_data, function(data)
1950
- {
1951
- }, function(XMLHttpRequest, textStatus, errorThrown)
1952
- {
1953
- });
1954
- }
1955
-
1956
- var wpvivid_scan_data={};
1957
-
1958
- function wpvivid_refresh_import_list()
1959
- {
1960
- var ajax_data = {
1961
- 'action': 'wpvivid_scan_import_folder'
1962
- };
1963
- wpvivid_post_request(ajax_data, function (data)
1964
- {
1965
- try {
1966
- var jsonarray = jQuery.parseJSON(data);
1967
- if(jsonarray.html !== false)
1968
- {
1969
- wpvivid_scan_data=jsonarray.data;
1970
- jQuery('#wpvivid_import_list').show();
1971
- jQuery('#wpvivid_import_list').html(jsonarray.html);
1972
- }
1973
- }
1974
- catch(err) {
1975
- alert(err);
1976
- }
1977
- }, function (XMLHttpRequest, textStatus, errorThrown)
1978
- {
1979
- var error_message = wpvivid_output_ajaxerror('scanning import folder', textStatus, errorThrown);
1980
- alert(error_message);
1981
- });
1982
- }
1983
-
1984
- jQuery('#wpvivid_import_list').on("click",'.first-page',function()
1985
- {
1986
- wpvivid_change_import_page('first');
1987
- });
1988
-
1989
- jQuery('#wpvivid_import_list').on("click",'.prev-page',function()
1990
- {
1991
- var page=parseInt(jQuery(this).attr('value'));
1992
- wpvivid_change_import_page(page-1);
1993
- });
1994
-
1995
- jQuery('#wpvivid_import_list').on("click",'.next-page',function()
1996
- {
1997
- var page=parseInt(jQuery(this).attr('value'));
1998
- wpvivid_change_import_page(page+1);
1999
- });
2000
-
2001
- jQuery('#wpvivid_import_list').on("click",'.last-page',function()
2002
- {
2003
- wpvivid_change_import_page('last');
2004
- });
2005
-
2006
- jQuery('#wpvivid_import_list').on("keypress", '.current-page', function(){
2007
- if(event.keyCode === 13){
2008
- var page = jQuery(this).val();
2009
- wpvivid_change_import_page(page);
2010
- }
2011
- });
2012
-
2013
- function wpvivid_change_import_page(page)
2014
- {
2015
- var post_ids = {};
2016
-
2017
- jQuery('input[name="export[]"]').each(function (i)
2018
- {
2019
- var id=jQuery(this).val();
2020
- if(jQuery(this).prop('checked'))
2021
- {
2022
- post_ids[id]=1;
2023
- }
2024
- else
2025
- {
2026
- post_ids[id]=0;
2027
- }
2028
- });
2029
-
2030
- var ajax_data = {
2031
- 'action':'wpvivid_get_import_list_page',
2032
- 'page': page,
2033
- 'post_ids':post_ids
2034
- };
2035
-
2036
- wpvivid_post_request(ajax_data, function(data)
2037
- {
2038
- var jsonarray = jQuery.parseJSON(data);
2039
- if (jsonarray.result === 'success')
2040
- {
2041
- jQuery('#wpvivid_import_list').html(jsonarray.rows);
2042
- }
2043
- else if (jsonarray.result === 'failed')
2044
- {
2045
- alert(jsonarray.error);
2046
- }
2047
- }, function(XMLHttpRequest, textStatus, errorThrown)
2048
- {
2049
- var error_message = wpvivid_output_ajaxerror('export the previously-exported settings', textStatus, errorThrown);
2050
- alert(error_message);
2051
- });
2052
- }
2053
-
2054
- jQuery('#wpvivid_import_list').on("click",".wpvivid-export-list-item td",function()
2055
- {
2056
- var id = jQuery(this).parent().attr('id');
2057
-
2058
- if(jQuery(this).find('div.export-list-import').length !== 0)
2059
- {
2060
- var data={};
2061
- data[id]=wpvivid_scan_data[id];
2062
- console.log(data[id]);
2063
- wpvivid_import_step2(data);
2064
- jQuery('#wpvivid_import_list').hide();
2065
- }
2066
- });
2067
-
2068
- function wpvivid_calc_import_folder_size(){
2069
- var ajax_data = {
2070
- 'action': 'wpvivid_calc_import_folder_size'
2071
- };
2072
- wpvivid_post_request(ajax_data, function(data)
2073
- {
2074
- var jsonarray = jQuery.parseJSON(data);
2075
- if (jsonarray.result === 'success')
2076
- {
2077
- jQuery('#wpvivid_empty_import_folder').val('Delete Exported Files In Folder ('+jsonarray.size+')');
2078
- }
2079
- }, function(XMLHttpRequest, textStatus, errorThrown)
2080
- {
2081
- var error_message = wpvivid_output_ajaxerror('calc import folder size', textStatus, errorThrown);
2082
- alert(error_message);
2083
- });
2084
- }
2085
-
2086
- jQuery(document).ready(function (){
2087
- wpvivid_calc_import_folder_size();
2088
- });
2089
- </script>
2090
- <?php
2091
- }
2092
-
2093
- public function wpvivid_check_import_file_name($file_name){
2094
- if(preg_match('/wpvivid-.*_.*_export_.*\.zip$/', $file_name))
2095
- {
2096
- if(preg_match('/wpvivid-(.*?)_/',$file_name,$matches))
2097
- {
2098
- $id= $matches[0];
2099
- $id=substr($id,0,strlen($id)-1);
2100
- $ret['result']=WPVIVID_SUCCESS;
2101
- $ret['id']=$id;
2102
- }
2103
- else
2104
- {
2105
- $ret['result']=WPVIVID_FAILED;
2106
- $ret['error']=$file_name.' is not the file exported by WPvivid backup plugin.';
2107
- }
2108
- }
2109
- else
2110
- {
2111
- $ret['result']=WPVIVID_FAILED;
2112
- $ret['error']=$file_name.' is not the file exported by WPvivid backup plugin.';
2113
- }
2114
- return $ret;
2115
- }
2116
-
2117
- public function check_import_file()
2118
- {
2119
- global $wpvivid_plugin;
2120
- $wpvivid_plugin->ajax_check_security();
2121
- if(isset($_POST['file_name']))
2122
- {
2123
- $ret = $this->wpvivid_check_import_file_name($_POST['file_name']);
2124
- }
2125
- else
2126
- {
2127
- $ret['result']=WPVIVID_FAILED;
2128
- $ret['error']='Failed to post file name.';
2129
- }
2130
-
2131
- echo json_encode($ret);
2132
- die();
2133
- }
2134
-
2135
- public function upload_import_dir($uploads)
2136
- {
2137
- $uploads['path'] = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
2138
- return $uploads;
2139
- }
2140
-
2141
- public function upload_import_files()
2142
- {
2143
- global $wpvivid_plugin;
2144
- $wpvivid_plugin->ajax_check_security();
2145
- $options['test_form'] =true;
2146
- $options['action'] ='wpvivid_upload_import_files';
2147
- $options['test_type'] = false;
2148
- $options['ext'] = 'zip';
2149
- $options['type'] = 'application/zip';
2150
- add_filter('upload_dir', array($this, 'upload_import_dir'));
2151
-
2152
- $status = wp_handle_upload($_FILES['async-upload'],$options);
2153
-
2154
- remove_filter('upload_dir', array($this, 'upload_import_dir'));
2155
- if (isset($status['error']))
2156
- {
2157
- echo json_encode(array('result'=>WPVIVID_FAILED, 'error' => $status['error']));
2158
- exit;
2159
- }
2160
-
2161
- $file_name=basename($_POST['name']);
2162
-
2163
- if (isset($_POST['chunks']) && isset($_POST['chunk']))
2164
- {
2165
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2166
- rename($status['file'],$path.$file_name.'_'.$_POST['chunk'].'.tmp');
2167
- $status['file'] = $path.$file_name.'_'.$_POST['chunk'].'.tmp';
2168
- if($_POST['chunk'] == $_POST['chunks']-1)
2169
- {
2170
- $file_handle = fopen($path.$file_name, 'wb');
2171
- if ($file_handle)
2172
- {
2173
- for ($i=0; $i<$_POST['chunks']; $i++)
2174
- {
2175
- $chunks_handle=fopen($path.$file_name.'_'.$i.'.tmp','rb');
2176
- if($chunks_handle)
2177
- {
2178
- while ($line = fread($chunks_handle, 1048576*2))
2179
- {
2180
- fwrite($file_handle, $line);
2181
- }
2182
- fclose($chunks_handle);
2183
- @unlink($path.$file_name.'_'.$i.'.tmp');
2184
- }
2185
- }
2186
- fclose($file_handle);
2187
- }
2188
- }
2189
- }
2190
- echo json_encode(array('result'=>WPVIVID_SUCCESS));
2191
- die();
2192
- }
2193
-
2194
- public function get_import_progress()
2195
- {
2196
- try
2197
- {
2198
- global $wpvivid_plugin;
2199
- $wpvivid_plugin->ajax_check_security();
2200
-
2201
- $tasks=WPvivid_Impoter_taskmanager::get_tasks();
2202
- foreach ($tasks as $task)
2203
- {
2204
- WPvivid_Impoter_taskmanager::get_task($task['id']);
2205
- $import_log = new WPvivid_import_data();
2206
- $ret['result'] = 'success';
2207
- $ret['status'] = WPvivid_Impoter_taskmanager::get_import_task_status($task['id']);
2208
- if ($ret['status'] === 'error')
2209
- {
2210
- WPvivid_Impoter_taskmanager::delete_task($task['id']);
2211
- }
2212
- if($ret['status'] === 'completed')
2213
- {
2214
- WPvivid_Impoter_taskmanager::delete_task($task['id']);
2215
- }
2216
- $ret['log'] = $import_log->get_log_content();
2217
- echo json_encode($ret);
2218
- die();
2219
- }
2220
- $ret['result'] = 'success';
2221
- $ret['status'] ='wait';
2222
- $ret['log']='';
2223
- echo json_encode($ret);
2224
- die();
2225
- }
2226
- catch (Exception $error) {
2227
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
2228
- error_log($message);
2229
- echo json_encode(array('result'=>'failed','error'=>$message));
2230
- die();
2231
- }
2232
- }
2233
-
2234
- public function upload_import_file_complete()
2235
- {
2236
- global $wpvivid_plugin;
2237
- $wpvivid_plugin->ajax_check_security();
2238
-
2239
- $ret['html']=false;
2240
- if(isset($_POST['files']))
2241
- {
2242
- $files =stripslashes($_POST['files']);
2243
- $files =json_decode($files,true);
2244
- if(is_null($files))
2245
- {
2246
- $ret['result']=WPVIVID_FAILED;
2247
- $ret['error']= 'Failed to decode files.';
2248
- echo json_encode($ret);
2249
- die();
2250
- }
2251
-
2252
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2253
-
2254
- //if(preg_match('/wpvivid-.*_.*_to_.*\.zip$/',$files[0]['name']))
2255
- //{
2256
- $data=array();
2257
- $check_result=true;
2258
- foreach ($files as $file)
2259
- {
2260
- $res=$this->check_is_import_file($path.$file['name']);
2261
- if($res['result'] =='success')
2262
- {
2263
- $add_file['file_name']=$file['name'];
2264
- $add_file['size']=filesize($path.$file['name']);
2265
- $add_file['export_type']=$res['export_type'];
2266
- $add_file['export_comment']=$res['export_comment'];
2267
- $add_file['posts_count']=$res['posts_count'];
2268
- $add_file['media_size']=size_format($res['media_size'],2);
2269
- $add_file['time']=$res['time'];
2270
- $data[]=$add_file;
2271
- }
2272
- else
2273
- {
2274
- $check_result=false;
2275
- }
2276
- }
2277
-
2278
- if($check_result === true)
2279
- {
2280
- $ret['result']=WPVIVID_SUCCESS;
2281
- $ret['data']=$data;
2282
- }
2283
- else
2284
- {
2285
- $ret['result']=WPVIVID_FAILED;
2286
- $ret['error']='Upload file failed.';
2287
- foreach ($files as $file)
2288
- {
2289
- $this->clean_tmp_files($path, $file['name']);
2290
- @unlink($path . $file['name']);
2291
- }
2292
- }
2293
- /*}
2294
- else
2295
- {
2296
- $ret['result']=WPVIVID_FAILED;
2297
- $ret['error']='The file is not created by WPvivid backup plugin.';
2298
- }*/
2299
- }
2300
- else {
2301
- $ret['result']=WPVIVID_FAILED;
2302
- $ret['error']='Failed to post file name.';
2303
- }
2304
- echo json_encode($ret);
2305
- die();
2306
- }
2307
-
2308
- public function check_is_import_file($file_name)
2309
- {
2310
- $ret=$this->get_backup_file_info($file_name);
2311
- if($ret['result'] === WPVIVID_SUCCESS)
2312
- {
2313
- $export_type_support_array = array('post', 'page');
2314
- if(isset($ret['json_data']['post_type']) && in_array($ret['json_data']['post_type'], $export_type_support_array))
2315
- {
2316
- $ret['export_type']=$ret['json_data']['post_type'];
2317
- $ret['export_comment']=isset($ret['json_data']['post_comment']) ? $ret['json_data']['post_comment'] : 'N/A';
2318
- $ret['export_time']=isset($ret['json_data']['create_time']) ? $ret['json_data']['create_time'] : '';
2319
- $ret['posts_count']=isset($ret['json_data']['posts_count']) ? $ret['json_data']['posts_count'] : 0;
2320
- $ret['media_size']=isset($ret['json_data']['media_size']) ? $ret['json_data']['media_size'] : 0;
2321
- $ret['time']=isset($ret['json_data']['create_time']) ? $ret['json_data']['create_time'] : time();
2322
- return $ret;
2323
- }
2324
- else{
2325
- $ret['result'] = WPVIVID_FAILED;
2326
- $ret['error'] = 'The backup is not an import file.';
2327
- return $ret;
2328
- }
2329
- }
2330
- else
2331
- {
2332
- return $ret;
2333
- }
2334
- }
2335
-
2336
- public function get_backup_file_info($file_name)
2337
- {
2338
- $zip=new WPvivid_ZipClass();
2339
- $ret=$zip->get_json_data($file_name, 'export');
2340
- if($ret['result'] === WPVIVID_SUCCESS)
2341
- {
2342
- $json=$ret['json_data'];
2343
- $json = json_decode($json, 1);
2344
- if (is_null($json))
2345
- {
2346
- return array('result'=>WPVIVID_FAILED,'error'=>'Failed to decode json');
2347
- } else {
2348
- return array('result'=>WPVIVID_SUCCESS,'json_data'=>$json);
2349
- }
2350
- }
2351
- else {
2352
- return $ret;
2353
- }
2354
- }
2355
-
2356
- function clean_tmp_files($path, $filename){
2357
- $handler=opendir($path);
2358
- if($handler===false)
2359
- return;
2360
- while(($file=readdir($handler))!==false) {
2361
- if (!is_dir($path.$file) && preg_match('/wpvivid-.*_.*_.*\.tmp$/', $file)) {
2362
- $iPos = strrpos($file, '_');
2363
- $file_temp = substr($file, 0, $iPos);
2364
- if($file_temp === $filename) {
2365
- @unlink($path.$file);
2366
- }
2367
- }
2368
- }
2369
- @closedir($handler);
2370
- }
2371
-
2372
- function wpvivid_write_upload_log($message, $id = ''){
2373
- if($id === ''){
2374
- $id=uniqid('wpvivid-');
2375
- }
2376
- global $wpvivid_plugin;
2377
- $wpvivid_plugin->upload_log=new WPvivid_Log();
2378
- $wpvivid_plugin->upload_log->CreateLogFile($id.'_upload','no_folder','upload');
2379
- $wpvivid_plugin->upload_log->WriteLogHander();
2380
- $wpvivid_plugin->upload_log->WriteLog($message,'notice');
2381
- }
2382
-
2383
- public function wpvivid_check_is_import_file_ex($file_name, &$backup_id){
2384
- if(preg_match('/wpvivid-.*_.*_to_.*\.zip$/', $file_name))
2385
- {
2386
- if(preg_match('/wpvivid-(.*?)_/', $file_name, $matches))
2387
- {
2388
- $id= $matches[0];
2389
- $id=substr($id,0,strlen($id)-1);
2390
- $backup_id=$id;
2391
- return true;
2392
- }
2393
- else
2394
- {
2395
- return false;
2396
- }
2397
- }
2398
- else
2399
- {
2400
- return false;
2401
- }
2402
- }
2403
-
2404
- public function calc_import_folder_size()
2405
- {
2406
- global $wpvivid_plugin;
2407
- $wpvivid_plugin->ajax_check_security();
2408
- $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2409
- $bytes_total = 0;
2410
- $path = realpath($path);
2411
- if($path!==false && $path!='' && file_exists($path))
2412
- {
2413
- foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object){
2414
- $bytes_total += $object->getSize();
2415
- }
2416
- }
2417
- $ret['result'] = WPVIVID_SUCCESS;
2418
- $ret['size'] = $wpvivid_plugin->formatBytes($bytes_total);
2419
- echo json_encode($ret);
2420
- die();
2421
- }
2422
-
2423
- public function clean_import_folder(){
2424
- global $wpvivid_plugin;
2425
- $wpvivid_plugin->ajax_check_security();
2426
- $path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2427
- if(is_dir($path))
2428
- {
2429
- $handler = opendir($path);
2430
- if($handler!==false)
2431
- {
2432
- while (($filename = readdir($handler)) !== false){
2433
- if ($filename != "." && $filename != ".."){
2434
- if (is_dir($path . $filename)) {
2435
- continue;
2436
- }
2437
- else{
2438
- $res=$this->check_is_import_file($path.$filename);
2439
- if($res['result'] =='success'){
2440
- @unlink($path.$filename);
2441
- }
2442
- }
2443
- }
2444
- }
2445
- }
2446
- }
2447
-
2448
- $data = array();
2449
- WPvivid_Setting::update_option('wpvivid_import_list_cache', $data);
2450
- $page=1;
2451
- $display_list=new WPvivid_Export_List();
2452
- $display_list->set_parent('wpvivid_import_list');
2453
- $display_list->set_list($data, $page);
2454
- $display_list->prepare_items();
2455
- ob_start();
2456
- $display_list->display();
2457
- $html = ob_get_clean();
2458
- $ret['html']=$html;
2459
- $ret['data']=$data;
2460
- $ret['result']=WPVIVID_SUCCESS;
2461
-
2462
- global $wpvivid_plugin;
2463
- $bytes_total = 0;
2464
- $path = realpath($path);
2465
- if($path!==false && $path!='' && file_exists($path))
2466
- {
2467
- foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object)
2468
- {
2469
- $bytes_total += $object->getSize();
2470
- }
2471
- }
2472
- $ret['size'] = $wpvivid_plugin->formatBytes($bytes_total);
2473
-
2474
- echo json_encode($ret);
2475
- die();
2476
- }
2477
-
2478
- public function wpvivid_scan_import_folder()
2479
- {
2480
- global $wpvivid_plugin;
2481
- $wpvivid_plugin->ajax_check_security();
2482
-
2483
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR;
2484
-
2485
- $data=array();
2486
- $count = 0;
2487
- if(is_dir($path))
2488
- {
2489
- $handler = opendir($path);
2490
- if($handler!==false)
2491
- {
2492
- while (($filename = readdir($handler)) !== false)
2493
- {
2494
- if ($filename != "." && $filename != "..")
2495
- {
2496
- $count++;
2497
-
2498
- if (is_dir($path . $filename))
2499
- {
2500
- continue;
2501
- }
2502
- else {
2503
-
2504
- $res=$this->check_is_import_file($path.$filename);
2505
- if($res['result'] =='success')
2506
- {
2507
- $add_file['file_name']=$filename;
2508
- $add_file['size']=filesize($path.$filename);
2509
- $add_file['export_type']=$res['export_type'];
2510
- $add_file['export_comment']=$res['export_comment'];
2511
- $add_file['posts_count']=$res['posts_count'];
2512
- $add_file['media_size']=size_format($res['media_size'],2);
2513
- $add_file['time']=$res['time'];
2514
- $data[$this->get_file_id($filename)]=$add_file;
2515
- }
2516
- }
2517
- }
2518
- }
2519
- if($handler)
2520
- @closedir($handler);
2521
- }
2522
- }
2523
- else{
2524
- global $wpvivid_plugin;
2525
- $wpvivid_plugin->wpvivid_log=new WPvivid_Log();
2526
- $id=uniqid('wpvivid-');
2527
- $wpvivid_plugin->wpvivid_log->CreateLogFile($id.'_scan','no_folder','scan');
2528
- $wpvivid_plugin->wpvivid_log->WriteLogHander();
2529
- $wpvivid_plugin->wpvivid_log->WriteLog('Failed to get local storage directory.','notice');
2530
- $ret['result']=WPVIVID_FAILED;
2531
- $ret['error']='Failed to get local storage directory.';
2532
- }
2533
- WPvivid_Setting::update_option('wpvivid_import_list_cache', $data);
2534
- $page=1;
2535
- $display_list=new WPvivid_Export_List();
2536
- $display_list->set_parent('wpvivid_import_list');
2537
- $display_list->set_list($data, $page);
2538
- $display_list->prepare_items();
2539
- ob_start();
2540
- $display_list->display();
2541
- $html = ob_get_clean();
2542
- $ret['html']=$html;
2543
- $ret['data']=$data;
2544
- $ret['result']=WPVIVID_SUCCESS;
2545
- echo json_encode($ret);
2546
- die();
2547
- }
2548
-
2549
- public function get_import_list_page(){
2550
- global $wpvivid_plugin;
2551
- $wpvivid_plugin->ajax_check_security();
2552
- if(!isset($_POST['page']))
2553
- {
2554
- die();
2555
- }
2556
- $page=$_POST['page'];
2557
-
2558
- $backups = get_option('wpvivid_import_list_cache');
2559
-
2560
- $display_list=new WPvivid_Export_List();
2561
- $display_list->set_parent('wpvivid_import_list');
2562
- $display_list->set_list($backups, $page);
2563
- $display_list->prepare_items();
2564
- ob_start();
2565
- $display_list->display();
2566
- $html = ob_get_clean();
2567
-
2568
- $ret['result']='success';
2569
- $ret['rows']=$html;
2570
- echo json_encode($ret);
2571
- die();
2572
- }
2573
-
2574
- public function deal_import_shutdown_error()
2575
- {
2576
- if($this->end_shutdown_function===false){
2577
- $last_error = error_get_last();
2578
- if (!empty($last_error) && !in_array($last_error['type'], array(E_NOTICE,E_WARNING,E_USER_NOTICE,E_USER_WARNING,E_DEPRECATED), true)) {
2579
- $error = $last_error;
2580
- } else {
2581
- $error = false;
2582
- }
2583
- $ret['result'] = 'failed';
2584
- if ($error === false) {
2585
- $ret['error'] = 'unknown Error';
2586
- } else {
2587
- $ret['error'] = 'type: '. $error['type'] . ', ' . $error['message'] . ' file:' . $error['file'] . ' line:' . $error['line'];
2588
- error_log($ret['error']);
2589
- }
2590
- $id = uniqid('wpvivid-');
2591
- $log_file_name = $id . '_import';
2592
- $log = new WPvivid_Log();
2593
- $log->CreateLogFile($log_file_name, 'no_folder', 'import');
2594
- $log->WriteLog($ret['error'], 'notice');
2595
- $log->CloseFile();
2596
- WPvivid_error_log::create_error_log($log->log_file);
2597
- echo json_encode($ret);
2598
- die();
2599
- }
2600
- }
2601
-
2602
- private function flush($task_id)
2603
- {
2604
- $ret['result']='success';
2605
- $ret['task_id']=$task_id;
2606
- $json=json_encode($ret);
2607
- if(!headers_sent())
2608
- {
2609
- header('Content-Length: '.strlen($json));
2610
- header('Connection: close');
2611
- header('Content-Encoding: none');
2612
- }
2613
-
2614
-
2615
- if (session_id())
2616
- session_write_close();
2617
- echo $json;
2618
-
2619
- if(function_exists('fastcgi_finish_request'))
2620
- {
2621
- fastcgi_finish_request();
2622
- }
2623
- else
2624
- {
2625
- ob_flush();
2626
- flush();
2627
- }
2628
- }
2629
-
2630
- public function start_import()
2631
- {
2632
- global $wpvivid_plugin;
2633
- $wpvivid_plugin->ajax_check_security();
2634
- $this->end_shutdown_function = false;
2635
- register_shutdown_function(array($this,'deal_import_shutdown_error'));
2636
- try
2637
- {
2638
- if (isset($_POST['file_name']) && !empty($_POST['file_name']) && is_string($_POST['file_name']))
2639
- {
2640
- $files=array();
2641
- $options=array();
2642
- $files[]=$_POST['file_name'];
2643
- $options['user']=0;
2644
- if(isset($_POST['user']))
2645
- {
2646
- $options['user']=$_POST['user'];
2647
- }
2648
- $options['update_exist']=0;
2649
- if(isset($_POST['update_exist']))
2650
- {
2651
- $options['update_exist']=$_POST['update_exist'];
2652
- }
2653
-
2654
- $task_id=$this->get_file_id($_POST['file_name']);
2655
- WPvivid_Impoter_taskmanager::new_task($task_id, $files,$options);
2656
- $import_log = new WPvivid_import_data();
2657
- $import_log->wpvivid_create_import_log();
2658
- $import_log->wpvivid_write_import_log('Start importing', 'notice');
2659
- $this->flush($task_id);
2660
- WPvivid_Impoter_taskmanager::update_import_task_status($task_id, 'running', true);
2661
- $importer = new WPvivid_media_importer();
2662
- $ret = $importer->import($task_id);
2663
- echo json_encode($ret);
2664
- }
2665
- }
2666
- catch (Exception $error)
2667
- {
2668
- $message = 'An error has occurred. class:'.get_class($error).';msg:'.$error->getMessage().';code:'.$error->getCode().';line:'.$error->getLine().';in_file:'.$error->getFile().';';
2669
- error_log($message);
2670
- WPvivid_Exporter_taskmanager::update_backup_task_status($task_id,false,'error',false,false,$message);
2671
- $wpvivid_plugin->wpvivid_log->WriteLog($message,'error');
2672
- $this->end_shutdown_function=true;
2673
- die();
2674
- }
2675
- $this->end_shutdown_function=true;
2676
- die();
2677
- }
2678
-
2679
- public function get_file_id($file_name)
2680
- {
2681
- if(preg_match('/wpvivid-.*_.*_to_.*\.zip$/',$file_name))
2682
- {
2683
- if(preg_match('/wpvivid-(.*?)_/',$file_name,$matches))
2684
- {
2685
- $id= $matches[0];
2686
- $id=substr($id,0,strlen($id)-1);
2687
- return $id;
2688
- }
2689
- else
2690
- {
2691
- $id=uniqid('wpvivid-');
2692
- return $id;
2693
- }
2694
- }
2695
- else
2696
- {
2697
- $id=uniqid('wpvivid-');
2698
- return $id;
2699
- }
2700
- }
2701
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-exporter.php DELETED
@@ -1,1985 +0,0 @@
1
- <?php
2
- /**
3
- * WPvivid addon: yes
4
- * Addon Name: wpvivid-backup-pro-all-in-one
5
- * Description: Pro
6
- * Version: 1.9.1
7
- */
8
-
9
- if ( ! class_exists( 'WP_List_Table' ) )
10
- {
11
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
12
- }
13
-
14
- class WPvivid_Post_List extends WP_List_Table
15
- {
16
- public $post_ids;
17
- public $page_num;
18
-
19
- public function __construct( $args = array() ) {
20
- global $post_type_object, $wpdb;
21
-
22
- parent::__construct(
23
- array(
24
- 'plural' => 'posts',
25
- 'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
26
- )
27
- );
28
-
29
- $post_type = $this->screen->post_type;
30
- $post_type_object = get_post_type_object( $post_type );
31
-
32
- $exclude_states = get_post_stati(
33
- array(
34
- 'show_in_admin_all_list' => false,
35
- )
36
- );
37
- $this->user_posts_count = intval(
38
- $wpdb->get_var(
39
- $wpdb->prepare(
40
- "
41
- SELECT COUNT( 1 )
42
- FROM $wpdb->posts
43
- WHERE post_type = %s
44
- AND post_status NOT IN ( '" . implode( "','", $exclude_states ) . "' )
45
- AND post_author = %d
46
- ",
47
- $post_type,
48
- get_current_user_id()
49
- )
50
- )
51
- );
52
-
53
- if ( $this->user_posts_count && ! current_user_can( $post_type_object->cap->edit_others_posts ) && empty( $_REQUEST['post_status'] ) && empty( $_REQUEST['all_posts'] ) && empty( $_REQUEST['author'] ) && empty( $_REQUEST['show_sticky'] ) ) {
54
- $_GET['author'] = get_current_user_id();
55
- }
56
-
57
- if ( 'post' === $post_type && $sticky_posts = get_option( 'sticky_posts' ) ) {
58
- $sticky_posts = implode( ', ', array_map( 'absint', (array) $sticky_posts ) );
59
- $this->sticky_posts_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( 1 ) FROM $wpdb->posts WHERE post_type = %s AND post_status NOT IN ('trash', 'auto-draft') AND ID IN ($sticky_posts)", $post_type ) );
60
- }
61
- }
62
-
63
- public function print_column_headers( $with_id = true ) {
64
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
65
-
66
- if ( ! empty( $columns['cb'] ) )
67
- {
68
- $checked='';
69
-
70
- static $cb_counter = 1;
71
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
72
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" '.$checked.'/>';
73
- $cb_counter++;
74
- }
75
-
76
- foreach ( $columns as $column_key => $column_display_name ) {
77
- $class = array( 'manage-column', "column-$column_key" );
78
-
79
- if ( in_array( $column_key, $hidden ) ) {
80
- $class[] = 'hidden';
81
- }
82
-
83
- if ( 'cb' === $column_key ) {
84
- $class[] = 'check-column';
85
- } elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) ) {
86
- $class[] = 'num';
87
- }
88
-
89
- if ( $column_key === $primary ) {
90
- $class[] = 'column-primary';
91
- }
92
-
93
- $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
94
- $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
95
- $id = $with_id ? "id='$column_key'" : '';
96
-
97
- if ( ! empty( $class ) ) {
98
- $class = "class='" . join( ' ', $class ) . "'";
99
- }
100
-
101
- echo "<$tag $scope $id $class>$column_display_name</$tag>";
102
- }
103
- }
104
-
105
- public function get_columns()
106
- {
107
- $post_type = $this->screen->post_type;
108
-
109
- $posts_columns = array();
110
-
111
- $posts_columns['cb'] = '<input type="checkbox"/>';
112
- /* translators: manage posts column name */
113
- $posts_columns['wpvivid_id'] = 'ID';
114
-
115
- $posts_columns['title'] = _x( 'Title', 'column name' );
116
-
117
- if ( post_type_supports( $post_type, 'author' ) ) {
118
- $posts_columns['author'] = __( 'Author' );
119
- }
120
-
121
- $taxonomies = get_object_taxonomies( $post_type, 'objects' );
122
- $taxonomies = wp_filter_object_list( $taxonomies, array( 'show_admin_column' => true ), 'and', 'name' );
123
-
124
- /**
125
- * Filters the taxonomy columns in the Posts list table.
126
- *
127
- * The dynamic portion of the hook name, `$post_type`, refers to the post
128
- * type slug.
129
- *
130
- * @since 3.5.0
131
- *
132
- * @param string[] $taxonomies Array of taxonomy names to show columns for.
133
- * @param string $post_type The post type.
134
- */
135
- $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type );
136
- $taxonomies = array_filter( $taxonomies, 'taxonomy_exists' );
137
-
138
- foreach ( $taxonomies as $taxonomy ) {
139
- if ( 'category' === $taxonomy ) {
140
- $column_key = 'categories';
141
- } elseif ( 'post_tag' === $taxonomy ) {
142
- $column_key = 'tags';
143
- } else {
144
- $column_key = 'taxonomy-' . $taxonomy;
145
- }
146
-
147
- $posts_columns[ $column_key ] = get_taxonomy( $taxonomy )->labels->name;
148
- }
149
-
150
- $posts_columns['comments'] =__( 'Comments' );
151
-
152
- $posts_columns['date'] = __( 'Date' );
153
-
154
- return $posts_columns;
155
- }
156
-
157
- function set_post_ids($post_ids,$page_num=1)
158
- {
159
- $this->post_ids=$post_ids;
160
- $this->page_num=$page_num;
161
- }
162
-
163
- public function get_pagenum()
164
- {
165
- if($this->page_num=='first')
166
- {
167
- $this->page_num=1;
168
- }
169
- else if($this->page_num=='last')
170
- {
171
- $this->page_num=$this->_pagination_args['total_pages'];
172
- }
173
- $pagenum = $this->page_num ? $this->page_num : 0;
174
-
175
- if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
176
- {
177
- $pagenum = $this->_pagination_args['total_pages'];
178
- }
179
-
180
- return max( 1, $pagenum );
181
- }
182
-
183
- function prepare_items()
184
- {
185
- $columns = $this->get_columns();
186
- $hidden = array();
187
- $sortable = array();
188
- $this->_column_headers = array($columns, $hidden, $sortable);
189
-
190
- $total_items =sizeof($this->post_ids);
191
-
192
- $this->set_pagination_args(
193
- array(
194
- 'total_items' => $total_items,
195
- 'per_page' => 30,
196
- )
197
- );
198
- }
199
-
200
- public function has_items()
201
- {
202
- return !empty($this->post_ids);
203
- }
204
-
205
- public function column_cb( $post )
206
- {
207
- $checked='';
208
- if($post->checked)
209
- {
210
- $checked='checked';
211
- }
212
- ?>
213
- <input id="cb-select-<?php echo $post->ID; ?>" type="checkbox" name="post[]" value="<?php echo $post->ID; ?>" <?php echo $checked ?>/>
214
- <?php
215
- }
216
-
217
- /**
218
- * @since 4.3.0
219
- *
220
- * @param WP_Post $post
221
- * @param string $classes
222
- * @param string $data
223
- * @param string $primary
224
- */
225
- protected function _column_title( $post, $classes, $data, $primary ) {
226
- echo '<td class="' . $classes . ' page-title" ', $data, '>';
227
- echo $this->column_title( $post );
228
- echo '</td>';
229
- }
230
-
231
- public function column_wpvivid_id( $post )
232
- {
233
- echo '<span>'.$post->ID.'</span>';
234
- }
235
- /**
236
- * Handles the title column output.
237
- *
238
- * @since 4.3.0
239
- *
240
- * @global string $mode List table view mode.
241
- *
242
- * @param WP_Post $post The current WP_Post object.
243
- */
244
- public function column_title( $post ) {
245
- echo '<strong>';
246
- $title = $post->post_title;
247
- echo $title;
248
- echo "</strong>\n";
249
- }
250
-
251
- /**
252
- * Handles the post date column output.
253
- *
254
- * @since 4.3.0
255
- *
256
- * @global string $mode List table view mode.
257
- *
258
- * @param WP_Post $post The current WP_Post object.
259
- */
260
- public function column_date( $post )
261
- {
262
- global $mode;
263
-
264
- if ( '0000-00-00 00:00:00' === $post->post_date ) {
265
- $t_time = $h_time = __( 'Unpublished', 'wpvivid-backuprestore' );
266
- $time_diff = 0;
267
- } else {
268
- $t_time = get_the_time( 'Y/m/d g:i:s a' );
269
- $m_time = $post->post_date;
270
- $time = get_post_time( 'G', true, $post );
271
-
272
- $time_diff = time() - $time;
273
-
274
- if ( $time_diff > 0 && $time_diff < DAY_IN_SECONDS ) {
275
- $h_time = sprintf( __( '%s ago', 'wpvivid-backuprestore' ), human_time_diff( $time ) );
276
- } else {
277
- $h_time = mysql2date( 'Y/m/d', $m_time );
278
- }
279
- }
280
-
281
- if ( 'publish' === $post->post_status ) {
282
- $status = __( 'Published', 'wpvivid-backuprestore' );
283
- } elseif ( 'future' === $post->post_status ) {
284
- if ( $time_diff > 0 ) {
285
- $status = '<strong class="error-message">' . __( 'Missed schedule', 'wpvivid-backuprestore' ) . '</strong>';
286
- } else {
287
- $status = __( 'Scheduled', 'wpvivid-backuprestore' );
288
- }
289
- } else {
290
- $status = __( 'Last Modified', 'wpvivid-backuprestore' );
291
- }
292
-
293
- /**
294
- * Filters the status text of the post.
295
- *
296
- * @since 4.8.0
297
- *
298
- * @param string $status The status text.
299
- * @param WP_Post $post Post object.
300
- * @param string $column_name The column name.
301
- * @param string $mode The list display mode ('excerpt' or 'list').
302
- */
303
- $status = apply_filters( 'post_date_column_status', $status, $post, 'date', $mode );
304
-
305
- if ( $status ) {
306
- echo $status . '<br />';
307
- }
308
-
309
- if ( 'excerpt' === $mode ) {
310
- /**
311
- * Filters the published time of the post.
312
- *
313
- * If `$mode` equals 'excerpt', the published time and date are both displayed.
314
- * If `$mode` equals 'list' (default), the publish date is displayed, with the
315
- * time and date together available as an abbreviation definition.
316
- *
317
- * @since 2.5.1
318
- *
319
- * @param string $t_time The published time.
320
- * @param WP_Post $post Post object.
321
- * @param string $column_name The column name.
322
- * @param string $mode The list display mode ('excerpt' or 'list').
323
- */
324
- echo apply_filters( 'post_date_column_time', $t_time, $post, 'date', $mode );
325
- } else {
326
-
327
- /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
328
- echo '<abbr title="' . $t_time . '">' . apply_filters( 'post_date_column_time', $h_time, $post, 'date', $mode ) . '</abbr>';
329
- }
330
- }
331
-
332
- /**
333
- * Handles the comments column output.
334
- *
335
- * @since 4.3.0
336
- *
337
- * @param WP_Post $post The current WP_Post object.
338
- */
339
- public function column_comments( $post ) {
340
- ?>
341
- <div class="post-com-count-wrapper">
342
- <?php
343
- echo '<span style="text-align:center">'.get_comments_number($post->ID).'</span>'
344
- ?>
345
- </div>
346
- <?php
347
- }
348
-
349
- /**
350
- * Handles the post author column output.
351
- *
352
- * @since 4.3.0
353
- *
354
- * @param WP_Post $post The current WP_Post object.
355
- */
356
- public function column_author( $post ) {
357
- $user_data = get_userdata($post->post_author );
358
-
359
- echo '<span>'.$user_data->display_name.'</span>';
360
- }
361
-
362
- /**
363
- * Handles the default column output.
364
- *
365
- * @since 4.3.0
366
- *
367
- * @param WP_Post $post The current WP_Post object.
368
- * @param string $column_name The current column name.
369
- */
370
- public function column_default( $post, $column_name ) {
371
- if ( 'categories' === $column_name )
372
- {
373
- $taxonomy = 'category';
374
- } elseif ( 'tags' === $column_name )
375
- {
376
- $taxonomy = 'post_tag';
377
- } elseif ( 0 === strpos( $column_name, 'taxonomy-' ) )
378
- {
379
- $taxonomy = substr( $column_name, 9 );
380
- } else {
381
- $taxonomy = false;
382
- }
383
- if ( $taxonomy ) {
384
- $taxonomy_object = get_taxonomy( $taxonomy );
385
- $terms = get_the_terms( $post->ID, $taxonomy );
386
- if ( is_array( $terms ) ) {
387
- $out = array();
388
- foreach ( $terms as $t ) {
389
- $posts_in_term_qv = array();
390
- if ( 'post' != $post->post_type ) {
391
- $posts_in_term_qv['post_type'] = $post->post_type;
392
- }
393
- if ( $taxonomy_object->query_var ) {
394
- $posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
395
- } else {
396
- $posts_in_term_qv['taxonomy'] = $taxonomy;
397
- $posts_in_term_qv['term'] = $t->slug;
398
- }
399
-
400
- $label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );
401
-
402
- $out[] = $label;
403
- }
404
- /* translators: used between list items, there is a space after the comma */
405
- echo join( ', ', $out );
406
- } else {
407
- echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
408
- }
409
- return;
410
- }
411
-
412
- if ( is_post_type_hierarchical( $post->post_type ) ) {
413
-
414
- /**
415
- * Fires in each custom column on the Posts list table.
416
- *
417
- * This hook only fires if the current post type is hierarchical,
418
- * such as pages.
419
- *
420
- * @since 2.5.0
421
- *
422
- * @param string $column_name The name of the column to display.
423
- * @param int $post_id The current post ID.
424
- */
425
- do_action( 'manage_pages_custom_column', $column_name, $post->ID );
426
- } else {
427
-
428
- /**
429
- * Fires in each custom column in the Posts list table.
430
- *
431
- * This hook only fires if the current post type is non-hierarchical,
432
- * such as posts.
433
- *
434
- * @since 1.5.0
435
- *
436
- * @param string $column_name The name of the column to display.
437
- * @param int $post_id The current post ID.
438
- */
439
- do_action( 'manage_posts_custom_column', $column_name, $post->ID );
440
- }
441
-
442
- /**
443
- * Fires for each custom column of a specific post type in the Posts list table.
444
- *
445
- * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
446
- *
447
- * @since 3.1.0
448
- *
449
- * @param string $column_name The name of the column to display.
450
- * @param int $post_id The current post ID.
451
- */
452
- do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
453
- }
454
-
455
- public function display_rows()
456
- {
457
- $this->_display_rows( $this->post_ids );
458
- }
459
-
460
- private function _display_rows($post_ids)
461
- {
462
- $page_post_ids=$post_ids;
463
- $page=$this->get_pagenum();
464
- $count=0;
465
- while ( $count<$page )
466
- {
467
- $page_post_ids = array_splice( $post_ids, 0, 30);
468
- $count++;
469
- }
470
- foreach ( $page_post_ids as $post_id)
471
- {
472
- $this->single_row($post_id);
473
- }
474
- }
475
-
476
- public function single_row($post_id)
477
- {
478
- $post = get_post($post_id['id']);
479
- $post->checked=$post_id['checked'];
480
- $classes = 'iedit author-' . ( get_current_user_id() == $post->post_author ? 'self' : 'other' );
481
-
482
- ?>
483
- <tr id="post-<?php echo $post->ID; ?>" class="<?php echo implode( ' ', get_post_class( $classes, $post->ID ) ); ?>">
484
- <?php $this->single_row_columns( $post ); ?>
485
- </tr>
486
- <?php
487
- }
488
-
489
- /**
490
- * Display the pagination.
491
- *
492
- * @since 3.1.0
493
- *
494
- * @param string $which
495
- */
496
- protected function pagination( $which ) {
497
- if ( empty( $this->_pagination_args ) ) {
498
- return;
499
- }
500
-
501
- $total_items = $this->_pagination_args['total_items'];
502
- $total_pages = $this->_pagination_args['total_pages'];
503
- $infinite_scroll = false;
504
- if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
505
- $infinite_scroll = $this->_pagination_args['infinite_scroll'];
506
- }
507
-
508
- if ( 'top' === $which && $total_pages > 1 ) {
509
- $this->screen->render_screen_reader_content( 'heading_pagination' );
510
- }
511
-
512
- $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
513
-
514
- $current = $this->get_pagenum();
515
- $removable_query_args = wp_removable_query_args();
516
-
517
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
518
-
519
- $current_url = remove_query_arg( $removable_query_args, $current_url );
520
-
521
- $page_links = array();
522
-
523
- $total_pages_before = '<span class="paging-input">';
524
- $total_pages_after = '</span></span>';
525
-
526
- $disable_first = $disable_last = $disable_prev = $disable_next = false;
527
-
528
- if ( $current == 1 ) {
529
- $disable_first = true;
530
- $disable_prev = true;
531
- }
532
- if ( $current == 2 ) {
533
- $disable_first = true;
534
- }
535
- if ( $current == $total_pages ) {
536
- $disable_last = true;
537
- $disable_next = true;
538
- }
539
- if ( $current == $total_pages - 1 ) {
540
- $disable_last = true;
541
- }
542
-
543
- if ( $disable_first ) {
544
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
545
- } else {
546
- $page_links[] = sprintf(
547
- "<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
548
- __( 'First page' ),
549
- '&laquo;'
550
- );
551
- }
552
-
553
- if ( $disable_prev ) {
554
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
555
- } else {
556
- $page_links[] = sprintf(
557
- "<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
558
- $current,
559
- __( 'Previous page' ),
560
- '&lsaquo;'
561
- );
562
- }
563
-
564
- if ( 'bottom' === $which ) {
565
- $html_current_page = $current;
566
- $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
567
- } else {
568
- $html_current_page = sprintf(
569
- "%s<input class='current-page' id='current-page-selector-export' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
570
- '<label for="current-page-selector-export" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
571
- $current,
572
- strlen( $total_pages )
573
- );
574
- }
575
- $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
576
- $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
577
-
578
- if ( $disable_next ) {
579
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
580
- } else {
581
- $page_links[] = sprintf(
582
- "<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
583
- $current,
584
- __( 'Next page' ),
585
- '&rsaquo;'
586
- );
587
- }
588
-
589
- if ( $disable_last ) {
590
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
591
- } else {
592
- $page_links[] = sprintf(
593
- "<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
594
- __( 'Last page' ),
595
- '&raquo;'
596
- );
597
- }
598
-
599
- $pagination_links_class = 'pagination-links';
600
- if ( ! empty( $infinite_scroll ) ) {
601
- $pagination_links_class .= ' hide-if-js';
602
- }
603
- $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
604
-
605
- if ( $total_pages ) {
606
- $page_class = $total_pages < 2 ? ' one-page' : '';
607
- } else {
608
- $page_class = ' no-pages';
609
- }
610
- $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
611
-
612
- echo $this->_pagination;
613
- }
614
-
615
- /**
616
- * Generate the table navigation above or below the table
617
- *
618
- * @since 3.1.0
619
- * @param string $which
620
- */
621
- protected function display_tablenav( $which ) {
622
- $css_type = '';
623
- if ( 'top' === $which ) {
624
- wp_nonce_field( 'bulk-' . $this->_args['plural'] );
625
- $css_type = 'margin: 0 0 10px 0';
626
- }
627
- else if( 'bottom' === $which ) {
628
- $css_type = 'margin: 10px 0 0 0';
629
- }
630
- ?>
631
- <div class="tablenav <?php echo esc_attr( $which ); ?>" style="<?php esc_attr_e($css_type); ?>">
632
- <div class="alignleft actions bulkactions">
633
- <?php echo '<input class="button-primary" id="wpvivid-post-research-submit" type="submit" name="post" value="Reset Filters">'; ?>
634
- </div>
635
- <?php
636
- $this->extra_tablenav( $which );
637
- $this->pagination( $which );
638
- ?>
639
-
640
- <br class="clear" />
641
- </div>
642
- <?php
643
- }
644
- }
645
-
646
- class WPvivid_Exporter_taskmanager
647
- {
648
- public static function get_task($task_id)
649
- {
650
- $default = array();
651
- $tasks = get_option('wpvivid_exporter_task_list', $default);
652
-
653
- if(array_key_exists ($task_id,$tasks))
654
- {
655
- return $tasks[$task_id];
656
- }
657
- else
658
- {
659
- return false;
660
- }
661
- }
662
-
663
- public static function update_task($task_id,$task)
664
- {
665
- $default = array();
666
- $options = get_option('wpvivid_exporter_task_list', $default);
667
- $options[$task_id]=$task;
668
- WPvivid_Setting::update_option('wpvivid_exporter_task_list',$options);
669
- }
670
-
671
- public static function get_tasks()
672
- {
673
- $default = array();
674
- return $options = get_option('wpvivid_exporter_task_list', $default);
675
- }
676
-
677
- public static function get_backup_task_status($task_id)
678
- {
679
- $tasks=self::get_tasks();
680
- if(array_key_exists ($task_id,$tasks))
681
- {
682
- $task = $tasks[$task_id];
683
- return $task['status'];
684
- }
685
- else
686
- {
687
- return false;
688
- }
689
- }
690
-
691
- public static function delete_task($task_id)
692
- {
693
- $options = get_option('wpvivid_exporter_task_list', array());
694
- unset($options[$task_id]);
695
- WPvivid_Setting::update_option('wpvivid_exporter_task_list',$options);
696
- }
697
-
698
- public static function update_backup_task_status($task_id,$reset_start_time=false,$status='',$reset_timeout=false,$resume_count=false,$error='')
699
- {
700
- $tasks=self::get_tasks();
701
- if(array_key_exists ($task_id,$tasks))
702
- {
703
- $task = $tasks[$task_id];
704
- $task['status']['run_time']=time();
705
- if($reset_start_time)
706
- $task['status']['start_time']=time();
707
- if(!empty($status))
708
- {
709
- $task['status']['str']=$status;
710
- }
711
- if($reset_timeout)
712
- $task['status']['timeout']=time();
713
- if($resume_count!==false)
714
- {
715
- $task['status']['resume_count']=$resume_count;
716
- }
717
-
718
- if(!empty($error))
719
- {
720
- $task['status']['error']=$error;
721
- }
722
- self::update_task($task_id,$task);
723
- return $task;
724
- }
725
- else
726
- {
727
- return false;
728
- }
729
- }
730
-
731
- public static function get_task_options($task_id,$option_names)
732
- {
733
- $tasks=self::get_tasks();
734
- if(array_key_exists ($task_id,$tasks))
735
- {
736
- $task=$tasks[$task_id];
737
-
738
- if(is_array($option_names))
739
- {
740
- $options=array();
741
- foreach ($option_names as $name)
742
- {
743
- $options[$name]=$task['options'][$name];
744
- }
745
- return $options;
746
- }
747
- else
748
- {
749
- return $task['options'][$option_names];
750
- }
751
- }
752
- else
753
- {
754
- return false;
755
- }
756
- }
757
-
758
- public static function is_tasks_running()
759
- {
760
- $tasks=self::get_tasks();
761
- foreach ($tasks as $task)
762
- {
763
- if ($task['status']['str']=='running'||$task['status']['str']=='no_responds')
764
- {
765
- return true;
766
- }
767
- }
768
- return false;
769
- }
770
-
771
- public static function update_main_task_progress($task_id,$job_name,$progress,$finished,$job_data=array())
772
- {
773
- $task=self::get_task($task_id);
774
- if($task!==false)
775
- {
776
- $task['status']['run_time']=time();
777
- $task['status']['str']='running';
778
- $task['data']['doing']=$job_name;
779
- $task['data'][$job_name]['finished']=$finished;
780
- $task['data'][$job_name]['progress']=$progress;
781
- $task['data'][$job_name]['job_data']=$job_data;
782
- self::update_task($task_id,$task);
783
- }
784
- }
785
-
786
- public static function get_backup_tasks_progress($task_id)
787
- {
788
- $tasks=self::get_tasks();
789
- if(array_key_exists ($task_id,$tasks))
790
- {
791
- $task = $tasks[$task_id];
792
- $current_time=date("Y-m-d H:i:s");
793
- $create_time=date("Y-m-d H:i:s",$task['status']['start_time']);
794
- $time_diff=strtotime($current_time)-strtotime($create_time);
795
- $running_time='';
796
- if(date("G",$time_diff) > 0){
797
- $running_time .= date("G",$time_diff).'hour';
798
- }
799
- if(intval(date("i",$time_diff)) > 0){
800
- $running_time .= intval(date("i",$time_diff)).'min';
801
- }
802
- if(intval(date("s",$time_diff)) > 0){
803
- $running_time .= intval(date("s",$time_diff)).'second';
804
- }
805
-
806
- $ret['type']=$task['data']['doing'];
807
- $ret['progress']=$task['data'][$ret['type']]['progress'];
808
- $ret['doing']=$task['data'][$ret['type']]['doing'];
809
- if(isset($task['data'][$ret['type']]['sub_job'][$ret['doing']]['progress']))
810
- $ret['descript']=__($task['data'][$ret['type']]['sub_job'][$ret['doing']]['progress'], 'wpvivid-backuprestore');
811
- else
812
- $ret['descript']='';
813
- if(isset($task['data'][$ret['type']]['sub_job'][$ret['doing']]['upload_data']))
814
- $ret['upload_data']=$task['data'][$ret['type']]['sub_job'][$ret['doing']]['upload_data'];
815
- $task['data'][$ret['type']]['sub_job'][$ret['doing']]['upload_data']=false;
816
- $ret['running_time']=$running_time;
817
- $ret['running_stamp']=$time_diff;
818
-
819
- return $ret;
820
- }
821
- else
822
- {
823
- return false;
824
- }
825
- }
826
- }
827
-
828
- class WPvivid_Exporter_task
829
- {
830
- private $task;
831
-
832
- public function __construct($task_id=false,$task=false)
833
- {
834
- if($task_id!==false)
835
- {
836
- $this->task=WPvivid_Exporter_taskmanager::get_task($task_id);
837
- }
838
-
839
- if($task!==false)
840
- {
841
- $this->task=$task;
842
- }
843
- }
844
-
845
- public function get_id()
846
- {
847
- return $this->task['id'];
848
- }
849
-
850
- public function new_backup_task($options)
851
- {
852
- $id=uniqid('wpvivid-');
853
- $this->task=false;
854
- $this->task['id']=$id;
855
-
856
- $this->task['status']['start_time']=time();
857
- $this->task['status']['run_time']=time();
858
- $this->task['status']['timeout']=time();
859
- $this->task['status']['str']='ready';
860
- $this->task['status']['resume_count']=0;
861
-
862
- if(isset($options['remote'])) {
863
- if($options['remote']=='1') {
864
- $this->task['options']['remote_options'] = isset($options['remote_options']) ? $options['remote_options'] : WPvivid_Setting::get_remote_options();
865
- }
866
- else {
867
- $this->task['options']['remote_options']=false;
868
- }
869
- }
870
- else {
871
- $this->task['options']['remote_options']=false;
872
- }
873
-
874
- $this->task['options']['remote_options'] = apply_filters('wpvivid_set_remote_options', $this->task['options']['remote_options'],$options);
875
-
876
- if(isset($options['local'])) {
877
- $this->task['options']['save_local'] = $options['local']=='1' ? 1 : 0;
878
- }
879
- else {
880
- $this->task['options']['save_local']=1;
881
- }
882
-
883
- $this->task['options']['post_comment'] = $options['post_comment'];
884
-
885
- if(empty($backup_prefix))
886
- $this->task['options']['file_prefix'] = $this->task['id'] . '_' . date('Y-m-d-H-i', $this->task['status']['start_time']);
887
- else
888
- $this->task['options']['file_prefix'] = $backup_prefix . '_' . $this->task['id'] . '_' . date('Y-m-d-H-i', $this->task['status']['start_time']);
889
-
890
- $this->task['options']['log_file_name']=$id.'_export';
891
- $log=new WPvivid_Log();
892
- $log->CreateLogFile($this->task['options']['log_file_name'],'no_folder','export');
893
- $this->task['options']['backup_options']['prefix']=$this->task['options']['file_prefix'];
894
- $this->task['options']['backup_options']['compress']=WPvivid_Setting::get_option('wpvivid_compress_setting');
895
- $this->task['options']['backup_options']['dir']=WPvivid_Setting::get_backupdir();
896
- $this->task['options']['backup_options']['post_ids']=$options['post_ids'];
897
- $this->task['options']['backup_options']['post_type']=$options['post_type'];
898
- $export_data['json_info']['post_type']=$options['post_type'];
899
- //$export_data['json_info']['post_ids']=$options['post_ids'];
900
- $export_data['json_info']['post_comment']=$options['post_comment'];
901
- $this->task['options']['backup_options']['backup'][$options['post_type']]=$export_data;
902
- $this->task['data']['doing']='export';
903
- $this->task['data']['export']['doing']='';
904
- $this->task['data']['export']['finished']=0;
905
- $this->task['data']['export']['progress']=0;
906
- if(sizeof($options['post_ids'])>50) {
907
- $this->task['data']['export']['pre_progress']=(50/sizeof($options['post_ids']))*100;
908
- }
909
- else {
910
- $this->task['data']['export']['pre_progress']=100;
911
- }
912
- $this->task['data']['export']['job_data']=array();
913
- $this->task['data']['export']['sub_job']=array();
914
- $this->task['data']['export']['export_info']['post_count']=sizeof($options['post_ids']);
915
- $this->task['data']['upload']['doing']='';
916
- $this->task['data']['upload']['finished']=0;
917
- $this->task['data']['upload']['progress']=0;
918
- $this->task['data']['upload']['job_data']=array();
919
- $this->task['data']['upload']['sub_job']=array();
920
- WPvivid_Exporter_taskmanager::update_task($id,$this->task);
921
- $ret['result']='success';
922
- $ret['task_id']=$this->task['id'];
923
- $log->CloseFile();
924
- return $ret;
925
- }
926
-
927
- private function parse_url_all($url)
928
- {
929
- $parse = parse_url($url);
930
- $path=str_replace('/','_',$parse['path']);
931
- return $parse['host'].$path;
932
- }
933
-
934
- public function update_sub_task_progress($key,$finished,$progress)
935
- {
936
- $this->task=WPvivid_Exporter_taskmanager::get_task($this->get_id());
937
- $this->task['status']['run_time']=time();
938
- $this->task['status']['str']='running';
939
- $this->task['data']['doing']='export';
940
- $sub_job_name=$key;
941
- $this->task['data']['export']['doing']=$key;
942
- $this->task['data']['export']['sub_job'][$sub_job_name]['finished']=$finished;
943
- $this->task['data']['export']['sub_job'][$sub_job_name]['progress']=$progress;
944
- if(!isset( $this->task['data']['export']['sub_job'][$sub_job_name]['job_data']))
945
- {
946
- $this->task['data']['export']['sub_job'][$sub_job_name]['job_data']=array();
947
- }
948
- WPvivid_Exporter_taskmanager::update_task($this->get_id(),$this->task);
949
- }
950
-
951
- public function get_next_posts()
952
- {
953
- asort($this->task['options']['backup_options']['post_ids']);
954
- WPvivid_Exporter_taskmanager::update_task($this->get_id(),$this->task);
955
- $post_ids=$this->task['options']['backup_options']['post_ids'];
956
- if(empty($post_ids))
957
- {
958
- return false;
959
- }
960
- /*if(sizeof($post_ids)>50)
961
- {
962
- $next_post_ids = array_splice( $post_ids, 0, 50 );
963
- }
964
- else
965
- {
966
- $next_post_ids=$post_ids;
967
- }*/
968
- $next_post_ids=$post_ids;
969
- $ret=$this->get_post_contain_attachment_ids($next_post_ids);
970
-
971
- $next_post_ids = array_splice( $this->task['options']['backup_options']['post_ids'], 0, $ret['post_count'] );
972
- $ret['next_post_ids']=$next_post_ids;
973
-
974
- $post_type = $this->task['options']['backup_options']['post_type'];
975
- $ret['json_info'] = $this->task['options']['backup_options']['backup'][$post_type]['json_info'];
976
-
977
- $first=reset($next_post_ids);
978
- $last=end($next_post_ids);
979
-
980
- $post_comment = !empty($this->task['options']['post_comment']) ? $this->task['options']['post_comment'].'_' : '';
981
- $ret['file_name']=$post_comment.self::get_id().'_'.date('Y-m-d-H-i', $this->task['status']['start_time']);
982
- $ret['export_type']=$this->task['options']['backup_options']['post_type'];
983
- return $ret;
984
- }
985
-
986
- public function update_finished_posts($finished_posts)
987
- {
988
- $this->task=WPvivid_Exporter_taskmanager::get_task( $this->get_id());
989
- array_splice( $this->task['options']['backup_options']['post_ids'], 0, $finished_posts['post_count'] );
990
- $this->task['data']['export']['progress']=$this->task['data']['export']['progress']+$this->task['data']['export']['pre_progress'];
991
- if($this->task['data']['export']['progress']>100)
992
- {
993
- $this->task['data']['export']['progress']=100;
994
- }
995
- WPvivid_Exporter_taskmanager::update_task($this->get_id(),$this->task);
996
- }
997
-
998
- public function update_export_files($file_data)
999
- {
1000
- $this->task=WPvivid_Exporter_taskmanager::get_task( $this->get_id());
1001
-
1002
- $this->task['data']['file_data'][]=$file_data;
1003
-
1004
- $this->task['data']['export']['export_info']['file_name']=$file_data['file_name'];
1005
- $this->task['data']['export']['export_info']['size']=$file_data['size'];
1006
-
1007
- WPvivid_Exporter_taskmanager::update_task($this->get_id(),$this->task);
1008
- }
1009
-
1010
- public function get_export_files()
1011
- {
1012
- $this->task=WPvivid_Exporter_taskmanager::get_task( $this->get_id());
1013
-
1014
- if(isset($this->task['data']['file_data']))
1015
- {
1016
- $file_data=$this->task['data']['file_data'];
1017
- return $file_data;
1018
- }
1019
- else
1020
- {
1021
- return array();
1022
- }
1023
- }
1024
-
1025
- public function get_post_contain_attachment_ids($post_ids)
1026
- {
1027
- $max_size=1024*1024*100;
1028
- $current_size=0;
1029
- $count=0;
1030
- $sum_attachment_ids=array();
1031
- $attachment_added_ids=array();
1032
- $files=array();
1033
- foreach ($post_ids as $id)
1034
- {
1035
- $count++;
1036
-
1037
- $attachment_ids=array();
1038
- $post = get_post( $id );
1039
- if (preg_match_all( '/<img [^>]+>/', $post->post_content, $matches ) )
1040
- {
1041
- foreach( $matches[0] as $image )
1042
- {
1043
- if ( preg_match( '/wp-image-([0-9]+)/i', $image, $class_id ) && ( $attachment_id = absint( $class_id[1] ) ) )
1044
- {
1045
- if(!in_array($attachment_id,$attachment_added_ids))
1046
- {
1047
- if(!is_null(get_post($attachment_id)))
1048
- {
1049
- $attachment_ids[] = $attachment_id;
1050
- $attachment_added_ids[]=$attachment_id;
1051
- }
1052
- else
1053
- {
1054
- $ret_attachment=$this->get_image_from_post_content($image);
1055
- $current_size+=$ret_attachment['size'];
1056
- $files=array_merge($files,$ret_attachment['files']);
1057
- }
1058
- }
1059
- }
1060
- else
1061
- {
1062
- $ret_attachment=$this->get_image_from_post_content($image);
1063
- $current_size+=$ret_attachment['size'];
1064
- $files=array_merge($files,$ret_attachment['files']);
1065
- }
1066
- }
1067
- }
1068
-
1069
- $_elementor_meta=get_post_meta($id,'_elementor_data',true);
1070
- if($_elementor_meta!=false)
1071
- {
1072
- if ( is_string( $_elementor_meta ) && ! empty( $_elementor_meta ) )
1073
- {
1074
- $_elementor_meta = json_decode( $_elementor_meta, true );
1075
- }
1076
- if ( empty( $_elementor_meta ) )
1077
- {
1078
- $_elementor_meta = array();
1079
- }
1080
- $elements_data=$_elementor_meta;
1081
- foreach ( $elements_data as $element_data )
1082
- {
1083
- $element_image=$this->get_element_image($element_data,$attachment_added_ids);
1084
- $attachment_ids=array_merge($attachment_ids,$element_image);
1085
- }
1086
- }
1087
-
1088
- //_thumbnail_id
1089
- $_thumbnail_id=get_post_meta($id,'_thumbnail_id',true);
1090
- if($_thumbnail_id!=false)
1091
- {
1092
- if(!in_array($_thumbnail_id,$attachment_added_ids))
1093
- {
1094
- if(!is_null(get_post($_thumbnail_id)))
1095
- {
1096
- $attachment_ids[] = $_thumbnail_id;
1097
- $attachment_added_ids[]=$_thumbnail_id;
1098
- }
1099
- }
1100
- }
1101
-
1102
- $sum_attachment_ids=array_merge($sum_attachment_ids,$attachment_ids);
1103
-
1104
- foreach ($attachment_ids as $attachment_id)
1105
- {
1106
- $ret_attachment=$this->get_attachment_size($attachment_id);
1107
- $current_size+=$ret_attachment['size'];
1108
- $files=array_merge($files,$ret_attachment['files']);
1109
- }
1110
-
1111
- if($current_size>$max_size)
1112
- {
1113
- break;
1114
- }
1115
- }
1116
-
1117
- $ret['attachment_ids']=$sum_attachment_ids;
1118
- $ret['post_count']=$count;
1119
- $ret['files']=$files;
1120
- return $ret;
1121
- }
1122
-
1123
- public function get_image_from_post_content($image)
1124
- {
1125
- $ret['size']=0;
1126
- $ret['files']=array();
1127
-
1128
- if(class_exists('DOMDocument'))
1129
- {
1130
- $doc = new DOMDocument();
1131
- $doc->loadHTML($image);
1132
- $xpath = new DOMXPath($doc);
1133
- $src = $xpath->evaluate("string(//img/@src)");
1134
- }
1135
- else
1136
- {
1137
- preg_match('/src="([^"]+)/i',$image, $src);
1138
- $src= str_ireplace( 'src="', '', $src[0]);
1139
- }
1140
-
1141
- $src=str_replace('https://','',$src);
1142
- $src=str_replace('http://','',$src);
1143
-
1144
- $upload=wp_upload_dir();
1145
-
1146
- $upload['baseurl']=str_replace('https://','',$upload['baseurl']);
1147
- $upload['baseurl']=str_replace('http://','',$upload['baseurl']);
1148
-
1149
-
1150
- $path=str_replace($upload['baseurl'],$upload['basedir'],$src);
1151
- if(file_exists($path))
1152
- {
1153
- $ret['size']+=filesize($path);
1154
- $ret['files'][]=$path;
1155
- }
1156
-
1157
- return $ret;
1158
- }
1159
-
1160
- public function get_attachment_size($attachment_id)
1161
- {
1162
- $files=array();
1163
- global $wpdb;
1164
-
1165
- $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $attachment_id ) );
1166
-
1167
- foreach ( $postmeta as $meta )
1168
- {
1169
- $upload_dir = wp_upload_dir();
1170
-
1171
- if ( $upload_dir['error'] !== false )
1172
- {
1173
- continue;
1174
- }
1175
-
1176
- $dir=$upload_dir['basedir'];
1177
- if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
1178
- continue;
1179
- }
1180
- if($meta->meta_key=='_wp_attached_file')
1181
- {
1182
- $bfound=false;
1183
- $name=$dir.DIRECTORY_SEPARATOR.$meta->meta_value;
1184
- if(!in_array($name,$files)&&file_exists($name))
1185
- {
1186
- $files[]=$name;
1187
- $bfound=true;
1188
- }
1189
- if($bfound)
1190
- {
1191
- $attach_meta = wp_get_attachment_metadata( $attachment_id );
1192
- if($attach_meta!=false)
1193
- {
1194
- if(isset($attach_meta['sizes']))
1195
- {
1196
- foreach ($attach_meta['sizes'] as $key=>$value)
1197
- {
1198
- $data=image_get_intermediate_size($attachment_id,$key);
1199
- $data['path']=ltrim($data['path'], './');
1200
- $name=$dir.DIRECTORY_SEPARATOR.$data['path'];
1201
- if(!in_array($name,$files)&&file_exists($name))
1202
- {
1203
- $files[]=$dir.DIRECTORY_SEPARATOR.$data['path'];
1204
- }
1205
- }
1206
- }
1207
- else
1208
- {
1209
- global $wpvivid_plugin;
1210
- $wpvivid_plugin->wpvivid_log->WriteLog('attach_meta size not found id:'.$attachment_id,'notice');
1211
- }
1212
- }
1213
- }
1214
- }
1215
-
1216
- }
1217
-
1218
- $size=0;
1219
-
1220
- if(!empty($files))
1221
- {
1222
- foreach ($files as $file)
1223
- {
1224
- $size+=filesize($file);
1225
- }
1226
- }
1227
-
1228
- $ret['size']=$size;
1229
- $ret['files']=$files;
1230
-
1231
- return $ret;
1232
- }
1233
-
1234
- public function get_element_image($element_data,&$attachment_added_ids)
1235
- {
1236
- $element_image=array();
1237
-
1238
- if(!empty($element_data['settings']))
1239
- {
1240
- $settings=$element_data['settings'];
1241
- if(isset($settings['image']))
1242
- {
1243
- if(!in_array($settings['image']['id'],$attachment_added_ids))
1244
- {
1245
- $element_image[]=$settings['image']['id'];
1246
- $attachment_added_ids[]=$settings['image']['id'];
1247
- }
1248
-
1249
- }
1250
- }
1251
-
1252
- if(!empty($element_data['elements']))
1253
- {
1254
- foreach ($element_data['elements'] as $element)
1255
- {
1256
- $temp=$this->get_element_image($element,$attachment_added_ids);
1257
- $element_image=array_merge($element_image,$temp);
1258
- }
1259
- }
1260
-
1261
- return $element_image;
1262
- }
1263
-
1264
- public function add_new_export()
1265
- {
1266
- $files=$this->get_export_files();
1267
-
1268
- $backup_data=array();
1269
- $status=WPvivid_Exporter_taskmanager::get_backup_task_status($this->task['id']);
1270
- $backup_data['create_time']=$status['start_time'];
1271
-
1272
- global $wpvivid_plugin;
1273
- $backup_data['log']=$wpvivid_plugin->wpvivid_log->log_file;
1274
- $backup_data['export']=$files;
1275
- $backup_data['id']=$this->task['id'];
1276
- $list = get_option('wpvivid_export_list',array());
1277
- $list[$this->task['id']]=$backup_data;
1278
- WPvivid_Setting::update_option('wpvivid_export_list',$list);
1279
- }
1280
- }
1281
-
1282
- class WPvivid_Exporter_Item{
1283
- private $config;
1284
-
1285
- public function __construct($options){
1286
- $this->config=$options;
1287
- }
1288
-
1289
- public function get_download_export_files(){
1290
- $files = isset($this->config['export']) ? $this->config['export'] : array();
1291
- if(empty($files)){
1292
- $ret['result'] = WPVIVID_FAILED;
1293
- $ret['error']='Failed to get export files.';
1294
- }
1295
- else{
1296
- $ret['result'] = WPVIVID_SUCCESS;
1297
- $ret['files']=$files;
1298
- }
1299
- return $ret;
1300
- }
1301
-
1302
- public function get_download_progress($backup_id, $files){
1303
- $this->config['local']['path'] = 'wpvividbackups';
1304
- foreach ($files as $file){
1305
- $need_download = false;
1306
- $file_path = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file;
1307
- $download_url = content_url().DIRECTORY_SEPARATOR.$this->config['local']['path'].DIRECTORY_SEPARATOR.$file;
1308
- if(file_exists($file_path)){
1309
- //need calc file size, then compare is need download
1310
-
1311
- }
1312
- else{
1313
- $need_download = true;
1314
- }
1315
-
1316
- if($need_download){
1317
-
1318
- }
1319
- else{
1320
- $ret['result'] = WPVIVID_SUCCESS;
1321
- $ret['files'][$file]['status'] = 'completed';
1322
- $ret['files'][$file]['download_path'] = $file_path;
1323
- $ret['files'][$file]['download_url'] = $download_url;
1324
- ob_start();
1325
- ?>
1326
- <div style="float:left;margin:10px 10px 10px 0;text-align:center; width:180px;">
1327
- <span>Part01</span><br>
1328
- <span><a class="wpvivid-download-export" id="trtr" name="<?php echo $file; ?>" style="cursor: pointer;">Download</a></span><br>
1329
- <div style="width:100%;height:5px; background-color:#dcdcdc;">
1330
- <div style="background-color:#0085ba; float:left;width:100%;height:5px;"></div>
1331
- </div>
1332
- <span>size: </span><span>1K</span>
1333
- </div>
1334
- <?php
1335
- $html = ob_get_clean();
1336
- $ret['html']=$html;
1337
- }
1338
- }
1339
- return $ret;
1340
- }
1341
- }
1342
-
1343
- class WPvivid_Exporter
1344
- {
1345
- public $task;
1346
- //public $config;
1347
-
1348
- public function __construct($task_id=false,$task=false)
1349
- {
1350
- if($task_id!==false)
1351
- {
1352
- $this->task=new WPvivid_Exporter_task($task_id);
1353
- }
1354
- else if($task!==false)
1355
- {
1356
- $this->task=new WPvivid_Exporter_task(false,$task);
1357
- }
1358
- else
1359
- {
1360
- $this->task=new WPvivid_Exporter_task();
1361
- }
1362
- }
1363
-
1364
- public function init_options($task_id)
1365
- {
1366
- $this->task=new WPvivid_Exporter_task($task_id);
1367
- }
1368
-
1369
- public function export($task_id)
1370
- {
1371
- $this->init_options($task_id);
1372
-
1373
- global $wpvivid_plugin;
1374
-
1375
- $next=$this->task->get_next_posts();
1376
-
1377
- $ret['result']='success';
1378
- WPvivid_Exporter_taskmanager::update_main_task_progress($task_id, 'export', 5, 0);
1379
- while($next!==false)
1380
- {
1381
- @set_time_limit(900);
1382
- $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to export post '.$next['file_name'],'notice');
1383
-
1384
- $this->task->update_sub_task_progress($next['file_name'],0,'Start export file '.$next['file_name']);
1385
- $ret=$this->export_post_to_xml($next['next_post_ids'], $next['attachment_ids'],$next['file_name'],$next['export_type']);
1386
- $wpvivid_plugin->wpvivid_log->WriteLog('Finished to export post '.$next['file_name'],'notice');
1387
- if($ret['result']=='success')
1388
- {
1389
- $wpvivid_plugin->wpvivid_log->WriteLog('Prepare to zip file '.$next['file_name'],'notice');
1390
- $next['json_info']['posts_count']=sizeof($next['next_post_ids']);
1391
- $ret=$this->zip_media_files($ret['xml_file_name'],$next['files'],$next['file_name'],$next['export_type'],$next['json_info']);
1392
- $wpvivid_plugin->wpvivid_log->WriteLog('Finished to zip file '.$next['file_name'],'notice');
1393
- if($ret['result']!='success')
1394
- {
1395
- $wpvivid_plugin->wpvivid_log->WriteLog('Failed to zip post '.$next['file_name'].' '.json_encode($ret),'notice');
1396
- return $ret;
1397
- }
1398
- $this->task->update_sub_task_progress($next['file_name'],1,'Backing up '.$next['file_name'].' finished');
1399
- $this->task->update_finished_posts($next);
1400
- $this->task->update_export_files($ret['file_data']);
1401
- }
1402
- else
1403
- {
1404
- $wpvivid_plugin->wpvivid_log->WriteLog('Failed to export post '.$next['file_name'].' '.json_encode($ret),'notice');
1405
- return $ret;
1406
- }
1407
- $next=$this->task->get_next_posts();
1408
- }
1409
- WPvivid_Exporter_taskmanager::update_main_task_progress($task_id, 'export', 100, 1);
1410
-
1411
- return $ret;
1412
- }
1413
-
1414
- public function export_post_to_xml($posts_ids,$attachment_ids,$file_name,$export_type)
1415
- {
1416
- $all_ids=array_merge($posts_ids,$attachment_ids);
1417
- //$xml_file_name=$file_name.'.xml';
1418
- $xml_file_name=$file_name.'_'.$export_type.'.xml';
1419
- //$files=array();
1420
- $export_folder = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
1421
- if(!file_exists($export_folder)) {
1422
- @mkdir($export_folder);
1423
- }
1424
- $path=$export_folder.DIRECTORY_SEPARATOR.$xml_file_name;
1425
- $ret['xml_file_name']=$path;
1426
- if(file_exists($path))
1427
- {
1428
- @unlink($path);
1429
- }
1430
-
1431
- $this->write_header_to_file($path);
1432
-
1433
- $this->write_authors_list_to_file($path,$all_ids);
1434
-
1435
- $this->write_cat_to_file($path,$posts_ids);
1436
-
1437
- global $wp_query,$wpdb;
1438
-
1439
- // Fake being in the loop.
1440
- $wp_query->in_the_loop = true;
1441
-
1442
- $task_id = $this->task->get_id();
1443
- while ( $next_posts = array_splice( $posts_ids, 0, 20 ) )
1444
- {
1445
- $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
1446
- $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
1447
- // Begin Loop.
1448
- foreach ( $posts as $post )
1449
- {
1450
- $this->write_post_to_file($path,$post);
1451
- }
1452
- }
1453
- WPvivid_Exporter_taskmanager::update_main_task_progress($task_id, 'export', 25, 0);
1454
- while ( $next_posts = array_splice( $attachment_ids, 0, 20 ) )
1455
- {
1456
- $where = 'WHERE ID IN (' . join( ',', $next_posts ) . ')';
1457
- $posts = $wpdb->get_results( "SELECT * FROM {$wpdb->posts} $where" );
1458
- // Begin Loop.
1459
- foreach ( $posts as $post )
1460
- {
1461
- $this->write_media_post_to_file($path,$post);
1462
- //$post_files=$this->write_media_post_to_file($path,$post);
1463
- //$files=array_merge($post_files,$files);
1464
- }
1465
- }
1466
- WPvivid_Exporter_taskmanager::update_main_task_progress($task_id, 'export', 50, 0);
1467
- $this->write_footer_to_file($path);
1468
-
1469
- //$ret['files']=$files;
1470
- $ret['result']='success';
1471
- return $ret;
1472
- }
1473
-
1474
- private function zip_media_files($xml_file,$files,$file_name,$export_type,$json_info=false)
1475
- {
1476
- if (!class_exists('PclZip'))
1477
- include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
1478
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR.$file_name.'_export_'.$export_type.'.zip';
1479
- $options['compress']['no_compress']=1;
1480
- $options['compress']['use_temp_file']=1;
1481
- $options['compress']['use_temp_size']=16;
1482
- $options['root_flag']=WPVIVID_BACKUP_ROOT_WP_CONTENT;
1483
-
1484
- if(file_exists($path))
1485
- @unlink($path);
1486
- $archive = new PclZip($path);
1487
-
1488
- if($json_info!==false) {
1489
- $temp_path = dirname($path).DIRECTORY_SEPARATOR.'wpvivid_export_package_info.json';
1490
- if(file_exists($temp_path)) {
1491
- @unlink($temp_path);
1492
- }
1493
- $json_info['create_time']=time();
1494
- $json_info['xml_file']=basename($xml_file);
1495
- $json_info['media_size']=0;
1496
- foreach ($files as $file)
1497
- {
1498
- $json_info['media_size']+=@filesize($file);
1499
- }
1500
- file_put_contents($temp_path,print_r(json_encode($json_info),true));
1501
- $archive -> add($temp_path,PCLZIP_OPT_REMOVE_PATH,dirname($temp_path));
1502
- @unlink($temp_path);
1503
- }
1504
-
1505
- $ret =$archive -> add($xml_file,PCLZIP_OPT_REMOVE_PATH,dirname($xml_file));
1506
- @unlink($xml_file);
1507
- if(!$ret)
1508
- {
1509
- return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true));
1510
- }
1511
-
1512
- if(!empty($files)) {
1513
- $ret = $archive->add($files, PCLZIP_OPT_REMOVE_PATH, WP_CONTENT_DIR, PCLZIP_OPT_TEMP_FILE_THRESHOLD, 16);
1514
- }
1515
-
1516
- if(!$ret)
1517
- {
1518
- return array('result'=>WPVIVID_FAILED,'error'=>$archive->errorInfo(true));
1519
- }
1520
-
1521
- $file_data = array();
1522
- $file_data['file_name'] = basename($path);
1523
- $file_data['size'] = filesize($path);
1524
-
1525
- return array('result'=>WPVIVID_SUCCESS,'file_data'=>$file_data);
1526
- }
1527
-
1528
- public function write_header_to_file($file)
1529
- {
1530
- $wxr_version=1.2;
1531
-
1532
- $line='<?xml version="1.0" encoding="' . get_bloginfo( 'charset' ) . "\" ?>\n";
1533
- $line.='<!-- This is a WordPress eXtended RSS file generated by WordPress as an export of your site. -->
1534
- <!-- It contains information about your site\'s posts, pages, comments, categories, and other content. -->
1535
- <!-- You may use this file to transfer that content from one site to another. -->
1536
- <!-- This file is not intended to serve as a complete backup of your site. -->
1537
-
1538
- <!-- To import this information into a WordPress site follow these steps: -->
1539
- <!-- 1. Log in to that site as an administrator. -->
1540
- <!-- 2. Go to Tools: Import in the WordPress admin panel. -->
1541
- <!-- 3. Install the "WordPress" importer from the list. -->
1542
- <!-- 4. Activate & Run Importer. -->
1543
- <!-- 5. Upload this file using the form provided on that page. -->
1544
- <!-- 6. You will first be asked to map the authors in this export file to users -->
1545
- <!-- on the site. For each author, you may choose to map to an -->
1546
- <!-- existing user on the site or to create a new user. -->
1547
- <!-- 7. WordPress will then import each of the posts, pages, comments, categories, etc. -->
1548
- <!-- contained in this file into your site. -->';
1549
- $line.=apply_filters( 'the_generator', get_the_generator( 'export' ), 'export' ) . "\n";
1550
- $line.='
1551
- <rss version="2.0"
1552
- xmlns:excerpt="http://wordpress.org/export/'.$wxr_version.'/excerpt/"
1553
- xmlns:content="http://purl.org/rss/1.0/modules/content/"
1554
- xmlns:wfw="http://wellformedweb.org/CommentAPI/"
1555
- xmlns:dc="http://purl.org/dc/elements/1.1/"
1556
- xmlns:wp="http://wordpress.org/export/'.$wxr_version.'/"
1557
- > ';
1558
- $line.='
1559
- <channel>
1560
- <title>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'name' ), 'name' ).'</title>
1561
- <link>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'url' ), 'url' ).'</link>
1562
- <description>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'description' ), 'description' ).'</description>
1563
- <pubDate>'.date( 'D, d M Y H:i:s +0000' ).'</pubDate>
1564
- <language>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'language' ), 'language' ).'</language>
1565
- <wp:wxr_version>'.$wxr_version.'</wp:wxr_version>
1566
- <wp:base_site_url>'.$this->wxr_site_url().'</wp:base_site_url>
1567
- <wp:base_blog_url>'.apply_filters( 'bloginfo_rss', get_bloginfo_rss( 'url' ), 'url' ).'</wp:base_blog_url>
1568
- ';
1569
- file_put_contents($file,$line);
1570
- }
1571
-
1572
- public function write_authors_list_to_file($file,$post_ids)
1573
- {
1574
- $line=$this->wxr_authors_list( $post_ids );
1575
- file_put_contents($file,$line,FILE_APPEND);
1576
- }
1577
-
1578
- public function write_footer_to_file($file)
1579
- {
1580
- $line='
1581
- </channel>
1582
- </rss> ';
1583
- file_put_contents($file,$line,FILE_APPEND);
1584
- }
1585
-
1586
- public function write_post_header_to_file($file,$post)
1587
- {
1588
- $is_sticky = is_sticky( $post->ID ) ? 1 : 0;
1589
- $post = get_post( $post );
1590
-
1591
- $guid = isset( $post->guid ) ? get_the_guid( $post ) : '';
1592
- $id = isset( $post->ID ) ? $post->ID : 0;
1593
-
1594
- $guid= apply_filters( 'the_guid', $guid, $id );
1595
- $item_header_line='
1596
- <item>
1597
- <title>
1598
- '.apply_filters( 'the_title_rss', $post->post_title ).'
1599
- </title>
1600
- <link>'.esc_url( apply_filters( 'the_permalink_rss', get_permalink($post->ID) ) ).'</link>
1601
- <pubDate>'.mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true,$post ), false ).'</pubDate>
1602
- <dc:creator>'.$this->wxr_cdata( get_the_author_meta( 'login' ) ).'</dc:creator>
1603
- <guid isPermaLink="false">'.$guid.'</guid>
1604
- <description></description>
1605
- <content:encoded>'.$this->wxr_cdata( apply_filters( 'the_content_export', $post->post_content ) ).' </content:encoded>
1606
- <excerpt:encoded>'.$this->wxr_cdata( apply_filters( 'the_excerpt_export', $post->post_excerpt ) ).'</excerpt:encoded>
1607
- <wp:post_id>'.intval( $post->ID ).'</wp:post_id>
1608
- <wp:post_date>'.$this->wxr_cdata( $post->post_date ).'</wp:post_date>
1609
- <wp:post_date_gmt>'.$this->wxr_cdata( $post->post_date_gmt ).'</wp:post_date_gmt>
1610
- <wp:comment_status>'.$this->wxr_cdata( $post->comment_status ).'</wp:comment_status>
1611
- <wp:ping_status>'.$this->wxr_cdata( $post->ping_status ).'</wp:ping_status>
1612
- <wp:post_name>'.$this->wxr_cdata( $post->post_name ).'</wp:post_name>
1613
- <wp:status>'.$this->wxr_cdata( $post->post_status ).'</wp:status>
1614
- <wp:post_parent>'.intval( $post->post_parent ).'</wp:post_parent>
1615
- <wp:menu_order>'.intval( $post->menu_order ).'</wp:menu_order>
1616
- <wp:post_type>'.$this->wxr_cdata( $post->post_type ).'</wp:post_type>
1617
- <wp:post_password>'.$this->wxr_cdata( $post->post_password ).'</wp:post_password>
1618
- <wp:is_sticky>'.intval( $is_sticky ).'</wp:is_sticky>
1619
- ';
1620
- if ( $post->post_type == 'attachment' )
1621
- $item_header_line.='<wp:attachment_url>'.$this->wxr_cdata( wp_get_attachment_url( $post->ID ) ).'</wp:attachment_url>';
1622
- file_put_contents($file,$item_header_line,FILE_APPEND);
1623
-
1624
- $line=$this->wxr_post_taxonomy($post);
1625
- file_put_contents($file,$line,FILE_APPEND);
1626
- }
1627
-
1628
- public function write_media_post_to_file($file,$post)
1629
- {
1630
- global $wpdb;
1631
-
1632
- $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
1633
- $post_meta_line='';
1634
- $added_meta_key=array();
1635
- foreach ( $postmeta as $meta )
1636
- {
1637
- if(in_array($meta->meta_key,$added_meta_key))
1638
- continue;
1639
- $added_meta_key[]=$meta->meta_key;
1640
-
1641
- $post_meta_line.='
1642
- <wp:postmeta>
1643
- <wp:meta_key>'.$this->wxr_cdata( $meta->meta_key ).'</wp:meta_key>
1644
- <wp:meta_value>'.$this->wxr_cdata( $meta->meta_value ).'</wp:meta_value>
1645
- </wp:postmeta>';
1646
- }
1647
-
1648
- $this->write_post_header_to_file($file,$post);
1649
-
1650
- file_put_contents($file,$post_meta_line,FILE_APPEND);
1651
-
1652
- $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
1653
- $comments = array_map( 'get_comment', $_comments );
1654
- $line='';
1655
- foreach ( $comments as $c )
1656
- {
1657
- $line.='
1658
- <wp:comment>
1659
- <wp:comment_id>'.intval( $c->comment_ID ).'</wp:comment_id>
1660
- <wp:comment_author>'.$this->wxr_cdata( $c->comment_author ).'</wp:comment_author>
1661
- <wp:comment_author_email>'.$this->wxr_cdata( $c->comment_author_email ).'</wp:comment_author_email>
1662
- <wp:comment_author_url>'.esc_url_raw( $c->comment_author_url ).'</wp:comment_author_url>
1663
- <wp:comment_author_IP>'.$this->wxr_cdata( $c->comment_author_IP ).'</wp:comment_author_IP>
1664
- <wp:comment_date>'.$this->wxr_cdata( $c->comment_date ).'</wp:comment_date>
1665
- <wp:comment_date_gmt>'.$this->wxr_cdata( $c->comment_date_gmt ).'</wp:comment_date_gmt>
1666
- <wp:comment_content>'.$this->wxr_cdata( $c->comment_content ).'</wp:comment_content>
1667
- <wp:comment_approved>'.$this->wxr_cdata( $c->comment_approved ).'</wp:comment_approved>
1668
- <wp:comment_type>'.$this->wxr_cdata( $c->comment_type ).'</wp:comment_type>
1669
- <wp:comment_parent>'.intval( $c->comment_parent ).'</wp:comment_parent>
1670
- <wp:comment_user_id>'.intval( $c->user_id ).'</wp:comment_user_id>';
1671
- $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
1672
- foreach ( $c_meta as $meta )
1673
- {
1674
- if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) )
1675
- {
1676
- continue;
1677
- }
1678
- $line.='
1679
- <wp:commentmeta>
1680
- <wp:meta_key>'.$this->wxr_cdata( $meta->meta_key ).'</wp:meta_key>
1681
- <wp:meta_value>'.$this->wxr_cdata( $meta->meta_value ).'</wp:meta_value>
1682
- </wp:commentmeta>';
1683
- }
1684
- $line.='
1685
- </wp:comment>';
1686
- }
1687
- file_put_contents($file,$line,FILE_APPEND);
1688
- $line='
1689
- </item>';
1690
- file_put_contents($file,$line,FILE_APPEND);
1691
- }
1692
-
1693
- public function write_post_to_file($file,$post)
1694
- {
1695
- global $wpdb;
1696
-
1697
- setup_postdata( $post );
1698
-
1699
- $postmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d", $post->ID ) );
1700
- $post_meta_line='';
1701
-
1702
- $added_meta_key=array();
1703
- foreach ( $postmeta as $meta )
1704
- {
1705
- //if ( apply_filters( 'wxr_export_skip_postmeta', false, $meta->meta_key, $meta ) ) {
1706
- // continue;
1707
- //}
1708
- if(in_array($meta->meta_key,$added_meta_key))
1709
- continue;
1710
- $added_meta_key[]=$meta->meta_key;
1711
- $post_meta_line.='
1712
- <wp:postmeta>
1713
- <wp:meta_key>'.$this->wxr_cdata( $meta->meta_key ).'</wp:meta_key>
1714
- <wp:meta_value>'.$this->wxr_cdata( $meta->meta_value ).'</wp:meta_value>
1715
- </wp:postmeta>';
1716
- }
1717
-
1718
- $this->write_post_header_to_file($file,$post);
1719
-
1720
- file_put_contents($file,$post_meta_line,FILE_APPEND);
1721
-
1722
- $_comments = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved <> 'spam'", $post->ID ) );
1723
- $comments = array_map( 'get_comment', $_comments );
1724
- $line='';
1725
- foreach ( $comments as $c )
1726
- {
1727
- $line.='
1728
- <wp:comment>
1729
- <wp:comment_id>'.intval( $c->comment_ID ).'</wp:comment_id>
1730
- <wp:comment_author>'.$this->wxr_cdata( $c->comment_author ).'</wp:comment_author>
1731
- <wp:comment_author_email>'.$this->wxr_cdata( $c->comment_author_email ).'</wp:comment_author_email>
1732
- <wp:comment_author_url>'.esc_url_raw( $c->comment_author_url ).'</wp:comment_author_url>
1733
- <wp:comment_author_IP>'.$this->wxr_cdata( $c->comment_author_IP ).'</wp:comment_author_IP>
1734
- <wp:comment_date>'.$this->wxr_cdata( $c->comment_date ).'</wp:comment_date>
1735
- <wp:comment_date_gmt>'.$this->wxr_cdata( $c->comment_date_gmt ).'</wp:comment_date_gmt>
1736
- <wp:comment_content>'.$this->wxr_cdata( $c->comment_content ).'</wp:comment_content>
1737
- <wp:comment_approved>'.$this->wxr_cdata( $c->comment_approved ).'</wp:comment_approved>
1738
- <wp:comment_type>'.$this->wxr_cdata( $c->comment_type ).'</wp:comment_type>
1739
- <wp:comment_parent>'.intval( $c->comment_parent ).'</wp:comment_parent>
1740
- <wp:comment_user_id>'.intval( $c->user_id ).'</wp:comment_user_id>';
1741
- $c_meta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->commentmeta WHERE comment_id = %d", $c->comment_ID ) );
1742
- foreach ( $c_meta as $meta )
1743
- {
1744
- if ( apply_filters( 'wxr_export_skip_commentmeta', false, $meta->meta_key, $meta ) )
1745
- {
1746
- continue;
1747
- }
1748
- $line.='
1749
- <wp:commentmeta>
1750
- <wp:meta_key>'.$this->wxr_cdata( $meta->meta_key ).'</wp:meta_key>
1751
- <wp:meta_value>'.$this->wxr_cdata( $meta->meta_value ).'</wp:meta_value>
1752
- </wp:commentmeta>';
1753
- }
1754
- $line.='
1755
- </wp:comment>';
1756
- }
1757
- file_put_contents($file,$line,FILE_APPEND);
1758
- $line='
1759
- </item>';
1760
- file_put_contents($file,$line,FILE_APPEND);
1761
- return true;
1762
- }
1763
-
1764
- public function write_cat_to_file($file,$post_ids)
1765
- {
1766
- $cats = $tags = $terms = array();
1767
-
1768
- $categories = (array) get_categories( array( 'object_ids' => $post_ids ) );
1769
- $tags = (array) get_tags( array( 'object_ids' => $post_ids ) );
1770
-
1771
- $custom_taxonomies = get_taxonomies( array( '_builtin' => false ) );
1772
- $custom_terms = (array) get_terms( $custom_taxonomies,array( 'object_ids' => $post_ids ) );
1773
-
1774
- // Put categories in order with no child going before its parent.
1775
- while ( $cat = array_shift( $categories ) ) {
1776
- if ( $cat->parent == 0 || isset( $cats[ $cat->parent ] ) ) {
1777
- $cats[ $cat->term_id ] = $cat;
1778
- } else {
1779
- $categories[] = $cat;
1780
- }
1781
- }
1782
-
1783
- // Put terms in order with no child going before its parent.
1784
- while ( $t = array_shift( $custom_terms ) ) {
1785
- if ( $t->parent == 0 || isset( $terms[ $t->parent ] ) ) {
1786
- $terms[ $t->term_id ] = $t;
1787
- } else {
1788
- $custom_terms[] = $t;
1789
- }
1790
- }
1791
-
1792
- unset( $categories, $custom_taxonomies, $custom_terms );
1793
-
1794
- $line='';
1795
- foreach ($cats as $c)
1796
- {
1797
- $line.='<wp:category>
1798
- <wp:term_id>'.intval( $c->term_id ).'</wp:term_id>
1799
- <wp:category_nicename>'.$this->wxr_cdata( $c->slug ).'</wp:category_nicename>
1800
- <wp:category_parent>'.$this->wxr_cdata( $c->parent ? $cats[ $c->parent ]->slug : '' ).'</wp:category_parent>
1801
- '.$this->wxr_cat_name( $c ).'
1802
- '.$this->wxr_category_description( $c ).'
1803
- '.$this->wxr_term_meta( $c ).'
1804
- </wp:category>';
1805
- }
1806
- file_put_contents($file,$line,FILE_APPEND);
1807
- $line='';
1808
- foreach ( $tags as $t )
1809
- {
1810
- $line.='<wp:tag>
1811
- <wp:term_id>'.intval( $t->term_id ).'</wp:term_id>
1812
- <wp:tag_slug>'.$this->wxr_cdata( $t->slug ).'</wp:tag_slug>
1813
- '.$this->wxr_tag_name( $t ).'
1814
- '.$this->wxr_tag_description( $t ).'
1815
- '.$this->wxr_term_meta( $t ).'
1816
- </wp:tag>';
1817
- }
1818
- file_put_contents($file,$line,FILE_APPEND);
1819
-
1820
- $line='';
1821
-
1822
- foreach ( $terms as $t)
1823
- {
1824
- $line.='<wp:term>
1825
- <wp:term_id>'.$this->wxr_cdata( $t->term_id ).'</wp:term_id>
1826
- <wp:term_taxonomy>'.$this->wxr_cdata( $t->taxonomy ).'</wp:term_taxonomy>
1827
- <wp:term_slug>'.$this->wxr_cdata( $t->slug ).'</wp:term_slug>
1828
- <wp:term_parent>'.$this->wxr_cdata( $t->parent ? $terms[ $t->parent ]->slug : '' ).'</wp:term_parent>
1829
- '.$this->wxr_term_name( $t ).'
1830
- '.$this->wxr_term_description( $t ).'
1831
- '.$this->wxr_term_meta( $t ).'
1832
- </wp:term>';
1833
- }
1834
- }
1835
-
1836
- private function wxr_cat_name( $category )
1837
- {
1838
- if ( empty( $category->name ) )
1839
- {
1840
- return '';
1841
- }
1842
-
1843
- return '<wp:cat_name>' . $this->wxr_cdata( $category->name ) . "</wp:cat_name>";
1844
- }
1845
-
1846
- private function wxr_category_description( $category ) {
1847
- if ( empty( $category->description ) ) {
1848
- return '<wp:category_description></wp:category_description>\n';
1849
- }
1850
-
1851
- return '<wp:category_description>' . $this->wxr_cdata( $category->description ) . "</wp:category_description>";
1852
- }
1853
-
1854
- private function wxr_tag_name( $tag ) {
1855
- if ( empty( $tag->name ) ) {
1856
- return '';
1857
- }
1858
-
1859
- return '<wp:tag_name>' . $this->wxr_cdata( $tag->name ) . "</wp:tag_name>";
1860
- }
1861
-
1862
- private function wxr_tag_description( $tag ) {
1863
- if ( empty( $tag->description ) ) {
1864
- return '';
1865
- }
1866
-
1867
- return '<wp:tag_description>' . $this->wxr_cdata( $tag->description ) . "</wp:tag_description>";
1868
- }
1869
-
1870
- private function wxr_term_name( $term ) {
1871
- if ( empty( $term->name ) ) {
1872
- return '';
1873
- }
1874
-
1875
- return '<wp:term_name>' . $this->wxr_cdata( $term->name ) . "</wp:term_name>";
1876
- }
1877
-
1878
- private function wxr_term_description( $term ) {
1879
- if ( empty( $term->description ) ) {
1880
- return '';
1881
- }
1882
-
1883
- return "\t\t<wp:term_description>" . $this->wxr_cdata( $term->description ) . "</wp:term_description>";
1884
- }
1885
-
1886
- private function wxr_term_meta( $term ) {
1887
- global $wpdb;
1888
-
1889
- $termmeta = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->termmeta WHERE term_id = %d", $term->term_id ) );
1890
-
1891
- $line='';
1892
- foreach ( $termmeta as $meta )
1893
- {
1894
- /**
1895
- * Filters whether to selectively skip term meta used for WXR exports.
1896
- *
1897
- * Returning a truthy value to the filter will skip the current meta
1898
- * object from being exported.
1899
- *
1900
- * @since 4.6.0
1901
- *
1902
- * @param bool $skip Whether to skip the current piece of term meta. Default false.
1903
- * @param string $meta_key Current meta key.
1904
- * @param object $meta Current meta object.
1905
- */
1906
- if ( ! apply_filters( 'wxr_export_skip_termmeta', false, $meta->meta_key, $meta ) )
1907
- {
1908
- $line.="\t\t<wp:termmeta>\n\t\t\t<wp:meta_key>".$this->wxr_cdata( $meta->meta_key )."</wp:meta_key>\n\t\t\t<wp:meta_value>".$this->wxr_cdata( $meta->meta_value )."</wp:meta_value>\n\t\t</wp:termmeta>\n";
1909
- }
1910
- }
1911
- return $line;
1912
- }
1913
-
1914
- private function wxr_cdata( $str )
1915
- {
1916
- if ( ! seems_utf8( $str ) ) {
1917
- $str = utf8_encode( $str );
1918
- }
1919
- // $str = ent2ncr(esc_html($str));
1920
- $str = '<![CDATA[' . str_replace( ']]>', ']]]]><![CDATA[>', $str ) . ']]>';
1921
-
1922
- return $str;
1923
- }
1924
-
1925
- private function wxr_site_url() {
1926
- if ( is_multisite() ) {
1927
- // Multisite: the base URL.
1928
- return network_home_url();
1929
- } else {
1930
- // WordPress (single site): the blog URL.
1931
- return get_bloginfo_rss( 'url' );
1932
- }
1933
- }
1934
-
1935
- private function wxr_authors_list( array $post_ids = null )
1936
- {
1937
- global $wpdb;
1938
-
1939
- if ( ! empty( $post_ids ) ) {
1940
- $post_ids = array_map( 'absint', $post_ids );
1941
- $and = 'AND ID IN ( ' . implode( ', ', $post_ids ) . ')';
1942
- } else {
1943
- $and = '';
1944
- }
1945
-
1946
- $authors = array();
1947
- $results = $wpdb->get_results( "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_status != 'auto-draft' $and" );
1948
- foreach ( (array) $results as $result )
1949
- {
1950
- $authors[] = get_userdata( $result->post_author );
1951
- }
1952
-
1953
- $authors = array_filter( $authors );
1954
-
1955
- $line='';
1956
- foreach ( $authors as $author )
1957
- {
1958
- $line.= "\t<wp:author>";
1959
- $line.= '<wp:author_id>' . intval( $author->ID ) . '</wp:author_id>';
1960
- $line.= '<wp:author_login>' . $this->wxr_cdata( $author->user_login ) . '</wp:author_login>';
1961
- $line.= '<wp:author_email>' . $this->wxr_cdata( $author->user_email ) . '</wp:author_email>';
1962
- $line.= '<wp:author_display_name>' . $this->wxr_cdata( $author->display_name ) . '</wp:author_display_name>';
1963
- $line.= '<wp:author_first_name>' . $this->wxr_cdata( $author->first_name ) . '</wp:author_first_name>';
1964
- $line.= '<wp:author_last_name>' . $this->wxr_cdata( $author->last_name ) . '</wp:author_last_name>';
1965
- $line.= "</wp:author>\n";
1966
- }
1967
- return $line;
1968
- }
1969
-
1970
- private function wxr_post_taxonomy($post)
1971
- {
1972
- $taxonomies = get_object_taxonomies( $post->post_type );
1973
- if ( empty( $taxonomies ) ) {
1974
- return;
1975
- }
1976
- $terms = wp_get_object_terms( $post->ID, $taxonomies );
1977
- $line='';
1978
- foreach ( (array) $terms as $term )
1979
- {
1980
- $line.= "\t\t<category domain=\"{$term->taxonomy}\" nicename=\"{$term->slug}\">" . $this->wxr_cdata( $term->name ) . "</category>\n";
1981
- }
1982
- return $line;
1983
- }
1984
- }
1985
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-function-realize.php DELETED
@@ -1,161 +0,0 @@
1
- <?php
2
-
3
- class WPvivid_Function_Realize
4
- {
5
- public function __construct()
6
- {
7
-
8
- }
9
-
10
- public function _backup_cancel($task_id = '')
11
- {
12
- global $wpvivid_plugin;
13
- try {
14
- $tasks = WPvivid_taskmanager::get_tasks();
15
- foreach ($tasks as $task){
16
- $task_id = $task['id'];
17
- $status=WPvivid_taskmanager::get_backup_task_status($task_id);
18
- $time_spend=$status['run_time']-$status['start_time'];
19
- $options=WPvivid_Setting::get_option('wpvivid_common_setting');
20
- if(isset($options['max_execution_time']))
21
- {
22
- $limit=$options['max_execution_time'];
23
- }
24
- else
25
- {
26
- $limit=WPVIVID_MAX_EXECUTION_TIME;
27
- }
28
- if($time_spend > $limit * 2){
29
- $file_name = WPvivid_taskmanager::get_task_options($task_id, 'file_prefix');
30
- $backup_options = WPvivid_taskmanager::get_task_options($task_id, 'backup_options');
31
- $file = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_options['dir'] . DIRECTORY_SEPARATOR . $file_name . '_cancel';
32
- touch($file);
33
-
34
- if($wpvivid_plugin->wpvivid_log->log_file_handle==false)
35
- {
36
- $wpvivid_plugin->wpvivid_log->OpenLogFile(WPvivid_taskmanager::get_task_options($task_id,'log_file_name'));
37
- }
38
- $wpvivid_plugin->wpvivid_log->WriteLog('Backup cancelled. Twice the setting time.','notice');
39
- $task=new WPvivid_Backup_Task($task_id);
40
- $task->update_status('cancel');
41
- $wpvivid_plugin->clean_backing_up_data_event($task_id);
42
- WPvivid_Schedule::clear_monitor_schedule($task_id);
43
- WPvivid_taskmanager::delete_task($task_id);
44
- }
45
- else {
46
- $file_name = WPvivid_taskmanager::get_task_options($task_id, 'file_prefix');
47
- $backup_options = WPvivid_taskmanager::get_task_options($task_id, 'backup_options');
48
- $file = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_options['dir'] . DIRECTORY_SEPARATOR . $file_name . '_cancel';
49
- touch($file);
50
-
51
- $timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT, array($task_id));
52
-
53
- if ($timestamp === false) {
54
- $wpvivid_plugin->add_monitor_event($task_id, 10);
55
- }
56
- }
57
- }
58
-
59
- /*if (WPvivid_taskmanager::get_task($task_id) !== false) {
60
- $file_name = WPvivid_taskmanager::get_task_options($task_id, 'file_prefix');
61
- $backup_options = WPvivid_taskmanager::get_task_options($task_id, 'backup_options');
62
- $file = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . $backup_options['dir'] . DIRECTORY_SEPARATOR . $file_name . '_cancel';
63
- touch($file);
64
- }
65
-
66
- $timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT, array($task_id));
67
-
68
- if ($timestamp === false) {
69
- $wpvivid_plugin->add_monitor_event($task_id, 10);
70
- }*/
71
- $ret['result'] = 'success';
72
- $ret['msg'] = __('The backup will be canceled after backing up the current chunk ends.', 'wpvivid-backuprestore');
73
- }
74
- catch (Exception $error) {
75
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
76
- error_log($message);
77
- return array('result'=>'failed','error'=>$message);
78
- }
79
- catch (Error $error) {
80
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
81
- error_log($message);
82
- return array('result'=>'failed','error'=>$message);
83
- }
84
- return $ret;
85
- }
86
-
87
- public function _get_log_file($read_type, $param){
88
- global $wpvivid_plugin;
89
- $ret['result']='failed';
90
- if($read_type == 'backuplist'){
91
- $backup_id = $param;
92
- $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
93
- if(!$backup) {
94
- $ret['result']='failed';
95
- $ret['error']=__('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid-backuprestore');
96
- return $ret;
97
- }
98
- if(!file_exists($backup['log'])) {
99
- $ret['result']='failed';
100
- $ret['error']=__('The log not found.', 'wpvivid-backuprestore');
101
- return $ret;
102
- }
103
- $ret['result']='success';
104
- $ret['log_file']=$backup['log'];
105
- }
106
- else if($read_type == 'lastlog'){
107
- $option = $param;
108
- $log_file_name= $wpvivid_plugin->wpvivid_log->GetSaveLogFolder().$option.'_log.txt';
109
- if(!file_exists($log_file_name))
110
- {
111
- $information['result']='failed';
112
- $information['error']=__('The log not found.', 'wpvivid-backuprestore');
113
- return $information;
114
- }
115
- $ret['result']='success';
116
- $ret['log_file']=$log_file_name;
117
- }
118
- else if($read_type == 'tasklog'){
119
- $backup_task_id = $param;
120
- $option=WPvivid_taskmanager::get_task_options($backup_task_id,'log_file_name');
121
- if(!$option) {
122
- $information['result']='failed';
123
- $information['error']=__('Retrieving the backup information failed while showing log. Please try again later.', 'wpvivid-backuprestore');
124
- return $information;
125
- }
126
- $log_file_name= $wpvivid_plugin->wpvivid_log->GetSaveLogFolder().$option.'_log.txt';
127
- if(!file_exists($log_file_name)) {
128
- $information['result']='failed';
129
- $information['error']=__('The log not found.', 'wpvivid-backuprestore');
130
- return $information;
131
- }
132
- $ret['result']='success';
133
- $ret['log_file']=$log_file_name;
134
- }
135
- return $ret;
136
- }
137
-
138
- public function _set_remote($remote){
139
- WPvivid_Setting::update_option('wpvivid_upload_setting',$remote['upload']);
140
- $history=WPvivid_Setting::get_option('wpvivid_user_history');
141
- $history['remote_selected']=$remote['history']['remote_selected'];
142
- WPvivid_Setting::update_option('wpvivid_user_history',$history);
143
- }
144
-
145
- public function _get_default_remote_storage(){
146
- $remote_storage_type = '';
147
- $remoteslist=WPvivid_Setting::get_all_remote_options();
148
- $default_remote_storage='';
149
- foreach ($remoteslist['remote_selected'] as $value) {
150
- $default_remote_storage=$value;
151
- }
152
- foreach ($remoteslist as $key=>$value)
153
- {
154
- if($key === $default_remote_storage)
155
- {
156
- $remote_storage_type=$value['type'];
157
- }
158
- }
159
- return $remote_storage_type;
160
- }
161
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-i18n.php DELETED
@@ -1,49 +0,0 @@
1
- <?php
2
- if (!defined('WPVIVID_PLUGIN_DIR')){
3
- die;
4
- }
5
- /**
6
- * Define the internationalization functionality
7
- *
8
- * Loads and defines the internationalization files for this plugin
9
- * so that it is ready for translation.
10
- *
11
- * @link https://wpvivid.com
12
- * @since 0.9.1
13
- *
14
- * @package wpvivid
15
- * @subpackage wpvivid/includes
16
- */
17
-
18
- /**
19
- * Define the internationalization functionality.
20
- *
21
- * Loads and defines the internationalization files for this plugin
22
- * so that it is ready for translation.
23
- *
24
- * @since 0.9.1
25
- * @package wpvivid
26
- * @subpackage wpvivid/includes
27
- * @author wpvivid team
28
- */
29
- class WPvivid_i18n {
30
-
31
-
32
- /**
33
- * Load the plugin text domain for translation.
34
- *
35
- *
36
- */
37
- public function load_plugin_textdomain() {
38
-
39
- load_plugin_textdomain(
40
- 'wpvivid-backuprestore',
41
- false,
42
- dirname( dirname( plugin_basename( __FILE__ ) ) ) . '/languages/'
43
- );
44
-
45
- }
46
-
47
-
48
-
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-importer.php DELETED
@@ -1,2547 +0,0 @@
1
- <?php
2
- /**
3
- * WPvivid addon: yes
4
- * Addon Name: wpvivid-backup-pro-all-in-one
5
- * Description: Pro
6
- * Version: 1.9.1
7
- * Need_init: yes
8
- * Interface Name: WPvivid_media_importer
9
- */
10
-
11
- if ( ! class_exists( 'WP_List_Table' ) )
12
- {
13
- require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
14
- }
15
-
16
- class WPvivid_Export_List extends WP_List_Table
17
- {
18
- public $list;
19
- public $page_num;
20
- public $parent;
21
-
22
- public function __construct( $args = array() )
23
- {
24
- global $wpdb;
25
- parent::__construct(
26
- array(
27
- 'plural' => 'import',
28
- 'screen' => 'import',
29
- )
30
- );
31
- }
32
-
33
- public function set_parent($parent)
34
- {
35
- $this->parent=$parent;
36
- }
37
-
38
- public function set_list($list, $page_num=1)
39
- {
40
- $this->list=$list;
41
- $this->page_num=$page_num;
42
- }
43
-
44
- public function print_column_headers( $with_id = true )
45
- {
46
- list($columns, $hidden, $sortable, $primary) = $this->get_column_info();
47
-
48
- if (!empty($columns['cb'])) {
49
- static $cb_counter = 1;
50
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __('Select All') . '</label>'
51
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox"/>';
52
- $cb_counter++;
53
- }
54
-
55
- foreach ($columns as $column_key => $column_display_name) {
56
- $class = array('manage-column', "column-$column_key");
57
-
58
- if (in_array($column_key, $hidden)) {
59
- $class[] = 'hidden';
60
- }
61
-
62
- if ('cb' === $column_key) {
63
- $class[] = 'check-column';
64
- }
65
-
66
- if ($column_key === $primary) {
67
- $class[] = 'column-primary';
68
- }
69
-
70
- $tag = ('cb' === $column_key) ? 'td' : 'th';
71
- $scope = ('th' === $tag) ? 'scope="col"' : '';
72
- $id = $with_id ? "id='$column_key'" : '';
73
-
74
- if (!empty($class)) {
75
- $class = "class='" . join(' ', $class) . "'";
76
- }
77
-
78
- echo "<$tag $scope $id $class>$column_display_name</$tag>";
79
- }
80
- }
81
-
82
- public function get_columns()
83
- {
84
- $posts_columns = array();
85
-
86
- $posts_columns['file_name'] = __( 'File Name', 'wpvivid-backuprestore' );
87
- $posts_columns['export_type'] = __( 'Post Types', 'wpvivid-backuprestore' );
88
- $posts_columns['posts_count'] = __( 'Count', 'wpvivid-backuprestore' );
89
- $posts_columns['media_size'] = __( 'Media Files Size', 'wpvivid-backuprestore' );
90
- $posts_columns['import'] = __( 'Action', 'wpvivid-backuprestore' );
91
-
92
- return $posts_columns;
93
- }
94
-
95
- protected function display_tablenav( $which ) {
96
- $total_items =sizeof($this->list);
97
- if($total_items > 10) {
98
- if ('top' === $which) {
99
- wp_nonce_field('bulk-' . $this->_args['plural']);
100
- }
101
- ?>
102
- <div class="tablenav <?php echo esc_attr($which); ?>">
103
-
104
- <?php if ($this->has_items()) : ?>
105
- <div class="alignleft actions bulkactions">
106
- <?php $this->bulk_actions($which); ?>
107
- </div>
108
- <?php
109
- endif;
110
- $this->extra_tablenav($which);
111
- $this->pagination($which);
112
- ?>
113
-
114
- <br class="clear"/>
115
- </div>
116
- <?php
117
- }
118
- }
119
-
120
- function prepare_items()
121
- {
122
- $columns = $this->get_columns();
123
- $hidden = array();
124
- $sortable = array();
125
- $this->_column_headers = array($columns, $hidden, $sortable);
126
-
127
- $total_items =sizeof($this->list);
128
- if($total_items > 10) {
129
- $this->set_pagination_args(
130
- array(
131
- 'total_items' => $total_items,
132
- 'per_page' => 10,
133
- )
134
- );
135
- }
136
- }
137
-
138
- public function has_items()
139
- {
140
- return !empty($this->list);
141
- }
142
-
143
- public function column_cb( $item )
144
- {
145
- ?>
146
- <input id="cb-select-<?php echo $item['id']; ?>" type="checkbox" name="export[]" value="<?php echo $item['id']; ?>"/>
147
- <?php
148
- }
149
-
150
- public function _column_file_name( $item, $classes, $data, $primary )
151
- {
152
- echo '<td>
153
- <div>
154
- '.$item['file_name'].'
155
- </div>
156
- <div style="padding-bottom: 5px;">
157
- <div class="backuptime">Data Modified: ' . __(date('M d, Y H:i', $item['time']), 'wpvivid-backuprestore') . '</div>
158
- </div>
159
- </td>';
160
- }
161
-
162
- public function _column_export_type( $item, $classes, $data, $primary )
163
- {
164
- $export = $item['export_type'] === 'page' ? 'Page' : 'Post';
165
- echo '<td style="color: #000;">
166
- <div>
167
- <div style="float:left;padding:10px 10px 10px 0;">'.__('Type: ').$export.'</div>
168
- </div>
169
- </td>';
170
- }
171
-
172
- public function _column_posts_count( $item, $classes, $data, $primary )
173
- {
174
- echo '<td style="min-width:100px;">
175
- <div style="float:left;padding:10px 10px 10px 0;">
176
- '.$item['posts_count'].'
177
- </div>
178
- </td>';
179
- }
180
-
181
- public function _column_media_size( $item, $classes, $data, $primary )
182
- {
183
- echo '<td style="min-width:100px;">
184
- <div style="float:left;padding:10px 10px 10px 0;">
185
- '.$item['media_size'].'
186
- </div>
187
- </td>';
188
- }
189
-
190
- public function _column_import( $item )
191
- {
192
- echo '<td style="min-width:100px;">
193
- <div class="export-list-import" style="cursor:pointer;padding:10px 0 10px 0;">
194
- <img src="' . esc_url(WPVIVID_PLUGIN_URL . '/admin/partials/images/Restore.png') . '" style="vertical-align:middle;" /><span>' . __('Import', 'wpvivid-backuprestore') . '</span>
195
- </div>
196
- </td>';
197
- }
198
-
199
- public function display_rows()
200
- {
201
- $this->_display_rows( $this->list );
202
- }
203
-
204
- private function _display_rows($lists)
205
- {
206
- $page_lists=$lists;
207
- $page=$this->get_pagenum();
208
- $count=0;
209
- while ( $count<$page )
210
- {
211
- $page_lists = array_splice( $lists, 0, 10);
212
- $count++;
213
- }
214
- foreach ( $page_lists as $key=>$item )
215
- {
216
- $item['id']=$key;
217
- $this->single_row($item);
218
- }
219
- ?>
220
- <?php
221
- }
222
-
223
- public function get_pagenum()
224
- {
225
- if($this->page_num=='first')
226
- {
227
- $this->page_num=1;
228
- }
229
- else if($this->page_num=='last')
230
- {
231
- $this->page_num=$this->_pagination_args['total_pages'];
232
- }
233
- $pagenum = $this->page_num ? $this->page_num : 0;
234
-
235
- if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
236
- {
237
- $pagenum = $this->_pagination_args['total_pages'];
238
- }
239
-
240
- return max( 1, $pagenum );
241
- }
242
-
243
- public function single_row($item)
244
- {
245
- ?>
246
- <tr id="<?php echo $item['id'] ?>" class="wpvivid-export-list-item">
247
- <?php $this->single_row_columns( $item ); ?>
248
- </tr>
249
- <?php
250
- }
251
-
252
- protected function pagination( $which ) {
253
- if ( empty( $this->_pagination_args ) ) {
254
- return;
255
- }
256
-
257
- $total_items = $this->_pagination_args['total_items'];
258
- $total_pages = $this->_pagination_args['total_pages'];
259
- $infinite_scroll = false;
260
- if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
261
- $infinite_scroll = $this->_pagination_args['infinite_scroll'];
262
- }
263
-
264
- if ( 'top' === $which && $total_pages > 1 ) {
265
- $this->screen->render_screen_reader_content( 'heading_pagination' );
266
- }
267
-
268
- $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
269
-
270
- $current = $this->get_pagenum();
271
- $removable_query_args = wp_removable_query_args();
272
-
273
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
274
-
275
- $current_url = remove_query_arg( $removable_query_args, $current_url );
276
-
277
- $page_links = array();
278
-
279
- $total_pages_before = '<span class="paging-input">';
280
- $total_pages_after = '</span></span>';
281
-
282
- $disable_first = $disable_last = $disable_prev = $disable_next = false;
283
-
284
- if ( $current == 1 ) {
285
- $disable_first = true;
286
- $disable_prev = true;
287
- }
288
- if ( $current == 2 ) {
289
- $disable_first = true;
290
- }
291
- if ( $current == $total_pages ) {
292
- $disable_last = true;
293
- $disable_next = true;
294
- }
295
- if ( $current == $total_pages - 1 ) {
296
- $disable_last = true;
297
- }
298
-
299
- if ( $disable_first ) {
300
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
301
- } else {
302
- $page_links[] = sprintf(
303
- "<div class='first-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
304
- __( 'First page' ),
305
- '&laquo;'
306
- );
307
- }
308
-
309
- if ( $disable_prev ) {
310
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
311
- } else {
312
- $page_links[] = sprintf(
313
- "<div class='prev-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
314
- $current,
315
- __( 'Previous page' ),
316
- '&lsaquo;'
317
- );
318
- }
319
-
320
- if ( 'bottom' === $which ) {
321
- $html_current_page = $current;
322
- $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
323
- } else {
324
- $html_current_page = sprintf(
325
- "%s<input class='current-page' id='current-page-selector-import' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' /><span class='tablenav-paging-text'>",
326
- '<label for="current-page-selector-import" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
327
- $current,
328
- strlen( $total_pages )
329
- );
330
- }
331
- $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
332
- $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
333
-
334
- if ( $disable_next ) {
335
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
336
- } else {
337
- $page_links[] = sprintf(
338
- "<div class='next-page button' value='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
339
- $current,
340
- __( 'Next page' ),
341
- '&rsaquo;'
342
- );
343
- }
344
-
345
- if ( $disable_last ) {
346
- $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
347
- } else {
348
- $page_links[] = sprintf(
349
- "<div class='last-page button'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></div>",
350
- __( 'Last page' ),
351
- '&raquo;'
352
- );
353
- }
354
-
355
- $pagination_links_class = 'pagination-links';
356
- if ( ! empty( $infinite_scroll ) ) {
357
- $pagination_links_class .= ' hide-if-js';
358
- }
359
- $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
360
-
361
- if ( $total_pages ) {
362
- $page_class = $total_pages < 2 ? ' one-page' : '';
363
- } else {
364
- $page_class = ' no-pages';
365
- }
366
- $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
367
-
368
- echo $this->_pagination;
369
- }
370
- }
371
-
372
- class WPvivid_Impoter_taskmanager
373
- {
374
- public static function new_task($task_id,$files,$options)
375
- {
376
- $task['id']=$task_id;
377
- $task['status']['start_time']=time();
378
- $task['status']['run_time']=time();
379
- $task['status']['timeout']=time();
380
- $task['status']['str']='ready';
381
- $task['status']['resume_count']=0;
382
- $task['options']=$options;
383
- $task['data']['files']=$files;
384
- self::update_task($task_id,$task);
385
- }
386
-
387
- public static function get_files($task_id)
388
- {
389
- $task=self::get_task($task_id);
390
- return $task['data']['files'];
391
- }
392
-
393
- public static function get_options($task_id)
394
- {
395
- $task=self::get_task($task_id);
396
- return $task['options'];
397
- }
398
-
399
- public static function get_tasks(){
400
- $default = array();
401
- return $options = get_option('wpvivid_importer_task_list', $default);
402
- }
403
-
404
- public static function get_task($task_id)
405
- {
406
- $default = array();
407
- $tasks = get_option('wpvivid_importer_task_list', $default);
408
- if(array_key_exists ($task_id, $tasks)) {
409
- return $tasks[$task_id];
410
- }
411
- else {
412
- return false;
413
- }
414
- }
415
-
416
- public static function update_task($task_id, $task)
417
- {
418
- $default = array();
419
- $options = get_option('wpvivid_importer_task_list', $default);
420
- $options[$task_id]=$task;
421
- WPvivid_Setting::update_option('wpvivid_importer_task_list', $options);
422
- }
423
-
424
- public static function delete_task($task_id){
425
- $options = get_option('wpvivid_importer_task_list', array());
426
- unset($options[$task_id]);
427
- WPvivid_Setting::update_option('wpvivid_importer_task_list', $options);
428
- }
429
-
430
- public static function get_import_task_status($task_id){
431
- $tasks=self::get_tasks();
432
- if(array_key_exists ($task_id, $tasks)) {
433
- $task = $tasks[$task_id];
434
- return $task['status']['str'];
435
- }
436
- else {
437
- return false;
438
- }
439
- }
440
-
441
- public static function update_import_task_status($task_id, $status, $reset_start_time=false, $reset_timeout=false, $resume_count=false, $error=''){
442
- $tasks=self::get_tasks();
443
- if(array_key_exists ($task_id, $tasks))
444
- {
445
- $task = $tasks[$task_id];
446
- $task['status']['run_time']=time();
447
- if($reset_start_time)
448
- $task['status']['start_time']=time();
449
- if(!empty($status)) {
450
- $task['status']['str']=$status;
451
- }
452
- if($reset_timeout)
453
- $task['status']['timeout']=time();
454
- if($resume_count!==false) {
455
- $task['status']['resume_count']=$resume_count;
456
- }
457
-
458
- if(!empty($error)) {
459
- $task['status']['error']=$error;
460
- }
461
- self::update_task($task_id, $task);
462
- return $task;
463
- }
464
- else {
465
- return false;
466
- }
467
- }
468
- }
469
-
470
- class WPvivid_import_data
471
- {
472
- public $import_log = false;
473
- public $import_log_file;
474
-
475
- public function __construct()
476
- {
477
- $this->import_log_file = WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR.DIRECTORY_SEPARATOR.'wpvivid_import_log.txt';
478
- }
479
-
480
- public function wpvivid_create_import_log()
481
- {
482
- $this->import_log=new WPvivid_Log();
483
- $this->import_log->CreateLogFile($this->import_log_file, 'has_folder', 'import');
484
- }
485
-
486
- public function wpvivid_write_import_log($message, $type)
487
- {
488
- if($this->import_log===false)
489
- {
490
- $this->import_log=new WPvivid_Log();
491
- $this->import_log->OpenLogFile($this->import_log_file,'has_folder');
492
- }
493
-
494
- clearstatcache();
495
- if(filesize($this->import_log_file)>4*1024*1024)
496
- {
497
- $this->import_log->CloseFile();
498
- unlink($this->import_log_file);
499
- $this->import_log=null;
500
- $this->import_log=new WPvivid_Log();
501
- $this->import_log->OpenLogFile($this->import_log_file,'has_folder');
502
- }
503
- $this->import_log->WriteLog($message, $type);
504
- }
505
-
506
- public function get_log_content()
507
- {
508
- $buffer = '';
509
- if(file_exists($this->import_log_file)){
510
- $file = fopen($this->import_log_file, 'r');
511
-
512
- if (!$file) {
513
- return '';
514
- }
515
-
516
- while (!feof($file)) {
517
- $buffer .= fread($file, 1024);
518
- }
519
- fclose($file);
520
- }
521
- return $buffer;
522
- }
523
- }
524
-
525
-
526
- global $xml_file_name;
527
- class WPvivid_media_importer
528
- {
529
- var $max_wxr_version = 1.2; // max. supported WXR version
530
-
531
- var $id; // WXR attachment ID
532
- var $default_user;
533
- // information to import from WXR file
534
- var $version;
535
- var $authors = array();
536
- var $posts = array();
537
- var $terms = array();
538
- var $categories = array();
539
- var $tags = array();
540
- var $base_url = '';
541
- var $new_site_url='';
542
-
543
- // mappings from old information to new
544
- var $processed_authors = array();
545
- var $author_mapping = array();
546
- var $processed_terms = array();
547
- var $processed_posts = array();
548
- var $post_orphans = array();
549
- var $processed_menu_items = array();
550
- var $menu_item_orphans = array();
551
- var $missing_menu_items = array();
552
-
553
- var $fetch_attachments = false;
554
- var $url_remap = array();
555
- var $featured_images = array();
556
-
557
- public $import_log;
558
-
559
- public function __construct()
560
- {
561
- }
562
-
563
- public function import($id)
564
- {
565
- if (!class_exists('PclZip')) include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
566
-
567
- $this->import_log = new WPvivid_import_data();
568
-
569
- @set_time_limit(900);
570
-
571
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.WPvivid_Setting::get_backupdir().DIRECTORY_SEPARATOR.WPVIVID_IMPORT_EXPORT_DIR;
572
-
573
- $files=WPvivid_Impoter_taskmanager::get_files($id);
574
-
575
- define(PCLZIP_TEMPORARY_DIR,dirname($path));
576
-
577
- global $xml_file_name;
578
- foreach ($files as $file)
579
- {
580
- $file_path=$path.DIRECTORY_SEPARATOR.$file;
581
- $this->import_log->wpvivid_write_import_log('Prepare to retrieve file info, file name: '.$file_path, 'notice');
582
- $archive = new PclZip($file_path);
583
- $ret=$this->get_file_info($file_path);
584
- if($ret['result']=='failed')
585
- {
586
- $this->import_log->wpvivid_write_import_log('Failed to retrieve file info, error: '.$ret['error'], 'notice');
587
- WPvivid_Impoter_taskmanager::update_import_task_status($id, 'error', true, false, false, $ret['error']);
588
- return $ret;
589
- }
590
- $this->import_log->wpvivid_write_import_log('Retrieving file info is completed.', 'notice');
591
- $xml_file=$ret['json_data']['xml_file'];
592
- $xml_file_name = $ret['json_data']['xml_file'];
593
- $this->import_log->wpvivid_write_import_log('Prepare to extract, file name: '.$xml_file, 'notice');
594
- $zip_ret = $archive->extract(PCLZIP_OPT_BY_NAME,basename($xml_file),PCLZIP_OPT_PATH,$path,PCLZIP_OPT_REPLACE_NEWER,PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
595
- if(!$zip_ret)
596
- {
597
- $this->import_log->wpvivid_write_import_log('Failed to extract, error: '.$archive->errorInfo(true), 'notice');
598
- WPvivid_Impoter_taskmanager::update_import_task_status($id, 'error', true, false, false, $archive->errorInfo(true));
599
- $ret['result']='failed';
600
- $ret['error'] = $archive->errorInfo(true);
601
- return $ret;
602
- }
603
- $this->import_log->wpvivid_write_import_log('The file extracton is completed, file name: '.$xml_file, 'notice');
604
- $this->import_log->wpvivid_write_import_log('Prepare to extract, file name: '.$file_path, 'notice');
605
- $zip_ret = $archive->extract(PCLZIP_OPT_PATH, WP_CONTENT_DIR, PCLZIP_OPT_REPLACE_NEWER, PCLZIP_CB_PRE_EXTRACT, 'wpvivid_function_pre_extract_import_callback', PCLZIP_OPT_TEMP_FILE_THRESHOLD,16);
606
- if(!$zip_ret)
607
- {
608
- $this->import_log->wpvivid_write_import_log('Failed to extract, error: '.$archive->errorInfo(true), 'notice');
609
- WPvivid_Impoter_taskmanager::update_import_task_status($id, 'error', true, false, false, $archive->errorInfo(true));
610
- $ret['result']='failed';
611
- $ret['error'] = $archive->errorInfo(true);
612
- return $ret;
613
- }
614
- $this->import_log->wpvivid_write_import_log('The file extracton is completed, file name: '.$file_path, 'notice');
615
-
616
- @set_time_limit(900);
617
- $file_path=$path.DIRECTORY_SEPARATOR.$xml_file;
618
- $this->import_log->wpvivid_write_import_log('Prepare import, file name: '.$file_path, 'notice');
619
- $ret=$this->_import($file_path, WPvivid_Impoter_taskmanager::get_options($id));
620
- if($ret['result']=='failed')
621
- {
622
- $this->import_log->wpvivid_write_import_log('Failed to import, error: '.$ret['error'], 'notice');
623
- WPvivid_Impoter_taskmanager::update_import_task_status($id, 'error', true, false, false, $ret['error']);
624
- return $ret;
625
- }
626
- $this->import_log->wpvivid_write_import_log('Import task is completed, file name: '.$file_path, 'notice');
627
- @unlink($file_path);
628
- }
629
-
630
- $this->replace_domain();
631
-
632
- $ret['result']='success';
633
- $ret['files']=$files;
634
- $this->import_log->wpvivid_write_import_log('Import task succeeded.', 'notice');
635
- WPvivid_Impoter_taskmanager::update_import_task_status($id, 'completed', false);
636
- return $ret;
637
- }
638
-
639
- public function get_file_info($file_name)
640
- {
641
- $zip=new WPvivid_ZipClass();
642
- $ret=$zip->get_json_data($file_name, 'export');
643
- if($ret['result'] === WPVIVID_SUCCESS)
644
- {
645
- $json=$ret['json_data'];
646
- $json = json_decode($json, 1);
647
- if (is_null($json))
648
- {
649
- return array('result'=>WPVIVID_FAILED,'error'=>'Failed to decode json');
650
- } else {
651
- return array('result'=>WPVIVID_SUCCESS,'json_data'=>$json);
652
- }
653
- }
654
- else {
655
- return $ret;
656
- }
657
- }
658
-
659
- public function _import($file,$options)
660
- {
661
- if(isset($options['user']))
662
- {
663
- $this->default_user=$options['user'];
664
- }
665
- else
666
- {
667
- $this->default_user=get_current_user_id();
668
- }
669
-
670
- if(isset($options['update_exist']))
671
- {
672
- $update_exist=$options['update_exist'];
673
- }
674
- else
675
- {
676
- $update_exist=false;
677
- }
678
-
679
- $ret=$this->import_start( $file );
680
-
681
- if($ret['result']=='failed')
682
- {
683
- return $ret;
684
- }
685
-
686
- $ret=$this->get_author_mapping();
687
-
688
- if($ret['result']=='failed')
689
- {
690
- return $ret;
691
- }
692
-
693
- wp_suspend_cache_invalidation( true );
694
- $ret=$this->process_categories();
695
- if($ret['result']=='failed')
696
- {
697
- return $ret;
698
- }
699
- $ret=$this->process_tags();
700
- if($ret['result']=='failed')
701
- {
702
- return $ret;
703
- }
704
- $ret=$this->process_terms();
705
- if($ret['result']=='failed')
706
- {
707
- return $ret;
708
- }
709
- $ret=$this->process_posts_ex($update_exist);
710
- if($ret['result']=='failed')
711
- {
712
- return $ret;
713
- }
714
- wp_suspend_cache_invalidation( false );
715
- $ret=$this->import_end();
716
-
717
- return $ret;
718
- }
719
-
720
- private function import_start( $file )
721
- {
722
- $this->import_log->wpvivid_write_import_log('Analyze the imported file, file name: '.$file, 'notice');
723
- $import_data = $this->parse( $file );
724
- if( is_wp_error( $import_data ) )
725
- {
726
- $this->import_log->wpvivid_write_import_log('Failed to analyze a file, file name: '.$file, 'notice');
727
- $ret['result']='failed';
728
- $ret['error']=$import_data->get_error_message();
729
- return $ret;
730
- }
731
-
732
- $this->version = $import_data['version'];
733
- $this->get_authors_from_import( $import_data );
734
- $this->posts = $import_data['posts'];
735
- $this->terms = $import_data['terms'];
736
- $this->categories = $import_data['categories'];
737
- $this->tags = $import_data['tags'];
738
- $this->base_url = esc_url( $import_data['base_url'] );
739
- $this->import_log->wpvivid_write_import_log('The file analysis is completed, file name: '.$file, 'notice');
740
- $ret['result']='success';
741
- return $ret;
742
- }
743
-
744
- private function get_author_mapping()
745
- {
746
- $ret['result']='success';
747
-
748
- return $ret;
749
-
750
- /*
751
- $create_users = false;
752
-
753
- foreach ( (array) $_POST['imported_authors'] as $i => $old_login )
754
- {
755
- // Multisite adds strtolower to sanitize_user. Need to sanitize here to stop breakage in process_posts.
756
- $santized_old_login = sanitize_user( $old_login, true );
757
- $old_id = isset( $this->authors[$old_login]['author_id'] ) ? intval($this->authors[$old_login]['author_id']) : false;
758
-
759
- if ( ! empty( $_POST['user_map'][$i] ) )
760
- {
761
- $user = get_userdata( intval($_POST['user_map'][$i]) );
762
- if ( isset( $user->ID ) ) {
763
- if ( $old_id )
764
- $this->processed_authors[$old_id] = $user->ID;
765
- $this->author_mapping[$santized_old_login] = $user->ID;
766
- }
767
- } else if ( $create_users )
768
- {
769
- if ( ! empty($_POST['user_new'][$i]) )
770
- {
771
- $user_id = wp_create_user( $_POST['user_new'][$i], wp_generate_password() );
772
- } else if ( $this->version != '1.0' )
773
- {
774
- $user_data = array(
775
- 'user_login' => $old_login,
776
- 'user_pass' => wp_generate_password(),
777
- 'user_email' => isset( $this->authors[$old_login]['author_email'] ) ? $this->authors[$old_login]['author_email'] : '',
778
- 'display_name' => $this->authors[$old_login]['author_display_name'],
779
- 'first_name' => isset( $this->authors[$old_login]['author_first_name'] ) ? $this->authors[$old_login]['author_first_name'] : '',
780
- 'last_name' => isset( $this->authors[$old_login]['author_last_name'] ) ? $this->authors[$old_login]['author_last_name'] : '',
781
- );
782
- $user_id = wp_insert_user( $user_data );
783
- }
784
-
785
- if ( ! is_wp_error( $user_id ) )
786
- {
787
- if ( $old_id )
788
- $this->processed_authors[$old_id] = $user_id;
789
- $this->author_mapping[$santized_old_login] = $user_id;
790
- } else {
791
- printf( __( 'Failed to create new user for %s. Their posts will be attributed to the current user.', 'wordpress-importer' ), esc_html($this->authors[$old_login]['author_display_name']) );
792
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
793
- echo ' ' . $user_id->get_error_message();
794
- echo '<br />';
795
- }
796
- }
797
-
798
- // failsafe: if the user_id was invalid, default to the current user
799
- if ( ! isset( $this->author_mapping[$santized_old_login] ) )
800
- {
801
- if ( $old_id )
802
- $this->processed_authors[$old_id] = (int) get_current_user_id();
803
- $this->author_mapping[$santized_old_login] = (int) get_current_user_id();
804
- }
805
- }
806
- */
807
- }
808
-
809
- private function process_categories()
810
- {
811
- $ret['result']='success';
812
- $this->categories = apply_filters( 'wp_import_categories', $this->categories );
813
- $this->import_log->wpvivid_write_import_log('Start importing categories.', 'notice');
814
- if ( empty( $this->categories ) ) {
815
- $this->import_log->wpvivid_write_import_log('Categories import is completed.', 'notice');
816
- return $ret;
817
- }
818
-
819
- foreach ( $this->categories as $cat )
820
- {
821
- // if the category already exists leave it alone
822
- $term_id = term_exists( $cat['category_nicename'], 'category' );
823
- if ( $term_id )
824
- {
825
- if ( is_array($term_id) ) $term_id = $term_id['term_id'];
826
- if ( isset($cat['term_id']) )
827
- $this->processed_terms[intval($cat['term_id'])] = (int) $term_id;
828
- continue;
829
- }
830
-
831
- $category_parent = empty( $cat['category_parent'] ) ? 0 : category_exists( $cat['category_parent'] );
832
- $category_description = isset( $cat['category_description'] ) ? $cat['category_description'] : '';
833
- $catarr = array(
834
- 'category_nicename' => $cat['category_nicename'],
835
- 'category_parent' => $category_parent,
836
- 'cat_name' => $cat['cat_name'],
837
- 'category_description' => $category_description
838
- );
839
- $catarr = wp_slash( $catarr );
840
-
841
- $id = wp_insert_category( $catarr );
842
- if ( ! is_wp_error( $id ) )
843
- {
844
- if ( isset($cat['term_id']) )
845
- $this->processed_terms[intval($cat['term_id'])] = $id;
846
- } else {
847
-
848
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
849
- {
850
- $this->import_log->wpvivid_write_import_log('Failed to import categories, error: '.$id->get_error_message(), 'notice');
851
- $ret['result']='failed';
852
- $ret['error']='Failed to import category '.$cat['category_nicename'].' '.$id->get_error_message();
853
- return $ret;
854
- }
855
- continue;
856
- }
857
-
858
- $this->process_termmeta( $cat, $id['term_id'] );
859
- }
860
-
861
- unset( $this->categories );
862
- $this->import_log->wpvivid_write_import_log('Categories import is completed.', 'notice');
863
- return $ret;
864
- }
865
-
866
- private function process_termmeta( $term, $term_id )
867
- {
868
- if ( ! isset( $term['termmeta'] ) )
869
- {
870
- $term['termmeta'] = array();
871
- }
872
-
873
- $term['termmeta'] = apply_filters( 'wp_import_term_meta', $term['termmeta'], $term_id, $term );
874
-
875
- if ( empty( $term['termmeta'] ) ) {
876
- return;
877
- }
878
-
879
- foreach ( $term['termmeta'] as $meta )
880
- {
881
- $key = apply_filters( 'import_term_meta_key', $meta['key'], $term_id, $term );
882
- if ( ! $key ) {
883
- continue;
884
- }
885
-
886
- // Export gets meta straight from the DB so could have a serialized string
887
- $value = maybe_unserialize( $meta['value'] );
888
-
889
- add_term_meta( $term_id, $key, $value );
890
-
891
- do_action( 'import_term_meta', $term_id, $key, $value );
892
- }
893
- }
894
-
895
- private function process_tags()
896
- {
897
- $ret['result']='success';
898
- $this->tags = apply_filters( 'wp_import_tags', $this->tags );
899
- $this->import_log->wpvivid_write_import_log('Start importing tags.', 'notice');
900
- if ( empty( $this->tags ) ){
901
- $this->import_log->wpvivid_write_import_log('Tags import is completed.', 'notice');
902
- return $ret;
903
- }
904
-
905
- foreach ( $this->tags as $tag )
906
- {
907
- $term_id = term_exists( $tag['tag_slug'], 'post_tag' );
908
- if ( $term_id )
909
- {
910
- if ( is_array($term_id) ) $term_id = $term_id['term_id'];
911
- if ( isset($tag['term_id']) )
912
- $this->processed_terms[intval($tag['term_id'])] = (int) $term_id;
913
- continue;
914
- }
915
-
916
- $tag = wp_slash( $tag );
917
- $tag_desc = isset( $tag['tag_description'] ) ? $tag['tag_description'] : '';
918
- $tagarr = array( 'slug' => $tag['tag_slug'], 'description' => $tag_desc );
919
-
920
- $id = wp_insert_term( $tag['tag_name'], 'post_tag', $tagarr );
921
- if ( ! is_wp_error( $id ) )
922
- {
923
- if ( isset($tag['term_id']) )
924
- $this->processed_terms[intval($tag['term_id'])] = $id['term_id'];
925
- } else {
926
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
927
- {
928
- $this->import_log->wpvivid_write_import_log('Failed to import tags, error: '.$id->get_error_message(), 'notice');
929
- $ret['result']='failed';
930
- $ret['error']='Failed to import post tag '.$tag['tag_name'].' '.$id->get_error_message();
931
- return $ret;
932
- }
933
- continue;
934
- }
935
-
936
- $this->process_termmeta( $tag, $id['term_id'] );
937
- }
938
-
939
- unset( $this->tags );
940
- $this->import_log->wpvivid_write_import_log('Tags import is completed.', 'notice');
941
- return $ret;
942
- }
943
-
944
- private function process_terms()
945
- {
946
- $ret['result']='success';
947
- $this->terms = apply_filters( 'wp_import_terms', $this->terms );
948
- $this->import_log->wpvivid_write_import_log('Start importing terms.', 'notice');
949
- if ( empty( $this->terms ) ) {
950
- $this->import_log->wpvivid_write_import_log('Terms import is completed.', 'notice');
951
- return $ret;
952
- }
953
-
954
- foreach ( $this->terms as $term )
955
- {
956
- // if the term already exists in the correct taxonomy leave it alone
957
- $term_id = term_exists( $term['slug'], $term['term_taxonomy'] );
958
- if ( $term_id ) {
959
- if ( is_array($term_id) ) $term_id = $term_id['term_id'];
960
- if ( isset($term['term_id']) )
961
- $this->processed_terms[intval($term['term_id'])] = (int) $term_id;
962
- continue;
963
- }
964
-
965
- if ( empty( $term['term_parent'] ) ) {
966
- $parent = 0;
967
- } else {
968
- $parent = term_exists( $term['term_parent'], $term['term_taxonomy'] );
969
- if ( is_array( $parent ) ) $parent = $parent['term_id'];
970
- }
971
- $term = wp_slash( $term );
972
- $description = isset( $term['term_description'] ) ? $term['term_description'] : '';
973
- $termarr = array( 'slug' => $term['slug'], 'description' => $description, 'parent' => intval($parent) );
974
-
975
- $id = wp_insert_term( $term['term_name'], $term['term_taxonomy'], $termarr );
976
- if ( ! is_wp_error( $id ) ) {
977
- if ( isset($term['term_id']) )
978
- $this->processed_terms[intval($term['term_id'])] = $id['term_id'];
979
- } else {
980
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
981
- {
982
- $this->import_log->wpvivid_write_import_log('Failed to import terms, error: '.$id->get_error_message(), 'notice');
983
- $ret['result']='failed';
984
- $ret['error']='Failed to import '.$term['term_taxonomy'].' '.$term['term_name'].' '.$id->get_error_message();
985
- return $ret;
986
- }
987
-
988
- continue;
989
- }
990
-
991
- $this->process_termmeta( $term, $id['term_id'] );
992
- }
993
-
994
- unset( $this->terms );
995
- $this->import_log->wpvivid_write_import_log('Terms import is completed.', 'notice');
996
- return $ret;
997
- }
998
-
999
- private function process_posts_ex($update_exist=false)
1000
- {
1001
- $this->import_log->wpvivid_write_import_log('Start importing posts.', 'notice');
1002
- $ret['result']='success';
1003
- $this->posts = apply_filters( 'wp_import_posts', $this->posts );
1004
-
1005
- foreach ( $this->posts as $post )
1006
- {
1007
- $this->import_log->wpvivid_write_import_log('Post id: '.$post['post_id'], 'notice');
1008
- $post = apply_filters( 'wp_import_post_data_raw', $post );
1009
- $post_type_object = get_post_type_object( $post['post_type'] );
1010
- $post_exists = post_exists( $post['post_title'], '', $post['post_date'] );
1011
- $post_exists = apply_filters( 'wp_import_existing_post', $post_exists, $post );
1012
- if ( $post_exists && get_post_type( $post_exists ) == $post['post_type'] )
1013
- {
1014
- $this->import_log->wpvivid_write_import_log('The post already exists.', 'notice');
1015
- $comment_post_ID=$post_id = $post_exists;
1016
- $this->processed_posts[ intval( $post['post_id'] ) ] = intval( $post_exists );
1017
-
1018
- if($update_exist)
1019
- {
1020
- $post_parent = (int) $post['post_parent'];
1021
- if ( $post_parent )
1022
- {
1023
- // if we already know the parent, map it to the new local ID
1024
- if ( isset( $this->processed_posts[$post_parent] ) )
1025
- {
1026
- $post_parent = $this->processed_posts[$post_parent];
1027
- // otherwise record the parent for later
1028
- } else {
1029
- $this->post_orphans[intval($post['post_id'])] = $post_parent;
1030
- $post_parent = 0;
1031
- }
1032
- }
1033
- $author = sanitize_user( $post['post_author'], true );
1034
- if ( isset( $this->author_mapping[$author] ) ) {
1035
- $author = $this->author_mapping[$author];
1036
- }
1037
- else {
1038
- $author = (int)$this->default_user;
1039
- }
1040
-
1041
- $postdata = array(
1042
- 'ID' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'],
1043
- 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'],
1044
- 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'],
1045
- 'post_status' => $post['status'], 'post_name' => $post['post_name'],
1046
- 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'],
1047
- 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'],
1048
- 'post_type' => $post['post_type'], 'post_password' => $post['post_password']
1049
- );
1050
-
1051
- wp_update_post($postdata);
1052
-
1053
- if ( ! empty( $post['postmeta'] ) )
1054
- {
1055
- foreach ( $post['postmeta'] as $meta )
1056
- {
1057
- $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post );
1058
- $value = false;
1059
-
1060
- if ( '_edit_last' == $key )
1061
- {
1062
- if ( isset( $this->processed_authors[intval($meta['value'])] ) )
1063
- $value = $this->processed_authors[intval($meta['value'])];
1064
- else
1065
- $key = false;
1066
- }
1067
-
1068
- if ( $key )
1069
- {
1070
- // export gets meta straight from the DB so could have a serialized string
1071
- if ( ! $value )
1072
- $value = maybe_unserialize( $meta['value'] );
1073
- if(metadata_exists('post', $post_id, $key))
1074
- {
1075
- update_post_meta($post_id,$key,$value);
1076
- }
1077
- else
1078
- {
1079
- add_post_meta( $post_id, $key, $value );
1080
- }
1081
-
1082
-
1083
- do_action( 'import_post_meta', $post_id, $key, $value );
1084
-
1085
- // if the post has a featured image, take note of this in case of remap
1086
- if ( '_thumbnail_id' == $key )
1087
- $this->featured_images[$post_id] = (int) $value;
1088
- }
1089
- }
1090
- }
1091
- }
1092
-
1093
- } else {
1094
- $post_parent = (int) $post['post_parent'];
1095
- if ( $post_parent )
1096
- {
1097
- // if we already know the parent, map it to the new local ID
1098
- if ( isset( $this->processed_posts[$post_parent] ) )
1099
- {
1100
- $post_parent = $this->processed_posts[$post_parent];
1101
- // otherwise record the parent for later
1102
- } else {
1103
- $this->post_orphans[intval($post['post_id'])] = $post_parent;
1104
- $post_parent = 0;
1105
- }
1106
- }
1107
- // map the post author
1108
- $author = sanitize_user( $post['post_author'], true );
1109
- if ( isset( $this->author_mapping[$author] ) ) {
1110
- $author = $this->author_mapping[$author];
1111
- }
1112
- else {
1113
- $author = (int)$this->default_user;
1114
- }
1115
- $postdata = array(
1116
- 'import_id' => $post['post_id'], 'post_author' => $author, 'post_date' => $post['post_date'],
1117
- 'post_date_gmt' => $post['post_date_gmt'], 'post_content' => $post['post_content'],
1118
- 'post_excerpt' => $post['post_excerpt'], 'post_title' => $post['post_title'],
1119
- 'post_status' => $post['status'], 'post_name' => $post['post_name'],
1120
- 'comment_status' => $post['comment_status'], 'ping_status' => $post['ping_status'],
1121
- 'guid' => $post['guid'], 'post_parent' => $post_parent, 'menu_order' => $post['menu_order'],
1122
- 'post_type' => $post['post_type'], 'post_password' => $post['post_password']
1123
- );
1124
- $original_post_ID = $post['post_id'];
1125
- $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
1126
- $postdata = wp_slash( $postdata );
1127
- if ( 'attachment' == $postdata['post_type'] )
1128
- {
1129
- $remote_url = ! empty($post['attachment_url']) ? $post['attachment_url'] : $post['guid'];
1130
- // try to use _wp_attached file for upload folder placement to ensure the same location as the export site
1131
- // e.g. location is 2003/05/image.jpg but the attachment post_date is 2010/09, see media_handle_upload()
1132
- $postdata['upload_date'] = $post['post_date'];
1133
- if ( isset( $post['postmeta'] ) )
1134
- {
1135
- foreach( $post['postmeta'] as $meta )
1136
- {
1137
- if ( $meta['key'] == '_wp_attached_file' ) {
1138
- if ( preg_match( '%^[0-9]{4}/[0-9]{2}%', $meta['value'], $matches ) )
1139
- $postdata['upload_date'] = $matches[0];
1140
- break;
1141
- }
1142
- }
1143
- $postmeta=$post['postmeta'];
1144
- }
1145
- else
1146
- {
1147
- $postmeta=false;
1148
- }
1149
-
1150
- $comment_post_ID = $post_id = $this->process_attachment_ex( $postdata, $remote_url ,$postmeta);
1151
- } else {
1152
- $comment_post_ID =$post_id = wp_insert_post( $postdata, true );
1153
- do_action( 'wp_import_insert_post', $post_id, $original_post_ID, $postdata, $post );
1154
- }
1155
- if ( is_wp_error( $post_id ) )
1156
- {
1157
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
1158
- {
1159
- $ret['result']='failed';
1160
- $ret['error']='Failed to import '.$post_type_object->labels->singular_name.' '.$post['post_title'].' '.$post_id->get_error_message();
1161
- return $ret;
1162
- }
1163
- continue;
1164
- }
1165
- if ( $post['is_sticky'] == 1 )
1166
- stick_post( $post_id );
1167
- // map pre-import ID to local ID
1168
- $this->processed_posts[intval($post['post_id'])] = (int) $post_id;
1169
- }
1170
-
1171
- if($post_exists)
1172
- continue;
1173
-
1174
- if ( ! isset( $post['terms'] ) )
1175
- $post['terms'] = array();
1176
-
1177
- $post['terms'] = apply_filters( 'wp_import_post_terms', $post['terms'], $post_id, $post );
1178
-
1179
- // add categories, tags and other terms
1180
- if ( ! empty( $post['terms'] ) )
1181
- {
1182
- $terms_to_set = array();
1183
- foreach ( $post['terms'] as $term )
1184
- {
1185
- // back compat with WXR 1.0 map 'tag' to 'post_tag'
1186
- $taxonomy = ( 'tag' == $term['domain'] ) ? 'post_tag' : $term['domain'];
1187
- $term_exists = term_exists( $term['slug'], $taxonomy );
1188
- $term_id = is_array( $term_exists ) ? $term_exists['term_id'] : $term_exists;
1189
- if ( ! $term_id )
1190
- {
1191
- $t = wp_insert_term( $term['name'], $taxonomy, array( 'slug' => $term['slug'] ) );
1192
- if ( ! is_wp_error( $t ) )
1193
- {
1194
- $term_id = $t['term_id'];
1195
- do_action( 'wp_import_insert_term', $t, $term, $post_id, $post );
1196
- } else {
1197
- if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG )
1198
- {
1199
- $this->import_log->wpvivid_write_import_log('Failed to import post, error: '.$post_id->get_error_message(), 'notice');
1200
- $ret['result']='failed';
1201
- $ret['error']='Failed to import '.esc_html($taxonomy).' '.esc_html($term['name']).' '.$post_id->get_error_message();
1202
- return $ret;
1203
- }
1204
- continue;
1205
- }
1206
- }
1207
- $terms_to_set[$taxonomy][] = intval( $term_id );
1208
- }
1209
-
1210
- foreach ( $terms_to_set as $tax => $ids )
1211
- {
1212
- $tt_ids = wp_set_post_terms( $post_id, $ids, $tax );
1213
- do_action( 'wp_import_set_post_terms', $tt_ids, $ids, $tax, $post_id, $post );
1214
- }
1215
- unset( $post['terms'], $terms_to_set );
1216
- }
1217
-
1218
- if ( ! isset( $post['comments'] ) )
1219
- $post['comments'] = array();
1220
-
1221
- $post['comments'] = apply_filters( 'wp_import_post_comments', $post['comments'], $post_id, $post );
1222
-
1223
- // add/update comments
1224
- if ( ! empty( $post['comments'] ) )
1225
- {
1226
- $num_comments = 0;
1227
- $inserted_comments = array();
1228
- foreach ( $post['comments'] as $comment )
1229
- {
1230
- $comment_id = $comment['comment_id'];
1231
- $newcomments[$comment_id]['comment_post_ID'] = $comment_post_ID;
1232
- $newcomments[$comment_id]['comment_author'] = $comment['comment_author'];
1233
- $newcomments[$comment_id]['comment_author_email'] = $comment['comment_author_email'];
1234
- $newcomments[$comment_id]['comment_author_IP'] = $comment['comment_author_IP'];
1235
- $newcomments[$comment_id]['comment_author_url'] = $comment['comment_author_url'];
1236
- $newcomments[$comment_id]['comment_date'] = $comment['comment_date'];
1237
- $newcomments[$comment_id]['comment_date_gmt'] = $comment['comment_date_gmt'];
1238
- $newcomments[$comment_id]['comment_content'] = $comment['comment_content'];
1239
- $newcomments[$comment_id]['comment_approved'] = $comment['comment_approved'];
1240
- $newcomments[$comment_id]['comment_type'] = $comment['comment_type'];
1241
- $newcomments[$comment_id]['comment_parent'] = $comment['comment_parent'];
1242
- $newcomments[$comment_id]['commentmeta'] = isset( $comment['commentmeta'] ) ? $comment['commentmeta'] : array();
1243
- if ( isset( $this->processed_authors[$comment['comment_user_id']] ) )
1244
- $newcomments[$comment_id]['user_id'] = $this->processed_authors[$comment['comment_user_id']];
1245
- }
1246
- ksort( $newcomments );
1247
-
1248
- foreach ( $newcomments as $key => $comment )
1249
- {
1250
- // if this is a new post we can skip the comment_exists() check
1251
- if ( ! $post_exists || ! comment_exists( $comment['comment_author'], $comment['comment_date'] ) )
1252
- {
1253
- if ( isset( $inserted_comments[$comment['comment_parent']] ) )
1254
- $comment['comment_parent'] = $inserted_comments[$comment['comment_parent']];
1255
- $comment = wp_slash( $comment );
1256
- $comment = wp_filter_comment( $comment );
1257
- $inserted_comments[$key] = wp_insert_comment( $comment );
1258
- do_action( 'wp_import_insert_comment', $inserted_comments[$key], $comment, $comment_post_ID, $post );
1259
-
1260
- foreach( $comment['commentmeta'] as $meta ) {
1261
- $value = maybe_unserialize( $meta['value'] );
1262
- add_comment_meta( $inserted_comments[$key], $meta['key'], $value );
1263
- }
1264
-
1265
- $num_comments++;
1266
- }
1267
- }
1268
- unset( $newcomments, $inserted_comments, $post['comments'] );
1269
- }
1270
-
1271
- if ( ! isset( $post['postmeta'] ) )
1272
- $post['postmeta'] = array();
1273
-
1274
- $post['postmeta'] = apply_filters( 'wp_import_post_meta', $post['postmeta'], $post_id, $post );
1275
-
1276
- // add/update post meta
1277
- if ( ! empty( $post['postmeta'] ) )
1278
- {
1279
- foreach ( $post['postmeta'] as $meta )
1280
- {
1281
- $key = apply_filters( 'import_post_meta_key', $meta['key'], $post_id, $post );
1282
- $value = false;
1283
-
1284
- if ( '_edit_last' == $key )
1285
- {
1286
- if ( isset( $this->processed_authors[intval($meta['value'])] ) )
1287
- $value = $this->processed_authors[intval($meta['value'])];
1288
- else
1289
- $key = false;
1290
- }
1291
-
1292
- if ( $key )
1293
- {
1294
- // export gets meta straight from the DB so could have a serialized string
1295
- if ( ! $value )
1296
- $value = maybe_unserialize( $meta['value'] );
1297
- if(metadata_exists('post', $post_id, $key))
1298
- {
1299
- update_post_meta($post_id,$key,$value);
1300
- }
1301
- else
1302
- {
1303
- add_post_meta( $post_id, $key, $value );
1304
- }
1305
-
1306
-
1307
- do_action( 'import_post_meta', $post_id, $key, $value );
1308
-
1309
- // if the post has a featured image, take note of this in case of remap
1310
- if ( '_thumbnail_id' == $key )
1311
- $this->featured_images[$post_id] = (int) $value;
1312
- }
1313
- }
1314
- }
1315
- }
1316
-
1317
- unset( $this->posts );
1318
- $this->import_log->wpvivid_write_import_log('Posts import is completed.', 'notice');
1319
- return $ret;
1320
- }
1321
-
1322
- public function replace_domain()
1323
- {
1324
- $this->new_site_url= untrailingslashit(site_url());
1325
- $this->import_log->wpvivid_write_import_log('The original domain name: '.$this->base_url, 'notice');
1326
- $this->import_log->wpvivid_write_import_log('The current domain name: '.$this->new_site_url, 'notice');
1327
- if(empty($this->base_url))
1328
- {
1329
- $this->import_log->wpvivid_write_import_log('Failed to retrieve the original domain name: '.$this->base_url, 'notice');
1330
- return ;
1331
- }
1332
-
1333
- if(empty($this->processed_posts))
1334
- {
1335
- $this->import_log->wpvivid_write_import_log('The unimported posts', 'notice');
1336
- return ;
1337
- }
1338
-
1339
- if($this->base_url===$this->new_site_url)
1340
- {
1341
- $this->import_log->wpvivid_write_import_log('Replacing domain name is not required.', 'notice');
1342
- return ;
1343
- }
1344
-
1345
-
1346
- global $wp_query,$wpdb;
1347
- $this->import_log->wpvivid_write_import_log('Start replacing domain name.', 'notice');
1348
- $wp_query->in_the_loop = true;
1349
- while ( $next_posts = array_splice( $this->processed_posts, 0, 20 ) )
1350
- {
1351
- $where = 'WHERE ID IN (' . join(',', $next_posts) . ')';
1352
- $posts = $wpdb->get_results("SELECT * FROM {$wpdb->posts} $where");
1353
-
1354
- foreach ( $posts as $post )
1355
- {
1356
- $old_data=$post->post_content;
1357
- $new_data=$this->replace_row_data($old_data);
1358
- if($new_data==$old_data)
1359
- {
1360
- $this->import_log->wpvivid_write_import_log('Post ID '.$post->ID.' is not changed.', 'notice');
1361
- continue;
1362
- }
1363
- else
1364
- {
1365
- $this->import_log->wpvivid_write_import_log('Post ID '.$post->ID.' is changed.', 'notice');
1366
- }
1367
- $post->post_content=$new_data;
1368
- wp_update_post($post);
1369
- }
1370
- }
1371
- }
1372
-
1373
- private function replace_row_data($old_data)
1374
- {
1375
- $unserialize_data = @unserialize($old_data);
1376
- if($unserialize_data===false)
1377
- {
1378
- $old_data=$this->replace_string($old_data);
1379
- }
1380
- else
1381
- {
1382
- $old_data=$this->replace_serialize_data($unserialize_data);
1383
- $old_data=serialize($old_data);
1384
- /*if(is_array($unserialize_data))
1385
- {
1386
- $temp_data = array();
1387
- foreach ($unserialize_data as $key => $value)
1388
- {
1389
- $temp_data[$key]=$this->replace_string($value);
1390
- }
1391
-
1392
- $old_data = $temp_data;
1393
- unset($temp_data);
1394
- $old_data=$this->replace_serialize_data($unserialize_data);
1395
- $old_data=serialize($old_data);
1396
- }
1397
- else if(is_object($unserialize_data))
1398
- {
1399
- $temp_data = $unserialize_data;
1400
- $props = get_object_vars($unserialize_data);
1401
- foreach ($props as $key => $value)
1402
- {
1403
- $temp_data->$key =$this->replace_string($value);
1404
- }
1405
- $old_data = $temp_data;
1406
- unset($temp_data);
1407
- $old_data=serialize($old_data);
1408
- }*/
1409
- }
1410
-
1411
- return $old_data;
1412
- }
1413
-
1414
- private function replace_serialize_data($data)
1415
- {
1416
- if(is_string($data))
1417
- {
1418
- $serialize_data =@unserialize($data);
1419
- if($serialize_data===false)
1420
- {
1421
- $data=$this->replace_string($data);
1422
- }
1423
- else
1424
- {
1425
- $data=serialize($this->replace_serialize_data($serialize_data));
1426
- }
1427
- }
1428
- else if(is_array($data))
1429
- {
1430
- foreach ($data as $key => $value)
1431
- {
1432
- if(is_string($value))
1433
- {
1434
- $data[$key]=$this->replace_string($value);
1435
- }
1436
- else if(is_array($value))
1437
- {
1438
- $data[$key]=$this->replace_serialize_data($value);
1439
- }
1440
- else if(is_object($value))
1441
- {
1442
- if (is_a($value, '__PHP_Incomplete_Class'))
1443
- {
1444
- //
1445
- }
1446
- else
1447
- {
1448
- $data[$key]=$this->replace_serialize_data($value);
1449
- }
1450
- }
1451
- }
1452
- }
1453
- else if(is_object($data))
1454
- {
1455
- $temp = $data; // new $data_class();
1456
- if (is_a($data, '__PHP_Incomplete_Class'))
1457
- {
1458
-
1459
- }
1460
- else
1461
- {
1462
- $props = get_object_vars($data);
1463
- foreach ($props as $key => $value)
1464
- {
1465
- if(is_string($value))
1466
- {
1467
- $temp->$key =$this->replace_string($value);
1468
- }
1469
- else if(is_array($value))
1470
- {
1471
- $temp->$key=$this->replace_serialize_data($value);
1472
- }
1473
- else if(is_object($value))
1474
- {
1475
- $temp->$key=$this->replace_serialize_data($value);
1476
- }
1477
- }
1478
- }
1479
- $data = $temp;
1480
- unset($temp);
1481
- }
1482
-
1483
- return $data;
1484
- }
1485
-
1486
- private function replace_string($old_string)
1487
- {
1488
- if(!is_string($old_string))
1489
- {
1490
- return $old_string;
1491
- }
1492
-
1493
- if($this->base_url!=$this->new_site_url)
1494
- {
1495
- $remove_http_link=$this->get_remove_http_link($this->base_url);
1496
- $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
1497
- if(strpos($new_remove_http_link,$remove_http_link)!==false)
1498
- {
1499
- return $this->replace_string_ex($old_string);
1500
- }
1501
- }
1502
-
1503
- if($this->base_url!=$this->new_site_url)
1504
- {
1505
- $old_string=str_replace($this->base_url,$this->new_site_url,$old_string);
1506
- $old_mix_link=$this->get_mix_link($this->base_url);
1507
- if($old_mix_link!==false)
1508
- {
1509
- $old_string=str_replace($old_mix_link,$this->new_site_url,$old_string);
1510
- }
1511
- $remove_http_link=$this->get_remove_http_link($this->base_url);
1512
- if($remove_http_link!==false)
1513
- {
1514
- $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
1515
- $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1516
- }
1517
-
1518
- $remove_http_link=$this->get_remove_http_link_ex($this->base_url);
1519
- if($remove_http_link!==false)
1520
- {
1521
- $new_remove_http_link=$this->get_remove_http_link_ex($this->new_site_url);
1522
- $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1523
- }
1524
- }
1525
-
1526
- return $old_string;
1527
- }
1528
-
1529
- private function replace_string_ex($old_string)
1530
- {
1531
- if(!is_string($old_string))
1532
- {
1533
- return $old_string;
1534
- }
1535
-
1536
- if($this->base_url!=$this->new_site_url)
1537
- {
1538
- $remove_http_link=$this->get_remove_http_link($this->base_url);
1539
- if($remove_http_link!==false)
1540
- {
1541
- $new_remove_http_link=$this->get_remove_http_link($this->new_site_url);
1542
- $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1543
- }
1544
-
1545
- $new_mix_link=$this->get_mix_link($this->new_site_url);
1546
- if($new_mix_link!==false)
1547
- {
1548
- $old_string=str_replace($new_mix_link,$this->new_site_url,$old_string);
1549
- }
1550
-
1551
- $remove_http_link=$this->get_remove_http_link_ex($this->base_url);
1552
- if($remove_http_link!==false)
1553
- {
1554
- $new_remove_http_link=$this->get_remove_http_link_ex($this->new_site_url);
1555
- $old_string=str_replace($remove_http_link,$new_remove_http_link,$old_string);
1556
- }
1557
- }
1558
-
1559
- return $old_string;
1560
- }
1561
-
1562
- private function get_remove_http_link($url)
1563
- {
1564
- if (0 === stripos($url, 'https://'))
1565
- {
1566
- $mix_link = '//'.substr($url, 8);
1567
- } elseif (0 === stripos($url, 'http://')) {
1568
- $mix_link = '//'.substr($url, 7);
1569
- }
1570
- else
1571
- {
1572
- $mix_link=false;
1573
- }
1574
- return $mix_link;
1575
- }
1576
-
1577
- private function get_remove_http_link_ex($url)
1578
- {
1579
- if (0 === stripos($url, 'https://'))
1580
- {
1581
- $mix_link = '\/\/'.substr($url, 8);
1582
- } elseif (0 === stripos($url, 'http://')) {
1583
- $mix_link = '\/\/'.substr($url, 7);
1584
- }
1585
- else
1586
- {
1587
- $mix_link=false;
1588
- }
1589
- return $mix_link;
1590
- }
1591
-
1592
- private function get_mix_link($url)
1593
- {
1594
- if (0 === stripos($url, 'https://'))
1595
- {
1596
- $mix_link = 'http://'.substr($url, 8);
1597
- } elseif (0 === stripos($url, 'http://')) {
1598
- $mix_link = 'https://'.substr($url, 7);
1599
- }
1600
- else
1601
- {
1602
- $mix_link=false;
1603
- }
1604
- return $mix_link;
1605
- }
1606
-
1607
- function process_attachment_ex( $post, $url,$postmeta )
1608
- {
1609
- // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1610
- if ( preg_match( '|^/[\w\W]+$|', $url ) )
1611
- $url = rtrim( $this->base_url, '/' ) . $url;
1612
-
1613
- $upload = $this->fetch_local_file_ex( $url, $post ,$postmeta);
1614
- if ( is_wp_error( $upload ) )
1615
- return $upload;
1616
- $post['post_mime_type']=$upload['type'];
1617
-
1618
- $post['guid'] = $upload['url'];
1619
-
1620
- // as per wp-admin/includes/upload.php
1621
- $post_id = wp_insert_attachment( $post, $upload['file'] );
1622
-
1623
- if ( is_wp_error( $post_id ) )
1624
- {
1625
- return $post_id;
1626
- }
1627
-
1628
- if ( preg_match( '!^image/!',$upload['type'] ) )
1629
- {
1630
- $parts = pathinfo( $url );
1631
- $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1632
-
1633
- $parts_new = pathinfo( $upload['url'] );
1634
- $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
1635
-
1636
- $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
1637
- }
1638
-
1639
- return $post_id;
1640
- }
1641
-
1642
- function fetch_local_file_ex($url,$post,$postmeta)
1643
- {
1644
- $file_name = basename( $url );
1645
-
1646
- $upload = wp_upload_dir( $post['upload_date'] );
1647
-
1648
- $new_file='';
1649
- if($postmeta!==false)
1650
- {
1651
- foreach( $postmeta as $meta )
1652
- {
1653
- if ( $meta['key'] == '_wp_attached_file' )
1654
- {
1655
- $new_file=$upload['basedir'].'/'.$meta['meta_value'];
1656
- $url = $upload['baseurl'].'/'.$meta['meta_value'];
1657
- }
1658
- }
1659
- }
1660
-
1661
- if(empty($new_file))
1662
- {
1663
- $new_file = $upload['path'] . "/$file_name";
1664
- $url = $upload['url'] . "/$file_name";
1665
- }
1666
-
1667
- if(!file_exists($new_file))
1668
- {
1669
- return new WP_Error( 'import_file_error', __('File not exist, file:'.$new_file, 'wpvivid-backuprestore') );
1670
- }
1671
-
1672
- $wp_filetype = wp_check_filetype( $file_name );
1673
-
1674
- if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) )
1675
- {
1676
- return new WP_Error( 'import_file_error', __( 'Sorry, this file type is not permitted for security reasons.' ) );
1677
- }
1678
-
1679
- return apply_filters(
1680
- 'wp_handle_upload',
1681
- array(
1682
- 'file' => $new_file,
1683
- 'url' => $url,
1684
- 'type' => $wp_filetype['type'],
1685
- 'error' => false,
1686
- ),
1687
- 'sideload'
1688
- );
1689
- }
1690
-
1691
- function parse( $file ) {
1692
- $parser = new WPvivid_WXR_Parser();
1693
- return $parser->parse( $file );
1694
- }
1695
-
1696
- function get_authors_from_import( $import_data )
1697
- {
1698
- if ( ! empty( $import_data['authors'] ) )
1699
- {
1700
- $this->authors = $import_data['authors'];
1701
- // no author information, grab it from the posts
1702
- } else {
1703
- foreach ( $import_data['posts'] as $post )
1704
- {
1705
- $login = sanitize_user( $post['post_author'], true );
1706
- if ( empty( $login ) )
1707
- {
1708
- continue;
1709
- }
1710
-
1711
- if ( ! isset($this->authors[$login]) )
1712
- $this->authors[$login] = array(
1713
- 'author_login' => $login,
1714
- 'author_display_name' => $post['post_author']
1715
- );
1716
- }
1717
- }
1718
- }
1719
-
1720
- function process_attachment( $post, $url )
1721
- {
1722
- if ( ! $this->fetch_attachments )
1723
- return new WP_Error( 'attachment_processing_error',
1724
- __( 'Fetching attachments is not enabled', 'wpvivid-backuprestore' ) );
1725
-
1726
- // if the URL is absolute, but does not contain address, then upload it assuming base_site_url
1727
- if ( preg_match( '|^/[\w\W]+$|', $url ) )
1728
- $url = rtrim( $this->base_url, '/' ) . $url;
1729
-
1730
- $upload = $this->fetch_local_file( $url, $post );
1731
- if ( is_wp_error( $upload ) )
1732
- return $upload;
1733
-
1734
- if ( $info = wp_check_filetype( $upload['file'] ) )
1735
- $post['post_mime_type'] = $info['type'];
1736
- else
1737
- return new WP_Error( 'attachment_processing_error', __('Invalid file type', 'wpvivid-backuprestore') );
1738
-
1739
- $post['guid'] = $upload['url'];
1740
-
1741
- // as per wp-admin/includes/upload.php
1742
- $post_id = wp_insert_attachment( $post, $upload['file'] );
1743
-
1744
- if ( is_wp_error( $post_id ) )
1745
- {
1746
- echo 'error file:'.$upload['file'];
1747
- }
1748
-
1749
- //$metadata=wp_generate_attachment_metadata( $post_id, $upload['file'] );
1750
- //wp_update_attachment_metadata( $post_id,$metadata );
1751
-
1752
- // remap resized image URLs, works by stripping the extension and remapping the URL stub.
1753
- if ( preg_match( '!^image/!', $info['type'] ) ) {
1754
- $parts = pathinfo( $url );
1755
- $name = basename( $parts['basename'], ".{$parts['extension']}" ); // PATHINFO_FILENAME in PHP 5.2
1756
-
1757
- $parts_new = pathinfo( $upload['url'] );
1758
- $name_new = basename( $parts_new['basename'], ".{$parts_new['extension']}" );
1759
-
1760
- $this->url_remap[$parts['dirname'] . '/' . $name] = $parts_new['dirname'] . '/' . $name_new;
1761
- }
1762
-
1763
- return $post_id;
1764
- }
1765
-
1766
- function fetch_local_file($url,$post)
1767
- {
1768
- $file_name = basename( $url );
1769
-
1770
- $upload = wp_upload_dir( $post['upload_date'] );
1771
- $new_file = $upload['path'] . "/$file_name";
1772
- $url = $upload['url'] . "/$file_name";
1773
-
1774
- $wp_filetype = wp_check_filetype( $file_name );
1775
-
1776
- if ( ! $wp_filetype['ext'] && ! current_user_can( 'unfiltered_upload' ) ) {
1777
- return array( 'error' => __( 'Sorry, this file type is not permitted for security reasons.' ) );
1778
- }
1779
-
1780
- if(!file_exists($new_file))
1781
- {
1782
- return new WP_Error( 'import_file_error', __('File not exist file:'.$new_file, 'wpvivid-backuprestore') );
1783
- }
1784
-
1785
- return apply_filters(
1786
- 'wp_handle_upload',
1787
- array(
1788
- 'file' => $new_file,
1789
- 'url' => $url,
1790
- 'type' => $wp_filetype['type'],
1791
- 'error' => false,
1792
- ),
1793
- 'sideload'
1794
- );
1795
- }
1796
-
1797
- /**
1798
- * Performs post-import cleanup of files and the cache
1799
- */
1800
- function import_end()
1801
- {
1802
- wp_import_cleanup( $this->id );
1803
-
1804
- wp_cache_flush();
1805
- foreach ( get_taxonomies() as $tax ) {
1806
- delete_option( "{$tax}_children" );
1807
- _get_term_hierarchy( $tax );
1808
- }
1809
-
1810
- wp_defer_term_counting( false );
1811
- wp_defer_comment_counting( false );
1812
-
1813
- $ret['result']='success';
1814
-
1815
- do_action( 'import_end' );
1816
- return $ret;
1817
- }
1818
- }
1819
-
1820
- function wpvivid_function_pre_extract_import_callback($p_event, &$p_header)
1821
- {
1822
- global $xml_file_name;
1823
-
1824
- if(strpos($p_header['filename'],$xml_file_name)!==false)
1825
- {
1826
- return 0;
1827
- }
1828
-
1829
- if(strpos($p_header['filename'],'wpvivid_export_package_info.json')!==false)
1830
- {
1831
- return 0;
1832
- }
1833
-
1834
- return 1;
1835
- }
1836
-
1837
- /**
1838
- * WordPress Importer class for managing parsing of WXR files.
1839
- */
1840
- class WPvivid_WXR_Parser
1841
- {
1842
- function parse( $file )
1843
- {
1844
- // Attempt to use proper XML parsers first
1845
- if ( extension_loaded( 'simplexml' ) )
1846
- {
1847
- $parser = new WPvivid_WXR_Parser_SimpleXML;
1848
- $result = $parser->parse( $file );
1849
-
1850
- // If SimpleXML succeeds or this is an invalid WXR file then return the results
1851
- if ( ! is_wp_error( $result ) || 'SimpleXML_parse_error' != $result->get_error_code() )
1852
- return $result;
1853
- }
1854
- else if ( extension_loaded( 'xml' ) )
1855
- {
1856
- $parser = new WPvivid_WXR_Parser_XML;
1857
- $result = $parser->parse( $file );
1858
-
1859
- // If XMLParser succeeds or this is an invalid WXR file then return the results
1860
- if ( ! is_wp_error( $result ) || 'XML_parse_error' != $result->get_error_code() )
1861
- return $result;
1862
- }
1863
-
1864
- // We have a malformed XML file, so display the error and fallthrough to regex
1865
- if ( isset($result) && defined('IMPORT_DEBUG') && IMPORT_DEBUG )
1866
- {
1867
- $msg='';
1868
- if ( 'SimpleXML_parse_error' == $result->get_error_code() )
1869
- {
1870
- foreach ( $result->get_error_data() as $error )
1871
- $msg.= $error->line . ':' . $error->column . ' ' . esc_html( $error->message ) . "\n";
1872
- } else if ( 'XML_parse_error' == $result->get_error_code() )
1873
- {
1874
- $error = $result->get_error_data();
1875
- $msg.= $error[0] . ':' . $error[1] . ' ' . esc_html( $error[2] );
1876
- }
1877
- $msg.=__( 'There was an error when reading this WXR file', 'wpvivid-backuprestore' ) ;
1878
- $msg.=__( 'Details are shown above. The importer will now try again with a different parser...', 'wpvivid-backuprestore' );
1879
-
1880
- return new WP_Error( 'WXR_Parser_error', $msg,'' );
1881
- }
1882
-
1883
- // use regular expressions if nothing else available or this is bad XML
1884
- $parser = new WPvivid_WXR_Parser_Regex;
1885
- return $parser->parse( $file );
1886
- }
1887
- }
1888
-
1889
- /**
1890
- * WXR Parser that makes use of the SimpleXML PHP extension.
1891
- */
1892
- class WPvivid_WXR_Parser_SimpleXML
1893
- {
1894
- function parse( $file )
1895
- {
1896
- $authors = $posts = $categories = $tags = $terms = array();
1897
-
1898
- $internal_errors = libxml_use_internal_errors(true);
1899
-
1900
- $dom = new DOMDocument;
1901
- $old_value = null;
1902
- if ( function_exists( 'libxml_disable_entity_loader' ) ) {
1903
- $old_value = libxml_disable_entity_loader( true );
1904
- }
1905
- $success = $dom->loadXML( file_get_contents( $file ) );
1906
- if ( ! is_null( $old_value ) )
1907
- {
1908
- libxml_disable_entity_loader( $old_value );
1909
- }
1910
-
1911
- if ( ! $success || isset( $dom->doctype ) )
1912
- {
1913
- return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wpvivid-backuprestore' ), libxml_get_errors() );
1914
- }
1915
-
1916
- $xml = simplexml_import_dom( $dom );
1917
- unset( $dom );
1918
-
1919
- // halt if loading produces an error
1920
- if ( ! $xml )
1921
- return new WP_Error( 'SimpleXML_parse_error', __( 'There was an error when reading this WXR file', 'wpvivid-backuprestore' ), libxml_get_errors() );
1922
-
1923
- $wxr_version = $xml->xpath('/rss/channel/wp:wxr_version');
1924
- if ( ! $wxr_version )
1925
- return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wpvivid-backuprestore' ) );
1926
-
1927
- $wxr_version = (string) trim( $wxr_version[0] );
1928
- // confirm that we are dealing with the correct file format
1929
- if ( ! preg_match( '/^\d+\.\d+$/', $wxr_version ) )
1930
- return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wpvivid-backuprestore' ) );
1931
-
1932
- $base_url = $xml->xpath('/rss/channel/wp:base_site_url');
1933
- $base_url = (string) trim( $base_url[0] );
1934
-
1935
- $namespaces = $xml->getDocNamespaces();
1936
- if ( ! isset( $namespaces['wp'] ) )
1937
- $namespaces['wp'] = 'http://wordpress.org/export/1.1/';
1938
- if ( ! isset( $namespaces['excerpt'] ) )
1939
- $namespaces['excerpt'] = 'http://wordpress.org/export/1.1/excerpt/';
1940
-
1941
- // grab authors
1942
- foreach ( $xml->xpath('/rss/channel/wp:author') as $author_arr )
1943
- {
1944
- $a = $author_arr->children( $namespaces['wp'] );
1945
- $login = (string) $a->author_login;
1946
- $authors[$login] = array(
1947
- 'author_id' => (int) $a->author_id,
1948
- 'author_login' => $login,
1949
- 'author_email' => (string) $a->author_email,
1950
- 'author_display_name' => (string) $a->author_display_name,
1951
- 'author_first_name' => (string) $a->author_first_name,
1952
- 'author_last_name' => (string) $a->author_last_name
1953
- );
1954
- }
1955
-
1956
- // grab cats, tags and terms
1957
- foreach ( $xml->xpath('/rss/channel/wp:category') as $term_arr )
1958
- {
1959
- $t = $term_arr->children( $namespaces['wp'] );
1960
- $category = array(
1961
- 'term_id' => (int) $t->term_id,
1962
- 'category_nicename' => (string) $t->category_nicename,
1963
- 'category_parent' => (string) $t->category_parent,
1964
- 'cat_name' => (string) $t->cat_name,
1965
- 'category_description' => (string) $t->category_description
1966
- );
1967
-
1968
- foreach ( $t->termmeta as $meta ) {
1969
- $category['termmeta'][] = array(
1970
- 'key' => (string) $meta->meta_key,
1971
- 'value' => (string) $meta->meta_value
1972
- );
1973
- }
1974
-
1975
- $categories[] = $category;
1976
- }
1977
-
1978
- foreach ( $xml->xpath('/rss/channel/wp:tag') as $term_arr )
1979
- {
1980
- $t = $term_arr->children( $namespaces['wp'] );
1981
- $tag = array(
1982
- 'term_id' => (int) $t->term_id,
1983
- 'tag_slug' => (string) $t->tag_slug,
1984
- 'tag_name' => (string) $t->tag_name,
1985
- 'tag_description' => (string) $t->tag_description
1986
- );
1987
-
1988
- foreach ( $t->termmeta as $meta ) {
1989
- $tag['termmeta'][] = array(
1990
- 'key' => (string) $meta->meta_key,
1991
- 'value' => (string) $meta->meta_value
1992
- );
1993
- }
1994
-
1995
- $tags[] = $tag;
1996
- }
1997
-
1998
- foreach ( $xml->xpath('/rss/channel/wp:term') as $term_arr )
1999
- {
2000
- $t = $term_arr->children( $namespaces['wp'] );
2001
- $term = array(
2002
- 'term_id' => (int) $t->term_id,
2003
- 'term_taxonomy' => (string) $t->term_taxonomy,
2004
- 'slug' => (string) $t->term_slug,
2005
- 'term_parent' => (string) $t->term_parent,
2006
- 'term_name' => (string) $t->term_name,
2007
- 'term_description' => (string) $t->term_description
2008
- );
2009
-
2010
- foreach ( $t->termmeta as $meta ) {
2011
- $term['termmeta'][] = array(
2012
- 'key' => (string) $meta->meta_key,
2013
- 'value' => (string) $meta->meta_value
2014
- );
2015
- }
2016
-
2017
- $terms[] = $term;
2018
- }
2019
-
2020
- // grab posts
2021
- foreach ( $xml->channel->item as $item )
2022
- {
2023
- $post = array(
2024
- 'post_title' => (string) $item->title,
2025
- 'guid' => (string) $item->guid,
2026
- );
2027
-
2028
- $dc = $item->children( 'http://purl.org/dc/elements/1.1/' );
2029
- $post['post_author'] = (string) $dc->creator;
2030
-
2031
- $content = $item->children( 'http://purl.org/rss/1.0/modules/content/' );
2032
- $excerpt = $item->children( $namespaces['excerpt'] );
2033
- $post['post_content'] = (string) $content->encoded;
2034
- $post['post_excerpt'] = (string) $excerpt->encoded;
2035
-
2036
- $wp = $item->children( $namespaces['wp'] );
2037
- $post['post_id'] = (int) $wp->post_id;
2038
- $post['post_date'] = (string) $wp->post_date;
2039
- $post['post_date_gmt'] = (string) $wp->post_date_gmt;
2040
- $post['comment_status'] = (string) $wp->comment_status;
2041
- $post['ping_status'] = (string) $wp->ping_status;
2042
- $post['post_name'] = (string) $wp->post_name;
2043
- $post['status'] = (string) $wp->status;
2044
- $post['post_parent'] = (int) $wp->post_parent;
2045
- $post['menu_order'] = (int) $wp->menu_order;
2046
- $post['post_type'] = (string) $wp->post_type;
2047
- $post['post_password'] = (string) $wp->post_password;
2048
- $post['is_sticky'] = (int) $wp->is_sticky;
2049
-
2050
- if ( isset($wp->attachment_url) )
2051
- $post['attachment_url'] = (string) $wp->attachment_url;
2052
-
2053
- foreach ( $item->category as $c )
2054
- {
2055
- $att = $c->attributes();
2056
- if ( isset( $att['nicename'] ) )
2057
- $post['terms'][] = array(
2058
- 'name' => (string) $c,
2059
- 'slug' => (string) $att['nicename'],
2060
- 'domain' => (string) $att['domain']
2061
- );
2062
- }
2063
-
2064
- foreach ( $wp->postmeta as $meta )
2065
- {
2066
- $post['postmeta'][] = array(
2067
- 'key' => (string) $meta->meta_key,
2068
- 'value' => (string) $meta->meta_value
2069
- );
2070
- }
2071
-
2072
- foreach ( $wp->comment as $comment )
2073
- {
2074
- $meta = array();
2075
- if ( isset( $comment->commentmeta ) ) {
2076
- foreach ( $comment->commentmeta as $m ) {
2077
- $meta[] = array(
2078
- 'key' => (string) $m->meta_key,
2079
- 'value' => (string) $m->meta_value
2080
- );
2081
- }
2082
- }
2083
-
2084
- $post['comments'][] = array(
2085
- 'comment_id' => (int) $comment->comment_id,
2086
- 'comment_author' => (string) $comment->comment_author,
2087
- 'comment_author_email' => (string) $comment->comment_author_email,
2088
- 'comment_author_IP' => (string) $comment->comment_author_IP,
2089
- 'comment_author_url' => (string) $comment->comment_author_url,
2090
- 'comment_date' => (string) $comment->comment_date,
2091
- 'comment_date_gmt' => (string) $comment->comment_date_gmt,
2092
- 'comment_content' => (string) $comment->comment_content,
2093
- 'comment_approved' => (string) $comment->comment_approved,
2094
- 'comment_type' => (string) $comment->comment_type,
2095
- 'comment_parent' => (string) $comment->comment_parent,
2096
- 'comment_user_id' => (int) $comment->comment_user_id,
2097
- 'commentmeta' => $meta,
2098
- );
2099
- }
2100
-
2101
- $posts[] = $post;
2102
- }
2103
-
2104
- return array(
2105
- 'authors' => $authors,
2106
- 'posts' => $posts,
2107
- 'categories' => $categories,
2108
- 'tags' => $tags,
2109
- 'terms' => $terms,
2110
- 'base_url' => $base_url,
2111
- 'version' => $wxr_version
2112
- );
2113
- }
2114
- }
2115
-
2116
- /**
2117
- * WXR Parser that makes use of the XML Parser PHP extension.
2118
- */
2119
- class WPvivid_WXR_Parser_XML {
2120
- var $wp_tags = array(
2121
- 'wp:post_id', 'wp:post_date', 'wp:post_date_gmt', 'wp:comment_status', 'wp:ping_status', 'wp:attachment_url',
2122
- 'wp:status', 'wp:post_name', 'wp:post_parent', 'wp:menu_order', 'wp:post_type', 'wp:post_password',
2123
- 'wp:is_sticky', 'wp:term_id', 'wp:category_nicename', 'wp:category_parent', 'wp:cat_name', 'wp:category_description',
2124
- 'wp:tag_slug', 'wp:tag_name', 'wp:tag_description', 'wp:term_taxonomy', 'wp:term_parent',
2125
- 'wp:term_name', 'wp:term_description', 'wp:author_id', 'wp:author_login', 'wp:author_email', 'wp:author_display_name',
2126
- 'wp:author_first_name', 'wp:author_last_name',
2127
- );
2128
- var $wp_sub_tags = array(
2129
- 'wp:comment_id', 'wp:comment_author', 'wp:comment_author_email', 'wp:comment_author_url',
2130
- 'wp:comment_author_IP', 'wp:comment_date', 'wp:comment_date_gmt', 'wp:comment_content',
2131
- 'wp:comment_approved', 'wp:comment_type', 'wp:comment_parent', 'wp:comment_user_id',
2132
- );
2133
-
2134
- function parse( $file ) {
2135
- $this->wxr_version = $this->in_post = $this->cdata = $this->data = $this->sub_data = $this->in_tag = $this->in_sub_tag = false;
2136
- $this->authors = $this->posts = $this->term = $this->category = $this->tag = array();
2137
-
2138
- $xml = xml_parser_create( 'UTF-8' );
2139
- xml_parser_set_option( $xml, XML_OPTION_SKIP_WHITE, 1 );
2140
- xml_parser_set_option( $xml, XML_OPTION_CASE_FOLDING, 0 );
2141
- xml_set_object( $xml, $this );
2142
- xml_set_character_data_handler( $xml, 'cdata' );
2143
- xml_set_element_handler( $xml, 'tag_open', 'tag_close' );
2144
-
2145
- if ( ! xml_parse( $xml, file_get_contents( $file ), true ) ) {
2146
- $current_line = xml_get_current_line_number( $xml );
2147
- $current_column = xml_get_current_column_number( $xml );
2148
- $error_code = xml_get_error_code( $xml );
2149
- $error_string = xml_error_string( $error_code );
2150
- return new WP_Error( 'XML_parse_error', 'There was an error when reading this WXR file', array( $current_line, $current_column, $error_string ) );
2151
- }
2152
- xml_parser_free( $xml );
2153
-
2154
- if ( ! preg_match( '/^\d+\.\d+$/', $this->wxr_version ) )
2155
- return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wpvivid-backuprestore' ) );
2156
-
2157
- return array(
2158
- 'authors' => $this->authors,
2159
- 'posts' => $this->posts,
2160
- 'categories' => $this->category,
2161
- 'tags' => $this->tag,
2162
- 'terms' => $this->term,
2163
- 'base_url' => $this->base_url,
2164
- 'version' => $this->wxr_version
2165
- );
2166
- }
2167
-
2168
- function tag_open( $parse, $tag, $attr ) {
2169
- if ( in_array( $tag, $this->wp_tags ) ) {
2170
- $this->in_tag = substr( $tag, 3 );
2171
- return;
2172
- }
2173
-
2174
- if ( in_array( $tag, $this->wp_sub_tags ) ) {
2175
- $this->in_sub_tag = substr( $tag, 3 );
2176
- return;
2177
- }
2178
-
2179
- switch ( $tag ) {
2180
- case 'category':
2181
- if ( isset($attr['domain'], $attr['nicename']) ) {
2182
- $this->sub_data['domain'] = $attr['domain'];
2183
- $this->sub_data['slug'] = $attr['nicename'];
2184
- }
2185
- break;
2186
- case 'item': $this->in_post = true;
2187
- case 'title': if ( $this->in_post ) $this->in_tag = 'post_title'; break;
2188
- case 'guid': $this->in_tag = 'guid'; break;
2189
- case 'dc:creator': $this->in_tag = 'post_author'; break;
2190
- case 'content:encoded': $this->in_tag = 'post_content'; break;
2191
- case 'excerpt:encoded': $this->in_tag = 'post_excerpt'; break;
2192
-
2193
- case 'wp:term_slug': $this->in_tag = 'slug'; break;
2194
- case 'wp:meta_key': $this->in_sub_tag = 'key'; break;
2195
- case 'wp:meta_value': $this->in_sub_tag = 'value'; break;
2196
- }
2197
- }
2198
-
2199
- function cdata( $parser, $cdata ) {
2200
- if ( ! trim( $cdata ) )
2201
- return;
2202
-
2203
- if ( false !== $this->in_tag || false !== $this->in_sub_tag ) {
2204
- $this->cdata .= $cdata;
2205
- } else {
2206
- $this->cdata .= trim( $cdata );
2207
- }
2208
- }
2209
-
2210
- function tag_close( $parser, $tag ) {
2211
- switch ( $tag ) {
2212
- case 'wp:comment':
2213
- unset( $this->sub_data['key'], $this->sub_data['value'] ); // remove meta sub_data
2214
- if ( ! empty( $this->sub_data ) )
2215
- $this->data['comments'][] = $this->sub_data;
2216
- $this->sub_data = false;
2217
- break;
2218
- case 'wp:commentmeta':
2219
- $this->sub_data['commentmeta'][] = array(
2220
- 'key' => $this->sub_data['key'],
2221
- 'value' => $this->sub_data['value']
2222
- );
2223
- break;
2224
- case 'category':
2225
- if ( ! empty( $this->sub_data ) ) {
2226
- $this->sub_data['name'] = $this->cdata;
2227
- $this->data['terms'][] = $this->sub_data;
2228
- }
2229
- $this->sub_data = false;
2230
- break;
2231
- case 'wp:postmeta':
2232
- if ( ! empty( $this->sub_data ) )
2233
- $this->data['postmeta'][] = $this->sub_data;
2234
- $this->sub_data = false;
2235
- break;
2236
- case 'item':
2237
- $this->posts[] = $this->data;
2238
- $this->data = false;
2239
- break;
2240
- case 'wp:category':
2241
- case 'wp:tag':
2242
- case 'wp:term':
2243
- $n = substr( $tag, 3 );
2244
- array_push( $this->$n, $this->data );
2245
- $this->data = false;
2246
- break;
2247
- case 'wp:author':
2248
- if ( ! empty($this->data['author_login']) )
2249
- $this->authors[$this->data['author_login']] = $this->data;
2250
- $this->data = false;
2251
- break;
2252
- case 'wp:base_site_url':
2253
- $this->base_url = $this->cdata;
2254
- break;
2255
- case 'wp:wxr_version':
2256
- $this->wxr_version = $this->cdata;
2257
- break;
2258
-
2259
- default:
2260
- if ( $this->in_sub_tag ) {
2261
- $this->sub_data[$this->in_sub_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
2262
- $this->in_sub_tag = false;
2263
- } else if ( $this->in_tag ) {
2264
- $this->data[$this->in_tag] = ! empty( $this->cdata ) ? $this->cdata : '';
2265
- $this->in_tag = false;
2266
- }
2267
- }
2268
-
2269
- $this->cdata = false;
2270
- }
2271
- }
2272
-
2273
- /**
2274
- * WXR Parser that uses regular expressions. Fallback for installs without an XML parser.
2275
- */
2276
- class WPvivid_WXR_Parser_Regex {
2277
- var $authors = array();
2278
- var $posts = array();
2279
- var $categories = array();
2280
- var $tags = array();
2281
- var $terms = array();
2282
- var $base_url = '';
2283
-
2284
- function __construct() {
2285
- $this->has_gzip = is_callable( 'gzopen' );
2286
- }
2287
-
2288
- function parse( $file ) {
2289
- $wxr_version = $in_multiline = false;
2290
-
2291
- $multiline_content = '';
2292
-
2293
- $multiline_tags = array(
2294
- 'item' => array( 'posts', array( $this, 'process_post' ) ),
2295
- 'wp:category' => array( 'categories', array( $this, 'process_category' ) ),
2296
- 'wp:tag' => array( 'tags', array( $this, 'process_tag' ) ),
2297
- 'wp:term' => array( 'terms', array( $this, 'process_term' ) ),
2298
- );
2299
-
2300
- $fp = $this->fopen( $file, 'r' );
2301
- if ( $fp ) {
2302
- while ( ! $this->feof( $fp ) ) {
2303
- $importline = rtrim( $this->fgets( $fp ) );
2304
-
2305
- if ( ! $wxr_version && preg_match( '|<wp:wxr_version>(\d+\.\d+)</wp:wxr_version>|', $importline, $version ) )
2306
- $wxr_version = $version[1];
2307
-
2308
- if ( false !== strpos( $importline, '<wp:base_site_url>' ) ) {
2309
- preg_match( '|<wp:base_site_url>(.*?)</wp:base_site_url>|is', $importline, $url );
2310
- $this->base_url = $url[1];
2311
- continue;
2312
- }
2313
-
2314
- if ( false !== strpos( $importline, '<wp:author>' ) ) {
2315
- preg_match( '|<wp:author>(.*?)</wp:author>|is', $importline, $author );
2316
- $a = $this->process_author( $author[1] );
2317
- $this->authors[$a['author_login']] = $a;
2318
- continue;
2319
- }
2320
-
2321
- foreach ( $multiline_tags as $tag => $handler ) {
2322
- // Handle multi-line tags on a singular line
2323
- if ( preg_match( '|<' . $tag . '>(.*?)</' . $tag . '>|is', $importline, $matches ) ) {
2324
- $this->{$handler[0]}[] = call_user_func( $handler[1], $matches[1] );
2325
-
2326
- } elseif ( false !== ( $pos = strpos( $importline, "<$tag>" ) ) ) {
2327
- // Take note of any content after the opening tag
2328
- $multiline_content = trim( substr( $importline, $pos + strlen( $tag ) + 2 ) );
2329
-
2330
- // We don't want to have this line added to `$is_multiline` below.
2331
- $importline = '';
2332
- $in_multiline = $tag;
2333
-
2334
- } elseif ( false !== ( $pos = strpos( $importline, "</$tag>" ) ) ) {
2335
- $in_multiline = false;
2336
- $multiline_content .= trim( substr( $importline, 0, $pos ) );
2337
-
2338
- $this->{$handler[0]}[] = call_user_func( $handler[1], $multiline_content );
2339
- }
2340
- }
2341
-
2342
- if ( $in_multiline && $importline ) {
2343
- $multiline_content .= $importline . "\n";
2344
- }
2345
- }
2346
-
2347
- $this->fclose($fp);
2348
- }
2349
-
2350
- if ( ! $wxr_version )
2351
- return new WP_Error( 'WXR_parse_error', __( 'This does not appear to be a WXR file, missing/invalid WXR version number', 'wpvivid-backuprestore' ) );
2352
-
2353
- return array(
2354
- 'authors' => $this->authors,
2355
- 'posts' => $this->posts,
2356
- 'categories' => $this->categories,
2357
- 'tags' => $this->tags,
2358
- 'terms' => $this->terms,
2359
- 'base_url' => $this->base_url,
2360
- 'version' => $wxr_version
2361
- );
2362
- }
2363
-
2364
- function get_tag( $string, $tag ) {
2365
- preg_match( "|<$tag.*?>(.*?)</$tag>|is", $string, $return );
2366
- if ( isset( $return[1] ) ) {
2367
- if ( substr( $return[1], 0, 9 ) == '<![CDATA[' ) {
2368
- if ( strpos( $return[1], ']]]]><![CDATA[>' ) !== false ) {
2369
- preg_match_all( '|<!\[CDATA\[(.*?)\]\]>|s', $return[1], $matches );
2370
- $return = '';
2371
- foreach( $matches[1] as $match )
2372
- $return .= $match;
2373
- } else {
2374
- $return = preg_replace( '|^<!\[CDATA\[(.*)\]\]>$|s', '$1', $return[1] );
2375
- }
2376
- } else {
2377
- $return = $return[1];
2378
- }
2379
- } else {
2380
- $return = '';
2381
- }
2382
- return $return;
2383
- }
2384
-
2385
- function process_category( $c ) {
2386
- return array(
2387
- 'term_id' => $this->get_tag( $c, 'wp:term_id' ),
2388
- 'cat_name' => $this->get_tag( $c, 'wp:cat_name' ),
2389
- 'category_nicename' => $this->get_tag( $c, 'wp:category_nicename' ),
2390
- 'category_parent' => $this->get_tag( $c, 'wp:category_parent' ),
2391
- 'category_description' => $this->get_tag( $c, 'wp:category_description' ),
2392
- );
2393
- }
2394
-
2395
- function process_tag( $t ) {
2396
- return array(
2397
- 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
2398
- 'tag_name' => $this->get_tag( $t, 'wp:tag_name' ),
2399
- 'tag_slug' => $this->get_tag( $t, 'wp:tag_slug' ),
2400
- 'tag_description' => $this->get_tag( $t, 'wp:tag_description' ),
2401
- );
2402
- }
2403
-
2404
- function process_term( $t ) {
2405
- return array(
2406
- 'term_id' => $this->get_tag( $t, 'wp:term_id' ),
2407
- 'term_taxonomy' => $this->get_tag( $t, 'wp:term_taxonomy' ),
2408
- 'slug' => $this->get_tag( $t, 'wp:term_slug' ),
2409
- 'term_parent' => $this->get_tag( $t, 'wp:term_parent' ),
2410
- 'term_name' => $this->get_tag( $t, 'wp:term_name' ),
2411
- 'term_description' => $this->get_tag( $t, 'wp:term_description' ),
2412
- );
2413
- }
2414
-
2415
- function process_author( $a ) {
2416
- return array(
2417
- 'author_id' => $this->get_tag( $a, 'wp:author_id' ),
2418
- 'author_login' => $this->get_tag( $a, 'wp:author_login' ),
2419
- 'author_email' => $this->get_tag( $a, 'wp:author_email' ),
2420
- 'author_display_name' => $this->get_tag( $a, 'wp:author_display_name' ),
2421
- 'author_first_name' => $this->get_tag( $a, 'wp:author_first_name' ),
2422
- 'author_last_name' => $this->get_tag( $a, 'wp:author_last_name' ),
2423
- );
2424
- }
2425
-
2426
- function process_post( $post ) {
2427
- $post_id = $this->get_tag( $post, 'wp:post_id' );
2428
- $post_title = $this->get_tag( $post, 'title' );
2429
- $post_date = $this->get_tag( $post, 'wp:post_date' );
2430
- $post_date_gmt = $this->get_tag( $post, 'wp:post_date_gmt' );
2431
- $comment_status = $this->get_tag( $post, 'wp:comment_status' );
2432
- $ping_status = $this->get_tag( $post, 'wp:ping_status' );
2433
- $status = $this->get_tag( $post, 'wp:status' );
2434
- $post_name = $this->get_tag( $post, 'wp:post_name' );
2435
- $post_parent = $this->get_tag( $post, 'wp:post_parent' );
2436
- $menu_order = $this->get_tag( $post, 'wp:menu_order' );
2437
- $post_type = $this->get_tag( $post, 'wp:post_type' );
2438
- $post_password = $this->get_tag( $post, 'wp:post_password' );
2439
- $is_sticky = $this->get_tag( $post, 'wp:is_sticky' );
2440
- $guid = $this->get_tag( $post, 'guid' );
2441
- $post_author = $this->get_tag( $post, 'dc:creator' );
2442
-
2443
- $post_excerpt = $this->get_tag( $post, 'excerpt:encoded' );
2444
- $post_excerpt = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_excerpt );
2445
- $post_excerpt = str_replace( '<br>', '<br />', $post_excerpt );
2446
- $post_excerpt = str_replace( '<hr>', '<hr />', $post_excerpt );
2447
-
2448
- $post_content = $this->get_tag( $post, 'content:encoded' );
2449
- $post_content = preg_replace_callback( '|<(/?[A-Z]+)|', array( &$this, '_normalize_tag' ), $post_content );
2450
- $post_content = str_replace( '<br>', '<br />', $post_content );
2451
- $post_content = str_replace( '<hr>', '<hr />', $post_content );
2452
-
2453
- $postdata = compact( 'post_id', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_excerpt',
2454
- 'post_title', 'status', 'post_name', 'comment_status', 'ping_status', 'guid', 'post_parent',
2455
- 'menu_order', 'post_type', 'post_password', 'is_sticky'
2456
- );
2457
-
2458
- $attachment_url = $this->get_tag( $post, 'wp:attachment_url' );
2459
- if ( $attachment_url )
2460
- $postdata['attachment_url'] = $attachment_url;
2461
-
2462
- preg_match_all( '|<category domain="([^"]+?)" nicename="([^"]+?)">(.+?)</category>|is', $post, $terms, PREG_SET_ORDER );
2463
- foreach ( $terms as $t ) {
2464
- $post_terms[] = array(
2465
- 'slug' => $t[2],
2466
- 'domain' => $t[1],
2467
- 'name' => str_replace( array( '<![CDATA[', ']]>' ), '', $t[3] ),
2468
- );
2469
- }
2470
- if ( ! empty( $post_terms ) ) $postdata['terms'] = $post_terms;
2471
-
2472
- preg_match_all( '|<wp:comment>(.+?)</wp:comment>|is', $post, $comments );
2473
- $comments = $comments[1];
2474
- if ( $comments ) {
2475
- foreach ( $comments as $comment ) {
2476
- preg_match_all( '|<wp:commentmeta>(.+?)</wp:commentmeta>|is', $comment, $commentmeta );
2477
- $commentmeta = $commentmeta[1];
2478
- $c_meta = array();
2479
- foreach ( $commentmeta as $m ) {
2480
- $c_meta[] = array(
2481
- 'key' => $this->get_tag( $m, 'wp:meta_key' ),
2482
- 'value' => $this->get_tag( $m, 'wp:meta_value' ),
2483
- );
2484
- }
2485
-
2486
- $post_comments[] = array(
2487
- 'comment_id' => $this->get_tag( $comment, 'wp:comment_id' ),
2488
- 'comment_author' => $this->get_tag( $comment, 'wp:comment_author' ),
2489
- 'comment_author_email' => $this->get_tag( $comment, 'wp:comment_author_email' ),
2490
- 'comment_author_IP' => $this->get_tag( $comment, 'wp:comment_author_IP' ),
2491
- 'comment_author_url' => $this->get_tag( $comment, 'wp:comment_author_url' ),
2492
- 'comment_date' => $this->get_tag( $comment, 'wp:comment_date' ),
2493
- 'comment_date_gmt' => $this->get_tag( $comment, 'wp:comment_date_gmt' ),
2494
- 'comment_content' => $this->get_tag( $comment, 'wp:comment_content' ),
2495
- 'comment_approved' => $this->get_tag( $comment, 'wp:comment_approved' ),
2496
- 'comment_type' => $this->get_tag( $comment, 'wp:comment_type' ),
2497
- 'comment_parent' => $this->get_tag( $comment, 'wp:comment_parent' ),
2498
- 'comment_user_id' => $this->get_tag( $comment, 'wp:comment_user_id' ),
2499
- 'commentmeta' => $c_meta,
2500
- );
2501
- }
2502
- }
2503
- if ( ! empty( $post_comments ) ) $postdata['comments'] = $post_comments;
2504
-
2505
- preg_match_all( '|<wp:postmeta>(.+?)</wp:postmeta>|is', $post, $postmeta );
2506
- $postmeta = $postmeta[1];
2507
- if ( $postmeta ) {
2508
- foreach ( $postmeta as $p ) {
2509
- $post_postmeta[] = array(
2510
- 'key' => $this->get_tag( $p, 'wp:meta_key' ),
2511
- 'value' => $this->get_tag( $p, 'wp:meta_value' ),
2512
- );
2513
- }
2514
- }
2515
- if ( ! empty( $post_postmeta ) ) $postdata['postmeta'] = $post_postmeta;
2516
-
2517
- return $postdata;
2518
- }
2519
-
2520
- function _normalize_tag( $matches ) {
2521
- return '<' . strtolower( $matches[1] );
2522
- }
2523
-
2524
- function fopen( $filename, $mode = 'r' ) {
2525
- if ( $this->has_gzip )
2526
- return gzopen( $filename, $mode );
2527
- return fopen( $filename, $mode );
2528
- }
2529
-
2530
- function feof( $fp ) {
2531
- if ( $this->has_gzip )
2532
- return gzeof( $fp );
2533
- return feof( $fp );
2534
- }
2535
-
2536
- function fgets( $fp, $len = 8192 ) {
2537
- if ( $this->has_gzip )
2538
- return gzgets( $fp, $len );
2539
- return fgets( $fp, $len );
2540
- }
2541
-
2542
- function fclose( $fp ) {
2543
- if ( $this->has_gzip )
2544
- return gzclose( $fp );
2545
- return fclose( $fp );
2546
- }
2547
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-interface-mainwp.php DELETED
@@ -1,547 +0,0 @@
1
- <?php
2
-
3
- class WPvivid_Interface_MainWP
4
- {
5
- public function __construct(){
6
- $this->load_wpvivid_mainwp_backup_filter();
7
- $this->load_wpvivid_mainwp_side_bar_filter();
8
- $this->load_wpvivid_mainwp_backup_list_filter();
9
- $this->load_wpvivid_mainwp_schedule_filter();
10
- $this->load_wpvivid_mainwp_setting_filter();
11
- $this->load_wpvivid_mainwp_remote_filter();
12
- }
13
-
14
- public function load_wpvivid_mainwp_backup_filter(){
15
- add_filter('wpvivid_get_status_mainwp', array($this, 'wpvivid_get_status_mainwp'));
16
- add_filter('wpvivid_get_backup_list_mainwp', array($this, 'wpvivid_get_backup_list_mainwp'));
17
- add_filter('wpvivid_get_backup_schedule_mainwp', array($this, 'wpvivid_get_backup_schedule_mainwp'));
18
- add_filter('wpvivid_get_default_remote_mainwp', array($this, 'wpvivid_get_default_remote_mainwp'));
19
- add_filter('wpvivid_prepare_backup_mainwp', array($this, 'wpvivid_prepare_backup_mainwp'));
20
- add_filter('wpvivid_backup_now_mainwp', array($this, 'wpvivid_backup_now_mainwp'));
21
- add_filter('wpvivid_view_backup_task_log_mainwp', array($this, 'wpvivid_view_backup_task_log_mainwp'));
22
- add_filter('wpvivid_backup_cancel_mainwp', array($this, 'wpvivid_backup_cancel_mainwp'));
23
- add_filter('wpvivid_set_backup_report_addon_mainwp', array($this, 'wpvivid_set_backup_report_addon_mainwp'));
24
- }
25
-
26
- public function load_wpvivid_mainwp_side_bar_filter(){
27
- add_filter('wpvivid_read_last_backup_log_mainwp', array($this, 'wpvivid_read_last_backup_log_mainwp'));
28
- }
29
-
30
- public function load_wpvivid_mainwp_backup_list_filter(){
31
- add_filter('wpvivid_set_security_lock_mainwp', array($this, 'wpvivid_set_security_lock_mainwp'));
32
- add_filter('wpvivid_view_log_mainwp', array($this, 'wpvivid_view_log_mainwp'));
33
- add_filter('wpvivid_init_download_page_mainwp', array($this, 'wpvivid_init_download_page_mainwp'));
34
- add_filter('wpvivid_prepare_download_backup_mainwp', array($this, 'wpvivid_prepare_download_backup_mainwp'));
35
- add_filter('wpvivid_get_download_task_mainwp', array($this, 'wpvivid_get_download_task_mainwp'));
36
- add_filter('wpvivid_download_backup_mainwp', array($this, 'wpvivid_download_backup_mainwp'));
37
- add_filter('wpvivid_delete_backup_mainwp', array($this, 'wpvivid_delete_backup_mainwp'));
38
- add_filter('wpvivid_delete_backup_array_mainwp', array($this, 'wpvivid_delete_backup_array_mainwp'));
39
- }
40
-
41
- public function load_wpvivid_mainwp_schedule_filter(){
42
- add_filter('wpvivid_set_schedule_mainwp', array($this, 'wpvivid_set_schedule_mainwp'));
43
- }
44
-
45
- public function load_wpvivid_mainwp_setting_filter(){
46
- add_filter('wpvivid_set_general_setting_mainwp', array($this, 'wpvivid_set_general_setting_mainwp'));
47
- }
48
-
49
- public function load_wpvivid_mainwp_remote_filter(){
50
- add_filter('wpvivid_set_remote_mainwp', array($this, 'wpvivid_set_remote_mainwp'));
51
- }
52
-
53
- public function wpvivid_get_status_mainwp($data){
54
- $ret['result']='success';
55
- $list_tasks=array();
56
- $tasks=WPvivid_Setting::get_tasks();
57
- foreach ($tasks as $task)
58
- {
59
- $backup = new WPvivid_Backup_Task($task['id']);
60
- $list_tasks[$task['id']]=$backup->get_backup_task_info($task['id']);
61
- if($list_tasks[$task['id']]['task_info']['need_update_last_task']===true){
62
- $task_msg = WPvivid_taskmanager::get_task($task['id']);
63
- WPvivid_Setting::update_option('wpvivid_last_msg',$task_msg);
64
- apply_filters('wpvivid_set_backup_report_addon_mainwp', $task_msg);
65
- }
66
- }
67
- $ret['wpvivid']['task']=$list_tasks;
68
- $backuplist=WPvivid_Backuplist::get_backuplist();
69
- $schedule=WPvivid_Schedule::get_schedule();
70
- $ret['wpvivid']['backup_list']=$backuplist;
71
- $ret['wpvivid']['schedule']=$schedule;
72
- $ret['wpvivid']['schedule']['last_message']=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg');
73
- WPvivid_taskmanager::delete_marked_task();
74
- return $ret;
75
- }
76
-
77
- public function wpvivid_get_backup_list_mainwp($data){
78
- $backuplist=WPvivid_Backuplist::get_backuplist();
79
- $ret['result']='success';
80
- $ret['wpvivid']['backup_list']=$backuplist;
81
- return $ret;
82
- }
83
-
84
- public function wpvivid_get_backup_schedule_mainwp($data){
85
- $schedule=WPvivid_Schedule::get_schedule();
86
- $ret['result']='success';
87
- $ret['wpvivid']['schedule']=$schedule;
88
- $ret['wpvivid']['schedule']['last_message']=WPvivid_Setting::get_last_backup_message('wpvivid_last_msg');
89
- return $ret;
90
- }
91
-
92
- public function wpvivid_get_default_remote_mainwp($data){
93
- global $wpvivid_plugin;
94
- $ret['result']='success';
95
- $ret['remote_storage_type']=$wpvivid_plugin->function_realize->_get_default_remote_storage();
96
- return $ret;
97
- }
98
-
99
- public function wpvivid_prepare_backup_mainwp($data){
100
- $backup_options = $data['backup'];
101
- global $wpvivid_plugin;
102
- if(isset($backup_options)&&!empty($backup_options)){
103
- if (is_null($backup_options)) {
104
- $ret['error']='Invalid parameter param:'.$backup_options;
105
- return $ret;
106
- }
107
- $backup_options = apply_filters('wpvivid_custom_backup_options', $backup_options);
108
-
109
- if(!isset($backup_options['type']))
110
- {
111
- $backup_options['type']='Manual';
112
- $backup_options['action']='backup';
113
- }
114
- $ret = $wpvivid_plugin->check_backup_option($backup_options, $backup_options['type']);
115
- if($ret['result']!='success') {
116
- return $ret;
117
- }
118
- $ret=$wpvivid_plugin->pre_backup($backup_options);
119
- if($ret['result']=='success') {
120
- //Check the website data to be backed up
121
- $ret['check']=$wpvivid_plugin->check_backup($ret['task_id'],$backup_options);
122
- if(isset($ret['check']['result']) && $ret['check']['result'] == 'failed') {
123
- $ret['error']=$ret['check']['error'];
124
- return $ret;
125
- }
126
- }
127
- }
128
- else{
129
- $ret['error']='Error occurred while parsing the request data. Please try to run backup again.';
130
- return $ret;
131
- }
132
- return $ret;
133
- }
134
-
135
- public function wpvivid_backup_now_mainwp($data){
136
- $task_id = $data['task_id'];
137
- global $wpvivid_plugin;
138
- if (!isset($task_id)||empty($task_id)||!is_string($task_id))
139
- {
140
- $ret['error']=__('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid-backuprestore');
141
- return $ret;
142
- }
143
- $task_id=sanitize_key($task_id);
144
- /*$ret['result']='success';
145
- $txt = '<mainwp>' . base64_encode( serialize( $ret ) ) . '</mainwp>';
146
- // Close browser connection so that it can resume AJAX polling
147
- if(!headers_sent()) {
148
- header('Content-Length: ' . ((!empty($txt)) ? strlen($txt) : '0'));
149
- header('Connection: close');
150
- header('Content-Encoding: none');
151
- }
152
- if ( session_id() ) {
153
- session_write_close();
154
- }
155
- echo $txt;
156
- // These two added - 19-Feb-15 - started being required on local dev machine, for unknown reason (probably some plugin that started an output buffer).
157
- $ob_level = ob_get_level();
158
- while ($ob_level > 0) {
159
- ob_end_flush();
160
- $ob_level--;
161
- }
162
- flush();
163
- if (function_exists('fastcgi_finish_request')) fastcgi_finish_request();*/
164
-
165
- $wpvivid_plugin->flush($task_id, true);
166
- //Start backup site
167
- $wpvivid_plugin->backup($task_id);
168
- $ret['result']='success';
169
- }
170
-
171
- public function wpvivid_view_backup_task_log_mainwp($data){
172
- $backup_task_id = $data['id'];
173
- global $wpvivid_plugin;
174
- if (!isset($backup_task_id)||empty($backup_task_id)||!is_string($backup_task_id)){
175
- $ret['error']='Reading the log failed. Please try again.';
176
- return $ret;
177
- }
178
- $backup_task_id = sanitize_key($backup_task_id);
179
- $ret=$wpvivid_plugin->function_realize->_get_log_file('tasklog', $backup_task_id);
180
- if($ret['result'] == 'success') {
181
- $file = fopen($ret['log_file'], 'r');
182
- if (!$file) {
183
- $ret['result'] = 'failed';
184
- $ret['error'] = __('Unable to open the log file.', 'wpvivid-backuprestore');
185
- return $ret;
186
- }
187
- $buffer = '';
188
- while (!feof($file)) {
189
- $buffer .= fread($file, 1024);
190
- }
191
- fclose($file);
192
- $ret['result'] = 'success';
193
- $ret['data'] = $buffer;
194
- }
195
- else{
196
- $ret['error']='Unknown error';
197
- }
198
- return $ret;
199
- }
200
-
201
- public function wpvivid_backup_cancel_mainwp($data){
202
- global $wpvivid_plugin;
203
- $ret=$wpvivid_plugin->function_realize->_backup_cancel();
204
- return $ret;
205
- }
206
-
207
- public function wpvivid_set_backup_report_addon_mainwp($data){
208
- $task_id = $data['id'];
209
- $option = array();
210
- $option[$task_id]['task_id'] = $task_id;
211
- $option[$task_id]['backup_time'] = $data['status']['start_time'];
212
- if($data['status']['str'] == 'completed'){
213
- $option[$task_id]['status'] = 'Succeeded';
214
- }
215
- elseif($data['status']['str'] == 'error'){
216
- $option[$task_id]['status'] = 'Failed, '.$data['status']['error'];
217
- }
218
- elseif($data['status']['str'] == 'cancel'){
219
- $option[$task_id]['status'] = 'Canceled';
220
- }
221
- else{
222
- $option[$task_id]['status'] = 'The last backup message not found.';
223
- }
224
-
225
- $backup_reports = get_option('wpvivid_backup_reports', array());
226
- if(!empty($backup_reports)){
227
- foreach ($option as $key => $value){
228
- $backup_reports[$key] = $value;
229
- update_option('wpvivid_backup_reports', $backup_reports);
230
- }
231
- }
232
- else{
233
- update_option('wpvivid_backup_reports', $option);
234
- }
235
- }
236
-
237
- public function wpvivid_read_last_backup_log_mainwp($data){
238
- $log_file_name = $data['log_file_name'];
239
- global $wpvivid_plugin;
240
- if(!isset($log_file_name)||empty($log_file_name)||!is_string($log_file_name))
241
- {
242
- $ret['result']='failed';
243
- $ret['error']=__('Reading the log failed. Please try again.', 'wpvivid-backuprestore');
244
- return $ret;
245
- }
246
- $log_file_name=sanitize_text_field($log_file_name);
247
- $ret=$wpvivid_plugin->function_realize->_get_log_file('lastlog', $log_file_name);
248
- if($ret['result'] == 'success') {
249
- $file = fopen($ret['log_file'], 'r');
250
- if (!$file) {
251
- $ret['result'] = 'failed';
252
- $ret['error'] = __('Unable to open the log file.', 'wpvivid-backuprestore');
253
- return $ret;
254
- }
255
- $buffer = '';
256
- while (!feof($file)) {
257
- $buffer .= fread($file, 1024);
258
- }
259
- fclose($file);
260
- $ret['result'] = 'success';
261
- $ret['data'] = $buffer;
262
- }
263
- else{
264
- $ret['error']='Unknown error';
265
- }
266
- return $ret;
267
- }
268
-
269
- public function wpvivid_set_security_lock_mainwp($data){
270
- $backup_id = $data['backup_id'];
271
- $lock = $data['lock'];
272
- if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)){
273
- $ret['error']='Backup id not found';
274
- return $ret;
275
- }
276
- if(!isset($lock)){
277
- $ret['error']='Invalid parameter param: lock';
278
- return $ret;
279
- }
280
- $backup_id=sanitize_key($backup_id);
281
- if($lock==0||$lock==1) {
282
- }
283
- else {
284
- $lock=0;
285
- }
286
- WPvivid_Backuplist::set_security_lock($backup_id,$lock);
287
- $backuplist=WPvivid_Backuplist::get_backuplist();
288
- $ret['wpvivid']['backup_list']=$backuplist;
289
- return $ret;
290
- }
291
-
292
- public function wpvivid_view_log_mainwp($data){
293
- $backup_id = $data['id'];
294
- global $wpvivid_plugin;
295
- if (!isset($backup_id)||empty($backup_id)||!is_string($backup_id)){
296
- $ret['error']='Backup id not found';
297
- return $ret;
298
- }
299
- $backup_id=sanitize_key($backup_id);
300
- $ret=$wpvivid_plugin->function_realize->_get_log_file('backuplist', $backup_id);
301
- if($ret['result'] == 'success') {
302
- $file = fopen($ret['log_file'], 'r');
303
- if (!$file) {
304
- $ret['result'] = 'failed';
305
- $ret['error'] = __('Unable to open the log file.', 'wpvivid-backuprestore');
306
- return $ret;
307
- }
308
- $buffer = '';
309
- while (!feof($file)) {
310
- $buffer .= fread($file, 1024);
311
- }
312
- fclose($file);
313
- $ret['data'] = $buffer;
314
- }
315
- else{
316
- $ret['error']='Unknown error';
317
- }
318
- return $ret;
319
- }
320
-
321
- public function wpvivid_init_download_page_mainwp($data){
322
- $backup_id = $data['backup_id'];
323
- global $wpvivid_plugin;
324
- if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
325
- $ret['error']='Invalid parameter param:'.$backup_id;
326
- return $ret;
327
- }
328
- else {
329
- $backup_id=sanitize_key($backup_id);
330
- return $wpvivid_plugin->init_download($backup_id);
331
- }
332
- }
333
-
334
- public function wpvivid_prepare_download_backup_mainwp($data){
335
- $backup_id = $data['backup_id'];
336
- $file_name = $data['file_name'];
337
- if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id))
338
- {
339
- $ret['error']='Invalid parameter param:'.$backup_id;
340
- return $ret;
341
- }
342
- if(!isset($file_name)||empty($file_name)||!is_string($file_name))
343
- {
344
- $ret['error']='Invalid parameter param:'.$file_name;
345
- return $ret;
346
- }
347
- $download_info=array();
348
- $download_info['backup_id']=sanitize_key($backup_id);
349
- $download_info['file_name'] = $file_name;
350
-
351
- @set_time_limit(600);
352
- if (session_id())
353
- session_write_close();
354
- try
355
- {
356
- $downloader=new WPvivid_downloader();
357
- $downloader->ready_download($download_info);
358
- }
359
- catch (Exception $e)
360
- {
361
- $message = 'A exception ('.get_class($e).') occurred '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
362
- error_log($message);
363
- return array('error'=>$message);
364
- }
365
- catch (Error $e)
366
- {
367
- $message = 'A error ('.get_class($e).') has occurred: '.$e->getMessage().' (Code: '.$e->getCode().', line '.$e->getLine().' in '.$e->getFile().')';
368
- error_log($message);
369
- return array('error'=>$message);
370
- }
371
-
372
- $ret['result']='success';
373
- return $ret;
374
- }
375
-
376
- public function wpvivid_get_download_task_mainwp($data){
377
- $backup_id = $data['backup_id'];
378
- if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
379
- $ret['error']='Invalid parameter param:'.$backup_id;
380
- return $ret;
381
- }
382
- else {
383
- $backup = WPvivid_Backuplist::get_backup_by_id($backup_id);
384
- if ($backup === false) {
385
- $ret['result'] = WPVIVID_FAILED;
386
- $ret['error'] = 'backup id not found';
387
- return $ret;
388
- }
389
- $backup_item = new WPvivid_Backup_Item($backup);
390
- $ret = $backup_item->update_download_page($backup_id);
391
- return $ret;
392
- }
393
- }
394
-
395
- public function wpvivid_download_backup_mainwp($data){
396
- $backup_id = $data['backup_id'];
397
- $file_name = $data['file_name'];
398
- global $wpvivid_plugin;
399
- if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
400
- $ret['error']='Invalid parameter param: backup_id';
401
- return $ret;
402
- }
403
- if(!isset($file_name)||empty($file_name)||!is_string($file_name)) {
404
- $ret['error']='Invalid parameter param: file_name';
405
- return $ret;
406
- }
407
- $backup_id=sanitize_key($backup_id);
408
- $cache=WPvivid_taskmanager::get_download_cache($backup_id);
409
- if($cache===false) {
410
- $wpvivid_plugin->init_download($backup_id);
411
- $cache=WPvivid_taskmanager::get_download_cache($backup_id);
412
- }
413
- $path=false;
414
- if(array_key_exists($file_name,$cache['files'])) {
415
- if($cache['files'][$file_name]['status']=='completed') {
416
- $path=$cache['files'][$file_name]['download_path'];
417
- $download_url = $cache['files'][$file_name]['download_url'];
418
- }
419
- }
420
- if($path!==false) {
421
- if (file_exists($path)) {
422
- $ret['download_url'] = $download_url;
423
- $ret['size'] = filesize($path);
424
- }
425
- }
426
- return $ret;
427
- }
428
-
429
- public function wpvivid_delete_backup_mainwp($data){
430
- $backup_id = $data['backup_id'];
431
- $force_del = $data['force'];
432
- global $wpvivid_plugin;
433
- if(!isset($backup_id)||empty($backup_id)||!is_string($backup_id)) {
434
- $ret['error']='Invalid parameter param: backup_id.';
435
- return $ret;
436
- }
437
- if(!isset($force_del)){
438
- $ret['error']='Invalid parameter param: force.';
439
- return $ret;
440
- }
441
- if($force_del==0||$force_del==1) {
442
- }
443
- else {
444
- $force_del=0;
445
- }
446
- $backup_id=sanitize_key($backup_id);
447
- $ret=$wpvivid_plugin->delete_backup_by_id($backup_id, $force_del);
448
- $backuplist=WPvivid_Backuplist::get_backuplist();
449
- $ret['wpvivid']['backup_list']=$backuplist;
450
- return $ret;
451
- }
452
-
453
- public function wpvivid_delete_backup_array_mainwp($data){
454
- $backup_id_array = $data['backup_id'];
455
- global $wpvivid_plugin;
456
- if(!isset($backup_id_array)||empty($backup_id_array)||!is_array($backup_id_array)) {
457
- $ret['error']='Invalid parameter param: backup_id';
458
- return $ret;
459
- }
460
- $ret=array();
461
- foreach($backup_id_array as $backup_id)
462
- {
463
- $backup_id=sanitize_key($backup_id);
464
- $ret=$wpvivid_plugin->delete_backup_by_id($backup_id);
465
- }
466
- $backuplist=WPvivid_Backuplist::get_backuplist();
467
- $ret['wpvivid']['backup_list']=$backuplist;
468
- return $ret;
469
- }
470
-
471
- public function wpvivid_set_schedule_mainwp($data){
472
- $schedule = $data['schedule'];
473
- $ret=array();
474
- try {
475
- if(isset($schedule)&&!empty($schedule)) {
476
- $json = $schedule;
477
- $json = stripslashes($json);
478
- $schedule = json_decode($json, true);
479
- if (is_null($schedule)) {
480
- $ret['error']='bad parameter';
481
- return $ret;
482
- }
483
- $ret=WPvivid_Schedule::set_schedule_ex($schedule);
484
- if($ret['result']!='success') {
485
- return $ret;
486
- }
487
- }
488
- $ret['result']='success';
489
- }
490
- catch (Exception $error) {
491
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
492
- error_log($message);
493
- return array('error'=>$message);
494
- }
495
- return $ret;
496
- }
497
-
498
- public function wpvivid_set_general_setting_mainwp($data){
499
- $setting = $data['setting'];
500
- $ret=array();
501
- try {
502
- if(isset($setting)&&!empty($setting)) {
503
- $json_setting = $setting;
504
- $json_setting = stripslashes($json_setting);
505
- $setting = json_decode($json_setting, true);
506
- if (is_null($setting)) {
507
- $ret['error']='bad parameter';
508
- return $ret;
509
- }
510
- WPvivid_Setting::update_setting($setting);
511
- }
512
-
513
- $ret['result']='success';
514
- }
515
- catch (Exception $error) {
516
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
517
- error_log($message);
518
- return array('error'=>$message);
519
- }
520
- return $ret;
521
- }
522
-
523
- public function wpvivid_set_remote_mainwp($data){
524
- $remote = $data['remote'];
525
- global $wpvivid_plugin;
526
- $ret=array();
527
- try {
528
- if(isset($remote)&&!empty($remote)) {
529
- $json = $remote;
530
- $json = stripslashes($json);
531
- $remote = json_decode($json, true);
532
- if (is_null($remote)) {
533
- $ret['error']='bad parameter';
534
- return $ret;
535
- }
536
- $wpvivid_plugin->function_realize->_set_remote($remote);
537
- }
538
- $ret['result']='success';
539
- }
540
- catch (Exception $error) {
541
- $message = 'An exception has occurred. class: '.get_class($error).';msg: '.$error->getMessage().';code: '.$error->getCode().';line: '.$error->getLine().';in_file: '.$error->getFile().';';
542
- error_log($message);
543
- return array('error'=>$message);
544
- }
545
- return $ret;
546
- }
547
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-log.php DELETED
@@ -1,171 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
- class WPvivid_Log
7
- {
8
- public $log_file;
9
- public $log_file_handle;
10
-
11
- public function __construct()
12
- {
13
- $this->log_file_handle=false;
14
- }
15
-
16
- public function CreateLogFile($file_name,$type,$describe)
17
- {
18
- if($type=='has_folder')
19
- {
20
- $this->log_file=$file_name;
21
- }
22
- else
23
- {
24
- $this->log_file=$this->GetSaveLogFolder().$file_name.'_log.txt';
25
- }
26
- if(file_exists($this->log_file))
27
- {
28
- @unlink( $this->log_file);
29
- }
30
- $this->log_file_handle = fopen($this->log_file, 'a');
31
- $time =date("Y-m-d H:i:s",time());
32
- $text='Log created: '.$time."\n";
33
- $text.='Type: '.$describe."\n";
34
- fwrite($this->log_file_handle,$text);
35
-
36
- return $this->log_file;
37
- }
38
-
39
- public function OpenLogFile($file_name,$type='no_folder',$delete=0)
40
- {
41
- if($type=='has_folder')
42
- {
43
- $this->log_file=$file_name;
44
- }
45
- else
46
- {
47
- $this->log_file=$this->GetSaveLogFolder().$file_name.'_log.txt';
48
- }
49
- if($delete==1)
50
- {
51
- unlink( $this->log_file);
52
- }
53
- $this->log_file_handle = fopen($this->log_file, 'a');
54
-
55
- return $this->log_file;
56
- }
57
-
58
- public function WriteLog($log,$type)
59
- {
60
- if ($this->log_file_handle)
61
- {
62
- $time =date("Y-m-d H:i:s",time());
63
- $text='['.$time.']'.'['.$type.']'.$log."\n";
64
- fwrite($this->log_file_handle,$text );
65
- }
66
- }
67
-
68
- public function CloseFile()
69
- {
70
- if ($this->log_file_handle)
71
- {
72
- fclose($this->log_file_handle);
73
- $this->log_file_handle=false;
74
- }
75
- }
76
-
77
- public function GetSaveLogFolder()
78
- {
79
- include_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wpvivid-setting.php';
80
-
81
- $options = WPvivid_Setting::get_option('wpvivid_common_setting');
82
-
83
- if(!isset($options['log_save_location']))
84
- {
85
- WPvivid_Setting::set_default_common_option();
86
- $options = WPvivid_Setting::get_option('wpvivid_common_setting');
87
- }
88
-
89
- if(!is_dir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$options['log_save_location']))
90
- {
91
- @mkdir(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$options['log_save_location'],0777,true);
92
- @fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$options['log_save_location'].DIRECTORY_SEPARATOR.'index.html', 'x');
93
- $tempfile=@fopen(WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$options['log_save_location'].DIRECTORY_SEPARATOR.'.htaccess', 'x');
94
- if($tempfile)
95
- {
96
- $text="deny from all";
97
- fwrite($tempfile,$text );
98
- }
99
- }
100
-
101
- return WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$options['log_save_location'].DIRECTORY_SEPARATOR;
102
- }
103
-
104
- public function WriteLogHander()
105
- {
106
- if ($this->log_file_handle)
107
- {
108
- global $wp_version;
109
- global $wpdb;
110
-
111
- $sapi_type=php_sapi_name();
112
- if($sapi_type=='cgi-fcgi'||$sapi_type==' fpm-fcgi') {
113
- $fcgi='On';
114
- }
115
- else {
116
- $fcgi='Off';
117
- }
118
-
119
- $options=WPvivid_Setting::get_option('wpvivid_common_setting');
120
- if(isset($options['max_execution_time'])) {
121
- $max_execution_time=$options['max_execution_time'];
122
- }
123
- else {
124
- $max_execution_time=WPVIVID_MAX_EXECUTION_TIME;
125
- }
126
-
127
- $log='server info fcgi:'.$fcgi.' max execution time: '.$max_execution_time.' wp version:'.$wp_version.' php version:'.phpversion().' db version:'.$wpdb->db_version().' php ini:safe_mode:'.ini_get('safe_mode').' ';
128
- $log.='memory_limit:'.ini_get('memory_limit').' memory_get_usage:'.size_format(memory_get_usage(),2).' memory_get_peak_usage:'.size_format(memory_get_peak_usage(),2);
129
- $log.=' extensions:';
130
- $loaded_extensions = get_loaded_extensions();
131
- if(!in_array('PDO', $loaded_extensions))
132
- {
133
- $log.='PDO not enabled ';
134
- }
135
- else
136
- {
137
- $log.='PDO enabled ';
138
- }
139
- if(!in_array('curl', $loaded_extensions))
140
- {
141
- $log.='curl not enabled ';
142
- }
143
- else
144
- {
145
- $log.='curl enabled ';
146
- }
147
-
148
- if(!in_array('zlib', $loaded_extensions)) {
149
- $log .= 'zlib not enabled ';
150
- }
151
- else
152
- {
153
- $log.='zlib enabled ';
154
- }
155
-
156
- $log.=' ';
157
- if(is_multisite())
158
- {
159
- $log.=' is_multisite:1';
160
- }
161
- else
162
- {
163
- $log.=' is_multisite:0';
164
- }
165
-
166
- $time =date("Y-m-d H:i:s",time());
167
- $text='['.$time.']'.'[notice]'.$log."\n";
168
- fwrite($this->log_file_handle,$text );
169
- }
170
- }
171
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-mail-report.php DELETED
@@ -1,584 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR')){
4
- die;
5
- }
6
- class WPvivid_mail_report
7
- {
8
- public static function send_report_mail($task,$log=false)
9
- {
10
- $option=WPvivid_Setting::get_option('wpvivid_email_setting');
11
-
12
- $option=apply_filters('wpvivid_get_mail_option_addon', $option);
13
- if(empty($option))
14
- {
15
- return true;
16
- }
17
-
18
- if($option['email_enable'] == 0){
19
- return true;
20
- }
21
-
22
- if(empty($option['send_to']))
23
- {
24
- return true;
25
- }
26
-
27
- if($task['status']['str']=='completed'&&$option['always']==false)
28
- {
29
- return true;
30
- }
31
-
32
- $headers = array('Content-Type: text/html; charset=UTF-8');
33
-
34
- $subject = '';
35
- $subject = apply_filters('wpvivid_set_mail_subject', $subject, $task);
36
-
37
- $body = '';
38
- $body = apply_filters('wpvivid_set_mail_body', $body, $task);
39
-
40
- $task_log=$task['options']['log_file_name'];
41
-
42
- if(isset($option['email_attach_log'])){
43
- if($option['email_attach_log'] == '1'){
44
- $attach_log = true;
45
- }
46
- else{
47
- $attach_log = false;
48
- }
49
- }
50
- else{
51
- $attach_log = true;
52
- }
53
- if($attach_log){
54
- $wpvivid_log=new WPvivid_Log();
55
- $log_file_name= $wpvivid_log->GetSaveLogFolder().$task_log.'_log.txt';
56
- $attachments[] = $log_file_name;
57
- }
58
- else{
59
- $attachments = array();
60
- }
61
-
62
- foreach ($option['send_to'] as $send_to)
63
- {
64
- if(wp_mail( $send_to, $subject, $body,$headers,$attachments)===false)
65
- {
66
- if($log!==false)
67
- {
68
- $message=get_error_messages('wp_mail_failed');
69
- $log->WriteLog($message,'error');
70
- }
71
- }
72
- }
73
-
74
- return true;
75
- }
76
-
77
-
78
-
79
- public static function create_subject($task)
80
- {
81
- $status=$task['status']['str'];
82
- if($status=='completed')
83
- {
84
- $status='Succeeded';
85
- }
86
- else
87
- {
88
- $status='Failed';
89
- }
90
- $header='[Backup '.$status.']'.gmdate('m-d-Y H:i:s', $task['status']['start_time']).' - By WPvivid Backup Plugin';
91
- return $header;
92
- }
93
-
94
- public static function create_body($task)
95
- {
96
- $status=$task['status']['str'];
97
- if($status=='completed')
98
- {
99
- $status='succeeded';
100
- }
101
- else
102
- {
103
- $status='failed. '.$task['status']['error'];
104
- }
105
- $type=$task['type'];
106
- $start_time=date("m-d-Y H:i:s",$task['status']['start_time']);
107
- $end_time=date("m-d-Y H:i:s",time());
108
- $running_time=($task['status']['run_time']-$task['status']['start_time']).'s';
109
- $remote_options= $task['options']['remote_options'];
110
- if($remote_options!==false)
111
- {
112
- $remote_option=array_shift($remote_options);
113
- $remote=apply_filters('wpvivid_storage_provider_tran', $remote_option['type']);
114
- }
115
- else
116
- {
117
- $remote='Localhost';
118
- }
119
- $content='';
120
-
121
- $backup_options=$task['options']['backup_options'];
122
- if($backup_options!==false)
123
- {
124
- if(isset($backup_options['backup'][WPVIVID_BACKUP_TYPE_DB])&&isset($backup_options['backup'][WPVIVID_BACKUP_TYPE_THEMES]))
125
- {
126
- $content.='Entire Website';
127
- }
128
- else if(isset($backup_options['backup'][WPVIVID_BACKUP_TYPE_DB]))
129
- {
130
- $content.='Database';
131
- }
132
- else if(isset($backup_options['backup'][WPVIVID_BACKUP_TYPE_THEMES]))
133
- {
134
- $content.='All Files (Exclude Database)';
135
- }
136
- }
137
- else
138
- {
139
- $content='Upload';
140
- }
141
-
142
- $body='
143
- <table width="100%" cellpadding="0" cellspacing="0" bgcolor="#F5F7F8">
144
- <tbody>
145
- <tr>
146
- <td style="padding-bottom:20px">
147
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
148
- <table align="center" style="border-spacing:0;color:#111111;Margin:0 auto;width:100%;max-width:600px" bgcolor="#F5F7F8">
149
- <tbody>
150
- <tr>
151
- <td bgcolor="#F5F7F8" style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
152
- <table width="73%" style="border-spacing:0;color:#111111" bgcolor="#F5F7F8">
153
- <tbody>
154
- <tr>
155
- <td style="padding-top:20px;padding-bottom:0px;padding-left:10px;padding-right:40px;width:100%;text-align:center;font-size:32px;color:#2ea3f2;line-height:32px;font-weight:bold;">
156
- <span><img src="https://wpvivid.com/wp-content/uploads/2019/02/wpvivid-logo.png" title="WPvivid.com"></span>
157
- </td>
158
- </tr>
159
- </tbody>
160
- </table>
161
- </td>
162
- <td width="100%" bgcolor="#F5F7F8" style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
163
- <table width="100%" style="border-spacing:0;color:#111111" bgcolor="#F5F7F8">
164
- <tbody>
165
- <tr>
166
- <td style="padding-top:10px;padding-bottom:0px;padding-left:10px;padding-right:0px;background-color:#f5f7f8;width:100%;text-align:right">
167
- <p style="Margin-top:0px;margin-bottom:0px;font-size:13px;line-height:16px"><strong><a href="https://twitter.com/wpvividcom" style="text-decoration:none;color:#111111" target="_blank">24/7 Support: <u></u>Twitter<u></u></a></strong></p>
168
- </td>
169
- </tr>
170
- <tr>
171
- <td style="padding-top:0px;padding-bottom:0px;padding-left:10px;padding-right:0px;background-color:#f5f7f8;width:100%;text-align:right">
172
- <p class="m_764812426175198487customerinfo" style="Margin-top:5px;margin-bottom:0px;font-size:13px;line-height:16px">Or <u></u><a href="https://wpvivid.com/contact-us">Email Us</a><u></u></p>
173
- </td>
174
- </tr>
175
- </tbody>
176
- </table>
177
- </td>
178
- </tr>
179
- </tbody>
180
- </table>
181
- </div>
182
- </td>
183
- </tr>
184
- </tbody>
185
- </table>
186
-
187
- <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#F5F7F8">
188
- <tbody>
189
- <tr>
190
- <td bgcolor="#F5F7F8" style="padding-top:0px;padding-bottom:0px">
191
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
192
- <table bgcolor="#FFFFFF" align="center" style="border-spacing:0;color:#111111;margin:0 auto;width:100%;max-width:600px">
193
- <tbody>
194
- <tr>
195
- <td style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
196
- <table width="100%" style="border-spacing:0;color:#111111">
197
- <tbody>
198
- <tr>
199
- <td style="padding-top:40px;padding-bottom:0px;padding-left:40px;padding-right:40px;background-color:#ffffff;width:100%;text-align:center;font-size:32px;line-height:42px;font-weight:bold;">
200
- <span>Wordpress Backup Report</span>
201
- </td>
202
- </tr>
203
- </tbody>
204
- </table>
205
- </td>
206
- </tr>
207
- </tbody>
208
- </table>
209
- </div>
210
- </td>
211
- </tr>
212
- </tbody>
213
- </table>
214
-
215
- <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#F5F7F8">
216
- <tbody>
217
- <tr>
218
- <td bgcolor="#F5F7F8" style="padding-top:0px;padding-bottom:0px">
219
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
220
- <table bgcolor="#FFFFFF" align="center" style="border-spacing:0;color:#111111;margin:0 auto;width:100%;max-width:600px">
221
- <tbody>
222
- <tr>
223
- <td style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
224
- <table width="100%" style="border-spacing:0;color:#111111">
225
- <tbody>
226
- <tr>
227
- <td style="padding-top:20px;padding-bottom:0px;padding-left:0px;padding-right:0px;background-color:#ffffff;width:100%;text-align:left">
228
- <p style="margin-top:0px;line-height:0px;margin-bottom:0px;font-size:4px"> </p>
229
- </td>
230
- </tr>
231
- </tbody>
232
- </table>
233
- </td>
234
- <td width="80" style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
235
- <table width="80" style="border-spacing:0;color:#111111;border-bottom-color:#ffcca8;border-bottom-width:2px;border-bottom-style:solid">
236
- <tbody>
237
- <tr>
238
- <td style="padding-top:20px;padding-bottom:0px;padding-left:0px;padding-right:0px;background-color:#ffffff;width:100%;text-align:left">
239
- <p style="margin-top:0px;line-height:0px;margin-bottom:0px;font-size:4px"></p>
240
- </td>
241
- </tr>
242
- </tbody>
243
- </table>
244
- </td>
245
- <td style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
246
- <table width="100%" style="border-spacing:0;color:#111111">
247
- <tbody>
248
- <tr>
249
- <td style="padding-top:20px;padding-bottom:0px;padding-left:0px;padding-right:0px;background-color:#ffffff;width:100%;text-align:left">
250
- <p style="margin-top:0px;line-height:0px;margin-bottom:0px;font-size:4px"> </p>
251
- </td>
252
- </tr>
253
- </tbody>
254
- </table>
255
- </td>
256
- </tr>
257
- </tbody>
258
- </table>
259
- </div>
260
- </td>
261
- </tr>
262
- </tbody>
263
- </table>
264
-
265
- <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#F5F7F8">
266
- <tbody>
267
- <tr>
268
- <td bgcolor="#F5F7F8" style="padding-top:0px;padding-bottom:0px">
269
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
270
- <table bgcolor="#FFFFFF" align="center" style="border-spacing:0;color:#111111;margin:0 auto;width:100%;max-width:600px">
271
- <tbody>
272
- <tr>
273
- <td style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
274
- <table width="100%" style="border-spacing:0;color:#111111">
275
- <tbody>
276
- <tr>
277
- <td style="padding-top:40px;padding-bottom:0px;padding-left:40px;padding-right:40px;background-color:#ffffff;width:100%;text-align:left">
278
- <p style="gdsherpa-regular;margin-top:0px;font-size:14px;line-height:24px;margin-bottom:0px">
279
- You receive this email because you have enabled the email notification feature in WPvivid plugin. Backup Details:
280
- </p>
281
- </td>
282
- </tr>
283
- </tbody>
284
- </table>
285
- </td>
286
- </tr>
287
- </tbody>
288
- </table>
289
- </div>
290
- </td>
291
- </tr>
292
- </tbody>
293
- </table>
294
-
295
- <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#F5F7F8">
296
- <tbody>
297
- <tr>
298
- <td bgcolor="#F5F7F8" style="background-color:#f5f7f8;padding-top:0;padding-right:0;padding-left:0;padding-bottom:0">
299
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
300
- <table bgcolor="#ffffff" width="100%" align="left" border="0" cellspacing="0" cellpadding="0" style="color:#111111">
301
- <tbody>
302
- <tr>
303
- <td bgcolor="#ffffff" align="left" style="padding-top:10px;padding-bottom:0;padding-right:40px;padding-left:40px;background-color:#ffffff">
304
- <table border="0" cellpadding="0" cellspacing="0" align="left" width="100%">
305
- <tbody>
306
- <tr>
307
- <td style="padding-top:10px;padding-right:0;padding-bottom:0;padding-left:20px">
308
- <table border="0" cellpadding="0" cellspacing="0" align="left">
309
- <tbody>
310
- <tr>
311
- <td valign="top" align="left" style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
312
- <p style="text-align:left;Margin-top:0px;Margin-bottom:0px;gdsherpa-regular;font-size:14px;line-height:24px"><label>Backup:</label><label>'.$status.'</label></p>
313
- </td>
314
- </tr>
315
- <tr>
316
- <td valign="top" align="left" style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
317
- <p style="text-align:left;Margin-top:0px;Margin-bottom:0px;gdsherpa-regular;font-size:14px;line-height:24px"><label>Backup Type:</label><label>'.$type.'</label></p>
318
- </td>
319
- </tr>
320
- <tr>
321
- <td valign="top" align="left" style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
322
- <p style="text-align:left;Margin-top:0px;Margin-bottom:0px;gdsherpa-regular;font-size:14px;line-height:24px"><label>Start Time:</label><label>'.$start_time.'</label></p>
323
- </td>
324
- </tr>
325
- <tr>
326
- <td valign="top" align="left" style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
327
- <p style="text-align:left;Margin-top:0px;Margin-bottom:0px;gdsherpa-regular;font-size:14px;line-height:24px"><label>End Time:</label><label>'.$end_time.'</label></p>
328
- </td>
329
- </tr>
330
- <tr>
331
- <td valign="top" align="left" style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
332
- <p style="text-align:left;Margin-top:0px;Margin-bottom:0px;gdsherpa-regular;font-size:14px;line-height:24px"><label>Running Time:</label><label>'.$running_time.'</label></p>
333
- </td>
334
- </tr>
335
- <tr>
336
- <td valign="top" align="left" style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
337
- <p style="text-align:left;Margin-top:0px;Margin-bottom:0px;gdsherpa-regular;font-size:14px;line-height:24px"><label>Back up to:</label><label>'.$remote.'</label></p>
338
- </td>
339
- </tr>
340
- <tr>
341
- <td valign="top" align="left" style="padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
342
- <p style="text-align:left;Margin-top:0px;Margin-bottom:0px;gdsherpa-regular;font-size:14px;line-height:24px"><label>Backup Content:</label><label>'.$content.'</label></p>
343
- </td>
344
- </tr>
345
- </tbody>
346
- </table>
347
- </td>
348
- </tr>
349
- </tbody>
350
- </table>
351
- </td>
352
- </tr>
353
- </tbody>
354
- </table>
355
- </div>
356
- </td>
357
- </tr>
358
- </tbody>
359
- </table>
360
-
361
- <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#F5F7F8">
362
- <tbody>
363
- <tr>
364
- <td bgcolor="#F5F7F8" style="padding-top:0px;padding-bottom:0px">
365
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
366
- <table bgcolor="#FFFFFF" align="center" style="border-spacing:0;color:#111111;margin:0 auto;width:100%;max-width:600px">
367
- <tbody>
368
- <tr>
369
- <td style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
370
- <table width="100%" style="border-spacing:0;color:#757575">
371
- <tbody>
372
- <tr>
373
- <td style="padding-top:20px;padding-bottom:0px;padding-left:40px;padding-right:40px;background-color:#ffffff;width:100%;text-align:left">
374
- <p style="gdsherpa-regular;margin-top:0px;font-size:14px;line-height:24px;margin-bottom:0px">
375
- *WPvivid Backup plugin is a Wordpress plugin that it will help you back up your site to the leading cloud storage providers like Dropbox, Google Drive, Amazon S3, Microsoft OneDrive, FTP and SFTP.
376
- </p>
377
- <p style="gdsherpa-regular;margin-top:0px;font-size:14px;line-height:24px;margin-bottom:0px">
378
- Plugin Page: <a href="https://wordpress.org/plugins/wpvivid-backuprestore/">https://wordpress.org/plugins/wpvivid-backuprestore/</a>
379
- </p>
380
- </td>
381
- </tr>
382
- </tbody>
383
- </table>
384
- </td>
385
- </tr>
386
- </tbody>
387
- </table>
388
- </div>
389
- </td>
390
- </tr>
391
- </tbody>
392
- </table>
393
-
394
- <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#F5F7F8">
395
- <tbody>
396
- <tr>
397
- <td bgcolor="#F5F7F8" style="padding-top:0px;padding-bottom:0px">
398
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
399
- <table bgcolor="#FFFFFF" align="center" style="border-spacing:0;color:#111111;margin:0 auto;width:100%;max-width:600px">
400
- <tbody>
401
- <tr>
402
- <td style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
403
- <table width="100%" style="border-spacing:0;color:#111111">
404
- <tbody>
405
- <tr>
406
- <td style="padding-top:40px;padding-bottom:0px;padding-left:40px;padding-right:40px;background-color:#ffffff;width:100%;text-align:left">
407
- <p style="margin-top:0px;line-height:0px;margin-bottom:0px;font-size:4px"></p>
408
- </td>
409
- </tr>
410
- </tbody>
411
- </table>
412
- </td>
413
- </tr>
414
- </tbody>
415
- </table>
416
- </div>
417
- </td>
418
- </tr>
419
- </tbody>
420
- </table>
421
-
422
- <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#F5F7F8">
423
- <tbody>
424
- <tr>
425
- <td bgcolor="#F5F7F8" style="background-color:#f5f7f8;padding-top:0;padding-right:0;padding-left:0;padding-bottom:0">
426
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
427
- <table width="100%" align="center" border="0" cellspacing="0" cellpadding="0" style="color:#111111">
428
- <tbody>
429
- <tr>
430
- <td align="center" style="padding-top:40px;padding-bottom:0;padding-right:0px;padding-left:0px">
431
- <table border="0" cellpadding="0" cellspacing="0" width="100%">
432
- <tbody>
433
- <tr>
434
- <td align="left" valign="bottom">
435
- <img src="https://wpvivid.com/wp-content/uploads/2019/03/report-background.png" width="270" height="60" style="display:block;width:100%;max-width:270px;min-width:10px;height:60px" class="CToWUd">
436
- </td>
437
- <td width="60" valign="bottom">
438
- <img src="https://wpvivid.com/wp-content/uploads/2019/03/female.png" width="60" height="60" style="display:block" class="CToWUd">
439
- </td>
440
- <td align="right" valign="bottom">
441
- <img src="https://wpvivid.com/wp-content/uploads/2019/03/report-background.png" width="270" height="60" style="display:block;width:100%;max-width:270px;min-width:10px;height:60px" class="CToWUd">
442
- </td>
443
- </tr>
444
- </tbody>
445
- </table>
446
- </td>
447
- </tr>
448
- </tbody>
449
- </table>
450
- <table bgcolor="#FFFFFF" width="100%" align="left" border="0" cellspacing="0" cellpadding="0" style="color:#111111">
451
- <tbody>
452
- <tr>
453
- <td bgcolor="#FFFFFF" align="left" style="padding-top:20px;padding-bottom:40px;padding-right:40px;padding-left:40px;background-color:#ffffff">
454
- <table border="0" cellpadding="0" cellspacing="0" width="100%" align="center">
455
- <tbody>
456
- <tr>
457
- <td align="center" style="padding-top:0px;padding-bottom:10px;padding-right:0;padding-left:0;text-align:center;font-size:18px;line-height:28px;font-weight:bold;">
458
- <span>We\'re here to help you do your thing.</span>
459
- </td>
460
- </tr>
461
- <tr>
462
- <td align="center" style="padding-top:0px;padding-bottom:0px;padding-right:0;padding-left:0;text-align:center">
463
- <p style="text-align:center;margin-top:0px;margin-bottom:0px;gdsherpa-regular;;font-size:14px;line-height:24px">
464
- <a href="https://wpvivid.com/contact-us">Contact Us</a> or <a href="https://twitter.com/wpvividcom">Twitter</a>
465
- </p>
466
- </td>
467
- </tr>
468
- </tbody>
469
- </table>
470
- </td>
471
- </tr>
472
- </tbody>
473
- </table>
474
- <table border="0" cellpadding="0" cellspacing="0" width="100%">
475
- <tbody>
476
- <tr>
477
- <td valign="top" style="font-size:0px;line-height:0px;padding-top:0px;padding-right:0px;padding-bottom:0px;padding-left:0px">
478
- <img src="https://wpvivid.com/wp-content/uploads/2019/03/unnamed6.jpg" width="600" height="5" style="display:block;width:100%;max-width:600px;min-width:10px;height:5px">
479
- </td>
480
- </tr>
481
- </tbody>
482
- </table>
483
- </div>
484
- </td>
485
- </tr>
486
- </tbody>
487
- </table>
488
-
489
- <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#F5F7F8">
490
- <tbody>
491
- <tr>
492
- <td bgcolor="#F5F7F8" style="padding-top:0px;padding-bottom:0px">
493
- <div style="max-width:600px;margin-top:0;margin-bottom:0;margin-right:auto;margin-left:auto;padding-left:20px;padding-right:20px">
494
- <table bgcolor="#F5F7F8" align="center" style="border-spacing:0;color:#111111;margin:0 auto;width:100%;max-width:600px">
495
- <tbody>
496
- <tr>
497
- <td style="padding-top:0;padding-bottom:0;padding-right:0;padding-left:0">
498
- <table width="100%" style="border-spacing:0;color:#111111">
499
- <tbody>
500
- <tr>
501
- <td style="padding-top:40px;padding-bottom:0px;padding-left:40px;padding-right:40px;background-color:#f5f7f8;width:100%;text-align:left">
502
- <p style="margin-top:0px;line-height:0px;margin-bottom:0px;font-size:4px">&nbsp;</p>
503
- </td>
504
- </tr>
505
- </tbody>
506
- </table>
507
- </td>
508
- </tr>
509
- </tbody>
510
- </table>
511
- </div>
512
- </td>
513
- </tr>
514
- </tbody>
515
- </table>';
516
- return $body;
517
- }
518
-
519
- public static function wpvivid_send_debug_info($user_email,$server_type,$host_provider,$comment)
520
- {
521
- $send_to = 'support@wpvivid.com';
522
- $subject = 'Debug Information';
523
- $body = '<div>User\'s email: '.$user_email.'.</div>';
524
- $body .= '<div>Server type: '.$server_type.'.</div>';
525
- $body .= '<div>Host provider: '.$host_provider.'.</div>';
526
- $body .= '<div>Comment: '.$comment.'.</div>';
527
- $headers = array('Content-Type: text/html; charset=UTF-8');
528
-
529
- $files=WPvivid_error_log::get_error_log();
530
-
531
- if (!class_exists('PclZip'))
532
- include_once(ABSPATH.'/wp-admin/includes/class-pclzip.php');
533
-
534
- $backup_path=WPvivid_Setting::get_backupdir();
535
- $path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'wpvivid_debug.zip';
536
-
537
- if(file_exists($path))
538
- {
539
- @unlink( $path);
540
- }
541
- $archive = new PclZip($path);
542
-
543
- if(!empty($files))
544
- {
545
- if(!$archive->add($files,PCLZIP_OPT_REMOVE_ALL_PATH))
546
- {
547
- echo $archive->errorInfo(true).' <a href="'.admin_url().'admin.php?page=WPvivid">retry</a>.';
548
- exit;
549
- }
550
- }
551
-
552
- global $wpvivid_plugin;
553
- $server_info=json_encode($wpvivid_plugin->get_website_info());
554
- $server_file_path=WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backup_path.DIRECTORY_SEPARATOR.'wpvivid_server_info.json';
555
- if(file_exists($server_file_path))
556
- {
557
- @unlink( $server_file_path);
558
- }
559
- $server_file = fopen($server_file_path, 'x');
560
- fclose($server_file);
561
- file_put_contents($server_file_path,$server_info);
562
- if(!$archive->add($server_file_path,PCLZIP_OPT_REMOVE_ALL_PATH))
563
- {
564
- echo $archive->errorInfo(true).' <a href="'.admin_url().'admin.php?page=WPvivid">retry</a>.';
565
- exit;
566
- }
567
- @unlink( $server_file_path);
568
-
569
- $attachments[] = $path;
570
-
571
- if(wp_mail( $send_to, $subject, $body,$headers,$attachments)===false)
572
- {
573
- $ret['result']='failed';
574
- $ret['error']=__('Unable to send email. Please check the configuration of email server.', 'wpvivid-backuprestore');
575
- }
576
- else
577
- {
578
- $ret['result']='success';
579
- }
580
-
581
- @unlink($path);
582
- return $ret;
583
- }
584
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-migrate.php DELETED
@@ -1,1268 +0,0 @@
1
- <?php
2
-
3
- if (!defined('WPVIVID_PLUGIN_DIR'))
4
- {
5
- die;
6
- }
7
-
8
- class WPvivid_Migrate
9
- {
10
- public function __construct()
11
- {
12
- add_filter('wpvivid_add_tab_page', array($this, 'wpvivid_add_migrate_tab_page'));
13
- add_action('wp_ajax_wpvivid_generate_url',array( $this,'generate_url'));
14
- add_action('wp_ajax_wpvivid_send_backup_to_site',array( $this,'send_backup_to_site'));
15
- add_action('wp_ajax_wpvivid_migrate_now',array( $this,'migrate_now'));
16
- add_filter('wpvivid_backuppage_load_backuplist', array($this, 'wpvivid_backuppage_load_backuplist'));
17
-
18
- add_action('wp_ajax_wpvivid_export_download_backup',array( $this,'export_download_backup'));
19
- add_action('wp_ajax_wpvivid_list_upload_tasks',array( $this,'list_tasks'));
20
- add_action('wp_ajax_wpvivid_test_connect_site',array( $this,'test_connect_site'));
21
- add_action('wp_ajax_wpvivid_delete_transfer_key',array($this, 'delete_transfer_key'));
22
-
23
- add_filter('wpvivid_put_transfer_key', array($this, 'wpvivid_put_transfer_key'));
24
- add_action('wpvivid_handle_backup_failed',array($this,'wpvivid_handle_backup_failed'),9);
25
-
26
- add_action('wpvivid_rescan_backup_list', array($this, 'wpvivid_rescan_backup_list'));
27
- add_action('wpvivid_handle_upload_succeed',array($this,'wpvivid_deal_upload_succeed'),11);
28
-
29
- add_filter('wpvivid_add_migrate_type', array($this, 'wpvivid_add_migrate_type'), 11, 2);
30
- add_filter('wpvivid_migrate_descript', array($this, 'wpvivid_migrate_descript'));
31
- add_filter('wpvivid_migrate_part_type', array($this, 'wpvivid_migrate_part_type'));
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){
41
- $page_array['migrate'] = array('index' => '3', 'tab_func' => array($this, 'wpvivid_add_tab_migrate'), 'page_func' => array($this, 'wpvivid_add_page_migrate'));
42
- $page_array['key'] = array('index' => '8', 'tab_func' => array($this, 'wpvivid_add_tab_key'), 'page_func' => array($this, 'wpvivid_add_page_key'));
43
- return $page_array;
44
- }
45
-
46
- public function wpvivid_add_tab_migrate()
47
- {
48
- ?>
49
- <a href="#" id="wpvivid_tab_migrate" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'migrate-page')"><?php _e('Auto-Migration', 'wpvivid-backuprestore'); ?></a>
50
- <?php
51
- }
52
-
53
- public function wpvivid_add_tab_key(){
54
- ?>
55
- <a href="#" id="wpvivid_tab_key" class="nav-tab wrap-nav-tab" onclick="switchTabs(event,'key-page')"><?php _e('Key', 'wpvivid-backuprestore'); ?></a>
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'){
76
- jQuery('#wpvivid_transfer_btn').show();
77
- jQuery('#wpvivid_export_download_btn').hide();
78
- }
79
- else if(value === 'export'){
80
- jQuery('#wpvivid_transfer_btn').hide();
81
- jQuery('#wpvivid_export_download_btn').show();
82
- }
83
- });
84
- //wpvivid_edit_url_button
85
- jQuery('#wpvivid_add_remote_site_url').show();
86
- jQuery('#wpvivid_upload_backup_percent').hide();
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'});
94
- jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
95
- jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'none', 'opacity': '0.4'});
96
- }
97
-
98
- function wpvivid_control_transfer_unlock(){
99
- jQuery('#wpvivid_quickbackup_btn').css({'pointer-events': 'auto', 'opacity': '1'});
100
- jQuery('#wpvivid_transfer_btn').css({'pointer-events': 'auto', 'opacity': '1'});
101
- jQuery("#wpvivid_delete_key_button").css({'pointer-events': 'auto', 'opacity': '1'});
102
- }
103
-
104
-
105
-
106
- function wpvivid_click_export_backup()
107
- {
108
- var option_data = wpvivid_ajax_data_transfer('migrate');
109
- var ajax_data = {
110
- 'action': 'wpvivid_export_download_backup',
111
- 'backup_options':option_data
112
- };
113
- migrate_task_need_update=true;
114
- jQuery('#wpvivid_export_download_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
115
- wpvivid_post_request(ajax_data, function (data)
116
- {
117
- }, function (XMLHttpRequest, textStatus, errorThrown)
118
- {
119
- var error_message = wpvivid_output_ajaxerror('test generate url', textStatus, errorThrown);
120
- alert(error_message);
121
- });
122
- }
123
-
124
- var wpvivid_display_get_key = false;
125
-
126
-
127
-
128
- function wpvivid_transfer_cancel_flow()
129
- {
130
- jQuery('#wpvivid_transfer_cancel_btn').click(function(){
131
- wpvivid_cancel_transfer();
132
- });
133
- }
134
-
135
- function wpvivid_cancel_transfer()
136
- {
137
- var ajax_data= {
138
- 'action': 'wpvivid_backup_cancel',
139
- 'task_id': wpvivid_transfer_id
140
- };
141
- jQuery('#wpvivid_transfer_cancel_btn').css({'pointer-events': 'none', 'opacity': '0.4'});
142
- wpvivid_post_request(ajax_data, function(data){
143
- try {
144
- var jsonarray = jQuery.parseJSON(data);
145
- jQuery('#wpvivid_upload_current_doing').html(jsonarray.msg);
146
- }
147
- catch(err){
148
- alert(err);
149
- }
150
- }, function(XMLHttpRequest, textStatus, errorThrown) {
151
- jQuery('#wpvivid_transfer_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
152
- var error_message = wpvivid_output_ajaxerror('cancelling the backup', textStatus, errorThrown);
153
- wpvivid_add_notice('Backup', 'Error', error_message);
154
- });
155
- }
156
-
157
- var migrate_task_need_update=true;
158
- var task_recheck_times=0;
159
- function wpvivid_check_upload_runningtask()
160
- {
161
- var ajax_data = {
162
- 'action': 'wpvivid_list_upload_tasks',
163
- };
164
- if(wpvivid_restoring === false) {
165
- wpvivid_post_request(ajax_data, function (data) {
166
- setTimeout(function () {
167
- wpvivid_manage_upload_task();
168
- }, 3000);
169
- try {
170
- var jsonarray = jQuery.parseJSON(data);
171
- if (jsonarray.transfer_succeed_notice != false) {
172
- jQuery('#wpvivid_backup_notice').show();
173
- jQuery('#wpvivid_backup_notice').append(jsonarray.transfer_succeed_notice);
174
- }
175
- if (jsonarray.transfer_error_notice != false) {
176
- jQuery('#wpvivid_backup_notice').show();
177
- jQuery.each(jsonarray.transfer_error_notice, function (index, value) {
178
- jQuery('#wpvivid_backup_notice').append(value.error_msg);
179
- });
180
- }
181
- var b_need_show = false;
182
- if (jsonarray.transfer.data.length !== 0) {
183
- b_need_show = true;
184
- task_recheck_times = 0;
185
- if (jsonarray.transfer.result === 'success') {
186
- jQuery.each(jsonarray.transfer.data, function (index, value) {
187
- if (value.status.str === 'ready') {
188
- wpvivid_control_transfer_lock();
189
- jQuery('#wpvivid_upload_backup_percent').show();
190
- jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
191
- migrate_task_need_update = true;
192
- }
193
- else if (value.status.str === 'running') {
194
- wpvivid_control_transfer_lock();
195
- jQuery('#wpvivid_upload_backup_percent').show();
196
- jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
197
- migrate_task_need_update = true;
198
- }
199
- else if (value.status.str === 'wait_resume') {
200
- wpvivid_control_transfer_lock();
201
- jQuery('#wpvivid_upload_backup_percent').show();
202
- jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
203
- if (value.data.next_resume_time !== 'get next resume time failed.') {
204
- wpvivid_resume_transfer(index, value.data.next_resume_time);
205
- }
206
- else {
207
- wpvivid_delete_backup_task(index);
208
- }
209
- }
210
- else if (value.status.str === 'no_responds') {
211
- wpvivid_control_transfer_lock();
212
- jQuery('#wpvivid_upload_backup_percent').show();
213
- jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
214
- migrate_task_need_update = true;
215
- }
216
- else if (value.status.str === 'completed') {
217
- wpvivid_control_transfer_unlock();
218
- jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
219
- jQuery('#wpvivid_upload_backup_percent').hide();
220
- migrate_task_need_update = true;
221
- alert('Transfer succeeded. Please scan the backup list on the destination site to display the backup, then restore the backup.');
222
- }
223
- else if (value.status.str === 'error') {
224
- wpvivid_control_transfer_unlock();
225
- jQuery('#wpvivid_upload_backup_percent').html(value.progress_html);
226
- jQuery('#wpvivid_upload_backup_percent').hide();
227
- migrate_task_need_update = true;
228
- }
229
- });
230
- }
231
- wpvivid_transfer_cancel_flow();
232
- }
233
- else{
234
- if(wpvivid_transfer_id != '') {
235
- jQuery('#wpvivid_transfer_cancel_btn').css({'pointer-events': 'auto', 'opacity': '1'});
236
- wpvivid_control_transfer_unlock();
237
- jQuery('#wpvivid_upload_backup_percent').hide();
238
- wpvivid_transfer_id = '';
239
- }
240
- }
241
- }
242
- catch (err) {
243
- alert(err);
244
- }
245
- if (!b_need_show) {
246
- task_recheck_times++;
247
- if (task_recheck_times < 5) {
248
- migrate_task_need_update = true;
249
- }
250
- }
251
-
252
- }, function (XMLHttpRequest, textStatus, errorThrown) {
253
- migrate_task_need_update = true;
254
- setTimeout(function () {
255
- wpvivid_manage_upload_task();
256
- }, 3000);
257
- });
258
- }
259
- }
260
-
261
- function wpvivid_resume_transfer(backup_id, next_resume_time){
262
- if(next_resume_time < 0){
263
- next_resume_time = 0;
264
- }
265
- next_resume_time = next_resume_time * 1000;
266
- setTimeout("wpvivid_activate_migrate_cron()", next_resume_time);
267
- setTimeout(function(){
268
- task_recheck_times = 0;
269
- migrate_task_need_update=true;
270
- }, next_resume_time);
271
- }
272
-
273
- function wpvivid_manage_upload_task()
274
- {
275
- if(migrate_task_need_update){
276
- migrate_task_need_update=false;
277
- wpvivid_check_upload_runningtask();
278
- }
279
- else {
280
- setTimeout(function () {
281
- wpvivid_manage_upload_task();
282
- }, 3000);
283
- }
284
- }
285
-
286
- function wpvivid_activate_migrate_cron(){
287
- var next_get_time = 3 * 60 * 1000;
288
- jQuery.get(wpvivid_home_url+'/wp-cron.php');
289
- setTimeout("wpvivid_activate_migrate_cron()", next_get_time);
290
- setTimeout(function(){
291
- migrate_task_need_update=true;
292
- }, 10000);
293
- }
294
-
295
- function switchmigrateTabs(evt,contentName,storage_page_id) {
296
- // Declare all variables
297
- var i, tabcontent, tablinks;
298
-
299
- // Get all elements with class="table-list-content" and hide them
300
- tabcontent = document.getElementsByClassName("migrate-tab-content");
301
- for (i = 0; i < tabcontent.length; i++) {
302
- tabcontent[i].style.display = "none";
303
- }
304
-
305
- // Get all elements with class="table-nav-tab" and remove the class "nav-tab-active"
306
- tablinks = document.getElementsByClassName("migrate-nav-tab");
307
- for (i = 0; i < tablinks.length; i++) {
308
- tablinks[i].className = tablinks[i].className.replace(" nav-tab-active", "");
309
- }
310
-
311
- // Show the current tab, and add an "storage-menu-active" class to the button that opened the tab
312
- document.getElementById(contentName).style.display = "block";
313
- evt.currentTarget.className += " nav-tab-active";
314
-
315
- var top = jQuery('#'+storage_page_id).offset().top-jQuery('#'+storage_page_id).height();
316
- jQuery('html, body').animate({scrollTop:top}, 'slow');
317
- }
318
-
319
- jQuery(document).ready(function ()
320
- {
321
- <?php
322
- $default_task_type = array();
323
- $default_task_type = apply_filters('wpvivid_get_task_type', $default_task_type);
324
- if(empty($default_task_type)){
325
- ?>
326
- wpvivid_activate_migrate_cron();
327
- wpvivid_manage_upload_task();
328
- <?php
329
- }
330
- ?>
331
- });
332
- </script>
333
- <?php
334
- }
335
-
336
-
337
- public function wpvivid_add_page_migrate(){
338
- $migrate_descript = '';
339
- $migrate_key = '';
340
- $migrate_part_type = '';
341
- $migrate_part_exec = '';
342
- $migrate_part_note = '';
343
- $migrate_part_tip = '';
344
- ?>
345
- <div id="migrate-page" class="wrap-tab-content wpvivid_tab_migrate" name="tab-migrate" style="display: none;">
346
- <div class="postbox wpvivid-element-space-bottom" style="padding: 10px;">
347
- <?php
348
- echo apply_filters('wpvivid_migrate_descript', $migrate_descript);
349
- echo apply_filters('wpvivid_put_transfer_key', $migrate_key);
350
- ?>
351
- </div>
352
-
353
- <div class="postbox wpvivid-element-space-bottom" id="wpvivid_upload_backup_percent" style="display: none;">
354
- <div class="action-progress-bar" id="wpvivid_upload_progress_bar">
355
- <div class="action-progress-bar-percent" id="wpvivid_upload_progress_bar_percent" style="height:24px;width:0"></div>
356
- </div>
357
- <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing"></p></div>
358
- <div style="clear: both;"></div>
359
- <div>
360
- <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-backuprestore' ); ?>" /></div>
361
- </div>
362
- </div>
363
-
364
- <div style="padding: 0 0 10px 0;">
365
-
366
- <?php echo apply_filters('wpvivid_migrate_part_type', $migrate_part_type); ?>
367
-
368
- <?php echo apply_filters('wpvivid_migrate_part_note', $migrate_part_note); ?>
369
-
370
- <div style="padding: 0 0 10px 0;">
371
- <?php echo apply_filters('wpvivid_migrate_part_exec', $migrate_part_exec); ?>
372
- </div>
373
- <div style="clear: both;"></div>
374
- <div style="padding: 10px 0 10px 0;">
375
- <?php echo apply_filters('wpvivid_migrate_part_tip', $migrate_part_tip); ?>
376
- </div>
377
- </div>
378
- </div>
379
- <?php
380
- $js = '';
381
- apply_filters('wpvivid_load_migrate_js', $js);
382
- ?>
383
- <?php
384
- }
385
-
386
- public function wpvivid_add_page_key(){
387
- ?>
388
- <div id="key-page" class="wrap-tab-content wpvivid_tab_key" name="tab-key" style="display: none;">
389
- <div style="padding: 0 0 0 10px">
390
- <div style="padding: 0 0 10px 0">
391
- <span><?php _e('In order to allow another site to send a backup to this site, please generate a key below. Once the key is generated, this site is ready to receive a backup from another site. Then, please copy and paste the key in sending site and save it.', 'wpvivid-backuprestore'); ?></span>
392
- </div>
393
- <strong><?php _e('The key will expire in ', 'wpvivid-backuprestore'); ?></strong>
394
- <select id="wpvivid_generate_url_expires" style="margin-bottom: 2px;">
395
- <option value="2 hour">2 hours</option>
396
- <option selected="selected" value="8 hour">8 hours</option>
397
- <option value="24 hour">24 hours</option>
398
- <!--<option value="Never">Never</option>-->
399
- </select>
400
- <p><?php _e('Tips: For security reason, please choose an appropriate expiration time for the key.', 'wpvivid-backuprestore'); ?></p>
401
- <div>
402
- <input class="button-primary" id="wpvivid_generate_url" type="submit" value="<?php esc_attr_e( 'Generate', 'wpvivid-backuprestore' ); ?>" onclick="wpvivid_click_generate_url();" />
403
- </div>
404
- <div id="wpvivid_test_generate_url" style="padding-top: 10px;">
405
- <textarea id="wpvivid_test_remote_site_url_text" style="width: 100%; height: 140px;"></textarea>
406
- </div>
407
- </div>
408
- </div>
409
- <script>
410
- jQuery("#wpvivid_test_remote_site_url_text").focus(function() {
411
- jQuery(this).select();
412
- jQuery(this).mouseup(function() {
413
- jQuery(this).unbind("mouseup");
414
- return false;
415
- });
416
- });
417
- function wpvivid_click_generate_url()
418
- {
419
- //
420
- var expires=jQuery('#wpvivid_generate_url_expires').val();
421
- var ajax_data = {
422
- 'action': 'wpvivid_generate_url',
423
- 'expires':expires
424
- };
425
- wpvivid_post_request(ajax_data, function (data)
426
- {
427
- jQuery('#wpvivid_test_remote_site_url_text').val(data);
428
- }, function (XMLHttpRequest, textStatus, errorThrown)
429
- {
430
- var error_message = wpvivid_output_ajaxerror('generating key', textStatus, errorThrown);
431
- alert(error_message);
432
- });
433
- }
434
- </script>
435
- <?php
436
- }
437
-
438
- public function test_connect_site()
439
- {
440
- if(isset($_POST['url']))
441
- {
442
- global $wpvivid_plugin;
443
- $wpvivid_plugin->ajax_check_security();
444
-
445
- $url=strtok($_POST['url'],'?');
446
-
447
- if (filter_var($url, FILTER_VALIDATE_URL) === FALSE)
448
- {
449
- $ret['result']=WPVIVID_FAILED;
450
- $ret['error']='The key is invalid.';
451
- echo json_encode($ret);
452
- die();
453
- }
454
-
455
- if($url==home_url())
456
- {
457
- $ret['result']=WPVIVID_FAILED;
458
- $ret['error']='The key generated by this site cannot be added into this site.';
459
- echo json_encode($ret);
460
- die();
461
- }
462
-
463
- $query=parse_url ($_POST['url'],PHP_URL_QUERY);
464
- if($query===null)
465
- {
466
- $query=strtok('?');
467
- }
468
- parse_str($query,$query_arr);
469
- $token=$query_arr['token'];
470
- $expires=$query_arr['expires'];
471
- $domain=$query_arr['domain'];
472
-
473
- if ($expires != 0 && time() > $expires) {
474
- $ret['result'] = 'failed';
475
- $ret['error'] = 'The key has expired.';
476
- echo json_encode($ret);
477
- die();
478
- }
479
-
480
- $json['test_connect']=1;
481
- $json=json_encode($json);
482
- $crypt=new WPvivid_crypt(base64_decode($token));
483
- $data=$crypt->encrypt_message($json);
484
- if($data===false)
485
- {
486
- $ret['result'] = 'failed';
487
- $ret['error'] = 'Data encryption failed.';
488
- echo json_encode($ret);
489
- die();
490
- }
491
- $data=base64_encode($data);
492
-
493
- $args['body']=array('wpvivid_content'=>$data,'wpvivid_action'=>'send_to_site_connect');
494
- $args['timeout']=30;
495
- $response=wp_remote_post($url,$args);
496
-
497
- if ( is_wp_error( $response ) )
498
- {
499
- $ret['result']=WPVIVID_FAILED;
500
- $ret['error']= $response->get_error_message();
501
- }
502
- else
503
- {
504
- if($response['response']['code']==200)
505
- {
506
- $res=json_decode($response['body'],1);
507
- if($res!=null)
508
- {
509
- if($res['result']==WPVIVID_SUCCESS)
510
- {
511
- $ret['result']=WPVIVID_SUCCESS;
512
-
513
- $options=WPvivid_Setting::get_option('wpvivid_saved_api_token');
514
-
515
- $options[$url]['token']=$token;
516
- $options[$url]['url']=$url;
517
- $options[$url]['expires']=$expires;
518
- $options[$url]['domain']=$domain;
519
-
520
- delete_option('wpvivid_saved_api_token');
521
- WPvivid_Setting::update_option('wpvivid_saved_api_token',$options);
522
-
523
- $html='';
524
- $i=0;
525
- foreach ($options as $key=>$site)
526
- {
527
- $check_status='';
528
- if($key==$url)
529
- {
530
- $check_status='checked';
531
- }
532
-
533
- if($site['expires']>time())
534
- {
535
- $date=date("l, F d, Y H:i", $site['expires']);
536
- }
537
- else
538
- {
539
- $date='Token has expired';
540
- }
541
-
542
- $i++;
543
- $html = apply_filters('wpvivid_put_transfer_key', $html);
544
- }
545
- $ret['html']= $html;
546
-
547
- }
548
- else
549
- {
550
- $ret['result']=WPVIVID_FAILED;
551
- $ret['error']= $res['error'];
552
- }
553
- }
554
- else
555
- {
556
- $ret['result']=WPVIVID_FAILED;
557
- $ret['error']= $response['body'];
558
- //$ret['error']= 'failed to parse returned data. Unable to retrieve the correct authorization data via HTTP request.';
559
- }
560
- }
561
- else
562
- {
563
- $ret['result']=WPVIVID_FAILED;
564
- $ret['error']= 'upload error '.$response['response']['code'].' '.$response['body'];
565
- //$response['body']
566
- }
567
- }
568
-
569
- echo json_encode($ret);
570
- }
571
- die();
572
- }
573
-
574
- public function delete_transfer_key()
575
- {
576
- global $wpvivid_plugin;
577
- $wpvivid_plugin->ajax_check_security();
578
- $ret['result']=WPVIVID_SUCCESS;
579
- delete_option('wpvivid_saved_api_token');
580
- $html='';
581
- $html = apply_filters('wpvivid_put_transfer_key', $html);
582
- $ret['html']=$html;
583
- echo json_encode($ret);
584
- die();
585
- }
586
-
587
- public function send_backup_to_site()
588
- {
589
- try {
590
- global $wpvivid_plugin;
591
- $wpvivid_plugin->ajax_check_security();
592
-
593
- $options = WPvivid_Setting::get_option('wpvivid_saved_api_token');
594
-
595
- if (empty($options)) {
596
- $ret['result'] = 'failed';
597
- $ret['error'] = 'A key is required.';
598
- echo json_encode($ret);
599
- die();
600
- }
601
-
602
- $url = '';
603
- foreach ($options as $key => $value) {
604
- $url = $value['url'];
605
- }
606
-
607
- if ($url === '') {
608
- $ret['result'] = 'failed';
609
- $ret['error'] = 'The key is invalid.';
610
- echo json_encode($ret);
611
- die();
612
- }
613
-
614
- if ($options[$url]['expires'] != 0 && $options[$url]['expires'] < time()) {
615
- $ret['result'] = 'failed';
616
- $ret['error'] = 'The key has expired.';
617
- echo json_encode($ret);
618
- die();
619
- }
620
-
621
- $json['test_connect']=1;
622
- $json=json_encode($json);
623
- $crypt=new WPvivid_crypt(base64_decode($options[$url]['token']));
624
- $data=$crypt->encrypt_message($json);
625
- $data=base64_encode($data);
626
- $args['body']=array('wpvivid_content'=>$data,'wpvivid_action'=>'send_to_site_connect');
627
- $response=wp_remote_post($url,$args);
628
-
629
- if ( is_wp_error( $response ) )
630
- {
631
- $ret['result']=WPVIVID_FAILED;
632
- $ret['error']= $response->get_error_message();
633
- echo json_encode($ret);
634
- die();
635
- }
636
- else
637
- {
638
- if($response['response']['code']==200) {
639
- $res=json_decode($response['body'],1);
640
- if($res!=null) {
641
- if($res['result']==WPVIVID_SUCCESS) {
642
- }
643
- else {
644
- $ret['result']=WPVIVID_FAILED;
645
- $ret['error']= $res['error'];
646
- echo json_encode($ret);
647
- die();
648
- }
649
- }
650
- else {
651
- $ret['result']=WPVIVID_FAILED;
652
- $ret['error']= 'failed to parse returned data, unable to establish connection with the target site.';
653
- $ret['response']=$response;
654
- echo json_encode($ret);
655
- die();
656
- }
657
- }
658
- else {
659
- $ret['result']=WPVIVID_FAILED;
660
- $ret['error']= 'upload error '.$response['response']['code'].' '.$response['body'];
661
- echo json_encode($ret);
662
- die();
663
- }
664
- }
665
-
666
- if (WPvivid_taskmanager::is_tasks_backup_running()) {
667
- $ret['result'] = 'failed';
668
- $ret['error'] = __('A task is already running. Please wait until the running task is complete, and try again.', 'wpvivid-backuprestore');
669
- echo json_encode($ret);
670
- die();
671
- }
672
-
673
- $remote_option['url'] = $options[$url]['url'];
674
- $remote_option['token'] = $options[$url]['token'];
675
- $remote_option['type'] = WPVIVID_REMOTE_SEND_TO_SITE;
676
- $remote_options['temp'] = $remote_option;
677
-
678
- $backup_options = stripslashes($_POST['backup_options']);
679
- $backup_options = json_decode($backup_options, true);
680
- $backup['backup_files'] = $backup_options['transfer_type'];
681
- $backup['local'] = 0;
682
- $backup['remote'] = 1;
683
- $backup['ismerge'] = 1;
684
- $backup['lock'] = 0;
685
- $backup['remote_options'] = $remote_options;
686
-
687
- $backup_task = new WPvivid_Backup_Task();
688
- $ret = $backup_task->new_backup_task($backup, 'Manual', 'transfer');
689
-
690
- $task_id = $ret['task_id'];
691
-
692
- global $wpvivid_plugin;
693
- $wpvivid_plugin->check_backup($task_id, $backup);
694
- echo json_encode($ret);
695
- die();
696
- }
697
- catch (Exception $e){
698
- $ret['result'] = 'failed';
699
- $ret['error'] = $e->getMessage();
700
- echo json_encode($ret);
701
- die();
702
- }
703
- }
704
-
705
- public function migrate_now()
706
- {
707
- global $wpvivid_plugin;
708
- $wpvivid_plugin->ajax_check_security();
709
-
710
- if (!isset($_POST['task_id'])||empty($_POST['task_id'])||!is_string($_POST['task_id']))
711
- {
712
- $ret['result']='failed';
713
- $ret['error']=__('Error occurred while parsing the request data. Please try to run backup again.', 'wpvivid-backuprestore');
714
- echo json_encode($ret);
715
- die();
716
- }
717
- $task_id=sanitize_key($_POST['task_id']);
718
-
719
- //flush buffer
720
- $wpvivid_plugin->flush($task_id);
721
- $wpvivid_plugin->backup($task_id);
722
- die();
723
- }
724
-
725
- function export_download_backup()
726
- {
727
- global $wpvivid_plugin;
728
- $wpvivid_plugin->ajax_check_security();
729
-
730
- $schedule_options=WPvivid_Schedule::get_schedule();
731
- if(empty($schedule_options))
732
- {
733
- die();
734
- }
735
- $backup_options = stripslashes($_POST['backup_options']);
736
- $backup_options = json_decode($backup_options, true);
737
- $backup['backup_files']= $backup_options['transfer_type'];
738
- $backup['local']=1;
739
- $backup['remote']=0;
740
- $backup['ismerge']=1;
741
- $backup['lock']=0;
742
- //$backup['remote_options']='';
743
-
744
- $backup_task=new WPvivid_Backup_Task();
745
- $task=$backup_task->new_backup_task($backup,'Manual', 'export');
746
-
747
- $task_id=$task['task_id'];
748
- //add_action('wpvivid_handle_upload_succeed',array($this,'wpvivid_deal_upload_succeed'),11);
749
- $wpvivid_plugin->check_backup($task_id,$backup['backup_files']);
750
- $wpvivid_plugin->flush($task_id);
751
- $wpvivid_plugin->backup($task_id);
752
- //}
753
- die();
754
- }
755
-
756
- function wpvivid_handle_backup_failed($task)
757
- {
758
- global $wpvivid_plugin;
759
- if($task['action'] === 'transfer') {
760
- $backup_error_array = WPvivid_Setting::get_option('wpvivid_transfer_error_array');
761
- if (empty($backup_error_array)) {
762
- $backup_error_array = array();
763
- }
764
- if (!array_key_exists($task['id'], $backup_error_array['bu_error'])) {
765
- $backup_error_array['bu_error']['task_id'] = $task['id'];
766
- $backup_error_array['bu_error']['error_msg'] = $task['status']['error'];
767
- WPvivid_Setting::update_option('wpvivid_transfer_error_array', $backup_error_array);
768
- }
769
- $backup=new WPvivid_Backup($task['id']);
770
- $backup->clean_backup();
771
- $wpvivid_plugin->wpvivid_log->WriteLog('Upload failed. Delete task '.$task['id'], 'notice');
772
- WPvivid_Backuplist::delete_backup($task['id']);
773
- }
774
- }
775
-
776
- public function wpvivid_deal_upload_succeed($task)
777
- {
778
- global $wpvivid_plugin;
779
- if($task['action'] === 'transfer')
780
- {
781
- $backup_success_count = WPvivid_Setting::get_option('wpvivid_transfer_success_count');
782
- if (empty($backup_success_count))
783
- {
784
- $backup_success_count = 0;
785
- }
786
- $backup_success_count++;
787
- WPvivid_Setting::update_option('wpvivid_transfer_success_count', $backup_success_count);
788
-
789
- $wpvivid_plugin->wpvivid_log->WriteLog('Upload finished. Delete task '.$task['id'], 'notice');
790
- WPvivid_Backuplist::delete_backup($task['id']);
791
- }
792
- }
793
-
794
- public function generate_url()
795
- {
796
- include_once WPVIVID_PLUGIN_DIR . '/vendor/autoload.php';
797
-
798
- global $wpvivid_plugin;
799
- $wpvivid_plugin->ajax_check_security();
800
-
801
- $expires=time()+3600;
802
-
803
- if(isset($_POST['expires']))
804
- {
805
- if($_POST['expires']=='1 month')
806
- {
807
- $expires=time()+2592000;
808
- }
809
- else if($_POST['expires']=='1 day')
810
- {
811
- $expires=time()+86400;
812
- }
813
- else if($_POST['expires']=='2 hour')
814
- {
815
- $expires=time()+7200;
816
- }
817
- else if($_POST['expires']=='8 hour')
818
- {
819
- $expires=time()+28800;
820
- }
821
- else if($_POST['expires']=='24 hour')
822
- {
823
- $expires=time()+86400;
824
- }
825
- else if($_POST['expires']=='Never')
826
- {
827
- $expires=0;
828
- }
829
- }
830
-
831
- $key_size = 2048;
832
- $rsa = new Crypt_RSA();
833
- $keys = $rsa->createKey($key_size);
834
- $options['public_key']=base64_encode($keys['publickey']);
835
- $options['private_key']=base64_encode($keys['privatekey']);
836
- $options['expires']=$expires;
837
- $options['domain']=home_url();
838
-
839
- WPvivid_Setting::update_option('wpvivid_api_token',$options);
840
-
841
- $url= $options['domain'];
842
- $url=$url.'?domain='.$options['domain'].'&token='.$options['public_key'].'&expires='.$expires;
843
- echo $url;
844
- die();
845
- }
846
-
847
- public function wpvivid_put_transfer_key($html){
848
- $html='<div id="wpvivid_transfer_key">';
849
- $options=WPvivid_Setting::get_option('wpvivid_saved_api_token');
850
- if(empty($options)){
851
- $html .= '<div style="padding: 0 0 10px 0;"><strong>'.__('Please paste the key below.', 'wpvivid-backuprestore').'</strong><a href="#" style="margin-left: 5px; text-decoration: none;" onclick="wpvivid_click_how_to_get_key();">'.__('How to get a site key?', 'wpvivid-backuprestore').'</a></div>
852
- <div id="wpvivid_how_to_get_key"></div>
853
- <div class="wpvivid-element-space-bottom"><textarea type="text" id="wpvivid_transfer_key_text" onKeyUp="wpvivid_check_key(this.value)" style="width: 100%; height: 140px;"/></textarea></div>
854
- <div><input class="button-primary" id="wpvivid_save_url_button" type="submit" value="'.esc_attr( 'Save', 'wpvivid-backuprestore' ).'" onclick="wpvivid_click_save_site_url();" /></div>';
855
- }
856
- else{
857
- foreach ($options as $key => $value)
858
- {
859
- $token = $value['token'];
860
- $source_dir=home_url();
861
- $target_dir=$value['domain'];
862
- $expires=$value['expires'];
863
-
864
- if ($expires != 0 && time() > $expires) {
865
- $key_status='The key has expired. Please delete it first and generate a new one.';
866
- }
867
- else{
868
- $time_diff = $expires - time();
869
- $key_status = 'The key will expire in: '.date("H:i:s",$time_diff).'. Once the key expires, you need to generate a new key.';
870
- }
871
- }
872
- $html .= '<div style="padding: 0 0 10px 0;">
873
- <span>Key:</span>
874
- <input type="text" id="wpvivid_send_remote_site_url_text" value="'.$token.'" readonly="readonly" />
875
- <input class="button-primary" id="wpvivid_delete_key_button" type="submit" value="'.esc_attr( 'Delete', 'wpvivid-backuprestore' ).'" onclick="wpvivid_click_delete_transfer_key();" />
876
- </div>
877
- <div class="wpvivid-element-space-bottom">'.$key_status.'</div>
878
- <div>The connection is ok. Now you can transfer the site <strong>'.$source_dir.'</strong> to the site <strong>'.$target_dir.'</strong></div>';
879
- }
880
- $html.='</div>
881
- <script>
882
- var source_site = \''.admin_url('admin-ajax.php').'\';
883
- function wpvivid_check_key(value){
884
- var pos = value.indexOf(\'?\');
885
- var site_url = value.substring(0, pos);
886
- if(site_url == source_site){
887
- alert(\'The key generated by this site cannot be added into this site.\');
888
- jQuery(\'#wpvivid_save_url_button\').prop(\'disabled\', true);
889
- }
890
- else{
891
- jQuery("#wpvivid_save_url_button").prop(\'disabled\', false);
892
- }
893
- }
894
-
895
- function wpvivid_click_save_site_url()
896
- {
897
- var url= jQuery(\'#wpvivid_transfer_key_text\').val();
898
- var ajax_data = {
899
- \'action\': \'wpvivid_test_connect_site\',
900
- \'url\':url
901
- };
902
-
903
- jQuery("#wpvivid_save_url_button").prop(\'disabled\', true);
904
- wpvivid_post_request(ajax_data, function (data)
905
- {
906
- jQuery("#wpvivid_save_url_button").prop(\'disabled\', false);
907
- try
908
- {
909
- var jsonarray = jQuery.parseJSON(data);
910
- if(jsonarray.result===\'success\')
911
- {
912
- jQuery(\'#wpvivid_transfer_key\').html(jsonarray.html);
913
- }
914
- else
915
- {
916
- alert(jsonarray.error);
917
- }
918
- }
919
- catch(err)
920
- {
921
- alert(err);
922
- }
923
- }, function (XMLHttpRequest, textStatus, errorThrown)
924
- {
925
- jQuery("#wpvivid_save_url_button").prop(\'disabled\', false);
926
- var error_message = wpvivid_output_ajaxerror(\'saving key\', textStatus, errorThrown);
927
- alert(error_message);
928
- });
929
- }
930
-
931
- function wpvivid_click_delete_transfer_key()
932
- {
933
- var ajax_data = {
934
- \'action\': \'wpvivid_delete_transfer_key\'
935
- };
936
-
937
- jQuery("#wpvivid_delete_key_button").css({\'pointer-events\': \'none\', \'opacity\': \'0.4\'});
938
- wpvivid_post_request(ajax_data, function (data)
939
- {
940
- jQuery("#wpvivid_delete_key_button").css({\'pointer-events\': \'none\', \'opacity\': \'0.4\'});
941
- try
942
- {
943
- var jsonarray = jQuery.parseJSON(data);
944
- if(jsonarray.result===\'success\')
945
- {
946
- jQuery(\'#wpvivid_transfer_key\').html(jsonarray.html);
947
- }
948
- }
949
- catch(err)
950
- {
951
- alert(err);
952
- }
953
- }, function (XMLHttpRequest, textStatus, errorThrown)
954
- {
955
- jQuery("#wpvivid_delete_key_button").css({\'pointer-events\': \'auto\', \'opacity\': \'1\'});
956
- var error_message = wpvivid_output_ajaxerror(\'deleting key\', textStatus, errorThrown);
957
- alert(error_message);
958
- });
959
- }
960
-
961
- function click_dismiss_key_notice(obj){
962
- wpvivid_display_get_key = false;
963
- jQuery(obj).parent().remove();
964
- }
965
-
966
- function wpvivid_click_how_to_get_key(){
967
- if(!wpvivid_display_get_key) {
968
- wpvivid_display_get_key = true;
969
- var div = "<div class=\'notice notice-info is-dismissible inline\'>" +
970
- "<p>" + wpvividlion.get_key_step1 + "</p>" +
971
- "<p>" + wpvividlion.get_key_step2 + "</p>" +
972
- "<p>" + wpvividlion.get_key_step3 + "</p>" +
973
- "<button type=\'button\' class=\'notice-dismiss\' onclick=\'click_dismiss_key_notice(this);\'>" +
974
- "<span class=\'screen-reader-text\'>Dismiss this notice.</span>" +
975
- "</button>" +
976
- "</div>";
977
- jQuery(\'#wpvivid_how_to_get_key\').append(div);
978
- }
979
- }
980
- </script>';
981
- return $html;
982
- }
983
-
984
- public function wpvivid_migrate_descript($html){
985
- $html .= '<div style="padding: 0 0 10px 0;">
986
- '.__('The feature can help you transfer a Wordpress site to a new domain(site). It would be a convenient way to migrate your WP site from dev environment to live server or from old server to the new.', 'wpvivid-backuprestore').'
987
- </div>';
988
- return $html;
989
- }
990
-
991
- public function wpvivid_migrate_part_type($html){
992
- $migrate_type = '';
993
- $type_name = 'transfer_type';
994
- $html = '<div class="postbox quicktransfer">
995
- <div class="wpvivid-element-space-bottom">
996
- <h2 style="padding: 0;"><span>'.__( 'Choose the content you want to transfer', 'wpvivid-backuprestore').'</span></h2>
997
- </div>
998
- <div class="quickstart-archive-block">
999
- <fieldset>
1000
- <legend class="screen-reader-text"><span>input type="radio"</span></legend>
1001
- '.apply_filters('wpvivid_add_migrate_type', $migrate_type, $type_name).'
1002
- </fieldset>
1003
- </div>
1004
- </div>';
1005
- return $html;
1006
- }
1007
-
1008
- public function wpvivid_migrate_part_exec($html){
1009
- $html = '';
1010
- $html .= '<div id="wpvivid_transfer_btn" style="float: left;">
1011
- <input class="button-primary quicktransfer-btn" type="submit" value="'.esc_attr( 'Clone then Transfer', 'wpvivid-backuprestore').'" onclick="wpvivid_click_send_backup();" />
1012
- </div>
1013
- <script>
1014
- function wpvivid_click_send_backup()
1015
- {
1016
- //send_to_remote
1017
- var option_data = wpvivid_ajax_data_transfer(\'migrate\');
1018
- var ajax_data = {
1019
- \'action\': \'wpvivid_send_backup_to_site\',
1020
- \'backup_options\':option_data
1021
- };
1022
- migrate_task_need_update=true;
1023
- wpvivid_clear_notice(\'wpvivid_backup_notice\');
1024
- wpvivid_control_transfer_lock();
1025
- wpvivid_post_request(ajax_data, function (data)
1026
- {
1027
- try
1028
- {
1029
- var jsonarray = jQuery.parseJSON(data);
1030
- if(jsonarray.result===\'failed\')
1031
- {
1032
- wpvivid_delete_transfer_ready_task(jsonarray.error);
1033
- }
1034
- else{
1035
- wpvivid_transfer_id = jsonarray.task_id;
1036
- wpvivid_migrate_now(jsonarray.task_id);
1037
- }
1038
- }
1039
- catch(err)
1040
- {
1041
- wpvivid_delete_transfer_ready_task(err);
1042
- }
1043
- }, function (XMLHttpRequest, textStatus, errorThrown)
1044
- {
1045
- var error_message = wpvivid_output_ajaxerror(\'trying to establish communication with your server\', textStatus, errorThrown);
1046
- wpvivid_delete_transfer_ready_task(error_message);
1047
- });
1048
- }
1049
-
1050
- function wpvivid_migrate_now(task_id){
1051
- var ajax_data = {
1052
- \'action\': \'wpvivid_migrate_now\',
1053
- \'task_id\': task_id
1054
- };
1055
- task_recheck_times = 0;
1056
- migrate_task_need_update=true;
1057
- wpvivid_post_request(ajax_data, function(data){
1058
- }, function(XMLHttpRequest, textStatus, errorThrown) {
1059
- });
1060
- }
1061
-
1062
- function wpvivid_delete_transfer_ready_task(error){
1063
- var ajax_data={
1064
- \'action\': \'wpvivid_delete_ready_task\'
1065
- };
1066
- wpvivid_post_request(ajax_data, function (data) {
1067
- try {
1068
- var jsonarray = jQuery.parseJSON(data);
1069
- if (jsonarray.result === \'success\') {
1070
- wpvivid_add_notice(\'Backup\', \'Error\', error);
1071
- wpvivid_control_transfer_unlock();
1072
- jQuery(\'#wpvivid_upload_backup_percent\').hide();
1073
- }
1074
- }
1075
- catch(err){
1076
- wpvivid_add_notice(\'Backup\', \'Error\', err);
1077
- wpvivid_control_transfer_unlock();
1078
- jQuery(\'#wpvivid_upload_backup_percent\').hide();
1079
- }
1080
- }, function (XMLHttpRequest, textStatus, errorThrown) {
1081
- setTimeout(function () {
1082
- wpvivid_delete_transfer_ready_task(error);
1083
- }, 3000);
1084
- });
1085
- }
1086
- </script>';
1087
- return $html;
1088
- }
1089
-
1090
- public function wpvivid_migrate_part_note($html){
1091
- $html .= '<p>'.__('Note: ', 'wpvivid-backuprestore').'</p>
1092
- <p>'.__('1. In order to successfully complete the migration, you\'d better deactivate <a href="https://wpvivid.com/best-redirect-plugins.html" target="_blank" style="text-decoration: none;">301 redirect plugin</a>, <a href="https://wpvivid.com/8-best-wordpress-firewall-plugins.html" target="_blank" style="text-decoration: none;">firewall and security plugin</a>, and <a href="https://wpvivid.com/best-free-wordpress-caching-plugins.html" target="_blank" style="text-decoration: none;">caching plugin</a> (if they exist) before transferring website.', 'wpvivid-backuprestore').'</p>
1093
- <p>'.__('2. Please migrate website with the manual way when using <strong>Local by Flywheel</strong> environment.', 'wpvivid-backuprestore').'</p>';
1094
- return $html;
1095
- }
1096
-
1097
- public function wpvivid_migrate_part_tip($html){
1098
- $backupdir=WPvivid_Setting::get_backupdir();
1099
- $html .= '<p>'.__('<strong>Tips: </strong>The unstable connection between sites could cause a failure of files transfer. In this case, uploading backups to destination site is a good alternative to the automatic website migration.', 'wpvivid-backuprestore').'</p>
1100
- <p><strong>'.__('How to migrate Wordpress site manually to a new domain(site) with WPvivid backup plugin?', 'wpvivid-backuprestore').'</strong></p>
1101
- <p>'.__('1. Download a backup in backups list to your computer.', 'wpvivid-backuprestore').'</p>
1102
- <p>'.__('2. Upload the backup to destination site. There are two ways available to use:', 'wpvivid-backuprestore').'</p>
1103
- <p style="margin-left: 20px;">'.__('2.1 Upload the backup to the upload section of WPvivid backup plugin in destination site.', 'wpvivid-backuprestore').'</p>
1104
- <p style="margin-left: 20px;">'.sprintf(__('2.2 Upload the backup with FTP client to backup directory %s in destination site, then click <strong>Scan uploaded backup or received backup</strong> button.', 'wpvivid-backuprestore'), WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backupdir).'</p>
1105
- <p>'.__('3. Once done, the backup appears in backups list. Then, restore the backup.', 'wpvivid-backuprestore').'</p>';
1106
- return $html;
1107
- }
1108
-
1109
- public function wpvivid_add_migrate_type($html, $name_type){
1110
- $html .= '<label>
1111
- <input type="radio" option="migrate" name="'.$name_type.'" value="files+db" checked />
1112
- <span>'.__( 'Database + Files (WordPress Files)', 'wpvivid-backuprestore' ).'</span>
1113
- </label><br>
1114
- <label>
1115
- <input type="radio" option="migrate" name="'.$name_type.'" value="files" />
1116
- <span>'.__( 'WordPress Files (Exclude Database)', 'wpvivid-backuprestore' ).'</span>
1117
- </label><br>
1118
- <label>
1119
- <input type="radio" option="migrate" name="'.$name_type.'" value="db" />
1120
- <span>'.__( 'Only Database', 'wpvivid-backuprestore' ).'</span>
1121
- </label><br>
1122
- <label>
1123
- <div style="float: left;">
1124
- <input type="radio" disabled />
1125
- <span class="wpvivid-element-space-right" style="color: #ddd;">'.__('Choose what to migrate', 'wpvivid-backuprestore').'</span>
1126
- </div>
1127
- <span class="wpvivid-feature-pro">
1128
- <a href="https://docs.wpvivid.com/custom-migration-overview.html" style="text-decoration: none;">'.__('Pro feature: learn more', 'wpvivid-backuprestore').'</a>
1129
- </span>
1130
- </label><br>';
1131
- return $html;
1132
- }
1133
-
1134
- public function list_tasks()
1135
- {
1136
- global $wpvivid_plugin;
1137
- $wpvivid_plugin->ajax_check_security();
1138
- $tasks=WPvivid_Setting::get_tasks();
1139
- $ret=array();
1140
- $list_tasks=array();
1141
- foreach ($tasks as $task)
1142
- {
1143
- if($task['action']=='transfer')
1144
- {
1145
- $backup=new WPvivid_Backup_Task($task['id']);
1146
- $list_tasks[$task['id']]=$backup->get_backup_task_info($task['id']);
1147
- if($list_tasks[$task['id']]['task_info']['need_next_schedule']===true){
1148
- $timestamp = wp_next_scheduled(WPVIVID_TASK_MONITOR_EVENT,array($task['id']));
1149
-
1150
- if($timestamp===false)
1151
- {
1152
- $wpvivid_plugin->add_monitor_event($task['id'],20);
1153
- }
1154
- }
1155
- if($list_tasks[$task['id']]['task_info']['need_update_last_task']===true){
1156
- $task_msg = WPvivid_taskmanager::get_task($task['id']);
1157
- $wpvivid_plugin->update_last_backup_task($task_msg);
1158
- }
1159
- $list_tasks[$task['id']]['progress_html'] = '<div class="action-progress-bar" id="wpvivid_upload_progress_bar">
1160
- <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>
1161
- </div>
1162
- <div id="wpvivid_estimate_backup_info" style="float:left;">
1163
- <div class="backup-basic-info"><span class="wpvivid-element-space-right">' . __('Database Size:', 'wpvivid-backuprestore') . '</span><span>' . $list_tasks[$task['id']]['task_info']['db_size'] . '</span></div>
1164
- <div class="backup-basic-info"><span class="wpvivid-element-space-right">' . __('File Size:', 'wpvivid-backuprestore') . '</span><span>' . $list_tasks[$task['id']]['task_info']['file_size'] . '</span></div>
1165
- </div>
1166
- <div id="wpvivid_estimate_upload_info" style="float: left;">
1167
- <div class="backup-basic-info"><span class="wpvivid-element-space-right">' . __('Total Size:', 'wpvivid-backuprestore') . '</span><span>' . $list_tasks[$task['id']]['task_info']['total'] . '</span></div>
1168
- <div class="backup-basic-info"><span class="wpvivid-element-space-right">' . __('Uploaded:', 'wpvivid-backuprestore') . '</span><span>' . $list_tasks[$task['id']]['task_info']['upload'] . '</span></div>
1169
- <div class="backup-basic-info"><span class="wpvivid-element-space-right">' . __('Speed:', 'wpvivid-backuprestore') . '</span><span>' . $list_tasks[$task['id']]['task_info']['speed'] . '</span></div>
1170
- </div>
1171
- <div style="float: left;">
1172
- <div class="backup-basic-info"><span class="wpvivid-element-space-right">' . __('Network Connection:', 'wpvivid-backuprestore') . '</span><span>' . $list_tasks[$task['id']]['task_info']['network_connection'] . '</span></div>
1173
- </div>
1174
- <div style="clear:both;"></div>
1175
- <div style="margin-left:10px; float: left; width:100%;"><p id="wpvivid_upload_current_doing">' . $list_tasks[$task['id']]['task_info']['descript'] . '</p></div>
1176
- <div style="clear: both;"></div>
1177
- <div>
1178
- <div id="wpvivid_transfer_cancel" class="backup-log-btn"><input class="button-primary" id="wpvivid_transfer_cancel_btn" type="submit" value="'.esc_attr( 'Cancel', 'wpvivid-backuprestore' ).'" /></div>
1179
- </div>';
1180
- }
1181
- }
1182
- WPvivid_taskmanager::delete_marked_task();
1183
-
1184
- $backup_success_count=WPvivid_Setting::get_option('wpvivid_transfer_success_count');
1185
- if(!empty($backup_success_count)){
1186
- $notice_msg = __('Transfer succeeded. Please scan the backup list on the destination site to display the backup, then restore the backup.', 'wpvivid-backuprestore');
1187
- $success_notice_html='<div class="notice notice-success is-dismissible inline"><p>'.$notice_msg.'</p>
1188
- <button type="button" class="notice-dismiss" onclick="click_dismiss_notice(this);">
1189
- <span class="screen-reader-text">Dismiss this notice.</span>
1190
- </button>
1191
- </div>';
1192
- WPvivid_Setting::delete_option('wpvivid_transfer_success_count');
1193
- }
1194
- else {
1195
- $success_notice_html = false;
1196
- }
1197
- $ret['transfer_succeed_notice'] = $success_notice_html;
1198
-
1199
- $backup_error_array=WPvivid_Setting::get_option('wpvivid_transfer_error_array');
1200
- if(!empty($backup_error_array)){
1201
- $error_notice_html = array();
1202
- foreach ($backup_error_array as $key => $value){
1203
- $notice_msg = 'Transfer failed, '.$value['error_msg'];
1204
- $error_notice_html['bu_error']['task_id']=$value['task_id'];
1205
- $error_notice_html['bu_error']['error_msg']='<div class="notice notice-error inline"><p>'.$notice_msg.'</p></div>';
1206
- }
1207
- WPvivid_Setting::delete_option('wpvivid_transfer_error_array');
1208
- }
1209
- else{
1210
- $error_notice_html = false;
1211
- }
1212
- $ret['transfer_error_notice'] = $error_notice_html;
1213
-
1214
- $ret['transfer']['result']='success';
1215
- $ret['transfer']['data']=$list_tasks;
1216
-
1217
- if(!empty($task_ids))
1218
- {
1219
- foreach ($task_ids as $id)
1220
- {
1221
- WPvivid_Setting::delete_task($id);
1222
- }
1223
- }
1224
-
1225
- echo json_encode($ret);
1226
- die();
1227
- }
1228
-
1229
- function wpvivid_rescan_backup_list(){
1230
- ?>
1231
- <div style="padding: 0 0 10px 0;">
1232
- <?php
1233
- Wpvivid_BackupUploader::rescan_local_folder();
1234
- ?>
1235
- </div>
1236
- <?php
1237
- }
1238
-
1239
- public function wpvivid_backuppage_load_backuplist($backuplist_array){
1240
- $backuplist_array['list_upload'] = array('index' => '2', 'tab_func' => array($this, 'wpvivid_add_tab_upload'), 'page_func' => array($this, 'wpvivid_add_page_upload'));
1241
- return $backuplist_array;
1242
- }
1243
-
1244
- function wpvivid_add_tab_upload(){
1245
- ?>
1246
- <a href="#" id="wpvivid_tab_upload" class="nav-tab backup-nav-tab" onclick="switchrestoreTabs(event,'page-upload')"><?php _e('Upload', 'wpvivid-backuprestore'); ?></a>
1247
- <?php
1248
- }
1249
-
1250
- function wpvivid_add_page_upload(){
1251
- $backupdir=WPvivid_Setting::get_backupdir();
1252
- ?>
1253
- <div class="backup-tab-content wpvivid_tab_upload" id="page-upload" style="display:none;">
1254
- <div style="padding: 10px 0 10px 0;">
1255
- <div style="padding-bottom: 10px;">
1256
- <span><?php echo sprintf(__('The backups will be uploaded to %s directory.', 'wpvivid-backuprestore'), WP_CONTENT_DIR.DIRECTORY_SEPARATOR.$backupdir); ?></span>
1257
- </div>
1258
- <div style="padding-bottom: 10px;">
1259
- <span><?php echo __('Note: The files you want to upload must be a backup created by WPvivid backup plugin. Make sure that uploading every part of a backup to the directory if the backup is split into many parts', 'wpvivid-backuprestore'); ?></span>
1260
- </div>
1261
- <?php
1262
- Wpvivid_BackupUploader::upload_meta_box();
1263
- ?>
1264
- </div>
1265
- </div>
1266
- <?php
1267
- }
1268
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-mysqldump-method.php DELETED
@@ -1,1626 +0,0 @@
1
- <?php
2
-
3
- use PDO as PDO;
4
- use PDOException as PDOException;
5
-
6
- /**
7
- * Enum with all available compression methods
8
- *
9
- */
10
-
11
- abstract class CompressMethod
12
- {
13
- public static $enums = array(
14
- "None",
15
- "Gzip",
16
- "Bzip2"
17
- );
18
-
19
- /**
20
- * @param string $c
21
- * @return boolean
22
- */
23
- public static function isValid($c)
24
- {
25
- return in_array($c, self::$enums);
26
- }
27
- }
28
-
29
- abstract class CompressManagerFactory
30
- {
31
- /**
32
- * @param string $c
33
- * @return CompressBzip2|CompressGzip|CompressNone
34
- */
35
- public static function create($c)
36
- {
37
- $c = ucfirst(strtolower($c));
38
- if (! CompressMethod::isValid($c)) {
39
- throw new Exception("Compression method ($c) is not defined yet");
40
- }
41
-
42
- $method = __NAMESPACE__ . "\\" . "Compress" . $c;
43
-
44
- return new $method;
45
- }
46
- }
47
-
48
- class CompressBzip2 extends CompressManagerFactory
49
- {
50
- private $fileHandler = null;
51
-
52
- public function __construct()
53
- {
54
- if (! function_exists("bzopen")) {
55
- throw new Exception("Compression is enabled, but bzip2 lib is not installed or configured properly");
56
- }
57
- }
58
-
59
- /**
60
- * @param string $filename
61
- */
62
- public function open($filename)
63
- {
64
- $this->fileHandler = bzopen($filename, "w");
65
- if (false === $this->fileHandler) {
66
- throw new Exception("Output file is not writable");
67
- }
68
-
69
- return true;
70
- }
71
-
72
- public function write($str)
73
- {
74
- if (false === ($bytesWritten = bzwrite($this->fileHandler, $str))) {
75
- throw new Exception("Writting to file failed! Probably, there is no more free space left?");
76
- }
77
- return $bytesWritten;
78
- }
79
-
80
- public function close()
81
- {
82
- return bzclose($this->fileHandler);
83
- }
84
- }
85
-
86
- class CompressGzip extends CompressManagerFactory
87
- {
88
- private $fileHandler = null;
89
-
90
- public function __construct()
91
- {
92
- if (! function_exists("gzopen")) {
93
- throw new Exception("Compression is enabled, but gzip lib is not installed or configured properly");
94
- }
95
- }
96
-
97
- /**
98
- * @param string $filename
99
- */
100
- public function open($filename)
101
- {
102
- $this->fileHandler = gzopen($filename, "wb");
103
- if (false === $this->fileHandler) {
104
- throw new Exception("Output file is not writable");
105
- }
106
-
107
- return true;
108
- }
109
-
110
- public function write($str)
111
- {
112
- if (false === ($bytesWritten = gzwrite($this->fileHandler, $str))) {
113
- throw new Exception("Writting to file failed! Probably, there is no more free space left?");
114
- }
115
- return $bytesWritten;
116
- }
117
-
118
- public function close()
119
- {
120
- return gzclose($this->fileHandler);
121
- }
122
- }
123
-
124
- class CompressNone extends CompressManagerFactory
125
- {
126
- private $fileHandler = null;
127
-
128
- /**
129
- * @param string $filename
130
- */
131
- public function open($filename)
132
- {
133
- $this->fileHandler = fopen($filename, "wb");
134
- if (false === $this->fileHandler) {
135
- throw new Exception("Output file is not writable");
136
- }
137
-
138
- return true;
139
- }
140
-
141
- public function write($str)
142
- {
143
- if (false === ($bytesWritten = fwrite($this->fileHandler, $str))) {
144
- throw new Exception("Writting to file failed! Probably, there is no more free space left?");
145
- }
146
- return $bytesWritten;
147
- }
148
-
149
- public function close()
150
- {
151
- return fclose($this->fileHandler);
152
- }
153
- }
154
-
155
- /**
156
- * Enum with all available TypeAdapter implementations
157
- *
158
- */
159
- abstract class TypeAdapter
160
- {
161
- public static $enums = array(
162
- "Sqlite",
163
- "Mysql",
164
- "Wpdb"
165
- );
166
-
167
- /**
168
- * @param string $c
169
- * @return boolean
170
- */
171
- public static function isValid($c)
172
- {
173
- return in_array($c, self::$enums);
174
- }
175
- }
176
-
177
- /**
178
- * TypeAdapter Factory
179
- *
180
- */
181
- abstract class TypeAdapterFactory
182
- {
183
- /**
184
- * @param string $c Type of database factory to create (Mysql, Sqlite,...)
185
- * @param PDO $dbHandler
186
- */
187
- public static function create($c, $dbHandler = null)
188
- {
189
- $c = ucfirst(strtolower($c));
190
- if (! TypeAdapter::isValid($c)) {
191
- if($c === 'Mysql'){
192
- $c = 'PDO_MySQL';
193
- }
194
- throw new Exception("Database type support for ($c) not yet available");
195
- }
196
- $method = __NAMESPACE__ . "\\" . "TypeAdapter" . $c;
197
- return new $method($dbHandler);
198
- }
199
-
200
- /**
201
- * function databases Add sql to create and use database
202
- * @todo make it do something with sqlite
203
- */
204
- public function databases()
205
- {
206
- return "";
207
- }
208
-
209
- public function show_create_table($tableName)
210
- {
211
- return "SELECT tbl_name as 'Table', sql as 'Create Table' " .
212
- "FROM sqlite_master " .
213
- "WHERE type='table' AND tbl_name='$tableName'";
214
- }
215
-
216
- /**
217
- * function create_table Get table creation code from database
218
- * @todo make it do something with sqlite
219
- */
220
- public function create_table($row, $dumpSettings)
221
- {
222
- return "";
223
- }
224
-
225
- public function show_create_view($viewName)
226
- {
227
- return "SELECT tbl_name as 'View', sql as 'Create View' " .
228
- "FROM sqlite_master " .
229
- "WHERE type='view' AND tbl_name='$viewName'";
230
- }
231
-
232
- /**
233
- * function create_view Get view creation code from database
234
- * @todo make it do something with sqlite
235
- */
236
- public function create_view($row)
237
- {
238
- return "";
239
- }
240
-
241
- /**
242
- * function show_create_trigger Get trigger creation code from database
243
- * @todo make it do something with sqlite
244
- */
245
- public function show_create_trigger($triggerName)
246
- {
247
- return "";
248
- }
249
-
250
- /**
251
- * function create_trigger Modify trigger code, add delimiters, etc
252
- * @todo make it do something with sqlite
253
- */
254
- public function create_trigger($triggerName)
255
- {
256
- return "";
257
- }
258
-
259
- /**
260
- * function create_procedure Modify procedure code, add delimiters, etc
261
- * @todo make it do something with sqlite
262
- */
263
- public function create_procedure($procedureName, $dumpSettings)
264
- {
265
- return "";
266
- }
267
-
268
- public function show_tables()
269
- {
270
- return "SELECT tbl_name FROM sqlite_master WHERE type='table'";
271
- }
272
-
273
- public function show_views()
274
- {
275
- return "SELECT tbl_name FROM sqlite_master WHERE type='view'";
276
- }
277
-
278
- public function show_triggers()
279
- {
280
- return "SELECT name FROM sqlite_master WHERE type='trigger'";
281
- }
282
-
283
- public function show_columns()
284
- {
285
- if (func_num_args() != 1) {
286
- return "";
287
- }
288
-
289
- $args = func_get_args();
290
-
291
- return "pragma table_info(${args[0]})";
292
- }
293
-
294
- public function show_procedures()
295
- {
296
- return "";
297
- }
298
-
299
- public function show_events()
300
- {
301
- return "";
302
- }
303
-
304
- public function setup_transaction()
305
- {
306
- return "";
307
- }
308
-
309
- public function start_transaction()
310
- {
311
- return "BEGIN EXCLUSIVE";
312
- }
313
-
314
- public function commit_transaction()
315
- {
316
- return "COMMIT";
317
- }
318
-
319
- public function lock_table()
320
- {
321
- return "";
322
- }
323
-
324
- public function unlock_table()
325
- {
326
- return "";
327
- }
328
-
329
- public function start_add_lock_table()
330
- {
331
- return PHP_EOL;
332
- }
333
-
334
- public function end_add_lock_table()
335
- {
336
- return PHP_EOL;
337
- }
338
-
339
- public function start_add_disable_keys()
340
- {
341
- return PHP_EOL;
342
- }
343
-
344
- public function end_add_disable_keys()
345
- {
346
- return PHP_EOL;
347
- }
348
-
349
- public function start_disable_foreign_keys_check()
350
- {
351
- return PHP_EOL;
352
- }
353
-
354
- public function end_disable_foreign_keys_check()
355
- {
356
- return PHP_EOL;
357
- }
358
-
359
- public function add_drop_database()
360
- {
361
- return PHP_EOL;
362
- }
363
-
364
- public function add_drop_trigger()
365
- {
366
- return PHP_EOL;
367
- }
368
-
369
- public function drop_table()
370
- {
371
- return PHP_EOL;
372
- }
373
-
374
- public function drop_view()
375
- {
376
- return PHP_EOL;
377
- }
378
-
379
- /**
380
- * Decode column metadata and fill info structure.
381
- * type, is_numeric and is_blob will always be available.
382
- *
383
- * @param array $colType Array returned from "SHOW COLUMNS FROM tableName"
384
- * @return array
385
- */
386
- public function parseColumnType($colType)
387
- {
388
- return array();
389
- }
390
-
391
- public function backup_parameters()
392
- {
393
- return PHP_EOL;
394
- }
395
-
396
- public function restore_parameters()
397
- {
398
- return PHP_EOL;
399
- }
400
- }
401
-
402
- class TypeAdapterPgsql extends TypeAdapterFactory
403
- {
404
- }
405
-
406
- class TypeAdapterDblib extends TypeAdapterFactory
407
- {
408
- }
409
-
410
- class TypeAdapterSqlite extends TypeAdapterFactory
411
- {
412
- }
413
-
414
-
415
-
416
- class TypeAdapterMysql extends TypeAdapterFactory
417
- {
418
-
419
- private $dbHandler = null;
420
-
421
- private $dsn;
422
- private $user;
423
- private $pass;
424
- private $pdoSettings;
425
- private $reconnect_count;
426
-
427
- // Numerical Mysql types
428
- public $mysqlTypes = array(
429
- 'numerical' => array(
430
- 'bit',
431
- 'tinyint',
432
- 'smallint',
433
- 'mediumint',
434
- 'int',
435
- 'integer',
436
- 'bigint',
437
- 'real',
438
- 'double',
439
- 'float',
440
- 'decimal',
441
- 'numeric'
442
- ),
443
- 'blob' => array(
444
- 'tinyblob',
445
- 'blob',
446
- 'mediumblob',
447
- 'longblob',
448
- 'binary',
449
- 'varbinary',
450
- 'bit',
451
- 'geometry', /* http://bugs.mysql.com/bug.php?id=43544 */
452
- 'point',
453
- 'linestring',
454
- 'polygon',
455
- 'multipoint',
456
- 'multilinestring',
457
- 'multipolygon',
458
- 'geometrycollection',
459
- )
460
- );
461
-
462
- public function __construct ($dbHandler)
463
- {
464
- $pdoSettingsDefault = array(
465
- PDO::ATTR_PERSISTENT => true,
466
- PDO::ATTR_ERRMODE => PDO::ERRMODE_WARNING,
467
- PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => false
468
- );
469
-
470
- $this->dbHandler = $dbHandler;
471
- $this->dsn='';
472
- $this->user='';
473
- $this->pass='';
474
- $this->pdoSettings=$pdoSettingsDefault;
475
- $this->reconnect_count=0;
476
- }
477
-
478
- public function set_connect_info($dsn,$user,$pass,$pdoSetting)
479
- {
480
- $this->dsn=$dsn;
481
- $this->user=$user;
482
- $this->pass=$pass;
483
- $this->pdoSettings=$pdoSetting;
484
- }
485
-
486
- public function connect($host,$dbname,$user,$pass,$init_commands=array())
487
- {
488
- if(empty($host))
489
- {
490
- $host=DB_HOST;
491
- }
492
- $res = explode(':',$host);
493
- $db_host = $res[0];
494
- $db_port = empty($res[1])?'':$res[1];
495
- if(!empty($db_port)) {
496
- $this->dsn='mysql:host=' . $db_host . ';port=' . $db_port . ';dbname=' . $dbname;
497
- }
498
- else{
499
- $this->dsn='mysql:host=' . $db_host . ';dbname=' . $dbname;
500
- }
501
- $this->user=$user;
502
- $this->pass=$pass;
503
- $this->dbHandler = @new PDO(
504
- $this->dsn,
505
- $this->user,
506
- $this->pass,
507
- $this->pdoSettings
508
- );
509
- // Execute init commands once connected
510
- foreach($init_commands as $stmt)
511
- {
512
- $this->dbHandler->exec($stmt);
513
- }
514
- $this->dbHandler->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_NATURAL);
515
- }
516
-
517
- public function errorInfo()
518
- {
519
- $error=$this->dbHandler->errorInfo();
520
- return $error;
521
- }
522
-
523
- public function quote($colValue)
524
- {
525
- return $this->dbHandler->quote($colValue);
526
- }
527
-
528
-
529
- public function databases()
530
- {
531
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
532
- $args = func_get_args();
533
- $databaseName = $args[0];
534
-
535
- $resultSet = $this->query("SHOW VARIABLES LIKE 'character_set_database';");
536
- $characterSet = $resultSet->fetchColumn(1);
537
- $resultSet->closeCursor();
538
-
539
- $resultSet = $this->query("SHOW VARIABLES LIKE 'collation_database';");
540
- $collationDb = $resultSet->fetchColumn(1);
541
- $resultSet->closeCursor();
542
- $ret = "";
543
-
544
- $ret .= "CREATE DATABASE /*!32312 IF NOT EXISTS*/ `${databaseName}`".
545
- " /*!40100 DEFAULT CHARACTER SET ${characterSet} " .
546
- " COLLATE ${collationDb} */;" . PHP_EOL . PHP_EOL .
547
- "USE `${databaseName}`;" . PHP_EOL . PHP_EOL;
548
-
549
- return $ret;
550
- }
551
-
552
- public function show_create_table($tableName)
553
- {
554
- return "SHOW CREATE TABLE `$tableName`";
555
- }
556
-
557
- public function show_create_view($viewName)
558
- {
559
- return "SHOW CREATE VIEW `$viewName`";
560
- }
561
-
562
- public function show_create_trigger($triggerName)
563
- {
564
- return "SHOW CREATE TRIGGER `$triggerName`";
565
- }
566
-
567
- public function show_create_procedure($procedureName)
568
- {
569
- return "SHOW CREATE PROCEDURE `$procedureName`";
570
- }
571
-
572
- public function show_create_event($eventName)
573
- {
574
- return "SHOW CREATE EVENT `$eventName`";
575
- }
576
-
577
- public function create_table( $row, $dumpSettings )
578
- {
579
-
580
- if ( !isset($row['Create Table']) ) {
581
- throw new Exception("Error getting table code, unknown output");
582
- }
583
-
584
- $createTable = str_replace('\'0000-00-00 00:00:00\'','\'1999-01-01 00:00:00\'',$row['Create Table']);
585
-
586
- if ( $dumpSettings['reset-auto-increment'] ) {
587
- $match = "/AUTO_INCREMENT=[0-9]+/s";
588
- $replace = "";
589
- $createTable = preg_replace($match, $replace, $createTable);
590
- }
591
-
592
- $ret = "/*!40101 SET @saved_cs_client = @@character_set_client */;" . PHP_EOL .
593
- "/*!40101 SET character_set_client = " . $dumpSettings['default-character-set'] . " */;" . PHP_EOL .
594
- $createTable . ";" . PHP_EOL .
595
- "/*!40101 SET character_set_client = @saved_cs_client */;" . PHP_EOL .
596
- PHP_EOL;
597
- return $ret;
598
- }
599
-
600
- public function create_view($row)
601
- {
602
- $ret = "";
603
- if (!isset($row['Create View'])) {
604
- throw new Exception("Error getting view structure, unknown output");
605
- }
606
-
607
- $triggerStmt = $row['Create View'];
608
-
609
- $triggerStmtReplaced1 = str_replace(
610
- "CREATE ALGORITHM",
611
- "/*!50001 CREATE ALGORITHM",
612
- $triggerStmt
613
- );
614
- $triggerStmtReplaced2 = str_replace(
615
- " DEFINER=",
616
- " */" . PHP_EOL . "/*!50013 DEFINER=",
617
- $triggerStmtReplaced1
618
- );
619
- $triggerStmtReplaced3 = str_replace(
620
- " VIEW ",
621
- " */" . PHP_EOL . "/*!50001 VIEW ",
622
- $triggerStmtReplaced2
623
- );
624
- if (false === $triggerStmtReplaced1 ||
625
- false === $triggerStmtReplaced2 ||
626
- false === $triggerStmtReplaced3) {
627
- $triggerStmtReplaced = $triggerStmt;
628
- } else {
629
- $triggerStmtReplaced = $triggerStmtReplaced3 . " */;";
630
- }
631
-
632
- $ret .= $triggerStmtReplaced . PHP_EOL . PHP_EOL;
633
- return $ret;
634
- }
635
-
636
- public function create_trigger($row)
637
- {
638
- $ret = "";
639
- if (!isset($row['SQL Original Statement'])) {
640
- throw new Exception("Error getting trigger code, unknown output");
641
- }
642
-
643
- $triggerStmt = $row['SQL Original Statement'];
644
- $triggerStmtReplaced = str_replace(
645
- "CREATE DEFINER",
646
- "/*!50003 CREATE*/ /*!50017 DEFINER",
647
- $triggerStmt
648
- );
649
- $triggerStmtReplaced = str_replace(
650
- " TRIGGER",
651
- "*/ /*!50003 TRIGGER",
652
- $triggerStmtReplaced
653
- );
654
- if ( false === $triggerStmtReplaced ) {
655
- $triggerStmtReplaced = $triggerStmt . " /* ";
656
- }
657
-
658
- $ret .= "DELIMITER ;;" . PHP_EOL .
659
- $triggerStmtReplaced . " */ ;;" . PHP_EOL .
660
- "DELIMITER ;" . PHP_EOL . PHP_EOL;
661
- return $ret;
662
- }
663
-
664
- public function create_procedure($row, $dumpSettings)
665
- {
666
- $ret = "";
667
- if (!isset($row['Create Procedure'])) {
668
- throw new Exception("Error getting procedure code, unknown output. " .
669
- "Please check 'https://bugs.mysql.com/bug.php?id=14564'");
670
- }
671
- $procedureStmt = $row['Create Procedure'];
672
-
673
- $ret .= "/*!50003 DROP PROCEDURE IF EXISTS `" .
674
- $row['Procedure'] . "` */;" . PHP_EOL .
675
- "/*!40101 SET @saved_cs_client = @@character_set_client */;" . PHP_EOL .
676
- "/*!40101 SET character_set_client = " . $dumpSettings['default-character-set'] . " */;" . PHP_EOL .
677
- "DELIMITER ;;" . PHP_EOL .
678
- $procedureStmt . " ;;" . PHP_EOL .
679
- "DELIMITER ;" . PHP_EOL .
680
- "/*!40101 SET character_set_client = @saved_cs_client */;" . PHP_EOL . PHP_EOL;
681
-
682
- return $ret;
683
- }
684
-
685
- public function create_event($row)
686
- {
687
- $ret = "";
688
- if ( !isset($row['Create Event']) ) {
689
- throw new Exception("Error getting event code, unknown output. " .
690
- "Please check 'http://stackoverflow.com/questions/10853826/mysql-5-5-create-event-gives-syntax-error'");
691
- }
692
- $eventName = $row['Event'];
693
- $eventStmt = $row['Create Event'];
694
- $sqlMode = $row['sql_mode'];
695
-
696
- $eventStmtReplaced = str_replace(
697
- "CREATE DEFINER",
698
- "/*!50106 CREATE*/ /*!50117 DEFINER",
699
- $eventStmt
700
- );
701
- $eventStmtReplaced = str_replace(
702
- " EVENT ",
703
- "*/ /*!50106 EVENT ",
704
- $eventStmtReplaced
705
- );
706
-
707
- if ( false === $eventStmtReplaced ) {
708
- $eventStmtReplaced = $eventStmt . " /* ";
709
- }
710
-
711
- $ret .= "/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;" . PHP_EOL .
712
- "/*!50106 DROP EVENT IF EXISTS `" . $eventName . "` */;" . PHP_EOL .
713
- "DELIMITER ;;" . PHP_EOL .
714
- "/*!50003 SET @saved_cs_client = @@character_set_client */ ;;" . PHP_EOL .
715
- "/*!50003 SET @saved_cs_results = @@character_set_results */ ;;" . PHP_EOL .
716
- "/*!50003 SET @saved_col_connection = @@collation_connection */ ;;" . PHP_EOL .
717
- "/*!50003 SET character_set_client = utf8 */ ;;" . PHP_EOL .
718
- "/*!50003 SET character_set_results = utf8 */ ;;" . PHP_EOL .
719
- "/*!50003 SET collation_connection = utf8_general_ci */ ;;" . PHP_EOL .
720
- "/*!50003 SET @saved_sql_mode = @@sql_mode */ ;;" . PHP_EOL .
721
- "/*!50003 SET sql_mode = '" . $sqlMode . "' */ ;;" . PHP_EOL .
722
- "/*!50003 SET @saved_time_zone = @@time_zone */ ;;" . PHP_EOL .
723
- "/*!50003 SET time_zone = 'SYSTEM' */ ;;" . PHP_EOL .
724
- $eventStmtReplaced . " */ ;;" . PHP_EOL .
725
- "/*!50003 SET time_zone = @saved_time_zone */ ;;" . PHP_EOL .
726
- "/*!50003 SET sql_mode = @saved_sql_mode */ ;;" . PHP_EOL .
727
- "/*!50003 SET character_set_client = @saved_cs_client */ ;;" . PHP_EOL .
728
- "/*!50003 SET character_set_results = @saved_cs_results */ ;;" . PHP_EOL .
729
- "/*!50003 SET collation_connection = @saved_col_connection */ ;;" . PHP_EOL .
730
- "DELIMITER ;" . PHP_EOL .
731
- "/*!50106 SET TIME_ZONE= @save_time_zone */ ;" . PHP_EOL . PHP_EOL;
732
- // Commented because we are doing this in restore_parameters()
733
- // "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;" . PHP_EOL . PHP_EOL;
734
-
735
- return $ret;
736
- }
737
-
738
- public function show_tables()
739
- {
740
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
741
- $args = func_get_args();
742
- return "SELECT TABLE_NAME AS tbl_name " .
743
- "FROM INFORMATION_SCHEMA.TABLES " .
744
- "WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='${args[0]}'";
745
- }
746
-
747
- public function show_views()
748
- {
749
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
750
- $args = func_get_args();
751
- return "SELECT TABLE_NAME AS tbl_name " .
752
- "FROM INFORMATION_SCHEMA.TABLES " .
753
- "WHERE TABLE_TYPE='VIEW' AND TABLE_SCHEMA='${args[0]}'";
754
- }
755
-
756
- public function show_triggers()
757
- {
758
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
759
- $args = func_get_args();
760
- return "SHOW TRIGGERS FROM `${args[0]}`;";
761
- }
762
-
763
- public function show_columns()
764
- {
765
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
766
- $args = func_get_args();
767
- return "SHOW COLUMNS FROM `${args[0]}`;";
768
- }
769
-
770
- public function show_procedures()
771
- {
772
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
773
- $args = func_get_args();
774
- return "SELECT SPECIFIC_NAME AS procedure_name " .
775
- "FROM INFORMATION_SCHEMA.ROUTINES " .
776
- "WHERE ROUTINE_TYPE='PROCEDURE' AND ROUTINE_SCHEMA='${args[0]}'";
777
- }
778
-
779
- /**
780
- * Get query string to ask for names of events from current database.
781
- *
782
- * @param string Name of database
783
- * @return string
784
- */
785
- public function show_events()
786
- {
787
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
788
- $args = func_get_args();
789
- return "SELECT EVENT_NAME AS event_name " .
790
- "FROM INFORMATION_SCHEMA.EVENTS " .
791
- "WHERE EVENT_SCHEMA='${args[0]}'";
792
- }
793
-
794
- public function setup_transaction()
795
- {
796
- return "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ";
797
- }
798
-
799
- public function start_transaction()
800
- {
801
- return "START TRANSACTION";
802
- }
803
-
804
- public function commit_transaction()
805
- {
806
- return "COMMIT";
807
- }
808
-
809
- public function lock_table()
810
- {
811
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
812
- $args = func_get_args();
813
- return $this->dbHandler->exec("LOCK TABLES `${args[0]}` READ LOCAL");
814
-
815
- }
816
-
817
- public function unlock_table()
818
- {
819
- return $this->dbHandler->exec("UNLOCK TABLES");
820
- }
821
-
822
- public function start_add_lock_table()
823
- {
824
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
825
- $args = func_get_args();
826
- return "LOCK TABLES `${args[0]}` WRITE;" . PHP_EOL;
827
- }
828
-
829
- public function end_add_lock_table()
830
- {
831
- return "UNLOCK TABLES;" . PHP_EOL;
832
- }
833
-
834
- public function start_add_disable_keys()
835
- {
836
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
837
- $args = func_get_args();
838
- return "/*!40000 ALTER TABLE `${args[0]}` DISABLE KEYS */;" .
839
- PHP_EOL;
840
- }
841
-
842
- public function end_add_disable_keys()
843
- {
844
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
845
- $args = func_get_args();
846
- return "/*!40000 ALTER TABLE `${args[0]}` ENABLE KEYS */;" .
847
- PHP_EOL;
848
- }
849
-
850
- public function start_disable_autocommit()
851
- {
852
- return "SET autocommit=0;" . PHP_EOL;
853
- }
854
-
855
- public function end_disable_autocommit()
856
- {
857
- return "COMMIT;" . PHP_EOL;
858
- }
859
-
860
- public function add_drop_database()
861
- {
862
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
863
- $args = func_get_args();
864
- return "/*!40000 DROP DATABASE IF EXISTS `${args[0]}`*/;" .
865
- PHP_EOL . PHP_EOL;
866
- }
867
-
868
- public function add_drop_trigger()
869
- {
870
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
871
- $args = func_get_args();
872
- return "DROP TRIGGER IF EXISTS `${args[0]}`;" . PHP_EOL;
873
- }
874
-
875
- public function drop_table()
876
- {
877
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
878
- $args = func_get_args();
879
- return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL;
880
- }
881
-
882
- public function drop_view()
883
- {
884
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
885
- $args = func_get_args();
886
- return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL .
887
- "/*!50001 DROP VIEW IF EXISTS `${args[0]}`*/;" . PHP_EOL;
888
- }
889
-
890
- public function getDatabaseHeader()
891
- {
892
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
893
- $args = func_get_args();
894
- return "--" . PHP_EOL .
895
- "-- Current Database: `${args[0]}`" . PHP_EOL .
896
- "--" . PHP_EOL . PHP_EOL;
897
- }
898
-
899
- /**
900
- * Decode column metadata and fill info structure.
901
- * type, is_numeric and is_blob will always be available.
902
- *
903
- * @param array $colType Array returned from "SHOW COLUMNS FROM tableName"
904
- * @return array
905
- */
906
- public function parseColumnType($colType)
907
- {
908
- $colInfo = array();
909
- $colParts = explode(" ", $colType['Type']);
910
-
911
- if($fparen = strpos($colParts[0], "("))
912
- {
913
- $colInfo['type'] = substr($colParts[0], 0, $fparen);
914
- $colInfo['length'] = str_replace(")", "", substr($colParts[0], $fparen+1));
915
- $colInfo['attributes'] = isset($colParts[1]) ? $colParts[1] : NULL;
916
- }
917
- else
918
- {
919
- $colInfo['type'] = $colParts[0];
920
- }
921
- $colInfo['is_numeric'] = in_array($colInfo['type'], $this->mysqlTypes['numerical']);
922
- $colInfo['is_blob'] = in_array($colInfo['type'], $this->mysqlTypes['blob']);
923
- // for virtual 'Extra' -> "STORED GENERATED"
924
- $colInfo['is_virtual'] = strpos($colType['Extra'], "STORED GENERATED") === false ? false : true;
925
-
926
- return $colInfo;
927
- }
928
-
929
- public function get_connection_charset($wpdb = null) {
930
- if (null === $wpdb) {
931
- global $wpdb;
932
- }
933
-
934
- $charset = (defined('DB_CHARSET') && DB_CHARSET) ? DB_CHARSET : 'utf8mb4';
935
-
936
- if (method_exists($wpdb, 'determine_charset')) {
937
- $charset_collate = $wpdb->determine_charset($charset, '');
938
- if (!empty($charset_collate['charset'])) $charset = $charset_collate['charset'];
939
- }
940
-
941
- return $charset;
942
- }
943
-
944
- public function backup_parameters()
945
- {
946
- global $wpdb;
947
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
948
- $args = func_get_args();
949
- $dumpSettings = $args[0];
950
- $ret = "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;" . PHP_EOL .
951
- "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;" . PHP_EOL .
952
- "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;" . PHP_EOL .
953
- "/*!40101 SET NAMES " . $this->get_connection_charset($wpdb) . " */;" . PHP_EOL;
954
-
955
- if (false === $dumpSettings['skip-tz-utc']) {
956
- $ret .= "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;" . PHP_EOL .
957
- "/*!40103 SET TIME_ZONE='+00:00' */;" . PHP_EOL;
958
- }
959
-
960
- $ret .= "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;" . PHP_EOL .
961
- "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;" . PHP_EOL .
962
- "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;" . PHP_EOL .
963
- "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;" . PHP_EOL .PHP_EOL;
964
-
965
- return $ret;
966
- }
967
-
968
- public function restore_parameters()
969
- {
970
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
971
- $args = func_get_args();
972
- $dumpSettings = $args[0];
973
- $ret = "";
974
-
975
- if (false === $dumpSettings['skip-tz-utc']) {
976
- $ret .= "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;" . PHP_EOL;
977
- }
978
-
979
- $ret .= "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;" . PHP_EOL .
980
- "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;" . PHP_EOL .
981
- "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;" . PHP_EOL .
982
- "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;" . PHP_EOL .
983
- "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;" . PHP_EOL .
984
- "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;" . PHP_EOL .
985
- "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;" . PHP_EOL . PHP_EOL;
986
-
987
- return $ret;
988
- }
989
-
990
- /**
991
- * Check number of parameters passed to function, useful when inheriting.
992
- * Raise exception if unexpected.
993
- *
994
- * @param integer $num_args
995
- * @param integer $expected_num_args
996
- * @param string $method_name
997
- */
998
- private function check_parameters($num_args, $expected_num_args, $method_name)
999
- {
1000
- if ( $num_args != $expected_num_args ) {
1001
- throw new Exception("Unexpected parameter passed to $method_name");
1002
- }
1003
- return;
1004
- }
1005
-
1006
- public function query($string)
1007
- {
1008
- $ret= $this->dbHandler->query($string);
1009
-
1010
- if($ret===false)
1011
- {
1012
- $info=$this->dbHandler->errorInfo();
1013
- if($info[1] == 2006)
1014
- {
1015
- if($this->reconnect_count>3)
1016
- {
1017
- throw new Exception("MySQL server has gone away. Too many reconnect.");
1018
- }
1019
- $this->reconnect();
1020
- $this->reconnect_count++;
1021
- $ret= $this->dbHandler->query($string);
1022
- if($ret!==false)
1023
- {
1024
- $ret->setFetchMode(PDO::FETCH_ASSOC);
1025
- }
1026
- }
1027
- }
1028
- else
1029
- {
1030
- $ret->setFetchMode(PDO::FETCH_ASSOC);
1031
- }
1032
-
1033
- return $ret;
1034
- }
1035
-
1036
- public function exec($string)
1037
- {
1038
- $ret=$this->dbHandler->exec($string);
1039
-
1040
- if($ret===false)
1041
- {
1042
- $info=$this->dbHandler->errorInfo();
1043
- if($info[1] == 2006)
1044
- {
1045
- if($this->reconnect_count>3)
1046
- {
1047
- throw new Exception("MySQL server has gone away. Too many reconnect.");
1048
- }
1049
- $this->reconnect();
1050
- $this->reconnect_count++;
1051
- $ret= $this->dbHandler->exec($string);
1052
- }
1053
- }
1054
- return $ret;
1055
- }
1056
-
1057
- public function reconnect()
1058
- {
1059
- $this->dbHandler = @new PDO(
1060
- $this->dsn,
1061
- $this->user,
1062
- $this->pass,
1063
- $this->pdoSettings
1064
- );
1065
- }
1066
-
1067
- public function closeCursor($resultSet)
1068
- {
1069
- $resultSet->closeCursor();
1070
- }
1071
- }
1072
-
1073
- class TypeAdapterWpdb extends TypeAdapterFactory
1074
- {
1075
-
1076
- private $dbHandler = null;
1077
-
1078
- // Numerical Mysql types
1079
- public $mysqlTypes = array(
1080
- 'numerical' => array(
1081
- 'bit',
1082
- 'tinyint',
1083
- 'smallint',
1084
- 'mediumint',
1085
- 'int',
1086
- 'integer',
1087
- 'bigint',
1088
- 'real',
1089
- 'double',
1090
- 'float',
1091
- 'decimal',
1092
- 'numeric'
1093
- ),
1094
- 'blob' => array(
1095
- 'tinyblob',
1096
- 'blob',
1097
- 'mediumblob',
1098
- 'longblob',
1099
- 'binary',
1100
- 'varbinary',
1101
- 'bit',
1102
- 'geometry', /* http://bugs.mysql.com/bug.php?id=43544 */
1103
- 'point',
1104
- 'linestring',
1105
- 'polygon',
1106
- 'multipoint',
1107
- 'multilinestring',
1108
- 'multipolygon',
1109
- 'geometrycollection',
1110
- )
1111
- );
1112
-
1113
- public function __construct ($dbHandler)
1114
- {
1115
- $this->dbHandler = $dbHandler;
1116
- }
1117
-
1118
- public function connect($host,$dbname,$user,$pass,$init_commands=array())
1119
- {
1120
- global $wpdb;
1121
-
1122
- $this->dbHandler=$wpdb;
1123
- }
1124
-
1125
- public function databases()
1126
- {
1127
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1128
- $args = func_get_args();
1129
- $databaseName = $args[0];
1130
-
1131
- $resultSet = $this->query("SHOW VARIABLES LIKE 'character_set_database';");
1132
- $characterSet = $resultSet->fetchColumn(1);
1133
- $resultSet->closeCursor();
1134
-
1135
- $resultSet = $this->query("SHOW VARIABLES LIKE 'collation_database';");
1136
- $collationDb = $resultSet->fetchColumn(1);
1137
- $resultSet->closeCursor();
1138
- $ret = "";
1139
-
1140
- $ret .= "CREATE DATABASE /*!32312 IF NOT EXISTS*/ `${databaseName}`".
1141
- " /*!40100 DEFAULT CHARACTER SET ${characterSet} " .
1142
- " COLLATE ${collationDb} */;" . PHP_EOL . PHP_EOL .
1143
- "USE `${databaseName}`;" . PHP_EOL . PHP_EOL;
1144
-
1145
- return $ret;
1146
- }
1147
-
1148
- public function show_create_table($tableName)
1149
- {
1150
- return "SHOW CREATE TABLE `$tableName`";
1151
- }
1152
-
1153
- public function show_create_view($viewName)
1154
- {
1155
- return "SHOW CREATE VIEW `$viewName`";
1156
- }
1157
-
1158
- public function show_create_trigger($triggerName)
1159
- {
1160
- return "SHOW CREATE TRIGGER `$triggerName`";
1161
- }
1162
-
1163
- public function show_create_procedure($procedureName)
1164
- {
1165
- return "SHOW CREATE PROCEDURE `$procedureName`";
1166
- }
1167
-
1168
- public function show_create_event($eventName)
1169
- {
1170
- return "SHOW CREATE EVENT `$eventName`";
1171
- }
1172
-
1173
- public function create_table( $row, $dumpSettings )
1174
- {
1175
-
1176
- if ( !isset($row['Create Table']) ) {
1177
- throw new Exception("Error getting table code, unknown output");
1178
- }
1179
-
1180
- $createTable = str_replace('\'0000-00-00 00:00:00\'','\'1999-01-01 00:00:00\'',$row['Create Table']);
1181
-
1182
- if ( $dumpSettings['reset-auto-increment'] ) {
1183
- $match = "/AUTO_INCREMENT=[0-9]+/s";
1184
- $replace = "";
1185
- $createTable = preg_replace($match, $replace, $createTable);
1186
- }
1187
-
1188
- $ret = "/*!40101 SET @saved_cs_client = @@character_set_client */;" . PHP_EOL .
1189
- "/*!40101 SET character_set_client = " . $dumpSettings['default-character-set'] . " */;" . PHP_EOL .
1190
- $createTable . ";" . PHP_EOL .
1191
- "/*!40101 SET character_set_client = @saved_cs_client */;" . PHP_EOL .
1192
- PHP_EOL;
1193
- return $ret;
1194
- }
1195
-
1196
- public function create_view($row)
1197
- {
1198
- $ret = "";
1199
- if (!isset($row['Create View'])) {
1200
- throw new Exception("Error getting view structure, unknown output");
1201
- }
1202
-
1203
- $triggerStmt = $row['Create View'];
1204
-
1205
- $triggerStmtReplaced1 = str_replace(
1206
- "CREATE ALGORITHM",
1207
- "/*!50001 CREATE ALGORITHM",
1208
- $triggerStmt
1209
- );
1210
- $triggerStmtReplaced2 = str_replace(
1211
- " DEFINER=",
1212
- " */" . PHP_EOL . "/*!50013 DEFINER=",
1213
- $triggerStmtReplaced1
1214
- );
1215
- $triggerStmtReplaced3 = str_replace(
1216
- " VIEW ",
1217
- " */" . PHP_EOL . "/*!50001 VIEW ",
1218
- $triggerStmtReplaced2
1219
- );
1220
- if (false === $triggerStmtReplaced1 ||
1221
- false === $triggerStmtReplaced2 ||
1222
- false === $triggerStmtReplaced3) {
1223
- $triggerStmtReplaced = $triggerStmt;
1224
- } else {
1225
- $triggerStmtReplaced = $triggerStmtReplaced3 . " */;";
1226
- }
1227
-
1228
- $ret .= $triggerStmtReplaced . PHP_EOL . PHP_EOL;
1229
- return $ret;
1230
- }
1231
-
1232
- public function create_trigger($row)
1233
- {
1234
- $ret = "";
1235
- if (!isset($row['SQL Original Statement'])) {
1236
- throw new Exception("Error getting trigger code, unknown output");
1237
- }
1238
-
1239
- $triggerStmt = $row['SQL Original Statement'];
1240
- $triggerStmtReplaced = str_replace(
1241
- "CREATE DEFINER",
1242
- "/*!50003 CREATE*/ /*!50017 DEFINER",
1243
- $triggerStmt
1244
- );
1245
- $triggerStmtReplaced = str_replace(
1246
- " TRIGGER",
1247
- "*/ /*!50003 TRIGGER",
1248
- $triggerStmtReplaced
1249
- );
1250
- if ( false === $triggerStmtReplaced ) {
1251
- $triggerStmtReplaced = $triggerStmt . " /* ";
1252
- }
1253
-
1254
- $ret .= "DELIMITER ;;" . PHP_EOL .
1255
- $triggerStmtReplaced . " */ ;;" . PHP_EOL .
1256
- "DELIMITER ;" . PHP_EOL . PHP_EOL;
1257
- return $ret;
1258
- }
1259
-
1260
- public function create_procedure($row, $dumpSettings)
1261
- {
1262
- $ret = "";
1263
- if (!isset($row['Create Procedure'])) {
1264
- throw new Exception("Error getting procedure code, unknown output. " .
1265
- "Please check 'https://bugs.mysql.com/bug.php?id=14564'");
1266
- }
1267
- $procedureStmt = $row['Create Procedure'];
1268
-
1269
- $ret .= "/*!50003 DROP PROCEDURE IF EXISTS `" .
1270
- $row['Procedure'] . "` */;" . PHP_EOL .
1271
- "/*!40101 SET @saved_cs_client = @@character_set_client */;" . PHP_EOL .
1272
- "/*!40101 SET character_set_client = " . $dumpSettings['default-character-set'] . " */;" . PHP_EOL .
1273
- "DELIMITER ;;" . PHP_EOL .
1274
- $procedureStmt . " ;;" . PHP_EOL .
1275
- "DELIMITER ;" . PHP_EOL .
1276
- "/*!40101 SET character_set_client = @saved_cs_client */;" . PHP_EOL . PHP_EOL;
1277
-
1278
- return $ret;
1279
- }
1280
-
1281
- public function create_event($row)
1282
- {
1283
- $ret = "";
1284
- if ( !isset($row['Create Event']) ) {
1285
- throw new Exception("Error getting event code, unknown output. " .
1286
- "Please check 'http://stackoverflow.com/questions/10853826/mysql-5-5-create-event-gives-syntax-error'");
1287
- }
1288
- $eventName = $row['Event'];
1289
- $eventStmt = $row['Create Event'];
1290
- $sqlMode = $row['sql_mode'];
1291
-
1292
- $eventStmtReplaced = str_replace(
1293
- "CREATE DEFINER",
1294
- "/*!50106 CREATE*/ /*!50117 DEFINER",
1295
- $eventStmt
1296
- );
1297
- $eventStmtReplaced = str_replace(
1298
- " EVENT ",
1299
- "*/ /*!50106 EVENT ",
1300
- $eventStmtReplaced
1301
- );
1302
-
1303
- if ( false === $eventStmtReplaced ) {
1304
- $eventStmtReplaced = $eventStmt . " /* ";
1305
- }
1306
-
1307
- $ret .= "/*!50106 SET @save_time_zone= @@TIME_ZONE */ ;" . PHP_EOL .
1308
- "/*!50106 DROP EVENT IF EXISTS `" . $eventName . "` */;" . PHP_EOL .
1309
- "DELIMITER ;;" . PHP_EOL .
1310
- "/*!50003 SET @saved_cs_client = @@character_set_client */ ;;" . PHP_EOL .
1311
- "/*!50003 SET @saved_cs_results = @@character_set_results */ ;;" . PHP_EOL .
1312
- "/*!50003 SET @saved_col_connection = @@collation_connection */ ;;" . PHP_EOL .
1313
- "/*!50003 SET character_set_client = utf8 */ ;;" . PHP_EOL .
1314
- "/*!50003 SET character_set_results = utf8 */ ;;" . PHP_EOL .
1315
- "/*!50003 SET collation_connection = utf8_general_ci */ ;;" . PHP_EOL .
1316
- "/*!50003 SET @saved_sql_mode = @@sql_mode */ ;;" . PHP_EOL .
1317
- "/*!50003 SET sql_mode = '" . $sqlMode . "' */ ;;" . PHP_EOL .
1318
- "/*!50003 SET @saved_time_zone = @@time_zone */ ;;" . PHP_EOL .
1319
- "/*!50003 SET time_zone = 'SYSTEM' */ ;;" . PHP_EOL .
1320
- $eventStmtReplaced . " */ ;;" . PHP_EOL .
1321
- "/*!50003 SET time_zone = @saved_time_zone */ ;;" . PHP_EOL .
1322
- "/*!50003 SET sql_mode = @saved_sql_mode */ ;;" . PHP_EOL .
1323
- "/*!50003 SET character_set_client = @saved_cs_client */ ;;" . PHP_EOL .
1324
- "/*!50003 SET character_set_results = @saved_cs_results */ ;;" . PHP_EOL .
1325
- "/*!50003 SET collation_connection = @saved_col_connection */ ;;" . PHP_EOL .
1326
- "DELIMITER ;" . PHP_EOL .
1327
- "/*!50106 SET TIME_ZONE= @save_time_zone */ ;" . PHP_EOL . PHP_EOL;
1328
- // Commented because we are doing this in restore_parameters()
1329
- // "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;" . PHP_EOL . PHP_EOL;
1330
-
1331
- return $ret;
1332
- }
1333
-
1334
- public function show_tables()
1335
- {
1336
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1337
- $args = func_get_args();
1338
- return "SELECT TABLE_NAME AS tbl_name " .
1339
- "FROM INFORMATION_SCHEMA.TABLES " .
1340
- "WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='${args[0]}'";
1341
- }
1342
-
1343
- public function show_views()
1344
- {
1345
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1346
- $args = func_get_args();
1347
- return "SELECT TABLE_NAME AS tbl_name " .
1348
- "FROM INFORMATION_SCHEMA.TABLES " .
1349
- "WHERE TABLE_TYPE='VIEW' AND TABLE_SCHEMA='${args[0]}'";
1350
- }
1351
-
1352
- public function show_triggers()
1353
- {
1354
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1355
- $args = func_get_args();
1356
- return "SHOW TRIGGERS FROM `${args[0]}`;";
1357
- }
1358
-
1359
- public function show_columns()
1360
- {
1361
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1362
- $args = func_get_args();
1363
- return "SHOW COLUMNS FROM `${args[0]}`;";
1364
- }
1365
-
1366
- public function show_procedures()
1367
- {
1368
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1369
- $args = func_get_args();
1370
- return "SELECT SPECIFIC_NAME AS procedure_name " .
1371
- "FROM INFORMATION_SCHEMA.ROUTINES " .
1372
- "WHERE ROUTINE_TYPE='PROCEDURE' AND ROUTINE_SCHEMA='${args[0]}'";
1373
- }
1374
-
1375
- /**
1376
- * Get query string to ask for names of events from current database.
1377
- *
1378
- * @param string Name of database
1379
- * @return string
1380
- */
1381
- public function show_events()
1382
- {
1383
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1384
- $args = func_get_args();
1385
- return "SELECT EVENT_NAME AS event_name " .
1386
- "FROM INFORMATION_SCHEMA.EVENTS " .
1387
- "WHERE EVENT_SCHEMA='${args[0]}'";
1388
- }
1389
-
1390
- public function setup_transaction()
1391
- {
1392
- return "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ";
1393
- }
1394
-
1395
- public function start_transaction()
1396
- {
1397
- return "START TRANSACTION";
1398
- }
1399
-
1400
- public function commit_transaction()
1401
- {
1402
- return "COMMIT";
1403
- }
1404
-
1405
- public function lock_table()
1406
- {
1407
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1408
- $args = func_get_args();
1409
- return $this->dbHandler->get_results("LOCK TABLES `${args[0]}` READ LOCAL",ARRAY_A);
1410
-
1411
- }
1412
-
1413
- public function unlock_table()
1414
- {
1415
- return $this->dbHandler->get_results("UNLOCK TABLES",ARRAY_A);
1416
- }
1417
-
1418
- public function start_add_lock_table()
1419
- {
1420
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1421
- $args = func_get_args();
1422
- return "LOCK TABLES `${args[0]}` WRITE;" . PHP_EOL;
1423
- }
1424
-
1425
- public function end_add_lock_table()
1426
- {
1427
- return "UNLOCK TABLES;" . PHP_EOL;
1428
- }
1429
-
1430
- public function start_add_disable_keys()
1431
- {
1432
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1433
- $args = func_get_args();
1434
- return "/*!40000 ALTER TABLE `${args[0]}` DISABLE KEYS */;" .
1435
- PHP_EOL;
1436
- }
1437
-
1438
- public function end_add_disable_keys()
1439
- {
1440
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1441
- $args = func_get_args();
1442
- return "/*!40000 ALTER TABLE `${args[0]}` ENABLE KEYS */;" .
1443
- PHP_EOL;
1444
- }
1445
-
1446
- public function start_disable_autocommit()
1447
- {
1448
- return "SET autocommit=0;" . PHP_EOL;
1449
- }
1450
-
1451
- public function end_disable_autocommit()
1452
- {
1453
- return "COMMIT;" . PHP_EOL;
1454
- }
1455
-
1456
- public function add_drop_database()
1457
- {
1458
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1459
- $args = func_get_args();
1460
- return "/*!40000 DROP DATABASE IF EXISTS `${args[0]}`*/;" .
1461
- PHP_EOL . PHP_EOL;
1462
- }
1463
-
1464
- public function add_drop_trigger()
1465
- {
1466
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1467
- $args = func_get_args();
1468
- return "DROP TRIGGER IF EXISTS `${args[0]}`;" . PHP_EOL;
1469
- }
1470
-
1471
- public function drop_table()
1472
- {
1473
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1474
- $args = func_get_args();
1475
- return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL;
1476
- }
1477
-
1478
- public function drop_view()
1479
- {
1480
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1481
- $args = func_get_args();
1482
- return "DROP TABLE IF EXISTS `${args[0]}`;" . PHP_EOL .
1483
- "/*!50001 DROP VIEW IF EXISTS `${args[0]}`*/;" . PHP_EOL;
1484
- }
1485
-
1486
- public function getDatabaseHeader()
1487
- {
1488
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1489
- $args = func_get_args();
1490
- return "--" . PHP_EOL .
1491
- "-- Current Database: `${args[0]}`" . PHP_EOL .
1492
- "--" . PHP_EOL . PHP_EOL;
1493
- }
1494
-
1495
- /**
1496
- * Decode column metadata and fill info structure.
1497
- * type, is_numeric and is_blob will always be available.
1498
- *
1499
- * @param array $colType Array returned from "SHOW COLUMNS FROM tableName"
1500
- * @return array
1501
- */
1502
- public function parseColumnType($colType)
1503
- {
1504
- $colInfo = array();
1505
- $colParts = explode(" ", $colType['Type']);
1506
-
1507
- if($fparen = strpos($colParts[0], "("))
1508
- {
1509
- $colInfo['type'] = substr($colParts[0], 0, $fparen);
1510
- $colInfo['length'] = str_replace(")", "", substr($colParts[0], $fparen+1));
1511
- $colInfo['attributes'] = isset($colParts[1]) ? $colParts[1] : NULL;
1512
- }
1513
- else
1514
- {
1515
- $colInfo['type'] = $colParts[0];
1516
- }
1517
- $colInfo['is_numeric'] = in_array($colInfo['type'], $this->mysqlTypes['numerical']);
1518
- $colInfo['is_blob'] = in_array($colInfo['type'], $this->mysqlTypes['blob']);
1519
- // for virtual 'Extra' -> "STORED GENERATED"
1520
- $colInfo['is_virtual'] = strpos($colType['Extra'], "STORED GENERATED") === false ? false : true;
1521
-
1522
- return $colInfo;
1523
- }
1524
-
1525
- public function get_connection_charset($wpdb = null) {
1526
- if (null === $wpdb) {
1527
- global $wpdb;
1528
- }
1529
-
1530
- $charset = (defined('DB_CHARSET') && DB_CHARSET) ? DB_CHARSET : 'utf8mb4';
1531
-
1532
- if (method_exists($wpdb, 'determine_charset')) {
1533
- $charset_collate = $wpdb->determine_charset($charset, '');
1534
- if (!empty($charset_collate['charset'])) $charset = $charset_collate['charset'];
1535
- }
1536
-
1537
- return $charset;
1538
- }
1539
-
1540
- public function backup_parameters()
1541
- {
1542
- global $wpdb;
1543
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1544
- $args = func_get_args();
1545
- $dumpSettings = $args[0];
1546
- $ret = "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;" . PHP_EOL .
1547
- "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;" . PHP_EOL .
1548
- "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;" . PHP_EOL .
1549
- "/*!40101 SET NAMES " . $this->get_connection_charset($wpdb) . " */;" . PHP_EOL;
1550
-
1551
- if (false === $dumpSettings['skip-tz-utc']) {
1552
- $ret .= "/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;" . PHP_EOL .
1553
- "/*!40103 SET TIME_ZONE='+00:00' */;" . PHP_EOL;
1554
- }
1555
-
1556
- $ret .= "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;" . PHP_EOL .
1557
- "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;" . PHP_EOL .
1558
- "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;" . PHP_EOL .
1559
- "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;" . PHP_EOL .PHP_EOL;
1560
-
1561
- return $ret;
1562
- }
1563
-
1564
- public function restore_parameters()
1565
- {
1566
- $this->check_parameters(func_num_args(), $expected_num_args = 1, __METHOD__);
1567
- $args = func_get_args();
1568
- $dumpSettings = $args[0];
1569
- $ret = "";
1570
-
1571
- if (false === $dumpSettings['skip-tz-utc']) {
1572
- $ret .= "/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;" . PHP_EOL;
1573
- }
1574
-
1575
- $ret .= "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;" . PHP_EOL .
1576
- "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;" . PHP_EOL .
1577
- "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;" . PHP_EOL .
1578
- "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;" . PHP_EOL .
1579
- "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;" . PHP_EOL .
1580
- "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;" . PHP_EOL .
1581
- "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;" . PHP_EOL . PHP_EOL;
1582
-
1583
- return $ret;
1584
- }
1585
-
1586
- /**
1587
- * Check number of parameters passed to function, useful when inheriting.
1588
- * Raise exception if unexpected.
1589
- *
1590
- * @param integer $num_args
1591
- * @param integer $expected_num_args
1592
- * @param string $method_name
1593
- */
1594
- private function check_parameters($num_args, $expected_num_args, $method_name)
1595
- {
1596
- if ( $num_args != $expected_num_args ) {
1597
- throw new Exception("Unexpected parameter passed to $method_name");
1598
- }
1599
- return;
1600
- }
1601
-
1602
- public function query($string)
1603
- {
1604
- return $this->dbHandler->get_results($string, ARRAY_A);
1605
- }
1606
-
1607
- public function exec($string)
1608
- {
1609
- return $this->dbHandler->get_results($string, ARRAY_A);
1610
- }
1611
-
1612
- public function quote($value)
1613
- {
1614
- $search = array("\x00", "\x0a", "\x0d", "\x1a");
1615
- $replace = array('\0', '\n', '\r', '\Z');
1616
- $value=str_replace('\\', '\\\\', $value);
1617
- $value=str_replace('\'', '\\\'', $value);
1618
- $value= "'" . str_replace($search, $replace, $value) . "'";
1619
- return $value;
1620
- }
1621
-
1622
- public function closeCursor($resultSet)
1623
- {
1624
- $this->dbHandler->flush();
1625
- }
1626
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
trunk/includes/class-wpvivid-mysqldump.php DELETED
@@ -1,1342 +0,0 @@
1
- <?php
2
- /**
3
- * Mysqldump File Doc Comment
4
- *
5
- * PHP version 5
6
- *
7
- * @category Library
8
- * @package Ifsnop\Mysqldump
9
- * @author Michael J. Calkins <clouddueling@github.com>
10
- * @author Diego Torres <ifsnop@github.com>
11
- * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
12
- * @link https://github.com/ifsnop/mysqldump-php
13
- *
14
- */
15
-
16
-
17
-
18
- use Exception as Exception;
19
-
20
-
21
- /**
22
- * Mysqldump Class Doc Comment
23
- *
24
- * @category Library
25
- * @package Ifsnop\Mysqldump
26
- * @author Michael J. Calkins <clouddueling@github.com>
27
- * @author Diego Torres <ifsnop@github.com>
28
- * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
29
- * @link https://github.com/ifsnop/mysqldump-php
30
- *
31
- */
32
- class WPvivid_Mysqldump
33
- {
34
-
35
- // Same as mysqldump
36
- const MAXLINESIZE = 1000000;
37
-
38
- // Available compression methods as constants
39
- const GZIP = 'Gzip';
40
- const BZIP2 = 'Bzip2';
41
- const NONE = 'None';
42
-
43
- // Available connection strings
44
- const UTF8 = 'utf8';
45
- const UTF8MB4 = 'utf8mb4';
46
-
47
- /**
48
- * Database username
49
- * @var string
50
- */
51
- public $user;
52
- /**
53
- * Database password
54
- * @var string
55
- */
56
- public $pass;
57
- /**
58
- * Destination filename, defaults to stdout
59
- * @var string
60
- */
61
- public $fileName = 'php://output';
62
-
63
- // Internal stuff
64
- private $tables = array();
65
- private $views = array();
66
- private $triggers = array();
67
- private $procedures = array();
68
- private $events = array();
69
- //private $dbHandler = null;
70
- private $dbType;
71
- private $compressManager;
72
- private $typeAdapter;
73
- private $dumpSettings = array();
74
- private $version;
75
- private $tableColumnTypes = array();
76
- public $log=false;
77
- public $task_id='';
78
- /**
79
- * database name, parsed from dsn
80
- * @var string
81
- */
82
- private $dbName;
83
- /**
84
- * host name, parsed from dsn
85
- * @var string
86
- */
87
- private $host;
88
- /**
89
- * dsn string parsed as an array
90
- * @var array
91
- */
92
- private $dsnArray = array();
93
-
94
- public $last_query_string='';
95
-
96
- public function __construct(
97
- $host = '',
98
- $dbname='',
99
- $user = '',
100
- $pass = '',
101
- $is_additional_db = false,
102
- $dumpSettings = array()
103
- ) {
104
- $dumpSettingsDefault = array(
105
- 'include-tables' => array(),
106
- 'exclude-tables' => array(),
107
- 'compress' => WPvivid_Mysqldump::NONE,
108
- 'init_commands' => array(),
109
- 'no-data' => array(),
110
- 'reset-auto-increment' => false,
111
- 'add-drop-database' => false,
112
- 'add-drop-table' => false,
113
- 'add-drop-trigger' => true,
114
- 'add-locks' => true,
115
- 'complete-insert' => false,
116
- 'databases' => false,
117
- 'default-character-set' => WPvivid_Mysqldump::UTF8,
118
- 'disable-keys' => true,
119
- 'extended-insert' => true,
120
- 'events' => false,
121
- 'hex-blob' => true, /* faster than escaped content */
122
- 'net_buffer_length' => self::MAXLINESIZE,
123
- 'no-autocommit' => false,
124
- 'no-create-info' => false,
125
- 'lock-tables' => false,
126
- 'routines' => false,
127
- 'single-transaction' => true,
128
- 'skip-triggers' => false,
129
- 'skip-tz-utc' => false,
130
- 'skip-comments' => false,
131
- 'skip-dump-date' => false,
132
- 'where' => '',
133
- /* deprecated */
134
- 'disable-foreign-keys-check' => true,
135
- 'site_url'=>'',
136
- 'home_url'=>'',
137
- 'content_url'=>'',
138
- 'prefix'=>''
139
- );
140
-
141
- if(defined('DB_CHARSET'))
142
- {
143
- $dumpSettingsDefault['default-character-set']=DB_CHARSET;
144
- }
145
-
146
- $this->dbType=$this->get_db_type($is_additional_db);
147
- $this->user = $user;
148
- $this->pass = $pass;
149
- $this->host=$host;
150
- $this->dbName=$dbname;
151
- $this->dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);
152
-
153
- $this->dumpSettings['init_commands'][] = "SET NAMES " . $this->dumpSettings['default-character-set'];
154
-
155
- if (false === $this->dumpSettings['skip-tz-utc'])
156
- {
157
- $this->dumpSettings['init_commands'][] = "SET TIME_ZONE='+00:00'";
158
- }
159
-
160
- $diff = array_diff(array_keys($this->dumpSettings), array_keys($dumpSettingsDefault));
161
- if (count($diff)>0) {
162
- throw new Exception("Unexpected value in dumpSettings: (" . implode(",", $diff) . ")");
163
- }
164
-
165
- if ( !is_array($this->dumpSettings['include-tables']) ||
166
- !is_array($this->dumpSettings['exclude-tables']) ) {
167
- throw new Exception("Include-tables and exclude-tables should be arrays");
168
- }
169
-
170
- // Dump the same views as tables, mimic mysqldump behaviour
171
- $this->dumpSettings['include-views'] = $this->dumpSettings['include-tables'];
172
-
173
- // Create a new compressManager to manage compressed output
174
- $this->compressManager = CompressManagerFactory::create($this->dumpSettings['compress']);
175
- }
176
-
177
- public function get_db_type($is_additional_db)
178
- {
179
- if($is_additional_db){
180
- return 'mysql';
181
- }
182
- else {
183
- $common_setting = WPvivid_Setting::get_setting(false, 'wpvivid_common_setting');
184
- $db_connect_method = isset($common_setting['options']['wpvivid_common_setting']['db_connect_method']) ? $common_setting['options']['wpvivid_common_setting']['db_connect_method'] : 'wpdb';
185
- if ($db_connect_method === 'wpdb') {
186
- return 'wpdb';
187
- } else {
188
- return 'mysql';
189
- }
190
- }
191
- }
192
-
193
- /**
194
- * Destructor of Mysqldump. Unsets dbHandlers and database objects.
195
- *
196
- */
197
- public function __destruct()
198
- {
199
- //$this->dbHandler = null;
200
- }
201
-
202
- /**
203
- * Custom array_replace_recursive to be used if PHP < 5.3
204
- * Replaces elements from passed arrays into the first array recursively
205
- *
206
- * @param array $array1 The array in which elements are replaced
207
- * @param array $array2 The array from which elements will be extracted
208
- *
209
- * @return array Returns an array, or NULL if an error occurs.
210
- */
211
- public static function array_replace_recursive($array1, $array2)
212
- {
213
- if (function_exists('array_replace_recursive')) {
214
- return array_replace_recursive($array1, $array2);
215
- }
216
-
217
- foreach ($array2 as $key => $value) {
218
- if (is_array($value)) {
219
- $array1[$key] = self::array_replace_recursive($array1[$key], $value);
220
- } else {
221
- $array1[$key] = $value;
222
- }
223
- }
224
- return $array1;
225
- }
226
-
227
- /**
228
- * Parse DSN string and extract dbname value
229
- * Several examples of a DSN string
230
- * mysql:host=localhost;dbname=testdb
231
- * mysql:host=localhost;port=3307;dbname=testdb
232
- * mysql:unix_socket=/tmp/mysql.sock;dbname=testdb
233
- *
234
- * @param string $dsn dsn string to parse
235
- */
236
- private function parseDsn($dsn)
237
- {
238
- if (empty($dsn) || (false === ($pos = strpos($dsn, ":")))) {
239
- throw new Exception("Empty DSN string");
240
- }
241
-
242
- $this->dsn = $dsn;
243
- $this->dbType = strtolower(substr($dsn, 0, $pos));
244
-
245
- if (empty($this->dbType)) {
246
- throw new Exception("Missing database type from DSN string");
247
- }
248
-
249
- $dsn = substr($dsn, $pos + 1);
250
-
251
- foreach(explode(";", $dsn) as $kvp) {
252
- $kvpArr = explode("=", $kvp);
253
- $this->dsnArray[strtolower($kvpArr[0])] = $kvpArr[1];
254
- }
255
-
256
- if (empty($this->dsnArray['host']) &&
257
- empty($this->ds