Extending XenForo_BbCode_Parser?

Floren

Well-known member
Hi guys,

I'm trying to modify the XenForo_BbCode_Parser::parse event.

Logic:
Code:
class Addon_CodeEvent
{
	public static function extendParser($class, array &$extend)
	{
		switch ($class)
		{
			case 'XenForo_BbCode_Parser':
			{
				$extend[] = 'Addon_BbCode_Parser';
				break;
			}
			// more cases here ...
		}
	}
}

class Addon_BbCode_Parser extends XFCP_Addon_BbCode_Parser
{
	public function parse($text)
	{
		var_dump($text);
		exit;
	}
}
I used a load_class_bb_code event listener, but the text is not var_dumped.
Obviously, if I edit the code in XenForo_BbCode_Parser::parse, it will work as expected.

Thank you for your help.
 

Kier

XenForo developer
Staff member
Why would you want to extend the parser? Surely it's the formatter you should be extending?
 

Kier

XenForo developer
Staff member
In fact, your code isn't even being hit, because we only allow the formatter to be extended: see the description of the code event:

Screen shot 2011-05-03 at 17.34.28.png
 

cclaerhout

Well-known member
Why would you want to extend the parser? Surely it's the formatter you should be extending?
I reply to this old thread to give a possible advantage that would be to extend this parser: modify the content of variable $_text, since it's central. The other entry gate to perform the same thing would be to be able to extend the censorString function of the string helper.Edit 01/26: nope, the censtorString function is initiated after the parser.

Purpose example:
Change this code:
Code:
[myBbCode=[specialTag]Caption[/specialTag]]content[/myBbCode]
To:
Code:
[myBbCode={specialTag}Caption{/specialTag}]content[/myBbCode]
Why ? => the XenForo parser will break if some tags are used in the bbcode option.
 

cclaerhout

Well-known member
It seems the public function "filterString" from class "XenForo_BbCode_Formatter_Base" can be used. It's less clean but it should be ok.
 
Top