From 1ad8f20bcea6395cd8f9a50907a36bae1e425352 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Wed, 16 Nov 2016 20:49:58 +0100 Subject: only turn [] and [x] into checkboxes if it is found inside a checklist --- include/bbcode.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/bbcode.php b/include/bbcode.php index 75e8a0f52..21bc6de77 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -403,6 +403,15 @@ function bb_definitionList_unescapeBraces($match) { return '
' . str_replace('\]', ']', $match[1]) . '
'; } + +function bb_checklist($match) { + $str = $match[1]; + $str = str_replace("[]", "
  • ", $str); + $str = str_replace("[x]", "
  • ", $str); + return ''; +} + + /** * @brief Sanitize style properties from BBCode to HTML. * @@ -787,14 +796,11 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/
    \[\*\]/ism",'[*]',$Text); $Text = str_replace("[*]", "
  • ", $Text); - $Text = str_replace("[]", "
  • ", $Text); - $Text = str_replace("[x]", "
  • ", $Text); // handle nested lists $endlessloop = 0; while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) || - ((strpos($Text, "[/checklist]") !== false) && (strpos($Text, "[checklist]") !== false)) || ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) || ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) || ((strpos($Text, "[/dl]") !== false) && (strpos($Text, "[dl") !== false)) || @@ -806,7 +812,6 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) $Text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '', $Text); $Text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '', $Text); $Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '', $Text); - $Text = preg_replace("/\[checklist\](.*?)\[\/checklist\]/ism", '', $Text); $Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '', $Text); $Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '', $Text); $Text = preg_replace("/\[\/li\]
    \[li\]/ism",'[/li][li]',$Text); @@ -818,7 +823,13 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $cache = false) // "[dl" "]" "[/dl]" // where optional-termStyles are: "terms=" $Text = preg_replace_callback('/\[dl[[:space:]]*(?:terms=(?:"|")?([a-zA-Z]+)(?:"|")?)?\](.*?)\[\/dl\]/ism', 'bb_definitionList', $Text); + + } + + if (strpos($Text,'[checklist]') !== false) { + $Text = preg_replace_callback("/\[checklist\](.*?)\[\/checklist\]/ism", 'bb_checklist', $Text); } + if (strpos($Text,'[th]') !== false) { $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '$1', $Text); } -- cgit v1.2.3