moved viewtopic functionality into the router

This commit is contained in:
Pachira 2016-03-11 20:13:14 +01:00
parent f109a86c5b
commit 8bf68062b2
10 changed files with 209 additions and 273 deletions

View file

@ -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');
}

View file

@ -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%);
}

View file

@ -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'];

View file

@ -1,214 +0,0 @@
<?php
/*
* Sakura Forum Topic Viewer
*/
// Declare Namespace
namespace Sakura;
use Sakura\Perms\Forum as ForumPerms;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
// Attempt to get the thread
$thread = new Forum\Thread(
isset($_GET['p'])
? (new Forum\Post($_GET['p']))->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));

View file

@ -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

View file

@ -8,7 +8,7 @@
namespace Sakura;
// Define Sakura version
define('SAKURA_VERSION', '20160310');
define('SAKURA_VERSION', '20160311');
// Define Sakura Path
define('ROOT', __DIR__ . '/');

View file

@ -14,28 +14,8 @@
{% if forumMarkRead %}
<a href="{{ forumMarkRead }}" class="forumbtn"><span class="fa fa-check-square-o"></span> Mark as Read</a>
{% endif %}
{% if forumSticky %}
<a href="{{ forumSticky }}" class="forumbtn"><span class="fa fa-thumb-tack"></span> Stick</a>
{% elseif forumUnsticky %}
<a href="{{ forumUnsticky }}" class="forumbtn"><span class="fa fa-remove"></span> Unstick</a>
{% endif %}
{% if forumAnnounce %}
<a href="{{ forumAnnounce }}" class="forumbtn"><span class="fa fa-bullhorn"></span> Announce</a>
{% elseif forumUnannounce %}
<a href="{{ forumUnannounce }}" class="forumbtn"><span class="fa fa-remove"></span> Unannounce</a>
{% endif %}
{% if forumLock %}
<a href="{{ forumLock }}" class="forumbtn"><span class="fa fa-lock"></span> Lock</a>
{% elseif forumUnlock %}
<a href="{{ forumUnlock }}" class="forumbtn"><span class="fa fa-unlock"></span> Unlock</a>
{% endif %}
{% if forumRestore %}
<a href="{{ forumRestore }}" class="forumbtn"><span class="fa fa-history"></span> Restore</a>
{% endif %}
{% if forumTrash %}
<a href="{{ forumTrash }}" class="forumbtn"><span class="fa fa-trash"></span> Trash</a>
{% elseif forumPrune %}
<a href="{{ forumPrune }}" class="forumbtn"><span class="fa fa-bomb"></span> Prune</a>
{% if thread.id and showMod %}
{% include 'forum/forumMod.twig' %}
{% endif %}
</div>
{% include 'elements/pagination.twig' %}

View file

@ -0,0 +1,26 @@
<form method="post" action="{{ route('forums.thread.mod', thread.id) }}" style="display: inline-block;">
<input type="hidden" name="session" value="{{ php.sessionid }}" />
{% if forumSticky %}
<button class="forumbtn" title="Sticky" name="action" value="sticky"><span class="fa fa-thumb-tack"></span></button>
{% elseif forumUnsticky %}
<button class="forumbtn" title="Unsticky" name="action" value="sticky"><span class="fa fa-remove"></span></button>
{% endif %}
{% if forumAnnounce %}
<button class="forumbtn" title="Announce" name="action" value="announce"><span class="fa fa-bullhorn"></span></button>
{% elseif forumUnannounce %}
<button class="forumbtn" title="Unannounce" name="action" value="announce"><span class="fa fa-remove"></span></button>
{% endif %}
{% if forumLock %}
<button class="forumbtn" title="Lock" name="action" value="lock"><span class="fa fa-lock"></span></button>
{% elseif forumUnlock %}
<button class="forumbtn" title="Unlock" name="action" value="lock"><span class="fa fa-unlock"></span></button>
{% endif %}
{% if forumRestore %}
<button class="forumbtn" title="Restore" name="action" value="restore"><span class="fa fa-history"></span></button>
{% endif %}
{% if forumTrash %}
<button class="forumbtn" title="Trash" name="action" value="delete"><span class="fa fa-trash"></span></button>
{% elseif forumPrune %}
<button class="forumbtn" title="Prune" name="action" value="delete"><span class="fa fa-bomb"></span></button>
{% endif %}
</form>

View file

@ -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 %}

View file

@ -25,7 +25,7 @@
sure that it is spelled correctly.
</li>
<li>
Open the <a href="/">flashii.net</a>
Open the <a href="{{ route('main.index') }}">flashii.net</a>
home page, and then look for links to the information you want.
</li>
<li>
@ -33,7 +33,7 @@
button to try another link.
</li>
<li>
Click <img src="{{ sakura.resources }}/images/404-search.gif" /><a href="http://www.bing.com/search?q=flashii">Search</a>
Click <img src="{{ sakura.resources }}/images/404-search.gif" /><a href="{{ route('main.search') }}">Search</a>
to look for information on the Internet.
</li>
</ul>