From 6b2bfb726f61dba858b5d1ff1903e1aea79c5fe3 Mon Sep 17 00:00:00 2001 From: flashwave Date: Tue, 11 Feb 2025 02:41:49 +0000 Subject: [PATCH] Added ability to filter search by topic. --- VERSION | 2 +- public-legacy/search.php | 13 ++++++++++--- src/Forum/ForumPostsData.php | 4 ++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 039de05f..a8de9279 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -20250210 +20250210.1 diff --git a/public-legacy/search.php b/public-legacy/search.php index 85174264..7f01642c 100644 --- a/public-legacy/search.php +++ b/public-legacy/search.php @@ -33,6 +33,11 @@ Template::addFunction('search_merge_query', function($attrs) use (&$searchQueryE elseif(!empty($searchQueryEvaluated['after'])) $existing[] = 'after:' . $searchQueryEvaluated['after']; + if(!empty($attrs['topic'])) + $existing[] = 'topic:' . $attrs['topic']; + elseif(!empty($searchQueryEvaluated['topic'])) + $existing[] = 'topic:' . $searchQueryEvaluated['topic']; + $existing = array_merge($existing, array_unique(array_merge( $searchQueryEvaluated['query'], empty($attrs['query']) ? [] : explode(' ', $attrs['query']) @@ -41,7 +46,7 @@ Template::addFunction('search_merge_query', function($attrs) use (&$searchQueryE return implode(' ', $existing); }); if(!empty($searchQuery)) { - $searchQueryAttributes = ['type', 'author', 'after']; + $searchQueryAttributes = ['type', 'author', 'after', 'topic']; $searchQueryParts = explode(' ', $searchQuery); foreach($searchQueryParts as $queryPart) { $queryPart = trim($queryPart); @@ -141,8 +146,10 @@ if(!empty($searchQuery)) { else $newsCategoryInfos[$categoryId] = $categoryInfo = $msz->news->getCategory(postInfo: $postInfo); - $commentsCount = $postInfo->commentsSectionId !== null - ? $msz->comments->countPosts(categoryInfo: $postInfo->commentsSectionId, deleted: false) : 0; + $commentsCount = $msz->commentsCtx->posts->countPosts( + categoryName: $postInfo->commentsCategoryName, + deleted: false, + ); $newsPosts[] = [ 'post' => $postInfo, diff --git a/src/Forum/ForumPostsData.php b/src/Forum/ForumPostsData.php index 65fb6389..25e4b5a7 100644 --- a/src/Forum/ForumPostsData.php +++ b/src/Forum/ForumPostsData.php @@ -94,6 +94,7 @@ class ForumPostsData { && $searchQuery['type'] !== 'forum:post') return []; + $topicInfo = null; $userInfo = null; $deleted = false; $pagination = null; @@ -101,6 +102,9 @@ class ForumPostsData { $afterPostInfo = null; $newerThanDays = null; + if(!empty($searchQuery['topic'])) + $topicInfo = $searchQuery['topic']; + if(!empty($searchQuery['author'])) $userInfo = $searchQuery['author'];