Subversion Repositories Applications.papyrus

Rev

Rev 1988 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1165 jp_milcent 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 5.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org)                                    |
7
// +------------------------------------------------------------------------------------------------------+
1283 florian 8
// | This file is part of papyrus_bp.                                                                     |
1165 jp_milcent 9
// |                                                                                                      |
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                                 |
12
// | the Free Software Foundation; either version 2 of the License, or                                    |
13
// | (at your option) any later version.                                                                  |
14
// |                                                                                                      |
15
// | Foobar is distributed in the hope that it will be useful,                                            |
16
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
17
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                        |
18
// | GNU General Public License for more details.                                                         |
19
// |                                                                                                      |
20
// | You should have received a copy of the GNU General Public License                                    |
21
// | along with Foobar; if not, write to the Free Software                                                |
22
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
23
// +------------------------------------------------------------------------------------------------------+
1961 alexandre_ 24
// CVS : $Id: syndication.php,v 1.11 2008-10-29 15:55:56 alexandre_tb Exp $
1165 jp_milcent 25
/**
26
* papyrus_bp - syndication.php
27
*
28
* Description :
29
*
30
*@package papyrus_bp
31
//Auteur original :
32
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
33
//Autres auteurs :
34
*@author        Aucun
35
*@copyright     Tela-Botanica 1999-2006
1961 alexandre_ 36
*@version       $Revision: 1.11 $ $Date: 2008-10-29 15:55:56 $
1165 jp_milcent 37
// +------------------------------------------------------------------------------------------------------+
38
*/
39
 
40
// +------------------------------------------------------------------------------------------------------+
41
// |                                            ENTÊTE du PROGRAMME                                       |
42
// +------------------------------------------------------------------------------------------------------+
43
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherSyndication';
44
$GLOBALS['_GEN_commun']['info_applette_balise'] = 	'\{\{[Ss]yndication'.
45
													'(?:\s*'.
46
														'(?:'.
47
															'(url="[^"]*")|'.
48
															'(titre="[^"]*")|'.
1471 alexandre_ 49
															'(nb="?\d+"?)|'.
1998 Aurelien 50
															'(nbmax="?\d+"?)|'.
1471 alexandre_ 51
															'(nouvellefenetre="?(?:0|1)"?)|'.
1165 jp_milcent 52
															'(formatdate="[^"]*")|'.
53
															'(formatdatepro="[^"]*")|'.
1471 alexandre_ 54
															'(template=".*")|'.
1165 jp_milcent 55
														')'.
56
													')+'.
57
													'\s*\}\}';
58
// +------------------------------------------------------------------------------------------------------+
59
/** Inclusion du fichier de configuration de cette application.*/
60
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'configuration'.GEN_SEP.'synd_configuration.inc.php';
61
 
62
// Inclusion des fichiers de traduction de l'applette SYND de Papyrus
63
if (file_exists(SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php')) {
64
    /** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/
65
    require_once SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php';
66
} else {
67
    /** Inclusion du fichier de traduction par défaut.*/
68
    require_once SYND_CHEMIN_LANGUE.'synd_langue_'.SYND_I18N_DEFAUT.'.inc.php';
69
}
70
/** Inclusion du fichier de la bibliotheque permettant de manipuler les flux RSS.*/
1283 florian 71
//require_once(MAGPIE_DIR.'rss_fetch.inc');
1529 jp_milcent 72
require_once PAP_CHEMIN_API_PEAR.'XML/Feed/Parser.php';
1165 jp_milcent 73
// +------------------------------------------------------------------------------------------------------+
74
// |                                            CORPS du PROGRAMME                                        |
75
// +------------------------------------------------------------------------------------------------------+
76
/** Fonction afficherSyndication() - Retourne la liste des pages des sites syndiqués.
77
*
78
* Cette fonction retourne la liste des pages des sites syndiqués.
79
*
80
* @param  array contient les arguments de la fonction.
81
* @param  array  tableau global de Papyrus.
82
* @return string XHTML la liste des pages.
83
*/
84
function afficherSyndication($tab_applette_arguments, $_GEN_commun)
85
{
86
	// Initialisation des variables
87
    $sortie = '';
88
	$GLOBALS['_SYNDICATION_']['erreurs'] = array();
89
	$GLOBALS['_SYNDICATION_']['informations'] = array();
90
	$GLOBALS['_SYNDICATION_']['sites'] = array();
91
 
92
	//+----------------------------------------------------------------------------------------------------------------+
93
	// Gestion des arguments
94
	$balise = $tab_applette_arguments[0];
95
    $tab_arguments = $tab_applette_arguments;
96
	unset($tab_arguments[0]);
97
    foreach($tab_arguments as $argument) {
98
    	if ($argument != '') {
1283 florian 99
	    	$tab_parametres = explode('=', $argument, 2);
1165 jp_milcent 100
	    	$options[$tab_parametres[0]] = trim($tab_parametres[1], '"');
101
    	}
102
    }
1961 alexandre_ 103
	//
1165 jp_milcent 104
	//+----------------------------------------------------------------------------------------------------------------+
1283 florian 105
    // Gestion des erreurs de paramétrage
1165 jp_milcent 106
	if (!isset($options['url'])) {
107
		$GLOBALS['_SYNDICATION_']['erreurs'][] = sprintf(SYND_LG_ERREUR_URL, $balise);
108
	}
109
	if (!isset($options['titre'])) {
110
		$options['titre'] = '';
111
	}
112
	if (!isset($options['nb'])) {
113
		$options['nb'] = SYND_NOMBRE;
114
	}
1998 Aurelien 115
	if (!isset($options['nbmax'])) {
116
		$options['nbmax'] = SYND_NOMBRE_MAX;
117
	}
1165 jp_milcent 118
    if (!isset($options['nouvellefenetre'])) {
119
		$options['nouvellefenetre'] = SYND_OUVRIR_LIEN_RSS_NOUVELLE_FENETRE;
120
	}
121
	if (!isset($options['formatdate'])) {
122
		$options['formatdate'] = SYND_FORMAT_DATE;
123
	}
124
	if (!isset($options['formatdatepro'])) {
1471 alexandre_ 125
		$options['formatdatepro'] = false;
1165 jp_milcent 126
	}
127
	if (!isset($options['template'])) {
128
		$options['template'] = SYND_CHEMIN_SQUELETTE.SYND_SQUELETTE_LISTE;
129
	} else {
130
		if (file_exists(SYND_CHEMIN_SQUELETTE.$options['template'])) {
131
			$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template'];
132
		}
133
	}
134
 
135
    //+----------------------------------------------------------------------------------------------------------------+
1283 florian 136
    // Recuperation des donnees
1165 jp_milcent 137
    if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) {
138
		$tab_url = array_map('trim', explode(',', $options['url']));
139
        foreach ($tab_url as $cle => $url) {
140
			if ($url != '') {
141
				$aso_site = array();
1745 jp_milcent 142
				// Liste des encodages acceptés pour les flux
143
				$encodages = 'UTF-8, ISO-8859-1, ISO-8859-15';
1529 jp_milcent 144
				try {
145
					$feed = new XML_Feed_Parser(file_get_contents($url));
146
				} catch (XML_Feed_Parser_Exception $e) {
1767 alexandre_ 147
					return('Le flux RSS est invalide : ' . $e->getMessage());
1529 jp_milcent 148
				}
149
 
1165 jp_milcent 150
				if ($options['template'] != '' && !file_exists($options['template'])) {
151
					$i = 0 ;
152
					$res= '';
1529 jp_milcent 153
					foreach ($feed as $item) {
1165 jp_milcent 154
						// Le test suivant pour savoir s il faut reduire l excendent de description
155
						// Si {all} est present dans le template on ne reduit pas
156
						if (preg_match ('/{all}/', $options['template'])) {
157
							$template = str_replace('{all}', '', $options['template']);
158
							$all = true ;
159
						} else {
160
							$all = false;
161
						}
1529 jp_milcent 162
						if (isset($item->summary)) {
1745 jp_milcent 163
							$item->description = mb_convert_encoding($item->summary, 'HTML-ENTITIES', $encodages);
1165 jp_milcent 164
						} else {
1529 jp_milcent 165
							if (strlen($item->description) > 200 && !$all) {
1745 jp_milcent 166
								$item->description = 	substr(mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), 0, 300).
167
														'... <a href="'.htmlentities($item->link).'">Lire la suite</a>';
1165 jp_milcent 168
							}
169
						}
1529 jp_milcent 170
						if (!isset($item->pubdate)) {
171
							$item->pubdate = date('dmY');
1165 jp_milcent 172
						}
1204 alexandre_ 173
						// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
174
						// lorsque les flux donne des dates au format iso
1529 jp_milcent 175
						if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item->pubdate, $match)) {
176
							$item->pubdate = $match[3].'-'.$match[2].'-'.$match[1];
1204 alexandre_ 177
							//echo $item['pubdate'];
178
						}
1165 jp_milcent 179
						$res .= str_replace ('{num}', ++$i,
1745 jp_milcent 180
								str_replace ('{item}', '<a href="'.htmlentities($item->link).'" target="_top">'.mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages).'</a>',
1529 jp_milcent 181
								str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item->pubdate)),
1745 jp_milcent 182
								str_replace ('{description}', mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), $options['template'])))) ;
1165 jp_milcent 183
						$res .= "\n";
184
						if ($i > $options['nb']) {
185
							break;
186
						}
187
					}
188
					return $res;
189
				}
190
				// Gestion du titre
191
				if ( $options['titre'] == '' ) {
1745 jp_milcent 192
					$aso_site['titre'] = mb_convert_encoding($feed->title, 'HTML-ENTITIES', $encodages);
1165 jp_milcent 193
				} else if ( $options['titre'] != '0' ) {
1529 jp_milcent 194
					$aso_site['titre'] = $options['titre'];
1165 jp_milcent 195
				}
196
				// Gestion de l'url du site
1529 jp_milcent 197
				$aso_site['url'] = htmlentities($feed->link);
198
 
1283 florian 199
				// Ouverture du lien dans une nouvelle fenetre
1165 jp_milcent 200
				$aso_site['ext'] = false;
201
				if ($options['nouvellefenetre'] == 1) {
202
					$aso_site['ext'] = true;
203
				}
1283 florian 204
				// Gestion des pages syndiquees
1165 jp_milcent 205
				$i = 0;
1529 jp_milcent 206
			    $nb_item = $feed->numberEntries;
1961 alexandre_ 207
 
1529 jp_milcent 208
				foreach ($feed as $item) {
1961 alexandre_ 209
 
1170 jp_milcent 210
					if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
211
						break;
212
					}
213
					$i++;
1961 alexandre_ 214
 
1165 jp_milcent 215
					$aso_page = array();
216
					$aso_page['site'] = $aso_site;
1745 jp_milcent 217
					$aso_page['url'] = htmlentities($item->link);
218
					$aso_page['titre'] = mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages);
1961 alexandre_ 219
					$aso_page['description'] = mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages);
220
					$aso_page['category'] = mb_convert_encoding($item->model->getElementsByTagName('category')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
221
					$aso_page['author'] = mb_convert_encoding($item->author, 'HTML-ENTITIES', $encodages);
1529 jp_milcent 222
					$aso_page['date'] = $item->pubDate;
1165 jp_milcent 223
					if ($options['formatdatepro']) {
1283 florian 224
						switch ($options['formatdatepro']) {
225
							case 'jm' :
1529 jp_milcent 226
								$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
1283 florian 227
								break;
228
							case 'jma' :
1529 jp_milcent 229
								$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
1283 florian 230
								break;
231
							case 'jmh' :
1529 jp_milcent 232
								$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
1283 florian 233
								break;
234
							case 'jmah' :
1529 jp_milcent 235
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
1283 florian 236
								break;
237
							default :
1529 jp_milcent 238
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
1283 florian 239
						}
1165 jp_milcent 240
					} else {
241
						switch ($options['formatdate']) {
242
							case 'jm' :
1529 jp_milcent 243
								$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
1165 jp_milcent 244
								break;
245
							case 'jma' :
1529 jp_milcent 246
								$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
1165 jp_milcent 247
								break;
248
							case 'jmh' :
1529 jp_milcent 249
								$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
1165 jp_milcent 250
								break;
251
							case 'jmah' :
1529 jp_milcent 252
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
1165 jp_milcent 253
								break;
254
							default :
1529 jp_milcent 255
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
1165 jp_milcent 256
						}
257
					}
258
					$aso_site['pages'][] = $aso_page;
259
					$GLOBALS['_SYNDICATION_']['pages'][strtotime($aso_page['date'])] = $aso_page;
260
				}
261
				$GLOBALS['_SYNDICATION_']['sites'][] = $aso_site;
262
			}
263
        }
264
    }
265
	// Trie des pages par date
266
	krsort($GLOBALS['_SYNDICATION_']['pages']);
1998 Aurelien 267
268
	$GLOBALS['_SYNDICATION_']['sites'] = array_slice($GLOBALS['_SYNDICATION_']['sites'],0,$options['nbmax'],true) ;
269
	$GLOBALS['_SYNDICATION_']['pages'] = array_slice($GLOBALS['_SYNDICATION_']['pages'],0,$options['nbmax'],true) ;
1165 jp_milcent 270
 
271
	//+----------------------------------------------------------------------------------------------------------------+
1283 florian 272
    // Extrait les variables et les ajoutes a l'espace de noms local
1165 jp_milcent 273
	// Gestion des squelettes
274
	extract($GLOBALS['_SYNDICATION_']);
1283 florian 275
	// Demarre le buffer
1165 jp_milcent 276
	ob_start();
277
	// Inclusion du fichier
278
	include($options['template']);
1283 florian 279
	// Recuperer le  contenu du buffer
1165 jp_milcent 280
	$sortie = ob_get_contents();
1283 florian 281
	// Arrete et detruit le buffer
1165 jp_milcent 282
	ob_end_clean();
283
 
284
	//+----------------------------------------------------------------------------------------------------------------+
285
	// Sortie
286
    return $sortie;
287
}
288
 
289
/* +--Fin du code ----------------------------------------------------------------------------------------+
290
*
291
* $Log: not supported by cvs2svn $
1961 alexandre_ 292
* Revision 1.10  2007-12-13 14:10:51  alexandre_tb
293
* Fusion avec la livraison AHA : 13 decembre 2007
294
*
1767 alexandre_ 295
* Revision 1.9  2007-12-03 14:54:14  jp_milcent
296
* Fusion avec la livraison AHA : 3 décembre 2007
297
*
1745 jp_milcent 298
* Revision 1.7.2.2  2007-12-03 14:52:21  jp_milcent
299
* Correction bogue : & dans les urls.
300
*
301
* Revision 1.8  2007-11-30 14:17:30  jp_milcent
302
* Fusion avec la livraison AHA : 30 novembre 2007
303
*
1739 jp_milcent 304
* Revision 1.7.2.1  2007-11-30 14:15:02  jp_milcent
305
* Amélioration du décodage utf8.
306
*
307
* Revision 1.7  2007-07-25 15:09:44  jp_milcent
308
* Fusion avec la livraison Narmer.
309
*
1529 jp_milcent 310
* Revision 1.5.2.4  2007-07-25 15:07:52  jp_milcent
311
* Correction problème url.
312
*
313
* Revision 1.5.2.3  2007-07-25 14:50:21  jp_milcent
314
* Corrections, meilleure utilisation de XML_Feed_Parser.
315
*
316
* Revision 1.5.2.2  2007-07-25 09:45:07  jp_milcent
317
* Utilisation de XML_Feed_Parser de Pear pour l'applette Syndication.
318
*
319
* Revision 1.6  2007-06-25 12:15:07  alexandre_tb
320
* merge from narmer
321
*
1471 alexandre_ 322
* Revision 1.5.2.1  2007-06-06 15:24:37  jp_milcent
323
* Amélioration de la compatibilité avec les anciennes version des balises de l'applette syndication.
324
*
325
* Revision 1.5  2007-04-20 12:50:18  florian
326
* correction bugs suite au merge
327
*
1359 florian 328
* Revision 1.4  2007/03/28 15:53:27  florian
329
* correction pb date, encodage utf-8
330
*
1283 florian 331
* Revision 1.3  2007/01/23 14:17:19  alexandre_tb
332
* backport : hack pour rattraper les dates du type 01012005 parsees par magpie
333
* lorsque les flux donne des dates au format iso
334
*
1204 alexandre_ 335
* Revision 1.2  2006/12/13 17:20:51  jp_milcent
336
* Correction bogue : paramètre nb non pris en compte
337
*
1170 jp_milcent 338
* Revision 1.1  2006/12/13 17:06:36  jp_milcent
339
* Ajout de l'applette Syndication.
1165 jp_milcent 340
*
1170 jp_milcent 341
*
1165 jp_milcent 342
* +-- Fin du code ----------------------------------------------------------------------------------------+
343
*/
344
?>