r20160130.1
This commit is contained in:
parent
232ddc6114
commit
bf0b1ec047
13 changed files with 290 additions and 205 deletions
62
libraries/Controllers/Forum.php
Normal file
62
libraries/Controllers/Forum.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
/*
|
||||
* Forum controllers
|
||||
*/
|
||||
|
||||
namespace Sakura\Controllers;
|
||||
|
||||
use Sakura\Config;
|
||||
use Sakura\Database;
|
||||
use Sakura\Forum as ForumData;
|
||||
use Sakura\Perms\Forum as ForumPerms;
|
||||
use Sakura\Template;
|
||||
use Sakura\User;
|
||||
use Sakura\Users;
|
||||
use Sakura\Utils;
|
||||
|
||||
/**
|
||||
* Class Forum
|
||||
* @package Sakura
|
||||
*/
|
||||
class Forum
|
||||
{
|
||||
// Forum index
|
||||
public static function index()
|
||||
{
|
||||
// Get the global renderData
|
||||
global $renderData;
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Merge index specific stuff with the global render data
|
||||
$renderData = array_merge(
|
||||
$renderData,
|
||||
[
|
||||
'forum' => (new ForumData\Forum()),
|
||||
'stats' => [
|
||||
'userCount' => Database::count('users', ['password_algo' => ['nologin', '!='], 'rank_main' => ['1', '!=']])[0],
|
||||
'newestUser' => User::construct(Users::getNewestUserId()),
|
||||
'lastRegData' => date_diff(
|
||||
date_create(date('Y-m-d', User::construct(Users::getNewestUserId())->registered)),
|
||||
date_create(date('Y-m-d'))
|
||||
)->format('%a'),
|
||||
'topicCount' => Database::count('topics')[0],
|
||||
'postCount' => Database::count('posts')[0],
|
||||
'onlineUsers' => Users::checkAllOnline(),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Return the compiled page
|
||||
return $template->render('forum/index');
|
||||
}
|
||||
|
||||
// View a forum
|
||||
public static function forum($id = null)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -5,7 +5,13 @@
|
|||
|
||||
namespace Sakura\Controllers;
|
||||
|
||||
use Sakura\Config;
|
||||
use Sakura\Database;
|
||||
use Sakura\News;
|
||||
use Sakura\Template;
|
||||
use Sakura\User;
|
||||
use Sakura\Users;
|
||||
use Sakura\Utils;
|
||||
|
||||
/**
|
||||
* Class Meta
|
||||
|
@ -13,4 +19,151 @@ use Sakura\Template;
|
|||
*/
|
||||
class Meta
|
||||
{
|
||||
// Site index
|
||||
public static function index()
|
||||
{
|
||||
// Get the global renderData
|
||||
global $renderData;
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Merge index specific stuff with the global render data
|
||||
$renderData = array_merge(
|
||||
$renderData,
|
||||
[
|
||||
'news' => new News(Config::get('site_news_category')),
|
||||
'newsCount' => Config::get('front_page_news_posts'),
|
||||
'stats' => [
|
||||
'userCount' => Database::count('users', ['password_algo' => ['nologin', '!='], 'rank_main' => ['1', '!=']])[0],
|
||||
'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' => Database::count('topics')[0],
|
||||
'postCount' => Database::count('posts')[0],
|
||||
'onlineUsers' => Users::checkAllOnline(),
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Return the compiled page
|
||||
return $template->render('main/index');
|
||||
}
|
||||
|
||||
// News
|
||||
public static function news()
|
||||
{
|
||||
// Get the global renderData
|
||||
global $renderData;
|
||||
|
||||
// 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);
|
||||
|
||||
// Merge the data for this page with the global
|
||||
$renderData = array_merge($renderData, [
|
||||
'news' => $news,
|
||||
'postsPerPage' => Config::get('news_posts_per_page'),
|
||||
'viewPost' => $post != 0,
|
||||
'postExists' => $news->postExists($post),
|
||||
]);
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
return $template->render('main/news');
|
||||
}
|
||||
|
||||
// FAQ
|
||||
public static function faq()
|
||||
{
|
||||
// Get the global renderData
|
||||
global $renderData;
|
||||
|
||||
// Add page specific things
|
||||
$renderData['page'] = [
|
||||
'title' => 'Frequently Asked Questions',
|
||||
'questions' => Utils::getFaqData(),
|
||||
];
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
echo $template->render('main/faq');
|
||||
|
||||
}
|
||||
|
||||
// Info pages
|
||||
public static function infoPage($id = null)
|
||||
{
|
||||
// Get the global renderData
|
||||
global $renderData;
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Set default variables
|
||||
$renderData['page'] = [
|
||||
'content' => '<h1>Unable to load the requested info page.</h1><p>Check the URL and try again.</p>',
|
||||
];
|
||||
|
||||
// Set page id
|
||||
$id = strtolower($id);
|
||||
|
||||
// Get info page data from the database
|
||||
if ($ipData = Utils::loadInfoPage($id)) {
|
||||
// Assign new proper variable
|
||||
$renderData['page'] = [
|
||||
'id' => $id,
|
||||
'title' => $ipData['page_title'],
|
||||
'content' => $ipData['page_content'],
|
||||
];
|
||||
}
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Return the compiled page
|
||||
return $template->render('main/infopage');
|
||||
}
|
||||
|
||||
// Search
|
||||
public static function search()
|
||||
{
|
||||
// Get the global renderData
|
||||
global $renderData;
|
||||
|
||||
// Add page specific things
|
||||
$renderData['page'] = [
|
||||
'title' => 'Search',
|
||||
];
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
echo $template->render('main/search');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class Router
|
|||
// Router container
|
||||
protected static $router = null;
|
||||
|
||||
// Base path
|
||||
// Base path (unused for now)
|
||||
protected static $basePath = null;
|
||||
|
||||
// Dispatcher
|
||||
|
@ -40,9 +40,10 @@ class Router
|
|||
// Check if the method exists
|
||||
if (in_array($name = strtoupper($name), self::$methods)) {
|
||||
$path = isset($args[2]) && $args !== null ? [$args[0], $args[2]] : $args[0];
|
||||
$handler = is_callable($args[1]) || is_array($args[1]) ? $args[1] : explode('@', $args[1]);
|
||||
$filter = isset($args[3]) ? $args[3] : [];
|
||||
|
||||
self::$router->addRoute($name, $path, $args[1], $filter);
|
||||
self::$router->addRoute($name, $path, $handler, $filter);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +66,7 @@ class Router
|
|||
// Parse the url
|
||||
private static function parseUrl($url)
|
||||
{
|
||||
return parse_url(str_replace(self::$basePath, '', $url), PHP_URL_PATH);
|
||||
return parse_url($url, PHP_URL_PATH);
|
||||
}
|
||||
|
||||
// Handle requests
|
||||
|
|
|
@ -16,7 +16,7 @@ class Urls
|
|||
|
||||
// General site sections
|
||||
'SITE_HOME' => [
|
||||
'/',
|
||||
'/index.php',
|
||||
'/',
|
||||
],
|
||||
'SITE_NEWS' => [
|
||||
|
@ -32,7 +32,7 @@ class Urls
|
|||
'/news/%s',
|
||||
],
|
||||
'SITE_NEWS_CAT_POST' => [
|
||||
'/news.php?cat=$s&id=%u',
|
||||
'/news.php?cat=%s&id=%u',
|
||||
'/news/%s/%u',
|
||||
],
|
||||
'SITE_SEARCH' => [
|
||||
|
@ -292,7 +292,7 @@ class Urls
|
|||
}
|
||||
|
||||
// Check if mod_rewrite is enabled
|
||||
$rewrite = ($rewrite === null ? Config::get('url_rewrite') : $rewrite) ? 1 : 0;
|
||||
$rewrite = 0; //($rewrite === null ? Config::get('url_rewrite') : $rewrite) ? 1 : 0;
|
||||
|
||||
// Format urls
|
||||
$formatted = vsprintf($this->urls[$lid][$rewrite], $args);
|
||||
|
|
|
@ -1,28 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Sakura FAQ Page
|
||||
*/
|
||||
|
||||
// Declare Namespace
|
||||
namespace Sakura;
|
||||
|
||||
// Include components
|
||||
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
||||
|
||||
// Add page specific things
|
||||
$renderData['page'] = [
|
||||
'title' => 'Frequently Asked Questions',
|
||||
'questions' => Utils::getFaqData(),
|
||||
];
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Change templating engine
|
||||
$template->setTemplate($templateName);
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
echo $template->render('main/faq');
|
|
@ -1,22 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Sakura User Groups
|
||||
*/
|
||||
|
||||
// Declare Namespace
|
||||
namespace Sakura;
|
||||
|
||||
// Include components
|
||||
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Change templating engine
|
||||
$template->setTemplate($templateName);
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
echo $template->render('group/index');
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/*
|
||||
* Sakura Main Index
|
||||
* Sakura Router
|
||||
*/
|
||||
|
||||
// Declare Namespace
|
||||
|
@ -9,72 +9,5 @@ namespace Sakura;
|
|||
// Include components
|
||||
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Change templating engine
|
||||
$template->setTemplate($templateName);
|
||||
|
||||
// Info pages
|
||||
if (isset($_GET['p'])) {
|
||||
// Set default variables
|
||||
$renderData['page'] = [
|
||||
'content' => '<h1>Unable to load the requested info page.</h1><p>Check the URL and try again.</p>',
|
||||
];
|
||||
|
||||
// Set page id
|
||||
$pageId = isset($_GET['p']) ? strtolower($_GET['p']) : '';
|
||||
|
||||
// Get info page data from the database
|
||||
if ($ipData = Utils::loadInfoPage($pageId)) {
|
||||
// Assign new proper variable
|
||||
$renderData['page'] = [
|
||||
'id' => $pageId,
|
||||
'title' => $ipData['page_title'],
|
||||
'content' => $ipData['page_content'],
|
||||
];
|
||||
}
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
echo $template->render('main/infopage');
|
||||
exit;
|
||||
}
|
||||
|
||||
// Are we in forum mode?
|
||||
$forumMode = isset($_GET['forum']) ? ($_GET['forum'] == true) : false;
|
||||
|
||||
$renderData['news'] = ($forumMode ? null : (new News(Config::get('site_news_category'))));
|
||||
|
||||
$renderData['newsCount'] = Config::get('front_page_news_posts');
|
||||
|
||||
$renderData['forum'] = ($forumMode ? (new Forum\Forum()) : null);
|
||||
|
||||
$renderData['latestPosts'] = Database::fetch('posts', true, null, ['post_id', true], [3]);
|
||||
|
||||
$renderData['stats'] = [
|
||||
'userCount' => Database::count('users', ['password_algo' => ['nologin', '!='], 'rank_main' => ['1', '!=']])[0],
|
||||
'newestUser' => ($_INDEX_NEWEST_USER = User::construct(Users::getNewestUserId())),
|
||||
'lastRegDate' => ($_INDEX_LAST_REGDATE = date_diff(
|
||||
date_create(
|
||||
date(
|
||||
'Y-m-d',
|
||||
$_INDEX_NEWEST_USER->registered
|
||||
)
|
||||
),
|
||||
date_create(
|
||||
date('Y-m-d')
|
||||
)
|
||||
)->format('%a')) . ' day' . ($_INDEX_LAST_REGDATE == 1 ? '' : 's'),
|
||||
'topicCount' => Database::count('topics')[0],
|
||||
'postCount' => Database::count('posts')[0],
|
||||
'onlineUsers' => Users::checkAllOnline(),
|
||||
];
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
echo $template->render(($forumMode ? 'forum' : 'main') . '/index');
|
||||
// Handle requests
|
||||
echo Router::handle($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Sakura News Page
|
||||
*/
|
||||
|
||||
// Declare Namespace
|
||||
namespace Sakura;
|
||||
|
||||
// Include components
|
||||
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
||||
|
||||
// Create a new News object
|
||||
$news = new News(isset($_GET['cat']) ? $_GET['cat'] : Config::get('site_news_category'));
|
||||
|
||||
$renderData = array_merge($renderData, [
|
||||
'news' => $news,
|
||||
'postsPerPage' => Config::get('news_posts_per_page'),
|
||||
'viewPost' => isset($_GET['id']),
|
||||
'postExists' => $news->postExists(isset($_GET['id']) ? $_GET['id'] : 0),
|
||||
]);
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Change templating engine
|
||||
$template->setTemplate($templateName);
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
echo $template->render('main/news');
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Sakura Router
|
||||
*/
|
||||
|
||||
// Declare Namespace
|
||||
namespace Sakura;
|
||||
|
||||
// Include components
|
||||
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
||||
|
||||
if (!Config::local('dev', 'show_changelog') || !Config::local('dev', 'show_errors')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
Router::setBasePath('/router.php');
|
||||
|
||||
// Handle requests
|
||||
echo Router::handle($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
|
@ -1,27 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* Sakura Search Page
|
||||
*/
|
||||
|
||||
// Declare Namespace
|
||||
namespace Sakura;
|
||||
|
||||
// Include components
|
||||
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
||||
|
||||
// Add page specific things
|
||||
$renderData['page'] = [
|
||||
'title' => 'Search',
|
||||
];
|
||||
|
||||
// Initialise templating engine
|
||||
$template = new Template();
|
||||
|
||||
// Change templating engine
|
||||
$template->setTemplate($templateName);
|
||||
|
||||
// Set parse variables
|
||||
$template->setVariables($renderData);
|
||||
|
||||
// Print page contents
|
||||
echo $template->render('main/search');
|
63
routes.php
63
routes.php
|
@ -5,3 +5,66 @@
|
|||
|
||||
// Define namespace
|
||||
namespace Sakura;
|
||||
|
||||
// Meta pages
|
||||
Router::get('/', 'Sakura\Controllers\Meta@index', 'main.index');
|
||||
Router::get('/faq', 'Sakura\Controllers\Meta@faq', 'main.faq');
|
||||
Router::get('/search', 'Sakura\Controllers\Meta@search', 'main.search');
|
||||
Router::get('/p/{id}', 'Sakura\Controllers\Meta@infoPage', 'main.infopage');
|
||||
|
||||
// News
|
||||
Router::get('/news', 'Sakura\Controllers\Meta@news', 'news.index');
|
||||
Router::get('/news/{category}', 'Sakura\Controllers\Meta@news', 'news.category');
|
||||
Router::get('/news/{category}/{id}', 'Sakura\Controllers\Meta@news', 'news.post');
|
||||
|
||||
// Forum
|
||||
Router::get('/forum', 'Sakura\Controllers\Forum@index', 'forum.index');
|
||||
|
||||
// Redirections
|
||||
Router::any('/index.php', function () {
|
||||
// Info pages
|
||||
if (isset($_REQUEST['p'])) {
|
||||
header('Location: /p/' . $_REQUEST['p']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Forum index
|
||||
if (isset($_REQUEST['forum']) && $_REQUEST['forum']) {
|
||||
header('Location: /forum');
|
||||
return;
|
||||
}
|
||||
|
||||
// Site index
|
||||
header('Location: /');
|
||||
});
|
||||
|
||||
Router::any('/news.php', function () {
|
||||
// Category + post
|
||||
if (isset($_REQUEST['cat']) && isset($_REQUEST['id'])) {
|
||||
header('Location: /news/' . $_REQUEST['cat'] . '/'. $_REQUEST['id']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Category
|
||||
if (isset($_REQUEST['cat'])) {
|
||||
header('Location: /news/' . $_REQUEST['cat']);
|
||||
return;
|
||||
}
|
||||
|
||||
// Post in the main category
|
||||
if (isset($_REQUEST['id'])) {
|
||||
header('Location: /news/' . $_REQUEST['id']);
|
||||
return;
|
||||
}
|
||||
|
||||
// All posts in main category
|
||||
header('Location: /news');
|
||||
});
|
||||
|
||||
Router::any('/faq.php', function () {
|
||||
header('Location: /faq');
|
||||
});
|
||||
|
||||
Router::any('/search.php', function () {
|
||||
header('Location: /search');
|
||||
});
|
||||
|
|
|
@ -61,6 +61,7 @@ require_once ROOT . 'libraries/Users.php';
|
|||
require_once ROOT . 'libraries/Utils.php';
|
||||
require_once ROOT . 'libraries/Whois.php';
|
||||
require_once ROOT . 'libraries/Console/Application.php';
|
||||
require_once ROOT . 'libraries/Controllers/Forum.php';
|
||||
require_once ROOT . 'libraries/Controllers/Meta.php';
|
||||
require_once ROOT . 'libraries/Forum/Forum.php';
|
||||
require_once ROOT . 'libraries/Forum/Post.php';
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
<div class="head">Stats</div>
|
||||
We have <b>{{ stats.userCount }} user{% if stats.userCount != 1 %}s{% endif %}</b>,
|
||||
<b><a href="{{ urls.format('USER_PROFILE', [stats.newestUser.id]) }}" style="color: {{ stats.newestUser.colour }};" class="default">{{ stats.newestUser.username }}</a></b> is the newest user,
|
||||
it has been <b>{{ stats.lastRegDate }}</b> since the last user registered and the forum has <b>{{ stats.topicCount }} thread{% if stats.topicCount != 1 %}s{% endif %}</b> and <b>{{ stats.postCount }} post{% if stats.postCount != 1 %}s{% endif %}</b>.
|
||||
it has been <b>{{ stats.lastRegDate }} day{{ stats.lastRegDate == 1 ? '' : 's' }}</b> since the last user registered and the forum has <b>{{ stats.topicCount }} thread{% if stats.topicCount != 1 %}s{% endif %}</b> and <b>{{ stats.postCount }} post{% if stats.postCount != 1 %}s{% endif %}</b>.
|
||||
<div class="head">Online Users</div>
|
||||
{% if stats.onlineUsers %}
|
||||
All active users in the past {{ sakura.onlineTimeout / 60 }} minute{% if sakura.onlineTimeout != 60 %}s{% endif %}
|
||||
|
|
Reference in a new issue