Workaround for the /e RegEx modifier

Get help with installation and running phpBB 3.3.x here. Please do not post bug reports, feature requests, or extension related questions here.
Locked
ayman1
Registered User
Posts: 117
Joined: Wed May 06, 2009 5:56 pm

Workaround for the /e RegEx modifier

Post by ayman1 »

I have a forum written with PHPBB 3.3, which has worked well for 12 years and I'm not allowed to upgrade it to the latest version of phpBB. Recently, I had to port it to a new server which has a newer version of PHP. The one the older server used was 5.6.x. The new server has the latest version of PHP. Now the forum on the new server fails to display some pages and instead displays notices that the /e modifier was deprecated and advices that I use preg_replace_callback instead as a workaround.

I found good suggestions online for doing that, so, I searched for every occurance of /e modifier and did the suggested replacement. For example, in file includes/bbcode.php, around line 379,

Code: Select all

// Replace {L_*} lang strings
//$bbcode_tpl = preg_replace('/{L_([A-Z_]+)}/e', "(!empty(\$user->lang['\$1'])) ? \$user->lang['\$1'] : ucwords(strtolower(str_replace('_', ' ', '\$1')))", $bbcode_tpl);
$bbcode_tpl = preg_replace_callback(
	'/{L_([A-Z_]+)}/', 
	function($matches){
		foreach($matches as $match)
			return (!empty($user->lang[$match])) ? $user->lang[$match] : ucwords(strtolower(str_replace('_', ' ', $match)));
	},
	$bbcode_tpl
);
And that seems to work. However, the reason it does is that the replacement is a literal, thus I can construct from it the return value of the callback function and simply replace numbered groups with $match.

There is, unfortunately one place where the replacement is not literal. It's in the same file, bbcode.php, around line 113,

Code: Select all

$message = preg_replace($preg['search'], $preg['replace'], $message);
$preg = array('search' => array(), 'replace' => array());
That one $message line causes numerous notices which either are displayed on the web page, or halt the forum completely.

How do I write a workaround for $preg['replace'] when I have no idea what the replacement may be?

All help is appreciated.

P.S. I tried commenting out that $message line and it resulted in no errors or notices but all BBCodes are no longer expanded :x
User avatar
warmweer
Jr. Extension Validator
Posts: 11235
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: Workaround for the /e RegEx modifier

Post by warmweer »

ayman1 wrote: Sat Oct 02, 2021 4:33 pm I have a forum written with PHPBB 3.3, which has worked well for 12 years and I'm not allowed to upgrade it to the latest version of phpBB. Recently, I had to port it to a new server which has a newer version of PHP. The one the older server used was 5.6.x. The new server has the latest version of PHP. Now the forum on the new server fails to display some pages and instead displays notices that the /e modifier was deprecated and advices that I use preg_replace_callback instead as a workaround.
Your last post (before this one) dates from the phpBB 3.0.x days.

You now mention "a forum written with phpBB 3.3". What does written with mean?
But you mention not being allowed to upgrade it to the latest version (which is 3.3.4). Is something forbidden? or it just fails?

You need to clarify the above statements.
Which version is your board using now?
Did you try to upgrade? and if yes how?

In case you did try: did you follow the instructions at Upgrading from 3.0 to 3.3?

As to the rest of your post:
It seems you're trying to get the old version (possibly 3.0.x) to work with the latest version of php, and that is problematic.
I take it that you have modifications (perhaps recognised mods) on your 3.0.x. If that's the case, most, if not all will produce errors with phpBB 3.3 (and php > 7)
Wouldn't it be better to upgrade to 3.3.4 and then use extensions to get back some or all functionalities of the mods?

Please post the Support Request Template, including as much info as necessary in order to allow a better assessment of what you're trying to do. (without which it's quite difficult to provide to the point assistance).
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
ayman1
Registered User
Posts: 117
Joined: Wed May 06, 2009 5:56 pm

Re: Workaround for the /e RegEx modifier

Post by ayman1 »

My bad! My board uses version 3.0 of phpBB. Team lead made numerous customizations to the default forum. That's why I cannot upgrade the forum to use the latest version of phpBB.
I managed to workaround all the errors that resulted from the new server using the latest PHP. The old server had no problem with the /e modifier. The only place that I couldn't fix is the code excerpt I quoted. Any help in working around that is apreciated.
User avatar
warmweer
Jr. Extension Validator
Posts: 11235
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: Workaround for the /e RegEx modifier

Post by warmweer »

ayman1 wrote: Sat Oct 02, 2021 11:00 pm My bad! My board uses version 3.0 of phpBB. Team lead made numerous customizations to the default forum. That's why I cannot upgrade the forum to use the latest version of phpBB.
I managed to workaround all the errors that resulted from the new server using the latest PHP. The old server had no problem with the /e modifier. The only place that I couldn't fix is the code excerpt I quoted. Any help in working around that is apreciated.
Strictly speaking In this specific forum support for 3.0.x is limited to help with upgrading to 3.3.x (since 3.0 has been EOL for quite some time now)
Perhaps if you describe the customisations, members here could suggest extensions which could cater to your specific needs.
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
User avatar
stevemaury
Support Team Member
Support Team Member
Posts: 52768
Joined: Thu Nov 02, 2006 12:21 am
Location: The U.P.
Name: Steve
Contact:

Re: Workaround for the /e RegEx modifier

Post by stevemaury »

Support for 3.0 and v3.1 ended long ago. The only support is assistance in upgrading to 3.4 orv3.3. Sooner or later, your host's php version will be end-of-life and your board will not work al all.

What is the php version being used on the new server?
I can stop all your spam. I can upgrade or update your Board. PM or email me. (Paid support)
ayman1
Registered User
Posts: 117
Joined: Wed May 06, 2009 5:56 pm

Re: Workaround for the /e RegEx modifier

Post by ayman1 »

The board is working, except for that one hurdle which I posted in detail. It cannot expand any BBCode because of the /e modifier. If there's a workaround for it, please suggest it.

The new server uses PHP 7.0.
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 5871
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.
Contact:

Re: Workaround for the /e RegEx modifier

Post by thecoalman »

As already noted we only support upgrading. The issue you are encountering now will only get worse as time goes by and the host forces php upgrades. A lot of them are already forcing php 7.2 which itself is already EOL.

Strongly suggest you look at path forward to upgrade as it's inevitable.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Workaround for the /e RegEx modifier

Post by AmigoJack »

ayman1 wrote: Sat Oct 02, 2021 4:33 pmdisplays notices that the /e modifier was deprecated
Workaround #1: disable notices. You aren't looking at any log anyway for notices - if you would you should have encountered other things to fix already.
ayman1 wrote: Sat Oct 02, 2021 4:33 pm

Code: Select all

	function($matches){
...
			return (!empty($user->lang[$match])) ? $user->lang[$match]
I'm surprised the function even knows the $user variable. Are you sure it actually works?
ayman1 wrote: Sat Oct 02, 2021 4:33 pmbbcode.php, around line 113
You could have checked how current phpBB versions do it around that line. And if I remember correctly you'd also have to fix the PHP code for BBCodes that is stored in the database, because their search patterns also include the e modifier. Especially if you defined custom BBCodes.
ayman1 wrote: Sun Oct 03, 2021 12:38 amThe board is working, except for
I have a counter example: "I'm not pregnant, except for...". Either it works or it doesn't. If you argument with "almost working" then you must also accept the workaround of "just don't use/parse BBCodes anymore" - that's your fix: disable BBCodes and the board can be used.

I've gone thru the same thing, but in 2016 already (and even then the deprecation of that feature wasn't new anymore) and can tell you: it's totally possible to fix all occurances and writing proper code. Supporting custom BBCodes is the challenge to check if you're mastering all this, because there you need to parse it yourself (unless you want to do something as trivially stupid as just throwing it all into eval()). Then you can take care of all the other fixes that are needed and have been ignored way too long (because nobody pays attention to PHP notices and hints although they were there for the whole time already).

Maybe you want to seek a professional and pay him.
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
User avatar
warmweer
Jr. Extension Validator
Posts: 11235
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Bel ... gium
Contact:

Re: Workaround for the /e RegEx modifier

Post by warmweer »

AmigoJack wrote: Sun Oct 03, 2021 3:36 am ...
Maybe you want to seek a professional and pay him.
or her ;-)
Spelling is freeware, which means you can use it for free.
On the other hand, it is not open source, which means you cannot change it or publish it in a modified form.


Time flies like an arrow, but fruit flies like a banana.
ayman1
Registered User
Posts: 117
Joined: Wed May 06, 2009 5:56 pm

Re: Workaround for the /e RegEx modifier

Post by ayman1 »

Good points you raise. Thank you.
AmigoJack wrote: Sun Oct 03, 2021 3:36 am Workaround #1: disable notices. You aren't looking at any log anyway for notices - if you would you should have encountered other things to fix already.
I tried to disable the notes, but they still display. I used error_reporting(E_ERROR | E_WARNING | E_PARSE). Maybe I should use error_reporting(0)?

I do look at error_log. It has the same notices and more. What is written to the log and what is written to the web pages?
AmigoJack wrote: Sun Oct 03, 2021 3:36 am I'm surprised the function even knows the $user variable. Are you sure it actually works?
It's odd, but it did. However, I corrected that later using function() use($user).
AmigoJack wrote: Sun Oct 03, 2021 3:36 am And if I remember correctly you'd also have to fix the PHP code for BBCodes that is stored in the database, because their search patterns also include the e modifier. Especially if you defined custom BBCodes.
Now that is an excellent suggestion! I'll certainly look into it.
AmigoJack wrote: Sun Oct 03, 2021 3:36 amI have a counter example: "I'm not pregnant, except for...". Either it works or it doesn't. If you argument with "almost working" then you must also accept the workaround of "just don't use/parse BBCodes anymore" - that's your fix: disable BBCodes and the board can be used.
The reason I say it works is that the important content displays fine. BBCodes produce something analogous to visual aids in a classroom :)
AmigoJack wrote: Sun Oct 03, 2021 3:36 amyou need to parse it yourself (unless you want to do something as trivially stupid as just throwing it all into eval()). Then you can take care of all the other fixes that are needed and have been ignored way too long
I'm fine with rewriting preg_match and preg_replace. Do you know of any site or book that has their algorithms?
AmigoJack wrote: Sun Oct 03, 2021 3:36 amMaybe you want to seek a professional and pay him.
That too is a good suggestion. I'll see if the team lead will go for it.
ayman1
Registered User
Posts: 117
Joined: Wed May 06, 2009 5:56 pm

Re: Workaround for the /e RegEx modifier

Post by ayman1 »

thecoalman wrote: Sun Oct 03, 2021 1:40 am As already noted we only support upgrading. The issue you are encountering now will only get worse as time goes by and the host forces php upgrades. A lot of them are already forcing php 7.2 which itself is already EOL.

Strongly suggest you look at path forward to upgrade as it's inevitable.
I attempted to install PHPBB3.3.4 this morning and immediately the installer gave me the error that the "phpbb_" prefix already exists and that I should use an alternative. I specified an alternative "phpbb334_" and I got an error that it couldn't connect. Version 3.0 can connect with no problem. So, the update option hit a brick wall.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53400
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: Workaround for the /e RegEx modifier

Post by Brf »

ayman1 wrote: Thu Oct 07, 2021 8:09 pm the installer gave me the error that the "phpbb_" prefix already exists
That is because your forum database already exists. If you are looking to upgrade you should not be installing, only updating the database.
User avatar
AmigoJack
Registered User
Posts: 6108
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Workaround for the /e RegEx modifier

Post by AmigoJack »

ayman1 wrote: Thu Oct 07, 2021 8:04 pmI used error_reporting(E_ERROR | E_WARNING | E_PARSE). Maybe I should use error_reporting(0)?
...
What is written to the log and what is written to the web pages?
As per the documentation an E_WARNING will happen, so you would have to omit that from reported errors, i.e. by calling error_reporting(E_ERROR | E_PARSE). However, that's just a quick workaround. It would be better to report any error and to not display any. The log file gets all messages that you want to be reported, and with the display setting you decide if everybody should see messages on the websites, too.
ayman1 wrote: Thu Oct 07, 2021 8:04 pmDo you know of any site or book that has their algorithms?
That would be one about phpBB's search and replace patterns in the database for replacing BBCode with the intended output. No, I'm sure such a book does not exist. Just look at what you got: it sure is some work to go thru, but it can be generalized. If you ever used /e yourself or are familiar with nested strings it should be even less challenging. One part could be:

Code: Select all

$this->bbcode_specialchars(('${1}') ? '${1}' : 'http://${2}')
...for which you then have to execute the actual PHP code. Translating almost everything into preg_replace_callback() even has a performance boost because it is then native PHP code (which needs to be parsed only once, whereas a replacement literal had to be parsed again and again to let PHP interpret it as code to be executed).
  • "The problem is probably not my English but you do not want to understand correctly. ... We will not come anybody anyway, nevertheless, it's best to shit this." Affin, 2018-11-20
  • "But this shit is not here for you. You can follow with your. Maybe the question, instead, was for you, who know, so you shoved us how you are." axe70, 2020-10-10
  • "My reaction is not to everyone, especially to you." Raptiye, 2021-02-28
ayman1
Registered User
Posts: 117
Joined: Wed May 06, 2009 5:56 pm

Re: Workaround for the /e RegEx modifier

Post by ayman1 »

Alright! The workaround for the e modifier is now working, with a minor glitch in the
BBCode. The forum now is functional and its content is intact. The team lead is happy, and I am too. Now I have time to look at the upgrade path you guys are encouraging.

Thanks for everyone who helped.
User avatar
Kailey
Community Team Leader
Community Team Leader
Posts: 3733
Joined: Mon Sep 01, 2014 1:00 am
Location: sudo rm -rf /
Name: Kailey Snay
Contact:

Re: Workaround for the /e RegEx modifier

Post by Kailey »

This forum is for 3.3 support, not 3.0.
Kailey Snay - Community Team Leader
Knowledge Base | Documentation | Community rules

If you have any questions about the rules/customs of this website, feel free to send me a PM.
Locked

Return to “[3.3.x] Support Forum”