Extensions and phpBB 3.2: you should probably read this topic

Discussion forum for Extension Writers regarding Extension Development.
User avatar
JoshyPHP
Code Contributor
Posts: 1029
Joined: Mon Jul 11, 2011 12:28 am

Extensions and phpBB 3.2: you should probably read this topic

Post by JoshyPHP » Sun Apr 12, 2015 9:16 pm

In phpBB 3.2, all of the BBCodes, smilies and other text formatting has been replaced by this library: s9e\TextFormatter. Posts and other rich text fields are stored in a different format, many things have changed and some extensions will need to be updated to continue to function properly with phpBB 3.2. Before describing what's changed, here's what has not changed:
  • If your extension does not modify posts, you probably won't have to update it for it to work on 3.2.
  • The functions decode_message(), generate_text_for_display(), generate_text_for_edit(), generate_text_for_storage() and strip_bbcode() work the same way.
  • Most custom BBCodes are compatible.
  • If your extension only modifies text through the core.modify_text_for_display_after event, there's a good chance it will work without any change.
Posts in phpBB 3.1 are stored as HTML, with BBCodes and some other features being replaced at rendering time. In phpBB 3.2, new posts are stored as XML and transformed into HTML at rendering time. This has multiple implications:
  1. It is unwise to modify posts in the database with string functions such as str_replace() or preg_replace().
  2. You cannot inject HTML into a post and have it be displayed as-is.
If you are currently developing an extension that either reads or modifies rich text and you want to make sure that it will work in phpBB 3.2, post a link to your extension here with a description of how it interacts with rich text. I will personally look into it and outline how it needs to be updated, if at all. Some documentation and examples are already available in the library's doc and more will be added based on feedback.

I will update this topic as time permits. What subject I will cover depends heavily on feedback from extension authors.
Last edited by JoshyPHP on Mon Apr 16, 2018 1:30 pm, edited 2 times in total.
I wrote the thing that does BBCodes in 3.2.

User avatar
hanelyp
Registered User
Posts: 124
Joined: Wed Apr 02, 2014 10:20 pm

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by hanelyp » Fri May 01, 2015 7:01 pm

viewtopic.php?f=456&t=2306161
uses events:
core.modify_text_for_display_before to catch text before normal bbcode processing. Matches $event['text'] against
'#\[dice\sseed=(\d+)\ssecure=(\w+):?\w*\](.+?)\[/dice\]#i'
for replacement.

core.posting_modify_message_text to inspect for a specific tag at posting time, again before bbcode processing. Matches $event['message_parser']->message against
'#\[dice\sseed=(\d+)\ssecure=(\w+):?\w*\](.+?)\[/dice\]#i'

brunoais
QA Team
Posts: 420
Joined: Wed Jun 18, 2008 10:50 am

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by brunoais » Sat May 02, 2015 1:17 pm

Is that a question...?

User avatar
JoshyPHP
Code Contributor
Posts: 1029
Joined: Mon Jul 11, 2011 12:28 am

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by JoshyPHP » Mon May 04, 2015 4:52 am

hanelyp wrote:viewtopic.php?f=456&t=2306161
uses events:
I looked into it but it's hard to make sense of it. The biggest problem is that you inject your PHP inside the BBCode definition rather than modify the text via an event.

If you want to modify what the user posts, you should probably do it in core.posting_modify_message_text.
For the template, don't inject PHP in second_pass_replace. How about outputting a simple <div> with your metadata as data- attributes then use events like core.modify_text_for_display_after and core.modify_format_display_text_after to fully render the div?

You could have a custom BBCodes such as this:

Code: Select all

[dice seed={NUMBER} secure={IDENTIFIER}]{TEXT}[/dice]

Code: Select all

<div data-seed="{NUMBER}" secure="{IDENTIFIER}">{TEXT}</div>
Then you would use the events mentionned above to add your dice roll to the HTML with preg_replace_callback() using the values in the div's attributes.
I wrote the thing that does BBCodes in 3.2.

User avatar
Neuropass
Registered User
Posts: 1158
Joined: Fri Apr 17, 2009 2:02 pm
Location: SciTE4AutoIt3

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by Neuropass » Wed May 06, 2015 8:34 pm

The usual confusion here with members. I see no ranks on JoshyPHP (no offense) meaning to me is a regular Joe posting something that might be true and might be not. These sorta of notifications should come from a designed phpBB team member or a what about a phpBB info Bot? Shouldn't be so hard. Yet this happens all the time. Stick to One source, make it official , follow a method. Thank-you.

User avatar
bonelifer
Community Team Member
Community Team Member
Posts: 3476
Joined: Wed Oct 27, 2004 11:35 pm
Name: William
Contact:

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by bonelifer » Wed May 06, 2015 9:19 pm

Neuropass, a team member stickied this, regular members don't have the ability to make posts stickies. OFFICIAL. Second, JoshyPHP, is the code contributor for s9e\TextFormatter.
Knowledge Base | phpBB Board Rules | Search Customisation Database
Image
Please don't contact me via PM or email for phpBB support .

User avatar
JoshyPHP
Code Contributor
Posts: 1029
Joined: Mon Jul 11, 2011 12:28 am

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by JoshyPHP » Fri Sep 11, 2015 7:14 pm

marcovo asked me to take a look at his Hide BBcode extension.

The extension adds a BBCode whose content is only displayed to some users. The BBCode's template displays the hidden text between HTML comments that serve as markers, and the extension listens for the core.modify_text_for_display_after and core.modify_format_display_text_after events to remove the text to hide it from unauthorized users. Those events are triggered after the BBCodes have been rendered as HTML so unless I missed something that extension should work in 3.2 without any modifications.

In phpBB 3.2 however, there is a better--albeit not backward compatible--way to display content differently depending on the user: conditionals and template parameters. For instance, the [HIDE] BBCode could be defined as follow:

Code: Select all

[HIDE]{TEXT}[/HIDE]

Code: Select all

<xsl:if test="$SHOW_HIDDEN_POSTS">{TEXT}</xsl:if>
That template will only display its content if $SHOW_HIDDEN_POSTS is true-ish, e.g. anything but an empty string or 0. Template parameters can be set during the core.text_formatter_s9e_renderer_setup or core.text_formatter_s9e_render_before events using the following:

Code: Select all

$renderer->get_renderer()->setParameter('SHOW_HIDDEN_POST', true);
I wrote the thing that does BBCodes in 3.2.

«THÖMÅS®©»
Registered User
Posts: 520
Joined: Sun Feb 27, 2011 5:38 pm
Location: UK
Contact:

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by «THÖMÅS®©» » Fri Jul 22, 2016 11:37 am

What does this mean for phpBB users running 3.0.x and 3.1.x?

Does this mean that an entire website that may contain thousands of posts may have to be started from scratch or is there a plan for an auto updater for this?
“No, this trick won't work... How on earth are you ever going to explain in terms of chemistry and physics so important a biological phenomenon as first love?” - Albert Einstein
"For every action has is an equal and opposite reaction". - Sir Isaac Newton
"In honor there is hope" - Alaska State Troopers

Owner & President @ =DN= Dark Nexus Multi-Gaming Clan

User avatar
david63
Registered User
Posts: 16561
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by david63 » Fri Jul 22, 2016 11:44 am

«THÖMÅS®©» wrote:What does this mean for phpBB users running 3.0.x and 3.1.x?

Does this mean that an entire website that may contain thousands of posts may have to be started from scratch or is there a plan for an auto updater for this?
If you read the OP it is talking about extensions, hence the reason it is in Extension Writers Discussion. So if you are developing any extensions you need to take note of what is being said - otherwise there is no problem
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3907
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by kasimi » Sun Sep 25, 2016 3:05 pm

The mChat extension has an option in the ACP to disallow BBCodes to be posted. For example the admin specifies b|u|code and when a user then sends the message

Code: Select all

[b]123[/b]
the BBCode should be removed and the message 123 should be stored in the database. The code that currently does this for 3.1 is admittedly not the cleanest but it gets the job done:

Code: Select all

$message = '[b]123[/b]';

$bbcode_replace = array(
    '#\[(' . str_replace('*', '\*', $this->config['mchat_bbcode_disallowed']) . ')[^\[\]]+\]#Usi',
    '#\[/(' . str_replace('*', '\*', $this->config['mchat_bbcode_disallowed']) . ')[^\[\]]+\]#Usi',
);

$message = preg_replace($bbcode_replace, '', $message); // '123'   
What's the best approach for 3.2?

User avatar
JoshyPHP
Code Contributor
Posts: 1029
Joined: Mon Jul 11, 2011 12:28 am

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by JoshyPHP » Sun Sep 25, 2016 3:15 pm

That would be through the textformatter.parser service using the disable_bbcode() method.

Look for parser_interface in https://area51.phpbb.com/docs/code/3.2.x/

Code: Select all

$parser = $phpbb_container->get('textformatter.parser');
$parser->disable_bbcode('b');
$parser->disable_bbcode('u');
$parser->disable_bbcode('code'); 
I wrote the thing that does BBCodes in 3.2.

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3907
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by kasimi » Sun Sep 25, 2016 3:35 pm

Works like charm, thank you.

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3907
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by kasimi » Mon Sep 26, 2016 9:00 pm

I have to correct myself, it works most of the time. It works with all the BBCodes that I've tested except for images:

Code: Select all

$this->parser->disable_bbcode('img');

$message = '[img]https://images.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png[/img]';

generate_text_for_storage($message, ...)
Posting this $message still shows the image. Any ideas?

Oh nevermind. phpBB's message_parser:parse() method overwrites the isDisabled flag of the [img] BBCode with the $allow_img_bbcode parameter passed to it.

User avatar
JoshyPHP
Code Contributor
Posts: 1029
Joined: Mon Jul 11, 2011 12:28 am

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by JoshyPHP » Mon Sep 26, 2016 9:10 pm

You could also just use the parser service directly to parse the text.
I wrote the thing that does BBCodes in 3.2.

User avatar
kasimi
Extension Customisations
Extension Customisations
Posts: 3907
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Extensions and phpBB 3.2: you should probably read this topic

Post by kasimi » Mon Sep 26, 2016 9:40 pm

generate_text_for_storage() uses phpBB's message_parser class that - in addition to parsing the message - checks for maximum message length, removes quotes that are nested too deep and more. I'd have to do all that myself if I use the parse() method, correct?

Apart from that, does that mean that $uid, $bitfield and $options that are passed to generate_text_for_storage() are obsolete in 3.2.x and the return value of $this->parser->parse($message) is the only thing required for displaying the message later?

Post Reply

Return to “Extension Writers Discussion”