From 602817684c510c8591b2bb150e23d14be51ac242 Mon Sep 17 00:00:00 2001 From: filesite Date: Sat, 9 Jul 2022 06:45:11 +0800 Subject: [PATCH] video play page done --- .../videoblog/controller/ListController.php | 19 +++++++--- .../videoblog/controller/ViewController.php | 27 +++++++++----- themes/videoblog/views/site/index.php | 10 +++-- themes/videoblog/views/view/index.php | 37 +++++++++++++++++++ 4 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 themes/videoblog/views/view/index.php diff --git a/themes/videoblog/controller/ListController.php b/themes/videoblog/controller/ListController.php index f890f71..b4c87b8 100644 --- a/themes/videoblog/controller/ListController.php +++ b/themes/videoblog/controller/ListController.php @@ -61,11 +61,20 @@ Class ListController extends Controller { protected function getBreadcrumbs($menus, $subcate) { $breads = []; - array_push($breads, [ - 'id' => $subcate['id'], - 'name' => $subcate['directory'], - 'url' => $subcate['path'], - ]); + 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) { diff --git a/themes/videoblog/controller/ViewController.php b/themes/videoblog/controller/ViewController.php index f9198e2..a8f2376 100644 --- a/themes/videoblog/controller/ViewController.php +++ b/themes/videoblog/controller/ViewController.php @@ -9,15 +9,22 @@ require_once __DIR__ . '/ListController.php'; Class ViewController extends ListController { public function actionIndex() { + $fileId = $this->get('id', ''); + if (!empty($fileId)) { + $fileId = preg_replace('/\W/', '', $fileId); + } + //获取数据 $scanner = new DirScanner(); $scanner->setWebRoot(FSC::$app['config']['content_directory']); $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); $scanResults = $scanner->getScanResults(); + if (empty($scanResults[$fileId])) { + throw new Exception("404 - 文件编号 {$fileId} 找不到", 404); + } //获取目录 $menus = $scanner->getMenus(); - $cateId = $this->get('id', $menus[0]['id']); $titles = []; $htmlReadme = ''; @@ -32,12 +39,12 @@ Class ViewController extends ListController { } //获取目录面包屑 - $subcate = $scanResults[$cateId]; - $breadcrumbs = $this->getBreadcrumbs($menus, $subcate); + $video = $scanResults[$fileId]; + $breadcrumbs = $this->getBreadcrumbs($scanResults, $video); //获取当前目录下的readme $htmlCateReadme = ''; - $cateReadmeFile = $scanner->getDefaultReadme($cateId); + $cateReadmeFile = $scanner->getDefaultReadme($fileId); if (!empty($cateReadmeFile)) { $Parsedown = new Parsedown(); $content = file_get_contents($cateReadmeFile['realpath']); @@ -46,14 +53,14 @@ Class ViewController extends ListController { } $pageTitle = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统"; - if (!empty($subcate)) { - $pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}"; - if (!empty($subcate['title'])) { - $pageTitle = $subcate['title']; + if (!empty($video)) { + $pageTitle = "{$video['directory']},来自{$pageTitle}"; + if (!empty($video['title'])) { + $pageTitle = $video['title']; } } - $viewName = '//site/index'; //共享视图 - $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme'); + $viewName = 'index'; + $params = compact('fileId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme', 'video'); return $this->render($viewName, $params, $pageTitle); } diff --git a/themes/videoblog/views/site/index.php b/themes/videoblog/views/site/index.php index 20497ac..6293510 100644 --- a/themes/videoblog/views/site/index.php +++ b/themes/videoblog/views/site/index.php @@ -61,10 +61,10 @@ eof; } if (!empty($category['directories'])) { //两级目录支持 - //如果已经是二级目录了,则当三级目录为视频目录,打开播放网页 $playBtnCls = ''; $playBtn = ''; - if (!empty($selectedId)) { + //如果已经是二级目录了,则当三级目录为视频目录,打开播放网页 + if (!empty($selectedId) && count($breadcrumbs) >= 2) { $playBtnCls = ' video-js vjs-big-play-centered'; $playBtn = <<