misuzu/public/forum/topic.php

74 lines
2.1 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);
if ($topicId < 1 && $postId > 0) {
2019-01-04 00:11:31 +00:00
$postInfo = forum_post_find($postId, user_session_current('user_id', 0));
2018-05-21 23:05:25 +00:00
2019-01-04 00:11:31 +00:00
if (!empty($postInfo['topic_id'])) {
$topicId = (int)$postInfo['topic_id'];
2018-05-21 23:05:25 +00:00
}
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 (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);
2018-05-20 20:12:45 +00:00
return;
}
if (!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) {
echo render_error(403);
return;
}
$topicPagination = pagination_create($topic['topic_post_count'], MSZ_FORUM_POSTS_PER_PAGE);
2019-01-03 00:33:02 +00:00
2019-01-03 02:19:53 +00:00
if (isset($postInfo['preceeding_post_count'])) {
2019-01-03 00:33:02 +00:00
$postsPage = floor($postInfo['preceeding_post_count'] / $topicPagination['range']) + 1;
}
2019-01-04 00:11:31 +00:00
$postsOffset = pagination_offset($topicPagination, $postsPage ?? pagination_param('page'));
2019-01-03 00:33:02 +00:00
if (!pagination_is_valid_offset($postsOffset)) {
echo render_error(404);
return;
}
2018-10-25 00:15:23 +00:00
tpl_var('topic_perms', $perms);
$posts = forum_post_listing(
$topic['topic_id'],
$postsOffset,
2019-01-03 00:33:02 +00:00
$topicPagination['range'],
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;
}
$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']);
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,
'can_reply' => $canReply,
2019-01-03 00:33:02 +00:00
'topic_pagination' => $topicPagination,
2018-05-20 20:12:45 +00:00
]);