Completed
Push — master ( 55c88a...92be1d )
by cam
04:36
created
ecrire/base/connect_sql.php 1 patch
Indentation   +309 added lines, -309 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\SQL
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 require_once _ROOT_RESTREINT . 'base/objets.php';
22 22
 
@@ -42,118 +42,118 @@  discard block
 block discarded – undo
42 42
  **/
43 43
 function spip_connect($serveur = '', $version = '') {
44 44
 
45
-	$serveur = !is_string($serveur) ? '' : strtolower($serveur);
46
-	$index = $serveur ? $serveur : 0;
47
-	if (!$version) {
48
-		$version = $GLOBALS['spip_sql_version'];
49
-	}
50
-	if (isset($GLOBALS['connexions'][$index][$version])) {
51
-		return $GLOBALS['connexions'][$index];
52
-	}
53
-
54
-	include_spip('base/abstract_sql');
55
-	$install = (_request('exec') == 'install');
56
-
57
-	// Premiere connexion ?
58
-	if (!($old = isset($GLOBALS['connexions'][$index]))) {
59
-		$f = (!preg_match('/^[\w\.]*$/', $serveur))
60
-			? '' // nom de serveur mal ecrit
61
-			: ($serveur ?
62
-				(_DIR_CONNECT . $serveur . '.php') // serveur externe
63
-				: (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok
64
-					: ($install ? _FILE_CONNECT_TMP // init du serveur principal
65
-						: ''))); // installation pas faite
66
-
67
-		unset($GLOBALS['db_ok']);
68
-		unset($GLOBALS['spip_connect_version']);
69
-		if ($f) {
70
-			if (is_readable($f)) {
71
-				include($f);
72
-			} elseif ($serveur and !$install) {
73
-				// chercher une declaration de serveur dans le path
74
-				// qui pourra un jour servir a declarer des bases sqlite
75
-				// par des plugins. Et sert aussi aux boucles POUR.
76
-				find_in_path("$serveur.php", 'connect/', true);
77
-			}
78
-		}
79
-		if (!isset($GLOBALS['db_ok'])) {
80
-			// fera mieux la prochaine fois
81
-			if ($install) {
82
-				return false;
83
-			}
84
-			if ($f and is_readable($f)) {
85
-				spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
86
-			} else {
87
-				spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
88
-			}
89
-			spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
90
-
91
-			// ne plus reessayer si ce n'est pas l'install
92
-			return $GLOBALS['connexions'][$index] = false;
93
-		}
94
-		$GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
95
-	}
96
-	// si la connexion a deja ete tentee mais a echoue, le dire!
97
-	if (!$GLOBALS['connexions'][$index]) {
98
-		return false;
99
-	}
100
-
101
-	// la connexion a reussi ou etait deja faite.
102
-	// chargement de la version du jeu de fonctions
103
-	// si pas dans le fichier par defaut
104
-	$type = $GLOBALS['db_ok']['type'];
105
-	$jeu = 'spip_' . $type . '_functions_' . $version;
106
-	if (!isset($GLOBALS[$jeu])) {
107
-		if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
108
-			spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
109
-
110
-			// ne plus reessayer
111
-			return $GLOBALS['connexions'][$index][$version] = array();
112
-		}
113
-	}
114
-	$GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
115
-	if ($old) {
116
-		return $GLOBALS['connexions'][$index];
117
-	}
118
-
119
-	$GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0;
120
-
121
-	// initialisation de l'alphabet utilise dans les connexions SQL
122
-	// si l'installation l'a determine.
123
-	// Celui du serveur principal l'impose aux serveurs secondaires
124
-	// s'ils le connaissent
125
-
126
-	if (!$serveur) {
127
-		$charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
128
-		if (!$charset) {
129
-			unset($GLOBALS['connexions'][$index]);
130
-			spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT);
131
-
132
-			return false;
133
-		}
134
-	} else {
135
-		if ($GLOBALS['db_ok']['charset']) {
136
-			$charset = $GLOBALS['db_ok']['charset'];
137
-		}
138
-		// spip_meta n'existe pas toujours dans la base
139
-		// C'est le cas d'un dump sqlite par exemple 
140
-		elseif ($GLOBALS['connexions'][$index]['spip_connect_version']
141
-			and sql_showtable('spip_meta', true, $serveur)
142
-			and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)
143
-		) {
144
-			$charset = $r;
145
-		} else {
146
-			$charset = -1;
147
-		}
148
-	}
149
-	if ($charset != -1) {
150
-		$f = $GLOBALS[$jeu]['set_charset'];
151
-		if (function_exists($f)) {
152
-			$f($charset, $serveur);
153
-		}
154
-	}
155
-
156
-	return $GLOBALS['connexions'][$index];
45
+    $serveur = !is_string($serveur) ? '' : strtolower($serveur);
46
+    $index = $serveur ? $serveur : 0;
47
+    if (!$version) {
48
+        $version = $GLOBALS['spip_sql_version'];
49
+    }
50
+    if (isset($GLOBALS['connexions'][$index][$version])) {
51
+        return $GLOBALS['connexions'][$index];
52
+    }
53
+
54
+    include_spip('base/abstract_sql');
55
+    $install = (_request('exec') == 'install');
56
+
57
+    // Premiere connexion ?
58
+    if (!($old = isset($GLOBALS['connexions'][$index]))) {
59
+        $f = (!preg_match('/^[\w\.]*$/', $serveur))
60
+            ? '' // nom de serveur mal ecrit
61
+            : ($serveur ?
62
+                (_DIR_CONNECT . $serveur . '.php') // serveur externe
63
+                : (_FILE_CONNECT ? _FILE_CONNECT // serveur principal ok
64
+                    : ($install ? _FILE_CONNECT_TMP // init du serveur principal
65
+                        : ''))); // installation pas faite
66
+
67
+        unset($GLOBALS['db_ok']);
68
+        unset($GLOBALS['spip_connect_version']);
69
+        if ($f) {
70
+            if (is_readable($f)) {
71
+                include($f);
72
+            } elseif ($serveur and !$install) {
73
+                // chercher une declaration de serveur dans le path
74
+                // qui pourra un jour servir a declarer des bases sqlite
75
+                // par des plugins. Et sert aussi aux boucles POUR.
76
+                find_in_path("$serveur.php", 'connect/', true);
77
+            }
78
+        }
79
+        if (!isset($GLOBALS['db_ok'])) {
80
+            // fera mieux la prochaine fois
81
+            if ($install) {
82
+                return false;
83
+            }
84
+            if ($f and is_readable($f)) {
85
+                spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE);
86
+            } else {
87
+                spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE);
88
+            }
89
+            spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS);
90
+
91
+            // ne plus reessayer si ce n'est pas l'install
92
+            return $GLOBALS['connexions'][$index] = false;
93
+        }
94
+        $GLOBALS['connexions'][$index] = $GLOBALS['db_ok'];
95
+    }
96
+    // si la connexion a deja ete tentee mais a echoue, le dire!
97
+    if (!$GLOBALS['connexions'][$index]) {
98
+        return false;
99
+    }
100
+
101
+    // la connexion a reussi ou etait deja faite.
102
+    // chargement de la version du jeu de fonctions
103
+    // si pas dans le fichier par defaut
104
+    $type = $GLOBALS['db_ok']['type'];
105
+    $jeu = 'spip_' . $type . '_functions_' . $version;
106
+    if (!isset($GLOBALS[$jeu])) {
107
+        if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) {
108
+            spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS);
109
+
110
+            // ne plus reessayer
111
+            return $GLOBALS['connexions'][$index][$version] = array();
112
+        }
113
+    }
114
+    $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu];
115
+    if ($old) {
116
+        return $GLOBALS['connexions'][$index];
117
+    }
118
+
119
+    $GLOBALS['connexions'][$index]['spip_connect_version'] = isset($GLOBALS['spip_connect_version']) ? $GLOBALS['spip_connect_version'] : 0;
120
+
121
+    // initialisation de l'alphabet utilise dans les connexions SQL
122
+    // si l'installation l'a determine.
123
+    // Celui du serveur principal l'impose aux serveurs secondaires
124
+    // s'ils le connaissent
125
+
126
+    if (!$serveur) {
127
+        $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']);
128
+        if (!$charset) {
129
+            unset($GLOBALS['connexions'][$index]);
130
+            spip_log("spip_connect: absence de charset", _LOG_AVERTISSEMENT);
131
+
132
+            return false;
133
+        }
134
+    } else {
135
+        if ($GLOBALS['db_ok']['charset']) {
136
+            $charset = $GLOBALS['db_ok']['charset'];
137
+        }
138
+        // spip_meta n'existe pas toujours dans la base
139
+        // C'est le cas d'un dump sqlite par exemple 
140
+        elseif ($GLOBALS['connexions'][$index]['spip_connect_version']
141
+            and sql_showtable('spip_meta', true, $serveur)
142
+            and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur)
143
+        ) {
144
+            $charset = $r;
145
+        } else {
146
+            $charset = -1;
147
+        }
148
+    }
149
+    if ($charset != -1) {
150
+        $f = $GLOBALS[$jeu]['set_charset'];
151
+        if (function_exists($f)) {
152
+            $f($charset, $serveur);
153
+        }
154
+    }
155
+
156
+    return $GLOBALS['connexions'][$index];
157 157
 }
158 158
 
159 159
 /**
@@ -162,12 +162,12 @@  discard block
 block discarded – undo
162 162
  * @param string $serveur Nom du connecteur de bdd utilisé
163 163
  **/
164 164
 function spip_sql_erreur($serveur = '') {
165
-	$connexion = spip_connect($serveur);
166
-	$e = sql_errno($serveur);
167
-	$t = (isset($connexion['type']) ? $connexion['type'] : 'sql');
168
-	$m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
-	$f = $t . $serveur;
170
-	spip_log($m, $f . '.' . _LOG_ERREUR);
165
+    $connexion = spip_connect($serveur);
166
+    $e = sql_errno($serveur);
167
+    $t = (isset($connexion['type']) ? $connexion['type'] : 'sql');
168
+    $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']);
169
+    $f = $t . $serveur;
170
+    spip_log($m, $f . '.' . _LOG_ERREUR);
171 171
 }
172 172
 
173 173
 /**
@@ -189,19 +189,19 @@  discard block
 block discarded – undo
189 189
  *     - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion
190 190
  **/
191 191
 function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) {
192
-	$desc = spip_connect($serveur, $version);
193
-	if (function_exists($f = @$desc[$version][$ins])) {
194
-		return $f;
195
-	}
196
-	if ($continue) {
197
-		return $desc;
198
-	}
199
-	if ($ins) {
200
-		spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
201
-	}
202
-	include_spip('inc/minipres');
203
-	echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503));
204
-	exit;
192
+    $desc = spip_connect($serveur, $version);
193
+    if (function_exists($f = @$desc[$version][$ins])) {
194
+        return $f;
195
+    }
196
+    if ($continue) {
197
+        return $desc;
198
+    }
199
+    if ($ins) {
200
+        spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR);
201
+    }
202
+    include_spip('inc/minipres');
203
+    echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503));
204
+    exit;
205 205
 }
206 206
 
207 207
 /**
@@ -227,70 +227,70 @@  discard block
 block discarded – undo
227 227
  * @return array          Description de la connexion
228 228
  */
229 229
 function spip_connect_db(
230
-	$host,
231
-	$port,
232
-	$login,
233
-	$pass,
234
-	$db = '',
235
-	$type = 'mysql',
236
-	$prefixe = '',
237
-	$auth = '',
238
-	$charset = ''
230
+    $host,
231
+    $port,
232
+    $login,
233
+    $pass,
234
+    $db = '',
235
+    $type = 'mysql',
236
+    $prefixe = '',
237
+    $auth = '',
238
+    $charset = ''
239 239
 ) {
240
-	// temps avant nouvelle tentative de connexion
241
-	// suite a une connection echouee
242
-	if (!defined('_CONNECT_RETRY_DELAY')) {
243
-		define('_CONNECT_RETRY_DELAY', 30);
244
-	}
245
-
246
-	$f = "";
247
-	// un fichier de identifiant par combinaison (type,host,port,db)
248
-	// pour ne pas declarer tout indisponible d'un coup
249
-	// si en cours d'installation ou si db=@test@ on ne pose rien
250
-	// car c'est un test de connexion
251
-	if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") {
252
-		$f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
253
-	} elseif ($db == '@test@') {
254
-		$db = '';
255
-	}
256
-
257
-	if ($f
258
-		and @file_exists($f)
259
-		and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
260
-	) {
261
-		spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
262
-
263
-		return;
264
-	}
265
-
266
-	if (!$prefixe) {
267
-		$prefixe = isset($GLOBALS['table_prefix'])
268
-			? $GLOBALS['table_prefix'] : $db;
269
-	}
270
-	$h = charger_fonction($type, 'req', true);
271
-	if (!$h) {
272
-		spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
273
-
274
-		return;
275
-	}
276
-	if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
277
-
278
-		if (!is_array($auth)) {
279
-			// compatibilite version 0.7 initiale
280
-			$g['ldap'] = $auth;
281
-			$auth = array('ldap' => $auth);
282
-		}
283
-		$g['authentification'] = $auth;
284
-		$g['type'] = $type;
285
-		$g['charset'] = $charset;
286
-
287
-		return $GLOBALS['db_ok'] = $g;
288
-	}
289
-	// En cas d'indisponibilite du serveur, eviter de le bombarder
290
-	if ($f) {
291
-		@touch($f);
292
-		spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
293
-	}
240
+    // temps avant nouvelle tentative de connexion
241
+    // suite a une connection echouee
242
+    if (!defined('_CONNECT_RETRY_DELAY')) {
243
+        define('_CONNECT_RETRY_DELAY', 30);
244
+    }
245
+
246
+    $f = "";
247
+    // un fichier de identifiant par combinaison (type,host,port,db)
248
+    // pour ne pas declarer tout indisponible d'un coup
249
+    // si en cours d'installation ou si db=@test@ on ne pose rien
250
+    // car c'est un test de connexion
251
+    if (!defined('_ECRIRE_INSTALL') and $db !== "@test@") {
252
+        $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out';
253
+    } elseif ($db == '@test@') {
254
+        $db = '';
255
+    }
256
+
257
+    if ($f
258
+        and @file_exists($f)
259
+        and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY)
260
+    ) {
261
+        spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS);
262
+
263
+        return;
264
+    }
265
+
266
+    if (!$prefixe) {
267
+        $prefixe = isset($GLOBALS['table_prefix'])
268
+            ? $GLOBALS['table_prefix'] : $db;
269
+    }
270
+    $h = charger_fonction($type, 'req', true);
271
+    if (!$h) {
272
+        spip_log("les requetes $type ne sont pas fournies", _LOG_HS);
273
+
274
+        return;
275
+    }
276
+    if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) {
277
+
278
+        if (!is_array($auth)) {
279
+            // compatibilite version 0.7 initiale
280
+            $g['ldap'] = $auth;
281
+            $auth = array('ldap' => $auth);
282
+        }
283
+        $g['authentification'] = $auth;
284
+        $g['type'] = $type;
285
+        $g['charset'] = $charset;
286
+
287
+        return $GLOBALS['db_ok'] = $g;
288
+    }
289
+    // En cas d'indisponibilite du serveur, eviter de le bombarder
290
+    if ($f) {
291
+        @touch($f);
292
+        spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS);
293
+    }
294 294
 }
295 295
 
296 296
 
@@ -322,31 +322,31 @@  discard block
 block discarded – undo
322 322
  *     - nom du charset sinon
323 323
  **/
324 324
 function spip_connect_main($connexion, $charset_sql_connexion = '') {
325
-	if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) {
326
-		include_spip('inc/headers');
327
-		redirige_url_ecrire('upgrade', 'reinstall=oui');
328
-	}
329
-
330
-	if (!($f = $connexion['select'])) {
331
-		return false;
332
-	}
333
-	// si le charset est fourni, l'utiliser
334
-	if ($charset_sql_connexion) {
335
-		return $charset_sql_connexion;
336
-	}
337
-	// sinon on regarde la table spip_meta
338
-	// en cas d'erreur select retourne la requette (is_string=true donc)
339
-	if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")
340
-		or is_string($r)
341
-	) {
342
-		return false;
343
-	}
344
-	if (!($f = $connexion['fetch'])) {
345
-		return false;
346
-	}
347
-	$r = $f($r);
348
-
349
-	return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1;
325
+    if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) {
326
+        include_spip('inc/headers');
327
+        redirige_url_ecrire('upgrade', 'reinstall=oui');
328
+    }
329
+
330
+    if (!($f = $connexion['select'])) {
331
+        return false;
332
+    }
333
+    // si le charset est fourni, l'utiliser
334
+    if ($charset_sql_connexion) {
335
+        return $charset_sql_connexion;
336
+    }
337
+    // sinon on regarde la table spip_meta
338
+    // en cas d'erreur select retourne la requette (is_string=true donc)
339
+    if (!$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'")
340
+        or is_string($r)
341
+    ) {
342
+        return false;
343
+    }
344
+    if (!($f = $connexion['fetch'])) {
345
+        return false;
346
+    }
347
+    $r = $f($r);
348
+
349
+    return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1;
350 350
 }
351 351
 
352 352
 /**
@@ -361,9 +361,9 @@  discard block
 block discarded – undo
361 361
  * @return array
362 362
  */
363 363
 function spip_connect_ldap($serveur = '') {
364
-	include_spip('auth/ldap');
364
+    include_spip('auth/ldap');
365 365
 
366
-	return auth_ldap_connect($serveur);
366
+    return auth_ldap_connect($serveur);
367 367
 }
368 368
 
369 369
 /**
@@ -379,9 +379,9 @@  discard block
 block discarded – undo
379 379
  * @return string Valeur échappée.
380 380
  **/
381 381
 function _q($a) {
382
-	return (is_numeric($a)) ? strval($a) :
383
-		(!is_array($a) ? ("'" . addslashes($a) . "'")
384
-			: join(",", array_map('_q', $a)));
382
+    return (is_numeric($a)) ? strval($a) :
383
+        (!is_array($a) ? ("'" . addslashes($a) . "'")
384
+            : join(",", array_map('_q', $a)));
385 385
 }
386 386
 
387 387
 
@@ -399,19 +399,19 @@  discard block
 block discarded – undo
399 399
  *     - chaîne vide si non trouvé.
400 400
  **/
401 401
 function table_jointure($x, $y) {
402
-	$trouver_table = charger_fonction('trouver_table', 'base');
403
-	$xdesc = $trouver_table(table_objet($x));
404
-	$ydesc = $trouver_table(table_objet($y));
405
-	$ix = @$xdesc['key']["PRIMARY KEY"];
406
-	$iy = @$ydesc['key']["PRIMARY KEY"];
407
-	if ($table = $ydesc['tables_jointures'][$ix]) {
408
-		return $table;
409
-	}
410
-	if ($table = $xdesc['tables_jointures'][$iy]) {
411
-		return $table;
412
-	}
413
-
414
-	return '';
402
+    $trouver_table = charger_fonction('trouver_table', 'base');
403
+    $xdesc = $trouver_table(table_objet($x));
404
+    $ydesc = $trouver_table(table_objet($y));
405
+    $ix = @$xdesc['key']["PRIMARY KEY"];
406
+    $iy = @$ydesc['key']["PRIMARY KEY"];
407
+    if ($table = $ydesc['tables_jointures'][$ix]) {
408
+        return $table;
409
+    }
410
+    if ($table = $xdesc['tables_jointures'][$iy]) {
411
+        return $table;
412
+    }
413
+
414
+    return '';
415 415
 }
416 416
 
417 417
 /**
@@ -427,41 +427,41 @@  discard block
 block discarded – undo
427 427
  * @return array
428 428
  */
429 429
 function query_echappe_textes($query) {
430
-	static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
431
-	$query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
432
-	if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) {
433
-		$textes = reset($textes); // indice 0 du match
434
-		switch (count($textes)) {
435
-			case 0:
436
-				$replace = array();
437
-				break;
438
-			case 1:
439
-				$replace = array('%1$s');
440
-				break;
441
-			case 2:
442
-				$replace = array('%1$s', '%2$s');
443
-				break;
444
-			case 3:
445
-				$replace = array('%1$s', '%2$s', '%3$s');
446
-				break;
447
-			case 4:
448
-				$replace = array('%1$s', '%2$s', '%3$s', '%4$s');
449
-				break;
450
-			case 5:
451
-				$replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s');
452
-				break;
453
-			default:
454
-				$replace = range(1, count($textes));
455
-				$replace = '%' . implode('$s,%', $replace) . '$s';
456
-				$replace = explode(',', $replace);
457
-				break;
458
-		}
459
-		$query = str_replace($textes, $replace, $query);
460
-	} else {
461
-		$textes = array();
462
-	}
463
-
464
-	return array($query, $textes);
430
+    static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
431
+    $query = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query);
432
+    if (preg_match_all("/((['])[^']*(\\2))|(([\"])[^\"]*(\\5))/S", $query, $textes)) {
433
+        $textes = reset($textes); // indice 0 du match
434
+        switch (count($textes)) {
435
+            case 0:
436
+                $replace = array();
437
+                break;
438
+            case 1:
439
+                $replace = array('%1$s');
440
+                break;
441
+            case 2:
442
+                $replace = array('%1$s', '%2$s');
443
+                break;
444
+            case 3:
445
+                $replace = array('%1$s', '%2$s', '%3$s');
446
+                break;
447
+            case 4:
448
+                $replace = array('%1$s', '%2$s', '%3$s', '%4$s');
449
+                break;
450
+            case 5:
451
+                $replace = array('%1$s', '%2$s', '%3$s', '%4$s', '%5$s');
452
+                break;
453
+            default:
454
+                $replace = range(1, count($textes));
455
+                $replace = '%' . implode('$s,%', $replace) . '$s';
456
+                $replace = explode(',', $replace);
457
+                break;
458
+        }
459
+        $query = str_replace($textes, $replace, $query);
460
+    } else {
461
+        $textes = array();
462
+    }
463
+
464
+    return array($query, $textes);
465 465
 }
466 466
 
467 467
 /**
@@ -475,40 +475,40 @@  discard block
 block discarded – undo
475 475
  * @return string
476 476
  */
477 477
 function query_reinjecte_textes($query, $textes) {
478
-	static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
479
-	# debug de la substitution
480
-	#if (($c1=substr_count($query,"%"))!=($c2=count($textes))){
481
-	#	spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR);
482
-	#	spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR);
483
-	#	spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR);
484
-	#}
485
-	switch (count($textes)) {
486
-		case 0:
487
-			break;
488
-		case 1:
489
-			$query = sprintf($query, $textes[0]);
490
-			break;
491
-		case 2:
492
-			$query = sprintf($query, $textes[0], $textes[1]);
493
-			break;
494
-		case 3:
495
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2]);
496
-			break;
497
-		case 4:
498
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]);
499
-			break;
500
-		case 5:
501
-			$query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]);
502
-			break;
503
-		default:
504
-			array_unshift($textes, $query);
505
-			$query = call_user_func_array('sprintf', $textes);
506
-			break;
507
-	}
508
-
509
-	$query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
510
-
511
-	return $query;
478
+    static $codeEchappements = array("''" => "\x1@##@\x1", "\'" => "\x2@##@\x2", "\\\"" => "\x3@##@\x3");
479
+    # debug de la substitution
480
+    #if (($c1=substr_count($query,"%"))!=($c2=count($textes))){
481
+    #	spip_log("$c1 ::". $query,"tradquery"._LOG_ERREUR);
482
+    #	spip_log("$c2 ::". var_export($textes,1),"tradquery"._LOG_ERREUR);
483
+    #	spip_log("ini ::". $qi,"tradquery"._LOG_ERREUR);
484
+    #}
485
+    switch (count($textes)) {
486
+        case 0:
487
+            break;
488
+        case 1:
489
+            $query = sprintf($query, $textes[0]);
490
+            break;
491
+        case 2:
492
+            $query = sprintf($query, $textes[0], $textes[1]);
493
+            break;
494
+        case 3:
495
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2]);
496
+            break;
497
+        case 4:
498
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3]);
499
+            break;
500
+        case 5:
501
+            $query = sprintf($query, $textes[0], $textes[1], $textes[2], $textes[3], $textes[4]);
502
+            break;
503
+        default:
504
+            array_unshift($textes, $query);
505
+            $query = call_user_func_array('sprintf', $textes);
506
+            break;
507
+    }
508
+
509
+    $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query);
510
+
511
+    return $query;
512 512
 }
513 513
 
514 514
 
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
  **/
528 528
 function spip_query($query, $serveur = '') {
529 529
 
530
-	$f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
530
+    $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true);
531 531
 
532
-	return function_exists($f) ? $f($query, $serveur) : false;
532
+    return function_exists($f) ? $f($query, $serveur) : false;
533 533
 }
Please login to merge, or discard this patch.
ecrire/inc/headers.php 1 patch
Indentation   +145 added lines, -145 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
 
@@ -38,122 +38,122 @@  discard block
 block discarded – undo
38 38
  * @param int $status Code de redirection (301 ou 302)
39 39
  **/
40 40
 function redirige_par_entete($url, $equiv = '', $status = 302) {
41
-	if (!in_array($status, array(301, 302))) {
42
-		$status = 302;
43
-	}
44
-
45
-	$url = trim(strtr($url, "\n\r", "  "));
46
-	# si l'url de redirection est relative, on la passe en absolue
47
-	if (!preg_match(",^(\w+:)?//,", $url)) {
48
-		include_spip("inc/filtres_mini");
49
-		$url = url_absolue($url);
50
-	}
51
-
52
-	if (defined('_AJAX') and _AJAX) {
53
-		$url = parametre_url($url, 'var_ajax_redir', 1, '&');
54
-	}
55
-
56
-	// ne pas laisser passer n'importe quoi dans l'url
57
-	$url = str_replace(array('<', '"'), array('&lt;', '&quot;'), $url);
58
-	$url = str_replace(array("\r", "\n", ' '), array('%0D', '%0A', '%20'), $url);
59
-	while (strpos($url, '%0A') !== false) {
60
-		$url = str_replace('%0A', '', $url);
61
-	}
62
-	// interdire les url inline avec des pseudo-protocoles :
63
-	if (
64
-		(preg_match(",data:,i", $url) and preg_match("/base64\s*,/i", $url))
65
-		or preg_match(",(javascript|mailto):,i", $url)
66
-	) {
67
-		$url = "./";
68
-	}
69
-
70
-	// Il n'y a que sous Apache que setcookie puis redirection fonctionne
71
-	include_spip('inc/cookie');
72
-	if ((!$equiv and !spip_cookie_envoye()) or (
73
-			   (strncmp("Apache", $_SERVER['SERVER_SOFTWARE'], 6) == 0)
74
-			or (isset($_SERVER['SERVER_SIGNATURE']) and stripos($_SERVER['SERVER_SIGNATURE'], 'Apache') !== false)
75
-			or function_exists('apache_getenv')
76
-			or defined('_SERVER_APACHE')
77
-		)
78
-	) {
79
-		@header("Location: " . $url);
80
-		$equiv = "";
81
-	} else {
82
-		@header("Refresh: 0; url=" . $url);
83
-		if (isset($GLOBALS['meta']['charset'])) {
84
-			@header("Content-Type: text/html; charset=" . $GLOBALS['meta']['charset']);
85
-		}
86
-		$equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
87
-	}
88
-	include_spip('inc/lang');
89
-	if ($status != 302) {
90
-		http_status($status);
91
-	}
92
-	echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
93
-	html_lang_attributes(), '
41
+    if (!in_array($status, array(301, 302))) {
42
+        $status = 302;
43
+    }
44
+
45
+    $url = trim(strtr($url, "\n\r", "  "));
46
+    # si l'url de redirection est relative, on la passe en absolue
47
+    if (!preg_match(",^(\w+:)?//,", $url)) {
48
+        include_spip("inc/filtres_mini");
49
+        $url = url_absolue($url);
50
+    }
51
+
52
+    if (defined('_AJAX') and _AJAX) {
53
+        $url = parametre_url($url, 'var_ajax_redir', 1, '&');
54
+    }
55
+
56
+    // ne pas laisser passer n'importe quoi dans l'url
57
+    $url = str_replace(array('<', '"'), array('&lt;', '&quot;'), $url);
58
+    $url = str_replace(array("\r", "\n", ' '), array('%0D', '%0A', '%20'), $url);
59
+    while (strpos($url, '%0A') !== false) {
60
+        $url = str_replace('%0A', '', $url);
61
+    }
62
+    // interdire les url inline avec des pseudo-protocoles :
63
+    if (
64
+        (preg_match(",data:,i", $url) and preg_match("/base64\s*,/i", $url))
65
+        or preg_match(",(javascript|mailto):,i", $url)
66
+    ) {
67
+        $url = "./";
68
+    }
69
+
70
+    // Il n'y a que sous Apache que setcookie puis redirection fonctionne
71
+    include_spip('inc/cookie');
72
+    if ((!$equiv and !spip_cookie_envoye()) or (
73
+                (strncmp("Apache", $_SERVER['SERVER_SOFTWARE'], 6) == 0)
74
+            or (isset($_SERVER['SERVER_SIGNATURE']) and stripos($_SERVER['SERVER_SIGNATURE'], 'Apache') !== false)
75
+            or function_exists('apache_getenv')
76
+            or defined('_SERVER_APACHE')
77
+        )
78
+    ) {
79
+        @header("Location: " . $url);
80
+        $equiv = "";
81
+    } else {
82
+        @header("Refresh: 0; url=" . $url);
83
+        if (isset($GLOBALS['meta']['charset'])) {
84
+            @header("Content-Type: text/html; charset=" . $GLOBALS['meta']['charset']);
85
+        }
86
+        $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>";
87
+    }
88
+    include_spip('inc/lang');
89
+    if ($status != 302) {
90
+        http_status($status);
91
+    }
92
+    echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n",
93
+    html_lang_attributes(), '
94 94
 <head>',
95
-	$equiv, '
95
+    $equiv, '
96 96
 <title>HTTP ' . $status . '</title>
97 97
 ' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . '
98 98
 </head>
99 99
 <body>
100 100
 <h1>HTTP ' . $status . '</h1>
101 101
 <a href="',
102
-	quote_amp($url),
103
-	'">',
104
-	_T('navigateur_pas_redirige'),
105
-	'</a></body></html>';
102
+    quote_amp($url),
103
+    '">',
104
+    _T('navigateur_pas_redirige'),
105
+    '</a></body></html>';
106 106
 
107
-	spip_log("redirige $status: $url");
107
+    spip_log("redirige $status: $url");
108 108
 
109
-	exit;
109
+    exit;
110 110
 }
111 111
 
112 112
 // http://code.spip.net/@redirige_formulaire
113 113
 function redirige_formulaire($url, $equiv = '', $format = 'message') {
114
-	if (!_AJAX
115
-		and !headers_sent()
116
-		and !_request('var_ajax')
117
-	) {
118
-		redirige_par_entete(str_replace('&amp;', '&', $url), $equiv);
119
-	} // si c'est une ancre, fixer simplement le window.location.hash
120
-	elseif ($format == 'ajaxform' and preg_match(',^#[0-9a-z\-_]+$,i', $url)) {
121
-		return array(
122
-			// on renvoie un lien masque qui sera traite par ajaxCallback.js
123
-			"<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
124
-			// et rien dans le message ok
125
-			''
126
-		);
127
-	} else {
128
-		// ne pas laisser passer n'importe quoi dans l'url
129
-		$url = str_replace(array('<', '"'), array('&lt;', '&quot;'), $url);
130
-
131
-		$url = strtr($url, "\n\r", "  ");
132
-		# en theorie on devrait faire ca tout le temps, mais quand la chaine
133
-		# commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
134
-		if ($url[0] == '?') {
135
-			$url = url_de_base() . $url;
136
-		}
137
-		$url = str_replace('&amp;', '&', $url);
138
-		spip_log("redirige formulaire ajax: $url");
139
-		include_spip('inc/filtres');
140
-		if ($format == 'ajaxform') {
141
-			return array(
142
-				// on renvoie un lien masque qui sera traite par ajaxCallback.js
143
-				'<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
144
-				// et un message au cas ou
145
-				'<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
146
-			);
147
-		} else // format message texte, tout en js inline
148
-		{
149
-			return
150
-				// ie poste les formulaires dans une iframe, il faut donc rediriger son parent
151
-				"<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
152
-				. http_img_pack('searching.gif', '')
153
-				. '<br />'
154
-				. '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
155
-		}
156
-	}
114
+    if (!_AJAX
115
+        and !headers_sent()
116
+        and !_request('var_ajax')
117
+    ) {
118
+        redirige_par_entete(str_replace('&amp;', '&', $url), $equiv);
119
+    } // si c'est une ancre, fixer simplement le window.location.hash
120
+    elseif ($format == 'ajaxform' and preg_match(',^#[0-9a-z\-_]+$,i', $url)) {
121
+        return array(
122
+            // on renvoie un lien masque qui sera traite par ajaxCallback.js
123
+            "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>",
124
+            // et rien dans le message ok
125
+            ''
126
+        );
127
+    } else {
128
+        // ne pas laisser passer n'importe quoi dans l'url
129
+        $url = str_replace(array('<', '"'), array('&lt;', '&quot;'), $url);
130
+
131
+        $url = strtr($url, "\n\r", "  ");
132
+        # en theorie on devrait faire ca tout le temps, mais quand la chaine
133
+        # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne
134
+        if ($url[0] == '?') {
135
+            $url = url_de_base() . $url;
136
+        }
137
+        $url = str_replace('&amp;', '&', $url);
138
+        spip_log("redirige formulaire ajax: $url");
139
+        include_spip('inc/filtres');
140
+        if ($format == 'ajaxform') {
141
+            return array(
142
+                // on renvoie un lien masque qui sera traite par ajaxCallback.js
143
+                '<a href="' . quote_amp($url) . '" name="ajax_redirect"  style="display:none;">' . _T('navigateur_pas_redirige') . '</a>',
144
+                // et un message au cas ou
145
+                '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'
146
+            );
147
+        } else // format message texte, tout en js inline
148
+        {
149
+            return
150
+                // ie poste les formulaires dans une iframe, il faut donc rediriger son parent
151
+                "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>"
152
+                . http_img_pack('searching.gif', '')
153
+                . '<br />'
154
+                . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>';
155
+        }
156
+    }
157 157
 }
158 158
 
159 159
 /**
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
  * @return void
175 175
  **/
176 176
 function redirige_url_ecrire($script = '', $args = '', $equiv = '') {
177
-	return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
177
+    return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv);
178 178
 }
179 179
 
180 180
 /**
@@ -189,49 +189,49 @@  discard block
 block discarded – undo
189 189
  **/
190 190
 function http_status($status) {
191 191
 
192
-	static $status_string = array(
193
-		200 => '200 OK',
194
-		204 => '204 No Content',
195
-		301 => '301 Moved Permanently',
196
-		302 => '302 Found',
197
-		304 => '304 Not Modified',
198
-		401 => '401 Unauthorized',
199
-		403 => '403 Forbidden',
200
-		404 => '404 Not Found',
201
-		503 => '503 Service Unavailable'
202
-	);
203
-
204
-	if (!empty($GLOBALS['REDIRECT_STATUS']) && $GLOBALS['REDIRECT_STATUS'] == $status) {
205
-		return;
206
-	}
207
-
208
-	$php_cgi = ($GLOBALS['flag_sapi_name'] and preg_match(",cgi,i", @php_sapi_name()));
209
-	if ($php_cgi) {
210
-		header("Status: " . $status_string[$status]);
211
-	} else {
212
-		header("HTTP/1.0 " . $status_string[$status]);
213
-	}
192
+    static $status_string = array(
193
+        200 => '200 OK',
194
+        204 => '204 No Content',
195
+        301 => '301 Moved Permanently',
196
+        302 => '302 Found',
197
+        304 => '304 Not Modified',
198
+        401 => '401 Unauthorized',
199
+        403 => '403 Forbidden',
200
+        404 => '404 Not Found',
201
+        503 => '503 Service Unavailable'
202
+    );
203
+
204
+    if (!empty($GLOBALS['REDIRECT_STATUS']) && $GLOBALS['REDIRECT_STATUS'] == $status) {
205
+        return;
206
+    }
207
+
208
+    $php_cgi = ($GLOBALS['flag_sapi_name'] and preg_match(",cgi,i", @php_sapi_name()));
209
+    if ($php_cgi) {
210
+        header("Status: " . $status_string[$status]);
211
+    } else {
212
+        header("HTTP/1.0 " . $status_string[$status]);
213
+    }
214 214
 }
215 215
 
216 216
 // Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache
217 217
 // http://code.spip.net/@http_no_cache
218 218
 function http_no_cache() {
219
-	if (headers_sent()) {
220
-		spip_log("http_no_cache arrive trop tard");
221
-
222
-		return;
223
-	}
224
-	$charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
225
-
226
-	// selon http://developer.apple.com/internet/safari/faq.html#anchor5
227
-	// il faudrait aussi pour Safari
228
-	// header("Cache-Control: post-check=0, pre-check=0", false)
229
-	// mais ca ne respecte pas
230
-	// http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
231
-
232
-	header("Content-Type: text/html; charset=$charset");
233
-	header("Expires: 0");
234
-	header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
235
-	header("Cache-Control: no-cache, must-revalidate");
236
-	header("Pragma: no-cache");
219
+    if (headers_sent()) {
220
+        spip_log("http_no_cache arrive trop tard");
221
+
222
+        return;
223
+    }
224
+    $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset'];
225
+
226
+    // selon http://developer.apple.com/internet/safari/faq.html#anchor5
227
+    // il faudrait aussi pour Safari
228
+    // header("Cache-Control: post-check=0, pre-check=0", false)
229
+    // mais ca ne respecte pas
230
+    // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
231
+
232
+    header("Content-Type: text/html; charset=$charset");
233
+    header("Expires: 0");
234
+    header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
235
+    header("Cache-Control: no-cache, must-revalidate");
236
+    header("Pragma: no-cache");
237 237
 }
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 1 patch
Indentation   +703 added lines, -703 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // securité
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 // se faciliter la lecture du charset
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
44 44
 function load_charset($charset = 'AUTO') {
45
-	if ($charset == 'AUTO') {
46
-		$charset = $GLOBALS['meta']['charset'];
47
-	}
48
-	$charset = trim(strtolower($charset));
49
-	if (isset($GLOBALS['CHARSET'][$charset])) {
50
-		return $charset;
51
-	}
52
-
53
-	if ($charset == 'utf-8') {
54
-		$GLOBALS['CHARSET'][$charset] = array();
55
-
56
-		return $charset;
57
-	}
58
-
59
-	// Quelques synonymes
60
-	if ($charset == '') {
61
-		$charset = 'iso-8859-1';
62
-	} else {
63
-		if ($charset == 'windows-1250') {
64
-			$charset = 'cp1250';
65
-		} else {
66
-			if ($charset == 'windows-1251') {
67
-				$charset = 'cp1251';
68
-			} else {
69
-				if ($charset == 'windows-1256') {
70
-					$charset = 'cp1256';
71
-				}
72
-			}
73
-		}
74
-	}
75
-
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
77
-		return $charset;
78
-	} else {
79
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
-		$GLOBALS['CHARSET'][$charset] = array();
81
-
82
-		return false;
83
-	}
45
+    if ($charset == 'AUTO') {
46
+        $charset = $GLOBALS['meta']['charset'];
47
+    }
48
+    $charset = trim(strtolower($charset));
49
+    if (isset($GLOBALS['CHARSET'][$charset])) {
50
+        return $charset;
51
+    }
52
+
53
+    if ($charset == 'utf-8') {
54
+        $GLOBALS['CHARSET'][$charset] = array();
55
+
56
+        return $charset;
57
+    }
58
+
59
+    // Quelques synonymes
60
+    if ($charset == '') {
61
+        $charset = 'iso-8859-1';
62
+    } else {
63
+        if ($charset == 'windows-1250') {
64
+            $charset = 'cp1250';
65
+        } else {
66
+            if ($charset == 'windows-1251') {
67
+                $charset = 'cp1251';
68
+            } else {
69
+                if ($charset == 'windows-1256') {
70
+                    $charset = 'cp1256';
71
+                }
72
+            }
73
+        }
74
+    }
75
+
76
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
77
+        return $charset;
78
+    } else {
79
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
+        $GLOBALS['CHARSET'][$charset] = array();
81
+
82
+        return false;
83
+    }
84 84
 }
85 85
 
86 86
 
@@ -91,30 +91,30 @@  discard block
 block discarded – undo
91 91
  *     true si toutes les fonctions mb nécessaires sont présentes
92 92
  **/
93 93
 function init_mb_string() {
94
-	static $mb;
95
-
96
-	// verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
-	// et que le charset interne est connu de mb_string
98
-	if (!$mb) {
99
-		if (function_exists('mb_internal_encoding')
100
-			and function_exists('mb_detect_order')
101
-			and function_exists('mb_substr')
102
-			and function_exists('mb_strlen')
103
-			and function_exists('mb_strtolower')
104
-			and function_exists('mb_strtoupper')
105
-			and function_exists('mb_encode_mimeheader')
106
-			and function_exists('mb_encode_numericentity')
107
-			and function_exists('mb_decode_numericentity')
108
-			and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
109
-		) {
110
-			mb_internal_encoding('utf-8');
111
-			$mb = 1;
112
-		} else {
113
-			$mb = -1;
114
-		}
115
-	}
116
-
117
-	return ($mb == 1);
94
+    static $mb;
95
+
96
+    // verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
+    // et que le charset interne est connu de mb_string
98
+    if (!$mb) {
99
+        if (function_exists('mb_internal_encoding')
100
+            and function_exists('mb_detect_order')
101
+            and function_exists('mb_substr')
102
+            and function_exists('mb_strlen')
103
+            and function_exists('mb_strtolower')
104
+            and function_exists('mb_strtoupper')
105
+            and function_exists('mb_encode_mimeheader')
106
+            and function_exists('mb_encode_numericentity')
107
+            and function_exists('mb_decode_numericentity')
108
+            and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
109
+        ) {
110
+            mb_internal_encoding('utf-8');
111
+            $mb = 1;
112
+        } else {
113
+            $mb = -1;
114
+        }
115
+    }
116
+
117
+    return ($mb == 1);
118 118
 }
119 119
 
120 120
 /**
@@ -129,21 +129,21 @@  discard block
 block discarded – undo
129 129
  *     true si iconv fonctionne correctement
130 130
  **/
131 131
 function test_iconv() {
132
-	static $iconv_ok;
133
-
134
-	if (!$iconv_ok) {
135
-		if (!function_exists('iconv')) {
136
-			$iconv_ok = -1;
137
-		} else {
138
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
139
-				$iconv_ok = 1;
140
-			} else {
141
-				$iconv_ok = -1;
142
-			}
143
-		}
144
-	}
145
-
146
-	return ($iconv_ok == 1);
132
+    static $iconv_ok;
133
+
134
+    if (!$iconv_ok) {
135
+        if (!function_exists('iconv')) {
136
+            $iconv_ok = -1;
137
+        } else {
138
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
139
+                $iconv_ok = 1;
140
+            } else {
141
+                $iconv_ok = -1;
142
+            }
143
+        }
144
+    }
145
+
146
+    return ($iconv_ok == 1);
147 147
 }
148 148
 
149 149
 
@@ -156,18 +156,18 @@  discard block
 block discarded – undo
156 156
  *     true si PCRE supporte l'UTF-8 correctement
157 157
  **/
158 158
 function test_pcre_unicode() {
159
-	static $pcre_ok = 0;
160
-
161
-	if (!$pcre_ok) {
162
-		$s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
163
-		if (preg_match(',\W...\W,u', $s)) {
164
-			$pcre_ok = 1;
165
-		} else {
166
-			$pcre_ok = -1;
167
-		}
168
-	}
169
-
170
-	return $pcre_ok == 1;
159
+    static $pcre_ok = 0;
160
+
161
+    if (!$pcre_ok) {
162
+        $s = " " . chr(195) . chr(169) . "t" . chr(195) . chr(169) . " ";
163
+        if (preg_match(',\W...\W,u', $s)) {
164
+            $pcre_ok = 1;
165
+        } else {
166
+            $pcre_ok = -1;
167
+        }
168
+    }
169
+
170
+    return $pcre_ok == 1;
171 171
 }
172 172
 
173 173
 /**
@@ -183,22 +183,22 @@  discard block
 block discarded – undo
183 183
  *    Plage de caractères
184 184
  **/
185 185
 function pcre_lettres_unicode() {
186
-	static $plage_unicode;
187
-
188
-	if (!$plage_unicode) {
189
-		if (test_pcre_unicode()) {
190
-			// cf. http://www.unicode.org/charts/
191
-			$plage_unicode = '\w' // iso-latin
192
-				. '\x{100}-\x{24f}' // europeen etendu
193
-				. '\x{300}-\x{1cff}' // des tas de trucs
194
-			;
195
-		} else {
196
-			// fallback a trois sous
197
-			$plage_unicode = '\w';
198
-		}
199
-	}
200
-
201
-	return $plage_unicode;
186
+    static $plage_unicode;
187
+
188
+    if (!$plage_unicode) {
189
+        if (test_pcre_unicode()) {
190
+            // cf. http://www.unicode.org/charts/
191
+            $plage_unicode = '\w' // iso-latin
192
+                . '\x{100}-\x{24f}' // europeen etendu
193
+                . '\x{300}-\x{1cff}' // des tas de trucs
194
+            ;
195
+        } else {
196
+            // fallback a trois sous
197
+            $plage_unicode = '\w';
198
+        }
199
+    }
200
+
201
+    return $plage_unicode;
202 202
 }
203 203
 
204 204
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
  *    Plage de caractères
217 217
  **/
218 218
 function plage_punct_unicode() {
219
-	return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
219
+    return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
220 220
 }
221 221
 
222 222
 /**
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
  *     Texte corrigé
237 237
  **/
238 238
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
239
-	static $trans;
240
-
241
-	if (is_array($texte)) {
242
-		return array_map('corriger_caracteres_windows', $texte);
243
-	}
244
-
245
-	if ($charset == 'AUTO') {
246
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
247
-	}
248
-	if ($charset == 'utf-8') {
249
-		$p = chr(194);
250
-		if (strpos($texte, $p) == false) {
251
-			return $texte;
252
-		}
253
-	} else {
254
-		if ($charset == 'iso-8859-1') {
255
-			$p = '';
256
-		} else {
257
-			return $texte;
258
-		}
259
-	}
260
-
261
-	if (!isset($trans[$charset][$charset_cible])) {
262
-		$trans[$charset][$charset_cible] = array(
263
-			$p . chr(128) => "&#8364;",
264
-			$p . chr(129) => ' ', # pas affecte
265
-			$p . chr(130) => "&#8218;",
266
-			$p . chr(131) => "&#402;",
267
-			$p . chr(132) => "&#8222;",
268
-			$p . chr(133) => "&#8230;",
269
-			$p . chr(134) => "&#8224;",
270
-			$p . chr(135) => "&#8225;",
271
-			$p . chr(136) => "&#710;",
272
-			$p . chr(137) => "&#8240;",
273
-			$p . chr(138) => "&#352;",
274
-			$p . chr(139) => "&#8249;",
275
-			$p . chr(140) => "&#338;",
276
-			$p . chr(141) => ' ', # pas affecte
277
-			$p . chr(142) => "&#381;",
278
-			$p . chr(143) => ' ', # pas affecte
279
-			$p . chr(144) => ' ', # pas affecte
280
-			$p . chr(145) => "&#8216;",
281
-			$p . chr(146) => "&#8217;",
282
-			$p . chr(147) => "&#8220;",
283
-			$p . chr(148) => "&#8221;",
284
-			$p . chr(149) => "&#8226;",
285
-			$p . chr(150) => "&#8211;",
286
-			$p . chr(151) => "&#8212;",
287
-			$p . chr(152) => "&#732;",
288
-			$p . chr(153) => "&#8482;",
289
-			$p . chr(154) => "&#353;",
290
-			$p . chr(155) => "&#8250;",
291
-			$p . chr(156) => "&#339;",
292
-			$p . chr(157) => ' ', # pas affecte
293
-			$p . chr(158) => "&#382;",
294
-			$p . chr(159) => "&#376;",
295
-		);
296
-		if ($charset_cible != 'unicode') {
297
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
298
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
299
-			}
300
-		}
301
-	}
302
-
303
-	return @str_replace(array_keys($trans[$charset][$charset_cible]),
304
-		array_values($trans[$charset][$charset_cible]), $texte);
239
+    static $trans;
240
+
241
+    if (is_array($texte)) {
242
+        return array_map('corriger_caracteres_windows', $texte);
243
+    }
244
+
245
+    if ($charset == 'AUTO') {
246
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
247
+    }
248
+    if ($charset == 'utf-8') {
249
+        $p = chr(194);
250
+        if (strpos($texte, $p) == false) {
251
+            return $texte;
252
+        }
253
+    } else {
254
+        if ($charset == 'iso-8859-1') {
255
+            $p = '';
256
+        } else {
257
+            return $texte;
258
+        }
259
+    }
260
+
261
+    if (!isset($trans[$charset][$charset_cible])) {
262
+        $trans[$charset][$charset_cible] = array(
263
+            $p . chr(128) => "&#8364;",
264
+            $p . chr(129) => ' ', # pas affecte
265
+            $p . chr(130) => "&#8218;",
266
+            $p . chr(131) => "&#402;",
267
+            $p . chr(132) => "&#8222;",
268
+            $p . chr(133) => "&#8230;",
269
+            $p . chr(134) => "&#8224;",
270
+            $p . chr(135) => "&#8225;",
271
+            $p . chr(136) => "&#710;",
272
+            $p . chr(137) => "&#8240;",
273
+            $p . chr(138) => "&#352;",
274
+            $p . chr(139) => "&#8249;",
275
+            $p . chr(140) => "&#338;",
276
+            $p . chr(141) => ' ', # pas affecte
277
+            $p . chr(142) => "&#381;",
278
+            $p . chr(143) => ' ', # pas affecte
279
+            $p . chr(144) => ' ', # pas affecte
280
+            $p . chr(145) => "&#8216;",
281
+            $p . chr(146) => "&#8217;",
282
+            $p . chr(147) => "&#8220;",
283
+            $p . chr(148) => "&#8221;",
284
+            $p . chr(149) => "&#8226;",
285
+            $p . chr(150) => "&#8211;",
286
+            $p . chr(151) => "&#8212;",
287
+            $p . chr(152) => "&#732;",
288
+            $p . chr(153) => "&#8482;",
289
+            $p . chr(154) => "&#353;",
290
+            $p . chr(155) => "&#8250;",
291
+            $p . chr(156) => "&#339;",
292
+            $p . chr(157) => ' ', # pas affecte
293
+            $p . chr(158) => "&#382;",
294
+            $p . chr(159) => "&#376;",
295
+        );
296
+        if ($charset_cible != 'unicode') {
297
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
298
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
299
+            }
300
+        }
301
+    }
302
+
303
+    return @str_replace(array_keys($trans[$charset][$charset_cible]),
304
+        array_values($trans[$charset][$charset_cible]), $texte);
305 305
 }
306 306
 
307 307
 
@@ -318,24 +318,24 @@  discard block
 block discarded – undo
318 318
  *     Texte converti
319 319
  **/
320 320
 function html2unicode($texte, $secure = false) {
321
-	if (strpos($texte, '&') === false) {
322
-		return $texte;
323
-	}
324
-	static $trans = array();
325
-	if (!$trans) {
326
-		load_charset('html');
327
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
328
-			$trans["&$key;"] = $val;
329
-		}
330
-	}
331
-
332
-	if ($secure) {
333
-		return str_replace(array_keys($trans), array_values($trans), $texte);
334
-	} else {
335
-		return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
336
-			str_replace(array_keys($trans), array_values($trans), $texte)
337
-		);
338
-	}
321
+    if (strpos($texte, '&') === false) {
322
+        return $texte;
323
+    }
324
+    static $trans = array();
325
+    if (!$trans) {
326
+        load_charset('html');
327
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
328
+            $trans["&$key;"] = $val;
329
+        }
330
+    }
331
+
332
+    if ($secure) {
333
+        return str_replace(array_keys($trans), array_values($trans), $texte);
334
+    } else {
335
+        return str_replace(array('&amp;', '&quot;', '&lt;', '&gt;'), array('&', '"', '<', '>'),
336
+            str_replace(array_keys($trans), array_values($trans), $texte)
337
+        );
338
+    }
339 339
 }
340 340
 
341 341
 
@@ -350,16 +350,16 @@  discard block
 block discarded – undo
350 350
  *     Texte converti
351 351
  **/
352 352
 function mathml2unicode($texte) {
353
-	static $trans;
354
-	if (!$trans) {
355
-		load_charset('mathml');
353
+    static $trans;
354
+    if (!$trans) {
355
+        load_charset('mathml');
356 356
 
357
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
358
-			$trans["&$key;"] = $val;
359
-		}
360
-	}
357
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
358
+            $trans["&$key;"] = $val;
359
+        }
360
+    }
361 361
 
362
-	return str_replace(array_keys($trans), array_values($trans), $texte);
362
+    return str_replace(array_keys($trans), array_values($trans), $texte);
363 363
 }
364 364
 
365 365
 
@@ -381,69 +381,69 @@  discard block
 block discarded – undo
381 381
  *     Texte converti en unicode
382 382
  **/
383 383
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
384
-	static $trans;
385
-
386
-	if ($charset == 'AUTO') {
387
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
388
-	}
389
-
390
-	if ($charset == '') {
391
-		$charset = 'iso-8859-1';
392
-	}
393
-	$charset = strtolower($charset);
394
-
395
-	switch ($charset) {
396
-		case 'utf-8':
397
-		case 'utf8':
398
-			return utf_8_to_unicode($texte);
399
-
400
-		case 'iso-8859-1':
401
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
402
-		// pas de break; ici, on suit sur default:
403
-
404
-		default:
405
-			// mbstring presente ?
406
-			if (init_mb_string()) {
407
-				if ($order = mb_detect_order() # mb_string connait-il $charset?
408
-					and mb_detect_order($charset)
409
-				) {
410
-					$s = mb_convert_encoding($texte, 'utf-8', $charset);
411
-					if ($s && $s != $texte) {
412
-						return utf_8_to_unicode($s);
413
-					}
414
-				}
415
-				mb_detect_order($order); # remettre comme precedemment
416
-			}
417
-
418
-			// Sinon, peut-etre connaissons-nous ce charset ?
419
-			if (!isset($trans[$charset])) {
420
-				if ($cset = load_charset($charset)
421
-					and is_array($GLOBALS['CHARSET'][$cset])
422
-				) {
423
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
425
-					}
426
-				}
427
-			}
428
-			if (count($trans[$charset])) {
429
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
430
-			}
431
-
432
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
433
-			// caractere n'appartient pas au charset, mais c'est un probleme
434
-			// surtout en utf-8, gere ci-dessus)
435
-			if (test_iconv()) {
436
-				$s = iconv($charset, 'utf-32le', $texte);
437
-				if ($s) {
438
-					return utf_32_to_unicode($s);
439
-				}
440
-			}
441
-
442
-			// Au pire ne rien faire
443
-			spip_log("erreur charset '$charset' non supporte");
444
-
445
-			return $texte;
446
-	}
384
+    static $trans;
385
+
386
+    if ($charset == 'AUTO') {
387
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
388
+    }
389
+
390
+    if ($charset == '') {
391
+        $charset = 'iso-8859-1';
392
+    }
393
+    $charset = strtolower($charset);
394
+
395
+    switch ($charset) {
396
+        case 'utf-8':
397
+        case 'utf8':
398
+            return utf_8_to_unicode($texte);
399
+
400
+        case 'iso-8859-1':
401
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
402
+        // pas de break; ici, on suit sur default:
403
+
404
+        default:
405
+            // mbstring presente ?
406
+            if (init_mb_string()) {
407
+                if ($order = mb_detect_order() # mb_string connait-il $charset?
408
+                    and mb_detect_order($charset)
409
+                ) {
410
+                    $s = mb_convert_encoding($texte, 'utf-8', $charset);
411
+                    if ($s && $s != $texte) {
412
+                        return utf_8_to_unicode($s);
413
+                    }
414
+                }
415
+                mb_detect_order($order); # remettre comme precedemment
416
+            }
417
+
418
+            // Sinon, peut-etre connaissons-nous ce charset ?
419
+            if (!isset($trans[$charset])) {
420
+                if ($cset = load_charset($charset)
421
+                    and is_array($GLOBALS['CHARSET'][$cset])
422
+                ) {
423
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
424
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
425
+                    }
426
+                }
427
+            }
428
+            if (count($trans[$charset])) {
429
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
430
+            }
431
+
432
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
433
+            // caractere n'appartient pas au charset, mais c'est un probleme
434
+            // surtout en utf-8, gere ci-dessus)
435
+            if (test_iconv()) {
436
+                $s = iconv($charset, 'utf-32le', $texte);
437
+                if ($s) {
438
+                    return utf_32_to_unicode($s);
439
+                }
440
+            }
441
+
442
+            // Au pire ne rien faire
443
+            spip_log("erreur charset '$charset' non supporte");
444
+
445
+            return $texte;
446
+    }
447 447
 }
448 448
 
449 449
 
@@ -462,44 +462,44 @@  discard block
 block discarded – undo
462 462
  *     Texte transformé dans le charset souhaité
463 463
  **/
464 464
 function unicode2charset($texte, $charset = 'AUTO') {
465
-	static $CHARSET_REVERSE = array();
466
-	static $trans = array();
467
-
468
-	if ($charset == 'AUTO') {
469
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
470
-	}
471
-
472
-	switch ($charset) {
473
-		case 'utf-8':
474
-			return unicode_to_utf_8($texte);
475
-			break;
476
-
477
-		default:
478
-			$charset = load_charset($charset);
479
-
480
-			if (empty($CHARSET_REVERSE[$charset])) {
481
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
482
-			}
483
-
484
-			if (!isset($trans[$charset])) {
485
-				$trans[$charset] = array();
486
-				$t = &$trans[$charset];
487
-				for ($e = 128; $e < 255; $e++) {
488
-					$h = dechex($e);
489
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
490
-						$s = $CHARSET_REVERSE[$charset][$e];
491
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
492
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
493
-					} else {
494
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
495
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
496
-					}
497
-				}
498
-			}
499
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
500
-
501
-			return $texte;
502
-	}
465
+    static $CHARSET_REVERSE = array();
466
+    static $trans = array();
467
+
468
+    if ($charset == 'AUTO') {
469
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
470
+    }
471
+
472
+    switch ($charset) {
473
+        case 'utf-8':
474
+            return unicode_to_utf_8($texte);
475
+            break;
476
+
477
+        default:
478
+            $charset = load_charset($charset);
479
+
480
+            if (empty($CHARSET_REVERSE[$charset])) {
481
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
482
+            }
483
+
484
+            if (!isset($trans[$charset])) {
485
+                $trans[$charset] = array();
486
+                $t = &$trans[$charset];
487
+                for ($e = 128; $e < 255; $e++) {
488
+                    $h = dechex($e);
489
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
490
+                        $s = $CHARSET_REVERSE[$charset][$e];
491
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
492
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
493
+                    } else {
494
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
495
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
496
+                    }
497
+                }
498
+            }
499
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
500
+
501
+            return $texte;
502
+    }
503 503
 }
504 504
 
505 505
 
@@ -517,37 +517,37 @@  discard block
 block discarded – undo
517 517
  *     Texte transformé dans le charset site
518 518
  **/
519 519
 function importer_charset($texte, $charset = 'AUTO') {
520
-	static $trans = array();
521
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
522
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
523
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
524
-		if (init_mb_string()) {
525
-			if ($order = mb_detect_order() # mb_string connait-il $charset?
526
-				and mb_detect_order($charset)
527
-			) {
528
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
529
-			}
530
-			mb_detect_order($order); # remettre comme precedemment
531
-			return $s;
532
-		}
533
-		// Sinon, peut-etre connaissons-nous ce charset ?
534
-		if (!isset($trans[$charset])) {
535
-			if ($cset = load_charset($charset)
536
-				and is_array($GLOBALS['CHARSET'][$cset])
537
-			) {
538
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
540
-				}
541
-			}
542
-		}
543
-		if (count($trans[$charset])) {
544
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
545
-		}
546
-
547
-		return $texte;
548
-	}
549
-
550
-	return unicode2charset(charset2unicode($texte, $charset));
520
+    static $trans = array();
521
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
522
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
523
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
524
+        if (init_mb_string()) {
525
+            if ($order = mb_detect_order() # mb_string connait-il $charset?
526
+                and mb_detect_order($charset)
527
+            ) {
528
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
529
+            }
530
+            mb_detect_order($order); # remettre comme precedemment
531
+            return $s;
532
+        }
533
+        // Sinon, peut-etre connaissons-nous ce charset ?
534
+        if (!isset($trans[$charset])) {
535
+            if ($cset = load_charset($charset)
536
+                and is_array($GLOBALS['CHARSET'][$cset])
537
+            ) {
538
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
539
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
540
+                }
541
+            }
542
+        }
543
+        if (count($trans[$charset])) {
544
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
545
+        }
546
+
547
+        return $texte;
548
+    }
549
+
550
+    return unicode2charset(charset2unicode($texte, $charset));
551 551
 }
552 552
 
553 553
 
@@ -563,92 +563,92 @@  discard block
 block discarded – undo
563 563
  **/
564 564
 function utf_8_to_unicode($source) {
565 565
 
566
-	// mb_string : methode rapide
567
-	if (init_mb_string()) {
568
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
569
-
570
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
571
-	}
572
-
573
-	// Sinon methode pas a pas
574
-	static $decrement;
575
-	static $shift;
576
-
577
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
578
-	if (!is_array($decrement)) {
579
-		// array used to figure what number to decrement from character order value
580
-		// according to number of characters used to map unicode to ascii by utf-8
581
-		$decrement[4] = 240;
582
-		$decrement[3] = 224;
583
-		$decrement[2] = 192;
584
-		$decrement[1] = 0;
585
-		// the number of bits to shift each charNum by
586
-		$shift[1][0] = 0;
587
-		$shift[2][0] = 6;
588
-		$shift[2][1] = 0;
589
-		$shift[3][0] = 12;
590
-		$shift[3][1] = 6;
591
-		$shift[3][2] = 0;
592
-		$shift[4][0] = 18;
593
-		$shift[4][1] = 12;
594
-		$shift[4][2] = 6;
595
-		$shift[4][3] = 0;
596
-	}
597
-
598
-	$pos = 0;
599
-	$len = strlen($source);
600
-	$encodedString = '';
601
-	while ($pos < $len) {
602
-		$char = '';
603
-		$ischar = false;
604
-		$asciiPos = ord(substr($source, $pos, 1));
605
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
606
-			// 4 chars representing one unicode character
607
-			$thisLetter = substr($source, $pos, 4);
608
-			$pos += 4;
609
-		} else {
610
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
611
-				// 3 chars representing one unicode character
612
-				$thisLetter = substr($source, $pos, 3);
613
-				$pos += 3;
614
-			} else {
615
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
616
-					// 2 chars representing one unicode character
617
-					$thisLetter = substr($source, $pos, 2);
618
-					$pos += 2;
619
-				} else {
620
-					// 1 char (lower ascii)
621
-					$thisLetter = substr($source, $pos, 1);
622
-					$pos += 1;
623
-					$char = $thisLetter;
624
-					$ischar = true;
625
-				}
626
-			}
627
-		}
628
-
629
-		if ($ischar) {
630
-			$encodedString .= $char;
631
-		} else {  // process the string representing the letter to a unicode entity
632
-			$thisLen = strlen($thisLetter);
633
-			$thisPos = 0;
634
-			$decimalCode = 0;
635
-			while ($thisPos < $thisLen) {
636
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
637
-				if ($thisPos == 0) {
638
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
639
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
640
-				} else {
641
-					$charNum = intval($thisCharOrd - 128);
642
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
643
-				}
644
-				$thisPos++;
645
-			}
646
-			$encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
647
-			$encodedString .= $encodedLetter;
648
-		}
649
-	}
650
-
651
-	return $encodedString;
566
+    // mb_string : methode rapide
567
+    if (init_mb_string()) {
568
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
569
+
570
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
571
+    }
572
+
573
+    // Sinon methode pas a pas
574
+    static $decrement;
575
+    static $shift;
576
+
577
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
578
+    if (!is_array($decrement)) {
579
+        // array used to figure what number to decrement from character order value
580
+        // according to number of characters used to map unicode to ascii by utf-8
581
+        $decrement[4] = 240;
582
+        $decrement[3] = 224;
583
+        $decrement[2] = 192;
584
+        $decrement[1] = 0;
585
+        // the number of bits to shift each charNum by
586
+        $shift[1][0] = 0;
587
+        $shift[2][0] = 6;
588
+        $shift[2][1] = 0;
589
+        $shift[3][0] = 12;
590
+        $shift[3][1] = 6;
591
+        $shift[3][2] = 0;
592
+        $shift[4][0] = 18;
593
+        $shift[4][1] = 12;
594
+        $shift[4][2] = 6;
595
+        $shift[4][3] = 0;
596
+    }
597
+
598
+    $pos = 0;
599
+    $len = strlen($source);
600
+    $encodedString = '';
601
+    while ($pos < $len) {
602
+        $char = '';
603
+        $ischar = false;
604
+        $asciiPos = ord(substr($source, $pos, 1));
605
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
606
+            // 4 chars representing one unicode character
607
+            $thisLetter = substr($source, $pos, 4);
608
+            $pos += 4;
609
+        } else {
610
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
611
+                // 3 chars representing one unicode character
612
+                $thisLetter = substr($source, $pos, 3);
613
+                $pos += 3;
614
+            } else {
615
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
616
+                    // 2 chars representing one unicode character
617
+                    $thisLetter = substr($source, $pos, 2);
618
+                    $pos += 2;
619
+                } else {
620
+                    // 1 char (lower ascii)
621
+                    $thisLetter = substr($source, $pos, 1);
622
+                    $pos += 1;
623
+                    $char = $thisLetter;
624
+                    $ischar = true;
625
+                }
626
+            }
627
+        }
628
+
629
+        if ($ischar) {
630
+            $encodedString .= $char;
631
+        } else {  // process the string representing the letter to a unicode entity
632
+            $thisLen = strlen($thisLetter);
633
+            $thisPos = 0;
634
+            $decimalCode = 0;
635
+            while ($thisPos < $thisLen) {
636
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
637
+                if ($thisPos == 0) {
638
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
639
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
640
+                } else {
641
+                    $charNum = intval($thisCharOrd - 128);
642
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
643
+                }
644
+                $thisPos++;
645
+            }
646
+            $encodedLetter = "&#" . preg_replace('/^0+/', '', $decimalCode) . ';';
647
+            $encodedString .= $encodedLetter;
648
+        }
649
+    }
650
+
651
+    return $encodedString;
652 652
 }
653 653
 
654 654
 /**
@@ -667,32 +667,32 @@  discard block
 block discarded – undo
667 667
  **/
668 668
 function utf_32_to_unicode($source) {
669 669
 
670
-	// mb_string : methode rapide
671
-	if (init_mb_string()) {
672
-		$convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
673
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
674
-
675
-		return str_replace(chr(0), '', $source);
676
-	}
677
-
678
-	// Sinon methode lente
679
-	$texte = '';
680
-	while ($source) {
681
-		$words = unpack("V*", substr($source, 0, 1024));
682
-		$source = substr($source, 1024);
683
-		foreach ($words as $word) {
684
-			if ($word < 128) {
685
-				$texte .= chr($word);
686
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687
-			else {
688
-				if ($word != 65279) {
689
-					$texte .= '&#' . $word . ';';
690
-				}
691
-			}
692
-		}
693
-	}
694
-
695
-	return $texte;
670
+    // mb_string : methode rapide
671
+    if (init_mb_string()) {
672
+        $convmap = array(0x7F, 0xFFFFFF, 0x0, 0xFFFFFF);
673
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
674
+
675
+        return str_replace(chr(0), '', $source);
676
+    }
677
+
678
+    // Sinon methode lente
679
+    $texte = '';
680
+    while ($source) {
681
+        $words = unpack("V*", substr($source, 0, 1024));
682
+        $source = substr($source, 1024);
683
+        foreach ($words as $word) {
684
+            if ($word < 128) {
685
+                $texte .= chr($word);
686
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
687
+            else {
688
+                if ($word != 65279) {
689
+                    $texte .= '&#' . $word . ';';
690
+                }
691
+            }
692
+        }
693
+    }
694
+
695
+    return $texte;
696 696
 
697 697
 }
698 698
 
@@ -710,21 +710,21 @@  discard block
 block discarded – undo
710 710
  *    Caractère utf8 si trouvé, '' sinon
711 711
  **/
712 712
 function caractere_utf_8($num) {
713
-	$num = intval($num);
714
-	if ($num < 128) {
715
-		return chr($num);
716
-	}
717
-	if ($num < 2048) {
718
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
719
-	}
720
-	if ($num < 65536) {
721
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
722
-	}
723
-	if ($num < 1114112) {
724
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
725
-	}
726
-
727
-	return '';
713
+    $num = intval($num);
714
+    if ($num < 128) {
715
+        return chr($num);
716
+    }
717
+    if ($num < 2048) {
718
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
719
+    }
720
+    if ($num < 65536) {
721
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
722
+    }
723
+    if ($num < 1114112) {
724
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
725
+    }
726
+
727
+    return '';
728 728
 }
729 729
 
730 730
 /**
@@ -737,30 +737,30 @@  discard block
 block discarded – undo
737 737
  **/
738 738
 function unicode_to_utf_8($texte) {
739 739
 
740
-	// 1. Entites &#128; et suivantes
741
-	$vu = array();
742
-	if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
743
-		$texte, $regs, PREG_SET_ORDER)) {
744
-		foreach ($regs as $reg) {
745
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
746
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
747
-			}
748
-		}
749
-	}
750
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
751
-
752
-	// 2. Entites > &#xFF;
753
-	//$vu = array();
754
-	if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
755
-		$texte, $regs, PREG_SET_ORDER)) {
756
-		foreach ($regs as $reg) {
757
-			if (!isset($vu[$reg[0]])) {
758
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
759
-			}
760
-		}
761
-	}
762
-
763
-	return str_replace(array_keys($vu), array_values($vu), $texte);
740
+    // 1. Entites &#128; et suivantes
741
+    $vu = array();
742
+    if (preg_match_all(',&#0*([1-9][0-9][0-9]+);,S',
743
+        $texte, $regs, PREG_SET_ORDER)) {
744
+        foreach ($regs as $reg) {
745
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
746
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
747
+            }
748
+        }
749
+    }
750
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
751
+
752
+    // 2. Entites > &#xFF;
753
+    //$vu = array();
754
+    if (preg_match_all(',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
755
+        $texte, $regs, PREG_SET_ORDER)) {
756
+        foreach ($regs as $reg) {
757
+            if (!isset($vu[$reg[0]])) {
758
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
759
+            }
760
+        }
761
+    }
762
+
763
+    return str_replace(array_keys($vu), array_values($vu), $texte);
764 764
 
765 765
 }
766 766
 
@@ -773,15 +773,15 @@  discard block
 block discarded – undo
773 773
  *     Texte converti
774 774
  **/
775 775
 function unicode_to_javascript($texte) {
776
-	$vu = array();
777
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778
-		$num = $regs[1];
779
-		$vu[$num] = true;
780
-		$s = '\u' . sprintf("%04x", $num);
781
-		$texte = str_replace($regs[0], $s, $texte);
782
-	}
783
-
784
-	return $texte;
776
+    $vu = array();
777
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
778
+        $num = $regs[1];
779
+        $vu[$num] = true;
780
+        $s = '\u' . sprintf("%04x", $num);
781
+        $texte = str_replace($regs[0], $s, $texte);
782
+    }
783
+
784
+    return $texte;
785 785
 }
786 786
 
787 787
 /**
@@ -793,11 +793,11 @@  discard block
 block discarded – undo
793 793
  *     Texte converti
794 794
  **/
795 795
 function javascript_to_unicode($texte) {
796
-	while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
797
-		$texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
798
-	}
796
+    while (preg_match(",%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),", $texte, $regs)) {
797
+        $texte = str_replace($regs[0], "&#" . hexdec($regs[1]) . ";", $texte);
798
+    }
799 799
 
800
-	return $texte;
800
+    return $texte;
801 801
 }
802 802
 
803 803
 /**
@@ -809,11 +809,11 @@  discard block
 block discarded – undo
809 809
  *     Texte converti
810 810
  **/
811 811
 function javascript_to_binary($texte) {
812
-	while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
813
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
814
-	}
812
+    while (preg_match(",%([0-9A-F][0-9A-F]),", $texte, $regs)) {
813
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
814
+    }
815 815
 
816
-	return $texte;
816
+    return $texte;
817 817
 }
818 818
 
819 819
 
@@ -831,26 +831,26 @@  discard block
 block discarded – undo
831 831
  * @return string
832 832
  */
833 833
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
834
-	static $trans = [];
835
-	if ($charset == 'AUTO') {
836
-		$charset = $GLOBALS['meta']['charset'];
837
-	}
838
-	if (!strlen($texte)) {
839
-		return $texte;
840
-	}
841
-
842
-	$table_translit = 'translit' . $complexe;
843
-
844
-	// 2. Translitterer grace a la table predefinie
845
-	if (!isset($trans[$complexe])) {
846
-		$trans[$complexe] = [];
847
-		load_charset($table_translit);
848
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
849
-			$trans[$complexe][caractere_utf_8($key)] = $val;
850
-		}
851
-	}
852
-
853
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
834
+    static $trans = [];
835
+    if ($charset == 'AUTO') {
836
+        $charset = $GLOBALS['meta']['charset'];
837
+    }
838
+    if (!strlen($texte)) {
839
+        return $texte;
840
+    }
841
+
842
+    $table_translit = 'translit' . $complexe;
843
+
844
+    // 2. Translitterer grace a la table predefinie
845
+    if (!isset($trans[$complexe])) {
846
+        $trans[$complexe] = [];
847
+        load_charset($table_translit);
848
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
849
+            $trans[$complexe][caractere_utf_8($key)] = $val;
850
+        }
851
+    }
852
+
853
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
854 854
 }
855 855
 
856 856
 /**
@@ -873,14 +873,14 @@  discard block
 block discarded – undo
873 873
  * @return string
874 874
  */
875 875
 function translitteration($texte, $charset = 'AUTO', $complexe = '') {
876
-	// 0. Supprimer les caracteres illegaux
877
-	include_spip('inc/filtres');
878
-	$texte = corriger_caracteres($texte);
876
+    // 0. Supprimer les caracteres illegaux
877
+    include_spip('inc/filtres');
878
+    $texte = corriger_caracteres($texte);
879 879
 
880
-	// 1. Passer le charset et les &eacute en utf-8
881
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
880
+    // 1. Passer le charset et les &eacute en utf-8
881
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
882 882
 
883
-	return translitteration_rapide($texte, $charset, $complexe);
883
+    return translitteration_rapide($texte, $charset, $complexe);
884 884
 }
885 885
 
886 886
 /**
@@ -895,17 +895,17 @@  discard block
 block discarded – undo
895 895
  * @return string
896 896
  */
897 897
 function translitteration_complexe($texte, $chiffres = false) {
898
-	$texte = translitteration($texte, 'AUTO', 'complexe');
898
+    $texte = translitteration($texte, 'AUTO', 'complexe');
899 899
 
900
-	if ($chiffres) {
901
-		$texte = preg_replace_callback(
902
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
903
-			function($m) { return translitteration_chiffree($m[0]); },
904
-			$texte
905
-		);
906
-	}
900
+    if ($chiffres) {
901
+        $texte = preg_replace_callback(
902
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
903
+            function($m) { return translitteration_chiffree($m[0]); },
904
+            $texte
905
+        );
906
+    }
907 907
 
908
-	return $texte;
908
+    return $texte;
909 909
 }
910 910
 
911 911
 /**
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
  * @return string
918 918
  */
919 919
 function translitteration_chiffree($car) {
920
-	return strtr($car, "'`?~.^+(-", "123456789");
920
+    return strtr($car, "'`?~.^+(-", "123456789");
921 921
 }
922 922
 
923 923
 
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
  *    true s'il a un BOM
931 931
  **/
932 932
 function bom_utf8($texte) {
933
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
933
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
934 934
 }
935 935
 
936 936
 /**
@@ -947,18 +947,18 @@  discard block
 block discarded – undo
947 947
  *     true si c'est le cas
948 948
  **/
949 949
 function is_utf8($string) {
950
-	return !strlen(
951
-		preg_replace(
952
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
953
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
954
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
955
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
956
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
957
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
958
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
959
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
960
-			. ',sS',
961
-			'', $string));
950
+    return !strlen(
951
+        preg_replace(
952
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
953
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
954
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
955
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
956
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
957
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
958
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
959
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
960
+            . ',sS',
961
+            '', $string));
962 962
 }
963 963
 
964 964
 /**
@@ -970,10 +970,10 @@  discard block
 block discarded – undo
970 970
  *     true si c'est le cas
971 971
  **/
972 972
 function is_ascii($string) {
973
-	return !strlen(
974
-		preg_replace(
975
-			',[\x09\x0A\x0D\x20-\x7E],sS',
976
-			'', $string));
973
+    return !strlen(
974
+        preg_replace(
975
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
976
+            '', $string));
977 977
 }
978 978
 
979 979
 /**
@@ -992,58 +992,58 @@  discard block
 block discarded – undo
992 992
  **/
993 993
 function transcoder_page($texte, $headers = '') {
994 994
 
995
-	// Si tout est < 128 pas la peine d'aller plus loin
996
-	if (is_ascii($texte)) {
997
-		#spip_log('charset: ascii');
998
-		return $texte;
999
-	}
1000
-
1001
-	// Reconnaitre le BOM utf-8 (0xEFBBBF)
1002
-	if (bom_utf8($texte)) {
1003
-		$charset = 'utf-8';
1004
-		$texte = substr($texte, 3);
1005
-	} // charset precise par le contenu (xml)
1006
-	else {
1007
-		if (preg_match(
1008
-			',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1009
-			$charset = trim(strtolower($regs[1]));
1010
-		} // charset precise par le contenu (html)
1011
-		else {
1012
-			if (preg_match(
1013
-					',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
1014
-					$texte, $regs)
1015
-				# eviter #CHARSET des squelettes
1016
-				and (($tmp = trim(strtolower($regs[2]))) != 'charset')
1017
-			) {
1018
-				$charset = $tmp;
1019
-			} // charset de la reponse http
1020
-			else {
1021
-				if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1022
-					$charset = trim(strtolower($regs[1]));
1023
-				} else {
1024
-					$charset = '';
1025
-				}
1026
-			}
1027
-		}
1028
-	}
1029
-	// normaliser les noms du shif-jis japonais
1030
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1031
-		$charset = 'shift-jis';
1032
-	}
1033
-
1034
-	if ($charset) {
1035
-		spip_log("charset: $charset");
1036
-	} else {
1037
-		// valeur par defaut
1038
-		if (is_utf8($texte)) {
1039
-			$charset = 'utf-8';
1040
-		} else {
1041
-			$charset = 'iso-8859-1';
1042
-		}
1043
-		spip_log("charset probable: $charset");
1044
-	}
1045
-
1046
-	return importer_charset($texte, $charset);
995
+    // Si tout est < 128 pas la peine d'aller plus loin
996
+    if (is_ascii($texte)) {
997
+        #spip_log('charset: ascii');
998
+        return $texte;
999
+    }
1000
+
1001
+    // Reconnaitre le BOM utf-8 (0xEFBBBF)
1002
+    if (bom_utf8($texte)) {
1003
+        $charset = 'utf-8';
1004
+        $texte = substr($texte, 3);
1005
+    } // charset precise par le contenu (xml)
1006
+    else {
1007
+        if (preg_match(
1008
+            ',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1009
+            $charset = trim(strtolower($regs[1]));
1010
+        } // charset precise par le contenu (html)
1011
+        else {
1012
+            if (preg_match(
1013
+                    ',<(meta|html|body)[^>]*charset[^>]*=[^>]*([-_a-z0-9]+?),UimsS',
1014
+                    $texte, $regs)
1015
+                # eviter #CHARSET des squelettes
1016
+                and (($tmp = trim(strtolower($regs[2]))) != 'charset')
1017
+            ) {
1018
+                $charset = $tmp;
1019
+            } // charset de la reponse http
1020
+            else {
1021
+                if (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1022
+                    $charset = trim(strtolower($regs[1]));
1023
+                } else {
1024
+                    $charset = '';
1025
+                }
1026
+            }
1027
+        }
1028
+    }
1029
+    // normaliser les noms du shif-jis japonais
1030
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1031
+        $charset = 'shift-jis';
1032
+    }
1033
+
1034
+    if ($charset) {
1035
+        spip_log("charset: $charset");
1036
+    } else {
1037
+        // valeur par defaut
1038
+        if (is_utf8($texte)) {
1039
+            $charset = 'utf-8';
1040
+        } else {
1041
+            $charset = 'iso-8859-1';
1042
+        }
1043
+        spip_log("charset probable: $charset");
1044
+    }
1045
+
1046
+    return importer_charset($texte, $charset);
1047 1047
 }
1048 1048
 
1049 1049
 
@@ -1067,26 +1067,26 @@  discard block
 block discarded – undo
1067 1067
  *     Le texte coupé
1068 1068
  **/
1069 1069
 function spip_substr($c, $start = 0, $length = null) {
1070
-	// Si ce n'est pas utf-8, utiliser substr
1071
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1072
-		if ($length) {
1073
-			return substr($c, $start, $length);
1074
-		} else {
1075
-			substr($c, $start);
1076
-		}
1077
-	}
1078
-
1079
-	// Si utf-8, voir si on dispose de mb_string
1080
-	if (init_mb_string()) {
1081
-		if ($length) {
1082
-			return mb_substr($c, $start, $length);
1083
-		} else {
1084
-			return mb_substr($c, $start);
1085
-		}
1086
-	}
1087
-
1088
-	// Version manuelle (cf. ci-dessous)
1089
-	return spip_substr_manuelle($c, $start, $length);
1070
+    // Si ce n'est pas utf-8, utiliser substr
1071
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1072
+        if ($length) {
1073
+            return substr($c, $start, $length);
1074
+        } else {
1075
+            substr($c, $start);
1076
+        }
1077
+    }
1078
+
1079
+    // Si utf-8, voir si on dispose de mb_string
1080
+    if (init_mb_string()) {
1081
+        if ($length) {
1082
+            return mb_substr($c, $start, $length);
1083
+        } else {
1084
+            return mb_substr($c, $start);
1085
+        }
1086
+    }
1087
+
1088
+    // Version manuelle (cf. ci-dessous)
1089
+    return spip_substr_manuelle($c, $start, $length);
1090 1090
 }
1091 1091
 
1092 1092
 
@@ -1105,40 +1105,40 @@  discard block
 block discarded – undo
1105 1105
  **/
1106 1106
 function spip_substr_manuelle($c, $start, $length = null) {
1107 1107
 
1108
-	// Cas pathologique
1109
-	if ($length === 0) {
1110
-		return '';
1111
-	}
1112
-
1113
-	// S'il y a un demarrage, on se positionne
1114
-	if ($start > 0) {
1115
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1116
-	} elseif ($start < 0) {
1117
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1118
-	}
1119
-
1120
-	if (!$length) {
1121
-		return $c;
1122
-	}
1123
-
1124
-	if ($length > 0) {
1125
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1126
-		// (un caractere utf-8 prenant au maximum n bytes)
1127
-		$n = 0;
1128
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1129
-			;
1130
-		}
1131
-		$c = substr($c, 0, $n * $length);
1132
-		// puis, tant qu'on est trop long, on coupe...
1133
-		while (($l = spip_strlen($c)) > $length) {
1134
-			$c = substr($c, 0, $length - $l);
1135
-		}
1136
-
1137
-		return $c;
1138
-	}
1139
-
1140
-	// $length < 0
1141
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1108
+    // Cas pathologique
1109
+    if ($length === 0) {
1110
+        return '';
1111
+    }
1112
+
1113
+    // S'il y a un demarrage, on se positionne
1114
+    if ($start > 0) {
1115
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1116
+    } elseif ($start < 0) {
1117
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1118
+    }
1119
+
1120
+    if (!$length) {
1121
+        return $c;
1122
+    }
1123
+
1124
+    if ($length > 0) {
1125
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1126
+        // (un caractere utf-8 prenant au maximum n bytes)
1127
+        $n = 0;
1128
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1129
+            ;
1130
+        }
1131
+        $c = substr($c, 0, $n * $length);
1132
+        // puis, tant qu'on est trop long, on coupe...
1133
+        while (($l = spip_strlen($c)) > $length) {
1134
+            $c = substr($c, 0, $length - $l);
1135
+        }
1136
+
1137
+        return $c;
1138
+    }
1139
+
1140
+    // $length < 0
1141
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1142 1142
 }
1143 1143
 
1144 1144
 /**
@@ -1152,14 +1152,14 @@  discard block
 block discarded – undo
1152 1152
  *     La chaîne avec une majuscule sur le premier mot
1153 1153
  */
1154 1154
 function spip_ucfirst($c) {
1155
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1156
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1157
-		return ucfirst($c);
1158
-	}
1155
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1156
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1157
+        return ucfirst($c);
1158
+    }
1159 1159
 
1160
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1160
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1161 1161
 
1162
-	return $lettre1 . spip_substr($c, 1);
1162
+    return $lettre1 . spip_substr($c, 1);
1163 1163
 }
1164 1164
 
1165 1165
 /**
@@ -1173,12 +1173,12 @@  discard block
 block discarded – undo
1173 1173
  *     La chaîne en minuscules
1174 1174
  */
1175 1175
 function spip_strtolower($c) {
1176
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1177
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1178
-		return strtolower($c);
1179
-	}
1176
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower 
1177
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1178
+        return strtolower($c);
1179
+    }
1180 1180
 
1181
-	return mb_strtolower($c);
1181
+    return mb_strtolower($c);
1182 1182
 }
1183 1183
 
1184 1184
 /**
@@ -1192,23 +1192,23 @@  discard block
 block discarded – undo
1192 1192
  *     Longueur de la chaîne
1193 1193
  */
1194 1194
 function spip_strlen($c) {
1195
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1196
-	$c = str_replace("\r\n", "\n", $c);
1197
-
1198
-	// Si ce n'est pas utf-8, utiliser strlen
1199
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1200
-		return strlen($c);
1201
-	}
1202
-
1203
-	// Sinon, utiliser mb_strlen() si disponible
1204
-	if (init_mb_string()) {
1205
-		return mb_strlen($c);
1206
-	}
1207
-
1208
-	// Methode manuelle : on supprime les bytes 10......,
1209
-	// on compte donc les ascii (0.......) et les demarrages
1210
-	// de caracteres utf-8 (11......)
1211
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1195
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1196
+    $c = str_replace("\r\n", "\n", $c);
1197
+
1198
+    // Si ce n'est pas utf-8, utiliser strlen
1199
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1200
+        return strlen($c);
1201
+    }
1202
+
1203
+    // Sinon, utiliser mb_strlen() si disponible
1204
+    if (init_mb_string()) {
1205
+        return mb_strlen($c);
1206
+    }
1207
+
1208
+    // Methode manuelle : on supprime les bytes 10......,
1209
+    // on compte donc les ascii (0.......) et les demarrages
1210
+    // de caracteres utf-8 (11......)
1211
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1212 1212
 }
1213 1213
 
1214 1214
 // Initialisation
@@ -1218,14 +1218,14 @@  discard block
 block discarded – undo
1218 1218
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1219 1219
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1220 1220
 if (!isset($GLOBALS['meta']['pcre_u'])
1221
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1221
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1222 1222
 ) {
1223
-	include_spip('inc/meta');
1224
-	ecrire_meta('pcre_u',
1225
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1226
-			and test_pcre_unicode())
1227
-			? 'u' : ''
1228
-	);
1223
+    include_spip('inc/meta');
1224
+    ecrire_meta('pcre_u',
1225
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1226
+            and test_pcre_unicode())
1227
+            ? 'u' : ''
1228
+    );
1229 1229
 }
1230 1230
 
1231 1231
 
@@ -1241,17 +1241,17 @@  discard block
 block discarded – undo
1241 1241
  *     en unicode : &#128169;
1242 1242
  */
1243 1243
 function utf8_noplanes($x) {
1244
-	$regexp_utf8_4bytes = '/(
1244
+    $regexp_utf8_4bytes = '/(
1245 1245
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1246 1246
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1247 1247
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1248 1248
 )/xS';
1249
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1250
-		foreach ($z[0] as $k) {
1251
-			$ku = utf_8_to_unicode($k);
1252
-			$x = str_replace($k, $ku, $x);
1253
-		}
1254
-	}
1255
-
1256
-	return $x;
1249
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1250
+        foreach ($z[0] as $k) {
1251
+            $ku = utf_8_to_unicode($k);
1252
+            $x = str_replace($k, $ku, $x);
1253
+        }
1254
+    }
1255
+
1256
+    return $x;
1257 1257
 }
Please login to merge, or discard this patch.
ecrire/inc/securiser_action.php 2 patches
Indentation   +181 added lines, -181 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
 /**
@@ -50,19 +50,19 @@  discard block
 block discarded – undo
50 50
  * @return array|string
51 51
  */
52 52
 function inc_securiser_action_dist($action = '', $arg = '', $redirect = "", $mode = false, $att = '', $public = false) {
53
-	if ($action) {
54
-		return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public);
55
-	} else {
56
-		$arg = _request('arg');
57
-		$hash = _request('hash');
58
-		$action = _request('action') ? _request('action') : _request('formulaire_action');
59
-		if ($a = verifier_action_auteur("$action-$arg", $hash)) {
60
-			return $arg;
61
-		}
62
-		include_spip('inc/minipres');
63
-		echo minipres();
64
-		exit;
65
-	}
53
+    if ($action) {
54
+        return securiser_action_auteur($action, $arg, $redirect, $mode, $att, $public);
55
+    } else {
56
+        $arg = _request('arg');
57
+        $hash = _request('hash');
58
+        $action = _request('action') ? _request('action') : _request('formulaire_action');
59
+        if ($a = verifier_action_auteur("$action-$arg", $hash)) {
60
+            return $arg;
61
+        }
62
+        include_spip('inc/minipres');
63
+        echo minipres();
64
+        exit;
65
+    }
66 66
 }
67 67
 
68 68
 /**
@@ -94,30 +94,30 @@  discard block
 block discarded – undo
94 94
  */
95 95
 function securiser_action_auteur($action, $arg, $redirect = "", $mode = false, $att = '', $public = false) {
96 96
 
97
-	// mode URL ou array
98
-	if (!is_string($mode)) {
99
-		$hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null);
100
-
101
-		$r = rawurlencode($redirect);
102
-		if ($mode === -1) {
103
-			return array('action' => $action, 'arg' => $arg, 'hash' => $hash);
104
-		} else {
105
-			return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
106
-				$mode, $public);
107
-		}
108
-	}
109
-
110
-	// mode formulaire
111
-	$hash = calculer_action_auteur("$action-$arg");
112
-	$att .= " style='margin: 0px; border: 0px'";
113
-	if ($redirect) {
114
-		$redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
115
-	}
116
-	$mode .= $redirect . "
97
+    // mode URL ou array
98
+    if (!is_string($mode)) {
99
+        $hash = calculer_action_auteur("$action-$arg", is_numeric($att) ? $att : null);
100
+
101
+        $r = rawurlencode($redirect);
102
+        if ($mode === -1) {
103
+            return array('action' => $action, 'arg' => $arg, 'hash' => $hash);
104
+        } else {
105
+            return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
106
+                $mode, $public);
107
+        }
108
+    }
109
+
110
+    // mode formulaire
111
+    $hash = calculer_action_auteur("$action-$arg");
112
+    $att .= " style='margin: 0px; border: 0px'";
113
+    if ($redirect) {
114
+        $redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
115
+    }
116
+    $mode .= $redirect . "
117 117
 <input name='hash' type='hidden' value='$hash' />
118 118
 <input name='arg' type='hidden' value='$arg' />";
119 119
 
120
-	return generer_form_action($action, $mode, $att, $public);
120
+    return generer_form_action($action, $mode, $att, $public);
121 121
 }
122 122
 
123 123
 /**
@@ -127,47 +127,47 @@  discard block
 block discarded – undo
127 127
  * @return array
128 128
  */
129 129
 function caracteriser_auteur($id_auteur = null) {
130
-	static $caracterisation = array();
131
-
132
-	if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) {
133
-		// si l'auteur courant n'est pas connu alors qu'il peut demander une action
134
-		// c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie.
135
-		// S'il n'avait pas le droit de realiser cette action, le hash sera faux.
136
-		if (isset($_COOKIE['spip_session'])
137
-			and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r))
138
-		) {
139
-			return array($r[1], '');
140
-			// Necessaire aux forums anonymes.
141
-			// Pour le reste, ca echouera.
142
-		} else {
143
-			return array('0', '');
144
-		}
145
-	}
146
-	// Eviter l'acces SQL si le pass est connu de PHP
147
-	if (is_null($id_auteur)) {
148
-		$id_auteur = isset($GLOBALS['visiteur_session']['id_auteur']) ? $GLOBALS['visiteur_session']['id_auteur'] : 0;
149
-		if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) {
150
-			return $caracterisation[$id_auteur] = array($id_auteur, $GLOBALS['visiteur_session']['pass']);
151
-		}
152
-	}
153
-
154
-	if (isset($caracterisation[$id_auteur])) {
155
-		return $caracterisation[$id_auteur];
156
-	}
157
-
158
-	if ($id_auteur) {
159
-		include_spip('base/abstract_sql');
160
-		$t = sql_fetsel("id_auteur, pass", "spip_auteurs", "id_auteur=$id_auteur");
161
-		if ($t) {
162
-			return $caracterisation[$id_auteur] = array($t['id_auteur'], $t['pass']);
163
-		}
164
-		include_spip('inc/minipres');
165
-		echo minipres();
166
-		exit;
167
-	} // Visiteur anonyme, pour ls forums par exemple
168
-	else {
169
-		return array('0', '');
170
-	}
130
+    static $caracterisation = array();
131
+
132
+    if (is_null($id_auteur) and !isset($GLOBALS['visiteur_session']['id_auteur'])) {
133
+        // si l'auteur courant n'est pas connu alors qu'il peut demander une action
134
+        // c'est une connexion par php_auth ou 1 instal, on se rabat sur le cookie.
135
+        // S'il n'avait pas le droit de realiser cette action, le hash sera faux.
136
+        if (isset($_COOKIE['spip_session'])
137
+            and (preg_match('/^(\d+)/', $_COOKIE['spip_session'], $r))
138
+        ) {
139
+            return array($r[1], '');
140
+            // Necessaire aux forums anonymes.
141
+            // Pour le reste, ca echouera.
142
+        } else {
143
+            return array('0', '');
144
+        }
145
+    }
146
+    // Eviter l'acces SQL si le pass est connu de PHP
147
+    if (is_null($id_auteur)) {
148
+        $id_auteur = isset($GLOBALS['visiteur_session']['id_auteur']) ? $GLOBALS['visiteur_session']['id_auteur'] : 0;
149
+        if (isset($GLOBALS['visiteur_session']['pass']) and $GLOBALS['visiteur_session']['pass']) {
150
+            return $caracterisation[$id_auteur] = array($id_auteur, $GLOBALS['visiteur_session']['pass']);
151
+        }
152
+    }
153
+
154
+    if (isset($caracterisation[$id_auteur])) {
155
+        return $caracterisation[$id_auteur];
156
+    }
157
+
158
+    if ($id_auteur) {
159
+        include_spip('base/abstract_sql');
160
+        $t = sql_fetsel("id_auteur, pass", "spip_auteurs", "id_auteur=$id_auteur");
161
+        if ($t) {
162
+            return $caracterisation[$id_auteur] = array($t['id_auteur'], $t['pass']);
163
+        }
164
+        include_spip('inc/minipres');
165
+        echo minipres();
166
+        exit;
167
+    } // Visiteur anonyme, pour ls forums par exemple
168
+    else {
169
+        return array('0', '');
170
+    }
171 171
 }
172 172
 
173 173
 /**
@@ -182,28 +182,28 @@  discard block
 block discarded – undo
182 182
  * @return string
183 183
  */
184 184
 function _action_auteur($action, $id_auteur, $pass, $alea) {
185
-	static $sha = array();
186
-	if (!isset($sha[$id_auteur . $pass . $alea])) {
187
-		if (!isset($GLOBALS['meta'][$alea])) {
188
-			if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)){
189
-				include_spip('inc/acces');
190
-				charger_aleas();
191
-				if (empty($GLOBALS['meta'][$alea])){
192
-					include_spip('inc/minipres');
193
-					echo minipres();
194
-					spip_log("$alea indisponible");
195
-					exit;
196
-				}
197
-			}
198
-		}
199
-		include_spip('auth/sha256.inc');
200
-		$sha[$id_auteur . $pass . $alea] = spip_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]);
201
-	}
202
-	if (function_exists('sha1')) {
203
-		return sha1($action . $sha[$id_auteur . $pass . $alea]);
204
-	} else {
205
-		return md5($action . $sha[$id_auteur . $pass . $alea]);
206
-	}
185
+    static $sha = array();
186
+    if (!isset($sha[$id_auteur . $pass . $alea])) {
187
+        if (!isset($GLOBALS['meta'][$alea])) {
188
+            if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)){
189
+                include_spip('inc/acces');
190
+                charger_aleas();
191
+                if (empty($GLOBALS['meta'][$alea])){
192
+                    include_spip('inc/minipres');
193
+                    echo minipres();
194
+                    spip_log("$alea indisponible");
195
+                    exit;
196
+                }
197
+            }
198
+        }
199
+        include_spip('auth/sha256.inc');
200
+        $sha[$id_auteur . $pass . $alea] = spip_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]);
201
+    }
202
+    if (function_exists('sha1')) {
203
+        return sha1($action . $sha[$id_auteur . $pass . $alea]);
204
+    } else {
205
+        return md5($action . $sha[$id_auteur . $pass . $alea]);
206
+    }
207 207
 }
208 208
 
209 209
 /**
@@ -214,9 +214,9 @@  discard block
 block discarded – undo
214 214
  * @return string
215 215
  */
216 216
 function calculer_action_auteur($action, $id_auteur = null) {
217
-	list($id_auteur, $pass) = caracteriser_auteur($id_auteur);
217
+    list($id_auteur, $pass) = caracteriser_auteur($id_auteur);
218 218
 
219
-	return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere');
219
+    return _action_auteur($action, $id_auteur, $pass, 'alea_ephemere');
220 220
 }
221 221
 
222 222
 
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
  * @return bool
230 230
  */
231 231
 function verifier_action_auteur($action, $hash) {
232
-	list($id_auteur, $pass) = caracteriser_auteur();
233
-	if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) {
234
-		return true;
235
-	}
236
-	if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')) {
237
-		return true;
238
-	}
239
-
240
-	return false;
232
+    list($id_auteur, $pass) = caracteriser_auteur();
233
+    if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere')) {
234
+        return true;
235
+    }
236
+    if ($hash == _action_auteur($action, $id_auteur, $pass, 'alea_ephemere_ancien')) {
237
+        return true;
238
+    }
239
+
240
+    return false;
241 241
 }
242 242
 
243 243
 //
@@ -253,25 +253,25 @@  discard block
 block discarded – undo
253 253
  * @return string
254 254
  */
255 255
 function secret_du_site() {
256
-	if (!isset($GLOBALS['meta']['secret_du_site'])) {
257
-		include_spip('base/abstract_sql');
258
-		$GLOBALS['meta']['secret_du_site'] = sql_getfetsel('valeur', 'spip_meta', "nom='secret_du_site'");
259
-	}
260
-	if (!isset($GLOBALS['meta']['secret_du_site'])
261
-		or (strlen($GLOBALS['meta']['secret_du_site']) < 64)
262
-	) {
263
-		include_spip('inc/acces');
264
-		include_spip('auth/sha256.inc');
265
-		ecrire_meta('secret_du_site',
266
-			spip_sha256(
267
-				$_SERVER["DOCUMENT_ROOT"] 
268
-				. (isset($_SERVER['SERVER_SIGNATURE']) ? $_SERVER["SERVER_SIGNATURE"] : "")
269
-				. creer_uniqid()
270
-			), 'non');
271
-		lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
272
-	}
273
-
274
-	return $GLOBALS['meta']['secret_du_site'];
256
+    if (!isset($GLOBALS['meta']['secret_du_site'])) {
257
+        include_spip('base/abstract_sql');
258
+        $GLOBALS['meta']['secret_du_site'] = sql_getfetsel('valeur', 'spip_meta', "nom='secret_du_site'");
259
+    }
260
+    if (!isset($GLOBALS['meta']['secret_du_site'])
261
+        or (strlen($GLOBALS['meta']['secret_du_site']) < 64)
262
+    ) {
263
+        include_spip('inc/acces');
264
+        include_spip('auth/sha256.inc');
265
+        ecrire_meta('secret_du_site',
266
+            spip_sha256(
267
+                $_SERVER["DOCUMENT_ROOT"] 
268
+                . (isset($_SERVER['SERVER_SIGNATURE']) ? $_SERVER["SERVER_SIGNATURE"] : "")
269
+                . creer_uniqid()
270
+            ), 'non');
271
+        lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas
272
+    }
273
+
274
+    return $GLOBALS['meta']['secret_du_site'];
275 275
 }
276 276
 
277 277
 /**
@@ -281,11 +281,11 @@  discard block
 block discarded – undo
281 281
  * @return string
282 282
  */
283 283
 function calculer_cle_action($action) {
284
-	if (function_exists('sha1')) {
285
-		return sha1($action . secret_du_site());
286
-	} else {
287
-		return md5($action . secret_du_site());
288
-	}
284
+    if (function_exists('sha1')) {
285
+        return sha1($action . secret_du_site());
286
+    } else {
287
+        return md5($action . secret_du_site());
288
+    }
289 289
 }
290 290
 
291 291
 /**
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
  * @return bool
297 297
  */
298 298
 function verifier_cle_action($action, $cle) {
299
-	return ($cle == calculer_cle_action($action));
299
+    return ($cle == calculer_cle_action($action));
300 300
 }
301 301
 
302 302
 
@@ -313,19 +313,19 @@  discard block
 block discarded – undo
313 313
  * @return string Token, de la forme "{id}*{hash}"
314 314
  */
315 315
 function calculer_token_previsu($url, $id_auteur = null, $alea = 'alea_ephemere') {
316
-	if (is_null($id_auteur)) {
317
-		if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
318
-			$id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
319
-		}
320
-	}
321
-	if (!$id_auteur = intval($id_auteur)) {
322
-		return "";
323
-	}
324
-	// On nettoie l’URL de tous les var_.
325
-	$url = nettoyer_uri_var($url);
326
-
327
-	$token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea);
328
-	return "$id_auteur-$token";
316
+    if (is_null($id_auteur)) {
317
+        if (!empty($GLOBALS['visiteur_session']['id_auteur'])) {
318
+            $id_auteur = $GLOBALS['visiteur_session']['id_auteur'];
319
+        }
320
+    }
321
+    if (!$id_auteur = intval($id_auteur)) {
322
+        return "";
323
+    }
324
+    // On nettoie l’URL de tous les var_.
325
+    $url = nettoyer_uri_var($url);
326
+
327
+    $token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea);
328
+    return "$id_auteur-$token";
329 329
 }
330 330
 
331 331
 
@@ -343,31 +343,31 @@  discard block
 block discarded – undo
343 343
  *     + Tableau (id auteur, type d’objet, id_objet) sinon.
344 344
  */
345 345
 function verifier_token_previsu($token) {
346
-	// retrouver auteur / hash
347
-	$e = explode('-', $token, 2);
348
-	if (count($e) == 2 and is_numeric(reset($e))) {
349
-		$id_auteur = intval(reset($e));
350
-	} else {
351
-		return false;
352
-	}
353
-
354
-	// calculer le type et id de l’url actuelle
355
-	include_spip('inc/urls');
356
-	include_spip('inc/filtres_mini');
357
-	$url = url_absolue(self());
358
-
359
-	// verifier le token
360
-	$_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere');
361
-	if (!$_token or $token !== $_token) {
362
-		$_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien');
363
-		if (!$_token or $token !== $_token) {
364
-			return false;
365
-		}
366
-	}
367
-
368
-	return array(
369
-		'id_auteur' => $id_auteur,
370
-	);
346
+    // retrouver auteur / hash
347
+    $e = explode('-', $token, 2);
348
+    if (count($e) == 2 and is_numeric(reset($e))) {
349
+        $id_auteur = intval(reset($e));
350
+    } else {
351
+        return false;
352
+    }
353
+
354
+    // calculer le type et id de l’url actuelle
355
+    include_spip('inc/urls');
356
+    include_spip('inc/filtres_mini');
357
+    $url = url_absolue(self());
358
+
359
+    // verifier le token
360
+    $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere');
361
+    if (!$_token or $token !== $_token) {
362
+        $_token = calculer_token_previsu($url, $id_auteur, 'alea_ephemere_ancien');
363
+        if (!$_token or $token !== $_token) {
364
+            return false;
365
+        }
366
+    }
367
+
368
+    return array(
369
+        'id_auteur' => $id_auteur,
370
+    );
371 371
 }
372 372
 
373 373
 /**
@@ -376,13 +376,13 @@  discard block
 block discarded – undo
376 376
  * @return bool|array
377 377
  */
378 378
 function decrire_token_previsu() {
379
-	static $desc = null;
380
-	if (is_null($desc)) {
381
-		if ($token = _request('var_previewtoken')) {
382
-			$desc = verifier_token_previsu($token);
383
-		} else {
384
-			$desc = false;
385
-		}
386
-	}
387
-	return $desc;
379
+    static $desc = null;
380
+    if (is_null($desc)) {
381
+        if ($token = _request('var_previewtoken')) {
382
+            $desc = verifier_token_previsu($token);
383
+        } else {
384
+            $desc = false;
385
+        }
386
+    }
387
+    return $desc;
388 388
 }
389 389
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		if ($mode === -1) {
103 103
 			return array('action' => $action, 'arg' => $arg, 'hash' => $hash);
104 104
 		} else {
105
-			return generer_url_action($action, "arg=" . rawurlencode($arg) . "&hash=$hash" . (!$r ? '' : "&redirect=$r"),
105
+			return generer_url_action($action, "arg=".rawurlencode($arg)."&hash=$hash".(!$r ? '' : "&redirect=$r"),
106 106
 				$mode, $public);
107 107
 		}
108 108
 	}
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 	$hash = calculer_action_auteur("$action-$arg");
112 112
 	$att .= " style='margin: 0px; border: 0px'";
113 113
 	if ($redirect) {
114
-		$redirect = "\n\t\t<input name='redirect' type='hidden' value='" . str_replace("'", '&#39;', $redirect) . "' />";
114
+		$redirect = "\n\t\t<input name='redirect' type='hidden' value='".str_replace("'", '&#39;', $redirect)."' />";
115 115
 	}
116
-	$mode .= $redirect . "
116
+	$mode .= $redirect."
117 117
 <input name='hash' type='hidden' value='$hash' />
118 118
 <input name='arg' type='hidden' value='$arg' />";
119 119
 
@@ -183,12 +183,12 @@  discard block
 block discarded – undo
183 183
  */
184 184
 function _action_auteur($action, $id_auteur, $pass, $alea) {
185 185
 	static $sha = array();
186
-	if (!isset($sha[$id_auteur . $pass . $alea])) {
186
+	if (!isset($sha[$id_auteur.$pass.$alea])) {
187 187
 		if (!isset($GLOBALS['meta'][$alea])) {
188
-			if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)){
188
+			if (!$exec = _request('exec') or !autoriser_sans_cookie($exec)) {
189 189
 				include_spip('inc/acces');
190 190
 				charger_aleas();
191
-				if (empty($GLOBALS['meta'][$alea])){
191
+				if (empty($GLOBALS['meta'][$alea])) {
192 192
 					include_spip('inc/minipres');
193 193
 					echo minipres();
194 194
 					spip_log("$alea indisponible");
@@ -197,12 +197,12 @@  discard block
 block discarded – undo
197 197
 			}
198 198
 		}
199 199
 		include_spip('auth/sha256.inc');
200
-		$sha[$id_auteur . $pass . $alea] = spip_sha256($id_auteur . $pass . @$GLOBALS['meta'][$alea]);
200
+		$sha[$id_auteur.$pass.$alea] = spip_sha256($id_auteur.$pass.@$GLOBALS['meta'][$alea]);
201 201
 	}
202 202
 	if (function_exists('sha1')) {
203
-		return sha1($action . $sha[$id_auteur . $pass . $alea]);
203
+		return sha1($action.$sha[$id_auteur.$pass.$alea]);
204 204
 	} else {
205
-		return md5($action . $sha[$id_auteur . $pass . $alea]);
205
+		return md5($action.$sha[$id_auteur.$pass.$alea]);
206 206
 	}
207 207
 }
208 208
 
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
  */
283 283
 function calculer_cle_action($action) {
284 284
 	if (function_exists('sha1')) {
285
-		return sha1($action . secret_du_site());
285
+		return sha1($action.secret_du_site());
286 286
 	} else {
287
-		return md5($action . secret_du_site());
287
+		return md5($action.secret_du_site());
288 288
 	}
289 289
 }
290 290
 
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 	// On nettoie l’URL de tous les var_.
325 325
 	$url = nettoyer_uri_var($url);
326 326
 
327
-	$token = _action_auteur('previsualiser-' . $url, $id_auteur, null, $alea);
327
+	$token = _action_auteur('previsualiser-'.$url, $id_auteur, null, $alea);
328 328
 	return "$id_auteur-$token";
329 329
 }
330 330
 
Please login to merge, or discard this patch.
ecrire/public/cacher.php 2 patches
Indentation   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 /**
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
  * @return string
28 28
  */
29 29
 function generer_nom_fichier_cache($contexte, $page) {
30
-	$u = md5(var_export(array($contexte, $page), true));
30
+    $u = md5(var_export(array($contexte, $page), true));
31 31
 
32
-	return $u . ".cache";
32
+    return $u . ".cache";
33 33
 }
34 34
 
35 35
 /**
@@ -40,13 +40,13 @@  discard block
 block discarded – undo
40 40
  * @return bool
41 41
  */
42 42
 function ecrire_cache($nom_cache, $valeur) {
43
-	$d = substr($nom_cache, 0, 2);
44
-	$u = substr($nom_cache, 2, 2);
45
-	$rep = _DIR_CACHE;
46
-	$rep = sous_repertoire($rep, '', false, true);
47
-	$rep = sous_repertoire($rep, $d, false, true);
43
+    $d = substr($nom_cache, 0, 2);
44
+    $u = substr($nom_cache, 2, 2);
45
+    $rep = _DIR_CACHE;
46
+    $rep = sous_repertoire($rep, '', false, true);
47
+    $rep = sous_repertoire($rep, $d, false, true);
48 48
 
49
-	return ecrire_fichier($rep . $u . ".cache", serialize(array("nom_cache" => $nom_cache, "valeur" => $valeur)));
49
+    return ecrire_fichier($rep . $u . ".cache", serialize(array("nom_cache" => $nom_cache, "valeur" => $valeur)));
50 50
 }
51 51
 
52 52
 /**
@@ -56,35 +56,35 @@  discard block
 block discarded – undo
56 56
  * @return mixed
57 57
  */
58 58
 function lire_cache($nom_cache) {
59
-	$d = substr($nom_cache, 0, 2);
60
-	$u = substr($nom_cache, 2, 2);
61
-	if (file_exists($f = _DIR_CACHE . "$d/$u.cache")
62
-		and lire_fichier($f, $tmp)
63
-		and $tmp = unserialize($tmp)
64
-		and $tmp['nom_cache'] == $nom_cache
65
-		and isset($tmp['valeur'])
66
-	) {
67
-		return $tmp['valeur'];
68
-	}
69
-
70
-	return false;
59
+    $d = substr($nom_cache, 0, 2);
60
+    $u = substr($nom_cache, 2, 2);
61
+    if (file_exists($f = _DIR_CACHE . "$d/$u.cache")
62
+        and lire_fichier($f, $tmp)
63
+        and $tmp = unserialize($tmp)
64
+        and $tmp['nom_cache'] == $nom_cache
65
+        and isset($tmp['valeur'])
66
+    ) {
67
+        return $tmp['valeur'];
68
+    }
69
+
70
+    return false;
71 71
 }
72 72
 
73 73
 // Parano : on signe le cache, afin d'interdire un hack d'injection
74 74
 // dans notre memcache
75 75
 function cache_signature(&$page) {
76
-	if (!isset($GLOBALS['meta']['cache_signature'])) {
77
-		include_spip('inc/acces');
78
-		include_spip('auth/sha256.inc');
79
-		ecrire_meta('cache_signature',
80
-			spip_sha256(
81
-				$_SERVER["DOCUMENT_ROOT"] 
82
-				. (isset($_SERVER['SERVER_SIGNATURE']) ? $_SERVER["SERVER_SIGNATURE"] : "")
83
-				. creer_uniqid()
84
-			), 'non');
85
-	}
86
-
87
-	return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']);
76
+    if (!isset($GLOBALS['meta']['cache_signature'])) {
77
+        include_spip('inc/acces');
78
+        include_spip('auth/sha256.inc');
79
+        ecrire_meta('cache_signature',
80
+            spip_sha256(
81
+                $_SERVER["DOCUMENT_ROOT"] 
82
+                . (isset($_SERVER['SERVER_SIGNATURE']) ? $_SERVER["SERVER_SIGNATURE"] : "")
83
+                . creer_uniqid()
84
+            ), 'non');
85
+    }
86
+
87
+    return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']);
88 88
 }
89 89
 
90 90
 /**
@@ -98,14 +98,14 @@  discard block
 block discarded – undo
98 98
  * @return array
99 99
  */
100 100
 function gzip_page($page) {
101
-	if (function_exists('gzcompress') and strlen($page['texte']) > 16 * 1024) {
102
-		$page['gz'] = true;
103
-		$page['texte'] = gzcompress($page['texte']);
104
-	} else {
105
-		$page['gz'] = false;
106
-	}
107
-
108
-	return $page;
101
+    if (function_exists('gzcompress') and strlen($page['texte']) > 16 * 1024) {
102
+        $page['gz'] = true;
103
+        $page['texte'] = gzcompress($page['texte']);
104
+    } else {
105
+        $page['gz'] = false;
106
+    }
107
+
108
+    return $page;
109 109
 }
110 110
 
111 111
 /**
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
  * @return void
121 121
  */
122 122
 function gunzip_page(&$page) {
123
-	if ($page['gz']) {
124
-		$page['texte'] = gzuncompress($page['texte']);
125
-		$page['gz'] = false; // ne pas gzuncompress deux fois une meme page
126
-	}
123
+    if ($page['gz']) {
124
+        $page['texte'] = gzuncompress($page['texte']);
125
+        $page['gz'] = false; // ne pas gzuncompress deux fois une meme page
126
+    }
127 127
 }
128 128
 
129 129
 /**
@@ -139,72 +139,72 @@  discard block
 block discarded – undo
139 139
  */
140 140
 /// http://code.spip.net/@cache_valide
141 141
 function cache_valide(&$page, $date) {
142
-	$now = $_SERVER['REQUEST_TIME'];
143
-
144
-	// Apparition d'un nouvel article post-date ?
145
-	if (isset($GLOBALS['meta']['post_dates'])
146
-		and $GLOBALS['meta']['post_dates'] == 'non'
147
-		and isset($GLOBALS['meta']['date_prochain_postdate'])
148
-		and $now > $GLOBALS['meta']['date_prochain_postdate']
149
-	) {
150
-		spip_log('Un article post-date invalide le cache');
151
-		include_spip('inc/rubriques');
152
-		calculer_prochain_postdate(true);
153
-	}
154
-
155
-	if (defined('_VAR_NOCACHE') and _VAR_NOCACHE) {
156
-		return -1;
157
-	}
158
-	if (isset($GLOBALS['meta']['cache_inhib']) and $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) {
159
-		return -1;
160
-	}
161
-	if (defined('_NO_CACHE')) {
162
-		return (_NO_CACHE == 0 and !isset($page['texte'])) ? 1 : _NO_CACHE;
163
-	}
164
-
165
-	// pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache)
166
-	if (!$page or !isset($page['texte']) or !isset($page['entetes']['X-Spip-Cache'])) {
167
-		return _IS_BOT ? -1 : 1;
168
-	}
169
-
170
-	// controle de la signature
171
-	if ($page['sig'] !== cache_signature($page)) {
172
-		return _IS_BOT ? -1 : 1;
173
-	}
174
-
175
-	// #CACHE{n,statique} => on n'invalide pas avec derniere_modif
176
-	// cf. ecrire/public/balises.php, balise_CACHE_dist()
177
-	if (!isset($page['entetes']['X-Spip-Statique']) or $page['entetes']['X-Spip-Statique'] !== 'oui') {
178
-
179
-		// Cache invalide par la meta 'derniere_modif'
180
-		// sauf pour les bots, qui utilisent toujours le cache
181
-		if (!_IS_BOT
182
-			and $GLOBALS['derniere_modif_invalide']
183
-			and isset($GLOBALS['meta']['derniere_modif'])
184
-			and $date < $GLOBALS['meta']['derniere_modif']
185
-		) {
186
-			return 1;
187
-		}
188
-
189
-	}
190
-
191
-	// Sinon comparer l'age du fichier a sa duree de cache
192
-	$duree = intval($page['entetes']['X-Spip-Cache']);
193
-	$cache_mark = (isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0);
194
-	if ($duree == 0)  #CACHE{0}
195
-	{
196
-		return -1;
197
-	} // sauf pour les bots, qui utilisent toujours le cache
198
-	else {
199
-		if ((!_IS_BOT and $date + $duree < $now)
200
-			# le cache est anterieur a la derniere purge : l'ignorer, meme pour les bots
201
-			or $date < $cache_mark
202
-		) {
203
-			return _IS_BOT ? -1 : 1;
204
-		} else {
205
-			return 0;
206
-		}
207
-	}
142
+    $now = $_SERVER['REQUEST_TIME'];
143
+
144
+    // Apparition d'un nouvel article post-date ?
145
+    if (isset($GLOBALS['meta']['post_dates'])
146
+        and $GLOBALS['meta']['post_dates'] == 'non'
147
+        and isset($GLOBALS['meta']['date_prochain_postdate'])
148
+        and $now > $GLOBALS['meta']['date_prochain_postdate']
149
+    ) {
150
+        spip_log('Un article post-date invalide le cache');
151
+        include_spip('inc/rubriques');
152
+        calculer_prochain_postdate(true);
153
+    }
154
+
155
+    if (defined('_VAR_NOCACHE') and _VAR_NOCACHE) {
156
+        return -1;
157
+    }
158
+    if (isset($GLOBALS['meta']['cache_inhib']) and $_SERVER['REQUEST_TIME'] < $GLOBALS['meta']['cache_inhib']) {
159
+        return -1;
160
+    }
161
+    if (defined('_NO_CACHE')) {
162
+        return (_NO_CACHE == 0 and !isset($page['texte'])) ? 1 : _NO_CACHE;
163
+    }
164
+
165
+    // pas de cache ? on le met a jour, sauf pour les bots (on leur calcule la page sans mise en cache)
166
+    if (!$page or !isset($page['texte']) or !isset($page['entetes']['X-Spip-Cache'])) {
167
+        return _IS_BOT ? -1 : 1;
168
+    }
169
+
170
+    // controle de la signature
171
+    if ($page['sig'] !== cache_signature($page)) {
172
+        return _IS_BOT ? -1 : 1;
173
+    }
174
+
175
+    // #CACHE{n,statique} => on n'invalide pas avec derniere_modif
176
+    // cf. ecrire/public/balises.php, balise_CACHE_dist()
177
+    if (!isset($page['entetes']['X-Spip-Statique']) or $page['entetes']['X-Spip-Statique'] !== 'oui') {
178
+
179
+        // Cache invalide par la meta 'derniere_modif'
180
+        // sauf pour les bots, qui utilisent toujours le cache
181
+        if (!_IS_BOT
182
+            and $GLOBALS['derniere_modif_invalide']
183
+            and isset($GLOBALS['meta']['derniere_modif'])
184
+            and $date < $GLOBALS['meta']['derniere_modif']
185
+        ) {
186
+            return 1;
187
+        }
188
+
189
+    }
190
+
191
+    // Sinon comparer l'age du fichier a sa duree de cache
192
+    $duree = intval($page['entetes']['X-Spip-Cache']);
193
+    $cache_mark = (isset($GLOBALS['meta']['cache_mark']) ? $GLOBALS['meta']['cache_mark'] : 0);
194
+    if ($duree == 0)  #CACHE{0}
195
+    {
196
+        return -1;
197
+    } // sauf pour les bots, qui utilisent toujours le cache
198
+    else {
199
+        if ((!_IS_BOT and $date + $duree < $now)
200
+            # le cache est anterieur a la derniere purge : l'ignorer, meme pour les bots
201
+            or $date < $cache_mark
202
+        ) {
203
+            return _IS_BOT ? -1 : 1;
204
+        } else {
205
+            return 0;
206
+        }
207
+    }
208 208
 }
209 209
 
210 210
 /**
@@ -219,55 +219,55 @@  discard block
 block discarded – undo
219 219
  */
220 220
 function creer_cache(&$page, &$chemin_cache) {
221 221
 
222
-	// Ne rien faire si on est en preview, debug, ou si une erreur
223
-	// grave s'est presentee (compilation du squelette, MySQL, etc)
224
-	// le cas var_nocache ne devrait jamais arriver ici (securite)
225
-	// le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable
226
-	if ((defined('_VAR_NOCACHE') and _VAR_NOCACHE)
227
-		or defined('spip_interdire_cache')
228
-	) {
229
-		return;
230
-	}
231
-
232
-	// Si la page c1234 a un invalideur de session 'zz', sauver dans
233
-	// 'tmp/cache/MD5(chemin_cache)_zz'
234
-	if (isset($page['invalideurs'])
235
-		and isset($page['invalideurs']['session'])
236
-	) {
237
-		// on verifie que le contenu du chemin cache indique seulement
238
-		// "cache sessionne" ; sa date indique la date de validite
239
-		// des caches sessionnes
240
-		if (!$tmp = lire_cache($chemin_cache)) {
241
-			spip_log('Creation cache sessionne ' . $chemin_cache);
242
-			$tmp = array(
243
-				'invalideurs' => array('session' => ''),
244
-				'lastmodified' => $_SERVER['REQUEST_TIME']
245
-			);
246
-			ecrire_cache($chemin_cache, $tmp);
247
-		}
248
-		$chemin_cache = generer_nom_fichier_cache(array("chemin_cache" => $chemin_cache),
249
-			array("session" => $page['invalideurs']['session']));
250
-	}
251
-
252
-	// ajouter la date de production dans le cache lui meme
253
-	// (qui contient deja sa duree de validite)
254
-	$page['lastmodified'] = $_SERVER['REQUEST_TIME'];
255
-
256
-	// compresser le contenu si besoin
257
-	$pagez = gzip_page($page);
258
-
259
-	// signer le contenu
260
-	$pagez['sig'] = cache_signature($pagez);
261
-
262
-	// l'enregistrer, compresse ou non...
263
-	$ok = ecrire_cache($chemin_cache, $pagez);
264
-
265
-	spip_log((_IS_BOT ? "Bot:" : "") . "Creation du cache $chemin_cache pour "
266
-		. $page['entetes']['X-Spip-Cache'] . " secondes" . ($ok ? '' : ' (erreur!)'), _LOG_INFO_IMPORTANTE);
267
-
268
-	// Inserer ses invalideurs
269
-	include_spip('inc/invalideur');
270
-	maj_invalideurs($chemin_cache, $page);
222
+    // Ne rien faire si on est en preview, debug, ou si une erreur
223
+    // grave s'est presentee (compilation du squelette, MySQL, etc)
224
+    // le cas var_nocache ne devrait jamais arriver ici (securite)
225
+    // le cas spip_interdire_cache correspond a une ereur SQL grave non anticipable
226
+    if ((defined('_VAR_NOCACHE') and _VAR_NOCACHE)
227
+        or defined('spip_interdire_cache')
228
+    ) {
229
+        return;
230
+    }
231
+
232
+    // Si la page c1234 a un invalideur de session 'zz', sauver dans
233
+    // 'tmp/cache/MD5(chemin_cache)_zz'
234
+    if (isset($page['invalideurs'])
235
+        and isset($page['invalideurs']['session'])
236
+    ) {
237
+        // on verifie que le contenu du chemin cache indique seulement
238
+        // "cache sessionne" ; sa date indique la date de validite
239
+        // des caches sessionnes
240
+        if (!$tmp = lire_cache($chemin_cache)) {
241
+            spip_log('Creation cache sessionne ' . $chemin_cache);
242
+            $tmp = array(
243
+                'invalideurs' => array('session' => ''),
244
+                'lastmodified' => $_SERVER['REQUEST_TIME']
245
+            );
246
+            ecrire_cache($chemin_cache, $tmp);
247
+        }
248
+        $chemin_cache = generer_nom_fichier_cache(array("chemin_cache" => $chemin_cache),
249
+            array("session" => $page['invalideurs']['session']));
250
+    }
251
+
252
+    // ajouter la date de production dans le cache lui meme
253
+    // (qui contient deja sa duree de validite)
254
+    $page['lastmodified'] = $_SERVER['REQUEST_TIME'];
255
+
256
+    // compresser le contenu si besoin
257
+    $pagez = gzip_page($page);
258
+
259
+    // signer le contenu
260
+    $pagez['sig'] = cache_signature($pagez);
261
+
262
+    // l'enregistrer, compresse ou non...
263
+    $ok = ecrire_cache($chemin_cache, $pagez);
264
+
265
+    spip_log((_IS_BOT ? "Bot:" : "") . "Creation du cache $chemin_cache pour "
266
+        . $page['entetes']['X-Spip-Cache'] . " secondes" . ($ok ? '' : ' (erreur!)'), _LOG_INFO_IMPORTANTE);
267
+
268
+    // Inserer ses invalideurs
269
+    include_spip('inc/invalideur');
270
+    maj_invalideurs($chemin_cache, $page);
271 271
 
272 272
 }
273 273
 
@@ -283,15 +283,15 @@  discard block
 block discarded – undo
283 283
  * @return void
284 284
  */
285 285
 function nettoyer_petit_cache($prefix, $duree = 300) {
286
-	// determiner le repertoire a purger : 'tmp/CACHE/rech/'
287
-	$dircache = sous_repertoire(_DIR_CACHE, $prefix);
288
-	if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) {
289
-		foreach (preg_files($dircache, '[.]txt$') as $f) {
290
-			if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) {
291
-				spip_unlink($f);
292
-			}
293
-		}
294
-	}
286
+    // determiner le repertoire a purger : 'tmp/CACHE/rech/'
287
+    $dircache = sous_repertoire(_DIR_CACHE, $prefix);
288
+    if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) {
289
+        foreach (preg_files($dircache, '[.]txt$') as $f) {
290
+            if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) {
291
+                spip_unlink($f);
292
+            }
293
+        }
294
+    }
295 295
 }
296 296
 
297 297
 
@@ -321,126 +321,126 @@  discard block
 block discarded – undo
321 321
  */
322 322
 function public_cacher_dist($contexte, &$use_cache, &$chemin_cache, &$page, &$lastmodified) {
323 323
 
324
-	# fonction de cache minimale : dire "non on ne met rien en cache"
325
-	# $use_cache = -1; return;
326
-
327
-	// Second appel, destine a l'enregistrement du cache sur le disque
328
-	if (isset($chemin_cache)) {
329
-		return creer_cache($page, $chemin_cache);
330
-	}
331
-
332
-	// Toute la suite correspond au premier appel
333
-	$contexte_implicite = $page['contexte_implicite'];
334
-
335
-	// Cas ignorant le cache car completement dynamique
336
-	if ($_SERVER['REQUEST_METHOD'] == 'POST'
337
-		or _request('connect')
338
-	) {
339
-		$use_cache = -1;
340
-		$lastmodified = 0;
341
-		$chemin_cache = "";
342
-		$page = array();
343
-
344
-		return;
345
-	}
346
-
347
-	// Controler l'existence d'un cache nous correspondant
348
-	$chemin_cache = generer_nom_fichier_cache($contexte, $page);
349
-	$lastmodified = 0;
350
-
351
-	// charger le cache s'il existe (et si il a bien le bon hash = anticollision)
352
-	if (!$page = lire_cache($chemin_cache)) {
353
-		$page = array();
354
-	}
355
-
356
-	// s'il est sessionne, charger celui correspondant a notre session
357
-	if (isset($page['invalideurs'])
358
-		and isset($page['invalideurs']['session'])
359
-	) {
360
-		$chemin_cache_session = generer_nom_fichier_cache(array("chemin_cache" => $chemin_cache),
361
-			array("session" => spip_session()));
362
-		if ($page_session = lire_cache($chemin_cache_session)
363
-			and $page_session['lastmodified'] >= $page['lastmodified']
364
-		) {
365
-			$page = $page_session;
366
-		} else {
367
-			$page = array();
368
-		}
369
-	}
370
-
371
-
372
-	// Faut-il effacer des pages invalidees (en particulier ce cache-ci) ?
373
-	if (isset($GLOBALS['meta']['invalider'])) {
374
-		// ne le faire que si la base est disponible
375
-		if (spip_connect()) {
376
-			include_spip('inc/invalideur');
377
-			retire_caches($chemin_cache); # API invalideur inutile
378
-			supprimer_fichier(_DIR_CACHE . $chemin_cache);
379
-			if (isset($chemin_cache_session) and $chemin_cache_session) {
380
-				supprimer_fichier(_DIR_CACHE . $chemin_cache_session);
381
-			}
382
-		}
383
-	}
384
-
385
-	// Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande,
386
-	// on supprime le cache
387
-	if (defined('_VAR_MODE') && _VAR_MODE &&
388
-		(isset($_COOKIE['spip_session'])
389
-			|| isset($_COOKIE['spip_admin'])
390
-			|| @file_exists(_ACCESS_FILE_NAME))
391
-	) {
392
-		$page = array('contexte_implicite' => $contexte_implicite); // ignorer le cache deja lu
393
-		include_spip('inc/invalideur');
394
-		retire_caches($chemin_cache); # API invalideur inutile
395
-		supprimer_fichier(_DIR_CACHE . $chemin_cache);
396
-		if (isset($chemin_cache_session) and $chemin_cache_session) {
397
-			supprimer_fichier(_DIR_CACHE . $chemin_cache_session);
398
-		}
399
-	}
400
-
401
-	// $delais par defaut
402
-	// pour toutes les pages sans #CACHE{} hors modeles/ et espace privé
403
-	// qui sont a cache nul par defaut
404
-	if (!isset($GLOBALS['delais'])) {
405
-		if (!defined('_DUREE_CACHE_DEFAUT')) {
406
-			define('_DUREE_CACHE_DEFAUT', 24 * 3600);
407
-		}
408
-		$GLOBALS['delais'] = _DUREE_CACHE_DEFAUT;
409
-	}
410
-
411
-	// determiner la validite de la page
412
-	if ($page) {
413
-		$use_cache = cache_valide($page, isset($page['lastmodified']) ? $page['lastmodified'] : 0);
414
-		// le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence
415
-		// par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul
416
-		$page['contexte_implicite'] = $contexte_implicite;
417
-		if (!$use_cache) {
418
-			// $page est un cache utilisable
419
-			gunzip_page($page);
420
-
421
-			return;
422
-		}
423
-	} else {
424
-		$page = array('contexte_implicite' => $contexte_implicite);
425
-		$use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul
426
-	}
427
-
428
-	// Si pas valide mais pas de connexion a la base, le garder quand meme
429
-	if (!spip_connect()) {
430
-		if (isset($page['texte'])) {
431
-			gunzip_page($page);
432
-			$use_cache = 0;
433
-		} else {
434
-			spip_log("Erreur base de donnees, impossible utiliser $chemin_cache");
435
-			include_spip('inc/minipres');
436
-
437
-			return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503));
438
-		}
439
-	}
440
-
441
-	if ($use_cache < 0) {
442
-		$chemin_cache = '';
443
-	}
444
-
445
-	return;
324
+    # fonction de cache minimale : dire "non on ne met rien en cache"
325
+    # $use_cache = -1; return;
326
+
327
+    // Second appel, destine a l'enregistrement du cache sur le disque
328
+    if (isset($chemin_cache)) {
329
+        return creer_cache($page, $chemin_cache);
330
+    }
331
+
332
+    // Toute la suite correspond au premier appel
333
+    $contexte_implicite = $page['contexte_implicite'];
334
+
335
+    // Cas ignorant le cache car completement dynamique
336
+    if ($_SERVER['REQUEST_METHOD'] == 'POST'
337
+        or _request('connect')
338
+    ) {
339
+        $use_cache = -1;
340
+        $lastmodified = 0;
341
+        $chemin_cache = "";
342
+        $page = array();
343
+
344
+        return;
345
+    }
346
+
347
+    // Controler l'existence d'un cache nous correspondant
348
+    $chemin_cache = generer_nom_fichier_cache($contexte, $page);
349
+    $lastmodified = 0;
350
+
351
+    // charger le cache s'il existe (et si il a bien le bon hash = anticollision)
352
+    if (!$page = lire_cache($chemin_cache)) {
353
+        $page = array();
354
+    }
355
+
356
+    // s'il est sessionne, charger celui correspondant a notre session
357
+    if (isset($page['invalideurs'])
358
+        and isset($page['invalideurs']['session'])
359
+    ) {
360
+        $chemin_cache_session = generer_nom_fichier_cache(array("chemin_cache" => $chemin_cache),
361
+            array("session" => spip_session()));
362
+        if ($page_session = lire_cache($chemin_cache_session)
363
+            and $page_session['lastmodified'] >= $page['lastmodified']
364
+        ) {
365
+            $page = $page_session;
366
+        } else {
367
+            $page = array();
368
+        }
369
+    }
370
+
371
+
372
+    // Faut-il effacer des pages invalidees (en particulier ce cache-ci) ?
373
+    if (isset($GLOBALS['meta']['invalider'])) {
374
+        // ne le faire que si la base est disponible
375
+        if (spip_connect()) {
376
+            include_spip('inc/invalideur');
377
+            retire_caches($chemin_cache); # API invalideur inutile
378
+            supprimer_fichier(_DIR_CACHE . $chemin_cache);
379
+            if (isset($chemin_cache_session) and $chemin_cache_session) {
380
+                supprimer_fichier(_DIR_CACHE . $chemin_cache_session);
381
+            }
382
+        }
383
+    }
384
+
385
+    // Si un calcul, recalcul [ou preview, mais c'est recalcul] est demande,
386
+    // on supprime le cache
387
+    if (defined('_VAR_MODE') && _VAR_MODE &&
388
+        (isset($_COOKIE['spip_session'])
389
+            || isset($_COOKIE['spip_admin'])
390
+            || @file_exists(_ACCESS_FILE_NAME))
391
+    ) {
392
+        $page = array('contexte_implicite' => $contexte_implicite); // ignorer le cache deja lu
393
+        include_spip('inc/invalideur');
394
+        retire_caches($chemin_cache); # API invalideur inutile
395
+        supprimer_fichier(_DIR_CACHE . $chemin_cache);
396
+        if (isset($chemin_cache_session) and $chemin_cache_session) {
397
+            supprimer_fichier(_DIR_CACHE . $chemin_cache_session);
398
+        }
399
+    }
400
+
401
+    // $delais par defaut
402
+    // pour toutes les pages sans #CACHE{} hors modeles/ et espace privé
403
+    // qui sont a cache nul par defaut
404
+    if (!isset($GLOBALS['delais'])) {
405
+        if (!defined('_DUREE_CACHE_DEFAUT')) {
406
+            define('_DUREE_CACHE_DEFAUT', 24 * 3600);
407
+        }
408
+        $GLOBALS['delais'] = _DUREE_CACHE_DEFAUT;
409
+    }
410
+
411
+    // determiner la validite de la page
412
+    if ($page) {
413
+        $use_cache = cache_valide($page, isset($page['lastmodified']) ? $page['lastmodified'] : 0);
414
+        // le contexte implicite n'est pas stocke dans le cache, mais il y a equivalence
415
+        // par le nom du cache. On le reinjecte donc ici pour utilisation eventuelle au calcul
416
+        $page['contexte_implicite'] = $contexte_implicite;
417
+        if (!$use_cache) {
418
+            // $page est un cache utilisable
419
+            gunzip_page($page);
420
+
421
+            return;
422
+        }
423
+    } else {
424
+        $page = array('contexte_implicite' => $contexte_implicite);
425
+        $use_cache = cache_valide($page, 0); // fichier cache absent : provoque le calcul
426
+    }
427
+
428
+    // Si pas valide mais pas de connexion a la base, le garder quand meme
429
+    if (!spip_connect()) {
430
+        if (isset($page['texte'])) {
431
+            gunzip_page($page);
432
+            $use_cache = 0;
433
+        } else {
434
+            spip_log("Erreur base de donnees, impossible utiliser $chemin_cache");
435
+            include_spip('inc/minipres');
436
+
437
+            return minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), array('status' => 503));
438
+        }
439
+    }
440
+
441
+    if ($use_cache < 0) {
442
+        $chemin_cache = '';
443
+    }
444
+
445
+    return;
446 446
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 function generer_nom_fichier_cache($contexte, $page) {
30 30
 	$u = md5(var_export(array($contexte, $page), true));
31 31
 
32
-	return $u . ".cache";
32
+	return $u.".cache";
33 33
 }
34 34
 
35 35
 /**
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	$rep = sous_repertoire($rep, '', false, true);
47 47
 	$rep = sous_repertoire($rep, $d, false, true);
48 48
 
49
-	return ecrire_fichier($rep . $u . ".cache", serialize(array("nom_cache" => $nom_cache, "valeur" => $valeur)));
49
+	return ecrire_fichier($rep.$u.".cache", serialize(array("nom_cache" => $nom_cache, "valeur" => $valeur)));
50 50
 }
51 51
 
52 52
 /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 function lire_cache($nom_cache) {
59 59
 	$d = substr($nom_cache, 0, 2);
60 60
 	$u = substr($nom_cache, 2, 2);
61
-	if (file_exists($f = _DIR_CACHE . "$d/$u.cache")
61
+	if (file_exists($f = _DIR_CACHE."$d/$u.cache")
62 62
 		and lire_fichier($f, $tmp)
63 63
 		and $tmp = unserialize($tmp)
64 64
 		and $tmp['nom_cache'] == $nom_cache
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 			), 'non');
85 85
 	}
86 86
 
87
-	return crc32($GLOBALS['meta']['cache_signature'] . $page['texte']);
87
+	return crc32($GLOBALS['meta']['cache_signature'].$page['texte']);
88 88
 }
89 89
 
90 90
 /**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		// "cache sessionne" ; sa date indique la date de validite
239 239
 		// des caches sessionnes
240 240
 		if (!$tmp = lire_cache($chemin_cache)) {
241
-			spip_log('Creation cache sessionne ' . $chemin_cache);
241
+			spip_log('Creation cache sessionne '.$chemin_cache);
242 242
 			$tmp = array(
243 243
 				'invalideurs' => array('session' => ''),
244 244
 				'lastmodified' => $_SERVER['REQUEST_TIME']
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
 	// l'enregistrer, compresse ou non...
263 263
 	$ok = ecrire_cache($chemin_cache, $pagez);
264 264
 
265
-	spip_log((_IS_BOT ? "Bot:" : "") . "Creation du cache $chemin_cache pour "
266
-		. $page['entetes']['X-Spip-Cache'] . " secondes" . ($ok ? '' : ' (erreur!)'), _LOG_INFO_IMPORTANTE);
265
+	spip_log((_IS_BOT ? "Bot:" : "")."Creation du cache $chemin_cache pour "
266
+		. $page['entetes']['X-Spip-Cache']." secondes".($ok ? '' : ' (erreur!)'), _LOG_INFO_IMPORTANTE);
267 267
 
268 268
 	// Inserer ses invalideurs
269 269
 	include_spip('inc/invalideur');
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 function nettoyer_petit_cache($prefix, $duree = 300) {
286 286
 	// determiner le repertoire a purger : 'tmp/CACHE/rech/'
287 287
 	$dircache = sous_repertoire(_DIR_CACHE, $prefix);
288
-	if (spip_touch($dircache . 'purger_' . $prefix, $duree, true)) {
288
+	if (spip_touch($dircache.'purger_'.$prefix, $duree, true)) {
289 289
 		foreach (preg_files($dircache, '[.]txt$') as $f) {
290 290
 			if ($_SERVER['REQUEST_TIME'] - (@file_exists($f) ? @filemtime($f) : 0) > $duree) {
291 291
 				spip_unlink($f);
@@ -375,9 +375,9 @@  discard block
 block discarded – undo
375 375
 		if (spip_connect()) {
376 376
 			include_spip('inc/invalideur');
377 377
 			retire_caches($chemin_cache); # API invalideur inutile
378
-			supprimer_fichier(_DIR_CACHE . $chemin_cache);
378
+			supprimer_fichier(_DIR_CACHE.$chemin_cache);
379 379
 			if (isset($chemin_cache_session) and $chemin_cache_session) {
380
-				supprimer_fichier(_DIR_CACHE . $chemin_cache_session);
380
+				supprimer_fichier(_DIR_CACHE.$chemin_cache_session);
381 381
 			}
382 382
 		}
383 383
 	}
@@ -392,9 +392,9 @@  discard block
 block discarded – undo
392 392
 		$page = array('contexte_implicite' => $contexte_implicite); // ignorer le cache deja lu
393 393
 		include_spip('inc/invalideur');
394 394
 		retire_caches($chemin_cache); # API invalideur inutile
395
-		supprimer_fichier(_DIR_CACHE . $chemin_cache);
395
+		supprimer_fichier(_DIR_CACHE.$chemin_cache);
396 396
 		if (isset($chemin_cache_session) and $chemin_cache_session) {
397
-			supprimer_fichier(_DIR_CACHE . $chemin_cache_session);
397
+			supprimer_fichier(_DIR_CACHE.$chemin_cache_session);
398 398
 		}
399 399
 	}
400 400
 
Please login to merge, or discard this patch.