XmlStreamReader
2 years ago
partner-discount-sdk
1 year ago
api.php
4 years ago
arraytoxml.php
8 years ago
chunk.php
1 year ago
config.php
2 years ago
download.php
13 years ago
error.php
2 years ago
handler.php
9 months ago
helper.php
8 years ago
input.php
7 years ago
nested.php
4 years ago
rapidaddon.php
9 months ago
render.php
4 years ago
session.php
9 months ago
upload.php
9 months ago
zip.php
10 years ago
nested.php
89 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 | $factory = XmlImportParser::factory($this->xml, $this->xpath, $nfile, $tmp_file)->parse(); |
| 27 | $nested_fileURL = array_shift($factory); $tmp_files[] = $tmp_file; |
| 28 | if ( ! empty($nested_fileURL) ){ |
| 29 | $errors = new WP_Error(); |
| 30 | |
| 31 | $uploader = new PMXI_Upload($nested_fileURL, $errors); |
| 32 | $upload_result = $uploader->url(); |
| 33 | |
| 34 | if ($upload_result instanceof WP_Error){ |
| 35 | $errors = $upload_result; |
| 36 | } |
| 37 | else{ |
| 38 | $source = $upload_result['source']; |
| 39 | $filePath = $upload_result['filePath']; |
| 40 | if ( ! empty($upload_result['root_element'])) |
| 41 | $root_element = $upload_result['root_element']; |
| 42 | else |
| 43 | $root_element = ''; |
| 44 | $feed_type = $upload_result['feed_type']; |
| 45 | } |
| 46 | |
| 47 | unset($uploader); |
| 48 | |
| 49 | $nested_xml = file_get_contents($filePath); |
| 50 | |
| 51 | if ( ! empty($nested_xml) ) |
| 52 | { |
| 53 | PMXI_Import_Record::preprocessXml($nested_xml); |
| 54 | |
| 55 | if ( PMXI_Import_Record::validateXml($nested_xml) === true ){ |
| 56 | |
| 57 | $nestedDom = new DOMDocument('1.0', 'UTF-8'); |
| 58 | $nestedold = libxml_use_internal_errors(true); |
| 59 | $nestedDom->loadXML($nested_xml); |
| 60 | libxml_use_internal_errors($nestedold); |
| 61 | $second = $nestedDom->documentElement; |
| 62 | |
| 63 | if ($second->hasChildNodes()) { |
| 64 | |
| 65 | foreach($second->childNodes as $node) |
| 66 | { |
| 67 | $importNode = $this->dom->importNode($node, true); |
| 68 | $this->dom->documentElement->appendChild($importNode); |
| 69 | } |
| 70 | |
| 71 | $this->xml = ($this->elements) ? $this->dom->saveXML($this->elements->item(0)) : $this->dom->saveXML(); |
| 72 | } |
| 73 | unset($nestedDom); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | foreach ($tmp_files as $tmp_file) { // remove all temporary files created |
| 79 | @unlink($tmp_file); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | public function get_xml(){ |
| 85 | return $this->xml; |
| 86 | } |
| 87 | |
| 88 | } |
| 89 | } |