771 |
florian |
1 |
<?php
|
1232 |
alexandre_ |
2 |
/*vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 4.1 |
|
|
|
5 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org) |
|
|
|
7 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
8 |
// | This library is free software; you can redistribute it and/or |
|
|
|
9 |
// | modify it under the terms of the GNU Lesser General Public |
|
|
|
10 |
// | License as published by the Free Software Foundation; either |
|
|
|
11 |
// | version 2.1 of the License, or (at your option) any later version. |
|
|
|
12 |
// | |
|
|
|
13 |
// | This library is distributed in the hope that it will be useful, |
|
|
|
14 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
15 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
16 |
// | Lesser General Public License for more details. |
|
|
|
17 |
// | |
|
|
|
18 |
// | You should have received a copy of the GNU Lesser General Public |
|
|
|
19 |
// | License along with this library; if not, write to the Free Software |
|
|
|
20 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
21 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
22 |
// CVS : $Id$
|
|
|
23 |
/**
|
|
|
24 |
*
|
|
|
25 |
* Fonctions du module rss de papyrus
|
|
|
26 |
*
|
|
|
27 |
*
|
|
|
28 |
*@package syndication_rss
|
|
|
29 |
//Auteur original :
|
|
|
30 |
*@author Alexandre Granier <alexandre@tela-botanica.org>
|
|
|
31 |
*@author Florian Schmitt <florian@ecole-et-nature.org>
|
|
|
32 |
//Autres auteurs :
|
|
|
33 |
*@copyright Tela-Botanica 2000-2007
|
|
|
34 |
*@version $Revision$
|
|
|
35 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
36 |
*/
|
771 |
florian |
37 |
|
772 |
florian |
38 |
define('MAGPIE_DIR', GEN_CHEMIN_API.'syndication_rss/magpierss/');
|
945 |
alexandre_ |
39 |
define('MAGPIE_CACHE_DIR', MAGPIE_DIR.'tmp/magpie_cache');
|
772 |
florian |
40 |
define('OUVRIR_LIEN_RSS_NOUVELLE_FENETRE', 1);
|
|
|
41 |
define('FORMAT_DATE', 'jma');
|
771 |
florian |
42 |
require_once(MAGPIE_DIR.'rss_fetch.inc');
|
|
|
43 |
|
843 |
alexandre_ |
44 |
function voir_rss($titre='', $url='', $nb=0, $nouvelle_fenetre=OUVRIR_LIEN_RSS_NOUVELLE_FENETRE, $formatdate=FORMAT_DATE, $template = "") {
|
771 |
florian |
45 |
$res= '';
|
|
|
46 |
if ( $url!='' ) {
|
|
|
47 |
$rss = fetch_rss( $url );
|
1039 |
alexandre_ |
48 |
|
843 |
alexandre_ |
49 |
if ($template != "") {
|
1039 |
alexandre_ |
50 |
$i = 0 ;
|
843 |
alexandre_ |
51 |
foreach ($rss->items as $item) {
|
945 |
alexandre_ |
52 |
// Le test suivant pour savoir s il faut reduire l excendent de description
|
|
|
53 |
// Si {all} est present dans le template on ne reduit pas
|
|
|
54 |
if (preg_match ('/{all}/', $template)) {
|
|
|
55 |
$template = str_replace('{all}', '', $template);
|
|
|
56 |
$all = true ;
|
1039 |
alexandre_ |
57 |
} else {
|
|
|
58 |
$all = false;
|
945 |
alexandre_ |
59 |
}
|
|
|
60 |
if (strlen($item['description']) > 200 && !$all) {
|
843 |
alexandre_ |
61 |
$item['description'] = substr ($item['description'] , 0, 300).'... <a href="'.$item['link'].'">Lire la suite</a>';
|
|
|
62 |
}
|
1039 |
alexandre_ |
63 |
if (!isset($item['pubdate'])) $item['pubdate'] = date('dmY');
|
1203 |
alexandre_ |
64 |
|
|
|
65 |
// Le code ci-apres est pour rattraper les dates du type 01012005 parsees par magpie
|
|
|
66 |
// lorsque les flux donne des dates au format iso
|
|
|
67 |
if (preg_match('/^([0-3][0-9])([0-1][0-9])([0-9][0-9][0-9][0-9])$/', $item['pubdate'], $match)) {
|
|
|
68 |
$item['pubdate'] = $match[3].'-'.$match[2].'-'.$match[1];
|
|
|
69 |
//echo $item['pubdate'];
|
|
|
70 |
}
|
843 |
alexandre_ |
71 |
$res .= str_replace ('{num}', ++$i,
|
|
|
72 |
str_replace ('{item}', '<a href="'.$item['link'].'" target="_top">'.$item['title'].'</a>',
|
945 |
alexandre_ |
73 |
str_replace ('{date}', strftime('%d.%m.%Y',strtotime($item['pubdate'])),
|
|
|
74 |
str_replace ('{description}', $item['description'], $template)))) ;
|
843 |
alexandre_ |
75 |
$res .= "\n";
|
1039 |
alexandre_ |
76 |
if ($i > $nb) break;
|
945 |
alexandre_ |
77 |
|
843 |
alexandre_ |
78 |
}
|
|
|
79 |
return $res ;
|
|
|
80 |
}
|
771 |
florian |
81 |
if ( $titre=='' ) {$res .= '<h2>'.$rss->channel['title'].'</h2>'."\n";}
|
|
|
82 |
elseif ( $titre!='0' ) {$res .= '<h2>'.$titre.'</h2>'."\n";}
|
|
|
83 |
$res .= '<ul class="liste_rss">'."\n";
|
|
|
84 |
$i=0;
|
772 |
florian |
85 |
$nb_item=count($rss->items);
|
771 |
florian |
86 |
if (($nb==0)or($nb_item<=$nb)) {
|
|
|
87 |
foreach ($rss->items as $item) {
|
|
|
88 |
$href = $item['link'];
|
|
|
89 |
$title = $item['title'];
|
772 |
florian |
90 |
$res .= '<li class="titre_rss">'."\n";
|
|
|
91 |
if (isset($item['pubdate'])) $date=$item['pubdate'];
|
|
|
92 |
elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
|
|
|
93 |
else $formatdate='';
|
|
|
94 |
if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
|
|
|
95 |
if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
|
|
|
96 |
if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
|
|
|
97 |
if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
|
|
|
98 |
$res .= '<a class="lien_rss" href="'.$href;
|
771 |
florian |
99 |
if ($nouvelle_fenetre==1) $res .= '" onclick="window.open(this.href); return false;';
|
|
|
100 |
$res .= '">'.$title.'</a></li>'."\n";
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
else {
|
|
|
104 |
$i=0;
|
|
|
105 |
foreach ($rss->items as $item) {
|
|
|
106 |
$href = $item['link'];
|
|
|
107 |
$title = $item['title'];
|
772 |
florian |
108 |
$res .= '<li class="titre_rss">'."\n";
|
771 |
florian |
109 |
if (isset($item['pubdate'])) $date=$item['pubdate'];
|
|
|
110 |
elseif ((!isset($item['pubdate']))and(isset($item['date_timestamp']))) $date=$item['date_timestamp'];
|
|
|
111 |
else $formatdate='';
|
|
|
112 |
if ($formatdate=='jm') {$res .= strftime('%d.%m',strtotime($date)).': ';}
|
|
|
113 |
if ($formatdate=='jma') {$res .= strftime('%d.%m.%Y',strtotime($date)).': ';}
|
|
|
114 |
if ($formatdate=='jmh') {$res .= strftime('%d.%m %H:%M',strtotime($date)).': ';}
|
|
|
115 |
if ($formatdate=='jmah') {$res .= strftime('%d.%m.%Y %H:%M',strtotime($date)).': ';}
|
772 |
florian |
116 |
$res .= '<a class="lien_rss" href="'.$href;
|
771 |
florian |
117 |
if ($nouvelle_fenetre==1) $res .= '" onclick="window.open(this.href); return false;';
|
|
|
118 |
$res .= '">'.$title.'</a></li>'."\n";
|
|
|
119 |
$i++;
|
|
|
120 |
if ($i>=$nb) break;
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
$res .= '</ul>'."\n";
|
|
|
124 |
}
|
|
|
125 |
//echo '<pre>'.var_dump($rss->items).'</pre><br /><br />';
|
|
|
126 |
return $res;
|
|
|
127 |
}
|
|
|
128 |
?>
|