diff --git a/conf/app.php b/conf/app.php index e89e6c4..6c3c266 100644 --- a/conf/app.php +++ b/conf/app.php @@ -48,6 +48,12 @@ $configs = array( ), */ + //皮肤TaJian相关 + 'tajian' => array( + 'data_dir' => 'data/', //数据目录 + 'tag_dir' => 'tags/', //tag分类目录 + ), + //目前支持的皮肤 'allowedThemes' => array( 'manual' => '文档站-默认', @@ -55,6 +61,7 @@ $configs = array( 'googleimage' => '图片站-默认', 'beauty' => '图片站-美图', 'videoblog' => '视频站-默认', + 'tajian' => 'TA荐-视频分享', ), //md5加密前缀 diff --git a/lib/DirScanner.php b/lib/DirScanner.php index 7ccddd7..64bf95b 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -274,6 +274,7 @@ Class DirScanner { //合并描述文件内容到md文件或者目录数据 //增加视频文件:mp4, m3u8描述文件支持 + //增加.url文件支持 private function mergeDescriptionData($realpath) { $data = array(); $ext = $this->parseDescriptionFiles($realpath); @@ -283,12 +284,15 @@ Class DirScanner { $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); + $targetFile_url = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.url', $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; + }else if (file_exists($targetFile_url)) { + $targetFile = $targetFile_url; } if (!empty($targetFile)) { diff --git a/themes/tajian/controller/ListController.php b/themes/tajian/controller/ListController.php new file mode 100644 index 0000000..cae0e21 --- /dev/null +++ b/themes/tajian/controller/ListController.php @@ -0,0 +1,106 @@ +setWebRoot(FSC::$app['config']['content_directory']); + $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3); + $scanResults = $scanner->getScanResults(); + + //获取目录 + $menus = $scanner->getMenus(); + + $titles = array(); + $readmeFile = $scanner->getDefaultReadme(); + if (!empty($readmeFile)) { + if (!empty($readmeFile['sort'])) { + $menus_sorted = explode("\n", $readmeFile['sort']); + } + + $titles = $scanner->getMDTitles($readmeFile['id']); + + $Parsedown = new Parsedown(); + $content = file_get_contents($readmeFile['realpath']); + $htmlReadme = $Parsedown->text($content); + $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); + } + + //排序 + $sortedTree = $this->sortMenusAndDirTree($menus_sorted, $menus, $dirTree); + if (!empty($sortedTree)) { + $menus = $sortedTree['menus']; + $dirTree = $sortedTree['dirTree']; + } + + //获取目录面包屑 + $cateId = $this->get('id', $menus[0]['id']); + $subcate = $scanResults[$cateId]; + $breadcrumbs = $this->getBreadcrumbs($scanResults, $subcate); + + //获取当前目录下的readme + $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 = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name']; + if (!empty($subcate)) { + $pageTitle = "{$subcate['directory']}相关视频,来自{$defaultTitle}"; + if (!empty($subcate['title'])) { + $pageTitle = "{$subcate['title']},来自{$defaultTitle}"; + } + } + $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(); + + 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($parent['pid']) && !empty($menus[$parent['pid']]) ? $menus[$parent['pid']] : null; + } + + return $breads; + } + +} diff --git a/themes/tajian/controller/SiteController.php b/themes/tajian/controller/SiteController.php new file mode 100644 index 0000000..96b6038 --- /dev/null +++ b/themes/tajian/controller/SiteController.php @@ -0,0 +1,73 @@ +setWebRoot(FSC::$app['config']['content_directory']); + $dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4); + $scanResults = $scanner->getScanResults(); + + //获取目录 + $menus = $scanner->getMenus(); + + $titles = array(); + $htmlReadme = ''; + $readmeFile = $scanner->getDefaultReadme(); + if (!empty($readmeFile)) { + if (!empty($readmeFile['sort'])) { + $menus_sorted = explode("\n", $readmeFile['sort']); + } + + $titles = $scanner->getMDTitles($readmeFile['id']); + + $Parsedown = new Parsedown(); + $content = file_get_contents($readmeFile['realpath']); + $htmlReadme = $Parsedown->text($content); + $htmlReadme = $scanner->fixMDUrls($readmeFile['realpath'], $htmlReadme); + } + + //排序 + $sortedTree = $this->sortMenusAndDirTree($menus_sorted, $menus, $dirTree); + if (!empty($sortedTree)) { + $menus = $sortedTree['menus']; + $dirTree = $sortedTree['dirTree']; + } + + //默认显示的目录 + $cateId = $this->get('id', $menus[0]['id']); + $subcate = $scanResults[$cateId]; + + //获取当前目录下的readme + $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 = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name']; + if (!empty($readmeFile['title'])) { + $pageTitle = "{$readmeFile['title']},来自{$defaultTitle}"; + } + if (!empty($subcate)) { + $pageTitle = "{$subcate['directory']},来自{$defaultTitle}"; + } + $viewName = 'index'; + $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme'); + return $this->render($viewName, $params, $pageTitle); + } + +} diff --git a/themes/tajian/controller/ViewController.php b/themes/tajian/controller/ViewController.php new file mode 100644 index 0000000..6d96552 --- /dev/null +++ b/themes/tajian/controller/ViewController.php @@ -0,0 +1,67 @@ +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(); + + $titles = array(); + $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); + } + + //获取目录面包屑 + $video = $scanResults[$fileId]; + $breadcrumbs = $this->getBreadcrumbs($scanResults, $video); + + //获取当前目录下的readme + $htmlCateReadme = ''; + $cateReadmeFile = $scanner->getDefaultReadme($fileId); + if (!empty($cateReadmeFile)) { + $Parsedown = new Parsedown(); + $content = file_get_contents($cateReadmeFile['realpath']); + $htmlCateReadme = $Parsedown->text($content); + $htmlCateReadme = $scanner->fixMDUrls($cateReadmeFile['realpath'], $htmlCateReadme); + } + + $pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name']; + if (!empty($video)) { + $pageTitle = "{$video['filename']},来自{$defaultTitle}"; + if (!empty($video['title'])) { + $pageTitle = "{$video['title']},来自{$defaultTitle}"; + } + } + $viewName = 'index'; + $params = compact('fileId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme', 'video'); + return $this->render($viewName, $params, $pageTitle); + } + +} diff --git a/themes/tajian/views/layout/main.php b/themes/tajian/views/layout/main.php new file mode 100644 index 0000000..8cb1c3f --- /dev/null +++ b/themes/tajian/views/layout/main.php @@ -0,0 +1,117 @@ + + + + +<?php echo $pageTitle;?> + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + diff --git a/themes/tajian/views/site/index.php b/themes/tajian/views/site/index.php new file mode 100644 index 0000000..4cf6b5d --- /dev/null +++ b/themes/tajian/views/site/index.php @@ -0,0 +1,170 @@ + + +
+ + + 当前位置: +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'])) { //两级目录支持 + $playBtnCls = ''; + $playBtn = ''; + //如果已经是二级目录了,则当三级目录为视频目录,打开播放网页 + if (!empty($selectedId) && count($breadcrumbs) >= 2) { + $playBtnCls = ' video-js vjs-big-play-centered'; + $playBtn = <<