Fixed pagination not counting properly for moderators, closes #123.

This commit is contained in:
flash 2019-01-05 18:21:48 +01:00
parent 2857f45f1a
commit ad6d4d9ec4
2 changed files with 15 additions and 9 deletions

View file

@ -4,20 +4,22 @@ require_once '../../misuzu.php';
$postId = (int)($_GET['p'] ?? 0);
$topicId = (int)($_GET['t'] ?? 0);
$topicUserId = user_session_current('user_id', 0);
if ($topicId < 1 && $postId > 0) {
$postInfo = forum_post_find($postId, user_session_current('user_id', 0));
$postInfo = forum_post_find($postId, $topicUserId);
if (!empty($postInfo['topic_id'])) {
$topicId = (int)$postInfo['topic_id'];
}
}
$topic = forum_topic_fetch($topicId);
$topic = forum_topic_fetch($topicId, $topicUserId);
$perms = $topic
? forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $topic['forum_id'], user_session_current('user_id', 0))
? forum_perms_get_user(MSZ_FORUM_PERMS_GENERAL, $topic['forum_id'], $topicUserId)
: 0;
if (user_warning_check_restriction(user_session_current('user_id', 0))) {
if (user_warning_check_restriction($topicUserId)) {
$perms &= ~MSZ_FORUM_PERM_SET_WRITE;
}
@ -61,7 +63,7 @@ if (!$posts) {
$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']);
forum_topic_mark_read($topicUserId, $topic['topic_id'], $topic['forum_id']);
echo tpl_render('forum.topic', [
'topic_breadcrumbs' => forum_get_breadcrumbs($topic['forum_id']),

View file

@ -69,33 +69,37 @@ function forum_topic_update(int $topicId, ?string $title, ?int $type = null): bo
return $updateTopic->execute();
}
function forum_topic_fetch(int $topicId, bool $showDeleted = false): array
function forum_topic_fetch(int $topicId, int $userId = 0): array
{
$getTopic = db_prepare(sprintf(
'
SELECT
t.`topic_id`, t.`forum_id`, t.`topic_title`, t.`topic_type`, t.`topic_locked`, t.`topic_created`,
f.`forum_archived` as `topic_archived`, t.`topic_deleted`, t.`topic_bumped`,
((%s) & %d) as `can_view_deleted`,
(
SELECT MIN(`post_id`)
FROM `msz_forum_posts`
WHERE `topic_id` = t.`topic_id`
%1$s
AND (`can_view_deleted` OR `post_deleted` IS NULL)
) as `topic_first_post_id`,
(
SELECT COUNT(`post_id`)
FROM `msz_forum_posts`
WHERE `topic_id` = t.`topic_id`
%1$s
AND (`can_view_deleted` OR `post_deleted` IS NULL)
) as `topic_post_count`
FROM `msz_forum_topics` as t
LEFT JOIN `msz_forum_categories` as f
ON f.`forum_id` = t.`forum_id`
WHERE t.`topic_id` = :topic_id
',
$showDeleted ? '' : 'AND `post_deleted` IS NULL'
forum_perms_get_user_sql(MSZ_FORUM_PERMS_GENERAL, 't.`forum_id`'),
MSZ_FORUM_PERM_DELETE_TOPIC | MSZ_FORUM_PERM_DELETE_ANY_POST
));
$getTopic->bindValue('topic_id', $topicId);
$getTopic->bindValue('perm_user_id_user', $userId);
$getTopic->bindValue('perm_user_id_role', $userId);
$topic = $getTopic->execute() ? $getTopic->fetch(PDO::FETCH_ASSOC) : false;
return $topic ? $topic : [];
}