X-Git-Url: http://git.cyclocoop.org/?p=lhc%2Fweb%2Fclavette_www.git;a=blobdiff_plain;f=www%2Fplugins-dist%2Fsites%2Finc%2Fsyndic.php;h=e84886fd128e3c3f7b294201bb5496a161e93ac8;hp=8b0ac69fe99fbe8fd7442484c1a80239152d5926;hb=cc641eb476987612f6d6df1a5417c1c5582a8ab8;hpb=7d84a490677fb716a1fd4df260f8eab35f6a8506 diff --git a/www/plugins-dist/sites/inc/syndic.php b/www/plugins-dist/sites/inc/syndic.php index 8b0ac69..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. * @@ -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', @@ -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']; @@ -436,9 +456,14 @@ function cdata_echappe(&$rss, &$echappe_cdata) { 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); } @@ -449,11 +474,11 @@ function cdata_echappe(&$rss, &$echappe_cdata) { // 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); } }