Browse Source

theme tajian update

master
filesite 1 year ago
parent
commit
6f5ac27b62
  1. 23
      plugins/Html.php
  2. 7
      themes/tajian/controller/SiteController.php
  3. 67
      themes/tajian/controller/ViewController.php
  4. 203
      themes/tajian/views/site/index.php
  5. 6
      themes/videoblog/controller/SiteController.php

23
plugins/Html.php

@ -28,4 +28,27 @@ Class Html {
return $ver; return $ver;
} }
public static function mb_substr($string, $start, $length) {
if (mb_strlen($string, 'utf-8') <= $length) {return $string;}
return mb_substr($string, $start, $length, 'utf-8') . "...";
}
public static function getShareVideosPlatform($url) {
$platform = '-';
if (preg_match("/douyin\.com/i", $url)) {
$platform = '抖音';
}else if (preg_match("/kuaishou\.com/i", $url)) {
$platform = '快手';
}else if (preg_match("/ixigua\.com/i", $url)) {
$platform = '西瓜视频';
}else if (preg_match("/b23\.tv/i", $url) || preg_match("/bilibili\.com/i", $url)) {
$platform = 'B站';
}
return $platform;
}
} }

7
themes/tajian/controller/SiteController.php

@ -59,12 +59,13 @@ Class SiteController extends Controller {
} }
$pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name']; $pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name'];
if (!empty($readmeFile['title'])) {
$pageTitle = "{$readmeFile['title']},来自{$defaultTitle}";
}
if (!empty($subcate)) { if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']},来自{$defaultTitle}"; $pageTitle = "{$subcate['directory']},来自{$defaultTitle}";
} }
if (!empty($readmeFile['title'])) {
$pageTitle = "{$readmeFile['title']},来自{$defaultTitle}";
}
$viewName = 'index'; $viewName = 'index';
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme'); $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme');
return $this->render($viewName, $params, $pageTitle); return $this->render($viewName, $params, $pageTitle);

67
themes/tajian/controller/ViewController.php

@ -1,67 +0,0 @@
<?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);
}
}

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

@ -1,15 +1,19 @@
<div class="menu">
<?php <?php
//常用方法
require_once __DIR__ . '/../../../../plugins/Html.php';
$imgPreffix = FSC::$app['config']['content_directory'] . FSC::$app['config']['tajian']['data_dir']; $imgPreffix = FSC::$app['config']['content_directory'] . FSC::$app['config']['tajian']['data_dir'];
?><div class="menu">
<?php
$selectedId = $viewData['cateId']; $selectedId = $viewData['cateId'];
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : []; $breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['menus'])) { //只显示第一级目录 if (!empty($viewData['menus'])) { //只显示第一级目录
foreach($viewData['menus'] as $index => $item) { foreach($viewData['menus'] as $index => $item) {
$selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'selected' : ''; $selected = $item['id'] == $selectedId || (!empty($breadcrumbs) && $item['id'] == $breadcrumbs[0]['id']) ? 'selected' : '';
echo <<<eof echo <<<eof
<a href="/?id={$item['id']}" class="{$selected}">{$item['directory']}</a> <a href="/?id={$item['id']}" class="{$selected}">{$item['directory']}</a>
eof; eof;
} }
} }
?> ?>
</div> </div>
@ -18,153 +22,76 @@ eof;
<?php <?php
if (!empty($breadcrumbs)) { if (!empty($breadcrumbs)) {
echo <<<eof echo <<<eof
<div class="breadcrumbs"> <div class="breadcrumbs">
<small>当前位置:</small> <small>当前位置:</small>
eof; eof;
foreach($breadcrumbs as $bread) { foreach($breadcrumbs as $bread) {
if ($bread['id'] != $selectedId) { if ($bread['id'] != $selectedId) {
echo <<<eof echo <<<eof
<a href="{$bread['url']}">{$bread['name']}</a> / <a href="{$bread['url']}">{$bread['name']}</a> /
eof; eof;
}else { }else {
echo <<<eof echo <<<eof
<strong>{$bread['name']}</strong> <strong>{$bread['name']}</strong>
eof; eof;
} }
} }
echo <<<eof echo <<<eof
</div> </div>
eof; eof;
} }
?> ?>
<div class="content"> <div class="content">
<?php <?php
$imgExts = array('jpg', 'jpeg', 'png', 'gif'); $imgExts = array('jpg', 'jpeg', 'png', 'gif');
$videoExts = array('url', 'mp4', 'm3u8'); $videoExts = array('url');
$category = $viewData['scanResults'][$selectedId]; $category = $viewData['scanResults'][$selectedId];
//当前目录的描述介绍 //当前目录的描述介绍
if (!empty($category['description'])) { if (!empty($category['description'])) {
echo <<<eof echo <<<eof
<p class="catedesc">{$category['description']}</p> <p class="catedesc">{$category['description']}</p>
eof; eof;
} }
//当前目录的readme详细介绍 //当前目录的readme详细介绍
if (!empty($viewData['htmlCateReadme'])) { if (!empty($viewData['htmlCateReadme'])) {
echo <<<eof echo <<<eof
<div class="cateinfo markdown-body">{$viewData['htmlCateReadme']}</div> <div class="cateinfo markdown-body">{$viewData['htmlCateReadme']}</div>
eof; 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;
}
if (!empty($category['files'])) { //一级目录支持,目录下直接存放视频文件
foreach($category['directories'] as $dir) { foreach($category['files'] as $file) {
$playUrl = !empty($playBtn) ? "/view/?id={$dir['id']}" : $dir['path']; //跳过非.url文件
$openInBlank = !empty($playBtn) ? ' target="_blank"' : ''; if (!in_array($file['extension'], $videoExts) || empty($file['shortcut'])) {
echo <<<eof continue;
<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'] : '/img/default.png';
$snapshot = !empty($file['cover']) ? $imgPreffix . $file['cover'] : (!empty($category['snapshot']) ? $category['snapshot'] : $title = !empty($file['title']) ? Html::mb_substr($file['title'], 0, 20, 'utf-8') : $file['filename'];
(!empty($first_img['path']) ? $first_img['path'] : '/img/default.png')
); $platform = Html::getShareVideosPlatform($file['shortcut']['url']);
$title = !empty($file['title']) ? $file['title'] : $file['filename']; echo <<<eof
echo <<<eof <a href="{$file['shortcut']['url']}" class="img-item img-preview" target="_blank">
<a href="/view/?id={$file['id']}" class="img-item img-preview" target="_blank"> <span class="img-con video-js vjs-big-play-centered">
<span class="img-con video-js vjs-big-play-centered"> <img data-src="{$snapshot}" class="lazyload" alt="封面图 - {$title}">
<img data-src="{$snapshot}" class="lazyload" alt="snapshot of {$title}"> <span class="duration">{$platform}</span>
<span class="duration">{$duration}</span> <button class="vjs-big-play-button" type="button" title="Play Video" aria-disabled="false" style="display:none">
<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-icon-placeholder" aria-hidden="true"></span> <span class="vjs-control-text" aria-live="polite">Play Video</span>
<span class="vjs-control-text" aria-live="polite">Play Video</span> </button>
</button> </span>
</span> <strong>{$title}</strong>
<strong>{$title}</strong> </a>
</a>
eof; eof;
} }
} }
?> ?>
</div> </div>

6
themes/videoblog/controller/SiteController.php

@ -60,12 +60,12 @@ Class SiteController extends Controller {
$pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name']; $pageTitle = $defaultTitle = !empty($titles) ? $titles[0]['name'] : FSC::$app['config']['site_name'];
if (!empty($readmeFile['title'])) {
$pageTitle = "{$readmeFile['title']},来自{$defaultTitle}";
}
if (!empty($subcate)) { if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']},来自{$defaultTitle}"; $pageTitle = "{$subcate['directory']},来自{$defaultTitle}";
} }
if (!empty($readmeFile['title'])) {
$pageTitle = "{$readmeFile['title']},来自{$defaultTitle}";
}
$viewName = 'index'; $viewName = 'index';
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme'); $params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme');
return $this->render($viewName, $params, $pageTitle); return $this->render($viewName, $params, $pageTitle);

Loading…
Cancel
Save