web: forums: display BBcode withing [pre] and [code].

Also, show long-ago dates (> 30 days) as the actual date
rather than "3423 days ago"
This commit is contained in:
David Anderson 2014-09-10 15:46:58 -07:00
parent 2659def911
commit bbb8ae2d1d
3 changed files with 33 additions and 12 deletions

View File

@ -101,32 +101,54 @@ function get_output_options($user) {
return $options;
}
// Converts bbcode to proper HTML
// Converts bbcode to HTML
// If $export is true, don't use BOINC CSS
// handle [pre] separately because we need to remove <br />s
// handle [pre] and [code] separately because we need to remove <br />s
//
function replace_pre($text, $export) {
function replace_pre_code($text, $export) {
if ($export) {
return preg_replace_callback(
$text = preg_replace_callback(
"@\[pre\](.*?)\[/pre\]@is",
function ($matches) {
$x = remove_br(substr($matches[0], 5, -6));
$x = htmlspecialchars($x);
$x = str_replace("[", "&#91;", $x);
return "<pre>$x</pre>";
},
$text
);
} else {
return preg_replace_callback(
"@\[code\](.*?)\[/code\]@is",
function ($matches) {
$x = remove_br(substr($matches[0], 6, -7));
$x = htmlspecialchars($x);
$x = str_replace("[", "&#91;", $x);
return "<code>$x</code>";
},
$text
);
} else {
$text = preg_replace_callback(
"@\[pre\](.*?)\[/pre\]@is",
function ($matches) {
$x = remove_br(substr($matches[0], 5, -6));
$x = htmlspecialchars($x);
$x = str_replace("[", "&#91;", $x);
return "<div class=\"pre\">$x</div>";
},
$text
);
return preg_replace_callback(
"@\[code\](.*?)\[/code\]@is",
function ($matches) {
$x = (substr($matches[0], 6, -7));
$x = htmlspecialchars($x);
$x = str_replace("[", "&#91;", $x);
return "<div class=\"code\">$x</div>";
},
$text
);
}
}
@ -135,7 +157,6 @@ function bb2html($text, $export=false) {
$httpsregex = "(?:\"?)https\:\/\/([^\[\"<\ ]+)(?:\"?)";
// List of allowable tags
$bbtags = array (
"@\[code\](.*?)\[/code\]@is",
"@\[b\](.*?)\[/b\]@is",
"@\[i\](.*?)\[/i\]@is",
"@\[u\](.*?)\[/u\]@is",
@ -168,7 +189,6 @@ function bb2html($text, $export=false) {
// What the above tags are turned in to
if ($export) {
$htmltags = array (
"<code>\\1</code>",
"<b>\\1</b>",
"<i>\\1</i>",
"<u>\\1</u>",
@ -196,7 +216,6 @@ function bb2html($text, $export=false) {
);
} else {
$htmltags = array (
"<div class=\"code\">\\1</div>",
"<b>\\1</b>",
"<i>\\1</i>",
"<u>\\1</u>",
@ -230,7 +249,7 @@ function bb2html($text, $export=false) {
// $i<1000 to prevent DoS
while ($text != $lasttext && $i<1000) {
$lasttext = $text;
$text = replace_pre($text, $export);
$text = replace_pre_code($text, $export);
$text = preg_replace($bbtags, $htmltags, $text);
$i = $i + 1;
}

View File

@ -16,7 +16,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// express a time difference in readable form
// express a time difference in readable form, e.g. "7 days ago".
// If it's more than 30 days, just show the date
//
function time_diff_str($t1, $t2) {
if (!$t1 || !$t2) return "---";
@ -26,6 +27,9 @@ function time_diff_str($t1, $t2) {
$post="";
$diff=-$diff;
} else {
if ($diff > 86400*30) {
return date_str($t1);
}
$pre="";
$post=" ago";
}

View File

@ -46,8 +46,6 @@ row2_plain("[trac]#1[/trac] or [trac]ticket:1[/trac]",
tra("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]",
tra("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]",
tra("use to link to SVN changeset on BOINC website").": <a href=\"http://boinc.berkeley.edu/trac/changeset/12345\">[12345]</a>");
end_table();
echo "<p>