Support ⇒ Modules & Blocks ⇒ nbbcode.php and List ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum IndexModules & Blocks

nbbcode.php and List Reply to topic

Go to page 1, 2 Next

I've managed a lot of tweaks to nbbcode, including adding new BBCodes and enhancing others, but have an issue I'd like to address which seems to be beyond my 'pay grade'.

BBCode will support most code pairs, eg: [b] ... [/b] nested to any depth (as long as the codes are closed in strict reversed order that they are opened).

But the existing list command [list][*] ... [/list] MUST be at the top level or it does not get processed at all.

It's clearly related to the code at function encode() where the list command gets pulled out, but has anyone any idea how it can be generalised to handle list at all levels?

TIA!

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


The problem might be [*] when it has no [/*], can you check that?

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial


DJ Maze wrote
The problem might be [*] when it has no [/*], can you check that?


Pretty sure * is a unary code. if you type [list][*]Test[/*][/list] you get
  • Test[/*]

Plus if you take a valid list command and place it inside, say, an italic command pair, then the list command is not processed. But switch the same list and italic command statements around and it works. Eg [i][list][*]Test[/list][/i] gives
  • Test
but [list][i][*]Test[/i][/list]
    [*]Test
works.

Looking through the code I can't see anywhere that list is treated differently (to the other open/close commands), except for that while loop in function encode(). That appears to be to handle the different versions of list (list=x) as noted in the comments, but I can't see anything there that would prevent it working at any level.

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


Ah, I think I see the cause of the problem ...

It seems LIST has been implement as a special case command - like PHP, CODE, QUOTE - which don't get buried inside the other BBCodes.

The recursion that gets i, b, color, etc, encoded/decoded at any level is in function encode().

So - I think - LIST needs to be implemented in function encode() rather than in function split_on_bbcodes() where it is currently handled (at the top level only).

[ You can find the instances where LIST has been added by simply searching for $tmptext - which seems to have been introduced to shoehorn in the LIST processing in function split_on_bbcodes(). ]

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


There are:
[list] [list=1] [list=a] [list=i]

And that is where decode_list is going.
The way how BBCode is parsed should be changed to travel up instead of down.

We have to check how to solve that.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial


Agreed. What I was referring to was where decode_list was called from.

function split_on_bbcodes() only gets called once at the top level. So if LIST is at the top level then it will get executed by the last else in function split_on_bbcodes().

However if function split_on_bbcodes() ever calls function encode() to process a 'normal' command - then function decode_list() can never get called.

Put another way, CODE, PHP and QUOTE are effectively meta-commands. Putting LIST processing in with the meta-commands rather than the 'normal' commands is the mistake. IMHO.

Have done some tracing which supports my hypothesis, so will see if I can add the code to prove it ... But Reg Ex (for LIST plus all its options) is very much not my thing!

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


The problem with regex and [list] is nested lists.
[list] [*] [list] [*] [/list] [/list]
How does regex know which [/list] is <ol> and which is <ul>?
That's why it gets looped and encoded as list:0

The loop needs to be fixed, i did a revamp but it failed on them as well.
Need to look further...

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial


Try the attachment.
Attachment: nbbcode.php.tar.gz
Description v9 modified nbbcode.php
Filename nbbcode.php.tar.gz
Filesize 8.06 KiB
Downloaded 1 Time(s)
You are not allowed to view/download this attachment

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial

Last edited by DJ Maze on Sun Dec 21, 2014 1:07 am; edited 1 time in total


Cool! 😎

Seems to work fine on my ad-hoc test cases.

( Fails on [list][i][*]text[/i][/list] but that is arguably invalid syntax - to insert bbcodes between LIST and * - so no issue, it just happened to work on prior version. It will allow bbcodes within the individual text strings which is the correct usage. )

Will incorporate into my Enhanced BBCode and test some more.

Well pleased. Thanks!

( Barring no issues, I'll upload my Enhanced BBCode to SCM in case you want to include any of the additional BBCodes into a future DF. Note enhancement affects all related components, because as well as new icons it adds a <p> </p> by default to all text so that line-length of text can be limited via CSS - instead of letting it just stretch to match the widest img on the page, eg images over 800px wide. )

Thanks again!

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


Images could have style max-width:100% so that they resize when needed.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial


Agreed, do that as well.

Have found 1 bug with nbbcode.

[quote] ( as against [quote="username"] which works fine ) doesn't get processed.

Also in Debug: includes/nbbcode.php Notice line 612: Uninitialized string offset: 6 Notice line 612: Uninitialized string offset: 6

			case 'quote':
				# [QUOTE] and [QUOTE=""]
				if ($part['code'][6] == ']') {
					$text .= $bb_codes['quote']
						. static::split_on_bbcodes($part['subc'], $allowed, $allow_html)
						. $bb_codes['quote_close'];

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


Change
				if ($part['code'][6] == ']') {
to
				if (strlen($part['code']) <= 5) {
?

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


Or try
# [QUOTE] and [QUOTE=""]
if (preg_match('/quote="?(.*?)"?$/Dsi', $part['code'])) {
	$text .= preg_replace('/quote="?(.*?)"?$/Dsi', $bb_codes['quote_name'], $part['code'])
		. static::split_on_bbcodes($part['subc'], $allowed, $allow_html)
		. $bb_codes['quote_close'];
} else {
	$text .= $bb_codes['quote']
		. static::split_on_bbcodes($part['subc'], $allowed, $allow_html)
		. $bb_codes['quote_close'];
}

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial


That works too. Wink

One last question if I may ... ? Do any of these changes (eg. the use of static:: in place of BBCodes::) imply a minimum version of PHP?

I run 5.5 in test and 5.4 in production so unlikely an issue, but wanted to clarify for release of the Enhanced BBCode module.

Thanks and Feliz Navidad!

Pro_News CM™ - Content Management for Dragonfly CMS™

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux / 1.3.39 - 2.4.9 / 5.5.42 - 5.6.16 / 5.4.37 - 5.5.11 / 9.4


PHP 5.3 php.net/manual/en/lang...ndings.php

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Fedora 25 / Apache 2.4.27 / MariaDB 10.1.26 / PHP 7.1.10 / Mercurial

All times are UTC
Go to page 1, 2 Next


Jump to: