diff --git a/lib/DirScanner.php b/lib/DirScanner.php index 30102c2..389319d 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -249,13 +249,25 @@ Class DirScanner { } //合并描述文件内容到md文件或者目录数据 + //增加视频文件:mp4, m3u8描述文件支持 private function mergeDescriptionData($realpath) { $data = []; $ext = $this->parseDescriptionFiles($realpath); //try to find the md file - $targetFile = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.md', $realpath); - if (file_exists($targetFile)) { + $targetFile = ''; + $targetFile_md = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.md', $realpath); + $targetFile_mp4 = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.mp4', $realpath); + $targetFile_m3u8 = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.m3u8', $realpath); + if (file_exists($targetFile_md)) { + $targetFile = $targetFile_md; + }else if (file_exists($targetFile_mp4)) { + $targetFile = $targetFile_mp4; + }else if (file_exists($targetFile_m3u8)) { + $targetFile = $targetFile_m3u8; + } + + if (!empty($targetFile)) { $fileId = $this->getId($targetFile); if (empty($this->scanResults[$fileId])) { $ext['id'] = $fileId; @@ -508,7 +520,7 @@ Class DirScanner { if (is_dir($realpath)) { $files = []; if ($nextLevels >= 0) { - $files = $this->scan($realpath, $nextLevels); + $files = $this->scan($realpath, $levels); if (!empty($files)) { foreach($files as $file) { $this->scanResults[$file['id']] = $file; diff --git a/themes/videoblog/controller/ListController.php b/themes/videoblog/controller/ListController.php index 8819e16..f890f71 100644 --- a/themes/videoblog/controller/ListController.php +++ b/themes/videoblog/controller/ListController.php @@ -11,12 +11,13 @@ Class ListController extends Controller { //获取数据 $scanner = new DirScanner(); $scanner->setWebRoot(FSC::$app['config']['content_directory']); - $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); + $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 = ''; @@ -32,7 +33,7 @@ Class ListController extends Controller { //获取目录面包屑 $subcate = $scanResults[$cateId]; - $breadcrumbs = $this->getBreadcrumbs($menus, $subcate); + $breadcrumbs = $this->getBreadcrumbs($scanResults, $subcate); //获取当前目录下的readme $htmlCateReadme = ''; @@ -66,13 +67,15 @@ Class ListController extends Controller { 'url' => $subcate['path'], ]); - $foundKey = array_search($subcate['pid'], array_column($menus, 'id')); - if ($foundKey !== false) { + $parent = !empty($menus[$subcate['pid']]) ? $menus[$subcate['pid']] : null; + while($parent) { array_unshift($breads, [ - 'id' => $menus[$foundKey]['id'], - 'name' => $menus[$foundKey]['directory'], - 'url' => $menus[$foundKey]['path'], + 'id' => $parent['id'], + 'name' => $parent['directory'], + 'url' => $parent['path'], ]); + + $parent = !empty($menus[$parent['pid']]) ? $menus[$parent['pid']] : null; } return $breads; diff --git a/themes/videoblog/controller/ViewController.php b/themes/videoblog/controller/ViewController.php new file mode 100644 index 0000000..f9198e2 --- /dev/null +++ b/themes/videoblog/controller/ViewController.php @@ -0,0 +1,60 @@ +setWebRoot(FSC::$app['config']['content_directory']); + $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); + $scanResults = $scanner->getScanResults(); + + //获取目录 + $menus = $scanner->getMenus(); + $cateId = $this->get('id', $menus[0]['id']); + + $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($menus, $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); + } + +} diff --git a/themes/videoblog/views/site/index.php b/themes/videoblog/views/site/index.php index 0e2b97d..20497ac 100644 --- a/themes/videoblog/views/site/index.php +++ b/themes/videoblog/views/site/index.php @@ -43,6 +43,7 @@ eof;