2016-01-30 00:18:23 +00:00
|
|
|
<?php
|
2016-02-03 22:22:56 +00:00
|
|
|
/**
|
|
|
|
* Holds the meta page controllers.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-03 22:22:56 +00:00
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
2016-01-30 00:18:23 +00:00
|
|
|
namespace Sakura\Controllers;
|
|
|
|
|
2016-01-30 13:25:18 +00:00
|
|
|
use Sakura\Config;
|
2016-02-18 23:28:44 +00:00
|
|
|
use Sakura\DB;
|
2016-03-28 14:47:43 +00:00
|
|
|
use Sakura\News\Category;
|
2016-01-30 00:18:23 +00:00
|
|
|
use Sakura\Template;
|
2016-01-30 13:25:18 +00:00
|
|
|
use Sakura\User;
|
2016-01-30 00:18:23 +00:00
|
|
|
|
|
|
|
/**
|
2016-02-15 21:20:46 +00:00
|
|
|
* Meta page controllers (sections that aren't big enough to warrant a dedicated controller).
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-01-30 00:18:23 +00:00
|
|
|
* @package Sakura
|
2016-02-02 21:04:15 +00:00
|
|
|
* @author Julian van de Groep <me@flash.moe>
|
2016-01-30 00:18:23 +00:00
|
|
|
*/
|
2016-02-27 16:46:16 +00:00
|
|
|
class MetaController extends Controller
|
2016-01-30 00:18:23 +00:00
|
|
|
{
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Serves the site index.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @return mixed HTML for the index.
|
|
|
|
*/
|
2016-02-14 22:46:07 +00:00
|
|
|
public function index()
|
2016-01-30 13:25:18 +00:00
|
|
|
{
|
2016-03-27 21:18:57 +00:00
|
|
|
// Get the newest user
|
|
|
|
$newestUserId = DB::table('users')
|
|
|
|
->where('rank_main', '!=', Config::get('restricted_rank_id'))
|
|
|
|
->where('rank_main', '!=', Config::get('deactive_rank_id'))
|
|
|
|
->orderBy('user_id', 'desc')
|
|
|
|
->limit(1)
|
|
|
|
->get(['user_id']);
|
|
|
|
$newestUser = User::construct($newestUserId ? $newestUserId[0]->user_id : 0);
|
|
|
|
|
|
|
|
// Get all the currently online users
|
|
|
|
$timeRange = time() - Config::get('max_online_time');
|
|
|
|
|
|
|
|
// Create a storage variable
|
|
|
|
$onlineUsers = [];
|
|
|
|
|
|
|
|
// Get all online users
|
|
|
|
$getOnline = DB::table('users')
|
|
|
|
->where('user_last_online', '>', $timeRange)
|
|
|
|
->get(['user_id']);
|
|
|
|
$getOnline = array_column($getOnline, 'user_id');
|
|
|
|
|
|
|
|
foreach ($getOnline as $user) {
|
|
|
|
$user = User::construct($user);
|
|
|
|
|
|
|
|
// Do a second check
|
|
|
|
if (!$user->isOnline()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$onlineUsers[$user->id] = $user;
|
|
|
|
}
|
|
|
|
|
2016-03-28 14:47:43 +00:00
|
|
|
// Get news
|
|
|
|
$news = new Category(Config::get('site_news_category'));
|
|
|
|
|
2016-01-30 13:25:18 +00:00
|
|
|
// Merge index specific stuff with the global render data
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars([
|
2016-03-28 14:47:43 +00:00
|
|
|
'news' => $news->posts(Config::get('front_page_news_posts')),
|
2016-02-04 20:56:40 +00:00
|
|
|
'stats' => [
|
2016-03-25 01:31:57 +00:00
|
|
|
'userCount' => DB::table('users')
|
|
|
|
->where('password_algo', '!=', 'disabled')
|
2016-04-25 02:01:14 +00:00
|
|
|
->whereNotIn('rank_main', [Config::get('deactive_rank_id'), Config::get('restricted_rank_id')])
|
2016-03-25 01:31:57 +00:00
|
|
|
->count(),
|
2016-03-27 21:18:57 +00:00
|
|
|
'newestUser' => $newestUser,
|
2016-02-04 20:56:40 +00:00
|
|
|
'lastRegDate' => date_diff(
|
2016-03-27 21:18:57 +00:00
|
|
|
date_create(date('Y-m-d', $newestUser->registered)),
|
2016-02-04 20:56:40 +00:00
|
|
|
date_create(date('Y-m-d'))
|
|
|
|
)->format('%a'),
|
2016-04-25 02:01:14 +00:00
|
|
|
'topicCount' => DB::table('topics')->where('forum_id', '!=', Config::get('forum_trash_id'))->count(),
|
|
|
|
'postCount' => DB::table('posts')->where('forum_id', '!=', Config::get('forum_trash_id'))->count(),
|
2016-03-27 21:18:57 +00:00
|
|
|
'onlineUsers' => $onlineUsers,
|
2016-02-04 20:56:40 +00:00
|
|
|
],
|
|
|
|
]);
|
2016-01-30 13:25:18 +00:00
|
|
|
|
|
|
|
// Return the compiled page
|
2016-03-28 14:47:43 +00:00
|
|
|
return Template::render('meta/index');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Displays the FAQ.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @return mixed HTML for the FAQ.
|
|
|
|
*/
|
2016-02-14 22:46:07 +00:00
|
|
|
public function faq()
|
2016-01-30 13:25:18 +00:00
|
|
|
{
|
2016-02-18 23:28:44 +00:00
|
|
|
// Get faq entries
|
2016-02-25 16:06:29 +00:00
|
|
|
$faq = DB::table('faq')
|
|
|
|
->orderBy('faq_id')
|
|
|
|
->get();
|
2016-02-18 23:28:44 +00:00
|
|
|
|
2016-01-30 13:25:18 +00:00
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars([
|
|
|
|
'page' => [
|
|
|
|
'title' => 'Frequently Asked Questions',
|
2016-02-18 23:28:44 +00:00
|
|
|
'questions' => $faq,
|
2016-02-04 20:56:40 +00:00
|
|
|
],
|
|
|
|
]);
|
2016-01-30 13:25:18 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-03-28 14:47:43 +00:00
|
|
|
return Template::render('meta/faq');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Handles the info pages.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @param string $id The page ID from the database.
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @return mixed HTML for the info page.
|
|
|
|
*/
|
2016-02-14 22:46:07 +00:00
|
|
|
public function infoPage($id = null)
|
2016-01-30 13:25:18 +00:00
|
|
|
{
|
|
|
|
// Set default variables
|
2016-02-18 23:28:44 +00:00
|
|
|
Template::vars([
|
|
|
|
'page' => [
|
|
|
|
'content' => '<h1>Unable to load the requested info page.</h1><p>Check the URL and try again.</p>',
|
|
|
|
],
|
|
|
|
]);
|
2016-01-30 13:25:18 +00:00
|
|
|
|
|
|
|
// Set page id
|
|
|
|
$id = strtolower($id);
|
|
|
|
|
2016-02-18 23:28:44 +00:00
|
|
|
// Get the page from the database
|
2016-02-25 16:06:29 +00:00
|
|
|
$ipData = DB::table('infopages')
|
|
|
|
->where('page_shorthand', $id)
|
|
|
|
->get();
|
2016-02-18 23:28:44 +00:00
|
|
|
|
2016-01-30 13:25:18 +00:00
|
|
|
// Get info page data from the database
|
2016-02-18 23:28:44 +00:00
|
|
|
if ($ipData) {
|
2016-01-30 13:25:18 +00:00
|
|
|
// Assign new proper variable
|
2016-02-18 23:28:44 +00:00
|
|
|
Template::vars([
|
|
|
|
'page' => [
|
|
|
|
'id' => $id,
|
2016-02-25 16:06:29 +00:00
|
|
|
'title' => $ipData[0]->page_title,
|
|
|
|
'content' => $ipData[0]->page_content,
|
2016-02-18 23:28:44 +00:00
|
|
|
],
|
|
|
|
]);
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the compiled page
|
2016-03-28 14:47:43 +00:00
|
|
|
return Template::render('meta/infopage');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Search page
|
2016-03-08 23:07:58 +00:00
|
|
|
*
|
2016-02-02 21:04:15 +00:00
|
|
|
* @return mixed HTML for the search page.
|
|
|
|
*/
|
2016-02-14 22:46:07 +00:00
|
|
|
public function search()
|
2016-01-30 13:25:18 +00:00
|
|
|
{
|
2016-03-28 14:47:43 +00:00
|
|
|
return Template::render('meta/search');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
2016-01-30 00:18:23 +00:00
|
|
|
}
|