3.2 Text Parser/Renderer tutorial

Discussion forum for Extension Writers regarding Extension Development.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: 3.2 Text Reparser tutorial

Post by mrgoldy »

Hmmm, I'm calling it a day for now, I honestly can't figure out what's going wrong.

1.
If I straight up insert_array['post_text'] = $this->request->variable('post_text', '', true); into the database, the database holds already the &lt;&amp;&gt;, without the <t>.

2.
If I straight up insert_array['post_text'] = $this->parser->parse('<&>') into the database, the database holds the correct <t>&lt;&amp;&gt;</t>

3.
And then when I $this->parser->parse($this->request->variable('post_text', '', true)); the output is <t>&amp;lt;&amp;amp;&amp;gt;</t>, so basically it decodes all the &-sings from example 1.
(I've tried various ways, options etc, multibyte makes no difference aswell. And I am sure I am not 'accidentaly' parsing it twice myself somewhere ..

I've uploaded the extension I've got thusfar, but it's already rather big so not sure if it's followable and I can't expect you to look at it, when I can't even make sense of it myself of what's going on.

Thanks for your trouble though, I'll stumble on the solution/problem in a couple of days when I least expect it :x *fingers crossed*
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: 3.2 Text Reparser tutorial

Post by mrgoldy »

Hey Joshy, I'm back. Bet you're happy to see me :D

I made the tiniest of extensions to show my problem: https://github.com/mrgoldy/textformatter
Could you please have a look at this one, as it shows/has the same problem I am currently having.
I am doing nothing special / weird, yet the requested outcome of inserting <&> is still &lt;&amp;&gt;
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
JoshyPHP
Code Contributor
Posts: 1288
Joined: Mon Jul 11, 2011 12:28 am

Re: 3.2 Text Reparser tutorial

Post by JoshyPHP »

I scanned through the files quickly but there's no reparser in that extension so I guess your problem is not the reparser. I can't debug that extension so here's the simplest way to parse and render something. Open phpBB's index.php and add that after $user->setup('viewforum');

Code: Select all

$text = '<&>';
$xml  = $phpbb_container->get('text_formatter.parser')->parse($text);
$html = $phpbb_container->get('text_formatter.renderer')->render($xml);
die($html);
Then go to the index and you'll see that the text is rendered properly. Hopefully it will help you find out what's wrong with your extension. Maybe something escapes your input.
I wrote the library that handles markup in phpBB 3.2+.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: 3.2 Text Reparser tutorial

Post by mrgoldy »

I made it so everything happens just in the controller:
https://github.com/mrgoldy/textformatte ... in.php#L97
Uses the three options, parse, utils and render.
No options are anything

And I understand that when I exchange the $this->request of the post text to a static/hard-coded <&>, it works.
ie. change Line #97 $post_text1 to <&>, it works.
But the problem is that I only use the simplest forms of requesting something from a (edit-)form and it doesn't work anymore.
ie. the current line #96

Alternatively, do you have/know an extension that uses the text_formatter in this way already, which I can have a look at?
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: 3.2 Text Parser/Renderer tutorial

Post by kasimi »

The $request->variable() method applies htmlspecialchars to the data. Before rendering, do the reverse:

Code: Select all

$post_text1 = htmlspecialchars_decode($post_text1, ENT_COMPAT);
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: 3.2 Text Parser/Renderer tutorial

Post by mrgoldy »

kasimi wrote: Wed Nov 29, 2017 12:08 pm The $request->variable() method applies htmlspecialchars to the data. Before rendering, do the reverse:

Code: Select all

$post_text1 = htmlspecialchars_decode($post_text1, ENT_COMPAT);
Saviour! Thanks for the final solution.

And thanks to JoshyPHP for sticking it out with me. :thumbsup:
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
Post Reply

Return to “Extension Writers Discussion”