Added permission checks to the recursive read status and last post function.
This commit is contained in:
parent
3686429df9
commit
deda5b1996
1 changed files with 47 additions and 35 deletions
|
@ -270,7 +270,6 @@ function forum_get_child_ids(int $forumId): array
|
||||||
return $memoized[$forumId] = array_column($children, 'forum_id');
|
return $memoized[$forumId] = array_column($children, 'forum_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Permissions checks
|
|
||||||
function forum_topics_unread(int $forumId, int $userId): int
|
function forum_topics_unread(int $forumId, int $userId): int
|
||||||
{
|
{
|
||||||
if ($userId < 1 || $forumId < 1) {
|
if ($userId < 1 || $forumId < 1) {
|
||||||
|
@ -291,27 +290,33 @@ function forum_topics_unread(int $forumId, int $userId): int
|
||||||
$memoized[$memoId] += forum_topics_unread($child, $userId);
|
$memoized[$memoId] += forum_topics_unread($child, $userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
$countUnread = db_prepare('
|
$countUnread = db_prepare(sprintf(
|
||||||
SELECT COUNT(ti.`topic_id`)
|
'
|
||||||
FROM `msz_forum_topics` AS ti
|
SELECT COUNT(ti.`topic_id`)
|
||||||
LEFT JOIN `msz_forum_topics_track` AS tt
|
FROM `msz_forum_topics` AS ti
|
||||||
ON tt.`topic_id` = ti.`topic_id` AND tt.`user_id` = :user_id
|
LEFT JOIN `msz_forum_topics_track` AS tt
|
||||||
WHERE ti.`forum_id` = :forum_id
|
ON tt.`topic_id` = ti.`topic_id` AND tt.`user_id` = :user_id
|
||||||
AND ti.`topic_deleted` IS NULL
|
WHERE ti.`forum_id` = :forum_id
|
||||||
AND ti.`topic_bumped` >= NOW() - INTERVAL 1 MONTH
|
AND (%s) > %d
|
||||||
AND (
|
AND ti.`topic_deleted` IS NULL
|
||||||
tt.`track_last_read` IS NULL
|
AND ti.`topic_bumped` >= NOW() - INTERVAL 1 MONTH
|
||||||
OR tt.`track_last_read` < ti.`topic_bumped`
|
AND (
|
||||||
)
|
tt.`track_last_read` IS NULL
|
||||||
');
|
OR tt.`track_last_read` < ti.`topic_bumped`
|
||||||
|
)
|
||||||
|
',
|
||||||
|
forum_perms_get_user_sql(MSZ_FORUM_PERMS_GENERAL, 'ti.`forum_id`'),
|
||||||
|
MSZ_FORUM_PERM_SET_READ
|
||||||
|
));
|
||||||
$countUnread->bindValue('forum_id', $forumId);
|
$countUnread->bindValue('forum_id', $forumId);
|
||||||
$countUnread->bindValue('user_id', $userId);
|
$countUnread->bindValue('user_id', $userId);
|
||||||
|
$countUnread->bindValue('perm_user_id_user', $userId);
|
||||||
|
$countUnread->bindValue('perm_user_id_role', $userId);
|
||||||
$memoized[$memoId] += (int)($countUnread->execute() ? $countUnread->fetchColumn() : 0);
|
$memoized[$memoId] += (int)($countUnread->execute() ? $countUnread->fetchColumn() : 0);
|
||||||
|
|
||||||
return $memoized[$memoId];
|
return $memoized[$memoId];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Permission checks
|
|
||||||
function forum_latest_post(int $forumId, int $userId): array
|
function forum_latest_post(int $forumId, int $userId): array
|
||||||
{
|
{
|
||||||
if ($forumId < 1) {
|
if ($forumId < 1) {
|
||||||
|
@ -325,27 +330,34 @@ function forum_latest_post(int $forumId, int $userId): array
|
||||||
return $memoized[$memoId];
|
return $memoized[$memoId];
|
||||||
}
|
}
|
||||||
|
|
||||||
$getLastPost = db_prepare('
|
$getLastPost = db_prepare(sprintf(
|
||||||
SELECT
|
'
|
||||||
p.`post_id` AS `recent_post_id`, t.`topic_id` AS `recent_topic_id`,
|
SELECT
|
||||||
t.`topic_title` AS `recent_topic_title`, t.`topic_bumped` AS `recent_topic_bumped`,
|
p.`post_id` AS `recent_post_id`, t.`topic_id` AS `recent_topic_id`,
|
||||||
p.`post_created` AS `recent_post_created`,
|
t.`topic_title` AS `recent_topic_title`, t.`topic_bumped` AS `recent_topic_bumped`,
|
||||||
u.`user_id` AS `recent_post_user_id`,
|
p.`post_created` AS `recent_post_created`,
|
||||||
u.`username` AS `recent_post_username`,
|
u.`user_id` AS `recent_post_user_id`,
|
||||||
COALESCE(u.`user_colour`, r.`role_colour`) AS `recent_post_user_colour`,
|
u.`username` AS `recent_post_username`,
|
||||||
UNIX_TIMESTAMP(p.`post_created`) AS `post_created_unix`
|
COALESCE(u.`user_colour`, r.`role_colour`) AS `recent_post_user_colour`,
|
||||||
FROM `msz_forum_posts` AS p
|
UNIX_TIMESTAMP(p.`post_created`) AS `post_created_unix`
|
||||||
LEFT JOIN `msz_forum_topics` AS t
|
FROM `msz_forum_posts` AS p
|
||||||
ON t.`topic_id` = p.`topic_id`
|
LEFT JOIN `msz_forum_topics` AS t
|
||||||
LEFT JOIN `msz_users` AS u
|
ON t.`topic_id` = p.`topic_id`
|
||||||
ON u.`user_id` = p.`user_id`
|
LEFT JOIN `msz_users` AS u
|
||||||
LEFT JOIN `msz_roles` AS r
|
ON u.`user_id` = p.`user_id`
|
||||||
ON r.`role_id` = u.`display_role`
|
LEFT JOIN `msz_roles` AS r
|
||||||
WHERE p.`forum_id` = :forum_id
|
ON r.`role_id` = u.`display_role`
|
||||||
AND p.`post_deleted` IS NULL
|
WHERE p.`forum_id` = :forum_id
|
||||||
ORDER BY p.`post_id` DESC
|
AND p.`post_deleted` IS NULL
|
||||||
');
|
AND (%s) > %d
|
||||||
|
ORDER BY p.`post_id` DESC
|
||||||
|
',
|
||||||
|
forum_perms_get_user_sql(MSZ_FORUM_PERMS_GENERAL, 't.`forum_id`'),
|
||||||
|
MSZ_FORUM_PERM_SET_READ
|
||||||
|
));
|
||||||
$getLastPost->bindValue('forum_id', $forumId);
|
$getLastPost->bindValue('forum_id', $forumId);
|
||||||
|
$getLastPost->bindValue('perm_user_id_user', $userId);
|
||||||
|
$getLastPost->bindValue('perm_user_id_role', $userId);
|
||||||
$currentLast = db_fetch($getLastPost);
|
$currentLast = db_fetch($getLastPost);
|
||||||
|
|
||||||
$children = forum_get_child_ids($forumId);
|
$children = forum_get_child_ids($forumId);
|
||||||
|
|
Loading…
Add table
Reference in a new issue