summaryrefslogtreecommitdiffstats
path: root/libs/Utils.php
diff options
context:
space:
mode:
authorBigCoke233 <hi@guhub.cn>2020-07-11 12:11:04 +0800
committerBigCoke233 <hi@guhub.cn>2020-07-11 12:11:04 +0800
commit5331ab525ff834b860778abfdc8a69cdc5ed783a (patch)
treec473944051cba410ae301c72b41d0bd7a8b7df34 /libs/Utils.php
parenta46bff318c2278eab5e616c49163bb0335b4099b (diff)
:pizza: Add: 允许使用 TimThumb 剪裁文章缩略图 #51
Diffstat (limited to 'libs/Utils.php')
-rw-r--r--libs/Utils.php42
1 files changed, 42 insertions, 0 deletions
diff --git a/libs/Utils.php b/libs/Utils.php
index 34ac4fe..541e46d 100644
--- a/libs/Utils.php
+++ b/libs/Utils.php
@@ -153,4 +153,46 @@ class Utils
->limit(1));
echo '一切开始于 '.date('Y-m-d', $content['created']);
}
+
+ /**
+ * 缩略图
+ */
+ public static function postBanner($post){
+ if($post->fields->banner && $post->fields->banner=!''):
+ $banner = $post->fields->banner;
+ else:
+ if($post->options->randomBanner==''){
+ $banner = '/usr/themes/Miracles/images/postbg/';
+ $banner .= srand(mb_strlen($post->title));
+ $banner .= rand(1,15).'.jpg';
+ }
+ else{
+ $banner_url = explode(',',$post->options->randomBanner);
+ $banner = $banner_url[mt_rand(0,count($banner_url)-1)].'\"';
+ }
+ endif;
+ //使用 TimThumb 剪裁
+ if($GLOBALS['miraclesIfTimThumb']=='on') {
+ if($GLOBALS['miraclesIfTimThumbSize']=='regular'){
+ $banner_size = '&h=336&w=564';
+ }
+ elseif($GLOBALS['miraclesIfTimThumbSize']=='big'){
+ $banner_size = '&h=420&w=705';
+ }
+ elseif($GLOBALS['miraclesIfTimThumbSize']=='large'){
+ $banner_size = '&h=504&w=846';
+ }
+ elseif($GLOBALS['miraclesIfTimThumbSize']=='huge'){
+ $banner_size = '&h=560&w=940';
+ }
+ else{
+ //避免有憨憨打错单词,当成 big 来算
+ $banner_size = '&h=420&w=705';
+ }
+ $banner_url = '/usr/themes/Miracles/libs/TimThumb.php';
+ $banner = $banner_url.'?src='.$banner.$banner_size;
+ }
+
+ echo $banner;
+ }
} \ No newline at end of file