@@ -17,21 +17,21 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/serial'); |
| 24 | 24 | |
| 25 | 25 | /** Estime la taille moyenne d'un fichier cache, pour ne pas les regarder (10ko) */ |
| 26 | 26 | if (!defined('_TAILLE_MOYENNE_FICHIER_CACHE')) { |
| 27 | - define('_TAILLE_MOYENNE_FICHIER_CACHE', 1024 * 10); |
|
| 27 | + define('_TAILLE_MOYENNE_FICHIER_CACHE', 1024 * 10); |
|
| 28 | 28 | } |
| 29 | 29 | /** |
| 30 | 30 | * Si un fichier n'a pas été servi (fileatime) depuis plus d'une heure, on se sent |
| 31 | 31 | * en droit de l'éliminer |
| 32 | 32 | */ |
| 33 | 33 | if (!defined('_AGE_CACHE_ATIME')) { |
| 34 | - define('_AGE_CACHE_ATIME', 3600); |
|
| 34 | + define('_AGE_CACHE_ATIME', 3600); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -48,24 +48,24 @@ discard block |
||
| 48 | 48 | * - array(nombre de fichiers, approximation de la taille en octet) sinon |
| 49 | 49 | **/ |
| 50 | 50 | function nombre_de_fichiers_repertoire($dir, $nb_estim_taille = 20) { |
| 51 | - $taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire |
|
| 52 | - $nb = $nb_estim_taille; |
|
| 53 | - if (!$h = opendir($dir)) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - $total = 0; |
|
| 57 | - while (($fichier = @readdir($h)) !== false) { |
|
| 58 | - if ($fichier[0] != '.' and !is_dir("$dir/$fichier")) { |
|
| 59 | - $total++; |
|
| 60 | - if ($nb and rand(1, 10) == 1) { |
|
| 61 | - $taille += filesize("$dir/$fichier"); |
|
| 62 | - $nb--; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - closedir($h); |
|
| 67 | - |
|
| 68 | - return array($total, $taille ? $taille / ($nb_estim_taille - $nb) : _TAILLE_MOYENNE_FICHIER_CACHE); |
|
| 51 | + $taille = 0; // mesurer la taille de N fichiers au hasard dans le repertoire |
|
| 52 | + $nb = $nb_estim_taille; |
|
| 53 | + if (!$h = opendir($dir)) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + $total = 0; |
|
| 57 | + while (($fichier = @readdir($h)) !== false) { |
|
| 58 | + if ($fichier[0] != '.' and !is_dir("$dir/$fichier")) { |
|
| 59 | + $total++; |
|
| 60 | + if ($nb and rand(1, 10) == 1) { |
|
| 61 | + $taille += filesize("$dir/$fichier"); |
|
| 62 | + $nb--; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + closedir($h); |
|
| 67 | + |
|
| 68 | + return array($total, $taille ? $taille / ($nb_estim_taille - $nb) : _TAILLE_MOYENNE_FICHIER_CACHE); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -78,31 +78,31 @@ discard block |
||
| 78 | 78 | * @return int Taille approximative en octets |
| 79 | 79 | **/ |
| 80 | 80 | function taille_du_cache() { |
| 81 | - # check dirs until we reach > 500 files |
|
| 82 | - $t = 0; |
|
| 83 | - $n = 0; |
|
| 84 | - $time = isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0; |
|
| 85 | - for ($i=0; $i < 256; $i++) { |
|
| 86 | - $dir = _DIR_CACHE.sprintf('%02s', dechex($i)); |
|
| 87 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 88 | - while (($f = readdir($d)) !== false) { |
|
| 89 | - if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 90 | - $n++; |
|
| 91 | - if ($a['mtime'] >= $time) { |
|
| 92 | - if ($a['blocks'] > 0) { |
|
| 93 | - $t += 512*$a['blocks']; |
|
| 94 | - } else { |
|
| 95 | - $t += $a['size']; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - if ($n > 500) { |
|
| 102 | - return intval(256*$t/(1+$i)); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - return $t; |
|
| 81 | + # check dirs until we reach > 500 files |
|
| 82 | + $t = 0; |
|
| 83 | + $n = 0; |
|
| 84 | + $time = isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0; |
|
| 85 | + for ($i=0; $i < 256; $i++) { |
|
| 86 | + $dir = _DIR_CACHE.sprintf('%02s', dechex($i)); |
|
| 87 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 88 | + while (($f = readdir($d)) !== false) { |
|
| 89 | + if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) { |
|
| 90 | + $n++; |
|
| 91 | + if ($a['mtime'] >= $time) { |
|
| 92 | + if ($a['blocks'] > 0) { |
|
| 93 | + $t += 512*$a['blocks']; |
|
| 94 | + } else { |
|
| 95 | + $t += $a['size']; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + if ($n > 500) { |
|
| 102 | + return intval(256*$t/(1+$i)); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + return $t; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
@@ -129,30 +129,30 @@ discard block |
||
| 129 | 129 | * Inutilisé |
| 130 | 130 | **/ |
| 131 | 131 | function inc_suivre_invalideur_dist($cond, $modif = true) { |
| 132 | - if (!$modif) { |
|
| 133 | - return; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - // determiner l'objet modifie : forum, article, etc |
|
| 137 | - if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 138 | - $objet = objet_type($r[1]); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 142 | - if (isset($objet)) { |
|
| 143 | - ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 147 | - // n'affecter la meta que si un de ces objets est modifie |
|
| 148 | - if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 149 | - if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 150 | - ecrire_meta('derniere_modif', time()); |
|
| 151 | - } |
|
| 152 | - } // sinon, cas standard, toujours affecter la meta |
|
| 153 | - else { |
|
| 154 | - ecrire_meta('derniere_modif', time()); |
|
| 155 | - } |
|
| 132 | + if (!$modif) { |
|
| 133 | + return; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + // determiner l'objet modifie : forum, article, etc |
|
| 137 | + if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) { |
|
| 138 | + $objet = objet_type($r[1]); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + // stocker la date_modif_$objet (ne sert a rien pour le moment) |
|
| 142 | + if (isset($objet)) { |
|
| 143 | + ecrire_meta('derniere_modif_' . $objet, time()); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + // si $derniere_modif_invalide est un array('article', 'rubrique') |
|
| 147 | + // n'affecter la meta que si un de ces objets est modifie |
|
| 148 | + if (is_array($GLOBALS['derniere_modif_invalide'])) { |
|
| 149 | + if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) { |
|
| 150 | + ecrire_meta('derniere_modif', time()); |
|
| 151 | + } |
|
| 152 | + } // sinon, cas standard, toujours affecter la meta |
|
| 153 | + else { |
|
| 154 | + ecrire_meta('derniere_modif', time()); |
|
| 155 | + } |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | |
@@ -177,49 +177,49 @@ discard block |
||
| 177 | 177 | * Nombre de fichiers supprimés |
| 178 | 178 | **/ |
| 179 | 179 | function purger_repertoire($dir, $options = array()) { |
| 180 | - if (!is_dir($dir) or !is_readable($dir)) { |
|
| 181 | - return; |
|
| 182 | - } |
|
| 183 | - $handle = opendir($dir); |
|
| 184 | - if (!$handle) { |
|
| 185 | - return; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $total = 0; |
|
| 189 | - |
|
| 190 | - while (($fichier = @readdir($handle)) !== false) { |
|
| 191 | - // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 192 | - if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 193 | - continue; |
|
| 194 | - } |
|
| 195 | - $chemin = "$dir/$fichier"; |
|
| 196 | - if (is_file($chemin)) { |
|
| 197 | - if ((!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 198 | - and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 199 | - ) { |
|
| 200 | - supprimer_fichier($chemin); |
|
| 201 | - $total++; |
|
| 202 | - } |
|
| 203 | - } else { |
|
| 204 | - if (is_dir($chemin)) { |
|
| 205 | - $opts = $options; |
|
| 206 | - if (isset($options['limit'])) { |
|
| 207 | - $opts['limit'] = $options['limit'] - $total; |
|
| 208 | - } |
|
| 209 | - $total += purger_repertoire($chemin, $opts); |
|
| 210 | - if (isset($options['subdir']) && $options['subdir']) { |
|
| 211 | - spip_unlink($chemin); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 217 | - break; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - closedir($handle); |
|
| 221 | - |
|
| 222 | - return $total; |
|
| 180 | + if (!is_dir($dir) or !is_readable($dir)) { |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | + $handle = opendir($dir); |
|
| 184 | + if (!$handle) { |
|
| 185 | + return; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $total = 0; |
|
| 189 | + |
|
| 190 | + while (($fichier = @readdir($handle)) !== false) { |
|
| 191 | + // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG |
|
| 192 | + if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') { |
|
| 193 | + continue; |
|
| 194 | + } |
|
| 195 | + $chemin = "$dir/$fichier"; |
|
| 196 | + if (is_file($chemin)) { |
|
| 197 | + if ((!isset($options['atime']) or (@fileatime($chemin) < $options['atime'])) |
|
| 198 | + and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime'])) |
|
| 199 | + ) { |
|
| 200 | + supprimer_fichier($chemin); |
|
| 201 | + $total++; |
|
| 202 | + } |
|
| 203 | + } else { |
|
| 204 | + if (is_dir($chemin)) { |
|
| 205 | + $opts = $options; |
|
| 206 | + if (isset($options['limit'])) { |
|
| 207 | + $opts['limit'] = $options['limit'] - $total; |
|
| 208 | + } |
|
| 209 | + $total += purger_repertoire($chemin, $opts); |
|
| 210 | + if (isset($options['subdir']) && $options['subdir']) { |
|
| 211 | + spip_unlink($chemin); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (isset($options['limit']) and $total >= $options['limit']) { |
|
| 217 | + break; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + closedir($handle); |
|
| 221 | + |
|
| 222 | + return $total; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -231,15 +231,15 @@ discard block |
||
| 231 | 231 | // http://code.spip.net/@retire_cache |
| 232 | 232 | function retire_cache($cache) { |
| 233 | 233 | |
| 234 | - if (preg_match( |
|
| 235 | - ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 236 | - $cache |
|
| 237 | - )) { |
|
| 238 | - // supprimer le fichier (de facon propre) |
|
| 239 | - supprimer_fichier(_DIR_CACHE . $cache); |
|
| 240 | - } else { |
|
| 241 | - spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 242 | - } |
|
| 234 | + if (preg_match( |
|
| 235 | + ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i', |
|
| 236 | + $cache |
|
| 237 | + )) { |
|
| 238 | + // supprimer le fichier (de facon propre) |
|
| 239 | + supprimer_fichier(_DIR_CACHE . $cache); |
|
| 240 | + } else { |
|
| 241 | + spip_log("Nom de fichier cache incorrect : $cache"); |
|
| 242 | + } |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | // Supprimer les caches marques "x" |
@@ -247,9 +247,9 @@ discard block |
||
| 247 | 247 | // la meta est toujours false ; mais evitons un bug si elle est appellee |
| 248 | 248 | // http://code.spip.net/@retire_caches |
| 249 | 249 | function inc_retire_caches_dist($chemin = '') { |
| 250 | - if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 251 | - effacer_meta('invalider_caches'); |
|
| 252 | - } # concurrence |
|
| 250 | + if (isset($GLOBALS['meta']['invalider_caches'])) { |
|
| 251 | + effacer_meta('invalider_caches'); |
|
| 252 | + } # concurrence |
|
| 253 | 253 | } |
| 254 | 254 | |
| 255 | 255 | ####################################################################### |
@@ -260,9 +260,9 @@ discard block |
||
| 260 | 260 | ## |
| 261 | 261 | |
| 262 | 262 | function retire_caches($chemin = '') { |
| 263 | - if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 264 | - return $retire_caches($chemin); |
|
| 265 | - } |
|
| 263 | + if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) { |
|
| 264 | + return $retire_caches($chemin); |
|
| 265 | + } |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
@@ -271,10 +271,10 @@ discard block |
||
| 271 | 271 | |
| 272 | 272 | // http://code.spip.net/@calcul_invalideurs |
| 273 | 273 | function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) { |
| 274 | - if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 275 | - return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 276 | - } |
|
| 277 | - return $corps; |
|
| 274 | + if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) { |
|
| 275 | + return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 276 | + } |
|
| 277 | + return $corps; |
|
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | |
@@ -284,27 +284,27 @@ discard block |
||
| 284 | 284 | // |
| 285 | 285 | // http://code.spip.net/@supprime_invalideurs |
| 286 | 286 | function supprime_invalideurs() { |
| 287 | - if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 288 | - return $supprime_invalideurs(); |
|
| 289 | - } |
|
| 287 | + if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) { |
|
| 288 | + return $supprime_invalideurs(); |
|
| 289 | + } |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | |
| 293 | 293 | // Calcul des pages : noter dans la base les liens d'invalidation |
| 294 | 294 | // http://code.spip.net/@maj_invalideurs |
| 295 | 295 | function maj_invalideurs($fichier, &$page) { |
| 296 | - if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 297 | - return $maj_invalideurs($fichier, $page); |
|
| 298 | - } |
|
| 296 | + if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) { |
|
| 297 | + return $maj_invalideurs($fichier, $page); |
|
| 298 | + } |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
| 302 | 302 | // les invalideurs sont de la forme "objet/id_objet" |
| 303 | 303 | // http://code.spip.net/@insere_invalideur |
| 304 | 304 | function insere_invalideur($inval, $fichier) { |
| 305 | - if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 306 | - return $insere_invalideur($inval, $fichier); |
|
| 307 | - } |
|
| 305 | + if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) { |
|
| 306 | + return $insere_invalideur($inval, $fichier); |
|
| 307 | + } |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | // |
@@ -312,16 +312,16 @@ discard block |
||
| 312 | 312 | // |
| 313 | 313 | // http://code.spip.net/@applique_invalideur |
| 314 | 314 | function applique_invalideur($depart) { |
| 315 | - if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 316 | - return $applique_invalideur($depart); |
|
| 317 | - } |
|
| 315 | + if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) { |
|
| 316 | + return $applique_invalideur($depart); |
|
| 317 | + } |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | // |
| 321 | 321 | // Invalider les caches liés à telle condition |
| 322 | 322 | // |
| 323 | 323 | function suivre_invalideur($cond, $modif = true) { |
| 324 | - if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 325 | - return $suivre_invalideur($cond, $modif); |
|
| 326 | - } |
|
| 324 | + if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) { |
|
| 325 | + return $suivre_invalideur($cond, $modif); |
|
| 326 | + } |
|
| 327 | 327 | } |
| 328 | 328 | \ No newline at end of file |