Fix #114: update BBCode to allow easy linking to Trac tickets, wiki and changesets.

svn path=/trunk/boinc/; revision=12632
This commit is contained in:
Rytis Slatkevičius 2007-05-09 19:30:46 +00:00
parent 78807f659c
commit 0379a5a655
4 changed files with 104 additions and 91 deletions

View File

@ -4657,3 +4657,12 @@ David 9 May 2007
sched/
sched_send.C
server_types.h
Rytis 9 May 2007
- Update BBCode to allow easy linking to Trac tickets, wiki and changesets.
html/
user/
bbcode.php
inc/
text_transform.inc

View File

@ -117,73 +117,77 @@ function get_transform_settings_from_user($user, $options = '') {
* Converts bbcode to proper HTML
**/
function bb2html($text) {
$urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)";
$httpsregex = "(?:\"?)https\:\/\/([^\[\"<\ ]+)(?:\"?)";
// List of allowable tags
$bbtags = array (
"@\[b\](.*?)\[/b\]@is",
"@\[i\](.*?)\[/i\]@is",
"@\[u\](.*?)\[/u\]@is",
"@\[url=$httpsregex\](.*?)\[/url\]@i",
"@\[url\]$httpsregex\[/url\]@i",
"@\[link=$urlregex\](.*?)\[/link\]@i",
"@\[link\]$urlregex\[/link\]@i",
"@\[url=$urlregex\](.*?)\[/url\]@i",
"@\[url\]$urlregex\[/url\]@i",
"@\[quote=(.*?)\](.*?)\[/quote\]@is",
"@\[quote\](.*?)\[/quote\]@is",
"@\[font=(.*?)\](.*?)\[/font\]@is",
$urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)";
$httpsregex = "(?:\"?)https\:\/\/([^\[\"<\ ]+)(?:\"?)";
// List of allowable tags
$bbtags = array (
"@\[b\](.*?)\[/b\]@is",
"@\[i\](.*?)\[/i\]@is",
"@\[u\](.*?)\[/u\]@is",
"@\[url=$httpsregex\](.*?)\[/url\]@i",
"@\[url\]$httpsregex\[/url\]@i",
"@\[link=$urlregex\](.*?)\[/link\]@i",
"@\[link\]$urlregex\[/link\]@i",
"@\[url=$urlregex\](.*?)\[/url\]@i",
"@\[url\]$urlregex\[/url\]@i",
"@\[quote=(.*?)\](.*?)\[/quote\]@is",
"@\[quote\](.*?)\[/quote\]@is",
"@\[list\](.*?)\[/list\]@is",
"@\[list=1\](.*?)\[/list\]@is",
"@\[pre\](.*?)\[/pre\]@is",
"@\[img\]$urlregex\[/img\]@is",
"@\[color=(?:\"?)(.{3,8})(?:\"?)\](.*?)\[/color\]@is",
"@((?:<ol>|<ul>).*?)\n\*([^\n]+)\n(.*?(</ol>|</ul>))@is",
"@\[size=([1-9]|[0-2][0-9])\](.*?)\[/size\]@is",
"@\[code\](.*?)\[/code\]@is",
"@\[mailto\](.*?)\[/mailto\]@is",
"@\[email\](.*?)\[/email\]@is"
//Note: The above list array member ensures we're within a list
// when doing list item transformations.
//TODO: Make sure we're not between two lists
);
// What the above tags are turned in to
$htmltags = array (
"<b>\\1</b>",
"<i>\\1</i>",
"<u>\\1</u>",
"<a href=\"https://\\1\" rel=\"nofollow\">\\2</a>",
"<a href=\"https://\\1\" rel=\"nofollow\">https://\\1</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"@\[pre\](.*?)\[/pre\]@is",
"@\[img\]$urlregex\[/img\]@is",
"@\[color=(?:\"?)(.{3,8})(?:\"?)\](.*?)\[/color\]@is",
"@((?:<ol>|<ul>).*?)\n\*([^\n]+)\n(.*?(</ol>|</ul>))@is",
"@\[size=([1-9]|[0-2][0-9])\](.*?)\[/size\]@is",
"@\[code\](.*?)\[/code\]@is",
"@\[mailto\](.*?)\[/mailto\]@is",
"@\[email\](.*?)\[/email\]@is",
"@\[trac\](?:\#|ticket:)(\d+)\[/trac\]@is",
"@\[trac\]wiki:(.*?)\[/trac\]@is",
"@\[trac\]changeset:(\d+)\[/trac\]@is"
//Note: The above list array member ensures we're within a list
//when doing list item transformations.
//TODO: Make sure we're not between two lists
);
// What the above tags are turned in to
$htmltags = array (
"<b>\\1</b>",
"<i>\\1</i>",
"<u>\\1</u>",
"<a href=\"https://\\1\" rel=\"nofollow\">\\2</a>",
"<a href=\"https://\\1\" rel=\"nofollow\">https://\\1</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">\\3</a>",
"<a href=\"http://\\2\" rel=\"nofollow\">http://\\2</a>",
"<div style='font-style: oblique'>\\1 wrote:</div><blockquote class='postbody'>\\2</blockquote>",
"<blockquote class='postbody'>\\1</blockquote>",
"<font face=\\1>\\2</font>",
"<ul>\\1</ul><p>",
"<ol>\\1</ol><p>",
"<pre>\\1</pre>",
"<img src=\"http://\\2\">",
"<font color=\"\\1\">\\2</font>",
"\\1<li>\\2</li>\n\\3",
"<span style=\"font-size: \\1px;\">\\2</span>",
"<div class=\"code\">\\1</div>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"mailto:\\1\">\\1</a>"
);
// Do the actual replacing - iterations for nested items
$lasttext = "";
$i = 0;
// $i<10 to prevent DoS
while ($text != $lasttext && $i<20) {
$lasttext = $text;
$text = preg_replace($bbtags,$htmltags,$text);
$i = $i + 1;
}
return $text;
"<ul>\\1</ul><p>",
"<ol>\\1</ol><p>",
"<pre>\\1</pre>",
"<img src=\"http://\\2\">",
"<font color=\"\\1\">\\2</font>",
"\\1<li>\\2</li>\n\\3",
"<span style=\"font-size: \\1px;\">\\2</span>",
"<div class=\"code\">\\1</div>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"mailto:\\1\">\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/ticket/\\1\">#\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/wiki/\\1\">\\1</a>",
"<a href=\"http://boinc.berkeley.edu/trac/changeset/\\1\">[\\1]</a>"
);
// Do the actual replacing - iterations for nested items
$lasttext = "";
$i = 0;
// $i<20 to prevent DoS
while ($text != $lasttext && $i<20) {
$lasttext = $text;
$text = preg_replace($bbtags,$htmltags,$text);
$i = $i + 1;
}
return $text;
}
/**

View File

@ -2,34 +2,34 @@
require_once("../inc/util.inc");
page_head("BBCode tags");
echo "
<p>
echo "<p>
BBCode tags let you format text in your profile and message-board postings.
It's similar to HTML, but simpler.
The tags start with a [ (where you would have used &lt; in HTML)
and end with ]
(where you would have used &gt; in HTML).</p>
<p>Examples:</p>
<ul>
<li>[b]Bold[/b] to <b>Bold</b></li>
<li>[i]Italic[/i] to <i>Italic</i></li>
<li>[u]Underline[/u] to <u>Underline</u></li>
<li>[size=15]Big text[/size] to <span style=\"font-size: 15px\">Big text</span></li>
<li>[color=red]Red text[/color] to <font color=\"red\">Red text</font></li>
<li>[url=http://google.com/]Google[/url] to <a href=\"http://google.com/\">Google</a></li>
<li>[quote]Quoted[/quote] for quoted blocks of text</li>
<li>[img]http://some.web.site/pic.jpg[/img] to display an image</li>
<li>[code]Code snippet here[/code] to display some code</li>
<li>[pre]Pre-formatted text here[/pre] to display some pre-formatted text</li>
<li>[[Term]] hyperlink to a term defined on the Unofficial BOINC Wiki
</ul>
<p>Lists are also possible:<br/>[list]<br/>*Item 1<br/>*Item 2<br/>[/list] to:</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<p>
It's similar to HTML, but simpler. The tags start with a [ (where you would
have used &lt; in HTML) and end with ] (where you would have used &gt; in
HTML).</p>";
start_table();
row1("Examples");
row2_plain("[b]Bold[/b]", "<b>Bold</b>");
row2_plain("[i]Italic[/i]", "<i>Italic</i>");
row2_plain("[u]Underline[/u]", "<u>Underline</u>");
row2_plain("[size=15]Big text[/size]", "<span style=\"font-size: 15px\">Big text</span>");
row2_plain("[color=red]Red text[/color]", "<font color=\"red\">Red text</font></li>");
row2_plain("[url=http://google.com/]Google[/url]", "<a href=\"http://google.com/\">Google</a>");
row2_plain("[quote]Quoted[/quoted]", "use for quoted blocks of text");
row2_plain("[img]http://example.com/pic.jpg[/img]", "use to display an image");
row2_plain("[code]Code snippet here[/code]", "use to display some code");
row2_plain("[pre]Pre-formatted text here[/pre]", "use to display pre-formatted (usually monospaced) text");
row2_plain("[list]<br>* Item 1<br>*Item2<br>[/list]", "<ul><li>Item 1</li><li>Item 2</li></ul>");
row2_plain("[trac]#1[/trac] or [trac]ticket:1[/trac]",
"use to link to Trac ticket on BOINC website: <a href=\"http://boinc.berkeley.edu/trac/ticket/1\">#1</a>");
row2_plain("[trac]wiki:WebForum[/trac]",
"use to link to Trac Wiki on BOINC website: <a href=\"http://boinc.berkeley.edu/trac/wiki/WebForum\">WebForum</a>");
row2_plain("[trac]changeset:12345[/trac]",
"use to link to SVN changeset on BOINC website: <a href=\"http://boinc.berkeley.edu/trac/changeset/12345\">[12345]</a>");
end_table();
echo "<p>
If you don't close a tag or don't specify a parameter correctly,
the raw tag itself will display instead of the formatted text.</p>
";

View File

@ -1,5 +1,5 @@
<?php
$cvs_version_tracker[]="\$Id: forum_pm.php,v 1.119 2007/03/14 18:05:28 Rytis Exp $";
$cvs_version_tracker[]="\$Id$";
require_once("../inc/forum.inc");
require_once("../inc/forum_std.inc");