PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.1.0
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.1.0
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 9 years ago CdataStrategyAlways.php 9 years ago CdataStrategyFactory.php 9 years ago CdataStrategyIllegalCharacters.php 9 years ago CdataStrategyIllegalCharactersHtmlEntities.php 9 years ago CdataStrategyNever.php 9 years ago XMLWriter.php 9 years ago chunk.php 9 years ago config.php 9 years ago download.php 9 years ago handler.php 9 years ago helper.php 9 years ago input.php 9 years ago session.php 9 years ago wpallimport.php 9 years ago zip.php 9 years ago
wpallimport.php
566 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 ( empty($export->parent_id) and in_array($custom_type, array('shop_order_refund'))) 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 self::prepare_import_template( $exportOptions );
288
289 if ( in_array('product', $exportOptions['cpt']) )
290 {
291 self::$templateOptions['single_page_parent'] = '';
292 if ( ! empty($exportOptions['export_variations']) && $exportOptions['export_variations'] == XmlExportEngine::VARIABLE_PRODUCTS_EXPORT_VARIATION ){
293 if ( $exportOptions['export_variations_title'] == XmlExportEngine::VARIATION_USE_PARENT_TITLE ){
294 self::$templateOptions['matching_parent'] = 'first_is_variation';
295 }
296 if ( $exportOptions['export_variations_title'] == XmlExportEngine::VARIATION_USE_DEFAULT_TITLE ) {
297 self::$templateOptions['matching_parent'] = 'first_is_parent_id';
298 //self::$templateOptions['single_product_id_first_is_parent_id'] = '{parent_id[1]}';
299 }
300 }
301 }
302
303 $tpl_options = self::$templateOptions;
304
305 if ( 'csv' == $exportOptions['export_to'] )
306 {
307 $tpl_options['delimiter'] = $exportOptions['delimiter'];
308 $tpl_options['root_element'] = 'node';
309 }
310 else
311 {
312 $tpl_options['root_element'] = $exportOptions['record_xml_tag'];
313 }
314
315 $tpl_options['update_all_data'] = 'yes';
316 $tpl_options['is_update_status'] = 1;
317 $tpl_options['is_update_title'] = 1;
318 $tpl_options['is_update_author'] = 1;
319 $tpl_options['is_update_slug'] = 1;
320 $tpl_options['is_update_content'] = 1;
321 $tpl_options['is_update_excerpt'] = 1;
322 $tpl_options['is_update_dates'] = 1;
323 $tpl_options['is_update_menu_order'] = 1;
324 $tpl_options['is_update_parent'] = 1;
325 $tpl_options['is_update_attachments'] = 1;
326 $tpl_options['is_update_acf'] = 1;
327 $tpl_options['update_acf_logic'] = 'full_update';
328 $tpl_options['acf_list'] = '';
329 $tpl_options['is_update_product_type'] = 1;
330 $tpl_options['is_update_attributes'] = 1;
331 $tpl_options['update_attributes_logic'] = 'full_update';
332 $tpl_options['attributes_list'] = '';
333 $tpl_options['is_update_images'] = 1;
334 $tpl_options['is_update_custom_fields'] = 1;
335 $tpl_options['update_custom_fields_logic'] = 'full_update';
336 $tpl_options['custom_fields_list'] = '';
337 $tpl_options['is_update_categories'] = 1;
338 $tpl_options['update_categories_logic'] = 'full_update';
339 $tpl_options['taxonomies_list'] = '';
340
341 $tpl_data = array(
342 'name' => $exportOptions['template_name'],
343 'is_keep_linebreaks' => 1,
344 'is_leave_html' => 0,
345 'fix_characters' => 0,
346 'options' => $tpl_options,
347 );
348
349 $exportOptions['tpl_data'] = $tpl_data;
350
351 $export->set(array(
352 'options' => $exportOptions
353 ))->save();
354
355 }
356
357 $link_to_import and $export->options['is_generate_import'] and self::link_template_to_import( $export, $file_path, $foundPosts );
358 }
359
360 public static function link_template_to_import( & $export, $file_path, $foundPosts )
361 {
362
363 $exportOptions = $export->options;
364
365 // associate exported posts with new import
366 if ( wp_all_export_is_compatible() )
367 {
368 $options = self::$templateOptions + PMXI_Plugin::get_default_import_options();
369
370 $import = new PMXI_Import_Record();
371
372 $import->getById($exportOptions['import_id']);
373
374 if ( ! $import->isEmpty() and $import->parent_import_id == 99999 ){
375
376 $xmlPath = $file_path;
377
378 $root_element = '';
379
380 $historyPath = $file_path;
381
382 if ( 'csv' == $exportOptions['export_to'] )
383 {
384 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
385
386 $options['delimiter'] = $exportOptions['delimiter'];
387
388 include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php' );
389
390 $path_info = pathinfo($xmlPath);
391
392 $path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']);
393
394 $security_folder = array_pop($path_parts);
395
396 $wp_uploads = wp_upload_dir();
397
398 $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path'];
399
400 $csv = new PMXI_CsvParser( array( 'filename' => $xmlPath, 'targetDir' => $target ) );
401
402 if ( ! in_array($xmlPath, $exportOptions['attachment_list']) )
403 {
404 $exportOptions['attachment_list'][] = $csv->xml_path;
405 }
406
407 $historyPath = $csv->xml_path;
408
409 $root_element = 'node';
410
411 }
412 else
413 {
414 $root_element = apply_filters('wp_all_export_record_xml_tag', $exportOptions['record_xml_tag'], $export->id);
415 }
416
417 $import->set(array(
418 'xpath' => '/' . $root_element,
419 'type' => 'upload',
420 'options' => $options,
421 'root_element' => $root_element,
422 'path' => $xmlPath,
423 'name' => basename($xmlPath),
424 'imported' => 0,
425 'created' => 0,
426 'updated' => 0,
427 'skipped' => 0,
428 'deleted' => 0,
429 'iteration' => 1,
430 'count' => $foundPosts
431 ))->save();
432
433 $history_file = new PMXI_File_Record();
434 $history_file->set(array(
435 'name' => $import->name,
436 'import_id' => $import->id,
437 'path' => $historyPath,
438 'registered_on' => date('Y-m-d H:i:s')
439 ))->save();
440
441 $exportOptions['import_id'] = $import->id;
442
443 $export->set(array(
444 'options' => $exportOptions
445 ))->save();
446 }
447 }
448 }
449
450 public static function prepare_import_template( $exportOptions )
451 {
452 $options = $exportOptions;
453
454 $is_xml_template = $options['export_to'] == 'xml';
455
456 $required_add_ons = array();
457
458 $cf_list = array();
459 $attr_list = array();
460 $taxs_list = array();
461 $acf_list = array();
462
463 $implode_delimiter = ($options['delimiter'] == ',') ? '|' : ',';
464
465 if ( ! empty($options['is_user_export']) ) self::$templateOptions['pmui']['import_users'] = 1;
466
467 foreach ($options['ids'] as $ID => $value)
468 {
469 if (empty($options['cc_type'][$ID])) continue;
470
471 if ($is_xml_template)
472 {
473 $element_name = (!empty($options['cc_name'][$ID])) ? str_replace(':', '_', preg_replace('/[^a-z0-9_:-]/i', '', $options['cc_name'][$ID])) : 'untitled_' . $ID;
474 }
475 else
476 {
477 $element_name = strtolower((!empty($options['cc_name'][$ID])) ? preg_replace('/[^a-z0-9_]/i', '', $options['cc_name'][$ID]) : 'untitled_' . $ID);
478 }
479
480 $element_type = $options['cc_type'][$ID];
481
482 switch ($element_type)
483 {
484 case 'woo':
485
486 if ( ! empty($options['cc_value'][$ID]) )
487 {
488 if (empty($required_add_ons['PMWI_Plugin']))
489 {
490 $required_add_ons['PMWI_Plugin'] = array(
491 'name' => 'WooCommerce Add-On Pro',
492 'paid' => true,
493 'url' => 'http://www.wpallimport.com/woocommerce-product-import/'
494 );
495 }
496
497 XmlExportWooCommerce::prepare_import_template( $options, self::$templateOptions, $cf_list, $attr_list, $element_name, $options['cc_label'][$ID] );
498 }
499
500 break;
501
502 case 'acf':
503
504 if (empty($required_add_ons['PMAI_Plugin']))
505 {
506 $required_add_ons['PMAI_Plugin'] = array(
507 'name' => 'ACF Add-On Pro',
508 'paid' => true,
509 'url' => 'http://www.wpallimport.com/advanced-custom-fields/?utm_source=wordpress.org&utm_medium=wpai-import-template&utm_campaign=free+wp+all+export+plugin'
510 );
511 }
512
513 $field_options = unserialize($options['cc_options'][$ID]);
514
515 // add ACF group ID to the template options
516 if( ! in_array($field_options['group_id'], self::$templateOptions['acf'])){
517 self::$templateOptions['acf'][$field_options['group_id']] = 1;
518 }
519
520 self::$templateOptions['fields'][$field_options['key']] = XmlExportACF::prepare_import_template( $options, self::$templateOptions, $acf_list, $element_name, $field_options);
521
522 break;
523
524 default:
525
526 XmlExportCpt::prepare_import_template( $options, self::$templateOptions, $cf_list, $attr_list, $taxs_list, $element_name, $ID);
527
528 XmlExportMediaGallery::prepare_import_template( $options, self::$templateOptions, $element_name, $ID);
529
530 XmlExportWooCommerceOrder::prepare_import_template( $options, self::$templateOptions, $element_name, $ID);
531
532 break;
533 }
534 }
535
536 if ( ! empty($cf_list) )
537 {
538 self::$templateOptions['is_update_custom_fields'] = 1;
539 self::$templateOptions['custom_fields_list'] = $cf_list;
540 }
541 if ( ! empty($attr_list) )
542 {
543 self::$templateOptions['is_update_attributes'] = 1;
544 self::$templateOptions['update_attributes_logic'] = 'only';
545 self::$templateOptions['attributes_list'] = $attr_list;
546 self::$templateOptions['attributes_only_list'] = implode(',', $attr_list);
547 }
548 else{
549 self::$templateOptions['is_update_attributes'] = 0;
550 }
551 if ( ! empty($taxs_list) )
552 {
553 self::$templateOptions['is_update_categories'] = 1;
554 self::$templateOptions['taxonomies_list'] = $taxs_list;
555 }
556 if ( ! empty($acf_list) )
557 {
558 self::$templateOptions['is_update_acf'] = 1;
559 self::$templateOptions['acf_list'] = $acf_list;
560 }
561
562 self::$templateOptions['required_add_ons'] = $required_add_ons;
563 }
564 }
565
566 PMXE_Wpallimport::getInstance();