mambax7 /
newbb5
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | use Xmf\Metagen; |
||
| 4 | use Xmf\Highlighter; |
||
| 5 | use Xmf\Request; |
||
| 6 | |||
| 7 | // |
||
| 8 | // ------------------------------------------------------------------------ // |
||
| 9 | // XOOPS - PHP Content Management System // |
||
| 10 | // Copyright (c) 2000-2016 XOOPS.org // |
||
| 11 | // <http://xoops.org/> // |
||
| 12 | // ------------------------------------------------------------------------ // |
||
| 13 | // This program is free software; you can redistribute it and/or modify // |
||
| 14 | // it under the terms of the GNU General Public License as published by // |
||
| 15 | // the Free Software Foundation; either version 2 of the License, or // |
||
| 16 | // (at your option) any later version. // |
||
| 17 | // // |
||
| 18 | // You may not change or alter any portion of this comment or credits // |
||
| 19 | // of supporting developers from this source code or any supporting // |
||
| 20 | // source code which is considered copyrighted (c) material of the // |
||
| 21 | // original comment or credit authors. // |
||
| 22 | // // |
||
| 23 | // This program is distributed in the hope that it will be useful, // |
||
| 24 | // but WITHOUT ANY WARRANTY; without even the implied warranty of // |
||
| 25 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
||
| 26 | // GNU General Public License for more details. // |
||
| 27 | // // |
||
| 28 | // You should have received a copy of the GNU General Public License // |
||
| 29 | // along with this program; if not, write to the Free Software // |
||
| 30 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
||
| 31 | // ------------------------------------------------------------------------ // |
||
| 32 | // Author: phppp (D.J., [email protected]) // |
||
| 33 | // URL: http://xoops.org // |
||
| 34 | // Project: Article Project // |
||
| 35 | // ------------------------------------------------------------------------ // |
||
| 36 | |||
| 37 | include_once __DIR__ . '/header.php'; |
||
| 38 | xoops_loadLanguage('search'); |
||
| 39 | /** @var \XoopsConfigHandler $configHandler */ |
||
| 40 | $configHandler = xoops_getHandler('config'); |
||
| 41 | $xoopsConfigSearch = $configHandler->getConfigsByCat(XOOPS_CONF_SEARCH); |
||
| 42 | if ($xoopsConfigSearch['enable_search'] !== 1) { |
||
| 43 | redirect_header(XOOPS_URL . '/modules/newbb/index.php', 2, _MD_NEWBB_SEARCHDISABLED); |
||
| 44 | } |
||
| 45 | |||
| 46 | $GLOBALS['xoopsConfig']['module_cache'][$xoopsModule->getVar('mid')] = 0; |
||
| 47 | $xoopsOption['template_main'] = 'newbb_search.tpl'; |
||
| 48 | include_once $GLOBALS['xoops']->path('header.php'); |
||
| 49 | |||
| 50 | include_once __DIR__ . '/include/functions.render.php'; |
||
| 51 | include_once __DIR__ . '/include/functions.forum.php'; |
||
| 52 | include_once __DIR__ . '/include/functions.time.php'; |
||
| 53 | |||
| 54 | include_once $GLOBALS['xoops']->path('modules/newbb/include/search.inc.php'); |
||
| 55 | $limit = $GLOBALS['xoopsModuleConfig']['topics_per_page']; |
||
| 56 | |||
| 57 | $queries = []; |
||
| 58 | $andor = ''; |
||
| 59 | $start = 0; |
||
| 60 | $uid = 0; |
||
| 61 | $forum = 0; |
||
| 62 | $sortby = 'p.post_time'; // irmtfan remove DESC |
||
| 63 | $criteriaExtra = new CriteriaCompo(); // irmtfan new criteria |
||
| 64 | $searchin = 'both'; |
||
| 65 | $sort = ''; |
||
| 66 | $since = Request::getInt('since', null); |
||
| 67 | $next_search['since'] = $since; |
||
| 68 | $term = Request::getString('term', null); |
||
| 69 | $uname = Request::getString('uname', null); |
||
| 70 | // irmtfan add select parameters |
||
| 71 | $selectlength = Request::getInt('selectlength', 200); |
||
| 72 | |||
| 73 | // irmtfan assign default values to variables |
||
| 74 | $show_search = 'post_text'; |
||
| 75 | $search_username = trim($uname); |
||
| 76 | |||
| 77 | if ($GLOBALS['xoopsModuleConfig']['wol_enabled']) { |
||
| 78 | /** @var \NewbbOnlineHandler $onlineHandler */ |
||
| 79 | $onlineHandler = xoops_getModuleHandler('online', 'newbb'); |
||
| 80 | $onlineHandler->init(0); |
||
| 81 | } |
||
| 82 | |||
| 83 | $xoopsTpl->assign('forumindex', sprintf(_MD_NEWBB_FORUMINDEX, htmlspecialchars($GLOBALS['xoopsConfig']['sitename'], ENT_QUOTES))); |
||
| 84 | //$xoopsTpl->assign("img_folder", newbbDisplayImage($forumImage['topic'])); |
||
| 85 | |||
| 86 | if (!empty($uname) || Request::getString('submit', '') || !empty($term)) { |
||
| 87 | // irmtfan filter positive numbers |
||
| 88 | $selectlength = !empty($selectlength) ? abs($selectlength) : 200; |
||
| 89 | // irmtfan add select parameters for next search |
||
| 90 | $next_search['selectlength'] = $selectlength; |
||
| 91 | |||
| 92 | $start = Request::getInt('start', 0); |
||
| 93 | $forum = Request::getInt('forum', null); |
||
| 94 | if (empty($forum) || $forum === 'all' || (is_array($forum) && in_array('all', $forum, true))) { |
||
| 95 | $forum = []; |
||
| 96 | } elseif (!is_array($forum)) { |
||
| 97 | $forum = array_map('intval', explode('|', $forum)); |
||
| 98 | } |
||
| 99 | $next_search['forum'] = implode('|', $forum); |
||
| 100 | // START irmtfan topic search |
||
| 101 | $topic = Request::getString('topic', null); |
||
| 102 | $next_search['topic'] = $topic; |
||
| 103 | // END irmtfan topic search |
||
| 104 | // START irmtfan add show search |
||
| 105 | $show_search = Request::getString('show_search', 'post_text'); |
||
| 106 | $next_search['show_search'] = $show_search; |
||
| 107 | // START irmtfan add show search |
||
| 108 | |||
| 109 | $addterms = Request::getString('andor', 'AND'); |
||
| 110 | $next_search['andor'] = $addterms; |
||
| 111 | $andor = strtoupper($addterms); |
||
| 112 | if (!in_array($addterms, ['OR', 'AND'], true)) { |
||
| 113 | $andor = 'AND'; |
||
| 114 | } |
||
| 115 | |||
| 116 | $uname_required = false; |
||
| 117 | $next_search['uname'] = $search_username; |
||
| 118 | if (!empty($search_username)) { |
||
| 119 | $uname_required = true; |
||
| 120 | $search_username = $GLOBALS['xoopsDB']->escape($search_username); |
||
| 121 | if (!$result = $GLOBALS['xoopsDB']->query('SELECT uid FROM ' . $GLOBALS['xoopsDB']->prefix('users') . " WHERE uname LIKE '%$search_username%'")) { |
||
| 122 | redirect_header(XOOPS_URL . '/search.php', 1, _MD_NEWBB_ERROROCCURED); |
||
| 123 | } |
||
| 124 | $uid = []; |
||
| 125 | while ($row = $GLOBALS['xoopsDB']->fetchArray($result)) { |
||
| 126 | $uid[] = $row['uid']; |
||
| 127 | } |
||
| 128 | } else { |
||
| 129 | $uid = 0; |
||
| 130 | } |
||
| 131 | |||
| 132 | $next_search['term'] = htmlspecialchars($term, ENT_QUOTES); |
||
| 133 | $query = trim($term); |
||
| 134 | |||
| 135 | if ($andor !== 'EXACT') { |
||
| 136 | $ignored_queries = []; // holds keywords that are shorter than allowed minimum length |
||
| 137 | $temp_queries = str_getcsv($query, ' ', '"'); |
||
| 138 | foreach ($temp_queries as $q) { |
||
| 139 | $q = trim($q); |
||
| 140 | if (strlen($q) >= $xoopsConfigSearch['keyword_min']) { |
||
| 141 | $queries[] = $q; |
||
| 142 | } else { |
||
| 143 | $ignored_queries[] = $q; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | View Code Duplication | if (!$uname_required && count($queries) === 0) { |
|
| 147 | redirect_header(XOOPS_URL . '/search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min'])); |
||
| 148 | } |
||
| 149 | } else { |
||
| 150 | //$query = trim($query); |
||
| 151 | View Code Duplication | if (!$uname_required && (strlen($query) < $xoopsConfigSearch['keyword_min'])) { |
|
| 152 | redirect_header(XOOPS_URL . '/search.php', 2, sprintf(_SR_KEYTOOSHORT, $xoopsConfigSearch['keyword_min'])); |
||
| 153 | } |
||
| 154 | $queries = [$query]; |
||
| 155 | } |
||
| 156 | |||
| 157 | // entries must be lowercase |
||
| 158 | $allowed = ['p.post_time', 'p.subject']; // irmtfan just post time and subject |
||
| 159 | |||
| 160 | $sortby = Request::getString('sortby', 'p.post_time'); |
||
| 161 | $next_search['sortby'] = $sortby; |
||
| 162 | //$sortby = (in_array(strtolower($sortby), $allowed)) ? $sortby : 't.topic_last_post_id'; |
||
| 163 | $sortby = in_array(strtolower($sortby), $allowed) ? $sortby : 'p.post_time'; |
||
| 164 | $searchin = Request::getString('searchin', 'both'); |
||
| 165 | $next_search['searchin'] = $searchin; |
||
| 166 | // START irmtfan use criteria - add since and topic search |
||
| 167 | if (!empty($since)) { |
||
| 168 | $criteriaExtra->add(new Criteria('p.post_time', time() - newbb_getSinceTime($since), '>='), 'OR'); |
||
| 169 | } |
||
| 170 | if (is_numeric($topic) && !empty($topic)) { |
||
| 171 | $criteriaExtra->add(new Criteria('p.topic_id', $topic), 'OR'); |
||
| 172 | } |
||
| 173 | // END irmtfan use criteria - add since and topic search |
||
| 174 | |||
| 175 | if ($uname_required && (!$uid || count($uid) < 1)) { |
||
| 176 | $results = []; |
||
| 177 | } // irmtfan bug fix array() |
||
| 178 | else { |
||
| 179 | $results = newbb_search($queries, $andor, $limit, $start, $uid, $forum, $sortby, $searchin, $criteriaExtra); |
||
| 180 | } // irmtfan $criteriaExtra |
||
| 181 | |||
| 182 | $search_info_keywords = Highlighter::apply($myts->htmlSpecialChars($term, ENT_QUOTES), implode(' ', $queries), '<mark>', '</mark>'); |
||
| 183 | $num_results = count($results); |
||
| 184 | if ($num_results < 1) { |
||
| 185 | $xoopsTpl->assign('lang_nomatch', _SR_NOMATCH); |
||
| 186 | } else { |
||
| 187 | $skipresults = 0; |
||
| 188 | foreach ($results as $row) { |
||
| 189 | $post_text_select = ''; |
||
| 190 | $post_subject_select = Highlighter::apply($queries, $row['title'], '<mark>', '</mark>'); |
||
| 191 | if ($show_search === 'post_text') { |
||
| 192 | $post_text_select = Metagen::getSearchSummary($row['post_text'], $queries, $selectlength); |
||
| 193 | $post_text_select = Highlighter::apply($queries, $post_text_select, '<mark>', '</mark>'); |
||
| 194 | } |
||
| 195 | // if no text remained after select text continue |
||
| 196 | if (empty($post_text_select) && empty($post_subject_select)) { |
||
| 197 | ++$skipresults; |
||
| 198 | continue; |
||
| 199 | } |
||
| 200 | $xoopsTpl->append('results', [ |
||
| 201 | 'forum_name' => $row['forum_name'], |
||
| 202 | 'forum_link' => $row['forum_link'], |
||
| 203 | 'link' => $row['link'], |
||
| 204 | 'title' => $post_subject_select, |
||
| 205 | 'poster' => $row['poster'], |
||
| 206 | 'post_time' => formatTimestamp($row['time'], 'm'), |
||
| 207 | 'post_text' => $post_text_select |
||
| 208 | ]); |
||
| 209 | } |
||
| 210 | unset($results); |
||
| 211 | |||
| 212 | if (count($next_search) > 0) { |
||
| 213 | $items = []; |
||
| 214 | foreach ($next_search as $para => $val) { |
||
| 215 | $items[] = "{$para}=" . urlencode($val); |
||
| 216 | } |
||
| 217 | if (count($items) > 0) { |
||
| 218 | $paras = implode('&', $items); |
||
| 219 | } |
||
| 220 | unset($next_search, $items); |
||
| 221 | } |
||
| 222 | $search_url = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/search.php?' . $paras; |
||
| 223 | // irmtfan remove to have just one query and appropriate next and prev links |
||
| 224 | //$next_results = newbb_search($queries, $andor, 1, $start + $limit, $uid, $forum, $sortby, $searchin, $subquery); |
||
| 225 | //$next_count = count($next_results); |
||
| 226 | //$has_next = false; |
||
| 227 | //if (is_array($next_results) && $next_count >0) { |
||
| 228 | //$has_next = true; |
||
| 229 | //} |
||
| 230 | // irmtfan if $results < $limit => it is impossible to have next |
||
| 231 | if ($num_results == $limit) { |
||
| 232 | $next = $start + $limit; |
||
| 233 | $queries = implode(',', $queries); |
||
| 234 | $search_url_next = htmlspecialchars($search_url . "&direction=next&start={$next}"); |
||
| 235 | $search_next = '<a href="' . $search_url_next . '">' . _SR_NEXT . '</a>'; |
||
| 236 | $xoopsTpl->assign('search_next', $search_next); |
||
| 237 | $xoopsTpl->assign('search_next_url', $search_url_next); |
||
| 238 | } |
||
| 239 | if ($start > 0) { |
||
| 240 | $prev = $start - $limit; |
||
| 241 | $search_url_prev = htmlspecialchars($search_url . "&direction=previous&start={$prev}"); |
||
| 242 | $search_prev = '<a href="' . $search_url_prev . '">' . _SR_PREVIOUS . '</a>'; |
||
| 243 | $xoopsTpl->assign('search_prev', $search_prev); |
||
| 244 | $xoopsTpl->assign('search_prev_url', $search_url_prev); |
||
| 245 | } |
||
| 246 | // irmtfan if all results skipped then redirect to the next/previous page |
||
| 247 | if ($num_results == $skipresults) { |
||
| 248 | $direction = Request::getString('direction', 'next'); |
||
| 249 | $search_url_redirect = (strtolower($direction) === 'next') ? $search_url_next : $search_url_prev; |
||
| 250 | redirect_header($search_url_redirect, 1, constant(strtoupper("_SR_{$direction}"))); |
||
| 251 | } |
||
| 252 | } |
||
| 253 | $search_info = _SR_KEYWORDS . ': ' . $search_info_keywords; |
||
| 254 | if ($uname_required) { |
||
| 255 | if ($search_info) { |
||
| 256 | $search_info .= '<br>'; |
||
| 257 | } |
||
| 258 | $search_info .= _MD_NEWBB_USERNAME . ': ' . $myts->htmlSpecialChars($search_username); |
||
| 259 | } |
||
| 260 | // add num_results |
||
| 261 | $search_info .= '<br>' . sprintf(_SR_SHOWING, $start + 1, $start + $num_results); |
||
| 262 | // if any result skip show the counter |
||
| 263 | if (!empty($skipresults)) { |
||
| 264 | $search_info .= ' - ' . sprintf(_SR_FOUND, $num_results - $skipresults); |
||
| 265 | } |
||
| 266 | $xoopsTpl->assign('search_info', $search_info); |
||
| 267 | } |
||
| 268 | // assign template vars for search |
||
| 269 | /* term */ |
||
| 270 | $xoopsTpl->assign('search_term', htmlspecialchars($term, ENT_QUOTES)); |
||
| 271 | |||
| 272 | /* andor */ |
||
| 273 | $andor_select = '<select name="andor" id="andor" class="form-control">'; |
||
| 274 | $andor_select .= '<option value="OR"'; |
||
| 275 | if ('OR' === $andor) { |
||
| 276 | $andor_select .= ' selected="selected"'; |
||
| 277 | } |
||
| 278 | $andor_select .= '>' . _SR_ANY . '</option>'; |
||
| 279 | $andor_select .= '<option value="AND"'; |
||
| 280 | if ('AND' === $andor || empty($andor)) { |
||
| 281 | $andor_select .= ' selected="selected"'; |
||
| 282 | } |
||
| 283 | $andor_select .= '>' . _SR_ALL . '</option>'; |
||
| 284 | $andor_select .= '</select>'; |
||
| 285 | $xoopsTpl->assign('andor_selection_box', $andor_select); |
||
| 286 | |||
| 287 | /* forum */ |
||
| 288 | $select_forum = '<select class="form-control" name="forum[]" id="forum" size="5" multiple="multiple">'; |
||
| 289 | $select_forum .= '<option value="all">' . _MD_NEWBB_SEARCHALLFORUMS . '</option>'; |
||
| 290 | $select_forum .= newbb_forumSelectBox($forum); |
||
|
0 ignored issues
–
show
|
|||
| 291 | $select_forum .= '</select>'; |
||
| 292 | $xoopsTpl->assign_by_ref('forum_selection_box', $select_forum); |
||
| 293 | |||
| 294 | /* searchin */ |
||
| 295 | $searchin_select = ''; |
||
| 296 | $searchin_select .= '<label class="radio-inline"><input type="radio" name="searchin" value="title"'; |
||
| 297 | if ('title' === $searchin) { |
||
| 298 | $searchin_select .= ' checked'; |
||
| 299 | } |
||
| 300 | $searchin_select .= ' />' . _MD_NEWBB_SUBJECT . ' </label>'; |
||
| 301 | $searchin_select .= '<label class="radio-inline"><input type="radio" name="searchin" value="text"'; |
||
| 302 | if ('text' === $searchin) { |
||
| 303 | $searchin_select .= ' checked'; |
||
| 304 | } |
||
| 305 | $searchin_select .= ' />' . _MD_NEWBB_BODY . ' </label>'; |
||
| 306 | $searchin_select .= '<label class="radio-inline"><input type="radio" name="searchin" value="both"'; |
||
| 307 | if ('both' === $searchin || empty($searchin)) { |
||
| 308 | $searchin_select .= ' checked'; |
||
| 309 | } |
||
| 310 | $searchin_select .= ' />' . _MD_NEWBB_SUBJECT . ' & ' . _MD_NEWBB_BODY . ' </label>'; |
||
| 311 | $xoopsTpl->assign('searchin_radio', $searchin_select); |
||
| 312 | |||
| 313 | /* show_search */ |
||
| 314 | $show_search_select = ''; |
||
| 315 | $show_search_select .= '<label class="radio-inline"><input type="radio" name="show_search" value="post"'; |
||
| 316 | if ('post' === $show_search) { |
||
| 317 | $show_search_select .= ' checked'; |
||
| 318 | } |
||
| 319 | $show_search_select .= ' />' . _MD_NEWBB_POSTS . ' </label>'; |
||
| 320 | $show_search_select .= '<label class="radio-inline"><input type="radio" name="show_search" value="post_text"'; |
||
| 321 | if ('post_text' === $show_search || empty($show_search)) { |
||
| 322 | $show_search_select .= ' checked'; |
||
| 323 | } |
||
| 324 | $show_search_select .= ' />' . _MD_NEWBB_SEARCHPOSTTEXT . ' </label>'; |
||
| 325 | $xoopsTpl->assign('show_search_radio', $show_search_select); |
||
| 326 | |||
| 327 | /* author */ |
||
| 328 | $xoopsTpl->assign('author_select', $search_username); |
||
| 329 | |||
| 330 | /* sortby */ |
||
| 331 | $sortby_select = '<select name="sortby" id="sortby" class="form-control">'; |
||
| 332 | $sortby_select .= '<option value=\'p.post_time\''; |
||
| 333 | if ('p.post_time' === $sortby || empty($sortby)) { |
||
| 334 | $sortby_select .= ' selected=\'selected\''; |
||
| 335 | } |
||
| 336 | $sortby_select .= '>' . _MD_NEWBB_DATE . '</option>'; |
||
| 337 | $sortby_select .= '<option value=\'p.subject\''; |
||
| 338 | if ('p.subject' === $sortby) { |
||
| 339 | $sortby_select .= ' selected="selected"'; |
||
| 340 | } |
||
| 341 | $sortby_select .= '>' . _MD_NEWBB_TOPIC . '</option>'; |
||
| 342 | $sortby_select .= '</select>'; |
||
| 343 | $xoopsTpl->assign('sortby_selection_box', $sortby_select); |
||
| 344 | |||
| 345 | /* selectlength */ |
||
| 346 | $xoopsTpl->assign('selectlength_select', $selectlength); |
||
| 347 | |||
| 348 | // irmtfan get since from the user for selction box |
||
| 349 | $since = Request::getInt('since', $GLOBALS['xoopsModuleConfig']['since_default']); |
||
| 350 | $select_since = newbb_sinceSelectBox($since); |
||
| 351 | $xoopsTpl->assign_by_ref('since_selection_box', $select_since); |
||
| 352 | |||
| 353 | if ($xoopsConfigSearch['keyword_min'] > 0) { |
||
| 354 | $xoopsTpl->assign('search_rule', sprintf(_SR_KEYIGNORE, $xoopsConfigSearch['keyword_min'])); |
||
| 355 | } |
||
| 356 | // irmtfan move to footer.php |
||
| 357 | include_once __DIR__ . '/footer.php'; |
||
| 358 | include $GLOBALS['xoops']->path('footer.php'); |
||
| 359 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.