Subversion Repositories Applications.papyrus

Rev

Rev 1961 | Rev 2081 | Go to most recent revision | 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+"?)|'.
2059 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
 
2059 aurelien 62
/** Inclusion du fichier de fonctions de cette application.*/
63
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'bibliotheque'.GEN_SEP.'syndication.fonct.php';
64
 
1165 jp_milcent 65
// Inclusion des fichiers de traduction de l'applette SYND de Papyrus
66
if (file_exists(SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php')) {
67
    /** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/
68
    require_once SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php';
69
} else {
70
    /** Inclusion du fichier de traduction par défaut.*/
71
    require_once SYND_CHEMIN_LANGUE.'synd_langue_'.SYND_I18N_DEFAUT.'.inc.php';
72
}
2059 aurelien 73
 
1165 jp_milcent 74
/** Inclusion du fichier de la bibliotheque permettant de manipuler les flux RSS.*/
1283 florian 75
//require_once(MAGPIE_DIR.'rss_fetch.inc');
1529 jp_milcent 76
require_once PAP_CHEMIN_API_PEAR.'XML/Feed/Parser.php';
1165 jp_milcent 77
// +------------------------------------------------------------------------------------------------------+
78
// |                                            CORPS du PROGRAMME                                        |
79
// +------------------------------------------------------------------------------------------------------+
80
/** Fonction afficherSyndication() - Retourne la liste des pages des sites syndiqués.
81
*
82
* Cette fonction retourne la liste des pages des sites syndiqués.
83
*
84
* @param  array contient les arguments de la fonction.
85
* @param  array  tableau global de Papyrus.
86
* @return string XHTML la liste des pages.
87
*/
88
function afficherSyndication($tab_applette_arguments, $_GEN_commun)
89
{
90
	// Initialisation des variables
91
    $sortie = '';
92
	$GLOBALS['_SYNDICATION_']['erreurs'] = array();
93
	$GLOBALS['_SYNDICATION_']['informations'] = array();
94
	$GLOBALS['_SYNDICATION_']['sites'] = array();
2059 aurelien 95
 
96
 
97
		$string_arguments = "";
1165 jp_milcent 98
	//+----------------------------------------------------------------------------------------------------------------+
99
	// Gestion des arguments
100
	$balise = $tab_applette_arguments[0];
101
    $tab_arguments = $tab_applette_arguments;
102
	unset($tab_arguments[0]);
103
    foreach($tab_arguments as $argument) {
104
    	if ($argument != '') {
2059 aurelien 105
	    		$string_arguments .= $argument;
1283 florian 106
	    	$tab_parametres = explode('=', $argument, 2);
1165 jp_milcent 107
	    	$options[$tab_parametres[0]] = trim($tab_parametres[1], '"');
108
    	}
109
    }
2059 aurelien 110
 
111
    $id_cache = md5($string_arguments);
112
 
113
	if($contenu_cache = verifierCache($id_cache)) {
114
		return $contenu_cache;
115
	}
1961 alexandre_ 116
	//
1165 jp_milcent 117
	//+----------------------------------------------------------------------------------------------------------------+
1283 florian 118
    // Gestion des erreurs de paramétrage
1165 jp_milcent 119
	if (!isset($options['url'])) {
120
		$GLOBALS['_SYNDICATION_']['erreurs'][] = sprintf(SYND_LG_ERREUR_URL, $balise);
121
	}
122
	if (!isset($options['titre'])) {
123
		$options['titre'] = '';
124
	}
125
	if (!isset($options['nb'])) {
126
		$options['nb'] = SYND_NOMBRE;
127
	}
2059 aurelien 128
	if (!isset($options['nbmax'])) {
129
		$options['nbmax'] = SYND_NOMBRE_MAX;
130
	}
1165 jp_milcent 131
    if (!isset($options['nouvellefenetre'])) {
132
		$options['nouvellefenetre'] = SYND_OUVRIR_LIEN_RSS_NOUVELLE_FENETRE;
133
	}
134
	if (!isset($options['formatdate'])) {
135
		$options['formatdate'] = SYND_FORMAT_DATE;
136
	}
137
	if (!isset($options['formatdatepro'])) {
1471 alexandre_ 138
		$options['formatdatepro'] = false;
1165 jp_milcent 139
	}
140
	if (!isset($options['template'])) {
141
		$options['template'] = SYND_CHEMIN_SQUELETTE.SYND_SQUELETTE_LISTE;
142
	} else {
143
		if (file_exists(SYND_CHEMIN_SQUELETTE.$options['template'])) {
144
			$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template'];
145
		}
146
	}
2059 aurelien 147
 
1165 jp_milcent 148
    //+----------------------------------------------------------------------------------------------------------------+
1283 florian 149
    // Recuperation des donnees
1165 jp_milcent 150
    if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) {
151
		$tab_url = array_map('trim', explode(',', $options['url']));
152
        foreach ($tab_url as $cle => $url) {
153
			if ($url != '') {
154
				$aso_site = array();
1745 jp_milcent 155
				// Liste des encodages acceptés pour les flux
156
				$encodages = 'UTF-8, ISO-8859-1, ISO-8859-15';
1529 jp_milcent 157
				try {
158
					$feed = new XML_Feed_Parser(file_get_contents($url));
159
				} catch (XML_Feed_Parser_Exception $e) {
1767 alexandre_ 160
					return('Le flux RSS est invalide : ' . $e->getMessage());
1529 jp_milcent 161
				}
2059 aurelien 162
 
1165 jp_milcent 163
				if ($options['template'] != '' && !file_exists($options['template'])) {
164
					$i = 0 ;
165
					$res= '';
1529 jp_milcent 166
					foreach ($feed as $item) {
1165 jp_milcent 167
						// Le test suivant pour savoir s il faut reduire l excendent de description
168
						// Si {all} est present dans le template on ne reduit pas
169
						if (preg_match ('/{all}/', $options['template'])) {
170
							$template = str_replace('{all}', '', $options['template']);
171
							$all = true ;
172
						} else {
173
							$all = false;
174
						}
1529 jp_milcent 175
						if (isset($item->summary)) {
2059 aurelien 176
							$item->description = mb_convert_encoding($item->summary, 'HTML-ENTITIES', $encodages);
1165 jp_milcent 177
						} else {
1529 jp_milcent 178
							if (strlen($item->description) > 200 && !$all) {
1745 jp_milcent 179
								$item->description = 	substr(mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), 0, 300).
180
														'... <a href="'.htmlentities($item->link).'">Lire la suite</a>';
1165 jp_milcent 181
							}
182
						}
1529 jp_milcent 183
						if (!isset($item->pubdate)) {
184
							$item->pubdate = date('dmY');
1165 jp_milcent 185
						}
1204 alexandre_ 186
						// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
187
						// lorsque les flux donne des dates au format iso
1529 jp_milcent 188
						if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item->pubdate, $match)) {
189
							$item->pubdate = $match[3].'-'.$match[2].'-'.$match[1];
1204 alexandre_ 190
							//echo $item['pubdate'];
191
						}
2059 aurelien 192
						$res .= str_replace ('{num}', ++$i,
193
								str_replace ('{item}', '<a href="'.htmlentities($item->link).'" target="_top">'.mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages).'</a>',
1529 jp_milcent 194
								str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item->pubdate)),
1745 jp_milcent 195
								str_replace ('{description}', mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), $options['template'])))) ;
1165 jp_milcent 196
						$res .= "\n";
197
						if ($i > $options['nb']) {
198
							break;
199
						}
200
					}
201
					return $res;
202
				}
203
				// Gestion du titre
204
				if ( $options['titre'] == '' ) {
1745 jp_milcent 205
					$aso_site['titre'] = mb_convert_encoding($feed->title, 'HTML-ENTITIES', $encodages);
1165 jp_milcent 206
				} else if ( $options['titre'] != '0' ) {
1529 jp_milcent 207
					$aso_site['titre'] = $options['titre'];
1165 jp_milcent 208
				}
209
				// Gestion de l'url du site
1529 jp_milcent 210
				$aso_site['url'] = htmlentities($feed->link);
211
 
1283 florian 212
				// Ouverture du lien dans une nouvelle fenetre
1165 jp_milcent 213
				$aso_site['ext'] = false;
214
				if ($options['nouvellefenetre'] == 1) {
215
					$aso_site['ext'] = true;
216
				}
1283 florian 217
				// Gestion des pages syndiquees
1165 jp_milcent 218
				$i = 0;
1529 jp_milcent 219
			    $nb_item = $feed->numberEntries;
1961 alexandre_ 220
 
1529 jp_milcent 221
				foreach ($feed as $item) {
2059 aurelien 222
 
1170 jp_milcent 223
					if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
224
						break;
225
					}
226
					$i++;
2059 aurelien 227
 
1165 jp_milcent 228
					$aso_page = array();
229
					$aso_page['site'] = $aso_site;
1745 jp_milcent 230
					$aso_page['url'] = htmlentities($item->link);
231
					$aso_page['titre'] = mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages);
1961 alexandre_ 232
					$aso_page['description'] = mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages);
233
					$aso_page['category'] = mb_convert_encoding($item->model->getElementsByTagName('category')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
234
					$aso_page['author'] = mb_convert_encoding($item->author, 'HTML-ENTITIES', $encodages);
2059 aurelien 235
					$aso_page['date'] = $item->pubDate;
1165 jp_milcent 236
					if ($options['formatdatepro']) {
1283 florian 237
						switch ($options['formatdatepro']) {
238
							case 'jm' :
1529 jp_milcent 239
								$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
1283 florian 240
								break;
241
							case 'jma' :
1529 jp_milcent 242
								$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
1283 florian 243
								break;
244
							case 'jmh' :
1529 jp_milcent 245
								$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
1283 florian 246
								break;
247
							case 'jmah' :
1529 jp_milcent 248
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
1283 florian 249
								break;
250
							default :
1529 jp_milcent 251
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
1283 florian 252
						}
1165 jp_milcent 253
					} else {
254
						switch ($options['formatdate']) {
255
							case 'jm' :
1529 jp_milcent 256
								$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
1165 jp_milcent 257
								break;
258
							case 'jma' :
1529 jp_milcent 259
								$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
1165 jp_milcent 260
								break;
261
							case 'jmh' :
1529 jp_milcent 262
								$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
1165 jp_milcent 263
								break;
264
							case 'jmah' :
1529 jp_milcent 265
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
1165 jp_milcent 266
								break;
267
							default :
1529 jp_milcent 268
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
1165 jp_milcent 269
						}
270
					}
271
					$aso_site['pages'][] = $aso_page;
272
					$GLOBALS['_SYNDICATION_']['pages'][strtotime($aso_page['date'])] = $aso_page;
273
				}
274
				$GLOBALS['_SYNDICATION_']['sites'][] = $aso_site;
275
			}
276
        }
277
    }
278
	// Trie des pages par date
279
	krsort($GLOBALS['_SYNDICATION_']['pages']);
2059 aurelien 280
 
281
	$GLOBALS['_SYNDICATION_']['sites'] = array_slice($GLOBALS['_SYNDICATION_']['sites'],0,$options['nbmax'],true) ;
282
	$GLOBALS['_SYNDICATION_']['pages'] = array_slice($GLOBALS['_SYNDICATION_']['pages'],0,$options['nbmax'],true) ;
283
 
1165 jp_milcent 284
	//+----------------------------------------------------------------------------------------------------------------+
1283 florian 285
    // Extrait les variables et les ajoutes a l'espace de noms local
1165 jp_milcent 286
	// Gestion des squelettes
287
	extract($GLOBALS['_SYNDICATION_']);
1283 florian 288
	// Demarre le buffer
1165 jp_milcent 289
	ob_start();
290
	// Inclusion du fichier
291
	include($options['template']);
1283 florian 292
	// Recuperer le  contenu du buffer
1165 jp_milcent 293
	$sortie = ob_get_contents();
2059 aurelien 294
	creer_cache($id_cache,$sortie);
1283 florian 295
	// Arrete et detruit le buffer
1165 jp_milcent 296
	ob_end_clean();
2059 aurelien 297
 
1165 jp_milcent 298
	//+----------------------------------------------------------------------------------------------------------------+
299
	// Sortie
300
    return $sortie;
301
}
302
 
303
/* +--Fin du code ----------------------------------------------------------------------------------------+
304
*
305
* $Log: not supported by cvs2svn $
1961 alexandre_ 306
* Revision 1.10  2007-12-13 14:10:51  alexandre_tb
307
* Fusion avec la livraison AHA : 13 decembre 2007
308
*
1767 alexandre_ 309
* Revision 1.9  2007-12-03 14:54:14  jp_milcent
310
* Fusion avec la livraison AHA : 3 décembre 2007
311
*
1745 jp_milcent 312
* Revision 1.7.2.2  2007-12-03 14:52:21  jp_milcent
313
* Correction bogue : & dans les urls.
314
*
315
* Revision 1.8  2007-11-30 14:17:30  jp_milcent
316
* Fusion avec la livraison AHA : 30 novembre 2007
317
*
1739 jp_milcent 318
* Revision 1.7.2.1  2007-11-30 14:15:02  jp_milcent
319
* Amélioration du décodage utf8.
320
*
321
* Revision 1.7  2007-07-25 15:09:44  jp_milcent
322
* Fusion avec la livraison Narmer.
323
*
1529 jp_milcent 324
* Revision 1.5.2.4  2007-07-25 15:07:52  jp_milcent
325
* Correction problème url.
326
*
327
* Revision 1.5.2.3  2007-07-25 14:50:21  jp_milcent
328
* Corrections, meilleure utilisation de XML_Feed_Parser.
329
*
330
* Revision 1.5.2.2  2007-07-25 09:45:07  jp_milcent
331
* Utilisation de XML_Feed_Parser de Pear pour l'applette Syndication.
332
*
333
* Revision 1.6  2007-06-25 12:15:07  alexandre_tb
334
* merge from narmer
335
*
1471 alexandre_ 336
* Revision 1.5.2.1  2007-06-06 15:24:37  jp_milcent
337
* Amélioration de la compatibilité avec les anciennes version des balises de l'applette syndication.
338
*
339
* Revision 1.5  2007-04-20 12:50:18  florian
340
* correction bugs suite au merge
341
*
1359 florian 342
* Revision 1.4  2007/03/28 15:53:27  florian
343
* correction pb date, encodage utf-8
344
*
1283 florian 345
* Revision 1.3  2007/01/23 14:17:19  alexandre_tb
346
* backport : hack pour rattraper les dates du type 01012005 parsees par magpie
347
* lorsque les flux donne des dates au format iso
348
*
1204 alexandre_ 349
* Revision 1.2  2006/12/13 17:20:51  jp_milcent
350
* Correction bogue : paramètre nb non pris en compte
351
*
1170 jp_milcent 352
* Revision 1.1  2006/12/13 17:06:36  jp_milcent
353
* Ajout de l'applette Syndication.
1165 jp_milcent 354
*
1170 jp_milcent 355
*
1165 jp_milcent 356
* +-- Fin du code ----------------------------------------------------------------------------------------+
357
*/
358
?>