Tema: Buscador
Ver Mensaje Individual
  #4 (permalink)  
Antiguo 03/03/2013, 16:16
Avatar de horizon
horizon
 
Fecha de Ingreso: septiembre-2012
Mensajes: 9
Antigüedad: 11 años, 7 meses
Puntos: 0
Respuesta: Buscador

Buenas noches:

Queria agradecer p su ayuda y p su tiempo. Sinceramente no consegui hacer las modificaciones que me sugirieron, pq mis conocimientos son básicos.
Encontre un buscador, este es el código:

Código PHP:
Ver original
  1. <?php
  2.  
  3. $url = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
  4. $url .= $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"] .
  5.  
  6. ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"] : $_SERVER
  7.  
  8. ['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
  9. $urlPath = explode("php/", $url);
  10. $dir = 'files/'; //define your folder to search, for default is files
  11. $files = scandir("../" . $dir); //if the folder "files" isn't in raiz
  12.  
  13. please change "../"
  14. $ele = array();
  15. $total = count((array) $files);
  16.  
  17. function file_get_contents_curl($url) {
  18.     $ch = curl_init();
  19.     curl_setopt($ch, CURLOPT_HEADER, 0);
  20.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  21.     curl_setopt($ch, CURLOPT_URL, $url);
  22.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  23.  
  24.     $data = curl_exec($ch);
  25.     curl_close($ch);
  26.  
  27.     return $data;
  28. }
  29.  
  30. foreach ($files as $key => $value) {
  31.     $html = file_get_contents_curl($urlPath[0] . $dir . $value);
  32.     $doc = new DOMDocument();
  33.     @$doc->loadHTML($html);
  34.     $nodes = $doc->getElementsByTagName('title');
  35.  
  36.     $title = $nodes->item(0)->nodeValue;
  37.  
  38.     $metas = $doc->getElementsByTagName('meta');
  39.  
  40.     for ($i = 0; $i < $metas->length; $i++) {
  41.         $meta = $metas->item($i);
  42.         if ($meta->getAttribute('name') == 'description')
  43.             $description = $meta->getAttribute('content');
  44.         if ($meta->getAttribute('name') == 'keywords')
  45.             $keywords = $meta->getAttribute('content');
  46.     }
  47.     $t = substr(strrchr($value, '.'), 1);
  48.     if ($t) {
  49.         $file = $urlPath[0] . $dir . $value;
  50.         if (strtolower(substr($file, stripos($file, ".htm"))) ==
  51.  
  52. ".htm" || strtolower(substr($file, stripos($file, ".html"))) ==
  53.  
  54. ".html" || strtolower(substr($file, stripos($file, ".asp"))) ==
  55.  
  56. ".asp" || strtolower(substr($file, stripos($file, ".php"))) ==
  57.  
  58. ".php") {
  59.             $obj = array(
  60.                 "title" => $title,
  61.                 "link" => $file,
  62.                 "description" => $keywords
  63.             );
  64.             array_push($ele, $obj);
  65.         } else {
  66.             $obj = array(
  67.                 "title" => $value,
  68.                 "link" => $file,
  69.                 "description" => "image"
  70.             );
  71.             array_push($ele, $obj);
  72.         }
  73.     }
  74.  
  75.     if ($total - 1 === $key) {
  76.         print json_encode($ele);
  77.     }
  78. }
  79. ?>


El buscador, realiza la busqueda en los archivos que se encuentran en la carpeta files.
El problema surge cuando agrego carpetas en la carpeta files ejemplo:

files/Ac_Dc
files/Aerosmith
files/Black_Sabbath

Quisiera saber como modificar la ruta, para que busque en la carpeta files y en todas las carpetas que voy agregando en ella.

Desde ya muchas gracias por su tiempo y por su ayuda. Disculpen insistir, pero realmente necesito que funcione, buenas noches p tds.