Просмотр файла forum/search.php

Размер файла: 12.47Kb
  1. <?php
  2. #-----------------------------------------------------#
  3. # ********* ROTORCMS ********* #
  4. # Made by : VANTUZ #
  5. # E-mail : visavi.net@mail.ru #
  6. # Site : http://pizdec.ru #
  7. # WAP-Site : http://visavi.net #
  8. # ICQ : 36-44-66 #
  9. # Вы не имеете право вносить изменения в код скрипта #
  10. # для его дальнейшего распространения #
  11. #-----------------------------------------------------#
  12. require_once ('../includes/start.php');
  13. require_once ('../includes/functions.php');
  14. require_once ('../includes/header.php');
  15. include_once ('../themes/' . $config['themes'] . '/index.php');
  16.  
  17. if (isset($_GET['start'])) {
  18. $start = abs(intval($_GET['start']));
  19. } else {
  20. $start = 0;
  21. }
  22. if (isset($_GET['act'])) {
  23. $act = check($_GET['act']);
  24. } else {
  25. $act = 'index';
  26. }
  27. if (isset($_GET['fid'])) {
  28. $fid = abs(intval($_GET['fid']));
  29. } else {
  30. $fid = 0;
  31. }
  32.  
  33. show_title('site.png', 'Поиск по форуму');
  34.  
  35. if (is_user()) {
  36. switch ($act):
  37. # ###########################################################################################
  38. # # Главная поиска ##
  39. # ###########################################################################################
  40. case "index":
  41.  
  42. $config['newtitle'] = 'Поиск по форуму';
  43.  
  44. $queryforum = DB :: $dbh -> query("SELECT `forums_id`, `forums_parent`, `forums_title` FROM `forums` ORDER BY `forums_order` ASC;");
  45. $forums = $queryforum -> fetchAll();
  46.  
  47. if (count($forums) > 0) {
  48. $output = array();
  49. foreach ($forums as $row) {
  50. $i = $row['forums_id'];
  51. $p = $row['forums_parent'];
  52. $output[$p][$i] = $row;
  53. }
  54.  
  55. echo '<div class="form" id="form"><form action="search.php?act=search&amp;' . SID . '" method="post">';
  56. echo 'Запрос:<br />';
  57. echo '<input type="text" name="find" /><br />';
  58.  
  59. echo 'Раздел:<br />';
  60. echo '<select name="section">';
  61. echo '<option value="0">Не имеет значения</option>';
  62.  
  63. foreach ($output[0] as $key => $data) {
  64. $selected = ($fid == $data['forums_id']) ? ' selected="selected"' : '';
  65.  
  66. echo '<option value="' . $data['forums_id'] . '"' . $selected . '>' . $data['forums_title'] . '</option>';
  67.  
  68. if (isset($output[$key])) {
  69. foreach($output[$key] as $datasub) {
  70. $selected = ($fid == $datasub['forums_id']) ? ' selected="selected"' : '';
  71. echo '<option value="' . $datasub['forums_id'] . '"' . $selected . '>– ' . $datasub['forums_title'] . '</option>';
  72. }
  73. }
  74. }
  75.  
  76. echo '</select><br />';
  77.  
  78. echo 'Период:<br />';
  79. echo '<select name="period">';
  80. echo '<option value="0">За все время</option>';
  81. echo '<option value="7">Последние 7 дней</option>';
  82. echo '<option value="30">Последние 30 дней</option>';
  83. echo '<option value="60">Последние 60 дней</option>';
  84. echo '<option value="90">Последние 90 дней</option>';
  85. echo '<option value="180">Последние 180 дней</option>';
  86. echo '<option value="365">Последние 365 дней</option>';
  87. echo '</select><br /><br />';
  88.  
  89. echo 'Искать:<br />';
  90. echo '<input name="where" type="radio" value="0" checked="checked" /> В темах<br />';
  91. echo '<input name="where" type="radio" value="1" /> В сообщениях<br /><br />';
  92.  
  93. echo 'Тип запроса:<br />';
  94. echo '<input name="type" type="radio" value="0" checked="checked" /> И<br />';
  95. echo '<input name="type" type="radio" value="1" /> Или<br />';
  96. echo '<input name="type" type="radio" value="2" /> Полный<br /><br />';
  97.  
  98. echo '<input type="submit" value="Поиск" /></form></div><br />';
  99. } else {
  100. show_error('Разделы форума еще не созданы!');
  101. }
  102. break;
  103. # ###########################################################################################
  104. # # Поиск ##
  105. # ###########################################################################################
  106. case "search":
  107.  
  108. if (isset($_POST['find'])) {
  109. $_SESSION['find'] = check(trim($_POST['find']));
  110. $_SESSION['findresult'] = '';
  111. }
  112. if (isset($_POST['type'])) {
  113. $type = abs(intval($_POST['type']));
  114. } else {
  115. $type = abs(intval($_GET['type']));
  116. }
  117. if (isset($_POST['where'])) {
  118. $where = abs(intval($_POST['where']));
  119. } else {
  120. $where = abs(intval($_GET['where']));
  121. }
  122. if (isset($_POST['period'])) {
  123. $period = abs(intval($_POST['period']));
  124. } else {
  125. $period = abs(intval($_GET['period']));
  126. }
  127. if (isset($_POST['section'])) {
  128. $section = abs(intval($_POST['section']));
  129. } else {
  130. $section = abs(intval($_GET['section']));
  131. }
  132.  
  133. if (utf_strlen($_SESSION['find']) < 50) {
  134. $findme = rus_utf_tolower($_SESSION['find']);
  135. $findmewords = explode(" ", $findme);
  136.  
  137. $find = array();
  138. foreach ($findmewords as $valfind) {
  139. if (utf_strlen($valfind) >= 3) {
  140. $find[] = $valfind;
  141. }
  142. }
  143. array_splice($find, 3);
  144.  
  145. if (count($find) > 0) {
  146. // -------------------------------- Кеширование запросов -----------------------------//
  147. $config['newtitle'] = $_SESSION['find'] . ' - Результаты поиска';
  148.  
  149. $types = (empty($type)) ? 'AND' : 'OR';
  150. $wheres = (empty($where)) ? 'topics' : 'posts';
  151. // ----------------------------- Поиск в темах -------------------------------//
  152. if ($wheres == 'topics') {
  153. echo 'Поиск запроса <b>&quot;' . $_SESSION['find'] . '&quot;</b> в темах<br />';
  154.  
  155. $searchsec = ($section > 0) ? "`topics_forums_id`=" . $section . " AND" : '';
  156. $searchper = ($period > 0) ? "`topics_time`>" . (SITETIME - ($period * 24 * 60 * 60)) . " AND" : '';
  157.  
  158. if ($type == 2) {
  159. $find[0] = $findme;
  160. }
  161. $search1 = (isset($find[1]) && $type != 2) ? $types . " `topics_title` LIKE '%" . $find[1] . "%'" : '';
  162. $search2 = (isset($find[2]) && $type != 2) ? $types . " `topics_title` LIKE '%" . $find[2] . "%'" : '';
  163.  
  164. if (empty($_SESSION['findresult'])) {
  165. $querysearch = DB :: $dbh -> query("SELECT `topics_id` FROM `topics` WHERE " . $searchsec . " " . $searchper . " `topics_title` LIKE '%" . $find[0] . "%' " . $search1 . " " . $search2 . " LIMIT 500;");
  166. $result = $querysearch -> fetchAll(PDO :: FETCH_COLUMN);
  167.  
  168. $_SESSION['findresult'] = $result;
  169. }
  170.  
  171. $total = count($_SESSION['findresult']);
  172.  
  173. if ($total > 0) {
  174. if ($start >= $total) {
  175. $start = 0;
  176. }
  177.  
  178. echo 'Найдено совпадений: <b>' . $total . '</b><br /><br />';
  179.  
  180. $result = implode(',', $_SESSION['findresult']);
  181.  
  182. $querypost = DB :: $dbh -> query("SELECT * FROM `topics` WHERE `topics_id` IN (" . $result . ") ORDER BY `topics_last_time` DESC LIMIT " . $start . ", " . $config['forumtem'] . ";");
  183.  
  184. while ($data = $querypost -> fetch()) {
  185. echo '<div class="b">';
  186.  
  187. if ($data['topics_locked'] == 1) {
  188. echo '<img src="../images/img/lock.gif" alt="image" /> ';
  189. } elseif ($data['topics_closed'] == 1) {
  190. echo '<img src="../images/img/closed.gif" alt="image" /> ';
  191. } else {
  192. echo '<img src="../images/img/forums.gif" alt="image" /> ';
  193. }
  194.  
  195. echo '<b><a href="topic.php?tid=' . $data['topics_id'] . '&amp;' . SID . '">' . $data['topics_title'] . '</a></b> (' . $data['topics_posts'] . ')</div>';
  196. echo '<div>Страницы: ';
  197. forum_navigation('topic.php?tid=' . $data['topics_id'] . '&amp;', $config['forumpost'], $data['topics_posts']);
  198. echo 'Сообщение: ' . nickname($data['topics_last_user']) . ' (' . date_fixed($data['topics_last_time']) . ')</div>';
  199. }
  200.  
  201. page_strnavigation('search.php?act=search&amp;type=' . $type . '&amp;where=' . $where . '&amp;period=' . $period . '&amp;section=' . $section . '&amp;', $config['forumtem'], $start, $total);
  202. } else {
  203. show_error('По вашему запросу ничего не найдено!');
  204. }
  205. }
  206. // --------------------------- Поиск в сообщениях -------------------------------//
  207. if ($wheres == 'posts') {
  208. echo 'Поиск запроса <b>&quot;' . $_SESSION['find'] . '&quot;</b> в сообщениях<br />';
  209.  
  210. $searchsec = ($section > 0) ? "`posts_forums_id`=" . $section . " AND" : '';
  211. $searchper = ($period > 0) ? "`posts_time`>" . (SITETIME - ($period * 24 * 60 * 60)) . " AND" : '';
  212. if ($type == 2) {
  213. $find[0] = $findme;
  214. }
  215. $search1 = (isset($find[1]) && $type != 2) ? $types . " `posts_text` LIKE '%" . $find[1] . "%'" : '';
  216. $search2 = (isset($find[2]) && $type != 2) ? $types . " `posts_text` LIKE '%" . $find[2] . "%'" : '';
  217.  
  218. if (empty($_SESSION['findresult'])) {
  219. $querysearch = DB :: $dbh -> query("SELECT `posts_id` FROM `posts` WHERE " . $searchsec . " " . $searchper . " `posts_text` LIKE '%" . $find[0] . "%' " . $search1 . " " . $search2 . " LIMIT 500;");
  220. $result = $querysearch -> fetchAll(PDO :: FETCH_COLUMN);
  221.  
  222. $_SESSION['findresult'] = $result;
  223. }
  224.  
  225. $total = count($_SESSION['findresult']);
  226.  
  227. if ($total > 0) {
  228. if ($start >= $total) {
  229. $start = 0;
  230. }
  231.  
  232. echo 'Найдено совпадений: <b>' . $total . '</b><br /><br />';
  233.  
  234. $result = implode(',', $_SESSION['findresult']);
  235.  
  236. $querypost = DB :: $dbh -> query("SELECT `posts`.*, `topics_title` FROM `posts` LEFT JOIN `topics` ON `posts`.`posts_topics_id`=`topics`.`topics_id` WHERE `posts_id` IN (" . $result . ") ORDER BY `posts_time` DESC LIMIT " . $start . ", " . $config['forumpost'] . ";");
  237.  
  238. while ($data = $querypost -> fetch()) {
  239. echo '<div class="b">';
  240.  
  241. echo '<img src="../images/img/forums.gif" alt="image" /> <b><a href="topic.php?act=viewpost&amp;tid=' . $data['posts_topics_id'] . '&amp;id=' . $data['posts_id'] . '&amp;' . SID . '">' . $data['topics_title'] . '</a></b></div>';
  242.  
  243. echo '<div>' . bb_code($data['posts_text']) . '<br />';
  244.  
  245. echo 'Написал: <a href="../pages/anketa.php?uz=' . $data['posts_user'] . '&amp;' . SID . '">' . nickname($data['posts_user']) . '</a> ' . user_online($data['posts_user']) . ' <small>(' . date_fixed($data['posts_time']) . ')</small><br />';
  246.  
  247. if (is_admin() || empty($config['anonymity'])) {
  248. echo '<span class="data">(' . $data['posts_brow'] . ', ' . $data['posts_ip'] . ')</span>';
  249. }
  250.  
  251. echo '</div>';
  252. }
  253.  
  254. page_strnavigation('search.php?act=search&amp;type=' . $type . '&amp;where=' . $where . '&amp;period=' . $period . '&amp;section=' . $section . '&amp;', $config['forumpost'], $start, $total);
  255. } else {
  256. show_error('По вашему запросу ничего не найдено!');
  257. }
  258. }
  259. } else {
  260. show_error('Ошибка! Необходимо не менее 3-х символов в слове!');
  261. }
  262. } else {
  263. show_error('Ошибка! Запрос должен содержать не более 50 символов!');
  264. }
  265.  
  266. echo '<img src="../images/img/back.gif" alt="image" /> <a href="search.php?' . SID . '">Вернуться</a><br />';
  267. break;
  268.  
  269. default:
  270. header("location: search.php?" . SID);
  271. exit;
  272. endswitch;
  273. } else {
  274. show_login('Вы не авторизованы, чтобы использовать поиск, необходимо');
  275. }
  276.  
  277. echo '<img src="../images/img/reload.gif" alt="image" /> <a href="index.php?' . SID . '">К форумам</a><br />';
  278. echo '<img src="../images/img/homepage.gif" alt="image" /> <a href="../index.php?' . SID . '">На главную</a>';
  279.  
  280. include_once ('../themes/' . $config['themes'] . '/foot.php');
  281.  
  282. ?>