diff --git a/contrib/wiki/main.php b/contrib/wiki/main.php index 3a52e22f..6a9252ae 100644 --- a/contrib/wiki/main.php +++ b/contrib/wiki/main.php @@ -228,8 +228,11 @@ class Wiki extends Extension { private function create_display_html($page) { $owner = $page->get_owner(); + $tfe = new TextFormattingEvent($page->body); + send_event($tfe); + $html = "
"; - $html .= bbcode_to_html($page->body); + $html .= $tfe->formatted; $html .= "
"; $html .= "
\\1
", $text); - $text = preg_replace("/>>(\d+)/s", - ">>\\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); - return $text; -} - -function bbcode_to_text($text) { - $text = trim($text); - $text = html_escape($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); - return $text; -} - function build_thumb_html($image, $query=null) { global $config; $h_view_link = make_link("post/view/{$image->id}", $query); diff --git a/ext/bbcode/main.php b/ext/bbcode/main.php new file mode 100644 index 00000000..328dc7b7 --- /dev/null +++ b/ext/bbcode/main.php @@ -0,0 +1,42 @@ +formatted = $this->bbcode_to_html($event->formatted); + $event->stripped = $this->bbcode_to_text($event->stripped); + } + } + + private function bbcode_to_html($text) { + $text = trim($text); + $text = html_escape($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("/\[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); + return $text; + } + + private function bbcode_to_text($text) { + $text = trim($text); + $text = html_escape($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); + return $text; + } +} +add_event_listener(new BBCode()); +?> diff --git a/ext/comment/main.php b/ext/comment/main.php index d861c740..90ae9719 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -31,17 +31,20 @@ class Comment { // {{{ public function to_html($trim=false) { global $user; + $tfe = new TextFormattingEvent($this->comment); + send_event($tfe); + $i_uid = int_escape($this->owner_id); $h_name = html_escape($this->owner_name); $h_poster_ip = html_escape($this->poster_ip); - $h_comment = ($trim ? substr(bbcode_to_text($this->comment), 0, 50)."..." : bbcode_to_html($this->comment)); + $h_comment = ($trim ? substr($tfe->stripped, 0, 50)."..." : $tfe->formatted); $i_comment_id = int_escape($this->comment_id); $i_image_id = int_escape($this->image_id); $h_userlink = "$h_name"; $h_dellink = $user->is_admin() ? "
($h_poster_ip, comment)."');\" ". + "onclick=\"return confirm('Delete comment by $h_name:\\n".$tfe->stripped."');\" ". "href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del)" : ""; $h_imagelink = $trim ? ">>>\n" : ""; return "

$h_userlink: $h_comment $h_imagelink $h_dellink

";