Example #1
0
 /**
  * Parse dom node
  *
  * @param \DOMNode $node
  * @return array
  */
 protected function _parseNode(\DOMNode $node)
 {
     $result = [];
     if (false === $node->hasChildNodes()) {
         $result = $this->_getSimpleNodeValue($node);
     } else {
         foreach ($node->childNodes as $childNode) {
             $sameNodesCount = $this->_getSameNodesCount($node->getElementsByTagName($childNode->nodeName), $childNode);
             /** @var array $nodeValue  */
             $nodeValue = $this->_parseNode($childNode);
             $siblingKey = $this->_getSiblingKey($childNode);
             if ($siblingKey !== 0) {
                 $nodeValue = isset($nodeValue[$childNode->nodeName]) ? $nodeValue[$childNode->nodeName] : $nodeValue;
             } elseif (empty($nodeValue)) {
                 continue;
             }
             // how many of these child nodes do we have?
             if ($sameNodesCount > 1) {
                 // more than 1 child - make numeric array
                 $result[$siblingKey][] = $nodeValue;
             } else {
                 $result[$siblingKey] = $nodeValue;
             }
         }
         // if the child is <foo>bar</foo>, the result will be array(bar)
         // make the result just 'bar'
         if (count($result) == 1 && isset($result[0])) {
             $result = current($result);
         }
     }
     $attributes = $this->_parseNodeAttributes($node);
     $result = array_merge($result, $attributes);
     return $result;
 }
 /**
  * @param DOMNode $node
  * @param ProxyObject $proxy
  */
 private function process(DOMNode $node, ProxyObject $proxy)
 {
     $proxy->setName($node->nodeName);
     if ($node->hasAttributes()) {
         for ($i = 0; $i < $node->attributes->length; $i++) {
             $attribute = $node->attributes->item($i);
             $proxy->set($attribute->name, $attribute->value);
         }
     }
     if ($node->hasChildNodes()) {
         $nodeTypes = array();
         foreach ($node->childNodes as $childNode) {
             if ($childNode->nodeName === '#text') {
                 $proxy->setValue($childNode->nodeValue);
             } else {
                 $childProxy = new ProxyObject();
                 $this->process($childNode, $childProxy);
                 $nodeTypes[$childProxy->getName()][] = $childProxy;
             }
         }
         foreach ($nodeTypes as $tagName => $nodes) {
             $proxy->set($tagName, $nodes);
         }
     }
 }
 /**
  * @param \DOMNode $parent
  * @param \AerialShip\LightSaml\Meta\SerializationContext $context
  * @return \DOMNode
  */
 function getXml(\DOMNode $parent, SerializationContext $context)
 {
     $objXMLSecDSig = new \XMLSecurityDSig();
     $objXMLSecDSig->setCanonicalMethod($this->getCanonicalMethod());
     $key = $this->getXmlSecurityKey();
     switch ($key->type) {
         case \XMLSecurityKey::RSA_SHA256:
             $type = \XMLSecurityDSig::SHA256;
             break;
         case \XMLSecurityKey::RSA_SHA384:
             $type = \XMLSecurityDSig::SHA384;
             break;
         case \XMLSecurityKey::RSA_SHA512:
             $type = \XMLSecurityDSig::SHA512;
             break;
         default:
             $type = \XMLSecurityDSig::SHA1;
     }
     $objXMLSecDSig->addReferenceList(array($parent), $type, array(Protocol::XMLSEC_TRANSFORM_ALGORITHM_ENVELOPED_SIGNATURE, \XMLSecurityDSig::EXC_C14N), array('id_name' => $this->getIDName(), 'overwrite' => FALSE));
     $objXMLSecDSig->sign($key);
     $objXMLSecDSig->add509Cert($this->getCertificate()->getData(), false, false);
     $firstChild = $parent->hasChildNodes() ? $parent->firstChild : null;
     if ($firstChild && $firstChild->localName == 'Issuer') {
         // The signature node should come after the issuer node
         $firstChild = $firstChild->nextSibling;
     }
     $objXMLSecDSig->insertSignature($parent, $firstChild);
 }
Example #4
0
 /**
  * Draw a final layout zone on its thumbnail.
  *
  * @access private
  *
  * @param ressource $thumbnail  The thumbnail ressource
  * @param DOMNode   $node       The current node zone
  * @param array     $clip       The clip rect to draw
  * @param int       $background The background color
  * @param int       $gridcolumn The number of columns in the grid
  * @param boolean   $lastChild  True if the current node is the last child of its parent node
  *
  * @return int The new X axis position;
  */
 private function drawThumbnailZone(&$thumbnail, $node, $clip, $background, $gridcolumn, $lastChild = false)
 {
     $x = $clip[0];
     $y = $clip[1];
     $width = $clip[2];
     $height = $clip[3];
     if (null !== ($spansize = preg_replace('/[^0-9]+/', '', $node->getAttribute('class')))) {
         $width = floor($width * $spansize / $gridcolumn);
     }
     if (false !== strpos($node->getAttribute('class'), 'Child')) {
         $height = floor($height / 2);
     }
     if (!$node->hasChildNodes()) {
         $this->drawRect($thumbnail, array($x, $y, $width, $height), $background, $width == $clip[2] || strpos($node->getAttribute('class'), 'hChild'), $lastChild);
         return $width + 2;
     }
     foreach ($node->childNodes as $child) {
         if (is_a($child, 'DOMText')) {
             continue;
         }
         if ('clear' == $child->getAttribute('class')) {
             $x = $clip[0];
             $y = $clip[1] + floor($height / 2) + 2;
             continue;
         }
         $x += $this->drawThumbnailZone($thumbnail, $child, array($x, $y, $clip[2], $height), $background, $gridcolumn, $node->isSameNode($node->parentNode->lastChild));
     }
     return $x + $width - 2;
 }
Example #5
0
	/**
	 * Parse through a child node of this table, usually a tr, thead, or tbody.
	 *
	 * This is a recursive safe function.
	 *
	 * @param \DOMNode $node
	 */
	private function _parseInto(\DOMNode $node){
		if($node->hasChildNodes()){
			$nodes = $node->childNodes;
			for($i = 0; $i < $nodes->length; $i++){
				/** @var \DOMNode $node */
				$node = $nodes->item($i);
				$nodeType = $node->nodeName;

				switch($nodeType){
					case 'tr':
						// Increment to the next row on a TR tag!
						++$this->_currentRow;
						$this->_currentCol = 0;
						$this->_parseInto($node);
						break;
					case 'thead':
					case 'tbody':
						// These simply get parsed again for TR tags.
						$this->_parseInto($node);
						break;
					case 'td':
					case 'th':
						$this->_parseCell($node);
						break;
				}
			}
		}
	}
Example #6
0
/**
 *通过指定的XPath和DOM对象查找子节点信息
 *@param string $path xpath格式路径(example: '/Location/CountryRegion', './State') 具体参考:http://www.w3school.com.cn/xpath/
 *@param DOMNode $DOMNode
 *@param DOMXpath $xpath
 *@return DOMNodeList|[] $children 返回一个空数组或者一个DOMNodeList对象
 */
function queryChildren($path, $DOMNode, $xpath)
{
    $children = array();
    if ($DOMNode->hasChildNodes()) {
        $children = $xpath->query($path, $DOMNode);
    }
    return $children;
}
function mobilize_remove_element(DOMNode $link)
{
    // Move all link tag content to its parent node just before it.
    while ($link->hasChildNodes()) {
        $child = $link->removeChild($link->firstChild);
        $link->parentNode->insertBefore($child, $link);
    }
    // Remove the link tag.
    $link->parentNode->removeChild($link);
}
Example #8
0
	private function processNode( DOMNode $node ) {
		if( $node ) {
			// make sure we are processing a module document
			if ( PAGE_TAG == $node->tagName ) {
				// process the child documents
				if ( $node->hasChildNodes() ) {
					$this->processNodeList( $node->childNodes );
				}
			}
		}
	}
Example #9
0
 /**
  *
  * @param \AppShed\Remote\XML\DOMDocument $xml
  * @param \DOMNode $node
  */
 private function checkNode($xml, $node)
 {
     if ($node->hasChildNodes()) {
         for ($i = 0; $i < $node->childNodes->length; $i++) {
             $this->checkNode($xml, $node->childNodes->item($i));
         }
     } else {
         if ($node instanceof \DOMElement && !in_array($node->tagName, ['img', 'br'])) {
             $node->appendChild($xml->createTextNode(''));
         }
     }
 }
 /**
  * @param DOMNode $parentElement - root element iteratoru
  * @throws LBoxExceptionConfig
  */
 public function setParent(DOMNode $parentElement)
 {
     if (strlen($this->nodeName) < 1) {
         throw new LBoxExceptionConfig(LBoxExceptionConfig::MSG_ABSTRACT_NODENAME_NOT_DEFINED, LBoxExceptionConfig::CODE_ABSTRACT_NODENAME_NOT_DEFINED);
     }
     $this->parentElement = $parentElement;
     // nacteme first child
     if ($this->parentElement->hasChildNodes()) {
         $firstChild = $this->parentElement->firstChild;
         // preskakovani irelevantnich nodu (#TEXT, #COMMENT etc..)
         while ($firstChild->nodeName != $this->nodeName) {
             if (!$firstChild->nextSibling instanceof DOMNode) {
                 break;
             }
             $firstChild = $firstChild->nextSibling;
         }
         if ($firstChild->nodeName == $this->nodeName) {
             $this->items[] = $firstChild;
         }
     }
 }
Example #11
0
 /**
  * Insert nodes into target as first childs.
  *
  * @param DOMNode $targetNode
  * @param array|DOMNodeList|FluentDOM $contentNodes
  */
 public static function insertChildrenBefore($targetNode, $contentNodes)
 {
     $result = array();
     if ($targetNode instanceof DOMElement) {
         $firstChild = $targetNode->hasChildNodes() ? $targetNode->childNodes->item(0) : NULL;
         foreach ($contentNodes as $contentNode) {
             if ($contentNode instanceof DOMElement || $contentNode instanceof DOMText) {
                 $result[] = $targetNode->insertBefore($contentNode->cloneNode(TRUE), $firstChild);
             }
         }
     }
     return $result;
 }
 /**
  * @param \DOMNode $node
  * @return array|null|string
  */
 private function nodeValue(\DOMNode $node)
 {
     $typeAttribute = $node->attributes->getNamedItem('type');
     if ($typeAttribute && $typeAttribute->textContent === 'collection') {
         return $this->collectionToArray($node->childNodes);
     } elseif ($node->hasChildNodes()) {
         if ($node->childNodes->length === 1 && $node->childNodes->item(0) instanceof \DOMText) {
             return $node->textContent;
         } else {
             return $this->nodesToArray($node->childNodes);
         }
     }
     return null;
 }
Example #13
0
 private static function removeCharacterDataNodes(\DOMNode $node)
 {
     $node->normalize();
     if ($node->hasChildNodes()) {
         for ($i = $node->childNodes->length - 1; $i >= 0; $i--) {
             $child = $node->childNodes->item($i);
             if ($child instanceof \DOMCharacterData) {
                 if (!strlen(trim($child->data))) {
                     $node->removeChild($child);
                 }
             }
         }
     }
 }
Example #14
0
 /**
  * Set the contents of a DOMNode.
  *
  * @param \DOMNode $node
  *   A DOMNode object.
  * @param string $content
  *   The text or HTML that will replace the contents of $node.
  */
 protected function setNodeContent(\DOMNode $node, $content)
 {
     // Remove all children of the DOMNode.
     while ($node->hasChildNodes()) {
         $node->removeChild($node->firstChild);
     }
     if (strlen($content)) {
         // Load the contents into a new DOMDocument and retrieve the elements.
         $replacement_nodes = Html::load($content)->getElementsByTagName('body')->item(0);
         // Finally, import and append the contents to the original node.
         foreach ($replacement_nodes->childNodes as $replacement_node) {
             $replacement_node = $node->ownerDocument->importNode($replacement_node, TRUE);
             $node->appendChild($replacement_node);
         }
     }
 }
Example #15
0
 /**
  * @param string  $needle
  * @param DOMNode $elem
  * @return \DOMNode|bool
  */
 private function findStringNode($needle, DOMNode $elem)
 {
     if ($elem->nodeType === XML_TEXT_NODE && strpos($elem->data, $needle) !== false) {
         return $elem;
     }
     if (!$elem->hasChildNodes()) {
         return false;
     }
     foreach ($elem->childNodes as $child) {
         $node = $this->findStringNode($needle, $child);
         if ($node !== false) {
             return $node;
         }
     }
     return false;
 }
Example #16
0
	/**
	 * Get the standard child content for this node, (or nodeValue if no children).
	 *
	 * @return string
	 */
	protected function _getContent(){
		$output = '';
		if($this->_node->hasChildNodes()){
			$nodes = $this->_node->childNodes;
			for($i = 0; $i < $nodes->length; $i++){
				$subElement = $this->_parentConverter->_resolveNodeToElement(
					$nodes->item($i)
				);
				$output .= $subElement->convert();
			}
		}
		else{
			$output .= $this->_node->nodeValue;
		}

		return trim($output) . ' ';
	}
Example #17
0
 /**
  * Zwraca liste dzieci danego noda w postaci tablicy
  *
  * @param DOMNode $node
  * @param bool $withAttributes - gdy ustawione na true zwraca w tablicy też atrybuty ich nazwy kluczy poprzedzone są znakiem: @
  *
  * @return array|bool|string
  */
 protected function getChildsAsArray(DOMNode $node, $withAttributes = false)
 {
     if ($node->hasChildNodes() || $withAttributes === true && $node->hasAttributes()) {
         $arr = array();
         if ($withAttributes === true && !is_null($node->attributes)) {
             foreach ($node->attributes as $attr) {
                 $arr["@{$attr->name}"] = $attr->value;
             }
         }
         foreach ($node->childNodes as $value) {
             if ($value->hasChildNodes()) {
                 $arr[$value->nodeName] = $this->getChildsAsArray($value, $withAttributes);
             } else {
                 if ($value->nodeName == "#text") {
                     return $value->nodeValue;
                 }
                 $arr[$value->nodeName] = $value->nodeValue;
             }
         }
         return $arr;
     }
     return false;
 }
 /**
  * @param DOMNode $functionTag
  * @param int $position
  * @param EiIteration $iteration
  */
 public function generateFromXML(DOMNode $functionTag, $position = 0, EiIteration $iteration = null)
 {
     $this->setXpath($functionTag->getAttribute('xpath'));
     $this->setFunctionId($functionTag->getAttribute('function_id'));
     $this->setFunctionRef($functionTag->getAttribute('function_ref'));
     $this->setEiFonctionId($functionTag->getAttribute('ei_fonction_id'));
     $this->setPosition($position);
     if ($functionTag->hasChildNodes() && $functionTag->firstChild->nodeName == 'parameters') {
         $params = new Doctrine_Collection('EiTestSetParam');
         foreach ($functionTag->firstChild->childNodes as $paramNode) {
             $param = new EiTestSetParam();
             $param->setValeur($paramNode->nodeValue);
             $param->setParamId($paramNode->getAttribute('param_id'));
             $param->setFunctionId($this->getFunctionId());
             $param->setFunctionRef($this->getFunctionRef());
             $param->setEiTestSetFunction($this);
             $param->setEiTestSet($this->getEiTestSet());
             $param->setEiIteration($iteration);
             $params->add($param);
         }
         $this->setEiTestSetParams($params);
     }
 }
Example #19
0
 /**
  *
  *
  * @param  DOMNode $node
  * @since  Method available since Release 3.3.0
  * @author Mattis Stordalen Flister <*****@*****.**>
  */
 public static function removeCharacterDataNodes(DOMNode $node)
 {
     if ($node->hasChildNodes()) {
         for ($i = $node->childNodes->length - 1; $i >= 0; $i--) {
             if (($child = $node->childNodes->item($i)) instanceof DOMCharacterData) {
                 $node->removeChild($child);
             }
         }
     }
 }
Example #20
0
 /**
  * @param DOMNode $node
  * @return array|string
  */
 protected function _nodeToObject(DOMNode $node)
 {
     if ($node->hasChildNodes()) {
         $object = new stdClass();
         foreach ($node->childNodes as $childNode) {
             /* @var $childNode DOMNode */
             if ($childNode->nodeName == '#text' || $childNode->nodeName == '#cdata-section') {
                 $object = $this->_nodeToArray($childNode);
             } else {
                 $nodeName = $childNode->nodeName;
                 $object->{$nodeName} = $this->_nodeToObject($childNode);
             }
         }
     } else {
         $object = $node->nodeValue;
     }
     return $object;
 }
 /**
  * convert blockquotes to quotes ("> ") and strip tags
  * 
  * this function uses tidy or DOM to recursivly walk the dom tree of the html mail
  * @see http://php.net/manual/de/tidy.root.php
  * @see http://php.net/manual/en/book.dom.php
  * 
  * @param tidyNode|DOMNode $_node
  * @param integer $_quoteIndent
  * @param string $_eol
  * @return string
  * 
  * @todo we can transform more tags here, i.e. the <strong>BOLDTEXT</strong> tag could be replaced with *BOLDTEXT*
  * @todo think about removing the tidy code
  * @todo reduce complexity
  */
 public static function addQuotesAndStripTags($_node, $_quoteIndent = 0, $_eol = "\n")
 {
     $result = '';
     $hasChildren = $_node instanceof DOMNode ? $_node->hasChildNodes() : $_node->hasChildren();
     $nameProperty = $_node instanceof DOMNode ? 'nodeName' : 'name';
     $valueProperty = $_node instanceof DOMNode ? 'nodeValue' : 'value';
     $divNewline = FALSE;
     if ($hasChildren) {
         $lastChild = NULL;
         $children = $_node instanceof DOMNode ? $_node->childNodes : $_node->child;
         if ($_node->{$nameProperty} == 'div') {
             $divNewline = TRUE;
         }
         foreach ($children as $child) {
             $isTextLeaf = $child instanceof DOMNode ? $child->{$nameProperty} == '#text' : !$child->{$nameProperty};
             if ($isTextLeaf) {
                 // leaf -> add quotes and append to content string
                 if ($_quoteIndent > 0) {
                     $result .= str_repeat(self::QUOTE, $_quoteIndent) . $child->{$valueProperty};
                 } else {
                     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . "value: " . $child->{$valueProperty} . " / name: " . $_node->{$nameProperty} . "\n");
                     }
                     if ($divNewline) {
                         $result .= $_eol . str_repeat(self::QUOTE, $_quoteIndent);
                         $divNewline = FALSE;
                     }
                     $result .= $child->{$valueProperty};
                 }
             } else {
                 if ($child->{$nameProperty} == 'blockquote') {
                     //  opening blockquote
                     $_quoteIndent++;
                 } else {
                     if ($child->{$nameProperty} == 'br') {
                         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
                             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . "value: " . $child->{$valueProperty} . " / name: " . $_node->{$nameProperty} . "\n");
                         }
                         // reset quoted state on newline
                         if ($lastChild !== NULL && $lastChild->{$nameProperty} == 'br') {
                             // add quotes to repeating newlines
                             $result .= str_repeat(self::QUOTE, $_quoteIndent);
                         }
                         $result .= $_eol;
                         $divNewline = FALSE;
                     }
                 }
             }
             $result .= self::addQuotesAndStripTags($child, $_quoteIndent, $_eol);
             if ($child->{$nameProperty} == 'blockquote') {
                 // closing blockquote
                 $_quoteIndent--;
                 // add newline after last closing blockquote
                 if ($_quoteIndent == 0) {
                     $result .= $_eol;
                 }
             }
             $lastChild = $child;
         }
         // add newline if closing div
         if ($divNewline) {
             $result .= $_eol . str_repeat(self::QUOTE, $_quoteIndent);
         }
     }
     return $result;
 }
Example #22
0
 /**
  * Recursive iterator to locate and return a specific node, targeting child nodes
  *
  * @param \DOMNode $node
  * @param string $chapter_name
  *
  * @return \DOMNode
  */
 protected function findTheNode(\DOMNode $node, $chapter_name)
 {
     if (XML_ELEMENT_NODE !== $node->nodeType) {
         return '';
     }
     $currentTag = $node->tagName;
     $currentValue = trim($node->nodeValue);
     if ($chapter_name == $currentValue && $this->tag == $currentTag) {
         return $node;
     }
     // test
     if ($node->hasChildNodes()) {
         $nodeList = $node->childNodes;
         for ($i = 0; $i < $nodeList->length; $i++) {
             if ($nodeList->item($i)->nodeType !== XML_ELEMENT_NODE) {
                 continue;
             }
             if ($chapter_name != $nodeList->item($i)->nodeValue && $this->tag != $nodeList->item($i)->tagName) {
                 // recursive
                 return $this->findTheNode($nodeList->item($i), $chapter_name);
             }
         }
     }
     return '';
 }
Example #23
0
 /**
  * VQModObject::__construct()
  *
  * @param DOMNode $node <modification> node
  * @param string $modFile File modification is from
  * @return null
  * @description Loads modification meta information
  */
 public function __construct(DOMNode $node, $modFile)
 {
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $child) {
             $name = (string) $child->nodeName;
             if (isset($this->{$name})) {
                 $this->{$name} = (string) $child->nodeValue;
             }
         }
     }
     $this->modFile = $modFile;
     $this->_parseMods($node);
 }
Example #24
0
 /**
  * A depth-checking function. Typically, it only needs to be
  * invoked with the first parameter. The rest are used for recursion.
  * @see deepest();
  * @param DOMNode $ele
  *  The element.
  * @param int $depth
  *  The depth guage
  * @param mixed $current
  *  The current set.
  * @param DOMNode $deepest
  *  A reference to the current deepest node.
  * @return array
  *  Returns an array of DOM nodes.
  */
 protected function deepestNode(\DOMNode $ele, $depth = 0, $current = NULL, &$deepest = NULL)
 {
     // FIXME: Should this use SplObjectStorage?
     if (!isset($current)) {
         $current = array($ele);
     }
     if (!isset($deepest)) {
         $deepest = $depth;
     }
     if ($ele->hasChildNodes()) {
         foreach ($ele->childNodes as $child) {
             if ($child->nodeType === XML_ELEMENT_NODE) {
                 $current = $this->deepestNode($child, $depth + 1, $current, $deepest);
             }
         }
     } elseif ($depth > $deepest) {
         $current = array($ele);
         $deepest = $depth;
     } elseif ($depth === $deepest) {
         $current[] = $ele;
     }
     return $current;
 }
Example #25
0
File: HTML.php Project: rikaix/zf2
 /**
  * highlight words in content of the specified node
  *
  * @param DOMNode $contextNode
  * @param array $wordsToHighlight
  * @param callback $callback   Callback method, used to transform (highlighting) text.
  * @param array    $params     Array of additionall callback parameters (first non-optional parameter is a text to transform)
  */
 protected function _highlightNodeRecursive(\DOMNode $contextNode, $wordsToHighlight, $callback, $params)
 {
     $textNodes = array();
     if (!$contextNode->hasChildNodes()) {
         return;
     }
     foreach ($contextNode->childNodes as $childNode) {
         if ($childNode->nodeType == XML_TEXT_NODE) {
             // process node later to leave childNodes structure untouched
             $textNodes[] = $childNode;
         } else {
             // Process node if it's not a script node
             if ($childNode->nodeName != 'script') {
                 $this->_highlightNodeRecursive($childNode, $wordsToHighlight, $callback, $params);
             }
         }
     }
     foreach ($textNodes as $textNode) {
         $this->_highlightTextNode($textNode, $wordsToHighlight, $callback, $params);
     }
 }
Example #26
0
 /**
  * The main loop that recurse on a node tree.
  * It output only allowed tags with allowed attributes and allowed inline styles
  *
  * @param DOMNode $node  HTML element
  * @param int     $level Recurrence level (safe initial value found empirically)
  */
 private function dumpHtml($node, $level = 20)
 {
     if (!$node->hasChildNodes()) {
         return '';
     }
     $level++;
     if ($this->max_nesting_level > 0 && $level == $this->max_nesting_level - 1) {
         // log error message once
         if (!$this->max_nesting_level_error) {
             $this->max_nesting_level_error = true;
             rcube::raise_error(array('code' => 500, 'type' => 'php', 'line' => __LINE__, 'file' => __FILE__, 'message' => "Maximum nesting level exceeded (xdebug.max_nesting_level={$this->max_nesting_level})"), true, false);
         }
         return '<!-- ignored -->';
     }
     $node = $node->firstChild;
     $dump = '';
     do {
         switch ($node->nodeType) {
             case XML_ELEMENT_NODE:
                 //Check element
                 $tagName = strtolower($node->tagName);
                 if ($callback = $this->handlers[$tagName]) {
                     $dump .= call_user_func($callback, $tagName, $this->wash_attribs($node), $this->dumpHtml($node, $level), $this);
                 } else {
                     if (isset($this->_html_elements[$tagName])) {
                         $content = $this->dumpHtml($node, $level);
                         $dump .= '<' . $tagName . $this->wash_attribs($node) . ($content === '' && isset($this->_void_elements[$tagName]) ? ' />' : ">{$content}</{$tagName}>");
                     } else {
                         if (isset($this->_ignore_elements[$tagName])) {
                             $dump .= '<!-- ' . htmlspecialchars($tagName, ENT_QUOTES) . ' not allowed -->';
                         } else {
                             $dump .= '<!-- ' . htmlspecialchars($tagName, ENT_QUOTES) . ' ignored -->';
                             $dump .= $this->dumpHtml($node, $level);
                             // ignore tags not its content
                         }
                     }
                 }
                 break;
             case XML_CDATA_SECTION_NODE:
                 $dump .= $node->nodeValue;
                 break;
             case XML_TEXT_NODE:
                 $dump .= htmlspecialchars($node->nodeValue);
                 break;
             case XML_HTML_DOCUMENT_NODE:
                 $dump .= $this->dumpHtml($node, $level);
                 break;
             case XML_DOCUMENT_TYPE_NODE:
                 break;
             default:
                 $dump .= '<!-- node type ' . $node->nodeType . ' -->';
         }
     } while ($node = $node->nextSibling);
     return $dump;
 }
Example #27
0
 /**
  * Parse the input DOMNode value (content and children) into an array or a string.
  *
  * @param \DOMNode $node xml to parse
  *
  * @return array|string
  */
 private function parseXmlValue(\DOMNode $node)
 {
     if (!$node->hasChildNodes()) {
         return $node->nodeValue;
     }
     if (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
         return $node->firstChild->nodeValue;
     }
     $value = array();
     foreach ($node->childNodes as $subnode) {
         $val = $this->parseXml($subnode);
         if ('item' === $subnode->nodeName && isset($val['@key'])) {
             if (isset($val['#'])) {
                 $value[$val['@key']] = $val['#'];
             } else {
                 $value[$val['@key']] = $val;
             }
         } else {
             $value[$subnode->nodeName][] = $val;
         }
     }
     foreach ($value as $key => $val) {
         if (is_array($val) && 1 === count($val)) {
             $value[$key] = current($val);
         }
     }
     return $value;
 }
Example #28
0
 private function hyphenateHtmlDom(DOMNode $node)
 {
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $child) {
             $this->hyphenateHtmlDom($child);
         }
     }
     if ($node instanceof DOMText) {
         $parts = $this->splitText($node->data);
         $this->Hyphen->joinHtmlDom($parts, $node);
     }
 }
Example #29
0
 protected static function deepestNode(DOMNode $node, $depth = 0, $current = null, &$deepest = null)
 {
     if (!isset($current)) {
         $current = array($node);
     }
     if (!isset($deepest)) {
         $deepest = $depth;
     }
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $child) {
             if ($child->nodeType === XML_ELEMENT_NODE) {
                 $current = self::deepestNode($child, $depth + 1, $current, $deepest);
             }
         }
     } elseif ($depth > $deepest) {
         $current = array($node);
         $deepest = $depth;
     } elseif ($depth === $deepest) {
         $current[] = $node;
     }
     return $current;
 }
Example #30
0
 /**
  * Recursively drills down in the xml tree in $node and
  * concatenates text content from the DOMNodes with a space
  * in-between to make sure search words from two different lines
  * are merged.
  *
  * @param DOMNode $node
  * @return string
  */
 static function concatTextContent($node)
 {
     $retString = '';
     if (!$node instanceof DOMNode) {
         return $retString;
     }
     if ($node->hasChildNodes()) {
         $childArray = $node->childNodes;
         foreach ($childArray as $child) {
             $retString .= eZXMLTextType::concatTextContent($child);
         }
     } elseif ($node->nodeType === XML_TEXT_NODE) {
         return $node->textContent . ' ';
     }
     return $retString;
 }