вопрос
Привет Друзья!
У меня к вам вопрос как сделать поиск только по статьям и убрать расширенный поиск?
Что отсюда лишнее нужно вырезать?
У меня к вам вопрос как сделать поиск только по статьям и убрать расширенный поиск?
Что отсюда лишнее нужно вырезать?
<?php
/*
=====================================================
DataLife Engine - by SoftNews Media Group
-----------------------------------------------------
http://dle-news.ru/
-----------------------------------------------------
Copyright (c) 2004,2013 SoftNews Media Group
=====================================================
Данный код защищен авторскими правами
=====================================================
Файл: search.php
-----------------------------------------------------
Назначение: поиск по сайту
=====================================================
*/
if( ! defined( 'DATALIFEENGINE' ) ) {
die( "Hacking attempt!" );
}
if( ! $user_group[$member_id['user_group']]['allow_search'] ) {
$lang['search_denied'] = str_replace( '{group}', $user_group[$member_id['user_group']]['group_name'], $lang['search_denied'] );
msgbox( $lang['all_info'], $lang['search_denied'] );
} else {
function strip_data($text) {
$quotes = array ( "\x60", "\t", "\n", "\r", ",", ";", ":", "[", "]", "{", "}", "=", "*", "^", "%", "$", "<", ">" );
$goodquotes = array ("#", "'", '"' );
$repquotes = array ("\#", "\'", '\"' );
$text = stripslashes( $text );
$text = trim( strip_tags( $text ) );
$text = str_replace( $quotes, '', $text );
$text = str_replace( $goodquotes, $repquotes, $text );
return $text;
}
$count_result = 0;
$sql_count = "";
$sql_find = "";
// Минимальное количество символов в слове поиска
$config['search_length_min'] = 4;
$tpl->load_template( 'search.tpl' );
$config['search_number'] = intval($config['search_number']);
if ( $config['search_number'] < 1) $config['search_number'] = 1;
$this_date = date( "Y-m-d H:i:s", $_TIME );
if( $config['no_date'] AND !$config['news_future'] ) $this_date = " AND " . PREFIX . "_post.date < '" . $this_date . "'"; else $this_date = "";
if( isset( $_REQUEST['story'] ) ) $story = dle_substr( strip_data( rawurldecode( $_REQUEST['story'] ) ), 0, 90, $config['charset'] ); else $story = "";
if( isset( $_REQUEST['search_start'] ) ) $search_start = intval( $_REQUEST['search_start'] ); else $search_start = 0;
if( isset( $_REQUEST['titleonly'] ) ) $titleonly = intval( $_REQUEST['titleonly'] ); else $titleonly = 0;
if( isset( $_REQUEST['searchuser'] ) ) $searchuser = dle_substr( $_REQUEST['searchuser'], 0, 40, $config['charset'] ); else $searchuser = "";
if( isset( $_REQUEST['exactname'] ) ) $exactname = $_REQUEST['exactname']; else $exactname = "";
if( isset( $_REQUEST['all_word_seach'] ) ) $all_word_seach = intval($_REQUEST['all_word_seach']); else $all_word_seach = 0;
if( isset( $_REQUEST['replyless'] ) ) $replyless = intval( $_REQUEST['replyless'] ); else $replyless = 0;
if( isset( $_REQUEST['replylimit'] ) ) $replylimit = intval( $_REQUEST['replylimit'] ); else $replylimit = 0;
if( isset( $_REQUEST['searchdate'] ) ) $searchdate = intval( $_REQUEST['searchdate'] ); else $searchdate = 0;
if( isset( $_REQUEST['beforeafter'] ) ) $beforeafter = htmlspecialchars( $_REQUEST['beforeafter'], ENT_QUOTES, $config['charset'] ); else $beforeafter = "after";
if( preg_match( "/[\||\'|\<|\>|\"|\!|\?|\$|\@|\/|\\\|\&\~\*\+]/", $searchuser ) ) $searchuser="";
if ($config['full_search']) {
if( isset( $_REQUEST['sortby'] ) ) $sortby = htmlspecialchars( $_REQUEST['sortby'], ENT_QUOTES, $config['charset'] ); else $sortby = "";
} else {
if( isset( $_REQUEST['sortby'] ) ) $sortby = htmlspecialchars( $_REQUEST['sortby'], ENT_QUOTES, $config['charset'] ); else $sortby = "date";
}
if( isset( $_REQUEST['resorder'] ) ) $resorder = htmlspecialchars( $_REQUEST['resorder'], ENT_QUOTES, $config['charset'] ); else $resorder = "desc";
if( isset( $_REQUEST['showposts'] ) ) $showposts = intval( $_REQUEST['showposts'] ); else $showposts = 0;
if( isset( $_REQUEST['result_from'] ) ) $result_from = intval( $_REQUEST['result_from'] ); else $result_from = 1; // Показать страницу с результатом № ХХХ
$full_search = intval( $_REQUEST['full_search'] );
if( !count( $_REQUEST['catlist'] ) ) {
$catlist = array ();
$catlist[] = '0';
} else
$catlist = $_REQUEST['catlist'];
$category_list = array();
foreach ( $catlist as $value ) {
$category_list[] = intval($value);
}
$category_list = $db->safesql( implode( ',', $category_list ) );
if( function_exists( "get_magic_quotes_gpc" ) && get_magic_quotes_gpc() ) $story = stripslashes( $story );
$findstory = stripslashes($story); // Для вывода в поле поиска
$findstory = htmlspecialchars($findstory, ENT_QUOTES, $config['charset']);
$story = addslashes( $story );
if ($titleonly == 2 AND !empty( $searchuser ) ) $searchuser = "";
if( empty( $story ) AND !empty( $searchuser ) AND $titleonly != 2) $story = "___SEARCH___ALL___"; // Для поиска всех статей
if( $search_start < 0 ) $search_start = 0; // Начальная страница поиска
if( $titleonly < 0 or $titleonly > 3 ) $titleonly = 0; // Искать в заголовках, статьях, комментариях
if( $replyless < 0 or $replyless > 1 ) $replyless = 0; // Искать больше или меньше ответов
if( $replylimit < 0 ) $replylimit = 0; // Лимит ответов
if( $showposts < 0 or $showposts > 1 ) $showposts = 0; // Искать в статьях или комментариях юзера
$listdate = array (0, - 1, 1, 7, 14, 30, 90, 180, 365 ); // Искать за период ХХХ дней
if( ! (in_array( $searchdate, $listdate )) ) $searchdate = 0;
if( $beforeafter != "after" and $beforeafter != "before" ) $beforeafter = "after"; // Искать до или после периода дней
$listsortby = array ("date", "title", "comm_num", "news_read", "autor", "category", "rating" );
if ($config['full_search']) {
if( ! (in_array( $sortby, $listsortby )) ) $sortby = ""; // Сортировать по полям
} else {
if( ! (in_array( $sortby, $listsortby )) ) $sortby = "date"; // Сортировать по полям
}
$listresorder = array ("desc", "asc" );
if( ! (in_array( $resorder, $listresorder )) ) $resorder = "desc"; // Сортировать по возрастающей или убывающей
// Определение выбранных ранее опций, переданных в форме
$titleonly_sel = array ('0' => '', '1' => '', '2' => '', '3' => '' );
$titleonly_sel[$titleonly] = 'selected="selected"';
$replyless_sel = array ('0' => '', '1' => '' );
$replyless_sel[$replyless] = 'selected="selected"';
$searchdate_sel = array ('0' => '', '-1' => '', '1' => '', '7' => '', '14' => '', '30' => '', '90' => '', '180' => '', '365' => '' );
$searchdate_sel[$searchdate] = 'selected="selected"';
$beforeafter_sel = array ('after' => '', 'before' => '' );
$beforeafter_sel[$beforeafter] = 'selected="selected"';
$sortby_sel = array ('date' => '', 'title' => '', 'comm_num' => '', 'news_read' => '', 'autor' => '', 'category' => '', 'rating' => '' );
$sortby_sel[$sortby] = 'selected="selected"';
$resorder_sel = array ('desc' => '', 'asc' => '' );
$resorder_sel[$resorder] = 'selected="selected"';
$showposts_sel = array ('0' => '', '1' => '' );
$showposts_sel[$showposts] = 'checked="checked"';
if( $exactname == "yes" ) $exactname_sel = 'checked="checked"';
else $exactname_sel = '';
if( $all_word_seach == 1 ) $all_word_seach_sel = 'checked="checked"';
else $all_word_seach_sel = '';
// Вывод формы поиска
if( $category_list == "" or $category_list == "0" ) {
$catselall = "selected=\"selected\"";
} else {
$catselall = "";
$category_list = preg_replace( "/^0\,/", '', $category_list );
}
// Определение и вывод доступных категорий
$cats = "<select style=\"width:95%;height:200px;\" name=\"catlist[]\" size=\"13\" multiple=\"multiple\">";
$cats .= "<option " . $catselall . " value=\"0\">" . $lang['s_allcat'] . "</option>";
$cats .= CategoryNewsSelection( explode( ',', $category_list ), 0, false );
$cats .= "</select>";
$tpl->copy_template .= <<<HTML
<script type="text/javascript">
<!-- begin
function clearform(frmname){
var frm = document.getElementById(frmname);
for (var i=0;i<frm.length;i++) {
var el=frm.elements[i];
if (el.type=="checkbox" || el.type=="radio") {
if (el.name=='showposts') {document.getElementById('rb_showposts_0').checked=1; } else {el.checked=0; }
}
if ((el.type=="text") || (el.type=="textarea") || (el.type == "password")) { el.value=""; continue; }
if ((el.type=="select-one") || (el.type=="select-multiple")) { el.selectedIndex=0; }
}
document.getElementById('replylimit').value = 0;
document.getElementById('search_start').value = 0;
document.getElementById('result_from').value = 1;
}
function list_submit(prm){
var frm = document.getElementById('fullsearch');
if (prm == -1) {
prm=Math.ceil(frm.result_from.value / {$config['search_number']});
} else {
frm.result_from.value=(prm-1) * {$config['search_number']} + 1;
}
frm.search_start.value=prm;
frm.submit();
return false;
}
function full_submit(prm){
document.getElementById('fullsearch').full_search.value=prm;
list_submit(-1);
}
function reg_keys(key) {
var code;
if (!key) var key = window.event;
if (key.keyCode) code = key.keyCode;
else if (key.which) code = key.which;
if (code == 13) {
list_submit(-1);
}
};
document.onkeydown = reg_keys;
// end -->
</script>
HTML;
$searchtable = <<<HTML
<form name="fullsearch" id="fullsearch" action="{$config['http_home_url']}index.php?do=search" method="post">
<input type="hidden" name="do" id="do" value="search" />
<input type="hidden" name="subaction" id="subaction" value="search" />
<input type="hidden" name="search_start" id="search_start" value="$search_start" />
<input type="hidden" name="full_search" id="full_search" value="$full_search" />
<input type="hidden" name="result_from" id="result_from" value="$result_from" />
HTML;
if( $full_search ) {
if ($config['full_search']) {
$full_search_option = "<option value=\"\" selected=\"selected\">{$lang['s_fsrelate']}</option><option {$sortby_sel['date']} value=\"date\">{$lang['s_fsdate']}</option>";
$all_word_option = "";
} else {
$full_search_option = "<option {$sortby_sel['date']} value=\"date\">{$lang['s_fsdate']}</option>";
$all_word_option = "<div><label for=\"all_word_seach\"><input type=\"checkbox\" name=\"all_word_seach\" value=\"1\" id=\"all_word_seach\" {$all_word_seach_sel} />{$lang['s_fword']}</label></div>";
}
$searchtable .= <<<HTML
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td class="search">
<div align="center">
<table cellpadding="0" cellspacing="2" width="100%">
<tr style="vertical-align: top;">
<td class="search">
<fieldset style="margin:0px">
<legend>{$lang['s_con']}</legend>
<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td class="search">
<div>{$lang['s_word']}</div>
<div><input type="text" name="story" id="searchinput" value="$findstory" class="textin" style="width:250px" onchange="document.getElementById('result_from').value = 1" /></div>
{$all_word_option}
</td>
</tr>
<tr>
<td class="search">
<select class="textin" name="titleonly" id="titleonly">
<option {$titleonly_sel['0']} value="0">{$lang['s_ncom']}</option>
<option {$titleonly_sel['1']} value="1">{$lang['s_ncom1']}</option>
<option {$titleonly_sel['2']} value="2">{$lang['s_static']}</option>
<option {$titleonly_sel['3']} value="3">{$lang['s_tnews']}</option>
</select>
</td>
</tr>
</table>
</fieldset>
</td>
<td class="search" valign="top">
<fieldset style="margin:0px">
<legend>{$lang['s_mname']}</legend>
<table cellpadding="0" cellspacing="3" border="0">
<tr>
<td class="search">
<div>{$lang['s_fname']}</div>
<div id="userfield"><input type="text" name="searchuser" id="searchuser" value="$searchuser" class="textin" style="width:250px" /><br /><label for="exactname"><input type="checkbox" name="exactname" value="yes" id="exactname" {$exactname_sel} />{$lang['s_fgname']}</label>
</div>
</td>
</tr>
</table>
</fieldset>
</td>
</tr>
<tr style="vertical-align: top;">
<td width="50%" class="search">
<fieldset style="margin:0px">
<legend>{$lang['s_fart']}</legend>
<div style="padding:3px">
<select class="textin" name="replyless" id="replyless" style="width:200px">
<option {$replyless_sel['0']} value="0">{$lang['s_fmin']}</option>
<option {$replyless_sel['1']} value="1">{$lang['s_fmax']}</option>
</select>
<input type="text" name="replylimit" id="replylimit" size="5" value="$replylimit" class="textin" /> {$lang['s_wcomm']}
</div>
</fieldset>
<fieldset style="padding-top:10px">
<legend>{$lang['s_fdaten']}</legend>
<div style="padding:3px">
<select name="searchdate" id="searchdate" class="textin" style="width:200px">
<option {$searchdate_sel['0']} value="0">{$lang['s_tall']}</option>
<option {$searchdate_sel['-1']} value="-1">{$lang['s_tlast']}</option>
<option {$searchdate_sel['1']} value="1">{$lang['s_tday']}</option>
<option {$searchdate_sel['7']} value="7">{$lang['s_tweek']}</option>
<option {$searchdate_sel['14']} value="14">{$lang['s_ttweek']}</option>
<option {$searchdate_sel['30']} value="30">{$lang['s_tmoth']}</option>
<option {$searchdate_sel['90']} value="90">{$lang['s_tfmoth']}</option>
<option {$searchdate_sel['180']} value="180">{$lang['s_tsmoth']}</option>
<option {$searchdate_sel['365']} value="365">{$lang['s_tyear']}</option>
</select>
<select name="beforeafter" id="beforeafter" class="textin">
<option {$beforeafter_sel['after']} value="after">{$lang['s_fnew']}</option>
<option {$beforeafter_sel['before']} value="before">{$lang['s_falt']}</option>
</select>
</div>
</fieldset>
<fieldset style="padding-top:10px">
<legend>{$lang['s_fsoft']}</legend>
<div style="padding:3px">
<select name="sortby" id="sortby" class="textin" style="width:200px">
{$full_search_option}
<option {$sortby_sel['title']} value="title" >{$lang['s_fstitle']}</option>
<option {$sortby_sel['comm_num']} value="comm_num" >{$lang['s_fscnum']}</option>
<option {$sortby_sel['news_read']} value="news_read" >{$lang['s_fsnnum']}</option>
<option {$sortby_sel['autor']} value="autor" >{$lang['s_fsaut']}</option>
<option {$sortby_sel['category']} value="category" >{$lang['s_fscat']}</option>
<option {$sortby_sel['rating']} value="rating" >{$lang['s_fsrate']}</option>
</select>
<select name="resorder" id="resorder" class="textin">
<option {$resorder_sel['desc']} value="desc">{$lang['s_fsdesc']}</option>
<option {$resorder_sel['asc']} value="asc">{$lang['s_fsasc']}</option>
</select>
</div>
</fieldset>
<fieldset style="padding-top:10px">
<legend>{$lang['s_vlegend']}</legend>
<table cellpadding="0" cellspacing="3" border="0">
<tr align="left" valign="middle">
<td align="left" class="search">{$lang['s_vwie']}
<label for="rb_showposts_0"><input type="radio" name="showposts" value="0" id="rb_showposts_0" {$showposts_sel['0']} />{$lang['s_vnews']}</label>
<label for="rb_showposts_1"><input type="radio" name="showposts" value="1" id="rb_showposts_1" {$showposts_sel['1']} />{$lang['s_vtitle']}</label>
</td>
</tr>
</table>
</fieldset>
</td>
<td width="50%" class="search" valign="top">
<fieldset style="margin:0px">
<legend>{$lang['s_fcats']}</legend>
<div style="padding:3px">
<div>$cats</div>
</div>
</fieldset>
</td>
</tr>
<tr>
<td class="search" colspan="2">
<div style="margin-top:6px">
<input type="button" class="bbcodes" style="margin:0px 20px 0 0px;" name="dosearch" id="dosearch" value="{$lang['s_fstart']}" onclick="javascript:list_submit(-1); return false;" />
<input type="button" class="bbcodes" style="margin:0px 20px 0 20px;" name="doclear" id="doclear" value="{$lang['s_fstop']}" onclick="javascript:clearform('fullsearch'); return false;" />
<input type="reset" class="bbcodes" style="margin:0px 20px 0 20px;" name="doreset" id="doreset" value="{$lang['s_freset']}" />
</div>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
HTML;
} else {
if ( $smartphone_detected ) {
$link_full_search = "";
} else {
$link_full_search = "<input type=\"button\" class=\"bbcodes\" name=\"dofullsearch\" id=\"dofullsearch\" value=\"{$lang['s_ffullstart']}\" onclick=\"javascript:full_submit(1); return false;\" />";
}
$searchtable .= <<<HTML
<table cellpadding="2" cellspacing="0">
<tr>
<td class="search">
<input type="text" name="story" id="searchinput" value="$findstory" class="textin" style="width:250px" onchange="document.getElementById('result_from').value = 1" />
<input type="button" class="bbcodes" name="dosearch" id="dosearch" value="{$lang['s_fstart']}" onclick="javascript:list_submit(-1); return false;" />
</td>
</tr>
</table>
HTML;
}
$searchtable .= <<<HTML
</form>
HTML;
$tpl->set( '{searchtable}', $searchtable );
// По умолчанию, выводится только форма поиска
if( $subaction != "search" ) {
$tpl->set_block( "'\[searchmsg\](.*?)\[/searchmsg\]'si", "" );
$tpl->compile( 'content' );
}
// Конец вывода формы поиска
if( $subaction == "search" ) {
// Вывод результатов поиска
if ($config['full_search']) {
$arr = explode( ' ', $story );
$story_maxlen = 0;
$story = array ();
foreach ( $arr as $word ) {
$wordlen = dle_strlen( trim( $word ), $config['charset'] );
if( $wordlen >= $config['search_length_min'] ) $story[] = $word;
if( $wordlen > $story_maxlen ) {
$story_maxlen = $wordlen;
}
}
$story = implode( " ", $story );
} else {
if ( !$all_word_seach ) $story = preg_replace( "#(\s+|__OR__)#i", '%', $story );
$story_maxlen = dle_strlen( trim( $story ), $config['charset'] );
}
if( (empty( $story ) or ($story_maxlen < $config['search_length_min'])) and (empty( $searchuser ) or (strlen( $searchuser ) < $config['search_length_min'])) ) {
msgbox( $lang['all_info'], $lang['search_err_3'] );
$tpl->set( '{searchmsg}', '' );
$tpl->set_block( "'\[searchmsg\](.*?)\[/searchmsg\]'si", "" );
$tpl->compile( 'content' );
} else {
// Начало подготовки поиска
if( $search_start ) {
$search_start = $search_start - 1;
$search_start = $search_start * $config['search_number'];
}
// Проверка разрешенных категорий из списка выбранных категорий
$allow_cats = $user_group[$member_id['user_group']]['allow_cats'];
$allow_list = explode( ',', $allow_cats );
$stop_list = "";
if( $allow_list[0] == "all" ) {
// Все категории доступны для группы
if( $category_list == "" or $category_list == "0" ) {
// Выбран поиск по всем категориям
;
} else {
// Выбран поиск по некоторым категориям
$stop_list = str_replace( ',', '|', $category_list );
}
} else {
// Не все категории доступны для группы
if( $category_list == "" or $category_list == "0" ) {
// Выбран поиск по всем категориям
$stop_list = str_replace( ',', '|', $allow_cats );
} else {
// Выбран поиск по некоторым категориям
$cats_list = explode( ',', $category_list );
foreach ( $cats_list as $id ) {
if( in_array( $id, $allow_list ) ) $stop_list .= $id . '|';
}
$stop_list = substr( $stop_list, 0, strlen( $stop_list ) - 1 );
}
}
// Ограничение по категориям
$where_category = "";
if( ! empty( $stop_list ) ) {
if( $config['allow_multi_category'] ) {
$where_category = "category regexp '[[:<:]](" . $stop_list . ")[[:>:]]'";
} else {
$stop_list = str_replace( "|", "','", $stop_list );
$where_category = "category IN ('" . $stop_list . "')";
}
}
if( $story == "___SEARCH___ALL___" ) $story = '';
$thistime = date( "Y-m-d H:i:s", (time() + $config['date_adjust'] * 60) );
if( $exactname == 'yes' ) $likename = '';
else $likename = '%';
if( $searchdate != '0' ) {
if( $searchdate != '-1' ) {
$qdate = date( "Y-m-d H:i:s", (time() + $config['date_adjust'] * 60 - $searchd