查看: 16|回复: 0

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

[复制链接]

1231

主题

286

回帖

1231

积分

管理员

贡献
97504
金币
8912

马山东

发表于 2026-3-21 13:51 | 显示全部楼层 |阅读模式

马上注册,结交更多好友

您需要 登录 才可以下载或查看,没有账号?立即注册

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

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

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

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

  17. Version        X5.0.0.Open Release 20260320
  18. 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
  19. PHP        8.2.28 fpm-fcgi on nginx/1.20.2
  20. MySQL        5.7.44-log
复制代码
错误核心解读

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


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

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

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

  19. if(!defined('IN_DISCUZ')) {
  20.         exit('Access Denied');
  21. }

  22. class plugin_nimba_forumdev {
  23.         function __construct(){
  24.                 global $_G;        
  25.                 loadcache('plugin');
  26.                 $vars = $_G['cache']['plugin']['nimba_forumdev'];
  27.                 $this->margin=intval($vars['margin']);
  28.                 if($this->margin==0){
  29.                         $this->margin='';
  30.                 }else{
  31.                         $this->margin='margin-left:'.$this->margin.'px;';
  32.                 }
  33.                 $this->listwidth=intval($vars['listwidth']);
  34.                 $this->forums=unserialize($vars['forums']);
  35.                 $this->num=intval($vars['num']);
  36.                 $this->order=intval($vars['order']);
  37.                 $this->style=intval($vars['style']);
  38.                 $this->tuicache=intval($vars['tuicache']);
  39.                 $this->highlight=0;
  40.                 $this->alltid=array();//free
  41.                 $this->tid_by_fid=array();//free
  42.                 $this->userpage=trim($vars['userpage']);
  43.         }
  44.         function userpage($uid){
  45.                 if($this->userpage) return $userpage=str_replace('{uid}',$uid,$this->userpage);
  46.                 return '';
  47.         }
  48.         
  49.         function devGetTuisMem($fid){
  50.                 if(!$this->tuis) return '';
  51.                 if(!$this->tid_by_fid[$fid]) return '';
  52.                 $cache=memory('get','nimba_forumdev_tui');
  53.                
  54.                 // 修复1:增加数组判断,避免extract传入非数组
  55.                 if (is_array($cache)) {
  56.                         extract($cache);
  57.                 } else {
  58.                         // 初始化默认值,防止未定义变量报错
  59.                         $dateline = 0;
  60.                         $hash = '';
  61.                         $threadlist = array();
  62.                 }
  63.                
  64.                 $newhash=md5($this->tuis);
  65.                 // 修复2:修正笔误 $newhash!=$hash(原代码是$newhash!=$newhash)
  66.                 if($newhash!=$hash||TIMESTAMP-$dateline>=$this->tuicache){//推送有跳转或者缓存到期
  67.                         $threadlist=C::t('forum_thread')->fetch_all_by_tid($this->alltid);
  68.                         if($threadlist){
  69.                                 $cache=array(
  70.                                         'threadlist'=>$threadlist,
  71.                                         'dateline'=>TIMESTAMP,
  72.                                         'hash'=>$newhash,
  73.                                 );
  74.                                 memory('set','nimba_forumdev_tui',$cache);
  75.                         }
  76.                 }
  77.                 $res=array();
  78.                 if($threadlist){
  79.                         foreach($threadlist as $k=>$thread){
  80.                                 if($thread['fid']==$fid&&in_array($thread['tid'],$this->tid_by_fid[$fid])) $res[]=$thread;
  81.                         }
  82.                 }
  83.                 return $res;
  84.         }
  85.         
  86.         function devGetTuis($fid){
  87.                 if(!$this->tuis) return '';
  88.                 if(!$this->tid_by_fid[$fid]) return '';
  89.                 $filepath=DISCUZ_ROOT.'./data/sysdata/cache_nimba_forumdev_tui.php';
  90.                 $dateline=0;
  91.                 $hash='';
  92.                 if(file_exists($filepath)){
  93.                         @include $filepath;        
  94.                 }
  95.                 $newhash=md5($this->tuis);
  96.                 // 修复3:修正笔误 $newhash!=$hash(原代码是$newhash!=$newhash)
  97.                 if($newhash!=$hash||TIMESTAMP-$dateline>=$this->tuicache){//推送有跳转或者缓存到期
  98.                         $threadlist=C::t('forum_thread')->fetch_all_by_tid($this->alltid);
  99.                         if($threadlist){
  100.                                 @require_once libfile('function/cache');
  101.                                 $cacheArray = "\$threadlist=".arrayeval($threadlist).";\n";
  102.                                 $cacheArray .= "\$dateline=".TIMESTAMP.";\n";
  103.                                 $cacheArray .= "\$hash='".$newhash."';\n";
  104.                                 writetocache('nimba_forumdev_tui',$cacheArray);        
  105.                         }
  106.                 }
  107.                 $res=array();
  108.                 if($threadlist){
  109.                         foreach($threadlist as $k=>$thread){
  110.                                 if($thread['fid']==$fid&&in_array($thread['tid'],$this->tid_by_fid[$fid])) $res[]=$thread;
  111.                         }
  112.                 }
  113.                 return $res;
  114.         }
  115.         
  116.         function devGetThreadsMem($fid,$threads,$posts){//按fid调取最新帖子
  117.                 $cache=memory('get','nimba_forumdev_'.$fid);
  118.                
  119.                 // 修复4:核心错误修复 - extract前必须判断数组类型
  120.                 if (is_array($cache)) {
  121.                         extract($cache);
  122.                 } else {
  123.                         // 初始化默认值,防止未定义变量报错
  124.                         $threadlist = array();
  125.                         $old_threads = 0;
  126.                         $old_posts = 0;
  127.                         $old_num = 0;
  128.                         $old_order = 0;
  129.                 }
  130.                
  131.                 if($threadlist&&$old_threads==$threads&&$old_posts==$posts&&$old_num==$this->num&&$old_order==$this->order){//缓存存在 且主题回复数一致、配置数据一致,直接返回数据
  132.                         //echo 'old';
  133.                         return $threadlist;
  134.                 }else{
  135.                         //echo 'new';
  136.                         if($this->order==2){
  137.                                 $order='lastpost';
  138.                         }else{
  139.                                 $order='dateline';
  140.                         }
  141.                         $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');
  142.                         if($threadlist){
  143.                                 $cache['threadlist']=$threadlist;
  144.                                 $cache['old_threads']=intval($threads);
  145.                                 $cache['old_posts']=intval($posts);
  146.                                 $cache['old_num']=intval($this->num);
  147.                                 $cache['old_order']=intval($this->order);
  148.                                 $cache['lasttime']=TIMESTAMP;
  149.                                 memory('set','nimba_forumdev_'.$fid,$cache);
  150.                         }
  151.                         return $threadlist;
  152.                 }        
  153.         }
  154.         function devGetThreads($fid,$threads,$posts){//按fid调取最新帖子
  155.                 $filepath=DISCUZ_ROOT.'./data/sysdata/cache_nimba_forumdev_'.$fid.'.php';
  156.                 $dateline=time();
  157.                 if(file_exists($filepath)){
  158.                         @include $filepath;        
  159.                 }
  160.                 if($threadlist&&$old_threads==$threads&&$old_posts==$posts&&$old_num==$this->num&&$old_order==$this->order){//缓存存在 且主题回复数一致、配置数据一致,直接返回数据
  161.                         return $threadlist;
  162.                 }else{
  163.                         if($this->order==2){
  164.                                 $order='lastpost';
  165.                         }else{
  166.                                 $order='dateline';
  167.                         }
  168.                         $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');
  169.                         if($threadlist){
  170.                                 @require_once libfile('function/cache');
  171.                                 $cacheArray = "\$threadlist=".arrayeval($threadlist).";\n";
  172.                                 $cacheArray .= "\$old_threads=".intval($threads).";\n";
  173.                                 $cacheArray .= "\$old_posts=".intval($posts).";\n";
  174.                                 $cacheArray .= "\$old_num=".intval($this->num).";\n";
  175.                                 $cacheArray .= "\$old_order=".intval($this->order).";\n";
  176.                                 writetocache('nimba_forumdev_'.$fid,$cacheArray);        
  177.                         }
  178.                         return $threadlist;
  179.                 }
  180.         }
  181.         
  182.         function global_header(){//引入css
  183.                 if(CURSCRIPT=='forum'&&CURMODULE=='index'){
  184.                         return '
  185. <style>               
  186. .forumdev {width:100%;margin-top:10px;'.$this->margin.'background: url(\'source/plugin/nimba_forumdev/listnum.gif\') no-repeat;/*font-size: 14px;*/}
  187. .forumdev ul {padding:0 2px 0 22px;list-style-type:none;line-height: 25px; }
  188. .forumdev ul li{height:25px;line-height:25px;width:'.$this->listwidth.'%;overflow:hidden;background:url(\'source/plugin/nimba_forumdev/dotline.gif\');}
  189. .forumdev ul li span{float:right;margin: 0 0 0 5px}
  190. </style>';
  191.                 }
  192.                 return '';
  193.         }
  194. }
  195. class plugin_nimba_forumdev_forum extends plugin_nimba_forumdev {
  196.         function devGetHighlight($highlight){//解析高亮
  197.                 global $_G;
  198.                 return '';//未开启高亮 free
  199.         }
  200.         
  201.         function index_forum_extra_output(){//对开启的版块逐个处理
  202.                 global $_G,$forumlist,$catlist;
  203.                 $html=array();
  204.                 loadcache('plugin');
  205.                 foreach($forumlist as $fid=>$forum){
  206.                         if(in_array($fid,$this->forums)){//关闭版块
  207.                                 $html[$fid]='';
  208.                                 continue;
  209.                         }
  210.                         if($forum['threads']==0||$forum['posts']==0){//版块没有内容
  211.                                 $html[$fid]='';
  212.                                 continue;
  213.                         }
  214.                         if(!isset($_GET['gid'])&&$catlist[$forum['fup']]['forumcolumns']<2){//论坛首页 横排检查
  215.                                 $html[$fid]='';
  216.                                 continue;
  217.                         }
  218.                         if(isset($_GET['gid'])&&$catlist[$forum['fup']]['catforumcolumns']<2){//分区页面 横排检查
  219.                                 $html[$fid]='';
  220.                                 continue;
  221.                         }
  222.                         if(C::memory()->enable&&C::memory()->type!='File'){
  223.                                 $thread_tui=$this->devGetTuisMem($fid);
  224.                                 $threads=$this->devGetThreadsMem($fid,$forum['threads'],$forum['posts']);
  225.                         }else{        
  226.                                 $thread_tui=$this->devGetTuis($fid);
  227.                                 $threads=$this->devGetThreads($fid,$forum['threads'],$forum['posts']);
  228.                         }
  229.                         if($thread_tui){
  230.                                 $threads=array_merge($thread_tui,$threads);
  231.                                 $threads=array_slice($threads,0,$this->num);
  232.                         }
  233.                         include template('nimba_forumdev:list');
  234.                         $html[$fid]=$list;
  235.                 }
  236.                 return $html;
  237.         }
  238.         
  239.         function forumdisplay_subforum_extra_output(){//子版块设置
  240.                 global $_G,$sublist;
  241.                 $html=array();
  242.                 if($_G['forum']['forumcolumns']>=2){
  243.                         foreach($sublist as $_k=>$forum){
  244.                                 $fid=$forum['fid'];
  245.                                 if(in_array($fid,$this->forums)){//关闭版块
  246.                                         $html[$fid]='';
  247.                                         continue;
  248.                                 }
  249.                                 if($forum['threads']==0||$forum['posts']==0){//版块没有内容
  250.                                         $html[$fid]='';
  251.                                         continue;
  252.                                 }
  253.                                 if(C::memory()->enable&&C::memory()->type!='File'){
  254.                                         $thread_tui=$this->devGetTuisMem($fid);
  255.                                         $threads=$this->devGetThreadsMem($fid,$forum['threads'],$forum['posts']);
  256.                                 }else{        
  257.                                         $thread_tui=$this->devGetTuis($fid);
  258.                                         $threads=$this->devGetThreads($fid,$forum['threads'],$forum['posts']);
  259.                                 }
  260.                                 if($thread_tui){
  261.                                         $threads=array_merge($thread_tui,$threads);
  262.                                         $threads=array_slice($threads,0,$this->num);
  263.                                 }
  264.                                 include template('nimba_forumdev:list');
  265.                                 $html[$fid]=$list;                                
  266.                         }        
  267.                 }
  268.                 //var_dump($html);
  269.                 return $html;
  270.         }
  271. }
复制代码



您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

在本版发帖
返回顶部