-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSearch.php
More file actions
93 lines (78 loc) · 3.02 KB
/
Search.php
File metadata and controls
93 lines (78 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Controller;
use FeatherBB\Core\Error;
use FeatherBB\Core\Interfaces\ForumSettings;
use FeatherBB\Core\Interfaces\Hooks;
use FeatherBB\Core\Interfaces\Input;
use FeatherBB\Core\Interfaces\Lang;
use FeatherBB\Core\Interfaces\Router;
use FeatherBB\Core\Interfaces\User;
use FeatherBB\Core\Interfaces\View;
use FeatherBB\Core\Utils;
class Search
{
public function __construct()
{
$this->model = new \FeatherBB\Model\Search();
Lang::load('userlist');
Lang::load('search');
Lang::load('topic');
Lang::load('forum');
}
public function display($req, $res, $args)
{
Hooks::fire('controller.search.display');
if (!User::can('search.topics')) {
throw new Error(__('No search permission'), 403);
}
// Figure out what to do :-)
if (Input::query('action') || isset($args['search_id'])) {
$search = (isset($args['search_id'])) ? $this->model->getSearchResults($args['search_id']) : $this->model->getSearchResults();
if (is_object($search)) {
// $search is most likely a Router::redirect() to search page (no hits or other error) or to a search_id
return $search;
} else {
// No results to display, redirect with message
if (!isset($search['is_result'])) {
return Router::redirect(Router::pathFor('search'), ['error', __('No hits')]);
}
// We have results to display
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Search results')],
'active_page' => 'search',
'search' => $search,
'footer' => $search,
]);
$display = $this->model->displaySearchResults($search);
View::setPageInfo([
'display' => $display,
]);
if ($search['show_as'] == 'posts') {
View::addTemplate('@forum/search/posts')->display();
} else {
View::addTemplate('@forum/search/topics')->display();
}
}
}
// Display the form
else {
View::setPageInfo([
'title' => [Utils::escape(ForumSettings::get('o_board_title')), __('Search')],
'active_page' => 'search',
'is_indexed' => true,
'forums' => $this->model->forumsList(),
])->addTemplate('@forum/search/form')->display();
}
}
public function quicksearches($req, $res, $args)
{
Hooks::fire('controller.search.quicksearches');
return Router::redirect(Router::pathFor('search').'?action=show_'.$args['show']);
}
}