Duck hunt
load_lng('forum'); $textl = $lng_forum['search_forum']; require('../incfiles/head.php'); /* ----------------------------------------------------------------- Функция подсветки результатов запроса ----------------------------------------------------------------- */ function ReplaceKeywords($keywords, $value) { $a = stripos(mb_strtolower($value), mb_strtolower($keywords)); if ($a === false) return $value; else { $zamen = 'qwertyzxcytrewq'; $b = substr($value, $a, strlen($keywords)); preg_match_all("/<.*>/Usi", $value, $out); $value = preg_replace('/<.*>/Usi', $zamen, $value); $value = str_replace($b, '' . $b . '', $value); $heck = 0; for ($i = 0; $i < count($out[0]); $i++) { $heck = strpos($value, $zamen, $heck); $value = substr($value, 0, $heck) . $out[0][$i] . substr($value, $heck + strlen($zamen)); } return $value; } } echo '

' . functions::forum_new(1) . '

'; echo '
' . $lng['forum'] . ' | ' . $lng['search'] . '
'; /* ----------------------------------------------------------------- Принимаем данные, выводим форму поиска ----------------------------------------------------------------- */ $search = isset($_POST['search']) ? trim($_POST['search']) : ''; $search = $search ? $search : rawurldecode(trim($_GET['search'])); $search = preg_replace("/[^\w\x7F-\xFF\s]/", " ", $search); $search_t = isset($_REQUEST['t']) ? 1 : 0; $search = preg_replace('/ {2,}/', ' ', $search); $search = str_replace('qwertyzxcytrewq', '', $search); echo '

' . '' . '
' . ' ' . $lng_forum['search_topic_name'] . '

'; /* ----------------------------------------------------------------- Проверям на ошибки ----------------------------------------------------------------- */ $error = false; if ($search && (mb_strlen($search) < 4 || mb_strlen($search) > 64)) $error = $lng_forum['error_search_lenght']; if ($search && !$error) { /* ----------------------------------------------------------------- Выводим результаты запроса ----------------------------------------------------------------- */ $array = explode(' ', $search); $count = count($array); echo '
' . $lng['search_results'] . '
'; $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE MATCH (`text`) AGAINST ('" . mysql_real_escape_string($search) . "') AND `type` = '" . ($search_t ? 't' : 'm') . "'" . ($rights >= 7 ? "" : " AND `close` != '1'")), 0); if ($total) { $searchs = str_replace(' ', '|', $search); $req = mysql_query("SELECT * FROM `forum` WHERE MATCH (`text`) AGAINST ('" . mysql_real_escape_string($search) . "') AND `type` = '" . ($search_t ? 't' : 'm') . "' LIMIT $start, $kmess"); while ($res = mysql_fetch_assoc($req)) { echo $i % 2 ? '
' : '
'; if (!$search_t) { $req_t = mysql_query("SELECT `id`,`text` FROM `forum` WHERE `id` = '" . $res['refid'] . "'"); $res_t = mysql_fetch_assoc($req_t); echo '' . $res_t['text'] . '
'; } else { $req_p = mysql_query("SELECT `text` FROM `forum` WHERE `refid` = '" . $res['id'] . "' ORDER BY `id` ASC LIMIT 1"); $res_p = mysql_fetch_assoc($req_p); if ($count > 1) { for ($s = 0; $s <= count($array); $s++) { if (mb_strlen($array[$s]) >= 3) { $res['text'] = ReplaceKeywords($array[$s], $res['text']); } } } else { $res['text'] = ReplaceKeywords($search, $res['text']); } echo '' . $res['text'] . '
'; } echo '' . $res['from'] . ' '; echo ' (' . date("d.m.Y / H:i", $res['time'] + $set_user['sdvig'] * 3600) . ')
'; $text = $search_t ? $res_p['text'] : $res['text']; $text = functions::checkout(mb_substr($text, 0, 400), 2, 1); $text = str_replace('qwertyzxcytrewq', '', $text); $text = preg_replace('#\[c\](.*?)\[/c\]#si', '
\1
', $text); if (!$search_t) { if ($count > 1) { for ($s = 0; $s <= count($array); $s++) { if (mb_strlen($array[$s]) >= 3) { $text = ReplaceKeywords($array[$s], $text); } } } else { $text = ReplaceKeywords($search, $text); } } echo $text; if (mb_strlen($res['text']) > 400) echo '...' . $lng_forum['read_all'] . ' >>'; echo '
' . $lng_forum['to_topic'] . '' . ($search_t ? '' : ' | ' . $lng_forum['to_post'] . ''); echo '
'; ++$i; } } else { echo '

' . $lng['search_results_empty'] . '

'; } echo '
' . $lng['total'] . ': ' . $total . '
'; if ($total > $kmess) { // Навигация по страницам echo '

' . functions::display_pagination('search.php?' . ($search_t ? 't=1&' : '') . 'search=' . rawurlencode($search) . '&', $start, $total, $kmess) . '

' . '

' . '' . '' . '

'; } } else { /* ----------------------------------------------------------------- Выводим сообщение об ошибке ----------------------------------------------------------------- */ if ($error) echo functions::display_error($error); /* ----------------------------------------------------------------- Инструкции для поиска ----------------------------------------------------------------- */ echo '
' . $lng_forum['search_help'] . '
'; } echo '

' . ($search ? '' . $lng['search_new'] . '
' : '') . '' . $lng['to_forum'] . '

'; require('../incfiles/end.php'); ?>