aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-07-22 21:17:57 +0200
committerThomas Lange <code@nerdmind.de>2021-07-22 21:17:57 +0200
commit0db1beaea6b849790aa0f1f4ecbf6439ce4f1104 (patch)
treee4fb555253891bbf8b192cd7ab5fd28cd7ef914c
parentcb9097e0199cf6afca3f144edb7d7addaec1cb59 (diff)
downloadblog-0db1beaea6b849790aa0f1f4ecbf6439ce4f1104.tar.gz
blog-0db1beaea6b849790aa0f1f4ecbf6439ce4f1104.tar.xz
blog-0db1beaea6b849790aa0f1f4ecbf6439ce4f1104.zip
Catch possible PDOException for search request
Catch possible PDOException on search requests with queries like "*" and pass the exception message to the template for displaying.
-rw-r--r--admin/page/search.php13
-rw-r--r--admin/post/search.php13
-rw-r--r--core/include/search/main.php8
-rw-r--r--theme/admin/html/page/search.php10
-rw-r--r--theme/admin/html/post/search.php10
5 files changed, 46 insertions, 8 deletions
diff --git a/admin/page/search.php b/admin/page/search.php
index 85448df..a88ab15 100644
--- a/admin/page/search.php
+++ b/admin/page/search.php
@@ -30,9 +30,13 @@ $offset = ($currentSite-1) * $site_size;
# Check for search request
#===============================================================================
if($search = HTTP::GET('q')) {
- foreach($PageRepository->search($search, [], $site_size, $offset) as $Page) {
- $User = $UserRepository->find($Page->get('user'));
- $templates[] = generatePageItemTemplate($Page, $User);
+ try {
+ foreach($PageRepository->search($search, [], $site_size, $offset) as $Page) {
+ $User = $UserRepository->find($Page->get('user'));
+ $templates[] = generatePageItemTemplate($Page, $User);
+ }
+ } catch(PDOException $Exception) {
+ $messages[] = $Exception->getMessage();
}
}
@@ -57,6 +61,9 @@ if($count = $PageRepository->getLastSearchOverallCount()) {
$SearchTemplate = Template\Factory::build('page/search');
$SearchTemplate->set('QUERY', $search);
$SearchTemplate->set('PAGES', $templates ?? []);
+$SearchTemplate->set('FORM', [
+ 'INFO' => $messages ?? []
+]);
$SearchTemplate->set('PAGINATION', $pagination_data ?? []);
$MainTemplate = Template\Factory::build('main');
diff --git a/admin/post/search.php b/admin/post/search.php
index a270ccb..8cbfafb 100644
--- a/admin/post/search.php
+++ b/admin/post/search.php
@@ -30,9 +30,13 @@ $offset = ($currentSite-1) * $site_size;
# Check for search request
#===============================================================================
if($search = HTTP::GET('q')) {
- foreach($PostRepository->search($search, [], $site_size, $offset) as $Post) {
- $User = $UserRepository->find($Post->get('user'));
- $templates[] = generatePostItemTemplate($Post, $User);
+ try {
+ foreach ($PostRepository->search($search, [], $site_size, $offset) as $Post) {
+ $User = $UserRepository->find($Post->get('user'));
+ $templates[] = generatePostItemTemplate($Post, $User);
+ }
+ } catch(PDOException $Exception) {
+ $messages[] = $Exception->getMessage();
}
}
@@ -57,6 +61,9 @@ if($count = $PostRepository->getLastSearchOverallCount()) {
$SearchTemplate = Template\Factory::build('post/search');
$SearchTemplate->set('QUERY', $search);
$SearchTemplate->set('POSTS', $templates ?? []);
+$SearchTemplate->set('FORM', [
+ 'INFO' => $messages ?? []
+]);
$SearchTemplate->set('PAGINATION', $pagination_data ?? []);
$MainTemplate = Template\Factory::build('main');
diff --git a/core/include/search/main.php b/core/include/search/main.php
index 14c2ac9..9e7c0a7 100644
--- a/core/include/search/main.php
+++ b/core/include/search/main.php
@@ -27,8 +27,12 @@ if($search = HTTP::GET('q')) {
'year' => HTTP::GET('y')
];
- if(!$posts = $PostRepository->search($search, $filter, $site_size, $offset)) {
- $message = $Language->text('search_no_results', escapeHTML($search));
+ try {
+ if (!$posts = $PostRepository->search($search, $filter, $site_size, $offset)) {
+ $message = $Language->text('search_no_results', escapeHTML($search));
+ }
+ } catch(PDOException $Exception) {
+ $message = $Exception->getMessage();
}
}
diff --git a/theme/admin/html/page/search.php b/theme/admin/html/page/search.php
index 906502f..7250056 100644
--- a/theme/admin/html/page/search.php
+++ b/theme/admin/html/page/search.php
@@ -2,6 +2,16 @@
<h1><i class="fa fa-search"></i><?=$Language->text('title_page_search')?></h1>
<p><?=$Language->text('search_page_desc')?></p>
+<?php if($FORM['INFO']): ?>
+ <div id="message-list-wrapper">
+ <ul id="message-list">
+ <?php foreach($FORM['INFO'] as $message): ?>
+ <li><?=$message?></li>
+ <?php endforeach ?>
+ </ul>
+ </div>
+<?php endif ?>
+
<form id="search-form" method="GET">
<div class="form-grid no-bottom-border">
<label for="form_query">
diff --git a/theme/admin/html/post/search.php b/theme/admin/html/post/search.php
index 1afc5e7..10aa43d 100644
--- a/theme/admin/html/post/search.php
+++ b/theme/admin/html/post/search.php
@@ -2,6 +2,16 @@
<h1><i class="fa fa-search"></i><?=$Language->text('title_post_search')?></h1>
<p><?=$Language->text('search_post_desc')?></p>
+<?php if($FORM['INFO']): ?>
+ <div id="message-list-wrapper">
+ <ul id="message-list">
+ <?php foreach($FORM['INFO'] as $message): ?>
+ <li><?=$message?></li>
+ <?php endforeach ?>
+ </ul>
+ </div>
+<?php endif ?>
+
<form id="search-form" method="GET">
<div class="form-grid no-bottom-border">
<label for="form_query">