break; case SEARCH_FREQUENCY_TOO_GREAT: $search_limit_count = forum_get_setting('search_limit_count', 'is_numeric', 1); $search_limit_time = forum_get_setting('search_limit_time', 'is_numeric', 30); $error_msg_array[] = sprintf(gettext("You can only perform %d search(es) every %s seconds."), $search_limit_count, $search_limit_time); break; case SEARCH_SPHINX_UNAVAILABLE: $error_msg_array[] = gettext("Search is currently unavailable. Please try again later."); break; } } } } else { if (isset($_GET['page']) && is_numeric($_GET['page'])) { $page = $_GET['page']; if (($search_results_array = search_fetch_results($page, $sort_by, $sort_dir)) !== false) { html_draw_top(array('js' => array('js/search.js', 'js/search_popup.js', 'js/thread_list.js'))); thread_list_draw_top(SEARCH_RESULTS); echo "<br />\n"; echo "<h1>", gettext("Search Results"), "</h1>\n"; echo "", html_style_image('search', gettext("Found")), " ", gettext("Found"), ": {$search_results_array['result_count']} ", gettext("matches"), "<br />\n"; if ($page > 1) { echo "", html_style_image('current_thread', gettext("Previous page")), " <a href=\"search.php?webtag={$webtag}&page=", $page - 1, "&sort_by={$sort_by}&sort_dir={$sort_dir}\">", gettext("Previous page"), "</a>\n"; } echo "<ol start=\"", $page * 20 - 20 + 1, "\">\n"; foreach ($search_results_array['result_array'] as $search_result) { if (($message = messages_get($search_result['TID'], $search_result['PID'], 1)) !== false) { if (($thread_data = thread_get($search_result['TID'])) !== false) { $message['TITLE'] = trim($thread_data['TITLE']); // Fetch the messaage content, strip the signature and remove HTML. $message['CONTENT'] = message_get_content($search_result['TID'], $search_result['PID']);
function search_fetch_results($page, $sort_by = null, $sort_dir = null) { if (!is_numeric($page) || $page < 1) { $page = 1; } $offset = calculate_page_offset($page, 20); if (!($db = db::get())) { return false; } if (!($table_prefix = get_table_prefix())) { return false; } if (!isset($_SESSION['UID']) || !is_numeric($_SESSION['UID'])) { return false; } $search_keywords = search_get_keywords(); if (!in_array($sort_dir, array(SEARCH_SORT_ASC, SEARCH_SORT_DESC))) { $sort_dir = SEARCH_SORT_ASC; } $sort_dir = $sort_dir == SEARCH_SORT_DESC ? 'DESC' : 'ASC'; $sql = "SELECT SQL_CALC_FOUND_ROWS THREAD.FID, THREAD.TID, POST.PID, THREAD.BY_UID, POST.FROM_UID, "; $sql .= "USER_TRACK.USER_VALUE AS KEYWORDS, UNIX_TIMESTAMP(POST.CREATED) AS CREATED, "; $sql .= "USER.LOGON AS FROM_LOGON, COALESCE(USER_PEER.PEER_NICKNAME, USER.NICKNAME) AS FROM_NICKNAME "; $sql .= "FROM SEARCH_RESULTS INNER JOIN `{$table_prefix}THREAD` THREAD ON (THREAD.TID = SEARCH_RESULTS.TID) "; $sql .= "INNER JOIN `{$table_prefix}FOLDER` FOLDER ON (FOLDER.FID = THREAD.FID) "; $sql .= "INNER JOIN `{$table_prefix}POST` POST ON (POST.TID = SEARCH_RESULTS.TID AND POST.PID = SEARCH_RESULTS.PID) "; $sql .= "INNER JOIN USER ON (USER.UID = POST.FROM_UID) LEFT JOIN `{$table_prefix}USER_PEER` USER_PEER "; $sql .= "ON (USER_PEER.PEER_UID = POST.FROM_UID AND USER_PEER.UID = '{$_SESSION['UID']}') "; $sql .= "LEFT JOIN `{$table_prefix}USER_TRACK` USER_TRACK ON (USER_TRACK.UID = SEARCH_RESULTS.UID "; $sql .= "AND USER_TRACK.USER_KEY = 'LAST_SEARCH_KEYWORDS') "; $sql .= "WHERE SEARCH_RESULTS.UID = '{$_SESSION['UID']}' "; $sql .= "AND ((USER_PEER.RELATIONSHIP & " . USER_IGNORED_COMPLETELY . ") = 0 "; $sql .= "OR USER_PEER.RELATIONSHIP IS NULL) "; $sql .= "AND ((USER_PEER.RELATIONSHIP & " . USER_IGNORED . ") = 0 "; $sql .= "OR USER_PEER.RELATIONSHIP IS NULL) "; switch ($sort_by) { case SEARCH_SORT_RELEVANCE: $sql .= "ORDER BY SEARCH_RESULTS.RELEVANCE {$sort_dir} LIMIT {$offset}, 20"; break; case SEARCH_SORT_NUM_REPLIES: $sql .= "ORDER BY THREAD.LENGTH {$sort_dir} LIMIT {$offset}, 20"; break; case SEARCH_SORT_FOLDER_NAME: $sql .= "ORDER BY FOLDER.TITLE {$sort_dir} LIMIT {$offset}, 20"; break; case SEARCH_SORT_AUTHOR_NAME: $sql .= "ORDER BY FROM_NICKNAME {$sort_dir} LIMIT {$offset}, 20"; break; default: $sql .= "ORDER BY POST.CREATED {$sort_dir} LIMIT {$offset}, 20"; break; } if (!($result = $db->query($sql))) { return false; } $sql = "SELECT FOUND_ROWS() AS ROW_COUNT"; if (!($result_count = $db->query($sql))) { return false; } list($result_count) = $result_count->fetch_row(); if ($result->num_rows == 0 && $result_count > 0 && $page > 1) { return search_fetch_results($page - 1, $sort_by, $sort_dir); } $search_results_array = array(); while (($search_result = $result->fetch_assoc()) !== null) { $search_result['KEYWORDS'] = $search_keywords; if (isset($search_result['FROM_LOGON']) && isset($search_result['PEER_NICKNAME'])) { if (!is_null($search_result['PEER_NICKNAME']) && strlen($search_result['PEER_NICKNAME']) > 0) { $search_result['FROM_NICKNAME'] = $search_result['PEER_NICKNAME']; } } if (!isset($search_result['FROM_LOGON'])) { $search_result['FROM_LOGON'] = gettext("Unknown user"); } if (!isset($search_result['FROM_NICKNAME'])) { $search_result['FROM_NICKNAME'] = gettext("Unknown user"); } $search_results_array[] = $search_result; } return array('result_count' => $result_count, 'result_array' => $search_results_array); }
$valid = false; break; case SEARCH_FREQUENCY_TOO_GREAT: $search_frequency = forum_get_setting('search_min_frequency', null, 0); $error_msg_array[] = sprintf(gettext("You can only search once every %s seconds. Please try again later."), $search_frequency); break; case SEARCH_SPHINX_UNAVAILABLE: $error_msg_array[] = gettext("Search is currently unavailable. Please try again later."); break; } } } } else { if (isset($_GET['page']) && is_numeric($_GET['page'])) { $page = $_GET['page']; if ($search_results_array = search_fetch_results($page, $sort_by, $sort_dir)) { html_draw_top('search.js', 'search_popup.js'); thread_list_draw_top(SEARCH_RESULTS); echo "<br />\n"; echo "<h1>", gettext("Search Results"), "</h1>\n"; echo "<img src=\"", html_style_image('search.png'), "\" alt=\"", gettext("Found"), "\" title=\"", gettext("Found"), "\" /> ", gettext("Found"), ": {$search_results_array['result_count']} ", gettext("matches"), "<br />\n"; if ($page > 1) { echo "<img src=\"" . html_style_image('current_thread.png') . "\" alt=\"", gettext("Previous page"), "\" title=\"", gettext("Previous page"), "\" /> <a href=\"search.php?webtag={$webtag}&page=", $page - 1, "&sort_by={$sort_by}&sort_dir={$sort_dir}\">", gettext("Previous page"), "</a>\n"; } echo "<ol start=\"", $page * 20 - 20 + 1, "\">\n"; foreach ($search_results_array['result_array'] as $search_result) { if ($message = messages_get($search_result['TID'], $search_result['PID'], 1)) { $message['CONTENT'] = message_get_content($search_result['TID'], $search_result['PID']); if ($thread_data = thread_get($search_result['TID'])) { $message['TITLE'] = trim($thread_data['TITLE']); $message['CONTENT'] = trim(strip_tags(message_get_content($search_result['TID'], $search_result['PID'])));
$search_limit_count = forum_get_setting('search_limit_count', 'is_numeric', 1); $search_limit_time = forum_get_setting('search_limit_time', 'is_numeric', 30); $error_msg_array[] = sprintf(gettext("You can only perform %d search(es) every %s seconds."), $search_limit_count, $search_limit_time); break; case SEARCH_SPHINX_UNAVAILABLE: $error_msg_array[] = gettext("Search is currently unavailable. Please try again later."); break; } } else { header_redirect("lsearch.php?webtag={$webtag}&page=1"); exit; } } else { if (isset($_GET['page']) && is_numeric($_GET['page'])) { $page = $_GET['page']; if (($search_results_array = search_fetch_results($page)) !== false) { light_html_draw_top(); light_navigation_bar(); light_thread_list_draw_top(SEARCH_RESULTS); if ($page > 1) { echo "<div class=\"search_pagination\"><a href=\"lsearch.php?webtag={$webtag}&page=", $page - 1, "\">", gettext("Previous 20 results"), "</a></div>\n"; } else { echo "<div class=\"search_pagination\">", gettext("Found"), ": {$search_results_array['result_count']} ", gettext("matches"), "</div>\n"; } echo "<ol start=\"", $page * 20 - 20 + 1, "\">\n"; foreach ($search_results_array['result_array'] as $search_result) { if (($message = messages_get($search_result['TID'], $search_result['PID'], 1)) !== false) { if (($thread_data = thread_get($search_result['TID'])) !== false) { $message['TITLE'] = trim($thread_data['TITLE']); // Fetch the messaage content, strip the signature and remove HTML. $message['CONTENT'] = message_get_content($search_result['TID'], $search_result['PID']);