Browse Source

improve list controller and view for videos

master
filesite 2 years ago
parent
commit
752b23dc87
  1. 18
      lib/DirScanner.php
  2. 17
      themes/videoblog/controller/ListController.php
  3. 60
      themes/videoblog/controller/ViewController.php
  4. 38
      themes/videoblog/views/site/index.php

18
lib/DirScanner.php

@ -249,13 +249,25 @@ Class DirScanner { @@ -249,13 +249,25 @@ Class DirScanner {
}
//合并描述文件内容到md文件或者目录数据
//增加视频文件:mp4, m3u8描述文件支持
private function mergeDescriptionData($realpath) {
$data = [];
$ext = $this->parseDescriptionFiles($realpath);
//try to find the md file
$targetFile = preg_replace('/_?[a-z0-9]+\.txt$/iU', '.md', $realpath);
if (file_exists($targetFile)) {
$targetFile = '';
$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);
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;
}
if (!empty($targetFile)) {
$fileId = $this->getId($targetFile);
if (empty($this->scanResults[$fileId])) {
$ext['id'] = $fileId;
@ -508,7 +520,7 @@ Class DirScanner { @@ -508,7 +520,7 @@ Class DirScanner {
if (is_dir($realpath)) {
$files = [];
if ($nextLevels >= 0) {
$files = $this->scan($realpath, $nextLevels);
$files = $this->scan($realpath, $levels);
if (!empty($files)) {
foreach($files as $file) {
$this->scanResults[$file['id']] = $file;

17
themes/videoblog/controller/ListController.php

@ -11,12 +11,13 @@ Class ListController extends Controller { @@ -11,12 +11,13 @@ Class ListController extends Controller {
//获取数据
$scanner = new DirScanner();
$scanner->setWebRoot(FSC::$app['config']['content_directory']);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 4);
$dirTree = $scanner->scan(__DIR__ . '/../../../www/' . FSC::$app['config']['content_directory'], 3);
$scanResults = $scanner->getScanResults();
//获取目录
$menus = $scanner->getMenus();
$cateId = $this->get('id', $menus[0]['id']);
//print_r($menus);exit;
$titles = [];
$htmlReadme = '';
@ -32,7 +33,7 @@ Class ListController extends Controller { @@ -32,7 +33,7 @@ Class ListController extends Controller {
//获取目录面包屑
$subcate = $scanResults[$cateId];
$breadcrumbs = $this->getBreadcrumbs($menus, $subcate);
$breadcrumbs = $this->getBreadcrumbs($scanResults, $subcate);
//获取当前目录下的readme
$htmlCateReadme = '';
@ -66,13 +67,15 @@ Class ListController extends Controller { @@ -66,13 +67,15 @@ Class ListController extends Controller {
'url' => $subcate['path'],
]);
$foundKey = array_search($subcate['pid'], array_column($menus, 'id'));
if ($foundKey !== false) {
$parent = !empty($menus[$subcate['pid']]) ? $menus[$subcate['pid']] : null;
while($parent) {
array_unshift($breads, [
'id' => $menus[$foundKey]['id'],
'name' => $menus[$foundKey]['directory'],
'url' => $menus[$foundKey]['path'],
'id' => $parent['id'],
'name' => $parent['directory'],
'url' => $parent['path'],
]);
$parent = !empty($menus[$parent['pid']]) ? $menus[$parent['pid']] : null;
}
return $breads;

60
themes/videoblog/controller/ViewController.php

@ -0,0 +1,60 @@ @@ -0,0 +1,60 @@
<?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() {
//获取数据
$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();
$cateId = $this->get('id', $menus[0]['id']);
$titles = [];
$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);
}
//获取目录面包屑
$subcate = $scanResults[$cateId];
$breadcrumbs = $this->getBreadcrumbs($menus, $subcate);
//获取当前目录下的readme
$htmlCateReadme = '';
$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 = !empty($titles) ? $titles[0]['name'] : "FileSite.io - 无数据库、基于文件和目录的Markdown文档、网址导航、图书、图片、视频网站PHP开源系统";
if (!empty($subcate)) {
$pageTitle = "{$subcate['directory']}的照片,来自{$pageTitle}";
if (!empty($subcate['title'])) {
$pageTitle = $subcate['title'];
}
}
$viewName = '//site/index'; //共享视图
$params = compact('cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme');
return $this->render($viewName, $params, $pageTitle);
}
}

38
themes/videoblog/views/site/index.php

@ -43,6 +43,7 @@ eof; @@ -43,6 +43,7 @@ eof;
<div class="content">
<?php
$imgExts = ['jpg', 'jpeg', 'png', 'gif'];
$videoExts = ['mp4', 'm3u8'];
$category = $viewData['scanResults'][$selectedId];
//当前目录的描述介绍
@ -60,10 +61,24 @@ eof; @@ -60,10 +61,24 @@ eof;
}
if (!empty($category['directories'])) { //两级目录支持
//如果已经是二级目录了,则当三级目录为视频目录,打开播放网页
$playBtnCls = '';
$playBtn = '';
if (!empty($selectedId)) {
$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) {
echo <<<eof
<a href="{$dir['path']}" class="img-item">
<span class="img-con video-js vjs-big-play-centered">
<span class="img-con{$playBtnCls}">
eof;
if (!empty($dir['snapshot'])) {
@ -96,10 +111,7 @@ eof; @@ -96,10 +111,7 @@ eof;
$title = !empty($dir['title']) ? $dir['title'] : $dir['directory'];
echo <<<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>
{$playBtn}
</span>
<strong>{$title}</strong>
</a>
@ -107,17 +119,25 @@ eof; @@ -107,17 +119,25 @@ eof;
}
}
if (!empty($category['files'])) { //一级目录支持
if (!empty($category['files'])) { //一级目录支持,目录下直接存放视频文件
$first_img = '';
foreach($category['files'] as $file) {
if (!in_array($file['extension'], $imgExts)) {continue;}
if (!in_array($file['extension'], $videoExts)) {
//如果是最后一层视频目录,取第一张图片做封面
if (empty($first_img) && empty($category['snapshot']) && in_array($file['extension'], $imgExts)) {
$first_img = $file;
}
continue;
}
$duration = !empty($category['duration']) ? $category['duration'] : '';
$snapshot = !empty($file['snapshot']) ? $file['snapshot'] : (!empty($category['snapshot']) ? $category['snapshot'] : $first_img['path']);
$title = !empty($file['title']) ? $file['title'] : $file['filename'];
$title = !empty($category['title']) ? $category['title'] : $file['filename'];
echo <<<eof
<a href="{$file['path']}" class="img-item img-preview" target="_blank">
<span class="img-con video-js vjs-big-play-centered">
<img data-src="{$file['path']}" class="lazyload" alt="{$file['filename']}">
<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>

Loading…
Cancel
Save