[RFC] Integrate s9e\TextFormatter

These requests for comments/change have lead to an implemented feature that has been successfully merged into the 3.2/Rhea branch. Everything listed in this forum will be available in phpBB 3.2.
Post Reply
User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Integrate s9e\TextFormatter

Post by EXreaction » Sat Aug 17, 2013 3:48 am

You might want to use the template engine to load and parse the bbcode.html file (the template code will all need to be rewritten in it as it uses old phpBB 2.0 style code). It can handle caching the file and rendering.

User avatar
JoshyPHP
Registered User
Posts: 363
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Sat Aug 17, 2013 1:47 pm

brunoais wrote:Wrong.
The bitfield marks which BBCodes were used in that text out of all the predefined ones.
You're talking about a different thing. If you look into bbcode::bbcode_cache_init() and bbcode::bbcode_tpl() you can see how $this->template_bitfield is being used.
EXreaction wrote:You might want to use the template engine to load and parse the bbcode.html file
I don't know about the template engine, so if you can provide me with the relevant snippet I'll gladly use that. Otherwise, I'll just reuse the current code from bbcode.php.
EXreaction wrote:(the template code will all need to be rewritten in it as it uses old phpBB 2.0 style code).
That part I didn't get. I'm not sure what template code we're talking about, and in what time frame. I assume you're talking about some long-term thing?
EXreaction wrote:It can handle caching the file and rendering.
s9e\TextFormatter handles its own caching and rendering already though. Based on the sum of all templates (including those used by BBCodes, emoticons, etc... any markup element) a PHP renderer is generated and dumped/cached on the disk. In phpBB's case, it's saved in cache/s9e_renderer_<hash>.php.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Integrate s9e\TextFormatter

Post by EXreaction » Sat Aug 17, 2013 6:32 pm

Just reuse the code from bbcode.php for now, it's pretty easy to address later.

I meant the bbcode.html template code (e.g. <!-- BEGIN -->). I'm not entirely sure I understand how you're planning on parsing things however, I assumed you would take the parsed output from the template engine for each bbcode, then have your engine handle the replacement of the actual strings/etc.

User avatar
JoshyPHP
Registered User
Posts: 363
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Sat Aug 17, 2013 7:23 pm

My plan right now is to capture all the template fragments from bbcode.html and recompose each BBCode's template using the same syntax as custom BBCodes. For instance, for the BBCode i: i_open + {TEXT} + i_close = <em>{TEXT}</em>. After this, it's exactly the same as a custom BBCode entered in the admin panel.

For BBCodes that have more than one representation like list or quote, s9e\TextFormatter supports conditionals that end up being compiled into PHP's if-elseif-else.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Integrate s9e\TextFormatter

Post by EXreaction » Sat Aug 17, 2013 8:00 pm

What would the html file look like then when you're done (any examples)?

User avatar
JoshyPHP
Registered User
Posts: 363
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Sat Aug 17, 2013 9:48 pm

It doesn't create any HTML file. In short, it goes like this: <special custom BBCode syntax like phpBB's admin panel> :arrow: XSLT :arrow: <internal representation> :arrow: PHP.

And here's a near-complete rundown.

In phpBB land, phpbb_textformatter_s9e_factory::get_configurator() creates an instance of s9e\TextFormatter\Configurator and adds all the custom BBCodes, smilies, etc... Here, BBCodes use the same syntax as the one you'd use in the admin panel. (it's more of a superset though)

At this point, a BBCode's template may look like this:

Code: Select all

<a href="{URL}">{TEXT}</a>
The BBCodes plugin in s9e\TextFormatter receives this template and transparently replaces the tokens with XSL elements, as XSL is the language it uses internally. Now this BBCode's template looks like this:

Code: Select all

<a href="{@url}"><xsl:apply-templates/></a>
Back in phpBB land, after everything's configured, phpbb_textformatter_s9e_factory::regenerate() calls for the configuration to be finalized, which automatically causes a renderer to be created by s9e\TextFormatter and saved to the configured dir (see services.yml/text_formatter.yml). The templates used by every BBCodes (but also other plugins such as the Emoticons plugin) are coalesced into a single XSL stylesheet. Here's an example of the stylesheet that gets generated by my test board, pretty-printed.

If you use s9e\TextFormatter's default XSLT renderer, that's where it ends. In phpBB, I use the PHP renderer instead, so the PHP renderer generator takes the stylesheet, parses it into an internal representation and finally serializes it into a PHP class, displayed here pretty-printed.


This PHP renderer is the equivalent of Twig's cache files. You can find it in cache/s9e_renderer_*.php

User avatar
JoshyPHP
Registered User
Posts: 363
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Sun Aug 18, 2013 9:40 pm

I'm a bit stuck wrt styles. What's the best way to get a list of all styles? Should I just query the database like style_select() does? And once I have the list of styles, what's the easiest way to get the bbcode.html of each style? I thought that reusing the code from bbcode::bbcode_cache_init() would be the simplest but it requires a user object and it ends up being too complicated and hard to test.

If there's no easy way to get the bbcode.html file for each style I might just look them up directly in the styles/*/template/ dir, and leave it to be refactored later.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Integrate s9e\TextFormatter

Post by EXreaction » Mon Aug 19, 2013 3:19 pm

You shouldn't need to get the bbcode.html file for each style, should you (I'm assuming you're trying to cache everything at once)?

If you just need the one for the current style, you could do template->set_filenames(array('bbcode => 'bbcode.html')); template->get_source_file_for_handle('bbcode') will then return the path to the correct file for the current user's style.

User avatar
JoshyPHP
Registered User
Posts: 363
Joined: Fri Jul 08, 2011 9:43 pm

Re: [RFC] Integrate s9e\TextFormatter

Post by JoshyPHP » Mon Aug 19, 2013 4:24 pm

Actually I do need every bbcode.html file at the same time. All the templates of all the BBCodes of all the styles get cached in the same file.

User avatar
EXreaction
Registered User
Posts: 1555
Joined: Sat Sep 10, 2005 2:15 am

Re: [RFC] Integrate s9e\TextFormatter

Post by EXreaction » Tue Aug 20, 2013 3:35 am

Yea, there really isn't any way of doing that with the current code, you'd need to run a query, create a new instance of the template engine, pass the paths and the inheritance chain, then have it search for the appropriate file. If you could figure out a way to only cache the current user's style and then grab the correct file name from the template engine if the current user's style isn't already cached and cache it, that might be easiest.

Post Reply