Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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