Subversion Repositories eFlore/Archives.herbiers

Rev

Rev 6 | Rev 10 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 9
1
<?php
1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
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                                  |
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                            |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
21
// +------------------------------------------------------------------------------------------------------+
22
// CVS : $Id: hb_rss.php,v 1.1 2006-10-30 18:57:17 jp_milcent Exp $
22
// CVS : $Id: hb_rss.php,v 1.2 2006-10-31 12:38:12 jp_milcent Exp $
23
/**
23
/**
24
* Générateur de flux RSS pour les Herbiers 
24
* Générateur de flux RSS pour les Herbiers 
25
*
25
*
26
*@package bazar
26
*@package bazar
27
//Auteur original :
27
//Auteur original :
28
*@author        Florian SCHMITT <florian@ecole-et-nature.org>
28
*@author        Florian SCHMITT <florian@ecole-et-nature.org>
29
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
29
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
30
*
30
*
31
*@copyright     Tela-Botanica 2000-2006
31
*@copyright     Tela-Botanica 2000-2006
32
*@version       $Revision: 1.1 $
32
*@version       $Revision: 1.2 $ $Date: 2006-10-31 12:38:12 $
33
// +------------------------------------------------------------------------------------------------------+
33
// +------------------------------------------------------------------------------------------------------+
34
*/
34
*/
35
 
35
 
36
//==================================== LES FLUX RSS==================================
36
//==================================== LES FLUX RSS==================================
37
// Constantes liées aux flux RSS
37
// Constantes liées aux flux RSS
38
//==================================================================================
38
//==================================================================================
39
define('HBR_CREER_FICHIERS_XML',0);//0=ne cree pas le fichier XML dans rss/; 1=cree le fichier XML dans rss/
39
define('HBR_CREER_FICHIERS_XML',0);//0=ne cree pas le fichier XML dans rss/; 1=cree le fichier XML dans rss/
40
define('HBR_RSS_NOMSITE','tela-botanica.org');//Nom du site indiqué dans les flux rss
40
define('HBR_RSS_NOMSITE','tela-botanica.org');//Nom du site indiqué dans les flux rss
41
define('HBR_RSS_ADRESSESITE','http://www.tela-botanica.org');//Adresse Internet du site indiqué dans les flux rss
41
define('HBR_RSS_ADRESSESITE','http://www.tela-botanica.org');//Adresse Internet du site indiqué dans les flux rss
42
define('HBR_RSS_DESCRIPTIONSITE','www.tela-botanica.org, pour mutualiser l\'information sur les Herbiers.');    //Description du site indiquée dans les flux rss
42
define('HBR_RSS_DESCRIPTIONSITE','www.tela-botanica.org, pour mutualiser l\'information sur les Herbiers.');    //Description du site indiquée dans les flux rss
43
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
43
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
44
define('HBR_RSS_MANAGINGEDITOR', 'accueil@tela-botanica.org') ;//Managing editor du site
44
define('HBR_RSS_MANAGINGEDITOR', 'accueil@tela-botanica.org') ;//Managing editor du site
45
define('HBR_RSS_WEBMASTER', 'jpm@tela-botanica.org') ; //Mail Webmaster du site
45
define('HBR_RSS_WEBMASTER', 'jpm@tela-botanica.org') ; //Mail Webmaster du site
46
define('HBR_RSS_CATEGORIE', 'Botanique, Herbiers'); //catégorie du flux RSS
46
define('HBR_RSS_CATEGORIE', 'Botanique, Herbiers'); //catégorie du flux RSS
47
// TODO : à mettre dans le fichier de langue
47
// TODO : à mettre dans le fichier de langue
48
define('HBR_PAS_D_ANNONCES', 'Pas d\'annonce'); //Message pas d'annonce
48
define('HBR_PAS_D_ANNONCES', 'Pas d\'annonce'); //Message pas d'annonce
49
 
49
 
50
if (isset($_GET['type'])) { 
50
if (isset($_GET['type'])) { 
51
	$annonce = $_GET['type'];
51
	$annonce = $_GET['type'];
52
} else {
52
} else {
53
	$annonce = '';
53
	$annonce = '';
54
}
54
}
55
 
55
 
56
if (isset($_GET['nbitem'])) { 
56
if (isset($_GET['nbitem'])) { 
57
	$nbitem = $_GET['nbitem'];
57
	$nbitem = $_GET['nbitem'];
58
} else {
58
} else {
59
	$nbitem = '';
59
	$nbitem = '';
60
}
60
}
-
 
61
 
-
 
62
// Generation de la requete MySQL personnalisee
-
 
63
switch ('type') {
-
 
64
	case 'herbier' :
-
 
65
		$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 '.
-
 
66
					'FROM HERBIERS_ORGANISATION, '.HB_BDD_NOM_ANNUAIRE.'.annuaire_tela '.
-
 
67
					'WHERE CE_MODIFIER_PAR = U_ID '.
-
 
68
					'ORDER BY DATE_DERNIERE_MODIF DESC';
-
 
69
		$url = 	HB_URL_COURANTE_CONSULTATION_FICHE_HERBIER_ID;
-
 
70
		$aso_meta['titre'] = 'Flux des Organisations';
-
 
71
		break;
-
 
72
	case 'collection' :
-
 
73
		$requete = 	'SELECT DISTINCT ID AS id, NOM_COLLECTION AS titre, DATE_DERNIERE_MODIF AS date_derniere_modif, U_NAME AS nom, U_SURNAME AS prenom '.
-
 
74
					'FROM HERBIERS_COLLECTION, '.HB_BDD_NOM_ANNUAIRE.'.annuaire_tela '.
-
 
75
					'WHERE CE_MODIFIER_PAR = U_ID '.
-
 
76
					'ORDER BY DATE_DERNIERE_MODIF DESC';
-
 
77
		$url = 	HB_URL_COURANTE_CONSULTATION_FICHE_COLECTION_ID;
-
 
78
		$aso_meta['titre'] = 'Flux des Collections';
-
 
79
		break;
-
 
80
	default :
-
 
81
		$requete = '';
-
 
82
}
-
 
83
$tab_infos = array();
-
 
84
if ($requete != '') {
-
 
85
	if ($nbitem != '') {
-
 
86
		$requete .= ' LIMIT 0,'.$nbitem;	
-
 
87
	}
-
 
88
	$resultat = $GLOBALS['_HERBIER_']['bdd']->query($requete) ;
-
 
89
	if (DB::isError($resultat)) {
-
 
90
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
-
 
91
	}
-
 
92
	while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
-
 
93
		$aso_infos = array();
-
 
94
		$aso_infos['title'] = $ligne['titre'];
-
 
95
		$aso_infos['link'] = str_replace('&', '&amp;', sprintf($url, $ligne['id']));
-
 
96
		$aso_infos['description'] = 'Modifié par '.$ligne['prenom'].' '.$ligne['nom'].' le '.$ligne['date_derniere_modif'];
-
 
97
		$aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', strtotime($ligne['date_derniere_modif']));
-
 
98
		$tab_infos[] = $aso_infos; 
-
 
99
	}
-
 
100
} else {
-
 
101
	$aso_flux = array('herbier', 'collection');
-
 
102
	foreach ($aso_flux as $flux) {
-
 
103
		$aso_infos = array();
-
 
104
		$aso_infos['title'] = 'Flux RSS : '.$flux;
-
 
105
		$GLOBALS['_HERBIER_']['url_rss']->addQueryString('type', $flux);
-
 
106
		$aso_infos['link'] = str_replace('&', '&amp;', $GLOBALS['_HERBIER_']['url_rss']->getURL());
-
 
107
		$aso_infos['description'] = 'Modifié par '.$ligne['prenom'].' '.$ligne['nom'].' le '.$ligne['date_derniere_modif'];
-
 
108
		$aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', strtotime(str_replace('$', str_replace('$Date: 2006-10-31 12:38:12 $Date$'))));
-
 
109
		$tab_infos[] = $aso_infos;
-
 
110
	} 
-
 
111
}
-
 
112
$aso_meta['description'] = HBR_RSS_DESCRIPTIONSITE;
-
 
113
$aso_meta['link'] = HBR_RSS_ADRESSESITE;
-
 
114
$aso_meta['language'] = 'fr-FR';
-
 
115
$aso_meta['copyright'] = 'Copyright 2005 '.HBR_RSS_NOMSITE;
-
 
116
$aso_meta['lastBuildDate'] = strftime('%d %b %Y %H:%M:%S GMT');
-
 
117
$aso_meta['docs'] = 'http://www.stervinou.com/projets/rss/';
-
 
118
$aso_meta['category'] = HBR_RSS_CATEGORIE;
-
 
119
$aso_meta['managingEditor'] = HBR_RSS_MANAGINGEDITOR;
-
 
120
$aso_meta['webMaster'] = HBR_RSS_WEBMASTER;
-
 
121
$aso_meta['ttl'] = 60;
-
 
122
$aso_meta['image']['title'] = HBR_RSS_NOMSITE;
-
 
123
$aso_meta['image']['url'] = HBR_RSS_LOGOSITE;
61
 
-
 
62
 
124
$aso_meta['image']['link'] = HBR_RSS_ADRESSESITE;
63
 
125
 
64
echo html_entity_decode(gen_RSS($annonce, $nbitem));
126
echo html_entity_decode(gen_RSS($aso_meta, $tab_infos, $nbitem));
65
 
127
 
66
 
128
 
67
/** gen_RSS() - generer un fichier de flux RSS par type d'annonce 
129
/** gen_RSS() - generer un fichier de flux RSS par type d'annonce 
68
*
130
*
69
* @param   string Le type de l'annonce (laisser vide pour tout type d'annonce)
131
* @param   string Le type de l'annonce (laisser vide pour tout type d'annonce)
70
* @param   integer Le nombre d'annonces a regrouper dans le fichier XML (laisser vide pour toutes)
132
* @param   integer Le nombre d'annonces a regrouper dans le fichier XML (laisser vide pour toutes)
71
* @param   integer L'identifiant de l'emetteur (laisser vide pour tous)
133
* @param   integer L'identifiant de l'emetteur (laisser vide pour tous)
72
* @param   integer L'etat de validation de l'annonce (laisser 1 pour les annonces validees, 0 pour les non-validees)
134
* @param   integer L'etat de validation de l'annonce (laisser 1 pour les annonces validees, 0 pour les non-validees)
73
* @param   string La requete SQL personnalisee
135
* @param   string La requete SQL personnalisee
74
* @param   integer La categorie des fiches bazar
136
* @param   integer La categorie des fiches bazar
75
*
137
*
76
* @return  string Le code du flux RSS
138
* @return  string Le code du flux RSS
77
*/
139
*/
78
function gen_RSS($typeannonce='', $nbitem='') {
140
function gen_RSS($meta = '', $infos = '', $nbitem = '') {
79
	// Generation de la requete MySQL personnalisee
-
 
80
	$requete = 	'SELECT DISTINCT * '.
-
 
81
				'FROM HERBIERS_ORGANISATION '.
-
 
82
				'ORDER BY  DATE_DERNIERE_MODIF DESC';
-
 
83
	if ($nbitem!='') {
-
 
84
		$requete .= ' LIMIT 0,'.$nbitem;	
-
 
85
	}
-
 
86
	$resultat = $GLOBALS['_HERBIER_']['bdd']->query($requete) ;
-
 
87
	if (DB::isError($resultat)) {
-
 
88
		die ($resultat->getMessage().$resultat->getDebugInfo()) ;
-
 
89
	}
-
 
90
	// Initialisation des variables
-
 
91
	$nomflux = 'Flux des '.$typeannonce;
-
 
92
	
-
 
93
	// En-tete du flux RSS version 2.0
141
	// En-tete du flux RSS version 2.0
94
	$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".'<rss version="2.0">'."\n";
142
	$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n";
-
 
143
	$xml .= '<rss version="2.0">'."\n";
-
 
144
	$xml .= '<channel>'."\n";
95
	$xml .= '<channel>'."\n".'<title>'.$nomflux.'</title>'."\n".'<link>'.HBR_RSS_ADRESSESITE.'</link>'."\n";
145
	$xml .= "\t\t".'<title>'.$meta['titre'].'</title>'."\n";
-
 
146
	$xml .= "\t\t".'<link>'.$meta['link'].'</link>'."\n";
96
	$xml .= '<description>'.HBR_RSS_DESCRIPTIONSITE.'</description>'."\n".'<language>fr-FR</language>'."\n".
147
	$xml .= "\t\t".'<description>'.$meta['description'].'</description>'."\n";
-
 
148
	$xml .= "\t\t".'<language>'.$meta['language'].'</language>'."\n";
97
	'<copyright>Copyright 2005 '.HBR_RSS_NOMSITE.'</copyright>'."\n";
149
	$xml .= "\t\t".'<copyright>'.$meta['copyright'].'</copyright>'."\n";
98
	// Ajout de la date actuelle de publication (suivant la DTD RSS)
150
	// Ajout de la date actuelle de publication (suivant la DTD RSS)
99
	$xml .= '<lastBuildDate>'.strftime('%d %b %Y %H:%M:%S GMT').'</lastBuildDate>'."\n";
151
	$xml .= "\t\t".'<lastBuildDate>'.$meta['lastBuildDate'].'</lastBuildDate>'."\n";
100
	// En-tete suite et fin
152
	// En-tete suite et fin
-
 
153
	$xml .= "\t\t".'<docs>'.$meta['docs'].'</docs>'."\n";
101
	$xml .= '<docs>http://www.stervinou.com/projets/rss/</docs>'."\n".'<category>'.HBR_RSS_CATEGORIE.'</category>'."\n".
154
	$xml .= "\t\t".'<category>'.$meta['category'].'</category>'."\n";
-
 
155
	$xml .= "\t\t".'<managingEditor>'.$meta['managingEditor'].'</managingEditor>'."\n";
102
	'<managingEditor>'.HBR_RSS_MANAGINGEDITOR.'</managingEditor>'."\n".'<webMaster>'.HBR_RSS_WEBMASTER.'</webMaster>'."\n";
156
	$xml .= "\t\t".'<webMaster>'.$meta['webMaster'].'</webMaster>'."\n";
-
 
157
	$xml .= "\t\t".'<ttl>'.$meta['ttl'].'</ttl>'."\n";
-
 
158
	$xml .= "\t\t".'<image>'."\n";
103
	$xml .= '<ttl>60</ttl>'."\n".'<image>'."\n".'<title>'.HBR_RSS_NOMSITE.'</title>'."\n".'<url>'.HBR_RSS_LOGOSITE.'</url>'."\n".
159
	$xml .= "\t\t\t".'<title>'.$meta['image']['title'].'</title>'."\n";
104
	'<link>'.HBR_RSS_ADRESSESITE.'</link>'."\n".'</image>'."\n";
160
	$xml .= "\t\t\t".'<url>'.$meta['image']['url'].'</url>'."\n";
-
 
161
	$xml .= "\t\t\t".'<link>'.$meta['image']['link'].'</link>'."\n";
-
 
162
	$xml .= "\t\t".'</image>'."\n";
105
	if ($resultat->numRows() > 0) {
163
	if (count($infos) > 0) {
106
		// Creation des items : titre + lien + description + date de publication
164
		// Creation des items : titre + lien + description + date de publication
107
		while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
165
		foreach ($infos as $info) {
108
			$xml .= '<item>'."\n";
166
			$xml .= "\t\t".'<item>'."\n";
109
			$xml .= '<title>'.$ligne['INSTITUTION_NAME'].'</title>'."\n";
167
			$xml .= "\t\t\t".'<title>'.$info['title'].'</title>'."\n";
110
			$lien = sprintf(HB_URL_COURANTE_CONSULTATION_FICHE_HERBIER_ID, $ligne['ID_ORG']);
-
 
111
			$xml .= '<link>'.str_replace('&', '&amp;', $lien).'</link>'."\n";
168
			$xml .= "\t\t\t".'<link>'.$info['link'].'</link>'."\n";
112
			$xml .= '<description>'."\n".'<![CDATA[' ;
169
			$xml .= "\t\t\t".'<description><![CDATA['."\n";
113
			$xml .= $ligne['ZIP'] ;
170
			$xml .= $info['description']."\n";
114
			$xml .= ']]>'."\n".'</description>'."\n";
171
			$xml .= "\t\t\t".']]></description>'."\n";
115
			$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime($ligne['DATE_DERNIERE_MODIF'])).'</pubDate>'."\n";
172
			$xml .= "\t\t\t".'<pubDate>'.$info['pubdate'].'</pubDate>'."\n";
116
			$xml .= '</item>'."\n";
173
			$xml .= "\t\t".'</item>'."\n";
117
		}
174
		}
118
	} else {//pas d'annonces
175
	} else {//pas d'annonces
119
		$xml .= '<item>'."\n";
176
		$xml .= "\t\t".'<item>'."\n";
120
		$xml .= '<title>'.HBR_PAS_D_ANNONCES.'</title>'."\n";
177
		$xml .= "\t\t\t".'<title>'.HBR_PAS_D_ANNONCES.'</title>'."\n";
121
		$xml .= '<link>#</link>'."\n";
178
		$xml .= "\t\t\t".'<link>#</link>'."\n";
122
		$xml .= '<description>'.HBR_PAS_D_ANNONCES.'</description>'."\n";
179
		$xml .= "\t\t\t".'<description>'.HBR_PAS_D_ANNONCES.'</description>'."\n";
123
		$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
180
		$xml .= "\t\t\t".'<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
124
		$xml .= '</item>'."\n";
181
		$xml .= "\t\t".'</item>'."\n";
125
	}
182
	}
126
	$xml .= '</channel>'."\n".'</rss>'."\n";
183
	$xml .= "\t".'</channel>'."\n";
-
 
184
	$xml .= '</rss>'."\n";
127
	return $xml;
185
	return $xml;
128
}
186
}
129
/* +--Fin du code ----------------------------------------------------------------------------------------+
187
/* +--Fin du code ----------------------------------------------------------------------------------------+
130
*
188
*
131
* $Log: not supported by cvs2svn $
189
* $Log: not supported by cvs2svn $
-
 
190
* Revision 1.1  2006/10/30 18:57:17  jp_milcent
-
 
191
* Début gestion des flux rss.
-
 
192
*
132
*
193
*
133
* +-- Fin du code ----------------------------------------------------------------------------------------+
194
* +-- Fin du code ----------------------------------------------------------------------------------------+
134
*/
195
*/
135
 
196
 
136
?>
197
?>