'; /** * Custom XML Loop end statement * @var string */ const XML_LOOP_END = ''; const EXPORT_TYPE_GOOLE_MERCHANTS = 'XmlGoogleMerchants'; const EXPORT_TYPE_XML = 'xml'; const EXPORT_TYPE_CSV = 'csv'; public static $acf_export; public static $woo_export; public static $woo_order_export; public static $woo_coupon_export; public static $woo_refund_export; public static $user_export; public static $comment_export; public static $taxonomy_export; public static $is_preview = false; public static $implode = ','; private $post; private $_existing_meta_keys = array(); private $_existing_taxonomies = array(); private $init_fields = array( array( 'label' => 'id', 'name' => 'ID', 'type' => 'id' ), array( 'label' => 'title', 'name' => 'Title', 'type' => 'title' ), array( 'label' => 'content', 'name' => 'Content', 'type' => 'content' ) ); public static $default_fields = array( array( 'label' => 'id', 'name' => 'ID', 'type' => 'id' ), array( 'label' => 'title', 'name' => 'Title', 'type' => 'title' ), array( 'label' => 'content', 'name' => 'Content', 'type' => 'content' ), array( 'label' => 'excerpt', 'name' => 'Excerpt', 'type' => 'excerpt' ), array( 'label' => 'date', 'name' => 'Date', 'type' => 'date' ), array( 'label' => 'post_type', 'name' => 'Post Type', 'type' => 'post_type' ), array( 'label' => 'permalink', 'name' => 'Permalink', 'type' => 'permalink' ) ); private $other_fields = array( array( 'label' => 'status', 'name' => 'Status', 'type' => 'status' ), array( 'label' => 'author', 'name' => 'Author ID', 'type' => 'author' ), array( 'label' => 'author_username', 'name' => 'Author Username', 'type' => 'author_username' ), array( 'label' => 'author_email', 'name' => 'Author Email', 'type' => 'author_email' ), array( 'label' => 'author_first_name', 'name' => 'Author First Name', 'type' => 'author_first_name' ), array( 'label' => 'author_last_name', 'name' => 'Author Last Name', 'type' => 'author_last_name' ), array( 'label' => 'slug', 'name' => 'Slug', 'type' => 'slug' ), array( 'label' => 'format', 'name' => 'Format', 'type' => 'format' ), array( 'label' => 'template', 'name' => 'Template', 'type' => 'template' ), array( 'label' => 'parent', 'name' => 'Parent', 'type' => 'parent' ), array( 'label' => 'parent_slug', 'name' => 'Parent Slug', 'type' => 'parent_slug' ), array( 'label' => 'order', 'name' => 'Order', 'type' => 'order' ), array( 'label' => 'comment_status', 'name' => 'Comment Status', 'type' => 'comment_status' ), array( 'label' => 'ping_status', 'name' => 'Ping Status', 'type' => 'ping_status' ), array( 'label' => 'post_modified', 'name' => 'Post Modified Date', 'type' => 'post_modified' ) ); private $available_sections = array(); private $filter_sections = array(); private $errors; private $available_data = array( 'acf_groups' => array(), 'existing_acf_meta_keys' => array(), 'existing_meta_keys' => array(), 'init_fields' => array(), 'default_fields' => array(), 'other_fields' => array(), 'woo_data' => array(), 'existing_attributes' => array(), 'existing_taxonomies' => array() ); private $filters; public static $is_user_export = false; public static $is_comment_export = false; public static $is_taxonomy_export = false; public static $post_types = array(); public static $exportOptions = array(); public static $exportQuery; public static $exportID = false; public static $exportRecord = false; public static $globalAvailableSections; public static $is_auto_generate_enabled = true; public function __construct( $post, & $errors = false ){ $this->post = $post; $this->errors = $errors; $this->available_sections = array( 'default' => array( 'title' => __("Standard", "wp_all_export_plugin"), 'content' => 'default_fields' ), 'media' => array( 'title' => __("Media", "wp_all_export_plugin"), 'content' => '', 'additional' => array( 'images' => array( 'title' => __("Images", "wp_all_export_plugin"), 'meta' => array( array( 'name' => 'URL', 'label' => 'url', 'type' => 'image_url', 'auto' => 1 ), array( 'name' => 'Filename', 'label' => 'filename', 'type' => 'image_filename' ), array( 'name' => 'Path', 'label' => 'path', 'type' => 'image_path' ), array( 'name' => 'ID', 'label' => 'image_id', 'type' => 'image_id' ), array( 'name' => 'Title', 'label' => 'title', 'type' => 'image_title', 'auto' => 1 ), array( 'name' => 'Caption', 'label' => 'caption', 'type' => 'image_caption', 'auto' => 1 ), array( 'name' => 'Description', 'label' => 'description', 'type' => 'image_description', 'auto' => 1 ), array( 'name' => 'Alt Text', 'label' => 'alt', 'type' => 'image_alt', 'auto' => 1 ), array( 'name' => 'Featured', 'label' => 'featured', 'type' => 'image_featured', 'auto' => 1 ), ) ), 'attachments' => array( 'title' => __("Attachments", "wp_all_export_plugin"), 'meta' => array( array( 'name' => 'URL', 'label' => 'url', 'type' => 'attachment_url', 'auto' => 1 ), array( 'name' => 'Filename', 'label' => 'filename', 'type' => 'attachment_filename' ), array( 'name' => 'Path', 'label' => 'path', 'type' => 'attachment_path' ), array( 'name' => 'ID', 'label' => 'attachment_id', 'type' => 'attachment_id' ), array( 'name' => 'Title', 'label' => 'title', 'type' => 'attachment_title' ), array( 'name' => 'Caption', 'label' => 'caption', 'type' => 'attachment_caption' ), array( 'name' => 'Description', 'label' => 'description', 'type' => 'attachment_description' ), array( 'name' => 'Alt Text', 'label' => 'alt', 'type' => 'attachment_alt' ), ) ) ) ), 'cats' => array( 'title' => __("Taxonomies", "wp_all_export_plugin"), 'content' => 'existing_taxonomies' ), 'cf' => array( 'title' => __("Custom Fields", "wp_all_export_plugin"), 'content' => 'existing_meta_keys' ), 'other' => array( 'title' => __("Other", "wp_all_export_plugin"), 'content' => 'other_fields' ) ); $this->filter_sections = array( 'author' => array( 'title' => __("Author", "wp_all_export_plugin"), 'fields' => array( 'user_ID' => 'User ID', 'user_login' => 'User Login', 'user_nicename' => 'Nicename', 'user_email' => 'Email', 'user_registered' => 'Date Registered (Y-m-d H:i:s)', 'display_name' => 'Display Name', 'cf_first_name' => 'First Name', 'cf_last_name' => 'Last Name', 'nickname' => 'Nickname', 'description' => 'User Description', 'wp_capabilities' => 'User Role' ) ) ); if ( 'specific' == $this->post['export_type']) { self::$post_types = ( ! is_array($this->post['cpt']) ) ? array($this->post['cpt']) : $this->post['cpt']; if ( in_array('product', self::$post_types) and ! in_array('product_variation', self::$post_types)) self::$post_types[] = 'product_variation'; self::$is_user_export = ( in_array('users', self::$post_types) or in_array('shop_customer', self::$post_types) ) ? true : false; self::$is_comment_export = ( in_array('comments', self::$post_types) ) ? true : false; self::$is_taxonomy_export = ( in_array('taxonomies', self::$post_types) ) ? true : false; } else { self::$is_user_export = ( 'wp_user_query' == $this->post['wp_query_selector'] ); self::$is_comment_export = ( 'wp_comment_query' == $this->post['wp_query_selector'] ); } if ( ! self::$is_user_export && ! self::$is_comment_export && ! self::$is_taxonomy_export) { add_filter("wp_all_export_filters", array( &$this, "filter_export_filters"), 10, 1); // When WPML is active and at least one post in the export has a trid if (class_exists('SitePress')) { self::$default_fields[] = array( 'label' => 'wpml_trid', 'name' => 'WPML Translation ID', 'type' => 'wpml_trid' ); self::$default_fields[] = array( 'label' => 'wpml_lang', 'name' => 'WPML Language Code', 'type' => 'wpml_lang' ); } } self::$exportOptions = $post; if ( ! empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session() ) { $filter_args = array( 'filter_rules_hierarhy' => $this->post['filter_rules_hierarhy'], 'product_matching_mode' => $this->post['product_matching_mode'], 'taxonomy_to_export' => empty($this->post['taxonomy_to_export']) ? '' : $this->post['taxonomy_to_export'] ); $this->filters = \Wpae\Pro\Filtering\FilteringFactory::getFilterEngine(); $this->filters->init($filter_args); $this->init(); } if (empty(self::$exportOptions['delimiter'])) self::$exportOptions['delimiter'] = ','; self::$implode = (self::$exportOptions['delimiter'] == ',') ? '|' : ','; self::$implode = apply_filters('wp_all_export_implode_delimiter', self::$implode, self::$exportID); if ( !empty(self::$exportOptions['xml_template_type']) && in_array(self::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ) self::$implode = '#delimiter#'; self::$acf_export = new XmlExportACF(); self::$woo_export = new XmlExportWooCommerce(); self::$user_export = new XmlExportUser(); self::$comment_export = new XmlExportComment(); self::$taxonomy_export = new XmlExportTaxonomy(); self::$woo_order_export = new XmlExportWooCommerceOrder(); self::$woo_coupon_export = new XmlExportWooCommerceCoupon(); } // [FILTERS] /** * * Filter data for advanced filtering * */ public function filter_export_filters($filters){ return array_merge($filters, $this->filter_sections); } // [\FILTERS] protected function init(){ PMXE_Plugin::$session->set('is_user_export', self::$is_user_export); PMXE_Plugin::$session->set('is_comment_export', self::$is_comment_export); PMXE_Plugin::$session->set('is_taxonomy_export', self::$is_taxonomy_export); PMXE_Plugin::$session->save_data(); if ('advanced' == $this->post['export_type']) { if( "" == $this->post['wp_query'] ){ $this->errors->add('form-validation', __('WP Query field is required', 'pmxe_plugin')); } else { $this->filters->parse(); PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere')); PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin')); PMXE_Plugin::$session->set('wp_query', $this->post['wp_query']); PMXE_Plugin::$session->save_data(); } } else { $this->filters->parse(); PMXE_Plugin::$session->set('cpt', self::$post_types); PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere')); PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin')); PMXE_Plugin::$session->save_data(); } PMXE_Plugin::$session->save_data(); } public function init_additional_data(){ self::$woo_order_export->init_additional_data(); self::$woo_export->init_additional_data(); } public function init_available_data(){ global $wpdb; $table_prefix = $wpdb->prefix; // Prepare existing taxonomies if ( 'specific' == $this->post['export_type'] and ! self::$is_user_export and ! self::$is_comment_export and ! self::$is_taxonomy_export ) { $this->_existing_taxonomies = wp_all_export_get_existing_taxonomies_by_cpt( self::$post_types[0] ); $this->_existing_meta_keys = wp_all_export_get_existing_meta_by_cpt( self::$post_types[0] ); } if ( 'advanced' == $this->post['export_type'] and ! self::$is_user_export and ! self::$is_comment_export and ! self::$is_taxonomy_export ) { $meta_keys = $wpdb->get_results("SELECT DISTINCT meta_key FROM {$table_prefix}postmeta WHERE {$table_prefix}postmeta.meta_key NOT LIKE '_edit%' LIMIT 500"); if ( ! empty($meta_keys)){ $exclude_keys = array('_first_variation_attributes', '_is_first_variation_created'); foreach ($meta_keys as $meta_key) { if ( strpos($meta_key->meta_key, "_tmp") === false && strpos($meta_key->meta_key, "_v_") === false && ! in_array($meta_key->meta_key, $exclude_keys)) $this->_existing_meta_keys[] = $meta_key->meta_key; } } global $wp_taxonomies; foreach ($wp_taxonomies as $key => $obj) { if (in_array($obj->name, array('nav_menu'))) continue; if (strpos($obj->name, "pa_") !== 0 and strlen($obj->name) > 3) $this->_existing_taxonomies[] = array( 'name' => empty($obj->label) ? $obj->name : $obj->label, 'label' => $obj->name, 'type' => 'cats' ); } } // Prepare existing ACF groups & fields self::$acf_export->init($this->_existing_meta_keys); // Prepare existing WooCommerce data self::$woo_export->init($this->_existing_meta_keys); // Prepare existing WooCommerce Order data self::$woo_order_export->init($this->_existing_meta_keys); // Prepare existing WooCommerce Coupon data self::$woo_coupon_export->init($this->_existing_meta_keys); // Prepare existing Users data self::$user_export->init($this->_existing_meta_keys); // Prepare existing Comments data self::$comment_export->init($this->_existing_meta_keys); // Prepare existing Taxonomy data self::$taxonomy_export->init($this->_existing_meta_keys); return $this->get_available_data(); } public function get_available_data(){ $this->available_data['acf_groups'] = self::$acf_export->get('_acf_groups'); $this->available_data['existing_acf_meta_keys'] = self::$acf_export->get('_existing_acf_meta_keys'); $this->available_data['existing_meta_keys'] = $this->_existing_meta_keys; $this->available_data['existing_taxonomies'] = $this->_existing_taxonomies; $this->available_data['init_fields'] = apply_filters('wp_all_export_init_fields', $this->init_fields); $this->available_data['default_fields'] = apply_filters('wp_all_export_default_fields', self::$default_fields); $this->available_data['other_fields'] = apply_filters('wp_all_export_other_fields', $this->other_fields); $this->available_data = apply_filters("wp_all_export_available_data", $this->available_data); return $this->available_data; } public function get_fields_options( $field_keys = array() ){ $fields = array( 'ids' => array(), 'cc_label' => array(), 'cc_php' => array(), 'cc_code' => array(), 'cc_sql' => array(), 'cc_options' => array(), 'cc_type' => array(), 'cc_value' => array(), 'cc_name' => array(), 'cc_settings' => array() ); self::$woo_order_export->get_fields_options( $fields, $field_keys ); $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections); foreach ($available_sections as $slug => $section) { if ( ! empty($this->available_data[$section['content']]) ): foreach ($this->available_data[$section['content']] as $field) { $field_key = (is_array($field)) ? $field['name'] : $field; if ( ! in_array($field_key, $field_keys) ) continue; $fields['ids'][] = 1; $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $field; $fields['cc_php'][] = ''; $fields['cc_code'][] = ''; $fields['cc_sql'][] = ''; $fields['cc_options'][] = ''; $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $slug; $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $field; $fields['cc_name'][] = $field_key; $fields['cc_settings'][] = ''; } endif; if ( ! empty($section['additional']) ) { foreach ($section['additional'] as $sub_slug => $sub_section) { foreach ($sub_section['meta'] as $field) { $key_to_check = (is_array($field)) ? $field['name'] : $field; if ( in_array($sub_slug, array('images', 'attachments')) ){ $key_to_check = preg_replace("%s$%","",ucfirst($sub_slug)) . ' ' . $key_to_check; } if ( ! in_array($key_to_check, $field_keys) ) continue; $field_options = ( in_array($sub_slug, array('images', 'attachments')) ) ? esc_attr('{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}') : '0'; $fields['ids'][] = 1; $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $field; $fields['cc_php'][] = ''; $fields['cc_code'][] = ''; $fields['cc_sql'][] = ''; $fields['cc_options'][] = $field_options; $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $sub_slug; $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $field; $fields['cc_name'][] = $key_to_check; $fields['cc_settings'][] = ''; } } } } if ( ! self::$is_comment_export ) { self::$acf_export->get_fields_options( $fields, $field_keys ); } $sort_fields = array(); foreach ($field_keys as $i => $field_key){ foreach ($fields['cc_name'] as $j => $cc_name){ if (!empty($cc_name) && $cc_name == $field_key){ $sort_fields['ids'][] = 1; $sort_fields['cc_label'][] = $fields['cc_label'][$j]; $sort_fields['cc_php'][] = $fields['cc_php'][$j]; $sort_fields['cc_code'][] = $fields['cc_code'][$j]; $sort_fields['cc_sql'][] = $fields['cc_sql'][$j]; $sort_fields['cc_options'][] = $fields['cc_options'][$j]; $sort_fields['cc_type'][] = $fields['cc_type'][$j]; $sort_fields['cc_value'][] = $fields['cc_value'][$j]; $sort_fields['cc_name'][] = $fields['cc_name'][$j]; $sort_fields['cc_settings'][] = $fields['cc_settings'][$j]; break; } } } return $sort_fields; } public function render(){ $i = 0; ob_start(); $available_sections = apply_filters("wp_all_export_available_sections", $this->available_sections); self::$globalAvailableSections = $available_sections; // Render Available WooCommerce Orders Data self::$woo_order_export->render($i); foreach ($available_sections as $slug => $section) { if ( ! empty($this->available_data[$section['content']]) or ! empty($section['additional']) ): ?>