/**
  * Remove all empty elements
  *
  * @param DOMNodeList $DOMNodeList The list of all elements we are checking
  * @return DOMNodeList The modified list of all remaining elements
  */
 protected function _filter_empty_elements(DOMNodeList $DOMNodeList)
 {
     $NodeListIndex = 0;
     // We might reduce $DOMNodeList->length during the loop
     for ($NodeListIndex = 0; $NodeListIndex < $DOMNodeList->length; ++$NodeListIndex) {
         $DOMNode = $DOMNodeList->item($NodeListIndex);
         if (!isset($DOMNode->nodeName) || !in_array($DOMNode->nodeName, $this->_checkTagNames, true)) {
             continue;
         }
         // Climb up to make sure we’re not in an Instant Article element (which should have proper handling elsewhere)
         $parentNode = $DOMNode;
         while (isset($parentNode->nodeName) && $parentNode->nodeName != 'body') {
             if ('figure' == $parentNode->nodeName && false !== strpos($parentNode->getAttribute('class'), 'op-')) {
                 // We found an element that’s likely to be an Instant Article element
                 continue 2;
             }
             $parentNode = $parentNode->parentNode;
         }
         // Check all childnodes first
         if (is_a($DOMNode, 'DOMElement') && isset($DOMNode->childNodes) && is_a($DOMNode->childNodes, 'DOMNodeList')) {
             $this->_filter_empty_elements($DOMNode->childNodes);
         }
         if (isset($DOMNode->nodeValue) && '' == trim($DOMNode->nodeValue)) {
             if (!isset($DOMNode->childNodes) || is_null($DOMNode->childNodes) || is_a($DOMNode->childNodes, 'DOMNodeList') && !$DOMNode->childNodes->length) {
                 // If the element is an empty node, remove it. But we must have a parentNode to remove a node
                 if (is_a($DOMNode->parentNode, 'DOMElement')) {
                     $DOMNode->parentNode->removeChild($DOMNode);
                 }
             }
         }
     }
     return $DOMNodeList;
 }
コード例 #2
0
 /**
  * @param DOMNodeList $nodeList
  */
 protected function iterate(DOMNodeList $nodeList)
 {
     for ($i = 0; $i < $nodeList->length; $i++) {
         $node = $nodeList->item($i);
         $this->childrenVisitor->visit($node);
     }
 }
コード例 #3
0
 /**
  * Get single dom node value from node list at 0-index, or null when empty result
  *
  * @param \DOMNodeList $item
  * @throws \Exception
  * @return string|null
  */
 protected function getDomNodeValue(\DOMNodeList $item)
 {
     if ($item->length == 0) {
         return null;
     }
     return $item->item(0) instanceof \DOMAttr ? trim($item->item(0)->value) : trim($item->item(0)->nodeValue);
 }
コード例 #4
0
ファイル: ResultSet.php プロジェクト: robertodormepoco/zf2
 /**
  * Implement SeekableIterator::current()
  *
  * @return Zend_Service_Amazon_Item
  */
 public function current()
 {
     $dom = $this->_results->item($this->_currentIndex);
     if ($dom === null) {
         throw new Exception\RuntimeException('no results found');
     }
     return new Item($dom);
 }
コード例 #5
0
ファイル: DOMNodeList.php プロジェクト: Nycto/Round-Eights
 /**
  * Returns the current value of the iterator
  *
  * @return DOMNode|NULL Returns NULL if there is no current value
  */
 public function current()
 {
     if ($this->offset === NULL) {
         return NULL;
     } else {
         return $this->nodelist->item($this->offset);
     }
 }
コード例 #6
0
ファイル: PostList.php プロジェクト: robertodormepoco/zf2
 /**
  * Transforms DOMNodeList to array of posts
  *
  * @param  DOMNodeList $nodeList
  * @return void
  */
 private function constructFromNodeList(\DOMNodeList $nodeList)
 {
     for ($i = 0; $i < $nodeList->length; $i++) {
         $curentNode = $nodeList->item($i);
         if ($curentNode->nodeName == 'post') {
             $this->addPost(new Post($this->service, $curentNode));
         }
     }
 }
コード例 #7
0
ファイル: FigDOMNodeList.php プロジェクト: jfrancr/figdice
 public function next()
 {
     if ($this->index < $this->count() - 1) {
         $this->current = $this->domNodeList->item(++$this->index);
     } else {
         $this->current = null;
     }
     return $this->current;
 }
コード例 #8
0
 /**
  * Transforms DOMNodeList to array of posts
  *
  * @param  DOMNodeList $nodeList
  * @return void
  */
 private function _constructFromNodeList(DOMNodeList $nodeList)
 {
     for ($i = 0; $i < $nodeList->length; $i++) {
         $curentNode = $nodeList->item($i);
         if ($curentNode->nodeName == 'post') {
             $this->_addPost(new Zend_Service_Delicious_Post($this->_service, $curentNode));
         }
     }
 }
コード例 #9
0
ファイル: Rss.php プロジェクト: inscriptionweb/kriss_feed
 /**
  * Check if tagName from $nodes are correct depending on $name
  *
  * @param DOMNodeList $nodes to check
  * @param string      $name  to compare with tagName
  *
  * @return array of nodes with correct $name
  */
 public static function filterNodeListByName($nodes, $name)
 {
     $res = array();
     for ($i = 0; $i < $nodes->length; $i++) {
         if ($nodes->item($i)->tagName === $name) {
             $res[] = $nodes->item($i);
         }
     }
     return $res;
 }
コード例 #10
0
ファイル: SoapRequestXmlFixer.php プロジェクト: Katoga/g-ads
 /**
  * Fix a list of nodes corresponding to an array of objects.
  *
  * @param \DOMNodeList $nodeList the node list matching <var>$objects</var>
  * @param array $objects the objects array matching <var>$nodeList</var>
  * @param \DOMXPath $xpath the xpath object representing the DOM
  */
 private function FixXmlNodes(\DOMNodeList $nodeList, array $objects, \DOMXPath $xpath)
 {
     if ($nodeList->length == sizeof($objects)) {
         $i = 0;
         foreach ($objects as $object) {
             $this->FixXmlNode($nodeList->item($i), $object, $xpath);
             $i++;
         }
     }
 }
コード例 #11
0
ファイル: XmlHelper.php プロジェクト: citypay/php-sdk
 /**
  * 
  * @param DOMNodeList $nodeList
  * @return type
  */
 public static function getFirstElement($nodeList)
 {
     if ($nodeList instanceof \DOMNodeList) {
         if ($nodeList->length > 0x0) {
             return $nodeList->item(0x0);
         } else {
             return null;
         }
     }
 }
コード例 #12
0
 /**
  * Add all nodes from the fixtures xml document.
  *
  * If the root node is not called jcr:root, autogenerate a root node.
  *
  * @param string       $workspaceName
  * @param \DOMNodeList $nodes
  *
  * @return DBUnitFixtureXML
  */
 public function addNodes($workspaceName, \DOMNodeList $nodes)
 {
     $node = $nodes->item(0);
     if ('jcr:root' !== $node->getAttributeNS($this->namespaces['sv'], 'name')) {
         $this->addRootNode('tests');
     }
     foreach ($nodes as $node) {
         $this->addNode($workspaceName, $node);
     }
     return $this;
 }
コード例 #13
0
ファイル: XmlUtil.php プロジェクト: sigmadesarrollo/logisoft
 public static function getElementByNodeName(DOMNodeList $nodeList, $nodeName)
 {
     for ($i = 0; $i < $nodeList->length; $i++) {
         /*DOMNode*/
         $item = $nodeList->item($i);
         if (self::cleearNS($item->nodeName) == $nodeName) {
             return self::getDOMDocument($item);
         }
     }
     return null;
 }
 /**
  * Dispatch each element in the nodelist to the transformer
  *
  * Note that we work directly on the DOMNodeList itself. Objects are passed by ref.
  *
  * @since 0.1
  * @param DOMNodeList  $DOMNodeList  List of images
  * @return DOMNodeList  The DOMNodeList. If you want to chain.
  */
 protected function _transform_elements(DOMNodeList $DOMNodeList)
 {
     // A foreach won’t work as we are changing the elements
     for ($i = 0; $i < $DOMNodeList->length; ++$i) {
         $origLength = $DOMNodeList->length;
         $this->_transform_element($DOMNodeList->item($i));
         if ($origLength !== $DOMNodeList->length) {
             // The element is replaced by an element of another type and is no longer in the nodelist
             --$i;
         }
     }
     return $DOMNodeList;
 }
コード例 #15
0
 /**
  * Implements SeekableIterator::current().
  *
  * @return  void
  * @throws  Zend_Service_Exception
  * @abstract
  */
 public function current()
 {
     if ($this->_resultClass === null) {
         throw new Zend_Service_Exception('Result class not provided');
     }
     $class = $this->_resultClass;
     return new $class($this->_results->item($this->_currentIndex));
 }
コード例 #16
0
ファイル: DomNodeList.php プロジェクト: ridaovic/VosArtistes
 /**
  * @param int $offset
  * @return mixed Can return all value types.
  */
 public function offsetGet($offset)
 {
     $node = $this->nodeList->item($offset);
     if ($node instanceof \DOMNode) {
         return new DomXPath($this->domDocument, $this->namespaces, $node);
     }
     return null;
 }
コード例 #17
0
ファイル: OrlyDB.php プロジェクト: Rogiel/predb
 /**
  *
  * @param DOMNodeList $node        	
  */
 private function parseRelease($node)
 {
     $extra = $node->item(3)->nodeValue;
     if (strlen($extra)) {
         list($size, $files) = explode("|", $extra);
         $size = trim($size);
         $files = trim($files);
     }
     $entry = new Release();
     $entry->release = $node->item(2)->nodeValue;
     $entry->type = $node->item(1)->nodeValue;
     $entry->date = new DateTime($node->item(0)->nodeValue, new DateTimeZone('UTC'));
     $entry->size = intval($size) * 1024 * 1024;
     // as bytes
     $entry->files = intval($files);
     $entry->nuke = $node->item(4)->nodeValue;
     return $entry;
 }
コード例 #18
0
ファイル: Transcoder.php プロジェクト: robmasters/optimus
 /**
  * @param \DOMNodeList $list
  * @param null $parentEvent
  */
 protected function transcodeList(\DOMNodeList $list, $parentEvent = null)
 {
     $i = 0;
     while ($node = $list->item($i)) {
         switch ($node->nodeType) {
             case XML_TEXT_NODE:
                 $event = new TranscodeTextEvent($node, $parentEvent, $i);
                 $this->transcodeTextNode($event);
                 break;
             case XML_ELEMENT_NODE:
                 $event = new TranscodeElementEvent($node, $parentEvent, $i);
                 $this->transcodeElementNode($event);
                 break;
             default:
                 // ?
         }
         $i++;
     }
 }
コード例 #19
0
ファイル: Pre_ScnSrc_Adapter.php プロジェクト: raumfish/predb
 /**
  * @param DOMNodeList $node
  */
 private function parseRelease($node)
 {
     //		$extra = $node->item(3)->nodeValue;
     //		if (strlen($extra)) {
     //			list ($size, $files) = explode("|", $extra);
     //			$size = trim($size);
     //			$files = trim($files);
     //		}
     $entry =& new Pre_Release();
     $entry->release = $node->item(1)->nodeValue;
     $entry->type = $node->item(0)->nodeValue;
     if ($node->length == 3) {
         $entry->date = strtotime(substr($node->item(2)->nodeValue, 4)) + $vbulletin->options['release_time_offset'];
     } else {
         $entry->size = intval($node->item(2)->nodeValue) * 1024 * 1024;
         //as bytes
         $entry->files = intval($files);
     }
     return $entry;
 }
コード例 #20
0
 /**
  * @param string $name
  * @return fDOMElement|null
  */
 protected function getElementByName($name)
 {
     $name = $this->sanitizeName($name);
     for ($index = 0; $index < $this->list->length; $index++) {
         $element = $this->list->item($index);
         $current = $this->sanitizeName($element->getAttribute('name'));
         if ($current === $name) {
             return $element;
         }
     }
 }
コード例 #21
0
ファイル: XmlPath.php プロジェクト: joelsantosjunior/wotdb
 /**
  * 
  * @param DOMNodeList $elements
  * @return multitype:multitype:NULL
  */
 protected function xmlToArray($elements)
 {
     if ($elements instanceof DOMNodeList) {
         if ($elements->length == 1) {
             return $this->xmlToArray($elements->item(0));
         } else {
             $result = array();
             foreach ($elements as $element) {
                 $result[] = $this->xmlToArray($element);
             }
             return $result;
         }
     } elseif ($elements instanceof DOMNode) {
         if ($elements->hasChildNodes()) {
             $result = array();
             foreach ($elements->childNodes as $element) {
                 if ($element->nodeType != 3) {
                     if (isset($result[$element->nodeName])) {
                         if (is_array($result[$element->nodeName]) && !self::isAssociative($result[$element->nodeName])) {
                             $result[$element->nodeName][] = $this->xmlToArray($element);
                         } else {
                             $v = $result[$element->nodeName];
                             $result[$element->nodeName] = array();
                             $result[$element->nodeName][] = $v;
                             $result[$element->nodeName][] = $this->xmlToArray($element);
                         }
                     } else {
                         $result[$element->nodeName] = $this->xmlToArray($element);
                     }
                 }
             }
             if (count($result) == 0) {
                 return $elements->nodeValue;
             } else {
                 return $result;
             }
         } else {
             return $elements->nodeValue;
         }
     }
 }
コード例 #22
0
ファイル: OpenGraphParser.php プロジェクト: cass-project/cass
 private function getMetaTags(string $property, string $attrName = 'property') : array
 {
     /** @var \DOMNode[] $result */
     $result = [];
     for ($index = 0; $index < $this->metaTags->length; $index++) {
         $node = $this->metaTags->item($index);
         if ($attrNode = $node->attributes->getNamedItem($attrName)) {
             if ($attrNode->textContent === $property) {
                 $result[] = $node;
             }
         }
     }
     return $result;
 }
 /**
  * The Instant Articles spec says we can only use each image once.
  *
  * @param DOMNodeList $DOMNodeList the list of images in the document
  * @return DOMNodeList The modified list of images in the document
  */
 protected function _filter_multiple_uses(DOMNodeList $DOMNodeList)
 {
     $used_images = array();
     $NodeListIndex = 0;
     // We’ll increase $NodeListIndex and/or reduce $DOMNodeList->length
     while ($NodeListIndex < $DOMNodeList->length) {
         $DOMNode = $DOMNodeList->item($NodeListIndex);
         $src = $DOMNode->getAttribute('src');
         // See how far up the tree we can go
         $removeDOMNode = $DOMNode;
         while ('body' != $removeDOMNode->parentNode->nodeName && 1 === $removeDOMNode->parentNode->childNodes->length) {
             $removeDOMNode = $removeDOMNode->parentNode;
         }
         // If the image is used already, remove it
         if (in_array($src, $used_images, true)) {
             // Please note that when we remove the node, $DOMNodeList->length is n-1. Our $NodeListIndex will thus point to the next item in the list.
             $removeDOMNode->parentNode->removeChild($removeDOMNode);
         }
         // Add the src to the stack so we can check for multiple uses later
         $used_images[] = $src;
         ++$NodeListIndex;
     }
     return $DOMNodeList;
 }
コード例 #24
0
ファイル: UCS.php プロジェクト: CrackHD/phpucssu
 /**
  * @param UCS $ucs
  * @param \DOMNodeList $cols
  * @param \DomXPath $xpath
  */
 function __construct($ucs, $cols, $xpath)
 {
     $this->ucs = $ucs;
     $this->contract_id = $ucs->getContractId();
     $date_str = $cols->item(0)->nodeValue;
     list($date_str) = explode("*", $date_str, 2);
     $this->date = new \DateTime($date_str);
     $this->currency = $cols->item(1)->nodeValue;
     $this->total_amount = floatval(str_replace(" ", "", $cols->item(2)->nodeValue));
     $this->total_commission = floatval(str_replace(" ", "", $cols->item(3)->nodeValue));
     $link = $cols->item(6);
     while (!$link->getAttribute("href")) {
         $link = $link->firstChild;
     }
     $this->terminals_url = UCS::URL_REPORTS . $link->getAttribute("href");
 }
コード例 #25
0
ファイル: Sanitizer.php プロジェクト: kreynen/elmsln
 /**
  * Start the cleaning with tags, then we move onto attributes and hrefs later
  *
  * @param \DOMNodeList $elements
  */
 protected function startClean(\DOMNodeList $elements)
 {
     // loop through all elements
     // we do this backwards so we don't skip anything if we delete a node
     // see comments at: http://php.net/manual/en/class.domnamednodemap.php
     for ($i = $elements->length - 1; $i >= 0; $i--) {
         $currentElement = $elements->item($i);
         // If the tag isn't in the whitelist, remove it and continue with next iteration
         if (!in_array($currentElement->tagName, $this->allowedTags)) {
             $currentElement->parentNode->removeChild($currentElement);
             continue;
         }
         $this->cleanAttributesOnWhitelist($currentElement);
         $this->cleanXlinkHrefs($currentElement);
         $this->cleanHrefs($currentElement);
     }
 }
コード例 #26
0
ファイル: ResultSet.php プロジェクト: dalinhuang/popo
 /**
  * Implements SeekableIterator::current()
  *
  * @return Zend_Service_Flickr_Result
  */
 public function current()
 {
     return new Zend_Service_Flickr_Result($this->_results->item($this->_currentIndex), $this->_flickr);
 }
コード例 #27
0
 /**
  * Find where to start, iterate through a list, add elements to a
  * new DomDocument, return resulting xhtml
  *
  * @param \DOMNodeList $dom_list
  * @param int $index
  * @param string $chapter_title
  *
  * @return string XHTML
  */
 protected function getChapter(\DOMNodeList $dom_list, $index, $chapter_title)
 {
     if ('' == $chapter_title) {
         $chapter_title = 'unknown';
     }
     $chapter = new \DOMDocument('1.0', 'UTF-8');
     // create a new node element
     $root = $chapter->createElement('div');
     $root->setAttribute('class', $chapter_title);
     $chapter->appendChild($root);
     // Start at the beginning if no h1 tags are found.
     // In other words...bring in the whole document.
     '__UNKNOWN__' == $chapter_title ? $i = 0 : ($i = $index);
     do {
         $node = $chapter->importNode($dom_list->item($i), true);
         $chapter->documentElement->appendChild($node);
         $i++;
         // TODO
         // This is problematic
         // DOMNodeList can be made up of DOMElement(s)
         // *and* DOMText(s) which do not have the property ->tagName
     } while (@$dom_list->item($i)->tagName != $this->tag && $i < $dom_list->length);
     // h1 tag will not be needed in the body of the html
     $h1 = $chapter->getElementsByTagName($this->tag)->item(0);
     // removeChild is quick to throw a fatal error
     if ($h1 && $this->tag == $h1->nodeName && 'div' == $h1->parentNode->nodeName) {
         $chapter->documentElement->removeChild($h1);
     }
     // hyperlinks
     $chapter = $this->addHyperlinks($chapter);
     // footnotes
     $chapter = $this->addFootnotes($chapter);
     $result = $chapter->saveHTML($chapter->documentElement);
     // appendChild brings over the namespace which is superfluous on every html element
     // the string below is from the xslt file
     // @see includes/modules/import/ooxml/xsl/docx2html.xsl
     $result = preg_replace('/xmlns="http:\\/\\/www.w3.org\\/1999\\/xhtml"/', '', $result);
     return $result;
 }
コード例 #28
0
 public function processEntries(DOMNodeList $entries, DOMElement $feed, $source)
 {
     for ($i = 0; $i < $entries->length; $i++) {
         $entry = $entries->item($i);
         try {
             $this->processEntry($entry, $feed, $source);
         } catch (AlreadyFulfilledException $e) {
             common_debug('We already had this entry: ' . $e->getMessage());
         } catch (ServerException $e) {
             // FIXME: This should be UnknownUriException and the ActivityUtils:: findLocalObject should only test one URI
             common_log(LOG_ERR, 'Entry threw exception while processing a feed from ' . $source . ': ' . $e->getMessage());
         }
     }
 }
コード例 #29
0
ファイル: DOMStatic.php プロジェクト: dcarbone/dom-plus
 /**
  * @param \DOMNodeList $sourceNodeList
  * @param \DOMNode $destinationNode
  * @return bool|\DOMNode
  */
 public static function cloneAndPrependChildrenTo(\DOMNodeList $sourceNodeList, \DOMNode $destinationNode)
 {
     for ($i = 0; $i < $sourceNodeList->length; $i++) {
         $ret = static::prependTo($sourceNodeList->item($i)->cloneNode(true), $destinationNode);
         if (!$ret instanceof \DOMNode) {
             return false;
         }
     }
     return $destinationNode;
 }
コード例 #30
0
ファイル: ResultSet.php プロジェクト: Cryde/sydney-core
 /**
  * Implement SeekableIterator::current()
  *
  * @return Zend_Service_Amazon_Item
  */
 public function current()
 {
     return new Zend_Service_Amazon_Item($this->_results->item($this->_currentIndex));
 }