chunk.php
11 years ago
config.php
11 years ago
download.php
11 years ago
handler.php
11 years ago
helper.php
11 years ago
input.php
11 years ago
nested.php
11 years ago
render.php
11 years ago
session.php
11 years ago
upload.php
11 years ago
nested.php
88 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! class_exists('PMXI_Nested')){ |
| 4 | |
| 5 | class PMXI_Nested{ |
| 6 | protected $nested_files; |
| 7 | protected $xpath; |
| 8 | protected $dom; |
| 9 | protected $elements; |
| 10 | public $xml; |
| 11 | |
| 12 | public function __construct( $dom, $nested_files, $xml, $xpath, $elements = false){ |
| 13 | $this->dom = $dom; |
| 14 | $this->nested_files = $nested_files; |
| 15 | $this->xpath = $xpath; |
| 16 | $this->xml = $xml; |
| 17 | $this->elements = $elements; |
| 18 | } |
| 19 | |
| 20 | public function merge(){ |
| 21 | |
| 22 | /* Merge nested XML/CSV files */ |
| 23 | if ( ! empty($this->nested_files) ){ |
| 24 | $tmp_files = array(); |
| 25 | foreach ($this->nested_files as $key => $nfile) { |
| 26 | $nested_fileURL = array_shift(XmlImportParser::factory($this->xml, $this->xpath, $nfile, $tmp_file)->parse()); $tmp_files[] = $tmp_file; |
| 27 | if ( ! empty($nested_fileURL) ){ |
| 28 | $errors = new WP_Error(); |
| 29 | |
| 30 | $uploader = new PMXI_Upload($nested_fileURL, $errors); |
| 31 | $upload_result = $uploader->url(); |
| 32 | |
| 33 | if ($upload_result instanceof WP_Error){ |
| 34 | $errors = $upload_result; |
| 35 | } |
| 36 | else{ |
| 37 | $source = $upload_result['source']; |
| 38 | $filePath = $upload_result['filePath']; |
| 39 | if ( ! empty($upload_result['root_element'])) |
| 40 | $root_element = $upload_result['root_element']; |
| 41 | else |
| 42 | $root_element = ''; |
| 43 | $feed_type = $upload_result['feed_type']; |
| 44 | } |
| 45 | |
| 46 | unset($uploader); |
| 47 | |
| 48 | $nested_xml = file_get_contents($filePath); |
| 49 | |
| 50 | if ( ! empty($nested_xml) ) |
| 51 | { |
| 52 | PMXI_Import_Record::preprocessXml($nested_xml); |
| 53 | |
| 54 | if ( PMXI_Import_Record::validateXml($nested_xml) === true ){ |
| 55 | |
| 56 | $nestedDom = new DOMDocument('1.0', 'UTF-8'); |
| 57 | $nestedold = libxml_use_internal_errors(true); |
| 58 | $nestedDom->loadXML($nested_xml); |
| 59 | libxml_use_internal_errors($nestedold); |
| 60 | $second = $nestedDom->documentElement; |
| 61 | |
| 62 | if ($second->hasChildNodes()) { |
| 63 | |
| 64 | foreach($second->childNodes as $node) |
| 65 | { |
| 66 | $importNode = $this->dom->importNode($node, true); |
| 67 | $this->dom->documentElement->appendChild($importNode); |
| 68 | } |
| 69 | |
| 70 | $this->xml = ($this->elements) ? $this->dom->saveXML($this->elements->item(0)) : $this->dom->saveXML(); |
| 71 | } |
| 72 | unset($nestedDom); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | foreach ($tmp_files as $tmp_file) { // remove all temporary files created |
| 78 | @unlink($tmp_file); |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | public function get_xml(){ |
| 84 | return $this->xml; |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | } |