Subversion Repositories Applications.papyrus

Rev

Rev 771 | Blame | Last modification | View Log | RSS feed

<?php

define('MAGPIE_DIR', GEN_CHEMIN_API.'syndication_rss/magpierss/');
define('MAGPIE_CACHE_DIR', '/tmp/magpie_cache');
define('OUVRIR_LIEN_RSS_NOUVELLE_FENETRE', 1);
define('FORMAT_DATE', 'jma');
require_once(MAGPIE_DIR.'rss_fetch.inc');

function voir_rss($titre='', $url='', $nb=0, $nouvelle_fenetre=OUVRIR_LIEN_RSS_NOUVELLE_FENETRE, $formatdate=FORMAT_DATE) {
        $res= '';
        if ( $url!='' ) {
                $rss = fetch_rss( $url );
                if ( $titre=='' ) {$res .= '<h2>'.$rss->channel['title'].'</h2>'."\n";}
                elseif ( $titre!='0' ) {$res .= '<h2>'.$titre.'</h2>'."\n";}
                $res .= '<ul class="liste_rss">'."\n";
                $i=0;
        $nb_item=count($rss->items);
                if (($nb==0)or($nb_item<=$nb)) {
                        foreach ($rss->items as $item) {
                                $href = $item['link'];
                                $title = $item['title'];        
                                $res .= '<li class="titre_rss">'."\n";
                                if (isset($item['pubdate'])) $date=$item['pubdate'];
                                elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
                                else $formatdate='';
                                if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
                                if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
                                if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
                                if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
                $res .= '<a class="lien_rss" href="'.$href;
                                if ($nouvelle_fenetre==1) $res .=  '" onclick="window.open(this.href); return false;';
                                $res .= '">'.$title.'</a></li>'."\n";
                        }
                }
                else {
                        $i=0;
                        foreach ($rss->items as $item) {
                                $href = $item['link'];
                                $title = $item['title'];        
                                $res .= '<li class="titre_rss">'."\n";
                                if (isset($item['pubdate'])) $date=$item['pubdate'];
                                elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
                                else $formatdate='';
                                if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
                                if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
                                if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
                                if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
                $res .= '<a class="lien_rss" href="'.$href;
                                if ($nouvelle_fenetre==1) $res .=  '" onclick="window.open(this.href); return false;';
                                $res .= '">'.$title.'</a></li>'."\n";
                                $i++;
                                if ($i>=$nb) break;
                        }
                }
                $res .= '</ul>'."\n";
        }
        //echo '<pre>'.var_dump($rss->items).'</pre><br /><br />';
        return $res;
}
?>