Browse Source

improve small image option switch

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

6
controller/CommandController.php

@ -35,6 +35,12 @@ eof; @@ -35,6 +35,12 @@ eof;
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";
if (file_exists($config_file)) {

38
themes/beauty/controller/SiteController.php

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

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

@ -189,6 +189,9 @@ eof; @@ -189,6 +189,9 @@ eof;
if (in_array($first_img['extension'], $imgExts)) {
$imgUrl = urlencode($first_img['path']);
$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
<img src="/img/beauty/lazy.svg"
data-id="{$first_img['id']}"
@ -265,6 +268,9 @@ eof; @@ -265,6 +268,9 @@ eof;
if (in_array($file['extension'], $imgExts)) {
$imgUrl = urlencode($file['path']);
$smallUrl = "/site/smallimg/?id={$file['id']}&url={$imgUrl}";
if (empty(FSC::$app['config']['enableSmallImage']) || FSC::$app['config']['enableSmallImage'] === 'false') {
$smallUrl = $file['path'];
}
echo <<<eof
<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"

Loading…
Cancel
Save