PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.3.1
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.3.1
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 4 years ago XmlExportComment.php 8 years ago XmlExportCpt.php 4 years ago XmlExportEngine.php 4 years ago XmlExportFiltering.php 9 years ago XmlExportMediaGallery.php 6 years ago XmlExportTaxonomy.php 9 years ago XmlGoogleMerchants.php 9 years ago XmlSpec.php 9 years ago
XmlExportEngine.php
1280 lines
1 <?php
2
3 if ( ! class_exists('XmlExportEngine') ){
4
5 require_once dirname(__FILE__) . '/XmlExportComment.php';
6 require_once dirname(__FILE__) . '/XmlExportTaxonomy.php';
7
8 final class XmlExportEngine
9 {
10
11 const VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION = 1;
12 const VARIABLE_PRODUCTS_EXPORT_VARIATION = 2;
13 const VARIABLE_PRODUCTS_EXPORT_PARENT = 3;
14
15 const VARIATION_USE_PARENT_TITLE = 1;
16 const VARIATION_USE_DEFAULT_TITLE = 2;
17
18 /**
19 * Custom XML Loop begin statement
20 * @var string
21 */
22 const XML_LOOP_START = '<!-- BEGIN LOOP -->';
23
24 /**
25 * Custom XML Loop end statement
26 * @var string
27 */
28 const XML_LOOP_END = '<!-- END LOOP -->';
29
30 const EXPORT_TYPE_GOOLE_MERCHANTS = 'XmlGoogleMerchants';
31 const EXPORT_TYPE_XML = 'xml';
32 const EXPORT_TYPE_CSV = 'csv';
33
34 public static $acf_export;
35 public static $woo_export = false;
36 public static $woo_order_export;
37 public static $woo_coupon_export;
38 public static $woo_refund_export;
39 public static $woo_review_export;
40 public static $user_export = false;
41 public static $comment_export;
42 public static $taxonomy_export;
43
44 public static $is_preview = false;
45
46 public static $implode = ',';
47
48 private $post;
49 private $_existing_meta_keys = array();
50 private $_existing_taxonomies = array();
51
52 private static $addons_service = false;
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::$comment_export = new XmlExportComment();
444 self::$taxonomy_export = new XmlExportTaxonomy();
445 do_action('pmxe_init_addons');
446 }
447
448 // [FILTERS]
449
450 /**
451 *
452 * Filter data for advanced filtering
453 *
454 */
455 public function filter_export_filters($filters){
456 return array_merge($filters, $this->filter_sections);
457 }
458
459 // [\FILTERS]
460
461 protected function init(){
462
463 PMXE_Plugin::$session->set('is_user_export', self::$is_user_export);
464 PMXE_Plugin::$session->set('is_comment_export', self::$is_comment_export);
465 PMXE_Plugin::$session->set('is_taxonomy_export', self::$is_taxonomy_export);
466 PMXE_Plugin::$session->save_data();
467
468 if ('advanced' == $this->post['export_type']) {
469
470 if( "" == $this->post['wp_query'] ){
471 $this->errors->add('form-validation', __('WP Query field is required', 'pmxe_plugin'));
472 }
473 else if(!XmlExportEngine::get_addons_service()->isWooCommerceAddonActive() && strpos($this->post['wp_query'], 'product') !== false) {
474 $this->errors->add('form-validation', __('The WooCommerce Export Add-On Pro is required to Export WooCommerce Products', 'pmxe_plugin'));
475 }
476 else if(!XmlExportEngine::get_addons_service()->isWooCommerceAddonActive() && strpos($this->post['wp_query'], 'shop_order') !== false) {
477 $this->errors->add('form-validation', __('The WooCommerce Export Add-On Pro is required to Export WooCommerce Orders', 'pmxe_plugin'));
478 }
479 else if(!XmlExportEngine::get_addons_service()->isWooCommerceAddonActive() && strpos($this->post['wp_query'], 'shop_coupon') !== false) {
480 $this->errors->add('form-validation', __('The WooCommerce Export Add-On Pro is required to Export WooCommerce Coupons', 'pmxe_plugin'));
481 }
482 else
483 {
484 $this->filters->parse();
485
486 PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere'));
487 PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin'));
488 PMXE_Plugin::$session->set('wp_query', $this->post['wp_query']);
489 PMXE_Plugin::$session->save_data();
490 }
491 }
492 else
493 {
494 $this->filters->parse();
495
496 PMXE_Plugin::$session->set('cpt', self::$post_types);
497 PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere'));
498 PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin'));
499 PMXE_Plugin::$session->save_data();
500 }
501
502 PMXE_Plugin::$session->save_data();
503
504 }
505
506 public function init_additional_data(){
507
508 if(self::$woo_export) {
509 self::$woo_order_export->init_additional_data();
510 self::$woo_export->init_additional_data();
511 }
512 }
513
514 public function init_available_data(){
515
516 global $wpdb;
517 $table_prefix = $wpdb->prefix;
518
519 // Prepare existing taxonomies
520 if ( 'specific' == $this->post['export_type'] and ! self::$is_user_export and ! self::$is_comment_export and ! self::$is_taxonomy_export )
521 {
522 $this->_existing_taxonomies = wp_all_export_get_existing_taxonomies_by_cpt( self::$post_types[0] );
523
524 $this->_existing_meta_keys = wp_all_export_get_existing_meta_by_cpt( self::$post_types[0] );
525 }
526 if ( 'advanced' == $this->post['export_type'] and ! self::$is_user_export and ! self::$is_comment_export and ! self::$is_taxonomy_export )
527 {
528 $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");
529 if ( ! empty($meta_keys)){
530 $exclude_keys = array('_first_variation_attributes', '_is_first_variation_created');
531 foreach ($meta_keys as $meta_key) {
532 if ( strpos($meta_key->meta_key, "_tmp") === false && strpos($meta_key->meta_key, "_v_") === false && ! in_array($meta_key->meta_key, $exclude_keys))
533 $this->_existing_meta_keys[] = $meta_key->meta_key;
534 }
535 }
536
537 global $wp_taxonomies;
538
539 foreach ($wp_taxonomies as $key => $obj) { if (in_array($obj->name, array('nav_menu'))) continue;
540
541 if (strpos($obj->name, "pa_") !== 0 and strlen($obj->name) > 3)
542 $this->_existing_taxonomies[] = array(
543 'name' => empty($obj->label) ? $obj->name : $obj->label,
544 'label' => $obj->name,
545 'type' => 'cats'
546 );
547 }
548 }
549
550 if(self::$acf_export) {
551 // Prepare existing ACF groups & fields
552 self::$acf_export->init($this->_existing_meta_keys);
553 }
554
555 if(XmlExportEngine::$woo_export) {
556 // Prepare existing WooCommerce data
557 self::$woo_export->init($this->_existing_meta_keys);
558
559 // Prepare existing WooCommerce Order data
560 self::$woo_order_export->init($this->_existing_meta_keys);
561
562 // Prepare existing WooCommerce Coupon data
563 self::$woo_coupon_export->init($this->_existing_meta_keys);
564 }
565
566 if(XmlExportEngine::$user_export) {
567 // Prepare existing Users data
568 self::$user_export->init($this->_existing_meta_keys);
569 }
570
571 // Prepare existing Comments data
572 self::$comment_export->init($this->_existing_meta_keys);
573
574 // Prepare existing Taxonomy data
575 self::$taxonomy_export->init($this->_existing_meta_keys);
576
577 return $this->get_available_data();
578 }
579
580 public function get_available_data(){
581
582 if(self::$acf_export) {
583 $this->available_data['acf_groups'] = self::$acf_export->get('_acf_groups');
584 $this->available_data['existing_acf_meta_keys'] = self::$acf_export->get('_existing_acf_meta_keys');
585 }
586
587 $this->available_data['existing_meta_keys'] = $this->_existing_meta_keys;
588 $this->available_data['existing_taxonomies'] = $this->_existing_taxonomies;
589
590 $this->available_data['init_fields'] = apply_filters('wp_all_export_init_fields', $this->init_fields);
591 $this->available_data['default_fields'] = apply_filters('wp_all_export_default_fields', self::$default_fields);
592 $this->available_data['other_fields'] = apply_filters('wp_all_export_other_fields', $this->other_fields);
593
594 $this->available_data = apply_filters("wp_all_export_available_data", $this->available_data);
595
596 return $this->available_data;
597
598 }
599
600 public function get_fields_options( $field_keys = array() ){
601
602 $fields = array(
603 'ids' => array(),
604 'cc_label' => array(),
605 'cc_php' => array(),
606 'cc_code' => array(),
607 'cc_sql' => array(),
608 'cc_options' => array(),
609 'cc_type' => array(),
610 'cc_value' => array(),
611 'cc_name' => array(),
612 'cc_settings' => array()
613 );
614
615 self::$woo_order_export->get_fields_options( $fields, $field_keys );
616
617 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
618
619 foreach ($available_sections as $slug => $section)
620 {
621 if ( ! empty($this->available_data[$section['content']]) ):
622
623 foreach ($this->available_data[$section['content']] as $field)
624 {
625
626 $field_key = (is_array($field)) ? $field['name'] : $field;
627
628 if ( ! in_array($field_key, $field_keys) ) continue;
629
630 $fields['ids'][] = 1;
631 $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $field;
632 $fields['cc_php'][] = '';
633 $fields['cc_code'][] = '';
634 $fields['cc_sql'][] = '';
635 $fields['cc_options'][] = '';
636 $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $slug;
637 $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $field;
638 $fields['cc_name'][] = $field_key;
639 $fields['cc_settings'][] = '';
640 }
641 endif;
642
643 if ( ! empty($section['additional']) )
644 {
645 foreach ($section['additional'] as $sub_slug => $sub_section)
646 {
647
648 foreach ($sub_section['meta'] as $field) {
649 $key_to_check = (is_array($field)) ? $field['name'] : $field;
650
651 if ( in_array($sub_slug, array('images', 'attachments')) ){
652 $key_to_check = preg_replace("%s$%","",ucfirst($sub_slug)) . ' ' . $key_to_check;
653 }
654
655 if ( ! in_array($key_to_check, $field_keys) ) continue;
656
657 $field_options = ( in_array($sub_slug, array('images', 'attachments')) ) ? esc_attr('{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}') : '0';
658
659 $fields['ids'][] = 1;
660 $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $field;
661 $fields['cc_php'][] = '';
662 $fields['cc_code'][] = '';
663 $fields['cc_sql'][] = '';
664 $fields['cc_options'][] = $field_options;
665 $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $sub_slug;
666 $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $field;
667 $fields['cc_name'][] = $key_to_check;
668 $fields['cc_settings'][] = '';
669 }
670 }
671 }
672 }
673
674 if ( ! self::$is_comment_export )
675 {
676 if(self::$acf_export) {
677 self::$acf_export->get_fields_options( $fields, $field_keys );
678 }
679 }
680
681 $sort_fields = array();
682 foreach ($field_keys as $i => $field_key){
683 foreach ($fields['cc_name'] as $j => $cc_name){
684 if (!empty($cc_name) && $cc_name == $field_key){
685 $sort_fields['ids'][] = 1;
686 $sort_fields['cc_label'][] = $fields['cc_label'][$j];
687 $sort_fields['cc_php'][] = $fields['cc_php'][$j];
688 $sort_fields['cc_code'][] = $fields['cc_code'][$j];
689 $sort_fields['cc_sql'][] = $fields['cc_sql'][$j];
690 $sort_fields['cc_options'][] = $fields['cc_options'][$j];
691 $sort_fields['cc_type'][] = $fields['cc_type'][$j];
692 $sort_fields['cc_value'][] = $fields['cc_value'][$j];
693 $sort_fields['cc_name'][] = $fields['cc_name'][$j];
694 $sort_fields['cc_settings'][] = $fields['cc_settings'][$j];
695 break;
696 }
697 }
698 }
699
700 return $sort_fields;
701
702 }
703
704 public function render(){
705
706 $i = 0;
707
708 ob_start();
709
710 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
711 self::$globalAvailableSections = $available_sections;
712
713 if(self::$woo_export) {
714 // Render Available WooCommerce Orders Data
715 self::$woo_order_export->render($i);
716 }
717
718 foreach ($available_sections as $slug => $section)
719 {
720
721 if ( ! empty($this->available_data[$section['content']]) or ! empty($section['additional']) ):
722 ?>
723 <p class="wpae-available-fields-group"><?php echo $section['title']; ?><span class="wpae-expander">+</span></p>
724 <div class="wpae-custom-field">
725 <?php
726 if($slug == 'cf' && XmlExportEngine::$is_user_export) {
727 ?>
728 <div class="wpallexport-free-edition-notice">
729 <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>
730 </div>
731 <?php
732 }
733 ?>
734 <?php
735 if($slug == 'other' && XmlExportEngine::$is_user_export) {
736 ?>
737 <div class="wpallexport-free-edition-notice">
738 <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>
739 </div>
740 <?php
741 }
742 $elementClass = "";
743 if(($slug == 'cf' || $slug == 'other') && XmlExportEngine::$is_user_export){
744 $elementClass = 'wpallexport_disabled';
745 }
746 ?>
747 <ul>
748 <?php if ( ! empty($this->available_data[$section['content']]) ): ?>
749 <li class="<?php echo $elementClass; ?>">
750 <div class="default_column" rel="">
751 <label class="wpallexport-element-label"><?php echo __("All", "wp_all_export_plugin") . ' ' . $section['title']; ?></label>
752 <input type="hidden" name="rules[]" value="pmxe_<?php echo $slug; ?>"/>
753 </div>
754 </li>
755 <?php
756 foreach ($this->available_data[$section['content']] as $field)
757 {
758 $field_type = is_array($field) ? $field['type'] : $slug;
759 $field_name = is_array($field) ? $field['name'] : $field;
760
761 if ( $field_type == 'cf' && $field_name == '_thumbnail_id' ) continue;
762
763 $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'))));
764
765 ?>
766 <li class="pmxe_<?php echo $slug; ?> <?php if ( $is_auto_field ) echo 'wp_all_export_auto_generate';?> <?php echo $elementClass;?>">
767 <div class="custom_column" rel="<?php echo ($i + 1);?>">
768 <label class="wpallexport-xml-element"><?php echo (is_array($field)) ? $field['name'] : $field; ?></label>
769 <input type="hidden" name="ids[]" value="1"/>
770 <input type="hidden" name="cc_label[]" value="<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/>
771 <input type="hidden" name="cc_php[]" value="0"/>
772 <input type="hidden" name="cc_code[]" value=""/>
773 <input type="hidden" name="cc_sql[]" value="0"/>
774 <input type="hidden" name="cc_options[]" value="0"/>
775 <input type="hidden" name="cc_type[]" value="<?php echo (is_array($field)) ? $field['type'] : $slug; ?>"/>
776 <input type="hidden" name="cc_value[]" value="<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/>
777 <input type="hidden" name="cc_name[]" value="<?php echo (is_array($field)) ? $field['name'] : $field;?>"/>
778 <input type="hidden" name="cc_settings[]" value="0"/>
779 </div>
780 </li>
781 <?php
782 $i++;
783 }
784 endif;
785
786 if ( ! empty($section['additional']) )
787 {
788 foreach ($section['additional'] as $sub_slug => $sub_section)
789 {
790 ?>
791 <li class="available_sub_section">
792 <p class="wpae-available-fields-group"><?php echo $sub_section['title']; ?><span class="wpae-expander">+</span></p>
793 <div class="wpae-custom-field">
794 <ul>
795 <li>
796 <div class="default_column" rel="">
797 <label class="wpallexport-element-label"><?php echo __("All", "wp_all_export_plugin") . ' ' . $sub_section['title']; ?></label>
798 <input type="hidden" name="rules[]" value="pmxe_<?php echo $slug;?>_<?php echo $sub_slug;?>"/>
799 </div>
800 </li>
801 <?php
802 foreach ($sub_section['meta'] as $field) {
803 $is_auto_field = empty($field['auto']) ? false : true;
804 $field_options = ( in_array($sub_slug, array('images', 'attachments')) ) ? esc_attr('{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}') : '0';
805 ?>
806 <li class="pmxe_<?php echo $slug; ?>_<?php echo $sub_slug;?> <?php if ( $is_auto_field ) echo 'wp_all_export_auto_generate';?>">
807 <div class="custom_column" rel="<?php echo ($i + 1);?>">
808 <label class="wpallexport-xml-element"><?php echo (is_array($field)) ? XmlExportEngine::sanitizeFieldName($field['name']) : $field; ?></label>
809 <input type="hidden" name="ids[]" value="1"/>
810 <input type="hidden" name="cc_label[]" value="<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/>
811 <input type="hidden" name="cc_php[]" value="0"/>
812 <input type="hidden" name="cc_code[]" value="0"/>
813 <input type="hidden" name="cc_sql[]" value="0"/>
814 <input type="hidden" name="cc_options[]" value="<?php echo $field_options; ?>"/>
815 <input type="hidden" name="cc_type[]" value="<?php echo (is_array($field)) ? $field['type'] : $sub_slug; ?>"/>
816 <input type="hidden" name="cc_value[]" value="<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/>
817 <input type="hidden" name="cc_name[]" value="<?php echo (is_array($field)) ? XmlExportEngine::sanitizeFieldName($field['name']) : $field;?>"/>
818 <input type="hidden" name="cc_settings[]" value=""/>
819 </div>
820 </li>
821 <?php
822 $i++;
823 }
824 ?>
825 </ul>
826 </li>
827 <?php
828 }
829 }
830 ?>
831 </ul>
832 </div>
833 <?php
834 endif;
835 }
836
837 if ( ! self::$is_comment_export )
838 {
839 if(self::$acf_export) {
840 // Render Available ACF
841 self::$acf_export->render($i);
842 } else {
843 if(!self::get_addons_service()->isAcfAddonActive()) {
844 ?>
845 <p class="wpae-available-fields-group">ACF<span class="wpae-expander">+</span></p>
846 <div class="wpae-custom-field">
847
848 <div class="wpallexport-free-edition-notice">
849 <a class="upgrade_link" target="_blank"
850 href="https://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=4206907&edd_options%5Bprice_id%5D=1&utm_source=export-plugin-free&utm_medium=upgrade-notice&utm_campaign=export-advanced-custom-fields">Upgrade to the ACF Export Package to Export Advanced Custom Fields</a>
851 </div>
852 </div>
853 <?php
854 }
855
856 }
857 }
858
859 return ob_get_clean();
860
861 }
862
863 public function render_filters(){
864
865 $available_sections = apply_filters("wp_all_export_available_sections", apply_filters('wp_all_export_filters', $this->available_sections) );
866
867 if(self::$woo_export) {
868 // Render Filters for WooCommerce Orders
869 self::$woo_order_export->render_filters();
870 }
871
872 if ( ! empty($available_sections) )
873 {
874 $exclude = array('wpml_lang', 'wpml_trid');
875
876 foreach ($available_sections as $slug => $section)
877 {
878 if ( ! empty($section['content']) and ! empty($this->available_data[$section['content']]) or ! empty($section['fields'])):
879 ?>
880
881 <optgroup label="<?php echo $section['title']; ?>">
882
883 <?php if ( ! empty($section['content']) && ! empty($this->available_data[$section['content']]) ): ?>
884
885 <?php foreach ($this->available_data[$section['content']] as $field) : ?>
886
887 <?php
888
889 $field_label = is_array($field) ? $field['label'] : $field;
890 $field_type = is_array($field) ? $field['type'] : $slug;
891 $field_name = is_array($field) ? $field['name'] : $field;
892
893 if ( in_array($field_label, $exclude) ) continue;
894
895 switch ($field_type)
896 {
897 case 'woo':
898 $exclude_fields = array('attributes');
899 if ( ! in_array($field_label, $exclude_fields)):
900 ?>
901 <option value="<?php echo 'cf_' . $field_label; ?>"><?php echo $field_name; ?></option>
902 <?php
903 endif;
904 break;
905 case 'cf':
906 ?>
907 <option value="<?php echo 'cf_' . $field_label; ?>"><?php echo $field_name; ?></option>
908 <?php
909 break;
910 case 'cats':
911 case 'attr':
912 ?>
913 <option value="<?php echo 'tx_' . $field_label; ?>"><?php echo $field_name; ?></option>
914 <?php
915 break;
916 default:
917
918 if (self::$is_user_export)
919 {
920 switch ($field_label)
921 {
922 case 'id':
923 $field_label = strtoupper($field_label);
924 break;
925 case 'user_nicename':
926 ?>
927 <option value="user_role"><?php _e('User Role', 'wp_all_export_plugin'); ?></option>
928 <?php
929 break;
930 }
931 }
932 else
933 {
934 switch ($field_label) {
935 case 'id':
936 $field_label = strtoupper($field_label);
937 break;
938 case 'parent':
939 case 'author':
940 case 'author_username':
941 case 'author_email':
942 case 'author_first_name':
943 case 'author_last_name':
944 case 'status':
945 case 'title':
946 case 'content':
947 case 'date':
948 case 'excerpt':
949 $field_label = 'post_' . $field_label;
950 break;
951 case 'permalink':
952 $field_label = 'guid';
953 break;
954 case 'slug':
955 $field_label = 'post_name';
956 break;
957 case 'order':
958 $field_label = 'menu_order';
959 break;
960 case 'template':
961 $field_label = 'cf__wp_page_template';
962 break;
963 case 'format':
964 $field_label = 'tx_post_format';
965 break;
966 default:
967 # code...
968 break;
969 }
970 }
971 ?>
972 <option value="<?php echo $field_label; ?>"><?php echo $field_name; ?></option>
973 <?php
974 break;
975 }
976 ?>
977
978 <?php endforeach; ?>
979
980 <?php endif; ?>
981
982 <?php if ( ! empty($section['fields'])): ?>
983
984 <?php foreach ($section['fields'] as $key => $title) : ?>
985
986 <option value="<?php echo $key; ?>"><?php echo $title; ?></option>
987
988 <?php endforeach; ?>
989
990 <?php endif; ?>
991
992 </optgroup>
993
994 <?php
995
996 endif;
997
998 if ( ! empty($section['additional']) )
999 {
1000 foreach ($section['additional'] as $sub_slug => $sub_section)
1001 {
1002 if ( $sub_slug == 'attributes' ) {
1003 ?>
1004 <optgroup label="<?php echo $sub_section['title']; ?>">
1005 <?php
1006 foreach ($sub_section['meta'] as $field) :
1007
1008 switch ($field['type']) {
1009 case 'attr':
1010 ?>
1011 <option value="<?php echo 'tx_' . $field['label']; ?>"><?php echo $field['name']; ?></option>
1012 <?php
1013 break;
1014 case 'cf':
1015 ?>
1016 <option value="<?php echo 'cf_' . $field['label']; ?>"><?php echo $field['name']; ?></option>
1017 <?php
1018 break;
1019 default:
1020 # code...
1021 break;
1022 }
1023
1024 endforeach;
1025 ?>
1026 </optgroup>
1027 <?php
1028 }
1029 }
1030 }
1031 }
1032 }
1033
1034 if ( ! self::$is_comment_export )
1035 {
1036 if(self::$acf_export) {
1037 // Render Available ACF
1038 self::$acf_export->render_filters();
1039 }
1040 }
1041
1042 }
1043
1044 public function render_new_field(){
1045
1046 ob_start();
1047
1048 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
1049
1050 if(self::$woo_export) {
1051 // Render Available WooCommerce Orders Data
1052 self::$woo_order_export->render_new_field();
1053 }
1054
1055 if ( ! empty($available_sections) ):?>
1056
1057 <select class="wp-all-export-chosen-select" name="column_value_type" style="width:350px;">
1058
1059 <?php
1060 foreach ($available_sections as $slug => $section)
1061 {
1062 if ( ! empty($this->available_data[$section['content']]) or ! empty($section['additional']) ):
1063 ?>
1064 <optgroup label="<?php echo $section['title']; ?>">
1065
1066 <?php
1067 if ( ! empty($this->available_data[$section['content']]) )
1068 {
1069 foreach ($this->available_data[$section['content']] as $field)
1070 {
1071 $field_label = is_array($field) ? $field['label'] : $field;
1072 $field_type = is_array($field) ? $field['type'] : $slug;
1073 $field_name = is_array($field) ? $field['name'] : $field;
1074 $field_options = empty ($field['options']) ? '' : $field['options'];
1075
1076 if ( $field_type == 'cf' && $field_name == '_thumbnail_id' || ($field_type=='other')) continue;
1077 $elementDisabled = "";
1078 if(($section['title'] == 'Custom Fields' || $section['title'] == 'Other') && XmlExportEngine::$is_user_export) {
1079 $elementDisabled = "disabled='disabled'";
1080 }
1081 ?>
1082 <option
1083 value="<?php echo $field_type;?>"
1084 label="<?php echo $field_label;?>"
1085 <?php echo $elementDisabled; ?>
1086 options="<?php echo $field_options; ?>"><?php echo $field_name;?></option>
1087 <?php
1088 }
1089 }
1090 ?>
1091
1092 </optgroup>
1093
1094 <?php
1095
1096 if ( ! empty($section['additional']) )
1097 {
1098 foreach ($section['additional'] as $sub_slug => $sub_section)
1099 {
1100 ?>
1101 <optgroup label="<?php echo $sub_section['title']; ?>">
1102
1103 <?php
1104 foreach ($sub_section['meta'] as $field)
1105 {
1106 $field_label = is_array($field) ? $field['label'] : $field;
1107 $field_type = is_array($field) ? $field['type'] : $slug;
1108 $field_name = is_array($field) ? $field['name'] : $field;
1109 $field_options = empty($field['options']) ? '{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}' : $field['options'];
1110 ?>
1111 <option
1112 value="<?php echo $field_type;?>"
1113 label="<?php echo $field_label;?>"
1114 options="<?php echo $field_options; ?>"><?php echo $field_name;?></option>
1115 <?php
1116 }
1117 ?>
1118 </optgroup>
1119 <?php
1120 }
1121 }
1122 endif;
1123 }
1124
1125 if ( ! self::$is_comment_export )
1126 {
1127 if(self::$acf_export) {
1128 // Render Available ACF
1129 self::$acf_export->render_new_field();
1130 }
1131 }
1132
1133 ?>
1134 <optgroup label="Advanced">
1135 <option value="sql" label="sql"><?php _e("SQL Query", "wp_all_export_plugin"); ?></option>
1136 </optgroup>
1137 </select>
1138 <?php
1139 endif;
1140
1141 return ob_get_clean();
1142
1143 }
1144
1145 public function parse_custom_xml_template(){
1146
1147 preg_match("%". self::XML_LOOP_START ."(.*)". self::XML_LOOP_END ."%", $this->post['custom_xml_template'], $matches);
1148 $parts = explode(self::XML_LOOP_START, $this->post['custom_xml_template']);
1149 $loopContent = $parts[1];
1150 $parts = explode(self::XML_LOOP_END, $loopContent);
1151 $loopContent = $parts[0];
1152 $line_numbers = substr_count($loopContent, "\n") +1;
1153
1154 $result['original_post_loop'] = $loopContent;
1155 $result['line_numbers'] = $line_numbers;
1156
1157 $custom_xml_template = str_replace("\n", "", $this->post['custom_xml_template']);
1158 // retrieve XML header
1159 preg_match("%(.*)". self::XML_LOOP_START ."%", $custom_xml_template, $matches);
1160 $result['custom_xml_template_header'] = empty($matches[1]) ? '' : rtrim($matches[1]);
1161 // retrieve XML POST LOOP
1162 preg_match("%". self::XML_LOOP_START ."(.*)". self::XML_LOOP_END ."%", $custom_xml_template, $matches);
1163 $result['custom_xml_template_loop'] = empty($matches[1]) ? '' : rtrim($matches[1]);
1164 // retrieve XML footer
1165 preg_match("%". self::XML_LOOP_END ."(.*)%", $custom_xml_template, $matches);
1166 $result['custom_xml_template_footer'] = empty($matches[1]) ? '' : $matches[1];
1167
1168 // Validate Custom XML Template header
1169 if ( empty($result['custom_xml_template_header']) )
1170 {
1171 $this->errors->add('form-validation', __('Missing custom XML template header.', 'wp_all_export_plugin'));
1172 }
1173 // Validate Custom XML Template post LOOP
1174 if ( empty($result['custom_xml_template_loop']) )
1175 {
1176 $this->errors->add('form-validation', __('Missing custom XML template post loop.', 'wp_all_export_plugin'));
1177 }
1178 // Validate Custom XML Template footer
1179 if ( empty($result['custom_xml_template_footer']) )
1180 {
1181 $this->errors->add('form-validation', __('Missing custom XML template footer.', 'wp_all_export_plugin'));
1182 }
1183
1184 if ( ! $this->errors->get_error_codes()) {
1185
1186 // retrieve all placeholders in the XML loop
1187 preg_match_all("%(\[[^\]\[]*\])%", $result['custom_xml_template_loop'], $matches);
1188 $loop_placeholders = empty($matches) ? array() : $matches[0];
1189
1190 $field_keys = array();
1191 // looking for placeholders e.q. {Post Type}, {Title}
1192 if ( ! empty($loop_placeholders) ){
1193
1194 foreach ($loop_placeholders as $snippet) {
1195 preg_match("%\{(.*)\}%", $snippet, $matches);
1196 if ( ! empty($matches[1]) ) $field_keys[] = $matches[1];
1197 }
1198 }
1199
1200 preg_match_all("%(\{[^\}\{]*\})%", $result['custom_xml_template_loop'], $matches);
1201 $loop_placeholders = empty($matches) ? array() : $matches[0];
1202
1203 $field_keys = array();
1204 // looking for placeholders e.q. {Post Type}, {Title}
1205 if ( ! empty($loop_placeholders) ){
1206
1207 foreach ($loop_placeholders as $snippet) {
1208 preg_match("%\{(.*)\}%", $snippet, $matches);
1209 if ( ! empty($matches[1]) and ! in_array($matches[1], $field_keys)) $field_keys[] = $matches[1];
1210 }
1211 }
1212
1213 if (!empty($field_keys)){
1214 $result['custom_xml_template_options'] = $this->get_fields_options( $field_keys );
1215 }
1216 }
1217 return $result;
1218 }
1219
1220 /**
1221 * __get function.
1222 *
1223 * @access public
1224 * @param mixed $key
1225 * @return mixed
1226 */
1227 public function __get( $key ) {
1228 return $this->get( $key );
1229 }
1230
1231 /**
1232 * Get a session variable
1233 *
1234 * @param string $key
1235 * @param mixed $default used if the session variable isn't set
1236 * @return mixed value of session variable
1237 */
1238 public function get( $key, $default = null ) {
1239 return isset( $this->{$key} ) ? $this->{$key} : $default;
1240 }
1241
1242 public static function getProductVariationMode()
1243 {
1244 if(!isset(self::$exportOptions['export_variations'])) {
1245 self::$exportOptions['export_variations'] = self::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION;
1246 }
1247
1248 return apply_filters('wp_all_export_product_variation_mode', self::$exportOptions['export_variations'], self::$exportID);
1249 }
1250
1251 public static function getProductVariationTitleMode()
1252 {
1253 if(!isset(self::$exportOptions['export_variations_title'])) {
1254 self::$exportOptions['export_variations_title'] = self::VARIATION_USE_PARENT_TITLE;
1255 }
1256
1257 return self::$exportOptions['export_variations_title'];
1258 }
1259
1260 public static function sanitizeFieldName($fieldName)
1261 {
1262 if (class_exists('XmlExportWooCommerce') && XmlExportWooCommerce::$is_active) {
1263 return urldecode($fieldName);
1264 }
1265
1266 return $fieldName;
1267 }
1268
1269 public static function get_addons_service()
1270 {
1271 if(!self::$addons_service) {
1272 self::$addons_service = new Wpae\App\Service\Addons\AddonService();
1273 }
1274
1275 return self::$addons_service;
1276 }
1277 }
1278
1279 }
1280