From dd19f1b39567e7c4b69c0bd1d0f845fb693b251a Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 27 May 2024 10:33:46 +0800 Subject: [PATCH] image add cdn support --- conf/app.php | 3 +++ plugins/Html.php | 10 ++++++++++ themes/tajian/views/my/favs.php | 2 +- themes/tajian/views/site/index.php | 2 +- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/conf/app.php b/conf/app.php index 8ab7bfa..6d4f8b3 100644 --- a/conf/app.php +++ b/conf/app.php @@ -130,6 +130,9 @@ $configs = array( 'service_3rd_api_key' => '你的密钥', 'sms_code_cache_time' => 600, //短信验证码缓存时长,单位:秒 + //图片cdn加速域名配置 + 'img_cdn_budget_url' => '', + //Google Analytics MEASUREMENT ID 'GA_MEASUREMENT_ID' => 'G-09MWT3Z9R0', diff --git a/plugins/Html.php b/plugins/Html.php index d67f778..08523ce 100644 --- a/plugins/Html.php +++ b/plugins/Html.php @@ -120,4 +120,14 @@ eof; return $tmp_arr; } + //获取用户图片的cdn地址 + public static function getCDNImageUrl($localImgUrl) { + if (!empty(FSC::$app['config']['debug'])) {return $localImgUrl;} + + $cdn = FSC::$app['config']['img_cdn_budget_url']; + if (empty($cdn)) {return $localImgUrl;} + + return "{$cdn}{$localImgUrl}"; + } + } diff --git a/themes/tajian/views/my/favs.php b/themes/tajian/views/my/favs.php index 8758d25..6c376c1 100644 --- a/themes/tajian/views/my/favs.php +++ b/themes/tajian/views/my/favs.php @@ -47,7 +47,7 @@ $allTags = Html::getTagNames($viewData['tags']); continue; } - $snapshot = !empty($file['cover']) ? $imgPreffix . $file['cover'] : '/img/default.png'; + $snapshot = !empty($file['cover']) ? Html::getCDNImageUrl($imgPreffix . $file['cover']) : '/img/default.png'; $title = !empty($file['title']) ? Html::mb_substr($file['title'], 0, 33, 'utf-8') : $file['filename']; $platform = Html::getShareVideosPlatform($file['shortcut']['url']); diff --git a/themes/tajian/views/site/index.php b/themes/tajian/views/site/index.php index 0637019..e21df94 100644 --- a/themes/tajian/views/site/index.php +++ b/themes/tajian/views/site/index.php @@ -56,7 +56,7 @@ eof; continue; } - $snapshot = !empty($file['cover']) ? $imgPreffix . $file['cover'] : '/img/default.png'; + $snapshot = !empty($file['cover']) ? Html::getCDNImageUrl($imgPreffix . $file['cover']) : '/img/default.png'; $title = !empty($file['title']) ? Html::mb_substr($file['title'], 0, 33, 'utf-8') : $file['filename']; $platform = Html::getShareVideosPlatform($file['shortcut']['url']);