From 064c843119576c1345a61a531dfaa1076a54f3f0 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 19 Feb 2012 21:07:45 +0100 Subject: [PATCH] Handling nested bbcodes. Some small design changes in html2bbcode. Change in poller.php is just for testing purposes. --- include/bbcode.php | 19 ++++++++++++------- include/html2bbcode.php | 35 +++++++++++++++++++++-------------- include/poller.php | 4 ++-- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/include/bbcode.php b/include/bbcode.php index 528df33ec4..d639b0c39a 100755 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -149,15 +149,20 @@ function bbcode($Text,$preserve_nl = false) { $Text = str_replace("[*]", "
  • ", $Text); $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '
  • $1
  • ' ,$Text); - $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '' ,$Text); + // handle nested lists + $endlessloop = 0; + while (strpos($Text, "[/list]") and strpos($Text, "[list") and (++$endlessloop < 20)) { + $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '' ,$Text); + $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '' ,$Text); + $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '' ,$Text); + $Text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'' ,$Text); + $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("/\[ul\](.*?)\[\/ul\]/ism", '' ,$Text); - $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '' ,$Text); - $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '' ,$Text); $Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '' ,$Text); - $Text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'' ,$Text); - $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("/\[th\](.*?)\[\/th\]/sm", '$1' ,$Text); $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '$1' ,$Text); diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 1b4b5e99ab..4297ff2f9d 100755 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -187,9 +187,13 @@ function html2bbcode($message) node2bbcode($doc, 'hr', array(), "[hr]", ""); - node2bbcode($doc, 'table', array(), "", ""); - node2bbcode($doc, 'tr', array(), "\n", ""); - node2bbcode($doc, 'td', array(), "\t", ""); + //node2bbcode($doc, 'table', array(), "", ""); + //node2bbcode($doc, 'tr', array(), "\n", ""); + //node2bbcode($doc, 'td', array(), "\t", ""); + node2bbcode($doc, 'table', array(), "[table]", "[/table]"); + node2bbcode($doc, 'th', array(), "[th]", "[/th]"); + node2bbcode($doc, 'tr', array(), "[tr]", "[/tr]"); + node2bbcode($doc, 'td', array(), "[td]", "[/td]"); node2bbcode($doc, 'h1', array(), "\n\n[size=xx-large][b]", "[/b][/size]\n"); node2bbcode($doc, 'h2', array(), "\n\n[size=x-large][b]", "[/b][/size]\n"); @@ -246,27 +250,30 @@ function html2bbcode($message) $message = str_replace("\n\n\n", "\n\n", $message); } while ($oldmessage != $message); - $message = str_replace(array( + do { + $oldmessage = $message; + $message = str_replace(array( "[/size]\n\n", - "\n\n[hr]\n", - "\n[hr]\n\n", - "\n\n[list", - "[/list]\n\n", + "\n[hr]", + "[hr]\n", + "\n[list", + "[/list]\n", "\n[/list]", "[list]\n", "[list=1]\n", - "\n\n[*]"), + "\n[*]"), array( "[/size]\n", - "\n[hr]\n", - "\n[hr]\n", - "\n[list", - "[/list]\n", + "[hr]", + "[hr]", + "[list", + "[/list]", "[/list]", "[list]", "[list=1]", - "\n[*]"), + "[*]"), $message); + } while ($message != $oldmessage); $message = str_replace(array('[b][b]', '[/b][/b]', '[i][i]', '[/i][/i]'), array('[b]', '[/b]', '[i]', '[/i]'), $message); diff --git a/include/poller.php b/include/poller.php index 7d42c63b5f..0297eeabc1 100755 --- a/include/poller.php +++ b/include/poller.php @@ -194,8 +194,8 @@ function poller_run($argv, $argc){ $update = true; break; } - if((! $update) && (! $force)) - continue; +// if((! $update) && (! $force)) +// continue; } // Check to see if we are running out of memory - if so spawn a new process and kill this one