misuzu/public/forum/topic.php

57 lines
1.5 KiB
PHP
Raw Normal View History

2018-05-18 01:20:27 +00:00
<?php
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
}
$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;
2018-05-20 20:12:45 +00:00
if (!$topic || !perms_check($perms, MSZ_FORUM_PERM_DELETE_TOPIC)) {
echo render_error(404);
2018-05-20 20:12:45 +00:00
return;
}
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);
$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) {
echo render_error(404);
2018-05-21 23:05:25 +00:00
return;
}
forum_topic_mark_read(user_session_current('user_id', 0), $topic['topic_id'], $topic['forum_id']);
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
]);