<?php
$domain = http://www.truc.machin/chose/;
//datepubli : bigint(20) --> timestamp
//titre : varchar
//description : varchar
//id : tinyint(3)
// SELECT $id as id, $titre as titre, $description as description, $datepubli as datepubli FROM $table ORDER BY datepubli DESC LIMIT 0,$numb
/***************************************************\
void gen_RSS(string $rss)
-Reçoit : $table Le nom de la table utilisée
$id Le nom du champ ID de la table $table
$titre Le nom du champ TITRE de la table $table
$description Le nom du champ DESCRIPTION de la table $table
$datepubli Le nom du champ DATEPUBLI de la table $table
$numb Le nombre d'éléments à affcher dans le RSS
$name Le titre du Flux
$rss Le nom du fichier RSS à créér
-Retourne : rien
\***************************************************/
function gen_RSS($table, $id, $titre, $description, $datepubli, $numb, $name, $rss) {
// En-tête du flux RSS version 2.0
$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>' . chr(13) . '<?xml-stylesheet type="text/xsl" href="rsspretty.xsl" version="1.0"?>' . chr(13);
$xml .= '<rss version="2.0">' . chr(13);
$xml .= chr(9) . '<channel>' . chr(13);
$xml .= chr(9) . chr(9) . '<title>'.$name.'</title>' . chr(13);
$xml .= chr(9) . chr(9) . '<link>'.$domain.'</link>' . chr(13);
$xml .= chr(9) . chr(9) . '<description>Description du flux</description>' . chr(13);
$xml .= chr(9) . chr(9) . '<language>fr-be</language>' . chr(13);
$xml .= chr(9) . chr(9) . '<copyright>Copyright du flux</copyright>' . chr(13);
// Ajout de la date actuelle de publication (suivant la DTD RSS)
$xml .= chr(9) . chr(9) . '<lastBuildDate>'.date("r",time()).'</lastBuildDate>' . chr(13);
// En-tête suite et fin
$xml .= chr(9) . chr(9) . '<docs>http://www.stervinou.com/projets/rss/</docs>' . chr(13);
$xml .= chr(9) . chr(9) . '<webMaster>webmaster@truc.machin</webMaster>' . chr(13);
$xml .= chr(9) . chr(9) . '<ttl>20</ttl>' . chr(13);
$xml .= chr(9) . chr(9) . '<image>' . chr(13);
$xml .= chr(9) . chr(9) . chr(9) . '<title>Titre de l'image</title>' . chr(13);
$xml .= chr(9) . chr(9) . chr(9) . '<url>Adresse de l'image</url>' . chr(13);
$xml .= chr(9) . chr(9) . chr(9) . '<link>http://'.$domain.'</link>' . chr(13);
$xml .= chr(9) . chr(9) . '</image>' . chr(13);
// Sélection des x dernières news triées de la plus récente à la plus ancienne
$Result = mysql_exec("SELECT $id as id, $titre as titre, $description as description, $datepubli as datepubli FROM $table ORDER BY datepubli DESC LIMIT 0,$numb");
// Creation des items : titre + lien + description + date de publication
while($val=mysql_fetch_array($Result)) {
$xml .= chr(9) . chr(9) . '<item>' . chr(13);
$xml .= chr(9) . chr(9) . chr(9) . '<title>'.htmlspecialchars ($val["titre"]).'</title>' . chr(13);
$xml .= chr(9) . chr(9) . chr(9) . '<link>http://'.$domain.'?news.php&id='.$val["id"].'</link>' . chr(13);
$xml .= chr(9) . chr(9) . chr(9) . '<description>'.htmlspecialchars ($val["description"]).'</description>' . chr(13);
$xml .= chr(9) . chr(9) . chr(9) . '<pubDate>'.date("r",$val["datepubli"]).'</pubDate>' . chr(13);
$xml .= chr(9) . chr(9) . chr(9) . '</item>' . chr(13);
}
// Fin du flux
$xml .= chr(9) . '</channel>' . chr(13);
$xml .= '</rss>' . chr(13);
// Ecriture du flux dans un fichier xml
$fp = fopen("rss/".$rss.".xml", 'w+');
fwrite($fp, $xml);
fclose($fp);
}
?>