Codice PHP:
<?php
require "config.php";
$link = mysql_connect($host, $dbuser, $dbpass)
or die("Impossibile connettersi al database");
mysql_select_db($dbname)
or die("Impossibile selezionare il database");
function strSelect( $myString, $maxLength ) {
$out = "";
$s = explode( " ",$myString );
for( $i = 0, $cs = count( $s ); $i < $cs; $i++ ) {
$out .= $s[$i]." ";
if( isSet( $s[$i+1] ) && ( strlen( $out ) + strlen( $s[$i+1] ) ) > $maxLength ) {
break;
}
}
return rtrim( $out );
}
header("Content-Type: application/xml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
echo "<rss version=\"2.0\">\n
<channel>\n
<title>ShaVis RSS feeder</title>\n
<link>[url]http://www.shavis.com[/url]</link>\n
<description>the visual's newsnet</description>\n
<language>en-EN</language>\n
<image>\n
<title>ShaVis</title>\n
<url>[url]http://www.shavis.com/logostart.jpg[/url]</url>\n
<link>[url]http://www.shavis.com[/url]</link>\n
</image>\n
<webMaster>info@shavis.com</webMaster>\n
";
$link = "http://www.shavis.com/onefeed.php?feed=";
$today = date("Y-m-d");
$week = date("Y-m-d" , strtotime('+1 week'));
list($anno, $mese, $giorno) = explode("-", $today);
$mese = $mese+3;
if ($mese == 1 || $mese == 2 || $mese == 3 || $mese == 4 || $mese == 5 || $mese == 6 || $mese == 7 || $mese == 8 || $mese == 9) {
$mese = "0" . $mese;
}
$month3 = $anno . "-" . $mese . "-" . $giorno;
$result = mysql_query("SELECT * FROM `news` WHERE `date` <= '$week' AND (`deadline` = '000-00-00' OR `deadline` >= CURDATE()) AND `date` <= '$month3' ORDER BY `news_id` DESC");
while ($row = mysql_fetch_array($result)) {
$tit = $row["title"];
$tit = str_replace("®","®","$tit");
$tit = strtoupper($tit);
$tit = str_replace("é","É","$tit");
$tit = str_replace("à","Á","$tit");
$tit = str_replace("á","Á","$tit");
$tit = str_replace("ò","Ó","$tit");
$tit = str_replace("è","É","$tit");
$tit = str_replace("ì","Í","$tit");
$tit = str_replace("ù","Ú","$tit");
$testo = $row["text"];
$testo = str_replace("’","'","$testo");
$testo = str_replace("è","è","$testo");
$testo = str_replace("à","à","$testo");
$testo = str_replace("á","à","$testo");
$testo = str_replace("–","-","$testo");
$testo = str_replace("ò","ò","$testo");
$testo = str_replace("ì","ì","$testo");
$testo = str_replace("ù","ù","$testo");
$testo = str_replace("é","é","$testo");
$testo = str_replace("…","...","$testo");
$testo = str_replace("“","","$testo");
$testo = str_replace("”","","$testo");
$testo = str_replace("í","í","$testo");
$testo = str_replace("ó","ó","$testo");
$nrmax = "60";
$lunghezza = strlen($testo);
if ($lunghezza > $nrmax) {
$testo = strSelect( $testo, 60 ) . " ...";
} else {
$testo = $testo;
}
echo "<item>\n";
echo "<title>" . $tit . "</title>\n";
echo "<link>" . $link . $row["news_id"] . "</link>\n";
echo "<description>" . $testo . "</description>\n";
echo "<date>" . $row["date"] . "</date>\n";
echo "</item>\n";
}
echo "</channel>\n
</rss>";
$query3 = ("OPTIMIZE TABLE `news`");
$result3 = mysql_query($query3)
or die("Optimize failed");
?>