function append_child(Frame $child, $update_node = true) { while ($child instanceof Frame_Decorator) { $child = $child->_frame; } $this->_frame->append_child($child, $update_node); }
/** * 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; } // Fixes 'cannot access undefined property for object with // overloaded access', fix by Stefan radulian // <*****@*****.**> //foreach ($node->childNodes as $child) { // Store the children in an array so that the tree can be modified $children = array(); for ($i = 0; $i < $node->childNodes->length; $i++) { $children[] = $node->childNodes->item($i); } foreach ($children as $child) { $node_name = mb_strtolower($child->nodeName); // Skip non-displaying nodes if (in_array($node_name, self::$_HIDDEN_TAGS)) { if ($node_name !== "head" && $node_name !== "style") { $child->parentNode->removeChild($child); } continue; } // Skip empty text nodes if ($node_name === "#text" && $child->nodeValue == "") { $child->parentNode->removeChild($child); continue; } // Skip empty image nodes if ($node_name === "img" && $child->getAttribute("src") == "") { $child->parentNode->removeChild($child); continue; } $frame->append_child($this->_build_tree_r($child), false); } return $frame; }
/** * 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; // Fixes 'cannot access undefined property for object with // overloaded access', fix by Stefan radulian // <*****@*****.**> //foreach ($node->childNodes as $child) { // Store the children in an array so that the tree can be modified $children = array(); for ($i = 0; $i < $node->childNodes->length; $i++) $children[] = $node->childNodes->item($i); foreach ($children as $child) { // Skip non-displaying nodes if ( in_array( mb_strtolower($child->nodeName), self::$_HIDDEN_TAGS) ) { if ( mb_strtolower($child->nodeName) != "head" && mb_strtolower($child->nodeName) != "style" ) $child->parentNode->removeChild($child); continue; } // Skip empty text nodes if ( $child->nodeName == "#text" && $child->nodeValue == "" ) { $child->parentNode->removeChild($child); continue; } // Add a container frame for images if ( $child->nodeName == "img" ) { $img_node = $child->ownerDocument->createElement("img_inner"); // Move attributes to inner node foreach ( $child->attributes as $attr => $attr_node ) { // Skip style, but move all other attributes if ( $attr == "style" ) continue; $img_node->setAttribute($attr, $attr_node->value); } foreach ( $child->attributes as $attr => $node ) { if ( $attr == "style" ) continue; $child->removeAttribute($attr); } $child->appendChild($img_node); } $frame->append_child($this->_build_tree_r($child), false); } 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; } $children = array(); for ($i = 0; $i < $node->childNodes->length; $i++) { $children[] = $node->childNodes->item($i); } foreach ($children as $child) { $node_name = mb_strtolower($child->nodeName); if (in_array($node_name, self::$_HIDDEN_TAGS)) { if ($node_name !== "head" && $node_name !== "style") { $child->parentNode->removeChild($child); } continue; } if ($node_name === "#text" && $child->nodeValue == "") { $child->parentNode->removeChild($child); continue; } if ($node_name === "img" && $child->getAttribute("src") == "") { $child->parentNode->removeChild($child); continue; } $frame->append_child($this->_build_tree_r($child), false); } return $frame; }
/** * 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); $frame->set_id($id = uniqid(rand())); $this->_registry[$id] = $frame; if (!$node->hasChildNodes()) { return $frame; } foreach ($node->childNodes as $child) { // Skip non-displaying nodes if (in_array($child->nodeName, self::$_HIDDEN_TAGS)) { continue; } // Skip empty #text nodes if ($child->nodeName == "#text" && $child->nodeValue == "") { continue; } // Add a container frame for images if ($child->nodeName == "img") { $img_node = $child->ownerDocument->createElement("img_inner"); // Move attributes to inner node foreach ($child->attributes as $attr => $attr_node) { // Skip style, but move all other attributes if ($attr == "style") { continue; } $img_node->setAttribute($attr, $attr_node->value); } foreach ($child->attributes as $attr => $node) { if ($attr == "style") { continue; } $child->removeAttribute($attr); } $child->appendChild($img_node); } $frame->append_child($this->_build_tree_r($child), false); } return $frame; }
/** * 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) { $node_name = mb_strtolower($node->nodeName); switch ($node_name) { // Let's dump inner svg elements into src attribute so the image renderer could take care of it case 'svg': /** @var DOMElement $node; */ if ($node->hasChildNodes()) { $node->setAttribute('src', 'data:image/svg+xml,' . self::exportOuterXML($node)); } $frame = new Frame($node); $id = $frame->get_id(); $this->_registry[$id] = $frame; return $frame; default: $frame = new Frame($node); $id = $frame->get_id(); $this->_registry[$id] = $frame; if (!$node->hasChildNodes()) { return $frame; } // Fixes 'cannot access undefined property for object with // overloaded access', fix by Stefan radulian // <*****@*****.**> //foreach ($node->childNodes as $child) { // Store the children in an array so that the tree can be modified $children = array(); for ($i = 0; $i < $node->childNodes->length; $i++) { $children[] = $node->childNodes->item($i); } foreach ($children as $child) { $node_name = mb_strtolower($child->nodeName); // Skip non-displaying nodes if (in_array($node_name, self::$_HIDDEN_TAGS)) { if ($node_name !== "head" && $node_name !== "style") { $child->parentNode->removeChild($child); } continue; } // Skip empty text nodes if ($node_name === "#text" && $child->nodeValue == "") { $child->parentNode->removeChild($child); continue; } // Skip empty image nodes if ($node_name === "img" && $child->getAttribute("src") == "") { $child->parentNode->removeChild($child); continue; } $frame->append_child($this->_build_tree_r($child), false); } return $frame; } }