Example #1
0
 function remove_child(Frame $child, $update_node = true)
 {
     if ($child->_parent !== $this) {
         throw new DOMPDF_Exception("Child not found in this frame");
     }
     if ($update_node) {
         $this->_node->removeChild($child->_node);
     }
     if ($child === $this->_first_child) {
         $this->_first_child = $child->_next_sibling;
     }
     if ($child === $this->_last_child) {
         $this->_last_child = $child->_prev_sibling;
     }
     if ($child->_prev_sibling) {
         $child->_prev_sibling->_next_sibling = $child->_next_sibling;
     }
     if ($child->_next_sibling) {
         $child->_next_sibling->_prev_sibling = $child->_prev_sibling;
     }
     $child->_next_sibling = null;
     $child->_prev_sibling = null;
     $child->_parent = null;
     return $child;
 }
Example #2
0
function recursiveStripQuotes(DOMNode $node)
{
    if (!$node->childNodes) {
        return;
    }
    $purge = array();
    foreach ($node->childNodes as $child) {
        $class = null;
        if ($child->attributes) {
            $class = $child->attributes->getNamedItem('class');
        }
        if ($class && $class->value == 'quoteheader') {
            $purge[] = $child;
        } elseif ($class && $class->value == 'quotefooter') {
            $purge[] = $child;
        } elseif ($child->nodeName == 'blockquote') {
            $purge[] = $child;
        } else {
            recursiveStripQuotes($child);
        }
    }
    foreach ($purge as $child) {
        $node->removeChild($child);
    }
    return $node;
}
Example #3
0
 /**
  * Delete a file from the list.
  *
  * @param string $file The file name.
  *
  * @return NULL
  */
 public function delete($file)
 {
     $this->_dir_list->deleteFile($file);
     if (isset($this->_install_list[$file])) {
         $this->_xml->removeWhitespace($this->_install_list[$file]->nextSibling);
         $this->_filelist->removeChild($this->_install_list[$file]);
     }
 }
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 #5
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 #6
0
 /**
  * nastavi obsah item
  * @param string $value
  */
 public function setContent($value)
 {
     try {
         if (htmlspecialchars($value) == $value && htmlspecialchars_decode($value) == $value) {
             $this->node->nodeValue = $value;
         } else {
             foreach ($this->node->childNodes as $nodeChild) {
                 $this->node->removeChild($nodeChild);
             }
             $this->node->appendChild($this->config->getDom()->createCDATASection($value));
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Example #7
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);
         }
     }
 }
 protected function visitProperty(PropertyMetadata $metadata, $data, Context $context)
 {
     $v = $metadata->getValue($data);
     if ($metadata->xmlAttribute) {
         $attributeName = $this->namingStrategy->translateName($metadata);
         $this->currentNodes = $this->document->createElement('tmp');
         $context->accept($v, $metadata->type);
         $node = $this->createAttributeNode($metadata, $attributeName);
         $node->appendChild($this->createTextNode((string) $this->currentNodes->nodeValue));
         return $this->currentNodes = $node;
     }
     if ($metadata->xmlValue) {
         $this->currentNodes = $this->document->createElement('tmp');
         $context->accept($v, $metadata->type);
         $node = $this->currentNodes->childNodes->item(0);
         $this->currentNodes->removeChild($node);
         return $this->currentNodes = $node;
     }
     if ($metadata->xmlAttributeMap) {
         $attributes = [];
         foreach ($v as $key => $value) {
             $node = $this->createAttributeNode($metadata, $key);
             $node->appendChild($this->createTextNode((string) $value));
             $attributes[] = $node;
         }
         return $this->currentNodes = $attributes;
     }
     if (null === $v && !$context->shouldSerializeNull()) {
         return $this->currentNodes = null;
     }
     $elementName = $this->namingStrategy->translateName($metadata);
     $this->currentNodes = $this->createElement($metadata->xmlNamespace, $elementName);
     $context->accept($v, $metadata->type);
     if (is_object($v) && null !== $v && !$metadata instanceof AdditionalPropertyMetadata && $context->isVisiting($v)) {
         return $this->currentNodes = null;
     }
     if ($metadata->xmlCollectionInline || $metadata->inline) {
         $children = iterator_to_array($this->currentNodes->childNodes);
         foreach ($children as $childNode) {
             $this->currentNodes->removeChild($childNode);
         }
         $this->currentNodes = $children;
     }
     return $this->currentNodes;
 }
Example #9
0
 public static function emptyNodeContent(DOMNode $oNode)
 {
     while ($oNode->childNodes->length > 0) {
         $oNode->removeChild($oNode->childNodes->item(0));
     }
 }
Example #10
0
 /**
  * Delete document child element
  *
  * @param OpenDocument_Element $element
  * @access public
  */
 public function deleteElement(OpenDocument_Element $element)
 {
     $this->cursor->removeChild($element->getNode());
     unset($element);
 }
Example #11
0
 public static function removeChilds(\DOMNode $ref)
 {
     while ($ref->hasChildNodes()) {
         $ref->removeChild($ref->firstChild);
     }
 }
 /**
  * Удалить из дерева элементов все элементы, у которых
  * локальное имя соответствует указанному
  *
  * @param DOMNode $node
  * @param $name
  * @return DOMNode
  */
 private function removeChildsByName(DOMNode $node, $name)
 {
     if ($node->hasChildNodes()) {
         foreach ($node->childNodes as $child) {
             if ($child->localName == $name) {
                 $node->removeChild($child);
             } else {
                 $this->removeChildsByName($child, $name);
             }
         }
     }
     return $node;
 }
Example #13
0
 /**
  * Appends the xml structure with our values.
  *
  * @param \DOMNode $node
  * @param boolean $printDefaults
  * @param bool $printComments
  * @return \DOMElement
  * @throws \Exception
  */
 public function appendXml(\DOMNode $node, $printDefaults = false, $printComments = false)
 {
     $doc = $node instanceof \DOMDocument ? $node : $node->ownerDocument;
     if ($printComments) {
         $this->lastRootElementComment = $doc->createComment($this->docBlock);
         $node->appendChild($this->lastRootElementComment);
     }
     try {
         $rootNode = $doc->createElement($this->rootName);
         $node->appendChild($rootNode);
     } catch (\DOMException $e) {
         throw new \Exception(sprintf('Can not create xml element `%s`', $this->rootName), 0, $e);
     }
     foreach ($this as $key => $val) {
         $this->appendXmlProperty($key, $rootNode, $printDefaults, $printComments);
     }
     foreach ($this->additionalNodes as $k => $v) {
         $this->appendXmlValue($k, $v, $rootNode, $printDefaults, $printComments);
     }
     foreach ($this->additionalAttributes as $k => $v) {
         $rootNode->setAttribute($k, (string) $v);
     }
     if ($this->lastRootElementComment && !$this->lastRootElementComment->substringData(0, 1)) {
         $node->removeChild($this->lastRootElementComment);
     }
     return $rootNode;
 }
Example #14
0
 protected function removeBlackNodes(\DOMNode $node, array $blackList)
 {
     foreach ($blackList as $blackNode) {
         $node->removeChild($blackNode);
     }
     return $node;
 }
Example #15
0
 /**
 	Perform a "replaceContent" operation.
 
 	@param $oAction		The taconite action.
 	@param $oElement	The document element.
 */
 protected function applyTagReplaceContent(DOMNode $oAction, DOMNode $oElement)
 {
     foreach ($oElement->childNodes as $oChild) {
         $oElement->removeChild($oChild);
     }
     $this->applyTagAppend($oAction, $oElement);
 }
Example #16
0
 static function remove_text_nodes(DOMNode $node)
 {
     $children = array();
     for ($i = 0; $i < $node->childNodes->length; $i++) {
         $child = $node->childNodes->item($i);
         if ($child->nodeName === "#text") {
             $children[] = $child;
         }
     }
     foreach ($children as $child) {
         $node->removeChild($child);
     }
 }
 /**
  * Search a WSDL XML DOM for "import" tags and import the files into 
  * one large DOM for the entire WSDL structure 
  * @ignore
  */
 protected function mergeWSDLImports(DOMNode &$wsdlDOM, $continued = false, DOMDocument &$newRootDocument = NULL)
 {
     static $rootNode = NULL;
     static $rootDocument = NULL;
     /* If this is an external call, find the "root" defintions node */
     if ($continued == false) {
         $rootNode = $wsdlDOM->getElementsByTagName('definitions')->item(0);
         $rootDocument = $wsdlDOM;
     }
     if ($newRootDocument == NULL) {
         $newRootDocument = $rootDocument;
     }
     //if (self::$debugMode) echo "Processing Node: ".$wsdlDOM->nodeName." which has ".$wsdlDOM->childNodes->length." child nodes".PHP_EOL;
     $nodesToRemove = array();
     /* Loop through the Child nodes of the provided DOM */
     foreach ($wsdlDOM->childNodes as $childNode) {
         //if (self::$debugMode) echo "\tProcessing Child Node: ".$childNode->nodeName." (".$childNode->localName.") which has ".$childNode->childNodes->length." child nodes".PHP_EOL;
         /* If this child is an IMPORT node, get the referenced WSDL, and remove the Import */
         if ($childNode->localName == 'import') {
             /* Get the location of the imported WSDL */
             if ($childNode->hasAttribute('location')) {
                 $importURI = $childNode->getAttribute('location');
             } else {
                 if ($childNode->hasAttribute('schemaLocation')) {
                     $importURI = $childNode->getAttribute('schemaLocation');
                 } else {
                     $importURI = NULL;
                 }
             }
             /* Only import if we found a URI - otherwise, don't change it! */
             if ($importURI != NULL) {
                 if (self::$debugMode) {
                     echo "\tImporting data from: " . $importURI . PHP_EOL;
                 }
                 $importDOM = new DOMDocument();
                 @$importDOM->load($importURI);
                 /* Find the "Definitions" on this imported node */
                 $importDefinitions = $importDOM->getElementsByTagName('definitions')->item(0);
                 /* If we have "Definitions", import them one by one - Otherwise, just import at this level */
                 if ($importDefinitions != NULL) {
                     /* Add all the attributes (namespace definitions) to the root definitions node */
                     foreach ($importDefinitions->attributes as $attribute) {
                         /* Don't copy the "TargetNamespace" attribute */
                         if ($attribute->name != 'targetNamespace') {
                             $rootNode->setAttributeNode($attribute);
                         }
                     }
                     $this->mergeWSDLImports($importDefinitions, true, $importDOM);
                     foreach ($importDefinitions->childNodes as $importNode) {
                         //if (self::$debugMode) echo "\t\tInserting Child: ".$importNode->C14N(true).PHP_EOL;
                         $importNode = $newRootDocument->importNode($importNode, true);
                         $wsdlDOM->insertBefore($importNode, $childNode);
                     }
                 } else {
                     //if (self::$debugMode) echo "\t\tInserting Child: ".$importNode->C14N(true).PHP_EOL;
                     $importNode = $newRootDocument->importNode($importDOM->firstChild, true);
                     $wsdlDOM->insertBefore($importNode, $childNode);
                 }
                 //if (self::$debugMode) echo "\t\tRemoving Child: ".$childNode->C14N(true).PHP_EOL;
                 $nodesToRemove[] = $childNode;
             }
         } else {
             //if (self::$debugMode) echo 'Preserving node: '.$childNode->localName.PHP_EOL;
             if ($childNode->hasChildNodes()) {
                 $this->mergeWSDLImports($childNode, true);
             }
         }
     }
     /* Actually remove the nodes (not done in the loop, as it messes up the ForEach pointer!) */
     foreach ($nodesToRemove as $node) {
         $wsdlDOM->removeChild($node);
     }
     return $wsdlDOM;
 }
Example #18
0
File: Rule.php Project: funddy/yodo
 public function sanitize(\DOMNode $node)
 {
     if ($node->hasChildNodes()) {
         for ($i = 0; $i < $node->childNodes->length;) {
             $childNode = $node->childNodes->item($i);
             if ($this->childNodeIsNotAllowed($childNode) && $childNode->nodeType !== XML_TEXT_NODE) {
                 $node->removeChild($childNode);
                 continue;
             }
             $i++;
         }
     }
     $this->sanitizeAttributes($node);
 }
Example #19
0
 /**
  * Visit paragraph
  *
  * @param DOMNode $root
  * @param ezcDocumentWikiNode $node
  * @return void
  */
 protected function visitParagraph(DOMNode $root, ezcDocumentWikiNode $node)
 {
     $para = $this->document->createElement('para');
     $root->appendChild($para);
     foreach ($node->nodes as $child) {
         $this->visitNode($para, $child);
     }
     // Check if paragraph should be converted into a literalayout section,
     // because it contains intentional line breaks. This marker is set by
     // the visitLineBreak() method.
     if ($para->hasAttribute('type') && $para->getAttribute('type') === 'literallayout') {
         // Change paragraph into a literallayout section
         $newPara = $this->document->createElement('literallayout');
         $newPara->setAttribute('class', 'normal');
         $root->appendChild($newPara);
         // Move all childs to new paragraph
         foreach ($para->childNodes as $child) {
             $newPara->appendChild($child->cloneNode(true));
         }
         // Remove old paragraph
         $root->removeChild($para);
     }
 }
 /**
  * recursive function to delete all children of a node
  * 
  * @param DOMNode $node
  */
 private function deleteChildren($node)
 {
     while (isset($node->firstChild)) {
         $this->deleteChildren($node->firstChild);
         $node->removeChild($node->firstChild);
     }
 }
Example #21
0
 /**
  * Remove all child nodes of the parent node
  * 
  * @param DOMNode $node // parent node
  * 
  * @return void
  */
 static function deleteChildren($node)
 {
     while (isset($node->firstChild)) {
         self::deleteChildren($node->firstChild);
         $node->removeChild($node->firstChild);
     }
 }
Example #22
0
 /**
  * Replace a certain node with its child nodes.
  *
  * @param DOMNode $parent An instance of DOMNode.
  *
  * @return void
  */
 private static function _replaceParentWithChildren(DOMNode $parent)
 {
     $child = $parent->firstChild;
     while ($child) {
         $nextChild = $child->nextSibling;
         $parent->removeChild($child);
         $parent->parentNode->insertBefore($child, $parent);
         $child = $nextChild;
     }
     $parent->parentNode->removeChild($parent);
 }
Example #23
0
 /**
  * Suppression des balises fonts imbriquées
  *  
  * @param DOMNode &$node noeud à parcourir
  * 
  * @return void
  */
 function recursiveRemoveNestedFont(DOMNode &$node)
 {
     if (!$node->hasChildNodes()) {
         return;
     }
     foreach ($node->childNodes as $child) {
         /** @var DOMElement $node->firstChild */
         if ($node->nodeName == "font" && $child->nodeName == "font" && $node->firstChild && $node->firstChild === $node->lastChild) {
             if ($node->firstChild->getAttribute("family") == "") {
                 $node->firstChild->setAttribute("family", $node->getAttribute("family"));
             }
             $child = $node->removeChild($node->firstChild);
             $parent = $node->parentNode;
             $parent->insertBefore($child, $node);
             $parent->removeChild($node);
         }
         CHtmlToPDF::recursiveRemoveNestedFont($child);
     }
 }
 function fixListItem(DOMNode $item)
 {
     // The HTML parser in libxml2 doesn't seem to properly handle
     // many cases of implied close tags, apparently because it doesn't
     // understand the nesting rules specified in the HTML DTD.
     //
     // This leads to sequences of adjacent <dt>s or <dd>s being incorrectly
     // interpreted as parent->child trees instead of siblings:
     //
     // When parsing this input: "<dt>aaa <dt>bbb"
     // should be equivalent to: "<dt>aaa </dt><dt>bbb</dt>"
     // but we're seeing instead: "<dt>aaa <dt>bbb</dt></dt>"
     //
     // It does at least know that going from dt to dd, or dd to dt,
     // should make a break.
     $toMove = array();
     foreach ($item->childNodes as $node) {
         if ($node->nodeType == XML_ELEMENT_NODE) {
             $el = strtolower($node->nodeName);
             if ($el == 'dt' || $el == 'dd') {
                 // dt & dd cannot contain each other;
                 // This node was incorrectly placed; move it up a level!
                 $toMove[] = $node;
             }
             if ($el == 'dl') {
                 // Sublist.
                 // Technically, these can only appear inside a <dd>.
                 $this->fixList($node);
             }
         }
     }
     $parent = $item->parentNode;
     $next = $item->nextSibling;
     foreach ($toMove as $node) {
         $item->removeChild($node);
         $parent->insertBefore($node, $next);
         $this->fixListItem($node);
     }
 }
 /**
  * Check if the list of nodes to be enclose aren't just empty text nodes, if not
  * alters the dom to enclose the specified nodes with the micro-update livepress mark tag.
  *
  * @access private
  *
  * @param array       $nodes_indexes List of nodes indexes to be enclosed.
  * @param DOMNode     $parent_node   Parent node of the nodes to be enclosed.
  * @param DOMDocument $dom           The DOM where the nodes belongs.
  * @param array       $current_ids   All the current used ids on updates.
  */
 private function enclose_indexes_by_chunk_mark_tag($nodes_indexes, $parent_node, $dom, $current_ids)
 {
     $nodes = array();
     foreach ($nodes_indexes as $i) {
         $nodes[] = $parent_node->childNodes->item($i);
     }
     $just_empty_textnode = TRUE;
     $took_off_len = 0;
     foreach ($nodes as $node) {
         if ($node->nodeType == XML_TEXT_NODE && $node->isWhitespaceInElementContent()) {
             $took_off_len++;
         } else {
             $just_empty_textnode = FALSE;
             break;
         }
     }
     if ($just_empty_textnode) {
         return;
     }
     $nodes = array_slice($nodes, $took_off_len);
     $last_node = $nodes[count($nodes) - 1];
     $ref_node = $last_node->nextSibling;
     foreach ($nodes as $node) {
         $parent_node->removeChild($node);
     }
     return $this->enclose_nodes_by_chunk_mark_tag($nodes, $parent_node, $dom, $current_ids, $ref_node);
 }
Example #26
0
 /**
  * Adds comments around a <!CDATA section in a \DOMNode.
  *
  * \DOMDocument::loadHTML() in \Drupal\Component\Utility\Html::load() makes
  * CDATA sections from the contents of inline script and style tags. This can
  * cause HTML4 browsers to throw exceptions.
  *
  * This function attempts to solve the problem by creating a
  * \DOMDocumentFragment to comment the CDATA tag.
  *
  * @param \DOMNode $node
  *   The element potentially containing a CDATA node.
  * @param string $comment_start
  *   (optional) A string to use as a comment start marker to escape the CDATA
  *   declaration. Defaults to '//'.
  * @param string $comment_end
  *   (optional) A string to use as a comment end marker to escape the CDATA
  *   declaration. Defaults to an empty string.
  */
 public static function escapeCdataElement(\DOMNode $node, $comment_start = '//', $comment_end = '')
 {
     foreach ($node->childNodes as $child_node) {
         if ($child_node instanceof \DOMCdataSection) {
             $embed_prefix = "\n<!--{$comment_start}--><![CDATA[{$comment_start} ><!--{$comment_end}\n";
             $embed_suffix = "\n{$comment_start}--><!]]>{$comment_end}\n";
             // Prevent invalid cdata escaping as this would throw a DOM error.
             // This is the same behavior as found in libxml2.
             // Related W3C standard: http://www.w3.org/TR/REC-xml/#dt-cdsection
             // Fix explanation: http://wikipedia.org/wiki/CDATA#Nesting
             $data = str_replace(']]>', ']]]]><![CDATA[>', $child_node->data);
             $fragment = $node->ownerDocument->createDocumentFragment();
             $fragment->appendXML($embed_prefix . $data . $embed_suffix);
             $node->appendChild($fragment);
             $node->removeChild($child_node);
         }
     }
 }
Example #27
0
 static function removeChild(DOMNode $parent, DOMNode $child)
 {
     if ($child->parentNode === $parent) {
         $parent->removeChild($child);
     }
 }
Example #28
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 #29
0
 /**
  * 
  * Supprime de façon récursive, tous les noeuds enfants d'un noeud HTML
  */
 private function _removeHtmlNodeChildren(DOMNode $oNode)
 {
     while (isset($oNode->firstChild)) {
         self::_removeHtmlNodeChildren($oNode->firstChild);
         $oNode->removeChild($oNode)->firstChild;
     }
 }