misuzu/public/forum/topic.php

64 lines
1.8 KiB
PHP

<?php
require_once '../../misuzu.php';
$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) {
$postInfo = forum_post_find($postId);
if ($postInfo) {
$topicId = (int)$postInfo['target_topic_id'];
$postsOffset = floor($postInfo['preceeding_post_count'] / $postsRange) * $postsRange;
}
}
$topic = forum_topic_fetch($topicId);
$perms = $topic
? forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $topic['forum_id'], user_session_current('user_id', 0))
: 0;
if (user_warning_check_restriction(user_session_current('user_id', 0))) {
$perms &= ~MSZ_FORUM_PERM_SET_WRITE;
}
if (!$topic || ($topic['topic_deleted'] !== null && !perms_check($perms, MSZ_FORUM_PERM_DELETE_TOPIC))) {
echo render_error(404);
return;
}
if (!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) {
echo render_error(403);
return;
}
tpl_var('topic_perms', $perms);
$posts = forum_post_listing(
$topic['topic_id'],
$postsOffset,
$postsRange,
perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST)
);
if (!$posts) {
echo render_error(404);
return;
}
$canReply = empty($topic['topic_archived']) && empty($topic['topic_locked']) && empty($topic['topic_deleted'])
&& perms_check($perms, MSZ_FORUM_PERM_CREATE_POST);
forum_topic_mark_read(user_session_current('user_id', 0), $topic['topic_id'], $topic['forum_id']);
echo tpl_render('forum.topic', [
'topic_breadcrumbs' => forum_get_breadcrumbs($topic['forum_id']),
'global_accent_colour' => forum_get_colour($topic['forum_id']),
'topic_info' => $topic,
'topic_posts' => $posts,
'topic_offset' => $postsOffset,
'topic_range' => $postsRange,
'can_reply' => $canReply,
]);