/***************************************************************************\
* 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. *
* 'force' - charger toujours (mettre a jour)
* @param string $local
* permet de specifier le nom du fichier local (stockage d'un cache par exemple, et non document IMG)
+ * @param int $taille_max
+ * taille maxi de la copie local, par defaut _COPIE_LOCALE_MAX_SIZE
* @return bool|string
*/
-function copie_locale($source, $mode='auto', $local = null) {
+function copie_locale($source, $mode='auto', $local=null, $taille_max=null){
// si c'est la protection de soi-meme, retourner le path
if ($mode !== 'force' AND preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) {
// passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation
// et des eventuelles recuperations concurantes
include_spip("inc/acces");
- $res = recuperer_page($source, $localrac, false, _COPIE_LOCALE_MAX_SIZE, '', '', false, $t ? filemtime($localrac) : '');
+ if (!$taille_max) $taille_max = _COPIE_LOCALE_MAX_SIZE;
+ $res = recuperer_page($source, $localrac, false, $taille_max, '', '', false, $t ? filemtime($localrac) : '');
if (!$res) {
if (!$t) // si $t c'est sans doute juste un not-modified-since qui fait renvoyer false
spip_log("copie_locale : Echec recuperation $source sur $localrac",_LOG_INFO_IMPORTANTE);
return array($entete, $chaine);
}
+/**
+ * Convertir une URL dont le host est en utf8 en ascii
+ * Utilise la librairie https://github.com/phlylabs/idna-convert/tree/v0.9.1
+ * dans sa derniere version compatible toutes version PHP 5
+ * La fonction PHP idn_to_ascii depend d'un package php5-intl et est rarement disponible
+ *
+ * @param string $url_idn
+ * @return array|string
+ */
+function url_to_ascii($url_idn) {
+
+ if ($parts = parse_url($url_idn)) {
+ $host = $parts['host'];
+ if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) {
+ include_spip('inc/idna_convert.class');
+ $IDN = new idna_convert();
+ $host_ascii = $IDN->encode($host);
+ $url_idn = explode($host, $url_idn, 2);
+ $url_idn = implode($host_ascii, $url_idn);
+ }
+ }
+
+ return $url_idn;
+}
+
//
// Recupere une page sur le net
// et au besoin l'encode dans le charset local
// Accepter les URLs au format feed:// ou qui ont oublie le http://
$url = preg_replace(',^feed://,i', 'http://', $url);
if (!preg_match(',^[a-z]+://,i', $url)) $url = 'http://' . $url;
+ $url = url_to_ascii($url);
if ($taille_max==0)
$get = 'HEAD';
// http://doc.spip.org/@recuperer_infos_distantes
function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true){
+ // pas la peine de perdre son temps
+ if (!tester_url_absolue($source)) {
+ return false;
+ }
+
# charger les alias des types mime
include_spip('base/typedoc');
global $mime_alias;
$a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE);
}
+ // si on a rien trouve pas la peine d'insister
+ if (!$a) {
+ return false;
+ }
+
// S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller
// recharger le document en GET et recuperer des donnees supplementaires...
if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)){