X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=www%2Fplugins-dist%2Fsites%2Finc%2Fsyndic.php;h=e84886fd128e3c3f7b294201bb5496a161e93ac8;hb=cc641eb476987612f6d6df1a5417c1c5582a8ab8;hp=3f9c6bf0840a6327b8ac4447d4db431279acb849;hpb=a33c2ba9d919664b3bb0f565f8e9a8b9d8530cdb;p=lhc%2Fweb%2Fclavette_www.git diff --git a/www/plugins-dist/sites/inc/syndic.php b/www/plugins-dist/sites/inc/syndic.php index 3f9c6bf..e84886f 100644 --- a/www/plugins-dist/sites/inc/syndic.php +++ b/www/plugins-dist/sites/inc/syndic.php @@ -3,7 +3,7 @@ /***************************************************************************\ * SPIP, Systeme de publication pour l'internet * * * - * Copyright (c) 2001-2014 * + * Copyright (c) 2001-2016 * * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James * * * * Ce programme est un logiciel libre distribue sous licence GNU/GPL. * @@ -21,7 +21,7 @@ include_spip('genie/syndic'); // prend un fichier backend et retourne un tableau des items lus, // et une chaine en cas d'erreur -// http://doc.spip.org/@analyser_backend +// http://code.spip.net/@analyser_backend function analyser_backend($rss, $url_syndic='') { include_spip('inc/texte'); # pour couper() @@ -73,8 +73,13 @@ function analyser_backend($rss, $url_syndic='') { if (!count($items)) return _T('sites:avis_echec_syndication_01'); + if (!defined('_SYNDICATION_MAX_ITEMS')) define('_SYNDICATION_MAX_ITEMS',1000); + $nb_items = 0; foreach ($items as $item) { $data = array(); + if ($nb_items++>_SYNDICATION_MAX_ITEMS){ + break; + } // URL (semi-obligatoire, sert de cle) @@ -264,6 +269,21 @@ function analyser_backend($rss, $url_syndic='') { // passer l'url en absolue $data['url'] = url_absolue(filtrer_entites($data['url']), $url_syndic); + // si on demande un dereferencement de l'URL, il faut verifier que ce n'est pas une redirection + if (_SYNDICATION_DEREFERENCER_URL){ + $target = $data['url']; + include_spip("inc/distant"); + for ($i = 0; $i<10; $i++){ + // on fait un GET et pas un HEAD car les vieux SPIP ne repondent pas la redirection avec un HEAD (honte) sur un article virtuel + $res = recuperer_lapage($target, false, "GET", 4096); + if (!$res) break; // c'est pas bon signe car on a pas trouve l'URL... + if (is_array($res)) break; // on a trouve la page, donc on a l'URL finale + $target = $res; // c'est une redirection, on la suit pour voir ou elle mene + } + // ici $target est l'URL finale de la page + $data['url'] = $target; + } + // Trouver les microformats (ecrase les et ) if (preg_match_all( ',]+[[:space:]])?rel=[^>]+>.*,Uims', @@ -290,7 +310,7 @@ function analyser_backend($rss, $url_syndic='') { // helas strtotime ne reconnait pas le format W3C // http://www.w3.org/TR/NOTE-datetime -// http://doc.spip.org/@my_strtotime +// http://code.spip.net/@my_strtotime function my_strtotime($la_date, $lang=null) { // format complet if (preg_match( @@ -326,7 +346,7 @@ function my_strtotime($la_date, $lang=null) { // par la version anglaise avant de faire strtotime if ($lang){ // "fr-fr" - $lang = reset(explode("-",$lang)); + list($lang) = explode("-", $lang); static $months = null; if (!isset($months[$lang])){ $prev_lang = $GLOBALS['spip_lang']; @@ -356,7 +376,7 @@ function my_strtotime($la_date, $lang=null) { } // A partir d'un ou autre essayer de recuperer // le mot et son url ; on cree -// http://doc.spip.org/@creer_tag +// http://code.spip.net/@creer_tag function creer_tag($mot,$type,$url) { if (!strlen($mot = trim($mot))) return ''; $mot = "$mot"; @@ -368,7 +388,7 @@ function creer_tag($mot,$type,$url) { } -// http://doc.spip.org/@ajouter_tags +// http://code.spip.net/@ajouter_tags function ajouter_tags($matches, $item) { include_spip('inc/filtres'); $tags = array(); @@ -430,15 +450,20 @@ function ajouter_tags($matches, $item) { // Lit contenu des blocs [[CDATA]] dans un flux -// http://doc.spip.org/@cdata_echappe_retour +// http://code.spip.net/@cdata_echappe_retour function cdata_echappe(&$rss, &$echappe_cdata) { $echappe_cdata = array(); if (preg_match_all(',,Uims', $rss, $regs, PREG_SET_ORDER)) { foreach ($regs as $n => $reg) { - if (preg_match(',[<>],', $reg[1])) { - $echappe_cdata[$n] = $reg[1]; - $rss = str_replace($reg[0], "@@@SPIP_CDATA$n@@@", $rss); + if (strpos($reg[1],'<')!==false + or strpos($reg[1],'>')!==false) { + // verifier que la chaine est encore dans le flux, car on peut avoir X fois la meme + // inutile de (sur)peupler le tableau avec des substitutions identiques + if (strpos($rss,$reg[0])!==false){ + $echappe_cdata["@@@SPIP_CDATA$n@@@"] = $reg[1]; + $rss = str_replace($reg[0], "@@@SPIP_CDATA$n@@@", $rss); + } } else $rss = str_replace($reg[0], $reg[1], $rss); } @@ -446,14 +471,14 @@ function cdata_echappe(&$rss, &$echappe_cdata) { } // Retablit le contenu des blocs [[CDATA]] dans une chaine ou un tableau -// http://doc.spip.org/@cdata_echappe_retour +// http://code.spip.net/@cdata_echappe_retour function cdata_echappe_retour(&$x, &$echappe_cdata) { if (is_string($x)) { - if (strpos($x, '@@@SPIP_CDATA') !== false - OR strpos($x, '<') !== false) { + if (strpos($x, '<') !== false){ $x = filtrer_entites($x); - foreach ($echappe_cdata as $n => $e) - $x = str_replace("@@@SPIP_CDATA$n@@@", $e, $x); + } + if (strpos($x, '@@@SPIP_CDATA') !== false){ + $x = str_replace( array_keys($echappe_cdata), array_values($echappe_cdata), $x); } }