4 |
david |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************\
|
|
|
4 |
* SPIP, Systeme de publication pour l'internet *
|
|
|
5 |
* *
|
|
|
6 |
* Copyright (c) 2001-2005 *
|
|
|
7 |
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
|
|
|
8 |
* *
|
|
|
9 |
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
|
|
|
10 |
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
|
|
|
11 |
\***************************************************************************/
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
//
|
|
|
15 |
// Ce fichier ne sera execute qu'une fois
|
|
|
16 |
if (defined("_INC_RSS")) return;
|
|
|
17 |
define("_INC_RSS", "1");
|
|
|
18 |
|
|
|
19 |
|
|
|
20 |
// mais d'abord un tri par date (inverse)
|
|
|
21 |
function trier_par_date($a, $b) {
|
|
|
22 |
return ($a['date'] < $b['date']);
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
|
|
|
26 |
//
|
|
|
27 |
// Prend un tableau et l'affiche au format rss
|
|
|
28 |
// (fonction inverse de analyser_backend)
|
|
|
29 |
// A completer (il manque des tests, des valeurs par defaut, les enclosures,
|
|
|
30 |
// differents formats de sortie, etc.)
|
|
|
31 |
//
|
|
|
32 |
function affiche_rss($rss, $intro = '', $fmt='') {
|
|
|
33 |
if (!$fmt) $fmt = 'rss';
|
|
|
34 |
if (function_exists($f = 'affiche_rss_'.$fmt)) {
|
|
|
35 |
return $f($rss, $intro);
|
|
|
36 |
}
|
|
|
37 |
else
|
|
|
38 |
spip_log("Format $fmt inconnu");
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
function affiche_rss_rss($rss, $intro = '') {
|
|
|
42 |
// entetes
|
|
|
43 |
$u = '<'.'?xml version="1.0" encoding="'.lire_meta('charset').'"?'.">\n";
|
|
|
44 |
|
|
|
45 |
$u .= '
|
|
|
46 |
<rss version="0.91" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
|
|
47 |
<channel>
|
|
|
48 |
<title>'.texte_backend($intro['title']).'</title>
|
|
|
49 |
<link>'.texte_backend(url_absolue($intro['url'])).'</link>
|
|
|
50 |
<description>'.texte_backend($intro['description']).'</description>
|
|
|
51 |
<language>'.texte_backend($intro['language']).'</language>
|
|
|
52 |
';
|
|
|
53 |
|
|
|
54 |
// elements
|
|
|
55 |
if (is_array($rss)) {
|
|
|
56 |
usort($rss, 'trier_par_date');
|
|
|
57 |
foreach ($rss as $article) {
|
|
|
58 |
if ($article['email'])
|
|
|
59 |
$article['author'].=' <'.$article['email'].'>';
|
|
|
60 |
$u .= '
|
|
|
61 |
<item>
|
|
|
62 |
<title>'.texte_backend($article['title']).'</title>
|
|
|
63 |
<link>'.texte_backend(url_absolue($article['url'])).'</link>
|
|
|
64 |
<date>'.texte_backend($article['date']).'</date>
|
|
|
65 |
<description>'.
|
|
|
66 |
texte_backend(liens_absolus($article['description']))
|
|
|
67 |
.'</description>
|
|
|
68 |
<author>'.texte_backend($article['author']).'</author>
|
|
|
69 |
<dc:date>'.date_iso($article['date']).'</dc:date>
|
|
|
70 |
<dc:format>text/html</dc:format>
|
|
|
71 |
<dc:language>'.texte_backend($article['lang']).'</dc:language>
|
|
|
72 |
<dc:creator>'.texte_backend($article['author']).'</dc:creator>
|
|
|
73 |
</item>
|
|
|
74 |
';
|
|
|
75 |
}
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
// pied
|
|
|
79 |
$u .= '
|
|
|
80 |
</channel>
|
|
|
81 |
</rss>
|
|
|
82 |
';
|
|
|
83 |
|
|
|
84 |
return array($u, 'Content-Type: text/xml; charset='.lire_meta('charset'));
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
function affiche_rss_ical($rss, $intro = '') {
|
|
|
88 |
|
|
|
89 |
// entetes
|
|
|
90 |
$u =
|
|
|
91 |
'BEGIN:VCALENDAR
|
|
|
92 |
CALSCALE:GREGORIAN
|
|
|
93 |
X-WR-CALNAME;VALUE=TEXT:'.filtrer_ical($intro['title']).'
|
|
|
94 |
X-WR-RELCALID:'.filtrer_ical(url_absolue($intro['url'])).'
|
|
|
95 |
';
|
|
|
96 |
|
|
|
97 |
// elements
|
|
|
98 |
if (is_array($rss)) {
|
|
|
99 |
usort($rss, 'trier_par_date');
|
|
|
100 |
foreach ($rss as $article) {
|
|
|
101 |
|
|
|
102 |
// Regler la date de fin a h+60min
|
|
|
103 |
if (!$article['enddate'])
|
|
|
104 |
$article['enddate'] = date_ical($article['date'],60);
|
|
|
105 |
else
|
|
|
106 |
$article['enddate'] = date_ical($article['enddate']);
|
|
|
107 |
|
|
|
108 |
// Type d'evenement
|
|
|
109 |
if ($article['type'] == 'todo')
|
|
|
110 |
$type = 'VTODO';
|
|
|
111 |
else
|
|
|
112 |
$type = 'VEVENT';
|
|
|
113 |
|
|
|
114 |
$u .=
|
|
|
115 |
'BEGIN:'.$type.'
|
|
|
116 |
SUMMARY:'.filtrer_ical($article['title']).'
|
|
|
117 |
URL:'.filtrer_ical(url_absolue($article['url'])).'
|
|
|
118 |
DTSTAMP:'. date_ical($article['date']).'
|
|
|
119 |
DTSTART:'. date_ical($article['date']).'
|
|
|
120 |
DTEND:'. $article['enddate'].'
|
|
|
121 |
DESCRIPTION:'.filtrer_ical(liens_absolus($article['description'])).'
|
|
|
122 |
ORGANIZER:'.filtrer_ical($article['author']).'
|
|
|
123 |
CATEGORIES:--
|
|
|
124 |
END:'.$type.'
|
|
|
125 |
';
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
// pied
|
|
|
130 |
$u .= 'END:VCALENDAR';
|
|
|
131 |
|
|
|
132 |
return array($u, 'Content-Type: text/calendar; charset=utf-8');
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
|
|
|
136 |
//
|
|
|
137 |
// Creer un bouton qui renvoie vers la bonne url spip_rss
|
|
|
138 |
function bouton_spip_rss($op, $args, $fmt='rss') {
|
|
|
139 |
include_ecrire("inc_acces.php3");
|
|
|
140 |
|
|
|
141 |
if (is_array($args))
|
|
|
142 |
foreach ($args as $val => $var)
|
|
|
143 |
if ($var) $a .= $val.'-'.$var.':';
|
|
|
144 |
$a = substr($a,0,-1);
|
|
|
145 |
|
|
|
146 |
$link = new Link("spip_rss.php?op=$op");
|
|
|
147 |
if ($a) $link->addVar('args', $a);
|
|
|
148 |
$link->addVar('id', $GLOBALS['connect_id_auteur']);
|
|
|
149 |
$cle = afficher_low_sec($GLOBALS['connect_id_auteur'], "rss $op $a");
|
|
|
150 |
$link->addVar('cle', $cle);
|
|
|
151 |
$link->addVar('lang', $GLOBALS['spip_lang']);
|
|
|
152 |
|
|
|
153 |
$url = $link->getUrl();
|
|
|
154 |
|
|
|
155 |
switch($fmt) {
|
|
|
156 |
case 'ical':
|
|
|
157 |
$url = preg_replace(',^.*?://,', 'webcal://', url_absolue($url))
|
|
|
158 |
. "&fmt=ical";
|
|
|
159 |
$button = 'iCal';
|
|
|
160 |
break;
|
|
|
161 |
case 'rss':
|
|
|
162 |
default:
|
|
|
163 |
$url = url_absolue($url);
|
|
|
164 |
$button = 'RSS';
|
|
|
165 |
break;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
return "<a href='"
|
|
|
169 |
. $url
|
|
|
170 |
. "'>"
|
|
|
171 |
. '<span class="rss-button">'.$button.'</span>'
|
|
|
172 |
. "</a>";
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
|
|
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
|
179 |
//
|
|
|
180 |
// Fonctions de remplissage du RSS
|
|
|
181 |
//
|
|
|
182 |
|
|
|
183 |
|
|
|
184 |
// Suivi des revisions d'articles
|
|
|
185 |
function rss_suivi_versions($a) {
|
|
|
186 |
include_ecrire("inc_suivi_revisions.php");
|
|
|
187 |
include_ecrire("lab_revisions.php");
|
|
|
188 |
include_ecrire("lab_diff.php");
|
|
|
189 |
include_ecrire("inc_presentation.php3");
|
|
|
190 |
$rss = afficher_suivi_versions (0, $a['id_secteur'], $a['id_auteur'], $a['lang_choisie'], true, true);
|
|
|
191 |
return $rss;
|
|
|
192 |
}
|
|
|
193 |
|
|
|
194 |
// Suivi des forums
|
|
|
195 |
function rss_suivi_forums($a, $query_forum='', $lien_moderation=false) {
|
|
|
196 |
include_ecrire("inc_forum.php3");
|
|
|
197 |
|
|
|
198 |
$result_forum = spip_query("
|
|
|
199 |
SELECT *
|
|
|
200 |
FROM spip_forum
|
|
|
201 |
WHERE " . $query_forum . "
|
|
|
202 |
ORDER BY date_heure DESC LIMIT 0,20"
|
|
|
203 |
);
|
|
|
204 |
|
|
|
205 |
while ($t = spip_fetch_array($result_forum)) {
|
|
|
206 |
$item = array();
|
|
|
207 |
$item['title'] = typo($t['titre']);
|
|
|
208 |
if ($a['page'] == 'public'
|
|
|
209 |
AND $t['statut']<>'publie'
|
|
|
210 |
)
|
|
|
211 |
$item['title'] .= ' ('.$t['statut'].')';
|
|
|
212 |
$item['date'] = $t['date_heure'];
|
|
|
213 |
$item['author'] = $t['auteur'];
|
|
|
214 |
$item['email'] = $t['email_auteur'];
|
|
|
215 |
|
|
|
216 |
if ($lien_moderation)
|
|
|
217 |
$item['url'] = _DIR_RESTREINT_ABS
|
|
|
218 |
.'controle_forum.php3?page='.$a['page']
|
|
|
219 |
.'&debut_id_forum='.$t['id_forum'];
|
|
|
220 |
else
|
|
|
221 |
$item['url'] = generer_url_forum($t['id_forum']);
|
|
|
222 |
|
|
|
223 |
$item['description'] = propre($t['texte']);
|
|
|
224 |
if ($GLOBALS['les_notes']) {
|
|
|
225 |
$item['description'] .= '<hr />'.$GLOBALS['les_notes'];
|
|
|
226 |
$GLOBALS['les_notes'] = '';
|
|
|
227 |
}
|
|
|
228 |
if ($t['nom_site'] OR vider_url($t['url_site']))
|
|
|
229 |
$item['description'] .= propre("\n- [".$t['nom_site']."->".$t['url_site']."]<br />");
|
|
|
230 |
|
|
|
231 |
$rss[] = $item;
|
|
|
232 |
}
|
|
|
233 |
|
|
|
234 |
return $rss;
|
|
|
235 |
}
|
|
|
236 |
|
|
|
237 |
|
|
|
238 |
|
|
|
239 |
// Suivi de la messagerie privee
|
|
|
240 |
function rss_suivi_messagerie($a) {
|
|
|
241 |
$rss = array();
|
|
|
242 |
|
|
|
243 |
// 1. les messages
|
|
|
244 |
$s = spip_query("SELECT * FROM spip_messages AS messages,
|
|
|
245 |
spip_auteurs_messages AS lien WHERE lien.id_auteur=".$a['id_auteur']
|
|
|
246 |
." AND lien.id_message=messages.id_message
|
|
|
247 |
GROUP BY messages.id_message ORDER BY messages.date_heure DESC");
|
|
|
248 |
while ($t = spip_fetch_array($s)) {
|
|
|
249 |
if ($compte++<10) {
|
|
|
250 |
$auteur = spip_fetch_array(spip_query("SELECT
|
|
|
251 |
auteurs.nom AS nom, auteurs.email AS email
|
|
|
252 |
FROM spip_auteurs AS auteurs,
|
|
|
253 |
spip_auteurs_messages AS lien
|
|
|
254 |
WHERE lien.id_message=".$t['id_message']."
|
|
|
255 |
AND lien.id_auteur!=".$t['id_auteur']."
|
|
|
256 |
AND lien.id_auteur = auteurs.id_auteur"));
|
|
|
257 |
$item = array(
|
|
|
258 |
'title' => typo($t['titre']),
|
|
|
259 |
'date' => $t['date_heure'],
|
|
|
260 |
'author' => typo($auteur['nom']),
|
|
|
261 |
'email' => $auteur['email'],
|
|
|
262 |
'description' => propre($t['texte']),
|
|
|
263 |
'url' => _DIR_RESTREINT_ABS
|
|
|
264 |
.'message.php3?id_message='.$t['id_message']
|
|
|
265 |
);
|
|
|
266 |
$rss[] = $item;
|
|
|
267 |
}
|
|
|
268 |
$messages_vus[] = $t['id_message'];
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
// 2. les reponses aux messages
|
|
|
272 |
if ($messages_vus) {
|
|
|
273 |
$s = spip_query("SELECT * FROM spip_forum WHERE id_message
|
|
|
274 |
IN (".join(',', $messages_vus).")
|
|
|
275 |
ORDER BY date_heure DESC LIMIT 0,10");
|
|
|
276 |
|
|
|
277 |
while ($t = spip_fetch_array($s)) {
|
|
|
278 |
$item = array(
|
|
|
279 |
'title' => typo($t['titre']),
|
|
|
280 |
'date' => $t['date_heure'],
|
|
|
281 |
'description' => propre($t['texte']),
|
|
|
282 |
'author' => typo($t['auteur']),
|
|
|
283 |
'email' => $t['email_auteur'],
|
|
|
284 |
'url' => _DIR_RESTREINT_ABS
|
|
|
285 |
.'message.php3?id_message='.$t['id_message']
|
|
|
286 |
.'#'.$t['id_forum']
|
|
|
287 |
);
|
|
|
288 |
$rss[] = $item;
|
|
|
289 |
}
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
return $rss;
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
// Suivi de la page "a suivre" : articles, breves, sites proposes et publies
|
|
|
296 |
function rss_a_suivre($a) {
|
|
|
297 |
$rss_articles = rss_articles("statut = 'prop'");
|
|
|
298 |
$rss_breves = rss_breves("statut = 'prop'");
|
|
|
299 |
$rss_sites = rss_sites("statut = 'prop'");
|
|
|
300 |
|
|
|
301 |
return array_merge($rss_articles, $rss_breves, $rss_sites);
|
|
|
302 |
}
|
|
|
303 |
|
|
|
304 |
function rss_articles($critere) {
|
|
|
305 |
$s = spip_query("SELECT * FROM spip_articles WHERE $critere
|
|
|
306 |
ORDER BY date DESC LIMIT 0,10");
|
|
|
307 |
while ($t = spip_fetch_array($s)) {
|
|
|
308 |
$auteur = spip_fetch_array(spip_query("SELECT
|
|
|
309 |
auteurs.nom AS nom, auteurs.email AS email
|
|
|
310 |
FROM spip_auteurs AS auteurs,
|
|
|
311 |
spip_auteurs_articles AS lien
|
|
|
312 |
WHERE lien.id_article=".$t['id_article']."
|
|
|
313 |
AND lien.id_auteur = auteurs.id_auteur"));
|
|
|
314 |
$item = array(
|
|
|
315 |
'title' => typo($t['titre']),
|
|
|
316 |
'date' => $t['date'],
|
|
|
317 |
'author' => typo($auteur['nom']),
|
|
|
318 |
'email' => $auteur['email'],
|
|
|
319 |
'description' => propre(couper("{{".$t['chapo']."}}\n\n".$t['texte'],300)),
|
|
|
320 |
'url' => _DIR_RESTREINT_ABS
|
|
|
321 |
.'articles.php3?id_article='.$t['id_article']
|
|
|
322 |
);
|
|
|
323 |
if ($t['statut'] == 'prop')
|
|
|
324 |
$item['title'] = _T('info_article_propose').' : '.$item['title'];
|
|
|
325 |
|
|
|
326 |
$rss[] = $item;
|
|
|
327 |
}
|
|
|
328 |
return $rss;
|
|
|
329 |
}
|
|
|
330 |
|
|
|
331 |
|
|
|
332 |
function rss_breves($critere) {
|
|
|
333 |
$s = spip_query("SELECT * FROM spip_breves WHERE $critere
|
|
|
334 |
ORDER BY date_heure DESC LIMIT 0,10");
|
|
|
335 |
while ($t = spip_fetch_array($s)) {
|
|
|
336 |
$item = array(
|
|
|
337 |
'title' => typo($t['titre']),
|
|
|
338 |
'date' => $t['date_heure'],
|
|
|
339 |
'description' => propre(couper($t['texte'],300)),
|
|
|
340 |
'url' => _DIR_RESTREINT_ABS
|
|
|
341 |
.'breves_voir.php3?id_breve='.$t['id_breve']
|
|
|
342 |
);
|
|
|
343 |
if ($t['statut'] == 'prop')
|
|
|
344 |
$item['title'] = _T('titre_breve_proposee').' : '.$item['title'];
|
|
|
345 |
|
|
|
346 |
$rss[] = $item;
|
|
|
347 |
}
|
|
|
348 |
return $rss;
|
|
|
349 |
}
|
|
|
350 |
|
|
|
351 |
|
|
|
352 |
function rss_sites($critere) {
|
|
|
353 |
$s = spip_query("SELECT * FROM spip_syndic WHERE $critere
|
|
|
354 |
ORDER BY date DESC LIMIT 0,10");
|
|
|
355 |
while ($t = spip_fetch_array($s)) {
|
|
|
356 |
$item = array(
|
|
|
357 |
'title' => typo($t['titre']." ".$t['url_site']),
|
|
|
358 |
'date' => $t['date'],
|
|
|
359 |
'description' => propre(couper($t['texte'],300)),
|
|
|
360 |
'url' => _DIR_RESTREINT_ABS
|
|
|
361 |
.'sites.php3?id_syndic='.$t['id_syndic']
|
|
|
362 |
);
|
|
|
363 |
if ($t['statut'] == 'prop')
|
|
|
364 |
$item['title'] = _T('info_site_attente').' : '.$item['title'];
|
|
|
365 |
|
|
|
366 |
$rss[] = $item;
|
|
|
367 |
}
|
|
|
368 |
return $rss;
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
|
|
|
372 |
?>
|