function exec_cs_boite_rss_dist() { cs_minipres(); // Constantes distantes include_spip('cout_define'); if(defined('_CS_PAS_DE_DISTANT')) { ajax_retour(_T('couteauprive:version_distante_off')); return; } $p = ''; // on cherche le flux rss toutes les _CS_RSS_UPDATE minutes $force = _request('force')=='oui'; if(!$force) { $lastmodified = @file_exists(_CS_TMP_RSS)?@filemtime(_CS_TMP_RSS):0; if(time()-$lastmodified < _CS_RSS_UPDATE) lire_fichier(_CS_TMP_RSS, $p); } if(strlen($p)) { ajax_retour($p); return; } include_spip('inc/filtres'); include_spip('action/editer_site'); include_spip('inc/xml'); $r = spip_xml_load(_CS_RSS_SOURCE); if(function_exists('spip_xml_match_nodes')) $c = spip_xml_match_nodes(',^item$,', $r, $r2); else { $r2 = !is_array($r)?array():array_shift(array_shift(array_shift(array_shift($r)))); $c = count($r2); } if($c) { $r3 = &$r2['item']; $c = count($r3); $p=''; for($i=0; $i<min($c, _CS_RSS_COUNT); $i++) { $l = $r3[$i]['link'][0]; $d = affdate_court(date('Y-m-d', strtotime($r3[$i]['pubDate'][0]))); $t = str_replace('&', '&', htmlentities($r3[$i]['title'][0], ENT_NOQUOTES, "UTF-8")); $t = preg_replace(',\s*€(¦)?,', ' (…)', $t); $t = preg_replace(',^(.*?):,', "• <a href='$l' class='spip_out' target='_cout'>$1</a> <i>($d)</i><br/>", $t); $p .= "<li style='padding-top:0.6em;'>$t</li>"; } } else { // pour cs_lien() include_spip('cout_fonctions'); $p = '<span style="color: red;">'._T('couteauprive:erreur:probleme', array('pb'=>cs_lien(_CS_RSS_SOURCE,_T('couteauprive:erreur:distant')))).'</span>'; } $du = affdate_heure(date('Y-m-d H:i:s',time())); $p = '<ul style="list-style-type:none; padding:0; margin:0; ">'.$p .'</ul><p class="spip_xx-small" style="border-top:solid gray thin;"><b>' ._T('couteauprive:rss_edition')."</b><br/>$du</p>" .'<p style="text-align:right"><a href="' .generer_url_ecrire('admin_couteau_suisse','var_mode=calcul', true).'" onclick="' ."javascipt:jQuery('div.cs_boite_rss').children().css('opacity', 0.5).parent().load('".generer_url_ecrire('cs_boite_rss', 'force=oui', true).'\');return false;">' ._T('couteauprive:rss_actualiser').'</a> | <a href="' ._CS_RSS_SOURCE.'">' ._T('couteauprive:rss_source').'</a></p>'; if($c) ecrire_fichier(_CS_TMP_RSS, $p); ajax_retour($p); }
function date_relative($date, $decalage_maxi = 0, $ref_date = null) { if (is_null($ref_date)) { $ref_time = time(); } else { $ref_time = strtotime($ref_date); } if (!$date) { return; } $decal = date("U", $ref_time) - date("U", strtotime($date)); if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { return ''; } if ($decal < 0) { $il_y_a = "date_dans"; $decal = -1 * $decal; } else { $il_y_a = "date_il_y_a"; } if ($decal > 3600 * 24 * 30 * 6) { return affdate_court($date); } if ($decal > 3600 * 24 * 30) { $mois = floor($decal / (3600 * 24 * 30)); if ($mois < 2) { $delai = "{$mois} " . _T("date_un_mois"); } else { $delai = "{$mois} " . _T("date_mois"); } } else { if ($decal > 3600 * 24 * 7) { $semaines = floor($decal / (3600 * 24 * 7)); if ($semaines < 2) { $delai = "{$semaines} " . _T("date_une_semaine"); } else { $delai = "{$semaines} " . _T("date_semaines"); } } else { if ($decal > 3600 * 24) { $jours = floor($decal / (3600 * 24)); if ($jours < 2) { return $il_y_a == "date_dans" ? _T("date_demain") : _T("date_hier"); } else { $delai = "{$jours} " . _T("date_jours"); } } else { if ($decal >= 3600) { $heures = floor($decal / 3600); if ($heures < 2) { $delai = "{$heures} " . _T("date_une_heure"); } else { $delai = "{$heures} " . _T("date_heures"); } } else { if ($decal >= 60) { $minutes = floor($decal / 60); if ($minutes < 2) { $delai = "{$minutes} " . _T("date_une_minute"); } else { $delai = "{$minutes} " . _T("date_minutes"); } } else { $secondes = ceil($decal); if ($secondes < 2) { $delai = "{$secondes} " . _T("date_une_seconde"); } else { $delai = "{$secondes} " . _T("date_secondes"); } } } } } } return _T($il_y_a, array("delai" => $delai)); }
function date_depuis($date) { if (!$date) return; $decal = date("U") - date("U", strtotime($date)); if ($decal < 0) { $il_y_a = "date_dans"; $decal = -1 * $decal; } else { $il_y_a = "spiplistes:date_depuis"; } if ($decal < 3600) { $minutes = ceil($decal / 60); $retour = _T($il_y_a, array("delai"=>"$minutes "._T("date_minutes"))); } else if ($decal < (3600 * 24) ) { $heures = ceil ($decal / 3600); $retour = _T($il_y_a, array("delai"=>"$heures "._T("date_heures"))); } else if ($decal < (3600 * 24 * 7)) { $jours = ceil ($decal / (3600 * 24)); $retour = _T($il_y_a, array("delai"=>"$jours "._T("date_jours"))); } else if ($decal < (3600 * 24 * 7 * 4)) { $semaines = ceil ($decal / (3600 * 24 * 7)); $retour = _T($il_y_a, array("delai"=>"$semaines "._T("date_semaines"))); } else if ($decal < (3600 * 24 * 30 * 6)) { $mois = ceil ($decal / (3600 * 24 * 30)); $retour = _T($il_y_a, array("delai"=>"$mois "._T("date_mois"))); } else { $retour = _T($il_y_a, array("delai"=>" ")).affdate_court($date); } return $retour; }