From cff7f23029e37e5e9c458aaf6f10110c7bd577a7 Mon Sep 17 00:00:00 2001
From: Thomas Lange <code@nerdmind.de>
Date: Sat, 24 Jul 2021 22:51:44 +0200
Subject: Show message if search was not successful

Show a message in the administration area's post and page search form if
the search query returned no results.
---
 admin/page/search.php | 7 ++++++-
 admin/post/search.php | 7 ++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

(limited to 'admin')

diff --git a/admin/page/search.php b/admin/page/search.php
index a88ab15..c9a39cf 100644
--- a/admin/page/search.php
+++ b/admin/page/search.php
@@ -31,7 +31,12 @@ $offset = ($currentSite-1) * $site_size;
 #===============================================================================
 if($search = HTTP::GET('q')) {
 	try {
-		foreach($PageRepository->search($search, [], $site_size, $offset) as $Page) {
+		if(!$pages = $PageRepository->search($search, [], $site_size, $offset)) {
+			$messages[] = Application::getLanguage()->text(
+				'search_no_results', htmlspecialchars($search));
+		}
+
+		foreach($pages as $Page) {
 			$User = $UserRepository->find($Page->get('user'));
 			$templates[] = generatePageItemTemplate($Page, $User);
 		}
diff --git a/admin/post/search.php b/admin/post/search.php
index 46ff60d..5ec7ddc 100644
--- a/admin/post/search.php
+++ b/admin/post/search.php
@@ -37,7 +37,12 @@ if($search = HTTP::GET('q')) {
 			'category' => HTTP::GET('category')
 		];
 
-		foreach ($PostRepository->search($search, $filter, $site_size, $offset) as $Post) {
+		if(!$posts = $PostRepository->search($search, $filter, $site_size, $offset)) {
+			$messages[] = Application::getLanguage()->text(
+				'search_no_results', htmlspecialchars($search));
+		}
+
+		foreach($posts as $Post) {
 			$User = $UserRepository->find($Post->get('user'));
 			$templates[] = generatePostItemTemplate($Post, $User);
 		}
-- 
cgit v1.2.3