@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('_TEST_FILE_EXISTS')) { |
| 23 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 23 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 24 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 30 | 30 | |
| 31 | 31 | if (_SPIP_LOCK_MODE == 2) { |
| 32 | - include_spip('inc/nfslock'); |
|
| 32 | + include_spip('inc/nfslock'); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['liste_verrous'] = []; |
@@ -52,24 +52,24 @@ discard block |
||
| 52 | 52 | * Ressource sur le fichier ouvert, sinon false. |
| 53 | 53 | **/ |
| 54 | 54 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 55 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | - // verrou |
|
| 58 | - @flock($fl, $verrou); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - return $fl; |
|
| 62 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | - |
|
| 66 | - return $fl; |
|
| 67 | - } else { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return @fopen($fichier, $mode); |
|
| 55 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 56 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 57 | + // verrou |
|
| 58 | + @flock($fl, $verrou); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + return $fl; |
|
| 62 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 63 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 64 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 65 | + |
|
| 66 | + return $fl; |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return @fopen($fichier, $mode); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | * true si succès, false sinon. |
| 85 | 85 | **/ |
| 86 | 86 | function spip_fclose_unlock($handle) { |
| 87 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | - @flock($handle, LOCK_UN); |
|
| 89 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return @fclose($handle); |
|
| 87 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 88 | + @flock($handle, LOCK_UN); |
|
| 89 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 90 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 91 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return @fclose($handle); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | |
@@ -105,23 +105,23 @@ discard block |
||
| 105 | 105 | * Contenu du fichier |
| 106 | 106 | **/ |
| 107 | 107 | function spip_file_get_contents($fichier) { |
| 108 | - if (substr($fichier, -3) != '.gz') { |
|
| 109 | - if (function_exists('file_get_contents')) { |
|
| 110 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | - // sinon on fait un file() pour avoir le coeur net |
|
| 113 | - $contenu = @file_get_contents($fichier); |
|
| 114 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 115 | - $contenu = @file($fichier); |
|
| 116 | - } |
|
| 117 | - } else { |
|
| 118 | - $contenu = @file($fichier); |
|
| 119 | - } |
|
| 120 | - } else { |
|
| 121 | - $contenu = @gzfile($fichier); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 108 | + if (substr($fichier, -3) != '.gz') { |
|
| 109 | + if (function_exists('file_get_contents')) { |
|
| 110 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 111 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 112 | + // sinon on fait un file() pour avoir le coeur net |
|
| 113 | + $contenu = @file_get_contents($fichier); |
|
| 114 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 115 | + $contenu = @file($fichier); |
|
| 116 | + } |
|
| 117 | + } else { |
|
| 118 | + $contenu = @file($fichier); |
|
| 119 | + } |
|
| 120 | + } else { |
|
| 121 | + $contenu = @gzfile($fichier); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | |
@@ -146,48 +146,48 @@ discard block |
||
| 146 | 146 | * true si l'opération a réussie, false sinon. |
| 147 | 147 | **/ |
| 148 | 148 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 149 | - $contenu = ''; |
|
| 150 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - #spip_timer('lire_fichier'); |
|
| 157 | - |
|
| 158 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | - // lire le fichier avant tout |
|
| 161 | - $contenu = spip_file_get_contents($fichier); |
|
| 162 | - |
|
| 163 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | - // et eviter un acces disque |
|
| 167 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 168 | - spip_fclose_unlock($fl); |
|
| 169 | - |
|
| 170 | - return false; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // liberer le verrou |
|
| 174 | - spip_fclose_unlock($fl); |
|
| 175 | - |
|
| 176 | - // Verifications |
|
| 177 | - $ok = true; |
|
| 178 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 179 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | - if (!$ok) { |
|
| 184 | - spip_log("echec lecture $fichier"); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $ok; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - return false; |
|
| 149 | + $contenu = ''; |
|
| 150 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 151 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 152 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + #spip_timer('lire_fichier'); |
|
| 157 | + |
|
| 158 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 159 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 160 | + // lire le fichier avant tout |
|
| 161 | + $contenu = spip_file_get_contents($fichier); |
|
| 162 | + |
|
| 163 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 164 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 165 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 166 | + // et eviter un acces disque |
|
| 167 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 168 | + spip_fclose_unlock($fl); |
|
| 169 | + |
|
| 170 | + return false; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // liberer le verrou |
|
| 174 | + spip_fclose_unlock($fl); |
|
| 175 | + |
|
| 176 | + // Verifications |
|
| 177 | + $ok = true; |
|
| 178 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 179 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 183 | + if (!$ok) { |
|
| 184 | + spip_log("echec lecture $fichier"); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $ok; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + return false; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -215,92 +215,92 @@ discard block |
||
| 215 | 215 | **/ |
| 216 | 216 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 217 | 217 | |
| 218 | - #spip_timer('ecrire_fichier'); |
|
| 219 | - |
|
| 220 | - // verrouiller le fichier destination |
|
| 221 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | - // ecrire les donnees, compressees le cas echeant |
|
| 223 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | - if (substr($fichier, -3) == '.gz') { |
|
| 226 | - $contenu = gzencode($contenu); |
|
| 227 | - } |
|
| 228 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | - // pour etre sur d'avoir une operation atomique |
|
| 230 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | - // sauf sous wintruc ou ca ne marche pas |
|
| 232 | - $ok = false; |
|
| 233 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 234 | - if (!function_exists('creer_uniqid')) { |
|
| 235 | - include_spip('inc/acces'); |
|
| 236 | - } |
|
| 237 | - $id = creer_uniqid(); |
|
| 238 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 241 | - $ok = ($s == $a); |
|
| 242 | - spip_fclose_unlock($fp2); |
|
| 243 | - spip_fclose_unlock($fp); |
|
| 244 | - $fp = null; |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - $fp = null; |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - // sinon ou si methode precedente a echoueee |
|
| 266 | - // on se rabat sur la methode ancienne |
|
| 267 | - if (!$ok and !is_null($fp)) { |
|
| 268 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | - if ($truncate) { |
|
| 270 | - @ftruncate($fp, 0); |
|
| 271 | - } |
|
| 272 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | - |
|
| 274 | - $ok = ($s == $a); |
|
| 275 | - spip_fclose_unlock($fp); |
|
| 276 | - } |
|
| 277 | - // on tente une dernière fois file_put_contents |
|
| 278 | - if (!$ok) { |
|
| 279 | - $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | - $ok = ($l === strlen($contenu)); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // liberer le verrou et fermer le fichier |
|
| 284 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | - if ($ok) { |
|
| 286 | - if (strpos($fichier, '.php') !== false) { |
|
| 287 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return $ok; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - if (!$ignorer_echec) { |
|
| 295 | - include_spip('inc/autoriser'); |
|
| 296 | - if (autoriser('chargerftp')) { |
|
| 297 | - raler_fichier($fichier); |
|
| 298 | - } |
|
| 299 | - spip_unlink($fichier); |
|
| 300 | - } |
|
| 301 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 302 | - |
|
| 303 | - return false; |
|
| 218 | + #spip_timer('ecrire_fichier'); |
|
| 219 | + |
|
| 220 | + // verrouiller le fichier destination |
|
| 221 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 222 | + // ecrire les donnees, compressees le cas echeant |
|
| 223 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 224 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 225 | + if (substr($fichier, -3) == '.gz') { |
|
| 226 | + $contenu = gzencode($contenu); |
|
| 227 | + } |
|
| 228 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 229 | + // pour etre sur d'avoir une operation atomique |
|
| 230 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 231 | + // sauf sous wintruc ou ca ne marche pas |
|
| 232 | + $ok = false; |
|
| 233 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 234 | + if (!function_exists('creer_uniqid')) { |
|
| 235 | + include_spip('inc/acces'); |
|
| 236 | + } |
|
| 237 | + $id = creer_uniqid(); |
|
| 238 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 239 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 240 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 241 | + $ok = ($s == $a); |
|
| 242 | + spip_fclose_unlock($fp2); |
|
| 243 | + spip_fclose_unlock($fp); |
|
| 244 | + $fp = null; |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + $fp = null; |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + // sinon ou si methode precedente a echoueee |
|
| 266 | + // on se rabat sur la methode ancienne |
|
| 267 | + if (!$ok and !is_null($fp)) { |
|
| 268 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 269 | + if ($truncate) { |
|
| 270 | + @ftruncate($fp, 0); |
|
| 271 | + } |
|
| 272 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 273 | + |
|
| 274 | + $ok = ($s == $a); |
|
| 275 | + spip_fclose_unlock($fp); |
|
| 276 | + } |
|
| 277 | + // on tente une dernière fois file_put_contents |
|
| 278 | + if (!$ok) { |
|
| 279 | + $l = file_put_contents($fichier, $contenu, $truncate ? LOCK_EX : LOCK_EX | FILE_APPEND); |
|
| 280 | + $ok = ($l === strlen($contenu)); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // liberer le verrou et fermer le fichier |
|
| 284 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 285 | + if ($ok) { |
|
| 286 | + if (strpos($fichier, '.php') !== false) { |
|
| 287 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return $ok; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + if (!$ignorer_echec) { |
|
| 295 | + include_spip('inc/autoriser'); |
|
| 296 | + if (autoriser('chargerftp')) { |
|
| 297 | + raler_fichier($fichier); |
|
| 298 | + } |
|
| 299 | + spip_unlink($fichier); |
|
| 300 | + } |
|
| 301 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 302 | + |
|
| 303 | + return false; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -320,12 +320,12 @@ discard block |
||
| 320 | 320 | * Écriture avec troncation ? |
| 321 | 321 | */ |
| 322 | 322 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 323 | - if (substr($fichier, -4) !== '.php') { |
|
| 324 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | - } |
|
| 326 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 323 | + if (substr($fichier, -4) !== '.php') { |
|
| 324 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 325 | + } |
|
| 326 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 327 | 327 | |
| 328 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 328 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -336,25 +336,25 @@ discard block |
||
| 336 | 336 | * @return bool |
| 337 | 337 | */ |
| 338 | 338 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 339 | - $fichier_tmp = $fichier . '.last'; |
|
| 340 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | - return false; |
|
| 342 | - } |
|
| 343 | - if ( |
|
| 344 | - $force |
|
| 345 | - or !file_exists($fichier) |
|
| 346 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 347 | - ) { |
|
| 348 | - if ($use_copy) { |
|
| 349 | - @copy($fichier_tmp, $fichier); |
|
| 350 | - } |
|
| 351 | - else { |
|
| 352 | - @rename($fichier_tmp, $fichier); |
|
| 353 | - } |
|
| 354 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | - clearstatcache(true, $fichier); |
|
| 356 | - } |
|
| 357 | - return true; |
|
| 339 | + $fichier_tmp = $fichier . '.last'; |
|
| 340 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 341 | + return false; |
|
| 342 | + } |
|
| 343 | + if ( |
|
| 344 | + $force |
|
| 345 | + or !file_exists($fichier) |
|
| 346 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 347 | + ) { |
|
| 348 | + if ($use_copy) { |
|
| 349 | + @copy($fichier_tmp, $fichier); |
|
| 350 | + } |
|
| 351 | + else { |
|
| 352 | + @rename($fichier_tmp, $fichier); |
|
| 353 | + } |
|
| 354 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 355 | + clearstatcache(true, $fichier); |
|
| 356 | + } |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | |
@@ -375,11 +375,11 @@ discard block |
||
| 375 | 375 | * true si l'opération a réussie, false sinon. |
| 376 | 376 | */ |
| 377 | 377 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 378 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 380 | - } |
|
| 378 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 379 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 380 | + } |
|
| 381 | 381 | |
| 382 | - return $res; |
|
| 382 | + return $res; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -394,25 +394,25 @@ discard block |
||
| 394 | 394 | * Chemin du fichier |
| 395 | 395 | **/ |
| 396 | 396 | function raler_fichier($fichier) { |
| 397 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 398 | - spip_initialisation_suite(); |
|
| 399 | - } |
|
| 400 | - include_spip('inc/minipres'); |
|
| 401 | - $dir = dirname($fichier); |
|
| 402 | - http_response_code(401); |
|
| 403 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 404 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 405 | - . " <a href='" |
|
| 406 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 407 | - . "'>" |
|
| 408 | - . _T('texte_inc_meta_2') |
|
| 409 | - . '</a> ' |
|
| 410 | - . _T( |
|
| 411 | - 'texte_inc_meta_3', |
|
| 412 | - ['repertoire' => joli_repertoire($dir)] |
|
| 413 | - ) |
|
| 414 | - . "</h4>\n"); |
|
| 415 | - exit; |
|
| 397 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 398 | + spip_initialisation_suite(); |
|
| 399 | + } |
|
| 400 | + include_spip('inc/minipres'); |
|
| 401 | + $dir = dirname($fichier); |
|
| 402 | + http_response_code(401); |
|
| 403 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 404 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 405 | + . " <a href='" |
|
| 406 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 407 | + . "'>" |
|
| 408 | + . _T('texte_inc_meta_2') |
|
| 409 | + . '</a> ' |
|
| 410 | + . _T( |
|
| 411 | + 'texte_inc_meta_3', |
|
| 412 | + ['repertoire' => joli_repertoire($dir)] |
|
| 413 | + ) |
|
| 414 | + . "</h4>\n"); |
|
| 415 | + exit; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | |
@@ -427,14 +427,14 @@ discard block |
||
| 427 | 427 | * - true si récent, false sinon |
| 428 | 428 | */ |
| 429 | 429 | function jeune_fichier($fichier, $n) { |
| 430 | - if (!file_exists($fichier)) { |
|
| 431 | - return false; |
|
| 432 | - } |
|
| 433 | - if (!$c = @filemtime($fichier)) { |
|
| 434 | - return false; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - return (time() - $n <= $c); |
|
| 430 | + if (!file_exists($fichier)) { |
|
| 431 | + return false; |
|
| 432 | + } |
|
| 433 | + if (!$c = @filemtime($fichier)) { |
|
| 434 | + return false; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + return (time() - $n <= $c); |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
@@ -449,22 +449,22 @@ discard block |
||
| 449 | 449 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 450 | 450 | */ |
| 451 | 451 | function supprimer_fichier($fichier, $lock = true) { |
| 452 | - if (!@file_exists($fichier)) { |
|
| 453 | - return true; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - if ($lock) { |
|
| 457 | - // verrouiller le fichier destination |
|
| 458 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 459 | - return false; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - // liberer le verrou |
|
| 463 | - spip_fclose_unlock($fp); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - // supprimer |
|
| 467 | - return @unlink($fichier); |
|
| 452 | + if (!@file_exists($fichier)) { |
|
| 453 | + return true; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + if ($lock) { |
|
| 457 | + // verrouiller le fichier destination |
|
| 458 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 459 | + return false; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + // liberer le verrou |
|
| 463 | + spip_fclose_unlock($fp); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + // supprimer |
|
| 467 | + return @unlink($fichier); |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -474,12 +474,12 @@ discard block |
||
| 474 | 474 | * Chemin du fichier |
| 475 | 475 | */ |
| 476 | 476 | function spip_unlink($f) { |
| 477 | - if (!is_dir($f)) { |
|
| 478 | - supprimer_fichier($f, false); |
|
| 479 | - } else { |
|
| 480 | - @unlink("$f/.ok"); |
|
| 481 | - @rmdir($f); |
|
| 482 | - } |
|
| 477 | + if (!is_dir($f)) { |
|
| 478 | + supprimer_fichier($f, false); |
|
| 479 | + } else { |
|
| 480 | + @unlink("$f/.ok"); |
|
| 481 | + @rmdir($f); |
|
| 482 | + } |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -493,26 +493,26 @@ discard block |
||
| 493 | 493 | * The absolute path of the PHP file to invalidate. |
| 494 | 494 | */ |
| 495 | 495 | function spip_clear_opcode_cache($filepath) { |
| 496 | - clearstatcache(true, $filepath); |
|
| 497 | - |
|
| 498 | - // Zend OPcache |
|
| 499 | - if (function_exists('opcache_invalidate')) { |
|
| 500 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 501 | - // si l'invalidation a echoue lever un flag |
|
| 502 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 503 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 504 | - } |
|
| 505 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 506 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 507 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 508 | - } |
|
| 509 | - // APC. |
|
| 510 | - if (function_exists('apc_delete_file')) { |
|
| 511 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 512 | - // not compiled yet. |
|
| 513 | - // @see http://php.net/apc-delete-file |
|
| 514 | - @apc_delete_file($filepath); |
|
| 515 | - } |
|
| 496 | + clearstatcache(true, $filepath); |
|
| 497 | + |
|
| 498 | + // Zend OPcache |
|
| 499 | + if (function_exists('opcache_invalidate')) { |
|
| 500 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 501 | + // si l'invalidation a echoue lever un flag |
|
| 502 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 503 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 504 | + } |
|
| 505 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 506 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 507 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 508 | + } |
|
| 509 | + // APC. |
|
| 510 | + if (function_exists('apc_delete_file')) { |
|
| 511 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 512 | + // not compiled yet. |
|
| 513 | + // @see http://php.net/apc-delete-file |
|
| 514 | + @apc_delete_file($filepath); |
|
| 515 | + } |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -535,25 +535,25 @@ discard block |
||
| 535 | 535 | * |
| 536 | 536 | */ |
| 537 | 537 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 538 | - if ( |
|
| 539 | - function_exists('opcache_get_configuration') |
|
| 540 | - and @ini_get('opcache.enable') |
|
| 541 | - and @ini_get('opcache.validate_timestamps') |
|
| 542 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 543 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 544 | - ) { |
|
| 545 | - $wait = $duree + 1; |
|
| 546 | - if ($timestamp) { |
|
| 547 | - $wait -= (time() - $timestamp); |
|
| 548 | - if ($wait < 0) { |
|
| 549 | - $wait = 0; |
|
| 550 | - } |
|
| 551 | - } |
|
| 552 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 553 | - if ($wait) { |
|
| 554 | - sleep($duree + 1); |
|
| 555 | - } |
|
| 556 | - } |
|
| 538 | + if ( |
|
| 539 | + function_exists('opcache_get_configuration') |
|
| 540 | + and @ini_get('opcache.enable') |
|
| 541 | + and @ini_get('opcache.validate_timestamps') |
|
| 542 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 543 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 544 | + ) { |
|
| 545 | + $wait = $duree + 1; |
|
| 546 | + if ($timestamp) { |
|
| 547 | + $wait -= (time() - $timestamp); |
|
| 548 | + if ($wait < 0) { |
|
| 549 | + $wait = 0; |
|
| 550 | + } |
|
| 551 | + } |
|
| 552 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 553 | + if ($wait) { |
|
| 554 | + sleep($duree + 1); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | 557 | } |
| 558 | 558 | |
| 559 | 559 | |
@@ -566,26 +566,26 @@ discard block |
||
| 566 | 566 | * @return bool Suppression reussie. |
| 567 | 567 | */ |
| 568 | 568 | function supprimer_repertoire($dir) { |
| 569 | - if (!file_exists($dir)) { |
|
| 570 | - return true; |
|
| 571 | - } |
|
| 572 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 573 | - return @unlink($dir); |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - foreach (scandir($dir) as $item) { |
|
| 577 | - if ($item == '.' || $item == '..') { |
|
| 578 | - continue; |
|
| 579 | - } |
|
| 580 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 581 | - @chmod($dir . '/' . $item, 0777); |
|
| 582 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 583 | - return false; |
|
| 584 | - } |
|
| 585 | - }; |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - return @rmdir($dir); |
|
| 569 | + if (!file_exists($dir)) { |
|
| 570 | + return true; |
|
| 571 | + } |
|
| 572 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 573 | + return @unlink($dir); |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + foreach (scandir($dir) as $item) { |
|
| 577 | + if ($item == '.' || $item == '..') { |
|
| 578 | + continue; |
|
| 579 | + } |
|
| 580 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 581 | + @chmod($dir . '/' . $item, 0777); |
|
| 582 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 583 | + return false; |
|
| 584 | + } |
|
| 585 | + }; |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + return @rmdir($dir); |
|
| 589 | 589 | } |
| 590 | 590 | |
| 591 | 591 | |
@@ -614,57 +614,57 @@ discard block |
||
| 614 | 614 | * Chemin du répertoire créé. |
| 615 | 615 | **/ |
| 616 | 616 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 617 | - static $dirs = []; |
|
| 618 | - |
|
| 619 | - $base = str_replace('//', '/', $base); |
|
| 620 | - |
|
| 621 | - # suppr le dernier caractere si c'est un / |
|
| 622 | - $base = rtrim($base, '/'); |
|
| 623 | - |
|
| 624 | - if (!strlen($subdir)) { |
|
| 625 | - $n = strrpos($base, '/'); |
|
| 626 | - if ($n === false) { |
|
| 627 | - return $nobase ? '' : ($base . '/'); |
|
| 628 | - } |
|
| 629 | - $subdir = substr($base, $n + 1); |
|
| 630 | - $base = substr($base, 0, $n + 1); |
|
| 631 | - } else { |
|
| 632 | - $base .= '/'; |
|
| 633 | - $subdir = str_replace('/', '', $subdir); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - $baseaff = $nobase ? '' : $base; |
|
| 637 | - if (isset($dirs[$base . $subdir])) { |
|
| 638 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 642 | - |
|
| 643 | - if (file_exists("$path/.ok")) { |
|
| 644 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 645 | - } |
|
| 646 | - |
|
| 647 | - @mkdir($path, _SPIP_CHMOD); |
|
| 648 | - @chmod($path, _SPIP_CHMOD); |
|
| 649 | - |
|
| 650 | - if (is_dir($path) && is_writable($path)) { |
|
| 651 | - @touch("$path/.ok"); |
|
| 652 | - spip_log("creation $base$subdir/"); |
|
| 653 | - |
|
| 654 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 658 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 659 | - spip_log("echec creation $base{$subdir}"); |
|
| 660 | - if ($tantpis) { |
|
| 661 | - return ''; |
|
| 662 | - } |
|
| 663 | - if (!_DIR_RESTREINT) { |
|
| 664 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 665 | - } |
|
| 666 | - $base .= $subdir; |
|
| 667 | - raler_fichier($base . '/.ok'); |
|
| 617 | + static $dirs = []; |
|
| 618 | + |
|
| 619 | + $base = str_replace('//', '/', $base); |
|
| 620 | + |
|
| 621 | + # suppr le dernier caractere si c'est un / |
|
| 622 | + $base = rtrim($base, '/'); |
|
| 623 | + |
|
| 624 | + if (!strlen($subdir)) { |
|
| 625 | + $n = strrpos($base, '/'); |
|
| 626 | + if ($n === false) { |
|
| 627 | + return $nobase ? '' : ($base . '/'); |
|
| 628 | + } |
|
| 629 | + $subdir = substr($base, $n + 1); |
|
| 630 | + $base = substr($base, 0, $n + 1); |
|
| 631 | + } else { |
|
| 632 | + $base .= '/'; |
|
| 633 | + $subdir = str_replace('/', '', $subdir); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + $baseaff = $nobase ? '' : $base; |
|
| 637 | + if (isset($dirs[$base . $subdir])) { |
|
| 638 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 642 | + |
|
| 643 | + if (file_exists("$path/.ok")) { |
|
| 644 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 645 | + } |
|
| 646 | + |
|
| 647 | + @mkdir($path, _SPIP_CHMOD); |
|
| 648 | + @chmod($path, _SPIP_CHMOD); |
|
| 649 | + |
|
| 650 | + if (is_dir($path) && is_writable($path)) { |
|
| 651 | + @touch("$path/.ok"); |
|
| 652 | + spip_log("creation $base$subdir/"); |
|
| 653 | + |
|
| 654 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 658 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 659 | + spip_log("echec creation $base{$subdir}"); |
|
| 660 | + if ($tantpis) { |
|
| 661 | + return ''; |
|
| 662 | + } |
|
| 663 | + if (!_DIR_RESTREINT) { |
|
| 664 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 665 | + } |
|
| 666 | + $base .= $subdir; |
|
| 667 | + raler_fichier($base . '/.ok'); |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | |
@@ -697,56 +697,56 @@ discard block |
||
| 697 | 697 | * Chemins des fichiers trouvés. |
| 698 | 698 | **/ |
| 699 | 699 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 700 | - $nbfiles = 0; |
|
| 701 | - if ($pattern == -1) { |
|
| 702 | - $pattern = ''; |
|
| 703 | - } |
|
| 704 | - $fichiers = []; |
|
| 705 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 706 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 707 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 708 | - if ($dir == '') { |
|
| 709 | - $dir = '.'; |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 713 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 714 | - if ( |
|
| 715 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 716 | - and $f != 'CVS' |
|
| 717 | - and $f != 'remove.txt' |
|
| 718 | - and is_readable($f = "$dir/$f") |
|
| 719 | - ) { |
|
| 720 | - if (is_file($f)) { |
|
| 721 | - if (!$pattern or preg_match(";$pattern;iS", $f)) { |
|
| 722 | - $fichiers[] = $f; |
|
| 723 | - $nbfiles++; |
|
| 724 | - } |
|
| 725 | - } else { |
|
| 726 | - if (is_dir($f) and is_array($recurs)) { |
|
| 727 | - $rp = @realpath($f); |
|
| 728 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 729 | - $rp = $f; |
|
| 730 | - } # realpath n'est peut etre pas autorise |
|
| 731 | - if (!isset($recurs[$rp])) { |
|
| 732 | - $recurs[$rp] = true; |
|
| 733 | - $beginning = $fichiers; |
|
| 734 | - $end = preg_files( |
|
| 735 | - "$f/", |
|
| 736 | - $pattern, |
|
| 737 | - $maxfiles - $nbfiles, |
|
| 738 | - $recurs |
|
| 739 | - ); |
|
| 740 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 741 | - $nbfiles = count($fichiers); |
|
| 742 | - } |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - } |
|
| 747 | - closedir($d); |
|
| 748 | - } |
|
| 749 | - sort($fichiers); |
|
| 750 | - |
|
| 751 | - return $fichiers; |
|
| 700 | + $nbfiles = 0; |
|
| 701 | + if ($pattern == -1) { |
|
| 702 | + $pattern = ''; |
|
| 703 | + } |
|
| 704 | + $fichiers = []; |
|
| 705 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 706 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 707 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 708 | + if ($dir == '') { |
|
| 709 | + $dir = '.'; |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 713 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 714 | + if ( |
|
| 715 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 716 | + and $f != 'CVS' |
|
| 717 | + and $f != 'remove.txt' |
|
| 718 | + and is_readable($f = "$dir/$f") |
|
| 719 | + ) { |
|
| 720 | + if (is_file($f)) { |
|
| 721 | + if (!$pattern or preg_match(";$pattern;iS", $f)) { |
|
| 722 | + $fichiers[] = $f; |
|
| 723 | + $nbfiles++; |
|
| 724 | + } |
|
| 725 | + } else { |
|
| 726 | + if (is_dir($f) and is_array($recurs)) { |
|
| 727 | + $rp = @realpath($f); |
|
| 728 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 729 | + $rp = $f; |
|
| 730 | + } # realpath n'est peut etre pas autorise |
|
| 731 | + if (!isset($recurs[$rp])) { |
|
| 732 | + $recurs[$rp] = true; |
|
| 733 | + $beginning = $fichiers; |
|
| 734 | + $end = preg_files( |
|
| 735 | + "$f/", |
|
| 736 | + $pattern, |
|
| 737 | + $maxfiles - $nbfiles, |
|
| 738 | + $recurs |
|
| 739 | + ); |
|
| 740 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 741 | + $nbfiles = count($fichiers); |
|
| 742 | + } |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + } |
|
| 747 | + closedir($d); |
|
| 748 | + } |
|
| 749 | + sort($fichiers); |
|
| 750 | + |
|
| 751 | + return $fichiers; |
|
| 752 | 752 | } |