/** * Sets the nodes parent * * @param BuckysBBCodeNode|BuckysBBCodeNodeContainer $parent */ public function set_parent(BuckysBBCodeNodeContainer $parent = null) { $this->parent = $parent; if ($parent instanceof BuckysBBCodeNodeContainerDocument) { $this->root = $parent; } else { $this->root = $parent->root(); } }
/** * Handles BuckysBBCode closing tag * * @param string $tag * @return bool */ private function tag_close($tag) { if (!$this->current_tag instanceof BuckysBBCodeNodeContainerDocument && $tag !== $this->current_tag->tag()) { $closing_tags = $this->bbcodes[$this->current_tag->tag()]->closing_tags(); if (in_array($tag, $closing_tags) || in_array('/' . $tag, $closing_tags)) { $this->current_tag = $this->current_tag->parent(); } } if ($this->current_tag instanceof BuckysBBCodeNodeContainerDocument) { return false; } else { if ($tag !== $this->current_tag->tag()) { // check if this is a tag inside another tag like // [tag1] [tag2] [/tag1] [/tag2] $node = $this->current_tag->find_parent_by_tag($tag); if ($node !== null) { $this->current_tag = $node->parent(); while (($node = $node->last_tag_node()) !== null) { $new_node = new BuckysBBCodeNodeContainerTag($node->tag(), $node->attributes()); $this->current_tag->add_child($new_node); $this->current_tag = $new_node; } } else { return false; } } else { $this->current_tag = $this->current_tag->parent(); } } return true; }