From 3446e68ac2aa3f970307b748fee5ee2da1af4ca4 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Tue, 26 Apr 2016 11:41:08 +0200 Subject: move spoiler= and quote= bbcode handling from prepare_body() to bbcode() and add open tag to bbco_autocomplete --- include/bbcode.php | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'include/bbcode.php') diff --git a/include/bbcode.php b/include/bbcode.php index 78a2759c1..b8cd23f59 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -330,8 +330,19 @@ function bb_map_location($match) { } function bb_opentag($match) { + $openclose = (($match[2]) ? '' . $match[1] . '' : t('Click to open/close')); + $text = (($match[2]) ? $match[2] : $match[1]); $rnd = mt_rand(); - return "
" . $match[1] . "
" . $match[2] . "
"; + + return ''; +} + +function bb_spoilertag($match) { + $openclose = (($match[2]) ? '' . $match[1] . ' ' . t('spoiler') . '' : t('Click to open/close')); + $text = (($match[2]) ? $match[2] : $match[1]); + $rnd = mt_rand(); + + return ''; } /** @@ -748,33 +759,34 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/\[code\](.*?)\[\/code\]/ism", "$CodeLayout", $Text); } - // Declare the format for [spoiler] layout - $SpoilerLayout = '
$1
'; - // Check for [spoiler] text - // handle nested quotes $endlessloop = 0; - while ((strpos($Text, "[/spoiler]") !== false) and (strpos($Text, "[spoiler]") !== false) and (++$endlessloop < 20)) - $Text = preg_replace("/\[spoiler\](.*?)\[\/spoiler\]/ism", "$SpoilerLayout", $Text); + while ((strpos($Text, "[/spoiler]")!== false) and (strpos($Text, "[spoiler]") !== false) and (++$endlessloop < 20)) { + $Text = preg_replace_callback("/\[spoiler\](.*?)\[\/spoiler\]/ism", 'bb_spoilertag', $Text); + } // Check for [spoiler=Author] text - - $t_wrote = t('$1 spoiler'); - - // handle nested quotes $endlessloop = 0; - while ((strpos($Text, "[/spoiler]")!== false) and (strpos($Text, "[spoiler=") !== false) and (++$endlessloop < 20)) - $Text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism", - "
" . $t_wrote . "
$2
", - $Text); + while ((strpos($Text, "[/spoiler]")!== false) and (strpos($Text, "[spoiler=") !== false) and (++$endlessloop < 20)) { + $Text = preg_replace_callback("/\[spoiler=(.*?)\](.*?)\[\/spoiler\]/ism", 'bb_spoilertag', $Text); + } + // Check for [open] text + $endlessloop = 0; + while ((strpos($Text, "[/open]")!== false) and (strpos($Text, "[open]") !== false) and (++$endlessloop < 20)) { + $Text = preg_replace_callback("/\[open\](.*?)\[\/open\]/ism", 'bb_opentag', $Text); + } + // Check for [open=Title] text $endlessloop = 0; while ((strpos($Text, "[/open]")!== false) and (strpos($Text, "[open=") !== false) and (++$endlessloop < 20)) { $Text = preg_replace_callback("/\[open=(.*?)\](.*?)\[\/open\]/ism", 'bb_opentag', $Text); } + + + // Declare the format for [quote] layout $QuoteLayout = '
$1
'; @@ -792,7 +804,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $endlessloop = 0; while ((strpos($Text, "[/quote]")!== false) and (strpos($Text, "[quote=") !== false) and (++$endlessloop < 20)) $Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism", - "
" . $t_wrote . "
$2
", + "" . $t_wrote . "
$2
", $Text); // Images -- cgit v1.2.3