From 52b077a48c743ba4d08ac00520a0bf1ef6deef5f Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Fri, 24 Feb 2017 21:27:59 +0100 Subject: Initial commit. --- system/search/main.php | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 system/search/main.php (limited to 'system/search/main.php') diff --git a/system/search/main.php b/system/search/main.php new file mode 100644 index 0000000..1c9921a --- /dev/null +++ b/system/search/main.php @@ -0,0 +1,89 @@ +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(PDO::FETCH_COLUMN), + 'M' => $M_LIST->fetchAll(PDO::FETCH_COLUMN), + 'Y' => $Y_LIST->fetchAll(PDO::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'), + 'DESC' => 'Wenn du einen bestimmten Beitrag suchst, aber ihn nicht finden kannst, dann kann dir die Suchfunktion bestimmt weiterhelfen.', + 'PERM' => Application::getURL('search/') + ]); + } + + echo $MainTemplate; +} + +#=============================================================================== +# CATCH: Template\Exception +#=============================================================================== +catch(Template\Exception $Exception) { + $Exception->defaultHandler(); +} +?> \ No newline at end of file -- cgit v1.2.3