Browse Source

add dataType support

master
filesite 4 months ago
parent
commit
8e64f39319
  1. 46
      themes/beauty/controller/ListController.php
  2. 45
      themes/beauty/controller/SiteController.php

46
themes/beauty/controller/ListController.php

@ -135,6 +135,52 @@ Class ListController extends Controller {
$pageTitle = $readmeFile['title']; $pageTitle = $readmeFile['title'];
} }
//dataType支持:[image, video]
$dataType = $this->get('dataType', 'html');
if ($dataType == 'image') {
$imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif');
$imgs = array();
$pageStartIndex = ($page-1) * $pageSize;
$index = 0;
foreach ($subcate['files'] as $id => $item) {
//翻页支持
if ($index < $pageStartIndex) {
$index ++;
continue;
}else if ($index >= $pageStartIndex + $pageSize) {
break;
}
if (in_array($item['extension'], $imgExts)) {
array_push($imgs, $item);
$index ++;
}
}
return $this->renderJson(compact('page', 'pageSize', 'imgs'));
}else if ($dataType == 'video') {
$videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8');
$videos = array();
$pageStartIndex = ($page-1) * $pageSize;
$index = 0;
foreach ($subcate['files'] as $id => $item) {
//翻页支持
if ($index < $pageStartIndex) {
$index ++;
continue;
}else if ($index >= $pageStartIndex + $pageSize) {
break;
}
if (in_array($item['extension'], $videoExts)) {
array_push($videos, $item);
$index ++;
}
}
return $this->renderJson(compact('page', 'pageSize', 'videos'));
}
$viewName = '//site/index'; //共享视图 $viewName = '//site/index'; //共享视图
$params = compact( $params = compact(
'cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme', 'cateId', 'dirTree', 'scanResults', 'menus', 'htmlReadme', 'breadcrumbs', 'htmlCateReadme',

45
themes/beauty/controller/SiteController.php

@ -137,6 +137,51 @@ Class SiteController extends Controller {
$copyright = $readmeFile['copyright']; $copyright = $readmeFile['copyright'];
} }
//dataType支持:[image, video]
$dataType = $this->get('dataType', 'html');
if ($dataType == 'image') {
$imgExts = !empty(FSC::$app['config']['supportedImageExts']) ? FSC::$app['config']['supportedImageExts'] : array('jpg', 'jpeg', 'png', 'webp', 'gif');
$imgs = array();
$pageStartIndex = ($page-1) * $pageSize;
$index = 0;
foreach ($scanResults as $id => $item) {
//翻页支持
if ($index < $pageStartIndex) {
$index ++;
continue;
}else if ($index >= $pageStartIndex + $pageSize) {
break;
}
if (in_array($item['extension'], $imgExts)) {
array_push($imgs, $item);
$index ++;
}
}
return $this->renderJson(compact('page', 'pageSize', 'imgs'));
}else if ($dataType == 'video') {
$videoExts = !empty(FSC::$app['config']['supportedVideoExts']) ? FSC::$app['config']['supportedVideoExts'] : array('mp4', 'mov', 'm3u8');
$videos = array();
$pageStartIndex = ($page-1) * $pageSize;
$index = 0;
foreach ($scanResults as $id => $item) {
//翻页支持
if ($index < $pageStartIndex) {
$index ++;
continue;
}else if ($index >= $pageStartIndex + $pageSize) {
break;
}
if (in_array($item['extension'], $videoExts)) {
array_push($videos, $item);
$index ++;
}
}
return $this->renderJson(compact('page', 'pageSize', 'videos'));
}
$viewName = 'index'; $viewName = 'index';
$params = compact( $params = compact(
'page', 'pageSize', 'cacheDataId', 'page', 'pageSize', 'cacheDataId',

Loading…
Cancel
Save