Файл: CMS/core/modules/search.php
Строк: 61
<?php
if (!defined('CMS')) { die('Access Denied!'); }
$q = !empty($_REQUEST['q']) ? (string) $_REQUEST['q'] : '';
$logic = !empty($_REQUEST['logic']) ? (string) $_REQUEST['logic'] : 'or';
$lang['OR'] = 'или';
$lang['AND'] = 'и';
$lang['SEARCH_WORD'] = '«%s»';
$error = '';
$bad_querius = array("x22", "x60", "t", "n", "r", "¬"); // Удаляемые символы из запроса
if ($is_logged) {
if (!empty($_REQUEST['q'])) {
if (!in_array($logic, array('and', 'or'))) {
$logic = 'or';
}
$logic = strtoupper( $logic );
$q = preg_replace('#[^a-zA-Zа-яА-Я0-9 -_@:;()+=.,&*!?<>#$"'/\]#siu', '', $q);
$q = preg_replace('/s/u', ' ', $q);
$q = preg_replace('/ {2,}/u', ' ', $q);
$q = str_replace($bad_querius, '', strip_tags($q));
if (get_magic_quotes_gpc()) $q = stripslashes($q);
$q = trim( $q );
if ( $q == '' ) {
$inSes->addMessage('Произошла Ошибка! Вы не ввели запрос "Что искать?"');
gen_red('search', '', RND);
}
else {
$q = explode(' ', $q);
array_splice($q, 3);
$escape_array = array(
"x2a" => "", //*
"x22" => "", //"
"x2b" => "", //+
"x2d" => "", //-
"x7e" => "", //~
"x28" => "", //(
"x29" => "", //)
"x3c" => "", //<
"x3e" => "" //>
);
for($i = 0, $query = array(); $i < count( $q ); $i++) {
$query[] = sprintf($lang['SEARCH_WORD'], check($q[$i]));
$q[$i] = strtr($q[$i], $escape_array);
}
$query = implode(' ' . $lang[$logic] . ' ', $query);
$part_of_news = $part_of_blog = $part_of_file = $part_of_forum = $part_of_photo = $part_of_comm = '';
for($i = 0, $sep = ''; $i < count( $q ); $i++, $sep = $logic) {
$part_of_news .= $sep . " MATCH(`news_title`,`news_text`) AGAINST('" . mysql_escape_string($q[$i]) . "*' IN BOOLEAN MODE) ";
$part_of_blog .= $sep . " MATCH(`blog_title`,`blog_text`) AGAINST('" . mysql_escape_string($q[$i]) . "*' IN BOOLEAN MODE) ";
$part_of_file .= $sep . " MATCH(`downs_title`,`downs_text`) AGAINST('" . mysql_escape_string($q[$i]) . "*' IN BOOLEAN MODE) ";
$part_of_file .= "AND `downs_cats_id` <> ''";
$part_of_forum .= $sep . " `posts_text` LIKE '%" . mysql_escape_string($q[$i]) . "%' ";
$part_of_photo .= $sep . " MATCH(`photo_title`,`photo_text`) AGAINST('" . mysql_escape_string($q[$i]) . "*' IN BOOLEAN MODE) ";
$part_of_comm .= $sep . " MATCH(`comm_name`,`comm_about`) AGAINST('" . mysql_escape_string($q[$i]) . "*' IN BOOLEAN MODE) ";
}
$rows = $db->select("SELECT COUNT(1) AS `news`,
(SELECT COUNT(1) FROM ?_blog_posts WHERE " . $part_of_blog . ") AS `blog`,
(SELECT COUNT(1) FROM ?_downs WHERE " . $part_of_file . ") AS `file`,
(SELECT COUNT(1) FROM ?_forums_posts WHERE " . $part_of_forum . ") AS `forum`,
(SELECT COUNT(1) FROM ?_users_photos WHERE " . $part_of_photo . ") AS `photo`,
(SELECT COUNT(1) FROM ?_comm_comm WHERE " . $part_of_comm . ") AS `comm`
FROM ?_news
WHERE " . $part_of_news);
if (!empty($rows)) {
show_header('Результаты поиска ' . $query . ' по сайту');
$show = $value = array();
$show['news'] = '<a href="' . $config['site_url'] . '/news/' . gen_uri('search', '', 'q=' . request('q')) . '">Новости</a>';
$show['blog'] = '<a href="' . $config['site_url'] . '/blog/' . gen_uri('search', '', 'q=' . request('q')) . '">Блоги</a>';
$show['file'] = '<a href="' . $config['site_url'] . '/load/' . gen_uri('search', '', 'q=' . request('q')) . '">Файлы</a>';
$show['forum'] = '<a href="' . $config['site_url'] . '/forum/' . gen_uri('search', '', 'q=' . request('q')) . '">Форум</a>';
$show['photo'] = '<a href="' . $config['site_url'] . '/gallery/' . gen_uri('search', '', 'q=' . request('q')) . '">Галерея</a>';
$show['comm'] = '<a href="' . $config['site_url'] . '/comm/' . gen_uri('search', '', 'q=' . request('q')) . '">Сообщества</a>';
foreach($show as $key => $val) {
$cnt = !empty($rows[0][$key]) ? num($rows[0][$key]) : 0;
if ($cnt > 0) {
$value[] = icon('site.png') . $val . ' (' . $cnt . ')<br />';
}
}
if (!empty($value) && count($value) > 0) echo '<div class="b">' . implode('', $value) . '</div>';
else show_error('К сожалению, по Вашему запросу ничего не найдено!');
}
else {
show_header('Результаты поиска ' . $query . ' по сайту');
show_error('К сожалению, по Вашему запросу ничего не найдено!');
}
}
}
else {
show_header('Поиск по сайту');
}
$form = new cmsForm(gen_uri('search', '', RND), 'post');
$form->addText('Ваш запрос:', 'q', request('q'));
echo $form->Submit('Искать');
unset($form);
}
else {
show_header('Поиск по сайту');
show_login('Вы не авторизованы, чтобы пользоваться поиском по сайту, необходимо');
}
?>