Rev 15 | Rev 21 | 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.8 2006-11-07 17:28:21 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.8 $ $Date: 2006-11-07 17:28:21 $// +------------------------------------------------------------------------------------------------------+*///==================================== LES FLUX RSS==================================// Constantes liées aux flux RSS//==================================================================================// TODO : à mettre dans un fichier de configdefine('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 rssdefine('HBR_RSS_ADRESSESITE','http://www.tela-botanica.org');//Adresse Internet du site indiqué dans les flux rssdefine('HBR_RSS_DESCRIPTIONSITE','www.tela-botanica.org, pour mutualiser l\'information sur les Herbiers.'); //Description du site indiquée dans les flux rssdefine('HBR_RSS_LOGOSITE','http://www.tela-botanica.org/sites/commun/generique/images/logos/logo_tela_ombre.png');//Logo du site indiqué dans les flux rssdefine('HBR_RSS_MANAGINGEDITOR', 'accueil@tela-botanica.org') ;//Managing editor du sitedefine('HBR_RSS_WEBMASTER', 'jpm@tela-botanica.org') ; //Mail Webmaster du sitedefine('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'].'/client/herbier/herbier_rss.php');// TODO : à mettre dans le fichier de languedefine('HBR_PAS_D_ANNONCES', 'Pas d\'annonce'); //Message pas d'annonceif (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 personnaliseeswitch ($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 PARENT_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('&', '&', 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('&', '&', 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('&', '&', 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('&', '&', $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-11-07 17:28:21 $'))));$tab_infos[] = $aso_infos;}}// En fonction, de l'appel depuis Papyrus ou pas nous affichons du XML ou du XHTMLif (!defined('PAP_VERSION')) {$sortie = html_entity_decode(gen_RSS($aso_meta, $tab_infos, $limite));} else {$sortie = gen_XHTML($aso_meta, $tab_infos);}/** gen_XHTML() - generer la liste des flux en XHTML** @param array Les méta données des flux* @param array Les infos sur les flux** @return string La liste des flux RSS*/function gen_XHTML($meta = '', $infos = ''){$xhtml = '<h1>'.$meta['titre'].'</h1>'."\n";$xhtml .= '<p>'.$meta['description'].'</p>'."\n";$xhtml .= '<ul>'."\n";foreach ($infos as $info) {$xhtml .= '<li>'."\n";$xhtml .= '<a href="'.$info['link'].'"><strong>'.$info['title'].'</strong></a><br />'."\n";$xhtml .= $info['description']."\n";$xhtml .= '</li>'."\n";}$xhtml .= '</ul>'."\n";return $xhtml;}/** gen_RSS() - generer un fichier de flux RSS par type d'annonce** @param array Les méta données du flux* @param array Les items du flux** @return string Le code du flux RSS*/function gen_RSS($meta = '', $infos = ''){// 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 publicationforeach ($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.7 2006/10/31 16:03:42 jp_milcent* Correction rendu xhtml dans Papyrus.** Revision 1.6 2006/10/31 15:33:15 jp_milcent* Gestion d'un rendu XHTML pour Papyrus.** Revision 1.5 2006/10/31 15:06:44 jp_milcent* Fin de gestion des flux rss.** 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 ----------------------------------------------------------------------------------------+*/?>