diff --git a/conf/app.php b/conf/app.php index 80ec874..f43b130 100644 --- a/conf/app.php +++ b/conf/app.php @@ -49,6 +49,9 @@ $configs = array( 'supportedImageExts' => array('jpg', 'jpeg', 'png', 'webp', 'gif'), ), + 'supportedImageExts' => array('jpg', 'jpeg', 'png', 'webp', 'gif'), + 'supportedVideoExts' => array('mp4', 'mov', 'm3u8'), + /* //视频皮肤配置 'videoblog' => array( diff --git a/lib/DirScanner.php b/lib/DirScanner.php index 70595f7..6d492dd 100644 --- a/lib/DirScanner.php +++ b/lib/DirScanner.php @@ -282,7 +282,7 @@ Class DirScanner { } //合并描述文件内容到md文件或者目录数据 - //增加视频文件:mp4, m3u8描述文件支持 + //增加视频文件:mp4, mov, m3u8描述文件支持 //增加.url文件支持 private function mergeDescriptionData($realpath) { $data = array(); @@ -292,12 +292,15 @@ Class DirScanner { $targetFile = ''; $targetFile_md = preg_replace('/_?[a-z0-9]+\.txt$/U', '.md', $realpath); $targetFile_mp4 = preg_replace('/_?[a-z0-9]+\.txt$/U', '.mp4', $realpath); + $targetFile_mov = preg_replace('/_?[a-z0-9]+\.txt$/U', '.mov', $realpath); $targetFile_m3u8 = preg_replace('/_?[a-z0-9]+\.txt$/U', '.m3u8', $realpath); $targetFile_url = preg_replace('/_?[a-z0-9]+\.txt$/U', '.url', $realpath); if (file_exists($targetFile_md)) { $targetFile = $targetFile_md; }else if (file_exists($targetFile_mp4)) { $targetFile = $targetFile_mp4; + }else if (file_exists($targetFile_mov)) { + $targetFile = $targetFile_mov; }else if (file_exists($targetFile_m3u8)) { $targetFile = $targetFile_m3u8; }else if (file_exists($targetFile_url)) { @@ -399,6 +402,7 @@ Class DirScanner { 'ico' => "{$webRoot}{$directory}{$filename}.{$extension}", 'mp3' => "{$webRoot}{$directory}{$filename}.{$extension}", 'mp4' => "{$webRoot}{$directory}{$filename}.{$extension}", + 'mov' => "{$webRoot}{$directory}{$filename}.{$extension}", 'ts' => "{$webRoot}{$directory}{$filename}.{$extension}", ); diff --git a/themes/beauty/controller/ListController.php b/themes/beauty/controller/ListController.php index 7d8cd75..6250922 100644 --- a/themes/beauty/controller/ListController.php +++ b/themes/beauty/controller/ListController.php @@ -85,7 +85,6 @@ Class ListController extends Controller { $scanResults = array($cateId => $currentDir); //重新组装数据 } - //非首页统一从缓存获取目录数据,有效期 1 小时 $cacheKey = $this->getCacheKey('all', 'menu', $maxScanDeep); $menus = Common::getCacheFromFile($cacheKey, 3600); diff --git a/themes/beauty/controller/SiteController.php b/themes/beauty/controller/SiteController.php index e8ceb03..217937c 100644 --- a/themes/beauty/controller/SiteController.php +++ b/themes/beauty/controller/SiteController.php @@ -173,6 +173,15 @@ Class SiteController extends Controller { $imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif'); $url = $scanner->getSnapshotImage($realpath, $imgExts); + + //支持视频目录 + if (empty($url)) { + $videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8'); + $firstVideoPath = $scanner->getSnapshotImage($realpath, $videoExts); + if (!empty($firstVideoPath)) { + $url = '/img/beauty/video_dir.png'; + } + } }else { $code = 0; $msg = '缓存数据已失效,请刷新网页'; @@ -182,4 +191,23 @@ Class SiteController extends Controller { return $this->renderJson(compact('code', 'msg', 'url')); } + public function actionPlayer() { + $videoUrl = $this->get('url', ''); + if (empty($videoUrl)) { + throw new Exception("缺少视频地址url参数!", 403); + } + + $arr = parse_url($videoUrl); + $videoFilename = basename($arr['path']); + + + $pageTitle = "视频播放器"; + $this->layout = 'player'; + $viewName = 'player'; + $params = compact( + 'videoUrl', 'videoFilename' + ); + return $this->render($viewName, $params, $pageTitle); + } + } diff --git a/themes/beauty/views/layout/player.php b/themes/beauty/views/layout/player.php new file mode 100644 index 0000000..348210b --- /dev/null +++ b/themes/beauty/views/layout/player.php @@ -0,0 +1,57 @@ + + + + + <?php echo $pageTitle; ?> + + + + + + + + + + + + +
+ + + + +
+ + + + + + + + + + \ No newline at end of file diff --git a/themes/beauty/views/site/index.php b/themes/beauty/views/site/index.php index d7bfcc9..202dbd1 100644 --- a/themes/beauty/views/site/index.php +++ b/themes/beauty/views/site/index.php @@ -58,11 +58,13 @@ eof; '; } + //显示图片、视频 if (!empty($category['files'])) { //一级目录支持 $pageStartIndex = ($viewData['page']-1) * $viewData['pageSize']; $index = 0; foreach ($category['files'] as $file) { - if (empty($file['extension']) || !in_array($file['extension'], $imgExts)) { + if (empty($file['extension']) || !in_array($file['extension'], $supportedExts)) { continue; } @@ -212,7 +215,8 @@ eof; } if ($index > 0) { - echo << {$file['filename']} @@ -224,8 +228,26 @@ eof; eof; + }else if (in_array($file['extension'], $videoExts)) { //输出视频 + $videoUrl = urlencode($file['path']); + echo << + + {$file['filename']} +
+ + {$title} + +
+
+ +eof; + } + + } else { - echo << {$file['filename']} @@ -237,6 +259,21 @@ eof; eof; + }else if (in_array($file['extension'], $videoExts)) { //输出视频 + $videoUrl = urlencode($file['path']); + echo << + + {$file['filename']} +
+ + {$title} + +
+
+ +eof; + } } $index++; diff --git a/themes/beauty/views/site/player.php b/themes/beauty/views/site/player.php new file mode 100644 index 0000000..474ed3a --- /dev/null +++ b/themes/beauty/views/site/player.php @@ -0,0 +1,38 @@ + + + + +
+ +
\ No newline at end of file diff --git a/www/css/beauty.css b/www/css/beauty.css index 3cb7392..a8ad0cd 100644 --- a/www/css/beauty.css +++ b/www/css/beauty.css @@ -75,7 +75,7 @@ a:link{text-decoration:none} .im_img:hover{transform:scale(1.03)} .im_item{padding:5px;height:16vw;overflow:hidden} .im_item>a{overflow: hidden;display:block;position:relative;width: 100%;height: 100%} -.im_img_title{background:rgba(7, 7, 7, .1);position:absolute;left:0;right:0;bottom:0;top:0;color:#DDD;border-radius:10px} +.im_img_title{background:rgba(7, 7, 7, .1);position:absolute;left:0;right:0;bottom:0;top:0;color:#EEE;border-radius:10px} .im_img_title span{position:absolute;bottom:10px;left:10px;margin-right:10px;font-weight:bold;padding:3px;border:solid 1px #DDD;border-radius:6px;font-size:13px} .im_img_title .right-bottom{left:auto;right:5px;bottom:5px;margin-right:0;padding:0 2px;font-size:11px;border:0 none;font-weight:300;color:#CCC} .im_img_title img{vertical-align:bottom} @@ -123,6 +123,10 @@ a:link{text-decoration:none} #qrimg{width:160px;height:160px;margin:0 auto 20px auto;background-color:#FFF;padding:5px;border:1px solid #EEE;border-radius:5px} +.videoplayer{max-width:800px;margin:0 auto;text-align:center} +.videoplayer video{width:100%} +.videotitle{max-width:600px;overflow:hidden;text-wrap:nowrap;text-overflow:ellipsis} + @media screen and (max-width: 1199px) { .im_item { height: 23vw; @@ -144,6 +148,7 @@ a:link{text-decoration:none} .img_main{margin-left:0} .pagination>li>a, .pagination>li>span{padding:3px 7px} + .videotitle{max-width:55%} } @keyframes musicTurn { diff --git a/www/img/beauty/video_dir.png b/www/img/beauty/video_dir.png new file mode 100644 index 0000000..817573b Binary files /dev/null and b/www/img/beauty/video_dir.png differ diff --git a/www/img/beauty/video_snap.jpg b/www/img/beauty/video_snap.jpg new file mode 100644 index 0000000..0b79a1a Binary files /dev/null and b/www/img/beauty/video_snap.jpg differ diff --git a/www/js/beauty.js b/www/js/beauty.js index 2422697..6540adf 100644 --- a/www/js/beauty.js +++ b/www/js/beauty.js @@ -65,123 +65,124 @@ if ($('#image_site').get(0)) { }, 500); }); +} - // 白天黑夜模式切换 - var saveLanpnumToLocalstorage = function(lanpnum) { - try { - var key = 'user_lanpnum'; - localStorage.setItem(key, lanpnum); - }catch(err) { - console.error('保存本地存储失败', err); - } - }; - - var getLanpnumFromLocalstorage = function() { - try { - var key = 'user_lanpnum'; - return localStorage.getItem(key); - }catch(err) { - console.error('保存本地存储失败', err); - } - - return false; - }; - - var toggleLampshow = function(lanpnum) { - if (lanpnum == 1) { - $('#markdowncss').attr('href', '/css/github-markdown-dark.css'); - $(document.body).addClass('lampshow'); - $('#image_site .navbarJS').removeClass('navbar-default').addClass('navbar-inverse'); // 导航栏用bootstrap主题切换 - } else if (lanpnum == 0) { - $('#markdowncss').attr('href', '/css/github-markdown-light.css'); - $(document.body).removeClass('lampshow'); - $('#image_site .navbarJS').addClass('navbar-default').removeClass('navbar-inverse'); - } - }; - var lanpnum = getLanpnumFromLocalstorage(); - if (lanpnum !== false) { - toggleLampshow(lanpnum); +// 白天黑夜模式切换 +var saveLanpnumToLocalstorage = function(lanpnum) { + try { + var key = 'user_lanpnum'; + localStorage.setItem(key, lanpnum); + }catch(err) { + console.error('保存本地存储失败', err); + } +}; + +var getLanpnumFromLocalstorage = function() { + try { + var key = 'user_lanpnum'; + return localStorage.getItem(key); + }catch(err) { + console.error('保存本地存储失败', err); } - $('#image_site .lampJS').click(function () { - lanpnum = !lanpnum || lanpnum != 1 ? 1 : 0; - toggleLampshow(lanpnum); - saveLanpnumToLocalstorage(lanpnum); - }); - //异步加载目录的封面图 - $('.dir_item').each(function(index, el) { - var cid = $(el).attr('data-cid'), id = $(el).attr('data-id'); - if ($(el).find('.im_img').length == 0) { - $.ajax({ - url: '/site/dirsnap', - method: 'POST', - dataType: 'json', - data: { - cid: cid, - id: id - } - }).done(function(data) { - if (data.code == 1 && data.url) { - $(el).find('.im_img_title').before(''); - }else { - console.warn('目录 %s 里没有任何图片', id); - } - }).fail(function(jqXHR, textStatus, errorThrown) { - console.error('获取封面图失败,错误信息:' + errorThrown); - }); - } - }); + return false; +}; + +var toggleLampshow = function(lanpnum) { + if (lanpnum == 1) { + $('#markdowncss').attr('href', '/css/github-markdown-dark.css'); + $(document.body).addClass('lampshow'); + $('.navbarJS').removeClass('navbar-default').addClass('navbar-inverse'); // 导航栏用bootstrap主题切换 + } else if (lanpnum == 0) { + $('#markdowncss').attr('href', '/css/github-markdown-light.css'); + $(document.body).removeClass('lampshow'); + $('.navbarJS').addClass('navbar-default').removeClass('navbar-inverse'); + } +}; - //刷新缓存 - $('.cleanCacheJS').click(function () { +var lanpnum = getLanpnumFromLocalstorage(); +if (lanpnum !== false) { + toggleLampshow(lanpnum); +} +$('.lampJS').click(function () { + lanpnum = !lanpnum || lanpnum != 1 ? 1 : 0; + toggleLampshow(lanpnum); + saveLanpnumToLocalstorage(lanpnum); +}); + +//异步加载目录的封面图 +$('.dir_item').each(function(index, el) { + var cid = $(el).attr('data-cid'), id = $(el).attr('data-id'); + if ($(el).find('.im_img').length == 0) { $.ajax({ - url: '/site/cleancache', + url: '/site/dirsnap', + method: 'POST', dataType: 'json', - method: 'POST' + data: { + cid: cid, + id: id + } }).done(function(data) { - if (data.code == 1) { - location.href = '/'; + if (data.code == 1 && data.url) { + $(el).find('.im_img_title').before(''); }else { - alert('缓存清空失败,请稍后重试,错误信息:' + data.msg); + console.warn('目录 %s 里没有任何图片', id); } }).fail(function(jqXHR, textStatus, errorThrown) { - alert('请求失败,请稍后重试,错误信息:' + errorThrown); + console.error('获取封面图失败,错误信息:' + errorThrown); }); + } +}); + + +//刷新缓存 +$('.cleanCacheJS').click(function () { + $.ajax({ + url: '/site/cleancache', + dataType: 'json', + method: 'POST' + }).done(function(data) { + if (data.code == 1) { + location.href = '/'; + }else { + alert('缓存清空失败,请稍后重试,错误信息:' + data.msg); + } + }).fail(function(jqXHR, textStatus, errorThrown) { + alert('请求失败,请稍后重试,错误信息:' + errorThrown); }); - - // 音乐播放 - if ($('#music_main').length > 0) { - var musicState = 0; - $('#music_main').get(0).volume = 0.5; // 控制音量 - $('.musicJS').click(function () { - if (musicState == 0) { - $('#music_main').get(0).play(); - $('.musicJS').addClass('music_put'); - musicState = 1; - } else { - $('#music_main').get(0).pause(); - $('.musicJS').removeClass('music_put'); - musicState = 0; - } - return; - }) - - $(document).one('touchstart mousedown', function () { +}); + +// 音乐播放 +if ($('#music_main').length > 0) { + var musicState = 0; + $('#music_main').get(0).volume = 0.5; // 控制音量 + $('.musicJS').click(function () { + if (musicState == 0) { $('#music_main').get(0).play(); $('.musicJS').addClass('music_put'); musicState = 1; - }); - } - - //二维码显示 - if ($('#qrimg').length > 0 && typeof(QRCode) != 'undefined') { - var qrcode = new QRCode("qrimg", { - text: location.href, - colorDark : "#000000", - colorLight : "#ffffff", - correctLevel : QRCode.CorrectLevel.H - }); - } + } else { + $('#music_main').get(0).pause(); + $('.musicJS').removeClass('music_put'); + musicState = 0; + } + return; + }) + $(document).one('touchstart mousedown', function () { + $('#music_main').get(0).play(); + $('.musicJS').addClass('music_put'); + musicState = 1; + }); } + +//二维码显示 +if ($('#qrimg').length > 0 && typeof(QRCode) != 'undefined') { + var qrcode = new QRCode("qrimg", { + text: location.href, + colorDark : "#000000", + colorLight : "#ffffff", + correctLevel : QRCode.CorrectLevel.L + }); +} \ No newline at end of file