Subversion Repositories Applications.papyrus

Rev

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

<?php

define('MAGPIE_DIR', GEN_CHEMIN_API.'syndication_rss/magpierss/');
define('MAGPIE_CACHE_DIR', MAGPIE_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, $template = "") {
        $res= '';
        if ( $url!='' ) {
                $rss = fetch_rss( $url );
                if ($template != "") {
                        $res = ""; $i = 0 ;
                        foreach ($rss->items as $item) {
                                // Le test suivant pour savoir s il faut reduire l excendent de description
                                // Si {all} est present dans le template on ne reduit pas
                                if (preg_match ('/{all}/', $template)) {
                                        $template = str_replace('{all}', '', $template);
                                        $all = true ;
                                }
                                if (strlen($item['description']) > 200 && !$all) {
                                        $item['description'] = substr ($item['description'] , 0, 300).'... <a href="'.$item['link'].'">Lire la suite</a>';
                                }
                                $res .= str_replace ('{num}', ++$i, 
                                                str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>', 
                                                str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])),
                                                str_replace ('{description}', $item['description'], $template)))) ;
                                $res .= "\n";
                                if ($i >= $nb) break;
                                
                        }
                        return $res ;
                }
                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;
}
?>