PluginProbe ʕ •ᴥ•ʔ
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel / 1.3.4
WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel v1.3.4
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 4 years ago XmlExportCpt.php 4 years ago XmlExportCustomRecord.php 4 years ago XmlExportEngine.php 4 years ago XmlExportFiltering.php 4 years ago XmlExportMediaGallery.php 7 years ago XmlExportTaxonomy.php 4 years ago XmlGoogleMerchants.php 9 years ago XmlSpec.php 9 years ago
XmlExportEngine.php
1336 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 public static $custom_record_export;
44
45 public static $is_preview = false;
46
47 public static $implode = ',';
48
49 private $post;
50 private $_existing_meta_keys = array();
51 private $_existing_taxonomies = array();
52
53 private static $addons_service = false;
54
55 private $init_fields = array(
56 array(
57 'label' => 'id',
58 'name' => 'ID',
59 'type' => 'id'
60 ),
61 array(
62 'label' => 'title',
63 'name' => 'Title',
64 'type' => 'title'
65 ),
66 array(
67 'label' => 'content',
68 'name' => 'Content',
69 'type' => 'content'
70 )
71 );
72
73 public static $default_fields = array(
74 array(
75 'label' => 'id',
76 'name' => 'ID',
77 'type' => 'id'
78 ),
79 array(
80 'label' => 'title',
81 'name' => 'Title',
82 'type' => 'title'
83 ),
84 array(
85 'label' => 'content',
86 'name' => 'Content',
87 'type' => 'content'
88 ),
89 array(
90 'label' => 'excerpt',
91 'name' => 'Excerpt',
92 'type' => 'excerpt'
93 ),
94 array(
95 'label' => 'date',
96 'name' => 'Date',
97 'type' => 'date'
98 ),
99 array(
100 'label' => 'post_type',
101 'name' => 'Post Type',
102 'type' => 'post_type'
103 ),
104 array(
105 'label' => 'permalink',
106 'name' => 'Permalink',
107 'type' => 'permalink'
108 )
109 );
110
111 private $other_fields = array(
112 array(
113 'label' => 'status',
114 'name' => 'Status',
115 'type' => 'status'
116 ),
117
118 array(
119 'label' => 'author',
120 'name' => 'Author ID',
121 'type' => 'author'
122 ),
123
124 array(
125 'label' => 'author_username',
126 'name' => 'Author Username',
127 'type' => 'author_username'
128 ),
129
130 array(
131 'label' => 'author_email',
132 'name' => 'Author Email',
133 'type' => 'author_email'
134 ),
135
136 array(
137 'label' => 'author_first_name',
138 'name' => 'Author First Name',
139 'type' => 'author_first_name'
140 ),
141
142 array(
143 'label' => 'author_last_name',
144 'name' => 'Author Last Name',
145 'type' => 'author_last_name'
146 ),
147
148 array(
149 'label' => 'slug',
150 'name' => 'Slug',
151 'type' => 'slug'
152 ),
153 array(
154 'label' => 'format',
155 'name' => 'Format',
156 'type' => 'format'
157 ),
158 array(
159 'label' => 'template',
160 'name' => 'Template',
161 'type' => 'template'
162 ),
163 array(
164 'label' => 'parent',
165 'name' => 'Parent',
166 'type' => 'parent'
167 ),
168 array(
169 'label' => 'parent_slug',
170 'name' => 'Parent Slug',
171 'type' => 'parent_slug'
172 ),
173 array(
174 'label' => 'order',
175 'name' => 'Order',
176 'type' => 'order'
177 ),
178 array(
179 'label' => 'comment_status',
180 'name' => 'Comment Status',
181 'type' => 'comment_status'
182 ),
183 array(
184 'label' => 'ping_status',
185 'name' => 'Ping Status',
186 'type' => 'ping_status'
187 ),
188 array(
189 'label' => 'post_modified',
190 'name' => 'Post Modified Date',
191 'type' => 'post_modified'
192 )
193 );
194
195 private $available_sections = array();
196 private $filter_sections = array();
197
198 private $errors;
199
200 private $available_data = array(
201 'acf_groups' => array(),
202 'existing_acf_meta_keys' => array(),
203 'existing_meta_keys' => array(),
204 'init_fields' => array(),
205 'default_fields' => array(),
206 'other_fields' => array(),
207 'woo_data' => array(),
208 'existing_attributes' => array(),
209 'existing_taxonomies' => array()
210 );
211
212 private $filters;
213
214 public static $is_user_export = false;
215 public static $is_comment_export = false;
216 public static $is_taxonomy_export = false;
217 public static $is_custom_addon_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( \class_exists('WooCommerce') && XmlExportEngine::get_addons_service()->isWooCommerceAddonActive()) {
386 if (in_array('product', self::$post_types) and !in_array('product_variation', self::$post_types)) self::$post_types[] = 'product_variation';
387 } else if(\class_exists('WooCommerce') && in_array('product', self::$post_types) && XmlExportEngine::get_addons_service()->isWooCommerceProductAddonActive()) {
388 self::$post_types = ['product'];
389 }
390
391 self::$is_user_export = ( in_array('users', self::$post_types) or in_array('shop_customer', self::$post_types) ) ? true : false;
392
393 self::$is_comment_export = ( in_array('comments', self::$post_types) ) ? true : false;
394
395 self::$is_taxonomy_export = ( in_array('taxonomies', self::$post_types) ) ? true : false;
396
397 if(count(self::$post_types) === 1) {
398 if(strpos(self::$post_types[0], 'custom_') === 0 ) {
399 self::$is_custom_addon_export = true;
400 }
401 }
402 }
403 else
404 {
405 self::$is_user_export = ( 'wp_user_query' == $this->post['wp_query_selector'] );
406 self::$is_comment_export = ( 'wp_comment_query' == $this->post['wp_query_selector'] );
407 }
408
409 if ( ! self::$is_user_export && ! self::$is_comment_export && ! self::$is_taxonomy_export)
410 {
411 add_filter("wp_all_export_filters", array( &$this, "filter_export_filters"), 10, 1);
412
413 // When WPML is active and at least one post in the export has a trid
414 if (class_exists('SitePress'))
415 {
416 self::$default_fields[] = array(
417 'label' => 'wpml_trid',
418 'name' => 'WPML Translation ID',
419 'type' => 'wpml_trid'
420 );
421
422 self::$default_fields[] = array(
423 'label' => 'wpml_lang',
424 'name' => 'WPML Language Code',
425 'type' => 'wpml_lang'
426 );
427 }
428 }
429
430 self::$exportOptions = $post;
431
432 if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() )
433 {
434 $filter_args = array(
435 'filter_rules_hierarhy' => $this->post['filter_rules_hierarhy'],
436 'product_matching_mode' => $this->post['product_matching_mode'],
437 'taxonomy_to_export' => empty($this->post['taxonomy_to_export']) ? '' : $this->post['taxonomy_to_export']
438 );
439
440 $this->filters = \Wpae\Pro\Filtering\FilteringFactory::getFilterEngine();
441 $this->filters->init($filter_args);
442
443 $this->init();
444 }
445
446 if (empty(self::$exportOptions['delimiter'])) self::$exportOptions['delimiter'] = ',';
447
448 self::$implode = (self::$exportOptions['delimiter'] == ',') ? '|' : ',';
449
450 self::$implode = apply_filters('wp_all_export_implode_delimiter', self::$implode, self::$exportID);
451
452 if ( !empty(self::$exportOptions['xml_template_type']) && in_array(self::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ) self::$implode = '#delimiter#';
453
454 self::$comment_export = new XmlExportComment();
455 self::$taxonomy_export = new XmlExportTaxonomy();
456 self::$custom_record_export = new XmlExportCustomRecord();
457
458 do_action('pmxe_init_addons');
459 }
460
461 // [FILTERS]
462
463 /**
464 *
465 * Filter data for advanced filtering
466 *
467 */
468 public function filter_export_filters($filters){
469 return array_merge($filters, $this->filter_sections);
470 }
471
472 // [\FILTERS]
473
474 protected function init(){
475
476 PMXE_Plugin::$session->set('is_user_export', self::$is_user_export);
477 PMXE_Plugin::$session->set('is_comment_export', self::$is_comment_export);
478 PMXE_Plugin::$session->set('is_taxonomy_export', self::$is_taxonomy_export);
479 PMXE_Plugin::$session->save_data();
480
481 if ('advanced' == $this->post['export_type']) {
482
483 if( "" == $this->post['wp_query'] ){
484 $this->errors->add('form-validation', __('WP Query field is required', 'pmxe_plugin'));
485 }
486 else if(!XmlExportEngine::get_addons_service()->isWooCommerceAddonActive() && strpos($this->post['wp_query'], 'product') !== false && \class_exists('WooCommerce')) {
487 $this->errors->add('form-validation', __('The WooCommerce Export Add-On Pro is required to Export WooCommerce Products', 'pmxe_plugin'));
488 }
489 else if(!XmlExportEngine::get_addons_service()->isWooCommerceAddonActive() && strpos($this->post['wp_query'], 'shop_order') !== false) {
490 $this->errors->add('form-validation', __('The WooCommerce Export Add-On Pro is required to Export WooCommerce Orders', 'pmxe_plugin'));
491 }
492 else if(!XmlExportEngine::get_addons_service()->isWooCommerceAddonActive() && strpos($this->post['wp_query'], 'shop_coupon') !== false) {
493 $this->errors->add('form-validation', __('The WooCommerce Export Add-On Pro is required to Export WooCommerce Coupons', 'pmxe_plugin'));
494 }
495 else
496 {
497 $this->filters->parse();
498
499 PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere'));
500 PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin'));
501 PMXE_Plugin::$session->set('wp_query', $this->post['wp_query']);
502 PMXE_Plugin::$session->save_data();
503 }
504 }
505 else
506 {
507 $this->filters->parse();
508
509 PMXE_Plugin::$session->set('cpt', self::$post_types);
510 PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere'));
511 PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin'));
512 PMXE_Plugin::$session->save_data();
513 }
514
515 PMXE_Plugin::$session->save_data();
516
517 }
518
519 public function init_additional_data(){
520
521 if(self::$woo_export) {
522 self::$woo_export->init_additional_data();
523 }
524
525 if(self::$woo_order_export) {
526 self::$woo_order_export->init_additional_data();
527 }
528 }
529
530 public function init_available_data(){
531
532 global $wpdb;
533 $table_prefix = $wpdb->prefix;
534
535 // Prepare existing taxonomies
536 if ( 'specific' == $this->post['export_type'] and ! self::$is_user_export and ! self::$is_comment_export and ! self::$is_taxonomy_export )
537 {
538 $this->_existing_taxonomies = wp_all_export_get_existing_taxonomies_by_cpt( self::$post_types[0] );
539
540 $this->_existing_meta_keys = wp_all_export_get_existing_meta_by_cpt( self::$post_types[0] );
541 }
542 if ( 'advanced' == $this->post['export_type'] and ! self::$is_user_export and ! self::$is_comment_export and ! self::$is_taxonomy_export )
543 {
544 $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");
545 if ( ! empty($meta_keys)){
546 $exclude_keys = array('_first_variation_attributes', '_is_first_variation_created');
547 foreach ($meta_keys as $meta_key) {
548 if ( strpos($meta_key->meta_key, "_tmp") === false && strpos($meta_key->meta_key, "_v_") === false && ! in_array($meta_key->meta_key, $exclude_keys))
549 $this->_existing_meta_keys[] = $meta_key->meta_key;
550 }
551 }
552
553 global $wp_taxonomies;
554
555 foreach ($wp_taxonomies as $key => $obj) { if (in_array($obj->name, array('nav_menu'))) continue;
556
557 if (strpos($obj->name, "pa_") !== 0 and strlen($obj->name) > 3)
558 $this->_existing_taxonomies[] = array(
559 'name' => empty($obj->label) ? $obj->name : $obj->label,
560 'label' => $obj->name,
561 'type' => 'cats'
562 );
563 }
564 }
565
566 if(self::$acf_export) {
567 // Prepare existing ACF groups & fields
568 self::$acf_export->init($this->_existing_meta_keys);
569 }
570
571 if(XmlExportEngine::$woo_export) {
572 // Prepare existing WooCommerce data
573 self::$woo_export->init($this->_existing_meta_keys);
574
575 if(self::get_addons_service()->isWooCommerceAddonActive()) {
576 // Prepare existing WooCommerce Coupon data
577 self::$woo_coupon_export->init($this->_existing_meta_keys);
578 }
579 }
580 if(XmlExportEngine::$woo_order_export) {
581 // Prepare existing WooCommerce Order data
582 self::$woo_order_export->init($this->_existing_meta_keys);
583
584
585 }
586
587 if(XmlExportEngine::$user_export) {
588 // Prepare existing Users data
589 self::$user_export->init($this->_existing_meta_keys);
590 }
591
592 // Prepare existing Comments data
593 self::$comment_export->init($this->_existing_meta_keys);
594
595 // Prepare existing Taxonomy data
596 self::$taxonomy_export->init($this->_existing_meta_keys);
597
598 return $this->get_available_data();
599 }
600
601 public function get_available_data(){
602
603 if(self::$acf_export) {
604 $this->available_data['acf_groups'] = self::$acf_export->get('_acf_groups');
605 $this->available_data['existing_acf_meta_keys'] = self::$acf_export->get('_existing_acf_meta_keys');
606 }
607
608 $this->available_data['existing_meta_keys'] = $this->_existing_meta_keys;
609 $this->available_data['existing_taxonomies'] = $this->_existing_taxonomies;
610
611 $this->available_data['init_fields'] = apply_filters('wp_all_export_init_fields', $this->init_fields);
612 $this->available_data['default_fields'] = apply_filters('wp_all_export_default_fields', self::$default_fields);
613 $this->available_data['other_fields'] = apply_filters('wp_all_export_other_fields', $this->other_fields);
614
615 $this->available_data = apply_filters("wp_all_export_available_data", $this->available_data);
616
617 return $this->available_data;
618
619 }
620
621 public function get_fields_options( $field_keys = array() ){
622
623 $fields = array(
624 'ids' => array(),
625 'cc_label' => array(),
626 'cc_php' => array(),
627 'cc_code' => array(),
628 'cc_sql' => array(),
629 'cc_options' => array(),
630 'cc_type' => array(),
631 'cc_value' => array(),
632 'cc_name' => array(),
633 'cc_settings' => array()
634 );
635
636 self::$woo_order_export->get_fields_options( $fields, $field_keys );
637
638 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
639
640 foreach ($available_sections as $slug => $section)
641 {
642 if ( ! empty($this->available_data[$section['content']]) ):
643
644 foreach ($this->available_data[$section['content']] as $field)
645 {
646
647 $field_key = (is_array($field)) ? $field['name'] : $field;
648
649 if ( ! in_array($field_key, $field_keys) ) continue;
650
651 $fields['ids'][] = 1;
652 $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $field;
653 $fields['cc_php'][] = '';
654 $fields['cc_code'][] = '';
655 $fields['cc_sql'][] = '';
656 $fields['cc_options'][] = '';
657 $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $slug;
658 $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $field;
659 $fields['cc_name'][] = $field_key;
660 $fields['cc_settings'][] = '';
661 }
662 endif;
663
664 if ( ! empty($section['additional']) )
665 {
666 foreach ($section['additional'] as $sub_slug => $sub_section)
667 {
668
669 foreach ($sub_section['meta'] as $field) {
670 $key_to_check = (is_array($field)) ? $field['name'] : $field;
671
672 if ( in_array($sub_slug, array('images', 'attachments')) ){
673 $key_to_check = preg_replace("%s$%","",ucfirst($sub_slug)) . ' ' . $key_to_check;
674 }
675
676 if ( ! in_array($key_to_check, $field_keys) ) continue;
677
678 $field_options = ( in_array($sub_slug, array('images', 'attachments')) ) ? esc_attr('{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}') : '0';
679
680 $fields['ids'][] = 1;
681 $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $field;
682 $fields['cc_php'][] = '';
683 $fields['cc_code'][] = '';
684 $fields['cc_sql'][] = '';
685 $fields['cc_options'][] = $field_options;
686 $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $sub_slug;
687 $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $field;
688 $fields['cc_name'][] = $key_to_check;
689 $fields['cc_settings'][] = '';
690 }
691 }
692 }
693 }
694
695 if ( ! self::$is_comment_export )
696 {
697 if(self::$acf_export) {
698 self::$acf_export->get_fields_options( $fields, $field_keys );
699 }
700 }
701
702 $sort_fields = array();
703 foreach ($field_keys as $i => $field_key){
704 foreach ($fields['cc_name'] as $j => $cc_name){
705 if (!empty($cc_name) && $cc_name == $field_key){
706 $sort_fields['ids'][] = 1;
707 $sort_fields['cc_label'][] = $fields['cc_label'][$j];
708 $sort_fields['cc_php'][] = $fields['cc_php'][$j];
709 $sort_fields['cc_code'][] = $fields['cc_code'][$j];
710 $sort_fields['cc_sql'][] = $fields['cc_sql'][$j];
711 $sort_fields['cc_options'][] = $fields['cc_options'][$j];
712 $sort_fields['cc_type'][] = $fields['cc_type'][$j];
713 $sort_fields['cc_value'][] = $fields['cc_value'][$j];
714 $sort_fields['cc_name'][] = $fields['cc_name'][$j];
715 $sort_fields['cc_settings'][] = $fields['cc_settings'][$j];
716 break;
717 }
718 }
719 }
720
721 return $sort_fields;
722
723 }
724
725 public function render(){
726
727 $i = 0;
728
729 ob_start();
730
731 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
732 self::$globalAvailableSections = $available_sections;
733
734 if(self::$woo_order_export) {
735 // Render Available WooCommerce Orders Data
736 self::$woo_order_export->render($i);
737 }
738
739 foreach ($available_sections as $slug => $section)
740 {
741
742 if ( ! empty($this->available_data[$section['content']]) or ! empty($section['additional']) ):
743 ?>
744 <p class="wpae-available-fields-group"><?php echo esc_html($section['title']); ?><span class="wpae-expander">+</span></p>
745 <div class="wpae-custom-field">
746 <?php
747 if($slug == 'cf' && XmlExportEngine::$is_user_export) {
748 ?>
749 <div class="wpallexport-free-edition-notice">
750 <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>
751 </div>
752 <?php
753 }
754 ?>
755 <?php
756 if($slug == 'other' && XmlExportEngine::$is_user_export) {
757 ?>
758 <div class="wpallexport-free-edition-notice">
759 <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>
760 </div>
761 <?php
762 }
763 $elementClass = "";
764 if(($slug == 'cf' || $slug == 'other') && XmlExportEngine::$is_user_export){
765 $elementClass = 'wpallexport_disabled';
766 }
767 ?>
768 <ul>
769 <?php if ( ! empty($this->available_data[$section['content']]) ): ?>
770 <li class="<?php echo esc_attr($elementClass); ?>">
771 <div class="default_column" rel="">
772 <label class="wpallexport-element-label"><?php esc_html_e("All", "wp_all_export_plugin") . ' ' . esc_html($section['title']); ?></label>
773 <input type="hidden" name="rules[]" value="<?php echo esc_attr("pmxe_" . $slug); ?>"/>
774 </div>
775 </li>
776 <?php
777 foreach ($this->available_data[$section['content']] as $field)
778 {
779 $field_type = is_array($field) ? $field['type'] : $slug;
780 $field_name = is_array($field) ? $field['name'] : $field;
781
782 if ( $field_type == 'cf' && $field_name == '_thumbnail_id' ) continue;
783
784 $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')) || !\class_exists('WooCommerce'))));
785
786 ?>
787 <li class="pmxe_<?php echo $slug; ?> <?php if ( $is_auto_field ) echo 'wp_all_export_auto_generate';?> <?php echo esc_attr($elementClass);?>">
788 <div class="custom_column" rel="<?php echo ($i + 1);?>">
789 <label class="wpallexport-xml-element"><?php echo esc_html(is_array($field) ? $field['name'] : $field); ?></label>
790 <input type="hidden" name="ids[]" value="1"/>
791 <input type="hidden" name="cc_label[]" value="<?php echo esc_html(is_array($field) ? $field['label'] : $field); ?>"/>
792 <input type="hidden" name="cc_php[]" value="0"/>
793 <input type="hidden" name="cc_code[]" value=""/>
794 <input type="hidden" name="cc_sql[]" value="0"/>
795 <input type="hidden" name="cc_options[]" value="0"/>
796 <input type="hidden" name="cc_type[]" value="<?php echo esc_html(is_array($field) ? $field['type'] : $slug); ?>"/>
797 <input type="hidden" name="cc_value[]" value="<?php echo esc_html(is_array($field) ? $field['label'] : $field); ?>"/>
798 <input type="hidden" name="cc_name[]" value="<?php echo esc_html(is_array($field) ? $field['name'] : $field); ?>"/>
799 <input type="hidden" name="cc_settings[]" value="0"/>
800 </div>
801 </li>
802 <?php
803 $i++;
804 }
805 endif;
806
807 if ( ! empty($section['additional']) )
808 {
809 foreach ($section['additional'] as $sub_slug => $sub_section)
810 {
811
812 ?>
813 <li class="available_sub_section">
814 <p class="wpae-available-fields-group"><?php echo esc_html($sub_section['title']); ?><span
815 class="wpae-expander">+</span></p>
816 <div class="wpae-custom-field">
817 <?php
818 $show_additional_subsection = apply_filters("wp_all_export_show_additional_subsection", true, $sub_slug, $sub_section);
819 do_action("wp_all_export_before_available_subsection", $sub_slug, $sub_section);
820
821
822 if($show_additional_subsection) { ?>
823
824 <ul>
825 <li>
826 <div class="default_column" rel="">
827 <label class="wpallexport-element-label"><?php echo __("All", "wp_all_export_plugin") . ' ' . esc_html($sub_section['title']); ?></label>
828 <input type="hidden" name="rules[]"
829 value="<?php echo esc_attr("pmxe_" . $slug . "_" . $sub_slug); ?>"/>
830 </div>
831 </li>
832 <?php
833 foreach ($sub_section['meta'] as $field) {
834 $is_auto_field = empty($field['auto']) ? false : true;
835 $field_options = (in_array($sub_slug, array('images', 'attachments'))) ? esc_attr('{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}') : '0';
836 ?>
837 <li class="<?php echo esc_attr("pmxe_" . $slug . "_" . $sub_slug); ?> <?php if ($is_auto_field) echo 'wp_all_export_auto_generate'; ?>">
838 <div class="custom_column" rel="<?php echo($i + 1); ?>">
839 <label class="wpallexport-xml-element"><?php echo (is_array($field)) ? esc_html(XmlExportEngine::sanitizeFieldName($field['name'])) : esc_html($field); ?></label>
840 <input type="hidden" name="ids[]" value="1"/>
841 <input type="hidden" name="cc_label[]"
842 value="<?php echo (is_array($field)) ? esc_attr($field['label']) : esc_attr($field); ?>"/>
843 <input type="hidden" name="cc_php[]" value="0"/>
844 <input type="hidden" name="cc_code[]" value="0"/>
845 <input type="hidden" name="cc_sql[]" value="0"/>
846 <input type="hidden" name="cc_options[]"
847 value="<?php echo esc_attr($field_options); ?>"/>
848 <input type="hidden" name="cc_type[]"
849 value="<?php echo (is_array($field)) ? esc_attr($field['type']) : esc_attr($sub_slug); ?>"/>
850 <input type="hidden" name="cc_value[]"
851 value="<?php echo (is_array($field)) ? esc_attr($field['label']) : esc_attr($field); ?>"/>
852 <input type="hidden" name="cc_name[]"
853 value="<?php echo (is_array($field)) ? esc_attr(XmlExportEngine::sanitizeFieldName($field['name'])) : esc_attr($field); ?>"/>
854 <input type="hidden" name="cc_settings[]" value=""/>
855 </div>
856 </li>
857 <?php
858 $i++;
859
860 }
861 ?>
862 </ul>
863 <?php
864 }
865 ?>
866 </div>
867 </li>
868 <?php
869
870 }
871 }
872 ?>
873 </ul>
874 </div>
875 <?php
876 endif;
877 }
878
879 if ( ! self::$is_comment_export )
880 {
881 if(self::$acf_export) {
882 // Render Available ACF
883 self::$acf_export->render($i);
884 } else {
885 if(!self::get_addons_service()->isAcfAddonActive()) {
886 ?>
887 <p class="wpae-available-fields-group">ACF<span class="wpae-expander">+</span></p>
888 <div class="wpae-custom-field">
889
890 <div class="wpallexport-free-edition-notice">
891 <a class="upgrade_link" target="_blank"
892 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>
893 </div>
894 </div>
895 <?php
896 }
897
898 }
899 }
900
901 return ob_get_clean();
902
903 }
904
905 public function render_filters(){
906
907 $available_sections = apply_filters("wp_all_export_available_sections", apply_filters('wp_all_export_filters', $this->available_sections) );
908
909 if(self::$woo_order_export) {
910 // Render Filters for WooCommerce Orders
911 self::$woo_order_export->render_filters();
912 }
913
914 if(self::$is_custom_addon_export) {
915 if(class_exists('GF_Export_Add_On')) {
916 $addon = GF_Export_Add_On::get_instance();
917 $addon->render_filters();
918 unset($available_sections);
919 }
920
921 }
922
923 if ( ! empty($available_sections) )
924 {
925 $exclude = array('wpml_lang', 'wpml_trid');
926
927 foreach ($available_sections as $slug => $section)
928 {
929 if ( ! empty($section['content']) and ! empty($this->available_data[$section['content']]) or ! empty($section['fields'])):
930 ?>
931
932 <optgroup label="<?php echo esc_attr($section['title']); ?>">
933
934 <?php if ( ! empty($section['content']) && ! empty($this->available_data[$section['content']]) ): ?>
935
936 <?php foreach ($this->available_data[$section['content']] as $field) : ?>
937
938 <?php
939
940 $field_label = is_array($field) ? $field['label'] : $field;
941 $field_type = is_array($field) ? $field['type'] : $slug;
942 $field_name = is_array($field) ? $field['name'] : $field;
943
944 if ( in_array($field_label, $exclude) ) continue;
945
946 switch ($field_type)
947 {
948 case 'woo':
949 $exclude_fields = array('attributes');
950 if ( ! in_array($field_label, $exclude_fields)):
951 ?>
952 <option value="<?php echo esc_attr('cf_' . $field_label); ?>"><?php echo esc_html($field_name); ?></option>
953 <?php
954 endif;
955 break;
956 case 'cf':
957 ?>
958 <option value="<?php echo esc_attr('cf_' . $field_label); ?>"><?php echo esc_html($field_name); ?></option>
959 <?php
960 break;
961 case 'cats':
962 case 'attr':
963 ?>
964 <option value="<?php echo esc_attr('tx_' . $field_label); ?>"><?php echo esc_html($field_name); ?></option>
965 <?php
966 break;
967 default:
968
969 if (self::$is_user_export)
970 {
971 switch ($field_label)
972 {
973 case 'id':
974 $field_label = strtoupper($field_label);
975 break;
976 case 'user_nicename':
977 ?>
978 <option value="user_role"><?php esc_html_e('User Role', 'wp_all_export_plugin'); ?></option>
979 <?php
980 break;
981 }
982 }
983 else
984 {
985 switch ($field_label) {
986 case 'id':
987 $field_label = strtoupper($field_label);
988 break;
989 case 'parent':
990 case 'author':
991 case 'author_username':
992 case 'author_email':
993 case 'author_first_name':
994 case 'author_last_name':
995 case 'status':
996 case 'title':
997 case 'content':
998 case 'date':
999 case 'excerpt':
1000 $field_label = 'post_' . $field_label;
1001 break;
1002 case 'permalink':
1003 $field_label = 'guid';
1004 break;
1005 case 'slug':
1006 $field_label = 'post_name';
1007 break;
1008 case 'order':
1009 $field_label = 'menu_order';
1010 break;
1011 case 'template':
1012 $field_label = 'cf__wp_page_template';
1013 break;
1014 case 'format':
1015 $field_label = 'tx_post_format';
1016 break;
1017 default:
1018 # code...
1019 break;
1020 }
1021 }
1022 ?>
1023 <option value="<?php echo esc_attr($field_label); ?>"><?php echo esc_html($field_name); ?></option>
1024 <?php
1025 break;
1026 }
1027 ?>
1028
1029 <?php endforeach; ?>
1030
1031 <?php endif; ?>
1032
1033 <?php if ( ! empty($section['fields'])): ?>
1034
1035 <?php foreach ($section['fields'] as $key => $title) : ?>
1036
1037 <option value="<?php echo esc_attr($key); ?>"><?php echo esc_html($title); ?></option>
1038
1039 <?php endforeach; ?>
1040
1041 <?php endif; ?>
1042
1043 </optgroup>
1044
1045 <?php
1046
1047 endif;
1048
1049 if ( ! empty($section['additional']) )
1050 {
1051 foreach ($section['additional'] as $sub_slug => $sub_section)
1052 {
1053 if ( $sub_slug == 'attributes' ) {
1054 ?>
1055 <optgroup label="<?php echo esc_attr($sub_section['title']); ?>">
1056 <?php
1057 foreach ($sub_section['meta'] as $field) :
1058 if ( isset( $field['type'] ) ) {
1059 switch ( $field['type'] ) {
1060 case 'attr':
1061 ?>
1062 <option value="<?php echo esc_attr('tx_' . $field['label']); ?>"><?php echo esc_html($field['name']); ?></option>
1063 <?php
1064 break;
1065 case 'cf':
1066 ?>
1067 <option value="<?php echo esc_attr('cf_' . $field['label']); ?>"><?php echo esc_html($field['name']); ?></option>
1068 <?php
1069 break;
1070 default:
1071 # code...
1072 break;
1073 }
1074 }
1075
1076 endforeach;
1077 ?>
1078 </optgroup>
1079 <?php
1080 }
1081 }
1082 }
1083 }
1084 }
1085
1086 if ( ! self::$is_comment_export )
1087 {
1088 if(self::$acf_export) {
1089 // Render Available ACF
1090 self::$acf_export->render_filters();
1091 }
1092 }
1093
1094 }
1095
1096 public function render_new_field(){
1097
1098 ob_start();
1099
1100 $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections);
1101
1102 if(self::$woo_order_export) {
1103 // Render Available WooCommerce Orders Data
1104 self::$woo_order_export->render_new_field();
1105 }
1106
1107 if ( ! empty($available_sections) ):?>
1108
1109 <select class="wp-all-export-chosen-select" name="column_value_type" style="width:350px;">
1110
1111 <?php
1112 foreach ($available_sections as $slug => $section)
1113 {
1114 if($slug === 'product_data' && !self::get_addons_service()->isWooCommerceAddonActive()) {
1115 unset($section['additional']);
1116 }
1117
1118 if ( ! empty($this->available_data[$section['content']]) or ! empty($section['additional']) ):
1119 ?>
1120 <optgroup label="<?php echo esc_attr($section['title']); ?>">
1121
1122 <?php
1123 if ( ! empty($this->available_data[$section['content']]) )
1124 {
1125 foreach ($this->available_data[$section['content']] as $field)
1126 {
1127 $field_label = is_array($field) ? $field['label'] : $field;
1128 $field_type = is_array($field) ? $field['type'] : $slug;
1129 $field_name = is_array($field) ? $field['name'] : $field;
1130 $field_options = empty ($field['options']) ? '' : $field['options'];
1131
1132 if ( $field_type == 'cf' && $field_name == '_thumbnail_id' || ($field_type=='other')) continue;
1133 $elementDisabled = "";
1134 if(($section['title'] == 'Custom Fields' || $section['title'] == 'Other') && XmlExportEngine::$is_user_export) {
1135 $elementDisabled = "disabled='disabled'";
1136 }
1137 ?>
1138 <option
1139 value="<?php echo esc_attr($field_type);?>"
1140 label="<?php echo esc_attr($field_label);?>"
1141 <?php echo esc_html($elementDisabled); ?>
1142 options="<?php echo esc_attr($field_options); ?>"><?php echo esc_html($field_name);?></option>
1143 <?php
1144 }
1145 }
1146 ?>
1147
1148 </optgroup>
1149
1150 <?php
1151
1152 if ( ! empty($section['additional']) )
1153 {
1154 foreach ($section['additional'] as $sub_slug => $sub_section)
1155 {
1156 ?>
1157 <optgroup label="<?php echo esc_attr($sub_section['title']); ?>">
1158
1159 <?php
1160 foreach ($sub_section['meta'] as $field)
1161 {
1162 $field_label = is_array($field) ? $field['label'] : $field;
1163 $field_type = is_array($field) ? $field['type'] : $slug;
1164 $field_name = is_array($field) ? $field['name'] : $field;
1165 $field_options = empty($field['options']) ? '{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}' : $field['options'];
1166 ?>
1167 <option
1168 value="<?php echo esc_attr($field_type);?>"
1169 label="<?php echo esc_attr($field_label);?>"
1170 options="<?php echo esc_attr($field_options); ?>"><?php echo esc_html($field_name);?></option>
1171 <?php
1172 }
1173 ?>
1174 </optgroup>
1175 <?php
1176 }
1177 }
1178 endif;
1179 }
1180
1181 if ( ! self::$is_comment_export )
1182 {
1183 if(self::$acf_export) {
1184 // Render Available ACF
1185 self::$acf_export->render_new_field();
1186 }
1187 }
1188
1189 ?>
1190 <optgroup label="Advanced">
1191 <option value="sql" label="sql"><?php esc_html_e("SQL Query", "wp_all_export_plugin"); ?></option>
1192 </optgroup>
1193 </select>
1194 <?php
1195 endif;
1196
1197 return ob_get_clean();
1198
1199 }
1200
1201 public function parse_custom_xml_template(){
1202
1203 preg_match("%". self::XML_LOOP_START ."(.*)". self::XML_LOOP_END ."%", $this->post['custom_xml_template'], $matches);
1204 $parts = explode(self::XML_LOOP_START, $this->post['custom_xml_template']);
1205 $loopContent = $parts[1];
1206 $parts = explode(self::XML_LOOP_END, $loopContent);
1207 $loopContent = $parts[0];
1208 $line_numbers = substr_count($loopContent, "\n") +1;
1209
1210 $result['original_post_loop'] = $loopContent;
1211 $result['line_numbers'] = $line_numbers;
1212
1213 $custom_xml_template = str_replace("\n", "", $this->post['custom_xml_template']);
1214 // retrieve XML header
1215 preg_match("%(.*)". self::XML_LOOP_START ."%", $custom_xml_template, $matches);
1216 $result['custom_xml_template_header'] = empty($matches[1]) ? '' : rtrim($matches[1]);
1217 // retrieve XML POST LOOP
1218 preg_match("%". self::XML_LOOP_START ."(.*)". self::XML_LOOP_END ."%", $custom_xml_template, $matches);
1219 $result['custom_xml_template_loop'] = empty($matches[1]) ? '' : rtrim($matches[1]);
1220 // retrieve XML footer
1221 preg_match("%". self::XML_LOOP_END ."(.*)%", $custom_xml_template, $matches);
1222 $result['custom_xml_template_footer'] = empty($matches[1]) ? '' : $matches[1];
1223
1224 // Validate Custom XML Template header
1225 if ( empty($result['custom_xml_template_header']) )
1226 {
1227 $this->errors->add('form-validation', __('Missing custom XML template header.', 'wp_all_export_plugin'));
1228 }
1229 // Validate Custom XML Template post LOOP
1230 if ( empty($result['custom_xml_template_loop']) )
1231 {
1232 $this->errors->add('form-validation', __('Missing custom XML template post loop.', 'wp_all_export_plugin'));
1233 }
1234 // Validate Custom XML Template footer
1235 if ( empty($result['custom_xml_template_footer']) )
1236 {
1237 $this->errors->add('form-validation', __('Missing custom XML template footer.', 'wp_all_export_plugin'));
1238 }
1239
1240 if ( ! $this->errors->get_error_codes()) {
1241
1242 // retrieve all placeholders in the XML loop
1243 preg_match_all("%(\[[^\]\[]*\])%", $result['custom_xml_template_loop'], $matches);
1244 $loop_placeholders = empty($matches) ? array() : $matches[0];
1245
1246 $field_keys = array();
1247 // looking for placeholders e.q. {Post Type}, {Title}
1248 if ( ! empty($loop_placeholders) ){
1249
1250 foreach ($loop_placeholders as $snippet) {
1251 preg_match("%\{(.*)\}%", $snippet, $matches);
1252 if ( ! empty($matches[1]) ) $field_keys[] = $matches[1];
1253 }
1254 }
1255
1256 preg_match_all("%(\{[^\}\{]*\})%", $result['custom_xml_template_loop'], $matches);
1257 $loop_placeholders = empty($matches) ? array() : $matches[0];
1258
1259 $field_keys = array();
1260 // looking for placeholders e.q. {Post Type}, {Title}
1261 if ( ! empty($loop_placeholders) ){
1262
1263 foreach ($loop_placeholders as $snippet) {
1264 preg_match("%\{(.*)\}%", $snippet, $matches);
1265 if ( ! empty($matches[1]) and ! in_array($matches[1], $field_keys)) $field_keys[] = $matches[1];
1266 }
1267 }
1268
1269 if (!empty($field_keys)){
1270 $result['custom_xml_template_options'] = $this->get_fields_options( $field_keys );
1271 }
1272 }
1273 return $result;
1274 }
1275
1276 /**
1277 * __get function.
1278 *
1279 * @access public
1280 * @param mixed $key
1281 * @return mixed
1282 */
1283 public function __get( $key ) {
1284 return $this->get( $key );
1285 }
1286
1287 /**
1288 * Get a session variable
1289 *
1290 * @param string $key
1291 * @param mixed $default used if the session variable isn't set
1292 * @return mixed value of session variable
1293 */
1294 public function get( $key, $default = null ) {
1295 return isset( $this->{$key} ) ? $this->{$key} : $default;
1296 }
1297
1298 public static function getProductVariationMode()
1299 {
1300 if(!isset(self::$exportOptions['export_variations'])) {
1301 self::$exportOptions['export_variations'] = self::VARIABLE_PRODUCTS_EXPORT_PARENT_AND_VARIATION;
1302 }
1303
1304 return apply_filters('wp_all_export_product_variation_mode', self::$exportOptions['export_variations'], self::$exportID);
1305 }
1306
1307 public static function getProductVariationTitleMode()
1308 {
1309 if(!isset(self::$exportOptions['export_variations_title'])) {
1310 self::$exportOptions['export_variations_title'] = self::VARIATION_USE_PARENT_TITLE;
1311 }
1312
1313 return self::$exportOptions['export_variations_title'];
1314 }
1315
1316 public static function sanitizeFieldName($fieldName)
1317 {
1318 if (class_exists('XmlExportWooCommerce') && XmlExportWooCommerce::$is_active) {
1319 return urldecode($fieldName);
1320 }
1321
1322 return $fieldName;
1323 }
1324
1325 public static function get_addons_service()
1326 {
1327 if(!self::$addons_service) {
1328 self::$addons_service = new Wpae\App\Service\Addons\AddonService();
1329 }
1330
1331 return self::$addons_service;
1332 }
1333 }
1334
1335 }
1336