Ir para conteúdo
Fórum Script Brasil
  • 0

Problemas com rotina de busca !


Dj Debas

Pergunta

Fala pessoal !!!

Peço uma ajuda a quem puder me ajudar.

Tenho uma rotina de busca que funcionava e agora não funciona mais, o servidor mudou e a rotina parou de funcionar.

Percebi que o REGISTER_GLOBALS esta OFF e não sei se isso afeta a rotina que uso, por isso peço um auxilio a quem puder me ajudar.

A rotina segue abaixo:

<?
 ############################################################################
 # WFSearch Engine by jID     Version 0.8 (PHP4) (09 jan 2003)              #
 # Copyright (C) jID, 2002-2003                                             #
 #               Jean-Charles Meyrignac 2003                                #
 #                                                                          #
 # Search unit :: Ìîäóëü ïîèñêà                                             #
 ############################################################################

require ("../config3.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

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;
  $query = ereg_replace( '[ÁÀÂÃÄ]', 'A', $query);
    $query = ereg_replace( '[áàâãäª]', 'a', $query);
    $query = ereg_replace( '[ÉÈÊË]', 'E', $query);
    $query = ereg_replace( '[éèêë]', 'e', $query);
    $query = ereg_replace( '[ÍÌÎÏ]', 'I', $query);
    $query = ereg_replace( '[íìîï]', 'i', $query);
    $query = ereg_replace( '[ÓÒÔÕÖ]', 'O', $query);
    $query = ereg_replace( '[óòôõöº]', 'o', $query);
    $query = ereg_replace( '[ÚÙÛÜ]', 'U', $query);
    $query = ereg_replace( '[úùûü]', 'u', $query);

    $query = str_replace( 'Ç', 'C', $query);
    $query = str_replace( 'ç', 'c', $query);
        
    $query = str_replace( '´', '', $query );
    $query = str_replace( '`', '', $query );
    $query = str_replace( '~', '', $query );
    $query = str_replace( '^', '', $query );
    $query = str_replace( '¨', '', $query );

    $query = str_replace( '-', '', $query );
    $query = str_replace( '_', '', $query );
//  $query = str_replace( ' ', '', $query );
  $t=explode(" ", $query);
   if ($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);
}


function Render($dirname, $filenumber)
{
  global $ip1, $rootdir, $query, $m, $from, $showed, $pages, $color1, $color2, $explodestring, $maxoccurrences, $desc_header, $desc_footer, $lang_bytes, $interface_all;
  $f=$rootdir.$dirname;
  $arq = basename ($dirname,".mid");
  $arq = str_replace("_"," ",$arq);     // nome inteiro sem underline
  ++$showed;
  if ($showed&1)
    echo "<div align='left' style='margin-left: 100px; margin-right: 50px'>";
  else
    echo "<div align='left' style='margin-left: 100px; margin-right: 50px'>";
    echo "<p class=\"link\"><a href=\"http://www.djdebas.net/Midis$dirname\">",str_replace("%1", $filenumber, $interface_all),"&nbsp;$arq</font></a></p>";


  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(" ",$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 "</div>\n";
}

// Display navigation bar
function DisplayNavbar($all)
{
  global $PHP_SELF;
  global $color0, $pages, $query, $m, $search_separator;
  echo "<div align='center' >";
  for ($k=1; $k<=$all; $k+=$pages)
  {
    if ($k!=1)
        echo $search_separator;
          echo "<a class='navbar' href=$PHP_SELF?query=".urlencode($query)."&m=$m&from=$k>$k-";
        if ($k+$pages>$all)
             echo $all;
        else
             echo ($k-1+$pages);
 //                echo "</div>";
  }
 // echo "</td></tr>\n";
}

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

if ($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><font color=\"#006400\">".str_replace("%2", sprintf("%01.3f", $seconds), str_replace("%1", $all, "Encontrado(s) <b>%1</b> arquivo(s)."))."</font></center><br>\n";
    echo "<div align='center'>\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 "</div><br>\n";
  }
  else
  {
    echo "<center><font color=\"#006400\">Nenhum arquivo encontrado.</font></center>";
  }
}
$time=explode(' ',microtime());
$seconds=($time[1]+$time[0]-$start_time);
// echo "<form><p align=center><input class=\"botao\" type=\"button\" value=\"Voltar\" onclick=\"history.go(-1)\"></p></form>";
?>
</tbody> </table></center></td></tr> </tbody> </table></center>
</body>
</html>

Rotina de Busca PHP

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...