You are here

function XBBCodeFilter::process in Extensible BBCode 5

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

File

./xbbcode-filter.php, line 27

Class

XBBCodeFilter

Code

function process($text) {

  /* this function adds forms like these [tag-n-] and later removes them.
   * to avoid unexpected side-effects, if such forms exist already,
   * we must first hide them, then restore them after removal.
   */
  $otc = _xbbcode_one_time_code($text);

  // generate a code that does not occur in the text.
  $text = preg_replace('/\\[([^\\]]+-[0-9]+-)\\]/i', '[$1' . $otc . ']', $text);

  // mask existing forms
  list($text, $pairs) = $this
    ->pair_tags($text);

  // pair up the tags
  if ($pairs) {
    ksort($pairs);
  }

  // sort by key.
  $text = $this
    ->filter_tags($text, $pairs);

  // filter the tags we found
  $text = preg_replace('/\\[([^\\]]+-[0-9]+-)' . $otc . '\\]/i', '[$1]', $text);

  // restore any masked stuff
  return $text;
}