2018-05-18 01:20:27 +00:00
|
|
|
<?php
|
2019-03-07 18:11:24 +00:00
|
|
|
use Misuzu\Request\RequestVar;
|
|
|
|
|
2018-10-04 20:30:55 +00:00
|
|
|
require_once '../../misuzu.php';
|
2018-05-18 01:20:27 +00:00
|
|
|
|
2019-03-07 18:11:24 +00:00
|
|
|
$forumId = RequestVar::get()->select('f')->value('int');
|
|
|
|
$forumId = max($forumId, 0);
|
2018-05-18 01:20:27 +00:00
|
|
|
|
|
|
|
if ($forumId === 0) {
|
|
|
|
header('Location: /forum/');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2019-01-18 17:08:19 +00:00
|
|
|
$forum = forum_get($forumId);
|
2019-01-04 01:40:18 +00:00
|
|
|
$forumUserId = user_session_current('user_id', 0);
|
2018-05-18 01:20:27 +00:00
|
|
|
|
2018-05-23 01:41:57 +00:00
|
|
|
if (empty($forum) || ($forum['forum_type'] == MSZ_FORUM_TYPE_LINK && empty($forum['forum_link']))) {
|
2018-05-26 20:33:05 +00:00
|
|
|
echo render_error(404);
|
2018-05-18 01:20:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-04 01:40:18 +00:00
|
|
|
$perms = forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $forum['forum_id'], $forumUserId);
|
2018-08-23 20:06:48 +00:00
|
|
|
|
|
|
|
if (!perms_check($perms, MSZ_FORUM_PERM_VIEW_FORUM)) {
|
|
|
|
echo render_error(403);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-04 01:40:18 +00:00
|
|
|
if (user_warning_check_restriction($forumUserId)) {
|
2018-12-28 05:03:42 +00:00
|
|
|
$perms &= ~MSZ_FORUM_PERM_SET_WRITE;
|
|
|
|
}
|
|
|
|
|
2018-08-23 20:06:48 +00:00
|
|
|
tpl_var('forum_perms', $perms);
|
|
|
|
|
2018-05-23 01:41:57 +00:00
|
|
|
if ($forum['forum_type'] == MSZ_FORUM_TYPE_LINK) {
|
|
|
|
forum_increment_clicks($forum['forum_id']);
|
2018-05-18 01:20:27 +00:00
|
|
|
header('Location: ' . $forum['forum_link']);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-03 00:33:02 +00:00
|
|
|
$forumPagination = pagination_create($forum['forum_topic_count'], 20);
|
|
|
|
$topicsOffset = pagination_offset($forumPagination, pagination_param());
|
|
|
|
|
2019-01-03 16:00:13 +00:00
|
|
|
if (!pagination_is_valid_offset($topicsOffset) && $forum['forum_topic_count'] > 0) {
|
2019-01-03 00:33:02 +00:00
|
|
|
echo render_error(404);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-18 21:54:21 +00:00
|
|
|
$forumMayHaveTopics = forum_may_have_topics($forum['forum_type']);
|
|
|
|
$topics = $forumMayHaveTopics
|
2018-12-22 11:02:26 +00:00
|
|
|
? forum_topic_listing(
|
|
|
|
$forum['forum_id'],
|
2019-01-04 01:40:18 +00:00
|
|
|
$forumUserId,
|
2018-12-22 11:02:26 +00:00
|
|
|
$topicsOffset,
|
2019-01-03 00:33:02 +00:00
|
|
|
$forumPagination['range'],
|
2019-01-11 23:00:53 +00:00
|
|
|
perms_check($perms, MSZ_FORUM_PERM_DELETE_ANY_POST)
|
2018-12-22 11:02:26 +00:00
|
|
|
)
|
2018-05-24 00:38:42 +00:00
|
|
|
: [];
|
2018-05-18 01:20:27 +00:00
|
|
|
|
2018-10-18 21:54:21 +00:00
|
|
|
$forumMayHaveChildren = forum_may_have_children($forum['forum_type']);
|
2018-05-18 01:20:27 +00:00
|
|
|
|
2018-10-18 21:54:21 +00:00
|
|
|
if ($forumMayHaveChildren) {
|
2019-01-04 01:40:18 +00:00
|
|
|
$forum['forum_subforums'] = forum_get_children($forum['forum_id'], $forumUserId, MSZ_FORUM_POSTS_PER_PAGE);
|
2018-10-18 21:54:21 +00:00
|
|
|
|
|
|
|
foreach ($forum['forum_subforums'] as $skey => $subforum) {
|
|
|
|
$forum['forum_subforums'][$skey]['forum_subforums']
|
2019-01-04 01:40:18 +00:00
|
|
|
= forum_get_children($subforum['forum_id'], $forumUserId, MSZ_FORUM_POSTS_PER_PAGE, true);
|
2018-10-18 21:54:21 +00:00
|
|
|
}
|
2018-05-18 01:20:27 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 01:12:58 +00:00
|
|
|
echo tpl_render('forum.forum', [
|
2018-05-23 01:41:57 +00:00
|
|
|
'forum_breadcrumbs' => forum_get_breadcrumbs($forum['forum_id']),
|
2018-10-21 22:11:14 +00:00
|
|
|
'global_accent_colour' => forum_get_colour($forum['forum_id']),
|
2018-10-18 21:54:21 +00:00
|
|
|
'forum_may_have_topics' => $forumMayHaveTopics,
|
|
|
|
'forum_may_have_children' => $forumMayHaveChildren,
|
2018-05-18 01:20:27 +00:00
|
|
|
'forum_info' => $forum,
|
|
|
|
'forum_topics' => $topics,
|
2019-01-03 00:33:02 +00:00
|
|
|
'forum_pagination' => $forumPagination,
|
2018-05-18 01:20:27 +00:00
|
|
|
]);
|