@@ -16,32 +16,32 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Distant |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 23 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 23 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 24 | 24 | } |
| 25 | 25 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 26 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 26 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | - define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 32 | + define('_INC_DISTANT_MAX_SIZE', 2097152); |
|
| 33 | 33 | } |
| 34 | 34 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 35 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 35 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 39 | - preg_replace( |
|
| 40 | - '@^https?:@', |
|
| 41 | - 'https?:', |
|
| 42 | - (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | - ) |
|
| 44 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 39 | + preg_replace( |
|
| 40 | + '@^https?:@', |
|
| 41 | + 'https?:', |
|
| 42 | + (isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : '') |
|
| 43 | + ) |
|
| 44 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 45 | 45 | |
| 46 | 46 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 47 | 47 | |
@@ -68,77 +68,77 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null) { |
| 70 | 70 | |
| 71 | - // si c'est la protection de soi-meme, retourner le path |
|
| 72 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | - |
|
| 75 | - return @file_exists($source) ? $source : false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (is_null($local)) { |
|
| 79 | - $local = fichier_copie_locale($source); |
|
| 80 | - } else { |
|
| 81 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | - if (!$local) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 94 | - $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | - |
|
| 96 | - // test d'existence du fichier |
|
| 97 | - if ($mode == 'test') { |
|
| 98 | - return $t ? $local : ''; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // sinon voir si on doit/peut le telecharger |
|
| 102 | - if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | - return $local; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ($mode == 'modif' or !$t) { |
|
| 107 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | - // et des eventuelles recuperations concurantes |
|
| 109 | - include_spip('inc/acces'); |
|
| 110 | - if (!$taille_max) { |
|
| 111 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | - } |
|
| 113 | - $res = recuperer_url( |
|
| 114 | - $source, |
|
| 115 | - array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
|
| 116 | - ); |
|
| 117 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE); |
|
| 119 | - } |
|
| 120 | - if (!$res['length']) { |
|
| 121 | - // si $t c'est sans doute juste un not-modified-since |
|
| 122 | - return $t ? $local : false; |
|
| 123 | - } |
|
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK'); |
|
| 125 | - |
|
| 126 | - // pour une eventuelle indexation |
|
| 127 | - pipeline( |
|
| 128 | - 'post_edition', |
|
| 129 | - array( |
|
| 130 | - 'args' => array( |
|
| 131 | - 'operation' => 'copie_locale', |
|
| 132 | - 'source' => $source, |
|
| 133 | - 'fichier' => $local, |
|
| 134 | - 'http_res' => $res['length'], |
|
| 135 | - ), |
|
| 136 | - 'data' => null |
|
| 137 | - ) |
|
| 138 | - ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $local; |
|
| 71 | + // si c'est la protection de soi-meme, retourner le path |
|
| 72 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 74 | + |
|
| 75 | + return @file_exists($source) ? $source : false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (is_null($local)) { |
|
| 79 | + $local = fichier_copie_locale($source); |
|
| 80 | + } else { |
|
| 81 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 82 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 87 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 88 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 89 | + if (!$local) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $localrac = _DIR_RACINE . $local; |
|
| 94 | + $t = ($mode == 'force') ? false : @file_exists($localrac); |
|
| 95 | + |
|
| 96 | + // test d'existence du fichier |
|
| 97 | + if ($mode == 'test') { |
|
| 98 | + return $t ? $local : ''; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // sinon voir si on doit/peut le telecharger |
|
| 102 | + if ($local == $source or !tester_url_absolue($source)) { |
|
| 103 | + return $local; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ($mode == 'modif' or !$t) { |
|
| 107 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 108 | + // et des eventuelles recuperations concurantes |
|
| 109 | + include_spip('inc/acces'); |
|
| 110 | + if (!$taille_max) { |
|
| 111 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 112 | + } |
|
| 113 | + $res = recuperer_url( |
|
| 114 | + $source, |
|
| 115 | + array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
|
| 116 | + ); |
|
| 117 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE); |
|
| 119 | + } |
|
| 120 | + if (!$res['length']) { |
|
| 121 | + // si $t c'est sans doute juste un not-modified-since |
|
| 122 | + return $t ? $local : false; |
|
| 123 | + } |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK'); |
|
| 125 | + |
|
| 126 | + // pour une eventuelle indexation |
|
| 127 | + pipeline( |
|
| 128 | + 'post_edition', |
|
| 129 | + array( |
|
| 130 | + 'args' => array( |
|
| 131 | + 'operation' => 'copie_locale', |
|
| 132 | + 'source' => $source, |
|
| 133 | + 'fichier' => $local, |
|
| 134 | + 'http_res' => $res['length'], |
|
| 135 | + ), |
|
| 136 | + 'data' => null |
|
| 137 | + ) |
|
| 138 | + ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $local; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | /** |
@@ -157,86 +157,86 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | function prepare_donnees_post($donnees, $boundary = '') { |
| 159 | 159 | |
| 160 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 161 | - // pour un appel soap par exemple |
|
| 162 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 163 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 164 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 165 | - $entete = ''; |
|
| 166 | - // on repasse tous les \r\n et \r en simples \n |
|
| 167 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 168 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 169 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 170 | - $p = strpos($donnees, "\n\n"); |
|
| 171 | - if ($p !== false) { |
|
| 172 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 173 | - $donnees = substr($donnees, $p + 2); |
|
| 174 | - } |
|
| 175 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 176 | - } else { |
|
| 177 | - /* boundary automatique */ |
|
| 178 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 179 | - if ($boundary === '') { |
|
| 180 | - $taille = 0; |
|
| 181 | - foreach ($donnees as $cle => $valeur) { |
|
| 182 | - if (is_array($valeur)) { |
|
| 183 | - foreach ($valeur as $val2) { |
|
| 184 | - $taille += strlen($val2); |
|
| 185 | - } |
|
| 186 | - } else { |
|
| 187 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 188 | - $taille += strlen($valeur); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - if ($taille > 500) { |
|
| 192 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 197 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 198 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 199 | - $chaine = ''; |
|
| 200 | - if (is_array($donnees)) { |
|
| 201 | - foreach ($donnees as $cle => $valeur) { |
|
| 202 | - if (is_array($valeur)) { |
|
| 203 | - foreach ($valeur as $val2) { |
|
| 204 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 205 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 206 | - $chaine .= "\r\n"; |
|
| 207 | - $chaine .= $val2; |
|
| 208 | - } |
|
| 209 | - } else { |
|
| 210 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 211 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 212 | - $chaine .= "\r\n"; |
|
| 213 | - $chaine .= $valeur; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 217 | - } |
|
| 218 | - } else { |
|
| 219 | - // fabrique une chaine HTTP simple pour un POST |
|
| 220 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 221 | - $chaine = array(); |
|
| 222 | - if (is_array($donnees)) { |
|
| 223 | - foreach ($donnees as $cle => $valeur) { |
|
| 224 | - if (is_array($valeur)) { |
|
| 225 | - foreach ($valeur as $val2) { |
|
| 226 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 227 | - } |
|
| 228 | - } else { |
|
| 229 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - $chaine = implode('&', $chaine); |
|
| 233 | - } else { |
|
| 234 | - $chaine = $donnees; |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return array($entete, $chaine); |
|
| 160 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 161 | + // pour un appel soap par exemple |
|
| 162 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 163 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 164 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 165 | + $entete = ''; |
|
| 166 | + // on repasse tous les \r\n et \r en simples \n |
|
| 167 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 168 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 169 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 170 | + $p = strpos($donnees, "\n\n"); |
|
| 171 | + if ($p !== false) { |
|
| 172 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 173 | + $donnees = substr($donnees, $p + 2); |
|
| 174 | + } |
|
| 175 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 176 | + } else { |
|
| 177 | + /* boundary automatique */ |
|
| 178 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 179 | + if ($boundary === '') { |
|
| 180 | + $taille = 0; |
|
| 181 | + foreach ($donnees as $cle => $valeur) { |
|
| 182 | + if (is_array($valeur)) { |
|
| 183 | + foreach ($valeur as $val2) { |
|
| 184 | + $taille += strlen($val2); |
|
| 185 | + } |
|
| 186 | + } else { |
|
| 187 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 188 | + $taille += strlen($valeur); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + if ($taille > 500) { |
|
| 192 | + $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 197 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 198 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 199 | + $chaine = ''; |
|
| 200 | + if (is_array($donnees)) { |
|
| 201 | + foreach ($donnees as $cle => $valeur) { |
|
| 202 | + if (is_array($valeur)) { |
|
| 203 | + foreach ($valeur as $val2) { |
|
| 204 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 205 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 206 | + $chaine .= "\r\n"; |
|
| 207 | + $chaine .= $val2; |
|
| 208 | + } |
|
| 209 | + } else { |
|
| 210 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 211 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 212 | + $chaine .= "\r\n"; |
|
| 213 | + $chaine .= $valeur; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 217 | + } |
|
| 218 | + } else { |
|
| 219 | + // fabrique une chaine HTTP simple pour un POST |
|
| 220 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 221 | + $chaine = array(); |
|
| 222 | + if (is_array($donnees)) { |
|
| 223 | + foreach ($donnees as $cle => $valeur) { |
|
| 224 | + if (is_array($valeur)) { |
|
| 225 | + foreach ($valeur as $val2) { |
|
| 226 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 227 | + } |
|
| 228 | + } else { |
|
| 229 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + $chaine = implode('&', $chaine); |
|
| 233 | + } else { |
|
| 234 | + $chaine = $donnees; |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return array($entete, $chaine); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -250,18 +250,18 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | function url_to_ascii($url_idn) { |
| 252 | 252 | |
| 253 | - if ($parts = parse_url($url_idn)) { |
|
| 254 | - $host = $parts['host']; |
|
| 255 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 256 | - include_spip('inc/idna_convert.class'); |
|
| 257 | - $IDN = new idna_convert(); |
|
| 258 | - $host_ascii = $IDN->encode($host); |
|
| 259 | - $url_idn = explode($host, $url_idn, 2); |
|
| 260 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return $url_idn; |
|
| 253 | + if ($parts = parse_url($url_idn)) { |
|
| 254 | + $host = $parts['host']; |
|
| 255 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 256 | + include_spip('inc/idna_convert.class'); |
|
| 257 | + $IDN = new idna_convert(); |
|
| 258 | + $host_ascii = $IDN->encode($host); |
|
| 259 | + $url_idn = explode($host, $url_idn, 2); |
|
| 260 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return $url_idn; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -300,172 +300,172 @@ discard block |
||
| 300 | 300 | * string file : nom du fichier si enregistre dans un fichier |
| 301 | 301 | */ |
| 302 | 302 | function recuperer_url($url, $options = array()) { |
| 303 | - $default = array( |
|
| 304 | - 'transcoder' => false, |
|
| 305 | - 'methode' => 'GET', |
|
| 306 | - 'taille_max' => null, |
|
| 307 | - 'datas' => '', |
|
| 308 | - 'boundary' => '', |
|
| 309 | - 'refuser_gz' => false, |
|
| 310 | - 'if_modified_since' => '', |
|
| 311 | - 'uri_referer' => '', |
|
| 312 | - 'file' => '', |
|
| 313 | - 'follow_location' => 10, |
|
| 314 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 315 | - ); |
|
| 316 | - $options = array_merge($default, $options); |
|
| 317 | - // copier directement dans un fichier ? |
|
| 318 | - $copy = $options['file']; |
|
| 319 | - |
|
| 320 | - if ($options['methode'] == 'HEAD') { |
|
| 321 | - $options['taille_max'] = 0; |
|
| 322 | - } |
|
| 323 | - if (is_null($options['taille_max'])) { |
|
| 324 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - if (!empty($options['datas'])) { |
|
| 328 | - list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 329 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 330 | - $head .= 'Content-Length: ' . strlen($postdata); |
|
| 331 | - } |
|
| 332 | - $options['datas'] = $head . "\r\n\r\n" . $postdata; |
|
| 333 | - if (strlen($postdata)) { |
|
| 334 | - $options['methode'] = 'POST'; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 339 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 340 | - if (!tester_url_absolue($url)) { |
|
| 341 | - $url = 'http://' . $url; |
|
| 342 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 343 | - $url = 'http:' . $url; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - $url = url_to_ascii($url); |
|
| 347 | - |
|
| 348 | - $result = array( |
|
| 349 | - 'status' => 0, |
|
| 350 | - 'headers' => '', |
|
| 351 | - 'page' => '', |
|
| 352 | - 'length' => 0, |
|
| 353 | - 'last_modified' => '', |
|
| 354 | - 'location' => '', |
|
| 355 | - 'url' => $url |
|
| 356 | - ); |
|
| 357 | - |
|
| 358 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 359 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 360 | - |
|
| 361 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 362 | - list($handle, $fopen) = init_http( |
|
| 363 | - $options['methode'], |
|
| 364 | - $url, |
|
| 365 | - $refuser_gz, |
|
| 366 | - $options['uri_referer'], |
|
| 367 | - $options['datas'], |
|
| 368 | - $options['version_http'], |
|
| 369 | - $options['if_modified_since'] |
|
| 370 | - ); |
|
| 371 | - if (!$handle) { |
|
| 372 | - spip_log("ECHEC init_http $url"); |
|
| 373 | - |
|
| 374 | - return false; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 378 | - // et recuperer les en-tetes de reponses |
|
| 379 | - if (!$fopen) { |
|
| 380 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 381 | - if (!$res) { |
|
| 382 | - fclose($handle); |
|
| 383 | - $t = @parse_url($url); |
|
| 384 | - $host = $t['host']; |
|
| 385 | - // Chinoisierie inexplicable pour contrer |
|
| 386 | - // les actions liberticides de l'empire du milieu |
|
| 387 | - if (!need_proxy($host) |
|
| 388 | - and $res = @file_get_contents($url) |
|
| 389 | - ) { |
|
| 390 | - $result['length'] = strlen($res); |
|
| 391 | - if ($copy) { |
|
| 392 | - ecrire_fichier($copy, $res); |
|
| 393 | - $result['file'] = $copy; |
|
| 394 | - } else { |
|
| 395 | - $result['page'] = $res; |
|
| 396 | - } |
|
| 397 | - $res = array( |
|
| 398 | - 'status' => 200, |
|
| 399 | - ); |
|
| 400 | - } else { |
|
| 401 | - return false; |
|
| 402 | - } |
|
| 403 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 404 | - $options['follow_location']--; |
|
| 405 | - fclose($handle); |
|
| 406 | - include_spip('inc/filtres'); |
|
| 407 | - $url = suivre_lien($url, $res['location']); |
|
| 408 | - spip_log("recuperer_url recommence sur $url"); |
|
| 409 | - |
|
| 410 | - return recuperer_url($url, $options); |
|
| 411 | - } elseif ($res['status'] !== 200) { |
|
| 412 | - spip_log('HTTP status ' . $res['status'] . " pour $url"); |
|
| 413 | - } |
|
| 414 | - $result['status'] = $res['status']; |
|
| 415 | - if (isset($res['headers'])) { |
|
| 416 | - $result['headers'] = $res['headers']; |
|
| 417 | - } |
|
| 418 | - if (isset($res['last_modified'])) { |
|
| 419 | - $result['last_modified'] = $res['last_modified']; |
|
| 420 | - } |
|
| 421 | - if (isset($res['location'])) { |
|
| 422 | - $result['location'] = $res['location']; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - // on ne veut que les entetes |
|
| 427 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 428 | - return $result; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 433 | - // sinon la memoire explose pour les gros flux |
|
| 434 | - |
|
| 435 | - $gz = false; |
|
| 436 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 437 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 441 | - if (!$result['length']) { |
|
| 442 | - $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 443 | - fclose($handle); |
|
| 444 | - if ($copy) { |
|
| 445 | - $result['length'] = $res; |
|
| 446 | - $result['file'] = $copy; |
|
| 447 | - } elseif ($res) { |
|
| 448 | - $result['page'] = &$res; |
|
| 449 | - $result['length'] = strlen($result['page']); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - if (!$result['page']) { |
|
| 453 | - return $result; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // Decompresser au besoin |
|
| 457 | - if ($gz) { |
|
| 458 | - $result['page'] = implode('', gzfile($gz)); |
|
| 459 | - supprimer_fichier($gz); |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - // Faut-il l'importer dans notre charset local ? |
|
| 463 | - if ($options['transcoder']) { |
|
| 464 | - include_spip('inc/charsets'); |
|
| 465 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - return $result; |
|
| 303 | + $default = array( |
|
| 304 | + 'transcoder' => false, |
|
| 305 | + 'methode' => 'GET', |
|
| 306 | + 'taille_max' => null, |
|
| 307 | + 'datas' => '', |
|
| 308 | + 'boundary' => '', |
|
| 309 | + 'refuser_gz' => false, |
|
| 310 | + 'if_modified_since' => '', |
|
| 311 | + 'uri_referer' => '', |
|
| 312 | + 'file' => '', |
|
| 313 | + 'follow_location' => 10, |
|
| 314 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 315 | + ); |
|
| 316 | + $options = array_merge($default, $options); |
|
| 317 | + // copier directement dans un fichier ? |
|
| 318 | + $copy = $options['file']; |
|
| 319 | + |
|
| 320 | + if ($options['methode'] == 'HEAD') { |
|
| 321 | + $options['taille_max'] = 0; |
|
| 322 | + } |
|
| 323 | + if (is_null($options['taille_max'])) { |
|
| 324 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + if (!empty($options['datas'])) { |
|
| 328 | + list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 329 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 330 | + $head .= 'Content-Length: ' . strlen($postdata); |
|
| 331 | + } |
|
| 332 | + $options['datas'] = $head . "\r\n\r\n" . $postdata; |
|
| 333 | + if (strlen($postdata)) { |
|
| 334 | + $options['methode'] = 'POST'; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 339 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 340 | + if (!tester_url_absolue($url)) { |
|
| 341 | + $url = 'http://' . $url; |
|
| 342 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 343 | + $url = 'http:' . $url; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + $url = url_to_ascii($url); |
|
| 347 | + |
|
| 348 | + $result = array( |
|
| 349 | + 'status' => 0, |
|
| 350 | + 'headers' => '', |
|
| 351 | + 'page' => '', |
|
| 352 | + 'length' => 0, |
|
| 353 | + 'last_modified' => '', |
|
| 354 | + 'location' => '', |
|
| 355 | + 'url' => $url |
|
| 356 | + ); |
|
| 357 | + |
|
| 358 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 359 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 360 | + |
|
| 361 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 362 | + list($handle, $fopen) = init_http( |
|
| 363 | + $options['methode'], |
|
| 364 | + $url, |
|
| 365 | + $refuser_gz, |
|
| 366 | + $options['uri_referer'], |
|
| 367 | + $options['datas'], |
|
| 368 | + $options['version_http'], |
|
| 369 | + $options['if_modified_since'] |
|
| 370 | + ); |
|
| 371 | + if (!$handle) { |
|
| 372 | + spip_log("ECHEC init_http $url"); |
|
| 373 | + |
|
| 374 | + return false; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 378 | + // et recuperer les en-tetes de reponses |
|
| 379 | + if (!$fopen) { |
|
| 380 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 381 | + if (!$res) { |
|
| 382 | + fclose($handle); |
|
| 383 | + $t = @parse_url($url); |
|
| 384 | + $host = $t['host']; |
|
| 385 | + // Chinoisierie inexplicable pour contrer |
|
| 386 | + // les actions liberticides de l'empire du milieu |
|
| 387 | + if (!need_proxy($host) |
|
| 388 | + and $res = @file_get_contents($url) |
|
| 389 | + ) { |
|
| 390 | + $result['length'] = strlen($res); |
|
| 391 | + if ($copy) { |
|
| 392 | + ecrire_fichier($copy, $res); |
|
| 393 | + $result['file'] = $copy; |
|
| 394 | + } else { |
|
| 395 | + $result['page'] = $res; |
|
| 396 | + } |
|
| 397 | + $res = array( |
|
| 398 | + 'status' => 200, |
|
| 399 | + ); |
|
| 400 | + } else { |
|
| 401 | + return false; |
|
| 402 | + } |
|
| 403 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 404 | + $options['follow_location']--; |
|
| 405 | + fclose($handle); |
|
| 406 | + include_spip('inc/filtres'); |
|
| 407 | + $url = suivre_lien($url, $res['location']); |
|
| 408 | + spip_log("recuperer_url recommence sur $url"); |
|
| 409 | + |
|
| 410 | + return recuperer_url($url, $options); |
|
| 411 | + } elseif ($res['status'] !== 200) { |
|
| 412 | + spip_log('HTTP status ' . $res['status'] . " pour $url"); |
|
| 413 | + } |
|
| 414 | + $result['status'] = $res['status']; |
|
| 415 | + if (isset($res['headers'])) { |
|
| 416 | + $result['headers'] = $res['headers']; |
|
| 417 | + } |
|
| 418 | + if (isset($res['last_modified'])) { |
|
| 419 | + $result['last_modified'] = $res['last_modified']; |
|
| 420 | + } |
|
| 421 | + if (isset($res['location'])) { |
|
| 422 | + $result['location'] = $res['location']; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + // on ne veut que les entetes |
|
| 427 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 428 | + return $result; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 433 | + // sinon la memoire explose pour les gros flux |
|
| 434 | + |
|
| 435 | + $gz = false; |
|
| 436 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 437 | + $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 441 | + if (!$result['length']) { |
|
| 442 | + $res = recuperer_body($handle, $options['taille_max'], $gz ? $gz : $copy); |
|
| 443 | + fclose($handle); |
|
| 444 | + if ($copy) { |
|
| 445 | + $result['length'] = $res; |
|
| 446 | + $result['file'] = $copy; |
|
| 447 | + } elseif ($res) { |
|
| 448 | + $result['page'] = &$res; |
|
| 449 | + $result['length'] = strlen($result['page']); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + if (!$result['page']) { |
|
| 453 | + return $result; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // Decompresser au besoin |
|
| 457 | + if ($gz) { |
|
| 458 | + $result['page'] = implode('', gzfile($gz)); |
|
| 459 | + supprimer_fichier($gz); |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + // Faut-il l'importer dans notre charset local ? |
|
| 463 | + if ($options['transcoder']) { |
|
| 464 | + include_spip('inc/charsets'); |
|
| 465 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + return $result; |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | /** |
@@ -481,72 +481,72 @@ discard block |
||
| 481 | 481 | * @return array|bool|mixed |
| 482 | 482 | */ |
| 483 | 483 | function recuperer_url_cache($url, $options = array()) { |
| 484 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 485 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 486 | - } |
|
| 487 | - $default = array( |
|
| 488 | - 'transcoder' => false, |
|
| 489 | - 'methode' => 'GET', |
|
| 490 | - 'taille_max' => null, |
|
| 491 | - 'datas' => '', |
|
| 492 | - 'boundary' => '', |
|
| 493 | - 'refuser_gz' => false, |
|
| 494 | - 'if_modified_since' => '', |
|
| 495 | - 'uri_referer' => '', |
|
| 496 | - 'file' => '', |
|
| 497 | - 'follow_location' => 10, |
|
| 498 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 499 | - 'delai_cache' => _DELAI_RECUPERER_URL_CACHE, |
|
| 500 | - ); |
|
| 501 | - $options = array_merge($default, $options); |
|
| 502 | - |
|
| 503 | - // cas ou il n'est pas possible de cacher |
|
| 504 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 505 | - return recuperer_url($url, $options); |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 509 | - static $errors = array(); |
|
| 510 | - if (isset($errors[$url])) { |
|
| 511 | - return $errors[$url]; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - $sig = $options; |
|
| 515 | - unset($sig['if_modified_since']); |
|
| 516 | - unset($sig['delai_cache']); |
|
| 517 | - $sig['url'] = $url; |
|
| 518 | - |
|
| 519 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 520 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 521 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 522 | - $cache = "$sub$cache"; |
|
| 523 | - |
|
| 524 | - $res = false; |
|
| 525 | - $is_cached = file_exists($cache); |
|
| 526 | - if ($is_cached |
|
| 527 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 528 | - ) { |
|
| 529 | - lire_fichier($cache, $res); |
|
| 530 | - if ($res = unserialize($res)) { |
|
| 531 | - // mettre le last_modified et le status=304 ? |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - if (!$res) { |
|
| 535 | - $res = recuperer_url($url, $options); |
|
| 536 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 537 | - if (!$res) { |
|
| 538 | - if ($is_cached) { |
|
| 539 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 540 | - lire_fichier($cache, $res); |
|
| 541 | - $res = unserialize($res); |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - return $errors[$url] = $res; |
|
| 545 | - } |
|
| 546 | - ecrire_fichier($cache, serialize($res)); |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - return $res; |
|
| 484 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 485 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 486 | + } |
|
| 487 | + $default = array( |
|
| 488 | + 'transcoder' => false, |
|
| 489 | + 'methode' => 'GET', |
|
| 490 | + 'taille_max' => null, |
|
| 491 | + 'datas' => '', |
|
| 492 | + 'boundary' => '', |
|
| 493 | + 'refuser_gz' => false, |
|
| 494 | + 'if_modified_since' => '', |
|
| 495 | + 'uri_referer' => '', |
|
| 496 | + 'file' => '', |
|
| 497 | + 'follow_location' => 10, |
|
| 498 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 499 | + 'delai_cache' => _DELAI_RECUPERER_URL_CACHE, |
|
| 500 | + ); |
|
| 501 | + $options = array_merge($default, $options); |
|
| 502 | + |
|
| 503 | + // cas ou il n'est pas possible de cacher |
|
| 504 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 505 | + return recuperer_url($url, $options); |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 509 | + static $errors = array(); |
|
| 510 | + if (isset($errors[$url])) { |
|
| 511 | + return $errors[$url]; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + $sig = $options; |
|
| 515 | + unset($sig['if_modified_since']); |
|
| 516 | + unset($sig['delai_cache']); |
|
| 517 | + $sig['url'] = $url; |
|
| 518 | + |
|
| 519 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 520 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 521 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 522 | + $cache = "$sub$cache"; |
|
| 523 | + |
|
| 524 | + $res = false; |
|
| 525 | + $is_cached = file_exists($cache); |
|
| 526 | + if ($is_cached |
|
| 527 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 528 | + ) { |
|
| 529 | + lire_fichier($cache, $res); |
|
| 530 | + if ($res = unserialize($res)) { |
|
| 531 | + // mettre le last_modified et le status=304 ? |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + if (!$res) { |
|
| 535 | + $res = recuperer_url($url, $options); |
|
| 536 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 537 | + if (!$res) { |
|
| 538 | + if ($is_cached) { |
|
| 539 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 540 | + lire_fichier($cache, $res); |
|
| 541 | + $res = unserialize($res); |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + return $errors[$url] = $res; |
|
| 545 | + } |
|
| 546 | + ecrire_fichier($cache, serialize($res)); |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + return $res; |
|
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | /** |
@@ -584,52 +584,52 @@ discard block |
||
| 584 | 584 | * - false si la page n'a pu être récupérée (status different de 200) |
| 585 | 585 | **/ |
| 586 | 586 | function recuperer_page( |
| 587 | - $url, |
|
| 588 | - $trans = false, |
|
| 589 | - $get_headers = false, |
|
| 590 | - $taille_max = null, |
|
| 591 | - $datas = '', |
|
| 592 | - $boundary = '', |
|
| 593 | - $refuser_gz = false, |
|
| 594 | - $date_verif = '', |
|
| 595 | - $uri_referer = '' |
|
| 587 | + $url, |
|
| 588 | + $trans = false, |
|
| 589 | + $get_headers = false, |
|
| 590 | + $taille_max = null, |
|
| 591 | + $datas = '', |
|
| 592 | + $boundary = '', |
|
| 593 | + $refuser_gz = false, |
|
| 594 | + $date_verif = '', |
|
| 595 | + $uri_referer = '' |
|
| 596 | 596 | ) { |
| 597 | - // $copy = copier le fichier ? |
|
| 598 | - $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-) |
|
| 599 | - |
|
| 600 | - if (!is_null($taille_max) and ($taille_max == 0)) { |
|
| 601 | - $get = 'HEAD'; |
|
| 602 | - } else { |
|
| 603 | - $get = 'GET'; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - $options = array( |
|
| 607 | - 'transcoder' => $trans === true, |
|
| 608 | - 'methode' => $get, |
|
| 609 | - 'datas' => $datas, |
|
| 610 | - 'boundary' => $boundary, |
|
| 611 | - 'refuser_gz' => $refuser_gz, |
|
| 612 | - 'if_modified_since' => $date_verif, |
|
| 613 | - 'uri_referer' => $uri_referer, |
|
| 614 | - 'file' => $copy ? $trans : '', |
|
| 615 | - 'follow_location' => 10, |
|
| 616 | - ); |
|
| 617 | - if (!is_null($taille_max)) { |
|
| 618 | - $options['taille_max'] = $taille_max; |
|
| 619 | - } |
|
| 620 | - // dix tentatives maximum en cas d'entetes 301... |
|
| 621 | - $res = recuperer_url($url, $options); |
|
| 622 | - if (!$res) { |
|
| 623 | - return false; |
|
| 624 | - } |
|
| 625 | - if ($res['status'] !== 200) { |
|
| 626 | - return false; |
|
| 627 | - } |
|
| 628 | - if ($get_headers) { |
|
| 629 | - return $res['headers'] . "\n" . $res['page']; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - return $res['page']; |
|
| 597 | + // $copy = copier le fichier ? |
|
| 598 | + $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-) |
|
| 599 | + |
|
| 600 | + if (!is_null($taille_max) and ($taille_max == 0)) { |
|
| 601 | + $get = 'HEAD'; |
|
| 602 | + } else { |
|
| 603 | + $get = 'GET'; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + $options = array( |
|
| 607 | + 'transcoder' => $trans === true, |
|
| 608 | + 'methode' => $get, |
|
| 609 | + 'datas' => $datas, |
|
| 610 | + 'boundary' => $boundary, |
|
| 611 | + 'refuser_gz' => $refuser_gz, |
|
| 612 | + 'if_modified_since' => $date_verif, |
|
| 613 | + 'uri_referer' => $uri_referer, |
|
| 614 | + 'file' => $copy ? $trans : '', |
|
| 615 | + 'follow_location' => 10, |
|
| 616 | + ); |
|
| 617 | + if (!is_null($taille_max)) { |
|
| 618 | + $options['taille_max'] = $taille_max; |
|
| 619 | + } |
|
| 620 | + // dix tentatives maximum en cas d'entetes 301... |
|
| 621 | + $res = recuperer_url($url, $options); |
|
| 622 | + if (!$res) { |
|
| 623 | + return false; |
|
| 624 | + } |
|
| 625 | + if ($res['status'] !== 200) { |
|
| 626 | + return false; |
|
| 627 | + } |
|
| 628 | + if ($get_headers) { |
|
| 629 | + return $res['headers'] . "\n" . $res['page']; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + return $res['page']; |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | |
@@ -666,48 +666,48 @@ discard block |
||
| 666 | 666 | * - false sinon |
| 667 | 667 | **/ |
| 668 | 668 | function recuperer_lapage( |
| 669 | - $url, |
|
| 670 | - $trans = false, |
|
| 671 | - $get = 'GET', |
|
| 672 | - $taille_max = 1048576, |
|
| 673 | - $datas = '', |
|
| 674 | - $refuser_gz = false, |
|
| 675 | - $date_verif = '', |
|
| 676 | - $uri_referer = '' |
|
| 669 | + $url, |
|
| 670 | + $trans = false, |
|
| 671 | + $get = 'GET', |
|
| 672 | + $taille_max = 1048576, |
|
| 673 | + $datas = '', |
|
| 674 | + $refuser_gz = false, |
|
| 675 | + $date_verif = '', |
|
| 676 | + $uri_referer = '' |
|
| 677 | 677 | ) { |
| 678 | - // $copy = copier le fichier ? |
|
| 679 | - $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-) |
|
| 680 | - |
|
| 681 | - // si on ecrit directement dans un fichier, pour ne pas manipuler |
|
| 682 | - // en memoire refuser gz |
|
| 683 | - if ($copy) { |
|
| 684 | - $refuser_gz = true; |
|
| 685 | - } |
|
| 686 | - |
|
| 687 | - $options = array( |
|
| 688 | - 'transcoder' => $trans === true, |
|
| 689 | - 'methode' => $get, |
|
| 690 | - 'datas' => $datas, |
|
| 691 | - 'refuser_gz' => $refuser_gz, |
|
| 692 | - 'if_modified_since' => $date_verif, |
|
| 693 | - 'uri_referer' => $uri_referer, |
|
| 694 | - 'file' => $copy ? $trans : '', |
|
| 695 | - 'follow_location' => false, |
|
| 696 | - ); |
|
| 697 | - if (!is_null($taille_max)) { |
|
| 698 | - $options['taille_max'] = $taille_max; |
|
| 699 | - } |
|
| 700 | - // dix tentatives maximum en cas d'entetes 301... |
|
| 701 | - $res = recuperer_url($url, $options); |
|
| 702 | - |
|
| 703 | - if (!$res) { |
|
| 704 | - return false; |
|
| 705 | - } |
|
| 706 | - if ($res['status'] !== 200) { |
|
| 707 | - return false; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return array($res['headers'], $res['page']); |
|
| 678 | + // $copy = copier le fichier ? |
|
| 679 | + $copy = (is_string($trans) and strlen($trans) > 5); // eviter "false" :-) |
|
| 680 | + |
|
| 681 | + // si on ecrit directement dans un fichier, pour ne pas manipuler |
|
| 682 | + // en memoire refuser gz |
|
| 683 | + if ($copy) { |
|
| 684 | + $refuser_gz = true; |
|
| 685 | + } |
|
| 686 | + |
|
| 687 | + $options = array( |
|
| 688 | + 'transcoder' => $trans === true, |
|
| 689 | + 'methode' => $get, |
|
| 690 | + 'datas' => $datas, |
|
| 691 | + 'refuser_gz' => $refuser_gz, |
|
| 692 | + 'if_modified_since' => $date_verif, |
|
| 693 | + 'uri_referer' => $uri_referer, |
|
| 694 | + 'file' => $copy ? $trans : '', |
|
| 695 | + 'follow_location' => false, |
|
| 696 | + ); |
|
| 697 | + if (!is_null($taille_max)) { |
|
| 698 | + $options['taille_max'] = $taille_max; |
|
| 699 | + } |
|
| 700 | + // dix tentatives maximum en cas d'entetes 301... |
|
| 701 | + $res = recuperer_url($url, $options); |
|
| 702 | + |
|
| 703 | + if (!$res) { |
|
| 704 | + return false; |
|
| 705 | + } |
|
| 706 | + if ($res['status'] !== 200) { |
|
| 707 | + return false; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return array($res['headers'], $res['page']); |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -725,41 +725,41 @@ discard block |
||
| 725 | 725 | * string contenu de la resource |
| 726 | 726 | */ |
| 727 | 727 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 728 | - $taille = 0; |
|
| 729 | - $result = ''; |
|
| 730 | - $fp = false; |
|
| 731 | - if ($fichier) { |
|
| 732 | - include_spip('inc/acces'); |
|
| 733 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 734 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 735 | - if (!$fp and file_exists($fichier)) { |
|
| 736 | - return filesize($fichier); |
|
| 737 | - } |
|
| 738 | - if (!$fp) { |
|
| 739 | - return false; |
|
| 740 | - } |
|
| 741 | - $result = 0; // on renvoie la taille du fichier |
|
| 742 | - } |
|
| 743 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 744 | - $res = fread($handle, 16384); |
|
| 745 | - $taille += strlen($res); |
|
| 746 | - if ($fp) { |
|
| 747 | - fwrite($fp, $res); |
|
| 748 | - $result = $taille; |
|
| 749 | - } else { |
|
| 750 | - $result .= $res; |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - if ($fp) { |
|
| 754 | - spip_fclose_unlock($fp); |
|
| 755 | - spip_unlink($fichier); |
|
| 756 | - @rename($tmpfile, $fichier); |
|
| 757 | - if (!file_exists($fichier)) { |
|
| 758 | - return false; |
|
| 759 | - } |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - return $result; |
|
| 728 | + $taille = 0; |
|
| 729 | + $result = ''; |
|
| 730 | + $fp = false; |
|
| 731 | + if ($fichier) { |
|
| 732 | + include_spip('inc/acces'); |
|
| 733 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 734 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 735 | + if (!$fp and file_exists($fichier)) { |
|
| 736 | + return filesize($fichier); |
|
| 737 | + } |
|
| 738 | + if (!$fp) { |
|
| 739 | + return false; |
|
| 740 | + } |
|
| 741 | + $result = 0; // on renvoie la taille du fichier |
|
| 742 | + } |
|
| 743 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 744 | + $res = fread($handle, 16384); |
|
| 745 | + $taille += strlen($res); |
|
| 746 | + if ($fp) { |
|
| 747 | + fwrite($fp, $res); |
|
| 748 | + $result = $taille; |
|
| 749 | + } else { |
|
| 750 | + $result .= $res; |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | + if ($fp) { |
|
| 754 | + spip_fclose_unlock($fp); |
|
| 755 | + spip_unlink($fichier); |
|
| 756 | + @rename($tmpfile, $fichier); |
|
| 757 | + if (!file_exists($fichier)) { |
|
| 758 | + return false; |
|
| 759 | + } |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + return $result; |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -781,34 +781,34 @@ discard block |
||
| 781 | 781 | * string location |
| 782 | 782 | */ |
| 783 | 783 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 784 | - $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => ''); |
|
| 785 | - |
|
| 786 | - $s = @trim(fgets($handle, 16384)); |
|
| 787 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 788 | - return false; |
|
| 789 | - } |
|
| 790 | - $result['status'] = intval($r[1]); |
|
| 791 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 792 | - $result['headers'][] = $s . "\n"; |
|
| 793 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 794 | - list(, $d, $v) = $r; |
|
| 795 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 796 | - $result['location'] = $v; |
|
| 797 | - } elseif ($d == 'Last-Modified') { |
|
| 798 | - $result['last_modified'] = strtotime($v); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - if ($if_modified_since |
|
| 802 | - and $result['last_modified'] |
|
| 803 | - and $if_modified_since > $result['last_modified'] |
|
| 804 | - and $result['status'] == 200 |
|
| 805 | - ) { |
|
| 806 | - $result['status'] = 304; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - $result['headers'] = implode('', $result['headers']); |
|
| 810 | - |
|
| 811 | - return $result; |
|
| 784 | + $result = array('status' => 0, 'headers' => array(), 'last_modified' => 0, 'location' => ''); |
|
| 785 | + |
|
| 786 | + $s = @trim(fgets($handle, 16384)); |
|
| 787 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 788 | + return false; |
|
| 789 | + } |
|
| 790 | + $result['status'] = intval($r[1]); |
|
| 791 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 792 | + $result['headers'][] = $s . "\n"; |
|
| 793 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 794 | + list(, $d, $v) = $r; |
|
| 795 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 796 | + $result['location'] = $v; |
|
| 797 | + } elseif ($d == 'Last-Modified') { |
|
| 798 | + $result['last_modified'] = strtotime($v); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + if ($if_modified_since |
|
| 802 | + and $result['last_modified'] |
|
| 803 | + and $if_modified_since > $result['last_modified'] |
|
| 804 | + and $result['status'] == 200 |
|
| 805 | + ) { |
|
| 806 | + $result['status'] = 304; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + $result['headers'] = implode('', $result['headers']); |
|
| 810 | + |
|
| 811 | + return $result; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -830,20 +830,20 @@ discard block |
||
| 830 | 830 | * - le tableau des entetes dans tous les autres cas |
| 831 | 831 | **/ |
| 832 | 832 | function recuperer_entetes($f, $date_verif = '') { |
| 833 | - //Cas ou la page distante n'a pas bouge depuis |
|
| 834 | - //la derniere visite |
|
| 835 | - $res = recuperer_entetes_complets($f, $date_verif); |
|
| 836 | - if (!$res) { |
|
| 837 | - return false; |
|
| 838 | - } |
|
| 839 | - if ($res['location']) { |
|
| 840 | - return $res['location']; |
|
| 841 | - } |
|
| 842 | - if ($res['status'] != 200) { |
|
| 843 | - return $res['status']; |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - return explode("\n", $res['headers']); |
|
| 833 | + //Cas ou la page distante n'a pas bouge depuis |
|
| 834 | + //la derniere visite |
|
| 835 | + $res = recuperer_entetes_complets($f, $date_verif); |
|
| 836 | + if (!$res) { |
|
| 837 | + return false; |
|
| 838 | + } |
|
| 839 | + if ($res['location']) { |
|
| 840 | + return $res['location']; |
|
| 841 | + } |
|
| 842 | + if ($res['status'] != 200) { |
|
| 843 | + return $res['status']; |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + return explode("\n", $res['headers']); |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
@@ -865,22 +865,22 @@ discard block |
||
| 865 | 865 | * Nom du fichier pour copie locale |
| 866 | 866 | **/ |
| 867 | 867 | function nom_fichier_copie_locale($source, $extension) { |
| 868 | - include_spip('inc/documents'); |
|
| 868 | + include_spip('inc/documents'); |
|
| 869 | 869 | |
| 870 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 871 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 870 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 871 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 872 | 872 | |
| 873 | - // on se place tout le temps comme si on etait a la racine |
|
| 874 | - if (_DIR_RACINE) { |
|
| 875 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 876 | - } |
|
| 873 | + // on se place tout le temps comme si on etait a la racine |
|
| 874 | + if (_DIR_RACINE) { |
|
| 875 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 876 | + } |
|
| 877 | 877 | |
| 878 | - $m = md5($source); |
|
| 878 | + $m = md5($source); |
|
| 879 | 879 | |
| 880 | - return $d |
|
| 881 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 882 | - . substr($m, 0, 4) |
|
| 883 | - . ".$extension"; |
|
| 880 | + return $d |
|
| 881 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 882 | + . substr($m, 0, 4) |
|
| 883 | + . ".$extension"; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | /** |
@@ -898,68 +898,68 @@ discard block |
||
| 898 | 898 | * Nom du fichier calculé |
| 899 | 899 | **/ |
| 900 | 900 | function fichier_copie_locale($source) { |
| 901 | - // Si c'est deja local pas de souci |
|
| 902 | - if (!tester_url_absolue($source)) { |
|
| 903 | - if (_DIR_RACINE) { |
|
| 904 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 905 | - } |
|
| 906 | - |
|
| 907 | - return $source; |
|
| 908 | - } |
|
| 909 | - |
|
| 910 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 911 | - // a deja ete copie en local avec cette extension |
|
| 912 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 913 | - $path_parts = pathinfo($source); |
|
| 914 | - if (!isset($path_parts['extension'])) { |
|
| 915 | - $path_parts['extension'] = ''; |
|
| 916 | - } |
|
| 917 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 918 | - if ($ext |
|
| 919 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 920 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 921 | - and file_exists(_DIR_RACINE . $f) |
|
| 922 | - ) { |
|
| 923 | - return $f; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - |
|
| 927 | - // Si c'est deja dans la table des documents, |
|
| 928 | - // ramener le nom de sa copie potentielle |
|
| 929 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 930 | - |
|
| 931 | - if ($ext) { |
|
| 932 | - return nom_fichier_copie_locale($source, $ext); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 936 | - // et si il n'aurait pas deja ete rapatrie |
|
| 937 | - |
|
| 938 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 939 | - |
|
| 940 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 941 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 942 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 943 | - return $f; |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - |
|
| 947 | - // Ping pour voir si son extension est connue et autorisee |
|
| 948 | - // avec mise en cache du resultat du ping |
|
| 949 | - |
|
| 950 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 951 | - if (!@file_exists($cache) |
|
| 952 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 953 | - or _request('var_mode') == 'recalcul' |
|
| 954 | - ) { |
|
| 955 | - $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 956 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 957 | - } |
|
| 958 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 959 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 960 | - return nom_fichier_copie_locale($source, $ext); |
|
| 961 | - } |
|
| 962 | - spip_log("pas de copie locale pour $source"); |
|
| 901 | + // Si c'est deja local pas de souci |
|
| 902 | + if (!tester_url_absolue($source)) { |
|
| 903 | + if (_DIR_RACINE) { |
|
| 904 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 905 | + } |
|
| 906 | + |
|
| 907 | + return $source; |
|
| 908 | + } |
|
| 909 | + |
|
| 910 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 911 | + // a deja ete copie en local avec cette extension |
|
| 912 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 913 | + $path_parts = pathinfo($source); |
|
| 914 | + if (!isset($path_parts['extension'])) { |
|
| 915 | + $path_parts['extension'] = ''; |
|
| 916 | + } |
|
| 917 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 918 | + if ($ext |
|
| 919 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 920 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 921 | + and file_exists(_DIR_RACINE . $f) |
|
| 922 | + ) { |
|
| 923 | + return $f; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + |
|
| 927 | + // Si c'est deja dans la table des documents, |
|
| 928 | + // ramener le nom de sa copie potentielle |
|
| 929 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 930 | + |
|
| 931 | + if ($ext) { |
|
| 932 | + return nom_fichier_copie_locale($source, $ext); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 936 | + // et si il n'aurait pas deja ete rapatrie |
|
| 937 | + |
|
| 938 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 939 | + |
|
| 940 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 941 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 942 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 943 | + return $f; |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + |
|
| 947 | + // Ping pour voir si son extension est connue et autorisee |
|
| 948 | + // avec mise en cache du resultat du ping |
|
| 949 | + |
|
| 950 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 951 | + if (!@file_exists($cache) |
|
| 952 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 953 | + or _request('var_mode') == 'recalcul' |
|
| 954 | + ) { |
|
| 955 | + $path_parts = recuperer_infos_distantes($source, 0, false); |
|
| 956 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 957 | + } |
|
| 958 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 959 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 960 | + return nom_fichier_copie_locale($source, $ext); |
|
| 961 | + } |
|
| 962 | + spip_log("pas de copie locale pour $source"); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | |
@@ -987,141 +987,141 @@ discard block |
||
| 987 | 987 | **/ |
| 988 | 988 | function recuperer_infos_distantes($source, $max = 0, $charger_si_petite_image = true) { |
| 989 | 989 | |
| 990 | - // pas la peine de perdre son temps |
|
| 991 | - if (!tester_url_absolue($source)) { |
|
| 992 | - return false; |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - # charger les alias des types mime |
|
| 996 | - include_spip('base/typedoc'); |
|
| 997 | - |
|
| 998 | - $a = array(); |
|
| 999 | - $mime_type = ''; |
|
| 1000 | - // On va directement charger le debut des images et des fichiers html, |
|
| 1001 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 1002 | - // ca echoue l'utilisateur devra les entrer... |
|
| 1003 | - if ($headers = recuperer_page($source, false, true, $max, '', '', true)) { |
|
| 1004 | - list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
|
| 1005 | - |
|
| 1006 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1007 | - $mime_type = (trim($regs[1])); |
|
| 1008 | - } else { |
|
| 1009 | - $mime_type = ''; |
|
| 1010 | - } // inconnu |
|
| 1011 | - |
|
| 1012 | - // Appliquer les alias |
|
| 1013 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1014 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1015 | - } |
|
| 1016 | - |
|
| 1017 | - // Si on a un mime-type insignifiant |
|
| 1018 | - // text/plain,application/octet-stream ou vide |
|
| 1019 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1020 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1021 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1022 | - $t = null; |
|
| 1023 | - if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) { |
|
| 1024 | - if (!$t |
|
| 1025 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1026 | - ) { |
|
| 1027 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1028 | - } |
|
| 1029 | - if (!$t |
|
| 1030 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1031 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1032 | - ) { |
|
| 1033 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1034 | - } |
|
| 1035 | - } |
|
| 1036 | - |
|
| 1037 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1038 | - if (!$t) { |
|
| 1039 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1043 | - // On essaie de nouveau avec l'extension |
|
| 1044 | - if (!$t |
|
| 1045 | - and $mime_type != 'text/plain' |
|
| 1046 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1047 | - ) { |
|
| 1048 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1049 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - if ($t) { |
|
| 1053 | - spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 1054 | - $a['extension'] = $t['extension']; |
|
| 1055 | - } else { |
|
| 1056 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1057 | - spip_log("mime-type $mime_type inconnu"); |
|
| 1058 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1059 | - if (!$t) { |
|
| 1060 | - return false; |
|
| 1061 | - } |
|
| 1062 | - $a['extension'] = $t['extension']; |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1066 | - $a['taille'] = intval($regs[1]); |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - // Echec avec HEAD, on tente avec GET |
|
| 1071 | - if (!$a and !$max) { |
|
| 1072 | - spip_log("tenter GET $source"); |
|
| 1073 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1074 | - } |
|
| 1075 | - |
|
| 1076 | - // si on a rien trouve pas la peine d'insister |
|
| 1077 | - if (!$a) { |
|
| 1078 | - return false; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1082 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1083 | - if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)) { |
|
| 1084 | - if ($max == 0 |
|
| 1085 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1086 | - and isset($GLOBALS['meta']['formats_graphiques']) |
|
| 1087 | - and (strpos($GLOBALS['meta']['formats_graphiques'], $a['extension']) !== false) |
|
| 1088 | - and $charger_si_petite_image |
|
| 1089 | - ) { |
|
| 1090 | - $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1091 | - } else { |
|
| 1092 | - if ($a['body']) { |
|
| 1093 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 1094 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1095 | - $size_image = @getimagesize($a['fichier']); |
|
| 1096 | - $a['largeur'] = intval($size_image[0]); |
|
| 1097 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1098 | - $a['type_image'] = true; |
|
| 1099 | - } |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - |
|
| 1103 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1104 | - // ce sera mieux que 0x0 |
|
| 1105 | - if ($a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1106 | - and empty($a['largeur']) |
|
| 1107 | - ) { |
|
| 1108 | - $a['largeur'] = 425; |
|
| 1109 | - $a['hauteur'] = 350; |
|
| 1110 | - } |
|
| 1111 | - |
|
| 1112 | - if ($mime_type == 'text/html') { |
|
| 1113 | - include_spip('inc/filtres'); |
|
| 1114 | - $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
|
| 1115 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1116 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1117 | - } |
|
| 1118 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1119 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1120 | - } |
|
| 1121 | - } |
|
| 1122 | - $a['mime_type'] = $mime_type; |
|
| 1123 | - |
|
| 1124 | - return $a; |
|
| 990 | + // pas la peine de perdre son temps |
|
| 991 | + if (!tester_url_absolue($source)) { |
|
| 992 | + return false; |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + # charger les alias des types mime |
|
| 996 | + include_spip('base/typedoc'); |
|
| 997 | + |
|
| 998 | + $a = array(); |
|
| 999 | + $mime_type = ''; |
|
| 1000 | + // On va directement charger le debut des images et des fichiers html, |
|
| 1001 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 1002 | + // ca echoue l'utilisateur devra les entrer... |
|
| 1003 | + if ($headers = recuperer_page($source, false, true, $max, '', '', true)) { |
|
| 1004 | + list($headers, $a['body']) = preg_split(',\n\n,', $headers, 2); |
|
| 1005 | + |
|
| 1006 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1007 | + $mime_type = (trim($regs[1])); |
|
| 1008 | + } else { |
|
| 1009 | + $mime_type = ''; |
|
| 1010 | + } // inconnu |
|
| 1011 | + |
|
| 1012 | + // Appliquer les alias |
|
| 1013 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1014 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1015 | + } |
|
| 1016 | + |
|
| 1017 | + // Si on a un mime-type insignifiant |
|
| 1018 | + // text/plain,application/octet-stream ou vide |
|
| 1019 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1020 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1021 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1022 | + $t = null; |
|
| 1023 | + if (in_array($mime_type, array('text/plain', '', 'application/octet-stream'))) { |
|
| 1024 | + if (!$t |
|
| 1025 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1026 | + ) { |
|
| 1027 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1028 | + } |
|
| 1029 | + if (!$t |
|
| 1030 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1031 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1032 | + ) { |
|
| 1033 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | + |
|
| 1037 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1038 | + if (!$t) { |
|
| 1039 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1043 | + // On essaie de nouveau avec l'extension |
|
| 1044 | + if (!$t |
|
| 1045 | + and $mime_type != 'text/plain' |
|
| 1046 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1047 | + ) { |
|
| 1048 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1049 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + if ($t) { |
|
| 1053 | + spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 1054 | + $a['extension'] = $t['extension']; |
|
| 1055 | + } else { |
|
| 1056 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1057 | + spip_log("mime-type $mime_type inconnu"); |
|
| 1058 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1059 | + if (!$t) { |
|
| 1060 | + return false; |
|
| 1061 | + } |
|
| 1062 | + $a['extension'] = $t['extension']; |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1066 | + $a['taille'] = intval($regs[1]); |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + // Echec avec HEAD, on tente avec GET |
|
| 1071 | + if (!$a and !$max) { |
|
| 1072 | + spip_log("tenter GET $source"); |
|
| 1073 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1074 | + } |
|
| 1075 | + |
|
| 1076 | + // si on a rien trouve pas la peine d'insister |
|
| 1077 | + if (!$a) { |
|
| 1078 | + return false; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1082 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1083 | + if (preg_match(',^image/(jpeg|gif|png|swf),', $mime_type)) { |
|
| 1084 | + if ($max == 0 |
|
| 1085 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1086 | + and isset($GLOBALS['meta']['formats_graphiques']) |
|
| 1087 | + and (strpos($GLOBALS['meta']['formats_graphiques'], $a['extension']) !== false) |
|
| 1088 | + and $charger_si_petite_image |
|
| 1089 | + ) { |
|
| 1090 | + $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
|
| 1091 | + } else { |
|
| 1092 | + if ($a['body']) { |
|
| 1093 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 1094 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1095 | + $size_image = @getimagesize($a['fichier']); |
|
| 1096 | + $a['largeur'] = intval($size_image[0]); |
|
| 1097 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1098 | + $a['type_image'] = true; |
|
| 1099 | + } |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + |
|
| 1103 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1104 | + // ce sera mieux que 0x0 |
|
| 1105 | + if ($a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1106 | + and empty($a['largeur']) |
|
| 1107 | + ) { |
|
| 1108 | + $a['largeur'] = 425; |
|
| 1109 | + $a['hauteur'] = 350; |
|
| 1110 | + } |
|
| 1111 | + |
|
| 1112 | + if ($mime_type == 'text/html') { |
|
| 1113 | + include_spip('inc/filtres'); |
|
| 1114 | + $page = recuperer_page($source, true, false, _INC_DISTANT_MAX_SIZE); |
|
| 1115 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1116 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1117 | + } |
|
| 1118 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1119 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1120 | + } |
|
| 1121 | + } |
|
| 1122 | + $a['mime_type'] = $mime_type; |
|
| 1123 | + |
|
| 1124 | + return $a; |
|
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | 1127 | |
@@ -1137,19 +1137,19 @@ discard block |
||
| 1137 | 1137 | * @return string |
| 1138 | 1138 | */ |
| 1139 | 1139 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1140 | - if (is_null($http_proxy)) { |
|
| 1141 | - $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1142 | - } |
|
| 1143 | - if (is_null($http_noproxy)) { |
|
| 1144 | - $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - $domain = substr($host, strpos($host, '.')); |
|
| 1148 | - |
|
| 1149 | - return ($http_proxy |
|
| 1150 | - and (strpos(" $http_noproxy ", " $host ") === false |
|
| 1151 | - and (strpos(" $http_noproxy ", " $domain ") === false))) |
|
| 1152 | - ? $http_proxy : ''; |
|
| 1140 | + if (is_null($http_proxy)) { |
|
| 1141 | + $http_proxy = isset($GLOBALS['meta']['http_proxy']) ? $GLOBALS['meta']['http_proxy'] : null; |
|
| 1142 | + } |
|
| 1143 | + if (is_null($http_noproxy)) { |
|
| 1144 | + $http_noproxy = isset($GLOBALS['meta']['http_noproxy']) ? $GLOBALS['meta']['http_noproxy'] : null; |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + $domain = substr($host, strpos($host, '.')); |
|
| 1148 | + |
|
| 1149 | + return ($http_proxy |
|
| 1150 | + and (strpos(" $http_noproxy ", " $host ") === false |
|
| 1151 | + and (strpos(" $http_noproxy ", " $domain ") === false))) |
|
| 1152 | + ? $http_proxy : ''; |
|
| 1153 | 1153 | } |
| 1154 | 1154 | |
| 1155 | 1155 | |
@@ -1172,58 +1172,58 @@ discard block |
||
| 1172 | 1172 | * @return array |
| 1173 | 1173 | */ |
| 1174 | 1174 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1175 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1176 | - $fopen = false; |
|
| 1177 | - |
|
| 1178 | - $t = @parse_url($url); |
|
| 1179 | - $host = $t['host']; |
|
| 1180 | - if ($t['scheme'] == 'http') { |
|
| 1181 | - $scheme = 'http'; |
|
| 1182 | - $noproxy = ''; |
|
| 1183 | - } elseif ($t['scheme'] == 'https') { |
|
| 1184 | - $scheme = 'ssl'; |
|
| 1185 | - $noproxy = 'ssl://'; |
|
| 1186 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1187 | - $t['port'] = 443; |
|
| 1188 | - } |
|
| 1189 | - } else { |
|
| 1190 | - $scheme = $t['scheme']; |
|
| 1191 | - $noproxy = $scheme . '://'; |
|
| 1192 | - } |
|
| 1193 | - if (isset($t['user'])) { |
|
| 1194 | - $user = array($t['user'], $t['pass']); |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1198 | - $port = 80; |
|
| 1199 | - } |
|
| 1200 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1201 | - $path = '/'; |
|
| 1202 | - } |
|
| 1203 | - |
|
| 1204 | - if (!empty($t['query'])) { |
|
| 1205 | - $path .= '?' . $t['query']; |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1209 | - if (!$f or !is_resource($f)) { |
|
| 1210 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1211 | - // ce qui correspond a $f===110 |
|
| 1212 | - if ($f !== 110 |
|
| 1213 | - and !need_proxy($host) |
|
| 1214 | - and !_request('tester_proxy') |
|
| 1215 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1216 | - ) { |
|
| 1217 | - $f = @fopen($url, 'rb'); |
|
| 1218 | - spip_log("connexion vers $url par simple fopen"); |
|
| 1219 | - $fopen = true; |
|
| 1220 | - } else { |
|
| 1221 | - // echec total |
|
| 1222 | - $f = false; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - return array($f, $fopen); |
|
| 1175 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1176 | + $fopen = false; |
|
| 1177 | + |
|
| 1178 | + $t = @parse_url($url); |
|
| 1179 | + $host = $t['host']; |
|
| 1180 | + if ($t['scheme'] == 'http') { |
|
| 1181 | + $scheme = 'http'; |
|
| 1182 | + $noproxy = ''; |
|
| 1183 | + } elseif ($t['scheme'] == 'https') { |
|
| 1184 | + $scheme = 'ssl'; |
|
| 1185 | + $noproxy = 'ssl://'; |
|
| 1186 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1187 | + $t['port'] = 443; |
|
| 1188 | + } |
|
| 1189 | + } else { |
|
| 1190 | + $scheme = $t['scheme']; |
|
| 1191 | + $noproxy = $scheme . '://'; |
|
| 1192 | + } |
|
| 1193 | + if (isset($t['user'])) { |
|
| 1194 | + $user = array($t['user'], $t['pass']); |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1198 | + $port = 80; |
|
| 1199 | + } |
|
| 1200 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1201 | + $path = '/'; |
|
| 1202 | + } |
|
| 1203 | + |
|
| 1204 | + if (!empty($t['query'])) { |
|
| 1205 | + $path .= '?' . $t['query']; |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1209 | + if (!$f or !is_resource($f)) { |
|
| 1210 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1211 | + // ce qui correspond a $f===110 |
|
| 1212 | + if ($f !== 110 |
|
| 1213 | + and !need_proxy($host) |
|
| 1214 | + and !_request('tester_proxy') |
|
| 1215 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1216 | + ) { |
|
| 1217 | + $f = @fopen($url, 'rb'); |
|
| 1218 | + spip_log("connexion vers $url par simple fopen"); |
|
| 1219 | + $fopen = true; |
|
| 1220 | + } else { |
|
| 1221 | + // echec total |
|
| 1222 | + $f = false; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + return array($f, $fopen); |
|
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | 1229 | /** |
@@ -1258,123 +1258,123 @@ discard block |
||
| 1258 | 1258 | * resource socket vers l'url demandee |
| 1259 | 1259 | */ |
| 1260 | 1260 | function lance_requete( |
| 1261 | - $method, |
|
| 1262 | - $scheme, |
|
| 1263 | - $user, |
|
| 1264 | - $host, |
|
| 1265 | - $path, |
|
| 1266 | - $port, |
|
| 1267 | - $noproxy, |
|
| 1268 | - $refuse_gz = false, |
|
| 1269 | - $referer = '', |
|
| 1270 | - $datas = '', |
|
| 1271 | - $vers = 'HTTP/1.0', |
|
| 1272 | - $date = '' |
|
| 1261 | + $method, |
|
| 1262 | + $scheme, |
|
| 1263 | + $user, |
|
| 1264 | + $host, |
|
| 1265 | + $path, |
|
| 1266 | + $port, |
|
| 1267 | + $noproxy, |
|
| 1268 | + $refuse_gz = false, |
|
| 1269 | + $referer = '', |
|
| 1270 | + $datas = '', |
|
| 1271 | + $vers = 'HTTP/1.0', |
|
| 1272 | + $date = '' |
|
| 1273 | 1273 | ) { |
| 1274 | 1274 | |
| 1275 | - $proxy_user = ''; |
|
| 1276 | - $http_proxy = need_proxy($host); |
|
| 1277 | - if ($user) { |
|
| 1278 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1279 | - } |
|
| 1280 | - |
|
| 1281 | - $connect = ''; |
|
| 1282 | - if ($http_proxy) { |
|
| 1283 | - if (defined('_PROXY_HTTPS_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1284 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1285 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1286 | - . "Host: $path_host\r\n" |
|
| 1287 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1288 | - } else { |
|
| 1289 | - $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1290 | - . (!$user ? '' : "$user@") |
|
| 1291 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1292 | - } |
|
| 1293 | - $t2 = @parse_url($http_proxy); |
|
| 1294 | - $first_host = $t2['host']; |
|
| 1295 | - if (!($port = $t2['port'])) { |
|
| 1296 | - $port = 80; |
|
| 1297 | - } |
|
| 1298 | - if ($t2['user']) { |
|
| 1299 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1300 | - } |
|
| 1301 | - } else { |
|
| 1302 | - $first_host = $noproxy . $host; |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - if ($connect) { |
|
| 1306 | - $streamContext = stream_context_create(array( |
|
| 1307 | - 'ssl' => array( |
|
| 1308 | - 'verify_peer' => false, |
|
| 1309 | - 'allow_self_signed' => true, |
|
| 1310 | - 'SNI_enabled' => true, |
|
| 1311 | - 'peer_name' => $host, |
|
| 1312 | - ) |
|
| 1313 | - )); |
|
| 1314 | - if (version_compare(phpversion(), '5.6', '<')) { |
|
| 1315 | - stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host); |
|
| 1316 | - } |
|
| 1317 | - $f = @stream_socket_client( |
|
| 1318 | - "tcp://$first_host:$port", |
|
| 1319 | - $errno, |
|
| 1320 | - $errstr, |
|
| 1321 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1322 | - STREAM_CLIENT_CONNECT, |
|
| 1323 | - $streamContext |
|
| 1324 | - ); |
|
| 1325 | - spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1326 | - if (!$f) { |
|
| 1327 | - spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 1328 | - return $errno; |
|
| 1329 | - } |
|
| 1330 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1331 | - |
|
| 1332 | - fputs($f, $connect); |
|
| 1333 | - fputs($f, "\r\n"); |
|
| 1334 | - $res = fread($f, 1024); |
|
| 1335 | - if (!$res |
|
| 1336 | - or !count($res = explode(' ', $res)) |
|
| 1337 | - or $res[1] !== '200' |
|
| 1338 | - ) { |
|
| 1339 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1340 | - fclose($f); |
|
| 1341 | - |
|
| 1342 | - return false; |
|
| 1343 | - } |
|
| 1344 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1345 | - stream_set_blocking($f, true); |
|
| 1346 | - // envoyer le handshake |
|
| 1347 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1348 | - spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1349 | - } else { |
|
| 1350 | - $ntry = 3; |
|
| 1351 | - do { |
|
| 1352 | - $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1353 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1354 | - spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1355 | - if (!$f) { |
|
| 1356 | - spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 1357 | - |
|
| 1358 | - return $errno; |
|
| 1359 | - } |
|
| 1360 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1364 | - |
|
| 1365 | - $req = "$method $path $vers\r\n" |
|
| 1366 | - . "Host: $host\r\n" |
|
| 1367 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1368 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1369 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1370 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1371 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1372 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1373 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1275 | + $proxy_user = ''; |
|
| 1276 | + $http_proxy = need_proxy($host); |
|
| 1277 | + if ($user) { |
|
| 1278 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1279 | + } |
|
| 1280 | + |
|
| 1281 | + $connect = ''; |
|
| 1282 | + if ($http_proxy) { |
|
| 1283 | + if (defined('_PROXY_HTTPS_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1284 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1285 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1286 | + . "Host: $path_host\r\n" |
|
| 1287 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1288 | + } else { |
|
| 1289 | + $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1290 | + . (!$user ? '' : "$user@") |
|
| 1291 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1292 | + } |
|
| 1293 | + $t2 = @parse_url($http_proxy); |
|
| 1294 | + $first_host = $t2['host']; |
|
| 1295 | + if (!($port = $t2['port'])) { |
|
| 1296 | + $port = 80; |
|
| 1297 | + } |
|
| 1298 | + if ($t2['user']) { |
|
| 1299 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1300 | + } |
|
| 1301 | + } else { |
|
| 1302 | + $first_host = $noproxy . $host; |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + if ($connect) { |
|
| 1306 | + $streamContext = stream_context_create(array( |
|
| 1307 | + 'ssl' => array( |
|
| 1308 | + 'verify_peer' => false, |
|
| 1309 | + 'allow_self_signed' => true, |
|
| 1310 | + 'SNI_enabled' => true, |
|
| 1311 | + 'peer_name' => $host, |
|
| 1312 | + ) |
|
| 1313 | + )); |
|
| 1314 | + if (version_compare(phpversion(), '5.6', '<')) { |
|
| 1315 | + stream_context_set_option($streamContext, 'ssl', 'SNI_server_name', $host); |
|
| 1316 | + } |
|
| 1317 | + $f = @stream_socket_client( |
|
| 1318 | + "tcp://$first_host:$port", |
|
| 1319 | + $errno, |
|
| 1320 | + $errstr, |
|
| 1321 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1322 | + STREAM_CLIENT_CONNECT, |
|
| 1323 | + $streamContext |
|
| 1324 | + ); |
|
| 1325 | + spip_log("Recuperer $path sur $first_host:$port par $f (via CONNECT)", 'connect'); |
|
| 1326 | + if (!$f) { |
|
| 1327 | + spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 1328 | + return $errno; |
|
| 1329 | + } |
|
| 1330 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1331 | + |
|
| 1332 | + fputs($f, $connect); |
|
| 1333 | + fputs($f, "\r\n"); |
|
| 1334 | + $res = fread($f, 1024); |
|
| 1335 | + if (!$res |
|
| 1336 | + or !count($res = explode(' ', $res)) |
|
| 1337 | + or $res[1] !== '200' |
|
| 1338 | + ) { |
|
| 1339 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1340 | + fclose($f); |
|
| 1341 | + |
|
| 1342 | + return false; |
|
| 1343 | + } |
|
| 1344 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1345 | + stream_set_blocking($f, true); |
|
| 1346 | + // envoyer le handshake |
|
| 1347 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1348 | + spip_log("OK CONNECT sur $first_host:$port", 'connect'); |
|
| 1349 | + } else { |
|
| 1350 | + $ntry = 3; |
|
| 1351 | + do { |
|
| 1352 | + $f = @fsockopen($first_host, $port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1353 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1354 | + spip_log("Recuperer $path sur $first_host:$port par $f"); |
|
| 1355 | + if (!$f) { |
|
| 1356 | + spip_log("Erreur connexion $errno $errstr", _LOG_ERREUR); |
|
| 1357 | + |
|
| 1358 | + return $errno; |
|
| 1359 | + } |
|
| 1360 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + $site = isset($GLOBALS['meta']['adresse_site']) ? $GLOBALS['meta']['adresse_site'] : ''; |
|
| 1364 | + |
|
| 1365 | + $req = "$method $path $vers\r\n" |
|
| 1366 | + . "Host: $host\r\n" |
|
| 1367 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1368 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1369 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1370 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1371 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1372 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1373 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1374 | 1374 | |
| 1375 | 1375 | # spip_log("Requete\n$req"); |
| 1376 | - fputs($f, $req); |
|
| 1377 | - fputs($f, $datas ? $datas : "\r\n"); |
|
| 1376 | + fputs($f, $req); |
|
| 1377 | + fputs($f, $datas ? $datas : "\r\n"); |
|
| 1378 | 1378 | |
| 1379 | - return $f; |
|
| 1379 | + return $f; |
|
| 1380 | 1380 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
| 27 | 27 | } |
| 28 | 28 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 29 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 29 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')'); |
|
| 30 | 30 | } |
| 31 | 31 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 32 | 32 | define('_INC_DISTANT_MAX_SIZE', 2097152); |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 38 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 39 | 39 | preg_replace( |
| 40 | 40 | '@^https?:@', |
| 41 | 41 | 'https?:', |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | |
| 71 | 71 | // si c'est la protection de soi-meme, retourner le path |
| 72 | 72 | if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 73 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 73 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 74 | 74 | |
| 75 | 75 | return @file_exists($source) ? $source : false; |
| 76 | 76 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | return false; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - $localrac = _DIR_RACINE . $local; |
|
| 93 | + $localrac = _DIR_RACINE.$local; |
|
| 94 | 94 | $t = ($mode == 'force') ? false : @file_exists($localrac); |
| 95 | 95 | |
| 96 | 96 | // test d'existence du fichier |
@@ -115,13 +115,13 @@ discard block |
||
| 115 | 115 | array('file' => $localrac, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : '') |
| 116 | 116 | ); |
| 117 | 117 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 118 | - spip_log("copie_locale : Echec recuperation $source sur $localrac status : " . $res['status'], _LOG_INFO_IMPORTANTE); |
|
| 118 | + spip_log("copie_locale : Echec recuperation $source sur $localrac status : ".$res['status'], _LOG_INFO_IMPORTANTE); |
|
| 119 | 119 | } |
| 120 | 120 | if (!$res['length']) { |
| 121 | 121 | // si $t c'est sans doute juste un not-modified-since |
| 122 | 122 | return $t ? $local : false; |
| 123 | 123 | } |
| 124 | - spip_log("copie_locale : recuperation $source sur $localrac taille " . $res['length'] . ' OK'); |
|
| 124 | + spip_log("copie_locale : recuperation $source sur $localrac taille ".$res['length'].' OK'); |
|
| 125 | 125 | |
| 126 | 126 | // pour une eventuelle indexation |
| 127 | 127 | pipeline( |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | if ($taille > 500) { |
| 192 | - $boundary = substr(md5(rand() . 'spip'), 0, 8); |
|
| 192 | + $boundary = substr(md5(rand().'spip'), 0, 8); |
|
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | |
@@ -217,16 +217,16 @@ discard block |
||
| 217 | 217 | } |
| 218 | 218 | } else { |
| 219 | 219 | // fabrique une chaine HTTP simple pour un POST |
| 220 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 220 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 221 | 221 | $chaine = array(); |
| 222 | 222 | if (is_array($donnees)) { |
| 223 | 223 | foreach ($donnees as $cle => $valeur) { |
| 224 | 224 | if (is_array($valeur)) { |
| 225 | 225 | foreach ($valeur as $val2) { |
| 226 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 226 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 227 | 227 | } |
| 228 | 228 | } else { |
| 229 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 229 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | $chaine = implode('&', $chaine); |
@@ -327,9 +327,9 @@ discard block |
||
| 327 | 327 | if (!empty($options['datas'])) { |
| 328 | 328 | list($head, $postdata) = prepare_donnees_post($options['datas'], $options['boundary']); |
| 329 | 329 | if (stripos($head, 'Content-Length:') === false) { |
| 330 | - $head .= 'Content-Length: ' . strlen($postdata); |
|
| 330 | + $head .= 'Content-Length: '.strlen($postdata); |
|
| 331 | 331 | } |
| 332 | - $options['datas'] = $head . "\r\n\r\n" . $postdata; |
|
| 332 | + $options['datas'] = $head."\r\n\r\n".$postdata; |
|
| 333 | 333 | if (strlen($postdata)) { |
| 334 | 334 | $options['methode'] = 'POST'; |
| 335 | 335 | } |
@@ -338,9 +338,9 @@ discard block |
||
| 338 | 338 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
| 339 | 339 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 340 | 340 | if (!tester_url_absolue($url)) { |
| 341 | - $url = 'http://' . $url; |
|
| 341 | + $url = 'http://'.$url; |
|
| 342 | 342 | } elseif (strncmp($url, '//', 2) == 0) { |
| 343 | - $url = 'http:' . $url; |
|
| 343 | + $url = 'http:'.$url; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | $url = url_to_ascii($url); |
@@ -409,7 +409,7 @@ discard block |
||
| 409 | 409 | |
| 410 | 410 | return recuperer_url($url, $options); |
| 411 | 411 | } elseif ($res['status'] !== 200) { |
| 412 | - spip_log('HTTP status ' . $res['status'] . " pour $url"); |
|
| 412 | + spip_log('HTTP status '.$res['status']." pour $url"); |
|
| 413 | 413 | } |
| 414 | 414 | $result['status'] = $res['status']; |
| 415 | 415 | if (isset($res['headers'])) { |
@@ -434,7 +434,7 @@ discard block |
||
| 434 | 434 | |
| 435 | 435 | $gz = false; |
| 436 | 436 | if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
| 437 | - $gz = (_DIR_TMP . md5(uniqid(mt_rand())) . '.tmp.gz'); |
|
| 437 | + $gz = (_DIR_TMP.md5(uniqid(mt_rand())).'.tmp.gz'); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | // si on a pas deja recuperer le contenu par une methode detournee |
@@ -517,7 +517,7 @@ discard block |
||
| 517 | 517 | $sig['url'] = $url; |
| 518 | 518 | |
| 519 | 519 | $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
| 520 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 520 | + $cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 521 | 521 | $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
| 522 | 522 | $cache = "$sub$cache"; |
| 523 | 523 | |
@@ -626,7 +626,7 @@ discard block |
||
| 626 | 626 | return false; |
| 627 | 627 | } |
| 628 | 628 | if ($get_headers) { |
| 629 | - return $res['headers'] . "\n" . $res['page']; |
|
| 629 | + return $res['headers']."\n".$res['page']; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | return $res['page']; |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | $fp = false; |
| 731 | 731 | if ($fichier) { |
| 732 | 732 | include_spip('inc/acces'); |
| 733 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 733 | + $tmpfile = "$fichier.".creer_uniqid().'.tmp'; |
|
| 734 | 734 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 735 | 735 | if (!$fp and file_exists($fichier)) { |
| 736 | 736 | return filesize($fichier); |
@@ -789,7 +789,7 @@ discard block |
||
| 789 | 789 | } |
| 790 | 790 | $result['status'] = intval($r[1]); |
| 791 | 791 | while ($s = trim(fgets($handle, 16384))) { |
| 792 | - $result['headers'][] = $s . "\n"; |
|
| 792 | + $result['headers'][] = $s."\n"; |
|
| 793 | 793 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 794 | 794 | list(, $d, $v) = $r; |
| 795 | 795 | if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
@@ -872,13 +872,13 @@ discard block |
||
| 872 | 872 | |
| 873 | 873 | // on se place tout le temps comme si on etait a la racine |
| 874 | 874 | if (_DIR_RACINE) { |
| 875 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 875 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | $m = md5($source); |
| 879 | 879 | |
| 880 | 880 | return $d |
| 881 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 881 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 882 | 882 | . substr($m, 0, 4) |
| 883 | 883 | . ".$extension"; |
| 884 | 884 | } |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | // Si c'est deja local pas de souci |
| 902 | 902 | if (!tester_url_absolue($source)) { |
| 903 | 903 | if (_DIR_RACINE) { |
| 904 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 904 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | return $source; |
@@ -918,7 +918,7 @@ discard block |
||
| 918 | 918 | if ($ext |
| 919 | 919 | and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 920 | 920 | and $f = nom_fichier_copie_locale($source, $ext) |
| 921 | - and file_exists(_DIR_RACINE . $f) |
|
| 921 | + and file_exists(_DIR_RACINE.$f) |
|
| 922 | 922 | ) { |
| 923 | 923 | return $f; |
| 924 | 924 | } |
@@ -926,7 +926,7 @@ discard block |
||
| 926 | 926 | |
| 927 | 927 | // Si c'est deja dans la table des documents, |
| 928 | 928 | // ramener le nom de sa copie potentielle |
| 929 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 929 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 930 | 930 | |
| 931 | 931 | if ($ext) { |
| 932 | 932 | return nom_fichier_copie_locale($source, $ext); |
@@ -937,9 +937,9 @@ discard block |
||
| 937 | 937 | |
| 938 | 938 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 939 | 939 | |
| 940 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 940 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 941 | 941 | $f = nom_fichier_copie_locale($source, $ext); |
| 942 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 942 | + if (file_exists(_DIR_RACINE.$f)) { |
|
| 943 | 943 | return $f; |
| 944 | 944 | } |
| 945 | 945 | } |
@@ -947,7 +947,7 @@ discard block |
||
| 947 | 947 | // Ping pour voir si son extension est connue et autorisee |
| 948 | 948 | // avec mise en cache du resultat du ping |
| 949 | 949 | |
| 950 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 950 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 951 | 951 | if (!@file_exists($cache) |
| 952 | 952 | or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
| 953 | 953 | or _request('var_mode') == 'recalcul' |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | ecrire_fichier($cache, serialize($path_parts)); |
| 957 | 957 | } |
| 958 | 958 | $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
| 959 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 959 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 960 | 960 | return nom_fichier_copie_locale($source, $ext); |
| 961 | 961 | } |
| 962 | 962 | spip_log("pas de copie locale pour $source"); |
@@ -1024,19 +1024,19 @@ discard block |
||
| 1024 | 1024 | if (!$t |
| 1025 | 1025 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1026 | 1026 | ) { |
| 1027 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1027 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1028 | 1028 | } |
| 1029 | 1029 | if (!$t |
| 1030 | 1030 | and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
| 1031 | 1031 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 1032 | 1032 | ) { |
| 1033 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1033 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 1038 | 1038 | if (!$t) { |
| 1039 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1039 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type)); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | |
| 1042 | 1042 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
@@ -1046,11 +1046,11 @@ discard block |
||
| 1046 | 1046 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1047 | 1047 | ) { |
| 1048 | 1048 | # eviter xxx.3 => 3gp (> SPIP 3) |
| 1049 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($rext[1], '', 'text')); |
|
| 1049 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote($rext[1], '', 'text')); |
|
| 1050 | 1050 | } |
| 1051 | 1051 | |
| 1052 | 1052 | if ($t) { |
| 1053 | - spip_log("mime-type $mime_type ok, extension " . $t['extension']); |
|
| 1053 | + spip_log("mime-type $mime_type ok, extension ".$t['extension']); |
|
| 1054 | 1054 | $a['extension'] = $t['extension']; |
| 1055 | 1055 | } else { |
| 1056 | 1056 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -1090,7 +1090,7 @@ discard block |
||
| 1090 | 1090 | $a = recuperer_infos_distantes($source, _INC_DISTANT_MAX_SIZE); |
| 1091 | 1091 | } else { |
| 1092 | 1092 | if ($a['body']) { |
| 1093 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $a['extension']); |
|
| 1093 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $a['extension']); |
|
| 1094 | 1094 | ecrire_fichier($a['fichier'], $a['body']); |
| 1095 | 1095 | $size_image = @getimagesize($a['fichier']); |
| 1096 | 1096 | $a['largeur'] = intval($size_image[0]); |
@@ -1188,7 +1188,7 @@ discard block |
||
| 1188 | 1188 | } |
| 1189 | 1189 | } else { |
| 1190 | 1190 | $scheme = $t['scheme']; |
| 1191 | - $noproxy = $scheme . '://'; |
|
| 1191 | + $noproxy = $scheme.'://'; |
|
| 1192 | 1192 | } |
| 1193 | 1193 | if (isset($t['user'])) { |
| 1194 | 1194 | $user = array($t['user'], $t['pass']); |
@@ -1202,7 +1202,7 @@ discard block |
||
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | if (!empty($t['query'])) { |
| 1205 | - $path .= '?' . $t['query']; |
|
| 1205 | + $path .= '?'.$t['query']; |
|
| 1206 | 1206 | } |
| 1207 | 1207 | |
| 1208 | 1208 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
@@ -1275,20 +1275,20 @@ discard block |
||
| 1275 | 1275 | $proxy_user = ''; |
| 1276 | 1276 | $http_proxy = need_proxy($host); |
| 1277 | 1277 | if ($user) { |
| 1278 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1278 | + $user = urlencode($user[0]).':'.urlencode($user[1]); |
|
| 1279 | 1279 | } |
| 1280 | 1280 | |
| 1281 | 1281 | $connect = ''; |
| 1282 | 1282 | if ($http_proxy) { |
| 1283 | - if (defined('_PROXY_HTTPS_VIA_CONNECT') and in_array($scheme , array('tls','ssl'))) { |
|
| 1284 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1285 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1283 | + if (defined('_PROXY_HTTPS_VIA_CONNECT') and in_array($scheme, array('tls', 'ssl'))) { |
|
| 1284 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 1285 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 1286 | 1286 | . "Host: $path_host\r\n" |
| 1287 | 1287 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 1288 | 1288 | } else { |
| 1289 | - $path = (in_array($scheme , array('tls','ssl')) ? 'https://' : "$scheme://") |
|
| 1289 | + $path = (in_array($scheme, array('tls', 'ssl')) ? 'https://' : "$scheme://") |
|
| 1290 | 1290 | . (!$user ? '' : "$user@") |
| 1291 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1291 | + . "$host".(($port != 80) ? ":$port" : '').$path; |
|
| 1292 | 1292 | } |
| 1293 | 1293 | $t2 = @parse_url($http_proxy); |
| 1294 | 1294 | $first_host = $t2['host']; |
@@ -1296,10 +1296,10 @@ discard block |
||
| 1296 | 1296 | $port = 80; |
| 1297 | 1297 | } |
| 1298 | 1298 | if ($t2['user']) { |
| 1299 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1299 | + $proxy_user = base64_encode($t2['user'].':'.$t2['pass']); |
|
| 1300 | 1300 | } |
| 1301 | 1301 | } else { |
| 1302 | - $first_host = $noproxy . $host; |
|
| 1302 | + $first_host = $noproxy.$host; |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | if ($connect) { |
@@ -1336,7 +1336,7 @@ discard block |
||
| 1336 | 1336 | or !count($res = explode(' ', $res)) |
| 1337 | 1337 | or $res[1] !== '200' |
| 1338 | 1338 | ) { |
| 1339 | - spip_log("Echec CONNECT sur $first_host:$port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1339 | + spip_log("Echec CONNECT sur $first_host:$port", 'connect'._LOG_INFO_IMPORTANTE); |
|
| 1340 | 1340 | fclose($f); |
| 1341 | 1341 | |
| 1342 | 1342 | return false; |
@@ -1364,11 +1364,11 @@ discard block |
||
| 1364 | 1364 | |
| 1365 | 1365 | $req = "$method $path $vers\r\n" |
| 1366 | 1366 | . "Host: $host\r\n" |
| 1367 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1368 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1367 | + . 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n" |
|
| 1368 | + . ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 1369 | 1369 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 1370 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1371 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1370 | + . (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n")) |
|
| 1371 | + . (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n")) |
|
| 1372 | 1372 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 1373 | 1373 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 1374 | 1374 | |