ElkArte Community

Elk Development => Feature Discussion => Topic started by: emanuele on September 25, 2016, 06:05:54 am

Title: BBC tag array grouped by tag
Post by: emanuele on September 25, 2016, 06:05:54 am
I'm pretty sure there are better ways, but considering the current situation I think we may do that little step further for sake of extendibility.

At the moment, in order to replace "change" a single BBC tag, we have to loop over the whole array, search for it and then do whatever we want, along the lines of:
Code: [Select]
		for ($i = count($codes) - 1; $i > 0; $i--)
{
$code = &$codes[$i];
if ($code['tag'] == 'url')
{
What I was thinking is to slightly re-organize the codes so that they are simply grouped by tag, that way we'd have just to loop over the target tag instead of the whole array, something like:
Code: [Select]
		'abbr' => array(
array(
self::ATTR_TAG => 'abbr',
self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
...
),
),
'anchor' => array(
array(
self::ATTR_TAG => 'anchor',
self::ATTR_TYPE => self::TYPE_UNPARSED_EQUALS,
...
),
),
'quote' => array(
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
...
),
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
...
),
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_EQUALS,
...
),
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
...
),
array(
self::ATTR_TAG => 'quote',
self::ATTR_TYPE => self::TYPE_PARSED_CONTENT,
...
),
),

That way, to change the url tag we'll need to just loop over a small number of elements:
Code: [Select]
		for ($i = count($codes['url']) - 1; $i > 0; $i--)
{
$code = &$codes[$i];
if ($code['tag'] == 'url')
{

Of course, that way, before use the tags in the parser code, we'll need to re-create the previous version of the array (unless even the code may take advantage of this structure.
Title: Re: BBC tag array grouped by tag
Post by: Spuds on September 25, 2016, 07:00:55 am
Seems like having named keys would make it a bit easier ... not sure how often addons replace tags vs add new ones, seems like a replace function inside of the codes class (to go along with the add and remove ones) would be useful.
Title: Re: BBC tag array grouped by tag
Post by: live627 on September 25, 2016, 09:30:57 pm
But currently some tags are duplicated to deal with different permutations. Wouldn't this idea destroy that?
Title: Re: BBC tag array grouped by tag
Post by: Joshua Dickerson on September 26, 2016, 11:52:29 am
How would you replace?
Title: Re: BBC tag array grouped by tag
Post by: emanuele on September 26, 2016, 12:24:22 pm
Scroll down the example code to the quote tag. :P
It's an array of arrays. ;)
Title: Re: BBC tag array grouped by tag
Post by: Joshua Dickerson on September 26, 2016, 03:57:29 pm
You would need to do the exact permutation of the tag. Unless you're talking about just replacing a tag with another. That seems rare.
Title: Re: BBC tag array grouped by tag
Post by: emanuele on September 26, 2016, 04:14:13 pm
O_o