1 | <?php |
||||
2 | /* |
||||
3 | You may not change or alter any portion of this comment or credits |
||||
4 | of supporting developers from this source code or any supporting source code |
||||
5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||||
6 | |||||
7 | This program is distributed in the hope that it will be useful, |
||||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
10 | */ |
||||
11 | |||||
12 | /** |
||||
13 | * @copyright The XUUPS Project http://sourceforge.net/projects/xuups/ |
||||
14 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
||||
15 | * @package Publisher |
||||
16 | * @subpackage Action |
||||
17 | * @since 1.0 |
||||
18 | * @author trabis <[email protected]> |
||||
19 | * @author Taiwen Jiang <[email protected]> |
||||
20 | */ |
||||
21 | |||||
22 | use Xmf\Request; |
||||
23 | use XoopsModules\Publisher; |
||||
24 | use XoopsModules\Publisher\Constants; |
||||
25 | |||||
26 | require_once __DIR__ . '/header.php'; |
||||
27 | xoops_loadLanguage('search'); |
||||
28 | //Checking general permissions |
||||
29 | $configHandler = xoops_getHandler('config'); |
||||
30 | $xoopsConfigSearch = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
31 | if (empty($xoopsConfigSearch['enable_search'])) { |
||||
32 | redirect_header(PUBLISHER_URL . '/index.php', 2, _NOPERM); |
||||
33 | // exit(); |
||||
34 | } |
||||
35 | |||||
36 | /** @var \XoopsModules\Publisher\Helper $helper */ |
||||
37 | $helper = \XoopsModules\Publisher\Helper::getInstance(); |
||||
38 | $groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||||
39 | $grouppermHandler = $helper->getHandler('GroupPerm'); |
||||
40 | $module_id = $helper->getModule()->mid(); |
||||
41 | |||||
42 | //Checking permissions |
||||
43 | if (!$helper->getConfig('perm_search') || !$grouppermHandler->checkRight('global', Constants::PUBLISHER_SEARCH, $groups, $module_id)) { |
||||
44 | redirect_header(PUBLISHER_URL, 2, _NOPERM); |
||||
45 | // exit(); |
||||
46 | } |
||||
47 | |||||
48 | $GLOBALS['xoopsConfig']['module_cache'][$module_id] = 0; |
||||
49 | $GLOBALS['xoopsOption']['template_main'] = 'publisher_search.tpl'; |
||||
50 | require_once $GLOBALS['xoops']->path('header.php'); |
||||
51 | |||||
52 | $module_info_search = $helper->getModule()->getInfo('search'); |
||||
53 | require_once PUBLISHER_ROOT_PATH . '/' . $module_info_search['file']; |
||||
54 | |||||
55 | $limit = 10; //$helper->getConfig('idxcat_perpage'); |
||||
56 | $uid = 0; |
||||
57 | $queries = []; |
||||
58 | $andor = Request::getString('andor', '', 'POST'); |
||||
59 | $start = Request::getInt('start', 0, 'POST'); |
||||
60 | $category = Request::getArray('category', [], 'POST'); |
||||
61 | $username = Request::getString('uname', '', 'POST'); |
||||
62 | $searchin = Request::getArray('searchin', [], 'POST'); |
||||
63 | $sortby = Request::getString('sortby', '', 'POST'); |
||||
64 | $term = Request::getString('term', '', 'POST'); |
||||
65 | |||||
66 | if (empty($category) || (is_array($category) && in_array('all', $category))) { |
||||
67 | $category = []; |
||||
68 | } else { |
||||
69 | $category = !is_array($category) ? explode(',', $category) : $category; |
||||
70 | $category = array_map('intval', $category); |
||||
71 | } |
||||
72 | |||||
73 | $andor = in_array(mb_strtoupper($andor), ['OR', 'AND', 'EXACT']) ? mb_strtoupper($andor) : 'OR'; |
||||
74 | $sortby = in_array(mb_strtolower($sortby), ['itemid', 'datesub', 'title', 'categoryid']) ? mb_strtolower($sortby) : 'itemid'; |
||||
75 | |||||
76 | if ($term && 'none' !== Request::getString('submit', 'none', 'POST')) { |
||||
77 | $next_search['category'] = implode(',', $category); |
||||
78 | $next_search['andor'] = $andor; |
||||
79 | $next_search['term'] = $term; |
||||
80 | $query = trim($term); |
||||
81 | |||||
82 | if ('EXACT' !== $andor) { |
||||
83 | $ignored_queries = []; // holds keywords that are shorter than allowed minimum length |
||||
84 | $temp_queries = preg_split("/[\s,]+/", $query); |
||||
85 | foreach ($temp_queries as $q) { |
||||
86 | $q = trim($q); |
||||
87 | if (mb_strlen($q) >= $xoopsConfigSearch['keyword_min']) { |
||||
88 | $queries[] = $myts->addSlashes($q); |
||||
89 | } else { |
||||
90 | $ignored_queries[] = $myts->addSlashes($q); |
||||
91 | } |
||||
92 | } |
||||
93 | // unset($q); |
||||
94 | if (0 == count($queries)) { |
||||
95 | redirect_header(PUBLISHER_URL . '/search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min'])); |
||||
96 | // exit(); |
||||
97 | } |
||||
98 | } else { |
||||
99 | if (mb_strlen($query) < $xoopsConfigSearch['keyword_min']) { |
||||
100 | redirect_header(PUBLISHER_URL . '/search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min'])); |
||||
101 | // exit(); |
||||
102 | } |
||||
103 | $queries = [$myts->addSlashes($query)]; |
||||
104 | } |
||||
105 | |||||
106 | $uname_required = false; |
||||
107 | $search_username = trim($username); |
||||
108 | $next_search['uname'] = $search_username; |
||||
109 | if (!empty($search_username)) { |
||||
110 | $uname_required = true; |
||||
111 | $search_username = $myts->addSlashes($search_username); |
||||
112 | if (!$result = $GLOBALS['xoopsDB']->query('SELECT uid FROM ' . $GLOBALS['xoopsDB']->prefix('users') . ' WHERE uname LIKE ' . $GLOBALS['xoopsDB']->quoteString("%$search_username%"))) { |
||||
113 | redirect_header(PUBLISHER_URL . '/search.php', 1, _CO_PUBLISHER_ERROR); |
||||
114 | // exit(); |
||||
115 | } |
||||
116 | $uid = []; |
||||
117 | while (false !== ($row = $GLOBALS['xoopsDB']->fetchArray($result))) { |
||||
118 | $uid[] = $row['uid']; |
||||
119 | } |
||||
120 | } else { |
||||
121 | $uid = 0; |
||||
122 | } |
||||
123 | |||||
124 | $next_search['sortby'] = $sortby; |
||||
125 | $next_search['searchin'] = implode('|', $searchin); |
||||
126 | |||||
127 | $extra = ''; |
||||
128 | if (!empty($time)) { |
||||
129 | $extra = ''; |
||||
130 | } |
||||
131 | |||||
132 | if ($uname_required && (!$uid || count($uid) < 1)) { |
||||
0 ignored issues
–
show
It seems like
$uid can also be of type integer ; however, parameter $var of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
133 | $results = []; |
||||
134 | } else { |
||||
135 | $results = $module_info_search['func']($queries, $andor, $limit, $start, $uid, $category, $sortby, $searchin, $extra); |
||||
136 | } |
||||
137 | |||||
138 | if (count($results) < 1) { |
||||
139 | $results[] = ['text' => _SR_NOMATCH]; |
||||
140 | } |
||||
141 | |||||
142 | $xoopsTpl->assign('results', $results); |
||||
143 | |||||
144 | if (count($next_search) > 0) { |
||||
145 | $items = []; |
||||
146 | foreach ($next_search as $para => $val) { |
||||
147 | if (!empty($val)) { |
||||
148 | $items[] = "{$para}={$val}"; |
||||
149 | } |
||||
150 | } |
||||
151 | if (count($items) > 0) { |
||||
152 | $paras = implode('&', $items); |
||||
153 | } |
||||
154 | unset($next_search, $para, $val, $items); |
||||
155 | } |
||||
156 | $search_url = PUBLISHER_URL . '/search.php?' . $paras; |
||||
157 | |||||
158 | if (count($results)) { |
||||
159 | $next = $start + $limit; |
||||
160 | $queries = implode(',', $queries); |
||||
161 | $search_url_next = $search_url . "&start={$next}"; |
||||
162 | $search_next = '<a href="' . htmlspecialchars($search_url_next, ENT_QUOTES | ENT_HTML5) . '">' . _SR_NEXT . '</a>'; |
||||
163 | $xoopsTpl->assign('search_next', $search_next); |
||||
164 | } |
||||
165 | if ($start > 0) { |
||||
166 | $prev = $start - $limit; |
||||
167 | $search_url_prev = $search_url . "&start={$prev}"; |
||||
168 | $search_prev = '<a href="' . htmlspecialchars($search_url_prev, ENT_QUOTES | ENT_HTML5) . '">' . _SR_PREVIOUS . '</a>'; |
||||
169 | $xoopsTpl->assign('search_prev', $search_prev); |
||||
170 | } |
||||
171 | |||||
172 | unset($results); |
||||
173 | $search_info = _SR_KEYWORDS . ': ' . $myts->htmlSpecialChars($term); |
||||
174 | if ($uname_required) { |
||||
175 | if ($search_info) { |
||||
176 | $search_info .= '<br>'; |
||||
177 | } |
||||
178 | $search_info .= _CO_PUBLISHER_UID . ': ' . $myts->htmlSpecialChars($search_username); |
||||
179 | } |
||||
180 | $xoopsTpl->assign('search_info', $search_info); |
||||
181 | } |
||||
182 | |||||
183 | /* type */ |
||||
184 | $typeSelect = '<select name="andor">'; |
||||
185 | $typeSelect .= '<option value="OR"'; |
||||
186 | if ('OR' === $andor) { |
||||
187 | $typeSelect .= ' selected="selected"'; |
||||
188 | } |
||||
189 | $typeSelect .= '>' . _SR_ANY . '</option>'; |
||||
190 | $typeSelect .= '<option value="AND"'; |
||||
191 | if ('AND' === $andor) { |
||||
192 | $typeSelect .= ' selected="selected"'; |
||||
193 | } |
||||
194 | $typeSelect .= '>' . _SR_ALL . '</option>'; |
||||
195 | $typeSelect .= '<option value="EXACT"'; |
||||
196 | if ('EXACT' === $andor) { |
||||
197 | $typeSelect .= ' selected="selected"'; |
||||
198 | } |
||||
199 | $typeSelect .= '>' . _SR_EXACT . '</option>'; |
||||
200 | $typeSelect .= '</select>'; |
||||
201 | |||||
202 | /* category */ |
||||
203 | $categories = $helper->getHandler('Category')->getCategoriesForSearch(); |
||||
0 ignored issues
–
show
The method
getCategoriesForSearch() does not exist on XoopsObjectHandler . It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
204 | |||||
205 | $categorySelect = '<select name="category[]" size="5" multiple="multiple">'; |
||||
206 | $categorySelect .= '<option value="all"'; |
||||
207 | if (empty($category) || 0 == count($category)) { |
||||
208 | $categorySelect .= 'selected="selected"'; |
||||
209 | } |
||||
210 | $categorySelect .= '>' . _ALL . '</option>'; |
||||
211 | foreach ($categories as $id => $cat) { |
||||
212 | $categorySelect .= '<option value="' . $id . '"'; |
||||
213 | if (in_array($id, $category)) { |
||||
214 | $categorySelect .= 'selected="selected"'; |
||||
215 | } |
||||
216 | $categorySelect .= '>' . $cat . '</option>'; |
||||
217 | } |
||||
218 | unset($id, $cat); |
||||
219 | $categorySelect .= '</select>'; |
||||
220 | |||||
221 | /* scope */ |
||||
222 | $searchSelect = ''; |
||||
223 | $searchSelect .= '<input type="checkbox" name="searchin[]" value="title"'; |
||||
224 | if (in_array('title', $searchin)) { |
||||
225 | $searchSelect .= ' checked'; |
||||
226 | } |
||||
227 | $searchSelect .= '>' . _CO_PUBLISHER_TITLE . ' '; |
||||
228 | $searchSelect .= '<input type="checkbox" name="searchin[]" value="subtitle"'; |
||||
229 | if (in_array('subtitle', $searchin)) { |
||||
230 | $searchSelect .= ' checked'; |
||||
231 | } |
||||
232 | $searchSelect .= '>' . _CO_PUBLISHER_SUBTITLE . ' '; |
||||
233 | $searchSelect .= '<input type="checkbox" name="searchin[]" value="summary"'; |
||||
234 | if (in_array('summary', $searchin)) { |
||||
235 | $searchSelect .= ' checked'; |
||||
236 | } |
||||
237 | $searchSelect .= '>' . _CO_PUBLISHER_SUMMARY . ' '; |
||||
238 | $searchSelect .= '<input type="checkbox" name="searchin[]" value="text"'; |
||||
239 | if (in_array('body', $searchin)) { |
||||
240 | $searchSelect .= ' checked'; |
||||
241 | } |
||||
242 | $searchSelect .= '>' . _CO_PUBLISHER_BODY . ' '; |
||||
243 | $searchSelect .= '<input type="checkbox" name="searchin[]" value="keywords"'; |
||||
244 | if (in_array('meta_keywords', $searchin)) { |
||||
245 | $searchSelect .= ' checked'; |
||||
246 | } |
||||
247 | $searchSelect .= '>' . _CO_PUBLISHER_ITEM_META_KEYWORDS . ' '; |
||||
248 | $searchSelect .= '<input type="checkbox" name="searchin[]" value="all"'; |
||||
249 | if (empty($searchin) || in_array('all', $searchin)) { |
||||
250 | $searchSelect .= ' checked'; |
||||
251 | } |
||||
252 | $searchSelect .= '>' . _ALL . ' '; |
||||
253 | |||||
254 | /* sortby */ |
||||
255 | $sortbySelect = '<select name="sortby">'; |
||||
256 | $sortbySelect .= '<option value="itemid"'; |
||||
257 | if ('itemid' === $sortby || empty($sortby)) { |
||||
258 | $sortbySelect .= ' selected="selected"'; |
||||
259 | } |
||||
260 | $sortbySelect .= '>' . _NONE . '</option>'; |
||||
261 | $sortbySelect .= '<option value="datesub"'; |
||||
262 | if ('datesub' === $sortby) { |
||||
263 | $sortbySelect .= ' selected="selected"'; |
||||
264 | } |
||||
265 | $sortbySelect .= '>' . _CO_PUBLISHER_DATESUB . '</option>'; |
||||
266 | $sortbySelect .= '<option value="title"'; |
||||
267 | if ('title' === $sortby) { |
||||
268 | $sortbySelect .= ' selected="selected"'; |
||||
269 | } |
||||
270 | $sortbySelect .= '>' . _CO_PUBLISHER_TITLE . '</option>'; |
||||
271 | $sortbySelect .= '<option value="categoryid"'; |
||||
272 | if ('categoryid' === $sortby) { |
||||
273 | $sortbySelect .= ' selected="selected"'; |
||||
274 | } |
||||
275 | $sortbySelect .= '>' . _CO_PUBLISHER_CATEGORY . '</option>'; |
||||
276 | $sortbySelect .= '</select>'; |
||||
277 | |||||
278 | $xoopsTpl->assign('type_select', $typeSelect); |
||||
279 | $xoopsTpl->assign('searchin_select', $searchSelect); |
||||
280 | $xoopsTpl->assign('category_select', $categorySelect); |
||||
281 | $xoopsTpl->assign('sortby_select', $sortbySelect); |
||||
282 | $xoopsTpl->assign('search_term', htmlspecialchars($term, ENT_QUOTES)); |
||||
283 | $xoopsTpl->assign('search_user', $username); |
||||
284 | |||||
285 | $xoopsTpl->assign('modulename', $helper->getModule()->name()); |
||||
286 | $xoopsTpl->assign('module_dirname', $helper->getDirname()); |
||||
287 | |||||
288 | if ($xoopsConfigSearch['keyword_min'] > 0) { |
||||
289 | $xoopsTpl->assign('search_rule', sprintf(_SR_KEYIGNORE, $xoopsConfigSearch['keyword_min'])); |
||||
290 | } |
||||
291 | |||||
292 | require $GLOBALS['xoops']->path('footer.php'); |
||||
293 |