Browse Source

improve small image option switch

master
filesite 4 months ago
parent
commit
8cd43cf36a
  1. 6
      controller/CommandController.php
  2. 24
      themes/beauty/controller/SiteController.php
  3. 6
      themes/beauty/views/site/index.php

6
controller/CommandController.php

@ -35,6 +35,12 @@ eof;
throw new Exception("缺少key参数!", 403); throw new Exception("缺少key参数!", 403);
} }
//val数据格式转换
if ($param_value === 'false') {
$param_value = false;
}else if ($param_value === 'true') {
$param_value = true;
}
$config_file = __DIR__ . "/../runtime/custom_config.json"; $config_file = __DIR__ . "/../runtime/custom_config.json";
if (file_exists($config_file)) { if (file_exists($config_file)) {

24
themes/beauty/controller/SiteController.php

@ -185,6 +185,13 @@ Class SiteController extends Controller {
$cacheSubDir = 'dir'; $cacheSubDir = 'dir';
$cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir); $cachedData = Common::getCacheFromFile($cacheKey, $expireSeconds, $cacheSubDir);
//如果关闭缩略图
if (empty(FSC::$app['config']['enableSmallImage']) || FSC::$app['config']['enableSmallImage'] === 'false') {
if (!empty($cachedData) && !empty($cachedData['size']) && $cachedData['size'] == 'small') {
$cachedData = null;
}
}
if (empty($cachedData)) { if (empty($cachedData)) {
//从缓存数据中获取目录的realpath //从缓存数据中获取目录的realpath
$cachedData = Common::getCacheFromFile($cacheId); $cachedData = Common::getCacheFromFile($cacheId);
@ -218,8 +225,10 @@ Class SiteController extends Controller {
}else { }else {
$url = $imgFile['path']; $url = $imgFile['path'];
$img_id = $imgFile['id']; $img_id = $imgFile['id'];
$size = 'orignal';
//小尺寸图片支持 //小尺寸图片支持
if (!empty(FSC::$app['config']['enableSmallImage']) && FSC::$app['config']['enableSmallImage'] !== 'false') {
$cacheKey_smimg = $this->getCacheKey($imgFile['id'], 'imgsm'); $cacheKey_smimg = $this->getCacheKey($imgFile['id'], 'imgsm');
$expireSeconds = FSC::$app['config']['screenshot_expire_seconds']; //有效期3650天 $expireSeconds = FSC::$app['config']['screenshot_expire_seconds']; //有效期3650天
$cacheSubDir = 'image'; $cacheSubDir = 'image';
@ -227,10 +236,12 @@ Class SiteController extends Controller {
if (!empty($cachedData)) { if (!empty($cachedData)) {
$url = $cachedData; $url = $cachedData;
$img_id = ''; //无需再次生成小尺寸图片 $img_id = ''; //无需再次生成小尺寸图片
$size = 'small';
}
} }
$cacheSubDir = 'dir'; $cacheSubDir = 'dir';
Common::saveCacheToFile($cacheKey, compact('url', 'img_id'), $cacheSubDir); Common::saveCacheToFile($cacheKey, compact('url', 'img_id', 'size'), $cacheSubDir);
} }
}else { }else {
$code = 0; $code = 0;
@ -259,7 +270,13 @@ Class SiteController extends Controller {
$cacheKey = $this->getCacheKey($cateId, 'snap'); $cacheKey = $this->getCacheKey($cateId, 'snap');
$img_id = ''; //为保持数据格式一致,图片id传空 $img_id = ''; //为保持数据格式一致,图片id传空
$cacheSubDir = 'dir'; $cacheSubDir = 'dir';
$saved = Common::saveCacheToFile($cacheKey, compact('url', 'img_id'), $cacheSubDir);
$size = 'orignal';
if (!empty(FSC::$app['config']['enableSmallImage']) && FSC::$app['config']['enableSmallImage'] !== 'false') {
$size = 'small';
}
$saved = Common::saveCacheToFile($cacheKey, compact('url', 'img_id', 'size'), $cacheSubDir);
if ($saved !== false) { if ($saved !== false) {
$code = 1; $code = 1;
@ -314,7 +331,8 @@ Class SiteController extends Controller {
$cacheKey = $this->getCacheKey($cateId, 'snap'); $cacheKey = $this->getCacheKey($cateId, 'snap');
$img_id = ''; //为保持数据格式一致,图片id传空 $img_id = ''; //为保持数据格式一致,图片id传空
$cacheSubDir = 'dir'; $cacheSubDir = 'dir';
Common::saveCacheToFile($cacheKey, array('url' => $imgData, 'img_id' => $img_id), $cacheSubDir); $size = 'small';
Common::saveCacheToFile($cacheKey, array('url' => $imgData, 'img_id' => $img_id, 'size' => $size), $cacheSubDir);
} }
$cacheKey = $this->getCacheKey($imgId, 'imgsm'); $cacheKey = $this->getCacheKey($imgId, 'imgsm');

6
themes/beauty/views/site/index.php

@ -189,6 +189,9 @@ eof;
if (in_array($first_img['extension'], $imgExts)) { if (in_array($first_img['extension'], $imgExts)) {
$imgUrl = urlencode($first_img['path']); $imgUrl = urlencode($first_img['path']);
$smallUrl = "/site/smallimg/?id={$first_img['id']}&url={$imgUrl}"; $smallUrl = "/site/smallimg/?id={$first_img['id']}&url={$imgUrl}";
if (empty(FSC::$app['config']['enableSmallImage']) || FSC::$app['config']['enableSmallImage'] === 'false') {
$smallUrl = $first_img['path'];
}
echo <<<eof echo <<<eof
<img src="/img/beauty/lazy.svg" <img src="/img/beauty/lazy.svg"
data-id="{$first_img['id']}" data-id="{$first_img['id']}"
@ -265,6 +268,9 @@ eof;
if (in_array($file['extension'], $imgExts)) { if (in_array($file['extension'], $imgExts)) {
$imgUrl = urlencode($file['path']); $imgUrl = urlencode($file['path']);
$smallUrl = "/site/smallimg/?id={$file['id']}&url={$imgUrl}"; $smallUrl = "/site/smallimg/?id={$file['id']}&url={$imgUrl}";
if (empty(FSC::$app['config']['enableSmallImage']) || FSC::$app['config']['enableSmallImage'] === 'false') {
$smallUrl = $file['path'];
}
echo <<<eof echo <<<eof
<div class="im_item bor_radius col-xs-6 col-sm-4 col-md-3 col-lg-2"> <div class="im_item bor_radius col-xs-6 col-sm-4 col-md-3 col-lg-2">
<a href="javascript:;" class="bor_radius" data-fancybox="gallery" <a href="javascript:;" class="bor_radius" data-fancybox="gallery"

Loading…
Cancel
Save