Process embed tags for a single tag type (embed or embed-inline).

@param \DOMDocument $xmlDoc
@param $tagName string name of the tag to extract
9037
protected function processTag(DOMDocument $xmlDoc, $tagName)
    {
        /** @var $embed \DOMElement */
        foreach ($xmlDoc->getElementsByTagName($tagName) as $embed) {
            if (!$view = $embed->getAttribute('view')) {
                $view = $tagName;
            }

            $embedContent = null;
            $parameters = $this->getParameters($embed);

            if ($contentId = $embed->getAttribute('object_id')) {
                try {
                    /** @var \eZ\Publish\API\Repository\Values\Content\Content $content */
                    $content = $this->repository->sudo(
                        static function (Repository $repository) use ($contentId) {
                            return $repository->getContentService()->loadContent($contentId);
                        }
                    );

                    if (
                        !$this->repository->canUser('content', 'read', $content)
                        && !$this->repository->canUser('content', 'view_embed', $content)
                    ) {
                        throw new UnauthorizedException('content', 'read', ['contentId' => $contentId]);
                    }

                    // Check published status of the Content
                    if (
                        $content->getVersionInfo()->status !== APIVersionInfo::STATUS_PUBLISHED
                        && !$this->repository->canUser('content', 'versionread', $content)
                    ) {
                        throw new UnauthorizedException('content', 'versionread', ['contentId' => $contentId]);
                    }

                    $embedContent = $this->fragmentHandler->render(
                        new ControllerReference(
                            'ez_content:embedAction',
                            [
                                'contentId' => $contentId,
                                'viewType' => $view,
                                'layout' => false,
                                'params' => $parameters,
                            ]
                        )
                    );
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->error(
                            'While generating embed for xmltext, could not locate ' .
                            'Content object with ID ' . $contentId
                        );
                    }
                }
            } elseif ($locationId = $embed->getAttribute('node_id')) {
                try {
                    /** @var \eZ\Publish\API\Repository\Values\Content\Location $location */
                    $location = $this->repository->sudo(
                        static function (Repository $repository) use ($locationId) {
                            return $repository->getLocationService()->loadLocation($locationId);
                        }
                    );

                    if (
                        !$this->repository->canUser('content', 'read', $location->getContentInfo(), $location)
                        && !$this->repository->canUser('content', 'view_embed', $location->getContentInfo(), $location)
                    ) {
                        throw new UnauthorizedException('content', 'read', ['locationId' => $location->id]);
                    }

                    $embedContent = $this->fragmentHandler->render(
                        new ControllerReference(
                            'ez_content:embedAction',
                            [
                                'contentId' => $location->getContentInfo()->id,
                                'locationId' => $location->id,
                                'viewType' => $view,
                                'layout' => false,
                                'params' => $parameters,
                            ]
                        )
                    );
                } catch (APINotFoundException $e) {
                    if ($this->logger) {
                        $this->logger->error(
                            'While generating embed for xmltext, could not locate ' .
                            'Location with ID ' . $locationId
                        );
                    }
                }
            }

            if ($embedContent === null) {
                // Remove empty embed
                $embed->parentNode->removeChild($embed);
            } else {
                while ($embed->hasChildNodes()) {
                    $embed->removeChild($embed->firstChild);
                }
                $embed->appendChild($xmlDoc->createCDATASection($embedContent));
            }
        }
    }
115972
public function check(DOMElement $template, Tag $tag)
	{
		$xpath = new DOMXPath($template->ownerDocument);

		foreach ($xpath->query($this->query) as $node)
		{
			throw new UnsafeTemplateException("Node '" . $node->nodeName . "' is disallowed because it matches '" . $this->query . "'", $node);
		}
	}
932635
public function check(DOMElement $template, Tag $tag)
	{
		// Regexp that matches the function call
		$regexp = '#(?!<\\pL)' . preg_quote($this->funcName, '#') . '\\s*\\(#iu';

		// Allow whitespace around colons (NOTE: colons are unnecessarily escaped by preg_quote())
		$regexp = str_replace('\\:', '\\s*:\\s*', $regexp);

		foreach ($this->getExpressions($template) as $expr => $node)
		{
			// Remove string literals from the expression
			$expr = preg_replace('#([\'"]).*?\\1#s', '', $expr);

			// Test whether the expression contains a document() call
			if (preg_match($regexp, $expr))
			{
				throw new UnsafeTemplateException('An XPath expression uses the ' . $this->funcName . '() function', $node);
			}
		}
	}
286602
protected function getNodeValueByTagName(DOMElement $node, $tagName)
    {
        $results = $node->getElementsByTagName($tagName);
        for ($i = 0; $i < $results->length; $i++) {
            $result = $results->item($i);
            if (!$result->nodeValue) {
                continue;
            }

            return $result->nodeValue;
        }

        return false;
    }
526998
public function parseXmlTag($tagLib,$tag,$attr,$content) {
        if(ini_get('magic_quotes_sybase'))
            $attr   =   str_replace('\"','\'',$attr);
        $parse      =   '_'.$tag;
        $content    =   trim($content);
        $tags       =   $tagLib->parseXmlAttr($attr,$tag);
        return $tagLib->$parse($tags,$content);
    }
409037
public function writeXml($filename)
    {
        $dom           = new DOMImplementation;
        $dtd           = $dom->createDocumentType('entity', '', $this->entityDtd);
        $xml           = $dom->createDocument('', '', $dtd);
        $xml->encoding = 'UTF-8';

        $root = $this->createRootElement($xml);
        $root->appendChild($this->createStorageElement($xml));
        $root->appendChild($this->createFieldsElement($xml));
        $root->appendChild($this->createRelationsElement($xml));

        $xml->formatOutput = true;
        $xml->save($filename);
    }
1317066
public function setupAndGetTitle($xmlDoc){
     //var_dump($xmlDoc->saveXML());
     $channel=$xmlDoc->getElementsByTagName('feed')->item(0);
     //var_dump($channel);
     $channel_title = $channel->getElementsByTagName('title')
     ->item(0)->childNodes->item(0)->nodeValue;
     return ($channel_title);
   }
1203707
public static function get($node, $tagName, $count = 1) {
        $node = $node->{$tagName};
        if ($node->count() !== $count)
            throw new XmlParserException("xml does not have exactly $count $tagName's");
        return $node[0];
    }
1315618
public function process(\DOMDocument $xml)
    {
        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query('//tag[@name=\'covers\']');

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            $refers = $node->getAttribute('refers');
            $refers_array = explode('::', $refers);

            // determine the type so we know where to put the @coveredby tag on
            $type = 'class';
            if (isset($refers_array[1])) {
                // starts with $ = property, ends with () = method,
                // otherwise constant
                $type = $refers_array[1][0] == '$' ? 'property' : 'constant';
                $type = substr($refers_array[1], -2) == '()' ? 'method' : $type;
            }

            switch ($type) {
                case 'class':
                    // escape single quotes in the class name
                    $xpath_refers = 'concat(\''.str_replace(
                        array("'", '"'),
                        array('\', "\'", \'', '\', \'"\' , \''),
                        $refers
                    ) . "', '')";

                    $qry = '/project/file/class[full_name=' . $xpath_refers . ']';
                    break;
                default:
                    $class_name = $refers_array[0];

                    // escape single quotes in the class name
                    $xpath_class_name = 'concat(\''.str_replace(
                        array("'", '"'),
                        array('\', "\'", \'', '\', \'"\' , \''),
                        $class_name
                    ) . "', '')";

                    // escape single quotes in the method name
                    $xpath_method_name = 'concat(\''.str_replace(
                        array("'", '"'),
                        array('\', "\'", \'', '\', \'"\' , \''),
                        rtrim($refers_array[1], '()')
                    ) . "', '')";

                    $qry = '/project/file/class[full_name=' . $xpath_class_name
                        . ']/'.$type.'[name=' . $xpath_method_name .']';
                    break;
            }

            /** @noinspection PhpUsageOfSilenceOperatorInspection as there is no pre-validation possible */
            $referral_nodes = @$xpath->query($qry);

            // if the query is wrong; output a Critical error and continue to
            // the next @covers
            if ($referral_nodes === false) {
                // $this->log(
                //    'An XPath error occurs while processing @covers, the query used was: ' . $qry,
                //    LogLevel::CRITICAL
                // );
                continue;
            }

            // check if the result is unique; if not we error and continue
            // to the next @covers
            if ($referral_nodes->length > 1) {
                continue;
            }

            // if there is one matching element; link them together
            if ($referral_nodes->length > 0) {
                /** @var \DOMElement $referral  */
                $referral = $referral_nodes->item(0);
                $docblock = $referral->getElementsByTagName('docblock');
                if ($docblock->length < 1) {
                    $docblock = new \DOMElement('docblock');
                    $referral->appendChild($docblock);
                } else {
                    $docblock = $docblock->item(0);
                }

                $used_by = new \DOMElement('tag');
                $docblock->appendChild($used_by);
                $used_by->setAttribute('name', 'used_by');
                $used_by->setAttribute('line', '');

                // gather the name of the referring element and set that as refers
                // attribute
                if ($node->parentNode->parentNode->nodeName == 'class') {
                    // if the element where the @covers is in is a class; nothing
                    // more than the class name need to returned
                    $referral_name = $node->parentNode->parentNode
                        ->getElementsByTagName('full_name')->item(0)->nodeValue;
                } else {

                    $referral_class_name = null;
                    if ($node->parentNode->parentNode->nodeName == 'method') {
                        // gather the name of the class where the @covers is in
                        $referral_class_name = $node->parentNode->parentNode
                            ->parentNode->getElementsByTagName('full_name')->item(0)
                            ->nodeValue;
                    }

                    // gather the name of the subelement of the class where
                    // the @covers is in
                    $referral_name = $node->parentNode->parentNode
                        ->getElementsByTagName('name')->item(0)->nodeValue;

                    // if it is a method; suffix with ()
                    if ($node->parentNode->parentNode->nodeName == 'method'
                        || $node->parentNode->parentNode->nodeName == 'function'
                    ) {
                        $referral_name .= '()';
                    }

                    // only prefix class name if this is a class member
                    if ($referral_class_name) {
                        $referral_name = $referral_class_name . '::'
                            . $referral_name;
                    }
                }

                $used_by->setAttribute('description', $referral_name);
                $used_by->setAttribute('refers', $referral_name);
            }
        }

        return $xml;
    }
336070
private function importXml(\DOMDocument $doc)
    {
        $importNodes=$doc->getElementsByTagName("import");
        for($i=$importNodes->length-1;$i>=0;$i--){
            $node = $importNodes->item($i);
            if($node->hasAttribute("file")){
                $file=$node->getAttribute("file");
                $path=rtrim(dirname($this->m_configFile),"/");
                $file=$path."/".ltrim($file,"/");
                if(file_exists($file)){
                    $_doc=new \DOMDocument();
                    $_doc->load($file);
                    $this->importXml($_doc);
                    $children=$_doc->documentElement->childNodes;
                    for($j=0;$j<$children->length;$j++){
                        $_node=$children->item($j);
                        if(is_a($_node,"DOMElement")){
                            $_node = $doc->importNode($_node, true);
                            $node->parentNode->insertBefore($_node,$node);
                        }
                    }
                    if(!in_array($file, $this->m_configFiles)){
                        $this->m_configFiles[]=$file;
                    }
                }
            }
            $node->parentNode->removeChild($node);
        }
    }
390101
public function toXML(DOMDocument $doc, $nodeName = "")
    {
        $node = $doc->createElement('array');

        foreach ($this->value as $value) {
            $node->appendChild($value->toXML($doc));
        }
        return $node;
    }
957800
public function convert(DOMDocument $xmlDoc)
    {
        foreach ($this->getPreConverters() as $preConverter) {
            $preConverter->convert($xmlDoc);
        }

        $xsl = $this->getXSLTProcessor();

        return $xsl->transformToXML($xmlDoc);
    }
185996
public static function stringToDOMDocument($xml, $filename = '')
    {
        $preUseInternalErrors = libxml_use_internal_errors(true);
        try {
            libxml_clear_errors();
            $doc = new DOMDocument();
            if (@$doc->loadXML($xml) === false) {
                throw new Exception(empty($filename) ? 'Failed to parse xml' : ('Failed to load file '.$filename));
            }
        } catch (Exception $x) {
            libxml_use_internal_errors($preUseInternalErrors);
            libxml_clear_errors();
            throw $x;
        }
        libxml_use_internal_errors($preUseInternalErrors);

        return $doc;
    }
543425
public function removeUnprocessableHtmlTag($tagName)
    {
        $key = \array_search($tagName, $this->unprocessableHtmlTags, true);
        if ($key !== false) {
            unset($this->unprocessableHtmlTags[$key]);
        }
    }
434794
public function loadDomDocument(\DOMDocument $domDocument)
    {
        $this->_dom = $domDocument;
        foreach ($this->_getNodesForCssSelector('[style]') as $node) {
            $node->setAttribute(
                'inlinestyle-original-style',
                $node->getAttribute('style')
            );
        }
    }
251088
protected function checkNode(DOMNode $node, Tag $tag)
	{
		if ($node instanceof DOMAttr)
		{
			$this->checkAttributeNode($node, $tag);
		}
		elseif ($node instanceof DOMElement)
		{
			if ($node->namespaceURI === self::XMLNS_XSL && $node->localName === 'copy-of')
			{
				$this->checkCopyOfNode($node, $tag);
			}
			else
			{
				$this->checkElementNode($node, $tag);
			}
		}
	}
312050
public function filter($node, $tagname)
    {
        $ret = array();
        while ($node = Dom::getNextSiblingElement($node)) {
            array_push($ret, $node);
        }
        return $ret;
    }