Subversion Repositories Applications.papyrus

Rev

Rev 553 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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