Handling nested bbcodes. Some small design changes in html2bbcode. Change in poller.php is just for testing purposes.

This commit is contained in:
Michael 2012-02-19 21:07:45 +01:00
parent 8c8efbdf64
commit 064c843119
3 changed files with 35 additions and 23 deletions

View file

@ -149,15 +149,20 @@ function bbcode($Text,$preserve_nl = false) {
$Text = str_replace("[*]", "<li>", $Text); $Text = str_replace("[*]", "<li>", $Text);
$Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>' ,$Text); $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>' ,$Text);
// handle nested lists
$endlessloop = 0;
while (strpos($Text, "[/list]") and strpos($Text, "[list") and (++$endlessloop < 20)) {
$Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>' ,$Text); $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>' ,$Text);
$Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>' ,$Text);
$Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>' ,$Text); $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>' ,$Text);
$Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>' ,$Text); $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>' ,$Text);
$Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>' ,$Text);
$Text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>' ,$Text); $Text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>' ,$Text);
$Text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>' ,$Text); $Text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>' ,$Text);
$Text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>' ,$Text); $Text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>' ,$Text);
$Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>' ,$Text); $Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>' ,$Text);
}
$Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>' ,$Text);
$Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>' ,$Text);
$Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>' ,$Text); $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>' ,$Text);
$Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '<td>$1</td>' ,$Text); $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '<td>$1</td>' ,$Text);

View file

@ -187,9 +187,13 @@ function html2bbcode($message)
node2bbcode($doc, 'hr', array(), "[hr]", ""); node2bbcode($doc, 'hr', array(), "[hr]", "");
node2bbcode($doc, 'table', array(), "", ""); //node2bbcode($doc, 'table', array(), "", "");
node2bbcode($doc, 'tr', array(), "\n", ""); //node2bbcode($doc, 'tr', array(), "\n", "");
node2bbcode($doc, 'td', array(), "\t", ""); //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, 'h1', array(), "\n\n[size=xx-large][b]", "[/b][/size]\n");
node2bbcode($doc, 'h2', array(), "\n\n[size=x-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); $message = str_replace("\n\n\n", "\n\n", $message);
} while ($oldmessage != $message); } while ($oldmessage != $message);
do {
$oldmessage = $message;
$message = str_replace(array( $message = str_replace(array(
"[/size]\n\n", "[/size]\n\n",
"\n\n[hr]\n", "\n[hr]",
"\n[hr]\n\n", "[hr]\n",
"\n\n[list", "\n[list",
"[/list]\n\n", "[/list]\n",
"\n[/list]", "\n[/list]",
"[list]\n", "[list]\n",
"[list=1]\n", "[list=1]\n",
"\n\n[*]"), "\n[*]"),
array( array(
"[/size]\n", "[/size]\n",
"\n[hr]\n", "[hr]",
"\n[hr]\n", "[hr]",
"\n[list", "[list",
"[/list]\n", "[/list]",
"[/list]", "[/list]",
"[list]", "[list]",
"[list=1]", "[list=1]",
"\n[*]"), "[*]"),
$message); $message);
} while ($message != $oldmessage);
$message = str_replace(array('[b][b]', '[/b][/b]', '[i][i]', '[/i][/i]'), $message = str_replace(array('[b][b]', '[/b][/b]', '[i][i]', '[/i][/i]'),
array('[b]', '[/b]', '[i]', '[/i]'), $message); array('[b]', '[/b]', '[i]', '[/i]'), $message);

View file

@ -194,8 +194,8 @@ function poller_run($argv, $argc){
$update = true; $update = true;
break; break;
} }
if((! $update) && (! $force)) // if((! $update) && (! $force))
continue; // continue;
} }
// Check to see if we are running out of memory - if so spawn a new process and kill this one // Check to see if we are running out of memory - if so spawn a new process and kill this one