2018-05-18 01:20:27 +00:00
|
|
|
<?php
|
2018-10-04 20:30:55 +00:00
|
|
|
require_once '../../misuzu.php';
|
2018-05-18 01:20:27 +00:00
|
|
|
|
2018-05-20 20:12:45 +00:00
|
|
|
$postId = (int)($_GET['p'] ?? 0);
|
|
|
|
$topicId = (int)($_GET['t'] ?? 0);
|
|
|
|
$postsOffset = max((int)($_GET['o'] ?? 0), 0);
|
|
|
|
$postsRange = max(min((int)($_GET['r'] ?? 10), 25), 5);
|
|
|
|
|
|
|
|
if ($topicId < 1 && $postId > 0) {
|
2018-05-23 01:41:57 +00:00
|
|
|
$postInfo = forum_post_find($postId);
|
2018-05-21 23:05:25 +00:00
|
|
|
|
|
|
|
if ($postInfo) {
|
|
|
|
$topicId = (int)$postInfo['target_topic_id'];
|
|
|
|
$postsOffset = floor($postInfo['preceeding_post_count'] / $postsRange) * $postsRange;
|
|
|
|
}
|
2018-05-20 20:12:45 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 00:38:42 +00:00
|
|
|
$topic = forum_topic_fetch($topicId);
|
2018-12-22 11:02:26 +00:00
|
|
|
$perms = $topic
|
|
|
|
? forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $topic['forum_id'], user_session_current('user_id', 0))
|
|
|
|
: 0;
|
2018-05-20 20:12:45 +00:00
|
|
|
|
2018-12-27 02:59:57 +00:00
|
|
|
if (!$topic || ($topic['topic_deleted'] !== null && !perms_check($perms, MSZ_FORUM_PERM_DELETE_TOPIC))) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-05-20 20:12:45 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-23 20:06:48 +00:00
|
|
|
if (!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) {
|
|
|
|
echo render_error(403);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-25 00:15:23 +00:00
|
|
|
tpl_var('topic_perms', $perms);
|
|
|
|
|
2018-12-22 11:02:26 +00:00
|
|
|
$posts = forum_post_listing(
|
|
|
|
$topic['topic_id'],
|
|
|
|
$postsOffset,
|
|
|
|
$postsRange,
|
|
|
|
perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST)
|
|
|
|
);
|
2018-05-20 20:12:45 +00:00
|
|
|
|
2018-05-21 23:05:25 +00:00
|
|
|
if (!$posts) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-05-21 23:05:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-02 22:34:05 +00:00
|
|
|
forum_topic_mark_read(user_session_current('user_id', 0), $topic['topic_id'], $topic['forum_id']);
|
2018-05-24 00:38:42 +00:00
|
|
|
|
2018-08-15 01:12:58 +00:00
|
|
|
echo tpl_render('forum.topic', [
|
2018-05-23 01:41:57 +00:00
|
|
|
'topic_breadcrumbs' => forum_get_breadcrumbs($topic['forum_id']),
|
2018-10-21 22:11:14 +00:00
|
|
|
'global_accent_colour' => forum_get_colour($topic['forum_id']),
|
2018-05-20 20:12:45 +00:00
|
|
|
'topic_info' => $topic,
|
|
|
|
'topic_posts' => $posts,
|
2018-05-21 23:05:25 +00:00
|
|
|
'topic_offset' => $postsOffset,
|
|
|
|
'topic_range' => $postsRange,
|
2018-05-20 20:12:45 +00:00
|
|
|
]);
|