Test whether an <xsl:copy-of/> node is safe

@param  DOMElement $node <xsl:copy-of/> node
@param  Tag        $tag  Reference tag
@return void
184480
protected function checkCopyOfNode(DOMElement $node, Tag $tag)
	{
		$this->checkSelectNode($node->getAttributeNode('select'), $tag);
	}
1234562
public static function remove_node($node) {
		if (
			! \is_a($node, 'DOMElement') &&
			! \is_a($node, 'DOMNode')
		) {
			return false;
		}

		$node->parentNode->removeChild($node);

		return true;
	}
893533
protected function isAncestor($tagname) {
        $candidate = $this->current;
        while ($candidate->nodeType === XML_ELEMENT_NODE) {
            if ($candidate->tagName == $tagname) {
                return true;
            }
            $candidate = $candidate->parentNode;
        }

        return false;
    }
551360
protected function checkContext(DOMNode $node)
	{
		// Test whether we know in what context this node is used. An <xsl:for-each/> ancestor would // change this node's context
		$xpath     = new DOMXPath($node->ownerDocument);
		$ancestors = $xpath->query('ancestor::xsl:for-each', $node);

		if ($ancestors->length)
		{
			throw new UnsafeTemplateException("Cannot assess context due to '" . $ancestors->item(0)->nodeName . "'", $node);
		}
	}
383178
public function check(DOMElement $template, Tag $tag)
	{
		$this->template = $template;
		$this->checkEmbeds();
		$this->checkObjects();
	}
1144424
protected function isEqualTag(DOMElement $el1, DOMElement $el2)
	{
		return ($el1->namespaceURI === $el2->namespaceURI && $el1->nodeName === $el2->nodeName && $this->getAttributes($el1) === $this->getAttributes($el2));
	}
1230508
public function check(DOMElement $template, Tag $tag)
	{
		$nodes = $template->getElementsByTagNameNS(self::XMLNS_XSL, 'copy');
		$node  = $nodes->item(0);

		if ($node)
		{
			throw new UnsafeTemplateException("Cannot assess the safety of an '" . $node->nodeName . "' element", $node);
		}
	}
708071
protected function registerNode(\DOMNode $node)
    {
        if ($node->nodeType == XML_ELEMENT_NODE) {
            /** @var \DOMElement $node */
            $localContext = $this->elementProcessor->processElement($node, $this->initialContext);

            // Register the node context
            $localContextId = spl_object_hash($localContext);
            if (empty($this->contexts[$localContextId])) {
                $this->contexts[$localContextId] = $localContext;
            }

            $this->contextMap[$node->getNodePath()] = $localContextId;
        }

        return $node;
    }
197979
private function addNewNotEmptyXmlElement(DOMDocument $dom, DOMElement $node, $name, $value)
    {
        if (!empty($value)) {
            $this->addNewXmlElement($dom, $node, $name, $value);
        }
    }
427719
private function canResetForm(\DOMElement $node)
    {
        $type = $node->hasAttribute('type') ? $node->getAttribute('type') : null;

        return in_array($node->nodeName, array('input', 'button'), true) && 'reset' === $type;
    }
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);
		}
	}
26159
private function protectTags(HtmlDomParser $dom): HtmlDomParser
    {
        // init
        $counter = 0;

        foreach ($dom->find('script, style') as $element) {

            // skip external links
            if ($element->tag === 'script' || $element->tag === 'style') {
                $attributes = $element->getAllAttributes();
                if (isset($attributes['src'])) {
                    continue;
                }
            }

            $this->protectedChildNodes[$counter] = $element->text();
            $element->getNode()->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>';

            ++$counter;
        }

        foreach ($dom->find('code, nocompress') as $element) {
            if ($element->isRemoved()) {
                continue;
            }

            $this->protectedChildNodes[$counter] = $element->parentNode()->innerHtml();
            $element->getNode()->parentNode->nodeValue = '<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>';

            ++$counter;
        }

        foreach ($dom->find('//comment()') as $element) {
            $text = $element->text();

            // skip normal comments
            if (!$this->isConditionalComment($text)) {
                continue;
            }

            $this->protectedChildNodes[$counter] = '<!--' . $text . '-->';

            /* @var $node \DOMComment */
            $node = $element->getNode();
            $child = new \DOMText('<' . $this->protectedChildNodesHelper . ' data-' . $this->protectedChildNodesHelper . '="' . $counter . '"></' . $this->protectedChildNodesHelper . '>');
            /** @noinspection UnusedFunctionResultInspection */
            $element->getNode()->parentNode->replaceChild($child, $node);

            ++$counter;
        }

        return $dom;
    }
253712
public function hasTag(Tag $tag)
    {
        foreach ($this->_tags as $knownTag) {
            if ($knownTag->getId() == $tag->getId()) {
                return true;
            }
        }

        return false;
    }
465442
public function setProperty(NodeInterface $node, \DOMElement $element) : void
    {
        $node->setTitle($element->nodeValue);
    }
326177
public function check(DOMElement $template, Tag $tag)
	{
		foreach ($this->getNodes($template) as $node)
		{
			// Test this node's safety
			$this->checkNode($node, $tag);
		}
	}
606841
protected function checkTag(array $rule, AbstractNode $node): bool
    {
        if ( ! empty($rule['tag']) && $rule['tag'] != $node->getTag()->name() &&
            $rule['tag'] != '*'
        ) {
            return false;
        }

        return true;
    }
990708
public static function copyElement(DOMElement $element, DOMElement $parent = null) : DOMElement
    {
        if ($parent === null) {
            $document = DOMDocumentFactory::create();
        } else {
            $document = $parent->ownerDocument;
        }

        $namespaces = [];
        for ($e = $element; $e instanceof DOMNode; $e = $e->parentNode) {
            foreach (Utils::xpQuery($e, './namespace::*') as $ns) {
                $prefix = $ns->localName;
                if ($prefix === 'xml' || $prefix === 'xmlns') {
                    continue;
                }
                $uri = $ns->nodeValue;
                if (!isset($namespaces[$prefix])) {
                    $namespaces[$prefix] = $uri;
                }
            }
        }

        /** @var \DOMElement $newElement */
        $newElement = $document->importNode($element, true);
        if ($parent !== null) {
            /* We need to append the child to the parent before we add the namespaces. */
            $parent->appendChild($newElement);
        }

        foreach ($namespaces as $prefix => $uri) {
            $newElement->setAttributeNS($uri, $prefix.':__ns_workaround__', 'tmp');
            $newElement->removeAttributeNS($uri, '__ns_workaround__');
        }

        return $newElement;
    }