2015-06-27 11:03:11 +00:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
* Sakura Forum Topic Viewer
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Declare Namespace
|
|
|
|
namespace Sakura;
|
|
|
|
|
2015-12-29 21:52:19 +00:00
|
|
|
use Sakura\Perms\Forum as ForumPerms;
|
|
|
|
|
2015-06-27 11:03:11 +00:00
|
|
|
// Include components
|
2015-12-03 19:40:01 +00:00
|
|
|
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . 'sakura.php';
|
2015-06-28 14:43:46 +00:00
|
|
|
|
2015-11-15 14:29:26 +00:00
|
|
|
// Attempt to get the thread
|
2015-11-22 22:10:23 +00:00
|
|
|
$thread = new Forum\Thread(
|
2015-10-11 21:59:17 +00:00
|
|
|
isset($_GET['p'])
|
2015-12-11 20:49:40 +00:00
|
|
|
? (new Forum\Post($_GET['p']))->thread
|
2015-10-11 21:59:17 +00:00
|
|
|
: (isset($_GET['t']) ? $_GET['t'] : 0)
|
|
|
|
);
|
2015-06-28 14:43:46 +00:00
|
|
|
|
2015-11-15 14:29:26 +00:00
|
|
|
// And attempt to get the forum
|
2015-11-22 22:10:23 +00:00
|
|
|
$forum = new Forum\Forum($thread->forum);
|
2015-11-15 14:29:26 +00:00
|
|
|
|
2015-06-28 14:43:46 +00:00
|
|
|
// Check if the forum exists
|
2015-11-15 14:29:26 +00:00
|
|
|
if (!$thread) {
|
2015-06-28 14:43:46 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
2015-09-14 20:51:23 +00:00
|
|
|
'message' => 'The topic you tried to access does not exist.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2015-06-28 14:43:46 +00:00
|
|
|
];
|
|
|
|
|
2015-11-06 22:30:37 +00:00
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2015-11-06 22:30:37 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2015-06-28 14:43:46 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2015-12-29 21:52:19 +00:00
|
|
|
// Check if the user has access to the forum
|
2016-01-17 01:58:31 +00:00
|
|
|
if (!$forum->permission(ForumPerms::VIEW, $currentUser->id)) {
|
2015-12-29 21:52:19 +00:00
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'message' => 'You do not have access to this thread.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2015-12-29 21:52:19 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2015-12-29 21:52:19 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2015-12-29 21:52:19 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2016-01-10 18:24:47 +00:00
|
|
|
// Sticky thread
|
2016-01-17 01:58:31 +00:00
|
|
|
if (isset($_GET['sticky']) && $_GET['sticky'] == session_id() && $forum->permission(ForumPerms::STICKY, $currentUser->id)) {
|
2016-01-10 18:24:47 +00:00
|
|
|
// 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.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2016-01-10 18:24:47 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2016-01-10 18:24:47 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Announce thread
|
2016-01-17 01:58:31 +00:00
|
|
|
if (isset($_GET['announce']) && $_GET['announce'] == session_id() && $forum->permission(ForumPerms::ANNOUNCEMENT, $currentUser->id)) {
|
2016-01-10 18:24:47 +00:00
|
|
|
// 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.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2016-01-10 18:24:47 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2016-01-10 18:24:47 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lock thread
|
2016-01-17 01:58:31 +00:00
|
|
|
if (isset($_GET['lock']) && $_GET['lock'] == session_id() && $forum->permission(ForumPerms::LOCK, $currentUser->id)) {
|
2016-01-10 18:24:47 +00:00
|
|
|
// 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.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2016-01-10 18:24:47 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2016-01-10 18:24:47 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Trash thread
|
2016-01-17 01:58:31 +00:00
|
|
|
if (isset($_GET['trash']) && $_GET['trash'] == session_id() && $forum->permission(ForumPerms::MOVE, $currentUser->id)) {
|
2016-01-10 18:24:47 +00:00
|
|
|
// 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.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'message' => 'This thread is already trashed.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2016-01-10 18:24:47 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2016-01-10 18:24:47 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore thread
|
2016-01-17 01:58:31 +00:00
|
|
|
if (isset($_GET['restore']) && $_GET['restore'] == session_id() && $forum->permission(ForumPerms::MOVE, $currentUser->id)) {
|
2016-01-10 18:24:47 +00:00
|
|
|
// 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.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'message' => 'This thread has never been moved.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2016-01-10 18:24:47 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2016-01-10 18:24:47 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prune thread
|
2016-01-17 01:58:31 +00:00
|
|
|
if (isset($_GET['prune']) && $_GET['prune'] == session_id() && $forum->permission(ForumPerms::DELETE_ANY, $currentUser->id)) {
|
2016-01-10 18:24:47 +00:00
|
|
|
// Check the status
|
|
|
|
if ($thread->forum == Config::get('forum_trash_id')) {
|
|
|
|
$thread->delete();
|
|
|
|
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'message' => 'The thread has been pruned.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.forum', $thread->forum),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
} else {
|
|
|
|
// Set render data
|
|
|
|
$renderData['page'] = [
|
|
|
|
'message' => 'You can only prune trashed threads.',
|
2016-03-10 18:54:36 +00:00
|
|
|
'redirect' => Router::route('forums.thread', $thread->id),
|
2016-01-10 18:24:47 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set parse variables
|
2016-02-04 20:56:40 +00:00
|
|
|
Template::vars($renderData);
|
2016-01-10 18:24:47 +00:00
|
|
|
|
|
|
|
// Print page contents
|
2016-02-04 20:56:40 +00:00
|
|
|
echo Template::render('global/information');
|
2016-01-10 18:24:47 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2016-03-10 18:54:36 +00:00
|
|
|
header('Location: ' . Router::route('forums.thread', $thread->id));
|