You are here

function XBBCodeFilter::pair_tag in Extensible BBCode 5

Same name and namespace in other branches
  1. 6 xbbcode.filter.inc \XBBCodeFilter::pair_tag()

File

./xbbcode-filter.php, line 77

Class

XBBCodeFilter

Code

function pair_tag($tagname, $isclosing, $args) {
  if (!in_array($tagname, $this->weighted_tags[$this->current_weight])) {
    return "[" . ($isclosing ? '/' : '') . "{$tagname}{$args}]";

    // don't pair unregistered tags
  }
  if ($isclosing) {
    if (!$this->tagpairs[$tagname]) {
      return "[/{$tagname}]";
    }

    // never opened? reject the closing tag.
    $last = array_pop($this->tagpairs[$tagname]);

    // read last stack entry and delete it.
    $this->tagpairs['#complete'][$last] = $tagname;
    return "[/{$tagname}-{$last}-]";
  }
  else {
    $this->tagpairs[$tagname][] = $this->pair_id;

    // add it to the stack
    $return = "[{$tagname}{$args}-{$this->pair_id}-]";

    // return the transformed opener.
    if ($this->tags[$tagname]['selfclosing']) {

      // if it's selfclosing...
      $return .= "[/{$tagname}-{$this->pair_id}-]";

      // also add a closing tag.
      $this->tagpairs['#complete'][$this->pair_id] = $tagname;

      // and add it to the finished stack.
    }
    $this->pair_id++;
    return $return;
  }
}