Some non-related updates

This commit is contained in:
flash 2016-03-24 19:28:32 +01:00
parent 86c4ac9c05
commit a9bae24479
9 changed files with 198 additions and 49 deletions

View file

@ -197,10 +197,12 @@ class AuthController extends Controller
->orWhere('last_ip', Net::pton(Net::IP()))
->get();
Template::vars([
'haltRegistration' => count($getUserIP) > 1,
'haltName' => $getUserIP[array_rand($getUserIP)]->username,
]);
if ($getUserIP) {
Template::vars([
'haltRegistration' => count($getUserIP) > 1,
'haltName' => $getUserIP[array_rand($getUserIP)]->username,
]);
}
return Template::render('main/register');
}

View file

@ -16,7 +16,6 @@ use Sakura\Perms\Forum as ForumPerms;
use Sakura\Router;
use Sakura\Template;
use Sakura\User;
use Sakura\Users;
/**
* Forum page controllers.
@ -33,24 +32,85 @@ class ForumController extends Controller
*/
public function index()
{
// Merge index specific stuff with the global render data
Template::vars([
'forum' => (new Forum()),
'stats' => [
'userCount' => DB::table('users')
->where('password_algo', '!=', 'disabled')
->whereNotIn('rank_main', [1, 10])
->count(),
'newestUser' => User::construct(Users::getNewestUserId()),
'lastRegDate' => date_diff(
date_create(date('Y-m-d', User::construct(Users::getNewestUserId())->registered)),
date_create(date('Y-m-d'))
)->format('%a'),
'topicCount' => DB::table('topics')->count(),
'postCount' => DB::table('posts')->count(),
'onlineUsers' => Users::checkAllOnline(),
],
]);
global $currentUser;
// Get the most active threads
$activeThreadsIds = DB::table('posts')
->groupBy('topic_id')
->orderByRaw('COUNT(*) DESC')
->limit(10)
->get(['topic_id']);
$activeThreads = [];
while (list($_n, $_t) = each($activeThreadsIds)) {
// Create the thread object
$thread = new Thread($_t->topic_id);
// Create a forum object
$forum = new Forum($thread->forum);
// Check if we have permission to view it
if (!$forum->permission(ForumPerms::VIEW, $currentUser->id)) {
$fetch = DB::table('posts')
->groupBy('topic_id')
->orderByRaw('COUNT(*) DESC')
->skip(11 + $_n)
->take(1)
->get(['topic_id']);
if ($fetch) {
$activeThreadsIds[] = $fetch[0];
}
continue;
}
$activeThreads[$thread->id] = $thread;
}
// Get the latest posts
$latestPostsIds = DB::table('posts')
->orderBy('post_id', 'desc')
->limit(10)
->get(['post_id']);
$latestPosts = [];
while (list($_n, $_p) = each($latestPostsIds)) {
// Create new post object
$post = new Post($_p->post_id);
// Forum id
$forum = new Forum($post->forum);
// Check if we have permission to view it
if (!$forum->permission(ForumPerms::VIEW, $currentUser->id)) {
$fetch = DB::table('posts')
->orderBy('post_id', 'desc')
->skip(11 + $_n)
->take(1)
->get(['post_id']);
if ($fetch) {
$latestPostsIds[] = $fetch[0];
}
continue;
}
$latestPosts[$post->id] = $post;
}
// Get the most active poster
$activePosterId = DB::table('posts')
->where('post_time', '>', time() - (24 * 60 * 60))
->groupBy('poster_id')
->orderByRaw('COUNT(*) DESC')
->limit(1)
->get(['poster_id']);
$activePoster = User::construct($activePosterId[0]->poster_id);
// Create the forum object
$forum = new Forum;
Template::vars(compact('forum', 'activeThreads', 'latestPosts', 'activePoster'));
// Return the compiled page
return Template::render('forum/index');

View file

@ -109,8 +109,6 @@ class UserController extends Controller
}
// Get all ranks
// Execute query
$getRanks = DB::table('ranks')
->get(['rank_id']);

View file

@ -233,4 +233,29 @@ class Post
->where('post_id', $this->id)
->delete();
}
/**
* Check if a user has read this post before.
*
* @param mixed $user The id of the user in question.
*
* @return bool A boolean indicating the read status.
*/
public function unread($user)
{
// Attempt to get track row from the database
$track = DB::table('topics_track')
->where('user_id', $user)
->where('topic_id', $this->thread)
->where('mark_time', '>', $this->time)
->count();
// If nothing was returned it's obvious that the status is unread
if (!$track) {
return true;
}
// Else just return false meaning everything is read
return false;
}
}

View file

@ -190,6 +190,7 @@ class Rank
// Fetch all users part of this rank
$get = DB::table('user_ranks')
->where('rank_id', $this->id)
->orderBy('user_id')
->get(['user_id']);
// Filter the user ids into one array

View file

@ -251,14 +251,8 @@ a.default:active {
width: 334px;
}
.content-left .head,
.news .head,
.support .head,
.viewforum .head,
.viewtopic .head,
.posting .head,
.loginPage .head,
.messages .head {
.content .head,
.loginPage .head {
margin: -1px -2px;
padding: 4px 5px 5px;
font-weight: 700;
@ -1321,13 +1315,12 @@ a.default:active {
}
.new-profile .new-profile-avatar {
margin: 0;
height: 190px;
width: 190px;
margin: 0 2px;
flex-grow: 0;
flex-shrink: 0;
background: no-repeat center center / cover transparent;
background: no-repeat center center / cover #FFF;
}
.new-profile .new-profile-username {
@ -2517,3 +2510,27 @@ button.forumbtn {
#comments ul > li > ul .comment > textarea.comment-content {
height: 40px;
}
/*
* User container
*/
.user-container {
display: flex;
align-items: center;
background: no-repeat center center / cover transparent;
}
.user-container-avatar {
height: 100px;
width: 100px;
margin: 0 2px;
flex-grow: 0;
flex-shrink: 0;
background: no-repeat center center / cover #FFF;
}
.user-container-info {
background: rgba(211, 191, 255, .8);
width: 100%;
padding: 0 5px;
}

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20160320');
define('SAKURA_VERSION', 20160324);
// Define Sakura Path
define('ROOT', __DIR__ . '/');
@ -103,7 +103,7 @@ $currentUser = User::construct($authCheck[0]);
// Create the Urls object
$urls = new Urls();
// Prepare the name of the template to load (outside of SAKURA_NO_TPL because it's used in imageserve.php)
// Prepare the name of the template to load
$templateName =
!defined('SAKURA_MANAGE')
&& isset($currentUser->optionFields()['useMisaki'])

View file

@ -1,12 +1,15 @@
<div id="indexPanel">
{% if session.checkLogin %}
<div class="head">Hi, {{ user.username }}!</div>
<a href="{{ urls.format('SETTING_MODE', ['appearance', 'avatar']) }}"><img src="{{ route('file.avatar', user.id) }}" alt="{{ user.username }}" class="default-avatar-setting homepage-menu-avatar" /></a>
<ul class="panelQuickLinks">
<li><a href="{{ urls.format('SETTING_MODE', ['friends', 'requests']) }}" title="Pending friend requests"><span class="fa fa-user-plus"></span><span class="count">{{ user.friends(-1, true)|length }}</span></a></li>
<li><a href="{{ urls.format('MESSAGES_INDEX') }}" title="View private messages"><span class="fa fa-envelope"></span><span class="count">0</span></a></li>
</ul>
<div class="clear"></div>
<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="{{ urls.format('SETTING_MODE', ['friends', 'requests']) }}" class="clean" style="display: block; height: 100%; width: 100%;"></a></div>
<div class="user-container-info">
<a href="{{ route('user.profile', user.id) }}" class="clean"><h1 style="color: {{ user.colour }}; text-shadow: 0 0 7px {% if user.colour != 'inherit' %}{{ user.colour }}{% else %}#222{% endif %}; padding: 0 0 2px;">{{ user.username }}</h1></a>
{% set friendRequests = user.friends(-1, true)|length %}
{% if friendRequests %}
<a class="default" href="{{ urls.format('SETTING_MODE', ['friends', 'requests']) }}" title="Pending friend requests">{{ friendRequests }} new friend requests</a>
{% endif %}
</div>
</div>
{% else %}
{% if sakura.lockAuth %}
<div class="head">Whoops!</div>

View file

@ -7,7 +7,54 @@
{% block content %}
<div class="content homepage forum">
<div class="content-right content-column">
{% include 'elements/indexPanel.twig' %}
<div id="forumIndexPopularThreads">
<div class="head">Popular threads</div>
<table class="panelTable" style="border-spacing: 0;">
<tr>
<th>Title</th>
<th>Last reply</th>
</tr>
{% for _t in activeThreads %}
<tr {% if _t.unread(user.id) %}style="font-weight: bold;"{% endif %}>
<td style="text-align: left; border-bottom: 1px solid #9475b2;">
<a href="{{ route('forums.thread', _t.id) }}" class="default">{{ _t.title }}</a>
</td>
<td class="rightAlign" style="border-bottom: 1px solid #9475b2;"><time>{{ _t.lastPost.time|date(sakura.dateFormat) }}</time></td>
</tr>
{% endfor %}
</table>
</div>
<div id="forumIndexNewPosts">
<div class="head">Latest posts</div>
<table class="panelTable" style="border-spacing: 0;">
<tr>
<th>Title &amp; user</th>
<th>Posted</th>
</tr>
{% for _p in latestPosts %}
<tr {% if _p.unread(user.id) %}style="font-weight: bold;"{% endif %}>
<td style="text-align: left; border-bottom: 1px solid #9475b2;">
<a href="{{ route('forums.post', _p.id) }}" class="default">{{ _p.subject }}</a>
by
<a href="{{ route('user.profile', _p.poster.id) }}" class="default"><span style="color: {{ _p.poster.colour }};">{{ _p.poster.username }}</span></a>
</td>
<td class="rightAlign" style="border-bottom: 1px solid #9475b2;"><time>{{ _p.time|date(sakura.dateFormat) }}</time></td>
</tr>
{% endfor %}
</table>
</div>
<div id="forumMostActivePoster">
<div class="head">Today's most active poster</div>
<a class="clean" href="{{ route('user.profile', activePoster.id) }}">
<div class="user-container" style="background-image: url({{ route('user.header', activePoster.id) }});">
<div class="default-avatar-setting user-container-avatar" style="background-image: url({{ route('file.avatar', activePoster.id) }}); box-shadow: 0 0 5px #{% if activePoster.isOnline %}484{% else %}844{% endif %};"></div>
<div class="user-container-info">
<h1 style="color: {{ activePoster.colour }}; text-shadow: 0 0 7px {% if activePoster.colour != 'inherit' %}{{ activePoster.colour }}{% else %}#222{% endif %}; padding: 0 0 2px;" {% if activePoster.getUsernameHistory %} title="Known as {{ activePoster.getUsernameHistory[0].username_old }} before {{ activePoster.getUsernameHistory[0].change_time|date(sakura.dateFormat) }}." {% endif %}>{{ activePoster.username }}</h1>
{% if activePoster.isPremium[0] %}<img src="{{ sakura.contentPath }}/images/tenshi.png" alt="Tenshi" style="vertical-align: middle;" /> {% endif %}<img src="{{ sakura.contentPath }}/images/flags/{{ activePoster.country|lower }}.png" alt="{{ activePoster.country }}" style="vertical-align: middle;" title="{{ activePoster.country(true) }}" /> <span style="font-size: .8em;">{{ activePoster.title }}</span>
</div>
</div>
</a>
</div>
</div>
<div class="content-left content-column">
{% include 'forum/forum.twig' %}
@ -15,7 +62,3 @@
<div class="clear"></div>
</div>
{% endblock %}
{% block js %}
<script type="text/javascript" src="{{ sakura.resources }}/js/ybabstat.js"></script>
{% endblock %}