aboutsummaryrefslogtreecommitdiffstats
path: root/include/bbcode.php
diff options
context:
space:
mode:
authorAbinoam P. Marques Jr <abinoam@gmail.com>2012-02-12 14:35:29 -0800
committerAbinoam P. Marques Jr <abinoam@gmail.com>2012-02-12 14:35:29 -0800
commit92a585ed23fb458c97b5e24f5b8b86ea68866886 (patch)
treee633969291e500afe1754af0875c295c6107ee2a /include/bbcode.php
parent6a17a3a8e249a11b55122de92f999876860b2b6f (diff)
downloadvolse-hubzilla-92a585ed23fb458c97b5e24f5b8b86ea68866886.tar.gz
volse-hubzilla-92a585ed23fb458c97b5e24f5b8b86ea68866886.tar.bz2
volse-hubzilla-92a585ed23fb458c97b5e24f5b8b86ea68866886.zip
Added support to [noparse], [nobb] and [pre] as bbcode escape tags.
Diffstat (limited to 'include/bbcode.php')
-rwxr-xr-xinclude/bbcode.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/bbcode.php b/include/bbcode.php
index 7133a1a34..3534a7315 100755
--- a/include/bbcode.php
+++ b/include/bbcode.php
@@ -24,13 +24,40 @@ function tryoembed($match){
}
+// [noparse][i]italic[/i][/noparse] turns into
+// [noparse][ i ]italic[ /i ][/noparse],
+// to hide them from parser.
+
+function bb_spacefy($st) {
+ $whole_match = $st[0];
+ $captured = $st[1];
+ $spacefied = preg_replace("/\[(.*?)\]/", "[ $1 ]", $captured);
+ $new_str = str_replace($captured, $spacefied, $whole_match);
+ return $new_str;
+}
+
+// The previously spacefied [noparse][ i ]italic[ /i ][/noparse],
+// now turns back and the [noparse] tags are trimed
+// returning [i]italic[/i]
+function bb_unspacefy_and_trim($st) {
+ $whole_match = $st[0];
+ $captured = $st[1];
+ $unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured);
+ return $unspacefied;
+}
// BBcode 2 HTML was written by WAY2WEB.net
// extended to work with Mistpark/Friendica - Mike Macgirvin
function bbcode($Text,$preserve_nl = false) {
+ // Hide all [noparse] contained bbtags spacefying them
+
+ $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text);
+ $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text);
+ $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
+
// Extract a single private image which uses data url's since preg has issues with
// large data sizes. Stash it away while we do bbcode conversion, and then put it back
@@ -227,6 +254,13 @@ upper-alpha;">$2</ul>' ,$Text);
$Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text);
}
+ // Unhide all [noparse] contained bbtags unspacefying them
+ // and triming the [noparse] tag.
+
+ $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim',$Text);
+ $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim',$Text);
+ $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim',$Text);
+
// fix any escaped ampersands that may have been converted into links
$Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&amp\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text);
if(strlen($saved_image))