/**
  * @param Frame $child
  * @param bool $update_node
  */
 function append_child(Frame $child, $update_node = true)
 {
     while ($child instanceof AbstractFrameDecorator) {
         $child = $child->_frame;
     }
     $this->_frame->append_child($child, $update_node);
 }
Beispiel #2
0
 /**
  * Recursively adds {@link Frame} objects to the tree
  *
  * Recursively build a tree of Frame objects based on a dom tree.
  * No layout information is calculated at this time, although the
  * tree may be adjusted (i.e. nodes and frames for generated content
  * and images may be created).
  *
  * @param DOMNode $node the current DOMNode being considered
  *
  * @return Frame
  */
 protected function _build_tree_r(DOMNode $node)
 {
     $frame = new Frame($node);
     $id = $frame->get_id();
     $this->_registry[$id] = $frame;
     if (!$node->hasChildNodes()) {
         return $frame;
     }
     for ($i = 0; $i < $node->childNodes->length; $i++) {
         $child = $node->childNodes->item($i);
         if (in_array($child->nodeName, self::$HIDDEN_TAGS)) {
             if ($child->nodeName !== "head" && $child->nodeName !== "HEAD" && ($child->nodeName !== "style" && $child->nodeName !== "STYLE")) {
                 $child->parentNode->removeChild($child);
             }
         } elseif (($child->nodeName === "#text" || $child->nodeName === "#TEXT") && $child->nodeValue == "") {
             $child->parentNode->removeChild($child);
         } elseif (($child->nodeName === "img" || $child->nodeName === "IMG") && $child->getAttribute("src") == "") {
             $child->parentNode->removeChild($child);
         } elseif (is_object($child)) {
             $frame->append_child($this->_build_tree_r($child), false);
         }
     }
     return $frame;
 }
Beispiel #3
0
 /**
  * Recursively adds {@link Frame} objects to the tree
  *
  * Recursively build a tree of Frame objects based on a dom tree.
  * No layout information is calculated at this time, although the
  * tree may be adjusted (i.e. nodes and frames for generated content
  * and images may be created).
  *
  * @param DOMNode $node the current DOMNode being considered
  *
  * @return Frame
  */
 protected function _build_tree_r(DOMNode $node)
 {
     $frame = new Frame($node);
     $id = $frame->get_id();
     $this->_registry[$id] = $frame;
     if (!$node->hasChildNodes()) {
         return $frame;
     }
     // Store the children in an array so that the tree can be modified
     $children = array();
     $length = $node->childNodes->length;
     for ($i = 0; $i < $length; $i++) {
         $children[] = $node->childNodes->item($i);
     }
     $index = 0;
     // INFO: We don't advance $index if a node is removed to avoid skipping nodes
     while ($index < count($children)) {
         $child = $children[$index];
         $nodeName = strtolower($child->nodeName);
         // Skip non-displaying nodes
         if (in_array($nodeName, self::$HIDDEN_TAGS)) {
             if ($nodeName !== "head" && $nodeName !== "style") {
                 $this->_remove_node($node, $children, $index);
             } else {
                 $index++;
             }
             continue;
         }
         // Skip empty text nodes
         if ($nodeName === "#text" && $child->nodeValue === "") {
             $this->_remove_node($node, $children, $index);
             continue;
         }
         // Skip empty image nodes
         if ($nodeName === "img" && $child->getAttribute("src") === "") {
             $this->_remove_node($node, $children, $index);
             continue;
         }
         if (is_object($child)) {
             $frame->append_child($this->_build_tree_r($child), false);
         }
         $index++;
     }
     return $frame;
 }