PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.1.5
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.1.5
trunk 0.9.0 0.9.1 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.14 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0
wp-all-export / classes / wpallimport.php
wp-all-export / classes Last commit date
CdataStrategy.php 8 years ago CdataStrategyAlways.php 8 years ago CdataStrategyFactory.php 8 years ago CdataStrategyIllegalCharacters.php 8 years ago CdataStrategyIllegalCharactersHtmlEntities.php 8 years ago CdataStrategyNever.php 8 years ago XMLWriter.php 8 years ago chunk.php 8 years ago config.php 8 years ago download.php 8 years ago handler.php 8 years ago helper.php 8 years ago input.php 8 years ago installer.php 8 years ago session.php 8 years ago wpallimport.php 8 years ago zip.php 8 years ago
wpallimport.php
575 lines
1 <?php
2
3 final class PMXE_Wpallimport
4 {
5 /**
6 * Singletone instance
7 * @var PMXE_Wpallimport
8 */
9 protected static $instance;
10
11 /**
12 * Return singletone instance
13 * @return PMXE_Wpallimport
14 */
15 static public function getInstance() {
16 if (self::$instance == NULL) {
17 self::$instance = new self();
18 }
19 return self::$instance;
20 }
21
22 private function __construct(){}
23
24 public static function create_an_import( & $export )
25 {
26
27 $custom_type = (empty($export->options['cpt'])) ? 'post' : $export->options['cpt'][0];
28
29 // Do not create an import for WooCommerce Orders & Refunds
30 // if ( in_array($custom_type, array('shop_order'))) return false;
31
32 if ( $export->options['is_generate_import'] and wp_all_export_is_compatible() ){
33
34 $import = new PMXI_Import_Record();
35
36 if ( ! empty($export->options['import_id']) ) $import->getById($export->options['import_id']);
37
38 if ($import->isEmpty())
39 {
40 $import->set(array(
41 'parent_import_id' => 99999,
42 'xpath' => '/',
43 'type' => 'upload',
44 'options' => array('empty'),
45 'root_element' => 'root',
46 'path' => 'path',
47 'imported' => 0,
48 'created' => 0,
49 'updated' => 0,
50 'skipped' => 0,
51 'deleted' => 0,
52 'iteration' => 1
53 ))->save();
54
55 if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
56 {
57 PMXE_Plugin::$session->set('import_id', $import->id);
58 }
59 $options = $export->options;
60 $options['import_id'] = $import->id;
61
62 $export->set(array(
63 'options' => $options
64 ))->save();
65 }
66 else
67 {
68 if ( $import->parent_import_id != 99999 )
69 {
70 $newImport = new PMXI_Import_Record();
71
72 $newImport->set(array(
73 'parent_import_id' => 99999,
74 'xpath' => '/',
75 'type' => 'upload',
76 'options' => array('empty'),
77 'root_element' => 'root',
78 'path' => 'path',
79 'imported' => 0,
80 'created' => 0,
81 'updated' => 0,
82 'skipped' => 0,
83 'deleted' => 0,
84 'iteration' => 1
85 ))->save();
86
87 if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
88 {
89 PMXE_Plugin::$session->set('import_id', $newImport->id);
90 }
91
92 $options = $export->options;
93 $options['import_id'] = $newImport->id;
94
95 $export->set(array(
96 'options' => $options
97 ))->save();
98 }
99 else
100 {
101 global $wpdb;
102 $post = new PMXI_Post_List();
103 $wpdb->query($wpdb->prepare('DELETE FROM ' . $post->getTable() . ' WHERE import_id = %s', $import->id));
104 }
105 }
106 }
107 }
108
109 public static $templateOptions = array();
110 public static function generateImportTemplate( & $export, $file_path = '', $foundPosts = 0, $link_to_import = true )
111 {
112 $exportOptions = $export->options;
113
114 $custom_type = (empty($exportOptions['cpt'])) ? 'post' : $exportOptions['cpt'][0];
115
116 // Do not create an import template for WooCommerce Refunds
117 if ( $export->options['export_to'] == 'xml' && in_array($export->options['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ) return false;
118
119 // Generate template for WP All Import
120 if ($exportOptions['is_generate_templates'])
121 {
122 self::$templateOptions = array(
123 'type' => ( ! empty($exportOptions['cpt']) and $exportOptions['cpt'][0] == 'page') ? 'page' : 'post',
124 'wizard_type' => 'new',
125 'deligate' => 'wpallexport',
126 'custom_type' => (XmlExportEngine::$is_user_export) ? 'import_users' : $custom_type,
127 'status' => 'xpath',
128 'is_multiple_page_parent' => 'no',
129 'unique_key' => '',
130 'acf' => array(),
131 'fields' => array(),
132 'is_multiple_field_value' => array(),
133 'multiple_value' => array(),
134 'fields_delimiter' => array(),
135 'update_all_data' => 'no',
136 'is_update_status' => 0,
137 'is_update_title' => 0,
138 'is_update_author' => 0,
139 'is_update_slug' => 0,
140 'is_update_content' => 0,
141 'is_update_excerpt' => 0,
142 'is_update_dates' => 0,
143 'is_update_menu_order' => 0,
144 'is_update_parent' => 0,
145 'is_update_attachments' => 0,
146 'is_update_acf' => 0,
147 'update_acf_logic' => 'only',
148 'acf_list' => '',
149 'is_update_product_type' => 1,
150 'is_update_attributes' => 0,
151 'update_attributes_logic' => 'only',
152 'attributes_list' => '',
153 'is_update_images' => 0,
154 'is_update_custom_fields' => 0,
155 'update_custom_fields_logic' => 'only',
156 'custom_fields_list' => '',
157 'is_update_categories' => 0,
158 'update_categories_logic' => 'only',
159 'taxonomies_list' => '',
160 'export_id' => $export->id
161 );
162
163 if ( in_array('product', $exportOptions['cpt']) )
164 {
165 $default = array(
166 'is_multiple_product_type' => 'yes',
167 'multiple_product_type' => 'simple',
168 'is_product_virtual' => 'no',
169 'is_product_downloadable' => 'no',
170 'is_product_enabled' => 'yes',
171 'is_variation_enabled' => 'yes',
172 'is_product_featured' => 'no',
173 'is_product_visibility' => 'visible',
174 'is_multiple_product_tax_status' => 'yes',
175 'multiple_product_tax_status' => 'none',
176 'is_multiple_product_tax_class' => 'yes',
177 'is_product_manage_stock' => 'no',
178 'product_stock_status' => 'auto',
179 'product_allow_backorders' => 'no',
180 'product_sold_individually' => 'no',
181 'is_multiple_product_shipping_class' => 'yes',
182 'is_multiple_grouping_product' => 'yes',
183 'is_product_enable_reviews' => 'no',
184 'single_sale_price_dates_from' => 'now',
185 'single_sale_price_dates_to' => 'now',
186 'product_files_delim' => ',',
187 'product_files_names_delim' => ',',
188 'matching_parent' => 'auto',
189 'parent_indicator' => 'custom field',
190 'missing_records_stock_status' => 0,
191 'is_variable_sale_price_shedule' => 0,
192 'is_variable_product_virtual' => 'no',
193 'is_variable_product_manage_stock' => 'no',
194 'is_multiple_variable_product_shipping_class' => 'yes',
195 'is_multiple_variable_product_tax_class' => 'yes',
196 'multiple_variable_product_tax_class' => 'parent',
197 'variable_stock_status' => 'instock',
198 'variable_allow_backorders' => 'no',
199 'is_variable_product_downloadable' => 'no',
200 'variable_product_files_delim' => ',',
201 'variable_product_files_names_delim' => ',',
202 'is_variable_product_enabled' => 'yes',
203 'first_is_parent' => 'yes',
204 'default_attributes_type' => 'first',
205 'disable_sku_matching' => 1,
206 'disable_prepare_price' => 1,
207 'convert_decimal_separator' => 1,
208 'grouping_indicator' => 'xpath',
209 'is_update_product_type' => 1,
210 'make_simple_product' => 1,
211 'single_product_regular_price_adjust_type' => '%',
212 'single_product_sale_price_adjust_type' => '%',
213 'is_variation_product_manage_stock' => 'no',
214 'variation_stock_status' => 'auto',
215 );
216
217 self::$templateOptions = array_replace_recursive(self::$templateOptions, $default);
218
219 self::$templateOptions['_virtual'] = 1;
220 self::$templateOptions['_downloadable'] = 1;
221 self::$templateOptions['put_variation_image_to_gallery'] = 1;
222 self::$templateOptions['disable_auto_sku_generation'] = 1;
223 }
224
225 if ( in_array('shop_order', $exportOptions['cpt']) )
226 {
227 self::$templateOptions['update_all_data'] = 'no';
228 self::$templateOptions['is_update_status'] = 0;
229 self::$templateOptions['is_update_dates'] = 0;
230 self::$templateOptions['is_update_excerpt'] = 0;
231
232 // $default = PMWI_Plugin::get_default_import_options();
233 // self::$templateOptions['pmwi_order'] = $default['pmwi_order'];
234 self::$templateOptions['pmwi_order'] = array();
235 self::$templateOptions['pmwi_order']['is_update_billing_details'] = 0;
236 self::$templateOptions['pmwi_order']['is_update_shipping_details'] = 0;
237 self::$templateOptions['pmwi_order']['is_update_payment'] = 0;
238 self::$templateOptions['pmwi_order']['is_update_notes'] = 0;
239 self::$templateOptions['pmwi_order']['is_update_products'] = 0;
240 self::$templateOptions['pmwi_order']['is_update_fees'] = 0;
241 self::$templateOptions['pmwi_order']['is_update_coupons'] = 0;
242 self::$templateOptions['pmwi_order']['is_update_shipping'] = 0;
243 self::$templateOptions['pmwi_order']['is_update_taxes'] = 0;
244 self::$templateOptions['pmwi_order']['is_update_refunds'] = 0;
245 self::$templateOptions['pmwi_order']['is_update_total'] = 0;
246 self::$templateOptions['pmwi_order']['is_guest_matching'] = 1;
247 self::$templateOptions['pmwi_order']['status'] = 'wc-pending';
248 self::$templateOptions['pmwi_order']['billing_source'] = 'existing';
249 self::$templateOptions['pmwi_order']['billing_source_match_by'] = 'username';
250 self::$templateOptions['pmwi_order']['shipping_source'] = 'guest';
251 self::$templateOptions['pmwi_order']['copy_from_billing'] = 1;
252 self::$templateOptions['pmwi_order']['products_repeater_mode'] = 'csv';
253 self::$templateOptions['pmwi_order']['products_repeater_mode_separator'] = '|';
254 self::$templateOptions['pmwi_order']['products_source'] = 'existing';
255 self::$templateOptions['pmwi_order']['fees_repeater_mode'] = 'csv';
256 self::$templateOptions['pmwi_order']['fees_repeater_mode_separator'] = '|';
257 self::$templateOptions['pmwi_order']['coupons_repeater_mode'] = 'csv';
258 self::$templateOptions['pmwi_order']['coupons_repeater_mode_separator'] = '|';
259 self::$templateOptions['pmwi_order']['shipping_repeater_mode'] = 'csv';
260 self::$templateOptions['pmwi_order']['shipping_repeater_mode_separator'] = '|';
261 self::$templateOptions['pmwi_order']['taxes_repeater_mode'] = 'csv';
262 self::$templateOptions['pmwi_order']['taxes_repeater_mode_separator'] = '|';
263 self::$templateOptions['pmwi_order']['order_total_logic'] = 'auto';
264 self::$templateOptions['pmwi_order']['order_refund_date'] = 'now';
265 self::$templateOptions['pmwi_order']['order_refund_issued_source'] = 'existing';
266 self::$templateOptions['pmwi_order']['order_refund_issued_match_by'] = 'username';
267 self::$templateOptions['pmwi_order']['notes_repeater_mode'] = 'csv';
268 self::$templateOptions['pmwi_order']['notes_repeater_mode_separator'] = '|';
269 }
270
271 if ( XmlExportEngine::$is_user_export )
272 {
273 self::$templateOptions['is_update_first_name'] = 0;
274 self::$templateOptions['is_update_last_name'] = 0;
275 self::$templateOptions['is_update_role'] = 0;
276 self::$templateOptions['is_update_nickname'] = 0;
277 self::$templateOptions['is_update_description'] = 0;
278 self::$templateOptions['is_update_login'] = 0;
279 self::$templateOptions['is_update_password'] = 0;
280 self::$templateOptions['is_update_nicename'] = 0;
281 self::$templateOptions['is_update_email'] = 0;
282 self::$templateOptions['is_update_registered'] = 0;
283 self::$templateOptions['is_update_display_name'] = 0;
284 self::$templateOptions['is_update_url'] = 0;
285 }
286
287 if (XmlExportEngine::$is_taxonomy_export){
288 self::$templateOptions['taxonomy_type'] = $exportOptions['taxonomy_to_export'];
289 }
290
291 self::prepare_import_template( $exportOptions );
292
293 if ( in_array('product', $exportOptions['cpt']) )
294 {
295 self::$templateOptions['single_page_parent'] = '';
296 if ( ! empty($exportOptions['export_variations']) && $exportOptions['export_variations'] == XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_VARIATION ){
297 if ( $exportOptions['export_variations_title'] == XmlExportEngine::VARIATION_USE_PARENT_TITLE ){
298 self::$templateOptions['matching_parent'] = 'first_is_variation';
299 }
300 if ( $exportOptions['export_variations_title'] == XmlExportEngine::VARIATION_USE_DEFAULT_TITLE ) {
301 self::$templateOptions['matching_parent'] = 'first_is_parent_id';
302 }
303 self::$templateOptions['create_new_records'] = 0;
304 self::$templateOptions['is_update_product_type'] = 0;
305 }
306 }
307
308 $tpl_options = self::$templateOptions;
309
310 if ( 'csv' == $exportOptions['export_to'] )
311 {
312 $tpl_options['delimiter'] = $exportOptions['delimiter'];
313 $tpl_options['root_element'] = 'node';
314 }
315 else
316 {
317 $tpl_options['root_element'] = $exportOptions['record_xml_tag'];
318 }
319
320 $tpl_options['update_all_data'] = 'yes';
321 $tpl_options['is_update_status'] = 1;
322 $tpl_options['is_update_title'] = 1;
323 $tpl_options['is_update_author'] = 1;
324 $tpl_options['is_update_slug'] = 1;
325 $tpl_options['is_update_content'] = 1;
326 $tpl_options['is_update_excerpt'] = 1;
327 $tpl_options['is_update_dates'] = 1;
328 $tpl_options['is_update_menu_order'] = 1;
329 $tpl_options['is_update_parent'] = 1;
330 $tpl_options['is_update_attachments'] = 1;
331 $tpl_options['is_update_acf'] = 1;
332 $tpl_options['update_acf_logic'] = 'full_update';
333 $tpl_options['acf_list'] = '';
334 $tpl_options['is_update_product_type'] = 1;
335 $tpl_options['is_update_attributes'] = 1;
336 $tpl_options['update_attributes_logic'] = 'full_update';
337 $tpl_options['attributes_list'] = '';
338 $tpl_options['is_update_images'] = 1;
339 $tpl_options['is_update_custom_fields'] = 1;
340 $tpl_options['update_custom_fields_logic'] = 'full_update';
341 $tpl_options['custom_fields_list'] = '';
342 $tpl_options['is_update_categories'] = 1;
343 $tpl_options['update_categories_logic'] = 'full_update';
344 $tpl_options['taxonomies_list'] = '';
345
346 $tpl_data = array(
347 'name' => $exportOptions['template_name'],
348 'is_keep_linebreaks' => 1,
349 'is_leave_html' => 0,
350 'fix_characters' => 0,
351 'options' => $tpl_options,
352 );
353
354 $exportOptions['tpl_data'] = $tpl_data;
355
356 $export->set(array(
357 'options' => $exportOptions
358 ))->save();
359
360 }
361
362 $link_to_import and $export->options['is_generate_import'] and self::link_template_to_import( $export, $file_path, $foundPosts );
363 }
364
365 public static function link_template_to_import( & $export, $file_path, $foundPosts )
366 {
367
368 $exportOptions = $export->options;
369
370 // associate exported posts with new import
371 if ( wp_all_export_is_compatible() )
372 {
373 $options = self::$templateOptions + PMXI_Plugin::get_default_import_options();
374
375 $import = new PMXI_Import_Record();
376
377 $import->getById($exportOptions['import_id']);
378
379 if ( ! $import->isEmpty() and $import->parent_import_id == 99999 ){
380
381 $xmlPath = $file_path;
382
383 $root_element = '';
384
385 $historyPath = $file_path;
386
387 if ( 'csv' == $exportOptions['export_to'] )
388 {
389 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
390
391 $options['delimiter'] = $exportOptions['delimiter'];
392
393 include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php' );
394
395 $path_info = pathinfo($xmlPath);
396
397 $path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']);
398
399 $security_folder = array_pop($path_parts);
400
401 $wp_uploads = wp_upload_dir();
402
403 $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path'];
404
405 $csv = new PMXI_CsvParser( array( 'filename' => $xmlPath, 'targetDir' => $target ) );
406
407 if ( ! in_array($xmlPath, $exportOptions['attachment_list']) )
408 {
409 $exportOptions['attachment_list'][] = $csv->xml_path;
410 }
411
412 $historyPath = $csv->xml_path;
413
414 $root_element = 'node';
415
416 }
417 else
418 {
419 $root_element = apply_filters('wp_all_export_record_xml_tag', $exportOptions['record_xml_tag'], $export->id);
420 }
421
422 $import->set(array(
423 'xpath' => '/' . $root_element,
424 'type' => 'upload',
425 'options' => $options,
426 'root_element' => $root_element,
427 'path' => $xmlPath,
428 'name' => basename($xmlPath),
429 'imported' => 0,
430 'created' => 0,
431 'updated' => 0,
432 'skipped' => 0,
433 'deleted' => 0,
434 'iteration' => 1,
435 'count' => $foundPosts
436 ))->save();
437
438 $history_file = new PMXI_File_Record();
439 $history_file->set(array(
440 'name' => $import->name,
441 'import_id' => $import->id,
442 'path' => $historyPath,
443 'registered_on' => date('Y-m-d H:i:s')
444 ))->save();
445
446 $exportOptions['import_id'] = $import->id;
447
448 $export->set(array(
449 'options' => $exportOptions
450 ))->save();
451 }
452 }
453 }
454
455 public static function prepare_import_template( $exportOptions )
456 {
457 $options = $exportOptions;
458
459 $is_xml_template = $options['export_to'] == 'xml';
460
461 $required_add_ons = array();
462
463 $cf_list = array();
464 $attr_list = array();
465 $taxs_list = array();
466 $acf_list = array();
467
468 $implode_delimiter = ($options['delimiter'] == ',') ? '|' : ',';
469
470 if ( ! empty($options['is_user_export']) ) self::$templateOptions['pmui']['import_users'] = 1;
471
472 foreach ($options['ids'] as $ID => $value)
473 {
474 if (empty($options['cc_type'][$ID])) continue;
475
476 if ($is_xml_template)
477 {
478 $element_name = (!empty($options['cc_name'][$ID])) ? str_replace(':', '_', preg_replace('/[^a-z0-9_:-]/i', '', $options['cc_name'][$ID])) : 'untitled_' . $ID;
479 }
480 else
481 {
482 $element_name = strtolower((!empty($options['cc_name'][$ID])) ? preg_replace('/[^a-z0-9_]/i', '', $options['cc_name'][$ID]) : 'untitled_' . $ID);
483 }
484
485 $element_type = $options['cc_type'][$ID];
486
487 switch ($element_type)
488 {
489 case 'woo':
490
491 if ( ! empty($options['cc_value'][$ID]) )
492 {
493 if (empty($required_add_ons['PMWI_Plugin']))
494 {
495 $required_add_ons['PMWI_Plugin'] = array(
496 'name' => 'WooCommerce Add-On Pro',
497 'paid' => true,
498 'url' => 'http://www.wpallimport.com/woocommerce-product-import/'
499 );
500 }
501
502 XmlExportWooCommerce::prepare_import_template( $options, self::$templateOptions, $cf_list, $attr_list, $element_name, $options['cc_label'][$ID] );
503 }
504
505 break;
506
507 case 'acf':
508
509 if (empty($required_add_ons['PMAI_Plugin']))
510 {
511 $required_add_ons['PMAI_Plugin'] = array(
512 'name' => 'ACF Add-On Pro',
513 'paid' => true,
514 'url' => 'http://www.wpallimport.com/advanced-custom-fields/?utm_source=wordpress.org&utm_medium=wpai-import-template&utm_campaign=free+wp+all+export+plugin'
515 );
516 }
517
518 $field_options = unserialize($options['cc_options'][$ID]);
519
520 // add ACF group ID to the template options
521 if( ! in_array($field_options['group_id'], self::$templateOptions['acf'])){
522 self::$templateOptions['acf'][$field_options['group_id']] = 1;
523 }
524
525 self::$templateOptions['fields'][$field_options['key']] = XmlExportACF::prepare_import_template( $options, self::$templateOptions, $acf_list, $element_name, $field_options);
526
527 break;
528
529 default:
530
531 XmlExportCpt::prepare_import_template( $options, self::$templateOptions, $cf_list, $attr_list, $taxs_list, $element_name, $ID);
532
533 XmlExportMediaGallery::prepare_import_template( $options, self::$templateOptions, $element_name, $ID);
534
535 XmlExportUser::prepare_import_template( $options, self::$templateOptions, $element_name, $ID);
536
537 XmlExportTaxonomy::prepare_import_template( $options, self::$templateOptions, $element_name, $ID);
538
539 XmlExportWooCommerceOrder::prepare_import_template( $options, self::$templateOptions, $element_name, $ID);
540
541 break;
542 }
543 }
544
545 if ( ! empty($cf_list) )
546 {
547 self::$templateOptions['is_update_custom_fields'] = 1;
548 self::$templateOptions['custom_fields_list'] = $cf_list;
549 }
550 if ( ! empty($attr_list) )
551 {
552 self::$templateOptions['is_update_attributes'] = 1;
553 self::$templateOptions['update_attributes_logic'] = 'only';
554 self::$templateOptions['attributes_list'] = $attr_list;
555 self::$templateOptions['attributes_only_list'] = implode(',', $attr_list);
556 }
557 else{
558 self::$templateOptions['is_update_attributes'] = 0;
559 }
560 if ( ! empty($taxs_list) )
561 {
562 self::$templateOptions['is_update_categories'] = 1;
563 self::$templateOptions['taxonomies_list'] = $taxs_list;
564 }
565 if ( ! empty($acf_list) )
566 {
567 self::$templateOptions['is_update_acf'] = 1;
568 self::$templateOptions['acf_list'] = $acf_list;
569 }
570
571 self::$templateOptions['required_add_ons'] = $required_add_ons;
572 }
573 }
574
575 PMXE_Wpallimport::getInstance();