Subversion Repositories eFlore/Archives.herbiers

Compare Revisions

Ignore whitespace Rev 5 → Rev 6

/trunk/applications/hb_rss/hb_rss.php
New file
0,0 → 1,136
<?php
/*vim: set expandtab tabstop=4 shiftwidth=4: */
// +------------------------------------------------------------------------------------------------------+
// | PHP version 4.1 |
// +------------------------------------------------------------------------------------------------------+
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
// +------------------------------------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU Lesser General Public |
// | License as published by the Free Software Foundation; either |
// | version 2.1 of the License, or (at your option) any later version. |
// | |
// | This library is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
// | Lesser General Public License for more details. |
// | |
// | You should have received a copy of the GNU Lesser General Public |
// | License along with this library; if not, write to the Free Software |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
// +------------------------------------------------------------------------------------------------------+
// CVS : $Id: hb_rss.php,v 1.1 2006-10-30 18:57:17 jp_milcent Exp $
/**
* Générateur de flux RSS pour les Herbiers
*
*@package bazar
//Auteur original :
*@author Florian SCHMITT <florian@ecole-et-nature.org>
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
*
*@copyright Tela-Botanica 2000-2006
*@version $Revision: 1.1 $
// +------------------------------------------------------------------------------------------------------+
*/
 
//==================================== LES FLUX RSS==================================
// Constantes liées aux flux RSS
//==================================================================================
define('HBR_CREER_FICHIERS_XML',0);//0=ne cree pas le fichier XML dans rss/; 1=cree le fichier XML dans rss/
define('HBR_RSS_NOMSITE','tela-botanica.org');//Nom du site indiqué dans les flux rss
define('HBR_RSS_ADRESSESITE','http://www.tela-botanica.org');//Adresse Internet du site indiqué dans les flux rss
define('HBR_RSS_DESCRIPTIONSITE','www.tela-botanica.org, pour mutualiser l\'information sur les Herbiers.'); //Description du site indiquée dans les flux rss
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
define('HBR_RSS_MANAGINGEDITOR', 'accueil@tela-botanica.org') ;//Managing editor du site
define('HBR_RSS_WEBMASTER', 'jpm@tela-botanica.org') ; //Mail Webmaster du site
define('HBR_RSS_CATEGORIE', 'Botanique, Herbiers'); //catégorie du flux RSS
// TODO : à mettre dans le fichier de langue
define('HBR_PAS_D_ANNONCES', 'Pas d\'annonce'); //Message pas d'annonce
 
if (isset($_GET['type'])) {
$annonce = $_GET['type'];
} else {
$annonce = '';
}
 
if (isset($_GET['nbitem'])) {
$nbitem = $_GET['nbitem'];
} else {
$nbitem = '';
}
 
 
 
echo html_entity_decode(gen_RSS($annonce, $nbitem));
 
 
/** gen_RSS() - generer un fichier de flux RSS par type d'annonce
*
* @param string Le type de l'annonce (laisser vide pour tout type d'annonce)
* @param integer Le nombre d'annonces a regrouper dans le fichier XML (laisser vide pour toutes)
* @param integer L'identifiant de l'emetteur (laisser vide pour tous)
* @param integer L'etat de validation de l'annonce (laisser 1 pour les annonces validees, 0 pour les non-validees)
* @param string La requete SQL personnalisee
* @param integer La categorie des fiches bazar
*
* @return string Le code du flux RSS
*/
function gen_RSS($typeannonce='', $nbitem='') {
// Generation de la requete MySQL personnalisee
$requete = 'SELECT DISTINCT * '.
'FROM HERBIERS_ORGANISATION '.
'ORDER BY DATE_DERNIERE_MODIF DESC';
if ($nbitem!='') {
$requete .= ' LIMIT 0,'.$nbitem;
}
$resultat = $GLOBALS['_HERBIER_']['bdd']->query($requete) ;
if (DB::isError($resultat)) {
die ($resultat->getMessage().$resultat->getDebugInfo()) ;
}
// Initialisation des variables
$nomflux = 'Flux des '.$typeannonce;
// En-tete du flux RSS version 2.0
$xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n".'<rss version="2.0">'."\n";
$xml .= '<channel>'."\n".'<title>'.$nomflux.'</title>'."\n".'<link>'.HBR_RSS_ADRESSESITE.'</link>'."\n";
$xml .= '<description>'.HBR_RSS_DESCRIPTIONSITE.'</description>'."\n".'<language>fr-FR</language>'."\n".
'<copyright>Copyright 2005 '.HBR_RSS_NOMSITE.'</copyright>'."\n";
// Ajout de la date actuelle de publication (suivant la DTD RSS)
$xml .= '<lastBuildDate>'.strftime('%d %b %Y %H:%M:%S GMT').'</lastBuildDate>'."\n";
// En-tete suite et fin
$xml .= '<docs>http://www.stervinou.com/projets/rss/</docs>'."\n".'<category>'.HBR_RSS_CATEGORIE.'</category>'."\n".
'<managingEditor>'.HBR_RSS_MANAGINGEDITOR.'</managingEditor>'."\n".'<webMaster>'.HBR_RSS_WEBMASTER.'</webMaster>'."\n";
$xml .= '<ttl>60</ttl>'."\n".'<image>'."\n".'<title>'.HBR_RSS_NOMSITE.'</title>'."\n".'<url>'.HBR_RSS_LOGOSITE.'</url>'."\n".
'<link>'.HBR_RSS_ADRESSESITE.'</link>'."\n".'</image>'."\n";
if ($resultat->numRows() > 0) {
// Creation des items : titre + lien + description + date de publication
while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
$xml .= '<item>'."\n";
$xml .= '<title>'.$ligne['INSTITUTION_NAME'].'</title>'."\n";
$lien = sprintf(HB_URL_COURANTE_CONSULTATION_FICHE_HERBIER_ID, $ligne['ID_ORG']);
$xml .= '<link>'.str_replace('&', '&amp;', $lien).'</link>'."\n";
$xml .= '<description>'."\n".'<![CDATA[' ;
$xml .= $ligne['ZIP'] ;
$xml .= ']]>'."\n".'</description>'."\n";
$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime($ligne['DATE_DERNIERE_MODIF'])).'</pubDate>'."\n";
$xml .= '</item>'."\n";
}
} else {//pas d'annonces
$xml .= '<item>'."\n";
$xml .= '<title>'.HBR_PAS_D_ANNONCES.'</title>'."\n";
$xml .= '<link>#</link>'."\n";
$xml .= '<description>'.HBR_PAS_D_ANNONCES.'</description>'."\n";
$xml .= '<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
$xml .= '</item>'."\n";
}
$xml .= '</channel>'."\n".'</rss>'."\n";
return $xml;
}
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
 
?>