PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.0.8
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.0.8
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
550 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']['status'] = 'wc-pending';
247 self::$templateOptions['pmwi_order']['billing_source'] = 'existing';
248 self::$templateOptions['pmwi_order']['billing_source_match_by'] = 'username';
249 self::$templateOptions['pmwi_order']['shipping_source'] = 'copy';
250 self::$templateOptions['pmwi_order']['products_repeater_mode'] = 'csv';
251 self::$templateOptions['pmwi_order']['products_repeater_mode_separator'] = '|';
252 self::$templateOptions['pmwi_order']['products_source'] = 'existing';
253 self::$templateOptions['pmwi_order']['fees_repeater_mode'] = 'csv';
254 self::$templateOptions['pmwi_order']['fees_repeater_mode_separator'] = '|';
255 self::$templateOptions['pmwi_order']['coupons_repeater_mode'] = 'csv';
256 self::$templateOptions['pmwi_order']['coupons_repeater_mode_separator'] = '|';
257 self::$templateOptions['pmwi_order']['shipping_repeater_mode'] = 'csv';
258 self::$templateOptions['pmwi_order']['shipping_repeater_mode_separator'] = '|';
259 self::$templateOptions['pmwi_order']['taxes_repeater_mode'] = 'csv';
260 self::$templateOptions['pmwi_order']['taxes_repeater_mode_separator'] = '|';
261 self::$templateOptions['pmwi_order']['order_total_logic'] = 'auto';
262 self::$templateOptions['pmwi_order']['order_refund_date'] = 'now';
263 self::$templateOptions['pmwi_order']['order_refund_issued_source'] = 'existing';
264 self::$templateOptions['pmwi_order']['order_refund_issued_match_by'] = 'username';
265 self::$templateOptions['pmwi_order']['notes_repeater_mode'] = 'csv';
266 self::$templateOptions['pmwi_order']['notes_repeater_mode_separator'] = '|';
267 }
268
269 if ( XmlExportEngine::$is_user_export )
270 {
271 self::$templateOptions['is_update_first_name'] = 0;
272 self::$templateOptions['is_update_last_name'] = 0;
273 self::$templateOptions['is_update_role'] = 0;
274 self::$templateOptions['is_update_nickname'] = 0;
275 self::$templateOptions['is_update_description'] = 0;
276 self::$templateOptions['is_update_login'] = 0;
277 self::$templateOptions['is_update_password'] = 0;
278 self::$templateOptions['is_update_nicename'] = 0;
279 self::$templateOptions['is_update_email'] = 0;
280 self::$templateOptions['is_update_registered'] = 0;
281 self::$templateOptions['is_update_display_name'] = 0;
282 self::$templateOptions['is_update_url'] = 0;
283 }
284
285 self::prepare_import_template( $exportOptions );
286
287 $tpl_options = self::$templateOptions;
288
289 if ( 'csv' == $exportOptions['export_to'] )
290 {
291 $tpl_options['delimiter'] = $exportOptions['delimiter'];
292 $tpl_options['root_element'] = 'node';
293 }
294 else
295 {
296 $tpl_options['root_element'] = $exportOptions['record_xml_tag'];
297 }
298
299 $tpl_options['update_all_data'] = 'yes';
300 $tpl_options['is_update_status'] = 1;
301 $tpl_options['is_update_title'] = 1;
302 $tpl_options['is_update_author'] = 1;
303 $tpl_options['is_update_slug'] = 1;
304 $tpl_options['is_update_content'] = 1;
305 $tpl_options['is_update_excerpt'] = 1;
306 $tpl_options['is_update_dates'] = 1;
307 $tpl_options['is_update_menu_order'] = 1;
308 $tpl_options['is_update_parent'] = 1;
309 $tpl_options['is_update_attachments'] = 1;
310 $tpl_options['is_update_acf'] = 1;
311 $tpl_options['update_acf_logic'] = 'full_update';
312 $tpl_options['acf_list'] = '';
313 $tpl_options['is_update_product_type'] = 1;
314 $tpl_options['is_update_attributes'] = 1;
315 $tpl_options['update_attributes_logic'] = 'full_update';
316 $tpl_options['attributes_list'] = '';
317 $tpl_options['is_update_images'] = 1;
318 $tpl_options['is_update_custom_fields'] = 1;
319 $tpl_options['update_custom_fields_logic'] = 'full_update';
320 $tpl_options['custom_fields_list'] = '';
321 $tpl_options['is_update_categories'] = 1;
322 $tpl_options['update_categories_logic'] = 'full_update';
323 $tpl_options['taxonomies_list'] = '';
324
325 $tpl_data = array(
326 'name' => $exportOptions['template_name'],
327 'is_keep_linebreaks' => 1,
328 'is_leave_html' => 0,
329 'fix_characters' => 0,
330 'options' => $tpl_options,
331 );
332
333 $exportOptions['tpl_data'] = $tpl_data;
334
335 $export->set(array(
336 'options' => $exportOptions
337 ))->save();
338
339 }
340
341 $link_to_import and $export->options['is_generate_import'] and self::link_template_to_import( $export, $file_path, $foundPosts );
342 }
343
344 public static function link_template_to_import( & $export, $file_path, $foundPosts )
345 {
346
347 $exportOptions = $export->options;
348
349 // associate exported posts with new import
350 if ( wp_all_export_is_compatible() )
351 {
352 $options = self::$templateOptions + PMXI_Plugin::get_default_import_options();
353
354 $import = new PMXI_Import_Record();
355
356 $import->getById($exportOptions['import_id']);
357
358 if ( ! $import->isEmpty() and $import->parent_import_id == 99999 ){
359
360 $xmlPath = $file_path;
361
362 $root_element = '';
363
364 $historyPath = $file_path;
365
366 if ( 'csv' == $exportOptions['export_to'] )
367 {
368 $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure');
369
370 $options['delimiter'] = $exportOptions['delimiter'];
371
372 include_once( PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php' );
373
374 $path_info = pathinfo($xmlPath);
375
376 $path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']);
377
378 $security_folder = array_pop($path_parts);
379
380 $wp_uploads = wp_upload_dir();
381
382 $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path'];
383
384 $csv = new PMXI_CsvParser( array( 'filename' => $xmlPath, 'targetDir' => $target ) );
385
386 if ( ! in_array($xmlPath, $exportOptions['attachment_list']) )
387 {
388 $exportOptions['attachment_list'][] = $csv->xml_path;
389 }
390
391 $historyPath = $csv->xml_path;
392
393 $root_element = 'node';
394
395 }
396 else
397 {
398 $root_element = apply_filters('wp_all_export_record_xml_tag', $exportOptions['record_xml_tag'], $export->id);
399 }
400
401 $import->set(array(
402 'xpath' => '/' . $root_element,
403 'type' => 'upload',
404 'options' => $options,
405 'root_element' => $root_element,
406 'path' => $xmlPath,
407 'name' => basename($xmlPath),
408 'imported' => 0,
409 'created' => 0,
410 'updated' => 0,
411 'skipped' => 0,
412 'deleted' => 0,
413 'iteration' => 1,
414 'count' => $foundPosts
415 ))->save();
416
417 $history_file = new PMXI_File_Record();
418 $history_file->set(array(
419 'name' => $import->name,
420 'import_id' => $import->id,
421 'path' => $historyPath,
422 'registered_on' => date('Y-m-d H:i:s')
423 ))->save();
424
425 $exportOptions['import_id'] = $import->id;
426
427 $export->set(array(
428 'options' => $exportOptions
429 ))->save();
430 }
431 }
432 }
433
434 public static function prepare_import_template( $exportOptions )
435 {
436 $options = $exportOptions;
437
438 $is_xml_template = $options['export_to'] == 'xml';
439
440 $required_add_ons = array();
441
442 $cf_list = array();
443 $attr_list = array();
444 $taxs_list = array();
445 $acf_list = array();
446
447 $implode_delimiter = ($options['delimiter'] == ',') ? '|' : ',';
448
449 if ( ! empty($options['is_user_export']) ) self::$templateOptions['pmui']['import_users'] = 1;
450
451 foreach ($options['ids'] as $ID => $value)
452 {
453 if (empty($options['cc_type'][$ID])) continue;
454
455 if ($is_xml_template)
456 {
457 $element_name = (!empty($options['cc_name'][$ID])) ? str_replace(':', '_', preg_replace('/[^a-z0-9_:-]/i', '', $options['cc_name'][$ID])) : 'untitled_' . $ID;
458 }
459 else
460 {
461 $element_name = strtolower((!empty($options['cc_name'][$ID])) ? preg_replace('/[^a-z0-9_]/i', '', $options['cc_name'][$ID]) : 'untitled_' . $ID);
462 }
463
464 $element_type = $options['cc_type'][$ID];
465
466 switch ($element_type)
467 {
468 case 'woo':
469
470 if ( ! empty($options['cc_value'][$ID]) )
471 {
472 if (empty($required_add_ons['PMWI_Plugin']))
473 {
474 $required_add_ons['PMWI_Plugin'] = array(
475 'name' => 'WooCommerce Add-On Pro',
476 'paid' => true,
477 'url' => 'http://www.wpallimport.com/woocommerce-product-import/'
478 );
479 }
480
481 XmlExportWooCommerce::prepare_import_template( $options, self::$templateOptions, $cf_list, $attr_list, $element_name, $options['cc_label'][$ID] );
482 }
483
484 break;
485
486 case 'acf':
487
488 if (empty($required_add_ons['PMAI_Plugin']))
489 {
490 $required_add_ons['PMAI_Plugin'] = array(
491 'name' => 'ACF Add-On Pro',
492 'paid' => true,
493 'url' => 'http://www.wpallimport.com/advanced-custom-fields/?utm_source=wordpress.org&utm_medium=wpai-import-template&utm_campaign=free+wp+all+export+plugin'
494 );
495 }
496
497 $field_options = unserialize($options['cc_options'][$ID]);
498
499 // add ACF group ID to the template options
500 if( ! in_array($field_options['group_id'], self::$templateOptions['acf'])){
501 self::$templateOptions['acf'][$field_options['group_id']] = 1;
502 }
503
504 self::$templateOptions['fields'][$field_options['key']] = XmlExportACF::prepare_import_template( $options, self::$templateOptions, $acf_list, $element_name, $field_options);
505
506 break;
507
508 default:
509
510 XmlExportCpt::prepare_import_template( $options, self::$templateOptions, $cf_list, $attr_list, $taxs_list, $element_name, $ID);
511
512 XmlExportMediaGallery::prepare_import_template( $options, self::$templateOptions, $element_name, $ID);
513
514 XmlExportWooCommerceOrder::prepare_import_template( $options, self::$templateOptions, $element_name, $ID);
515
516 break;
517 }
518 }
519
520 if ( ! empty($cf_list) )
521 {
522 self::$templateOptions['is_update_custom_fields'] = 1;
523 self::$templateOptions['custom_fields_list'] = $cf_list;
524 }
525 if ( ! empty($attr_list) )
526 {
527 self::$templateOptions['is_update_attributes'] = 1;
528 self::$templateOptions['update_attributes_logic'] = 'only';
529 self::$templateOptions['attributes_list'] = $attr_list;
530 self::$templateOptions['attributes_only_list'] = implode(',', $attr_list);
531 }
532 else{
533 self::$templateOptions['is_update_attributes'] = 0;
534 }
535 if ( ! empty($taxs_list) )
536 {
537 self::$templateOptions['is_update_categories'] = 1;
538 self::$templateOptions['taxonomies_list'] = $taxs_list;
539 }
540 if ( ! empty($acf_list) )
541 {
542 self::$templateOptions['is_update_acf'] = 1;
543 self::$templateOptions['acf_list'] = $acf_list;
544 }
545
546 self::$templateOptions['required_add_ons'] = $required_add_ons;
547 }
548 }
549
550 PMXE_Wpallimport::getInstance();