public function __construct() { if (!class_exists('WooCommerce') or XmlExportEngine::$exportOptions['export_type'] == 'specific' and !in_array('shop_order', XmlExportEngine::$post_types) or XmlExportEngine::$exportOptions['export_type'] == 'advanced' and strpos(XmlExportEngine::$exportOptions['wp_query'], 'shop_order') === false) { self::$is_active = false; return; } $this->filter_sections = array('general' => array('title' => __("Order", "wp_all_export_plugin"), 'fields' => array('ID' => __('Order ID', 'wp_all_export_plugin'), 'cf__order_key' => __('Order Key', 'wp_all_export_plugin'), 'post_date' => __('Order Date', 'wp_all_export_plugin'), 'cf__completed_date' => __('Completed Date', 'wp_all_export_plugin'), 'post_title' => __('Title', 'wp_all_export_plugin'), 'post_status' => __('Order Status', 'wp_all_export_plugin'), 'cf__order_currency' => __('Order Currency', 'wp_all_export_plugin'), 'cf__payment_method_title' => __('Payment Method', 'wp_all_export_plugin'), 'cf__order_total' => __('Order Total', 'wp_all_export_plugin'))), 'customer' => array('title' => __("Customer", "wp_all_export_plugin"), 'fields' => array())); foreach ($this->available_customer_data() as $key => $value) { $this->filter_sections['customer']['fields'][$key == 'post_excerpt' ? $key : 'cf_' . $key] = $value; } if (empty(PMXE_Plugin::$session)) { $id = $_GET['export_id']; $export = new PMXE_Export_Record(); $export->getById($id); if (!$export->isEmpty() and $export->options['export_to'] == 'csv') { $this->init_additional_data(); } } else { self::$orders_data = PMXE_Plugin::$session->get('orders_data'); //self::$exportQuery = XmlExportEngine::$exportQuery; } add_filter("wp_all_export_available_sections", array(&$this, "filter_available_sections"), 10, 1); add_filter("wp_all_export_available_filter_sections", array(&$this, "filter_available_filter_sections"), 10, 1); add_filter("wp_all_export_csv_rows", array(&$this, "filter_csv_rows"), 10, 2); self::$order_sections = $this->available_sections(); }
/** * Checks whether corresponding step of wizard is complete * @param string $action */ protected function _step_ready($action) { // step #1: xml selction - has no prerequisites if ('index' == $action) { return true; } if ('element' == $action) { return true; } $this->data['update_previous'] = $update_previous = new PMXE_Export_Record(); $update_previous->getById(PMXE_Plugin::$session->update_previous); if (!$update_previous->isEmpty()) { $update_previous->fix_template_options(); } if ('options' == $action) { return true; } if (!PMXE_Plugin::$session->has_session()) { wp_redirect_or_javascript($this->baseUrl); die; } if ('process' == $action) { return true; } }
private function __construct() { if (!class_exists('WooCommerce') or XmlExportEngine::$exportOptions['export_type'] == 'specific' and !in_array('product', XmlExportEngine::$post_types) or XmlExportEngine::$exportOptions['export_type'] == 'advanced' and strpos(XmlExportEngine::$exportOptions['wp_query'], 'product') === false) { self::$is_active = false; return; } $this->_woo_data = array('_visibility', '_stock_status', '_downloadable', '_virtual', '_regular_price', '_sale_price', '_purchase_note', '_featured', '_weight', '_length', '_width', '_height', '_sku', '_sale_price_dates_from', '_sale_price_dates_to', '_price', '_sold_individually', '_manage_stock', '_stock', '_upsell_ids', '_crosssell_ids', '_downloadable_files', '_download_limit', '_download_expiry', '_download_type', '_product_url', '_button_text', '_backorders', '_tax_status', '_tax_class', '_product_image_gallery', '_default_attributes', 'total_sales', '_product_attributes', '_product_version'); $this->_product_data = array('_sku', '_price', '_regular_price', '_sale_price', '_stock_status', '_stock', '_visibility', '_product_url', 'total_sales', 'attributes'); if (empty(PMXE_Plugin::$session)) { $id = $_GET['export_id']; $export = new PMXE_Export_Record(); $export->getById($id); if (!$export->isEmpty() and $export->options['export_to'] == 'csv') { $this->init_additional_data(); } } else { self::$products_data = PMXE_Plugin::$session->get('products_data'); } add_filter("wp_all_export_init_fields", array(&$this, "filter_init_fields"), 10, 1); add_filter("wp_all_export_default_fields", array(&$this, "filter_default_fields"), 10, 1); add_filter("wp_all_export_other_fields", array(&$this, "filter_other_fields"), 10, 1); add_filter("wp_all_export_available_sections", array(&$this, "filter_available_sections"), 10, 1); add_filter("wp_all_export_available_data", array(&$this, "filter_available_data"), 10, 1); add_filter("wp_all_export_filters", array(&$this, "filter_export_filters"), 10, 1); }
function wp_all_export_pre_user_query($obj) { // cron job execution if (empty(PMXE_Plugin::$session)) { $id = $_GET['export_id']; $export = new PMXE_Export_Record(); $export->getById($id); if (!$export->isEmpty()) { if (!empty($export->options['whereclause'])) { $obj->query_where .= $export->options['whereclause']; } if (!empty($export->options['joinclause'])) { $obj->query_from .= implode(' ', array_unique($export->options['joinclause'])); } } } else { $customWhere = PMXE_Plugin::$session->get('whereclause'); $obj->query_where .= $customWhere; $customJoin = PMXE_Plugin::$session->get('joinclause'); if (!empty($customJoin)) { $obj->query_from .= implode(' ', array_unique($customJoin)); } } return $obj; }
function pmxe_wp_all_import_is_exported_file_valid($is_valid, $export_id, $elements_cloud) { $exportRecord = new PMXE_Export_Record(); $exportRecord->getById($export_id); if (!$exportRecord->isEmpty()) { $exportOptions = $exportRecord->options; $required_fields = array(); foreach ($exportOptions['ids'] as $ID => $value) { if (is_numeric($ID)) { $element_name = !empty($exportOptions['cc_name'][$ID]) ? str_replace(" ", "_", $exportOptions['cc_name'][$ID]) : 'untitled_' . $ID; switch ($exportOptions['cc_type'][$ID]) { case 'id': $required_fields[] = $element_name; break; case 'post_type': if ($exportOptions['export_type'] == 'advanced') { $required_fields[] = $element_name; } break; case 'woo': if (!empty($exportOptions['cpt']) and in_array('product', $exportOptions['cpt'])) { switch ($exportOptions['cc_label'][$ID]) { case '_sku': $required_fields[] = $element_name; break; } } break; case 'cats': if (!empty($exportOptions['cpt']) and in_array('product', $exportOptions['cpt'])) { switch ($exportOptions['cc_label'][$ID]) { case 'product_type': $required_fields[] = $element_name; break; } } break; } } } if (!empty($required_fields)) { $is_file_valid = true; foreach ($required_fields as $field) { if (empty($elements_cloud[$field]) and empty($elements_cloud[strtolower($field)])) { $is_valid = false; break; } } } } return $is_valid; }
function wp_all_export_generate_export_file($export_id) { $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); $wp_uploads = wp_upload_dir(); $target = $is_secure_import ? wp_all_export_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY, $export_id) : $wp_uploads['path']; $export = new PMXE_Export_Record(); $export->getById($export_id); if (!$export->isEmpty() and $export->options['creata_a_new_export_file']) { $export_file_name = sanitize_file_name($export->options['friendly_name']) . ' - ' . ($export->iteration + 1) . '.' . $export->options['export_to']; } else { $export_file_name = sanitize_file_name($export->options['friendly_name']) . '.' . $export->options['export_to']; } return $target . DIRECTORY_SEPARATOR . $export_file_name; }
function wp_all_export_generate_export_file($export_id) { $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); $wp_uploads = wp_upload_dir(); $target = $is_secure_import ? wp_all_export_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY, $export_id) : $wp_uploads['path']; $export = new PMXE_Export_Record(); $export->getById($export_id); if (!$export->isEmpty()) { if ($export->options['creata_a_new_export_file'] and !XmlExportWooCommerceOrder::$is_active || $export->options['export_type'] != 'specific') { $export_file_name = sanitize_file_name($export->friendly_name) . ' - ' . ($export->iteration + 1) . '.' . $export->options['export_to']; } else { $export_file_name = sanitize_file_name($export->friendly_name) . '.' . $export->options['export_to']; } } return apply_filters('wp_all_export_export_file_name', $target . DIRECTORY_SEPARATOR . $export_file_name, $export_id); }
function pmxe_wp_loaded() { @ini_set("max_input_time", PMXE_Plugin::getInstance()->getOption('max_input_time')); @ini_set("max_execution_time", PMXE_Plugin::getInstance()->getOption('max_execution_time')); /* Check if cron is manualy, then execute export */ $cron_job_key = PMXE_Plugin::getInstance()->getOption('cron_job_key'); if (!empty($cron_job_key) and !empty($_GET['export_id']) and !empty($_GET['export_key']) and $_GET['export_key'] == $cron_job_key and !empty($_GET['action']) and in_array($_GET['action'], array('processing', 'trigger'))) { $logger = create_function('$m', 'echo "<p>$m</p>\\n";'); $export = new PMXE_Export_Record(); $ids = explode(',', $_GET['export_id']); if (!empty($ids) and is_array($ids)) { foreach ($ids as $id) { if (empty($id)) { continue; } $export->getById($id); if (!$export->isEmpty()) { switch ($_GET['action']) { case 'trigger': if ((int) $export->executing) { $logger and call_user_func($logger, sprintf(__('Export #%s is currently in manually process. Request skipped.', 'wp_all_export_plugin'), $id)); } elseif (!$export->processing and !$export->triggered) { $export->set(array('triggered' => 1, 'exported' => 0, 'last_activity' => date('Y-m-d H:i:s')))->update(); $logger and call_user_func($logger, sprintf(__('#%s Cron job triggered.', 'wp_all_export_plugin'), $id)); } elseif ($export->processing and !$export->triggered) { $logger and call_user_func($logger, sprintf(__('Export #%s currently in process. Request skipped.', 'wp_all_export_plugin'), $id)); } elseif (!$export->processing and $export->triggered) { $logger and call_user_func($logger, sprintf(__('Export #%s already triggered. Request skipped.', 'wp_all_export_plugin'), $id)); } break; case 'processing': if ($export->processing == 1 and time() - strtotime($export->registered_on) > 120) { // it means processor crashed, so it will reset processing to false, and terminate. Then next run it will work normally. $export->set(array('processing' => 0))->update(); } // start execution imports that is in the cron process if (!(int) $export->triggered) { $logger and call_user_func($logger, sprintf(__('Export #%s is not triggered. Request skipped.', 'wp_all_export_plugin'), $id)); } elseif ((int) $export->executing) { $logger and call_user_func($logger, sprintf(__('Export #%s is currently in manually process. Request skipped.', 'wp_all_export_plugin'), $id)); } elseif ((int) $export->triggered and !(int) $export->processing) { ob_start(); $export->set(array('canceled' => 0))->execute($logger, true); if (!(int) $export->exported) { $logger and call_user_func($logger, sprintf(__('Export #%s complete', 'wp_all_export_plugin'), $export->id)); } else { $logger and call_user_func($logger, sprintf(__('Records Processed %s', 'wp_all_export_plugin'), (int) $export->exported)); } } else { $logger and call_user_func($logger, sprintf(__('Export #%s already processing. Request skipped.', 'wp_all_export_plugin'), $id)); } break; } } } } } }
public function __construct() { $this->order_core_fields = array('_prices_include_tax', '_customer_ip_address', '_customer_user_agent', '_created_via', '_order_version', '_payment_method', '_cart_discount_tax', '_order_shipping_tax', '_recorded_sales', '_order_stock_reduced', '_recorded_coupon_usage_counts', '_transaction_id'); if (!class_exists('WooCommerce') or XmlExportEngine::$exportOptions['export_type'] == 'specific' and !in_array('shop_order', XmlExportEngine::$post_types) or XmlExportEngine::$exportOptions['export_type'] == 'advanced' and strpos(XmlExportEngine::$exportOptions['wp_query'], 'shop_order') === false) { self::$is_active = false; return; } self::$is_active = true; if (empty(PMXE_Plugin::$session)) { $id = $_GET['export_id']; $export = new PMXE_Export_Record(); $export->getById($id); if (!$export->isEmpty() and $export->options['export_to'] == 'csv') { $this->init_additional_data(); } } else { $this->init_additional_data(); } add_filter("wp_all_export_available_sections", array(&$this, "filter_available_sections"), 10, 1); add_filter("wp_all_export_csv_rows", array(&$this, "filter_csv_rows"), 10, 2); add_filter("wp_all_export_init_fields", array(&$this, "filter_init_fields"), 10, 1); self::$order_sections = $this->available_sections(); }
</label> </div> <div class="input"> <input type="hidden" name="is_delete_attachments" value="no"/> <input type="checkbox" id="is_delete_attachments" name="is_delete_attachments" value="yes" /> <label for="is_delete_attachments"><?php _e('Delete associated files from media gallery', 'wp_all_import_plugin'); ?> </label> </div> </div> <?php if (!empty($item->options['deligate']) and $item->options['deligate'] == 'wpallexport' and class_exists('PMXE_Plugin')) { ?> <?php $export = new PMXE_Export_Record(); $export->getById($item->options['export_id']); if (!$export->isEmpty()) { printf(__('<p class="wpallimport-delete-posts-warning"><strong>Important</strong>: this import was created automatically by WP All Export. All posts exported by the "%s" export job have been automatically associated with this import.</p>', 'wp_all_export_plugin'), $export->friendly_name); } ?> <?php } ?> </div> <p class="submit"> <?php wp_nonce_field('delete-import', '_wpnonce_delete-import'); ?> <input type="hidden" name="is_confirmed" value="1" /> <input type="submit" class="button-primary" value="Delete" />
if (!empty($update_previous->options['split_large_exports'])) { ?> <div class="input" style="margin-left: 10px;"> <button class="button button-primary button-hero wpallexport-large-button download_data" rel="<?php echo add_query_arg(array('page' => 'pmxe-admin-manage', 'id' => $update_previous->id, 'action' => 'split_bundle', '_wpnonce' => wp_create_nonce('_wpnonce-download_split_bundle')), $this->baseUrl); ?> "><?php printf(__('Split %ss', 'wp_all_export_plugin'), strtoupper(wp_all_export_get_export_format($update_previous->options))); ?> </button> </div> <?php } ?> <?php if (PMXE_Export_Record::is_bundle_supported($update_previous->options)) { ?> <div class="input" style="margin-left: 10px;"> <button class="button button-primary button-hero wpallexport-large-button download_data" rel="<?php echo add_query_arg(array('page' => 'pmxe-admin-manage', 'id' => $update_previous->id, 'action' => 'bundle', '_wpnonce' => wp_create_nonce('_wpnonce-download_bundle')), $this->baseUrl); ?> "><?php _e('Bundle', 'wp_all_export_plugin'); ?> </button> <span><?php _e('Settings & Data for WP All Import', 'wp_all_export_plugin'); ?> </span> </div> <?php
function pmxe_wp_ajax_export_filtering_count() { if (!check_ajax_referer('wp_all_export_secure', 'security', false)) { exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin')))); } if (!current_user_can('manage_options')) { exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin')))); } ob_start(); $input = new PMXE_Input(); $post = $input->post('data', array()); $filter_args = array('filter_rules_hierarhy' => $post['filter_rules_hierarhy'], 'product_matching_mode' => $post['product_matching_mode']); $input = new PMXE_Input(); $export_id = $input->get('id', 0); if (empty($export_id)) { $export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0; } $export = new PMXE_Export_Record(); $export->getById($export_id); if (!$export->isEmpty()) { XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options(); XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff']; } XmlExportEngine::$is_user_export = 'users' == $post['cpt'] ? true : false; XmlExportEngine::$post_types = array($post['cpt']); $filters = new XmlExportFiltering($filter_args); $filters->parseQuery(); PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere')); PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin')); PMXE_Plugin::$session->save_data(); $found_records = 0; if ('users' == $post['cpt']) { add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1); $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10)); if (!empty($exportQuery->results)) { $found_records = $exportQuery->get_total(); } remove_action('pre_user_query', 'wp_all_export_pre_user_query'); } else { add_filter('posts_where', 'wp_all_export_posts_where', 10, 1); add_filter('posts_join', 'wp_all_export_posts_join', 10, 1); $cpt = $post['cpt'] == 'product' ? array('product', 'product_variation') : $post['cpt']; $exportQuery = new WP_Query(array('post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10)); if (!empty($exportQuery->found_posts)) { $found_records = $exportQuery->found_posts; } remove_filter('posts_join', 'wp_all_export_posts_join'); remove_filter('posts_where', 'wp_all_export_posts_where'); } if ($post['is_confirm_screen']) { ?> <?php if ($found_records > 0) { ?> <h3><?php _e('Your export is ready to run.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__('WP All Export will export %d %s.', 'wp_all_export_plugin'), $found_records, wp_all_export_get_cpt_name(array($post['cpt']), $found_records)); ?> </h4> <?php } else { ?> <?php if (!$export->isEmpty() and $export->options['export_only_new_stuff']) { ?> <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt']))); ?> </h4> <?php } else { ?> <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt']))); ?> </h4> <?php } ?> <?php } ?> <?php } else { ?> <div class="founded_records"> <?php if ($found_records > 0) { ?> <h3><span class="matches_count"><?php echo $found_records; ?> </span> <strong><?php echo wp_all_export_get_cpt_name(array($post['cpt']), $found_records); ?> </strong> will be exported</h3> <h4><?php _e("Continue to Step 2 to choose data to include in the export file.", "wp_all_export_plugin"); ?> </h4> <?php } else { ?> <h4 style="line-height:60px;"><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name(array($post['cpt']))); ?> </h4> <?php } ?> </div> <?php } exit(json_encode(array('html' => ob_get_clean(), 'found_records' => $found_records))); die; }
function pmxe_pmxe_after_export($export_id) { $export = new PMXE_Export_Record(); $export->getById($export_id); $splitSize = $export->options['split_large_exports_count']; if (!$export->isEmpty()) { $export->set(array('iteration' => $export->options['creata_a_new_export_file'] ? $export->iteration + 1 : 0))->update(); $exportOptions = $export->options; // remove previously genereted chunks if (!empty($exportOptions['split_files_list']) and !$export->options['creata_a_new_export_file']) { foreach ($exportOptions['split_files_list'] as $file) { @unlink($file); } } $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); if (!$is_secure_import) { $filepath = get_attached_file($export->attch_id); } else { $filepath = wp_all_export_get_absolute_path($export->options['filepath']); } // Split large exports into chunks if ($export->options['split_large_exports'] and $splitSize < $export->exported) { $exportOptions['split_files_list'] = array(); if (@file_exists($filepath)) { switch ($export->options['export_to']) { case 'xml': $records_count = 0; $chunk_records_count = 0; $fileCount = 1; $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<" . $export->options['main_xml_tag'] . ">"; $file = new PMXE_Chunk($filepath, array('element' => $export->options['record_xml_tag'], 'encoding' => 'UTF-8')); // loop through the file until all lines are read while ($xml = $file->read()) { if (!empty($xml)) { $chunk = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml; $dom = new DOMDocument('1.0', "UTF-8"); $old = libxml_use_internal_errors(true); $dom->loadXML($chunk); // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); $records_count++; $chunk_records_count++; $feed .= $xml; } if ($chunk_records_count == $splitSize or $records_count == $export->exported) { $feed .= "</" . $export->options['main_xml_tag'] . ">"; $outputFile = str_replace(basename($filepath), str_replace('.xml', '', basename($filepath)) . '-' . $fileCount++ . '.xml', $filepath); file_put_contents($outputFile, $feed); if (!in_array($outputFile, $exportOptions['split_files_list'])) { $exportOptions['split_files_list'][] = $outputFile; } $chunk_records_count = 0; $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<" . $export->options['main_xml_tag'] . ">"; } } break; case 'csv': $in = fopen($filepath, 'r'); $rowCount = 0; $fileCount = 1; $headers = fgetcsv($in); while (!feof($in)) { $data = fgetcsv($in); if (empty($data)) { continue; } if ($rowCount % $splitSize == 0) { if ($rowCount > 0) { fclose($out); } $outputFile = str_replace(basename($filepath), str_replace('.csv', '', basename($filepath)) . '-' . $fileCount++ . '.csv', $filepath); if (!in_array($outputFile, $exportOptions['split_files_list'])) { $exportOptions['split_files_list'][] = $outputFile; } $out = fopen($outputFile, 'w'); } if ($data) { if ($rowCount % $splitSize == 0) { fputcsv($out, $headers); } fputcsv($out, $data); } $rowCount++; } fclose($out); break; default: break; } $export->set(array('options' => $exportOptions))->save(); } } } }
<?php } ?> <?php if ($is_secure_import and !empty($item['options']['filepath'])) { ?> <span class="update"><a class="update" href="<?php echo esc_url(add_query_arg(array('id' => $item['id'], 'action' => 'get_file', '_wpnonce' => wp_create_nonce('_wpnonce-download_feed')), $this->baseUrl)); ?> "><?php echo strtoupper(wp_all_export_get_export_format($item['options'])); ?> </a></span> | <?php if (!empty($item['options']['bundlepath']) and PMXE_Export_Record::is_bundle_supported($item['options'])) { ?> <span class="update"><a class="update" href="<?php echo esc_url(add_query_arg(array('id' => $item['id'], 'action' => 'bundle', '_wpnonce' => wp_create_nonce('_wpnonce-download_bundle')), $this->baseUrl)); ?> "><?php _e('Bundle', 'wp_all_export_plugin'); ?> </a></span> | <?php } ?> <?php } ?>
public function get_file() { $nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : ''; if (!wp_verify_nonce($nonce, '_wpnonce-download_feed')) { die(__('Security check', 'wp_all_export_plugin')); } else { $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); $id = $this->input->get('id'); $export = new PMXE_Export_Record(); $filepath = ''; if (!$export->getById($id)->isEmpty()) { if (!$is_secure_import) { $filepath = get_attached_file($export->attch_id); } else { $filepath = wp_all_export_get_absolute_path($export->options['filepath']); } if (@file_exists($filepath)) { switch ($export->options['export_to']) { case 'xml': PMXE_download::xml($filepath); break; case 'csv': PMXE_download::csv($filepath); break; default: wp_redirect(add_query_arg('pmxe_nt', urlencode(__('File format not supported', 'pmxe_plugin')), $this->baseUrl)); die; break; } } else { wp_redirect(add_query_arg('pmxe_nt', urlencode(__('The exported file is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'pmxe_plugin')), $this->baseUrl)); die; } } else { wp_redirect(add_query_arg('pmxe_nt', urlencode(__('The exported file is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'pmxe_plugin')), $this->baseUrl)); die; } } }
/** * AJAX action export processing */ function pmxe_wp_ajax_wpallexport() { if (!check_ajax_referer('wp_all_export_secure', 'security', false)) { exit(__('Security check', 'wp_all_export_plugin')); } if (!current_user_can(PMXE_Plugin::$capabilities)) { exit(__('Security check', 'wp_all_export_plugin')); } $input = new PMXE_Input(); $export_id = $input->get('id', 0); if (empty($export_id)) { $export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0; } $wp_uploads = wp_upload_dir(); $export = new PMXE_Export_Record(); $export->getById($export_id); if ($export->isEmpty()) { exit(__('Export is not defined.', 'wp_all_export_plugin')); } $exportOptions = $export->options + PMXE_Plugin::get_default_import_options(); wp_reset_postdata(); XmlExportEngine::$exportOptions = $exportOptions; XmlExportEngine::$is_user_export = $exportOptions['is_user_export']; XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export']; XmlExportEngine::$exportID = $export_id; XmlExportEngine::$exportRecord = $export; $errors = new WP_Error(); $engine = new XmlExportEngine($exportOptions, $errors); $posts_per_page = $exportOptions['records_per_iteration']; if ('advanced' == $exportOptions['export_type']) { if (XmlExportEngine::$is_user_export) { exit(json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Users', 'wp_all_export_plugin')))); } elseif (XmlExportEngine::$is_comment_export) { exit(json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Comments', 'wp_all_export_plugin')))); } else { remove_all_actions('parse_query'); remove_all_actions('pre_get_posts'); remove_all_filters('posts_clauses'); add_filter('posts_join', 'wp_all_export_posts_join', 10, 1); add_filter('posts_where', 'wp_all_export_posts_where', 10, 1); $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));'); remove_filter('posts_where', 'wp_all_export_posts_where'); remove_filter('posts_join', 'wp_all_export_posts_join'); } } else { XmlExportEngine::$post_types = $exportOptions['cpt']; // $is_products_export = ($exportOptions['cpt'] == 'product' and class_exists('WooCommerce')); if (in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt'])) { exit(json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Users', 'wp_all_export_plugin')))); } elseif (in_array('comments', $exportOptions['cpt'])) { exit(json_encode(array('html' => __('Upgrade to the Pro edition of WP All Export to Export Comments', 'wp_all_export_plugin')))); } else { remove_all_actions('parse_query'); remove_all_actions('pre_get_posts'); remove_all_filters('posts_clauses'); add_filter('posts_join', 'wp_all_export_posts_join', 10, 1); add_filter('posts_where', 'wp_all_export_posts_where', 10, 1); $exportQuery = new WP_Query(array('post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $export->exported, 'posts_per_page' => $posts_per_page)); remove_filter('posts_where', 'wp_all_export_posts_where'); remove_filter('posts_join', 'wp_all_export_posts_join'); } } XmlExportEngine::$exportQuery = $exportQuery; $engine->init_additional_data(); // get total founded records if (XmlExportEngine::$is_comment_export) { } else { $foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total(); $postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results()); } // [ \get total founded records ] if (!$export->exported) { $attachment_list = $export->options['attachment_list']; if (!empty($attachment_list)) { foreach ($attachment_list as $attachment) { if (!is_numeric($attachment)) { @unlink($attachment); } } } $exportOptions['attachment_list'] = array(); $export->set(array('options' => $exportOptions))->save(); $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); if ($is_secure_import and !empty($exportOptions['filepath'])) { $exportOptions['filepath'] = ''; } PMXE_Plugin::$session->set('count', $foundPosts); PMXE_Plugin::$session->save_data(); } // if posts still exists then export them if ($postCount) { XmlCsvExport::export(); $export->set(array('exported' => $export->exported + $postCount, 'last_activity' => date('Y-m-d H:i:s')))->save(); } if ($posts_per_page != -1 and $postCount) { wp_send_json(array('export_id' => $export->id, 'queue_export' => false, 'exported' => $export->exported, 'percentage' => ceil($export->exported / $foundPosts * 100), 'done' => false, 'records_per_request' => $exportOptions['records_per_iteration'])); } else { if (file_exists(PMXE_Plugin::$session->file)) { if ($exportOptions['export_to'] == 'xml') { $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], $export->id); file_put_contents(PMXE_Plugin::$session->file, '</' . $main_xml_tag . '>', FILE_APPEND); $xml_footer = apply_filters('wp_all_export_xml_footer', '', $export->id); if (!empty($xml_footer)) { file_put_contents(PMXE_Plugin::$session->file, $xml_footer, FILE_APPEND); } } $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); if (!$is_secure_import) { if (!$export->isEmpty()) { $wp_filetype = wp_check_filetype(basename(PMXE_Plugin::$session->file), null); $attachment_data = array('guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path(PMXE_Plugin::$session->file), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename(PMXE_Plugin::$session->file)), 'post_content' => '', 'post_status' => 'inherit'); if (empty($export->attch_id)) { $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file); } elseif ($export->options['creata_a_new_export_file']) { $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file); } else { $attach_id = $export->attch_id; $attachment = get_post($attach_id); if ($attachment) { update_attached_file($attach_id, PMXE_Plugin::$session->file); wp_update_attachment_metadata($attach_id, $attachment_data); } else { $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file); } } if (!in_array($attach_id, $exportOptions['attachment_list'])) { $exportOptions['attachment_list'][] = $attach_id; } $export->set(array('attch_id' => $attach_id, 'options' => $exportOptions))->save(); } } else { $exportOptions['filepath'] = wp_all_export_get_relative_path(PMXE_Plugin::$session->file); if (!$export->isEmpty()) { $export->set(array('options' => $exportOptions))->save(); } } PMXE_Wpallimport::generateImportTemplate($export, PMXE_Plugin::$session->file, PMXE_Plugin::$session->count); } $export->set(array('executing' => 0, 'canceled' => 0, 'iteration' => ++$export->iteration))->save(); do_action('pmxe_after_export', $export->id, $export); $queue_exports = empty($export->parent_id) ? array() : get_option('wp_all_export_queue_' . $export->parent_id); if (!empty($queue_exports) and !empty($export->parent_id)) { array_shift($queue_exports); } if (empty($queue_exports)) { delete_option('wp_all_export_queue_' . (empty($export->parent_id) ? $export->id : $export->parent_id)); } else { update_option('wp_all_export_queue_' . (empty($export->parent_id) ? $export->id : $export->parent_id), $queue_exports); } wp_send_json(array('export_id' => $export->id, 'queue_export' => empty($queue_exports) ? false : $queue_exports[0], 'exported' => $export->exported, 'percentage' => 100, 'done' => true, 'records_per_request' => $exportOptions['records_per_iteration'])); } }
function pmxe_wp_ajax_export_filtering_count() { if (!check_ajax_referer('wp_all_export_secure', 'security', false)) { exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin')))); } if (!current_user_can(PMXE_Plugin::$capabilities)) { exit(json_encode(array('html' => __('Security check', 'wp_all_export_plugin')))); } ob_start(); $input = new PMXE_Input(); $post = $input->post('data', array()); $filter_args = array('filter_rules_hierarhy' => empty($post['filter_rules_hierarhy']) ? array() : $post['filter_rules_hierarhy'], 'product_matching_mode' => empty($post['product_matching_mode']) ? 'strict' : $post['product_matching_mode']); $input = new PMXE_Input(); $export_id = $input->get('id', 0); if (empty($export_id)) { $export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0; } $export = new PMXE_Export_Record(); $export->getById($export_id); if (!$export->isEmpty()) { XmlExportEngine::$exportOptions = $export->options + PMXE_Plugin::get_default_import_options(); XmlExportEngine::$exportOptions['export_only_new_stuff'] = $post['export_only_new_stuff']; } XmlExportEngine::$is_user_export = ('users' == $post['cpt'] or 'shop_customer' == $post['cpt']) ? true : false; XmlExportEngine::$is_comment_export = 'comments' == $post['cpt'] ? true : false; XmlExportEngine::$post_types = array($post['cpt']); $filters = new XmlExportFiltering($filter_args); $filters->parseQuery(); PMXE_Plugin::$session->set('whereclause', $filters->get('queryWhere')); PMXE_Plugin::$session->set('joinclause', $filters->get('queryJoin')); PMXE_Plugin::$session->save_data(); $found_records = 0; $total_records = 0; $cpt = array($post['cpt']); $is_products_export = ($post['cpt'] == 'product' and class_exists('WooCommerce')); if ($post['export_type'] == 'advanced') { if (XmlExportEngine::$is_user_export) { // get total users $totalQuery = eval('return new WP_User_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'number\' => 10 ));'); if (!empty($totalQuery->results)) { $found_records = $total_records = $totalQuery->get_total(); } } elseif (XmlExportEngine::$is_comment_export) { // get total comments $totalQuery = eval('return new WP_Comment_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'number\' => 10, \'count\' => true ));'); $found_records = $total_records = $totalQuery->get_comments(); } else { remove_all_actions('parse_query'); remove_all_actions('pre_get_posts'); ob_start(); // get custom post type records depends on filters add_filter('posts_where', 'wp_all_export_posts_where', 10, 1); add_filter('posts_join', 'wp_all_export_posts_join', 10, 1); // get total custom post type records $totalQuery = eval('return new WP_Query(array(' . PMXE_Plugin::$session->get('wp_query') . ', \'offset\' => 0, \'posts_per_page\' => 10 ));'); if (!empty($totalQuery->found_posts)) { $found_records = $total_records = $totalQuery->found_posts; } wp_reset_postdata(); remove_filter('posts_join', 'wp_all_export_posts_join'); remove_filter('posts_where', 'wp_all_export_posts_where'); ob_get_clean(); } } else { if ('users' == $post['cpt'] or 'shop_customer' == $post['cpt']) { // get total users $totalQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10)); if (!empty($totalQuery->results)) { $found_records = $total_records = $totalQuery->get_total(); } } elseif ('comments' == $post['cpt']) { // get total comments global $wp_version; if (version_compare($wp_version, '4.2.0', '>=')) { $totalQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true)); $found_records = $total_records = $totalQuery->get_comments(); } else { $found_records = $total_records = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10, 'count' => true)); } } else { remove_all_actions('parse_query'); remove_all_actions('pre_get_posts'); $cpt = $is_products_export ? array('product', 'product_variation') : array($post['cpt']); ob_start(); // get custom post type records depends on filters add_filter('posts_where', 'wp_all_export_posts_where', 10, 1); add_filter('posts_join', 'wp_all_export_posts_join', 10, 1); // get total custom post type records $totalQuery = new WP_Query(array('post_type' => $cpt, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10)); if (!empty($totalQuery->found_posts)) { $found_records = $total_records = $totalQuery->found_posts; } wp_reset_postdata(); remove_filter('posts_join', 'wp_all_export_posts_join'); remove_filter('posts_where', 'wp_all_export_posts_where'); ob_end_clean(); } } if ($post['is_confirm_screen']) { ?> <?php if ($found_records > 0) { ?> <h3><?php _e('Your export is ready to run.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__('WP All Export will export %d %s.', 'wp_all_export_plugin'), $found_records, wp_all_export_get_cpt_name($cpt, $found_records)); ?> </h4> <?php } else { ?> <?php if (!$export->isEmpty() and $export->options['export_only_new_stuff']) { ?> <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } elseif ($total_records > 0) { ?> <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } else { ?> <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } ?> <?php } ?> <?php } elseif ($post['is_template_screen']) { ?> <?php if ($found_records > 0) { ?> <h3><span class="matches_count"><?php echo $found_records; ?> </span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $found_records); ?> </strong> will be exported</h3> <h4><?php _e("Choose data to include in the export file.", "wp_all_export_plugin"); ?> </h4> <?php } else { ?> <?php if (!$export->isEmpty() and $export->options['export_only_new_stuff']) { ?> <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__("All %s have already been exported.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } elseif ($total_records > 0) { ?> <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } else { ?> <h3><?php _e('Nothing to export.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } ?> <?php } ?> <?php } else { ?> <div class="founded_records"> <?php if ($found_records > 0) { ?> <?php if (XmlExportEngine::$is_user_export || XmlExportEngine::$is_comment_export) { ?> <h3><span class="matches_count"><?php echo $found_records; ?> </span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $found_records); ?> </strong> can be exported</h3> <h4><?php printf(__('Upgrade to the professional edition of WP All Export to export %s.', 'wp_all_export_plugin'), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } else { ?> <h3><span class="matches_count"><?php echo $found_records; ?> </span> <strong><?php echo wp_all_export_get_cpt_name($cpt, $found_records); ?> </strong> will be exported</h3> <h4><?php _e("Continue to configure and run your export.", "wp_all_export_plugin"); ?> </h4> <?php } ?> <?php } elseif ($total_records > 0) { ?> <h4 style="line-height:60px;"><?php printf(__("No matching %s found for selected filter rules.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } else { ?> <h4 style="line-height:60px;"><?php printf(__("There aren't any %s to export.", "wp_all_export_plugin"), wp_all_export_get_cpt_name($cpt)); ?> </h4> <?php } ?> </div> <?php } exit(json_encode(array('html' => ob_get_clean(), 'found_records' => $found_records))); die; }
/** * AJAX action export processing */ function pmxe_wp_ajax_wpallexport() { if (!check_ajax_referer('wp_all_export_secure', 'security', false)) { exit(__('Security check', 'wp_all_export_plugin')); } if (!current_user_can('manage_options')) { exit(__('Security check', 'wp_all_export_plugin')); } $input = new PMXE_Input(); $export_id = $input->get('id', 0); if (empty($export_id)) { $export_id = !empty(PMXE_Plugin::$session->update_previous) ? PMXE_Plugin::$session->update_previous : 0; } $wp_uploads = wp_upload_dir(); $export = new PMXE_Export_Record(); $export->getById($export_id); if ($export->isEmpty()) { exit(__('Export is not defined.', 'wp_all_export_plugin')); } $exportOptions = $export->options + PMXE_Plugin::get_default_import_options(); wp_reset_postdata(); XmlExportEngine::$exportOptions = $exportOptions; XmlExportEngine::$is_user_export = $exportOptions['is_user_export']; XmlExportEngine::$exportID = $export_id; $posts_per_page = $exportOptions['records_per_iteration']; if ('advanced' == $exportOptions['export_type']) { if (XmlExportEngine::$is_user_export) { exit(json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin')))); } else { $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => ' . $export->exported . ', \'posts_per_page\' => ' . $posts_per_page . ' ));'); } } else { XmlExportEngine::$post_types = $exportOptions['cpt']; if (!in_array('users', $exportOptions['cpt'])) { $exportQuery = new WP_Query(array('post_type' => $exportOptions['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $export->exported, 'posts_per_page' => $posts_per_page)); } else { exit(json_encode(array('html' => __('Upgrade to the professional edition of WP All Export to export users.', 'wp_all_export_plugin')))); } } XmlExportEngine::$exportQuery = $exportQuery; $foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total(); $postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results()); if (!$export->exported) { $attachment_list = $export->options['attachment_list']; if (!empty($attachment_list)) { foreach ($attachment_list as $attachment) { if (!is_numeric($attachment)) { @unlink($attachment); } } } $exportOptions['attachment_list'] = array(); $export->set(array('options' => $exportOptions))->save(); $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); if ($is_secure_import and !empty($exportOptions['filepath'])) { // if 'Create a new file each time export is run' disabled remove all previously generated source files // if ( ! $exportOptions['creata_a_new_export_file'] or ! $export->iteration ){ // wp_all_export_remove_source(wp_all_export_get_absolute_path($exportOptions['filepath'])); // } $exportOptions['filepath'] = ''; } PMXE_Plugin::$session->set('count', $foundPosts); PMXE_Plugin::$session->save_data(); } // if posts still exists then export them if ($postCount) { switch ($exportOptions['export_to']) { case 'xml': pmxe_export_xml($exportQuery, $exportOptions); break; case 'csv': pmxe_export_csv($exportQuery, $exportOptions); break; default: # code... break; } wp_reset_postdata(); } if ($postCount) { $export->set(array('exported' => $export->exported + $postCount))->save(); } if ($posts_per_page != -1 and $postCount) { wp_send_json(array('exported' => $export->exported, 'percentage' => ceil($export->exported / $foundPosts * 100), 'done' => false, 'records_per_request' => $exportOptions['records_per_iteration'])); } else { wp_reset_postdata(); if (file_exists(PMXE_Plugin::$session->file)) { if ($exportOptions['export_to'] == 'xml') { file_put_contents(PMXE_Plugin::$session->file, '</' . $exportOptions['main_xml_tag'] . '>', FILE_APPEND); } $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); if (!$is_secure_import) { if (!$export->isEmpty()) { $wp_filetype = wp_check_filetype(basename(PMXE_Plugin::$session->file), null); $attachment_data = array('guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path(PMXE_Plugin::$session->file), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename(PMXE_Plugin::$session->file)), 'post_content' => '', 'post_status' => 'inherit'); if (empty($export->attch_id)) { $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file); } elseif ($export->options['creata_a_new_export_file']) { $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file); } else { $attach_id = $export->attch_id; $attachment = get_post($attach_id); if ($attachment) { update_attached_file($attach_id, PMXE_Plugin::$session->file); wp_update_attachment_metadata($attach_id, $attachment_data); } else { $attach_id = wp_insert_attachment($attachment_data, PMXE_Plugin::$session->file); } } if (!in_array($attach_id, $exportOptions['attachment_list'])) { $exportOptions['attachment_list'][] = $attach_id; } $export->set(array('attch_id' => $attach_id, 'options' => $exportOptions))->save(); } } else { $exportOptions['filepath'] = wp_all_export_get_relative_path(PMXE_Plugin::$session->file); if (!$export->isEmpty()) { $export->set(array('options' => $exportOptions))->save(); } } // Generate templa for WP All Import if ($exportOptions['is_generate_templates']) { $custom_type = empty($exportOptions['cpt']) ? 'post' : $exportOptions['cpt'][0]; $templateOptions = array('type' => (!empty($exportOptions['cpt']) and $exportOptions['cpt'][0] == 'page') ? 'page' : 'post', 'wizard_type' => 'new', 'deligate' => 'wpallexport', 'custom_type' => XmlExportEngine::$is_user_export ? 'import_users' : $custom_type, 'status' => 'xpath', 'is_multiple_page_parent' => 'no', 'unique_key' => '', 'acf' => array(), 'fields' => array(), 'is_multiple_field_value' => array(), 'multiple_value' => array(), 'fields_delimiter' => array(), 'update_all_data' => 'no', 'is_update_status' => 0, 'is_update_title' => 0, 'is_update_author' => 0, 'is_update_slug' => 0, 'is_update_content' => 0, 'is_update_excerpt' => 0, 'is_update_dates' => 0, 'is_update_menu_order' => 0, 'is_update_parent' => 0, 'is_update_attachments' => 0, 'is_update_acf' => 0, 'update_acf_logic' => 'only', 'acf_list' => '', 'is_update_product_type' => 1, 'is_update_attributes' => 0, 'update_attributes_logic' => 'only', 'attributes_list' => '', 'is_update_images' => 0, 'is_update_custom_fields' => 0, 'update_custom_fields_logic' => 'only', 'custom_fields_list' => '', 'is_update_categories' => 0, 'update_categories_logic' => 'only', 'taxonomies_list' => '', 'export_id' => $export->id); if (in_array('product', $exportOptions['cpt'])) { $templateOptions['_virtual'] = 1; $templateOptions['_downloadable'] = 1; $templateOptions['put_variation_image_to_gallery'] = 1; $templateOptions['disable_auto_sku_generation'] = 1; } if (XmlExportEngine::$is_user_export) { $templateOptions['is_update_first_name'] = 0; $templateOptions['is_update_last_name'] = 0; $templateOptions['is_update_role'] = 0; $templateOptions['is_update_nickname'] = 0; $templateOptions['is_update_description'] = 0; $templateOptions['is_update_login'] = 0; $templateOptions['is_update_password'] = 0; $templateOptions['is_update_nicename'] = 0; $templateOptions['is_update_email'] = 0; $templateOptions['is_update_registered'] = 0; $templateOptions['is_update_display_name'] = 0; $templateOptions['is_update_url'] = 0; } if ('xml' == $exportOptions['export_to']) { wp_all_export_prepare_template_xml($exportOptions, $templateOptions); } else { wp_all_export_prepare_template_csv($exportOptions, $templateOptions); } //$template = new PMXI_Template_Record(); $tpl_options = $templateOptions; if ('csv' == $exportOptions['export_to']) { $tpl_options['delimiter'] = $exportOptions['delimiter']; } $tpl_options['update_all_data'] = 'yes'; $tpl_options['is_update_status'] = 1; $tpl_options['is_update_title'] = 1; $tpl_options['is_update_author'] = 1; $tpl_options['is_update_slug'] = 1; $tpl_options['is_update_content'] = 1; $tpl_options['is_update_excerpt'] = 1; $tpl_options['is_update_dates'] = 1; $tpl_options['is_update_menu_order'] = 1; $tpl_options['is_update_parent'] = 1; $tpl_options['is_update_attachments'] = 1; $tpl_options['is_update_acf'] = 1; $tpl_options['update_acf_logic'] = 'full_update'; $tpl_options['acf_list'] = ''; $tpl_options['is_update_product_type'] = 1; $tpl_options['is_update_attributes'] = 1; $tpl_options['update_attributes_logic'] = 'full_update'; $tpl_options['attributes_list'] = ''; $tpl_options['is_update_images'] = 1; $tpl_options['is_update_custom_fields'] = 1; $tpl_options['update_custom_fields_logic'] = 'full_update'; $tpl_options['custom_fields_list'] = ''; $tpl_options['is_update_categories'] = 1; $tpl_options['update_categories_logic'] = 'full_update'; $tpl_options['taxonomies_list'] = ''; $tpl_data = array('name' => $exportOptions['template_name'], 'is_keep_linebreaks' => 0, 'is_leave_html' => 0, 'fix_characters' => 0, 'options' => $tpl_options); $exportOptions['tpl_data'] = $tpl_data; $export->set(array('options' => $exportOptions))->save(); // if ( ! empty($exportOptions['template_name'])) { // save template in database // $template->getByName($exportOptions['template_name'])->set($tpl_data)->save(); // } } // associate exported posts with new import if (wp_all_export_is_compatible() and $exportOptions['is_generate_import']) { $options = $templateOptions + PMXI_Plugin::get_default_import_options(); $import = new PMXI_Import_Record(); $import->getById($exportOptions['import_id']); if (!$import->isEmpty() and $import->parent_import_id == 99999) { $xmlPath = PMXE_Plugin::$session->file; $root_element = ''; $historyPath = PMXE_Plugin::$session->file; if ('csv' == $exportOptions['export_to']) { $options['delimiter'] = $exportOptions['delimiter']; include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $path_info = pathinfo($xmlPath); $path_parts = explode(DIRECTORY_SEPARATOR, $path_info['dirname']); $security_folder = array_pop($path_parts); $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . $security_folder : $wp_uploads['path']; $csv = new PMXI_CsvParser(array('filename' => $xmlPath, 'targetDir' => $target)); if (!in_array($xmlPath, $exportOptions['attachment_list'])) { $exportOptions['attachment_list'][] = $csv->xml_path; } $historyPath = $csv->xml_path; $root_element = 'node'; } else { $root_element = 'post'; } $import->set(array('xpath' => '/' . $root_element, 'type' => 'upload', 'options' => $options, 'root_element' => $root_element, 'path' => $xmlPath, 'name' => basename($xmlPath), 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1, 'count' => PMXE_Plugin::$session->count))->save(); $history_file = new PMXI_File_Record(); $history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => $historyPath, 'registered_on' => date('Y-m-d H:i:s')))->save(); $exportOptions['import_id'] = $import->id; $export->set(array('options' => $exportOptions))->save(); } } } $export->set(array('executing' => 0, 'canceled' => 0))->save(); do_action('pmxe_after_export', $export->id); wp_send_json(array('exported' => $export->exported, 'percentage' => 100, 'done' => true, 'records_per_request' => $exportOptions['records_per_iteration'], 'file' => PMXE_Plugin::$session->file)); } }
function pmxe_pmxe_after_export($export_id, $export) { if (!empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session()) { PMXE_Plugin::$session->set('file', ''); PMXE_Plugin::$session->save_data(); } if (!$export->isEmpty()) { $splitSize = $export->options['split_large_exports_count']; $exportOptions = $export->options; // remove previously genereted chunks if (!empty($exportOptions['split_files_list']) and !$export->options['creata_a_new_export_file']) { foreach ($exportOptions['split_files_list'] as $file) { @unlink($file); } } $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); if (!$is_secure_import) { $filepath = get_attached_file($export->attch_id); } else { $filepath = wp_all_export_get_absolute_path($export->options['filepath']); } $is_export_csv_headers = apply_filters('wp_all_export_is_csv_headers_enabled', true, $export->id); // Remove headers row from CSV file if (!$is_export_csv_headers && @file_exists($filepath) && $export->options['export_to'] == 'csv') { $tmp_file = str_replace(basename($filepath), 'iteration_' . basename($filepath), $filepath); copy($filepath, $tmp_file); $in = fopen($tmp_file, 'r'); $out = fopen($filepath, 'w'); $headers = fgetcsv($in); if (is_resource($in)) { $lineNumber = 0; while (!feof($in)) { $data = fgetcsv($in, 0, XmlExportEngine::$exportOptions['delimiter']); if (empty($data)) { continue; } $data_assoc = array_combine($headers, array_values($data)); $line = array(); foreach ($headers as $header) { $line[$header] = isset($data_assoc[$header]) ? $data_assoc[$header] : ''; } if (!$lineNumber && XmlExportEngine::$exportOptions['include_bom']) { fwrite($out, chr(0xef) . chr(0xbb) . chr(0xbf)); fputcsv($out, $line, XmlExportEngine::$exportOptions['delimiter']); } else { fputcsv($out, $line, XmlExportEngine::$exportOptions['delimiter']); } apply_filters('wp_all_export_after_csv_line', $out, XmlExportEngine::$exportID); $lineNumber++; } fclose($in); } fclose($out); @unlink($tmp_file); } // Split large exports into chunks if ($export->options['split_large_exports'] and $splitSize < $export->exported) { $exportOptions['split_files_list'] = array(); if (@file_exists($filepath)) { switch ($export->options['export_to']) { case 'xml': $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $export->options['main_xml_tag'], $export->id); $record_xml_tag = apply_filters('wp_all_export_record_xml_tag', $export->options['record_xml_tag'], $export->id); $records_count = 0; $chunk_records_count = 0; $fileCount = 1; $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<" . $main_xml_tag . ">"; $file = new PMXE_Chunk($filepath, array('element' => $record_xml_tag, 'encoding' => 'UTF-8')); // loop through the file until all lines are read while ($xml = $file->read()) { if (!empty($xml)) { $chunk = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . $xml; $dom = new DOMDocument('1.0', "UTF-8"); $old = libxml_use_internal_errors(true); $dom->loadXML($chunk); // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); $records_count++; $chunk_records_count++; $feed .= $xml; } if ($chunk_records_count == $splitSize or $records_count == $export->exported) { $feed .= "</" . $main_xml_tag . ">"; $outputFile = str_replace(basename($filepath), str_replace('.xml', '', basename($filepath)) . '-' . $fileCount++ . '.xml', $filepath); file_put_contents($outputFile, $feed); if (!in_array($outputFile, $exportOptions['split_files_list'])) { $exportOptions['split_files_list'][] = $outputFile; } $chunk_records_count = 0; $feed = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n" . "<" . $main_xml_tag . ">"; } } break; case 'csv': $in = fopen($filepath, 'r'); $rowCount = 0; $fileCount = 1; $headers = fgetcsv($in); while (!feof($in)) { $data = fgetcsv($in); if (empty($data)) { continue; } if ($rowCount % $splitSize == 0) { if ($rowCount > 0) { fclose($out); } $outputFile = str_replace(basename($filepath), str_replace('.csv', '', basename($filepath)) . '-' . $fileCount++ . '.csv', $filepath); if (!in_array($outputFile, $exportOptions['split_files_list'])) { $exportOptions['split_files_list'][] = $outputFile; } $out = fopen($outputFile, 'w'); } if ($data) { if ($rowCount % $splitSize == 0) { fputcsv($out, $headers); } fputcsv($out, $data); } $rowCount++; } fclose($in); fclose($out); break; default: break; } $export->set(array('options' => $exportOptions))->save(); } } // make a temporary copy of current file if (empty($export->parent_id) and @file_exists($filepath) and @copy($filepath, str_replace(basename($filepath), '', $filepath) . 'current-' . basename($filepath))) { $exportOptions = $export->options; $exportOptions['current_filepath'] = str_replace(basename($filepath), '', $filepath) . 'current-' . basename($filepath); $export->set(array('options' => $exportOptions))->save(); } // genereta export bundle $export->generate_bundle(); if (!empty($export->parent_id)) { $parent_export = new PMXE_Export_Record(); $parent_export->getById($export->parent_id); if (!$parent_export->isEmpty()) { $parent_export->generate_bundle(true); } } // clean session if (!empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session()) { PMXE_Plugin::$session->clean_session($export->id); } } }
public function download() { $nonce = !empty($_REQUEST['_wpnonce']) ? $_REQUEST['_wpnonce'] : ''; if (!wp_verify_nonce($nonce, '_wpnonce-download_feed')) { die(__('Security check', 'wp_all_export_plugin')); } else { $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); $id = $this->input->get('id'); $export = new PMXE_Export_Record(); $filepath = ''; if (!$export->getById($id)->isEmpty()) { if (!$is_secure_import) { $filepath = get_attached_file($export->attch_id); } else { $filepath = wp_all_export_get_absolute_path($export->options['filepath']); } if (@file_exists($filepath)) { switch ($export['options']['export_to']) { case 'xml': PMXE_download::xml($filepath); break; case 'csv': PMXE_download::csv($filepath); break; default: break; } } } } }