Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
// +------------------------------------------------------------------------------------------------------+
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
// +------------------------------------------------------------------------------------------------------+
24
// CVS : $Id: syndication.php,v 1.1 2006-12-13 17:06:36 jp_milcent Exp $
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
36
*@version       $Revision: 1.1 $ $Date: 2006-12-13 17:06:36 $
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('&amp;', '&', $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
						}
164
						$res .= str_replace ('{num}', ++$i,
165
								str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>',
166
								str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])),
167
								str_replace ('{description}', $item['description'], $options['template'])))) ;
168
						$res .= "\n";
169
						if ($i > $options['nb']) {
170
							break;
171
						}
172
					}
173
					return $res;
174
				}
175
				// Gestion du titre
176
				if ( $options['titre'] == '' ) {
177
					$aso_site['titre'] = $rss->channel['title'];
178
				} else if ( $options['titre'] != '0' ) {
179
					$aso_site['titre'] = $options['titre'];
180
				}
181
				// Gestion de l'url du site
182
				if (isset($rss->channel['link'])) {
183
					$aso_site['url'] = $rss->channel['link'];
184
				}
185
				// Ouverture du lien dans une nouvelle fenêtre
186
				$aso_site['ext'] = false;
187
				if ($options['nouvellefenetre'] == 1) {
188
					$aso_site['ext'] = true;
189
				}
190
				// Gestion des pages syndiquées
191
				$i = 0;
192
			    $nb_item = count($rss->items);
193
 
194
				foreach ($rss->items as $item) {
195
					$aso_page = array();
196
					$aso_page['site'] = $aso_site;
197
					$aso_page['url'] = $item['link'];
198
					$aso_page['titre'] = $item['title'];
199
					if (isset($item['pubdate'])) {
200
						$aso_page['date'] = $item['pubdate'];
201
					} elseif (isset($item['date'])) {
202
						$aso_page['date'] = $item['date'];
203
					} elseif (isset($item['date_timestamp'])) {
204
						$aso_page['date'] = $item['date_timestamp'];
205
					} else {
206
						$aso_page['date'] = '';
207
					}
208
					if ($options['formatdatepro']) {
209
						$aso_page['date'] = strftime($options['formatdatepro'], strtotime($aso_page['date']));
210
					} else {
211
						switch ($options['formatdate']) {
212
							case 'jm' :
213
								$aso_page['date'] = strftime('%d.%m', strtotime($aso_page['date']));
214
								break;
215
							case 'jma' :
216
								$aso_page['date'] = strftime('%d.%m.%Y', strtotime($aso_page['date']));
217
								break;
218
							case 'jmh' :
219
								$aso_page['date'] = strftime('%d.%m %H:%M', strtotime($aso_page['date']));
220
								break;
221
							case 'jmah' :
222
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date']));
223
								break;
224
							default :
225
								$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date']));
226
						}
227
					}
228
					if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
229
						break;
230
					}
231
					$aso_site['pages'][] = $aso_page;
232
					$GLOBALS['_SYNDICATION_']['pages'][strtotime($aso_page['date'])] = $aso_page;
233
				}
234
				$GLOBALS['_SYNDICATION_']['sites'][] = $aso_site;
235
			}
236
        }
237
    }
238
	// Trie des pages par date
239
	krsort($GLOBALS['_SYNDICATION_']['pages']);
240
 
241
	//+----------------------------------------------------------------------------------------------------------------+
242
    // Extrait les variables et les ajoutes à l'espace de noms local
243
	// Gestion des squelettes
244
	extract($GLOBALS['_SYNDICATION_']);
245
	// Démarre le buffer
246
	ob_start();
247
	// Inclusion du fichier
248
	include($options['template']);
249
	// Récupérer le  contenu du buffer
250
	$sortie = ob_get_contents();
251
	// Arrête et détruit le buffer
252
	ob_end_clean();
253
 
254
	//+----------------------------------------------------------------------------------------------------------------+
255
	// Sortie
256
    return $sortie;
257
}
258
 
259
/* +--Fin du code ----------------------------------------------------------------------------------------+
260
*
261
* $Log: not supported by cvs2svn $
262
*
263
* +-- Fin du code ----------------------------------------------------------------------------------------+
264
*/
265
?>