[开发]插件修复报告

👑Lv.11 元老 🌞 骨干会员
2026-10-25 00:48:01

本文由 FlintHub 开发文档归档发布。原始文档日期见标题前缀,来源:暂存20260913/docs/插件修复报告.md。

插件修复报告

修复日期:2026-07-16

基于 plugins_审计报告.md 的审计结果,逐一修复


修复清单

✅ 1. 删除残留备份文件(6 个)

文件操作
plugins/content_review/hook/admin_sidebar_links.php.bak删除
plugins/content_review/hook/auth_register_after.php.bak删除
plugins/content_review/hook/controller_view_before.php.bak删除
plugins/content_review/hook/nav_user_menu_items.php.bak删除
plugins/invite/hook/init_after.php.revert删除
plugins/announcements/hook/init_after.php.revert删除


✅ 2. 修复 dev_docs 命名空间大小写 bug

文件:plugins/dev_docs/AdminController.php

问题:reset() 方法中调用 \Plugin\dev_docs\Plugin::activate(),但实际命名空间是 \Plugin\DevDocs\Plugin(首字母大写),调用会报错。

修复:将 \Plugin\dev_docs\Plugin 改为 \Plugin\DevDocs\Plugin。


✅ 3. 修复 seo 自定义头代码转义问题

文件:plugins/seo/hook/layout_head_end.php

问题:$seoCustomHead 经过 htmlspecialchars() 输出,<> 被转义,导致管理员无法添加统计脚本等自定义 HTML 代码。

修复:改为 \app\Helpers\Content::decode($seoCustomHead) 输出,保留 HTML 标签。


✅ 4. 修复 announcements 资源路径 BASE_PATH

文件:plugins/announcements/hook/announcements_display.php

问题:CSS 资源路径硬编码 /plugins/announcements/assets/style.css,二级目录部署时 404。

修复:改为 <?php echo \defined('BASE_PATH') ? BASE_PATH : ''; ?>/plugins/announcements/assets/style.css。


✅ 5. 修复 post_favorite 资源路径 BASE_PATH

文件:plugins/post_favorite/hook/layout_head_end.php

问题:CSS/JS 资源路径硬编码 /plugins/post_favorite/assets/...,二级目录部署时 404。

修复:定义 $bp 变量拼接 BASE_PATH 前缀。


✅ 6. 修复 friend_links BASE_PATH 和 emoji 图标

文件:plugins/friend_links/hook/home_sidebar_bottom.php

问题:

  • 标题使用 emoji 🔗 而非 FA 图标
  • 申请友链链接硬编码 /links/apply

修复:

  • emoji 替换为 <i class="fa" style="font-size:14px">&#xf0c1;</i>(link 图标)
  • 链接改为 <?php echo \defined('BASE_PATH') ? BASE_PATH : ''; ?>/links/apply

✅ 7. 修复 invite BASE_PATH 和 layout_head_end

文件:plugins/invite/hook/layout_head_end.php

问题:preg_match('#^/register#', ...) 未考虑 BASE_PATH,二级目录部署时匹配失败。

修复:改用 strpos($_SERVER['REQUEST_URI'], $bp . '/register') !== false,$bp 为 BASE_PATH 值。


✅ 8. 修复 daily_checkin 登录检查方式

文件:plugins/daily_checkin/CheckinController.php

问题:index() 和 doCheckin() 方法中使用了 header('Location: /login'); exit; 而非框架的 $this->requireLogin()。

修复:替换为 $this->requireLogin(),该方法自动处理 BASE_PATH 和重定向。


✅ 9. 修复 red_packet 建表逻辑

涉及文件:

  • plugins/red_packet/plugin.json(添加 init_after 钩子)
  • plugins/red_packet/hook/init_after.php(新建,使用缓存文件)
  • plugins/red_packet/RedPacketController.php(移除 ensureTables() 方法及 4 处调用)

问题:建表逻辑在控制器中,每次请求都尝试检测表是否存在,未使用缓存文件。

修复:

  • 添加 init_after 钩子,使用缓存文件 .red_packet_table_cache 记录表已创建
  • 移除控制器中冗余的 ensureTables() 方法

✅ 10. 修复 edit_info SQLite 兼容问题

文件:

  • plugins/edit_info/hook/post_edit_after.php
  • plugins/edit_info/hook/thread_edit_after.php

问题:建表 SQL 硬编码 ENGINE=InnoDB DEFAULT CHARSET=utf8mb4,SQLite 不兼容。

修复:改用 $db->query() 执行建表语句,由 Database 类自动适配数据库类型。


✅ 11. 修复 user_profile 404 处理方式

文件:plugins/user_profile/FrontController.php

问题:用户不存在时直接 echo '<h1>404...</h1>'; exit;,未使用框架错误页。

修复:改为 $this->view('errors/404', ['message' => '用户不存在']);,使用框架统一错误页。


未修复的审计项目

以下问题属于优化建议,未修改(风险/收益考量):

项目原因
冗余 require_once 引入控制器不影响功能,删除后需测试自动加载器兼容性
钩子文件中内联 CSS/JS分离后可能破坏样式,需上线前充分测试
edit_info 的 init_after.php 为空可接受,激活时已建表,编辑钩子有兜底建表逻辑
Plugins.php 中 insertDefaultData() 过于庞大属数据结构迁移,非逻辑问题


验证结果

所有修改过的 PHP 文件均通过 php -l 语法检查,无错误。

部署注意事项

  1. 服务器部署前需删除 plugins/plugins_cache.php,强制重建插件缓存(red_packet 新增了 init_after 钩子)
  2. 如果服务器使用 SQLite,edit_info 的建表现在能正常工作了
轻量级、高性能、零 MySQL 依赖的PHP社区系统。
| 浏览 1 次 | 回复 0 次

全部回复 (0)

暂无回复

请 登录