/** * AJAX action for preview export row */ function pmxe_wp_ajax_wpae_preview() { 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')))); } XmlExportEngine::$is_preview = true; $custom_xml_valid = true; ob_start(); $values = array(); parse_str($_POST['data'], $values); $export_id = isset($_GET['id']) ? stripcslashes($_GET['id']) : 0; $exportOptions = $values + (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options(); $exportOptions['custom_xml_template'] = isset($_POST['custom_xml']) ? stripcslashes($_POST['custom_xml']) : ''; $exportOptions['custom_xml_template'] = str_replace('<ID>', '<id>', $exportOptions['custom_xml_template']); $exportOptions['custom_xml_template'] = str_replace('</ID>', '</id>', $exportOptions['custom_xml_template']); if (!empty($exportOptions['custom_xml_template'])) { $custom_xml_template_line_count = substr_count($exportOptions['custom_xml_template'], "\n"); } $errors = new WP_Error(); $engine = new XmlExportEngine($exportOptions, $errors); XmlExportEngine::$exportOptions = $exportOptions; XmlExportEngine::$is_user_export = $exportOptions['is_user_export']; XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export']; XmlExportEngine::$exportID = $export_id; if (in_array(XmlExportEngine::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) { if (empty(XmlExportEngine::$exportOptions['custom_xml_template'])) { $errors->add('form-validation', __('XML template is empty.', 'wp_all_export_plugin')); } if (!empty(XmlExportEngine::$exportOptions['custom_xml_template'])) { $engine->init_additional_data(); $engine->init_available_data(); $result = $engine->parse_custom_xml_template(); $line_numbers = $result['line_numbers']; if (!$errors->get_error_codes()) { XmlExportEngine::$exportOptions = array_merge(XmlExportEngine::$exportOptions, $result); } $originalXmlTemplate = $exportOptions['custom_xml_template']; libxml_use_internal_errors(true); libxml_clear_errors(); //Add root se we make sure there is a root tag $result['original_post_loop'] = '<root>' . $result['original_post_loop'] . '</root>'; $custom_xml_template = simplexml_load_string($result['original_post_loop']); if ($custom_xml_template === false) { $custom_xml_template_errors = libxml_get_errors(); libxml_clear_errors(); $custom_xml_valid = false; // Remove one line because we added root $line_difference = $custom_xml_template_line_count - $line_numbers - 1; } $exportOptions['custom_xml_template'] = str_replace("<!-- BEGIN POST LOOP -->", "<!-- BEGIN LOOP -->", $exportOptions['custom_xml_template']); $exportOptions['custom_xml_template'] = str_replace("<!-- END POST LOOP -->", "<!-- END LOOP -->", $exportOptions['custom_xml_template']); } } if (isset($_GET['show_cdata'])) { XmlExportEngine::$exportOptions['show_cdata_in_preview'] = (bool) $_GET['show_cdata']; } else { XmlExportEngine::$exportOptions['show_cdata_in_preview'] = false; } if ($errors->get_error_codes()) { $msgs = $errors->get_error_messages(); if (!is_array($msgs)) { $msgs = array($msgs); } foreach ($msgs as $msg) { ?> <div class="error"><p><?php echo $msg; ?> </p></div> <?php } exit(json_encode(array('html' => ob_get_clean()))); } if ('advanced' == $exportOptions['export_type']) { if (XmlExportEngine::$is_user_export) { $exportQuery = eval('return new WP_User_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));'); } elseif (XmlExportEngine::$is_comment_export) { $exportQuery = eval('return new WP_Comment_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));'); } else { $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'posts_per_page\' => 10));'); } } else { XmlExportEngine::$post_types = $exportOptions['cpt']; if (in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['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)); remove_action('pre_user_query', 'wp_all_export_pre_user_query'); } elseif (in_array('comments', $exportOptions['cpt'])) { add_action('comments_clauses', 'wp_all_export_comments_clauses', 10, 1); global $wp_version; if (version_compare($wp_version, '4.2.0', '>=')) { $exportQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10)); } else { $exportQuery = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10)); } remove_action('comments_clauses', 'wp_all_export_comments_clauses'); } 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' => 'title', 'order' => 'ASC', 'posts_per_page' => 10)); 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(); ?> <div id="post-preview" class="wpallexport-preview"> <p class="wpallexport-preview-title"><?php echo sprintf("Preview first 10 %s", wp_all_export_get_cpt_name($exportOptions['cpt'], 10)); ?> </p> <div class="wpallexport-preview-content"> <?php if (!$custom_xml_valid) { $error_msg = '<strong class="error">' . __('Invalid XML', 'wp_all_import_plugin') . '</strong><ul class="error">'; foreach ($custom_xml_template_errors as $error) { $error_msg .= '<li>'; $error_msg .= __('Line', 'wp_all_import_plugin') . ' ' . ($error->line + $line_difference) . ', '; $error_msg .= __('Column', 'wp_all_import_plugin') . ' ' . $error->column . ', '; $error_msg .= __('Code', 'wp_all_import_plugin') . ' ' . $error->code . ': '; $error_msg .= '<em>' . trim(esc_html($error->message)) . '</em>'; $error_msg .= '</li>'; } $error_msg .= '</ul>'; echo $error_msg; exit(json_encode(array('html' => ob_get_clean()))); } $wp_uploads = wp_upload_dir(); $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php'; if (@file_exists($functions)) { require_once $functions; } switch ($exportOptions['export_to']) { case 'xml': $dom = new DOMDocument('1.0', $exportOptions['encoding']); libxml_use_internal_errors(true); try { $xml = XmlCsvExport::export_xml(true); } catch (WpaeMethodNotFoundException $e) { // Find the line where the function is $errorMessage = ''; $functionName = $e->getMessage(); $txtParts = explode("\n", $originalXmlTemplate); for ($i = 0, $length = count($txtParts); $i < $length; $i++) { $tmp = strstr($txtParts[$i], $functionName); if ($tmp) { $errorMessage .= 'Error parsing XML feed: Call to undefined function <em>"' . $functionName . '"</em> on Line ' . ($i + 1); } } $error_msg = '<span class="error">' . __($errorMessage, 'wp_all_import_plugin') . '</span>'; echo $error_msg; exit(json_encode(array('html' => ob_get_clean()))); } catch (WpaeInvalidStringException $e) { // Find the line where the function is $errorMessage = ''; $functionName = $e->getMessage(); $txtParts = explode("\n", $originalXmlTemplate); for ($i = 0, $length = count($txtParts); $i < $length; $i++) { $tmp = strstr($txtParts[$i], $functionName); if ($tmp) { $errorMessage .= 'Error parsing XML feed: Unterminated string on line ' . ($i + 1); } } $error_msg = '<span class="error">' . __($errorMessage, 'wp_all_import_plugin') . '</span>'; echo $error_msg; exit(json_encode(array('html' => ob_get_clean()))); } catch (WpaeTooMuchRecursionException $e) { $errorMessage = __('There was a problem parsing the custom XML template'); $error_msg = '<span class="error">' . __($errorMessage, 'wp_all_import_plugin') . '</span>'; echo $error_msg; exit(json_encode(array('html' => ob_get_clean()))); } $xml_errors = false; $main_xml_tag = ''; switch (XmlExportEngine::$exportOptions['xml_template_type']) { case 'custom': case 'XmlGoogleMerchants': require_once PMXE_ROOT_DIR . '/classes/XMLWriter.php'; $preview_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" . "\n<Preview>\n" . $xml . "\n</Preview>"; $preview_xml = str_replace('<![CDATA[', 'CDATABEGIN', $preview_xml); $preview_xml = str_replace(']]>', 'CDATACLOSE', $preview_xml); $preview_xml = str_replace('&', '&', $preview_xml); $preview_xml = str_replace('&', '&', $preview_xml); $xml = PMXE_XMLWriter::preprocess_xml(XmlExportEngine::$exportOptions['custom_xml_template_header']) . "\n" . $xml . "\n" . PMXE_XMLWriter::preprocess_xml(XmlExportEngine::$exportOptions['custom_xml_template_footer']); $xml = str_replace('<![CDATA[', 'CDATABEGIN', $xml); $xml = str_replace(']]>', 'CDATACLOSE', $xml); $xml = str_replace('&', '&', $xml); $xml = str_replace('&', '&', $xml); // Determine XML root element preg_match_all("%<[\\w]+[\\s|>]{1}%", XmlExportEngine::$exportOptions['custom_xml_template_header'], $matches); if (!empty($matches[0])) { $main_xml_tag = preg_replace("%[\\s|<|>]%", "", array_shift($matches[0])); } libxml_clear_errors(); $dom->loadXML($xml); $xml_errors = libxml_get_errors(); libxml_clear_errors(); if (!$xml_errors) { $xpath = new DOMXPath($dom); if ($elements = @$xpath->query('/' . $main_xml_tag) and $elements->length) { pmxe_render_xml_element($elements->item(0), true); } else { $xml_errors = true; } } break; default: libxml_clear_errors(); $dom->loadXML($xml); $xml_errors = libxml_get_errors(); libxml_clear_errors(); $xpath = new DOMXPath($dom); // Determine XML root element $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], XmlExportEngine::$exportID); $elements = @$xpath->query('/' . $main_xml_tag); if ($elements->length) { pmxe_render_xml_element($elements->item(0), true); $xml_errors = false; } else { $error_msg = '<strong>' . __('Can\'t preview the document.', 'wp_all_import_plugin') . '</strong><ul>'; $error_msg .= '<li>'; $error_msg .= __('You can continue export or try to use <data> tag as root element.', 'wp_all_import_plugin'); $error_msg .= '</li>'; $error_msg .= '</ul>'; echo $error_msg; exit(json_encode(array('html' => ob_get_clean()))); } break; } if ($xml_errors) { $preview_dom = new DOMDocument('1.0', $exportOptions['encoding']); libxml_clear_errors(); $preview_dom->loadXML($preview_xml); $preview_xml_errors = libxml_get_errors(); libxml_clear_errors(); if ($preview_xml_errors) { $error_msg = '<strong class="error">' . __('Invalid XML', 'wp_all_import_plugin') . '</strong><ul class="error">'; foreach ($preview_xml_errors as $error) { $error_msg .= '<li>'; $error_msg .= __('Line', 'wp_all_import_plugin') . ' ' . $error->line . ', '; $error_msg .= __('Column', 'wp_all_import_plugin') . ' ' . $error->column . ', '; $error_msg .= __('Code', 'wp_all_import_plugin') . ' ' . $error->code . ': '; $error_msg .= '<em>' . trim(esc_html($error->message)) . '</em>'; $error_msg .= '</li>'; } $error_msg .= '</ul>'; echo $error_msg; exit(json_encode(array('html' => ob_get_clean()))); } else { $xpath = new DOMXPath($preview_dom); if ($elements = @$xpath->query('/Preview') and $elements->length) { pmxe_render_xml_element($elements->item(0), true); } else { $error_msg = '<strong>' . __('Can\'t preview the document. Root element is not detected.', 'wp_all_import_plugin') . '</strong><ul>'; $error_msg .= '<li>'; $error_msg .= __('You can continue export or try to use <data> tag as root element.', 'wp_all_import_plugin'); $error_msg .= '</li>'; $error_msg .= '</ul>'; echo $error_msg; exit(json_encode(array('html' => ob_get_clean()))); } } } break; case 'csv': ?> <small> <?php $csv = XmlCsvExport::export_csv(true); if (!empty($csv)) { $csv_rows = array_filter(explode("\n", $csv)); if ($csv_rows) { ?> <table class="pmxe_preview" cellpadding="0" cellspacing="0"> <?php foreach ($csv_rows as $rkey => $row) { $cells = str_getcsv($row, $exportOptions['delimiter']); if ($cells) { ?> <tr> <?php foreach ($cells as $key => $value) { ?> <td> <?php if (!$rkey) { ?> <strong><?php } ?> <?php echo $value; ?> <?php if (!$rkey) { ?> </strong><?php } ?> </td> <?php } ?> </tr> <?php } } ?> </table> <?php } } else { _e('Data not found.', 'wp_all_export_plugin'); } ?> </small> <?php break; default: _e('This format is not supported.', 'wp_all_export_plugin'); break; } wp_reset_postdata(); ?> </div> </div> <?php exit(json_encode(array('html' => ob_get_clean()))); die; }
protected function init() { PMXE_Plugin::$session->set('is_user_export', self::$is_user_export); if ('advanced' == $this->post['export_type']) { if ("" == $this->post['wp_query']) { $this->errors->add('form-validation', __('WP Query field is required', 'pmxe_plugin')); } else { if (self::$is_user_export) { $this->errors->add('form-validation', __('Upgrade to the professional edition of WP All Export to export users.', 'pmxe_plugin')); } else { self::$exportQuery = eval('return new WP_Query(array(' . $this->post['wp_query'] . ', \'offset\' => 0, \'posts_per_page\' => 10));'); if (empty(self::$exportQuery)) { $this->errors->add('form-validation', __('Invalid query', 'pmxe_plugin')); } elseif (empty(self::$exportQuery->found_posts)) { $this->errors->add('count-validation', __('No matching posts found for WP_Query expression specified.', 'pmxe_plugin')); PMXE_Plugin::$session->set('found_posts', 0); } else { PMXE_Plugin::$session->set('wp_query', $this->post['wp_query']); PMXE_Plugin::$session->set('found_posts', self::$exportQuery->found_posts); } } } } else { if (self::$is_user_export) { $this->errors->add('form-validation', __('Upgrade to the professional edition of WP All Export to export users.', 'pmxe_plugin')); } else { self::$exportQuery = new WP_Query(array('post_type' => self::$post_types, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10)); PMXE_Plugin::$session->set('cpt', self::$post_types); if (empty(self::$exportQuery->found_posts)) { $this->errors->add('count-validation', __('No matching posts found for selected post types.', 'pmxe_plugin')); PMXE_Plugin::$session->set('found_posts', 0); } else { PMXE_Plugin::$session->set('found_posts', self::$exportQuery->found_posts); } } } PMXE_Plugin::$session->save_data(); }
protected function init() { PMXE_Plugin::$session->set('is_user_export', self::$is_user_export); if ('advanced' == $this->post['export_type']) { if ("" == $this->post['wp_query']) { $this->errors->add('form-validation', __('WP Query field is required', 'pmxe_plugin')); } else { if (self::$is_user_export) { self::$exportQuery = eval('return new WP_User_Query(array(' . $this->post['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => 0, \'number\' => 10));'); if (empty(self::$exportQuery->results)) { $this->errors->add('form-validation', __('No matching users found', 'pmxe_plugin')); } else { PMXE_Plugin::$session->set('wp_query', $this->post['wp_query']); PMXE_Plugin::$session->set('found_posts', self::$exportQuery->get_total()); } } else { self::$exportQuery = eval('return new WP_Query(array(' . $this->post['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => 0, \'posts_per_page\' => 10));'); if (empty(self::$exportQuery)) { $this->errors->add('form-validation', __('Invalid query', 'pmxe_plugin')); } elseif (empty(self::$exportQuery->found_posts)) { $this->errors->add('form-validation', __('No matching posts found for WP_Query expression specified', 'pmxe_plugin')); } else { PMXE_Plugin::$session->set('wp_query', $this->post['wp_query']); PMXE_Plugin::$session->set('found_posts', self::$exportQuery->found_posts); } } } } else { $this->filters->parseQuery(); PMXE_Plugin::$session->set('whereclause', $this->filters->get('queryWhere')); PMXE_Plugin::$session->set('joinclause', $this->filters->get('queryJoin')); PMXE_Plugin::$session->save_data(); if (self::$is_user_export) { add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1); self::$exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10)); if (empty(self::$exportQuery->results)) { $this->errors->add('form-validation', __('No matching posts found for selected post types', 'pmxe_plugin')); } else { PMXE_Plugin::$session->set('cpt', self::$post_types); PMXE_Plugin::$session->set('found_posts', self::$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); self::$exportQuery = new WP_Query(array('post_type' => self::$post_types, 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'posts_per_page' => 10)); if (empty(self::$exportQuery->found_posts)) { $this->errors->add('form-validation', __('No matching posts found for selected post types', 'pmxe_plugin')); } else { PMXE_Plugin::$session->set('cpt', self::$post_types); PMXE_Plugin::$session->set('found_posts', self::$exportQuery->found_posts); } remove_filter('posts_join', 'wp_all_export_posts_join'); remove_filter('posts_where', 'wp_all_export_posts_where'); } } PMXE_Plugin::$session->save_data(); }
/** * Step #2: Template */ public function template() { $default = PMXE_Plugin::get_default_import_options(); if ($this->isWizard) { $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $default; $post = $this->input->post($DefaultOptions); } else { $DefaultOptions = $this->data['export']->options + $default; $post = $this->input->post($DefaultOptions); $post['scheduled'] = $this->data['export']->scheduled; foreach ($post as $key => $value) { PMXE_Plugin::$session->set($key, $value); } } PMXE_Plugin::$session->save_data(); $this->data['post'] =& $post; if ($this->input->post('is_submitted')) { check_admin_referer('template', '_wpnonce_template'); if (empty($post['cc_type'][0])) { $this->errors->add('form-validation', __('You haven\'t selected any columns for export.', 'pmxe_plugin')); } if ('csv' == $post['export_to'] and '' == $post['delimiter']) { $this->errors->add('form-validation', __('CSV delimiter must be specified', 'pmxe_plugin')); } if (!$this->errors->get_error_codes()) { if ($this->isWizard) { foreach ($this->data['post'] as $key => $value) { PMXE_Plugin::$session->set($key, $value); } PMXE_Plugin::$session->save_data(); wp_redirect(add_query_arg('action', 'options', $this->baseUrl)); die; } else { $this->data['export']->set(array('options' => $post, 'settings_update_on' => date('Y-m-d H:i:s')))->save(); if (!empty($post['friendly_name'])) { $this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => $post['is_scheduled'] ? $post['scheduled_period'] : ''))->save(); } wp_redirect(add_query_arg(array('page' => 'pmxe-admin-manage', 'pmxe_nt' => urlencode(__('Options updated', 'pmxi_plugin'))) + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php'))); die; } } } $engine = new XmlExportEngine($post, $this->errors); $engine->init_additional_data(); $this->data = array_merge($this->data, $engine->init_available_data()); $this->data['available_data_view'] = $engine->render(); $this->render(); }
function pmxe_wp_ajax_export_filtering() { 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')))); } $response = array('html' => '', 'btns' => ''); ob_start(); $errors = new WP_Error(); $input = new PMXE_Input(); $post = $input->post('data', array()); if (!empty($post['cpt'])) { $engine = new XmlExportEngine($post, $errors); $engine->init_available_data(); ?> <div class="wpallexport-content-section"> <div class="wpallexport-collapsed-header"> <h3><?php _e('Add Filtering Options', 'wp_all_export_plugin'); ?> </h3> </div> <div class="wpallexport-collapsed-content"> <?php include_once PMXE_ROOT_DIR . '/views/admin/export/blocks/filters.php'; ?> </div> </div> <?php } $response['html'] = ob_get_clean(); if (XmlExportEngine::$is_user_export || XmlExportEngine::$is_comment_export) { $response['btns'] = ''; exit(json_encode($response)); die; } ob_start(); if (XmlExportEngine::$is_auto_generate_enabled) { ?> <span class="wp_all_export_btn_with_note"> <a href="javascript:void(0);" class="back rad3 auto-generate-template" style="float:none; background: #425f9a; padding: 0 50px; margin-right: 10px; color: #fff; font-weight: normal;"><?php printf(__('Migrate %s', 'wp_all_export_plugin'), wp_all_export_get_cpt_name(array($post['cpt']), 2)); ?> </a> <span class="auto-generate-template"> </span> </span> <span class="wp_all_export_btn_with_note"> <input type="submit" class="button button-primary button-hero wpallexport-large-button" value="<?php _e('Customize Export File', 'wp_all_export_plugin'); ?> "/> <span class="auto-generate-template"> </span> </span> <?php } else { ?> <span class="wp_all_export_btn_with_note"> <input type="submit" class="button button-primary button-hero wpallexport-large-button" value="<?php _e('Customize Export File', 'wp_all_export_plugin'); ?> "/> </span> <?php } $response['btns'] = ob_get_clean(); exit(json_encode($response)); die; }
public static function auto_genetate_export_fields($post, $errors = false) { $errors or $errors = new WP_Error(); remove_all_filters("wp_all_export_init_fields", 10); remove_all_filters("wp_all_export_default_fields", 10); remove_all_filters("wp_all_export_other_fields", 10); remove_all_filters("wp_all_export_available_sections", 10); remove_all_filters("wp_all_export_available_data", 10); $engine = new XmlExportEngine($post, $errors); $engine->init_additional_data(); $auto_generate = array('ids' => array(), 'cc_label' => array(), 'cc_php' => array(), 'cc_code' => array(), 'cc_sql' => array(), 'cc_type' => array(), 'cc_options' => array(), 'cc_value' => array(), 'cc_name' => array()); $available_data = $engine->init_available_data(); $available_sections = apply_filters("wp_all_export_available_sections", $engine->get('available_sections')); foreach ($available_sections as $slug => $section) { if (!empty($section['content']) and !empty($available_data[$section['content']])) { foreach ($available_data[$section['content']] as $field) { if (is_array($field) and (isset($field['auto']) or !in_array('product', $post['cpt']))) { $auto_generate['ids'][] = 1; $auto_generate['cc_label'][] = is_array($field) ? $field['label'] : $field; $auto_generate['cc_php'][] = 0; $auto_generate['cc_code'][] = ''; $auto_generate['cc_sql'][] = ''; $auto_generate['cc_settings'][] = ''; $auto_generate['cc_type'][] = is_array($field) ? $field['type'] : $slug; $auto_generate['cc_options'][] = ''; $auto_generate['cc_value'][] = is_array($field) ? $field['label'] : $field; $auto_generate['cc_name'][] = is_array($field) ? $field['name'] : $field; } } } if (!empty($section['additional'])) { foreach ($section['additional'] as $sub_slug => $sub_section) { foreach ($sub_section['meta'] as $field) { $field_options = in_array($sub_slug, array('images', 'attachments')) ? esc_attr('{"is_export_featured":true,"is_export_attached":true,"image_separator":"|"}') : '0'; $field_name = ''; switch ($sub_slug) { case 'images': $field_name = 'Image ' . $field['name']; break; case 'attachments': $field_name = 'Attachment ' . $field['name']; break; default: $field_name = $field['name']; break; } if (is_array($field) and isset($field['auto'])) { $auto_generate['ids'][] = 1; $auto_generate['cc_label'][] = is_array($field) ? $field['label'] : $field; $auto_generate['cc_php'][] = 0; $auto_generate['cc_code'][] = ''; $auto_generate['cc_sql'][] = ''; $auto_generate['cc_settings'][] = ''; $auto_generate['cc_type'][] = is_array($field) ? $field['type'] : $sub_slug; $auto_generate['cc_options'][] = $field_options; $auto_generate['cc_value'][] = is_array($field) ? $field['label'] : $field; $auto_generate['cc_name'][] = $field_name; } } } } } if (XmlExportWooCommerceOrder::$is_active) { foreach (XmlExportWooCommerceOrder::$order_sections as $slug => $section) { if (!empty($section['meta'])) { foreach ($section['meta'] as $cur_meta_key => $field) { $auto_generate['ids'][] = 1; $auto_generate['cc_label'][] = is_array($field) ? $field['label'] : $cur_meta_key; $auto_generate['cc_php'][] = 0; $auto_generate['cc_code'][] = ''; $auto_generate['cc_sql'][] = ''; $auto_generate['cc_settings'][] = ''; $auto_generate['cc_type'][] = is_array($field) ? $field['type'] : 'woo_order'; $auto_generate['cc_options'][] = is_array($field) ? $field['options'] : $slug; $auto_generate['cc_value'][] = is_array($field) ? $field['label'] : $cur_meta_key; $auto_generate['cc_name'][] = is_array($field) ? $field['name'] : $field; } } } } return $auto_generate; }
function pmxe_wp_ajax_export_filtering() { 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(); $errors = new WP_Error(); $input = new PMXE_Input(); $post = $input->post('data', array()); if (!empty($post['cpt'])) { $engine = new XmlExportEngine($post, $errors); $engine->init_available_data(); ?> <div class="wpallexport-content-section"> <div class="wpallexport-collapsed-header"> <h3><?php _e('Add Filtering Options', 'wp_all_export_plugin'); ?> </h3> </div> <div class="wpallexport-collapsed-content"> <div class="wp_all_export_rule_inputs"> <table> <tr> <th><?php _e('Element', 'wp_all_export_plugin'); ?> </th> <th><?php _e('Rule', 'wp_all_export_plugin'); ?> </th> <th><?php _e('Value', 'wp_all_export_plugin'); ?> </th> <th> </th> </tr> <tr> <td style="width: 25%;"> <select id="wp_all_export_xml_element"> <option value=""><?php _e('Select Element', 'wp_all_export_plugin'); ?> </option> <?php echo $engine->render_filters(); ?> </select> </td> <td style="width: 25%;" id="wp_all_export_available_rules"> <select id="wp_all_export_rule"> <option value=""><?php _e('Select Rule', 'wp_all_export_plugin'); ?> </option> </select> </td> <td style="width: 25%;"> <input id="wp_all_export_value" type="text" placeholder="value" value=""/> </td> <td style="width: 15%;"> <a id="wp_all_export_add_rule" href="javascript:void(0);"><?php _e('Add Rule', 'wp_all_export_plugin'); ?> </a> </td> </tr> </table> </div> <div id="wpallexport-filters" style="padding:0;"> <div class="wpallexport-content-section" style="padding:0; border: none;"> <fieldset id="wp_all_export_filtering_rules"> <?php $filter_rules = PMXE_Plugin::$session->get('filter_rules_hierarhy'); $filter_rules_hierarhy = json_decode($filter_rules); ?> <p style="margin:20px 0 5px; text-align:center; <?php if (!empty($filter_rules_hierarhy)) { ?> display:none;<?php } ?> "><?php _e('No filtering options. Add filtering options to only export records matching some specified criteria.', 'wp_all_export_plugin'); ?> </p> <ol class="wp_all_export_filtering_rules"> <?php if (!empty($filter_rules_hierarhy) and is_array($filter_rules_hierarhy)) { $rulenumber = 0; foreach ($filter_rules_hierarhy as $rule) { if (is_null($rule->parent_id)) { $rulenumber++; ?> <li id="item_<?php echo $rulenumber; ?> " class="dragging"> <div class="drag-element"> <input type="hidden" value="<?php echo $rule->element; ?> " class="wp_all_export_xml_element" name="wp_all_export_xml_element[<?php echo $rulenumber; ?> ]"/> <input type="hidden" value="<?php echo $rule->title; ?> " class="wp_all_export_xml_element_title" name="wp_all_export_xml_element_title[<?php echo $rulenumber; ?> ]"/> <input type="hidden" value="<?php echo $rule->condition; ?> " class="wp_all_export_rule" name="wp_all_export_rule[<?php echo $rulenumber; ?> ]"/> <input type="hidden" value="<?php echo $rule->value; ?> " class="wp_all_export_value" name="wp_all_export_value[<?php echo $rulenumber; ?> ]"/> <span class="rule_element"><?php echo $rule->title; ?> </span> <span class="rule_as_is"><?php echo $rule->condition; ?> </span> <span class="rule_condition_value"><?php echo $rule->value; ?> </span> <span class="condition" <?php if ($rulenumber == count($filter_rules_hierarhy)) { ?> style="display:none;"<?php } ?> > <label for="rule_and_<?php echo $rulenumber; ?> ">AND</label> <input id="rule_and_<?php echo $rulenumber; ?> " type="radio" value="and" name="rule[<?php echo $rulenumber; ?> ]" <?php if ($rule->clause == 'AND') { ?> checked="checked"<?php } ?> class="rule_condition"/> <label for="rule_or_<?php echo $rulenumber; ?> ">OR</label> <input id="rule_or_<?php echo $rulenumber; ?> " type="radio" value="or" name="rule[<?php echo $rulenumber; ?> ]" <?php if ($rule->clause == 'OR') { ?> checked="checked"<?php } ?> class="rule_condition"/> </span> </div> <a href="javascript:void(0);" class="icon-item remove-ico"></a> <?php echo wp_all_export_reverse_rules_html($filter_rules_hierarhy, $rule, $rulenumber); ?> </li> <?php } } } ?> </ol> <div class="clear"></div> <div class="ajax-console" id="filtering_result"> </div> <!--a href="javascript:void(0);" id="wp_all_export_apply_filters" <?php if (empty($filter_rules_hierarhy)) { ?> style="display:none;"<?php } ?> ><?php _e('Apply Filters To Export Data', 'wp_all_export_plugin'); ?> </a--> <div class="wp_all_export_filter_preloader"></div> </fieldset> <?php if ("product" == $post["cpt"] and class_exists('WooCommerce')) { ?> <div class="input wp_all_export_product_matching_mode" <?php if (empty($filter_rules_hierarhy)) { ?> style="display:none;"<?php } ?> > <?php $product_matching_mode = PMXE_Plugin::$session->get('product_matching_mode'); ?> <label><?php _e("Variable product matching rules: ", "wp_all_export_plugin"); ?> </label> <select name="product_matching_mode"> <option value="strict" <?php echo $product_matching_mode == 'strict' ? 'selected="selected"' : ''; ?> ><?php _e("Strict", "wp_all_export_plugin"); ?> </option> <option value="permissive" <?php echo $product_matching_mode == 'permissive' ? 'selected="selected"' : ''; ?> ><?php _e("Permissive", "wp_all_export_plugin"); ?> </option> </select> <a href="#help" class="wpallexport-help" style="position: relative; top: 0px;" title="<?php _e('Strict matching requires all variations to pass in order for the product to be exported. Permissive matching allows the product to be exported if any of the variations pass.', 'wp_all_export_plugin'); ?> ">?</a> </div> <?php } ?> </div> </div> </div> </div> <?php } exit(json_encode(array('html' => ob_get_clean()))); die; }
public function __construct($post, &$errors = false) { $this->post = $post; $this->errors = $errors; $this->available_sections = array('default' => array('title' => __("Standard", "wp_all_export_plugin"), 'content' => 'default_fields'), 'media' => array('title' => __("Media", "wp_all_export_plugin"), 'content' => '', 'additional' => array('images' => array('title' => __("Images", "wp_all_export_plugin"), 'meta' => array(array('name' => 'URL', 'label' => 'url', 'type' => 'image_url', 'auto' => 1), array('name' => 'Filename', 'label' => 'filename', 'type' => 'image_filename'), array('name' => 'Path', 'label' => 'path', 'type' => 'image_path'), array('name' => 'ID', 'label' => 'image_id', 'type' => 'image_id'), array('name' => 'Title', 'label' => 'title', 'type' => 'image_title', 'auto' => 1), array('name' => 'Caption', 'label' => 'caption', 'type' => 'image_caption', 'auto' => 1), array('name' => 'Description', 'label' => 'description', 'type' => 'image_description', 'auto' => 1), array('name' => 'Alt Text', 'label' => 'alt', 'type' => 'image_alt', 'auto' => 1))), 'attachments' => array('title' => __("Attachments", "wp_all_export_plugin"), 'meta' => array(array('name' => 'URL', 'label' => 'url', 'type' => 'attachment_url', 'auto' => 1), array('name' => 'Filename', 'label' => 'filename', 'type' => 'attachment_filename'), array('name' => 'Path', 'label' => 'path', 'type' => 'attachment_path'), array('name' => 'ID', 'label' => 'attachment_id', 'type' => 'attachment_id'), array('name' => 'Title', 'label' => 'title', 'type' => 'attachment_title'), array('name' => 'Caption', 'label' => 'caption', 'type' => 'attachment_caption'), array('name' => 'Description', 'label' => 'description', 'type' => 'attachment_description'), array('name' => 'Alt Text', 'label' => 'alt', 'type' => 'attachment_alt'))))), 'cats' => array('title' => __("Taxonomies", "wp_all_export_plugin"), 'content' => 'existing_taxonomies'), 'cf' => array('title' => __("Custom Fields", "wp_all_export_plugin"), 'content' => 'existing_meta_keys'), 'other' => array('title' => __("Other", "wp_all_export_plugin"), 'content' => 'other_fields')); $this->filter_sections = array('author' => array('title' => __("Author", "wp_all_export_plugin"), 'fields' => array('user_ID' => 'User ID', 'user_login' => 'User Login', 'user_nicename' => 'Nicename', 'user_email' => 'Email', 'user_registered' => 'Date Registered (Y-m-d H:i:s)', 'display_name' => 'Display Name', 'cf_first_name' => 'First Name', 'cf_last_name' => 'Last Name', 'nickname' => 'Nickname', 'description' => 'User Description', 'wp_capabilities' => 'User Role'))); if ('specific' == $this->post['export_type']) { self::$post_types = !is_array($this->post['cpt']) ? array($this->post['cpt']) : $this->post['cpt']; if (in_array('product', self::$post_types) and !in_array('product_variation', self::$post_types)) { self::$post_types[] = 'product_variation'; } self::$is_user_export = (in_array('users', self::$post_types) or in_array('shop_customer', self::$post_types)) ? true : false; self::$is_comment_export = in_array('comments', self::$post_types) ? true : false; } else { self::$is_user_export = 'wp_user_query' == $this->post['wp_query_selector']; self::$is_comment_export = 'wp_comment_query' == $this->post['wp_query_selector']; } if (!self::$is_user_export && !self::$is_comment_export) { add_filter("wp_all_export_filters", array(&$this, "filter_export_filters"), 10, 1); // When WPML is active and at least one post in the export has a trid if (class_exists('SitePress')) { self::$default_fields[] = array('label' => 'wpml_trid', 'name' => 'WPML Translation ID', 'type' => 'wpml_trid'); self::$default_fields[] = array('label' => 'wpml_lang', 'name' => 'WPML Language Code', 'type' => 'wpml_lang'); } } self::$exportOptions = $post; if (!empty(PMXE_Plugin::$session) and PMXE_Plugin::$session->has_session()) { $filter_args = array('filter_rules_hierarhy' => $this->post['filter_rules_hierarhy'], 'product_matching_mode' => $this->post['product_matching_mode']); $this->filters = new XmlExportFiltering($filter_args); $this->init(); } self::$implode = self::$exportOptions['delimiter'] == ',' ? '|' : ','; self::$implode = apply_filters('wp_all_export_implode_delimiter', self::$implode, self::$exportID); if (!empty(self::$exportOptions['xml_template_type']) && in_array(self::$exportOptions['xml_template_type'], array('custom', 'XmlGoogleMerchants'))) { self::$implode = '#delimiter#'; } self::$acf_export = new XmlExportACF(); self::$woo_export = new XmlExportWooCommerce(); self::$user_export = new XmlExportUser(); self::$comment_export = new XmlExportComment(); self::$woo_order_export = new XmlExportWooCommerceOrder(); self::$woo_coupon_export = new XmlExportWooCommerceCoupon(); }
/** * 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_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; }
/** * Import all files matched by path * @param callback[optional] $logger Method where progress messages are submmitted * @return PMXI_Import_Record * @chainable */ public function execute($logger = NULL, $cron = false) { $this->set('registered_on', date('Y-m-d H:i:s'))->save(); // update registered_on to indicated that job has been exectured even if no files are going to be imported by the rest of the method $wp_uploads = wp_upload_dir(); $this->set(array('processing' => 1))->update(); // lock cron requests wp_reset_postdata(); XmlExportEngine::$exportOptions = $this->options; XmlExportEngine::$is_user_export = $this->options['is_user_export']; if ('advanced' == $this->options['export_type']) { if (XmlExportEngine::$is_user_export) { $exportQuery = eval('return new WP_User_Query(array(' . $this->options['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => ' . $this->exported . ', \'number\' => ' . $this->options['records_per_iteration'] . '));'); } else { $exportQuery = eval('return new WP_Query(array(' . $this->options['wp_query'] . ', \'orderby\' => \'ID\', \'order\' => \'ASC\', \'offset\' => ' . $this->exported . ', \'posts_per_page\' => ' . $this->options['records_per_iteration'] . '));'); } } else { XmlExportEngine::$post_types = $this->options['cpt']; if (!in_array('users', $this->options['cpt'])) { add_filter('posts_where', 'wp_all_export_posts_where', 10, 1); add_filter('posts_join', 'wp_all_export_posts_join', 10, 1); $exportQuery = new WP_Query(array('post_type' => $this->options['cpt'], 'post_status' => 'any', 'orderby' => 'ID', 'order' => 'ASC', 'offset' => $this->exported, 'posts_per_page' => $this->options['records_per_iteration'])); remove_filter('posts_join', 'wp_all_export_posts_join'); remove_filter('posts_where', 'wp_all_export_posts_where'); } else { add_action('pre_user_query', 'wp_all_export_pre_user_query', 10, 1); $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => $this->options['records_per_iteration'], 'offset' => $this->exported)); remove_action('pre_user_query', 'wp_all_export_pre_user_query'); } } XmlExportEngine::$exportQuery = $exportQuery; $file_path = false; $is_secure_import = PMXE_Plugin::getInstance()->getOption('secure'); if ($this->exported == 0) { $import = new PMXI_Import_Record(); $import->getById($this->options['import_id']); if ($import->isEmpty()) { $import->set(array('parent_import_id' => 99999, 'xpath' => '/', 'type' => 'upload', 'options' => array('empty'), 'root_element' => 'root', 'path' => 'path', 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1))->save(); $exportOptions = $this->options; $exportOptions['import_id'] = $import->id; $this->set(array('options' => $exportOptions))->save(); } else { if ($import->parent_import_id != 99999) { $newImport = new PMXI_Import_Record(); $newImport->set(array('parent_import_id' => 99999, 'xpath' => '/', 'type' => 'upload', 'options' => array('empty'), 'root_element' => 'root', 'path' => 'path', 'imported' => 0, 'created' => 0, 'updated' => 0, 'skipped' => 0, 'deleted' => 0, 'iteration' => 1))->save(); $exportOptions = $this->options; $exportOptions['import_id'] = $newImport->id; $this->set(array('options' => $exportOptions))->save(); } } if (!empty($this->attch_id)) { wp_delete_attachment($this->attch_id, true); } $target = $is_secure_import ? wp_all_export_secure_file($wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY) : $wp_uploads['path']; $file_path = $target . DIRECTORY_SEPARATOR . time() . '.' . $this->options['export_to']; if (!$is_secure_import) { $wp_filetype = wp_check_filetype(basename($file_path), null); $attachment_data = array('guid' => $wp_uploads['baseurl'] . '/' . _wp_relative_upload_path($file_path), 'post_mime_type' => $wp_filetype['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file_path)), 'post_content' => '', 'post_status' => 'inherit'); $attach_id = wp_insert_attachment($attachment_data, $file_path); $this->set(array('attch_id' => $attach_id))->save(); } else { wp_all_export_remove_source(wp_all_export_get_absolute_path($this->options['filepath'])); $exportOptions = $this->options; $exportOptions['filepath'] = $file_path; $this->set(array('options' => $exportOptions))->save(); } } else { if (!$is_secure_import) { $file_path = str_replace($wp_uploads['baseurl'], $wp_uploads['basedir'], wp_get_attachment_url($this->attch_id)); } else { $file_path = wp_all_export_get_absolute_path($this->options['filepath']); } } $foundPosts = !XmlExportEngine::$is_user_export ? $exportQuery->found_posts : $exportQuery->get_total(); $postCount = !XmlExportEngine::$is_user_export ? $exportQuery->post_count : count($exportQuery->get_results()); // if posts still exists then export them if ($postCount) { switch ($this->options['export_to']) { case 'xml': if (!XmlExportEngine::$is_user_export) { $exported_to_file = pmxe_export_xml($exportQuery, $this->options, false, $cron, $file_path); } else { $exported_to_file = pmxe_export_users_xml($exportQuery, $this->options, false, $cron, $file_path); } break; case 'csv': if (!XmlExportEngine::$is_user_export) { $exported_to_file = pmxe_export_csv($exportQuery, $this->options, false, $cron, $file_path, $this->exported); } else { $exported_to_file = pmxe_export_users_csv($exportQuery, $this->options, false, $cron, $file_path, $this->exported); } break; default: # code... break; } wp_reset_postdata(); $this->set(array('exported' => $this->exported + $postCount, 'last_activity' => date('Y-m-d H:i:s'), 'processing' => 0))->save(); } else { wp_reset_postdata(); if (file_exists($file_path)) { if ($this->options['export_to'] == 'xml') { file_put_contents($file_path, '</data>', FILE_APPEND); } if (wp_all_export_is_compatible() and ($this->options['is_generate_templates'] or $this->options['is_generate_import'])) { $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' => $this->id); if (in_array('product', $this->options['cpt'])) { $templateOptions['_virtual'] = 1; $templateOptions['_downloadable'] = 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' == $this->options['export_to']) { wp_all_export_prepare_template_xml($this->options, $templateOptions); } else { wp_all_export_prepare_template_csv($this->options, $templateOptions); } $options = $templateOptions + PMXI_Plugin::get_default_import_options(); if ($this->options['is_generate_templates']) { $template = new PMXI_Template_Record(); $tpl_data = array('name' => $this->options['template_name'], 'is_keep_linebreaks' => 0, 'is_leave_html' => 0, 'fix_characters' => 0, 'options' => $options); if (!empty($this->options['template_name'])) { // save template in database $template->getByName($this->options['template_name'])->set($tpl_data)->save(); } } if ($this->options['is_generate_import']) { $import = new PMXI_Import_Record(); $import->getById($this->options['import_id']); if (!$import->isEmpty() and $import->parent_import_id == 99999) { $xmlPath = $file_path; $root_element = ''; if ('csv' == $this->options['export_to']) { $options['delimiter'] = $this->options['delimiter']; include_once PMXI_Plugin::ROOT_DIR . '/libraries/XmlImportCsvParse.php'; $path_parts = pathinfo($xmlPath); $path_parts_arr = explode(DIRECTORY_SEPARATOR, $path_parts['dirname']); $target = $is_secure_import ? $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::UPLOADS_DIRECTORY . DIRECTORY_SEPARATOR . array_pop($path_parts_arr) : $wp_uploads['path']; $csv = new PMXI_CsvParser(array('filename' => $xmlPath, 'targetDir' => $target)); $xmlPath = $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, 'count' => $exportQuery->found_posts))->save(); $history_file = new PMXI_File_Record(); $history_file->set(array('name' => $import->name, 'import_id' => $import->id, 'path' => $xmlPath, 'registered_on' => date('Y-m-d H:i:s')))->save(); $exportOptions = $this->options; $exportOptions['import_id'] = $import->id; $this->set(array('options' => $exportOptions))->save(); } } } // update export file for remove access # 1 meg at a time, you can adjust this. $to_dirname = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . PMXE_Plugin::CRON_DIRECTORY . DIRECTORY_SEPARATOR . md5(PMXE_Plugin::getInstance()->getOption('cron_job_key') . $this->id); if (!@is_dir($to_dirname)) { wp_mkdir_p($to_dirname); } if (!@file_exists($to_dirname . DIRECTORY_SEPARATOR . 'index.php')) { @touch($to_dirname . DIRECTORY_SEPARATOR . 'index.php'); } $to = $to_dirname . DIRECTORY_SEPARATOR . (!empty($this->friendly_name) ? sanitize_file_name($this->friendly_name) : 'feed') . '.' . $this->options['export_to']; $buffer_size = 1048576; $fin = @fopen($file_path, "rb"); $fout = @fopen($to, "w"); while (!@feof($fin)) { @fwrite($fout, @fread($fin, $buffer_size)); } @fclose($fin); @fclose($fout); if ($this->options['is_scheduled'] and "" != $this->options['scheduled_email']) { add_filter('wp_mail_content_type', array($this, 'set_html_content_type')); $headers = 'From: ' . get_bloginfo('name') . ' <' . get_bloginfo('admin_email') . '>' . "\r\n"; $message = '<p>Export ' . $this->options['friendly_name'] . ' has been completed. You can find exported file in attachments.</p>'; wp_mail($this->options['scheduled_email'], __("WP All Export", "pmxe_plugin"), $message, $headers, array($file_path)); remove_filter('wp_mail_content_type', array($this, 'set_html_content_type')); } } $this->set(array('processing' => 0, 'triggered' => 0, 'canceled' => 0, 'registered_on' => date('Y-m-d H:i:s')))->update(); } return $this; }
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']); 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); $exportQuery = new WP_Query(array('post_type' => $post['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'); } ?> <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."); ?> </h4> <?php } else { ?> <h4 style="line-height:60px;"><?php printf(__("No matching %s found for selected filter rules"), wp_all_export_get_cpt_name(array($post['cpt']))); ?> </h4> <?php } ?> </div> <?php exit(json_encode(array('html' => ob_get_clean()))); die; }
/** * AJAX action for preview export row */ function pmxe_wp_ajax_export_preview() { 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(); $values = array(); parse_str($_POST['data'], $values); $exportOptions = $values + (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options(); XmlExportEngine::$exportOptions = $exportOptions; XmlExportEngine::$is_user_export = $exportOptions['is_user_export']; 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\' => 0, \'posts_per_page\' => 10));'); } } 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' => 'title', 'order' => 'ASC', 'posts_per_page' => 10)); } 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; ?> <div id="post-preview" class="wpallexport-preview"> <div class="wpallexport-preview-content"> <?php switch ($exportOptions['export_to']) { case 'xml': $dom = new DOMDocument('1.0', $exportOptions['encoding']); $old = libxml_use_internal_errors(true); $xml = pmxe_export_xml($exportQuery, $exportOptions, true); $dom->loadXML($xml); libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); if ($elements = @$xpath->query('/' . $exportOptions['main_xml_tag']) and $elements->length) { pmxe_render_xml_element($elements->item(0), true); } break; case 'csv': ?> <small> <?php $csv = pmxe_export_csv($exportQuery, $exportOptions, true); if (!empty($csv)) { $csv_rows = array_filter(explode("\n", $csv)); if ($csv_rows) { ?> <table class="pmxe_preview" cellpadding="0" cellspacing="0"> <?php foreach ($csv_rows as $rkey => $row) { $cells = str_getcsv($row, $exportOptions['delimiter']); if ($cells) { ?> <tr> <?php foreach ($cells as $key => $value) { ?> <td> <?php if (!$rkey) { ?> <strong><?php } ?> <?php echo $value; ?> <?php if (!$rkey) { ?> </strong><?php } ?> </td> <?php } ?> </tr> <?php } } ?> </table> <?php } } else { _e('Data not found.', 'pmxe_plugin'); } ?> </small> <?php break; default: _e('This format is not supported.', 'pmxe_plugin'); break; } wp_reset_postdata(); ?> </div> </div> <?php exit(json_encode(array('html' => ob_get_clean()))); die; }
/** * AJAX action for preview export row */ function pmxe_wp_ajax_export_preview() { 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(); $values = array(); parse_str($_POST['data'], $values); $export_id = isset($_GET['id']) ? stripcslashes($_GET['id']) : 0; $exportOptions = $values + (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + PMXE_Plugin::get_default_import_options(); $errors = new WP_Error(); $engine = new XmlExportEngine($exportOptions, $errors); XmlExportEngine::$exportOptions = $exportOptions; XmlExportEngine::$is_user_export = $exportOptions['is_user_export']; XmlExportEngine::$is_comment_export = $exportOptions['is_comment_export']; XmlExportEngine::$exportID = $export_id; if ('advanced' == $exportOptions['export_type']) { if (XmlExportEngine::$is_user_export) { $exportQuery = eval('return new WP_User_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));'); } elseif (XmlExportEngine::$is_comment_export) { $exportQuery = eval('return new WP_Comment_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'number\' => 10));'); } else { $exportQuery = eval('return new WP_Query(array(' . $exportOptions['wp_query'] . ', \'offset\' => 0, \'posts_per_page\' => 10));'); } } else { XmlExportEngine::$post_types = $exportOptions['cpt']; if (in_array('users', $exportOptions['cpt']) or in_array('shop_customer', $exportOptions['cpt'])) { $exportQuery = new WP_User_Query(array('orderby' => 'ID', 'order' => 'ASC', 'number' => 10)); } elseif (in_array('comments', $exportOptions['cpt'])) { global $wp_version; if (version_compare($wp_version, '4.2.0', '>=')) { $exportQuery = new WP_Comment_Query(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10)); } else { $exportQuery = get_comments(array('orderby' => 'comment_ID', 'order' => 'ASC', 'number' => 10)); } } else { remove_all_actions('parse_query'); remove_all_actions('pre_get_posts'); 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' => 'title', 'order' => 'ASC', 'posts_per_page' => 10)); remove_filter('posts_where', 'wp_all_export_posts_where'); remove_filter('posts_join', 'wp_all_export_posts_join'); } } XmlExportEngine::$exportQuery = $exportQuery; ?> <div id="post-preview" class="wpallexport-preview"> <div class="wpallexport-preview-content"> <?php $wp_uploads = wp_upload_dir(); $functions = $wp_uploads['basedir'] . DIRECTORY_SEPARATOR . WP_ALL_EXPORT_UPLOADS_BASE_DIRECTORY . DIRECTORY_SEPARATOR . 'functions.php'; if (@file_exists($functions)) { require_once $functions; } switch ($exportOptions['export_to']) { case 'xml': $dom = new DOMDocument('1.0', $exportOptions['encoding']); $old = libxml_use_internal_errors(true); $xml = XmlCsvExport::export_xml(true); $dom->loadXML($xml); libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); $main_xml_tag = apply_filters('wp_all_export_main_xml_tag', $exportOptions['main_xml_tag'], XmlExportEngine::$exportID); if ($elements = @$xpath->query('/' . $main_xml_tag) and $elements->length) { pmxe_render_xml_element($elements->item(0), true); } break; case 'csv': ?> <small> <?php $csv = XmlCsvExport::export_csv(true); if (!empty($csv)) { $csv_rows = array_filter(explode("\n", $csv)); if ($csv_rows) { ?> <table class="pmxe_preview" cellpadding="0" cellspacing="0"> <?php foreach ($csv_rows as $rkey => $row) { $cells = str_getcsv($row, $exportOptions['delimiter']); if ($cells) { ?> <tr> <?php foreach ($cells as $key => $value) { ?> <td> <?php if (!$rkey) { ?> <strong><?php } ?> <?php echo $value; ?> <?php if (!$rkey) { ?> </strong><?php } ?> </td> <?php } ?> </tr> <?php } } ?> </table> <?php } } else { _e('Data not found.', 'wp_all_export_plugin'); } ?> </small> <?php break; default: _e('This format is not supported.', 'wp_all_export_plugin'); break; } wp_reset_postdata(); ?> </div> </div> <?php exit(json_encode(array('html' => ob_get_clean()))); die; }
/** * Step #1: Choose CPT */ public function index() { $action = $this->input->get('action'); $DefaultOptions = array('cpt' => '', 'export_to' => 'xml', 'export_type' => 'specific', 'wp_query' => '', 'filter_rules_hierarhy' => '', 'product_matching_mode' => 'strict', 'wp_query_selector' => 'wp_query', 'auto_generate' => 0); if (!in_array($action, array('index'))) { PMXE_Plugin::$session->clean_session(); $this->data['preload'] = false; } else { $DefaultOptions = (PMXE_Plugin::$session->has_session() ? PMXE_Plugin::$session->get_clear_session_data() : array()) + $DefaultOptions; $this->data['preload'] = true; } $wp_uploads = wp_upload_dir(); $this->data['post'] = $post = $this->input->post($DefaultOptions); if (is_array($this->data['post']['cpt'])) { $this->data['post']['cpt'] = $this->data['post']['cpt'][0]; } // Delete history $history_files = PMXE_Helper::safe_glob(PMXE_ROOT_DIR . '/history/*', PMXE_Helper::GLOB_RECURSE | PMXE_Helper::GLOB_PATH); if (!empty($history_files)) { foreach ($history_files as $filePath) { @file_exists($filePath) and @unlink($filePath); } } if (!class_exists('ZipArchive')) { $this->errors->add('form-validation', __('ZipArchive class is missing on your server.<br/>Please contact your web hosting provider and ask them to install and activate ZipArchive.', 'wp_all_export_plugin')); } if (!class_exists('XMLReader') or !class_exists('XMLWriter')) { $this->errors->add('form-validation', __('Required PHP components are missing.<br/><br/>WP All Export requires XMLReader, and XMLWriter PHP modules to be installed.<br/>These are standard features of PHP, and are necessary for WP All Export to write the files you are trying to export.<br/>Please contact your web hosting provider and ask them to install and activate the DOMDocument, XMLReader, and XMLWriter PHP modules.', 'wp_all_export_plugin')); } if ($this->input->post('is_submitted')) { PMXE_Plugin::$session->set('export_type', $post['export_type']); PMXE_Plugin::$session->set('filter_rules_hierarhy', $post['filter_rules_hierarhy']); PMXE_Plugin::$session->set('product_matching_mode', $post['product_matching_mode']); PMXE_Plugin::$session->set('wp_query_selector', $post['wp_query_selector']); if (!empty($post['auto_generate'])) { $auto_generate = XmlCsvExport::auto_genetate_export_fields($post, $this->errors); foreach ($auto_generate as $key => $value) { PMXE_Plugin::$session->set($key, $value); } PMXE_Plugin::$session->save_data(); } else { $engine = new XmlExportEngine($post, $this->errors); $engine->init_additional_data(); } } if ($this->input->post('is_submitted') and !$this->errors->get_error_codes()) { check_admin_referer('choose-cpt', '_wpnonce_choose-cpt'); PMXE_Plugin::$session->save_data(); if (!empty($post['auto_generate'])) { wp_redirect(add_query_arg('action', 'options', $this->baseUrl)); die; } else { wp_redirect(add_query_arg('action', 'template', $this->baseUrl)); die; } } $this->render(); }
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; }
/** * 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'])); } }
public static function auto_genetate_export_fields($post, $errors = false) { $errors or $errors = new WP_Error(); remove_all_filters("wp_all_export_init_fields", 10); remove_all_filters("wp_all_export_default_fields", 10); remove_all_filters("wp_all_export_other_fields", 10); remove_all_filters("wp_all_export_available_sections", 10); remove_all_filters("wp_all_export_available_data", 10); $engine = new XmlExportEngine($post, $errors); $engine->init_additional_data(); $auto_generate = array('ids' => array(), 'cc_label' => array(), 'cc_php' => array(), 'cc_code' => array(), 'cc_sql' => array(), 'cc_type' => array(), 'cc_options' => array(), 'cc_value' => array(), 'cc_name' => array()); $available_data = $engine->init_available_data(); $available_sections = apply_filters("wp_all_export_available_sections", $engine->get('available_sections')); foreach ($available_sections as $slug => $section) { if (!empty($section['content']) and !empty($available_data[$section['content']])) { foreach ($available_data[$section['content']] as $field) { if (isset($field['auto']) or !in_array('product', $post['cpt'])) { $auto_generate['ids'][] = 1; $auto_generate['cc_label'][] = is_array($field) ? $field['label'] : $field; $auto_generate['cc_php'][] = 0; $auto_generate['cc_code'][] = ''; $auto_generate['cc_sql'][] = ''; $auto_generate['cc_type'][] = is_array($field) ? $field['type'] : $slug; $auto_generate['cc_options'][] = ''; $auto_generate['cc_value'][] = is_array($field) ? $field['label'] : $field; $auto_generate['cc_name'][] = is_array($field) ? $field['name'] : $field; } } } } return $auto_generate; }