phpphpbb

Make PHPBB 3.0.14 and ABBC3 compatible with PHP 7.3


I'm trying to make ABBC3 work with PHP 7.3 and PHPBB 3.0.14 since I can't move to PHPBB 3.3 due lots of issues with MODs not ported to extensions and theme (Absolution).

I have asked help in PHPBB forum without luck because 3.0.x and 3.1.x version are not supported anymore.

So after dozens of hours trying to understand bbcode functions I'm almost ready.

My code works when there's a single bbcode in message. But doesn't works when there's more bbcode or it's mixed with texts.

So I would like to get some help to solve this part to make everything work.

In line 98 in includes/bbcode.php this function:

$message = preg_replace($preg['search'], $preg['replace'], $message);

Is returning something like this:

$message = "some text $this->Text_effect_pass('glow', 'red', 'abc') another text. $this->moderator_pass('"fernando"', 'hello!') more text"

For this message:

some text [glow=red]abc[/glow] another text.

[mod="fernando"]hello![/mod] more text

The input for preg_replace above is like this just for context:

"some text [glow=red:mkpanc3g]abc[/glow:mkpanc3g] another text. [mod="fernando":mkpanc3g]hello![/mod:mkpanc3g]"

So basically I have to split this string in valid expressions to apply eval() then concatenate everything. Like this:

$message = "some text". eval($this->Text_effect_pass('glow', 'red', 'abc');) . "another text " . eval($this->moderator_pass('"fernando"', 'hello!');). "more text"

In this specific case there's also double quotes left in '"fernando"'.

I know is not safe apply eval() to user input so I would like to make some type of preg_match and/or preg_split to get values inside of () to pass as parameter to my functions.

The functions are basically:

Text_effect_pass()
moderator_pass()
anchor_pass()
simpleTabs_pass()

I'm thinking in something like this (Please ignore errors here):

if(preg_match("/$this->Text_effect_pass/", $message)
{
 then split the string and get value inside of() and remove extra single or double quotes.


 after:
 $textEffect = Text_effect_pass($value[0], $value[1], $value[2]);

 Finally concatenate everything:
 $message = $string[0] .$textEffect. $string[1]; 
}
if(preg_match("/$this->moderator_pass/", $message)
{
.....
}

P.S.: ABBC3 is not compatible with PHP 7.3 due usage of e modifier. I have edited everything to remove the modifier.

Here you can see it working separately:

bbcode 1

bbcode 2

Can someone give me some help please?


Solution

  • After long time searching for a solution for this problem I found this site that helped me build the regex.

    Now I have managed to solve the problem and I have my forum fully working with PHPBB 3.14, PHP 7.3 and ABBC3.

    My solution is:

    // Start Text_effect_pass
    $regex = "/(\\$)(this->Text_effect_pass)(\().*?(\')(,)( )(\').*?(\')(,)( )(\').*?(\'\))/is";
    
    if (preg_match_all($regex, $message, $matches)) {
            foreach ($matches[0] as $key => $func) {
                    $bracket = preg_split("/(\\$)(this->Text_effect_pass)/", $func);
                    $param = explode("', '", $bracket[1]);
                    $param[0] = substr($param[0], 2);
                    $param[2] = substr($param[2], 0, strrpos($param[2], "')"));
                    $effect = $this->Text_effect_pass($param[0], $param[1], $param[2]);
                    if ($key == 0) {
                            $init = $message;
                    } else {
                            $init = $mess;
                    }
                    $mess = str_replace($matches[0][$key], $effect, $init);
            }
            $message = $mess;
    } // End Text_effect_pass
    
    // Start moderator_pass
    $regex = "/(\\$)(this->moderator_pass)(\().*?(\')(,).*?(\').*?(\'\))/is";
    
    if (preg_match_all($regex, $message, $matches)) {
            foreach ($matches[0] as $key => $func) {
                    $bracket = "/(\\$)(this->moderator_pass)/";
                    $bracket = preg_split($bracket, $func);
                    $param = explode("', '", $bracket[1]);
                    $param[0] = substr($param[0], 2);
                    $param[1] = substr($param[1], 0, strrpos($param[1], "')"));
    
                    $effect = $this->moderator_pass($param[0], $param[1]);
                    if ($key == 0) {
                            $init = $message;
                    } else {
                            $init = $mess;
                    }
                    $mess = str_replace($matches[0][$key], $effect, $init);
            }
            $message = $mess;
    } // End moderator_pass
    

    If someone is interested can find patch files and instructions here.

    Best regards.