Completed
Push — master ( f9980f...501063 )
by cam
01:32
created
ecrire/inc/utils.php 1 patch
Indentation   +2265 added lines, -2266 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
 
@@ -48,71 +48,71 @@  discard block
 block discarded – undo
48 48
  *     Nom de la fonction, ou false.
49 49
  */
50 50
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
51
-	static $echecs = [];
52
-
53
-	if (strlen($dossier) and substr($dossier, -1) != '/') {
54
-		$dossier .= '/';
55
-	}
56
-	$f = str_replace('/', '_', $dossier) . $nom;
57
-
58
-	if (function_exists($f)) {
59
-		return $f;
60
-	}
61
-	if (function_exists($g = $f . '_dist')) {
62
-		return $g;
63
-	}
64
-
65
-	if (isset($echecs[$f])) {
66
-		return $echecs[$f];
67
-	}
68
-	// Sinon charger le fichier de declaration si plausible
69
-
70
-	if (!preg_match(',^\w+$,', $f)) {
71
-		if ($continue) {
72
-			return false;
73
-		} //appel interne, on passe
74
-		include_spip('inc/minipres');
75
-		echo minipres();
76
-		exit;
77
-	}
78
-
79
-	// passer en minuscules (cf les balises de formulaires)
80
-	// et inclure le fichier
81
-	if (
82
-		!$inc = include_spip($dossier . ($d = strtolower($nom)))
83
-		// si le fichier truc/machin/nom.php n'existe pas,
84
-		// la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
-		and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
-	) {
87
-		include_spip(substr($dossier, 0, -1));
88
-	}
89
-	if (function_exists($f)) {
90
-		return $f;
91
-	}
92
-	if (function_exists($g)) {
93
-		return $g;
94
-	}
95
-
96
-	if ($continue) {
97
-		return $echecs[$f] = false;
98
-	}
99
-
100
-	// Echec : message d'erreur
101
-	spip_log("fonction $nom ($f ou $g) indisponible" .
102
-		($inc ? '' : " (fichier $d absent de $dossier)"));
103
-
104
-	include_spip('inc/minipres');
105
-	echo minipres(
106
-		_T('forum_titre_erreur'),
107
-		$inc ?
108
-			_T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
109
-			. '<br />'
110
-			. _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
111
-			:
112
-			_T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
113
-		['all_inline' => true,'status' => 404]
114
-	);
115
-	exit;
51
+    static $echecs = [];
52
+
53
+    if (strlen($dossier) and substr($dossier, -1) != '/') {
54
+        $dossier .= '/';
55
+    }
56
+    $f = str_replace('/', '_', $dossier) . $nom;
57
+
58
+    if (function_exists($f)) {
59
+        return $f;
60
+    }
61
+    if (function_exists($g = $f . '_dist')) {
62
+        return $g;
63
+    }
64
+
65
+    if (isset($echecs[$f])) {
66
+        return $echecs[$f];
67
+    }
68
+    // Sinon charger le fichier de declaration si plausible
69
+
70
+    if (!preg_match(',^\w+$,', $f)) {
71
+        if ($continue) {
72
+            return false;
73
+        } //appel interne, on passe
74
+        include_spip('inc/minipres');
75
+        echo minipres();
76
+        exit;
77
+    }
78
+
79
+    // passer en minuscules (cf les balises de formulaires)
80
+    // et inclure le fichier
81
+    if (
82
+        !$inc = include_spip($dossier . ($d = strtolower($nom)))
83
+        // si le fichier truc/machin/nom.php n'existe pas,
84
+        // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions
85
+        and strlen(dirname($dossier)) and dirname($dossier) != '.'
86
+    ) {
87
+        include_spip(substr($dossier, 0, -1));
88
+    }
89
+    if (function_exists($f)) {
90
+        return $f;
91
+    }
92
+    if (function_exists($g)) {
93
+        return $g;
94
+    }
95
+
96
+    if ($continue) {
97
+        return $echecs[$f] = false;
98
+    }
99
+
100
+    // Echec : message d'erreur
101
+    spip_log("fonction $nom ($f ou $g) indisponible" .
102
+        ($inc ? '' : " (fichier $d absent de $dossier)"));
103
+
104
+    include_spip('inc/minipres');
105
+    echo minipres(
106
+        _T('forum_titre_erreur'),
107
+        $inc ?
108
+            _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
109
+            . '<br />'
110
+            . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
111
+            :
112
+            _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
113
+        ['all_inline' => true,'status' => 404]
114
+    );
115
+    exit;
116 116
 }
117 117
 
118 118
 /**
@@ -122,17 +122,17 @@  discard block
 block discarded – undo
122 122
  * @return bool
123 123
  */
124 124
 function include_once_check($file) {
125
-	if (file_exists($file)) {
126
-		include_once $file;
125
+    if (file_exists($file)) {
126
+        include_once $file;
127 127
 
128
-		return true;
129
-	}
130
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
131
-	$crash = ($crash ?: []);
132
-	$crash[$file] = true;
133
-	ecrire_meta('message_crash_plugins', serialize($crash));
128
+        return true;
129
+    }
130
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
131
+    $crash = ($crash ?: []);
132
+    $crash[$file] = true;
133
+    ecrire_meta('message_crash_plugins', serialize($crash));
134 134
 
135
-	return false;
135
+    return false;
136 136
 }
137 137
 
138 138
 
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
  *     - string : chemin du fichier trouvé
157 157
  **/
158 158
 function include_spip($f, $include = true) {
159
-	return find_in_path($f . '.php', '', $include);
159
+    return find_in_path($f . '.php', '', $include);
160 160
 }
161 161
 
162 162
 /**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
  *     - string : chemin du fichier trouvé
177 177
  **/
178 178
 function require_spip($f) {
179
-	return find_in_path($f . '.php', '', 'required');
179
+    return find_in_path($f . '.php', '', 'required');
180 180
 }
181 181
 
182 182
 
@@ -185,27 +185,27 @@  discard block
 block discarded – undo
185 185
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
186 186
  */
187 187
 function include_fichiers_fonctions() {
188
-	static $done = false;
189
-	if (!$done) {
190
-		include_spip('inc/lang');
191
-
192
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
193
-		// donc il faut l'inclure "en globals"
194
-		if ($f = find_in_path('mes_fonctions.php')) {
195
-			global $dossier_squelettes;
196
-			include_once(_ROOT_CWD . $f);
197
-		}
198
-
199
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
200
-			// chargement optimise precompile
201
-			include_once(_CACHE_PLUGINS_FCT);
202
-		}
203
-		if (test_espace_prive()) {
204
-			include_spip('inc/filtres_ecrire');
205
-		}
206
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
207
-		$done = true;
208
-	}
188
+    static $done = false;
189
+    if (!$done) {
190
+        include_spip('inc/lang');
191
+
192
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
193
+        // donc il faut l'inclure "en globals"
194
+        if ($f = find_in_path('mes_fonctions.php')) {
195
+            global $dossier_squelettes;
196
+            include_once(_ROOT_CWD . $f);
197
+        }
198
+
199
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
200
+            // chargement optimise precompile
201
+            include_once(_CACHE_PLUGINS_FCT);
202
+        }
203
+        if (test_espace_prive()) {
204
+            include_spip('inc/filtres_ecrire');
205
+        }
206
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
207
+        $done = true;
208
+    }
209 209
 }
210 210
 
211 211
 /**
@@ -231,23 +231,23 @@  discard block
 block discarded – undo
231 231
  *     Les paramètres du pipeline modifiés
232 232
  **/
233 233
 function minipipe($fonc, &$val) {
234
-	// fonction
235
-	if (function_exists($fonc)) {
236
-		$val = $fonc($val);
237
-	} // Class::Methode
238
-	else {
239
-		if (
240
-			preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
241
-			and $methode = [$regs[1], $regs[2]]
242
-			and is_callable($methode)
243
-		) {
244
-			$val = $methode($val);
245
-		} else {
246
-			spip_log("Erreur - '$fonc' non definie !");
247
-		}
248
-	}
249
-
250
-	return $val;
234
+    // fonction
235
+    if (function_exists($fonc)) {
236
+        $val = $fonc($val);
237
+    } // Class::Methode
238
+    else {
239
+        if (
240
+            preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
241
+            and $methode = [$regs[1], $regs[2]]
242
+            and is_callable($methode)
243
+        ) {
244
+            $val = $methode($val);
245
+        } else {
246
+            spip_log("Erreur - '$fonc' non definie !");
247
+        }
248
+    }
249
+
250
+    return $val;
251 251
 }
252 252
 
253 253
 /**
@@ -278,46 +278,46 @@  discard block
 block discarded – undo
278 278
  *     Résultat
279 279
  */
280 280
 function pipeline($action, $val = null) {
281
-	static $charger;
282
-
283
-	// chargement initial des fonctions mises en cache, ou generation du cache
284
-	if (!$charger) {
285
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
286
-			include_spip('inc/plugin');
287
-			// generer les fichiers php precompiles
288
-			// de chargement des plugins et des pipelines
289
-			actualise_plugins_actifs();
290
-			if (!($ok = @is_readable($charger))) {
291
-				spip_log("fichier $charger pas cree");
292
-			}
293
-		}
294
-
295
-		if ($ok) {
296
-			include_once $charger;
297
-		}
298
-	}
299
-
300
-	// appliquer notre fonction si elle existe
301
-	$fonc = 'execute_pipeline_' . strtolower($action);
302
-	if (function_exists($fonc)) {
303
-		$val = $fonc($val);
304
-	} // plantage ?
305
-	else {
306
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
307
-	}
308
-
309
-	// si le flux est une table avec 2 cle args&data
310
-	// on ne ressort du pipe que les donnees dans 'data'
311
-	// array_key_exists pour php 4.1.0
312
-	if (
313
-		is_array($val)
314
-		and count($val) == 2
315
-		and (array_key_exists('data', $val))
316
-	) {
317
-		$val = $val['data'];
318
-	}
319
-
320
-	return $val;
281
+    static $charger;
282
+
283
+    // chargement initial des fonctions mises en cache, ou generation du cache
284
+    if (!$charger) {
285
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
286
+            include_spip('inc/plugin');
287
+            // generer les fichiers php precompiles
288
+            // de chargement des plugins et des pipelines
289
+            actualise_plugins_actifs();
290
+            if (!($ok = @is_readable($charger))) {
291
+                spip_log("fichier $charger pas cree");
292
+            }
293
+        }
294
+
295
+        if ($ok) {
296
+            include_once $charger;
297
+        }
298
+    }
299
+
300
+    // appliquer notre fonction si elle existe
301
+    $fonc = 'execute_pipeline_' . strtolower($action);
302
+    if (function_exists($fonc)) {
303
+        $val = $fonc($val);
304
+    } // plantage ?
305
+    else {
306
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
307
+    }
308
+
309
+    // si le flux est une table avec 2 cle args&data
310
+    // on ne ressort du pipe que les donnees dans 'data'
311
+    // array_key_exists pour php 4.1.0
312
+    if (
313
+        is_array($val)
314
+        and count($val) == 2
315
+        and (array_key_exists('data', $val))
316
+    ) {
317
+        $val = $val['data'];
318
+    }
319
+
320
+    return $val;
321 321
 }
322 322
 
323 323
 /**
@@ -361,38 +361,38 @@  discard block
 block discarded – undo
361 361
  *     paramètre est planté pour cause de compatibilité ascendante.
362 362
  */
363 363
 function spip_log($message = null, $name = null) {
364
-	static $pre = [];
365
-	static $log;
366
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
367
-	if (!isset($regs[1]) or !$logname = $regs[1]) {
368
-		$logname = null;
369
-	}
370
-	if (!isset($regs[2])) {
371
-		$niveau = _LOG_INFO;
372
-	}
373
-	else {
374
-		$niveau = intval($regs[2]);
375
-	}
376
-
377
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
378
-		if (!$pre) {
379
-			$pre = [
380
-				_LOG_HS => 'HS:',
381
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
382
-				_LOG_CRITIQUE => 'CRITIQUE:',
383
-				_LOG_ERREUR => 'ERREUR:',
384
-				_LOG_AVERTISSEMENT => 'WARNING:',
385
-				_LOG_INFO_IMPORTANTE => '!INFO:',
386
-				_LOG_INFO => 'info:',
387
-				_LOG_DEBUG => 'debug:'
388
-			];
389
-			$log = charger_fonction('log', 'inc');
390
-		}
391
-		if (!is_string($message)) {
392
-			$message = print_r($message, true);
393
-		}
394
-		$log($pre[$niveau] . ' ' . $message, $logname);
395
-	}
364
+    static $pre = [];
365
+    static $log;
366
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
367
+    if (!isset($regs[1]) or !$logname = $regs[1]) {
368
+        $logname = null;
369
+    }
370
+    if (!isset($regs[2])) {
371
+        $niveau = _LOG_INFO;
372
+    }
373
+    else {
374
+        $niveau = intval($regs[2]);
375
+    }
376
+
377
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
378
+        if (!$pre) {
379
+            $pre = [
380
+                _LOG_HS => 'HS:',
381
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
382
+                _LOG_CRITIQUE => 'CRITIQUE:',
383
+                _LOG_ERREUR => 'ERREUR:',
384
+                _LOG_AVERTISSEMENT => 'WARNING:',
385
+                _LOG_INFO_IMPORTANTE => '!INFO:',
386
+                _LOG_INFO => 'info:',
387
+                _LOG_DEBUG => 'debug:'
388
+            ];
389
+            $log = charger_fonction('log', 'inc');
390
+        }
391
+        if (!is_string($message)) {
392
+            $message = print_r($message, true);
393
+        }
394
+        $log($pre[$niveau] . ' ' . $message, $logname);
395
+    }
396 396
 }
397 397
 
398 398
 /**
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
  * @param array $opt Tableau d'options
404 404
  **/
405 405
 function journal($phrase, $opt = []) {
406
-	$journal = charger_fonction('journal', 'inc');
407
-	$journal($phrase, $opt);
406
+    $journal = charger_fonction('journal', 'inc');
407
+    $journal($phrase, $opt);
408 408
 }
409 409
 
410 410
 
@@ -423,37 +423,37 @@  discard block
 block discarded – undo
423 423
  **/
424 424
 function _request($var, $c = false) {
425 425
 
426
-	if (is_array($c)) {
427
-		return $c[$var] ?? null;
428
-	}
429
-
430
-	if (isset($_GET[$var])) {
431
-		$a = $_GET[$var];
432
-	} elseif (isset($_POST[$var])) {
433
-		$a = $_POST[$var];
434
-	} else {
435
-		return null;
436
-	}
437
-
438
-	// Si on est en ajax et en POST tout a ete encode
439
-	// via encodeURIComponent, il faut donc repasser
440
-	// dans le charset local...
441
-	if (
442
-		defined('_AJAX')
443
-		and _AJAX
444
-		and isset($GLOBALS['meta']['charset'])
445
-		and $GLOBALS['meta']['charset'] != 'utf-8'
446
-		and is_string($a)
447
-		// check rapide mais pas fiable
448
-		and preg_match(',[\x80-\xFF],', $a)
449
-		// check fiable
450
-		and include_spip('inc/charsets')
451
-		and is_utf8($a)
452
-	) {
453
-		return importer_charset($a, 'utf-8');
454
-	}
455
-
456
-	return $a;
426
+    if (is_array($c)) {
427
+        return $c[$var] ?? null;
428
+    }
429
+
430
+    if (isset($_GET[$var])) {
431
+        $a = $_GET[$var];
432
+    } elseif (isset($_POST[$var])) {
433
+        $a = $_POST[$var];
434
+    } else {
435
+        return null;
436
+    }
437
+
438
+    // Si on est en ajax et en POST tout a ete encode
439
+    // via encodeURIComponent, il faut donc repasser
440
+    // dans le charset local...
441
+    if (
442
+        defined('_AJAX')
443
+        and _AJAX
444
+        and isset($GLOBALS['meta']['charset'])
445
+        and $GLOBALS['meta']['charset'] != 'utf-8'
446
+        and is_string($a)
447
+        // check rapide mais pas fiable
448
+        and preg_match(',[\x80-\xFF],', $a)
449
+        // check fiable
450
+        and include_spip('inc/charsets')
451
+        and is_utf8($a)
452
+    ) {
453
+        return importer_charset($a, 'utf-8');
454
+    }
455
+
456
+    return $a;
457 457
 }
458 458
 
459 459
 
@@ -471,22 +471,22 @@  discard block
 block discarded – undo
471 471
  *     - false sinon
472 472
  **/
473 473
 function set_request($var, $val = null, $c = false) {
474
-	if (is_array($c)) {
475
-		unset($c[$var]);
476
-		if ($val !== null) {
477
-			$c[$var] = $val;
478
-		}
474
+    if (is_array($c)) {
475
+        unset($c[$var]);
476
+        if ($val !== null) {
477
+            $c[$var] = $val;
478
+        }
479 479
 
480
-		return $c;
481
-	}
480
+        return $c;
481
+    }
482 482
 
483
-	unset($_GET[$var]);
484
-	unset($_POST[$var]);
485
-	if ($val !== null) {
486
-		$_GET[$var] = $val;
487
-	}
483
+    unset($_GET[$var]);
484
+    unset($_POST[$var]);
485
+    if ($val !== null) {
486
+        $_GET[$var] = $val;
487
+    }
488 488
 
489
-	return false; # n'affecte pas $c
489
+    return false; # n'affecte pas $c
490 490
 }
491 491
 
492 492
 /**
@@ -506,25 +506,25 @@  discard block
 block discarded – undo
506 506
  * @return array|mixed|string
507 507
  */
508 508
 function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') {
509
-	if (is_array($value)) {
510
-		if ($key == '*') {
511
-			$key = array_keys($value);
512
-		}
513
-		if (!is_array($key)) {
514
-			$key = [$key];
515
-		}
516
-		foreach ($key as $k) {
517
-			if (!empty($value[$k])) {
518
-				$value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
519
-			}
520
-		}
521
-		return $value;
522
-	}
523
-	// si la valeur vient des GET ou POST on la sanitize
524
-	if (!empty($value) and $value == _request($key)) {
525
-		$value = $sanitize_function($value);
526
-	}
527
-	return $value;
509
+    if (is_array($value)) {
510
+        if ($key == '*') {
511
+            $key = array_keys($value);
512
+        }
513
+        if (!is_array($key)) {
514
+            $key = [$key];
515
+        }
516
+        foreach ($key as $k) {
517
+            if (!empty($value[$k])) {
518
+                $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function);
519
+            }
520
+        }
521
+        return $value;
522
+    }
523
+    // si la valeur vient des GET ou POST on la sanitize
524
+    if (!empty($value) and $value == _request($key)) {
525
+        $value = $sanitize_function($value);
526
+    }
527
+    return $value;
528 528
 }
529 529
 
530 530
 /**
@@ -532,23 +532,22 @@  discard block
 block discarded – undo
532 532
  *
533 533
  * On est sur le web, on exclut certains protocoles,
534 534
  * notamment 'file://', 'php://' et d'autres…
535
-
536 535
  * @param string $url
537 536
  * @return bool
538 537
  */
539 538
 function tester_url_absolue($url) {
540
-	$url = trim($url ?? '');
541
-	if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
542
-		if (
543
-			isset($m[1])
544
-			and $p = strtolower(rtrim($m[1], ':'))
545
-			and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
546
-		) {
547
-			return false;
548
-		}
549
-		return true;
550
-	}
551
-	return false;
539
+    $url = trim($url ?? '');
540
+    if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) {
541
+        if (
542
+            isset($m[1])
543
+            and $p = strtolower(rtrim($m[1], ':'))
544
+            and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip'])
545
+        ) {
546
+            return false;
547
+        }
548
+        return true;
549
+    }
550
+    return false;
552 551
 }
553 552
 
554 553
 /**
@@ -570,100 +569,100 @@  discard block
 block discarded – undo
570 569
  * @return string URL
571 570
  */
572 571
 function parametre_url($url, $c, $v = null, $sep = '&amp;') {
573
-	// requete erronnee : plusieurs variable dans $c et aucun $v
574
-	if (strpos($c, '|') !== false and is_null($v)) {
575
-		return null;
576
-	}
577
-
578
-	// lever l'#ancre
579
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
580
-		$url = $r[1];
581
-		$ancre = $r[2];
582
-	} else {
583
-		$ancre = '';
584
-	}
585
-
586
-	// eclater
587
-	$url = preg_split(',[?]|&amp;|&,', $url);
588
-
589
-	// recuperer la base
590
-	$a = array_shift($url);
591
-	if (!$a) {
592
-		$a = './';
593
-	}
594
-
595
-	// preparer la regexp de maniere securisee
596
-	$regexp = explode('|', $c);
597
-	foreach ($regexp as $r => $e) {
598
-		$regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e));
599
-	}
600
-	$regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
601
-	$ajouts = array_flip(explode('|', $c));
602
-	$u = is_array($v) ? $v : rawurlencode((string) $v);
603
-	$testv = (is_array($v) ? count($v) : strlen((string) $v));
604
-	$v_read = null;
605
-	// lire les variables et agir
606
-	foreach ($url as $n => $val) {
607
-		if (preg_match($regexp, urldecode($val), $r)) {
608
-			$r = array_pad($r, 3, null);
609
-			if ($v === null) {
610
-				// c'est un tableau, on memorise les valeurs
611
-				if (substr($r[1], -2) == '[]') {
612
-					if (!$v_read) {
613
-						$v_read = [];
614
-					}
615
-					$v_read[] = $r[2] ? substr($r[2], 1) : '';
616
-				} // c'est un scalaire, on retourne direct
617
-				else {
618
-					return $r[2] ? substr($r[2], 1) : '';
619
-				}
620
-			} // suppression
621
-			elseif (!$testv) {
622
-				unset($url[$n]);
623
-			}
624
-			// Ajout. Pour une variable, remplacer au meme endroit,
625
-			// pour un tableau ce sera fait dans la prochaine boucle
626
-			elseif (substr($r[1], -2) != '[]') {
627
-				$url[$n] = $r[1] . '=' . $u;
628
-				unset($ajouts[$r[1]]);
629
-			}
630
-			// Pour les tableaux on laisse tomber les valeurs de
631
-			// départ, on remplira à l'étape suivante
632
-			else {
633
-				unset($url[$n]);
634
-			}
635
-		}
636
-	}
637
-
638
-	// traiter les parametres pas encore trouves
639
-	if (
640
-		$v === null
641
-		and $args = func_get_args()
642
-		and count($args) == 2
643
-	) {
644
-		return $v_read; // rien trouve ou un tableau
645
-	} elseif ($testv) {
646
-		foreach ($ajouts as $k => $n) {
647
-			if (!is_array($v)) {
648
-				$url[] = $k . '=' . $u;
649
-			} else {
650
-				$id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
651
-				foreach ($v as $w) {
652
-					$url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
653
-				}
654
-			}
655
-		}
656
-	}
657
-
658
-	// eliminer les vides
659
-	$url = array_filter($url);
660
-
661
-	// recomposer l'adresse
662
-	if ($url) {
663
-		$a .= '?' . join($sep, $url);
664
-	}
665
-
666
-	return $a . $ancre;
572
+    // requete erronnee : plusieurs variable dans $c et aucun $v
573
+    if (strpos($c, '|') !== false and is_null($v)) {
574
+        return null;
575
+    }
576
+
577
+    // lever l'#ancre
578
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
579
+        $url = $r[1];
580
+        $ancre = $r[2];
581
+    } else {
582
+        $ancre = '';
583
+    }
584
+
585
+    // eclater
586
+    $url = preg_split(',[?]|&amp;|&,', $url);
587
+
588
+    // recuperer la base
589
+    $a = array_shift($url);
590
+    if (!$a) {
591
+        $a = './';
592
+    }
593
+
594
+    // preparer la regexp de maniere securisee
595
+    $regexp = explode('|', $c);
596
+    foreach ($regexp as $r => $e) {
597
+        $regexp[$r] = str_replace('[]', '\[\]', preg_replace(',[^\w\d\[\]-],', '', $e));
598
+    }
599
+    $regexp = ',^(' . implode('|', $regexp) . '[[]?[]]?)(=.*)?$,';
600
+    $ajouts = array_flip(explode('|', $c));
601
+    $u = is_array($v) ? $v : rawurlencode((string) $v);
602
+    $testv = (is_array($v) ? count($v) : strlen((string) $v));
603
+    $v_read = null;
604
+    // lire les variables et agir
605
+    foreach ($url as $n => $val) {
606
+        if (preg_match($regexp, urldecode($val), $r)) {
607
+            $r = array_pad($r, 3, null);
608
+            if ($v === null) {
609
+                // c'est un tableau, on memorise les valeurs
610
+                if (substr($r[1], -2) == '[]') {
611
+                    if (!$v_read) {
612
+                        $v_read = [];
613
+                    }
614
+                    $v_read[] = $r[2] ? substr($r[2], 1) : '';
615
+                } // c'est un scalaire, on retourne direct
616
+                else {
617
+                    return $r[2] ? substr($r[2], 1) : '';
618
+                }
619
+            } // suppression
620
+            elseif (!$testv) {
621
+                unset($url[$n]);
622
+            }
623
+            // Ajout. Pour une variable, remplacer au meme endroit,
624
+            // pour un tableau ce sera fait dans la prochaine boucle
625
+            elseif (substr($r[1], -2) != '[]') {
626
+                $url[$n] = $r[1] . '=' . $u;
627
+                unset($ajouts[$r[1]]);
628
+            }
629
+            // Pour les tableaux on laisse tomber les valeurs de
630
+            // départ, on remplira à l'étape suivante
631
+            else {
632
+                unset($url[$n]);
633
+            }
634
+        }
635
+    }
636
+
637
+    // traiter les parametres pas encore trouves
638
+    if (
639
+        $v === null
640
+        and $args = func_get_args()
641
+        and count($args) == 2
642
+    ) {
643
+        return $v_read; // rien trouve ou un tableau
644
+    } elseif ($testv) {
645
+        foreach ($ajouts as $k => $n) {
646
+            if (!is_array($v)) {
647
+                $url[] = $k . '=' . $u;
648
+            } else {
649
+                $id = (substr($k, -2) == '[]') ? $k : ($k . '[]');
650
+                foreach ($v as $w) {
651
+                    $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w));
652
+                }
653
+            }
654
+        }
655
+    }
656
+
657
+    // eliminer les vides
658
+    $url = array_filter($url);
659
+
660
+    // recomposer l'adresse
661
+    if ($url) {
662
+        $a .= '?' . join($sep, $url);
663
+    }
664
+
665
+    return $a . $ancre;
667 666
 }
668 667
 
669 668
 /**
@@ -681,21 +680,21 @@  discard block
 block discarded – undo
681 680
  * @return string
682 681
  */
683 682
 function ancre_url($url, $ancre) {
684
-	// lever l'#ancre
685
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
686
-		$url = $r[1];
687
-	}
688
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
689
-		if (!function_exists('translitteration')) {
690
-			include_spip('inc/charsets');
691
-		}
692
-		$ancre = preg_replace(
693
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
694
-			['', '-'],
695
-			translitteration($ancre)
696
-		);
697
-	}
698
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
683
+    // lever l'#ancre
684
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
685
+        $url = $r[1];
686
+    }
687
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
688
+        if (!function_exists('translitteration')) {
689
+            include_spip('inc/charsets');
690
+        }
691
+        $ancre = preg_replace(
692
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
693
+            ['', '-'],
694
+            translitteration($ancre)
695
+        );
696
+    }
697
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
699 698
 }
700 699
 
701 700
 /**
@@ -705,16 +704,16 @@  discard block
 block discarded – undo
705 704
  * @return string
706 705
  */
707 706
 function nettoyer_uri($reset = null) {
708
-	static $done = false;
709
-	static $propre = '';
710
-	if (!is_null($reset)) {
711
-		return $propre = $reset;
712
-	}
713
-	if ($done) {
714
-		return $propre;
715
-	}
716
-	$done = true;
717
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
707
+    static $done = false;
708
+    static $propre = '';
709
+    if (!is_null($reset)) {
710
+        return $propre = $reset;
711
+    }
712
+    if ($done) {
713
+        return $propre;
714
+    }
715
+    $done = true;
716
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
718 717
 }
719 718
 
720 719
 /**
@@ -726,16 +725,16 @@  discard block
 block discarded – undo
726 725
  * @return string
727 726
  */
728 727
 function nettoyer_uri_var($request_uri) {
729
-	$uri1 = $request_uri;
730
-	do {
731
-		$uri = $uri1;
732
-		$uri1 = preg_replace(
733
-			',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
734
-			'\1',
735
-			$uri
736
-		);
737
-	} while ($uri <> $uri1);
738
-	return preg_replace(',[?&]$,', '', $uri1);
728
+    $uri1 = $request_uri;
729
+    do {
730
+        $uri = $uri1;
731
+        $uri1 = preg_replace(
732
+            ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
733
+            '\1',
734
+            $uri
735
+        );
736
+    } while ($uri <> $uri1);
737
+    return preg_replace(',[?&]$,', '', $uri1);
739 738
 }
740 739
 
741 740
 
@@ -749,48 +748,48 @@  discard block
 block discarded – undo
749 748
  *    URL vers soi-même
750 749
  **/
751 750
 function self($amp = '&amp;', $root = false) {
752
-	$url = nettoyer_uri();
753
-	if (
754
-		!$root
755
-		and (
756
-			// si pas de profondeur on peut tronquer
757
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
758
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
759
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
760
-	) {
761
-		$url = preg_replace(',^[^?]*/,', '', $url);
762
-	}
763
-	// ajouter le cas echeant les variables _POST['id_...']
764
-	foreach ($_POST as $v => $c) {
765
-		if (substr($v, 0, 3) == 'id_') {
766
-			$url = parametre_url($url, $v, $c, '&');
767
-		}
768
-	}
769
-
770
-	// supprimer les variables sans interet
771
-	if (test_espace_prive()) {
772
-		$url = preg_replace(',([?&])('
773
-			. 'lang|show_docs|'
774
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
775
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
776
-		$url = preg_replace(',[&]$,', '\1', $url);
777
-	}
778
-
779
-	// eviter les hacks
780
-	include_spip('inc/filtres_mini');
781
-	$url = spip_htmlspecialchars($url);
782
-
783
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
784
-
785
-	// &amp; ?
786
-	if ($amp != '&amp;') {
787
-		$url = str_replace('&amp;', $amp, $url);
788
-	}
789
-
790
-	// Si ca demarre par ? ou vide, donner './'
791
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
792
-
793
-	return $url;
751
+    $url = nettoyer_uri();
752
+    if (
753
+        !$root
754
+        and (
755
+            // si pas de profondeur on peut tronquer
756
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
757
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
758
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
759
+    ) {
760
+        $url = preg_replace(',^[^?]*/,', '', $url);
761
+    }
762
+    // ajouter le cas echeant les variables _POST['id_...']
763
+    foreach ($_POST as $v => $c) {
764
+        if (substr($v, 0, 3) == 'id_') {
765
+            $url = parametre_url($url, $v, $c, '&');
766
+        }
767
+    }
768
+
769
+    // supprimer les variables sans interet
770
+    if (test_espace_prive()) {
771
+        $url = preg_replace(',([?&])('
772
+            . 'lang|show_docs|'
773
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
774
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
775
+        $url = preg_replace(',[&]$,', '\1', $url);
776
+    }
777
+
778
+    // eviter les hacks
779
+    include_spip('inc/filtres_mini');
780
+    $url = spip_htmlspecialchars($url);
781
+
782
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
783
+
784
+    // &amp; ?
785
+    if ($amp != '&amp;') {
786
+        $url = str_replace('&amp;', $amp, $url);
787
+    }
788
+
789
+    // Si ca demarre par ? ou vide, donner './'
790
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
791
+
792
+    return $url;
794 793
 }
795 794
 
796 795
 
@@ -801,7 +800,7 @@  discard block
 block discarded – undo
801 800
  *     true si c'est le cas, false sinon.
802 801
  */
803 802
 function test_espace_prive() {
804
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
803
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
805 804
 }
806 805
 
807 806
 /**
@@ -811,7 +810,7 @@  discard block
 block discarded – undo
811 810
  * @return bool
812 811
  */
813 812
 function test_plugin_actif($plugin) {
814
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
813
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
815 814
 }
816 815
 
817 816
 /**
@@ -842,52 +841,52 @@  discard block
 block discarded – undo
842 841
  *     Texte
843 842
  */
844 843
 function _T($texte, $args = [], $options = []) {
845
-	static $traduire = false;
846
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
847
-	if ($options) {
848
-		// support de l'ancien argument $class
849
-		if (is_string($options)) {
850
-			$options = ['class' => $options];
851
-		}
852
-		$o = array_merge($o, $options);
853
-	}
854
-
855
-	if (!$traduire) {
856
-		$traduire = charger_fonction('traduire', 'inc');
857
-		include_spip('inc/lang');
858
-	}
859
-
860
-	// On peut passer explicitement la langue dans le tableau
861
-	// On utilise le même nom de variable que la globale
862
-	if (isset($args['spip_lang'])) {
863
-		$lang = $args['spip_lang'];
864
-		// On l'enleve pour ne pas le passer au remplacement
865
-		unset($args['spip_lang']);
866
-	} // Sinon on prend la langue du contexte
867
-	else {
868
-		$lang = $GLOBALS['spip_lang'];
869
-	}
870
-	$text = $traduire($texte, $lang);
871
-
872
-	if ($text === null || !strlen($text)) {
873
-		if (!$o['force']) {
874
-			return '';
875
-		}
876
-
877
-		$text = $texte;
878
-
879
-		// pour les chaines non traduites, assurer un service minimum
880
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
881
-			$n = strpos($text, ':');
882
-			if ($n !== false) {
883
-				$text = substr($text, $n + 1);
884
-			}
885
-			$text = str_replace('_', ' ', $text);
886
-		}
887
-		$o['class'] = null;
888
-	}
889
-
890
-	return _L($text, $args, $o);
844
+    static $traduire = false;
845
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
846
+    if ($options) {
847
+        // support de l'ancien argument $class
848
+        if (is_string($options)) {
849
+            $options = ['class' => $options];
850
+        }
851
+        $o = array_merge($o, $options);
852
+    }
853
+
854
+    if (!$traduire) {
855
+        $traduire = charger_fonction('traduire', 'inc');
856
+        include_spip('inc/lang');
857
+    }
858
+
859
+    // On peut passer explicitement la langue dans le tableau
860
+    // On utilise le même nom de variable que la globale
861
+    if (isset($args['spip_lang'])) {
862
+        $lang = $args['spip_lang'];
863
+        // On l'enleve pour ne pas le passer au remplacement
864
+        unset($args['spip_lang']);
865
+    } // Sinon on prend la langue du contexte
866
+    else {
867
+        $lang = $GLOBALS['spip_lang'];
868
+    }
869
+    $text = $traduire($texte, $lang);
870
+
871
+    if ($text === null || !strlen($text)) {
872
+        if (!$o['force']) {
873
+            return '';
874
+        }
875
+
876
+        $text = $texte;
877
+
878
+        // pour les chaines non traduites, assurer un service minimum
879
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
880
+            $n = strpos($text, ':');
881
+            if ($n !== false) {
882
+                $text = substr($text, $n + 1);
883
+            }
884
+            $text = str_replace('_', ' ', $text);
885
+        }
886
+        $o['class'] = null;
887
+    }
888
+
889
+    return _L($text, $args, $o);
891 890
 }
892 891
 
893 892
 
@@ -914,53 +913,53 @@  discard block
 block discarded – undo
914 913
  *     Texte
915 914
  */
916 915
 function _L($text, $args = [], $options = []) {
917
-	$f = $text;
918
-	$defaut_options = [
919
-		'class' => null,
920
-		'sanitize' => true,
921
-	];
922
-	// support de l'ancien argument $class
923
-	if ($options and is_string($options)) {
924
-		$options = ['class' => $options];
925
-	}
926
-	if (is_array($options)) {
927
-		$options += $defaut_options;
928
-	} else {
929
-		$options = $defaut_options;
930
-	}
931
-
932
-	if (is_array($args) and count($args)) {
933
-		if (!function_exists('interdire_scripts')) {
934
-			include_spip('inc/texte');
935
-		}
936
-		if (!function_exists('echapper_html_suspect')) {
937
-			include_spip('inc/texte_mini');
938
-		}
939
-		foreach ($args as $name => $value) {
940
-			if (strpos($text, (string) "@$name@") !== false) {
941
-				if ($options['sanitize']) {
942
-					$value = echapper_html_suspect($value);
943
-					$value = interdire_scripts($value, -1);
944
-				}
945
-				if (!empty($options['class'])) {
946
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
947
-				}
948
-				$text = str_replace("@$name@", $value, $text);
949
-				unset($args[$name]);
950
-			}
951
-		}
952
-		// Si des variables n'ont pas ete inserees, le signaler
953
-		// (chaines de langues pas a jour)
954
-		if ($args) {
955
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
956
-		}
957
-	}
958
-
959
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
960
-		return "<span class='debug-traduction-erreur'>$text</span>";
961
-	} else {
962
-		return $text;
963
-	}
916
+    $f = $text;
917
+    $defaut_options = [
918
+        'class' => null,
919
+        'sanitize' => true,
920
+    ];
921
+    // support de l'ancien argument $class
922
+    if ($options and is_string($options)) {
923
+        $options = ['class' => $options];
924
+    }
925
+    if (is_array($options)) {
926
+        $options += $defaut_options;
927
+    } else {
928
+        $options = $defaut_options;
929
+    }
930
+
931
+    if (is_array($args) and count($args)) {
932
+        if (!function_exists('interdire_scripts')) {
933
+            include_spip('inc/texte');
934
+        }
935
+        if (!function_exists('echapper_html_suspect')) {
936
+            include_spip('inc/texte_mini');
937
+        }
938
+        foreach ($args as $name => $value) {
939
+            if (strpos($text, (string) "@$name@") !== false) {
940
+                if ($options['sanitize']) {
941
+                    $value = echapper_html_suspect($value);
942
+                    $value = interdire_scripts($value, -1);
943
+                }
944
+                if (!empty($options['class'])) {
945
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
946
+                }
947
+                $text = str_replace("@$name@", $value, $text);
948
+                unset($args[$name]);
949
+            }
950
+        }
951
+        // Si des variables n'ont pas ete inserees, le signaler
952
+        // (chaines de langues pas a jour)
953
+        if ($args) {
954
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
955
+        }
956
+    }
957
+
958
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
959
+        return "<span class='debug-traduction-erreur'>$text</span>";
960
+    } else {
961
+        return $text;
962
+    }
964 963
 }
965 964
 
966 965
 
@@ -974,13 +973,13 @@  discard block
 block discarded – undo
974 973
  * @return string
975 974
  */
976 975
 function joli_repertoire($rep) {
977
-	$a = substr($rep, 0, 1);
978
-	if ($a <> '.' and $a <> '/') {
979
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
980
-	}
981
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
976
+    $a = substr($rep, 0, 1);
977
+    if ($a <> '.' and $a <> '/') {
978
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
979
+    }
980
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
982 981
 
983
-	return $rep;
982
+    return $rep;
984 983
 }
985 984
 
986 985
 
@@ -1005,54 +1004,54 @@  discard block
 block discarded – undo
1005 1004
  * @return float|int|string|void
1006 1005
  */
1007 1006
 function spip_timer($t = 'rien', $raw = false) {
1008
-	static $time;
1009
-	$a = time();
1010
-	$b = microtime();
1011
-	// microtime peut contenir les microsecondes et le temps
1012
-	$b = explode(' ', $b);
1013
-	if (count($b) == 2) {
1014
-		$a = end($b);
1015
-	} // plus precis !
1016
-	$b = reset($b);
1017
-	if (!isset($time[$t])) {
1018
-		$time[$t] = $a + $b;
1019
-	} else {
1020
-		$p = ($a + $b - $time[$t]) * 1000;
1021
-		unset($time[$t]);
1007
+    static $time;
1008
+    $a = time();
1009
+    $b = microtime();
1010
+    // microtime peut contenir les microsecondes et le temps
1011
+    $b = explode(' ', $b);
1012
+    if (count($b) == 2) {
1013
+        $a = end($b);
1014
+    } // plus precis !
1015
+    $b = reset($b);
1016
+    if (!isset($time[$t])) {
1017
+        $time[$t] = $a + $b;
1018
+    } else {
1019
+        $p = ($a + $b - $time[$t]) * 1000;
1020
+        unset($time[$t]);
1022 1021
 #			echo "'$p'";exit;
1023
-		if ($raw) {
1024
-			return $p;
1025
-		}
1026
-		if ($p < 1000) {
1027
-			$s = '';
1028
-		} else {
1029
-			$s = sprintf('%d ', $x = floor($p / 1000));
1030
-			$p -= ($x * 1000);
1031
-		}
1022
+        if ($raw) {
1023
+            return $p;
1024
+        }
1025
+        if ($p < 1000) {
1026
+            $s = '';
1027
+        } else {
1028
+            $s = sprintf('%d ', $x = floor($p / 1000));
1029
+            $p -= ($x * 1000);
1030
+        }
1032 1031
 
1033
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1034
-	}
1032
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1033
+    }
1035 1034
 }
1036 1035
 
1037 1036
 
1038 1037
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
1039 1038
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1040 1039
 function spip_touch($fichier, $duree = 0, $touch = true) {
1041
-	if ($duree) {
1042
-		clearstatcache();
1043
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1044
-			return false;
1045
-		}
1046
-	}
1047
-	if ($touch !== false) {
1048
-		if (!@touch($fichier)) {
1049
-			spip_unlink($fichier);
1050
-			@touch($fichier);
1051
-		};
1052
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1053
-	}
1040
+    if ($duree) {
1041
+        clearstatcache();
1042
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1043
+            return false;
1044
+        }
1045
+    }
1046
+    if ($touch !== false) {
1047
+        if (!@touch($fichier)) {
1048
+            spip_unlink($fichier);
1049
+            @touch($fichier);
1050
+        };
1051
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1052
+    }
1054 1053
 
1055
-	return true;
1054
+    return true;
1056 1055
 }
1057 1056
 
1058 1057
 
@@ -1063,11 +1062,11 @@  discard block
 block discarded – undo
1063 1062
  * @uses cron()
1064 1063
  **/
1065 1064
 function action_cron() {
1066
-	include_spip('inc/headers');
1067
-	http_response_code(204); // No Content
1068
-	header('Connection: close');
1069
-	define('_DIRECT_CRON_FORCE', true);
1070
-	cron();
1065
+    include_spip('inc/headers');
1066
+    http_response_code(204); // No Content
1067
+    header('Connection: close');
1068
+    define('_DIRECT_CRON_FORCE', true);
1069
+    cron();
1071 1070
 }
1072 1071
 
1073 1072
 /**
@@ -1083,26 +1082,26 @@  discard block
 block discarded – undo
1083 1082
  *     True si la tache a pu être effectuée
1084 1083
  */
1085 1084
 function cron($taches = [], $taches_old = []) {
1086
-	// si pas en mode cron force, laisser tomber.
1087
-	if (!defined('_DIRECT_CRON_FORCE')) {
1088
-		return false;
1089
-	}
1090
-	if (!is_array($taches)) {
1091
-		$taches = $taches_old;
1092
-	} // compat anciens appels
1093
-	// si taches a inserer en base et base inaccessible, laisser tomber
1094
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1095
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1096
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1097
-	if ($taches and count($taches) and !spip_connect()) {
1098
-		return false;
1099
-	}
1100
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1101
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1102
-		return $genie($taches);
1103
-	}
1104
-
1105
-	return false;
1085
+    // si pas en mode cron force, laisser tomber.
1086
+    if (!defined('_DIRECT_CRON_FORCE')) {
1087
+        return false;
1088
+    }
1089
+    if (!is_array($taches)) {
1090
+        $taches = $taches_old;
1091
+    } // compat anciens appels
1092
+    // si taches a inserer en base et base inaccessible, laisser tomber
1093
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1094
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1095
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1096
+    if ($taches and count($taches) and !spip_connect()) {
1097
+        return false;
1098
+    }
1099
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1100
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1101
+        return $genie($taches);
1102
+    }
1103
+
1104
+    return false;
1106 1105
 }
1107 1106
 
1108 1107
 /**
@@ -1134,17 +1133,17 @@  discard block
 block discarded – undo
1134 1133
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1135 1134
  */
1136 1135
 function job_queue_add(
1137
-	$function,
1138
-	$description,
1139
-	$arguments = [],
1140
-	$file = '',
1141
-	$no_duplicate = false,
1142
-	$time = 0,
1143
-	$priority = 0
1136
+    $function,
1137
+    $description,
1138
+    $arguments = [],
1139
+    $file = '',
1140
+    $no_duplicate = false,
1141
+    $time = 0,
1142
+    $priority = 0
1144 1143
 ) {
1145
-	include_spip('inc/queue');
1144
+    include_spip('inc/queue');
1146 1145
 
1147
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1146
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1148 1147
 }
1149 1148
 
1150 1149
 /**
@@ -1155,9 +1154,9 @@  discard block
 block discarded – undo
1155 1154
  * @return bool
1156 1155
  */
1157 1156
 function job_queue_remove($id_job) {
1158
-	include_spip('inc/queue');
1157
+    include_spip('inc/queue');
1159 1158
 
1160
-	return queue_remove_job($id_job);
1159
+    return queue_remove_job($id_job);
1161 1160
 }
1162 1161
 
1163 1162
 /**
@@ -1170,9 +1169,9 @@  discard block
 block discarded – undo
1170 1169
  *     or an array of simple array to link multiples objet in one time
1171 1170
  */
1172 1171
 function job_queue_link($id_job, $objets) {
1173
-	include_spip('inc/queue');
1172
+    include_spip('inc/queue');
1174 1173
 
1175
-	return queue_link_job($id_job, $objets);
1174
+    return queue_link_job($id_job, $objets);
1176 1175
 }
1177 1176
 
1178 1177
 
@@ -1192,36 +1191,36 @@  discard block
 block discarded – undo
1192 1191
  *  - `null` si la queue n'est pas encore initialisée
1193 1192
  */
1194 1193
 function queue_sleep_time_to_next_job($force = null) {
1195
-	static $queue_next_job_time = -1;
1196
-	if ($force === true) {
1197
-		$queue_next_job_time = -1;
1198
-	} elseif ($force) {
1199
-		$queue_next_job_time = $force;
1200
-	}
1201
-
1202
-	if ($queue_next_job_time == -1) {
1203
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1204
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1205
-		}
1206
-		// utiliser un cache memoire si dispo
1207
-		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1208
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1209
-		} else {
1210
-			$queue_next_job_time = null;
1211
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1212
-				$queue_next_job_time = intval($contenu);
1213
-			}
1214
-		}
1215
-	}
1216
-
1217
-	if (is_null($queue_next_job_time)) {
1218
-		return null;
1219
-	}
1220
-	if (!$_SERVER['REQUEST_TIME']) {
1221
-		$_SERVER['REQUEST_TIME'] = time();
1222
-	}
1223
-
1224
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1194
+    static $queue_next_job_time = -1;
1195
+    if ($force === true) {
1196
+        $queue_next_job_time = -1;
1197
+    } elseif ($force) {
1198
+        $queue_next_job_time = $force;
1199
+    }
1200
+
1201
+    if ($queue_next_job_time == -1) {
1202
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1203
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1204
+        }
1205
+        // utiliser un cache memoire si dispo
1206
+        if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1207
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1208
+        } else {
1209
+            $queue_next_job_time = null;
1210
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1211
+                $queue_next_job_time = intval($contenu);
1212
+            }
1213
+        }
1214
+    }
1215
+
1216
+    if (is_null($queue_next_job_time)) {
1217
+        return null;
1218
+    }
1219
+    if (!$_SERVER['REQUEST_TIME']) {
1220
+        $_SERVER['REQUEST_TIME'] = time();
1221
+    }
1222
+
1223
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1225 1224
 }
1226 1225
 
1227 1226
 
@@ -1233,11 +1232,11 @@  discard block
 block discarded – undo
1233 1232
  * @return string
1234 1233
  */
1235 1234
 function quote_amp($u) {
1236
-	return preg_replace(
1237
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1238
-		'&amp;',
1239
-		$u
1240
-	);
1235
+    return preg_replace(
1236
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1237
+        '&amp;',
1238
+        $u
1239
+    );
1241 1240
 }
1242 1241
 
1243 1242
 
@@ -1260,27 +1259,27 @@  discard block
 block discarded – undo
1260 1259
  *     Balise HTML `<script>` et son contenu
1261 1260
  **/
1262 1261
 function http_script($script, $src = '', $noscript = '') {
1263
-	static $done = [];
1262
+    static $done = [];
1264 1263
 
1265
-	if ($src && !isset($done[$src])) {
1266
-		$done[$src] = true;
1267
-		$src = find_in_path($src, _JAVASCRIPT);
1268
-		$src = " src='$src'";
1269
-	} else {
1270
-		$src = '';
1271
-	}
1272
-	if ($script) {
1273
-		$script = ("/*<![CDATA[*/\n" .
1274
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1275
-			'/*]]>*/');
1276
-	}
1277
-	if ($noscript) {
1278
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1279
-	}
1264
+    if ($src && !isset($done[$src])) {
1265
+        $done[$src] = true;
1266
+        $src = find_in_path($src, _JAVASCRIPT);
1267
+        $src = " src='$src'";
1268
+    } else {
1269
+        $src = '';
1270
+    }
1271
+    if ($script) {
1272
+        $script = ("/*<![CDATA[*/\n" .
1273
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1274
+            '/*]]>*/');
1275
+    }
1276
+    if ($noscript) {
1277
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1278
+    }
1280 1279
 
1281
-	return ($src or $script or $noscript)
1282
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1283
-		: '';
1280
+    return ($src or $script or $noscript)
1281
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1282
+        : '';
1284 1283
 }
1285 1284
 
1286 1285
 
@@ -1315,7 +1314,7 @@  discard block
 block discarded – undo
1315 1314
  *     Texte échappé
1316 1315
  **/
1317 1316
 function texte_script(string $texte): string {
1318
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1317
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1319 1318
 }
1320 1319
 
1321 1320
 
@@ -1352,68 +1351,68 @@  discard block
 block discarded – undo
1352 1351
  *     Liste des chemins, par ordre de priorité.
1353 1352
  **/
1354 1353
 function _chemin($dir_path = null) {
1355
-	static $path_base = null;
1356
-	static $path_full = null;
1357
-	if ($path_base == null) {
1358
-		// Chemin standard depuis l'espace public
1359
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1360
-			_DIR_RACINE . ':' .
1361
-			_DIR_RACINE . 'squelettes-dist/:' .
1362
-			_DIR_RACINE . 'prive/:' .
1363
-			_DIR_RESTREINT;
1364
-		// Ajouter squelettes/
1365
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1366
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1367
-		}
1368
-		foreach (explode(':', $path) as $dir) {
1369
-			if (strlen($dir) and substr($dir, -1) != '/') {
1370
-				$dir .= '/';
1371
-			}
1372
-			$path_base[] = $dir;
1373
-		}
1374
-		$path_full = $path_base;
1375
-		// Et le(s) dossier(s) des squelettes nommes
1376
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1377
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1378
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1379
-			}
1380
-		}
1381
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1382
-	}
1383
-	if ($dir_path === null) {
1384
-		return $path_full;
1385
-	}
1386
-
1387
-	if (is_array($dir_path) or strlen($dir_path)) {
1388
-		$tete = '';
1389
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1390
-			$tete = array_shift($path_base);
1391
-		}
1392
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1393
-		$dirs = array_reverse($dirs);
1394
-		foreach ($dirs as $dir_path) {
1395
-			if (substr($dir_path, -1) != '/') {
1396
-				$dir_path .= '/';
1397
-			}
1398
-			if (!in_array($dir_path, $path_base)) {
1399
-				array_unshift($path_base, $dir_path);
1400
-			}
1401
-		}
1402
-		if (strlen($tete)) {
1403
-			array_unshift($path_base, $tete);
1404
-		}
1405
-	}
1406
-	$path_full = $path_base;
1407
-	// Et le(s) dossier(s) des squelettes nommes
1408
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1409
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1410
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1411
-		}
1412
-	}
1413
-
1414
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1415
-
1416
-	return $path_full;
1354
+    static $path_base = null;
1355
+    static $path_full = null;
1356
+    if ($path_base == null) {
1357
+        // Chemin standard depuis l'espace public
1358
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1359
+            _DIR_RACINE . ':' .
1360
+            _DIR_RACINE . 'squelettes-dist/:' .
1361
+            _DIR_RACINE . 'prive/:' .
1362
+            _DIR_RESTREINT;
1363
+        // Ajouter squelettes/
1364
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1365
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1366
+        }
1367
+        foreach (explode(':', $path) as $dir) {
1368
+            if (strlen($dir) and substr($dir, -1) != '/') {
1369
+                $dir .= '/';
1370
+            }
1371
+            $path_base[] = $dir;
1372
+        }
1373
+        $path_full = $path_base;
1374
+        // Et le(s) dossier(s) des squelettes nommes
1375
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1376
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1377
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1378
+            }
1379
+        }
1380
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1381
+    }
1382
+    if ($dir_path === null) {
1383
+        return $path_full;
1384
+    }
1385
+
1386
+    if (is_array($dir_path) or strlen($dir_path)) {
1387
+        $tete = '';
1388
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1389
+            $tete = array_shift($path_base);
1390
+        }
1391
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1392
+        $dirs = array_reverse($dirs);
1393
+        foreach ($dirs as $dir_path) {
1394
+            if (substr($dir_path, -1) != '/') {
1395
+                $dir_path .= '/';
1396
+            }
1397
+            if (!in_array($dir_path, $path_base)) {
1398
+                array_unshift($path_base, $dir_path);
1399
+            }
1400
+        }
1401
+        if (strlen($tete)) {
1402
+            array_unshift($path_base, $tete);
1403
+        }
1404
+    }
1405
+    $path_full = $path_base;
1406
+    // Et le(s) dossier(s) des squelettes nommes
1407
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1408
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1409
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1410
+        }
1411
+    }
1412
+
1413
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1414
+
1415
+    return $path_full;
1417 1416
 }
1418 1417
 
1419 1418
 /**
@@ -1426,78 +1425,78 @@  discard block
 block discarded – undo
1426 1425
  * @return array Liste de chemins
1427 1426
  **/
1428 1427
 function creer_chemin() {
1429
-	$path_a = _chemin();
1430
-	static $c = '';
1428
+    $path_a = _chemin();
1429
+    static $c = '';
1431 1430
 
1432
-	// on calcule le chemin si le dossier skel a change
1433
-	if ($c != $GLOBALS['dossier_squelettes']) {
1434
-		// assurer le non plantage lors de la montee de version :
1435
-		$c = $GLOBALS['dossier_squelettes'];
1436
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1437
-	}
1431
+    // on calcule le chemin si le dossier skel a change
1432
+    if ($c != $GLOBALS['dossier_squelettes']) {
1433
+        // assurer le non plantage lors de la montee de version :
1434
+        $c = $GLOBALS['dossier_squelettes'];
1435
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1436
+    }
1438 1437
 
1439
-	return $path_a;
1438
+    return $path_a;
1440 1439
 }
1441 1440
 
1442 1441
 
1443 1442
 function lister_themes_prives() {
1444
-	static $themes = null;
1445
-	if (is_null($themes)) {
1446
-		// si pas encore definie
1447
-		if (!defined('_SPIP_THEME_PRIVE')) {
1448
-			define('_SPIP_THEME_PRIVE', 'spip');
1449
-		}
1450
-		$themes = [_SPIP_THEME_PRIVE];
1451
-		// lors d'une installation neuve, prefs n'est pas definie.
1452
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1453
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1454
-		} else {
1455
-			$prefs = [];
1456
-		}
1457
-		if (is_string($prefs)) {
1458
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1459
-		}
1460
-		if (
1461
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1462
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1463
-			and $theme != _SPIP_THEME_PRIVE
1464
-		) {
1465
-			array_unshift($themes, $theme);
1466
-		} // placer le theme choisi en tete
1467
-	}
1468
-
1469
-	return $themes;
1443
+    static $themes = null;
1444
+    if (is_null($themes)) {
1445
+        // si pas encore definie
1446
+        if (!defined('_SPIP_THEME_PRIVE')) {
1447
+            define('_SPIP_THEME_PRIVE', 'spip');
1448
+        }
1449
+        $themes = [_SPIP_THEME_PRIVE];
1450
+        // lors d'une installation neuve, prefs n'est pas definie.
1451
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1452
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1453
+        } else {
1454
+            $prefs = [];
1455
+        }
1456
+        if (is_string($prefs)) {
1457
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1458
+        }
1459
+        if (
1460
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1461
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1462
+            and $theme != _SPIP_THEME_PRIVE
1463
+        ) {
1464
+            array_unshift($themes, $theme);
1465
+        } // placer le theme choisi en tete
1466
+    }
1467
+
1468
+    return $themes;
1470 1469
 }
1471 1470
 
1472 1471
 function find_in_theme($file, $subdir = '', $include = false) {
1473
-	static $themefiles = [];
1474
-	if (isset($themefiles["$subdir$file"])) {
1475
-		return $themefiles["$subdir$file"];
1476
-	}
1477
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1478
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1479
-	if (
1480
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1481
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1482
-		and $f = find_in_theme("$file_svg_generique")
1483
-	) {
1484
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1485
-			return $themefiles["$subdir$file"] = $fsize;
1486
-		}
1487
-		else {
1488
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1489
-		}
1490
-	}
1491
-
1492
-	$themes = lister_themes_prives();
1493
-	foreach ($themes as $theme) {
1494
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1495
-			return $themefiles["$subdir$file"] = $f;
1496
-		}
1497
-	}
1498
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1499
-
1500
-	return $themefiles["$subdir$file"] = '';
1472
+    static $themefiles = [];
1473
+    if (isset($themefiles["$subdir$file"])) {
1474
+        return $themefiles["$subdir$file"];
1475
+    }
1476
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1477
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1478
+    if (
1479
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1480
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1481
+        and $f = find_in_theme("$file_svg_generique")
1482
+    ) {
1483
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1484
+            return $themefiles["$subdir$file"] = $fsize;
1485
+        }
1486
+        else {
1487
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1488
+        }
1489
+    }
1490
+
1491
+    $themes = lister_themes_prives();
1492
+    foreach ($themes as $theme) {
1493
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1494
+            return $themefiles["$subdir$file"] = $f;
1495
+        }
1496
+    }
1497
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1498
+
1499
+    return $themefiles["$subdir$file"] = '';
1501 1500
 }
1502 1501
 
1503 1502
 
@@ -1521,31 +1520,31 @@  discard block
 block discarded – undo
1521 1520
  *     sinon chaîne vide.
1522 1521
  **/
1523 1522
 function chemin_image($icone) {
1524
-	static $icone_renommer;
1525
-	if ($p = strpos($icone, '?')) {
1526
-		$icone = substr($icone, 0, $p);
1527
-	}
1528
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1529
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1530
-		return $icone;
1531
-	}
1532
-
1533
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1534
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1535
-		return $f;
1536
-	}
1537
-	// sinon passer par le module de renommage
1538
-	if (is_null($icone_renommer)) {
1539
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1540
-	}
1541
-	if ($icone_renommer) {
1542
-		[$icone, $fonction] = $icone_renommer($icone, '');
1543
-		if (file_exists($icone)) {
1544
-			return $icone;
1545
-		}
1546
-	}
1547
-
1548
-	return find_in_path($icone, _NOM_IMG_PACK);
1523
+    static $icone_renommer;
1524
+    if ($p = strpos($icone, '?')) {
1525
+        $icone = substr($icone, 0, $p);
1526
+    }
1527
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1528
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1529
+        return $icone;
1530
+    }
1531
+
1532
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1533
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1534
+        return $f;
1535
+    }
1536
+    // sinon passer par le module de renommage
1537
+    if (is_null($icone_renommer)) {
1538
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1539
+    }
1540
+    if ($icone_renommer) {
1541
+        [$icone, $fonction] = $icone_renommer($icone, '');
1542
+        if (file_exists($icone)) {
1543
+            return $icone;
1544
+        }
1545
+    }
1546
+
1547
+    return find_in_path($icone, _NOM_IMG_PACK);
1549 1548
 }
1550 1549
 
1551 1550
 //
@@ -1583,128 +1582,128 @@  discard block
 block discarded – undo
1583 1582
  *     - false : fichier introuvable
1584 1583
  **/
1585 1584
 function find_in_path($file, $dirname = '', $include = false) {
1586
-	static $dirs = [];
1587
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1588
-	static $c = '';
1589
-
1590
-	if (!$file and !strlen($file)) {
1591
-		return false;
1592
-	}
1593
-
1594
-	// on calcule le chemin si le dossier skel a change
1595
-	if ($c != $GLOBALS['dossier_squelettes']) {
1596
-		// assurer le non plantage lors de la montee de version :
1597
-		$c = $GLOBALS['dossier_squelettes'];
1598
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1599
-	}
1600
-
1601
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1602
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1603
-			return false;
1604
-		}
1605
-		if ($include and !isset($inc[$dirname][$file])) {
1606
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1607
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1608
-		}
1609
-
1610
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1611
-	}
1612
-
1613
-	$a = strrpos($file, '/');
1614
-	if ($a !== false) {
1615
-		$dirname .= substr($file, 0, ++$a);
1616
-		$file = substr($file, $a);
1617
-	}
1618
-
1619
-	foreach (creer_chemin() as $dir) {
1620
-		if (!isset($dirs[$a = $dir . $dirname])) {
1621
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1622
-		}
1623
-		if ($dirs[$a]) {
1624
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1625
-				if ($include and !isset($inc[$dirname][$file])) {
1626
-					include_once _ROOT_CWD . $a;
1627
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1628
-				}
1629
-				if (!defined('_SAUVER_CHEMIN')) {
1630
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1631
-					if (is_null($GLOBALS['path_files'])) {
1632
-						return $a;
1633
-					}
1634
-					define('_SAUVER_CHEMIN', true);
1635
-				}
1636
-
1637
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1638
-			}
1639
-		}
1640
-	}
1641
-
1642
-	if ($include) {
1643
-		spip_log("include_spip $dirname$file non trouve");
1644
-		if ($include === 'required') {
1645
-			echo '<pre>',
1646
-			'<strong>Erreur Fatale</strong><br />';
1647
-			if (function_exists('debug_print_backtrace')) {
1648
-				echo debug_print_backtrace();
1649
-			}
1650
-			echo '</pre>';
1651
-			die("Erreur interne: ne peut inclure $dirname$file");
1652
-		}
1653
-	}
1654
-
1655
-	if (!defined('_SAUVER_CHEMIN')) {
1656
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1657
-		if (is_null($GLOBALS['path_files'])) {
1658
-			return false;
1659
-		}
1660
-		define('_SAUVER_CHEMIN', true);
1661
-	}
1662
-
1663
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1585
+    static $dirs = [];
1586
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1587
+    static $c = '';
1588
+
1589
+    if (!$file and !strlen($file)) {
1590
+        return false;
1591
+    }
1592
+
1593
+    // on calcule le chemin si le dossier skel a change
1594
+    if ($c != $GLOBALS['dossier_squelettes']) {
1595
+        // assurer le non plantage lors de la montee de version :
1596
+        $c = $GLOBALS['dossier_squelettes'];
1597
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1598
+    }
1599
+
1600
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1601
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1602
+            return false;
1603
+        }
1604
+        if ($include and !isset($inc[$dirname][$file])) {
1605
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1606
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1607
+        }
1608
+
1609
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1610
+    }
1611
+
1612
+    $a = strrpos($file, '/');
1613
+    if ($a !== false) {
1614
+        $dirname .= substr($file, 0, ++$a);
1615
+        $file = substr($file, $a);
1616
+    }
1617
+
1618
+    foreach (creer_chemin() as $dir) {
1619
+        if (!isset($dirs[$a = $dir . $dirname])) {
1620
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1621
+        }
1622
+        if ($dirs[$a]) {
1623
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1624
+                if ($include and !isset($inc[$dirname][$file])) {
1625
+                    include_once _ROOT_CWD . $a;
1626
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1627
+                }
1628
+                if (!defined('_SAUVER_CHEMIN')) {
1629
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1630
+                    if (is_null($GLOBALS['path_files'])) {
1631
+                        return $a;
1632
+                    }
1633
+                    define('_SAUVER_CHEMIN', true);
1634
+                }
1635
+
1636
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1637
+            }
1638
+        }
1639
+    }
1640
+
1641
+    if ($include) {
1642
+        spip_log("include_spip $dirname$file non trouve");
1643
+        if ($include === 'required') {
1644
+            echo '<pre>',
1645
+            '<strong>Erreur Fatale</strong><br />';
1646
+            if (function_exists('debug_print_backtrace')) {
1647
+                echo debug_print_backtrace();
1648
+            }
1649
+            echo '</pre>';
1650
+            die("Erreur interne: ne peut inclure $dirname$file");
1651
+        }
1652
+    }
1653
+
1654
+    if (!defined('_SAUVER_CHEMIN')) {
1655
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1656
+        if (is_null($GLOBALS['path_files'])) {
1657
+            return false;
1658
+        }
1659
+        define('_SAUVER_CHEMIN', true);
1660
+    }
1661
+
1662
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1664 1663
 }
1665 1664
 
1666 1665
 function clear_path_cache() {
1667
-	$GLOBALS['path_files'] = [];
1668
-	spip_unlink(_CACHE_CHEMIN);
1666
+    $GLOBALS['path_files'] = [];
1667
+    spip_unlink(_CACHE_CHEMIN);
1669 1668
 }
1670 1669
 
1671 1670
 function load_path_cache() {
1672
-	// charger le path des plugins
1673
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1674
-		include_once(_CACHE_PLUGINS_PATH);
1675
-	}
1676
-	$GLOBALS['path_files'] = [];
1677
-	// si le visiteur est admin,
1678
-	// on ne recharge pas le cache pour forcer sa mise a jour
1679
-	if (
1680
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1681
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1682
-		// utiliser le cookie est un pis aller qui marche 'en general'
1683
-		// on blinde par un second test au moment de la lecture de la session
1684
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1685
-		// et en ignorant ce cache en cas de recalcul explicite
1686
-		!_request('var_mode')
1687
-	) {
1688
-		// on essaye de lire directement sans verrou pour aller plus vite
1689
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1690
-			// mais si semble corrompu on relit avec un verrou
1691
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1692
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1693
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1694
-					$GLOBALS['path_files'] = [];
1695
-				}
1696
-			}
1697
-		}
1698
-	}
1671
+    // charger le path des plugins
1672
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1673
+        include_once(_CACHE_PLUGINS_PATH);
1674
+    }
1675
+    $GLOBALS['path_files'] = [];
1676
+    // si le visiteur est admin,
1677
+    // on ne recharge pas le cache pour forcer sa mise a jour
1678
+    if (
1679
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1680
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1681
+        // utiliser le cookie est un pis aller qui marche 'en general'
1682
+        // on blinde par un second test au moment de la lecture de la session
1683
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1684
+        // et en ignorant ce cache en cas de recalcul explicite
1685
+        !_request('var_mode')
1686
+    ) {
1687
+        // on essaye de lire directement sans verrou pour aller plus vite
1688
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1689
+            // mais si semble corrompu on relit avec un verrou
1690
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1691
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1692
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1693
+                    $GLOBALS['path_files'] = [];
1694
+                }
1695
+            }
1696
+        }
1697
+    }
1699 1698
 }
1700 1699
 
1701 1700
 function save_path_cache() {
1702
-	if (
1703
-		defined('_SAUVER_CHEMIN')
1704
-		and _SAUVER_CHEMIN
1705
-	) {
1706
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1707
-	}
1701
+    if (
1702
+        defined('_SAUVER_CHEMIN')
1703
+        and _SAUVER_CHEMIN
1704
+    ) {
1705
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1706
+    }
1708 1707
 }
1709 1708
 
1710 1709
 
@@ -1724,33 +1723,33 @@  discard block
 block discarded – undo
1724 1723
  * @return array
1725 1724
  */
1726 1725
 function find_all_in_path($dir, $pattern, $recurs = false) {
1727
-	$liste_fichiers = [];
1728
-	$maxfiles = 10000;
1729
-
1730
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1731
-	// on a pas encore inclus flock.php
1732
-	if (!function_exists('preg_files')) {
1733
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1734
-	}
1735
-
1736
-	// Parcourir le chemin
1737
-	foreach (creer_chemin() as $d) {
1738
-		$f = $d . $dir;
1739
-		if (@is_dir($f)) {
1740
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1741
-			foreach ($liste as $chemin) {
1742
-				$nom = basename($chemin);
1743
-				// ne prendre que les fichiers pas deja trouves
1744
-				// car find_in_path prend le premier qu'il trouve,
1745
-				// les autres sont donc masques
1746
-				if (!isset($liste_fichiers[$nom])) {
1747
-					$liste_fichiers[$nom] = $chemin;
1748
-				}
1749
-			}
1750
-		}
1751
-	}
1752
-
1753
-	return $liste_fichiers;
1726
+    $liste_fichiers = [];
1727
+    $maxfiles = 10000;
1728
+
1729
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1730
+    // on a pas encore inclus flock.php
1731
+    if (!function_exists('preg_files')) {
1732
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1733
+    }
1734
+
1735
+    // Parcourir le chemin
1736
+    foreach (creer_chemin() as $d) {
1737
+        $f = $d . $dir;
1738
+        if (@is_dir($f)) {
1739
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1740
+            foreach ($liste as $chemin) {
1741
+                $nom = basename($chemin);
1742
+                // ne prendre que les fichiers pas deja trouves
1743
+                // car find_in_path prend le premier qu'il trouve,
1744
+                // les autres sont donc masques
1745
+                if (!isset($liste_fichiers[$nom])) {
1746
+                    $liste_fichiers[$nom] = $chemin;
1747
+                }
1748
+            }
1749
+        }
1750
+    }
1751
+
1752
+    return $liste_fichiers;
1754 1753
 }
1755 1754
 
1756 1755
 /**
@@ -1762,17 +1761,17 @@  discard block
 block discarded – undo
1762 1761
  * @return bool
1763 1762
  */
1764 1763
 function autoriser_sans_cookie($nom, $strict = false) {
1765
-	static $autsanscookie = ['install', 'base_repair'];
1764
+    static $autsanscookie = ['install', 'base_repair'];
1766 1765
 
1767
-	if (in_array($nom, $autsanscookie)) {
1768
-		if (test_espace_prive()) {
1769
-			include_spip('base/connect_sql');
1770
-			if (!$strict or !spip_connect()) {
1771
-				return true;
1772
-			}
1773
-		}
1774
-	}
1775
-	return false;
1766
+    if (in_array($nom, $autsanscookie)) {
1767
+        if (test_espace_prive()) {
1768
+            include_spip('base/connect_sql');
1769
+            if (!$strict or !spip_connect()) {
1770
+                return true;
1771
+            }
1772
+        }
1773
+    }
1774
+    return false;
1776 1775
 }
1777 1776
 
1778 1777
 /**
@@ -1782,60 +1781,60 @@  discard block
 block discarded – undo
1782 1781
  * @return string
1783 1782
  */
1784 1783
 function charger_fonction_url(string $quoi, string $type = '') {
1785
-	if ($type === 'defaut') {
1786
-		$objet = objet_type($quoi);
1787
-		if (
1788
-			$f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1789
-			// deprecated
1790
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1791
-		) {
1792
-			return $f;
1793
-		}
1794
-		return '';
1795
-	}
1796
-
1797
-	$url_type = $type;
1798
-	if (!$url_type) {
1799
-		$url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1800
-	}
1801
-
1802
-	// inclure le module d'url
1803
-	include_spip('urls/' . $url_type);
1804
-
1805
-	switch ($quoi) {
1806
-		case 'page':
1807
-			if (
1808
-				 function_exists($f = "urls_{$url_type}_generer_url_page")
1809
-				or function_exists($f .= '_dist')
1810
-				// ou une fonction custom utilisateur independante du type d'url
1811
-				or function_exists($f = 'generer_url_page')
1812
-				or function_exists($f .= '_dist')
1813
-			) {
1814
-				return $f;
1815
-			}
1816
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1817
-			return '';
1818
-		case 'objet':
1819
-		case 'decoder':
1820
-		default:
1821
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1822
-			if (
1823
-				function_exists($f = "urls_{$url_type}_{$fquoi}")
1824
-				or function_exists($f .= '_dist')
1825
-			) {
1826
-				return $f;
1827
-			}
1828
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1829
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1830
-			if ($f = charger_fonction($url_type, 'urls', true)) {
1831
-				return $f;
1832
-			}
1833
-			// sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1834
-			if (!$type and $url_type !== 'page') {
1835
-				return charger_fonction_url($quoi, 'page');
1836
-			}
1837
-			return '';
1838
-	}
1784
+    if ($type === 'defaut') {
1785
+        $objet = objet_type($quoi);
1786
+        if (
1787
+            $f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1788
+            // deprecated
1789
+            or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1790
+        ) {
1791
+            return $f;
1792
+        }
1793
+        return '';
1794
+    }
1795
+
1796
+    $url_type = $type;
1797
+    if (!$url_type) {
1798
+        $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1799
+    }
1800
+
1801
+    // inclure le module d'url
1802
+    include_spip('urls/' . $url_type);
1803
+
1804
+    switch ($quoi) {
1805
+        case 'page':
1806
+            if (
1807
+                    function_exists($f = "urls_{$url_type}_generer_url_page")
1808
+                or function_exists($f .= '_dist')
1809
+                // ou une fonction custom utilisateur independante du type d'url
1810
+                or function_exists($f = 'generer_url_page')
1811
+                or function_exists($f .= '_dist')
1812
+            ) {
1813
+                return $f;
1814
+            }
1815
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1816
+            return '';
1817
+        case 'objet':
1818
+        case 'decoder':
1819
+        default:
1820
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1821
+            if (
1822
+                function_exists($f = "urls_{$url_type}_{$fquoi}")
1823
+                or function_exists($f .= '_dist')
1824
+            ) {
1825
+                return $f;
1826
+            }
1827
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1828
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1829
+            if ($f = charger_fonction($url_type, 'urls', true)) {
1830
+                return $f;
1831
+            }
1832
+            // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1833
+            if (!$type and $url_type !== 'page') {
1834
+                return charger_fonction_url($quoi, 'page');
1835
+            }
1836
+            return '';
1837
+    }
1839 1838
 }
1840 1839
 
1841 1840
 
@@ -1864,48 +1863,48 @@  discard block
 block discarded – undo
1864 1863
  *           (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_spip_url et une fonction generer_spip_url_ecrire)
1865 1864
  */
1866 1865
 function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1867
-	if ($public === null) {
1868
-		$public = !test_espace_prive();
1869
-	}
1870
-	$id = intval($id);
1871
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1872
-
1873
-	if (!$public) {
1874
-		if (!$entite) {
1875
-			return '';
1876
-		}
1877
-		if (!function_exists('generer_objet_url_ecrire')) {
1878
-			include_spip('inc/urls');
1879
-		}
1880
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1881
-	} else {
1882
-		$f = charger_fonction_url('objet', $type ?? '');
1883
-
1884
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
1885
-		// @see charger_fonction_url
1886
-		if (!$entite) {
1887
-			return $f;
1888
-		}
1889
-
1890
-		// mais d'abord il faut tester le cas des urls sur une
1891
-		// base distante
1892
-		if (
1893
-			$connect
1894
-			and $g = charger_fonction('connect', 'urls', true)
1895
-		) {
1896
-			$f = $g;
1897
-		}
1898
-
1899
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1900
-	}
1901
-	if ($res) {
1902
-		return $res;
1903
-	}
1904
-
1905
-	// On a ete gentil mais la ....
1906
-	spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1907
-
1908
-	return '';
1866
+    if ($public === null) {
1867
+        $public = !test_espace_prive();
1868
+    }
1869
+    $id = intval($id);
1870
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1871
+
1872
+    if (!$public) {
1873
+        if (!$entite) {
1874
+            return '';
1875
+        }
1876
+        if (!function_exists('generer_objet_url_ecrire')) {
1877
+            include_spip('inc/urls');
1878
+        }
1879
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1880
+    } else {
1881
+        $f = charger_fonction_url('objet', $type ?? '');
1882
+
1883
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
1884
+        // @see charger_fonction_url
1885
+        if (!$entite) {
1886
+            return $f;
1887
+        }
1888
+
1889
+        // mais d'abord il faut tester le cas des urls sur une
1890
+        // base distante
1891
+        if (
1892
+            $connect
1893
+            and $g = charger_fonction('connect', 'urls', true)
1894
+        ) {
1895
+            $f = $g;
1896
+        }
1897
+
1898
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1899
+    }
1900
+    if ($res) {
1901
+        return $res;
1902
+    }
1903
+
1904
+    // On a ete gentil mais la ....
1905
+    spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1906
+
1907
+    return '';
1909 1908
 }
1910 1909
 
1911 1910
 /**
@@ -1913,10 +1912,10 @@  discard block
 block discarded – undo
1913 1912
  * @see generer_objet_url
1914 1913
  */
1915 1914
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1916
-	if ($public and is_string($public)) {
1917
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1918
-	}
1919
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1915
+    if ($public and is_string($public)) {
1916
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1917
+    }
1918
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1920 1919
 }
1921 1920
 
1922 1921
 /**
@@ -1928,19 +1927,19 @@  discard block
 block discarded – undo
1928 1927
  * @return string
1929 1928
  */
1930 1929
 function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string {
1931
-	$id = intval($id);
1932
-	$exec = objet_info($entite, 'url_edit');
1933
-	$url = generer_url_ecrire($exec, $args);
1934
-	if (intval($id)) {
1935
-		$url = parametre_url($url, id_table_objet($entite), $id);
1936
-	} else {
1937
-		$url = parametre_url($url, 'new', 'oui');
1938
-	}
1939
-	if ($ancre) {
1940
-		$url = ancre_url($url, $ancre);
1941
-	}
1930
+    $id = intval($id);
1931
+    $exec = objet_info($entite, 'url_edit');
1932
+    $url = generer_url_ecrire($exec, $args);
1933
+    if (intval($id)) {
1934
+        $url = parametre_url($url, id_table_objet($entite), $id);
1935
+    } else {
1936
+        $url = parametre_url($url, 'new', 'oui');
1937
+    }
1938
+    if ($ancre) {
1939
+        $url = ancre_url($url, $ancre);
1940
+    }
1942 1941
 
1943
-	return $url;
1942
+    return $url;
1944 1943
 }
1945 1944
 
1946 1945
 /**
@@ -1948,18 +1947,18 @@  discard block
 block discarded – undo
1948 1947
  * @see generer_objet_url_ecrire_edit
1949 1948
  */
1950 1949
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1951
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1950
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1952 1951
 }
1953 1952
 
1954 1953
 
1955 1954
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1956
-	include_spip('base/connect_sql');
1957
-	$id_type = id_table_objet($entite, $public);
1955
+    include_spip('base/connect_sql');
1956
+    $id_type = id_table_objet($entite, $public);
1958 1957
 
1959
-	return _DIR_RACINE . get_spip_script('./')
1960
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1961
-	. (!$args ? '' : "&$args")
1962
-	. (!$ancre ? '' : "#$ancre");
1958
+    return _DIR_RACINE . get_spip_script('./')
1959
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1960
+    . (!$args ? '' : "&$args")
1961
+    . (!$ancre ? '' : "#$ancre");
1963 1962
 }
1964 1963
 
1965 1964
 
@@ -1970,18 +1969,18 @@  discard block
 block discarded – undo
1970 1969
  * @return string
1971 1970
  */
1972 1971
 function urlencode_1738($url) {
1973
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1974
-		$uri = '';
1975
-		for ($i = 0; $i < strlen($url); $i++) {
1976
-			if (ord($a = $url[$i]) > 127) {
1977
-				$a = rawurlencode($a);
1978
-			}
1979
-			$uri .= $a;
1980
-		}
1981
-		$url = $uri;
1982
-	}
1972
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1973
+        $uri = '';
1974
+        for ($i = 0; $i < strlen($url); $i++) {
1975
+            if (ord($a = $url[$i]) > 127) {
1976
+                $a = rawurlencode($a);
1977
+            }
1978
+            $uri .= $a;
1979
+        }
1980
+        $url = $uri;
1981
+    }
1983 1982
 
1984
-	return quote_amp($url);
1983
+    return quote_amp($url);
1985 1984
 }
1986 1985
 
1987 1986
 /**
@@ -1997,14 +1996,14 @@  discard block
 block discarded – undo
1997 1996
  * @return string
1998 1997
  */
1999 1998
 function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
2000
-	$id = intval($id);
2001
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
2002
-	if (!preg_match(',^\w+:,', $h)) {
2003
-		include_spip('inc/filtres_mini');
2004
-		$h = url_absolue($h);
2005
-	}
1999
+    $id = intval($id);
2000
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
2001
+    if (!preg_match(',^\w+:,', $h)) {
2002
+        include_spip('inc/filtres_mini');
2003
+        $h = url_absolue($h);
2004
+    }
2006 2005
 
2007
-	return $h;
2006
+    return $h;
2008 2007
 }
2009 2008
 
2010 2009
 /**
@@ -2012,7 +2011,7 @@  discard block
 block discarded – undo
2012 2011
  * @see  generer_objet_url_absolue
2013 2012
  */
2014 2013
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) {
2015
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect);
2014
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect);
2016 2015
 }
2017 2016
 
2018 2017
 
@@ -2028,11 +2027,11 @@  discard block
 block discarded – undo
2028 2027
  *     true si la valeur est considérée active ; false sinon.
2029 2028
  **/
2030 2029
 function test_valeur_serveur($truc) {
2031
-	if (!$truc) {
2032
-		return false;
2033
-	}
2030
+    if (!$truc) {
2031
+        return false;
2032
+    }
2034 2033
 
2035
-	return (strtolower($truc) !== 'off');
2034
+    return (strtolower($truc) !== 'off');
2036 2035
 }
2037 2036
 
2038 2037
 //
@@ -2060,89 +2059,89 @@  discard block
 block discarded – undo
2060 2059
  */
2061 2060
 function url_de_base($profondeur = null) {
2062 2061
 
2063
-	static $url = [];
2064
-	if (is_array($profondeur)) {
2065
-		return $url = $profondeur;
2066
-	}
2067
-	if ($profondeur === false) {
2068
-		return $url;
2069
-	}
2070
-
2071
-	if (is_null($profondeur)) {
2072
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2073
-	}
2074
-
2075
-	if (isset($url[$profondeur])) {
2076
-		return $url[$profondeur];
2077
-	}
2078
-
2079
-	$http = 'http';
2080
-
2081
-	if (
2082
-		isset($_SERVER['SCRIPT_URI'])
2083
-		and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2084
-	) {
2085
-		$http = 'https';
2086
-	} elseif (
2087
-		isset($_SERVER['HTTPS'])
2088
-		and test_valeur_serveur($_SERVER['HTTPS'])
2089
-	) {
2090
-		$http = 'https';
2091
-	}
2092
-
2093
-	// note : HTTP_HOST contient le :port si necessaire
2094
-	if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2095
-		// Filtrer $host pour proteger d'attaques d'entete HTTP
2096
-		$host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2097
-	}
2098
-
2099
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2100
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2101
-		$host = $GLOBALS['meta']['adresse_site'];
2102
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2103
-			$http = $scheme;
2104
-			$host = str_replace("{$scheme}://", '', $host);
2105
-		}
2106
-	}
2107
-	if (
2108
-		isset($_SERVER['SERVER_PORT'])
2109
-		and $port = $_SERVER['SERVER_PORT']
2110
-		and strpos($host, ':') == false
2111
-	) {
2112
-		if (!defined('_PORT_HTTP_STANDARD')) {
2113
-			define('_PORT_HTTP_STANDARD', '80');
2114
-		}
2115
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2116
-			define('_PORT_HTTPS_STANDARD', '443');
2117
-		}
2118
-		if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2119
-			$host .= ":$port";
2120
-		}
2121
-		if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2122
-			$host .= ":$port";
2123
-		}
2124
-	}
2125
-
2126
-	if (!$GLOBALS['REQUEST_URI']) {
2127
-		if (isset($_SERVER['REQUEST_URI'])) {
2128
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2129
-		} else {
2130
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2131
-			if (
2132
-				!empty($_SERVER['QUERY_STRING'])
2133
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2134
-			) {
2135
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2136
-			}
2137
-		}
2138
-	}
2139
-
2140
-	// Et nettoyer l'url
2141
-	$GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2142
-
2143
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2144
-
2145
-	return $url[$profondeur];
2062
+    static $url = [];
2063
+    if (is_array($profondeur)) {
2064
+        return $url = $profondeur;
2065
+    }
2066
+    if ($profondeur === false) {
2067
+        return $url;
2068
+    }
2069
+
2070
+    if (is_null($profondeur)) {
2071
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2072
+    }
2073
+
2074
+    if (isset($url[$profondeur])) {
2075
+        return $url[$profondeur];
2076
+    }
2077
+
2078
+    $http = 'http';
2079
+
2080
+    if (
2081
+        isset($_SERVER['SCRIPT_URI'])
2082
+        and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2083
+    ) {
2084
+        $http = 'https';
2085
+    } elseif (
2086
+        isset($_SERVER['HTTPS'])
2087
+        and test_valeur_serveur($_SERVER['HTTPS'])
2088
+    ) {
2089
+        $http = 'https';
2090
+    }
2091
+
2092
+    // note : HTTP_HOST contient le :port si necessaire
2093
+    if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2094
+        // Filtrer $host pour proteger d'attaques d'entete HTTP
2095
+        $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2096
+    }
2097
+
2098
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2099
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2100
+        $host = $GLOBALS['meta']['adresse_site'];
2101
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2102
+            $http = $scheme;
2103
+            $host = str_replace("{$scheme}://", '', $host);
2104
+        }
2105
+    }
2106
+    if (
2107
+        isset($_SERVER['SERVER_PORT'])
2108
+        and $port = $_SERVER['SERVER_PORT']
2109
+        and strpos($host, ':') == false
2110
+    ) {
2111
+        if (!defined('_PORT_HTTP_STANDARD')) {
2112
+            define('_PORT_HTTP_STANDARD', '80');
2113
+        }
2114
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2115
+            define('_PORT_HTTPS_STANDARD', '443');
2116
+        }
2117
+        if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2118
+            $host .= ":$port";
2119
+        }
2120
+        if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2121
+            $host .= ":$port";
2122
+        }
2123
+    }
2124
+
2125
+    if (!$GLOBALS['REQUEST_URI']) {
2126
+        if (isset($_SERVER['REQUEST_URI'])) {
2127
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2128
+        } else {
2129
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2130
+            if (
2131
+                !empty($_SERVER['QUERY_STRING'])
2132
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2133
+            ) {
2134
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2135
+            }
2136
+        }
2137
+    }
2138
+
2139
+    // Et nettoyer l'url
2140
+    $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2141
+
2142
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2143
+
2144
+    return $url[$profondeur];
2146 2145
 }
2147 2146
 
2148 2147
 /**
@@ -2155,26 +2154,26 @@  discard block
 block discarded – undo
2155 2154
  * @return string
2156 2155
  */
2157 2156
 function url_de_($http, $host, $request, $prof = 0) {
2158
-	$prof = max($prof, 0);
2157
+    $prof = max($prof, 0);
2159 2158
 
2160
-	$myself = ltrim($request, '/');
2161
-	# supprimer la chaine de GET
2162
-	[$myself] = explode('?', $myself);
2163
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2164
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2165
-	if (strpos($myself, '://') !== false) {
2166
-		$myself = explode('://', $myself);
2167
-		array_shift($myself);
2168
-		$myself = implode('://', $myself);
2169
-		$myself = explode('/', $myself);
2170
-		array_shift($myself);
2171
-		$myself = implode('/', $myself);
2172
-	}
2173
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2159
+    $myself = ltrim($request, '/');
2160
+    # supprimer la chaine de GET
2161
+    [$myself] = explode('?', $myself);
2162
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2163
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2164
+    if (strpos($myself, '://') !== false) {
2165
+        $myself = explode('://', $myself);
2166
+        array_shift($myself);
2167
+        $myself = implode('://', $myself);
2168
+        $myself = explode('/', $myself);
2169
+        array_shift($myself);
2170
+        $myself = implode('/', $myself);
2171
+    }
2172
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2174 2173
 
2175
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2174
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2176 2175
 
2177
-	return $url;
2176
+    return $url;
2178 2177
 }
2179 2178
 
2180 2179
 
@@ -2209,26 +2208,26 @@  discard block
 block discarded – undo
2209 2208
  * @return string URL
2210 2209
  **/
2211 2210
 function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) {
2212
-	$script ??= '';
2213
-	if (!$rel) {
2214
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2215
-	} else {
2216
-		if (!is_string($rel)) {
2217
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2218
-		}
2219
-	}
2220
-
2221
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2222
-	if ($script and ($script <> 'accueil' or $rel)) {
2223
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2224
-	} elseif ($args) {
2225
-		$args = "?$args";
2226
-	}
2227
-	if ($ancre) {
2228
-		$args .= "#$ancre";
2229
-	}
2230
-
2231
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2211
+    $script ??= '';
2212
+    if (!$rel) {
2213
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2214
+    } else {
2215
+        if (!is_string($rel)) {
2216
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2217
+        }
2218
+    }
2219
+
2220
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
2221
+    if ($script and ($script <> 'accueil' or $rel)) {
2222
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2223
+    } elseif ($args) {
2224
+        $args = "?$args";
2225
+    }
2226
+    if ($ancre) {
2227
+        $args .= "#$ancre";
2228
+    }
2229
+
2230
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2232 2231
 }
2233 2232
 
2234 2233
 //
@@ -2250,15 +2249,15 @@  discard block
 block discarded – undo
2250 2249
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2251 2250
  **/
2252 2251
 function get_spip_script($default = '') {
2253
-	if (!defined('_SPIP_SCRIPT')) {
2254
-		return 'spip.php';
2255
-	}
2256
-	# cas define('_SPIP_SCRIPT', '');
2257
-	if (_SPIP_SCRIPT) {
2258
-		return _SPIP_SCRIPT;
2259
-	} else {
2260
-		return $default;
2261
-	}
2252
+    if (!defined('_SPIP_SCRIPT')) {
2253
+        return 'spip.php';
2254
+    }
2255
+    # cas define('_SPIP_SCRIPT', '');
2256
+    if (_SPIP_SCRIPT) {
2257
+        return _SPIP_SCRIPT;
2258
+    } else {
2259
+        return $default;
2260
+    }
2262 2261
 }
2263 2262
 
2264 2263
 /**
@@ -2287,45 +2286,45 @@  discard block
 block discarded – undo
2287 2286
  * @return string URL
2288 2287
  **/
2289 2288
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2290
-	// si le script est une action (spip_pass, spip_inscription),
2291
-	// standardiser vers la nouvelle API
2292
-
2293
-	if (is_array($args)) {
2294
-		$args = http_build_query($args);
2295
-	}
2296
-
2297
-	$url = '';
2298
-	if ($f = charger_fonction_url('page')) {
2299
-		$url = $f($script, $args);
2300
-		if ($url and !$rel) {
2301
-			include_spip('inc/filtres_mini');
2302
-			$url = url_absolue($url);
2303
-		}
2304
-	}
2305
-	if (!$url) {
2306
-		if (!$action) {
2307
-			$action = get_spip_script();
2308
-		}
2309
-		if ($script) {
2310
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2311
-		}
2312
-		if ($args) {
2313
-			$action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2314
-		}
2315
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2316
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2317
-	}
2318
-
2319
-	if (!$no_entities) {
2320
-		$url = quote_amp($url);
2321
-	}
2322
-
2323
-	return $url;
2289
+    // si le script est une action (spip_pass, spip_inscription),
2290
+    // standardiser vers la nouvelle API
2291
+
2292
+    if (is_array($args)) {
2293
+        $args = http_build_query($args);
2294
+    }
2295
+
2296
+    $url = '';
2297
+    if ($f = charger_fonction_url('page')) {
2298
+        $url = $f($script, $args);
2299
+        if ($url and !$rel) {
2300
+            include_spip('inc/filtres_mini');
2301
+            $url = url_absolue($url);
2302
+        }
2303
+    }
2304
+    if (!$url) {
2305
+        if (!$action) {
2306
+            $action = get_spip_script();
2307
+        }
2308
+        if ($script) {
2309
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2310
+        }
2311
+        if ($args) {
2312
+            $action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2313
+        }
2314
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2315
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2316
+    }
2317
+
2318
+    if (!$no_entities) {
2319
+        $url = quote_amp($url);
2320
+    }
2321
+
2322
+    return $url;
2324 2323
 }
2325 2324
 
2326 2325
 function generer_url_prive($script, $args = '', $no_entities = false) {
2327 2326
 
2328
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2327
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2329 2328
 }
2330 2329
 
2331 2330
 // Pour les formulaires en methode POST,
@@ -2350,19 +2349,19 @@  discard block
 block discarded – undo
2350 2349
  **/
2351 2350
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2352 2351
 
2353
-	$script1 = explode('&', $script);
2354
-	$script1 = reset($script1);
2352
+    $script1 = explode('&', $script);
2353
+    $script1 = reset($script1);
2355 2354
 
2356
-	return "<form action='"
2357
-	. ($script ? generer_url_ecrire($script) : '')
2358
-	. "' "
2359
-	. ($atts ?: " method='post'")
2360
-	. "><div>\n"
2361
-	. "<input type='hidden' name='exec' value='$script1' />"
2362
-	. $corps
2363
-	. (!$submit ? '' :
2364
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2365
-	. "</div></form>\n";
2355
+    return "<form action='"
2356
+    . ($script ? generer_url_ecrire($script) : '')
2357
+    . "' "
2358
+    . ($atts ?: " method='post'")
2359
+    . "><div>\n"
2360
+    . "<input type='hidden' name='exec' value='$script1' />"
2361
+    . $corps
2362
+    . (!$submit ? '' :
2363
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2364
+    . "</div></form>\n";
2366 2365
 }
2367 2366
 
2368 2367
 /**
@@ -2379,22 +2378,22 @@  discard block
 block discarded – undo
2379 2378
  * @return string
2380 2379
  */
2381 2380
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2382
-	// si l'on est dans l'espace prive, on garde dans l'url
2383
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2384
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2385
-	$h = (_DIR_RACINE and !$public)
2386
-		? generer_url_ecrire(_request('exec'))
2387
-		: generer_url_public();
2381
+    // si l'on est dans l'espace prive, on garde dans l'url
2382
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2383
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2384
+    $h = (_DIR_RACINE and !$public)
2385
+        ? generer_url_ecrire(_request('exec'))
2386
+        : generer_url_public();
2388 2387
 
2389
-	return "\n<form action='" .
2390
-	$h .
2391
-	"'" .
2392
-	$atts .
2393
-	">\n" .
2394
-	'<div>' .
2395
-	"\n<input type='hidden' name='action' value='$script' />" .
2396
-	$corps .
2397
-	'</div></form>';
2388
+    return "\n<form action='" .
2389
+    $h .
2390
+    "'" .
2391
+    $atts .
2392
+    ">\n" .
2393
+    '<div>' .
2394
+    "\n<input type='hidden' name='action' value='$script' />" .
2395
+    $corps .
2396
+    '</div></form>';
2398 2397
 }
2399 2398
 
2400 2399
 /**
@@ -2413,22 +2412,22 @@  discard block
 block discarded – undo
2413 2412
  *     URL
2414 2413
  */
2415 2414
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2416
-	// si l'on est dans l'espace prive, on garde dans l'url
2417
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2418
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2419
-	$url = (_DIR_RACINE and !$public)
2420
-		? generer_url_ecrire(_request('exec'))
2421
-		: generer_url_public('', '', false, false);
2422
-	$url = parametre_url($url, 'action', $script);
2423
-	if ($args) {
2424
-		$url .= quote_amp('&' . $args);
2425
-	}
2415
+    // si l'on est dans l'espace prive, on garde dans l'url
2416
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2417
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2418
+    $url = (_DIR_RACINE and !$public)
2419
+        ? generer_url_ecrire(_request('exec'))
2420
+        : generer_url_public('', '', false, false);
2421
+    $url = parametre_url($url, 'action', $script);
2422
+    if ($args) {
2423
+        $url .= quote_amp('&' . $args);
2424
+    }
2426 2425
 
2427
-	if ($no_entities) {
2428
-		$url = str_replace('&amp;', '&', $url);
2429
-	}
2426
+    if ($no_entities) {
2427
+        $url = str_replace('&amp;', '&', $url);
2428
+    }
2430 2429
 
2431
-	return $url;
2430
+    return $url;
2432 2431
 }
2433 2432
 
2434 2433
 
@@ -2447,23 +2446,23 @@  discard block
 block discarded – undo
2447 2446
  *     URL
2448 2447
  */
2449 2448
 function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
2450
-	if (is_null($public)) {
2451
-		$public = (_DIR_RACINE ? false : '');
2452
-	}
2453
-	if (substr($script, -4) !== '.api') {
2454
-		$script .= '.api';
2455
-	}
2456
-	$url =
2457
-		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2458
-	. $script . '/'
2459
-	. ($path ? trim($path, '/') : '')
2460
-	. ($args ? '?' . quote_amp($args) : '');
2449
+    if (is_null($public)) {
2450
+        $public = (_DIR_RACINE ? false : '');
2451
+    }
2452
+    if (substr($script, -4) !== '.api') {
2453
+        $script .= '.api';
2454
+    }
2455
+    $url =
2456
+        (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2457
+    . $script . '/'
2458
+    . ($path ? trim($path, '/') : '')
2459
+    . ($args ? '?' . quote_amp($args) : '');
2461 2460
 
2462
-	if ($no_entities) {
2463
-		$url = str_replace('&amp;', '&', $url);
2464
-	}
2461
+    if ($no_entities) {
2462
+        $url = str_replace('&amp;', '&', $url);
2463
+    }
2465 2464
 
2466
-	return $url;
2465
+    return $url;
2467 2466
 }
2468 2467
 
2469 2468
 
@@ -2476,8 +2475,8 @@  discard block
 block discarded – undo
2476 2475
  * @param string $ta Répertoire temporaire accessible
2477 2476
  */
2478 2477
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2479
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2480
-	spip_initialisation_suite();
2478
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2479
+    spip_initialisation_suite();
2481 2480
 }
2482 2481
 
2483 2482
 /**
@@ -2497,310 +2496,310 @@  discard block
 block discarded – undo
2497 2496
  * @param string $ta Répertoire temporaire accessible
2498 2497
  */
2499 2498
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2500
-	static $too_late = 0;
2501
-	if ($too_late++) {
2502
-		return;
2503
-	}
2504
-
2505
-	// Declaration des repertoires
2506
-
2507
-	// le nom du repertoire plugins/ activables/desactivables
2508
-	if (!defined('_DIR_PLUGINS')) {
2509
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2510
-	}
2511
-
2512
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2513
-	if (!defined('_DIR_PLUGINS_DIST')) {
2514
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2515
-	}
2516
-
2517
-	// le nom du repertoire des librairies
2518
-	if (!defined('_DIR_LIB')) {
2519
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2520
-	}
2521
-
2522
-	if (!defined('_DIR_IMG')) {
2523
-		define('_DIR_IMG', $pa);
2524
-	}
2525
-	if (!defined('_DIR_LOGOS')) {
2526
-		define('_DIR_LOGOS', $pa);
2527
-	}
2528
-	if (!defined('_DIR_IMG_ICONES')) {
2529
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2530
-	}
2531
-
2532
-	if (!defined('_DIR_DUMP')) {
2533
-		define('_DIR_DUMP', $ti . 'dump/');
2534
-	}
2535
-	if (!defined('_DIR_SESSIONS')) {
2536
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2537
-	}
2538
-	if (!defined('_DIR_TRANSFERT')) {
2539
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2540
-	}
2541
-	if (!defined('_DIR_CACHE')) {
2542
-		define('_DIR_CACHE', $ti . 'cache/');
2543
-	}
2544
-	if (!defined('_DIR_CACHE_XML')) {
2545
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2546
-	}
2547
-	if (!defined('_DIR_SKELS')) {
2548
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2549
-	}
2550
-	if (!defined('_DIR_AIDE')) {
2551
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2552
-	}
2553
-	if (!defined('_DIR_TMP')) {
2554
-		define('_DIR_TMP', $ti);
2555
-	}
2556
-
2557
-	if (!defined('_DIR_VAR')) {
2558
-		define('_DIR_VAR', $ta);
2559
-	}
2560
-
2561
-	if (!defined('_DIR_ETC')) {
2562
-		define('_DIR_ETC', $pi);
2563
-	}
2564
-	if (!defined('_DIR_CONNECT')) {
2565
-		define('_DIR_CONNECT', $pi);
2566
-	}
2567
-	if (!defined('_DIR_CHMOD')) {
2568
-		define('_DIR_CHMOD', $pi);
2569
-	}
2570
-
2571
-	if (!isset($GLOBALS['test_dirs'])) {
2572
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2573
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2574
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2575
-	}
2576
-
2577
-	// Declaration des fichiers
2578
-
2579
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2580
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2581
-	}
2582
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2583
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2584
-	}
2585
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2586
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2587
-	}
2588
-	if (!defined('_CACHE_PIPELINES')) {
2589
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2590
-	}
2591
-	if (!defined('_CACHE_CHEMIN')) {
2592
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2593
-	}
2594
-
2595
-	# attention .php obligatoire pour ecrire_fichier_securise
2596
-	if (!defined('_FILE_META')) {
2597
-		define('_FILE_META', $ti . 'meta_cache.php');
2598
-	}
2599
-	if (!defined('_DIR_LOG')) {
2600
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2601
-	}
2602
-	if (!defined('_FILE_LOG')) {
2603
-		define('_FILE_LOG', 'spip');
2604
-	}
2605
-	if (!defined('_FILE_LOG_SUFFIX')) {
2606
-		define('_FILE_LOG_SUFFIX', '.log');
2607
-	}
2608
-
2609
-	// Le fichier de connexion a la base de donnees
2610
-	// tient compte des anciennes versions (inc_connect...)
2611
-	if (!defined('_FILE_CONNECT_INS')) {
2612
-		define('_FILE_CONNECT_INS', 'connect');
2613
-	}
2614
-	if (!defined('_FILE_CONNECT')) {
2615
-		define(
2616
-			'_FILE_CONNECT',
2617
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2618
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2619
-			: false))
2620
-		);
2621
-	}
2622
-
2623
-	// Le fichier de reglages des droits
2624
-	if (!defined('_FILE_CHMOD_INS')) {
2625
-		define('_FILE_CHMOD_INS', 'chmod');
2626
-	}
2627
-	if (!defined('_FILE_CHMOD')) {
2628
-		define(
2629
-			'_FILE_CHMOD',
2630
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2631
-			: false)
2632
-		);
2633
-	}
2634
-
2635
-	if (!defined('_FILE_LDAP')) {
2636
-		define('_FILE_LDAP', 'ldap.php');
2637
-	}
2638
-
2639
-	if (!defined('_FILE_TMP_SUFFIX')) {
2640
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2641
-	}
2642
-	if (!defined('_FILE_CONNECT_TMP')) {
2643
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2644
-	}
2645
-	if (!defined('_FILE_CHMOD_TMP')) {
2646
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2647
-	}
2648
-
2649
-	// Definition des droits d'acces en ecriture
2650
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2651
-		include_once _FILE_CHMOD;
2652
-	}
2653
-
2654
-	// Se mefier des fichiers mal remplis!
2655
-	if (!defined('_SPIP_CHMOD')) {
2656
-		define('_SPIP_CHMOD', 0777);
2657
-	}
2658
-
2659
-	if (!defined('_DEFAULT_CHARSET')) {
2660
-		/** Le charset par défaut lors de l'installation */
2661
-		define('_DEFAULT_CHARSET', 'utf-8');
2662
-	}
2663
-	if (!defined('_ROOT_PLUGINS')) {
2664
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2665
-	}
2666
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2667
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2668
-	}
2669
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2670
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2671
-	}
2672
-
2673
-	// La taille des Log
2674
-	if (!defined('_MAX_LOG')) {
2675
-		define('_MAX_LOG', 100);
2676
-	}
2677
-
2678
-	// Sommes-nous dans l'empire du Mal ?
2679
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2680
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2681
-		if (!defined('_OS_SERVEUR')) {
2682
-			define('_OS_SERVEUR', 'windows');
2683
-		}
2684
-		if (!defined('_SPIP_LOCK_MODE')) {
2685
-			define('_SPIP_LOCK_MODE', 1);
2686
-		} // utiliser le flock php
2687
-	} else {
2688
-		if (!defined('_OS_SERVEUR')) {
2689
-			define('_OS_SERVEUR', '');
2690
-		}
2691
-		if (!defined('_SPIP_LOCK_MODE')) {
2692
-			define('_SPIP_LOCK_MODE', 1);
2693
-		} // utiliser le flock php
2694
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2695
-	}
2696
-
2697
-	// Langue par defaut
2698
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2699
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2700
-	}
2701
-
2702
-	//
2703
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2704
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2705
-	// pour le rendre surchargeable, on va provoquer un reecriture
2706
-	// systematique du noyau ou une baisse de perfs => a etudier)
2707
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2708
-
2709
-	// charger tout de suite le path et son cache
2710
-	load_path_cache();
2711
-
2712
-	// *********** traiter les variables ************
2713
-
2714
-	//
2715
-	// Securite
2716
-	//
2717
-
2718
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2719
-	if (isset($_REQUEST['GLOBALS'])) {
2720
-		die();
2721
-	}
2722
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2723
-	spip_desinfecte($_GET);
2724
-	spip_desinfecte($_POST);
2725
-	spip_desinfecte($_COOKIE);
2726
-	spip_desinfecte($_REQUEST);
2727
-
2728
-	// appliquer le cookie_prefix
2729
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2730
-		include_spip('inc/cookie');
2731
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2732
-	}
2733
-
2734
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2735
-	if (isset($_SERVER['REQUEST_URI'])) {
2736
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2737
-	} else {
2738
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2739
-		if (
2740
-			!empty($_SERVER['QUERY_STRING'])
2741
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2742
-		) {
2743
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2744
-		}
2745
-	}
2746
-
2747
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2748
-	if (!defined('_RENOUVELLE_ALEA')) {
2749
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2750
-	}
2751
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2752
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2753
-	}
2754
-
2755
-	// charger les meta si possible et renouveller l'alea au besoin
2756
-	// charge aussi effacer_meta et ecrire_meta
2757
-	$inc_meta = charger_fonction('meta', 'inc');
2758
-	$inc_meta();
2759
-
2760
-	// nombre de repertoires depuis la racine
2761
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2762
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2763
-	// le calcul est faux)
2764
-	if (!_DIR_RESTREINT) {
2765
-		$GLOBALS['profondeur_url'] = 1;
2766
-	} else {
2767
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2768
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2769
-		if (
2770
-			!$uri_ref
2771
-			// si on est appele avec un autre ti, on est sans doute en mutu
2772
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2773
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2774
-			// s'en remettre a l'adresse du site. alea jacta est.
2775
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2776
-		) {
2777
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2778
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2779
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2780
-			} else {
2781
-				$uri_ref = '';
2782
-			}
2783
-		}
2784
-		if (!$uri or !$uri_ref) {
2785
-			$GLOBALS['profondeur_url'] = 0;
2786
-		} else {
2787
-			$GLOBALS['profondeur_url'] = max(
2788
-				0,
2789
-				substr_count($uri[0], '/')
2790
-				- substr_count($uri_ref, '/')
2791
-			);
2792
-		}
2793
-	}
2794
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2795
-	if (_FILE_CONNECT) {
2796
-		if (
2797
-			verifier_visiteur() == '0minirezo'
2798
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2799
-			and !isset($_COOKIE['spip_admin'])
2800
-		) {
2801
-			clear_path_cache();
2802
-		}
2803
-	}
2499
+    static $too_late = 0;
2500
+    if ($too_late++) {
2501
+        return;
2502
+    }
2503
+
2504
+    // Declaration des repertoires
2505
+
2506
+    // le nom du repertoire plugins/ activables/desactivables
2507
+    if (!defined('_DIR_PLUGINS')) {
2508
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2509
+    }
2510
+
2511
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2512
+    if (!defined('_DIR_PLUGINS_DIST')) {
2513
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2514
+    }
2515
+
2516
+    // le nom du repertoire des librairies
2517
+    if (!defined('_DIR_LIB')) {
2518
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2519
+    }
2520
+
2521
+    if (!defined('_DIR_IMG')) {
2522
+        define('_DIR_IMG', $pa);
2523
+    }
2524
+    if (!defined('_DIR_LOGOS')) {
2525
+        define('_DIR_LOGOS', $pa);
2526
+    }
2527
+    if (!defined('_DIR_IMG_ICONES')) {
2528
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2529
+    }
2530
+
2531
+    if (!defined('_DIR_DUMP')) {
2532
+        define('_DIR_DUMP', $ti . 'dump/');
2533
+    }
2534
+    if (!defined('_DIR_SESSIONS')) {
2535
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2536
+    }
2537
+    if (!defined('_DIR_TRANSFERT')) {
2538
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2539
+    }
2540
+    if (!defined('_DIR_CACHE')) {
2541
+        define('_DIR_CACHE', $ti . 'cache/');
2542
+    }
2543
+    if (!defined('_DIR_CACHE_XML')) {
2544
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2545
+    }
2546
+    if (!defined('_DIR_SKELS')) {
2547
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2548
+    }
2549
+    if (!defined('_DIR_AIDE')) {
2550
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2551
+    }
2552
+    if (!defined('_DIR_TMP')) {
2553
+        define('_DIR_TMP', $ti);
2554
+    }
2555
+
2556
+    if (!defined('_DIR_VAR')) {
2557
+        define('_DIR_VAR', $ta);
2558
+    }
2559
+
2560
+    if (!defined('_DIR_ETC')) {
2561
+        define('_DIR_ETC', $pi);
2562
+    }
2563
+    if (!defined('_DIR_CONNECT')) {
2564
+        define('_DIR_CONNECT', $pi);
2565
+    }
2566
+    if (!defined('_DIR_CHMOD')) {
2567
+        define('_DIR_CHMOD', $pi);
2568
+    }
2569
+
2570
+    if (!isset($GLOBALS['test_dirs'])) {
2571
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2572
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2573
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2574
+    }
2575
+
2576
+    // Declaration des fichiers
2577
+
2578
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2579
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2580
+    }
2581
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2582
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2583
+    }
2584
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2585
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2586
+    }
2587
+    if (!defined('_CACHE_PIPELINES')) {
2588
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2589
+    }
2590
+    if (!defined('_CACHE_CHEMIN')) {
2591
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2592
+    }
2593
+
2594
+    # attention .php obligatoire pour ecrire_fichier_securise
2595
+    if (!defined('_FILE_META')) {
2596
+        define('_FILE_META', $ti . 'meta_cache.php');
2597
+    }
2598
+    if (!defined('_DIR_LOG')) {
2599
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2600
+    }
2601
+    if (!defined('_FILE_LOG')) {
2602
+        define('_FILE_LOG', 'spip');
2603
+    }
2604
+    if (!defined('_FILE_LOG_SUFFIX')) {
2605
+        define('_FILE_LOG_SUFFIX', '.log');
2606
+    }
2607
+
2608
+    // Le fichier de connexion a la base de donnees
2609
+    // tient compte des anciennes versions (inc_connect...)
2610
+    if (!defined('_FILE_CONNECT_INS')) {
2611
+        define('_FILE_CONNECT_INS', 'connect');
2612
+    }
2613
+    if (!defined('_FILE_CONNECT')) {
2614
+        define(
2615
+            '_FILE_CONNECT',
2616
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2617
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2618
+            : false))
2619
+        );
2620
+    }
2621
+
2622
+    // Le fichier de reglages des droits
2623
+    if (!defined('_FILE_CHMOD_INS')) {
2624
+        define('_FILE_CHMOD_INS', 'chmod');
2625
+    }
2626
+    if (!defined('_FILE_CHMOD')) {
2627
+        define(
2628
+            '_FILE_CHMOD',
2629
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2630
+            : false)
2631
+        );
2632
+    }
2633
+
2634
+    if (!defined('_FILE_LDAP')) {
2635
+        define('_FILE_LDAP', 'ldap.php');
2636
+    }
2637
+
2638
+    if (!defined('_FILE_TMP_SUFFIX')) {
2639
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2640
+    }
2641
+    if (!defined('_FILE_CONNECT_TMP')) {
2642
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2643
+    }
2644
+    if (!defined('_FILE_CHMOD_TMP')) {
2645
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2646
+    }
2647
+
2648
+    // Definition des droits d'acces en ecriture
2649
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2650
+        include_once _FILE_CHMOD;
2651
+    }
2652
+
2653
+    // Se mefier des fichiers mal remplis!
2654
+    if (!defined('_SPIP_CHMOD')) {
2655
+        define('_SPIP_CHMOD', 0777);
2656
+    }
2657
+
2658
+    if (!defined('_DEFAULT_CHARSET')) {
2659
+        /** Le charset par défaut lors de l'installation */
2660
+        define('_DEFAULT_CHARSET', 'utf-8');
2661
+    }
2662
+    if (!defined('_ROOT_PLUGINS')) {
2663
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2664
+    }
2665
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2666
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2667
+    }
2668
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2669
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2670
+    }
2671
+
2672
+    // La taille des Log
2673
+    if (!defined('_MAX_LOG')) {
2674
+        define('_MAX_LOG', 100);
2675
+    }
2676
+
2677
+    // Sommes-nous dans l'empire du Mal ?
2678
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2679
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2680
+        if (!defined('_OS_SERVEUR')) {
2681
+            define('_OS_SERVEUR', 'windows');
2682
+        }
2683
+        if (!defined('_SPIP_LOCK_MODE')) {
2684
+            define('_SPIP_LOCK_MODE', 1);
2685
+        } // utiliser le flock php
2686
+    } else {
2687
+        if (!defined('_OS_SERVEUR')) {
2688
+            define('_OS_SERVEUR', '');
2689
+        }
2690
+        if (!defined('_SPIP_LOCK_MODE')) {
2691
+            define('_SPIP_LOCK_MODE', 1);
2692
+        } // utiliser le flock php
2693
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2694
+    }
2695
+
2696
+    // Langue par defaut
2697
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2698
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2699
+    }
2700
+
2701
+    //
2702
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2703
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2704
+    // pour le rendre surchargeable, on va provoquer un reecriture
2705
+    // systematique du noyau ou une baisse de perfs => a etudier)
2706
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2707
+
2708
+    // charger tout de suite le path et son cache
2709
+    load_path_cache();
2710
+
2711
+    // *********** traiter les variables ************
2712
+
2713
+    //
2714
+    // Securite
2715
+    //
2716
+
2717
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2718
+    if (isset($_REQUEST['GLOBALS'])) {
2719
+        die();
2720
+    }
2721
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2722
+    spip_desinfecte($_GET);
2723
+    spip_desinfecte($_POST);
2724
+    spip_desinfecte($_COOKIE);
2725
+    spip_desinfecte($_REQUEST);
2726
+
2727
+    // appliquer le cookie_prefix
2728
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2729
+        include_spip('inc/cookie');
2730
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2731
+    }
2732
+
2733
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2734
+    if (isset($_SERVER['REQUEST_URI'])) {
2735
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2736
+    } else {
2737
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2738
+        if (
2739
+            !empty($_SERVER['QUERY_STRING'])
2740
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2741
+        ) {
2742
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2743
+        }
2744
+    }
2745
+
2746
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2747
+    if (!defined('_RENOUVELLE_ALEA')) {
2748
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2749
+    }
2750
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2751
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2752
+    }
2753
+
2754
+    // charger les meta si possible et renouveller l'alea au besoin
2755
+    // charge aussi effacer_meta et ecrire_meta
2756
+    $inc_meta = charger_fonction('meta', 'inc');
2757
+    $inc_meta();
2758
+
2759
+    // nombre de repertoires depuis la racine
2760
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2761
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2762
+    // le calcul est faux)
2763
+    if (!_DIR_RESTREINT) {
2764
+        $GLOBALS['profondeur_url'] = 1;
2765
+    } else {
2766
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2767
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2768
+        if (
2769
+            !$uri_ref
2770
+            // si on est appele avec un autre ti, on est sans doute en mutu
2771
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2772
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2773
+            // s'en remettre a l'adresse du site. alea jacta est.
2774
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2775
+        ) {
2776
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2777
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2778
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2779
+            } else {
2780
+                $uri_ref = '';
2781
+            }
2782
+        }
2783
+        if (!$uri or !$uri_ref) {
2784
+            $GLOBALS['profondeur_url'] = 0;
2785
+        } else {
2786
+            $GLOBALS['profondeur_url'] = max(
2787
+                0,
2788
+                substr_count($uri[0], '/')
2789
+                - substr_count($uri_ref, '/')
2790
+            );
2791
+        }
2792
+    }
2793
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2794
+    if (_FILE_CONNECT) {
2795
+        if (
2796
+            verifier_visiteur() == '0minirezo'
2797
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2798
+            and !isset($_COOKIE['spip_admin'])
2799
+        ) {
2800
+            clear_path_cache();
2801
+        }
2802
+    }
2804 2803
 }
2805 2804
 
2806 2805
 /**
@@ -2809,157 +2808,157 @@  discard block
 block discarded – undo
2809 2808
  *
2810 2809
  */
2811 2810
 function spip_initialisation_suite() {
2812
-	static $too_late = 0;
2813
-	if ($too_late++) {
2814
-		return;
2815
-	}
2816
-
2817
-	// taille mini des login
2818
-	if (!defined('_LOGIN_TROP_COURT')) {
2819
-		define('_LOGIN_TROP_COURT', 4);
2820
-	}
2821
-
2822
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2823
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2824
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2825
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2826
-
2827
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2828
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2829
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2830
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2831
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2832
-
2833
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2834
-		define('_PASS_LONGUEUR_MINI', 6);
2835
-	}
2836
-
2837
-	// largeur maximale des images dans l'administration
2838
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2839
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2840
-	}
2841
-
2842
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2843
-	if (!defined('_IMG_QUALITE')) {
2844
-		define('_IMG_QUALITE', 85);
2845
-	} # valeur par defaut
2846
-	if (!defined('_IMG_GD_QUALITE')) {
2847
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2848
-	} # surcharge pour la lib GD
2849
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2850
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2851
-	} # surcharge pour imagick en ligne de commande
2852
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2853
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2854
-		define('_IMG_IMAGICK_QUALITE', 75);
2855
-	} # surcharge pour imagick en PHP
2856
-
2857
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2858
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2859
-	} // poids en octet
2860
-
2861
-	// qq chaines standard
2862
-	if (!defined('_ACCESS_FILE_NAME')) {
2863
-		define('_ACCESS_FILE_NAME', '.htaccess');
2864
-	}
2865
-	if (!defined('_AUTH_USER_FILE')) {
2866
-		define('_AUTH_USER_FILE', '.htpasswd');
2867
-	}
2868
-	if (!defined('_SPIP_DUMP')) {
2869
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2870
-	}
2871
-	if (!defined('_CACHE_RUBRIQUES')) {
2872
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2873
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2874
-	}
2875
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2876
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2877
-		define('_CACHE_RUBRIQUES_MAX', 500);
2878
-	}
2879
-
2880
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2881
-		/**
2882
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2883
-		 * @var int Nombre de caractères */
2884
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2885
-	}
2886
-
2887
-	if (!defined('_EXTENSION_SQUELETTES')) {
2888
-		define('_EXTENSION_SQUELETTES', 'html');
2889
-	}
2890
-
2891
-	if (!defined('_DOCTYPE_ECRIRE')) {
2892
-		/** Définit le doctype de l’espace privé */
2893
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2894
-	}
2895
-	if (!defined('_DOCTYPE_AIDE')) {
2896
-		/** Définit le doctype de l’aide en ligne */
2897
-		define(
2898
-			'_DOCTYPE_AIDE',
2899
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2900
-		);
2901
-	}
2902
-
2903
-	if (!defined('_SPIP_SCRIPT')) {
2904
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2905
-		 * le script de l'espace public, alias index.php */
2906
-		define('_SPIP_SCRIPT', 'spip.php');
2907
-	}
2908
-	if (!defined('_SPIP_PAGE')) {
2909
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2910
-		define('_SPIP_PAGE', 'page');
2911
-	}
2912
-
2913
-	// le script de l'espace prive
2914
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2915
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2916
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2917
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2918
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2919
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2920
-		} else {
2921
-			define('_SPIP_ECRIRE_SCRIPT', '');
2922
-		}
2923
-	}
2924
-
2925
-
2926
-	if (!defined('_SPIP_AJAX')) {
2927
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2928
-			? 1
2929
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2930
-	}
2931
-
2932
-	// La requete est-elle en ajax ?
2933
-	if (!defined('_AJAX')) {
2934
-		define(
2935
-			'_AJAX',
2936
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2937
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2938
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2939
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2940
-			)
2941
-			and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2942
-		);
2943
-	}
2944
-
2945
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2946
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2947
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2948
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2949
-		define(
2950
-			'_IMG_GD_MAX_PIXELS',
2951
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2952
-			? $GLOBALS['meta']['max_taille_vignettes']
2953
-			: 0
2954
-		);
2955
-	}
2956
-
2957
-	// Protocoles a normaliser dans les chaines de langues
2958
-	if (!defined('_PROTOCOLES_STD')) {
2959
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2960
-	}
2961
-
2962
-	init_var_mode();
2811
+    static $too_late = 0;
2812
+    if ($too_late++) {
2813
+        return;
2814
+    }
2815
+
2816
+    // taille mini des login
2817
+    if (!defined('_LOGIN_TROP_COURT')) {
2818
+        define('_LOGIN_TROP_COURT', 4);
2819
+    }
2820
+
2821
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2822
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2823
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2824
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2825
+
2826
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2827
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2828
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2829
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2830
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2831
+
2832
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2833
+        define('_PASS_LONGUEUR_MINI', 6);
2834
+    }
2835
+
2836
+    // largeur maximale des images dans l'administration
2837
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2838
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2839
+    }
2840
+
2841
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2842
+    if (!defined('_IMG_QUALITE')) {
2843
+        define('_IMG_QUALITE', 85);
2844
+    } # valeur par defaut
2845
+    if (!defined('_IMG_GD_QUALITE')) {
2846
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2847
+    } # surcharge pour la lib GD
2848
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2849
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2850
+    } # surcharge pour imagick en ligne de commande
2851
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2852
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2853
+        define('_IMG_IMAGICK_QUALITE', 75);
2854
+    } # surcharge pour imagick en PHP
2855
+
2856
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2857
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2858
+    } // poids en octet
2859
+
2860
+    // qq chaines standard
2861
+    if (!defined('_ACCESS_FILE_NAME')) {
2862
+        define('_ACCESS_FILE_NAME', '.htaccess');
2863
+    }
2864
+    if (!defined('_AUTH_USER_FILE')) {
2865
+        define('_AUTH_USER_FILE', '.htpasswd');
2866
+    }
2867
+    if (!defined('_SPIP_DUMP')) {
2868
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2869
+    }
2870
+    if (!defined('_CACHE_RUBRIQUES')) {
2871
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2872
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2873
+    }
2874
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2875
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2876
+        define('_CACHE_RUBRIQUES_MAX', 500);
2877
+    }
2878
+
2879
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2880
+        /**
2881
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2882
+         * @var int Nombre de caractères */
2883
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2884
+    }
2885
+
2886
+    if (!defined('_EXTENSION_SQUELETTES')) {
2887
+        define('_EXTENSION_SQUELETTES', 'html');
2888
+    }
2889
+
2890
+    if (!defined('_DOCTYPE_ECRIRE')) {
2891
+        /** Définit le doctype de l’espace privé */
2892
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2893
+    }
2894
+    if (!defined('_DOCTYPE_AIDE')) {
2895
+        /** Définit le doctype de l’aide en ligne */
2896
+        define(
2897
+            '_DOCTYPE_AIDE',
2898
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2899
+        );
2900
+    }
2901
+
2902
+    if (!defined('_SPIP_SCRIPT')) {
2903
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2904
+         * le script de l'espace public, alias index.php */
2905
+        define('_SPIP_SCRIPT', 'spip.php');
2906
+    }
2907
+    if (!defined('_SPIP_PAGE')) {
2908
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2909
+        define('_SPIP_PAGE', 'page');
2910
+    }
2911
+
2912
+    // le script de l'espace prive
2913
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2914
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2915
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2916
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2917
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2918
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2919
+        } else {
2920
+            define('_SPIP_ECRIRE_SCRIPT', '');
2921
+        }
2922
+    }
2923
+
2924
+
2925
+    if (!defined('_SPIP_AJAX')) {
2926
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2927
+            ? 1
2928
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2929
+    }
2930
+
2931
+    // La requete est-elle en ajax ?
2932
+    if (!defined('_AJAX')) {
2933
+        define(
2934
+            '_AJAX',
2935
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2936
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2937
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2938
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2939
+            )
2940
+            and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient
2941
+        );
2942
+    }
2943
+
2944
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2945
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2946
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2947
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2948
+        define(
2949
+            '_IMG_GD_MAX_PIXELS',
2950
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2951
+            ? $GLOBALS['meta']['max_taille_vignettes']
2952
+            : 0
2953
+        );
2954
+    }
2955
+
2956
+    // Protocoles a normaliser dans les chaines de langues
2957
+    if (!defined('_PROTOCOLES_STD')) {
2958
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2959
+    }
2960
+
2961
+    init_var_mode();
2963 2962
 }
2964 2963
 
2965 2964
 /**
@@ -2993,136 +2992,136 @@  discard block
 block discarded – undo
2993 2992
  * `   var_mode` (calcul ou recalcul).
2994 2993
  */
2995 2994
 function init_var_mode() {
2996
-	static $done = false;
2997
-	if (!$done) {
2998
-		if (isset($_GET['var_mode'])) {
2999
-			$var_mode = explode(',', $_GET['var_mode']);
3000
-			// tout le monde peut calcul/recalcul
3001
-			if (!defined('_VAR_MODE')) {
3002
-				if (in_array('recalcul', $var_mode)) {
3003
-					define('_VAR_MODE', 'recalcul');
3004
-				} elseif (in_array('calcul', $var_mode)) {
3005
-					define('_VAR_MODE', 'calcul');
3006
-				}
3007
-			}
3008
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3009
-			if ($var_mode) {
3010
-				include_spip('inc/autoriser');
3011
-				// autoriser preview si preview seulement, et sinon autoriser debug
3012
-				if (
3013
-					autoriser(
3014
-						($_GET['var_mode'] == 'preview')
3015
-						? 'previsualiser'
3016
-						: 'debug'
3017
-					)
3018
-				) {
3019
-					if (in_array('traduction', $var_mode)) {
3020
-						// forcer le calcul pour passer dans traduire
3021
-						if (!defined('_VAR_MODE')) {
3022
-							define('_VAR_MODE', 'calcul');
3023
-						}
3024
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3025
-						if (!defined('_VAR_NOCACHE')) {
3026
-							define('_VAR_NOCACHE', true);
3027
-						}
3028
-						$var_mode = array_diff($var_mode, ['traduction']);
3029
-					}
3030
-					if (in_array('preview', $var_mode)) {
3031
-						// basculer sur les criteres de preview dans les boucles
3032
-						if (!defined('_VAR_PREVIEW')) {
3033
-							define('_VAR_PREVIEW', true);
3034
-						}
3035
-						// forcer le calcul
3036
-						if (!defined('_VAR_MODE')) {
3037
-							define('_VAR_MODE', 'calcul');
3038
-						}
3039
-						// et ne pas enregistrer de cache
3040
-						if (!defined('_VAR_NOCACHE')) {
3041
-							define('_VAR_NOCACHE', true);
3042
-						}
3043
-						$var_mode = array_diff($var_mode, ['preview']);
3044
-					}
3045
-					if (in_array('inclure', $var_mode)) {
3046
-						// forcer le compilo et ignorer les caches existants
3047
-						if (!defined('_VAR_MODE')) {
3048
-							define('_VAR_MODE', 'calcul');
3049
-						}
3050
-						if (!defined('_VAR_INCLURE')) {
3051
-							define('_VAR_INCLURE', true);
3052
-						}
3053
-						// et ne pas enregistrer de cache
3054
-						if (!defined('_VAR_NOCACHE')) {
3055
-							define('_VAR_NOCACHE', true);
3056
-						}
3057
-						$var_mode = array_diff($var_mode, ['inclure']);
3058
-					}
3059
-					if (in_array('urls', $var_mode)) {
3060
-						// forcer le compilo et ignorer les caches existants
3061
-						if (!defined('_VAR_MODE')) {
3062
-							define('_VAR_MODE', 'calcul');
3063
-						}
3064
-						if (!defined('_VAR_URLS')) {
3065
-							define('_VAR_URLS', true);
3066
-						}
3067
-						$var_mode = array_diff($var_mode, ['urls']);
3068
-					}
3069
-					if (in_array('images', $var_mode)) {
3070
-						// forcer le compilo et ignorer les caches existants
3071
-						if (!defined('_VAR_MODE')) {
3072
-							define('_VAR_MODE', 'calcul');
3073
-						}
3074
-						// indiquer qu'on doit recalculer les images
3075
-						if (!defined('_VAR_IMAGES')) {
3076
-							define('_VAR_IMAGES', true);
3077
-						}
3078
-						$var_mode = array_diff($var_mode, ['images']);
3079
-					}
3080
-					if (in_array('debug', $var_mode)) {
3081
-						if (!defined('_VAR_MODE')) {
3082
-							define('_VAR_MODE', 'debug');
3083
-						}
3084
-						// et ne pas enregistrer de cache
3085
-						if (!defined('_VAR_NOCACHE')) {
3086
-							define('_VAR_NOCACHE', true);
3087
-						}
3088
-						$var_mode = array_diff($var_mode, ['debug']);
3089
-					}
3090
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3091
-						define('_VAR_MODE', reset($var_mode));
3092
-					}
3093
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3094
-						spip_log($GLOBALS['visiteur_session']['nom']
3095
-							. ' ' . _VAR_MODE);
3096
-					}
3097
-				} // pas autorise ?
3098
-				else {
3099
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3100
-					if (
3101
-						!$GLOBALS['visiteur_session']
3102
-						and !empty($_SERVER['HTTP_HOST'])
3103
-						and !empty($_SERVER['REQUEST_METHOD'])
3104
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3105
-					) {
3106
-						$self = self('&', true);
3107
-						if (strpos($self, 'page=login') === false) {
3108
-							include_spip('inc/headers');
3109
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3110
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3111
-						}
3112
-					}
3113
-					// sinon tant pis
3114
-				}
3115
-			}
3116
-		}
3117
-		if (!defined('_VAR_MODE')) {
3118
-			/**
3119
-			 * Indique le mode de calcul ou d'affichage de la page.
3120
-			 * @see init_var_mode()
3121
-			 */
3122
-			define('_VAR_MODE', false);
3123
-		}
3124
-		$done = true;
3125
-	}
2995
+    static $done = false;
2996
+    if (!$done) {
2997
+        if (isset($_GET['var_mode'])) {
2998
+            $var_mode = explode(',', $_GET['var_mode']);
2999
+            // tout le monde peut calcul/recalcul
3000
+            if (!defined('_VAR_MODE')) {
3001
+                if (in_array('recalcul', $var_mode)) {
3002
+                    define('_VAR_MODE', 'recalcul');
3003
+                } elseif (in_array('calcul', $var_mode)) {
3004
+                    define('_VAR_MODE', 'calcul');
3005
+                }
3006
+            }
3007
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3008
+            if ($var_mode) {
3009
+                include_spip('inc/autoriser');
3010
+                // autoriser preview si preview seulement, et sinon autoriser debug
3011
+                if (
3012
+                    autoriser(
3013
+                        ($_GET['var_mode'] == 'preview')
3014
+                        ? 'previsualiser'
3015
+                        : 'debug'
3016
+                    )
3017
+                ) {
3018
+                    if (in_array('traduction', $var_mode)) {
3019
+                        // forcer le calcul pour passer dans traduire
3020
+                        if (!defined('_VAR_MODE')) {
3021
+                            define('_VAR_MODE', 'calcul');
3022
+                        }
3023
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3024
+                        if (!defined('_VAR_NOCACHE')) {
3025
+                            define('_VAR_NOCACHE', true);
3026
+                        }
3027
+                        $var_mode = array_diff($var_mode, ['traduction']);
3028
+                    }
3029
+                    if (in_array('preview', $var_mode)) {
3030
+                        // basculer sur les criteres de preview dans les boucles
3031
+                        if (!defined('_VAR_PREVIEW')) {
3032
+                            define('_VAR_PREVIEW', true);
3033
+                        }
3034
+                        // forcer le calcul
3035
+                        if (!defined('_VAR_MODE')) {
3036
+                            define('_VAR_MODE', 'calcul');
3037
+                        }
3038
+                        // et ne pas enregistrer de cache
3039
+                        if (!defined('_VAR_NOCACHE')) {
3040
+                            define('_VAR_NOCACHE', true);
3041
+                        }
3042
+                        $var_mode = array_diff($var_mode, ['preview']);
3043
+                    }
3044
+                    if (in_array('inclure', $var_mode)) {
3045
+                        // forcer le compilo et ignorer les caches existants
3046
+                        if (!defined('_VAR_MODE')) {
3047
+                            define('_VAR_MODE', 'calcul');
3048
+                        }
3049
+                        if (!defined('_VAR_INCLURE')) {
3050
+                            define('_VAR_INCLURE', true);
3051
+                        }
3052
+                        // et ne pas enregistrer de cache
3053
+                        if (!defined('_VAR_NOCACHE')) {
3054
+                            define('_VAR_NOCACHE', true);
3055
+                        }
3056
+                        $var_mode = array_diff($var_mode, ['inclure']);
3057
+                    }
3058
+                    if (in_array('urls', $var_mode)) {
3059
+                        // forcer le compilo et ignorer les caches existants
3060
+                        if (!defined('_VAR_MODE')) {
3061
+                            define('_VAR_MODE', 'calcul');
3062
+                        }
3063
+                        if (!defined('_VAR_URLS')) {
3064
+                            define('_VAR_URLS', true);
3065
+                        }
3066
+                        $var_mode = array_diff($var_mode, ['urls']);
3067
+                    }
3068
+                    if (in_array('images', $var_mode)) {
3069
+                        // forcer le compilo et ignorer les caches existants
3070
+                        if (!defined('_VAR_MODE')) {
3071
+                            define('_VAR_MODE', 'calcul');
3072
+                        }
3073
+                        // indiquer qu'on doit recalculer les images
3074
+                        if (!defined('_VAR_IMAGES')) {
3075
+                            define('_VAR_IMAGES', true);
3076
+                        }
3077
+                        $var_mode = array_diff($var_mode, ['images']);
3078
+                    }
3079
+                    if (in_array('debug', $var_mode)) {
3080
+                        if (!defined('_VAR_MODE')) {
3081
+                            define('_VAR_MODE', 'debug');
3082
+                        }
3083
+                        // et ne pas enregistrer de cache
3084
+                        if (!defined('_VAR_NOCACHE')) {
3085
+                            define('_VAR_NOCACHE', true);
3086
+                        }
3087
+                        $var_mode = array_diff($var_mode, ['debug']);
3088
+                    }
3089
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3090
+                        define('_VAR_MODE', reset($var_mode));
3091
+                    }
3092
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3093
+                        spip_log($GLOBALS['visiteur_session']['nom']
3094
+                            . ' ' . _VAR_MODE);
3095
+                    }
3096
+                } // pas autorise ?
3097
+                else {
3098
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3099
+                    if (
3100
+                        !$GLOBALS['visiteur_session']
3101
+                        and !empty($_SERVER['HTTP_HOST'])
3102
+                        and !empty($_SERVER['REQUEST_METHOD'])
3103
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3104
+                    ) {
3105
+                        $self = self('&', true);
3106
+                        if (strpos($self, 'page=login') === false) {
3107
+                            include_spip('inc/headers');
3108
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3109
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3110
+                        }
3111
+                    }
3112
+                    // sinon tant pis
3113
+                }
3114
+            }
3115
+        }
3116
+        if (!defined('_VAR_MODE')) {
3117
+            /**
3118
+             * Indique le mode de calcul ou d'affichage de la page.
3119
+             * @see init_var_mode()
3120
+             */
3121
+            define('_VAR_MODE', false);
3122
+        }
3123
+        $done = true;
3124
+    }
3126 3125
 }
3127 3126
 
3128 3127
 /**
@@ -3134,16 +3133,16 @@  discard block
 block discarded – undo
3134 3133
  * @param bool $deep = true : appliquer récursivement
3135 3134
 **/
3136 3135
 function spip_desinfecte(&$t, $deep = true) {
3137
-	foreach ($t as $key => $val) {
3138
-		if (is_string($t[$key])) {
3139
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3140
-		} // traiter aussi les "texte_plus" de article_edit
3141
-		else {
3142
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3143
-				spip_desinfecte($t[$key], $deep);
3144
-			}
3145
-		}
3146
-	}
3136
+    foreach ($t as $key => $val) {
3137
+        if (is_string($t[$key])) {
3138
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3139
+        } // traiter aussi les "texte_plus" de article_edit
3140
+        else {
3141
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3142
+                spip_desinfecte($t[$key], $deep);
3143
+            }
3144
+        }
3145
+    }
3147 3146
 }
3148 3147
 
3149 3148
 /**
@@ -3156,64 +3155,64 @@  discard block
 block discarded – undo
3156 3155
  * @return string|0|false
3157 3156
 **/
3158 3157
 function verifier_visiteur() {
3159
-	@spip_initialisation_core(
3160
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3161
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3162
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3163
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3164
-	);
3165
-
3166
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3167
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3168
-	// Attention on separe bien session_nom et nom, pour eviter
3169
-	// les melanges entre donnees SQL et variables plus aleatoires
3170
-	$variables_session = ['session_nom', 'session_email'];
3171
-	foreach ($variables_session as $var) {
3172
-		if (_request($var) !== null) {
3173
-			$init = true;
3174
-			break;
3175
-		}
3176
-	}
3177
-	if (isset($init)) {
3178
-		#@spip_initialisation_suite();
3179
-		$session = charger_fonction('session', 'inc');
3180
-		$session();
3181
-		include_spip('inc/texte');
3182
-		foreach ($variables_session as $var) {
3183
-			if (($a = _request($var)) !== null) {
3184
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3185
-			}
3186
-		}
3187
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3188
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3189
-		}
3190
-		$session($GLOBALS['visiteur_session']);
3191
-
3192
-		return 0;
3193
-	}
3194
-
3195
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3196
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3197
-		$session = charger_fonction('session', 'inc');
3198
-		if ($session()) {
3199
-			return $GLOBALS['visiteur_session']['statut'];
3200
-		}
3201
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3202
-			include_spip('inc/auth');
3203
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3204
-		}
3205
-		if ($h) {
3206
-			$GLOBALS['visiteur_session'] = $h;
3207
-
3208
-			return $GLOBALS['visiteur_session']['statut'];
3209
-		}
3210
-	}
3211
-
3212
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3213
-	include_spip('inc/lang');
3214
-	utiliser_langue_visiteur();
3215
-
3216
-	return false;
3158
+    @spip_initialisation_core(
3159
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3160
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3161
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3162
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3163
+    );
3164
+
3165
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3166
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3167
+    // Attention on separe bien session_nom et nom, pour eviter
3168
+    // les melanges entre donnees SQL et variables plus aleatoires
3169
+    $variables_session = ['session_nom', 'session_email'];
3170
+    foreach ($variables_session as $var) {
3171
+        if (_request($var) !== null) {
3172
+            $init = true;
3173
+            break;
3174
+        }
3175
+    }
3176
+    if (isset($init)) {
3177
+        #@spip_initialisation_suite();
3178
+        $session = charger_fonction('session', 'inc');
3179
+        $session();
3180
+        include_spip('inc/texte');
3181
+        foreach ($variables_session as $var) {
3182
+            if (($a = _request($var)) !== null) {
3183
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3184
+            }
3185
+        }
3186
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3187
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3188
+        }
3189
+        $session($GLOBALS['visiteur_session']);
3190
+
3191
+        return 0;
3192
+    }
3193
+
3194
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3195
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3196
+        $session = charger_fonction('session', 'inc');
3197
+        if ($session()) {
3198
+            return $GLOBALS['visiteur_session']['statut'];
3199
+        }
3200
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3201
+            include_spip('inc/auth');
3202
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3203
+        }
3204
+        if ($h) {
3205
+            $GLOBALS['visiteur_session'] = $h;
3206
+
3207
+            return $GLOBALS['visiteur_session']['statut'];
3208
+        }
3209
+    }
3210
+
3211
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3212
+    include_spip('inc/lang');
3213
+    utiliser_langue_visiteur();
3214
+
3215
+    return false;
3217 3216
 }
3218 3217
 
3219 3218
 
@@ -3236,21 +3235,21 @@  discard block
 block discarded – undo
3236 3235
  *     - string Langue utilisée.
3237 3236
  **/
3238 3237
 function lang_select($lang = null) {
3239
-	static $pile_langues = [];
3240
-	if (!function_exists('changer_langue')) {
3241
-		include_spip('inc/lang');
3242
-	}
3243
-	if ($lang === null) {
3244
-		$lang = array_pop($pile_langues);
3245
-	} else {
3246
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3247
-	}
3248
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3249
-		return $lang;
3250
-	}
3251
-	changer_langue($lang);
3238
+    static $pile_langues = [];
3239
+    if (!function_exists('changer_langue')) {
3240
+        include_spip('inc/lang');
3241
+    }
3242
+    if ($lang === null) {
3243
+        $lang = array_pop($pile_langues);
3244
+    } else {
3245
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3246
+    }
3247
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3248
+        return $lang;
3249
+    }
3250
+    changer_langue($lang);
3252 3251
 
3253
-	return $lang;
3252
+    return $lang;
3254 3253
 }
3255 3254
 
3256 3255
 /**
@@ -3267,20 +3266,20 @@  discard block
 block discarded – undo
3267 3266
  *     Identifiant de la session
3268 3267
  **/
3269 3268
 function spip_session($force = false) {
3270
-	static $session;
3271
-	if ($force or !isset($session)) {
3272
-		$s = pipeline(
3273
-			'definir_session',
3274
-			$GLOBALS['visiteur_session']
3275
-				? serialize($GLOBALS['visiteur_session'])
3276
-				. '_' . @$_COOKIE['spip_session']
3277
-				: ''
3278
-		);
3279
-		$session = $s ? substr(md5($s), 0, 8) : '';
3280
-	}
3269
+    static $session;
3270
+    if ($force or !isset($session)) {
3271
+        $s = pipeline(
3272
+            'definir_session',
3273
+            $GLOBALS['visiteur_session']
3274
+                ? serialize($GLOBALS['visiteur_session'])
3275
+                . '_' . @$_COOKIE['spip_session']
3276
+                : ''
3277
+        );
3278
+        $session = $s ? substr(md5($s), 0, 8) : '';
3279
+    }
3281 3280
 
3282
-	#spip_log('session: '.$session);
3283
-	return $session;
3281
+    #spip_log('session: '.$session);
3282
+    return $session;
3284 3283
 }
3285 3284
 
3286 3285
 
@@ -3299,9 +3298,9 @@  discard block
 block discarded – undo
3299 3298
  *    Lien sur une icone d'aide
3300 3299
  **/
3301 3300
 function aider($aide = '', $distante = false) {
3302
-	$aider = charger_fonction('aide', 'inc', true);
3301
+    $aider = charger_fonction('aide', 'inc', true);
3303 3302
 
3304
-	return $aider ? $aider($aide, '', [], $distante) : '';
3303
+    return $aider ? $aider($aide, '', [], $distante) : '';
3305 3304
 }
3306 3305
 
3307 3306
 /**
@@ -3311,35 +3310,35 @@  discard block
 block discarded – undo
3311 3310
  */
3312 3311
 function exec_info_dist() {
3313 3312
 
3314
-	include_spip('inc/autoriser');
3315
-	if (autoriser('phpinfos')) {
3316
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3317
-		$cookies_backup = [];
3318
-		$server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE']];
3319
-		$env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE']];
3320
-		$mask = '******************************';
3321
-		foreach ($cookies_masques as $k) {
3322
-			if (!empty($_COOKIE[$k])) {
3323
-				$cookies_backup[$k] = $_COOKIE[$k];
3324
-				$_SERVER['HTTP_COOKIE'] = str_replace("$k=".$_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE']);
3325
-				$_ENV['HTTP_COOKIE'] = str_replace("$k=".$_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE']);
3326
-				$_COOKIE[$k] = $mask;
3327
-			}
3328
-		}
3329
-		phpinfo();
3330
-		foreach ($cookies_backup as $k => $v) {
3331
-			$_COOKIE[$k] = $v;
3332
-		}
3333
-		foreach ($server_backup as $k => $v) {
3334
-			$_SERVER[$k] = $v;
3335
-		}
3336
-		foreach ($env_backup as $k => $v) {
3337
-			$_ENV[$k] = $v;
3338
-		}
3339
-	} else {
3340
-		include_spip('inc/filtres');
3341
-		sinon_interdire_acces();
3342
-	}
3313
+    include_spip('inc/autoriser');
3314
+    if (autoriser('phpinfos')) {
3315
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3316
+        $cookies_backup = [];
3317
+        $server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE']];
3318
+        $env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE']];
3319
+        $mask = '******************************';
3320
+        foreach ($cookies_masques as $k) {
3321
+            if (!empty($_COOKIE[$k])) {
3322
+                $cookies_backup[$k] = $_COOKIE[$k];
3323
+                $_SERVER['HTTP_COOKIE'] = str_replace("$k=".$_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE']);
3324
+                $_ENV['HTTP_COOKIE'] = str_replace("$k=".$_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE']);
3325
+                $_COOKIE[$k] = $mask;
3326
+            }
3327
+        }
3328
+        phpinfo();
3329
+        foreach ($cookies_backup as $k => $v) {
3330
+            $_COOKIE[$k] = $v;
3331
+        }
3332
+        foreach ($server_backup as $k => $v) {
3333
+            $_SERVER[$k] = $v;
3334
+        }
3335
+        foreach ($env_backup as $k => $v) {
3336
+            $_ENV[$k] = $v;
3337
+        }
3338
+    } else {
3339
+        include_spip('inc/filtres');
3340
+        sinon_interdire_acces();
3341
+    }
3343 3342
 }
3344 3343
 
3345 3344
 /**
@@ -3359,13 +3358,13 @@  discard block
 block discarded – undo
3359 3358
  *     - string si $message à false.
3360 3359
  **/
3361 3360
 function erreur_squelette($message = '', $lieu = '') {
3362
-	$debusquer = charger_fonction('debusquer', 'public');
3363
-	if (is_array($lieu)) {
3364
-		include_spip('public/compiler');
3365
-		$lieu = reconstruire_contexte_compil($lieu);
3366
-	}
3361
+    $debusquer = charger_fonction('debusquer', 'public');
3362
+    if (is_array($lieu)) {
3363
+        include_spip('public/compiler');
3364
+        $lieu = reconstruire_contexte_compil($lieu);
3365
+    }
3367 3366
 
3368
-	return $debusquer($message, $lieu);
3367
+    return $debusquer($message, $lieu);
3369 3368
 }
3370 3369
 
3371 3370
 /**
@@ -3402,108 +3401,108 @@  discard block
 block discarded – undo
3402 3401
  *     - ou tableau d'information sur le squelette.
3403 3402
  */
3404 3403
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3405
-	if (!function_exists('evaluer_fond')) {
3406
-		include_spip('public/assembler');
3407
-	}
3408
-	// assurer la compat avec l'ancienne syntaxe
3409
-	// (trim etait le 3eme argument, par defaut a true)
3410
-	if (!is_array($options)) {
3411
-		$options = ['trim' => $options];
3412
-	}
3413
-	if (!isset($options['trim'])) {
3414
-		$options['trim'] = true;
3415
-	}
3416
-
3417
-	if (isset($contexte['connect'])) {
3418
-		$connect = $contexte['connect'];
3419
-		unset($contexte['connect']);
3420
-	}
3421
-
3422
-	$texte = '';
3423
-	$pages = [];
3424
-	$lang_select = '';
3425
-	if (!isset($options['etoile']) or !$options['etoile']) {
3426
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3427
-		if (!isset($contexte['lang'])) {
3428
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3429
-		}
3430
-
3431
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3432
-			$lang_select = lang_select($contexte['lang']);
3433
-		}
3434
-	}
3435
-
3436
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3437
-		$GLOBALS['_INC_PUBLIC'] = 0;
3438
-	}
3439
-
3440
-	$GLOBALS['_INC_PUBLIC']++;
3441
-
3442
-	// fix #4235
3443
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3444
-
3445
-
3446
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3447
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3448
-
3449
-		$page = evaluer_fond($f, $contexte, $connect);
3450
-		if ($page === '') {
3451
-			$c = $options['compil'] ?? '';
3452
-			$a = ['fichier' => $f];
3453
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3454
-			erreur_squelette($erreur, $c);
3455
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3456
-			$page = ['texte' => '', 'erreur' => $erreur];
3457
-		}
3458
-
3459
-		$page = pipeline('recuperer_fond', [
3460
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3461
-			'data' => $page
3462
-		]);
3463
-		if (isset($options['ajax']) and $options['ajax']) {
3464
-			if (!function_exists('encoder_contexte_ajax')) {
3465
-				include_spip('inc/filtres');
3466
-			}
3467
-			$page['texte'] = encoder_contexte_ajax(
3468
-				array_merge(
3469
-					$contexte,
3470
-					['fond' => $f],
3471
-					($connect ? ['connect' => $connect] : [])
3472
-				),
3473
-				'',
3474
-				$page['texte'],
3475
-				$options['ajax']
3476
-			);
3477
-		}
3478
-
3479
-		if (isset($options['raw']) and $options['raw']) {
3480
-			$pages[] = $page;
3481
-		} else {
3482
-			$texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3483
-		}
3484
-
3485
-		// contamination de la session appelante, pour les inclusions statiques
3486
-		if (isset($page['invalideurs']['session'])) {
3487
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3488
-		}
3489
-	}
3490
-
3491
-	// restaurer le sessionnement du contexte appelant,
3492
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3493
-	if (isset($cache_utilise_session_appelant)) {
3494
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3495
-	}
3496
-
3497
-	$GLOBALS['_INC_PUBLIC']--;
3498
-
3499
-	if ($lang_select) {
3500
-		lang_select();
3501
-	}
3502
-	if (isset($options['raw']) and $options['raw']) {
3503
-		return is_array($fond) ? $pages : reset($pages);
3504
-	} else {
3505
-		return $options['trim'] ? ltrim($texte) : $texte;
3506
-	}
3404
+    if (!function_exists('evaluer_fond')) {
3405
+        include_spip('public/assembler');
3406
+    }
3407
+    // assurer la compat avec l'ancienne syntaxe
3408
+    // (trim etait le 3eme argument, par defaut a true)
3409
+    if (!is_array($options)) {
3410
+        $options = ['trim' => $options];
3411
+    }
3412
+    if (!isset($options['trim'])) {
3413
+        $options['trim'] = true;
3414
+    }
3415
+
3416
+    if (isset($contexte['connect'])) {
3417
+        $connect = $contexte['connect'];
3418
+        unset($contexte['connect']);
3419
+    }
3420
+
3421
+    $texte = '';
3422
+    $pages = [];
3423
+    $lang_select = '';
3424
+    if (!isset($options['etoile']) or !$options['etoile']) {
3425
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3426
+        if (!isset($contexte['lang'])) {
3427
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3428
+        }
3429
+
3430
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3431
+            $lang_select = lang_select($contexte['lang']);
3432
+        }
3433
+    }
3434
+
3435
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3436
+        $GLOBALS['_INC_PUBLIC'] = 0;
3437
+    }
3438
+
3439
+    $GLOBALS['_INC_PUBLIC']++;
3440
+
3441
+    // fix #4235
3442
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3443
+
3444
+
3445
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3446
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3447
+
3448
+        $page = evaluer_fond($f, $contexte, $connect);
3449
+        if ($page === '') {
3450
+            $c = $options['compil'] ?? '';
3451
+            $a = ['fichier' => $f];
3452
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3453
+            erreur_squelette($erreur, $c);
3454
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3455
+            $page = ['texte' => '', 'erreur' => $erreur];
3456
+        }
3457
+
3458
+        $page = pipeline('recuperer_fond', [
3459
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3460
+            'data' => $page
3461
+        ]);
3462
+        if (isset($options['ajax']) and $options['ajax']) {
3463
+            if (!function_exists('encoder_contexte_ajax')) {
3464
+                include_spip('inc/filtres');
3465
+            }
3466
+            $page['texte'] = encoder_contexte_ajax(
3467
+                array_merge(
3468
+                    $contexte,
3469
+                    ['fond' => $f],
3470
+                    ($connect ? ['connect' => $connect] : [])
3471
+                ),
3472
+                '',
3473
+                $page['texte'],
3474
+                $options['ajax']
3475
+            );
3476
+        }
3477
+
3478
+        if (isset($options['raw']) and $options['raw']) {
3479
+            $pages[] = $page;
3480
+        } else {
3481
+            $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3482
+        }
3483
+
3484
+        // contamination de la session appelante, pour les inclusions statiques
3485
+        if (isset($page['invalideurs']['session'])) {
3486
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3487
+        }
3488
+    }
3489
+
3490
+    // restaurer le sessionnement du contexte appelant,
3491
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3492
+    if (isset($cache_utilise_session_appelant)) {
3493
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3494
+    }
3495
+
3496
+    $GLOBALS['_INC_PUBLIC']--;
3497
+
3498
+    if ($lang_select) {
3499
+        lang_select();
3500
+    }
3501
+    if (isset($options['raw']) and $options['raw']) {
3502
+        return is_array($fond) ? $pages : reset($pages);
3503
+    } else {
3504
+        return $options['trim'] ? ltrim($texte) : $texte;
3505
+    }
3507 3506
 }
3508 3507
 
3509 3508
 /**
@@ -3513,7 +3512,7 @@  discard block
 block discarded – undo
3513 3512
  * @return string
3514 3513
  */
3515 3514
 function trouve_modele($nom) {
3516
-	return trouver_fond($nom, 'modeles/');
3515
+    return trouver_fond($nom, 'modeles/');
3517 3516
 }
3518 3517
 
3519 3518
 /**
@@ -3529,21 +3528,21 @@  discard block
 block discarded – undo
3529 3528
  * @return array|string
3530 3529
  */
3531 3530
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3532
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3533
-	if (!$pathinfo) {
3534
-		return $f;
3535
-	}
3536
-	// renvoyer un tableau detaille si $pathinfo==true
3537
-	$p = pathinfo($f);
3538
-	if (!isset($p['extension']) or !$p['extension']) {
3539
-		$p['extension'] = _EXTENSION_SQUELETTES;
3540
-	}
3541
-	if (!isset($p['extension']) or !$p['filename']) {
3542
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3543
-	}
3544
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3531
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3532
+    if (!$pathinfo) {
3533
+        return $f;
3534
+    }
3535
+    // renvoyer un tableau detaille si $pathinfo==true
3536
+    $p = pathinfo($f);
3537
+    if (!isset($p['extension']) or !$p['extension']) {
3538
+        $p['extension'] = _EXTENSION_SQUELETTES;
3539
+    }
3540
+    if (!isset($p['extension']) or !$p['filename']) {
3541
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3542
+    }
3543
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3545 3544
 
3546
-	return $p;
3545
+    return $p;
3547 3546
 }
3548 3547
 
3549 3548
 /**
@@ -3563,21 +3562,21 @@  discard block
 block discarded – undo
3563 3562
  *     Nom de l'exec, sinon chaîne vide.
3564 3563
  **/
3565 3564
 function tester_url_ecrire($nom) {
3566
-	static $exec = [];
3567
-	if (isset($exec[$nom])) {
3568
-		return $exec[$nom];
3569
-	}
3570
-	// tester si c'est une page en squelette
3571
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3572
-		return $exec[$nom] = 'fond';
3573
-	} // echafaudage d'un fond !
3574
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3575
-		return $exec[$nom] = 'fond';
3576
-	}
3577
-	// attention, il ne faut pas inclure l'exec ici
3578
-	// car sinon #URL_ECRIRE provoque des inclusions
3579
-	// et des define intrusifs potentiels
3580
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3565
+    static $exec = [];
3566
+    if (isset($exec[$nom])) {
3567
+        return $exec[$nom];
3568
+    }
3569
+    // tester si c'est une page en squelette
3570
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3571
+        return $exec[$nom] = 'fond';
3572
+    } // echafaudage d'un fond !
3573
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3574
+        return $exec[$nom] = 'fond';
3575
+    }
3576
+    // attention, il ne faut pas inclure l'exec ici
3577
+    // car sinon #URL_ECRIRE provoque des inclusions
3578
+    // et des define intrusifs potentiels
3579
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3581 3580
 }
3582 3581
 
3583 3582
 /**
@@ -3587,8 +3586,8 @@  discard block
 block discarded – undo
3587 3586
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3588 3587
  **/
3589 3588
 function html5_permis() {
3590
-	return (!defined('_VERSION_HTML')
3591
-		or _VERSION_HTML !== 'html4');
3589
+    return (!defined('_VERSION_HTML')
3590
+        or _VERSION_HTML !== 'html4');
3592 3591
 }
3593 3592
 
3594 3593
 /**
@@ -3598,30 +3597,30 @@  discard block
 block discarded – undo
3598 3597
  * @return array
3599 3598
  */
3600 3599
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3601
-	$formats = null;
3602
-	if (!is_null($gd)) {
3603
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3604
-		if (isset($GLOBALS['meta'][$config])) {
3605
-			$formats = $GLOBALS['meta'][$config];
3606
-			$formats = explode(',', $formats);
3607
-			$formats = array_filter($formats);
3608
-			$formats = array_map('trim', $formats);
3609
-		}
3610
-	}
3611
-	if (is_null($formats)) {
3612
-		include_spip('inc/filtres_images_lib_mini');
3613
-		$formats = _image_extensions_acceptees_en_entree();
3614
-	}
3615
-
3616
-	if ($svg_allowed) {
3617
-		if (!in_array('svg', $formats)) {
3618
-			$formats[] = 'svg';
3619
-		}
3620
-	}
3621
-	else {
3622
-		$formats = array_diff($formats, ['svg']);
3623
-	}
3624
-	return $formats;
3600
+    $formats = null;
3601
+    if (!is_null($gd)) {
3602
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3603
+        if (isset($GLOBALS['meta'][$config])) {
3604
+            $formats = $GLOBALS['meta'][$config];
3605
+            $formats = explode(',', $formats);
3606
+            $formats = array_filter($formats);
3607
+            $formats = array_map('trim', $formats);
3608
+        }
3609
+    }
3610
+    if (is_null($formats)) {
3611
+        include_spip('inc/filtres_images_lib_mini');
3612
+        $formats = _image_extensions_acceptees_en_entree();
3613
+    }
3614
+
3615
+    if ($svg_allowed) {
3616
+        if (!in_array('svg', $formats)) {
3617
+            $formats[] = 'svg';
3618
+        }
3619
+    }
3620
+    else {
3621
+        $formats = array_diff($formats, ['svg']);
3622
+    }
3623
+    return $formats;
3625 3624
 }
3626 3625
 
3627 3626
 /**
@@ -3630,20 +3629,20 @@  discard block
 block discarded – undo
3630 3629
  * @return array|bool
3631 3630
  */
3632 3631
 function spip_getimagesize($fichier) {
3633
-	if (!$imagesize = @getimagesize($fichier)) {
3634
-		include_spip('inc/svg');
3635
-		if ($attrs = svg_lire_attributs($fichier)) {
3636
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3637
-			$imagesize = [
3638
-				$width,
3639
-				$height,
3640
-				IMAGETYPE_SVG,
3641
-				"width=\"{$width}\" height=\"{$height}\"",
3642
-				'mime' => 'image/svg+xml'
3643
-			];
3644
-		}
3645
-	}
3646
-	return $imagesize;
3632
+    if (!$imagesize = @getimagesize($fichier)) {
3633
+        include_spip('inc/svg');
3634
+        if ($attrs = svg_lire_attributs($fichier)) {
3635
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3636
+            $imagesize = [
3637
+                $width,
3638
+                $height,
3639
+                IMAGETYPE_SVG,
3640
+                "width=\"{$width}\" height=\"{$height}\"",
3641
+                'mime' => 'image/svg+xml'
3642
+            ];
3643
+        }
3644
+    }
3645
+    return $imagesize;
3647 3646
 }
3648 3647
 
3649 3648
 /**
@@ -3657,19 +3656,19 @@  discard block
 block discarded – undo
3657 3656
  * @param string $statut
3658 3657
  */
3659 3658
 function avertir_auteurs($nom, $message, $statut = '') {
3660
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3661
-	if (
3662
-		!$alertes
3663
-		or !is_array($alertes = unserialize($alertes))
3664
-	) {
3665
-		$alertes = [];
3666
-	}
3659
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3660
+    if (
3661
+        !$alertes
3662
+        or !is_array($alertes = unserialize($alertes))
3663
+    ) {
3664
+        $alertes = [];
3665
+    }
3667 3666
 
3668
-	if (!isset($alertes[$statut])) {
3669
-		$alertes[$statut] = [];
3670
-	}
3671
-	$alertes[$statut][$nom] = $message;
3672
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3667
+    if (!isset($alertes[$statut])) {
3668
+        $alertes[$statut] = [];
3669
+    }
3670
+    $alertes[$statut][$nom] = $message;
3671
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3673 3672
 }
3674 3673
 
3675 3674
 /**
@@ -3683,10 +3682,10 @@  discard block
 block discarded – undo
3683 3682
  * @return string|string[]
3684 3683
  */
3685 3684
 function spip_sanitize_classname($classes) {
3686
-	if (is_array($classes)) {
3687
-		return array_map('spip_sanitize_classname', $classes);
3688
-	}
3689
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3685
+    if (is_array($classes)) {
3686
+        return array_map('spip_sanitize_classname', $classes);
3687
+    }
3688
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3690 3689
 }
3691 3690
 
3692 3691
 
@@ -3711,32 +3710,32 @@  discard block
 block discarded – undo
3711 3710
  *    Avec operateur : bool.
3712 3711
  **/
3713 3712
 function spip_version_compare($v1, $v2, $op = null) {
3714
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3715
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3716
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3717
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3718
-
3719
-	$v1 = explode('.', $v1);
3720
-	$v2 = explode('.', $v2);
3721
-	// $v1 est toujours une version, donc sans etoile
3722
-	while (count($v1) < count($v2)) {
3723
-		$v1[] = '0';
3724
-	}
3725
-
3726
-	// $v2 peut etre une borne, donc accepte l'etoile
3727
-	$etoile = false;
3728
-	foreach ($v1 as $k => $v) {
3729
-		if (!isset($v2[$k])) {
3730
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3731
-		} else {
3732
-			if ($v2[$k] == '*') {
3733
-				$etoile = true;
3734
-				$v2[$k] = $v;
3735
-			}
3736
-		}
3737
-	}
3738
-	$v1 = implode('.', $v1);
3739
-	$v2 = implode('.', $v2);
3740
-
3741
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3713
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3714
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3715
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3716
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3717
+
3718
+    $v1 = explode('.', $v1);
3719
+    $v2 = explode('.', $v2);
3720
+    // $v1 est toujours une version, donc sans etoile
3721
+    while (count($v1) < count($v2)) {
3722
+        $v1[] = '0';
3723
+    }
3724
+
3725
+    // $v2 peut etre une borne, donc accepte l'etoile
3726
+    $etoile = false;
3727
+    foreach ($v1 as $k => $v) {
3728
+        if (!isset($v2[$k])) {
3729
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3730
+        } else {
3731
+            if ($v2[$k] == '*') {
3732
+                $etoile = true;
3733
+                $v2[$k] = $v;
3734
+            }
3735
+        }
3736
+    }
3737
+    $v1 = implode('.', $v1);
3738
+    $v2 = implode('.', $v2);
3739
+
3740
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3742 3741
 }
Please login to merge, or discard this patch.