Completed
Push — master ( df46b5...c667cf )
by cam
01:01
created
ecrire/inc/utils.php 1 patch
Indentation   +2266 added lines, -2267 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,78 +1423,78 @@  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
 
1441 1440
 function lister_themes_prives() {
1442
-	static $themes = null;
1443
-	if (is_null($themes)) {
1444
-		// si pas encore definie
1445
-		if (!defined('_SPIP_THEME_PRIVE')) {
1446
-			define('_SPIP_THEME_PRIVE', 'spip');
1447
-		}
1448
-		$themes = [_SPIP_THEME_PRIVE];
1449
-		// lors d'une installation neuve, prefs n'est pas definie.
1450
-		if (isset($GLOBALS['visiteur_session']['prefs'])) {
1451
-			$prefs = $GLOBALS['visiteur_session']['prefs'];
1452
-		} else {
1453
-			$prefs = [];
1454
-		}
1455
-		if (is_string($prefs)) {
1456
-			$prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1457
-		}
1458
-		if (
1459
-			((isset($prefs['theme']) and $theme = $prefs['theme'])
1460
-				or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1461
-			and $theme != _SPIP_THEME_PRIVE
1462
-		) {
1463
-			array_unshift($themes, $theme);
1464
-		} // placer le theme choisi en tete
1465
-	}
1466
-
1467
-	return $themes;
1441
+    static $themes = null;
1442
+    if (is_null($themes)) {
1443
+        // si pas encore definie
1444
+        if (!defined('_SPIP_THEME_PRIVE')) {
1445
+            define('_SPIP_THEME_PRIVE', 'spip');
1446
+        }
1447
+        $themes = [_SPIP_THEME_PRIVE];
1448
+        // lors d'une installation neuve, prefs n'est pas definie.
1449
+        if (isset($GLOBALS['visiteur_session']['prefs'])) {
1450
+            $prefs = $GLOBALS['visiteur_session']['prefs'];
1451
+        } else {
1452
+            $prefs = [];
1453
+        }
1454
+        if (is_string($prefs)) {
1455
+            $prefs = unserialize($GLOBALS['visiteur_session']['prefs']);
1456
+        }
1457
+        if (
1458
+            ((isset($prefs['theme']) and $theme = $prefs['theme'])
1459
+                or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut']))
1460
+            and $theme != _SPIP_THEME_PRIVE
1461
+        ) {
1462
+            array_unshift($themes, $theme);
1463
+        } // placer le theme choisi en tete
1464
+    }
1465
+
1466
+    return $themes;
1468 1467
 }
1469 1468
 
1470 1469
 function find_in_theme($file, $subdir = '', $include = false) {
1471
-	static $themefiles = [];
1472
-	if (isset($themefiles["$subdir$file"])) {
1473
-		return $themefiles["$subdir$file"];
1474
-	}
1475
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1476
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1477
-	if (
1478
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1479
-		and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1480
-		and $f = find_in_theme("$file_svg_generique")
1481
-	) {
1482
-		if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1483
-			return $themefiles["$subdir$file"] = $fsize;
1484
-		}
1485
-		else {
1486
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1487
-		}
1488
-	}
1489
-
1490
-	$themes = lister_themes_prives();
1491
-	foreach ($themes as $theme) {
1492
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1493
-			return $themefiles["$subdir$file"] = $f;
1494
-		}
1495
-	}
1496
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1497
-
1498
-	return $themefiles["$subdir$file"] = '';
1470
+    static $themefiles = [];
1471
+    if (isset($themefiles["$subdir$file"])) {
1472
+        return $themefiles["$subdir$file"];
1473
+    }
1474
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1475
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1476
+    if (
1477
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1478
+        and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg'
1479
+        and $f = find_in_theme("$file_svg_generique")
1480
+    ) {
1481
+        if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) {
1482
+            return $themefiles["$subdir$file"] = $fsize;
1483
+        }
1484
+        else {
1485
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1486
+        }
1487
+    }
1488
+
1489
+    $themes = lister_themes_prives();
1490
+    foreach ($themes as $theme) {
1491
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1492
+            return $themefiles["$subdir$file"] = $f;
1493
+        }
1494
+    }
1495
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1496
+
1497
+    return $themefiles["$subdir$file"] = '';
1499 1498
 }
1500 1499
 
1501 1500
 
@@ -1519,31 +1518,31 @@  discard block
 block discarded – undo
1519 1518
  *     sinon chaîne vide.
1520 1519
  **/
1521 1520
 function chemin_image($icone) {
1522
-	static $icone_renommer;
1523
-	if ($p = strpos($icone, '?')) {
1524
-		$icone = substr($icone, 0, $p);
1525
-	}
1526
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1527
-	if (strpos($icone, '/') !== false and file_exists($icone)) {
1528
-		return $icone;
1529
-	}
1530
-
1531
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1532
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1533
-		return $f;
1534
-	}
1535
-	// sinon passer par le module de renommage
1536
-	if (is_null($icone_renommer)) {
1537
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1538
-	}
1539
-	if ($icone_renommer) {
1540
-		[$icone, $fonction] = $icone_renommer($icone, '');
1541
-		if (file_exists($icone)) {
1542
-			return $icone;
1543
-		}
1544
-	}
1545
-
1546
-	return find_in_path($icone, _NOM_IMG_PACK);
1521
+    static $icone_renommer;
1522
+    if ($p = strpos($icone, '?')) {
1523
+        $icone = substr($icone, 0, $p);
1524
+    }
1525
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1526
+    if (strpos($icone, '/') !== false and file_exists($icone)) {
1527
+        return $icone;
1528
+    }
1529
+
1530
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1531
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) {
1532
+        return $f;
1533
+    }
1534
+    // sinon passer par le module de renommage
1535
+    if (is_null($icone_renommer)) {
1536
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1537
+    }
1538
+    if ($icone_renommer) {
1539
+        [$icone, $fonction] = $icone_renommer($icone, '');
1540
+        if (file_exists($icone)) {
1541
+            return $icone;
1542
+        }
1543
+    }
1544
+
1545
+    return find_in_path($icone, _NOM_IMG_PACK);
1547 1546
 }
1548 1547
 
1549 1548
 //
@@ -1581,128 +1580,128 @@  discard block
 block discarded – undo
1581 1580
  *     - false : fichier introuvable
1582 1581
  **/
1583 1582
 function find_in_path($file, $dirname = '', $include = false) {
1584
-	static $dirs = [];
1585
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1586
-	static $c = '';
1587
-
1588
-	if (!$file and !strlen($file)) {
1589
-		return false;
1590
-	}
1591
-
1592
-	// on calcule le chemin si le dossier skel a change
1593
-	if ($c != $GLOBALS['dossier_squelettes']) {
1594
-		// assurer le non plantage lors de la montee de version :
1595
-		$c = $GLOBALS['dossier_squelettes'];
1596
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1597
-	}
1598
-
1599
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1600
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1601
-			return false;
1602
-		}
1603
-		if ($include and !isset($inc[$dirname][$file])) {
1604
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1605
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1606
-		}
1607
-
1608
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1609
-	}
1610
-
1611
-	$a = strrpos($file, '/');
1612
-	if ($a !== false) {
1613
-		$dirname .= substr($file, 0, ++$a);
1614
-		$file = substr($file, $a);
1615
-	}
1616
-
1617
-	foreach (creer_chemin() as $dir) {
1618
-		if (!isset($dirs[$a = $dir . $dirname])) {
1619
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1620
-		}
1621
-		if ($dirs[$a]) {
1622
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1623
-				if ($include and !isset($inc[$dirname][$file])) {
1624
-					include_once _ROOT_CWD . $a;
1625
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1626
-				}
1627
-				if (!defined('_SAUVER_CHEMIN')) {
1628
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1629
-					if (is_null($GLOBALS['path_files'])) {
1630
-						return $a;
1631
-					}
1632
-					define('_SAUVER_CHEMIN', true);
1633
-				}
1634
-
1635
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1636
-			}
1637
-		}
1638
-	}
1639
-
1640
-	if ($include) {
1641
-		spip_log("include_spip $dirname$file non trouve");
1642
-		if ($include === 'required') {
1643
-			echo '<pre>',
1644
-			'<strong>Erreur Fatale</strong><br />';
1645
-			if (function_exists('debug_print_backtrace')) {
1646
-				echo debug_print_backtrace();
1647
-			}
1648
-			echo '</pre>';
1649
-			die("Erreur interne: ne peut inclure $dirname$file");
1650
-		}
1651
-	}
1652
-
1653
-	if (!defined('_SAUVER_CHEMIN')) {
1654
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1655
-		if (is_null($GLOBALS['path_files'])) {
1656
-			return false;
1657
-		}
1658
-		define('_SAUVER_CHEMIN', true);
1659
-	}
1660
-
1661
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1583
+    static $dirs = [];
1584
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1585
+    static $c = '';
1586
+
1587
+    if (!$file and !strlen($file)) {
1588
+        return false;
1589
+    }
1590
+
1591
+    // on calcule le chemin si le dossier skel a change
1592
+    if ($c != $GLOBALS['dossier_squelettes']) {
1593
+        // assurer le non plantage lors de la montee de version :
1594
+        $c = $GLOBALS['dossier_squelettes'];
1595
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1596
+    }
1597
+
1598
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1599
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1600
+            return false;
1601
+        }
1602
+        if ($include and !isset($inc[$dirname][$file])) {
1603
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1604
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1605
+        }
1606
+
1607
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1608
+    }
1609
+
1610
+    $a = strrpos($file, '/');
1611
+    if ($a !== false) {
1612
+        $dirname .= substr($file, 0, ++$a);
1613
+        $file = substr($file, $a);
1614
+    }
1615
+
1616
+    foreach (creer_chemin() as $dir) {
1617
+        if (!isset($dirs[$a = $dir . $dirname])) {
1618
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1619
+        }
1620
+        if ($dirs[$a]) {
1621
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1622
+                if ($include and !isset($inc[$dirname][$file])) {
1623
+                    include_once _ROOT_CWD . $a;
1624
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1625
+                }
1626
+                if (!defined('_SAUVER_CHEMIN')) {
1627
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1628
+                    if (is_null($GLOBALS['path_files'])) {
1629
+                        return $a;
1630
+                    }
1631
+                    define('_SAUVER_CHEMIN', true);
1632
+                }
1633
+
1634
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1635
+            }
1636
+        }
1637
+    }
1638
+
1639
+    if ($include) {
1640
+        spip_log("include_spip $dirname$file non trouve");
1641
+        if ($include === 'required') {
1642
+            echo '<pre>',
1643
+            '<strong>Erreur Fatale</strong><br />';
1644
+            if (function_exists('debug_print_backtrace')) {
1645
+                echo debug_print_backtrace();
1646
+            }
1647
+            echo '</pre>';
1648
+            die("Erreur interne: ne peut inclure $dirname$file");
1649
+        }
1650
+    }
1651
+
1652
+    if (!defined('_SAUVER_CHEMIN')) {
1653
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1654
+        if (is_null($GLOBALS['path_files'])) {
1655
+            return false;
1656
+        }
1657
+        define('_SAUVER_CHEMIN', true);
1658
+    }
1659
+
1660
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1662 1661
 }
1663 1662
 
1664 1663
 function clear_path_cache() {
1665
-	$GLOBALS['path_files'] = [];
1666
-	spip_unlink(_CACHE_CHEMIN);
1664
+    $GLOBALS['path_files'] = [];
1665
+    spip_unlink(_CACHE_CHEMIN);
1667 1666
 }
1668 1667
 
1669 1668
 function load_path_cache() {
1670
-	// charger le path des plugins
1671
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1672
-		include_once(_CACHE_PLUGINS_PATH);
1673
-	}
1674
-	$GLOBALS['path_files'] = [];
1675
-	// si le visiteur est admin,
1676
-	// on ne recharge pas le cache pour forcer sa mise a jour
1677
-	if (
1678
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1679
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1680
-		// utiliser le cookie est un pis aller qui marche 'en general'
1681
-		// on blinde par un second test au moment de la lecture de la session
1682
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1683
-		// et en ignorant ce cache en cas de recalcul explicite
1684
-		!_request('var_mode')
1685
-	) {
1686
-		// on essaye de lire directement sans verrou pour aller plus vite
1687
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1688
-			// mais si semble corrompu on relit avec un verrou
1689
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1690
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1691
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1692
-					$GLOBALS['path_files'] = [];
1693
-				}
1694
-			}
1695
-		}
1696
-	}
1669
+    // charger le path des plugins
1670
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1671
+        include_once(_CACHE_PLUGINS_PATH);
1672
+    }
1673
+    $GLOBALS['path_files'] = [];
1674
+    // si le visiteur est admin,
1675
+    // on ne recharge pas le cache pour forcer sa mise a jour
1676
+    if (
1677
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1678
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1679
+        // utiliser le cookie est un pis aller qui marche 'en general'
1680
+        // on blinde par un second test au moment de la lecture de la session
1681
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1682
+        // et en ignorant ce cache en cas de recalcul explicite
1683
+        !_request('var_mode')
1684
+    ) {
1685
+        // on essaye de lire directement sans verrou pour aller plus vite
1686
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1687
+            // mais si semble corrompu on relit avec un verrou
1688
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1689
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1690
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1691
+                    $GLOBALS['path_files'] = [];
1692
+                }
1693
+            }
1694
+        }
1695
+    }
1697 1696
 }
1698 1697
 
1699 1698
 function save_path_cache() {
1700
-	if (
1701
-		defined('_SAUVER_CHEMIN')
1702
-		and _SAUVER_CHEMIN
1703
-	) {
1704
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1705
-	}
1699
+    if (
1700
+        defined('_SAUVER_CHEMIN')
1701
+        and _SAUVER_CHEMIN
1702
+    ) {
1703
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1704
+    }
1706 1705
 }
1707 1706
 
1708 1707
 
@@ -1722,33 +1721,33 @@  discard block
 block discarded – undo
1722 1721
  * @return array
1723 1722
  */
1724 1723
 function find_all_in_path($dir, $pattern, $recurs = false) {
1725
-	$liste_fichiers = [];
1726
-	$maxfiles = 10000;
1727
-
1728
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1729
-	// on a pas encore inclus flock.php
1730
-	if (!function_exists('preg_files')) {
1731
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1732
-	}
1733
-
1734
-	// Parcourir le chemin
1735
-	foreach (creer_chemin() as $d) {
1736
-		$f = $d . $dir;
1737
-		if (@is_dir($f)) {
1738
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1739
-			foreach ($liste as $chemin) {
1740
-				$nom = basename($chemin);
1741
-				// ne prendre que les fichiers pas deja trouves
1742
-				// car find_in_path prend le premier qu'il trouve,
1743
-				// les autres sont donc masques
1744
-				if (!isset($liste_fichiers[$nom])) {
1745
-					$liste_fichiers[$nom] = $chemin;
1746
-				}
1747
-			}
1748
-		}
1749
-	}
1750
-
1751
-	return $liste_fichiers;
1724
+    $liste_fichiers = [];
1725
+    $maxfiles = 10000;
1726
+
1727
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1728
+    // on a pas encore inclus flock.php
1729
+    if (!function_exists('preg_files')) {
1730
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1731
+    }
1732
+
1733
+    // Parcourir le chemin
1734
+    foreach (creer_chemin() as $d) {
1735
+        $f = $d . $dir;
1736
+        if (@is_dir($f)) {
1737
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1738
+            foreach ($liste as $chemin) {
1739
+                $nom = basename($chemin);
1740
+                // ne prendre que les fichiers pas deja trouves
1741
+                // car find_in_path prend le premier qu'il trouve,
1742
+                // les autres sont donc masques
1743
+                if (!isset($liste_fichiers[$nom])) {
1744
+                    $liste_fichiers[$nom] = $chemin;
1745
+                }
1746
+            }
1747
+        }
1748
+    }
1749
+
1750
+    return $liste_fichiers;
1752 1751
 }
1753 1752
 
1754 1753
 /**
@@ -1760,17 +1759,17 @@  discard block
 block discarded – undo
1760 1759
  * @return bool
1761 1760
  */
1762 1761
 function autoriser_sans_cookie($nom, $strict = false) {
1763
-	static $autsanscookie = ['install', 'base_repair'];
1762
+    static $autsanscookie = ['install', 'base_repair'];
1764 1763
 
1765
-	if (in_array($nom, $autsanscookie)) {
1766
-		if (test_espace_prive()) {
1767
-			include_spip('base/connect_sql');
1768
-			if (!$strict or !spip_connect()) {
1769
-				return true;
1770
-			}
1771
-		}
1772
-	}
1773
-	return false;
1764
+    if (in_array($nom, $autsanscookie)) {
1765
+        if (test_espace_prive()) {
1766
+            include_spip('base/connect_sql');
1767
+            if (!$strict or !spip_connect()) {
1768
+                return true;
1769
+            }
1770
+        }
1771
+    }
1772
+    return false;
1774 1773
 }
1775 1774
 
1776 1775
 /**
@@ -1780,60 +1779,60 @@  discard block
 block discarded – undo
1780 1779
  * @return string
1781 1780
  */
1782 1781
 function charger_fonction_url(string $quoi, string $type = '') {
1783
-	if ($type === 'defaut') {
1784
-		$objet = objet_type($quoi);
1785
-		if (
1786
-			$f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1787
-			// deprecated
1788
-			or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1789
-		) {
1790
-			return $f;
1791
-		}
1792
-		return '';
1793
-	}
1794
-
1795
-	$url_type = $type;
1796
-	if (!$url_type) {
1797
-		$url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1798
-	}
1799
-
1800
-	// inclure le module d'url
1801
-	include_spip('urls/' . $url_type);
1802
-
1803
-	switch ($quoi) {
1804
-		case 'page':
1805
-			if (
1806
-				 function_exists($f = "urls_{$url_type}_generer_url_page")
1807
-				or function_exists($f .= '_dist')
1808
-				// ou une fonction custom utilisateur independante du type d'url
1809
-				or function_exists($f = 'generer_url_page')
1810
-				or function_exists($f .= '_dist')
1811
-			) {
1812
-				return $f;
1813
-			}
1814
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1815
-			return '';
1816
-		case 'objet':
1817
-		case 'decoder':
1818
-		default:
1819
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1820
-			if (
1821
-				function_exists($f = "urls_{$url_type}_{$fquoi}")
1822
-				or function_exists($f .= '_dist')
1823
-			) {
1824
-				return $f;
1825
-			}
1826
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1827
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1828
-			if ($f = charger_fonction($url_type, 'urls', true)) {
1829
-				return $f;
1830
-			}
1831
-			// sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1832
-			if (!$type and $url_type !== 'page') {
1833
-				return charger_fonction_url($quoi, 'page');
1834
-			}
1835
-			return '';
1836
-	}
1782
+    if ($type === 'defaut') {
1783
+        $objet = objet_type($quoi);
1784
+        if (
1785
+            $f = charger_fonction('generer_' . $objet . '_url', 'urls', true)
1786
+            // deprecated
1787
+            or $f = charger_fonction('generer_url_' . $objet, 'urls', true)
1788
+        ) {
1789
+            return $f;
1790
+        }
1791
+        return '';
1792
+    }
1793
+
1794
+    $url_type = $type;
1795
+    if (!$url_type) {
1796
+        $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1797
+    }
1798
+
1799
+    // inclure le module d'url
1800
+    include_spip('urls/' . $url_type);
1801
+
1802
+    switch ($quoi) {
1803
+        case 'page':
1804
+            if (
1805
+                    function_exists($f = "urls_{$url_type}_generer_url_page")
1806
+                or function_exists($f .= '_dist')
1807
+                // ou une fonction custom utilisateur independante du type d'url
1808
+                or function_exists($f = 'generer_url_page')
1809
+                or function_exists($f .= '_dist')
1810
+            ) {
1811
+                return $f;
1812
+            }
1813
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1814
+            return '';
1815
+        case 'objet':
1816
+        case 'decoder':
1817
+        default:
1818
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1819
+            if (
1820
+                function_exists($f = "urls_{$url_type}_{$fquoi}")
1821
+                or function_exists($f .= '_dist')
1822
+            ) {
1823
+                return $f;
1824
+            }
1825
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1826
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1827
+            if ($f = charger_fonction($url_type, 'urls', true)) {
1828
+                return $f;
1829
+            }
1830
+            // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1831
+            if (!$type and $url_type !== 'page') {
1832
+                return charger_fonction_url($quoi, 'page');
1833
+            }
1834
+            return '';
1835
+    }
1837 1836
 }
1838 1837
 
1839 1838
 
@@ -1859,48 +1858,48 @@  discard block
 block discarded – undo
1859 1858
  *   url codee ou fonction de decodage
1860 1859
  */
1861 1860
 function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1862
-	if ($public === null) {
1863
-		$public = !test_espace_prive();
1864
-	}
1865
-	$id = intval($id);
1866
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1867
-
1868
-	if (!$public) {
1869
-		if (!$entite) {
1870
-			return '';
1871
-		}
1872
-		if (!function_exists('generer_objet_url_ecrire')) {
1873
-			include_spip('inc/urls');
1874
-		}
1875
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1876
-	} else {
1877
-		$f = charger_fonction_url('objet', $type ?? '');
1878
-
1879
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
1880
-		// @see charger_fonction_url
1881
-		if (!$entite) {
1882
-			return $f;
1883
-		}
1884
-
1885
-		// mais d'abord il faut tester le cas des urls sur une
1886
-		// base distante
1887
-		if (
1888
-			$connect
1889
-			and $g = charger_fonction('connect', 'urls', true)
1890
-		) {
1891
-			$f = $g;
1892
-		}
1893
-
1894
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1895
-	}
1896
-	if ($res) {
1897
-		return $res;
1898
-	}
1899
-
1900
-	// On a ete gentil mais la ....
1901
-	spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1902
-
1903
-	return '';
1861
+    if ($public === null) {
1862
+        $public = !test_espace_prive();
1863
+    }
1864
+    $id = intval($id);
1865
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1866
+
1867
+    if (!$public) {
1868
+        if (!$entite) {
1869
+            return '';
1870
+        }
1871
+        if (!function_exists('generer_objet_url_ecrire')) {
1872
+            include_spip('inc/urls');
1873
+        }
1874
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1875
+    } else {
1876
+        $f = charger_fonction_url('objet', $type ?? '');
1877
+
1878
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
1879
+        // @see charger_fonction_url
1880
+        if (!$entite) {
1881
+            return $f;
1882
+        }
1883
+
1884
+        // mais d'abord il faut tester le cas des urls sur une
1885
+        // base distante
1886
+        if (
1887
+            $connect
1888
+            and $g = charger_fonction('connect', 'urls', true)
1889
+        ) {
1890
+            $f = $g;
1891
+        }
1892
+
1893
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1894
+    }
1895
+    if ($res) {
1896
+        return $res;
1897
+    }
1898
+
1899
+    // On a ete gentil mais la ....
1900
+    spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR);
1901
+
1902
+    return '';
1904 1903
 }
1905 1904
 
1906 1905
 /**
@@ -1908,10 +1907,10 @@  discard block
 block discarded – undo
1908 1907
  * @see generer_objet_url
1909 1908
  */
1910 1909
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1911
-	if ($public and is_string($public)) {
1912
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1913
-	}
1914
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1910
+    if ($public and is_string($public)) {
1911
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1912
+    }
1913
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1915 1914
 }
1916 1915
 
1917 1916
 /**
@@ -1923,19 +1922,19 @@  discard block
 block discarded – undo
1923 1922
  * @return string
1924 1923
  */
1925 1924
 function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string {
1926
-	$id = intval($id);
1927
-	$exec = objet_info($entite, 'url_edit');
1928
-	$url = generer_url_ecrire($exec, $args);
1929
-	if (intval($id)) {
1930
-		$url = parametre_url($url, id_table_objet($entite), $id);
1931
-	} else {
1932
-		$url = parametre_url($url, 'new', 'oui');
1933
-	}
1934
-	if ($ancre) {
1935
-		$url = ancre_url($url, $ancre);
1936
-	}
1925
+    $id = intval($id);
1926
+    $exec = objet_info($entite, 'url_edit');
1927
+    $url = generer_url_ecrire($exec, $args);
1928
+    if (intval($id)) {
1929
+        $url = parametre_url($url, id_table_objet($entite), $id);
1930
+    } else {
1931
+        $url = parametre_url($url, 'new', 'oui');
1932
+    }
1933
+    if ($ancre) {
1934
+        $url = ancre_url($url, $ancre);
1935
+    }
1937 1936
 
1938
-	return $url;
1937
+    return $url;
1939 1938
 }
1940 1939
 
1941 1940
 /**
@@ -1943,18 +1942,18 @@  discard block
 block discarded – undo
1943 1942
  * @see generer_objet_url_ecrire_edit
1944 1943
  */
1945 1944
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1946
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1945
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1947 1946
 }
1948 1947
 
1949 1948
 
1950 1949
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1951
-	include_spip('base/connect_sql');
1952
-	$id_type = id_table_objet($entite, $public);
1950
+    include_spip('base/connect_sql');
1951
+    $id_type = id_table_objet($entite, $public);
1953 1952
 
1954
-	return _DIR_RACINE . get_spip_script('./')
1955
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1956
-	. (!$args ? '' : "&$args")
1957
-	. (!$ancre ? '' : "#$ancre");
1953
+    return _DIR_RACINE . get_spip_script('./')
1954
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1955
+    . (!$args ? '' : "&$args")
1956
+    . (!$ancre ? '' : "#$ancre");
1958 1957
 }
1959 1958
 
1960 1959
 
@@ -1965,18 +1964,18 @@  discard block
 block discarded – undo
1965 1964
  * @return string
1966 1965
  */
1967 1966
 function urlencode_1738($url) {
1968
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
1969
-		$uri = '';
1970
-		for ($i = 0; $i < strlen($url); $i++) {
1971
-			if (ord($a = $url[$i]) > 127) {
1972
-				$a = rawurlencode($a);
1973
-			}
1974
-			$uri .= $a;
1975
-		}
1976
-		$url = $uri;
1977
-	}
1967
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1968
+        $uri = '';
1969
+        for ($i = 0; $i < strlen($url); $i++) {
1970
+            if (ord($a = $url[$i]) > 127) {
1971
+                $a = rawurlencode($a);
1972
+            }
1973
+            $uri .= $a;
1974
+        }
1975
+        $url = $uri;
1976
+    }
1978 1977
 
1979
-	return quote_amp($url);
1978
+    return quote_amp($url);
1980 1979
 }
1981 1980
 
1982 1981
 /**
@@ -1992,14 +1991,14 @@  discard block
 block discarded – undo
1992 1991
  * @return string
1993 1992
  */
1994 1993
 function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1995
-	$id = intval($id);
1996
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1997
-	if (!preg_match(',^\w+:,', $h)) {
1998
-		include_spip('inc/filtres_mini');
1999
-		$h = url_absolue($h);
2000
-	}
1994
+    $id = intval($id);
1995
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
1996
+    if (!preg_match(',^\w+:,', $h)) {
1997
+        include_spip('inc/filtres_mini');
1998
+        $h = url_absolue($h);
1999
+    }
2001 2000
 
2002
-	return $h;
2001
+    return $h;
2003 2002
 }
2004 2003
 
2005 2004
 /**
@@ -2007,7 +2006,7 @@  discard block
 block discarded – undo
2007 2006
  * @see  generer_objet_url_absolue
2008 2007
  */
2009 2008
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) {
2010
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
2009
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
2011 2010
 }
2012 2011
 
2013 2012
 
@@ -2023,11 +2022,11 @@  discard block
 block discarded – undo
2023 2022
  *     true si la valeur est considérée active ; false sinon.
2024 2023
  **/
2025 2024
 function test_valeur_serveur($truc) {
2026
-	if (!$truc) {
2027
-		return false;
2028
-	}
2025
+    if (!$truc) {
2026
+        return false;
2027
+    }
2029 2028
 
2030
-	return (strtolower($truc) !== 'off');
2029
+    return (strtolower($truc) !== 'off');
2031 2030
 }
2032 2031
 
2033 2032
 //
@@ -2055,89 +2054,89 @@  discard block
 block discarded – undo
2055 2054
  */
2056 2055
 function url_de_base($profondeur = null) {
2057 2056
 
2058
-	static $url = [];
2059
-	if (is_array($profondeur)) {
2060
-		return $url = $profondeur;
2061
-	}
2062
-	if ($profondeur === false) {
2063
-		return $url;
2064
-	}
2065
-
2066
-	if (is_null($profondeur)) {
2067
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2068
-	}
2069
-
2070
-	if (isset($url[$profondeur])) {
2071
-		return $url[$profondeur];
2072
-	}
2073
-
2074
-	$http = 'http';
2075
-
2076
-	if (
2077
-		isset($_SERVER['SCRIPT_URI'])
2078
-		and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2079
-	) {
2080
-		$http = 'https';
2081
-	} elseif (
2082
-		isset($_SERVER['HTTPS'])
2083
-		and test_valeur_serveur($_SERVER['HTTPS'])
2084
-	) {
2085
-		$http = 'https';
2086
-	}
2087
-
2088
-	// note : HTTP_HOST contient le :port si necessaire
2089
-	if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2090
-		// Filtrer $host pour proteger d'attaques d'entete HTTP
2091
-		$host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2092
-	}
2093
-
2094
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2095
-	if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2096
-		$host = $GLOBALS['meta']['adresse_site'];
2097
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2098
-			$http = $scheme;
2099
-			$host = str_replace("{$scheme}://", '', $host);
2100
-		}
2101
-	}
2102
-	if (
2103
-		isset($_SERVER['SERVER_PORT'])
2104
-		and $port = $_SERVER['SERVER_PORT']
2105
-		and strpos($host, ':') == false
2106
-	) {
2107
-		if (!defined('_PORT_HTTP_STANDARD')) {
2108
-			define('_PORT_HTTP_STANDARD', '80');
2109
-		}
2110
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2111
-			define('_PORT_HTTPS_STANDARD', '443');
2112
-		}
2113
-		if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2114
-			$host .= ":$port";
2115
-		}
2116
-		if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2117
-			$host .= ":$port";
2118
-		}
2119
-	}
2120
-
2121
-	if (!$GLOBALS['REQUEST_URI']) {
2122
-		if (isset($_SERVER['REQUEST_URI'])) {
2123
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2124
-		} else {
2125
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2126
-			if (
2127
-				!empty($_SERVER['QUERY_STRING'])
2128
-				and !strpos($_SERVER['REQUEST_URI'], '?')
2129
-			) {
2130
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2131
-			}
2132
-		}
2133
-	}
2134
-
2135
-	// Et nettoyer l'url
2136
-	$GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2137
-
2138
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2139
-
2140
-	return $url[$profondeur];
2057
+    static $url = [];
2058
+    if (is_array($profondeur)) {
2059
+        return $url = $profondeur;
2060
+    }
2061
+    if ($profondeur === false) {
2062
+        return $url;
2063
+    }
2064
+
2065
+    if (is_null($profondeur)) {
2066
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2067
+    }
2068
+
2069
+    if (isset($url[$profondeur])) {
2070
+        return $url[$profondeur];
2071
+    }
2072
+
2073
+    $http = 'http';
2074
+
2075
+    if (
2076
+        isset($_SERVER['SCRIPT_URI'])
2077
+        and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https'
2078
+    ) {
2079
+        $http = 'https';
2080
+    } elseif (
2081
+        isset($_SERVER['HTTPS'])
2082
+        and test_valeur_serveur($_SERVER['HTTPS'])
2083
+    ) {
2084
+        $http = 'https';
2085
+    }
2086
+
2087
+    // note : HTTP_HOST contient le :port si necessaire
2088
+    if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2089
+        // Filtrer $host pour proteger d'attaques d'entete HTTP
2090
+        $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2091
+    }
2092
+
2093
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2094
+    if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) {
2095
+        $host = $GLOBALS['meta']['adresse_site'];
2096
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2097
+            $http = $scheme;
2098
+            $host = str_replace("{$scheme}://", '', $host);
2099
+        }
2100
+    }
2101
+    if (
2102
+        isset($_SERVER['SERVER_PORT'])
2103
+        and $port = $_SERVER['SERVER_PORT']
2104
+        and strpos($host, ':') == false
2105
+    ) {
2106
+        if (!defined('_PORT_HTTP_STANDARD')) {
2107
+            define('_PORT_HTTP_STANDARD', '80');
2108
+        }
2109
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2110
+            define('_PORT_HTTPS_STANDARD', '443');
2111
+        }
2112
+        if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2113
+            $host .= ":$port";
2114
+        }
2115
+        if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2116
+            $host .= ":$port";
2117
+        }
2118
+    }
2119
+
2120
+    if (!$GLOBALS['REQUEST_URI']) {
2121
+        if (isset($_SERVER['REQUEST_URI'])) {
2122
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2123
+        } else {
2124
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2125
+            if (
2126
+                !empty($_SERVER['QUERY_STRING'])
2127
+                and !strpos($_SERVER['REQUEST_URI'], '?')
2128
+            ) {
2129
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2130
+            }
2131
+        }
2132
+    }
2133
+
2134
+    // Et nettoyer l'url
2135
+    $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2136
+
2137
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2138
+
2139
+    return $url[$profondeur];
2141 2140
 }
2142 2141
 
2143 2142
 /**
@@ -2150,26 +2149,26 @@  discard block
 block discarded – undo
2150 2149
  * @return string
2151 2150
  */
2152 2151
 function url_de_($http, $host, $request, $prof = 0) {
2153
-	$prof = max($prof, 0);
2152
+    $prof = max($prof, 0);
2154 2153
 
2155
-	$myself = ltrim($request, '/');
2156
-	# supprimer la chaine de GET
2157
-	[$myself] = explode('?', $myself);
2158
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2159
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2160
-	if (strpos($myself, '://') !== false) {
2161
-		$myself = explode('://', $myself);
2162
-		array_shift($myself);
2163
-		$myself = implode('://', $myself);
2164
-		$myself = explode('/', $myself);
2165
-		array_shift($myself);
2166
-		$myself = implode('/', $myself);
2167
-	}
2168
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2154
+    $myself = ltrim($request, '/');
2155
+    # supprimer la chaine de GET
2156
+    [$myself] = explode('?', $myself);
2157
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2158
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2159
+    if (strpos($myself, '://') !== false) {
2160
+        $myself = explode('://', $myself);
2161
+        array_shift($myself);
2162
+        $myself = implode('://', $myself);
2163
+        $myself = explode('/', $myself);
2164
+        array_shift($myself);
2165
+        $myself = implode('/', $myself);
2166
+    }
2167
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2169 2168
 
2170
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2169
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2171 2170
 
2172
-	return $url;
2171
+    return $url;
2173 2172
 }
2174 2173
 
2175 2174
 
@@ -2204,26 +2203,26 @@  discard block
 block discarded – undo
2204 2203
  * @return string URL
2205 2204
  **/
2206 2205
 function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) {
2207
-	$script ??= '';
2208
-	if (!$rel) {
2209
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2210
-	} else {
2211
-		if (!is_string($rel)) {
2212
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2213
-		}
2214
-	}
2215
-
2216
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2217
-	if ($script and ($script <> 'accueil' or $rel)) {
2218
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2219
-	} elseif ($args) {
2220
-		$args = "?$args";
2221
-	}
2222
-	if ($ancre) {
2223
-		$args .= "#$ancre";
2224
-	}
2225
-
2226
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2206
+    $script ??= '';
2207
+    if (!$rel) {
2208
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2209
+    } else {
2210
+        if (!is_string($rel)) {
2211
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2212
+        }
2213
+    }
2214
+
2215
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
2216
+    if ($script and ($script <> 'accueil' or $rel)) {
2217
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2218
+    } elseif ($args) {
2219
+        $args = "?$args";
2220
+    }
2221
+    if ($ancre) {
2222
+        $args .= "#$ancre";
2223
+    }
2224
+
2225
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2227 2226
 }
2228 2227
 
2229 2228
 //
@@ -2245,15 +2244,15 @@  discard block
 block discarded – undo
2245 2244
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2246 2245
  **/
2247 2246
 function get_spip_script($default = '') {
2248
-	if (!defined('_SPIP_SCRIPT')) {
2249
-		return 'spip.php';
2250
-	}
2251
-	# cas define('_SPIP_SCRIPT', '');
2252
-	if (_SPIP_SCRIPT) {
2253
-		return _SPIP_SCRIPT;
2254
-	} else {
2255
-		return $default;
2256
-	}
2247
+    if (!defined('_SPIP_SCRIPT')) {
2248
+        return 'spip.php';
2249
+    }
2250
+    # cas define('_SPIP_SCRIPT', '');
2251
+    if (_SPIP_SCRIPT) {
2252
+        return _SPIP_SCRIPT;
2253
+    } else {
2254
+        return $default;
2255
+    }
2257 2256
 }
2258 2257
 
2259 2258
 /**
@@ -2282,45 +2281,45 @@  discard block
 block discarded – undo
2282 2281
  * @return string URL
2283 2282
  **/
2284 2283
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2285
-	// si le script est une action (spip_pass, spip_inscription),
2286
-	// standardiser vers la nouvelle API
2287
-
2288
-	if (is_array($args)) {
2289
-		$args = http_build_query($args);
2290
-	}
2291
-
2292
-	$url = '';
2293
-	if ($f = charger_fonction_url('page')) {
2294
-		$url = $f($script, $args);
2295
-		if ($url and !$rel) {
2296
-			include_spip('inc/filtres_mini');
2297
-			$url = url_absolue($url);
2298
-		}
2299
-	}
2300
-	if (!$url) {
2301
-		if (!$action) {
2302
-			$action = get_spip_script();
2303
-		}
2304
-		if ($script) {
2305
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2306
-		}
2307
-		if ($args) {
2308
-			$action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2309
-		}
2310
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2311
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2312
-	}
2313
-
2314
-	if (!$no_entities) {
2315
-		$url = quote_amp($url);
2316
-	}
2317
-
2318
-	return $url;
2284
+    // si le script est une action (spip_pass, spip_inscription),
2285
+    // standardiser vers la nouvelle API
2286
+
2287
+    if (is_array($args)) {
2288
+        $args = http_build_query($args);
2289
+    }
2290
+
2291
+    $url = '';
2292
+    if ($f = charger_fonction_url('page')) {
2293
+        $url = $f($script, $args);
2294
+        if ($url and !$rel) {
2295
+            include_spip('inc/filtres_mini');
2296
+            $url = url_absolue($url);
2297
+        }
2298
+    }
2299
+    if (!$url) {
2300
+        if (!$action) {
2301
+            $action = get_spip_script();
2302
+        }
2303
+        if ($script) {
2304
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2305
+        }
2306
+        if ($args) {
2307
+            $action .= (strpos($action, '?') !== false ? '&' : '?') . $args;
2308
+        }
2309
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2310
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2311
+    }
2312
+
2313
+    if (!$no_entities) {
2314
+        $url = quote_amp($url);
2315
+    }
2316
+
2317
+    return $url;
2319 2318
 }
2320 2319
 
2321 2320
 function generer_url_prive($script, $args = '', $no_entities = false) {
2322 2321
 
2323
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2322
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2324 2323
 }
2325 2324
 
2326 2325
 // Pour les formulaires en methode POST,
@@ -2345,19 +2344,19 @@  discard block
 block discarded – undo
2345 2344
  **/
2346 2345
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2347 2346
 
2348
-	$script1 = explode('&', $script);
2349
-	$script1 = reset($script1);
2347
+    $script1 = explode('&', $script);
2348
+    $script1 = reset($script1);
2350 2349
 
2351
-	return "<form action='"
2352
-	. ($script ? generer_url_ecrire($script) : '')
2353
-	. "' "
2354
-	. ($atts ?: " method='post'")
2355
-	. "><div>\n"
2356
-	. "<input type='hidden' name='exec' value='$script1' />"
2357
-	. $corps
2358
-	. (!$submit ? '' :
2359
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2360
-	. "</div></form>\n";
2350
+    return "<form action='"
2351
+    . ($script ? generer_url_ecrire($script) : '')
2352
+    . "' "
2353
+    . ($atts ?: " method='post'")
2354
+    . "><div>\n"
2355
+    . "<input type='hidden' name='exec' value='$script1' />"
2356
+    . $corps
2357
+    . (!$submit ? '' :
2358
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2359
+    . "</div></form>\n";
2361 2360
 }
2362 2361
 
2363 2362
 /**
@@ -2374,22 +2373,22 @@  discard block
 block discarded – undo
2374 2373
  * @return string
2375 2374
  */
2376 2375
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2377
-	// si l'on est dans l'espace prive, on garde dans l'url
2378
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2379
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2380
-	$h = (_DIR_RACINE and !$public)
2381
-		? generer_url_ecrire(_request('exec'))
2382
-		: generer_url_public();
2376
+    // si l'on est dans l'espace prive, on garde dans l'url
2377
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2378
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2379
+    $h = (_DIR_RACINE and !$public)
2380
+        ? generer_url_ecrire(_request('exec'))
2381
+        : generer_url_public();
2383 2382
 
2384
-	return "\n<form action='" .
2385
-	$h .
2386
-	"'" .
2387
-	$atts .
2388
-	">\n" .
2389
-	'<div>' .
2390
-	"\n<input type='hidden' name='action' value='$script' />" .
2391
-	$corps .
2392
-	'</div></form>';
2383
+    return "\n<form action='" .
2384
+    $h .
2385
+    "'" .
2386
+    $atts .
2387
+    ">\n" .
2388
+    '<div>' .
2389
+    "\n<input type='hidden' name='action' value='$script' />" .
2390
+    $corps .
2391
+    '</div></form>';
2393 2392
 }
2394 2393
 
2395 2394
 /**
@@ -2408,22 +2407,22 @@  discard block
 block discarded – undo
2408 2407
  *     URL
2409 2408
  */
2410 2409
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2411
-	// si l'on est dans l'espace prive, on garde dans l'url
2412
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2413
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2414
-	$url = (_DIR_RACINE and !$public)
2415
-		? generer_url_ecrire(_request('exec'))
2416
-		: generer_url_public('', '', false, false);
2417
-	$url = parametre_url($url, 'action', $script);
2418
-	if ($args) {
2419
-		$url .= quote_amp('&' . $args);
2420
-	}
2410
+    // si l'on est dans l'espace prive, on garde dans l'url
2411
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2412
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2413
+    $url = (_DIR_RACINE and !$public)
2414
+        ? generer_url_ecrire(_request('exec'))
2415
+        : generer_url_public('', '', false, false);
2416
+    $url = parametre_url($url, 'action', $script);
2417
+    if ($args) {
2418
+        $url .= quote_amp('&' . $args);
2419
+    }
2421 2420
 
2422
-	if ($no_entities) {
2423
-		$url = str_replace('&amp;', '&', $url);
2424
-	}
2421
+    if ($no_entities) {
2422
+        $url = str_replace('&amp;', '&', $url);
2423
+    }
2425 2424
 
2426
-	return $url;
2425
+    return $url;
2427 2426
 }
2428 2427
 
2429 2428
 
@@ -2442,23 +2441,23 @@  discard block
 block discarded – undo
2442 2441
  *     URL
2443 2442
  */
2444 2443
 function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
2445
-	if (is_null($public)) {
2446
-		$public = (_DIR_RACINE ? false : '');
2447
-	}
2448
-	if (substr($script, -4) !== '.api') {
2449
-		$script .= '.api';
2450
-	}
2451
-	$url =
2452
-		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2453
-	. $script . '/'
2454
-	. ($path ? trim($path, '/') : '')
2455
-	. ($args ? '?' . quote_amp($args) : '');
2444
+    if (is_null($public)) {
2445
+        $public = (_DIR_RACINE ? false : '');
2446
+    }
2447
+    if (substr($script, -4) !== '.api') {
2448
+        $script .= '.api';
2449
+    }
2450
+    $url =
2451
+        (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2452
+    . $script . '/'
2453
+    . ($path ? trim($path, '/') : '')
2454
+    . ($args ? '?' . quote_amp($args) : '');
2456 2455
 
2457
-	if ($no_entities) {
2458
-		$url = str_replace('&amp;', '&', $url);
2459
-	}
2456
+    if ($no_entities) {
2457
+        $url = str_replace('&amp;', '&', $url);
2458
+    }
2460 2459
 
2461
-	return $url;
2460
+    return $url;
2462 2461
 }
2463 2462
 
2464 2463
 
@@ -2471,8 +2470,8 @@  discard block
 block discarded – undo
2471 2470
  * @param string $ta Répertoire temporaire accessible
2472 2471
  */
2473 2472
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2474
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2475
-	spip_initialisation_suite();
2473
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2474
+    spip_initialisation_suite();
2476 2475
 }
2477 2476
 
2478 2477
 /**
@@ -2492,310 +2491,310 @@  discard block
 block discarded – undo
2492 2491
  * @param string $ta Répertoire temporaire accessible
2493 2492
  */
2494 2493
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2495
-	static $too_late = 0;
2496
-	if ($too_late++) {
2497
-		return;
2498
-	}
2499
-
2500
-	// Declaration des repertoires
2501
-
2502
-	// le nom du repertoire plugins/ activables/desactivables
2503
-	if (!defined('_DIR_PLUGINS')) {
2504
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2505
-	}
2506
-
2507
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2508
-	if (!defined('_DIR_PLUGINS_DIST')) {
2509
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2510
-	}
2511
-
2512
-	// le nom du repertoire des librairies
2513
-	if (!defined('_DIR_LIB')) {
2514
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2515
-	}
2516
-
2517
-	if (!defined('_DIR_IMG')) {
2518
-		define('_DIR_IMG', $pa);
2519
-	}
2520
-	if (!defined('_DIR_LOGOS')) {
2521
-		define('_DIR_LOGOS', $pa);
2522
-	}
2523
-	if (!defined('_DIR_IMG_ICONES')) {
2524
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2525
-	}
2526
-
2527
-	if (!defined('_DIR_DUMP')) {
2528
-		define('_DIR_DUMP', $ti . 'dump/');
2529
-	}
2530
-	if (!defined('_DIR_SESSIONS')) {
2531
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2532
-	}
2533
-	if (!defined('_DIR_TRANSFERT')) {
2534
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2535
-	}
2536
-	if (!defined('_DIR_CACHE')) {
2537
-		define('_DIR_CACHE', $ti . 'cache/');
2538
-	}
2539
-	if (!defined('_DIR_CACHE_XML')) {
2540
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2541
-	}
2542
-	if (!defined('_DIR_SKELS')) {
2543
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2544
-	}
2545
-	if (!defined('_DIR_AIDE')) {
2546
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2547
-	}
2548
-	if (!defined('_DIR_TMP')) {
2549
-		define('_DIR_TMP', $ti);
2550
-	}
2551
-
2552
-	if (!defined('_DIR_VAR')) {
2553
-		define('_DIR_VAR', $ta);
2554
-	}
2555
-
2556
-	if (!defined('_DIR_ETC')) {
2557
-		define('_DIR_ETC', $pi);
2558
-	}
2559
-	if (!defined('_DIR_CONNECT')) {
2560
-		define('_DIR_CONNECT', $pi);
2561
-	}
2562
-	if (!defined('_DIR_CHMOD')) {
2563
-		define('_DIR_CHMOD', $pi);
2564
-	}
2565
-
2566
-	if (!isset($GLOBALS['test_dirs'])) {
2567
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2568
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2569
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2570
-	}
2571
-
2572
-	// Declaration des fichiers
2573
-
2574
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2575
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2576
-	}
2577
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2578
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2579
-	}
2580
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2581
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2582
-	}
2583
-	if (!defined('_CACHE_PIPELINES')) {
2584
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2585
-	}
2586
-	if (!defined('_CACHE_CHEMIN')) {
2587
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2588
-	}
2589
-
2590
-	# attention .php obligatoire pour ecrire_fichier_securise
2591
-	if (!defined('_FILE_META')) {
2592
-		define('_FILE_META', $ti . 'meta_cache.php');
2593
-	}
2594
-	if (!defined('_DIR_LOG')) {
2595
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2596
-	}
2597
-	if (!defined('_FILE_LOG')) {
2598
-		define('_FILE_LOG', 'spip');
2599
-	}
2600
-	if (!defined('_FILE_LOG_SUFFIX')) {
2601
-		define('_FILE_LOG_SUFFIX', '.log');
2602
-	}
2603
-
2604
-	// Le fichier de connexion a la base de donnees
2605
-	// tient compte des anciennes versions (inc_connect...)
2606
-	if (!defined('_FILE_CONNECT_INS')) {
2607
-		define('_FILE_CONNECT_INS', 'connect');
2608
-	}
2609
-	if (!defined('_FILE_CONNECT')) {
2610
-		define(
2611
-			'_FILE_CONNECT',
2612
-			(@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2613
-			: (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2614
-			: false))
2615
-		);
2616
-	}
2617
-
2618
-	// Le fichier de reglages des droits
2619
-	if (!defined('_FILE_CHMOD_INS')) {
2620
-		define('_FILE_CHMOD_INS', 'chmod');
2621
-	}
2622
-	if (!defined('_FILE_CHMOD')) {
2623
-		define(
2624
-			'_FILE_CHMOD',
2625
-			(@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2626
-			: false)
2627
-		);
2628
-	}
2629
-
2630
-	if (!defined('_FILE_LDAP')) {
2631
-		define('_FILE_LDAP', 'ldap.php');
2632
-	}
2633
-
2634
-	if (!defined('_FILE_TMP_SUFFIX')) {
2635
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2636
-	}
2637
-	if (!defined('_FILE_CONNECT_TMP')) {
2638
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2639
-	}
2640
-	if (!defined('_FILE_CHMOD_TMP')) {
2641
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2642
-	}
2643
-
2644
-	// Definition des droits d'acces en ecriture
2645
-	if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2646
-		include_once _FILE_CHMOD;
2647
-	}
2648
-
2649
-	// Se mefier des fichiers mal remplis!
2650
-	if (!defined('_SPIP_CHMOD')) {
2651
-		define('_SPIP_CHMOD', 0777);
2652
-	}
2653
-
2654
-	if (!defined('_DEFAULT_CHARSET')) {
2655
-		/** Le charset par défaut lors de l'installation */
2656
-		define('_DEFAULT_CHARSET', 'utf-8');
2657
-	}
2658
-	if (!defined('_ROOT_PLUGINS')) {
2659
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2660
-	}
2661
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2662
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2663
-	}
2664
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2665
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2666
-	}
2667
-
2668
-	// La taille des Log
2669
-	if (!defined('_MAX_LOG')) {
2670
-		define('_MAX_LOG', 100);
2671
-	}
2672
-
2673
-	// Sommes-nous dans l'empire du Mal ?
2674
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2675
-	if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2676
-		if (!defined('_OS_SERVEUR')) {
2677
-			define('_OS_SERVEUR', 'windows');
2678
-		}
2679
-		if (!defined('_SPIP_LOCK_MODE')) {
2680
-			define('_SPIP_LOCK_MODE', 1);
2681
-		} // utiliser le flock php
2682
-	} else {
2683
-		if (!defined('_OS_SERVEUR')) {
2684
-			define('_OS_SERVEUR', '');
2685
-		}
2686
-		if (!defined('_SPIP_LOCK_MODE')) {
2687
-			define('_SPIP_LOCK_MODE', 1);
2688
-		} // utiliser le flock php
2689
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2690
-	}
2691
-
2692
-	// Langue par defaut
2693
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2694
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2695
-	}
2696
-
2697
-	//
2698
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2699
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2700
-	// pour le rendre surchargeable, on va provoquer un reecriture
2701
-	// systematique du noyau ou une baisse de perfs => a etudier)
2702
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2703
-
2704
-	// charger tout de suite le path et son cache
2705
-	load_path_cache();
2706
-
2707
-	// *********** traiter les variables ************
2708
-
2709
-	//
2710
-	// Securite
2711
-	//
2712
-
2713
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2714
-	if (isset($_REQUEST['GLOBALS'])) {
2715
-		die();
2716
-	}
2717
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2718
-	spip_desinfecte($_GET);
2719
-	spip_desinfecte($_POST);
2720
-	spip_desinfecte($_COOKIE);
2721
-	spip_desinfecte($_REQUEST);
2722
-
2723
-	// appliquer le cookie_prefix
2724
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2725
-		include_spip('inc/cookie');
2726
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2727
-	}
2728
-
2729
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2730
-	if (isset($_SERVER['REQUEST_URI'])) {
2731
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2732
-	} else {
2733
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2734
-		if (
2735
-			!empty($_SERVER['QUERY_STRING'])
2736
-			and !strpos($_SERVER['REQUEST_URI'], '?')
2737
-		) {
2738
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2739
-		}
2740
-	}
2741
-
2742
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2743
-	if (!defined('_RENOUVELLE_ALEA')) {
2744
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2745
-	}
2746
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2747
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2748
-	}
2749
-
2750
-	// charger les meta si possible et renouveller l'alea au besoin
2751
-	// charge aussi effacer_meta et ecrire_meta
2752
-	$inc_meta = charger_fonction('meta', 'inc');
2753
-	$inc_meta();
2754
-
2755
-	// nombre de repertoires depuis la racine
2756
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2757
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2758
-	// le calcul est faux)
2759
-	if (!_DIR_RESTREINT) {
2760
-		$GLOBALS['profondeur_url'] = 1;
2761
-	} else {
2762
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2763
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2764
-		if (
2765
-			!$uri_ref
2766
-			// si on est appele avec un autre ti, on est sans doute en mutu
2767
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2768
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2769
-			// s'en remettre a l'adresse du site. alea jacta est.
2770
-			or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2771
-		) {
2772
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2773
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2774
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2775
-			} else {
2776
-				$uri_ref = '';
2777
-			}
2778
-		}
2779
-		if (!$uri or !$uri_ref) {
2780
-			$GLOBALS['profondeur_url'] = 0;
2781
-		} else {
2782
-			$GLOBALS['profondeur_url'] = max(
2783
-				0,
2784
-				substr_count($uri[0], '/')
2785
-				- substr_count($uri_ref, '/')
2786
-			);
2787
-		}
2788
-	}
2789
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2790
-	if (_FILE_CONNECT) {
2791
-		if (
2792
-			verifier_visiteur() == '0minirezo'
2793
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2794
-			and !isset($_COOKIE['spip_admin'])
2795
-		) {
2796
-			clear_path_cache();
2797
-		}
2798
-	}
2494
+    static $too_late = 0;
2495
+    if ($too_late++) {
2496
+        return;
2497
+    }
2498
+
2499
+    // Declaration des repertoires
2500
+
2501
+    // le nom du repertoire plugins/ activables/desactivables
2502
+    if (!defined('_DIR_PLUGINS')) {
2503
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2504
+    }
2505
+
2506
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2507
+    if (!defined('_DIR_PLUGINS_DIST')) {
2508
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2509
+    }
2510
+
2511
+    // le nom du repertoire des librairies
2512
+    if (!defined('_DIR_LIB')) {
2513
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2514
+    }
2515
+
2516
+    if (!defined('_DIR_IMG')) {
2517
+        define('_DIR_IMG', $pa);
2518
+    }
2519
+    if (!defined('_DIR_LOGOS')) {
2520
+        define('_DIR_LOGOS', $pa);
2521
+    }
2522
+    if (!defined('_DIR_IMG_ICONES')) {
2523
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2524
+    }
2525
+
2526
+    if (!defined('_DIR_DUMP')) {
2527
+        define('_DIR_DUMP', $ti . 'dump/');
2528
+    }
2529
+    if (!defined('_DIR_SESSIONS')) {
2530
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2531
+    }
2532
+    if (!defined('_DIR_TRANSFERT')) {
2533
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2534
+    }
2535
+    if (!defined('_DIR_CACHE')) {
2536
+        define('_DIR_CACHE', $ti . 'cache/');
2537
+    }
2538
+    if (!defined('_DIR_CACHE_XML')) {
2539
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2540
+    }
2541
+    if (!defined('_DIR_SKELS')) {
2542
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2543
+    }
2544
+    if (!defined('_DIR_AIDE')) {
2545
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2546
+    }
2547
+    if (!defined('_DIR_TMP')) {
2548
+        define('_DIR_TMP', $ti);
2549
+    }
2550
+
2551
+    if (!defined('_DIR_VAR')) {
2552
+        define('_DIR_VAR', $ta);
2553
+    }
2554
+
2555
+    if (!defined('_DIR_ETC')) {
2556
+        define('_DIR_ETC', $pi);
2557
+    }
2558
+    if (!defined('_DIR_CONNECT')) {
2559
+        define('_DIR_CONNECT', $pi);
2560
+    }
2561
+    if (!defined('_DIR_CHMOD')) {
2562
+        define('_DIR_CHMOD', $pi);
2563
+    }
2564
+
2565
+    if (!isset($GLOBALS['test_dirs'])) {
2566
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2567
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2568
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2569
+    }
2570
+
2571
+    // Declaration des fichiers
2572
+
2573
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2574
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2575
+    }
2576
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2577
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2578
+    }
2579
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2580
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2581
+    }
2582
+    if (!defined('_CACHE_PIPELINES')) {
2583
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2584
+    }
2585
+    if (!defined('_CACHE_CHEMIN')) {
2586
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2587
+    }
2588
+
2589
+    # attention .php obligatoire pour ecrire_fichier_securise
2590
+    if (!defined('_FILE_META')) {
2591
+        define('_FILE_META', $ti . 'meta_cache.php');
2592
+    }
2593
+    if (!defined('_DIR_LOG')) {
2594
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2595
+    }
2596
+    if (!defined('_FILE_LOG')) {
2597
+        define('_FILE_LOG', 'spip');
2598
+    }
2599
+    if (!defined('_FILE_LOG_SUFFIX')) {
2600
+        define('_FILE_LOG_SUFFIX', '.log');
2601
+    }
2602
+
2603
+    // Le fichier de connexion a la base de donnees
2604
+    // tient compte des anciennes versions (inc_connect...)
2605
+    if (!defined('_FILE_CONNECT_INS')) {
2606
+        define('_FILE_CONNECT_INS', 'connect');
2607
+    }
2608
+    if (!defined('_FILE_CONNECT')) {
2609
+        define(
2610
+            '_FILE_CONNECT',
2611
+            (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f
2612
+            : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f
2613
+            : false))
2614
+        );
2615
+    }
2616
+
2617
+    // Le fichier de reglages des droits
2618
+    if (!defined('_FILE_CHMOD_INS')) {
2619
+        define('_FILE_CHMOD_INS', 'chmod');
2620
+    }
2621
+    if (!defined('_FILE_CHMOD')) {
2622
+        define(
2623
+            '_FILE_CHMOD',
2624
+            (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f
2625
+            : false)
2626
+        );
2627
+    }
2628
+
2629
+    if (!defined('_FILE_LDAP')) {
2630
+        define('_FILE_LDAP', 'ldap.php');
2631
+    }
2632
+
2633
+    if (!defined('_FILE_TMP_SUFFIX')) {
2634
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2635
+    }
2636
+    if (!defined('_FILE_CONNECT_TMP')) {
2637
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2638
+    }
2639
+    if (!defined('_FILE_CHMOD_TMP')) {
2640
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2641
+    }
2642
+
2643
+    // Definition des droits d'acces en ecriture
2644
+    if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) {
2645
+        include_once _FILE_CHMOD;
2646
+    }
2647
+
2648
+    // Se mefier des fichiers mal remplis!
2649
+    if (!defined('_SPIP_CHMOD')) {
2650
+        define('_SPIP_CHMOD', 0777);
2651
+    }
2652
+
2653
+    if (!defined('_DEFAULT_CHARSET')) {
2654
+        /** Le charset par défaut lors de l'installation */
2655
+        define('_DEFAULT_CHARSET', 'utf-8');
2656
+    }
2657
+    if (!defined('_ROOT_PLUGINS')) {
2658
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2659
+    }
2660
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2661
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2662
+    }
2663
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2664
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2665
+    }
2666
+
2667
+    // La taille des Log
2668
+    if (!defined('_MAX_LOG')) {
2669
+        define('_MAX_LOG', 100);
2670
+    }
2671
+
2672
+    // Sommes-nous dans l'empire du Mal ?
2673
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2674
+    if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) {
2675
+        if (!defined('_OS_SERVEUR')) {
2676
+            define('_OS_SERVEUR', 'windows');
2677
+        }
2678
+        if (!defined('_SPIP_LOCK_MODE')) {
2679
+            define('_SPIP_LOCK_MODE', 1);
2680
+        } // utiliser le flock php
2681
+    } else {
2682
+        if (!defined('_OS_SERVEUR')) {
2683
+            define('_OS_SERVEUR', '');
2684
+        }
2685
+        if (!defined('_SPIP_LOCK_MODE')) {
2686
+            define('_SPIP_LOCK_MODE', 1);
2687
+        } // utiliser le flock php
2688
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2689
+    }
2690
+
2691
+    // Langue par defaut
2692
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2693
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2694
+    }
2695
+
2696
+    //
2697
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2698
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2699
+    // pour le rendre surchargeable, on va provoquer un reecriture
2700
+    // systematique du noyau ou une baisse de perfs => a etudier)
2701
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2702
+
2703
+    // charger tout de suite le path et son cache
2704
+    load_path_cache();
2705
+
2706
+    // *********** traiter les variables ************
2707
+
2708
+    //
2709
+    // Securite
2710
+    //
2711
+
2712
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2713
+    if (isset($_REQUEST['GLOBALS'])) {
2714
+        die();
2715
+    }
2716
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2717
+    spip_desinfecte($_GET);
2718
+    spip_desinfecte($_POST);
2719
+    spip_desinfecte($_COOKIE);
2720
+    spip_desinfecte($_REQUEST);
2721
+
2722
+    // appliquer le cookie_prefix
2723
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2724
+        include_spip('inc/cookie');
2725
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2726
+    }
2727
+
2728
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2729
+    if (isset($_SERVER['REQUEST_URI'])) {
2730
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2731
+    } else {
2732
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2733
+        if (
2734
+            !empty($_SERVER['QUERY_STRING'])
2735
+            and !strpos($_SERVER['REQUEST_URI'], '?')
2736
+        ) {
2737
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2738
+        }
2739
+    }
2740
+
2741
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2742
+    if (!defined('_RENOUVELLE_ALEA')) {
2743
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2744
+    }
2745
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2746
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2747
+    }
2748
+
2749
+    // charger les meta si possible et renouveller l'alea au besoin
2750
+    // charge aussi effacer_meta et ecrire_meta
2751
+    $inc_meta = charger_fonction('meta', 'inc');
2752
+    $inc_meta();
2753
+
2754
+    // nombre de repertoires depuis la racine
2755
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2756
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2757
+    // le calcul est faux)
2758
+    if (!_DIR_RESTREINT) {
2759
+        $GLOBALS['profondeur_url'] = 1;
2760
+    } else {
2761
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2762
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2763
+        if (
2764
+            !$uri_ref
2765
+            // si on est appele avec un autre ti, on est sans doute en mutu
2766
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2767
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2768
+            // s'en remettre a l'adresse du site. alea jacta est.
2769
+            or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2770
+        ) {
2771
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2772
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2773
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2774
+            } else {
2775
+                $uri_ref = '';
2776
+            }
2777
+        }
2778
+        if (!$uri or !$uri_ref) {
2779
+            $GLOBALS['profondeur_url'] = 0;
2780
+        } else {
2781
+            $GLOBALS['profondeur_url'] = max(
2782
+                0,
2783
+                substr_count($uri[0], '/')
2784
+                - substr_count($uri_ref, '/')
2785
+            );
2786
+        }
2787
+    }
2788
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2789
+    if (_FILE_CONNECT) {
2790
+        if (
2791
+            verifier_visiteur() == '0minirezo'
2792
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2793
+            and !isset($_COOKIE['spip_admin'])
2794
+        ) {
2795
+            clear_path_cache();
2796
+        }
2797
+    }
2799 2798
 }
2800 2799
 
2801 2800
 /**
@@ -2804,157 +2803,157 @@  discard block
 block discarded – undo
2804 2803
  *
2805 2804
  */
2806 2805
 function spip_initialisation_suite() {
2807
-	static $too_late = 0;
2808
-	if ($too_late++) {
2809
-		return;
2810
-	}
2811
-
2812
-	// taille mini des login
2813
-	if (!defined('_LOGIN_TROP_COURT')) {
2814
-		define('_LOGIN_TROP_COURT', 4);
2815
-	}
2816
-
2817
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2818
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2819
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2820
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2821
-
2822
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2823
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2824
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2825
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2826
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2827
-
2828
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2829
-		define('_PASS_LONGUEUR_MINI', 6);
2830
-	}
2831
-
2832
-	// largeur maximale des images dans l'administration
2833
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2834
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2835
-	}
2836
-
2837
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2838
-	if (!defined('_IMG_QUALITE')) {
2839
-		define('_IMG_QUALITE', 85);
2840
-	} # valeur par defaut
2841
-	if (!defined('_IMG_GD_QUALITE')) {
2842
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2843
-	} # surcharge pour la lib GD
2844
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2845
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2846
-	} # surcharge pour imagick en ligne de commande
2847
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2848
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2849
-		define('_IMG_IMAGICK_QUALITE', 75);
2850
-	} # surcharge pour imagick en PHP
2851
-
2852
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2853
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2854
-	} // poids en octet
2855
-
2856
-	// qq chaines standard
2857
-	if (!defined('_ACCESS_FILE_NAME')) {
2858
-		define('_ACCESS_FILE_NAME', '.htaccess');
2859
-	}
2860
-	if (!defined('_AUTH_USER_FILE')) {
2861
-		define('_AUTH_USER_FILE', '.htpasswd');
2862
-	}
2863
-	if (!defined('_SPIP_DUMP')) {
2864
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2865
-	}
2866
-	if (!defined('_CACHE_RUBRIQUES')) {
2867
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2868
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2869
-	}
2870
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2871
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2872
-		define('_CACHE_RUBRIQUES_MAX', 500);
2873
-	}
2874
-
2875
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2876
-		/**
2877
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2878
-		 * @var int Nombre de caractères */
2879
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2880
-	}
2881
-
2882
-	if (!defined('_EXTENSION_SQUELETTES')) {
2883
-		define('_EXTENSION_SQUELETTES', 'html');
2884
-	}
2885
-
2886
-	if (!defined('_DOCTYPE_ECRIRE')) {
2887
-		/** Définit le doctype de l’espace privé */
2888
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2889
-	}
2890
-	if (!defined('_DOCTYPE_AIDE')) {
2891
-		/** Définit le doctype de l’aide en ligne */
2892
-		define(
2893
-			'_DOCTYPE_AIDE',
2894
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2895
-		);
2896
-	}
2897
-
2898
-	if (!defined('_SPIP_SCRIPT')) {
2899
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2900
-		 * le script de l'espace public, alias index.php */
2901
-		define('_SPIP_SCRIPT', 'spip.php');
2902
-	}
2903
-	if (!defined('_SPIP_PAGE')) {
2904
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2905
-		define('_SPIP_PAGE', 'page');
2906
-	}
2907
-
2908
-	// le script de l'espace prive
2909
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2910
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2911
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2912
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2913
-		if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2914
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2915
-		} else {
2916
-			define('_SPIP_ECRIRE_SCRIPT', '');
2917
-		}
2918
-	}
2919
-
2920
-
2921
-	if (!defined('_SPIP_AJAX')) {
2922
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2923
-			? 1
2924
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2925
-	}
2926
-
2927
-	// La requete est-elle en ajax ?
2928
-	if (!defined('_AJAX')) {
2929
-		define(
2930
-			'_AJAX',
2931
-			(isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2932
-				or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2933
-				or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2934
-				or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2935
-			)
2936
-			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
2937
-		);
2938
-	}
2939
-
2940
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2941
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2942
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2943
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2944
-		define(
2945
-			'_IMG_GD_MAX_PIXELS',
2946
-			(isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2947
-			? $GLOBALS['meta']['max_taille_vignettes']
2948
-			: 0
2949
-		);
2950
-	}
2951
-
2952
-	// Protocoles a normaliser dans les chaines de langues
2953
-	if (!defined('_PROTOCOLES_STD')) {
2954
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2955
-	}
2956
-
2957
-	init_var_mode();
2806
+    static $too_late = 0;
2807
+    if ($too_late++) {
2808
+        return;
2809
+    }
2810
+
2811
+    // taille mini des login
2812
+    if (!defined('_LOGIN_TROP_COURT')) {
2813
+        define('_LOGIN_TROP_COURT', 4);
2814
+    }
2815
+
2816
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2817
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2818
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2819
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2820
+
2821
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2822
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2823
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2824
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2825
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2826
+
2827
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2828
+        define('_PASS_LONGUEUR_MINI', 6);
2829
+    }
2830
+
2831
+    // largeur maximale des images dans l'administration
2832
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2833
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2834
+    }
2835
+
2836
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2837
+    if (!defined('_IMG_QUALITE')) {
2838
+        define('_IMG_QUALITE', 85);
2839
+    } # valeur par defaut
2840
+    if (!defined('_IMG_GD_QUALITE')) {
2841
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2842
+    } # surcharge pour la lib GD
2843
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2844
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2845
+    } # surcharge pour imagick en ligne de commande
2846
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2847
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2848
+        define('_IMG_IMAGICK_QUALITE', 75);
2849
+    } # surcharge pour imagick en PHP
2850
+
2851
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2852
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2853
+    } // poids en octet
2854
+
2855
+    // qq chaines standard
2856
+    if (!defined('_ACCESS_FILE_NAME')) {
2857
+        define('_ACCESS_FILE_NAME', '.htaccess');
2858
+    }
2859
+    if (!defined('_AUTH_USER_FILE')) {
2860
+        define('_AUTH_USER_FILE', '.htpasswd');
2861
+    }
2862
+    if (!defined('_SPIP_DUMP')) {
2863
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2864
+    }
2865
+    if (!defined('_CACHE_RUBRIQUES')) {
2866
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2867
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2868
+    }
2869
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2870
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2871
+        define('_CACHE_RUBRIQUES_MAX', 500);
2872
+    }
2873
+
2874
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2875
+        /**
2876
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2877
+         * @var int Nombre de caractères */
2878
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2879
+    }
2880
+
2881
+    if (!defined('_EXTENSION_SQUELETTES')) {
2882
+        define('_EXTENSION_SQUELETTES', 'html');
2883
+    }
2884
+
2885
+    if (!defined('_DOCTYPE_ECRIRE')) {
2886
+        /** Définit le doctype de l’espace privé */
2887
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2888
+    }
2889
+    if (!defined('_DOCTYPE_AIDE')) {
2890
+        /** Définit le doctype de l’aide en ligne */
2891
+        define(
2892
+            '_DOCTYPE_AIDE',
2893
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2894
+        );
2895
+    }
2896
+
2897
+    if (!defined('_SPIP_SCRIPT')) {
2898
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2899
+         * le script de l'espace public, alias index.php */
2900
+        define('_SPIP_SCRIPT', 'spip.php');
2901
+    }
2902
+    if (!defined('_SPIP_PAGE')) {
2903
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2904
+        define('_SPIP_PAGE', 'page');
2905
+    }
2906
+
2907
+    // le script de l'espace prive
2908
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2909
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2910
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2911
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2912
+        if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2913
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2914
+        } else {
2915
+            define('_SPIP_ECRIRE_SCRIPT', '');
2916
+        }
2917
+    }
2918
+
2919
+
2920
+    if (!defined('_SPIP_AJAX')) {
2921
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2922
+            ? 1
2923
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2924
+    }
2925
+
2926
+    // La requete est-elle en ajax ?
2927
+    if (!defined('_AJAX')) {
2928
+        define(
2929
+            '_AJAX',
2930
+            (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2931
+                or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery
2932
+                or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2933
+                or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2934
+            )
2935
+            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
2936
+        );
2937
+    }
2938
+
2939
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2940
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2941
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2942
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2943
+        define(
2944
+            '_IMG_GD_MAX_PIXELS',
2945
+            (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes'])
2946
+            ? $GLOBALS['meta']['max_taille_vignettes']
2947
+            : 0
2948
+        );
2949
+    }
2950
+
2951
+    // Protocoles a normaliser dans les chaines de langues
2952
+    if (!defined('_PROTOCOLES_STD')) {
2953
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2954
+    }
2955
+
2956
+    init_var_mode();
2958 2957
 }
2959 2958
 
2960 2959
 /**
@@ -2988,136 +2987,136 @@  discard block
 block discarded – undo
2988 2987
  * `   var_mode` (calcul ou recalcul).
2989 2988
  */
2990 2989
 function init_var_mode() {
2991
-	static $done = false;
2992
-	if (!$done) {
2993
-		if (isset($_GET['var_mode'])) {
2994
-			$var_mode = explode(',', $_GET['var_mode']);
2995
-			// tout le monde peut calcul/recalcul
2996
-			if (!defined('_VAR_MODE')) {
2997
-				if (in_array('recalcul', $var_mode)) {
2998
-					define('_VAR_MODE', 'recalcul');
2999
-				} elseif (in_array('calcul', $var_mode)) {
3000
-					define('_VAR_MODE', 'calcul');
3001
-				}
3002
-			}
3003
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3004
-			if ($var_mode) {
3005
-				include_spip('inc/autoriser');
3006
-				// autoriser preview si preview seulement, et sinon autoriser debug
3007
-				if (
3008
-					autoriser(
3009
-						($_GET['var_mode'] == 'preview')
3010
-						? 'previsualiser'
3011
-						: 'debug'
3012
-					)
3013
-				) {
3014
-					if (in_array('traduction', $var_mode)) {
3015
-						// forcer le calcul pour passer dans traduire
3016
-						if (!defined('_VAR_MODE')) {
3017
-							define('_VAR_MODE', 'calcul');
3018
-						}
3019
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3020
-						if (!defined('_VAR_NOCACHE')) {
3021
-							define('_VAR_NOCACHE', true);
3022
-						}
3023
-						$var_mode = array_diff($var_mode, ['traduction']);
3024
-					}
3025
-					if (in_array('preview', $var_mode)) {
3026
-						// basculer sur les criteres de preview dans les boucles
3027
-						if (!defined('_VAR_PREVIEW')) {
3028
-							define('_VAR_PREVIEW', true);
3029
-						}
3030
-						// forcer le calcul
3031
-						if (!defined('_VAR_MODE')) {
3032
-							define('_VAR_MODE', 'calcul');
3033
-						}
3034
-						// et ne pas enregistrer de cache
3035
-						if (!defined('_VAR_NOCACHE')) {
3036
-							define('_VAR_NOCACHE', true);
3037
-						}
3038
-						$var_mode = array_diff($var_mode, ['preview']);
3039
-					}
3040
-					if (in_array('inclure', $var_mode)) {
3041
-						// forcer le compilo et ignorer les caches existants
3042
-						if (!defined('_VAR_MODE')) {
3043
-							define('_VAR_MODE', 'calcul');
3044
-						}
3045
-						if (!defined('_VAR_INCLURE')) {
3046
-							define('_VAR_INCLURE', true);
3047
-						}
3048
-						// et ne pas enregistrer de cache
3049
-						if (!defined('_VAR_NOCACHE')) {
3050
-							define('_VAR_NOCACHE', true);
3051
-						}
3052
-						$var_mode = array_diff($var_mode, ['inclure']);
3053
-					}
3054
-					if (in_array('urls', $var_mode)) {
3055
-						// forcer le compilo et ignorer les caches existants
3056
-						if (!defined('_VAR_MODE')) {
3057
-							define('_VAR_MODE', 'calcul');
3058
-						}
3059
-						if (!defined('_VAR_URLS')) {
3060
-							define('_VAR_URLS', true);
3061
-						}
3062
-						$var_mode = array_diff($var_mode, ['urls']);
3063
-					}
3064
-					if (in_array('images', $var_mode)) {
3065
-						// forcer le compilo et ignorer les caches existants
3066
-						if (!defined('_VAR_MODE')) {
3067
-							define('_VAR_MODE', 'calcul');
3068
-						}
3069
-						// indiquer qu'on doit recalculer les images
3070
-						if (!defined('_VAR_IMAGES')) {
3071
-							define('_VAR_IMAGES', true);
3072
-						}
3073
-						$var_mode = array_diff($var_mode, ['images']);
3074
-					}
3075
-					if (in_array('debug', $var_mode)) {
3076
-						if (!defined('_VAR_MODE')) {
3077
-							define('_VAR_MODE', 'debug');
3078
-						}
3079
-						// et ne pas enregistrer de cache
3080
-						if (!defined('_VAR_NOCACHE')) {
3081
-							define('_VAR_NOCACHE', true);
3082
-						}
3083
-						$var_mode = array_diff($var_mode, ['debug']);
3084
-					}
3085
-					if (count($var_mode) and !defined('_VAR_MODE')) {
3086
-						define('_VAR_MODE', reset($var_mode));
3087
-					}
3088
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3089
-						spip_log($GLOBALS['visiteur_session']['nom']
3090
-							. ' ' . _VAR_MODE);
3091
-					}
3092
-				} // pas autorise ?
3093
-				else {
3094
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3095
-					if (
3096
-						!$GLOBALS['visiteur_session']
3097
-						and !empty($_SERVER['HTTP_HOST'])
3098
-						and !empty($_SERVER['REQUEST_METHOD'])
3099
-						and $_SERVER['REQUEST_METHOD'] === 'GET'
3100
-					) {
3101
-						$self = self('&', true);
3102
-						if (strpos($self, 'page=login') === false) {
3103
-							include_spip('inc/headers');
3104
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3105
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3106
-						}
3107
-					}
3108
-					// sinon tant pis
3109
-				}
3110
-			}
3111
-		}
3112
-		if (!defined('_VAR_MODE')) {
3113
-			/**
3114
-			 * Indique le mode de calcul ou d'affichage de la page.
3115
-			 * @see init_var_mode()
3116
-			 */
3117
-			define('_VAR_MODE', false);
3118
-		}
3119
-		$done = true;
3120
-	}
2990
+    static $done = false;
2991
+    if (!$done) {
2992
+        if (isset($_GET['var_mode'])) {
2993
+            $var_mode = explode(',', $_GET['var_mode']);
2994
+            // tout le monde peut calcul/recalcul
2995
+            if (!defined('_VAR_MODE')) {
2996
+                if (in_array('recalcul', $var_mode)) {
2997
+                    define('_VAR_MODE', 'recalcul');
2998
+                } elseif (in_array('calcul', $var_mode)) {
2999
+                    define('_VAR_MODE', 'calcul');
3000
+                }
3001
+            }
3002
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3003
+            if ($var_mode) {
3004
+                include_spip('inc/autoriser');
3005
+                // autoriser preview si preview seulement, et sinon autoriser debug
3006
+                if (
3007
+                    autoriser(
3008
+                        ($_GET['var_mode'] == 'preview')
3009
+                        ? 'previsualiser'
3010
+                        : 'debug'
3011
+                    )
3012
+                ) {
3013
+                    if (in_array('traduction', $var_mode)) {
3014
+                        // forcer le calcul pour passer dans traduire
3015
+                        if (!defined('_VAR_MODE')) {
3016
+                            define('_VAR_MODE', 'calcul');
3017
+                        }
3018
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3019
+                        if (!defined('_VAR_NOCACHE')) {
3020
+                            define('_VAR_NOCACHE', true);
3021
+                        }
3022
+                        $var_mode = array_diff($var_mode, ['traduction']);
3023
+                    }
3024
+                    if (in_array('preview', $var_mode)) {
3025
+                        // basculer sur les criteres de preview dans les boucles
3026
+                        if (!defined('_VAR_PREVIEW')) {
3027
+                            define('_VAR_PREVIEW', true);
3028
+                        }
3029
+                        // forcer le calcul
3030
+                        if (!defined('_VAR_MODE')) {
3031
+                            define('_VAR_MODE', 'calcul');
3032
+                        }
3033
+                        // et ne pas enregistrer de cache
3034
+                        if (!defined('_VAR_NOCACHE')) {
3035
+                            define('_VAR_NOCACHE', true);
3036
+                        }
3037
+                        $var_mode = array_diff($var_mode, ['preview']);
3038
+                    }
3039
+                    if (in_array('inclure', $var_mode)) {
3040
+                        // forcer le compilo et ignorer les caches existants
3041
+                        if (!defined('_VAR_MODE')) {
3042
+                            define('_VAR_MODE', 'calcul');
3043
+                        }
3044
+                        if (!defined('_VAR_INCLURE')) {
3045
+                            define('_VAR_INCLURE', true);
3046
+                        }
3047
+                        // et ne pas enregistrer de cache
3048
+                        if (!defined('_VAR_NOCACHE')) {
3049
+                            define('_VAR_NOCACHE', true);
3050
+                        }
3051
+                        $var_mode = array_diff($var_mode, ['inclure']);
3052
+                    }
3053
+                    if (in_array('urls', $var_mode)) {
3054
+                        // forcer le compilo et ignorer les caches existants
3055
+                        if (!defined('_VAR_MODE')) {
3056
+                            define('_VAR_MODE', 'calcul');
3057
+                        }
3058
+                        if (!defined('_VAR_URLS')) {
3059
+                            define('_VAR_URLS', true);
3060
+                        }
3061
+                        $var_mode = array_diff($var_mode, ['urls']);
3062
+                    }
3063
+                    if (in_array('images', $var_mode)) {
3064
+                        // forcer le compilo et ignorer les caches existants
3065
+                        if (!defined('_VAR_MODE')) {
3066
+                            define('_VAR_MODE', 'calcul');
3067
+                        }
3068
+                        // indiquer qu'on doit recalculer les images
3069
+                        if (!defined('_VAR_IMAGES')) {
3070
+                            define('_VAR_IMAGES', true);
3071
+                        }
3072
+                        $var_mode = array_diff($var_mode, ['images']);
3073
+                    }
3074
+                    if (in_array('debug', $var_mode)) {
3075
+                        if (!defined('_VAR_MODE')) {
3076
+                            define('_VAR_MODE', 'debug');
3077
+                        }
3078
+                        // et ne pas enregistrer de cache
3079
+                        if (!defined('_VAR_NOCACHE')) {
3080
+                            define('_VAR_NOCACHE', true);
3081
+                        }
3082
+                        $var_mode = array_diff($var_mode, ['debug']);
3083
+                    }
3084
+                    if (count($var_mode) and !defined('_VAR_MODE')) {
3085
+                        define('_VAR_MODE', reset($var_mode));
3086
+                    }
3087
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3088
+                        spip_log($GLOBALS['visiteur_session']['nom']
3089
+                            . ' ' . _VAR_MODE);
3090
+                    }
3091
+                } // pas autorise ?
3092
+                else {
3093
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3094
+                    if (
3095
+                        !$GLOBALS['visiteur_session']
3096
+                        and !empty($_SERVER['HTTP_HOST'])
3097
+                        and !empty($_SERVER['REQUEST_METHOD'])
3098
+                        and $_SERVER['REQUEST_METHOD'] === 'GET'
3099
+                    ) {
3100
+                        $self = self('&', true);
3101
+                        if (strpos($self, 'page=login') === false) {
3102
+                            include_spip('inc/headers');
3103
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3104
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3105
+                        }
3106
+                    }
3107
+                    // sinon tant pis
3108
+                }
3109
+            }
3110
+        }
3111
+        if (!defined('_VAR_MODE')) {
3112
+            /**
3113
+             * Indique le mode de calcul ou d'affichage de la page.
3114
+             * @see init_var_mode()
3115
+             */
3116
+            define('_VAR_MODE', false);
3117
+        }
3118
+        $done = true;
3119
+    }
3121 3120
 }
3122 3121
 
3123 3122
 /**
@@ -3129,16 +3128,16 @@  discard block
 block discarded – undo
3129 3128
  * @param bool $deep = true : appliquer récursivement
3130 3129
 **/
3131 3130
 function spip_desinfecte(&$t, $deep = true) {
3132
-	foreach ($t as $key => $val) {
3133
-		if (is_string($t[$key])) {
3134
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3135
-		} // traiter aussi les "texte_plus" de article_edit
3136
-		else {
3137
-			if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3138
-				spip_desinfecte($t[$key], $deep);
3139
-			}
3140
-		}
3141
-	}
3131
+    foreach ($t as $key => $val) {
3132
+        if (is_string($t[$key])) {
3133
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3134
+        } // traiter aussi les "texte_plus" de article_edit
3135
+        else {
3136
+            if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') {
3137
+                spip_desinfecte($t[$key], $deep);
3138
+            }
3139
+        }
3140
+    }
3142 3141
 }
3143 3142
 
3144 3143
 /**
@@ -3151,64 +3150,64 @@  discard block
 block discarded – undo
3151 3150
  * @return string|0|false
3152 3151
 **/
3153 3152
 function verifier_visiteur() {
3154
-	@spip_initialisation_core(
3155
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3156
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3157
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3158
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3159
-	);
3160
-
3161
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3162
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3163
-	// Attention on separe bien session_nom et nom, pour eviter
3164
-	// les melanges entre donnees SQL et variables plus aleatoires
3165
-	$variables_session = ['session_nom', 'session_email'];
3166
-	foreach ($variables_session as $var) {
3167
-		if (_request($var) !== null) {
3168
-			$init = true;
3169
-			break;
3170
-		}
3171
-	}
3172
-	if (isset($init)) {
3173
-		#@spip_initialisation_suite();
3174
-		$session = charger_fonction('session', 'inc');
3175
-		$session();
3176
-		include_spip('inc/texte');
3177
-		foreach ($variables_session as $var) {
3178
-			if (($a = _request($var)) !== null) {
3179
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3180
-			}
3181
-		}
3182
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3183
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3184
-		}
3185
-		$session($GLOBALS['visiteur_session']);
3186
-
3187
-		return 0;
3188
-	}
3189
-
3190
-	$h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3191
-	if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3192
-		$session = charger_fonction('session', 'inc');
3193
-		if ($session()) {
3194
-			return $GLOBALS['visiteur_session']['statut'];
3195
-		}
3196
-		if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3197
-			include_spip('inc/auth');
3198
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3199
-		}
3200
-		if ($h) {
3201
-			$GLOBALS['visiteur_session'] = $h;
3202
-
3203
-			return $GLOBALS['visiteur_session']['statut'];
3204
-		}
3205
-	}
3206
-
3207
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3208
-	include_spip('inc/lang');
3209
-	utiliser_langue_visiteur();
3210
-
3211
-	return false;
3153
+    @spip_initialisation_core(
3154
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3155
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3156
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3157
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3158
+    );
3159
+
3160
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3161
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3162
+    // Attention on separe bien session_nom et nom, pour eviter
3163
+    // les melanges entre donnees SQL et variables plus aleatoires
3164
+    $variables_session = ['session_nom', 'session_email'];
3165
+    foreach ($variables_session as $var) {
3166
+        if (_request($var) !== null) {
3167
+            $init = true;
3168
+            break;
3169
+        }
3170
+    }
3171
+    if (isset($init)) {
3172
+        #@spip_initialisation_suite();
3173
+        $session = charger_fonction('session', 'inc');
3174
+        $session();
3175
+        include_spip('inc/texte');
3176
+        foreach ($variables_session as $var) {
3177
+            if (($a = _request($var)) !== null) {
3178
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3179
+            }
3180
+        }
3181
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3182
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3183
+        }
3184
+        $session($GLOBALS['visiteur_session']);
3185
+
3186
+        return 0;
3187
+    }
3188
+
3189
+    $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']);
3190
+    if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3191
+        $session = charger_fonction('session', 'inc');
3192
+        if ($session()) {
3193
+            return $GLOBALS['visiteur_session']['statut'];
3194
+        }
3195
+        if ($h and isset($_SERVER['PHP_AUTH_PW'])) {
3196
+            include_spip('inc/auth');
3197
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3198
+        }
3199
+        if ($h) {
3200
+            $GLOBALS['visiteur_session'] = $h;
3201
+
3202
+            return $GLOBALS['visiteur_session']['statut'];
3203
+        }
3204
+    }
3205
+
3206
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3207
+    include_spip('inc/lang');
3208
+    utiliser_langue_visiteur();
3209
+
3210
+    return false;
3212 3211
 }
3213 3212
 
3214 3213
 
@@ -3231,21 +3230,21 @@  discard block
 block discarded – undo
3231 3230
  *     - string Langue utilisée.
3232 3231
  **/
3233 3232
 function lang_select($lang = null) {
3234
-	static $pile_langues = [];
3235
-	if (!function_exists('changer_langue')) {
3236
-		include_spip('inc/lang');
3237
-	}
3238
-	if ($lang === null) {
3239
-		$lang = array_pop($pile_langues);
3240
-	} else {
3241
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3242
-	}
3243
-	if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3244
-		return $lang;
3245
-	}
3246
-	changer_langue($lang);
3233
+    static $pile_langues = [];
3234
+    if (!function_exists('changer_langue')) {
3235
+        include_spip('inc/lang');
3236
+    }
3237
+    if ($lang === null) {
3238
+        $lang = array_pop($pile_langues);
3239
+    } else {
3240
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3241
+    }
3242
+    if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) {
3243
+        return $lang;
3244
+    }
3245
+    changer_langue($lang);
3247 3246
 
3248
-	return $lang;
3247
+    return $lang;
3249 3248
 }
3250 3249
 
3251 3250
 /**
@@ -3262,20 +3261,20 @@  discard block
 block discarded – undo
3262 3261
  *     Identifiant de la session
3263 3262
  **/
3264 3263
 function spip_session($force = false) {
3265
-	static $session;
3266
-	if ($force or !isset($session)) {
3267
-		$s = pipeline(
3268
-			'definir_session',
3269
-			$GLOBALS['visiteur_session']
3270
-				? serialize($GLOBALS['visiteur_session'])
3271
-				. '_' . @$_COOKIE['spip_session']
3272
-				: ''
3273
-		);
3274
-		$session = $s ? substr(md5($s), 0, 8) : '';
3275
-	}
3264
+    static $session;
3265
+    if ($force or !isset($session)) {
3266
+        $s = pipeline(
3267
+            'definir_session',
3268
+            $GLOBALS['visiteur_session']
3269
+                ? serialize($GLOBALS['visiteur_session'])
3270
+                . '_' . @$_COOKIE['spip_session']
3271
+                : ''
3272
+        );
3273
+        $session = $s ? substr(md5($s), 0, 8) : '';
3274
+    }
3276 3275
 
3277
-	#spip_log('session: '.$session);
3278
-	return $session;
3276
+    #spip_log('session: '.$session);
3277
+    return $session;
3279 3278
 }
3280 3279
 
3281 3280
 
@@ -3294,9 +3293,9 @@  discard block
 block discarded – undo
3294 3293
  *    Lien sur une icone d'aide
3295 3294
  **/
3296 3295
 function aider($aide = '', $distante = false) {
3297
-	$aider = charger_fonction('aide', 'inc', true);
3296
+    $aider = charger_fonction('aide', 'inc', true);
3298 3297
 
3299
-	return $aider ? $aider($aide, '', [], $distante) : '';
3298
+    return $aider ? $aider($aide, '', [], $distante) : '';
3300 3299
 }
3301 3300
 
3302 3301
 /**
@@ -3306,35 +3305,35 @@  discard block
 block discarded – undo
3306 3305
  */
3307 3306
 function exec_info_dist() {
3308 3307
 
3309
-	include_spip('inc/autoriser');
3310
-	if (autoriser('phpinfos')) {
3311
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3312
-		$cookies_backup = [];
3313
-		$server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3314
-		$env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3315
-		$mask = '******************************';
3316
-		foreach ($cookies_masques as $k) {
3317
-			if (!empty($_COOKIE[$k])) {
3318
-				$cookies_backup[$k] = $_COOKIE[$k];
3319
-				$_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3320
-				$_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3321
-				$_COOKIE[$k] = $mask;
3322
-			}
3323
-		}
3324
-		phpinfo();
3325
-		foreach ($cookies_backup as $k => $v) {
3326
-			$_COOKIE[$k] = $v;
3327
-		}
3328
-		foreach ($server_backup as $k => $v) {
3329
-			$_SERVER[$k] = $v;
3330
-		}
3331
-		foreach ($env_backup as $k => $v) {
3332
-			$_ENV[$k] = $v;
3333
-		}
3334
-	} else {
3335
-		include_spip('inc/filtres');
3336
-		sinon_interdire_acces();
3337
-	}
3308
+    include_spip('inc/autoriser');
3309
+    if (autoriser('phpinfos')) {
3310
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3311
+        $cookies_backup = [];
3312
+        $server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3313
+        $env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3314
+        $mask = '******************************';
3315
+        foreach ($cookies_masques as $k) {
3316
+            if (!empty($_COOKIE[$k])) {
3317
+                $cookies_backup[$k] = $_COOKIE[$k];
3318
+                $_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3319
+                $_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3320
+                $_COOKIE[$k] = $mask;
3321
+            }
3322
+        }
3323
+        phpinfo();
3324
+        foreach ($cookies_backup as $k => $v) {
3325
+            $_COOKIE[$k] = $v;
3326
+        }
3327
+        foreach ($server_backup as $k => $v) {
3328
+            $_SERVER[$k] = $v;
3329
+        }
3330
+        foreach ($env_backup as $k => $v) {
3331
+            $_ENV[$k] = $v;
3332
+        }
3333
+    } else {
3334
+        include_spip('inc/filtres');
3335
+        sinon_interdire_acces();
3336
+    }
3338 3337
 }
3339 3338
 
3340 3339
 /**
@@ -3354,13 +3353,13 @@  discard block
 block discarded – undo
3354 3353
  *     - string si $message à false.
3355 3354
  **/
3356 3355
 function erreur_squelette($message = '', $lieu = '') {
3357
-	$debusquer = charger_fonction('debusquer', 'public');
3358
-	if (is_array($lieu)) {
3359
-		include_spip('public/compiler');
3360
-		$lieu = reconstruire_contexte_compil($lieu);
3361
-	}
3356
+    $debusquer = charger_fonction('debusquer', 'public');
3357
+    if (is_array($lieu)) {
3358
+        include_spip('public/compiler');
3359
+        $lieu = reconstruire_contexte_compil($lieu);
3360
+    }
3362 3361
 
3363
-	return $debusquer($message, $lieu);
3362
+    return $debusquer($message, $lieu);
3364 3363
 }
3365 3364
 
3366 3365
 /**
@@ -3397,108 +3396,108 @@  discard block
 block discarded – undo
3397 3396
  *     - ou tableau d'information sur le squelette.
3398 3397
  */
3399 3398
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3400
-	if (!function_exists('evaluer_fond')) {
3401
-		include_spip('public/assembler');
3402
-	}
3403
-	// assurer la compat avec l'ancienne syntaxe
3404
-	// (trim etait le 3eme argument, par defaut a true)
3405
-	if (!is_array($options)) {
3406
-		$options = ['trim' => $options];
3407
-	}
3408
-	if (!isset($options['trim'])) {
3409
-		$options['trim'] = true;
3410
-	}
3411
-
3412
-	if (isset($contexte['connect'])) {
3413
-		$connect = $contexte['connect'];
3414
-		unset($contexte['connect']);
3415
-	}
3416
-
3417
-	$texte = '';
3418
-	$pages = [];
3419
-	$lang_select = '';
3420
-	if (!isset($options['etoile']) or !$options['etoile']) {
3421
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3422
-		if (!isset($contexte['lang'])) {
3423
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3424
-		}
3425
-
3426
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3427
-			$lang_select = lang_select($contexte['lang']);
3428
-		}
3429
-	}
3430
-
3431
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3432
-		$GLOBALS['_INC_PUBLIC'] = 0;
3433
-	}
3434
-
3435
-	$GLOBALS['_INC_PUBLIC']++;
3436
-
3437
-	// fix #4235
3438
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3439
-
3440
-
3441
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3442
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3443
-
3444
-		$page = evaluer_fond($f, $contexte, $connect);
3445
-		if ($page === '') {
3446
-			$c = $options['compil'] ?? '';
3447
-			$a = ['fichier' => $f];
3448
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3449
-			erreur_squelette($erreur, $c);
3450
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3451
-			$page = ['texte' => '', 'erreur' => $erreur];
3452
-		}
3453
-
3454
-		$page = pipeline('recuperer_fond', [
3455
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3456
-			'data' => $page
3457
-		]);
3458
-		if (isset($options['ajax']) and $options['ajax']) {
3459
-			if (!function_exists('encoder_contexte_ajax')) {
3460
-				include_spip('inc/filtres');
3461
-			}
3462
-			$page['texte'] = encoder_contexte_ajax(
3463
-				array_merge(
3464
-					$contexte,
3465
-					['fond' => $f],
3466
-					($connect ? ['connect' => $connect] : [])
3467
-				),
3468
-				'',
3469
-				$page['texte'],
3470
-				$options['ajax']
3471
-			);
3472
-		}
3473
-
3474
-		if (isset($options['raw']) and $options['raw']) {
3475
-			$pages[] = $page;
3476
-		} else {
3477
-			$texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3478
-		}
3479
-
3480
-		// contamination de la session appelante, pour les inclusions statiques
3481
-		if (isset($page['invalideurs']['session'])) {
3482
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3483
-		}
3484
-	}
3485
-
3486
-	// restaurer le sessionnement du contexte appelant,
3487
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3488
-	if (isset($cache_utilise_session_appelant)) {
3489
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3490
-	}
3491
-
3492
-	$GLOBALS['_INC_PUBLIC']--;
3493
-
3494
-	if ($lang_select) {
3495
-		lang_select();
3496
-	}
3497
-	if (isset($options['raw']) and $options['raw']) {
3498
-		return is_array($fond) ? $pages : reset($pages);
3499
-	} else {
3500
-		return $options['trim'] ? ltrim($texte) : $texte;
3501
-	}
3399
+    if (!function_exists('evaluer_fond')) {
3400
+        include_spip('public/assembler');
3401
+    }
3402
+    // assurer la compat avec l'ancienne syntaxe
3403
+    // (trim etait le 3eme argument, par defaut a true)
3404
+    if (!is_array($options)) {
3405
+        $options = ['trim' => $options];
3406
+    }
3407
+    if (!isset($options['trim'])) {
3408
+        $options['trim'] = true;
3409
+    }
3410
+
3411
+    if (isset($contexte['connect'])) {
3412
+        $connect = $contexte['connect'];
3413
+        unset($contexte['connect']);
3414
+    }
3415
+
3416
+    $texte = '';
3417
+    $pages = [];
3418
+    $lang_select = '';
3419
+    if (!isset($options['etoile']) or !$options['etoile']) {
3420
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3421
+        if (!isset($contexte['lang'])) {
3422
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3423
+        }
3424
+
3425
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3426
+            $lang_select = lang_select($contexte['lang']);
3427
+        }
3428
+    }
3429
+
3430
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3431
+        $GLOBALS['_INC_PUBLIC'] = 0;
3432
+    }
3433
+
3434
+    $GLOBALS['_INC_PUBLIC']++;
3435
+
3436
+    // fix #4235
3437
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3438
+
3439
+
3440
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3441
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3442
+
3443
+        $page = evaluer_fond($f, $contexte, $connect);
3444
+        if ($page === '') {
3445
+            $c = $options['compil'] ?? '';
3446
+            $a = ['fichier' => $f];
3447
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3448
+            erreur_squelette($erreur, $c);
3449
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3450
+            $page = ['texte' => '', 'erreur' => $erreur];
3451
+        }
3452
+
3453
+        $page = pipeline('recuperer_fond', [
3454
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3455
+            'data' => $page
3456
+        ]);
3457
+        if (isset($options['ajax']) and $options['ajax']) {
3458
+            if (!function_exists('encoder_contexte_ajax')) {
3459
+                include_spip('inc/filtres');
3460
+            }
3461
+            $page['texte'] = encoder_contexte_ajax(
3462
+                array_merge(
3463
+                    $contexte,
3464
+                    ['fond' => $f],
3465
+                    ($connect ? ['connect' => $connect] : [])
3466
+                ),
3467
+                '',
3468
+                $page['texte'],
3469
+                $options['ajax']
3470
+            );
3471
+        }
3472
+
3473
+        if (isset($options['raw']) and $options['raw']) {
3474
+            $pages[] = $page;
3475
+        } else {
3476
+            $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3477
+        }
3478
+
3479
+        // contamination de la session appelante, pour les inclusions statiques
3480
+        if (isset($page['invalideurs']['session'])) {
3481
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3482
+        }
3483
+    }
3484
+
3485
+    // restaurer le sessionnement du contexte appelant,
3486
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3487
+    if (isset($cache_utilise_session_appelant)) {
3488
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3489
+    }
3490
+
3491
+    $GLOBALS['_INC_PUBLIC']--;
3492
+
3493
+    if ($lang_select) {
3494
+        lang_select();
3495
+    }
3496
+    if (isset($options['raw']) and $options['raw']) {
3497
+        return is_array($fond) ? $pages : reset($pages);
3498
+    } else {
3499
+        return $options['trim'] ? ltrim($texte) : $texte;
3500
+    }
3502 3501
 }
3503 3502
 
3504 3503
 /**
@@ -3508,7 +3507,7 @@  discard block
 block discarded – undo
3508 3507
  * @return string
3509 3508
  */
3510 3509
 function trouve_modele($nom) {
3511
-	return trouver_fond($nom, 'modeles/');
3510
+    return trouver_fond($nom, 'modeles/');
3512 3511
 }
3513 3512
 
3514 3513
 /**
@@ -3524,21 +3523,21 @@  discard block
 block discarded – undo
3524 3523
  * @return array|string
3525 3524
  */
3526 3525
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3527
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3528
-	if (!$pathinfo) {
3529
-		return $f;
3530
-	}
3531
-	// renvoyer un tableau detaille si $pathinfo==true
3532
-	$p = pathinfo($f);
3533
-	if (!isset($p['extension']) or !$p['extension']) {
3534
-		$p['extension'] = _EXTENSION_SQUELETTES;
3535
-	}
3536
-	if (!isset($p['extension']) or !$p['filename']) {
3537
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3538
-	}
3539
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3526
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3527
+    if (!$pathinfo) {
3528
+        return $f;
3529
+    }
3530
+    // renvoyer un tableau detaille si $pathinfo==true
3531
+    $p = pathinfo($f);
3532
+    if (!isset($p['extension']) or !$p['extension']) {
3533
+        $p['extension'] = _EXTENSION_SQUELETTES;
3534
+    }
3535
+    if (!isset($p['extension']) or !$p['filename']) {
3536
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3537
+    }
3538
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3540 3539
 
3541
-	return $p;
3540
+    return $p;
3542 3541
 }
3543 3542
 
3544 3543
 /**
@@ -3558,21 +3557,21 @@  discard block
 block discarded – undo
3558 3557
  *     Nom de l'exec, sinon chaîne vide.
3559 3558
  **/
3560 3559
 function tester_url_ecrire($nom) {
3561
-	static $exec = [];
3562
-	if (isset($exec[$nom])) {
3563
-		return $exec[$nom];
3564
-	}
3565
-	// tester si c'est une page en squelette
3566
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3567
-		return $exec[$nom] = 'fond';
3568
-	} // echafaudage d'un fond !
3569
-	elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3570
-		return $exec[$nom] = 'fond';
3571
-	}
3572
-	// attention, il ne faut pas inclure l'exec ici
3573
-	// car sinon #URL_ECRIRE provoque des inclusions
3574
-	// et des define intrusifs potentiels
3575
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3560
+    static $exec = [];
3561
+    if (isset($exec[$nom])) {
3562
+        return $exec[$nom];
3563
+    }
3564
+    // tester si c'est une page en squelette
3565
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3566
+        return $exec[$nom] = 'fond';
3567
+    } // echafaudage d'un fond !
3568
+    elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) {
3569
+        return $exec[$nom] = 'fond';
3570
+    }
3571
+    // attention, il ne faut pas inclure l'exec ici
3572
+    // car sinon #URL_ECRIRE provoque des inclusions
3573
+    // et des define intrusifs potentiels
3574
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : '');
3576 3575
 }
3577 3576
 
3578 3577
 /**
@@ -3582,8 +3581,8 @@  discard block
 block discarded – undo
3582 3581
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3583 3582
  **/
3584 3583
 function html5_permis() {
3585
-	return (!defined('_VERSION_HTML')
3586
-		or _VERSION_HTML !== 'html4');
3584
+    return (!defined('_VERSION_HTML')
3585
+        or _VERSION_HTML !== 'html4');
3587 3586
 }
3588 3587
 
3589 3588
 /**
@@ -3593,30 +3592,30 @@  discard block
 block discarded – undo
3593 3592
  * @return array
3594 3593
  */
3595 3594
 function formats_image_acceptables($gd = null, $svg_allowed = true) {
3596
-	$formats = null;
3597
-	if (!is_null($gd)) {
3598
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3599
-		if (isset($GLOBALS['meta'][$config])) {
3600
-			$formats = $GLOBALS['meta'][$config];
3601
-			$formats = explode(',', $formats);
3602
-			$formats = array_filter($formats);
3603
-			$formats = array_map('trim', $formats);
3604
-		}
3605
-	}
3606
-	if (is_null($formats)) {
3607
-		include_spip('inc/filtres_images_lib_mini');
3608
-		$formats = _image_extensions_acceptees_en_entree();
3609
-	}
3610
-
3611
-	if ($svg_allowed) {
3612
-		if (!in_array('svg', $formats)) {
3613
-			$formats[] = 'svg';
3614
-		}
3615
-	}
3616
-	else {
3617
-		$formats = array_diff($formats, ['svg']);
3618
-	}
3619
-	return $formats;
3595
+    $formats = null;
3596
+    if (!is_null($gd)) {
3597
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3598
+        if (isset($GLOBALS['meta'][$config])) {
3599
+            $formats = $GLOBALS['meta'][$config];
3600
+            $formats = explode(',', $formats);
3601
+            $formats = array_filter($formats);
3602
+            $formats = array_map('trim', $formats);
3603
+        }
3604
+    }
3605
+    if (is_null($formats)) {
3606
+        include_spip('inc/filtres_images_lib_mini');
3607
+        $formats = _image_extensions_acceptees_en_entree();
3608
+    }
3609
+
3610
+    if ($svg_allowed) {
3611
+        if (!in_array('svg', $formats)) {
3612
+            $formats[] = 'svg';
3613
+        }
3614
+    }
3615
+    else {
3616
+        $formats = array_diff($formats, ['svg']);
3617
+    }
3618
+    return $formats;
3620 3619
 }
3621 3620
 
3622 3621
 /**
@@ -3625,20 +3624,20 @@  discard block
 block discarded – undo
3625 3624
  * @return array|bool
3626 3625
  */
3627 3626
 function spip_getimagesize($fichier) {
3628
-	if (!$imagesize = @getimagesize($fichier)) {
3629
-		include_spip('inc/svg');
3630
-		if ($attrs = svg_lire_attributs($fichier)) {
3631
-			[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3632
-			$imagesize = [
3633
-				$width,
3634
-				$height,
3635
-				IMAGETYPE_SVG,
3636
-				"width=\"{$width}\" height=\"{$height}\"",
3637
-				'mime' => 'image/svg+xml'
3638
-			];
3639
-		}
3640
-	}
3641
-	return $imagesize;
3627
+    if (!$imagesize = @getimagesize($fichier)) {
3628
+        include_spip('inc/svg');
3629
+        if ($attrs = svg_lire_attributs($fichier)) {
3630
+            [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3631
+            $imagesize = [
3632
+                $width,
3633
+                $height,
3634
+                IMAGETYPE_SVG,
3635
+                "width=\"{$width}\" height=\"{$height}\"",
3636
+                'mime' => 'image/svg+xml'
3637
+            ];
3638
+        }
3639
+    }
3640
+    return $imagesize;
3642 3641
 }
3643 3642
 
3644 3643
 /**
@@ -3652,19 +3651,19 @@  discard block
 block discarded – undo
3652 3651
  * @param string $statut
3653 3652
  */
3654 3653
 function avertir_auteurs($nom, $message, $statut = '') {
3655
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3656
-	if (
3657
-		!$alertes
3658
-		or !is_array($alertes = unserialize($alertes))
3659
-	) {
3660
-		$alertes = [];
3661
-	}
3654
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3655
+    if (
3656
+        !$alertes
3657
+        or !is_array($alertes = unserialize($alertes))
3658
+    ) {
3659
+        $alertes = [];
3660
+    }
3662 3661
 
3663
-	if (!isset($alertes[$statut])) {
3664
-		$alertes[$statut] = [];
3665
-	}
3666
-	$alertes[$statut][$nom] = $message;
3667
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3662
+    if (!isset($alertes[$statut])) {
3663
+        $alertes[$statut] = [];
3664
+    }
3665
+    $alertes[$statut][$nom] = $message;
3666
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3668 3667
 }
3669 3668
 
3670 3669
 /**
@@ -3678,10 +3677,10 @@  discard block
 block discarded – undo
3678 3677
  * @return string|string[]
3679 3678
  */
3680 3679
 function spip_sanitize_classname($classes) {
3681
-	if (is_array($classes)) {
3682
-		return array_map('spip_sanitize_classname', $classes);
3683
-	}
3684
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3680
+    if (is_array($classes)) {
3681
+        return array_map('spip_sanitize_classname', $classes);
3682
+    }
3683
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3685 3684
 }
3686 3685
 
3687 3686
 
@@ -3706,32 +3705,32 @@  discard block
 block discarded – undo
3706 3705
  *    Avec operateur : bool.
3707 3706
  **/
3708 3707
 function spip_version_compare($v1, $v2, $op = null) {
3709
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3710
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3711
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3712
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3713
-
3714
-	$v1 = explode('.', $v1);
3715
-	$v2 = explode('.', $v2);
3716
-	// $v1 est toujours une version, donc sans etoile
3717
-	while (count($v1) < count($v2)) {
3718
-		$v1[] = '0';
3719
-	}
3720
-
3721
-	// $v2 peut etre une borne, donc accepte l'etoile
3722
-	$etoile = false;
3723
-	foreach ($v1 as $k => $v) {
3724
-		if (!isset($v2[$k])) {
3725
-			$v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3726
-		} else {
3727
-			if ($v2[$k] == '*') {
3728
-				$etoile = true;
3729
-				$v2[$k] = $v;
3730
-			}
3731
-		}
3732
-	}
3733
-	$v1 = implode('.', $v1);
3734
-	$v2 = implode('.', $v2);
3735
-
3736
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3708
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3709
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3710
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3711
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3712
+
3713
+    $v1 = explode('.', $v1);
3714
+    $v2 = explode('.', $v2);
3715
+    // $v1 est toujours une version, donc sans etoile
3716
+    while (count($v1) < count($v2)) {
3717
+        $v1[] = '0';
3718
+    }
3719
+
3720
+    // $v2 peut etre une borne, donc accepte l'etoile
3721
+    $etoile = false;
3722
+    foreach ($v1 as $k => $v) {
3723
+        if (!isset($v2[$k])) {
3724
+            $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0';
3725
+        } else {
3726
+            if ($v2[$k] == '*') {
3727
+                $etoile = true;
3728
+                $v2[$k] = $v;
3729
+            }
3730
+        }
3731
+    }
3732
+    $v1 = implode('.', $v1);
3733
+    $v2 = implode('.', $v2);
3734
+
3735
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3737 3736
 }
Please login to merge, or discard this patch.