add option of adding query string to avatar

This commit is contained in:
printempw 2016-08-07 16:56:54 +08:00
parent 03da79e482
commit c0363f5915
8 changed files with 50 additions and 18 deletions

View File

@ -234,8 +234,8 @@ class User
public function getAvatar($size) public function getAvatar($size)
{ {
// output image directly // output image directly
if (!is_null($this->eloquent_model) && $this->eloquent_model->avatar) { if (!is_null($this->eloquent_model) && $this->getAvatarId()) {
$png = \Minecraft::generateAvatarFromSkin(BASE_DIR."/textures/".Texture::find($this->eloquent_model->avatar)->hash, $size); $png = \Minecraft::generateAvatarFromSkin(BASE_DIR."/textures/".Texture::find($this->getAvatarId())->hash, $size);
header('Content-Type: image/png'); header('Content-Type: image/png');
imagepng($png); imagepng($png);
imagedestroy($png); imagedestroy($png);
@ -249,6 +249,11 @@ class User
} }
} }
public function getAvatarId()
{
return $this->eloquent_model->avatar;
}
public function setAvatar($tid) public function setAvatar($tid)
{ {
$this->eloquent_model->avatar = $tid; $this->eloquent_model->avatar = $tid;

View File

@ -52,4 +52,18 @@ class Utils
return ($timestamp == 0) ? date('Y-m-d H:i:s') : date('Y-m-d H:i:s', $timestamp); return ($timestamp == 0) ? date('Y-m-d H:i:s') : date('Y-m-d H:i:s', $timestamp);
} }
public static function getNameOrEmail(\App\Models\User $user)
{
return ($user->getNickName() == '') ? $_SESSION['email'] : $user->getNickName();
}
public static function getAvatarFname(\App\Models\User $user)
{
$fname = base64_encode($user->email).".png";
if (Option::get('avatar_query_string')) {
$fname .= '?v='.$user->getAvatarId();
}
return $fname;
}
} }

View File

@ -50,12 +50,12 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-user"></i> <i class="fa fa-user"></i>
<!-- hidden-xs hides the username on small devices so only the image appears. --> <!-- hidden-xs hides the username on small devices so only the image appears. -->
<span class="hidden-xs nickname">{{ ($user->getNickName() == '') ? $_SESSION['email'] : $user->getNickName() }}</span> <span class="hidden-xs nickname">{{ Utils::getNameOrEmail($user) }}</span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<!-- The user image in the menu --> <!-- The user image in the menu -->
<li class="user-header"> <li class="user-header">
<img src="../avatar/128/{{ base64_encode($_SESSION['email']) }}.png" alt="User Image"> <img src="../avatar/128/{{ Utils::getAvatarFname($user) }}" alt="User Image">
<p>{{ $_SESSION['email'] }}</p> <p>{{ $_SESSION['email'] }}</p>
</li> </li>
<!-- Menu Footer--> <!-- Menu Footer-->
@ -82,10 +82,10 @@
<!-- Sidebar user panel (optional) --> <!-- Sidebar user panel (optional) -->
<div class="user-panel"> <div class="user-panel">
<div class="pull-left image"> <div class="pull-left image">
<img src="../avatar/45/<?php echo base64_encode($_SESSION['email']); ?>.png" alt="User Image"> <img src="../avatar/45/{{ Utils::getAvatarFname($user) }}" alt="User Image">
</div> </div>
<div class="pull-left info"> <div class="pull-left info">
<p class="nickname">{{ ($user->getNickName() == '') ? $_SESSION['email'] : $user->getNickName() }}</p> <p class="nickname">{{ Utils::getNameOrEmail($user) }}</p>
<i class="fa fa-circle text-success"></i> Online <i class="fa fa-circle text-success"></i> Online
</div> </div>
</div> </div>

View File

@ -37,6 +37,7 @@
// pre-set user_can_register because it will not be posted if not checked // pre-set user_can_register because it will not be posted if not checked
$_POST['user_can_register'] = isset($_POST['user_can_register']) ? $_POST['user_can_register'] : "0"; $_POST['user_can_register'] = isset($_POST['user_can_register']) ? $_POST['user_can_register'] : "0";
$_POST['allow_chinese_playername'] = isset($_POST['allow_chinese_playername']) ? $_POST['allow_chinese_playername'] : "0"; $_POST['allow_chinese_playername'] = isset($_POST['allow_chinese_playername']) ? $_POST['allow_chinese_playername'] : "0";
$_POST['avatar_query_string'] = isset($_POST['avatar_query_string']) ? $_POST['avatar_query_string'] : "0";
foreach ($_POST as $key => $value) { foreach ($_POST as $key => $value) {
// remove slash if site_url is ended with slash // remove slash if site_url is ended with slash
@ -106,6 +107,17 @@
</td> </td>
</tr> </tr>
<tr>
<td class="key">头像缓存
<i class="fa fa-question-circle" title="如果对头像启用了 CDN 缓存请开启此项" data-toggle="tooltip" data-placement="top"></i>
</td>
<td class="value">
<label for="avatar_query_string">
<input {{ (Option::get('avatar_query_string') == '1') ? 'checked="true"' : '' }} type="checkbox" id="avatar_query_string" name="avatar_query_string" value="1"> 为头像添加 Query String
</label>
</td>
</tr>
<tr> <tr>
<td class="key">评论代码 <td class="key">评论代码
<i class="fa fa-question-circle" title="就是 Disqus多说畅言等评论服务提供的代码。留空以停用评论功能" data-toggle="tooltip" data-placement="top"></i> <i class="fa fa-question-circle" title="就是 Disqus多说畅言等评论服务提供的代码。留空以停用评论功能" data-toggle="tooltip" data-placement="top"></i>

View File

@ -50,14 +50,14 @@
<!-- Menu Toggle Button --> <!-- Menu Toggle Button -->
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<!-- The user image in the navbar--> <!-- The user image in the navbar-->
<img src="./avatar/25/{{ base64_encode($_SESSION['email']) }}.png" class="user-image" alt="User Image"> <img src="./avatar/25/{{ Utils::getAvatarFname($user) }}" class="user-image" alt="User Image">
<!-- hidden-xs hides the username on small devices so only the image appears. --> <!-- hidden-xs hides the username on small devices so only the image appears. -->
<span class="hidden-xs nickname">{{ ($user->getNickName() == '') ? $_SESSION['email'] : $user->getNickName() }}</span> <span class="hidden-xs nickname">{{ Utils::getNameOrEmail($user) }}</span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<!-- The user image in the menu --> <!-- The user image in the menu -->
<li class="user-header"> <li class="user-header">
<img src="./avatar/128/{{ base64_encode($_SESSION['email']) }}.png" alt="User Image"> <img src="./avatar/128/{{ Utils::getAvatarFname($user) }}" alt="User Image">
<p>{{ $_SESSION['email'] }}</p> <p>{{ $_SESSION['email'] }}</p>
</li> </li>
<!-- Menu Footer--> <!-- Menu Footer-->

View File

@ -84,14 +84,14 @@
<!-- Menu Toggle Button --> <!-- Menu Toggle Button -->
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<!-- The user image in the navbar--> <!-- The user image in the navbar-->
<img src="../avatar/25/{{ base64_encode($_SESSION['email']) }}.png" class="user-image" alt="User Image"> <img src="../avatar/25/{{ Utils::getAvatarFname($user) }}" class="user-image" alt="User Image">
<!-- hidden-xs hides the username on small devices so only the image appears. --> <!-- hidden-xs hides the username on small devices so only the image appears. -->
<span class="hidden-xs nickname">{{ ($user->getNickName() == '') ? $_SESSION['email'] : $user->getNickName() }}</span> <span class="hidden-xs nickname">{{ Utils::getNameOrEmail($user) }}</span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<!-- The user image in the menu --> <!-- The user image in the menu -->
<li class="user-header"> <li class="user-header">
<img src="../avatar/128/{{ base64_encode($_SESSION['email']) }}.png" alt="User Image"> <img src="../avatar/128/{{ Utils::getAvatarFname($user) }}" alt="User Image">
<p>{{ $_SESSION['email'] }}</p> <p>{{ $_SESSION['email'] }}</p>
</li> </li>
<!-- Menu Footer--> <!-- Menu Footer-->

View File

@ -48,12 +48,12 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown">
<i class="fa fa-user"></i> <i class="fa fa-user"></i>
<!-- hidden-xs hides the username on small devices so only the image appears. --> <!-- hidden-xs hides the username on small devices so only the image appears. -->
<span class="hidden-xs nickname">{{ ($user->getNickName() == '') ? $_SESSION['email'] : $user->getNickName() }}</span> <span class="hidden-xs nickname">{{ Utils::getNameOrEmail($user) }}</span>
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<!-- The user image in the menu --> <!-- The user image in the menu -->
<li class="user-header"> <li class="user-header">
<img src="../avatar/128/{{ base64_encode($_SESSION['email']) }}.png" alt="User Image"> <img src="../avatar/128/{{ Utils::getAvatarFname($user) }}" alt="User Image">
<p>{{ $_SESSION['email'] }}</p> <p>{{ $_SESSION['email'] }}</p>
</li> </li>
<!-- Menu Footer--> <!-- Menu Footer-->
@ -80,10 +80,10 @@
<!-- Sidebar user panel (optional) --> <!-- Sidebar user panel (optional) -->
<div class="user-panel"> <div class="user-panel">
<div class="pull-left image"> <div class="pull-left image">
<img src="../avatar/45/<?php echo base64_encode($_SESSION['email']); ?>.png" alt="User Image"> <img src="../avatar/45/{{ Utils::getAvatarFname($user) }}" alt="User Image">
</div> </div>
<div class="pull-left info"> <div class="pull-left info">
<p class="nickname">{{ ($user->getNickName() == '') ? $_SESSION['email'] : $user->getNickName() }}</p> <p class="nickname">{{ Utils::getNameOrEmail($user) }}</p>
<i class="fa fa-circle text-success"></i> Online <i class="fa fa-circle text-success"></i> Online
</div> </div>
</div> </div>

View File

@ -3,7 +3,7 @@
* @Author: printempw * @Author: printempw
* @Date: 2016-07-29 11:53:11 * @Date: 2016-07-29 11:53:11
* @Last Modified by: printempw * @Last Modified by: printempw
* @Last Modified time: 2016-07-29 13:35:57 * @Last Modified time: 2016-08-07 16:43:16
*/ */
return [ return [
@ -28,5 +28,6 @@ return [
'sign_score' => '10,100', 'sign_score' => '10,100',
'score_per_storage' => '1', 'score_per_storage' => '1',
'score_per_player' => '100', 'score_per_player' => '100',
'sign_after_zero' => '0' 'sign_after_zero' => '0',
'avatar_query_string' => '0'
]; ];