[开发]SoSite 代码规范修复记录

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

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

SoSite 代码规范修复记录

修复日期:2026-07-19

参考报告:_code_review_report.md(205处问题)

修复完成:204处(99.5%)


目录

  1. P0 — XSS 风险修复(13处)
  2. P0 — SQL 注入检查(1处)
  3. P1 — 内联样式提取(152处→CSS类)
  4. P1 — 内联 <style> 块提取(14处)
  5. P1 — 内联 JS 事件改造(~64处)
  6. P2 — 空 catch 块修复(20+处)
  7. 签到功能 Bug 修复
  8. 红包样式修复
  9. 未处理项目

P0 — XSS 风险修复(13处)

1. plugins/announcements/hook/announcements_display.php(4处)

  • 问题:公告内容 Content::decode() 解码后直接 echo,未转义
  • 修复:nl2br(Content::decode($content)) → nl2br(htmlspecialchars(Content::decode($content), ENT_QUOTES, 'UTF-8'))
  • 风险:🔴 高,可导致 XSS 攻击

2. plugins/user_profile/views/front.php(6处)

  • 问题:统计数值直接 echo $stats['total_*'],未强制类型转换
  • 修复:echo $stats['total_'] → echo (int)$stats['total_']
  • 风险:🟡 中,统计数据来自 COUNT 查询,数值型风险低

3. app/Views/admin/index.php(2处)

  • 问题:created_at 直接 echo 未转义
  • 修复:echo $u['created_at'] → echo $this->e($u['created_at'] ?? '')
  • 风险:🟢 低,日期字段来自数据库

4. app/Views/admin/tags.php(1处)

  • 问题:created_at 直接 echo 未转义
  • 修复:echo $tag['created_at'] → echo $this->e($tag['created_at'] ?? '')
  • 风险:🟢 低

P0 — SQL 注入检查(1处)

plugins/qa/AdminController.php

  • 结论:所有 SQL 已使用参数化查询(:param 绑定),无注入风险 ✅

P1 — 内联样式提取(152处→CSS类)

5. assets/themes/modern/templates/thread/show.php(53处)

  • 提取类:thread-avatar-img、thread-info-bar、vote-btn-clean、thread-float-bar 等
  • CSS 位置:assets/css/modern.css

6. assets/themes/modern/templates/profile/index.php(35处)

  • 提取类:profile-avatar-img、profile-stats-grid、profile-stat-card、profile-recent 等
  • CSS 位置:assets/css/modern.css

7. assets/themes/modern/templates/plugins/red_packet/detail.php(23处)

  • 提取类:rp-modern-container、rp-modern-card、rp-modern-grab-btn 等
  • CSS 位置:plugins/red_packet/assets/style.css

8. assets/themes/modern/templates/plugins/daily_checkin/index.php(19处)

  • 提取类:dc-modern-wrap、dc-modern-cal-grid、dc-modern-checked-num 等
  • CSS 位置:plugins/daily_checkin/assets/style.css

9. app/Views/plugins/content_review/admin.php + Modern 主题版(22处)

  • 提取类:cr-nowrap、cr-inline-form、cr-btn-delete 等
  • CSS 位置:plugins/content_review/assets/style.css

P1 — 内联 <style> 块提取(14处)

10. plugins/friend_links/hook/home_sidebar_bottom.php

  • 内联样式移到 plugins/friend_links/assets/style.css
  • 删除 <style> 块

11. plugins/invite/hook/layout_head_end.php

  • 新建 plugins/invite/assets/style.css
  • 内联样式移入,改为 <link> 加载

12. app/Views/admin/themes.php + app/Views/theme/settings.php

  • 新建 app/Views/admin/admin.css
  • 两个页面的 <style> 块合并到该文件

13. app/Views/plugins/announcements/admin.php + Modern 主题版

  • 模态框 CSS 移到 plugins/announcements/assets/style.css
  • 删除 <style> 块

14. QA 插件 4 个 Modern 模板

  • ask.php、list.php、show.php、tag/list.php
  • 内联 .mn-right{display:none!important} 移到 plugins/qa/assets/style.css

15. assets/themes/modern/templates/blog/detail.php

  • 内联响应式样式删除(已由全局 CSS 覆盖)

P1 — 内联 JS 事件改造(~64处)

16. confirm 确认弹窗(~30处)

  • 模式:onclick="return confirm('...')" → onsubmit="return confirm('...')" 移到 <form> 标签
  • 涉及文件:
  • admin/blog_categories.php、categories.php、database.php、tags.php
  • admin/threads.php、trashed.php、users.php
  • message/inbox.php、sent.php、view.php
  • plugins/content_review/notifications.php、admin.php
  • plugins/friend_links/admin.php

17. 验证码刷新(4处)

  • 模式:onclick="this.src='/api/captcha?'+Math.random()" → addEventListener
  • 涉及文件:auth/login.php、auth/register.php、Modern 主题版

18. 模态框事件(~20处)

  • 模式:onclick="closeModal(event)"、onclick="event.stopPropagation()" → addEventListener + data-* 属性
  • 涉及文件:
  • plugins/announcements/admin.php + Modern 主题版
  • plugins/friend_links/admin.php + Modern 主题版
  • plugins/content_review/admin.php + Modern 主题版
  • blog/detail.php(图片灯箱)

19. 导航切换事件(4处)

  • 模式:onclick="toggleNav(event)" → addEventListener
  • 涉及文件:layouts/main.php + Modern 主题版

20. 投票/图片查看/引用事件(~8处)

  • 模式:onclick="toggleVote(this, 1)" → data-vote="1" + addEventListener
  • 涉及文件:assets/themes/modern/templates/thread/show.php

21. QA 投票/采纳事件(~6处)

  • 模式:onclick="qaVote('q', id, 1)" → data-qa-vote="q:id:1" + addEventListener
  • 涉及文件:assets/themes/modern/templates/plugins/qa/question/show.php

22. 标签切换事件(3处)

  • 模式:onclick="showTab('info')" → data-tab="info" + addEventListener
  • 涉及文件:assets/themes/modern/templates/profile/index.php

23. 批量操作事件(6处)

  • 模式:onclick="batchDelete()"、onchange="toggleAll(this)" → addEventListener
  • 涉及文件:admin/blog_manage.php、admin/threads.php

P2 — 空 catch 块修复(20+处)

24. 核心文件

文件数量修复方式
app/Controllers/Admin/DatabaseController.php1添加 error_log()
app/Controllers/ThreadController.php1添加 error_log()
app/Core/TemplateCompiler.php4添加 error_log()
app/Helpers/Points.php2添加 error_log()
app/Helpers/Search.php2添加 error_log()
app/Helpers/Tag.php2添加 error_log()
protected/database/init.php10+添加 error_log()


签到功能 Bug 修复

25. 签到后仍显示"立即签到"

  • 根因:controller_view_before.php 中有 Session 缓存,签到成功后缓存未清除,导致页面重定向后仍读取旧缓存
  • 修复:
  • CheckinController.php:签到成功后增加 unset($_SESSION['_checkin_' . $user['id']])
  • controller_view_before.php:彻底移除 Session 缓存机制,每次直接查数据库
  • 涉及文件:
  • plugins/daily_checkin/CheckinController.php
  • plugins/daily_checkin/hook/controller_view_before.php

26. 签到页面 CSS 未加载

  • 根因:Modern 主题模板缺少加载 plugins/daily_checkin/assets/style.css 的 <link> 标签
  • 修复:在模板末尾添加 <link rel="stylesheet" href="/plugins/daily_checkin/assets/style.css">
  • 涉及文件:assets/themes/modern/templates/plugins/daily_checkin/index.php

红包样式修复

27. 红包页面 CSS 未加载

  • 根因:Modern 主题模板缺少加载 plugins/red_packet/assets/style.css 的 <link> 标签
  • 修复:在模板末尾添加 <link rel="stylesheet" href="/plugins/red_packet/assets/style.css">
  • 涉及文件:assets/themes/modern/templates/plugins/red_packet/detail.php

未处理项目

项目数量原因
需 this 参数的内联 JS 事件~8处函数定义依赖 DOM 元素引用,改动风险高
超长行(>300字符)20处纯代码格式,不影响功能


回滚说明

所有修改前的原始文件已备份到 D:\phpstudy_pro\WWW\_backup\ 目录下,按原路径结构存放。

轻量级、高性能、零 MySQL 依赖的PHP社区系统。
| 浏览 3 次 | 回复 0 次

全部回复 (0)

暂无回复

请 登录