Пример #1
0
 public function __construct($post, &$errors)
 {
     $this->post = $post;
     $this->errors = $errors;
     $this->available_sections = array('default' => array('title' => __("Standard", "wp_all_export_plugin"), 'content' => 'default_fields'), '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('general' => array('title' => __("General", "wp_all_export_plugin"), 'fields' => array('ID' => 'ID', 'post_title' => 'Title', 'post_content' => 'Content', 'post_parent' => 'Parent ID', 'post_date' => 'Date (Y-m-d H:i:s)', 'post_status' => 'Status')), 'author' => array('title' => __("Author", "wp_all_export_plugin"), 'fields' => array('post_author' => 'Author ID')));
     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';
         }
         if (in_array('users', self::$post_types)) {
             self::$is_user_export = true;
         }
     } else {
         if ('wp_user_query' == $this->post['wp_query_selector']) {
             self::$is_user_export = true;
         }
     }
     self::$exportOptions = $post;
     $filter_args = array('filter_rules_hierarhy' => $this->post['filter_rules_hierarhy'], 'product_matching_mode' => $this->post['product_matching_mode']);
     $this->filters = new XmlExportFiltering($filter_args);
     $this->init();
     $this->acf_export = XmlExportACF::getInstance();
     $this->woo_export = XmlExportWooCommerce::getInstance();
     $this->user_export = XmlExportUser::getInstance();
     $this->woo_order_export = XmlExportWooCommerceOrder::getInstance();
 }
Пример #2
0
 public function __construct()
 {
     if (XmlExportEngine::$exportOptions['export_type'] == 'specific' and !in_array('users', XmlExportEngine::$post_types) or XmlExportEngine::$exportOptions['export_type'] == 'advanced' and XmlExportEngine::$exportOptions['wp_query_selector'] != 'wp_user_query') {
         self::$is_active = false;
         return;
     }
     $this->filter_sections = array('general' => array('title' => __("General", "wp_all_export_plugin"), 'fields' => array('ID' => 'ID', 'user_login' => 'User Login', 'user_email' => 'User Email', 'cf_first_name' => 'First Name', 'cf_last_name' => 'Last Name', 'user_role' => 'User Role', 'user_nicename' => 'User Nicename', 'user_url' => 'User URL', 'user_registered' => 'Registered Date (Y-m-d H:i:s)', 'user_status' => 'User Status', 'display_name' => 'Display Name', 'cf_nickname' => 'Nickname', 'cf_description' => 'Description')), 'advanced' => array('title' => __("Advanced", "wp_all_export_plugin"), 'fields' => array()));
     foreach ($this->advanced_fields as $key => $field) {
         if ($field['type'] == 'cf') {
             $this->filter_sections['advanced']['fields']['cf_' . $field['name']] = $field['name'];
         }
     }
     if (is_multisite()) {
         $this->filter_sections['network'] = array('title' => __("Network", "wp_all_export_plugin"), 'fields' => array('blog_id' => 'Blog ID'));
     }
     add_filter("wp_all_export_available_sections", array(&$this, "filter_available_sections"), 10, 1);
 }
Пример #3
0
 public function init(&$existing_meta_keys = array())
 {
     if (!self::$is_active) {
         return;
     }
     global $wpdb;
     $table_prefix = $wpdb->prefix;
     self::$meta_keys = $wpdb->get_results("SELECT DISTINCT {$table_prefix}usermeta.meta_key FROM {$table_prefix}usermeta, {$table_prefix}users WHERE {$table_prefix}usermeta.user_id = {$table_prefix}users.ID LIMIT 500");
     $user_ids = array();
     if (!empty(XmlExportEngine::$exportQuery->results)) {
         foreach (XmlExportEngine::$exportQuery->results as $user) {
             $user_ids[] = $user->ID;
         }
     }
     if (!empty(self::$meta_keys)) {
         $address_fields = $this->available_customer_data();
         $customer_users = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT meta_value FROM {$wpdb->postmeta}, {$wpdb->users} WHERE meta_key = %s AND meta_value != %s ", '_customer_user', '0'));
         // detect if at least one filtered user is a WooCommerce customer
         if (!empty($customer_users)) {
             foreach ($customer_users as $customer_user) {
                 if (in_array($customer_user->meta_value, $user_ids)) {
                     self::$is_woo_custom_founded = true;
                     break;
                 }
             }
         }
         $exclude_keys = array('_first_variation_attributes', '_is_first_variation_created');
         foreach (self::$meta_keys as $meta_key) {
             if (!in_array($meta_key->meta_key, $exclude_keys)) {
                 $to_add = true;
                 foreach ($this->default_fields as $default_value) {
                     if ($meta_key->meta_key == $default_value['name'] || $meta_key->meta_key == $default_value['type']) {
                         $to_add = false;
                         break;
                     }
                 }
                 if ($to_add) {
                     foreach ($this->advanced_fields as $advanced_value) {
                         if ($meta_key->meta_key == $advanced_value['name'] || $meta_key->meta_key == $advanced_value['type']) {
                             $to_add = false;
                             break;
                         }
                     }
                 }
                 if ($to_add) {
                     foreach ($this->user_core_fields as $core_field) {
                         if ($meta_key->meta_key == $core_field) {
                             $to_add = false;
                             break;
                         }
                     }
                 }
                 if ($to_add && (self::$is_export_shop_customer || self::$is_woo_custom_founded)) {
                     foreach ($address_fields as $address_value) {
                         if ($meta_key->meta_key == $address_value['label']) {
                             $to_add = false;
                             break;
                         }
                     }
                 }
                 if ($to_add) {
                     $existing_meta_keys[] = $meta_key->meta_key;
                 }
             }
         }
     }
 }
Пример #4
0
 public static function export_xml($preview = false, $is_cron = false, $file_path = false, $exported_by_cron = 0)
 {
     $is_custom_xml = !empty(XmlExportEngine::$exportOptions['xml_template_type']) && in_array(XmlExportEngine::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants')) ? true : false;
     if (!empty(XmlExportEngine::$exportOptions['xml_template_type'])) {
         switch (XmlExportEngine::$exportOptions['xml_template_type']) {
             case 'custom':
             case 'XmlGoogleMerchants':
                 XmlExportEngine::$exportOptions['ids'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['ids'];
                 XmlExportEngine::$exportOptions['cc_label'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_label'];
                 XmlExportEngine::$exportOptions['cc_type'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_type'];
                 XmlExportEngine::$exportOptions['cc_value'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_value'];
                 XmlExportEngine::$exportOptions['cc_name'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_name'];
                 XmlExportEngine::$exportOptions['cc_php'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_php'];
                 XmlExportEngine::$exportOptions['cc_code'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_code'];
                 XmlExportEngine::$exportOptions['cc_sql'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_sql'];
                 XmlExportEngine::$exportOptions['cc_options'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_options'];
                 XmlExportEngine::$exportOptions['cc_settings'] = XmlExportEngine::$exportOptions['custom_xml_template_options']['cc_settings'];
                 break;
             default:
                 # code...
                 break;
         }
     }
     if (XmlExportEngine::$exportOptions['delimiter'] == '\\t') {
         XmlExportEngine::$exportOptions['delimiter'] = "\t";
     }
     require_once PMXE_ROOT_DIR . '/classes/XMLWriter.php';
     $woo = array();
     $woo_order = array();
     $acfs = array();
     self::$main_xml_tag = apply_filters('wp_all_export_main_xml_tag', XmlExportEngine::$exportOptions['main_xml_tag'], XmlExportEngine::$exportID);
     self::$node_xml_tag = apply_filters('wp_all_export_record_xml_tag', XmlExportEngine::$exportOptions['record_xml_tag'], XmlExportEngine::$exportID);
     //        self::$implode = (XmlExportEngine::$exportOptions['delimiter'] == ',') ? '|' : ',';
     //
     //        if ( $is_custom_xml ) self::$implode = '#delimiter#';
     $xmlWriter = new PMXE_XMLWriter();
     if (!$is_custom_xml) {
         $xmlWriter->openMemory();
         $xmlWriter->setIndent(true);
         $xmlWriter->setIndentString("\t");
         $xmlWriter->startDocument('1.0', XmlExportEngine::$exportOptions['encoding']);
         $xmlWriter->startElement(self::$main_xml_tag);
         // add additional data after XML root element
         self::xml_header($xmlWriter, $is_cron, $exported_by_cron);
     }
     // [ Exporting requested data ]
     if (XmlExportEngine::$is_user_export) {
         foreach (XmlExportEngine::$exportQuery->results as $user) {
             $is_export_record = apply_filters('wp_all_export_xml_rows', true, $user, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
             if (!$is_export_record) {
                 continue;
             }
             if (!$is_custom_xml) {
                 // add additional information before each node
                 self::before_xml_node($xmlWriter, $user->ID);
                 $xmlWriter->startElement(self::$node_xml_tag);
                 XmlExportUser::prepare_data($user, $xmlWriter, $acfs, XmlExportEngine::$implode, $preview);
                 $xmlWriter->closeElement();
                 // end post
                 // add additional information after each node
                 self::after_xml_node($xmlWriter, $user->ID);
             } else {
                 $articles = array();
                 $articles[] = XmlExportUser::prepare_data($user, $xmlWriter, $acfs, XmlExportEngine::$implode, $preview);
                 $articles = apply_filters('wp_all_export_csv_rows', $articles, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
                 $xmlWriter->writeArticle($articles);
             }
             if (!$preview) {
                 do_action('pmxe_exported_post', $user->ID, XmlExportEngine::$exportRecord);
             }
         }
     } elseif (XmlExportEngine::$is_comment_export) {
         global $wp_version;
         if (version_compare($wp_version, '4.2.0', '>=')) {
             $comments = XmlExportEngine::$exportQuery->get_comments();
         } else {
             $comments = XmlExportEngine::$exportQuery;
         }
         foreach ($comments as $comment) {
             $is_export_record = apply_filters('wp_all_export_xml_rows', true, $comment, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
             if (!$is_export_record) {
                 continue;
             }
             if (!$is_custom_xml) {
                 // add additional information before each node
                 self::before_xml_node($xmlWriter, $comment->comment_ID);
                 $xmlWriter->startElement(self::$node_xml_tag);
                 XmlExportComment::prepare_data($comment, $xmlWriter, XmlExportEngine::$implode, $preview);
                 $xmlWriter->closeElement();
                 // end post
                 // add additional information after each node
                 self::after_xml_node($xmlWriter, $comment->comment_ID);
             } else {
                 $articles = array();
                 $articles[] = XmlExportComment::prepare_data($comment, $xmlWriter, XmlExportEngine::$implode, $preview);
                 $articles = apply_filters('wp_all_export_csv_rows', $articles, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
                 $xmlWriter->writeArticle($articles);
             }
             if (!$preview) {
                 do_action('pmxe_exported_post', $comment->comment_ID, XmlExportEngine::$exportRecord);
             }
         }
     } else {
         // exporting custom post types
         while (XmlExportEngine::$exportQuery->have_posts()) {
             XmlExportEngine::$exportQuery->the_post();
             $record = get_post(get_the_ID());
             $is_export_record = apply_filters('wp_all_export_xml_rows', true, $record, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
             if (!$is_export_record) {
                 continue;
             }
             if (!$is_custom_xml) {
                 // add additional information before each node
                 self::before_xml_node($xmlWriter, $record->ID);
                 $xmlWriter->startElement(self::$node_xml_tag);
                 XmlExportCpt::prepare_data($record, $xmlWriter, $acfs, $woo, $woo_order, XmlExportEngine::$implode, $preview);
                 $xmlWriter->closeElement();
                 // end post
                 // add additional information after each node
                 self::after_xml_node($xmlWriter, $record->ID);
             } else {
                 $articles = array();
                 $articles[] = XmlExportCpt::prepare_data($record, $xmlWriter, $acfs, $woo, $woo_order, XmlExportEngine::$implode, $preview);
                 $articles = apply_filters('wp_all_export_csv_rows', $articles, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
                 $xmlWriter->writeArticle($articles);
             }
             if (!$preview) {
                 do_action('pmxe_exported_post', $record->ID, XmlExportEngine::$exportRecord);
             }
         }
         wp_reset_postdata();
     }
     // [ \Exporting requested data ]
     if (!$is_custom_xml) {
         $xmlWriter->closeElement();
     }
     // close root XML element
     if ($preview) {
         return $xmlWriter->wpae_flush();
     }
     return self::save_xml_to_file($xmlWriter, $file_path, $is_cron, $exported_by_cron);
 }
Пример #5
0
 public static function export_xml($preview = false, $is_cron = false, $file_path = false, $exported_by_cron = 0)
 {
     require_once PMXE_ROOT_DIR . '/classes/XMLWriter.php';
     $woo = array();
     $woo_order = array();
     $acfs = array();
     $taxes = array();
     $attributes = array();
     self::$main_xml_tag = apply_filters('wp_all_export_main_xml_tag', XmlExportEngine::$exportOptions['main_xml_tag'], XmlExportEngine::$exportID);
     self::$node_xml_tag = apply_filters('wp_all_export_record_xml_tag', XmlExportEngine::$exportOptions['record_xml_tag'], XmlExportEngine::$exportID);
     $implode_delimiter = XmlExportEngine::$exportOptions['delimiter'] == ',' ? '|' : ',';
     $xmlWriter = new PMXE_XMLWriter();
     $xmlWriter->openMemory();
     $xmlWriter->setIndent(true);
     $xmlWriter->setIndentString("\t");
     $xmlWriter->startDocument('1.0', XmlExportEngine::$exportOptions['encoding']);
     $xmlWriter->startElement(self::$main_xml_tag);
     // add additional data after XML root element
     self::xml_header($xmlWriter, $is_cron, $exported_by_cron);
     // [ Exporting requested data ]
     if (XmlExportEngine::$is_user_export) {
         foreach (XmlExportEngine::$exportQuery->results as $user) {
             $is_export_record = apply_filters('wp_all_export_xml_rows', true, $user, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
             if (!$is_export_record) {
                 continue;
             }
             // add additional information before each node
             self::before_xml_node($xmlWriter, $user->ID);
             $xmlWriter->startElement(self::$node_xml_tag);
             XmlExportUser::prepare_data($user, $xmlWriter, $acfs, $implode_delimiter, $preview);
             $xmlWriter->endElement();
             // end post
             // add additional information after each node
             self::after_xml_node($xmlWriter, $user->ID);
             if ($preview) {
                 break;
             }
             do_action('pmxe_exported_post', $user->ID, XmlExportEngine::$exportRecord);
         }
     } elseif (XmlExportEngine::$is_comment_export) {
         global $wp_version;
         if (version_compare($wp_version, '4.2.0', '>=')) {
             $comments = XmlExportEngine::$exportQuery->get_comments();
         } else {
             $comments = XmlExportEngine::$exportQuery;
         }
         foreach ($comments as $comment) {
             $is_export_record = apply_filters('wp_all_export_xml_rows', true, $comment, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
             if (!$is_export_record) {
                 continue;
             }
             // add additional information before each node
             self::before_xml_node($xmlWriter, $comment->comment_ID);
             $xmlWriter->startElement(self::$node_xml_tag);
             XmlExportComment::prepare_data($comment, $xmlWriter, $implode_delimiter, $preview);
             $xmlWriter->endElement();
             // end post
             // add additional information after each node
             self::after_xml_node($xmlWriter, $comment->comment_ID);
             if ($preview) {
                 break;
             }
             do_action('pmxe_exported_post', $comment->comment_ID, XmlExportEngine::$exportRecord);
         }
     } else {
         while (XmlExportEngine::$exportQuery->have_posts()) {
             XmlExportEngine::$exportQuery->the_post();
             $record = get_post(get_the_ID());
             $is_export_record = apply_filters('wp_all_export_xml_rows', true, $record, XmlExportEngine::$exportOptions, XmlExportEngine::$exportID);
             if (!$is_export_record) {
                 continue;
             }
             // add additional information before each node
             self::before_xml_node($xmlWriter, $record->ID);
             $xmlWriter->startElement(self::$node_xml_tag);
             XmlExportCpt::prepare_data($record, $xmlWriter, $acfs, $woo, $woo_order, $implode_delimiter, $preview);
             $xmlWriter->endElement();
             // end post
             // add additional information after each node
             self::after_xml_node($xmlWriter, $record->ID);
             if ($preview) {
                 break;
             }
             do_action('pmxe_exported_post', $record->ID, XmlExportEngine::$exportRecord);
         }
         wp_reset_postdata();
     }
     // [ \Exporting requested data ]
     $xmlWriter->endElement();
     // close root XML element
     if ($preview) {
         return $xmlWriter->flush(true);
     }
     return self::save_xml_to_file($xmlWriter, $file_path, $is_cron, $exported_by_cron);
 }