PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.2.2
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.2.2
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 / libraries / XmlExportEngine.php
wp-all-export / libraries Last commit date
VariableProductTitle 7 years ago .gitkeep 7 years ago WpaeInvalidPhpException.php 7 years ago WpaeInvalidStringException.php 7 years ago WpaeMethodNotFoundException.php 7 years ago WpaePhpInterpreterErrorHandler.php 7 years ago WpaeString.php 7 years ago WpaeTooMuchRecursionException.php 7 years ago WpaeXmlProcessor.php 7 years ago XmlCsvExport.php 7 years ago XmlExportACF.php 7 years ago XmlExportComment.php 7 years ago XmlExportCpt.php 7 years ago XmlExportEngine.php 7 years ago XmlExportFiltering.php 7 years ago XmlExportMediaGallery.php 7 years ago XmlExportTaxonomy.php 7 years ago XmlExportUser.php 7 years ago XmlExportWooCommerce.php 7 years ago XmlExportWooCommerceCoupon.php 7 years ago XmlExportWooCommerceOrder.php 7 years ago XmlGoogleMerchants.php 7 years ago XmlSpec.php 7 years ago
XmlExportEngine.php
1200 lines
1 <?php
2
3 if ( ! class_exists('XmlExportEngine') ){
4
5 require_once dirname(__FILE__) . '/XmlExportACF.php';
6 require_once dirname(__FILE__) . '/XmlExportWooCommerce.php';
7 require_once dirname(__FILE__) . '/XmlExportWooCommerceOrder.php';
8 require_once dirname(__FILE__) . '/XmlExportUser.php';
9 require_once dirname(__FILE__) . '/XmlExportComment.php';
10 require_once dirname(__FILE__) . '/XmlExportTaxonomy.php';
11
12 final class XmlExportEngine
13 {
14
15 const VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION = 1;
16 const VARIABLE_PRODUCTS_EXPORT_VARIATION = 2;
17 const VARIABLE_PRODUCTS_EXPORT_PARENT = 3;
18
19 const VARIATION_USE_PARENT_TITLE = 1;
20 const VARIATION_USE_DEFAULT_TITLE = 2;
21
22 /**
23 * Custom XML Loop begin statement
24 * @var string
25 */
26 const XML_LOOP_START = '<!-- BEGIN LOOP -->';
27
28 /**
29 * Custom XML Loop end statement
30 * @var string
31 */
32 const XML_LOOP_END = '<!-- END LOOP -->';
33
34 const EXPORT_TYPE_GOOLE_MERCHANTS = 'XmlGoogleMerchants';
35 const EXPORT_TYPE_XML = 'xml';
36 const EXPORT_TYPE_CSV = 'csv';
37
38 public static $acf_export;
39 public static $woo_export;
40 public static $woo_order_export;
41 public static $woo_coupon_export;
42 public static $woo_refund_export;
43 public static $user_export;
44 public static $comment_export;
45 public static $taxonomy_export;
46
47 public static $is_preview = false;
48
49 public static $implode = ',';
50
51 private $post;
52 private $_existing_meta_keys = array();
53 private $_existing_taxonomies = array();
54
55 private $init_fields = array(
56 array(
57 'label' => 'id',
58 'name' => 'ID',
59 'type' => 'id'
60 ),
61 array(
62 'label' => 'title',
63 'name' => 'Title',
64 'type' => 'title'
65 ),
66 array(
67 'label' => 'content',
68 'name' => 'Content',
69 'type' => 'content'
70 )
71 );
72
73 public static $default_fields = array(
74 array(
75 'label' => 'id',
76 'name' => 'ID',
77 'type' => 'id'
78 ),
79 array(
80 'label' => 'title',
81 'name' => 'Title',
82 'type' => 'title'
83 ),
84 array(
85 'label' => 'content',
86 'name' => 'Content',
87 'type' => 'content'
88 ),
89 array(
90 'label' => 'excerpt',
91 'name' => 'Excerpt',
92 'type' => 'excerpt'
93 ),
94 array(
95 'label' => 'date',
96 'name' => 'Date',
97 'type' => 'date'
98 ),
99 array(
100 'label' => 'post_type',
101 'name' => 'Post Type',
102 'type' => 'post_type'
103 ),
104 array(
105 'label' => 'permalink',
106 'name' => 'Permalink',
107 'type' => 'permalink'
108 )
109 );
110
111 private $other_fields = array(
112 array(
113 'label' => 'status',
114 'name' => 'Status',
115 'type' => 'status'
116 ),
117
118 array(
119 'label' => 'author',
120 'name' => 'Author ID',
121 'type' => 'author'
122 ),
123
124 array(
125 'label' => 'author_username',
126 'name' => 'Author Username',
127 'type' => 'author_username'
128 ),
129
130 array(
131 'label' => 'author_email',
132 'name' => 'Author Email',
133 'type' => 'author_email'
134 ),
135
136 array(
137 'label' => 'author_first_name',
138 'name' => 'Author First Name',
139 'type' => 'author_first_name'
140 ),
141
142 array(
143 'label' => 'author_last_name',
144 'name' => 'Author Last Name',
145 'type' => 'author_last_name'
146 ),
147
148 array(
149 'label' => 'slug',
150 'name' => 'Slug',
151 'type' => 'slug'
152 ),
153 array(
154 'label' => 'format',
155 'name' => 'Format',
156 'type' => 'format'
157 ),
158 array(
159 'label' => 'template',
160 'name' => 'Template',
161 'type' => 'template'
162 ),
163 array(
164 'label' => 'parent',
165 'name' => 'Parent',
166 'type' => 'parent'
167 ),
168 array(
169 'label' => 'parent_slug',
170 'name' => 'Parent Slug',
171 'type' => 'parent_slug'
172 ),
173 array(
174 'label' => 'order',
175 'name' => 'Order',
176 'type' => 'order'
177 ),
178 array(
179 'label' => 'comment_status',
180 'name' => 'Comment Status',
181 'type' => 'comment_status'
182 ),
183 array(
184 'label' => 'ping_status',
185 'name' => 'Ping Status',
186 'type' => 'ping_status'
187 ),
188 array(
189 'label' => 'post_modified',
190 'name' => 'Post Modified Date',
191 'type' => 'post_modified'
192 )
193 );
194
195 private $available_sections = array();
196 private $filter_sections = array();
197
198 private $errors;
199
200 private $available_data = array(
201 'acf_groups' => array(),
202 'existing_acf_meta_keys' => array(),
203 'existing_meta_keys' => array(),
204 'init_fields' => array(),
205 'default_fields' => array(),
206 'other_fields' => array(),
207 'woo_data' => array(),
208 'existing_attributes' => array(),
209 'existing_taxonomies' => array()
210 );
211
212 private $filters;
213
214 public static $is_user_export = false;
215 public static $is_comment_export = false;
216 public static $is_taxonomy_export = false;
217 public static $post_types = array();
218 public static $exportOptions = array();
219 public static $exportQuery;
220 public static $exportID = false;
221 public static $exportRecord = false;
222 public static $globalAvailableSections;
223
224 public static $is_auto_generate_enabled = true;
225
226 public function __construct( $post, & $errors = false ){
227
228 $this->post = $post;
229 $this->errors = $errors;
230
231 $this->available_sections = array(
232 'default' => array(
233 'title' => __("Standard", "wp_all_export_plugin"),
234 'content' => 'default_fields'
235 ),
236 'media' => array(
237 'title' => __("Media", "wp_all_export_plugin"),
238 'content' => '',
239 'additional' => array(
240 'images' => array(
241 'title' => __("Images", "wp_all_export_plugin"),
242 'meta' => array(
243 array(
244 'name' => 'URL',
245 'label' => 'url',
246 'type' => 'image_url',
247 'auto' => 1
248 ),
249 array(
250 'name' => 'Filename',
251 'label' => 'filename',
252 'type' => 'image_filename'
253 ),
254 array(
255 'name' => 'Path',
256 'label' => 'path',
257 'type' => 'image_path'
258 ),
259 array(
260 'name' => 'ID',
261 'label' => 'image_id',
262 'type' => 'image_id'
263 ),
264 array(
265 'name' => 'Title',
266 'label' => 'title',
267 'type' => 'image_title',
268 'auto' => 1
269 ),
270 array(
271 'name' => 'Caption',
272 'label' => 'caption',
273 'type' => 'image_caption',
274 'auto' => 1
275 ),
276 array(
277 'name' => 'Description',
278 'label' => 'description',
279 'type' => 'image_description',
280 'auto' => 1
281 ),
282 array(
283 'name' => 'Alt Text',
284 'label' => 'alt',
285 'type' => 'image_alt',
286 'auto' => 1
287 ),
288 array(
289 'name' => 'Featured',
290 'label' => 'featured',
291 'type' => 'image_featured',
292 'auto' => 1
293 ),
294 )
295 ),
296 'attachments' => array(
297 'title' => __("Attachments", "wp_all_export_plugin"),
298 'meta' => array(
299 array(
300 'name' => 'URL',
301 'label' => 'url',
302 'type' => 'attachment_url',
303 'auto' => 1
304 ),
305 array(
306 'name' => 'Filename',
307 'label' => 'filename',
308 'type' => 'attachment_filename'
309 ),
310 array(
311 'name' => 'Path',
312 'label' => 'path',
313 'type' => 'attachment_path'
314 ),
315 array(
316 'name' => 'ID',
317 'label' => 'attachment_id',
318 'type' => 'attachment_id'
319 ),
320 array(
321 'name' => 'Title',
322 'label' => 'title',
323 'type' => 'attachment_title'
324 ),
325 array(
326 'name' => 'Caption',
327 'label' => 'caption',
328 'type' => 'attachment_caption'
329 ),
330 array(
331 'name' => 'Description',
332 'label' => 'description',
333 'type' => 'attachment_description'
334 ),
335 array(
336 'name' => 'Alt Text',
337 'label' => 'alt',
338 'type' => 'attachment_alt'
339 ),
340 )
341 )
342 )
343 ),
344 'cats' => array(
345 'title' => __("Taxonomies", "wp_all_export_plugin"),
346 'content' => 'existing_taxonomies'
347 ),
348 'cf' => array(
349 'title' => __("Custom Fields", "wp_all_export_plugin"),
350 'content' => 'existing_meta_keys'
351 ),
352 'other' => array(
353 'title' => __("Other", "wp_all_export_plugin"),
354 'content' => 'other_fields'
355 )
356 );
357
358 $this->filter_sections = array(
359 'author' => array(
360 'title' => __("Author", "wp_all_export_plugin"),
361 'fields' => array(
362 'user_ID' => 'User ID',
363 'user_login' => 'User Login',
364 'user_nicename' => 'Nicename',
365 'user_email' => 'Email',
366 'user_registered' => 'Date Registered (Y-m-d H:i:s)',
367 'display_name' => 'Display Name',
368 'cf_first_name' => 'First Name',
369 'cf_last_name' => 'Last Name',
370 'nickname' => 'Nickname',
371 'description' => 'User Description',
372 'wp_capabilities' => 'User Role'
373 )
374 )
375 );
376
377 if ( 'specific' == $this->post['export_type'])
378 {
379
380 self::$post_types = ( ! is_array($this->post['cpt']) ) ? array($this->post['cpt']) : $this->post['cpt'];
381
382 if ( in_array('product', self::$post_types) and ! in_array('product_variation', self::$post_types)) self::$post_types[] = 'product_variation';
383
384 self::$is_user_export = ( in_array('users', self::$post_types) or in_array('shop_customer', self::$post_types) ) ? true : false;
385
386 self::$is_comment_export = ( in_array('comments', self::$post_types) ) ? true : false;
387
388 self::$is_taxonomy_export = ( in_array('taxonomies', self::$post_types) ) ? true : false;
389
390 }
391 else
392 {
393 self::$is_user_export = ( 'wp_user_query' == $this->post['wp_query_selector'] );
394 self::$is_comment_export = ( 'wp_comment_query' == $this->post['wp_query_selector'] );
395 }
396
397 if ( ! self::$is_user_export && ! self::$is_comment_export && ! self::$is_taxonomy_export)
398 {
399 add_filter("wp_all_export_filters", array( &$this, "filter_export_filters"), 10, 1);
400
401 // When WPML is active and at least one post in the export has a trid
402 if (class_exists('SitePress'))
403 {
404 self::$default_fields[] = array(
405 'label' => 'wpml_trid',
406 'name' => 'WPML Translation ID',
407 'type' => 'wpml_trid'
408 );
409
410 self::$default_fields[] = array(
411 'label' => 'wpml_lang',
412 'name' => 'WPML Language Code',
413 'type' => 'wpml_lang'
414 );
415 }
416 }
417
418 self::$exportOptions = $post;
419
420 if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
421 {
422 $filter_args = array(
423 'filter_rules_hierarhy' => $this->post['filter_rules_hierarhy'],
424 'product_matching_mode' => $this->post['product_matching_mode'],
425 'taxonomy_to_export' => empty($this->post['taxonomy_to_export']) ? '' : $this->post['taxonomy_to_export']
426 );
427
428 $this->filters = \Wpae\Pro\Filtering\FilteringFactory::getFilterEngine();
429 $this->filters->init($filter_args);
430
431 $this->init();
432 }
433
434 if (empty(self::$exportOptions['delimiter'])) self::$exportOptions['delimiter'] = ',';
435
436 self::$implode = (self::$exportOptions['delimiter'] == ',') ? '|' : ',';
437
438 self::$implode = apply_filters('wp_all_export_implode_delimiter', self::$implode, self::$exportID);
439
440 if ( !empty(self::$exportOptions['xml_template_type']) && in_array(self::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ) self::$implode = '#delimiter#';
441
442 self::$acf_export = new XmlExportACF();
443 self::$woo_export = new XmlExportWooCommerce();
444 self::$user_export = new XmlExportUser();
445 self::$comment_export = new XmlExportComment();
446 self::$taxonomy_export = new XmlExportTaxonomy();
447 self::$woo_order_export = new XmlExportWooCommerceOrder();
448 self::$woo_coupon_export = new XmlExportWooCommerceCoupon();
449
450 }
451
452 // [FILTERS]
453
454 /**
455 *
456 * Filter data for advanced filtering
457 *
458 */
459 public function filter_export_filters($filters){
460 return array_merge($filters, $this->filter_sections);
461 }
462
463 // [\FILTERS]
464
465 protected function init(){
466
467 PMXE_Plugin::$session->set('is_user_export', self::$is_user_export);
468 PMXE_Plugin::$session->set('is_comment_export', self::$is_comment_export);
469 PMXE_Plugin::$session->set('is_taxonomy_export', self::$is_taxonomy_export);
470 PMXE_Plugin::$session->save_data();
471
472 if ('advanced' == $this->post['export_type']) {
473
474 if( "" == $this->post['wp_query'] ){
475 $this->errors->add('form-validation', __('WP Query field is required', 'pmxe_plugin'));
476 }
477 else
478 {
479 $this->filters->parse();
480
481 PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere'));
482 PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin'));
483 PMXE_Plugin::$session->set('wp_query', $this->post['wp_query']);
484 PMXE_Plugin::$session->save_data();
485 }
486 }
487 else
488 {
489 $this->filters->parse();
490
491 PMXE_Plugin::$session->set('cpt', self::$post_types);
492 PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere'));
493 PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin'));
494 PMXE_Plugin::$session->save_data();
495 }
496
497 PMXE_Plugin::$session->save_data();
498
499 }
500
501 public function init_additional_data(){
502
503 self::$woo_order_export->init_additional_data();
504 self::$woo_export->init_additional_data();
505
506 }
507
508 public function init_available_data(){
509
510 global $wpdb;
511 $table_prefix = $wpdb->prefix;
512
513 // Prepare existing taxonomies
514 if ( 'specific' == $this->post['export_type'] and ! self::$is_user_export and ! self::$is_comment_export and ! self::$is_taxonomy_export )
515 {
516 $this->_existing_taxonomies = wp_all_export_get_existing_taxonomies_by_cpt( self::$post_types[0] );
517
518 $this->_existing_meta_keys = wp_all_export_get_existing_meta_by_cpt( self::$post_types[0] );
519 }
520 if ( 'advanced' == $this->post['export_type'] and ! self::$is_user_export and ! self::$is_comment_export and ! self::$is_taxonomy_export )
521 {
522 $meta_keys = $wpdb->get_results("SELECT DISTINCT meta_key FROM {$table_prefix}postmeta WHERE {$table_prefix}postmeta.meta_key NOT LIKE '_edit%' LIMIT 1000");
523 if ( ! empty($meta_keys)){
524 $exclude_keys = array('_first_variation_attributes', '_is_first_variation_created');
525 foreach ($meta_keys as $meta_key) {
526 if ( strpos($meta_key->meta_key, "_tmp") === false && strpos($meta_key->meta_key, "_v_") === false && ! in_array($meta_key->meta_key, $exclude_keys))
527 $this->_existing_meta_keys[] = $meta_key->meta_key;
528 }
529 }
530
531 global $wp_taxonomies;
532
533 foreach ($wp_taxonomies as $key => $obj) { if (in_array($obj->name, array('nav_menu'))) continue;
534
535 if (strpos($obj->name, "pa_") !== 0 and strlen($obj->name) > 3)
536 $this->_existing_taxonomies[] = array(
537 'name' => empty($obj->label) ? $obj->name : $obj->label,
538 'label' => $obj->name,
539 'type' => 'cats'
540 );
541 }
542 }
543
544 // Prepare existing ACF groups & fields
545 self::$acf_export->init($this->_existing_meta_keys);
546
547 // Prepare existing WooCommerce data
548 self::$woo_export->init($this->_existing_meta_keys);
549
550 // Prepare existing WooCommerce Order data
551 self::$woo_order_export->init($this->_existing_meta_keys);
552
553 // Prepare existing WooCommerce Coupon data
554 self::$woo_coupon_export->init($this->_existing_meta_keys);
555
556 // Prepare existing Users data
557 self::$user_export->init($this->_existing_meta_keys);
558
559 // Prepare existing Comments data
560 self::$comment_export->init($this->_existing_meta_keys);
561
562 // Prepare existing Taxonomy data
563 self::$taxonomy_export->init($this->_existing_meta_keys);
564
565 return $this->get_available_data();
566 }
567
568 public function get_available_data(){
569
570 $this->available_data['acf_groups'] = self::$acf_export->get('_acf_groups');
571 $this->available_data['existing_acf_meta_keys'] = self::$acf_export->get('_existing_acf_meta_keys');
572 $this->available_data['existing_meta_keys'] = $this->_existing_meta_keys;
573 $this->available_data['existing_taxonomies'] = $this->_existing_taxonomies;
574
575 $this->available_data['init_fields'] = apply_filters('wp_all_export_init_fields', $this->init_fields);
576 $this->available_data['default_fields'] = apply_filters('wp_all_export_default_fields', self::$default_fields);
577 $this->available_data['other_fields'] = apply_filters('wp_all_export_other_fields', $this->other_fields);
578
579 $this->available_data = apply_filters("wp_all_export_available_data", $this->available_data);
580
581 return $this->available_data;
582
583 }
584
585 public function get_fields_options( $field_keys = array() ){
586
587 $fields = array(
588 'ids' => array(),
589 'cc_label' => array(),
590 'cc_php' => array(),
591 'cc_code' => array(),
592 'cc_sql' => array(),
593 'cc_options' => array(),
594 'cc_type' => array(),
595 'cc_value' => array(),
596 'cc_name' => array(),
597 'cc_settings' => array()
598 );
599
600 self::$woo_order_export->get_fields_options( $fields, $field_keys );
601
602 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
603
604 foreach ($available_sections as $slug => $section)
605 {
606 if ( ! empty($this->available_data[$section['content']]) ):
607
608 foreach ($this->available_data[$section['content']] as $field)
609 {
610
611 $field_key = (is_array($field)) ? $field['name'] : $field;
612
613 if ( ! in_array($field_key, $field_keys) ) continue;
614
615 $fields['ids'][] = 1;
616 $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $field;
617 $fields['cc_php'][] = '';
618 $fields['cc_code'][] = '';
619 $fields['cc_sql'][] = '';
620 $fields['cc_options'][] = '';
621 $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $slug;
622 $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $field;
623 $fields['cc_name'][] = $field_key;
624 $fields['cc_settings'][] = '';
625 }
626 endif;
627
628 if ( ! empty($section['additional']) )
629 {
630 foreach ($section['additional'] as $sub_slug => $sub_section)
631 {
632
633 foreach ($sub_section['meta'] as $field) {
634 $key_to_check = (is_array($field)) ? $field['name'] : $field;
635
636 if ( in_array($sub_slug, array('images', 'attachments')) ){
637 $key_to_check = preg_replace("%s$%","",ucfirst($sub_slug)) . ' ' . $key_to_check;
638 }
639
640 if ( ! in_array($key_to_check, $field_keys) ) continue;
641
642 $field_options = ( in_array($sub_slug, array('images', 'attachments')) ) ? esc_attr('{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}') : '0';
643
644 $fields['ids'][] = 1;
645 $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $field;
646 $fields['cc_php'][] = '';
647 $fields['cc_code'][] = '';
648 $fields['cc_sql'][] = '';
649 $fields['cc_options'][] = $field_options;
650 $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $sub_slug;
651 $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $field;
652 $fields['cc_name'][] = $key_to_check;
653 $fields['cc_settings'][] = '';
654 }
655 }
656 }
657 }
658
659 if ( ! self::$is_comment_export )
660 {
661 self::$acf_export->get_fields_options( $fields, $field_keys );
662 }
663
664 $sort_fields = array();
665 foreach ($field_keys as $i => $field_key){
666 foreach ($fields['cc_name'] as $j => $cc_name){
667 if (!empty($cc_name) && $cc_name == $field_key){
668 $sort_fields['ids'][] = 1;
669 $sort_fields['cc_label'][] = $fields['cc_label'][$j];
670 $sort_fields['cc_php'][] = $fields['cc_php'][$j];
671 $sort_fields['cc_code'][] = $fields['cc_code'][$j];
672 $sort_fields['cc_sql'][] = $fields['cc_sql'][$j];
673 $sort_fields['cc_options'][] = $fields['cc_options'][$j];
674 $sort_fields['cc_type'][] = $fields['cc_type'][$j];
675 $sort_fields['cc_value'][] = $fields['cc_value'][$j];
676 $sort_fields['cc_name'][] = $fields['cc_name'][$j];
677 $sort_fields['cc_settings'][] = $fields['cc_settings'][$j];
678 break;
679 }
680 }
681 }
682
683 return $sort_fields;
684
685 }
686
687 public function render(){
688
689 $i = 0;
690
691 ob_start();
692
693 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
694 self::$globalAvailableSections = $available_sections;
695
696 // Render Available WooCommerce Orders Data
697 self::$woo_order_export->render($i);
698
699 foreach ($available_sections as $slug => $section)
700 {
701 if ( ! empty($this->available_data[$section['content']]) or ! empty($section['additional']) ):
702 ?>
703 <p class="wpae-available-fields-group"><?php echo $section['title']; ?><span class="wpae-expander">+</span></p>
704 <div class="wpae-custom-field">
705 <ul>
706 <?php if ( ! empty($this->available_data[$section['content']]) ): ?>
707 <li>
708 <div class="default_column" rel="">
709 <label class="wpallexport-element-label"><?php echo __("All", "wp_all_export_plugin") . ' ' . $section['title']; ?></label>
710 <input type="hidden" name="rules[]" value="pmxe_<?php echo $slug; ?>"/>
711 </div>
712 </li>
713 <?php
714 foreach ($this->available_data[$section['content']] as $field)
715 {
716 $field_type = is_array($field) ? $field['type'] : $slug;
717 $field_name = is_array($field) ? $field['name'] : $field;
718
719 if ( $field_type == 'cf' && $field_name == '_thumbnail_id' ) continue;
720
721 $is_auto_field = ( ! empty($field['auto']) or self::$is_auto_generate_enabled and ('specific' != $this->post['export_type'] or 'specific' == $this->post['export_type'] and ! in_array(self::$post_types[0], array('product'))));
722
723 ?>
724 <li class="pmxe_<?php echo $slug; ?> <?php if ( $is_auto_field ) echo 'wp_all_export_auto_generate';?>">
725 <div class="custom_column" rel="<?php echo ($i + 1);?>">
726 <label class="wpallexport-xml-element"><?php echo (is_array($field)) ? $field['name'] : $field; ?></label>
727 <input type="hidden" name="ids[]" value="1"/>
728 <input type="hidden" name="cc_label[]" value="<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/>
729 <input type="hidden" name="cc_php[]" value="0"/>
730 <input type="hidden" name="cc_code[]" value=""/>
731 <input type="hidden" name="cc_sql[]" value="0"/>
732 <input type="hidden" name="cc_options[]" value="0"/>
733 <input type="hidden" name="cc_type[]" value="<?php echo (is_array($field)) ? $field['type'] : $slug; ?>"/>
734 <input type="hidden" name="cc_value[]" value="<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/>
735 <input type="hidden" name="cc_name[]" value="<?php echo (is_array($field)) ? $field['name'] : $field;?>"/>
736 <input type="hidden" name="cc_settings[]" value="0"/>
737 </div>
738 </li>
739 <?php
740 $i++;
741 }
742 endif;
743
744 if ( ! empty($section['additional']) )
745 {
746 foreach ($section['additional'] as $sub_slug => $sub_section)
747 {
748 ?>
749 <li class="available_sub_section">
750 <p class="wpae-available-fields-group"><?php echo $sub_section['title']; ?><span class="wpae-expander">+</span></p>
751 <div class="wpae-custom-field">
752 <ul>
753 <li>
754 <div class="default_column" rel="">
755 <label class="wpallexport-element-label"><?php echo __("All", "wp_all_export_plugin") . ' ' . $sub_section['title']; ?></label>
756 <input type="hidden" name="rules[]" value="pmxe_<?php echo $slug;?>_<?php echo $sub_slug;?>"/>
757 </div>
758 </li>
759 <?php
760 foreach ($sub_section['meta'] as $field) {
761 $is_auto_field = empty($field['auto']) ? false : true;
762 $field_options = ( in_array($sub_slug, array('images', 'attachments')) ) ? esc_attr('{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}') : '0';
763 ?>
764 <li class="pmxe_<?php echo $slug; ?>_<?php echo $sub_slug;?> <?php if ( $is_auto_field ) echo 'wp_all_export_auto_generate';?>">
765 <div class="custom_column" rel="<?php echo ($i + 1);?>">
766 <label class="wpallexport-xml-element"><?php echo (is_array($field)) ? XmlExportEngine::sanitizeFieldName($field['name']) : $field; ?></label>
767 <input type="hidden" name="ids[]" value="1"/>
768 <input type="hidden" name="cc_label[]" value="<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/>
769 <input type="hidden" name="cc_php[]" value="0"/>
770 <input type="hidden" name="cc_code[]" value="0"/>
771 <input type="hidden" name="cc_sql[]" value="0"/>
772 <input type="hidden" name="cc_options[]" value="<?php echo $field_options; ?>"/>
773 <input type="hidden" name="cc_type[]" value="<?php echo (is_array($field)) ? $field['type'] : $sub_slug; ?>"/>
774 <input type="hidden" name="cc_value[]" value="<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/>
775 <input type="hidden" name="cc_name[]" value="<?php echo (is_array($field)) ? XmlExportEngine::sanitizeFieldName($field['name']) : $field;?>"/>
776 <input type="hidden" name="cc_settings[]" value=""/>
777 </div>
778 </li>
779 <?php
780 $i++;
781 }
782 ?>
783 </ul>
784 </li>
785 <?php
786 }
787 }
788 ?>
789 </ul>
790 </div>
791 <?php
792 endif;
793 }
794
795 if ( ! self::$is_comment_export )
796 {
797 // Render Available ACF
798 self::$acf_export->render($i);
799 }
800
801 return ob_get_clean();
802
803 }
804
805 public function render_filters(){
806
807 $available_sections = apply_filters("wp_all_export_available_sections", apply_filters('wp_all_export_filters', $this->available_sections) );
808
809 // Render Filters for WooCommerce Orders
810 self::$woo_order_export->render_filters();
811
812 if ( ! empty($available_sections) )
813 {
814 $exclude = array('wpml_lang', 'wpml_trid');
815
816 foreach ($available_sections as $slug => $section)
817 {
818 if ( ! empty($section['content']) and ! empty($this->available_data[$section['content']]) or ! empty($section['fields'])):
819 ?>
820
821 <optgroup label="<?php echo $section['title']; ?>">
822
823 <?php if ( ! empty($section['content']) && ! empty($this->available_data[$section['content']]) ): ?>
824
825 <?php foreach ($this->available_data[$section['content']] as $field) : ?>
826
827 <?php
828
829 $field_label = is_array($field) ? $field['label'] : $field;
830 $field_type = is_array($field) ? $field['type'] : $slug;
831 $field_name = is_array($field) ? $field['name'] : $field;
832
833 if ( in_array($field_label, $exclude) ) continue;
834
835 switch ($field_type)
836 {
837 case 'woo':
838 $exclude_fields = array('attributes');
839 if ( ! in_array($field_label, $exclude_fields)):
840 ?>
841 <option value="<?php echo 'cf_' . $field_label; ?>"><?php echo $field_name; ?></option>
842 <?php
843 endif;
844 break;
845 case 'cf':
846 ?>
847 <option value="<?php echo 'cf_' . $field_label; ?>"><?php echo $field_name; ?></option>
848 <?php
849 break;
850 case 'cats':
851 case 'attr':
852 ?>
853 <option value="<?php echo 'tx_' . $field_label; ?>"><?php echo $field_name; ?></option>
854 <?php
855 break;
856 default:
857
858 if (self::$is_user_export)
859 {
860 switch ($field_label)
861 {
862 case 'id':
863 $field_label = strtoupper($field_label);
864 break;
865 case 'user_nicename':
866 ?>
867 <option value="user_role"><?php _e('User Role', 'wp_all_export_plugin'); ?></option>
868 <?php
869 break;
870 }
871 }
872 else
873 {
874 switch ($field_label) {
875 case 'id':
876 $field_label = strtoupper($field_label);
877 break;
878 case 'parent':
879 case 'author':
880 case 'author_username':
881 case 'author_email':
882 case 'author_first_name':
883 case 'author_last_name':
884 case 'status':
885 case 'title':
886 case 'content':
887 case 'date':
888 case 'excerpt':
889 $field_label = 'post_' . $field_label;
890 break;
891 case 'permalink':
892 $field_label = 'guid';
893 break;
894 case 'slug':
895 $field_label = 'post_name';
896 break;
897 case 'order':
898 $field_label = 'menu_order';
899 break;
900 case 'template':
901 $field_label = 'cf__wp_page_template';
902 break;
903 case 'format':
904 $field_label = 'tx_post_format';
905 break;
906 default:
907 # code...
908 break;
909 }
910 }
911 ?>
912 <option value="<?php echo $field_label; ?>"><?php echo $field_name; ?></option>
913 <?php
914 break;
915 }
916 ?>
917
918 <?php endforeach; ?>
919
920 <?php endif; ?>
921
922 <?php if ( ! empty($section['fields'])): ?>
923
924 <?php foreach ($section['fields'] as $key => $title) : ?>
925
926 <option value="<?php echo $key; ?>"><?php echo $title; ?></option>
927
928 <?php endforeach; ?>
929
930 <?php endif; ?>
931
932 </optgroup>
933
934 <?php
935
936 endif;
937
938 if ( ! empty($section['additional']) )
939 {
940 foreach ($section['additional'] as $sub_slug => $sub_section)
941 {
942 if ( $sub_slug == 'attributes' ) {
943 ?>
944 <optgroup label="<?php echo $sub_section['title']; ?>">
945 <?php
946 foreach ($sub_section['meta'] as $field) :
947
948 switch ($field['type']) {
949 case 'attr':
950 ?>
951 <option value="<?php echo 'tx_' . $field['label']; ?>"><?php echo $field['name']; ?></option>
952 <?php
953 break;
954 case 'cf':
955 ?>
956 <option value="<?php echo 'cf_' . $field['label']; ?>"><?php echo $field['name']; ?></option>
957 <?php
958 break;
959 default:
960 # code...
961 break;
962 }
963
964 endforeach;
965 ?>
966 </optgroup>
967 <?php
968 }
969 }
970 }
971 }
972 }
973
974 if ( ! self::$is_comment_export )
975 {
976 // Render Available ACF
977 self::$acf_export->render_filters();
978 }
979
980 }
981
982 public function render_new_field(){
983
984 ob_start();
985
986 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
987
988 // Render Available WooCommerce Orders Data
989 self::$woo_order_export->render_new_field();
990
991 if ( ! empty($available_sections) ):?>
992
993 <select class="wp-all-export-chosen-select" name="column_value_type" style="width:350px;">
994
995 <?php
996 foreach ($available_sections as $slug => $section)
997 {
998 if ( ! empty($this->available_data[$section['content']]) or ! empty($section['additional']) ):
999 ?>
1000 <optgroup label="<?php echo $section['title']; ?>">
1001
1002 <?php
1003 if ( ! empty($this->available_data[$section['content']]) )
1004 {
1005 foreach ($this->available_data[$section['content']] as $field)
1006 {
1007 $field_label = is_array($field) ? $field['label'] : $field;
1008 $field_type = is_array($field) ? $field['type'] : $slug;
1009 $field_name = is_array($field) ? $field['name'] : $field;
1010 $field_options = empty ($field['options']) ? '' : $field['options'];
1011
1012 if ( $field_type == 'cf' && $field_name == '_thumbnail_id' ) continue;
1013 ?>
1014 <option
1015 value="<?php echo $field_type;?>"
1016 label="<?php echo $field_label;?>"
1017 options="<?php echo $field_options; ?>"><?php echo $field_name;?></option>
1018 <?php
1019 }
1020 }
1021 ?>
1022
1023 </optgroup>
1024
1025 <?php
1026
1027 if ( ! empty($section['additional']) )
1028 {
1029 foreach ($section['additional'] as $sub_slug => $sub_section)
1030 {
1031 ?>
1032 <optgroup label="<?php echo $sub_section['title']; ?>">
1033
1034 <?php
1035 foreach ($sub_section['meta'] as $field)
1036 {
1037 $field_label = is_array($field) ? $field['label'] : $field;
1038 $field_type = is_array($field) ? $field['type'] : $slug;
1039 $field_name = is_array($field) ? $field['name'] : $field;
1040 $field_options = empty($field['options']) ? '{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}' : $field['options'];
1041 ?>
1042 <option
1043 value="<?php echo $field_type;?>"
1044 label="<?php echo $field_label;?>"
1045 options="<?php echo $field_options; ?>"><?php echo $field_name;?></option>
1046 <?php
1047 }
1048 ?>
1049 </optgroup>
1050 <?php
1051 }
1052 }
1053 endif;
1054 }
1055
1056 if ( ! self::$is_comment_export )
1057 {
1058 // Render Available ACF
1059 self::$acf_export->render_new_field();
1060 }
1061
1062 ?>
1063 <optgroup label="Advanced">
1064 <option value="sql" label="sql"><?php _e("SQL Query", "wp_all_export_plugin"); ?></option>
1065 </optgroup>
1066 </select>
1067 <?php
1068 endif;
1069
1070 return ob_get_clean();
1071
1072 }
1073
1074 public function parse_custom_xml_template(){
1075
1076 preg_match("%". self::XML_LOOP_START ."(.*)". self::XML_LOOP_END ."%", $this->post['custom_xml_template'], $matches);
1077 $parts = explode(self::XML_LOOP_START, $this->post['custom_xml_template']);
1078 $loopContent = $parts[1];
1079 $parts = explode(self::XML_LOOP_END, $loopContent);
1080 $loopContent = $parts[0];
1081 $line_numbers = substr_count($loopContent, "\n") +1;
1082
1083 $result['original_post_loop'] = $loopContent;
1084 $result['line_numbers'] = $line_numbers;
1085
1086 $custom_xml_template = str_replace("\n", "", $this->post['custom_xml_template']);
1087 // retrieve XML header
1088 preg_match("%(.*)". self::XML_LOOP_START ."%", $custom_xml_template, $matches);
1089 $result['custom_xml_template_header'] = empty($matches[1]) ? '' : rtrim($matches[1]);
1090 // retrieve XML POST LOOP
1091 preg_match("%". self::XML_LOOP_START ."(.*)". self::XML_LOOP_END ."%", $custom_xml_template, $matches);
1092 $result['custom_xml_template_loop'] = empty($matches[1]) ? '' : rtrim($matches[1]);
1093 // retrieve XML footer
1094 preg_match("%". self::XML_LOOP_END ."(.*)%", $custom_xml_template, $matches);
1095 $result['custom_xml_template_footer'] = empty($matches[1]) ? '' : $matches[1];
1096
1097 // Validate Custom XML Template header
1098 if ( empty($result['custom_xml_template_header']) )
1099 {
1100 $this->errors->add('form-validation', __('Missing custom XML template header.', 'wp_all_export_plugin'));
1101 }
1102 // Validate Custom XML Template post LOOP
1103 if ( empty($result['custom_xml_template_loop']) )
1104 {
1105 $this->errors->add('form-validation', __('Missing custom XML template post loop.', 'wp_all_export_plugin'));
1106 }
1107 // Validate Custom XML Template footer
1108 if ( empty($result['custom_xml_template_footer']) )
1109 {
1110 $this->errors->add('form-validation', __('Missing custom XML template footer.', 'wp_all_export_plugin'));
1111 }
1112
1113 if ( ! $this->errors->get_error_codes()) {
1114
1115 // retrieve all placeholders in the XML loop
1116 preg_match_all("%(\[[^\]\[]*\])%", $result['custom_xml_template_loop'], $matches);
1117 $loop_placeholders = empty($matches) ? array() : $matches[0];
1118
1119 $field_keys = array();
1120 // looking for placeholders e.q. {Post Type}, {Title}
1121 if ( ! empty($loop_placeholders) ){
1122
1123 foreach ($loop_placeholders as $snippet) {
1124 preg_match("%\{(.*)\}%", $snippet, $matches);
1125 if ( ! empty($matches[1]) ) $field_keys[] = $matches[1];
1126 }
1127 }
1128
1129 preg_match_all("%(\{[^\}\{]*\})%", $result['custom_xml_template_loop'], $matches);
1130 $loop_placeholders = empty($matches) ? array() : $matches[0];
1131
1132 $field_keys = array();
1133 // looking for placeholders e.q. {Post Type}, {Title}
1134 if ( ! empty($loop_placeholders) ){
1135
1136 foreach ($loop_placeholders as $snippet) {
1137 preg_match("%\{(.*)\}%", $snippet, $matches);
1138 if ( ! empty($matches[1]) and ! in_array($matches[1], $field_keys)) $field_keys[] = $matches[1];
1139 }
1140 }
1141
1142 if (!empty($field_keys)){
1143 $result['custom_xml_template_options'] = $this->get_fields_options( $field_keys );
1144 }
1145 }
1146 return $result;
1147 }
1148
1149 /**
1150 * __get function.
1151 *
1152 * @access public
1153 * @param mixed $key
1154 * @return mixed
1155 */
1156 public function __get( $key ) {
1157 return $this->get( $key );
1158 }
1159
1160 /**
1161 * Get a session variable
1162 *
1163 * @param string $key
1164 * @param mixed $default used if the session variable isn't set
1165 * @return mixed value of session variable
1166 */
1167 public function get( $key, $default = null ) {
1168 return isset( $this->{$key} ) ? $this->{$key} : $default;
1169 }
1170
1171 public static function getProductVariationMode()
1172 {
1173 if(!isset(self::$exportOptions['export_variations'])) {
1174 self::$exportOptions['export_variations'] = self::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION;
1175 }
1176
1177 return apply_filters('wp_all_export_product_variation_mode', self::$exportOptions['export_variations'], self::$exportID);
1178 }
1179
1180 public static function getProductVariationTitleMode()
1181 {
1182 if(!isset(self::$exportOptions['export_variations_title'])) {
1183 self::$exportOptions['export_variations_title'] = self::VARIATION_USE_PARENT_TITLE;
1184 }
1185
1186 return self::$exportOptions['export_variations_title'];
1187 }
1188
1189 public static function sanitizeFieldName($fieldName)
1190 {
1191 if (class_exists('XmlExportWooCommerce') && XmlExportWooCommerce::$is_active) {
1192 return urldecode($fieldName);
1193 }
1194
1195 return $fieldName;
1196 }
1197 }
1198
1199 }
1200