diff --git a/libraries/Controllers/Forum.php b/libraries/Controllers/Forum.php deleted file mode 100644 index a742953..0000000 --- a/libraries/Controllers/Forum.php +++ /dev/null @@ -1,65 +0,0 @@ - - */ -class Forum -{ - /** - * Serves the forum index. - * - * @return mixed HTML for the 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'); - } -} diff --git a/libraries/Controllers/Forums.php b/libraries/Controllers/Forums.php new file mode 100644 index 0000000..049c5d3 --- /dev/null +++ b/libraries/Controllers/Forums.php @@ -0,0 +1,134 @@ + + */ +class Forums +{ + /** + * Serves the forum index. + * + * @return mixed HTML for the forum index. + */ + public static function index() + { + // Merge index specific stuff with the global render data + Template::vars([ + 'forum' => (new Forum\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(), + ], + ]); + + // Return the compiled page + return Template::render('forum/index'); + } + + public static function forum($id = 0) + { + global $currentUser; + + // Get the forum + $forum = new Forum\Forum($id); + + // Redirect forum id 0 to the main page + if ($forum->id === 0) { + header('Location: ' . (new \Sakura\Urls)->format('FORUM_INDEX')); + exit; + } + + // Check if the forum exists + if ($forum->id < 0) { + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'The forum you tried to access does not exist.', + ], + ]); + + // Print page contents + return Template::render('global/information'); + } + + // Check if the user has access to the forum + if (!$forum->permission(ForumPerms::VIEW, $currentUser->id)) { + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'You do not have access to this forum.', + ], + ]); + + // Print page contents + return Template::render('global/information'); + } + + // Check if the forum isn't a link + if ($forum->type === 2) { + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'The forum you tried to access is a link. You\'re being redirected.', + 'redirect' => $forum->link, + ] + ]); + + // Print page contents + return Template::render('global/information'); + } + + // Check if we're marking as read + if (isset($_GET['read']) && $_GET['read'] && isset($_GET['session']) && $_GET['session'] == session_id()) { + // Run the function + $forum->trackUpdateAll($currentUser->id); + + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'All threads have been marked as read.', + 'redirect' => (new \Sakura\Urls)->format('FORUM_SUB', [$forum->id]), + ] + ]); + + // Print page contents + return Template::render('global/information'); + } + + $renderData['forum'] = $forum; + + // Set parse variables + Template::vars([ + 'forum' => $forum, + ]); + + // Print page contents + return Template::render('forum/viewforum'); + } +} diff --git a/libraries/Controllers/Meta.php b/libraries/Controllers/Meta.php index 1ff4e54..b8f5c17 100644 --- a/libraries/Controllers/Meta.php +++ b/libraries/Controllers/Meta.php @@ -30,37 +30,25 @@ class Meta */ 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); + Template::vars([ + '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(), + ], + ]); // Return the compiled page - return $template->render('main/index'); + return Template::render('main/index'); } /** @@ -70,9 +58,6 @@ class Meta */ 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'); @@ -83,22 +68,16 @@ class Meta // Create news object $news = new News($category); - // Merge the data for this page with the global - $renderData = array_merge($renderData, [ + // Set parse variables + Template::vars([ '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'); + return Template::render('main/news'); } /** @@ -108,23 +87,16 @@ class Meta */ 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); + Template::vars([ + 'page' => [ + 'title' => 'Frequently Asked Questions', + 'questions' => Utils::getFaqData(), + ], + ]); // Print page contents - return $template->render('main/faq'); + return Template::render('main/faq'); } /** @@ -136,12 +108,6 @@ class Meta */ public static function infoPage($id = null) { - // Get the global renderData - global $renderData; - - // Initialise templating engine - $template = new Template(); - // Set default variables $renderData['page'] = [ 'content' => '

Unable to load the requested info page.

Check the URL and try again.

', @@ -161,10 +127,10 @@ class Meta } // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Return the compiled page - return $template->render('main/infopage'); + return Template::render('main/infopage'); } /** @@ -174,21 +140,14 @@ class Meta */ 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); + Template::vars([ + 'page' => [ + 'title' => 'Search', + ], + ]); // Print page contents - return $template->render('main/search'); + return Template::render('main/search'); } } diff --git a/libraries/Controllers/User.php b/libraries/Controllers/User.php new file mode 100644 index 0000000..049f446 --- /dev/null +++ b/libraries/Controllers/User.php @@ -0,0 +1,110 @@ + + */ +class User +{ + /** + * Display the profile of a user + * + * @param mixed $id The user ID. + * + * @return bool|string The profile page. + */ + public static function profile($id = 0) + { + global $currentUser; + + // Get the user's context + $profile = UserContext::construct($id); + + // If the user id is zero check if there was a namechange + if ($profile->id == 0) { + // Fetch from username_history + $check = Database::fetch('username_history', false, ['username_old_clean' => [Utils::cleanString(isset($_GET['u']) ? $_GET['u'] : 0, true, true), '=']]); + + // Redirect if so + if ($check) { + Template::vars([ + 'message' => 'The user this profile belongs to changed their username, you are being redirected.', + 'redirect' => (new \Sakura\Urls)->format('USER_PROFILE', [$check['user_id']]), + ]); + + // Print page contents + return Template::render('global/information'); + } + } + + // Check if we're trying to restrict + if (isset($_GET['restrict']) && $_GET['restrict'] == session_id() && $currentUser->permission(\Sakura\Perms\Manage::CAN_RESTRICT_USERS, \Sakura\Perms::MANAGE)) { + // Check restricted status + $restricted = $profile->permission(\Sakura\Perms\Site::RESTRICTED); + + if ($restricted) { + $profile->removeRanks([Config::get('restricted_rank_id')]); + $profile->addRanks([2]); + } else { + $profile->addRanks([Config::get('restricted_rank_id')]); + $profile->removeRanks(array_keys($profile->ranks)); + } + + Template::vars([ + 'page' => [ + 'message' => 'Toggled the restricted status of the user.', + 'redirect' => (new \Sakura\Urls)->format('USER_PROFILE', [$profile->id]), + ], + ]); + + // Print page contents + return Template::render('global/information'); + } + + // Set parse variables + Template::vars([ + 'profile' => $profile, + ]); + + // Print page contents + return Template::render('main/profile'); + } + + public static function members($rank = 0) + { + global $currentUser; + + // Check permission + if (!$currentUser->permission(\Sakura\Perms\Site::VIEW_MEMBERLIST)) { + return Template::render('global/restricted'); + } + + // Set parse variables + Template::vars([ + 'memberlist' => [ + 'ranks' => ($_MEMBERLIST_RANKS = \Sakura\Users::getAllRanks()), + 'active' => ($_MEMBERLIST_ACTIVE = (array_key_exists($rank, $_MEMBERLIST_RANKS) ? $rank : 0)), + 'users' => ($_MEMBERLIST_ACTIVE ? \Sakura\Users::getUsersInRank($_MEMBERLIST_ACTIVE) : \Sakura\Users::getAllUsers(false)), + 'membersPerPage' => Config::get('members_per_page'), + ] + ]); + + // Render the template + return Template::render('main/memberlist'); + } +} diff --git a/libraries/Router.php b/libraries/Router.php index b47773b..9548244 100644 --- a/libraries/Router.php +++ b/libraries/Router.php @@ -7,8 +7,10 @@ namespace Sakura; -use Phroute\Phroute\RouteCollector; use Phroute\Phroute\Dispatcher; +use Phroute\Phroute\Exception\HttpRouteNotFoundException; +use Phroute\Phroute\Exception\HttpMethodNotAllowedException; +use Phroute\Phroute\RouteCollector; /** * Sakura Wrapper for Phroute. @@ -108,6 +110,19 @@ class Router return parse_url($url, PHP_URL_PATH); } + /** + * Generate the URI of a route using names. + * + * @param string $name The identifier of the route. + * @param string|array $args The route arguments. + * + * @return string The generated URI. + */ + public static function url($name, $args = null) + { + return self::$router->route($name, $args); + } + /** * Handle requests. * @@ -127,6 +142,13 @@ class Router $url = self::parseUrl($url); // Handle the request - return self::$dispatcher->dispatch($method, $url); + try { + try { + return self::$dispatcher->dispatch($method, $url); + } catch (HttpMethodNotAllowedException $e) {} + } catch (HttpRouteNotFoundException $e) {} + + // Default to the not found page + return Template::render('global/notfound'); } } diff --git a/libraries/Template.php b/libraries/Template.php index e0e3a31..c2bb7a9 100644 --- a/libraries/Template.php +++ b/libraries/Template.php @@ -24,51 +24,40 @@ class Template * * @var array */ - private $vars = []; + private static $vars = []; /** * The templating engine. * * @var Twig_Environment */ - private $template; + private static $template; /** * The template name. * * @var string */ - private $templateName; + private static $templateName; /** * The template options. * * @var array */ - private $templateOptions; + private static $templateOptions; /** * The file extension used by template files - * - * @var string */ - protected $templateFileExtension = ".twig"; - - /** - * Constructor. - */ - public function __construct() - { - // Set template to default - $this->setTemplate(Config::get('site_style')); - } + const FILE_EXT = '.twig'; /** * Set the template name. * * @param string $name The name of the template directory. */ - public function setTemplate($name) + public static function set($name) { // Assign config path to a variable so we don't have to type it out twice $confPath = ROOT . 'templates/' . $name . '/template.ini'; @@ -79,22 +68,22 @@ class Template } // Parse and store the configuration - $this->templateOptions = parse_ini_file($confPath, true); + self::$templateOptions = parse_ini_file($confPath, true); // Set variables - $this->templateName = $name; + self::$templateName = $name; // Reinitialise - $this->initTemplate(); + self::init(); } /** * Initialise the templating engine. */ - public function initTemplate() + public static function init() { // Initialise Twig Filesystem Loader - $twigLoader = new Twig_Loader_Filesystem(ROOT . 'templates/' . $this->templateName); + $twigLoader = new Twig_Loader_Filesystem(ROOT . 'templates/' . self::$templateName); // Environment variable $twigEnv = []; @@ -105,10 +94,10 @@ class Template } // And now actually initialise the templating engine - $this->template = new Twig_Environment($twigLoader, $twigEnv); + self::$template = new Twig_Environment($twigLoader, $twigEnv); // Load String template loader - $this->template->addExtension(new Twig_Extension_StringLoader()); + self::$template->addExtension(new Twig_Extension_StringLoader()); } /** @@ -116,9 +105,9 @@ class Template * * @param array $vars The new variables. */ - public function setVariables($vars) + public static function vars($vars) { - $this->vars = array_merge($this->vars, $vars); + self::$vars = array_merge(self::$vars, $vars); } /** @@ -128,10 +117,10 @@ class Template * * @return bool|string An error or the HTML. */ - public function render($file) + public static function render($file) { try { - return $this->template->render($file . $this->templateFileExtension, $this->vars); + return self::$template->render($file . self::FILE_EXT, self::$vars); } catch (\Exception $e) { return trigger_error($e->getMessage(), E_USER_ERROR); } diff --git a/public/404.php b/public/404.php deleted file mode 100644 index 858aa2d..0000000 --- a/public/404.php +++ /dev/null @@ -1,25 +0,0 @@ -setTemplate($templateName); - -// Set parse variables -$template->setVariables($renderData); - -// Print page contents -echo $template->render('global/notfound'); diff --git a/public/authenticate.php b/public/authenticate.php index 8fa7099..5901e0d 100644 --- a/public/authenticate.php +++ b/public/authenticate.php @@ -9,12 +9,6 @@ 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); - // Page actions if (isset($_REQUEST['mode'])) { // Continue @@ -108,7 +102,6 @@ if (isset($_REQUEST['mode'])) { // Add page specific things $renderData['page'] = [ - 'redirect' => ( $passforget[0] ? $urls->format('SITE_LOGIN') : @@ -116,7 +109,6 @@ if (isset($_REQUEST['mode'])) { ), 'message' => $messages[$passforget[1]], 'success' => $passforget[0], - ]; break; @@ -289,8 +281,8 @@ if (isset($_REQUEST['mode'])) { $renderData['page']['success'] . '|' . $renderData['page']['redirect']; } else { - $template->setVariables($renderData); - echo $template->render('global/information'); + Template::vars($renderData); + echo Template::render('global/information'); } exit; } @@ -317,8 +309,8 @@ if (Users::checkLogin()) { ]; - $template->setVariables($renderData); - echo $template->render('global/information'); + Template::vars($renderData); + echo Template::render('global/information'); exit; } @@ -341,11 +333,11 @@ if (isset($_REQUEST['pw']) && $_REQUEST['pw']) { $renderData['auth']['forgotKey'] = $_REQUEST['key']; } - $template->setVariables($renderData); - echo $template->render('main/forgotpassword'); + Template::vars($renderData); + echo Template::render('main/forgotpassword'); exit; } // Print page contents -$template->setVariables($renderData); -echo $template->render('main/authenticate'); +Template::vars($renderData); +echo Template::render('main/authenticate'); diff --git a/public/manage.php b/public/manage.php index 6b5ebe7..58ba6f4 100644 --- a/public/manage.php +++ b/public/manage.php @@ -15,19 +15,13 @@ define('SAKURA_MANAGE', true); // Include components require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php'; -// Initialise templating engine -$template = new Template(); - -// Change templating engine -$template->setTemplate($templateName); - // Make sure user has the permissions to view this if (!$currentUser->permission(Manage::USE_MANAGE, Perms::MANAGE)) { // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/restricted'); + echo Template::render('global/restricted'); exit; } @@ -268,10 +262,10 @@ if (!$category header('HTTP/1.0 404 Not Found'); // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/notfound'); + echo Template::render('global/notfound'); exit; } @@ -313,7 +307,7 @@ switch ($category . '.' . $mode) { } // Set parse variables -$template->setVariables($renderData); +Template::vars($renderData); // Print page contents -echo $template->render('main/settings'); +echo Template::render('main/settings'); diff --git a/public/members.php b/public/members.php deleted file mode 100644 index 06f440d..0000000 --- a/public/members.php +++ /dev/null @@ -1,43 +0,0 @@ -setTemplate($templateName); - -// CHeck if the user is logged in -if (Users::checkLogin()) { - // Add page specific things - $renderData['memberlist'] = [ - 'ranks' => ($_MEMBERLIST_RANKS = Users::getAllRanks()), - 'active' => ($_MEMBERLIST_ACTIVE = ( - isset($_GET['rank']) - && $_GET['rank'] - && array_key_exists($_GET['rank'], $_MEMBERLIST_RANKS) ? $_GET['rank'] : 0 - )), - 'users' => ($_MEMBERLIST_ACTIVE ? Users::getUsersInRank($_MEMBERLIST_ACTIVE) : Users::getAllUsers(false)), - 'membersPerPage' => Config::get('members_per_page'), - ]; - - // Set parse variables - $template->setVariables($renderData); - - // Print page contents - echo $template->render('main/memberlist'); -} else { - // Set parse variables - $template->setVariables($renderData); - - // Print page contents - echo $template->render('global/restricted'); -} diff --git a/public/posting.php b/public/posting.php index 4cd86c3..5391b96 100644 --- a/public/posting.php +++ b/public/posting.php @@ -12,12 +12,6 @@ use Sakura\Perms\Forum as ForumPerms; // 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 location $topicId = isset($_GET['t']) ? $_GET['t'] : @@ -48,10 +42,10 @@ if (!$forum->permission(ForumPerms::VIEW, $currentUser->id) || !$forum->permissi ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -64,10 +58,10 @@ if (!isset($thread) && !$forum->permission(ForumPerms::CREATE_THREADS, $currentU ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -92,10 +86,10 @@ if ($mode != 'f') { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -108,10 +102,10 @@ if ($mode != 'f') { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -134,10 +128,10 @@ if ($mode != 'f') { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } // Checks @@ -149,10 +143,10 @@ if ($mode != 'f') { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -176,10 +170,10 @@ if ($mode != 'f') { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -192,10 +186,10 @@ if ($mode != 'f') { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -225,10 +219,10 @@ if ($mode != 'f') { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; // Return to previous page } else { @@ -246,10 +240,10 @@ if ($mode != 'f') { ]); // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/confirm'); + echo Template::render('global/confirm'); exit; } @@ -296,10 +290,10 @@ if (isset($_POST['post'])) { $renderData['page']['redirect']; } else { // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); } exit; } @@ -310,7 +304,7 @@ $renderData = array_merge($renderData, [ ]); // Set parse variables -$template->setVariables($renderData); +Template::vars($renderData); // Print page contents -echo $template->render('forum/posting'); +echo Template::render('forum/posting'); diff --git a/public/profile.php b/public/profile.php deleted file mode 100644 index ae94d96..0000000 --- a/public/profile.php +++ /dev/null @@ -1,86 +0,0 @@ -setTemplate($templateName); - -// Get the user's context -$profile = User::construct(isset($_GET['u']) ? $_GET['u'] : 0); - -// Views array -$views = [ - 'index', - 'friends', - //'threads', - //'posts', - 'comments', - //'groups', -]; - -// Assign the object to a renderData variable -$renderData['profile'] = $profile; -$renderData['profileView'] = isset($_GET['view']) && in_array($_GET['view'], $views) ? $_GET['view'] : $views[0]; - -// If the user id is zero check if there was a namechange -if ($profile->id == 0) { - // Fetch from username_history - $check = Database::fetch('username_history', false, ['username_old_clean' => [Utils::cleanString(isset($_GET['u']) ? $_GET['u'] : 0, true, true), '=']]); - - // Redirect if so - if ($check) { - $renderData['page'] = [ - 'message' => 'The user this profile belongs to changed their username, you are being redirected.', - 'redirect' => $urls->format('USER_PROFILE', [$check['user_id']]), - ]; - - // Set parse variables - $template->setVariables($renderData); - - // Print page contents - echo $template->render('global/information'); - exit; - } -} - -// If the user id is zero check if there was a namechange -if (isset($_GET['restrict']) && $_GET['restrict'] == session_id() && $currentUser->permission(Perms\Manage::CAN_RESTRICT_USERS, Perms::MANAGE)) { - // Check restricted status - $restricted = $profile->permission(Perms\Site::RESTRICTED); - - if ($restricted) { - $profile->removeRanks([Config::get('restricted_rank_id')]); - $profile->addRanks([2]); - } else { - $profile->addRanks([Config::get('restricted_rank_id')]); - $profile->removeRanks(array_keys($profile->ranks)); - } - - $renderData['page'] = [ - 'message' => 'Toggled the restricted status of the user.', - 'redirect' => $urls->format('USER_PROFILE', [$profile->id]), - ]; - - // Set parse variables - $template->setVariables($renderData); - - // Print page contents - echo $template->render('global/information'); - exit; -} - -// Set parse variables -$template->setVariables($renderData); - -// Print page contents -echo $template->render('main/profile'); diff --git a/public/report.php b/public/report.php deleted file mode 100644 index bf895ef..0000000 --- a/public/report.php +++ /dev/null @@ -1,22 +0,0 @@ -setTemplate($templateName); - -// Set parse variables -$template->setVariables($renderData); - -// Print page contents -echo $template->render('main/report'); diff --git a/public/settings.php b/public/settings.php index 2edafc4..181a217 100644 --- a/public/settings.php +++ b/public/settings.php @@ -16,14 +16,6 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification // Include components require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php'; -if (!defined('SAKURA_NO_TPL')) { - // Initialise templating engine - $template = new Template(); - - // Change templating engine - $template->setTemplate($templateName); -} - // Notifications if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notifications']) { // Create the notification container array @@ -275,10 +267,10 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification $renderData['page']['redirect']; } else { // If not allowed print the restricted page - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); } exit; } elseif (isset($_REQUEST['friend-action']) && $_REQUEST['friend-action'] && Users::checkLogin()) { @@ -404,10 +396,10 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification $renderData['page']['redirect']; } else { // If not allowed print the restricted page - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); } exit; } elseif (isset($_POST['submit']) && isset($_POST['submit'])) { @@ -1158,10 +1150,10 @@ if (isset($_REQUEST['request-notifications']) && $_REQUEST['request-notification $renderData['page']['redirect']; } else { // If not allowed print the restricted page - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); } exit; } @@ -1429,10 +1421,10 @@ if (Users::checkLogin()) { header('HTTP/1.0 404 Not Found'); // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/notfound'); + echo Template::render('global/notfound'); exit; } @@ -1518,14 +1510,14 @@ if (Users::checkLogin()) { } // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('main/settings'); + echo Template::render('main/settings'); } else { // If not allowed print the restricted page - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/restricted'); + echo Template::render('global/restricted'); } diff --git a/public/support.php b/public/support.php index 9eea190..75e4e39 100644 --- a/public/support.php +++ b/public/support.php @@ -11,12 +11,6 @@ use Sakura\Perms\Site; // Include components require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php'; -// Initialise templating engine -$template = new Template(); - -// Change templating engine -$template->setTemplate($templateName); - // Switch between modes (we only allow this to be used by logged in user) if (isset($_REQUEST['mode']) && Users::checkLogin() @@ -126,10 +120,10 @@ if (isset($_REQUEST['mode']) ], $renderData); // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('main/premiumcomplete'); + echo Template::render('main/premiumcomplete'); break; default: @@ -147,10 +141,10 @@ if (isset($_GET['tracker'])) { $renderData['tracker'] = Utils::getPremiumTrackerData(); // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('main/supporttracker'); + echo Template::render('main/supporttracker'); exit; } @@ -165,7 +159,7 @@ $renderData['page'] = [ ]; // Set parse variables -$template->setVariables($renderData); +Template::vars($renderData); // Print page contents -echo $template->render('main/support'); +echo Template::render('main/support'); diff --git a/public/viewforum.php b/public/viewforum.php deleted file mode 100644 index ad36927..0000000 --- a/public/viewforum.php +++ /dev/null @@ -1,104 +0,0 @@ -setTemplate($templateName); - -// Check if the forum exists -if ($forum->id < 0) { - // Set render data - $renderData['page'] = [ - 'title' => 'Information', - 'message' => 'The forum you tried to access does not exist.', - ]; - - // Set parse variables - $template->setVariables($renderData); - - // Print page contents - echo $template->render('global/information'); - exit; -} - -// Check if the user has access to the forum -if (!$forum->permission(ForumPerms::VIEW, $currentUser->id)) { - // Set render data - $renderData['page'] = [ - 'title' => 'Information', - 'message' => 'You do not have access to this forum.', - ]; - - // Set parse variables - $template->setVariables($renderData); - - // Print page contents - echo $template->render('global/information'); - exit; -} - -// Check if the forum isn't a link -if ($forum->type === 2) { - // Set render data - $renderData['page'] = [ - 'title' => 'Information', - 'message' => 'The forum you tried to access is a link. You\'re being redirected.', - 'redirect' => $forum->link, - ]; - - // Set parse variables - $template->setVariables($renderData); - - // Print page contents - echo $template->render('global/information'); - exit; -} - -// Check if we're marking as read -if (isset($_GET['read']) && $_GET['read'] && isset($_GET['session']) && $_GET['session'] == session_id()) { - // Run the function - $forum->trackUpdateAll($currentUser->id); - - // Set render data - $renderData['page'] = [ - 'title' => 'Information', - 'message' => 'All threads have been marked as read.', - 'redirect' => $urls->format('FORUM_SUB', [$forum->id]), - ]; - - // Set parse variables - $template->setVariables($renderData); - - // Print page contents - echo $template->render('global/information'); - exit; -} - -// Redirect forum id 0 to the main page -if ($forum->id === 0) { - header('Location: ' . $urls->format('FORUM_INDEX')); - exit; -} - -$renderData['forum'] = $forum; - -// Set parse variables -$template->setVariables($renderData); - -// Print page contents -echo $template->render('forum/viewforum'); diff --git a/public/viewtopic.php b/public/viewtopic.php index 2c7af53..7623ed8 100644 --- a/public/viewtopic.php +++ b/public/viewtopic.php @@ -21,12 +21,6 @@ $thread = new Forum\Thread( // And attempt to get the forum $forum = new Forum\Forum($thread->forum); -// Initialise templating engine -$template = new Template(); - -// Change templating engine -$template->setTemplate($templateName); - // Check if the forum exists if (!$thread) { // Set render data @@ -36,10 +30,10 @@ if (!$thread) { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -52,10 +46,10 @@ if (!$forum->permission(ForumPerms::VIEW, $currentUser->id)) { ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -78,10 +72,10 @@ if (isset($_GET['sticky']) && $_GET['sticky'] == session_id() && $forum->permiss ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -103,10 +97,10 @@ if (isset($_GET['announce']) && $_GET['announce'] == session_id() && $forum->per ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -128,10 +122,10 @@ if (isset($_GET['lock']) && $_GET['lock'] == session_id() && $forum->permission( ]; // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -155,10 +149,10 @@ if (isset($_GET['trash']) && $_GET['trash'] == session_id() && $forum->permissio } // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -183,10 +177,10 @@ if (isset($_GET['restore']) && $_GET['restore'] == session_id() && $forum->permi } // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -210,10 +204,10 @@ if (isset($_GET['prune']) && $_GET['prune'] == session_id() && $forum->permissio } // Set parse variables - $template->setVariables($renderData); + Template::vars($renderData); // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } @@ -230,7 +224,7 @@ $renderData = array_merge($renderData, [ ]); // Set parse variables -$template->setVariables($renderData); +Template::vars($renderData); // Print page contents -echo $template->render('forum/viewtopic'); +echo Template::render('forum/viewtopic'); diff --git a/routes.php b/routes.php index 66ac099..968292c 100644 --- a/routes.php +++ b/routes.php @@ -18,7 +18,15 @@ 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'); +Router::get('/forum', 'Sakura\Controllers\Forums@index', 'forums.index'); +Router::get('/forum/{id}', 'Sakura\Controllers\Forums@forum', 'forums.forum'); + +// Members +Router::get('/members', 'Sakura\Controllers\User@members', 'members.all'); +Router::get('/members/{rank}', 'Sakura\Controllers\User@members', 'members.rank'); + +// User +Router::get('/u/{id}', 'Sakura\Controllers\User@profile', 'user.profile'); // Redirections Router::any('/index.php', function () { @@ -61,6 +69,51 @@ Router::any('/news.php', function () { header('Location: /news'); }); +Router::any('/profile.php', function () { + // Redirect to the profile + if (isset($_REQUEST['u'])) { + header('Location: /u/' . $_REQUEST['u']); + return; + } + + // Redirect to index + header('Location: /'); +}); + +Router::any('/members.php', function () { + // Append sort + $append = isset($_REQUEST['sort']) ? '?sort=' . $_REQUEST['sort'] : ''; + + // Redirect to the profile + if (isset($_REQUEST['rank'])) { + header('Location: /members/' . $_REQUEST['rank'] . $append); + return; + } + + // Redirect to index + header('Location: /members/' . $append); +}); + +Router::any('/viewforum.php', function () { + // Redirect to the profile + if (isset($_REQUEST['f'])) { + $req = []; + foreach ($_REQUEST as $k => $v) { + if ($k == 'f') { + continue; + } + + $req[] = $k . '=' . $v; + } + + header('Location: /forum/' . $_REQUEST['f'] . ($req ? '?' . implode('&', $req) : '')); + return; + } + + // Redirect to index + header('Location: /forum/'); +}); + Router::any('/faq.php', function () { header('Location: /faq'); }); diff --git a/sakura.php b/sakura.php index d3e8bcb..07d46b5 100644 --- a/sakura.php +++ b/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20160202'); +define('SAKURA_VERSION', '20160204'); define('SAKURA_VLABEL', 'Amethyst'); define('SAKURA_COLOUR', '#9966CC'); @@ -59,8 +59,9 @@ 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/Forums.php'; require_once ROOT . 'libraries/Controllers/Meta.php'; +require_once ROOT . 'libraries/Controllers/User.php'; require_once ROOT . 'libraries/Forum/Forum.php'; require_once ROOT . 'libraries/Forum/Post.php'; require_once ROOT . 'libraries/Forum/Thread.php'; @@ -140,6 +141,9 @@ $templateName = 'misaki' : Config::get('site_style'); if (!defined('SAKURA_NO_TPL')) { + // Start templating engine + Template::set($templateName); + // Set base page rendering data $renderData = [ 'sakura' => [ @@ -202,33 +206,27 @@ if (!defined('SAKURA_NO_TPL')) { 'post' => $_POST, ]; + // Add the default render data + Template::vars($renderData); + // Site closing if (Config::get('site_closed')) { - // Additional render data - $renderData = array_merge($renderData, [ + // Set parse variables + Template::vars([ 'page' => [ 'message' => Config::get('site_closed_reason'), ], ]); - // Initialise templating engine - $template = new Template(); - - // Change templating engine - $template->setTemplate($templateName); - - // Set parse variables - $template->setVariables($renderData); - // Print page contents - echo $template->render('global/information'); + echo Template::render('global/information'); exit; } // Ban checking if ($authCheck && !in_array($_SERVER['PHP_SELF'], [$urls->format('AUTH_ACTION', [], false)]) && $ban = Bans::checkBan($currentUser->id)) { // Additional render data - $renderData = array_merge($renderData, [ + Template::vars([ 'ban' => [ 'reason' => $ban['reason'], 'issued' => $ban['issued'], @@ -237,17 +235,8 @@ if (!defined('SAKURA_NO_TPL')) { ], ]); - // 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/banned'); + echo Template::render('main/banned'); exit; } } diff --git a/server.php b/server.php index d3f69d7..bb028b0 100644 --- a/server.php +++ b/server.php @@ -3,10 +3,13 @@ * mod_rewrite emulator for php's build in server */ +// Decode and parse the request uri $uri = urldecode(parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)); +// Check if the file exist in the public directory and if it does serve it. if ($uri !== '/' && file_exists(__DIR__ . '/public' . $uri)) { return false; } +// Otherwise include the router require_once __DIR__ . '/public/index.php'; diff --git a/templates/yuuno/forum/index.twig b/templates/yuuno/forum/index.twig index 4acb320..f0f2f33 100644 --- a/templates/yuuno/forum/index.twig +++ b/templates/yuuno/forum/index.twig @@ -4,8 +4,6 @@ {% block title %}{{ title }}{% endblock %} -{% set forumMarkRead %}{{ urls.format('FORUM_MARK_READ', [forum.id, php.sessionid]) }}{% endset %} - {% block content %}
@@ -13,7 +11,6 @@
{% include 'forum/forum.twig' %} - {% include 'forum/forumBtns.twig' %}
diff --git a/templates/yuuno/main/profile.twig b/templates/yuuno/main/profile.twig index b44b547..b414616 100644 --- a/templates/yuuno/main/profile.twig +++ b/templates/yuuno/main/profile.twig @@ -8,6 +8,55 @@ {% block title %}{% if profileHidden %}User not found!{% else %}Profile of {{ profile.username }}{% endif %}{% endblock %} +{% block js %} + +{% endblock %} + {% block content %} {% if profileHidden %}
@@ -22,133 +71,6 @@
- {% elseif get.old %} -
-
-
- {{ profile.username }}'s Avatar
- {% if profile.mainRankId > 1 and profile.checkBan|length < 1 %} - {{ profile.title }} -

{{ profile.username }}

- {% if profile.isPremium[0] %}Tenshi {% endif %}{{ profile.country }} {{ profile.country(true) }} - {% if session.checkLogin %} - - {% endif %} -
- Joined {{ profile.elapsed.joined }} -
- {% if profile.lastOnline < 1 %} - {{ profile.username }} hasn't logged in yet. - {% else %} - Last online {{ profile.elapsed.lastOnline }} - {% endif %} -
- {{ profile.username }} has {% if not profile.forumStats.posts %}no{% else %}{{ profile.forumStats.posts }}{% endif %} forum post{% if profile.forumStats.posts != 1 %}s{% endif %}. - {% if profile.birthday != '0000-00-00' and profile.birthday|split('-')[0] > 0 %} -
Age {{ profile.birthday(true) }} years old - {% endif %} - {% if profile.profileFields or user.permission(constant('Sakura\\Perms\\Manage::USE_MANAGE'), constant('Sakura\\Perms::MANAGE')) %} -
- {% if session.checkLogin %} - - {% for name,field in profile.profileFields %} - - - - - {% endfor %} - {% if user.permission(constant('Sakura\\Perms\\Manage::USE_MANAGE'), constant('Sakura\\Perms::MANAGE')) %} - - - - - - - - - - - - - {% endif %} -
- {{ field.name }} - - {% if name == 'youtube' %} - {% if field.youtubetype == true %}{{ profile.username }}'s Channel{% else %}{{ field.value }}{% endif %} - {% else %} - {% if field.islink %} - - {% endif %} - {{ field.value }} - {% if field.islink %} - - {% endif %} - {% endif %} -
E-mail address{{ profile.email }}
Register IP{{ profile.registerIp }}
Last IP{{ profile.lastIp }}
- {% else %} - Log in to view the full profile! - {% endif %} - {% endif %} - {% else %} -

{{ profile.username }}

- {% endif %} -
- Account Standing - {% if profile.permission(constant('Sakura\\Perms\\Site::DEACTIVATED')) %} -

Deactivated

- {% elseif profile.checkBan %} -

Banned

- {% elseif profile.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) %} -

Restricted

- {% elseif profile.getWarnings %} -

Bad

- {% else %} -

Good

- {% endif %} - {% if profile.getWarnings %} - - - - - - - {% for warning in profile.getWarnings %} - - - - - - {% endfor %} -
ActionDurationReason
{{ warning.warning_action_text }}{{ warning.warning_length }} minute{% if warning.warning_length != 1 %}s{% endif %}{{ warning.warning_reason }}
- {% endif %} -
-
-
- {% include 'profile/' ~ profileView ~ '.twig' %} -
-
-
{% else %}
@@ -175,14 +97,14 @@
- - {# - #} - - {##} {% if not noUserpage %} - + {% endif %} + {# + #} + + {##} +
{% if session.checkLogin %}
@@ -201,8 +123,24 @@
-
- {% include 'profile/' ~ profileView ~ '.twig' %} + + + + + + +
diff --git a/templates/yuuno/profile/index.twig b/templates/yuuno/profile/userpage.twig similarity index 100% rename from templates/yuuno/profile/index.twig rename to templates/yuuno/profile/userpage.twig