|
|
@ -9,6 +9,13 @@ require_once __DIR__ . '/../../../plugins/Common.php'; |
|
|
|
Class ListController extends Controller { |
|
|
|
Class ListController extends Controller { |
|
|
|
|
|
|
|
|
|
|
|
public function actionIndex() { |
|
|
|
public function actionIndex() { |
|
|
|
|
|
|
|
$cateId = $this->get('id', ''); |
|
|
|
|
|
|
|
$cacheParentDataId = $this->get('cid', ''); |
|
|
|
|
|
|
|
if (empty($cateId) || empty($cacheParentDataId)) { |
|
|
|
|
|
|
|
throw new Exception("参数缺失!", 403); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取数据 |
|
|
|
//获取数据 |
|
|
|
$menus = array(); //菜单,一级目录 |
|
|
|
$menus = array(); //菜单,一级目录 |
|
|
|
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍 |
|
|
|
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍 |
|
|
@ -16,23 +23,42 @@ Class ListController extends Controller { |
|
|
|
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序 |
|
|
|
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序 |
|
|
|
|
|
|
|
|
|
|
|
$scanner = new DirScanner(); |
|
|
|
$scanner = new DirScanner(); |
|
|
|
$scanner->setWebRoot(FSC::$app['config']['content_directory']); |
|
|
|
|
|
|
|
$scanner->setRootDir(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory']); |
|
|
|
//TODO: 根据参数cid获取id对应的目录realpath,从而只扫描这个目录 |
|
|
|
|
|
|
|
$cacheSeconds = 3600; |
|
|
|
|
|
|
|
$cachedParentData = Common::getCacheFromFile($cacheParentDataId, $cacheSeconds); |
|
|
|
|
|
|
|
if (empty($cachedParentData)) { |
|
|
|
|
|
|
|
throw new Exception("缓存已过期,请返回上一页重新进入!", 404); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$currentDir = $cachedParentData[$cateId]; |
|
|
|
|
|
|
|
if (empty($currentDir)) { |
|
|
|
|
|
|
|
throw new Exception("缓存数据中找不到当前目录,请返回上一页重新进入!", 404); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//$scanner->setWebRoot(FSC::$app['config']['content_directory']); |
|
|
|
|
|
|
|
$scanner->setWebRoot($this->getCurrentWebroot($currentDir)); |
|
|
|
|
|
|
|
$scanner->setRootDir($currentDir['realpath']); |
|
|
|
|
|
|
|
//header('Content-Type: text/html; charset=utf-8'); |
|
|
|
|
|
|
|
//echo $this->getCurrentWebroot($currentDir) . "\n"; |
|
|
|
|
|
|
|
//echo $currentDir['realpath'] . "\n"; |
|
|
|
|
|
|
|
//exit; |
|
|
|
|
|
|
|
|
|
|
|
//优先从缓存读取数据 |
|
|
|
//优先从缓存读取数据 |
|
|
|
$prefix = FSC::$app['config']['theme']; |
|
|
|
$prefix = FSC::$app['config']['theme'] . '_v1.0'; |
|
|
|
$cacheKey = "{$prefix}_allFilesTree"; |
|
|
|
$maxScanDeep = 2; //最大扫描目录级数 |
|
|
|
|
|
|
|
$cacheKey = "{$prefix}_ltree_{$maxScanDeep}_{$cateId}"; |
|
|
|
$cachedData = Common::getCacheFromFile($cacheKey); |
|
|
|
$cachedData = Common::getCacheFromFile($cacheKey); |
|
|
|
if (!empty($cachedData)) { |
|
|
|
if (!empty($cachedData)) { |
|
|
|
$dirTree = $cachedData; |
|
|
|
$dirTree = $cachedData; |
|
|
|
$scanner->setTreeData($cachedData); |
|
|
|
$scanner->setTreeData($cachedData); |
|
|
|
}else { |
|
|
|
}else { |
|
|
|
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); |
|
|
|
$dirTree = $scanner->scan($currentDir['realpath'], $maxScanDeep); |
|
|
|
Common::saveCacheToFile($cacheKey, $dirTree); |
|
|
|
Common::saveCacheToFile($cacheKey, $dirTree); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//优先从缓存读取数据 |
|
|
|
//优先从缓存读取数据 |
|
|
|
$cacheKey = "{$prefix}_allFilesData"; |
|
|
|
$cacheKey = $cacheDataId = "{$prefix}_ldata_{$maxScanDeep}_{$cateId}"; |
|
|
|
$cachedData = Common::getCacheFromFile($cacheKey); |
|
|
|
$cachedData = Common::getCacheFromFile($cacheKey); |
|
|
|
if (!empty($cachedData)) { |
|
|
|
if (!empty($cachedData)) { |
|
|
|
$scanResults = $cachedData; |
|
|
|
$scanResults = $cachedData; |
|
|
@ -42,6 +68,23 @@ Class ListController extends Controller { |
|
|
|
Common::saveCacheToFile($cacheKey, $scanResults); |
|
|
|
Common::saveCacheToFile($cacheKey, $scanResults); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//按照scanResults格式把当前目录扫描结果中的目录数据拼接到当前目录数据里: currentDir |
|
|
|
|
|
|
|
if (!empty($currentDir['directories'])) { |
|
|
|
|
|
|
|
foreach ($currentDir['directories'] as $id => $item) { |
|
|
|
|
|
|
|
if (empty($scanResults[$id]['directories'])) { |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$currentDir['directories'][$id] = $scanResults[$id]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
$scanResults = array($cateId => $currentDir); //重新组装数据 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//header('Content-Type: text/html; charset=utf-8'); |
|
|
|
|
|
|
|
//print_r($currentDir); |
|
|
|
|
|
|
|
//print_r($scanResults); |
|
|
|
|
|
|
|
//exit; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取目录 |
|
|
|
//获取目录 |
|
|
|
$menus = $scanner->getMenus(); |
|
|
|
$menus = $scanner->getMenus(); |
|
|
@ -69,16 +112,9 @@ Class ListController extends Controller { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//获取目录面包屑 |
|
|
|
//获取目录面包屑 |
|
|
|
$cateId = $this->get('id', $menus[0]['id']); |
|
|
|
//TODO: 重写此方法,根据scanner->getId()方法来逐级目录生成 |
|
|
|
$subcate = $scanResults[$cateId]; |
|
|
|
$subcate = $scanResults[$cateId]; |
|
|
|
$breadcrumbs = $this->getBreadcrumbs($menus, $subcate); |
|
|
|
$breadcrumbs = $this->getBreadcrumbs($currentDir, $cachedParentData, $scanner); |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
header('Content-type: text/html; charset=utf-8'); |
|
|
|
|
|
|
|
print_r($subcate); |
|
|
|
|
|
|
|
print_r($breadcrumbs); |
|
|
|
|
|
|
|
print_r($menus);exit; |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取当前目录下的readme |
|
|
|
//获取当前目录下的readme |
|
|
|
$cateReadmeFile = $scanner->getDefaultReadme($cateId); |
|
|
|
$cateReadmeFile = $scanner->getDefaultReadme($cateId); |
|
|
@ -110,7 +146,7 @@ print_r($menus);exit; |
|
|
|
$viewName = '//site/index'; //共享视图 |
|
|
|
$viewName = '//site/index'; //共享视图 |
|
|
|
$params = compact( |
|
|
|
$params = compact( |
|
|
|
'cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme', |
|
|
|
'cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme', |
|
|
|
'mp3File', 'page', 'pageSize' |
|
|
|
'mp3File', 'page', 'pageSize', 'cacheDataId', 'cacheParentDataId' |
|
|
|
); |
|
|
|
); |
|
|
|
return $this->render($viewName, $params, $pageTitle); |
|
|
|
return $this->render($viewName, $params, $pageTitle); |
|
|
|
} |
|
|
|
} |
|
|
@ -148,29 +184,49 @@ print_r($menus);exit; |
|
|
|
return $parent; |
|
|
|
return $parent; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected function getCurrentWebroot($currentDir) { |
|
|
|
|
|
|
|
$webroot = FSC::$app['config']['content_directory']; |
|
|
|
|
|
|
|
$arr = explode($webroot, $currentDir['realpath']); |
|
|
|
|
|
|
|
if (count($arr) < 2) { |
|
|
|
|
|
|
|
return $webroot; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return "{$webroot}{$arr[1]}/"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//根据目录结构以及当前目录获取面包屑 |
|
|
|
//根据目录结构以及当前目录获取面包屑 |
|
|
|
protected function getBreadcrumbs($menus, $subcate) { |
|
|
|
protected function getBreadcrumbs($currentDir, $scanResults, $scanner) { |
|
|
|
|
|
|
|
$webroot = FSC::$app['config']['content_directory']; |
|
|
|
|
|
|
|
$arr = explode($webroot, $currentDir['realpath']); |
|
|
|
$breads = array(); |
|
|
|
$breads = array(); |
|
|
|
|
|
|
|
|
|
|
|
array_push($breads, [ |
|
|
|
if (count($arr) < 2) { |
|
|
|
'id' => $subcate['id'], |
|
|
|
return $breads; |
|
|
|
'name' => $subcate['directory'], |
|
|
|
} |
|
|
|
'url' => $subcate['path'], |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$pid = $subcate['pid']; |
|
|
|
$cates = explode('/', $arr[1]); |
|
|
|
$parentCate = $this->getParentCateByPid($pid, $menus); |
|
|
|
$parentCate = "{$arr[0]}{$webroot}"; |
|
|
|
while (!empty($parentCate)) { |
|
|
|
foreach ($cates as $cate) { |
|
|
|
array_unshift($breads, [ |
|
|
|
if ($cate == $currentDir['directory']) {break;} |
|
|
|
'id' => $parentCate['id'], |
|
|
|
|
|
|
|
'name' => $parentCate['directory'], |
|
|
|
$subcate = "{$parentCate}{$cate}"; |
|
|
|
'url' => $parentCate['path'], |
|
|
|
$cateId = $scanner->getId($subcate); |
|
|
|
|
|
|
|
array_push($breads, [ |
|
|
|
|
|
|
|
'id' => $cateId, |
|
|
|
|
|
|
|
'name' => $cate, |
|
|
|
|
|
|
|
'url' => $scanResults[$cateId]['path'], |
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
$pid = $parentCate['pid']; |
|
|
|
$parentCate = "{$subcate}/"; //记录上一级目录 |
|
|
|
$parentCate = $this->getParentCateByPid($pid, $menus); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//最后一级 |
|
|
|
|
|
|
|
array_push($breads, [ |
|
|
|
|
|
|
|
'id' => $currentDir['id'], |
|
|
|
|
|
|
|
'name' => $currentDir['directory'], |
|
|
|
|
|
|
|
'url' => $currentDir['path'], |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
return $breads; |
|
|
|
return $breads; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|