View file down/search.php

File size: 11.16Kb
<?php
require_once"../template/start.php";
require_once"../template/regglobals.php";
require_once"../template/config.php";
require_once"../template/functions.php";
require_once"../template/antidos.php";
require_once"../template/cookies.php";
require_once"../template/gzip.php";
require_once"../template/header.php";
require_once"../template/referer.php";
include_once"../themes/$config_themes/index.php";
include_once"../template/isset.php";


$minfindme=3; // Минимальное кол-во символов в слове для поиска
$maxfindme=25; // Максимальное кол-во символов в слове для поиска
$config_searchdown=10;	//Файлов на страницу
	
echo '<img src="../images/img/bsearch.gif" alt="">  <b>Поиск</b><br><br>';

if(!isset($action)){	
	
if($config_themes!="wml"){	
echo '<form action="search.php?action=search&amp;'.SID.'" method="post">';
echo '<b>Запрос:</b><br><input type="text" name="findme" /><br>';
echo '<br><b>Искать:</b><br>';
echo '<input name="ftype" type="radio" value="2" checked> В описании<br>';
echo '<input name="ftype" type="radio" value="1"> В названии<br>';
echo '<br><b>Тип запроса:</b><br>';
echo '<input name="tip" type="radio" value="1" checked> Или<br>';
echo '<input name="tip" type="radio" value="2"> И<br>';
echo '<br><input type="submit" value="Поиск" /></form><hr>';

}else{
	
echo '<br>Запрос:<br>';
echo '<input name="findme" /><br>';
echo '<br>Искать: <br><select name="ftype">';
echo '<option value="2">В описании</option>';
echo '<option value="1">В названии</option></select><br>';
echo '<br>Тип запроса: <br><select name="tip">';
echo '<option value="1">Или</option>';
echo '<option value="2">И</option></select><br>';
echo '<br><anchor>Поиск';
echo '<go href="search.php?action=search&amp;'.SID.'" method="post">';
echo '<postfield name="findme" value="$(findme)"/>';
echo '<postfield name="ftype" value="$(ftype)"/>';
echo '<postfield name="tip" value="$(tip)"/>';
echo '</go></anchor><br>--------------------<br>';	
}
echo '<b>Последние запросы</b><br><br>';
$file = file(BASEDIR."local/datatmp/downsearch.dat");
$file = array_reverse($file);
$countf=count($file); if($countf>5){$countf=5;}
if($countf>0){
for ($i = 0; $i < $countf; $i++){
echo $file[$i].'<br>';}
}else{echo 'Запросов еще не было!<br>';}}


if($action=="search"){
$findme=check(trim($findme));
$findmetol=rus_utf_tolower($findme);
$findmewords=explode(" ",$findmetol);
$wordsitogos=count($findmewords);

$findmeword = array();

for ($wi = 0; $wi < $wordsitogos; $wi++){
if(strlen(utf_to_win($findmewords[$wi]))>=3){$findmeword[]=$findmewords[$wi];}	
}
$wordsitogo=count($findmeword);

if ($findme!= "" && strlen(utf_to_win($findme)) >= $minfindme && strlen(utf_to_win($findme))<$maxfindme) {
	
$dows= file(BASEDIR."local/datatmp/downsearch.dat"); 
$dows=preg_replace ("|[\r\n]+|si","",$dows);
if (!in_array($findme, $dows)) {
	
$fp=fopen(BASEDIR."local/datatmp/downsearch.dat","a+");  
flock ($fp,LOCK_EX);                                                              
fputs($fp,"$findme\r\n");
fflush ($fp);
flock ($fp,LOCK_UN);
fclose($fp);  
chmod ($fp, 0666);
chmod (BASEDIR."local/datatmp/downsearch.dat", 0666);

$file=file(BASEDIR."local/datatmp/downsearch.dat"); 
$i = count($file);
if ($i>6) {
$fp=fopen(BASEDIR."local/datatmp/downsearch.dat","w");
flock ($fp,LOCK_EX);
unset($file[0],$file[1]);
fputs($fp, implode("",$file));
flock ($fp,LOCK_UN);
fclose($fp);
}}
	
$a = array();	
$dir = opendir ("."); 
while ($file = readdir ($dir)) 
{
if(!eregi("[^a-z0-9_-]",$file)) {$a[]=$file;}
}  
closedir ($dir); 

$total = count($a);  



if($ftype==1){	

$pt = array();
$ft = array();
$ftno = array();	

for ($i = 0; $i < $total; $i++){ 
$d=opendir($a[$i]); 
while ($file = readdir ($d)) {
if (( $file != ".") && ($file != "..") && ($file != ".htaccess") && ($file != "index.php") && ($file != "name.dat") && !ereg (".txt$",$file)&& !ereg (".JPG$",$file)&& !ereg (".GIF$",$file)&& !ereg (".PNG$",$file)){
	
$pt[]=$a[$i];
$ft[]=$file;
$ftno[]=strtolower(substr($file,0,strrpos($file,'.')));

}
}
closedir($d); 
}

$totals = count($ft);  
$dres = array();
$dresult = array();
$dresultno = array();

for ($wi = 0; $wi < $wordsitogo; $wi++){
$findmetols=$findmeword[$wi];	

for ($it = 0; $it < $totals; $it++){ 
	

	
if (strstr($ftno[$it],$findmetols)){
	
if (!in_array($ftno[$it],$dresultno)){	

$dres[]=$pt[$it];
$dresult[]=$ft[$it];		
$dresultno[]=$ftno[$it];

}
}
}}

$total=count($dresult);

if($total>0){
echo '<br>Поиск запроса <b>'.$findme.'</b> в названиях<br>';
echo 'Найдено совпадений: <b>'.(int)$total.'</b><br><br>';


$start = (int)$_GET['start'];
if($start < 0 || $start > $total){$start = 0;}
if ($total < $start + $config_searchdown){ $end = $total; }
else {$end = $start + $config_searchdown; }
for ($i = $start; $i < $end; $i++){

$siz= filesize("$dres[$i]/$dresult[$i]");  # размер
$siz=formatsize($siz);
	
echo '<img src="../images/img/files.gif" alt=""> '; 
echo '<b>'.($i+1).'. <a href="down.php?action=alt&amp;did='.$dres[$i].'&amp;fid='.$dresult[$i].'&amp;'.SID.'">'.$dresult[$i].'</a></b> ';
echo '('.$siz.')<br>';
}

echo '<hr>'; 
if ($start != 0) {echo '<a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;start='.($start - $config_searchdown).'&amp;'.SID.'">&lt;-Назад </a> ';}else{echo '&lt;-Назад ';}
echo '|'; 
if ($total > $start + $config_searchdown) {echo ' <a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;start='.($start + $config_searchdown).'&amp;'.SID.'"> Далее-&gt;</a>';}else{echo ' Далее-&gt;';}

if($total>0){

$ba=ceil($total/$config_searchdown);
$ba2=$ba*$config_searchdown-$config_searchdown;

echo '<br><hr>Страницы:';
$asd=$start-($config_searchdown*3);
$asd2=$start+($config_searchdown*4);

if($asd<$total && $asd>0){echo ' <a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;start=0&amp;'.SID.'">1</a> ... ';}

for($i=$asd; $i<$asd2;)
{
if($i<$total && $i>=0){
$ii=floor(1+$i/$config_searchdown);

if ($start==$i) {
echo ' <b>('.$ii.')</b>';
               }
                else {
echo ' <a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;start='.$i.'&amp;'.SID.'">'.$ii.'</a>';
                     }}


$i=$i+$config_searchdown;}
if($asd2<$total){echo ' ... <a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;start='.$ba2.'&amp;'.SID.'">'.$ba.'</a>';}
}
echo '<br><br>';


}else{echo '<br>По вашему запросу ничего не найдено.<br>';}

}


if($ftype==2){	
	
$pt = array();
$ftno = array();
$ftopis = array();

for ($i = 0; $i < $total; $i++){ 
$d=opendir($a[$i]); 
while ($file = readdir ($d)) {
if (ereg(".txt$", "$file")){
	
$pt[]=$a[$i];
$ftno[]=str_replace(".txt","",$file);
$ftopis[]=rus_utf_tolower(file_get_contents("$a[$i]/$file"));


}
}
closedir($d); 
}

$ftopis=str_replace("<br>"," ",$ftopis);

$totals = count($ftno); 


if($tip==1){
$dres = array();
$dresult = array();
$dresultno = array();	
	
for ($wi = 0; $wi < $wordsitogo; $wi++){
$findmetols=$findmeword[$wi];	

for ($it = 0; $it < $totals; $it++){ 
	
$frename=preg_replace("/$findmetols/",'<font color="#FF0000">'.$findmetols.'</font>',$ftopis[$it],1);
$frename=utf_to_win($frename);

$ma=strpos($frename,"<font")-70; if($ma<0){$ma=0;}

if($ma>0){$msgtowrite='...';}else{$msgtowrite='';}
 
 $msgtowrite.=substr($frename,$ma,160); 
  
if(strlen($frename)>($ma+150)){$msgtowrite.='...';}else{$msgtowrite.='';}


 $msgtowrite=win_to_utf($msgtowrite);
 

if (strstr($msgtowrite,$findmetols)){
	
if (!in_array($msgtowrite,$dresultno)){	

$dres[]=$pt[$it];
$dresult[]=$ftno[$it];		
$dresultno[]=$msgtowrite;

}}}}}

if($tip==2){

$dres = array();
$dresult = array();
$dresultno = array();

for ($it = 0; $it < $totals; $it++){ 
	
$frename=preg_replace("/$findmetol/",'<font color="#FF0000">'.$findmetol.'</font>',$ftopis[$it],1);
$frename=utf_to_win($frename);

$ma=strpos($frename,"<font")-70; if($ma<0){$ma=0;}

if($ma>0){$msgtowrite='...';}else{$msgtowrite='';}
 
 $msgtowrite.=substr($frename,$ma,160); 
  
if(strlen($frename)>($ma+150)){$msgtowrite.='...';}else{$msgtowrite.='';}


 $msgtowrite=win_to_utf($msgtowrite);
 

if (strstr($msgtowrite,$findmetol)){
	
if (!in_array($msgtowrite,$dresultno)){	

$dres[]=$pt[$it];
$dresult[]=$ftno[$it];		
$dresultno[]=$msgtowrite;

}}}}


$total=count($dresultno);
 
 //------------------------------ Вывод найденного ----------------------------------//
if($total>0){
echo '<br>Поиск запроса <b>'.$findme.'</b> в описании<br>';
echo 'Найдено совпадений: <b>'.(int)$total.'</b><br><br>';


$start = (int)$_GET['start'];
if($start < 0 || $start > $total){$start = 0;}
if ($total < $start + $config_searchdown){ $end = $total; }
else {$end = $start + $config_searchdown; }
for ($i = $start; $i < $end; $i++){


	
echo '<div class=b><img src="../images/img/files.gif" alt=""> '; 
echo '<b>'.($i+1).'. <a href="down.php?action=alt&amp;did='.$dres[$i].'&amp;fid='.$dresult[$i].'&amp;'.SID.'">'.$dresult[$i].'</a></b></div>';
echo $dresultno[$i].'<br>';
}

echo '<hr>'; 
if ($start != 0) {echo '<a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;tip='.$tip.'&amp;start='.($start - $config_searchdown).'&amp;'.SID.'">&lt;-Назад </a> ';}else{echo '&lt;-Назад ';}
echo '|'; 
if ($total > $start + $config_searchdown) {echo ' <a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;tip='.$tip.'&amp;start='.($start + $config_searchdown).'&amp;'.SID.'"> Далее-&gt;</a>';}else{echo ' Далее-&gt;';}

if($total>0){

$ba=ceil($total/$config_searchdown);
$ba2=$ba*$config_searchdown-$config_searchdown;

echo '<br><hr>Страницы:';
$asd=$start-($config_searchdown*3);
$asd2=$start+($config_searchdown*4);

if($asd<$total && $asd>0){echo ' <a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;tip='.$tip.'&amp;start=0&amp;'.SID.'">1</a> ... ';}

for($i=$asd; $i<$asd2;)
{
if($i<$total && $i>=0){
$ii=floor(1+$i/$config_searchdown);

if ($start==$i) {
echo ' <b>('.$ii.')</b>';
               }
                else {
echo ' <a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;tip='.$tip.'&amp;start='.$i.'&amp;'.SID.'">'.$ii.'</a>';
                     }}


$i=$i+$config_searchdown;}
if($asd2<$total){echo ' ... <a href="search.php?action=search&amp;findme='.$findme.'&amp;ftype='.$ftype.'&amp;tip='.$tip.'&amp;start='.$ba2.'&amp;'.SID.'">'.$ba.'</a>';}
}
echo '<br><br>';



}else{echo '<br>По вашему запросу ничего не найдено.<br>';}
 
 
}


}else{echo '<br>Ваш запрос пуст, менее '.(int)$minfindme.' или более '.(int)$maxfindme.' символов!<br>'; }
echo '<br><img src="../images/img/back.gif" alt=""> <a href="search.php?'.SID.'">Вернуться</a>'; 
}



echo '<br><img src="../images/img/panel.gif" alt=""> <a href="index.php?'.SID.'">В загрузки</a>'; 
echo '<br><img src="../images/img/homepage.gif" alt=""> <a href="../index.php?'.SID.'">На главную</a>'; 
include_once"../themes/$config_themes/foot.php";
?>