Subversion Repositories Applications.papyrus

Rev

Rev 553 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
345 jpm 1
<?php
2
require_once PAP_CHEMIN_API_PEAR.'XML/RSS.php';
3
 
4
class Text_Wiki_Render_Xhtml_Syndication extends Text_Wiki_Render {
5
 
6
    /**
7
    *
8
    * Renders a token into text matching the requested format.
9
    *
10
    * @access public
11
    *
12
    * @param array $options The "options" portion of the token (second
13
    * element).
14
    *
15
    * @return string The text rendered from the token options.
16
    *
17
    */
18
 
19
    function token($options)
20
    {
21
        // Initialisation des variables
22
        $sortie = '';
735 florian 23
        $titre = $options['titre'];
345 jpm 24
        $urls = $options['url'];
735 florian 25
        $nblimite = $options['nb'];
345 jpm 26
        $tab_url = array_map('trim', explode(',', $urls));
27
        if (ini_get('allow_url_fopen') != 0) {
28
            ini_set('allow_url_fopen', 1);
29
        }
30
        if (ini_get('allow_url_fopen') != 0) {
31
            foreach ($tab_url as $cle => $url) {
735 florian 32
                $url = str_replace('&amp;', '&', $url) ;
345 jpm 33
                $rss =& new XML_RSS($url);
34
                $rss->parse();
35
                $aso_info_rss = $rss->getChannelInfo();
533 florian 36
                if ($titre!='') {
37
			$sortie .= '<h2>'.$titre.'</h2>';
38
		}
39
		elseif (isset($aso_info_rss['title'])) {
354 jpm 40
                    $sortie .= '<h2>'.$aso_info_rss['title'].'</h2>';
41
                }
42
                $sortie .= '<ul class="syndication" >'."\n";
533 florian 43
		$nbannonces=0;
44
		$tabsortie=array();
345 jpm 45
                foreach ($rss->getItems() as $item) {
533 florian 46
				$tabsortie[$nbannonces]='<li><a href="'.preg_replace ('/&/', '&amp;', $item['link']).'">'.$item['title'].'</a></li>'."\n";
47
				$nbannonces++;
345 jpm 48
                }
553 alexandre_ 49
		//affichage du nombre limité d'annonces classées de la plus récente à  la plus vieille
533 florian 50
		if ($nblimite>0) {
51
			for ($i = $nbannonces-1; (($i >= $nbannonces-$nblimite)and($i>=0)); $i--) {
52
				$sortie .= $tabsortie[$i];
53
			}
54
		}
55
		else {
56
			for ($i = $nbannonces-1; ($i>=0); $i--) {
57
				$sortie .= $tabsortie[$i];
58
			}
59
		}
60
		//si toutes les annonces n'ont pas été affichées, on propose de consulter les reste des annonces
553 alexandre_ 61
		if ($i>0) $sortie .= '<li>'.
62
							'<a href="'.$aso_info_rss['link'].'">'.
63
							'toutes les annonces</a></li>';
345 jpm 64
                $sortie .= '</ul>'."\n";
65
            }
66
        }
67
        return $sortie;
68
    }
69
}
70
?>