本文由 FlintHub 开发文档归档发布。原始文档日期见标题前缀,来源:暂存20260913/docs/二级目录改造计划.md。
SoSite 二级目录支持改造计划
核心思路
增加 BASE_PATH 概念,所有 URL 生成都通过它拼接。
| 部署方式 | `BASE_PATH` | 效果 |
|---|
根目录 http://localhost/ | ''(空) | 所有 URL 不变,和现在一样 |
二级目录 http://localhost/sosite/ | /sosite | 路由自动拼接,URL 自动加前缀 |
任意多级 http://localhost/a/b/c/ | /a/b/c | 同样支持 |
改完后只改一个配置值,BASE_PATH 设成什么就适配什么目录深度。
第一阶段:核心基础设施(5 个文件)
| 顺序 | 文件 | 改动内容 |
|---|
| 1 | config.php | 新增 define('BASE_PATH', ''); 常量 |
| 2 | app/Core/Router.php | dispatch() 时从 REQUEST_URI 剥离 BASE_PATH 再匹配路由 |
| 3 | app/Core/Controller.php | redirect() 的 URL 自动拼接 BASE_PATH |
| 4 | app/Core/TemplateCompiler.php | asset() 返回的路径自动拼接 BASE_PATH;新增 url() 方法供视图调用 |
| 5 | app/init.php | 从 settings 表读取 base_path 覆盖常量(支持后台配置) |
第二阶段:后台设置项(2 个文件)
| 顺序 | 文件 | 改动内容 |
|---|
| 6 | app/Controllers/Admin/SettingsController.php | basic() 方法保存 base_path 字段 |
| 7 | app/Views/admin/settings_basic.php | 加一个"站点部署路径"输入框 |
第三阶段:默认主题视图(逐个文件替换硬编码链接)
所有 href="/xxx"、action="/xxx"、src="/assets/..." 改为 $this->url('/xxx') 或 $this->asset('...')。
| 顺序 | 文件 |
|---|
| 8 | app/Views/layouts/main.php |
| 9 | app/Views/admin/_sidebar.php |
| 10 | app/Views/home/index.php |
| 11 | app/Views/forum/index.php |
| 12 | app/Views/forum/category.php |
| 13 | app/Views/thread/show.php |
| 14 | app/Views/thread/edit.php |
| 15 | app/Views/post/create.php |
| 16 | app/Views/post/edit.php |
| 17 | app/Views/auth/login.php |
| 18 | app/Views/auth/register.php |
| 19 | app/Views/auth/forgot_password.php |
| 20 | app/Views/auth/reset_password.php |
| 21 | app/Views/auth/message.php |
| 22 | app/Views/blog/index.php |
| 23 | app/Views/blog/detail.php |
| 24 | app/Views/blog/edit.php |
| 25 | app/Views/search/index.php |
| 26 | app/Views/profile/index.php |
| 27 | app/Views/message/compose.php |
| 28 | app/Views/message/inbox.php |
| 29 | app/Views/message/sent.php |
| 30 | app/Views/message/view.php |
| 31 | app/Views/tags/index.php |
| 32 | app/Views/tags/show.php |
| 33 | app/Views/theme/settings.php |
| 34 | app/Views/invite/index.php |
| 35 | app/Views/admin/index.php |
| 36 | app/Views/admin/settings_basic.php |
| 37 | app/Views/admin/settings_display.php |
| 38 | app/Views/admin/mail_settings.php |
| 39 | app/Views/admin/search_settings.php |
| 40 | app/Views/admin/categories.php |
| 41 | app/Views/admin/permissions.php |
| 42 | app/Views/admin/threads.php |
| 43 | app/Views/admin/thread_edit.php |
| 44 | app/Views/admin/tags.php |
| 45 | app/Views/admin/trashed.php |
| 46 | app/Views/admin/users.php |
| 47 | app/Views/admin/user_edit.php |
| 48 | app/Views/admin/groups.php |
| 49 | app/Views/admin/levels.php |
| 50 | app/Views/admin/database.php |
| 51 | app/Views/admin/maintenance.php |
| 52 | app/Views/admin/themes.php |
| 53 | app/Views/admin/plugins.php |
| 54 | app/Views/admin/plugin-edit.php |
| 55 | app/Views/admin/blog_categories.php |
| 56 | app/Views/admin/blog_manage.php |
| 57 | app/Views/admin/verify.php |
第四阶段:Morden 主题视图(逐个文件)
| 顺序 | 文件 |
|---|
| 58 | assets/themes/morden/templates/layouts/main.php |
| 59 | assets/themes/morden/templates/home/index.php |
| 60 | assets/themes/morden/templates/forum/index.php |
| 61 | assets/themes/morden/templates/forum/category.php |
| 62 | assets/themes/morden/templates/thread/show.php |
| 63 | assets/themes/morden/templates/thread/edit.php |
| 64 | assets/themes/morden/templates/post/create.php |
| 65 | assets/themes/morden/templates/post/edit.php |
| 66 | assets/themes/morden/templates/auth/login.php |
| 67 | assets/themes/morden/templates/auth/register.php |
| 68 | assets/themes/morden/templates/auth/forgot_password.php |
| 69 | assets/themes/morden/templates/auth/reset_password.php |
| 70 | assets/themes/morden/templates/blog/index.php |
| 71 | assets/themes/morden/templates/blog/detail.php |
| 72 | assets/themes/morden/templates/blog/edit.php |
| 73 | assets/themes/morden/templates/search/index.php |
| 74 | assets/themes/morden/templates/profile/index.php |
| 75 | assets/themes/morden/templates/message/compose.php |
| 76 | assets/themes/morden/templates/message/inbox.php |
| 77 | assets/themes/morden/templates/message/sent.php |
| 78 | assets/themes/morden/templates/message/view.php |
| 79 | assets/themes/morden/templates/tags/index.php |
| 80 | assets/themes/morden/templates/tags/show.php |
| 81 | assets/themes/morden/templates/theme/settings.php |
| 82 | assets/themes/morden/templates/invite/index.php |
| 83 | assets/themes/morden/templates/_components/left_sidebar.php |
| 84 | assets/themes/morden/templates/_components/right_sidebar.php |
第五阶段:JavaScript 文件(2 个文件)
| 顺序 | 文件 | 改动内容 |
|---|
| 85 | assets/js/editor.js | 硬编码的 /assets/img/emoji/ 和 /assets/js/ 改为读取 window.BASE_PATH |
| 86 | assets/js/vote.js | 检查是否有硬编码 URL |
第六阶段:插件(每个插件逐个改)
| 顺序 | 插件 | 涉及文件 |
|---|
| 87 | announcements | 钩子文件、视图 |
| 88 | content_review | 钩子文件、视图 |
| 89 | daily_checkin | 钩子文件、视图 |
| 90 | dev_docs | 钩子文件、视图 |
| 91 | edit_info | 钩子文件 |
| 92 | friend_links | 钩子文件、视图 |
| 93 | invite | 钩子文件、视图 |
| 94 | post_favorite | 钩子文件、视图 |
| 95 | qa | 钩子文件、视图 |
| 96 | red_packet | 钩子文件、视图 |
| 97 | seo | 钩子文件、视图 |
| 98 | user_profile | 钩子文件、视图 |
第七阶段:测试
| 顺序 | 测试内容 |
|---|
| 99 | BASE_PATH = '' 根目录下全功能测试 |
| 100 | 设置 BASE_PATH = '/sosite',二级目录下全功能测试 |
总计:约 100 步,每步改一个文件。