summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBigCoke233 <hi@guhub.cn>2020-07-14 16:01:49 +0800
committerBigCoke233 <hi@guhub.cn>2020-07-14 16:01:49 +0800
commit0615f62964b26f5d2f54da3c9262a1ea17df41ce (patch)
treea88fa7033911be612d12c635fd14b514c3290c60
parentd75331d8b8816f0806ca324b550483cbadaf656f (diff)
:poop: Fix: 自定义随机图失效
-rw-r--r--functions.php11
-rw-r--r--index.php2
-rw-r--r--libs/Utils.php12
3 files changed, 16 insertions, 9 deletions
diff --git a/functions.php b/functions.php
index 796a4f2..8e62dce 100644
--- a/functions.php
+++ b/functions.php
@@ -1,5 +1,8 @@
-<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
-<?php
+<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit;
+/**
+ * Miracles 核心文件
+ */
+
require_once("themeConfig.php");
require_once("libs/Utils.php");
require_once("libs/Contents.php");
@@ -25,7 +28,9 @@ function themeInit($archive) {
Helper::options()->commentsMaxNestingLevels = '9999';//最大嵌套层数
Helper::options()->commentsPageDisplay = 'first';//强制评论第一页
Helper::options()->commentsOrder = 'DESC';//将最新的评论展示在前
- Helper::options()->commentsCheckReferer = false;//关闭检查评论来源URL与文章链接是否一致判断(否则会无法评论)
+ Helper::options()->commentsCheckReferer = false;//关闭检查评论来源URL与文章链接是否一致判断(否则会无法评论)
+ //将设置储存到全局变量以便使用
+ $GLOBALS['miraclesOptions_randomBanner'] = Helper::options()->randomBanner;
}
/**
diff --git a/index.php b/index.php
index ed79ec9..f2de215 100644
--- a/index.php
+++ b/index.php
@@ -22,7 +22,7 @@ $this->need('includes/header.php');
<div class="col-md-6 post-banner-box">
<a href="<?php $this->permalink(); ?>" class="post-link">
<div class="post-banner">
- <img src="<?php Utils::indexTheme('images/loading/'.$this->options->loading_image.'.gif') ?>" data-gisrc="<?php Utils::postBanner($this, $post->options->randomBanner); ?>">
+ <img src="<?php Utils::indexTheme('images/loading/'.$this->options->loading_image.'.gif') ?>" data-gisrc="<?php Utils::postBanner($this); ?>">
</div>
</a>
</div>
diff --git a/libs/Utils.php b/libs/Utils.php
index b78aa06..3d62f77 100644
--- a/libs/Utils.php
+++ b/libs/Utils.php
@@ -157,18 +157,18 @@ class Utils
/**
* 缩略图
*/
- public static function postBanner($post, $random){
+ public static function postBanner($post){
if($post->fields->banner && $post->fields->banner=!''):
$banner = $post->fields->banner;
else:
- if($random==''){
+ if($GLOBALS['miraclesOptions_randomBanner']==''){
$banner = '/usr/themes/Miracles/images/postbg/';
$banner .= srand(mb_strlen($post->title));
- $banner .= rand(1,15).'.jpg';
+ $banner .= mt_rand(1,15).'.jpg';
}
else{
- $banner_url = explode(',',$random);
- $banner = $banner_url[mt_rand(0,count($banner_url)-1)].'\"';
+ $banner_url = explode(',', $GLOBALS['miraclesOptions_randomBanner']);
+ $banner = $banner_url[mt_rand(0,count($banner_url)-1)];
}
endif;
//使用 TimThumb 剪裁
@@ -192,6 +192,8 @@ class Utils
$banner_url = '/usr/themes/Miracles/libs/TimThumb.php';
$banner = $banner_url.'?src='.$banner.$banner_size;
}
+ //不知道为什么会有奇怪的空格,所以这里用暴力的方法去掉
+ $banner = trim($banner);
echo $banner;
}