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 |
|
843 |
alexandre_ |
9 |
function voir_rss($titre='', $url='', $nb=0, $nouvelle_fenetre=OUVRIR_LIEN_RSS_NOUVELLE_FENETRE, $formatdate=FORMAT_DATE, $template = "") {
|
771 |
florian |
10 |
$res= '';
|
|
|
11 |
if ( $url!='' ) {
|
|
|
12 |
$rss = fetch_rss( $url );
|
843 |
alexandre_ |
13 |
if ($template != "") {
|
|
|
14 |
$res = ""; $i = 0 ;
|
|
|
15 |
foreach ($rss->items as $item) {
|
|
|
16 |
if (strlen($item['description']) > 200) {
|
|
|
17 |
$item['description'] = substr ($item['description'] , 0, 300).'... <a href="'.$item['link'].'">Lire la suite</a>';
|
|
|
18 |
}
|
|
|
19 |
$res .= str_replace ('{num}', ++$i,
|
|
|
20 |
str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>',
|
|
|
21 |
str_replace ('{description}', $item['description'], $template))) ;
|
|
|
22 |
$res .= "\n";
|
|
|
23 |
if ($i >= $nb) break;
|
|
|
24 |
}
|
|
|
25 |
return $res ;
|
|
|
26 |
}
|
771 |
florian |
27 |
if ( $titre=='' ) {$res .= '<h2>'.$rss->channel['title'].'</h2>'."\n";}
|
|
|
28 |
elseif ( $titre!='0' ) {$res .= '<h2>'.$titre.'</h2>'."\n";}
|
|
|
29 |
$res .= '<ul class="liste_rss">'."\n";
|
|
|
30 |
$i=0;
|
772 |
florian |
31 |
$nb_item=count($rss->items);
|
771 |
florian |
32 |
if (($nb==0)or($nb_item<=$nb)) {
|
|
|
33 |
foreach ($rss->items as $item) {
|
|
|
34 |
$href = $item['link'];
|
|
|
35 |
$title = $item['title'];
|
772 |
florian |
36 |
$res .= '<li class="titre_rss">'."\n";
|
|
|
37 |
if (isset($item['pubdate'])) $date=$item['pubdate'];
|
|
|
38 |
elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
|
|
|
39 |
else $formatdate='';
|
|
|
40 |
if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
|
|
|
41 |
if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
|
|
|
42 |
if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
|
|
|
43 |
if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
|
|
|
44 |
$res .= '<a class="lien_rss" href="'.$href;
|
771 |
florian |
45 |
if ($nouvelle_fenetre==1) $res .= '" onclick="window.open(this.href); return false;';
|
|
|
46 |
$res .= '">'.$title.'</a></li>'."\n";
|
|
|
47 |
}
|
|
|
48 |
}
|
|
|
49 |
else {
|
|
|
50 |
$i=0;
|
|
|
51 |
foreach ($rss->items as $item) {
|
|
|
52 |
$href = $item['link'];
|
|
|
53 |
$title = $item['title'];
|
772 |
florian |
54 |
$res .= '<li class="titre_rss">'."\n";
|
771 |
florian |
55 |
if (isset($item['pubdate'])) $date=$item['pubdate'];
|
|
|
56 |
elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
|
|
|
57 |
else $formatdate='';
|
|
|
58 |
if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
|
|
|
59 |
if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
|
|
|
60 |
if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
|
|
|
61 |
if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
|
772 |
florian |
62 |
$res .= '<a class="lien_rss" href="'.$href;
|
771 |
florian |
63 |
if ($nouvelle_fenetre==1) $res .= '" onclick="window.open(this.href); return false;';
|
|
|
64 |
$res .= '">'.$title.'</a></li>'."\n";
|
|
|
65 |
$i++;
|
|
|
66 |
if ($i>=$nb) break;
|
|
|
67 |
}
|
|
|
68 |
}
|
|
|
69 |
$res .= '</ul>'."\n";
|
|
|
70 |
}
|
|
|
71 |
//echo '<pre>'.var_dump($rss->items).'</pre><br /><br />';
|
|
|
72 |
return $res;
|
|
|
73 |
}
|
|
|
74 |
?>
|