Beispiel #1
0
	<?php 
// Se intenta crear la conexión a la BD para leer las publicaciones y los comentarios
try {
    @($con_bd = new mysqli($datosbd['conexion'], $datosbd['usuario1'], $datosbd['contra1'], $datosbd['nombre_bd']));
    // En caso de fallo, se muestra un mensaje de error, y se cambia el valor de la variable $error_bd a 'true' para que no intente usar la BD.
} catch (Exception $e) {
    echo '<head><title>Rebel Gamers Clan - Leer publicación</title>
		<meta name="description" content="Leer una publicación escrita en Rebel Gamers Clan">
		<meta name="keywords" content="rebel,gamers,clan,comunidad,team,fortress,española,españa,steam,leer,publicacion">
		<meta name="author" content="DR.DVD">';
    mostrarPrimeraPartePagina();
    echo '<div class="notificacion_error"><b>Ha fallado la conexión con la base de datos.</b> Vuelve más tarde, a ver si se ha podido solucionar el problema.</div>';
    $error_bd = true;
}
if (!$error_bd) {
    prepararConexionUTF8($con_bd);
    // Comprobamos si se ha introducido el parámetro de ID. En caso afirmativo, mostramos la página.
    if (isset($_GET['id'])) {
        // Obtenemos la ID introducida.
        $id_publicacion = $_GET['id'];
        // Se crea la sentencia para buscar la publicación en la BD.
        $sent_prep = $con_bd->prepare("SELECT publicaciones.*, usuarios.id AS id_autor, usuarios.nombre, usuarios.id_steam, usuarios.url_perfil, usuarios.url_avatar FROM publicaciones JOIN usuarios ON usuarios.id = publicaciones.autor WHERE publicaciones.id = (?)");
        if (!$sent_prep) {
            echo '<head><title>Rebel Gamers Clan - Leer publicación</title>
				<meta name="description" content="Leer una publicación escrita en Rebel Gamers Clan">
				<meta name="keywords" content="rebel,gamers,clan,comunidad,team,fortress,española,españa,steam,leer,publicacion">
				<meta name="author" content="DR.DVD">';
            mostrarPrimeraPartePagina();
            echo '<div class="notificacion_error"><b>Ha habido un problema obteniendo los datos de la publicación de la base de datos.</b>' . ' Vuelve más tarde, a ver si se ha podido solucionar el problema.</div>';
        } else {
            $sent_prep->bind_param("i", $id_publicacion);
Beispiel #2
0
function generarRSS()
{
    include 'datosbd.php';
    $docXml = new DOMDocument("1.0", "UTF-8");
    $docXml->formatOutput = true;
    $rss = $docXml->createElement("rss");
    $nodo_rss = $docXml->appendChild($rss);
    $nodo_rss->setAttribute("version", "2.0");
    $channel = $docXml->createElement("channel");
    $nodo_channel = $nodo_rss->appendChild($channel);
    $title = $docXml->createElement("title");
    $nodo_title = $nodo_channel->appendChild($title);
    $texto_title = $docXml->createTextNode("Rebel Gamers Clan");
    $nodo_title->appendChild($texto_title);
    $link = $docXml->createElement("link");
    $nodo_link = $nodo_channel->appendChild($link);
    $texto_link = $docXml->createTextNode("http://rebelgamersclan.es");
    $nodo_link->appendChild($texto_link);
    $description = $docXml->createElement("description");
    $nodo_description = $nodo_channel->appendChild($description);
    $texto_description = $docXml->createTextNode("RSS con la actualidad de Rebel Gamers Clan");
    $nodo_description->appendChild($texto_description);
    $error_bd = false;
    try {
        $con_bd = new mysqli($datosbd['conexion'], $datosbd['usuario1'], $datosbd['contra1'], $datosbd['nombre_bd']);
    } catch (Exception $e) {
        $error_bd = true;
    }
    if (!$error_bd) {
        prepararConexionUTF8($con_bd);
        $sent = "SELECT publicaciones.id AS id_publicacion, publicaciones.fecha, publicaciones.titulo, publicaciones.resumen," . "publicaciones.idioma, publicaciones.categoria, usuarios.id AS id_autor, usuarios.nombre FROM publicaciones " . "JOIN usuarios ON usuarios.id = publicaciones.autor ORDER BY id_publicacion DESC LIMIT 10";
        $result_list_textos = $con_bd->query($sent);
        if ($result_list_textos) {
            if (mysqli_num_rows($result_list_textos) > 0) {
                while ($texto = $result_list_textos->fetch_assoc()) {
                    $item = $docXml->createElement("item");
                    $nodo_item = $nodo_channel->appendChild($item);
                    // Nodos dentro de cada 'item', que representa los atributos de la publicación.
                    $title = $docXml->createElement("title");
                    $nodo_title = $nodo_item->appendChild($title);
                    $texto_title = $docXml->createTextNode($texto['titulo']);
                    $nodo_title->appendChild($texto_title);
                    $link = $docXml->createElement("link");
                    $nodo_link = $nodo_item->appendChild($link);
                    $texto_link = $docXml->createTextNode("http://rebelgamersclan.es/leer.php?id=" . $texto['id_publicacion']);
                    $nodo_link->appendChild($texto_link);
                    $description = $docXml->createElement("description");
                    $nodo_description = $nodo_item->appendChild($description);
                    $texto_description = $docXml->createTextNode($texto['resumen']);
                    $nodo_description->appendChild($texto_description);
                    $objFecha = new DateTime($texto['fecha']);
                    $fechaRSS = $objFecha->format(DateTime::RSS);
                    $pubDate = $docXml->createElement("pubDate");
                    $nodo_pubDate = $nodo_item->appendChild($pubDate);
                    $texto_pubDate = $docXml->createTextNode($fechaRSS);
                    $nodo_pubDate->appendChild($texto_pubDate);
                    $author = $docXml->createElement("author");
                    $nodo_author = $nodo_item->appendChild($author);
                    $texto_author = $docXml->createTextNode($texto['nombre']);
                    $nodo_author->appendChild($texto_author);
                    $category = $docXml->createElement("category");
                    $nodo_category = $nodo_item->appendChild($category);
                    $texto_category = $docXml->createTextNode(tratarCategoria($texto['categoria']));
                    $nodo_category->appendChild($texto_category);
                    $comments = $docXml->createElement("comments");
                    $nodo_comments = $nodo_item->appendChild($comments);
                    $texto_comments = $docXml->createTextNode("http://rebelgamersclan.es/leer.php?id=" . $texto['id_publicacion'] . "#comentarios");
                    $nodo_comments->appendChild($texto_comments);
                    $guid = $docXml->createElement("guid");
                    $nodo_guid = $nodo_item->appendChild($guid);
                    $texto_guid = $docXml->createTextNode("http://rebelgamersclan.es/leer.php?id=" . $texto['id_publicacion']);
                    $nodo_guid->appendChild($texto_guid);
                    $nodo_guid->setAttribute("isPermaLink", "true");
                }
            }
        }
        mysqli_close($con_bd);
    }
    $docXml->save("/var/www/rebelgamersclan/public_html/rss.xml");
}