ridding more prefetched variables

This commit is contained in:
Pachira 2016-04-02 17:59:45 +02:00
parent e242567a3c
commit 6d1a06039f
12 changed files with 41 additions and 37 deletions

View file

@ -99,7 +99,11 @@ class Template
}));
// Add config function
self::$engine->addFunction(new Twig_SimpleFunction('config', function ($name) {
self::$engine->addFunction(new Twig_SimpleFunction('config', function ($name, $local = false) {
if ($local) {
$name = explode('.', $name);
return Config::local($name[0], $name[1]);
}
return Config::get($name);
}));

View file

@ -425,6 +425,16 @@ class User
return $this->lastOnline > (time() - Config::get('max_online_time'));
}
/**
* Runs some checks to see if this user is activated.
*
* @return bool Are they activated?
*/
public function isActive()
{
return $this->id !== 0 && !$this->permission(Site::DEACTIVATED);
}
/**
* Get a few forum statistics.
*

View file

@ -8,7 +8,7 @@ namespace Sakura;
// Check if logged out
Router::filter('logoutCheck', function () {
if (ActiveUser::$user->id !== 0) {
if (ActiveUser::$user->isActive()) {
$message = "You must be logged out to do that!";
Template::vars(['page' => compact('message')]);
@ -19,8 +19,7 @@ Router::filter('logoutCheck', function () {
// Check if logged in
Router::filter('loginCheck', function () {
if (ActiveUser::$user->id === 0
|| ActiveUser::$user->permission(Perms\Site::DEACTIVATED)) {
if (!ActiveUser::$user->isActive()) {
$message = "You must be logged in to do that!";
Template::vars(['page' => compact('message')]);

View file

@ -102,20 +102,11 @@ if (!defined('SAKURA_NO_TPL')) {
// Set base page rendering data
Template::vars([
'sakura' => [
'versionInfo' => [
'version' => SAKURA_VERSION,
],
'dev' => [
'showChangelog' => Config::local('dev', 'show_changelog'),
],
'currentPage' => $_SERVER['REQUEST_URI'] ?? null,
'referrer' => $_SERVER['HTTP_REFERER'] ?? null,
],
'session' => array_merge([
'checkLogin' => ActiveUser::$user->id && !ActiveUser::$user->permission(Perms\Site::DEACTIVATED),
'sessionId' => ActiveUser::$session->sessionId,
], $_SESSION),

View file

@ -55,7 +55,7 @@
"minUserLen": {{ config('username_min_length') }},
"maxUserLen": {{ config('username_max_length') }},
"minPwdEntropy": {{ config('min_entropy') }},
"checkLogin": {% if session.checkLogin %}true{% else %}false{% endif %}
"checkLogin": {% if user.isActive %}true{% else %}false{% endif %}
};
@ -92,17 +92,17 @@
</ul>
<ul class="user-menu">
<li class="nav-usermenu">
<a href="{% if session.checkLogin %}javascript:void(0);{% else %}{{ urls.format('SITE_LOGIN') }}{% endif %}">
<a href="{% if user.isActive %}javascript:void(0);{% else %}{{ urls.format('SITE_LOGIN') }}{% endif %}">
<div>
<div class="nav-username"{% if session.checkLogin %} style="color: {{ user.colour }};"{% endif %}>
{% if session.checkLogin %}{{ user.username }} <span class="nav-user-dropdown"></span>{% else %}Guest{% endif %}
<div class="nav-username"{% if user.isActive %} style="color: {{ user.colour }};"{% endif %}>
{% if user.isActive %}{{ user.username }} <span class="nav-user-dropdown"></span>{% else %}Guest{% endif %}
</div>
<div class="nav-userstats">
{% if session.checkLogin %}<span class="fa fa-envelope"></span> 0 / <span class="fa fa-user-plus"></span> 0 / <span class="fa fa-warning"></span> 0 / <span class="fa fa-reply"></span> 0{% else %}Please log in to proceed!{% endif %}
{% if user.isActive %}<span class="fa fa-envelope"></span> 0 / <span class="fa fa-user-plus"></span> 0 / <span class="fa fa-warning"></span> 0 / <span class="fa fa-reply"></span> 0{% else %}Please log in to proceed!{% endif %}
</div>
</div>
</a>
{% if session.checkLogin %}
{% if user.isActive %}
<ul>
<li><a href="{{ urls.format('USER_PROFILE', [user.id]) }}">My Profile</a></li>
<li><a href="{{ urls.format('SETTING_CAT', ['messages']) }}">Private Messages</a></li>
@ -112,7 +112,7 @@
</ul>
{% endif %}
</li>
<li><a href="{% if session.checkLogin %}{{ urls.format('USER_PROFILE', [user.id]) }}{% else %}{{ urls.format('SITE_LOGIN') }}{% endif %}"><img src="{{ config('content_path') }}/pixel.png" alt="{{ user.username }}" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [user.id]) }}');" class="nav-avatar" /></a></li>
<li><a href="{% if user.isActive %}{{ urls.format('USER_PROFILE', [user.id]) }}{% else %}{{ urls.format('SITE_LOGIN') }}{% endif %}"><img src="{{ config('content_path') }}/pixel.png" alt="{{ user.username }}" style="background-image: url('{{ urls.format('IMAGE_AVATAR', [user.id]) }}');" class="nav-avatar" /></a></li>
</ul>
</div>

View file

@ -87,7 +87,7 @@
</div>
</div>
{% endif %}
{% if session.checkLogin %}
{% if user.isActive %}
<div class="profilePlatform userActions">
<div class="inner">
<ul class="actions">
@ -104,7 +104,7 @@
{% endif %}
<div class="profilePlatform userAccounts">
<div class="inner">
{% if session.checkLogin %}
{% if user.isActive %}
{% if profile.profileFields %}
{% for name,field in profile.profileFields %}
<div class="field">

View file

@ -1,6 +1,6 @@
<div id="comments">
<div class="comment-input-section">
{% if session.checkLogin %}
{% if user.isActive %}
<div class="comment">
<div class="comment-avatar" style="background-image: url('{{ route('file.avatar', user.id) }}');"></div>
<div class="comment-pointer"></div>

View file

@ -1,5 +1,5 @@
<div id="indexPanel">
{% if session.checkLogin %}
{% if user.isActive %}
<div class="user-container" style="background-image: url({{ route('user.header', user.id) }});">
<div class="default-avatar-setting user-container-avatar" style="background-image: url({{ route('file.avatar', user.id) }}); box-shadow: 0 0 5px {{ user.colour }};"><a href="{{ route('settings.appearance.avatar') }}" class="clean" style="display: block; height: 100%; width: 100%;"></a></div>
<div class="user-container-info">

View file

@ -87,7 +87,7 @@
<div class="userdata">
<div class="usertitle">{{ post.poster.title }}</div>
<img src="{{ config('content_path') }}/images/tenshi.png" alt="Tenshi"{% if not post.poster.isPremium %} style="opacity: 0;"{% endif %} /> <img src="{{ config('content_path') }}/images/flags/{{ post.poster.country|lower }}.png" alt="{{ post.poster.country(true) }}" />{% if post.poster.id == (thread.posts|first).poster.id %} <img src="{{ config('content_path') }}/images/op.png" alt="OP" title="Original Poster" />{% endif %}
{% if session.checkLogin %}
{% if user.isActive %}
<div class="actions">
{% if (user.id == post.poster.id and forum.permission(constant('Sakura\\Perms\\Forum::EDIT_OWN'), user.id)) or forum.permission(constant('Sakura\\Perms\\Forum::EDIT_ANY'), user.id) %}
<a class="fa fa-pencil-square-o" title="Edit this post" href="javascript:void(0);" onclick="editPost({{ post.id }});"></a>

View file

@ -55,7 +55,7 @@
"minUserLen": {{ config('username_min_length') }},
"maxUserLen": {{ config('username_max_length') }},
"minPwdEntropy": {{ config('min_entropy') }},
"checkLogin": {{ session.checkLogin ? 'true' : 'false' }}
"checkLogin": {{ user.isActive ? 'true' : 'false' }}
};
// Set cookie prefix and path
@ -86,14 +86,14 @@
<a class="menu-item fa-commenting" href="{{ route('main.infopage', 'chat') }}" title="Chat"></a>
<a class="menu-item fa-list" href="{{ route('forums.index') }}" title="Forums"></a>
<a class="menu-item fa-search" href="{{ route('main.search') }}" title="Search"></a>
{% if session.checkLogin %}
{% if user.isActive %}
<a class="menu-item fa-users" href="{{ route('members.index') }}" title="Members"></a>
<a class="menu-item fa-heart" href="{{ route('premium.index') }}" title="Support us"></a>
{% endif %}
</div>
<div class="menu-ucp" id="navMenuUser">
<!-- User menu, displayed on right side of the bar. -->
{% if session.checkLogin %}
{% if user.isActive %}
<a class="menu-item avatar" href="{{ route('user.profile', user.id) }}" title="Logged in as {{ user.username }}" style="background-image: url('{{ route('file.avatar', user.id) }}'); width: auto; color: {{ user.colour }}; border-color: {{ user.colour }}; font-weight: 700;"></a>
{#<a class="menu-item fa-envelope" href="#" title="Messages"></a>#}
{% if user.permission(constant('Sakura\\Perms\\Manage::USE_MANAGE'), constant('Sakura\\Perms::MANAGE')) %}
@ -117,7 +117,7 @@
{% if profile is defined ? profile.background : (user.permission(constant('Sakura\\Perms\\Site::CHANGE_BACKGROUND')) and user.optionFields.profileBackgroundSiteWide and user.background) %}
<div id="userBackground" style="background-image: url('{{ route('file.background', (profile is defined ? profile : user).id) }}');"></div>
{% endif %}
{% if not session.checkLogin and sakura.currentPage != route('auth.login') %}
{% if not user.isActive and sakura.currentPage != route('auth.login') %}
<div class="headerLoginContainer">
<form method="post" action="{{ route('auth.login') }}" id="headerLoginForm">
<input type="hidden" name="redirect" value="{{ sakura.currentPage }}" />
@ -173,7 +173,7 @@
</div>
<div class="footer">
<div class="ftsections">
<div class="copycentre">Powered by <a href="https://github.com/flashwave/sakura/" target="_blank">Sakura</a>{% if sakura.dev.showChangelog %} <a href="https://sakura.flash.moe/#r{{ sakura.versionInfo.version }}" target="_blank">r{{ sakura.versionInfo.version }}</a>{% endif %} &copy; 2013-2016 <a href="http://flash.moe/" target="_blank">Flashwave</a></div>
<div class="copycentre">Powered by <a href="https://github.com/flashwave/sakura/" target="_blank">Sakura</a>{% if config('dev.show_changelog', true) %} <a href="https://sakura.flash.moe/#r{{ constant('SAKURA_VERSION') }}" target="_blank">r{{ constant('SAKURA_VERSION') }}</a>{% endif %} &copy; 2013-2016 <a href="http://flash.moe/" target="_blank">Flashwave</a></div>
<ul class="ftsection">
<li class="fthead">General</li>
<li><a href="{{ route('main.index') }}">Home</a></li>
@ -266,7 +266,7 @@
friendClient.start(HTTPMethods.POST);
}
</script>
{% if sakura.dev.showChangelog and stats %}
{% if config('dev.show_changelog', true) and stats %}
<script type="text/javascript" src="https://sakura.flash.moe/?get=all&amp;limit=5&amp;variable=true"></script>
<script type="text/javascript">
// Column colours for actions
@ -295,7 +295,7 @@
var _cllink = document.createElement('a');
_cllink.className = 'underline';
_cllink.target = '_blank';
_cllink.href = 'https://sakura.flash.moe/#r{{ sakura.versionInfo.version }}';
_cllink.href = 'https://sakura.flash.moe/#r{{ constant('SAKURA_VERSION') }}';
// Append everything
_cllink.appendChild(document.createTextNode('Changelog'));

View file

@ -90,7 +90,7 @@
</div>
</div>
</div>
{% if session.checkLogin and user.permission(constant('Sakura\\Perms\\Site::OBTAIN_PREMIUM')) %}
{% if user.isActive and user.permission(constant('Sakura\\Perms\\Site::OBTAIN_PREMIUM')) %}
<div class="slider">
<input class="inputStyling" type="range" min="1" max="{{ amountLimit }}" value="1" onchange="document.getElementById('monthsNo').value = this.value; document.getElementById('monthNoBtn').innerHTML = this.value; document.getElementById('monthsTrailingS').innerHTML = (this.value == 1 ? '' : 's'); document.getElementById('totalAmount').innerHTML = (this.value * {{ price }}).formatMoney(2);" />
</div>
@ -103,13 +103,13 @@
</div>
<div class="clear"></div>
</div>
{% elseif session.checkLogin %}
{% elseif user.isActive %}
<h1 style="text-align: center; margin: 1em auto;" class="stylised">You can't get Tenshi at the current moment!</h1>
{% else %}
<h1 style="text-align: center; margin: 1em auto;" class="stylised">You need to be logged in to get Tenshi!</h1>
{% endif %}
</div>
{% if session.checkLogin and user.permission(constant('Sakura\\Perms\\Site::OBTAIN_PREMIUM')) %}
{% if user.isActive and user.permission(constant('Sakura\\Perms\\Site::OBTAIN_PREMIUM')) %}
<form action="{{ route('premium.purchase') }}" method="post" id="purchaseForm" class="hidden">
<input type="hidden" name="mode" value="purchase" />
<input type="hidden" name="time" value="{{ date().timestamp }}" />

View file

@ -108,7 +108,7 @@
{#<a class="fa fa-users" title="View {{ profile.username }}'s groups" href="#_groups" onclick="profileMode('groups');"></a>#}
<a class="fa fa-comments-o" title="View {{ profile.username }}'s profile comments" href="#_comments" onclick="profileMode('comments');"></a>
</div>
{% if session.checkLogin %}
{% if user.isActive %}
<div class="new-profile-actions">
{% if user.id == profile.id %}
<a class="fa fa-pencil-square-o" title="Edit your profile" href="{{ route('settings.general.profile') }}"></a>
@ -162,7 +162,7 @@
</table>
<hr class="default" />
{% if profile.profileFields or user.permission(constant('Sakura\\Perms\\Manage::USE_MANAGE'), constant('Sakura\\Perms::MANAGE')) %}
{% if session.checkLogin %}
{% if user.isActive %}
<table style="width: 100%;">
{% for name,field in profile.profileFields %}
<tr>