Completed
Push — master ( 2db97a...762316 )
by cam
02:04
created
ecrire/inc/utils.php 1 patch
Indentation   +2292 added lines, -2293 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -47,71 +47,71 @@  discard block
 block discarded – undo
47 47
  *     Nom de la fonction, ou false.
48 48
  */
49 49
 function charger_fonction($nom, $dossier = 'exec', $continue = false) {
50
-	static $echecs = [];
51
-
52
-	if (strlen($dossier) && !str_ends_with($dossier, '/')) {
53
-		$dossier .= '/';
54
-	}
55
-	$f = str_replace('/', '_', $dossier) . $nom;
56
-
57
-	if (function_exists($f)) {
58
-		return $f;
59
-	}
60
-	if (function_exists($g = $f . '_dist')) {
61
-		return $g;
62
-	}
63
-
64
-	if (isset($echecs[$f])) {
65
-		return $echecs[$f];
66
-	}
67
-	// Sinon charger le fichier de declaration si plausible
68
-
69
-	if (!preg_match(',^\w+$,', $f)) {
70
-		if ($continue) {
71
-			return false;
72
-		} //appel interne, on passe
73
-		include_spip('inc/minipres');
74
-		echo minipres();
75
-		exit;
76
-	}
77
-
78
-	// passer en minuscules (cf les balises de formulaires)
79
-	// et inclure le fichier
80
-	if (
81
-		!($inc = include_spip($dossier . ($d = strtolower($nom))))
82
-		&& strlen(dirname($dossier))
83
-		&& dirname($dossier) != '.'
84
-	) {
85
-		include_spip(substr($dossier, 0, -1));
86
-	}
87
-	if (function_exists($f)) {
88
-		return $f;
89
-	}
90
-	if (function_exists($g)) {
91
-		return $g;
92
-	}
93
-
94
-	if ($continue) {
95
-		return $echecs[$f] = false;
96
-	}
97
-
98
-	// Echec : message d'erreur
99
-	spip_log("fonction $nom ($f ou $g) indisponible" .
100
-		($inc ? '' : " (fichier $d absent de $dossier)"));
101
-
102
-	include_spip('inc/minipres');
103
-	include_spip('inc/filtres_mini');
104
-	echo minipres(
105
-		_T('forum_titre_erreur'),
106
-		$inc ?
107
-			_T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
108
-			. '<br />'
109
-			. _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
110
-			:
111
-			_T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
112
-		['all_inline' => true,'status' => 404]
113
-	);
114
-	exit;
50
+    static $echecs = [];
51
+
52
+    if (strlen($dossier) && !str_ends_with($dossier, '/')) {
53
+        $dossier .= '/';
54
+    }
55
+    $f = str_replace('/', '_', $dossier) . $nom;
56
+
57
+    if (function_exists($f)) {
58
+        return $f;
59
+    }
60
+    if (function_exists($g = $f . '_dist')) {
61
+        return $g;
62
+    }
63
+
64
+    if (isset($echecs[$f])) {
65
+        return $echecs[$f];
66
+    }
67
+    // Sinon charger le fichier de declaration si plausible
68
+
69
+    if (!preg_match(',^\w+$,', $f)) {
70
+        if ($continue) {
71
+            return false;
72
+        } //appel interne, on passe
73
+        include_spip('inc/minipres');
74
+        echo minipres();
75
+        exit;
76
+    }
77
+
78
+    // passer en minuscules (cf les balises de formulaires)
79
+    // et inclure le fichier
80
+    if (
81
+        !($inc = include_spip($dossier . ($d = strtolower($nom))))
82
+        && strlen(dirname($dossier))
83
+        && dirname($dossier) != '.'
84
+    ) {
85
+        include_spip(substr($dossier, 0, -1));
86
+    }
87
+    if (function_exists($f)) {
88
+        return $f;
89
+    }
90
+    if (function_exists($g)) {
91
+        return $g;
92
+    }
93
+
94
+    if ($continue) {
95
+        return $echecs[$f] = false;
96
+    }
97
+
98
+    // Echec : message d'erreur
99
+    spip_log("fonction $nom ($f ou $g) indisponible" .
100
+        ($inc ? '' : " (fichier $d absent de $dossier)"));
101
+
102
+    include_spip('inc/minipres');
103
+    include_spip('inc/filtres_mini');
104
+    echo minipres(
105
+        _T('forum_titre_erreur'),
106
+        $inc ?
107
+            _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>'])
108
+            . '<br />'
109
+            . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>'])
110
+            :
111
+            _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']),
112
+        ['all_inline' => true,'status' => 404]
113
+    );
114
+    exit;
115 115
 }
116 116
 
117 117
 /**
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
  * @return bool
122 122
  */
123 123
 function include_once_check($file) {
124
-	if (file_exists($file)) {
125
-		include_once $file;
124
+    if (file_exists($file)) {
125
+        include_once $file;
126 126
 
127
-		return true;
128
-	}
129
-	$crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
130
-	$crash = ($crash ?: []);
131
-	$crash[$file] = true;
132
-	ecrire_meta('message_crash_plugins', serialize($crash));
127
+        return true;
128
+    }
129
+    $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : '');
130
+    $crash = ($crash ?: []);
131
+    $crash[$file] = true;
132
+    ecrire_meta('message_crash_plugins', serialize($crash));
133 133
 
134
-	return false;
134
+    return false;
135 135
 }
136 136
 
137 137
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
  *     - string : chemin du fichier trouvé
156 156
  **/
157 157
 function include_spip($f, $include = true) {
158
-	return find_in_path($f . '.php', '', $include);
158
+    return find_in_path($f . '.php', '', $include);
159 159
 }
160 160
 
161 161
 /**
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
  *     - string : chemin du fichier trouvé
176 176
  **/
177 177
 function require_spip($f) {
178
-	return find_in_path($f . '.php', '', 'required');
178
+    return find_in_path($f . '.php', '', 'required');
179 179
 }
180 180
 
181 181
 
@@ -184,27 +184,27 @@  discard block
 block discarded – undo
184 184
  * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis
185 185
  */
186 186
 function include_fichiers_fonctions() {
187
-	static $done = false;
188
-	if (!$done) {
189
-		include_spip('inc/lang');
190
-
191
-		// NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
192
-		// donc il faut l'inclure "en globals"
193
-		if ($f = find_in_path('mes_fonctions.php')) {
194
-			global $dossier_squelettes;
195
-			include_once(_ROOT_CWD . $f);
196
-		}
197
-
198
-		if (@is_readable(_CACHE_PLUGINS_FCT)) {
199
-			// chargement optimise precompile
200
-			include_once(_CACHE_PLUGINS_FCT);
201
-		}
202
-		if (test_espace_prive()) {
203
-			include_spip('inc/filtres_ecrire');
204
-		}
205
-		include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
206
-		$done = true;
207
-	}
187
+    static $done = false;
188
+    if (!$done) {
189
+        include_spip('inc/lang');
190
+
191
+        // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style)
192
+        // donc il faut l'inclure "en globals"
193
+        if ($f = find_in_path('mes_fonctions.php')) {
194
+            global $dossier_squelettes;
195
+            include_once(_ROOT_CWD . $f);
196
+        }
197
+
198
+        if (@is_readable(_CACHE_PLUGINS_FCT)) {
199
+            // chargement optimise precompile
200
+            include_once(_CACHE_PLUGINS_FCT);
201
+        }
202
+        if (test_espace_prive()) {
203
+            include_spip('inc/filtres_ecrire');
204
+        }
205
+        include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises..
206
+        $done = true;
207
+    }
208 208
 }
209 209
 
210 210
 /**
@@ -230,23 +230,23 @@  discard block
 block discarded – undo
230 230
  *     Les paramètres du pipeline modifiés
231 231
  **/
232 232
 function minipipe($fonc, &$val) {
233
-	// fonction
234
-	if (function_exists($fonc)) {
235
-		$val = $fonc($val);
236
-	} // Class::Methode
237
-	else {
238
-		if (
239
-			preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
240
-			&& ($methode = [$regs[1], $regs[2]])
241
-			&& is_callable($methode)
242
-		) {
243
-			$val = $methode($val);
244
-		} else {
245
-			spip_log("Erreur - '$fonc' non definie !");
246
-		}
247
-	}
248
-
249
-	return $val;
233
+    // fonction
234
+    if (function_exists($fonc)) {
235
+        $val = $fonc($val);
236
+    } // Class::Methode
237
+    else {
238
+        if (
239
+            preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs)
240
+            && ($methode = [$regs[1], $regs[2]])
241
+            && is_callable($methode)
242
+        ) {
243
+            $val = $methode($val);
244
+        } else {
245
+            spip_log("Erreur - '$fonc' non definie !");
246
+        }
247
+    }
248
+
249
+    return $val;
250 250
 }
251 251
 
252 252
 /**
@@ -277,46 +277,46 @@  discard block
 block discarded – undo
277 277
  *     Résultat
278 278
  */
279 279
 function pipeline($action, $val = null) {
280
-	static $charger;
281
-
282
-	// chargement initial des fonctions mises en cache, ou generation du cache
283
-	if (!$charger) {
284
-		if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
285
-			include_spip('inc/plugin');
286
-			// generer les fichiers php precompiles
287
-			// de chargement des plugins et des pipelines
288
-			actualise_plugins_actifs();
289
-			if (!($ok = @is_readable($charger))) {
290
-				spip_log("fichier $charger pas cree");
291
-			}
292
-		}
293
-
294
-		if ($ok) {
295
-			include_once $charger;
296
-		}
297
-	}
298
-
299
-	// appliquer notre fonction si elle existe
300
-	$fonc = 'execute_pipeline_' . strtolower($action);
301
-	if (function_exists($fonc)) {
302
-		$val = $fonc($val);
303
-	} // plantage ?
304
-	else {
305
-		spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
306
-	}
307
-
308
-	// si le flux est une table avec 2 cle args&data
309
-	// on ne ressort du pipe que les donnees dans 'data'
310
-	// array_key_exists pour php 4.1.0
311
-	if (
312
-		is_array($val)
313
-		&& count($val) == 2
314
-		&& array_key_exists('data', $val)
315
-	) {
316
-		$val = $val['data'];
317
-	}
318
-
319
-	return $val;
280
+    static $charger;
281
+
282
+    // chargement initial des fonctions mises en cache, ou generation du cache
283
+    if (!$charger) {
284
+        if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) {
285
+            include_spip('inc/plugin');
286
+            // generer les fichiers php precompiles
287
+            // de chargement des plugins et des pipelines
288
+            actualise_plugins_actifs();
289
+            if (!($ok = @is_readable($charger))) {
290
+                spip_log("fichier $charger pas cree");
291
+            }
292
+        }
293
+
294
+        if ($ok) {
295
+            include_once $charger;
296
+        }
297
+    }
298
+
299
+    // appliquer notre fonction si elle existe
300
+    $fonc = 'execute_pipeline_' . strtolower($action);
301
+    if (function_exists($fonc)) {
302
+        $val = $fonc($val);
303
+    } // plantage ?
304
+    else {
305
+        spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR);
306
+    }
307
+
308
+    // si le flux est une table avec 2 cle args&data
309
+    // on ne ressort du pipe que les donnees dans 'data'
310
+    // array_key_exists pour php 4.1.0
311
+    if (
312
+        is_array($val)
313
+        && count($val) == 2
314
+        && array_key_exists('data', $val)
315
+    ) {
316
+        $val = $val['data'];
317
+    }
318
+
319
+    return $val;
320 320
 }
321 321
 
322 322
 /**
@@ -360,38 +360,38 @@  discard block
 block discarded – undo
360 360
  *     paramètre est planté pour cause de compatibilité ascendante.
361 361
  */
362 362
 function spip_log($message = null, $name = null) {
363
-	static $pre = [];
364
-	static $log;
365
-	preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
366
-	if (!isset($regs[1]) || !$logname = $regs[1]) {
367
-		$logname = null;
368
-	}
369
-	if (!isset($regs[2])) {
370
-		$niveau = _LOG_INFO;
371
-	}
372
-	else {
373
-		$niveau = intval($regs[2]);
374
-	}
375
-
376
-	if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
377
-		if (!$pre) {
378
-			$pre = [
379
-				_LOG_HS => 'HS:',
380
-				_LOG_ALERTE_ROUGE => 'ALERTE:',
381
-				_LOG_CRITIQUE => 'CRITIQUE:',
382
-				_LOG_ERREUR => 'ERREUR:',
383
-				_LOG_AVERTISSEMENT => 'WARNING:',
384
-				_LOG_INFO_IMPORTANTE => '!INFO:',
385
-				_LOG_INFO => 'info:',
386
-				_LOG_DEBUG => 'debug:'
387
-			];
388
-			$log = charger_fonction('log', 'inc');
389
-		}
390
-		if (!is_string($message)) {
391
-			$message = print_r($message, true);
392
-		}
393
-		$log($pre[$niveau] . ' ' . $message, $logname);
394
-	}
363
+    static $pre = [];
364
+    static $log;
365
+    preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs);
366
+    if (!isset($regs[1]) || !$logname = $regs[1]) {
367
+        $logname = null;
368
+    }
369
+    if (!isset($regs[2])) {
370
+        $niveau = _LOG_INFO;
371
+    }
372
+    else {
373
+        $niveau = intval($regs[2]);
374
+    }
375
+
376
+    if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) {
377
+        if (!$pre) {
378
+            $pre = [
379
+                _LOG_HS => 'HS:',
380
+                _LOG_ALERTE_ROUGE => 'ALERTE:',
381
+                _LOG_CRITIQUE => 'CRITIQUE:',
382
+                _LOG_ERREUR => 'ERREUR:',
383
+                _LOG_AVERTISSEMENT => 'WARNING:',
384
+                _LOG_INFO_IMPORTANTE => '!INFO:',
385
+                _LOG_INFO => 'info:',
386
+                _LOG_DEBUG => 'debug:'
387
+            ];
388
+            $log = charger_fonction('log', 'inc');
389
+        }
390
+        if (!is_string($message)) {
391
+            $message = print_r($message, true);
392
+        }
393
+        $log($pre[$niveau] . ' ' . $message, $logname);
394
+    }
395 395
 }
396 396
 
397 397
 
@@ -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
-		&& _AJAX
444
-		&& isset($GLOBALS['meta']['charset'])
445
-		&& $GLOBALS['meta']['charset'] != 'utf-8'
446
-		// check rapide mais pas fiable
447
-		&& is_string($a)
448
-		&& preg_match(',[\x80-\xFF],', $a)
449
-		// check fiable
450
-		&& include_spip('inc/charsets')
451
-		&& 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
+        && _AJAX
444
+        && isset($GLOBALS['meta']['charset'])
445
+        && $GLOBALS['meta']['charset'] != 'utf-8'
446
+        // check rapide mais pas fiable
447
+        && is_string($a)
448
+        && preg_match(',[\x80-\xFF],', $a)
449
+        // check fiable
450
+        && include_spip('inc/charsets')
451
+        && 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) && $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) && $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
-			&& ($p = strtolower(rtrim($m[1], ':')))
545
-			&& 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
+            && ($p = strtolower(rtrim($m[1], ':')))
544
+            && 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 (str_contains($c, '|') && 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 (str_ends_with($r[1], '[]')) {
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 (!str_ends_with($r[1], '[]')) {
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
-		&& ($args = func_get_args())
642
-		&& 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 = (str_ends_with($k, '[]')) ? $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 (str_contains($c, '|') && 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 (str_ends_with($r[1], '[]')) {
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 (!str_ends_with($r[1], '[]')) {
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
+        && ($args = func_get_args())
641
+        && 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 = (str_ends_with($k, '[]')) ? $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
 /**
@@ -727,36 +726,36 @@  discard block
 block discarded – undo
727 726
  * @return string
728 727
  */
729 728
 function nettoyer_uri_var($request_uri) {
730
-	static $preg_nettoyer;
731
-	if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) {
732
-		/** @var array<string> Liste (regexp) de noms de variables à ignorer d’une URI */
733
-		define('_CONTEXTE_IGNORE_LISTE_VARIABLES', ['^var_', '^PHPSESSID$', '^fbclid$', '^utm_']);
734
-	}
735
-	if (empty($preg_nettoyer)) {
736
-		$preg_nettoyer_vars = _CONTEXTE_IGNORE_LISTE_VARIABLES;
737
-		foreach ($preg_nettoyer_vars as &$var) {
738
-			if (str_starts_with($var, '^')) {
739
-				$var = substr($var, 1);
740
-			} else {
741
-				$var = '[^=&]*' . $var;
742
-			}
743
-			if (str_ends_with($var, '$')) {
744
-				$var = substr($var, 0, -1);
745
-			} else {
746
-				$var .= '[^=&]*';
747
-			}
748
-		}
749
-		$preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i';
750
-	}
751
-	if (empty($request_uri)) {
752
-		return $request_uri;
753
-	}
754
-	$uri1 = $request_uri;
755
-	do {
756
-		$uri = $uri1;
757
-		$uri1 = preg_replace($preg_nettoyer, '\1', $uri);
758
-	} while ($uri <> $uri1);
759
-	return rtrim($uri1, '?&');
729
+    static $preg_nettoyer;
730
+    if (!defined('_CONTEXTE_IGNORE_LISTE_VARIABLES')) {
731
+        /** @var array<string> Liste (regexp) de noms de variables à ignorer d’une URI */
732
+        define('_CONTEXTE_IGNORE_LISTE_VARIABLES', ['^var_', '^PHPSESSID$', '^fbclid$', '^utm_']);
733
+    }
734
+    if (empty($preg_nettoyer)) {
735
+        $preg_nettoyer_vars = _CONTEXTE_IGNORE_LISTE_VARIABLES;
736
+        foreach ($preg_nettoyer_vars as &$var) {
737
+            if (str_starts_with($var, '^')) {
738
+                $var = substr($var, 1);
739
+            } else {
740
+                $var = '[^=&]*' . $var;
741
+            }
742
+            if (str_ends_with($var, '$')) {
743
+                $var = substr($var, 0, -1);
744
+            } else {
745
+                $var .= '[^=&]*';
746
+            }
747
+        }
748
+        $preg_nettoyer = ',([?&])(' . implode('|', $preg_nettoyer_vars) . ')=[^&]*(&|$),i';
749
+    }
750
+    if (empty($request_uri)) {
751
+        return $request_uri;
752
+    }
753
+    $uri1 = $request_uri;
754
+    do {
755
+        $uri = $uri1;
756
+        $uri1 = preg_replace($preg_nettoyer, '\1', $uri);
757
+    } while ($uri <> $uri1);
758
+    return rtrim($uri1, '?&');
760 759
 }
761 760
 
762 761
 
@@ -770,49 +769,49 @@  discard block
 block discarded – undo
770 769
  *    URL vers soi-même
771 770
  **/
772 771
 function self($amp = '&amp;', $root = false) {
773
-	$url = nettoyer_uri();
774
-	if (
775
-		!$root
776
-		&& (
777
-			// si pas de profondeur on peut tronquer
778
-			$GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
779
-			// sinon c'est OK si _SET_HTML_BASE a ete force a false
780
-			|| defined('_SET_HTML_BASE') && !_SET_HTML_BASE
781
-		)
782
-	) {
783
-		$url = preg_replace(',^[^?]*/,', '', $url);
784
-	}
785
-	// ajouter le cas echeant les variables _POST['id_...']
786
-	foreach ($_POST as $v => $c) {
787
-		if (str_starts_with($v, 'id_')) {
788
-			$url = parametre_url($url, $v, $c, '&');
789
-		}
790
-	}
791
-
792
-	// supprimer les variables sans interet
793
-	if (test_espace_prive()) {
794
-		$url = preg_replace(',([?&])('
795
-			. 'lang|show_docs|'
796
-			. 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
797
-		$url = preg_replace(',([?&])[&]+,', '\1', $url);
798
-		$url = preg_replace(',[&]$,', '\1', $url);
799
-	}
800
-
801
-	// eviter les hacks
802
-	include_spip('inc/filtres_mini');
803
-	$url = spip_htmlspecialchars($url);
804
-
805
-	$url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
806
-
807
-	// &amp; ?
808
-	if ($amp != '&amp;') {
809
-		$url = str_replace('&amp;', $amp, $url);
810
-	}
811
-
812
-	// Si ca demarre par ? ou vide, donner './'
813
-	$url = preg_replace(',^([?].*)?$,', './\1', $url);
814
-
815
-	return $url;
772
+    $url = nettoyer_uri();
773
+    if (
774
+        !$root
775
+        && (
776
+            // si pas de profondeur on peut tronquer
777
+            $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2)
778
+            // sinon c'est OK si _SET_HTML_BASE a ete force a false
779
+            || defined('_SET_HTML_BASE') && !_SET_HTML_BASE
780
+        )
781
+    ) {
782
+        $url = preg_replace(',^[^?]*/,', '', $url);
783
+    }
784
+    // ajouter le cas echeant les variables _POST['id_...']
785
+    foreach ($_POST as $v => $c) {
786
+        if (str_starts_with($v, 'id_')) {
787
+            $url = parametre_url($url, $v, $c, '&');
788
+        }
789
+    }
790
+
791
+    // supprimer les variables sans interet
792
+    if (test_espace_prive()) {
793
+        $url = preg_replace(',([?&])('
794
+            . 'lang|show_docs|'
795
+            . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url);
796
+        $url = preg_replace(',([?&])[&]+,', '\1', $url);
797
+        $url = preg_replace(',[&]$,', '\1', $url);
798
+    }
799
+
800
+    // eviter les hacks
801
+    include_spip('inc/filtres_mini');
802
+    $url = spip_htmlspecialchars($url);
803
+
804
+    $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url);
805
+
806
+    // &amp; ?
807
+    if ($amp != '&amp;') {
808
+        $url = str_replace('&amp;', $amp, $url);
809
+    }
810
+
811
+    // Si ca demarre par ? ou vide, donner './'
812
+    $url = preg_replace(',^([?].*)?$,', './\1', $url);
813
+
814
+    return $url;
816 815
 }
817 816
 
818 817
 
@@ -823,7 +822,7 @@  discard block
 block discarded – undo
823 822
  *     true si c'est le cas, false sinon.
824 823
  */
825 824
 function test_espace_prive() {
826
-	return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
825
+    return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false;
827 826
 }
828 827
 
829 828
 /**
@@ -833,7 +832,7 @@  discard block
 block discarded – undo
833 832
  * @return bool
834 833
  */
835 834
 function test_plugin_actif($plugin) {
836
-	return ($plugin && defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
835
+    return ($plugin && defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false;
837 836
 }
838 837
 
839 838
 /**
@@ -864,52 +863,52 @@  discard block
 block discarded – undo
864 863
  *     texte
865 864
  */
866 865
 function _T($texte, $args = [], $options = []) {
867
-	static $traduire = false;
868
-	$o = ['class' => '', 'force' => true, 'sanitize' => true];
869
-	if ($options) {
870
-		// support de l'ancien argument $class
871
-		if (is_string($options)) {
872
-			$options = ['class' => $options];
873
-		}
874
-		$o = array_merge($o, $options);
875
-	}
876
-
877
-	if (!$traduire) {
878
-		$traduire = charger_fonction('traduire', 'inc');
879
-		include_spip('inc/lang');
880
-	}
881
-
882
-	// On peut passer explicitement la langue dans le tableau
883
-	// On utilise le même nom de variable que la globale
884
-	if (isset($args['spip_lang'])) {
885
-		$lang = $args['spip_lang'];
886
-		// On l'enleve pour ne pas le passer au remplacement
887
-		unset($args['spip_lang']);
888
-	} // Sinon on prend la langue du contexte
889
-	else {
890
-		$lang = $GLOBALS['spip_lang'];
891
-	}
892
-	$text = $traduire($texte, $lang);
893
-
894
-	if ($text === null || !strlen($text)) {
895
-		if (!$o['force']) {
896
-			return '';
897
-		}
898
-
899
-		$text = $texte;
900
-
901
-		// pour les chaines non traduites, assurer un service minimum
902
-		if (!$GLOBALS['test_i18n'] && _request('var_mode') != 'traduction') {
903
-			$n = strpos($text, ':');
904
-			if ($n !== false) {
905
-				$text = substr($text, $n + 1);
906
-			}
907
-			$text = str_replace('_', ' ', $text);
908
-		}
909
-		$o['class'] = null;
910
-	}
911
-
912
-	return _L($text, $args, $o);
866
+    static $traduire = false;
867
+    $o = ['class' => '', 'force' => true, 'sanitize' => true];
868
+    if ($options) {
869
+        // support de l'ancien argument $class
870
+        if (is_string($options)) {
871
+            $options = ['class' => $options];
872
+        }
873
+        $o = array_merge($o, $options);
874
+    }
875
+
876
+    if (!$traduire) {
877
+        $traduire = charger_fonction('traduire', 'inc');
878
+        include_spip('inc/lang');
879
+    }
880
+
881
+    // On peut passer explicitement la langue dans le tableau
882
+    // On utilise le même nom de variable que la globale
883
+    if (isset($args['spip_lang'])) {
884
+        $lang = $args['spip_lang'];
885
+        // On l'enleve pour ne pas le passer au remplacement
886
+        unset($args['spip_lang']);
887
+    } // Sinon on prend la langue du contexte
888
+    else {
889
+        $lang = $GLOBALS['spip_lang'];
890
+    }
891
+    $text = $traduire($texte, $lang);
892
+
893
+    if ($text === null || !strlen($text)) {
894
+        if (!$o['force']) {
895
+            return '';
896
+        }
897
+
898
+        $text = $texte;
899
+
900
+        // pour les chaines non traduites, assurer un service minimum
901
+        if (!$GLOBALS['test_i18n'] && _request('var_mode') != 'traduction') {
902
+            $n = strpos($text, ':');
903
+            if ($n !== false) {
904
+                $text = substr($text, $n + 1);
905
+            }
906
+            $text = str_replace('_', ' ', $text);
907
+        }
908
+        $o['class'] = null;
909
+    }
910
+
911
+    return _L($text, $args, $o);
913 912
 }
914 913
 
915 914
 
@@ -936,53 +935,53 @@  discard block
 block discarded – undo
936 935
  *     texte
937 936
  */
938 937
 function _L($text, $args = [], $options = []) {
939
-	$f = $text;
940
-	$defaut_options = [
941
-		'class' => null,
942
-		'sanitize' => true,
943
-	];
944
-	// support de l'ancien argument $class
945
-	if ($options && is_string($options)) {
946
-		$options = ['class' => $options];
947
-	}
948
-	if (is_array($options)) {
949
-		$options += $defaut_options;
950
-	} else {
951
-		$options = $defaut_options;
952
-	}
953
-
954
-	if (is_array($args) && count($args)) {
955
-		if (!function_exists('interdire_scripts')) {
956
-			include_spip('inc/texte');
957
-		}
958
-		if (!function_exists('echapper_html_suspect')) {
959
-			include_spip('inc/texte_mini');
960
-		}
961
-		foreach ($args as $name => $value) {
962
-			if (str_contains($text, (string) "@$name@")) {
963
-				if ($options['sanitize']) {
964
-					$value = echapper_html_suspect($value);
965
-					$value = interdire_scripts($value, -1);
966
-				}
967
-				if (!empty($options['class'])) {
968
-					$value = "<span class='" . $options['class'] . "'>$value</span>";
969
-				}
970
-				$text = str_replace("@$name@", (string) $value, (string) $text);
971
-				unset($args[$name]);
972
-			}
973
-		}
974
-		// Si des variables n'ont pas ete inserees, le signaler
975
-		// (chaines de langues pas a jour)
976
-		if ($args) {
977
-			spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
978
-		}
979
-	}
980
-
981
-	if (($GLOBALS['test_i18n'] || _request('var_mode') == 'traduction') && is_null($options['class'])) {
982
-		return "<span class='debug-traduction-erreur'>$text</span>";
983
-	} else {
984
-		return $text;
985
-	}
938
+    $f = $text;
939
+    $defaut_options = [
940
+        'class' => null,
941
+        'sanitize' => true,
942
+    ];
943
+    // support de l'ancien argument $class
944
+    if ($options && is_string($options)) {
945
+        $options = ['class' => $options];
946
+    }
947
+    if (is_array($options)) {
948
+        $options += $defaut_options;
949
+    } else {
950
+        $options = $defaut_options;
951
+    }
952
+
953
+    if (is_array($args) && count($args)) {
954
+        if (!function_exists('interdire_scripts')) {
955
+            include_spip('inc/texte');
956
+        }
957
+        if (!function_exists('echapper_html_suspect')) {
958
+            include_spip('inc/texte_mini');
959
+        }
960
+        foreach ($args as $name => $value) {
961
+            if (str_contains($text, (string) "@$name@")) {
962
+                if ($options['sanitize']) {
963
+                    $value = echapper_html_suspect($value);
964
+                    $value = interdire_scripts($value, -1);
965
+                }
966
+                if (!empty($options['class'])) {
967
+                    $value = "<span class='" . $options['class'] . "'>$value</span>";
968
+                }
969
+                $text = str_replace("@$name@", (string) $value, (string) $text);
970
+                unset($args[$name]);
971
+            }
972
+        }
973
+        // Si des variables n'ont pas ete inserees, le signaler
974
+        // (chaines de langues pas a jour)
975
+        if ($args) {
976
+            spip_log("$f:  variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG);
977
+        }
978
+    }
979
+
980
+    if (($GLOBALS['test_i18n'] || _request('var_mode') == 'traduction') && is_null($options['class'])) {
981
+        return "<span class='debug-traduction-erreur'>$text</span>";
982
+    } else {
983
+        return $text;
984
+    }
986 985
 }
987 986
 
988 987
 
@@ -996,13 +995,13 @@  discard block
 block discarded – undo
996 995
  * @return string
997 996
  */
998 997
 function joli_repertoire($rep) {
999
-	$a = substr($rep, 0, 1);
1000
-	if ($a <> '.' && $a <> '/') {
1001
-		$rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
1002
-	}
1003
-	$rep = preg_replace(',(^\.\.\/),', '', $rep);
998
+    $a = substr($rep, 0, 1);
999
+    if ($a <> '.' && $a <> '/') {
1000
+        $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep;
1001
+    }
1002
+    $rep = preg_replace(',(^\.\.\/),', '', $rep);
1004 1003
 
1005
-	return $rep;
1004
+    return $rep;
1006 1005
 }
1007 1006
 
1008 1007
 
@@ -1027,54 +1026,54 @@  discard block
 block discarded – undo
1027 1026
  * @return float|int|string|void
1028 1027
  */
1029 1028
 function spip_timer($t = 'rien', $raw = false) {
1030
-	static $time;
1031
-	$a = time();
1032
-	$b = microtime();
1033
-	// microtime peut contenir les microsecondes et le temps
1034
-	$b = explode(' ', $b);
1035
-	if (count($b) == 2) {
1036
-		$a = end($b);
1037
-	} // plus precis !
1038
-	$b = reset($b);
1039
-	if (!isset($time[$t])) {
1040
-		$time[$t] = $a + $b;
1041
-	} else {
1042
-		$p = ($a + $b - $time[$t]) * 1000;
1043
-		unset($time[$t]);
1029
+    static $time;
1030
+    $a = time();
1031
+    $b = microtime();
1032
+    // microtime peut contenir les microsecondes et le temps
1033
+    $b = explode(' ', $b);
1034
+    if (count($b) == 2) {
1035
+        $a = end($b);
1036
+    } // plus precis !
1037
+    $b = reset($b);
1038
+    if (!isset($time[$t])) {
1039
+        $time[$t] = $a + $b;
1040
+    } else {
1041
+        $p = ($a + $b - $time[$t]) * 1000;
1042
+        unset($time[$t]);
1044 1043
 #			echo "'$p'";exit;
1045
-		if ($raw) {
1046
-			return $p;
1047
-		}
1048
-		if ($p < 1000) {
1049
-			$s = '';
1050
-		} else {
1051
-			$s = sprintf('%d ', $x = floor($p / 1000));
1052
-			$p -= ($x * 1000);
1053
-		}
1044
+        if ($raw) {
1045
+            return $p;
1046
+        }
1047
+        if ($p < 1000) {
1048
+            $s = '';
1049
+        } else {
1050
+            $s = sprintf('%d ', $x = floor($p / 1000));
1051
+            $p -= ($x * 1000);
1052
+        }
1054 1053
 
1055
-		return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1056
-	}
1054
+        return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p);
1055
+    }
1057 1056
 }
1058 1057
 
1059 1058
 
1060 1059
 // Renvoie False si un fichier n'est pas plus vieux que $duree secondes,
1061 1060
 // sinon renvoie True et le date sauf si ca n'est pas souhaite
1062 1061
 function spip_touch($fichier, $duree = 0, $touch = true) {
1063
-	if ($duree) {
1064
-		clearstatcache();
1065
-		if (($f = @filemtime($fichier)) && $f >= time() - $duree) {
1066
-			return false;
1067
-		}
1068
-	}
1069
-	if ($touch !== false) {
1070
-		if (!@touch($fichier)) {
1071
-			spip_unlink($fichier);
1072
-			@touch($fichier);
1073
-		};
1074
-		@chmod($fichier, _SPIP_CHMOD & ~0111);
1075
-	}
1062
+    if ($duree) {
1063
+        clearstatcache();
1064
+        if (($f = @filemtime($fichier)) && $f >= time() - $duree) {
1065
+            return false;
1066
+        }
1067
+    }
1068
+    if ($touch !== false) {
1069
+        if (!@touch($fichier)) {
1070
+            spip_unlink($fichier);
1071
+            @touch($fichier);
1072
+        };
1073
+        @chmod($fichier, _SPIP_CHMOD & ~0111);
1074
+    }
1076 1075
 
1077
-	return true;
1076
+    return true;
1078 1077
 }
1079 1078
 
1080 1079
 
@@ -1085,11 +1084,11 @@  discard block
 block discarded – undo
1085 1084
  * @uses cron()
1086 1085
  **/
1087 1086
 function action_cron() {
1088
-	include_spip('inc/headers');
1089
-	http_response_code(204); // No Content
1090
-	header('Connection: close');
1091
-	define('_DIRECT_CRON_FORCE', true);
1092
-	cron();
1087
+    include_spip('inc/headers');
1088
+    http_response_code(204); // No Content
1089
+    header('Connection: close');
1090
+    define('_DIRECT_CRON_FORCE', true);
1091
+    cron();
1093 1092
 }
1094 1093
 
1095 1094
 /**
@@ -1105,26 +1104,26 @@  discard block
 block discarded – undo
1105 1104
  *     True si la tache a pu être effectuée
1106 1105
  */
1107 1106
 function cron($taches = [], $taches_old = []) {
1108
-	// si pas en mode cron force, laisser tomber.
1109
-	if (!defined('_DIRECT_CRON_FORCE')) {
1110
-		return false;
1111
-	}
1112
-	if (!is_array($taches)) {
1113
-		$taches = $taches_old;
1114
-	} // compat anciens appels
1115
-	// si taches a inserer en base et base inaccessible, laisser tomber
1116
-	// sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1117
-	// queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1118
-	// et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1119
-	if ($taches && count($taches) && !spip_connect()) {
1120
-		return false;
1121
-	}
1122
-	spip_log('cron !', 'jq' . _LOG_DEBUG);
1123
-	if ($genie = charger_fonction('genie', 'inc', true)) {
1124
-		return $genie($taches);
1125
-	}
1126
-
1127
-	return false;
1107
+    // si pas en mode cron force, laisser tomber.
1108
+    if (!defined('_DIRECT_CRON_FORCE')) {
1109
+        return false;
1110
+    }
1111
+    if (!is_array($taches)) {
1112
+        $taches = $taches_old;
1113
+    } // compat anciens appels
1114
+    // si taches a inserer en base et base inaccessible, laisser tomber
1115
+    // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve
1116
+    // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire
1117
+    // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php)
1118
+    if ($taches && count($taches) && !spip_connect()) {
1119
+        return false;
1120
+    }
1121
+    spip_log('cron !', 'jq' . _LOG_DEBUG);
1122
+    if ($genie = charger_fonction('genie', 'inc', true)) {
1123
+        return $genie($taches);
1124
+    }
1125
+
1126
+    return false;
1128 1127
 }
1129 1128
 
1130 1129
 /**
@@ -1156,17 +1155,17 @@  discard block
 block discarded – undo
1156 1155
  *     Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté.
1157 1156
  */
1158 1157
 function job_queue_add(
1159
-	$function,
1160
-	$description,
1161
-	$arguments = [],
1162
-	$file = '',
1163
-	$no_duplicate = false,
1164
-	$time = 0,
1165
-	$priority = 0
1158
+    $function,
1159
+    $description,
1160
+    $arguments = [],
1161
+    $file = '',
1162
+    $no_duplicate = false,
1163
+    $time = 0,
1164
+    $priority = 0
1166 1165
 ) {
1167
-	include_spip('inc/queue');
1166
+    include_spip('inc/queue');
1168 1167
 
1169
-	return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1168
+    return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority);
1170 1169
 }
1171 1170
 
1172 1171
 /**
@@ -1177,9 +1176,9 @@  discard block
 block discarded – undo
1177 1176
  * @return bool
1178 1177
  */
1179 1178
 function job_queue_remove($id_job) {
1180
-	include_spip('inc/queue');
1179
+    include_spip('inc/queue');
1181 1180
 
1182
-	return queue_remove_job($id_job);
1181
+    return queue_remove_job($id_job);
1183 1182
 }
1184 1183
 
1185 1184
 /**
@@ -1192,9 +1191,9 @@  discard block
 block discarded – undo
1192 1191
  *     or an array of simple array to link multiples objet in one time
1193 1192
  */
1194 1193
 function job_queue_link($id_job, $objets) {
1195
-	include_spip('inc/queue');
1194
+    include_spip('inc/queue');
1196 1195
 
1197
-	return queue_link_job($id_job, $objets);
1196
+    return queue_link_job($id_job, $objets);
1198 1197
 }
1199 1198
 
1200 1199
 
@@ -1213,37 +1212,37 @@  discard block
 block discarded – undo
1213 1212
  *  - `null` si la queue n'est pas encore initialisée
1214 1213
  */
1215 1214
 function queue_sleep_time_to_next_job($force = null) {
1216
-	static $queue_next_job_time = -1;
1217
-	if ($force === true) {
1218
-		$queue_next_job_time = -1;
1219
-	} elseif ($force) {
1220
-		$queue_next_job_time = $force;
1221
-	}
1222
-
1223
-	if ($queue_next_job_time == -1) {
1224
-		if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1225
-			define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1226
-		}
1227
-		// utiliser un cache memoire si dispo
1228
-		if (function_exists('cache_get') && defined('_MEMOIZE_MEMORY') && _MEMOIZE_MEMORY) {
1229
-			$queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1230
-		} else {
1231
-			$queue_next_job_time = null;
1232
-			$contenu = null;
1233
-			if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1234
-				$queue_next_job_time = intval($contenu);
1235
-			}
1236
-		}
1237
-	}
1238
-
1239
-	if (is_null($queue_next_job_time)) {
1240
-		return null;
1241
-	}
1242
-	if (!$_SERVER['REQUEST_TIME']) {
1243
-		$_SERVER['REQUEST_TIME'] = time();
1244
-	}
1245
-
1246
-	return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1215
+    static $queue_next_job_time = -1;
1216
+    if ($force === true) {
1217
+        $queue_next_job_time = -1;
1218
+    } elseif ($force) {
1219
+        $queue_next_job_time = $force;
1220
+    }
1221
+
1222
+    if ($queue_next_job_time == -1) {
1223
+        if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) {
1224
+            define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt');
1225
+        }
1226
+        // utiliser un cache memoire si dispo
1227
+        if (function_exists('cache_get') && defined('_MEMOIZE_MEMORY') && _MEMOIZE_MEMORY) {
1228
+            $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME);
1229
+        } else {
1230
+            $queue_next_job_time = null;
1231
+            $contenu = null;
1232
+            if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) {
1233
+                $queue_next_job_time = intval($contenu);
1234
+            }
1235
+        }
1236
+    }
1237
+
1238
+    if (is_null($queue_next_job_time)) {
1239
+        return null;
1240
+    }
1241
+    if (!$_SERVER['REQUEST_TIME']) {
1242
+        $_SERVER['REQUEST_TIME'] = time();
1243
+    }
1244
+
1245
+    return $queue_next_job_time - $_SERVER['REQUEST_TIME'];
1247 1246
 }
1248 1247
 
1249 1248
 
@@ -1255,11 +1254,11 @@  discard block
 block discarded – undo
1255 1254
  * @return string
1256 1255
  */
1257 1256
 function quote_amp($u) {
1258
-	return preg_replace(
1259
-		'/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1260
-		'&amp;',
1261
-		$u
1262
-	);
1257
+    return preg_replace(
1258
+        '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i',
1259
+        '&amp;',
1260
+        $u
1261
+    );
1263 1262
 }
1264 1263
 
1265 1264
 
@@ -1282,27 +1281,27 @@  discard block
 block discarded – undo
1282 1281
  *     Balise HTML `<script>` et son contenu
1283 1282
  **/
1284 1283
 function http_script($script, $src = '', $noscript = '') {
1285
-	static $done = [];
1284
+    static $done = [];
1286 1285
 
1287
-	if ($src && !isset($done[$src])) {
1288
-		$done[$src] = true;
1289
-		$src = find_in_path($src, _JAVASCRIPT);
1290
-		$src = " src='$src'";
1291
-	} else {
1292
-		$src = '';
1293
-	}
1294
-	if ($script) {
1295
-		$script = ("/*<![CDATA[*/\n" .
1296
-			preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1297
-			'/*]]>*/');
1298
-	}
1299
-	if ($noscript) {
1300
-		$noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1301
-	}
1286
+    if ($src && !isset($done[$src])) {
1287
+        $done[$src] = true;
1288
+        $src = find_in_path($src, _JAVASCRIPT);
1289
+        $src = " src='$src'";
1290
+    } else {
1291
+        $src = '';
1292
+    }
1293
+    if ($script) {
1294
+        $script = ("/*<![CDATA[*/\n" .
1295
+            preg_replace(',</([^>]*)>,', '<\/\1>', $script) .
1296
+            '/*]]>*/');
1297
+    }
1298
+    if ($noscript) {
1299
+        $noscript = "<noscript>\n\t$noscript\n</noscript>\n";
1300
+    }
1302 1301
 
1303
-	return ($src || $script || $noscript)
1304
-		? "<script type='text/javascript'$src>$script</script>$noscript"
1305
-		: '';
1302
+    return ($src || $script || $noscript)
1303
+        ? "<script type='text/javascript'$src>$script</script>$noscript"
1304
+        : '';
1306 1305
 }
1307 1306
 
1308 1307
 
@@ -1337,10 +1336,10 @@  discard block
 block discarded – undo
1337 1336
  *     texte échappé
1338 1337
  **/
1339 1338
 function texte_script(?string $texte): string {
1340
-	if ($texte === null || $texte === '') {
1341
-		return '';
1342
-	}
1343
-	return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1339
+    if ($texte === null || $texte === '') {
1340
+        return '';
1341
+    }
1342
+    return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte));
1344 1343
 }
1345 1344
 
1346 1345
 
@@ -1377,68 +1376,68 @@  discard block
 block discarded – undo
1377 1376
  *     Liste des chemins, par ordre de priorité.
1378 1377
  **/
1379 1378
 function _chemin($dir_path = null) {
1380
-	static $path_base = null;
1381
-	static $path_full = null;
1382
-	if ($path_base == null) {
1383
-		// Chemin standard depuis l'espace public
1384
-		$path = defined('_SPIP_PATH') ? _SPIP_PATH :
1385
-			_DIR_RACINE . ':' .
1386
-			_DIR_RACINE . 'squelettes-dist/:' .
1387
-			_DIR_RACINE . 'prive/:' .
1388
-			_DIR_RESTREINT;
1389
-		// Ajouter squelettes/
1390
-		if (@is_dir(_DIR_RACINE . 'squelettes')) {
1391
-			$path = _DIR_RACINE . 'squelettes/:' . $path;
1392
-		}
1393
-		foreach (explode(':', $path) as $dir) {
1394
-			if (strlen($dir) && !str_ends_with($dir, '/')) {
1395
-				$dir .= '/';
1396
-			}
1397
-			$path_base[] = $dir;
1398
-		}
1399
-		$path_full = $path_base;
1400
-		// Et le(s) dossier(s) des squelettes nommes
1401
-		if (strlen($GLOBALS['dossier_squelettes'])) {
1402
-			foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1403
-				array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1404
-			}
1405
-		}
1406
-		$GLOBALS['path_sig'] = md5(serialize($path_full));
1407
-	}
1408
-	if ($dir_path === null) {
1409
-		return $path_full;
1410
-	}
1411
-
1412
-	if (is_array($dir_path) || strlen($dir_path)) {
1413
-		$tete = '';
1414
-		if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1415
-			$tete = array_shift($path_base);
1416
-		}
1417
-		$dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1418
-		$dirs = array_reverse($dirs);
1419
-		foreach ($dirs as $dir_path) {
1420
-			if (!str_ends_with($dir_path, '/')) {
1421
-				$dir_path .= '/';
1422
-			}
1423
-			if (!in_array($dir_path, $path_base)) {
1424
-				array_unshift($path_base, $dir_path);
1425
-			}
1426
-		}
1427
-		if (strlen($tete)) {
1428
-			array_unshift($path_base, $tete);
1429
-		}
1430
-	}
1431
-	$path_full = $path_base;
1432
-	// Et le(s) dossier(s) des squelettes nommes
1433
-	if (strlen($GLOBALS['dossier_squelettes'])) {
1434
-		foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1435
-			array_unshift($path_full, ((isset($d[0]) && $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1436
-		}
1437
-	}
1438
-
1439
-	$GLOBALS['path_sig'] = md5(serialize($path_full));
1440
-
1441
-	return $path_full;
1379
+    static $path_base = null;
1380
+    static $path_full = null;
1381
+    if ($path_base == null) {
1382
+        // Chemin standard depuis l'espace public
1383
+        $path = defined('_SPIP_PATH') ? _SPIP_PATH :
1384
+            _DIR_RACINE . ':' .
1385
+            _DIR_RACINE . 'squelettes-dist/:' .
1386
+            _DIR_RACINE . 'prive/:' .
1387
+            _DIR_RESTREINT;
1388
+        // Ajouter squelettes/
1389
+        if (@is_dir(_DIR_RACINE . 'squelettes')) {
1390
+            $path = _DIR_RACINE . 'squelettes/:' . $path;
1391
+        }
1392
+        foreach (explode(':', $path) as $dir) {
1393
+            if (strlen($dir) && !str_ends_with($dir, '/')) {
1394
+                $dir .= '/';
1395
+            }
1396
+            $path_base[] = $dir;
1397
+        }
1398
+        $path_full = $path_base;
1399
+        // Et le(s) dossier(s) des squelettes nommes
1400
+        if (strlen($GLOBALS['dossier_squelettes'])) {
1401
+            foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1402
+                array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/');
1403
+            }
1404
+        }
1405
+        $GLOBALS['path_sig'] = md5(serialize($path_full));
1406
+    }
1407
+    if ($dir_path === null) {
1408
+        return $path_full;
1409
+    }
1410
+
1411
+    if (is_array($dir_path) || strlen($dir_path)) {
1412
+        $tete = '';
1413
+        if (reset($path_base) == _DIR_RACINE . 'squelettes/') {
1414
+            $tete = array_shift($path_base);
1415
+        }
1416
+        $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path));
1417
+        $dirs = array_reverse($dirs);
1418
+        foreach ($dirs as $dir_path) {
1419
+            if (!str_ends_with($dir_path, '/')) {
1420
+                $dir_path .= '/';
1421
+            }
1422
+            if (!in_array($dir_path, $path_base)) {
1423
+                array_unshift($path_base, $dir_path);
1424
+            }
1425
+        }
1426
+        if (strlen($tete)) {
1427
+            array_unshift($path_base, $tete);
1428
+        }
1429
+    }
1430
+    $path_full = $path_base;
1431
+    // Et le(s) dossier(s) des squelettes nommes
1432
+    if (strlen($GLOBALS['dossier_squelettes'])) {
1433
+        foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) {
1434
+            array_unshift($path_full, ((isset($d[0]) && $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/');
1435
+        }
1436
+    }
1437
+
1438
+    $GLOBALS['path_sig'] = md5(serialize($path_full));
1439
+
1440
+    return $path_full;
1442 1441
 }
1443 1442
 
1444 1443
 /**
@@ -1451,17 +1450,17 @@  discard block
 block discarded – undo
1451 1450
  * @return array Liste de chemins
1452 1451
  **/
1453 1452
 function creer_chemin() {
1454
-	$path_a = _chemin();
1455
-	static $c = '';
1453
+    $path_a = _chemin();
1454
+    static $c = '';
1456 1455
 
1457
-	// on calcule le chemin si le dossier skel a change
1458
-	if ($c != $GLOBALS['dossier_squelettes']) {
1459
-		// assurer le non plantage lors de la montee de version :
1460
-		$c = $GLOBALS['dossier_squelettes'];
1461
-		$path_a = _chemin(''); // forcer un recalcul du chemin
1462
-	}
1456
+    // on calcule le chemin si le dossier skel a change
1457
+    if ($c != $GLOBALS['dossier_squelettes']) {
1458
+        // assurer le non plantage lors de la montee de version :
1459
+        $c = $GLOBALS['dossier_squelettes'];
1460
+        $path_a = _chemin(''); // forcer un recalcul du chemin
1461
+    }
1463 1462
 
1464
-	return $path_a;
1463
+    return $path_a;
1465 1464
 }
1466 1465
 
1467 1466
 
@@ -1473,61 +1472,61 @@  discard block
 block discarded – undo
1473 1472
  * @return string[] Nom des thèmes.
1474 1473
  */
1475 1474
 function lister_themes_prives(): array {
1476
-	static $themes = null;
1477
-	if (is_null($themes)) {
1478
-		// si pas encore definie
1479
-		if (!defined('_SPIP_THEME_PRIVE')) {
1480
-			define('_SPIP_THEME_PRIVE', 'spip');
1481
-		}
1482
-		$themes = [_SPIP_THEME_PRIVE];
1483
-		// Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé
1484
-		// FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp;
1485
-		$prefs = $GLOBALS['visiteur_session']['prefs'] ?? [];
1486
-		if (is_string($prefs) && stripos($prefs, 'a:') === 0) {
1487
-			$prefs = unserialize($prefs);
1488
-		} else {
1489
-			$prefs = [];
1490
-		}
1491
-
1492
-		$theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null;
1493
-		if ($theme && $theme !== _SPIP_THEME_PRIVE) {
1494
-			// placer le theme choisi en tete
1495
-			array_unshift($themes, $theme);
1496
-		}
1497
-	}
1498
-
1499
-	return $themes;
1475
+    static $themes = null;
1476
+    if (is_null($themes)) {
1477
+        // si pas encore definie
1478
+        if (!defined('_SPIP_THEME_PRIVE')) {
1479
+            define('_SPIP_THEME_PRIVE', 'spip');
1480
+        }
1481
+        $themes = [_SPIP_THEME_PRIVE];
1482
+        // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé
1483
+        // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp;
1484
+        $prefs = $GLOBALS['visiteur_session']['prefs'] ?? [];
1485
+        if (is_string($prefs) && stripos($prefs, 'a:') === 0) {
1486
+            $prefs = unserialize($prefs);
1487
+        } else {
1488
+            $prefs = [];
1489
+        }
1490
+
1491
+        $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null;
1492
+        if ($theme && $theme !== _SPIP_THEME_PRIVE) {
1493
+            // placer le theme choisi en tete
1494
+            array_unshift($themes, $theme);
1495
+        }
1496
+    }
1497
+
1498
+    return $themes;
1500 1499
 }
1501 1500
 
1502 1501
 function find_in_theme($file, $subdir = '', $include = false) {
1503
-	static $themefiles = [];
1504
-	if (isset($themefiles["$subdir$file"])) {
1505
-		return $themefiles["$subdir$file"];
1506
-	}
1507
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1508
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1509
-	if (
1510
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1511
-		&& ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg')
1512
-		&& ($f = find_in_theme("$file_svg_generique"))
1513
-	) {
1514
-		if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) {
1515
-			return $themefiles["$subdir$file"] = $fsize;
1516
-		}
1517
-		else {
1518
-			return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1519
-		}
1520
-	}
1521
-
1522
-	$themes = lister_themes_prives();
1523
-	foreach ($themes as $theme) {
1524
-		if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1525
-			return $themefiles["$subdir$file"] = $f;
1526
-		}
1527
-	}
1528
-	spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1529
-
1530
-	return $themefiles["$subdir$file"] = '';
1502
+    static $themefiles = [];
1503
+    if (isset($themefiles["$subdir$file"])) {
1504
+        return $themefiles["$subdir$file"];
1505
+    }
1506
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
1507
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
1508
+    if (
1509
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m)
1510
+        && ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg')
1511
+        && ($f = find_in_theme("$file_svg_generique"))
1512
+    ) {
1513
+        if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) {
1514
+            return $themefiles["$subdir$file"] = $fsize;
1515
+        }
1516
+        else {
1517
+            return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px';
1518
+        }
1519
+    }
1520
+
1521
+    $themes = lister_themes_prives();
1522
+    foreach ($themes as $theme) {
1523
+        if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) {
1524
+            return $themefiles["$subdir$file"] = $f;
1525
+        }
1526
+    }
1527
+    spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme');
1528
+
1529
+    return $themefiles["$subdir$file"] = '';
1531 1530
 }
1532 1531
 
1533 1532
 
@@ -1551,31 +1550,31 @@  discard block
 block discarded – undo
1551 1550
  *     sinon chaîne vide.
1552 1551
  **/
1553 1552
 function chemin_image($icone) {
1554
-	static $icone_renommer;
1555
-	if ($p = strpos($icone, '?')) {
1556
-		$icone = substr($icone, 0, $p);
1557
-	}
1558
-	// gerer le cas d'un double appel en evitant de refaire le travail inutilement
1559
-	if (str_contains($icone, '/') && file_exists($icone)) {
1560
-		return $icone;
1561
-	}
1562
-
1563
-	// si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1564
-	if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) && ($f = find_in_theme("images/$icone"))) {
1565
-		return $f;
1566
-	}
1567
-	// sinon passer par le module de renommage
1568
-	if (is_null($icone_renommer)) {
1569
-		$icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1570
-	}
1571
-	if ($icone_renommer) {
1572
-		[$icone, $fonction] = $icone_renommer($icone, '');
1573
-		if (file_exists($icone)) {
1574
-			return $icone;
1575
-		}
1576
-	}
1577
-
1578
-	return find_in_path($icone, _NOM_IMG_PACK);
1553
+    static $icone_renommer;
1554
+    if ($p = strpos($icone, '?')) {
1555
+        $icone = substr($icone, 0, $p);
1556
+    }
1557
+    // gerer le cas d'un double appel en evitant de refaire le travail inutilement
1558
+    if (str_contains($icone, '/') && file_exists($icone)) {
1559
+        return $icone;
1560
+    }
1561
+
1562
+    // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct
1563
+    if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) && ($f = find_in_theme("images/$icone"))) {
1564
+        return $f;
1565
+    }
1566
+    // sinon passer par le module de renommage
1567
+    if (is_null($icone_renommer)) {
1568
+        $icone_renommer = charger_fonction('icone_renommer', 'inc', true);
1569
+    }
1570
+    if ($icone_renommer) {
1571
+        [$icone, $fonction] = $icone_renommer($icone, '');
1572
+        if (file_exists($icone)) {
1573
+            return $icone;
1574
+        }
1575
+    }
1576
+
1577
+    return find_in_path($icone, _NOM_IMG_PACK);
1579 1578
 }
1580 1579
 
1581 1580
 //
@@ -1613,128 +1612,128 @@  discard block
 block discarded – undo
1613 1612
  *     - false : fichier introuvable
1614 1613
  **/
1615 1614
 function find_in_path($file, $dirname = '', $include = false) {
1616
-	static $dirs = [];
1617
-	static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1618
-	static $c = '';
1619
-
1620
-	if (!$file && !strlen($file)) {
1621
-		return false;
1622
-	}
1623
-
1624
-	// on calcule le chemin si le dossier skel a change
1625
-	if ($c != $GLOBALS['dossier_squelettes']) {
1626
-		// assurer le non plantage lors de la montee de version :
1627
-		$c = $GLOBALS['dossier_squelettes'];
1628
-		creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1629
-	}
1630
-
1631
-	if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1632
-		if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1633
-			return false;
1634
-		}
1635
-		if ($include && !isset($inc[$dirname][$file])) {
1636
-			include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1637
-			$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1638
-		}
1639
-
1640
-		return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1641
-	}
1642
-
1643
-	$a = strrpos($file, '/');
1644
-	if ($a !== false) {
1645
-		$dirname .= substr($file, 0, ++$a);
1646
-		$file = substr($file, $a);
1647
-	}
1648
-
1649
-	foreach (creer_chemin() as $dir) {
1650
-		if (!isset($dirs[$a = $dir . $dirname])) {
1651
-			$dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1652
-		}
1653
-		if ($dirs[$a]) {
1654
-			if (file_exists(_ROOT_CWD . ($a .= $file))) {
1655
-				if ($include && !isset($inc[$dirname][$file])) {
1656
-					include_once _ROOT_CWD . $a;
1657
-					$inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1658
-				}
1659
-				if (!defined('_SAUVER_CHEMIN')) {
1660
-					// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1661
-					if (is_null($GLOBALS['path_files'])) {
1662
-						return $a;
1663
-					}
1664
-					define('_SAUVER_CHEMIN', true);
1665
-				}
1666
-
1667
-				return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1668
-			}
1669
-		}
1670
-	}
1671
-
1672
-	if ($include) {
1673
-		spip_log("include_spip $dirname$file non trouve");
1674
-		if ($include === 'required') {
1675
-			echo '<pre>',
1676
-			'<strong>Erreur Fatale</strong><br />';
1677
-			if (function_exists('debug_print_backtrace')) {
1678
-				debug_print_backtrace();
1679
-			}
1680
-			echo '</pre>';
1681
-			die("Erreur interne: ne peut inclure $dirname$file");
1682
-		}
1683
-	}
1684
-
1685
-	if (!defined('_SAUVER_CHEMIN')) {
1686
-		// si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1687
-		if (is_null($GLOBALS['path_files'])) {
1688
-			return false;
1689
-		}
1690
-		define('_SAUVER_CHEMIN', true);
1691
-	}
1692
-
1693
-	return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1615
+    static $dirs = [];
1616
+    static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec
1617
+    static $c = '';
1618
+
1619
+    if (!$file && !strlen($file)) {
1620
+        return false;
1621
+    }
1622
+
1623
+    // on calcule le chemin si le dossier skel a change
1624
+    if ($c != $GLOBALS['dossier_squelettes']) {
1625
+        // assurer le non plantage lors de la montee de version :
1626
+        $c = $GLOBALS['dossier_squelettes'];
1627
+        creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig
1628
+    }
1629
+
1630
+    if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) {
1631
+        if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) {
1632
+            return false;
1633
+        }
1634
+        if ($include && !isset($inc[$dirname][$file])) {
1635
+            include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1636
+            $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1637
+        }
1638
+
1639
+        return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file];
1640
+    }
1641
+
1642
+    $a = strrpos($file, '/');
1643
+    if ($a !== false) {
1644
+        $dirname .= substr($file, 0, ++$a);
1645
+        $file = substr($file, $a);
1646
+    }
1647
+
1648
+    foreach (creer_chemin() as $dir) {
1649
+        if (!isset($dirs[$a = $dir . $dirname])) {
1650
+            $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a);
1651
+        }
1652
+        if ($dirs[$a]) {
1653
+            if (file_exists(_ROOT_CWD . ($a .= $file))) {
1654
+                if ($include && !isset($inc[$dirname][$file])) {
1655
+                    include_once _ROOT_CWD . $a;
1656
+                    $inc[$dirname][$file] = $inc[''][$dirname . $file] = true;
1657
+                }
1658
+                if (!defined('_SAUVER_CHEMIN')) {
1659
+                    // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1660
+                    if (is_null($GLOBALS['path_files'])) {
1661
+                        return $a;
1662
+                    }
1663
+                    define('_SAUVER_CHEMIN', true);
1664
+                }
1665
+
1666
+                return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a;
1667
+            }
1668
+        }
1669
+    }
1670
+
1671
+    if ($include) {
1672
+        spip_log("include_spip $dirname$file non trouve");
1673
+        if ($include === 'required') {
1674
+            echo '<pre>',
1675
+            '<strong>Erreur Fatale</strong><br />';
1676
+            if (function_exists('debug_print_backtrace')) {
1677
+                debug_print_backtrace();
1678
+            }
1679
+            echo '</pre>';
1680
+            die("Erreur interne: ne peut inclure $dirname$file");
1681
+        }
1682
+    }
1683
+
1684
+    if (!defined('_SAUVER_CHEMIN')) {
1685
+        // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher
1686
+        if (is_null($GLOBALS['path_files'])) {
1687
+            return false;
1688
+        }
1689
+        define('_SAUVER_CHEMIN', true);
1690
+    }
1691
+
1692
+    return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false;
1694 1693
 }
1695 1694
 
1696 1695
 function clear_path_cache() {
1697
-	$GLOBALS['path_files'] = [];
1698
-	spip_unlink(_CACHE_CHEMIN);
1696
+    $GLOBALS['path_files'] = [];
1697
+    spip_unlink(_CACHE_CHEMIN);
1699 1698
 }
1700 1699
 
1701 1700
 function load_path_cache() {
1702
-	// charger le path des plugins
1703
-	if (@is_readable(_CACHE_PLUGINS_PATH)) {
1704
-		include_once(_CACHE_PLUGINS_PATH);
1705
-	}
1706
-	$GLOBALS['path_files'] = [];
1707
-	// si le visiteur est admin,
1708
-	// on ne recharge pas le cache pour forcer sa mise a jour
1709
-	if (
1710
-		// la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1711
-		//AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1712
-		// utiliser le cookie est un pis aller qui marche 'en general'
1713
-		// on blinde par un second test au moment de la lecture de la session
1714
-		// !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1715
-		// et en ignorant ce cache en cas de recalcul explicite
1716
-		!_request('var_mode')
1717
-	) {
1718
-		// on essaye de lire directement sans verrou pour aller plus vite
1719
-		if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1720
-			// mais si semble corrompu on relit avec un verrou
1721
-			if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1722
-				lire_fichier(_CACHE_CHEMIN, $contenu);
1723
-				if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1724
-					$GLOBALS['path_files'] = [];
1725
-				}
1726
-			}
1727
-		}
1728
-	}
1701
+    // charger le path des plugins
1702
+    if (@is_readable(_CACHE_PLUGINS_PATH)) {
1703
+        include_once(_CACHE_PLUGINS_PATH);
1704
+    }
1705
+    $GLOBALS['path_files'] = [];
1706
+    // si le visiteur est admin,
1707
+    // on ne recharge pas le cache pour forcer sa mise a jour
1708
+    if (
1709
+        // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier
1710
+        //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo')
1711
+        // utiliser le cookie est un pis aller qui marche 'en general'
1712
+        // on blinde par un second test au moment de la lecture de la session
1713
+        // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin'])
1714
+        // et en ignorant ce cache en cas de recalcul explicite
1715
+        !_request('var_mode')
1716
+    ) {
1717
+        // on essaye de lire directement sans verrou pour aller plus vite
1718
+        if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) {
1719
+            // mais si semble corrompu on relit avec un verrou
1720
+            if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1721
+                lire_fichier(_CACHE_CHEMIN, $contenu);
1722
+                if (!$GLOBALS['path_files'] = unserialize($contenu)) {
1723
+                    $GLOBALS['path_files'] = [];
1724
+                }
1725
+            }
1726
+        }
1727
+    }
1729 1728
 }
1730 1729
 
1731 1730
 function save_path_cache() {
1732
-	if (
1733
-		defined('_SAUVER_CHEMIN')
1734
-		&& _SAUVER_CHEMIN
1735
-	) {
1736
-		ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1737
-	}
1731
+    if (
1732
+        defined('_SAUVER_CHEMIN')
1733
+        && _SAUVER_CHEMIN
1734
+    ) {
1735
+        ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files']));
1736
+    }
1738 1737
 }
1739 1738
 
1740 1739
 
@@ -1754,33 +1753,33 @@  discard block
 block discarded – undo
1754 1753
  * @return array
1755 1754
  */
1756 1755
 function find_all_in_path($dir, $pattern, $recurs = false) {
1757
-	$liste_fichiers = [];
1758
-	$maxfiles = 10000;
1759
-
1760
-	// cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1761
-	// on a pas encore inclus flock.php
1762
-	if (!function_exists('preg_files')) {
1763
-		include_once _ROOT_RESTREINT . 'inc/flock.php';
1764
-	}
1765
-
1766
-	// Parcourir le chemin
1767
-	foreach (creer_chemin() as $d) {
1768
-		$f = $d . $dir;
1769
-		if (@is_dir($f)) {
1770
-			$liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1771
-			foreach ($liste as $chemin) {
1772
-				$nom = basename($chemin);
1773
-				// ne prendre que les fichiers pas deja trouves
1774
-				// car find_in_path prend le premier qu'il trouve,
1775
-				// les autres sont donc masques
1776
-				if (!isset($liste_fichiers[$nom])) {
1777
-					$liste_fichiers[$nom] = $chemin;
1778
-				}
1779
-			}
1780
-		}
1781
-	}
1782
-
1783
-	return $liste_fichiers;
1756
+    $liste_fichiers = [];
1757
+    $maxfiles = 10000;
1758
+
1759
+    // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue
1760
+    // on a pas encore inclus flock.php
1761
+    if (!function_exists('preg_files')) {
1762
+        include_once _ROOT_RESTREINT . 'inc/flock.php';
1763
+    }
1764
+
1765
+    // Parcourir le chemin
1766
+    foreach (creer_chemin() as $d) {
1767
+        $f = $d . $dir;
1768
+        if (@is_dir($f)) {
1769
+            $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs);
1770
+            foreach ($liste as $chemin) {
1771
+                $nom = basename($chemin);
1772
+                // ne prendre que les fichiers pas deja trouves
1773
+                // car find_in_path prend le premier qu'il trouve,
1774
+                // les autres sont donc masques
1775
+                if (!isset($liste_fichiers[$nom])) {
1776
+                    $liste_fichiers[$nom] = $chemin;
1777
+                }
1778
+            }
1779
+        }
1780
+    }
1781
+
1782
+    return $liste_fichiers;
1784 1783
 }
1785 1784
 
1786 1785
 /**
@@ -1792,17 +1791,17 @@  discard block
 block discarded – undo
1792 1791
  * @return bool
1793 1792
  */
1794 1793
 function autoriser_sans_cookie($nom, $strict = false) {
1795
-	static $autsanscookie = ['install', 'base_repair'];
1794
+    static $autsanscookie = ['install', 'base_repair'];
1796 1795
 
1797
-	if (in_array($nom, $autsanscookie)) {
1798
-		if (test_espace_prive()) {
1799
-			include_spip('base/connect_sql');
1800
-			if (!$strict || !spip_connect()) {
1801
-				return true;
1802
-			}
1803
-		}
1804
-	}
1805
-	return false;
1796
+    if (in_array($nom, $autsanscookie)) {
1797
+        if (test_espace_prive()) {
1798
+            include_spip('base/connect_sql');
1799
+            if (!$strict || !spip_connect()) {
1800
+                return true;
1801
+            }
1802
+        }
1803
+    }
1804
+    return false;
1806 1805
 }
1807 1806
 
1808 1807
 /**
@@ -1814,59 +1813,59 @@  discard block
 block discarded – undo
1814 1813
  * @return string
1815 1814
  */
1816 1815
 function charger_fonction_url(string $quoi, string $type = '') {
1817
-	if ($type === 'defaut') {
1818
-		$objet = objet_type($quoi);
1819
-		if (
1820
-			($f = charger_fonction('generer_' . $objet . '_url', 'urls', true))
1821
-			|| ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated
1822
-		) {
1823
-			return $f;
1824
-		}
1825
-		return '';
1826
-	}
1827
-
1828
-	$url_type = $type;
1829
-	if (!$url_type) {
1830
-		$url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1831
-	}
1832
-
1833
-	// inclure le module d'url
1834
-	include_spip('urls/' . $url_type);
1835
-
1836
-	switch ($quoi) {
1837
-		case 'page':
1838
-			if (
1839
-				function_exists($f = "urls_{$url_type}_generer_url_page")
1840
-				|| function_exists($f .= '_dist')
1841
-				// ou une fonction custom utilisateur independante du type d'url
1842
-				|| function_exists($f = 'generer_url_page')
1843
-				|| function_exists($f .= '_dist')
1844
-			) {
1845
-				return $f;
1846
-			}
1847
-			// pas de compat ancienne version ici, c'est une nouvelle feature
1848
-			return '';
1849
-		case 'objet':
1850
-		case 'decoder':
1851
-		default:
1852
-			$fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1853
-			if (
1854
-				function_exists($f = "urls_{$url_type}_{$fquoi}")
1855
-				|| function_exists($f .= '_dist')
1856
-			) {
1857
-				return $f;
1858
-			}
1859
-			// est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1860
-			// c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1861
-			if ($f = charger_fonction($url_type, 'urls', true)) {
1862
-				return $f;
1863
-			}
1864
-			// sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1865
-			if (!$type && $url_type !== 'page') {
1866
-				return charger_fonction_url($quoi, 'page');
1867
-			}
1868
-			return '';
1869
-	}
1816
+    if ($type === 'defaut') {
1817
+        $objet = objet_type($quoi);
1818
+        if (
1819
+            ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true))
1820
+            || ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated
1821
+        ) {
1822
+            return $f;
1823
+        }
1824
+        return '';
1825
+    }
1826
+
1827
+    $url_type = $type;
1828
+    if (!$url_type) {
1829
+        $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut
1830
+    }
1831
+
1832
+    // inclure le module d'url
1833
+    include_spip('urls/' . $url_type);
1834
+
1835
+    switch ($quoi) {
1836
+        case 'page':
1837
+            if (
1838
+                function_exists($f = "urls_{$url_type}_generer_url_page")
1839
+                || function_exists($f .= '_dist')
1840
+                // ou une fonction custom utilisateur independante du type d'url
1841
+                || function_exists($f = 'generer_url_page')
1842
+                || function_exists($f .= '_dist')
1843
+            ) {
1844
+                return $f;
1845
+            }
1846
+            // pas de compat ancienne version ici, c'est une nouvelle feature
1847
+            return '';
1848
+        case 'objet':
1849
+        case 'decoder':
1850
+        default:
1851
+            $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url');
1852
+            if (
1853
+                function_exists($f = "urls_{$url_type}_{$fquoi}")
1854
+                || function_exists($f .= '_dist')
1855
+            ) {
1856
+                return $f;
1857
+            }
1858
+            // est-ce qu'on a une ancienne fonction urls_xxx_dist() ?
1859
+            // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout
1860
+            if ($f = charger_fonction($url_type, 'urls', true)) {
1861
+                return $f;
1862
+            }
1863
+            // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement
1864
+            if (!$type && $url_type !== 'page') {
1865
+                return charger_fonction_url($quoi, 'page');
1866
+            }
1867
+            return '';
1868
+    }
1870 1869
 }
1871 1870
 
1872 1871
 
@@ -1892,48 +1891,48 @@  discard block
 block discarded – undo
1892 1891
  *   url codee ou fonction de decodage
1893 1892
  */
1894 1893
 function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
1895
-	if ($public === null) {
1896
-		$public = !test_espace_prive();
1897
-	}
1898
-	$id = intval($id);
1899
-	$entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1900
-
1901
-	if (!$public) {
1902
-		if (!$entite) {
1903
-			return '';
1904
-		}
1905
-		if (!function_exists('generer_objet_url_ecrire')) {
1906
-			include_spip('inc/urls');
1907
-		}
1908
-		$res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1909
-	} else {
1910
-		$f = charger_fonction_url('objet', $type ?? '');
1911
-
1912
-		// @deprecated si $entite='', on veut la fonction de passage URL ==> id
1913
-		// @see charger_fonction_url
1914
-		if (!$entite) {
1915
-			return $f;
1916
-		}
1917
-
1918
-		// mais d'abord il faut tester le cas des urls sur une
1919
-		// base distante
1920
-		if (
1921
-			$connect
1922
-			&& ($g = charger_fonction('connect', 'urls', true))
1923
-		) {
1924
-			$f = $g;
1925
-		}
1926
-
1927
-		$res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1928
-	}
1929
-	if ($res) {
1930
-		return $res;
1931
-	}
1932
-
1933
-	// On a ete gentil mais la ....
1934
-	spip_log("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect", _LOG_ERREUR);
1935
-
1936
-	return '';
1894
+    if ($public === null) {
1895
+        $public = !test_espace_prive();
1896
+    }
1897
+    $id = intval($id);
1898
+    $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet...
1899
+
1900
+    if (!$public) {
1901
+        if (!$entite) {
1902
+            return '';
1903
+        }
1904
+        if (!function_exists('generer_objet_url_ecrire')) {
1905
+            include_spip('inc/urls');
1906
+        }
1907
+        $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect);
1908
+    } else {
1909
+        $f = charger_fonction_url('objet', $type ?? '');
1910
+
1911
+        // @deprecated si $entite='', on veut la fonction de passage URL ==> id
1912
+        // @see charger_fonction_url
1913
+        if (!$entite) {
1914
+            return $f;
1915
+        }
1916
+
1917
+        // mais d'abord il faut tester le cas des urls sur une
1918
+        // base distante
1919
+        if (
1920
+            $connect
1921
+            && ($g = charger_fonction('connect', 'urls', true))
1922
+        ) {
1923
+            $f = $g;
1924
+        }
1925
+
1926
+        $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect);
1927
+    }
1928
+    if ($res) {
1929
+        return $res;
1930
+    }
1931
+
1932
+    // On a ete gentil mais la ....
1933
+    spip_log("generer_objet_url: entite $entite " . ($public ? "($f)" : '') . " inconnue $type $public $connect", _LOG_ERREUR);
1934
+
1935
+    return '';
1937 1936
 }
1938 1937
 
1939 1938
 /**
@@ -1941,11 +1940,11 @@  discard block
 block discarded – undo
1941 1940
  * @see generer_objet_url
1942 1941
  */
1943 1942
 function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) {
1944
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url');
1945
-	if ($public && is_string($public)) {
1946
-		return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1947
-	}
1948
-	return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1943
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url');
1944
+    if ($public && is_string($public)) {
1945
+        return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public);
1946
+    }
1947
+    return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? '');
1949 1948
 }
1950 1949
 
1951 1950
 /**
@@ -1953,19 +1952,19 @@  discard block
 block discarded – undo
1953 1952
  * @param int|string|null $id
1954 1953
  */
1955 1954
 function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string {
1956
-	$id = intval($id);
1957
-	$exec = objet_info($entite, 'url_edit');
1958
-	$url = generer_url_ecrire($exec, $args);
1959
-	if (intval($id)) {
1960
-		$url = parametre_url($url, id_table_objet($entite), $id);
1961
-	} else {
1962
-		$url = parametre_url($url, 'new', 'oui');
1963
-	}
1964
-	if ($ancre) {
1965
-		$url = ancre_url($url, $ancre);
1966
-	}
1955
+    $id = intval($id);
1956
+    $exec = objet_info($entite, 'url_edit');
1957
+    $url = generer_url_ecrire($exec, $args);
1958
+    if (intval($id)) {
1959
+        $url = parametre_url($url, id_table_objet($entite), $id);
1960
+    } else {
1961
+        $url = parametre_url($url, 'new', 'oui');
1962
+    }
1963
+    if ($ancre) {
1964
+        $url = ancre_url($url, $ancre);
1965
+    }
1967 1966
 
1968
-	return $url;
1967
+    return $url;
1969 1968
 }
1970 1969
 
1971 1970
 /**
@@ -1973,19 +1972,19 @@  discard block
 block discarded – undo
1973 1972
  * @see generer_objet_url_ecrire_edit
1974 1973
  */
1975 1974
 function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') {
1976
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit');
1977
-	return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1975
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_ecrire_edit');
1976
+    return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre);
1978 1977
 }
1979 1978
 
1980 1979
 
1981 1980
 function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) {
1982
-	include_spip('base/connect_sql');
1983
-	$id_type = id_table_objet($entite, $public);
1981
+    include_spip('base/connect_sql');
1982
+    $id_type = id_table_objet($entite, $public);
1984 1983
 
1985
-	return _DIR_RACINE . get_spip_script('./')
1986
-	. '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1987
-	. (!$args ? '' : "&$args")
1988
-	. (!$ancre ? '' : "#$ancre");
1984
+    return _DIR_RACINE . get_spip_script('./')
1985
+    . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public"
1986
+    . (!$args ? '' : "&$args")
1987
+    . (!$ancre ? '' : "#$ancre");
1989 1988
 }
1990 1989
 
1991 1990
 
@@ -1996,18 +1995,18 @@  discard block
 block discarded – undo
1996 1995
  * @return string
1997 1996
  */
1998 1997
 function urlencode_1738($url) {
1999
-	if (preg_match(',[^\x00-\x7E],sS', $url)) {
2000
-		$uri = '';
2001
-		for ($i = 0; $i < strlen($url); $i++) {
2002
-			if (ord($a = $url[$i]) > 127) {
2003
-				$a = rawurlencode($a);
2004
-			}
2005
-			$uri .= $a;
2006
-		}
2007
-		$url = $uri;
2008
-	}
1998
+    if (preg_match(',[^\x00-\x7E],sS', $url)) {
1999
+        $uri = '';
2000
+        for ($i = 0; $i < strlen($url); $i++) {
2001
+            if (ord($a = $url[$i]) > 127) {
2002
+                $a = rawurlencode($a);
2003
+            }
2004
+            $uri .= $a;
2005
+        }
2006
+        $url = $uri;
2007
+    }
2009 2008
 
2010
-	return quote_amp($url);
2009
+    return quote_amp($url);
2011 2010
 }
2012 2011
 
2013 2012
 /**
@@ -2016,14 +2015,14 @@  discard block
 block discarded – undo
2016 2015
  * @param int|string|null $id
2017 2016
  */
2018 2017
 function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string {
2019
-	$id = intval($id);
2020
-	$h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
2021
-	if (!preg_match(',^\w+:,', $h)) {
2022
-		include_spip('inc/filtres_mini');
2023
-		$h = url_absolue($h);
2024
-	}
2018
+    $id = intval($id);
2019
+    $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect);
2020
+    if (!preg_match(',^\w+:,', $h)) {
2021
+        include_spip('inc/filtres_mini');
2022
+        $h = url_absolue($h);
2023
+    }
2025 2024
 
2026
-	return $h;
2025
+    return $h;
2027 2026
 }
2028 2027
 
2029 2028
 /**
@@ -2031,8 +2030,8 @@  discard block
 block discarded – undo
2031 2030
  * @see  generer_objet_url_absolue
2032 2031
  */
2033 2032
 function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) {
2034
-	trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue');
2035
-	return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
2033
+    trigger_deprecation('spip', '4.1', 'Using "%s" is deprecated, use "%s" instead', __FUNCTION__, 'generer_objet_url_absolue');
2034
+    return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect ?? '');
2036 2035
 }
2037 2036
 
2038 2037
 
@@ -2048,11 +2047,11 @@  discard block
 block discarded – undo
2048 2047
  *     true si la valeur est considérée active ; false sinon.
2049 2048
  **/
2050 2049
 function test_valeur_serveur($truc) {
2051
-	if (!$truc) {
2052
-		return false;
2053
-	}
2050
+    if (!$truc) {
2051
+        return false;
2052
+    }
2054 2053
 
2055
-	return (strtolower($truc) !== 'off');
2054
+    return (strtolower($truc) !== 'off');
2056 2055
 }
2057 2056
 
2058 2057
 //
@@ -2080,89 +2079,89 @@  discard block
 block discarded – undo
2080 2079
  */
2081 2080
 function url_de_base($profondeur = null) {
2082 2081
 
2083
-	static $url = [];
2084
-	if (is_array($profondeur)) {
2085
-		return $url = $profondeur;
2086
-	}
2087
-	if ($profondeur === false) {
2088
-		return $url;
2089
-	}
2090
-
2091
-	if (is_null($profondeur)) {
2092
-		$profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2093
-	}
2094
-
2095
-	if (isset($url[$profondeur])) {
2096
-		return $url[$profondeur];
2097
-	}
2098
-
2099
-	$http = 'http';
2100
-
2101
-	if (
2102
-		isset($_SERVER['SCRIPT_URI'])
2103
-		&& str_starts_with($_SERVER['SCRIPT_URI'], 'https')
2104
-	) {
2105
-		$http = 'https';
2106
-	} elseif (
2107
-		isset($_SERVER['HTTPS'])
2108
-		&& test_valeur_serveur($_SERVER['HTTPS'])
2109
-	) {
2110
-		$http = 'https';
2111
-	}
2112
-
2113
-	// note : HTTP_HOST contient le :port si necessaire
2114
-	if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2115
-		// Filtrer $host pour proteger d'attaques d'entete HTTP
2116
-		$host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2117
-	}
2118
-
2119
-	// si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2120
-	if (is_null($host) && isset($GLOBALS['meta']['adresse_site'])) {
2121
-		$host = $GLOBALS['meta']['adresse_site'];
2122
-		if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2123
-			$http = $scheme;
2124
-			$host = str_replace("{$scheme}://", '', $host);
2125
-		}
2126
-	}
2127
-	if (
2128
-		isset($_SERVER['SERVER_PORT'])
2129
-		&& ($port = $_SERVER['SERVER_PORT'])
2130
-		&& !str_contains($host, ':')
2131
-	) {
2132
-		if (!defined('_PORT_HTTP_STANDARD')) {
2133
-			define('_PORT_HTTP_STANDARD', '80');
2134
-		}
2135
-		if (!defined('_PORT_HTTPS_STANDARD')) {
2136
-			define('_PORT_HTTPS_STANDARD', '443');
2137
-		}
2138
-		if ($http == 'http' && !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2139
-			$host .= ":$port";
2140
-		}
2141
-		if ($http == 'https' && !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2142
-			$host .= ":$port";
2143
-		}
2144
-	}
2145
-
2146
-	if (!$GLOBALS['REQUEST_URI']) {
2147
-		if (isset($_SERVER['REQUEST_URI'])) {
2148
-			$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2149
-		} else {
2150
-			$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2151
-			if (
2152
-				!empty($_SERVER['QUERY_STRING'])
2153
-				&& !str_contains($_SERVER['REQUEST_URI'], '?')
2154
-			) {
2155
-				$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2156
-			}
2157
-		}
2158
-	}
2159
-
2160
-	// Et nettoyer l'url
2161
-	$GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2162
-
2163
-	$url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2164
-
2165
-	return $url[$profondeur];
2082
+    static $url = [];
2083
+    if (is_array($profondeur)) {
2084
+        return $url = $profondeur;
2085
+    }
2086
+    if ($profondeur === false) {
2087
+        return $url;
2088
+    }
2089
+
2090
+    if (is_null($profondeur)) {
2091
+        $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1);
2092
+    }
2093
+
2094
+    if (isset($url[$profondeur])) {
2095
+        return $url[$profondeur];
2096
+    }
2097
+
2098
+    $http = 'http';
2099
+
2100
+    if (
2101
+        isset($_SERVER['SCRIPT_URI'])
2102
+        && str_starts_with($_SERVER['SCRIPT_URI'], 'https')
2103
+    ) {
2104
+        $http = 'https';
2105
+    } elseif (
2106
+        isset($_SERVER['HTTPS'])
2107
+        && test_valeur_serveur($_SERVER['HTTPS'])
2108
+    ) {
2109
+        $http = 'https';
2110
+    }
2111
+
2112
+    // note : HTTP_HOST contient le :port si necessaire
2113
+    if ($host = $_SERVER['HTTP_HOST'] ?? null) {
2114
+        // Filtrer $host pour proteger d'attaques d'entete HTTP
2115
+        $host = (filter_var($host, FILTER_SANITIZE_URL) ?: null);
2116
+    }
2117
+
2118
+    // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback
2119
+    if (is_null($host) && isset($GLOBALS['meta']['adresse_site'])) {
2120
+        $host = $GLOBALS['meta']['adresse_site'];
2121
+        if ($scheme = parse_url($host, PHP_URL_SCHEME)) {
2122
+            $http = $scheme;
2123
+            $host = str_replace("{$scheme}://", '', $host);
2124
+        }
2125
+    }
2126
+    if (
2127
+        isset($_SERVER['SERVER_PORT'])
2128
+        && ($port = $_SERVER['SERVER_PORT'])
2129
+        && !str_contains($host, ':')
2130
+    ) {
2131
+        if (!defined('_PORT_HTTP_STANDARD')) {
2132
+            define('_PORT_HTTP_STANDARD', '80');
2133
+        }
2134
+        if (!defined('_PORT_HTTPS_STANDARD')) {
2135
+            define('_PORT_HTTPS_STANDARD', '443');
2136
+        }
2137
+        if ($http == 'http' && !in_array($port, explode(',', _PORT_HTTP_STANDARD))) {
2138
+            $host .= ":$port";
2139
+        }
2140
+        if ($http == 'https' && !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) {
2141
+            $host .= ":$port";
2142
+        }
2143
+    }
2144
+
2145
+    if (!$GLOBALS['REQUEST_URI']) {
2146
+        if (isset($_SERVER['REQUEST_URI'])) {
2147
+            $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2148
+        } else {
2149
+            $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2150
+            if (
2151
+                !empty($_SERVER['QUERY_STRING'])
2152
+                && !str_contains($_SERVER['REQUEST_URI'], '?')
2153
+            ) {
2154
+                $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2155
+            }
2156
+        }
2157
+    }
2158
+
2159
+    // Et nettoyer l'url
2160
+    $GLOBALS['REQUEST_URI'] = (filter_var($GLOBALS['REQUEST_URI'], FILTER_SANITIZE_URL) ?: '');
2161
+
2162
+    $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur);
2163
+
2164
+    return $url[$profondeur];
2166 2165
 }
2167 2166
 
2168 2167
 /**
@@ -2175,26 +2174,26 @@  discard block
 block discarded – undo
2175 2174
  * @return string
2176 2175
  */
2177 2176
 function url_de_($http, $host, $request, $prof = 0) {
2178
-	$prof = max($prof, 0);
2177
+    $prof = max($prof, 0);
2179 2178
 
2180
-	$myself = ltrim($request, '/');
2181
-	# supprimer la chaine de GET
2182
-	[$myself] = explode('?', $myself);
2183
-	// vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2184
-	// protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2185
-	if (str_contains($myself, '://')) {
2186
-		$myself = explode('://', $myself);
2187
-		array_shift($myself);
2188
-		$myself = implode('://', $myself);
2189
-		$myself = explode('/', $myself);
2190
-		array_shift($myself);
2191
-		$myself = implode('/', $myself);
2192
-	}
2193
-	$url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2179
+    $myself = ltrim($request, '/');
2180
+    # supprimer la chaine de GET
2181
+    [$myself] = explode('?', $myself);
2182
+    // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte
2183
+    // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"]
2184
+    if (str_contains($myself, '://')) {
2185
+        $myself = explode('://', $myself);
2186
+        array_shift($myself);
2187
+        $myself = implode('://', $myself);
2188
+        $myself = explode('/', $myself);
2189
+        array_shift($myself);
2190
+        $myself = implode('/', $myself);
2191
+    }
2192
+    $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/';
2194 2193
 
2195
-	$url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2194
+    $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/');
2196 2195
 
2197
-	return $url;
2196
+    return $url;
2198 2197
 }
2199 2198
 
2200 2199
 
@@ -2229,26 +2228,26 @@  discard block
 block discarded – undo
2229 2228
  * @return string URL
2230 2229
  **/
2231 2230
 function generer_url_ecrire(?string $script = '', $args = '', $no_entities = false, $rel = false) {
2232
-	$script ??= '';
2233
-	if (!$rel) {
2234
-		$rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2235
-	} else {
2236
-		if (!is_string($rel)) {
2237
-			$rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2238
-		}
2239
-	}
2240
-
2241
-	[$script, $ancre] = array_pad(explode('#', $script), 2, null);
2242
-	if ($script && ($script <> 'accueil' || $rel)) {
2243
-		$args = "?exec=$script" . (!$args ? '' : "&$args");
2244
-	} elseif ($args) {
2245
-		$args = "?$args";
2246
-	}
2247
-	if ($ancre) {
2248
-		$args .= "#$ancre";
2249
-	}
2250
-
2251
-	return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2231
+    $script ??= '';
2232
+    if (!$rel) {
2233
+        $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT;
2234
+    } else {
2235
+        if (!is_string($rel)) {
2236
+            $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT;
2237
+        }
2238
+    }
2239
+
2240
+    [$script, $ancre] = array_pad(explode('#', $script), 2, null);
2241
+    if ($script && ($script <> 'accueil' || $rel)) {
2242
+        $args = "?exec=$script" . (!$args ? '' : "&$args");
2243
+    } elseif ($args) {
2244
+        $args = "?$args";
2245
+    }
2246
+    if ($ancre) {
2247
+        $args .= "#$ancre";
2248
+    }
2249
+
2250
+    return $rel . ($no_entities ? $args : str_replace('&', '&amp;', $args));
2252 2251
 }
2253 2252
 
2254 2253
 //
@@ -2270,15 +2269,15 @@  discard block
 block discarded – undo
2270 2269
  *     Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut
2271 2270
  **/
2272 2271
 function get_spip_script($default = '') {
2273
-	if (!defined('_SPIP_SCRIPT')) {
2274
-		return 'spip.php';
2275
-	}
2276
-	# cas define('_SPIP_SCRIPT', '');
2277
-	if (_SPIP_SCRIPT) {
2278
-		return _SPIP_SCRIPT;
2279
-	} else {
2280
-		return $default;
2281
-	}
2272
+    if (!defined('_SPIP_SCRIPT')) {
2273
+        return 'spip.php';
2274
+    }
2275
+    # cas define('_SPIP_SCRIPT', '');
2276
+    if (_SPIP_SCRIPT) {
2277
+        return _SPIP_SCRIPT;
2278
+    } else {
2279
+        return $default;
2280
+    }
2282 2281
 }
2283 2282
 
2284 2283
 /**
@@ -2307,45 +2306,45 @@  discard block
 block discarded – undo
2307 2306
  * @return string URL
2308 2307
  **/
2309 2308
 function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') {
2310
-	// si le script est une action (spip_pass, spip_inscription),
2311
-	// standardiser vers la nouvelle API
2312
-
2313
-	if (is_array($args)) {
2314
-		$args = http_build_query($args);
2315
-	}
2316
-
2317
-	$url = '';
2318
-	if ($f = charger_fonction_url('page')) {
2319
-		$url = $f($script, $args);
2320
-		if ($url && !$rel) {
2321
-			include_spip('inc/filtres_mini');
2322
-			$url = url_absolue($url);
2323
-		}
2324
-	}
2325
-	if (!$url) {
2326
-		if (!$action) {
2327
-			$action = get_spip_script();
2328
-		}
2329
-		if ($script) {
2330
-			$action = parametre_url($action, _SPIP_PAGE, $script, '&');
2331
-		}
2332
-		if ($args) {
2333
-			$action .= (str_contains($action, '?') ? '&' : '?') . $args;
2334
-		}
2335
-		// ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2336
-		$url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2337
-	}
2338
-
2339
-	if (!$no_entities) {
2340
-		$url = quote_amp($url);
2341
-	}
2342
-
2343
-	return $url;
2309
+    // si le script est une action (spip_pass, spip_inscription),
2310
+    // standardiser vers la nouvelle API
2311
+
2312
+    if (is_array($args)) {
2313
+        $args = http_build_query($args);
2314
+    }
2315
+
2316
+    $url = '';
2317
+    if ($f = charger_fonction_url('page')) {
2318
+        $url = $f($script, $args);
2319
+        if ($url && !$rel) {
2320
+            include_spip('inc/filtres_mini');
2321
+            $url = url_absolue($url);
2322
+        }
2323
+    }
2324
+    if (!$url) {
2325
+        if (!$action) {
2326
+            $action = get_spip_script();
2327
+        }
2328
+        if ($script) {
2329
+            $action = parametre_url($action, _SPIP_PAGE, $script, '&');
2330
+        }
2331
+        if ($args) {
2332
+            $action .= (str_contains($action, '?') ? '&' : '?') . $args;
2333
+        }
2334
+        // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide
2335
+        $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action"));
2336
+    }
2337
+
2338
+    if (!$no_entities) {
2339
+        $url = quote_amp($url);
2340
+    }
2341
+
2342
+    return $url;
2344 2343
 }
2345 2344
 
2346 2345
 function generer_url_prive($script, $args = '', $no_entities = false) {
2347 2346
 
2348
-	return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2347
+    return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php');
2349 2348
 }
2350 2349
 
2351 2350
 // Pour les formulaires en methode POST,
@@ -2370,19 +2369,19 @@  discard block
 block discarded – undo
2370 2369
  **/
2371 2370
 function generer_form_ecrire($script, $corps, $atts = '', $submit = '') {
2372 2371
 
2373
-	$script1 = explode('&', $script);
2374
-	$script1 = reset($script1);
2372
+    $script1 = explode('&', $script);
2373
+    $script1 = reset($script1);
2375 2374
 
2376
-	return "<form action='"
2377
-	. ($script ? generer_url_ecrire($script) : '')
2378
-	. "' "
2379
-	. ($atts ?: " method='post'")
2380
-	. "><div>\n"
2381
-	. "<input type='hidden' name='exec' value='$script1' />"
2382
-	. $corps
2383
-	. (!$submit ? '' :
2384
-		("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2385
-	. "</div></form>\n";
2375
+    return "<form action='"
2376
+    . ($script ? generer_url_ecrire($script) : '')
2377
+    . "' "
2378
+    . ($atts ?: " method='post'")
2379
+    . "><div>\n"
2380
+    . "<input type='hidden' name='exec' value='$script1' />"
2381
+    . $corps
2382
+    . (!$submit ? '' :
2383
+        ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>'))
2384
+    . "</div></form>\n";
2386 2385
 }
2387 2386
 
2388 2387
 /**
@@ -2399,22 +2398,22 @@  discard block
 block discarded – undo
2399 2398
  * @return string
2400 2399
  */
2401 2400
 function generer_form_action($script, $corps, $atts = '', $public = false) {
2402
-	// si l'on est dans l'espace prive, on garde dans l'url
2403
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2404
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2405
-	$h = (_DIR_RACINE && !$public)
2406
-		? generer_url_ecrire(_request('exec'))
2407
-		: generer_url_public();
2401
+    // si l'on est dans l'espace prive, on garde dans l'url
2402
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2403
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2404
+    $h = (_DIR_RACINE && !$public)
2405
+        ? generer_url_ecrire(_request('exec'))
2406
+        : generer_url_public();
2408 2407
 
2409
-	return "\n<form action='" .
2410
-	$h .
2411
-	"'" .
2412
-	$atts .
2413
-	">\n" .
2414
-	'<div>' .
2415
-	"\n<input type='hidden' name='action' value='$script' />" .
2416
-	$corps .
2417
-	'</div></form>';
2408
+    return "\n<form action='" .
2409
+    $h .
2410
+    "'" .
2411
+    $atts .
2412
+    ">\n" .
2413
+    '<div>' .
2414
+    "\n<input type='hidden' name='action' value='$script' />" .
2415
+    $corps .
2416
+    '</div></form>';
2418 2417
 }
2419 2418
 
2420 2419
 /**
@@ -2433,22 +2432,22 @@  discard block
 block discarded – undo
2433 2432
  *     URL
2434 2433
  */
2435 2434
 function generer_url_action($script, $args = '', $no_entities = false, $public = false) {
2436
-	// si l'on est dans l'espace prive, on garde dans l'url
2437
-	// l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2438
-	// ou non de proceder a l'authentification (cas typique de l'install par exemple)
2439
-	$url = (_DIR_RACINE && !$public)
2440
-		? generer_url_ecrire(_request('exec'))
2441
-		: generer_url_public('', '', false, false);
2442
-	$url = parametre_url($url, 'action', $script);
2443
-	if ($args) {
2444
-		$url .= quote_amp('&' . $args);
2445
-	}
2435
+    // si l'on est dans l'espace prive, on garde dans l'url
2436
+    // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire
2437
+    // ou non de proceder a l'authentification (cas typique de l'install par exemple)
2438
+    $url = (_DIR_RACINE && !$public)
2439
+        ? generer_url_ecrire(_request('exec'))
2440
+        : generer_url_public('', '', false, false);
2441
+    $url = parametre_url($url, 'action', $script);
2442
+    if ($args) {
2443
+        $url .= quote_amp('&' . $args);
2444
+    }
2446 2445
 
2447
-	if ($no_entities) {
2448
-		$url = str_replace('&amp;', '&', $url);
2449
-	}
2446
+    if ($no_entities) {
2447
+        $url = str_replace('&amp;', '&', $url);
2448
+    }
2450 2449
 
2451
-	return $url;
2450
+    return $url;
2452 2451
 }
2453 2452
 
2454 2453
 
@@ -2467,23 +2466,23 @@  discard block
 block discarded – undo
2467 2466
  *     URL
2468 2467
  */
2469 2468
 function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) {
2470
-	if (is_null($public)) {
2471
-		$public = (_DIR_RACINE ? false : true);
2472
-	}
2473
-	if (!str_ends_with($script, '.api')) {
2474
-		$script .= '.api';
2475
-	}
2476
-	$url =
2477
-		(($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2478
-	. $script . '/'
2479
-	. ($path ? trim($path, '/') : '')
2480
-	. ($args ? '?' . quote_amp($args) : '');
2469
+    if (is_null($public)) {
2470
+        $public = (_DIR_RACINE ? false : true);
2471
+    }
2472
+    if (!str_ends_with($script, '.api')) {
2473
+        $script .= '.api';
2474
+    }
2475
+    $url =
2476
+        (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './')
2477
+    . $script . '/'
2478
+    . ($path ? trim($path, '/') : '')
2479
+    . ($args ? '?' . quote_amp($args) : '');
2481 2480
 
2482
-	if ($no_entities) {
2483
-		$url = str_replace('&amp;', '&', $url);
2484
-	}
2481
+    if ($no_entities) {
2482
+        $url = str_replace('&amp;', '&', $url);
2483
+    }
2485 2484
 
2486
-	return $url;
2485
+    return $url;
2487 2486
 }
2488 2487
 
2489 2488
 
@@ -2496,8 +2495,8 @@  discard block
 block discarded – undo
2496 2495
  * @param string $ta Répertoire temporaire accessible
2497 2496
  */
2498 2497
 function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) {
2499
-	spip_initialisation_core($pi, $pa, $ti, $ta);
2500
-	spip_initialisation_suite();
2498
+    spip_initialisation_core($pi, $pa, $ti, $ta);
2499
+    spip_initialisation_suite();
2501 2500
 }
2502 2501
 
2503 2502
 /**
@@ -2517,311 +2516,311 @@  discard block
 block discarded – undo
2517 2516
  * @param string $ta Répertoire temporaire accessible
2518 2517
  */
2519 2518
 function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) {
2520
-	static $too_late = 0;
2521
-	if ($too_late++) {
2522
-		return;
2523
-	}
2524
-
2525
-	// Declaration des repertoires
2526
-
2527
-	// le nom du repertoire plugins/ activables/desactivables
2528
-	if (!defined('_DIR_PLUGINS')) {
2529
-		define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2530
-	}
2531
-
2532
-	// le nom du repertoire des extensions/ permanentes du core, toujours actives
2533
-	if (!defined('_DIR_PLUGINS_DIST')) {
2534
-		define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2535
-	}
2536
-
2537
-	// le nom du repertoire des librairies
2538
-	if (!defined('_DIR_LIB')) {
2539
-		define('_DIR_LIB', _DIR_RACINE . 'lib/');
2540
-	}
2541
-
2542
-	// répertoire des libs via Composer
2543
-	if (!defined('_DIR_VENDOR')) {
2544
-		define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2545
-	}
2546
-
2547
-	if (!defined('_DIR_IMG')) {
2548
-		define('_DIR_IMG', $pa);
2549
-	}
2550
-	if (!defined('_DIR_LOGOS')) {
2551
-		define('_DIR_LOGOS', $pa);
2552
-	}
2553
-	if (!defined('_DIR_IMG_ICONES')) {
2554
-		define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2555
-	}
2556
-
2557
-	if (!defined('_DIR_DUMP')) {
2558
-		define('_DIR_DUMP', $ti . 'dump/');
2559
-	}
2560
-	if (!defined('_DIR_SESSIONS')) {
2561
-		define('_DIR_SESSIONS', $ti . 'sessions/');
2562
-	}
2563
-	if (!defined('_DIR_TRANSFERT')) {
2564
-		define('_DIR_TRANSFERT', $ti . 'upload/');
2565
-	}
2566
-	if (!defined('_DIR_CACHE')) {
2567
-		define('_DIR_CACHE', $ti . 'cache/');
2568
-	}
2569
-	if (!defined('_DIR_CACHE_XML')) {
2570
-		define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2571
-	}
2572
-	if (!defined('_DIR_SKELS')) {
2573
-		define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2574
-	}
2575
-	if (!defined('_DIR_AIDE')) {
2576
-		define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2577
-	}
2578
-	if (!defined('_DIR_TMP')) {
2579
-		define('_DIR_TMP', $ti);
2580
-	}
2581
-
2582
-	if (!defined('_DIR_VAR')) {
2583
-		define('_DIR_VAR', $ta);
2584
-	}
2585
-
2586
-	if (!defined('_DIR_ETC')) {
2587
-		define('_DIR_ETC', $pi);
2588
-	}
2589
-	if (!defined('_DIR_CONNECT')) {
2590
-		define('_DIR_CONNECT', $pi);
2591
-	}
2592
-	if (!defined('_DIR_CHMOD')) {
2593
-		define('_DIR_CHMOD', $pi);
2594
-	}
2595
-
2596
-	if (!isset($GLOBALS['test_dirs'])) {
2597
-		// Pas $pi car il est bon de le mettre hors ecriture apres intstall
2598
-		// il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2599
-	$GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2600
-	}
2601
-
2602
-	// Declaration des fichiers
2603
-
2604
-	if (!defined('_CACHE_PLUGINS_PATH')) {
2605
-		define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2606
-	}
2607
-	if (!defined('_CACHE_PLUGINS_OPT')) {
2608
-		define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2609
-	}
2610
-	if (!defined('_CACHE_PLUGINS_FCT')) {
2611
-		define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2612
-	}
2613
-	if (!defined('_CACHE_PIPELINES')) {
2614
-		define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2615
-	}
2616
-	if (!defined('_CACHE_CHEMIN')) {
2617
-		define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2618
-	}
2619
-
2620
-	# attention .php obligatoire pour ecrire_fichier_securise
2621
-	if (!defined('_FILE_META')) {
2622
-		define('_FILE_META', $ti . 'meta_cache.php');
2623
-	}
2624
-	if (!defined('_DIR_LOG')) {
2625
-		define('_DIR_LOG', _DIR_TMP . 'log/');
2626
-	}
2627
-	if (!defined('_FILE_LOG')) {
2628
-		define('_FILE_LOG', 'spip');
2629
-	}
2630
-	if (!defined('_FILE_LOG_SUFFIX')) {
2631
-		define('_FILE_LOG_SUFFIX', '.log');
2632
-	}
2633
-
2634
-	// Le fichier de connexion a la base de donnees
2635
-	if (!defined('_FILE_CONNECT_INS')) {
2636
-		define('_FILE_CONNECT_INS', 'connect');
2637
-	}
2638
-	if (!defined('_FILE_CONNECT')) {
2639
-		define(
2640
-			'_FILE_CONNECT',
2641
-			@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false
2642
-		);
2643
-	}
2644
-
2645
-	// Le fichier de reglages des droits
2646
-	if (!defined('_FILE_CHMOD_INS')) {
2647
-		define('_FILE_CHMOD_INS', 'chmod');
2648
-	}
2649
-	if (!defined('_FILE_CHMOD')) {
2650
-		define(
2651
-			'_FILE_CHMOD',
2652
-			@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false
2653
-		);
2654
-	}
2655
-
2656
-	if (!defined('_FILE_LDAP')) {
2657
-		define('_FILE_LDAP', 'ldap.php');
2658
-	}
2659
-
2660
-	if (!defined('_FILE_TMP_SUFFIX')) {
2661
-		define('_FILE_TMP_SUFFIX', '.tmp.php');
2662
-	}
2663
-	if (!defined('_FILE_CONNECT_TMP')) {
2664
-		define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2665
-	}
2666
-	if (!defined('_FILE_CHMOD_TMP')) {
2667
-		define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2668
-	}
2669
-
2670
-	// Definition des droits d'acces en ecriture
2671
-	if (!defined('_SPIP_CHMOD') && _FILE_CHMOD) {
2672
-		include_once _FILE_CHMOD;
2673
-	}
2674
-
2675
-	// Se mefier des fichiers mal remplis!
2676
-	if (!defined('_SPIP_CHMOD')) {
2677
-		define('_SPIP_CHMOD', 0777);
2678
-	}
2679
-
2680
-	if (!defined('_DEFAULT_CHARSET')) {
2681
-		/** Le charset par défaut lors de l'installation */
2682
-		define('_DEFAULT_CHARSET', 'utf-8');
2683
-	}
2684
-	if (!defined('_ROOT_PLUGINS')) {
2685
-		define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2686
-	}
2687
-	if (!defined('_ROOT_PLUGINS_DIST')) {
2688
-		define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2689
-	}
2690
-	if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2691
-		define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2692
-	}
2693
-
2694
-	// La taille des Log
2695
-	if (!defined('_MAX_LOG')) {
2696
-		define('_MAX_LOG', 100);
2697
-	}
2698
-
2699
-	// Sommes-nous dans l'empire du Mal ?
2700
-	// (ou sous le signe du Pingouin, ascendant GNU ?)
2701
-	if (isset($_SERVER['SERVER_SOFTWARE']) && str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) {
2702
-		if (!defined('_OS_SERVEUR')) {
2703
-			define('_OS_SERVEUR', 'windows');
2704
-		}
2705
-		if (!defined('_SPIP_LOCK_MODE')) {
2706
-			define('_SPIP_LOCK_MODE', 1);
2707
-		} // utiliser le flock php
2708
-	} else {
2709
-		if (!defined('_OS_SERVEUR')) {
2710
-			define('_OS_SERVEUR', '');
2711
-		}
2712
-		if (!defined('_SPIP_LOCK_MODE')) {
2713
-			define('_SPIP_LOCK_MODE', 1);
2714
-		} // utiliser le flock php
2715
-		#if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2716
-	}
2717
-
2718
-	// Langue par defaut
2719
-	if (!defined('_LANGUE_PAR_DEFAUT')) {
2720
-		define('_LANGUE_PAR_DEFAUT', 'fr');
2721
-	}
2722
-
2723
-	//
2724
-	// Module de lecture/ecriture/suppression de fichiers utilisant flock()
2725
-	// (non surchargeable en l'etat ; attention si on utilise include_spip()
2726
-	// pour le rendre surchargeable, on va provoquer un reecriture
2727
-	// systematique du noyau ou une baisse de perfs => a etudier)
2728
-	include_once _ROOT_RESTREINT . 'inc/flock.php';
2729
-
2730
-	// charger tout de suite le path et son cache
2731
-	load_path_cache();
2732
-
2733
-	// *********** traiter les variables ************
2734
-
2735
-	//
2736
-	// Securite
2737
-	//
2738
-
2739
-	// Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2740
-	if (isset($_REQUEST['GLOBALS'])) {
2741
-		die();
2742
-	}
2743
-	// nettoyer les magic quotes \' et les caracteres nuls %00
2744
-	spip_desinfecte($_GET);
2745
-	spip_desinfecte($_POST);
2746
-	spip_desinfecte($_COOKIE);
2747
-	spip_desinfecte($_REQUEST);
2748
-
2749
-	// appliquer le cookie_prefix
2750
-	if ($GLOBALS['cookie_prefix'] != 'spip') {
2751
-		include_spip('inc/cookie');
2752
-		recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2753
-	}
2754
-
2755
-	// Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2756
-	if (isset($_SERVER['REQUEST_URI'])) {
2757
-		$GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2758
-	} else {
2759
-		$GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2760
-		if (
2761
-			!empty($_SERVER['QUERY_STRING'])
2762
-			&& !strpos($_SERVER['REQUEST_URI'], '?')
2763
-		) {
2764
-			$GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2765
-		}
2766
-	}
2767
-
2768
-	// Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2769
-	if (!defined('_RENOUVELLE_ALEA')) {
2770
-		define('_RENOUVELLE_ALEA', 12 * 3600);
2771
-	}
2772
-	if (!defined('_DUREE_COOKIE_ADMIN')) {
2773
-		define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2774
-	}
2775
-
2776
-	// charger les meta si possible et renouveller l'alea au besoin
2777
-	// charge aussi effacer_meta et ecrire_meta
2778
-	$inc_meta = charger_fonction('meta', 'inc');
2779
-	$inc_meta();
2780
-
2781
-	// nombre de repertoires depuis la racine
2782
-	// on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2783
-	// ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2784
-	// le calcul est faux)
2785
-	if (!_DIR_RESTREINT) {
2786
-		$GLOBALS['profondeur_url'] = 1;
2787
-	} else {
2788
-		$uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2789
-		$uri_ref = $_SERVER['SCRIPT_NAME'];
2790
-		if (
2791
-			!$uri_ref
2792
-			// si on est appele avec un autre ti, on est sans doute en mutu
2793
-			// si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2794
-			// a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2795
-			// s'en remettre a l'adresse du site. alea jacta est.
2796
-			|| $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2797
-		) {
2798
-			if (isset($GLOBALS['meta']['adresse_site'])) {
2799
-				$uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2800
-				$uri_ref = ($uri_ref['path'] ?? '') . '/';
2801
-			} else {
2802
-				$uri_ref = '';
2803
-			}
2804
-		}
2805
-		if (!$uri || !$uri_ref) {
2806
-			$GLOBALS['profondeur_url'] = 0;
2807
-		} else {
2808
-			$GLOBALS['profondeur_url'] = max(
2809
-				0,
2810
-				substr_count($uri[0], '/')
2811
-				- substr_count($uri_ref, '/')
2812
-			);
2813
-		}
2814
-	}
2815
-	// s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2816
-	if (_FILE_CONNECT) {
2817
-		if (
2818
-			verifier_visiteur() == '0minirezo'
2819
-			// si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2820
-			&& !isset($_COOKIE['spip_admin'])
2821
-		) {
2822
-			clear_path_cache();
2823
-		}
2824
-	}
2519
+    static $too_late = 0;
2520
+    if ($too_late++) {
2521
+        return;
2522
+    }
2523
+
2524
+    // Declaration des repertoires
2525
+
2526
+    // le nom du repertoire plugins/ activables/desactivables
2527
+    if (!defined('_DIR_PLUGINS')) {
2528
+        define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/');
2529
+    }
2530
+
2531
+    // le nom du repertoire des extensions/ permanentes du core, toujours actives
2532
+    if (!defined('_DIR_PLUGINS_DIST')) {
2533
+        define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/');
2534
+    }
2535
+
2536
+    // le nom du repertoire des librairies
2537
+    if (!defined('_DIR_LIB')) {
2538
+        define('_DIR_LIB', _DIR_RACINE . 'lib/');
2539
+    }
2540
+
2541
+    // répertoire des libs via Composer
2542
+    if (!defined('_DIR_VENDOR')) {
2543
+        define('_DIR_VENDOR', _DIR_RACINE . 'vendor/');
2544
+    }
2545
+
2546
+    if (!defined('_DIR_IMG')) {
2547
+        define('_DIR_IMG', $pa);
2548
+    }
2549
+    if (!defined('_DIR_LOGOS')) {
2550
+        define('_DIR_LOGOS', $pa);
2551
+    }
2552
+    if (!defined('_DIR_IMG_ICONES')) {
2553
+        define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/');
2554
+    }
2555
+
2556
+    if (!defined('_DIR_DUMP')) {
2557
+        define('_DIR_DUMP', $ti . 'dump/');
2558
+    }
2559
+    if (!defined('_DIR_SESSIONS')) {
2560
+        define('_DIR_SESSIONS', $ti . 'sessions/');
2561
+    }
2562
+    if (!defined('_DIR_TRANSFERT')) {
2563
+        define('_DIR_TRANSFERT', $ti . 'upload/');
2564
+    }
2565
+    if (!defined('_DIR_CACHE')) {
2566
+        define('_DIR_CACHE', $ti . 'cache/');
2567
+    }
2568
+    if (!defined('_DIR_CACHE_XML')) {
2569
+        define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/');
2570
+    }
2571
+    if (!defined('_DIR_SKELS')) {
2572
+        define('_DIR_SKELS', _DIR_CACHE . 'skel/');
2573
+    }
2574
+    if (!defined('_DIR_AIDE')) {
2575
+        define('_DIR_AIDE', _DIR_CACHE . 'aide/');
2576
+    }
2577
+    if (!defined('_DIR_TMP')) {
2578
+        define('_DIR_TMP', $ti);
2579
+    }
2580
+
2581
+    if (!defined('_DIR_VAR')) {
2582
+        define('_DIR_VAR', $ta);
2583
+    }
2584
+
2585
+    if (!defined('_DIR_ETC')) {
2586
+        define('_DIR_ETC', $pi);
2587
+    }
2588
+    if (!defined('_DIR_CONNECT')) {
2589
+        define('_DIR_CONNECT', $pi);
2590
+    }
2591
+    if (!defined('_DIR_CHMOD')) {
2592
+        define('_DIR_CHMOD', $pi);
2593
+    }
2594
+
2595
+    if (!isset($GLOBALS['test_dirs'])) {
2596
+        // Pas $pi car il est bon de le mettre hors ecriture apres intstall
2597
+        // il sera rajoute automatiquement si besoin a l'etape 2 de l'install
2598
+    $GLOBALS['test_dirs'] = [$pa, $ti, $ta];
2599
+    }
2600
+
2601
+    // Declaration des fichiers
2602
+
2603
+    if (!defined('_CACHE_PLUGINS_PATH')) {
2604
+        define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php');
2605
+    }
2606
+    if (!defined('_CACHE_PLUGINS_OPT')) {
2607
+        define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php');
2608
+    }
2609
+    if (!defined('_CACHE_PLUGINS_FCT')) {
2610
+        define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php');
2611
+    }
2612
+    if (!defined('_CACHE_PIPELINES')) {
2613
+        define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php');
2614
+    }
2615
+    if (!defined('_CACHE_CHEMIN')) {
2616
+        define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt');
2617
+    }
2618
+
2619
+    # attention .php obligatoire pour ecrire_fichier_securise
2620
+    if (!defined('_FILE_META')) {
2621
+        define('_FILE_META', $ti . 'meta_cache.php');
2622
+    }
2623
+    if (!defined('_DIR_LOG')) {
2624
+        define('_DIR_LOG', _DIR_TMP . 'log/');
2625
+    }
2626
+    if (!defined('_FILE_LOG')) {
2627
+        define('_FILE_LOG', 'spip');
2628
+    }
2629
+    if (!defined('_FILE_LOG_SUFFIX')) {
2630
+        define('_FILE_LOG_SUFFIX', '.log');
2631
+    }
2632
+
2633
+    // Le fichier de connexion a la base de donnees
2634
+    if (!defined('_FILE_CONNECT_INS')) {
2635
+        define('_FILE_CONNECT_INS', 'connect');
2636
+    }
2637
+    if (!defined('_FILE_CONNECT')) {
2638
+        define(
2639
+            '_FILE_CONNECT',
2640
+            @is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false
2641
+        );
2642
+    }
2643
+
2644
+    // Le fichier de reglages des droits
2645
+    if (!defined('_FILE_CHMOD_INS')) {
2646
+        define('_FILE_CHMOD_INS', 'chmod');
2647
+    }
2648
+    if (!defined('_FILE_CHMOD')) {
2649
+        define(
2650
+            '_FILE_CHMOD',
2651
+            @is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false
2652
+        );
2653
+    }
2654
+
2655
+    if (!defined('_FILE_LDAP')) {
2656
+        define('_FILE_LDAP', 'ldap.php');
2657
+    }
2658
+
2659
+    if (!defined('_FILE_TMP_SUFFIX')) {
2660
+        define('_FILE_TMP_SUFFIX', '.tmp.php');
2661
+    }
2662
+    if (!defined('_FILE_CONNECT_TMP')) {
2663
+        define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX);
2664
+    }
2665
+    if (!defined('_FILE_CHMOD_TMP')) {
2666
+        define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX);
2667
+    }
2668
+
2669
+    // Definition des droits d'acces en ecriture
2670
+    if (!defined('_SPIP_CHMOD') && _FILE_CHMOD) {
2671
+        include_once _FILE_CHMOD;
2672
+    }
2673
+
2674
+    // Se mefier des fichiers mal remplis!
2675
+    if (!defined('_SPIP_CHMOD')) {
2676
+        define('_SPIP_CHMOD', 0777);
2677
+    }
2678
+
2679
+    if (!defined('_DEFAULT_CHARSET')) {
2680
+        /** Le charset par défaut lors de l'installation */
2681
+        define('_DEFAULT_CHARSET', 'utf-8');
2682
+    }
2683
+    if (!defined('_ROOT_PLUGINS')) {
2684
+        define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/');
2685
+    }
2686
+    if (!defined('_ROOT_PLUGINS_DIST')) {
2687
+        define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/');
2688
+    }
2689
+    if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) {
2690
+        define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL));
2691
+    }
2692
+
2693
+    // La taille des Log
2694
+    if (!defined('_MAX_LOG')) {
2695
+        define('_MAX_LOG', 100);
2696
+    }
2697
+
2698
+    // Sommes-nous dans l'empire du Mal ?
2699
+    // (ou sous le signe du Pingouin, ascendant GNU ?)
2700
+    if (isset($_SERVER['SERVER_SOFTWARE']) && str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) {
2701
+        if (!defined('_OS_SERVEUR')) {
2702
+            define('_OS_SERVEUR', 'windows');
2703
+        }
2704
+        if (!defined('_SPIP_LOCK_MODE')) {
2705
+            define('_SPIP_LOCK_MODE', 1);
2706
+        } // utiliser le flock php
2707
+    } else {
2708
+        if (!defined('_OS_SERVEUR')) {
2709
+            define('_OS_SERVEUR', '');
2710
+        }
2711
+        if (!defined('_SPIP_LOCK_MODE')) {
2712
+            define('_SPIP_LOCK_MODE', 1);
2713
+        } // utiliser le flock php
2714
+        #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite
2715
+    }
2716
+
2717
+    // Langue par defaut
2718
+    if (!defined('_LANGUE_PAR_DEFAUT')) {
2719
+        define('_LANGUE_PAR_DEFAUT', 'fr');
2720
+    }
2721
+
2722
+    //
2723
+    // Module de lecture/ecriture/suppression de fichiers utilisant flock()
2724
+    // (non surchargeable en l'etat ; attention si on utilise include_spip()
2725
+    // pour le rendre surchargeable, on va provoquer un reecriture
2726
+    // systematique du noyau ou une baisse de perfs => a etudier)
2727
+    include_once _ROOT_RESTREINT . 'inc/flock.php';
2728
+
2729
+    // charger tout de suite le path et son cache
2730
+    load_path_cache();
2731
+
2732
+    // *********** traiter les variables ************
2733
+
2734
+    //
2735
+    // Securite
2736
+    //
2737
+
2738
+    // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto
2739
+    if (isset($_REQUEST['GLOBALS'])) {
2740
+        die();
2741
+    }
2742
+    // nettoyer les magic quotes \' et les caracteres nuls %00
2743
+    spip_desinfecte($_GET);
2744
+    spip_desinfecte($_POST);
2745
+    spip_desinfecte($_COOKIE);
2746
+    spip_desinfecte($_REQUEST);
2747
+
2748
+    // appliquer le cookie_prefix
2749
+    if ($GLOBALS['cookie_prefix'] != 'spip') {
2750
+        include_spip('inc/cookie');
2751
+        recuperer_cookies_spip($GLOBALS['cookie_prefix']);
2752
+    }
2753
+
2754
+    // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI
2755
+    if (isset($_SERVER['REQUEST_URI'])) {
2756
+        $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
2757
+    } else {
2758
+        $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : '';
2759
+        if (
2760
+            !empty($_SERVER['QUERY_STRING'])
2761
+            && !strpos($_SERVER['REQUEST_URI'], '?')
2762
+        ) {
2763
+            $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
2764
+        }
2765
+    }
2766
+
2767
+    // Duree de validite de l'alea pour les cookies et ce qui s'ensuit.
2768
+    if (!defined('_RENOUVELLE_ALEA')) {
2769
+        define('_RENOUVELLE_ALEA', 12 * 3600);
2770
+    }
2771
+    if (!defined('_DUREE_COOKIE_ADMIN')) {
2772
+        define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600);
2773
+    }
2774
+
2775
+    // charger les meta si possible et renouveller l'alea au besoin
2776
+    // charge aussi effacer_meta et ecrire_meta
2777
+    $inc_meta = charger_fonction('meta', 'inc');
2778
+    $inc_meta();
2779
+
2780
+    // nombre de repertoires depuis la racine
2781
+    // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"]
2782
+    // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse
2783
+    // le calcul est faux)
2784
+    if (!_DIR_RESTREINT) {
2785
+        $GLOBALS['profondeur_url'] = 1;
2786
+    } else {
2787
+        $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : '';
2788
+        $uri_ref = $_SERVER['SCRIPT_NAME'];
2789
+        if (
2790
+            !$uri_ref
2791
+            // si on est appele avec un autre ti, on est sans doute en mutu
2792
+            // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie
2793
+            // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer
2794
+            // s'en remettre a l'adresse du site. alea jacta est.
2795
+            || $ti !== _NOM_TEMPORAIRES_INACCESSIBLES
2796
+        ) {
2797
+            if (isset($GLOBALS['meta']['adresse_site'])) {
2798
+                $uri_ref = parse_url($GLOBALS['meta']['adresse_site']);
2799
+                $uri_ref = ($uri_ref['path'] ?? '') . '/';
2800
+            } else {
2801
+                $uri_ref = '';
2802
+            }
2803
+        }
2804
+        if (!$uri || !$uri_ref) {
2805
+            $GLOBALS['profondeur_url'] = 0;
2806
+        } else {
2807
+            $GLOBALS['profondeur_url'] = max(
2808
+                0,
2809
+                substr_count($uri[0], '/')
2810
+                - substr_count($uri_ref, '/')
2811
+            );
2812
+        }
2813
+    }
2814
+    // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session
2815
+    if (_FILE_CONNECT) {
2816
+        if (
2817
+            verifier_visiteur() == '0minirezo'
2818
+            // si c'est un admin sans cookie admin, il faut ignorer le cache chemin !
2819
+            && !isset($_COOKIE['spip_admin'])
2820
+        ) {
2821
+            clear_path_cache();
2822
+        }
2823
+    }
2825 2824
 }
2826 2825
 
2827 2826
 /**
@@ -2830,158 +2829,158 @@  discard block
 block discarded – undo
2830 2829
  *
2831 2830
  */
2832 2831
 function spip_initialisation_suite() {
2833
-	static $too_late = 0;
2834
-	if ($too_late++) {
2835
-		return;
2836
-	}
2837
-
2838
-	// taille mini des login
2839
-	if (!defined('_LOGIN_TROP_COURT')) {
2840
-		define('_LOGIN_TROP_COURT', 4);
2841
-	}
2842
-
2843
-	// la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2844
-	#if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2845
-	#if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2846
-	#if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2847
-
2848
-	// la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2849
-	#if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2850
-	#if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2851
-	#if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2852
-	#if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2853
-
2854
-	if (!defined('_PASS_LONGUEUR_MINI')) {
2855
-		define('_PASS_LONGUEUR_MINI', 6);
2856
-	}
2857
-
2858
-	// largeur maximale des images dans l'administration
2859
-	if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2860
-		define('_IMG_ADMIN_MAX_WIDTH', 768);
2861
-	}
2862
-
2863
-	// Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2864
-	if (!defined('_IMG_QUALITE')) {
2865
-		define('_IMG_QUALITE', 85);
2866
-	} # valeur par defaut
2867
-	if (!defined('_IMG_GD_QUALITE')) {
2868
-		define('_IMG_GD_QUALITE', _IMG_QUALITE);
2869
-	} # surcharge pour la lib GD
2870
-	if (!defined('_IMG_CONVERT_QUALITE')) {
2871
-		define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2872
-	} # surcharge pour imagick en ligne de commande
2873
-	// Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2874
-	if (!defined('_IMG_IMAGICK_QUALITE')) {
2875
-		define('_IMG_IMAGICK_QUALITE', 75);
2876
-	} # surcharge pour imagick en PHP
2877
-
2878
-	if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2879
-		define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2880
-	} // poids en octet
2881
-
2882
-	// qq chaines standard
2883
-	if (!defined('_ACCESS_FILE_NAME')) {
2884
-		define('_ACCESS_FILE_NAME', '.htaccess');
2885
-	}
2886
-	if (!defined('_AUTH_USER_FILE')) {
2887
-		define('_AUTH_USER_FILE', '.htpasswd');
2888
-	}
2889
-	if (!defined('_SPIP_DUMP')) {
2890
-		define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2891
-	}
2892
-	if (!defined('_CACHE_RUBRIQUES')) {
2893
-		/** Fichier cache pour le navigateur de rubrique du bandeau */
2894
-		define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2895
-	}
2896
-	if (!defined('_CACHE_RUBRIQUES_MAX')) {
2897
-		/** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2898
-		define('_CACHE_RUBRIQUES_MAX', 500);
2899
-	}
2900
-
2901
-	if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2902
-		/**
2903
-		 * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2904
-		 * @var int Nombre de caractères */
2905
-		define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2906
-	}
2907
-
2908
-	if (!defined('_EXTENSION_SQUELETTES')) {
2909
-		define('_EXTENSION_SQUELETTES', 'html');
2910
-	}
2911
-
2912
-	if (!defined('_DOCTYPE_ECRIRE')) {
2913
-		/** Définit le doctype de l’espace privé */
2914
-		define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2915
-	}
2916
-	if (!defined('_DOCTYPE_AIDE')) {
2917
-		/** Définit le doctype de l’aide en ligne */
2918
-		define(
2919
-			'_DOCTYPE_AIDE',
2920
-			"<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2921
-		);
2922
-	}
2923
-
2924
-	if (!defined('_SPIP_SCRIPT')) {
2925
-		/** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2926
-		 * le script de l'espace public, alias index.php */
2927
-		define('_SPIP_SCRIPT', 'spip.php');
2928
-	}
2929
-	if (!defined('_SPIP_PAGE')) {
2930
-		/** Argument page, personalisable en cas de conflit avec un autre script */
2931
-		define('_SPIP_PAGE', 'page');
2932
-	}
2933
-
2934
-	// le script de l'espace prive
2935
-	// Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2936
-	// les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2937
-	// meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2938
-	if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2939
-		if (!empty($_SERVER['SERVER_SOFTWARE']) && preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2940
-			define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2941
-		} else {
2942
-			define('_SPIP_ECRIRE_SCRIPT', '');
2943
-		}
2944
-	}
2945
-
2946
-
2947
-	if (!defined('_SPIP_AJAX')) {
2948
-		define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2949
-			? 1
2950
-			: (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2951
-	}
2952
-
2953
-	// La requete est-elle en ajax ?
2954
-	if (!defined('_AJAX')) {
2955
-		define(
2956
-			'_AJAX',
2957
-			(
2958
-				isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2959
-				|| !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuer
2960
-				|| !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2961
-				|| !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2962
-			)
2963
-			&& 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
2964
-		);
2965
-	}
2966
-
2967
-	# nombre de pixels maxi pour calcul de la vignette avec gd
2968
-	# au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2969
-	# les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2970
-	if (!defined('_IMG_GD_MAX_PIXELS')) {
2971
-		define(
2972
-			'_IMG_GD_MAX_PIXELS',
2973
-			(isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes'])
2974
-			? $GLOBALS['meta']['max_taille_vignettes']
2975
-			: 0
2976
-		);
2977
-	}
2978
-
2979
-	// Protocoles a normaliser dans les chaines de langues
2980
-	if (!defined('_PROTOCOLES_STD')) {
2981
-		define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2982
-	}
2983
-
2984
-	init_var_mode();
2832
+    static $too_late = 0;
2833
+    if ($too_late++) {
2834
+        return;
2835
+    }
2836
+
2837
+    // taille mini des login
2838
+    if (!defined('_LOGIN_TROP_COURT')) {
2839
+        define('_LOGIN_TROP_COURT', 4);
2840
+    }
2841
+
2842
+    // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2843
+    #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko
2844
+    #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels
2845
+    #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels
2846
+
2847
+    // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile)
2848
+    #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko
2849
+    #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko
2850
+    #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels
2851
+    #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels
2852
+
2853
+    if (!defined('_PASS_LONGUEUR_MINI')) {
2854
+        define('_PASS_LONGUEUR_MINI', 6);
2855
+    }
2856
+
2857
+    // largeur maximale des images dans l'administration
2858
+    if (!defined('_IMG_ADMIN_MAX_WIDTH')) {
2859
+        define('_IMG_ADMIN_MAX_WIDTH', 768);
2860
+    }
2861
+
2862
+    // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite)
2863
+    if (!defined('_IMG_QUALITE')) {
2864
+        define('_IMG_QUALITE', 85);
2865
+    } # valeur par defaut
2866
+    if (!defined('_IMG_GD_QUALITE')) {
2867
+        define('_IMG_GD_QUALITE', _IMG_QUALITE);
2868
+    } # surcharge pour la lib GD
2869
+    if (!defined('_IMG_CONVERT_QUALITE')) {
2870
+        define('_IMG_CONVERT_QUALITE', _IMG_QUALITE);
2871
+    } # surcharge pour imagick en ligne de commande
2872
+    // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE
2873
+    if (!defined('_IMG_IMAGICK_QUALITE')) {
2874
+        define('_IMG_IMAGICK_QUALITE', 75);
2875
+    } # surcharge pour imagick en PHP
2876
+
2877
+    if (!defined('_COPIE_LOCALE_MAX_SIZE')) {
2878
+        define('_COPIE_LOCALE_MAX_SIZE', 33_554_432);
2879
+    } // poids en octet
2880
+
2881
+    // qq chaines standard
2882
+    if (!defined('_ACCESS_FILE_NAME')) {
2883
+        define('_ACCESS_FILE_NAME', '.htaccess');
2884
+    }
2885
+    if (!defined('_AUTH_USER_FILE')) {
2886
+        define('_AUTH_USER_FILE', '.htpasswd');
2887
+    }
2888
+    if (!defined('_SPIP_DUMP')) {
2889
+        define('_SPIP_DUMP', 'dump@nom_site@@[email protected]');
2890
+    }
2891
+    if (!defined('_CACHE_RUBRIQUES')) {
2892
+        /** Fichier cache pour le navigateur de rubrique du bandeau */
2893
+        define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt');
2894
+    }
2895
+    if (!defined('_CACHE_RUBRIQUES_MAX')) {
2896
+        /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */
2897
+        define('_CACHE_RUBRIQUES_MAX', 500);
2898
+    }
2899
+
2900
+    if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) {
2901
+        /**
2902
+         * Basculer les contextes ajax en fichier si la longueur d’url est trop grande
2903
+         * @var int Nombre de caractères */
2904
+        define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000);
2905
+    }
2906
+
2907
+    if (!defined('_EXTENSION_SQUELETTES')) {
2908
+        define('_EXTENSION_SQUELETTES', 'html');
2909
+    }
2910
+
2911
+    if (!defined('_DOCTYPE_ECRIRE')) {
2912
+        /** Définit le doctype de l’espace privé */
2913
+        define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n");
2914
+    }
2915
+    if (!defined('_DOCTYPE_AIDE')) {
2916
+        /** Définit le doctype de l’aide en ligne */
2917
+        define(
2918
+            '_DOCTYPE_AIDE',
2919
+            "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>"
2920
+        );
2921
+    }
2922
+
2923
+    if (!defined('_SPIP_SCRIPT')) {
2924
+        /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par
2925
+         * le script de l'espace public, alias index.php */
2926
+        define('_SPIP_SCRIPT', 'spip.php');
2927
+    }
2928
+    if (!defined('_SPIP_PAGE')) {
2929
+        /** Argument page, personalisable en cas de conflit avec un autre script */
2930
+        define('_SPIP_PAGE', 'page');
2931
+    }
2932
+
2933
+    // le script de l'espace prive
2934
+    // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes:
2935
+    // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419)
2936
+    // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html
2937
+    if (!defined('_SPIP_ECRIRE_SCRIPT')) {
2938
+        if (!empty($_SERVER['SERVER_SOFTWARE']) && preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) {
2939
+            define('_SPIP_ECRIRE_SCRIPT', 'index.php');
2940
+        } else {
2941
+            define('_SPIP_ECRIRE_SCRIPT', '');
2942
+        }
2943
+    }
2944
+
2945
+
2946
+    if (!defined('_SPIP_AJAX')) {
2947
+        define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax']))
2948
+            ? 1
2949
+            : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0)));
2950
+    }
2951
+
2952
+    // La requete est-elle en ajax ?
2953
+    if (!defined('_AJAX')) {
2954
+        define(
2955
+            '_AJAX',
2956
+            (
2957
+                isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery
2958
+                || !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuer
2959
+                || !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins
2960
+                || !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip
2961
+            )
2962
+            && 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
2963
+        );
2964
+    }
2965
+
2966
+    # nombre de pixels maxi pour calcul de la vignette avec gd
2967
+    # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation
2968
+    # les configurations limitees en memoire ont un seuil plutot vers 1MPixel
2969
+    if (!defined('_IMG_GD_MAX_PIXELS')) {
2970
+        define(
2971
+            '_IMG_GD_MAX_PIXELS',
2972
+            (isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes'])
2973
+            ? $GLOBALS['meta']['max_taille_vignettes']
2974
+            : 0
2975
+        );
2976
+    }
2977
+
2978
+    // Protocoles a normaliser dans les chaines de langues
2979
+    if (!defined('_PROTOCOLES_STD')) {
2980
+        define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal');
2981
+    }
2982
+
2983
+    init_var_mode();
2985 2984
 }
2986 2985
 
2987 2986
 /**
@@ -3015,136 +3014,136 @@  discard block
 block discarded – undo
3015 3014
  * `   var_mode` (calcul ou recalcul).
3016 3015
  */
3017 3016
 function init_var_mode() {
3018
-	static $done = false;
3019
-	if (!$done) {
3020
-		if (isset($_GET['var_mode'])) {
3021
-			$var_mode = explode(',', $_GET['var_mode']);
3022
-			// tout le monde peut calcul/recalcul
3023
-			if (!defined('_VAR_MODE')) {
3024
-				if (in_array('recalcul', $var_mode)) {
3025
-					define('_VAR_MODE', 'recalcul');
3026
-				} elseif (in_array('calcul', $var_mode)) {
3027
-					define('_VAR_MODE', 'calcul');
3028
-				}
3029
-			}
3030
-			$var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3031
-			if ($var_mode) {
3032
-				include_spip('inc/autoriser');
3033
-				// autoriser preview si preview seulement, et sinon autoriser debug
3034
-				if (
3035
-					autoriser(
3036
-						($_GET['var_mode'] == 'preview')
3037
-						? 'previsualiser'
3038
-						: 'debug'
3039
-					)
3040
-				) {
3041
-					if (in_array('traduction', $var_mode)) {
3042
-						// forcer le calcul pour passer dans traduire
3043
-						if (!defined('_VAR_MODE')) {
3044
-							define('_VAR_MODE', 'calcul');
3045
-						}
3046
-						// et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3047
-						if (!defined('_VAR_NOCACHE')) {
3048
-							define('_VAR_NOCACHE', true);
3049
-						}
3050
-						$var_mode = array_diff($var_mode, ['traduction']);
3051
-					}
3052
-					if (in_array('preview', $var_mode)) {
3053
-						// basculer sur les criteres de preview dans les boucles
3054
-						if (!defined('_VAR_PREVIEW')) {
3055
-							define('_VAR_PREVIEW', true);
3056
-						}
3057
-						// forcer le calcul
3058
-						if (!defined('_VAR_MODE')) {
3059
-							define('_VAR_MODE', 'calcul');
3060
-						}
3061
-						// et ne pas enregistrer de cache
3062
-						if (!defined('_VAR_NOCACHE')) {
3063
-							define('_VAR_NOCACHE', true);
3064
-						}
3065
-						$var_mode = array_diff($var_mode, ['preview']);
3066
-					}
3067
-					if (in_array('inclure', $var_mode)) {
3068
-						// forcer le compilo et ignorer les caches existants
3069
-						if (!defined('_VAR_MODE')) {
3070
-							define('_VAR_MODE', 'calcul');
3071
-						}
3072
-						if (!defined('_VAR_INCLURE')) {
3073
-							define('_VAR_INCLURE', true);
3074
-						}
3075
-						// et ne pas enregistrer de cache
3076
-						if (!defined('_VAR_NOCACHE')) {
3077
-							define('_VAR_NOCACHE', true);
3078
-						}
3079
-						$var_mode = array_diff($var_mode, ['inclure']);
3080
-					}
3081
-					if (in_array('urls', $var_mode)) {
3082
-						// forcer le compilo et ignorer les caches existants
3083
-						if (!defined('_VAR_MODE')) {
3084
-							define('_VAR_MODE', 'calcul');
3085
-						}
3086
-						if (!defined('_VAR_URLS')) {
3087
-							define('_VAR_URLS', true);
3088
-						}
3089
-						$var_mode = array_diff($var_mode, ['urls']);
3090
-					}
3091
-					if (in_array('images', $var_mode)) {
3092
-						// forcer le compilo et ignorer les caches existants
3093
-						if (!defined('_VAR_MODE')) {
3094
-							define('_VAR_MODE', 'calcul');
3095
-						}
3096
-						// indiquer qu'on doit recalculer les images
3097
-						if (!defined('_VAR_IMAGES')) {
3098
-							define('_VAR_IMAGES', true);
3099
-						}
3100
-						$var_mode = array_diff($var_mode, ['images']);
3101
-					}
3102
-					if (in_array('debug', $var_mode)) {
3103
-						if (!defined('_VAR_MODE')) {
3104
-							define('_VAR_MODE', 'debug');
3105
-						}
3106
-						// et ne pas enregistrer de cache
3107
-						if (!defined('_VAR_NOCACHE')) {
3108
-							define('_VAR_NOCACHE', true);
3109
-						}
3110
-						$var_mode = array_diff($var_mode, ['debug']);
3111
-					}
3112
-					if (count($var_mode) && !defined('_VAR_MODE')) {
3113
-						define('_VAR_MODE', reset($var_mode));
3114
-					}
3115
-					if (isset($GLOBALS['visiteur_session']['nom'])) {
3116
-						spip_log($GLOBALS['visiteur_session']['nom']
3117
-							. ' ' . _VAR_MODE);
3118
-					}
3119
-				} // pas autorise ?
3120
-				else {
3121
-					// si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3122
-					if (
3123
-						!$GLOBALS['visiteur_session']
3124
-						&& !empty($_SERVER['HTTP_HOST'])
3125
-						&& !empty($_SERVER['REQUEST_METHOD'])
3126
-						&& $_SERVER['REQUEST_METHOD'] === 'GET'
3127
-					) {
3128
-						$self = self('&', true);
3129
-						if (!str_contains($self, 'page=login')) {
3130
-							include_spip('inc/headers');
3131
-							$redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3132
-							redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3133
-						}
3134
-					}
3135
-					// sinon tant pis
3136
-				}
3137
-			}
3138
-		}
3139
-		if (!defined('_VAR_MODE')) {
3140
-			/**
3141
-			 * Indique le mode de calcul ou d'affichage de la page.
3142
-			 * @see init_var_mode()
3143
-			 */
3144
-			define('_VAR_MODE', false);
3145
-		}
3146
-		$done = true;
3147
-	}
3017
+    static $done = false;
3018
+    if (!$done) {
3019
+        if (isset($_GET['var_mode'])) {
3020
+            $var_mode = explode(',', $_GET['var_mode']);
3021
+            // tout le monde peut calcul/recalcul
3022
+            if (!defined('_VAR_MODE')) {
3023
+                if (in_array('recalcul', $var_mode)) {
3024
+                    define('_VAR_MODE', 'recalcul');
3025
+                } elseif (in_array('calcul', $var_mode)) {
3026
+                    define('_VAR_MODE', 'calcul');
3027
+                }
3028
+            }
3029
+            $var_mode = array_diff($var_mode, ['calcul', 'recalcul']);
3030
+            if ($var_mode) {
3031
+                include_spip('inc/autoriser');
3032
+                // autoriser preview si preview seulement, et sinon autoriser debug
3033
+                if (
3034
+                    autoriser(
3035
+                        ($_GET['var_mode'] == 'preview')
3036
+                        ? 'previsualiser'
3037
+                        : 'debug'
3038
+                    )
3039
+                ) {
3040
+                    if (in_array('traduction', $var_mode)) {
3041
+                        // forcer le calcul pour passer dans traduire
3042
+                        if (!defined('_VAR_MODE')) {
3043
+                            define('_VAR_MODE', 'calcul');
3044
+                        }
3045
+                        // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages
3046
+                        if (!defined('_VAR_NOCACHE')) {
3047
+                            define('_VAR_NOCACHE', true);
3048
+                        }
3049
+                        $var_mode = array_diff($var_mode, ['traduction']);
3050
+                    }
3051
+                    if (in_array('preview', $var_mode)) {
3052
+                        // basculer sur les criteres de preview dans les boucles
3053
+                        if (!defined('_VAR_PREVIEW')) {
3054
+                            define('_VAR_PREVIEW', true);
3055
+                        }
3056
+                        // forcer le calcul
3057
+                        if (!defined('_VAR_MODE')) {
3058
+                            define('_VAR_MODE', 'calcul');
3059
+                        }
3060
+                        // et ne pas enregistrer de cache
3061
+                        if (!defined('_VAR_NOCACHE')) {
3062
+                            define('_VAR_NOCACHE', true);
3063
+                        }
3064
+                        $var_mode = array_diff($var_mode, ['preview']);
3065
+                    }
3066
+                    if (in_array('inclure', $var_mode)) {
3067
+                        // forcer le compilo et ignorer les caches existants
3068
+                        if (!defined('_VAR_MODE')) {
3069
+                            define('_VAR_MODE', 'calcul');
3070
+                        }
3071
+                        if (!defined('_VAR_INCLURE')) {
3072
+                            define('_VAR_INCLURE', true);
3073
+                        }
3074
+                        // et ne pas enregistrer de cache
3075
+                        if (!defined('_VAR_NOCACHE')) {
3076
+                            define('_VAR_NOCACHE', true);
3077
+                        }
3078
+                        $var_mode = array_diff($var_mode, ['inclure']);
3079
+                    }
3080
+                    if (in_array('urls', $var_mode)) {
3081
+                        // forcer le compilo et ignorer les caches existants
3082
+                        if (!defined('_VAR_MODE')) {
3083
+                            define('_VAR_MODE', 'calcul');
3084
+                        }
3085
+                        if (!defined('_VAR_URLS')) {
3086
+                            define('_VAR_URLS', true);
3087
+                        }
3088
+                        $var_mode = array_diff($var_mode, ['urls']);
3089
+                    }
3090
+                    if (in_array('images', $var_mode)) {
3091
+                        // forcer le compilo et ignorer les caches existants
3092
+                        if (!defined('_VAR_MODE')) {
3093
+                            define('_VAR_MODE', 'calcul');
3094
+                        }
3095
+                        // indiquer qu'on doit recalculer les images
3096
+                        if (!defined('_VAR_IMAGES')) {
3097
+                            define('_VAR_IMAGES', true);
3098
+                        }
3099
+                        $var_mode = array_diff($var_mode, ['images']);
3100
+                    }
3101
+                    if (in_array('debug', $var_mode)) {
3102
+                        if (!defined('_VAR_MODE')) {
3103
+                            define('_VAR_MODE', 'debug');
3104
+                        }
3105
+                        // et ne pas enregistrer de cache
3106
+                        if (!defined('_VAR_NOCACHE')) {
3107
+                            define('_VAR_NOCACHE', true);
3108
+                        }
3109
+                        $var_mode = array_diff($var_mode, ['debug']);
3110
+                    }
3111
+                    if (count($var_mode) && !defined('_VAR_MODE')) {
3112
+                        define('_VAR_MODE', reset($var_mode));
3113
+                    }
3114
+                    if (isset($GLOBALS['visiteur_session']['nom'])) {
3115
+                        spip_log($GLOBALS['visiteur_session']['nom']
3116
+                            . ' ' . _VAR_MODE);
3117
+                    }
3118
+                } // pas autorise ?
3119
+                else {
3120
+                    // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger
3121
+                    if (
3122
+                        !$GLOBALS['visiteur_session']
3123
+                        && !empty($_SERVER['HTTP_HOST'])
3124
+                        && !empty($_SERVER['REQUEST_METHOD'])
3125
+                        && $_SERVER['REQUEST_METHOD'] === 'GET'
3126
+                    ) {
3127
+                        $self = self('&', true);
3128
+                        if (!str_contains($self, 'page=login')) {
3129
+                            include_spip('inc/headers');
3130
+                            $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&');
3131
+                            redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true));
3132
+                        }
3133
+                    }
3134
+                    // sinon tant pis
3135
+                }
3136
+            }
3137
+        }
3138
+        if (!defined('_VAR_MODE')) {
3139
+            /**
3140
+             * Indique le mode de calcul ou d'affichage de la page.
3141
+             * @see init_var_mode()
3142
+             */
3143
+            define('_VAR_MODE', false);
3144
+        }
3145
+        $done = true;
3146
+    }
3148 3147
 }
3149 3148
 
3150 3149
 /**
@@ -3156,16 +3155,16 @@  discard block
 block discarded – undo
3156 3155
  * @param bool $deep = true : appliquer récursivement
3157 3156
 **/
3158 3157
 function spip_desinfecte(&$t, $deep = true) {
3159
-	foreach ($t as $key => $val) {
3160
-		if (is_string($t[$key])) {
3161
-			$t[$key] = str_replace(chr(0), '-', $t[$key]);
3162
-		} // traiter aussi les "texte_plus" de article_edit
3163
-		else {
3164
-			if ($deep && is_array($t[$key]) && $key !== 'GLOBALS') {
3165
-				spip_desinfecte($t[$key], $deep);
3166
-			}
3167
-		}
3168
-	}
3158
+    foreach ($t as $key => $val) {
3159
+        if (is_string($t[$key])) {
3160
+            $t[$key] = str_replace(chr(0), '-', $t[$key]);
3161
+        } // traiter aussi les "texte_plus" de article_edit
3162
+        else {
3163
+            if ($deep && is_array($t[$key]) && $key !== 'GLOBALS') {
3164
+                spip_desinfecte($t[$key], $deep);
3165
+            }
3166
+        }
3167
+    }
3169 3168
 }
3170 3169
 
3171 3170
 /**
@@ -3178,64 +3177,64 @@  discard block
 block discarded – undo
3178 3177
  * @return string|0|false
3179 3178
 **/
3180 3179
 function verifier_visiteur() {
3181
-	@spip_initialisation_core(
3182
-		(_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3183
-		(_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3184
-		(_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3185
-		(_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3186
-	);
3187
-
3188
-	// Demarrer une session NON AUTHENTIFIEE si on donne son nom
3189
-	// dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3190
-	// Attention on separe bien session_nom et nom, pour eviter
3191
-	// les melanges entre donnees SQL et variables plus aleatoires
3192
-	$variables_session = ['session_nom', 'session_email'];
3193
-	foreach ($variables_session as $var) {
3194
-		if (_request($var) !== null) {
3195
-			$init = true;
3196
-			break;
3197
-		}
3198
-	}
3199
-	if (isset($init)) {
3200
-		#@spip_initialisation_suite();
3201
-		$session = charger_fonction('session', 'inc');
3202
-		$session();
3203
-		include_spip('inc/texte');
3204
-		foreach ($variables_session as $var) {
3205
-			if (($a = _request($var)) !== null) {
3206
-				$GLOBALS['visiteur_session'][$var] = safehtml($a);
3207
-			}
3208
-		}
3209
-		if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3210
-			$GLOBALS['visiteur_session']['id_auteur'] = 0;
3211
-		}
3212
-		$session($GLOBALS['visiteur_session']);
3213
-
3214
-		return 0;
3215
-	}
3216
-
3217
-	$h = (isset($_SERVER['PHP_AUTH_USER']) && !$GLOBALS['ignore_auth_http']);
3218
-	if ($h || isset($_COOKIE['spip_session']) || isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3219
-		$session = charger_fonction('session', 'inc');
3220
-		if ($session()) {
3221
-			return $GLOBALS['visiteur_session']['statut'];
3222
-		}
3223
-		if ($h && isset($_SERVER['PHP_AUTH_PW'])) {
3224
-			include_spip('inc/auth');
3225
-			$h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3226
-		}
3227
-		if ($h) {
3228
-			$GLOBALS['visiteur_session'] = $h;
3229
-
3230
-			return $GLOBALS['visiteur_session']['statut'];
3231
-		}
3232
-	}
3233
-
3234
-	// au moins son navigateur nous dit la langue preferee de cet inconnu
3235
-	include_spip('inc/lang');
3236
-	utiliser_langue_visiteur();
3237
-
3238
-	return false;
3180
+    @spip_initialisation_core(
3181
+        (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES),
3182
+        (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES),
3183
+        (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES),
3184
+        (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES)
3185
+    );
3186
+
3187
+    // Demarrer une session NON AUTHENTIFIEE si on donne son nom
3188
+    // dans un formulaire sans login (ex: #FORMULAIRE_FORUM)
3189
+    // Attention on separe bien session_nom et nom, pour eviter
3190
+    // les melanges entre donnees SQL et variables plus aleatoires
3191
+    $variables_session = ['session_nom', 'session_email'];
3192
+    foreach ($variables_session as $var) {
3193
+        if (_request($var) !== null) {
3194
+            $init = true;
3195
+            break;
3196
+        }
3197
+    }
3198
+    if (isset($init)) {
3199
+        #@spip_initialisation_suite();
3200
+        $session = charger_fonction('session', 'inc');
3201
+        $session();
3202
+        include_spip('inc/texte');
3203
+        foreach ($variables_session as $var) {
3204
+            if (($a = _request($var)) !== null) {
3205
+                $GLOBALS['visiteur_session'][$var] = safehtml($a);
3206
+            }
3207
+        }
3208
+        if (!isset($GLOBALS['visiteur_session']['id_auteur'])) {
3209
+            $GLOBALS['visiteur_session']['id_auteur'] = 0;
3210
+        }
3211
+        $session($GLOBALS['visiteur_session']);
3212
+
3213
+        return 0;
3214
+    }
3215
+
3216
+    $h = (isset($_SERVER['PHP_AUTH_USER']) && !$GLOBALS['ignore_auth_http']);
3217
+    if ($h || isset($_COOKIE['spip_session']) || isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) {
3218
+        $session = charger_fonction('session', 'inc');
3219
+        if ($session()) {
3220
+            return $GLOBALS['visiteur_session']['statut'];
3221
+        }
3222
+        if ($h && isset($_SERVER['PHP_AUTH_PW'])) {
3223
+            include_spip('inc/auth');
3224
+            $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
3225
+        }
3226
+        if ($h) {
3227
+            $GLOBALS['visiteur_session'] = $h;
3228
+
3229
+            return $GLOBALS['visiteur_session']['statut'];
3230
+        }
3231
+    }
3232
+
3233
+    // au moins son navigateur nous dit la langue preferee de cet inconnu
3234
+    include_spip('inc/lang');
3235
+    utiliser_langue_visiteur();
3236
+
3237
+    return false;
3239 3238
 }
3240 3239
 
3241 3240
 
@@ -3258,21 +3257,21 @@  discard block
 block discarded – undo
3258 3257
  *     - string Langue utilisée.
3259 3258
  **/
3260 3259
 function lang_select($lang = null) {
3261
-	static $pile_langues = [];
3262
-	if (!function_exists('changer_langue')) {
3263
-		include_spip('inc/lang');
3264
-	}
3265
-	if ($lang === null) {
3266
-		$lang = array_pop($pile_langues);
3267
-	} else {
3268
-		array_push($pile_langues, $GLOBALS['spip_lang']);
3269
-	}
3270
-	if (isset($GLOBALS['spip_lang']) && $lang == $GLOBALS['spip_lang']) {
3271
-		return $lang;
3272
-	}
3273
-	changer_langue($lang);
3260
+    static $pile_langues = [];
3261
+    if (!function_exists('changer_langue')) {
3262
+        include_spip('inc/lang');
3263
+    }
3264
+    if ($lang === null) {
3265
+        $lang = array_pop($pile_langues);
3266
+    } else {
3267
+        array_push($pile_langues, $GLOBALS['spip_lang']);
3268
+    }
3269
+    if (isset($GLOBALS['spip_lang']) && $lang == $GLOBALS['spip_lang']) {
3270
+        return $lang;
3271
+    }
3272
+    changer_langue($lang);
3274 3273
 
3275
-	return $lang;
3274
+    return $lang;
3276 3275
 }
3277 3276
 
3278 3277
 /**
@@ -3289,20 +3288,20 @@  discard block
 block discarded – undo
3289 3288
  *     Identifiant de la session
3290 3289
  **/
3291 3290
 function spip_session($force = false) {
3292
-	static $session;
3293
-	if ($force || !isset($session)) {
3294
-		$s = '';
3295
-		if (!empty($GLOBALS['visiteur_session'])) {
3296
-			include_spip('inc/session');
3297
-			$cookie = lire_cookie_session();
3298
-			$s = serialize($GLOBALS['visiteur_session']) . '_' . ($cookie ?: '');
3299
-		}
3300
-		$s = pipeline('definir_session', $s);
3301
-		$session = ($s ? substr(md5($s), 0, 8) : '');
3302
-	}
3291
+    static $session;
3292
+    if ($force || !isset($session)) {
3293
+        $s = '';
3294
+        if (!empty($GLOBALS['visiteur_session'])) {
3295
+            include_spip('inc/session');
3296
+            $cookie = lire_cookie_session();
3297
+            $s = serialize($GLOBALS['visiteur_session']) . '_' . ($cookie ?: '');
3298
+        }
3299
+        $s = pipeline('definir_session', $s);
3300
+        $session = ($s ? substr(md5($s), 0, 8) : '');
3301
+    }
3303 3302
 
3304
-	#spip_log('session: '.$session);
3305
-	return $session;
3303
+    #spip_log('session: '.$session);
3304
+    return $session;
3306 3305
 }
3307 3306
 
3308 3307
 
@@ -3321,9 +3320,9 @@  discard block
 block discarded – undo
3321 3320
  *    Lien sur une icone d'aide
3322 3321
  **/
3323 3322
 function aider($aide = '', $distante = false) {
3324
-	$aider = charger_fonction('aide', 'inc', true);
3323
+    $aider = charger_fonction('aide', 'inc', true);
3325 3324
 
3326
-	return $aider ? $aider($aide, '', [], $distante) : '';
3325
+    return $aider ? $aider($aide, '', [], $distante) : '';
3327 3326
 }
3328 3327
 
3329 3328
 /**
@@ -3333,35 +3332,35 @@  discard block
 block discarded – undo
3333 3332
  */
3334 3333
 function exec_info_dist() {
3335 3334
 
3336
-	include_spip('inc/autoriser');
3337
-	if (autoriser('phpinfos')) {
3338
-		$cookies_masques = ['spip_session', 'PHPSESSID'];
3339
-		$cookies_backup = [];
3340
-		$server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3341
-		$env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3342
-		$mask = '******************************';
3343
-		foreach ($cookies_masques as $k) {
3344
-			if (!empty($_COOKIE[$k])) {
3345
-				$cookies_backup[$k] = $_COOKIE[$k];
3346
-				$_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3347
-				$_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3348
-				$_COOKIE[$k] = $mask;
3349
-			}
3350
-		}
3351
-		phpinfo();
3352
-		foreach ($cookies_backup as $k => $v) {
3353
-			$_COOKIE[$k] = $v;
3354
-		}
3355
-		foreach ($server_backup as $k => $v) {
3356
-			$_SERVER[$k] = $v;
3357
-		}
3358
-		foreach ($env_backup as $k => $v) {
3359
-			$_ENV[$k] = $v;
3360
-		}
3361
-	} else {
3362
-		include_spip('inc/filtres');
3363
-		sinon_interdire_acces();
3364
-	}
3335
+    include_spip('inc/autoriser');
3336
+    if (autoriser('phpinfos')) {
3337
+        $cookies_masques = ['spip_session', 'PHPSESSID'];
3338
+        $cookies_backup = [];
3339
+        $server_backup = ['HTTP_COOKIE' => $_SERVER['HTTP_COOKIE'] ?? []];
3340
+        $env_backup = ['HTTP_COOKIE' => $_ENV['HTTP_COOKIE'] ?? []];
3341
+        $mask = '******************************';
3342
+        foreach ($cookies_masques as $k) {
3343
+            if (!empty($_COOKIE[$k])) {
3344
+                $cookies_backup[$k] = $_COOKIE[$k];
3345
+                $_SERVER['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_SERVER['HTTP_COOKIE'] ?? []);
3346
+                $_ENV['HTTP_COOKIE'] = str_replace("$k=" . $_COOKIE[$k], "$k=$mask", $_ENV['HTTP_COOKIE'] ?? []);
3347
+                $_COOKIE[$k] = $mask;
3348
+            }
3349
+        }
3350
+        phpinfo();
3351
+        foreach ($cookies_backup as $k => $v) {
3352
+            $_COOKIE[$k] = $v;
3353
+        }
3354
+        foreach ($server_backup as $k => $v) {
3355
+            $_SERVER[$k] = $v;
3356
+        }
3357
+        foreach ($env_backup as $k => $v) {
3358
+            $_ENV[$k] = $v;
3359
+        }
3360
+    } else {
3361
+        include_spip('inc/filtres');
3362
+        sinon_interdire_acces();
3363
+    }
3365 3364
 }
3366 3365
 
3367 3366
 /**
@@ -3381,13 +3380,13 @@  discard block
 block discarded – undo
3381 3380
  *     - string si $message à false.
3382 3381
  **/
3383 3382
 function erreur_squelette($message = '', $lieu = '') {
3384
-	$debusquer = charger_fonction('debusquer', 'public');
3385
-	if (is_array($lieu)) {
3386
-		include_spip('public/compiler');
3387
-		$lieu = reconstruire_contexte_compil($lieu);
3388
-	}
3383
+    $debusquer = charger_fonction('debusquer', 'public');
3384
+    if (is_array($lieu)) {
3385
+        include_spip('public/compiler');
3386
+        $lieu = reconstruire_contexte_compil($lieu);
3387
+    }
3389 3388
 
3390
-	return $debusquer($message, $lieu);
3389
+    return $debusquer($message, $lieu);
3391 3390
 }
3392 3391
 
3393 3392
 /**
@@ -3424,108 +3423,108 @@  discard block
 block discarded – undo
3424 3423
  *     - ou tableau d'information sur le squelette.
3425 3424
  */
3426 3425
 function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') {
3427
-	if (!function_exists('evaluer_fond')) {
3428
-		include_spip('public/assembler');
3429
-	}
3430
-	// assurer la compat avec l'ancienne syntaxe
3431
-	// (trim etait le 3eme argument, par defaut a true)
3432
-	if (!is_array($options)) {
3433
-		$options = ['trim' => $options];
3434
-	}
3435
-	if (!isset($options['trim'])) {
3436
-		$options['trim'] = true;
3437
-	}
3438
-
3439
-	if (isset($contexte['connect'])) {
3440
-		$connect = $contexte['connect'];
3441
-		unset($contexte['connect']);
3442
-	}
3443
-
3444
-	$texte = '';
3445
-	$pages = [];
3446
-	$lang_select = '';
3447
-	if (!isset($options['etoile']) || !$options['etoile']) {
3448
-		// Si on a inclus sans fixer le critere de lang, on prend la langue courante
3449
-		if (!isset($contexte['lang'])) {
3450
-			$contexte['lang'] = $GLOBALS['spip_lang'];
3451
-		}
3452
-
3453
-		if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3454
-			$lang_select = lang_select($contexte['lang']);
3455
-		}
3456
-	}
3457
-
3458
-	if (!isset($GLOBALS['_INC_PUBLIC'])) {
3459
-		$GLOBALS['_INC_PUBLIC'] = 0;
3460
-	}
3461
-
3462
-	$GLOBALS['_INC_PUBLIC']++;
3463
-
3464
-	// fix #4235
3465
-	$cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3466
-
3467
-
3468
-	foreach (is_array($fond) ? $fond : [$fond] as $f) {
3469
-		unset($GLOBALS['cache_utilise_session']);	// fix #4235
3470
-
3471
-		$page = evaluer_fond($f, $contexte, $connect);
3472
-		if ($page === '') {
3473
-			$c = $options['compil'] ?? '';
3474
-			$a = ['fichier' => $f];
3475
-			$erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3476
-			erreur_squelette($erreur, $c);
3477
-			// eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3478
-			$page = ['texte' => '', 'erreur' => $erreur];
3479
-		}
3480
-
3481
-		$page = pipeline('recuperer_fond', [
3482
-			'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3483
-			'data' => $page
3484
-		]);
3485
-		if (isset($options['ajax']) && $options['ajax']) {
3486
-			if (!function_exists('encoder_contexte_ajax')) {
3487
-				include_spip('inc/filtres');
3488
-			}
3489
-			$page['texte'] = encoder_contexte_ajax(
3490
-				array_merge(
3491
-					$contexte,
3492
-					['fond' => $f],
3493
-					($connect ? ['connect' => $connect] : [])
3494
-				),
3495
-				'',
3496
-				$page['texte'],
3497
-				$options['ajax']
3498
-			);
3499
-		}
3500
-
3501
-		if (isset($options['raw']) && $options['raw']) {
3502
-			$pages[] = $page;
3503
-		} else {
3504
-			$texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3505
-		}
3506
-
3507
-		// contamination de la session appelante, pour les inclusions statiques
3508
-		if (isset($page['invalideurs']['session'])) {
3509
-			$cache_utilise_session_appelant = $page['invalideurs']['session'];
3510
-		}
3511
-	}
3512
-
3513
-	// restaurer le sessionnement du contexte appelant,
3514
-	// éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3515
-	if (isset($cache_utilise_session_appelant)) {
3516
-		$GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3517
-	}
3518
-
3519
-	$GLOBALS['_INC_PUBLIC']--;
3520
-
3521
-	if ($lang_select) {
3522
-		lang_select();
3523
-	}
3524
-	if (isset($options['raw']) && $options['raw']) {
3525
-		return is_array($fond) ? $pages : reset($pages);
3526
-	} else {
3527
-		return $options['trim'] ? ltrim($texte) : $texte;
3528
-	}
3426
+    if (!function_exists('evaluer_fond')) {
3427
+        include_spip('public/assembler');
3428
+    }
3429
+    // assurer la compat avec l'ancienne syntaxe
3430
+    // (trim etait le 3eme argument, par defaut a true)
3431
+    if (!is_array($options)) {
3432
+        $options = ['trim' => $options];
3433
+    }
3434
+    if (!isset($options['trim'])) {
3435
+        $options['trim'] = true;
3436
+    }
3437
+
3438
+    if (isset($contexte['connect'])) {
3439
+        $connect = $contexte['connect'];
3440
+        unset($contexte['connect']);
3441
+    }
3442
+
3443
+    $texte = '';
3444
+    $pages = [];
3445
+    $lang_select = '';
3446
+    if (!isset($options['etoile']) || !$options['etoile']) {
3447
+        // Si on a inclus sans fixer le critere de lang, on prend la langue courante
3448
+        if (!isset($contexte['lang'])) {
3449
+            $contexte['lang'] = $GLOBALS['spip_lang'];
3450
+        }
3451
+
3452
+        if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) {
3453
+            $lang_select = lang_select($contexte['lang']);
3454
+        }
3455
+    }
3456
+
3457
+    if (!isset($GLOBALS['_INC_PUBLIC'])) {
3458
+        $GLOBALS['_INC_PUBLIC'] = 0;
3459
+    }
3460
+
3461
+    $GLOBALS['_INC_PUBLIC']++;
3462
+
3463
+    // fix #4235
3464
+    $cache_utilise_session_appelant	= ($GLOBALS['cache_utilise_session'] ?? null);
3465
+
3466
+
3467
+    foreach (is_array($fond) ? $fond : [$fond] as $f) {
3468
+        unset($GLOBALS['cache_utilise_session']);	// fix #4235
3469
+
3470
+        $page = evaluer_fond($f, $contexte, $connect);
3471
+        if ($page === '') {
3472
+            $c = $options['compil'] ?? '';
3473
+            $a = ['fichier' => $f];
3474
+            $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable
3475
+            erreur_squelette($erreur, $c);
3476
+            // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4
3477
+            $page = ['texte' => '', 'erreur' => $erreur];
3478
+        }
3479
+
3480
+        $page = pipeline('recuperer_fond', [
3481
+            'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect],
3482
+            'data' => $page
3483
+        ]);
3484
+        if (isset($options['ajax']) && $options['ajax']) {
3485
+            if (!function_exists('encoder_contexte_ajax')) {
3486
+                include_spip('inc/filtres');
3487
+            }
3488
+            $page['texte'] = encoder_contexte_ajax(
3489
+                array_merge(
3490
+                    $contexte,
3491
+                    ['fond' => $f],
3492
+                    ($connect ? ['connect' => $connect] : [])
3493
+                ),
3494
+                '',
3495
+                $page['texte'],
3496
+                $options['ajax']
3497
+            );
3498
+        }
3499
+
3500
+        if (isset($options['raw']) && $options['raw']) {
3501
+            $pages[] = $page;
3502
+        } else {
3503
+            $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte'];
3504
+        }
3505
+
3506
+        // contamination de la session appelante, pour les inclusions statiques
3507
+        if (isset($page['invalideurs']['session'])) {
3508
+            $cache_utilise_session_appelant = $page['invalideurs']['session'];
3509
+        }
3510
+    }
3511
+
3512
+    // restaurer le sessionnement du contexte appelant,
3513
+    // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée
3514
+    if (isset($cache_utilise_session_appelant)) {
3515
+        $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant;
3516
+    }
3517
+
3518
+    $GLOBALS['_INC_PUBLIC']--;
3519
+
3520
+    if ($lang_select) {
3521
+        lang_select();
3522
+    }
3523
+    if (isset($options['raw']) && $options['raw']) {
3524
+        return is_array($fond) ? $pages : reset($pages);
3525
+    } else {
3526
+        return $options['trim'] ? ltrim($texte) : $texte;
3527
+    }
3529 3528
 }
3530 3529
 
3531 3530
 /**
@@ -3535,7 +3534,7 @@  discard block
 block discarded – undo
3535 3534
  * @return string
3536 3535
  */
3537 3536
 function trouve_modele($nom) {
3538
-	return trouver_fond($nom, 'modeles/');
3537
+    return trouver_fond($nom, 'modeles/');
3539 3538
 }
3540 3539
 
3541 3540
 /**
@@ -3551,21 +3550,21 @@  discard block
 block discarded – undo
3551 3550
  * @return array|string
3552 3551
  */
3553 3552
 function trouver_fond($nom, $dir = '', $pathinfo = false) {
3554
-	$f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3555
-	if (!$pathinfo) {
3556
-		return $f;
3557
-	}
3558
-	// renvoyer un tableau detaille si $pathinfo==true
3559
-	$p = pathinfo($f);
3560
-	if (!isset($p['extension']) || !$p['extension']) {
3561
-		$p['extension'] = _EXTENSION_SQUELETTES;
3562
-	}
3563
-	if (!isset($p['extension']) || !$p['filename']) {
3564
-		$p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3565
-	}
3566
-	$p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3553
+    $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : '');
3554
+    if (!$pathinfo) {
3555
+        return $f;
3556
+    }
3557
+    // renvoyer un tableau detaille si $pathinfo==true
3558
+    $p = pathinfo($f);
3559
+    if (!isset($p['extension']) || !$p['extension']) {
3560
+        $p['extension'] = _EXTENSION_SQUELETTES;
3561
+    }
3562
+    if (!isset($p['extension']) || !$p['filename']) {
3563
+        $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : '');
3564
+    }
3565
+    $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : '');
3567 3566
 
3568
-	return $p;
3567
+    return $p;
3569 3568
 }
3570 3569
 
3571 3570
 /**
@@ -3585,21 +3584,21 @@  discard block
 block discarded – undo
3585 3584
  *     Nom de l'exec, sinon chaîne vide.
3586 3585
  **/
3587 3586
 function tester_url_ecrire($nom) {
3588
-	static $exec = [];
3589
-	if (isset($exec[$nom])) {
3590
-		return $exec[$nom];
3591
-	}
3592
-	// tester si c'est une page en squelette
3593
-	if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3594
-		return $exec[$nom] = 'fond';
3595
-	} // echafaudage d'un fond !
3596
-	elseif (include_spip('public/styliser_par_z') && z_echafaudable($nom)) {
3597
-		return $exec[$nom] = 'fond';
3598
-	}
3599
-	// attention, il ne faut pas inclure l'exec ici
3600
-	// car sinon #URL_ECRIRE provoque des inclusions
3601
-	// et des define intrusifs potentiels
3602
-	return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') || charger_fonction($nom, 'exec', true)) ? $nom : '');
3587
+    static $exec = [];
3588
+    if (isset($exec[$nom])) {
3589
+        return $exec[$nom];
3590
+    }
3591
+    // tester si c'est une page en squelette
3592
+    if (trouver_fond($nom, 'prive/squelettes/contenu/')) {
3593
+        return $exec[$nom] = 'fond';
3594
+    } // echafaudage d'un fond !
3595
+    elseif (include_spip('public/styliser_par_z') && z_echafaudable($nom)) {
3596
+        return $exec[$nom] = 'fond';
3597
+    }
3598
+    // attention, il ne faut pas inclure l'exec ici
3599
+    // car sinon #URL_ECRIRE provoque des inclusions
3600
+    // et des define intrusifs potentiels
3601
+    return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') || charger_fonction($nom, 'exec', true)) ? $nom : '');
3603 3602
 }
3604 3603
 
3605 3604
 /**
@@ -3609,36 +3608,36 @@  discard block
 block discarded – undo
3609 3608
  *     true si la constante _VERSION_HTML n'est pas définie ou égale à html5
3610 3609
  **/
3611 3610
 function html5_permis() {
3612
-	return (!defined('_VERSION_HTML') || _VERSION_HTML !== 'html4');
3611
+    return (!defined('_VERSION_HTML') || _VERSION_HTML !== 'html4');
3613 3612
 }
3614 3613
 
3615 3614
 /**
3616 3615
  * Lister les formats image acceptes par les lib et fonctions images
3617 3616
  */
3618 3617
 function formats_image_acceptables(?bool $gd = null, bool $svg_allowed = true): array {
3619
-	$formats = null;
3620
-	if (!is_null($gd)) {
3621
-		$config = ($gd ? 'gd_formats' : 'formats_graphiques');
3622
-		if (isset($GLOBALS['meta'][$config])) {
3623
-			$formats = $GLOBALS['meta'][$config];
3624
-			$formats = explode(',', $formats);
3625
-			$formats = array_filter($formats);
3626
-			$formats = array_map('trim', $formats);
3627
-		}
3628
-	}
3629
-	if (is_null($formats)) {
3630
-		include_spip('inc/filtres_images_lib_mini');
3631
-		$formats = _image_extensions_acceptees_en_entree();
3632
-	}
3633
-
3634
-	if ($svg_allowed) {
3635
-		if (!in_array('svg', $formats)) {
3636
-			$formats[] = 'svg';
3637
-		}
3638
-	} else {
3639
-		$formats = array_diff($formats, ['svg']);
3640
-	}
3641
-	return $formats;
3618
+    $formats = null;
3619
+    if (!is_null($gd)) {
3620
+        $config = ($gd ? 'gd_formats' : 'formats_graphiques');
3621
+        if (isset($GLOBALS['meta'][$config])) {
3622
+            $formats = $GLOBALS['meta'][$config];
3623
+            $formats = explode(',', $formats);
3624
+            $formats = array_filter($formats);
3625
+            $formats = array_map('trim', $formats);
3626
+        }
3627
+    }
3628
+    if (is_null($formats)) {
3629
+        include_spip('inc/filtres_images_lib_mini');
3630
+        $formats = _image_extensions_acceptees_en_entree();
3631
+    }
3632
+
3633
+    if ($svg_allowed) {
3634
+        if (!in_array('svg', $formats)) {
3635
+            $formats[] = 'svg';
3636
+        }
3637
+    } else {
3638
+        $formats = array_diff($formats, ['svg']);
3639
+    }
3640
+    return $formats;
3642 3641
 }
3643 3642
 
3644 3643
 /**
@@ -3647,24 +3646,24 @@  discard block
 block discarded – undo
3647 3646
  * @return array|bool
3648 3647
  */
3649 3648
 function spip_getimagesize($fichier) {
3650
-	if (file_exists($fichier) && ($imagesize = @getimagesize($fichier))) {
3651
-		return $imagesize;
3652
-	}
3649
+    if (file_exists($fichier) && ($imagesize = @getimagesize($fichier))) {
3650
+        return $imagesize;
3651
+    }
3653 3652
 
3654
-	include_spip('inc/svg');
3655
-	if ($attrs = svg_lire_attributs($fichier)) {
3656
-		[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3657
-		$imagesize = [
3658
-			$width,
3659
-			$height,
3660
-			IMAGETYPE_SVG,
3661
-			"width=\"{$width}\" height=\"{$height}\"",
3662
-			'mime' => 'image/svg+xml'
3663
-		];
3664
-		return $imagesize;
3665
-	}
3653
+    include_spip('inc/svg');
3654
+    if ($attrs = svg_lire_attributs($fichier)) {
3655
+        [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
3656
+        $imagesize = [
3657
+            $width,
3658
+            $height,
3659
+            IMAGETYPE_SVG,
3660
+            "width=\"{$width}\" height=\"{$height}\"",
3661
+            'mime' => 'image/svg+xml'
3662
+        ];
3663
+        return $imagesize;
3664
+    }
3666 3665
 
3667
-	return false;
3666
+    return false;
3668 3667
 }
3669 3668
 
3670 3669
 /**
@@ -3678,18 +3677,18 @@  discard block
 block discarded – undo
3678 3677
  * @param string $statut
3679 3678
  */
3680 3679
 function avertir_auteurs($nom, $message, $statut = '') {
3681
-	$alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3682
-	if (
3683
-		!$alertes || !is_array($alertes = unserialize($alertes))
3684
-	) {
3685
-		$alertes = [];
3686
-	}
3680
+    $alertes = $GLOBALS['meta']['message_alertes_auteurs'];
3681
+    if (
3682
+        !$alertes || !is_array($alertes = unserialize($alertes))
3683
+    ) {
3684
+        $alertes = [];
3685
+    }
3687 3686
 
3688
-	if (!isset($alertes[$statut])) {
3689
-		$alertes[$statut] = [];
3690
-	}
3691
-	$alertes[$statut][$nom] = $message;
3692
-	ecrire_meta('message_alertes_auteurs', serialize($alertes));
3687
+    if (!isset($alertes[$statut])) {
3688
+        $alertes[$statut] = [];
3689
+    }
3690
+    $alertes[$statut][$nom] = $message;
3691
+    ecrire_meta('message_alertes_auteurs', serialize($alertes));
3693 3692
 }
3694 3693
 
3695 3694
 /**
@@ -3703,10 +3702,10 @@  discard block
 block discarded – undo
3703 3702
  * @return string|string[]
3704 3703
  */
3705 3704
 function spip_sanitize_classname($classes) {
3706
-	if (is_array($classes)) {
3707
-		return array_map('spip_sanitize_classname', $classes);
3708
-	}
3709
-	return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3705
+    if (is_array($classes)) {
3706
+        return array_map('spip_sanitize_classname', $classes);
3707
+    }
3708
+    return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes);
3710 3709
 }
3711 3710
 
3712 3711
 
@@ -3731,32 +3730,32 @@  discard block
 block discarded – undo
3731 3730
  *    Avec operateur : bool.
3732 3731
  **/
3733 3732
 function spip_version_compare($v1, $v2, $op = null) {
3734
-	$v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3735
-	$v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3736
-	$v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3737
-	$v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3738
-
3739
-	$v1 = explode('.', $v1);
3740
-	$v2 = explode('.', $v2);
3741
-	// $v1 est toujours une version, donc sans etoile
3742
-	while (count($v1) < count($v2)) {
3743
-		$v1[] = '0';
3744
-	}
3745
-
3746
-	// $v2 peut etre une borne, donc accepte l'etoile
3747
-	$etoile = false;
3748
-	foreach ($v1 as $k => $v) {
3749
-		if (!isset($v2[$k])) {
3750
-			$v2[] = ($etoile && (is_numeric($v) || $v == 'pl' || $v == 'p')) ? $v : '0';
3751
-		} else {
3752
-			if ($v2[$k] == '*') {
3753
-				$etoile = true;
3754
-				$v2[$k] = $v;
3755
-			}
3756
-		}
3757
-	}
3758
-	$v1 = implode('.', $v1);
3759
-	$v2 = implode('.', $v2);
3760
-
3761
-	return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3733
+    $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1));
3734
+    $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2));
3735
+    $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule
3736
+    $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule
3737
+
3738
+    $v1 = explode('.', $v1);
3739
+    $v2 = explode('.', $v2);
3740
+    // $v1 est toujours une version, donc sans etoile
3741
+    while (count($v1) < count($v2)) {
3742
+        $v1[] = '0';
3743
+    }
3744
+
3745
+    // $v2 peut etre une borne, donc accepte l'etoile
3746
+    $etoile = false;
3747
+    foreach ($v1 as $k => $v) {
3748
+        if (!isset($v2[$k])) {
3749
+            $v2[] = ($etoile && (is_numeric($v) || $v == 'pl' || $v == 'p')) ? $v : '0';
3750
+        } else {
3751
+            if ($v2[$k] == '*') {
3752
+                $etoile = true;
3753
+                $v2[$k] = $v;
3754
+            }
3755
+        }
3756
+    }
3757
+    $v1 = implode('.', $v1);
3758
+    $v2 = implode('.', $v2);
3759
+
3760
+    return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2);
3762 3761
 }
Please login to merge, or discard this patch.
ecrire/inc/svg.php 2 patches
Indentation   +430 added lines, -430 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 if (!defined('IMG_SVG')) {
23
-	// complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
24
-	define('IMG_SVG', 128);
25
-	define('IMAGETYPE_SVG', 19);
23
+    // complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
24
+    define('IMG_SVG', 128);
25
+    define('IMAGETYPE_SVG', 19);
26 26
 }
27 27
 
28 28
 /**
@@ -38,35 +38,35 @@  discard block
 block discarded – undo
38 38
  *   false si on a pas pu charger l'image
39 39
  */
40 40
 function svg_charger($fichier, $maxlen = null) {
41
-	if (str_starts_with($fichier, 'data:image/svg+xml')) {
42
-		$image = explode(';', $fichier, 2);
43
-		$image = end($image);
44
-		if (str_starts_with($image, 'base64,')) {
45
-			$image = base64_decode(substr($image, 7));
46
-		}
47
-		if (str_contains($image, '<svg')) {
48
-			return $image;
49
-		}
50
-		// encodage inconnu ou autre format d'image ?
51
-		return false;
52
-	}
53
-	// c'est peut etre deja une image svg ?
54
-	if (str_contains($fichier, '<svg')) {
55
-		return $fichier;
56
-	}
57
-	if (!file_exists($fichier)) {
58
-		include_spip('inc/filtres');
59
-		$fichier  = supprimer_timestamp($fichier);
60
-		if (!file_exists($fichier)) {
61
-			return false;
62
-		}
63
-	}
64
-	$image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen);
65
-	// est-ce bien une image svg ?
66
-	if (str_contains($image, '<svg')) {
67
-		return $image;
68
-	}
69
-	return false;
41
+    if (str_starts_with($fichier, 'data:image/svg+xml')) {
42
+        $image = explode(';', $fichier, 2);
43
+        $image = end($image);
44
+        if (str_starts_with($image, 'base64,')) {
45
+            $image = base64_decode(substr($image, 7));
46
+        }
47
+        if (str_contains($image, '<svg')) {
48
+            return $image;
49
+        }
50
+        // encodage inconnu ou autre format d'image ?
51
+        return false;
52
+    }
53
+    // c'est peut etre deja une image svg ?
54
+    if (str_contains($fichier, '<svg')) {
55
+        return $fichier;
56
+    }
57
+    if (!file_exists($fichier)) {
58
+        include_spip('inc/filtres');
59
+        $fichier  = supprimer_timestamp($fichier);
60
+        if (!file_exists($fichier)) {
61
+            return false;
62
+        }
63
+    }
64
+    $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen);
65
+    // est-ce bien une image svg ?
66
+    if (str_contains($image, '<svg')) {
67
+        return $image;
68
+    }
69
+    return false;
70 70
 }
71 71
 
72 72
 /**
@@ -75,28 +75,28 @@  discard block
 block discarded – undo
75 75
  * @return array|bool
76 76
  */
77 77
 function svg_lire_balise_svg($fichier) {
78
-	if (!$debut_fichier = svg_charger($fichier, 4096)) {
79
-		return false;
80
-	}
81
-
82
-	if (($ps = stripos($debut_fichier, '<svg')) !== false) {
83
-		$pe = stripos($debut_fichier, '>', $ps);
84
-		$balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
85
-
86
-		if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
87
-			if (!function_exists('extraire_attribut')) {
88
-				include_spip('inc/filtres');
89
-			}
90
-			$attributs = [];
91
-			foreach ($matches[1] as $att) {
92
-				$attributs[$att] = extraire_attribut($balise_svg, $att);
93
-			}
94
-
95
-			return [$balise_svg, $attributs];
96
-		}
97
-	}
98
-
99
-	return false;
78
+    if (!$debut_fichier = svg_charger($fichier, 4096)) {
79
+        return false;
80
+    }
81
+
82
+    if (($ps = stripos($debut_fichier, '<svg')) !== false) {
83
+        $pe = stripos($debut_fichier, '>', $ps);
84
+        $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
85
+
86
+        if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
87
+            if (!function_exists('extraire_attribut')) {
88
+                include_spip('inc/filtres');
89
+            }
90
+            $attributs = [];
91
+            foreach ($matches[1] as $att) {
92
+                $attributs[$att] = extraire_attribut($balise_svg, $att);
93
+            }
94
+
95
+            return [$balise_svg, $attributs];
96
+        }
97
+    }
98
+
99
+    return false;
100 100
 }
101 101
 
102 102
 /**
@@ -106,12 +106,12 @@  discard block
 block discarded – undo
106 106
  */
107 107
 function svg_lire_attributs($img) {
108 108
 
109
-	if ($svg_infos = svg_lire_balise_svg($img)) {
110
-		[$balise_svg, $attributs] = $svg_infos;
111
-		return $attributs;
112
-	}
109
+    if ($svg_infos = svg_lire_balise_svg($img)) {
110
+        [$balise_svg, $attributs] = $svg_infos;
111
+        return $attributs;
112
+    }
113 113
 
114
-	return false;
114
+    return false;
115 115
 }
116 116
 
117 117
 /**
@@ -121,19 +121,19 @@  discard block
 block discarded – undo
121 121
  * @return bool|float|int
122 122
  */
123 123
 function svg_dimension_to_pixels($dimension, $precision = 2) {
124
-	if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
125
-		return match (strtolower($m[2])) {
126
-			'%' => false,
127
-			'em' => round($m[1] * 16, $precision),
128
-			'ex' => round($m[1] * 16, $precision),
129
-			'pc' => round($m[1] * 16, $precision),
130
-			'cm' => round($m[1] * 96 / 2.54, $precision),
131
-			'mm' => round($m[1] * 96 / 25.4, $precision),
132
-			'in' => round($m[1] * 96, $precision),
133
-			default => $m[1],
134
-		};
135
-	}
136
-	return false;
124
+    if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
125
+        return match (strtolower($m[2])) {
126
+            '%' => false,
127
+            'em' => round($m[1] * 16, $precision),
128
+            'ex' => round($m[1] * 16, $precision),
129
+            'pc' => round($m[1] * 16, $precision),
130
+            'cm' => round($m[1] * 96 / 2.54, $precision),
131
+            'mm' => round($m[1] * 96 / 25.4, $precision),
132
+            'in' => round($m[1] * 96, $precision),
133
+            default => $m[1],
134
+        };
135
+    }
136
+    return false;
137 137
 }
138 138
 
139 139
 /**
@@ -144,14 +144,14 @@  discard block
 block discarded – undo
144 144
  * @return string
145 145
  */
146 146
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
147
-	$new_balise_svg = '<svg';
148
-	foreach ($attributs as $k => $v) {
149
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
150
-	}
151
-	$new_balise_svg .= '>';
152
-
153
-	$p = strpos($svg, $old_balise_svg);
154
-	return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
147
+    $new_balise_svg = '<svg';
148
+    foreach ($attributs as $k => $v) {
149
+        $new_balise_svg .= " $k=\"" . entites_html($v) . '"';
150
+    }
151
+    $new_balise_svg .= '>';
152
+
153
+    $p = strpos($svg, $old_balise_svg);
154
+    return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
155 155
 }
156 156
 
157 157
 /**
@@ -163,15 +163,15 @@  discard block
 block discarded – undo
163 163
  */
164 164
 function svg_insert_shapes($svg, $shapes, $start = true) {
165 165
 
166
-	if ($start === false || $start === 'end') {
167
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
168
-	}
169
-	else {
170
-		$p = stripos($svg, '<svg');
171
-		$p = strpos($svg, '>', $p);
172
-		$svg = substr_replace($svg, $shapes, $p + 1, 0);
173
-	}
174
-	return $svg;
166
+    if ($start === false || $start === 'end') {
167
+        $svg = str_replace('</svg>', $shapes . '</svg>', $svg);
168
+    }
169
+    else {
170
+        $p = stripos($svg, '<svg');
171
+        $p = strpos($svg, '>', $p);
172
+        $svg = substr_replace($svg, $shapes, $p + 1, 0);
173
+    }
174
+    return $svg;
175 175
 }
176 176
 
177 177
 /**
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
  * @return string
185 185
  */
186 186
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
187
-	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
188
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
189
-	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
190
-	$g = "<g clip-path=\"url(#$id)\">";
191
-	$svg = svg_insert_shapes($svg, $clippath . $g);
192
-	return svg_insert_shapes($svg, '</g>', false);
187
+    $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
188
+    $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
189
+    $clippath = "<clipPath id=\"$id\">$rect</clipPath>";
190
+    $g = "<g clip-path=\"url(#$id)\">";
191
+    $svg = svg_insert_shapes($svg, $clippath . $g);
192
+    return svg_insert_shapes($svg, '</g>', false);
193 193
 }
194 194
 
195 195
 /**
@@ -200,20 +200,20 @@  discard block
 block discarded – undo
200 200
  * @return bool|string
201 201
  */
202 202
 function svg_redimensionner($img, $new_width, $new_height) {
203
-	if (
204
-		($svg = svg_charger($img))
205
-		&& ($svg_infos = svg_lire_balise_svg($svg))
206
-	) {
207
-		[$balise_svg, $attributs] = $svg_infos;
208
-		if (!isset($attributs['viewBox'])) {
209
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
210
-		}
211
-		$attributs['width'] = (string) $new_width;
212
-		$attributs['height'] = (string) $new_height;
213
-		return svg_change_balise_svg($svg, $balise_svg, $attributs);
214
-	}
215
-
216
-	return $img;
203
+    if (
204
+        ($svg = svg_charger($img))
205
+        && ($svg_infos = svg_lire_balise_svg($svg))
206
+    ) {
207
+        [$balise_svg, $attributs] = $svg_infos;
208
+        if (!isset($attributs['viewBox'])) {
209
+            $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
210
+        }
211
+        $attributs['width'] = (string) $new_width;
212
+        $attributs['height'] = (string) $new_height;
213
+        return svg_change_balise_svg($svg, $balise_svg, $attributs);
214
+    }
215
+
216
+    return $img;
217 217
 }
218 218
 
219 219
 /**
@@ -222,14 +222,14 @@  discard block
 block discarded – undo
222 222
  * @return string
223 223
  */
224 224
 function svg_couleur_to_hexa($couleur) {
225
-	if (str_starts_with($couleur, 'rgb(')) {
226
-		$c = explode(',', substr($couleur, 4));
227
-		$couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]);
228
-	}
229
-	else {
230
-		$couleur = couleur_html_to_hex($couleur);
231
-	}
232
-	return '#' . ltrim($couleur, '#');
225
+    if (str_starts_with($couleur, 'rgb(')) {
226
+        $c = explode(',', substr($couleur, 4));
227
+        $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]);
228
+    }
229
+    else {
230
+        $couleur = couleur_html_to_hex($couleur);
231
+    }
232
+    return '#' . ltrim($couleur, '#');
233 233
 }
234 234
 
235 235
 /**
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
  * @return array
239 239
  */
240 240
 function svg_couleur_to_rgb($couleur) {
241
-	if (str_starts_with($couleur, 'rgb(')) {
242
-		$c = explode(',', substr($couleur, 4));
243
-		return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]];
244
-	}
245
-	return _couleur_hex_to_dec($couleur);
241
+    if (str_starts_with($couleur, 'rgb(')) {
242
+        $c = explode(',', substr($couleur, 4));
243
+        return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]];
244
+    }
245
+    return _couleur_hex_to_dec($couleur);
246 246
 }
247 247
 
248 248
 
@@ -252,80 +252,80 @@  discard block
 block discarded – undo
252 252
  * @return array
253 253
  */
254 254
 function svg_getimagesize_from_attr($attributs) {
255
-	$width = 350; // default width
256
-	$height = 150; // default height
257
-
258
-	$viewBox = "0 0 $width $height";
259
-	if (isset($attributs['viewBox'])) {
260
-		$viewBox = $attributs['viewBox'];
261
-		$viewBox = preg_replace(',\s+,', ' ', $viewBox);
262
-	}
263
-	// et on la convertit en px
264
-	$viewBox = explode(' ', $viewBox);
265
-	$viewBox = array_map('svg_dimension_to_pixels', $viewBox);
266
-	if (!$viewBox[2]) {
267
-		$viewBox[2] = $width;
268
-	}
269
-	if (!$viewBox[3]) {
270
-		$viewBox[3] = $height;
271
-	}
272
-
273
-	$coeff = 1;
274
-	if (
275
-		isset($attributs['width'])
276
-		&& ($w = svg_dimension_to_pixels($attributs['width']))
277
-	) {
278
-		$width = $w;
279
-		// si on avait pas de viewBox, la construire a partir de ce width
280
-		if (empty($attributs['viewBox'])) {
281
-			$viewBox[2] = $width;
282
-			// si pas de height valide, on suppose l'image carree
283
-			$viewBox[3] = $width;
284
-		}
285
-	}
286
-	else {
287
-		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
288
-		$width = $viewBox[2];
289
-		if ($width < 1) {
290
-			$coeff = max($coeff, 1000);
291
-		}
292
-		elseif ($width < 10) {
293
-			$coeff = max($coeff, 100);
294
-		}
295
-		elseif ($width < 100) {
296
-			$coeff = max($coeff, 10);
297
-		}
298
-	}
299
-	if (
300
-		isset($attributs['height'])
301
-		&& ($h = svg_dimension_to_pixels($attributs['height']))
302
-	) {
303
-		$height = $h;
304
-		// si on avait pas de viewBox, la construire a partir de ce height
305
-		if (empty($attributs['viewBox'])) {
306
-			$viewBox[3] = $height;
307
-		}
308
-	}
309
-	else {
310
-		$height = $viewBox[3];
311
-		if ($height < 1) {
312
-			$coeff = max($coeff, 1000);
313
-		}
314
-		elseif ($height < 10) {
315
-			$coeff = max($coeff, 100);
316
-		}
317
-		elseif ($height < 100) {
318
-			$coeff = max($coeff, 10);
319
-		}
320
-	}
321
-
322
-	// arrondir le width et height en pixel in fine
323
-	$width = round($coeff * $width);
324
-	$height = round($coeff * $height);
325
-
326
-	$viewBox = implode(' ', $viewBox);
327
-
328
-	return [$width, $height, $viewBox];
255
+    $width = 350; // default width
256
+    $height = 150; // default height
257
+
258
+    $viewBox = "0 0 $width $height";
259
+    if (isset($attributs['viewBox'])) {
260
+        $viewBox = $attributs['viewBox'];
261
+        $viewBox = preg_replace(',\s+,', ' ', $viewBox);
262
+    }
263
+    // et on la convertit en px
264
+    $viewBox = explode(' ', $viewBox);
265
+    $viewBox = array_map('svg_dimension_to_pixels', $viewBox);
266
+    if (!$viewBox[2]) {
267
+        $viewBox[2] = $width;
268
+    }
269
+    if (!$viewBox[3]) {
270
+        $viewBox[3] = $height;
271
+    }
272
+
273
+    $coeff = 1;
274
+    if (
275
+        isset($attributs['width'])
276
+        && ($w = svg_dimension_to_pixels($attributs['width']))
277
+    ) {
278
+        $width = $w;
279
+        // si on avait pas de viewBox, la construire a partir de ce width
280
+        if (empty($attributs['viewBox'])) {
281
+            $viewBox[2] = $width;
282
+            // si pas de height valide, on suppose l'image carree
283
+            $viewBox[3] = $width;
284
+        }
285
+    }
286
+    else {
287
+        // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
288
+        $width = $viewBox[2];
289
+        if ($width < 1) {
290
+            $coeff = max($coeff, 1000);
291
+        }
292
+        elseif ($width < 10) {
293
+            $coeff = max($coeff, 100);
294
+        }
295
+        elseif ($width < 100) {
296
+            $coeff = max($coeff, 10);
297
+        }
298
+    }
299
+    if (
300
+        isset($attributs['height'])
301
+        && ($h = svg_dimension_to_pixels($attributs['height']))
302
+    ) {
303
+        $height = $h;
304
+        // si on avait pas de viewBox, la construire a partir de ce height
305
+        if (empty($attributs['viewBox'])) {
306
+            $viewBox[3] = $height;
307
+        }
308
+    }
309
+    else {
310
+        $height = $viewBox[3];
311
+        if ($height < 1) {
312
+            $coeff = max($coeff, 1000);
313
+        }
314
+        elseif ($height < 10) {
315
+            $coeff = max($coeff, 100);
316
+        }
317
+        elseif ($height < 100) {
318
+            $coeff = max($coeff, 10);
319
+        }
320
+    }
321
+
322
+    // arrondir le width et height en pixel in fine
323
+    $width = round($coeff * $width);
324
+    $height = round($coeff * $height);
325
+
326
+    $viewBox = implode(' ', $viewBox);
327
+
328
+    return [$width, $height, $viewBox];
329 329
 }
330 330
 
331 331
 /**
@@ -341,23 +341,23 @@  discard block
 block discarded – undo
341 341
  * @return string
342 342
  */
343 343
 function svg_force_viewBox_px($img, $force_width_and_height = false) {
344
-	if (
345
-		($svg = svg_charger($img))
346
-		&& ($svg_infos = svg_lire_balise_svg($svg))
347
-	) {
348
-		[$balise_svg, $attributs] = $svg_infos;
349
-
350
-		[$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs);
351
-
352
-		if ($force_width_and_height) {
353
-			$attributs['width'] = $width;
354
-			$attributs['height'] = $height;
355
-		}
356
-
357
-		$attributs['viewBox'] = $viewBox;
358
-		return svg_change_balise_svg($svg, $balise_svg, $attributs);
359
-	}
360
-	return $img;
344
+    if (
345
+        ($svg = svg_charger($img))
346
+        && ($svg_infos = svg_lire_balise_svg($svg))
347
+    ) {
348
+        [$balise_svg, $attributs] = $svg_infos;
349
+
350
+        [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs);
351
+
352
+        if ($force_width_and_height) {
353
+            $attributs['width'] = $width;
354
+            $attributs['height'] = $height;
355
+        }
356
+
357
+        $attributs['viewBox'] = $viewBox;
358
+        return svg_change_balise_svg($svg, $balise_svg, $attributs);
359
+    }
360
+    return $img;
361 361
 }
362 362
 
363 363
 /**
@@ -366,13 +366,13 @@  discard block
 block discarded – undo
366 366
  * @return array|mixed
367 367
  */
368 368
 function svg_extract_couleurs($img) {
369
-	if (
370
-		($svg = svg_charger($img))
371
-		&& preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)
372
-	) {
373
-		return $matches[0];
374
-	}
375
-	return [];
369
+    if (
370
+        ($svg = svg_charger($img))
371
+        && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)
372
+    ) {
373
+        return $matches[0];
374
+    }
375
+    return [];
376 376
 }
377 377
 
378 378
 /**
@@ -383,58 +383,58 @@  discard block
 block discarded – undo
383 383
  * @return bool|string
384 384
  */
385 385
 function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') {
386
-	if (
387
-		($svg = svg_force_viewBox_px($img))
388
-		&& ($svg_infos = svg_lire_balise_svg($svg))
389
-	) {
390
-		[$balise_svg, $attributs] = $svg_infos;
391
-		$viewBox = explode(' ', $attributs['viewBox']);
392
-
393
-		$viewport_w = $new_width;
394
-		$viewport_h = $new_height;
395
-		$viewport_ox = $offset_width;
396
-		$viewport_oy = $offset_height;
397
-
398
-		// si on a un width/height qui rescale, il faut rescaler
399
-		if (
400
-			isset($attributs['width'])
401
-			&& ($w = svg_dimension_to_pixels($attributs['width']))
402
-			&& isset($attributs['height'])
403
-			&& ($h = svg_dimension_to_pixels($attributs['height']))
404
-		) {
405
-			$xscale = $viewBox[2] / $w;
406
-			$viewport_w = round($viewport_w * $xscale, 2);
407
-			$viewport_ox = round($viewport_ox * $xscale, 2);
408
-			$yscale = $viewBox[3] / $h;
409
-			$viewport_h = round($viewport_h * $yscale, 2);
410
-			$viewport_oy = round($viewport_oy * $yscale, 2);
411
-		}
412
-
413
-		if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) {
414
-			$svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
415
-		}
416
-
417
-		// maintenant on redefinit la viewBox
418
-		$viewBox[0] += $viewport_ox;
419
-		$viewBox[1] += $viewport_oy;
420
-		$viewBox[2] = $viewport_w;
421
-		$viewBox[3] = $viewport_h;
422
-
423
-		$attributs['viewBox'] = implode(' ', $viewBox);
424
-		$attributs['width'] = (string) $new_width;
425
-		$attributs['height'] = (string) $new_height;
426
-
427
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
428
-
429
-		// ajouter un background
430
-		if ($background_color && $background_color !== 'transparent') {
431
-			$svg = svg_ajouter_background($svg, $background_color);
432
-		}
433
-
434
-		return $svg;
435
-	}
436
-
437
-	return $img;
386
+    if (
387
+        ($svg = svg_force_viewBox_px($img))
388
+        && ($svg_infos = svg_lire_balise_svg($svg))
389
+    ) {
390
+        [$balise_svg, $attributs] = $svg_infos;
391
+        $viewBox = explode(' ', $attributs['viewBox']);
392
+
393
+        $viewport_w = $new_width;
394
+        $viewport_h = $new_height;
395
+        $viewport_ox = $offset_width;
396
+        $viewport_oy = $offset_height;
397
+
398
+        // si on a un width/height qui rescale, il faut rescaler
399
+        if (
400
+            isset($attributs['width'])
401
+            && ($w = svg_dimension_to_pixels($attributs['width']))
402
+            && isset($attributs['height'])
403
+            && ($h = svg_dimension_to_pixels($attributs['height']))
404
+        ) {
405
+            $xscale = $viewBox[2] / $w;
406
+            $viewport_w = round($viewport_w * $xscale, 2);
407
+            $viewport_ox = round($viewport_ox * $xscale, 2);
408
+            $yscale = $viewBox[3] / $h;
409
+            $viewport_h = round($viewport_h * $yscale, 2);
410
+            $viewport_oy = round($viewport_oy * $yscale, 2);
411
+        }
412
+
413
+        if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) {
414
+            $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
415
+        }
416
+
417
+        // maintenant on redefinit la viewBox
418
+        $viewBox[0] += $viewport_ox;
419
+        $viewBox[1] += $viewport_oy;
420
+        $viewBox[2] = $viewport_w;
421
+        $viewBox[3] = $viewport_h;
422
+
423
+        $attributs['viewBox'] = implode(' ', $viewBox);
424
+        $attributs['width'] = (string) $new_width;
425
+        $attributs['height'] = (string) $new_height;
426
+
427
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
428
+
429
+        // ajouter un background
430
+        if ($background_color && $background_color !== 'transparent') {
431
+            $svg = svg_ajouter_background($svg, $background_color);
432
+        }
433
+
434
+        return $svg;
435
+    }
436
+
437
+    return $img;
438 438
 }
439 439
 
440 440
 /**
@@ -444,26 +444,26 @@  discard block
 block discarded – undo
444 444
  * @return bool|string
445 445
  */
446 446
 function svg_ajouter_background($img, $background_color) {
447
-	if (
448
-		($svg = svg_charger($img))
449
-		&& ($svg_infos = svg_lire_balise_svg($svg))
450
-	) {
451
-		if ($background_color && $background_color !== 'transparent') {
452
-			[$balise_svg, $attributs] = $svg_infos;
453
-
454
-			$background_color = svg_couleur_to_hexa($background_color);
455
-			if (isset($attributs['viewBox'])) {
456
-				$viewBox = explode(' ', $attributs['viewBox']);
457
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
458
-			}
459
-			else {
460
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
461
-			}
462
-			$svg = svg_insert_shapes($svg, $rect);
463
-		}
464
-		return $svg;
465
-	}
466
-	return $img;
447
+    if (
448
+        ($svg = svg_charger($img))
449
+        && ($svg_infos = svg_lire_balise_svg($svg))
450
+    ) {
451
+        if ($background_color && $background_color !== 'transparent') {
452
+            [$balise_svg, $attributs] = $svg_infos;
453
+
454
+            $background_color = svg_couleur_to_hexa($background_color);
455
+            if (isset($attributs['viewBox'])) {
456
+                $viewBox = explode(' ', $attributs['viewBox']);
457
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
458
+            }
459
+            else {
460
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
461
+            }
462
+            $svg = svg_insert_shapes($svg, $rect);
463
+        }
464
+        return $svg;
465
+    }
466
+    return $img;
467 467
 }
468 468
 
469 469
 
@@ -474,26 +474,26 @@  discard block
 block discarded – undo
474 474
  * @return bool|string
475 475
  */
476 476
 function svg_ajouter_voile($img, $background_color, $opacity) {
477
-	if (
478
-		($svg = svg_charger($img))
479
-		&& ($svg_infos = svg_lire_balise_svg($svg))
480
-	) {
481
-		if ($background_color && $background_color !== 'transparent') {
482
-			[$balise_svg, $attributs] = $svg_infos;
483
-
484
-			$background_color = svg_couleur_to_hexa($background_color);
485
-			if (isset($attributs['viewBox'])) {
486
-				$viewBox = explode(' ', $attributs['viewBox']);
487
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
488
-			}
489
-			else {
490
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
491
-			}
492
-			$svg = svg_insert_shapes($svg, $rect, false);
493
-		}
494
-		return $svg;
495
-	}
496
-	return $img;
477
+    if (
478
+        ($svg = svg_charger($img))
479
+        && ($svg_infos = svg_lire_balise_svg($svg))
480
+    ) {
481
+        if ($background_color && $background_color !== 'transparent') {
482
+            [$balise_svg, $attributs] = $svg_infos;
483
+
484
+            $background_color = svg_couleur_to_hexa($background_color);
485
+            if (isset($attributs['viewBox'])) {
486
+                $viewBox = explode(' ', $attributs['viewBox']);
487
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
488
+            }
489
+            else {
490
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
491
+            }
492
+            $svg = svg_insert_shapes($svg, $rect, false);
493
+        }
494
+        return $svg;
495
+    }
496
+    return $img;
497 497
 }
498 498
 
499 499
 
@@ -504,27 +504,27 @@  discard block
 block discarded – undo
504 504
  * @return bool|string
505 505
  */
506 506
 function svg_transformer($img, $attributs) {
507
-	if (
508
-		($svg = svg_charger($img))
509
-		&& ($svg_infos = svg_lire_balise_svg($svg))
510
-	) {
511
-		if ($attributs) {
512
-			[$balise_svg, ] = $svg_infos;
513
-			$g = '<g';
514
-			foreach ($attributs as $k => $v) {
515
-				if (strlen($v)) {
516
-					$g .= " $k=\"" . attribut_html($v) . '"';
517
-				}
518
-			}
519
-			if (strlen($g) > 2) {
520
-				$g .= '>';
521
-				$svg = svg_insert_shapes($svg, $g);
522
-				$svg = svg_insert_shapes($svg, '</g>', false);
523
-			}
524
-		}
525
-		return $svg;
526
-	}
527
-	return $img;
507
+    if (
508
+        ($svg = svg_charger($img))
509
+        && ($svg_infos = svg_lire_balise_svg($svg))
510
+    ) {
511
+        if ($attributs) {
512
+            [$balise_svg, ] = $svg_infos;
513
+            $g = '<g';
514
+            foreach ($attributs as $k => $v) {
515
+                if (strlen($v)) {
516
+                    $g .= " $k=\"" . attribut_html($v) . '"';
517
+                }
518
+            }
519
+            if (strlen($g) > 2) {
520
+                $g .= '>';
521
+                $svg = svg_insert_shapes($svg, $g);
522
+                $svg = svg_insert_shapes($svg, '</g>', false);
523
+            }
524
+        }
525
+        return $svg;
526
+    }
527
+    return $img;
528 528
 }
529 529
 
530 530
 /**
@@ -535,21 +535,21 @@  discard block
 block discarded – undo
535 535
  * @return bool|string
536 536
  */
537 537
 function svg_apply_filter($img, $filter_def) {
538
-	if (
539
-		($svg = svg_charger($img))
540
-		&& ($svg_infos = svg_lire_balise_svg($svg))
541
-	) {
542
-		if ($filter_def) {
543
-			[$balise_svg, ] = $svg_infos;
544
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
545
-			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
546
-			$g = "<g filter=\"url(#$filter_id)\">";
547
-			$svg = svg_insert_shapes($svg, $filter . $g);
548
-			$svg = svg_insert_shapes($svg, '</g>', false);
549
-		}
550
-		return $svg;
551
-	}
552
-	return $img;
538
+    if (
539
+        ($svg = svg_charger($img))
540
+        && ($svg_infos = svg_lire_balise_svg($svg))
541
+    ) {
542
+        if ($filter_def) {
543
+            [$balise_svg, ] = $svg_infos;
544
+            $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
545
+            $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
546
+            $g = "<g filter=\"url(#$filter_id)\">";
547
+            $svg = svg_insert_shapes($svg, $filter . $g);
548
+            $svg = svg_insert_shapes($svg, '</g>', false);
549
+        }
550
+        return $svg;
551
+    }
552
+    return $img;
553 553
 }
554 554
 
555 555
 /**
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
  * @return string
560 560
  */
561 561
 function svg_filter_blur($img, $blur_width) {
562
-	$blur_width = (int) $blur_width;
563
-	return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
562
+    $blur_width = (int) $blur_width;
563
+    return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
564 564
 }
565 565
 
566 566
 /**
@@ -570,10 +570,10 @@  discard block
 block discarded – undo
570 570
  * @return bool|string
571 571
  */
572 572
 function svg_filter_grayscale($img, $intensity) {
573
-	$value = round(1.0 - $intensity, 2);
574
-	//$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
575
-	$filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
576
-	return svg_apply_filter($img, $filter);
573
+    $value = round(1.0 - $intensity, 2);
574
+    //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
575
+    $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
576
+    return svg_apply_filter($img, $filter);
577 577
 }
578 578
 
579 579
 /**
@@ -586,8 +586,8 @@  discard block
 block discarded – undo
586 586
  * @return bool|string
587 587
  */
588 588
 function svg_filter_sepia($img, $intensity) {
589
-	$filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
590
-	return svg_apply_filter($img, $filter);
589
+    $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
590
+    return svg_apply_filter($img, $filter);
591 591
 }
592 592
 
593 593
 /**
@@ -597,30 +597,30 @@  discard block
 block discarded – undo
597 597
  * @return bool|string
598 598
  */
599 599
 function svg_flip($img, $HorV) {
600
-	if (
601
-		($svg = svg_force_viewBox_px($img))
602
-		&& ($svg_infos = svg_lire_balise_svg($svg))
603
-	) {
604
-		[$balise_svg, $atts] = $svg_infos;
605
-		$viewBox = explode(' ', $atts['viewBox']);
606
-
607
-		if (!in_array($HorV, ['h', 'H'])) {
608
-			$transform = 'scale(-1,1)';
609
-
610
-			$x = (int) $viewBox[0] + (int) ($viewBox[2] / 2);
611
-			$mx = -$x;
612
-			$transform = "translate($x, 0) $transform translate($mx, 0)";
613
-		}
614
-		else {
615
-			$transform = 'scale(1,-1)';
616
-
617
-			$y = (int) $viewBox[1] + (int) ($viewBox[3] / 2);
618
-			$my = -$y;
619
-			$transform = "translate(0, $y) $transform translate(0, $my)";
620
-		}
621
-		return svg_transformer($svg, ['transform' => $transform]);
622
-	}
623
-	return $img;
600
+    if (
601
+        ($svg = svg_force_viewBox_px($img))
602
+        && ($svg_infos = svg_lire_balise_svg($svg))
603
+    ) {
604
+        [$balise_svg, $atts] = $svg_infos;
605
+        $viewBox = explode(' ', $atts['viewBox']);
606
+
607
+        if (!in_array($HorV, ['h', 'H'])) {
608
+            $transform = 'scale(-1,1)';
609
+
610
+            $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2);
611
+            $mx = -$x;
612
+            $transform = "translate($x, 0) $transform translate($mx, 0)";
613
+        }
614
+        else {
615
+            $transform = 'scale(1,-1)';
616
+
617
+            $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2);
618
+            $my = -$y;
619
+            $transform = "translate(0, $y) $transform translate(0, $my)";
620
+        }
621
+        return svg_transformer($svg, ['transform' => $transform]);
622
+    }
623
+    return $img;
624 624
 }
625 625
 
626 626
 /**
@@ -634,19 +634,19 @@  discard block
 block discarded – undo
634 634
  * @return bool|string
635 635
  */
636 636
 function svg_rotate($img, $angle, $center_x, $center_y) {
637
-	if (
638
-		($svg = svg_force_viewBox_px($img))
639
-		&& ($svg_infos = svg_lire_balise_svg($svg))
640
-	) {
641
-		[$balise_svg, $atts] = $svg_infos;
642
-		$viewBox = explode(' ', $atts['viewBox']);
643
-
644
-		$center_x = round($viewBox[0] + $center_x * $viewBox[2]);
645
-		$center_y = round($viewBox[1] + $center_y * $viewBox[3]);
646
-
647
-		return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
648
-	}
649
-	return $img;
637
+    if (
638
+        ($svg = svg_force_viewBox_px($img))
639
+        && ($svg_infos = svg_lire_balise_svg($svg))
640
+    ) {
641
+        [$balise_svg, $atts] = $svg_infos;
642
+        $viewBox = explode(' ', $atts['viewBox']);
643
+
644
+        $center_x = round($viewBox[0] + $center_x * $viewBox[2]);
645
+        $center_y = round($viewBox[1] + $center_y * $viewBox[3]);
646
+
647
+        return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
648
+    }
649
+    return $img;
650 650
 }
651 651
 
652 652
 /**
@@ -658,40 +658,40 @@  discard block
 block discarded – undo
658 658
  * @return bool|mixed|string
659 659
  */
660 660
 function svg_filtrer_couleurs($img, $callback_filter) {
661
-	if (
662
-		($svg = svg_force_viewBox_px($img))
663
-		&& ($colors = svg_extract_couleurs($svg))
664
-	) {
665
-		$colors = array_unique($colors);
666
-
667
-		$short = [];
668
-		$long = [];
669
-		while (count($colors)) {
670
-			$c = array_shift($colors);
671
-			if (strlen($c) == 4) {
672
-				$short[] = $c;
673
-			}
674
-			else {
675
-				$long[] = $c;
676
-			}
677
-		}
678
-
679
-		$colors = [...$long, ...$short];
680
-		$new_colors = [];
681
-		$colors = array_flip($colors);
682
-		foreach ($colors as $c => $k) {
683
-			$colors[$c] = "@@@COLOR$$k$@@@";
684
-		}
685
-
686
-
687
-		foreach ($colors as $original => $replace) {
688
-			$new = svg_couleur_to_hexa($original);
689
-			$new_colors[$replace] = $callback_filter($new);
690
-		}
691
-
692
-		$svg = str_replace(array_keys($colors), array_values($colors), $svg);
693
-
694
-		return str_replace(array_keys($new_colors), array_values($new_colors), $svg);
695
-	}
696
-	return $img;
661
+    if (
662
+        ($svg = svg_force_viewBox_px($img))
663
+        && ($colors = svg_extract_couleurs($svg))
664
+    ) {
665
+        $colors = array_unique($colors);
666
+
667
+        $short = [];
668
+        $long = [];
669
+        while (count($colors)) {
670
+            $c = array_shift($colors);
671
+            if (strlen($c) == 4) {
672
+                $short[] = $c;
673
+            }
674
+            else {
675
+                $long[] = $c;
676
+            }
677
+        }
678
+
679
+        $colors = [...$long, ...$short];
680
+        $new_colors = [];
681
+        $colors = array_flip($colors);
682
+        foreach ($colors as $c => $k) {
683
+            $colors[$c] = "@@@COLOR$$k$@@@";
684
+        }
685
+
686
+
687
+        foreach ($colors as $original => $replace) {
688
+            $new = svg_couleur_to_hexa($original);
689
+            $new_colors[$replace] = $callback_filter($new);
690
+        }
691
+
692
+        $svg = str_replace(array_keys($colors), array_values($colors), $svg);
693
+
694
+        return str_replace(array_keys($new_colors), array_values($new_colors), $svg);
695
+    }
696
+    return $img;
697 697
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	}
57 57
 	if (!file_exists($fichier)) {
58 58
 		include_spip('inc/filtres');
59
-		$fichier  = supprimer_timestamp($fichier);
59
+		$fichier = supprimer_timestamp($fichier);
60 60
 		if (!file_exists($fichier)) {
61 61
 			return false;
62 62
 		}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
147 147
 	$new_balise_svg = '<svg';
148 148
 	foreach ($attributs as $k => $v) {
149
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
149
+		$new_balise_svg .= " $k=\"".entites_html($v).'"';
150 150
 	}
151 151
 	$new_balise_svg .= '>';
152 152
 
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 function svg_insert_shapes($svg, $shapes, $start = true) {
165 165
 
166 166
 	if ($start === false || $start === 'end') {
167
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
167
+		$svg = str_replace('</svg>', $shapes.'</svg>', $svg);
168 168
 	}
169 169
 	else {
170 170
 		$p = stripos($svg, '<svg');
@@ -185,10 +185,10 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
187 187
 	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
188
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
188
+	$id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8);
189 189
 	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
190 190
 	$g = "<g clip-path=\"url(#$id)\">";
191
-	$svg = svg_insert_shapes($svg, $clippath . $g);
191
+	$svg = svg_insert_shapes($svg, $clippath.$g);
192 192
 	return svg_insert_shapes($svg, '</g>', false);
193 193
 }
194 194
 
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
 	) {
207 207
 		[$balise_svg, $attributs] = $svg_infos;
208 208
 		if (!isset($attributs['viewBox'])) {
209
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
209
+			$attributs['viewBox'] = '0 0 '.$attributs['width'].' '.$attributs['height'];
210 210
 		}
211 211
 		$attributs['width'] = (string) $new_width;
212 212
 		$attributs['height'] = (string) $new_height;
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 	else {
230 230
 		$couleur = couleur_html_to_hex($couleur);
231 231
 	}
232
-	return '#' . ltrim($couleur, '#');
232
+	return '#'.ltrim($couleur, '#');
233 233
 }
234 234
 
235 235
 /**
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 function svg_couleur_to_rgb($couleur) {
241 241
 	if (str_starts_with($couleur, 'rgb(')) {
242 242
 		$c = explode(',', substr($couleur, 4));
243
-		return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]];
243
+		return ['red' => (int) $c[0], 'green' => (int) $c[1], 'blue' => (int) $c[2]];
244 244
 	}
245 245
 	return _couleur_hex_to_dec($couleur);
246 246
 }
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 			$background_color = svg_couleur_to_hexa($background_color);
455 455
 			if (isset($attributs['viewBox'])) {
456 456
 				$viewBox = explode(' ', $attributs['viewBox']);
457
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
457
+				$rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\"/>";
458 458
 			}
459 459
 			else {
460 460
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 			$background_color = svg_couleur_to_hexa($background_color);
485 485
 			if (isset($attributs['viewBox'])) {
486 486
 				$viewBox = explode(' ', $attributs['viewBox']);
487
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
487
+				$rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>";
488 488
 			}
489 489
 			else {
490 490
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
 			$g = '<g';
514 514
 			foreach ($attributs as $k => $v) {
515 515
 				if (strlen($v)) {
516
-					$g .= " $k=\"" . attribut_html($v) . '"';
516
+					$g .= " $k=\"".attribut_html($v).'"';
517 517
 				}
518 518
 			}
519 519
 			if (strlen($g) > 2) {
@@ -541,10 +541,10 @@  discard block
 block discarded – undo
541 541
 	) {
542 542
 		if ($filter_def) {
543 543
 			[$balise_svg, ] = $svg_infos;
544
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
544
+			$filter_id = 'filter-'.substr(md5($filter_def.strlen($svg)), 0, 8);
545 545
 			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
546 546
 			$g = "<g filter=\"url(#$filter_id)\">";
547
-			$svg = svg_insert_shapes($svg, $filter . $g);
547
+			$svg = svg_insert_shapes($svg, $filter.$g);
548 548
 			$svg = svg_insert_shapes($svg, '</g>', false);
549 549
 		}
550 550
 		return $svg;
Please login to merge, or discard this patch.