122 lines
2.9 KiB
PHP
122 lines
2.9 KiB
PHP
<?php
|
||
|
||
require_once "rssparser.inc.php";
|
||
|
||
global $nbnews;
|
||
global $titre;
|
||
|
||
$rootdir="/web/website/backends/xml/";
|
||
|
||
$sitedata=get_sitedata($source);
|
||
extract($sitedata);
|
||
$news=parse_rss2($rootdir.$source);
|
||
|
||
/************************ partie affichage *************************/
|
||
/*extract($themeset, EXTR_OVERWRITE);
|
||
|
||
if (!isset($nbnews))
|
||
{
|
||
$nbnews = $index_title;
|
||
}
|
||
|
||
$ga = 0;
|
||
while($ga<=$nbnews-1)
|
||
{
|
||
$news[$ga]["title"] = str_replace("& ","&", $news[$ga]["title"]);
|
||
|
||
echo "<a href=\"$base_url".htmlspecialchars($news[$ga]["link"])."\" target=\"_blank\">".$news[$ga++]["title"]."</a><br/>\n";
|
||
}
|
||
*/
|
||
function parse_rss2($filename)
|
||
{
|
||
$xml = simplexml_load_file($filename);
|
||
foreach($xml->channel->item as $news) {
|
||
echo '<a href="'.$news->link.'">', utf8_decode((string) $news->title), '</a><br />';
|
||
}
|
||
}
|
||
|
||
class RSSDisplay {
|
||
public $fichierRss;
|
||
|
||
function __construct($fichierRss) {
|
||
$this->fichierRss = $fichierRss;
|
||
$xml = simplexml_load_file($fichierRss);
|
||
echo '<ul>';
|
||
foreach($xml->channel->item as $news) {
|
||
echo '<li><a href="'.$news->link.'">', utf8_decode((string) $news->title), '</a></li>';
|
||
}
|
||
echo '</ul>';
|
||
}
|
||
}
|
||
|
||
//************************************************
|
||
//* renvoie les titres d'un fichier backend RSS **
|
||
//************************************************
|
||
/*
|
||
function parse_rss($filename)
|
||
{
|
||
$php_ver = phpversion();
|
||
if ($php_ver[0] >= 5)
|
||
{
|
||
$s = simplexml_load_file($filename);
|
||
foreach ($s->channel->item as $news)
|
||
{
|
||
$items[$cpt]["title"] = $news->title;
|
||
echo $items[$cpt]["title"];
|
||
$items[$cpt++]["link"] = $news->link;
|
||
}
|
||
|
||
}
|
||
else
|
||
{
|
||
global $convert;
|
||
//$trans["&"] = "&";
|
||
$trans[">"] = ">\n";
|
||
|
||
if (isset($convert) && $convert="on")
|
||
$data = strtr(implode("",file($filename)),$trans);
|
||
else
|
||
$data = implode("",file($filename));
|
||
|
||
// initialise les compteurs
|
||
$cpt = 0;
|
||
$index_item = 0;
|
||
|
||
// parse le fichier et remplit les tableaux
|
||
$p = xml_parser_create("");
|
||
xml_parser_set_option($p, XML_OPTION_TARGET_ENCODING, "iso-8859-1");
|
||
xml_parse_into_struct($p,$data,&$vals,&$index);
|
||
xml_parser_free($p);
|
||
|
||
// parcourt et r<>cup<75>re les donn<6E>es
|
||
foreach($index as $key->$val)
|
||
{
|
||
$array = $key->$val;
|
||
$pos = $array[0];
|
||
$tag = $vals[$pos][tag];
|
||
$val = $vals[$pos][value];
|
||
|
||
if ($tag == "ITEM")
|
||
{
|
||
while ($index[ITEM][$index_item] != "")
|
||
{
|
||
$tag2 = $vals[$index[ITEM][$index_item]+1][tag];
|
||
$value2 = $vals[$index[ITEM][$index_item]+1][value];
|
||
$index_item++;
|
||
|
||
if ($tag2 == "TITLE")
|
||
{
|
||
$items[$cpt]["title"] = utf8_decode($value2);
|
||
// echo "$value2";
|
||
}
|
||
if ($tag2 == "LINK")
|
||
$items[$cpt++]["link"] = $value2;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return $items;
|
||
}
|
||
*/
|
||
|
||
?>
|