aboutsummaryrefslogtreecommitdiffstats
path: root/core/include/search
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2017-04-11 07:13:13 +0200
committerThomas Lange <code@nerdmind.de>2017-04-11 07:13:13 +0200
commit85e48b669f65933d5376f9214219c7e5eb10a9e7 (patch)
tree5a08463dc9d770d98442e1c9f8d65044cdd9f1ff /core/include/search
parentdd0433cf81fe5329b694a148191f09e427d4a56c (diff)
downloadblog-85e48b669f65933d5376f9214219c7e5eb10a9e7.tar.gz
blog-85e48b669f65933d5376f9214219c7e5eb10a9e7.tar.xz
blog-85e48b669f65933d5376f9214219c7e5eb10a9e7.zip
The system directory has been moved to a non-public directory. After the commit e33c245d910e55b8cab407a03e669470509a705d, it is no longer necessary that the directory is publicly accessible via HTTP because all requests are running through the router.v1.2
Diffstat (limited to 'core/include/search')
-rw-r--r--core/include/search/main.php90
1 files changed, 90 insertions, 0 deletions
diff --git a/core/include/search/main.php b/core/include/search/main.php
new file mode 100644
index 0000000..8854b79
--- /dev/null
+++ b/core/include/search/main.php
@@ -0,0 +1,90 @@
+<?php
+#===============================================================================
+# Get instances
+#===============================================================================
+$Database = Application::getDatabase();
+$Language = Application::getLanguage();
+
+$SEARCH_SUCCESS = FALSE;
+$D_LIST = $Database->query(sprintf('SELECT DISTINCT DAY(time_insert) AS temp FROM %s ORDER BY temp', Post\Attribute::TABLE));
+$M_LIST = $Database->query(sprintf('SELECT DISTINCT MONTH(time_insert) AS temp FROM %s ORDER BY temp', Post\Attribute::TABLE));
+$Y_LIST = $Database->query(sprintf('SELECT DISTINCT YEAR(time_insert) AS temp FROM %s ORDER BY temp', Post\Attribute::TABLE));
+
+if($search = HTTP::GET('q')) {
+ if(!$postIDs = Post\Item::getSearchResultIDs($search, [HTTP::GET('d'), HTTP::GET('m'), HTTP::GET('y')], $Database)) {
+ $message = $Language->text('search_no_results', escapeHTML($search));
+ }
+}
+
+$form_data = [
+ 'SELECT' => [
+ 'D' => HTTP::GET('d'),
+ 'M' => HTTP::GET('m'),
+ 'Y' => HTTP::GET('y'),
+ ],
+ 'OPTIONS' => [
+ 'D' => $D_LIST->fetchAll($Database::FETCH_COLUMN),
+ 'M' => $M_LIST->fetchAll($Database::FETCH_COLUMN),
+ 'Y' => $Y_LIST->fetchAll($Database::FETCH_COLUMN),
+ ]
+];
+
+$search_data = [
+ 'TEXT' => $search,
+ 'INFO' => isset($message) ? $message : FALSE,
+];
+
+#===============================================================================
+# TRY: Template\Exception
+#===============================================================================
+try {
+ if(isset($postIDs) AND !empty($postIDs)) {
+ foreach($postIDs as $postID) {
+ try {
+ $Post = Post\Factory::build($postID);
+ $User = User\Factory::build($Post->attr('user'));
+
+ $posts[] = generatePostItemTemplate($Post, $User);
+ }
+ catch(Post\Exception $Exception){}
+ catch(User\Exception $Exception){}
+ }
+
+ $ResultTemplate = Template\Factory::build('search/result');
+ $ResultTemplate->set('FORM', $form_data);
+ $ResultTemplate->set('SEARCH', $search_data);
+ $ResultTemplate->set('RESULT', [
+ 'LIST' => $posts ?? []
+ ]);
+
+ $MainTemplate = Template\Factory::build('main');
+ $MainTemplate->set('HTML', $ResultTemplate);
+ $MainTemplate->set('HEAD', [
+ 'NAME' => $Language->text('title_search_results', escapeHTML($search)),
+ 'PERM' => Application::getURL('search/')
+ ]);
+ }
+
+ else {
+ $SearchTemplate = Template\Factory::build('search/main');
+ $SearchTemplate->set('FORM', $form_data);
+ $SearchTemplate->set('SEARCH', $search_data);
+
+ $MainTemplate = Template\Factory::build('main');
+ $MainTemplate->set('HTML', $SearchTemplate);
+ $MainTemplate->set('HEAD', [
+ 'NAME' => $Language->text('title_search_request'),
+ 'PERM' => Application::getURL('search/')
+ ]);
+ }
+
+ echo $MainTemplate;
+}
+
+#===============================================================================
+# CATCH: Template\Exception
+#===============================================================================
+catch(Template\Exception $Exception) {
+ Application::exit($Exception->getMessage());
+}
+?> \ No newline at end of file