All-in-One WP Migration - Version 1.9.2

Version Description

  • Added PHP <
Download this release

Release Info

Developer yani.iliev
Plugin Icon 128x128 All-in-One WP Migration
Version 1.9.2
Comparing to
See all releases

Code changes from version 2.0.0 to 1.9.2

Files changed (111) hide show
  1. all-in-one-wp-migration.php +2 -2
  2. constants.php +6 -93
  3. lib/controller/class-ai1wm-export-controller.php +25 -46
  4. lib/controller/class-ai1wm-feedback-controller.php +1 -7
  5. lib/controller/class-ai1wm-import-controller.php +17 -118
  6. lib/controller/class-ai1wm-main-controller.php +52 -39
  7. lib/controller/class-ai1wm-message-controller.php +5 -7
  8. lib/model/class-ai1wm-error.php +8 -6
  9. lib/model/class-ai1wm-export.php +264 -70
  10. lib/model/class-ai1wm-feedback.php +9 -11
  11. lib/model/class-ai1wm-file.php +123 -0
  12. lib/model/class-ai1wm-import.php +287 -128
  13. lib/model/class-ai1wm-message.php +19 -51
  14. lib/model/class-ai1wm-report.php +7 -5
  15. lib/model/class-ai1wm-template.php +2 -2
  16. lib/vendor/bandar/bandar/README.md +100 -0
  17. lib/vendor/mysqldump-factory/mysqldump-factory/README.md +34 -0
  18. lib/vendor/mysqldump-factory/mysqldump-factory/bump_version.sh +63 -0
  19. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpFactory.php +2 -2
  20. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpInterface.php +2 -40
  21. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php +35 -108
  22. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php +10 -97
  23. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlFileAdapter.php +2 -2
  24. lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlQueryAdapter.php +2 -2
  25. lib/vendor/storage-factory/storage-factory/README.md +32 -0
  26. lib/vendor/storage-factory/storage-factory/bump-version.sh +63 -0
  27. lib/vendor/storage-factory/storage-factory/lib/StorageAbstract.php +29 -10
  28. lib/vendor/storage-factory/storage-factory/lib/StorageArea.php +18 -56
  29. lib/vendor/storage-factory/storage-factory/lib/StorageDirectory.php +124 -17
  30. lib/vendor/storage-factory/storage-factory/lib/StorageFile.php +23 -26
  31. lib/vendor/zip-factory/zip-factory/README.md +31 -0
  32. lib/vendor/zip-factory/zip-factory/bump-version.sh +63 -0
  33. lib/view/assets/css/export.min.css +1 -1
  34. lib/view/assets/css/import.min.css +1 -1
  35. lib/view/assets/font/servmask.eot +0 -0
  36. lib/view/assets/font/servmask.svg +22 -7
  37. lib/view/assets/font/servmask.ttf +0 -0
  38. lib/view/assets/font/servmask.woff +0 -0
  39. lib/view/assets/javascript/export.min.js +1 -1
  40. lib/view/assets/javascript/import.min.js +1 -1
  41. lib/view/export/index.php +96 -187
  42. lib/view/import/index.php +46 -156
  43. loader.php +4 -44
  44. readme.txt +16 -13
  45. trunk/LICENSE +675 -0
  46. trunk/all-in-one-wp-migration.php +53 -0
  47. trunk/constants.php +184 -0
  48. trunk/lib/controller/class-ai1wm-export-controller.php +111 -0
  49. trunk/lib/controller/class-ai1wm-feedback-controller.php +60 -0
  50. trunk/lib/controller/class-ai1wm-import-controller.php +189 -0
  51. trunk/lib/controller/class-ai1wm-main-controller.php +332 -0
  52. trunk/lib/controller/class-ai1wm-message-controller.php +44 -0
  53. trunk/lib/controller/class-ai1wm-report-controller.php +54 -0
  54. {lib → trunk/lib}/exception/class-ai1wm-export-exception.php +0 -0
  55. {lib → trunk/lib}/exception/class-ai1wm-import-exception.php +0 -0
  56. trunk/lib/model/class-ai1wm-error.php +85 -0
  57. trunk/lib/model/class-ai1wm-export.php +152 -0
  58. trunk/lib/model/class-ai1wm-feedback.php +71 -0
  59. trunk/lib/model/class-ai1wm-import.php +204 -0
  60. {lib → trunk/lib}/model/class-ai1wm-logger.php +0 -0
  61. {lib → trunk/lib}/model/class-ai1wm-maintenance.php +0 -0
  62. trunk/lib/model/class-ai1wm-message.php +94 -0
  63. trunk/lib/model/class-ai1wm-report.php +67 -0
  64. trunk/lib/model/class-ai1wm-template.php +46 -0
  65. {lib → trunk/lib}/model/service/class-ai1wm-service-database.php +0 -4
  66. {lib → trunk/lib}/model/service/class-ai1wm-service-interface.php +0 -0
  67. {lib → trunk/lib}/model/service/class-ai1wm-service-media.php +0 -0
  68. {lib → trunk/lib}/model/service/class-ai1wm-service-package.php +0 -0
  69. {lib → trunk/lib}/model/service/class-ai1wm-service-plugins.php +0 -0
  70. {lib → trunk/lib}/model/service/class-ai1wm-service-sites.php +0 -0
  71. {lib → trunk/lib}/model/service/class-ai1wm-service-themes.php +0 -0
  72. trunk/lib/vendor/bandar/bandar/LICENSE +20 -0
  73. trunk/lib/vendor/bandar/bandar/lib/Bandar.php +223 -0
  74. trunk/lib/vendor/bandar/bandar/lib/Exceptions/TemplateDoesNotExistException.php +50 -0
  75. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/LICENSE +20 -0
  76. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpFactory.php +69 -0
  77. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpInterface.php +303 -0
  78. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpPDO.php +798 -0
  79. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlDumpSQL.php +738 -0
  80. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlFileAdapter.php +74 -0
  81. trunk/lib/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlQueryAdapter.php +109 -0
  82. {lib → trunk/lib}/vendor/mysqldump-factory/mysqldump-factory/lib/MysqlUtility.php +2 -2
  83. trunk/lib/vendor/storage-factory/storage-factory/LICENSE +20 -0
  84. trunk/lib/vendor/storage-factory/storage-factory/lib/StorageAbstract.php +70 -0
  85. trunk/lib/vendor/storage-factory/storage-factory/lib/StorageArea.php +130 -0
  86. trunk/lib/vendor/storage-factory/storage-factory/lib/StorageDirectory.php +100 -0
  87. trunk/lib/vendor/storage-factory/storage-factory/lib/StorageFile.php +100 -0
  88. {lib → trunk/lib}/vendor/storage-factory/storage-factory/lib/StorageUtility.php +0 -0
  89. trunk/lib/vendor/zip-factory/zip-factory/LICENSE +20 -0
  90. trunk/lib/vendor/zip-factory/zip-factory/lib/ArchiverInterface.php +118 -0
  91. trunk/lib/vendor/zip-factory/zip-factory/lib/ArchiverPclZip.php +218 -0
  92. trunk/lib/vendor/zip-factory/zip-factory/lib/ArchiverZipArchive.php +223 -0
  93. trunk/lib/vendor/zip-factory/zip-factory/lib/ZipFactory.php +70 -0
  94. trunk/lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/gnu-lgpl.txt +504 -0
  95. trunk/lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/pclzip.lib.php +5690 -0
  96. trunk/lib/vendor/zip-factory/zip-factory/lib/vendor/pclzip-2-8-2/readme.txt +421 -0
  97. trunk/lib/view/assets/css/export.min.css +1 -0
  98. trunk/lib/view/assets/css/import.min.css +1 -0
  99. trunk/lib/view/assets/font/servmask.eot +0 -0
  100. trunk/lib/view/assets/font/servmask.svg +22 -0
  101. trunk/lib/view/assets/font/servmask.ttf +0 -0
  102. trunk/lib/view/assets/font/servmask.woff +0 -0
  103. {lib → trunk/lib}/view/assets/img/ajax-loader.gif +0 -0
  104. trunk/lib/view/assets/javascript/export.min.js +1 -0
  105. trunk/lib/view/assets/javascript/import.min.js +1 -0
  106. trunk/lib/view/export/index.php +341 -0
  107. trunk/lib/view/import/index.php +247 -0
  108. trunk/loader.php +161 -0
  109. trunk/readme.txt +174 -0
  110. trunk/uninstall.php +43 -0
  111. uninstall.php +6 -5
all-in-one-wp-migration.php CHANGED
@@ -2,10 +2,10 @@
2
/**
3
* Plugin Name: All-in-One WP Migration
4
* Plugin URI: https://servmask.com/
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: 2.0.0
9
*
10
* Copyright (C) 2014 ServMask Inc.
11
*
2
/**
3
* Plugin Name: All-in-One WP Migration
4
* Plugin URI: https://servmask.com/
5
+ * Description: Migration tool for all your blog data
6
* Author: ServMask
7
* Author URI: https://servmask.com/
8
+ * Version: 1.9.2
9
*
10
* Copyright (C) 2014 ServMask Inc.
11
*
constants.php CHANGED
@@ -24,25 +24,15 @@
24
*/
25
26
// ==================
27
- // = Plugin Version =
28
// ==================
29
- define( 'AI1WM_VERSION', '2.0.0' );
30
31
// ===============
32
// = Plugin Name =
33
// ===============
34
define( 'AI1WM_PLUGIN_NAME', 'all-in-one-wp-migration' );
35
36
- // ===============
37
- // = Plugin PRO Basename =
38
- // ===============
39
- define( 'AI1WM_PRO_PLUGIN_BASENAME', 'all-in-one-wp-migration-pro/all-in-one-wp-migration-pro.php' );
40
-
41
- // ===============
42
- // = Storage Index =
43
- // ===============
44
- define( 'AI1WM_STORAGE_INDEX', 'index.php' );
45
-
46
// ===============
47
// = Storage Path =
48
// ===============
@@ -63,11 +53,6 @@ define( 'AI1WM_CONTROLLER_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'control
63
// ==============
64
define( 'AI1WM_MODEL_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'model' );
65
66
- // ==============
67
- // = Service Path =
68
- // ==============
69
- define( 'AI1WM_SERVICE_PATH', AI1WM_MODEL_PATH . DIRECTORY_SEPARATOR . 'service' );
70
-
71
// =============
72
// = View Path =
73
// =============
@@ -99,91 +84,19 @@ define( 'AI1WM_REPORT_URL', 'https://servmask.com/ai1wm/report/create' );
99
define( 'AI1WM_TABLE_PREFIX', 'SERVMASK_PREFIX_' );
100
101
// ==============
102
- // = Archive Database Name =
103
- // ==============
104
- define( 'AI1WM_DATABASE_NAME', 'database.sql' );
105
-
106
- // ==============
107
- // = Archive Media Name =
108
- // ==============
109
- define( 'AI1WM_MEDIA_NAME', 'media' );
110
-
111
- // ==============
112
- // = Archive Sites Name =
113
- // ==============
114
- define( 'AI1WM_SITES_NAME', 'sites' );
115
-
116
- // ==============
117
- // = Archive Blogs Name =
118
- // ==============
119
- define( 'AI1WM_BLOGS_NAME', 'blogs.dir' );
120
-
121
- // ==============
122
- // = Archive Themes Name =
123
- // ==============
124
- define( 'AI1WM_THEMES_NAME', 'themes' );
125
-
126
- // ==============
127
- // = Archive Plugins Name =
128
- // ==============
129
- define( 'AI1WM_PLUGINS_NAME', 'plugins' );
130
-
131
- // ==============
132
- // = Archive Package Name =
133
- // ==============
134
- define( 'AI1WM_PACKAGE_NAME', 'package.json' );
135
-
136
- // ==============
137
- // = Export Options Key =
138
- // ==============
139
- define( 'AI1WM_EXPORT_OPTIONS', 'ai1wm_export_options' );
140
-
141
- // ==============
142
- // = Error Handler Key =
143
- // ==============
144
- define( 'AI1WM_ERROR_HANDLER', 'ai1wm_error_handler' );
145
-
146
- // ==============
147
- // = Exception Handler Key =
148
- // ==============
149
- define( 'AI1WM_EXCEPTION_HANDLER', 'ai1wm_exception_handler' );
150
-
151
- // ==============
152
- // = Maintenance Mode Key =
153
- // ==============
154
- define( 'AI1WM_MAINTENANCE_MODE', 'ai1wm_maintenance_mode' );
155
-
156
- // ==============
157
- // = Messages Key =
158
- // ==============
159
- define( 'AI1WM_MESSAGES', 'ai1wm_messages' );
160
-
161
- // ==============
162
- // = Max File Size =
163
- // ==============
164
- define( 'AI1WM_MAX_FILE_SIZE', '512MB' );
165
-
166
- // ==============
167
- // = Max Chunk Size =
168
- // ==============
169
- define( 'AI1WM_MAX_CHUNK_SIZE', '500KB' );
170
-
171
- // ==============
172
- // = Max Chunk Retries =
173
// ==============
174
- define( 'AI1WM_MAX_CHUNK_RETRIES', '100' );
175
176
// ===========================
177
// = WP_CONTENT_DIR Constant =
178
// ===========================
179
- if ( ! defined( 'WP_CONTENT_DIR' ) ) {
180
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
181
- }
182
183
// ==========================
184
// = WP_PLUGIN_DIR Constant =
185
// ==========================
186
- if ( ! defined( 'WP_PLUGIN_DIR' ) ) {
187
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
188
- }
189
24
*/
25
26
// ==================
27
+ // = Plugin VERSION =
28
// ==================
29
+ define( 'AI1WM_VERSION', '1.9.2' );
30
31
// ===============
32
// = Plugin Name =
33
// ===============
34
define( 'AI1WM_PLUGIN_NAME', 'all-in-one-wp-migration' );
35
36
// ===============
37
// = Storage Path =
38
// ===============
53
// ==============
54
define( 'AI1WM_MODEL_PATH', AI1WM_LIB_PATH . DIRECTORY_SEPARATOR . 'model' );
55
56
// =============
57
// = View Path =
58
// =============
84
define( 'AI1WM_TABLE_PREFIX', 'SERVMASK_PREFIX_' );
85
86
// ==============
87
+ // = ServMask Storage Prefix =
88
// ==============
89
+ define( 'AI1WM_STORAGE_PREFIX', 'wm_' );
90
91
// ===========================
92
// = WP_CONTENT_DIR Constant =
93
// ===========================
94
+ if ( ! defined( 'WP_CONTENT_DIR' ) )
95
define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
96
97
// ==========================
98
// = WP_PLUGIN_DIR Constant =
99
// ==========================
100
+ if ( ! defined( 'WP_PLUGIN_DIR' ) )
101
define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
102
lib/controller/class-ai1wm-export-controller.php CHANGED
@@ -27,20 +27,23 @@ class Ai1wm_Export_Controller
27
{
28
public static function index() {
29
try {
30
- $is_accessible = StorageArea::getInstance()->getRootPath();
31
} catch ( Exception $e ) {
32
$is_accessible = false;
33
}
34
35
- // Messages
36
- $model = new Ai1wm_Message;
37
- $messages = $model->get_messages();
38
39
Ai1wm_Template::render(
40
'export/index',
41
array(
42
- 'messages' => $messages,
43
'is_accessible' => $is_accessible,
44
)
45
);
46
}
@@ -52,60 +55,36 @@ class Ai1wm_Export_Controller
52
53
// Get options
54
if ( isset( $_POST['options'] ) && ( $options = $_POST['options'] ) ) {
55
56
- // Log options
57
- Ai1wm_Logger::debug( AI1WM_EXPORT_OPTIONS, $options );
58
-
59
- // Export site
60
- $model = new Ai1wm_Export( $options );
61
- $file = $model->export();
62
63
// Send the file to the user
64
header( 'Content-Description: File Transfer' );
65
header( 'Content-Type: application/octet-stream' );
66
- header( 'Content-Disposition: attachment; filename=' . self::filename() );
67
header( 'Content-Transfer-Encoding: binary' );
68
header( 'Expires: 0' );
69
header( 'Cache-Control: must-revalidate' );
70
header( 'Pragma: public' );
71
- header( 'Content-Length: ' . $file->getSize() );
72
73
// Clear output buffering and read file content
74
- while (@ob_end_clean());
75
-
76
- // Load file content
77
- $handle = fopen( $file->getName(), 'rb' );
78
- while ( !feof( $handle ) ) {
79
- echo fread( $handle, 8192 );
80
}
81
- fclose( $handle );
82
-
83
- // Flush storage
84
- StorageArea::getInstance()->flush();
85
exit;
86
}
87
}
88
-
89
- public static function filename() {
90
- $url = parse_url( home_url() );
91
- $name = array();
92
-
93
- // Add domain
94
- if ( isset( $url['host'] ) ) {
95
- $name[] = $url['host'];
96
- }
97
-
98
- // Add path
99
- if ( isset( $url['path'] ) ) {
100
- $name[] = $url['path'];
101
- }
102
-
103
- // Add year, month and day
104
- $name[] = date('Ymd');
105
-
106
- // Add hours, minutes and seconds
107
- $name[] = date('His');
108
-
109
- return sprintf( '%s.zip', implode( '-', $name ) );
110
- }
111
}
27
{
28
public static function index() {
29
try {
30
+ $storage = new StorageArea;
31
+ $is_accessible = $storage->makeFile();
32
+ $storage->flush();
33
} catch ( Exception $e ) {
34
$is_accessible = false;
35
}
36
37
+ // Message
38
+ $message = new Ai1wm_Message;
39
+ $is_closed = $message->is_closed( Ai1wm_Message::MESSAGE_INFO );
40
41
Ai1wm_Template::render(
42
'export/index',
43
array(
44
+ 'list_plugins' => get_plugins(),
45
'is_accessible' => $is_accessible,
46
+ 'is_closed' => $is_closed,
47
)
48
);
49
}
55
56
// Get options
57
if ( isset( $_POST['options'] ) && ( $options = $_POST['options'] ) ) {
58
+ $storage = new StorageArea;
59
60
+ // Export archive
61
+ $model = new Ai1wm_Export;
62
+ $file = $model->export( $storage, $options );
63
64
// Send the file to the user
65
header( 'Content-Description: File Transfer' );
66
header( 'Content-Type: application/octet-stream' );
67
+ header(
68
+ sprintf(
69
+ 'Content-Disposition: attachment; filename=%s-%s.%s',
70
+ Ai1wm_Export::EXPORT_ARCHIVE_NAME,
71
+ time(),
72
+ 'zip'
73
+ )
74
+ );
75
header( 'Content-Transfer-Encoding: binary' );
76
header( 'Expires: 0' );
77
header( 'Cache-Control: must-revalidate' );
78
header( 'Pragma: public' );
79
+ header( 'Content-Length: ' . filesize( $file->getAs( 'string' ) ) );
80
81
// Clear output buffering and read file content
82
+ if ( ob_get_length() > 0 ) {
83
+ @ob_end_clean();
84
}
85
+ readfile( $file->getAs( 'string' ) );
86
+ $storage->flush();
87
exit;
88
}
89
}
90
}
lib/controller/class-ai1wm-feedback-controller.php CHANGED
@@ -26,12 +26,6 @@
26
class Ai1wm_Feedback_Controller
27
{
28
public static function leave_feedback() {
29
- // Set Type
30
- $type = null;
31
- if ( isset( $_POST['type'] ) ) {
32
- $type = trim( $_POST['type'] );
33
- }
34
-
35
// Set E-mail
36
$email = null;
37
if ( isset( $_POST['email'] ) ) {
@@ -52,7 +46,7 @@ class Ai1wm_Feedback_Controller
52
53
// Send Feedback
54
$model = new Ai1wm_Feedback;
55
- $result = $model->leave_feedback( $type, $email, $message, $terms );
56
57
echo json_encode( $result );
58
exit;
26
class Ai1wm_Feedback_Controller
27
{
28
public static function leave_feedback() {
29
// Set E-mail
30
$email = null;
31
if ( isset( $_POST['email'] ) ) {
46
47
// Send Feedback
48
$model = new Ai1wm_Feedback;
49
+ $result = $model->leave_feedback( $email, $message, $terms );
50
51
echo json_encode( $result );
52
exit;
lib/controller/class-ai1wm-import-controller.php CHANGED
@@ -27,7 +27,9 @@ class Ai1wm_Import_Controller
27
{
28
public static function index() {
29
try {
30
- $is_accessible = StorageArea::getInstance()->getRootPath();
31
} catch ( Exception $e ) {
32
$is_accessible = false;
33
}
@@ -40,23 +42,21 @@ class Ai1wm_Import_Controller
40
);
41
}
42
43
- public static function import() {
44
global $wp_rewrite;
45
46
// Set default handlers
47
set_error_handler( array( 'Ai1wm_Error', 'error_handler' ) );
48
set_exception_handler( array( 'Ai1wm_Error', 'exception_handler' ) );
49
50
- $messages = array();
51
52
- if ( isset( $_FILES['upload-file'] ) || isset( $_REQUEST['force'] ) ) {
53
$options = array(
54
- 'chunk' => 0,
55
- 'chunks' => 1,
56
- 'import' => array(
57
- 'file' => null,
58
- 'force' => null,
59
- ),
60
);
61
62
// Ordinal number of the current chunk in the set (starts with zero)
@@ -69,120 +69,19 @@ class Ai1wm_Import_Controller
69
$options['chunks'] = intval( $_REQUEST['chunks'] );
70
}
71
72
- // Import file
73
if ( isset( $_REQUEST['name'] ) ) {
74
- $options['import']['file'] = $_REQUEST['name'];
75
}
76
77
- // Force file
78
- if ( isset( $_REQUEST['force'] ) ) {
79
- $options['import']['force'] = $_REQUEST['force'];
80
- }
81
-
82
- try {
83
- // Upload file
84
- if ( self::upload( $options ) ) {
85
-
86
- // Import site
87
- $model = new Ai1wm_Import( $options );
88
- if ( $model->import() ) {
89
- $messages[] = array(
90
- 'type' => 'success',
91
- 'text' => sprintf(
92
- _(
93
- 'Your data has been imported successfuly!<br />' .
94
- 'You need to perform two more steps:<br />' .
95
- '<strong>1. You must save your permalinks structure twice. <a class="ai1wm-no-underline" href="%s#submit" target="_blank">Permalinks Settings</a></strong> (opens a new window)<br />' .
96
- '<strong>2. <a class="ai1wm-no-underline" href="https://wordpress.org/support/view/plugin-reviews/all-in-one-wp-migration?rate=5#postform" target="_blank">Review the plugin</a>.</strong> (opens a new window)'
97
- ),
98
- admin_url( 'options-permalink.php' )
99
- ),
100
- );
101
-
102
- // Flush storage
103
- StorageArea::getInstance()->flush();
104
- }
105
- }
106
- } catch ( Exception $e ) {
107
- $messages[] = array(
108
- 'type' => 'error',
109
- 'text' => $e->getMessage(),
110
- );
111
- }
112
- }
113
-
114
- // Regenerate permalinks
115
- $wp_rewrite->flush_rules( true );
116
-
117
- // Display messages
118
- echo json_encode( $messages );
119
- exit;
120
- }
121
122
- public static function upload( $options ) {
123
- $storage = StorageArea::getInstance();
124
-
125
- // Partial upload file
126
- $partial_file = $storage->makeFile( $options['import']['file'] );
127
-
128
- // Upload file
129
- if ( isset( $_FILES['upload-file'] ) ) {
130
-
131
- // Has any upload error?
132
- if ( empty( $_FILES['upload-file']['error'] ) ) {
133
-
134
- // Flush storage
135
- if ( $options['chunk'] === 0 ) {
136
- $storage->flush();
137
- }
138
-
139
- // Open partial file
140
- $out = fopen( $partial_file->getName(), $options['chunk'] == 0 ? 'wb' : 'ab' );
141
- if ( $out ) {
142
- // Read binary input stream and append it to temp file
143
- $in = fopen( $_FILES['upload-file']['tmp_name'], 'rb' );
144
- if ( $in ) {
145
- while ( $buff = fread( $in, 4096 ) ) {
146
- fwrite( $out, $buff );
147
- }
148
- }
149
-
150
- fclose( $in );
151
- fclose( $out );
152
-
153
- // Remove temporary uploaded file
154
- unlink( $_FILES['upload-file']['tmp_name'] );
155
- } else {
156
- throw new Ai1wm_Import_Exception(
157
- sprintf(
158
- _(
159
- 'Site could not be imported!<br />' .
160
- 'Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
161
- ),
162
- AI1WM_STORAGE_PATH
163
- )
164
- );
165
-
166
- // Flush storage
167
- $storage->flush();
168
- }
169
- } else {
170
- throw new Ai1wm_Import_Exception(
171
- sprintf(
172
- _(
173
- 'Site could not be imported!<br />' .
174
- 'Please contact ServMask Support and report the following error code: %d'
175
- ),
176
- $_FILES['upload-file']['error']
177
- )
178
- );
179
- }
180
}
181
182
- // Upload completed?
183
- if ( ! $options['chunks'] || $options['chunk'] == $options['chunks'] - 1 ) {
184
- return $partial_file;
185
- }
186
exit;
187
}
188
}
27
{
28
public static function index() {
29
try {
30
+ $storage = new StorageArea;
31
+ $is_accessible = $storage->makeFile();
32
+ $storage->flush();
33
} catch ( Exception $e ) {
34
$is_accessible = false;
35
}
42
);
43
}
44
45
+ public static function upload_file() {
46
global $wp_rewrite;
47
48
// Set default handlers
49
set_error_handler( array( 'Ai1wm_Error', 'error_handler' ) );
50
set_exception_handler( array( 'Ai1wm_Error', 'exception_handler' ) );
51
52
+ $result = array();
53
54
+ // Get options
55
+ if ( isset( $_FILES['input_file'] ) && ( $input_file = $_FILES['input_file'] ) ) {
56
$options = array(
57
+ 'chunk' => 0,
58
+ 'chunks' => 0,
59
+ 'name' => null,
60
);
61
62
// Ordinal number of the current chunk in the set (starts with zero)
69
$options['chunks'] = intval( $_REQUEST['chunks'] );
70
}
71
72
+ // Name of partial file
73
if ( isset( $_REQUEST['name'] ) ) {
74
+ $options['name'] = $_REQUEST['name'];
75
}
76
77
+ $model = new Ai1wm_Import;
78
+ $result = $model->import( $input_file, $options );
79
80
+ // Regenerate permalinks
81
+ $wp_rewrite->flush_rules( true );
82
}
83
84
+ echo json_encode( $result );
85
exit;
86
}
87
}
lib/controller/class-ai1wm-main-controller.php CHANGED
@@ -25,6 +25,7 @@
25
26
class Ai1wm_Main_Controller
27
{
28
/**
29
* Main Application Controller
30
*
@@ -74,10 +75,13 @@ class Ai1wm_Main_Controller
74
add_action( 'init', array( $this, 'router' ) );
75
add_action( 'wp_ajax_leave_feedback', 'Ai1wm_Feedback_Controller::leave_feedback' );
76
add_action( 'wp_ajax_report_problem', 'Ai1wm_Report_Controller::report_problem' );
77
- add_action( 'wp_ajax_import', 'Ai1wm_Import_Controller::import' );
78
add_action( 'wp_ajax_close_message', 'Ai1wm_Message_Controller::close_message' );
79
- add_action( 'wp_ajax_disable_maintenance', 'Ai1wm_Maintenance::disable' );
80
- add_action( 'get_header', 'Ai1wm_Maintenance::display' );
81
82
// Add a links to plugin list page
83
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
@@ -105,6 +109,23 @@ class Ai1wm_Main_Controller
105
return $this;
106
}
107
108
/**
109
* Register plugin menus
110
*/
@@ -154,20 +175,26 @@ class Ai1wm_Main_Controller
154
*/
155
public function admin_head() {
156
global $wp_version;
157
$url = AI1WM_URL . '/lib/view/assets';
158
?>
159
<style type="text/css" media="all">
160
@font-face {
161
font-family: 'servmask';
162
- src:url('<?php echo esc_url( $url ); ?>/font/servmask.eot?v=<?php echo AI1WM_VERSION; ?>');
163
- src:url('<?php echo esc_url( $url ); ?>/font/servmask.eot?v=<?php echo AI1WM_VERSION; ?>#iefix') format('embedded-opentype'),
164
- url('<?php echo esc_url( $url ); ?>/font/servmask.woff?v=<?php echo AI1WM_VERSION; ?>') format('woff'),
165
- url('<?php echo esc_url( $url ); ?>/font/servmask.ttf?v=<?php echo AI1WM_VERSION; ?>') format('truetype'),
166
- url('<?php echo esc_url( $url ); ?>/font/servmask.svg?v=<?php echo AI1WM_VERSION; ?>#servmask') format('svg');
167
font-weight: normal;
168
font-style: normal;
169
}
170
- <?php if ( version_compare( $wp_version, '3.8', '<' ) ) : ?>
171
.toplevel_page_site-migration-export > div.wp-menu-image {
172
background: none !important;
173
}
@@ -235,12 +262,6 @@ class Ai1wm_Main_Controller
235
),
236
);
237
wp_localize_script( 'ai1wm-js-export', 'ai1wm_message', $message_init );
238
- $maintenance_init = array(
239
- 'ajax' => array(
240
- 'url' => admin_url( 'admin-ajax.php' ) . '?action=disable_maintenance',
241
- ),
242
- );
243
- wp_localize_script( 'ai1wm-js-export', 'ai1wm_maintenance', $maintenance_init );
244
}
245
246
/**
@@ -261,19 +282,17 @@ class Ai1wm_Main_Controller
261
'browse_button' => 'ai1wm-browse-button',
262
'container' => 'ai1wm-plupload-upload-ui',
263
'drop_element' => 'ai1wm-drag-drop-area',
264
- 'file_data_name' => 'upload-file',
265
- 'max_file_size' => AI1WM_MAX_FILE_SIZE,
266
- 'chunk_size' => AI1WM_MAX_CHUNK_SIZE,
267
- 'max_retries' => AI1WM_MAX_CHUNK_RETRIES,
268
- 'url' => admin_url( 'admin-ajax.php' ),
269
- 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
270
- 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
271
'multiple_queues' => false,
272
- 'urlstream_upload' => true,
273
- 'unique_names' => true,
274
- 'multipart' => true,
275
- 'multipart_params' => array(
276
- 'action' => 'import',
277
),
278
'filters' => array(
279
array(
@@ -281,6 +300,12 @@ class Ai1wm_Main_Controller
281
'extensions' => 'zip',
282
),
283
),
284
);
285
wp_localize_script( 'ai1wm-js-import', 'ai1wm_uploader', $plupload_init );
286
$feedback_init = array(
@@ -295,18 +320,6 @@ class Ai1wm_Main_Controller
295
),
296
);
297
wp_localize_script( 'ai1wm-js-import', 'ai1wm_report', $report_init );
298
- $maintenance_init = array(
299
- 'ajax' => array(
300
- 'url' => admin_url( 'admin-ajax.php' ) . '?action=disable_maintenance',
301
- ),
302
- );
303
- wp_localize_script( 'ai1wm-js-import', 'ai1wm_maintenance', $maintenance_init );
304
- $import_init = array(
305
- 'ajax' => array(
306
- 'url' => admin_url( 'admin-ajax.php' ) . '?action=import',
307
- ),
308
- );
309
- wp_localize_script( 'ai1wm-js-import', 'ai1wm_import', $import_init );
310
}
311
312
/**
25
26
class Ai1wm_Main_Controller
27
{
28
+
29
/**
30
* Main Application Controller
31
*
75
add_action( 'init', array( $this, 'router' ) );
76
add_action( 'wp_ajax_leave_feedback', 'Ai1wm_Feedback_Controller::leave_feedback' );
77
add_action( 'wp_ajax_report_problem', 'Ai1wm_Report_Controller::report_problem' );
78
+ add_action( 'wp_ajax_upload_file', 'Ai1wm_Import_Controller::upload_file' );
79
add_action( 'wp_ajax_close_message', 'Ai1wm_Message_Controller::close_message' );
80
+
81
+ // Enable or disable maintenance mode
82
+ if ( get_option( Ai1wm_Import::MAINTENANCE_MODE ) ) {
83
+ add_action( 'get_header', array( $this, 'activate_maintenance_mode' ) );
84
+ }
85
86
// Add a links to plugin list page
87
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
109
return $this;
110
}
111
112
+ /**
113
+ * Enable or disable Wordpress maintenance mode
114
+ * @return void
115
+ */
116
+ public function activate_maintenance_mode() {
117
+ $title = _( 'Maintenance Mode' );
118
+ $body = sprintf(
119
+ '<h1>%s</h1><p>%s<br /><strong>%s%s</strong></p>',
120
+ _( 'Website Under Maintenance' ),
121
+ _( 'Hi, our Website is currently undergoing scheduled maintenance' ),
122
+ _( 'Please check back very soon. ' ),
123
+ _( 'Sorry for the inconvenience!' )
124
+ );
125
+
126
+ wp_die( $body, $title );
127
+ }
128
+
129
/**
130
* Register plugin menus
131
*/
175
*/
176
public function admin_head() {
177
global $wp_version;
178
+ $_wp_version = $wp_version;
179
+ if ( strlen( $_wp_version ) === '3' ) {
180
+ $_wp_version += '.0';
181
+ } else if ( strlen( $_wp_version ) === '1' ) {
182
+ $_wp_version += '0.0';
183
+ }
184
$url = AI1WM_URL . '/lib/view/assets';
185
?>
186
<style type="text/css" media="all">
187
@font-face {
188
font-family: 'servmask';
189
+ src:url('<?php echo esc_url( $url ); ?>/font/servmask.eot');
190
+ src:url('<?php echo esc_url( $url ); ?>/font/servmask.eot?#iefix') format('embedded-opentype'),
191
+ url('<?php echo esc_url( $url ); ?>/font/servmask.woff') format('woff'),
192
+ url('<?php echo esc_url( $url ); ?>/font/servmask.ttf') format('truetype'),
193
+ url('<?php echo esc_url( $url ); ?>/font/servmask.svg#servmask') format('svg');
194
font-weight: normal;
195
font-style: normal;
196
}
197
+ <?php if ( version_compare( $_wp_version, '3.8', '<' ) ) : ?>
198
.toplevel_page_site-migration-export > div.wp-menu-image {
199
background: none !important;
200
}
262
),
263
);
264
wp_localize_script( 'ai1wm-js-export', 'ai1wm_message', $message_init );
265
}
266
267
/**
282
'browse_button' => 'ai1wm-browse-button',
283
'container' => 'ai1wm-plupload-upload-ui',
284
'drop_element' => 'ai1wm-drag-drop-area',
285
+ 'file_data_name' => 'input_file',
286
'multiple_queues' => false,
287
+ 'max_file_size' => Ai1wm_Import::MAX_FILE_SIZE,
288
+ 'chunk_size' => Ai1wm_Import::MAX_CHUNK_SIZE,
289
+ 'max_retries' => Ai1wm_Import::MAX_CHUNK_RETRIES,
290
+ 'url' => admin_url( 'admin-ajax.php' ),
291
+ 'flash_swf_url' => includes_url(
292
+ 'js/plupload/plupload.flash.swf'
293
+ ),
294
+ 'silverlight_xap_url' => includes_url(
295
+ 'js/plupload/plupload.silverlight.xap'
296
),
297
'filters' => array(
298
array(
300
'extensions' => 'zip',
301
),
302
),
303
+ 'multipart' => true,
304
+ 'urlstream_upload' => true,
305
+ 'multipart_params' => array(
306
+ 'action' => 'upload_file',
307
+ 'name' => uniqid() . '.part',
308
+ ),
309
);
310
wp_localize_script( 'ai1wm-js-import', 'ai1wm_uploader', $plupload_init );
311
$feedback_init = array(
320
),
321
);
322
wp_localize_script( 'ai1wm-js-import', 'ai1wm_report', $report_init );
323
}
324
325
/**
lib/controller/class-ai1wm-message-controller.php CHANGED
@@ -26,17 +26,15 @@
26
class Ai1wm_Message_Controller
27
{
28
public static function close_message() {
29
- $errors = array();
30
-
31
- // Set Key
32
- $key = null;
33
- if ( isset( $_POST['key'] ) ) {
34
- $key = trim( $_POST['key'] );
35
}
36
37
// Close message
38
$model = new Ai1wm_Message;
39
- $result = $model->close_message( $key );
40
41
echo json_encode( $result );
42
exit;
26
class Ai1wm_Message_Controller
27
{
28
public static function close_message() {
29
+ // Set Type
30
+ $type = null;
31
+ if ( isset( $_POST['type'] ) ) {
32
+ $type = trim( $_POST['type'] );
33
}
34
35
// Close message
36
$model = new Ai1wm_Message;
37
+ $result = $model->close_message( $type );
38
39
echo json_encode( $result );
40
exit;
lib/model/class-ai1wm-error.php CHANGED
@@ -25,8 +25,10 @@
25
26
class Ai1wm_Error
27
{
28
- const ERROR_LIMIT = 10;
29
- const EXCEPTION_LIMIT = 10;
30
31
/**
32
* Custom Error Handler
@@ -38,7 +40,7 @@ class Ai1wm_Error
38
* @return void
39
*/
40
public static function error_handler( $code, $message, $file, $line ) {
41
- $errors = get_option( AI1WM_ERROR_HANDLER, array() );
42
43
// Limit errors
44
if ( count( $errors ) > self::ERROR_LIMIT ) {
@@ -54,7 +56,7 @@ class Ai1wm_Error
54
'time' => time(),
55
);
56
57
- Ai1wm_Logger::error( AI1WM_ERROR_HANDLER, $errors );
58
}
59
60
/**
@@ -64,7 +66,7 @@ class Ai1wm_Error
64
* @return void
65
*/
66
public static function exception_handler( $e ) {
67
- $exceptions = get_option( AI1WM_EXCEPTION_HANDLER, array() );
68
69
// Limit errors
70
if ( count( $exceptions ) > self::EXCEPTION_LIMIT ) {
@@ -80,6 +82,6 @@ class Ai1wm_Error
80
'time' => time(),
81
);
82
83
- Ai1wm_Logger::error( AI1WM_EXCEPTION_HANDLER, $exceptions );
84
}
85
}
25
26
class Ai1wm_Error
27
{
28
+ const ERROR_LIMIT = 20;
29
+ const EXCEPTION_LIMIT = 20;
30
+ const ERROR_HANDLER = 'ai1wm_error_handler';
31
+ const EXCEPTION_HANDLER = 'ai1wm_exception_handler';
32
33
/**
34
* Custom Error Handler
40
* @return void
41
*/
42
public static function error_handler( $code, $message, $file, $line ) {
43
+ $errors = get_option( self::ERROR_HANDLER, array() );
44
45
// Limit errors
46
if ( count( $errors ) > self::ERROR_LIMIT ) {
56
'time' => time(),
57
);
58
59
+ update_option( self::ERROR_HANDLER, $errors );
60
}
61
62
/**
66
* @return void
67
*/
68
public static function exception_handler( $e ) {
69
+ $exceptions = get_option( self::EXCEPTION_HANDLER, array() );
70
71
// Limit errors
72
if ( count( $exceptions ) > self::EXCEPTION_LIMIT ) {
82
'time' => time(),
83
);
84
85
+ update_option( self::EXCEPTION_HANDLER, $exceptions );
86
}
87
}
lib/model/class-ai1wm-export.php CHANGED
@@ -25,128 +25,322 @@
25
26
class Ai1wm_Export
27
{
28
- protected $options = array();
29
-
30
- public function __construct( array $options = array() ) {
31
- $this->options = $options;
32
- }
33
34
/**
35
- * Export site
36
*
37
- * @return StorageFile
38
*/
39
- public function export() {
40
- $storage = StorageArea::getInstance();
41
42
- // Enable maintenance mode
43
- Ai1wm_Maintenance::enable();
44
45
- // Create export file
46
- $export_file = $storage->makeFile();
47
48
- // Make archive file
49
try {
50
- $zip = ZipFactory::makeZipArchiver( $export_file->getName(), ! class_exists( 'ZipArchive' ), true );
51
} catch ( Exception $e ) {
52
- $zip = ZipFactory::makeZipArchiver( $export_file->getName(), true, true );
53
}
54
55
- // Package
56
- if ( $this->should_export_package() ) {
57
- $service = new Ai1wm_Service_Package( $this->options );
58
- $zip->addFromString( AI1WM_PACKAGE_NAME, $service->export() );
59
- }
60
-
61
- // Database
62
- if ( $this->should_export_database() ) {
63
- $service = new Ai1wm_Service_Database( $this->options );
64
65
// Add database to archive
66
- $zip->addFile( $service->export(), AI1WM_DATABASE_NAME );
67
}
68
69
- // Media
70
- if ( $this->should_export_media() ) {
71
- $service = new Ai1wm_Service_Media( $this->options );
72
73
- // Add media to archive
74
- $zip->addDir( $service->export(), AI1WM_MEDIA_NAME );
75
76
- // Sites (Network mode)
77
- $service = new Ai1wm_Service_Sites( $this->options );
78
- if ( ( $sites = $service->export() ) ) {
79
- // Add sites to archive
80
- $zip->addDir( $sites, AI1WM_SITES_NAME );
81
}
82
}
83
84
- // Themes
85
- if ( $this->should_export_themes() ) {
86
- $service = new Ai1wm_Service_Themes( $this->options );
87
88
- // Add themes to archive
89
- $zip->addDir( $service->export(), AI1WM_THEMES_NAME );
90
}
91
92
- // Plugins
93
- if ( $this->should_export_plugins() ) {
94
- $service = new Ai1wm_Service_Plugins( $this->options );
95
96
- // Add plugins to archive
97
- if ( ( $plugins = $service->get_installed_plugins() ) ) {
98
- $zip->addDir( $service->export(), AI1WM_PLUGINS_NAME, $plugins );
99
}
100
}
101
102
- // Disable maintenance mode
103
- Ai1wm_Maintenance::disable();
104
105
- return $export_file;
106
}
107
108
/**
109
- * Should export package?
110
*
111
- * @return boolean
112
*/
113
- public function should_export_package() {
114
- return true;
115
}
116
117
/**
118
- * Should export database?
119
*
120
- * @return boolean
121
*/
122
- public function should_export_database() {
123
- return ! isset( $this->options['export-database'] );
124
}
125
126
/**
127
- * Should export media?
128
*
129
- * @return boolean
130
*/
131
- public function should_export_media() {
132
- return ! isset( $this->options['export-media'] );
133
}
134
135
/**
136
- * Should export themes?
137
*
138
- * @return boolean
139
*/
140
- public function should_export_themes() {
141
- return ! isset( $this->options['export-themes'] );
142
}
143
144
/**
145
- * Should export plugins?
146
*
147
- * @return boolean
148
*/
149
- public function should_export_plugins() {
150
- return ! isset( $this->options['export-plugins'] );
151
}
152
}
25
26
class Ai1wm_Export
27
{
28
+ const EXPORT_ARCHIVE_NAME = 'dump';
29
+ const EXPORT_DATABASE_NAME = 'database.sql';
30
+ const EXPORT_PACKAGE_NAME = 'package.json';
31
+ const EXPORT_MEDIA_NAME = 'media';
32
+ const EXPORT_PLUGINS_NAME = 'plugins';
33
+ const EXPORT_THEMES_NAME = 'themes';
34
+ const EXPORT_LAST_OPTIONS = 'ai1wm_export_last_options';
35
36
/**
37
+ * Export archive file (database, media, package.json)
38
*
39
+ * @param StorageArea $storage Storage instance
40
+ * @param array $options Export settings
41
+ * @return StorageFile StorageFile instance
42
*/
43
+ public function export( StorageArea $storage, array $options = array() ) {
44
+ global $wp_version;
45
+ $options['plugin_version'] = AI1WM_VERSION;
46
+ $options['wp_version'] = $wp_version;
47
+ $options['php_version'] = phpversion();
48
+ $options['php_uname'] = php_uname();
49
+ $options['max_execution_time'] = ini_get( 'max_execution_time' );
50
+ $options['memory_limit'] = ini_get( 'memory_limit' );
51
+ $options['memory_get_peak_usage'] = memory_get_peak_usage();
52
+ $options['memory_get_usage'] = memory_get_usage();
53
+ $options['ZipArchive'] = class_exists( 'ZipArchive' ) ? 1 : 0;
54
+ $options['ZLIB_installed'] = function_exists( 'gzopen' ) ? 1 : 0;
55
+ $options['PDO_available'] = class_exists( 'PDO' ) ? 1 : 0;
56
+ $options['home_url'] = home_url();
57
58
+ // Export last options
59
+ update_option( self::EXPORT_LAST_OPTIONS, $options );
60
61
+ // Flush storage directory
62
+ StorageDirectory::flush( AI1WM_STORAGE_PATH, array( '.gitignore' ) );
63
64
+ // Create output file
65
+ $output_file = $storage->makeFile();
66
+
67
+ // Make archive
68
try {
69
+ $archive = ZipFactory::makeZipArchiver( $output_file->getAs( 'resource' ), ! class_exists( 'ZipArchive' ), true );
70
} catch ( Exception $e ) {
71
+ $archive = ZipFactory::makeZipArchiver( $output_file->getAs( 'resource' ), true, true );
72
}
73
74
+ // Should we export database?
75
+ if ( ! isset( $options['export-database'] ) ) {
76
+ // Prepare database file
77
+ $database_file = $this->prepare_database( $storage, $options );
78
79
// Add database to archive
80
+ $archive->addFile(
81
+ $database_file->getAs( 'resource' ),
82
+ self::EXPORT_DATABASE_NAME
83
+ );
84
}
85
86
+ // Should we export media?
87
+ if ( ! isset( $options['export-media'] ) ) {
88
+ $archive->addDir(
89
+ $this->prepare_media( $options ),
90
+ self::EXPORT_MEDIA_NAME
91
+ );
92
+ }
93
94
+ // Should we export themes?
95
+ if ( ! isset( $options['export-themes'] ) ) {
96
+ $archive->addDir(
97
+ $this->prepare_themes( $options ),
98
+ self::EXPORT_THEMES_NAME
99
+ );
100
+ }
101
102
+ // Should we export plugins?
103
+ if ( ! isset( $options['export-plugins'] ) ) {
104
+ if ( ( $include = $this->get_plugins( array( AI1WM_PLUGIN_NAME ) ) ) ) {
105
+ $archive->addDir(
106
+ $this->prepare_plugins( $options ),
107
+ self::EXPORT_PLUGINS_NAME,
108
+ $include
109
+ );
110
}
111
}
112
113
+ // Add package
114
+ $archive->addFromString(
115
+ self::EXPORT_PACKAGE_NAME,
116
+ $this->prepare_package( $options )
117
+ );
118
+
119
+ return $output_file;
120
+ }
121
+
122
+ /**
123
+ * Export database in SQL format
124
+ *
125
+ * @param StorageArea $storage Storage instance
126
+ * @param array $options Export settings
127
+ * @return StorageFile StorageFile instance
128
+ */
129
+ public function prepare_database( StorageArea $storage, array $options = array() ) {
130
+ global $wpdb;
131
+
132
+ $file = new Ai1wm_File;
133
+ $database_file = $storage->makeFile();
134
+
135
+ // Set include tables
136
+ $includeTables = array();
137
+ if ( isset( $options['include-tables'] ) ) {
138
+ $includeTables = $options['include-tables'];
139
+ }
140
+
141
+ // Set exclude tables
142
+ $excludeTables = array();
143
+ if ( isset( $options['exclude-tables' ] ) ) {
144
+ $excludeTables = $options['exclude-tables'];
145
+ }
146
+
147
+ // Set no table data
148
+ $noTableData = false;
149
+ if ( isset( $options['no-table-data'] ) ) {
150
+ $noTableData = true;
151
+ }
152
+
153
+ $clauses = array();
154
+
155
+ // Spam comments
156
+ if ( isset( $options['export-spam-comments'] ) ) {
157
+ $clauses[ $wpdb->comments ] = ' WHERE comment_approved != "spam" ORDER BY comment_ID ';
158
+ $clauses[ $wpdb->commentmeta ] = sprintf(
159
+ ' INNER JOIN `%1$s`
160
+ ON `%1$s`.comment_ID = `%2$s`.comment_id AND `%1$s`.comment_approved != \'spam\'
161
+ ORDER BY `%2$s`.meta_id ', $wpdb->comments, $wpdb->commentmeta
162
+ );
163
+ }
164
+
165
+ // Post revisions
166
+ if ( isset( $options['export-revisions'] ) ) {
167
+ $clauses[ $wpdb->posts ] = ' WHERE post_type != "revision" ORDER BY ID ';
168
+ }
169
+
170
+ // No table data, but leave Administrator account unchanged
171
+ if ( $noTableData ) {
172
+ $clauses = array();
173
+ $clauses[ $wpdb->options ] = ' ORDER BY option_id ASC ';
174
+ $clauses[ $wpdb->users ] = ' WHERE id = 1 ';
175
+ $clauses[ $wpdb->usermeta ] = ' WHERE user_id = 1 ';
176
+ }
177
178
+ // Make connection
179
+ try {
180
+ $db = MysqlDumpFactory::makeMysqlDump(
181
+ DB_HOST,
182
+ DB_USER,
183
+ DB_PASSWORD,
184
+ DB_NAME,
185
+ (
186
+ class_exists(
187
+ 'PDO'
188
+ ) && in_array( 'mysql', PDO::getAvailableDrivers() )
189
+ )
190
+ );
191
+ $db->getConnection();
192
+ } catch ( Exception $e ) {
193
+ // Use "old" mysql adapter
194
+ $db = MysqlDumpFactory::makeMysqlDump( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, false );
195
}
196
197
+ // Set dump options
198
+ $db->setFileName( $database_file->getAs( 'string' ) )
199
+ ->setIncludeTables( $includeTables )
200
+ ->setExcludeTables( $excludeTables )
201
+ ->setNoTableData( $noTableData )
202
+ ->setOldTablePrefix( $wpdb->prefix )
203
+ ->setNewTablePrefix( AI1WM_TABLE_PREFIX )
204
+ ->setQueryClauses( $clauses );
205
+
206
+ // Export database into a file
207
+ $db->export();
208
209
+ // Replace Old/New Values
210
+ if ( isset( $options['replace'] ) && ( $replace = $options['replace'] ) ) {
211
+ $old_values = array();
212
+ $new_values = array();
213
+ for ( $i = 0; $i < count( $replace['old-value'] ); $i++ ) {
214
+ if (
215
+ ! empty( $replace['old-value'][$i] ) &&
216
+ ! empty( $replace['new-value'][$i] ) &&
217
+ $replace['old-value'][$i] != $replace['new-value'][$i]
218
+ ) {
219
+ $old_values[] = $replace['old-value'][$i];
220
+ $new_values[] = $replace['new-value'][$i];
221
+ }
222
+ }
223
+ // Do String Replacement
224
+ if ( $old_values && $new_values ) {
225
+ $database_file = $file->str_replace_file(
226
+ $storage,
227
+ $database_file,
228
+ $old_values,
229
+ $new_values
230
+ );
231
+
232
+ // Do find and replace
233
+ $database_file = $file->preg_replace_file(
234
+ $storage,
235
+ $database_file,
236
+ '/s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");/'
237
+ );
238
}
239
}
240
241
+ return $database_file;
242
+ }
243
244
+ /**
245
+ * Unescape to avoid dump-text issues
246
+ *
247
+ * @param [type] $value [description]
248
+ * @return [type] [description]
249
+ */
250
+ public static function unescape_mysql( $value ) {
251
+ return str_replace(
252
+ array( '\\\\', '\\0', "\\n", "\\r", '\Z', "\'", '\"', ),
253
+ array( '\\', '\0', "\n", "\r", "\x1a", "'", '"', ),
254
+ $value
255
+ );
256
+ }
257
+
258
+ /**
259
+ * Fix strange behaviour if you have escaped quotes in your replacement
260
+ *
261
+ * @param [type] $value [description]
262
+ * @return [type] [description]
263
+ */
264
+ public static function unescape_quotes( $value ) {
265
+ return str_replace( '\"', '"', $value );
266
}
267
268
/**
269
+ * Export media library base directory
270
*
271
+ * @param array $options Export settings
272
+ * @return string Media base directory
273
*/
274
+ public function prepare_media( array $options = array() ) {
275
+ if ( ! isset( $options['export-media'] ) ) {
276
+ $upload_dir = wp_upload_dir();
277
+
278
+ return $upload_dir['basedir'];
279
+ }
280
}
281
282
/**
283
+ * Export themes root directory
284
*
285
+ * @param array $options Export settings
286
+ * @return string Themes root directory
287
*/
288
+ public function prepare_themes( array $options = array() ) {
289
+ if ( ! isset( $options['export-themes'] ) ) {
290
+ $themes_dir = get_theme_root();
291
+
292
+ return $themes_dir;
293
+ }
294
}
295
296
/**
297
+ * Export plugins root directory
298
*
299
+ * @param array $options Export settings
300
+ * @return string Plugins root directory
301
*/
302
+ public function prepare_plugins( array $options = array() ) {
303
+ if ( ! isset( $options['export-plugins'] ) ) {
304
+ return WP_PLUGIN_DIR;
305
+ }
306
}
307
308
/**
309
+ * Export package json file which includes information about installed plugins and etc.
310
*
311
+ * @param array $options Export settings
312
+ * @return string Package config
313
*/
314
+ public function prepare_package( array $options = array() ) {
315
+ $config = array(
316
+ 'Version' => AI1WM_VERSION,
317
+ 'SiteURL' => site_url(),
318
+ 'HomeURL' => home_url(),
319
+ 'Domain' => parse_url( home_url(), PHP_URL_HOST ),
320
+ );
321
+
322
+ return json_encode( $config );
323
}
324
325
/**
326
+ * Get available plugins
327
*
328
+ * @param array $exclude Exclude plugins
329
+ * @return array List of installed plugins
330
*/
331
+ public function get_plugins( $exclude = array() ) {
332
+ if ( ! function_exists( 'get_plugins' ) ) {
333
+ require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
334
+ }
335
+
336
+ $plugins = array();
337
+ foreach ( get_plugins() as $key => $plugin ) {
338
+ $directory = dirname( $key );
339
+ if ( $directory !== '.' && ! in_array( $directory, $exclude ) ) {
340
+ $plugins[] = $directory;
341
+ }
342
+ }
343
+
344
+ return $plugins;
345
}
346
}
lib/model/class-ai1wm-feedback.php CHANGED
@@ -25,22 +25,20 @@
25
26
class Ai1wm_Feedback
27
{
28
/**
29
* Submit customer feedback to ServMask.com
30
*
31
- * @param string $type Feedback Type
32
* @param string $email User E-mail
33
* @param string $message User Message
34
* @param integer $terms User Accept Terms
35
- * @return array
36
*/
37
- public function leave_feedback( $type, $email, $message, $terms ) {
38
$errors = array();
39
40
// Submit feedback to ServMask
41
- if ( empty( $type ) ) {
42
- $errors[] = 'Feedback type is invalid.';
43
- } else if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
44
$errors[] = 'Your email is not valid.';
45
} else if ( empty( $message ) ) {
46
$errors[] = 'Please enter comments in the text area.';
@@ -51,18 +49,18 @@ class Ai1wm_Feedback
51
AI1WM_FEEDBACK_URL,
52
array(
53
'body' => array(
54
- 'type' => $type,
55
'email' => $email,
56
'message' => $message,
57
- 'export_options' => json_encode( get_option( AI1WM_EXPORT_OPTIONS, array() ) ),
58
- 'error_handler' => json_encode( get_option( AI1WM_ERROR_HANDLER, array() ) ),
59
- 'exception_handler' => json_encode( get_option( AI1WM_EXCEPTION_HANDLER, array() ) ),
60
),
61
)
62
);
63
64
if ( is_wp_error( $response ) ) {
65
- $errors[] = 'Something went wrong: ' . $response->get_error_message();
66
}
67
}
68
25
26
class Ai1wm_Feedback
27
{
28
+
29
/**
30
* Submit customer feedback to ServMask.com
31
*
32
* @param string $email User E-mail
33
* @param string $message User Message
34
* @param integer $terms User Accept Terms
35
+ * @return void
36
*/
37
+ public function leave_feedback( $email, $message, $terms ) {
38
$errors = array();
39
40
// Submit feedback to ServMask
41
+ if ( ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
42
$errors[] = 'Your email is not valid.';
43
} else if ( empty( $message ) ) {
44
$errors[] = 'Please enter comments in the text area.';
49
AI1WM_FEEDBACK_URL,
50
array(
51
'body' => array(
52
'email' => $email,
53
'message' => $message,
54
+ 'export_last_options' => json_encode( get_option( Ai1wm_Export::EXPORT_LAST_OPTIONS, array() ) ),
55
+ 'error_handler' => json_encode( get_option( Ai1wm_Error::ERROR_HANDLER, array() ) ),
56
+ 'exception_handler' => json_encode( get_option( Ai1wm_Error::EXCEPTION_HANDLER, array() ) ),
57
),
58
)
59
);
60
61
if ( is_wp_error( $response ) ) {
62
+ $errors[] = 'Something went wrong: ' .
63
+ $response->get_error_message();
64
}
65
}
66
lib/model/class-ai1wm-file.php ADDED
@@ -0,0 +1,123 @@
1
+ <?php
2
+ /**
3
+ * Copyright (C) 2014 ServMask Inc.
4
+ *
5
+ * This program is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ *
18
+ * ███████╗███████╗██████╗ ██╗ ██╗███╗ ███╗ █████╗ ███████╗██╗ ██╗
19
+ * ██╔════╝██╔════╝██╔══██╗██║ ██║████╗ ████║██╔══██╗██╔════╝██║ ██╔╝
20
+ * ███████╗█████╗ ██████╔╝██║ ██║██╔████╔██║███████║███████╗█████╔╝
21
+ * ╚════██║██╔══╝ ██╔══██╗╚██╗ ██╔╝██║╚██╔╝██║██╔══██║╚════██║██╔═██╗
22
+ * ███████║███████╗██║ ██║ ╚████╔╝ ██║ ╚═╝ ██║██║ ██║███████║██║ ██╗
23
+ * ╚══════╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝
24
+ */
25
+
26
+ class Ai1wm_File
27
+ {
28
+
29
+ /**
30
+ * Replace a file, line by line with the str pattern and then writes the
31
+ * output to a new file.
32
+ *
33
+ * @param StorageArea $storage Storage instance
34
+ * @param StorageFile $file StorageFile instance
35
+ * @param mixed $pattern Find and replace pattern
36
+ * @param mixed $replacement Replace term
37
+ * @return StorageFile StorageFile instance
38
+ */
39
+ public function str_replace_file( StorageArea $storage, StorageFile $file, $pattern, $replacement ) {
40
+ $new_file = $storage->makeFile();
41
+ $current_file = $file->getAs( 'resource' );
42
+
43
+ while ( ! feof( $current_file ) ) {
44
+ $line = stream_get_line( $current_file, 1000000, "\n" );
45
+
46
+ // Append new line at the end of the line
47
+ if ( strlen( $line ) < 1000000 && ! feof( $current_file ) ) {
48
+ $line .= "\n";
49
+ }
50
+
51
+ if ( false === fwrite( $new_file->getAs( 'resource' ), str_replace( $pattern, $replacement, $line ) ) ) {
52
+ wp_die(
53
+ 'Writting to a file failed! Probably, there is no more free space left?',
54
+ 'Out of disk space'
55
+ );
56
+ }
57
+ }
58
+
59
+ return $new_file;
60
+ }
61
+
62
+ /**
63
+ * Replace a file, line by line with the regex pattern and then writes the
64
+ * output to a new file.
65
+ *
66
+ * @param StorageArea $storage Storage instance
67
+ * @param StorageFile $file StorageFile instance
68
+ * @param string $pattern Find and replace pattern
69
+ * @return StorageFile StorageFile instance
70
+ */
71
+ public function preg_replace_file( StorageArea $storage, StorageFile $file, $pattern ) {
72
+ $new_file = $storage->makeFile();
73
+ $current_file = $file->getAs( 'resource' );
74
+
75
+ // Set file handle to the beginning of the file
76
+ rewind( $current_file );
77
+
78
+ while ( ! feof( $current_file ) ) {
79
+ $line = stream_get_line( $current_file, 1000000, "\n" );
80
+
81
+ // Append new line at the end of the line
82
+ if ( strlen( $line ) < 1000000 && ! feof( $current_file ) ) {
83
+ $line .= "\n";
84
+ }
85
+
86
+ $replaced = $this->_preg_replace( $line, $pattern );
87
+ if ( false === fwrite( $new_file->getAs( 'resource' ), $replaced ) ) {
88
+ wp_die(
89
+ 'Writting to a file failed! Probably, there is no more free space left?',
90
+ 'Out of disk space'
91
+ );
92
+ }
93
+ }
94
+
95
+ return $new_file;
96
+ }
97
+
98
+ /**
99
+ * Find and replace line by line with pattern
100
+ *
101
+ * @param string $line Line to replace
102
+ * @param string $pattern Pattern
103
+ * @return string New line
104
+ */
105
+ public function _preg_replace( $line, $pattern ) {
106
+ // PHP doesn't garbage collect functions created by create_function()
107
+ static $callback = null;
108
+
109
+ if ( $callback === null ) {
110
+ $callback = create_function(
111
+ '$matches',
112
+ "return isset(\$matches[3]) ? 's:' .
113
+ strlen( Ai1wm_Export::unescape_mysql( \$matches[3] ) ) .
114
+ ':\"'.
115
+ Ai1wm_Export::unescape_quotes( \$matches[3] ) .
116
+ '\";' : \$matches[0];
117
+ "
118
+ );
119
+ }
120
+
121
+ return preg_replace_callback( $pattern, $callback, $line );
122
+ }
123
+ }
lib/model/class-ai1wm-import.php CHANGED
@@ -25,180 +25,339 @@
25
26
class Ai1wm_Import
27
{
28
- protected $options = array();
29
-
30
- public function __construct( array $options = array() ) {
31
- $this->options = $options;
32
- }
33
34
/**
35
- * Import site
36
*
37
- * @return StorageFile
38
*/
39
- public function import() {
40
- global $wp_version;
41
42
- $storage = StorageArea::getInstance();
43
44
- // Create import file
45
- $import_file = $storage->makeFile( $this->options['import']['file'] );
46
47
- // Extract archive
48
- try {
49
- try {
50
- $zip = ZipFactory::makeZipArchiver( $import_file->getName(), ! class_exists( 'ZipArchive' ) );
51
- $zip->extractTo( $storage->getRootPath() );
52
- $zip->close();
53
} catch ( Exception $e ) {
54
- $zip = ZipFactory::makeZipArchiver( $import_file->getName(), true );
55
- $zip->extractTo( $storage->getRootPath() );
56
- $zip->close();
57
}
58
- } catch ( Exception $e ) {
59
- throw new Ai1wm_Import_Exception(
60
- _(
61
- 'Site could not be imported!<br />' .
62
- 'Archive file is broken or is not compatible with the plugin! Please verify your archive file.'
63
- )
64
- );
65
- }
66
67
- // Verify package
68
- if ( $this->should_import_package() ) {
69
70
- // Enable maintenance mode
71
- Ai1wm_Maintenance::enable();
72
73
- // Database
74
- if ( $this->should_import_database() ) {
75
- $service = new Ai1wm_Service_Database( $this->options );
76
- $service->import();
77
- }
78
79
- // Media
80
- if ( $this->should_import_media() ) {
81
- $service = new Ai1wm_Service_Media( $this->options );
82
- $service->import();
83
- }
84
85
- // Sites (Network mode)
86
- if ( $this->should_import_sites() ) {
87
- $service = new Ai1wm_Service_Sites( $this->options );
88
- $service->import();
89
- }
90
91
- // Themes
92
- if ( $this->should_import_themes() ) {
93
- $service = new Ai1wm_Service_Themes( $this->options );
94
- $service->import();
95
- }
96
97
- // Plugins
98
- if ( $this->should_import_plugins() ) {
99
- $service = new Ai1wm_Service_Plugins( $this->options );
100
- $service->import();
101
- }
102
103
- // Disable maintenance mode
104
- Ai1wm_Maintenance::disable();
105
106
- } else {
107
- throw new Ai1wm_Import_Exception(
108
- _(
109
- 'Site could not be imported!<br />' .
110
- 'Archive file is not compatible with the plugin! Please verify your archive file.'
111
- )
112
- );
113
- }
114
115
- return $import_file;
116
- }
117
118
- /**
119
- * Should import package?
120
- *
121
- * @return boolean
122
- */
123
- public function should_import_package() {
124
- global $wp_version;
125
126
- // Has package.json file?
127
- if ( ! is_file( StorageArea::getInstance()->getRootPath() . AI1WM_PACKAGE_NAME ) ) {
128
- return false;
129
- }
130
131
- // Force import
132
- if ( isset( $this->options['import']['force'] ) ) {
133
- return true;
134
- }
135
136
- // Get configuration
137
- $service = new Ai1wm_Service_Package( $this->options );
138
- $config = $service->import();
139
140
- // Verify WordPress version
141
- if ( version_compare( $config['WordPress']['Version'], $wp_version, '<=' ) ) {
142
- return true;
143
} else {
144
- throw new Ai1wm_Import_Exception(
145
- sprintf(
146
- _(
147
- 'You are trying to import data from WordPress v%1$s into WordPress v%2$s, while the process might work,' .
148
- 'we do not recommend this. You should update your WordPress to version %1$s or above and then import the file.' .
149
- 'If you still want to proceed, after making a backup, using the plugin,' .
150
- '<button type="button" class="ai1wm-button-green-small" id="ai1wm-force-import" data-name="%3$s">CLICK HERE TO CONTINUE</button>'
151
- ),
152
- $config['WordPress']['Version'],
153
- $wp_version,
154
- $this->options['import']['file']
155
- )
156
- );
157
}
158
- }
159
160
- /**
161
- * Should import database?
162
- *
163
- * @return boolean
164
- */
165
- public function should_import_database() {
166
- return is_file( StorageArea::getInstance()->getRootPath() . AI1WM_DATABASE_NAME );
167
}
168
169
/**
170
- * Should import media?
171
*
172
- * @return boolean
173
*/
174
- public function should_import_media() {
175
- return is_dir( StorageArea::getInstance()->getRootPath() . AI1WM_MEDIA_NAME );
176
}
177
178
/**
179
- * Should import sites?
180
*
181
- * @return boolean
182
*/
183
- public function should_import_sites() {
184
- return is_dir( StorageArea::getInstance()->getRootPath() . AI1WM_SITES_NAME );
185
}
186
187
/**
188
- * Should import themes?
189
*
190
- * @return boolean
191
*/
192
- public function should_import_themes() {
193
- return is_dir( StorageArea::getInstance()->getRootPath() . AI1WM_THEMES_NAME );
194
}
195
196
/**
197
- * Should import plugins?
198
*
199
- * @return boolean
200
*/
201
- public function should_import_plugins() {
202
- return is_dir( StorageArea::getInstance()->getRootPath() . AI1WM_PLUGINS_NAME );
203
}
204
}
25
26
class Ai1wm_Import
27
{
28
+ const MAX_FILE_SIZE = '512MB';
29
+ const MAX_CHUNK_SIZE = '500KB';
30
+ const MAX_CHUNK_RETRIES = 100;
31
+ const MAINTENANCE_MODE = 'ai1wm_maintenance_mode';
32
33
/**
34
+ * Import archive file (database, media, package.json)
35
*
36
+ * @param array $input_file Upload file parameters
37
+ * @param array $options Additional upload settings
38
+ * @return array List of messages
39
*/
40
+ public function import( $input_file, $options = array() ) {
41
+ global $wpdb;
42
+ $errors = array();
43
44
+ if ( empty( $input_file['error'] ) ) {
45
+ try {
46
+ $storage = new StorageArea;
47
48
+ // Flush storage directory
49
+ if ( $options['chunk'] === 0 ) {
50
+ StorageDirectory::flush( AI1WM_STORAGE_PATH, array( '.gitignore' ) );
51
+ }
52
53
+ // Partial file path
54
+ $upload_file = $storage->makeFile( $options['name'] )->getAs( 'string' );
55
+
56
+ // Open partial file
57
+ $out = fopen( $upload_file, $options['chunk'] == 0 ? 'wb' : 'ab' );
58
+ if ( $out ) {
59
+ // Read binary input stream and append it to temp file
60
+ $in = fopen( $input_file['tmp_name'], 'rb' );
61
+ if ( $in ) {
62
+ while ( $buff = fread( $in, 4096 ) ) {
63
+ fwrite( $out, $buff );
64
+ }
65
+ }
66
+
67
+ fclose( $in );
68
+ fclose( $out );
69
+
70
+ // Remove temporary uploaded file
71
+ unlink( $input_file['tmp_name'] );
72
+ } else {
73
+ $errors[] = sprintf(
74
+ _(
75
+ 'Site could not be imported!<br />
76
+ Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
77
+ ),
78
+ AI1WM_STORAGE_PATH
79
+ );
80
+
81
+ // Clear storage
82
+ $storage->flush();
83
+ }
84
} catch ( Exception $e ) {
85
+ $errors[] = sprintf(
86
+ _(
87
+ 'Site could not be imported!<br />
88
+ Please make sure that storage directory <strong>%s</strong> has read and write permissions.'
89
+ ),
90
+ AI1WM_STORAGE_PATH
91
+ );
92
+
93
+ // Clear storage
94
+ $storage->flush();
95
}
96
97
+ // Check if file has been uploaded
98
+ if ( empty( $errors ) && ( ! $options['chunks'] || $options['chunk'] == $options['chunks'] - 1 ) ) {
99
+ // Create temporary directory
100
+ $extract_to = $storage->makeDirectory()->getAs( 'string' );
101
102
+ // Extract archive to a temporary directory
103
+ try {
104
+ try {
105
+ $archive = ZipFactory::makeZipArchiver( $upload_file, ! class_exists( 'ZipArchive' ) );
106
+ $archive->extractTo( $extract_to );
107
+ $archive->close();
108
+ } catch ( Exception $e ) {
109
+ $archive = ZipFactory::makeZipArchiver( $upload_file, true );
110
+ $archive->extractTo( $extract_to );
111
+ $archive->close();
112
+ }
113
+ } catch ( Exception $e ) {
114
+ $errors[] = _(
115
+ 'Archive file is broken or is not compatible with
116
+ "All In One WP Migration" plugin! Please verify your archive file.'
117
+ );
118
+ }
119
120
+ if ( empty( $errors ) ) {
121
+ // Verify whether this archive is valid
122
+ if ( $this->is_valid( $extract_to ) ) {
123
+ // Enable maintenance mode
124
+ $this->maintenance_mode( true );
125
126
+ // Parse package config file
127
+ $config = $this->parse_package( $extract_to . Ai1wm_Export::EXPORT_PACKAGE_NAME );
128
129
+ // Database import
130
+ if ( is_file( $extract_to . Ai1wm_Export::EXPORT_DATABASE_NAME ) ) {
131
+ // Backup database
132
+ $model = new Ai1wm_Export;
133
+ $database_file = $model->prepare_database( $storage );
134
135
+ try {
136
+ $db = MysqlDumpFactory::makeMysqlDump(
137
+ DB_HOST,
138
+ DB_USER,
139
+ DB_PASSWORD,
140
+ DB_NAME,
141
+ (
142
+ class_exists(
143
+ 'PDO'
144
+ ) && in_array( 'mysql', PDO::getAvailableDrivers() )
145
+ )
146
+ );
147
+ $db->getConnection();
148
+ } catch ( Exception $e ) {
149
+ // Use "old" mysql adapter
150
+ $db = MysqlDumpFactory::makeMysqlDump( DB_HOST, DB_USER, DB_PASSWORD, DB_NAME, false );
151
+ }
152
153
+ // Flush database
154
+ $db->flush();
155
156
+ $old_values = array();
157
+ $new_values = array();
158
159
+ // Get Site URL
160
+ if ( isset( $config['SiteURL'] ) && ( $config['SiteURL'] != site_url() ) ) {
161
+ $old_values[] = $config['SiteURL'];
162
+ $new_values[] = site_url();
163
+ }
164
165
+ // Get Home URL
166
+ if ( isset( $config['HomeURL'] ) && ( $config['HomeURL'] != home_url() ) ) {
167
+ $old_values[] = $config['HomeURL'];
168
+ $new_values[] = home_url();
169
+ }
170
171
+ // Get Domain
172
+ if ( isset( $config['Domain'] ) && ( $config['Domain'] != ( $domain = parse_url( home_url(), PHP_URL_HOST ) ) ) ) {
173
+ $old_values[] = $config['Domain'];
174
+ $new_values[] = $domain;
175
+ }
176
177
+ $file = new Ai1wm_File;
178
+ $database_file = $storage->makeFile( Ai1wm_Export::EXPORT_DATABASE_NAME, $extract_to );
179
180
+ // Replace Old/New Values
181
+ if ( $old_values && $new_values ) {
182
+ $database_file = $file->str_replace_file(
183
+ $storage,
184
+ $database_file,
185
+ $old_values,
186
+ $new_values
187
+ );
188
+
189
+ $database_file = $file->preg_replace_file(
190
+ $storage,
191
+ $database_file,
192
+ '/s:(\d+):([\\\\]?"[\\\\]?"|[\\\\]?"((.*?)[^\\\\])[\\\\]?");/'
193
+ );
194
+ }
195
+
196
+ // Import database
197
+ $db->setOldTablePrefix( AI1WM_TABLE_PREFIX )
198
+ ->setNewTablePrefix( $wpdb->prefix )
199
+ ->import( $database_file->getAs( 'string' ) );
200
+ }
201
+
202
+ // Media import
203
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME ) ) {
204
+ // Media base directory
205
+ $upload_dir = wp_upload_dir();
206
+ $upload_basedir = $upload_dir['basedir'] . DIRECTORY_SEPARATOR;
207
+ if ( ! is_dir( $upload_basedir ) ) {
208
+ mkdir( $upload_basedir );
209
+ }
210
+
211
+ // Backup media files
212
+ $backup_media_to = $storage->makeDirectory()->getAs( 'string' );
213
+
214
+ StorageDirectory::copy( $upload_basedir, $backup_media_to );
215
+
216
+ // Flush media files
217
+ StorageDirectory::flush( $upload_basedir );
218
+
219
+ // Import media files
220
+ StorageDirectory::copy( $extract_to . Ai1wm_Export::EXPORT_MEDIA_NAME, $upload_basedir );
221
+ }
222
223
+ // Themes import
224
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME ) ) {
225
+ // Themes base directory
226
+ $themes_dir = get_theme_root();
227
+ $themes_basedir = $themes_dir . DIRECTORY_SEPARATOR;
228
+ if ( ! is_dir( $themes_basedir ) ) {
229
+ mkdir( $themes_basedir );
230
+ }
231
232
+ // Backup themes files
233
+ $backup_themes_to = $storage->makeDirectory()->getAs( 'string' );
234
+
235
+ StorageDirectory::copy( $themes_basedir, $backup_themes_to );
236
+
237
+ // Flush themes files
238
+ StorageDirectory::flush( $themes_basedir );
239
+
240
+ // Import themes files
241
+ StorageDirectory::copy( $extract_to . Ai1wm_Export::EXPORT_THEMES_NAME, $themes_basedir );
242
+ }
243
+
244
+ // Plugins import
245
+ if ( is_dir( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME ) ) {
246
+ // Backup plugin files
247
+ $backup_plugins_to = $storage->makeDirectory()->getAs( 'string' );
248
+
249
+ StorageDirectory::copy( WP_PLUGIN_DIR, $backup_plugins_to, array( AI1WM_PLUGIN_NAME ) );
250
+
251
+ // Flush plugin files
252
+ StorageDirectory::flush( WP_PLUGIN_DIR, array( AI1WM_PLUGIN_NAME ) );
253
+
254
+ // Import plugin files
255
+ StorageDirectory::copy( $extract_to . Ai1wm_Export::EXPORT_PLUGINS_NAME, WP_PLUGIN_DIR );
256
+ }
257
+
258
+ // Disable maintenance mode
259
+ $this->maintenance_mode( false );
260
+ } else {
261
+ $errors[] = _( 'File is not compatible with "All In One WP Migration" plugin! Please verify your archive file.' );
262
+ }
263
+ }
264
+
265
+ // Clear storage
266
+ $storage->flush();
267
+ }
268
} else {
269
+ $errors[] = $this->code_to_message( $input_file['error'] );
270
}
271
272
+ return array( 'errors' => $errors );
273
}
274
275
+
276
/**
277
+ * Enable or disable WordPress maintenance mode
278
*
279
+ * @param boolean $enabled Enable or disable maintenance mode
280
+ * @return boolean True if option value has changed, false if not or if update failed
281
*/
282
+ public function maintenance_mode( $enabled = true ) {
283
+ return update_option( self::MAINTENANCE_MODE, $enabled );
284
}
285
286
/**
287
+ * Verify whether directory contains necessary archive files
288
*
289
+ * @param string $path Archive path
290
+ * @return boolean Compatible archive
291
*/
292
+ public function is_valid( $path ) {
293
+ $required_objects = array(
294
+ Ai1wm_Export::EXPORT_PACKAGE_NAME,
295
+ );
296
+
297
+ // Verify whether file or directory exist
298
+ foreach ( $required_objects as $object ) {
299
+ if ( ! file_exists( $path . $object ) ) {
300
+ return false;
301
+ }
302
+ }
303
+
304
+ return true;
305
}
306
307
/**
308
+ * Parse package config file
309
*
310
+ * @param string $file Path to package config file
311
+ * @return array Config parameters
312
*/
313
+ public function parse_package( $file ) {
314
+ // Get config file
315
+ $data = file_get_contents( $file );
316
+
317
+ return json_decode( $data, true );
318
}
319
320
/**
321
+ * Display message for upload error code
322
*
323
+ * @param integer $code Upload error code
324
+ * @return string Error message
325
*/
326
+ public function code_to_message( $code ) {
327
+ switch ( $code ) {
328
+ case UPLOAD_ERR_INI_SIZE:
329
+ $message = _( 'The uploaded file exceeds the upload_max_filesize directive in php.ini' );
330
+ break;
331
+
332
+ case UPLOAD_ERR_FORM_SIZE:
333
+ $message = _( 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form' );
334
+ break;
335
+
336
+ case UPLOAD_ERR_PARTIAL:
337
+ $message = _( 'The uploaded file was only partially uploaded' );
338
+ break;
339
+
340
+ case UPLOAD_ERR_NO_FILE:
341
+ $message = _( 'No file was uploaded' );
342
+ break;
343
+
344
+ case UPLOAD_ERR_NO_TMP_DIR:
345
+ $message = _( 'Missing a temporary folder' );
346
+ break;
347
+
348
+ case UPLOAD_ERR_CANT_WRITE:
349
+ $message = _( 'Failed to write file to disk' );
350
+ break;
351
+
352
+ case UPLOAD_ERR_EXTENSION:
353
+ $message = _( 'File upload stopped by extension' );
354
+ break;
355
+
356
+ default:
357
+ $message = _( 'Unknown upload error' );
358
+ break;
359
+ }
360
+
361
+ return $message;
362
}
363
}
lib/model/class-ai1wm-message.php CHANGED
@@ -25,70 +25,38 @@
25
26
class Ai1wm_Message
27
{
28
- protected $messages = array();
29
-
30
- public function __construct() {
31
- $this->messages = array(
32
- 'SiteURLDepricated' => _(
33
- 'Since version 1.8.0, Site URL is deprecated.' .
34
- 'Upon import, the plugin auto-detects Site URL and makes necessary changes to the database.'
35
- ),
36
- );
37
-
38
- // Prepare messages
39
- $msgs = array();
40
- $keys = get_option( AI1WM_MESSAGES );
41
- foreach ( array_keys( $this->messages ) as $key ) {
42
- if ( ! isset( $keys[$key] ) ) {
43
- $msgs[$key] = true;
44
- }
45
- }
46
-
47
- // Update messages
48
- if ( $msgs ) {
49
- update_option( AI1WM_MESSAGES, $msgs );
50
- }
51
- }
52
53
/**
54
- * Get list of all active messages
55
*
56
* @return array
57
*/
58
- public function get_messages() {
59
- $msgs = array();
60
- $keys = get_option( AI1WM_MESSAGES );
61
- foreach ( $keys as $key => $active ) {
62
- if ( isset( $this->messages[$key] ) && $active ) {
63
- $msgs[$key] = $this->messages[$key];
64
- }
65
}
66
67
- return $msgs;
68
}
69
70
/**
71
- * Close message by key
72
*
73
- * @param string $key Message key
74
- * @return array
75
*/
76
- public function close_message( $key ) {
77
- $errors = array();
78
-
79
- $keys = get_option( AI1WM_MESSAGES );
80
- if ( isset( $keys[$key] ) ) {
81
- // Deactivate message from the list
82
- $keys[$key] = false;
83
-
84
- // Update keys
85
- if ( ! update_option( AI1WM_MESSAGES, $keys ) ) {
86
- $errors[] = 'Something went wrong! Please try again later.';
87
- }
88
- } else {
89
- $errors[] = 'Message key does not exist in the list.';
90
}
91
92
- return array( 'errors' => $errors );
93
}
94
}
25
26
class Ai1wm_Message
27
{
28
+ const MESSAGE_INFO = 'info';
29
+ const MESSAGE_INFO_CLOSE = 'ai1wm_message_info_close';
30
31
/**
32
+ * Close message dialog by type
33
*
34
+ * @param string $type Type of message
35
* @return array
36
*/
37
+ public function close_message( $type ) {
38
+ $errors = array();
39
+
40
+ if ( $type == self::MESSAGE_INFO ) {
41
+ update_option( self::MESSAGE_INFO_CLOSE, true );
42
+ } else {
43
+ $errors[] = 'Unregonized message type.';
44
}
45
46
+ return array( 'errors' => $errors );
47
}
48
49
/**
50
+ * Is message dialog closed
51
*
52
+ * @param string $type Type of message
53
+ * @return boolean
54
*/
55
+ public function is_closed( $type ) {
56
+ if ( $type == self::MESSAGE_INFO ) {
57
+ return get_option( self::MESSAGE_INFO_CLOSE );
58
}
59
60
+ return false;
61
}
62
}
lib/model/class-ai1wm-report.php CHANGED
@@ -25,13 +25,14 @@
25
26
class Ai1wm_Report
27
{
28
/**
29
* Submit customer report to ServMask.com
30
*
31
* @param string $email User E-mail
32
* @param string $message User Message
33
* @param integer $terms User Accept Terms
34
- * @return array
35
*/
36
public function report_problem( $email, $message, $terms ) {
37
$errors = array();
@@ -50,15 +51,16 @@ class Ai1wm_Report
50
'body' => array(
51
'email' => $email,
52
'message' => $message,
53
- 'export_options' => json_encode( get_option( AI1WM_EXPORT_OPTIONS, array() ) ),
54
- 'error_handler' => json_encode( get_option( AI1WM_ERROR_HANDLER, array() ) ),
55
- 'exception_handler' => json_encode( get_option( AI1WM_EXCEPTION_HANDLER, array() ) ),
56
),
57
)
58
);
59
60
if ( is_wp_error( $response ) ) {
61
- $errors[] = 'Something went wrong: ' . $response->get_error_message();
62
}
63
}
64
25
26
class Ai1wm_Report
27
{
28
+
29
/**
30
* Submit customer report to ServMask.com
31
*
32
* @param string $email User E-mail
33
* @param string $message User Message
34
* @param integer $terms User Accept Terms
35
+ * @return void
36
*/
37
public function report_problem( $email, $message, $terms ) {
38
$errors = array();
51
'body' => array(
52
'email' => $email,
53
'message' => $message,
54
+ 'export_last_options' => json_encode( get_option( Ai1wm_Export::EXPORT_LAST_OPTIONS, array() ) ),
55
+ 'error_handler' => json_encode( get_option( Ai1wm_Error::ERROR_HANDLER, array() ) ),
56
+ 'exception_handler' => json_encode( get_option( Ai1wm_Error::EXCEPTION_HANDLER, array() ) ),
57
),
58
)
59
);
60
61
if ( is_wp_error( $response ) ) {
62
+ $errors[] = 'Something went wrong: ' .
63
+ $response->get_error_message();
64
}
65
}
66
lib/model/class-ai1wm-template.php CHANGED
@@ -28,8 +28,8 @@ class Ai1wm_Template extends Bandar
28
/**
29
* Renders a file and returns its contents bacl
30
* @param string $file View to render
31
- * @param array $args Set of arguments
32
- * @return string Rendered view
33
*/
34
public static function render( $view, $args = array() ) {
35
parent::render( $view, $args );
28
/**
29
* Renders a file and returns its contents bacl
30
* @param string $file View to render
31
+ * @param [type] $args [description]
32
+ * @return [type] [description]
33
*/
34
public static function render( $view, $args = array() ) {
35
parent::render( $view, $args );
lib/vendor/bandar/bandar/README.md ADDED
@@ -0,0 +1,100 @@