-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.searchcategory.plugin.php
132 lines (110 loc) · 4.84 KB
/
class.searchcategory.plugin.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php if(!defined('APPLICATION')) exit();
/* Copyright 2013 Franco Solerio
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
$PluginInfo['SearchCategory'] = array(
'Name' => 'Search Category',
'Description' => 'Filters search by category.',
'Version' => '1.0',
'RequiredApplications' => array('Vanilla' => '2.1'),
'RequiredTheme' => FALSE,
'RequiredPlugins' => FALSE,
'MobileFriendly' => TRUE,
'HasLocale' => FALSE,
'RegisterPermissions' => FALSE,
// 'SettingsUrl' => '/settings/mandrillmailer',
// 'SettingsPermission' => 'Garden.Settings.Manage',
'Author' => "Franco Solerio",
'AuthorEmail' => '[email protected]',
'AuthorUrl' => 'http://digitalia.fm',
'License' => 'ApacheV2.0'
);
class SearchCategoryPlugin extends Gdn_Plugin {
// Overridden Index method of SearchController.php to retrieve category to search into from the form data
// and to call the overridden model's search() function with the added $CategoryFilter variable
//
public function SearchController_Index_Create($Sender, $Page = '') {
$Sender->AddJsFile('search.js');
$Sender->Title(T('Search'));
SaveToConfig('Garden.Format.EmbedSize', '160x90', FALSE);
list($Offset, $Limit) = OffsetLimit($Page, C('Garden.Search.PerPage', 20));
$Sender->SetData('_Limit', $Limit);
$CategoryToSearch = $Sender->Form->GetFormValue('CategoryID');
$Search = $Sender->Form->GetFormValue('Search');
$Mode = $Sender->Form->GetFormValue('Mode');
if ($Mode)
$Sender->SearchModel->ForceSearchMode = $Mode;
try {
$ResultSet = $Sender->SearchModel->Search($Search, $Offset, $Limit, $CategoryToSearch);
} catch (Gdn_UserException $Ex) {
$Sender->Form->AddError($Ex);
$ResultSet = array();
} catch (Exception $Ex) {
LogException($Ex);
$Sender->Form->AddError($Ex);
$ResultSet = array();
}
Gdn::UserModel()->JoinUsers($ResultSet, array('UserID'));
$Sender->SetData('SearchResults', $ResultSet, TRUE);
$Sender->SetData('SearchTerm', Gdn_Format::Text($Search), TRUE);
if($ResultSet)
$NumResults = count($ResultSet);
else
$NumResults = 0;
if ($NumResults == $Offset + $Limit)
$NumResults++;
// Build a pager
$PagerFactory = new Gdn_PagerFactory();
$Sender->Pager = $PagerFactory->GetPager('MorePager', $Sender);
$Sender->Pager->MoreCode = 'More Results';
$Sender->Pager->LessCode = 'Previous Results';
$Sender->Pager->ClientID = 'Pager';
$Sender->Pager->Configure(
$Offset,
$Limit,
$NumResults,
'dashboard/search/%1$s/%2$s/?Search='.Gdn_Format::Url($Search)
);
// if ($Sender->_DeliveryType != DELIVERY_TYPE_ALL) {
// $Sender->SetJson('LessRow', $Sender->Pager->ToString('less'));
// $Sender->SetJson('MoreRow', $Sender->Pager->ToString('more'));
// $Sender->View = 'results';
// }
$Sender->CanonicalUrl(Url('search', TRUE));
$Sender->Render();
}
// This is needed to override searchmodel.php with local copy
public function Gdn_Dispatcher_BeforeDispatch_Handler($Sender) {
require_once 'plugins/SearchCategory/class.searchmodel.php';
}
// Intercept render_before to render custom view instead of original forum/search?xx page
//
public function SearchController_Render_Before($Sender) {
$Sender->AddCssFile($this->GetResource('views/dashboard/search/style.css', FALSE, FALSE));
$Sender->AddJsFile($this->GetResource('js/searchcategory.js', FALSE, FALSE));
$View = 'dashboard/search/index.php';
$ThemeView = CombinePaths(array(PATH_THEMES, $Sender->Theme, strtolower($this->GetPluginFolder(false)), $View));
if (file_exists($ThemeView))
{
$Sender->View = $ThemeView;
} else {
$Sender->View = $this->GetView($View);
}
}
// Try to inject the search for category filter here (WHERE clause?)
//
public function SearchModel_Search_Handler($Sender) {
}
}
?>