*/ class PMXI_Admin_Import extends PMXI_Controller_Admin { protected $isWizard = true; // indicates whether controller is in wizard mode (otherwize it called to be deligated an edit action) protected $isTemplateEdit = false; // indicates whether controlled is deligated by manage imports controller protected function init() { parent::init(); error_reporting(0); //PMXI_Plugin::$session = PMXI_Session::get_instance(); if ('PMXI_Admin_Manage' == PMXI_Plugin::getInstance()->getAdminCurrentScreen()->base) { // prereqisites are not checked when flow control is deligated $id = $this->input->get('id'); $this->data['import'] = $import = new PMXI_Import_Record(); if ( ! $id or $import->getById($id)->isEmpty()) { // specified import is not found wp_redirect(add_query_arg('page', 'pmxi-admin-manage', admin_url('admin.php'))); die(); } $this->isWizard = false; } else { $action = PMXI_Plugin::getInstance()->getAdminCurrentScreen()->action; $this->_step_ready($action); $this->isInline = 'process' == $action; } XmlImportConfig::getInstance()->setCacheDirectory(sys_get_temp_dir()); // preserve id parameter as part of baseUrl $id = $this->input->get('id') and $this->baseUrl = add_query_arg('id', $id, $this->baseUrl); $this->baseUrl = apply_filters('pmxi_base_url', $this->baseUrl); } public function set($var, $val) { $this->{$var} = $val; } public function get($var) { return $this->{$var}; } /** * Checks whether corresponding step of wizard is complete * @param string $action */ protected function _step_ready($action) { // step #1: xml selction - has no prerequisites if ('index' == $action) return true; // step #2: element selection $this->data['dom'] = $dom = new DOMDocument('1.0', PMXI_Plugin::$session->encoding); $this->data['update_previous'] = $update_previous = new PMXI_Import_Record(); $old = libxml_use_internal_errors(true); $xml = $this->get_xml(); if (empty($xml) and in_array($action, array('process')) ){ ! empty( PMXI_Plugin::$session->update_previous ) and $update_previous->getById(PMXI_Plugin::$session->update_previous); return true; } if ( ! PMXI_Plugin::$session->has_session() or ! empty( PMXI_Plugin::$session->update_previous ) and $update_previous->getById(PMXI_Plugin::$session->update_previous)->isEmpty() or ! @$dom->loadXML($xml)// FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load ) { if ( ! PMXI_Plugin::is_ajax() ){ $this->errors->add('form-validation', __('WP All Import lost track of where you are.

Maybe you cleared your cookies or maybe it is just a temporary issue on your or your web host\'s end.
If you can\'t do an import without seeing this error, change your session settings on the All Import -> Settings page.', 'wp_all_import_plugin')); wp_redirect_or_javascript($this->baseUrl); die(); } } libxml_use_internal_errors($old); if ('element' == $action) return true; if ('evaluate' == $action) return true; if ('evaluate_variations' == $action) return true; // step #3: template $xpath = new DOMXPath($dom); $this->data['elements'] = $elements = @$xpath->query(PMXI_Plugin::$session->xpath); if ('preview' == $action or 'tag' == $action or 'preview_images' == $action or 'preview_taxonomies' == $action or 'preview_images' == $action) return true; if ( ! PMXI_Plugin::$session->get('xpath', false) or empty($elements) or ! $elements->length) { $this->errors->add('form-validation', __('There are no elements to import based on your XPath.

If you are in Step 2, you probably specified filtering options that don’t match any elements present in your file.
If you are seeing this error elsewhere, it means that while the XPath expression for your initial import matched some elements in your file previously, there are now zero elements in the file that match this expression.
You can edit the XPath for your import by going to the Manage Imports -> Import Settings page.', 'wp_all_import_plugin')); wp_redirect_or_javascript(add_query_arg('action', 'element', $this->baseUrl)); die(); } if ('template' == $action or 'preview' == $action or 'tag' == $action) return true; // step #4: options if ( empty( PMXI_Plugin::$session->options ) ) { wp_redirect_or_javascript(add_query_arg('action', 'template', $this->baseUrl)); die(); } if ('options' == $action) return true; if ( empty( PMXI_Plugin::$session->options ) ) { wp_redirect(add_query_arg('action', 'options', $this->baseUrl)); die(); } } /** * Step #1: Choose File */ public function index() { $action = $this->input->get('action'); $this->data['reimported_import'] = $import = new PMXI_Import_Record(); $this->data['id'] = $id = $this->input->get('id'); $this->data['parent_import'] = $parent_import = $this->input->get('parent_import', 0); $parent_import_record = new PMXI_Import_Record(); $DefaultOptions = array( 'type' => '', 'wizard_type' => 'new', 'custom_type' => 'post', 'show_hidden_cpt' => 0, 'feed_type' => '', 'url' => '', 'ftp' => array('url' => 'ftp://'), 'file' => '', 'reimport' => '', 'is_update_previous' => $id ? 1 : 0, 'update_previous' => $id, 'xpath' => '/', 'filepath' => '', 'root_element' => '', 'downloaded' => '', 'auto_generate' => 0, 'template' => false ); if ($parent_import and ! $parent_import_record->getById($parent_import)->isEmpty()){ $DefaultOptions['custom_type'] = $parent_import_record->options['custom_type']; } if ($id) { // update requested but corresponding import is not found if ($import->getById($id)->isEmpty()){ if (!empty($_GET['deligate']) and $_GET['deligate'] == 'wpallexport'){ wp_redirect(add_query_arg('pmxi_nt', array('error' => urlencode(__('The import associated with this export has been deleted.', 'wp_all_import_plugin')), 'updated' => urlencode(__('Please re-run your export by clicking Run Export on the All Export -> Manage Exports page. Then try your import again.', 'wp_all_import_plugin'))), remove_query_arg('id', $this->baseUrl))); die(); } else{ wp_redirect(add_query_arg('pmxi_nt', array('error' => urlencode(__('This import has been deleted.', 'wp_all_import_plugin'))), remove_query_arg('id', $this->baseUrl))); die(); } } else{ $DefaultOptions['custom_type'] = $import->options['custom_type']; } } if ( ! in_array($action, array('index'))) { PMXI_Plugin::$session->clean_session(); } else { $DefaultOptions = (PMXI_Plugin::$session->has_session() ? PMXI_Plugin::$session->first_step : array()) + $DefaultOptions; } $this->data['post'] = $post = $this->input->post( $DefaultOptions ); if ( ! class_exists('DOMDocument') or ! class_exists('XMLReader') ) { $this->errors->add('form-validation', __('Required PHP components are missing.

WP All Import requires DOMDocument, XMLReader, and XMLWriter PHP modules to be installed.
These are standard features of PHP, and are necessary for WP All Import to read the files you are trying to import.
Please contact your web hosting provider and ask them to install and activate the DOMDocument, XMLReader, and XMLWriter PHP modules.', 'wp_all_import_plugin')); } $this->data['upload_validation'] = false; if ($this->input->post('is_submitted') and ! $this->errors->get_error_codes()) { check_admin_referer('choose-file', '_wpnonce_choose-file'); if ('upload' == $this->input->post('type')) { $uploader = new PMXI_Upload($post['filepath'], $this->errors, rtrim(str_replace(basename($post['filepath']), '', $post['filepath']), '/')); $upload_result = $uploader->upload(); if ($upload_result instanceof WP_Error){ $this->errors = $upload_result; } else{ $source = $upload_result['source']; $filePath = $upload_result['filePath']; $post['template'] = $upload_result['template']; PMXI_Plugin::$is_csv = $upload_result['is_csv']; if ( ! empty($upload_result['root_element'])) $post['root_element'] = $upload_result['root_element']; } } if ($this->input->post('is_submitted') and '' == $this->input->post('custom_type')) { $this->errors->add('form-validation', __('Select an item type to import the data', 'wp_all_import_plugin')); } if ($post['is_update_previous'] and empty($post['update_previous'])) { $this->errors->add('form-validation', __('Previous import for update must be selected to proceed with a new one', 'wp_all_import_plugin')); } $this->data['detection_feed_extension'] = false; $elements_cloud = array(); @set_time_limit(0); $table = PMXI_Plugin::getInstance()->getTablePrefix() . 'imports'; $deligate = $this->input->get('deligate', false); $redirect_to_template = false; $importRecord = new PMXI_Import_Record(); switch ( $deligate ) { case 'wpallexport': global $wpdb; $import_id = $this->input->get('id', 0); $importRecord->clear(); $importRecord->getById($import_id); if ( ! $importRecord->isEmpty() and ! empty($importRecord->options['unique_key'])) { $importRecord->set(array( 'path' => wp_all_import_get_relative_path($filePath), 'parent_import_id' => 0 ))->save(); $post['is_update_previous'] = 1; $post['update_previous'] = $importRecord->id; //$chunks = $importRecord->count; $redirect_to_template = true; } if ( $importRecord->isEmpty() ){ $this->errors->add('form-validation', __('File is no longer in the correct format', 'wp_all_import_plugin')); } elseif (empty($importRecord->options['unique_key'])) { $this->errors->add('form-validation', __('Certain columns are required to be present in your file to enable it to be re-imported with WP All Import. These columns are missing. Re-export your file using WP All Export, and don\'t delete any of the columns when editing it. Then, re-import will work correctly.', 'wp_all_import_plugin')); } elseif($importRecord->options['custom_type'] == 'import_users' && ! class_exists('PMUI_Plugin')){ $this->errors->add('form-validation', __('

The import template you are using requires User Import Add-On.

Purchase the User Import Add-On', 'wp_all_import_plugin')); } break; default: # code... break; } $local_paths = !empty($local_paths) ? $local_paths : array($filePath); // if ( 'file' == $this->input->post('type') ){ // $root_element = wp_all_import_get_reader_engine( $local_paths, $post ); // if ( empty($post['root_element']) and ! empty($root_element)) // { // $post['root_element'] = $root_element; // } // } foreach ($local_paths as $key => $path) { if ( @file_exists($path) ){ $file = new PMXI_Chunk($path, array('element' => $post['root_element'], 'get_cloud' => true)); if ( ! empty($file->options['element']) ) { $xpath = "/" . $file->options['element']; $elements_cloud = $file->cloud; if ( ! empty($elements_cloud) and class_exists('PMXE_Plugin') and ! $importRecord->isEmpty() ){ $is_file_valid = apply_filters('wp_all_import_is_exported_file_valid', true, $importRecord->options['export_id'], $elements_cloud); if ( ! $is_file_valid ) { $this->errors->add('form-validation', __('Certain columns are required to be present in your file to enable it to be re-imported with WP All Import. These columns are missing. Re-export your file using WP All Export, and don\'t delete any of the columns when editing it. Then, re-import will work correctly.', 'wp_all_import_plugin')); } } if ( ($redirect_to_template or $post['auto_generate']) and ! $this->errors->get_error_codes() ){ // loop through the file until all lines are read while ($xml = $file->read()) { if ( ! empty($xml) ) { //PMXI_Import_Record::preprocessXml($xml); $xml = "" . "\n" . $xml; $dom = new DOMDocument('1.0', 'UTF-8'); $old = libxml_use_internal_errors(true); $dom->loadXML($xml); libxml_use_internal_errors($old); $dxpath = new DOMXPath($dom); if (($elements = @$dxpath->query($xpath)) and $elements->length){ $chunks += $elements->length; unset($dom, $dxpath, $elements); } } } //unset($file); } break; } } else $this->errors->add('form-validation', __('Unable to download feed resource.', 'wp_all_import_plugin')); } if ( ! $this->errors->get_error_codes() ) { // xml is valid $source['root_element'] = $file->options['element']; $source['first_import'] = date("Y-m-d H:i:s"); PMXI_Plugin::$session->clean_session(); $session_data = array( 'filePath' => $filePath, 'parent_import_id' => $parent_import, 'xpath' => (!empty($xpath)) ? $xpath : '', 'feed_type' => $post['feed_type'], 'wizard_type' => $post['wizard_type'], 'custom_type' => $post['custom_type'], 'source' => $source, 'encoding' => 'UTF-8', 'is_csv' => PMXI_Plugin::$is_csv, 'csv_path' => PMXI_Plugin::$csv_path, 'chunk_number' => 1, 'log' => '', 'processing' => 0, 'queue_chunk_number' => 0, 'count' => (isset($chunks)) ? $chunks : 0, 'warnings' => 0, 'errors' => 0, 'start_time' => 0, 'local_paths' => (!empty($local_paths)) ? $local_paths : array(), // ftp import local copies of remote files 'csv_paths' => array(PMXI_Plugin::$csv_path), // ftp import local copies of remote CSV files 'action' => 'import', 'elements_cloud' => (!empty($elements_cloud)) ? $elements_cloud : array(), 'pointer' => 1, 'deligate' => $deligate, 'first_step' => $post ); // apply options from WP All Export bundle if ( ! empty($post['template'])) { $templates = json_decode($post['template'], true); $template_options = maybe_unserialize($templates[0]['options']); $template_options['type'] = ($post['custom_type'] == 'page') ? 'page' : 'post'; $template_options['custom_type'] = $post['custom_type']; $template_options['wizard_type'] = $post['wizard_type']; if ($post['wizard_type'] == 'new') { $template_options['create_new_records'] = 1; } $this->data['post'] = $template_options; PMXI_Plugin::$session->set('options', $template_options); } foreach ($session_data as $key => $value) { PMXI_Plugin::$session->set( $key, $value ); } $update_previous = new PMXI_Import_Record(); if ($post['is_update_previous'] and ! $update_previous->getById($post['update_previous'])->isEmpty()) { PMXI_Plugin::$session->set('update_previous', $update_previous->id); PMXI_Plugin::$session->set('xpath', $update_previous->xpath); PMXI_Plugin::$session->set('options', $update_previous->options); } else { PMXI_Plugin::$session->set('update_previous', ''); } PMXI_Plugin::$session->save_data(); $xml = $this->get_xml(); if ( empty($xml) ) { $this->errors->add('upload-validation', __('Please confirm you are importing a valid feed.
Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.

WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.

It is also possible that there is a bug in WP All Import, and the problem is not with the feed.

If you need assistance, please contact support – support@wpallimport.com – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'wp_all_import_plugin')); $this->data['upload_validation'] = true; } elseif( $redirect_to_template ) { wp_redirect(add_query_arg('action', 'template', $this->baseUrl)); die(); } elseif( $post['auto_generate'] ) { wp_redirect(add_query_arg('action', 'options', $this->baseUrl)); die(); } else { wp_redirect(add_query_arg('action', 'element', $this->baseUrl)); die(); } } else if ('url' == $this->input->post('type') and !empty($this->errors)) { $this->errors->add('form-validation', __('WP All Import unable to detect file type.

WP All Import not able to determine what type of file you are importing. Make sure your file extension is correct for the file type you are importing.
Please choose the correct file type from the dropdown below, or try adding &type=xml or &type=csv to the end of the URL, for example http://example.com/export-products.php?&type=xml', 'wp_all_import_plugin')); $this->data['detection_feed_extension'] = true; } else { $this->errors->add('upload-validation', __('Please confirm you are importing a valid feed.
Often, feed providers distribute feeds with invalid data, improperly wrapped HTML, line breaks where they should not be, faulty character encodings, syntax errors in the XML, and other issues.

WP All Import has checks in place to automatically fix some of the most common problems, but we can’t catch every single one.

It is also possible that there is a bug in WP All Import, and the problem is not with the feed.

If you need assistance, please contact support – support@wpallimport.com – with your XML/CSV file. We will identify the problem and release a bug fix if necessary.', 'wp_all_import_plugin')); $this->data['upload_validation'] = true; } do_action("pmxi_get_file", $filePath); } if ($this->input->post('is_submitted') and $this->errors->get_error_codes()) PMXI_Plugin::$session->clean_session(); $this->render(); } /** * Step #2: Choose elements */ public function element() { $xpath = new DOMXPath($this->data['dom']); $post = $this->input->post(array('xpath' => '')); $this->data['post'] =& $post; $this->data['elements_cloud'] = PMXI_Plugin::$session->elements_cloud; $this->data['is_csv'] = PMXI_Plugin::$session->is_csv; $wp_uploads = wp_upload_dir(); if ($this->input->post('is_submitted')) { check_admin_referer('choose-elements', '_wpnonce_choose-elements'); if ('' == $post['xpath']) { $this->errors->add('form-validation', __('No elements selected', 'wp_all_import_plugin')); } else { $node_list = @ $xpath->query($post['xpath']); // make sure only element selection is allowed; prevent parsing warning to be displayed if (FALSE === $node_list) { $this->errors->add('form-validation', __('Your XPath is not valid.

Click "get default XPath" to get the default XPath.', 'wp_all_import_plugin')); } else { foreach ($node_list as $el) { if ( ! $el instanceof DOMElement) { $this->errors->add('form-validation', __('XPath must match only elements', 'wp_all_import_plugin')); break; }; } } } if ( ! $this->errors->get_error_codes()) { wp_redirect(apply_filters('pmxi_element_redirect' , add_query_arg('action', 'template', $this->baseUrl))); die(); } } else { if ( PMXI_Plugin::$session->xpath ) { $post['xpath'] = PMXI_Plugin::$session->xpath; $this->data['elements'] = $elements = $xpath->query($post['xpath']); $this->data['is_show_warning'] = true; foreach ($elements as $element) { if ($element instanceof DOMElement) { foreach ($element->childNodes as $child) { if ($child instanceof DOMElement) { $this->data['is_show_warning'] = false; } } break; } } if ( ! $elements->length and ! empty( PMXI_Plugin::$session->update_previous ) ) { $_GET['pmxi_nt'] = __('Warning: No matching elements found for XPath expression from the import being updated. It probably means that new XML file has different format. Though you can update XPath, procceed only if you sure about update operation being valid.', 'wp_all_import_plugin'); } } else { // suggest 1st repeating element as default selection $post['xpath'] = PMXI_Render::xml_find_repeating($this->data['dom']->documentElement); if ( ! empty($post['xpath'])){ $this->data['elements'] = $elements = $xpath->query($post['xpath']); } } } // workaround to prevent rendered XML representation to eat memory since it has to be stored in memory when output is bufferred $this->render(); } /** * Helper to evaluate xpath and return matching elements as direct paths for javascript side to highlight them */ public function evaluate() { if ( ! PMXI_Plugin::getInstance()->getAdminCurrentScreen()->is_ajax) { // call is only valid when send with ajax wp_redirect(add_query_arg('action', 'element', $this->baseUrl)); die(); } // HTTP headers for no cache etc header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); $xpath = new DOMXPath($this->data['dom']); $post = $this->input->post(array('xpath' => '', 'show_element' => 1, 'root_element' => PMXI_Plugin::$session->source['root_element'], 'delimiter' => '', 'is_csv' => 0)); $wp_uploads = wp_upload_dir(); if ( ! check_ajax_referer( 'wp_all_import_secure', 'security', false )){ $this->errors->add('form-validation', __('Security check', 'wp_all_import_plugin')); } elseif ('' == $post['xpath']) { $this->errors->add('form-validation', __('Your XPath is empty.

Please enter an XPath expression, or click "get default XPath" to get the default XPath.', 'wp_all_import_plugin')); } else { $source = PMXI_Plugin::$session->get('source'); // counting selected elements if ('' != $post['delimiter'] and $post['delimiter'] != PMXI_Plugin::$session->is_csv ) { include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php'); PMXI_Plugin::$session->set('is_csv', $post['delimiter']); wp_all_import_remove_source(PMXI_Plugin::$session->filePath, false); $csv = new PMXI_CsvParser( array( 'filename' => PMXI_Plugin::$session->get('csv_path'), 'xpath' => '', 'delimiter' => $post['delimiter'], 'targetDir' => rtrim(str_replace(basename(PMXI_Plugin::$session->filePath), '', PMXI_Plugin::$session->filePath), '/') )); $filePath = $csv->xml_path; PMXI_Plugin::$session->set('filePath', $filePath); PMXI_Plugin::$session->set('local_paths', array($filePath)); } // counting selected elements PMXI_Plugin::$session->set('xpath', $post['xpath']); $current_xpath = ''; if ($post['show_element'] == 1) { PMXI_Plugin::$session->set('count', $this->data['node_list_count'] = 0); }else{ $this->data['node_list_count'] = PMXI_Plugin::$session->count; } $xpath_elements = explode('[', $post['xpath']); $xpath_parts = explode('/', $xpath_elements[0]); $source['root_element'] = $xpath_parts[1]; PMXI_Plugin::$session->set('source', $source); PMXI_Plugin::$session->save_data(); $loop = 0; foreach (PMXI_Plugin::$session->local_paths as $key => $path) { $file = new PMXI_Chunk($path, array('element' => $source['root_element'], 'encoding' => PMXI_Plugin::$session->encoding)); // loop through the file until all lines are read while ($xml = $file->read()) { if ( ! empty($xml) ) { //PMXI_Import_Record::preprocessXml($xml); $xml = "encoding ."\"?>" . "\n" . $xml; $dom = new DOMDocument('1.0', PMXI_Plugin::$session->encoding); $old = libxml_use_internal_errors(true); $dom->loadXML($xml); libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); if (($elements = @$xpath->query($post['xpath'])) and $elements->length){ if ( $post['show_element'] == 1 ){ $this->data['node_list_count'] += $elements->length; if (!$loop) $this->data['dom'] = $dom; } $loop += $elements->length; if ( $post['show_element'] > 1 and $loop == $post['show_element']) { $this->data['dom'] = $dom; break(2); } unset($dom, $xpath, $elements); } } } unset($file); PMXI_Plugin::$session->set('count', $this->data['node_list_count']); } if ( ! $this->data['node_list_count']) { $this->errors->add('form-validation', __('There are no elements to import based on your XPath.

If you are in Step 2, you probably specified filtering options that don’t match any elements present in your file.
If you are seeing this error elsewhere, it means that while the XPath expression for your initial import matched some elements in your file previously, there are now zero elements in the file that match this expression.
You can edit the XPath for your import by going to the Manage Imports -> Import Settings page.', 'wp_all_import_plugin')); } } $this->data['show_element'] = $post['show_element']; PMXI_Plugin::$session->save_data(); $this->data['is_csv'] = $post['is_csv']; ob_start(); if ( ! $this->errors->get_error_codes()) { $xpath = new DOMXPath($this->data['dom']); $this->data['elements'] = $elements = @ $xpath->query($post['xpath']); // prevent parsing warning to be displayed $paths = array(); $this->data['paths'] =& $paths; if (PMXI_Plugin::getInstance()->getOption('highlight_limit') and $elements->length <= PMXI_Plugin::getInstance()->getOption('highlight_limit')) { foreach ($elements as $el) { if ( ! $el instanceof DOMElement) continue; $p = PMXI_Render::get_xml_path($el, $xpath) and $paths[] = $p; } } $this->render(); } else { $this->error(); } $html = ob_get_clean(); ob_start(); if ( ! empty($elements->length) ) PMXI_Render::render_xml_elements_for_filtring($elements->item(0)); $render_element = ob_get_clean(); exit( json_encode( array('result' => true, 'html' => $html, 'root_element' => $source['root_element'], 'count' => $this->data['node_list_count'], 'render_element' => $render_element ))); } /** * Helper to evaluate xpath and return matching elements as direct paths for javascript side to highlight them */ public function evaluate_variations() { if ( ! PMXI_Plugin::getInstance()->getAdminCurrentScreen()->is_ajax) { // call is only valid when send with ajax wp_redirect(add_query_arg('action', 'element', $this->baseUrl)); die(); } $post = $this->input->post(array('xpath' => '', 'show_element' => 1, 'root_element' => (!empty(PMXI_Plugin::$session->source['root_element'])) ? PMXI_Plugin::$session->source['root_element'] : '', 'tagno' => 0, 'parent_tagno' => 1)); $wp_uploads = wp_upload_dir(); $this->get_xml( $post['parent_tagno'], true ); $xpath = new DOMXPath($this->data['dom']); $this->data['tagno'] = max(intval($this->input->getpost('tagno', 1)), 0); if ('' == $post['xpath']) { $this->errors->add('form-validation', __('Your XPath is empty.

Please enter an XPath expression, or click "get default XPath" to get the default XPath.', 'wp_all_import_plugin')); } else { $post['xpath'] = '/' . ((!empty($this->data['update_previous']->root_element)) ? $this->data['update_previous']->root_element : PMXI_Plugin::$session->source['root_element']) .'/'. ltrim(trim(str_replace("[*]","",$post['xpath']),'{}'), '/'); // in default mode $this->data['variation_elements'] = $elements = @ $xpath->query($post['xpath']); // prevent parsing warning to be displayed $this->data['variation_list_count'] = $elements->length; if (FALSE === $elements) { $this->errors->add('form-validation', __('Your XPath is not valid.

Click "get default XPath" to get the default XPath.', 'wp_all_import_plugin')); } elseif ( ! $elements->length) { $this->errors->add('form-validation', __('No matching variations found for XPath specified', 'wp_all_import_plugin')); } else { foreach ($elements as $el) { if ( ! $el instanceof DOMElement) { $this->errors->add('form-validation', __('XPath must match only elements', 'wp_all_import_plugin')); break; }; } } } ob_start(); if ( ! $this->errors->get_error_codes()) { $paths = array(); $this->data['paths'] =& $paths; if (PMXI_Plugin::getInstance()->getOption('highlight_limit') and $elements->length <= PMXI_Plugin::getInstance()->getOption('highlight_limit')) { foreach ($elements as $el) { if ( ! $el instanceof DOMElement) continue; $p = PMXI_Render::get_xml_path($el, $xpath) and $paths[] = $p; } } $this->render(); } else { $this->error(); } exit( json_encode(array('html' => ob_get_clean())) ); } /** * Preview selected xml tag (called with ajax from `template` step) */ public function tag( $is_json = true ) { if ($is_json) check_ajax_referer( 'wp_all_import_secure', 'security' ); $wp_uploads = wp_upload_dir(); if (empty($this->data['elements']->length)) { $update_previous = new PMXI_Import_Record(); $id = $this->input->get('id'); if ($id and $update_previous->getById($id)) { PMXI_Plugin::$session->set('update_previous', $update_previous->id); PMXI_Plugin::$session->set('xpath', $update_previous->xpath); PMXI_Plugin::$session->set('options', $update_previous->options); $history = new PMXI_File_List(); $history->setColumns('id', 'name', 'registered_on', 'path')->getBy(array('import_id' => $update_previous->id), 'id DESC'); if ($history->count()){ $history_file = new PMXI_File_Record(); $history_file->getBy('id', $history[0]['id']); if ( PMXI_Plugin::$session->has_session() ){ PMXI_Plugin::$session->set('filePath', wp_all_import_get_absolute_path($history_file->path)); PMXI_Plugin::$session->set('count', $update_previous->count); PMXI_Plugin::$session->set('encoding', ( ! empty($update_previous->options['encoding'])) ? $update_previous->options['encoding'] : 'UTF-8'); PMXI_Plugin::$session->save_data(); } } } else { unset(PMXI_Plugin::$session->update_previous); } } $this->data['tagno'] = max(intval($this->input->getpost('tagno', 1)), 1); $this->data['import_action'] = $this->input->getpost('import_action', false); if ($this->data['tagno']){ $local_paths = ( ! empty(PMXI_Plugin::$session->local_paths) ) ? PMXI_Plugin::$session->local_paths : array(PMXI_Plugin::$session->filePath); PMXI_Plugin::$session->set('local_paths', $local_paths); $loop = 0; foreach ($local_paths as $key => $path) { if (@file_exists($path)){ $file = new PMXI_Chunk($path, array( 'element' => PMXI_Plugin::$session->source['root_element'], 'encoding' => PMXI_Plugin::$session->encoding )); // loop through the file until all lines are read while ($xml = $file->read()) { if ( ! empty($xml) ) { //PMXI_Import_Record::preprocessXml($xml); $xml = "encoding ."\"?>" . "\n" . $xml; $dom = new DOMDocument('1.0', PMXI_Plugin::$session->encoding); $old = libxml_use_internal_errors(true); $dom->loadXML($xml); libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); if (($elements = @$xpath->query(PMXI_Plugin::$session->xpath)) and $elements->length){ $this->data['elements'] = $elements; $loop += $elements->length; if ($loop == $this->data['tagno'] or $loop == PMXI_Plugin::$session->count){ /* Merge nested XML/CSV files */ /*$nested_files = json_decode(PMXI_Plugin::$session->options['nested_files'], true); if ( ! empty($nested_files) ){ $merger = new PMXI_Nested($dom, $nested_files, $xml, PMXI_Plugin::$session->xpath); $merger->merge(); $xml = $merger->get_xml(); unset($merger); }*/ unset($dom, $xpath, $elements); break(2); } unset($dom, $xpath, $elements); } } } unset($file); } } } if ( $is_json ){ ob_start(); $this->render(); exit( json_encode(array('html' => ob_get_clean())) ); } else $this->render(); } /** * Preview future post based on current template and tag (called with ajax from `template` step) */ public function preview() { if ( ! PMXI_Plugin::getInstance()->getAdminCurrentScreen()->is_ajax) { // call is only valid when send with ajax exit('Nice try!'); } if ( ! check_ajax_referer( 'wp_all_import_preview', 'security', false )){ $this->errors->add('form-validation', __('Security check', 'wp_all_import_plugin')); } if ( ! $this->errors->get_error_codes()) { $post = $this->input->post(array( 'title' => '', 'content' => '', 'is_keep_linebreaks' => 0, 'is_leave_html' => 0, 'fix_characters' => 0, 'import_encoding' => 'UTF-8', 'tagno' => 0 )); $wp_uploads = wp_upload_dir(); $this->data['tagno'] = $tagno = min(max(intval($this->input->getpost('tagno', 1)), 1), PMXI_Plugin::$session->count); $xml = ''; $local_paths = ( ! empty(PMXI_Plugin::$session->local_paths) ) ? PMXI_Plugin::$session->local_paths : array(PMXI_Plugin::$session->filePath); $loop = 1; foreach ($local_paths as $key => $path) { if (PMXI_Plugin::$session->encoding != $post['import_encoding'] and ! empty(PMXI_Plugin::$session->csv_paths[$key])){ // conver CSV to XML with selected encoding include_once(PMXI_Plugin::ROOT_DIR.'/libraries/XmlImportCsvParse.php'); $csv = new PMXI_CsvParser(array( 'filename' => PMXI_Plugin::$session->csv_paths[$key], 'xpath' => '', 'delimiter' => PMXI_Plugin::$is_csv, 'encoding' => $post['import_encoding'], 'xml_path' => $path )); } $file = new PMXI_Chunk($path, array( 'element' => PMXI_Plugin::$session->source['root_element'], 'encoding' => $post['import_encoding'] )); // loop through the file until all lines are read while ($xml = $file->read()) { if ( ! empty($xml) ) { //PMXI_Import_Record::preprocessXml($xml); $xml = "" . "\n" . $xml; $dom = new DOMDocument('1.0', $post['import_encoding']); $old = libxml_use_internal_errors(true); $dom->loadXML($xml); // FIX: libxml xpath doesn't handle default namespace properly, so remove it upon XML load libxml_use_internal_errors($old); $xpath = new DOMXPath($dom); if (($this->data['elements'] = $elements = @$xpath->query(PMXI_Plugin::$session->xpath)) and $elements->length){ if ( $loop == $tagno ){ /* Merge nested XML/CSV files */ /*$nested_files = json_decode(PMXI_Plugin::$session->options['nested_files'], true); if ( ! empty($nested_files) ){ $merger = new PMXI_Nested($dom, $nested_files, $xml, PMXI_Plugin::$session->xpath); $merger->merge(); $xml = $merger->get_xml(); unset($merger); }*/ unset($dom, $xpath, $elements); break(2); } unset($dom, $xpath, $elements); $loop++; } } } unset($file); } //$this->data['tagno'] = $tagno = 1; $xpath = "(" . PMXI_Plugin::$session->xpath . ")[1]"; PMXI_Plugin::$session->set('encoding', $post['import_encoding']); PMXI_Plugin::$session->save_data(); // validate try { if (empty($xml)){ $this->errors->add('form-validation', __('WP All Import lost track of where you are.

Maybe you cleared your cookies or maybe it is just a temporary issue on your web host\'s end.
If you can\'t do an import without seeing this error, change your session settings on the All Import -> Settings page.', 'wp_all_import_plugin')); } elseif (empty($post['title'])) { $this->errors->add('form-validation', __('Warning: your title is blank.', 'wp_all_import_plugin')); $this->data['title'] = ""; } else { list($this->data['title']) = XmlImportParser::factory($xml, $xpath, $post['title'], $file)->parse(); unlink($file); if ( ! isset($this->data['title']) or '' == strval(trim(strip_tags($this->data['title'], '