All-in-One WP Migration - Version 6.44

Version Description

** Added ** * PHP and DB version metadata in package.json * Find/Replace values in package.json * Internal Site URL and Internal Home URL in package.json * Confirmation mechanism when uploading chunk by chunk on import * Progress indicator on database export/import * Shutdown handler to catch fatal errors

** Changed ** * Replace TYPE with ENGINE keyword on database export * Detect Site URL and Home URL in Find/Replace values * Activate template and stylesheet on import * Import database chunk by chunk to avoid timeout limitation

** Fixed ** * An issue on export/import when using HipHop for PHP

Download this release

Release Info

Developer bangelov
Plugin Icon 128x128 All-in-One WP Migration
Version 6.44
Comparing to
See all releases

Code changes from version 6.43 to 6.44

Files changed (39) hide show
  1. all-in-one-wp-migration.php +1 -1
  2. changelog.txt +320 -0
  3. constants.php +11 -1
  4. functions.php +48 -0
  5. lib/controller/class-ai1wm-backups-controller.php +8 -3
  6. lib/controller/class-ai1wm-export-controller.php +5 -2
  7. lib/controller/class-ai1wm-feedback-controller.php +14 -9
  8. lib/controller/class-ai1wm-import-controller.php +6 -3
  9. lib/controller/class-ai1wm-main-controller.php +1 -1
  10. lib/controller/class-ai1wm-report-controller.php +12 -7
  11. lib/controller/class-ai1wm-resolve-controller.php +0 -3
  12. lib/controller/class-ai1wm-updater-controller.php +10 -5
  13. lib/model/class-ai1wm-extensions.php +1 -1
  14. lib/model/class-ai1wm-handler.php +11 -0
  15. lib/model/class-ai1wm-http.php +15 -15
  16. lib/model/export/class-ai1wm-export-config.php +46 -15
  17. lib/model/export/class-ai1wm-export-content.php +12 -12
  18. lib/model/export/class-ai1wm-export-database.php +52 -45
  19. lib/model/export/class-ai1wm-export-enumerate.php +14 -14
  20. lib/model/import/class-ai1wm-import-blogs.php +36 -8
  21. lib/model/import/class-ai1wm-import-content.php +12 -12
  22. lib/model/import/class-ai1wm-import-database.php +396 -225
  23. lib/model/import/class-ai1wm-import-done.php +29 -22
  24. lib/model/import/class-ai1wm-import-enumerate.php +4 -4
  25. lib/model/import/{class-ai1wm-import-plugins.php → class-ai1wm-import-mu-plugins.php} +1 -1
  26. lib/model/import/class-ai1wm-import-upload.php +2 -0
  27. lib/vendor/servmask/archiver/class-ai1wm-archiver.php +4 -4
  28. lib/vendor/servmask/archiver/class-ai1wm-extractor.php +18 -18
  29. lib/vendor/servmask/cron/class-ai1wm-cron.php +5 -5
  30. lib/vendor/servmask/database/class-ai1wm-database-mysql.php +1 -1
  31. lib/vendor/servmask/database/class-ai1wm-database-mysqli.php +1 -1
  32. lib/vendor/servmask/database/class-ai1wm-database-utility.php +3 -4
  33. lib/vendor/servmask/database/class-ai1wm-database.php +258 -133
  34. lib/view/assets/javascript/backups.min.js +12 -11
  35. lib/view/assets/javascript/export.min.js +11 -9
  36. lib/view/assets/javascript/import.min.js +26 -14
  37. lib/view/export/find-replace.php +2 -2
  38. loader.php +1 -1
  39. readme.txt +51 -334
all-in-one-wp-migration.php CHANGED
@@ -5,7 +5,7 @@
5
  * Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
6
  * Author: ServMask
7
  * Author URI: https://servmask.com/
8
- * Version: 6.43
9
  * Text Domain: all-in-one-wp-migration
10
  * Domain Path: /languages
11
  * Network: True
5
  * Description: Migration tool for all your blog data. Import or Export your blog content with a single click.
6
  * Author: ServMask
7
  * Author URI: https://servmask.com/
8
+ * Version: 6.44
9
  * Text Domain: all-in-one-wp-migration
10
  * Domain Path: /languages
11
  * Network: True
changelog.txt ADDED
@@ -0,0 +1,320 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ = 5.56 =
2
+ * Fix an issue with WP_Hook class introcuded in WP 4.7
3
+
4
+ = 5.55 =
5
+ * Fix an issue with resolving URL on export/import when using non-blocking streams client
6
+
7
+ = 5.54 =
8
+ * Fix an issue with resolving URL on export/import
9
+
10
+ = 5.53 =
11
+ * Send HTTP basic authorization header on upload (fetch method)
12
+ * Add Accept-Encoding, Accept-Charset and Accept-Language on export/import
13
+ * Do not replace already replaced values on database import/export
14
+ * Set silent mode when activating sidewide plugins
15
+ * Replace old media style URLs with the new media style URLs on database import
16
+ * Replace user_level and capabilities user meta keys if tables have empty prefix on export
17
+ * Create separate action for extracting must-use plugins
18
+ * Add option "Do not export must-use plugins" in advanced settings
19
+ * Fix an issue with SSL that produces "Unable to resolve URL..."
20
+
21
+ = 5.52 =
22
+ * Simplify the text on import page
23
+ * Fix an issue with special characters on export and import
24
+ * Fix an issue with export and import of large files
25
+
26
+ = 5.51 =
27
+ * Add support for utf8mb4_unicode_520_ci database collation
28
+
29
+ = 5.50 =
30
+ * Improve database export process
31
+ * Simplify export and import cron
32
+ * Fix an issue with export and import progress status
33
+
34
+ = 5.49 =
35
+ * Test plugin up to WordPress 4.6
36
+
37
+ = 5.48 =
38
+ * Improve support for large databases on export
39
+ * Add support for Box cloud storage
40
+ * Fix an issue with status on export/import
41
+ * Fix an issue with asynchronous requests on export/import
42
+
43
+ = 5.47 =
44
+ * Fix an issue with incorrect file size on export
45
+
46
+ = 5.46 =
47
+ * Add "Restore from Backups" video in readme file
48
+ * Display message if backups are inaccessible
49
+
50
+ = 5.45 =
51
+ * Fix an issue with blogs.dir path replacement
52
+
53
+ = 5.44 =
54
+ * Add "Do not replace email domain" option in advanced settings
55
+ * Add "ai1wm_exclude_content_from_export" WordPress hook on export
56
+ * Add HTML5 uploader
57
+
58
+ = 5.43 =
59
+ * Fix an issue when archiving dynamic files on export
60
+ * Support custom upload path for multisites
61
+ * Add support for various cache plugins
62
+
63
+ = 5.42 =
64
+ * Catch E_PARSE error on mu-plugins import
65
+ * Fix an issue with stop export that doesn't clean up the storage directory
66
+ * Initialize new cache instead of flushing the existing one on import/export
67
+
68
+ = 5.41 =
69
+ * Fix an issue when replacing serialized values on import
70
+ * List files in chunks
71
+ * Convert svg images to png
72
+ * Check if backups are readable before displaying them on "Backups" page
73
+ * Display version incompatibility notification on export/import/restore screen
74
+ * Fix double port issue on Bitnami
75
+ * Fix an issue on multisite export with cloud extensions
76
+
77
+ = 5.40 =
78
+ * Test plugin up to WordPress 4.5
79
+
80
+ = 5.39 =
81
+ * Fix a bug in uploads path replacement
82
+
83
+ = 5.38 =
84
+ * Deactivate mu-plugins if fatal error appears on import
85
+
86
+ = 5.37 =
87
+ * Validate the archive before import
88
+
89
+ = 5.36 =
90
+ * Add OneDrive to readme.txt
91
+ * Fix a typo on import
92
+
93
+ = 5.35 =
94
+ * Add OneDrive to export/import pages
95
+ * Fix a bug when WordPress was used without a db prefix
96
+ * Fix a problem when downloading wpress files
97
+ * Improve the log system
98
+
99
+ = 4.19 =
100
+ * Fixed an issue with options cache
101
+
102
+ = 4.18 =
103
+ * Fixed an issue with large media files
104
+ * Fixed an issue with status file being cached
105
+
106
+ = 4.17 =
107
+ * Set "Tested up to" WordPress 4.4
108
+
109
+ = 4.16 =
110
+ * Fix an issue with the transport layer on export/import
111
+
112
+ = 4.15 =
113
+ * Fix an issue with resovling mechanism on export/import
114
+
115
+ = 4.14 =
116
+ * Fix an issue with database import
117
+
118
+ = 4.13 =
119
+ * Add new mechanism for resolving HTTP requests
120
+
121
+ = 4.12 =
122
+ * Fix an issue with Google Drive extension
123
+
124
+ = 4.11 =
125
+ * Fix content filters on export
126
+
127
+ = 4.10 =
128
+ * Add HTTPS URL replacement
129
+ * Fix an issue when PDO is not available
130
+
131
+ = 4.6 =
132
+ * Fix an issue when the plugin was getting stuck on "Done creating an empty archive"
133
+ * Fix an issue when the plugin was getting stuck during import
134
+
135
+ = 4.3 =
136
+ * Add URL extension support
137
+ * Filter "mu-plugins" directory if "Do not export plugins (files)" is checked
138
+ * Fix utf8mb4 issue
139
+ * Fix translation issue
140
+
141
+ = 4.2 =
142
+ * Fix .wpress.bin format
143
+
144
+ = 4.1 =
145
+ * Add port to the host header on export/import
146
+ * Rename .wpress file to .wpress.bin file
147
+
148
+ = 4.0 =
149
+ * Fix file permission checks
150
+
151
+ = 3.9 =
152
+ * Fix could not resolve domain name on export/import
153
+
154
+ = 3.8 =
155
+ * Fix undefined method on Backups page if PHP version is < 5.3.6
156
+
157
+ = 3.7 =
158
+ * Add IPv6 support on export/import
159
+
160
+ = 3.6 =
161
+ * Fixed undefined constant warnings
162
+
163
+ = 3.5 =
164
+ * Exclude core plugin and extensions on export if they have custom names
165
+
166
+ = 3.4 =
167
+ * Made export/import processes more reliable
168
+ * Allow the plugin to work with non-default name
169
+ * Preserve backups during plugin updates
170
+ * Improved find & replace functionality on the serialized data
171
+ * Removed backup file name restrictions
172
+
173
+ = 3.3 =
174
+ * Fixed a bug when retrieving export/import status progress
175
+ * Fixed a bug when database encoding utf8mb4_unicode_ci is not available
176
+
177
+ = 3.2.2 =
178
+ * Fixed plugin incompatibility during export/import that was reporting that the process could not be started
179
+
180
+ = 3.2.1 =
181
+ * Added username/password settings for WordPress sites behind HTTP basic authentication
182
+ * Fixed a bug when exporting/importing without public DNS record
183
+ * Fixed a bug when exporting/importing media files
184
+
185
+ = 3.2.0 =
186
+ * Added advanced settings on export page
187
+
188
+ = 3.1.1 =
189
+ * Fixed secret key issue on upgrade of the plugin
190
+
191
+ = 3.0.0 =
192
+ * Added export to File, [Dropbox](https://servmask.com/products/dropbox-extension), [Amazon S3](https://servmask.com/products/amazon-s3-extension), [Google Drive](https://servmask.com/products/google-drive-extension)
193
+ * Added import from File, [Dropbox](https://servmask.com/products/dropbox-extension), [Amazon S3](https://servmask.com/products/amazon-s3-extension), [Google Drive](https://servmask.com/products/google-drive-extension)
194
+ * Implemented our own archiving format that reduces export and import by a factor of 10
195
+ * One-click export with the new simplified export page
196
+ * Improved upload functionality with auto-recognizing chunk size on import
197
+ * New **Backups** page for storing all WordPress site exports
198
+ * Easy restore WordPress site from **Backups** page
199
+ * Monitoring availability of the disk space on the server
200
+ * Both export and import happen in time chunks of 3 seconds
201
+ * Plugin works behind HTTP basic authentication
202
+
203
+ = 2.0.4 =
204
+ * Updated readme to reflect that the plugin is not multisite compatible
205
+
206
+ = 2.0.3 =
207
+ * Fixed a security issue while importing site using regular users
208
+
209
+ = 2.0.2 =
210
+ * Added support for WordPress v4.0
211
+
212
+ = 2.0.1 =
213
+ * Fixed a bug when all user permissions are lost on import
214
+
215
+ = 2.0.0 =
216
+ * Added support for migration of WordPress in Network Mode (Multi Site)
217
+ * New improved UI and UX
218
+ * New improved language translations on the menu items and help texts
219
+ * Better error handling and notifications
220
+ * Fixed a bug while exporting comments and associated comments meta data
221
+ * Fixed a bug while using find/replace functionality
222
+ * Fixed a bug with storage directory permissions and search indexation
223
+
224
+ = 1.9.2 =
225
+ * Added PHP <= v5.2.7 compatibility
226
+
227
+ = 1.9.1 =
228
+ * Fixed an issue with earlier versions of PHP
229
+
230
+ = 1.9.0 =
231
+ * New improved design on the export/import page
232
+ * Added an option for gathering user experience statistics
233
+ * Added a message box with important notifications about the plugin
234
+ * Fixed a bug while exporting database with multiple WordPress sites
235
+ * Fixed a bug while exporting database with table constraints
236
+ * Fixed a bug with auto recognizing zip archiver
237
+
238
+ = 1.8.1 =
239
+ * Added "Get Support" link in the plugin list page
240
+ * Removed "All in One WP Migration Beta" link from the readme file
241
+
242
+ = 1.8.0 =
243
+ * Added support for dynamically recognizing Site URL and Home URL on the import page
244
+ * Fixed a bug when maximum uploaded size is exceeded
245
+ * Fixed a bug while exporting big database tables
246
+
247
+ = 1.7.2 =
248
+ * Added support for automatically switching database adapters for better performance and optimization
249
+ * Fixed a bug while using host:port syntax with MySQL PDO
250
+ * Fixed a bug while using find/replace functionality
251
+
252
+ = 1.7.1 =
253
+ * Fixed a bug while exporting WordPress plugins directory
254
+
255
+ = 1.7.0 =
256
+ * Added storage layer to avoid permission issues with OS's directory used for temporary storage
257
+ * Added additional checks to verify the consistency of the imported archive
258
+ * Fixed a bug that caused the database to be exported without data
259
+ * Removed unused variables from package.json file
260
+
261
+ = 1.6.0 =
262
+ * Added additional check for directory's permissions
263
+ * Added additional check for output buffering when exporting a file
264
+ * Fixed a bug when the archive was exported or imported with old version of Zlib library
265
+ * Fixed a bug with permalinks and flushing the rules
266
+
267
+ = 1.5.0 =
268
+ * Added support for additional errors and exceptions handling
269
+ * Added support for reporting a problem in better and easier way
270
+ * Improved support process in ZenDesk system for faster response time
271
+ * Fixed typos on the import page. Thanks to Terry Heenan
272
+
273
+ = 1.4.0 =
274
+ * Added a Twitter and Facebook share buttons to the sidebar on import and export pages
275
+
276
+ = 1.3.1 =
277
+ * Fixed a bug when the user was unable to import site archive
278
+ * Optimized and speeded up import process
279
+
280
+ = 1.3.0 =
281
+ * Added support for mysql connection to happen over sockets or TCP
282
+ * Added support for Windows OS and fully tested the plugin on IIS
283
+ * Added support for limited memory_limit - 1MB - The plugin now requires only 1MB to operate properly
284
+ * Added support for multisite
285
+ * Used mysql_unbuffered_query instead of mysql_query to overcome any memory problems
286
+ * Fixed a deprecated warning for mysql_pconnect when php 5.5 and above is used
287
+ * Fixed memory_limit problem with PCLZIP library
288
+ * Fixed a bug when the archive is exported with zero size when using PCLZIP
289
+ * Fixed a bug when the archive was exported broken on some servers
290
+ * Fixed a deprecated usage of preg_replace \e in php v5.5 and above
291
+
292
+ = 1.2.1 =
293
+ * Fixed an issue when HTTP Error was shown on some hosts after import, credit to Michael Simon
294
+ * Fixed an issue when exporting databases with different prefix than wp_, credit to najtrox
295
+ * Fixed an issue when PDO is avalable but mysql driver for PDO is not, credit to Jaydesain69
296
+ * Deleted a plugin specific option when uninstalling the plugin (clean after itself)
297
+ * Support is done via Zendesk
298
+ * Included WP Version and Plugin version in the feedback form
299
+
300
+ = 1.2.0 =
301
+ * Increased upload limit of files from 128MB to 512MB
302
+ * Used ZipArchive with fallback to PclZip (a few users notified us that they don’t have ZipArchive enabled on their servers)
303
+ * Used PDO with fallback to mysql (a few users notified us that they dont have PDO enabled on their servers, mysql is deprecated as of PHP v5.5 but we are supporting PHP v5.2.17)
304
+ * Supported PHP v5.2.17 and WordPress v3.3 and above
305
+ * Fixed a bug during export that causes plugins to not be exported on some hosts (the problem that you are experiencing)
306
+
307
+ = 1.1.0 =
308
+ * Importing files using chunks to overcome any webserver upload size restriction
309
+ * Fixed a bug where HTTP code error was shown to some users
310
+
311
+ = 1.0.0 =
312
+ * Export database as SQL file
313
+ * Export media files
314
+ * Export themes files
315
+ * Export installed plugins
316
+ * Unlimited find/replace actions
317
+ * Option to exclude spam comments
318
+ * Option to apply find/replace to GUIDs
319
+ * Option to exclude post revisions
320
+ * Option to exclude tables data
constants.php CHANGED
@@ -31,7 +31,7 @@ define( 'AI1WM_DEBUG', false );
31
  // ==================
32
  // = Plugin Version =
33
  // ==================
34
- define( 'AI1WM_VERSION', '6.43' );
35
 
36
  // ===============
37
  // = Plugin Name =
@@ -218,6 +218,16 @@ define( 'AI1WM_JETPACK_ACTIVE_MODULES', 'jetpack_active_modules' );
218
  // ======================
219
  define( 'AI1WM_MS_FILES_REWRITING', 'ms_files_rewriting' );
220
 
 
 
 
 
 
 
 
 
 
 
221
  // ===============
222
  // = Updater Key =
223
  // ===============
31
  // ==================
32
  // = Plugin Version =
33
  // ==================
34
+ define( 'AI1WM_VERSION', '6.44' );
35
 
36
  // ===============
37
  // = Plugin Name =
218
  // ======================
219
  define( 'AI1WM_MS_FILES_REWRITING', 'ms_files_rewriting' );
220
 
221
+ // ===================
222
+ // = Active Template =
223
+ // ===================
224
+ define( 'AI1WM_ACTIVE_TEMPLATE', 'template' );
225
+
226
+ // =====================
227
+ // = Active Stylesheet =
228
+ // =====================
229
+ define( 'AI1WM_ACTIVE_STYLESHEET', 'stylesheet' );
230
+
231
  // ===============
232
  // = Updater Key =
233
  // ===============
functions.php CHANGED
@@ -219,6 +219,16 @@ function ai1wm_download_bytes( $params ) {
219
  return filesize( ai1wm_download_path( $params ) );
220
  }
221
 
 
 
 
 
 
 
 
 
 
 
222
  /**
223
  * Get archive size as text
224
  *
@@ -673,6 +683,44 @@ function ai1wm_activate_plugins( $plugins ) {
673
  return update_option( AI1WM_ACTIVE_PLUGINS, $current );
674
  }
675
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
676
  /**
677
  * Flush WP options cache
678
  *
219
  return filesize( ai1wm_download_path( $params ) );
220
  }
221
 
222
+ /**
223
+ * Get database size in bytes
224
+ *
225
+ * @param array $params Request parameters
226
+ * @return integer
227
+ */
228
+ function ai1wm_database_bytes( $params ) {
229
+ return filesize( ai1wm_database_path( $params ) );
230
+ }
231
+
232
  /**
233
  * Get archive size as text
234
  *
683
  return update_option( AI1WM_ACTIVE_PLUGINS, $current );
684
  }
685
 
686
+ /**
687
+ * Get active template
688
+ *
689
+ * @return string
690
+ */
691
+ function ai1wm_active_template() {
692
+ return get_option( AI1WM_ACTIVE_TEMPLATE );
693
+ }
694
+
695
+ /**
696
+ * Get active stylesheet
697
+ *
698
+ * @return string
699
+ */
700
+ function ai1wm_active_stylesheet() {
701
+ return get_option( AI1WM_ACTIVE_STYLESHEET );
702
+ }
703
+
704
+ /**
705
+ * Set active template
706
+ *
707
+ * @param string $template Template name
708
+ * @return boolean
709
+ */
710
+ function ai1wm_activate_template( $template ) {
711
+ return update_option( AI1WM_ACTIVE_TEMPLATE, $template );
712
+ }
713
+
714
+ /**
715
+ * Set active stylesheet
716
+ *
717
+ * @param string $stylesheet Stylesheet name
718
+ * @return boolean
719
+ */
720
+ function ai1wm_activate_stylesheet( $stylesheet ) {
721
+ return update_option( AI1WM_ACTIVE_STYLESHEET, $stylesheet );
722
+ }
723
+
724
  /**
725
  * Flush WP options cache
726
  *
lib/controller/class-ai1wm-backups-controller.php CHANGED
@@ -38,13 +38,18 @@ class Ai1wm_Backups_Controller {
38
  );
39
  }
40
 
41
- public static function delete() {
42
  $response = array( 'errors' => array() );
43
 
 
 
 
 
 
44
  // Set archive
45
  $archive = null;
46
- if ( isset( $_POST['archive'] ) ) {
47
- $archive = trim( $_POST['archive'] );
48
  }
49
 
50
  $model = new Ai1wm_Backups;
38
  );
39
  }
40
 
41
+ public static function delete( $params = array() ) {
42
  $response = array( 'errors' => array() );
43
 
44
+ // Set params
45
+ if ( empty( $params ) ) {
46
+ $params = stripslashes_deep( $_POST );
47
+ }
48
+
49
  // Set archive
50
  $archive = null;
51
+ if ( isset( $params['archive'] ) ) {
52
+ $archive = trim( $params['archive'] );
53
  }
54
 
55
  $model = new Ai1wm_Backups;
lib/controller/class-ai1wm-export-controller.php CHANGED
@@ -35,6 +35,9 @@ class Ai1wm_Export_Controller {
35
  // Set error handler
36
  @set_error_handler( 'Ai1wm_Handler::error' );
37
 
 
 
 
38
  // Set params
39
  if ( empty( $params ) ) {
40
  $params = ai1wm_urldecode( $_REQUEST );
@@ -65,8 +68,8 @@ class Ai1wm_Export_Controller {
65
  if ( isset( $wp_filter['ai1wm_export'] ) && ( $filters = $wp_filter['ai1wm_export'] ) ) {
66
  // WordPress 4.7 introduces new class for working with filters/actions called WP_Hook
67
  // which adds another level of abstraction and we need to address it.
68
- if ( is_object( $filters ) ) {
69
- $filters = current( $filters );
70
  }
71
 
72
  ksort( $filters );
35
  // Set error handler
36
  @set_error_handler( 'Ai1wm_Handler::error' );
37
 
38
+ // Set shutdown handler
39
+ @register_shutdown_function( 'Ai1wm_Handler::shutdown' );
40
+
41
  // Set params
42
  if ( empty( $params ) ) {
43
  $params = ai1wm_urldecode( $_REQUEST );
68
  if ( isset( $wp_filter['ai1wm_export'] ) && ( $filters = $wp_filter['ai1wm_export'] ) ) {
69
  // WordPress 4.7 introduces new class for working with filters/actions called WP_Hook
70
  // which adds another level of abstraction and we need to address it.
71
+ if ( isset( $filters->callbacks ) ) {
72
+ $filters = $filters->callbacks;
73
  }
74
 
75
  ksort( $filters );
lib/controller/class-ai1wm-feedback-controller.php CHANGED
@@ -25,30 +25,35 @@
25
 
26
  class Ai1wm_Feedback_Controller {
27
 
28
- public static function feedback() {
 
 
 
 
 
29
 
30
  // Set Type
31
  $type = null;
32
- if ( isset( $_POST['ai1wm_type'] ) ) {
33
- $type = trim( $_POST['ai1wm_type'] );
34
  }
35
 
36
  // Set E-mail
37
  $email = null;
38
- if ( isset( $_POST['ai1wm_email'] ) ) {
39
- $email = trim( $_POST['ai1wm_email'] );
40
  }
41
 
42
  // Set Message
43
  $message = null;
44
- if ( isset( $_POST['ai1wm_message'] ) ) {
45
- $message = trim( $_POST['ai1wm_message'] );
46
  }
47
 
48
  // Set Terms
49
  $terms = false;
50
- if ( isset( $_POST['ai1wm_terms'] ) ) {
51
- $terms = (bool) $_POST['ai1wm_terms'];
52
  }
53
 
54
  $model = new Ai1wm_Feedback;
25
 
26
  class Ai1wm_Feedback_Controller {
27
 
28
+ public static function feedback( $params = array() ) {
29
+
30
+ // Set params
31
+ if ( empty( $params ) ) {
32
+ $params = stripslashes_deep( $_POST );
33
+ }
34
 
35
  // Set Type
36
  $type = null;
37
+ if ( isset( $params['ai1wm_type'] ) ) {
38
+ $type = trim( $params['ai1wm_type'] );
39
  }
40
 
41
  // Set E-mail
42
  $email = null;
43
+ if ( isset( $params['ai1wm_email'] ) ) {
44
+ $email = trim( $params['ai1wm_email'] );
45
  }
46
 
47
  // Set Message
48
  $message = null;
49
+ if ( isset( $params['ai1wm_message'] ) ) {
50
+ $message = trim( $params['ai1wm_message'] );
51
  }
52
 
53
  // Set Terms
54
  $terms = false;
55
+ if ( isset( $params['ai1wm_terms'] ) ) {
56
+ $terms = (bool) $params['ai1wm_terms'];
57
  }
58
 
59
  $model = new Ai1wm_Feedback;
lib/controller/class-ai1wm-import-controller.php CHANGED
@@ -35,6 +35,9 @@ class Ai1wm_Import_Controller {
35
  // Set error handler
36
  @set_error_handler( 'Ai1wm_Handler::error' );
37
 
 
 
 
38
  // Set params
39
  if ( empty( $params ) ) {
40
  $params = ai1wm_urldecode( $_REQUEST );
@@ -65,8 +68,8 @@ class Ai1wm_Import_Controller {
65
  if ( isset( $wp_filter['ai1wm_import'] ) && ( $filters = $wp_filter['ai1wm_import'] ) ) {
66
  // WordPress 4.7 introduces new class for working with filters/actions called WP_Hook
67
  // which adds another level of abstraction and we need to address it.
68
- if ( is_object( $filters ) ) {
69
- $filters = current( $filters );
70
  }
71
 
72
  ksort( $filters );
@@ -85,7 +88,7 @@ class Ai1wm_Import_Controller {
85
 
86
  } catch ( Ai1wm_Import_Retry_Exception $e ) {
87
  status_header( $e->getCode() );
88
- echo json_encode( array( 'message' => $e->getMessage() ) );
89
  exit;
90
  } catch ( Exception $e ) {
91
  Ai1wm_Status::error( $e->getMessage(), __( 'Unable to import', AI1WM_PLUGIN_NAME ) );
35
  // Set error handler
36
  @set_error_handler( 'Ai1wm_Handler::error' );
37
 
38
+ // Set shutdown handler
39
+ @register_shutdown_function( 'Ai1wm_Handler::shutdown' );
40
+
41
  // Set params
42
  if ( empty( $params ) ) {
43
  $params = ai1wm_urldecode( $_REQUEST );
68
  if ( isset( $wp_filter['ai1wm_import'] ) && ( $filters = $wp_filter['ai1wm_import'] ) ) {
69
  // WordPress 4.7 introduces new class for working with filters/actions called WP_Hook
70
  // which adds another level of abstraction and we need to address it.
71
+ if ( isset( $filters->callbacks ) ) {
72
+ $filters = $filters->callbacks;
73
  }
74
 
75
  ksort( $filters );
88
 
89
  } catch ( Ai1wm_Import_Retry_Exception $e ) {
90
  status_header( $e->getCode() );
91
+ echo json_encode( array( 'errors' => array( array( 'code' => $e->getCode(), 'message' => $e->getMessage() ) ) ) );
92
  exit;
93
  } catch ( Exception $e ) {
94
  Ai1wm_Status::error( $e->getMessage(), __( 'Unable to import', AI1WM_PLUGIN_NAME ) );
lib/controller/class-ai1wm-main-controller.php CHANGED
@@ -153,7 +153,7 @@ class Ai1wm_Main_Controller {
153
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Blogs::execute', 150 );
154
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Enumerate::execute', 200 );
155
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Content::execute', 250 );
156
- add_filter( 'ai1wm_import', 'Ai1wm_Import_Plugins::execute', 270 );
157
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Database::execute', 300 );
158
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Done::execute', 350 );
159
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Clean::execute', 400 );
153
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Blogs::execute', 150 );
154
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Enumerate::execute', 200 );
155
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Content::execute', 250 );
156
+ add_filter( 'ai1wm_import', 'Ai1wm_Import_Mu_Plugins::execute', 270 );
157
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Database::execute', 300 );
158
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Done::execute', 350 );
159
  add_filter( 'ai1wm_import', 'Ai1wm_Import_Clean::execute', 400 );
lib/controller/class-ai1wm-report-controller.php CHANGED
@@ -25,24 +25,29 @@
25
 
26
  class Ai1wm_Report_Controller {
27
 
28
- public static function report() {
 
 
 
 
 
29
 
30
  // Set E-mail
31
  $email = null;
32
- if ( isset( $_POST['ai1wm_email'] ) ) {
33
- $email = trim( $_POST['ai1wm_email'] );
34
  }
35
 
36
  // Set Message
37
  $message = null;
38
- if ( isset( $_POST['ai1wm_message'] ) ) {
39
- $message = trim( $_POST['ai1wm_message'] );
40
  }
41
 
42
  // Set Terms
43
  $terms = false;
44
- if ( isset( $_POST['ai1wm_terms'] ) ) {
45
- $terms = (bool) $_POST['ai1wm_terms'];
46
  }
47
 
48
  $model = new Ai1wm_Report;
25
 
26
  class Ai1wm_Report_Controller {
27
 
28
+ public static function report( $params = array() ) {
29
+
30
+ // Set params
31
+ if ( empty( $params ) ) {
32
+ $params = stripslashes_deep( $_POST );
33
+ }
34
 
35
  // Set E-mail
36
  $email = null;
37
+ if ( isset( $params['ai1wm_email'] ) ) {
38
+ $email = trim( $params['ai1wm_email'] );
39
  }
40
 
41
  // Set Message
42
  $message = null;
43
+ if ( isset( $params['ai1wm_message'] ) ) {
44
+ $message = trim( $params['ai1wm_message'] );
45
  }
46
 
47
  // Set Terms
48
  $terms = false;
49
+ if ( isset( $params['ai1wm_terms'] ) ) {
50
+ $terms = (bool) $params['ai1wm_terms'];
51
  }
52
 
53
  $model = new Ai1wm_Report;
lib/controller/class-ai1wm-resolve-controller.php CHANGED
@@ -27,9 +27,6 @@ class Ai1wm_Resolve_Controller {
27
 
28
  public static function resolve( $params = array() ) {
29
 
30
- // Set error handler
31
- @set_error_handler( 'Ai1wm_Handler::error' );
32
-
33
  // Set params
34
  if ( empty( $params ) ) {
35
  $params = ai1wm_urldecode( $_REQUEST );
27
 
28
  public static function resolve( $params = array() ) {
29
 
 
 
 
30
  // Set params
31
  if ( empty( $params ) ) {
32
  $params = ai1wm_urldecode( $_REQUEST );
lib/controller/class-ai1wm-updater-controller.php CHANGED
@@ -52,19 +52,24 @@ class Ai1wm_Updater_Controller {
52
  return Ai1wm_Updater::plugin_row_meta( $links, $file );
53
  }
54
 
55
- public static function updater() {
56
  $extensions = Ai1wm_Extensions::get();
57
 
 
 
 
 
 
58
  // Set uuid
59
  $uuid = null;
60
- if ( isset( $_POST['ai1wm_uuid'] ) ) {
61
- $uuid = trim( $_POST['ai1wm_uuid'] );
62
  }
63
 
64
  // Set extension
65
  $extension = null;
66
- if ( isset( $_POST['ai1wm_extension'] ) ) {
67
- $extension = trim( $_POST['ai1wm_extension'] );
68
  }
69
 
70
  // Verify whether extension exists
52
  return Ai1wm_Updater::plugin_row_meta( $links, $file );
53
  }
54
 
55
+ public static function updater( $params = array() ) {
56
  $extensions = Ai1wm_Extensions::get();
57
 
58
+ // Set params
59
+ if ( empty( $params ) ) {
60
+ $params = stripslashes_deep( $_POST );
61
+ }
62
+
63
  // Set uuid
64
  $uuid = null;
65
+ if ( isset( $params['ai1wm_uuid'] ) ) {
66
+ $uuid = trim( $params['ai1wm_uuid'] );
67
  }
68
 
69
  // Set extension
70
  $extension = null;
71
+ if ( isset( $params['ai1wm_extension'] ) ) {
72
+ $extension = trim( $params['ai1wm_extension'] );
73
  }
74
 
75
  // Verify whether extension exists
lib/model/class-ai1wm-extensions.php CHANGED
@@ -76,7 +76,7 @@ class Ai1wm_Extensions {
76
  'about' => AI1WMME_PLUGIN_ABOUT,
77
  'basename' => AI1WMME_PLUGIN_BASENAME,
78
  'version' => AI1WMME_VERSION,
79
- 'requires' => '3.26',
80
  'short' => AI1WMME_PLUGIN_SHORT,
81
  );
82
  }
76
  'about' => AI1WMME_PLUGIN_ABOUT,
77
  'basename' => AI1WMME_PLUGIN_BASENAME,
78
  'version' => AI1WMME_VERSION,
79
+ 'requires' => '3.30',
80
  'short' => AI1WMME_PLUGIN_SHORT,
81
  );
82
  }
lib/model/class-ai1wm-handler.php CHANGED
@@ -42,4 +42,15 @@ class Ai1wm_Handler {
42
  'Line' => $errline,
43
  ) );
44
  }
 
 
 
 
 
 
 
 
 
 
 
45
  }
42
  'Line' => $errline,
43
  ) );
44
  }
45
+
46
+ /**
47
+ * Shutdown handler
48
+ *
49
+ * @return void
50
+ */
51
+ public static function shutdown() {
52
+ if ( ( $error = error_get_last() ) ) {
53
+ Ai1wm_Log::error( $error );
54
+ }
55
+ }
56
  }
lib/model/class-ai1wm-http.php CHANGED
@@ -25,7 +25,7 @@
25
 
26
  class Ai1wm_Http {
27
 
28
- public static function get( $url, $params = array(), Ai1wm_Http_Abstract $client = null ) {
29
 
30
  // Get IP address
31
  $ip = get_option( AI1WM_URL_IP );
@@ -40,31 +40,31 @@ class Ai1wm_Http {
40
  $port = parse_url( $url, PHP_URL_PORT );
41
 
42
  // Set HTTP client
43
- if ( is_null( $client ) ) {
44
- $client = Ai1wm_Http_Factory::create( $adapter );
45
  }
46
 
47
  // Set HTTP host
48
  if ( empty( $port ) ) {
49
- $client->set_header( 'Host', $host );
50
  } else {
51
- $client->set_header( 'Host', "{$host}:{$port}" );
52
  }
53
 
54
  // Set HTTP authorization
55
  if ( ( $user = get_option( AI1WM_AUTH_USER ) ) && ( $password = get_option( AI1WM_AUTH_PASSWORD ) ) ) {
56
  if ( ( $hash = base64_encode( "{$user}:{$password}" ) ) ) {
57
- $client->set_header( 'Authorization', "Basic {$hash}" );
58
  }
59
  }
60
 
61
  $blocking = false;
62
 
63
  // Run non-blocking HTTP request
64
- $client->get( add_query_arg( ai1wm_urlencode( $params ), str_replace( "//{$host}", "//{$ip}", $url ) ), $blocking );
65
  }
66
 
67
- public static function resolve( $url, $params = array(), Ai1wm_Http_Abstract $client = null ) {
68
 
69
  // Reset IP address and adapter
70
  delete_option( AI1WM_URL_IP );
@@ -108,28 +108,28 @@ class Ai1wm_Http {
108
  ) );
109
 
110
  // Set HTTP client
111
- if ( is_null( $client ) ) {
112
- $client = Ai1wm_Http_Factory::create( $adapter );
113
  }
114
 
115
  // Set HTTP host
116
  if ( empty( $port ) ) {
117
- $client->set_header( 'Host', $host );
118
  } else {
119
- $client->set_header( 'Host', "{$host}:{$port}" );
120
  }
121
 
122
  // Set HTTP authorization
123
  if ( ( $user = get_option( AI1WM_AUTH_USER ) ) && ( $password = get_option( AI1WM_AUTH_PASSWORD ) ) ) {
124
  if ( ( $hash = base64_encode( "{$user}:{$password}" ) ) ) {
125
- $client->set_header( 'Authorization', "Basic {$hash}" );
126
  }
127
  }
128
 
129
  $blocking = true;
130
 
131
  // Run blocking HTTP request
132
- $client->get( add_query_arg( ai1wm_urlencode( $params ), str_replace( "//{$host}", "//{$ip}", $url ) ), $blocking );
133
 
134
  // Flush WP cache
135
  ai1wm_cache_flush();
@@ -140,7 +140,7 @@ class Ai1wm_Http {
140
  }
141
 
142
  // Reset HTTP client
143
- $client = null;
144
  }
145
  }
146
 
25
 
26
  class Ai1wm_Http {
27
 
28
+ public static function get( $url, $params = array(), Ai1wm_Http_Abstract $http = null ) {
29
 
30
  // Get IP address
31
  $ip = get_option( AI1WM_URL_IP );
40
  $port = parse_url( $url, PHP_URL_PORT );
41
 
42
  // Set HTTP client
43
+ if ( empty( $http ) ) {
44
+ $http = Ai1wm_Http_Factory::create( $adapter );
45
  }
46
 
47
  // Set HTTP host
48
  if ( empty( $port ) ) {
49
+ $http->set_header( 'Host', $host );
50
  } else {
51
+ $http->set_header( 'Host', "{$host}:{$port}" );
52
  }
53
 
54
  // Set HTTP authorization
55
  if ( ( $user = get_option( AI1WM_AUTH_USER ) ) && ( $password = get_option( AI1WM_AUTH_PASSWORD ) ) ) {
56
  if ( ( $hash = base64_encode( "{$user}:{$password}" ) ) ) {
57
+ $http->set_header( 'Authorization', "Basic {$hash}" );
58
  }
59
  }
60
 
61
  $blocking = false;
62
 
63
  // Run non-blocking HTTP request
64
+ $http->get( add_query_arg( ai1wm_urlencode( $params ), str_replace( "//{$host}", "//{$ip}", $url ) ), $blocking );
65
  }
66
 
67
+ public static function resolve( $url, $params = array(), Ai1wm_Http_Abstract $http = null ) {
68
 
69
  // Reset IP address and adapter
70
  delete_option( AI1WM_URL_IP );
108
  ) );
109
 
110
  // Set HTTP client
111
+ if ( empty( $http ) ) {
112
+ $http = Ai1wm_Http_Factory::create( $adapter );
113
  }
114
 
115
  // Set HTTP host
116
  if ( empty( $port ) ) {
117
+ $http->set_header( 'Host', $host );
118
  } else {
119
+ $http->set_header( 'Host', "{$host}:{$port}" );
120
  }
121
 
122
  // Set HTTP authorization
123
  if ( ( $user = get_option( AI1WM_AUTH_USER ) ) && ( $password = get_option( AI1WM_AUTH_PASSWORD ) ) ) {
124
  if ( ( $hash = base64_encode( "{$user}:{$password}" ) ) ) {
125
+ $http->set_header( 'Authorization', "Basic {$hash}" );
126
  }
127
  }
128
 
129
  $blocking = true;
130
 
131
  // Run blocking HTTP request
132
+ $http->get( add_query_arg( ai1wm_urlencode( $params ), str_replace( "//{$host}", "//{$ip}", $url ) ), $blocking );
133
 
134
  // Flush WP cache
135
  ai1wm_cache_flush();
140
  }
141
 
142
  // Reset HTTP client
143
+ $http = null;
144
  }
145
  }
146
 
lib/model/export/class-ai1wm-export-config.php CHANGED
@@ -26,7 +26,7 @@
26
  class Ai1wm_Export_Config {
27
 
28
  public static function execute( $params ) {
29
- global $wp_version;
30
 
31
  // Set progress
32
  Ai1wm_Status::info( __( 'Adding configuration to archive...', AI1WM_PLUGIN_NAME ) );
@@ -40,33 +40,64 @@ class Ai1wm_Export_Config {
40
  // Set config
41
  $config = array();
42
 
43
- // Set site URL
44
- if ( isset( $options['siteurl'] ) ) {
45
- $config['SiteURL'] = untrailingslashit( $options['siteurl'] );
46
  } else {
47
- $config['SiteURL'] = site_url();
48
  }
49
 
 
 
 
50
  // Set home URL
51
- if ( isset( $options['home'] ) ) {
52
- $config['HomeURL'] = untrailingslashit( $options['home'] );
53
- } else {
54
- $config['HomeURL'] = home_url();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  }
56
 
57
  // Set plugin version
58
  $config['Plugin'] = array( 'Version' => AI1WM_VERSION );
59
 
 
 
 
 
 
 
 
 
 
60
  // Set active plugins
61
  $config['Plugins'] = array_values( array_diff( ai1wm_active_plugins(), ai1wm_active_servmask_plugins() ) );
62
 
63
- // Set WordPress version and content
64
- $config['WordPress'] = array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR );
65
 
66
- // Set no replace email
67
- if ( isset( $params['options']['no_email_replace'] ) ) {
68
- $config['NoEmailReplace'] = true;
69
- }
70
 
71
  // Save package.json file
72
  $handle = ai1wm_open( ai1wm_package_path( $params ), 'w' );
26
  class Ai1wm_Export_Config {
27
 
28
  public static function execute( $params ) {
29
+ global $wp_version, $wpdb;
30
 
31
  // Set progress
32
  Ai1wm_Status::info( __( 'Adding configuration to archive...', AI1WM_PLUGIN_NAME ) );
40
  // Set config
41
  $config = array();
42
 
43
+ // Get database client
44
+ if ( empty( $wpdb->use_mysqli ) ) {
45
+ $mysql = new Ai1wm_Database_Mysql( $wpdb );
46
  } else {
47
+ $mysql = new Ai1wm_Database_Mysqli( $wpdb );
48
  }
49
 
50
+ // Set site URL
51
+ $config['SiteURL'] = site_url();
52
+
53
  // Set home URL
54
+ $config['HomeURL'] = home_url();
55
+
56
+ // Set internal site URL
57
+ if ( isset( $options['siteurl'] ) && ( untrailingslashit( $options['siteurl'] ) !== site_url() ) ) {
58
+ $config['InternalSiteURL'] = untrailingslashit( $options['siteurl'] );
59
+ }
60
+
61
+ // Set internal home URL
62
+ if ( isset( $options['home'] ) && ( untrailingslashit( $options['home'] ) !== home_url() ) ) {
63
+ $config['InternalHomeURL'] = untrailingslashit( $options['home'] );
64
+ }
65
+
66
+ // Set replace old and new values
67
+ if ( isset( $params['options']['replace'] ) && ( $replace = $params['options']['replace'] ) ) {
68
+ for ( $i = 0; $i < count( $replace['old_value'] ); $i++ ) {
69
+ if ( ! empty( $replace['old_value'][ $i ] ) && ! empty( $replace['new_value'][ $i ] ) ) {
70
+ $config['Replace']['OldValues'][] = $replace['old_value'][ $i ];
71
+ $config['Replace']['NewValues'][] = $replace['new_value'][ $i ];
72
+ }
73
+ }
74
+ }
75
+
76
+ // Set no replace email
77
+ if ( isset( $params['options']['no_email_replace'] ) ) {
78
+ $config['NoEmailReplace'] = true;
79
  }
80
 
81
  // Set plugin version
82
  $config['Plugin'] = array( 'Version' => AI1WM_VERSION );
83
 
84
+ // Set WordPress version and content
85
+ $config['WordPress'] = array( 'Version' => $wp_version, 'Content' => WP_CONTENT_DIR );
86
+
87
+ // Set database version
88
+ $config['Database'] = array( 'Version' => $mysql->version() );
89
+
90
+ // Set PHP version
91
+ $config['PHP'] = array( 'Version' => phpversion() );
92
+
93
  // Set active plugins
94
  $config['Plugins'] = array_values( array_diff( ai1wm_active_plugins(), ai1wm_active_servmask_plugins() ) );
95
 
96
+ // Set active template
97
+ $config['Template'] = ai1wm_active_template();
98
 
99
+ // Set active stylesheet
100
+ $config['Stylesheet'] = ai1wm_active_stylesheet();
 
 
101
 
102
  // Save package.json file
103
  $handle = ai1wm_open( ai1wm_package_path( $params ), 'w' );
lib/model/export/class-ai1wm-export-content.php CHANGED
@@ -48,18 +48,18 @@ class Ai1wm_Export_Content {
48
  $filemap_offset = 0;
49
  }
50
 
51
- // Get total files
52
- if ( isset( $params['total_files'] ) ) {
53
- $total_files = (int) $params['total_files'];
54
  } else {
55
- $total_files = 1;
56
  }
57
 
58
- // Get total size
59
- if ( isset( $params['total_size'] ) ) {
60
- $total_size = (int) $params['total_size'];
61
  } else {
62
- $total_size = 1;
63
  }
64
 
65
  // Get processed files
@@ -70,11 +70,11 @@ class Ai1wm_Export_Content {
70
  }
71
 
72
  // What percent of files have we processed?
73
- $progress = (int) ( ( $processed / $total_size ) * 100 );
74
 
75
  // Set progress
76
  if ( empty( $content_offset ) ) {
77
- Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );
78
  }
79
 
80
  // Start time
@@ -97,11 +97,11 @@ class Ai1wm_Export_Content {
97
 
98
  // What percent of files have we processed?
99
  if ( ( $processed += ( $current_offset - $content_offset ) ) ) {
100
- $progress = (int) ( ( $processed / $total_size ) * 100 );
101
  }
102
 
103
  // Set progress
104
- Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );
105
 
106
  // Set current filesize
107
  $current_filesize = $archive->get_current_filesize();
48
  $filemap_offset = 0;
49
  }
50
 
51
+ // Get total files count
52
+ if ( isset( $params['total_files_count'] ) ) {
53
+ $total_files_count = (int) $params['total_files_count'];
54
  } else {
55
+ $total_files_count = 1;
56
  }
57
 
58
+ // Get total files size
59
+ if ( isset( $params['total_files_size'] ) ) {
60
+ $total_files_size = (int) $params['total_files_size'];
61
  } else {
62
+ $total_files_size = 1;
63
  }
64
 
65
  // Get processed files
70
  }
71
 
72
  // What percent of files have we processed?
73
+ $progress = (int) ( ( $processed / $total_files_size ) * 100 );
74
 
75
  // Set progress
76
  if ( empty( $content_offset ) ) {
77
+ Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
78
  }
79
 
80
  // Start time
97
 
98
  // What percent of files have we processed?
99
  if ( ( $processed += ( $current_offset - $content_offset ) ) ) {
100
+ $progress = (int) ( ( $processed / $total_files_size ) * 100 );
101
  }
102
 
103
  // Set progress
104
+ Ai1wm_Status::info( sprintf( __( 'Archiving %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
105
 
106
  // Set current filesize
107
  $current_filesize = $archive->get_current_filesize();
lib/model/export/class-ai1wm-export-database.php CHANGED
@@ -33,20 +33,37 @@ class Ai1wm_Export_Database {
33
  return $params;
34
  }
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  // Set progress
37
- Ai1wm_Status::info( __( 'Exporting database...', AI1WM_PLUGIN_NAME ) );
38
 
39
  // Get database client
40
  if ( empty( $wpdb->use_mysqli ) ) {
41
- $client = new Ai1wm_Database_Mysql( $wpdb );
42
  } else {
43
- $client = new Ai1wm_Database_Mysqli( $wpdb );
44
  }
45
 
46
  // Spam comments
47
  if ( isset( $params['options']['no_spam_comments'] ) ) {
48
- $client->set_table_query_clauses( ai1wm_table_prefix() . 'comments', " WHERE comment_approved != 'spam' " );
49
- $client->set_table_query_clauses( ai1wm_table_prefix() . 'commentmeta', sprintf(
50
  " WHERE comment_id IN ( SELECT comment_ID FROM `%s` WHERE comment_approved != 'spam' ) ",
51
  ai1wm_table_prefix() . 'comments'
52
  ) );
@@ -54,20 +71,7 @@ class Ai1wm_Export_Database {
54
 
55
  // Post revisions
56
  if ( isset( $params['options']['no_revisions'] ) ) {
57
- $client->set_table_query_clauses( ai1wm_table_prefix() . 'posts', " WHERE post_type != 'revision' " );
58
- }
59
-
60
- $old_table_values = array();
61
- $new_table_values = array();
62
-
63
- // Find and replace
64
- if ( isset( $params['options']['replace'] ) && ( $replace = $params['options']['replace'] ) ) {
65
- for ( $i = 0; $i < count( $replace['old_value'] ); $i++ ) {
66
- if ( ! empty( $replace['old_value'][ $i ] ) && ! empty( $replace['new_value'][ $i ] ) ) {
67
- $old_table_values[] = $replace['old_value'][ $i ];
68
- $new_table_values[] = $replace['new_value'][ $i ];
69
- }
70
- }
71
  }
72
 
73
  $old_table_prefixes = array();
@@ -79,7 +83,7 @@ class Ai1wm_Export_Database {
79
  $new_table_prefixes[] = ai1wm_servmask_prefix();
80
  } else {
81
  // Set table prefixes based on table name
82
- foreach ( $client->get_tables() as $table_name ) {
83
  $old_table_prefixes[] = $table_name;
84
  $new_table_prefixes[] = ai1wm_servmask_prefix() . $table_name;
85
  }
@@ -97,35 +101,23 @@ class Ai1wm_Export_Database {
97
  if ( ai1wm_table_prefix() ) {
98
  $include_table_prefixes[] = ai1wm_table_prefix();
99
  } else {
100
- foreach ( $client->get_tables() as $table_name ) {
101
  $include_table_prefixes[] = $table_name;
102
  }
103
  }
104
 
105
  // Set database options
106
- $client->set_old_table_prefixes( $old_table_prefixes )
107
- ->set_new_table_prefixes( $new_table_prefixes )
108
- ->set_old_replace_values( $old_table_values )
109
- ->set_new_replace_values( $new_table_values )
110
- ->set_include_table_prefixes( $include_table_prefixes )
111
- ->set_table_prefix_columns( ai1wm_table_prefix() . 'options', array( 'option_name' ) )
112
- ->set_table_prefix_columns( ai1wm_table_prefix() . 'usermeta', array( 'meta_key' ) );
113
 
114
  // Exclude active plugins and status options
115
- $client->set_table_query_clauses( ai1wm_table_prefix() . 'options', sprintf( " WHERE option_name NOT IN ('%s', '%s') ", AI1WM_ACTIVE_PLUGINS, AI1WM_STATUS ) );
116
-
117
- // Set Visual Composer
118
- $client->set_visual_composer( ! is_wp_error( validate_plugin( 'js_composer/js_composer.php' ) ) );
119
-
120
- // Set current table index
121
- if ( isset( $params['current_table_index'] ) ) {
122
- $current_table_index = (int) $params['current_table_index'];
123
- } else {
124
- $current_table_index = 0;
125
- }
126
 
127
  // Export database
128
- if ( $client->export( ai1wm_database_path( $params ), $current_table_index, 10 ) ) {
129
 
130
  // Get archive file
131
  $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
@@ -135,18 +127,33 @@ class Ai1wm_Export_Database {
135
  $archive->close();
136
 
137
  // Set progress
138
- Ai1wm_Status::info( __( 'Done exporting database.', AI1WM_PLUGIN_NAME ) );
 
 
 
139
 
140
- // Unset current table index
141
- unset( $params['current_table_index'] );
142
 
143
  // Unset completed flag
144
  unset( $params['completed'] );
145
 
146
  } else {
147
 
148
- // Set current table index
149
- $params['current_table_index'] = $current_table_index;
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
  // Set completed flag
152
  $params['completed'] = false;
33
  return $params;
34
  }
35
 
36
+ // Set table offset
37
+ if ( isset( $params['table_offset'] ) ) {
38
+ $table_offset = (int) $params['table_offset'];
39
+ } else {
40
+ $table_offset = 0;
41
+ }
42
+
43
+ // Set total tables count
44
+ if ( isset( $params['total_tables_count'] ) ) {
45
+ $total_tables_count = (int) $params['total_tables_count'];
46
+ } else {
47
+ $total_tables_count = 1;
48
+ }
49
+
50
+ // What percent of tables have we processed?
51
+ $progress = (int) ( ( $table_offset / $total_tables_count ) * 100 );
52
+
53
  // Set progress
54
+ Ai1wm_Status::info( sprintf( __( 'Exporting database...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $progress ) );
55
 
56
  // Get database client
57
  if ( empty( $wpdb->use_mysqli ) ) {
58
+ $mysql = new Ai1wm_Database_Mysql( $wpdb );
59
  } else {
60
+ $mysql = new Ai1wm_Database_Mysqli( $wpdb );
61
  }
62
 
63
  // Spam comments
64
  if ( isset( $params['options']['no_spam_comments'] ) ) {
65
+ $mysql->set_table_query_clauses( ai1wm_table_prefix() . 'comments', " WHERE comment_approved != 'spam' " );
66
+ $mysql->set_table_query_clauses( ai1wm_table_prefix() . 'commentmeta', sprintf(
67
  " WHERE comment_id IN ( SELECT comment_ID FROM `%s` WHERE comment_approved != 'spam' ) ",
68
  ai1wm_table_prefix() . 'comments'
69
  ) );
71
 
72
  // Post revisions
73
  if ( isset( $params['options']['no_revisions'] ) ) {
74
+ $mysql->set_table_query_clauses( ai1wm_table_prefix() . 'posts', " WHERE post_type != 'revision' " );
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  }
76
 
77
  $old_table_prefixes = array();
83
  $new_table_prefixes[] = ai1wm_servmask_prefix();
84
  } else {
85
  // Set table prefixes based on table name
86
+ foreach ( $mysql->get_tables() as $table_name ) {
87
  $old_table_prefixes[] = $table_name;
88
  $new_table_prefixes[] = ai1wm_servmask_prefix() . $table_name;
89
  }
101
  if ( ai1wm_table_prefix() ) {
102
  $include_table_prefixes[] = ai1wm_table_prefix();
103
  } else {
104
+ foreach ( $mysql->get_tables() as $table_name ) {
105
  $include_table_prefixes[] = $table_name;
106
  }
107
  }
108
 
109
  // Set database options
110
+ $mysql->set_old_table_prefixes( $old_table_prefixes )
111
+ ->set_new_table_prefixes( $new_table_prefixes )
112
+ ->set_include_table_prefixes( $include_table_prefixes )
113
+ ->set_table_prefix_columns( ai1wm_table_prefix() . 'options', array( 'option_name' ) )
114
+ ->set_table_prefix_columns( ai1wm_table_prefix() . 'usermeta', array( 'meta_key' ) );
 
 
115
 
116
  // Exclude active plugins and status options
117
+ $mysql->set_table_query_clauses( ai1wm_table_prefix() . 'options', sprintf( " WHERE option_name NOT IN ('%s', '%s', '%s', '%s') ", AI1WM_ACTIVE_PLUGINS, AI1WM_ACTIVE_TEMPLATE, AI1WM_ACTIVE_STYLESHEET, AI1WM_STATUS ) );
 
 
 
 
 
 
 
 
 
 
118
 
119
  // Export database
120
+ if ( $mysql->export( ai1wm_database_path( $params ), $table_offset, 10 ) ) {
121
 
122
  // Get archive file
123
  $archive = new Ai1wm_Compressor( ai1wm_archive_path( $params ) );
127
  $archive->close();
128
 
129
  // Set progress
130
+ Ai1wm_Status::info( __( 'Done exporting database...', AI1WM_PLUGIN_NAME ) );
131
+
132
+ // Unset table offset
133
+ unset( $params['table_offset'] );
134
 
135
+ // Unset total tables count
136
+ unset( $params['total_tables_count'] );
137
 
138
  // Unset completed flag
139
  unset( $params['completed'] );
140
 
141
  } else {
142
 
143
+ // Get total tables count
144
+ $total_tables_count = count( $mysql->get_tables() );
145
+
146
+ // What percent of tables have we processed?
147
+ $progress = (int) ( ( $table_offset / $total_tables_count ) * 100 );
148
+
149
+ // Set progress
150
+ Ai1wm_Status::info( sprintf( __( 'Exporting database...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $progress ) );
151
+
152
+ // Set table offset
153
+ $params['table_offset'] = $table_offset;
154
+
155
+ // Set total tables count
156
+ $params['total_tables_count'] = $total_tables_count;
157
 
158
  // Set completed flag
159
  $params['completed'] = false;
lib/model/export/class-ai1wm-export-enumerate.php CHANGED
@@ -88,18 +88,18 @@ class Ai1wm_Export_Enumerate {
88
  $exclude_filters = array_merge( $exclude_filters, array( 'uploads', 'blogs.dir' ) );
89
  }
90
 
91
- // Get total files
92
- if ( isset( $params['total_files'] ) ) {
93
- $total_files = (int) $params['total_files'];
94
  } else {
95
- $total_files = 0;
96
  }
97
 
98
- // Get total size
99
- if ( isset( $params['total_size'] ) ) {
100
- $total_size = (int) $params['total_size'];
101
  } else {
102
- $total_size = 0;
103
  }
104
 
105
  // Create map file
@@ -120,10 +120,10 @@ class Ai1wm_Export_Enumerate {
120
  foreach ( $iterator as $item ) {
121
  if ( $item->isFile() ) {
122
  if ( ai1wm_write( $filemap, $iterator->getSubPathName() . PHP_EOL ) ) {
123
- $total_files++;
124
 
125
  // Add current file size
126
- $total_size += filesize( $iterator->getPathname() );
127
  }
128
  }
129
  }
@@ -136,11 +136,11 @@ class Ai1wm_Export_Enumerate {
136
  // Set progress
137
  Ai1wm_Status::info( __( 'Done retrieving a list of all WordPress files.', AI1WM_PLUGIN_NAME ) );
138
 
139
- // Set total files
140
- $params['total_files'] = $total_files;
141
 
142
- // Set total size
143
- $params['total_size'] = $total_size;
144
 
145
  // Close the filemap file
146
  ai1wm_close( $filemap );
88
  $exclude_filters = array_merge( $exclude_filters, array( 'uploads', 'blogs.dir' ) );
89
  }
90
 
91
+ // Get total files count
92
+ if ( isset( $params['total_files_count'] ) ) {
93
+ $total_files_count = (int) $params['total_files_count'];
94
  } else {
95
+ $total_files_count = 0;
96
  }
97
 
98
+ // Get total files size
99
+ if ( isset( $params['total_files_size'] ) ) {
100
+ $total_files_size = (int) $params['total_files_size'];
101
  } else {
102
+ $total_files_size = 0;
103
  }
104
 
105
  // Create map file
120
  foreach ( $iterator as $item ) {
121
  if ( $item->isFile() ) {
122
  if ( ai1wm_write( $filemap, $iterator->getSubPathName() . PHP_EOL ) ) {
123
+ $total_files_count++;
124
 
125
  // Add current file size
126
+ $total_files_size += filesize( $iterator->getPathname() );
127
  }
128
  }
129
  }
136
  // Set progress
137
  Ai1wm_Status::info( __( 'Done retrieving a list of all WordPress files.', AI1WM_PLUGIN_NAME ) );
138
 
139
+ // Set total files count
140
+ $params['total_files_count'] = $total_files_count;
141
 
142
+ // Set total files size
143
+ $params['total_files_size'] = $total_files_size;
144
 
145
  // Close the filemap file
146
  ai1wm_close( $filemap );
lib/model/import/class-ai1wm-import-blogs.php CHANGED
@@ -50,24 +50,52 @@ class Ai1wm_Import_Blogs {
50
  if ( isset( $multisite['Sites'] ) && ( $sites = $multisite['Sites'] ) ) {
51
  if ( count( $sites ) === 1 && ( $subsite = current( $sites ) ) ) {
52
 
 
 
 
 
 
 
 
 
 
 
53
  // Set active plugins (backward compatibility)
54
  if ( empty( $subsite['Plugins'] ) ) {
55
  $subsite['Plugins'] = array();
56
  }
57
 
 
 
 
 
 
 
 
 
 
 
58
  // Set blog items
59
  $blogs[] = array(
60
  'Old' => array(
61
- 'BlogID' => $subsite['BlogID'],
62
- 'SiteURL' => $subsite['SiteURL'],
63
- 'HomeURL' => $subsite['HomeURL'],
64
- 'Plugins' => $subsite['Plugins'],
 
 
 
 
65
  ),
66
  'New' => array(
67
- 'BlogID' => null,
68
- 'SiteURL' => site_url(),
69
- 'HomeURL' => home_url(),
70
- 'Plugins' => $subsite['Plugins'],
 
 
 
 
71
  ),
72
  );
73
  } else {
50
  if ( isset( $multisite['Sites'] ) && ( $sites = $multisite['Sites'] ) ) {
51
  if ( count( $sites ) === 1 && ( $subsite = current( $sites ) ) ) {
52
 
53
+ // Set internal Site URL (backward compatibility)
54
+ if ( empty( $subsite['InternalSiteURL'] ) ) {
55
+ $subsite['InternalSiteURL'] = null;
56
+ }
57
+
58
+ // Set internal Home URL (backward compatibility)
59
+ if ( empty( $subsite['InternalHomeURL'] ) ) {
60
+ $subsite['InternalHomeURL'] = null;
61
+ }
62
+
63
  // Set active plugins (backward compatibility)
64
  if ( empty( $subsite['Plugins'] ) ) {
65
  $subsite['Plugins'] = array();
66
  }
67
 
68
+ // Set active template (backward compatibility)
69
+ if ( empty( $subsite['Template'] ) ) {
70
+ $subsite['Template'] = null;
71
+ }
72
+
73
+ // Set active stylesheet (backward compatibility)
74
+ if ( empty( $subsite['Stylesheet'] ) ) {
75
+ $subsite['Stylesheet'] = null;
76
+ }
77
+
78
  // Set blog items
79
  $blogs[] = array(
80
  'Old' => array(
81
+ 'BlogID' => $subsite['BlogID'],
82
+ 'SiteURL' => $subsite['SiteURL'],
83
+ 'HomeURL' => $subsite['HomeURL'],
84
+ 'InternalSiteURL' => $subsite['InternalSiteURL'],
85
+ 'InternalHomeURL' => $subsite['InternalHomeURL'],
86
+ 'Plugins' => $subsite['Plugins'],
87
+ 'Template' => $subsite['Template'],
88
+ 'Stylesheet' => $subsite['Stylesheet'],
89
  ),
90
  'New' => array(
91
+ 'BlogID' => null,
92
+ 'SiteURL' => site_url(),
93
+ 'HomeURL' => home_url(),
94
+ 'InternalSiteURL' => site_url(),
95
+ 'InternalHomeURL' => home_url(),
96
+ 'Plugins' => $subsite['Plugins'],
97
+ 'Template' => $subsite['Template'],
98
+ 'Stylesheet' => $subsite['Stylesheet'],
99
  ),
100
  );
101
  } else {
lib/model/import/class-ai1wm-import-content.php CHANGED
@@ -51,18 +51,18 @@ class Ai1wm_Import_Content {
51
  $archive_offset = 0;
52
  }
53
 
54
- // Get total files
55
- if ( isset( $params['total_files'] ) ) {
56
- $total_files = (int) $params['total_files'];
57
  } else {
58
- $total_files = 1;
59
  }
60
 
61
- // Get total size
62
- if ( isset( $params['total_size'] ) ) {
63
- $total_size = (int) $params['total_size'];
64
  } else {
65
- $total_size = 1;
66
  }
67
 
68
  // Get processed files
@@ -73,11 +73,11 @@ class Ai1wm_Import_Content {
73
  }
74
 
75
  // What percent of files have we processed?
76
- $progress = (int) ( ( $processed / $total_size ) * 100 );
77
 
78
  // Set progress
79
  if ( empty( $content_offset ) ) {
80
- Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );
81
  }
82
 
83
  // Start time
@@ -157,11 +157,11 @@ class Ai1wm_Import_Content {
157
 
158
  // What percent of files have we processed?
159
  if ( ( $processed += ( $current_offset - $content_offset ) ) ) {
160
- $progress = (int) ( ( $processed / $total_size ) * 100 );
161
  }
162
 
163
  // Set progress
164
- Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files, $progress ) );
165
 
166
  // Set content offset
167
  $content_offset = $current_offset;
51
  $archive_offset = 0;
52
  }
53
 
54
+ // Get total files count
55
+ if ( isset( $params['total_files_count'] ) ) {
56
+ $total_files_count = (int) $params['total_files_count'];
57
  } else {
58
+ $total_files_count = 1;
59
  }
60
 
61
+ // Get total files size
62
+ if ( isset( $params['total_files_size'] ) ) {
63
+ $total_files_size = (int) $params['total_files_size'];
64
  } else {
65
+ $total_files_size = 1;
66
  }
67
 
68
  // Get processed files
73
  }
74
 
75
  // What percent of files have we processed?
76
+ $progress = (int) ( ( $processed / $total_files_size ) * 100 );
77
 
78
  // Set progress
79
  if ( empty( $content_offset ) ) {
80
+ Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
81
  }
82
 
83
  // Start time
157
 
158
  // What percent of files have we processed?
159
  if ( ( $processed += ( $current_offset - $content_offset ) ) ) {
160
+ $progress = (int) ( ( $processed / $total_files_size ) * 100 );
161
  }
162
 
163
  // Set progress
164
+ Ai1wm_Status::info( sprintf( __( 'Restoring %d files...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $total_files_count, $progress ) );
165
 
166
  // Set content offset
167
  $content_offset = $current_offset;
lib/model/import/class-ai1wm-import-database.php CHANGED
@@ -33,6 +33,20 @@ class Ai1wm_Import_Database {
33
  return $params;
34
  }
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  // Read blogs.json file
37
  $handle = ai1wm_open( ai1wm_blogs_path( $params ), 'r' );
38
 
@@ -53,312 +67,434 @@ class Ai1wm_Import_Database {
53
  // Close handle
54
  ai1wm_close( $handle );
55
 
 
 
 
56
  // Set progress
57
- Ai1wm_Status::info( __( 'Restoring database...', AI1WM_PLUGIN_NAME ) );
58
 
59
  $old_values = array();
60
  $new_values = array();
61
 
 
 
 
62
  // Get Blog URLs
63
  foreach ( $blogs as $blog ) {
64
 
65
- // Get blogs dir Upload Path
66
- if ( ! in_array( sprintf( "'%s'", trim( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '/' ) ), $old_values ) ) {
67
- $old_values[] = sprintf( "'%s'", trim( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '/' ) );
68
- $new_values[] = sprintf( "'%s'", get_option( 'upload_path' ) );
 
69
  }
70
 
71
- // Get sites dir Upload Path
72
- if ( ! in_array( sprintf( "'%s'", trim( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '/' ) ), $old_values ) ) {
73
- $old_values[] = sprintf( "'%s'", trim( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '/' ) );
74
- $new_values[] = sprintf( "'%s'", get_option( 'upload_path' ) );
75
  }
76
 
77
- // Handle old and new sites dir style
78
- if ( defined( 'UPLOADBLOGSDIR' ) ) {
79
 
80
- // Get Upload Path
81
- if ( ! in_array( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), $old_values ) ) {
82
- $old_values[] = ai1wm_blogsdir_path( $blog['Old']['BlogID'] );
83
- $new_values[] = ai1wm_blogsdir_path( $blog['New']['BlogID'] );
84
  }
85
 
86
- // Get escaped Upload Path
87
- if ( ! in_array( addslashes( addcslashes( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '\/' ) ), $old_values ) ) {
88
- $old_values[] = addslashes( addcslashes( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '\/' ) );
89
- $new_values[] = addslashes( addcslashes( ai1wm_blogsdir_path( $blog['New']['BlogID'] ), '\/' ) );
90
  }
91
 
92
- // Get Upload Path
93
- if ( ! in_array( ai1wm_uploads_path( $blog['Old']['BlogID'] ), $old_values ) ) {
94
- $old_values[] = ai1wm_uploads_path( $blog['Old']['BlogID'] );
95
- $new_values[] = ai1wm_blogsdir_path( $blog['New']['BlogID'] );
96
- }
97
 
98
- // Get escaped Upload Path
99
- if ( ! in_array( addslashes( addcslashes( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '\/' ) ), $old_values ) ) {
100
- $old_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '\/' ) );
101
- $new_values[] = addslashes( addcslashes( ai1wm_blogsdir_path( $blog['New']['BlogID'] ), '\/' ) );
102
- }
103
- } else {
104
 
105
- // Get files dir Upload URL
106
- if ( ! in_array( sprintf( '%s/%s/', untrailingslashit( $blog['Old']['HomeURL'] ), 'files' ), $old_values ) ) {
107
- $old_values[] = sprintf( '%s/%s/', untrailingslashit( $blog['Old']['HomeURL'] ), 'files' );
108
- $new_values[] = ai1wm_uploads_url( $blog['New']['BlogID'] );
109
- }
110
 
111
- // Get Upload Path
112
- if ( ! in_array( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), $old_values ) ) {
113
- $old_values[] = ai1wm_blogsdir_path( $blog['Old']['BlogID'] );
114
- $new_values[] = ai1wm_uploads_path( $blog['New']['BlogID'] );
115
- }
116
 
117
- // Get escaped Upload Path
118
- if ( ! in_array( addslashes( addcslashes( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '\/' ) ), $old_values ) ) {
119
- $old_values[] = addslashes( addcslashes( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '\/' ) );
120
- $new_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog['New']['BlogID'] ), '\/' ) );
121
- }
 
122
 
123
- // Get Upload Path
124
- if ( ! in_array( ai1wm_uploads_path( $blog['Old']['BlogID'] ), $old_values ) ) {
125
- $old_values[] = ai1wm_uploads_path( $blog['Old']['BlogID'] );
126
- $new_values[] = ai1wm_uploads_path( $blog['New']['BlogID'] );
127
- }
 
 
 
 
 
 
128
 
129
- // Get escaped Upload Path
130
- if ( ! in_array( addslashes( addcslashes( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '\/' ) ), $old_values ) ) {
131
- $old_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '\/' ) );
132
- $new_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog['New']['BlogID'] ), '\/' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  }
134
  }
135
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  // Get Site URL
137
- if ( isset( $blog['Old']['SiteURL'] ) && ( $blog['Old']['SiteURL'] !== $blog['New']['SiteURL'] ) ) {
138
 
139
- // Get domain
140
- $old_domain = parse_url( $blog['Old']['SiteURL'], PHP_URL_HOST );
141
- $new_domain = parse_url( $blog['New']['SiteURL'], PHP_URL_HOST );
142
 
143
- // Get scheme
144
- $new_scheme = parse_url( $blog['New']['SiteURL'], PHP_URL_SCHEME );
 
145
 
146
- // Replace Site URL scheme
147
- foreach ( array( 'http', 'https' ) as $old_scheme ) {
 
148
 
149
- // Add plain Site URL
150
- if ( ! in_array( set_url_scheme( $blog['Old']['SiteURL'], $old_scheme ), $old_values ) ) {
151
- $old_values[] = set_url_scheme( $blog['Old']['SiteURL'], $old_scheme );
152
- $new_values[] = set_url_scheme( $blog['New']['SiteURL'], $new_scheme );
153
- }
154
 
155
- // Add encoded Site URL
156
- if ( ! in_array( urlencode( set_url_scheme( $blog['Old']['SiteURL'], $old_scheme ) ), $old_values ) ) {
157
- $old_values[] = urlencode( set_url_scheme( $blog['Old']['SiteURL'], $old_scheme ) );
158
- $new_values[] = urlencode( set_url_scheme( $blog['New']['SiteURL'], $new_scheme ) );
159
  }
160
 
161
- // Add escaped Site URL
162
- if ( ! in_array( addslashes( addcslashes( set_url_scheme( $blog['Old']['SiteURL'], $old_scheme ), '/' ) ), $old_values ) ) {
163
- $old_values[] = addslashes( addcslashes( set_url_scheme( $blog['Old']['SiteURL'], $old_scheme ), '/' ) );
164
- $new_values[] = addslashes( addcslashes( set_url_scheme( $blog['New']['SiteURL'], $new_scheme ), '/' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  }
166
- }
167
 
168
- // Add email
169
- if ( ! isset( $config['NoEmailReplace'] ) ) {
170
- if ( ! in_array( sprintf( '@%s', $old_domain ), $old_values ) ) {
171
- $old_values[] = sprintf( '@%s', $old_domain );
172
- $new_values[] = sprintf( '@%s', $new_domain );
 
173
  }
174
  }
175
  }
176
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  // Get Home URL
178
- if ( isset( $blog['Old']['HomeURL'] ) && ( $blog['Old']['HomeURL'] !== $blog['New']['HomeURL'] ) ) {
179
 
180
- // Get domain
181
- $old_domain = parse_url( $blog['Old']['HomeURL'], PHP_URL_HOST );
182
- $new_domain = parse_url( $blog['New']['HomeURL'], PHP_URL_HOST );
183
 
184
- // Get scheme
185
- $new_scheme = parse_url( $blog['New']['HomeURL'], PHP_URL_SCHEME );
 
186
 
187
- // Replace Home URL scheme
188
- foreach ( array( 'http', 'https' ) as $old_scheme ) {
 
189
 
190
- // Add plain Home URL
191
- if ( ! in_array( set_url_scheme( $blog['Old']['HomeURL'], $old_scheme ), $old_values ) ) {
192
- $old_values[] = set_url_scheme( $blog['Old']['HomeURL'], $old_scheme );
193
- $new_values[] = set_url_scheme( $blog['New']['HomeURL'], $new_scheme );
194
- }
195
 
196
- // Add encoded Home URL
197
- if ( ! in_array( urlencode( set_url_scheme( $blog['Old']['HomeURL'], $old_scheme ) ), $old_values ) ) {
198
- $old_values[] = urlencode( set_url_scheme( $blog['Old']['HomeURL'], $old_scheme ) );
199
- $new_values[] = urlencode( set_url_scheme( $blog['New']['HomeURL'], $new_scheme ) );
200
  }
201
 
202
- // Add escaped Home URL
203
- if ( ! in_array( addslashes( addcslashes( set_url_scheme( $blog['Old']['HomeURL'], $old_scheme ), '/' ) ), $old_values ) ) {
204
- $old_values[] = addslashes( addcslashes( set_url_scheme( $blog['Old']['HomeURL'], $old_scheme ), '/' ) );
205
- $new_values[] = addslashes( addcslashes( set_url_scheme( $blog['New']['HomeURL'], $new_scheme ), '/' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
206
  }
207
- }
208
 
209
- // Add email
210
- if ( ! isset( $config['NoEmailReplace'] ) ) {
211
- if ( ! in_array( sprintf( '@%s', $old_domain ), $old_values ) ) {
212
- $old_values[] = sprintf( '@%s', $old_domain );
213
- $new_values[] = sprintf( '@%s', $new_domain );
 
214
  }
215
  }
216
  }
217
  }
218
 
219
- // Get Site URL
220
- if ( isset( $config['SiteURL'] ) && ( $config['SiteURL'] !== site_url() ) ) {
221
 
222
- // Get www URL
223
- if ( stripos( $config['SiteURL'], '//www.' ) !== false ) {
224
- $www = str_ireplace( '//www.', '//', $config['SiteURL'] );
225
- } else {
226
- $www = str_ireplace( '//', '//www.', $config['SiteURL'] );
227
- }
228
-
229
- // Replace Site URL
230
- foreach ( array( $config['SiteURL'], $www ) as $url ) {
231
 
232
- // Get domain
233
- $old_domain = parse_url( $url, PHP_URL_HOST );
234
- $new_domain = parse_url( site_url(), PHP_URL_HOST );
 
235
 
236
- // Get path
237
- $old_path = parse_url( $url, PHP_URL_PATH );
238
- $new_path = parse_url( site_url(), PHP_URL_PATH );
239
 
240
- // Get scheme
241
- $new_scheme = parse_url( site_url(), PHP_URL_SCHEME );
242
 
243
- // Add domain and path
244
- if ( ! in_array( sprintf( "%s','%s", $old_domain, trailingslashit( $old_path ) ), $old_values ) ) {
245
- $old_values[] = sprintf( "%s','%s", $old_domain, trailingslashit( $old_path ) );
246
- $new_values[] = sprintf( "%s','%s", $new_domain, trailingslashit( $new_path ) );
 
247
  }
248
 
249
- // Replace Site URL scheme
250
- foreach ( array( 'http', 'https' ) as $old_scheme ) {
251
 
252
- // Add plain Site URL
253
- if ( ! in_array( set_url_scheme( $url, $old_scheme ), $old_values ) ) {
254
- $old_values[] = set_url_scheme( $url, $old_scheme );
255
- $new_values[] = set_url_scheme( site_url(), $new_scheme );
256
- }
 
 
257
 
258
- // Add encoded Site URL
259
- if ( ! in_array( urlencode( set_url_scheme( $url, $old_scheme ) ), $old_values ) ) {
260
- $old_values[] = urlencode( set_url_scheme( $url, $old_scheme ) );
261
- $new_values[] = urlencode( set_url_scheme( site_url(), $new_scheme ) );
 
 
 
262
  }
263
 
264
- // Add escaped Site URL
265
- if ( ! in_array( addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) ), $old_values ) ) {
266
- $old_values[] = addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) );
267
- $new_values[] = addslashes( addcslashes( set_url_scheme( site_url(), $new_scheme ), '/' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
268
  }
269
- }
270
 
271
- // Add email
272
- if ( ! isset( $config['NoEmailReplace'] ) ) {
273
- if ( ! in_array( sprintf( '@%s', $old_domain ), $old_values ) ) {
274
- $old_values[] = sprintf( '@%s', $old_domain );
275
- $new_values[] = sprintf( '@%s', $new_domain );
 
276
  }
277
  }
278
  }
279
  }
280
 
281
- // Get Home URL
282
- if ( isset( $config['HomeURL'] ) && ( $config['HomeURL'] !== home_url() ) ) {
283
-
284
- // Get www URL
285
- if ( stripos( $config['HomeURL'], '//www.' ) !== false ) {
286
- $www = str_ireplace( '//www.', '//', $config['HomeURL'] );
287
- } else {
288
- $www = str_ireplace( '//', '//www.', $config['HomeURL'] );
289
- }
290
 
291
- // Replace Home URL
292
- foreach ( array( $config['HomeURL'], $www ) as $url ) {
 
 
293
 
294
- // Get domain
295
- $old_domain = parse_url( $url, PHP_URL_HOST );
296
- $new_domain = parse_url( home_url(), PHP_URL_HOST );
 
297
 
298
- // Get path
299
- $old_path = parse_url( $url, PHP_URL_PATH );
300
- $new_path = parse_url( home_url(), PHP_URL_PATH );
301
 
302
- // Get scheme
303
- $new_scheme = parse_url( home_url(), PHP_URL_SCHEME );
304
 
305
- // Add domain and path
306
- if ( ! in_array( sprintf( "%s','%s", $old_domain, trailingslashit( $old_path ) ), $old_values ) ) {
307
- $old_values[] = sprintf( "%s','%s", $old_domain, trailingslashit( $old_path ) );
308
- $new_values[] = sprintf( "%s','%s", $new_domain, trailingslashit( $new_path ) );
 
309
  }
310
 
311
- // Replace Home URL scheme
312
- foreach ( array( 'http', 'https' ) as $old_scheme ) {
313
 
314
- // Add plain Home URL
315
- if ( ! in_array( set_url_scheme( $url, $old_scheme ), $old_values ) ) {
316
- $old_values[] = set_url_scheme( $url, $old_scheme );
317
- $new_values[] = set_url_scheme( home_url(), $new_scheme );
318
- }
 
 
319
 
320
- // Add encoded Home URL
321
- if ( ! in_array( urlencode( set_url_scheme( $url, $old_scheme ) ), $old_values ) ) {
322
- $old_values[] = urlencode( set_url_scheme( $url, $old_scheme ) );
323
- $new_values[] = urlencode( set_url_scheme( home_url(), $new_scheme ) );
 
 
 
324
  }
325
 
326
- // Add escaped Home URL
327
- if ( ! in_array( addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) ), $old_values ) ) {
328
- $old_values[] = addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) );
329
- $new_values[] = addslashes( addcslashes( set_url_scheme( home_url(), $new_scheme ), '/' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
  }
331
- }
332
 
333
- // Add email
334
- if ( ! isset( $config['NoEmailReplace'] ) ) {
335
- if ( ! in_array( sprintf( '@%s', $old_domain ), $old_values ) ) {
336
- $old_values[] = sprintf( '@%s', $old_domain );
337
- $new_values[] = sprintf( '@%s', $new_domain );
 
338
  }
339
  }
340
  }
341
  }
342
 
343
- // Get WordPress Content
344
- if ( isset( $config['WordPress']['Content'] ) && ( $config['WordPress']['Content'] !== WP_CONTENT_DIR ) ) {
345
 
346
- // Add plain WordPress Content
347
- if ( ! in_array( $config['WordPress']['Content'], $old_values ) ) {
348
- $old_values[] = $config['WordPress']['Content'];
349
- $new_values[] = WP_CONTENT_DIR;
350
- }
 
 
 
351
 
352
- // Add encoded WordPress Content
353
- if ( ! in_array( urlencode( $config['WordPress']['Content'] ), $old_values ) ) {
354
- $old_values[] = urlencode( $config['WordPress']['Content'] );
355
- $new_values[] = urlencode( WP_CONTENT_DIR );
 
 
 
 
 
 
 
356
  }
 
357
 
358
- // Add escaped WordPress Content
359
- if ( ! in_array( addslashes( addcslashes( $config['WordPress']['Content'], '\/' ) ), $old_values ) ) {
360
- $old_values[] = addslashes( addcslashes( $config['WordPress']['Content'], '\/' ) );
361
- $new_values[] = addslashes( addcslashes( WP_CONTENT_DIR, '\/' ) );
 
 
 
 
 
362
  }
363
  }
364
 
@@ -414,37 +550,72 @@ class Ai1wm_Import_Database {
414
 
415
  // Get database client
416
  if ( empty( $wpdb->use_mysqli ) ) {
417
- $client = new Ai1wm_Database_Mysql( $wpdb );
418
  } else {
419
- $client = new Ai1wm_Database_Mysqli( $wpdb );
420
  }
421
 
422
  // Set database options
423
- $client->set_old_table_prefixes( $old_prefixes )
424
- ->set_new_table_prefixes( $new_prefixes )
425
- ->set_old_replace_values( $old_values )
426
- ->set_new_replace_values( $new_values );
 
 
427
 
428
  // Flush database
429
- if ( ( $version = $config['Plugin']['Version'] ) ) {
430
  if ( $version !== 'develop' && version_compare( $version, '4.10', '<' ) ) {
431
- $client->set_include_table_prefixes( array( ai1wm_table_prefix() ) );
432
- $client->flush();
433
  }
434
  }
435
 
 
 
 
436
  // Set Visual Composer
437
- $client->set_visual_composer( ! is_wp_error( validate_plugin( 'js_composer/js_composer.php' ) ) );
438
 
439
  // Import database
440
- $client->import( ai1wm_database_path( $params ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
 
442
  // Flush WP cache
443
  ai1wm_cache_flush();
444
 
445
- // Set progress
446
- Ai1wm_Status::info( __( 'Done restoring database...', AI1WM_PLUGIN_NAME ) );
447
-
448
  // Activate plugins
449
  ai1wm_activate_plugins( ai1wm_active_servmask_plugins() );
450
 
33
  return $params;
34
  }
35
 
36
+ // Set query offset
37
+ if ( isset( $params['query_offset'] ) ) {
38
+ $query_offset = (int) $params['query_offset'];
39
+ } else {
40
+ $query_offset = 0;
41
+ }
42
+
43
+ // Set total queries size
44
+ if ( isset( $params['total_queries_size'] ) ) {
45
+ $total_queries_size = (int) $params['total_queries_size'];
46
+ } else {
47
+ $total_queries_size = 1;
48
+ }
49
+
50
  // Read blogs.json file
51
  $handle = ai1wm_open( ai1wm_blogs_path( $params ), 'r' );
52
 
67
  // Close handle
68
  ai1wm_close( $handle );
69
 
70
+ // What percent of queries have we processed?
71
+ $progress = (int) ( ( $query_offset / $total_queries_size ) * 100 );
72
+
73
  // Set progress
74
+ Ai1wm_Status::info( sprintf( __( 'Restoring database...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $progress ) );
75
 
76
  $old_values = array();
77
  $new_values = array();
78
 
79
+ $old_raw_values = array();
80
+ $new_raw_values = array();
81
+
82
  // Get Blog URLs
83
  foreach ( $blogs as $blog ) {
84
 
85
+ $home_urls = array();
86
+
87
+ // Add Home URL
88
+ if ( ! empty( $blog['Old']['HomeURL'] ) ) {
89
+ $home_urls[] = $blog['Old']['HomeURL'];
90
  }
91
 
92
+ // Add Internal Home URL
93
+ if ( ! empty( $blog['Old']['InternalHomeURL'] ) ) {
94
+ $home_urls[] = $blog['Old']['InternalHomeURL'];
 
95
  }
96
 
97
+ // Get Home URL
98
+ foreach ( $home_urls as $home_url ) {
99
 
100
+ // Get blogs dir Upload Path
101
+ if ( ! in_array( sprintf( "'%s'", trim( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '/' ) ), $old_raw_values ) ) {
102
+ $old_raw_values[] = sprintf( "'%s'", trim( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '/' ) );
103
+ $new_raw_values[] = sprintf( "'%s'", get_option( 'upload_path' ) );
104
  }
105
 
106
+ // Get sites dir Upload Path
107
+ if ( ! in_array( sprintf( "'%s'", trim( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '/' ) ), $old_raw_values ) ) {
108
+ $old_raw_values[] = sprintf( "'%s'", trim( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '/' ) );
109
+ $new_raw_values[] = sprintf( "'%s'", get_option( 'upload_path' ) );
110
  }
111
 
112
+ // Handle old and new sites dir style
113
+ if ( defined( 'UPLOADBLOGSDIR' ) ) {
 
 
 
114
 
115
+ // Get Upload Path
116
+ if ( ! in_array( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), $old_values ) ) {
117
+ $old_values[] = ai1wm_blogsdir_path( $blog['Old']['BlogID'] );
118
+ $new_values[] = ai1wm_blogsdir_path( $blog['New']['BlogID'] );
119
+ }
 
120
 
121
+ // Get escaped Upload Path
122
+ if ( ! in_array( addslashes( addcslashes( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '\/' ) ), $old_values ) ) {
123
+ $old_values[] = addslashes( addcslashes( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '\/' ) );
124
+ $new_values[] = addslashes( addcslashes( ai1wm_blogsdir_path( $blog['New']['BlogID'] ), '\/' ) );
125
+ }
126
 
127
+ // Get Upload Path
128
+ if ( ! in_array( ai1wm_uploads_path( $blog['Old']['BlogID'] ), $old_values ) ) {
129
+ $old_values[] = ai1wm_uploads_path( $blog['Old']['BlogID'] );
130
+ $new_values[] = ai1wm_blogsdir_path( $blog['New']['BlogID'] );
131
+ }
132
 
133
+ // Get escaped Upload Path
134
+ if ( ! in_array( addslashes( addcslashes( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '\/' ) ), $old_values ) ) {
135
+ $old_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '\/' ) );
136
+ $new_values[] = addslashes( addcslashes( ai1wm_blogsdir_path( $blog['New']['BlogID'] ), '\/' ) );
137
+ }
138
+ } else {
139
 
140
+ // Get files dir Upload URL
141
+ if ( ! in_array( sprintf( '%s/%s/', untrailingslashit( $home_url ), 'files' ), $old_values ) ) {
142
+ $old_values[] = sprintf( '%s/%s/', untrailingslashit( $home_url ), 'files' );
143
+ $new_values[] = ai1wm_uploads_url( $blog['New']['BlogID'] );
144
+ }
145
+
146
+ // Get Upload Path
147
+ if ( ! in_array( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), $old_values ) ) {
148
+ $old_values[] = ai1wm_blogsdir_path( $blog['Old']['BlogID'] );
149
+ $new_values[] = ai1wm_uploads_path( $blog['New']['BlogID'] );
150
+ }
151
 
152
+ // Get escaped Upload Path
153
+ if ( ! in_array( addslashes( addcslashes( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '\/' ) ), $old_values ) ) {
154
+ $old_values[] = addslashes( addcslashes( ai1wm_blogsdir_path( $blog['Old']['BlogID'] ), '\/' ) );
155
+ $new_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog['New']['BlogID'] ), '\/' ) );
156
+ }
157
+
158
+ // Get Upload Path
159
+ if ( ! in_array( ai1wm_uploads_path( $blog['Old']['BlogID'] ), $old_values ) ) {
160
+ $old_values[] = ai1wm_uploads_path( $blog['Old']['BlogID'] );
161
+ $new_values[] = ai1wm_uploads_path( $blog['New']['BlogID'] );
162
+ }
163
+
164
+ // Get escaped Upload Path
165
+ if ( ! in_array( addslashes( addcslashes( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '\/' ) ), $old_values ) ) {
166
+ $old_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog['Old']['BlogID'] ), '\/' ) );
167
+ $new_values[] = addslashes( addcslashes( ai1wm_uploads_path( $blog['New']['BlogID'] ), '\/' ) );
168
+ }
169
  }
170
  }
171
 
172
+ $site_urls = array();
173
+
174
+ // Add Site URL
175
+ if ( ! empty( $blog['Old']['SiteURL'] ) ) {
176
+ $site_urls[] = $blog['Old']['SiteURL'];
177
+ }
178
+
179
+ // Add Internal Site URL
180
+ if ( ! empty( $blog['Old']['InternalSiteURL'] ) ) {
181
+ $site_urls[] = $blog['Old']['InternalSiteURL'];
182
+ }
183
+
184
  // Get Site URL
185
+ foreach ( $site_urls as $site_url ) {
186
 
187
+ // Replace Site URL
188
+ if ( $site_url !== $blog['New']['SiteURL'] ) {
 
189
 
190
+ // Get domain
191
+ $old_domain = parse_url( $site_url, PHP_URL_HOST );
192
+ $new_domain = parse_url( $blog['New']['SiteURL'], PHP_URL_HOST );
193
 
194
+ // Get path
195
+ $old_path = parse_url( $site_url, PHP_URL_PATH );
196
+ $new_path = parse_url( $blog['New']['SiteURL'], PHP_URL_PATH );
197
 
198
+ // Get scheme
199
+ $new_scheme = parse_url( $blog['New']['SiteURL'], PHP_URL_SCHEME );
 
 
 
200
 
201
+ // Add domain and path
202
+ if ( ! in_array( sprintf( "'%s','%s'", $old_domain, trailingslashit( $old_path ) ), $old_raw_values ) ) {
203
+ $old_raw_values[] = sprintf( "'%s','%s'", $old_domain, trailingslashit( $old_path ) );
204
+ $new_raw_values[] = sprintf( "'%s','%s'", $new_domain, trailingslashit( $new_path ) );
205
  }
206
 
207
+ // Replace Site URL scheme
208
+ foreach ( array( 'http', 'https' ) as $old_scheme ) {
209
+
210
+ // Add plain Site URL
211
+ if ( ! in_array( set_url_scheme( $site_url, $old_scheme ), $old_values ) ) {
212
+ $old_values[] = set_url_scheme( $site_url, $old_scheme );
213
+ $new_values[] = set_url_scheme( $blog['New']['SiteURL'], $new_scheme );
214
+ }
215
+
216
+ // Add encoded Site URL
217
+ if ( ! in_array( urlencode( set_url_scheme( $site_url, $old_scheme ) ), $old_values ) ) {
218
+ $old_values[] = urlencode( set_url_scheme( $site_url, $old_scheme ) );
219
+ $new_values[] = urlencode( set_url_scheme( $blog['New']['SiteURL'], $new_scheme ) );
220
+ }
221
+
222
+ // Add escaped Site URL
223
+ if ( ! in_array( addslashes( addcslashes( set_url_scheme( $site_url, $old_scheme ), '/' ) ), $old_values ) ) {
224
+ $old_values[] = addslashes( addcslashes( set_url_scheme( $site_url, $old_scheme ), '/' ) );
225
+ $new_values[] = addslashes( addcslashes( set_url_scheme( $blog['New']['SiteURL'], $new_scheme ), '/' ) );
226
+ }
227
  }
 
228
 
229
+ // Add email
230
+ if ( ! isset( $config['NoEmailReplace'] ) ) {
231
+ if ( ! in_array( sprintf( '@%s', $old_domain ), $old_values ) ) {
232
+ $old_values[] = sprintf( '@%s', $old_domain );
233
+ $new_values[] = sprintf( '@%s', $new_domain );
234
+ }
235
  }
236
  }
237
  }
238
 
239
+ $home_urls = array();
240
+
241
+ // Add Home URL
242
+ if ( ! empty( $blog['Old']['HomeURL'] ) ) {
243
+ $home_urls[] = $blog['Old']['HomeURL'];
244
+ }
245
+
246
+ // Add Internal Home URL
247
+ if ( ! empty( $blog['Old']['InternalHomeURL'] ) ) {
248
+ $home_urls[] = $blog['Old']['InternalHomeURL'];
249
+ }
250
+
251
  // Get Home URL
252
+ foreach ( $home_urls as $home_url ) {
253
 
254
+ // Replace Home URL
255
+ if ( $home_url !== $blog['New']['HomeURL'] ) {
 
256
 
257
+ // Get domain
258
+ $old_domain = parse_url( $home_url, PHP_URL_HOST );
259
+ $new_domain = parse_url( $blog['New']['HomeURL'], PHP_URL_HOST );
260
 
261
+ // Get path
262
+ $old_path = parse_url( $home_url, PHP_URL_PATH );
263
+ $new_path = parse_url( $blog['New']['HomeURL'], PHP_URL_PATH );
264
 
265
+ // Get scheme
266
+ $new_scheme = parse_url( $blog['New']['HomeURL'], PHP_URL_SCHEME );
 
 
 
267
 
268
+ // Add domain and path
269
+ if ( ! in_array( sprintf( "'%s','%s'", $old_domain, trailingslashit( $old_path ) ), $old_raw_values ) ) {
270
+ $old_raw_values[] = sprintf( "'%s','%s'", $old_domain, trailingslashit( $old_path ) );
271
+ $new_raw_values[] = sprintf( "'%s','%s'", $new_domain, trailingslashit( $new_path ) );
272
  }
273
 
274
+ // Replace Home URL scheme
275
+ foreach ( array( 'http', 'https' ) as $old_scheme ) {
276
+
277
+ // Add plain Home URL
278
+ if ( ! in_array( set_url_scheme( $home_url, $old_scheme ), $old_values ) ) {
279
+ $old_values[] = set_url_scheme( $home_url, $old_scheme );
280
+ $new_values[] = set_url_scheme( $blog['New']['HomeURL'], $new_scheme );
281
+ }
282
+
283
+ // Add encoded Home URL
284
+ if ( ! in_array( urlencode( set_url_scheme( $home_url, $old_scheme ) ), $old_values ) ) {
285
+ $old_values[] = urlencode( set_url_scheme( $home_url, $old_scheme ) );
286
+ $new_values[] = urlencode( set_url_scheme( $blog['New']['HomeURL'], $new_scheme ) );
287
+ }
288
+
289
+ // Add escaped Home URL
290
+ if ( ! in_array( addslashes( addcslashes( set_url_scheme( $home_url, $old_scheme ), '/' ) ), $old_values ) ) {
291
+ $old_values[] = addslashes( addcslashes( set_url_scheme( $home_url, $old_scheme ), '/' ) );
292
+ $new_values[] = addslashes( addcslashes( set_url_scheme( $blog['New']['HomeURL'], $new_scheme ), '/' ) );
293
+ }
294
  }
 
295
 
296
+ // Add email
297
+ if ( ! isset( $config['NoEmailReplace'] ) ) {
298
+ if ( ! in_array( sprintf( '@%s', $old_domain ), $old_values ) ) {
299
+ $old_values[] = sprintf( '@%s', $old_domain );
300
+ $new_values[] = sprintf( '@%s', $new_domain );
301
+ }
302
  }
303
  }
304
  }
305
  }
306
 
307
+ $site_urls = array();
 
308
 
309
+ // Add Site URL
310
+ if ( ! empty( $config['SiteURL'] ) ) {
311
+ $site_urls[] = $config['SiteURL'];
312
+ }
 
 
 
 
 
313
 
314
+ // Add Internal Site URL
315
+ if ( ! empty( $config['InternalSiteURL'] ) ) {
316
+ $site_urls[] = $config['InternalSiteURL'];
317
+ }
318
 
319
+ // Get Site URL
320
+ foreach ( $site_urls as $site_url ) {
 
321
 
322
+ // Replace Site URL
323
+ if ( $site_url !== site_url() ) {
324
 
325
+ // Get www URL
326
+ if ( stripos( $site_url, '//www.' ) !== false ) {
327
+ $www_url = str_ireplace( '//www.', '//', $site_url );
328
+ } else {
329
+ $www_url = str_ireplace( '//', '//www.', $site_url );
330
  }
331
 
332
+ // Replace Site URL
333
+ foreach ( array( $site_url, $www_url ) as $url ) {
334
 
335
+ // Get domain
336
+ $old_domain = parse_url( $url, PHP_URL_HOST );
337
+ $new_domain = parse_url( site_url(), PHP_URL_HOST );
338
+
339
+ // Get path
340
+ $old_path = parse_url( $url, PHP_URL_PATH );
341
+ $new_path = parse_url( site_url(), PHP_URL_PATH );
342
 
343
+ // Get scheme
344
+ $new_scheme = parse_url( site_url(), PHP_URL_SCHEME );
345
+
346
+ // Add domain and path
347
+ if ( ! in_array( sprintf( "'%s','%s'", $old_domain, trailingslashit( $old_path ) ), $old_raw_values ) ) {
348
+ $old_raw_values[] = sprintf( "'%s','%s'", $old_domain, trailingslashit( $old_path ) );
349
+ $new_raw_values[] = sprintf( "'%s','%s'", $new_domain, trailingslashit( $new_path ) );
350
  }
351
 
352
+ // Replace Site URL scheme
353
+ foreach ( array( 'http', 'https' ) as $old_scheme ) {
354
+
355
+ // Add plain Site URL
356
+ if ( ! in_array( set_url_scheme( $url, $old_scheme ), $old_values ) ) {
357
+ $old_values[] = set_url_scheme( $url, $old_scheme );
358
+ $new_values[] = set_url_scheme( site_url(), $new_scheme );
359
+ }
360
+
361
+ // Add encoded Site URL
362
+ if ( ! in_array( urlencode( set_url_scheme( $url, $old_scheme ) ), $old_values ) ) {
363
+ $old_values[] = urlencode( set_url_scheme( $url, $old_scheme ) );
364
+ $new_values[] = urlencode( set_url_scheme( site_url(), $new_scheme ) );
365
+ }
366
+
367
+ // Add escaped Site URL
368
+ if ( ! in_array( addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) ), $old_values ) ) {
369
+ $old_values[] = addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) );
370
+ $new_values[] = addslashes( addcslashes( set_url_scheme( site_url(), $new_scheme ), '/' ) );
371
+ }
372
  }
 
373
 
374
+ // Add email
375
+ if ( ! isset( $config['NoEmailReplace'] ) ) {
376
+ if ( ! in_array( sprintf( '@%s', $old_domain ), $old_values ) ) {
377
+ $old_values[] = sprintf( '@%s', $old_domain );
378
+ $new_values[] = sprintf( '@%s', $new_domain );
379
+ }
380
  }
381
  }
382
  }
383
  }
384
 
385
+ $home_urls = array();
 
 
 
 
 
 
 
 
386
 
387
+ // Add Home URL
388
+ if ( ! empty( $config['HomeURL'] ) ) {
389
+ $home_urls[] = $config['HomeURL'];
390
+ }
391
 
392
+ // Add Internal Home URL
393
+ if ( ! empty( $config['InternalHomeURL'] ) ) {
394
+ $home_urls[] = $config['InternalHomeURL'];
395
+ }
396
 
397
+ // Get Home URL
398
+ foreach ( $home_urls as $home_url ) {
 
399
 
400
+ // Replace Home URL
401
+ if ( $home_url !== home_url() ) {
402
 
403
+ // Get www URL
404
+ if ( stripos( $home_url, '//www.' ) !== false ) {
405
+ $www_url = str_ireplace( '//www.', '//', $home_url );
406
+ } else {
407
+ $www_url = str_ireplace( '//', '//www.', $home_url );
408
  }
409
 
410
+ // Replace Home URL
411
+ foreach ( array( $home_url, $www_url ) as $url ) {
412
 
413
+ // Get domain
414
+ $old_domain = parse_url( $url, PHP_URL_HOST );
415
+ $new_domain = parse_url( home_url(), PHP_URL_HOST );
416
+
417
+ // Get path
418
+ $old_path = parse_url( $url, PHP_URL_PATH );
419
+ $new_path = parse_url( home_url(), PHP_URL_PATH );
420
 
421
+ // Get scheme
422
+ $new_scheme = parse_url( home_url(), PHP_URL_SCHEME );
423
+
424
+ // Add domain and path
425
+ if ( ! in_array( sprintf( "'%s','%s'", $old_domain, trailingslashit( $old_path ) ), $old_raw_values ) ) {
426
+ $old_raw_values[] = sprintf( "'%s','%s'", $old_domain, trailingslashit( $old_path ) );
427
+ $new_raw_values[] = sprintf( "'%s','%s'", $new_domain, trailingslashit( $new_path ) );
428
  }
429
 
430
+ // Replace Home URL scheme
431
+ foreach ( array( 'http', 'https' ) as $old_scheme ) {
432
+
433
+ // Add plain Home URL
434
+ if ( ! in_array( set_url_scheme( $url, $old_scheme ), $old_values ) ) {
435
+ $old_values[] = set_url_scheme( $url, $old_scheme );
436
+ $new_values[] = set_url_scheme( home_url(), $new_scheme );
437
+ }
438
+
439
+ // Add encoded Home URL
440
+ if ( ! in_array( urlencode( set_url_scheme( $url, $old_scheme ) ), $old_values ) ) {
441
+ $old_values[] = urlencode( set_url_scheme( $url, $old_scheme ) );
442
+ $new_values[] = urlencode( set_url_scheme( home_url(), $new_scheme ) );
443
+ }
444
+
445
+ // Add escaped Home URL
446
+ if ( ! in_array( addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) ), $old_values ) ) {
447
+ $old_values[] = addslashes( addcslashes( set_url_scheme( $url, $old_scheme ), '/' ) );
448
+ $new_values[] = addslashes( addcslashes( set_url_scheme( home_url(), $new_scheme ), '/' ) );
449
+ }
450
  }
 
451
 
452
+ // Add email
453
+ if ( ! isset( $config['NoEmailReplace'] ) ) {
454
+ if ( ! in_array( sprintf( '@%s', $old_domain ), $old_values ) ) {
455
+ $old_values[] = sprintf( '@%s', $old_domain );
456
+ $new_values[] = sprintf( '@%s', $new_domain );
457
+ }
458
  }
459
  }
460
  }
461
  }
462
 
463
+ // Get WordPress Content Dir
464
+ if ( isset( $config['WordPress']['Content'] ) && ( $content_dir = $config['WordPress']['Content'] ) ) {
465
 
466
+ // Replace WordPress Content Dir
467
+ if ( $content_dir !== WP_CONTENT_DIR ) {
468
+
469
+ // Add plain WordPress Content
470
+ if ( ! in_array( $content_dir, $old_values ) ) {
471
+ $old_values[] = $content_dir;
472
+ $new_values[] = WP_CONTENT_DIR;
473
+ }
474
 
475
+ // Add encoded WordPress Content
476
+ if ( ! in_array( urlencode( $content_dir ), $old_values ) ) {
477
+ $old_values[] = urlencode( $content_dir );
478
+ $new_values[] = urlencode( WP_CONTENT_DIR );
479
+ }
480
+
481
+ // Add escaped WordPress Content
482
+ if ( ! in_array( addslashes( addcslashes( $content_dir, '\/' ) ), $old_values ) ) {
483
+ $old_values[] = addslashes( addcslashes( $content_dir, '\/' ) );
484
+ $new_values[] = addslashes( addcslashes( WP_CONTENT_DIR, '\/' ) );
485
+ }
486
  }
487
+ }
488
 
489
+ // Get replace old and new values
490
+ if ( isset( $config['Replace'] ) && ( $replace = $config['Replace'] ) ) {
491
+ for ( $i = 0; $i < count( $replace['OldValues'] ); $i++ ) {
492
+ if ( ! empty( $replace['OldValues'][ $i ] ) && ! empty( $replace['NewValues'][ $i ] ) ) {
493
+ if ( ! in_array( $replace['OldValues'][ $i ], $old_values ) ) {
494
+ $old_values[] = $replace['OldValues'][ $i ];
495
+ $new_values[] = $replace['NewValues'][ $i ];
496
+ }
497
+ }
498
  }
499
  }
500
 
550
 
551
  // Get database client
552
  if ( empty( $wpdb->use_mysqli ) ) {
553
+ $mysql = new Ai1wm_Database_Mysql( $wpdb );
554
  } else {
555
+ $mysql = new Ai1wm_Database_Mysqli( $wpdb );
556
  }
557
 
558
  // Set database options
559
+ $mysql->set_old_table_prefixes( $old_prefixes )
560
+ ->set_new_table_prefixes( $new_prefixes )
561
+ ->set_old_replace_values( $old_values )
562
+ ->set_new_replace_values( $new_values )
563
+ ->set_old_replace_raw_values( $old_raw_values )
564
+ ->set_new_replace_raw_values( $new_raw_values );
565
 
566
  // Flush database
567
+ if ( isset( $config['Plugin']['Version'] ) && ( $version = $config['Plugin']['Version'] ) ) {
568
  if ( $version !== 'develop' && version_compare( $version, '4.10', '<' ) ) {
569
+ $mysql->set_include_table_prefixes( array( ai1wm_table_prefix() ) );
570
+ $mysql->flush();
571
  }
572
  }
573
 
574
+ // Set atomic tables (do not stop the current request for all listed tables if timeout has been exceeded)
575
+ $mysql->set_atomic_tables( array( ai1wm_table_prefix() . 'options' ) );
576
+
577
  // Set Visual Composer
578
+ $mysql->set_visual_composer( ! is_wp_error( validate_plugin( 'js_composer/js_composer.php' ) ) );
579
 
580
  // Import database
581
+ if ( $mysql->import( ai1wm_database_path( $params ), $query_offset, 10 ) ) {
582
+
583
+ // Set progress
584
+ Ai1wm_Status::info( __( 'Done restoring database...', AI1WM_PLUGIN_NAME ) );
585
+
586
+ // Unset query offset
587
+ unset( $params['query_offset'] );
588
+
589
+ // Unset total queries size
590
+ unset( $params['total_queries_size'] );
591
+
592
+ // Unset completed flag
593
+ unset( $params['completed'] );
594
+
595
+ } else {
596
+
597
+ // Get total queries size
598
+ $total_queries_size = ai1wm_database_bytes( $params );
599
+
600
+ // What percent of queries have we processed?
601
+ $progress = (int) ( ( $query_offset / $total_queries_size ) * 100 );
602
+
603
+ // Set progress
604
+ Ai1wm_Status::info( sprintf( __( 'Restoring database...<br />%d%% complete', AI1WM_PLUGIN_NAME ), $progress ) );
605
+
606
+ // Set query offset
607
+ $params['query_offset'] = $query_offset;
608
+
609
+ // Set total queries size
610
+ $params['total_queries_size'] = $total_queries_size;
611
+
612
+ // Set completed flag
613
+ $params['completed'] = false;
614
+ }
615
 
616
  // Flush WP cache
617
  ai1wm_cache_flush();
618
 
 
 
 
619
  // Activate plugins
620
  ai1wm_activate_plugins( ai1wm_active_servmask_plugins() );
621
 
lib/model/import/class-ai1wm-import-done.php CHANGED
@@ -27,12 +27,8 @@ class Ai1wm_Import_Done {
27
 
28
  public static function execute( $params ) {
29
 
30
- // Set shutdown handler
31
- @register_shutdown_function( 'Ai1wm_Import_Done::shutdown' );
32
-
33
  // Check multisite.json file
34
  if ( true === is_file( ai1wm_multisite_path( $params ) ) ) {
35
-
36
  // Read multisite.json file
37
  $handle = ai1wm_open( ai1wm_multisite_path( $params ), 'r' );
38
 
@@ -45,14 +41,9 @@ class Ai1wm_Import_Done {
45
 
46
  // Activate sitewide plugins
47
  if ( isset( $multisite['Plugins'] ) && ( $plugins = $multisite['Plugins'] ) ) {
48
- // Activate sitewide plugins
49
  ai1wm_activate_plugins( $plugins );
50
-
51
- // Disable Jetpack Photon module
52
- ai1wm_disable_jetpack_photon();
53
  }
54
  } else {
55
-
56
  // Check package.json file
57
  if ( true === is_file( ai1wm_package_path( $params ) ) ) {
58
 
@@ -68,18 +59,26 @@ class Ai1wm_Import_Done {
68
 
69
  // Activate plugins
70
  if ( isset( $package['Plugins'] ) && ( $plugins = $package['Plugins'] ) ) {
71
- // Activate plugins
72
  ai1wm_activate_plugins( $plugins );
 
73
 
74
- // Disable Jetpack Photon module
75
- ai1wm_disable_jetpack_photon();
 
76
  }
 
 
 
 
 
 
 
 
77
  }
78
  }
79
 
80
  // Check blogs.json file
81
  if ( true === is_file( ai1wm_blogs_path( $params ) ) ) {
82
-
83
  // Read blogs.json file
84
  $handle = ai1wm_open( ai1wm_blogs_path( $params ), 'r' );
85
 
@@ -90,22 +89,28 @@ class Ai1wm_Import_Done {
90
  // Close handle
91
  ai1wm_close( $handle );
92
 
93
- // Activate plugins
94
  foreach ( $blogs as $blog ) {
 
 
95
  if ( isset( $blog['New']['Plugins'] ) && ( $plugins = $blog['New']['Plugins'] ) ) {
96
- // Activate plugins
97
  ai1wm_activate_plugins( $plugins );
 
98
 
99
- // Disable Jetpack Photon module
100
- ai1wm_disable_jetpack_photon();
 
101
  }
102
- }
103
- }
104
 
105
- return $params;
106
- }
 
 
107
 
108
- public static function shutdown() {
 
 
 
109
 
110
  // Set progress
111
  Ai1wm_Status::done(
@@ -123,5 +128,7 @@ class Ai1wm_Import_Done {
123
  AI1WM_PLUGIN_NAME
124
  )
125
  );
 
 
126
  }
127
  }
27
 
28
  public static function execute( $params ) {
29
 
 
 
 
30
  // Check multisite.json file
31
  if ( true === is_file( ai1wm_multisite_path( $params ) ) ) {
 
32
  // Read multisite.json file
33
  $handle = ai1wm_open( ai1wm_multisite_path( $params ), 'r' );
34
 
41
 
42
  // Activate sitewide plugins
43
  if ( isset( $multisite['Plugins'] ) && ( $plugins = $multisite['Plugins'] ) ) {
 
44
  ai1wm_activate_plugins( $plugins );
 
 
 
45
  }
46
  } else {
 
47
  // Check package.json file
48
  if ( true === is_file( ai1wm_package_path( $params ) ) ) {
49
 
59
 
60
  // Activate plugins
61
  if ( isset( $package['Plugins'] ) && ( $plugins = $package['Plugins'] ) ) {
 
62
  ai1wm_activate_plugins( $plugins );
63
+ }
64
 
65
+ // Activate template
66
+ if ( isset( $package['Template'] ) && ( $template = $package['Template'] ) ) {
67
+ ai1wm_activate_template( $template );
68
  }
69
+
70
+ // Activate stylesheet
71
+ if ( isset( $package['Stylesheet'] ) && ( $stylesheet = $package['Stylesheet'] ) ) {
72
+ ai1wm_activate_stylesheet( $stylesheet );
73
+ }
74
+
75
+ // Disable Jetpack Photon module
76
+ ai1wm_disable_jetpack_photon();
77
  }
78
  }
79
 
80
  // Check blogs.json file
81
  if ( true === is_file( ai1wm_blogs_path( $params ) ) ) {
 
82
  // Read blogs.json file
83
  $handle = ai1wm_open( ai1wm_blogs_path( $params ), 'r' );
84
 
89
  // Close handle
90
  ai1wm_close( $handle );
91
 
92
+ // Loop over blogs
93
  foreach ( $blogs as $blog ) {
94
+
95
+ // Activate plugins
96
  if ( isset( $blog['New']['Plugins'] ) && ( $plugins = $blog['New']['Plugins'] ) ) {
 
97
  ai1wm_activate_plugins( $plugins );
98
+ }
99
 
100
+ // Activate template
101
+ if ( isset( $blog['New']['Template'] ) && ( $template = $blog['New']['Template'] ) ) {
102
+ ai1wm_activate_template( $template );
103
  }
 
 
104
 
105
+ // Activate stylesheet
106
+ if ( isset( $blog['New']['Stylesheet'] ) && ( $stylesheet = $blog['New']['Stylesheet'] ) ) {
107
+ ai1wm_activate_stylesheet( $stylesheet );
108
+ }
109
 
110
+ // Disable Jetpack Photon module
111
+ ai1wm_disable_jetpack_photon();
112
+ }
113
+ }
114
 
115
  // Set progress
116
  Ai1wm_Status::done(
128
  AI1WM_PLUGIN_NAME
129
  )
130
  );
131
+
132
+ return $params;
133
  }
134
  }
lib/model/import/class-ai1wm-import-enumerate.php CHANGED
@@ -33,11 +33,11 @@ class Ai1wm_Import_Enumerate {
33
  // Open the archive file for reading
34
  $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );
35
 
36
- // Get total files
37
- $params['total_files'] = $archive->get_total_files();
38
 
39
- // Get total size
40
- $params['total_size'] = $archive->get_total_size();
41
 
42
  // Close the archive file
43
  $archive->close();
33
  // Open the archive file for reading
34
  $archive = new Ai1wm_Extractor( ai1wm_archive_path( $params ) );
35
 
36
+ // Get total files count
37
+ $params['total_files_count'] = $archive->get_total_files_count();
38
 
39
+ // Get total files size
40
+ $params['total_files_size'] = $archive->get_total_files_size();
41
 
42
  // Close the archive file
43
  $archive->close();
lib/model/import/{class-ai1wm-import-plugins.php → class-ai1wm-import-mu-plugins.php} RENAMED
@@ -23,7 +23,7 @@
23
  * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
24
  */
25
 
26
- class Ai1wm_Import_Plugins {
27
 
28
  public static function execute( $params ) {
29
 
23
  * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
24
  */
25
 
26
+ class Ai1wm_Import_Mu_Plugins {
27
 
28
  public static function execute( $params ) {
29
 
lib/model/import/class-ai1wm-import-upload.php CHANGED
@@ -103,6 +103,8 @@ class Ai1wm_Import_Upload {
103
  400
104
  );
105
  }
 
 
106
  exit;
107
  }
108
  }
103
  400
104
  );
105
  }
106
+
107
+ echo json_encode( array( 'errors' => array() ) );
108
  exit;
109
  }
110
  }
lib/vendor/servmask/archiver/class-ai1wm-archiver.php CHANGED
@@ -37,10 +37,10 @@ abstract class Ai1wm_Archiver {
37
  * @type string
38
  */
39
  protected $block_format = array(
40
- 'a255', // filename
41
- 'a14', // size of file contents
42
- 'a12', // last time modified
43
- 'a4096' // path
44
  );
45
 
46
  public function get_block_format() {
37
  * @type string
38
  */
39
  protected $block_format = array(
40
+ 'a255', // filename
41
+ 'a14', // size of file contents
42
+ 'a12', // last time modified
43
+ 'a4096', // path
44
  );
45
 
46
  public function get_block_format() {
lib/vendor/servmask/archiver/class-ai1wm-extractor.php CHANGED
@@ -36,17 +36,17 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
36
  }
37
 
38
  /**
39
- * Get the total files in an archive
40
  *
41
- * @return int Total files in the archive
42
  * @throws \Ai1wm_Not_Accesible_Exception
43
  * @throws \Ai1wm_Not_Readable_Exception
44
  */
45
- public function get_total_files() {
46
  fseek( $this->file_handle, SEEK_SET, 0 );
47
 
48
- // total files
49
- $total_files = 0;
50
 
51
  while ( $block = $this->read_from_handle( $this->file_handle, 4377 ) ) {
52
  // end block has been reached
@@ -58,27 +58,27 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
58
  $data = $this->get_data_from_block( $block );
59
 
60
  // we have a file, increment the counter
61
- $total_files++;
62
 
63
  // skip file content so we can move forward to the next file
64
  $this->set_file_pointer( $this->file_handle, $data['size'] );
65
  }
66
 
67
- return $total_files;
68
  }
69
 
70
  /**
71
- * Get the total size of files in an archive
72
  *
73
- * @return int Total size of files in the archive
74
  * @throws \Ai1wm_Not_Accesible_Exception
75
  * @throws \Ai1wm_Not_Readable_Exception
76
  */
77
- public function get_total_size() {
78
  fseek( $this->file_handle, SEEK_SET, 0 );
79
 
80
- // total size
81
- $total_size = 0;
82
 
83
  while ( $block = $this->read_from_handle( $this->file_handle, 4377 ) ) {
84
  // end block has been reached
@@ -90,13 +90,13 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
90
  $data = $this->get_data_from_block( $block );
91
 
92
  // we have a file, increment the counter
93
- $total_size += $data['size'];
94
 
95
  // skip file content so we can move forward to the next file
96
  $this->set_file_pointer( $this->file_handle, $data['size'] );
97
  }
98
 
99
- return $total_size;
100
  }
101
 
102
  public function extract_one_file_to( $location, $exclude = array(), $old_paths = array(), $new_paths = array(), $offset = 0, $timeout = 0 ) {
@@ -131,7 +131,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
131
 
132
  // should we skip this file?
133
  for ( $i = 0; $i < count( $exclude ); $i++ ) {
134
- if ( strpos( $filename . DIRECTORY_SEPARATOR, $exclude[$i] . DIRECTORY_SEPARATOR ) === 0 ) {
135
  $this->set_file_pointer( $this->file_handle, $data['size'] );
136
  return;
137
  }
@@ -139,8 +139,8 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
139
 
140
  // replace extract paths
141
  for ( $i = 0; $i < count( $old_paths ); $i++ ) {
142
- if ( strpos( $path . DIRECTORY_SEPARATOR, $old_paths[$i] . DIRECTORY_SEPARATOR ) === 0 ) {
143
- $path = substr_replace( $path, $new_paths[$i], 0, strlen( $old_paths[$i] ) );
144
  break;
145
  }
146
  }
@@ -210,7 +210,7 @@ class Ai1wm_Extractor extends Ai1wm_Archiver {
210
 
211
  // files to extract
212
  for ( $i = 0; $i < count( $files ); $i++ ) {
213
- if ( strpos( $filename . DIRECTORY_SEPARATOR, $files[$i] . DIRECTORY_SEPARATOR ) === 0 ) {
214
  $include = true;
215
  break;
216
  }
36
  }
37
 
38
  /**
39
+ * Get the total files count in an archive
40
  *
41
+ * @return int Total files count in the archive
42
  * @throws \Ai1wm_Not_Accesible_Exception
43
  * @throws \Ai1wm_Not_Readable_Exception
44
  */
45
+ public function get_total_files_count() {
46
  fseek( $this->file_handle, SEEK_SET, 0 );
47
 
48
+ // total files count
49
+ $total_files_count = 0;
50
 
51
  while ( $block = $this->read_from_handle( $this->file_handle, 4377 ) ) {
52
  // end block has been reached
58
  $data = $this->get_data_from_block( $block );
59
 
60
  // we have a file, increment the counter
61
+ $total_files_count++;
62
 
63
  // skip file content so we can move forward to the next file
64
  $this->set_file_pointer( $this->file_handle, $data['size'] );
65
  }
66
 
67
+ return $total_files_count;
68
  }
69
 
70
  /**
71
+ * Get the total files size in an archive
72
  *
73
+ * @return int Total files size in the archive
74
  * @throws \Ai1wm_Not_Accesible_Exception
75
  * @throws \Ai1wm_Not_Readable_Exception
76
  */
77
+ public function get_total_files_size() {
78
  fseek( $this->file_handle, SEEK_SET, 0 );
79
 
80
+ // total files size
81
+ $total_files_size = 0;
82
 
83
  while ( $block = $this->read_from_handle( $this->file_handle, 4377 ) ) {
84
  // end block has been reached
90
  $data = $this->get_data_from_block( $block );
91
 
92
  // we have a file, increment the counter
93
+ $total_files_size += $data['size'];
94
 
95
  // skip file content so we can move forward to the next file
96
  $this->set_file_pointer( $this->file_handle, $data['size'] );
97
  }
98
 
99
+ return $total_files_size;
100
  }
101
 
102
  public function extract_one_file_to( $location, $exclude = array(), $old_paths = array(), $new_paths = array(), $offset = 0, $timeout = 0 ) {
131
 
132
  // should we skip this file?
133
  for ( $i = 0; $i < count( $exclude ); $i++ ) {
134
+ if ( strpos( $filename . DIRECTORY_SEPARATOR, $exclude[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
135
  $this->set_file_pointer( $this->file_handle, $data['size'] );
136
  return;
137
  }
139
 
140
  // replace extract paths
141
  for ( $i = 0; $i < count( $old_paths ); $i++ ) {
142
+ if ( strpos( $path . DIRECTORY_SEPARATOR, $old_paths[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
143
+ $path = substr_replace( $path, $new_paths[ $i ], 0, strlen( $old_paths[ $i ] ) );
144
  break;
145
  }
146
  }
210
 
211
  // files to extract
212
  for ( $i = 0; $i < count( $files ); $i++ ) {
213
+ if ( strpos( $filename . DIRECTORY_SEPARATOR, $files[ $i ] . DIRECTORY_SEPARATOR ) === 0 ) {
214
  $include = true;
215
  break;
216
  }
lib/vendor/servmask/cron/class-ai1wm-cron.php CHANGED
@@ -38,7 +38,7 @@ class Ai1wm_Cron {
38
  $args = array_slice( func_get_args(), 2 );
39
  $schedules = wp_get_schedules();
40
 
41
- if ( isset( $schedules[$recurrence] ) && ( $current = $schedules[$recurrence] ) ) {
42
  return wp_schedule_event( time() + $current['interval'], $recurrence, $hook, $args );
43
  }
44
  }
@@ -57,12 +57,12 @@ class Ai1wm_Cron {
57
  }
58
 
59
  foreach ( $crons as $timestamp => $cron ) {
60
- if ( ! empty( $cron[$hook] ) ) {
61
- unset( $crons[$timestamp][$hook] );
62
 
63
  // Unset empty timestamps
64
- if ( empty( $crons[$timestamp] ) ) {
65
- unset( $crons[$timestamp] );
66
  }
67
  }
68
  }
38
  $args = array_slice( func_get_args(), 2 );
39
  $schedules = wp_get_schedules();
40
 
41
+ if ( isset( $schedules[ $recurrence ] ) && ( $current = $schedules[ $recurrence ] ) ) {
42
  return wp_schedule_event( time() + $current['interval'], $recurrence, $hook, $args );
43
  }
44
  }
57
  }
58
 
59
  foreach ( $crons as $timestamp => $cron ) {
60
+ if ( ! empty( $cron[ $hook ] ) ) {
61
+ unset( $crons[ $timestamp ][ $hook ] );
62
 
63
  // Unset empty timestamps
64
+ if ( empty( $crons[ $timestamp ] ) ) {
65
+ unset( $crons[ $timestamp ] );
66
  }
67
  }
68
  }
lib/vendor/servmask/database/class-ai1wm-database-mysql.php CHANGED
@@ -101,4 +101,4 @@ class Ai1wm_Database_Mysql extends Ai1wm_Database {
101
  public function free_result( $result ) {
102
  return mysql_free_result( $result );
103
  }
104
- }
101
  public function free_result( $result ) {
102
  return mysql_free_result( $result );
103
  }
104
+ }
lib/vendor/servmask/database/class-ai1wm-database-mysqli.php CHANGED
@@ -101,4 +101,4 @@ class Ai1wm_Database_Mysqli extends Ai1wm_Database {
101
  public function free_result( $result ) {
102
  return mysqli_free_result( $result );
103
  }
104
- }
101
  public function free_result( $result ) {
102
  return mysqli_free_result( $result );
103
  }
104
+ }
lib/vendor/servmask/database/class-ai1wm-database-utility.php CHANGED
@@ -58,7 +58,7 @@ class Ai1wm_Database_Utility {
58
  } else if ( is_array( $data ) ) {
59
  $tmp = array();
60
  foreach ( $data as $key => $value ) {
61
- $tmp[$key] = self::replace_serialized_values( $from, $to, $value, false );
62
  }
63
 
64
  $data = $tmp;
@@ -81,7 +81,6 @@ class Ai1wm_Database_Utility {
81
  if ( $serialized ) {
82
  return serialize( $data );
83
  }
84
-
85
  } catch ( Exception $e ) {
86
  // pass
87
  }
@@ -96,7 +95,7 @@ class Ai1wm_Database_Utility {
96
  * @return string
97
  */
98
  public static function escape_mysql( $data ) {
99
- return str_ireplace(
100
  array( '\\', '\0', "\n", "\r", "\x1a", "'", '"', "\0" ),
101
  array( '\\\\', '\\0', "\\n", "\\r", '\Z', "\'", '\"', '\0' ),
102
  $data
@@ -110,7 +109,7 @@ class Ai1wm_Database_Utility {
110
  * @return string
111
  */
112
  public static function unescape_mysql( $data ) {
113
- return str_ireplace(
114
  array( '\\\\', '\\0', "\\n", "\\r", '\Z', "\'", '\"', '\0' ),
115
  array( '\\', '\0', "\n", "\r", "\x1a", "'", '"', "\0" ),
116
  $data
58
  } else if ( is_array( $data ) ) {
59
  $tmp = array();
60
  foreach ( $data as $key => $value ) {
61
+ $tmp[ $key ] = self::replace_serialized_values( $from, $to, $value, false );
62
  }
63
 
64
  $data = $tmp;
81
  if ( $serialized ) {
82
  return serialize( $data );
83
  }
 
84
  } catch ( Exception $e ) {
85
  // pass
86
  }
95
  * @return string
96
  */
97
  public static function escape_mysql( $data ) {
98
+ return str_replace(
99
  array( '\\', '\0', "\n", "\r", "\x1a", "'", '"', "\0" ),
100
  array( '\\\\', '\\0', "\\n", "\\r", '\Z', "\'", '\"', '\0' ),
101
  $data
109
  * @return string
110
  */
111
  public static function unescape_mysql( $data ) {
112
+ return str_replace(
113
  array( '\\\\', '\\0', "\\n", "\\r", '\Z', "\'", '\"', '\0' ),
114
  array( '\\', '\0', "\n", "\r", "\x1a", "'", '"', "\0" ),
115
  $data
lib/vendor/servmask/database/class-ai1wm-database.php CHANGED
@@ -105,12 +105,12 @@ abstract class Ai1wm_Database {
105
  protected $exclude_table_prefixes = array();
106
 
107
  /**
108
- * Number of serialized replaces
109
  *
110
  * @access protected
111
- * @var int
112
  */
113
- protected $number_of_replaces = 0;
114
 
115
  /**
116
  * Visual Composer
@@ -228,6 +228,48 @@ abstract class Ai1wm_Database {
228
  return $this->new_replace_values;
229
  }
230
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  /**
232
  * Set table query clauses
233
  *
@@ -322,6 +364,27 @@ abstract class Ai1wm_Database {
322
  return $this->exclude_table_prefixes;
323
  }
324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
325
  /**
326
  * Set Visual Composer
327
  *
@@ -405,17 +468,17 @@ abstract class Ai1wm_Database {
405
  /**
406
  * Export database into a file
407
  *
408
- * @param string $file_name Name of file
409
- * @param string $current_table_index Current table index
410
- * @param int $timeout Process timeout
411
  * @return bool
412
  */
413
- public function export( $file_name, &$current_table_index = 0, $timeout = 0 ) {
414
  // Set file handler
415
  $file_handler = ai1wm_open( $file_name, 'ab' );
416
 
417
  // Write headers
418
- if ( $current_table_index === 0 ) {
419
  ai1wm_write( $file_handler, $this->get_header() );
420
  }
421
 
@@ -429,16 +492,16 @@ abstract class Ai1wm_Database {
429
  $tables = $this->get_tables();
430
 
431
  // Export tables
432
- for ( ; $current_table_index < count( $tables ); ) {
433
 
434
  // Get table name
435
- $table_name = $tables[ $current_table_index ];
436
 
437
  // Replace table name prefixes
438
  $new_table_name = $this->replace_table_prefixes( $table_name, 0 );
439
 
440
  // Get table structure
441
- $structure = $this->query( "SHOW CREATE TABLE `$table_name`" );
442
  $table = $this->fetch_assoc( $structure );
443
 
444
  // Close structure cursor
@@ -448,7 +511,7 @@ abstract class Ai1wm_Database {
448
  if ( isset( $table['Create Table'] ) ) {
449
 
450
  // Write table drop statement
451
- $drop_table = "\nDROP TABLE IF EXISTS `$new_table_name`;\n";
452
 
453
  // Write table statement
454
  ai1wm_write( $file_handler, $drop_table );
@@ -469,10 +532,10 @@ abstract class Ai1wm_Database {
469
  ai1wm_write( $file_handler, ";\n\n" );
470
  }
471
 
472
- $current_table_offset = 0;
473
 
474
  // Set query
475
- $query = sprintf( "SELECT * FROM `$table_name` %s", $this->get_table_query_clauses( $table_name ) );
476
 
477
  // Apply additional table prefix columns
478
  $columns = $this->get_table_prefix_columns( $table_name );
@@ -482,7 +545,7 @@ abstract class Ai1wm_Database {
482
 
483
  // Generate insert statements
484
  while ( $row = $this->fetch_assoc( $result ) ) {
485
- if ( $current_table_offset % Ai1wm_Database::QUERIES_PER_TRANSACTION === 0 ) {
486
  // Write start transaction
487
  ai1wm_write( $file_handler, "START TRANSACTION;\n" );
488
  }
@@ -495,32 +558,32 @@ abstract class Ai1wm_Database {
495
  }
496
 
497
  // Replace table values
498
- $items[] = is_null( $value ) ? 'NULL' : "'" . $this->replace_table_export_values( $this->escape( $value ) ) . "'";
499
  }
500
 
501
  // Set table values
502
  $table_values = implode( ',', $items );
503
 
504
  // Set insert statement
505
- $table_insert = "INSERT INTO `$new_table_name` VALUES ($table_values);\n";
506
 
507
  // Write insert statement
508
  ai1wm_write( $file_handler, $table_insert );
509
 
510
- $current_table_offset++;
511
 
512
  // Write end of transaction
513
- if ( $current_table_offset % Ai1wm_Database::QUERIES_PER_TRANSACTION === 0 ) {
514
  ai1wm_write( $file_handler, "COMMIT;\n" );
515
  }
516
  }
517
 
518
  // Write end of transaction
519
- if ( $current_table_offset % Ai1wm_Database::QUERIES_PER_TRANSACTION !== 0 ) {
520
  ai1wm_write( $file_handler, "COMMIT;\n" );
521
  }
522
 
523
- $current_table_index += 1;
524
 
525
  // Close result cursor
526
  $this->free_result( $result );
@@ -543,70 +606,85 @@ abstract class Ai1wm_Database {
543
  /**
544
  * Import database from a file
545
  *
546
- * @param string $file_name Name of file
 
 
547
  * @return bool
548
  */
549
- public function import( $file_name ) {
550
  // Set max allowed packet
551
  $max_allowed_packet = $this->get_max_allowed_packet();
552
 
553
  // Set file handler
554
  $file_handler = ai1wm_open( $file_name, 'r' );
555
 
556
- $passed = 0;
557
- $failed = 0;
558
- $query = null;
 
 
 
 
 
559
 
560
- // Read database file line by line
561
- while ( ( $line = fgets( $file_handler ) ) !== false ) {
562
- $query .= $line;
563
 
564
- // End of query
565
- if ( preg_match( '/;\s*$/', $query ) ) {
566
 
567
- // Check max allowed packet
568
- if ( strlen( $query ) <= $max_allowed_packet ) {
 
569
 
570
- // Replace table prefixes
571
- $query = $this->replace_table_prefixes( $query );
 
572
 
573
- // Replace table collations
574
- $query = $this->replace_table_collations( $query );
575
 
576
- // Replace table values
577
- $query = $this->replace_table_import_values( $query );
 
 
 
 
 
 
578
 
579
- try {
 
580
 
581
  // Run SQL query
582
- $result = $this->query( $query );
583
- if ( $result === false ) {
584
- throw new Exception( $this->error(), $this->errno() );
585
- } else {
586
- $passed++;
 
 
 
 
 
 
 
 
587
  }
588
-
589
- } catch ( Exception $e ) {
590
- $failed++;
591
  }
592
 
593
- } else {
594
- $failed++;
595
  }
596
-
597
- $query = null;
598
  }
 
 
 
599
  }
600
 
601
  // Close file handler
602
  ai1wm_close( $file_handler );
603
 
604
- // Check failed queries
605
- if ( ( ( $failed / $passed ) * 100 ) > 2 ) {
606
- return false;
607
- }
608
-
609
- return true;
610
  }
611
 
612
  /**
@@ -616,7 +694,7 @@ abstract class Ai1wm_Database {
616
  */
617
  public function flush() {
618
  foreach ( $this->get_tables() as $table_name ) {
619
- $this->query( "DROP TABLE IF EXISTS `$table_name`" );
620
  }
621
  }
622
 
@@ -673,7 +751,7 @@ abstract class Ai1wm_Database {
673
  protected function get_collation( $collation_name ) {
674
  $collation_result = null;
675
 
676
- $result = $this->query( "SHOW COLLATION LIKE '$collation_name'" );
677
  while ( $row = $this->fetch_row( $result ) ) {
678
  if ( isset( $row[0] ) ) {
679
  $collation_result = $row[0];
@@ -702,9 +780,9 @@ abstract class Ai1wm_Database {
702
  // Replace first occurance at a specified position
703
  if ( $position !== false ) {
704
  for ( $i = 0; $i < count( $search ); $i++ ) {
705
- $current = stripos( $input, $search[$i] );
706
  if ( $current === $position ) {
707
- $input = substr_replace( $input, $replace[$i], $current, strlen( $search[$i] ) );
708
  }
709
  }
710
 
@@ -716,31 +794,22 @@ abstract class Ai1wm_Database {
716
  }
717
 
718
  /**
719
- * Replace table export values
720
  *
721
  * @param string $input Table value
722
  * @return string
723
  */
724
- protected function replace_table_export_values( $input ) {
725
- if ( $this->get_old_replace_values() ) {
726
- $this->number_of_replaces = 0;
727
-
728
- // Serialization format
729
- $array = '(a:\d+:{.+?})';
730
- $string = '(s:\d+:\\\\?"(.+?)\\\\?";)';
731
- $object = '(O:\d+:\\\\?"(.+?)\\\\?":\d+:{.*?})';
732
-
733
- // Replace base64 encoded values (Visual Composer)
734
- if ( $this->get_visual_composer() ) {
735
- $input = preg_replace_callback( "/(?<=\[vc_raw_html\])(.+?)(?=\[\/vc_raw_html\])/S", array( $this, 'replace_base64_values_callback' ), $input );
736
- }
737
-
738
- // Replace serialized values
739
- $input = preg_replace_callback( "/(?<=\A)($array|$string|$object)(?=\z)/S", array( $this, 'replace_serialized_values_callback' ), $input );
740
 
741
- // Replace values
742
- if ( $this->number_of_replaces === 0 ) {
743
- $input = Ai1wm_Database_Utility::replace_values( $this->get_old_replace_values(), $this->get_new_replace_values(), $input );
 
 
744
  }
745
  }
746
 
@@ -748,35 +817,20 @@ abstract class Ai1wm_Database {
748
  }
749
 
750
  /**
751
- * Replace table import values
752
  *
753
- * @param string $input Table value
754
  * @return string
755
  */
756
- protected function replace_table_import_values( $input ) {
757
- if ( $this->get_old_replace_values() ) {
758
- $this->number_of_replaces = 0;
759
-
760
- // Serialization format
761
- $array = '(a:\d+:{.+?})';
762
- $string = '(s:\d+:\\\\?"(.+?)\\\\?";)';
763
- $object = '(O:\d+:\\\\?"(.+?)\\\\?":\d+:{.*?})';
764
-
765
- // Replace base64 encoded values (Visual Composer)
766
- if ( $this->get_visual_composer() ) {
767
- $input = preg_replace_callback( "/(?<=\[vc_raw_html\])(.+?)(?=\[\/vc_raw_html\])/S", array( $this, 'replace_base64_values_callback' ), $input );
768
- }
769
-
770
- // Replace serialized values
771
- $input = preg_replace_callback( "/(?<=')($array|$string|$object)(?=')/S", array( $this, 'replace_serialized_values_callback' ), $input );
772
 
773
- // Replace values
774
- if ( $this->number_of_replaces === 0 ) {
775
- $input = Ai1wm_Database_Utility::replace_values( $this->get_old_replace_values(), $this->get_new_replace_values(), $input );
776
- }
777
- }
778
 
779
- return $input;
 
780
  }
781
 
782
  /**
@@ -786,8 +840,6 @@ abstract class Ai1wm_Database {
786
  * @return string
787
  */
788
  protected function replace_base64_values_callback( $matches ) {
789
- $this->number_of_replaces++;
790
-
791
  // Decode base64 characters
792
  $input = rawurldecode( base64_decode( strip_tags( $matches[1] ) ) );
793
 
@@ -795,30 +847,7 @@ abstract class Ai1wm_Database {
795
  $input = Ai1wm_Database_Utility::replace_values( $this->get_old_replace_values(), $this->get_new_replace_values(), $input );
796
 
797
  // Encode base64 characters
798
- $input = base64_encode( rawurlencode( $input ) );
799
-
800
- return $input;
801
- }
802
-
803
- /**
804
- * Replace serialized values (callback)
805
- *
806
- * @param array $matches List of matches
807
- * @return string
808
- */
809
- protected function replace_serialized_values_callback( $matches ) {
810
- $this->number_of_replaces++;
811
-
812
- // Unescape MySQL special characters
813
- $input = Ai1wm_Database_Utility::unescape_mysql( $matches[1] );
814
-
815
- // Replace serialized values
816
- $input = Ai1wm_Database_Utility::replace_serialized_values( $this->get_old_replace_values(), $this->get_new_replace_values(), $input );
817
-
818
- // Escape MySQL special characters
819
- $input = Ai1wm_Database_Utility::escape_mysql( $input );
820
-
821
- return $input;
822
  }
823
 
824
  /**
@@ -844,7 +873,17 @@ abstract class Ai1wm_Database {
844
  }
845
  }
846
 
847
- return str_ireplace( $search, $replace, $input );
 
 
 
 
 
 
 
 
 
 
848
  }
849
 
850
  /**
@@ -862,6 +901,88 @@ abstract class Ai1wm_Database {
862
  return preg_replace( $pattern, '', $input );
863
  }
864
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
865
  /**
866
  * Replace table options
867
  *
@@ -871,6 +992,8 @@ abstract class Ai1wm_Database {
871
  protected function replace_table_options( $input ) {
872
  // Set table replace options
873
  $search = array(
 
 
874
  'ENGINE=Aria',
875
  'TRANSACTIONAL=0',
876
  'TRANSACTIONAL=1',
@@ -884,6 +1007,8 @@ abstract class Ai1wm_Database {
884
 
885
  );
886
  $replace = array(
 
 
887
  'ENGINE=MyISAM',
888
  '',
889
  '',
105
  protected $exclude_table_prefixes = array();
106
 
107
  /**
108
+ * List all tables that should not be affected by the timeout of the current request
109
  *
110
  * @access protected
111
+ * @var array
112
  */
113
+ protected $atomic_tables = array();
114
 
115
  /**
116
  * Visual Composer
228
  return $this->new_replace_values;
229
  }
230
 
231
+ /**
232
+ * Set old replace raw values
233
+ *
234
+ * @param array $values List of values
235
+ * @return Ai1wm_Database
236
+ */
237
+ public function set_old_replace_raw_values( $values ) {
238
+ $this->old_replace_raw_values = $values;
239
+
240
+ return $this;
241
+ }
242
+
243
+ /**
244
+ * Get old replace raw values
245
+ *
246
+ * @return array
247
+ */
248
+ public function get_old_replace_raw_values() {
249
+ return $this->old_replace_raw_values;
250
+ }
251
+
252
+ /**
253
+ * Set new replace raw values
254
+ *
255
+ * @param array $values List of values
256
+ * @return Ai1wm_Database
257
+ */
258
+ public function set_new_replace_raw_values( $values ) {
259
+ $this->new_replace_raw_values = $values;
260
+
261
+ return $this;
262
+ }
263
+
264
+ /**
265
+ * Get new replace raw values
266
+ *
267
+ * @return array
268
+ */
269
+ public function get_new_replace_raw_values() {
270
+ return $this->new_replace_raw_values;
271
+ }
272
+
273
  /**
274
  * Set table query clauses
275
  *
364
  return $this->exclude_table_prefixes;
365
  }
366
 
367
+ /**
368
+ * Set atomic tables
369
+ *
370
+ * @param array $tables List of tables
371
+ * @return Ai1wm_Database
372
+ */
373
+ public function set_atomic_tables( $tables ) {
374
+ $this->atomic_tables = $tables;
375
+
376
+ return $this;
377
+ }
378
+
379
+ /**
380
+ * Get atomic tables
381
+ *
382
+ * @return array
383
+ */
384
+ public function get_atomic_tables() {
385
+ return $this->atomic_tables;
386
+ }
387
+
388
  /**
389
  * Set Visual Composer
390
  *
468
  /**
469
  * Export database into a file
470
  *
471
+ * @param string $file_name Name of file
472
+ * @param string $table_offset Table offset
473
+ * @param int $timeout Process timeout
474
  * @return bool
475
  */
476
+ public function export( $file_name, &$table_offset = 0, $timeout = 0 ) {
477
  // Set file handler
478
  $file_handler = ai1wm_open( $file_name, 'ab' );
479
 
480
  // Write headers
481
+ if ( $table_offset === 0 ) {
482
  ai1wm_write( $file_handler, $this->get_header() );
483
  }
484
 
492
  $tables = $this->get_tables();
493
 
494
  // Export tables
495
+ for ( ; $table_offset < count( $tables ); ) {
496
 
497
  // Get table name
498
+ $table_name = $tables[ $table_offset ];
499
 
500
  // Replace table name prefixes
501
  $new_table_name = $this->replace_table_prefixes( $table_name, 0 );
502
 
503
  // Get table structure
504
+ $structure = $this->query( "SHOW CREATE TABLE `{$table_name}`" );
505
  $table = $this->fetch_assoc( $structure );
506
 
507
  // Close structure cursor
511
  if ( isset( $table['Create Table'] ) ) {
512
 
513
  // Write table drop statement
514
+ $drop_table = "\nDROP TABLE IF EXISTS `{$new_table_name}`;\n";
515
 
516
  // Write table statement
517
  ai1wm_write( $file_handler, $drop_table );
532
  ai1wm_write( $file_handler, ";\n\n" );
533
  }
534
 
535
+ $count = 0;
536
 
537
  // Set query
538
+ $query = sprintf( 'SELECT * FROM `%s` %s', $table_name, $this->get_table_query_clauses( $table_name ) );
539
 
540
  // Apply additional table prefix columns
541
  $columns = $this->get_table_prefix_columns( $table_name );
545
 
546
  // Generate insert statements
547
  while ( $row = $this->fetch_assoc( $result ) ) {
548
+ if ( $count % Ai1wm_Database::QUERIES_PER_TRANSACTION === 0 ) {
549
  // Write start transaction
550
  ai1wm_write( $file_handler, "START TRANSACTION;\n" );
551
  }
558
  }
559
 
560
  // Replace table values
561
+ $items[] = is_null( $value ) ? 'NULL' : "'" . $this->escape( $value ) . "'";
562
  }
563
 
564
  // Set table values
565
  $table_values = implode( ',', $items );
566
 
567
  // Set insert statement
568
+ $table_insert = "INSERT INTO `{$new_table_name}` VALUES ({$table_values});\n";
569
 
570
  // Write insert statement
571
  ai1wm_write( $file_handler, $table_insert );
572
 
573
+ $count++;
574
 
575
  // Write end of transaction
576
+ if ( $count % Ai1wm_Database::QUERIES_PER_TRANSACTION === 0 ) {
577
  ai1wm_write( $file_handler, "COMMIT;\n" );
578
  }
579
  }
580
 
581
  // Write end of transaction
582
+ if ( $count % Ai1wm_Database::QUERIES_PER_TRANSACTION !== 0 ) {
583
  ai1wm_write( $file_handler, "COMMIT;\n" );
584
  }
585
 
586
+ $table_offset++;
587
 
588
  // Close result cursor
589
  $this->free_result( $result );
606
  /**
607
  * Import database from a file
608
  *
609
+ * @param string $file_name Name of file
610
+ * @param int $query_offset Query offset
611
+ * @param int $timeout Process timeout
612
  * @return bool
613
  */
614
+ public function import( $file_name, &$query_offset = 0, $timeout = 0 ) {
615
  // Set max allowed packet
616
  $max_allowed_packet = $this->get_max_allowed_packet();
617
 
618
  // Set file handler
619
  $file_handler = ai1wm_open( $file_name, 'r' );
620
 
621
+ // Start time
622
+ $start = microtime( true );
623
+
624
+ // Flag to hold if all tables have been processed
625
+ $completed = true;
626
+
627
+ // Set empty query
628
+ $query = null;
629
 
630
+ // Set file pointer at the query offset
631
+ if ( fseek( $file_handler, $query_offset ) !== -1 ) {
 
632
 
633
+ // Start transaction
634
+ $this->query( 'START TRANSACTION' );
635
 
636
+ // Read database file line by line
637
+ while ( ( $line = fgets( $file_handler ) ) !== false ) {
638
+ $query .= $line;
639
 
640
+ // End of query
641
+ if ( preg_match( '/;\s*$/S', $query ) ) {
642
+ $query = trim( $query );
643
 
644
+ // Check max allowed packet
645
+ if ( strlen( $query ) <= $max_allowed_packet ) {
646
 
647
+ // Replace table prefixes
648
+ $query = $this->replace_table_prefixes( $query );
649
+
650
+ // Replace table collations
651
+ $query = $this->replace_table_collations( $query );
652
+
653
+ // Replace table values
654
+ $query = $this->replace_table_values( $query );
655
 
656
+ // Replace raw values
657
+ $query = $this->replace_raw_values( $query );
658
 
659
  // Run SQL query
660
+ $this->query( $query );
661
+
662
+ // Set query offset
663
+ $query_offset = ftell( $file_handler );
664
+
665
+ // Time elapsed
666
+ if ( $timeout ) {
667
+ if ( ! $this->is_atomic_query( $query ) ) {
668
+ if ( ( microtime( true ) - $start ) > $timeout ) {
669
+ $completed = false;
670
+ break;
671
+ }
672
+ }
673
  }
 
 
 
674
  }
675
 
676
+ $query = null;
 
677
  }
 
 
678
  }
679
+
680
+ // End transaction
681
+ $this->query( 'COMMIT' );
682
  }
683
 
684
  // Close file handler
685
  ai1wm_close( $file_handler );
686
 
687
+ return $completed;
 
 
 
 
 
688
  }
689
 
690
  /**
694
  */
695
  public function flush() {
696
  foreach ( $this->get_tables() as $table_name ) {
697
+ $this->query( "DROP TABLE IF EXISTS `{$table_name}`" );
698
  }
699
  }
700
 
751
  protected function get_collation( $collation_name ) {
752
  $collation_result = null;
753
 
754
+ $result = $this->query( "SHOW COLLATION LIKE '{$collation_name}'" );
755
  while ( $row = $this->fetch_row( $result ) ) {
756
  if ( isset( $row[0] ) ) {
757
  $collation_result = $row[0];
780
  // Replace first occurance at a specified position
781
  if ( $position !== false ) {
782
  for ( $i = 0; $i < count( $search ); $i++ ) {
783
+ $current = stripos( $input, $search[ $i ] );
784
  if ( $current === $position ) {
785
+ $input = substr_replace( $input, $replace[ $i ], $current, strlen( $search[ $i ] ) );
786
  }
787
  }
788
 
794
  }
795
 
796
  /**
797
+ * Replace table values
798
  *
799
  * @param string $input Table value
800
  * @return string
801
  */
802
+ protected function replace_table_values( $input ) {
803
+ // Replace base64 encoded values (Visual Composer)
804
+ if ( $this->get_visual_composer() ) {
805
+ $input = preg_replace_callback( '/\[vc_raw_html\](.+?)\[\/vc_raw_html\]/S', array( $this, 'replace_base64_values_callback' ), $input );
806
+ }
 
 
 
 
 
 
 
 
 
 
 
807
 
808
+ // Replace serialized values
809
+ foreach ( $this->get_old_replace_values() as $old_value ) {
810
+ if ( strpos( $input, $old_value ) !== false ) {
811
+ $input = preg_replace_callback( "/'(.*?)(?<!\\\\)'/S", array( $this, 'replace_table_values_callback' ), $input );
812
+ break;
813
  }
814
  }
815
 
817
  }
818
 
819
  /**
820
+ * Replace table values (callback)
821
  *
822
+ * @param array $matches List of matches
823
  * @return string
824
  */
825
+ protected function replace_table_values_callback( $matches ) {
826
+ // Unescape MySQL special characters
827
+ $input = Ai1wm_Database_Utility::unescape_mysql( $matches[1] );
 
 
 
 
 
 
 
 
 
 
 
 
 
828
 
829
+ // Replace serialized values
830
+ $input = Ai1wm_Database_Utility::replace_serialized_values( $this->get_old_replace_values(), $this->get_new_replace_values(), $input );
 
 
 
831
 
832
+ // Escape MySQL special characters
833
+ return "'" . Ai1wm_Database_Utility::escape_mysql( $input ) . "'";
834
  }
835
 
836
  /**
840
  * @return string
841
  */
842
  protected function replace_base64_values_callback( $matches ) {
 
 
843
  // Decode base64 characters
844
  $input = rawurldecode( base64_decode( strip_tags( $matches[1] ) ) );
845
 
847
  $input = Ai1wm_Database_Utility::replace_values( $this->get_old_replace_values(), $this->get_new_replace_values(), $input );
848
 
849
  // Encode base64 characters
850
+ return '[vc_raw_html]' . base64_encode( rawurlencode( $input ) ) . '[/vc_raw_html]';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
851
  }
852
 
853
  /**
873
  }
874
  }
875
 
876
+ return str_replace( $search, $replace, $input );
877
+ }
878
+
879
+ /**
880
+ * Replace raw values
881
+ *
882
+ * @param string $input SQL statement
883
+ * @return string
884
+ */
885
+ protected function replace_raw_values( $input ) {
886
+ return Ai1wm_Database_Utility::replace_values( $this->get_old_replace_raw_values(), $this->get_new_replace_raw_values(), $input );
887
  }
888
 
889
  /**
901
  return preg_replace( $pattern, '', $input );
902
  }
903
 
904
+ /**
905
+ * Check whether input is START TRANSACTION query
906
+ *
907
+ * @param string $input SQL statement
908
+ * @return bool
909
+ */
910
+ protected function is_start_transaction_query( $input ) {
911
+ return strpos( $input, 'START TRANSACTION' ) === 0;
912
+ }
913
+
914
+ /**
915
+ * Check whether input is COMMIT query
916
+ *
917
+ * @param string $input SQL statement
918
+ * @return bool
919
+ */
920
+ protected function is_commit_query( $input ) {
921
+ return strpos( $input, 'COMMIT' ) === 0;
922
+ }
923
+
924
+ /**
925
+ * Check whether input is DROP TABLE query
926
+ *
927
+ * @param string $input SQL statement
928
+ * @return bool
929
+ */
930
+ protected function is_drop_table_query( $input ) {
931
+ return strpos( $input, 'DROP TABLE' ) === 0;
932
+ }
933
+
934
+ /**
935
+ * Check whether input is CREATE TABLE query
936
+ *
937
+ * @param string $input SQL statement
938
+ * @return bool
939
+ */
940
+ protected function is_create_table_query( $input ) {
941
+ return strpos( $input, 'CREATE TABLE' ) === 0;
942
+ }
943
+
944
+ /**
945
+ * Check whether input is INSERT INTO query
946
+ *
947
+ * @param string $input SQL statement
948
+ * @param string $table Table name (case insensitive)
949
+ * @return bool
950
+ */
951
+ protected function is_insert_into_query( $input, $table ) {
952
+ return stripos( $input, sprintf( 'INSERT INTO `%s`', $table ) ) === 0;
953
+ }
954
+
955
+ /**
956
+ * Check whether input is atomic query
957
+ *
958
+ * @param string $input SQL statement
959
+ * @return bool
960
+ */
961
+ protected function is_atomic_query( $input ) {
962
+ $atomic = false;
963
+
964
+ // Skip timeout based on table query
965
+ switch ( true ) {
966
+ case $this->is_drop_table_query( $input ):
967
+ case $this->is_create_table_query( $input ):
968
+ case $this->is_start_transaction_query( $input ):
969
+ case $this->is_commit_query( $input ):
970
+ $atomic = true;
971
+ break;
972
+
973
+ default:
974
+ // Skip timeout based on table query and table name
975
+ foreach ( $this->get_atomic_tables() as $table_name ) {
976
+ if ( $this->is_insert_into_query( $input, $table_name ) ) {
977
+ $atomic = true;
978
+ break;
979
+ }
980
+ }
981
+ }
982
+
983
+ return $atomic;
984
+ }
985
+
986
  /**
987
  * Replace table options
988
  *
992
  protected function replace_table_options( $input ) {
993
  // Set table replace options
994
  $search = array(
995
+ 'TYPE=InnoDB',
996
+ 'TYPE=MyISAM',
997
  'ENGINE=Aria',
998
  'TRANSACTIONAL=0',
999
  'TRANSACTIONAL=1',
1007
 
1008
  );
1009
  $replace = array(
1010
+ 'ENGINE=InnoDB',
1011
+ 'ENGINE=MyISAM',
1012
  'ENGINE=MyISAM',
1013
  '',
1014
  '',
lib/view/assets/javascript/backups.min.js CHANGED
@@ -99,8 +99,7 @@
99
  return Util.json(data);
100
  },
101
  success: function success(data) {
102
- var errors = data.errors;
103
- if (errors.length === 0) {
104
  self.closest('tr').remove();
105
  if ($('.ai1wm-backups tbody tr').length === 0) {
106
  $('.ai1wm-backups').addClass('ai1wm-hide');
@@ -193,13 +192,12 @@
193
  return Util.json(data);
194
  },
195
  success: function success(data) {
196
- var errors = data.errors;
197
- if (errors.length > 0) {
198
  // Reset previous messages
199
  $('.ai1wm-report-problem-dialog .ai1wm-message').remove();
200
 
201
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
202
- $.each(errors, function (key, value) {
203
  errorMessage.append('<p>' + value + '</p>');
204
  });
205
 
@@ -287,10 +285,14 @@
287
  return input;
288
  },
289
  json: function json(input) {
290
- var result = input.match(/{[\s\S]+}/);
291
- if (result !== null) {
292
- return result[0];
 
 
293
  }
 
 
294
  }
295
  };
296
 
@@ -393,13 +395,12 @@
393
  return Util.json(data);
394
  },
395
  success: function success(data) {
396
- var errors = data.errors;
397
- if (errors.length > 0) {
398
  // Reset previous messages
399
  $('.ai1wm-feedback .ai1wm-message').remove();
400
 
401
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
402
- $.each(errors, function (key, value) {
403
  errorMessage.append('<p>' + value + '</p>');
404
  });
405
 
99
  return Util.json(data);
100
  },
101
  success: function success(data) {
102
+ if (data.errors.length === 0) {
 
103
  self.closest('tr').remove();
104
  if ($('.ai1wm-backups tbody tr').length === 0) {
105
  $('.ai1wm-backups').addClass('ai1wm-hide');
192
  return Util.json(data);
193
  },
194
  success: function success(data) {
195
+ if (data.errors.length > 0) {
 
196
  // Reset previous messages
197
  $('.ai1wm-report-problem-dialog .ai1wm-message').remove();
198
 
199
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
200
+ $.each(data.errors, function (key, value) {
201
  errorMessage.append('<p>' + value + '</p>');
202
  });
203
 
285
  return input;
286
  },
287
  json: function json(input) {
288
+ if ($.type(input) === 'string') {
289
+ var result = input.match(/{[\s\S]+}/);
290
+ if (result !== null) {
291
+ return result[0];
292
+ }
293
  }
294
+
295
+ return false;
296
  }
297
  };
298
 
395
  return Util.json(data);
396
  },
397
  success: function success(data) {
398
+ if (data.errors.length > 0) {
 
399
  // Reset previous messages
400
  $('.ai1wm-feedback .ai1wm-message').remove();
401
 
402
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
403
+ $.each(data.errors, function (key, value) {
404
  errorMessage.append('<p>' + value + '</p>');
405
  });
406
 
lib/view/assets/javascript/export.min.js CHANGED
@@ -175,13 +175,12 @@
175
  return Util.json(data);
176
  },
177
  success: function success(data) {
178
- var errors = data.errors;
179
- if (errors.length > 0) {
180
  // Reset previous messages
181
  $('.ai1wm-report-problem-dialog .ai1wm-message').remove();
182
 
183
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
184
- $.each(errors, function (key, value) {
185
  errorMessage.append('<p>' + value + '</p>');
186
  });
187
 
@@ -269,10 +268,14 @@
269
  return input;
270
  },
271
  json: function json(input) {
272
- var result = input.match(/{[\s\S]+}/);
273
- if (result !== null) {
274
- return result[0];
 
 
275
  }
 
 
276
  }
277
  };
278
 
@@ -375,13 +378,12 @@
375
  return Util.json(data);
376
  },
377
  success: function success(data) {
378
- var errors = data.errors;
379
- if (errors.length > 0) {
380
  // Reset previous messages
381
  $('.ai1wm-feedback .ai1wm-message').remove();
382
 
383
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
384
- $.each(errors, function (key, value) {
385
  errorMessage.append('<p>' + value + '</p>');
386
  });
387
 
175
  return Util.json(data);
176
  },
177
  success: function success(data) {
178
+ if (data.errors.length > 0) {
 
179
  // Reset previous messages
180
  $('.ai1wm-report-problem-dialog .ai1wm-message').remove();
181
 
182
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
183
+ $.each(data.errors, function (key, value) {
184
  errorMessage.append('<p>' + value + '</p>');
185
  });
186
 
268
  return input;
269
  },
270
  json: function json(input) {
271
+ if ($.type(input) === 'string') {
272
+ var result = input.match(/{[\s\S]+}/);
273
+ if (result !== null) {
274
+ return result[0];
275
+ }
276
  }
277
+
278
+ return false;
279
  }
280
  };
281
 
378
  return Util.json(data);
379
  },
380
  success: function success(data) {
381
+ if (data.errors.length > 0) {
 
382
  // Reset previous messages
383
  $('.ai1wm-feedback .ai1wm-message').remove();
384
 
385
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
386
+ $.each(data.errors, function (key, value) {
387
  errorMessage.append('<p>' + value + '</p>');
388
  });
389
 
lib/view/assets/javascript/import.min.js CHANGED
@@ -149,13 +149,12 @@
149
  return Util.json(data);
150
  },
151
  success: function success(data) {
152
- var errors = data.errors;
153
- if (errors.length > 0) {
154
  // Reset previous messages
155
  $('.ai1wm-report-problem-dialog .ai1wm-message').remove();
156
 
157
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
158
- $.each(errors, function (key, value) {
159
  errorMessage.append('<p>' + value + '</p>');
160
  });
161
 
@@ -243,10 +242,14 @@
243
  return input;
244
  },
245
  json: function json(input) {
246
- var result = input.match(/{[\s\S]+}/);
247
- if (result !== null) {
248
- return result[0];
 
 
249
  }
 
 
250
  }
251
  };
252
 
@@ -349,13 +352,12 @@
349
  return Util.json(data);
350
  },
351
  success: function success(data) {
352
- var errors = data.errors;
353
- if (errors.length > 0) {
354
  // Reset previous messages
355
  $('.ai1wm-feedback .ai1wm-message').remove();
356
 
357
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
358
- $.each(errors, function (key, value) {
359
  errorMessage.append('<p>' + value + '</p>');
360
  });
361
 
@@ -1377,11 +1379,21 @@
1377
  ai1wm_uploader.chunk_size = chunkSize / 2;
1378
  return _this2.upload(file);
1379
  case 200:
1380
- file = file.slice(chunkSize, file.size, 'application/octet-binary');
1381
- var uploadedBytes = _this2.fileSize - file.size;
1382
- var progress = uploadedBytes / _this2.fileSize * 100;
1383
- _this2.onUploadProgress(progress.toFixed(2));
1384
- return progress === 100 ? _this2.onFileUploaded() : _this2.upload(file);
 
 
 
 
 
 
 
 
 
 
1385
  default:
1386
  throw new Error(response.status);
1387
  }
149
  return Util.json(data);
150
  },
151
  success: function success(data) {
152
+ if (data.errors.length > 0) {
 
153
  // Reset previous messages
154
  $('.ai1wm-report-problem-dialog .ai1wm-message').remove();
155
 
156
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
157
+ $.each(data.errors, function (key, value) {
158
  errorMessage.append('<p>' + value + '</p>');
159
  });
160
 
242
  return input;
243
  },
244
  json: function json(input) {
245
+ if ($.type(input) === 'string') {
246
+ var result = input.match(/{[\s\S]+}/);
247
+ if (result !== null) {
248
+ return result[0];
249
+ }
250
  }
251
+
252
+ return false;
253
  }
254
  };
255
 
352
  return Util.json(data);
353
  },
354
  success: function success(data) {
355
+ if (data.errors.length > 0) {
 
356
  // Reset previous messages
357
  $('.ai1wm-feedback .ai1wm-message').remove();
358
 
359
  var errorMessage = $('<div />').addClass('ai1wm-message ai1wm-error-message');
360
+ $.each(data.errors, function (key, value) {
361
  errorMessage.append('<p>' + value + '</p>');
362
  });
363
 
1379
  ai1wm_uploader.chunk_size = chunkSize / 2;
1380
  return _this2.upload(file);
1381
  case 200:
1382
+ return response.text().then(function (text) {
1383
+ var extractedJsonText = Util.json(text);
1384
+ if (extractedJsonText) {
1385
+ var json = JSON.parse(extractedJsonText);
1386
+ if (json.errors.length === 0) {
1387
+ file = file.slice(chunkSize, file.size, 'application/octet-binary');
1388
+ var uploadedBytes = _this2.fileSize - file.size;
1389
+ var progress = uploadedBytes / _this2.fileSize * 100;
1390
+ _this2.onUploadProgress(progress.toFixed(2));
1391
+ return progress === 100 ? _this2.onFileUploaded() : _this2.upload(file);
1392
+ }
1393
+ }
1394
+
1395
+ throw new Error(text);
1396
+ });
1397
  default:
1398
  throw new Error(response.status);
1399
  }
lib/view/export/find-replace.php CHANGED
@@ -3,9 +3,9 @@
3
  <p>
4
  <span>
5
  <strong><?php _e( 'Find', AI1WM_PLUGIN_NAME ); ?></strong>
6
- <small class="ai1wm-query-find-text ai1wm-tooltip" title="Search the database for this text"><?php echo esc_attr( __( '<text>', AI1WM_PLUGIN_NAME ) ); ?></small>
7
  <strong><?php _e( 'Replace with', AI1WM_PLUGIN_NAME ); ?></strong>
8
- <small class="ai1wm-query-replace-text ai1wm-tooltip" title="Replace the database with this text"><?php echo esc_attr( __( '<another-text>', AI1WM_PLUGIN_NAME ) ); ?></small>
9
  <strong><?php _e( 'in the database', AI1WM_PLUGIN_NAME ); ?></strong>
10
  </span>
11
  <span class="ai1wm-query-arrow ai1wm-icon-chevron-right"></span>
3
  <p>
4
  <span>
5
  <strong><?php _e( 'Find', AI1WM_PLUGIN_NAME ); ?></strong>
6
+ <small class="ai1wm-query-find-text ai1wm-tooltip" title="Search the database for this text"><?php echo esc_html( __( '<text>', AI1WM_PLUGIN_NAME ) ); ?></small>
7
  <strong><?php _e( 'Replace with', AI1WM_PLUGIN_NAME ); ?></strong>
8
+ <small class="ai1wm-query-replace-text ai1wm-tooltip" title="Replace the database with this text"><?php echo esc_html( __( '<another-text>', AI1WM_PLUGIN_NAME ) ); ?></small>
9
  <strong><?php _e( 'in the database', AI1WM_PLUGIN_NAME ); ?></strong>
10
  </span>
11
  <span class="ai1wm-query-arrow ai1wm-icon-chevron-right"></span>
loader.php CHANGED
@@ -270,7 +270,7 @@ require_once AI1WM_IMPORT_PATH .
270
 
271
  require_once AI1WM_IMPORT_PATH .
272
  DIRECTORY_SEPARATOR .
273
- 'class-ai1wm-import-plugins.php';
274
 
275
  require_once AI1WM_IMPORT_PATH .
276
  DIRECTORY_SEPARATOR .
270
 
271
  require_once AI1WM_IMPORT_PATH .
272
  DIRECTORY_SEPARATOR .
273
+ 'class-ai1wm-import-mu-plugins.php';
274
 
275
  require_once AI1WM_IMPORT_PATH .
276
  DIRECTORY_SEPARATOR .
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: yani.iliev, bangelov, pimjitsawang
3
  Tags: move, transfer, copy, migrate, backup, clone, restore, db migration, migration, wordpress migration, website migration, database export, database import
4
  Requires at least: 3.3
5
  Tested up to: 4.7
6
- Stable tag: 6.43
7
  License: GPLv2 or later
8
 
9
  Move, transfer, copy, migrate, and backup a site with 1-click. Quick, easy, and reliable.
@@ -78,363 +78,80 @@ All in One WP Plugin is the first plugin to offer true mobile experience on Word
78
  3. Plugin Menu
79
 
80
  == Changelog ==
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  = 6.43 =
82
- * Update plugin tags and description
 
83
 
84
  = 6.42 =
85
- * Improve the performance when exporting database
 
86
 
87
  = 6.41 =
 
88
  * Support Visual Composer plugin
89
  * Support Jetpack Photon module
 
 
90
  * Improved Maria DB support
91
  * Disable WordPress authentication checking during migration
92
  * Clean any temporary files after migration
93
 
94
  = 6.40 =
 
 
 
 
95
  * Do not extract dropins files on import
96
- * Fix an issue with large files on import
97
- * Fix an issue with inactive plugins option in advanced settings on export
98
  * Do not exclude active plugins in package.json and multisite.json on export
99
  * Do not show "Resolving URL address..." on export/import
100
- * Add separate action hook in advanced settings called "ai1wm_export_advanced_settings" to allow custom checkbox options on export
 
 
 
101
 
102
  = 6.39 =
103
- * Add support for MariaDB
 
 
 
104
  * Do not include package.json, multisite.json, blogs.json, database.sql and filemap.list files on export
105
- * Fix an issue with unpacking archive on import
106
- * Fix an issue with inactivated plugins on import
107
  * Remove HTTP Basic authentication from Backups page
108
 
 
 
 
 
109
  = 6.38 =
110
- * Add support for HyperDB plugin
111
- * Add support for RevSlider plugin
 
112
  * Check available disk space during export/import
113
  * Support very restricted hosting environments
114
- * Add wpress mime-type to web.config when the server is IIS
 
 
115
  * Switch to AJAX from cURL on export/import
116
  * Respect WordPress constants FS_CHMOD_DIR and FS_CHMOD_FILE on import
117
- * Fix an issue related to generating archive and folder names
118
- * Fix an issue related to CSS styles on export page
119
  * Remove misleading available disk space information on "Backups" page
120
 
121
- = 5.56 =
122
- * Fix an issue with WP_Hook class introcuded in WP 4.7
123
-
124
- = 5.55 =
125
- * Fix an issue with resolving URL on export/import when using non-blocking streams client
126
-
127
- = 5.54 =
128
- * Fix an issue with resolving URL on export/import
129
-
130
- = 5.53 =
131
- * Send HTTP basic authorization header on upload (fetch method)
132
- * Add Accept-Encoding, Accept-Charset and Accept-Language on export/import
133
- * Do not replace already replaced values on database import/export
134
- * Set silent mode when activating sidewide plugins
135
- * Replace old media style URLs with the new media style URLs on database import
136
- * Replace user_level and capabilities user meta keys if tables have empty prefix on export
137
- * Create separate action for extracting must-use plugins
138
- * Add option "Do not export must-use plugins" in advanced settings
139
- * Fix an issue with SSL that produces "Unable to resolve URL..."
140
-
141
- = 5.52 =
142
- * Simplify the text on import page
143
- * Fix an issue with special characters on export and import
144
- * Fix an issue with export and import of large files
145
-
146
- = 5.51 =
147
- * Add support for utf8mb4_unicode_520_ci database collation
148
-
149
- = 5.50 =
150
- * Improve database export process
151
- * Simplify export and import cron
152
- * Fix an issue with export and import progress status
153
-
154
- = 5.49 =
155
- * Test plugin up to WordPress 4.6
156
-
157
- = 5.48 =
158
- * Improve support for large databases on export
159
- * Add support for Box cloud storage
160
- * Fix an issue with status on export/import
161
- * Fix an issue with asynchronous requests on export/import
162
-
163
- = 5.47 =
164
- * Fix an issue with incorrect file size on export
165
-
166
- = 5.46 =
167
- * Add "Restore from Backups" video in readme file
168
- * Display message if backups are inaccessible
169
-
170
- = 5.45 =
171
- * Fix an issue with blogs.dir path replacement
172
-
173
- = 5.44 =
174
- * Add "Do not replace email domain" option in advanced settings
175
- * Add "ai1wm_exclude_content_from_export" WordPress hook on export
176
- * Add HTML5 uploader
177
-
178
- = 5.43 =
179
- * Fix an issue when archiving dynamic files on export
180
- * Support custom upload path for multisites
181
- * Add support for various cache plugins
182
-
183
- = 5.42 =
184
- * Catch E_PARSE error on mu-plugins import
185
- * Fix an issue with stop export that doesn't clean up the storage directory
186
- * Initialize new cache instead of flushing the existing one on import/export
187
-
188
- = 5.41 =
189
- * Fix an issue when replacing serialized values on import
190
- * List files in chunks
191
- * Convert svg images to png
192
- * Check if backups are readable before displaying them on "Backups" page
193
- * Display version incompatibility notification on export/import/restore screen
194
- * Fix double port issue on Bitnami
195
- * Fix an issue on multisite export with cloud extensions
196
-
197
- = 5.40 =
198
- * Test plugin up to WordPress 4.5
199
-
200
- = 5.39 =
201
- * Fix a bug in uploads path replacement
202
-
203
- = 5.38 =
204
- * Deactivate mu-plugins if fatal error appears on import
205
-
206
- = 5.37 =
207
- * Validate the archive before import
208
-
209
- = 5.36 =
210
- * Add OneDrive to readme.txt
211
- * Fix a typo on import
212
-
213
- = 5.35 =
214
- * Add OneDrive to export/import pages
215
- * Fix a bug when WordPress was used without a db prefix
216
- * Fix a problem when downloading wpress files
217
- * Improve the log system
218
-
219
- = 4.19 =
220
- * Fixed an issue with options cache
221
-
222
- = 4.18 =
223
- * Fixed an issue with large media files
224
- * Fixed an issue with status file being cached
225
-
226
- = 4.17 =
227
- * Set "Tested up to" WordPress 4.4
228
-
229
- = 4.16 =
230
- * Fix an issue with the transport layer on export/import
231
-
232
- = 4.15 =
233
- * Fix an issue with resovling mechanism on export/import
234
-
235
- = 4.14 =
236
- * Fix an issue with database import
237
-
238
- = 4.13 =
239
- * Add new mechanism for resolving HTTP requests
240
-
241
- = 4.12 =
242
- * Fix an issue with Google Drive extension
243
-
244
- = 4.11 =
245
- * Fix content filters on export
246
-
247
- = 4.10 =
248
- * Add HTTPS URL replacement
249
- * Fix an issue when PDO is not available
250
-
251
- = 4.6 =
252
- * Fix an issue when the plugin was getting stuck on "Done creating an empty archive"
253
- * Fix an issue when the plugin was getting stuck during import
254
-
255
- = 4.3 =
256
- * Add URL extension support
257
- * Filter "mu-plugins" directory if "Do not export plugins (files)" is checked
258
- * Fix utf8mb4 issue
259
- * Fix translation issue
260
-
261
- = 4.2 =
262
- * Fix .wpress.bin format
263
-
264
- = 4.1 =
265
- * Add port to the host header on export/import
266
- * Rename .wpress file to .wpress.bin file
267
-
268
- = 4.0 =
269
- * Fix file permission checks
270
-
271
- = 3.9 =
272
- * Fix could not resolve domain name on export/import
273
-
274
- = 3.8 =
275
- * Fix undefined method on Backups page if PHP version is < 5.3.6
276
-
277
- = 3.7 =
278
- * Add IPv6 support on export/import
279
-
280
- = 3.6 =
281
- * Fixed undefined constant warnings
282
-
283
- = 3.5 =
284
- * Exclude core plugin and extensions on export if they have custom names
285
-
286
- = 3.4 =
287
- * Made export/import processes more reliable
288
- * Allow the plugin to work with non-default name
289
- * Preserve backups during plugin updates
290
- * Improved find & replace functionality on the serialized data
291
- * Removed backup file name restrictions
292
-
293
- = 3.3 =
294
- * Fixed a bug when retrieving export/import status progress
295
- * Fixed a bug when database encoding utf8mb4_unicode_ci is not available
296
-
297
- = 3.2.2 =
298
- * Fixed plugin incompatibility during export/import that was reporting that the process could not be started
299
-
300
- = 3.2.1 =
301
- * Added username/password settings for WordPress sites behind HTTP basic authentication
302
- * Fixed a bug when exporting/importing without public DNS record
303
- * Fixed a bug when exporting/importing media files
304
-
305
- = 3.2.0 =
306
- * Added advanced settings on export page
307
-
308
- = 3.1.1 =
309
- * Fixed secret key issue on upgrade of the plugin
310
-
311
- = 3.0.0 =
312
- * Added export to File, [Dropbox](https://servmask.com/products/dropbox-extension), [Amazon S3](https://servmask.com/products/amazon-s3-extension), [Google Drive](https://servmask.com/products/google-drive-extension)
313
- * Added import from File, [Dropbox](https://servmask.com/products/dropbox-extension), [Amazon S3](https://servmask.com/products/amazon-s3-extension), [Google Drive](https://servmask.com/products/google-drive-extension)
314
- * Implemented our own archiving format that reduces export and import by a factor of 10
315
- * One-click export with the new simplified export page
316
- * Improved upload functionality with auto-recognizing chunk size on import
317
- * New **Backups** page for storing all WordPress site exports
318
- * Easy restore WordPress site from **Backups** page
319
- * Monitoring availability of the disk space on the server
320
- * Both export and import happen in time chunks of 3 seconds
321
- * Plugin works behind HTTP basic authentication
322
-
323
- = 2.0.4 =
324
- * Updated readme to reflect that the plugin is not multisite compatible
325
-
326
- = 2.0.3 =
327
- * Fixed a security issue while importing site using regular users
328
-
329
- = 2.0.2 =
330
- * Added support for WordPress v4.0
331
-
332
- = 2.0.1 =
333
- * Fixed a bug when all user permissions are lost on import
334
-
335
- = 2.0.0 =
336
- * Added support for migration of WordPress in Network Mode (Multi Site)
337
- * New improved UI and UX
338
- * New improved language translations on the menu items and help texts
339
- * Better error handling and notifications
340
- * Fixed a bug while exporting comments and associated comments meta data
341
- * Fixed a bug while using find/replace functionality
342
- * Fixed a bug with storage directory permissions and search indexation
343
-
344
- = 1.9.2 =
345
- * Added PHP <= v5.2.7 compatibility
346
-
347
- = 1.9.1 =
348
- * Fixed an issue with earlier versions of PHP
349
-
350
- = 1.9.0 =
351
- * New improved design on the export/import page
352
- * Added an option for gathering user experience statistics
353
- * Added a message box with important notifications about the plugin
354
- * Fixed a bug while exporting database with multiple WordPress sites
355
- * Fixed a bug while exporting database with table constraints
356
- * Fixed a bug with auto recognizing zip archiver
357
-
358
- = 1.8.1 =
359
- * Added "Get Support" link in the plugin list page
360
- * Removed "All in One WP Migration Beta" link from the readme file
361
-
362
- = 1.8.0 =
363
- * Added support for dynamically recognizing Site URL and Home URL on the import page
364
- * Fixed a bug when maximum uploaded size is exceeded
365
- * Fixed a bug while exporting big database tables
366
-
367
- = 1.7.2 =
368
- * Added support for automatically switching database adapters for better performance and optimization
369
- * Fixed a bug while using host:port syntax with MySQL PDO
370
- * Fixed a bug while using find/replace functionality
371
-
372
- = 1.7.1 =
373
- * Fixed a bug while exporting WordPress plugins directory
374
-
375
- = 1.7.0 =
376
- * Added storage layer to avoid permission issues with OS's directory used for temporary storage
377
- * Added additional checks to verify the consistency of the imported archive
378
- * Fixed a bug that caused the database to be exported without data
379
- * Removed unused variables from package.json file
380
-
381
- = 1.6.0 =
382
- * Added additional check for directory's permissions
383
- * Added additional check for output buffering when exporting a file
384
- * Fixed a bug when the archive was exported or imported with old version of Zlib library
385
- * Fixed a bug with permalinks and flushing the rules
386
-
387
- = 1.5.0 =
388
- * Added support for additional errors and exceptions handling
389
- * Added support for reporting a problem in better and easier way
390
- * Improved support process in ZenDesk system for faster response time
391
- * Fixed typos on the import page. Thanks to Terry Heenan
392
-
393
- = 1.4.0 =
394
- * Added a Twitter and Facebook share buttons to the sidebar on import and export pages
395
-
396
- = 1.3.1 =
397
- * Fixed a bug when the user was unable to import site archive
398
- * Optimized and speeded up import process
399
-
400
- = 1.3.0 =
401
- * Added support for mysql connection to happen over sockets or TCP
402
- * Added support for Windows OS and fully tested the plugin on IIS
403
- * Added support for limited memory_limit - 1MB - The plugin now requires only 1MB to operate properly
404
- * Added support for multisite
405
- * Used mysql_unbuffered_query instead of mysql_query to overcome any memory problems
406
- * Fixed a deprecated warning for mysql_pconnect when php 5.5 and above is used
407
- * Fixed memory_limit problem with PCLZIP library
408
- * Fixed a bug when the archive is exported with zero size when using PCLZIP
409
- * Fixed a bug when the archive was exported broken on some servers
410
- * Fixed a deprecated usage of preg_replace \e in php v5.5 and above
411
-
412
- = 1.2.1 =
413
- * Fixed an issue when HTTP Error was shown on some hosts after import, credit to Michael Simon
414
- * Fixed an issue when exporting databases with different prefix than wp_, credit to najtrox
415
- * Fixed an issue when PDO is avalable but mysql driver for PDO is not, credit to Jaydesain69
416
- * Deleted a plugin specific option when uninstalling the plugin (clean after itself)
417
- * Support is done via Zendesk
418
- * Included WP Version and Plugin version in the feedback form
419
-
420
- = 1.2.0 =
421
- * Increased upload limit of files from 128MB to 512MB
422
- * Used ZipArchive with fallback to PclZip (a few users notified us that they don’t have ZipArchive enabled on their servers)
423
- * Used PDO with fallback to mysql (a few users notified us that they dont have PDO enabled on their servers, mysql is deprecated as of PHP v5.5 but we are supporting PHP v5.2.17)
424
- * Supported PHP v5.2.17 and WordPress v3.3 and above
425
- * Fixed a bug during export that causes plugins to not be exported on some hosts (the problem that you are experiencing)
426
-
427
- = 1.1.0 =
428
- * Importing files using chunks to overcome any webserver upload size restriction
429
- * Fixed a bug where HTTP code error was shown to some users
430
-
431
- = 1.0.0 =
432
- * Export database as SQL file
433
- * Export media files
434
- * Export themes files
435
- * Export installed plugins
436
- * Unlimited find/replace actions
437
- * Option to exclude spam comments
438
- * Option to apply find/replace to GUIDs
439
- * Option to exclude post revisions
440
- * Option to exclude tables data
3
  Tags: move, transfer, copy, migrate, backup, clone, restore, db migration, migration, wordpress migration, website migration, database export, database import
4
  Requires at least: 3.3
5
  Tested up to: 4.7
6
+ Stable tag: 6.44
7
  License: GPLv2 or later
8
 
9
  Move, transfer, copy, migrate, and backup a site with 1-click. Quick, easy, and reliable.
78
  3. Plugin Menu
79
 
80
  == Changelog ==
81
+ = 6.44 =
82
+ ** Added **
83
+ * PHP and DB version metadata in package.json
84
+ * Find/Replace values in package.json
85
+ * Internal Site URL and Internal Home URL in package.json
86
+ * Confirmation mechanism when uploading chunk by chunk on import
87
+ * Progress indicator on database export/import
88
+ * Shutdown handler to catch fatal errors
89
+
90
+ ** Changed **
91
+ * Replace TYPE with ENGINE keyword on database export
92
+ * Detect Site URL and Home URL in Find/Replace values
93
+ * Activate template and stylesheet on import
94
+ * Import database chunk by chunk to avoid timeout limitation
95
+
96
+ ** Fixed **
97
+ * An issue on export/import when using HipHop for PHP
98
+
99
  = 6.43 =
100
+ ** Changed **
101
+ * Plugin tags and description
102
 
103
  = 6.42 =
104
+ ** Changed **
105
+ * Improved performance when exporting database
106
 
107
  = 6.41 =
108
+ ** Added **
109
  * Support Visual Composer plugin
110
  * Support Jetpack Photon module
111
+
112
+ ** Changed **
113
  * Improved Maria DB support
114
  * Disable WordPress authentication checking during migration
115
  * Clean any temporary files after migration
116
 
117
  = 6.40 =
118
+ ** Added **
119
+ * Separate action hook in advanced settings called "ai1wm_export_advanced_settings" to allow custom checkbox options on export
120
+
121
+ ** Changed **
122
  * Do not extract dropins files on import
 
 
123
  * Do not exclude active plugins in package.json and multisite.json on export
124
  * Do not show "Resolving URL address..." on export/import
125
+
126
+ ** Fixed **
127
+ * An issue with large files on import
128
+ * An issue with inactive plugins option in advanced settings on export
129
 
130
  = 6.39 =
131
+ ** Added **
132
+ * Support for MariaDB
133
+
134
+ ** Changed **
135
  * Do not include package.json, multisite.json, blogs.json, database.sql and filemap.list files on export
 
 
136
  * Remove HTTP Basic authentication from Backups page
137
 
138
+ ** Fixed **
139
+ * An issue with unpacking archive on import
140
+ * An issue with inactivated plugins on import
141
+
142
  = 6.38 =
143
+ ** Added **
144
+ * Support for HyperDB plugin
145
+ * Support for RevSlider plugin
146
  * Check available disk space during export/import
147
  * Support very restricted hosting environments
148
+ * WPRESS mime-type to web.config when the server is IIS
149
+
150
+ ** Changed **
151
  * Switch to AJAX from cURL on export/import
152
  * Respect WordPress constants FS_CHMOD_DIR and FS_CHMOD_FILE on import
 
 
153
  * Remove misleading available disk space information on "Backups" page
154
 
155
+ ** Fixed **
156
+ * An issue related to generating archive and folder names
157
+ * An issue related to CSS styles on export page