Recordad que para pedir soporte alguno, debéis facilitar los datos de soporte oportunos por favor, mirad aquí y leer las Normas generales del foro, esto nos servirá de ayuda para dar el mejor soporte..

Gracias.

La Administración de phpBB España.

Buscador

Foros donde podréis dejar vuestras dudas sobre phpBB 3.0.x
Cerrado
horizon
Observador/a
Mensajes: 3
Registrado: 04 Mar 2013, 14:22

Buscador

#1

Mensaje por horizon »

Buenos días:

Quiero colocar un buscador en mi site. Y tengo el siguiente código:

<?php

$url = $_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://';
$url .= $_SERVER['SERVER_PORT'] != '80' ? $_SERVER["SERVER_NAME"] .

":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"] : $_SERVER

['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$urlPath = explode("php/", $url);
$dir = 'files/'; //define your folder to search, for default is files
$files = scandir("../" . $dir); //if the folder "files" isn't in raiz

please change "../"
$ele = array();
$total = count((array) $files);

function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$data = curl_exec($ch);
curl_close($ch);

return $data;
}

foreach ($files as $key => $value) {
$html = file_get_contents_curl($urlPath[0] . $dir . $value);
$doc = new DOMDocument();
@$doc->loadHTML($html);
$nodes = $doc->getElementsByTagName('title');

$title = $nodes->item(0)->nodeValue;

$metas = $doc->getElementsByTagName('meta');

for ($i = 0; $i < $metas->length; $i++) {
$meta = $metas->item($i);
if ($meta->getAttribute('name') == 'description')
$description = $meta->getAttribute('content');
if ($meta->getAttribute('name') == 'keywords')
$keywords = $meta->getAttribute('content');
}
$t = substr(strrchr($value, '.'), 1);
if ($t) {
$file = $urlPath[0] . $dir . $value;
if (strtolower(substr($file, stripos($file, ".htm"))) ==

".htm" || strtolower(substr($file, stripos($file, ".html"))) ==

".html" || strtolower(substr($file, stripos($file, ".asp"))) ==

".asp" || strtolower(substr($file, stripos($file, ".php"))) ==

".php") {
$obj = array(
"title" => $title,
"link" => $file,
"description" => $keywords
);
array_push($ele, $obj);
} else {
$obj = array(
"title" => $value,
"link" => $file,
"description" => "image"
);
array_push($ele, $obj);
}
}

if ($total - 1 === $key) {
print json_encode($ele);
}
}
?>

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.

Avatar de Usuario
ThE KuKa
Administrador
Mensajes: 10374
Registrado: 04 Ene 2004, 19:27
Género:
Edad: 49

Re: Buscador

#2

Mensaje por ThE KuKa »

Tema cerrado, las razones son mas que claras y estoy cansado de repetir mil veces lo mismo.

Lee las Normas y sabrás el porque.

📌 Raul [ThE KuKa] en phpBB 📌
✅ Jr. Extension Validator - Jr. Styles Validator - Style Customisations - Translator - International Support Team
✅

Si te gustan mis estilos, traducciones, etc. y quieres mostrar algo de aprecio, no dudes en hacer una donación Imagen
:flag_es: phpBB España - En línea desde 2003 :heart:



Cerrado

Volver a “Foros de Soporte 3.0.x”