formatted = $this->bbcode_to_html($event->formatted);
$event->stripped = $this->bbcode_to_text($event->stripped);
}
}
private function bbcode_to_html($text) {
$text = preg_replace("/\[b\](.*?)\[\/b\]/s", "\\1", $text);
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "\\1", $text);
$text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text);
$text = preg_replace("/\[code\](.*?)\[\/code\]/s", "
\\1
", $text);
$text = preg_replace("/>>(\d+)/s", ">>\\1", $text);
$text = preg_replace("/>>([^\d].+)/", "\\1
", $text);
$text = preg_replace("/\[url=((?:https?|ftp|irc):\/\/.*?)\](.*?)\[\/url\]/s", "\\2", $text);
$text = preg_replace("/\[url\]((?:https?|ftp|irc):\/\/.*?)\[\/url\]/s", "\\1", $text);
$text = preg_replace("/\[\[(.*?)\]\]/s", "\\1", $text);
$text = str_replace("\n", "\n
", $text);
$text = preg_replace("/\[quote\](.*?)\[\/quote\]/s", "\\1
", $text);
$text = preg_replace("/\[quote=(.*?)\](.*?)\[\/quote\]/s", "Quoting \\1\\2
", $text);
$text = preg_replace("/\[h1\](.*?)\[\/h1\]/s", "\\1
", $text);
$text = preg_replace("/\[h2\](.*?)\[\/h2\]/s", "\\1
", $text);
$text = preg_replace("/\[h3\](.*?)\[\/h3\]/s", "\\1
", $text);
$text = preg_replace("/\[h4\](.*?)\[\/h4\]/s", "\\1
", $text);
$text = preg_replace("/\[ul\](.*?)\[\/ul\]/s", "", $text);
$text = preg_replace("/\[ol\](.*?)\[\/ol\]/s", "\\1
", $text);
$text = preg_replace("/\[li\](.*?)\[\/li\]/s", "\\1", $text);
$text = preg_replace("#\[\*\]#s", "", $text);
$text = preg_replace("#
<(li|ul|ol|/ul|/ol)>#s", "<\\1>", $text);
return $text;
}
private function bbcode_to_text($text) {
$text = preg_replace("/\[b\](.*?)\[\/b\]/s", "\\1", $text);
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "\\1", $text);
$text = preg_replace("/\[u\](.*?)\[\/u\]/s", "\\1", $text);
$text = preg_replace("/\[code\](.*?)\[\/code\]/s", "\\1", $text);
$text = preg_replace("/\[url=(.*?)\](.*?)\[\/url\]/s", "\\2", $text);
$text = preg_replace("/\[url\](.*?)\[\/url\]/s", "\\1", $text);
$text = preg_replace("/\[\[(.*?)\]\]/s", "\\1", $text);
$text = preg_replace("/\[quote\](.*?)\[\/quote\]/s", "", $text);
$text = preg_replace("/\[quote=(.*?)\](.*?)\[\/quote\]/s", "", $text);
$text = preg_replace("/\[h1\](.*?)\[\/h1\]/s", "\\1", $text);
$text = preg_replace("/\[h2\](.*?)\[\/h2\]/s", "\\1", $text);
$text = preg_replace("/\[h3\](.*?)\[\/h3\]/s", "\\1", $text);
$text = preg_replace("/\[h4\](.*?)\[\/h4\]/s", "\\1", $text);
$text = preg_replace("/\[ul\](.*?)\[\/ul\]/s", "\\1", $text);
$text = preg_replace("/\[ol\](.*?)\[\/ol\]/s", "\\1", $text);
$text = preg_replace("/\[li\](.*?)\[\/li\]/s", "\\1", $text);
$text = preg_replace("/\[\*\](.*?)/s", "\\1", $text);
return $text;
}
}
add_event_listener(new BBCode());
?>