probleme flux rss
Posté : 30 janv. 2012, 21:08
Bonjour, j'ai sur mon site une page qui annonce des evenements à venir, j'ai lié cette page à un flux rss.
Quand je consulte ce flux, je vois toutes les annonces, mais si je m'abonne à ce flux je ne vois plus qu'une seule annonce, celle la plus proche de la date d'aujourd'hui.
Y-a-t'il un probleme dans mon code php?
Quand je consulte ce flux, je vois toutes les annonces, mais si je m'abonne à ce flux je ne vois plus qu'une seule annonce, celle la plus proche de la date d'aujourd'hui.
Y-a-t'il un probleme dans mon code php?
<?php
mysql_connect("localhost", "login", "password");
mysql_select_db("database");
$rss = '<?xml version="1.0" encoding="ISO-8859-15" ?>'."\n";
$rss .= '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">'."\n";
$rss .= "\t".'<channel xml:lang="fr">'."\n";
$rss .= "\t\t".'<title>Agenda</title>'."\n";
$rss .= "\t\t".'<link>http://www.monsite.com/agenda.php</link>'."\n";
$rss .= "\t\t".'<description>Agenda</description>'."\n";
$rss .= "\t\t".'<language>fr</language>'."\n";
$rss .= '<pubDate>'.date('D, d M Y H:i:s O').'</pubDate>'."\n";
$rss .= '<lastBuildDate>'.gmdate('D, d M Y H:i:s').' GMT</lastBuildDate>'."\n";
$rss .= "\t\t".'<managingEditor>[email protected] (nom)</managingEditor>'."\n";
$rss .= "\t\t".'<webMaster>[email protected] (nom)</webMaster>'."\n";
$rss .= "\t\t".'<ttl>5</ttl>'."\n";
$rss .= "\t\t".'<atom:link href="http://www.monsite.com/flux_rss?feed=RSS" rel="self" type="application/rss+xml" />'."\n";
$modiff = array("&","\\","<",">","alt=\"affiche\"/>");
$amodiff = array("&","","<",">","alt=\"affiche\" style=\"float:right;\"/>");
function recherche($d,$a) {
$heure = substr(date('D', strtotime("$d")),0,3).', '.date('d', strtotime("$d")).' '.substr(date('M', strtotime("$d")),0,3).' '.date('Y', strtotime("$d")).' ';
if (substr($a,0,1) == ' ')
$a = substr($a,1,strlen($a));
if (is_numeric(substr($a,3,4))) {
$heure .= substr($a,0,2).':'.substr($a,3,5).':00 +0100';
}
else {
$heure .= substr($a,0,2).':00:00 +0100';
}
return $heure;
}
$nws = mysql_query("SELECT id, titre, date, image, lieu, lien, contenu, heure FROM agenda ORDER BY date asc")or die("Impossible d'exécuter la requête : " . mysql_error());
while ($info = mysql_fetch_array($nws))
{
$desc = date('d', strtotime($info['date'])).'/'.date('m', strtotime($info['date'])).'/'.date('Y', strtotime($info['date'])).' '.$info['heure'].'<br/>'.$info['lieu'].' <br>'.$info['contenu'];
$desc = str_replace($modiff,$amodiff,$desc);
$titre = $info['titre'];
$titre = str_replace($modiff,$amodiff,$titre);
$rss .= "\t\t".'<item>'."\n";
$rss .= "\t\t\t".'<title>'.$titre.'</title>'."\n";
if ((isset($info['lien']))&&($info['lien'] != ""))
$rss .= "\t\t\t".'<link>'.$info['lien'].'</link>'."\n";
else
$rss .= "\t\t\t".'<link>http://www.monsite.com/agenda.php</link>'."\n";
$rss .= "\t\t\t".'<description><img src="http://www.monsite.com/doc/'.$info['image'].'" border=0 style="float:left;" >'.$desc.'</description>'."\n";
$rss .= "\t\t\t".'<pubDate>'.recherche($info['date'],$info['heure']).'</pubDate>'."\n";
$rss .= "\t\t\t".'<guid>http://www.monsite.com</guid>'."\n";
$rss .= "\t\t".'</item>'."\n";
}
$rss .= "\t".'</channel>'."\n";
$rss .= '</rss>'."\n";
$Name = ('fluxagenda.xml'); // Création du fichier txt
$fp = fopen($Name,"w");
fputs($fp, $rss); // Met les données Flash dans le fichier txt
fclose($fp);
echo '<META HTTP-EQUIV="Refresh" CONTENT="1; URL=fluxagenda.xml">';
?>
voici le code simplifié du fluxagenda.xml que le php génère:
Code : Tout sélectionner
<?xml version="1.0" encoding="ISO-8859-15" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel xml:lang="fr">
<title>Agenda</title>
<link>http://www.monsite.com/agenda.php</link>
<description>Agenda</description>
<language>fr</language>
<pubDate>Mon, 30 Jan 2012 15:35:31 +0100</pubDate>
<lastBuildDate>Mon, 30 Jan 2012 14:35:31 GMT</lastBuildDate>
<managingEditor>[email protected] (nom)</managingEditor>
<webMaster>[email protected] (nom)</webMaster>
<ttl>5</ttl>
<atom:link href="http://www.monsite.com/flux_rss?feed=RSS" rel="self" type="application/rss+xml" />
<item>
<title>annonce 1</title>
<link>http://www.monsite.com/agenda.php</link>
<description>01/02/2012 20h30 annonce 1</description>
<pubDate>Wed, 01 Feb 2012 20:00:00 +0100</pubDate>
<guid>http://www.monsite.com</guid>
</item>
<item>
<title>annonce 2</title>
<link>http://www.monsite.com/agenda.php</link>
<description>03/02/2012 20h30 annonce 2</description>
<pubDate>Fri, 03 Feb 2012 20:00:00 +0100</pubDate>
<guid>http://www.monsite.com</guid>
</item>
<item>
<title>annonce 3</title>
<link>http://www.monsite.com/agenda.php</link>
<description>03/02/2012 20h30 annonce 3</description>
<pubDate>Fri, 03 Feb 2012 20:00:00 +0100</pubDate>
<guid>http://www.monsite.com</guid>
</item>
</channel>
</rss>