Skip to main content
Topic: Parser Fun (Read 635 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Parser Fun

Just posting this as I stumbled on it while doing some portal testing, and it took me a moment to realize what was occuring.

For the most part, we get our message parser with $bbc_parser = BBCParserWrapper::instance(); or good old parse_bbc and you will get the sole instance of ParseWrapper which is just that, a wrapper of helpful functions around the parsers, most notably BBC.  The constructor of this class is private, so you must use ::instance to get it.

The issue is if you have a page where you want to manipulate the parser for an area.  The example here is the Shoutbox on a portal where you might choose to only allow certain BBC codes to render, but the other blocks are not restricted, say a recent posts block.

Doing this essentially creates a race condition, where you have modified the sole instance to only render x,y,z tags but other blocks may grab that instance to render its content, and some tags are disabled as the first block (shoutbox) is still rendering and has not restored the tags for use (in that instance)

So long story short if you choose to disable/enable tags be sure there are not other areas on that same page that require those tags, if so you will want to get your own parser to play with and not the "site" one so to speak.  a bare bones one is $parser = new BBCParser($codes = new Codes()); that will be only default bbc codes, no addon codes, does not check if bbc is enabled, etc etc.  Then $codes->disable('bla'); Anyway if you are reading this you know what to do.
Be safe, Be kind, Happy Programing

Re: Parser Fun

Reply #1

hmm... indeed, the wrapper is built basically to work with the core and nothing else... In order to use it "externally", you have to go back to basics and instantiate your own parser.
I guess it was kind of intentional (i.e. if you need specific solutions you may very well find it easier to just implement your own wrapper), though it may become handy having some function already available.
Bugs creator.
Features destroyer.
Template killer.