[开发]SoSite 二级目录支持改造计划

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

本文由 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 个文件)

顺序文件改动内容
1config.php新增 define('BASE_PATH', ''); 常量
2app/Core/Router.phpdispatch() 时从 REQUEST_URI 剥离 BASE_PATH 再匹配路由
3app/Core/Controller.phpredirect() 的 URL 自动拼接 BASE_PATH
4app/Core/TemplateCompiler.phpasset() 返回的路径自动拼接 BASE_PATH;新增 url() 方法供视图调用
5app/init.php从 settings 表读取 base_path 覆盖常量(支持后台配置)


第二阶段:后台设置项(2 个文件)

顺序文件改动内容
6app/Controllers/Admin/SettingsController.phpbasic() 方法保存 base_path 字段
7app/Views/admin/settings_basic.php加一个"站点部署路径"输入框


第三阶段:默认主题视图(逐个文件替换硬编码链接)

所有 href="/xxx"、action="/xxx"、src="/assets/..." 改为 $this->url('/xxx') 或 $this->asset('...')。

顺序文件
8app/Views/layouts/main.php
9app/Views/admin/_sidebar.php
10app/Views/home/index.php
11app/Views/forum/index.php
12app/Views/forum/category.php
13app/Views/thread/show.php
14app/Views/thread/edit.php
15app/Views/post/create.php
16app/Views/post/edit.php
17app/Views/auth/login.php
18app/Views/auth/register.php
19app/Views/auth/forgot_password.php
20app/Views/auth/reset_password.php
21app/Views/auth/message.php
22app/Views/blog/index.php
23app/Views/blog/detail.php
24app/Views/blog/edit.php
25app/Views/search/index.php
26app/Views/profile/index.php
27app/Views/message/compose.php
28app/Views/message/inbox.php
29app/Views/message/sent.php
30app/Views/message/view.php
31app/Views/tags/index.php
32app/Views/tags/show.php
33app/Views/theme/settings.php
34app/Views/invite/index.php
35app/Views/admin/index.php
36app/Views/admin/settings_basic.php
37app/Views/admin/settings_display.php
38app/Views/admin/mail_settings.php
39app/Views/admin/search_settings.php
40app/Views/admin/categories.php
41app/Views/admin/permissions.php
42app/Views/admin/threads.php
43app/Views/admin/thread_edit.php
44app/Views/admin/tags.php
45app/Views/admin/trashed.php
46app/Views/admin/users.php
47app/Views/admin/user_edit.php
48app/Views/admin/groups.php
49app/Views/admin/levels.php
50app/Views/admin/database.php
51app/Views/admin/maintenance.php
52app/Views/admin/themes.php
53app/Views/admin/plugins.php
54app/Views/admin/plugin-edit.php
55app/Views/admin/blog_categories.php
56app/Views/admin/blog_manage.php
57app/Views/admin/verify.php


第四阶段:Morden 主题视图(逐个文件)

顺序文件
58assets/themes/morden/templates/layouts/main.php
59assets/themes/morden/templates/home/index.php
60assets/themes/morden/templates/forum/index.php
61assets/themes/morden/templates/forum/category.php
62assets/themes/morden/templates/thread/show.php
63assets/themes/morden/templates/thread/edit.php
64assets/themes/morden/templates/post/create.php
65assets/themes/morden/templates/post/edit.php
66assets/themes/morden/templates/auth/login.php
67assets/themes/morden/templates/auth/register.php
68assets/themes/morden/templates/auth/forgot_password.php
69assets/themes/morden/templates/auth/reset_password.php
70assets/themes/morden/templates/blog/index.php
71assets/themes/morden/templates/blog/detail.php
72assets/themes/morden/templates/blog/edit.php
73assets/themes/morden/templates/search/index.php
74assets/themes/morden/templates/profile/index.php
75assets/themes/morden/templates/message/compose.php
76assets/themes/morden/templates/message/inbox.php
77assets/themes/morden/templates/message/sent.php
78assets/themes/morden/templates/message/view.php
79assets/themes/morden/templates/tags/index.php
80assets/themes/morden/templates/tags/show.php
81assets/themes/morden/templates/theme/settings.php
82assets/themes/morden/templates/invite/index.php
83assets/themes/morden/templates/_components/left_sidebar.php
84assets/themes/morden/templates/_components/right_sidebar.php


第五阶段:JavaScript 文件(2 个文件)

顺序文件改动内容
85assets/js/editor.js硬编码的 /assets/img/emoji/ 和 /assets/js/ 改为读取 window.BASE_PATH
86assets/js/vote.js检查是否有硬编码 URL


第六阶段:插件(每个插件逐个改)

顺序插件涉及文件
87announcements钩子文件、视图
88content_review钩子文件、视图
89daily_checkin钩子文件、视图
90dev_docs钩子文件、视图
91edit_info钩子文件
92friend_links钩子文件、视图
93invite钩子文件、视图
94post_favorite钩子文件、视图
95qa钩子文件、视图
96red_packet钩子文件、视图
97seo钩子文件、视图
98user_profile钩子文件、视图


第七阶段:测试

顺序测试内容
99BASE_PATH = '' 根目录下全功能测试
100设置 BASE_PATH = '/sosite',二级目录下全功能测试


总计:约 100 步,每步改一个文件。

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

全部回复 (0)

暂无回复

请 登录