From f109a86c5b9fdaf5ce8b24902077f4ecb0594eda Mon Sep 17 00:00:00 2001 From: flashwave Date: Thu, 10 Mar 2016 19:54:36 +0100 Subject: [PATCH] Some more moves. --- composer.json | 3 +- libraries/Controllers/ForumController.php | 175 +++++++++++++++++++--- libraries/Forum/Thread.php | 2 +- public/viewtopic.php | 40 ++--- routes.php | 8 + sakura.php | 2 +- templates/yuuno/forum/topicEntry.twig | 6 +- templates/yuuno/forum/viewforum.twig | 4 +- templates/yuuno/forum/viewtopic.twig | 4 +- templates/yuuno/global/master.twig | 85 +++++++---- 10 files changed, 237 insertions(+), 92 deletions(-) diff --git a/composer.json b/composer.json index 8cb3357..ba3f33a 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "jbbcode/jbbcode": "*", "corneltek/cliframework": "*", "phroute/phroute": "^2.1", - "illuminate/database": "5.2.*" + "illuminate/database": "5.2.*", + "doctrine/dbal": "~2.4" } } diff --git a/libraries/Controllers/ForumController.php b/libraries/Controllers/ForumController.php index 2c5d309..7c154ea 100644 --- a/libraries/Controllers/ForumController.php +++ b/libraries/Controllers/ForumController.php @@ -8,8 +8,10 @@ namespace Sakura\Controllers; use Sakura\DB; -use Sakura\Forum; +use Sakura\Forum\Forum; +use Sakura\Forum\Thread; use Sakura\Perms\Forum as ForumPerms; +use Sakura\Router; use Sakura\Template; use Sakura\User; use Sakura\Users; @@ -31,7 +33,7 @@ class ForumController extends Controller { // Merge index specific stuff with the global render data Template::vars([ - 'forum' => (new Forum\Forum()), + 'forum' => (new Forum()), 'stats' => [ 'userCount' => DB::table('users')->where('password_algo', '!=', 'disabled')->whereNotIn('rank_main', [1, 10])->count(), 'newestUser' => User::construct(Users::getNewestUserId()), @@ -54,11 +56,11 @@ class ForumController extends Controller global $currentUser; // Get the forum - $forum = new Forum\Forum($id); + $forum = new Forum($id); // Redirect forum id 0 to the main page if ($forum->id === 0) { - header('Location: ' . (new \Sakura\Urls)->format('FORUM_INDEX')); + header('Location: ' . Router::route('forums.index')); exit; } @@ -68,6 +70,7 @@ class ForumController extends Controller Template::vars([ 'page' => [ 'message' => 'The forum you tried to access does not exist.', + 'redirect' => Router::route('forums.index'), ], ]); @@ -81,6 +84,7 @@ class ForumController extends Controller Template::vars([ 'page' => [ 'message' => 'You do not have access to this forum.', + 'redirect' => Router::route('forums.index'), ], ]); @@ -95,24 +99,7 @@ class ForumController extends Controller '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 @@ -127,4 +114,148 @@ class ForumController extends Controller // Print page contents return Template::render('forum/viewforum'); } + + public function markForumRead($id = 0) + { + global $currentUser; + + // Check if the session id was supplied + if (!isset($_GET['s']) || $_GET['s'] != session_id()) { + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'Your session expired! Go back and try again.', + 'redirect' => Router::route('forums.index'), + ], + ]); + + // Print page contents + return Template::render('global/information'); + } + + // Get the forum + $forum = new Forum($id); + + // Check if the forum exists + if ($forum->id < 1) { + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'The forum you tried to access does not exist.', + 'redirect' => Router::route('forums.index'), + ], + ]); + + // 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.', + 'redirect' => Router::route('forums.index'), + ], + ]); + + // Print page contents + return Template::render('global/information'); + } + + // Run the function + $forum->trackUpdateAll($currentUser->id); + + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'All threads have been marked as read.', + 'redirect' => Router::route('forums.forum', $forum->id), + ], + ]); + + // Print page contents + return Template::render('global/information'); + } + + public function thread($id = 0) + { + global $currentUser; + + // Attempt to get the thread + $thread = new Thread($id); + + // And attempt to get the forum + $forum = new Forum($thread->forum); + + // Check if the forum exists + if ($thread->id == 0 || !$forum->permission(ForumPerms::VIEW, $currentUser->id)) { + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'This thread doesn\'t exist or you don\'t have access to it!', + 'redirect' => Router::route('forums.index'), + ], + ]); + + // Print page contents + return Template::render('global/information'); + } + + // Update the tracking status + $thread->trackUpdate($currentUser->id); + + // Update views + $thread->viewsUpdate(); + + // Set parse variables + Template::vars([ + 'thread' => $thread, + 'forum' => $forum, + ]); + + // Print page contents + return Template::render('forum/viewtopic'); + } + + public function threadModerate($id = 0) + { + global $currentUser; + + // Attempt to get the thread + $thread = new Thread($id); + + // And attempt to get the forum + $forum = new Forum($thread->forum); + + // Check if the forum exists + if ($thread->id == 0 || !$forum->permission(ForumPerms::VIEW, $currentUser->id)) { + // Set render data + Template::vars([ + 'page' => [ + 'message' => 'This thread doesn\'t exist or you don\'t have access to it!', + 'redirect' => Router::route('forums.index'), + ], + ]); + } else { + // Take the action + $action = isset($_POST['action']) ? $_POST['action'] : null; + + // Switch + switch ($action) { + default: + Template::vars([ + 'page' => [ + 'message' => 'Unknown moderation action.', + 'redirect' => Router::route('forums.thread', $thread->id), + ], + ]); + break; + } + } + + // Print page contents + return Template::render('global/information'); + } } diff --git a/libraries/Forum/Thread.php b/libraries/Forum/Thread.php index 9496165..5ba5db3 100644 --- a/libraries/Forum/Thread.php +++ b/libraries/Forum/Thread.php @@ -226,7 +226,7 @@ class Thread ->update([ 'topic_hidden' => $this->hidden, 'topic_title' => $this->title, - 'topic_limit' => $this->timeLimit, + 'topic_time_limit' => $this->timeLimit, 'topic_status' => $this->status, 'topic_status_change' => $this->statusChange, 'topic_type' => $this->type, diff --git a/public/viewtopic.php b/public/viewtopic.php index 7623ed8..dec404b 100644 --- a/public/viewtopic.php +++ b/public/viewtopic.php @@ -26,7 +26,7 @@ if (!$thread) { // Set render data $renderData['page'] = [ 'message' => 'The topic you tried to access does not exist.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; // Set parse variables @@ -42,7 +42,7 @@ if (!$forum->permission(ForumPerms::VIEW, $currentUser->id)) { // Set render data $renderData['page'] = [ 'message' => 'You do not have access to this thread.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; // Set parse variables @@ -68,7 +68,7 @@ if (isset($_GET['sticky']) && $_GET['sticky'] == session_id() && $forum->permiss // Set render data $renderData['page'] = [ 'message' => 'Changed the thread type.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; // Set parse variables @@ -93,7 +93,7 @@ if (isset($_GET['announce']) && $_GET['announce'] == session_id() && $forum->per // Set render data $renderData['page'] = [ 'message' => 'Changed the thread type.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; // Set parse variables @@ -118,7 +118,7 @@ if (isset($_GET['lock']) && $_GET['lock'] == session_id() && $forum->permission( // Set render data $renderData['page'] = [ 'message' => 'Changed the thread status.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; // Set parse variables @@ -138,13 +138,13 @@ if (isset($_GET['trash']) && $_GET['trash'] == session_id() && $forum->permissio // Set render data $renderData['page'] = [ 'message' => 'Moved thread to the trash.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; } else { // Set render data $renderData['page'] = [ 'message' => 'This thread is already trashed.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; } @@ -166,13 +166,13 @@ if (isset($_GET['restore']) && $_GET['restore'] == session_id() && $forum->permi // Set render data $renderData['page'] = [ 'message' => 'Restored the thread to its previous location.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; } else { // Set render data $renderData['page'] = [ 'message' => 'This thread has never been moved.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; } @@ -193,13 +193,13 @@ if (isset($_GET['prune']) && $_GET['prune'] == session_id() && $forum->permissio // Set render data $renderData['page'] = [ 'message' => 'The thread has been pruned.', - 'redirect' => $urls->format('FORUM_SUB', [$thread->forum]), + 'redirect' => Router::route('forums.forum', $thread->forum), ]; } else { // Set render data $renderData['page'] = [ 'message' => 'You can only prune trashed threads.', - 'redirect' => $urls->format('FORUM_THREAD', [$thread->id]), + 'redirect' => Router::route('forums.thread', $thread->id), ]; } @@ -211,20 +211,4 @@ if (isset($_GET['prune']) && $_GET['prune'] == session_id() && $forum->permissio exit; } -// Update the tracking status -$thread->trackUpdate($currentUser->id); - -// Update views -$thread->viewsUpdate(); - -// Set additional render data -$renderData = array_merge($renderData, [ - 'thread' => $thread, - 'forum' => $forum, -]); - -// Set parse variables -Template::vars($renderData); - -// Print page contents -echo Template::render('forum/viewtopic'); +header('Location: ' . Router::route('forums.thread', $thread->id)); diff --git a/routes.php b/routes.php index 568c8d6..4bfc0fd 100644 --- a/routes.php +++ b/routes.php @@ -33,8 +33,16 @@ Router::group(['prefix' => 'news'], function () { // Forum Router::group(['prefix' => 'forum'], function () { + // Thread + Router::group(['prefix' => 'thread'], function () { + Router::get('/{id}', 'ForumController@thread', 'forums.thread'); + Router::post('/{id}/mod', 'ForumController@threadModerate', 'forums.mod'); + }); + + // Forum Router::get('/', 'ForumController@index', 'forums.index'); Router::get('/{id}', 'ForumController@forum', 'forums.forum'); + Router::get('/{id}/mark', 'ForumController@markForumRead', 'forums.mark'); }); // Members diff --git a/sakura.php b/sakura.php index de97c09..0492648 100644 --- a/sakura.php +++ b/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20160228'); +define('SAKURA_VERSION', '20160310'); // Define Sakura Path define('ROOT', __DIR__ . '/'); diff --git a/templates/yuuno/forum/topicEntry.twig b/templates/yuuno/forum/topicEntry.twig index e125bfb..0c3024d 100644 --- a/templates/yuuno/forum/topicEntry.twig +++ b/templates/yuuno/forum/topicEntry.twig @@ -3,11 +3,11 @@
- {{ thread.title }} + {{ thread.title }} {% if thread.firstPost.poster.id %} - {{ thread.firstPost.poster.username }} + {{ thread.firstPost.poster.username }} {% else %} [deleted user] {% endif %} @@ -18,7 +18,7 @@ {% if thread.lastPost.poster.id %} - {{ thread.lastPost.poster.username }} + {{ thread.lastPost.poster.username }} {% else %} [deleted user] {% endif %}
diff --git a/templates/yuuno/forum/viewforum.twig b/templates/yuuno/forum/viewforum.twig index d863087..9489d51 100644 --- a/templates/yuuno/forum/viewforum.twig +++ b/templates/yuuno/forum/viewforum.twig @@ -2,9 +2,9 @@ {% set title %}Forums / {{ forum.name }}{% endset %} -{% set forumBackLink %}{{ urls.format('FORUM_INDEX') }}{% endset %} +{% set forumBackLink %}{{ route('forums.index') }}{% endset %} {% set forumNewLink %}{{ urls.format('FORUM_NEW_THREAD', [forum.id]) }}{% endset %} -{% set forumMarkRead %}{{ urls.format('FORUM_MARK_READ', [forum.id, php.sessionid]) }}{% endset %} +{% set forumMarkRead %}{{ route('forums.mark', forum.id) }}?s={{ php.sessionid }}{% endset %} {% block title %}{{ title }}{% endblock %} diff --git a/templates/yuuno/forum/viewtopic.twig b/templates/yuuno/forum/viewtopic.twig index 8df196f..7f2d395 100644 --- a/templates/yuuno/forum/viewtopic.twig +++ b/templates/yuuno/forum/viewtopic.twig @@ -84,8 +84,8 @@ {% for post in posts[get.page|default(1) - 1] %} - {% if not post.poster.permission(constant('Sakura\\Perms\\Site::DEACTIVATED')) or post.poster.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) %}{{ post.poster.username }} - {{ post.poster.username }} + {% if not post.poster.permission(constant('Sakura\\Perms\\Site::DEACTIVATED')) or post.poster.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) %}{{ post.poster.username }} + {{ post.poster.username }} {% else %} [deleted user] {% endif %} diff --git a/templates/yuuno/global/master.twig b/templates/yuuno/global/master.twig index 22b180f..1b41497 100644 --- a/templates/yuuno/global/master.twig +++ b/templates/yuuno/global/master.twig @@ -200,7 +200,7 @@ - {% if sakura.dev.showChangelog and php.self == '/index.php' and stats %} - + {% if sakura.dev.showChangelog and stats %} +