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