From 7d7432a374a9db0bf19e2d4ca33845f4daec723e Mon Sep 17 00:00:00 2001 From: printempw Date: Thu, 11 Aug 2016 12:47:02 +0800 Subject: [PATCH] add placeholders for comment script --- app/Services/Utils.php | 30 +++++++++++++++++++++++++----- resources/views/admin/options.tpl | 5 ++++- resources/views/admin/update.tpl | 2 +- resources/views/skinlib/show.tpl | 5 +++-- 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/app/Services/Utils.php b/app/Services/Utils.php index da42c795..92b76af4 100644 --- a/app/Services/Utils.php +++ b/app/Services/Utils.php @@ -20,14 +20,11 @@ class Utils * Get the value of key in an array if index exist * * @param string $key - * @param array $array + * @param array $array * @return string|boolean */ public static function getValue($key, $array) { - if (array_key_exists($key, $array)) { - return $array[$key]; - } - return false; + return array_key_exists($key, $array) ? $array[$key] : false; } /** @@ -66,6 +63,14 @@ class Utils return $fname; } + /** + * Generate omitted string + * + * @param string $str + * @param int $length + * @param boolean $append + * @return string + */ public static function getStringOmitted($str, $length, $append = true) { $str = trim($str); @@ -96,4 +101,19 @@ class Utils return $newstr; } + /** + * Replace content of string according to given rules + * + * @param string $str + * @param array $rules + * @return string + */ + public function getStringReplaced($str, $rules) + { + foreach ($rules as $search => $replace) { + $str = str_replace($search, $replace, $str); + } + return $str; + } + } diff --git a/resources/views/admin/options.tpl b/resources/views/admin/options.tpl index a943c789..67c2e70c 100644 --- a/resources/views/admin/options.tpl +++ b/resources/views/admin/options.tpl @@ -5,6 +5,7 @@ @section('style') @endsection @@ -123,7 +124,8 @@ - + +

评论代码内可使用占位符,{tid} 将会被自动替换为材质的 id,{name} 会被替换为材质名称,{url} 会被替换为当前页面地址。

@@ -151,6 +153,7 @@ } ?> +

站点公告内容不会被转义,因此您可以使用 HTML 进行排版

-
@if (Option::get('comment_script') != "") - {!! Option::get('comment_script') !!} + + {!! Utils::getStringReplaced(Option::get('comment_script'), ['{tid}' => $texture->tid, '{name}' => $texture->name, '{url}' => Http::getCurrentUrl()]) !!} + @else

本站未开启评论服务

@endif