2016-01-30 00:18:23 +00:00
|
|
|
<?php
|
2016-02-03 22:22:56 +00:00
|
|
|
/**
|
|
|
|
* Holds the meta page controllers.
|
|
|
|
*
|
|
|
|
* @package Sakura
|
|
|
|
*/
|
|
|
|
|
2016-01-30 00:18:23 +00:00
|
|
|
namespace Sakura\Controllers;
|
|
|
|
|
2016-01-30 13:25:18 +00:00
|
|
|
use Sakura\Config;
|
|
|
|
use Sakura\Database;
|
2016-02-18 23:28:44 +00:00
|
|
|
use Sakura\DB;
|
2016-01-30 13:25:18 +00:00
|
|
|
use Sakura\News;
|
2016-01-30 00:18:23 +00:00
|
|
|
use Sakura\Template;
|
2016-01-30 13:25:18 +00:00
|
|
|
use Sakura\User;
|
|
|
|
use Sakura\Users;
|
|
|
|
use Sakura\Utils;
|
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-02-02 21:04:15 +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-15 21:20:46 +00:00
|
|
|
class Meta extends Controller
|
2016-01-30 00:18:23 +00:00
|
|
|
{
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Serves the site index.
|
|
|
|
*
|
|
|
|
* @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-02-18 23:28:44 +00:00
|
|
|
$userCount = DB::prepare("SELECT * FROM `{prefix}users` WHERE `password_algo` != 'disabled' AND `rank_main` != 1");
|
|
|
|
$userCount->execute();
|
|
|
|
$threadCount = DB::prepare('SELECT * FROM `{prefix}topics`');
|
|
|
|
$threadCount->execute();
|
|
|
|
$postCount = DB::prepare('SELECT * FROM `{prefix}posts`');
|
|
|
|
$postCount->execute();
|
|
|
|
|
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([
|
|
|
|
'news' => new News(Config::get('site_news_category')),
|
|
|
|
'newsCount' => Config::get('front_page_news_posts'),
|
|
|
|
'stats' => [
|
2016-02-18 23:28:44 +00:00
|
|
|
'userCount' => $userCount->rowCount(),
|
2016-02-04 20:56:40 +00:00
|
|
|
'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'),
|
2016-02-18 23:28:44 +00:00
|
|
|
'topicCount' => $threadCount->rowCount(),
|
|
|
|
'postCount' => $postCount->rowCount(),
|
2016-02-04 20:56:40 +00:00
|
|
|
'onlineUsers' => Users::checkAllOnline(),
|
|
|
|
],
|
|
|
|
]);
|
2016-01-30 13:25:18 +00:00
|
|
|
|
|
|
|
// Return the compiled page
|
2016-02-04 20:56:40 +00:00
|
|
|
return Template::render('main/index');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Handles the news pages.
|
|
|
|
*
|
|
|
|
* @return mixed HTML for the correct news section.
|
|
|
|
*/
|
2016-02-14 22:46:07 +00:00
|
|
|
public function news()
|
2016-01-30 13:25:18 +00:00
|
|
|
{
|
|
|
|
// Get arguments
|
|
|
|
$args = func_get_args();
|
|
|
|
$category = isset($args[0]) && !is_numeric($args[0]) ? $args[0] : Config::get('site_news_category');
|
|
|
|
$post = isset($args[1]) && is_numeric($args[1]) ? $args[1] : (
|
|
|
|
isset($args[0]) && is_numeric($args[0]) ? $args[0] : 0
|
|
|
|
);
|
|
|
|
|
|
|
|
// Create news object
|
|
|
|
$news = new News($category);
|
|
|
|
|
2016-02-04 20:56:40 +00:00
|
|
|
// Set parse variables
|
|
|
|
Template::vars([
|
2016-01-30 13:25:18 +00:00
|
|
|
'news' => $news,
|
|
|
|
'postsPerPage' => Config::get('news_posts_per_page'),
|
|
|
|
'viewPost' => $post != 0,
|
|
|
|
'postExists' => $news->postExists($post),
|
|
|
|
]);
|
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
return Template::render('main/news');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Displays the FAQ.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
$faq = DB::prepare('SELECT * FROM `{prefix}faq` ORDER BY `faq_id`');
|
|
|
|
$faq->execute();
|
|
|
|
$faq = $faq->fetchAll();
|
|
|
|
|
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-02-04 20:56:40 +00:00
|
|
|
return Template::render('main/faq');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Handles the info pages.
|
|
|
|
*
|
|
|
|
* @param string $id The page ID from the database.
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
$ipData = DB::prepare('SELECT * FROM `{prefix}infopages` WHERE `page_shorthand` = :id');
|
|
|
|
$ipData->execute([
|
|
|
|
'id' => $id,
|
|
|
|
]);
|
|
|
|
$ipData = $ipData->fetch();
|
|
|
|
|
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,
|
|
|
|
'title' => $ipData->page_title,
|
|
|
|
'content' => $ipData->page_content,
|
|
|
|
],
|
|
|
|
]);
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the compiled page
|
2016-02-04 20:56:40 +00:00
|
|
|
return Template::render('main/infopage');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 21:04:15 +00:00
|
|
|
/**
|
|
|
|
* Search page
|
|
|
|
*
|
|
|
|
* @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
|
|
|
{
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars([
|
|
|
|
'page' => [
|
|
|
|
'title' => 'Search',
|
|
|
|
],
|
|
|
|
]);
|
2016-01-30 13:25:18 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
return Template::render('main/search');
|
2016-01-30 13:25:18 +00:00
|
|
|
}
|
2016-01-30 00:18:23 +00:00
|
|
|
}
|