diff --git a/public-legacy/comments.php b/public-legacy/comments.php index c2f7e92..68da310 100644 --- a/public-legacy/comments.php +++ b/public-legacy/comments.php @@ -31,7 +31,7 @@ if($msz->hasActiveBan()) { $comments = $msz->getComments(); -$commentPerms = $currentUserInfo->commentPerms(); +$commentPerms = perms_for_comments($currentUserInfo->getId()); $commentId = (string)filter_input(INPUT_GET, 'c', FILTER_SANITIZE_NUMBER_INT); $commentMode = (string)filter_input(INPUT_GET, 'm'); diff --git a/public/index.php b/public/index.php index 020e765..9d3fb76 100644 --- a/public/index.php +++ b/public/index.php @@ -168,6 +168,11 @@ $hasManageAccess = User::hasCurrent() && perms_check_user(MSZ_PERMS_GENERAL, User::getCurrent()->getId(), MSZ_PERM_GENERAL_CAN_MANAGE); Template::set('has_manage_access', $hasManageAccess); +$canViewForumLeaderboard = User::hasCurrent() + && !$msz->hasActiveBan() + && perms_check_user(MSZ_PERMS_GENERAL, User::getCurrent()->getId(), MSZ_PERM_FORUM_VIEW_LEADERBOARD); +Template::set('can_view_forum_leaderboard', $canViewForumLeaderboard); + if($inManageMode) { if(!$hasManageAccess) { echo render_error(403); diff --git a/src/Comments/CommentsEx.php b/src/Comments/CommentsEx.php index b89dddd..dcffad5 100644 --- a/src/Comments/CommentsEx.php +++ b/src/Comments/CommentsEx.php @@ -19,7 +19,9 @@ class CommentsEx { if(is_string($category)) $category = $this->comments->ensureCategory($category); - $info->user = User::getCurrent(); + $hasUser = User::hasCurrent(); + $info->user = $hasUser ? User::getCurrent() : null; + $info->perms = $hasUser ? perms_for_comments($info->user->getId()) : []; $info->category = $category; $info->posts = []; diff --git a/src/Users/User.php b/src/Users/User.php index 31e78b2..4dd3127 100644 --- a/src/Users/User.php +++ b/src/Users/User.php @@ -314,28 +314,6 @@ class User { ->execute(); } - // TODO: Is this the proper location/implementation for this? (no) - private $commentPermsArray = null; - public function commentPerms(): array { - if($this->commentPermsArray === null) - $this->commentPermsArray = perms_check_user_bulk(MSZ_PERMS_COMMENTS, $this->getId(), [ - 'can_comment' => MSZ_PERM_COMMENTS_CREATE, - 'can_delete' => MSZ_PERM_COMMENTS_DELETE_OWN | MSZ_PERM_COMMENTS_DELETE_ANY, - 'can_delete_any' => MSZ_PERM_COMMENTS_DELETE_ANY, - 'can_pin' => MSZ_PERM_COMMENTS_PIN, - 'can_lock' => MSZ_PERM_COMMENTS_LOCK, - 'can_vote' => MSZ_PERM_COMMENTS_VOTE, - ]); - return $this->commentPermsArray; - } - - private $legacyPerms = null; - public function getLegacyPerms(): array { - if($this->legacyPerms === null) - $this->legacyPerms = perms_get_user($this->getId()); - return $this->legacyPerms; - } - /************ * PASSWORD * ************/ diff --git a/src/perms.php b/src/perms.php index 5388131..635955f 100644 --- a/src/perms.php +++ b/src/perms.php @@ -261,3 +261,14 @@ function perms_check_user_bulk(string $prefix, ?int $userId, array $set, bool $s $perms = perms_get_user($userId)[$prefix] ?? 0; return perms_check_bulk($perms, $set, $strict); } + +function perms_for_comments(string|int $userId): array { + return perms_check_user_bulk(MSZ_PERMS_COMMENTS, (int)$userId, [ + 'can_comment' => MSZ_PERM_COMMENTS_CREATE, + 'can_delete' => MSZ_PERM_COMMENTS_DELETE_OWN | MSZ_PERM_COMMENTS_DELETE_ANY, + 'can_delete_any' => MSZ_PERM_COMMENTS_DELETE_ANY, + 'can_pin' => MSZ_PERM_COMMENTS_PIN, + 'can_lock' => MSZ_PERM_COMMENTS_LOCK, + 'can_vote' => MSZ_PERM_COMMENTS_VOTE, + ]); +} diff --git a/templates/_layout/comments.twig b/templates/_layout/comments.twig index 55e01a5..1b2d3c0 100644 --- a/templates/_layout/comments.twig +++ b/templates/_layout/comments.twig @@ -1,4 +1,4 @@ -{% macro comments_input(category, user, reply_to) %} +{% macro comments_input(category, user, perms, reply_to) %} {% set reply_mode = reply_to is not null %} {% from 'macros.twig' import avatar %} @@ -24,10 +24,10 @@ name="comment[text]" placeholder="Share your extensive insights...">