Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 1528 → Rev 1529

/trunk/papyrus/applettes/syndication/syndication.php
21,7 → 21,7
// | 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.6 2007-06-25 12:15:07 alexandre_tb Exp $
// CVS : $Id: syndication.php,v 1.7 2007-07-25 15:09:44 jp_milcent Exp $
/**
* papyrus_bp - syndication.php
*
33,7 → 33,7
//Autres auteurs :
*@author Aucun
*@copyright Tela-Botanica 1999-2006
*@version $Revision: 1.6 $ $Date: 2007-06-25 12:15:07 $
*@version $Revision: 1.7 $ $Date: 2007-07-25 15:09:44 $
// +------------------------------------------------------------------------------------------------------+
*/
 
68,7 → 68,7
}
/** 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/RSS.php';
require_once PAP_CHEMIN_API_PEAR.'XML/Feed/Parser.php';
// +------------------------------------------------------------------------------------------------------+
// | CORPS du PROGRAMME |
// +------------------------------------------------------------------------------------------------------+
135,12 → 135,16
foreach ($tab_url as $cle => $url) {
if ($url != '') {
$aso_site = array();
$rss =& new XML_RSS(str_replace('&', '&', $url));
$rss->parse();
try {
$feed = new XML_Feed_Parser(file_get_contents($url));
} catch (XML_Feed_Parser_Exception $e) {
die('Le flux RSS est invalide : ' . $e->getMessage());
}
if ($options['template'] != '' && !file_exists($options['template'])) {
$i = 0 ;
$res= '';
foreach ($rss->getItems() as $item) {
foreach ($feed 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'])) {
149,27 → 153,27
} else {
$all = false;
}
if (isset($item['summary'])) {
$item['description'] = $item['summary'];
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 (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');
if (!isset($item->pubdate)) {
$item->pubdate = date('dmY');
}
// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
// lorsque les flux donne des dates au format iso
if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item['pubdate'], $match)) {
$item['pubdate'] = $match[3].'-'.$match[2].'-'.$match[1];
if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item->pubdate, $match)) {
$item->pubdate = $match[3].'-'.$match[2].'-'.$match[1];
//echo $item['pubdate'];
}
$res .= str_replace ('{num}', ++$i,
str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.htmlentities($item['title']).'</a>',
str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])),
str_replace ('{description}', $item['description'], $options['template'])))) ;
str_replace ('{item}', '<a href="'.$item->link.'" target="_top">'.htmlentities($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;
177,18 → 181,15
}
return $res;
}
$channel=$rss->getChannelInfo();
//var_dump($channel);
// Gestion du titre
if ( $options['titre'] == '' ) {
$aso_site['titre'] = utf8_decode($channel['title']);
$aso_site['titre'] = utf8_decode($feed->title);
} else if ( $options['titre'] != '0' ) {
$aso_site['titre'] = utf8_decode($options['titre']);
$aso_site['titre'] = $options['titre'];
}
// Gestion de l'url du site
if (isset($channel['link'])) {
$aso_site['url'] = htmlentities($channel['link']);
}
$aso_site['url'] = htmlentities($feed->link);
 
// Ouverture du lien dans une nouvelle fenetre
$aso_site['ext'] = false;
if ($options['nouvellefenetre'] == 1) {
196,8 → 197,9
}
// Gestion des pages syndiquees
$i = 0;
$nb_item = count($rss->getItems());
foreach ($rss->getItems() as $item) {
$nb_item = $feed->numberEntries;
foreach ($feed as $item) {
//echo '<pre>'.print_r($item, true).'</pre>';
if ($options['nb'] != 0 && $nb_item >= $options['nb'] && $i >= $options['nb']) {
break;
}
204,50 → 206,42
$i++;
$aso_page = array();
$aso_page['site'] = $aso_site;
$aso_page['url'] = $item['link'];
$aso_page['titre'] = utf8_decode($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'] = '';
}
$aso_page['url'] = $item->link;
$aso_page['titre'] = utf8_decode($item->title);
$aso_page['date'] = $item->pubDate;
if ($options['formatdatepro']) {
switch ($options['formatdatepro']) {
case 'jm' :
$aso_page['date'] = strftime('%d.%m', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
break;
case 'jma' :
$aso_page['date'] = strftime('%d.%m.%Y', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
break;
case 'jmh' :
$aso_page['date'] = strftime('%d.%m %H:%M', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
break;
case 'jmah' :
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
break;
default :
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
}
} else {
switch ($options['formatdate']) {
case 'jm' :
$aso_page['date'] = strftime('%d.%m', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m', $aso_page['date']);
break;
case 'jma' :
$aso_page['date'] = strftime('%d.%m.%Y', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m.%Y', $aso_page['date']);
break;
case 'jmh' :
$aso_page['date'] = strftime('%d.%m %H:%M', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m %H:%M', $aso_page['date']);
break;
case 'jmah' :
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
break;
default :
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', strtotime($aso_page['date']));
$aso_page['date'] = strftime('%d.%m.%Y %H:%M', $aso_page['date']);
}
}
$aso_site['pages'][] = $aso_page;
282,6 → 276,18
/* +--Fin du code ----------------------------------------------------------------------------------------+
*
* $Log: not supported by cvs2svn $
* Revision 1.5.2.4 2007-07-25 15:07:52 jp_milcent
* Correction problème url.
*
* Revision 1.5.2.3 2007-07-25 14:50:21 jp_milcent
* Corrections, meilleure utilisation de XML_Feed_Parser.
*
* Revision 1.5.2.2 2007-07-25 09:45:07 jp_milcent
* Utilisation de XML_Feed_Parser de Pear pour l'applette Syndication.
*
* Revision 1.6 2007-06-25 12:15:07 alexandre_tb
* merge from narmer
*
* Revision 1.5.2.1 2007-06-06 15:24:37 jp_milcent
* Amélioration de la compatibilité avec les anciennes version des balises de l'applette syndication.
*