From bbb8ae2d1d4101e1e6e2884533c193b84b43c4ef Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 10 Sep 2014 15:46:58 -0700 Subject: [PATCH] web: forums: display BBcode withing [pre] and [code]. Also, show long-ago dates (> 30 days) as the actual date rather than "3423 days ago" --- html/inc/text_transform.inc | 37 ++++++++++++++++++++++++++++--------- html/inc/time.inc | 6 +++++- html/user/bbcode.php | 2 -- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/html/inc/text_transform.inc b/html/inc/text_transform.inc index 8268dfb457..ce4c0cacac 100644 --- a/html/inc/text_transform.inc +++ b/html/inc/text_transform.inc @@ -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
s +// handle [pre] and [code] separately because we need to remove
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("[", "[", $x); return "
$x
"; }, $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("[", "[", $x); + return "$x"; + }, + $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("[", "[", $x); return "
$x
"; }, $text ); + return preg_replace_callback( + "@\[code\](.*?)\[/code\]@is", + function ($matches) { + $x = (substr($matches[0], 6, -7)); + $x = htmlspecialchars($x); + $x = str_replace("[", "[", $x); + return "
$x
"; + }, + $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 ( - "\\1", "\\1", "\\1", "\\1", @@ -196,7 +216,6 @@ function bb2html($text, $export=false) { ); } else { $htmltags = array ( - "
\\1
", "\\1", "\\1", "\\1", @@ -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; } diff --git a/html/inc/time.inc b/html/inc/time.inc index b19c5a2ebe..fa69f770ea 100644 --- a/html/inc/time.inc +++ b/html/inc/time.inc @@ -16,7 +16,8 @@ // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . -// 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"; } diff --git a/html/user/bbcode.php b/html/user/bbcode.php index e5c46049ca..88534d6808 100644 --- a/html/user/bbcode.php +++ b/html/user/bbcode.php @@ -46,8 +46,6 @@ row2_plain("[trac]#1[/trac] or [trac]ticket:1[/trac]", tra("use to link to Trac ticket on BOINC website").": #1"); row2_plain("[trac]wiki:WebForum[/trac]", tra("use to link to Trac Wiki on BOINC website").": WebForum"); -row2_plain("[trac]changeset:12345[/trac]", - tra("use to link to SVN changeset on BOINC website").": [12345]"); end_table(); echo "