Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2058 → Rev 2059

/trunk/papyrus/applettes/syndication/configuration/synd_configuration.inc.php
51,10 → 51,13
// Paramétrage de la bibliothèque de manipulation des flux RSS
/** Constante stockant le chemin vers la bibliothèque MAGPIERSS.*/
define('MAGPIE_DIR', GEN_CHEMIN_API.'syndication_rss/magpierss/');
/** Constante stockant le chemin vers le dossier de cache pour MAGPIERSS.*/
define('MAGPIE_CACHE_DIR', MAGPIE_DIR.'/tmp/magpie_cache');
/** Constante stockant le nombre de page syndiqués à afficher par site.*/
define('SYND_NOMBRE', 10);
 
/** Constante stockant le chemin vers le dossier de cache pour MAGPIERSS.*/
define('CACHE_DIR', PAP_CHEMIN_RACINE.'/tmp');
/** Constante stockant la durée de vie d'un fichier de cache **/
define('CACHE_LIFETIME', 24*60*60);
/** Constante stockant si oui ou non on ouvre une nouvelle fenêtre pour consulter la page d'un site syndiqué.*/
define('SYND_OUVRIR_LIEN_RSS_NOUVELLE_FENETRE', 1);
/** Constante stockant le format des dates.*/
72,10 → 75,10
/** Nom du fichier de squelette, par défaut, à utiliser pour la liste des pages.*/
define('SYND_SQUELETTE_LISTE', 'synd_liste.tpl.html');
 
$GLOBALS['jours'] = array (1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi',
$GLOBALS['jours'] = array (1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi',
6 => 'samedi', 0 => 'dimanche') ;
$GLOBALS['mois'] = array (1 => 'janvier', 2 => 'février', 3 => 'mars', 4 => 'avril', 5 => 'mai', 6 => 'juin',
7 => 'juillet', 8 => 'août', 9 => 'septembre', 10 => 'octobre', 11 =>'novembre',
7 => 'juillet', 8 => 'août', 9 => 'septembre', 10 => 'octobre', 11 =>'novembre',
12 => 'décembre') ;
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
/trunk/papyrus/applettes/syndication/syndication.php
47,6 → 47,7
'(url="[^"]*")|'.
'(titre="[^"]*")|'.
'(nb="?\d+"?)|'.
'(nbmax="?\d+"?)|'.
'(nouvellefenetre="?(?:0|1)"?)|'.
'(formatdate="[^"]*")|'.
'(formatdatepro="[^"]*")|'.
58,6 → 59,9
/** Inclusion du fichier de configuration de cette application.*/
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'configuration'.GEN_SEP.'synd_configuration.inc.php';
 
/** Inclusion du fichier de fonctions de cette application.*/
require_once GEN_CHEMIN_APPLETTE.'syndication'.GEN_SEP.'bibliotheque'.GEN_SEP.'syndication.fonct.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.*/
66,6 → 70,7
/** 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');
require_once PAP_CHEMIN_API_PEAR.'XML/Feed/Parser.php';
87,7 → 92,9
$GLOBALS['_SYNDICATION_']['erreurs'] = array();
$GLOBALS['_SYNDICATION_']['informations'] = array();
$GLOBALS['_SYNDICATION_']['sites'] = array();
 
 
$string_arguments = "";
//+----------------------------------------------------------------------------------------------------------------+
// Gestion des arguments
$balise = $tab_applette_arguments[0];
95,10 → 102,17
unset($tab_arguments[0]);
foreach($tab_arguments as $argument) {
if ($argument != '') {
$string_arguments .= $argument;
$tab_parametres = explode('=', $argument, 2);
$options[$tab_parametres[0]] = trim($tab_parametres[1], '"');
}
}
 
$id_cache = md5($string_arguments);
 
if($contenu_cache = verifierCache($id_cache)) {
return $contenu_cache;
}
//
//+----------------------------------------------------------------------------------------------------------------+
// Gestion des erreurs de paramétrage
111,6 → 125,9
if (!isset($options['nb'])) {
$options['nb'] = SYND_NOMBRE;
}
if (!isset($options['nbmax'])) {
$options['nbmax'] = SYND_NOMBRE_MAX;
}
if (!isset($options['nouvellefenetre'])) {
$options['nouvellefenetre'] = SYND_OUVRIR_LIEN_RSS_NOUVELLE_FENETRE;
}
127,7 → 144,7
$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template'];
}
}
 
//+----------------------------------------------------------------------------------------------------------------+
// Recuperation des donnees
if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) {
142,7 → 159,7
} catch (XML_Feed_Parser_Exception $e) {
return('Le flux RSS est invalide : ' . $e->getMessage());
}
 
if ($options['template'] != '' && !file_exists($options['template'])) {
$i = 0 ;
$res= '';
156,7 → 173,7
$all = false;
}
if (isset($item->summary)) {
$item->description = mb_convert_encoding($item->summary, 'HTML-ENTITIES', $encodages);
$item->description = mb_convert_encoding($item->summary, 'HTML-ENTITIES', $encodages);
} else {
if (strlen($item->description) > 200 && !$all) {
$item->description = substr(mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), 0, 300).
172,8 → 189,8
$item->pubdate = $match[3].'-'.$match[2].'-'.$match[1];
//echo $item['pubdate'];
}
$res .= str_replace ('{num}', ++$i,
str_replace ('{item}', '<a href="'.htmlentities($item->link).'" target="_top">'.mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages).'</a>',
$res .= str_replace ('{num}', ++$i,
str_replace ('{item}', '<a href="'.htmlentities($item->link).'" target="_top">'.mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages).'</a>',
str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item->pubdate)),
str_replace ('{description}', mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages), $options['template'])))) ;
$res .= "\n";
202,12 → 219,12
$nb_item = $feed->numberEntries;
 
foreach ($feed as $item) {
 
if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
break;
}
$i++;
 
$aso_page = array();
$aso_page['site'] = $aso_site;
$aso_page['url'] = htmlentities($item->link);
215,7 → 232,7
$aso_page['description'] = mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages);
$aso_page['category'] = mb_convert_encoding($item->model->getElementsByTagName('category')->item(0)->nodeValue, 'HTML-ENTITIES', $encodages);
$aso_page['author'] = mb_convert_encoding($item->author, 'HTML-ENTITIES', $encodages);
$aso_page['date'] = $item->pubDate;
$aso_page['date'] = $item->pubDate;
if ($options['formatdatepro']) {
switch ($options['formatdatepro']) {
case 'jm' :
259,9 → 276,11
}
}
// Trie des pages par date
//var_dump($GLOBALS['_SYNDICATION_']['pages']);
krsort($GLOBALS['_SYNDICATION_']['pages']);
 
$GLOBALS['_SYNDICATION_']['sites'] = array_slice($GLOBALS['_SYNDICATION_']['sites'],0,$options['nbmax'],true) ;
$GLOBALS['_SYNDICATION_']['pages'] = array_slice($GLOBALS['_SYNDICATION_']['pages'],0,$options['nbmax'],true) ;
 
//+----------------------------------------------------------------------------------------------------------------+
// Extrait les variables et les ajoutes a l'espace de noms local
// Gestion des squelettes
272,9 → 291,10
include($options['template']);
// Recuperer le contenu du buffer
$sortie = ob_get_contents();
creer_cache($id_cache,$sortie);
// Arrete et detruit le buffer
ob_end_clean();
 
//+----------------------------------------------------------------------------------------------------------------+
// Sortie
return $sortie;
/trunk/papyrus/applettes/syndication/bibliotheque/syndication.fonct.php
New file
0,0 → 1,36
<?php
/**
* PHP Version 5
*
* @category PHP
* @package papyrus_bp
* @author aurelien <aurelien@tela-botanica.org>
* @copyright 2009 Tela-Botanica
* @license http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version SVN: <svn_id>
* @link /doc/papyrus_bp/
*/
 
function verifierCache($id) {
 
$chemin_fichier_cache = CACHE_DIR.GEN_SEP.$id.'.html';
if(file_exists($chemin_fichier_cache ) && (time() - @filemtime($chemin_fichier_cache) < CACHE_LIFETIME)) {
return file_get_contents($chemin_fichier_cache);
} else {
return false;
}
}
 
function creer_cache($id, $contenu) {
 
$chemin_fichier_cache = CACHE_DIR.GEN_SEP.$id.'.html';
 
if(!file_exists($chemin_fichier_cache) || (time() - @filemtime($chemin_fichier_cache) > CACHE_LIFETIME)) {
 
$fh = fopen($chemin_fichier_cache,'w+');
if($fh) {
fputs($fh,$contenu);
}
}
}
?>