Subversion Repositories Applications.papyrus

Rev

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

Rev 1203 Rev 1232
1
<?php
1
<?php
-
 
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
-
 
3
// +------------------------------------------------------------------------------------------------------+
-
 
4
// | PHP version 4.1                                                                                      |
-
 
5
// +------------------------------------------------------------------------------------------------------+
-
 
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
-
 
7
// +------------------------------------------------------------------------------------------------------+
-
 
8
// | This library is free software; you can redistribute it and/or                                        |
-
 
9
// | modify it under the terms of the GNU Lesser General Public                                           |
-
 
10
// | License as published by the Free Software Foundation; either                                         |
-
 
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
-
 
12
// |                                                                                                      |
-
 
13
// | This library is distributed in the hope that it will be useful,                                      |
-
 
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
-
 
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
-
 
16
// | Lesser General Public License for more details.                                                      |
-
 
17
// |                                                                                                      |
-
 
18
// | You should have received a copy of the GNU Lesser General Public                                     |
-
 
19
// | License along with this library; if not, write to the Free Software                                  |
-
 
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
-
 
21
// +------------------------------------------------------------------------------------------------------+
-
 
22
// CVS : $Id$
-
 
23
/**
-
 
24
*
-
 
25
* Fonctions du module rss de papyrus
-
 
26
* 
-
 
27
*
-
 
28
*@package syndication_rss
-
 
29
//Auteur original :
-
 
30
*@author        Alexandre Granier <alexandre@tela-botanica.org>
-
 
31
*@author        Florian Schmitt <florian@ecole-et-nature.org>
-
 
32
//Autres auteurs :
-
 
33
*@copyright     Tela-Botanica 2000-2007
-
 
34
*@version       $Revision$
-
 
35
// +------------------------------------------------------------------------------------------------------+
-
 
36
*/
2
 
37
 
3
define('MAGPIE_DIR', GEN_CHEMIN_API.'syndication_rss/magpierss/');
38
define('MAGPIE_DIR', GEN_CHEMIN_API.'syndication_rss/magpierss/');
4
define('MAGPIE_CACHE_DIR', MAGPIE_DIR.'tmp/magpie_cache');
39
define('MAGPIE_CACHE_DIR', MAGPIE_DIR.'tmp/magpie_cache');
5
define('OUVRIR_LIEN_RSS_NOUVELLE_FENETRE', 1);
40
define('OUVRIR_LIEN_RSS_NOUVELLE_FENETRE', 1);
6
define('FORMAT_DATE', 'jma');
41
define('FORMAT_DATE', 'jma');
7
require_once(MAGPIE_DIR.'rss_fetch.inc');
42
require_once(MAGPIE_DIR.'rss_fetch.inc');
8
 
43
 
9
function voir_rss($titre='', $url='', $nb=0, $nouvelle_fenetre=OUVRIR_LIEN_RSS_NOUVELLE_FENETRE, $formatdate=FORMAT_DATE, $template = "") {
44
function voir_rss($titre='', $url='', $nb=0, $nouvelle_fenetre=OUVRIR_LIEN_RSS_NOUVELLE_FENETRE, $formatdate=FORMAT_DATE, $template = "") {
10
	$res= '';
45
	$res= '';
11
	if ( $url!='' ) {
46
	if ( $url!='' ) {
12
		$rss = fetch_rss( $url );
47
		$rss = fetch_rss( $url );
13
		
48
		
14
		if ($template != "") {
49
		if ($template != "") {
15
			$i = 0 ;
50
			$i = 0 ;
16
			foreach ($rss->items as $item) {
51
			foreach ($rss->items as $item) {
17
				// Le test suivant pour savoir s il faut reduire l excendent de description
52
				// 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
53
				// Si {all} est present dans le template on ne reduit pas
19
				if (preg_match ('/{all}/', $template)) {
54
				if (preg_match ('/{all}/', $template)) {
20
					$template = str_replace('{all}', '', $template);
55
					$template = str_replace('{all}', '', $template);
21
					$all = true ;
56
					$all = true ;
22
				} else {
57
				} else {
23
					$all = false;
58
					$all = false;
24
				}
59
				}
25
				if (strlen($item['description']) > 200 && !$all) {
60
				if (strlen($item['description']) > 200 && !$all) {
26
					$item['description'] = substr ($item['description'] , 0, 300).'... <a href="'.$item['link'].'">Lire la suite</a>';
61
					$item['description'] = substr ($item['description'] , 0, 300).'... <a href="'.$item['link'].'">Lire la suite</a>';
27
				}
62
				}
28
				if (!isset($item['pubdate'])) $item['pubdate'] = date('dmY');
63
				if (!isset($item['pubdate'])) $item['pubdate'] = date('dmY');
29
				
64
				
30
				// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
65
				// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
31
				// lorsque les flux donne des dates au format iso
66
				// lorsque les flux donne des dates au format iso
32
				if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item['pubdate'], $match)) {
67
				if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item['pubdate'], $match)) {
33
					$item['pubdate'] = $match[3].'-'.$match[2].'-'.$match[1];
68
					$item['pubdate'] = $match[3].'-'.$match[2].'-'.$match[1];
34
					//echo $item['pubdate'];
69
					//echo $item['pubdate'];
35
				}
70
				}
36
				$res .= str_replace ('{num}', ++$i, 
71
				$res .= str_replace ('{num}', ++$i, 
37
						str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>', 
72
						str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>', 
38
						str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])),
73
						str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])),
39
						str_replace ('{description}', $item['description'], $template)))) ;
74
						str_replace ('{description}', $item['description'], $template)))) ;
40
				$res .= "\n";
75
				$res .= "\n";
41
				if ($i > $nb) break;
76
				if ($i > $nb) break;
42
				
77
				
43
			}
78
			}
44
			return $res ;
79
			return $res ;
45
		}
80
		}
46
		if ( $titre=='' ) {$res .= '<h2>'.$rss->channel['title'].'</h2>'."\n";}
81
		if ( $titre=='' ) {$res .= '<h2>'.$rss->channel['title'].'</h2>'."\n";}
47
		elseif ( $titre!='0' ) {$res .= '<h2>'.$titre.'</h2>'."\n";}
82
		elseif ( $titre!='0' ) {$res .= '<h2>'.$titre.'</h2>'."\n";}
48
		$res .= '<ul class="liste_rss">'."\n";
83
		$res .= '<ul class="liste_rss">'."\n";
49
		$i=0;
84
		$i=0;
50
        $nb_item=count($rss->items);
85
        $nb_item=count($rss->items);
51
		if (($nb==0)or($nb_item<=$nb)) {
86
		if (($nb==0)or($nb_item<=$nb)) {
52
			foreach ($rss->items as $item) {
87
			foreach ($rss->items as $item) {
53
				$href = $item['link'];
88
				$href = $item['link'];
54
				$title = $item['title'];	
89
				$title = $item['title'];	
55
				$res .= '<li class="titre_rss">'."\n";
90
				$res .= '<li class="titre_rss">'."\n";
56
				if (isset($item['pubdate'])) $date=$item['pubdate'];
91
				if (isset($item['pubdate'])) $date=$item['pubdate'];
57
				elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
92
				elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
58
				else $formatdate='';
93
				else $formatdate='';
59
				if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
94
				if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
60
				if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
95
				if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
61
				if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
96
				if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
62
				if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
97
				if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
63
                $res .= '<a class="lien_rss" href="'.$href;
98
                $res .= '<a class="lien_rss" href="'.$href;
64
        	               	if ($nouvelle_fenetre==1) $res .=  '" onclick="window.open(this.href); return false;';
99
        	               	if ($nouvelle_fenetre==1) $res .=  '" onclick="window.open(this.href); return false;';
65
				$res .= '">'.$title.'</a></li>'."\n";
100
				$res .= '">'.$title.'</a></li>'."\n";
66
			}
101
			}
67
		}
102
		}
68
		else {
103
		else {
69
			$i=0;
104
			$i=0;
70
			foreach ($rss->items as $item) {
105
			foreach ($rss->items as $item) {
71
				$href = $item['link'];
106
				$href = $item['link'];
72
				$title = $item['title'];	
107
				$title = $item['title'];	
73
				$res .= '<li class="titre_rss">'."\n";
108
				$res .= '<li class="titre_rss">'."\n";
74
				if (isset($item['pubdate'])) $date=$item['pubdate'];
109
				if (isset($item['pubdate'])) $date=$item['pubdate'];
75
				elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
110
				elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
76
				else $formatdate='';
111
				else $formatdate='';
77
				if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
112
				if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
78
				if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
113
				if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
79
				if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
114
				if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
80
				if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
115
				if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
81
                $res .= '<a class="lien_rss" href="'.$href;
116
                $res .= '<a class="lien_rss" href="'.$href;
82
        	               	if ($nouvelle_fenetre==1) $res .=  '" onclick="window.open(this.href); return false;';
117
        	               	if ($nouvelle_fenetre==1) $res .=  '" onclick="window.open(this.href); return false;';
83
				$res .= '">'.$title.'</a></li>'."\n";
118
				$res .= '">'.$title.'</a></li>'."\n";
84
				$i++;
119
				$i++;
85
				if ($i>=$nb) break;
120
				if ($i>=$nb) break;
86
			}
121
			}
87
		}
122
		}
88
		$res .= '</ul>'."\n";
123
		$res .= '</ul>'."\n";
89
	}
124
	}
90
        //echo '<pre>'.var_dump($rss->items).'</pre><br /><br />';
125
        //echo '<pre>'.var_dump($rss->items).'</pre><br /><br />';
91
	return $res;
126
	return $res;
92
}
127
}
93
?>
128
?>