Source code of filesite.io.
https://filesite.io
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
3.3 KiB
93 lines
3.3 KiB
<?php |
|
/** |
|
* List Controller |
|
*/ |
|
require_once __DIR__ . '/../../../lib/DirScanner.php'; |
|
require_once __DIR__ . '/../../../plugins/Parsedown.php'; |
|
|
|
Class ListController extends Controller { |
|
|
|
public function actionIndex() { |
|
//获取数据 |
|
$scanner = new DirScanner(); |
|
$scanner->setWebRoot(FSC::$app['config']['content_directory']); |
|
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); |
|
$scanResults = $scanner->getScanResults(); |
|
|
|
//获取目录 |
|
$menus = $scanner->getMenus(); |
|
$cateId = $this->get('id', $menus[0]['id']); |
|
//print_r($menus);exit; |
|
|
|
$titles = []; |
|
$htmlReadme = ''; |
|
$readmeFile = $scanner->getDefaultReadme(); |
|
if (!empty($readmeFile)) { |
|
$titles = $scanner->getMDTitles($readmeFile['id']); |
|
|
|
$Parsedown = new Parsedown(); |
|
$content = file_get_contents($readmeFile['realpath']); |
|
$htmlReadme = $Parsedown->text($content); |
|
$htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); |
|
} |
|
|
|
//获取目录面包屑 |
|
$subcate = $scanResults[$cateId]; |
|
$breadcrumbs = $this->getBreadcrumbs($scanResults, $subcate); |
|
|
|
//获取当前目录下的readme |
|
$htmlCateReadme = ''; |
|
$cateReadmeFile = $scanner->getDefaultReadme($cateId); |
|
if (!empty($cateReadmeFile)) { |
|
$Parsedown = new Parsedown(); |
|
$content = file_get_contents($cateReadmeFile['realpath']); |
|
$htmlCateReadme = $Parsedown->text($content); |
|
$htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme); |
|
} |
|
|
|
$pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; |
|
if (!empty($subcate)) { |
|
$pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}"; |
|
if (!empty($subcate['title'])) { |
|
$pageTitle = $subcate['title']; |
|
} |
|
} |
|
$viewName = '//site/index'; //共享视图 |
|
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme'); |
|
return $this->render($viewName, $params, $pageTitle); |
|
} |
|
|
|
//根据目录结构以及当前目录获取面包屑 |
|
protected function getBreadcrumbs($menus, $subcate) { |
|
$breads = []; |
|
|
|
if (!empty($subcate['directory'])) { |
|
array_push($breads, [ |
|
'id' => $subcate['id'], |
|
'name' => $subcate['directory'], |
|
'url' => $subcate['path'], |
|
]); |
|
}else { //如果是文件 |
|
array_push($breads, [ |
|
'id' => $subcate['id'], |
|
'name' => $subcate['filename'], |
|
'url' => $subcate['path'], |
|
]); |
|
} |
|
|
|
|
|
$parent = !empty($menus[$subcate['pid']]) ? $menus[$subcate['pid']] : null; |
|
while($parent) { |
|
array_unshift($breads, [ |
|
'id' => $parent['id'], |
|
'name' => $parent['directory'], |
|
'url' => $parent['path'], |
|
]); |
|
|
|
$parent = !empty($menus[$parent['pid']]) ? $menus[$parent['pid']] : null; |
|
} |
|
|
|
return $breads; |
|
} |
|
|
|
}
|
|
|