Completed
Push — master ( 15b76a...0288ab )
by cam
01:36
created
ecrire/inc/utils.php 1 patch
Indentation   +2269 added lines, -2270 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
 /**
@@ -678,22 +677,22 @@  discard block
 block discarded – undo
678 677
  * @uses translitteration()
679 678
  */
680 679
 function ancre_url(string $url, ?string $ancre = ''): string {
681
-	$ancre ??= '';
682
-	// lever l'#ancre
683
-	if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
684
-		$url = $r[1];
685
-	}
686
-	if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
687
-		if (!function_exists('translitteration')) {
688
-			include_spip('inc/charsets');
689
-		}
690
-		$ancre = preg_replace(
691
-			['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
692
-			['', '-'],
693
-			translitteration($ancre)
694
-		);
695
-	}
696
-	return $url . (strlen($ancre) ? '#' . $ancre : '');
680
+    $ancre ??= '';
681
+    // lever l'#ancre
682
+    if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) {
683
+        $url = $r[1];
684
+    }
685
+    if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) {
686
+        if (!function_exists('translitteration')) {
687
+            include_spip('inc/charsets');
688
+        }
689
+        $ancre = preg_replace(
690
+            ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'],
691
+            ['', '-'],
692
+            translitteration($ancre)
693
+        );
694
+    }
695
+    return $url . (strlen($ancre) ? '#' . $ancre : '');
697 696
 }
698 697
 
699 698
 /**
@@ -703,16 +702,16 @@  discard block
 block discarded – undo
703 702
  * @return string
704 703
  */
705 704
 function nettoyer_uri($reset = null) {
706
-	static $done = false;
707
-	static $propre = '';
708
-	if (!is_null($reset)) {
709
-		return $propre = $reset;
710
-	}
711
-	if ($done) {
712
-		return $propre;
713
-	}
714
-	$done = true;
715
-	return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
705
+    static $done = false;
706
+    static $propre = '';
707
+    if (!is_null($reset)) {
708
+        return $propre = $reset;
709
+    }
710
+    if ($done) {
711
+        return $propre;
712
+    }
713
+    $done = true;
714
+    return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']);
716 715
 }
717 716
 
718 717
 /**
@@ -724,16 +723,16 @@  discard block
 block discarded – undo
724 723
  * @return string
725 724
  */
726 725
 function nettoyer_uri_var($request_uri) {
727
-	$uri1 = $request_uri;
728
-	do {
729
-		$uri = $uri1;
730
-		$uri1 = preg_replace(
731
-			',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
732
-			'\1',
733
-			$uri
734
-		);
735
-	} while ($uri <> $uri1);
736
-	return preg_replace(',[?&]$,', '', $uri1);
726
+    $uri1 = $request_uri;
727
+    do {
728
+        $uri = $uri1;
729
+        $uri1 = preg_replace(
730
+            ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i',
731
+            '\1',
732
+            $uri
733
+        );
734
+    } while ($uri <> $uri1);
735
+    return preg_replace(',[?&]$,', '', $uri1);
737 736
 }
738 737
 
739 738
 
@@ -747,48 +746,48 @@  discard block
 block discarded – undo
747 746
  *    URL vers soi-même
748 747
  **/
749 748
 function self($amp = '&amp;', $root = false) {
750
-	$url = nettoyer_uri();
751
-	if (
752
-		!$root
753
-		and (
754
-			// si pas de profondeur on peut tronquer
755
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
756
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
757
-			or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
758
-	) {
759
-		$url = preg_replace(',^[^?]*/,', '', $url);
760
-	}
761
-	// ajouter le cas echeant les variables _POST['id_...']
762
-	foreach ($_POST as $v => $c) {
763
-		if (substr($v, 0, 3) == 'id_') {
764
-			$url = parametre_url($url, $v, $c, '&');
765
-		}
766
-	}
767
-
768
-	// supprimer les variables sans interet
769
-	if (test_espace_prive()) {
770
-		$url = preg_replace(',([?&])('
771
-			. 'lang|show_docs|'
772
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
773
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
774
-		$url = preg_replace(',[&]$,', '\1', $url);
775
-	}
776
-
777
-	// eviter les hacks
778
-	include_spip('inc/filtres_mini');
779
-	$url = spip_htmlspecialchars($url);
780
-
781
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
782
-
783
-	// &amp; ?
784
-	if ($amp != '&amp;') {
785
-		$url = str_replace('&amp;', $amp, $url);
786
-	}
787
-
788
-	// Si ca demarre par ? ou vide, donner './'
789
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
790
-
791
-	return $url;
749
+    $url = nettoyer_uri();
750
+    if (
751
+        !$root
752
+        and (
753
+            // si pas de profondeur on peut tronquer
754
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
755
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
756
+            or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE))
757
+    ) {
758
+        $url = preg_replace(',^[^?]*/,', '', $url);
759
+    }
760
+    // ajouter le cas echeant les variables _POST['id_...']
761
+    foreach ($_POST as $v => $c) {
762
+        if (substr($v, 0, 3) == 'id_') {
763
+            $url = parametre_url($url, $v, $c, '&');
764
+        }
765
+    }
766
+
767
+    // supprimer les variables sans interet
768
+    if (test_espace_prive()) {
769
+        $url = preg_replace(',([?&])('
770
+            . 'lang|show_docs|'
771
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
772
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
773
+        $url = preg_replace(',[&]$,', '\1', $url);
774
+    }
775
+
776
+    // eviter les hacks
777
+    include_spip('inc/filtres_mini');
778
+    $url = spip_htmlspecialchars($url);
779
+
780
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
781
+
782
+    // &amp; ?
783
+    if ($amp != '&amp;') {
784
+        $url = str_replace('&amp;', $amp, $url);
785
+    }
786
+
787
+    // Si ca demarre par ? ou vide, donner './'
788
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
789
+
790
+    return $url;
792 791
 }
793 792
 
794 793
 
@@ -799,7 +798,7 @@  discard block
 block discarded – undo
799 798
  *     true si c'est le cas, false sinon.
800 799
  */
801 800
 function test_espace_prive() {
802
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
801
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
803 802
 }
804 803
 
805 804
 /**
@@ -809,7 +808,7 @@  discard block
 block discarded – undo
809 808
  * @return bool
810 809
  */
811 810
 function test_plugin_actif($plugin) {
812
-	return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
811
+    return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
813 812
 }
814 813
 
815 814
 /**
@@ -840,52 +839,52 @@  discard block
 block discarded – undo
840 839
  *     texte
841 840
  */
842 841
 function _T($texte, $args = [], $options = []) {
843
-	static $traduire = false;
844
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
845
-	if ($options) {
846
-		// support de l'ancien argument $class
847
-		if (is_string($options)) {
848
-			$options = ['class' => $options];
849
-		}
850
-		$o = array_merge($o, $options);
851
-	}
852
-
853
-	if (!$traduire) {
854
-		$traduire = charger_fonction('traduire', 'inc');
855
-		include_spip('inc/lang');
856
-	}
857
-
858
-	// On peut passer explicitement la langue dans le tableau
859
-	// On utilise le même nom de variable que la globale
860
-	if (isset($args['spip_lang'])) {
861
-		$lang = $args['spip_lang'];
862
-		// On l'enleve pour ne pas le passer au remplacement
863
-		unset($args['spip_lang']);
864
-	} // Sinon on prend la langue du contexte
865
-	else {
866
-		$lang = $GLOBALS['spip_lang'];
867
-	}
868
-	$text = $traduire($texte, $lang);
869
-
870
-	if ($text === null || !strlen($text)) {
871
-		if (!$o['force']) {
872
-			return '';
873
-		}
874
-
875
-		$text = $texte;
876
-
877
-		// pour les chaines non traduites, assurer un service minimum
878
-		if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
879
-			$n = strpos($text, ':');
880
-			if ($n !== false) {
881
-				$text = substr($text, $n + 1);
882
-			}
883
-			$text = str_replace('_', ' ', $text);
884
-		}
885
-		$o['class'] = null;
886
-	}
887
-
888
-	return _L($text, $args, $o);
842
+    static $traduire = false;
843
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
844
+    if ($options) {
845
+        // support de l'ancien argument $class
846
+        if (is_string($options)) {
847
+            $options = ['class' => $options];
848
+        }
849
+        $o = array_merge($o, $options);
850
+    }
851
+
852
+    if (!$traduire) {
853
+        $traduire = charger_fonction('traduire', 'inc');
854
+        include_spip('inc/lang');
855
+    }
856
+
857
+    // On peut passer explicitement la langue dans le tableau
858
+    // On utilise le même nom de variable que la globale
859
+    if (isset($args['spip_lang'])) {
860
+        $lang = $args['spip_lang'];
861
+        // On l'enleve pour ne pas le passer au remplacement
862
+        unset($args['spip_lang']);
863
+    } // Sinon on prend la langue du contexte
864
+    else {
865
+        $lang = $GLOBALS['spip_lang'];
866
+    }
867
+    $text = $traduire($texte, $lang);
868
+
869
+    if ($text === null || !strlen($text)) {
870
+        if (!$o['force']) {
871
+            return '';
872
+        }
873
+
874
+        $text = $texte;
875
+
876
+        // pour les chaines non traduites, assurer un service minimum
877
+        if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) {
878
+            $n = strpos($text, ':');
879
+            if ($n !== false) {
880
+                $text = substr($text, $n + 1);
881
+            }
882
+            $text = str_replace('_', ' ', $text);
883
+        }
884
+        $o['class'] = null;
885
+    }
886
+
887
+    return _L($text, $args, $o);
889 888
 }
890 889
 
891 890
 
@@ -912,53 +911,53 @@  discard block
 block discarded – undo
912 911
  *     texte
913 912
  */
914 913
 function _L($text, $args = [], $options = []) {
915
-	$f = $text;
916
-	$defaut_options = [
917
-		'class' => null,
918
-		'sanitize' => true,
919
-	];
920
-	// support de l'ancien argument $class
921
-	if ($options and is_string($options)) {
922
-		$options = ['class' => $options];
923
-	}
924
-	if (is_array($options)) {
925
-		$options += $defaut_options;
926
-	} else {
927
-		$options = $defaut_options;
928
-	}
929
-
930
-	if (is_array($args) and count($args)) {
931
-		if (!function_exists('interdire_scripts')) {
932
-			include_spip('inc/texte');
933
-		}
934
-		if (!function_exists('echapper_html_suspect')) {
935
-			include_spip('inc/texte_mini');
936
-		}
937
-		foreach ($args as $name => $value) {
938
-			if (strpos($text, (string) "@$name@") !== false) {
939
-				if ($options['sanitize']) {
940
-					$value = echapper_html_suspect($value);
941
-					$value = interdire_scripts($value, -1);
942
-				}
943
-				if (!empty($options['class'])) {
944
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
945
-				}
946
-				$text = str_replace("@$name@", $value, $text);
947
-				unset($args[$name]);
948
-			}
949
-		}
950
-		// Si des variables n'ont pas ete inserees, le signaler
951
-		// (chaines de langues pas a jour)
952
-		if ($args) {
953
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
954
-		}
955
-	}
956
-
957
-	if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
958
-		return "<span class='debug-traduction-erreur'>$text</span>";
959
-	} else {
960
-		return $text;
961
-	}
914
+    $f = $text;
915
+    $defaut_options = [
916
+        'class' => null,
917
+        'sanitize' => true,
918
+    ];
919
+    // support de l'ancien argument $class
920
+    if ($options and is_string($options)) {
921
+        $options = ['class' => $options];
922
+    }
923
+    if (is_array($options)) {
924
+        $options += $defaut_options;
925
+    } else {
926
+        $options = $defaut_options;
927
+    }
928
+
929
+    if (is_array($args) and count($args)) {
930
+        if (!function_exists('interdire_scripts')) {
931
+            include_spip('inc/texte');
932
+        }
933
+        if (!function_exists('echapper_html_suspect')) {
934
+            include_spip('inc/texte_mini');
935
+        }
936
+        foreach ($args as $name => $value) {
937
+            if (strpos($text, (string) "@$name@") !== false) {
938
+                if ($options['sanitize']) {
939
+                    $value = echapper_html_suspect($value);
940
+                    $value = interdire_scripts($value, -1);
941
+                }
942
+                if (!empty($options['class'])) {
943
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
944
+                }
945
+                $text = str_replace("@$name@", $value, $text);
946
+                unset($args[$name]);
947
+            }
948
+        }
949
+        // Si des variables n'ont pas ete inserees, le signaler
950
+        // (chaines de langues pas a jour)
951
+        if ($args) {
952
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
953
+        }
954
+    }
955
+
956
+    if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) {
957
+        return "<span class='debug-traduction-erreur'>$text</span>";
958
+    } else {
959
+        return $text;
960
+    }
962 961
 }
963 962
 
964 963
 
@@ -972,13 +971,13 @@  discard block
 block discarded – undo
972 971
  * @return string
973 972
  */
974 973
 function joli_repertoire($rep) {
975
-	$a = substr($rep, 0, 1);
976
-	if ($a <> '.' and $a <> '/') {
977
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
978
-	}
979
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
974
+    $a = substr($rep, 0, 1);
975
+    if ($a <> '.' and $a <> '/') {
976
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
977
+    }
978
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
980 979
 
981
-	return $rep;
980
+    return $rep;
982 981
 }
983 982
 
984 983
 
@@ -1003,54 +1002,54 @@  discard block
 block discarded – undo
1003 1002
  * @return float|int|string|void
1004 1003
  */
1005 1004
 function spip_timer($t = 'rien', $raw = false) {
1006
-	static $time;
1007
-	$a = time();
1008
-	$b = microtime();
1009
-	// microtime peut contenir les microsecondes et le temps
1010
-	$b = explode(' ', $b);
1011
-	if (count($b) == 2) {
1012
-		$a = end($b);
1013
-	} // plus precis !
1014
-	$b = reset($b);
1015
-	if (!isset($time[$t])) {
1016
-		$time[$t] = $a + $b;
1017
-	} else {
1018
-		$p = ($a + $b - $time[$t]) * 1000;
1019
-		unset($time[$t]);
1005
+    static $time;
1006
+    $a = time();
1007
+    $b = microtime();
1008
+    // microtime peut contenir les microsecondes et le temps
1009
+    $b = explode(' ', $b);
1010
+    if (count($b) == 2) {
1011
+        $a = end($b);
1012
+    } // plus precis !
1013
+    $b = reset($b);
1014
+    if (!isset($time[$t])) {
1015
+        $time[$t] = $a + $b;
1016
+    } else {
1017
+        $p = ($a + $b - $time[$t]) * 1000;
1018
+        unset($time[$t]);
1020 1019
 #			echo "'$p'";exit;
1021
-		if ($raw) {
1022
-			return $p;
1023
-		}
1024
-		if ($p < 1000) {
1025
-			$s = '';
1026
-		} else {
1027
-			$s = sprintf('%d ', $x = floor($p / 1000));
1028
-			$p -= ($x * 1000);
1029
-		}
1020
+        if ($raw) {
1021
+            return $p;
1022
+        }
1023
+        if ($p < 1000) {
1024
+            $s = '';
1025
+        } else {
1026
+            $s = sprintf('%d ', $x = floor($p / 1000));
1027
+            $p -= ($x * 1000);
1028
+        }
1030 1029
 
1031
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1032
-	}
1030
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1031
+    }
1033 1032
 }
1034 1033
 
1035 1034
 
1036 1035
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
1037 1036
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1038 1037
 function spip_touch($fichier, $duree = 0, $touch = true) {
1039
-	if ($duree) {
1040
-		clearstatcache();
1041
-		if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1042
-			return false;
1043
-		}
1044
-	}
1045
-	if ($touch !== false) {
1046
-		if (!@touch($fichier)) {
1047
-			spip_unlink($fichier);
1048
-			@touch($fichier);
1049
-		};
1050
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1051
-	}
1038
+    if ($duree) {
1039
+        clearstatcache();
1040
+        if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) {
1041
+            return false;
1042
+        }
1043
+    }
1044
+    if ($touch !== false) {
1045
+        if (!@touch($fichier)) {
1046
+            spip_unlink($fichier);
1047
+            @touch($fichier);
1048
+        };
1049
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1050
+    }
1052 1051
 
1053
-	return true;
1052
+    return true;
1054 1053
 }
1055 1054
 
1056 1055
 
@@ -1061,11 +1060,11 @@  discard block
 block discarded – undo
1061 1060
  * @uses cron()
1062 1061
  **/
1063 1062
 function action_cron() {
1064
-	include_spip('inc/headers');
1065
-	http_response_code(204); // No Content
1066
-	header('Connection: close');
1067
-	define('_DIRECT_CRON_FORCE', true);
1068
-	cron();
1063
+    include_spip('inc/headers');
1064
+    http_response_code(204); // No Content
1065
+    header('Connection: close');
1066
+    define('_DIRECT_CRON_FORCE', true);
1067
+    cron();
1069 1068
 }
1070 1069
 
1071 1070
 /**
@@ -1081,26 +1080,26 @@  discard block
 block discarded – undo
1081 1080
  *     True si la tache a pu être effectuée
1082 1081
  */
1083 1082
 function cron($taches = [], $taches_old = []) {
1084
-	// si pas en mode cron force, laisser tomber.
1085
-	if (!defined('_DIRECT_CRON_FORCE')) {
1086
-		return false;
1087
-	}
1088
-	if (!is_array($taches)) {
1089
-		$taches = $taches_old;
1090
-	} // compat anciens appels
1091
-	// si taches a inserer en base et base inaccessible, laisser tomber
1092
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1093
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1094
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1095
-	if ($taches and count($taches) and !spip_connect()) {
1096
-		return false;
1097
-	}
1098
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1099
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1100
-		return $genie($taches);
1101
-	}
1102
-
1103
-	return false;
1083
+    // si pas en mode cron force, laisser tomber.
1084
+    if (!defined('_DIRECT_CRON_FORCE')) {
1085
+        return false;
1086
+    }
1087
+    if (!is_array($taches)) {
1088
+        $taches = $taches_old;
1089
+    } // compat anciens appels
1090
+    // si taches a inserer en base et base inaccessible, laisser tomber
1091
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1092
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1093
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1094
+    if ($taches and count($taches) and !spip_connect()) {
1095
+        return false;
1096
+    }
1097
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1098
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1099
+        return $genie($taches);
1100
+    }
1101
+
1102
+    return false;
1104 1103
 }
1105 1104
 
1106 1105
 /**
@@ -1132,17 +1131,17 @@  discard block
 block discarded – undo
1132 1131
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1133 1132
  */
1134 1133
 function job_queue_add(
1135
-	$function,
1136
-	$description,
1137
-	$arguments = [],
1138
-	$file = '',
1139
-	$no_duplicate = false,
1140
-	$time = 0,
1141
-	$priority = 0
1134
+    $function,
1135
+    $description,
1136
+    $arguments = [],
1137
+    $file = '',
1138
+    $no_duplicate = false,
1139
+    $time = 0,
1140
+    $priority = 0
1142 1141
 ) {
1143
-	include_spip('inc/queue');
1142
+    include_spip('inc/queue');
1144 1143
 
1145
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1144
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1146 1145
 }
1147 1146
 
1148 1147
 /**
@@ -1153,9 +1152,9 @@  discard block
 block discarded – undo
1153 1152
  * @return bool
1154 1153
  */
1155 1154
 function job_queue_remove($id_job) {
1156
-	include_spip('inc/queue');
1155
+    include_spip('inc/queue');
1157 1156
 
1158
-	return queue_remove_job($id_job);
1157
+    return queue_remove_job($id_job);
1159 1158
 }
1160 1159
 
1161 1160
 /**
@@ -1168,9 +1167,9 @@  discard block
 block discarded – undo
1168 1167
  *     or an array of simple array to link multiples objet in one time
1169 1168
  */
1170 1169
 function job_queue_link($id_job, $objets) {
1171
-	include_spip('inc/queue');
1170
+    include_spip('inc/queue');
1172 1171
 
1173
-	return queue_link_job($id_job, $objets);
1172
+    return queue_link_job($id_job, $objets);
1174 1173
 }
1175 1174
 
1176 1175
 
@@ -1190,36 +1189,36 @@  discard block
 block discarded – undo
1190 1189
  *  - `null` si la queue n'est pas encore initialisée
1191 1190
  */
1192 1191
 function queue_sleep_time_to_next_job($force = null) {
1193
-	static $queue_next_job_time = -1;
1194
-	if ($force === true) {
1195
-		$queue_next_job_time = -1;
1196
-	} elseif ($force) {
1197
-		$queue_next_job_time = $force;
1198
-	}
1199
-
1200
-	if ($queue_next_job_time == -1) {
1201
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1202
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1203
-		}
1204
-		// utiliser un cache memoire si dispo
1205
-		if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1206
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1207
-		} else {
1208
-			$queue_next_job_time = null;
1209
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1210
-				$queue_next_job_time = intval($contenu);
1211
-			}
1212
-		}
1213
-	}
1214
-
1215
-	if (is_null($queue_next_job_time)) {
1216
-		return null;
1217
-	}
1218
-	if (!$_SERVER['REQUEST_TIME']) {
1219
-		$_SERVER['REQUEST_TIME'] = time();
1220
-	}
1221
-
1222
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1192
+    static $queue_next_job_time = -1;
1193
+    if ($force === true) {
1194
+        $queue_next_job_time = -1;
1195
+    } elseif ($force) {
1196
+        $queue_next_job_time = $force;
1197
+    }
1198
+
1199
+    if ($queue_next_job_time == -1) {
1200
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1201
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1202
+        }
1203
+        // utiliser un cache memoire si dispo
1204
+        if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) {
1205
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1206
+        } else {
1207
+            $queue_next_job_time = null;
1208
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1209
+                $queue_next_job_time = intval($contenu);
1210
+            }
1211
+        }
1212
+    }
1213
+
1214
+    if (is_null($queue_next_job_time)) {
1215
+        return null;
1216
+    }
1217
+    if (!$_SERVER['REQUEST_TIME']) {
1218
+        $_SERVER['REQUEST_TIME'] = time();
1219
+    }
1220
+
1221
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1223 1222
 }
1224 1223
 
1225 1224
 
@@ -1231,11 +1230,11 @@  discard block
 block discarded – undo
1231 1230
  * @return string
1232 1231
  */
1233 1232
 function quote_amp($u) {
1234
-	return preg_replace(
1235
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1236
-		'&amp;',
1237
-		$u
1238
-	);
1233
+    return preg_replace(
1234
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1235
+        '&amp;',
1236
+        $u
1237
+    );
1239 1238
 }
1240 1239
 
1241 1240
 
@@ -1258,27 +1257,27 @@  discard block
 block discarded – undo
1258 1257
  *     Balise HTML `<script>` et son contenu
1259 1258
  **/
1260 1259
 function http_script($script, $src = '', $noscript = '') {
1261
-	static $done = [];
1260
+    static $done = [];
1262 1261
 
1263
-	if ($src && !isset($done[$src])) {
1264
-		$done[$src] = true;
1265
-		$src = find_in_path($src, _JAVASCRIPT);
1266
-		$src = " src='$src'";
1267
-	} else {
1268
-		$src = '';
1269
-	}
1270
-	if ($script) {
1271
-		$script = ("/*<![CDATA[*/\n" .
1272
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1273
-			'/*]]>*/');
1274
-	}
1275
-	if ($noscript) {
1276
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1277
-	}
1262
+    if ($src && !isset($done[$src])) {
1263
+        $done[$src] = true;
1264
+        $src = find_in_path($src, _JAVASCRIPT);
1265
+        $src = " src='$src'";
1266
+    } else {
1267
+        $src = '';
1268
+    }
1269
+    if ($script) {
1270
+        $script = ("/*<![CDATA[*/\n" .
1271
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1272
+            '/*]]>*/');
1273
+    }
1274
+    if ($noscript) {
1275
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1276
+    }
1278 1277
 
1279
-	return ($src or $script or $noscript)
1280
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1281
-		: '';
1278
+    return ($src or $script or $noscript)
1279
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1280
+        : '';
1282 1281
 }
1283 1282
 
1284 1283
 
@@ -1313,7 +1312,7 @@  discard block
 block discarded – undo
1313 1312
  *     texte échappé
1314 1313
  **/
1315 1314
 function texte_script(string $texte): string {
1316
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1315
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1317 1316
 }
1318 1317
 
1319 1318
 
@@ -1350,68 +1349,68 @@  discard block
 block discarded – undo
1350 1349
  *     Liste des chemins, par ordre de priorité.
1351 1350
  **/
1352 1351
 function _chemin($dir_path = null) {
1353
-	static $path_base = null;
1354
-	static $path_full = null;
1355
-	if ($path_base == null) {
1356
-		// Chemin standard depuis l'espace public
1357
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1358
-			_DIR_RACINE . ':' .
1359
-			_DIR_RACINE . 'squelettes-dist/:' .
1360
-			_DIR_RACINE . 'prive/:' .
1361
-			_DIR_RESTREINT;
1362
-		// Ajouter squelettes/
1363
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1364
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1365
-		}
1366
-		foreach (explode(':', $path) as $dir) {
1367
-			if (strlen($dir) and substr($dir, -1) != '/') {
1368
-				$dir .= '/';
1369
-			}
1370
-			$path_base[] = $dir;
1371
-		}
1372
-		$path_full = $path_base;
1373
-		// Et le(s) dossier(s) des squelettes nommes
1374
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1375
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1376
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1377
-			}
1378
-		}
1379
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1380
-	}
1381
-	if ($dir_path === null) {
1382
-		return $path_full;
1383
-	}
1384
-
1385
-	if (is_array($dir_path) or strlen($dir_path)) {
1386
-		$tete = '';
1387
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1388
-			$tete = array_shift($path_base);
1389
-		}
1390
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1391
-		$dirs = array_reverse($dirs);
1392
-		foreach ($dirs as $dir_path) {
1393
-			if (substr($dir_path, -1) != '/') {
1394
-				$dir_path .= '/';
1395
-			}
1396
-			if (!in_array($dir_path, $path_base)) {
1397
-				array_unshift($path_base, $dir_path);
1398
-			}
1399
-		}
1400
-		if (strlen($tete)) {
1401
-			array_unshift($path_base, $tete);
1402
-		}
1403
-	}
1404
-	$path_full = $path_base;
1405
-	// Et le(s) dossier(s) des squelettes nommes
1406
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1407
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1408
-			array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1409
-		}
1410
-	}
1411
-
1412
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1413
-
1414
-	return $path_full;
1352
+    static $path_base = null;
1353
+    static $path_full = null;
1354
+    if ($path_base == null) {
1355
+        // Chemin standard depuis l'espace public
1356
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1357
+            _DIR_RACINE . ':' .
1358
+            _DIR_RACINE . 'squelettes-dist/:' .
1359
+            _DIR_RACINE . 'prive/:' .
1360
+            _DIR_RESTREINT;
1361
+        // Ajouter squelettes/
1362
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1363
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1364
+        }
1365
+        foreach (explode(':', $path) as $dir) {
1366
+            if (strlen($dir) and substr($dir, -1) != '/') {
1367
+                $dir .= '/';
1368
+            }
1369
+            $path_base[] = $dir;
1370
+        }
1371
+        $path_full = $path_base;
1372
+        // Et le(s) dossier(s) des squelettes nommes
1373
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1374
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1375
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1376
+            }
1377
+        }
1378
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1379
+    }
1380
+    if ($dir_path === null) {
1381
+        return $path_full;
1382
+    }
1383
+
1384
+    if (is_array($dir_path) or strlen($dir_path)) {
1385
+        $tete = '';
1386
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1387
+            $tete = array_shift($path_base);
1388
+        }
1389
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1390
+        $dirs = array_reverse($dirs);
1391
+        foreach ($dirs as $dir_path) {
1392
+            if (substr($dir_path, -1) != '/') {
1393
+                $dir_path .= '/';
1394
+            }
1395
+            if (!in_array($dir_path, $path_base)) {
1396
+                array_unshift($path_base, $dir_path);
1397
+            }
1398
+        }
1399
+        if (strlen($tete)) {
1400
+            array_unshift($path_base, $tete);
1401
+        }
1402
+    }
1403
+    $path_full = $path_base;
1404
+    // Et le(s) dossier(s) des squelettes nommes
1405
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1406
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1407
+            array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1408
+        }
1409
+    }
1410
+
1411
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1412
+
1413
+    return $path_full;
1415 1414
 }
1416 1415
 
1417 1416
 /**
@@ -1424,17 +1423,17 @@  discard block
 block discarded – undo
1424 1423
  * @return array Liste de chemins
1425 1424
  **/
1426 1425
 function creer_chemin() {
1427
-	$path_a = _chemin();
1428
-	static $c = '';
1426
+    $path_a = _chemin();
1427
+    static $c = '';
1429 1428
 
1430
-	// on calcule le chemin si le dossier skel a change
1431
-	if ($c != $GLOBALS['dossier_squelettes']) {
1432
-		// assurer le non plantage lors de la montee de version :
1433
-		$c = $GLOBALS['dossier_squelettes'];
1434
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1435
-	}
1429
+    // on calcule le chemin si le dossier skel a change
1430
+    if ($c != $GLOBALS['dossier_squelettes']) {
1431
+        // assurer le non plantage lors de la montee de version :
1432
+        $c = $GLOBALS['dossier_squelettes'];
1433
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1434
+    }
1436 1435
 
1437
-	return $path_a;
1436
+    return $path_a;
1438 1437
 }
1439 1438
 
1440 1439
 
@@ -1446,61 +1445,61 @@  discard block
 block discarded – undo
1446 1445
  * @return string[] Nom des thèmes.
1447 1446
  */
1448 1447
 function lister_themes_prives(): array {
1449
-	static $themes = null;
1450
-	if (is_null($themes)) {
1451
-		// si pas encore definie
1452
-		if (!defined('_SPIP_THEME_PRIVE')) {
1453
-			define('_SPIP_THEME_PRIVE', 'spip');
1454
-		}
1455
-		$themes = [_SPIP_THEME_PRIVE];
1456
-		// Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé
1457
-		// FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp;
1458
-		$prefs = $GLOBALS['visiteur_session']['prefs'] ?? [];
1459
-		if (is_string($prefs) and (stripos($prefs, 'a:') === 0)) {
1460
-			$prefs = unserialize($prefs);
1461
-		} else {
1462
-			$prefs = [];
1463
-		}
1464
-
1465
-		$theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null;
1466
-		if ($theme and $theme !== _SPIP_THEME_PRIVE) {
1467
-			// placer le theme choisi en tete
1468
-			array_unshift($themes, $theme);
1469
-		}
1470
-	}
1471
-
1472
-	return $themes;
1448
+    static $themes = null;
1449
+    if (is_null($themes)) {
1450
+        // si pas encore definie
1451
+        if (!defined('_SPIP_THEME_PRIVE')) {
1452
+            define('_SPIP_THEME_PRIVE', 'spip');
1453
+        }
1454
+        $themes = [_SPIP_THEME_PRIVE];
1455
+        // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé
1456
+        // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp;
1457
+        $prefs = $GLOBALS['visiteur_session']['prefs'] ?? [];
1458
+        if (is_string($prefs) and (stripos($prefs, 'a:') === 0)) {
1459
+            $prefs = unserialize($prefs);
1460
+        } else {
1461
+            $prefs = [];
1462
+        }
1463
+
1464
+        $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null;
1465
+        if ($theme and $theme !== _SPIP_THEME_PRIVE) {
1466
+            // placer le theme choisi en tete
1467
+            array_unshift($themes, $theme);
1468
+        }
1469
+    }
1470
+
1471
+    return $themes;
1473 1472
 }
1474 1473
 
1475 1474
 function find_in_theme($file, $subdir = '', $include = false) {
1476
-	static $themefiles = [];
1477
-	if (isset($themefiles["$subdir$file"])) {
1478
-		return $themefiles["$subdir$file"];
1479
-	}
1480
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1481
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1482
-	if (
1483
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1484
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1485
-		and $f = find_in_theme("$file_svg_generique")
1486
-	) {
1487
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1488
-			return $themefiles["$subdir$file"] = $fsize;
1489
-		}
1490
-		else {
1491
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1492
-		}
1493
-	}
1494
-
1495
-	$themes = lister_themes_prives();
1496
-	foreach ($themes as $theme) {
1497
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1498
-			return $themefiles["$subdir$file"] = $f;
1499
-		}
1500
-	}
1501
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1502
-
1503
-	return $themefiles["$subdir$file"] = '';
1475
+    static $themefiles = [];
1476
+    if (isset($themefiles["$subdir$file"])) {
1477
+        return $themefiles["$subdir$file"];
1478
+    }
1479
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1480
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1481
+    if (
1482
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1483
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1484
+        and $f = find_in_theme("$file_svg_generique")
1485
+    ) {
1486
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1487
+            return $themefiles["$subdir$file"] = $fsize;
1488
+        }
1489
+        else {
1490
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1491
+        }
1492
+    }
1493
+
1494
+    $themes = lister_themes_prives();
1495
+    foreach ($themes as $theme) {
1496
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1497
+            return $themefiles["$subdir$file"] = $f;
1498
+        }
1499
+    }
1500
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1501
+
1502
+    return $themefiles["$subdir$file"] = '';
1504 1503
 }
1505 1504
 
1506 1505
 
@@ -1524,31 +1523,31 @@  discard block
 block discarded – undo
1524 1523
  *     sinon chaîne vide.
1525 1524
  **/
1526 1525
 function chemin_image($icone) {
1527
-	static $icone_renommer;
1528
-	if ($p = strpos($icone, '?')) {
1529
-		$icone = substr($icone, 0, $p);
1530
-	}
1531
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1532
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1533
-		return $icone;
1534
-	}
1535
-
1536
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1537
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1538
-		return $f;
1539
-	}
1540
-	// sinon passer par le module de renommage
1541
-	if (is_null($icone_renommer)) {
1542
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1543
-	}
1544
-	if ($icone_renommer) {
1545
-		[$icone, $fonction] = $icone_renommer($icone, '');
1546
-		if (file_exists($icone)) {
1547
-			return $icone;
1548
-		}
1549
-	}
1550
-
1551
-	return find_in_path($icone, _NOM_IMG_PACK);
1526
+    static $icone_renommer;
1527
+    if ($p = strpos($icone, '?')) {
1528
+        $icone = substr($icone, 0, $p);
1529
+    }
1530
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1531
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1532
+        return $icone;
1533
+    }
1534
+
1535
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1536
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1537
+        return $f;
1538
+    }
1539
+    // sinon passer par le module de renommage
1540
+    if (is_null($icone_renommer)) {
1541
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1542
+    }
1543
+    if ($icone_renommer) {
1544
+        [$icone, $fonction] = $icone_renommer($icone, '');
1545
+        if (file_exists($icone)) {
1546
+            return $icone;
1547
+        }
1548
+    }
1549
+
1550
+    return find_in_path($icone, _NOM_IMG_PACK);
1552 1551
 }
1553 1552
 
1554 1553
 //
@@ -1586,128 +1585,128 @@  discard block
 block discarded – undo
1586 1585
  *     - false : fichier introuvable
1587 1586
  **/
1588 1587
 function find_in_path($file, $dirname = '', $include = false) {
1589
-	static $dirs = [];
1590
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1591
-	static $c = '';
1592
-
1593
-	if (!$file and !strlen($file)) {
1594
-		return false;
1595
-	}
1596
-
1597
-	// on calcule le chemin si le dossier skel a change
1598
-	if ($c != $GLOBALS['dossier_squelettes']) {
1599
-		// assurer le non plantage lors de la montee de version :
1600
-		$c = $GLOBALS['dossier_squelettes'];
1601
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1602
-	}
1603
-
1604
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1605
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1606
-			return false;
1607
-		}
1608
-		if ($include and !isset($inc[$dirname][$file])) {
1609
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1610
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1611
-		}
1612
-
1613
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1614
-	}
1615
-
1616
-	$a = strrpos($file, '/');
1617
-	if ($a !== false) {
1618
-		$dirname .= substr($file, 0, ++$a);
1619
-		$file = substr($file, $a);
1620
-	}
1621
-
1622
-	foreach (creer_chemin() as $dir) {
1623
-		if (!isset($dirs[$a = $dir . $dirname])) {
1624
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1625
-		}
1626
-		if ($dirs[$a]) {
1627
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1628
-				if ($include and !isset($inc[$dirname][$file])) {
1629
-					include_once _ROOT_CWD . $a;
1630
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1631
-				}
1632
-				if (!defined('_SAUVER_CHEMIN')) {
1633
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1634
-					if (is_null($GLOBALS['path_files'])) {
1635
-						return $a;
1636
-					}
1637
-					define('_SAUVER_CHEMIN', true);
1638
-				}
1639
-
1640
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1641
-			}
1642
-		}
1643
-	}
1644
-
1645
-	if ($include) {
1646
-		spip_log("include_spip $dirname$file non trouve");
1647
-		if ($include === 'required') {
1648
-			echo '<pre>',
1649
-			'<strong>Erreur Fatale</strong><br />';
1650
-			if (function_exists('debug_print_backtrace')) {
1651
-				debug_print_backtrace();
1652
-			}
1653
-			echo '</pre>';
1654
-			die("Erreur interne: ne peut inclure $dirname$file");
1655
-		}
1656
-	}
1657
-
1658
-	if (!defined('_SAUVER_CHEMIN')) {
1659
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1660
-		if (is_null($GLOBALS['path_files'])) {
1661
-			return false;
1662
-		}
1663
-		define('_SAUVER_CHEMIN', true);
1664
-	}
1665
-
1666
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1588
+    static $dirs = [];
1589
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1590
+    static $c = '';
1591
+
1592
+    if (!$file and !strlen($file)) {
1593
+        return false;
1594
+    }
1595
+
1596
+    // on calcule le chemin si le dossier skel a change
1597
+    if ($c != $GLOBALS['dossier_squelettes']) {
1598
+        // assurer le non plantage lors de la montee de version :
1599
+        $c = $GLOBALS['dossier_squelettes'];
1600
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1601
+    }
1602
+
1603
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1604
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1605
+            return false;
1606
+        }
1607
+        if ($include and !isset($inc[$dirname][$file])) {
1608
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1609
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1610
+        }
1611
+
1612
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1613
+    }
1614
+
1615
+    $a = strrpos($file, '/');
1616
+    if ($a !== false) {
1617
+        $dirname .= substr($file, 0, ++$a);
1618
+        $file = substr($file, $a);
1619
+    }
1620
+
1621
+    foreach (creer_chemin() as $dir) {
1622
+        if (!isset($dirs[$a = $dir . $dirname])) {
1623
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1624
+        }
1625
+        if ($dirs[$a]) {
1626
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1627
+                if ($include and !isset($inc[$dirname][$file])) {
1628
+                    include_once _ROOT_CWD . $a;
1629
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1630
+                }
1631
+                if (!defined('_SAUVER_CHEMIN')) {
1632
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1633
+                    if (is_null($GLOBALS['path_files'])) {
1634
+                        return $a;
1635
+                    }
1636
+                    define('_SAUVER_CHEMIN', true);
1637
+                }
1638
+
1639
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1640
+            }
1641
+        }
1642
+    }
1643
+
1644
+    if ($include) {
1645
+        spip_log("include_spip $dirname$file non trouve");
1646
+        if ($include === 'required') {
1647
+            echo '<pre>',
1648
+            '<strong>Erreur Fatale</strong><br />';
1649
+            if (function_exists('debug_print_backtrace')) {
1650
+                debug_print_backtrace();
1651
+            }
1652
+            echo '</pre>';
1653
+            die("Erreur interne: ne peut inclure $dirname$file");
1654
+        }
1655
+    }
1656
+
1657
+    if (!defined('_SAUVER_CHEMIN')) {
1658
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1659
+        if (is_null($GLOBALS['path_files'])) {
1660
+            return false;
1661
+        }
1662
+        define('_SAUVER_CHEMIN', true);
1663
+    }
1664
+
1665
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1667 1666
 }
1668 1667
 
1669 1668
 function clear_path_cache() {
1670
-	$GLOBALS['path_files'] = [];
1671
-	spip_unlink(_CACHE_CHEMIN);
1669
+    $GLOBALS['path_files'] = [];
1670
+    spip_unlink(_CACHE_CHEMIN);
1672 1671
 }
1673 1672
 
1674 1673
 function load_path_cache() {
1675
-	// charger le path des plugins
1676
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1677
-		include_once(_CACHE_PLUGINS_PATH);
1678
-	}
1679
-	$GLOBALS['path_files'] = [];
1680
-	// si le visiteur est admin,
1681
-	// on ne recharge pas le cache pour forcer sa mise a jour
1682
-	if (
1683
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1684
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1685
-		// utiliser le cookie est un pis aller qui marche 'en general'
1686
-		// on blinde par un second test au moment de la lecture de la session
1687
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1688
-		// et en ignorant ce cache en cas de recalcul explicite
1689
-		!_request('var_mode')
1690
-	) {
1691
-		// on essaye de lire directement sans verrou pour aller plus vite
1692
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1693
-			// mais si semble corrompu on relit avec un verrou
1694
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1695
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1696
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1697
-					$GLOBALS['path_files'] = [];
1698
-				}
1699
-			}
1700
-		}
1701
-	}
1674
+    // charger le path des plugins
1675
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1676
+        include_once(_CACHE_PLUGINS_PATH);
1677
+    }
1678
+    $GLOBALS['path_files'] = [];
1679
+    // si le visiteur est admin,
1680
+    // on ne recharge pas le cache pour forcer sa mise a jour
1681
+    if (
1682
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1683
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1684
+        // utiliser le cookie est un pis aller qui marche 'en general'
1685
+        // on blinde par un second test au moment de la lecture de la session
1686
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1687
+        // et en ignorant ce cache en cas de recalcul explicite
1688
+        !_request('var_mode')
1689
+    ) {
1690
+        // on essaye de lire directement sans verrou pour aller plus vite
1691
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1692
+            // mais si semble corrompu on relit avec un verrou
1693
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1694
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1695
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1696
+                    $GLOBALS['path_files'] = [];
1697
+                }
1698
+            }
1699
+        }
1700
+    }
1702 1701
 }
1703 1702
 
1704 1703
 function save_path_cache() {
1705
-	if (
1706
-		defined('_SAUVER_CHEMIN')
1707
-		and _SAUVER_CHEMIN
1708
-	) {
1709
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1710
-	}
1704
+    if (
1705
+        defined('_SAUVER_CHEMIN')
1706
+        and _SAUVER_CHEMIN
1707
+    ) {
1708
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1709
+    }
1711 1710
 }
1712 1711
 
1713 1712
 
@@ -1727,33 +1726,33 @@  discard block
 block discarded – undo
1727 1726
  * @return array
1728 1727
  */
1729 1728
 function find_all_in_path($dir, $pattern, $recurs = false) {
1730
-	$liste_fichiers = [];
1731
-	$maxfiles = 10000;
1732
-
1733
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1734
-	// on a pas encore inclus flock.php
1735
-	if (!function_exists('preg_files')) {
1736
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1737
-	}
1738
-
1739
-	// Parcourir le chemin
1740
-	foreach (creer_chemin() as $d) {
1741
-		$f = $d . $dir;
1742
-		if (@is_dir($f)) {
1743
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1744
-			foreach ($liste as $chemin) {
1745
-				$nom = basename($chemin);
1746
-				// ne prendre que les fichiers pas deja trouves
1747
-				// car find_in_path prend le premier qu'il trouve,
1748
-				// les autres sont donc masques
1749
-				if (!isset($liste_fichiers[$nom])) {
1750
-					$liste_fichiers[$nom] = $chemin;
1751
-				}
1752
-			}
1753
-		}
1754
-	}
1755
-
1756
-	return $liste_fichiers;
1729
+    $liste_fichiers = [];
1730
+    $maxfiles = 10000;
1731
+
1732
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1733
+    // on a pas encore inclus flock.php
1734
+    if (!function_exists('preg_files')) {
1735
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1736
+    }
1737
+
1738
+    // Parcourir le chemin
1739
+    foreach (creer_chemin() as $d) {
1740
+        $f = $d . $dir;
1741
+        if (@is_dir($f)) {
1742
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1743
+            foreach ($liste as $chemin) {
1744
+                $nom = basename($chemin);
1745
+                // ne prendre que les fichiers pas deja trouves
1746
+                // car find_in_path prend le premier qu'il trouve,
1747
+                // les autres sont donc masques
1748
+                if (!isset($liste_fichiers[$nom])) {
1749
+                    $liste_fichiers[$nom] = $chemin;
1750
+                }
1751
+            }
1752
+        }
1753
+    }
1754
+
1755
+    return $liste_fichiers;
1757 1756
 }
1758 1757
 
1759 1758
 /**
@@ -1765,17 +1764,17 @@  discard block
 block discarded – undo
1765 1764
  * @return bool
1766 1765
  */
1767 1766
 function autoriser_sans_cookie($nom, $strict = false) {
1768
-	static $autsanscookie = ['install', 'base_repair'];
1767
+    static $autsanscookie = ['install', 'base_repair'];
1769 1768
 
1770
-	if (in_array($nom, $autsanscookie)) {
1771
-		if (test_espace_prive()) {
1772
-			include_spip('base/connect_sql');
1773
-			if (!$strict or !spip_connect()) {
1774
-				return true;
1775
-			}
1776
-		}
1777
-	}
1778
-	return false;
1769
+    if (in_array($nom, $autsanscookie)) {
1770
+        if (test_espace_prive()) {
1771
+            include_spip('base/connect_sql');
1772
+            if (!$strict or !spip_connect()) {
1773
+                return true;
1774
+            }
1775
+        }
1776
+    }
1777
+    return false;
1779 1778
 }
1780 1779
 
1781 1780
 /**
@@ -1785,60 +1784,60 @@  discard block
 block discarded – undo
1785 1784
  * @return string
1786 1785
  */
1787 1786
 function charger_fonction_url(string $quoi, string $type = '') {
1788
-	if ($type === 'defaut') {
1789
-		$objet = objet_type($quoi);
1790
-		if (
1791
-			$f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1792
-			// deprecated
1793
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1794
-		) {
1795
-			return $f;
1796
-		}
1797
-		return '';
1798
-	}
1799
-
1800
-	$url_type = $type;
1801
-	if (!$url_type) {
1802
-		$url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1803
-	}
1804
-
1805
-	// inclure le module d'url
1806
-	include_spip('urls/' . $url_type);
1807
-
1808
-	switch ($quoi) {
1809
-		case 'page':
1810
-			if (
1811
-				 function_exists($f = "urls_{$url_type}_generer_url_page")
1812
-				or function_exists($f .= '_dist')
1813
-				// ou une fonction custom utilisateur independante du type d'url
1814
-				or function_exists($f = 'generer_url_page')
1815
-				or function_exists($f .= '_dist')
1816
-			) {
1817
-				return $f;
1818
-			}
1819
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1820
-			return '';
1821
-		case 'objet':
1822
-		case 'decoder':
1823
-		default:
1824
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1825
-			if (
1826
-				function_exists($f = "urls_{$url_type}_{$fquoi}")
1827
-				or function_exists($f .= '_dist')
1828
-			) {
1829
-				return $f;
1830
-			}
1831
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1832
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1833
-			if ($f = charger_fonction($url_type, 'urls', true)) {
1834
-				return $f;
1835
-			}
1836
-			// sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1837
-			if (!$type and $url_type !== 'page') {
1838
-				return charger_fonction_url($quoi, 'page');
1839
-			}
1840
-			return '';
1841
-	}
1787
+    if ($type === 'defaut') {
1788
+        $objet = objet_type($quoi);
1789
+        if (
1790
+            $f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1791
+            // deprecated
1792
+            or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1793
+        ) {
1794
+            return $f;
1795
+        }
1796
+        return '';
1797
+    }
1798
+
1799
+    $url_type = $type;
1800
+    if (!$url_type) {
1801
+        $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1802
+    }
1803
+
1804
+    // inclure le module d'url
1805
+    include_spip('urls/' . $url_type);
1806
+
1807
+    switch ($quoi) {
1808
+        case 'page':
1809
+            if (
1810
+                    function_exists($f = "urls_{$url_type}_generer_url_page")
1811
+                or function_exists($f .= '_dist')
1812
+                // ou une fonction custom utilisateur independante du type d'url
1813
+                or function_exists($f = 'generer_url_page')
1814
+                or function_exists($f .= '_dist')
1815
+            ) {
1816
+                return $f;
1817
+            }
1818
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1819
+            return '';
1820
+        case 'objet':
1821
+        case 'decoder':
1822
+        default:
1823
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1824
+            if (
1825
+                function_exists($f = "urls_{$url_type}_{$fquoi}")
1826
+                or function_exists($f .= '_dist')
1827
+            ) {
1828
+                return $f;
1829
+            }
1830
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1831
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1832
+            if ($f = charger_fonction($url_type, 'urls', true)) {
1833
+                return $f;
1834
+            }
1835
+            // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1836
+            if (!$type and $url_type !== 'page') {
1837
+                return charger_fonction_url($quoi, 'page');
1838
+            }
1839
+            return '';
1840
+    }
1842 1841
 }
1843 1842
 
1844 1843
 
@@ -1864,48 +1863,48 @@  discard block
 block discarded – undo
1864 1863
  *   url codee ou fonction de decodage
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,315 +2496,315 @@  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
-	// répertoire des libs via Composer
2523
-	if (!defined('_DIR_VENDOR')) {
2524
-		define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2525
-	}
2526
-
2527
-	if (!defined('_DIR_IMG')) {
2528
-		define('_DIR_IMG', $pa);
2529
-	}
2530
-	if (!defined('_DIR_LOGOS')) {
2531
-		define('_DIR_LOGOS', $pa);
2532
-	}
2533
-	if (!defined('_DIR_IMG_ICONES')) {
2534
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2535
-	}
2536
-
2537
-	if (!defined('_DIR_DUMP')) {
2538
-		define('_DIR_DUMP', $ti . 'dump/');
2539
-	}
2540
-	if (!defined('_DIR_SESSIONS')) {
2541
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2542
-	}
2543
-	if (!defined('_DIR_TRANSFERT')) {
2544
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2545
-	}
2546
-	if (!defined('_DIR_CACHE')) {
2547
-		define('_DIR_CACHE', $ti . 'cache/');
2548
-	}
2549
-	if (!defined('_DIR_CACHE_XML')) {
2550
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2551
-	}
2552
-	if (!defined('_DIR_SKELS')) {
2553
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2554
-	}
2555
-	if (!defined('_DIR_AIDE')) {
2556
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2557
-	}
2558
-	if (!defined('_DIR_TMP')) {
2559
-		define('_DIR_TMP', $ti);
2560
-	}
2561
-
2562
-	if (!defined('_DIR_VAR')) {
2563
-		define('_DIR_VAR', $ta);
2564
-	}
2565
-
2566
-	if (!defined('_DIR_ETC')) {
2567
-		define('_DIR_ETC', $pi);
2568
-	}
2569
-	if (!defined('_DIR_CONNECT')) {
2570
-		define('_DIR_CONNECT', $pi);
2571
-	}
2572
-	if (!defined('_DIR_CHMOD')) {
2573
-		define('_DIR_CHMOD', $pi);
2574
-	}
2575
-
2576
-	if (!isset($GLOBALS['test_dirs'])) {
2577
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2578
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2579
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2580
-	}
2581
-
2582
-	// Declaration des fichiers
2583
-
2584
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2585
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2586
-	}
2587
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2588
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2589
-	}
2590
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2591
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2592
-	}
2593
-	if (!defined('_CACHE_PIPELINES')) {
2594
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2595
-	}
2596
-	if (!defined('_CACHE_CHEMIN')) {
2597
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2598
-	}
2599
-
2600
-	# attention .php obligatoire pour ecrire_fichier_securise
2601
-	if (!defined('_FILE_META')) {
2602
-		define('_FILE_META', $ti . 'meta_cache.php');
2603
-	}
2604
-	if (!defined('_DIR_LOG')) {
2605
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2606
-	}
2607
-	if (!defined('_FILE_LOG')) {
2608
-		define('_FILE_LOG', 'spip');
2609
-	}
2610
-	if (!defined('_FILE_LOG_SUFFIX')) {
2611
-		define('_FILE_LOG_SUFFIX', '.log');
2612
-	}
2613
-
2614
-	// Le fichier de connexion a la base de donnees
2615
-	// tient compte des anciennes versions (inc_connect...)
2616
-	if (!defined('_FILE_CONNECT_INS')) {
2617
-		define('_FILE_CONNECT_INS', 'connect');
2618
-	}
2619
-	if (!defined('_FILE_CONNECT')) {
2620
-		define(
2621
-			'_FILE_CONNECT',
2622
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2623
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2624
-			: false))
2625
-		);
2626
-	}
2627
-
2628
-	// Le fichier de reglages des droits
2629
-	if (!defined('_FILE_CHMOD_INS')) {
2630
-		define('_FILE_CHMOD_INS', 'chmod');
2631
-	}
2632
-	if (!defined('_FILE_CHMOD')) {
2633
-		define(
2634
-			'_FILE_CHMOD',
2635
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2636
-			: false)
2637
-		);
2638
-	}
2639
-
2640
-	if (!defined('_FILE_LDAP')) {
2641
-		define('_FILE_LDAP', 'ldap.php');
2642
-	}
2643
-
2644
-	if (!defined('_FILE_TMP_SUFFIX')) {
2645
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2646
-	}
2647
-	if (!defined('_FILE_CONNECT_TMP')) {
2648
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2649
-	}
2650
-	if (!defined('_FILE_CHMOD_TMP')) {
2651
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2652
-	}
2653
-
2654
-	// Definition des droits d'acces en ecriture
2655
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2656
-		include_once _FILE_CHMOD;
2657
-	}
2658
-
2659
-	// Se mefier des fichiers mal remplis!
2660
-	if (!defined('_SPIP_CHMOD')) {
2661
-		define('_SPIP_CHMOD', 0777);
2662
-	}
2663
-
2664
-	if (!defined('_DEFAULT_CHARSET')) {
2665
-		/** Le charset par défaut lors de l'installation */
2666
-		define('_DEFAULT_CHARSET', 'utf-8');
2667
-	}
2668
-	if (!defined('_ROOT_PLUGINS')) {
2669
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2670
-	}
2671
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2672
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2673
-	}
2674
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2675
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2676
-	}
2677
-
2678
-	// La taille des Log
2679
-	if (!defined('_MAX_LOG')) {
2680
-		define('_MAX_LOG', 100);
2681
-	}
2682
-
2683
-	// Sommes-nous dans l'empire du Mal ?
2684
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2685
-	if (isset($_SERVER['SERVER_SOFTWARE']) and str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) {
2686
-		if (!defined('_OS_SERVEUR')) {
2687
-			define('_OS_SERVEUR', 'windows');
2688
-		}
2689
-		if (!defined('_SPIP_LOCK_MODE')) {
2690
-			define('_SPIP_LOCK_MODE', 1);
2691
-		} // utiliser le flock php
2692
-	} else {
2693
-		if (!defined('_OS_SERVEUR')) {
2694
-			define('_OS_SERVEUR', '');
2695
-		}
2696
-		if (!defined('_SPIP_LOCK_MODE')) {
2697
-			define('_SPIP_LOCK_MODE', 1);
2698
-		} // utiliser le flock php
2699
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2700
-	}
2701
-
2702
-	// Langue par defaut
2703
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2704
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2705
-	}
2706
-
2707
-	//
2708
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2709
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2710
-	// pour le rendre surchargeable, on va provoquer un reecriture
2711
-	// systematique du noyau ou une baisse de perfs => a etudier)
2712
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2713
-
2714
-	// charger tout de suite le path et son cache
2715
-	load_path_cache();
2716
-
2717
-	// *********** traiter les variables ************
2718
-
2719
-	//
2720
-	// Securite
2721
-	//
2722
-
2723
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2724
-	if (isset($_REQUEST['GLOBALS'])) {
2725
-		die();
2726
-	}
2727
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2728
-	spip_desinfecte($_GET);
2729
-	spip_desinfecte($_POST);
2730
-	spip_desinfecte($_COOKIE);
2731
-	spip_desinfecte($_REQUEST);
2732
-
2733
-	// appliquer le cookie_prefix
2734
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2735
-		include_spip('inc/cookie');
2736
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2737
-	}
2738
-
2739
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2740
-	if (isset($_SERVER['REQUEST_URI'])) {
2741
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2742
-	} else {
2743
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2744
-		if (
2745
-			!empty($_SERVER['QUERY_STRING'])
2746
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2747
-		) {
2748
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2749
-		}
2750
-	}
2751
-
2752
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2753
-	if (!defined('_RENOUVELLE_ALEA')) {
2754
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2755
-	}
2756
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2757
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2758
-	}
2759
-
2760
-	// charger les meta si possible et renouveller l'alea au besoin
2761
-	// charge aussi effacer_meta et ecrire_meta
2762
-	$inc_meta = charger_fonction('meta', 'inc');
2763
-	$inc_meta();
2764
-
2765
-	// nombre de repertoires depuis la racine
2766
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2767
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2768
-	// le calcul est faux)
2769
-	if (!_DIR_RESTREINT) {
2770
-		$GLOBALS['profondeur_url'] = 1;
2771
-	} else {
2772
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2773
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2774
-		if (
2775
-			!$uri_ref
2776
-			// si on est appele avec un autre ti, on est sans doute en mutu
2777
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2778
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2779
-			// s'en remettre a l'adresse du site. alea jacta est.
2780
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2781
-		) {
2782
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2783
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2784
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2785
-			} else {
2786
-				$uri_ref = '';
2787
-			}
2788
-		}
2789
-		if (!$uri or !$uri_ref) {
2790
-			$GLOBALS['profondeur_url'] = 0;
2791
-		} else {
2792
-			$GLOBALS['profondeur_url'] = max(
2793
-				0,
2794
-				substr_count($uri[0], '/')
2795
-				- substr_count($uri_ref, '/')
2796
-			);
2797
-		}
2798
-	}
2799
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2800
-	if (_FILE_CONNECT) {
2801
-		if (
2802
-			verifier_visiteur() == '0minirezo'
2803
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2804
-			and !isset($_COOKIE['spip_admin'])
2805
-		) {
2806
-			clear_path_cache();
2807
-		}
2808
-	}
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
+    // répertoire des libs via Composer
2522
+    if (!defined('_DIR_VENDOR')) {
2523
+        define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2524
+    }
2525
+
2526
+    if (!defined('_DIR_IMG')) {
2527
+        define('_DIR_IMG', $pa);
2528
+    }
2529
+    if (!defined('_DIR_LOGOS')) {
2530
+        define('_DIR_LOGOS', $pa);
2531
+    }
2532
+    if (!defined('_DIR_IMG_ICONES')) {
2533
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2534
+    }
2535
+
2536
+    if (!defined('_DIR_DUMP')) {
2537
+        define('_DIR_DUMP', $ti . 'dump/');
2538
+    }
2539
+    if (!defined('_DIR_SESSIONS')) {
2540
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2541
+    }
2542
+    if (!defined('_DIR_TRANSFERT')) {
2543
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2544
+    }
2545
+    if (!defined('_DIR_CACHE')) {
2546
+        define('_DIR_CACHE', $ti . 'cache/');
2547
+    }
2548
+    if (!defined('_DIR_CACHE_XML')) {
2549
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2550
+    }
2551
+    if (!defined('_DIR_SKELS')) {
2552
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2553
+    }
2554
+    if (!defined('_DIR_AIDE')) {
2555
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2556
+    }
2557
+    if (!defined('_DIR_TMP')) {
2558
+        define('_DIR_TMP', $ti);
2559
+    }
2560
+
2561
+    if (!defined('_DIR_VAR')) {
2562
+        define('_DIR_VAR', $ta);
2563
+    }
2564
+
2565
+    if (!defined('_DIR_ETC')) {
2566
+        define('_DIR_ETC', $pi);
2567
+    }
2568
+    if (!defined('_DIR_CONNECT')) {
2569
+        define('_DIR_CONNECT', $pi);
2570
+    }
2571
+    if (!defined('_DIR_CHMOD')) {
2572
+        define('_DIR_CHMOD', $pi);
2573
+    }
2574
+
2575
+    if (!isset($GLOBALS['test_dirs'])) {
2576
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2577
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2578
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2579
+    }
2580
+
2581
+    // Declaration des fichiers
2582
+
2583
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2584
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2585
+    }
2586
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2587
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2588
+    }
2589
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2590
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2591
+    }
2592
+    if (!defined('_CACHE_PIPELINES')) {
2593
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2594
+    }
2595
+    if (!defined('_CACHE_CHEMIN')) {
2596
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2597
+    }
2598
+
2599
+    # attention .php obligatoire pour ecrire_fichier_securise
2600
+    if (!defined('_FILE_META')) {
2601
+        define('_FILE_META', $ti . 'meta_cache.php');
2602
+    }
2603
+    if (!defined('_DIR_LOG')) {
2604
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2605
+    }
2606
+    if (!defined('_FILE_LOG')) {
2607
+        define('_FILE_LOG', 'spip');
2608
+    }
2609
+    if (!defined('_FILE_LOG_SUFFIX')) {
2610
+        define('_FILE_LOG_SUFFIX', '.log');
2611
+    }
2612
+
2613
+    // Le fichier de connexion a la base de donnees
2614
+    // tient compte des anciennes versions (inc_connect...)
2615
+    if (!defined('_FILE_CONNECT_INS')) {
2616
+        define('_FILE_CONNECT_INS', 'connect');
2617
+    }
2618
+    if (!defined('_FILE_CONNECT')) {
2619
+        define(
2620
+            '_FILE_CONNECT',
2621
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2622
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2623
+            : false))
2624
+        );
2625
+    }
2626
+
2627
+    // Le fichier de reglages des droits
2628
+    if (!defined('_FILE_CHMOD_INS')) {
2629
+        define('_FILE_CHMOD_INS', 'chmod');
2630
+    }
2631
+    if (!defined('_FILE_CHMOD')) {
2632
+        define(
2633
+            '_FILE_CHMOD',
2634
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2635
+            : false)
2636
+        );
2637
+    }
2638
+
2639
+    if (!defined('_FILE_LDAP')) {
2640
+        define('_FILE_LDAP', 'ldap.php');
2641
+    }
2642
+
2643
+    if (!defined('_FILE_TMP_SUFFIX')) {
2644
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2645
+    }
2646
+    if (!defined('_FILE_CONNECT_TMP')) {
2647
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2648
+    }
2649
+    if (!defined('_FILE_CHMOD_TMP')) {
2650
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2651
+    }
2652
+
2653
+    // Definition des droits d'acces en ecriture
2654
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2655
+        include_once _FILE_CHMOD;
2656
+    }
2657
+
2658
+    // Se mefier des fichiers mal remplis!
2659
+    if (!defined('_SPIP_CHMOD')) {
2660
+        define('_SPIP_CHMOD', 0777);
2661
+    }
2662
+
2663
+    if (!defined('_DEFAULT_CHARSET')) {
2664
+        /** Le charset par défaut lors de l'installation */
2665
+        define('_DEFAULT_CHARSET', 'utf-8');
2666
+    }
2667
+    if (!defined('_ROOT_PLUGINS')) {
2668
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2669
+    }
2670
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2671
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2672
+    }
2673
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2674
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2675
+    }
2676
+
2677
+    // La taille des Log
2678
+    if (!defined('_MAX_LOG')) {
2679
+        define('_MAX_LOG', 100);
2680
+    }
2681
+
2682
+    // Sommes-nous dans l'empire du Mal ?
2683
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2684
+    if (isset($_SERVER['SERVER_SOFTWARE']) and str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) {
2685
+        if (!defined('_OS_SERVEUR')) {
2686
+            define('_OS_SERVEUR', 'windows');
2687
+        }
2688
+        if (!defined('_SPIP_LOCK_MODE')) {
2689
+            define('_SPIP_LOCK_MODE', 1);
2690
+        } // utiliser le flock php
2691
+    } else {
2692
+        if (!defined('_OS_SERVEUR')) {
2693
+            define('_OS_SERVEUR', '');
2694
+        }
2695
+        if (!defined('_SPIP_LOCK_MODE')) {
2696
+            define('_SPIP_LOCK_MODE', 1);
2697
+        } // utiliser le flock php
2698
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2699
+    }
2700
+
2701
+    // Langue par defaut
2702
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2703
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2704
+    }
2705
+
2706
+    //
2707
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2708
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2709
+    // pour le rendre surchargeable, on va provoquer un reecriture
2710
+    // systematique du noyau ou une baisse de perfs => a etudier)
2711
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2712
+
2713
+    // charger tout de suite le path et son cache
2714
+    load_path_cache();
2715
+
2716
+    // *********** traiter les variables ************
2717
+
2718
+    //
2719
+    // Securite
2720
+    //
2721
+
2722
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2723
+    if (isset($_REQUEST['GLOBALS'])) {
2724
+        die();
2725
+    }
2726
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2727
+    spip_desinfecte($_GET);
2728
+    spip_desinfecte($_POST);
2729
+    spip_desinfecte($_COOKIE);
2730
+    spip_desinfecte($_REQUEST);
2731
+
2732
+    // appliquer le cookie_prefix
2733
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2734
+        include_spip('inc/cookie');
2735
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2736
+    }
2737
+
2738
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2739
+    if (isset($_SERVER['REQUEST_URI'])) {
2740
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2741
+    } else {
2742
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2743
+        if (
2744
+            !empty($_SERVER['QUERY_STRING'])
2745
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2746
+        ) {
2747
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2748
+        }
2749
+    }
2750
+
2751
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2752
+    if (!defined('_RENOUVELLE_ALEA')) {
2753
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2754
+    }
2755
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2756
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2757
+    }
2758
+
2759
+    // charger les meta si possible et renouveller l'alea au besoin
2760
+    // charge aussi effacer_meta et ecrire_meta
2761
+    $inc_meta = charger_fonction('meta', 'inc');
2762
+    $inc_meta();
2763
+
2764
+    // nombre de repertoires depuis la racine
2765
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2766
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2767
+    // le calcul est faux)
2768
+    if (!_DIR_RESTREINT) {
2769
+        $GLOBALS['profondeur_url'] = 1;
2770
+    } else {
2771
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2772
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2773
+        if (
2774
+            !$uri_ref
2775
+            // si on est appele avec un autre ti, on est sans doute en mutu
2776
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2777
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2778
+            // s'en remettre a l'adresse du site. alea jacta est.
2779
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2780
+        ) {
2781
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2782
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2783
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2784
+            } else {
2785
+                $uri_ref = '';
2786
+            }
2787
+        }
2788
+        if (!$uri or !$uri_ref) {
2789
+            $GLOBALS['profondeur_url'] = 0;
2790
+        } else {
2791
+            $GLOBALS['profondeur_url'] = max(
2792
+                0,
2793
+                substr_count($uri[0], '/')
2794
+                - substr_count($uri_ref, '/')
2795
+            );
2796
+        }
2797
+    }
2798
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2799
+    if (_FILE_CONNECT) {
2800
+        if (
2801
+            verifier_visiteur() == '0minirezo'
2802
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2803
+            and !isset($_COOKIE['spip_admin'])
2804
+        ) {
2805
+            clear_path_cache();
2806
+        }
2807
+    }
2809 2808
 }
2810 2809
 
2811 2810
 /**
@@ -2814,157 +2813,157 @@  discard block
 block discarded – undo
2814 2813
  *
2815 2814
  */
2816 2815
 function spip_initialisation_suite() {
2817
-	static $too_late = 0;
2818
-	if ($too_late++) {
2819
-		return;
2820
-	}
2821
-
2822
-	// taille mini des login
2823
-	if (!defined('_LOGIN_TROP_COURT')) {
2824
-		define('_LOGIN_TROP_COURT', 4);
2825
-	}
2826
-
2827
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2828
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2829
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2830
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2831
-
2832
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2833
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2834
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2835
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2836
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2837
-
2838
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2839
-		define('_PASS_LONGUEUR_MINI', 6);
2840
-	}
2841
-
2842
-	// largeur maximale des images dans l'administration
2843
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2844
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2845
-	}
2846
-
2847
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2848
-	if (!defined('_IMG_QUALITE')) {
2849
-		define('_IMG_QUALITE', 85);
2850
-	} # valeur par defaut
2851
-	if (!defined('_IMG_GD_QUALITE')) {
2852
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2853
-	} # surcharge pour la lib GD
2854
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2855
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2856
-	} # surcharge pour imagick en ligne de commande
2857
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2858
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2859
-		define('_IMG_IMAGICK_QUALITE', 75);
2860
-	} # surcharge pour imagick en PHP
2861
-
2862
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2863
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2864
-	} // poids en octet
2865
-
2866
-	// qq chaines standard
2867
-	if (!defined('_ACCESS_FILE_NAME')) {
2868
-		define('_ACCESS_FILE_NAME', '.htaccess');
2869
-	}
2870
-	if (!defined('_AUTH_USER_FILE')) {
2871
-		define('_AUTH_USER_FILE', '.htpasswd');
2872
-	}
2873
-	if (!defined('_SPIP_DUMP')) {
2874
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2875
-	}
2876
-	if (!defined('_CACHE_RUBRIQUES')) {
2877
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2878
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2879
-	}
2880
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2881
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2882
-		define('_CACHE_RUBRIQUES_MAX', 500);
2883
-	}
2884
-
2885
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2886
-		/**
2887
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2888
-		 * @var int Nombre de caractères */
2889
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2890
-	}
2891
-
2892
-	if (!defined('_EXTENSION_SQUELETTES')) {
2893
-		define('_EXTENSION_SQUELETTES', 'html');
2894
-	}
2895
-
2896
-	if (!defined('_DOCTYPE_ECRIRE')) {
2897
-		/** Définit le doctype de l’espace privé */
2898
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2899
-	}
2900
-	if (!defined('_DOCTYPE_AIDE')) {
2901
-		/** Définit le doctype de l’aide en ligne */
2902
-		define(
2903
-			'_DOCTYPE_AIDE',
2904
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2905
-		);
2906
-	}
2907
-
2908
-	if (!defined('_SPIP_SCRIPT')) {
2909
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2910
-		 * le script de l'espace public, alias index.php */
2911
-		define('_SPIP_SCRIPT', 'spip.php');
2912
-	}
2913
-	if (!defined('_SPIP_PAGE')) {
2914
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2915
-		define('_SPIP_PAGE', 'page');
2916
-	}
2917
-
2918
-	// le script de l'espace prive
2919
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2920
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2921
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2922
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2923
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2924
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2925
-		} else {
2926
-			define('_SPIP_ECRIRE_SCRIPT', '');
2927
-		}
2928
-	}
2929
-
2930
-
2931
-	if (!defined('_SPIP_AJAX')) {
2932
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2933
-			? 1
2934
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2935
-	}
2936
-
2937
-	// La requete est-elle en ajax ?
2938
-	if (!defined('_AJAX')) {
2939
-		define(
2940
-			'_AJAX',
2941
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2942
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2943
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2944
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2945
-			)
2946
-			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
2947
-		);
2948
-	}
2949
-
2950
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2951
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2952
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2953
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2954
-		define(
2955
-			'_IMG_GD_MAX_PIXELS',
2956
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2957
-			? $GLOBALS['meta']['max_taille_vignettes']
2958
-			: 0
2959
-		);
2960
-	}
2961
-
2962
-	// Protocoles a normaliser dans les chaines de langues
2963
-	if (!defined('_PROTOCOLES_STD')) {
2964
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2965
-	}
2966
-
2967
-	init_var_mode();
2816
+    static $too_late = 0;
2817
+    if ($too_late++) {
2818
+        return;
2819
+    }
2820
+
2821
+    // taille mini des login
2822
+    if (!defined('_LOGIN_TROP_COURT')) {
2823
+        define('_LOGIN_TROP_COURT', 4);
2824
+    }
2825
+
2826
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2827
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2828
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2829
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2830
+
2831
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2832
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2833
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2834
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2835
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2836
+
2837
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2838
+        define('_PASS_LONGUEUR_MINI', 6);
2839
+    }
2840
+
2841
+    // largeur maximale des images dans l'administration
2842
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2843
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2844
+    }
2845
+
2846
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2847
+    if (!defined('_IMG_QUALITE')) {
2848
+        define('_IMG_QUALITE', 85);
2849
+    } # valeur par defaut
2850
+    if (!defined('_IMG_GD_QUALITE')) {
2851
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2852
+    } # surcharge pour la lib GD
2853
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2854
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2855
+    } # surcharge pour imagick en ligne de commande
2856
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2857
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2858
+        define('_IMG_IMAGICK_QUALITE', 75);
2859
+    } # surcharge pour imagick en PHP
2860
+
2861
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2862
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2863
+    } // poids en octet
2864
+
2865
+    // qq chaines standard
2866
+    if (!defined('_ACCESS_FILE_NAME')) {
2867
+        define('_ACCESS_FILE_NAME', '.htaccess');
2868
+    }
2869
+    if (!defined('_AUTH_USER_FILE')) {
2870
+        define('_AUTH_USER_FILE', '.htpasswd');
2871
+    }
2872
+    if (!defined('_SPIP_DUMP')) {
2873
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2874
+    }
2875
+    if (!defined('_CACHE_RUBRIQUES')) {
2876
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2877
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2878
+    }
2879
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2880
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2881
+        define('_CACHE_RUBRIQUES_MAX', 500);
2882
+    }
2883
+
2884
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2885
+        /**
2886
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2887
+         * @var int Nombre de caractères */
2888
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2889
+    }
2890
+
2891
+    if (!defined('_EXTENSION_SQUELETTES')) {
2892
+        define('_EXTENSION_SQUELETTES', 'html');
2893
+    }
2894
+
2895
+    if (!defined('_DOCTYPE_ECRIRE')) {
2896
+        /** Définit le doctype de l’espace privé */
2897
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2898
+    }
2899
+    if (!defined('_DOCTYPE_AIDE')) {
2900
+        /** Définit le doctype de l’aide en ligne */
2901
+        define(
2902
+            '_DOCTYPE_AIDE',
2903
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2904
+        );
2905
+    }
2906
+
2907
+    if (!defined('_SPIP_SCRIPT')) {
2908
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2909
+         * le script de l'espace public, alias index.php */
2910
+        define('_SPIP_SCRIPT', 'spip.php');
2911
+    }
2912
+    if (!defined('_SPIP_PAGE')) {
2913
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2914
+        define('_SPIP_PAGE', 'page');
2915
+    }
2916
+
2917
+    // le script de l'espace prive
2918
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2919
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2920
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2921
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2922
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2923
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2924
+        } else {
2925
+            define('_SPIP_ECRIRE_SCRIPT', '');
2926
+        }
2927
+    }
2928
+
2929
+
2930
+    if (!defined('_SPIP_AJAX')) {
2931
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2932
+            ? 1
2933
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2934
+    }
2935
+
2936
+    // La requete est-elle en ajax ?
2937
+    if (!defined('_AJAX')) {
2938
+        define(
2939
+            '_AJAX',
2940
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2941
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2942
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2943
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2944
+            )
2945
+            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
2946
+        );
2947
+    }
2948
+
2949
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2950
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2951
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2952
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2953
+        define(
2954
+            '_IMG_GD_MAX_PIXELS',
2955
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2956
+            ? $GLOBALS['meta']['max_taille_vignettes']
2957
+            : 0
2958
+        );
2959
+    }
2960
+
2961
+    // Protocoles a normaliser dans les chaines de langues
2962
+    if (!defined('_PROTOCOLES_STD')) {
2963
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2964
+    }
2965
+
2966
+    init_var_mode();
2968 2967
 }
2969 2968
 
2970 2969
 /**
@@ -2998,136 +2997,136 @@  discard block
 block discarded – undo
2998 2997
  * `   var_mode` (calcul ou recalcul).
2999 2998
  */
3000 2999
 function init_var_mode() {
3001
-	static $done = false;
3002
-	if (!$done) {
3003
-		if (isset($_GET['var_mode'])) {
3004
-			$var_mode = explode(',', $_GET['var_mode']);
3005
-			// tout le monde peut calcul/recalcul
3006
-			if (!defined('_VAR_MODE')) {
3007
-				if (in_array('recalcul', $var_mode)) {
3008
-					define('_VAR_MODE', 'recalcul');
3009
-				} elseif (in_array('calcul', $var_mode)) {
3010
-					define('_VAR_MODE', 'calcul');
3011
-				}
3012
-			}
3013
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3014
-			if ($var_mode) {
3015
-				include_spip('inc/autoriser');
3016
-				// autoriser preview si preview seulement, et sinon autoriser debug
3017
-				if (
3018
-					autoriser(
3019
-						($_GET['var_mode'] == 'preview')
3020
-						? 'previsualiser'
3021
-						: 'debug'
3022
-					)
3023
-				) {
3024
-					if (in_array('traduction', $var_mode)) {
3025
-						// forcer le calcul pour passer dans traduire
3026
-						if (!defined('_VAR_MODE')) {
3027
-							define('_VAR_MODE', 'calcul');
3028
-						}
3029
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3030
-						if (!defined('_VAR_NOCACHE')) {
3031
-							define('_VAR_NOCACHE', true);
3032
-						}
3033
-						$var_mode = array_diff($var_mode, ['traduction']);
3034
-					}
3035
-					if (in_array('preview', $var_mode)) {
3036
-						// basculer sur les criteres de preview dans les boucles
3037
-						if (!defined('_VAR_PREVIEW')) {
3038
-							define('_VAR_PREVIEW', true);
3039
-						}
3040
-						// forcer le calcul
3041
-						if (!defined('_VAR_MODE')) {
3042
-							define('_VAR_MODE', 'calcul');
3043
-						}
3044
-						// et ne pas enregistrer de cache
3045
-						if (!defined('_VAR_NOCACHE')) {
3046
-							define('_VAR_NOCACHE', true);
3047
-						}
3048
-						$var_mode = array_diff($var_mode, ['preview']);
3049
-					}
3050
-					if (in_array('inclure', $var_mode)) {
3051
-						// forcer le compilo et ignorer les caches existants
3052
-						if (!defined('_VAR_MODE')) {
3053
-							define('_VAR_MODE', 'calcul');
3054
-						}
3055
-						if (!defined('_VAR_INCLURE')) {
3056
-							define('_VAR_INCLURE', true);
3057
-						}
3058
-						// et ne pas enregistrer de cache
3059
-						if (!defined('_VAR_NOCACHE')) {
3060
-							define('_VAR_NOCACHE', true);
3061
-						}
3062
-						$var_mode = array_diff($var_mode, ['inclure']);
3063
-					}
3064
-					if (in_array('urls', $var_mode)) {
3065
-						// forcer le compilo et ignorer les caches existants
3066
-						if (!defined('_VAR_MODE')) {
3067
-							define('_VAR_MODE', 'calcul');
3068
-						}
3069
-						if (!defined('_VAR_URLS')) {
3070
-							define('_VAR_URLS', true);
3071
-						}
3072
-						$var_mode = array_diff($var_mode, ['urls']);
3073
-					}
3074
-					if (in_array('images', $var_mode)) {
3075
-						// forcer le compilo et ignorer les caches existants
3076
-						if (!defined('_VAR_MODE')) {
3077
-							define('_VAR_MODE', 'calcul');
3078
-						}
3079
-						// indiquer qu'on doit recalculer les images
3080
-						if (!defined('_VAR_IMAGES')) {
3081
-							define('_VAR_IMAGES', true);
3082
-						}
3083
-						$var_mode = array_diff($var_mode, ['images']);
3084
-					}
3085
-					if (in_array('debug', $var_mode)) {
3086
-						if (!defined('_VAR_MODE')) {
3087
-							define('_VAR_MODE', 'debug');
3088
-						}
3089
-						// et ne pas enregistrer de cache
3090
-						if (!defined('_VAR_NOCACHE')) {
3091
-							define('_VAR_NOCACHE', true);
3092
-						}
3093
-						$var_mode = array_diff($var_mode, ['debug']);
3094
-					}
3095
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3096
-						define('_VAR_MODE', reset($var_mode));
3097
-					}
3098
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3099
-						spip_log($GLOBALS['visiteur_session']['nom']
3100
-							. ' ' . _VAR_MODE);
3101
-					}
3102
-				} // pas autorise ?
3103
-				else {
3104
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3105
-					if (
3106
-						!$GLOBALS['visiteur_session']
3107
-						and !empty($_SERVER['HTTP_HOST'])
3108
-						and !empty($_SERVER['REQUEST_METHOD'])
3109
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3110
-					) {
3111
-						$self = self('&', true);
3112
-						if (strpos($self, 'page=login') === false) {
3113
-							include_spip('inc/headers');
3114
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3115
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3116
-						}
3117
-					}
3118
-					// sinon tant pis
3119
-				}
3120
-			}
3121
-		}
3122
-		if (!defined('_VAR_MODE')) {
3123
-			/**
3124
-			 * Indique le mode de calcul ou d'affichage de la page.
3125
-			 * @see init_var_mode()
3126
-			 */
3127
-			define('_VAR_MODE', false);
3128
-		}
3129
-		$done = true;
3130
-	}
3000
+    static $done = false;
3001
+    if (!$done) {
3002
+        if (isset($_GET['var_mode'])) {
3003
+            $var_mode = explode(',', $_GET['var_mode']);
3004
+            // tout le monde peut calcul/recalcul
3005
+            if (!defined('_VAR_MODE')) {
3006
+                if (in_array('recalcul', $var_mode)) {
3007
+                    define('_VAR_MODE', 'recalcul');
3008
+                } elseif (in_array('calcul', $var_mode)) {
3009
+                    define('_VAR_MODE', 'calcul');
3010
+                }
3011
+            }
3012
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3013
+            if ($var_mode) {
3014
+                include_spip('inc/autoriser');
3015
+                // autoriser preview si preview seulement, et sinon autoriser debug
3016
+                if (
3017
+                    autoriser(
3018
+                        ($_GET['var_mode'] == 'preview')
3019
+                        ? 'previsualiser'
3020
+                        : 'debug'
3021
+                    )
3022
+                ) {
3023
+                    if (in_array('traduction', $var_mode)) {
3024
+                        // forcer le calcul pour passer dans traduire
3025
+                        if (!defined('_VAR_MODE')) {
3026
+                            define('_VAR_MODE', 'calcul');
3027
+                        }
3028
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3029
+                        if (!defined('_VAR_NOCACHE')) {
3030
+                            define('_VAR_NOCACHE', true);
3031
+                        }
3032
+                        $var_mode = array_diff($var_mode, ['traduction']);
3033
+                    }
3034
+                    if (in_array('preview', $var_mode)) {
3035
+                        // basculer sur les criteres de preview dans les boucles
3036
+                        if (!defined('_VAR_PREVIEW')) {
3037
+                            define('_VAR_PREVIEW', true);
3038
+                        }
3039
+                        // forcer le calcul
3040
+                        if (!defined('_VAR_MODE')) {
3041
+                            define('_VAR_MODE', 'calcul');
3042
+                        }
3043
+                        // et ne pas enregistrer de cache
3044
+                        if (!defined('_VAR_NOCACHE')) {
3045
+                            define('_VAR_NOCACHE', true);
3046
+                        }
3047
+                        $var_mode = array_diff($var_mode, ['preview']);
3048
+                    }
3049
+                    if (in_array('inclure', $var_mode)) {
3050
+                        // forcer le compilo et ignorer les caches existants
3051
+                        if (!defined('_VAR_MODE')) {
3052
+                            define('_VAR_MODE', 'calcul');
3053
+                        }
3054
+                        if (!defined('_VAR_INCLURE')) {
3055
+                            define('_VAR_INCLURE', true);
3056
+                        }
3057
+                        // et ne pas enregistrer de cache
3058
+                        if (!defined('_VAR_NOCACHE')) {
3059
+                            define('_VAR_NOCACHE', true);
3060
+                        }
3061
+                        $var_mode = array_diff($var_mode, ['inclure']);
3062
+                    }
3063
+                    if (in_array('urls', $var_mode)) {
3064
+                        // forcer le compilo et ignorer les caches existants
3065
+                        if (!defined('_VAR_MODE')) {
3066
+                            define('_VAR_MODE', 'calcul');
3067
+                        }
3068
+                        if (!defined('_VAR_URLS')) {
3069
+                            define('_VAR_URLS', true);
3070
+                        }
3071
+                        $var_mode = array_diff($var_mode, ['urls']);
3072
+                    }
3073
+                    if (in_array('images', $var_mode)) {
3074
+                        // forcer le compilo et ignorer les caches existants
3075
+                        if (!defined('_VAR_MODE')) {
3076
+                            define('_VAR_MODE', 'calcul');
3077
+                        }
3078
+                        // indiquer qu'on doit recalculer les images
3079
+                        if (!defined('_VAR_IMAGES')) {
3080
+                            define('_VAR_IMAGES', true);
3081
+                        }
3082
+                        $var_mode = array_diff($var_mode, ['images']);
3083
+                    }
3084
+                    if (in_array('debug', $var_mode)) {
3085
+                        if (!defined('_VAR_MODE')) {
3086
+                            define('_VAR_MODE', 'debug');
3087
+                        }
3088
+                        // et ne pas enregistrer de cache
3089
+                        if (!defined('_VAR_NOCACHE')) {
3090
+                            define('_VAR_NOCACHE', true);
3091
+                        }
3092
+                        $var_mode = array_diff($var_mode, ['debug']);
3093
+                    }
3094
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3095
+                        define('_VAR_MODE', reset($var_mode));
3096
+                    }
3097
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3098
+                        spip_log($GLOBALS['visiteur_session']['nom']
3099
+                            . ' ' . _VAR_MODE);
3100
+                    }
3101
+                } // pas autorise ?
3102
+                else {
3103
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3104
+                    if (
3105
+                        !$GLOBALS['visiteur_session']
3106
+                        and !empty($_SERVER['HTTP_HOST'])
3107
+                        and !empty($_SERVER['REQUEST_METHOD'])
3108
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3109
+                    ) {
3110
+                        $self = self('&', true);
3111
+                        if (strpos($self, 'page=login') === false) {
3112
+                            include_spip('inc/headers');
3113
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3114
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3115
+                        }
3116
+                    }
3117
+                    // sinon tant pis
3118
+                }
3119
+            }
3120
+        }
3121
+        if (!defined('_VAR_MODE')) {
3122
+            /**
3123
+             * Indique le mode de calcul ou d'affichage de la page.
3124
+             * @see init_var_mode()
3125
+             */
3126
+            define('_VAR_MODE', false);
3127
+        }
3128
+        $done = true;
3129
+    }
3131 3130
 }
3132 3131
 
3133 3132
 /**
@@ -3139,16 +3138,16 @@  discard block
 block discarded – undo
3139 3138
  * @param bool $deep = true : appliquer récursivement
3140 3139
 **/
3141 3140
 function spip_desinfecte(&$t, $deep = true) {
3142
-	foreach ($t as $key => $val) {
3143
-		if (is_string($t[$key])) {
3144
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3145
-		} // traiter aussi les "texte_plus" de article_edit
3146
-		else {
3147
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3148
-				spip_desinfecte($t[$key], $deep);
3149
-			}
3150
-		}
3151
-	}
3141
+    foreach ($t as $key => $val) {
3142
+        if (is_string($t[$key])) {
3143
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3144
+        } // traiter aussi les "texte_plus" de article_edit
3145
+        else {
3146
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3147
+                spip_desinfecte($t[$key], $deep);
3148
+            }
3149
+        }
3150
+    }
3152 3151
 }
3153 3152
 
3154 3153
 /**
@@ -3161,64 +3160,64 @@  discard block
 block discarded – undo
3161 3160
  * @return string|0|false
3162 3161
 **/
3163 3162
 function verifier_visiteur() {
3164
-	@spip_initialisation_core(
3165
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3166
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3167
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3168
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3169
-	);
3170
-
3171
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3172
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3173
-	// Attention on separe bien session_nom et nom, pour eviter
3174
-	// les melanges entre donnees SQL et variables plus aleatoires
3175
-	$variables_session = ['session_nom', 'session_email'];
3176
-	foreach ($variables_session as $var) {
3177
-		if (_request($var) !== null) {
3178
-			$init = true;
3179
-			break;
3180
-		}
3181
-	}
3182
-	if (isset($init)) {
3183
-		#@spip_initialisation_suite();
3184
-		$session = charger_fonction('session', 'inc');
3185
-		$session();
3186
-		include_spip('inc/texte');
3187
-		foreach ($variables_session as $var) {
3188
-			if (($a = _request($var)) !== null) {
3189
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3190
-			}
3191
-		}
3192
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3193
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3194
-		}
3195
-		$session($GLOBALS['visiteur_session']);
3196
-
3197
-		return 0;
3198
-	}
3199
-
3200
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3201
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3202
-		$session = charger_fonction('session', 'inc');
3203
-		if ($session()) {
3204
-			return $GLOBALS['visiteur_session']['statut'];
3205
-		}
3206
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3207
-			include_spip('inc/auth');
3208
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3209
-		}
3210
-		if ($h) {
3211
-			$GLOBALS['visiteur_session'] = $h;
3212
-
3213
-			return $GLOBALS['visiteur_session']['statut'];
3214
-		}
3215
-	}
3216
-
3217
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3218
-	include_spip('inc/lang');
3219
-	utiliser_langue_visiteur();
3220
-
3221
-	return false;
3163
+    @spip_initialisation_core(
3164
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3165
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3166
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3167
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3168
+    );
3169
+
3170
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3171
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3172
+    // Attention on separe bien session_nom et nom, pour eviter
3173
+    // les melanges entre donnees SQL et variables plus aleatoires
3174
+    $variables_session = ['session_nom', 'session_email'];
3175
+    foreach ($variables_session as $var) {
3176
+        if (_request($var) !== null) {
3177
+            $init = true;
3178
+            break;
3179
+        }
3180
+    }
3181
+    if (isset($init)) {
3182
+        #@spip_initialisation_suite();
3183
+        $session = charger_fonction('session', 'inc');
3184
+        $session();
3185
+        include_spip('inc/texte');
3186
+        foreach ($variables_session as $var) {
3187
+            if (($a = _request($var)) !== null) {
3188
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3189
+            }
3190
+        }
3191
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3192
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3193
+        }
3194
+        $session($GLOBALS['visiteur_session']);
3195
+
3196
+        return 0;
3197
+    }
3198
+
3199
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3200
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3201
+        $session = charger_fonction('session', 'inc');
3202
+        if ($session()) {
3203
+            return $GLOBALS['visiteur_session']['statut'];
3204
+        }
3205
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3206
+            include_spip('inc/auth');
3207
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3208
+        }
3209
+        if ($h) {
3210
+            $GLOBALS['visiteur_session'] = $h;
3211
+
3212
+            return $GLOBALS['visiteur_session']['statut'];
3213
+        }
3214
+    }
3215
+
3216
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3217
+    include_spip('inc/lang');
3218
+    utiliser_langue_visiteur();
3219
+
3220
+    return false;
3222 3221
 }
3223 3222
 
3224 3223
 
@@ -3241,21 +3240,21 @@  discard block
 block discarded – undo
3241 3240
  *     - string Langue utilisée.
3242 3241
  **/
3243 3242
 function lang_select($lang = null) {
3244
-	static $pile_langues = [];
3245
-	if (!function_exists('changer_langue')) {
3246
-		include_spip('inc/lang');
3247
-	}
3248
-	if ($lang === null) {
3249
-		$lang = array_pop($pile_langues);
3250
-	} else {
3251
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3252
-	}
3253
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3254
-		return $lang;
3255
-	}
3256
-	changer_langue($lang);
3243
+    static $pile_langues = [];
3244
+    if (!function_exists('changer_langue')) {
3245
+        include_spip('inc/lang');
3246
+    }
3247
+    if ($lang === null) {
3248
+        $lang = array_pop($pile_langues);
3249
+    } else {
3250
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3251
+    }
3252
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3253
+        return $lang;
3254
+    }
3255
+    changer_langue($lang);
3257 3256
 
3258
-	return $lang;
3257
+    return $lang;
3259 3258
 }
3260 3259
 
3261 3260
 /**
@@ -3272,20 +3271,20 @@  discard block
 block discarded – undo
3272 3271
  *     Identifiant de la session
3273 3272
  **/
3274 3273
 function spip_session($force = false) {
3275
-	static $session;
3276
-	if ($force or !isset($session)) {
3277
-		$s = pipeline(
3278
-			'definir_session',
3279
-			$GLOBALS['visiteur_session']
3280
-				? serialize($GLOBALS['visiteur_session'])
3281
-				. '_' . @$_COOKIE['spip_session']
3282
-				: ''
3283
-		);
3284
-		$session = $s ? substr(md5($s), 0, 8) : '';
3285
-	}
3274
+    static $session;
3275
+    if ($force or !isset($session)) {
3276
+        $s = pipeline(
3277
+            'definir_session',
3278
+            $GLOBALS['visiteur_session']
3279
+                ? serialize($GLOBALS['visiteur_session'])
3280
+                . '_' . @$_COOKIE['spip_session']
3281
+                : ''
3282
+        );
3283
+        $session = $s ? substr(md5($s), 0, 8) : '';
3284
+    }
3286 3285
 
3287
-	#spip_log('session: '.$session);
3288
-	return $session;
3286
+    #spip_log('session: '.$session);
3287
+    return $session;
3289 3288
 }
3290 3289
 
3291 3290
 
@@ -3304,9 +3303,9 @@  discard block
 block discarded – undo
3304 3303
  *    Lien sur une icone d'aide
3305 3304
  **/
3306 3305
 function aider($aide = '', $distante = false) {
3307
-	$aider = charger_fonction('aide', 'inc', true);
3306
+    $aider = charger_fonction('aide', 'inc', true);
3308 3307
 
3309
-	return $aider ? $aider($aide, '', [], $distante) : '';
3308
+    return $aider ? $aider($aide, '', [], $distante) : '';
3310 3309
 }
3311 3310
 
3312 3311
 /**
@@ -3316,35 +3315,35 @@  discard block
 block discarded – undo
3316 3315
  */
3317 3316
 function exec_info_dist() {
3318 3317
 
3319
-	include_spip('inc/autoriser');
3320
-	if (autoriser('phpinfos')) {
3321
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3322
-		$cookies_backup = [];
3323
-		$server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3324
-		$env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3325
-		$mask = '******************************';
3326
-		foreach ($cookies_masques as $k) {
3327
-			if (!empty($_COOKIE[$k])) {
3328
-				$cookies_backup[$k] = $_COOKIE[$k];
3329
-				$_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3330
-				$_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3331
-				$_COOKIE[$k] = $mask;
3332
-			}
3333
-		}
3334
-		phpinfo();
3335
-		foreach ($cookies_backup as $k => $v) {
3336
-			$_COOKIE[$k] = $v;
3337
-		}
3338
-		foreach ($server_backup as $k => $v) {
3339
-			$_SERVER[$k] = $v;
3340
-		}
3341
-		foreach ($env_backup as $k => $v) {
3342
-			$_ENV[$k] = $v;
3343
-		}
3344
-	} else {
3345
-		include_spip('inc/filtres');
3346
-		sinon_interdire_acces();
3347
-	}
3318
+    include_spip('inc/autoriser');
3319
+    if (autoriser('phpinfos')) {
3320
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3321
+        $cookies_backup = [];
3322
+        $server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3323
+        $env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3324
+        $mask = '******************************';
3325
+        foreach ($cookies_masques as $k) {
3326
+            if (!empty($_COOKIE[$k])) {
3327
+                $cookies_backup[$k] = $_COOKIE[$k];
3328
+                $_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3329
+                $_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3330
+                $_COOKIE[$k] = $mask;
3331
+            }
3332
+        }
3333
+        phpinfo();
3334
+        foreach ($cookies_backup as $k => $v) {
3335
+            $_COOKIE[$k] = $v;
3336
+        }
3337
+        foreach ($server_backup as $k => $v) {
3338
+            $_SERVER[$k] = $v;
3339
+        }
3340
+        foreach ($env_backup as $k => $v) {
3341
+            $_ENV[$k] = $v;
3342
+        }
3343
+    } else {
3344
+        include_spip('inc/filtres');
3345
+        sinon_interdire_acces();
3346
+    }
3348 3347
 }
3349 3348
 
3350 3349
 /**
@@ -3364,13 +3363,13 @@  discard block
 block discarded – undo
3364 3363
  *     - string si $message à false.
3365 3364
  **/
3366 3365
 function erreur_squelette($message = '', $lieu = '') {
3367
-	$debusquer = charger_fonction('debusquer', 'public');
3368
-	if (is_array($lieu)) {
3369
-		include_spip('public/compiler');
3370
-		$lieu = reconstruire_contexte_compil($lieu);
3371
-	}
3366
+    $debusquer = charger_fonction('debusquer', 'public');
3367
+    if (is_array($lieu)) {
3368
+        include_spip('public/compiler');
3369
+        $lieu = reconstruire_contexte_compil($lieu);
3370
+    }
3372 3371
 
3373
-	return $debusquer($message, $lieu);
3372
+    return $debusquer($message, $lieu);
3374 3373
 }
3375 3374
 
3376 3375
 /**
@@ -3407,108 +3406,108 @@  discard block
 block discarded – undo
3407 3406
  *     - ou tableau d'information sur le squelette.
3408 3407
  */
3409 3408
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3410
-	if (!function_exists('evaluer_fond')) {
3411
-		include_spip('public/assembler');
3412
-	}
3413
-	// assurer la compat avec l'ancienne syntaxe
3414
-	// (trim etait le 3eme argument, par defaut a true)
3415
-	if (!is_array($options)) {
3416
-		$options = ['trim' => $options];
3417
-	}
3418
-	if (!isset($options['trim'])) {
3419
-		$options['trim'] = true;
3420
-	}
3421
-
3422
-	if (isset($contexte['connect'])) {
3423
-		$connect = $contexte['connect'];
3424
-		unset($contexte['connect']);
3425
-	}
3426
-
3427
-	$texte = '';
3428
-	$pages = [];
3429
-	$lang_select = '';
3430
-	if (!isset($options['etoile']) or !$options['etoile']) {
3431
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3432
-		if (!isset($contexte['lang'])) {
3433
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3434
-		}
3435
-
3436
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3437
-			$lang_select = lang_select($contexte['lang']);
3438
-		}
3439
-	}
3440
-
3441
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3442
-		$GLOBALS['_INC_PUBLIC'] = 0;
3443
-	}
3444
-
3445
-	$GLOBALS['_INC_PUBLIC']++;
3446
-
3447
-	// fix #4235
3448
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3449
-
3450
-
3451
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3452
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3453
-
3454
-		$page = evaluer_fond($f, $contexte, $connect);
3455
-		if ($page === '') {
3456
-			$c = $options['compil'] ?? '';
3457
-			$a = ['fichier' => $f];
3458
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3459
-			erreur_squelette($erreur, $c);
3460
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3461
-			$page = ['texte' => '', 'erreur' => $erreur];
3462
-		}
3463
-
3464
-		$page = pipeline('recuperer_fond', [
3465
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3466
-			'data' => $page
3467
-		]);
3468
-		if (isset($options['ajax']) and $options['ajax']) {
3469
-			if (!function_exists('encoder_contexte_ajax')) {
3470
-				include_spip('inc/filtres');
3471
-			}
3472
-			$page['texte'] = encoder_contexte_ajax(
3473
-				array_merge(
3474
-					$contexte,
3475
-					['fond' => $f],
3476
-					($connect ? ['connect' => $connect] : [])
3477
-				),
3478
-				'',
3479
-				$page['texte'],
3480
-				$options['ajax']
3481
-			);
3482
-		}
3483
-
3484
-		if (isset($options['raw']) and $options['raw']) {
3485
-			$pages[] = $page;
3486
-		} else {
3487
-			$texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3488
-		}
3489
-
3490
-		// contamination de la session appelante, pour les inclusions statiques
3491
-		if (isset($page['invalideurs']['session'])) {
3492
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3493
-		}
3494
-	}
3495
-
3496
-	// restaurer le sessionnement du contexte appelant,
3497
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3498
-	if (isset($cache_utilise_session_appelant)) {
3499
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3500
-	}
3501
-
3502
-	$GLOBALS['_INC_PUBLIC']--;
3503
-
3504
-	if ($lang_select) {
3505
-		lang_select();
3506
-	}
3507
-	if (isset($options['raw']) and $options['raw']) {
3508
-		return is_array($fond) ? $pages : reset($pages);
3509
-	} else {
3510
-		return $options['trim'] ? ltrim($texte) : $texte;
3511
-	}
3409
+    if (!function_exists('evaluer_fond')) {
3410
+        include_spip('public/assembler');
3411
+    }
3412
+    // assurer la compat avec l'ancienne syntaxe
3413
+    // (trim etait le 3eme argument, par defaut a true)
3414
+    if (!is_array($options)) {
3415
+        $options = ['trim' => $options];
3416
+    }
3417
+    if (!isset($options['trim'])) {
3418
+        $options['trim'] = true;
3419
+    }
3420
+
3421
+    if (isset($contexte['connect'])) {
3422
+        $connect = $contexte['connect'];
3423
+        unset($contexte['connect']);
3424
+    }
3425
+
3426
+    $texte = '';
3427
+    $pages = [];
3428
+    $lang_select = '';
3429
+    if (!isset($options['etoile']) or !$options['etoile']) {
3430
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3431
+        if (!isset($contexte['lang'])) {
3432
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3433
+        }
3434
+
3435
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3436
+            $lang_select = lang_select($contexte['lang']);
3437
+        }
3438
+    }
3439
+
3440
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3441
+        $GLOBALS['_INC_PUBLIC'] = 0;
3442
+    }
3443
+
3444
+    $GLOBALS['_INC_PUBLIC']++;
3445
+
3446
+    // fix #4235
3447
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3448
+
3449
+
3450
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3451
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3452
+
3453
+        $page = evaluer_fond($f, $contexte, $connect);
3454
+        if ($page === '') {
3455
+            $c = $options['compil'] ?? '';
3456
+            $a = ['fichier' => $f];
3457
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3458
+            erreur_squelette($erreur, $c);
3459
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3460
+            $page = ['texte' => '', 'erreur' => $erreur];
3461
+        }
3462
+
3463
+        $page = pipeline('recuperer_fond', [
3464
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3465
+            'data' => $page
3466
+        ]);
3467
+        if (isset($options['ajax']) and $options['ajax']) {
3468
+            if (!function_exists('encoder_contexte_ajax')) {
3469
+                include_spip('inc/filtres');
3470
+            }
3471
+            $page['texte'] = encoder_contexte_ajax(
3472
+                array_merge(
3473
+                    $contexte,
3474
+                    ['fond' => $f],
3475
+                    ($connect ? ['connect' => $connect] : [])
3476
+                ),
3477
+                '',
3478
+                $page['texte'],
3479
+                $options['ajax']
3480
+            );
3481
+        }
3482
+
3483
+        if (isset($options['raw']) and $options['raw']) {
3484
+            $pages[] = $page;
3485
+        } else {
3486
+            $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3487
+        }
3488
+
3489
+        // contamination de la session appelante, pour les inclusions statiques
3490
+        if (isset($page['invalideurs']['session'])) {
3491
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3492
+        }
3493
+    }
3494
+
3495
+    // restaurer le sessionnement du contexte appelant,
3496
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3497
+    if (isset($cache_utilise_session_appelant)) {
3498
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3499
+    }
3500
+
3501
+    $GLOBALS['_INC_PUBLIC']--;
3502
+
3503
+    if ($lang_select) {
3504
+        lang_select();
3505
+    }
3506
+    if (isset($options['raw']) and $options['raw']) {
3507
+        return is_array($fond) ? $pages : reset($pages);
3508
+    } else {
3509
+        return $options['trim'] ? ltrim($texte) : $texte;
3510
+    }
3512 3511
 }
3513 3512
 
3514 3513
 /**
@@ -3518,7 +3517,7 @@  discard block
 block discarded – undo
3518 3517
  * @return string
3519 3518
  */
3520 3519
 function trouve_modele($nom) {
3521
-	return trouver_fond($nom, 'modeles/');
3520
+    return trouver_fond($nom, 'modeles/');
3522 3521
 }
3523 3522
 
3524 3523
 /**
@@ -3534,21 +3533,21 @@  discard block
 block discarded – undo
3534 3533
  * @return array|string
3535 3534
  */
3536 3535
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3537
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3538
-	if (!$pathinfo) {
3539
-		return $f;
3540
-	}
3541
-	// renvoyer un tableau detaille si $pathinfo==true
3542
-	$p = pathinfo($f);
3543
-	if (!isset($p['extension']) or !$p['extension']) {
3544
-		$p['extension'] = _EXTENSION_SQUELETTES;
3545
-	}
3546
-	if (!isset($p['extension']) or !$p['filename']) {
3547
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3548
-	}
3549
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3536
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3537
+    if (!$pathinfo) {
3538
+        return $f;
3539
+    }
3540
+    // renvoyer un tableau detaille si $pathinfo==true
3541
+    $p = pathinfo($f);
3542
+    if (!isset($p['extension']) or !$p['extension']) {
3543
+        $p['extension'] = _EXTENSION_SQUELETTES;
3544
+    }
3545
+    if (!isset($p['extension']) or !$p['filename']) {
3546
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3547
+    }
3548
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3550 3549
 
3551
-	return $p;
3550
+    return $p;
3552 3551
 }
3553 3552
 
3554 3553
 /**
@@ -3568,21 +3567,21 @@  discard block
 block discarded – undo
3568 3567
  *     Nom de l'exec, sinon chaîne vide.
3569 3568
  **/
3570 3569
 function tester_url_ecrire($nom) {
3571
-	static $exec = [];
3572
-	if (isset($exec[$nom])) {
3573
-		return $exec[$nom];
3574
-	}
3575
-	// tester si c'est une page en squelette
3576
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3577
-		return $exec[$nom] = 'fond';
3578
-	} // echafaudage d'un fond !
3579
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3580
-		return $exec[$nom] = 'fond';
3581
-	}
3582
-	// attention, il ne faut pas inclure l'exec ici
3583
-	// car sinon #URL_ECRIRE provoque des inclusions
3584
-	// et des define intrusifs potentiels
3585
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3570
+    static $exec = [];
3571
+    if (isset($exec[$nom])) {
3572
+        return $exec[$nom];
3573
+    }
3574
+    // tester si c'est une page en squelette
3575
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3576
+        return $exec[$nom] = 'fond';
3577
+    } // echafaudage d'un fond !
3578
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3579
+        return $exec[$nom] = 'fond';
3580
+    }
3581
+    // attention, il ne faut pas inclure l'exec ici
3582
+    // car sinon #URL_ECRIRE provoque des inclusions
3583
+    // et des define intrusifs potentiels
3584
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3586 3585
 }
3587 3586
 
3588 3587
 /**
@@ -3592,8 +3591,8 @@  discard block
 block discarded – undo
3592 3591
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3593 3592
  **/
3594 3593
 function html5_permis() {
3595
-	return (!defined('_VERSION_HTML')
3596
-		or _VERSION_HTML !== 'html4');
3594
+    return (!defined('_VERSION_HTML')
3595
+        or _VERSION_HTML !== 'html4');
3597 3596
 }
3598 3597
 
3599 3598
 /**
@@ -3603,30 +3602,30 @@  discard block
 block discarded – undo
3603 3602
  * @return array
3604 3603
  */
3605 3604
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3606
-	$formats = null;
3607
-	if (!is_null($gd)) {
3608
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3609
-		if (isset($GLOBALS['meta'][$config])) {
3610
-			$formats = $GLOBALS['meta'][$config];
3611
-			$formats = explode(',', $formats);
3612
-			$formats = array_filter($formats);
3613
-			$formats = array_map('trim', $formats);
3614
-		}
3615
-	}
3616
-	if (is_null($formats)) {
3617
-		include_spip('inc/filtres_images_lib_mini');
3618
-		$formats = _image_extensions_acceptees_en_entree();
3619
-	}
3620
-
3621
-	if ($svg_allowed) {
3622
-		if (!in_array('svg', $formats)) {
3623
-			$formats[] = 'svg';
3624
-		}
3625
-	}
3626
-	else {
3627
-		$formats = array_diff($formats, ['svg']);
3628
-	}
3629
-	return $formats;
3605
+    $formats = null;
3606
+    if (!is_null($gd)) {
3607
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3608
+        if (isset($GLOBALS['meta'][$config])) {
3609
+            $formats = $GLOBALS['meta'][$config];
3610
+            $formats = explode(',', $formats);
3611
+            $formats = array_filter($formats);
3612
+            $formats = array_map('trim', $formats);
3613
+        }
3614
+    }
3615
+    if (is_null($formats)) {
3616
+        include_spip('inc/filtres_images_lib_mini');
3617
+        $formats = _image_extensions_acceptees_en_entree();
3618
+    }
3619
+
3620
+    if ($svg_allowed) {
3621
+        if (!in_array('svg', $formats)) {
3622
+            $formats[] = 'svg';
3623
+        }
3624
+    }
3625
+    else {
3626
+        $formats = array_diff($formats, ['svg']);
3627
+    }
3628
+    return $formats;
3630 3629
 }
3631 3630
 
3632 3631
 /**
@@ -3635,20 +3634,20 @@  discard block
 block discarded – undo
3635 3634
  * @return array|bool
3636 3635
  */
3637 3636
 function spip_getimagesize($fichier) {
3638
-	if (!$imagesize = @getimagesize($fichier)) {
3639
-		include_spip('inc/svg');
3640
-		if ($attrs = svg_lire_attributs($fichier)) {
3641
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3642
-			$imagesize = [
3643
-				$width,
3644
-				$height,
3645
-				IMAGETYPE_SVG,
3646
-				"width=\"{$width}\" height=\"{$height}\"",
3647
-				'mime' => 'image/svg+xml'
3648
-			];
3649
-		}
3650
-	}
3651
-	return $imagesize;
3637
+    if (!$imagesize = @getimagesize($fichier)) {
3638
+        include_spip('inc/svg');
3639
+        if ($attrs = svg_lire_attributs($fichier)) {
3640
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3641
+            $imagesize = [
3642
+                $width,
3643
+                $height,
3644
+                IMAGETYPE_SVG,
3645
+                "width=\"{$width}\" height=\"{$height}\"",
3646
+                'mime' => 'image/svg+xml'
3647
+            ];
3648
+        }
3649
+    }
3650
+    return $imagesize;
3652 3651
 }
3653 3652
 
3654 3653
 /**
@@ -3662,19 +3661,19 @@  discard block
 block discarded – undo
3662 3661
  * @param string $statut
3663 3662
  */
3664 3663
 function avertir_auteurs($nom, $message, $statut = '') {
3665
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3666
-	if (
3667
-		!$alertes
3668
-		or !is_array($alertes = unserialize($alertes))
3669
-	) {
3670
-		$alertes = [];
3671
-	}
3664
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3665
+    if (
3666
+        !$alertes
3667
+        or !is_array($alertes = unserialize($alertes))
3668
+    ) {
3669
+        $alertes = [];
3670
+    }
3672 3671
 
3673
-	if (!isset($alertes[$statut])) {
3674
-		$alertes[$statut] = [];
3675
-	}
3676
-	$alertes[$statut][$nom] = $message;
3677
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3672
+    if (!isset($alertes[$statut])) {
3673
+        $alertes[$statut] = [];
3674
+    }
3675
+    $alertes[$statut][$nom] = $message;
3676
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3678 3677
 }
3679 3678
 
3680 3679
 /**
@@ -3688,10 +3687,10 @@  discard block
 block discarded – undo
3688 3687
  * @return string|string[]
3689 3688
  */
3690 3689
 function spip_sanitize_classname($classes) {
3691
-	if (is_array($classes)) {
3692
-		return array_map('spip_sanitize_classname', $classes);
3693
-	}
3694
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3690
+    if (is_array($classes)) {
3691
+        return array_map('spip_sanitize_classname', $classes);
3692
+    }
3693
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3695 3694
 }
3696 3695
 
3697 3696
 
@@ -3716,32 +3715,32 @@  discard block
 block discarded – undo
3716 3715
  *    Avec operateur : bool.
3717 3716
  **/
3718 3717
 function spip_version_compare($v1, $v2, $op = null) {
3719
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3720
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3721
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3722
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3723
-
3724
-	$v1 = explode('.', $v1);
3725
-	$v2 = explode('.', $v2);
3726
-	// $v1 est toujours une version, donc sans etoile
3727
-	while (count($v1) < count($v2)) {
3728
-		$v1[] = '0';
3729
-	}
3730
-
3731
-	// $v2 peut etre une borne, donc accepte l'etoile
3732
-	$etoile = false;
3733
-	foreach ($v1 as $k => $v) {
3734
-		if (!isset($v2[$k])) {
3735
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3736
-		} else {
3737
-			if ($v2[$k] == '*') {
3738
-				$etoile = true;
3739
-				$v2[$k] = $v;
3740
-			}
3741
-		}
3742
-	}
3743
-	$v1 = implode('.', $v1);
3744
-	$v2 = implode('.', $v2);
3745
-
3746
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3718
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3719
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3720
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3721
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3722
+
3723
+    $v1 = explode('.', $v1);
3724
+    $v2 = explode('.', $v2);
3725
+    // $v1 est toujours une version, donc sans etoile
3726
+    while (count($v1) < count($v2)) {
3727
+        $v1[] = '0';
3728
+    }
3729
+
3730
+    // $v2 peut etre une borne, donc accepte l'etoile
3731
+    $etoile = false;
3732
+    foreach ($v1 as $k => $v) {
3733
+        if (!isset($v2[$k])) {
3734
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3735
+        } else {
3736
+            if ($v2[$k] == '*') {
3737
+                $etoile = true;
3738
+                $v2[$k] = $v;
3739
+            }
3740
+        }
3741
+    }
3742
+    $v1 = implode('.', $v1);
3743
+    $v2 = implode('.', $v2);
3744
+
3745
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3747 3746
 }
Please login to merge, or discard this patch.