Browse Source

add controller and views for tajian

master
filesite 1 year ago
parent
commit
ffa7f9c26a
  1. 7
      conf/app.php
  2. 4
      lib/DirScanner.php
  3. 106
      themes/tajian/controller/ListController.php
  4. 73
      themes/tajian/controller/SiteController.php
  5. 67
      themes/tajian/controller/ViewController.php
  6. 117
      themes/tajian/views/layout/main.php
  7. 170
      themes/tajian/views/site/index.php
  8. 37
      themes/tajian/views/view/index.php

7
conf/app.php

@ -48,6 +48,12 @@ $configs = array(
), ),
*/ */
//皮肤TaJian相关
'tajian' => array(
'data_dir' => 'data/', //数据目录
'tag_dir' => 'tags/', //tag分类目录
),
//目前支持的皮肤 //目前支持的皮肤
'allowedThemes' => array( 'allowedThemes' => array(
'manual' => '文档站-默认', 'manual' => '文档站-默认',
@ -55,6 +61,7 @@ $configs = array(
'googleimage' => '图片站-默认', 'googleimage' => '图片站-默认',
'beauty' => '图片站-美图', 'beauty' => '图片站-美图',
'videoblog' => '视频站-默认', 'videoblog' => '视频站-默认',
'tajian' => 'TA荐-视频分享',
), ),
//md5加密前缀 //md5加密前缀

4
lib/DirScanner.php

@ -274,6 +274,7 @@ Class DirScanner {
//合并描述文件内容到md文件或者目录数据 //合并描述文件内容到md文件或者目录数据
//增加视频文件:mp4, m3u8描述文件支持 //增加视频文件:mp4, m3u8描述文件支持
//增加.url文件支持
private function mergeDescriptionData($realpath) { private function mergeDescriptionData($realpath) {
$data = array(); $data = array();
$ext = $this->parseDescriptionFiles($realpath); $ext = $this->parseDescriptionFiles($realpath);
@ -283,12 +284,15 @@ Class DirScanner {
$targetFile_md = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.md', $realpath); $targetFile_md = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.md', $realpath);
$targetFile_mp4 = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.mp4', $realpath); $targetFile_mp4 = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.mp4', $realpath);
$targetFile_m3u8 = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.m3u8', $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)) { if (file_exists($targetFile_md)) {
$targetFile = $targetFile_md; $targetFile = $targetFile_md;
}else if (file_exists($targetFile_mp4)) { }else if (file_exists($targetFile_mp4)) {
$targetFile = $targetFile_mp4; $targetFile = $targetFile_mp4;
}else if (file_exists($targetFile_m3u8)) { }else if (file_exists($targetFile_m3u8)) {
$targetFile = $targetFile_m3u8; $targetFile = $targetFile_m3u8;
}else if (file_exists($targetFile_url)) {
$targetFile = $targetFile_url;
} }
if (!empty($targetFile)) { if (!empty($targetFile)) {

106
themes/tajian/controller/ListController.php

@ -0,0 +1,106 @@
<?php
/**
* List Controller
*/
require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php';
Class ListController extends Controller {
public function actionIndex() {
//获取数据
$menus = array(); //菜单,一级目录
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
$scanner = new DirScanner();
$scanner->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;
}
}

73
themes/tajian/controller/SiteController.php

@ -0,0 +1,73 @@
<?php
/**
* Site Controller
*/
require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php';
Class SiteController extends Controller {
public function actionIndex() {
//获取数据
$menus = array(); //菜单,一级目录
$htmlReadme = ''; //Readme.md 内容,底部网站详细介绍
$htmlCateReadme = ''; //当前目录下的Readme.md 内容
$menus_sorted = array(); //Readme_sort.txt 说明文件内容,一级目录菜单从上到下的排序
$scanner = new DirScanner();
$scanner->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);
}
}

67
themes/tajian/controller/ViewController.php

@ -0,0 +1,67 @@
<?php
/**
* View Controller
*/
require_once __DIR__ . '/../../../lib/DirScanner.php';
require_once __DIR__ . '/../../../plugins/Parsedown.php';
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();
$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);
}
}

117
themes/tajian/views/layout/main.php

@ -0,0 +1,117 @@
<?php
//常用方法
require_once __DIR__ . '/../../../../plugins/Html.php';
?><!DocType html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $pageTitle;?></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<link rel="icon" type="image/x-icon" href="/favicon.ico?v1.0">
<link href="/css/main.css?v.1.1" rel="stylesheet">
<!--for theme videoblog-->
<link href="/css/github-markdown-dark.css" rel="stylesheet">
<link href="/css/video-js.min.css" rel="stylesheet">
<link href="/css/videoblog.css?v<?=Html::getStaticFileVersion('videoblog.css', 'css')?>" rel="stylesheet">
<style>
<?php if (!empty(FSC::$app['config']['videoblog']['imageHeight'])) { ?>
.img-item img{height: <?php echo FSC::$app['config']['videoblog']['imageHeight']; ?>px;}
<?php } ?>
</style>
</head>
<body>
<div class="header">
<a href="/" class="logo">
<img src="/content/machete_icon.png" alt="Logo of FileSite.io" height="34">
TaJian.tv
</a>
<a href="#modal_about" role="button" class="about btn-open">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" width="24" height="24"><!--! Font Awesome Pro 6.1.1 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. --><path d="M191.1 224c0-17.72-14.34-32.04-32-32.04L144 192c-35.34 0-64 28.66-64 64.08v47.79C80 339.3 108.7 368 144 368H160c17.66 0 32-14.36 32-32.06L191.1 224zM256 0C112.9 0 4.583 119.1 .0208 256L0 296C0 309.3 10.75 320 23.1 320S48 309.3 48 296V256c0-114.7 93.34-207.8 208-207.8C370.7 48.2 464 141.3 464 256v144c0 22.09-17.91 40-40 40h-110.7C305 425.7 289.7 416 272 416H241.8c-23.21 0-44.5 15.69-48.87 38.49C187 485.2 210.4 512 239.1 512H272c17.72 0 33.03-9.711 41.34-24H424c48.6 0 88-39.4 88-88V256C507.4 119.1 399.1 0 256 0zM368 368c35.34 0 64-28.7 64-64.13V256.1C432 220.7 403.3 192 368 192l-16 0c-17.66 0-32 14.34-32 32.04L320 335.9C320 353.7 334.3 368 352 368H368z"/></svg>
</a>
</div>
<?php
//### Render view file
if (!empty($viewFile) && file_exists($viewFile)) {
include_once $viewFile;
}
?>
<div class="modal-mask" id="modal_about">
<div class="modal-about">
<div class="modal-head">
<h3>联系我</h3>
<span class="btn-close" role="button"><svg width="24" height="24" viewBox="0 0 24 24" focusable="false" class=" NMm5M"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"></path></svg></span>
</div>
<div class="hr"></div>
<div class="modal-body markdown-body">
<?php echo !empty($viewData['htmlReadme']) ? $viewData['htmlReadme'] : ''; ?>
</div>
</div>
</div>
<div class="footer">
<?php if (!empty(FSC::$app['config']['theme'])) { ?>
Theme name <strong><?php echo FSC::$app['config']['theme']; ?></strong>
<br>
<?php } ?>
&copy;FSC 2022 - execute time: {page_time_cost} ms
<?php if (!empty(FSC::$app['config']['videoblog']['contact'])) {
$contactInfo = FSC::$app['config']['videoblog']['contact'];
echo <<<eof
<p>{$contactInfo}</p>
eof;
} ?>
</div>
<!-- The Gallery as lightbox dialog, should be a document body child element -->
<div
id="blueimp-gallery"
class="blueimp-gallery blueimp-gallery-controls"
aria-label="image gallery"
aria-modal="true"
role="dialog"
>
<div class="slides" aria-live="polite"></div>
<h3 class="title"></h3>
<a
class="prev"
aria-controls="blueimp-gallery"
aria-label="previous slide"
aria-keyshortcuts="ArrowLeft"
></a>
<a
class="next"
aria-controls="blueimp-gallery"
aria-label="next slide"
aria-keyshortcuts="ArrowRight"
></a>
<a
class="close"
aria-controls="blueimp-gallery"
aria-label="close"
aria-keyshortcuts="Escape"
></a>
<a
class="play-pause"
aria-controls="blueimp-gallery"
aria-label="play slideshow"
aria-keyshortcuts="Space"
aria-pressed="false"
role="button"
></a>
<ol class="indicator"></ol>
</div>
<script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/js.cookie.min.js"></script>
<script src="/js/main.js?v.1.0"></script>
<!--for theme videoblog-->
<script src="/js/lazysizes.min.js"></script>
<script src="/js/video.min.js"></script>
<script src="/js/videoblog.js?v<?=Html::getStaticFileVersion('videoblog.js', 'js')?>"></script>
</body>
</html>

170
themes/tajian/views/site/index.php

@ -0,0 +1,170 @@
<div class="menu">
<?php
$imgPreffix = FSC::$app['config']['content_directory'] . FSC::$app['config']['tajian']['data_dir'];
$selectedId = $viewData['cateId'];
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['menus'])) { //只显示第一级目录
foreach($viewData['menus'] as $index => $item) {
$selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'selected' : '';
echo <<<eof
<a href="/?id={$item['id']}" class="{$selected}">{$item['directory']}</a>
eof;
}
}
?>
</div>
<div class="hr"></div>
<?php
if (!empty($breadcrumbs)) {
echo <<<eof
<div class="breadcrumbs">
<small>当前位置:</small>
eof;
foreach($breadcrumbs as $bread) {
if ($bread['id'] != $selectedId) {
echo <<<eof
<a href="{$bread['url']}">{$bread['name']}</a> /
eof;
}else {
echo <<<eof
<strong>{$bread['name']}</strong>
eof;
}
}
echo <<<eof
</div>
eof;
}
?>
<div class="content">
<?php
$imgExts = array('jpg', 'jpeg', 'png', 'gif');
$videoExts = array('url', 'mp4', 'm3u8');
$category = $viewData['scanResults'][$selectedId];
//当前目录的描述介绍
if (!empty($category['description'])) {
echo <<<eof
<p class="catedesc">{$category['description']}</p>
eof;
}
//当前目录的readme详细介绍
if (!empty($viewData['htmlCateReadme'])) {
echo <<<eof
<div class="cateinfo markdown-body">{$viewData['htmlCateReadme']}</div>
eof;
}
if (!empty($category['directories'])) { //两级目录支持
$playBtnCls = '';
$playBtn = '';
//如果已经是二级目录了,则当三级目录为视频目录,打开播放网页
if (!empty($selectedId) && count($breadcrumbs) >= 2) {
$playBtnCls = ' video-js vjs-big-play-centered';
$playBtn = <<<eof
<button class="vjs-big-play-button" type="button" title="Play Video" aria-disabled="false" style="display:none">
<span class="vjs-icon-placeholder" aria-hidden="true"></span>
<span class="vjs-control-text" aria-live="polite">Play Video</span>
</button>
eof;
}
foreach($category['directories'] as $dir) {
$playUrl = !empty($playBtn) ? "/view/?id={$dir['id']}" : $dir['path'];
$openInBlank = !empty($playBtn) ? ' target="_blank"' : '';
echo <<<eof
<a href="{$playUrl}" class="img-item"{$openInBlank}>
<span class="img-con{$playBtnCls}">
eof;
if (!empty($dir['snapshot'])) {
echo <<<eof
<img data-src="{$dir['snapshot']}" class="lazyload" alt="{$dir['directory']}">
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
<img data-src="{$first_img['path']}" class="lazyload" alt="{$first_img['filename']}">
eof;
}else {
echo <<<eof
<img src="/img/default.png" alt="default image">
eof;
}
}
if (!empty($dir['duration'])) {
echo <<<eof
<span class="duration">{$dir['duration']}</span>
eof;
}
$title = !empty($dir['title']) ? $dir['title'] : $dir['directory'];
echo <<<eof
{$playBtn}
</span>
<strong>{$title}</strong>
</a>
eof;
}
}
if (!empty($category['files'])) { //一级目录支持,目录下直接存放视频文件
$first_img = '';
//如果目录没有封面图,则先找出第一个图片做封面
if (empty($category['snapshot'])) {
foreach($category['files'] as $file) {
if (empty($first_img) && in_array($file['extension'], $imgExts)) {
$first_img = $file;
break;
}
}
}
foreach($category['files'] as $file) {
//跳过非视频文件
if (!in_array($file['extension'], $videoExts)) {
continue;
}
$duration = !empty($category['duration']) ? $category['duration'] : '';
$snapshot = !empty($file['cover']) ? $imgPreffix . $file['cover'] : (!empty($category['snapshot']) ? $category['snapshot'] :
(!empty($first_img['path']) ? $first_img['path'] : '/img/default.png')
);
$title = !empty($file['title']) ? $file['title'] : $file['filename'];
echo <<<eof
<a href="/view/?id={$file['id']}" class="img-item img-preview" target="_blank">
<span class="img-con video-js vjs-big-play-centered">
<img data-src="{$snapshot}" class="lazyload" alt="snapshot of {$title}">
<span class="duration">{$duration}</span>
<button class="vjs-big-play-button" type="button" title="Play Video" aria-disabled="false" style="display:none">
<span class="vjs-icon-placeholder" aria-hidden="true"></span>
<span class="vjs-control-text" aria-live="polite">Play Video</span>
</button>
</span>
<strong>{$title}</strong>
</a>
eof;
}
}
?>
</div>

37
themes/tajian/views/view/index.php

@ -0,0 +1,37 @@
<?php
$videoUrl = '';
$poster = '';
$imgExts = array('jpg', 'jpeg', 'png', 'gif');
$videoExts = array('mp4', 'm3u8');
if (!empty($viewData['video'])) {
$video = $viewData['video'];
if (!empty($video['directory'])) { //如果是目录,则找出里面第一个mp4作为播放地址
$poster = $video['snapshot'];
if (!empty($video['files'])) {
foreach ($video['files'] as $id => $item) {
if (empty($poster) && in_array($item['extension'], $imgExts)) {
$poster = $item['path'];
}
if (in_array($item['extension'], $videoExts)) {
$videoUrl = $item['path'];
break;
}
}
}
}else {
$videoUrl = $video['path'];
}
}
?><div class="video">
<video class="video-js vjs-big-play-centered vjs-fluid vjs-16-9"
controls
playsinline
data-setup='{"autoplay":"muted"}'
poster="<?php echo !empty($viewData['video']['snapshot']) ? $viewData['video']['snapshot'] : ''; ?>"
id="myvideo">
<source src="<?php echo $videoUrl; ?>" type="video/mp4">
</video>
</div>
Loading…
Cancel
Save