email bbcode tag

This commit is contained in:
Shish 2009-12-30 09:13:57 +00:00
parent 830635c5a9
commit f3cd5d03a4
2 changed files with 8 additions and 0 deletions

View File

@ -19,6 +19,7 @@ class BBCode extends FormatterExtension {
$text = preg_replace("/&gt;&gt;([^\d].+)/", "<blockquote><small>\\1</small></blockquote>", $text); $text = preg_replace("/&gt;&gt;([^\d].+)/", "<blockquote><small>\\1</small></blockquote>", $text);
$text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "<a href=\"\\1\">\\2</a>", $text); $text = preg_replace("/\[url=((?:https?|ftp|irc|mailto):\/\/.*?)\](.*?)\[\/url\]/s", "<a href=\"\\1\">\\2</a>", $text);
$text = preg_replace("/\[url\]((?:https?|ftp|irc|mailto):\/\/.*?)\[\/url\]/s", "<a href=\"\\1\">\\1</a>", $text); $text = preg_replace("/\[url\]((?:https?|ftp|irc|mailto):\/\/.*?)\[\/url\]/s", "<a href=\"\\1\">\\1</a>", $text);
$text = preg_replace("/\[email\](.*?)\[\/email\]/s", "<a href=\"mailto:\\1\">\\1</a>", $text);
$text = preg_replace("/\[img\](https?:\/\/.*?)\[\/img\]/s", "<img src=\"\\1\">", $text); $text = preg_replace("/\[img\](https?:\/\/.*?)\[\/img\]/s", "<img src=\"\\1\">", $text);
$text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "<a href=\"".make_link("wiki/\\1")."\">\\2</a>", $text); $text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "<a href=\"".make_link("wiki/\\1")."\">\\2</a>", $text);
$text = preg_replace("/\[\[([^\]]+)\]\]/s", "<a href=\"".make_link("wiki/\\1")."\">\\1</a>", $text); $text = preg_replace("/\[\[([^\]]+)\]\]/s", "<a href=\"".make_link("wiki/\\1")."\">\\1</a>", $text);
@ -60,6 +61,7 @@ class BBCode extends FormatterExtension {
$text = preg_replace("/\[code\](.*?)\[\/code\]/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", "\\2", $text);
$text = preg_replace("/\[url\](.*?)\[\/url\]/s", "\\1", $text); $text = preg_replace("/\[url\](.*?)\[\/url\]/s", "\\1", $text);
$text = preg_replace("/\[email\](.*?)\[\/email\]/s", "\\1", $text);
$text = preg_replace("/\[img\](.*?)\[\/img\]/s", "", $text); $text = preg_replace("/\[img\](.*?)\[\/img\]/s", "", $text);
$text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "\\2", $text); $text = preg_replace("/\[\[([^\|\]]+)\|([^\]]+)\]\]/s", "\\2", $text);
$text = preg_replace("/\[\[([^\]]+)\]\]/s", "\\1", $text); $text = preg_replace("/\[\[([^\]]+)\]\]/s", "\\1", $text);

View File

@ -62,6 +62,12 @@ class BBCodeUnitTest extends UnitTestCase {
"[url=javascript:alert(&quot;owned&quot;)]click to fail[/url]"); "[url=javascript:alert(&quot;owned&quot;)]click to fail[/url]");
} }
public function testURL() {
$this->assertEqual(
$this->filter("[email]spam@shishnet.org[/email]"),
"<a href=\"mailto:spam@shishnet.org\">spam@shishnet.org</a>");
}
private function filter($in) { private function filter($in) {
$bb = new BBCode(); $bb = new BBCode();
$tfe = new TextFormattingEvent($in); $tfe = new TextFormattingEvent($in);