<html>
<head>
<title> Current Articles </title>
</head>
<body>
<h2>RSS news aggregator (exercice maltt-0)</h2>
<?php
// error_reporting(E_ALL);
// begin configure
$base_dir = "/data/web/etu-maltt/linus";
echo "Je cherche des fichiers appelés 'backend.xml' qui se trouvent dans les sous-répertoires directs de $base_dir: ";
$rss_urls = array();
$handle = opendir($base_dir);
while ($student_directory = readdir($handle)) {
$filename = $base_dir."/".$student_directory."/backend.xml";
if (file_exists($filename)) {
// echo "<br>Fichier trouve: " . $filename;
$rss_urls[] = $filename;
}
}
closedir($handle);
?>
<?php
// end configure
include("class.RSS.php");
function do_news_feed ($rss_url) {
$data = implode("",file($rss_url));
$size = strlen($data);
// print "Searching [$size] bytes of data.\n";
$rss = new RSS($data);
$count = $rss->getCount();
// print "Class parsed [$count] channels\n";
echo "<hr>";
echo "[ Input de " . $rss_url . " ]<br>";
for ($x=0;$x<$count;$x++)
{
$info = $rss->getChannelInfo($x);
$title = "NEWS FEED";
if ($info) {
while ( list ($tagName,$tagVal) = each ($info) )
{
// print "Channel [$x] [$tagName]: [$tagVal]\n";
if ($tagName == "title") $title=$tagVal;
elseif ($tagName == "link") $link=$tagVal;
elseif ($tagName == "description") $description=$tagVal;
elseif ($tagName == "url") $icon=$tagVal;
}
} else {
echo "<br>[ Ce channel n'est pas bien documenté ]";
}
}
// ****************************** print the stuff
if ($icon) print "<img src=\"" . $icon . "\" align=\"left\">" . "\n";
if ($link) print "<h1> <a href=\"" . $link . "\">" . $title . "</a> </h1> \n" ;
if ($description) print $description ;
print "<br clear=\"all\"\n>";
// print "\nItem information\n";
$allItems = $rss->getAllItems();
$itemCount = count($allItems);
print "<p>";
print "Tous les channels combinés ont $itemCount items:\n\n";
print "</p>";
print "<ul>\n";
for($y=0;$y<$itemCount;$y++)
{
print "<li>\n";
print "<a href=\"" . $allItems[$y]['LINK'] . "\">" . $allItems[$y]['TITLE'] . "</a> \n" ;
$desc = $allItems[$y]['DESCRIPTION'];
if ($desc != "") print "<br> \n" . $desc;
print "</li>\n";
}
print "</ul>\n";
}
if ($rss_urls) {
foreach ($rss_urls as $rss_url) {
do_news_feed ($rss_url);
}
}
else { echo "<p>hmm, rien trouvé pour le moment</p>"; }
?>
</body>
</html>