ud3 发表于 2026-3-21 13:51

discuz从3.5升级到x5后插件【首页版块主题显示v4.4.1 免费版】报错

discuz从3.5升级到x5后因为在全部应用里启用【记录】,点击首页会报错,错误信息如下
是插件【首页版块主题显示v4.4.1 免费版】原因造成的

Discuz! System Error
Time: 2026-03-21 13:35:04 +0800 IP: 223.8.8.8 BackTraceID: f4917887e7d44e5366de571899862f8b

extract(): Argument #1 ($array) must be of type array, bool given
PHP Debug

No.      File      Code
1      forum.php:11      require(%s)
2      index.php:27      require(%s)
3      source/app/forum/forum.php:72      require_once(%s)
4      source/app/forum/module/index.php:63      include(%s)
5      data/template/3_diy_forum_discuz.tpl.php:1      hookscriptoutput()
6      source/function/function_core.php:1656      hookscript()
7      source/function/function_core.php:1612      plugin_nimba_forumdev_forum->index_forum_extra_output()
8      source/plugin/nimba_forumdev/hook.class.php:204      plugin_nimba_forumdev->devGetThreadsMem()
9      source/plugin/nimba_forumdev/hook.class.php:110      extract()
10      source/plugin/nimba_forumdev/hook.class.php:110      break()
System Info

Version      X5.0.0.Open Release 20260320
OS      Linux / Linux VM-4-12-centos 3.10.0-1160.66.1.el7.x86_64 #1 SMP Wed May 18 16:02:34 UTC 2022 x86_64
PHP      8.2.28 fpm-fcgi on nginx/1.20.2
MySQL      5.7.44-log错误核心解读

从错误堆栈可以定位到问题出在:
source/plugin/nimba_forumdev/hook.class.php 文件的 第 110 行,这里调用了 extract() 函数,但传入的参数不是数组。

下面是修复后的文件,
将修复后的代码覆盖原文件 source/plugin/nimba_forumdev/hook.class.php。
登录 Discuz 后台,清理缓存(后台 → 工具 → 缓存清理)。

<?php
/**
*      This is NOT a freeware, use is subject to license terms
*      应用名称: 首页版块主题显示 v4.0.1 免费版
*      下载地址: https://addon.dismall.com/plugins/nimba_forumdev.html
*      应用开发者: 人工智能实验室
*      开发者QQ: 281688302
*      更新日期: 202304241245
*      授权域名: ud3.cn
*      授权码: 2023042403CE6jnz60H0
*      未经应用程序开发者/所有者的书面许可,不得进行反向工程、反向汇编、反向编译等,不得擅自复制、修改、链接、转载、汇编、发表、出版、发展与之有关的衍生产品、作品等
*/

/*
* 主页:https://addon.dismall.com/?@1552.developer
* 人工智能实验室:Discuz!应用中心十大优秀开发者!
* 插件定制 联系QQ281688302
* From ailab.cn
*/

if(!defined('IN_DISCUZ')) {
      exit('Access Denied');
}

class plugin_nimba_forumdev {
      function __construct(){
                global $_G;      
                loadcache('plugin');
                $vars = $_G['cache']['plugin']['nimba_forumdev'];
                $this->margin=intval($vars['margin']);
                if($this->margin==0){
                        $this->margin='';
                }else{
                        $this->margin='margin-left:'.$this->margin.'px;';
                }
                $this->listwidth=intval($vars['listwidth']);
                $this->forums=unserialize($vars['forums']);
                $this->num=intval($vars['num']);
                $this->order=intval($vars['order']);
                $this->style=intval($vars['style']);
                $this->tuicache=intval($vars['tuicache']);
                $this->highlight=0;
                $this->alltid=array();//free
                $this->tid_by_fid=array();//free
                $this->userpage=trim($vars['userpage']);
      }
      function userpage($uid){
                if($this->userpage) return $userpage=str_replace('{uid}',$uid,$this->userpage);
                return '';
      }
      
      function devGetTuisMem($fid){
                if(!$this->tuis) return '';
                if(!$this->tid_by_fid[$fid]) return '';
                $cache=memory('get','nimba_forumdev_tui');
               
                // 修复1:增加数组判断,避免extract传入非数组
                if (is_array($cache)) {
                        extract($cache);
                } else {
                        // 初始化默认值,防止未定义变量报错
                        $dateline = 0;
                        $hash = '';
                        $threadlist = array();
                }
               
                $newhash=md5($this->tuis);
                // 修复2:修正笔误 $newhash!=$hash(原代码是$newhash!=$newhash)
                if($newhash!=$hash||TIMESTAMP-$dateline>=$this->tuicache){//推送有跳转或者缓存到期
                        $threadlist=C::t('forum_thread')->fetch_all_by_tid($this->alltid);
                        if($threadlist){
                              $cache=array(
                                        'threadlist'=>$threadlist,
                                        'dateline'=>TIMESTAMP,
                                        'hash'=>$newhash,
                              );
                              memory('set','nimba_forumdev_tui',$cache);
                        }
                }
                $res=array();
                if($threadlist){
                        foreach($threadlist as $k=>$thread){
                              if($thread['fid']==$fid&&in_array($thread['tid'],$this->tid_by_fid[$fid])) $res[]=$thread;
                        }
                }
                return $res;
      }
      
      function devGetTuis($fid){
                if(!$this->tuis) return '';
                if(!$this->tid_by_fid[$fid]) return '';
                $filepath=DISCUZ_ROOT.'./data/sysdata/cache_nimba_forumdev_tui.php';
                $dateline=0;
                $hash='';
                if(file_exists($filepath)){
                        @include $filepath;      
                }
                $newhash=md5($this->tuis);
                // 修复3:修正笔误 $newhash!=$hash(原代码是$newhash!=$newhash)
                if($newhash!=$hash||TIMESTAMP-$dateline>=$this->tuicache){//推送有跳转或者缓存到期
                        $threadlist=C::t('forum_thread')->fetch_all_by_tid($this->alltid);
                        if($threadlist){
                              @require_once libfile('function/cache');
                              $cacheArray = "\$threadlist=".arrayeval($threadlist).";\n";
                              $cacheArray .= "\$dateline=".TIMESTAMP.";\n";
                              $cacheArray .= "\$hash='".$newhash."';\n";
                              writetocache('nimba_forumdev_tui',$cacheArray);      
                        }
                }
                $res=array();
                if($threadlist){
                        foreach($threadlist as $k=>$thread){
                              if($thread['fid']==$fid&&in_array($thread['tid'],$this->tid_by_fid[$fid])) $res[]=$thread;
                        }
                }
                return $res;
      }
      
      function devGetThreadsMem($fid,$threads,$posts){//按fid调取最新帖子
                $cache=memory('get','nimba_forumdev_'.$fid);
               
                // 修复4:核心错误修复 - extract前必须判断数组类型
                if (is_array($cache)) {
                        extract($cache);
                } else {
                        // 初始化默认值,防止未定义变量报错
                        $threadlist = array();
                        $old_threads = 0;
                        $old_posts = 0;
                        $old_num = 0;
                        $old_order = 0;
                }
               
                if($threadlist&&$old_threads==$threads&&$old_posts==$posts&&$old_num==$this->num&&$old_order==$this->order){//缓存存在 且主题回复数一致、配置数据一致,直接返回数据
                        //echo 'old';
                        return $threadlist;
                }else{
                        //echo 'new';
                        if($this->order==2){
                              $order='lastpost';
                        }else{
                              $order='dateline';
                        }
                        $threadlist=DB::fetch_all("SELECT * FROM ".DB::table('forum_thread')." WHERE fid=%d AND displayorder>=0 ORDER BY `$order` DESC LIMIT ".$this->num,array($fid),'tid');
                        if($threadlist){
                              $cache['threadlist']=$threadlist;
                              $cache['old_threads']=intval($threads);
                              $cache['old_posts']=intval($posts);
                              $cache['old_num']=intval($this->num);
                              $cache['old_order']=intval($this->order);
                              $cache['lasttime']=TIMESTAMP;
                              memory('set','nimba_forumdev_'.$fid,$cache);
                        }
                        return $threadlist;
                }      
      }
      function devGetThreads($fid,$threads,$posts){//按fid调取最新帖子
                $filepath=DISCUZ_ROOT.'./data/sysdata/cache_nimba_forumdev_'.$fid.'.php';
                $dateline=time();
                if(file_exists($filepath)){
                        @include $filepath;      
                }
                if($threadlist&&$old_threads==$threads&&$old_posts==$posts&&$old_num==$this->num&&$old_order==$this->order){//缓存存在 且主题回复数一致、配置数据一致,直接返回数据
                        return $threadlist;
                }else{
                        if($this->order==2){
                              $order='lastpost';
                        }else{
                              $order='dateline';
                        }
                        $threadlist=DB::fetch_all("SELECT * FROM ".DB::table('forum_thread')." WHERE fid=%d AND displayorder>=0 ORDER BY `$order` DESC LIMIT ".$this->num,array($fid),'tid');
                        if($threadlist){
                              @require_once libfile('function/cache');
                              $cacheArray = "\$threadlist=".arrayeval($threadlist).";\n";
                              $cacheArray .= "\$old_threads=".intval($threads).";\n";
                              $cacheArray .= "\$old_posts=".intval($posts).";\n";
                              $cacheArray .= "\$old_num=".intval($this->num).";\n";
                              $cacheArray .= "\$old_order=".intval($this->order).";\n";
                              writetocache('nimba_forumdev_'.$fid,$cacheArray);      
                        }
                        return $threadlist;
                }
      }
      
      function global_header(){//引入css
                if(CURSCRIPT=='forum'&&CURMODULE=='index'){
                        return '
<style>               
.forumdev {width:100%;margin-top:10px;'.$this->margin.'background: url(\'source/plugin/nimba_forumdev/listnum.gif\') no-repeat;/*font-size: 14px;*/}
.forumdev ul {padding:0 2px 0 22px;list-style-type:none;line-height: 25px; }
.forumdev ul li{height:25px;line-height:25px;width:'.$this->listwidth.'%;overflow:hidden;background:url(\'source/plugin/nimba_forumdev/dotline.gif\');}
.forumdev ul li span{float:right;margin: 0 0 0 5px}
</style>';
                }
                return '';
      }
}
class plugin_nimba_forumdev_forum extends plugin_nimba_forumdev {
      function devGetHighlight($highlight){//解析高亮
                global $_G;
                return '';//未开启高亮 free
      }
      
      function index_forum_extra_output(){//对开启的版块逐个处理
                global $_G,$forumlist,$catlist;
                $html=array();
                loadcache('plugin');
                foreach($forumlist as $fid=>$forum){
                        if(in_array($fid,$this->forums)){//关闭版块
                              $html[$fid]='';
                              continue;
                        }
                        if($forum['threads']==0||$forum['posts']==0){//版块没有内容
                              $html[$fid]='';
                              continue;
                        }
                        if(!isset($_GET['gid'])&&$catlist[$forum['fup']]['forumcolumns']<2){//论坛首页 横排检查
                              $html[$fid]='';
                              continue;
                        }
                        if(isset($_GET['gid'])&&$catlist[$forum['fup']]['catforumcolumns']<2){//分区页面 横排检查
                              $html[$fid]='';
                              continue;
                        }
                        if(C::memory()->enable&&C::memory()->type!='File'){
                              $thread_tui=$this->devGetTuisMem($fid);
                              $threads=$this->devGetThreadsMem($fid,$forum['threads'],$forum['posts']);
                        }else{      
                              $thread_tui=$this->devGetTuis($fid);
                              $threads=$this->devGetThreads($fid,$forum['threads'],$forum['posts']);
                        }
                        if($thread_tui){
                              $threads=array_merge($thread_tui,$threads);
                              $threads=array_slice($threads,0,$this->num);
                        }
                        include template('nimba_forumdev:list');
                        $html[$fid]=$list;
                }
                return $html;
      }
      
      function forumdisplay_subforum_extra_output(){//子版块设置
                global $_G,$sublist;
                $html=array();
                if($_G['forum']['forumcolumns']>=2){
                        foreach($sublist as $_k=>$forum){
                              $fid=$forum['fid'];
                              if(in_array($fid,$this->forums)){//关闭版块
                                        $html[$fid]='';
                                        continue;
                              }
                              if($forum['threads']==0||$forum['posts']==0){//版块没有内容
                                        $html[$fid]='';
                                        continue;
                              }
                              if(C::memory()->enable&&C::memory()->type!='File'){
                                        $thread_tui=$this->devGetTuisMem($fid);
                                        $threads=$this->devGetThreadsMem($fid,$forum['threads'],$forum['posts']);
                              }else{      
                                        $thread_tui=$this->devGetTuis($fid);
                                        $threads=$this->devGetThreads($fid,$forum['threads'],$forum['posts']);
                              }
                              if($thread_tui){
                                        $threads=array_merge($thread_tui,$threads);
                                        $threads=array_slice($threads,0,$this->num);
                              }
                              include template('nimba_forumdev:list');
                              $html[$fid]=$list;                              
                        }      
                }
                //var_dump($html);
                return $html;
      }
}


页: [1]
查看完整版本: discuz从3.5升级到x5后插件【首页版块主题显示v4.4.1 免费版】报错