From fe387262006286804536fd6316e55f4b7033442a Mon Sep 17 00:00:00 2001 From: filesite Date: Wed, 17 Apr 2024 13:47:02 +0800 Subject: [PATCH] multiple user support --- conf/app.php | 9 ++++++ lib/FSC.php | 32 +++++++++++++++++++-- themes/tajian/controller/ListController.php | 2 +- themes/tajian/views/layout/main.php | 8 +++++- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/conf/app.php b/conf/app.php index 8426880..cd1fd23 100644 --- a/conf/app.php +++ b/conf/app.php @@ -7,6 +7,15 @@ $configs = array( 'default_timezone' => 'Asia/Shanghai', //timezone 'site_name' => 'FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统', + //多用户网址解析开关,默认为关闭状态 + //规则:当此开关打开的情况下,网址中域名后面第一个目录,如果是纯数字,则把它作为用户ID + //示例:https://tajian.tv/1000/site/index,其中的1000就是用户ID + //解析成功后会将用户ID保存在FSC::$app全局变量中,通过:FSC::$app['user_id']访问 + //并自动把用户ID加入到数据目录content_directory路径后面 + 'multipleUserUriParse' => false, + //只有上面这个开关开启,此默认用户ID才会被使用 + 'defaultUserId' => '1000', + //文档站皮肤 //'content_directory' => 'content/', //directory of contents in /www/ //when it's empty, use layout and views in directory views/ diff --git a/lib/FSC.php b/lib/FSC.php index d083875..ac30f91 100644 --- a/lib/FSC.php +++ b/lib/FSC.php @@ -48,7 +48,27 @@ Class FSC { $arr = parse_url($url); $path = !empty($arr['path']) ? $arr['path'] : '/'; - @list(, $controller, $action) = explode('/', $path); + $controller = $action = $user_id = ''; + if (!empty($config['multipleUserUriParse'])) { //如果开启了多用户解析支持 + $pathArr = explode('/', $path); + if (count($pathArr) >= 2 && is_numeric($pathArr[1])) { + $user_id = $pathArr[1]; + if (!empty($pathArr[2])) { + $controller = $pathArr[2]; + } + if (!empty($pathArr[3])) { + $action = $pathArr[3]; + } + }else { + @list(, $controller, $action) = $pathArr; + if (!empty($config['defaultUserId'])) { + $user_id = $config['defaultUserId']; + } + } + }else { + @list(, $controller, $action) = explode('/', $path); + } + if (empty($controller)) { $controller = !empty($config['defaultController']) ? $config['defaultController'] : 'site'; }else if(preg_match('/\w+\.\w+/i', $controller)) { //not controller but some file not exist @@ -63,7 +83,7 @@ Class FSC { $action = preg_replace('/\W/', '', $action); } - return compact('controller', 'action'); + return compact('controller', 'action', 'user_id'); } //add themes support @@ -73,10 +93,16 @@ Class FSC { $arr = self::getControllerAndAction($requestUrl, $config); $controller = $arr['controller']; $action = $arr['action']; + $user_id = $arr['user_id']; $start_time = self::$start_time; + //如果多用户解析支持开启 + if (!empty($config['multipleUserUriParse']) && !empty($user_id)) { + $config['content_directory'] = "{$config['content_directory']}{$user_id}/"; + } + //set parameters - self::$app = compact('config', 'controller', 'action', 'requestUrl', 'start_time'); + self::$app = compact('config', 'controller', 'action', 'user_id', 'requestUrl', 'start_time'); //call class and function $className = ucfirst($controller) . 'Controller'; diff --git a/themes/tajian/controller/ListController.php b/themes/tajian/controller/ListController.php index 06ef86c..bfc21cf 100644 --- a/themes/tajian/controller/ListController.php +++ b/themes/tajian/controller/ListController.php @@ -14,7 +14,7 @@ Class ListController extends SiteController { $htmlReadme = ''; //Readme.md 内容,底部网站详细介绍 $htmlCateReadme = ''; //当前目录下的Readme.md 内容 $menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序 - + $scanner = new DirScanner(); $scanner->setWebRoot(FSC::$app['config']['content_directory']); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); diff --git a/themes/tajian/views/layout/main.php b/themes/tajian/views/layout/main.php index e01bc7e..8a020d1 100644 --- a/themes/tajian/views/layout/main.php +++ b/themes/tajian/views/layout/main.php @@ -53,10 +53,16 @@ require_once __DIR__ . '/../../../../plugins/Html.php'; $selectedId = !empty($viewData['cateId']) ? $viewData['cateId'] : ''; $breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : []; if (!empty($viewData['tags'])) { //显示tags分类 + $tagLink = '/list/'; + //多用户路径支持 + if (!empty(FSC::$app['config']['multipleUserUriParse']) && !empty(FSC::$app['user_id'])) { + $tagLink = '/' . FSC::$app['user_id'] . '/list/'; + } + foreach($viewData['tags'] as $id => $item) { $selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'this_set' : ''; echo << + 菜单图标 {$item['name']}