• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Extending XenForo_BbCode_Parser?

Floren

Well-known member
#1
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
#2
Why would you want to extend the parser? Surely it's the formatter you should be extending?
 

cclaerhout

Well-known member
#4
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
#5
It seems the public function "filterString" from class "XenForo_BbCode_Formatter_Base" can be used. It's less clean but it should be ok.