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