New file |
0,0 → 1,265 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 5.1 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of papyrus_bp. | |
// | | |
// | Foobar is free software; you can redistribute it and/or modify | |
// | it under the terms of the GNU General Public License as published by | |
// | the Free Software Foundation; either version 2 of the License, or | |
// | (at your option) any later version. | |
// | | |
// | Foobar 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 General Public License for more details. | |
// | | |
// | You should have received a copy of the GNU General Public License | |
// | along with Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id: syndication.php,v 1.1 2006-12-13 17:06:36 jp_milcent Exp $ |
/** |
* papyrus_bp - syndication.php |
* |
* Description : |
* |
*@package papyrus_bp |
//Auteur original : |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
//Autres auteurs : |
*@author Aucun |
*@copyright Tela-Botanica 1999-2006 |
*@version $Revision: 1.1 $ $Date: 2006-12-13 17:06:36 $ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
|
// +------------------------------------------------------------------------------------------------------+ |
// | ENTÊTE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
$GLOBALS['_GEN_commun']['info_applette_nom_fonction'] = 'afficherSyndication'; |
$GLOBALS['_GEN_commun']['info_applette_balise'] = '\{\{[Ss]yndication'. |
'(?:\s*'. |
'(?:'. |
'(url="[^"]*")|'. |
'(titre="[^"]*")|'. |
'(nb=(?:"|)\d+(?:"|))|'. |
'(nouvellefenetre=(?:"|)(?:0|1)(?:"|))|'. |
'(formatdate="[^"]*")|'. |
'(formatdatepro="[^"]*")|'. |
'(template="[^"]*")|'. |
')'. |
')+'. |
'\s*\}\}'; |
// +------------------------------------------------------------------------------------------------------+ |
/** Inclusion du fichier de configuration de cette application.*/ |
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'configuration'.GEN_SEP.'synd_configuration.inc.php'; |
|
// Inclusion des fichiers de traduction de l'applette SYND de Papyrus |
if (file_exists(SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php')) { |
/** Inclusion du fichier de traduction suite à la transaction avec le navigateur.*/ |
require_once SYND_CHEMIN_LANGUE.'synd_langue_'.$GLOBALS['_GEN_commun']['i18n'].'.inc.php'; |
} else { |
/** Inclusion du fichier de traduction par défaut.*/ |
require_once SYND_CHEMIN_LANGUE.'synd_langue_'.SYND_I18N_DEFAUT.'.inc.php'; |
} |
/** Inclusion du fichier de la bibliotheque permettant de manipuler les flux RSS.*/ |
require_once(MAGPIE_DIR.'rss_fetch.inc'); |
|
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
/** Fonction afficherSyndication() - Retourne la liste des pages des sites syndiqués. |
* |
* Cette fonction retourne la liste des pages des sites syndiqués. |
* |
* @param array contient les arguments de la fonction. |
* @param array tableau global de Papyrus. |
* @return string XHTML la liste des pages. |
*/ |
function afficherSyndication($tab_applette_arguments, $_GEN_commun) |
{ |
// Initialisation des variables |
$sortie = ''; |
$GLOBALS['_SYNDICATION_']['erreurs'] = array(); |
$GLOBALS['_SYNDICATION_']['informations'] = array(); |
$GLOBALS['_SYNDICATION_']['sites'] = array(); |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Gestion des arguments |
$balise = $tab_applette_arguments[0]; |
$tab_arguments = $tab_applette_arguments; |
unset($tab_arguments[0]); |
foreach($tab_arguments as $argument) { |
if ($argument != '') { |
$tab_parametres = explode('=', $argument); |
$options[$tab_parametres[0]] = trim($tab_parametres[1], '"'); |
} |
} |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Gestion des erreurs de paramètrage |
if (!isset($options['url'])) { |
$GLOBALS['_SYNDICATION_']['erreurs'][] = sprintf(SYND_LG_ERREUR_URL, $balise); |
} |
if (!isset($options['titre'])) { |
$options['titre'] = ''; |
} |
if (!isset($options['nb'])) { |
$options['nb'] = SYND_NOMBRE; |
} |
if (!isset($options['nouvellefenetre'])) { |
$options['nouvellefenetre'] = SYND_OUVRIR_LIEN_RSS_NOUVELLE_FENETRE; |
} |
if (!isset($options['formatdate'])) { |
$options['formatdate'] = SYND_FORMAT_DATE; |
} |
if (!isset($options['formatdatepro'])) { |
$options['formatdatepro'] = SYND_FORMAT_DATE; |
} |
if (!isset($options['template'])) { |
$options['template'] = SYND_CHEMIN_SQUELETTE.SYND_SQUELETTE_LISTE; |
} else { |
if (file_exists(SYND_CHEMIN_SQUELETTE.$options['template'])) { |
$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template']; |
} |
} |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Récupération des données |
if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) { |
$tab_url = array_map('trim', explode(',', $options['url'])); |
foreach ($tab_url as $cle => $url) { |
if ($url != '') { |
$aso_site = array(); |
$url = str_replace('&', '&', $url) ; |
$rss = fetch_rss($url); |
//echo '<pre>'.print_r($rss, true).'</pre>'; |
if ($options['template'] != '' && !file_exists($options['template'])) { |
$i = 0 ; |
$res= ''; |
foreach ($rss->items as $item) { |
// Le test suivant pour savoir s il faut reduire l excendent de description |
// Si {all} est present dans le template on ne reduit pas |
if (preg_match ('/{all}/', $options['template'])) { |
$template = str_replace('{all}', '', $options['template']); |
$all = true ; |
} else { |
$all = false; |
} |
if (isset($item['summary'])) { |
$item['description'] = $item['summary']; |
} else { |
if (strlen($item['description']) > 200 && !$all) { |
$item['description'] = substr ($item['description'] , 0, 300). |
'... <a href="'.$item['link'].'">Lire la suite</a>'; |
} |
} |
if (!isset($item['pubdate'])) { |
$item['pubdate'] = date('dmY'); |
} |
$res .= str_replace ('{num}', ++$i, |
str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>', |
str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])), |
str_replace ('{description}', $item['description'], $options['template'])))) ; |
$res .= "\n"; |
if ($i > $options['nb']) { |
break; |
} |
} |
return $res; |
} |
// Gestion du titre |
if ( $options['titre'] == '' ) { |
$aso_site['titre'] = $rss->channel['title']; |
} else if ( $options['titre'] != '0' ) { |
$aso_site['titre'] = $options['titre']; |
} |
// Gestion de l'url du site |
if (isset($rss->channel['link'])) { |
$aso_site['url'] = $rss->channel['link']; |
} |
// Ouverture du lien dans une nouvelle fenêtre |
$aso_site['ext'] = false; |
if ($options['nouvellefenetre'] == 1) { |
$aso_site['ext'] = true; |
} |
// Gestion des pages syndiquées |
$i = 0; |
$nb_item = count($rss->items); |
|
foreach ($rss->items as $item) { |
$aso_page = array(); |
$aso_page['site'] = $aso_site; |
$aso_page['url'] = $item['link']; |
$aso_page['titre'] = $item['title']; |
if (isset($item['pubdate'])) { |
$aso_page['date'] = $item['pubdate']; |
} elseif (isset($item['date'])) { |
$aso_page['date'] = $item['date']; |
} elseif (isset($item['date_timestamp'])) { |
$aso_page['date'] = $item['date_timestamp']; |
} else { |
$aso_page['date'] = ''; |
} |
if ($options['formatdatepro']) { |
$aso_page['date'] = strftime($options['formatdatepro'], strtotime($aso_page['date'])); |
} else { |
switch ($options['formatdate']) { |
case 'jm' : |
$aso_page['date'] = strftime('%d.%m', strtotime($aso_page['date'])); |
break; |
case 'jma' : |
$aso_page['date'] = strftime('%d.%m.%Y', strtotime($aso_page['date'])); |
break; |
case 'jmh' : |
$aso_page['date'] = strftime('%d.%m %H:%M', strtotime($aso_page['date'])); |
break; |
case 'jmah' : |
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date'])); |
break; |
default : |
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date'])); |
} |
} |
if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) { |
break; |
} |
$aso_site['pages'][] = $aso_page; |
$GLOBALS['_SYNDICATION_']['pages'][strtotime($aso_page['date'])] = $aso_page; |
} |
$GLOBALS['_SYNDICATION_']['sites'][] = $aso_site; |
} |
} |
} |
// Trie des pages par date |
krsort($GLOBALS['_SYNDICATION_']['pages']); |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Extrait les variables et les ajoutes à l'espace de noms local |
// Gestion des squelettes |
extract($GLOBALS['_SYNDICATION_']); |
// Démarre le buffer |
ob_start(); |
// Inclusion du fichier |
include($options['template']); |
// Récupérer le contenu du buffer |
$sortie = ob_get_contents(); |
// Arrête et détruit le buffer |
ob_end_clean(); |
|
//+----------------------------------------------------------------------------------------------------------------+ |
// Sortie |
return $sortie; |
} |
|
/* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log: not supported by cvs2svn $ |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
?> |