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