[RFC] Integrate s9e\TextFormatter
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Integrate s9e\TextFormatter
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.
Re: [RFC] Integrate s9e\TextFormatter
You're talking about a different thing. If you look into bbcode::bbcode_cache_init() and bbcode::bbcode_tpl() you can see howbrunoais wrote:Wrong.
The bitfield marks which BBCodes were used in that text out of all the predefined ones.
$this->template_bitfield
is being used.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:You might want to use the template engine to load and parse the bbcode.html file
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:(the template code will all need to be rewritten in it as it uses old phpBB 2.0 style code).
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.EXreaction wrote:It can handle caching the file and rendering.
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Integrate s9e\TextFormatter
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.
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.
Re: [RFC] Integrate s9e\TextFormatter
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:
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.
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.
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Integrate s9e\TextFormatter
What would the html file look like then when you're done (any examples)?
Re: [RFC] Integrate s9e\TextFormatter
It doesn't create any HTML file. In short, it goes like this: <special custom BBCode syntax like phpBB's admin panel>
XSLT
<internal representation>
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:
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:
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
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>
Code: Select all
<a href="{@url}"><xsl:apply-templates/></a>
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
Re: [RFC] Integrate s9e\TextFormatter
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.
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.
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Integrate s9e\TextFormatter
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.
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.
Re: [RFC] Integrate s9e\TextFormatter
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.
- EXreaction
- Registered User
- Posts: 1555
- Joined: Sat Sep 10, 2005 2:15 am
Re: [RFC] Integrate s9e\TextFormatter
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.