/** * Imprimir categorías * * Crea los archivos para cada categoria como nombre.html */ protected function imprimir_individuales() { // Cargar configuración de las categorías $categorias_config = new \Configuracion\CategoriasConfig(); // Iniciar la plantilla $plantilla = new Plantilla(); $plantilla->navegacion = new Navegacion(); $plantilla->mapa_inferior = new MapaInferior(); $plantilla->directorio = \Configuracion\CategoriasConfig::DIRECTORIO; $plantilla->navegacion->opcion_activa = \Configuracion\CategoriasConfig::NAVEGACION_OPCION_ACTIVA; // Bucle por todas las categorías foreach ($this->recolector->obtener_categorias() as $categoria_texto) { // Obtener instancia de Categoria $categoria = $categorias_config->obtener($categoria_texto); // Si está definido en \Configuracion\CategoriasConfig if ($categoria === false) { $categoria = new Categoria($categoria_texto); $categoria->descripcion = "Publicaciones en la categoría {$categoria_texto}"; } // Definir ruta del archivo a crear, las banderas en falso hacen que el URL sea categoria.html $categoria->en_raiz = false; $categoria->en_otro = false; $ruta = sprintf('%s/%s', $plantilla->directorio, $categoria->url()); // Filtrar por esta categoría $this->recolector->filtrar_publicaciones_de_categoria($categoria_texto); // Iniciar página $pagina = new PaginasCategoriasIndividual($categoria, $this->recolector); $pagina->en_raiz = false; $pagina->en_otro = true; // Pasar a la plantilla los valores que cambian en cada página $plantilla->titulo = $pagina->titulo; $plantilla->descripcion = $pagina->descripcion; $plantilla->claves = "Categoria, {$categoria_texto}"; $plantilla->archivo_ruta = $ruta; // Pasar a la plantilla el HTML y Javascript $plantilla->contenido = $pagina->html(); $plantilla->javascript = $pagina->javascript(); // Crear archivo $this->crear_archivo($plantilla->archivo_ruta, $plantilla->html()); $this->contador++; } }
function sitemap($file = "./sitemap.xml") { //define( "ENT_XML1", 16 );//Porque no conoce esto el PHP?????!!! $sl = "\n"; $sg = "\t"; $fp = fopen($file, "w"); $where = "visible=1"; $order = "id asc"; $limit = ""; $tipo = "arrIds"; $arrIdsProd = Producto::AllToArray($where, $order, $limit, $tipo); $where = "visible=1"; $order = "id asc"; $limit = ""; $tipo = "arrIds"; $arrIdsCat = Categoria::AllToArray($where, $order, $limit, $tipo); $contents = '<?xml version="1.0" encoding="UTF-8" ?>' . $sl; $contents .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . $sl; foreach ($arrIdsCat as $idCat) { $objCat = new Categoria($idCat); $contents .= $sg . '<url>' . $sl; $contents .= $sg . $sg . '<loc>'; $contents .= str_replace("&", "&", $objCat->url(false)); $contents .= '</loc>' . $sl; $contents .= $sg . $sg . '<lastmod>'; $contents .= Fecha::toW3C(Fecha::fromMysql($objCat->GETupdate())); $contents .= '</lastmod>' . $sl; $contents .= $sg . $sg . '<changefreq>'; $contents .= "weekly"; $contents .= '</changefreq>' . $sl; $contents .= $sg . $sg . '<priority>'; $contents .= '0.5'; //TODO: mejora: establecer este valor en base a las valoraciones de los usuarios $contents .= '</priority>' . $sl; $contents .= $sg . '</url>' . $sl; } foreach ($arrIdsProd as $idProd) { $objProd = new Producto($idProd); $contents .= $sg . '<url>' . $sl; $contents .= $sg . $sg . '<loc>'; $contents .= str_replace("&", "&", $objProd->url(false)); $contents .= '</loc>' . $sl; $contents .= $sg . $sg . '<lastmod>'; $contents .= Fecha::toW3C(Fecha::fromMysql($objProd->GETupdate())); $contents .= '</lastmod>' . $sl; $contents .= $sg . $sg . '<changefreq>'; $contents .= "weekly"; $contents .= '</changefreq>' . $sl; $contents .= $sg . $sg . '<priority>'; $contents .= '0.5'; //TODO: mejora: establecer este valor en base a las valoraciones de los usuarios $contents .= '</priority>' . $sl; $contents .= $sg . '</url>' . $sl; } $contents .= '</urlset>' . $sl; fwrite($fp, $contents); fclose($fp); chmod($file, 0666); //comprimirlo $gzfile = $file . ".gz"; // Open the gz file (w9 is the highest compression) $fp = gzopen($gzfile, 'w9'); // Compress the file gzwrite($fp, file_get_contents($file)); // Close the gz file and we are done gzclose($fp); chmod($gzfile, 0666); unlink($file); }