Subversion Repositories Applications.papyrus

Rev

Rev 2148 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2148 Rev 2153
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 5.1                                                                                      |
4
// | PHP version 5.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org)                                    |
6
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org)                                    |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This file is part of papyrus_bp.                                                                     |
8
// | This file is part of papyrus_bp.                                                                     |
9
// |                                                                                                      |
9
// |                                                                                                      |
10
// | Foobar is free software; you can redistribute it and/or modify                                       |
10
// | Foobar is free software; you can redistribute it and/or modify                                       |
11
// | it under the terms of the GNU General Public License as published by                                 |
11
// | it under the terms of the GNU General Public License as published by                                 |
12
// | the Free Software Foundation; either version 2 of the License, or                                    |
12
// | the Free Software Foundation; either version 2 of the License, or                                    |
13
// | (at your option) any later version.                                                                  |
13
// | (at your option) any later version.                                                                  |
14
// |                                                                                                      |
14
// |                                                                                                      |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
18
// | GNU General Public License for more details.                                                         |
18
// | GNU General Public License for more details.                                                         |
19
// |                                                                                                      |
19
// |                                                                                                      |
20
// | You should have received a copy of the GNU General Public License                                    |
20
// | You should have received a copy of the GNU General Public License                                    |
21
// | along with Foobar; if not, write to the Free Software                                                |
21
// | along with Foobar; if not, write to the Free Software                                                |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
23
// +------------------------------------------------------------------------------------------------------+
23
// +------------------------------------------------------------------------------------------------------+
24
// CVS : $Id: syndication.php,v 1.11 2008-10-29 15:55:56 alexandre_tb Exp $
24
// CVS : $Id: syndication.php,v 1.11 2008-10-29 15:55:56 alexandre_tb Exp $
25
/**
25
/**
26
* papyrus_bp - syndication.php
26
* papyrus_bp - syndication.php
27
*
27
*
28
* Description :
28
* Description :
29
*
29
*
30
*@package papyrus_bp
30
*@package papyrus_bp
31
//Auteur original :
31
//Auteur original :
32
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
32
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
33
//Autres auteurs :
33
//Autres auteurs :
34
*@author        Aucun
34
*@author        Aucun
35
*@copyright     Tela-Botanica 1999-2006
35
*@copyright     Tela-Botanica 1999-2006
36
*@version       $Revision: 1.11 $ $Date: 2008-10-29 15:55:56 $
36
*@version       $Revision: 1.11 $ $Date: 2008-10-29 15:55:56 $
37
// +------------------------------------------------------------------------------------------------------+
37
// +------------------------------------------------------------------------------------------------------+
38
*/
38
*/
39
 
39
 
40
// +------------------------------------------------------------------------------------------------------+
40
// +------------------------------------------------------------------------------------------------------+
41
// |                                            ENTÊTE du PROGRAMME                                       |
41
// |                                            ENTÊTE du PROGRAMME                                       |
42
// +------------------------------------------------------------------------------------------------------+
42
// +------------------------------------------------------------------------------------------------------+
43
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherSyndication';
43
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherSyndication';
44
$GLOBALS['_GEN_commun']['info_applette_balise'] = 	'\{\{[Ss]yndication'.
44
$GLOBALS['_GEN_commun']['info_applette_balise'] = 	'\{\{[Ss]yndication'.
45
													'(?:\s*'.
45
													'(?:\s*'.
46
														'(?:'.
46
														'(?:'.
47
															'(url="[^"]*")|'.
47
															'(url="[^"]*")|'.
48
															'(titre="[^"]*")|'.
48
															'(titre="[^"]*")|'.
49
															'(nb="?\d+"?)|'.
49
															'(nb="?\d+"?)|'.
50
															'(tailledesc="?\d+"?)|'.
50
															'(tailledesc="?\d+"?)|'.
51
															'(voirsuite="[^"]*")|'.
51
															'(voirsuite="[^"]*")|'.
52
															'(dureecache="?\d+"?)|'.
52
															'(dureecache="?\d+"?)|'.
53
															'(id="[^"]*")|'.
53
															'(id="[^"]*")|'.
54
															'(nbmax="?\d+"?)|'.
54
															'(nbmax="?\d+"?)|'.
55
															'(nouvellefenetre="?(?:0|1)"?)|'.
55
															'(nouvellefenetre="?(?:0|1)"?)|'.
56
															'(formatdate="[^"]*")|'.
56
															'(formatdate="[^"]*")|'.
57
															'(formatdatepro="[^"]*")|'.
57
															'(formatdatepro="[^"]*")|'.
58
															'(template=".*")|'.
58
															'(template=".*")|'.
59
														')'.
59
														')'.
60
													')+'.
60
													')+'.
61
													'\s*\}\}';
61
													'\s*\}\}';
62
// +------------------------------------------------------------------------------------------------------+
62
// +------------------------------------------------------------------------------------------------------+
63
/** Inclusion du fichier de configuration de cette application.*/
63
/** Inclusion du fichier de configuration de cette application.*/
64
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'configuration'.GEN_SEP.'synd_configuration.inc.php';
64
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'configuration'.GEN_SEP.'synd_configuration.inc.php';
65
 
65
 
66
/** Inclusion du fichier de fonctions de cette application.*/
66
/** Inclusion du fichier de fonctions de cette application.*/
67
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'bibliotheque'.GEN_SEP.'syndication.fonct.php';
67
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'bibliotheque'.GEN_SEP.'syndication.fonct.php';
68
 
68
 
69
// Inclusion des fichiers de traduction de l'applette SYND de Papyrus
69
// Inclusion des fichiers de traduction de l'applette SYND de Papyrus
70
if (file_exists(SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php')) {
70
if (file_exists(SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php')) {
71
    /** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/
71
    /** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/
72
    require_once SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php';
72
    require_once SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php';
73
} else {
73
} else {
74
    /** Inclusion du fichier de traduction par défaut.*/
74
    /** Inclusion du fichier de traduction par défaut.*/
75
    require_once SYND_CHEMIN_LANGUE.'synd_langue_'.SYND_I18N_DEFAUT.'.inc.php';
75
    require_once SYND_CHEMIN_LANGUE.'synd_langue_'.SYND_I18N_DEFAUT.'.inc.php';
76
}
76
}
77
 
77
 
78
/** Inclusion du fichier de la bibliotheque permettant de manipuler les flux RSS.*/
78
/** Inclusion du fichier de la bibliotheque permettant de manipuler les flux RSS.*/
79
//require_once(MAGPIE_DIR.'rss_fetch.inc');
79
//require_once(MAGPIE_DIR.'rss_fetch.inc');
80
require_once PAP_CHEMIN_API_PEAR.'XML/Feed/Parser.php';
80
require_once PAP_CHEMIN_API_PEAR.'XML/Feed/Parser.php';
81
// +------------------------------------------------------------------------------------------------------+
81
// +------------------------------------------------------------------------------------------------------+
82
// |                                            CORPS du PROGRAMME                                        |
82
// |                                            CORPS du PROGRAMME                                        |
83
// +------------------------------------------------------------------------------------------------------+
83
// +------------------------------------------------------------------------------------------------------+
84
 
84
 
85
// l'applette est un peu teubée et ne comprend pas certains flux
85
// l'applette est un peu teubée et ne comprend pas certains flux
86
// pourtant valides, par sécurité, on supprime donc certains caractères
86
// pourtant valides, par sécurité, on supprime donc certains caractères
87
function supprimerXmlDangereux($xml)
87
function supprimerXmlDangereux($xml)
88
{
88
{
89
    $ret = "";
89
    $ret = "";
90
    $encours;
90
    $encours;
91
    if (empty($xml)) 
91
    if (empty($xml)) 
92
    {
92
    {
93
        return $ret;
93
        return $ret;
94
    }
94
    }
95
 
95
 
96
    $lg = strlen($xml);
96
    $lg = strlen($xml);
97
    for ($i=0; $i < $lg; $i++)
97
    for ($i=0; $i < $lg; $i++)
98
    {
98
    {
99
        $encours = ord($xml{$i});
99
        $encours = ord($xml{$i});
100
        if (($encours == 0x9) ||
100
        if (($encours == 0x9) ||
101
            ($encours == 0xA) ||
101
            ($encours == 0xA) ||
102
            ($encours == 0xD) ||
102
            ($encours == 0xD) ||
103
            (($encours >= 0x20) && ($encours <= 0xD7FF)) ||
103
            (($encours >= 0x20) && ($encours <= 0xD7FF)) ||
104
            (($encours >= 0xE000) && ($encours <= 0xFFFD)) ||
104
            (($encours >= 0xE000) && ($encours <= 0xFFFD)) ||
105
            (($encours >= 0x10000) && ($encours <= 0x10FFFF)))
105
            (($encours >= 0x10000) && ($encours <= 0x10FFFF)))
106
        {
106
        {
107
            $ret .= chr($encours);
107
            $ret .= chr($encours);
108
        }
108
        }
109
        else
109
        else
110
        {
110
        {
111
            $ret .= " ";
111
            $ret .= " ";
112
        }
112
        }
113
    }
113
    }
114
    return $ret;
114
    return $ret;
115
}
115
}
116
 
116
 
117
/** Fonction afficherSyndication() - Retourne la liste des pages des sites syndiqués.
117
/** Fonction afficherSyndication() - Retourne la liste des pages des sites syndiqués.
118
*
118
*
119
* Cette fonction retourne la liste des pages des sites syndiqués.
119
* Cette fonction retourne la liste des pages des sites syndiqués.
120
*
120
*
121
* @param  array contient les arguments de la fonction.
121
* @param  array contient les arguments de la fonction.
122
* @param  array  tableau global de Papyrus.
122
* @param  array  tableau global de Papyrus.
123
* @return string XHTML la liste des pages.
123
* @return string XHTML la liste des pages.
124
*/
124
*/
125
function afficherSyndication($tab_applette_arguments, $_GEN_commun)
125
function afficherSyndication($tab_applette_arguments, $_GEN_commun)
126
{
126
{
127
	// Initialisation des variables
127
	// Initialisation des variables
128
    $sortie = '';
128
    $sortie = '';
129
	$GLOBALS['_SYNDICATION_']['erreurs'] = array();
129
	$GLOBALS['_SYNDICATION_']['erreurs'] = array();
130
	$GLOBALS['_SYNDICATION_']['informations'] = array();
130
	$GLOBALS['_SYNDICATION_']['informations'] = array();
131
	$GLOBALS['_SYNDICATION_']['sites'] = array();
131
	$GLOBALS['_SYNDICATION_']['sites'] = array();
132
 
132
 
133
 
133
 
134
		$string_arguments = "";
134
		$string_arguments = "";
135
	//+----------------------------------------------------------------------------------------------------------------+
135
	//+----------------------------------------------------------------------------------------------------------------+
136
	// Gestion des arguments
136
	// Gestion des arguments
137
	$balise = $tab_applette_arguments[0];
137
	$balise = $tab_applette_arguments[0];
138
    $tab_arguments = $tab_applette_arguments;
138
    $tab_arguments = $tab_applette_arguments;
139
 
139
 
140
	unset($tab_arguments[0]);
140
	unset($tab_arguments[0]);
141
    foreach($tab_arguments as $argument) {
141
    foreach($tab_arguments as $argument) {
142
    	if ($argument != '') {
142
    	if ($argument != '') {
143
	    		$string_arguments .= $argument;
143
	    		$string_arguments .= $argument;
144
	    	$tab_parametres = explode('=', $argument, 2);
144
	    	$tab_parametres = explode('=', $argument, 2);
145
	    	$options[$tab_parametres[0]] = trim($tab_parametres[1], '"');
145
	    	$options[$tab_parametres[0]] = trim($tab_parametres[1], '"');
146
    	}
146
    	}
147
    }
147
    }
148
 
148
 
149
    $id_cache = md5($string_arguments);
149
    $id_cache = md5($string_arguments);
150
	//Greg : possibilité d'ajouter une durée au cache
150
	//Greg : possibilité d'ajouter une durée au cache
151
	if (!isset($options['dureecache'])) {
151
	if (!isset($options['dureecache'])) {
152
		$options['dureecache'] = CACHE_LIFETIME;
152
		$options['dureecache'] = CACHE_LIFETIME;
153
	}
153
	}
154
 
154
 
155
	if($contenu_cache = verifierCache($id_cache, $options['dureecache'])) {
155
	if($contenu_cache = verifierCache($id_cache, $options['dureecache'])) {
156
		return $contenu_cache;
156
		return $contenu_cache;
157
	}
157
	}
158
	//
158
	//
159
	//+----------------------------------------------------------------------------------------------------------------+
159
	//+----------------------------------------------------------------------------------------------------------------+
160
    // Gestion des erreurs de paramétrage
160
    // Gestion des erreurs de paramétrage
161
 
161
 
162
	if (!isset($options['url'])) {
162
	if (!isset($options['url'])) {
163
		$GLOBALS['_SYNDICATION_']['erreurs'][] = sprintf(SYND_LG_ERREUR_URL, $balise);
163
		$GLOBALS['_SYNDICATION_']['erreurs'][] = sprintf(SYND_LG_ERREUR_URL, $balise);
164
	}
164
	}
165
	if (!isset($options['titre'])) {
165
	if (!isset($options['titre'])) {
166
		$options['titre'] = '';
166
		$options['titre'] = '';
167
	}
167
	}
168
	if (!isset($options['nb'])) {
168
	if (!isset($options['nb'])) {
169
		$options['nb'] = SYND_NOMBRE;
169
		$options['nb'] = SYND_NOMBRE;
170
	}
170
	}
171
	if (!isset($options['nbmax'])) {
171
	if (!isset($options['nbmax'])) {
172
		$options['nbmax'] = SYND_NOMBRE_MAX;
172
		$options['nbmax'] = SYND_NOMBRE_MAX;
173
	}
173
	}
174
    	if (!isset($options['nouvellefenetre'])) {
174
    	if (!isset($options['nouvellefenetre'])) {
175
		$options['nouvellefenetre'] = SYND_OUVRIR_LIEN_RSS_NOUVELLE_FENETRE;
175
		$options['nouvellefenetre'] = SYND_OUVRIR_LIEN_RSS_NOUVELLE_FENETRE;
176
	}
176
	}
177
	if (!isset($options['formatdate'])) {
177
	if (!isset($options['formatdate'])) {
178
		$options['formatdate'] = SYND_FORMAT_DATE;
178
		$options['formatdate'] = SYND_FORMAT_DATE;
179
	}
179
	}
180
	if (!isset($options['formatdatepro'])) {
180
	if (!isset($options['formatdatepro'])) {
181
		$options['formatdatepro'] = false;
181
		$options['formatdatepro'] = false;
182
	}
182
	}
183
	if (!isset($options['template'])) {
183
	if (!isset($options['template'])) {
184
		$options['template'] = SYND_CHEMIN_SQUELETTE.SYND_SQUELETTE_LISTE;
184
		$options['template'] = SYND_CHEMIN_SQUELETTE.SYND_SQUELETTE_LISTE;
185
	} else {
185
	} else {
186
		if (file_exists(SYND_CHEMIN_SQUELETTE.$options['template'])) {
186
		if (file_exists(SYND_CHEMIN_SQUELETTE.$options['template'])) {
187
			$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template'];
187
			$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template'];
188
		}
188
		}
189
	}
189
	}
190
 
190
 
191
 
191
 
192
 
192
 
193
 
193
 
194
    //+----------------------------------------------------------------------------------------------------------------+
194
    //+----------------------------------------------------------------------------------------------------------------+
195
    // Recuperation des donnees
195
    // Recuperation des donnees
196
    if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) {
196
    if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) {
197
		$tab_url = array_map('trim', explode(',', $options['url']));
197
		$tab_url = array_map('trim', explode(',', $options['url']));
198
        foreach ($tab_url as $cle => $url) {
198
        foreach ($tab_url as $cle => $url) {
199
			if ($url != '') {
199
			if ($url != '') {
200
				$aso_site = array();
200
				$aso_site = array();
201
				// Liste des encodages acceptés pour les flux
201
				// Liste des encodages acceptés pour les flux
202
				$encodages = 'UTF-8, ISO-8859-1, ISO-8859-15';
202
				$encodages = 'UTF-8, ISO-8859-1, ISO-8859-15';
203
				try {
203
				try {
204
					$xml = file_get_contents($url);
204
					$xml = file_get_contents($url);
205
					$xml = supprimerXmlDangereux($xml);
205
					$xml = supprimerXmlDangereux($xml);
206
					$feed = new XML_Feed_Parser($xml);
206
					$feed = new XML_Feed_Parser($xml);
207
				} catch (XML_Feed_Parser_Exception $e) {
207
				} catch (XML_Feed_Parser_Exception $e) {
208
					creer_cache('erreur', $xml, 86400);
208
					creer_cache('erreur', $xml, 86400);
209
					return('Le flux RSS est invalide : ' . $e->getMessage());
209
					return('Le flux RSS est invalide : ' . $e->getMessage());
210
				}
210
				}
211
 
211
 
212
				if ($options['template'] != '' && !file_exists($options['template'])) {
212
				if ($options['template'] != '' && !file_exists($options['template'])) {
213
					$i = 0 ;
213
					$i = 0 ;
214
					$res= '';
214
					$res= '';
215
					foreach ($feed as $item) {
215
					foreach ($feed as $item) {
216
						// Le test suivant pour savoir s il faut reduire l excendent de description
216
						// Le test suivant pour savoir s il faut reduire l excendent de description
217
						// Si {all} est present dans le template on ne reduit pas
217
						// Si {all} est present dans le template on ne reduit pas
218
						if (preg_match ('/{all}/', $options['template'])) {
218
						if (preg_match ('/{all}/', $options['template'])) {
219
							$template = str_replace('{all}', '', $options['template']);
219
							$template = str_replace('{all}', '', $options['template']);
220
							$all = true ;
220
							$all = true ;
221
						} else {
221
						} else {
222
							$all = false;
222
							$all = false;
223
						}
223
						}
224
						if (isset($item->summary)) {
224
						if (isset($item->summary)) {
225
							$item->description = mb_convert_encoding($item->summary, 'HTML-ENTITIES', $encodages);
225
							$item->description = mb_convert_encoding($item->summary, 'HTML-ENTITIES', $encodages);
226
						} else {
226
						} else {
227
							if (strlen($item->description) > 200 && !$all) {
227
							if (strlen($item->description) > 200 && !$all) {
228
								$item->description = 	substr(mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), 0, 300).
228
								$item->description = 	substr(mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), 0, 300).
229
														'... <a href="'.htmlentities($item->link).'">Lire la suite</a>';
229
														'... <a href="'.htmlentities($item->link).'">Lire la suite</a>';
230
							}
230
							}
231
						}
231
						}
232
						if (!isset($item->pubdate)) {
232
						if (!isset($item->pubdate)) {
233
							$item->pubdate = date('dmY');
233
							$item->pubdate = date('dmY');
234
						}
234
						}
235
						// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
235
						// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
236
						// lorsque les flux donne des dates au format iso
236
						// lorsque les flux donne des dates au format iso
237
						if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item->pubdate, $match)) {
237
						if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item->pubdate, $match)) {
238
							$item->pubdate = $match[3].'-'.$match[2].'-'.$match[1];
238
							$item->pubdate = $match[3].'-'.$match[2].'-'.$match[1];
239
							//echo $item['pubdate'];
239
							//echo $item['pubdate'];
240
						}
240
						}
241
						$res .= str_replace ('{num}', ++$i,
241
						$res .= str_replace ('{num}', ++$i,
242
								str_replace ('{item}', '<a href="'.htmlentities($item->link).'" target="_top">'.mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages).'</a>',
242
								str_replace ('{item}', '<a href="'.htmlentities($item->link).'" target="_top">'.mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages).'</a>',
243
								str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item->pubdate)),
243
								str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item->pubdate)),
244
								str_replace ('{description}', mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), $options['template'])))) ;
244
								str_replace ('{description}', mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), $options['template'])))) ;
245
						$res .= "\n";
245
						$res .= "\n";
246
						if ($i > $options['nb']) {
246
						if ($i > $options['nb']) {
247
							break;
247
							break;
248
						}
248
						}
249
					}
249
					}
250
					return $res;
250
					return $res;
251
				}
251
				}
252
				// Gestion du titre
252
				// Gestion du titre
253
				if ( $options['titre'] == '' ) {
253
				if ( $options['titre'] == '' ) {
254
					$aso_site['titre'] = mb_convert_encoding($feed->title, 'HTML-ENTITIES', $encodages);
254
					$aso_site['titre'] = mb_convert_encoding($feed->title, 'HTML-ENTITIES', $encodages);
255
				} else if ( $options['titre'] != '0' ) {
255
				} else if ( $options['titre'] != '0' ) {
256
					$aso_site['titre'] = $options['titre'];
256
					$aso_site['titre'] = $options['titre'];
257
				}
257
				}
258
 
258
 
259
				//Gestion de l'ID
259
				//Gestion de l'ID
260
				if ( $options['id'] != '' ) {
260
				if ( $options['id'] != '' ) {
261
					$aso_site['id'] = $options['id'];
261
					$aso_site['id'] = $options['id'];
262
				}
262
				}
263
 
263
 
264
				//Gestion du lien vers la suite
264
				//Gestion du lien vers la suite
265
				if ( $options['voirsuite'] != '' ) {
265
				if ( $options['voirsuite'] != '' ) {
266
					$aso_site['voirsuite'] = $options['voirsuite'];
266
					$aso_site['voirsuite'] = $options['voirsuite'];
267
				}
267
				}
268
 
268
 
269
				// Gestion de l'url du site
269
				// Gestion de l'url du site
270
				$aso_site['url'] = htmlentities($feed->link);
270
				$aso_site['url'] = htmlentities($feed->link);
271
 
271
 
272
				// Ouverture du lien dans une nouvelle fenetre
272
				// Ouverture du lien dans une nouvelle fenetre
273
				$aso_site['ext'] = false;
273
				$aso_site['ext'] = false;
274
				if ($options['nouvellefenetre'] == 1) {
274
				if ($options['nouvellefenetre'] == 1) {
275
					$aso_site['ext'] = true;
275
					$aso_site['ext'] = true;
276
				}
276
				}
277
				// Gestion des pages syndiquees
277
				// Gestion des pages syndiquees
278
				$i = 0;
278
				$i = 0;
279
			    $nb_item = $feed->numberEntries;
279
			    $nb_item = $feed->numberEntries;
280
 
280
 
281
				foreach ($feed as $item) {
281
				foreach ($feed as $item) {
282
 
282
 
283
					if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
283
					if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
284
						break;
284
						break;
285
					}
285
					}
286
					$i++;
286
					$i++;
287
 
287
 
288
					$aso_page = array();
288
					$aso_page = array();
289
					$aso_page['site'] = $aso_site;
289
					$aso_page['site'] = $aso_site;
290
					$aso_page['url'] = htmlentities($item->link);
290
					$aso_page['url'] = htmlentities($item->link);
291
					$aso_page['titre'] = mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages);
291
					$aso_page['titre'] = mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages);
292
					$aso_page['description'] = mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages);
292
					$aso_page['description'] = mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages);
293
 
293
 
294
					/* Extraction de l'image si incluse dans description */
294
					/* Extraction de l'image si incluse dans description */
295
					$image = "";
295
					$image = "";
296
					$description = $aso_page['description'];
296
					$description = $aso_page['description'];
297
 
297
 
298
					$taille = $options['tailledesc'];
298
					$taille = $options['tailledesc'];
299
 
299
 
300
					if (!(strpos($description, '<img') === false))	{
300
					if (!(strpos($description, '<img') === false))	{
301
						$pos_debut = strpos($description, '<img');
301
						$pos_debut = strpos($description, '<img');
302
						$pos_fin_image = strpos($description, '>', $posimage) + 1;
302
						$pos_fin_image = strpos($description, '>', $posimage) + 1;
303
						$image = substr($description, $pos_debut, ($pos_fin_image - $pos_debut));
303
						$image = substr($description, $pos_debut, ($pos_fin_image - $pos_debut));
304
						$description = substr_replace($description,' ', $pos_debut,  ($pos_fin_image - $pos_debut));
304
						$description = substr_replace($description,' ', $pos_debut,  ($pos_fin_image - $pos_debut));
305
					}
305
					}
306
 
306
 
307
					$aso_page['image'] = $image;
307
					$aso_page['image'] = $image;
308
					$aso_page['description_sans_image'] = $description;
308
					$aso_page['description_sans_image'] = $description;
309
 
309
 
310
					if ($taille != null)	{
310
					if ($taille != null)	{
311
 
311
 
312
						//Attention : si on coupe simplement, on peut couper une balise en plein milieu.
312
						//Attention : si on coupe simplement, on peut couper une balise en plein milieu.
313
						//On va donc vérifier
313
						//On va donc vérifier
314
						//1. recherche de tags simples <i> ou <b>
314
						//1. recherche de tags simples <i> ou <b>
315
						$description = html_entity_decode($description);
315
						$description = html_entity_decode($description);
316
						$description = strip_tags($description, "<i><b>");
316
						$description = strip_tags($description, "<i><b>");
317
 
317
 
318
						//Va-ton couper un mot ?
318
						//Va-ton couper un mot ?
319
 
319
 
320
						if ($description[$taille] != ' ' && $description[$taille+1] != ' ' && $description[$taille-1] != ' ')	{
320
						if ($description[$taille] != ' ' && $description[$taille+1] != ' ' && $description[$taille-1] != ' ')	{
321
  								$strpos = strpos($description, ' ', $taille);
321
  								$strpos = strpos($description, ' ', $taille);
322
  								if ($strpos === true)	{
322
  								if ($strpos === true)	{
323
  									$taille = $strpos;
323
  									$taille = $strpos;
324
  								}
324
  								}
325
  						}
325
  						}
326
 
326
 
327
 
327
 
328
						$description = substr($description, 0, $taille);
328
						$description = substr($description, 0, $taille);
329
						$description.='(...)';
329
						$description.='(...)';
330
 
330
 
331
						$pattern = '#<([ib])[ ]*[a-z]*>(.*?)</\1>#i';
331
						$pattern = '#<([ib])[ ]*[a-z]*>(.*?)</\1>#i';
332
						//1. remplacer toutes le	s balises fermées
332
						//1. remplacer toutes le	s balises fermées
333
						$chaine = preg_replace($pattern, '$2', $description);
333
						$chaine = preg_replace($pattern, '$2', $description);
334
						$nb_occurences_i = substr_count($chaine, '<i');
334
						$nb_occurences_i = substr_count($chaine, '<i');
335
						for ($occurences = 0; $occurences < $nb_occurences_i; $occurences++)	{
335
						for ($occurences = 0; $occurences < $nb_occurences_i; $occurences++)	{
336
							$description .= "</i>";
336
							$description .= "</i>";
337
						}
337
						}
338
 
338
 
339
						$nb_occurences_b = substr_count($chaine, '<b');
339
						$nb_occurences_b = substr_count($chaine, '<b');
340
						for ($occurences = 0; $occurences < $nb_occurences_b; $occurences++)	{
340
						for ($occurences = 0; $occurences < $nb_occurences_b; $occurences++)	{
341
							$description .= "</b>";
341
							$description .= "</b>";
342
						}
342
						}
343
					}
343
					}
344
 
344
 
345
					$aso_page['description_light'] = $description;
345
					$aso_page['description_light'] = $description;
346
 
346
 
347
					//Greg : ajout GUID
347
					//Greg : ajout GUID
348
					$aso_page['guid'] = mb_convert_encoding($item->model->getElementsByTagName('guid')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
348
					$aso_page['guid'] = mb_convert_encoding($item->model->getElementsByTagName('guid')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
349
 
349
 
350
					$aso_page['category'] = mb_convert_encoding($item->model->getElementsByTagName('category')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
350
					$aso_page['category'] = mb_convert_encoding($item->model->getElementsByTagName('category')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
351
					$aso_page['author'] = mb_convert_encoding($item->author, 'HTML-ENTITIES', $encodages);
351
					$aso_page['author'] = mb_convert_encoding($item->author, 'HTML-ENTITIES', $encodages);
-
 
352
 
-
 
353
					// Remplacement de $item->pubDate (bool false -> pquoi ?) par $item->published
-
 
354
					// Marche pour le flux des comm & prop IdentiPlante, sur la page d'accueil du monde Botanique
352
 
-
 
353
 
355
					$aso_page['date'] = $item->published;
354
					$aso_page['date'] = $item->pubDate;
356
 
355
					if ($options['formatdatepro']) {
357
					if ($options['formatdatepro']) {
356
						switch ($options['formatdatepro']) {
358
						switch ($options['formatdatepro']) {
357
							case 'jm' :
359
							case 'jm' :
358
								$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
360
								$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
359
								break;
361
								break;
360
							case 'jma' :
362
							case 'jma' :
361
								$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
363
								$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
362
								break;
364
								break;
363
							case 'jmh' :
365
							case 'jmh' :
364
								$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
366
								$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
365
								break;
367
								break;
366
							case 'jmah' :
368
							case 'jmah' :
367
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
369
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
368
								break;
370
								break;
369
							default :
371
							default :
370
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
372
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
371
						}
373
						}
372
					} else {
374
					} else {
373
						switch ($options['formatdate']) {
375
						switch ($options['formatdate']) {
374
							case 'jm' :
376
							case 'jm' :
375
								$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
377
								$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
376
								break;
378
								break;
377
							case 'jma' :
379
							case 'jma' :
378
								$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
380
								$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
379
								break;
381
								break;
380
							case 'jmh' :
382
							case 'jmh' :
381
								$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
383
								$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
382
								break;
384
								break;
383
							case 'jmah' :
385
							case 'jmah' :
384
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
386
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
385
								break;
387
								break;
386
							default :
388
							default :
387
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
389
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
388
						}
390
						}
389
					}
391
					}
390
					$aso_site['pages'][] = $aso_page;
392
					$aso_site['pages'][] = $aso_page;
391
					$GLOBALS['_SYNDICATION_']['pages'][strtotime($aso_page['date'])] = $aso_page;
393
					$GLOBALS['_SYNDICATION_']['pages'][strtotime($aso_page['date'])] = $aso_page;
392
				}
394
				}
393
				$GLOBALS['_SYNDICATION_']['sites'][] = $aso_site;
395
				$GLOBALS['_SYNDICATION_']['sites'][] = $aso_site;
394
			}
396
			}
395
        }
397
        }
396
    }
398
    }
397
	// Trie des pages par date
399
	// Trie des pages par date
398
	krsort($GLOBALS['_SYNDICATION_']['pages']);
400
	krsort($GLOBALS['_SYNDICATION_']['pages']);
399
 
401
 
400
	$GLOBALS['_SYNDICATION_']['sites'] = array_slice($GLOBALS['_SYNDICATION_']['sites'],0,$options['nbmax'],true) ;
402
	$GLOBALS['_SYNDICATION_']['sites'] = array_slice($GLOBALS['_SYNDICATION_']['sites'],0,$options['nbmax'],true) ;
401
	$GLOBALS['_SYNDICATION_']['pages'] = array_slice($GLOBALS['_SYNDICATION_']['pages'],0,$options['nbmax'],true) ;
403
	$GLOBALS['_SYNDICATION_']['pages'] = array_slice($GLOBALS['_SYNDICATION_']['pages'],0,$options['nbmax'],true) ;
402
 
404
 
403
	//+----------------------------------------------------------------------------------------------------------------+
405
	//+----------------------------------------------------------------------------------------------------------------+
404
    // Extrait les variables et les ajoutes a l'espace de noms local
406
    // Extrait les variables et les ajoutes a l'espace de noms local
405
	// Gestion des squelettes
407
	// Gestion des squelettes
406
	extract($GLOBALS['_SYNDICATION_']);
408
	extract($GLOBALS['_SYNDICATION_']);
407
	// Demarre le buffer
409
	// Demarre le buffer
408
	ob_start();
410
	ob_start();
409
	// Inclusion du fichier
411
	// Inclusion du fichier
410
	include($options['template']);
412
	include($options['template']);
411
	// Recuperer le  contenu du buffer
413
	// Recuperer le  contenu du buffer
412
	$sortie = ob_get_contents();
414
	$sortie = ob_get_contents();
413
	creer_cache($id_cache,$sortie, $options['dureecache']);
415
	creer_cache($id_cache,$sortie, $options['dureecache']);
414
	// Arrete et detruit le buffer
416
	// Arrete et detruit le buffer
415
	ob_end_clean();
417
	ob_end_clean();
416
 
418
 
417
	//+----------------------------------------------------------------------------------------------------------------+
419
	//+----------------------------------------------------------------------------------------------------------------+
418
	// Sortie
420
	// Sortie
419
    return $sortie;
421
    return $sortie;
420
}
422
}
421
 
423
 
422
function transcribe_cp1252_to_latin1($cp1252) {
424
function transcribe_cp1252_to_latin1($cp1252) {
423
  return strtr(
425
  return strtr(
424
    $cp1252,
426
    $cp1252,
425
    array(
427
    array(
426
      "\x80" => "e",  "\x81" => " ",    "\x82" => "'", "\x83" => 'f',
428
      "\x80" => "e",  "\x81" => " ",    "\x82" => "'", "\x83" => 'f',
427
      "\x84" => '"',  "\x85" => "...",  "\x86" => "+", "\x87" => "#",
429
      "\x84" => '"',  "\x85" => "...",  "\x86" => "+", "\x87" => "#",
428
      "\x88" => "^",  "\x89" => "0/00", "\x8A" => "S", "\x8B" => "<",
430
      "\x88" => "^",  "\x89" => "0/00", "\x8A" => "S", "\x8B" => "<",
429
      "\x8C" => "OE", "\x8D" => " ",    "\x8E" => "Z", "\x8F" => " ",
431
      "\x8C" => "OE", "\x8D" => " ",    "\x8E" => "Z", "\x8F" => " ",
430
      "\x90" => " ",  "\x91" => "`",    "\x92" => "'", "\x93" => '"',
432
      "\x90" => " ",  "\x91" => "`",    "\x92" => "'", "\x93" => '"',
431
      "\x94" => '"',  "\x95" => "*",    "\x96" => "-", "\x97" => "--",
433
      "\x94" => '"',  "\x95" => "*",    "\x96" => "-", "\x97" => "--",
432
      "\x98" => "~",  "\x99" => "(TM)", "\x9A" => "s", "\x9B" => ">",
434
      "\x98" => "~",  "\x99" => "(TM)", "\x9A" => "s", "\x9B" => ">",
433
      "\x9C" => "oe", "\x9D" => " ",    "\x9E" => "z", "\x9F" => "Y"));
435
      "\x9C" => "oe", "\x9D" => " ",    "\x9E" => "z", "\x9F" => "Y"));
434
}
436
}
435
 
437
 
436
/* +--Fin du code ----------------------------------------------------------------------------------------+
438
/* +--Fin du code ----------------------------------------------------------------------------------------+
437
*
439
*
438
* $Log: not supported by cvs2svn $
440
* $Log: not supported by cvs2svn $
439
* Revision 1.10  2007-12-13 14:10:51  alexandre_tb
441
* Revision 1.10  2007-12-13 14:10:51  alexandre_tb
440
* Fusion avec la livraison AHA : 13 decembre 2007
442
* Fusion avec la livraison AHA : 13 decembre 2007
441
*
443
*
442
* Revision 1.9  2007-12-03 14:54:14  jp_milcent
444
* Revision 1.9  2007-12-03 14:54:14  jp_milcent
443
* Fusion avec la livraison AHA : 3 décembre 2007
445
* Fusion avec la livraison AHA : 3 décembre 2007
444
*
446
*
445
* Revision 1.7.2.2  2007-12-03 14:52:21  jp_milcent
447
* Revision 1.7.2.2  2007-12-03 14:52:21  jp_milcent
446
* Correction bogue : & dans les urls.
448
* Correction bogue : & dans les urls.
447
*
449
*
448
* Revision 1.8  2007-11-30 14:17:30  jp_milcent
450
* Revision 1.8  2007-11-30 14:17:30  jp_milcent
449
* Fusion avec la livraison AHA : 30 novembre 2007
451
* Fusion avec la livraison AHA : 30 novembre 2007
450
*
452
*
451
* Revision 1.7.2.1  2007-11-30 14:15:02  jp_milcent
453
* Revision 1.7.2.1  2007-11-30 14:15:02  jp_milcent
452
* Amélioration du décodage utf8.
454
* Amélioration du décodage utf8.
453
*
455
*
454
* Revision 1.7  2007-07-25 15:09:44  jp_milcent
456
* Revision 1.7  2007-07-25 15:09:44  jp_milcent
455
* Fusion avec la livraison Narmer.
457
* Fusion avec la livraison Narmer.
456
*
458
*
457
* Revision 1.5.2.4  2007-07-25 15:07:52  jp_milcent
459
* Revision 1.5.2.4  2007-07-25 15:07:52  jp_milcent
458
* Correction problème url.
460
* Correction problème url.
459
*
461
*
460
* Revision 1.5.2.3  2007-07-25 14:50:21  jp_milcent
462
* Revision 1.5.2.3  2007-07-25 14:50:21  jp_milcent
461
* Corrections, meilleure utilisation de XML_Feed_Parser.
463
* Corrections, meilleure utilisation de XML_Feed_Parser.
462
*
464
*
463
* Revision 1.5.2.2  2007-07-25 09:45:07  jp_milcent
465
* Revision 1.5.2.2  2007-07-25 09:45:07  jp_milcent
464
* Utilisation de XML_Feed_Parser de Pear pour l'applette Syndication.
466
* Utilisation de XML_Feed_Parser de Pear pour l'applette Syndication.
465
*
467
*
466
* Revision 1.6  2007-06-25 12:15:07  alexandre_tb
468
* Revision 1.6  2007-06-25 12:15:07  alexandre_tb
467
* merge from narmer
469
* merge from narmer
468
*
470
*
469
* Revision 1.5.2.1  2007-06-06 15:24:37  jp_milcent
471
* Revision 1.5.2.1  2007-06-06 15:24:37  jp_milcent
470
* Amélioration de la compatibilité avec les anciennes version des balises de l'applette syndication.
472
* Amélioration de la compatibilité avec les anciennes version des balises de l'applette syndication.
471
*
473
*
472
* Revision 1.5  2007-04-20 12:50:18  florian
474
* Revision 1.5  2007-04-20 12:50:18  florian
473
* correction bugs suite au merge
475
* correction bugs suite au merge
474
*
476
*
475
* Revision 1.4  2007/03/28 15:53:27  florian
477
* Revision 1.4  2007/03/28 15:53:27  florian
476
* correction pb date, encodage utf-8
478
* correction pb date, encodage utf-8
477
*
479
*
478
* Revision 1.3  2007/01/23 14:17:19  alexandre_tb
480
* Revision 1.3  2007/01/23 14:17:19  alexandre_tb
479
* backport : hack pour rattraper les dates du type 01012005 parsees par magpie
481
* backport : hack pour rattraper les dates du type 01012005 parsees par magpie
480
* lorsque les flux donne des dates au format iso
482
* lorsque les flux donne des dates au format iso
481
*
483
*
482
* Revision 1.2  2006/12/13 17:20:51  jp_milcent
484
* Revision 1.2  2006/12/13 17:20:51  jp_milcent
483
* Correction bogue : paramètre nb non pris en compte
485
* Correction bogue : paramètre nb non pris en compte
484
*
486
*
485
* Revision 1.1  2006/12/13 17:06:36  jp_milcent
487
* Revision 1.1  2006/12/13 17:06:36  jp_milcent
486
* Ajout de l'applette Syndication.
488
* Ajout de l'applette Syndication.
487
*
489
*
488
*
490
*
489
* +-- Fin du code ----------------------------------------------------------------------------------------+
491
* +-- Fin du code ----------------------------------------------------------------------------------------+
490
*/
492
*/
491
?>
493
?>