bbcode_second_pass_by_extension() method

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

bbcode_second_pass_by_extension() method

Post by v12mike » Sun Sep 16, 2018 6:46 am

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: 564
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: bbcode_second_pass_by_extension() method

Post by GanstaZ » 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.
"When answer lies in the question,.. question becomes redundant!"

v12mike
Registered User
Posts: 260
Joined: Thu Jul 09, 2015 5:03 pm

Re: bbcode_second_pass_by_extension() method

Post by v12mike » Sun Sep 16, 2018 7:16 am

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: 564
Joined: Wed Oct 11, 2017 10:29 pm
Location: Zverse

Re: bbcode_second_pass_by_extension() method

Post by GanstaZ » 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.
"When answer lies in the question,.. question becomes redundant!"

User avatar
3Di
Registered User
Posts: 12981
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: bbcode_second_pass_by_extension() method

Post by 3Di » Mon Sep 17, 2018 1:12 am

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.
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

v12mike
Registered User
Posts: 260
Joined: Thu Jul 09, 2015 5:03 pm

Re: bbcode_second_pass_by_extension() method

Post by v12mike » Mon Sep 17, 2018 5:48 am

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
Registered User
Posts: 12981
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milan (IT) Frankfurt (DE)
Name: Marco
Contact:

Re: bbcode_second_pass_by_extension() method

Post by 3Di » Mon Sep 17, 2018 6:23 am

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
Want to compensate me for my interest? Donate
Please PM me only to request paid works. Thx.
Extensions, Scripts, MOD porting, Update/Upgrades
My development's activity º PhpStorm's proud user

v12mike
Registered User
Posts: 260
Joined: Thu Jul 09, 2015 5:03 pm

Re: bbcode_second_pass_by_extension() method

Post by v12mike » Mon Sep 17, 2018 7:51 am

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
Recognised Extension Developer
Posts: 1769
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: bbcode_second_pass_by_extension() method

Post by Ger » 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/
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:
-Available for custom work-

v12mike
Registered User
Posts: 260
Joined: Thu Jul 09, 2015 5:03 pm

Re: bbcode_second_pass_by_extension() method

Post by v12mike » Tue Sep 25, 2018 7:29 am

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
Recognised Extension Developer
Posts: 1769
Joined: Wed Jan 02, 2008 7:35 pm
Location: 192.168.1.100
Contact:

Re: bbcode_second_pass_by_extension() method

Post by Ger » Tue Sep 25, 2018 7:43 am

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:
-Available for custom work-

Post Reply

Return to “Extension Writers Discussion”

Who is online

Users browsing this forum: No registered users and 8 guests