예제 #1
0
파일: import.php 프로젝트: hikaram/wee
 /**
  * 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.<br/><br/>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 = "<?xml version=\"1.0\" encoding=\"" . PMXI_Plugin::$session->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;
                             PMXI_Plugin::$session->set('count', $this->data['node_list_count']);
                             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);
         }
         if (!$this->data['node_list_count']) {
             $this->errors->add('form-validation', __('There are no elements to import based on your XPath.<br/><br/>If you are in Step 2, you probably specified filtering options that don’t match any elements present in your file.<br/>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.<br/>You can edit the XPath for your import by going to the Manage Imports -> Import Settings page.', 'wp_all_import_plugin'));
         }
     }
     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)));
 }
예제 #2
0
</th>
								<th><?php 
_e('Value', 'wp_all_import_plugin');
?>
</th>
								<th>&nbsp;</th>
							</tr>
							<tr>
								<td style="width:25%;">
									<select id="pmxi_xml_element">
										<option value=""><?php 
_e('Select Element', 'wp_all_import_plugin');
?>
</option>
										<?php 
PMXI_Render::render_xml_elements_for_filtring($elements->item(0));
?>
									</select>
								</td>
								<td style="width:25%;">
									<select id="pmxi_rule">
										<option value=""><?php 
_e('Select Rule', 'wp_all_import_plugin');
?>
</option>
										<option value="equals"><?php 
_e('equals', 'wp_all_import_plugin');
?>
</option>
										<option value="not_equals"><?php 
_e('not equals', 'wp_all_import_plugin');