mirror of https://github.com/BOINC/boinc.git
web: handle BBcode [pre] correctly
This commit is contained in:
parent
31541e166d
commit
0189132695
|
@ -104,12 +104,33 @@ function get_output_options($user) {
|
||||||
// Converts bbcode to proper HTML
|
// Converts bbcode to proper HTML
|
||||||
// If $export is true, don't use BOINC CSS
|
// If $export is true, don't use BOINC CSS
|
||||||
|
|
||||||
|
// handle [pre] separately because we need to remove <br />s
|
||||||
|
//
|
||||||
|
function replace_pre($text, $export) {
|
||||||
|
if ($export) {
|
||||||
|
return preg_replace_callback(
|
||||||
|
"@\[pre\](.*?)\[/pre\]@is",
|
||||||
|
function ($matches) {
|
||||||
|
return "<pre>".remove_br(substr($matches[0], 5, -6))."</pre>";
|
||||||
|
},
|
||||||
|
$text
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return preg_replace_callback(
|
||||||
|
"@\[pre\](.*?)\[/pre\]@is",
|
||||||
|
function ($matches) {
|
||||||
|
return "<div class=\"pre\">".remove_br(substr($matches[0], 5, -6))."</div>";
|
||||||
|
},
|
||||||
|
$text
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function bb2html($text, $export=false) {
|
function bb2html($text, $export=false) {
|
||||||
$urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)";
|
$urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)";
|
||||||
$httpsregex = "(?:\"?)https\:\/\/([^\[\"<\ ]+)(?:\"?)";
|
$httpsregex = "(?:\"?)https\:\/\/([^\[\"<\ ]+)(?:\"?)";
|
||||||
// List of allowable tags
|
// List of allowable tags
|
||||||
$bbtags = array (
|
$bbtags = array (
|
||||||
"@\[pre\](.*?)\[/pre\]@is",
|
|
||||||
"@\[code\](.*?)\[/code\]@is",
|
"@\[code\](.*?)\[/code\]@is",
|
||||||
"@\[b\](.*?)\[/b\]@is",
|
"@\[b\](.*?)\[/b\]@is",
|
||||||
"@\[i\](.*?)\[/i\]@is",
|
"@\[i\](.*?)\[/i\]@is",
|
||||||
|
@ -143,7 +164,6 @@ function bb2html($text, $export=false) {
|
||||||
// What the above tags are turned in to
|
// What the above tags are turned in to
|
||||||
if ($export) {
|
if ($export) {
|
||||||
$htmltags = array (
|
$htmltags = array (
|
||||||
"<pre>\\1</pre>",
|
|
||||||
"<code>\\1</code>",
|
"<code>\\1</code>",
|
||||||
"<b>\\1</b>",
|
"<b>\\1</b>",
|
||||||
"<i>\\1</i>",
|
"<i>\\1</i>",
|
||||||
|
@ -172,7 +192,6 @@ function bb2html($text, $export=false) {
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$htmltags = array (
|
$htmltags = array (
|
||||||
"<div class=\"pre\">\\1</div>",
|
|
||||||
"<div class=\"code\">\\1</div>",
|
"<div class=\"code\">\\1</div>",
|
||||||
"<b>\\1</b>",
|
"<b>\\1</b>",
|
||||||
"<i>\\1</i>",
|
"<i>\\1</i>",
|
||||||
|
@ -207,7 +226,8 @@ function bb2html($text, $export=false) {
|
||||||
// $i<1000 to prevent DoS
|
// $i<1000 to prevent DoS
|
||||||
while ($text != $lasttext && $i<1000) {
|
while ($text != $lasttext && $i<1000) {
|
||||||
$lasttext = $text;
|
$lasttext = $text;
|
||||||
$text = preg_replace($bbtags,$htmltags,$text);
|
$text = replace_pre($text, $export);
|
||||||
|
$text = preg_replace($bbtags, $htmltags, $text);
|
||||||
$i = $i + 1;
|
$i = $i + 1;
|
||||||
}
|
}
|
||||||
return $text;
|
return $text;
|
||||||
|
|
Loading…
Reference in New Issue