ANTICHAT Forum
HOME FORUMS MEMBERS RECENT POSTS LOG IN  
Баннер 1   Баннер 2
НОВЫЕ ТОРГОВАЯ НОВОСТИ
loading...
Скрыть
Вернуться   ANTICHAT > ПРОГРАММИРОВАНИЕ > PHP
   
Ответ
 
Опции темы Поиск в этой теме Опции просмотра

Помогите со скриптом!
  #1  
Старый 27.08.2008, 13:22
~NeiTRoN~
Познающий
Регистрация: 03.07.2008
Сообщений: 65
С нами: 9397381

Репутация: 4
По умолчанию Помогите со скриптом!

Хай народ. Имеется вот такой скрипт поиска
PHP код:
<?
 
require ("config.php");
require (
"language/".$languagefile);

$time=explode(' ', microtime());
$start_time=$time[1]+$time[0];

// This function returns:
//
// 0=unauthorized access to this file
// 1=not parsable file
// 2=parsable file

// Функция возвращает:
//
// 0=неавторизированный доступ к файлу
// 1=в файле нельзя вести поиск
// 2=файл годится для поиска
function IsAllowed($f)
{
  global 
$allowed_names, $disallowed_names;
  for (
$i=0; $i<count($disallowed_names); ++$i)
    if (
stristr(realpath($f), $disallowed_names[$i])) return 0;
  for (
$i=0; $i<count($allowed_names); ++$i)
    if (
stristr(realpath($f), $allowed_names[$i])) return 2;
  return 
1;
}

// Does buffer matches the query ?
// Проверка буфера на совпадение с запросом
function FindQuery($buffer)
{
  global 
$query, $m;
  
$t=explode(" ", $_POST[query]);
   if (
$_POST[m]=="or")
   {
     for (
$j=0; $j<count($t); ++$j)
     {
       if (
stristr($buffer, $t[$j])) return 1;
       
$key=htmlentities($t[$j]);
       if (
$key!=$t[$j])
       {
         if (
stristr($buffer, $key)) return 1;
       }
     }
     return 
0;
   } else
   {
     for (
$j=0; $j<count($t); ++$j)
       if (!
stristr($buffer, $t[$j]))
       {
         
$key=htmlentities($t[$j]);
         if (
$key!=$t[$j])
         {
           if (!
stristr($buffer, $key)) return 0;
         } else
         {
           return 
0;
         }
       }
     return 
1;
   }
}

// First pass: we build a list of all files matching the criterions
// Первый проход: мы строим список всех файлов, удволетворяющих условиям
function countdirs($dirname)
{
  global 
$filesearch;
  
$dir=opendir(".");
  while((
$f=readdir($dir))!==false)
  {
    if (
is_dir($f))
    {
      if ((
$f!=".") && ($f!=".."))
      {
        if (
IsAllowed($f))
        {
          
chdir($f);
          
countdirs($dirname."/".$f);
          
chdir("..");
        }
      }
    } else
    {
      
$n=IsAllowed($f);
      if (
$n)
      {
        
// Does the filename matches the query ?
        // Имя файла совпадает с запросом ?
        
if (FindQuery($f))
        {
          
$filesearch[] = $dirname.'/'.$f;
        } else
        if (
$n==2)
        {
          
// Does the content matches the query ?
          // Содержимое совпадает с запросом ?
          
$fd=fopen($f,"r");
          
$buffer=fread($fd, filesize($f));
          
fclose($fd);
          if (
FindQuery($buffer))
          {
            
$filesearch[] = $dirname.'/'.$f;
          }
        }
      }
    }
  }
  
closedir($dir);
}

// Second pass: we render the file
// Второй проход: обрабатываем файл
function Render($dirname, $filenumber)
{
  global 
$rootdir, $query, $m, $from, $showed, $pages, $color1, $color2, $explodestring, $maxoccurrences, $desc_header, $desc_footer, $lang_bytes, $interface_all;
  
$f=$rootdir.$dirname;
  ++
$showed;
  if (
$showed&1)
    echo 
"<tr><td bgcolor=$color2>";
  else
    echo 
"<tr><td bgcolor=$color1>";
  echo 
str_replace("%1", $filenumber, $interface_all);
  echo 
"<a href=\"$dirname\">$dirname</a> ";
  echo 
filesize($f)." $lang_bytes, ".date("d M Y", filectime($f)).". ";

  if (
IsAllowed($dirname)==2)
  {
    
$fc=file($f);
    
$filet=join("", $fc);
    if (
preg_match("/<title.*>(.*)<\/title.*>/isU", $filet, $match))
    {
      
// display the title
      // показать заголовок
      
echo trim($match[1]);
    }
    
// display the content matches
    // показать содержимое
    
$s=implode($fc, $explodestring);
    
$s=strip_tags($s);
    
$fc=explode($explodestring, $s);
    
$q=explode(" ",$_POST[query]);
    
$occurrence=0;
    echo 
"<br>$desc_header";
    for (
$i=0; $i<count($fc); ++$i)
    {
      
$occ=0;
      
$s=strtolower(strip_tags($fc[$i]));
      for (
$j=0; $j<count($q); ++$j)
      {
        if (
stristr($s, $q[$j]))
        {
          
$s=str_replace($q[$j], "<b>$q[$j]</b>", $s);
          
$occ=1;
        }
        else
        {
          
$key=htmlentities($q[$j]);
          if (
stristr($s, $key))
          {
            
$s=str_replace($key, "<b>$key</b>", $s);
            
$occ=1;
          }
        }
      }
      if (
$occ)
      {
        
$occ=0;
        echo 
"...$s...";
        ++
$occurrence;
        if (
$occurrence > $maxoccurrences) break;
      }
    }
    echo 
$desc_footer;
  }
  echo 
"</td></tr>\n";
}

// Display navigation bar
// Вывести панель навигации
function DisplayNavbar($all)
{
  global 
$PHP_SELF;
  global 
$color0, $pages, $query, $m, $search_separator;
  echo 
"<tr bgcolor=$color0><td align=center>";
  for (
$k=1; $k<=$all; $k+=$pages)
  {
    if (
$k!=1) echo $search_separator;
    echo 
"<a href=$PHP_SELF?query=".urlencode($_POST[query])."&m=$_POST[m]&from=$k>$k-";
    if (
$k+$pages>$all) echo $all; else echo ($k-1+$pages);
    echo 
"</a>";
  }
  echo 
"</td></tr>\n";
}

// ****************************> MAIN CODE <*********************************
if (!isset($from)) $from=1;
if (!isset(
$_POST[query])) $_POST[query]="";
$_POST[query]=strtolower(trim(strip_tags($_POST[query])));

place_header();

if (
$_POST[query]!="")
{
  
$rootdir=$DOCUMENT_ROOT;
  unset(
$filesearch);
  
countdirs($start_search);
  
$time=explode(' ', microtime());
  
$seconds=($time[1]+$time[0]-$start_time);
  
$all=count($filesearch);
  if (
$all>0)
  {
    echo 
"<center>".str_replace("%2", sprintf("%01.3f", $seconds), str_replace("%1", $all, $lang_wasfound))."<br></center>\n";
    echo 
"<table width=95% cellspacing=0 cellpadding=1>\n";
    
$showed=0;
    
DisplayNavbar($all);
    for(
$i=$from;$i < $from+$pages;++$i)
    {
      if (
$i >= $all+1) break;
      
Render($filesearch[$i-1], $i);
    }
    
DisplayNavbar($all);
    echo 
"</table>\n";
  }
  else
  {
    echo 
"<center>".str_replace("%1", sprintf("%01.3f", $seconds), $lang_nofiles)."</center>";
  }
}
$time=explode(' ',microtime());
$seconds=($time[1]+$time[0]-$start_time);
echo 
"<p align=right><small>".str_replace("%1", sprintf("%01.3f", $seconds), $lang_generated)."</small></p>";
place_footer();
?>
Он выводит ссылки на файлы в которых найдены запрашивамые данные ввиде ссылки этого фала, тоесть если текст найден в hot.php? то он выведет ссылку на этот файл таким образом: катало/hot.php. А теперь суть вопроса, как можно сделать так, чтобы он забирал текст между <title></title> и имя ссылки было то что между тетл файла в котором нашлась искомаю комбинация???
 
Ответить с цитированием

  #2  
Старый 27.08.2008, 13:50
Doom123
Постоянный
Регистрация: 11.11.2006
Сообщений: 834
С нами: 10262314

Репутация: 668


По умолчанию

PHP код:
<? 
  
require ("config.php"); 
require (
"language/".$languagefile); 

$time=explode(' ', microtime()); 
$start_time=$time[1]+$time[0]; 
$title = array();

// This function returns: 
// 
// 0=unauthorized access to this file 
// 1=not parsable file 
// 2=parsable file 

// Функция возвращает: 
// 
// 0=неавторизированный доступ к файлу 
// 1=в файле нельзя вести поиск 
// 2=файл годится для поиска 
function IsAllowed($f) 
{ 
  global 
$allowed_names, $disallowed_names; 
  for (
$i=0; $i<count($disallowed_names); ++$i) 
    if (
stristr(realpath($f), $disallowed_names[$i])) return 0; 
  for (
$i=0; $i<count($allowed_names); ++$i) 
    if (
stristr(realpath($f), $allowed_names[$i])) return 2; 
  return 
1; 
} 

// Does buffer matches the query ? 
// Проверка буфера на совпадение с запросом 
function FindQuery($buffer) 
{ 
  global 
$query, $m; 
  
$t=explode(" ", $_POST[query]); 
   if (
$_POST[m]=="or") 
   { 
     for (
$j=0; $j<count($t); ++$j) 
     { 
       if (
stristr($buffer, $t[$j])) return 1; 
       
$key=htmlentities($t[$j]); 
       if (
$key!=$t[$j]) 
       { 
         if (
stristr($buffer, $key)) return 1; 
       } 
     } 
     return 
0; 
   } else 
   { 
     for (
$j=0; $j<count($t); ++$j) 
       if (!
stristr($buffer, $t[$j])) 
       { 
         
$key=htmlentities($t[$j]); 
         if (
$key!=$t[$j]) 
         { 
           if (!
stristr($buffer, $key)) return 0; 
         } else 
         { 
           return 
0; 
         } 
       } 
     return 
1; 
   } 
} 

// First pass: we build a list of all files matching the criterions 
// Первый проход: мы строим список всех файлов, удволетворяющих условиям 
function countdirs($dirname) 
{ 
  global 
$filesearch,$title; 
  
$dir=opendir("."); 
  while((
$f=readdir($dir))!==false) 
  { 
    if (
is_dir($f)) 
    { 
      if ((
$f!=".") && ($f!="..")) 
      { 
        if (
IsAllowed($f)) 
        { 
          
chdir($f); 
          
countdirs($dirname."/".$f); 
          
chdir(".."); 
        } 
      } 
    } else 
    { 
      
$n=IsAllowed($f); 
      if (
$n) 
      { 
        
// Does the filename matches the query ? 
        // Имя файла совпадает с запросом ? 
        
if (FindQuery($f)) 
        { 
          
$filesearch[] = $dirname.'/'.$f; 
        } else 
        if (
$n==2) 
        { 
          
// Does the content matches the query ? 
          // Содержимое совпадает с запросом ? 
          
$fd=fopen($f,"r"); 
          
$buffer=fread($fd, filesize($f)); 
          
fclose($fd); 
          if (
FindQuery($buffer)) 
          { 
            
$filesearch[] = $dirname.'/'.$f; 
          }
          
          
$title[] = substr($buffer,strpos($buffer,'<title>')+7,strpos($buffer,'</title>')); 
        } 
      } 
    } 
  } 
  
closedir($dir); 
} 

// Second pass: we render the file 
// Второй проход: обрабатываем файл 
function Render($dirname, $filenumber,$title) 
{ 
  global 
$rootdir, $query, $m, $from, $showed, $pages, $color1, $color2, $explodestring, $maxoccurrences, $desc_header, $desc_footer, $lang_bytes, $interface_all; 
  
$f=$rootdir.$dirname; 
  ++
$showed; 
  if (
$showed&1) 
    echo 
"<tr><td bgcolor=$color2>"; 
  else 
    echo 
"<tr><td bgcolor=$color1>"; 
  echo 
str_replace("%1", $filenumber, $interface_all); 
  echo 
"<a href=\"$dirname\">$title</a> "; 
  echo 
filesize($f)." $lang_bytes, ".date("d M Y", filectime($f)).". "; 

  if (
IsAllowed($dirname)==2) 
  { 
    
$fc=file($f); 
    
$filet=join("", $fc); 
    if (
preg_match("/<title.*>(.*)<\/title.*>/isU", $filet, $match)) 
    { 
      
// display the title 
      // показать заголовок 
      
echo trim($match[1]); 
    } 
    
// display the content matches 
    // показать содержимое 
    
$s=implode($fc, $explodestring); 
    
$s=strip_tags($s); 
    
$fc=explode($explodestring, $s); 
    
$q=explode(" ",$_POST[query]); 
    
$occurrence=0; 
    echo 
"<br>$desc_header"; 
    for (
$i=0; $i<count($fc); ++$i) 
    { 
      
$occ=0; 
      
$s=strtolower(strip_tags($fc[$i])); 
      for (
$j=0; $j<count($q); ++$j) 
      { 
        if (
stristr($s, $q[$j])) 
        { 
          
$s=str_replace($q[$j], "<b>$q[$j]</b>", $s); 
          
$occ=1; 
        } 
        else 
        { 
          
$key=htmlentities($q[$j]); 
          if (
stristr($s, $key)) 
          { 
            
$s=str_replace($key, "<b>$key</b>", $s); 
            
$occ=1; 
          } 
        } 
      } 
      if (
$occ) 
      { 
        
$occ=0; 
        echo 
"...$s..."; 
        ++
$occurrence; 
        if (
$occurrence > $maxoccurrences) break; 
      } 
    } 
    echo 
$desc_footer; 
  } 
  echo 
"</td></tr>\n"; 
} 

// Display navigation bar 
// Вывести панель навигации 
function DisplayNavbar($all) 
{ 
  global 
$PHP_SELF; 
  global 
$color0, $pages, $query, $m, $search_separator; 
  echo 
"<tr bgcolor=$color0><td align=center>"; 
  for (
$k=1; $k<=$all; $k+=$pages) 
  { 
    if (
$k!=1) echo $search_separator; 
    echo 
"<a href=$PHP_SELF?query=".urlencode($_POST[query])."&m=$_POST[m]&from=$k>$k-"; 
    if (
$k+$pages>$all) echo $all; else echo ($k-1+$pages); 
    echo 
"</a>"; 
  } 
  echo 
"</td></tr>\n"; 
} 

// ****************************> MAIN CODE <********************************* 
if (!isset($from)) $from=1; 
if (!isset(
$_POST[query])) $_POST[query]=""; 
$_POST[query]=strtolower(trim(strip_tags($_POST[query]))); 

place_header(); 

if (
$_POST[query]!="") 
{ 
  
$rootdir=$DOCUMENT_ROOT; 
  unset(
$filesearch); 
  
countdirs($start_search); 
  
$time=explode(' ', microtime()); 
  
$seconds=($time[1]+$time[0]-$start_time); 
  
$all=count($filesearch); 
  if (
$all>0) 
  { 
    echo 
"<center>".str_replace("%2", sprintf("%01.3f", $seconds), str_replace("%1", $all, $lang_wasfound))."<br></center>\n"; 
    echo 
"<table width=95% cellspacing=0 cellpadding=1>\n"; 
    
$showed=0; 
    
DisplayNavbar($all); 
    for(
$i=$from;$i < $from+$pages;++$i) 
    { 
      if (
$i >= $all+1) break; 
      
Render($filesearch[$i-1], $i,$title[$i-1]); 
    } 
    
DisplayNavbar($all); 
    echo 
"</table>\n"; 
  } 
  else 
  { 
    echo 
"<center>".str_replace("%1", sprintf("%01.3f", $seconds), $lang_nofiles)."</center>"; 
  } 
} 
$time=explode(' ',microtime()); 
$seconds=($time[1]+$time[0]-$start_time); 
echo 
"<p align=right><small>".str_replace("%1", sprintf("%01.3f", $seconds), $lang_generated)."</small></p>"; 
place_footer(); 
?>

Вот попробуй так ...
 
Ответить с цитированием

  #3  
Старый 27.08.2008, 14:02
~NeiTRoN~
Познающий
Регистрация: 03.07.2008
Сообщений: 65
С нами: 9397381

Репутация: 4
По умолчанию

Цитата:
Сообщение от Doom123  
Вот попробуй так ...
Ага получилось, только там строчку надо одну ниже перенести и все становится нормально! Спс

Последний раз редактировалось ~NeiTRoN~; 27.08.2008 в 14:17..
 
Ответить с цитированием
Ответ



Предыдущая тема Следующая тема
Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Помогите со скриптом mail() Tapaceuka PHP 7 16.08.2008 05:28
Помогите со скриптом T40 PHP 4 26.05.2008 18:11
Помогите со скриптом для чеканья мыл lastsmile PHP 1 10.03.2008 20:49
помогите с скриптом Kain Болталка 0 06.02.2006 16:10



Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT ™ © 2001- Antichat Kft.