diff --git a/plugins/Html.php b/plugins/Html.php index c67646a..ea516d1 100644 --- a/plugins/Html.php +++ b/plugins/Html.php @@ -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; + } + } diff --git a/themes/tajian/controller/SiteController.php b/themes/tajian/controller/SiteController.php index 96b6038..13b8c90 100644 --- a/themes/tajian/controller/SiteController.php +++ b/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']; - 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); diff --git a/themes/tajian/controller/ViewController.php b/themes/tajian/controller/ViewController.php deleted file mode 100644 index 6d96552..0000000 --- a/themes/tajian/controller/ViewController.php +++ /dev/null @@ -1,67 +0,0 @@ -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/site/index.php b/themes/tajian/views/site/index.php index 4cf6b5d..1fe7a12 100644 --- a/themes/tajian/views/site/index.php +++ b/themes/tajian/views/site/index.php @@ -1,15 +1,19 @@ - eof; - } - } + } - if (!empty($category['files'])) { //一级目录支持,目录下直接存放视频文件 - $first_img = ''; + if (!empty($category['files'])) { //一级目录支持,目录下直接存放视频文件 - //如果目录没有封面图,则先找出第一个图片做封面 - 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) { + //跳过非.url文件 + if (!in_array($file['extension'], $videoExts) || empty($file['shortcut'])) { + continue; } - } - - 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 << - - snapshot of {$title} - {$duration} - - - {$title} - + $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']); + + echo << + + 封面图 - {$title} + {$platform} + + + {$title} + eof; - } - } - ?> + } + } + ?> diff --git a/themes/videoblog/controller/SiteController.php b/themes/videoblog/controller/SiteController.php index af0dd0e..8beb6f0 100644 --- a/themes/videoblog/controller/SiteController.php +++ b/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']; - 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);