bbcode_second_pass_by_extension() method

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
v12mike
Registered User
Posts: 584
Joined: Thu Jul 09, 2015 5:03 pm

bbcode_second_pass_by_extension() method

Post by v12mike »

I am trying to write an extension that modifies the rendering of some existing bbcodes. When the s9e renderer was introduced in phpBB 3.2, the old bbcode renderer was left in place, and existing bbcodes in posts were not re-parsed. This means that currently, if you want to modify the rendering of a bbcode, you need to write a method compatible with s9e and also a method compatible with the old renderer.

I have managed to get my extension working with s9e, but am having difficulty getting the old method to work. I am beginning to think that it is broken. Does anyone know of a currently working extension that uses the "bbcode_second_pass_by_extension" method?

The problem that I have encountered is that the event 'core.bbcode_cache_init_end' is used to pass back a custom preg_replace callback function which gets added into the bbcode parsing array.

The phpBB source code gives the example:

Code: Select all

/**
	* Function to perform custom bbcode second pass by extensions
	* can be used to assign bbcode pattern replacement
	* Example: '#\[list=([^\[]+):$uid\]#e'	=> "\$this->bbcode_second_pass_by_extension('\$1')"
	*
	* Accepts variable number of parameters
	*
	* @return mixed Second pass result
	*/
But the processing after the 'core.bbcode_cache_init_end' event has the code:

Code: Select all

							if (is_callable($preg['replace'][$key]))
							{
								$message = preg_replace_callback($search, $preg['replace'][$key], $message);
							}
Where '$preg['replace'][$key]' holds the extension-supplied callback function.

On my installation, (php7.1, phpBB3.2.3) the is_callable test fails if the callback function is specified with parameters, and the preg_replace_callback function fails if the callback function is specified without parameters.
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: bbcode_second_pass_by_extension() method

Post by GanstaZ »

Haven't seen anyone using that old method anymore and as i understand, there's no need to use it.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
v12mike
Registered User
Posts: 584
Joined: Thu Jul 09, 2015 5:03 pm

Re: bbcode_second_pass_by_extension() method

Post by v12mike »

GanstaZ wrote: Sun Sep 16, 2018 7:05 am Haven't seen anyone using that old method anymore and as i understand, there's no need to use it.
So how do you modify the handling of a pre-3.2 bbcode that is in the database in the format :

'[img:25vcjqrz]http://i42.photobucket.com/albums/e318/adnil11/Vince/oiu.jpg[/img:25vcjqrz]',

as this is not rendered by the s9e renderer, but is rendered by the function $bbcode->bbcode_second_pass($text, $uid); ?
User avatar
GanstaZ
Registered User
Posts: 1187
Joined: Wed Oct 11, 2017 10:29 pm
Location: GZOverse

Re: bbcode_second_pass_by_extension() method

Post by GanstaZ »

I was never interested in bbcodes, so can't say much about how, what and so on.. but i always remember useful topics: phpBB 3.2 Upgrade Notes for Extensions (BBCODE Changes) and Extensions and phpBB 3.2: you should probably read this topic.
Usus est magister optimus! phpBB pre-Triton & latest php environment.
When answer lies in the question, question becomes redundant!
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: bbcode_second_pass_by_extension() method

Post by 3Di »

v12mike wrote: Sun Sep 16, 2018 7:16 am So how do you modify the handling of a pre-3.2 bbcode that is in the database in the format :

'[img:25vcjqrz]http://i42.photobucket.com/albums/e318/adnil11/Vince/oiu.jpg[/img:25vcjqrz]',

as this is not rendered by the s9e renderer, but is rendered by the function $bbcode->bbcode_second_pass($text, $uid); ?
Did you try to reparse a singular post using the CLI reparser and see what happens?
Otherwise we could use another way I believe, try it first.
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
v12mike
Registered User
Posts: 584
Joined: Thu Jul 09, 2015 5:03 pm

Re: bbcode_second_pass_by_extension() method

Post by v12mike »

GanstaZ wrote: Sun Sep 16, 2018 3:21 pm I was never interested in bbcodes, so can't say much about how, what and so on.. but i always remember useful topics: phpBB 3.2 Upgrade Notes for Extensions (BBCODE Changes) and Extensions and phpBB 3.2: you should probably read this topic.
Although I had previously read those, I went back and read them again, and noticed:
Text Reparser (3.2 optional)
If your extension is storing text with BBCodes in its own tables in the database, you may want to consider adding a text reparser class. When phpBB updates a board to 3.2, it reparses all posts and a few other spots where phpBB uses BBCodes, updating them to the new BBCode format. Unparsed old bbcodes should still work as expected, but it can be piece of mind, especially if your extension stores a lot of messages with BBCodes, to have them updated to the new format.
Somehow, when my boards were upgraded to 3.2.0, this reparsing did not occur (I now have no recollection of that upgrade), and all of the old BBCodes were still in the 3.1 format. I have now run the reparser ( bin/phpbbcli.php reparser:reparse) on my test database and now I don't need to use the bbcode_second_pass_by_extension() method.

Thank you both for your help.

I now don't understand why the code for the 3.1 style BBCodes has been retained in phpBB 3.2, but presumably it will be removed one day.
User avatar
3Di
I've Been Banned!
Posts: 17538
Joined: Mon Apr 04, 2005 11:09 pm
Location: I'm with Ukraine 🇺🇦
Name: Marco
Contact:

Re: bbcode_second_pass_by_extension() method

Post by 3Di »

v12mike wrote: Mon Sep 17, 2018 5:48 am I now don't understand why the code for the 3.1 style BBCodes has been retained in phpBB 3.2, but presumably it will be removed one day.
That could be since that code is very old and basically unused nowadays.
In any case since you asked for an extension (here ABD) which have in use those events, and for the posterity.. here you go:

https://github.com/cYbercOsmOnauT/wysiw ... parser.php
🆓 Free support for our extensions also provided here: phpBB Studio
🚀 Looking for a specific feature or alternative option? We will rock you!
Please PM me only to request paid works. Thx. Buy me a coffee -> Image
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
v12mike
Registered User
Posts: 584
Joined: Thu Jul 09, 2015 5:03 pm

Re: bbcode_second_pass_by_extension() method

Post by v12mike »

3Di wrote: Mon Sep 17, 2018 6:23 am In any case since you asked for an extension (here ABD) which have in use those events, and for the posterity.. here you go:

https://github.com/cYbercOsmOnauT/wysiw ... parser.php
I did already see that, and although I did not try installing that extension, I copied the code from it's listener file, and it does not work either.

My suspicion is that php V7.x has tightened up the rules for callback function syntax and that has broken the method.
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: bbcode_second_pass_by_extension() method

Post by Ger »

Perhaps you're better off just reparsing your text. 1 time job that spares you a lot of work: https://www.phpbb.com/support/docs/en/3 ... -reparser/
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
v12mike
Registered User
Posts: 584
Joined: Thu Jul 09, 2015 5:03 pm

Re: bbcode_second_pass_by_extension() method

Post by v12mike »

Ger wrote: Tue Sep 25, 2018 7:25 am Perhaps you're better off just reparsing your text. 1 time job that spares you a lot of work: https://www.phpbb.com/support/docs/en/3 ... -reparser/
Yes, I already came to that conclusion. It is a pity that there is no warning to the admin that the database still contains old-style BBCodes that should be reparsed.
User avatar
Ger
Registered User
Posts: 2108
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: bbcode_second_pass_by_extension() method

Post by Ger »

Well, for most admins (i really think >99%) it's not a matter of concern at all. My Quoted Where extension does have such a warning since it depends on the textformatter (and it's the reason why I wrote that KB article).
My extensions:
Simple CMS, Feed post bot, Avatar Resize, Modbreak, Magic OGP, Live topic update, Modern Quote, Quoted Where (GDPR) and Autoresponder.
Newest: FAQ manager for 3.2

Like my work? Buy me a coffee to keep it coming. :ugeek:

-Don't PM me for support-
Post Reply

Return to “Extension Writers Discussion”