Browse Source

multiple user support

master
filesite 7 months ago
parent
commit
fe38726200
  1. 9
      conf/app.php
  2. 30
      lib/FSC.php
  3. 8
      themes/tajian/views/layout/main.php

9
conf/app.php

@ -7,6 +7,15 @@ $configs = array(
'default_timezone' => 'Asia/Shanghai', //timezone 'default_timezone' => 'Asia/Shanghai', //timezone
'site_name' => 'FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统', '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/ //'content_directory' => 'content/', //directory of contents in /www/
//when it's empty, use layout and views in directory views/ //when it's empty, use layout and views in directory views/

30
lib/FSC.php

@ -48,7 +48,27 @@ Class FSC {
$arr = parse_url($url); $arr = parse_url($url);
$path = !empty($arr['path']) ? $arr['path'] : '/'; $path = !empty($arr['path']) ? $arr['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); @list(, $controller, $action) = explode('/', $path);
}
if (empty($controller)) { if (empty($controller)) {
$controller = !empty($config['defaultController']) ? $config['defaultController'] : 'site'; $controller = !empty($config['defaultController']) ? $config['defaultController'] : 'site';
}else if(preg_match('/\w+\.\w+/i', $controller)) { //not controller but some file not exist }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); $action = preg_replace('/\W/', '', $action);
} }
return compact('controller', 'action'); return compact('controller', 'action', 'user_id');
} }
//add themes support //add themes support
@ -73,10 +93,16 @@ Class FSC {
$arr = self::getControllerAndAction($requestUrl, $config); $arr = self::getControllerAndAction($requestUrl, $config);
$controller = $arr['controller']; $controller = $arr['controller'];
$action = $arr['action']; $action = $arr['action'];
$user_id = $arr['user_id'];
$start_time = self::$start_time; $start_time = self::$start_time;
//如果多用户解析支持开启
if (!empty($config['multipleUserUriParse']) && !empty($user_id)) {
$config['content_directory'] = "{$config['content_directory']}{$user_id}/";
}
//set parameters //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 //call class and function
$className = ucfirst($controller) . 'Controller'; $className = ucfirst($controller) . 'Controller';

8
themes/tajian/views/layout/main.php

@ -53,10 +53,16 @@ require_once __DIR__ . '/../../../../plugins/Html.php';
$selectedId = !empty($viewData['cateId']) ? $viewData['cateId'] : ''; $selectedId = !empty($viewData['cateId']) ? $viewData['cateId'] : '';
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : []; $breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['tags'])) { //显示tags分类 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) { foreach($viewData['tags'] as $id => $item) {
$selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'this_set' : ''; $selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'this_set' : '';
echo <<<eof echo <<<eof
<a href="/list/?id={$item['id']}" class="{$selected}"> <a href="{$tagLink}?id={$item['id']}" class="{$selected}">
<img src="/img/other.svg" alt="菜单图标" /> <img src="/img/other.svg" alt="菜单图标" />
<span>{$item['name']}</span> <span>{$item['name']}</span>
</a> </a>

Loading…
Cancel
Save