Retrieve proper node name

@param \DOMNode $node The configuration XML node to parse

@return string
12660
protected function parseNodeName($node)
    {
        $nodeName = $node->nodeName;
        if ($node->hasAttributes()) {
            $storeCodeNode     = $node->attributes->getNamedItem('store_code');
            $containerNameNode = $node->attributes->getNamedItem('name');
            if ($containerNameNode) {
                $nodeName = $containerNameNode->nodeValue;
                if ($storeCodeNode) {
                    $nodeName = $nodeName . "|" . $storeCodeNode->nodeValue;
                }
            }
        }

        return $nodeName;
    }
397916
public static function getChildNodesOfName(\DOMElement $element, $elementName) {
    $result = [];
    foreach ($element->childNodes as $child) {
      if ($child->nodeName == $elementName) {
        $result[] = $child;
      }
    }
    return $result;
  }
232635
public static function get_block_parent( \DOMNode $node ) {
		$parent = $node->parentNode;
		if ( ! $parent instanceof \DOMElement ) {
			return null;
		}

		while ( ! self::is_block_tag( $parent ) && $parent->parentNode instanceof \DOMElement ) {
			/**
			 * The parent is sure to be a \DOMElement.
			 *
			 * @var \DOMElement
			 */
			$parent = $parent->parentNode;
		}

		return $parent;
	}
331414
public static function getElementsByTagName($node, $tagName)
    {
        $ret = array();
        $nodes = $node->getElementsByTagName($tagName);
        foreach ($nodes as $node) {
            if ($node instanceof DOMElement) {
                array_push($ret, $node);
            }
        }
        return $ret;
    }
154814
protected function convertDom(\DOMNode $node)
    {
        $isArray = false;
        $current = array();
        $text = '';

        if ($node instanceof \DOMElement) {
            foreach ($node->attributes as $name => $attribute) {
                $current["_{$name}"] = $attribute->value;
            }
        }

        $parentTagName = $node instanceof \DOMElement ? $node->tagName : false;
        foreach ($node->childNodes as $childNode) {
            switch ($childNode->nodeType) {
                case XML_ELEMENT_NODE:
                    $tagName = $childNode->tagName;

                    if (in_array($tagName, $this->fieldTypeHashElements)) {
                        $current[$tagName] = $this->parseFieldTypeHash($childNode);
                    } elseif (!isset($current[$tagName])) {
                        if (isset($this->forceList[$parentTagName]) &&
                             in_array($tagName, $this->forceList[$parentTagName], true)) {
                            $isArray = true;
                            $current[$tagName] = array(
                                $this->convertDom($childNode),
                            );
                        } else {
                            $current[$tagName] = $this->convertDom($childNode);
                        }
                    } elseif (!$isArray) {
                        $current[$tagName] = array(
                            $current[$tagName],
                            $this->convertDom($childNode),
                        );
                        $isArray = true;
                    } else {
                        $current[$tagName][] = $this->convertDom($childNode);
                    }

                    break;

                case XML_TEXT_NODE:
                    $text .= $childNode->wholeText;
                    break;

                case XML_CDATA_SECTION_NODE:
                    $text .= $childNode->data;
                    break;
            }
        }

        $text = trim($text);

        if ($text !== '' && count($current)) {
            $current['#text'] = $text;
        } elseif ($text !== '') {
            $current = $text;
        } elseif (!count($current)) {
            return null;
        }

        return $current;
    }
377051
private function getNodeAttributes( $domNode )
	{
		$attributes	= array();
		foreach( $domNode->attributes as $attribute )
			$attributes[$attribute->name]	= $attribute->value;
		return $attributes;
	}
43916
protected function getValue(DOMNode $node)
    {
      // Init value
      $value = null;

      if(is_numeric($node->nodeValue))
        $value = $node->nodeValue;
      elseif(is_string($node->nodeValue))
        $value = utf8_decode($node->nodeValue);

      return $value;
    }
1268919
protected function valueOf(DOMNode $node)
	{
		switch ($node->nodeName)
		{
			case 'input':

				switch ($node->getAttribute('type'))
				{
					case 'checkbox':
						return $node->getAttribute('checked') ? $node->getAttribute('value') : false;
						break;

					default:
						return $node->getAttribute('value');
				}

			break;
		}
		return null;
	}
610156
private function ensureNodeClass(DOMNode $node)
    {
        $class = $this->nodeClasses['DOMElement'];

        if (true !== ($node instanceof $class) && $node instanceof \DOMElement) {
            return $node->ownerDocument->importNode($node, true);
        }

        return $node;
    }
37589
protected function nextTagName($node)
    {
        $nextNode = $node->nextSibling;
        while ($nextNode != null) {
            if ($nextNode instanceof DOMElement) {
                break;
            }
            $nextNode = $nextNode->nextSibling;
        }
        $nextTag = '';
        if ($nextNode instanceof DOMElement && $nextNode != null) {
            $nextTag = strtolower($nextNode->nodeName);
        }

        return $nextTag;
    }
1327163
private function getNodes($node)
    {
        $this->logger->info('[Get Nodes] Retrieving nodes...');

        $stripUnlikelyCandidates = $this->configuration->getStripUnlikelyCandidates();

        $elementsToScore = [];

        /*
         * First, node prepping. Trash nodes that look cruddy (like ones with the
         * class name "comment", etc), and turn divs into P tags where they have been
         * used inappropriately (as in, where they contain no other block level elements.)
         */

        while ($node) {
            // Remove DOMComments nodes as we don't need them and mess up children counting
            if ($node->nodeType === XML_COMMENT_NODE) {
                $this->logger->debug(sprintf('[Get Nodes] Found comment node, removing... Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            $matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id');

            if (!$node->isProbablyVisible()) {
                $this->logger->debug(sprintf('[Get Nodes] Removing hidden node... Match string was: \'%s\'', $matchString));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            // Check to see if this node is a byline, and remove it if it is.
            if ($this->checkByline($node, $matchString)) {
                $this->logger->debug(sprintf('[Get Nodes] Found byline, removing... Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            // Remove unlikely candidates
            if ($stripUnlikelyCandidates) {
                if (
                    preg_match(NodeUtility::$regexps['unlikelyCandidates'], $matchString) &&
                    !preg_match(NodeUtility::$regexps['okMaybeItsACandidate'], $matchString) &&
                    $node->nodeName !== 'body' &&
                    $node->nodeName !== 'a'
                ) {
                    $this->logger->debug(sprintf('[Get Nodes] Removing unlikely candidate. Node content was: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $node = NodeUtility::removeAndGetNext($node);
                    continue;
                }
            }

            // Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe).
            if (($node->nodeName === 'div' || $node->nodeName === 'section' || $node->nodeName === 'header' ||
                    $node->nodeName === 'h1' || $node->nodeName === 'h2' || $node->nodeName === 'h3' ||
                    $node->nodeName === 'h4' || $node->nodeName === 'h5' || $node->nodeName === 'h6' ||
                    $node->nodeName === 'p') &&
                $node->isElementWithoutContent()) {
                $this->logger->debug(sprintf('[Get Nodes] Removing empty \'%s\' node.', $node->nodeName));
                $node = NodeUtility::removeAndGetNext($node);
                continue;
            }

            if (in_array(strtolower($node->nodeName), $this->defaultTagsToScore)) {
                $this->logger->debug(sprintf('[Get Nodes] Adding node to score list, node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                $elementsToScore[] = $node;
            }

            // Turn all divs that don't have children block level elements into p's
            if ($node->nodeName === 'div') {
                // Put phrasing content into paragraphs.
                $p = null;
                $childNode = $node->firstChild;
                while ($childNode) {
                    $nextSibling = $childNode->nextSibling;
                    if ($childNode->isPhrasingContent()) {
                        if ($p !== null) {
                            $p->appendChild($childNode);
                        } elseif (!$childNode->isWhitespace()) {
                            $p = $this->dom->createElement('p');
                            $node->replaceChild($p, $childNode);
                            $p->appendChild($childNode);
                        }
                    } elseif ($p !== null) {
                        while ($p->lastChild && $p->lastChild->isWhitespace()) {
                            $p->removeChild($p->lastChild);
                        }
                        $p = null;
                    }
                    $childNode = $nextSibling;
                }

                /*
                 * Sites like http://mobile.slate.com encloses each paragraph with a DIV
                 * element. DIVs with only a P element inside and no text content can be
                 * safely converted into plain P elements to avoid confusing the scoring
                 * algorithm with DIVs with are, in practice, paragraphs.
                 */
                if ($node->hasSingleTagInsideElement('p') && $node->getLinkDensity() < 0.25) {
                    $this->logger->debug(sprintf('[Get Nodes] Found DIV with a single P node, removing DIV. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $pNode = $node->getChildren(true)[0];
                    $node->parentNode->replaceChild($pNode, $node);
                    $node = $pNode;
                    $elementsToScore[] = $node;
                } elseif (!$node->hasSingleChildBlockElement()) {
                    $this->logger->debug(sprintf('[Get Nodes] Found DIV with a single child block element, converting to a P node. Node content is: \'%s\'', substr($node->nodeValue, 0, 128)));
                    $node = NodeUtility::setNodeTag($node, 'p');
                    $elementsToScore[] = $node;
                }
            }

            $node = NodeUtility::getNextNode($node);
        }

        return $elementsToScore;
    }
1345820
public function getTypeForDOMNode( $node )
	{
		$ns = $node->namespaceURI;
		if ( ! $ns )
		{
			if ( $node instanceof \DOMElement )
			{
				// Get the default namespace for the DOMNode
				$doc = $node->ownerDocument;
				/**
				 * @var DOMNode $firstChild
				 */
				$firstChild = $doc->documentElement;
				$ns = $firstChild->getAttributeNode('xmlns')
					? $firstChild->getAttributeNode('xmlns')->nodeValue
					: "";
			}
			else if ( $node instanceof \DOMAttr )
			{
				$parent = $node->parentNode;
				if ( $parent )
				{
					$ns = $parent->namespaceURI;
				}
			}
		}

		$prefix = $this->getPrefixForNamespace( $ns );
		$types;

		if ( is_a( $node, "DOMElement" ) )
		{
			$el = $this->getElement( $node->localName, $prefix );
			if ( $el === false ) throw new SchemaException( "Unable to locate element '{$node->localName}' in the schema types" );
			$types = isset( $el['types'] ) ? $el['types'] : array();
		}
		else if ( is_a( $node, "DOMAttr" ) )
		{
			$attr = $this->getAttribute( $node->localName, $prefix );
			if ( $attr === false ) throw new SchemaException( "Unable to locate attribute '{$node->localName}' in the schema types" );
			$types = isset( $attr['types'] ) ? $attr['types'] : array();
		}
		else if ( is_a( $node, "DOMDocument" ) )
		{
			throw new SchemaException("Getting the type for a Document node is not supported");
		}
		else if ( is_a( $node, "DOMComment" ) )
		{
			// BMS 2018-04-09 Test candidates changed.
			return "xs:string";
		}
		else if ( is_a( $node, "DOMProcessingInstruction" ) )
		{
			throw new SchemaException("Getting the type for a Processing Instruction node is not supported");
		}
		else if ( is_a( $node, "DOMText" ) )
		{
			// BMS 2018-04-09 Test candidates changed.
			return "xs:string";
		}
		else if ( is_a( $node, "DOMNameSpaceNode" ) )
		{
			throw new SchemaException("Getting the type for a Namespace node is not supported");
		}

		// Get the first simple type
		$type = null;
		foreach ( $types as $xmlType )
		{
			if ( is_array( $xmlType ) )
			{
				if ( isset( $xmlType['class'] ) && $xmlType['class'] == "complex" )
				{
					continue;
				}

				if ( isset( $xmlType['contentType'] ) && $xmlType['contentType'] == "extension" && isset( $xmlType['base'] ) )
				{
					return $xmlType['parent'];
				}

				if ( isset( $xmlType['contentType'] ) && $xmlType['contentType'] == "restriction" && isset( $xmlType['base'] ) )
				{
					return $xmlType['parent'];
				}
			}

			return $xmlType;
		}

		return false;
	}
709949
protected function normalizeNode(DOMNode $node)
	{
		if (!$node->parentNode)
		{
			// Ignore nodes that have been removed from the document
			return;
		}
		if ($node instanceof DOMElement)
		{
			$this->normalizeElement($node);
		}
		elseif ($node instanceof DOMAttr)
		{
			$this->normalizeAttribute($node);
		}
	}
466917
protected static function getInnerHTML($node) {
		if(!$node)
			return null;
		$innerHTML= ''; 
		$children = $node->childNodes; 
		foreach ($children as $child)
			$innerHTML .= $child->ownerDocument->saveHTML($child);
		return $innerHTML; 
	}
28762
public static function getNodePath($node)
    {
        $result = '';
        if ($node instanceof static) {
            $result = $node->slug;
            if (!empty($node->parent_id)) {
                $parent = static::node($node->parent_id);
                if (!empty($parent)) {
                    $result = static::getNodePath($parent) . '/' . $result;
                }
            }
        }
        return $result;
    }
732937
public function saveHTML(\DOMNode $node = null): string
    {
        if (!$this->loaded) {
            return '<!DOCTYPE html>';
        }

        $nodeMode = $node !== null;
        if ($nodeMode && $node instanceof \DOMDocument) {
            $nodeMode = false;
        }

        if ($nodeMode) {
            if (!isset(self::$newObjectsCache['html5domdocument'])) {
                self::$newObjectsCache['html5domdocument'] = new HTML5DOMDocument();
            }
            $tempDomDocument = clone(self::$newObjectsCache['html5domdocument']);
            if ($node->nodeName === 'html') {
                $tempDomDocument->loadHTML('<!DOCTYPE html>');
                $tempDomDocument->appendChild($tempDomDocument->importNode(clone($node), true));
                $html = $tempDomDocument->saveHTML();
                $html = substr($html, 16); // remove the DOCTYPE + the new line after
            } elseif ($node->nodeName === 'head' || $node->nodeName === 'body') {
                $tempDomDocument->loadHTML("<!DOCTYPE html>\n<html></html>");
                $tempDomDocument->childNodes[1]->appendChild($tempDomDocument->importNode(clone($node), true));
                $html = $tempDomDocument->saveHTML();
                $html = substr($html, 22, -7); // remove the DOCTYPE + the new line after + html tag
            } else {
                $isInHead = false;
                $parentNode = $node;
                for ($i = 0; $i < 1000; $i++) {
                    $parentNode = $parentNode->parentNode;
                    if ($parentNode === null) {
                        break;
                    }
                    if ($parentNode->nodeName === 'body') {
                        break;
                    } elseif ($parentNode->nodeName === 'head') {
                        $isInHead = true;
                        break;
                    }
                }
                $tempDomDocument->loadHTML("<!DOCTYPE html>\n<html>" . ($isInHead ? '<head></head>' : '<body></body>') . '</html>');
                $tempDomDocument->childNodes[1]->childNodes[0]->appendChild($tempDomDocument->importNode(clone($node), true));
                $html = $tempDomDocument->saveHTML();
                $html = substr($html, 28, -14); // remove the DOCTYPE + the new line + html + body or head tags
            }
            $html = trim($html);
        } else {
            $removeHtmlElement = false;
            $removeHeadElement = false;
            $headElement = $this->getElementsByTagName('head')->item(0);
            if ($headElement === null) {
                if ($this->addHtmlElementIfMissing()) {
                    $removeHtmlElement = true;
                }
                if ($this->addHeadElementIfMissing()) {
                    $removeHeadElement = true;
                }
                $headElement = $this->getElementsByTagName('head')->item(0);
            }
            $meta = $this->createElement('meta');
            $meta->setAttribute('data-html5-dom-document-internal-attribute', 'charset-meta');
            $meta->setAttribute('http-equiv', 'content-type');
            $meta->setAttribute('content', 'text/html; charset=utf-8');
            if ($headElement->firstChild !== null) {
                $headElement->insertBefore($meta, $headElement->firstChild);
            } else {
                $headElement->appendChild($meta);
            }
            $html = parent::saveHTML();
            $html = rtrim($html, "\n");

            if ($removeHeadElement) {
                $headElement->parentNode->removeChild($headElement);
            } else {
                $meta->parentNode->removeChild($meta);
            }

            if (strpos($html, 'html5-dom-document-internal-entity') !== false) {
                $html = preg_replace('/html5-dom-document-internal-entity1-(.*?)-end/', '&$1;', $html);
                $html = preg_replace('/html5-dom-document-internal-entity2-(.*?)-end/', '&#$1;', $html);
            }

            $codeToRemove = [
                'html5-dom-document-internal-content',
                '<meta data-html5-dom-document-internal-attribute="charset-meta" http-equiv="content-type" content="text/html; charset=utf-8">',
                '</area>', '</base>', '</br>', '</col>', '</command>', '</embed>', '</hr>', '</img>', '</input>', '</keygen>', '</link>', '</meta>', '</param>', '</source>', '</track>', '</wbr>'
            ];
            if ($removeHeadElement) {
                $codeToRemove[] = '<head></head>';
            }
            if ($removeHtmlElement) {
                $codeToRemove[] = '<html></html>';
            }

            $html = str_replace($codeToRemove, '', $html);
        }
        return $html;
    }
784206
protected function getCustomTagContent(DOMNode $node)
    {
        $xmlString = '';

        /** @var \DOMNode $child */
        foreach ($node->childNodes as $child) {
            $xmlString .= $node->ownerDocument->saveXML($child);
        }

        return $xmlString;
    }