From 955b4a1fc8f03eb6e98a920bdab0df8de3bbff24 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 7 Jul 2023 19:37:32 +0100 Subject: [PATCH 1/2] Fix forum index showing topics without view other topics permission --- modules/Forum/classes/Forum.php | 98 ++++++++++++++++-------- modules/Forum/pages/forum/view_forum.php | 2 +- 2 files changed, 66 insertions(+), 34 deletions(-) diff --git a/modules/Forum/classes/Forum.php b/modules/Forum/classes/Forum.php index 1c8b862457..7cdf4a57ef 100644 --- a/modules/Forum/classes/Forum.php +++ b/modules/Forum/classes/Forum.php @@ -62,7 +62,15 @@ public function listAllForums(array $groups = [0], int $user_id = 0): array { // Get discussion forums $forums = $this->_db->query( <<getAnySubforums($item->id, $groups, 0, true, $user_id); - $latest_post = [$item->last_post_date, $item->last_user_posted, $item->last_topic_posted]; + if ($item->view_other_topics) { + $latest_post = [$item->last_post_date, $item->last_user_posted, $item->last_topic_posted]; + } else { + $latest_post = $this->getLatestPostInOwnTopicForum($item->id, $user_id); + } if (count($subforums)) { $return[$forum->id]['subforums'][$item->id]->subforums = []; @@ -733,41 +745,18 @@ public function getAnySubforums( foreach ($subforums_query->results() as $result) { $to_add = new stdClass(); - $to_add->id = Output::getClean($result->id); + $to_add->id = $result->id; $to_add->forum_title = Output::getClean($result->forum_title); $to_add->icon = Output::getPurified($result->icon); $to_add->category = false; // Latest post - if ($onlyOwnTopics && $result->view_other_topics != '1') { - // Get the latest topic that the user can view - $latest_post = $this->_db->query( - <<id, $user_id] - ); - - if ($latest_post->count() && $latest_post = $latest_post->first()) { - $to_add->last_post_date = $latest_post->created ?? strtotime($latest_post->post_date); - $to_add->last_user_posted = $latest_post->post_creator; - $to_add->last_topic_posted = $latest_post->topic_id; - } + if ($onlyOwnTopics && $result->view_other_topics !== 1) { + [ + $to_add->last_post_date, + $to_add->last_user_posted, + $to_add->last_topic_posted, + ] = $this->getLatestPostInOwnTopicForum($result->id, $user_id); } else { $to_add->last_post_date = $result->last_post_date; $to_add->last_user_posted = $result->last_user_posted; @@ -776,7 +765,7 @@ public function getAnySubforums( $ret[] = $to_add; - $subforums = $this->getAnySubforums($result->id, $groups, ++$depth); + $subforums = $this->getAnySubforums($result->id, $groups, ++$depth, $onlyOwnTopics, $user_id); if (count($subforums)) { foreach ($subforums as $subforum) { @@ -808,4 +797,47 @@ public static function getAccessibleLabels(array $labels, array $user_groups): a return $prev; }, []); } + + /** + * Get the latest post in a "View own topic" forum + * This could be a topic created by the user, or a sticky topic + * + * @param int $forumId + * @param int $userId + * @return array|null Time of latest post, post creator ID, topic ID + */ + private function getLatestPostInOwnTopicForum(int $forumId, int $userId): ?array { + $latest_post = $this->_db->query( + <<count() && $latest_post = $latest_post->first()) { + return [ + $latest_post->created ?? strtotime($latest_post->post_date), + $latest_post->post_creator, + $latest_post->topic_id, + ]; + } + + return null; + } } diff --git a/modules/Forum/pages/forum/view_forum.php b/modules/Forum/pages/forum/view_forum.php index e8040fca3f..742a7abbf4 100644 --- a/modules/Forum/pages/forum/view_forum.php +++ b/modules/Forum/pages/forum/view_forum.php @@ -192,7 +192,7 @@ if ($forum->canViewOtherTopics($subforum->id, $user_groups)) { $latest_post = DB::getInstance()->query('SELECT * FROM nl2_topics WHERE forum_id = ? AND deleted = 0 ORDER BY topic_reply_date DESC', [$subforum->id])->results(); } else { - $latest_post = DB::getInstance()->query('SELECT * FROM nl2_topics WHERE forum_id = ? AND deleted = 0 AND topic_creator = ? ORDER BY topic_reply_date DESC', [$subforum->id, $user_id])->results(); + $latest_post = DB::getInstance()->query('SELECT * FROM nl2_topics WHERE forum_id = ? AND deleted = 0 AND (topic_creator = ? OR sticky = 1) ORDER BY topic_reply_date DESC', [$subforum->id, $user_id])->results(); } $subforum_topics = count($latest_post); From 093d4b3e919eca6e6f30731246b3cf460e9d3d70 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 2 Aug 2023 20:00:53 +0100 Subject: [PATCH 2/2] Small reactions fixes (#3411) * Small reactions fixes * Add close button to reactions modal and style updates * Add scroll bar back to reaction menu --- core/classes/Core/Validate.php | 2 +- .../Default/core/reactions_form.tpl | 2 +- custom/templates/DefaultRevamp/css/custom.css | 42 +++++++++++++++++-- .../DefaultRevamp/forum/view_topic.tpl | 1 + custom/templates/DefaultRevamp/profile.tpl | 1 + .../DefaultRevamp/reactions_modal.tpl | 2 +- 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/core/classes/Core/Validate.php b/core/classes/Core/Validate.php index 2124cf6d82..29dbf0572c 100644 --- a/core/classes/Core/Validate.php +++ b/core/classes/Core/Validate.php @@ -159,7 +159,7 @@ public static function check(array $source, array $items = []): Validate { if (empty($source[$array][$matches[1]])) { $missing = true; } - } else if (empty($value)) { + } else if (empty($value) && $value !== '0') { $missing = true; } diff --git a/custom/panel_templates/Default/core/reactions_form.tpl b/custom/panel_templates/Default/core/reactions_form.tpl index 93a1fc93e8..344d6a0b36 100644 --- a/custom/panel_templates/Default/core/reactions_form.tpl +++ b/custom/panel_templates/Default/core/reactions_form.tpl @@ -73,7 +73,7 @@ diff --git a/custom/templates/DefaultRevamp/css/custom.css b/custom/templates/DefaultRevamp/css/custom.css index 12a1fa23ed..ae0b7bcf8c 100755 --- a/custom/templates/DefaultRevamp/css/custom.css +++ b/custom/templates/DefaultRevamp/css/custom.css @@ -288,13 +288,17 @@ body.pushable>.pusher { } #topic-post #post-content { - margin-top: auto; padding: .7em 1.2em .7em 1.2em; min-height: 32.5px; - font-size: .85em; +} + +#post-content #reactions { + margin-top: auto; } .reaction-button { + margin-left: 5px; + margin-right: 5px; opacity: 50%; } @@ -1238,6 +1242,11 @@ body.dark .ui.threaded.comments .comment .text { color: #fff; } +body.dark .ui.segment .forum_post a, +body.dark .ui.comments .comment .forum_post a { + color: #62b6f7; +} + body.dark .ui.card .meta, .ui.cards>.card .meta, body.dark .ui.header, @@ -1331,6 +1340,7 @@ body.dark .ui.form input[type=url] { color: #fff; } +body.dark .ui.mini.message, body.dark .ui.mini.info.message { background-color: #282828; box-shadow: 0 0 0 1px #282828 inset, 0 0 0 0 transparent; @@ -1387,7 +1397,12 @@ body.dark .ui.table tbody tr td.selectable:hover { } } -body.dark .forum_post { +body.dark .forum_post, +body.dark .ui.comments .forum_post.text { + color: #fff; +} + +body.dark .ui.comments .comment .author { color: #fff; } @@ -1486,6 +1501,27 @@ body.dark .cc-window.cc-floating .cc-highlight .cc-btn.cc-allow { border-color: transparent; } +body.dark #modal-reactions .ui.menu { + background-color: #282828; + overflow-x: auto; +} + +body.dark #modal-reactions .ui.menu .item { + color: #fff; +} + +body.dark #modal-reactions .ui.menu .item.active { + background-color: #222; +} + +body.dark #modal-reactions .ui.large.selection.divided.list.middle.aligned .item .content { + color: #fff; +} + +body.dark ::-webkit-scrollbar-corner { + background-color: transparent; +} + /* * Colours */ diff --git a/custom/templates/DefaultRevamp/forum/view_topic.tpl b/custom/templates/DefaultRevamp/forum/view_topic.tpl index 6fd050e95e..8b49e0f0e9 100755 --- a/custom/templates/DefaultRevamp/forum/view_topic.tpl +++ b/custom/templates/DefaultRevamp/forum/view_topic.tpl @@ -291,6 +291,7 @@ {if $REACTIONS_ENABLED}