/** * 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; }
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; }
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; }
</a> </div> </div> <div class="clear"></div> </div> <div class="clear"></div> <div class="wpallexport-content-section wpallexport-console" style="display: block; margin-bottom: 0;"> <div class="ajax-console"> <div class="founded_records"> <h3><span class="matches_count"><?php echo PMXE_Plugin::$session->found_posts; ?> </span> <strong><?php echo wp_all_export_get_cpt_name($post['cpt']); ?> </strong> will be exported</h3> <h4><?php _e("Choose data to include in the export file."); ?> </h4> </div> </div> </div> <table class="wpallexport-layout wpallexport-export-template"> <tr> <td class="left"> <script type="text/javascript">
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; }
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; }
_e('records', 'wp_all_export_plugin'); ?> </label> <a href="#help" class="wpallexport-help" style="position: relative; top: -2px;" title="<?php _e('WP All Export must be able to process this many records in less than your server\'s timeout settings. If your export fails before completion, to troubleshoot you should lower this number.', 'wp_all_export_plugin'); ?> ">?</a> </div> <div class="input" style="margin:5px 0px;"> <input type="hidden" name="export_only_new_stuff" value="0" /> <input type="checkbox" id="export_only_new_stuff" name="export_only_new_stuff" value="1" <?php echo $post['export_only_new_stuff'] ? 'checked="checked"' : ''; ?> disabled="disabled"/> <label for="export_only_new_stuff" disabled="disabled"><?php printf(__('Only export %s once', 'wp_all_export_plugin'), empty($post['cpt']) ? __('records', 'wp_all_export_plugin') : wp_all_export_get_cpt_name($post['cpt'])); ?> </label> <a href="#help" class="wpallexport-help" style="position: relative; top: -2px;" title="<?php _e('If re-run, this export will only include records that have not been previously exported.<br><br><strong>Upgrade to the professional edition of WP All Export to use this option.</strong>', 'wp_all_export_plugin'); ?> ">?</a> </div> <div class="input" style="margin:5px 0px;"> <input type="hidden" name="include_bom" value="0" /> <input type="checkbox" id="include_bom" name="include_bom" value="1" <?php echo $post['include_bom'] ? 'checked="checked"' : ''; ?> /> <label for="include_bom"><?php _e('Include BOM in export file', 'wp_all_export_plugin');
_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($post['cpt'])); ?> </h4> <?php } else { ?> <h3><?php _e('Your export is ready to run.', 'wp_all_export_plugin'); ?> </h3> <h4><?php printf(__('WP All Export will export %d %s.'), PMXE_Plugin::$session->found_posts, wp_all_export_get_cpt_name($post['cpt'])); ?> </h4> <?php } ?> </div> <form class="confirm <?php echo !$isWizard ? 'edit' : ''; ?> " method="post" style="float:right;"> <?php wp_nonce_field('update-export', '_wpnonce_update-export');