Location: PHPKode > projects > Spacemarc News > spacemarc-news/rss.php
<?php

/*****************************************************************
*  Spacemarc News
*  Version: 1.2.0
*  Author and copyright (C): Marcello Vitagliano
*  Web site: http://www.spacemarc.it
*  License: GNU General Public License
*
*  This program is free software: you can redistribute it and/or
*  modify it under the terms of the GNU General Public License
*  as published by the Free Software Foundation, either version 3
*  of the License, or (at your option) any later version.
*
*  Current file: rss.php
*****************************************************************/
header("Content-type: text/xml; charset=ISO-8859-1");

//includo i file di configurazione
require_once (dirname(__FILE__) . '/config.php');

//apro la connessione a mysql
$db = mysql_connect($db_host, $db_user, $db_password) or die("Impossibile connettersi a MySQL<br />Numero errore: " . mysql_errno() . "<br />Tipo di errore: " . mysql_error());
mysql_select_db($db_name, $db) or die("Impossibile selezionare il database $db_name<br />Numero errore: " . mysql_errno() . "<br />Tipo di errore: " . mysql_error());

//estraggo alcune impostazioni
$conf = mysql_query("SELECT nome_sito, url_sito FROM $tab_config");
$rowconf = @mysql_fetch_array($conf);
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n";
echo "<channel>\n";
echo "<atom:link href=\"" . $rowconf['url_sito'] . "/$news_dir/rss.php\" rel=\"self\" type=\"application/rss+xml\" />\n";
echo "<title>" . $rowconf['nome_sito'] . " - Feed RSS</title>\n";
echo "<link>" . $rowconf['url_sito'] . "</link>\n";
echo "<description>Le ultime notizie dal sito</description>\n";
echo "<copyright>Copyright " . $rowconf['nome_sito'] . "</copyright>\n";
echo "<docs>http://blogs.law.harvard.edu/tech/rss</docs>\n";
echo "<language>IT-it</language>\n\n";
$query = mysql_query("SELECT nt.id, nu.nome_cognome, nt.data_pubb, nt.titolo, nt.testo FROM $tab_news nt JOIN $tab_utenti nu ON nu.user_id=nt.user_id ORDER BY nt.data_pubb DESC LIMIT 0,10");

while ($row = @mysql_fetch_array($query)) {
    $titolo = html_entity_decode($row['titolo'], ENT_QUOTES);
    $autore = html_entity_decode($row['nome_cognome'], ENT_QUOTES);
    $testo = nl2br($row['testo']);
    $format_text = array(
        "{\[email\](\r\n|\r|\n)*([a-zA-Z0-9\._-]+@(([a-zA-Z0-9_-])+\.)+[a-z]{2,6})\[/email\]}siU",
        "{\[email=(\w[\w\-\.\+]*?@\w[\w\-\.]*?\w\.[a-zA-Z]{2,4})\](.+)?\[\/email\]}siU",
        "{(\[)(url)(])((http|ftp|https)://)([^;<>\*\(\)\"\s]*)(\[/url\])}siU",
        "{(\[)(url)(=)(['\"]?)((http|ftp|https)://)([^;<>\*\(\)\"\s]*)(\\4])(.*)(\[/url\])}siU",
        "{(\[)(callto)(])((callto):)([^;<>\*\(\)\"\s]*)(\[/callto\])}siU",
        "{(\[)(callto)(=)(['\"]?)((callto):)([^;<>\*\(\)\"\s]*)(\\4])(.*)(\[/callto\])}siU",
        "{\[img\](\r\n|\r|\n)*((http|https)://([^;<>\*\(\)\"\s]+)|[a-z0-9/\\\._\- ]+)\[/img\]}siU",
        "{\[quote\](\r\n|\r|\n)*(.+)\[/quote\]}siU",
        "{\[code\](\r\n|\r|\n)*(.+)\[/code\]}siU",
        "{\[yt\]([0-9A-Za-z-_]{11})\[/yt]}siU"
    );
    $replace_text = array(
        "<a href=\"mailto:\\2\">\\2</a>",
        "<a href=\"mailto:\\1\">\\2</a>",
        "<a href=\"\\4\\6\" target=\"_blank\">\\4\\6</a>",
        "<a href=\"\\5\\7\" target=\"_blank\">\\9</a>",
        "<a href=\"\\4\\6\" target=\"_blank\">\\4\\6</a>",
        "<a href=\"\\5\\7\" target=\"_blank\">\\9</a>",
        "<img src=\"\\2\" alt=\"immagine\" title=\"\" />",
        "[Citazione]<i>\n\\2\n</i>[/Citazione]",
        "[Codice]\n\\2\n[/Codice]",
        "<a href=\"http://www.youtube.com/watch?v=\\1\" target=\"_blank\">Video</a>"
    );
    $testo = preg_replace($format_text, $replace_text, $testo);
    $replace_list = array(
        '[ul]' => '<ul>',
        '[/ul]' => '</ul>',
        '[li]' => '<li>',
        '[/li]' => '</li>',
        '[b]' => '<b>',
        '[/b]' => '</b>',
        '[i]' => '<i>',
        '[/i]' => '</i>',
        '[u]' => '<u>',
        '[/u]' => '</u>',
        ':cool:' => '',
        ':)' => '',
        '):' => '',
        ':p' => '',
        ':D' => '',
        ';)' => '',
        ':o' => '',
        ':zizi:' => '',
        ':(' => '',
        ':green:' => '',
        ':dotto:' => '',
        ':cry:' => '',
        ':parolaccia:' => '',
        ':incupito:' => '',
        ':stordito:' => '',
        ':info:' => '',
        ':star:' => '',
        ':alert:' => '',
        ':???:' => '',
        ':check:' => '',
        ':wiki:' => '',
        ':chat:' => '',
        ':www:' => '',
        ':man:' => '',
        ':mail:' => '',
        ':fb:' => '',
        ':li:' => '',
        ':ms:' => '',
        ':tw:' => '',
        ':gw:' => ''
    );
    $testo = strtr($testo, $replace_list);
    echo "<item>\n";
    echo "<title><![CDATA[$titolo]]></title>\n";
    echo "<dc:creator><![CDATA[$autore]]></dc:creator>\n";
    echo "<category>News</category>\n";
    echo "<pubDate>" . date("r", $row['data_pubb']) . "</pubDate>\n";
    echo "<guid>" . $rowconf['url_sito'] . "/$news_dir/view.php?id=" . $row['id'] . "</guid>\n";
    echo "<description><![CDATA[$testo]]></description>\n";
    echo "</item>\n\n";
}
echo "</channel>\n";
echo "</rss>";
?>
Return current item: Spacemarc News