【问题标题】:Make PHPBB 3.0.14 and ABBC3 compatible with PHP 7.3使 PHPBB 3.0.14 和 ABBC3 与 PHP 7.3 兼容
【发布时间】:2019-12-02 18:59:06
【问题描述】:

我正在尝试使 ABBC3 与 PHP 7.3 和 PHPBB 3.0.14 一起使用,因为我无法迁移到 PHPBB 3.3,因为未移植到扩展和主题的 MOD 存在很多问题(绝对解决)。

我已经在PHPBB forum 寻求帮助但没有运气,因为不再支持 3.0.x 和 3.1.x 版本。

所以在尝试理解 bbcode 功能数十小时后,我几乎准备好了。

当消息中只有一个 bbcode 时,我的代码有效。但在 bbcode 较多或与文本混合时不起作用。

所以我想获得一些帮助来解决这部分问题,以使一切正常。

includes/bbcode.php这个函数的第98行:

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

返回的是这样的:

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

对于这条消息:

一些文本 [glow=red]abc[/glow] 另一个文本。

[mod="fernando"]你好![/mod] 更多文字

上面 preg_replace 的输入只是为了上下文:

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

所以基本上我必须将此字符串拆分为有效的表达式以应用 eval() 然后连接所有内容。像这样:

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

在这种特定情况下,'"fernando"' 中还留有双引号。

我知道将 eval() 应用于用户输入是不安全的,所以我想制作某种类型的 preg_match 和/或 preg_split获取 () 内的值作为参数传递给我的函数。

功能基本是:

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

我在想这样的事情(请忽略这里的错误):

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.:由于使用了 e 修饰符,ABBC3 与 PHP 7.3 不兼容。我已经编辑了所有内容以删除修饰符。

在这里你可以看到它单独工作:

bbcode 1

bbcode 2

有人可以帮帮我吗?

【问题讨论】:

    标签: php phpbb


    【解决方案1】:

    在为这个问题寻找解决方案很长时间后,我发现了这个site,它帮助我构建了正则表达式。

    现在我已经设法解决了这个问题,并且我的论坛完全使用 PHPBB 3.14、PHP 7.3 和 ABBC3。

    我的解决办法是:

    // 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
    

    如果有人有兴趣可以找到补丁文件和说明here

    最好的问候。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多