Mise en route du suivi.
[aidenligne_francais_universite.git] / plugins / couteau_suisse / exec / cs_boite_rss.php
1 <?php
2 #-----------------------------------------------------#
3 # Plugin : Couteau Suisse - Licence : GPL #
4 # Auteur : Patrice Vanneufville, 2007 #
5 # Contact : patrice¡.!vanneufville¡@!laposte¡.!net #
6 # Infos : http://www.spip-contrib.net/?article2166 #
7 #-----------------------------------------------------#
8 if (!defined("_ECRIRE_INC_VERSION")) return;
9
10 // compatibilite spip 1.9
11 if(!function_exists(ajax_retour)) {
12 function ajax_retour($corps) {
13 $c = $GLOBALS['meta']["charset"];
14 header('Content-Type: text/html; charset='. $c);
15 $c = '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n";
16 echo $c, $corps;
17 exit;
18 }
19 }
20 if(defined('_SPIP19100') && !function_exists('spip_xml_load')) {
21 function spip_xml_load($url){
22 include_spip('inc/distant');
23 $texte = recuperer_page($url);
24 include_spip('inc/plugin');
25 return parse_plugin_xml($texte);
26 }
27 }
28
29 function exec_cs_boite_rss_dist() {
30 if (!cout_autoriser()) {
31 include_spip('inc/minipres');
32 echo defined('_SPIP19100')?minipres( _T('avis_non_acces_page')):minipres();
33 exit;
34 }
35 $force = _request('force');
36 $force = false;
37 $p = '';
38 // on cherche le flux rss toutes les deux heures
39 if(!$force) {
40 $lastmodified = @file_exists(_DIR_RSS_TMP)?@filemtime(_DIR_RSS_TMP):0;
41 if (time()-$lastmodified < 2*3600) lire_fichier(_DIR_RSS_TMP, $p);
42 }
43 if(strlen($p)) { ajax_retour($p); return; }
44 include_spip('action/editer_site');
45 include_spip('inc/xml');
46 $r = spip_xml_load(_CS_RSS_SOURCE);
47 if (function_exists('spip_xml_match_nodes')) $c = spip_xml_match_nodes(',^item$,', $r, $r2);
48 else {
49 $r2= array_shift(array_shift(array_shift(array_shift($r))));
50 $c = count($r2);
51 }
52 if($c) {
53 $r3 = &$r2['item'];
54 $c = count($r3); $p='';
55 for($i=0; $i<min($c, 12); $i++) {
56 $l = $r3[$i]['link'][0];
57 $t = str_replace('&amp;', '&', htmlentities($r3[$i]['title'][0], ENT_NOQUOTES, "UTF-8"));
58 $t = preg_replace(',\s*&#8364;(&brvbar;)?,', '&nbsp;(&hellip;)', $t);
59 $t = preg_replace(',^(.*?):,', "&bull; <a href='$l' class='spip_out' target='_cout'>$1</a>:", $t);
60 $p .= "<li style='padding-top:0.6em;'>$t</li>";
61 }
62 } else {
63 include(_DIR_PLUGIN_COUTEAU_SUISSE.'cout_fonctions');
64 $p = '<span style="color: red;">'._T('couteauprive:erreur:probleme', array('pb'=>cs_lien(_CS_RSS_SOURCE,_T('couteauprive:erreur:distant')))).'</span>';
65 }
66 include_spip('inc/filtres');
67 $du = affdate_heure(date('Y-m-d H:i:s',time()));
68 $p = '<ul style="list-style-type:none; padding:0; margin:0; ">'.$p
69 .'</ul><p class="spip_xx-small"><b>'
70 ._T('couteauprive:rss_edition')."</b><br/>$du</p>";
71 if($c) ecrire_fichier(_DIR_RSS_TMP, $p);
72
73 ajax_retour($p);
74 }
75 ?>