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