ElkArte Community

Elk Development => Feature Discussion => Topic started by: Spuds on April 18, 2021, 11:41:15 am

Title: Parser Fun
Post by: Spuds on April 18, 2021, 11:41:15 am
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.
Title: Re: Parser Fun
Post by: emanuele on April 23, 2021, 03:11:30 pm
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.