Completed
Push — master ( 9518f9...cd5173 )
by cam
11:30
created
ecrire/inc/invalideur.php 2 patches
Doc Comments   +7 added lines patch added patch discarded remove patch
@@ -232,6 +232,10 @@  discard block
 block discarded – undo
232 232
 // (note: si absente, n'est pas appellee)
233 233
 
234 234
 // https://code.spip.net/@calcul_invalideurs
235
+/**
236
+ * @param string $corps
237
+ * @param string $id_boucle
238
+ */
235 239
 function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) {
236 240
 	if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
237 241
 		return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
@@ -254,6 +258,9 @@  discard block
 block discarded – undo
254 258
 
255 259
 // Calcul des pages : noter dans la base les liens d'invalidation
256 260
 // https://code.spip.net/@maj_invalideurs
261
+/**
262
+ * @param string $fichier
263
+ */
257 264
 function maj_invalideurs($fichier, &$page) {
258 265
 	if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
259 266
 		return $maj_invalideurs($fichier, $page);
Please login to merge, or discard this patch.
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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');
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  * en droit de l'éliminer
28 28
  */
29 29
 if (!defined('_AGE_CACHE_ATIME')) {
30
-	define('_AGE_CACHE_ATIME', 3600);
30
+    define('_AGE_CACHE_ATIME', 3600);
31 31
 }
32 32
 
33 33
 
@@ -40,31 +40,31 @@  discard block
 block discarded – undo
40 40
  * @return int Taille approximative en octets
41 41
  **/
42 42
 function taille_du_cache() {
43
-	# check dirs until we reach > 500 files
44
-	$t = 0;
45
-	$n = 0;
46
-	$time = isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0;
47
-	for ($i=0; $i < 256; $i++) {
48
-		$dir = _DIR_CACHE.sprintf('%02s', dechex($i));
49
-		if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
50
-			while (($f = readdir($d)) !== false) {
51
-				if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) {
52
-					$n++;
53
-					if ($a['mtime'] >= $time) {
54
-						if ($a['blocks'] > 0) {
55
-							$t += 512*$a['blocks'];
56
-						} else {
57
-							$t += $a['size'];
58
-						}
59
-					}
60
-				}
61
-			}
62
-		}
63
-		if ($n > 500) {
64
-			return intval(256*$t/(1+$i));
65
-		}
66
-	}
67
-	return $t;
43
+    # check dirs until we reach > 500 files
44
+    $t = 0;
45
+    $n = 0;
46
+    $time = isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0;
47
+    for ($i=0; $i < 256; $i++) {
48
+        $dir = _DIR_CACHE.sprintf('%02s', dechex($i));
49
+        if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
50
+            while (($f = readdir($d)) !== false) {
51
+                if (preg_match(',^[[0-9a-f]+\.cache$,S', $f) and $a = stat("$dir/$f")) {
52
+                    $n++;
53
+                    if ($a['mtime'] >= $time) {
54
+                        if ($a['blocks'] > 0) {
55
+                            $t += 512*$a['blocks'];
56
+                        } else {
57
+                            $t += $a['size'];
58
+                        }
59
+                    }
60
+                }
61
+            }
62
+        }
63
+        if ($n > 500) {
64
+            return intval(256*$t/(1+$i));
65
+        }
66
+    }
67
+    return $t;
68 68
 }
69 69
 
70 70
 
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
  *     Inutilisé
92 92
  **/
93 93
 function inc_suivre_invalideur_dist($cond, $modif = true) {
94
-	if (!$modif) {
95
-		return;
96
-	}
97
-
98
-	// determiner l'objet modifie : forum, article, etc
99
-	if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
100
-		$objet = objet_type($r[1]);
101
-	}
102
-
103
-	// stocker la date_modif_$objet (ne sert a rien pour le moment)
104
-	if (isset($objet)) {
105
-		ecrire_meta('derniere_modif_' . $objet, time());
106
-	}
107
-
108
-	// si $derniere_modif_invalide est un array('article', 'rubrique')
109
-	// n'affecter la meta que si un de ces objets est modifie
110
-	if (is_array($GLOBALS['derniere_modif_invalide'])) {
111
-		if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
112
-			ecrire_meta('derniere_modif', time());
113
-		}
114
-	} // sinon, cas standard, toujours affecter la meta
115
-	else {
116
-		ecrire_meta('derniere_modif', time());
117
-	}
94
+    if (!$modif) {
95
+        return;
96
+    }
97
+
98
+    // determiner l'objet modifie : forum, article, etc
99
+    if (preg_match(',["\']([a-z_]+)[/"\'],', $cond, $r)) {
100
+        $objet = objet_type($r[1]);
101
+    }
102
+
103
+    // stocker la date_modif_$objet (ne sert a rien pour le moment)
104
+    if (isset($objet)) {
105
+        ecrire_meta('derniere_modif_' . $objet, time());
106
+    }
107
+
108
+    // si $derniere_modif_invalide est un array('article', 'rubrique')
109
+    // n'affecter la meta que si un de ces objets est modifie
110
+    if (is_array($GLOBALS['derniere_modif_invalide'])) {
111
+        if (in_array($objet, $GLOBALS['derniere_modif_invalide'])) {
112
+            ecrire_meta('derniere_modif', time());
113
+        }
114
+    } // sinon, cas standard, toujours affecter la meta
115
+    else {
116
+        ecrire_meta('derniere_modif', time());
117
+    }
118 118
 }
119 119
 
120 120
 
@@ -139,49 +139,49 @@  discard block
 block discarded – undo
139 139
  *     Nombre de fichiers supprimés
140 140
  **/
141 141
 function purger_repertoire($dir, $options = array()) {
142
-	if (!is_dir($dir) or !is_readable($dir)) {
143
-		return;
144
-	}
145
-	$handle = opendir($dir);
146
-	if (!$handle) {
147
-		return;
148
-	}
149
-
150
-	$total = 0;
151
-
152
-	while (($fichier = @readdir($handle)) !== false) {
153
-		// Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG
154
-		if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') {
155
-			continue;
156
-		}
157
-		$chemin = "$dir/$fichier";
158
-		if (is_file($chemin)) {
159
-			if ((!isset($options['atime']) or (@fileatime($chemin) < $options['atime']))
160
-				and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime']))
161
-			) {
162
-				supprimer_fichier($chemin);
163
-				$total++;
164
-			}
165
-		} else {
166
-			if (is_dir($chemin)) {
167
-				$opts = $options;
168
-				if (isset($options['limit'])) {
169
-					$opts['limit'] = $options['limit'] - $total;
170
-				}
171
-				$total += purger_repertoire($chemin, $opts);
172
-				if (isset($options['subdir']) && $options['subdir']) {
173
-					spip_unlink($chemin);
174
-				}
175
-			}
176
-		}
177
-
178
-		if (isset($options['limit']) and $total >= $options['limit']) {
179
-			break;
180
-		}
181
-	}
182
-	closedir($handle);
183
-
184
-	return $total;
142
+    if (!is_dir($dir) or !is_readable($dir)) {
143
+        return;
144
+    }
145
+    $handle = opendir($dir);
146
+    if (!$handle) {
147
+        return;
148
+    }
149
+
150
+    $total = 0;
151
+
152
+    while (($fichier = @readdir($handle)) !== false) {
153
+        // Eviter ".", "..", ".htaccess", ".svn" etc & CACHEDIR.TAG
154
+        if ($fichier[0] == '.' or $fichier == 'CACHEDIR.TAG') {
155
+            continue;
156
+        }
157
+        $chemin = "$dir/$fichier";
158
+        if (is_file($chemin)) {
159
+            if ((!isset($options['atime']) or (@fileatime($chemin) < $options['atime']))
160
+                and (!isset($options['mtime']) or (@filemtime($chemin) < $options['mtime']))
161
+            ) {
162
+                supprimer_fichier($chemin);
163
+                $total++;
164
+            }
165
+        } else {
166
+            if (is_dir($chemin)) {
167
+                $opts = $options;
168
+                if (isset($options['limit'])) {
169
+                    $opts['limit'] = $options['limit'] - $total;
170
+                }
171
+                $total += purger_repertoire($chemin, $opts);
172
+                if (isset($options['subdir']) && $options['subdir']) {
173
+                    spip_unlink($chemin);
174
+                }
175
+            }
176
+        }
177
+
178
+        if (isset($options['limit']) and $total >= $options['limit']) {
179
+            break;
180
+        }
181
+    }
182
+    closedir($handle);
183
+
184
+    return $total;
185 185
 }
186 186
 
187 187
 
@@ -193,15 +193,15 @@  discard block
 block discarded – undo
193 193
 // https://code.spip.net/@retire_cache
194 194
 function retire_cache($cache) {
195 195
 
196
-	if (preg_match(
197
-		',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i',
198
-		$cache
199
-	)) {
200
-		// supprimer le fichier (de facon propre)
201
-		supprimer_fichier(_DIR_CACHE . $cache);
202
-	} else {
203
-		spip_log("Nom de fichier cache incorrect : $cache");
204
-	}
196
+    if (preg_match(
197
+        ',^([0-9a-f]/)?([0-9]+/)?[0-9a-f]+\.cache(\.gz)?$,i',
198
+        $cache
199
+    )) {
200
+        // supprimer le fichier (de facon propre)
201
+        supprimer_fichier(_DIR_CACHE . $cache);
202
+    } else {
203
+        spip_log("Nom de fichier cache incorrect : $cache");
204
+    }
205 205
 }
206 206
 
207 207
 // Supprimer les caches marques "x"
@@ -209,9 +209,9 @@  discard block
 block discarded – undo
209 209
 // la meta est toujours false ; mais evitons un bug si elle est appellee
210 210
 // https://code.spip.net/@retire_caches
211 211
 function inc_retire_caches_dist($chemin = '') {
212
-	if (isset($GLOBALS['meta']['invalider_caches'])) {
213
-		effacer_meta('invalider_caches');
214
-	} # concurrence
212
+    if (isset($GLOBALS['meta']['invalider_caches'])) {
213
+        effacer_meta('invalider_caches');
214
+    } # concurrence
215 215
 }
216 216
 
217 217
 #######################################################################
@@ -222,9 +222,9 @@  discard block
 block discarded – undo
222 222
 ##
223 223
 
224 224
 function retire_caches($chemin = '') {
225
-	if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) {
226
-		return $retire_caches($chemin);
227
-	}
225
+    if ($retire_caches = charger_fonction('retire_caches', 'inc', true)) {
226
+        return $retire_caches($chemin);
227
+    }
228 228
 }
229 229
 
230 230
 
@@ -233,10 +233,10 @@  discard block
 block discarded – undo
233 233
 
234 234
 // https://code.spip.net/@calcul_invalideurs
235 235
 function calcul_invalideurs($corps, $primary, &$boucles, $id_boucle) {
236
-	if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
237
-		return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
238
-	}
239
-	return $corps;
236
+    if ($calcul_invalideurs = charger_fonction('calcul_invalideurs', 'inc', true)) {
237
+        return $calcul_invalideurs($corps, $primary, $boucles, $id_boucle);
238
+    }
239
+    return $corps;
240 240
 }
241 241
 
242 242
 
@@ -246,27 +246,27 @@  discard block
 block discarded – undo
246 246
 //
247 247
 // https://code.spip.net/@supprime_invalideurs
248 248
 function supprime_invalideurs() {
249
-	if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) {
250
-		return $supprime_invalideurs();
251
-	}
249
+    if ($supprime_invalideurs = charger_fonction('supprime_invalideurs', 'inc', true)) {
250
+        return $supprime_invalideurs();
251
+    }
252 252
 }
253 253
 
254 254
 
255 255
 // Calcul des pages : noter dans la base les liens d'invalidation
256 256
 // https://code.spip.net/@maj_invalideurs
257 257
 function maj_invalideurs($fichier, &$page) {
258
-	if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
259
-		return $maj_invalideurs($fichier, $page);
260
-	}
258
+    if ($maj_invalideurs = charger_fonction('maj_invalideurs', 'inc', true)) {
259
+        return $maj_invalideurs($fichier, $page);
260
+    }
261 261
 }
262 262
 
263 263
 
264 264
 // les invalideurs sont de la forme "objet/id_objet"
265 265
 // https://code.spip.net/@insere_invalideur
266 266
 function insere_invalideur($inval, $fichier) {
267
-	if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) {
268
-		return $insere_invalideur($inval, $fichier);
269
-	}
267
+    if ($insere_invalideur = charger_fonction('insere_invalideur', 'inc', true)) {
268
+        return $insere_invalideur($inval, $fichier);
269
+    }
270 270
 }
271 271
 
272 272
 //
@@ -274,16 +274,16 @@  discard block
 block discarded – undo
274 274
 //
275 275
 // https://code.spip.net/@applique_invalideur
276 276
 function applique_invalideur($depart) {
277
-	if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) {
278
-		return $applique_invalideur($depart);
279
-	}
277
+    if ($applique_invalideur = charger_fonction('applique_invalideur', 'inc', true)) {
278
+        return $applique_invalideur($depart);
279
+    }
280 280
 }
281 281
 
282 282
 //
283 283
 // Invalider les caches liés à telle condition
284 284
 //
285 285
 function suivre_invalideur($cond, $modif = true) {
286
-	if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) {
287
-		return $suivre_invalideur($cond, $modif);
288
-	}
286
+    if ($suivre_invalideur = charger_fonction('suivre_invalideur', 'inc', true)) {
287
+        return $suivre_invalideur($cond, $modif);
288
+    }
289 289
 }
290 290
\ No newline at end of file
Please login to merge, or discard this patch.