diff --git a/libraries/ActiveUser.php b/libraries/ActiveUser.php index a4c94a9..ee09b32 100644 --- a/libraries/ActiveUser.php +++ b/libraries/ActiveUser.php @@ -39,6 +39,7 @@ class ActiveUser ->where('user_id', self::$user->id) ->update([ 'user_last_online' => time(), + 'last_ip' => Net::pton(Net::ip()), ]); } else { self::$user = User::construct(0); diff --git a/libraries/Controllers/ForumController.php b/libraries/Controllers/ForumController.php index 61bc3e6..ec6fa10 100644 --- a/libraries/Controllers/ForumController.php +++ b/libraries/Controllers/ForumController.php @@ -36,6 +36,7 @@ class ForumController extends Controller { // Get the most active threads $activeThreadsIds = DB::table('posts') + ->where('forum_id', '!=', Config::get('forum_trash_id')) ->groupBy('topic_id') ->orderByRaw('COUNT(*) DESC') ->limit(10) @@ -69,6 +70,7 @@ class ForumController extends Controller // Get the latest posts $latestPostsIds = DB::table('posts') + ->where('forum_id', '!=', Config::get('forum_trash_id')) ->orderBy('post_id', 'desc') ->limit(10) ->get(['post_id']); @@ -100,6 +102,7 @@ class ForumController extends Controller // Get the most active poster $activePosterId = DB::table('posts') + ->where('forum_id', '!=', Config::get('forum_trash_id')) ->where('post_time', '>', time() - (24 * 60 * 60)) ->groupBy('poster_id') ->orderByRaw('COUNT(*) DESC') diff --git a/libraries/Controllers/MetaController.php b/libraries/Controllers/MetaController.php index d2b3fa3..74399c7 100644 --- a/libraries/Controllers/MetaController.php +++ b/libraries/Controllers/MetaController.php @@ -69,15 +69,15 @@ class MetaController extends Controller 'stats' => [ 'userCount' => DB::table('users') ->where('password_algo', '!=', 'disabled') - ->whereNotIn('rank_main', [1, 10]) + ->whereNotIn('rank_main', [Config::get('deactive_rank_id'), Config::get('restricted_rank_id')]) ->count(), 'newestUser' => $newestUser, 'lastRegDate' => date_diff( date_create(date('Y-m-d', $newestUser->registered)), date_create(date('Y-m-d')) )->format('%a'), - 'topicCount' => DB::table('topics')->count(), - 'postCount' => DB::table('posts')->count(), + '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(), 'onlineUsers' => $onlineUsers, ], ]); diff --git a/libraries/Controllers/Settings/AdvancedController.php b/libraries/Controllers/Settings/AdvancedController.php index 42a50a7..4740bec 100644 --- a/libraries/Controllers/Settings/AdvancedController.php +++ b/libraries/Controllers/Settings/AdvancedController.php @@ -82,8 +82,9 @@ class AdvancedController extends Controller $sessions = DB::table('sessions') ->where('user_id', ActiveUser::$user->id) ->get(); + $active = ActiveUser::$session->sessionId; - Template::vars(compact('sessions')); + Template::vars(compact('sessions', 'active')); return Template::render('settings/advanced/sessions'); } diff --git a/libraries/Exception.php b/libraries/Exception.php new file mode 100644 index 0000000..05b985e --- /dev/null +++ b/libraries/Exception.php @@ -0,0 +1,18 @@ + + */ +class Exception extends \Exception +{ +} diff --git a/libraries/Forum/Post.php b/libraries/Forum/Post.php index 7d7e252..f5a6026 100644 --- a/libraries/Forum/Post.php +++ b/libraries/Forum/Post.php @@ -10,6 +10,7 @@ namespace Sakura\Forum; use Sakura\BBcode; use Sakura\Config; use Sakura\DB; +use Sakura\Exception; use Sakura\Net; use Sakura\User; @@ -124,13 +125,20 @@ class Post $this->thread = $postRow->topic_id; $this->forum = $postRow->forum_id; $this->poster = User::construct($postRow->poster_id); - $this->ip = $postRow->poster_ip; $this->time = $postRow->post_time; $this->subject = $postRow->post_subject; $this->text = $postRow->post_text; $this->editTime = $postRow->post_edit_time; $this->editReason = $postRow->post_edit_reason; $this->editUser = User::construct($postRow->post_edit_user); + + // Temporary backwards compatible IP storage system + try { + $this->ip = Net::ntop($postRow->poster_ip); + } catch (Exception $e) { + $this->ip = $postRow->poster_ip; + $this->update(); + } } // Parse the markup @@ -168,7 +176,7 @@ class Post 'topic_id' => $thread->id, 'forum_id' => $thread->forum, 'poster_id' => $poster->id, - 'poster_ip' => Net::ip(), + 'poster_ip' => Net::pton(Net::ip()), 'post_time' => time(), 'post_subject' => $subject, 'post_text' => $text, @@ -235,6 +243,11 @@ class Post */ public function unread($user) { + // Return false if the user id is less than 1 + if ($user < 1) { + return false; + } + // Attempt to get track row from the database $track = DB::table('topics_track') ->where('user_id', $user) diff --git a/libraries/Forum/Thread.php b/libraries/Forum/Thread.php index 18dcf57..af0ac93 100644 --- a/libraries/Forum/Thread.php +++ b/libraries/Forum/Thread.php @@ -347,6 +347,11 @@ class Thread */ public function unread($user) { + // Return false if the user id is less than 1 + if ($user < 1) { + return false; + } + // Attempt to get track row from the database $track = DB::table('topics_track') ->where('user_id', $user) diff --git a/libraries/Net.php b/libraries/Net.php index 3545ab4..a8048ef 100644 --- a/libraries/Net.php +++ b/libraries/Net.php @@ -56,7 +56,7 @@ class Net * * @param string $ip Printable IP string. * - * @throws \Exception Thrown if an invalid IP is supplied. + * @throws Exception Thrown if an invalid IP is supplied. * * @return string Unpacked IP address. */ @@ -76,7 +76,7 @@ class Net } // Throw an exception if an invalid IP was supplied - throw new \Exception("Invalid IP address supplied."); + throw new Exception("Invalid IP address supplied."); } /** @@ -84,7 +84,7 @@ class Net * * @param string $bin The unpacked IP. * - * @throws \Exception Thrown if the unpacked IP is invalid. + * @throws Exception Thrown if the unpacked IP is invalid. * * @return string The packed IP. */ @@ -95,7 +95,7 @@ class Net // Throw an exception if it's not 4 or 16 bytes if ($len !== 4 && $len !== 16) { - throw new \Exception("Could not handle this IP type."); + throw new Exception("Could not handle this IP type."); } // Finally pack the IP diff --git a/libraries/Session.php b/libraries/Session.php index e7a9fbc..3336845 100644 --- a/libraries/Session.php +++ b/libraries/Session.php @@ -133,51 +133,8 @@ class Session return 0; } - // IP Check - $ipCheck = false; // Forced disabled due to incompatibility with the Net class. -- Config::get('session_check'); - - // Origin checking - if ($ipCheck) { - // Split both IPs up - $sessionIP = explode('.', $session[0]->user_ip); - $userIP = explode('.', Net::ip()); - - // Take 1 off the ipCheck variable so it's equal to the array keys - $ipCheck = $ipCheck - 1; - - // Check if the user's IP is similar to the session's registered IP - switch ($ipCheck) { - // 000.xxx.xxx.xxx - case 3: - if ($userIP[3] !== $sessionIP[3]) { - return 0; - } - - // xxx.000.xxx.xxx - case 2: - case 3: - if ($userIP[2] !== $sessionIP[2]) { - return 0; - } - - // xxx.xxx.000.xxx - case 1: - case 2: - case 3: - if ($userIP[1] !== $sessionIP[1]) { - return 0; - } - - // xxx.xxx.xxx.000 - case 0: - case 1: - case 2: - case 3: - if ($userIP[0] !== $sessionIP[0]) { - return 0; - } - } - } + /* completely removed the code for ip checking because it only worked with IPv4 + good thing is i can probably do CIDR based checking */ // If the remember flag is set extend the session time if ($session[0]->session_remember) { diff --git a/libraries/User.php b/libraries/User.php index b4a4802..8607ab6 100644 --- a/libraries/User.php +++ b/libraries/User.php @@ -316,8 +316,6 @@ class User $this->email = $userRow->email; $this->mainRankId = $userRow->rank_main; $this->colour = $userRow->user_colour; - $this->registerIp = Net::ntop($userRow->register_ip); - $this->lastIp = Net::ntop($userRow->last_ip); $this->title = $userRow->user_title; $this->registered = $userRow->user_registered; $this->lastOnline = $userRow->user_last_online; @@ -328,6 +326,31 @@ class User $this->header = $userRow->user_header; $this->page = $userRow->user_page; $this->signature = $userRow->user_signature; + + // Temporary backwards compatible IP storage system + try { + $this->registerIp = Net::ntop($userRow->register_ip); + } catch (Exception $e) { + $this->registerIp = $userRow->register_ip; + + DB::table('users') + ->where('user_id', $this->id) + ->update([ + 'register_ip' => Net::pton($this->registerIp), + ]); + } + + try { + $this->lastIp = Net::ntop($userRow->last_ip); + } catch (Exception $e) { + $this->lastIp = $userRow->last_ip; + + DB::table('users') + ->where('user_id', $this->id) + ->update([ + 'last_ip' => Net::pton($this->lastIp), + ]); + } } // Get all ranks diff --git a/routes.php b/routes.php index e70dfdc..625b107 100644 --- a/routes.php +++ b/routes.php @@ -28,223 +28,239 @@ Router::filter('loginCheck', function () { } }); -// Meta pages -Router::get('/', 'MetaController@index', 'main.index'); -Router::get('/faq', 'MetaController@faq', 'main.faq'); -Router::get('/search', 'MetaController@search', 'main.search'); -Router::get('/p/{id}', 'MetaController@infoPage', 'main.infopage'); +// Maintenance check +Router::filter('maintenance', function () { + if (Config::get('site_closed')) { + ActiveUser::$session->destroy(); -// Auth -Router::group(['before' => 'logoutCheck'], function () { - Router::get('/login', 'AuthController@loginGet', 'auth.login'); - Router::post('/login', 'AuthController@loginPost', 'auth.login'); - Router::get('/register', 'AuthController@registerGet', 'auth.register'); - Router::post('/register', 'AuthController@registerPost', 'auth.register'); - Router::get('/resetpassword', 'AuthController@resetPasswordGet', 'auth.resetpassword'); - Router::post('/resetpassword', 'AuthController@resetPasswordPost', 'auth.resetpassword'); - Router::get('/reactivate', 'AuthController@reactivateGet', 'auth.reactivate'); - Router::post('/reactivate', 'AuthController@reactivatePost', 'auth.reactivate'); - Router::get('/activate', 'AuthController@activate', 'auth.activate'); -}); -Router::group(['before' => 'loginCheck'], function () { - Router::get('/logout', 'AuthController@logout', 'auth.logout'); + http_response_code(503); + + $message = Config::get('site_closed_reason'); + + Template::vars(compact('message')); + + return Template::render('global/maintenance'); + } }); -// News -Router::group(['prefix' => 'news'], function () { - Router::get('/{category:c}?', 'NewsController@category', 'news.category'); - Router::get('/post/{id:i}', 'NewsController@post', 'news.post'); -}); +Router::group(['before' => 'maintenance'], function () { + // Meta pages + Router::get('/', 'MetaController@index', 'main.index'); + Router::get('/faq', 'MetaController@faq', 'main.faq'); + Router::get('/search', 'MetaController@search', 'main.search'); + Router::get('/p/{id}', 'MetaController@infoPage', 'main.infopage'); -// Forum -Router::group(['prefix' => 'forum'], function () { - // Post - Router::group(['prefix' => 'post'], function () { - Router::get('/{id:i}', 'ForumController@post', 'forums.post'); - Router::group(['before' => 'loginCheck'], function () { - Router::get('/{id:i}/raw', 'ForumController@postRaw', 'forums.post.raw'); - Router::get('/{id:i}/delete', 'ForumController@deletePost', 'forums.post.delete'); - Router::post('/{id:i}/delete', 'ForumController@deletePost', 'forums.post.delete'); - Router::post('/{id:i}/edit', 'ForumController@editPost', 'forums.post.edit'); - }); + // Auth + Router::group(['before' => 'logoutCheck'], function () { + Router::get('/login', 'AuthController@loginGet', 'auth.login'); + Router::post('/login', 'AuthController@loginPost', 'auth.login'); + Router::get('/register', 'AuthController@registerGet', 'auth.register'); + Router::post('/register', 'AuthController@registerPost', 'auth.register'); + Router::get('/resetpassword', 'AuthController@resetPasswordGet', 'auth.resetpassword'); + Router::post('/resetpassword', 'AuthController@resetPasswordPost', 'auth.resetpassword'); + Router::get('/reactivate', 'AuthController@reactivateGet', 'auth.reactivate'); + Router::post('/reactivate', 'AuthController@reactivatePost', 'auth.reactivate'); + Router::get('/activate', 'AuthController@activate', 'auth.activate'); + }); + Router::group(['before' => 'loginCheck'], function () { + Router::get('/logout', 'AuthController@logout', 'auth.logout'); }); - // Thread - Router::group(['prefix' => 'thread'], function () { - Router::get('/{id:i}', 'ForumController@thread', 'forums.thread'); - Router::post('/{id:i}/mod', 'ForumController@threadModerate', 'forums.thread.mod'); - Router::post('/{id:i}/reply', 'ForumController@threadReply', 'forums.thread.reply'); + // News + Router::group(['prefix' => 'news'], function () { + Router::get('/{category:c}?', 'NewsController@category', 'news.category'); + Router::get('/post/{id:i}', 'NewsController@post', 'news.post'); }); // Forum - Router::get('/', 'ForumController@index', 'forums.index'); - Router::get('/{id:i}', 'ForumController@forum', 'forums.forum'); - Router::group(['before' => 'loginCheck'], function () { - Router::get('/{id:i}/mark', 'ForumController@markForumRead', 'forums.mark'); - Router::get('/{id:i}/new', 'ForumController@createThread', 'forums.new'); - Router::post('/{id:i}/new', 'ForumController@createThread', 'forums.new'); + Router::group(['prefix' => 'forum'], function () { + // Post + Router::group(['prefix' => 'post'], function () { + Router::get('/{id:i}', 'ForumController@post', 'forums.post'); + Router::group(['before' => 'loginCheck'], function () { + Router::get('/{id:i}/raw', 'ForumController@postRaw', 'forums.post.raw'); + Router::get('/{id:i}/delete', 'ForumController@deletePost', 'forums.post.delete'); + Router::post('/{id:i}/delete', 'ForumController@deletePost', 'forums.post.delete'); + Router::post('/{id:i}/edit', 'ForumController@editPost', 'forums.post.edit'); + }); + }); + + // Thread + Router::group(['prefix' => 'thread'], function () { + Router::get('/{id:i}', 'ForumController@thread', 'forums.thread'); + Router::post('/{id:i}/mod', 'ForumController@threadModerate', 'forums.thread.mod'); + Router::post('/{id:i}/reply', 'ForumController@threadReply', 'forums.thread.reply'); + }); + + // Forum + Router::get('/', 'ForumController@index', 'forums.index'); + Router::get('/{id:i}', 'ForumController@forum', 'forums.forum'); + Router::group(['before' => 'loginCheck'], function () { + Router::get('/{id:i}/mark', 'ForumController@markForumRead', 'forums.mark'); + Router::get('/{id:i}/new', 'ForumController@createThread', 'forums.new'); + Router::post('/{id:i}/new', 'ForumController@createThread', 'forums.new'); + }); }); -}); -// Members -Router::group(['prefix' => 'members', 'before' => 'loginCheck'], function () { - Router::get('/', 'UserController@members', 'members.index'); - Router::get('/{rank:i}', 'UserController@members', 'members.rank'); -}); - -// User -Router::group(['prefix' => 'u'], function () { - Router::get('/{id}', 'UserController@profile', 'user.profile'); - Router::get('/{id}/report', 'UserController@report', 'user.report'); - Router::get('/{id}/header', 'FileController@header', 'user.header'); -}); - -// Notifications -Router::group(['prefix' => 'notifications'], function () { - Router::get('/', 'NotificationsController@notifications', 'notifications.get'); - Router::get('/{id}/mark', 'NotificationsController@mark', 'notifications.mark'); -}); - -// Comments -Router::group(['prefix' => 'comments', 'before' => 'loginCheck'], function () { - Router::post('/{category:c}/post/{reply:i}?', 'CommentsController@post', 'comments.category.post'); - Router::post('/{id:i}/delete', 'CommentsController@delete', 'comments.comment.delete'); - Router::post('/{id:i}/vote', 'CommentsController@vote', 'comments.comment.vote'); -}); - -// Comments -Router::group(['prefix' => 'friends', 'before' => 'loginCheck'], function () { - Router::post('/{id:i}/add', 'FriendsController@add', 'friends.add'); - Router::post('/{id:i}/remove', 'FriendsController@remove', 'friends.remove'); -}); - -// Files -Router::get('/a/{id}', 'FileController@avatar', 'file.avatar'); -Router::get('/bg/{id}', 'FileController@background', 'file.background'); - -// Premium -Router::group(['prefix' => 'support', 'before' => 'loginCheck'], function () { - Router::get('/', 'PremiumController@index', 'premium.index'); - Router::get('/handle', 'PremiumController@handle', 'premium.handle'); - Router::get('/complete', 'PremiumController@complete', 'premium.complete'); - Router::post('/purchase', 'PremiumController@purchase', 'premium.purchase'); -}); - -// Helpers -Router::group(['prefix' => 'helper'], function () { - // BBcode - Router::group(['prefix' => 'bbcode', 'before' => 'loginCheck'], function () { - Router::post('/parse', 'HelperController@bbcodeParse', 'helper.bbcode.parse'); + // Members + Router::group(['prefix' => 'members', 'before' => 'loginCheck'], function () { + Router::get('/', 'UserController@members', 'members.index'); + Router::get('/{rank:i}', 'UserController@members', 'members.rank'); }); -}); -// Settings -Router::group(['prefix' => 'settings', 'before' => 'loginCheck'], function () { - Router::get('/', function () { - $route = Router::route('settings.general.home'); - return header("Location: {$route}"); - }, 'settings.index'); + // User + Router::group(['prefix' => 'u'], function () { + Router::get('/{id}', 'UserController@profile', 'user.profile'); + Router::get('/{id}/report', 'UserController@report', 'user.report'); + Router::get('/{id}/header', 'FileController@header', 'user.header'); + }); - // General section - Router::group(['prefix' => 'general'], function () { + // Notifications + Router::group(['prefix' => 'notifications'], function () { + Router::get('/', 'NotificationsController@notifications', 'notifications.get'); + Router::get('/{id}/mark', 'NotificationsController@mark', 'notifications.mark'); + }); + + // Comments + Router::group(['prefix' => 'comments', 'before' => 'loginCheck'], function () { + Router::post('/{category:c}/post/{reply:i}?', 'CommentsController@post', 'comments.category.post'); + Router::post('/{id:i}/delete', 'CommentsController@delete', 'comments.comment.delete'); + Router::post('/{id:i}/vote', 'CommentsController@vote', 'comments.comment.vote'); + }); + + // Comments + Router::group(['prefix' => 'friends', 'before' => 'loginCheck'], function () { + Router::post('/{id:i}/add', 'FriendsController@add', 'friends.add'); + Router::post('/{id:i}/remove', 'FriendsController@remove', 'friends.remove'); + }); + + // Files + Router::get('/a/{id}', 'FileController@avatar', 'file.avatar'); + Router::get('/bg/{id}', 'FileController@background', 'file.background'); + + // Premium + Router::group(['prefix' => 'support', 'before' => 'loginCheck'], function () { + Router::get('/', 'PremiumController@index', 'premium.index'); + Router::get('/handle', 'PremiumController@handle', 'premium.handle'); + Router::get('/complete', 'PremiumController@complete', 'premium.complete'); + Router::post('/purchase', 'PremiumController@purchase', 'premium.purchase'); + }); + + // Helpers + Router::group(['prefix' => 'helper'], function () { + // BBcode + Router::group(['prefix' => 'bbcode', 'before' => 'loginCheck'], function () { + Router::post('/parse', 'HelperController@bbcodeParse', 'helper.bbcode.parse'); + }); + }); + + // Settings + Router::group(['prefix' => 'settings', 'before' => 'loginCheck'], function () { Router::get('/', function () { $route = Router::route('settings.general.home'); return header("Location: {$route}"); + }, 'settings.index'); + + // General section + Router::group(['prefix' => 'general'], function () { + Router::get('/', function () { + $route = Router::route('settings.general.home'); + return header("Location: {$route}"); + }); + + Router::get('/home', 'Settings.GeneralController@home', 'settings.general.home'); + Router::get('/profile', 'Settings.GeneralController@profile', 'settings.general.profile'); + Router::post('/profile', 'Settings.GeneralController@profile', 'settings.general.profile'); + Router::get('/options', 'Settings.GeneralController@options', 'settings.general.options'); + Router::post('/options', 'Settings.GeneralController@options', 'settings.general.options'); }); - Router::get('/home', 'Settings.GeneralController@home', 'settings.general.home'); - Router::get('/profile', 'Settings.GeneralController@profile', 'settings.general.profile'); - Router::post('/profile', 'Settings.GeneralController@profile', 'settings.general.profile'); - Router::get('/options', 'Settings.GeneralController@options', 'settings.general.options'); - Router::post('/options', 'Settings.GeneralController@options', 'settings.general.options'); - }); + // Friends section + Router::group(['prefix' => 'friends'], function () { + Router::get('/', function () { + $route = Router::route('settings.friends.listing'); + return header("Location: {$route}"); + }); - // Friends section - Router::group(['prefix' => 'friends'], function () { - Router::get('/', function () { - $route = Router::route('settings.friends.listing'); - return header("Location: {$route}"); + Router::get('/listing', 'Settings.FriendsController@listing', 'settings.friends.listing'); + Router::get('/requests', 'Settings.FriendsController@requests', 'settings.friends.requests'); }); - Router::get('/listing', 'Settings.FriendsController@listing', 'settings.friends.listing'); - Router::get('/requests', 'Settings.FriendsController@requests', 'settings.friends.requests'); - }); + // Groups section + Router::group(['prefix' => 'groups'], function () { + Router::get('/', function () { + $route = Router::route('settings.groups.listing'); + return header("Location: {$route}"); + }); - // Groups section - Router::group(['prefix' => 'groups'], function () { - Router::get('/', function () { - $route = Router::route('settings.groups.listing'); - return header("Location: {$route}"); + Router::get('/listing', 'Settings.GroupsController@listing', 'settings.groups.listing'); + Router::get('/invites', 'Settings.GroupsController@invites', 'settings.groups.invites'); }); - Router::get('/listing', 'Settings.GroupsController@listing', 'settings.groups.listing'); - Router::get('/invites', 'Settings.GroupsController@invites', 'settings.groups.invites'); - }); + // Notifications section + Router::group(['prefix' => 'notifications'], function () { + Router::get('/', function () { + $route = Router::route('settings.notifications.history'); + return header("Location: {$route}"); + }); - // Notifications section - Router::group(['prefix' => 'notifications'], function () { - Router::get('/', function () { - $route = Router::route('settings.notifications.history'); - return header("Location: {$route}"); + Router::get('/history', 'Settings.NotificationsController@history', 'settings.notifications.history'); }); - Router::get('/history', 'Settings.NotificationsController@history', 'settings.notifications.history'); - }); + // Appearance section + Router::group(['prefix' => 'appearance'], function () { + Router::get('/', function () { + $route = Router::route('settings.appearance.avatar'); + return header("Location: {$route}"); + }); - // Appearance section - Router::group(['prefix' => 'appearance'], function () { - Router::get('/', function () { - $route = Router::route('settings.appearance.avatar'); - return header("Location: {$route}"); + Router::get('/avatar', 'Settings.AppearanceController@avatar', 'settings.appearance.avatar'); + Router::post('/avatar', 'Settings.AppearanceController@avatar', 'settings.appearance.avatar'); + Router::get('/background', 'Settings.AppearanceController@background', 'settings.appearance.background'); + Router::post('/background', 'Settings.AppearanceController@background', 'settings.appearance.background'); + Router::get('/header', 'Settings.AppearanceController@header', 'settings.appearance.header'); + Router::post('/header', 'Settings.AppearanceController@header', 'settings.appearance.header'); + Router::get('/userpage', 'Settings.AppearanceController@userpage', 'settings.appearance.userpage'); + Router::post('/userpage', 'Settings.AppearanceController@userpage', 'settings.appearance.userpage'); + Router::get('/signature', 'Settings.AppearanceController@signature', 'settings.appearance.signature'); + Router::post('/signature', 'Settings.AppearanceController@signature', 'settings.appearance.signature'); }); - Router::get('/avatar', 'Settings.AppearanceController@avatar', 'settings.appearance.avatar'); - Router::post('/avatar', 'Settings.AppearanceController@avatar', 'settings.appearance.avatar'); - Router::get('/background', 'Settings.AppearanceController@background', 'settings.appearance.background'); - Router::post('/background', 'Settings.AppearanceController@background', 'settings.appearance.background'); - Router::get('/header', 'Settings.AppearanceController@header', 'settings.appearance.header'); - Router::post('/header', 'Settings.AppearanceController@header', 'settings.appearance.header'); - Router::get('/userpage', 'Settings.AppearanceController@userpage', 'settings.appearance.userpage'); - Router::post('/userpage', 'Settings.AppearanceController@userpage', 'settings.appearance.userpage'); - Router::get('/signature', 'Settings.AppearanceController@signature', 'settings.appearance.signature'); - Router::post('/signature', 'Settings.AppearanceController@signature', 'settings.appearance.signature'); - }); + // Account section + Router::group(['prefix' => 'account'], function () { + Router::get('/', function () { + $route = Router::route('settings.account.email'); + return header("Location: {$route}"); + }); - // Account section - Router::group(['prefix' => 'account'], function () { - Router::get('/', function () { - $route = Router::route('settings.account.email'); - return header("Location: {$route}"); + Router::get('/email', 'Settings.AccountController@email', 'settings.account.email'); + Router::post('/email', 'Settings.AccountController@email', 'settings.account.email'); + Router::get('/username', 'Settings.AccountController@username', 'settings.account.username'); + Router::post('/username', 'Settings.AccountController@username', 'settings.account.username'); + Router::get('/title', 'Settings.AccountController@title', 'settings.account.title'); + Router::post('/title', 'Settings.AccountController@title', 'settings.account.title'); + Router::get('/password', 'Settings.AccountController@password', 'settings.account.password'); + Router::post('/password', 'Settings.AccountController@password', 'settings.account.password'); + Router::get('/ranks', 'Settings.AccountController@ranks', 'settings.account.ranks'); + Router::post('/ranks', 'Settings.AccountController@ranks', 'settings.account.ranks'); }); - Router::get('/email', 'Settings.AccountController@email', 'settings.account.email'); - Router::post('/email', 'Settings.AccountController@email', 'settings.account.email'); - Router::get('/username', 'Settings.AccountController@username', 'settings.account.username'); - Router::post('/username', 'Settings.AccountController@username', 'settings.account.username'); - Router::get('/title', 'Settings.AccountController@title', 'settings.account.title'); - Router::post('/title', 'Settings.AccountController@title', 'settings.account.title'); - Router::get('/password', 'Settings.AccountController@password', 'settings.account.password'); - Router::post('/password', 'Settings.AccountController@password', 'settings.account.password'); - Router::get('/ranks', 'Settings.AccountController@ranks', 'settings.account.ranks'); - Router::post('/ranks', 'Settings.AccountController@ranks', 'settings.account.ranks'); - }); + // Advanced section + Router::group(['prefix' => 'advanced'], function () { + Router::get('/', function () { + $route = Router::route('settings.advanced.sessions'); + return header("Location: {$route}"); + }); - // Advanced section - Router::group(['prefix' => 'advanced'], function () { - Router::get('/', function () { - $route = Router::route('settings.advanced.sessions'); - return header("Location: {$route}"); + Router::get('/sessions', 'Settings.AdvancedController@sessions', 'settings.advanced.sessions'); + Router::post('/sessions', 'Settings.AdvancedController@sessions', 'settings.advanced.sessions'); + Router::get('/deactivate', 'Settings.AdvancedController@deactivate', 'settings.advanced.deactivate'); + Router::post('/deactivate', 'Settings.AdvancedController@deactivate', 'settings.advanced.deactivate'); }); - - Router::get('/sessions', 'Settings.AdvancedController@sessions', 'settings.advanced.sessions'); - Router::post('/sessions', 'Settings.AdvancedController@sessions', 'settings.advanced.sessions'); - Router::get('/deactivate', 'Settings.AdvancedController@deactivate', 'settings.advanced.deactivate'); - Router::post('/deactivate', 'Settings.AdvancedController@deactivate', 'settings.advanced.deactivate'); }); -}); // Management -/* + /* * General * - Dashboard * - Info pages (possibly deprecate with wiki) @@ -274,3 +290,4 @@ Router::group(['prefix' => 'settings', 'before' => 'loginCheck'], function () { * - Management * - Errors */ +}); diff --git a/sakura.php b/sakura.php index 1cf32ee..c91527c 100644 --- a/sakura.php +++ b/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', 20160408); +define('SAKURA_VERSION', 20160425); // Define Sakura Path define('ROOT', __DIR__ . '/'); @@ -25,12 +25,12 @@ mb_internal_encoding('utf-8'); // Stop the execution if the PHP Version is older than 7.0.0 if (version_compare(phpversion(), '7.0.0', '<')) { - throw new \Exception('Sakura requires at least PHP 7.0.0, please upgrade to a newer PHP version.'); + throw new Exception('Sakura requires at least PHP 7.0.0, please upgrade to a newer PHP version.'); } // Check if the composer autoloader exists if (!file_exists(ROOT . 'vendor/autoload.php')) { - throw new \Exception('Autoloader not found, did you run composer install?'); + throw new Exception('Autoloader not found, did you run composer install?'); } // Require composer libraries @@ -87,9 +87,10 @@ Router::init(); include_once ROOT . 'routes.php'; // Initialise the current session +$cookiePrefix = Config::get('cookie_prefix'); ActiveUser::init( - intval($_COOKIE[Config::get('cookie_prefix') . 'id'] ?? 0), - $_COOKIE[Config::get('cookie_prefix') . 'session'] ?? '' + intval($_COOKIE["{$cookiePrefix}id"] ?? 0), + $_COOKIE["{$cookiePrefix}session"] ?? '' ); if (!defined('SAKURA_NO_TPL')) { @@ -98,32 +99,11 @@ if (!defined('SAKURA_NO_TPL')) { // Set base page rendering data Template::vars([ - 'sakura' => [ - 'currentPage' => $_SERVER['REQUEST_URI'] ?? null, - 'referrer' => $_SERVER['HTTP_REFERER'] ?? null, - ], - - 'session' => array_merge([ - 'sessionId' => ActiveUser::$session->sessionId, - ], $_SESSION), - - 'user' => ActiveUser::$user, - 'get' => $_GET, + 'user' => ActiveUser::$user, 'post' => $_POST, - 'request' => $_REQUEST, 'server' => $_SERVER, + 'request' => $_REQUEST, + 'session' => $_SESSION, ]); - - // Site closing - if (Config::get('site_closed')) { - // Set parse variables - Template::vars([ - 'message' => Config::get('site_closed_reason'), - ]); - - // Print page contents - echo Template::render('global/information'); - exit; - } } diff --git a/templates/misaki/global/master.twig b/templates/misaki/global/master.twig index c3739d5..14156da 100644 --- a/templates/misaki/global/master.twig +++ b/templates/misaki/global/master.twig @@ -108,7 +108,7 @@