@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -30,11 +30,11 @@ discard block |
||
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | 32 | function set_spip_doc($fichier) { |
| 33 | - if (strpos($fichier, _DIR_IMG) === 0) { |
|
| 34 | - return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | - } else { |
|
| 36 | - return $fichier; |
|
| 37 | - } // ex: fichier distant |
|
| 33 | + if (strpos($fichier, _DIR_IMG) === 0) { |
|
| 34 | + return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | + } else { |
|
| 36 | + return $fichier; |
|
| 37 | + } // ex: fichier distant |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | * @return bool|string |
| 47 | 47 | */ |
| 48 | 48 | function get_spip_doc($fichier) { |
| 49 | - // fichier distant |
|
| 50 | - if (tester_url_absolue($fichier)) { |
|
| 51 | - return $fichier; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // gestion d'erreurs, fichier='' |
|
| 55 | - if (!strlen($fichier)) { |
|
| 56 | - return false; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $fichier = ( |
|
| 60 | - strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0 |
|
| 61 | - ) |
|
| 62 | - ? _DIR_IMG . $fichier |
|
| 63 | - : $fichier; |
|
| 64 | - |
|
| 65 | - // fichier normal |
|
| 66 | - return $fichier; |
|
| 49 | + // fichier distant |
|
| 50 | + if (tester_url_absolue($fichier)) { |
|
| 51 | + return $fichier; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // gestion d'erreurs, fichier='' |
|
| 55 | + if (!strlen($fichier)) { |
|
| 56 | + return false; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $fichier = ( |
|
| 60 | + strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0 |
|
| 61 | + ) |
|
| 62 | + ? _DIR_IMG . $fichier |
|
| 63 | + : $fichier; |
|
| 64 | + |
|
| 65 | + // fichier normal |
|
| 66 | + return $fichier; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -77,26 +77,26 @@ discard block |
||
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | 79 | function creer_repertoire_documents($ext) { |
| 80 | - $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 81 | - |
|
| 82 | - if (!$ext or !$rep) { |
|
| 83 | - spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 84 | - exit; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 88 | - // par exemple acces_restreint |
|
| 89 | - // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 90 | - if ( |
|
| 91 | - isset($GLOBALS['meta']['creer_htaccess']) |
|
| 92 | - and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 93 | - and $ext !== 'logo' |
|
| 94 | - ) { |
|
| 95 | - include_spip('inc/acces'); |
|
| 96 | - verifier_htaccess($rep); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return $rep; |
|
| 80 | + $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 81 | + |
|
| 82 | + if (!$ext or !$rep) { |
|
| 83 | + spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 84 | + exit; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 88 | + // par exemple acces_restreint |
|
| 89 | + // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 90 | + if ( |
|
| 91 | + isset($GLOBALS['meta']['creer_htaccess']) |
|
| 92 | + and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 93 | + and $ext !== 'logo' |
|
| 94 | + ) { |
|
| 95 | + include_spip('inc/acces'); |
|
| 96 | + verifier_htaccess($rep); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return $rep; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,22 +105,22 @@ discard block |
||
| 105 | 105 | * @param string $nom |
| 106 | 106 | */ |
| 107 | 107 | function effacer_repertoire_temporaire($nom) { |
| 108 | - if ($d = opendir($nom)) { |
|
| 109 | - while (($f = readdir($d)) !== false) { |
|
| 110 | - if (is_file("$nom/$f")) { |
|
| 111 | - spip_unlink("$nom/$f"); |
|
| 112 | - } else { |
|
| 113 | - if ( |
|
| 114 | - $f <> '.' and $f <> '..' |
|
| 115 | - and is_dir("$nom/$f") |
|
| 116 | - ) { |
|
| 117 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - closedir($d); |
|
| 123 | - @rmdir($nom); |
|
| 108 | + if ($d = opendir($nom)) { |
|
| 109 | + while (($f = readdir($d)) !== false) { |
|
| 110 | + if (is_file("$nom/$f")) { |
|
| 111 | + spip_unlink("$nom/$f"); |
|
| 112 | + } else { |
|
| 113 | + if ( |
|
| 114 | + $f <> '.' and $f <> '..' |
|
| 115 | + and is_dir("$nom/$f") |
|
| 116 | + ) { |
|
| 117 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + closedir($d); |
|
| 123 | + @rmdir($nom); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // |
@@ -137,43 +137,43 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | function copier_document($ext, $orig, $source, $subdir = null) { |
| 139 | 139 | |
| 140 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 141 | - $dir = creer_repertoire_documents($subdir ? $subdir : $ext); |
|
| 142 | - |
|
| 143 | - $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 144 | - $dest = preg_replace('/\.([^.]+)$/','', $dest); |
|
| 145 | - $dest = translitteration($dest); |
|
| 146 | - $dest = preg_replace('/[^.=\w-]+/','_', $dest); |
|
| 147 | - |
|
| 148 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 149 | - // pour les images transformees par rotation (action/documenter) |
|
| 150 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 151 | - |
|
| 152 | - while (preg_match(",\.(\w+)$,", $dest, $m)) { |
|
| 153 | - if (!function_exists('verifier_upload_autorise') |
|
| 154 | - or !$r = verifier_upload_autorise($dest) |
|
| 155 | - or $r['autozip']) { |
|
| 156 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 157 | - break; |
|
| 158 | - } |
|
| 159 | - else { |
|
| 160 | - $dest = substr($dest, 0, -strlen($m[0])); |
|
| 161 | - $ext = $m[1] . "." . $ext; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 166 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 167 | - return $source; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 171 | - $n = 0; |
|
| 172 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 173 | - ; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return deplacer_fichier_upload($source, $newFile); |
|
| 140 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 141 | + $dir = creer_repertoire_documents($subdir ? $subdir : $ext); |
|
| 142 | + |
|
| 143 | + $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 144 | + $dest = preg_replace('/\.([^.]+)$/','', $dest); |
|
| 145 | + $dest = translitteration($dest); |
|
| 146 | + $dest = preg_replace('/[^.=\w-]+/','_', $dest); |
|
| 147 | + |
|
| 148 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 149 | + // pour les images transformees par rotation (action/documenter) |
|
| 150 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 151 | + |
|
| 152 | + while (preg_match(",\.(\w+)$,", $dest, $m)) { |
|
| 153 | + if (!function_exists('verifier_upload_autorise') |
|
| 154 | + or !$r = verifier_upload_autorise($dest) |
|
| 155 | + or $r['autozip']) { |
|
| 156 | + $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 157 | + break; |
|
| 158 | + } |
|
| 159 | + else { |
|
| 160 | + $dest = substr($dest, 0, -strlen($m[0])); |
|
| 161 | + $ext = $m[1] . "." . $ext; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 166 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 167 | + return $source; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 171 | + $n = 0; |
|
| 172 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 173 | + ; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return deplacer_fichier_upload($source, $newFile); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -188,28 +188,28 @@ discard block |
||
| 188 | 188 | * @return bool|string |
| 189 | 189 | */ |
| 190 | 190 | function determine_upload($type = '') { |
| 191 | - if (!function_exists('autoriser')) { |
|
| 192 | - include_spip('inc/autoriser'); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ( |
|
| 196 | - !autoriser('chargerftp') |
|
| 197 | - or $type == 'logos' |
|
| 198 | - ) { # on ne le permet pas pour les logos |
|
| 199 | - return false; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $repertoire = _DIR_TRANSFERT; |
|
| 203 | - if (!@is_dir($repertoire)) { |
|
| 204 | - $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 205 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 209 | - return $repertoire; |
|
| 210 | - } else { |
|
| 211 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 212 | - } |
|
| 191 | + if (!function_exists('autoriser')) { |
|
| 192 | + include_spip('inc/autoriser'); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ( |
|
| 196 | + !autoriser('chargerftp') |
|
| 197 | + or $type == 'logos' |
|
| 198 | + ) { # on ne le permet pas pour les logos |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $repertoire = _DIR_TRANSFERT; |
|
| 203 | + if (!@is_dir($repertoire)) { |
|
| 204 | + $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 205 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 209 | + return $repertoire; |
|
| 210 | + } else { |
|
| 211 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -228,35 +228,35 @@ discard block |
||
| 228 | 228 | * @return bool|mixed|string |
| 229 | 229 | */ |
| 230 | 230 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 231 | - // Securite |
|
| 232 | - if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 233 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 234 | - } else { |
|
| 235 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - if ($move) { |
|
| 239 | - $ok = @rename($source, $dest); |
|
| 240 | - } else { |
|
| 241 | - $ok = @copy($source, $dest); |
|
| 242 | - } |
|
| 243 | - if (!$ok) { |
|
| 244 | - $ok = @move_uploaded_file($source, $dest); |
|
| 245 | - } |
|
| 246 | - if ($ok) { |
|
| 247 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 248 | - } else { |
|
| 249 | - $f = @fopen($dest, 'w'); |
|
| 250 | - if ($f) { |
|
| 251 | - fclose($f); |
|
| 252 | - } else { |
|
| 253 | - include_spip('inc/flock'); |
|
| 254 | - raler_fichier($dest); |
|
| 255 | - } |
|
| 256 | - spip_unlink($dest); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - return $ok ? $dest : false; |
|
| 231 | + // Securite |
|
| 232 | + if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 233 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 234 | + } else { |
|
| 235 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + if ($move) { |
|
| 239 | + $ok = @rename($source, $dest); |
|
| 240 | + } else { |
|
| 241 | + $ok = @copy($source, $dest); |
|
| 242 | + } |
|
| 243 | + if (!$ok) { |
|
| 244 | + $ok = @move_uploaded_file($source, $dest); |
|
| 245 | + } |
|
| 246 | + if ($ok) { |
|
| 247 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 248 | + } else { |
|
| 249 | + $f = @fopen($dest, 'w'); |
|
| 250 | + if ($f) { |
|
| 251 | + fclose($f); |
|
| 252 | + } else { |
|
| 253 | + include_spip('inc/flock'); |
|
| 254 | + raler_fichier($dest); |
|
| 255 | + } |
|
| 256 | + spip_unlink($dest); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + return $ok ? $dest : false; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
@@ -280,58 +280,58 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | function check_upload_error($error, $msg = '', $return = false) { |
| 282 | 282 | |
| 283 | - if (!$error) { |
|
| 284 | - return false; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 288 | - |
|
| 289 | - switch ($error) { |
|
| 290 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 291 | - return true; |
|
| 292 | - |
|
| 293 | - # on peut affiner les differents messages d'erreur |
|
| 294 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 295 | - $msg = _T( |
|
| 296 | - 'upload_limit', |
|
| 297 | - ['max' => ini_get('upload_max_filesize')] |
|
| 298 | - ); |
|
| 299 | - break; |
|
| 300 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 301 | - $msg = _T( |
|
| 302 | - 'upload_limit', |
|
| 303 | - ['max' => ini_get('upload_max_filesize')] |
|
| 304 | - ); |
|
| 305 | - break; |
|
| 306 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 307 | - $msg = _T( |
|
| 308 | - 'upload_limit', |
|
| 309 | - ['max' => ini_get('upload_max_filesize')] |
|
| 310 | - ); |
|
| 311 | - break; |
|
| 312 | - |
|
| 313 | - default: /* autre */ |
|
| 314 | - if (!$msg) { |
|
| 315 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 316 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 317 | - } |
|
| 318 | - break; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - spip_log("erreur upload $error"); |
|
| 322 | - if ($return) { |
|
| 323 | - return $msg; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - if (_request('iframe') == 'iframe') { |
|
| 327 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 328 | - exit; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - include_spip('inc/minipres'); |
|
| 332 | - echo minipres( |
|
| 333 | - $msg, |
|
| 334 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 335 | - ); |
|
| 336 | - exit; |
|
| 283 | + if (!$error) { |
|
| 284 | + return false; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 288 | + |
|
| 289 | + switch ($error) { |
|
| 290 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 291 | + return true; |
|
| 292 | + |
|
| 293 | + # on peut affiner les differents messages d'erreur |
|
| 294 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 295 | + $msg = _T( |
|
| 296 | + 'upload_limit', |
|
| 297 | + ['max' => ini_get('upload_max_filesize')] |
|
| 298 | + ); |
|
| 299 | + break; |
|
| 300 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 301 | + $msg = _T( |
|
| 302 | + 'upload_limit', |
|
| 303 | + ['max' => ini_get('upload_max_filesize')] |
|
| 304 | + ); |
|
| 305 | + break; |
|
| 306 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 307 | + $msg = _T( |
|
| 308 | + 'upload_limit', |
|
| 309 | + ['max' => ini_get('upload_max_filesize')] |
|
| 310 | + ); |
|
| 311 | + break; |
|
| 312 | + |
|
| 313 | + default: /* autre */ |
|
| 314 | + if (!$msg) { |
|
| 315 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 316 | + . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 317 | + } |
|
| 318 | + break; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + spip_log("erreur upload $error"); |
|
| 322 | + if ($return) { |
|
| 323 | + return $msg; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + if (_request('iframe') == 'iframe') { |
|
| 327 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 328 | + exit; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + include_spip('inc/minipres'); |
|
| 332 | + echo minipres( |
|
| 333 | + $msg, |
|
| 334 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 335 | + ); |
|
| 336 | + exit; |
|
| 337 | 337 | } |