ridding more prefetched variables

This commit is contained in:
flash 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 // 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); return Config::get($name);
})); }));

View file

@ -425,6 +425,16 @@ class User
return $this->lastOnline > (time() - Config::get('max_online_time')); 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. * Get a few forum statistics.
* *

View file

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

View file

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

View file

@ -55,7 +55,7 @@
"minUserLen": {{ config('username_min_length') }}, "minUserLen": {{ config('username_min_length') }},
"maxUserLen": {{ config('username_max_length') }}, "maxUserLen": {{ config('username_max_length') }},
"minPwdEntropy": {{ config('min_entropy') }}, "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>
<ul class="user-menu"> <ul class="user-menu">
<li class="nav-usermenu"> <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>
<div class="nav-username"{% if session.checkLogin %} style="color: {{ user.colour }};"{% endif %}> <div class="nav-username"{% if user.isActive %} style="color: {{ user.colour }};"{% endif %}>
{% if session.checkLogin %}{{ user.username }} <span class="nav-user-dropdown"></span>{% else %}Guest{% endif %} {% if user.isActive %}{{ user.username }} <span class="nav-user-dropdown"></span>{% else %}Guest{% endif %}
</div> </div>
<div class="nav-userstats"> <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>
</div> </div>
</a> </a>
{% if session.checkLogin %} {% if user.isActive %}
<ul> <ul>
<li><a href="{{ urls.format('USER_PROFILE', [user.id]) }}">My Profile</a></li> <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> <li><a href="{{ urls.format('SETTING_CAT', ['messages']) }}">Private Messages</a></li>
@ -112,7 +112,7 @@
</ul> </ul>
{% endif %} {% endif %}
</li> </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> </ul>
</div> </div>

View file

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

View file

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

View file

@ -1,5 +1,5 @@
<div id="indexPanel"> <div id="indexPanel">
{% if session.checkLogin %} {% if user.isActive %}
<div class="user-container" style="background-image: url({{ route('user.header', user.id) }});"> <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="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"> <div class="user-container-info">

View file

@ -87,7 +87,7 @@
<div class="userdata"> <div class="userdata">
<div class="usertitle">{{ post.poster.title }}</div> <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 %} <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"> <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) %} {% 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> <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') }}, "minUserLen": {{ config('username_min_length') }},
"maxUserLen": {{ config('username_max_length') }}, "maxUserLen": {{ config('username_max_length') }},
"minPwdEntropy": {{ config('min_entropy') }}, "minPwdEntropy": {{ config('min_entropy') }},
"checkLogin": {{ session.checkLogin ? 'true' : 'false' }} "checkLogin": {{ user.isActive ? 'true' : 'false' }}
}; };
// Set cookie prefix and path // 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-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-list" href="{{ route('forums.index') }}" title="Forums"></a>
<a class="menu-item fa-search" href="{{ route('main.search') }}" title="Search"></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-users" href="{{ route('members.index') }}" title="Members"></a>
<a class="menu-item fa-heart" href="{{ route('premium.index') }}" title="Support us"></a> <a class="menu-item fa-heart" href="{{ route('premium.index') }}" title="Support us"></a>
{% endif %} {% endif %}
</div> </div>
<div class="menu-ucp" id="navMenuUser"> <div class="menu-ucp" id="navMenuUser">
<!-- User menu, displayed on right side of the bar. --> <!-- 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 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>#} {#<a class="menu-item fa-envelope" href="#" title="Messages"></a>#}
{% if user.permission(constant('Sakura\\Perms\\Manage::USE_MANAGE'), constant('Sakura\\Perms::MANAGE')) %} {% 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) %} {% 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> <div id="userBackground" style="background-image: url('{{ route('file.background', (profile is defined ? profile : user).id) }}');"></div>
{% endif %} {% endif %}
{% if not session.checkLogin and sakura.currentPage != route('auth.login') %} {% if not user.isActive and sakura.currentPage != route('auth.login') %}
<div class="headerLoginContainer"> <div class="headerLoginContainer">
<form method="post" action="{{ route('auth.login') }}" id="headerLoginForm"> <form method="post" action="{{ route('auth.login') }}" id="headerLoginForm">
<input type="hidden" name="redirect" value="{{ sakura.currentPage }}" /> <input type="hidden" name="redirect" value="{{ sakura.currentPage }}" />
@ -173,7 +173,7 @@
</div> </div>
<div class="footer"> <div class="footer">
<div class="ftsections"> <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"> <ul class="ftsection">
<li class="fthead">General</li> <li class="fthead">General</li>
<li><a href="{{ route('main.index') }}">Home</a></li> <li><a href="{{ route('main.index') }}">Home</a></li>
@ -266,7 +266,7 @@
friendClient.start(HTTPMethods.POST); friendClient.start(HTTPMethods.POST);
} }
</script> </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" src="https://sakura.flash.moe/?get=all&amp;limit=5&amp;variable=true"></script>
<script type="text/javascript"> <script type="text/javascript">
// Column colours for actions // Column colours for actions
@ -295,7 +295,7 @@
var _cllink = document.createElement('a'); var _cllink = document.createElement('a');
_cllink.className = 'underline'; _cllink.className = 'underline';
_cllink.target = '_blank'; _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 // Append everything
_cllink.appendChild(document.createTextNode('Changelog')); _cllink.appendChild(document.createTextNode('Changelog'));

View file

@ -90,7 +90,7 @@
</div> </div>
</div> </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"> <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);" /> <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> </div>
@ -103,13 +103,13 @@
</div> </div>
<div class="clear"></div> <div class="clear"></div>
</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> <h1 style="text-align: center; margin: 1em auto;" class="stylised">You can't get Tenshi at the current moment!</h1>
{% else %} {% else %}
<h1 style="text-align: center; margin: 1em auto;" class="stylised">You need to be logged in to get Tenshi!</h1> <h1 style="text-align: center; margin: 1em auto;" class="stylised">You need to be logged in to get Tenshi!</h1>
{% endif %} {% endif %}
</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')) %}
<form action="{{ route('premium.purchase') }}" method="post" id="purchaseForm" class="hidden"> <form action="{{ route('premium.purchase') }}" method="post" id="purchaseForm" class="hidden">
<input type="hidden" name="mode" value="purchase" /> <input type="hidden" name="mode" value="purchase" />
<input type="hidden" name="time" value="{{ date().timestamp }}" /> <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-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> <a class="fa fa-comments-o" title="View {{ profile.username }}'s profile comments" href="#_comments" onclick="profileMode('comments');"></a>
</div> </div>
{% if session.checkLogin %} {% if user.isActive %}
<div class="new-profile-actions"> <div class="new-profile-actions">
{% if user.id == profile.id %} {% if user.id == profile.id %}
<a class="fa fa-pencil-square-o" title="Edit your profile" href="{{ route('settings.general.profile') }}"></a> <a class="fa fa-pencil-square-o" title="Edit your profile" href="{{ route('settings.general.profile') }}"></a>
@ -162,7 +162,7 @@
</table> </table>
<hr class="default" /> <hr class="default" />
{% if profile.profileFields or user.permission(constant('Sakura\\Perms\\Manage::USE_MANAGE'), constant('Sakura\\Perms::MANAGE')) %} {% 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%;"> <table style="width: 100%;">
{% for name,field in profile.profileFields %} {% for name,field in profile.profileFields %}
<tr> <tr>