771 |
florian |
1 |
<?php
|
|
|
2 |
|
772 |
florian |
3 |
define('MAGPIE_DIR', GEN_CHEMIN_API.'syndication_rss/magpierss/');
|
945 |
alexandre_ |
4 |
define('MAGPIE_CACHE_DIR', MAGPIE_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) {
|
945 |
alexandre_ |
16 |
// Le test suivant pour savoir s il faut reduire l excendent de description
|
|
|
17 |
// Si {all} est present dans le template on ne reduit pas
|
|
|
18 |
if (preg_match ('/{all}/', $template)) {
|
|
|
19 |
$template = str_replace('{all}', '', $template);
|
|
|
20 |
$all = true ;
|
|
|
21 |
}
|
|
|
22 |
if (strlen($item['description']) > 200 && !$all) {
|
843 |
alexandre_ |
23 |
$item['description'] = substr ($item['description'] , 0, 300).'... <a href="'.$item['link'].'">Lire la suite</a>';
|
|
|
24 |
}
|
|
|
25 |
$res .= str_replace ('{num}', ++$i,
|
|
|
26 |
str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>',
|
945 |
alexandre_ |
27 |
str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])),
|
|
|
28 |
str_replace ('{description}', $item['description'], $template)))) ;
|
843 |
alexandre_ |
29 |
$res .= "\n";
|
|
|
30 |
if ($i >= $nb) break;
|
945 |
alexandre_ |
31 |
|
843 |
alexandre_ |
32 |
}
|
|
|
33 |
return $res ;
|
|
|
34 |
}
|
771 |
florian |
35 |
if ( $titre=='' ) {$res .= '<h2>'.$rss->channel['title'].'</h2>'."\n";}
|
|
|
36 |
elseif ( $titre!='0' ) {$res .= '<h2>'.$titre.'</h2>'."\n";}
|
|
|
37 |
$res .= '<ul class="liste_rss">'."\n";
|
|
|
38 |
$i=0;
|
772 |
florian |
39 |
$nb_item=count($rss->items);
|
771 |
florian |
40 |
if (($nb==0)or($nb_item<=$nb)) {
|
|
|
41 |
foreach ($rss->items as $item) {
|
|
|
42 |
$href = $item['link'];
|
|
|
43 |
$title = $item['title'];
|
772 |
florian |
44 |
$res .= '<li class="titre_rss">'."\n";
|
|
|
45 |
if (isset($item['pubdate'])) $date=$item['pubdate'];
|
|
|
46 |
elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
|
|
|
47 |
else $formatdate='';
|
|
|
48 |
if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
|
|
|
49 |
if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
|
|
|
50 |
if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
|
|
|
51 |
if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
|
|
|
52 |
$res .= '<a class="lien_rss" href="'.$href;
|
771 |
florian |
53 |
if ($nouvelle_fenetre==1) $res .= '" onclick="window.open(this.href); return false;';
|
|
|
54 |
$res .= '">'.$title.'</a></li>'."\n";
|
|
|
55 |
}
|
|
|
56 |
}
|
|
|
57 |
else {
|
|
|
58 |
$i=0;
|
|
|
59 |
foreach ($rss->items as $item) {
|
|
|
60 |
$href = $item['link'];
|
|
|
61 |
$title = $item['title'];
|
772 |
florian |
62 |
$res .= '<li class="titre_rss">'."\n";
|
771 |
florian |
63 |
if (isset($item['pubdate'])) $date=$item['pubdate'];
|
|
|
64 |
elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
|
|
|
65 |
else $formatdate='';
|
|
|
66 |
if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
|
|
|
67 |
if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
|
|
|
68 |
if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
|
|
|
69 |
if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
|
772 |
florian |
70 |
$res .= '<a class="lien_rss" href="'.$href;
|
771 |
florian |
71 |
if ($nouvelle_fenetre==1) $res .= '" onclick="window.open(this.href); return false;';
|
|
|
72 |
$res .= '">'.$title.'</a></li>'."\n";
|
|
|
73 |
$i++;
|
|
|
74 |
if ($i>=$nb) break;
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
$res .= '</ul>'."\n";
|
|
|
78 |
}
|
|
|
79 |
//echo '<pre>'.var_dump($rss->items).'</pre><br /><br />';
|
|
|
80 |
return $res;
|
|
|
81 |
}
|
|
|
82 |
?>
|