771 |
florian |
1 |
<?php
|
|
|
2 |
|
772 |
florian |
3 |
define('MAGPIE_DIR', GEN_CHEMIN_API.'syndication_rss/magpierss/');
|
771 |
florian |
4 |
define('MAGPIE_CACHE_DIR', '/tmp/magpie_cache');
|
772 |
florian |
5 |
define('OUVRIR_LIEN_RSS_NOUVELLE_FENETRE', 1);
|
|
|
6 |
define('FORMAT_DATE', 'jma');
|
771 |
florian |
7 |
require_once(MAGPIE_DIR.'rss_fetch.inc');
|
|
|
8 |
|
772 |
florian |
9 |
function voir_rss($titre='', $url='', $nb=0, $nouvelle_fenetre=OUVRIR_LIEN_RSS_NOUVELLE_FENETRE, $formatdate=FORMAT_DATE) {
|
771 |
florian |
10 |
$res= '';
|
|
|
11 |
if ( $url!='' ) {
|
|
|
12 |
$rss = fetch_rss( $url );
|
|
|
13 |
if ( $titre=='' ) {$res .= '<h2>'.$rss->channel['title'].'</h2>'."\n";}
|
|
|
14 |
elseif ( $titre!='0' ) {$res .= '<h2>'.$titre.'</h2>'."\n";}
|
|
|
15 |
$res .= '<ul class="liste_rss">'."\n";
|
|
|
16 |
$i=0;
|
772 |
florian |
17 |
$nb_item=count($rss->items);
|
771 |
florian |
18 |
if (($nb==0)or($nb_item<=$nb)) {
|
|
|
19 |
foreach ($rss->items as $item) {
|
|
|
20 |
$href = $item['link'];
|
|
|
21 |
$title = $item['title'];
|
772 |
florian |
22 |
$res .= '<li class="titre_rss">'."\n";
|
|
|
23 |
if (isset($item['pubdate'])) $date=$item['pubdate'];
|
|
|
24 |
elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
|
|
|
25 |
else $formatdate='';
|
|
|
26 |
if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
|
|
|
27 |
if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
|
|
|
28 |
if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
|
|
|
29 |
if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
|
|
|
30 |
$res .= '<a class="lien_rss" href="'.$href;
|
771 |
florian |
31 |
if ($nouvelle_fenetre==1) $res .= '" onclick="window.open(this.href); return false;';
|
|
|
32 |
$res .= '">'.$title.'</a></li>'."\n";
|
|
|
33 |
}
|
|
|
34 |
}
|
|
|
35 |
else {
|
|
|
36 |
$i=0;
|
|
|
37 |
foreach ($rss->items as $item) {
|
|
|
38 |
$href = $item['link'];
|
|
|
39 |
$title = $item['title'];
|
772 |
florian |
40 |
$res .= '<li class="titre_rss">'."\n";
|
771 |
florian |
41 |
if (isset($item['pubdate'])) $date=$item['pubdate'];
|
|
|
42 |
elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
|
|
|
43 |
else $formatdate='';
|
|
|
44 |
if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
|
|
|
45 |
if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
|
|
|
46 |
if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
|
|
|
47 |
if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
|
772 |
florian |
48 |
$res .= '<a class="lien_rss" href="'.$href;
|
771 |
florian |
49 |
if ($nouvelle_fenetre==1) $res .= '" onclick="window.open(this.href); return false;';
|
|
|
50 |
$res .= '">'.$title.'</a></li>'."\n";
|
|
|
51 |
$i++;
|
|
|
52 |
if ($i>=$nb) break;
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
$res .= '</ul>'."\n";
|
|
|
56 |
}
|
|
|
57 |
//echo '<pre>'.var_dump($rss->items).'</pre><br /><br />';
|
|
|
58 |
return $res;
|
|
|
59 |
}
|
|
|
60 |
?>
|