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. 103
      themes/tajian/views/site/index.php
  5. 6
      themes/videoblog/controller/SiteController.php

23
plugins/Html.php

@ -28,4 +28,27 @@ Class Html { @@ -28,4 +28,27 @@ Class Html {
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 { @@ -59,12 +59,13 @@ Class SiteController extends Controller {
}
$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}";
}
if (!empty($readmeFile['title'])) {
$pageTitle = "{$readmeFile['title']},来自{$defaultTitle}";
}
$viewName = 'index';
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme');
return $this->render($viewName, $params, $pageTitle);

67
themes/tajian/controller/ViewController.php

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

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

@ -1,6 +1,10 @@ @@ -1,6 +1,10 @@
<div class="menu">
<?php
//常用方法
require_once __DIR__ . '/../../../../plugins/Html.php';
$imgPreffix = FSC::$app['config']['content_directory'] . FSC::$app['config']['tajian']['data_dir'];
?><div class="menu">
<?php
$selectedId = $viewData['cateId'];
$breadcrumbs = !empty($viewData['breadcrumbs']) ? $viewData['breadcrumbs'] : [];
if (!empty($viewData['menus'])) { //只显示第一级目录
@ -44,7 +48,7 @@ eof; @@ -44,7 +48,7 @@ eof;
<div class="content">
<?php
$imgExts = array('jpg', 'jpeg', 'png', 'gif');
$videoExts = array('url', 'mp4', 'm3u8');
$videoExts = array('url');
$category = $viewData['scanResults'][$selectedId];
//当前目录的描述介绍
@ -61,101 +65,24 @@ eof; @@ -61,101 +65,24 @@ 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;
}
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)) {
//跳过非.url文件
if (!in_array($file['extension'], $videoExts) || empty($file['shortcut'])) {
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')
);
$snapshot = !empty($file['cover']) ? $imgPreffix . $file['cover'] : '/img/default.png';
$title = !empty($file['title']) ? Html::mb_substr($file['title'], 0, 20, 'utf-8') : $file['filename'];
$platform = Html::getShareVideosPlatform($file['shortcut']['url']);
$title = !empty($file['title']) ? $file['title'] : $file['filename'];
echo <<<eof
<a href="/view/?id={$file['id']}" class="img-item img-preview" target="_blank">
<a href="{$file['shortcut']['url']}" 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>
<img data-src="{$snapshot}" class="lazyload" alt="封面图 - {$title}">
<span class="duration">{$platform}</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>

6
themes/videoblog/controller/SiteController.php

@ -60,12 +60,12 @@ Class SiteController extends Controller { @@ -60,12 +60,12 @@ Class SiteController extends Controller {
$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}";
}
if (!empty($readmeFile['title'])) {
$pageTitle = "{$readmeFile['title']},来自{$defaultTitle}";
}
$viewName = 'index';
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'htmlCateReadme');
return $this->render($viewName, $params, $pageTitle);

Loading…
Cancel
Save