Commit | Line | Data |
---|---|---|
c495c100 P |
1 | <?php |
2 | ||
3 | /***************************************************************************\ | |
4 | * SPIP, Systeme de publication pour l'internet * | |
5 | * * | |
6 | * Copyright (c) 2001-2007 * | |
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 | if (!defined("_ECRIRE_INC_VERSION")) return; | |
15 | ||
16 | include_spip('inc/minipres'); | |
17 | include_spip('inc/acces'); | |
18 | include_spip('inc/texte'); // utile pour l'espace public, deja fait sinon | |
19 | ||
20 | // mais d'abord un tri par date (inverse) | |
21 | // http://doc.spip.org/@trier_par_date | |
22 | function trier_par_date($a, $b) { | |
23 | return ($a['date'] < $b['date']); | |
24 | } | |
25 | ||
26 | // | |
27 | // Fonctions de remplissage du RSS | |
28 | // | |
29 | ||
30 | // Suivi des revisions d'articles | |
31 | // http://doc.spip.org/@rss_suivi_versions | |
32 | function rss_suivi_versions($a) { | |
33 | include_spip('inc/suivi_versions'); | |
34 | return afficher_suivi_versions (0, $a['id_secteur'], $a['id_auteur'], $a['lang_choisie'], true, true); | |
35 | ||
36 | } | |
37 | ||
38 | // Suivi des forums | |
39 | // http://doc.spip.org/@rss_suivi_forums | |
40 | function rss_suivi_forums($a, $from, $where, $lien_moderation=false) { | |
41 | $rss = array(); | |
42 | ||
43 | $result_forum = spip_query("SELECT * FROM $from " . (!$where ? '' : " WHERE $where ") . "ORDER BY date_heure DESC LIMIT 20"); | |
44 | ||
45 | while ($t = spip_fetch_array($result_forum)) { | |
46 | $item = array(); | |
47 | $item['title'] = typo($t['titre']); | |
48 | if ($a['page'] == 'public' | |
49 | AND $t['statut']<>'publie' | |
50 | ) | |
51 | $item['title'] .= ' ('.$t['statut'].')'; | |
52 | $item['date'] = $t['date_heure']; | |
53 | $item['author'] = typo($t['auteur']); | |
54 | $item['email'] = $t['email_auteur']; | |
55 | ||
56 | if ($lien_moderation) | |
57 | $item['url'] = generer_url_ecrire('controle_forum', 'type='.$a['page'] .'&debut_id_forum='.$t['id_forum']); | |
58 | else | |
59 | $item['url'] = generer_url_forum($t['id_forum']); | |
60 | ||
61 | $item['description'] = propre($t['texte']); | |
62 | if ($GLOBALS['les_notes']) { | |
63 | $item['description'] .= '<hr />'.$GLOBALS['les_notes']; | |
64 | $GLOBALS['les_notes'] = ''; | |
65 | } | |
66 | if ($t['nom_site'] OR vider_url($t['url_site'])) | |
67 | $item['description'] .= propre("\n- [".$t['nom_site']."->".$t['url_site']."]<br />"); | |
68 | ||
69 | $rss[] = $item; | |
70 | } | |
71 | ||
72 | return $rss; | |
73 | } | |
74 | ||
75 | // Suivi de la messagerie privee | |
76 | // http://doc.spip.org/@rss_suivi_messagerie | |
77 | function rss_suivi_messagerie($a) { | |
78 | $rss = array(); | |
79 | ||
80 | // 1. les messages | |
81 | $s = spip_query("SELECT * FROM spip_messages AS messages, spip_auteurs_messages AS lien WHERE lien.id_auteur=".$a['id_auteur']." AND lien.id_message=messages.id_message GROUP BY messages.id_message ORDER BY messages.date_heure DESC"); | |
82 | while ($t = spip_fetch_array($s)) { | |
83 | if ($compte++<10) { | |
84 | $auteur = spip_fetch_array(spip_query("SELECT auteurs.nom AS nom, auteurs.email AS email FROM spip_auteurs AS auteurs, spip_auteurs_messages AS lien WHERE lien.id_message=".$t['id_message']." AND lien.id_auteur!=".$t['id_auteur']." AND lien.id_auteur = auteurs.id_auteur")); | |
85 | $item = array( | |
86 | 'title' => typo($t['titre']), | |
87 | 'date' => $t['date_heure'], | |
88 | 'author' => typo($auteur['nom']), | |
89 | 'email' => $auteur['email'], | |
90 | 'description' => propre($t['texte']), | |
91 | 'url' => generer_url_ecrire('message', 'id_message='.$t['id_message'] )); | |
92 | $rss[] = $item; | |
93 | } | |
94 | $messages_vus[] = $t['id_message']; | |
95 | } | |
96 | ||
97 | // 2. les reponses aux messages | |
98 | if ($messages_vus) { | |
99 | $s = spip_query("SELECT * FROM spip_forum WHERE id_message IN (".join(',', $messages_vus).") ORDER BY date_heure DESC LIMIT 10"); | |
100 | ||
101 | while ($t = spip_fetch_array($s)) { | |
102 | $item = array( | |
103 | 'title' => typo($t['titre']), | |
104 | 'date' => $t['date_heure'], | |
105 | 'description' => propre($t['texte']), | |
106 | 'author' => typo($t['auteur']), | |
107 | 'email' => $t['email_auteur'], | |
108 | 'url' => generer_url_ecrire('message', 'id_message='.$t['id_message'] .'#'.$t['id_forum'] )); | |
109 | $rss[] = $item; | |
110 | } | |
111 | } | |
112 | ||
113 | return $rss; | |
114 | } | |
115 | ||
116 | // Suivi de la page "a suivre" : articles, breves, sites proposes et publies | |
117 | // http://doc.spip.org/@rss_a_suivre | |
118 | function rss_a_suivre($a) { | |
119 | $rss_articles = rss_articles("statut = 'prop'"); | |
120 | $rss_breves = rss_breves("statut = 'prop'"); | |
121 | $rss_sites = rss_sites("statut = 'prop'"); | |
122 | ||
123 | return array_merge($rss_articles, $rss_breves, $rss_sites); | |
124 | } | |
125 | ||
126 | // http://doc.spip.org/@rss_articles | |
127 | function rss_articles($critere) { | |
128 | $rss = array(); | |
129 | $s = spip_query("SELECT * FROM spip_articles WHERE $critere ORDER BY date DESC LIMIT 10"); | |
130 | while ($t = spip_fetch_array($s)) { | |
131 | $auteur = spip_fetch_array(spip_query("SELECT auteurs.nom AS nom, auteurs.email AS email FROM spip_auteurs AS auteurs, spip_auteurs_articles AS lien WHERE lien.id_article=".$t['id_article']." AND lien.id_auteur = auteurs.id_auteur")); | |
132 | $item = array( | |
133 | 'title' => typo($t['titre']), | |
134 | 'date' => $t['date'], | |
135 | 'author' => typo($auteur['nom']), | |
136 | 'email' => $auteur['email'], | |
137 | 'description' => propre(couper("{{".$t['chapo']."}}\n\n".$t['texte'],300)), | |
138 | 'url' => generer_url_ecrire('articles', 'id_article='.$t['id_article'] )); | |
139 | if ($t['statut'] == 'prop') | |
140 | $item['title'] = _T('info_article_propose').' : '.$item['title']; | |
141 | ||
142 | $rss[] = $item; | |
143 | } | |
144 | return $rss; | |
145 | } | |
146 | ||
147 | ||
148 | // http://doc.spip.org/@rss_breves | |
149 | function rss_breves($critere) { | |
150 | $rss = array(); | |
151 | $s = spip_query("SELECT * FROM spip_breves WHERE $critere ORDER BY date_heure DESC LIMIT 10"); | |
152 | while ($t = spip_fetch_array($s)) { | |
153 | $item = array( | |
154 | 'title' => typo($t['titre']), | |
155 | 'date' => $t['date_heure'], | |
156 | 'description' => propre(couper($t['texte'],300)), | |
157 | 'url' => generer_url_ecrire('breves_voir', 'id_breve='.$t['id_breve'] )); | |
158 | if ($t['statut'] == 'prop') | |
159 | $item['title'] = _T('titre_breve_proposee').' : '.$item['title']; | |
160 | ||
161 | $rss[] = $item; | |
162 | } | |
163 | return $rss; | |
164 | } | |
165 | ||
166 | ||
167 | // http://doc.spip.org/@rss_sites | |
168 | function rss_sites($critere) { | |
169 | $rss = array(); | |
170 | $s = spip_query("SELECT * FROM spip_syndic WHERE $critere ORDER BY date DESC LIMIT 10"); | |
171 | while ($t = spip_fetch_array($s)) { | |
172 | $item = array( | |
173 | 'title' => typo($t['titre']." ".$t['url_site']), | |
174 | 'date' => $t['date'], | |
175 | 'description' => propre(couper($t['texte'],300)), | |
176 | 'url' => generer_url_ecrire('sites', 'id_syndic='.$t['id_syndic'] )); | |
177 | if ($t['statut'] == 'prop') | |
178 | $item['title'] = _T('info_site_attente').' : '.$item['title']; | |
179 | ||
180 | $rss[] = $item; | |
181 | } | |
182 | return $rss; | |
183 | } | |
184 | ||
185 | // On recoit un op (operation) + args (arguments) | |
186 | // + id (id_auteur) + cle (low_sec(id_auteur, "op args")) | |
187 | // On verifie que la cle correspond | |
188 | // On cree ensuite le RSS correspondant a l'operation | |
189 | ||
190 | ||
191 | // http://doc.spip.org/@action_rss_dist | |
192 | function action_rss_dist() | |
193 | { | |
194 | global $args, $cle, $fmt, $id, $lang, $op; | |
195 | ||
196 | charger_generer_url(); | |
197 | ||
198 | // | |
199 | // Verifier la securite du lien et decoder les arguments | |
200 | // | |
201 | ||
202 | // Pour memoire, la forme des URLs : | |
203 | // 1.8: spip_rss.php?op=forums&args=page-public&id=4&cle=047b4183&lang=fr | |
204 | // 1.9: spip.php?action=rss&op=forums&args=page-public&id=4&cle=047b4183&lang=fr | |
205 | // ou encore spip.php?action=rss&op=a-suivre&id=5&cle=5731e121&lang=fr | |
206 | ||
207 | spip_timer('rss'); | |
208 | if (!verifier_low_sec ($id, $cle, | |
209 | "rss $op $args" | |
210 | )) { | |
211 | $op = 'erreur securite'; | |
212 | unset($a); | |
213 | } else { | |
214 | $a = array(); | |
215 | foreach (split(':', $args) as $bout) { | |
216 | list($var, $val) = split('-', $bout, 2); | |
217 | $a[$var] = $val; | |
218 | } | |
219 | include_spip('inc/lang'); | |
220 | lang_select($lang); | |
221 | } | |
222 | ||
223 | // | |
224 | // Choisir la fonction de calcul du RSS | |
225 | // | |
226 | ||
227 | spip_connect(); | |
228 | switch($op) { | |
229 | # forum public | |
230 | case 'forum': | |
231 | include_spip('inc/forum'); | |
232 | if ($id = intval($a['id_article'])) { | |
233 | $critere = "statut='publie' AND id_article=$id"; | |
234 | $r = spip_fetch_array(spip_query("SELECT titre FROM spip_articles WHERE id_article=$id")); | |
235 | $url = generer_url_article($id); | |
236 | } | |
237 | else if ($id = intval($a['id_syndic'])) { | |
238 | $critere = "statut='publie' AND id_syndic=$id"; | |
239 | $r = spip_fetch_array(spip_query("SELECT nom_site AS titre FROM spip_syndic WHERE id_article=$id")); | |
240 | $url = generer_url_site($id); | |
241 | } | |
242 | else if ($id = intval($a['id_breve'])) { | |
243 | $critere = "statut='publie' AND id_breve=$id"; | |
244 | $r = spip_fetch_array(spip_query("SELECT titre FROM spip_articles WHERE id_article=$id")); | |
245 | $url = generer_url_breve($id); | |
246 | } | |
247 | else if ($id = intval($a['id_rubrique'])) { | |
248 | $critere = "statut='publie' AND id_rubrique=$id"; | |
249 | $r = spip_fetch_array(spip_query("SELECT titre FROM spip_articles WHERE id_article=$id")); | |
250 | $url = generer_url_rubrique($id); | |
251 | } | |
252 | else if ($id = intval($a['id_thread'])) { | |
253 | $critere = "statut='publie' AND id_thread=$id"; | |
254 | $r = spip_fetch_array(spip_query("SELECT titre FROM spip_articles WHERE id_article=$id")); | |
255 | $url = generer_url_forum($id); | |
256 | } | |
257 | if ($id) $rss = rss_suivi_forums($a, "spip_forum", $critere, false); | |
258 | ||
259 | $title = $r['titre'] . ' (' . _T("ecrire:titre_page_forum_suivi") .')'; | |
260 | break; | |
261 | # suivi prive des forums | |
262 | case 'forums': | |
263 | include_spip('inc/forum'); | |
264 | list($f,$w) = critere_statut_controle_forum($a['page']); | |
265 | $rss = rss_suivi_forums($a, $f, $w, true); | |
266 | $title = _T("ecrire:titre_page_forum_suivi")." (".$a['page'].")"; | |
267 | $url = generer_url_ecrire('controle_forum', 'type='.$a['page']); | |
268 | break; | |
269 | # revisions des articles | |
270 | case 'revisions': | |
271 | $rss = rss_suivi_versions($a); | |
272 | $title = _T("icone_suivi_revisions"); | |
273 | $url = ""; | |
274 | foreach (array('id_secteur', 'id_auteur', 'lang_choisie') as $var) | |
275 | if ($a[$var]) $url.= $var.'='.$a[$var] . '&'; | |
276 | $url = generer_url_ecrire('suivi_revisions', $url); | |
277 | break; | |
278 | # messagerie privee | |
279 | case 'messagerie': | |
280 | $rss = rss_suivi_messagerie($a); | |
281 | $title = _T("icone_messagerie_personnelle"); | |
282 | $url = generer_url_ecrire('messagerie'); | |
283 | break; | |
284 | # a suivre | |
285 | case 'a-suivre': | |
286 | $rss = rss_a_suivre($a); | |
287 | $title = _T("icone_a_suivre"); | |
288 | $url = _DIR_RESTREINT_ABS; | |
289 | break; | |
290 | case 'erreur securite': | |
291 | $rss = array(array('title' => _T('login_erreur_pass'))); | |
292 | $title = _T('login_erreur_pass'); | |
293 | $url = ''; | |
294 | break; | |
295 | default: | |
296 | $rss = array(array('title' => _T('forum_titre_erreur'))); | |
297 | $title = _T('forum_titre_erreur'); | |
298 | $url = ''; | |
299 | break; | |
300 | } | |
301 | ||
302 | if (!$fmt) $fmt = 'rss'; | |
303 | $f = charger_fonction($fmt, 'xml'); | |
304 | $f($rss, array( | |
305 | 'title' => "[".$GLOBALS['meta']['nom_site']."] RSS ".$title, | |
306 | 'url' => $url, | |
307 | 'language'=> $GLOBALS['spip_lang'])); | |
308 | ||
309 | spip_log("spip_rss applique $f sur '$fmt $opt $args' - " . spip_timer('rss')); | |
310 | } | |
311 | ?> |