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

Extending XenForo_BbCode_Parser?

Discussion in 'XenForo Development Discussions' started by Floren, May 1, 2011.

  1. Floren

    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.
     
  2. Kier

    Kier XenForo Developer Staff Member

    Why would you want to extend the parser? Surely it's the formatter you should be extending?
     
  3. Kier

    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
     
    Jeremy and Mikey like this.
  4. cclaerhout

    cclaerhout Well-Known Member

    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.
     
    0xym0r0n likes this.
  5. cclaerhout

    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.
     
  6. cclaerhout

    cclaerhout Well-Known Member

    Nope, it's not ok. The parser breaks so the string in the formatter is not correct.
     

Share This Page