diff --git a/themes/manual/controller/SiteController.php b/themes/manual/controller/SiteController.php index ffe3b33..a76ddec 100644 --- a/themes/manual/controller/SiteController.php +++ b/themes/manual/controller/SiteController.php @@ -10,13 +10,15 @@ Class SiteController extends Controller { public function actionIndex() { //获取数据 + $titles = []; + $content = ''; + $html = ''; + $scanner = new DirScanner(); $scanner->setWebRoot('/content/'); $dirTree = $scanner->scan(__DIR__ . '/../../../www/content/', 4); $readmeFile = $scanner->getDefaultReadme(); - $titles = []; - $content = ''; - $html = ''; + if (!empty($readmeFile)) { $titles = $scanner->getMDTitles($readmeFile['id']); $content = file_get_contents($readmeFile['realpath']); @@ -26,15 +28,9 @@ Class SiteController extends Controller { $html = $scanner->fixMDUrls($readmeFile['realpath'], $html); } - //alert message test - //$this->sendMsgToClient('Alert message - danger', 'danger'); - //$this->sendMsgToClient('Alert message - warning', 'warning'); - //$this->sendMsgToClient('Alert message - success', 'success'); - //$this->sendMsgToClient('Alert message - info', 'info'); - $pageTitle = "FileSite.io - 无数据库、基于文件和目录的网址导航、图书、图片、视频网站PHP开源系统"; $viewName = 'index'; - $params = compact('dirTree', 'readmeFile', 'titles', 'content', 'html'); + $params = compact('titles', 'content', 'html'); return $this->render($viewName, $params, $pageTitle); } diff --git a/themes/manual/controller/ViewController.php b/themes/manual/controller/ViewController.php new file mode 100644 index 0000000..8bc41fd --- /dev/null +++ b/themes/manual/controller/ViewController.php @@ -0,0 +1,45 @@ +get('id', ''); + if (!empty($fileId)) { + $fileId = preg_replace('/\W/', '', $fileId); + } + + //获取数据 + $titles = []; + $content = ''; + $html = ''; + + $scanner = new DirScanner(); + $scanner->setWebRoot('/content/'); + $dirTree = $scanner->scan(__DIR__ . '/../../../www/content/', 4); + + $scanResults = $scanner->getScanResults(); + if (!empty($scanResults[$fileId])) { + $readmeFile = $scanResults[$fileId]; + $titles = $scanner->getMDTitles($readmeFile['id']); + $content = file_get_contents($readmeFile['realpath']); + + $Parsedown = new Parsedown(); + $html = $Parsedown->text($content); + $html = $scanner->fixMDUrls($readmeFile['realpath'], $html); + }else { + throw new Exception("404 - 文件编号 {$fileId} 找不到", 404); + } + + $pageTitle = !empty($titles) ? $titles[0]['name'] : "404 - 文件找不到"; + $viewName = 'index'; + $params = compact('titles', 'content', 'html'); + return $this->render($viewName, $params, $pageTitle); + } + +} diff --git a/themes/manual/views/view/index.php b/themes/manual/views/view/index.php new file mode 100644 index 0000000..c3280ee --- /dev/null +++ b/themes/manual/views/view/index.php @@ -0,0 +1,16 @@ +