/** * @desc Function to update a node with new HTML. This is a public function because the TagArray class uses it. Users will not need to use this function. * * @param TreeNode $node - the node to update * @param string $html - the new HTML * @param string $fullReplace - replace the node itself (true) or just its children (false) * @return void * @author Karthik Viswanathan */ public function updateNode(&$node, $html, $fullReplace = false) { // @nodoc $root = new TreeNode('root'); // holder node $this->extractTags($html, $root); if ($fullReplace) { $newNode = $node->getParent(); $index = $newNode->remChild($node); $node->setParent(null); // array elements were shifted back one // thus, it is necessary to use $index - 1 // to insert the new nodes in the right place $newNode->addChildren($root->getChildren(), $index - 1); foreach ($root->getChildren() as $child) { $child->setParent($newNode); } // these children haven't had their parent set } else { $node->remAllChildren(); // copy all the child nodes foreach ($root->getChildren() as $child) { $node->addChild($child); $child->setParent($node); } } }