Subversion Repositories eFlore/Archives.herbiers

Rev

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

Rev Author Line No. Line
6 jp_milcent 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
23 jp_milcent 22
// CVS : $Id: hb_rss.php,v 1.10 2007-11-23 10:04:12 jp_milcent Exp $
6 jp_milcent 23
/**
24
* Générateur de flux RSS pour les Herbiers
25
*
26
*@package bazar
27
//Auteur original :
28
*@author        Florian SCHMITT <florian@ecole-et-nature.org>
29
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
30
*
31
*@copyright     Tela-Botanica 2000-2006
23 jp_milcent 32
*@version       $Revision: 1.10 $ $Date: 2007-11-23 10:04:12 $
6 jp_milcent 33
// +------------------------------------------------------------------------------------------------------+
34
*/
35
 
36
//==================================== LES FLUX RSS==================================
37
// Constantes liées aux flux RSS
38
//==================================================================================
12 jp_milcent 39
// TODO : à mettre dans un fichier de config
11 jp_milcent 40
define('HBR_CREER_FICHIERS_XML', 0);//0=ne cree pas le fichier XML dans rss/; 1=cree le fichier XML dans rss/
6 jp_milcent 41
define('HBR_RSS_NOMSITE','tela-botanica.org');//Nom du site indiqué dans les flux rss
42
define('HBR_RSS_ADRESSESITE','http://www.tela-botanica.org');//Adresse Internet du site indiqué dans les flux rss
43
define('HBR_RSS_DESCRIPTIONSITE','www.tela-botanica.org, pour mutualiser l\'information sur les Herbiers.');    //Description du site indiquée dans les flux rss
44
define('HBR_RSS_LOGOSITE','http://www.tela-botanica.org/sites/commun/generique/images/logos/logo_tela_ombre.png');//Logo du site indiqué dans les flux rss
45
define('HBR_RSS_MANAGINGEDITOR', 'accueil@tela-botanica.org') ;//Managing editor du site
46
define('HBR_RSS_WEBMASTER', 'jpm@tela-botanica.org') ; //Mail Webmaster du site
47
define('HBR_RSS_CATEGORIE', 'Botanique, Herbiers'); //catégorie du flux RSS
12 jp_milcent 48
$GLOBALS['_HERBIER_']['rss']['flux'] = array('herbier', 'collection', 'equipe', 'note');
15 jp_milcent 49
$GLOBALS['_HERBIER_']['rss']['url'] = new Net_URL('http://'.$_SERVER['HTTP_HOST'].'/client/herbier/herbier_rss.php');
6 jp_milcent 50
// TODO : à mettre dans le fichier de langue
51
define('HBR_PAS_D_ANNONCES', 'Pas d\'annonce'); //Message pas d'annonce
52
 
53
if (isset($_GET['type'])) {
12 jp_milcent 54
	$type = $_GET['type'];
6 jp_milcent 55
} else {
12 jp_milcent 56
	$type = '';
6 jp_milcent 57
}
58
 
12 jp_milcent 59
if (isset($_GET['limite'])) {
60
	$limite = $_GET['limite'];
6 jp_milcent 61
} else {
12 jp_milcent 62
	$limite = '';
6 jp_milcent 63
}
12 jp_milcent 64
// Renseignement des méta données par défaut du flux RSS
65
$aso_meta['description'] = HBR_RSS_DESCRIPTIONSITE;
66
$aso_meta['link'] = HBR_RSS_ADRESSESITE;
67
$aso_meta['language'] = 'fr-FR';
68
$aso_meta['copyright'] = 'Copyright 2005 '.HBR_RSS_NOMSITE;
69
$aso_meta['lastBuildDate'] = strftime('%d %b %Y %H:%M:%S GMT');
70
$aso_meta['docs'] = 'http://www.stervinou.com/projets/rss/';
71
$aso_meta['category'] = HBR_RSS_CATEGORIE;
72
$aso_meta['managingEditor'] = HBR_RSS_MANAGINGEDITOR;
73
$aso_meta['webMaster'] = HBR_RSS_WEBMASTER;
74
$aso_meta['ttl'] = 60;
75
$aso_meta['image']['title'] = HBR_RSS_NOMSITE;
76
$aso_meta['image']['url'] = HBR_RSS_LOGOSITE;
77
$aso_meta['image']['link'] = HBR_RSS_ADRESSESITE;
6 jp_milcent 78
 
9 jp_milcent 79
// Generation de la requete MySQL personnalisee
12 jp_milcent 80
switch ($type) {
9 jp_milcent 81
	case 'herbier' :
82
		$requete = 	'SELECT DISTINCT ID_ORG AS id, INSTITUTION_NAME AS titre, DATE_DERNIERE_MODIF AS date_derniere_modif, U_NAME AS nom, U_SURNAME AS prenom '.
83
					'FROM HERBIERS_ORGANISATION, '.HB_BDD_NOM_ANNUAIRE.'.annuaire_tela '.
84
					'WHERE CE_MODIFIER_PAR = U_ID '.
85
					'ORDER BY DATE_DERNIERE_MODIF DESC';
86
		$url = 	HB_URL_COURANTE_CONSULTATION_FICHE_HERBIER_ID;
87
		$aso_meta['titre'] = 'Flux des Organisations';
88
		break;
89
	case 'collection' :
16 jp_milcent 90
		$requete = 	'SELECT DISTINCT PARENT_ID AS id, NOM_COLLECTION AS titre, '.
12 jp_milcent 91
					'DATE_DERNIERE_MODIF AS date_derniere_modif, U_NAME AS nom, U_SURNAME AS prenom '.
9 jp_milcent 92
					'FROM HERBIERS_COLLECTION, '.HB_BDD_NOM_ANNUAIRE.'.annuaire_tela '.
93
					'WHERE CE_MODIFIER_PAR = U_ID '.
94
					'ORDER BY DATE_DERNIERE_MODIF DESC';
95
		$url = 	HB_URL_COURANTE_CONSULTATION_FICHE_COLECTION_ID;
96
		$aso_meta['titre'] = 'Flux des Collections';
97
		break;
12 jp_milcent 98
	case 'equipe' :
99
		$requete = 	'SELECT DISTINCT HOS.ID_ORG AS id_org, HS.ID_STAFF AS id_equipe, PRENOM as titre_prenom, NOM AS titre_nom, '.
100
					'DATE_DERNIERE_MODIF AS date_derniere_modif, U_NAME AS nom, U_SURNAME AS prenom '.
101
					'FROM HERBIERS_STAFF AS HS, '.HB_BDD_NOM_ANNUAIRE.'.annuaire_tela, HERBIERS_ont_un_staff AS HOS '.
102
					'WHERE CE_MODIFIER_PAR = U_ID '.
103
					'AND HOS.ID_STAFF = HS.ID_STAFF '.
104
					'ORDER BY DATE_DERNIERE_MODIF DESC';
105
		$url = 	HB_URL_COURANTE_ADMIN_ACTION_ORG_EQUIPE;
106
		$aso_meta['titre'] = 'Flux des Équipes';
107
		break;
108
	case 'note' :
109
		$requete = 	'SELECT DISTINCT HC.PARENT_ID AS id_org, HC.ID AS id_coll, HI.ID_INDIC AS id_note, HI.REM_INDIC AS titre, '.
110
					'HI.TXT_INDIC AS description, HI.MAJ_INDIC AS date_derniere_modif, U_NAME AS nom, U_SURNAME AS prenom '.
111
					'FROM HERBIERS_INDIC AS HI, HERBIERS_INDIC_HISTORIQUE AS HIH, '.
112
					HB_BDD_NOM_ANNUAIRE.'.annuaire_tela, HERBIERS_COLLECTION AS HC '.
113
					'WHERE HI.ID_INDIC = HIH.ID_INDIC AND HI.MAJ_INDIC = HIH.DATE_INDIC AND HIH.ID_INDICATEUR = U_ID AND HI.ID = HC.ID '.
114
					'ORDER BY HI.MAJ_INDIC DESC';
115
		$url = 	HB_URL_COURANTE_ADMIN_ACTION_ORG_COLL_NOTE;
116
		$aso_meta['titre'] = 'Flux des Notes';
117
		break;
9 jp_milcent 118
	default :
119
		$requete = '';
12 jp_milcent 120
		$aso_meta['titre'] = 'Liste des flux RSS de l\'application Herbiers';
121
		$aso_meta['description'] = 	'Veuillez sélectionner un des flux RSS ci-dessous pour obtenir la liste '.
122
									'des dernières modifications correspondantes.';
9 jp_milcent 123
}
124
$tab_infos = array();
125
if ($requete != '') {
12 jp_milcent 126
	if ($limite != '') {
127
		$requete .= ' LIMIT 0,'.$limite;
9 jp_milcent 128
	}
129
	$resultat = $GLOBALS['_HERBIER_']['bdd']->query($requete) ;
130
	if (DB::isError($resultat)) {
131
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
132
	}
133
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
134
		$aso_infos = array();
12 jp_milcent 135
		switch ($type) {
136
			case 'equipe' :
137
				$aso_infos['title'] = $ligne['titre_prenom'].' '.$ligne['titre_nom'];
138
				$aso_infos['link'] = str_replace('&', '&amp;', sprintf($url, 32, $ligne['id_org'], $ligne['id_equipe']));
139
				$aso_infos['description'] = 'Modifié par '.$ligne['prenom'].' '.$ligne['nom'].' le '.$ligne['date_derniere_modif'];
23 jp_milcent 140
				$aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', strtotime($ligne['date_derniere_modif']));
12 jp_milcent 141
				break;
142
			case 'note' :
143
				if ($ligne['titre'] != '') {
144
					$aso_infos['title'] = $ligne['titre'];
145
				} else {
146
					$aso_infos['title'] = strtoupper($ligne['nom']).' '.date('j.m.Y', $ligne['date_derniere_modif']);
147
				}
148
				$aso_infos['link'] = str_replace('&', '&amp;', sprintf($url, 42, $ligne['id_org'], $ligne['id_coll'], $ligne['id_note']));
149
				$aso_infos['description'] = 'Modifié par '.$ligne['prenom'].' '.$ligne['nom'].
150
											' le '.date('Y-m-j H:i:s', $ligne['date_derniere_modif']).'<br />'.
151
											$ligne['description'];
152
				$aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', $ligne['date_derniere_modif']);
153
				break;
154
			default :
155
				$aso_infos['title'] = $ligne['titre'];
156
				$aso_infos['link'] = str_replace('&', '&amp;', sprintf($url, $ligne['id']));
157
				$aso_infos['description'] = 'Modifié par '.$ligne['prenom'].' '.$ligne['nom'].' le '.$ligne['date_derniere_modif'];
158
				$aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', strtotime($ligne['date_derniere_modif']));
159
		}
9 jp_milcent 160
		$tab_infos[] = $aso_infos;
161
	}
162
} else {
12 jp_milcent 163
	foreach ($GLOBALS['_HERBIER_']['rss']['flux'] as $flux) {
9 jp_milcent 164
		$aso_infos = array();
165
		$aso_infos['title'] = 'Flux RSS : '.$flux;
12 jp_milcent 166
		$GLOBALS['_HERBIER_']['rss']['url']->addQueryString('type', $flux);
167
		$aso_infos['link'] = str_replace('&', '&amp;', $GLOBALS['_HERBIER_']['rss']['url']->getURL());
168
		$aso_infos['description'] = 'Flux RSS sur les '.$flux.'s.';
23 jp_milcent 169
		$aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', strtotime(str_replace('$', '', str_replace('Date: ', '', '$Date: 2007-11-23 10:04:12 $'))));
9 jp_milcent 170
		$tab_infos[] = $aso_infos;
171
	}
172
}
14 jp_milcent 173
// En fonction, de l'appel depuis Papyrus ou pas nous affichons du XML ou du XHTML
174
if (!defined('PAP_VERSION')) {
21 jp_milcent 175
	$sortie = html_entity_decode(hb_generer_rss($aso_meta, $tab_infos, $limite));
14 jp_milcent 176
} else {
21 jp_milcent 177
	$sortie = hb_generer_xhtml($aso_meta, $tab_infos);
14 jp_milcent 178
}
6 jp_milcent 179
 
21 jp_milcent 180
/** hb_generer_xhtml() - generer la liste des flux en XHTML
14 jp_milcent 181
*
182
* @param   array Les  méta données des flux
183
* @param   array Les infos sur les flux
184
*
185
* @return  string La liste des flux RSS
186
*/
21 jp_milcent 187
function hb_generer_xhtml($meta = '', $infos = '')
14 jp_milcent 188
{
189
	$xhtml = '<h1>'.$meta['titre'].'</h1>'."\n";
15 jp_milcent 190
	$xhtml .= '<p>'.$meta['description'].'</p>'."\n";
14 jp_milcent 191
	$xhtml .= '<ul>'."\n";
192
	foreach ($infos as $info) {
193
		$xhtml .= '<li>'."\n";
15 jp_milcent 194
		$xhtml .= '<a href="'.$info['link'].'"><strong>'.$info['title'].'</strong></a><br />'."\n";
14 jp_milcent 195
		$xhtml .= $info['description']."\n";
196
		$xhtml .= '</li>'."\n";
197
	}
198
	$xhtml .= '</ul>'."\n";
199
	return $xhtml;
200
}
6 jp_milcent 201
 
21 jp_milcent 202
/** hb_generer_rss() - generer un fichier de flux RSS par type d'annonce
6 jp_milcent 203
*
14 jp_milcent 204
* @param   array Les  méta données du flux
205
* @param   array Les items du flux
206
*
6 jp_milcent 207
* @return  string Le code du flux RSS
208
*/
21 jp_milcent 209
function hb_generer_rss($meta = '', $infos = '')
14 jp_milcent 210
{
6 jp_milcent 211
	// En-tete du flux RSS version 2.0
9 jp_milcent 212
	$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n";
213
	$xml .= '<rss version="2.0">'."\n";
214
	$xml .= '<channel>'."\n";
215
	$xml .= "\t\t".'<title>'.$meta['titre'].'</title>'."\n";
216
	$xml .= "\t\t".'<link>'.$meta['link'].'</link>'."\n";
217
	$xml .= "\t\t".'<description>'.$meta['description'].'</description>'."\n";
218
	$xml .= "\t\t".'<language>'.$meta['language'].'</language>'."\n";
219
	$xml .= "\t\t".'<copyright>'.$meta['copyright'].'</copyright>'."\n";
6 jp_milcent 220
	// Ajout de la date actuelle de publication (suivant la DTD RSS)
9 jp_milcent 221
	$xml .= "\t\t".'<lastBuildDate>'.$meta['lastBuildDate'].'</lastBuildDate>'."\n";
6 jp_milcent 222
	// En-tete suite et fin
9 jp_milcent 223
	$xml .= "\t\t".'<docs>'.$meta['docs'].'</docs>'."\n";
224
	$xml .= "\t\t".'<category>'.$meta['category'].'</category>'."\n";
225
	$xml .= "\t\t".'<managingEditor>'.$meta['managingEditor'].'</managingEditor>'."\n";
226
	$xml .= "\t\t".'<webMaster>'.$meta['webMaster'].'</webMaster>'."\n";
227
	$xml .= "\t\t".'<ttl>'.$meta['ttl'].'</ttl>'."\n";
228
	$xml .= "\t\t".'<image>'."\n";
229
	$xml .= "\t\t\t".'<title>'.$meta['image']['title'].'</title>'."\n";
230
	$xml .= "\t\t\t".'<url>'.$meta['image']['url'].'</url>'."\n";
231
	$xml .= "\t\t\t".'<link>'.$meta['image']['link'].'</link>'."\n";
232
	$xml .= "\t\t".'</image>'."\n";
233
	if (count($infos) > 0) {
6 jp_milcent 234
		// Creation des items : titre + lien + description + date de publication
9 jp_milcent 235
		foreach ($infos as $info) {
236
			$xml .= "\t\t".'<item>'."\n";
237
			$xml .= "\t\t\t".'<title>'.$info['title'].'</title>'."\n";
238
			$xml .= "\t\t\t".'<link>'.$info['link'].'</link>'."\n";
239
			$xml .= "\t\t\t".'<description><![CDATA['."\n";
240
			$xml .= $info['description']."\n";
241
			$xml .= "\t\t\t".']]></description>'."\n";
242
			$xml .= "\t\t\t".'<pubDate>'.$info['pubdate'].'</pubDate>'."\n";
243
			$xml .= "\t\t".'</item>'."\n";
6 jp_milcent 244
		}
245
	} else {//pas d'annonces
9 jp_milcent 246
		$xml .= "\t\t".'<item>'."\n";
247
		$xml .= "\t\t\t".'<title>'.HBR_PAS_D_ANNONCES.'</title>'."\n";
248
		$xml .= "\t\t\t".'<link>#</link>'."\n";
249
		$xml .= "\t\t\t".'<description>'.HBR_PAS_D_ANNONCES.'</description>'."\n";
250
		$xml .= "\t\t\t".'<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
251
		$xml .= "\t\t".'</item>'."\n";
6 jp_milcent 252
	}
9 jp_milcent 253
	$xml .= "\t".'</channel>'."\n";
254
	$xml .= '</rss>'."\n";
6 jp_milcent 255
	return $xml;
256
}
257
/* +--Fin du code ----------------------------------------------------------------------------------------+
258
*
259
* $Log: not supported by cvs2svn $
23 jp_milcent 260
* Revision 1.9  2007-08-22 14:34:04  jp_milcent
261
* Correction problème : même nom de fonction que dans Bazar...
262
*
21 jp_milcent 263
* Revision 1.8  2006-11-07 17:28:21  jp_milcent
264
* Correction concernant les urls des collections.
265
*
16 jp_milcent 266
* Revision 1.7  2006/10/31 16:03:42  jp_milcent
267
* Correction rendu xhtml dans Papyrus.
268
*
15 jp_milcent 269
* Revision 1.6  2006/10/31 15:33:15  jp_milcent
270
* Gestion d'un rendu XHTML pour Papyrus.
271
*
14 jp_milcent 272
* Revision 1.5  2006/10/31 15:06:44  jp_milcent
273
* Fin de gestion des flux rss.
274
*
12 jp_milcent 275
* Revision 1.4  2006/10/31 12:42:00  jp_milcent
276
* Amélioration de la gestion de la date des flux via les infos cvs.
277
*
11 jp_milcent 278
* Revision 1.3  2006/10/31 12:39:23  jp_milcent
279
* Modification de la gestion de la date des flux via les infos cvs.
280
*
10 jp_milcent 281
* Revision 1.2  2006/10/31 12:38:12  jp_milcent
282
* Début gestion des différents type de flux.
283
*
9 jp_milcent 284
* Revision 1.1  2006/10/30 18:57:17  jp_milcent
285
* Début gestion des flux rss.
6 jp_milcent 286
*
9 jp_milcent 287
*
6 jp_milcent 288
* +-- Fin du code ----------------------------------------------------------------------------------------+
289
*/
290
 
291
?>