From 8bf68062b217f3fc7fad6cea007f3f400cb2ec21 Mon Sep 17 00:00:00 2001 From: flashwave Date: Fri, 11 Mar 2016 20:13:14 +0100 Subject: [PATCH] moved viewtopic functionality into the router --- libraries/Controllers/ForumController.php | 125 +++++++++++-- public/content/data/yuuno/css/yuuno.css | 17 +- public/posting.php | 25 +-- public/viewtopic.php | 214 ---------------------- routes.php | 33 +++- sakura.php | 2 +- templates/yuuno/forum/forumBtns.twig | 24 +-- templates/yuuno/forum/forumMod.twig | 26 +++ templates/yuuno/forum/viewtopic.twig | 12 +- templates/yuuno/global/notfound.twig | 4 +- 10 files changed, 209 insertions(+), 273 deletions(-) delete mode 100644 public/viewtopic.php create mode 100644 templates/yuuno/forum/forumMod.twig diff --git a/libraries/Controllers/ForumController.php b/libraries/Controllers/ForumController.php index 7c154ea..83c5ba7 100644 --- a/libraries/Controllers/ForumController.php +++ b/libraries/Controllers/ForumController.php @@ -7,6 +7,7 @@ namespace Sakura\Controllers; +use Sakura\Config; use Sakura\DB; use Sakura\Forum\Forum; use Sakura\Forum\Thread; @@ -229,32 +230,126 @@ class ForumController extends Controller // And attempt to get the forum $forum = new Forum($thread->forum); + // Default stuff + $message = 'Unknown moderation action.'; + $redirect = Router::route('forums.thread', $thread->id); + // 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'), - ], - ]); + if ($thread->id == 0 + || !$forum->permission(ForumPerms::VIEW, $currentUser->id) + || !isset($_POST['session']) + || $_POST['session'] != session_id()) { + $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), - ], - ]); + case 'sticky': + // Check permission + if (!$forum->permission(ForumPerms::STICKY, $currentUser->id)) { + $message = "You're not allowed to do this!"; + break; + } + + // Update the type + $thread->type = $thread->type !== 1 ? 1 : 0; + + $thread->update(); + + // Add page variable stuff + $message = $thread->type ? 'Changed the thread to sticky!' : 'Reverted the thread back to normal!'; + break; + + case 'announce': + // Check permission + if (!$forum->permission(ForumPerms::ANNOUNCEMENT, $currentUser->id)) { + $message = "You're not allowed to do this!"; + break; + } + + // Update the type + $thread->type = $thread->type !== 2 ? 2 : 0; + + $thread->update(); + + // Add page variable stuff + $message = $thread->type ? 'Changed the thread to anto an announcement!' : 'Reverted the thread back to normal!'; + break; + + case 'lock': + // Check permission + if (!$forum->permission(ForumPerms::LOCK, $currentUser->id)) { + $message = "You're not allowed to do this!"; + break; + } + + // Update the status + $thread->status = $thread->status !== 1 ? 1 : 0; + + $thread->update(); + + // Add page variable stuff + $message = ($thread->status ? 'Locked' : 'Unlocked') . ' the thread!'; + break; + + case 'delete': + // Get the id of the trash forum + $trash = Config::get('forum_trash_id'); + + // Check if we're operating from the trash + if ($thread->forum == $trash) { + // Check permission + if (!$forum->permission(ForumPerms::DELETE_ANY, $currentUser->id)) { + $message = "You're not allowed to do this!"; + break; + } + + // Set pruned to true + $pruned = true; + + // Delete the thread + $thread->delete(); + + // Set message + $message = "Deleted the thread!"; + $redirect = Router::route('forums.forum', $trash); + } else { + // Check permission + if (!$forum->permission(ForumPerms::MOVE, $currentUser->id)) { + $message = "You're not allowed to do this!"; + break; + } + + // Move the thread + $thread->move($trash); + + // Trashed! + $message = "Moved the thread to the trash!"; + } + break; + + case 'restore': + // Check if this thread has record of being in a previous forum + if ($thread->oldForum) { + // Move the thread back + $thread->move($thread->oldForum, false); + + $message = "Moved the thread back to it's old location!"; + } else { + $message = "This thread has never been moved!"; + } break; } } + // Set the variables + Template::vars([ + 'page' => compact('message', 'redirect'), + ]); + // Print page contents return Template::render('global/information'); } diff --git a/public/content/data/yuuno/css/yuuno.css b/public/content/data/yuuno/css/yuuno.css index f7094fb..07dd7ff 100644 --- a/public/content/data/yuuno/css/yuuno.css +++ b/public/content/data/yuuno/css/yuuno.css @@ -2321,7 +2321,8 @@ textarea.inputStyling { /* * Pagination */ -.pagination a { +.pagination a, +.forumbtn { background: linear-gradient(0deg, #9475B2 10%, #C2AFFE 90%); color: #306; padding: 4px 8px; @@ -2331,17 +2332,25 @@ textarea.inputStyling { display: inline-block; font-size: 1.3em; border: 1px solid #9475B2; + cursor: pointer; } -.pagination a.current { +button.forumbtn { + padding: 3px 6px; +} + +.pagination a.current, +.forumbtn.current { background: linear-gradient(0deg, #A586C3, #D3BFFF); } -.pagination a:hover { +.pagination a:hover, +.forumbtn:hover { background: linear-gradient(0deg, #9475B2 30%, #C2AFFE 70%); } -.pagination a:active { +.pagination a:active, +.forumbtn:active { background: linear-gradient(180deg, #9475B2 30%, #C2AFFE 70%); } diff --git a/public/posting.php b/public/posting.php index e3cadc7..934e1b3 100644 --- a/public/posting.php +++ b/public/posting.php @@ -84,7 +84,7 @@ if ($mode != 'f') { if (!$thread->id) { // Add page specific things $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')), + 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), 'message' => 'The requested post does not exist.', ]; @@ -100,7 +100,7 @@ if ($mode != 'f') { if ($thread->status == 1 && !$forum->permission(ForumPerms::LOCK, $currentUser->id)) { // Add page specific things $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')), + 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), 'message' => 'The thread you tried to reply to is locked.', ]; @@ -126,7 +126,7 @@ if ($mode != 'f') { if (!$currentUser->permission(ForumPerms::EDIT_OWN, Perms::FORUM)) { // Add page specific things $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')), + 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), 'message' => 'You are not allowed to edit posts!', ]; @@ -141,7 +141,7 @@ if ($mode != 'f') { if ($thread->posts()[$_GET['p']]->poster->id != $currentUser->id && !$forum->permission(ForumPerms::EDIT_ANY, $currentUser->id)) { // Add page specific things $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')), + 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), 'message' => 'You can only edit your own posts!', ]; @@ -168,7 +168,7 @@ if ($mode != 'f') { if (!$currentUser->permission(ForumPerms::DELETE_OWN, Perms::FORUM)) { // Add page specific things $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')), + 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), 'message' => 'You are not allowed to delete posts!', ]; @@ -184,7 +184,7 @@ if ($mode != 'f') { if ($thread->posts()[$_GET['p']]->poster->id != $currentUser->id && !$forum->permission(ForumPerms::DELETE_ANY, $currentUser->id)) { // Add page specific things $renderData['page'] = [ - 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $urls->format('FORUM_INDEX')), + 'redirect' => (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : Router::route('forums.index')), 'message' => 'You can only delete your own posts!', ]; @@ -203,8 +203,8 @@ if ($mode != 'f') { // Delete the post DBv2::prepare('DELETE FROM `{prefix}posts` WHERE `post_id` = :post') ->execute([ - 'post' => $_POST['post_id'], - ]); + 'post' => $_POST['post_id'], + ]); // Reload the topic $thread = new Forum\Thread($topicId); @@ -213,13 +213,13 @@ if ($mode != 'f') { if (!$thread->replyCount()) { DBv2::prepare('DELETE FROM `{prefix}topics` WHERE `topic_id` = :thread') ->execute([ - 'thread' => $thread->id, - ]); + 'thread' => $thread->id, + ]); } // Add page specific things $renderData['page'] = [ - 'redirect' => ($thread->replyCount() ? $urls->format('FORUM_THREAD', [$thread->id]) : $urls->format('FORUM_INDEX')), + 'redirect' => ($thread->replyCount() ? Router::route('forums.thread', $thread->id) : Router::route('forums.index')), 'message' => 'Your post has been deleted!', ]; @@ -231,6 +231,7 @@ if ($mode != 'f') { exit; // Return to previous page } else { + // (haven't (re)implemented post linking yet) header('Location: ' . $urls->format('FORUM_POST', [$_POST['post_id']])); exit; } @@ -264,7 +265,7 @@ if (isset($_POST['post'])) { if (isset($_POST['id'])) { // Attempt to create a post object $post = new Forum\Post($_POST['id']); - + // Check if the post israel if ($post->id == $_POST['id']) { $post->subject = $_POST['subject']; diff --git a/public/viewtopic.php b/public/viewtopic.php deleted file mode 100644 index dec404b..0000000 --- a/public/viewtopic.php +++ /dev/null @@ -1,214 +0,0 @@ -thread - : (isset($_GET['t']) ? $_GET['t'] : 0) -); - -// And attempt to get the forum -$forum = new Forum\Forum($thread->forum); - -// Check if the forum exists -if (!$thread) { - // Set render data - $renderData['page'] = [ - 'message' => 'The topic you tried to access does not exist.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - - // Set parse variables - Template::vars($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'] = [ - 'message' => 'You do not have access to this thread.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -// Sticky thread -if (isset($_GET['sticky']) && $_GET['sticky'] == session_id() && $forum->permission(ForumPerms::STICKY, $currentUser->id)) { - // Check the status - if ($thread->type == 1) { - $thread->type = 0; - } else { - $thread->type = 1; - } - - // Update the thread - $thread->update(); - - // Set render data - $renderData['page'] = [ - 'message' => 'Changed the thread type.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -// Announce thread -if (isset($_GET['announce']) && $_GET['announce'] == session_id() && $forum->permission(ForumPerms::ANNOUNCEMENT, $currentUser->id)) { - // Check the status - if ($thread->type == 2) { - $thread->type = 0; - } else { - $thread->type = 2; - } - - // Update the thread - $thread->update(); - // Set render data - $renderData['page'] = [ - 'message' => 'Changed the thread type.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -// Lock thread -if (isset($_GET['lock']) && $_GET['lock'] == session_id() && $forum->permission(ForumPerms::LOCK, $currentUser->id)) { - // Check the status - if ($thread->status == 1) { - $thread->status = 0; - } else { - $thread->status = 1; - } - - // Update the thread - $thread->update(); - // Set render data - $renderData['page'] = [ - 'message' => 'Changed the thread status.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -// Trash thread -if (isset($_GET['trash']) && $_GET['trash'] == session_id() && $forum->permission(ForumPerms::MOVE, $currentUser->id)) { - // Check the status - if ($thread->forum != Config::get('forum_trash_id')) { - $thread->move(Config::get('forum_trash_id')); - - // Set render data - $renderData['page'] = [ - 'message' => 'Moved thread to the trash.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - } else { - // Set render data - $renderData['page'] = [ - 'message' => 'This thread is already trashed.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - } - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -// Restore thread -if (isset($_GET['restore']) && $_GET['restore'] == session_id() && $forum->permission(ForumPerms::MOVE, $currentUser->id)) { - // Check the status - if ($thread->oldForum) { - // Move thread - $thread->move($thread->oldForum, false); - - // Set render data - $renderData['page'] = [ - 'message' => 'Restored the thread to its previous location.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - } else { - // Set render data - $renderData['page'] = [ - 'message' => 'This thread has never been moved.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - } - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -// Prune thread -if (isset($_GET['prune']) && $_GET['prune'] == session_id() && $forum->permission(ForumPerms::DELETE_ANY, $currentUser->id)) { - // Check the status - if ($thread->forum == Config::get('forum_trash_id')) { - $thread->delete(); - - // Set render data - $renderData['page'] = [ - 'message' => 'The thread has been pruned.', - 'redirect' => Router::route('forums.forum', $thread->forum), - ]; - } else { - // Set render data - $renderData['page'] = [ - 'message' => 'You can only prune trashed threads.', - 'redirect' => Router::route('forums.thread', $thread->id), - ]; - } - - // Set parse variables - Template::vars($renderData); - - // Print page contents - echo Template::render('global/information'); - exit; -} - -header('Location: ' . Router::route('forums.thread', $thread->id)); diff --git a/routes.php b/routes.php index 4bfc0fd..2aa89c9 100644 --- a/routes.php +++ b/routes.php @@ -36,7 +36,7 @@ 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'); + Router::post('/{id}/mod', 'ForumController@threadModerate', 'forums.thread.mod'); }); // Forum @@ -65,6 +65,37 @@ Router::group(['prefix' => 'support'], function () { Router::get('/tracker', 'PremiumController@tracker', 'premium.tracker'); }); +// Settings +/* + * General + * - Home (make this not worthless while you're at it) + * - Edit Profile + * - Site Options + * Friends + * - Listing + * - Requests + * Groups + * - Listing + * - Invites + * Notifications (will probably deprecate this entire section at some point but not relevant yet) + * - History + * Appearance (possibly combine ava, bg and header down into one menu as well as userpage and signature maybe) + * - Avatar + * - Background + * - Header + * - Userpage + * - Signature + * Account (also down to one section maybe) + * - E-mail + * - Username + * - Usertitle + * - Password + * - Ranks (except this one i guess) + * Advanced + * - Session manager + * - Deactivate account + */ + // Management /* * General diff --git a/sakura.php b/sakura.php index 0492648..f113cd5 100644 --- a/sakura.php +++ b/sakura.php @@ -8,7 +8,7 @@ namespace Sakura; // Define Sakura version -define('SAKURA_VERSION', '20160310'); +define('SAKURA_VERSION', '20160311'); // Define Sakura Path define('ROOT', __DIR__ . '/'); diff --git a/templates/yuuno/forum/forumBtns.twig b/templates/yuuno/forum/forumBtns.twig index 71d030e..46a24bf 100644 --- a/templates/yuuno/forum/forumBtns.twig +++ b/templates/yuuno/forum/forumBtns.twig @@ -14,28 +14,8 @@ {% if forumMarkRead %} Mark as Read {% endif %} - {% if forumSticky %} - Stick - {% elseif forumUnsticky %} - Unstick - {% endif %} - {% if forumAnnounce %} - Announce - {% elseif forumUnannounce %} - Unannounce - {% endif %} - {% if forumLock %} - Lock - {% elseif forumUnlock %} - Unlock - {% endif %} - {% if forumRestore %} - Restore - {% endif %} - {% if forumTrash %} - Trash - {% elseif forumPrune %} - Prune + {% if thread.id and showMod %} + {% include 'forum/forumMod.twig' %} {% endif %} {% include 'elements/pagination.twig' %} diff --git a/templates/yuuno/forum/forumMod.twig b/templates/yuuno/forum/forumMod.twig new file mode 100644 index 0000000..cdf074c --- /dev/null +++ b/templates/yuuno/forum/forumMod.twig @@ -0,0 +1,26 @@ +
+ + {% if forumSticky %} + + {% elseif forumUnsticky %} + + {% endif %} + {% if forumAnnounce %} + + {% elseif forumUnannounce %} + + {% endif %} + {% if forumLock %} + + {% elseif forumUnlock %} + + {% endif %} + {% if forumRestore %} + + {% endif %} + {% if forumTrash %} + + {% elseif forumPrune %} + + {% endif %} +
diff --git a/templates/yuuno/forum/viewtopic.twig b/templates/yuuno/forum/viewtopic.twig index 7f2d395..59b936a 100644 --- a/templates/yuuno/forum/viewtopic.twig +++ b/templates/yuuno/forum/viewtopic.twig @@ -1,11 +1,19 @@ {% extends 'global/master.twig' %} -{% set forumBackLink %}{{ urls.format('FORUM_SUB', [forum.id]) }}{% endset %} +{% set forumBackLink %}{{ route('forums.forum', forum.id) }}{% endset %} {% if thread.status != 1 or forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id) %} {% set forumReplyLink %}{{ urls.format('FORUM_REPLY', [thread.id]) }}{% endset %} {% endif %} +{% if forum.permission(constant('Sakura\\Perms\\Forum::STICKY'), user.id) + or forum.permission(constant('Sakura\\Perms\\Forum::ANNOUNCEMENT'), user.id) + or forum.permission(constant('Sakura\\Perms\\Forum::LOCK'), user.id) + or forum.permission(constant('Sakura\\Perms\\Forum::MOVE'), user.id) + or forum.permission(constant('Sakura\\Perms\\Forum::DELETE_ANY'), user.id) %} + {% set showMod = true %} +{% endif %} + {% if forum.permission(constant('Sakura\\Perms\\Forum::STICKY'), user.id) %} {% if thread.type == 1 %} {% set forumUnsticky %}{{ urls.format('FORUM_STICKY', [thread.id, php.sessionid]) }}{% endset %} @@ -62,7 +70,7 @@ {% endif %} {% set paginationPages = posts %} -{% set paginationUrl %}{{ urls.format('FORUM_THREAD', [thread.id]) }}{% endset %} +{% set paginationUrl %}{{ route('forums.thread', thread.id) }}{% endset %} {% block title %}{{ thread.title }}{% endblock %} diff --git a/templates/yuuno/global/notfound.twig b/templates/yuuno/global/notfound.twig index 3f0f46b..6f84f45 100644 --- a/templates/yuuno/global/notfound.twig +++ b/templates/yuuno/global/notfound.twig @@ -25,7 +25,7 @@ sure that it is spelled correctly.
  • - Open the flashii.net + Open the flashii.net home page, and then look for links to the information you want.
  • @@ -33,7 +33,7 @@ button to try another link.
  • - Click Search + Click Search to look for information on the Internet.