nodeName; if ( ! $el->parentNode instanceof DOMDocument) { $path .= '[1]'; } $children = array(); foreach ($el->childNodes as $child) { if ($child instanceof DOMElement) { if ( ! empty($children[$child->nodeName])) { return $path . '/' . $child->nodeName; } else { $children[$child->nodeName] = true; } } } // reaching this point means we didn't find anything among current element children, so recursively ask children to find something in them foreach ($el->childNodes as $child) { if ($child instanceof DOMElement) { $result = slef::xml_find_repeating($child, $path . '/'); if ($result) { return $result; } } } // reaching this point means we didn't find anything, so return element itself if the function was called for it if ('/' . $el->nodeName == $path) { return $path; } return NULL; } public static function render_csv_element(DOMElement $el, $shorten = false, $path = '/', $ind = 1, $lvl = 0) { $path .= $el->nodeName; if ( ! $el->parentNode instanceof DOMDocument and $ind > 0) { $path .= "[$ind]"; } echo '
'; if ($el->hasChildNodes()) { $is_render_collapsed = $ind > 1; if ($lvl) echo '
' . $el->nodeName . ''; echo '
'; if (1 == $el->childNodes->length and $el->childNodes->item(0) instanceof DOMText) { $child = $el->childNodes->item(0); if (!empty($child->wholeText)){ self::render_csv_text(trim($child->wholeText), $shorten, $is_render_collapsed); } elseif (is_callable(array($child, 'nodeValue'), true) && isset($child->nodeValue)){ self::render_csv_text(trim($child->nodeValue), $shorten, $is_render_collapsed); } } else { echo '
'; $indexes = array(); foreach ($el->childNodes as $child) { if ($child instanceof DOMElement) { empty($indexes[$child->nodeName]) and $indexes[$child->nodeName] = 0; $indexes[$child->nodeName]++; self::render_csv_element($child, $shorten, $path . '/', $indexes[$child->nodeName], $lvl + 1); } elseif ($child instanceof DOMText) { self::render_csv_text(trim($child->wholeText), $shorten); } elseif ($child instanceof DOMComment) { if (preg_match('%\[pmxi_more:(\d+)\]%', $child->nodeValue, $mtch)) { $no = intval($mtch[1]); echo '
[ ⇓ ' . sprintf(__('%s %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' ⇓ ]
'; } } } echo '
'; } //echo '
' . $el->nodeName . '
'; } else { echo '
' . $el->nodeName . ''; self::render_xml_attributes($el); echo '
'; } echo '
'; } protected static function render_csv_text($text, $shorten = false, $is_render_collapsed = false) { if (empty($text) and 0 !== (int)$text) { return; // do not display empty text nodes } if (preg_match('%\[more:(\d+)\]%', $text, $mtch)) { $no = intval($mtch[1]); echo '
[ ⇓ ' . sprintf(__('%s %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' ⇓ ]
'; return; } $more = ''; if ($shorten and preg_match('%^(.*?\s+){20}(?=\S)%', $text, $mtch)) { $text = $mtch[0]; $more = '[' . __('more', 'wp_all_import_plugin') . ']'; } $is_short = strlen($text) <= 40; $newtext = htmlspecialchars($text); //$newtext = preg_replace('%(?' . $newtext . $more . ''; } public static $option_paths = array(); public static function render_xml_elements_for_filtring(DOMElement $el, $originPath ='', $lvl = 0){ $path = $originPath; if ("" != $path){ if ($lvl > 1) $path .= "->" . $el->nodeName; else $path = $el->nodeName; if (empty(self::$option_paths[$path])) self::$option_paths[$path] = 1; else self::$option_paths[$path]++; echo ''; } else $path = $el->nodeName; foreach ($el->attributes as $attr) { if (empty($originPath)){ echo ''; } else{ echo ''; } } if ($el->hasChildNodes()) { foreach ($el->childNodes as $child) { if ($child instanceof DOMElement) self::render_xml_elements_for_filtring($child, $path, $lvl + 1); } } } public static function render_xml_element(DOMElement $el, $shorten = false, $path = '/', $ind = 1, $lvl = 0) { $render_whole_tree = apply_filters('wp_all_import_is_render_whole_xml_tree', true); $path .= $el->nodeName; $alternativePath = $path; if ( ! $el->parentNode instanceof DOMDocument and $ind > 0) { $path .= "[$ind]"; } echo '
'; //if ($el->hasAttributes()){ echo '
'; self::render_element_xpaths($el, $alternativePath, $ind, $lvl); echo '
'; //} if ($el->hasChildNodes()) { $is_render_collapsed = $ind > 1; if ($el->childNodes->length > 1 or ! $el->childNodes->item(0) instanceof DOMText or strlen(trim($el->childNodes->item(0)->wholeText)) > 40) { echo '
' . ($is_render_collapsed ? '+' : '-') . '
'; } echo '
<' . $el->nodeName . ''; self::render_xml_attributes($el, $path . '/'); echo '>
'; if (1 == $el->childNodes->length and $el->childNodes->item(0) instanceof DOMText) { $item = $el->childNodes->item(0); if (!empty($item->wholeText)){ self::render_xml_text(trim($item->wholeText), $shorten, $is_render_collapsed); } else{ self::render_xml_text(trim($item->nodeValue), $shorten, $is_render_collapsed); } } else { echo '
'; $indexes = array(); foreach ($el->childNodes as $eli => $child) { if ($child instanceof DOMElement) { empty($indexes[$child->nodeName]) and $indexes[$child->nodeName] = 0; $indexes[$child->nodeName]++; if ( $render_whole_tree || $indexes[$child->nodeName] === 1){ self::render_xml_element($child, $shorten, $path . '/', $indexes[$child->nodeName], $lvl + 1); } } elseif ($child instanceof DOMCdataSection) { self::render_xml_text(trim($child->wholeText), $shorten, false, true); } elseif ($child instanceof DOMText) { if ( $el->childNodes->item($eli - 1) and ($el->childNodes->item($eli - 1) instanceof DOMCdataSection) ){ } elseif( $el->childNodes->item($eli + 1) and ($el->childNodes->item($eli + 1) instanceof DOMCdataSection) ){ } else{ self::render_xml_text(trim($child->wholeText), $shorten); } } elseif ($child instanceof DOMComment) { if (preg_match('%\[pmxi_more:(\d+)\]%', $child->nodeValue, $mtch)) { $no = intval($mtch[1]); echo '
[ ⇓ ' . sprintf(__('%s %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' ⇓ ]
'; } } } echo '
'; } echo '
</' . $el->nodeName . '>
'; } else { echo '
<' . $el->nodeName . ''; self::render_xml_attributes($el); echo '/>
'; } echo '
'; } protected static function render_xml_text($text, $shorten = false, $is_render_collapsed = false, $is_cdata = false) { if (empty($text) and 0 !== (int)$text) { return; // do not display empty text nodes } if (preg_match('%\[more:(\d+)\]%', $text, $mtch)) { $no = intval($mtch[1]); echo '
[ ⇓ ' . sprintf(__('%s %s more', 'wp_all_import_plugin'), $no, _n('element', 'elements', $no, 'wp_all_import_plugin')) . ' ⇓ ]
'; return; } $more = ''; if ($shorten and preg_match('%^(.*?\s+){20}(?=\S)%', $text, $mtch)) { $text = $mtch[0]; $more = '[' . __('more', 'wp_all_import_plugin') . ']'; } $is_short = strlen($text) <= 40; $text = htmlspecialchars($text); if ($is_cdata){ $text = "" . htmlspecialchars(" " . $text . " " . htmlspecialchars("]]>") . ""; } //$text = preg_replace('%(?' . $text . $more . ''; } public static function get_xml_path(DOMElement $el, DOMXPath $xpath) { for($p = '', $doc = $el; $doc and ! $doc instanceof DOMDocument; $doc = $doc->parentNode) { if (($ind = $xpath->query('preceding-sibling::' . $doc->nodeName, $doc)->length)) { $p = '[' . ++$ind . ']' . $p; } elseif ( ! $doc->parentNode instanceof DOMDocument) { $p = '[' . ($ind = 1) . ']' . $p; } $p = '/' . $doc->nodeName . $p; } return $p; } protected static function render_xml_attributes(DOMElement $el, $path = '/') { foreach ($el->attributes as $attr) { echo ' ' . $attr->nodeName . '="' . esc_attr($attr->value) . '"'; } } protected static function render_element_xpaths(DOMElement $el, $path = '/', $ind = 1, $lvl = 0){ ?>