bbcode support moved to a generic text formatting extension
git-svn-id: file:///home/shish/svn/shimmie2/trunk@241 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
parent
9298649c30
commit
8ad916c136
4 changed files with 51 additions and 33 deletions
|
@ -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 = "<div class='wiki-page'>";
|
||||
$html .= bbcode_to_html($page->body);
|
||||
$html .= $tfe->formatted;
|
||||
$html .= "<hr>";
|
||||
$html .= "<p class='wiki-footer'>Revision {$page->revision} by ".
|
||||
"<a href='".make_link("user/{$owner->name}")."'>{$owner->name}</a> at {$page->date} ";
|
||||
|
|
|
@ -107,36 +107,6 @@ function make_link($page, $query=null) {
|
|||
}
|
||||
}
|
||||
|
||||
function bbcode_to_html($text) {
|
||||
$text = trim($text);
|
||||
$text = html_escape($text);
|
||||
$text = preg_replace("/\[b\](.*?)\[\/b\]/s", "<b>\\1</b>", $text);
|
||||
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $text);
|
||||
$text = preg_replace("/\[u\](.*?)\[\/u\]/s", "<u>\\1</u>", $text);
|
||||
$text = preg_replace("/\[code\](.*?)\[\/code\]/s", "<pre>\\1</pre>", $text);
|
||||
$text = preg_replace("/>>(\d+)/s",
|
||||
"<a href='".make_link("post/view/\\1")."'>>>\\1</a>", $text);
|
||||
$text = preg_replace("/\[url=((?:https?|ftp|irc):\/\/.*?)\](.*?)\[\/url\]/s", "<a href='\\1'>\\2</a>", $text);
|
||||
$text = preg_replace("/\[url\]((?:https?|ftp|irc):\/\/.*?)\[\/url\]/s", "<a href='\\1'>\\1</a>", $text);
|
||||
$text = preg_replace("/\[\[(.*?)\]\]/s",
|
||||
"<a href='".make_link("wiki/\\1")."'>\\1</a>", $text);
|
||||
$text = str_replace("\n", "\n<br>", $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);
|
||||
|
|
42
ext/bbcode/main.php
Normal file
42
ext/bbcode/main.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
class BBCode extends Extension {
|
||||
public function receive_event($event) {
|
||||
if(is_a($event, 'TextFormattingEvent')) {
|
||||
$event->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", "<b>\\1</b>", $text);
|
||||
$text = preg_replace("/\[i\](.*?)\[\/i\]/s", "<i>\\1</i>", $text);
|
||||
$text = preg_replace("/\[u\](.*?)\[\/u\]/s", "<u>\\1</u>", $text);
|
||||
$text = preg_replace("/\[code\](.*?)\[\/code\]/s", "<pre>\\1</pre>", $text);
|
||||
$text = preg_replace("/>>(\d+)/s",
|
||||
"<a href='".make_link("post/view/\\1")."'>>>\\1</a>", $text);
|
||||
$text = preg_replace("/\[url=((?:https?|ftp|irc):\/\/.*?)\](.*?)\[\/url\]/s", "<a href='\\1'>\\2</a>", $text);
|
||||
$text = preg_replace("/\[url\]((?:https?|ftp|irc):\/\/.*?)\[\/url\]/s", "<a href='\\1'>\\1</a>", $text);
|
||||
$text = preg_replace("/\[\[(.*?)\]\]/s",
|
||||
"<a href='".make_link("wiki/\\1")."'>\\1</a>", $text);
|
||||
$text = str_replace("\n", "\n<br>", $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());
|
||||
?>
|
|
@ -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 = "<a href='".make_link("user/$h_name")."'>$h_name</a>";
|
||||
$h_dellink = $user->is_admin() ?
|
||||
"<br>($h_poster_ip, <a ".
|
||||
"onclick=\"return confirm('Delete comment by $h_name:\\n".bbcode_to_text($this->comment)."');\" ".
|
||||
"onclick=\"return confirm('Delete comment by $h_name:\\n".$tfe->stripped."');\" ".
|
||||
"href='".make_link("comment/delete/$i_comment_id/$i_image_id")."'>Del</a>)" : "";
|
||||
$h_imagelink = $trim ? "<a href='".make_link("post/view/$i_image_id")."'>>>></a>\n" : "";
|
||||
return "<p>$h_userlink: $h_comment $h_imagelink $h_dellink</p>";
|
||||
|
|
Reference in a new issue