Version Description
- security improvement
Download this release
Release Info
Developer | soflyy |
Plugin | Import any XML or CSV File to WordPress |
Version | 3.6.8 |
Comparing to | |
See all releases |
Code changes from version 3.6.7 to 3.6.8
- classes/PHPExcel/Settings.php +2 -2
- classes/upload.php +148 -136
- plugin.php +2 -2
- readme.txt +12 -1
classes/PHPExcel/Settings.php
CHANGED
@@ -362,7 +362,7 @@ class PHPExcel_Settings
|
|
362 |
if (is_null($options) && defined(LIBXML_DTDLOAD)) {
|
363 |
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
|
364 |
}
|
365 |
-
|
366 |
@libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
|
367 |
}
|
368 |
self::$libXmlLoaderOptions = $options;
|
@@ -379,7 +379,7 @@ class PHPExcel_Settings
|
|
379 |
if (is_null(self::$libXmlLoaderOptions) && defined(LIBXML_DTDLOAD)) {
|
380 |
self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
|
381 |
}
|
382 |
-
|
383 |
@libxml_disable_entity_loader(self::$libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
|
384 |
}
|
385 |
return self::$libXmlLoaderOptions;
|
362 |
if (is_null($options) && defined(LIBXML_DTDLOAD)) {
|
363 |
$options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
|
364 |
}
|
365 |
+
if (version_compare(PHP_VERSION, '5.2.11') >= 0 && \LIBXML_VERSION < 20900) {
|
366 |
@libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
|
367 |
}
|
368 |
self::$libXmlLoaderOptions = $options;
|
379 |
if (is_null(self::$libXmlLoaderOptions) && defined(LIBXML_DTDLOAD)) {
|
380 |
self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
|
381 |
}
|
382 |
+
if (version_compare(PHP_VERSION, '5.2.11') >= 0 && \LIBXML_VERSION < 20900) {
|
383 |
@libxml_disable_entity_loader(self::$libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
|
384 |
}
|
385 |
return self::$libXmlLoaderOptions;
|
classes/upload.php
CHANGED
@@ -8,7 +8,7 @@ if ( ! class_exists('PMXI_Upload')){
|
|
8 |
protected $root_element = '';
|
9 |
protected $is_csv = false;
|
10 |
|
11 |
-
protected $uploadsPath;
|
12 |
|
13 |
function __construct( $file, $errors, $targetDir = false ){
|
14 |
|
@@ -43,22 +43,22 @@ if ( ! class_exists('PMXI_Upload')){
|
|
43 |
|
44 |
$this->file = wp_all_import_get_absolute_path($this->file);
|
45 |
|
46 |
-
$templates = false;
|
47 |
|
48 |
-
$bundle = array();
|
49 |
|
50 |
$bundleFiles = array();
|
51 |
|
52 |
$csv_path = '';
|
53 |
|
54 |
if (empty($this->file)) {
|
55 |
-
$this->errors->add('form-validation', __('Please specify a file to import.<br/><br/>If you are uploading the file from your computer, please wait for it to finish uploading (progress bar at 100%), before trying to continue.', 'wp_all_import_plugin'));
|
56 |
} elseif (!is_file($this->file)) {
|
57 |
$this->errors->add('form-validation', __('Uploaded file is empty', 'wp_all_import_plugin'));
|
58 |
} elseif ( ! preg_match('%\W(xml|gzip|zip|csv|tsv|gz|json|txt|dat|psv|sql|xls|xlsx)$%i', trim(basename($this->file)))) {
|
59 |
$this->errors->add('form-validation', __('Uploaded file must be XML, CSV, ZIP, GZIP, GZ, JSON, SQL, TXT, DAT or PSV', 'wp_all_import_plugin'));
|
60 |
} elseif (preg_match('%\W(zip)$%i', trim(basename($this->file)))) {
|
61 |
-
|
62 |
if (!class_exists('PclZip')) {
|
63 |
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
64 |
}
|
@@ -71,6 +71,10 @@ if ( ! class_exists('PMXI_Upload')){
|
|
71 |
$decodedTemplates = array();
|
72 |
if ( ! empty($v_result_list) ) {
|
73 |
foreach ($v_result_list as $unzipped_file) {
|
|
|
|
|
|
|
|
|
74 |
if ($unzipped_file['status'] == 'ok' and preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($unzipped_file['stored_filename'])) and strpos($unzipped_file['stored_filename'], 'readme.txt') === false ) {
|
75 |
if ( strpos(basename($unzipped_file['stored_filename']), 'WP All Import Template') === 0 || strpos(basename($unzipped_file['stored_filename']), 'templates_') === 0 ) {
|
76 |
$templates = file_get_contents($unzipped_file['filename']);
|
@@ -79,10 +83,10 @@ if ( ! class_exists('PMXI_Upload')){
|
|
79 |
if ( ! empty($templateOptions) and isset($templateOptions[0]['_import_type']) and $templateOptions[0]['_import_type'] == 'url' ) {
|
80 |
$options = maybe_unserialize($templateOptions[0]['options']);
|
81 |
return array(
|
82 |
-
'filePath' => $templateOptions[0]['_import_url'],
|
83 |
'bundle' => $bundle,
|
84 |
-
'template' => json_encode($templateOptions),
|
85 |
-
'templates' => $templates,
|
86 |
'post_type' => (!empty($options)) ? $options['custom_type'] : false,
|
87 |
'taxonomy_type' => (!empty($options['taxonomy_type'])) ? $options['taxonomy_type'] : false,
|
88 |
'is_empty_bundle_file' => true
|
@@ -90,7 +94,7 @@ if ( ! class_exists('PMXI_Upload')){
|
|
90 |
}
|
91 |
} else {
|
92 |
if ($filePath == '') {
|
93 |
-
$filePath = $unzipped_file['filename'];
|
94 |
}
|
95 |
if ( ! in_array($unzipped_file['filename'], $bundleFiles) ) {
|
96 |
$bundleFiles[basename($unzipped_file['filename'])] = $unzipped_file['filename'];
|
@@ -108,7 +112,7 @@ if ( ! class_exists('PMXI_Upload')){
|
|
108 |
}
|
109 |
}
|
110 |
if ( ! empty($bundle)) $filePath = current($bundle);
|
111 |
-
}
|
112 |
|
113 |
if ( $this->uploadsPath === false ){
|
114 |
$this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
|
@@ -116,68 +120,70 @@ if ( ! class_exists('PMXI_Upload')){
|
|
116 |
|
117 |
if (empty($filePath)) {
|
118 |
$zip = zip_open(trim($this->file));
|
119 |
-
if (is_resource($zip)) {
|
120 |
while ($zip_entry = zip_read($zip)) {
|
121 |
-
$filePath = zip_entry_name($zip_entry);
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
|
|
|
|
130 |
}
|
131 |
zip_close($zip);
|
132 |
} else {
|
133 |
-
$this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'wp_all_import_plugin'));
|
134 |
-
}
|
135 |
}
|
136 |
-
// Detect if file is very large
|
137 |
$source = array(
|
138 |
'name' => basename($this->file),
|
139 |
-
'type' => 'upload',
|
140 |
-
'path' => $this->file,
|
141 |
);
|
142 |
$fileFormats = $this->get_xml_file( $filePath );
|
143 |
$filePath = $fileFormats['xml'];
|
144 |
$csv_path = $fileFormats['csv'];
|
145 |
}
|
146 |
} elseif ( preg_match('%\W(csv|txt|dat|psv|tsv)$%i', trim($this->file))) { // If CSV file uploaded
|
147 |
-
|
148 |
if ( $this->uploadsPath === false ){
|
149 |
$this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
|
150 |
-
}
|
151 |
$filePath = $this->file;
|
152 |
$source = array(
|
153 |
'name' => basename($this->file),
|
154 |
'type' => 'upload',
|
155 |
'path' => $filePath,
|
156 |
-
);
|
157 |
|
158 |
-
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
159 |
|
160 |
-
$csv = new PMXI_CsvParser( array( 'filename' => $this->file, 'targetDir' => $this->uploadsPath ) );
|
161 |
//@unlink($filePath);
|
162 |
$csv_path = $filePath;
|
163 |
-
$filePath = $csv->xml_path;
|
164 |
$this->is_csv = $csv->is_csv;
|
165 |
-
$this->root_element = 'node';
|
166 |
-
|
167 |
} elseif(preg_match('%\W(gz)$%i', trim($this->file))){ // If gz file uploaded
|
168 |
$fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath);
|
169 |
if ( ! is_wp_error($fileInfo) ){
|
170 |
$filePath = $fileInfo['localPath'];
|
171 |
-
// Detect if file is very large
|
172 |
$source = array(
|
173 |
'name' => basename($this->file),
|
174 |
'type' => 'upload',
|
175 |
-
'path' => $this->file,
|
176 |
);
|
177 |
-
// detect CSV or XML
|
178 |
-
if ( $fileInfo['type'] == 'csv') { // it is CSV file
|
179 |
-
|
180 |
-
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
181 |
$csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targeDir' => $this->uploadsPath ) ); // create chunks
|
182 |
//@unlink($filePath);
|
183 |
$csv_path = $filePath;
|
@@ -189,36 +195,36 @@ if ( ! class_exists('PMXI_Upload')){
|
|
189 |
else $this->errors->add('form-validation', $fileInfo->get_error_message());
|
190 |
} elseif (preg_match('%\W(json)$%i', trim($this->file))){
|
191 |
|
192 |
-
// Detect if file is very large
|
193 |
$source = array(
|
194 |
'name' => basename($this->file),
|
195 |
'type' => 'upload',
|
196 |
-
'path' => $this->file,
|
197 |
);
|
198 |
|
199 |
$json_str = trim(file_get_contents($this->file));
|
200 |
$json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
|
201 |
$is_json = wp_all_import_is_json($json_str);
|
202 |
-
|
203 |
if( is_wp_error($is_json)){
|
204 |
$this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
|
205 |
} else {
|
206 |
$xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
|
207 |
if ( empty($xml_data) ){
|
208 |
-
$this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
|
209 |
} else{
|
210 |
$jsontmpname = $this->uploadsPath .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($this->file))));
|
211 |
//@unlink($this->file);
|
212 |
file_put_contents($jsontmpname, $xml_data);
|
213 |
-
$filePath = $jsontmpname;
|
214 |
-
|
215 |
}
|
216 |
}
|
217 |
} elseif (preg_match('%\W(sql)$%i', trim($this->file))) {
|
218 |
$source = array(
|
219 |
'name' => basename($this->file),
|
220 |
'type' => 'upload',
|
221 |
-
'path' => $this->file,
|
222 |
);
|
223 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
|
224 |
$sql = new PMXI_SQLParser( $this->file, $this->uploadsPath );
|
@@ -227,7 +233,7 @@ if ( ! class_exists('PMXI_Upload')){
|
|
227 |
$source = array(
|
228 |
'name' => basename($this->file),
|
229 |
'type' => 'upload',
|
230 |
-
'path' => $this->file,
|
231 |
);
|
232 |
|
233 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' );
|
@@ -240,21 +246,21 @@ if ( ! class_exists('PMXI_Upload')){
|
|
240 |
'type' => 'upload',
|
241 |
'path' => $filePath,
|
242 |
);
|
243 |
-
}
|
244 |
|
245 |
if ( $this->errors->get_error_codes() ) return $this->errors;
|
246 |
|
247 |
-
$decodedTemplates = empty($templates) ? false : json_decode($templates, true);
|
|
|
|
|
248 |
|
249 |
-
$source['path'] = wp_all_import_get_relative_path($source['path']);
|
250 |
-
|
251 |
$templateOptions = "";
|
252 |
|
253 |
if ( is_array($decodedTemplates) ) {
|
254 |
$templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
|
255 |
-
}
|
256 |
|
257 |
-
$options = (empty($templateOptions[0]['options'])) ? false : maybe_unserialize($templateOptions[0]['options']);
|
258 |
|
259 |
if ( ! empty($options['root_element'])) $this->root_element = $options['root_element'];
|
260 |
|
@@ -278,14 +284,14 @@ if ( ! class_exists('PMXI_Upload')){
|
|
278 |
|
279 |
$templates = false;
|
280 |
|
281 |
-
$bundle = array();
|
282 |
|
283 |
$bundleFiles = array();
|
284 |
|
285 |
if (empty($this->file)) {
|
286 |
-
$this->errors->add('form-validation', __('Please specify a file to import.', 'wp_all_import_plugin'));
|
287 |
} elseif ( ! preg_match('%^https?://%i', $this->file)) {
|
288 |
-
$this->errors->add('form-validation', __('The URL to your file is not valid.<br/><br/>Please make sure the URL starts with http:// or https://. To import from https://, your server must have OpenSSL installed.'), 'wp_all_import_plugin');
|
289 |
} elseif( ! is_writeable($this->uploadsPath)){
|
290 |
$this->errors->add('form-validation', __('Uploads folder '.$this->uploadsPath.' is not writable.'), 'wp_all_import_plugin');
|
291 |
}
|
@@ -298,16 +304,16 @@ if ( ! class_exists('PMXI_Upload')){
|
|
298 |
|
299 |
if( '' == $feed_type and ! preg_match('%\W(xml|csv|zip|gz|xls|xlsx)$%i', trim($this->file))) $feed_type = wp_all_import_get_remote_file_name(trim($this->file));
|
300 |
|
301 |
-
if ('zip' == $feed_type or empty($feed_type) and preg_match('%\W(zip)$%i', trim($this->file))) {
|
302 |
-
|
303 |
$tmpname = $this->uploadsPath . '/' . wp_unique_filename($this->uploadsPath, md5(basename($this->file)) . '.zip');
|
304 |
-
|
305 |
-
@copy($this->file, $tmpname);
|
306 |
-
|
307 |
-
if (!file_exists($tmpname)) {
|
308 |
$request = get_file_curl($this->file, $tmpname);
|
309 |
-
if (is_wp_error($request)) $this->errors->add('form-validation', $request->get_error_message());
|
310 |
-
if (!file_exists($tmpname)) $this->errors->add('form-validation', __('Failed upload ZIP archive', 'wp_all_import_plugin'));
|
311 |
}
|
312 |
|
313 |
if (!class_exists('PclZip')) {
|
@@ -321,19 +327,23 @@ if ( ! class_exists('PMXI_Upload')){
|
|
321 |
$filePath = '';
|
322 |
if (!empty($v_result_list)) {
|
323 |
foreach ($v_result_list as $unzipped_file) {
|
|
|
|
|
|
|
|
|
324 |
if ($unzipped_file['status'] == 'ok' and preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($unzipped_file['stored_filename'])) and strpos($unzipped_file['stored_filename'], 'readme.txt') === false ) {
|
325 |
if ( strpos(basename($unzipped_file['stored_filename']), 'WP All Import Template') === 0 || strpos(basename($unzipped_file['stored_filename']), 'templates_') === 0) {
|
326 |
$templates = file_get_contents($unzipped_file['filename']);
|
327 |
$decodedTemplates = json_decode($templates, true);
|
328 |
-
$templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
|
329 |
}
|
330 |
else {
|
331 |
if ($filePath == '') {
|
332 |
-
$filePath = $unzipped_file['filename'];
|
333 |
}
|
334 |
if ( ! in_array($unzipped_file['filename'], $bundleFiles) ) {
|
335 |
$bundleFiles[basename($unzipped_file['filename'])] = $unzipped_file['filename'];
|
336 |
-
}
|
337 |
}
|
338 |
}
|
339 |
}
|
@@ -347,36 +357,38 @@ if ( ! class_exists('PMXI_Upload')){
|
|
347 |
}
|
348 |
}
|
349 |
if ( ! empty($bundle)) $filePath = current($bundle);
|
350 |
-
}
|
351 |
|
352 |
if($this->uploadsPath === false){
|
353 |
$this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
|
354 |
-
}
|
355 |
|
356 |
-
if(empty($filePath)){
|
357 |
$zip = zip_open(trim($tmpname));
|
358 |
-
if (is_resource($zip)) {
|
359 |
while ($zip_entry = zip_read($zip)) {
|
360 |
-
$filePath = zip_entry_name($zip_entry);
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
|
|
|
|
369 |
}
|
370 |
zip_close($zip);
|
371 |
} else {
|
372 |
-
$this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'wp_all_import_plugin'));
|
373 |
-
}
|
374 |
}
|
375 |
-
// Detect if file is very large
|
376 |
$source = array(
|
377 |
'name' => basename(parse_url($this->file, PHP_URL_PATH)),
|
378 |
'type' => 'url',
|
379 |
-
'path' => $feed_xpath,
|
380 |
);
|
381 |
$fileFormats = $this->get_xml_file( $filePath );
|
382 |
$csv_path = $fileFormats['csv'];
|
@@ -384,20 +396,20 @@ if ( ! class_exists('PMXI_Upload')){
|
|
384 |
}
|
385 |
if (file_exists($tmpname)) wp_all_import_remove_source($tmpname, false);
|
386 |
} elseif ('csv' == $feed_type or '' == $feed_type and preg_match('%\W(csv|txt|dat|psv|tsv)$%i', trim($this->file))) {
|
387 |
-
|
388 |
$source = array(
|
389 |
'name' => basename(parse_url($this->file, PHP_URL_PATH)),
|
390 |
'type' => 'url',
|
391 |
-
'path' => $feed_xpath,
|
392 |
);
|
393 |
// copy remote file in binary mode
|
394 |
$filePath = wp_all_import_get_url($this->file, $this->uploadsPath, 'csv');
|
395 |
if ( ! is_wp_error($filePath) ){
|
396 |
if ( ! file_exists($filePath)) {
|
397 |
-
$this->errors->add('form-validation', __('WP All Import was not able to download your file.<br/><br/>Please make sure the URL to your file is valid.<br/>You can test this by pasting it into your browser.<br/>Other reasons for this error can include some server setting on your host restricting access to this particular URL or external URLs in general, or some setting on the server hosting the file you are trying to access preventing your server from accessing it.', 'wp_all_import_plugin'));
|
398 |
}
|
399 |
-
// Detect if file is very large
|
400 |
-
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
401 |
$csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
|
402 |
//wp_all_import_remove_source($filePath, false);
|
403 |
$csv_path = $filePath;
|
@@ -412,7 +424,7 @@ if ( ! class_exists('PMXI_Upload')){
|
|
412 |
$source = array(
|
413 |
'name' => basename(parse_url($this->file, PHP_URL_PATH)),
|
414 |
'type' => 'url',
|
415 |
-
'path' => $feed_xpath,
|
416 |
);
|
417 |
// copy remote file in binary mode
|
418 |
$filePath = wp_all_import_get_url($this->file, $this->uploadsPath, 'json');
|
@@ -424,98 +436,98 @@ if ( ! class_exists('PMXI_Upload')){
|
|
424 |
} else {
|
425 |
$xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
|
426 |
if ( empty($xml_data) ){
|
427 |
-
$this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
|
428 |
} else {
|
429 |
-
$tmpname = $this->uploadsPath .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
|
430 |
file_put_contents($tmpname, $xml_data);
|
431 |
wp_all_import_remove_source($filePath, false);
|
432 |
-
$filePath = $tmpname;
|
433 |
}
|
434 |
}
|
435 |
} elseif ('sql' == $feed_type or preg_match('%\W(sql)$%i', trim($this->file))){
|
436 |
$source = array(
|
437 |
'name' => basename($this->file),
|
438 |
'type' => 'url',
|
439 |
-
'path' => $feed_xpath,
|
440 |
);
|
441 |
// copy remote file in binary mode
|
442 |
$localSQLPath = wp_all_import_get_url($this->file, $this->uploadsPath, 'sql');
|
443 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
|
444 |
-
$sql = new PMXI_SQLParser( $localSQLPath, $this->uploadsPath );
|
445 |
-
$filePath = $sql->parse();
|
446 |
wp_all_import_remove_source($localSQLPath, false);
|
447 |
} elseif (preg_match('%\W(xls|xlsx)$%i', $feed_type) || preg_match('%\W(xls|xlsx)$%i', strtok(trim($this->file), "?")) || preg_match('%\W(xls|xlsx)$%i', trim($this->file))) {
|
448 |
|
449 |
$source = array(
|
450 |
'name' => basename($this->file),
|
451 |
'type' => 'url',
|
452 |
-
'path' => $feed_xpath,
|
453 |
);
|
454 |
// copy remote file in binary mode
|
455 |
$localXLSPath = wp_all_import_get_url($this->file, $this->uploadsPath, 'xls');
|
456 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' );
|
457 |
-
$xls = new PMXI_XLSParser( $localXLSPath, $this->uploadsPath );
|
458 |
-
$filePath = $xls->parse();
|
459 |
wp_all_import_remove_source($localXLSPath, false);
|
460 |
} else {
|
461 |
if ('gz' == $feed_type or '' == $feed_type and preg_match('%\W(gz|gzip)$%i', trim($this->file))){
|
462 |
-
$fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath);
|
463 |
} else {
|
464 |
$headers = wp_all_import_get_feed_type($this->file);
|
465 |
-
if ($headers['Content-Type'] and in_array($headers['Content-Type'], array('gz', 'gzip')) or $headers['Content-Encoding'] and in_array($headers['Content-Encoding'], array('gz', 'gzip'))){
|
466 |
$fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath, $headers);
|
467 |
} else {
|
468 |
$fileInfo = wp_all_import_get_url($this->file, $this->uploadsPath, $headers['Content-Type'], $headers['Content-Encoding'], true);
|
469 |
-
}
|
470 |
-
}
|
471 |
-
|
472 |
if ( ! is_wp_error($fileInfo) ){
|
473 |
$filePath = $fileInfo['localPath'];
|
474 |
if ( ! file_exists($filePath)) {
|
475 |
-
$this->errors->add('form-validation', __('WP All Import was not able to download your file.<br/><br/>Please make sure the URL to your file is valid.<br/>You can test this by pasting it into your browser.<br/>Other reasons for this error can include some server setting on your host restricting access to this particular URL or external URLs in general, or some setting on the server hosting the file you are trying to access preventing your server from accessing it.', 'wp_all_import_plugin'));
|
476 |
}
|
477 |
-
// Detect if file is very large
|
478 |
$source = array(
|
479 |
'name' => basename(parse_url($this->file, PHP_URL_PATH)),
|
480 |
'type' => 'url',
|
481 |
-
'path' => $feed_xpath,
|
482 |
);
|
483 |
$fileInfo['type'] = apply_filters('wp_all_import_feed_type', $fileInfo['type'], $this->file);
|
484 |
-
// detect CSV or XML
|
485 |
switch ($fileInfo['type']) {
|
486 |
case 'csv':
|
487 |
-
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
488 |
$csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
|
489 |
$csv_path = $filePath;
|
490 |
//wp_all_import_remove_source($filePath, false);
|
491 |
$filePath = $csv->xml_path;
|
492 |
$this->is_csv = $csv->is_csv;
|
493 |
-
$this->root_element = 'node';
|
494 |
break;
|
495 |
case 'json':
|
496 |
$json_str = file_get_contents($filePath);
|
497 |
$json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
|
498 |
$is_json = wp_all_import_is_json($json_str);
|
499 |
-
|
500 |
if( is_wp_error($is_json)){
|
501 |
$this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
|
502 |
} else {
|
503 |
$xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
|
504 |
if ( empty($xml_data) ) {
|
505 |
-
$this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
|
506 |
} else {
|
507 |
-
$tmpname = $this->uploadsPath .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
|
508 |
file_put_contents($tmpname, $xml_data);
|
509 |
wp_all_import_remove_source($filePath, false);
|
510 |
-
$filePath = $tmpname;
|
511 |
}
|
512 |
}
|
513 |
break;
|
514 |
case 'sql':
|
515 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
|
516 |
-
$sql = new PMXI_SQLParser( $filePath, $this->uploadsPath );
|
517 |
$filePath = $sql->parse();
|
518 |
-
break;
|
519 |
default:
|
520 |
# code...
|
521 |
break;
|
@@ -527,15 +539,15 @@ if ( ! class_exists('PMXI_Upload')){
|
|
527 |
|
528 |
if ( $this->errors->get_error_codes() ) return $this->errors;
|
529 |
|
530 |
-
$decodedTemplates = empty($templates) ? json_decode($importTemplate, true) : json_decode($templates, true);
|
531 |
-
|
532 |
$templateOptions = "";
|
533 |
|
534 |
if ( is_array($decodedTemplates) and ! empty($decodedTemplates)) {
|
535 |
$templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
|
536 |
}
|
537 |
|
538 |
-
$options = (empty($templateOptions[0]['options'])) ? false : maybe_unserialize($templateOptions[0]['options']);
|
539 |
|
540 |
if ( ! empty($options['root_element'])) $this->root_element = $options['root_element'];
|
541 |
|
@@ -553,7 +565,7 @@ if ( ! class_exists('PMXI_Upload')){
|
|
553 |
'taxonomy_type' => (!empty($options['taxonomy_type'])) ? $options['taxonomy_type'] : false,
|
554 |
);
|
555 |
}
|
556 |
-
|
557 |
protected function get_xml_file( $filePath )
|
558 |
{
|
559 |
$csv_path = '';
|
@@ -562,35 +574,35 @@ if ( ! class_exists('PMXI_Upload')){
|
|
562 |
|
563 |
if($this->uploadsPath === false){
|
564 |
$this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
|
565 |
-
}
|
566 |
-
|
567 |
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
568 |
$csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
|
569 |
-
|
570 |
$csv_path = $filePath;
|
571 |
|
572 |
$filePath = $csv->xml_path;
|
573 |
$this->is_csv = $csv->is_csv;
|
574 |
-
$this->root_element = 'node';
|
575 |
-
|
576 |
} elseif (preg_match('%\W(json)$%i', trim($filePath))){
|
577 |
|
578 |
$json_str = file_get_contents($filePath);
|
579 |
$json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
|
580 |
$is_json = wp_all_import_is_json($json_str);
|
581 |
-
|
582 |
if( is_wp_error($is_json)){
|
583 |
$this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
|
584 |
}
|
585 |
-
else{
|
586 |
-
|
587 |
$xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
|
588 |
|
589 |
if ( empty($xml_data) ){
|
590 |
-
$this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
|
591 |
}
|
592 |
else{
|
593 |
-
$jsontmpname = $this->uploadsPath .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
|
594 |
file_put_contents($jsontmpname, $xml_data);
|
595 |
wp_all_import_remove_source($filePath, false);
|
596 |
$filePath = $jsontmpname;
|
@@ -600,20 +612,20 @@ if ( ! class_exists('PMXI_Upload')){
|
|
600 |
}
|
601 |
elseif (preg_match('%\W(sql)$%i', trim($filePath))){
|
602 |
|
603 |
-
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
|
604 |
|
605 |
$localSQLPath = $filePath;
|
606 |
$sql = new PMXI_SQLParser( $localSQLPath, $this->uploadsPath );
|
607 |
$filePath = $sql->parse();
|
608 |
wp_all_import_remove_source($localSQLPath, false);
|
609 |
-
}
|
610 |
elseif (preg_match('%\W(xls|xlsx)$%i', trim($filePath))){
|
611 |
|
612 |
-
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' );
|
613 |
|
614 |
-
$localXLSPath = $filePath;
|
615 |
-
$xls = new PMXI_XLSParser( $localXLSPath, $this->uploadsPath );
|
616 |
-
$filePath = $xls->parse();
|
617 |
wp_all_import_remove_source($localXLSPath, false);
|
618 |
|
619 |
}
|
8 |
protected $root_element = '';
|
9 |
protected $is_csv = false;
|
10 |
|
11 |
+
protected $uploadsPath;
|
12 |
|
13 |
function __construct( $file, $errors, $targetDir = false ){
|
14 |
|
43 |
|
44 |
$this->file = wp_all_import_get_absolute_path($this->file);
|
45 |
|
46 |
+
$templates = false;
|
47 |
|
48 |
+
$bundle = array();
|
49 |
|
50 |
$bundleFiles = array();
|
51 |
|
52 |
$csv_path = '';
|
53 |
|
54 |
if (empty($this->file)) {
|
55 |
+
$this->errors->add('form-validation', __('Please specify a file to import.<br/><br/>If you are uploading the file from your computer, please wait for it to finish uploading (progress bar at 100%), before trying to continue.', 'wp_all_import_plugin'));
|
56 |
} elseif (!is_file($this->file)) {
|
57 |
$this->errors->add('form-validation', __('Uploaded file is empty', 'wp_all_import_plugin'));
|
58 |
} elseif ( ! preg_match('%\W(xml|gzip|zip|csv|tsv|gz|json|txt|dat|psv|sql|xls|xlsx)$%i', trim(basename($this->file)))) {
|
59 |
$this->errors->add('form-validation', __('Uploaded file must be XML, CSV, ZIP, GZIP, GZ, JSON, SQL, TXT, DAT or PSV', 'wp_all_import_plugin'));
|
60 |
} elseif (preg_match('%\W(zip)$%i', trim(basename($this->file)))) {
|
61 |
+
|
62 |
if (!class_exists('PclZip')) {
|
63 |
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
64 |
}
|
71 |
$decodedTemplates = array();
|
72 |
if ( ! empty($v_result_list) ) {
|
73 |
foreach ($v_result_list as $unzipped_file) {
|
74 |
+
if ($unzipped_file['status'] == 'ok' and preg_match('%\W(php)$%i', trim($unzipped_file['stored_filename']))) {
|
75 |
+
unlink($unzipped_file['filename']);
|
76 |
+
continue;
|
77 |
+
}
|
78 |
if ($unzipped_file['status'] == 'ok' and preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($unzipped_file['stored_filename'])) and strpos($unzipped_file['stored_filename'], 'readme.txt') === false ) {
|
79 |
if ( strpos(basename($unzipped_file['stored_filename']), 'WP All Import Template') === 0 || strpos(basename($unzipped_file['stored_filename']), 'templates_') === 0 ) {
|
80 |
$templates = file_get_contents($unzipped_file['filename']);
|
83 |
if ( ! empty($templateOptions) and isset($templateOptions[0]['_import_type']) and $templateOptions[0]['_import_type'] == 'url' ) {
|
84 |
$options = maybe_unserialize($templateOptions[0]['options']);
|
85 |
return array(
|
86 |
+
'filePath' => $templateOptions[0]['_import_url'],
|
87 |
'bundle' => $bundle,
|
88 |
+
'template' => json_encode($templateOptions),
|
89 |
+
'templates' => $templates,
|
90 |
'post_type' => (!empty($options)) ? $options['custom_type'] : false,
|
91 |
'taxonomy_type' => (!empty($options['taxonomy_type'])) ? $options['taxonomy_type'] : false,
|
92 |
'is_empty_bundle_file' => true
|
94 |
}
|
95 |
} else {
|
96 |
if ($filePath == '') {
|
97 |
+
$filePath = $unzipped_file['filename'];
|
98 |
}
|
99 |
if ( ! in_array($unzipped_file['filename'], $bundleFiles) ) {
|
100 |
$bundleFiles[basename($unzipped_file['filename'])] = $unzipped_file['filename'];
|
112 |
}
|
113 |
}
|
114 |
if ( ! empty($bundle)) $filePath = current($bundle);
|
115 |
+
}
|
116 |
|
117 |
if ( $this->uploadsPath === false ){
|
118 |
$this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
|
120 |
|
121 |
if (empty($filePath)) {
|
122 |
$zip = zip_open(trim($this->file));
|
123 |
+
if (is_resource($zip)) {
|
124 |
while ($zip_entry = zip_read($zip)) {
|
125 |
+
$filePath = zip_entry_name($zip_entry);
|
126 |
+
if (preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($filePath))) {
|
127 |
+
$fp = fopen($this->uploadsPath."/".$filePath, "w");
|
128 |
+
if (zip_entry_open($zip, $zip_entry, "r")) {
|
129 |
+
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
|
130 |
+
fwrite($fp,"$buf");
|
131 |
+
zip_entry_close($zip_entry);
|
132 |
+
fclose($fp);
|
133 |
+
}
|
134 |
+
break;
|
135 |
+
}
|
136 |
}
|
137 |
zip_close($zip);
|
138 |
} else {
|
139 |
+
$this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'wp_all_import_plugin'));
|
140 |
+
}
|
141 |
}
|
142 |
+
// Detect if file is very large
|
143 |
$source = array(
|
144 |
'name' => basename($this->file),
|
145 |
+
'type' => 'upload',
|
146 |
+
'path' => $this->file,
|
147 |
);
|
148 |
$fileFormats = $this->get_xml_file( $filePath );
|
149 |
$filePath = $fileFormats['xml'];
|
150 |
$csv_path = $fileFormats['csv'];
|
151 |
}
|
152 |
} elseif ( preg_match('%\W(csv|txt|dat|psv|tsv)$%i', trim($this->file))) { // If CSV file uploaded
|
153 |
+
|
154 |
if ( $this->uploadsPath === false ){
|
155 |
$this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
|
156 |
+
}
|
157 |
$filePath = $this->file;
|
158 |
$source = array(
|
159 |
'name' => basename($this->file),
|
160 |
'type' => 'upload',
|
161 |
'path' => $filePath,
|
162 |
+
);
|
163 |
|
164 |
+
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
165 |
|
166 |
+
$csv = new PMXI_CsvParser( array( 'filename' => $this->file, 'targetDir' => $this->uploadsPath ) );
|
167 |
//@unlink($filePath);
|
168 |
$csv_path = $filePath;
|
169 |
+
$filePath = $csv->xml_path;
|
170 |
$this->is_csv = $csv->is_csv;
|
171 |
+
$this->root_element = 'node';
|
172 |
+
|
173 |
} elseif(preg_match('%\W(gz)$%i', trim($this->file))){ // If gz file uploaded
|
174 |
$fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath);
|
175 |
if ( ! is_wp_error($fileInfo) ){
|
176 |
$filePath = $fileInfo['localPath'];
|
177 |
+
// Detect if file is very large
|
178 |
$source = array(
|
179 |
'name' => basename($this->file),
|
180 |
'type' => 'upload',
|
181 |
+
'path' => $this->file,
|
182 |
);
|
183 |
+
// detect CSV or XML
|
184 |
+
if ( $fileInfo['type'] == 'csv') { // it is CSV file
|
185 |
+
|
186 |
+
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
187 |
$csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targeDir' => $this->uploadsPath ) ); // create chunks
|
188 |
//@unlink($filePath);
|
189 |
$csv_path = $filePath;
|
195 |
else $this->errors->add('form-validation', $fileInfo->get_error_message());
|
196 |
} elseif (preg_match('%\W(json)$%i', trim($this->file))){
|
197 |
|
198 |
+
// Detect if file is very large
|
199 |
$source = array(
|
200 |
'name' => basename($this->file),
|
201 |
'type' => 'upload',
|
202 |
+
'path' => $this->file,
|
203 |
);
|
204 |
|
205 |
$json_str = trim(file_get_contents($this->file));
|
206 |
$json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
|
207 |
$is_json = wp_all_import_is_json($json_str);
|
208 |
+
|
209 |
if( is_wp_error($is_json)){
|
210 |
$this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
|
211 |
} else {
|
212 |
$xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
|
213 |
if ( empty($xml_data) ){
|
214 |
+
$this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
|
215 |
} else{
|
216 |
$jsontmpname = $this->uploadsPath .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($this->file))));
|
217 |
//@unlink($this->file);
|
218 |
file_put_contents($jsontmpname, $xml_data);
|
219 |
+
$filePath = $jsontmpname;
|
220 |
+
|
221 |
}
|
222 |
}
|
223 |
} elseif (preg_match('%\W(sql)$%i', trim($this->file))) {
|
224 |
$source = array(
|
225 |
'name' => basename($this->file),
|
226 |
'type' => 'upload',
|
227 |
+
'path' => $this->file,
|
228 |
);
|
229 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
|
230 |
$sql = new PMXI_SQLParser( $this->file, $this->uploadsPath );
|
233 |
$source = array(
|
234 |
'name' => basename($this->file),
|
235 |
'type' => 'upload',
|
236 |
+
'path' => $this->file,
|
237 |
);
|
238 |
|
239 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' );
|
246 |
'type' => 'upload',
|
247 |
'path' => $filePath,
|
248 |
);
|
249 |
+
}
|
250 |
|
251 |
if ( $this->errors->get_error_codes() ) return $this->errors;
|
252 |
|
253 |
+
$decodedTemplates = empty($templates) ? false : json_decode($templates, true);
|
254 |
+
|
255 |
+
$source['path'] = wp_all_import_get_relative_path($source['path']);
|
256 |
|
|
|
|
|
257 |
$templateOptions = "";
|
258 |
|
259 |
if ( is_array($decodedTemplates) ) {
|
260 |
$templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
|
261 |
+
}
|
262 |
|
263 |
+
$options = (empty($templateOptions[0]['options'])) ? false : maybe_unserialize($templateOptions[0]['options']);
|
264 |
|
265 |
if ( ! empty($options['root_element'])) $this->root_element = $options['root_element'];
|
266 |
|
284 |
|
285 |
$templates = false;
|
286 |
|
287 |
+
$bundle = array();
|
288 |
|
289 |
$bundleFiles = array();
|
290 |
|
291 |
if (empty($this->file)) {
|
292 |
+
$this->errors->add('form-validation', __('Please specify a file to import.', 'wp_all_import_plugin'));
|
293 |
} elseif ( ! preg_match('%^https?://%i', $this->file)) {
|
294 |
+
$this->errors->add('form-validation', __('The URL to your file is not valid.<br/><br/>Please make sure the URL starts with http:// or https://. To import from https://, your server must have OpenSSL installed.'), 'wp_all_import_plugin');
|
295 |
} elseif( ! is_writeable($this->uploadsPath)){
|
296 |
$this->errors->add('form-validation', __('Uploads folder '.$this->uploadsPath.' is not writable.'), 'wp_all_import_plugin');
|
297 |
}
|
304 |
|
305 |
if( '' == $feed_type and ! preg_match('%\W(xml|csv|zip|gz|xls|xlsx)$%i', trim($this->file))) $feed_type = wp_all_import_get_remote_file_name(trim($this->file));
|
306 |
|
307 |
+
if ('zip' == $feed_type or empty($feed_type) and preg_match('%\W(zip)$%i', trim($this->file))) {
|
308 |
+
|
309 |
$tmpname = $this->uploadsPath . '/' . wp_unique_filename($this->uploadsPath, md5(basename($this->file)) . '.zip');
|
310 |
+
|
311 |
+
@copy($this->file, $tmpname);
|
312 |
+
|
313 |
+
if (!file_exists($tmpname)) {
|
314 |
$request = get_file_curl($this->file, $tmpname);
|
315 |
+
if (is_wp_error($request)) $this->errors->add('form-validation', $request->get_error_message());
|
316 |
+
if (!file_exists($tmpname)) $this->errors->add('form-validation', __('Failed upload ZIP archive', 'wp_all_import_plugin'));
|
317 |
}
|
318 |
|
319 |
if (!class_exists('PclZip')) {
|
327 |
$filePath = '';
|
328 |
if (!empty($v_result_list)) {
|
329 |
foreach ($v_result_list as $unzipped_file) {
|
330 |
+
if ($unzipped_file['status'] == 'ok' and preg_match('%\W(php)$%i', trim($unzipped_file['stored_filename']))) {
|
331 |
+
unlink($unzipped_file['filename']);
|
332 |
+
continue;
|
333 |
+
}
|
334 |
if ($unzipped_file['status'] == 'ok' and preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($unzipped_file['stored_filename'])) and strpos($unzipped_file['stored_filename'], 'readme.txt') === false ) {
|
335 |
if ( strpos(basename($unzipped_file['stored_filename']), 'WP All Import Template') === 0 || strpos(basename($unzipped_file['stored_filename']), 'templates_') === 0) {
|
336 |
$templates = file_get_contents($unzipped_file['filename']);
|
337 |
$decodedTemplates = json_decode($templates, true);
|
338 |
+
$templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
|
339 |
}
|
340 |
else {
|
341 |
if ($filePath == '') {
|
342 |
+
$filePath = $unzipped_file['filename'];
|
343 |
}
|
344 |
if ( ! in_array($unzipped_file['filename'], $bundleFiles) ) {
|
345 |
$bundleFiles[basename($unzipped_file['filename'])] = $unzipped_file['filename'];
|
346 |
+
}
|
347 |
}
|
348 |
}
|
349 |
}
|
357 |
}
|
358 |
}
|
359 |
if ( ! empty($bundle)) $filePath = current($bundle);
|
360 |
+
}
|
361 |
|
362 |
if($this->uploadsPath === false){
|
363 |
$this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
|
364 |
+
}
|
365 |
|
366 |
+
if(empty($filePath)){
|
367 |
$zip = zip_open(trim($tmpname));
|
368 |
+
if (is_resource($zip)) {
|
369 |
while ($zip_entry = zip_read($zip)) {
|
370 |
+
$filePath = zip_entry_name($zip_entry);
|
371 |
+
if (preg_match('%\W(xml|csv|txt|dat|psv|json|xls|xlsx|gz)$%i', trim($filePath))) {
|
372 |
+
$fp = fopen($this->uploadsPath . "/" . $filePath, "w");
|
373 |
+
if (zip_entry_open($zip, $zip_entry, "r")) {
|
374 |
+
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
|
375 |
+
fwrite($fp, "$buf");
|
376 |
+
zip_entry_close($zip_entry);
|
377 |
+
fclose($fp);
|
378 |
+
}
|
379 |
+
break;
|
380 |
+
}
|
381 |
}
|
382 |
zip_close($zip);
|
383 |
} else {
|
384 |
+
$this->errors->add('form-validation', __('WP All Import couldn\'t find a file to import inside your ZIP.<br/><br/>Either the .ZIP file is broken, or doesn\'t contain a file with an extension of XML, CSV, PSV, DAT, or TXT. <br/>Please attempt to unzip your .ZIP file on your computer to ensure it is a valid .ZIP file which can actually be unzipped, and that it contains a file which WP All Import can import.', 'wp_all_import_plugin'));
|
385 |
+
}
|
386 |
}
|
387 |
+
// Detect if file is very large
|
388 |
$source = array(
|
389 |
'name' => basename(parse_url($this->file, PHP_URL_PATH)),
|
390 |
'type' => 'url',
|
391 |
+
'path' => $feed_xpath,
|
392 |
);
|
393 |
$fileFormats = $this->get_xml_file( $filePath );
|
394 |
$csv_path = $fileFormats['csv'];
|
396 |
}
|
397 |
if (file_exists($tmpname)) wp_all_import_remove_source($tmpname, false);
|
398 |
} elseif ('csv' == $feed_type or '' == $feed_type and preg_match('%\W(csv|txt|dat|psv|tsv)$%i', trim($this->file))) {
|
399 |
+
|
400 |
$source = array(
|
401 |
'name' => basename(parse_url($this->file, PHP_URL_PATH)),
|
402 |
'type' => 'url',
|
403 |
+
'path' => $feed_xpath,
|
404 |
);
|
405 |
// copy remote file in binary mode
|
406 |
$filePath = wp_all_import_get_url($this->file, $this->uploadsPath, 'csv');
|
407 |
if ( ! is_wp_error($filePath) ){
|
408 |
if ( ! file_exists($filePath)) {
|
409 |
+
$this->errors->add('form-validation', __('WP All Import was not able to download your file.<br/><br/>Please make sure the URL to your file is valid.<br/>You can test this by pasting it into your browser.<br/>Other reasons for this error can include some server setting on your host restricting access to this particular URL or external URLs in general, or some setting on the server hosting the file you are trying to access preventing your server from accessing it.', 'wp_all_import_plugin'));
|
410 |
}
|
411 |
+
// Detect if file is very large
|
412 |
+
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
413 |
$csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
|
414 |
//wp_all_import_remove_source($filePath, false);
|
415 |
$csv_path = $filePath;
|
424 |
$source = array(
|
425 |
'name' => basename(parse_url($this->file, PHP_URL_PATH)),
|
426 |
'type' => 'url',
|
427 |
+
'path' => $feed_xpath,
|
428 |
);
|
429 |
// copy remote file in binary mode
|
430 |
$filePath = wp_all_import_get_url($this->file, $this->uploadsPath, 'json');
|
436 |
} else {
|
437 |
$xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
|
438 |
if ( empty($xml_data) ){
|
439 |
+
$this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
|
440 |
} else {
|
441 |
+
$tmpname = $this->uploadsPath .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
|
442 |
file_put_contents($tmpname, $xml_data);
|
443 |
wp_all_import_remove_source($filePath, false);
|
444 |
+
$filePath = $tmpname;
|
445 |
}
|
446 |
}
|
447 |
} elseif ('sql' == $feed_type or preg_match('%\W(sql)$%i', trim($this->file))){
|
448 |
$source = array(
|
449 |
'name' => basename($this->file),
|
450 |
'type' => 'url',
|
451 |
+
'path' => $feed_xpath,
|
452 |
);
|
453 |
// copy remote file in binary mode
|
454 |
$localSQLPath = wp_all_import_get_url($this->file, $this->uploadsPath, 'sql');
|
455 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
|
456 |
+
$sql = new PMXI_SQLParser( $localSQLPath, $this->uploadsPath );
|
457 |
+
$filePath = $sql->parse();
|
458 |
wp_all_import_remove_source($localSQLPath, false);
|
459 |
} elseif (preg_match('%\W(xls|xlsx)$%i', $feed_type) || preg_match('%\W(xls|xlsx)$%i', strtok(trim($this->file), "?")) || preg_match('%\W(xls|xlsx)$%i', trim($this->file))) {
|
460 |
|
461 |
$source = array(
|
462 |
'name' => basename($this->file),
|
463 |
'type' => 'url',
|
464 |
+
'path' => $feed_xpath,
|
465 |
);
|
466 |
// copy remote file in binary mode
|
467 |
$localXLSPath = wp_all_import_get_url($this->file, $this->uploadsPath, 'xls');
|
468 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' );
|
469 |
+
$xls = new PMXI_XLSParser( $localXLSPath, $this->uploadsPath );
|
470 |
+
$filePath = $xls->parse();
|
471 |
wp_all_import_remove_source($localXLSPath, false);
|
472 |
} else {
|
473 |
if ('gz' == $feed_type or '' == $feed_type and preg_match('%\W(gz|gzip)$%i', trim($this->file))){
|
474 |
+
$fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath);
|
475 |
} else {
|
476 |
$headers = wp_all_import_get_feed_type($this->file);
|
477 |
+
if ($headers['Content-Type'] and in_array($headers['Content-Type'], array('gz', 'gzip')) or $headers['Content-Encoding'] and in_array($headers['Content-Encoding'], array('gz', 'gzip'))){
|
478 |
$fileInfo = wp_all_import_get_gz($this->file, 0, $this->uploadsPath, $headers);
|
479 |
} else {
|
480 |
$fileInfo = wp_all_import_get_url($this->file, $this->uploadsPath, $headers['Content-Type'], $headers['Content-Encoding'], true);
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
if ( ! is_wp_error($fileInfo) ){
|
485 |
$filePath = $fileInfo['localPath'];
|
486 |
if ( ! file_exists($filePath)) {
|
487 |
+
$this->errors->add('form-validation', __('WP All Import was not able to download your file.<br/><br/>Please make sure the URL to your file is valid.<br/>You can test this by pasting it into your browser.<br/>Other reasons for this error can include some server setting on your host restricting access to this particular URL or external URLs in general, or some setting on the server hosting the file you are trying to access preventing your server from accessing it.', 'wp_all_import_plugin'));
|
488 |
}
|
489 |
+
// Detect if file is very large
|
490 |
$source = array(
|
491 |
'name' => basename(parse_url($this->file, PHP_URL_PATH)),
|
492 |
'type' => 'url',
|
493 |
+
'path' => $feed_xpath,
|
494 |
);
|
495 |
$fileInfo['type'] = apply_filters('wp_all_import_feed_type', $fileInfo['type'], $this->file);
|
496 |
+
// detect CSV or XML
|
497 |
switch ($fileInfo['type']) {
|
498 |
case 'csv':
|
499 |
+
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
500 |
$csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
|
501 |
$csv_path = $filePath;
|
502 |
//wp_all_import_remove_source($filePath, false);
|
503 |
$filePath = $csv->xml_path;
|
504 |
$this->is_csv = $csv->is_csv;
|
505 |
+
$this->root_element = 'node';
|
506 |
break;
|
507 |
case 'json':
|
508 |
$json_str = file_get_contents($filePath);
|
509 |
$json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
|
510 |
$is_json = wp_all_import_is_json($json_str);
|
511 |
+
|
512 |
if( is_wp_error($is_json)){
|
513 |
$this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
|
514 |
} else {
|
515 |
$xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
|
516 |
if ( empty($xml_data) ) {
|
517 |
+
$this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
|
518 |
} else {
|
519 |
+
$tmpname = $this->uploadsPath .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
|
520 |
file_put_contents($tmpname, $xml_data);
|
521 |
wp_all_import_remove_source($filePath, false);
|
522 |
+
$filePath = $tmpname;
|
523 |
}
|
524 |
}
|
525 |
break;
|
526 |
case 'sql':
|
527 |
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
|
528 |
+
$sql = new PMXI_SQLParser( $filePath, $this->uploadsPath );
|
529 |
$filePath = $sql->parse();
|
530 |
+
break;
|
531 |
default:
|
532 |
# code...
|
533 |
break;
|
539 |
|
540 |
if ( $this->errors->get_error_codes() ) return $this->errors;
|
541 |
|
542 |
+
$decodedTemplates = empty($templates) ? json_decode($importTemplate, true) : json_decode($templates, true);
|
543 |
+
|
544 |
$templateOptions = "";
|
545 |
|
546 |
if ( is_array($decodedTemplates) and ! empty($decodedTemplates)) {
|
547 |
$templateOptions = empty($decodedTemplates[0]) ? current($decodedTemplates) : $decodedTemplates;
|
548 |
}
|
549 |
|
550 |
+
$options = (empty($templateOptions[0]['options'])) ? false : maybe_unserialize($templateOptions[0]['options']);
|
551 |
|
552 |
if ( ! empty($options['root_element'])) $this->root_element = $options['root_element'];
|
553 |
|
565 |
'taxonomy_type' => (!empty($options['taxonomy_type'])) ? $options['taxonomy_type'] : false,
|
566 |
);
|
567 |
}
|
568 |
+
|
569 |
protected function get_xml_file( $filePath )
|
570 |
{
|
571 |
$csv_path = '';
|
574 |
|
575 |
if($this->uploadsPath === false){
|
576 |
$this->errors->add('form-validation', __('WP All Import can\'t access your WordPress uploads folder.', 'wp_all_import_plugin'));
|
577 |
+
}
|
578 |
+
|
579 |
include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php');
|
580 |
$csv = new PMXI_CsvParser( array( 'filename' => $filePath, 'targetDir' => $this->uploadsPath ) ); // create chunks
|
581 |
+
|
582 |
$csv_path = $filePath;
|
583 |
|
584 |
$filePath = $csv->xml_path;
|
585 |
$this->is_csv = $csv->is_csv;
|
586 |
+
$this->root_element = 'node';
|
587 |
+
|
588 |
} elseif (preg_match('%\W(json)$%i', trim($filePath))){
|
589 |
|
590 |
$json_str = file_get_contents($filePath);
|
591 |
$json_str = str_replace("\xEF\xBB\xBF",'', $json_str);
|
592 |
$is_json = wp_all_import_is_json($json_str);
|
593 |
+
|
594 |
if( is_wp_error($is_json)){
|
595 |
$this->errors->add('form-validation', $is_json->get_error_message(), 'wp_all_import_plugin');
|
596 |
}
|
597 |
+
else{
|
598 |
+
|
599 |
$xml_data = wp_all_import_json_to_xml( json_decode($json_str, true) );
|
600 |
|
601 |
if ( empty($xml_data) ){
|
602 |
+
$this->errors->add('form-validation', __('Can not import this file. JSON to XML convertation failed.', 'wp_all_import_plugin'));
|
603 |
}
|
604 |
else{
|
605 |
+
$jsontmpname = $this->uploadsPath .'/'. wp_all_import_url_title(wp_unique_filename($this->uploadsPath, str_replace("json", "xml", basename($filePath))));
|
606 |
file_put_contents($jsontmpname, $xml_data);
|
607 |
wp_all_import_remove_source($filePath, false);
|
608 |
$filePath = $jsontmpname;
|
612 |
}
|
613 |
elseif (preg_match('%\W(sql)$%i', trim($filePath))){
|
614 |
|
615 |
+
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportSQLParse.php' );
|
616 |
|
617 |
$localSQLPath = $filePath;
|
618 |
$sql = new PMXI_SQLParser( $localSQLPath, $this->uploadsPath );
|
619 |
$filePath = $sql->parse();
|
620 |
wp_all_import_remove_source($localSQLPath, false);
|
621 |
+
}
|
622 |
elseif (preg_match('%\W(xls|xlsx)$%i', trim($filePath))){
|
623 |
|
624 |
+
include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportXLSParse.php' );
|
625 |
|
626 |
+
$localXLSPath = $filePath;
|
627 |
+
$xls = new PMXI_XLSParser( $localXLSPath, $this->uploadsPath );
|
628 |
+
$filePath = $xls->parse();
|
629 |
wp_all_import_remove_source($localXLSPath, false);
|
630 |
|
631 |
}
|
plugin.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: WP All Import
|
4 |
Plugin URI: http://www.wpallimport.com/wordpress-xml-csv-import/?utm_source=import-plugin-free&utm_medium=wp-plugins-page&utm_campaign=upgrade-to-pro
|
5 |
Description: The most powerful solution for importing XML and CSV files to WordPress. Create Posts and Pages with content from any XML or CSV file. A paid upgrade to WP All Import Pro is available for support and additional features.
|
6 |
-
Version: 3.6.
|
7 |
Author: Soflyy
|
8 |
*/
|
9 |
|
@@ -25,7 +25,7 @@ define('WP_ALL_IMPORT_ROOT_URL', rtrim(plugin_dir_url(__FILE__), '/'));
|
|
25 |
*/
|
26 |
define('WP_ALL_IMPORT_PREFIX', 'pmxi_');
|
27 |
|
28 |
-
define('PMXI_VERSION', '3.6.
|
29 |
|
30 |
define('PMXI_EDITION', 'free');
|
31 |
|
3 |
Plugin Name: WP All Import
|
4 |
Plugin URI: http://www.wpallimport.com/wordpress-xml-csv-import/?utm_source=import-plugin-free&utm_medium=wp-plugins-page&utm_campaign=upgrade-to-pro
|
5 |
Description: The most powerful solution for importing XML and CSV files to WordPress. Create Posts and Pages with content from any XML or CSV file. A paid upgrade to WP All Import Pro is available for support and additional features.
|
6 |
+
Version: 3.6.8
|
7 |
Author: Soflyy
|
8 |
*/
|
9 |
|
25 |
*/
|
26 |
define('WP_ALL_IMPORT_PREFIX', 'pmxi_');
|
27 |
|
28 |
+
define('PMXI_VERSION', '3.6.8');
|
29 |
|
30 |
define('PMXI_EDITION', 'free');
|
31 |
|
readme.txt
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
Contributors: soflyy, wpallimport
|
3 |
Requires at least: 4.1
|
4 |
Tested up to: 6.0
|
5 |
-
Stable tag: 3.6.
|
6 |
Tags: wordpress csv import, wordpress xml import, xml, csv, datafeed, import, migrate, import csv to wordpress, import xml to wordpress, advanced xml import, advanced csv import, bulk csv import, bulk xml import, bulk data import, xml to custom post type, csv to custom post type, woocommerce csv import, woocommerce xml import, csv import, import csv, xml import, import xml, csv importer
|
7 |
|
8 |
WP All Import is an extremely powerful importer that makes it easy to import any XML or CSV file to WordPress.
|
@@ -72,6 +72,14 @@ Learn more about our add-ons at [http://www.wpallimport.com/add-ons](http://www.
|
|
72 |
|
73 |
A [developer API](http://www.wpallimport.com/documentation/developers/action-reference/?utm_source=import-plugin-free&utm_medium=readme&utm_campaign=docs) (action hooks) is also available.
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
== Premium Support ==
|
76 |
Support for the free version of WP All Import is handled through the WordPress.org community forums.
|
77 |
|
@@ -105,6 +113,9 @@ Does it work with special character encoding like Hebrew, Arabic, Chinese, etc?
|
|
105 |
|
106 |
== Changelog ==
|
107 |
|
|
|
|
|
|
|
108 |
= 3.6.7 =
|
109 |
* security improvement
|
110 |
* improvement: changed Manage Imports page button labels to be more precise
|
2 |
Contributors: soflyy, wpallimport
|
3 |
Requires at least: 4.1
|
4 |
Tested up to: 6.0
|
5 |
+
Stable tag: 3.6.8
|
6 |
Tags: wordpress csv import, wordpress xml import, xml, csv, datafeed, import, migrate, import csv to wordpress, import xml to wordpress, advanced xml import, advanced csv import, bulk csv import, bulk xml import, bulk data import, xml to custom post type, csv to custom post type, woocommerce csv import, woocommerce xml import, csv import, import csv, xml import, import xml, csv importer
|
7 |
|
8 |
WP All Import is an extremely powerful importer that makes it easy to import any XML or CSV file to WordPress.
|
72 |
|
73 |
A [developer API](http://www.wpallimport.com/documentation/developers/action-reference/?utm_source=import-plugin-free&utm_medium=readme&utm_campaign=docs) (action hooks) is also available.
|
74 |
|
75 |
+
= Related Plugins =
|
76 |
+
[Export any WordPress data to XML/CSV](https://wordpress.org/plugins/wp-all-export/)
|
77 |
+
[Import Products from any XML or CSV to WooCommerce](https://wordpress.org/plugins/woocommerce-xml-csv-product-import/)
|
78 |
+
[Export Products to CSV/XML for WooCommerce](https://wordpress.org/plugins/product-export-for-woocommerce/)
|
79 |
+
[Custom Product Tabs for WooCommerce WP All Import Add-on](https://wordpress.org/plugins/custom-product-tabs-wp-all-import-add-on/)
|
80 |
+
[Export Orders to CSV/XML for WooCommerce](https://wordpress.org/plugins/order-export-for-woocommerce/)
|
81 |
+
[Export WordPress Users to CSV/XML](https://wordpress.org/plugins/export-wp-users-xml-csv/)
|
82 |
+
|
83 |
== Premium Support ==
|
84 |
Support for the free version of WP All Import is handled through the WordPress.org community forums.
|
85 |
|
113 |
|
114 |
== Changelog ==
|
115 |
|
116 |
+
= 3.6.8 =
|
117 |
+
* security improvement
|
118 |
+
|
119 |
= 3.6.7 =
|
120 |
* security improvement
|
121 |
* improvement: changed Manage Imports page button labels to be more precise
|