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 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
8 |
// | This file is part of papyrus_bp. |
|
|
|
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 |
// +------------------------------------------------------------------------------------------------------+
|
1204 |
alexandre_ |
24 |
// CVS : $Id: syndication.php,v 1.3 2007-01-23 14:17:19 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
|
1204 |
alexandre_ |
36 |
*@version $Revision: 1.3 $ $Date: 2007-01-23 14:17:19 $
|
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="[^"]*")|'.
|
|
|
49 |
'(nb=(?:"|)\d+(?:"|))|'.
|
|
|
50 |
'(nouvellefenetre=(?:"|)(?:0|1)(?:"|))|'.
|
|
|
51 |
'(formatdate="[^"]*")|'.
|
|
|
52 |
'(formatdatepro="[^"]*")|'.
|
|
|
53 |
'(template="[^"]*")|'.
|
|
|
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.*/
|
|
|
70 |
require_once(MAGPIE_DIR.'rss_fetch.inc');
|
|
|
71 |
|
|
|
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 != '') {
|
|
|
98 |
$tab_parametres = explode('=', $argument);
|
|
|
99 |
$options[$tab_parametres[0]] = trim($tab_parametres[1], '"');
|
|
|
100 |
}
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
104 |
// Gestion des erreurs de paramètrage
|
|
|
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'])) {
|
|
|
121 |
$options['formatdatepro'] = SYND_FORMAT_DATE;
|
|
|
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 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
132 |
// Récupération des données
|
|
|
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();
|
|
|
138 |
$url = str_replace('&', '&', $url) ;
|
|
|
139 |
$rss = fetch_rss($url);
|
|
|
140 |
//echo '<pre>'.print_r($rss, true).'</pre>';
|
|
|
141 |
if ($options['template'] != '' && !file_exists($options['template'])) {
|
|
|
142 |
$i = 0 ;
|
|
|
143 |
$res= '';
|
|
|
144 |
foreach ($rss->items as $item) {
|
|
|
145 |
// Le test suivant pour savoir s il faut reduire l excendent de description
|
|
|
146 |
// Si {all} est present dans le template on ne reduit pas
|
|
|
147 |
if (preg_match ('/{all}/', $options['template'])) {
|
|
|
148 |
$template = str_replace('{all}', '', $options['template']);
|
|
|
149 |
$all = true ;
|
|
|
150 |
} else {
|
|
|
151 |
$all = false;
|
|
|
152 |
}
|
|
|
153 |
if (isset($item['summary'])) {
|
|
|
154 |
$item['description'] = $item['summary'];
|
|
|
155 |
} else {
|
|
|
156 |
if (strlen($item['description']) > 200 && !$all) {
|
|
|
157 |
$item['description'] = substr ($item['description'] , 0, 300).
|
|
|
158 |
'... <a href="'.$item['link'].'">Lire la suite</a>';
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
if (!isset($item['pubdate'])) {
|
|
|
162 |
$item['pubdate'] = date('dmY');
|
|
|
163 |
}
|
1204 |
alexandre_ |
164 |
// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
|
|
|
165 |
// lorsque les flux donne des dates au format iso
|
|
|
166 |
if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item['pubdate'], $match)) {
|
|
|
167 |
$item['pubdate'] = $match[3].'-'.$match[2].'-'.$match[1];
|
|
|
168 |
//echo $item['pubdate'];
|
|
|
169 |
}
|
1165 |
jp_milcent |
170 |
$res .= str_replace ('{num}', ++$i,
|
|
|
171 |
str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>',
|
|
|
172 |
str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])),
|
|
|
173 |
str_replace ('{description}', $item['description'], $options['template'])))) ;
|
|
|
174 |
$res .= "\n";
|
|
|
175 |
if ($i > $options['nb']) {
|
|
|
176 |
break;
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
return $res;
|
|
|
180 |
}
|
|
|
181 |
// Gestion du titre
|
|
|
182 |
if ( $options['titre'] == '' ) {
|
|
|
183 |
$aso_site['titre'] = $rss->channel['title'];
|
|
|
184 |
} else if ( $options['titre'] != '0' ) {
|
|
|
185 |
$aso_site['titre'] = $options['titre'];
|
|
|
186 |
}
|
|
|
187 |
// Gestion de l'url du site
|
|
|
188 |
if (isset($rss->channel['link'])) {
|
|
|
189 |
$aso_site['url'] = $rss->channel['link'];
|
|
|
190 |
}
|
|
|
191 |
// Ouverture du lien dans une nouvelle fenêtre
|
|
|
192 |
$aso_site['ext'] = false;
|
|
|
193 |
if ($options['nouvellefenetre'] == 1) {
|
|
|
194 |
$aso_site['ext'] = true;
|
|
|
195 |
}
|
|
|
196 |
// Gestion des pages syndiquées
|
|
|
197 |
$i = 0;
|
|
|
198 |
$nb_item = count($rss->items);
|
|
|
199 |
foreach ($rss->items as $item) {
|
1170 |
jp_milcent |
200 |
if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
|
|
|
201 |
break;
|
|
|
202 |
}
|
|
|
203 |
$i++;
|
1165 |
jp_milcent |
204 |
$aso_page = array();
|
|
|
205 |
$aso_page['site'] = $aso_site;
|
|
|
206 |
$aso_page['url'] = $item['link'];
|
|
|
207 |
$aso_page['titre'] = $item['title'];
|
|
|
208 |
if (isset($item['pubdate'])) {
|
|
|
209 |
$aso_page['date'] = $item['pubdate'];
|
|
|
210 |
} elseif (isset($item['date'])) {
|
|
|
211 |
$aso_page['date'] = $item['date'];
|
|
|
212 |
} elseif (isset($item['date_timestamp'])) {
|
|
|
213 |
$aso_page['date'] = $item['date_timestamp'];
|
|
|
214 |
} else {
|
|
|
215 |
$aso_page['date'] = '';
|
|
|
216 |
}
|
|
|
217 |
if ($options['formatdatepro']) {
|
|
|
218 |
$aso_page['date'] = strftime($options['formatdatepro'], strtotime($aso_page['date']));
|
|
|
219 |
} else {
|
|
|
220 |
switch ($options['formatdate']) {
|
|
|
221 |
case 'jm' :
|
|
|
222 |
$aso_page['date'] = strftime('%d.%m', strtotime($aso_page['date']));
|
|
|
223 |
break;
|
|
|
224 |
case 'jma' :
|
|
|
225 |
$aso_page['date'] = strftime('%d.%m.%Y', strtotime($aso_page['date']));
|
|
|
226 |
break;
|
|
|
227 |
case 'jmh' :
|
|
|
228 |
$aso_page['date'] = strftime('%d.%m %H:%M', strtotime($aso_page['date']));
|
|
|
229 |
break;
|
|
|
230 |
case 'jmah' :
|
|
|
231 |
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date']));
|
|
|
232 |
break;
|
|
|
233 |
default :
|
|
|
234 |
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date']));
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
$aso_site['pages'][] = $aso_page;
|
|
|
238 |
$GLOBALS['_SYNDICATION_']['pages'][strtotime($aso_page['date'])] = $aso_page;
|
|
|
239 |
}
|
|
|
240 |
$GLOBALS['_SYNDICATION_']['sites'][] = $aso_site;
|
|
|
241 |
}
|
|
|
242 |
}
|
|
|
243 |
}
|
|
|
244 |
// Trie des pages par date
|
|
|
245 |
krsort($GLOBALS['_SYNDICATION_']['pages']);
|
|
|
246 |
|
|
|
247 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
248 |
// Extrait les variables et les ajoutes à l'espace de noms local
|
|
|
249 |
// Gestion des squelettes
|
|
|
250 |
extract($GLOBALS['_SYNDICATION_']);
|
|
|
251 |
// Démarre le buffer
|
|
|
252 |
ob_start();
|
|
|
253 |
// Inclusion du fichier
|
|
|
254 |
include($options['template']);
|
|
|
255 |
// Récupérer le contenu du buffer
|
|
|
256 |
$sortie = ob_get_contents();
|
|
|
257 |
// Arrête et détruit le buffer
|
|
|
258 |
ob_end_clean();
|
|
|
259 |
|
|
|
260 |
//+----------------------------------------------------------------------------------------------------------------+
|
|
|
261 |
// Sortie
|
|
|
262 |
return $sortie;
|
|
|
263 |
}
|
|
|
264 |
|
|
|
265 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
266 |
*
|
|
|
267 |
* $Log: not supported by cvs2svn $
|
1204 |
alexandre_ |
268 |
* Revision 1.2 2006/12/13 17:20:51 jp_milcent
|
|
|
269 |
* Correction bogue : paramètre nb non pris en compte
|
|
|
270 |
*
|
1170 |
jp_milcent |
271 |
* Revision 1.1 2006/12/13 17:06:36 jp_milcent
|
|
|
272 |
* Ajout de l'applette Syndication.
|
1165 |
jp_milcent |
273 |
*
|
1170 |
jp_milcent |
274 |
*
|
1165 |
jp_milcent |
275 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
276 |
*/
|
|
|
277 |
?>
|