Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 2080 → Rev 2081

/trunk/papyrus/applettes/syndication/syndication.php
47,6 → 47,10
'(url="[^"]*")|'.
'(titre="[^"]*")|'.
'(nb="?\d+"?)|'.
'(tailledesc="?\d+"?)|'.
'(voirsuite="[^"]*")|'.
'(dureecache="?\d+"?)|'.
'(id="[^"]*")|'.
'(nbmax="?\d+"?)|'.
'(nouvellefenetre="?(?:0|1)"?)|'.
'(formatdate="[^"]*")|'.
99,6 → 103,7
// Gestion des arguments
$balise = $tab_applette_arguments[0];
$tab_arguments = $tab_applette_arguments;
unset($tab_arguments[0]);
foreach($tab_arguments as $argument) {
if ($argument != '') {
109,13 → 114,18
}
 
$id_cache = md5($string_arguments);
//Greg : possibilité d'ajouter une durée au cache
if (!isset($options['dureecache'])) {
$options['dureecache'] = CACHE_LIFETIME;
}
 
if($contenu_cache = verifierCache($id_cache)) {
if($contenu_cache = verifierCache($id_cache, $options['dureecache'])) {
return $contenu_cache;
}
//
//+----------------------------------------------------------------------------------------------------------------+
// Gestion des erreurs de paramétrage
if (!isset($options['url'])) {
$GLOBALS['_SYNDICATION_']['erreurs'][] = sprintf(SYND_LG_ERREUR_URL, $balise);
}
128,7 → 138,7
if (!isset($options['nbmax'])) {
$options['nbmax'] = SYND_NOMBRE_MAX;
}
if (!isset($options['nouvellefenetre'])) {
if (!isset($options['nouvellefenetre'])) {
$options['nouvellefenetre'] = SYND_OUVRIR_LIEN_RSS_NOUVELLE_FENETRE;
}
if (!isset($options['formatdate'])) {
144,7 → 154,10
$options['template'] = SYND_CHEMIN_SQUELETTE.$options['template'];
}
}
 
//+----------------------------------------------------------------------------------------------------------------+
// Recuperation des donnees
if (count($GLOBALS['_SYNDICATION_']['erreurs']) == 0) {
206,6 → 219,17
} else if ( $options['titre'] != '0' ) {
$aso_site['titre'] = $options['titre'];
}
//Gestion de l'ID
if ( $options['id'] != '' ) {
$aso_site['id'] = $options['id'];
}
//Gestion du lien vers la suite
if ( $options['voirsuite'] != '' ) {
$aso_site['voirsuite'] = $options['voirsuite'];
}
// Gestion de l'url du site
$aso_site['url'] = htmlentities($feed->link);
 
219,7 → 243,7
$nb_item = $feed->numberEntries;
 
foreach ($feed as $item) {
 
if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
break;
}
230,8 → 254,67
$aso_page['url'] = htmlentities($item->link);
$aso_page['titre'] = mb_convert_encoding($item->title, 'HTML-ENTITIES', $encodages);
$aso_page['description'] = mb_convert_encoding($item->description, 'HTML-ENTITIES', $encodages);
/* Extraction de l'image si incluse dans description */
$image = "";
$description = $aso_page['description'];
$taille = $options['tailledesc'];
if (!(strpos($description, '<img') === false)) {
$pos_debut = strpos($description, '<img');
$pos_fin_image = strpos($description, '>', $posimage) + 1;
$image = substr($description, $pos_debut, ($pos_fin_image - $pos_debut));
$description = substr_replace($description,' ', $pos_debut, ($pos_fin_image - $pos_debut));
}
$aso_page['image'] = $image;
$aso_page['description_sans_image'] = $description;
 
if ($taille != null) {
//Attention : si on coupe simplement, on peut couper une balise en plein milieu.
//On va donc vérifier
//1. recherche de tags simples <i> ou <b>
$description = html_entity_decode($description);
$description = strip_tags($description, "<i><b>");
//Va-ton couper un mot ?
if ($description[$taille] != ' ' && $description[$taille+1] != ' ' && $description[$taille-1] != ' ') {
$strpos = strpos($description, ' ', $taille);
if ($strpos === true) {
$taille = $strpos;
}
}
$description = substr($description, 0, $taille);
$description.='(...)';
$pattern = '#<([ib])[ ]*[a-z]*>(.*?)</\1>#i';
//1. remplacer toutes le s balises fermées
$chaine = preg_replace($pattern, '$2', $description);
$nb_occurences_i = substr_count($chaine, '<i');
for ($occurences = 0; $occurences < $nb_occurences_i; $occurences++) {
$description .= "</i>";
}
$nb_occurences_b = substr_count($chaine, '<b');
for ($occurences = 0; $occurences < $nb_occurences_b; $occurences++) {
$description .= "</b>";
}
}
$aso_page['description_light'] = $description;
 
//Greg : ajout GUID
$aso_page['guid'] = mb_convert_encoding($item->model->getElementsByTagName('guid')->item(0)->nodeValue, '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;
if ($options['formatdatepro']) {
switch ($options['formatdatepro']) {
291,7 → 374,7
include($options['template']);
// Recuperer le contenu du buffer
$sortie = ob_get_contents();
creer_cache($id_cache,$sortie);
creer_cache($id_cache,$sortie, $options['dureecache']);
// Arrete et detruit le buffer
ob_end_clean();
 
355,4 → 438,4
*
* +-- Fin du code ----------------------------------------------------------------------------------------+
*/
?>
?>