add placeholders for comment script

This commit is contained in:
printempw 2016-08-11 12:47:02 +08:00
parent d4623f453d
commit 7d7432a374
4 changed files with 33 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -5,6 +5,7 @@
@section('style')
<style type="text/css">
.box-body > textarea { height: 200px; }
.description { margin: 7px 0 0 0; color: #555; }
</style>
@endsection
@ -123,7 +124,8 @@
<i class="fa fa-question-circle" title="就是 Disqus多说畅言等评论服务提供的代码。留空以停用评论功能" data-toggle="tooltip" data-placement="top"></i>
</td>
<td class="value">
<textarea class="form-control" rows="4" name="comment_script">{{ Option::get('comment_script') }}</textarea>
<textarea class="form-control" rows="6" name="comment_script">{{ Option::get('comment_script') }}</textarea>
<p class="description">评论代码内可使用占位符,<code>{tid}</code> 将会被自动替换为材质的 id<code>{name}</code> 会被替换为材质名称,<code>{url}</code> 会被替换为当前页面地址。</p>
</td>
</tr>
</tbody>
@ -151,6 +153,7 @@
} ?>
<textarea name="announcement" class="form-control" rows="3">{{ Option::get('announcement') }}</textarea>
<p class="description">站点公告内容不会被转义,因此您可以使用 HTML 进行排版</p>
</div><!-- /.box-body -->
<div class="box-footer">

View File

@ -74,7 +74,7 @@
<tr>
<td class="key">发布时间:</td>
<td class="value">
{{ date('Y-m-d H:i:s', $updater->getUpdateInfo()['releases'][$updater->current_version]['release_time']) }}
{{ @date('Y-m-d H:i:s', $updater->getUpdateInfo()['releases'][$updater->current_version]['release_time']) }}
</td>
</tr>
</tbody>

View File

@ -144,9 +144,10 @@
<h3 class="box-title">评论区</h3>
</div><!-- /.box-header -->
<div class="box-body">
<div id="disqus_thread"></div>
@if (Option::get('comment_script') != "")
{!! Option::get('comment_script') !!}
<!-- Comment Start -->
{!! Utils::getStringReplaced(Option::get('comment_script'), ['{tid}' => $texture->tid, '{name}' => $texture->name, '{url}' => Http::getCurrentUrl()]) !!}
<!-- Comment End -->
@else
<p style="text-align: center; margin: 30px 0;">本站未开启评论服务</p>
@endif