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