[ Index ] |
|
Code source de SPIP 1.8.3 |
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 $rss = array(); 197 include_ecrire ("inc_forum.php3"); 198 199 $result_forum = spip_query(" 200 SELECT * 201 FROM spip_forum 202 WHERE " . $query_forum . " 203 ORDER BY date_heure DESC LIMIT 0,20" 204 ); 205 206 while ($t = spip_fetch_array($result_forum)) { 207 $item = array(); 208 $item['title'] = typo($t['titre']); 209 if ($a['page'] == 'public' 210 AND $t['statut']<>'publie' 211 ) 212 $item['title'] .= ' ('.$t['statut'].')'; 213 $item['date'] = $t['date_heure']; 214 $item['author'] = $t['auteur']; 215 $item['email'] = $t['email_auteur']; 216 217 if ($lien_moderation) 218 $item['url'] = _DIR_RESTREINT_ABS 219 .'controle_forum.php3?page='.$a['page'] 220 .'&debut_id_forum='.$t['id_forum']; 221 else 222 $item['url'] = generer_url_forum($t['id_forum']); 223 224 $item['description'] = propre($t['texte']); 225 if ($GLOBALS['les_notes']) { 226 $item['description'] .= '<hr />'.$GLOBALS['les_notes']; 227 $GLOBALS['les_notes'] = ''; 228 } 229 if ($t['nom_site'] OR vider_url($t['url_site'])) 230 $item['description'] .= propre("\n- [".$t['nom_site']."->".$t['url_site']."]<br />"); 231 232 $rss[] = $item; 233 } 234 235 return $rss; 236 } 237 238 239 240 // Suivi de la messagerie privee 241 function rss_suivi_messagerie($a) { 242 $rss = array(); 243 244 // 1. les messages 245 $s = spip_query("SELECT * FROM spip_messages AS messages, 246 spip_auteurs_messages AS lien WHERE lien.id_auteur=".$a['id_auteur'] 247 ." AND lien.id_message=messages.id_message 248 GROUP BY messages.id_message ORDER BY messages.date_heure DESC"); 249 while ($t = spip_fetch_array($s)) { 250 if ($compte++<10) { 251 $auteur = spip_fetch_array(spip_query("SELECT 252 auteurs.nom AS nom, auteurs.email AS email 253 FROM spip_auteurs AS auteurs, 254 spip_auteurs_messages AS lien 255 WHERE lien.id_message=".$t['id_message']." 256 AND lien.id_auteur!=".$t['id_auteur']." 257 AND lien.id_auteur = auteurs.id_auteur")); 258 $item = array( 259 'title' => typo($t['titre']), 260 'date' => $t['date_heure'], 261 'author' => typo($auteur['nom']), 262 'email' => $auteur['email'], 263 'description' => propre($t['texte']), 264 'url' => _DIR_RESTREINT_ABS 265 .'message.php3?id_message='.$t['id_message'] 266 ); 267 $rss[] = $item; 268 } 269 $messages_vus[] = $t['id_message']; 270 } 271 272 // 2. les reponses aux messages 273 if ($messages_vus) { 274 $s = spip_query("SELECT * FROM spip_forum WHERE id_message 275 IN (".join(',', $messages_vus).") 276 ORDER BY date_heure DESC LIMIT 0,10"); 277 278 while ($t = spip_fetch_array($s)) { 279 $item = array( 280 'title' => typo($t['titre']), 281 'date' => $t['date_heure'], 282 'description' => propre($t['texte']), 283 'author' => typo($t['auteur']), 284 'email' => $t['email_auteur'], 285 'url' => _DIR_RESTREINT_ABS 286 .'message.php3?id_message='.$t['id_message'] 287 .'#'.$t['id_forum'] 288 ); 289 $rss[] = $item; 290 } 291 } 292 293 return $rss; 294 } 295 296 // Suivi de la page "a suivre" : articles, breves, sites proposes et publies 297 function rss_a_suivre($a) { 298 $rss_articles = rss_articles("statut = 'prop'"); 299 $rss_breves = rss_breves("statut = 'prop'"); 300 $rss_sites = rss_sites("statut = 'prop'"); 301 302 return array_merge($rss_articles, $rss_breves, $rss_sites); 303 } 304 305 function rss_articles($critere) { 306 $rss = array(); 307 $s = spip_query("SELECT * FROM spip_articles WHERE $critere 308 ORDER BY date DESC LIMIT 0,10"); 309 while ($t = spip_fetch_array($s)) { 310 $auteur = spip_fetch_array(spip_query("SELECT 311 auteurs.nom AS nom, auteurs.email AS email 312 FROM spip_auteurs AS auteurs, 313 spip_auteurs_articles AS lien 314 WHERE lien.id_article=".$t['id_article']." 315 AND lien.id_auteur = auteurs.id_auteur")); 316 $item = array( 317 'title' => typo($t['titre']), 318 'date' => $t['date'], 319 'author' => typo($auteur['nom']), 320 'email' => $auteur['email'], 321 'description' => propre(couper("{{".$t['chapo']."}}\n\n".$t['texte'],300)), 322 'url' => _DIR_RESTREINT_ABS 323 .'articles.php3?id_article='.$t['id_article'] 324 ); 325 if ($t['statut'] == 'prop') 326 $item['title'] = _T('info_article_propose').' : '.$item['title']; 327 328 $rss[] = $item; 329 } 330 return $rss; 331 } 332 333 334 function rss_breves($critere) { 335 $rss = array(); 336 $s = spip_query("SELECT * FROM spip_breves WHERE $critere 337 ORDER BY date_heure DESC LIMIT 0,10"); 338 while ($t = spip_fetch_array($s)) { 339 $item = array( 340 'title' => typo($t['titre']), 341 'date' => $t['date_heure'], 342 'description' => propre(couper($t['texte'],300)), 343 'url' => _DIR_RESTREINT_ABS 344 .'breves_voir.php3?id_breve='.$t['id_breve'] 345 ); 346 if ($t['statut'] == 'prop') 347 $item['title'] = _T('titre_breve_proposee').' : '.$item['title']; 348 349 $rss[] = $item; 350 } 351 return $rss; 352 } 353 354 355 function rss_sites($critere) { 356 $rss = array(); 357 $s = spip_query("SELECT * FROM spip_syndic WHERE $critere 358 ORDER BY date DESC LIMIT 0,10"); 359 while ($t = spip_fetch_array($s)) { 360 $item = array( 361 'title' => typo($t['titre']." ".$t['url_site']), 362 'date' => $t['date'], 363 'description' => propre(couper($t['texte'],300)), 364 'url' => _DIR_RESTREINT_ABS 365 .'sites.php3?id_syndic='.$t['id_syndic'] 366 ); 367 if ($t['statut'] == 'prop') 368 $item['title'] = _T('info_site_attente').' : '.$item['title']; 369 370 $rss[] = $item; 371 } 372 return $rss; 373 } 374 375 376 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Feb 22 22:27:47 2007 | par Balluche grâce à PHPXref 0.7 |