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:
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:
'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:
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.
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.
But currently some tags are duplicated to deal with different permutations. Wouldn't this idea destroy that?
Scroll down the example code to the quote tag. :P
It's an array of arrays. ;)
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.