Пример #1
0
 /**
  * Sets the nodes parent
  * @param Node_Container $parent
  */
 public function set_parent(Node_Container $parent = null)
 {
     $this->parent = $parent;
     if ($parent instanceof Node_Container_Document) {
         $this->root = $parent;
     } else {
         $this->root = $parent->root();
     }
 }
Пример #2
0
 /**
  * Handles BBCode closing tag
  * @param string $tag
  * @return bool
  */
 private function tag_close($tag)
 {
     if (!$this->current_tag instanceof Node_Container_Document && $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 Node_Container_Document) {
         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 Node_Container_Tag($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;
 }