Subversion Repositories eFlore/Archives.herbiers

Rev

Rev 11 | Rev 14 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?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.5 2006-10-31 15:06:44 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.5 $ $Date: 2006-10-31 15:06:44 $
// +------------------------------------------------------------------------------------------------------+
*/

//==================================== LES FLUX RSS==================================
// Constantes liées aux flux RSS
//==================================================================================
// TODO : à mettre dans un fichier de config
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
$GLOBALS['_HERBIER_']['rss']['flux'] = array('herbier', 'collection', 'equipe', 'note');
$GLOBALS['_HERBIER_']['rss']['url'] = new Net_URL('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
// TODO : à mettre dans le fichier de langue
define('HBR_PAS_D_ANNONCES', 'Pas d\'annonce'); //Message pas d'annonce

if (isset($_GET['type'])) { 
        $type = $_GET['type'];
} else {
        $type = '';
}

if (isset($_GET['limite'])) { 
        $limite = $_GET['limite'];
} else {
        $limite = '';
}
// Renseignement des méta données par défaut du flux RSS
$aso_meta['description'] = HBR_RSS_DESCRIPTIONSITE;
$aso_meta['link'] = HBR_RSS_ADRESSESITE;
$aso_meta['language'] = 'fr-FR';
$aso_meta['copyright'] = 'Copyright 2005 '.HBR_RSS_NOMSITE;
$aso_meta['lastBuildDate'] = strftime('%d %b %Y %H:%M:%S GMT');
$aso_meta['docs'] = 'http://www.stervinou.com/projets/rss/';
$aso_meta['category'] = HBR_RSS_CATEGORIE;
$aso_meta['managingEditor'] = HBR_RSS_MANAGINGEDITOR;
$aso_meta['webMaster'] = HBR_RSS_WEBMASTER;
$aso_meta['ttl'] = 60;
$aso_meta['image']['title'] = HBR_RSS_NOMSITE;
$aso_meta['image']['url'] = HBR_RSS_LOGOSITE;
$aso_meta['image']['link'] = HBR_RSS_ADRESSESITE;

// Generation de la requete MySQL personnalisee
switch ($type) {
        case 'herbier' :
                $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 '.
                                        'FROM HERBIERS_ORGANISATION, '.HB_BDD_NOM_ANNUAIRE.'.annuaire_tela '.
                                        'WHERE CE_MODIFIER_PAR = U_ID '.
                                        'ORDER BY DATE_DERNIERE_MODIF DESC';
                $url =  HB_URL_COURANTE_CONSULTATION_FICHE_HERBIER_ID;
                $aso_meta['titre'] = 'Flux des Organisations';
                break;
        case 'collection' :
                $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 '.
                                        'FROM HERBIERS_COLLECTION, '.HB_BDD_NOM_ANNUAIRE.'.annuaire_tela '.
                                        'WHERE CE_MODIFIER_PAR = U_ID '.
                                        'ORDER BY DATE_DERNIERE_MODIF DESC';
                $url =  HB_URL_COURANTE_CONSULTATION_FICHE_COLECTION_ID;
                $aso_meta['titre'] = 'Flux des Collections';
                break;
        case 'equipe' :
                $requete =      'SELECT DISTINCT HOS.ID_ORG AS id_org, HS.ID_STAFF AS id_equipe, PRENOM as titre_prenom, NOM AS titre_nom, '.
                                        'DATE_DERNIERE_MODIF AS date_derniere_modif, U_NAME AS nom, U_SURNAME AS prenom '.
                                        'FROM HERBIERS_STAFF AS HS, '.HB_BDD_NOM_ANNUAIRE.'.annuaire_tela, HERBIERS_ont_un_staff AS HOS '.
                                        'WHERE CE_MODIFIER_PAR = U_ID '.
                                        'AND HOS.ID_STAFF = HS.ID_STAFF '.
                                        'ORDER BY DATE_DERNIERE_MODIF DESC';
                $url =  HB_URL_COURANTE_ADMIN_ACTION_ORG_EQUIPE;
                $aso_meta['titre'] = 'Flux des Équipes';
                break;
        case 'note' :
                $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, '.
                                        'HI.TXT_INDIC AS description, HI.MAJ_INDIC AS date_derniere_modif, U_NAME AS nom, U_SURNAME AS prenom '.
                                        'FROM HERBIERS_INDIC AS HI, HERBIERS_INDIC_HISTORIQUE AS HIH, '.
                                        HB_BDD_NOM_ANNUAIRE.'.annuaire_tela, HERBIERS_COLLECTION AS HC '.
                                        '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 '.
                                        'ORDER BY HI.MAJ_INDIC DESC';
                $url =  HB_URL_COURANTE_ADMIN_ACTION_ORG_COLL_NOTE;
                $aso_meta['titre'] = 'Flux des Notes';
                break;
        default :
                $requete = '';
                $aso_meta['titre'] = 'Liste des flux RSS de l\'application Herbiers';
                $aso_meta['description'] =      'Veuillez sélectionner un des flux RSS ci-dessous pour obtenir la liste '.
                                                                        'des dernières modifications correspondantes.';
}
$tab_infos = array();
if ($requete != '') {
        if ($limite != '') {
                $requete .= ' LIMIT 0,'.$limite;        
        }
        $resultat = $GLOBALS['_HERBIER_']['bdd']->query($requete) ;
        if (DB::isError($resultat)) {
                die ($resultat->getMessage().$resultat->getDebugInfo()) ;
        }
        while ($ligne = $resultat->fetchRow(DB_FETCHMODE_ASSOC)) {
                $aso_infos = array();
                switch ($type) {
                        case 'equipe' :
                                $aso_infos['title'] = $ligne['titre_prenom'].' '.$ligne['titre_nom'];
                                $aso_infos['link'] = str_replace('&', '&amp;', sprintf($url, 32, $ligne['id_org'], $ligne['id_equipe']));
                                $aso_infos['description'] = 'Modifié par '.$ligne['prenom'].' '.$ligne['nom'].' le '.$ligne['date_derniere_modif'];
                                $aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', $ligne['date_derniere_modif']);               
                                break;
                        case 'note' :
                                if ($ligne['titre'] != '') {
                                        $aso_infos['title'] = $ligne['titre'];
                                } else {
                                        $aso_infos['title'] = strtoupper($ligne['nom']).' '.date('j.m.Y', $ligne['date_derniere_modif']);
                                }
                                $aso_infos['link'] = str_replace('&', '&amp;', sprintf($url, 42, $ligne['id_org'], $ligne['id_coll'], $ligne['id_note']));
                                $aso_infos['description'] = 'Modifié par '.$ligne['prenom'].' '.$ligne['nom'].
                                                                                        ' le '.date('Y-m-j H:i:s', $ligne['date_derniere_modif']).'<br />'.
                                                                                        $ligne['description'];
                                $aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', $ligne['date_derniere_modif']);               
                                break;
                        default :
                                $aso_infos['title'] = $ligne['titre'];
                                $aso_infos['link'] = str_replace('&', '&amp;', sprintf($url, $ligne['id']));
                                $aso_infos['description'] = 'Modifié par '.$ligne['prenom'].' '.$ligne['nom'].' le '.$ligne['date_derniere_modif'];
                                $aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', strtotime($ligne['date_derniere_modif']));            
                }               
                $tab_infos[] = $aso_infos; 
        }
} else {
        foreach ($GLOBALS['_HERBIER_']['rss']['flux'] as $flux) {
                $aso_infos = array();
                $aso_infos['title'] = 'Flux RSS : '.$flux;
                $GLOBALS['_HERBIER_']['rss']['url']->addQueryString('type', $flux);
                $aso_infos['link'] = str_replace('&', '&amp;', $GLOBALS['_HERBIER_']['rss']['url']->getURL());
                $aso_infos['description'] = 'Flux RSS sur les '.$flux.'s.';
                $aso_infos['pubdate'] = strftime('%d %b %Y %H:%M:%S GMT', strtotime(str_replace('$', '', str_replace('Date: ', '', '$Date: 2006-10-31 15:06:44 $'))));
                $tab_infos[] = $aso_infos;
        } 
}
echo html_entity_decode(gen_RSS($aso_meta, $tab_infos, $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($meta = '', $infos = '', $nbitem = '') {
        // En-tete du flux RSS version 2.0
        $xml = '<?xml version="1.0" encoding="ISO-8859-1"?>'."\n";
        $xml .= '<rss version="2.0">'."\n";
        $xml .= '<channel>'."\n";
        $xml .= "\t\t".'<title>'.$meta['titre'].'</title>'."\n";
        $xml .= "\t\t".'<link>'.$meta['link'].'</link>'."\n";
        $xml .= "\t\t".'<description>'.$meta['description'].'</description>'."\n";
        $xml .= "\t\t".'<language>'.$meta['language'].'</language>'."\n";
        $xml .= "\t\t".'<copyright>'.$meta['copyright'].'</copyright>'."\n";
        // Ajout de la date actuelle de publication (suivant la DTD RSS)
        $xml .= "\t\t".'<lastBuildDate>'.$meta['lastBuildDate'].'</lastBuildDate>'."\n";
        // En-tete suite et fin
        $xml .= "\t\t".'<docs>'.$meta['docs'].'</docs>'."\n";
        $xml .= "\t\t".'<category>'.$meta['category'].'</category>'."\n";
        $xml .= "\t\t".'<managingEditor>'.$meta['managingEditor'].'</managingEditor>'."\n";
        $xml .= "\t\t".'<webMaster>'.$meta['webMaster'].'</webMaster>'."\n";
        $xml .= "\t\t".'<ttl>'.$meta['ttl'].'</ttl>'."\n";
        $xml .= "\t\t".'<image>'."\n";
        $xml .= "\t\t\t".'<title>'.$meta['image']['title'].'</title>'."\n";
        $xml .= "\t\t\t".'<url>'.$meta['image']['url'].'</url>'."\n";
        $xml .= "\t\t\t".'<link>'.$meta['image']['link'].'</link>'."\n";
        $xml .= "\t\t".'</image>'."\n";
        if (count($infos) > 0) {
                // Creation des items : titre + lien + description + date de publication
                foreach ($infos as $info) {
                        $xml .= "\t\t".'<item>'."\n";
                        $xml .= "\t\t\t".'<title>'.$info['title'].'</title>'."\n";
                        $xml .= "\t\t\t".'<link>'.$info['link'].'</link>'."\n";
                        $xml .= "\t\t\t".'<description><![CDATA['."\n";
                        $xml .= $info['description']."\n";
                        $xml .= "\t\t\t".']]></description>'."\n";
                        $xml .= "\t\t\t".'<pubDate>'.$info['pubdate'].'</pubDate>'."\n";
                        $xml .= "\t\t".'</item>'."\n";
                }
        } else {//pas d'annonces
                $xml .= "\t\t".'<item>'."\n";
                $xml .= "\t\t\t".'<title>'.HBR_PAS_D_ANNONCES.'</title>'."\n";
                $xml .= "\t\t\t".'<link>#</link>'."\n";
                $xml .= "\t\t\t".'<description>'.HBR_PAS_D_ANNONCES.'</description>'."\n";
                $xml .= "\t\t\t".'<pubDate>'.strftime('%d %b %Y %H:%M:%S GMT',strtotime('12/12/2004')).'</pubDate>'."\n";
                $xml .= "\t\t".'</item>'."\n";
        }
        $xml .= "\t".'</channel>'."\n";
        $xml .= '</rss>'."\n";
        return $xml;
}
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
* Revision 1.4  2006/10/31 12:42:00  jp_milcent
* Amélioration de la gestion de la date des flux via les infos cvs.
*
* Revision 1.3  2006/10/31 12:39:23  jp_milcent
* Modification de la gestion de la date des flux via les infos cvs.
*
* Revision 1.2  2006/10/31 12:38:12  jp_milcent
* Début gestion des différents type de flux.
*
* Revision 1.1  2006/10/30 18:57:17  jp_milcent
* Début gestion des flux rss.
*
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/

?>