예제 #1
0
 /**
  * Return singletone instance
  * @return XmlExportCpt
  */
 public static function getInstance()
 {
     if (self::$instance == NULL) {
         self::$instance = new self();
     }
     return self::$instance;
 }
예제 #2
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);
 }
예제 #3
0
 public static function prepare_import_template($exportOptions)
 {
     $options = $exportOptions;
     $is_xml_template = $options['export_to'] == 'xml';
     $required_add_ons = array();
     $cf_list = array();
     $attr_list = array();
     $taxs_list = array();
     $acf_list = array();
     $implode_delimiter = $options['delimiter'] == ',' ? '|' : ',';
     if (!empty($options['is_user_export'])) {
         self::$templateOptions['pmui']['import_users'] = 1;
     }
     foreach ($options['ids'] as $ID => $value) {
         if (empty($options['cc_type'][$ID])) {
             continue;
         }
         if ($is_xml_template) {
             $element_name = !empty($options['cc_name'][$ID]) ? str_replace(':', '_', preg_replace('/[^a-z0-9_:-]/i', '', $options['cc_name'][$ID])) : 'untitled_' . $ID;
         } else {
             $element_name = strtolower(!empty($options['cc_name'][$ID]) ? preg_replace('/[^a-z0-9_]/i', '', $options['cc_name'][$ID]) : 'untitled_' . $ID);
         }
         $element_type = $options['cc_type'][$ID];
         switch ($element_type) {
             case 'woo':
                 if (!empty($options['cc_value'][$ID])) {
                     if (empty($required_add_ons['PMWI_Plugin'])) {
                         $required_add_ons['PMWI_Plugin'] = array('name' => 'WooCommerce Add-On Pro', 'paid' => true, 'url' => 'http://www.wpallimport.com/woocommerce-product-import/');
                     }
                     XmlExportWooCommerce::prepare_import_template($options, self::$templateOptions, $cf_list, $attr_list, $element_name, $options['cc_label'][$ID]);
                 }
                 break;
             case 'acf':
                 if (empty($required_add_ons['PMAI_Plugin'])) {
                     $required_add_ons['PMAI_Plugin'] = array('name' => 'ACF Add-On Pro', 'paid' => true, 'url' => 'http://www.wpallimport.com/advanced-custom-fields/?utm_source=wordpress.org&utm_medium=wpai-import-template&utm_campaign=free+wp+all+export+plugin');
                 }
                 $field_options = unserialize($options['cc_options'][$ID]);
                 // add ACF group ID to the template options
                 if (!in_array($field_options['group_id'], self::$templateOptions['acf'])) {
                     self::$templateOptions['acf'][$field_options['group_id']] = 1;
                 }
                 self::$templateOptions['fields'][$field_options['key']] = XmlExportACF::prepare_import_template($options, self::$templateOptions, $acf_list, $element_name, $field_options);
                 break;
             default:
                 XmlExportCpt::prepare_import_template($options, self::$templateOptions, $cf_list, $attr_list, $taxs_list, $element_name, $ID);
                 XmlExportMediaGallery::prepare_import_template($options, self::$templateOptions, $element_name, $ID);
                 XmlExportWooCommerceOrder::prepare_import_template($options, self::$templateOptions, $element_name, $ID);
                 break;
         }
     }
     if (!empty($cf_list)) {
         self::$templateOptions['is_update_custom_fields'] = 1;
         self::$templateOptions['custom_fields_list'] = $cf_list;
     }
     if (!empty($attr_list)) {
         self::$templateOptions['is_update_attributes'] = 1;
         self::$templateOptions['update_attributes_logic'] = 'only';
         self::$templateOptions['attributes_list'] = $attr_list;
         self::$templateOptions['attributes_only_list'] = implode(',', $attr_list);
     } else {
         self::$templateOptions['is_update_attributes'] = 0;
     }
     if (!empty($taxs_list)) {
         self::$templateOptions['is_update_categories'] = 1;
         self::$templateOptions['taxonomies_list'] = $taxs_list;
     }
     if (!empty($acf_list)) {
         self::$templateOptions['is_update_acf'] = 1;
         self::$templateOptions['acf_list'] = $acf_list;
     }
     self::$templateOptions['required_add_ons'] = $required_add_ons;
 }
 protected function prepare_export_data($record, $options, $elId, $preview)
 {
     // an array with data to export
     $data = array('items' => array(), 'taxes' => array(), 'shipping' => array(), 'coupons' => array(), 'surcharge' => array());
     global $wpdb;
     $table_prefix = $wpdb->prefix;
     $implode_delimiter = XmlExportEngine::$implode;
     if (empty($this->order_id) or $this->order_id != $record->ID) {
         $this->order_id = $record->ID;
         $all_order_items = $wpdb->get_results("SELECT * FROM {$table_prefix}woocommerce_order_items WHERE order_id = {$record->ID}");
         if (!empty($all_order_items)) {
             foreach ($all_order_items as $item) {
                 switch ($item->order_item_type) {
                     case 'line_item':
                         $this->order_items[] = $item;
                         break;
                     case 'tax':
                         $this->order_taxes[] = $item;
                         break;
                     case 'shipping':
                         $this->order_shipping[] = $item;
                         break;
                     case 'coupon':
                         $this->order_coupons[] = $item;
                         break;
                     case 'fee':
                         $this->order_surcharge[] = $item;
                         break;
                 }
             }
         }
         $this->order_refunds = $wpdb->get_results("SELECT * FROM {$table_prefix}posts WHERE post_parent = {$record->ID} AND post_type = 'shop_order_refund'");
     }
     if (!empty($options['cc_value'][$elId])) {
         $is_items_in_list = false;
         $is_item_data_in_list = false;
         foreach ($options['ids'] as $ID => $value) {
             if ($options['cc_options'][$ID] == 'items') {
                 $is_items_in_list = true;
             }
             if (strpos($options['cc_label'][$ID], "item_data__") !== false) {
                 $is_item_data_in_list = true;
             }
         }
         $fieldSnipped = (!empty($options['cc_php'][$elId]) and !empty($options['cc_code'][$elId])) ? $options['cc_code'][$elId] : false;
         if (!$is_items_in_list and $is_item_data_in_list) {
             if (!empty($this->order_items)) {
                 foreach ($this->order_items as $n => $order_item) {
                     $meta_data = $wpdb->get_results("SELECT * FROM {$table_prefix}woocommerce_order_itemmeta WHERE order_item_id = {$order_item->order_item_id}", ARRAY_A);
                     $item_data = array();
                     foreach ($options['ids'] as $subID => $subvalue) {
                         if (strpos($options['cc_label'][$subID], 'item_data__') !== false) {
                             $product_id = '';
                             $variation_id = '';
                             foreach ($meta_data as $meta) {
                                 if ($meta['meta_key'] == '_variation_id' and !empty($meta['meta_value'])) {
                                     $variation_id = $meta['meta_value'];
                                 }
                                 if ($meta['meta_key'] == '_product_id' and !empty($meta['meta_value'])) {
                                     $product_id = $meta['meta_value'];
                                 }
                             }
                             $_product_id = empty($variation_id) ? $product_id : $variation_id;
                             $_product = get_post($_product_id);
                             // do not export anything if product doesn't exist
                             if (!empty($_product)) {
                                 $item_add_data = XmlExportCpt::prepare_data($_product, false, $this->acfs, $this->woo, $this->woo_order, ",", $preview, true, $subID);
                                 if (!empty($item_add_data)) {
                                     foreach ($item_add_data as $item_add_data_key => $item_add_data_value) {
                                         if (!isset($item_data[$item_add_data_key])) {
                                             $item_data[$item_add_data_key] = $item_add_data_value;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                     if (!empty($item_data)) {
                         $data['items'][] = $item_data;
                     }
                 }
                 $this->order_items = null;
             }
         }
         switch ($options['cc_options'][$elId]) {
             case 'order':
             case 'customer':
                 $data[$options['cc_name'][$elId]] = strpos($options['cc_value'][$elId], "_") === 0 ? get_post_meta($record->ID, $options['cc_value'][$elId], true) : $record->{$options['cc_value'][$elId]};
                 if ($options['cc_value'][$elId] == "post_title") {
                     $data[$options['cc_name'][$elId]] = str_replace("–", '-', $data[$options['cc_name'][$elId]]);
                 }
                 $data[$options['cc_name'][$elId]] = pmxe_filter($data[$options['cc_name'][$elId]], $fieldSnipped);
                 break;
         }
     }
     return $data;
 }
예제 #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);
 }