aboutsummaryrefslogtreecommitdiffstats
path: root/core/include
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2021-07-22 21:04:02 +0200
committerThomas Lange <code@nerdmind.de>2021-07-22 21:04:02 +0200
commitcb9097e0199cf6afca3f144edb7d7addaec1cb59 (patch)
treeb4aff017f6a8c22b4b32c8316f4ae3b887bcbd3a /core/include
parentae38025d1d03ef3fa12c73b8ea48af3df02e2351 (diff)
downloadblog-cb9097e0199cf6afca3f144edb7d7addaec1cb59.tar.gz
blog-cb9097e0199cf6afca3f144edb7d7addaec1cb59.tar.xz
blog-cb9097e0199cf6afca3f144edb7d7addaec1cb59.zip
Add pagination for search results
Add pagination for search results in the admin and default theme.
Diffstat (limited to 'core/include')
-rw-r--r--core/include/search/main.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/core/include/search/main.php b/core/include/search/main.php
index 564f0dd..14c2ac9 100644
--- a/core/include/search/main.php
+++ b/core/include/search/main.php
@@ -10,6 +10,16 @@ $Language = Application::getLanguage();
$PostRepository = Application::getRepository('Post');
$UserRepository = Application::getRepository('User');
+#===============================================================================
+# Pagination
+#===============================================================================
+$site_size = Application::get('POST.LIST_SIZE');
+$site_sort = Application::get('POST.LIST_SORT');
+
+$currentSite = HTTP::GET('site') ?? 1;
+$currentSite = intval($currentSite);
+$offset = ($currentSite-1) * $site_size;
+
if($search = HTTP::GET('q')) {
$filter = [
'day' => HTTP::GET('d'),
@@ -17,7 +27,7 @@ if($search = HTTP::GET('q')) {
'year' => HTTP::GET('y')
];
- if(!$posts = $PostRepository->search($search, $filter)) {
+ if(!$posts = $PostRepository->search($search, $filter, $site_size, $offset)) {
$message = $Language->text('search_no_results', escapeHTML($search));
}
}
@@ -49,6 +59,9 @@ if(!empty($posts)) {
$templates[] = generatePostItemTemplate($Post, $User);
}
+ $count = $PostRepository->getLastSearchOverallCount();
+ $last = ceil($count / $site_size);
+
$ResultTemplate = Template\Factory::build('search/result');
$ResultTemplate->set('FORM', $form_data);
$ResultTemplate->set('SEARCH', $search_data);
@@ -56,6 +69,14 @@ if(!empty($posts)) {
'LIST' => $templates ?? []
]);
+ $ResultTemplate->set('PAGINATION', [
+ 'THIS' => $currentSite,
+ 'LAST' => $last,
+ 'HTML' => createPaginationTemplate(
+ $currentSite, $last, Application::getURL('search/')
+ )
+ ]);
+
$MainTemplate = Template\Factory::build('main');
$MainTemplate->set('HTML', $ResultTemplate);
$MainTemplate->set('HEAD', [