diff --git a/conf/app.php b/conf/app.php index d228d75..04fc1b3 100644 --- a/conf/app.php +++ b/conf/app.php @@ -6,9 +6,9 @@ return array( 'default_timezone' => 'Asia/Shanghai', //timezone //文档站皮肤 - 'content_directory' => 'content/', //directory of contents in /www/ + //'content_directory' => 'content/', //directory of contents in /www/ //when it's empty, use layout and views in directory views/ - 'theme' => 'manual', //name of theme which is enabled + //'theme' => 'manual', //name of theme which is enabled //导航站皮肤 //'content_directory' => 'navs/', //directory of contents in /www/ @@ -17,6 +17,10 @@ return array( //图片站皮肤 //'content_directory' => 'girls/', //directory of contents in /www/ //'theme' => 'googleimage', //name of theme which is enabled + + //视频站皮肤 + 'content_directory' => 'videos/', //directory of contents in /www/ + 'theme' => 'videoblog', //name of theme which is enabled 'default_layout' => 'main', //default layout 'error_layout' => 'error', //exception layout, show error title and content @@ -26,9 +30,16 @@ return array( //for themes /* + //图片皮肤配置 'googleimage' => [ 'imageHeight' => 350, //图片高度,单位:px 'contact' => 'FileSite图片网站订制联系:FileSite.io', ], */ + + //视频皮肤配置 + 'videoblog' => [ + 'imageHeight' => 180, //图片高度,单位:px + 'contact' => 'FileSite视频网站订制联系:FileSite.io', + ], ); diff --git a/themes/videoblog/controller/ListController.php b/themes/videoblog/controller/ListController.php new file mode 100644 index 0000000..8819e16 --- /dev/null +++ b/themes/videoblog/controller/ListController.php @@ -0,0 +1,81 @@ +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); + } + + //根据目录结构以及当前目录获取面包屑 + protected function getBreadcrumbs($menus, $subcate) { + $breads = []; + + array_push($breads, [ + 'id' => $subcate['id'], + 'name' => $subcate['directory'], + 'url' => $subcate['path'], + ]); + + $foundKey = array_search($subcate['pid'], array_column($menus, 'id')); + if ($foundKey !== false) { + array_unshift($breads, [ + 'id' => $menus[$foundKey]['id'], + 'name' => $menus[$foundKey]['directory'], + 'url' => $menus[$foundKey]['path'], + ]); + } + + return $breads; + } + +} diff --git a/themes/videoblog/controller/SiteController.php b/themes/videoblog/controller/SiteController.php new file mode 100644 index 0000000..76dbf88 --- /dev/null +++ b/themes/videoblog/controller/SiteController.php @@ -0,0 +1,57 @@ +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]; + + //获取当前目录下的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($readmeFile['title'])) { + $pageTitle = $readmeFile['title']; + } + if (!empty($subcate)) { + $pageTitle = "{$subcate['directory']},来自{$pageTitle}"; + } + $viewName = 'index'; + $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme'); + return $this->render($viewName, $params, $pageTitle); + } + +} diff --git a/themes/videoblog/views/layout/main.php b/themes/videoblog/views/layout/main.php new file mode 100644 index 0000000..92ffdd4 --- /dev/null +++ b/themes/videoblog/views/layout/main.php @@ -0,0 +1,117 @@ + + + + +<?php echo $pageTitle;?> + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + diff --git a/themes/videoblog/views/site/index.php b/themes/videoblog/views/site/index.php new file mode 100644 index 0000000..0e2b97d --- /dev/null +++ b/themes/videoblog/views/site/index.php @@ -0,0 +1,133 @@ + + +
+ + + 当前位置: +eof; + + foreach($breadcrumbs as $bread) { + if ($bread['id'] != $selectedId) { + echo <<{$bread['name']} / +eof; + }else { + echo <<{$bread['name']} +eof; + } + } + + echo << +eof; +} +?> + +
+ {$category['description']}

+eof; + } + + //当前目录的readme详细介绍 + if (!empty($viewData['htmlCateReadme'])) { + echo <<{$viewData['htmlCateReadme']}
+eof; + } + + if (!empty($category['directories'])) { //两级目录支持 + foreach($category['directories'] as $dir) { + echo << + +eof; + + if (!empty($dir['snapshot'])) { + echo << +eof; + }else if (!empty($dir['files'])) { + $first_img = array_shift($dir['files']); + if (!in_array($first_img['extension'], $imgExts)) { + foreach($dir['files'] as $file) { + if (in_array($file['extension'], $imgExts)) { + $first_img = $file; + break; + } + } + } + + if (in_array($first_img['extension'], $imgExts)) { + echo << +eof; + } + } + + if (!empty($dir['duration'])) { + echo <<{$dir['duration']} +eof; + } + + $title = !empty($dir['title']) ? $dir['title'] : $dir['directory']; + echo <<