Skip to main content
Topic: BBC tag array grouped by tag (Read 2265 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

BBC tag array grouped by tag

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.
Bugs creator.
Features destroyer.
Template killer.

Re: BBC tag array grouped by tag

Reply #1

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.

Re: BBC tag array grouped by tag

Reply #2

But currently some tags are duplicated to deal with different permutations. Wouldn't this idea destroy that?
LiveGallery - Simple gallery addon for ElkArte

Re: BBC tag array grouped by tag

Reply #3

How would you replace?

Re: BBC tag array grouped by tag

Reply #4

Scroll down the example code to the quote tag. :P
It's an array of arrays. ;)
Bugs creator.
Features destroyer.
Template killer.

Re: BBC tag array grouped by tag

Reply #5

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.

 

Re: BBC tag array grouped by tag

Reply #6

O_o
Bugs creator.
Features destroyer.
Template killer.