Completed
Push — master ( 8add54...8bab99 )
by cam
01:19
created
ecrire/inc/filtres.php 1 patch
Indentation   +2347 added lines, -2347 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
  * @package SPIP\Core\Filtres
21 21
  **/
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 include_spip('inc/charsets');
@@ -46,8 +46,8 @@  discard block
 block discarded – undo
46 46
  * @return string Fonction PHP correspondante du filtre
47 47
  */
48 48
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
49
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
50
-	return chercher_filtre($fonc, $default);
49
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
50
+    return chercher_filtre($fonc, $default);
51 51
 }
52 52
 
53 53
 /**
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
  * @return string texte
58 58
  **/
59 59
 function filtre_identite_dist($texte) {
60
- return $texte;
60
+    return $texte;
61 61
 }
62 62
 
63 63
 /**
@@ -81,33 +81,33 @@  discard block
 block discarded – undo
81 81
  *     Fonction PHP correspondante du filtre demandé
82 82
  */
83 83
 function chercher_filtre($fonc, $default = null) {
84
-	if (!$fonc) {
85
-		return $default;
86
-	}
87
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
88
-	// Foo::Bar
89
-	// qui peuvent etre avec un namespace : space\Foo::Bar
90
-	if (preg_match(',^[\w]+/,', $fonc)) {
91
-		$nom = preg_replace(',\W,', '_', $fonc);
92
-		$f = chercher_filtre($nom);
93
-		// cas du sous-type MIME sans filtre associe, passer au type:
94
-		// si filtre_text_plain pas defini, passe a filtre_text
95
-		if (!$f && $nom !== $fonc) {
96
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
97
-		}
98
-
99
-		return $f;
100
-	}
101
-
102
-	include_fichiers_fonctions();
103
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
104
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
105
-		if (is_callable($f)) {
106
-			return $f;
107
-		}
108
-	}
109
-
110
-	return $default;
84
+    if (!$fonc) {
85
+        return $default;
86
+    }
87
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
88
+    // Foo::Bar
89
+    // qui peuvent etre avec un namespace : space\Foo::Bar
90
+    if (preg_match(',^[\w]+/,', $fonc)) {
91
+        $nom = preg_replace(',\W,', '_', $fonc);
92
+        $f = chercher_filtre($nom);
93
+        // cas du sous-type MIME sans filtre associe, passer au type:
94
+        // si filtre_text_plain pas defini, passe a filtre_text
95
+        if (!$f && $nom !== $fonc) {
96
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
97
+        }
98
+
99
+        return $f;
100
+    }
101
+
102
+    include_fichiers_fonctions();
103
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
104
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
105
+        if (is_callable($f)) {
106
+            return $f;
107
+        }
108
+    }
109
+
110
+    return $default;
111 111
 }
112 112
 
113 113
 /**
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
  *     Chaîne vide sinon.
152 152
  **/
153 153
 function appliquer_filtre(mixed $arg, $filtre) {
154
-	$args = func_get_args();
155
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
154
+    $args = func_get_args();
155
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
156 156
 }
157 157
 
158 158
 /**
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
  *     texte d'origine sinon
178 178
  **/
179 179
 function appliquer_si_filtre(mixed $arg, $filtre) {
180
-	$args = func_get_args();
181
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
180
+    $args = func_get_args();
181
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
182 182
 }
183 183
 
184 184
 /**
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
  *     Version de SPIP
195 195
  **/
196 196
 function spip_version() {
197
-	$version = $GLOBALS['spip_version_affichee'];
198
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
199
-		$version .= " $vcs_version";
200
-	}
197
+    $version = $GLOBALS['spip_version_affichee'];
198
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
199
+        $version .= " $vcs_version";
200
+    }
201 201
 
202
-	return $version;
202
+    return $version;
203 203
 }
204 204
 
205 205
 /**
@@ -211,11 +211,11 @@  discard block
 block discarded – undo
211 211
  * @return string
212 212
  */
213 213
 function header_silencieux($version): string {
214
-	if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
215
-		$version = '';
216
-	}
214
+    if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
215
+        $version = '';
216
+    }
217 217
 
218
-	return (string) $version;
218
+    return (string) $version;
219 219
 }
220 220
 
221 221
 /**
@@ -228,16 +228,16 @@  discard block
 block discarded – undo
228 228
  *    - string|null si $raw = false
229 229
  */
230 230
 function version_vcs_courante($dir, $raw = false) {
231
-	$desc = decrire_version_git($dir);
232
-	if ($desc === null || $raw) {
233
-		return $desc;
234
-	}
235
-	// affichage "GIT [master: abcdef]"
236
-	$commit = $desc['commit_short'] ?? $desc['commit'];
237
-	if ($desc['branch']) {
238
-		$commit = $desc['branch'] . ': ' . $commit;
239
-	}
240
-	return "{$desc['vcs']} [$commit]";
231
+    $desc = decrire_version_git($dir);
232
+    if ($desc === null || $raw) {
233
+        return $desc;
234
+    }
235
+    // affichage "GIT [master: abcdef]"
236
+    $commit = $desc['commit_short'] ?? $desc['commit'];
237
+    if ($desc['branch']) {
238
+        $commit = $desc['branch'] . ': ' . $commit;
239
+    }
240
+    return "{$desc['vcs']} [$commit]";
241 241
 }
242 242
 
243 243
 /**
@@ -249,26 +249,26 @@  discard block
 block discarded – undo
249 249
  *      array ['branch' => xx, 'commit' => yy] sinon.
250 250
  **/
251 251
 function decrire_version_git($dir) {
252
-	$c = null;
253
-	$hash = null;
254
-	if (!$dir) {
255
-		$dir = '.';
256
-	}
257
-
258
-	// version installee par GIT
259
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
260
-		$currentHead = trim(substr((string) $c, 4));
261
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
262
-			return [
263
-				'vcs' => 'GIT',
264
-				'branch' => basename($currentHead),
265
-				'commit' => trim((string) $hash),
266
-				'commit_short' => substr(trim((string) $hash), 0, 8),
267
-			];
268
-		}
269
-	}
270
-
271
-	return null;
252
+    $c = null;
253
+    $hash = null;
254
+    if (!$dir) {
255
+        $dir = '.';
256
+    }
257
+
258
+    // version installee par GIT
259
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
260
+        $currentHead = trim(substr((string) $c, 4));
261
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
262
+            return [
263
+                'vcs' => 'GIT',
264
+                'branch' => basename($currentHead),
265
+                'commit' => trim((string) $hash),
266
+                'commit_short' => substr(trim((string) $hash), 0, 8),
267
+            ];
268
+        }
269
+    }
270
+
271
+    return null;
272 272
 }
273 273
 
274 274
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -315,18 +315,18 @@  discard block
 block discarded – undo
315 315
  *     Code HTML retourné par le filtre
316 316
  **/
317 317
 function filtrer($filtre) {
318
-	$tous = func_get_args();
319
-	if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) {
320
-		return image_filtrer($tous);
321
-	} elseif ($f = chercher_filtre($filtre)) {
322
-		array_shift($tous);
323
-		return $f(...$tous);
324
-	} else {
325
-		// le filtre n'existe pas, on provoque une erreur
326
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
327
-		erreur_squelette($msg);
328
-		return '';
329
-	}
318
+    $tous = func_get_args();
319
+    if (trouver_filtre_matrice($filtre) && str_starts_with($filtre, 'image_')) {
320
+        return image_filtrer($tous);
321
+    } elseif ($f = chercher_filtre($filtre)) {
322
+        array_shift($tous);
323
+        return $f(...$tous);
324
+    } else {
325
+        // le filtre n'existe pas, on provoque une erreur
326
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
327
+        erreur_squelette($msg);
328
+        return '';
329
+    }
330 330
 }
331 331
 
332 332
 /**
@@ -343,11 +343,11 @@  discard block
 block discarded – undo
343 343
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
344 344
  */
345 345
 function trouver_filtre_matrice($filtre) {
346
-	if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
347
-		find_in_path($f, '', true);
348
-		$GLOBALS['spip_matrice'][$filtre] = true;
349
-	}
350
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
346
+    if (isset($GLOBALS['spip_matrice'][$filtre]) && is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
347
+        find_in_path($f, '', true);
348
+        $GLOBALS['spip_matrice'][$filtre] = true;
349
+    }
350
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
351 351
 }
352 352
 
353 353
 
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
  * @return mixed
376 376
  */
377 377
 function filtre_set(&$Pile, mixed $val, $key, $continue = null) {
378
-	$Pile['vars'][$key] = $val;
379
-	return $continue ? $val : '';
378
+    $Pile['vars'][$key] = $val;
379
+    return $continue ? $val : '';
380 380
 }
381 381
 
382 382
 /**
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
403 403
  */
404 404
 function filtre_setenv(&$Pile, mixed $val, mixed $key, $continue = null) {
405
-	$Pile[0][$key] = $val;
406
-	return $continue ? $val : '';
405
+    $Pile[0][$key] = $val;
406
+    return $continue ? $val : '';
407 407
 }
408 408
 
409 409
 /**
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
  * @return string
413 413
  */
414 414
 function filtre_sanitize_env(&$Pile, $keys) {
415
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
416
-	return '';
415
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
416
+    return '';
417 417
 }
418 418
 
419 419
 
@@ -436,18 +436,18 @@  discard block
 block discarded – undo
436 436
  * @return mixed Retourne la valeur (sans la modifier).
437 437
  */
438 438
 function filtre_debug(mixed $val, $key = null) {
439
-	$debug = (
440
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
441
-		) . var_export($val, true);
439
+    $debug = (
440
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
441
+        ) . var_export($val, true);
442 442
 
443
-	include_spip('inc/autoriser');
444
-	if (autoriser('webmestre')) {
445
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
446
-	}
443
+    include_spip('inc/autoriser');
444
+    if (autoriser('webmestre')) {
445
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
446
+    }
447 447
 
448
-	spip_logger('debug')->info($debug);
448
+    spip_logger('debug')->info($debug);
449 449
 
450
-	return $val;
450
+    return $val;
451 451
 }
452 452
 
453 453
 
@@ -477,81 +477,81 @@  discard block
 block discarded – undo
477 477
  *     texte qui a reçu les filtres
478 478
  **/
479 479
 function image_filtrer($args) {
480
-	$filtre = array_shift($args); # enlever $filtre
481
-	$texte = array_shift($args);
482
-	if ($texte === null || !strlen((string) $texte)) {
483
-		return '';
484
-	}
485
-	find_in_path('filtres_images_mini.php', 'inc/', true);
486
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
487
-	// Cas du nom de fichier local
488
-	$is_file = trim((string) $texte);
489
-	if (
490
-		str_contains(substr($is_file, strlen(_DIR_RACINE)), '..')
491
-		|| strpbrk($is_file, "<>\n\r\t") !== false
492
-		|| str_starts_with($is_file, '/')
493
-	) {
494
-		$is_file = false;
495
-	}
496
-	if ($is_file) {
497
-		$is_local_file = function ($path) {
498
-			if (str_contains($path, '?')) {
499
-				$path = supprimer_timestamp($path);
500
-				// remove ?24px added by find_in_theme on .svg files
501
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
502
-			}
503
-			return file_exists($path);
504
-		};
505
-		if ($is_local_file($is_file) || tester_url_absolue($is_file)) {
506
-			$res = $filtre("<img src='$is_file' />", ...$args);
507
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
508
-			return $res;
509
-		}
510
-	}
511
-
512
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
513
-	if (
514
-		preg_match_all(
515
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
516
-			(string) $texte,
517
-			$tags,
518
-			PREG_SET_ORDER
519
-		)
520
-	) {
521
-		foreach ($tags as $tag) {
522
-			$class = extraire_attribut($tag[3], 'class');
523
-			if (
524
-				(!$class || !str_contains($class, 'filtre_inactif'))
525
-				&& ($reduit = $filtre($tag[3], ...$args))
526
-			) {
527
-				// En cas de span spip_documents, modifier le style=...width:
528
-				if ($tag[1]) {
529
-					$w = extraire_attribut($reduit, 'width');
530
-					if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
531
-						$w = $regs[1];
532
-					}
533
-					if ($w && ($style = extraire_attribut($tag[1], 'style'))) {
534
-						$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
535
-						$replace = inserer_attribut($tag[1], 'style', $style);
536
-						$texte = str_replace($tag[1], $replace, (string) $texte);
537
-					}
538
-				}
539
-				// traiter aussi un eventuel mouseover
540
-				if (
541
-					($mouseover = extraire_attribut($reduit, 'onmouseover'))
542
-					&& preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)
543
-				) {
544
-					$srcover = $match[1];
545
-					$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
546
-					$srcover_filter = extraire_attribut($srcover_filter, 'src');
547
-					$reduit = str_replace($srcover, $srcover_filter, (string) $reduit);
548
-				}
549
-				$texte = str_replace($tag[3], $reduit, (string) $texte);
550
-			}
551
-		}
552
-	}
553
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
554
-	return $texte;
480
+    $filtre = array_shift($args); # enlever $filtre
481
+    $texte = array_shift($args);
482
+    if ($texte === null || !strlen((string) $texte)) {
483
+        return '';
484
+    }
485
+    find_in_path('filtres_images_mini.php', 'inc/', true);
486
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
487
+    // Cas du nom de fichier local
488
+    $is_file = trim((string) $texte);
489
+    if (
490
+        str_contains(substr($is_file, strlen(_DIR_RACINE)), '..')
491
+        || strpbrk($is_file, "<>\n\r\t") !== false
492
+        || str_starts_with($is_file, '/')
493
+    ) {
494
+        $is_file = false;
495
+    }
496
+    if ($is_file) {
497
+        $is_local_file = function ($path) {
498
+            if (str_contains($path, '?')) {
499
+                $path = supprimer_timestamp($path);
500
+                // remove ?24px added by find_in_theme on .svg files
501
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
502
+            }
503
+            return file_exists($path);
504
+        };
505
+        if ($is_local_file($is_file) || tester_url_absolue($is_file)) {
506
+            $res = $filtre("<img src='$is_file' />", ...$args);
507
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
508
+            return $res;
509
+        }
510
+    }
511
+
512
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
513
+    if (
514
+        preg_match_all(
515
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
516
+            (string) $texte,
517
+            $tags,
518
+            PREG_SET_ORDER
519
+        )
520
+    ) {
521
+        foreach ($tags as $tag) {
522
+            $class = extraire_attribut($tag[3], 'class');
523
+            if (
524
+                (!$class || !str_contains($class, 'filtre_inactif'))
525
+                && ($reduit = $filtre($tag[3], ...$args))
526
+            ) {
527
+                // En cas de span spip_documents, modifier le style=...width:
528
+                if ($tag[1]) {
529
+                    $w = extraire_attribut($reduit, 'width');
530
+                    if (!$w && preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
531
+                        $w = $regs[1];
532
+                    }
533
+                    if ($w && ($style = extraire_attribut($tag[1], 'style'))) {
534
+                        $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
535
+                        $replace = inserer_attribut($tag[1], 'style', $style);
536
+                        $texte = str_replace($tag[1], $replace, (string) $texte);
537
+                    }
538
+                }
539
+                // traiter aussi un eventuel mouseover
540
+                if (
541
+                    ($mouseover = extraire_attribut($reduit, 'onmouseover'))
542
+                    && preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)
543
+                ) {
544
+                    $srcover = $match[1];
545
+                    $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
546
+                    $srcover_filter = extraire_attribut($srcover_filter, 'src');
547
+                    $reduit = str_replace($srcover, $srcover_filter, (string) $reduit);
548
+                }
549
+                $texte = str_replace($tag[3], $reduit, (string) $texte);
550
+            }
551
+        }
552
+    }
553
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
554
+    return $texte;
555 555
 }
556 556
 
557 557
 /**
@@ -568,94 +568,94 @@  discard block
 block discarded – undo
568 568
  **/
569 569
 function infos_image($img, $force_refresh = false) {
570 570
 
571
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
572
-	$srcWidth = 0;
573
-	$srcHeight = 0;
574
-	$srcSize = null;
575
-	$valeurs = null;
576
-
577
-	$src = extraire_attribut($img, 'src');
578
-
579
-	if (!$src) {
580
-		$src = $img;
581
-	} else {
582
-		$srcWidth = extraire_attribut($img, 'width');
583
-		$srcHeight = extraire_attribut($img, 'height');
584
-		if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) {
585
-			$srcWidth = $srcHeight = 0;
586
-		}
587
-	}
588
-
589
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
590
-	// la copie locale a toutes les chances d'etre la ou de resservir
591
-	if (tester_url_absolue($src)) {
592
-		include_spip('inc/distant');
593
-		$fichier = copie_locale($src);
594
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
595
-	}
596
-	if (($p = strpos($src, '?')) !== false) {
597
-		$src = substr($src, 0, $p);
598
-	}
599
-
600
-	$imagesize = false;
601
-	if (isset($largeur_img[$src]) && !$force_refresh) {
602
-		$srcWidth = $largeur_img[$src];
603
-	}
604
-	if (isset($hauteur_img[$src]) && !$force_refresh) {
605
-		$srcHeight = $hauteur_img[$src];
606
-	}
607
-	if (isset($poids_img[$src]) && !$force_refresh) {
608
-		$srcSize = $poids_img[$src];
609
-	}
610
-	if (!$srcWidth || !$srcHeight || is_null($srcSize)) {
611
-		if (
612
-			file_exists($src) && ($imagesize = spip_getimagesize($src))
613
-		) {
614
-			if (!$srcWidth) {
615
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
616
-			}
617
-			if (!$srcHeight) {
618
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
619
-			}
620
-			if (!$srcSize) {
621
-				$poids_img[$src] = filesize($src);
622
-			}
623
-		}
624
-		elseif (str_contains($src, '<svg')) {
625
-			include_spip('inc/svg');
626
-			if ($attrs = svg_lire_attributs($src)) {
627
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
628
-				if (!$srcWidth) {
629
-					$largeur_img[$src] = $srcWidth = $width;
630
-				}
631
-				if (!$srcHeight) {
632
-					$hauteur_img[$src] = $srcHeight = $height;
633
-				}
634
-				if (!$srcSize) {
635
-					$poids_img[$src] = $srcSize = strlen($src);
636
-				}
637
-			}
638
-		}
639
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
640
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
641
-		elseif (
642
-			@file_exists($f = "$src.src")
643
-			&& lire_fichier($f, $valeurs)
644
-			&& ($valeurs = unserialize($valeurs))
645
-		) {
646
-			if (!$srcWidth) {
647
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
648
-			}
649
-			if (!$srcHeight) {
650
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
651
-			}
652
-			if (!$srcSize) {
653
-				$poids_img[$src] = $srcSize = 0;
654
-			}
655
-		}
656
-	}
657
-
658
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
571
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
572
+    $srcWidth = 0;
573
+    $srcHeight = 0;
574
+    $srcSize = null;
575
+    $valeurs = null;
576
+
577
+    $src = extraire_attribut($img, 'src');
578
+
579
+    if (!$src) {
580
+        $src = $img;
581
+    } else {
582
+        $srcWidth = extraire_attribut($img, 'width');
583
+        $srcHeight = extraire_attribut($img, 'height');
584
+        if (!ctype_digit((string) $srcWidth) || !ctype_digit((string) $srcHeight)) {
585
+            $srcWidth = $srcHeight = 0;
586
+        }
587
+    }
588
+
589
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
590
+    // la copie locale a toutes les chances d'etre la ou de resservir
591
+    if (tester_url_absolue($src)) {
592
+        include_spip('inc/distant');
593
+        $fichier = copie_locale($src);
594
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
595
+    }
596
+    if (($p = strpos($src, '?')) !== false) {
597
+        $src = substr($src, 0, $p);
598
+    }
599
+
600
+    $imagesize = false;
601
+    if (isset($largeur_img[$src]) && !$force_refresh) {
602
+        $srcWidth = $largeur_img[$src];
603
+    }
604
+    if (isset($hauteur_img[$src]) && !$force_refresh) {
605
+        $srcHeight = $hauteur_img[$src];
606
+    }
607
+    if (isset($poids_img[$src]) && !$force_refresh) {
608
+        $srcSize = $poids_img[$src];
609
+    }
610
+    if (!$srcWidth || !$srcHeight || is_null($srcSize)) {
611
+        if (
612
+            file_exists($src) && ($imagesize = spip_getimagesize($src))
613
+        ) {
614
+            if (!$srcWidth) {
615
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
616
+            }
617
+            if (!$srcHeight) {
618
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
619
+            }
620
+            if (!$srcSize) {
621
+                $poids_img[$src] = filesize($src);
622
+            }
623
+        }
624
+        elseif (str_contains($src, '<svg')) {
625
+            include_spip('inc/svg');
626
+            if ($attrs = svg_lire_attributs($src)) {
627
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
628
+                if (!$srcWidth) {
629
+                    $largeur_img[$src] = $srcWidth = $width;
630
+                }
631
+                if (!$srcHeight) {
632
+                    $hauteur_img[$src] = $srcHeight = $height;
633
+                }
634
+                if (!$srcSize) {
635
+                    $poids_img[$src] = $srcSize = strlen($src);
636
+                }
637
+            }
638
+        }
639
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
640
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
641
+        elseif (
642
+            @file_exists($f = "$src.src")
643
+            && lire_fichier($f, $valeurs)
644
+            && ($valeurs = unserialize($valeurs))
645
+        ) {
646
+            if (!$srcWidth) {
647
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
648
+            }
649
+            if (!$srcHeight) {
650
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
651
+            }
652
+            if (!$srcSize) {
653
+                $poids_img[$src] = $srcSize = 0;
654
+            }
655
+        }
656
+    }
657
+
658
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
659 659
 }
660 660
 
661 661
 /**
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
  *     poids
672 672
  **/
673 673
 function poids_image($img, $force_refresh = false) {
674
-	$infos = infos_image($img, $force_refresh);
675
-	return $infos['poids'];
674
+    $infos = infos_image($img, $force_refresh);
675
+    return $infos['poids'];
676 676
 }
677 677
 
678 678
 function taille_image($img, $force_refresh = false) {
679
-	$infos = infos_image($img, $force_refresh);
680
-	return [$infos['hauteur'], $infos['largeur']];
679
+    $infos = infos_image($img, $force_refresh);
680
+    return [$infos['hauteur'], $infos['largeur']];
681 681
 }
682 682
 
683 683
 /**
@@ -694,12 +694,12 @@  discard block
 block discarded – undo
694 694
  *     Largeur en pixels, NULL ou 0 si aucune image.
695 695
  **/
696 696
 function largeur($img) {
697
-	if (!$img) {
698
-		return;
699
-	}
700
-	[$h, $l] = taille_image($img);
697
+    if (!$img) {
698
+        return;
699
+    }
700
+    [$h, $l] = taille_image($img);
701 701
 
702
-	return $l;
702
+    return $l;
703 703
 }
704 704
 
705 705
 /**
@@ -716,12 +716,12 @@  discard block
 block discarded – undo
716 716
  *     Hauteur en pixels, NULL ou 0 si aucune image.
717 717
  **/
718 718
 function hauteur($img) {
719
-	if (!$img) {
720
-		return;
721
-	}
722
-	[$h, $l] = taille_image($img);
719
+    if (!$img) {
720
+        return;
721
+    }
722
+    [$h, $l] = taille_image($img);
723 723
 
724
-	return $h;
724
+    return $h;
725 725
 }
726 726
 
727 727
 
@@ -741,11 +741,11 @@  discard block
 block discarded – undo
741 741
  * @return string
742 742
  **/
743 743
 function corriger_entites_html($texte) {
744
-	if (!str_contains($texte, '&amp;')) {
745
-		return $texte;
746
-	}
744
+    if (!str_contains($texte, '&amp;')) {
745
+        return $texte;
746
+    }
747 747
 
748
-	return preg_replace(',&amp;(#\d\d\d+;|amp;),iS', '&\1', $texte);
748
+    return preg_replace(',&amp;(#\d\d\d+;|amp;),iS', '&\1', $texte);
749 749
 }
750 750
 
751 751
 /**
@@ -760,11 +760,11 @@  discard block
 block discarded – undo
760 760
  * @return string
761 761
  **/
762 762
 function corriger_toutes_entites_html($texte) {
763
-	if (!str_contains($texte, '&amp;')) {
764
-		return $texte;
765
-	}
763
+    if (!str_contains($texte, '&amp;')) {
764
+        return $texte;
765
+    }
766 766
 
767
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
767
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
768 768
 }
769 769
 
770 770
 /**
@@ -774,7 +774,7 @@  discard block
 block discarded – undo
774 774
  * @return string
775 775
  **/
776 776
 function proteger_amp($texte) {
777
-	return str_replace('&', '&amp;', $texte);
777
+    return str_replace('&', '&amp;', $texte);
778 778
 }
779 779
 
780 780
 
@@ -805,20 +805,20 @@  discard block
 block discarded – undo
805 805
  * @return mixed|string
806 806
  */
807 807
 function entites_html($texte, $tout = false, $quote = true) {
808
-	if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) {
809
-		return $texte;
810
-	}
811
-	include_spip('inc/texte');
812
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
813
-	$flags |= ENT_HTML401;
814
-	$texte = CollecteurHtmlTag::proteger_balisesHtml($texte);
815
-	$texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte, '', 'proteger_amp');
816
-	$texte = spip_htmlspecialchars($texte, $flags);
817
-	if ($tout) {
818
-		return corriger_toutes_entites_html($texte);
819
-	} else {
820
-		return corriger_entites_html($texte);
821
-	}
808
+    if (!is_string($texte) || !$texte || strpbrk($texte, "&\"'<>") == false) {
809
+        return $texte;
810
+    }
811
+    include_spip('inc/texte');
812
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
813
+    $flags |= ENT_HTML401;
814
+    $texte = CollecteurHtmlTag::proteger_balisesHtml($texte);
815
+    $texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte, '', 'proteger_amp');
816
+    $texte = spip_htmlspecialchars($texte, $flags);
817
+    if ($tout) {
818
+        return corriger_toutes_entites_html($texte);
819
+    } else {
820
+        return corriger_entites_html($texte);
821
+    }
822 822
 }
823 823
 
824 824
 /**
@@ -837,38 +837,38 @@  discard block
 block discarded – undo
837 837
  *     texte converti
838 838
  **/
839 839
 function filtrer_entites(?string $texte): string {
840
-	$texte ??= '';
841
-	if (!str_contains($texte, '&')) {
842
-		return $texte;
843
-	}
844
-	// filtrer
845
-	$texte = html2unicode($texte);
846
-	// remettre le tout dans le charset cible
847
-	$texte = unicode2charset($texte);
848
-	// cas particulier des " et ' qu'il faut filtrer aussi
849
-	// (on le faisait deja avec un &quot;)
850
-	if (str_contains($texte, '&#')) {
851
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
852
-	}
840
+    $texte ??= '';
841
+    if (!str_contains($texte, '&')) {
842
+        return $texte;
843
+    }
844
+    // filtrer
845
+    $texte = html2unicode($texte);
846
+    // remettre le tout dans le charset cible
847
+    $texte = unicode2charset($texte);
848
+    // cas particulier des " et ' qu'il faut filtrer aussi
849
+    // (on le faisait deja avec un &quot;)
850
+    if (str_contains($texte, '&#')) {
851
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
852
+    }
853 853
 
854
-	return $texte;
854
+    return $texte;
855 855
 }
856 856
 
857 857
 
858 858
 if (!function_exists('filtre_filtrer_entites_dist')) {
859
-	/**
860
-	 * Version sécurisée de filtrer_entites
861
-	 *
862
-	 * @uses interdire_scripts()
863
-	 * @uses filtrer_entites()
864
-	 *
865
-	 * @param string $t
866
-	 * @return string
867
-	 */
868
-	function filtre_filtrer_entites_dist($t) {
869
-		include_spip('inc/texte');
870
-		return interdire_scripts(filtrer_entites($t));
871
-	}
859
+    /**
860
+     * Version sécurisée de filtrer_entites
861
+     *
862
+     * @uses interdire_scripts()
863
+     * @uses filtrer_entites()
864
+     *
865
+     * @param string $t
866
+     * @return string
867
+     */
868
+    function filtre_filtrer_entites_dist($t) {
869
+        include_spip('inc/texte');
870
+        return interdire_scripts(filtrer_entites($t));
871
+    }
872 872
 }
873 873
 
874 874
 
@@ -883,18 +883,18 @@  discard block
 block discarded – undo
883 883
  * @return string|array
884 884
  **/
885 885
 function supprimer_caracteres_illegaux($texte) {
886
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
887
-	static $to = null;
886
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
887
+    static $to = null;
888 888
 
889
-	if (is_array($texte)) {
890
-		return array_map('supprimer_caracteres_illegaux', $texte);
891
-	}
889
+    if (is_array($texte)) {
890
+        return array_map('supprimer_caracteres_illegaux', $texte);
891
+    }
892 892
 
893
-	if (!$to) {
894
-		$to = str_repeat('-', strlen((string) $from));
895
-	}
893
+    if (!$to) {
894
+        $to = str_repeat('-', strlen((string) $from));
895
+    }
896 896
 
897
-	return strtr($texte, $from, $to);
897
+    return strtr($texte, $from, $to);
898 898
 }
899 899
 
900 900
 /**
@@ -906,9 +906,9 @@  discard block
 block discarded – undo
906 906
  * @return string|array
907 907
  **/
908 908
 function corriger_caracteres($texte) {
909
-	$texte = corriger_caracteres_windows($texte);
909
+    $texte = corriger_caracteres_windows($texte);
910 910
 
911
-	return supprimer_caracteres_illegaux($texte);
911
+    return supprimer_caracteres_illegaux($texte);
912 912
 }
913 913
 
914 914
 /**
@@ -925,44 +925,44 @@  discard block
 block discarded – undo
925 925
  *     texte encodé pour XML
926 926
  */
927 927
 function texte_backend(?string $texte): string {
928
-	if ($texte === null || $texte === '') {
929
-		return '';
930
-	}
928
+    if ($texte === null || $texte === '') {
929
+        return '';
930
+    }
931 931
 
932
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
932
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
933 933
 
934
-	// si on a des liens ou des images, les passer en absolu
935
-	$texte = liens_absolus($texte);
934
+    // si on a des liens ou des images, les passer en absolu
935
+    $texte = liens_absolus($texte);
936 936
 
937
-	// echapper les tags &gt; &lt;
938
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
937
+    // echapper les tags &gt; &lt;
938
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
939 939
 
940
-	// importer les &eacute;
941
-	$texte = filtrer_entites($texte);
940
+    // importer les &eacute;
941
+    $texte = filtrer_entites($texte);
942 942
 
943
-	// " -> &quot; et tout ce genre de choses
944
-	$u = $GLOBALS['meta']['pcre_u'];
945
-	$texte = str_replace('&nbsp;', ' ', $texte);
946
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
947
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
948
-	$texte = entites_html($texte, false, false);
949
-	// mais bien echapper les double quotes !
950
-	$texte = str_replace('"', '&#034;', (string) $texte);
943
+    // " -> &quot; et tout ce genre de choses
944
+    $u = $GLOBALS['meta']['pcre_u'];
945
+    $texte = str_replace('&nbsp;', ' ', $texte);
946
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
947
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
948
+    $texte = entites_html($texte, false, false);
949
+    // mais bien echapper les double quotes !
950
+    $texte = str_replace('"', '&#034;', (string) $texte);
951 951
 
952
-	// verifier le charset
953
-	$texte = charset2unicode($texte);
952
+    // verifier le charset
953
+    $texte = charset2unicode($texte);
954 954
 
955
-	// Caracteres problematiques en iso-latin 1
956
-	if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') {
957
-		$texte = str_replace(chr(156), '&#156;', $texte);
958
-		$texte = str_replace(chr(140), '&#140;', $texte);
959
-		$texte = str_replace(chr(159), '&#159;', $texte);
960
-	}
955
+    // Caracteres problematiques en iso-latin 1
956
+    if (isset($GLOBALS['meta']['charset']) && $GLOBALS['meta']['charset'] == 'iso-8859-1') {
957
+        $texte = str_replace(chr(156), '&#156;', $texte);
958
+        $texte = str_replace(chr(140), '&#140;', $texte);
959
+        $texte = str_replace(chr(159), '&#159;', $texte);
960
+    }
961 961
 
962
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
963
-	// et le caractere apostrophe alourdit les squelettes avec PHP
964
-	// ==> on les remplace par l'entite HTML
965
-	return str_replace($apostrophe, "'", $texte);
962
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
963
+    // et le caractere apostrophe alourdit les squelettes avec PHP
964
+    // ==> on les remplace par l'entite HTML
965
+    return str_replace($apostrophe, "'", $texte);
966 966
 }
967 967
 
968 968
 /**
@@ -979,7 +979,7 @@  discard block
 block discarded – undo
979 979
  *     texte encodé et quote pour XML
980 980
  */
981 981
 function texte_backendq(?string $texte): string {
982
-	return addslashes(texte_backend($texte));
982
+    return addslashes(texte_backend($texte));
983 983
 }
984 984
 
985 985
 
@@ -1001,14 +1001,14 @@  discard block
 block discarded – undo
1001 1001
  *     Texte sans son numéro éventuel
1002 1002
  **/
1003 1003
 function supprimer_numero(?string $texte): string {
1004
-	if ($texte === null || $texte === '') {
1005
-		return '';
1006
-	}
1007
-	return preg_replace(
1008
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1009
-		'',
1010
-		$texte
1011
-	);
1004
+    if ($texte === null || $texte === '') {
1005
+        return '';
1006
+    }
1007
+    return preg_replace(
1008
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1009
+        '',
1010
+        $texte
1011
+    );
1012 1012
 }
1013 1013
 
1014 1014
 /**
@@ -1031,19 +1031,19 @@  discard block
 block discarded – undo
1031 1031
  *     Numéro de titre, sinon chaîne vide
1032 1032
  **/
1033 1033
 function recuperer_numero(?string $texte): string {
1034
-	if ($texte === null || $texte === '') {
1035
-		return '';
1036
-	}
1037
-	if (preg_match(
1038
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1039
-			$texte,
1040
-			$regs
1041
-		)
1042
-	) {
1043
-		return (string) $regs[1];
1044
-	}
1034
+    if ($texte === null || $texte === '') {
1035
+        return '';
1036
+    }
1037
+    if (preg_match(
1038
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1039
+            $texte,
1040
+            $regs
1041
+        )
1042
+    ) {
1043
+        return (string) $regs[1];
1044
+    }
1045 1045
 
1046
-	return '';
1046
+    return '';
1047 1047
 }
1048 1048
 
1049 1049
 /**
@@ -1070,16 +1070,16 @@  discard block
 block discarded – undo
1070 1070
  *     texte ou tableau de textes converti
1071 1071
  **/
1072 1072
 function supprimer_tags($texte, $rempl = '') {
1073
-	if ($texte === null || $texte === '') {
1074
-		return '';
1075
-	}
1076
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1077
-	// ne pas oublier un < final non ferme car coupe
1078
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1079
-	// mais qui peut aussi etre un simple signe plus petit que
1080
-	$texte = str_replace('<', '&lt;', $texte);
1073
+    if ($texte === null || $texte === '') {
1074
+        return '';
1075
+    }
1076
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1077
+    // ne pas oublier un < final non ferme car coupe
1078
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1079
+    // mais qui peut aussi etre un simple signe plus petit que
1080
+    $texte = str_replace('<', '&lt;', $texte);
1081 1081
 
1082
-	return $texte;
1082
+    return $texte;
1083 1083
 }
1084 1084
 
1085 1085
 /**
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
  *     texte converti
1103 1103
  **/
1104 1104
 function echapper_tags($texte, $rempl = '') {
1105
-	return preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1105
+    return preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1106 1106
 }
1107 1107
 
1108 1108
 /**
@@ -1123,21 +1123,21 @@  discard block
 block discarded – undo
1123 1123
  *     texte converti
1124 1124
  **/
1125 1125
 function textebrut($texte) {
1126
-	if ($texte === null || $texte === '') {
1127
-		return '';
1128
-	}
1129
-	$u = $GLOBALS['meta']['pcre_u'];
1130
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1131
-	$texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte);
1132
-	$texte = preg_replace("/^\n+/", '', $texte);
1133
-	$texte = preg_replace("/\n+$/", '', $texte);
1134
-	$texte = preg_replace("/\n +/", "\n", $texte);
1135
-	$texte = supprimer_tags($texte);
1136
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1137
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1138
-	$texte = str_replace('&#8217;', "'", $texte);
1126
+    if ($texte === null || $texte === '') {
1127
+        return '';
1128
+    }
1129
+    $u = $GLOBALS['meta']['pcre_u'];
1130
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1131
+    $texte = preg_replace('/<(p|br)( [^>]*)?>/iS', "\n\n", $texte);
1132
+    $texte = preg_replace("/^\n+/", '', $texte);
1133
+    $texte = preg_replace("/\n+$/", '', $texte);
1134
+    $texte = preg_replace("/\n +/", "\n", $texte);
1135
+    $texte = supprimer_tags($texte);
1136
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1137
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1138
+    $texte = str_replace('&#8217;', "'", $texte);
1139 1139
 
1140
-	return $texte;
1140
+    return $texte;
1141 1141
 }
1142 1142
 
1143 1143
 
@@ -1153,26 +1153,26 @@  discard block
 block discarded – undo
1153 1153
  *     texte avec liens ouvrants
1154 1154
  **/
1155 1155
 function liens_ouvrants($texte) {
1156
-	if ($texte === null || $texte === '') {
1157
-		return '';
1158
-	}
1159
-	if (
1160
-		preg_match_all(
1161
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1162
-			$texte,
1163
-			$liens,
1164
-			PREG_PATTERN_ORDER
1165
-		)
1166
-	) {
1167
-		foreach ($liens[0] as $a) {
1168
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1169
-			$ablank = inserer_attribut($a, 'rel', $rel);
1170
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1171
-			$texte = str_replace($a, $ablank, $texte);
1172
-		}
1173
-	}
1174
-
1175
-	return $texte;
1156
+    if ($texte === null || $texte === '') {
1157
+        return '';
1158
+    }
1159
+    if (
1160
+        preg_match_all(
1161
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1162
+            $texte,
1163
+            $liens,
1164
+            PREG_PATTERN_ORDER
1165
+        )
1166
+    ) {
1167
+        foreach ($liens[0] as $a) {
1168
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1169
+            $ablank = inserer_attribut($a, 'rel', $rel);
1170
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1171
+            $texte = str_replace($a, $ablank, $texte);
1172
+        }
1173
+    }
1174
+
1175
+    return $texte;
1176 1176
 }
1177 1177
 
1178 1178
 /**
@@ -1182,25 +1182,25 @@  discard block
 block discarded – undo
1182 1182
  * @return string
1183 1183
  */
1184 1184
 function liens_nofollow($texte) {
1185
-	if ($texte === null || $texte === '') {
1186
-		return '';
1187
-	}
1188
-	if (stripos($texte, '<a') === false) {
1189
-		return $texte;
1190
-	}
1185
+    if ($texte === null || $texte === '') {
1186
+        return '';
1187
+    }
1188
+    if (stripos($texte, '<a') === false) {
1189
+        return $texte;
1190
+    }
1191 1191
 
1192
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1193
-		foreach ($regs[0] as $a) {
1194
-			$rel = extraire_attribut($a, 'rel') ?? '';
1195
-			if (!str_contains($rel, 'nofollow')) {
1196
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1197
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1198
-				$texte = str_replace($a, $anofollow, $texte);
1199
-			}
1200
-		}
1201
-	}
1192
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1193
+        foreach ($regs[0] as $a) {
1194
+            $rel = extraire_attribut($a, 'rel') ?? '';
1195
+            if (!str_contains($rel, 'nofollow')) {
1196
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1197
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1198
+                $texte = str_replace($a, $anofollow, $texte);
1199
+            }
1200
+        }
1201
+    }
1202 1202
 
1203
-	return $texte;
1203
+    return $texte;
1204 1204
 }
1205 1205
 
1206 1206
 /**
@@ -1219,14 +1219,14 @@  discard block
 block discarded – undo
1219 1219
  *     texte sans paraghaphes
1220 1220
  **/
1221 1221
 function PtoBR($texte) {
1222
-	if ($texte === null || $texte === '') {
1223
-		return '';
1224
-	}
1225
-	$u = $GLOBALS['meta']['pcre_u'];
1226
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1227
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1222
+    if ($texte === null || $texte === '') {
1223
+        return '';
1224
+    }
1225
+    $u = $GLOBALS['meta']['pcre_u'];
1226
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1227
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1228 1228
 
1229
-	return preg_replace('@^\s*<br />@S' . $u, '', $texte);
1229
+    return preg_replace('@^\s*<br />@S' . $u, '', $texte);
1230 1230
 }
1231 1231
 
1232 1232
 /**
@@ -1245,30 +1245,30 @@  discard block
 block discarded – undo
1245 1245
  * @return string texte en majuscule
1246 1246
  */
1247 1247
 function majuscules($texte) {
1248
-	if ($texte === null || $texte === '') {
1249
-		return '';
1250
-	}
1248
+    if ($texte === null || $texte === '') {
1249
+        return '';
1250
+    }
1251 1251
 
1252
-	// Cas du turc
1253
-	if ($GLOBALS['spip_lang'] == 'tr') {
1254
-		# remplacer hors des tags et des entites
1255
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1256
-			foreach ($regs as $n => $match) {
1257
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1258
-			}
1259
-		}
1252
+    // Cas du turc
1253
+    if ($GLOBALS['spip_lang'] == 'tr') {
1254
+        # remplacer hors des tags et des entites
1255
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1256
+            foreach ($regs as $n => $match) {
1257
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1258
+            }
1259
+        }
1260 1260
 
1261
-		$texte = str_replace('i', '&#304;', $texte);
1261
+        $texte = str_replace('i', '&#304;', $texte);
1262 1262
 
1263
-		if ($regs) {
1264
-			foreach ($regs as $n => $match) {
1265
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1266
-			}
1267
-		}
1268
-	}
1263
+        if ($regs) {
1264
+            foreach ($regs as $n => $match) {
1265
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1266
+            }
1267
+        }
1268
+    }
1269 1269
 
1270
-	// Cas general
1271
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1270
+    // Cas general
1271
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1272 1272
 }
1273 1273
 
1274 1274
 /**
@@ -1290,38 +1290,38 @@  discard block
 block discarded – undo
1290 1290
  */
1291 1291
 function taille_en_octets($octets, $systeme = 'BI') {
1292 1292
 
1293
-	// Texte à afficher pour la taille
1294
-	$affichage = '';
1293
+    // Texte à afficher pour la taille
1294
+    $affichage = '';
1295 1295
 
1296
-	static $unites = ['octets', 'ko', 'mo', 'go'];
1297
-	static $precisions = [0, 1, 1, 2];
1296
+    static $unites = ['octets', 'ko', 'mo', 'go'];
1297
+    static $precisions = [0, 1, 1, 2];
1298 1298
 
1299
-	if ($octets >= 1) {
1300
-		// Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1301
-		$systeme = strtolower($systeme);
1302
-		if ($systeme === 'bi') {
1303
-			$kilo = 1024;
1304
-			$suffixe_item = "_$systeme";
1305
-		} elseif ($systeme === 'si') {
1306
-			$kilo = 1000;
1307
-			$suffixe_item = '';
1308
-		} else {
1309
-			return $affichage;
1310
-		}
1299
+    if ($octets >= 1) {
1300
+        // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1301
+        $systeme = strtolower($systeme);
1302
+        if ($systeme === 'bi') {
1303
+            $kilo = 1024;
1304
+            $suffixe_item = "_$systeme";
1305
+        } elseif ($systeme === 'si') {
1306
+            $kilo = 1000;
1307
+            $suffixe_item = '';
1308
+        } else {
1309
+            return $affichage;
1310
+        }
1311 1311
 
1312
-		// Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1313
-		$puissance = floor(log($octets, $kilo));
1312
+        // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1313
+        $puissance = floor(log($octets, $kilo));
1314 1314
 
1315
-		// Calcul de la taille et choix de l'unité
1316
-		$affichage = _T(
1317
-			'spip:taille_' . $unites[$puissance] . $suffixe_item,
1318
-			[
1319
-				'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance])
1320
-			]
1321
-		);
1322
-	}
1315
+        // Calcul de la taille et choix de l'unité
1316
+        $affichage = _T(
1317
+            'spip:taille_' . $unites[$puissance] . $suffixe_item,
1318
+            [
1319
+                'taille' => round($octets / $kilo ** $puissance, $precisions[$puissance])
1320
+            ]
1321
+        );
1322
+    }
1323 1323
 
1324
-	return $affichage;
1324
+    return $affichage;
1325 1325
 }
1326 1326
 
1327 1327
 
@@ -1343,21 +1343,21 @@  discard block
 block discarded – undo
1343 1343
  *     texte prêt pour être utilisé en attribut HTML
1344 1344
  **/
1345 1345
 function attribut_html(?string $texte, $textebrut = true): string {
1346
-	if ($texte === null || $texte === '') {
1347
-		return '';
1348
-	}
1349
-	$u = $GLOBALS['meta']['pcre_u'];
1350
-	if ($textebrut) {
1351
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1352
-	}
1353
-	$texte = texte_backend($texte);
1354
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1346
+    if ($texte === null || $texte === '') {
1347
+        return '';
1348
+    }
1349
+    $u = $GLOBALS['meta']['pcre_u'];
1350
+    if ($textebrut) {
1351
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1352
+    }
1353
+    $texte = texte_backend($texte);
1354
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1355 1355
 
1356
-	return preg_replace(
1357
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1358
-		['&', '&#38;'],
1359
-		$texte
1360
-	);
1356
+    return preg_replace(
1357
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1358
+        ['&', '&#38;'],
1359
+        $texte
1360
+    );
1361 1361
 }
1362 1362
 
1363 1363
 
@@ -1377,15 +1377,15 @@  discard block
 block discarded – undo
1377 1377
  *     URL ou chaîne vide
1378 1378
  **/
1379 1379
 function vider_url(?string $url, $entites = true): string {
1380
-	if ($url === null || $url === '') {
1381
-		return '';
1382
-	}
1383
-	# un message pour abs_url
1384
-	$GLOBALS['mode_abs_url'] = 'url';
1385
-	$url = trim($url);
1386
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1380
+    if ($url === null || $url === '') {
1381
+        return '';
1382
+    }
1383
+    # un message pour abs_url
1384
+    $GLOBALS['mode_abs_url'] = 'url';
1385
+    $url = trim($url);
1386
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1387 1387
 
1388
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1388
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1389 1389
 }
1390 1390
 
1391 1391
 
@@ -1400,10 +1400,10 @@  discard block
 block discarded – undo
1400 1400
  * @return string Adresse email maquillée
1401 1401
  **/
1402 1402
 function antispam($texte) {
1403
-	include_spip('inc/acces');
1404
-	$masque = creer_pass_aleatoire(3);
1403
+    include_spip('inc/acces');
1404
+    $masque = creer_pass_aleatoire(3);
1405 1405
 
1406
-	return preg_replace('/@/', " $masque ", $texte);
1406
+    return preg_replace('/@/', " $masque ", $texte);
1407 1407
 }
1408 1408
 
1409 1409
 /**
@@ -1435,8 +1435,8 @@  discard block
 block discarded – undo
1435 1435
  *     True si on a le droit d'accès, false sinon.
1436 1436
  **/
1437 1437
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1438
-	include_spip('inc/acces');
1439
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1438
+    include_spip('inc/acces');
1439
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1440 1440
 }
1441 1441
 
1442 1442
 /**
@@ -1460,13 +1460,13 @@  discard block
 block discarded – undo
1460 1460
  *     Retourne $texte, sinon $sinon.
1461 1461
  **/
1462 1462
 function sinon(mixed $texte, mixed $sinon = '') {
1463
-	if ($texte) {
1464
-		return $texte;
1465
-	} elseif (is_scalar($texte) && strlen($texte)) {
1466
-		return $texte;
1467
-	}
1463
+    if ($texte) {
1464
+        return $texte;
1465
+    } elseif (is_scalar($texte) && strlen($texte)) {
1466
+        return $texte;
1467
+    }
1468 1468
 
1469
-	return $sinon;
1469
+    return $sinon;
1470 1470
 }
1471 1471
 
1472 1472
 /**
@@ -1490,7 +1490,7 @@  discard block
 block discarded – undo
1490 1490
  * @return mixed
1491 1491
  **/
1492 1492
 function choixsivide(mixed $a, mixed $vide, mixed $pasvide) {
1493
-	return $a ? $pasvide : $vide;
1493
+    return $a ? $pasvide : $vide;
1494 1494
 }
1495 1495
 
1496 1496
 /**
@@ -1514,7 +1514,7 @@  discard block
 block discarded – undo
1514 1514
  * @return mixed
1515 1515
  **/
1516 1516
 function choixsiegal(mixed $a1, mixed $a2, mixed $v, mixed $f) {
1517
-	return ($a1 == $a2) ? $v : $f;
1517
+    return ($a1 == $a2) ? $v : $f;
1518 1518
 }
1519 1519
 
1520 1520
 //
@@ -1533,15 +1533,15 @@  discard block
 block discarded – undo
1533 1533
  * @return string
1534 1534
  **/
1535 1535
 function filtrer_ical($texte) {
1536
-	if ($texte === null || $texte === '') {
1537
-		return '';
1538
-	}
1539
-	#include_spip('inc/charsets');
1540
-	$texte = html2unicode($texte);
1541
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1542
-	$texte = preg_replace("/\n/", ' ', $texte);
1536
+    if ($texte === null || $texte === '') {
1537
+        return '';
1538
+    }
1539
+    #include_spip('inc/charsets');
1540
+    $texte = html2unicode($texte);
1541
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1542
+    $texte = preg_replace("/\n/", ' ', $texte);
1543 1543
 
1544
-	return preg_replace('/,/', '\,', $texte);
1544
+    return preg_replace('/,/', '\,', $texte);
1545 1545
 }
1546 1546
 
1547 1547
 
@@ -1566,56 +1566,56 @@  discard block
 block discarded – undo
1566 1566
  * @return string
1567 1567
  **/
1568 1568
 function post_autobr($texte, $delim = "\n_ ") {
1569
-	if (!function_exists('echappe_html')) {
1570
-		include_spip('inc/texte_mini');
1571
-	}
1572
-	$texte = str_replace("\r\n", "\r", $texte);
1573
-	$texte = str_replace("\r", "\n", $texte);
1574
-
1575
-	if (preg_match(",\n+$,", $texte, $fin)) {
1576
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1577
-	} else {
1578
-		$fin = '';
1579
-	}
1580
-
1581
-	$texte = CollecteurHtmlTag::proteger_balisesHtml($texte);
1582
-
1583
-	// echapper les modeles
1584
-	$collecteurModeles = null;
1585
-	if (str_contains($texte, '<')) {
1586
-		$collecteurModeles = new CollecteurModeles();
1587
-		$texte = $collecteurModeles->echapper($texte);
1588
-	}
1589
-
1590
-	$debut = '';
1591
-	$suite = $texte;
1592
-	while ($t = strpos((string) ('-' . $suite), "\n", 1)) {
1593
-		$debut .= substr($suite, 0, $t - 1);
1594
-		$suite = substr($suite, $t);
1595
-		$car = substr($suite, 0, 1);
1596
-		if (
1597
-			$car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}'
1598
-			&& !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1599
-			&& !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1600
-		) {
1601
-			$debut .= $delim;
1602
-		} else {
1603
-			$debut .= "\n";
1604
-		}
1605
-		if (preg_match(",^\n+,", $suite, $regs)) {
1606
-			$debut .= $regs[0];
1607
-			$suite = substr($suite, strlen($regs[0]));
1608
-		}
1609
-	}
1610
-	$texte = $debut . $suite;
1611
-
1612
-	if ($collecteurModeles) {
1613
-		$texte = $collecteurModeles->retablir($texte);
1614
-	}
1615
-
1616
-	$texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte);
1617
-
1618
-	return $texte . $fin;
1569
+    if (!function_exists('echappe_html')) {
1570
+        include_spip('inc/texte_mini');
1571
+    }
1572
+    $texte = str_replace("\r\n", "\r", $texte);
1573
+    $texte = str_replace("\r", "\n", $texte);
1574
+
1575
+    if (preg_match(",\n+$,", $texte, $fin)) {
1576
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1577
+    } else {
1578
+        $fin = '';
1579
+    }
1580
+
1581
+    $texte = CollecteurHtmlTag::proteger_balisesHtml($texte);
1582
+
1583
+    // echapper les modeles
1584
+    $collecteurModeles = null;
1585
+    if (str_contains($texte, '<')) {
1586
+        $collecteurModeles = new CollecteurModeles();
1587
+        $texte = $collecteurModeles->echapper($texte);
1588
+    }
1589
+
1590
+    $debut = '';
1591
+    $suite = $texte;
1592
+    while ($t = strpos((string) ('-' . $suite), "\n", 1)) {
1593
+        $debut .= substr($suite, 0, $t - 1);
1594
+        $suite = substr($suite, $t);
1595
+        $car = substr($suite, 0, 1);
1596
+        if (
1597
+            $car != '-' && $car != '_' && $car != "\n" && $car != '|' && $car != '}'
1598
+            && !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1599
+            && !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1600
+        ) {
1601
+            $debut .= $delim;
1602
+        } else {
1603
+            $debut .= "\n";
1604
+        }
1605
+        if (preg_match(",^\n+,", $suite, $regs)) {
1606
+            $debut .= $regs[0];
1607
+            $suite = substr($suite, strlen($regs[0]));
1608
+        }
1609
+    }
1610
+    $texte = $debut . $suite;
1611
+
1612
+    if ($collecteurModeles) {
1613
+        $texte = $collecteurModeles->retablir($texte);
1614
+    }
1615
+
1616
+    $texte = CollecteurHtmlTag::retablir_depuisHtmlBase64($texte);
1617
+
1618
+    return $texte . $fin;
1619 1619
 }
1620 1620
 
1621 1621
 
@@ -1648,25 +1648,25 @@  discard block
 block discarded – undo
1648 1648
  **/
1649 1649
 function extraire_idiome($letexte, $lang = null, $options = []) {
1650 1650
 
1651
-	if ($letexte && str_contains($letexte, '<:')) {
1652
-		if (!$lang) {
1653
-			$lang = $GLOBALS['spip_lang'];
1654
-		}
1655
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1656
-		if (is_bool($options)) {
1657
-			trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']');
1658
-			$options = ['echappe_span' => $options];
1659
-		}
1660
-		if (!isset($options['echappe_span'])) {
1661
-			$options = array_merge($options, ['echappe_span' => false]);
1662
-		}
1663
-		$options['lang'] = $lang;
1651
+    if ($letexte && str_contains($letexte, '<:')) {
1652
+        if (!$lang) {
1653
+            $lang = $GLOBALS['spip_lang'];
1654
+        }
1655
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1656
+        if (is_bool($options)) {
1657
+            trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']');
1658
+            $options = ['echappe_span' => $options];
1659
+        }
1660
+        if (!isset($options['echappe_span'])) {
1661
+            $options = array_merge($options, ['echappe_span' => false]);
1662
+        }
1663
+        $options['lang'] = $lang;
1664 1664
 
1665
-		$collecteurIdiomes = new CollecteurIdiomes();
1665
+        $collecteurIdiomes = new CollecteurIdiomes();
1666 1666
 
1667
-		$letexte = $collecteurIdiomes->traiter($letexte, $options);
1668
-	}
1669
-	return $letexte;
1667
+        $letexte = $collecteurIdiomes->traiter($letexte, $options);
1668
+    }
1669
+    return $letexte;
1670 1670
 }
1671 1671
 
1672 1672
 /**
@@ -1704,30 +1704,30 @@  discard block
 block discarded – undo
1704 1704
  **/
1705 1705
 function extraire_multi($letexte, $lang = null, $options = []) {
1706 1706
 
1707
-	if ($letexte && stripos($letexte, '<multi') !== false) {
1708
-		if (!$lang) {
1709
-			$lang = $GLOBALS['spip_lang'];
1710
-		}
1707
+    if ($letexte && stripos($letexte, '<multi') !== false) {
1708
+        if (!$lang) {
1709
+            $lang = $GLOBALS['spip_lang'];
1710
+        }
1711 1711
 
1712
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1713
-		if (is_bool($options)) {
1714
-			trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']');
1715
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1716
-		}
1717
-		if (!isset($options['echappe_span'])) {
1718
-			$options = array_merge($options, ['echappe_span' => false]);
1719
-		}
1720
-		if (!isset($options['lang_defaut'])) {
1721
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1722
-		}
1723
-		$options['lang'] = $lang;
1712
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1713
+        if (is_bool($options)) {
1714
+            trigger_deprecation('spip', '5.0', 'Using boolean $options parameter in "%s()" function is deprecated. Use %s array parameter instead.', __FUNCTION__, '[\'echappe_span\' => ' . var_export($options, true) . ']');
1715
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1716
+        }
1717
+        if (!isset($options['echappe_span'])) {
1718
+            $options = array_merge($options, ['echappe_span' => false]);
1719
+        }
1720
+        if (!isset($options['lang_defaut'])) {
1721
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1722
+        }
1723
+        $options['lang'] = $lang;
1724 1724
 
1725
-		$collecteurMultis = new CollecteurMultis();
1725
+        $collecteurMultis = new CollecteurMultis();
1726 1726
 
1727
-		$letexte = $collecteurMultis->traiter($letexte, $options);
1728
-	}
1727
+        $letexte = $collecteurMultis->traiter($letexte, $options);
1728
+    }
1729 1729
 
1730
-	return $letexte;
1730
+    return $letexte;
1731 1731
 }
1732 1732
 
1733 1733
 /**
@@ -1737,7 +1737,7 @@  discard block
 block discarded – undo
1737 1737
  * @return string L'initiale en majuscule
1738 1738
  */
1739 1739
 function filtre_initiale($nom) {
1740
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1740
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1741 1741
 }
1742 1742
 
1743 1743
 
@@ -1782,33 +1782,33 @@  discard block
 block discarded – undo
1782 1782
  *      - null (interne) : si on empile
1783 1783
  **/
1784 1784
 function unique($donnee, $famille = '', $cpt = false) {
1785
-	static $mem = [];
1786
-	// permettre de vider la pile et de la restaurer
1787
-	// pour le calcul de introduction...
1788
-	if ($famille == '_spip_raz_') {
1789
-		$tmp = $mem;
1790
-		$mem = [];
1791
-
1792
-		return $tmp;
1793
-	} elseif ($famille == '_spip_set_') {
1794
-		$mem = $donnee;
1795
-
1796
-		return;
1797
-	}
1798
-	// eviter une notice
1799
-	if (!isset($mem[$famille])) {
1800
-		$mem[$famille] = [];
1801
-	}
1802
-	if ($cpt) {
1803
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1804
-	}
1805
-	// eviter une notice
1806
-	if (!isset($mem[$famille][$donnee])) {
1807
-		$mem[$famille][$donnee] = 0;
1808
-	}
1809
-	if (!($mem[$famille][$donnee]++)) {
1810
-		return $donnee;
1811
-	}
1785
+    static $mem = [];
1786
+    // permettre de vider la pile et de la restaurer
1787
+    // pour le calcul de introduction...
1788
+    if ($famille == '_spip_raz_') {
1789
+        $tmp = $mem;
1790
+        $mem = [];
1791
+
1792
+        return $tmp;
1793
+    } elseif ($famille == '_spip_set_') {
1794
+        $mem = $donnee;
1795
+
1796
+        return;
1797
+    }
1798
+    // eviter une notice
1799
+    if (!isset($mem[$famille])) {
1800
+        $mem[$famille] = [];
1801
+    }
1802
+    if ($cpt) {
1803
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1804
+    }
1805
+    // eviter une notice
1806
+    if (!isset($mem[$famille][$donnee])) {
1807
+        $mem[$famille][$donnee] = 0;
1808
+    }
1809
+    if (!($mem[$famille][$donnee]++)) {
1810
+        return $donnee;
1811
+    }
1812 1812
 }
1813 1813
 
1814 1814
 
@@ -1838,20 +1838,20 @@  discard block
 block discarded – undo
1838 1838
  *     Une des valeurs en fonction du compteur.
1839 1839
  **/
1840 1840
 function alterner($i, ...$args) {
1841
-	// recuperer les arguments (attention fonctions un peu space)
1842
-	$num = count($args);
1841
+    // recuperer les arguments (attention fonctions un peu space)
1842
+    $num = count($args);
1843 1843
 
1844
-	if ($num === 1 && is_array($args[0])) {
1845
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1846
-		$args = array_values($args[0]);
1847
-		$num = count($args);
1848
-	}
1844
+    if ($num === 1 && is_array($args[0])) {
1845
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1846
+        $args = array_values($args[0]);
1847
+        $num = count($args);
1848
+    }
1849 1849
 
1850
-	// un index compris entre 0 et num exclus
1851
-	$i = (((int) $i - 1) % $num); // dans ]-$num;$num[
1852
-	$i = ($i + $num) % $num; // dans [0;$num[
1853
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1854
-	return $args[$i];
1850
+    // un index compris entre 0 et num exclus
1851
+    $i = (((int) $i - 1) % $num); // dans ]-$num;$num[
1852
+    $i = ($i + $num) % $num; // dans [0;$num[
1853
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1854
+    return $args[$i];
1855 1855
 }
1856 1856
 
1857 1857
 
@@ -1877,52 +1877,52 @@  discard block
 block discarded – undo
1877 1877
  *     - null lorsque l’attribut n’existe pas.
1878 1878
  **/
1879 1879
 function extraire_attribut($balise, $attribut, $complet = false) {
1880
-	if (is_array($balise)) {
1881
-		array_walk(
1882
-			$balise,
1883
-			function (&$a, $key, $t) {
1884
-				$a = extraire_attribut($a, $t);
1885
-			},
1886
-			$attribut
1887
-		);
1888
-
1889
-		return $balise;
1890
-	}
1891
-	if (
1892
-		$balise
1893
-		&& stripos($balise, $attribut) !== false
1894
-		&& preg_match(
1895
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1896
-			. $attribut
1897
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1898
-			$balise,
1899
-			$r
1900
-		)
1901
-	) {
1902
-		if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) {
1903
-			$r[4] = substr($r[3], 1, -1);
1904
-			$r[3] = $r[3][0];
1905
-		} elseif ($r[3] !== '') {
1906
-			$r[4] = $r[3];
1907
-			$r[3] = '';
1908
-		} else {
1909
-			$r[4] = trim($r[2]);
1910
-		}
1911
-		$att = $r[4];
1912
-		if (str_contains($att, '&#')) {
1913
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1914
-		}
1915
-		$att = filtrer_entites($att);
1916
-	} else {
1917
-		$att = null;
1918
-		$r = [];
1919
-	}
1920
-
1921
-	if ($complet) {
1922
-		return [$att, $r];
1923
-	} else {
1924
-		return $att;
1925
-	}
1880
+    if (is_array($balise)) {
1881
+        array_walk(
1882
+            $balise,
1883
+            function (&$a, $key, $t) {
1884
+                $a = extraire_attribut($a, $t);
1885
+            },
1886
+            $attribut
1887
+        );
1888
+
1889
+        return $balise;
1890
+    }
1891
+    if (
1892
+        $balise
1893
+        && stripos($balise, $attribut) !== false
1894
+        && preg_match(
1895
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1896
+            . $attribut
1897
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1898
+            $balise,
1899
+            $r
1900
+        )
1901
+    ) {
1902
+        if (isset($r[3][0]) && ($r[3][0] == '"' || $r[3][0] == "'")) {
1903
+            $r[4] = substr($r[3], 1, -1);
1904
+            $r[3] = $r[3][0];
1905
+        } elseif ($r[3] !== '') {
1906
+            $r[4] = $r[3];
1907
+            $r[3] = '';
1908
+        } else {
1909
+            $r[4] = trim($r[2]);
1910
+        }
1911
+        $att = $r[4];
1912
+        if (str_contains($att, '&#')) {
1913
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1914
+        }
1915
+        $att = filtrer_entites($att);
1916
+    } else {
1917
+        $att = null;
1918
+        $r = [];
1919
+    }
1920
+
1921
+    if ($complet) {
1922
+        return [$att, $r];
1923
+    } else {
1924
+        return $att;
1925
+    }
1926 1926
 }
1927 1927
 
1928 1928
 /**
@@ -1955,37 +1955,37 @@  discard block
 block discarded – undo
1955 1955
  **/
1956 1956
 function inserer_attribut(?string $balise, string $attribut, ?string $val, bool $proteger = true, bool $vider = false): string {
1957 1957
 
1958
-	if ($balise === null || $balise === '') {
1959
-		return '';
1960
-	}
1958
+    if ($balise === null || $balise === '') {
1959
+        return '';
1960
+    }
1961 1961
 
1962
-	// preparer l'attribut
1963
-	// supprimer les &nbsp; etc mais pas les balises html
1964
-	// qui ont un sens dans un attribut value d'un input
1965
-	if ($proteger) {
1966
-		$val = attribut_html($val, false);
1967
-	}
1962
+    // preparer l'attribut
1963
+    // supprimer les &nbsp; etc mais pas les balises html
1964
+    // qui ont un sens dans un attribut value d'un input
1965
+    if ($proteger) {
1966
+        $val = attribut_html($val, false);
1967
+    }
1968 1968
 
1969
-	// echapper les ' pour eviter tout bug
1970
-	$val = str_replace("'", '&#039;', $val ?? '');
1971
-	$insert = $vider && (string) $val === '' ? '' : " $attribut='$val'";
1969
+    // echapper les ' pour eviter tout bug
1970
+    $val = str_replace("'", '&#039;', $val ?? '');
1971
+    $insert = $vider && (string) $val === '' ? '' : " $attribut='$val'";
1972 1972
 
1973
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
1973
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
1974 1974
 
1975
-	if ($old !== null) {
1976
-		// Remplacer l'ancien attribut du meme nom
1977
-		$balise = $r[1] . $insert . $r[5];
1978
-	} else {
1979
-		// preferer une balise " />" (comme <img />)
1980
-		if (preg_match(',/>,', $balise)) {
1981
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
1982
-		} // sinon une balise <a ...> ... </a>
1983
-		else {
1984
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
1985
-		}
1986
-	}
1975
+    if ($old !== null) {
1976
+        // Remplacer l'ancien attribut du meme nom
1977
+        $balise = $r[1] . $insert . $r[5];
1978
+    } else {
1979
+        // preferer une balise " />" (comme <img />)
1980
+        if (preg_match(',/>,', $balise)) {
1981
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
1982
+        } // sinon une balise <a ...> ... </a>
1983
+        else {
1984
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
1985
+        }
1986
+    }
1987 1987
 
1988
-	return $balise;
1988
+    return $balise;
1989 1989
 }
1990 1990
 
1991 1991
 /**
@@ -2003,7 +2003,7 @@  discard block
 block discarded – undo
2003 2003
  * @return string Code HTML sans l'attribut
2004 2004
  **/
2005 2005
 function vider_attribut(?string $balise, string $attribut): string {
2006
-	return inserer_attribut($balise, $attribut, '', false, true);
2006
+    return inserer_attribut($balise, $attribut, '', false, true);
2007 2007
 }
2008 2008
 
2009 2009
 /**
@@ -2015,50 +2015,50 @@  discard block
 block discarded – undo
2015 2015
  * @return string
2016 2016
  */
2017 2017
 function modifier_class($balise, $class, $operation = 'ajouter') {
2018
-	if (is_string($class)) {
2019
-		$class = explode(' ', trim($class));
2020
-	}
2021
-	$class = array_filter($class);
2022
-	$class = array_unique($class);
2023
-	if (!$class) {
2024
-		return $balise;
2025
-	}
2026
-
2027
-	$class_courante = extraire_attribut($balise, 'class');
2028
-	$class_new = $class_courante;
2029
-	foreach ($class as $c) {
2030
-		$is_class_presente = false;
2031
-		if (
2032
-			$class_courante
2033
-			&& str_contains($class_courante, (string) $c)
2034
-			&& in_array($c, preg_split(',\s+,', $class_courante))
2035
-		) {
2036
-			$is_class_presente = true;
2037
-		}
2038
-		if (
2039
-			in_array($operation, ['ajouter', 'commuter'])
2040
-			&& !$is_class_presente
2041
-		) {
2042
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2043
-		} elseif (
2044
-			in_array($operation, ['supprimer', 'commuter'])
2045
-			&& $is_class_presente
2046
-		) {
2047
-			$class_new = preg_split(',\s+,', $class_new);
2048
-			$class_new = array_diff($class_new, [$c]);
2049
-			$class_new = implode(' ', $class_new);
2050
-		}
2051
-	}
2052
-
2053
-	if ($class_new !== $class_courante) {
2054
-		if (strlen($class_new)) {
2055
-			$balise = inserer_attribut($balise, 'class', $class_new);
2056
-		} elseif ($class_courante) {
2057
-			$balise = vider_attribut($balise, 'class');
2058
-		}
2059
-	}
2060
-
2061
-	return $balise;
2018
+    if (is_string($class)) {
2019
+        $class = explode(' ', trim($class));
2020
+    }
2021
+    $class = array_filter($class);
2022
+    $class = array_unique($class);
2023
+    if (!$class) {
2024
+        return $balise;
2025
+    }
2026
+
2027
+    $class_courante = extraire_attribut($balise, 'class');
2028
+    $class_new = $class_courante;
2029
+    foreach ($class as $c) {
2030
+        $is_class_presente = false;
2031
+        if (
2032
+            $class_courante
2033
+            && str_contains($class_courante, (string) $c)
2034
+            && in_array($c, preg_split(',\s+,', $class_courante))
2035
+        ) {
2036
+            $is_class_presente = true;
2037
+        }
2038
+        if (
2039
+            in_array($operation, ['ajouter', 'commuter'])
2040
+            && !$is_class_presente
2041
+        ) {
2042
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2043
+        } elseif (
2044
+            in_array($operation, ['supprimer', 'commuter'])
2045
+            && $is_class_presente
2046
+        ) {
2047
+            $class_new = preg_split(',\s+,', $class_new);
2048
+            $class_new = array_diff($class_new, [$c]);
2049
+            $class_new = implode(' ', $class_new);
2050
+        }
2051
+    }
2052
+
2053
+    if ($class_new !== $class_courante) {
2054
+        if (strlen($class_new)) {
2055
+            $balise = inserer_attribut($balise, 'class', $class_new);
2056
+        } elseif ($class_courante) {
2057
+            $balise = vider_attribut($balise, 'class');
2058
+        }
2059
+    }
2060
+
2061
+    return $balise;
2062 2062
 }
2063 2063
 
2064 2064
 /**
@@ -2068,7 +2068,7 @@  discard block
 block discarded – undo
2068 2068
  * @return string
2069 2069
  */
2070 2070
 function ajouter_class($balise, $class) {
2071
-	return modifier_class($balise, $class, 'ajouter');
2071
+    return modifier_class($balise, $class, 'ajouter');
2072 2072
 }
2073 2073
 
2074 2074
 /**
@@ -2078,7 +2078,7 @@  discard block
 block discarded – undo
2078 2078
  * @return string
2079 2079
  */
2080 2080
 function supprimer_class($balise, $class) {
2081
-	return modifier_class($balise, $class, 'supprimer');
2081
+    return modifier_class($balise, $class, 'supprimer');
2082 2082
 }
2083 2083
 
2084 2084
 /**
@@ -2089,7 +2089,7 @@  discard block
 block discarded – undo
2089 2089
  * @return string
2090 2090
  */
2091 2091
 function commuter_class($balise, $class) {
2092
-	return modifier_class($balise, $class, 'commuter');
2092
+    return modifier_class($balise, $class, 'commuter');
2093 2093
 }
2094 2094
 
2095 2095
 /**
@@ -2100,19 +2100,19 @@  discard block
 block discarded – undo
2100 2100
  * @return string
2101 2101
  */
2102 2102
 function tester_config($id, $mode = '') {
2103
-	include_spip('action/inscrire_auteur');
2103
+    include_spip('action/inscrire_auteur');
2104 2104
 
2105
-	return tester_statut_inscription($mode, $id);
2105
+    return tester_statut_inscription($mode, $id);
2106 2106
 }
2107 2107
 
2108 2108
 //
2109 2109
 // Quelques fonctions de calcul arithmetique
2110 2110
 //
2111 2111
 function floatstr($a) {
2112
-	return str_replace(',', '.', (string)(float) $a);
2112
+    return str_replace(',', '.', (string)(float) $a);
2113 2113
 }
2114 2114
 function strize($f, $a, $b) {
2115
-	return floatstr($f(floatstr($a), floatstr($b)));
2115
+    return floatstr($f(floatstr($a), floatstr($b)));
2116 2116
 }
2117 2117
 
2118 2118
 /**
@@ -2131,11 +2131,11 @@  discard block
 block discarded – undo
2131 2131
  * @return int $a+$b
2132 2132
  **/
2133 2133
 function plus($a, $b) {
2134
-	return $a + $b;
2134
+    return $a + $b;
2135 2135
 }
2136 2136
 
2137 2137
 function strplus($a, $b) {
2138
-	return strize('plus', $a, $b);
2138
+    return strize('plus', $a, $b);
2139 2139
 }
2140 2140
 
2141 2141
 /**
@@ -2154,11 +2154,11 @@  discard block
 block discarded – undo
2154 2154
  * @return int $a-$b
2155 2155
  **/
2156 2156
 function moins($a, $b) {
2157
-	return $a - $b;
2157
+    return $a - $b;
2158 2158
 }
2159 2159
 
2160 2160
 function strmoins($a, $b) {
2161
-	return strize('moins', $a, $b);
2161
+    return strize('moins', $a, $b);
2162 2162
 }
2163 2163
 
2164 2164
 /**
@@ -2178,11 +2178,11 @@  discard block
 block discarded – undo
2178 2178
  * @return int $a*$b
2179 2179
  **/
2180 2180
 function mult($a, $b) {
2181
-	return $a * $b;
2181
+    return $a * $b;
2182 2182
 }
2183 2183
 
2184 2184
 function strmult($a, $b) {
2185
-	return strize('mult', $a, $b);
2185
+    return strize('mult', $a, $b);
2186 2186
 }
2187 2187
 
2188 2188
 /**
@@ -2202,11 +2202,11 @@  discard block
 block discarded – undo
2202 2202
  * @return int $a/$b (ou 0 si $b est nul)
2203 2203
  **/
2204 2204
 function div($a, $b) {
2205
-	return $b ? $a / $b : 0;
2205
+    return $b ? $a / $b : 0;
2206 2206
 }
2207 2207
 
2208 2208
 function strdiv($a, $b) {
2209
-	return strize('div', $a, $b);
2209
+    return strize('div', $a, $b);
2210 2210
 }
2211 2211
 
2212 2212
 /**
@@ -2227,7 +2227,7 @@  discard block
 block discarded – undo
2227 2227
  * @return int ($nb % $mod) + $add
2228 2228
  **/
2229 2229
 function modulo($nb, $mod, $add = 0) {
2230
-	return ($mod ? $nb % $mod : 0) + $add;
2230
+    return ($mod ? $nb % $mod : 0) + $add;
2231 2231
 }
2232 2232
 
2233 2233
 
@@ -2242,26 +2242,26 @@  discard block
 block discarded – undo
2242 2242
  *      - true sinon
2243 2243
  **/
2244 2244
 function nom_acceptable($nom) {
2245
-	$remp2 = [];
2246
-	$remp1 = [];
2247
-	if (!is_string($nom)) {
2248
-		return false;
2249
-	}
2250
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2251
-		define('_TAGS_NOM_AUTEUR', '');
2252
-	}
2253
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2254
-	foreach ($tags_acceptes as $tag) {
2255
-		if (strlen($tag)) {
2256
-			$remp1[] = '<' . trim($tag) . '>';
2257
-			$remp1[] = '</' . trim($tag) . '>';
2258
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2259
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2260
-		}
2261
-	}
2262
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2263
-
2264
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2245
+    $remp2 = [];
2246
+    $remp1 = [];
2247
+    if (!is_string($nom)) {
2248
+        return false;
2249
+    }
2250
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2251
+        define('_TAGS_NOM_AUTEUR', '');
2252
+    }
2253
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2254
+    foreach ($tags_acceptes as $tag) {
2255
+        if (strlen($tag)) {
2256
+            $remp1[] = '<' . trim($tag) . '>';
2257
+            $remp1[] = '</' . trim($tag) . '>';
2258
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2259
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2260
+        }
2261
+    }
2262
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2263
+
2264
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2265 2265
 }
2266 2266
 
2267 2267
 
@@ -2277,13 +2277,13 @@  discard block
 block discarded – undo
2277 2277
  *      - renvoie un tableau si l'entree est un tableau
2278 2278
  **/
2279 2279
 function email_valide($adresses) {
2280
-	if (is_array($adresses)) {
2281
-		$adresses = array_map('email_valide', $adresses);
2282
-		return array_filter($adresses);
2283
-	}
2280
+    if (is_array($adresses)) {
2281
+        $adresses = array_map('email_valide', $adresses);
2282
+        return array_filter($adresses);
2283
+    }
2284 2284
 
2285
-	$email_valide = charger_fonction('email_valide', 'inc');
2286
-	return $email_valide($adresses);
2285
+    $email_valide = charger_fonction('email_valide', 'inc');
2286
+    return $email_valide($adresses);
2287 2287
 }
2288 2288
 
2289 2289
 /**
@@ -2297,29 +2297,29 @@  discard block
 block discarded – undo
2297 2297
  * @return string texte
2298 2298
  **/
2299 2299
 function afficher_enclosures($tags) {
2300
-	$s = [];
2301
-	foreach (extraire_balises($tags, 'a') as $tag) {
2302
-		if (
2303
-			extraire_attribut($tag, 'rel') == 'enclosure'
2304
-			&& ($t = extraire_attribut($tag, 'href'))
2305
-		) {
2306
-			$s[] = preg_replace(
2307
-				',>[^<]+</a>,S',
2308
-				'>'
2309
-				. http_img_pack(
2310
-					'attachment-16.png',
2311
-					$t,
2312
-					'',
2313
-					$t,
2314
-					['utiliser_suffixe_size' => true]
2315
-				)
2316
-				. '</a>',
2317
-				(string) $tag
2318
-			);
2319
-		}
2320
-	}
2321
-
2322
-	return implode('&nbsp;', $s);
2300
+    $s = [];
2301
+    foreach (extraire_balises($tags, 'a') as $tag) {
2302
+        if (
2303
+            extraire_attribut($tag, 'rel') == 'enclosure'
2304
+            && ($t = extraire_attribut($tag, 'href'))
2305
+        ) {
2306
+            $s[] = preg_replace(
2307
+                ',>[^<]+</a>,S',
2308
+                '>'
2309
+                . http_img_pack(
2310
+                    'attachment-16.png',
2311
+                    $t,
2312
+                    '',
2313
+                    $t,
2314
+                    ['utiliser_suffixe_size' => true]
2315
+                )
2316
+                . '</a>',
2317
+                (string) $tag
2318
+            );
2319
+        }
2320
+    }
2321
+
2322
+    return implode('&nbsp;', $s);
2323 2323
 }
2324 2324
 
2325 2325
 /**
@@ -2334,15 +2334,15 @@  discard block
 block discarded – undo
2334 2334
  * @return string Liens trouvés
2335 2335
  **/
2336 2336
 function afficher_tags($tags, $rels = 'tag,directory') {
2337
-	$s = [];
2338
-	foreach (extraire_balises($tags, 'a') as $tag) {
2339
-		$rel = extraire_attribut($tag, 'rel');
2340
-		if (strstr(",$rels,", (string) ",$rel,")) {
2341
-			$s[] = $tag;
2342
-		}
2343
-	}
2337
+    $s = [];
2338
+    foreach (extraire_balises($tags, 'a') as $tag) {
2339
+        $rel = extraire_attribut($tag, 'rel');
2340
+        if (strstr(",$rels,", (string) ",$rel,")) {
2341
+            $s[] = $tag;
2342
+        }
2343
+    }
2344 2344
 
2345
-	return implode(', ', $s);
2345
+    return implode(', ', $s);
2346 2346
 }
2347 2347
 
2348 2348
 
@@ -2364,21 +2364,21 @@  discard block
 block discarded – undo
2364 2364
  * @return string Tag HTML `<a>` avec microformat.
2365 2365
  **/
2366 2366
 function enclosure2microformat($e) {
2367
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2368
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2369
-	}
2370
-	$type = extraire_attribut($e, 'type');
2371
-	if (!$length = extraire_attribut($e, 'length')) {
2372
-		# <media:content : longeur dans fileSize. On tente.
2373
-		$length = extraire_attribut($e, 'fileSize');
2374
-	}
2375
-	$fichier = basename($url);
2367
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2368
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2369
+    }
2370
+    $type = extraire_attribut($e, 'type');
2371
+    if (!$length = extraire_attribut($e, 'length')) {
2372
+        # <media:content : longeur dans fileSize. On tente.
2373
+        $length = extraire_attribut($e, 'fileSize');
2374
+    }
2375
+    $fichier = basename($url);
2376 2376
 
2377
-	return '<a rel="enclosure"'
2378
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2379
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2380
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2381
-	. '>' . $fichier . '</a>';
2377
+    return '<a rel="enclosure"'
2378
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2379
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2380
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2381
+    . '>' . $fichier . '</a>';
2382 2382
 }
2383 2383
 
2384 2384
 /**
@@ -2396,24 +2396,24 @@  discard block
 block discarded – undo
2396 2396
  * @return string Tags RSS `<enclosure>`.
2397 2397
  **/
2398 2398
 function microformat2enclosure($tags) {
2399
-	$enclosures = [];
2400
-	foreach (extraire_balises($tags, 'a') as $e) {
2401
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2402
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2403
-			$type = extraire_attribut($e, 'type');
2404
-			if (!$length = (int) extraire_attribut($e, 'title')) {
2405
-				$length = (int) extraire_attribut($e, 'length');
2406
-			} # vieux data
2407
-			$fichier = basename($url);
2408
-			$enclosures[] = '<enclosure'
2409
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2410
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2411
-				. ($length ? ' length="' . $length . '"' : '')
2412
-				. ' />';
2413
-		}
2414
-	}
2399
+    $enclosures = [];
2400
+    foreach (extraire_balises($tags, 'a') as $e) {
2401
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2402
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2403
+            $type = extraire_attribut($e, 'type');
2404
+            if (!$length = (int) extraire_attribut($e, 'title')) {
2405
+                $length = (int) extraire_attribut($e, 'length');
2406
+            } # vieux data
2407
+            $fichier = basename($url);
2408
+            $enclosures[] = '<enclosure'
2409
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2410
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2411
+                . ($length ? ' length="' . $length . '"' : '')
2412
+                . ' />';
2413
+        }
2414
+    }
2415 2415
 
2416
-	return implode("\n", $enclosures);
2416
+    return implode("\n", $enclosures);
2417 2417
 }
2418 2418
 
2419 2419
 
@@ -2429,16 +2429,16 @@  discard block
 block discarded – undo
2429 2429
  * @return string Tags RSS Atom `<dc:subject>`.
2430 2430
  **/
2431 2431
 function tags2dcsubject($tags) {
2432
-	$subjects = '';
2433
-	foreach (extraire_balises($tags, 'a') as $e) {
2434
-		if (extraire_attribut($e, 'rel') == 'tag') {
2435
-			$subjects .= '<dc:subject>'
2436
-				. texte_backend(textebrut($e))
2437
-				. '</dc:subject>' . "\n";
2438
-		}
2439
-	}
2432
+    $subjects = '';
2433
+    foreach (extraire_balises($tags, 'a') as $e) {
2434
+        if (extraire_attribut($e, 'rel') == 'tag') {
2435
+            $subjects .= '<dc:subject>'
2436
+                . texte_backend(textebrut($e))
2437
+                . '</dc:subject>' . "\n";
2438
+        }
2439
+    }
2440 2440
 
2441
-	return $subjects;
2441
+    return $subjects;
2442 2442
 }
2443 2443
 
2444 2444
 /**
@@ -2467,12 +2467,12 @@  discard block
 block discarded – undo
2467 2467
  *     - Tableau de résultats, si tableau en entrée.
2468 2468
  **/
2469 2469
 function extraire_balise($texte, $tag = 'a', $profondeur = 1) {
2470
-	$balises = extraire_balises($texte, $tag, ['nb_max' => 1, 'profondeur' => $profondeur]);
2471
-	if (is_array($texte)) {
2472
-		return array_map(fn (array $a) => empty($a) ? '' : reset($a), $balises);
2473
-	}
2470
+    $balises = extraire_balises($texte, $tag, ['nb_max' => 1, 'profondeur' => $profondeur]);
2471
+    if (is_array($texte)) {
2472
+        return array_map(fn (array $a) => empty($a) ? '' : reset($a), $balises);
2473
+    }
2474 2474
 
2475
-	return (empty($balises) ? '' : reset($balises));
2475
+    return (empty($balises) ? '' : reset($balises));
2476 2476
 }
2477 2477
 
2478 2478
 /**
@@ -2500,25 +2500,25 @@  discard block
 block discarded – undo
2500 2500
  *     - Tableau de résultats, si tableau en entrée.
2501 2501
  **/
2502 2502
 function extraire_balises($texte, $tag = 'a', $options = []) {
2503
-	if (is_array($texte)) {
2504
-		array_walk(
2505
-			$texte,
2506
-			function (&$a, $key, $t) {
2507
-				$a = extraire_balises($a, $t);
2508
-			},
2509
-			$tag
2510
-		);
2503
+    if (is_array($texte)) {
2504
+        array_walk(
2505
+            $texte,
2506
+            function (&$a, $key, $t) {
2507
+                $a = extraire_balises($a, $t);
2508
+            },
2509
+            $tag
2510
+        );
2511 2511
 
2512
-		return $texte;
2513
-	}
2512
+        return $texte;
2513
+    }
2514 2514
 
2515
-	$htmlTagCollecteur = new CollecteurHtmlTag($tag);
2516
-	$collection = $htmlTagCollecteur->collecter($texte, $options);
2517
-	if (!empty($collection)) {
2518
-		return array_column($collection, 'raw');
2519
-	}
2515
+    $htmlTagCollecteur = new CollecteurHtmlTag($tag);
2516
+    $collection = $htmlTagCollecteur->collecter($texte, $options);
2517
+    if (!empty($collection)) {
2518
+        return array_column($collection, 'raw');
2519
+    }
2520 2520
 
2521
-	return [];
2521
+    return [];
2522 2522
 }
2523 2523
 
2524 2524
 /**
@@ -2547,11 +2547,11 @@  discard block
 block discarded – undo
2547 2547
  *     - `$def` si on n'a pas transmis de tableau
2548 2548
  **/
2549 2549
 function in_any($val, $vals, $def = '') {
2550
-	if (!is_array($vals) && $vals && ($v = unserialize($vals))) {
2551
-		$vals = $v;
2552
-	}
2550
+    if (!is_array($vals) && $vals && ($v = unserialize($vals))) {
2551
+        $vals = $v;
2552
+    }
2553 2553
 
2554
-	return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def));
2554
+    return (is_array($vals) ? (in_array($val, $vals) ? ' ' : '') : ($def));
2555 2555
 }
2556 2556
 
2557 2557
 
@@ -2572,12 +2572,12 @@  discard block
 block discarded – undo
2572 2572
  *     Résultat du calcul
2573 2573
  **/
2574 2574
 function valeur_numerique($expr) {
2575
-	$a = 0;
2576
-	if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) {
2577
-		eval("\$a = $expr;");
2578
-	}
2575
+    $a = 0;
2576
+    if (preg_match(',^\d+(\s*[+*-]\s*\d+)*$,S', trim($expr))) {
2577
+        eval("\$a = $expr;");
2578
+    }
2579 2579
 
2580
-	return (int) $a;
2580
+    return (int) $a;
2581 2581
 }
2582 2582
 
2583 2583
 /**
@@ -2596,7 +2596,7 @@  discard block
 block discarded – undo
2596 2596
  *      Retourne `$a*$b/$c`
2597 2597
  **/
2598 2598
 function regledetrois($a, $b, $c) {
2599
-	return round($a * $b / $c);
2599
+    return round($a * $b / $c);
2600 2600
 }
2601 2601
 
2602 2602
 
@@ -2619,79 +2619,79 @@  discard block
 block discarded – undo
2619 2619
  * @return string Suite de champs input hidden
2620 2620
  **/
2621 2621
 function form_hidden(?string $action = ''): string {
2622
-	$action ??= '';
2623
-
2624
-	$contexte = [];
2625
-	include_spip('inc/urls');
2626
-	if (
2627
-		($p = urls_decoder_url($action, ''))
2628
-		&& reset($p)
2629
-	) {
2630
-		$fond = array_shift($p);
2631
-		if ($fond != '404') {
2632
-			$contexte = array_shift($p);
2633
-			$contexte['page'] = $fond;
2634
-			$action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2635
-		}
2636
-	}
2637
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2638
-	if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) {
2639
-		unset($contexte['type']);
2640
-	}
2641
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) {
2642
-		unset($contexte['type-page']);
2643
-	}
2644
-
2645
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2646
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2647
-	$values = [];
2648
-
2649
-	// d'abord avec celles de l'url
2650
-	if (false !== ($p = strpos($action, '?'))) {
2651
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2652
-			$c = explode('=', (string) $c, 2);
2653
-			$var = array_shift($c);
2654
-			$val = array_shift($c) ?? '';
2655
-			if ($var) {
2656
-				$val = rawurldecode($val);
2657
-				$var = rawurldecode($var); // decoder les [] eventuels
2658
-				if (preg_match(',\[\]$,S', $var)) {
2659
-					$values[] = [$var, $val];
2660
-				} else {
2661
-					if (!isset($values[$var])) {
2662
-						$values[$var] = [$var, $val];
2663
-					}
2664
-				}
2665
-			}
2666
-		}
2667
-	}
2668
-
2669
-	// ensuite avec celles du contexte, sans doublonner !
2670
-	foreach ($contexte as $var => $val) {
2671
-		if (preg_match(',\[\]$,S', (string) $var)) {
2672
-			$values[] = [$var, $val];
2673
-		} else {
2674
-			if (!isset($values[$var])) {
2675
-				$values[$var] = [$var, $val];
2676
-			}
2677
-		}
2678
-	}
2679
-
2680
-	// puis on rassemble le tout
2681
-	$hidden = [];
2682
-	foreach ($values as $value) {
2683
-		[$var, $val] = $value;
2684
-		$hidden[] = '<input name="'
2685
-			. entites_html($var)
2686
-			. '"'
2687
-			. (is_null($val)
2688
-				? ''
2689
-				: ' value="' . entites_html($val) . '"'
2690
-			)
2691
-			. ' type="hidden"' . "\n/>";
2692
-	}
2693
-
2694
-	return implode('', $hidden);
2622
+    $action ??= '';
2623
+
2624
+    $contexte = [];
2625
+    include_spip('inc/urls');
2626
+    if (
2627
+        ($p = urls_decoder_url($action, ''))
2628
+        && reset($p)
2629
+    ) {
2630
+        $fond = array_shift($p);
2631
+        if ($fond != '404') {
2632
+            $contexte = array_shift($p);
2633
+            $contexte['page'] = $fond;
2634
+            $action = preg_replace('/([?]' . preg_quote((string) $fond, '/') . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2635
+        }
2636
+    }
2637
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2638
+    if (defined('_DEFINIR_CONTEXTE_TYPE') && _DEFINIR_CONTEXTE_TYPE) {
2639
+        unset($contexte['type']);
2640
+    }
2641
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') || _DEFINIR_CONTEXTE_TYPE_PAGE) {
2642
+        unset($contexte['type-page']);
2643
+    }
2644
+
2645
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2646
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2647
+    $values = [];
2648
+
2649
+    // d'abord avec celles de l'url
2650
+    if (false !== ($p = strpos($action, '?'))) {
2651
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2652
+            $c = explode('=', (string) $c, 2);
2653
+            $var = array_shift($c);
2654
+            $val = array_shift($c) ?? '';
2655
+            if ($var) {
2656
+                $val = rawurldecode($val);
2657
+                $var = rawurldecode($var); // decoder les [] eventuels
2658
+                if (preg_match(',\[\]$,S', $var)) {
2659
+                    $values[] = [$var, $val];
2660
+                } else {
2661
+                    if (!isset($values[$var])) {
2662
+                        $values[$var] = [$var, $val];
2663
+                    }
2664
+                }
2665
+            }
2666
+        }
2667
+    }
2668
+
2669
+    // ensuite avec celles du contexte, sans doublonner !
2670
+    foreach ($contexte as $var => $val) {
2671
+        if (preg_match(',\[\]$,S', (string) $var)) {
2672
+            $values[] = [$var, $val];
2673
+        } else {
2674
+            if (!isset($values[$var])) {
2675
+                $values[$var] = [$var, $val];
2676
+            }
2677
+        }
2678
+    }
2679
+
2680
+    // puis on rassemble le tout
2681
+    $hidden = [];
2682
+    foreach ($values as $value) {
2683
+        [$var, $val] = $value;
2684
+        $hidden[] = '<input name="'
2685
+            . entites_html($var)
2686
+            . '"'
2687
+            . (is_null($val)
2688
+                ? ''
2689
+                : ' value="' . entites_html($val) . '"'
2690
+            )
2691
+            . ' type="hidden"' . "\n/>";
2692
+    }
2693
+
2694
+    return implode('', $hidden);
2695 2695
 }
2696 2696
 
2697 2697
 
@@ -2713,7 +2713,7 @@  discard block
 block discarded – undo
2713 2713
  *    - la première valeur du tableau sinon.
2714 2714
  **/
2715 2715
 function filtre_reset($array) {
2716
-	return is_array($array) ? reset($array) : null;
2716
+    return is_array($array) ? reset($array) : null;
2717 2717
 }
2718 2718
 
2719 2719
 /**
@@ -2734,7 +2734,7 @@  discard block
 block discarded – undo
2734 2734
  *    - la dernière valeur du tableau sinon.
2735 2735
  **/
2736 2736
 function filtre_end($array) {
2737
-	return is_array($array) ? end($array) : null;
2737
+    return is_array($array) ? end($array) : null;
2738 2738
 }
2739 2739
 
2740 2740
 /**
@@ -2754,11 +2754,11 @@  discard block
 block discarded – undo
2754 2754
  *
2755 2755
  **/
2756 2756
 function filtre_push($array, mixed $val) {
2757
-	if (!is_array($array) || !array_push($array, $val)) {
2758
-		return '';
2759
-	}
2757
+    if (!is_array($array) || !array_push($array, $val)) {
2758
+        return '';
2759
+    }
2760 2760
 
2761
-	return $array;
2761
+    return $array;
2762 2762
 }
2763 2763
 
2764 2764
 /**
@@ -2777,7 +2777,7 @@  discard block
 block discarded – undo
2777 2777
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2778 2778
  **/
2779 2779
 function filtre_find($array, mixed $val) {
2780
-	return (is_array($array) && in_array($val, $array));
2780
+    return (is_array($array) && in_array($val, $array));
2781 2781
 }
2782 2782
 
2783 2783
 
@@ -2794,13 +2794,13 @@  discard block
 block discarded – undo
2794 2794
  *     Contenu avec urls en absolus
2795 2795
  **/
2796 2796
 function urls_absolues_css($contenu, $source) {
2797
-	$path = suivre_lien(url_absolue($source), './');
2797
+    $path = suivre_lien(url_absolue($source), './');
2798 2798
 
2799
-	return preg_replace_callback(
2800
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2801
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2802
-		$contenu
2803
-	);
2799
+    return preg_replace_callback(
2800
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2801
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2802
+        $contenu
2803
+    );
2804 2804
 }
2805 2805
 
2806 2806
 
@@ -2829,123 +2829,123 @@  discard block
 block discarded – undo
2829 2829
  *     Chemin du fichier CSS inversé
2830 2830
  **/
2831 2831
 function direction_css($css, $voulue = '') {
2832
-	if (!$css) {
2833
-		return '';
2834
-	}
2835
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2836
-		return $css;
2837
-	}
2838
-	include_spip('inc/lang');
2839
-	// si on a precise le sens voulu en argument, le prendre en compte
2840
-	if ($voulue = strtolower($voulue)) {
2841
-		if ($voulue != 'rtl' && $voulue != 'ltr') {
2842
-			$voulue = lang_dir($voulue);
2843
-		}
2844
-	} else {
2845
-		$voulue = lang_dir();
2846
-	}
2847
-
2848
-	$r = count($r) > 1;
2849
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2850
-	$dir = $r ? 'rtl' : 'ltr';
2851
-	$ndir = $r ? 'ltr' : 'rtl';
2852
-
2853
-	if ($voulue == $dir) {
2854
-		return $css;
2855
-	}
2856
-
2857
-	if (
2858
-		// url absolue
2859
-		preg_match(',^https?:,i', $css)
2860
-		// ou qui contient un ?
2861
-		|| ($p = strpos($css, '?')) !== false
2862
-	) {
2863
-		$distant = true;
2864
-		$cssf = parse_url($css);
2865
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2866
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2867
-	} else {
2868
-		$distant = false;
2869
-		$cssf = $css;
2870
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2871
-		//propose (rien a faire dans ce cas)
2872
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2873
-		if (@file_exists($f)) {
2874
-			return $f;
2875
-		}
2876
-	}
2877
-
2878
-	// 2.
2879
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2880
-	$f = $dir_var
2881
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2882
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2883
-
2884
-	// la css peut etre distante (url absolue !)
2885
-	$contenu = null;
2886
-	if ($distant) {
2887
-		include_spip('inc/distant');
2888
-		$res = recuperer_url($css);
2889
-		if (!$res || !($contenu = $res['page'])) {
2890
-			return $css;
2891
-		}
2892
-	} else {
2893
-		if (
2894
-			@filemtime($f) > @filemtime($css)
2895
-			&& _VAR_MODE != 'recalcul'
2896
-		) {
2897
-			return $f;
2898
-		}
2899
-		if (!lire_fichier($css, $contenu)) {
2900
-			return $css;
2901
-		}
2902
-	}
2903
-
2904
-
2905
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2906
-	include_spip('lib/csstidy/class.csstidy');
2907
-	$parser = new csstidy();
2908
-	$parser->set_cfg('optimise_shorthands', 0);
2909
-	$parser->set_cfg('reverse_left_and_right', true);
2910
-	$parser->parse($contenu);
2911
-
2912
-	$contenu = $parser->print->plain();
2913
-
2914
-
2915
-	// reperer les @import auxquels il faut propager le direction_css
2916
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", (string) $contenu, $regs);
2917
-	$src = [];
2918
-	$src_direction_css = [];
2919
-	$src_faux_abs = [];
2920
-	$d = dirname($css);
2921
-	foreach ($regs[1] as $k => $import_css) {
2922
-		$css_direction = direction_css("$d/$import_css", $voulue);
2923
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2924
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2925
-			$css_direction = substr($css_direction, strlen($d) + 1);
2926
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2927
-		elseif (str_starts_with($css_direction, $dir_var)) {
2928
-			$css_direction = substr($css_direction, strlen($dir_var));
2929
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2930
-			$css_direction = '/@@@@@@/' . $css_direction;
2931
-		}
2932
-		$src[] = $regs[0][$k];
2933
-		$src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]);
2934
-	}
2935
-	$contenu = str_replace($src, $src_direction_css, (string) $contenu);
2936
-
2937
-	$contenu = urls_absolues_css($contenu, $css);
2938
-
2939
-	// virer les fausses url absolues que l'on a mis dans les import
2940
-	if ($src_faux_abs !== []) {
2941
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2942
-	}
2943
-
2944
-	if (!ecrire_fichier($f, $contenu)) {
2945
-		return $css;
2946
-	}
2947
-
2948
-	return $f;
2832
+    if (!$css) {
2833
+        return '';
2834
+    }
2835
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2836
+        return $css;
2837
+    }
2838
+    include_spip('inc/lang');
2839
+    // si on a precise le sens voulu en argument, le prendre en compte
2840
+    if ($voulue = strtolower($voulue)) {
2841
+        if ($voulue != 'rtl' && $voulue != 'ltr') {
2842
+            $voulue = lang_dir($voulue);
2843
+        }
2844
+    } else {
2845
+        $voulue = lang_dir();
2846
+    }
2847
+
2848
+    $r = count($r) > 1;
2849
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2850
+    $dir = $r ? 'rtl' : 'ltr';
2851
+    $ndir = $r ? 'ltr' : 'rtl';
2852
+
2853
+    if ($voulue == $dir) {
2854
+        return $css;
2855
+    }
2856
+
2857
+    if (
2858
+        // url absolue
2859
+        preg_match(',^https?:,i', $css)
2860
+        // ou qui contient un ?
2861
+        || ($p = strpos($css, '?')) !== false
2862
+    ) {
2863
+        $distant = true;
2864
+        $cssf = parse_url($css);
2865
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2866
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2867
+    } else {
2868
+        $distant = false;
2869
+        $cssf = $css;
2870
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2871
+        //propose (rien a faire dans ce cas)
2872
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2873
+        if (@file_exists($f)) {
2874
+            return $f;
2875
+        }
2876
+    }
2877
+
2878
+    // 2.
2879
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2880
+    $f = $dir_var
2881
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2882
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2883
+
2884
+    // la css peut etre distante (url absolue !)
2885
+    $contenu = null;
2886
+    if ($distant) {
2887
+        include_spip('inc/distant');
2888
+        $res = recuperer_url($css);
2889
+        if (!$res || !($contenu = $res['page'])) {
2890
+            return $css;
2891
+        }
2892
+    } else {
2893
+        if (
2894
+            @filemtime($f) > @filemtime($css)
2895
+            && _VAR_MODE != 'recalcul'
2896
+        ) {
2897
+            return $f;
2898
+        }
2899
+        if (!lire_fichier($css, $contenu)) {
2900
+            return $css;
2901
+        }
2902
+    }
2903
+
2904
+
2905
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2906
+    include_spip('lib/csstidy/class.csstidy');
2907
+    $parser = new csstidy();
2908
+    $parser->set_cfg('optimise_shorthands', 0);
2909
+    $parser->set_cfg('reverse_left_and_right', true);
2910
+    $parser->parse($contenu);
2911
+
2912
+    $contenu = $parser->print->plain();
2913
+
2914
+
2915
+    // reperer les @import auxquels il faut propager le direction_css
2916
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", (string) $contenu, $regs);
2917
+    $src = [];
2918
+    $src_direction_css = [];
2919
+    $src_faux_abs = [];
2920
+    $d = dirname($css);
2921
+    foreach ($regs[1] as $k => $import_css) {
2922
+        $css_direction = direction_css("$d/$import_css", $voulue);
2923
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2924
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2925
+            $css_direction = substr($css_direction, strlen($d) + 1);
2926
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2927
+        elseif (str_starts_with($css_direction, $dir_var)) {
2928
+            $css_direction = substr($css_direction, strlen($dir_var));
2929
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2930
+            $css_direction = '/@@@@@@/' . $css_direction;
2931
+        }
2932
+        $src[] = $regs[0][$k];
2933
+        $src_direction_css[] = str_replace($import_css, $css_direction, (string) $regs[0][$k]);
2934
+    }
2935
+    $contenu = str_replace($src, $src_direction_css, (string) $contenu);
2936
+
2937
+    $contenu = urls_absolues_css($contenu, $css);
2938
+
2939
+    // virer les fausses url absolues que l'on a mis dans les import
2940
+    if ($src_faux_abs !== []) {
2941
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2942
+    }
2943
+
2944
+    if (!ecrire_fichier($f, $contenu)) {
2945
+        return $css;
2946
+    }
2947
+
2948
+    return $f;
2949 2949
 }
2950 2950
 
2951 2951
 
@@ -2968,47 +2968,47 @@  discard block
 block discarded – undo
2968 2968
  *     - Chemin ou URL du fichier CSS source sinon.
2969 2969
  **/
2970 2970
 function url_absolue_css($css) {
2971
-	if (!preg_match(',\.css$,i', $css, $r)) {
2972
-		return $css;
2973
-	}
2971
+    if (!preg_match(',\.css$,i', $css, $r)) {
2972
+        return $css;
2973
+    }
2974 2974
 
2975
-	$url_absolue_css = url_absolue($css);
2975
+    $url_absolue_css = url_absolue($css);
2976 2976
 
2977
-	$f = basename($css, '.css');
2978
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
2979
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2980
-		. '.css';
2977
+    $f = basename($css, '.css');
2978
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
2979
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
2980
+        . '.css';
2981 2981
 
2982
-	if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') {
2983
-		return $f;
2984
-	}
2982
+    if (@filemtime($f) > @filemtime($css) && _VAR_MODE != 'recalcul') {
2983
+        return $f;
2984
+    }
2985 2985
 
2986
-	$contenu = null;
2987
-	if ($url_absolue_css == $css) {
2988
-		if (
2989
-			strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0
2990
-			|| !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2991
-		) {
2992
-			include_spip('inc/distant');
2993
-			$contenu = recuperer_url($css);
2994
-			$contenu = $contenu['page'] ?? '';
2995
-			if (!$contenu) {
2996
-				return $css;
2997
-			}
2998
-		}
2999
-	} elseif (!lire_fichier($css, $contenu)) {
3000
-		return $css;
3001
-	}
2986
+    $contenu = null;
2987
+    if ($url_absolue_css == $css) {
2988
+        if (
2989
+            strncmp((string) $GLOBALS['meta']['adresse_site'], $css, $l = strlen((string) $GLOBALS['meta']['adresse_site'])) != 0
2990
+            || !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
2991
+        ) {
2992
+            include_spip('inc/distant');
2993
+            $contenu = recuperer_url($css);
2994
+            $contenu = $contenu['page'] ?? '';
2995
+            if (!$contenu) {
2996
+                return $css;
2997
+            }
2998
+        }
2999
+    } elseif (!lire_fichier($css, $contenu)) {
3000
+        return $css;
3001
+    }
3002 3002
 
3003
-	// passer les url relatives a la css d'origine en url absolues
3004
-	$contenu = urls_absolues_css($contenu, $css);
3003
+    // passer les url relatives a la css d'origine en url absolues
3004
+    $contenu = urls_absolues_css($contenu, $css);
3005 3005
 
3006
-	// ecrire la css
3007
-	if (!ecrire_fichier($f, $contenu)) {
3008
-		return $css;
3009
-	}
3006
+    // ecrire la css
3007
+    if (!ecrire_fichier($f, $contenu)) {
3008
+        return $css;
3009
+    }
3010 3010
 
3011
-	return $f;
3011
+    return $f;
3012 3012
 }
3013 3013
 
3014 3014
 
@@ -3042,24 +3042,24 @@  discard block
 block discarded – undo
3042 3042
  *     Valeur trouvée ou valeur par défaut.
3043 3043
  **/
3044 3044
 function table_valeur(mixed $table, $cle, mixed $defaut = '', $conserver_null = false) {
3045
-	foreach (explode('/', $cle) as $k) {
3046
-		$table = (is_string($table) ? @unserialize($table) : $table);
3045
+    foreach (explode('/', $cle) as $k) {
3046
+        $table = (is_string($table) ? @unserialize($table) : $table);
3047 3047
 
3048
-		if (is_object($table)) {
3049
-			$table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut;
3050
-		} elseif (is_array($table)) {
3051
-			if ($conserver_null) {
3052
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3053
-			} else {
3054
-				$table = ($table[$k] ?? $defaut);
3055
-			}
3056
-		} else {
3057
-			$table = $defaut;
3058
-			break;
3059
-		}
3060
-	}
3048
+        if (is_object($table)) {
3049
+            $table = ($k !== '' && isset($table->$k)) ? $table->$k : $defaut;
3050
+        } elseif (is_array($table)) {
3051
+            if ($conserver_null) {
3052
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3053
+            } else {
3054
+                $table = ($table[$k] ?? $defaut);
3055
+            }
3056
+        } else {
3057
+            $table = $defaut;
3058
+            break;
3059
+        }
3060
+    }
3061 3061
 
3062
-	return $table;
3062
+    return $table;
3063 3063
 }
3064 3064
 
3065 3065
 /**
@@ -3092,22 +3092,22 @@  discard block
 block discarded – undo
3092 3092
  *     - string : expression trouvée.
3093 3093
  **/
3094 3094
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3095
-	if ((int) $modif && $capte == 0) {
3096
-		$capte = $modif;
3097
-		$modif = 'UuimsS';
3098
-	}
3099
-	$expression = str_replace('\/', '/', $expression);
3100
-	$expression = str_replace('/', '\/', $expression);
3095
+    if ((int) $modif && $capte == 0) {
3096
+        $capte = $modif;
3097
+        $modif = 'UuimsS';
3098
+    }
3099
+    $expression = str_replace('\/', '/', $expression);
3100
+    $expression = str_replace('/', '\/', $expression);
3101 3101
 
3102
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3103
-		if (isset($r[$capte])) {
3104
-			return $r[$capte];
3105
-		} else {
3106
-			return true;
3107
-		}
3108
-	}
3102
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3103
+        if (isset($r[$capte])) {
3104
+            return $r[$capte];
3105
+        } else {
3106
+            return true;
3107
+        }
3108
+    }
3109 3109
 
3110
-	return false;
3110
+    return false;
3111 3111
 }
3112 3112
 
3113 3113
 
@@ -3134,14 +3134,14 @@  discard block
 block discarded – undo
3134 3134
  *     Texte
3135 3135
  **/
3136 3136
 function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string {
3137
-	if (null === $texte) {
3138
-		return '';
3139
-	}
3137
+    if (null === $texte) {
3138
+        return '';
3139
+    }
3140 3140
 
3141
-	$expression = str_replace('\/', '/', $expression);
3142
-	$expression = str_replace('/', '\/', $expression);
3141
+    $expression = str_replace('\/', '/', $expression);
3142
+    $expression = str_replace('/', '\/', $expression);
3143 3143
 
3144
-	return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3144
+    return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3145 3145
 }
3146 3146
 
3147 3147
 
@@ -3159,25 +3159,25 @@  discard block
 block discarded – undo
3159 3159
  **/
3160 3160
 function traiter_doublons_documents(&$doublons, $letexte) {
3161 3161
 
3162
-	// Verifier dans le texte & les notes (pas beau, helas)
3163
-	$t = $letexte . $GLOBALS['les_notes'];
3162
+    // Verifier dans le texte & les notes (pas beau, helas)
3163
+    $t = $letexte . $GLOBALS['les_notes'];
3164 3164
 
3165
-	if (
3166
-		strstr($t, 'spip_document_')
3167
-		&& preg_match_all(
3168
-			',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS',
3169
-			$t,
3170
-			$matches,
3171
-			PREG_PATTERN_ORDER
3172
-		)
3173
-	) {
3174
-		if (!isset($doublons['documents'])) {
3175
-			$doublons['documents'] = '';
3176
-		}
3177
-		$doublons['documents'] .= ',' . implode(',', $matches[1]);
3178
-	}
3165
+    if (
3166
+        strstr($t, 'spip_document_')
3167
+        && preg_match_all(
3168
+            ',<[^>]+\sclass=["\']spip_document_(\d+)[\s"\'],imsS',
3169
+            $t,
3170
+            $matches,
3171
+            PREG_PATTERN_ORDER
3172
+        )
3173
+    ) {
3174
+        if (!isset($doublons['documents'])) {
3175
+            $doublons['documents'] = '';
3176
+        }
3177
+        $doublons['documents'] .= ',' . implode(',', $matches[1]);
3178
+    }
3179 3179
 
3180
-	return $letexte;
3180
+    return $letexte;
3181 3181
 }
3182 3182
 
3183 3183
 /**
@@ -3191,7 +3191,7 @@  discard block
 block discarded – undo
3191 3191
  * @return string Chaîne vide
3192 3192
  **/
3193 3193
 function vide(mixed $texte) {
3194
-	return '';
3194
+    return '';
3195 3195
 }
3196 3196
 
3197 3197
 //
@@ -3220,23 +3220,23 @@  discard block
 block discarded – undo
3220 3220
  *      Code HTML résultant
3221 3221
  **/
3222 3222
 function env_to_params($env, $ignore_params = []) {
3223
-	$ignore_params = array_merge(
3224
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3225
-		$ignore_params
3226
-	);
3227
-	if (!is_array($env)) {
3228
-		$env = unserialize($env);
3229
-	}
3230
-	$texte = '';
3231
-	if ($env) {
3232
-		foreach ($env as $i => $j) {
3233
-			if (is_string($j) && !in_array($i, $ignore_params)) {
3234
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3235
-			}
3236
-		}
3237
-	}
3238
-
3239
-	return $texte;
3223
+    $ignore_params = array_merge(
3224
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3225
+        $ignore_params
3226
+    );
3227
+    if (!is_array($env)) {
3228
+        $env = unserialize($env);
3229
+    }
3230
+    $texte = '';
3231
+    if ($env) {
3232
+        foreach ($env as $i => $j) {
3233
+            if (is_string($j) && !in_array($i, $ignore_params)) {
3234
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3235
+            }
3236
+        }
3237
+    }
3238
+
3239
+    return $texte;
3240 3240
 }
3241 3241
 
3242 3242
 /**
@@ -3259,23 +3259,23 @@  discard block
 block discarded – undo
3259 3259
  *      Code HTML résultant
3260 3260
  **/
3261 3261
 function env_to_attributs($env, $ignore_params = []) {
3262
-	$ignore_params = array_merge(
3263
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3264
-		$ignore_params
3265
-	);
3266
-	if (!is_array($env)) {
3267
-		$env = unserialize($env);
3268
-	}
3269
-	$texte = '';
3270
-	if ($env) {
3271
-		foreach ($env as $i => $j) {
3272
-			if (is_string($j) && !in_array($i, $ignore_params)) {
3273
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3274
-			}
3275
-		}
3276
-	}
3262
+    $ignore_params = array_merge(
3263
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3264
+        $ignore_params
3265
+    );
3266
+    if (!is_array($env)) {
3267
+        $env = unserialize($env);
3268
+    }
3269
+    $texte = '';
3270
+    if ($env) {
3271
+        foreach ($env as $i => $j) {
3272
+            if (is_string($j) && !in_array($i, $ignore_params)) {
3273
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3274
+            }
3275
+        }
3276
+    }
3277 3277
 
3278
-	return $texte;
3278
+    return $texte;
3279 3279
 }
3280 3280
 
3281 3281
 
@@ -3293,7 +3293,7 @@  discard block
 block discarded – undo
3293 3293
  * @return string Chaînes concaténés
3294 3294
  **/
3295 3295
 function concat(...$args): string {
3296
-	return implode('', $args);
3296
+    return implode('', $args);
3297 3297
 }
3298 3298
 
3299 3299
 
@@ -3313,23 +3313,23 @@  discard block
 block discarded – undo
3313 3313
  *     Contenu du ou des fichiers, concaténé
3314 3314
  **/
3315 3315
 function charge_scripts($files, $script = true) {
3316
-	$flux = '';
3317
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3318
-		if (!is_string($file)) {
3319
-			continue;
3320
-		}
3321
-		if ($script) {
3322
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3323
-		}
3324
-		if ($file) {
3325
-			$path = find_in_path($file);
3326
-			if ($path) {
3327
-				$flux .= spip_file_get_contents($path);
3328
-			}
3329
-		}
3330
-	}
3331
-
3332
-	return $flux;
3316
+    $flux = '';
3317
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3318
+        if (!is_string($file)) {
3319
+            continue;
3320
+        }
3321
+        if ($script) {
3322
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3323
+        }
3324
+        if ($file) {
3325
+            $path = find_in_path($file);
3326
+            if ($path) {
3327
+                $flux .= spip_file_get_contents($path);
3328
+            }
3329
+        }
3330
+    }
3331
+
3332
+    return $flux;
3333 3333
 }
3334 3334
 
3335 3335
 /**
@@ -3340,24 +3340,24 @@  discard block
 block discarded – undo
3340 3340
  * @return string
3341 3341
  */
3342 3342
 function http_img_variante_svg_si_possible($img_file) {
3343
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3344
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3345
-	if (
3346
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3347
-		&& ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg')
3348
-		&& file_exists($variante_svg_generique)
3349
-	) {
3350
-		if (
3351
-			($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg')
3352
-			&& file_exists($variante_svg_size)
3353
-		) {
3354
-			$img_file = $variante_svg_size;
3355
-		} else {
3356
-			$img_file = $variante_svg_generique;
3357
-		}
3358
-	}
3359
-
3360
-	return $img_file;
3343
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3344
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3345
+    if (
3346
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3347
+        && ($variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg')
3348
+        && file_exists($variante_svg_generique)
3349
+    ) {
3350
+        if (
3351
+            ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg')
3352
+            && file_exists($variante_svg_size)
3353
+        ) {
3354
+            $img_file = $variante_svg_size;
3355
+        } else {
3356
+            $img_file = $variante_svg_generique;
3357
+        }
3358
+    }
3359
+
3360
+    return $img_file;
3361 3361
 }
3362 3362
 
3363 3363
 /**
@@ -3378,51 +3378,51 @@  discard block
 block discarded – undo
3378 3378
  */
3379 3379
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3380 3380
 
3381
-	$img_file = $img;
3382
-	if ($p = strpos($img_file, '?')) {
3383
-		$img_file = substr($img_file, 0, $p);
3384
-	}
3385
-	if (!isset($options['chemin_image']) || $options['chemin_image'] == true) {
3386
-		$img_file = chemin_image($img);
3387
-	}
3388
-	else {
3389
-		if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) {
3390
-			$img_file = http_img_variante_svg_si_possible($img_file);
3391
-		}
3392
-	}
3393
-	if (stripos($atts, 'width') === false) {
3394
-		// utiliser directement l'info de taille presente dans le nom
3395
-		if (
3396
-			(!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg'))
3397
-			&& (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs))
3398
-		) {
3399
-			$largeur = $hauteur = (int) $regs[1];
3400
-		} else {
3401
-			$taille = taille_image($img_file);
3402
-			[$hauteur, $largeur] = $taille;
3403
-			if (!$hauteur || !$largeur) {
3404
-				return '';
3405
-			}
3406
-		}
3407
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3408
-	}
3409
-
3410
-	if (file_exists($img_file)) {
3411
-		$img_file = timestamp($img_file);
3412
-	}
3413
-	if ($alt === false) {
3414
-		$alt = '';
3415
-	}
3416
-	elseif ($alt || $alt === '') {
3417
-		$alt = " alt='" . attribut_html($alt) . "'";
3418
-	}
3419
-	else {
3420
-		$alt = " alt='" . attribut_html($title) . "'";
3421
-	}
3422
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3423
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3424
-	. ' ' . ltrim($atts)
3425
-	. ' />';
3381
+    $img_file = $img;
3382
+    if ($p = strpos($img_file, '?')) {
3383
+        $img_file = substr($img_file, 0, $p);
3384
+    }
3385
+    if (!isset($options['chemin_image']) || $options['chemin_image'] == true) {
3386
+        $img_file = chemin_image($img);
3387
+    }
3388
+    else {
3389
+        if (!isset($options['variante_svg_si_possible']) || $options['variante_svg_si_possible'] == true) {
3390
+            $img_file = http_img_variante_svg_si_possible($img_file);
3391
+        }
3392
+    }
3393
+    if (stripos($atts, 'width') === false) {
3394
+        // utiliser directement l'info de taille presente dans le nom
3395
+        if (
3396
+            (!isset($options['utiliser_suffixe_size']) || $options['utiliser_suffixe_size'] == true || str_contains($img_file, '-xx.svg'))
3397
+            && (preg_match(',-(\d+)[.](png|gif|svg)$,', $img, $regs) || preg_match(',\?(\d+)px$,', $img, $regs))
3398
+        ) {
3399
+            $largeur = $hauteur = (int) $regs[1];
3400
+        } else {
3401
+            $taille = taille_image($img_file);
3402
+            [$hauteur, $largeur] = $taille;
3403
+            if (!$hauteur || !$largeur) {
3404
+                return '';
3405
+            }
3406
+        }
3407
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3408
+    }
3409
+
3410
+    if (file_exists($img_file)) {
3411
+        $img_file = timestamp($img_file);
3412
+    }
3413
+    if ($alt === false) {
3414
+        $alt = '';
3415
+    }
3416
+    elseif ($alt || $alt === '') {
3417
+        $alt = " alt='" . attribut_html($alt) . "'";
3418
+    }
3419
+    else {
3420
+        $alt = " alt='" . attribut_html($title) . "'";
3421
+    }
3422
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3423
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3424
+    . ' ' . ltrim($atts)
3425
+    . ' />';
3426 3426
 }
3427 3427
 
3428 3428
 /**
@@ -3434,70 +3434,70 @@  discard block
 block discarded – undo
3434 3434
  * @return string
3435 3435
  */
3436 3436
 function http_style_background($img, $att = '', $size = null) {
3437
-	if ($size && is_numeric($size)) {
3438
-		$size = trim($size) . 'px';
3439
-	}
3440
-	return " style='background" .
3441
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3442
-		. ($size ? "background-size:{$size};" : '')
3443
-		. "'";
3437
+    if ($size && is_numeric($size)) {
3438
+        $size = trim($size) . 'px';
3439
+    }
3440
+    return " style='background" .
3441
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3442
+        . ($size ? "background-size:{$size};" : '')
3443
+        . "'";
3444 3444
 }
3445 3445
 
3446 3446
 
3447 3447
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3448
-	$args = [$alt_or_size, $class_or_size, $size];
3449
-	while (is_null(end($args)) && count($args)) {
3450
-		array_pop($args);
3451
-	}
3452
-	if ($args === []) {
3453
-		return [null, null, null];
3454
-	}
3455
-	if (count($args) < 3) {
3456
-		$maybe_size = array_pop($args);
3457
-		// @2x
3458
-		// @1.5x
3459
-		// 512
3460
-		// 512x*
3461
-		// 512x300
3462
-		if (
3463
-			!strlen((string) $maybe_size)
3464
-			|| !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim((string) $maybe_size))
3465
-		) {
3466
-			$args[] = $maybe_size;
3467
-			$maybe_size = null;
3468
-		}
3469
-		while (count($args) < 2) {
3470
-			$args[] = null; // default alt or class
3471
-		}
3472
-		$args[] = $maybe_size;
3473
-	}
3474
-	return $args;
3448
+    $args = [$alt_or_size, $class_or_size, $size];
3449
+    while (is_null(end($args)) && count($args)) {
3450
+        array_pop($args);
3451
+    }
3452
+    if ($args === []) {
3453
+        return [null, null, null];
3454
+    }
3455
+    if (count($args) < 3) {
3456
+        $maybe_size = array_pop($args);
3457
+        // @2x
3458
+        // @1.5x
3459
+        // 512
3460
+        // 512x*
3461
+        // 512x300
3462
+        if (
3463
+            !strlen((string) $maybe_size)
3464
+            || !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim((string) $maybe_size))
3465
+        ) {
3466
+            $args[] = $maybe_size;
3467
+            $maybe_size = null;
3468
+        }
3469
+        while (count($args) < 2) {
3470
+            $args[] = null; // default alt or class
3471
+        }
3472
+        $args[] = $maybe_size;
3473
+    }
3474
+    return $args;
3475 3475
 }
3476 3476
 
3477 3477
 function helper_filtre_balise_img_svg_size($img, $size) {
3478
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3479
-	if (str_starts_with((string) $size, '@') && str_ends_with((string) $size, 'x')) {
3480
-		$coef = (float) substr((string) $size, 1, -1);
3481
-		[$h, $w] = taille_image($img);
3482
-		$height = (int) round($h / $coef);
3483
-		$width = (int) round($w / $coef);
3484
-	}
3485
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3486
-	else {
3487
-		$size = explode('x', (string) $size, 2);
3488
-		$size = array_map('trim', $size);
3489
-		$height = $width = (int) array_shift($size);
3490
-
3491
-		if (count($size) && reset($size)) {
3492
-			$height = array_shift($size);
3493
-			if ($height === '*') {
3494
-				[$h, $w] = taille_image($img);
3495
-				$height = (int) round($h * $width / $w);
3496
-			}
3497
-		}
3498
-	}
3499
-
3500
-	return [$width, $height];
3478
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3479
+    if (str_starts_with((string) $size, '@') && str_ends_with((string) $size, 'x')) {
3480
+        $coef = (float) substr((string) $size, 1, -1);
3481
+        [$h, $w] = taille_image($img);
3482
+        $height = (int) round($h / $coef);
3483
+        $width = (int) round($w / $coef);
3484
+    }
3485
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3486
+    else {
3487
+        $size = explode('x', (string) $size, 2);
3488
+        $size = array_map('trim', $size);
3489
+        $height = $width = (int) array_shift($size);
3490
+
3491
+        if (count($size) && reset($size)) {
3492
+            $height = array_shift($size);
3493
+            if ($height === '*') {
3494
+                [$h, $w] = taille_image($img);
3495
+                $height = (int) round($h * $width / $w);
3496
+            }
3497
+        }
3498
+    }
3499
+
3500
+    return [$width, $height];
3501 3501
 }
3502 3502
 
3503 3503
 /**
@@ -3533,38 +3533,38 @@  discard block
 block discarded – undo
3533 3533
  */
3534 3534
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3535 3535
 
3536
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3536
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3537 3537
 
3538
-	$img = trim((string) $img);
3539
-	if (str_starts_with($img, '<img')) {
3540
-		if (!is_null($alt)) {
3541
-			$img = inserer_attribut($img, 'alt', $alt);
3542
-		}
3543
-		if (!is_null($class)) {
3544
-			$img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class');
3545
-		}
3546
-	}
3547
-	else {
3548
-		$img = http_img_pack(
3549
-			$img,
3550
-			$alt,
3551
-			$class ? " class='" . attribut_html($class) . "'" : '',
3552
-			'',
3553
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3554
-		);
3555
-		if (is_null($alt)) {
3556
-			$img = vider_attribut($img, 'alt');
3557
-		}
3558
-	}
3538
+    $img = trim((string) $img);
3539
+    if (str_starts_with($img, '<img')) {
3540
+        if (!is_null($alt)) {
3541
+            $img = inserer_attribut($img, 'alt', $alt);
3542
+        }
3543
+        if (!is_null($class)) {
3544
+            $img = strlen((string) $class) ? inserer_attribut($img, 'class', $class) : vider_attribut($img, 'class');
3545
+        }
3546
+    }
3547
+    else {
3548
+        $img = http_img_pack(
3549
+            $img,
3550
+            $alt,
3551
+            $class ? " class='" . attribut_html($class) . "'" : '',
3552
+            '',
3553
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3554
+        );
3555
+        if (is_null($alt)) {
3556
+            $img = vider_attribut($img, 'alt');
3557
+        }
3558
+    }
3559 3559
 
3560
-	if ($img && !is_null($size) && strlen($size = trim((string) $size))) {
3561
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3560
+    if ($img && !is_null($size) && strlen($size = trim((string) $size))) {
3561
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3562 3562
 
3563
-		$img = inserer_attribut($img, 'width', $width);
3564
-		$img = inserer_attribut($img, 'height', $height);
3565
-	}
3563
+        $img = inserer_attribut($img, 'width', $width);
3564
+        $img = inserer_attribut($img, 'height', $height);
3565
+    }
3566 3566
 
3567
-	return $img;
3567
+    return $img;
3568 3568
 }
3569 3569
 
3570 3570
 
@@ -3598,77 +3598,77 @@  discard block
 block discarded – undo
3598 3598
  */
3599 3599
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3600 3600
 
3601
-	$svg = null;
3602
-	$img = trim($img);
3603
-	$img_file = $img;
3604
-	if (!str_contains($img, '<svg')) {
3605
-		if ($p = strpos($img_file, '?')) {
3606
-			$img_file = substr($img_file, 0, $p);
3607
-		}
3608
-
3609
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3610
-		// la copie locale a toutes les chances d'etre la ou de resservir
3611
-		if (tester_url_absolue($img_file)) {
3612
-			include_spip('inc/distant');
3613
-			$fichier = copie_locale($img_file);
3614
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3615
-		}
3616
-
3617
-		if (
3618
-			!$img_file
3619
-			|| !file_exists($img_file)
3620
-			|| !$svg = file_get_contents($img_file)
3621
-		) {
3622
-			return '';
3623
-		}
3624
-	}
3625
-
3626
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3627
-		return '';
3628
-	}
3629
-
3630
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3631
-
3632
-	$balise_svg = $match[0];
3633
-	$balise_svg_source = $balise_svg;
3634
-
3635
-	// entete XML à supprimer
3636
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg);
3637
-
3638
-	// IE est toujours mon ami
3639
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3640
-
3641
-	// regler la classe
3642
-	if (!is_null($class)) {
3643
-		$balise_svg = strlen((string) $class)
3644
-			? inserer_attribut($balise_svg, 'class', $class)
3645
-			: vider_attribut($balise_svg, 'class');
3646
-	}
3647
-
3648
-	// regler le alt
3649
-	if ($alt) {
3650
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3651
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3652
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3653
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3654
-		$balise_svg .= $title;
3655
-	}
3656
-	else {
3657
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3658
-	}
3659
-
3660
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3661
-
3662
-	if (!is_null($size) && strlen($size = trim((string) $size))) {
3663
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3664
-
3665
-		if (!function_exists('svg_redimensionner')) {
3666
-			include_spip('inc/svg');
3667
-		}
3668
-		$svg = svg_redimensionner($svg, $width, $height);
3669
-	}
3670
-
3671
-	return $svg;
3601
+    $svg = null;
3602
+    $img = trim($img);
3603
+    $img_file = $img;
3604
+    if (!str_contains($img, '<svg')) {
3605
+        if ($p = strpos($img_file, '?')) {
3606
+            $img_file = substr($img_file, 0, $p);
3607
+        }
3608
+
3609
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3610
+        // la copie locale a toutes les chances d'etre la ou de resservir
3611
+        if (tester_url_absolue($img_file)) {
3612
+            include_spip('inc/distant');
3613
+            $fichier = copie_locale($img_file);
3614
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3615
+        }
3616
+
3617
+        if (
3618
+            !$img_file
3619
+            || !file_exists($img_file)
3620
+            || !$svg = file_get_contents($img_file)
3621
+        ) {
3622
+            return '';
3623
+        }
3624
+    }
3625
+
3626
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3627
+        return '';
3628
+    }
3629
+
3630
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3631
+
3632
+    $balise_svg = $match[0];
3633
+    $balise_svg_source = $balise_svg;
3634
+
3635
+    // entete XML à supprimer
3636
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?>,', '', $svg);
3637
+
3638
+    // IE est toujours mon ami
3639
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3640
+
3641
+    // regler la classe
3642
+    if (!is_null($class)) {
3643
+        $balise_svg = strlen((string) $class)
3644
+            ? inserer_attribut($balise_svg, 'class', $class)
3645
+            : vider_attribut($balise_svg, 'class');
3646
+    }
3647
+
3648
+    // regler le alt
3649
+    if ($alt) {
3650
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3651
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3652
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3653
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3654
+        $balise_svg .= $title;
3655
+    }
3656
+    else {
3657
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3658
+    }
3659
+
3660
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3661
+
3662
+    if (!is_null($size) && strlen($size = trim((string) $size))) {
3663
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3664
+
3665
+        if (!function_exists('svg_redimensionner')) {
3666
+            include_spip('inc/svg');
3667
+        }
3668
+        $svg = svg_redimensionner($svg, $width, $height);
3669
+    }
3670
+
3671
+    return $svg;
3672 3672
 }
3673 3673
 
3674 3674
 /**
@@ -3692,37 +3692,37 @@  discard block
 block discarded – undo
3692 3692
  *         - tout : retourne toutes les informations du plugin actif
3693 3693
  **/
3694 3694
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3695
-	include_spip('inc/plugin');
3696
-	$plugin = strtoupper($plugin);
3697
-	$plugins_actifs = liste_plugin_actifs();
3698
-
3699
-	if (!$plugin) {
3700
-		return serialize(array_keys($plugins_actifs));
3701
-	} elseif (empty($plugins_actifs[$plugin]) && !$reload) {
3702
-		return '';
3703
-	} elseif ($type_info == 'est_actif' && !$reload) {
3704
-		return $plugins_actifs[$plugin] ? 1 : 0;
3705
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) {
3706
-		return $plugins_actifs[$plugin][$type_info];
3707
-	} else {
3708
-		$get_infos = charger_fonction('get_infos', 'plugins');
3709
-		// On prend en compte les extensions
3710
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3711
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3712
-		} else {
3713
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3714
-		}
3715
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3716
-			return '';
3717
-		}
3718
-		if ($type_info == 'tout') {
3719
-			return $infos;
3720
-		} elseif ($type_info == 'est_actif') {
3721
-			return $infos ? 1 : 0;
3722
-		} else {
3723
-			return (string) $infos[$type_info];
3724
-		}
3725
-	}
3695
+    include_spip('inc/plugin');
3696
+    $plugin = strtoupper($plugin);
3697
+    $plugins_actifs = liste_plugin_actifs();
3698
+
3699
+    if (!$plugin) {
3700
+        return serialize(array_keys($plugins_actifs));
3701
+    } elseif (empty($plugins_actifs[$plugin]) && !$reload) {
3702
+        return '';
3703
+    } elseif ($type_info == 'est_actif' && !$reload) {
3704
+        return $plugins_actifs[$plugin] ? 1 : 0;
3705
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) && !$reload) {
3706
+        return $plugins_actifs[$plugin][$type_info];
3707
+    } else {
3708
+        $get_infos = charger_fonction('get_infos', 'plugins');
3709
+        // On prend en compte les extensions
3710
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3711
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3712
+        } else {
3713
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3714
+        }
3715
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3716
+            return '';
3717
+        }
3718
+        if ($type_info == 'tout') {
3719
+            return $infos;
3720
+        } elseif ($type_info == 'est_actif') {
3721
+            return $infos ? 1 : 0;
3722
+        } else {
3723
+            return (string) $infos[$type_info];
3724
+        }
3725
+    }
3726 3726
 }
3727 3727
 
3728 3728
 
@@ -3749,9 +3749,9 @@  discard block
 block discarded – undo
3749 3749
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3750 3750
  */
3751 3751
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3752
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3752
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3753 3753
 
3754
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3754
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3755 3755
 }
3756 3756
 
3757 3757
 
@@ -3781,19 +3781,19 @@  discard block
 block discarded – undo
3781 3781
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3782 3782
  */
3783 3783
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3784
-	static $puce_statut = null;
3785
-	if (!$puce_statut) {
3786
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3787
-	}
3784
+    static $puce_statut = null;
3785
+    if (!$puce_statut) {
3786
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3787
+    }
3788 3788
 
3789
-	return $puce_statut(
3790
-		$id_objet,
3791
-		$statut,
3792
-		$id_parent,
3793
-		$objet,
3794
-		false,
3795
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3796
-	);
3789
+    return $puce_statut(
3790
+        $id_objet,
3791
+        $statut,
3792
+        $id_parent,
3793
+        $objet,
3794
+        false,
3795
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3796
+    );
3797 3797
 }
3798 3798
 
3799 3799
 
@@ -3820,94 +3820,94 @@  discard block
 block discarded – undo
3820 3820
  *   hash du contexte
3821 3821
  */
3822 3822
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3823
-	$env = null;
3824
-	if (is_string($c) && @unserialize($c) !== false) {
3825
-		$c = unserialize($c);
3826
-	}
3827
-
3828
-	// supprimer les parametres debut_x
3829
-	// pour que la pagination ajax ne soit pas plantee
3830
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3831
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3832
-	if (is_array($c)) {
3833
-		foreach (array_keys($c) as $k) {
3834
-			if (str_starts_with($k, 'debut_')) {
3835
-				unset($c[$k]);
3836
-			}
3837
-		}
3838
-	}
3839
-
3840
-	if (!function_exists('calculer_cle_action')) {
3841
-		include_spip('inc/securiser_action');
3842
-	}
3843
-
3844
-	$c = serialize($c);
3845
-	$cle = calculer_cle_action($form . $c);
3846
-	$c = "$cle:$c";
3847
-
3848
-	// on ne stocke pas les contextes dans des fichiers en cache
3849
-	// par defaut, sauf si cette configuration a été forcée
3850
-	// OU que la longueur de l’argument géneré est plus long
3851
-	// que ce qui est toléré.
3852
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX);
3853
-	if (!$cache_contextes_ajax) {
3854
-		$env = $c;
3855
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3856
-			$env = gzdeflate($env);
3857
-		}
3858
-		$env = _xor($env);
3859
-		$env = base64_encode($env);
3860
-		$len = strlen($env);
3861
-		// Si l’url est trop longue pour le navigateur
3862
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3863
-		if ($len > $max_len) {
3864
-			$cache_contextes_ajax = true;
3865
-			spip_logger()->warning(
3866
-				'Contextes AJAX forces en fichiers !'
3867
-				. ' Cela arrive lorsque la valeur du contexte'
3868
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3869
-			);
3870
-		}
3871
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3872
-		elseif (
3873
-			($max_len = @ini_get('suhosin.get.max_value_length'))
3874
-			&& $max_len < $len
3875
-		) {
3876
-			$cache_contextes_ajax = true;
3877
-			spip_logger()->warning('Contextes AJAX forces en fichiers !'
3878
-				. ' Cela arrive lorsque la valeur du contexte'
3879
-				. ' depasse la longueur maximale autorisee par Suhosin'
3880
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3881
-				. ' Vous devriez modifier les parametres de Suhosin'
3882
-				. ' pour accepter au moins 1024 caracteres.');
3883
-		}
3884
-	}
3885
-
3886
-	if ($cache_contextes_ajax) {
3887
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3888
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3889
-		$md5 = md5($c);
3890
-		ecrire_fichier("$dir/c$md5", $c);
3891
-		$env = $md5;
3892
-	}
3893
-
3894
-	if ($emboite === null) {
3895
-		return $env;
3896
-	}
3897
-	if (!trim($emboite)) {
3898
-		return '';
3899
-	}
3900
-	// toujours encoder l'url source dans le bloc ajax
3901
-	$r = self();
3902
-	$r = ' data-origin="' . $r . '"';
3903
-	$class = 'ajaxbloc';
3904
-	if ($ajaxid && is_string($ajaxid)) {
3905
-		// ajaxid est normalement conforme a un nom de classe css
3906
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3907
-		$class .= ' ajax-id-' . entites_html($ajaxid);
3908
-	}
3909
-
3910
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3823
+    $env = null;
3824
+    if (is_string($c) && @unserialize($c) !== false) {
3825
+        $c = unserialize($c);
3826
+    }
3827
+
3828
+    // supprimer les parametres debut_x
3829
+    // pour que la pagination ajax ne soit pas plantee
3830
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3831
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3832
+    if (is_array($c)) {
3833
+        foreach (array_keys($c) as $k) {
3834
+            if (str_starts_with($k, 'debut_')) {
3835
+                unset($c[$k]);
3836
+            }
3837
+        }
3838
+    }
3839
+
3840
+    if (!function_exists('calculer_cle_action')) {
3841
+        include_spip('inc/securiser_action');
3842
+    }
3843
+
3844
+    $c = serialize($c);
3845
+    $cle = calculer_cle_action($form . $c);
3846
+    $c = "$cle:$c";
3847
+
3848
+    // on ne stocke pas les contextes dans des fichiers en cache
3849
+    // par defaut, sauf si cette configuration a été forcée
3850
+    // OU que la longueur de l’argument géneré est plus long
3851
+    // que ce qui est toléré.
3852
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX);
3853
+    if (!$cache_contextes_ajax) {
3854
+        $env = $c;
3855
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3856
+            $env = gzdeflate($env);
3857
+        }
3858
+        $env = _xor($env);
3859
+        $env = base64_encode($env);
3860
+        $len = strlen($env);
3861
+        // Si l’url est trop longue pour le navigateur
3862
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3863
+        if ($len > $max_len) {
3864
+            $cache_contextes_ajax = true;
3865
+            spip_logger()->warning(
3866
+                'Contextes AJAX forces en fichiers !'
3867
+                . ' Cela arrive lorsque la valeur du contexte'
3868
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3869
+            );
3870
+        }
3871
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3872
+        elseif (
3873
+            ($max_len = @ini_get('suhosin.get.max_value_length'))
3874
+            && $max_len < $len
3875
+        ) {
3876
+            $cache_contextes_ajax = true;
3877
+            spip_logger()->warning('Contextes AJAX forces en fichiers !'
3878
+                . ' Cela arrive lorsque la valeur du contexte'
3879
+                . ' depasse la longueur maximale autorisee par Suhosin'
3880
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3881
+                . ' Vous devriez modifier les parametres de Suhosin'
3882
+                . ' pour accepter au moins 1024 caracteres.');
3883
+        }
3884
+    }
3885
+
3886
+    if ($cache_contextes_ajax) {
3887
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3888
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3889
+        $md5 = md5($c);
3890
+        ecrire_fichier("$dir/c$md5", $c);
3891
+        $env = $md5;
3892
+    }
3893
+
3894
+    if ($emboite === null) {
3895
+        return $env;
3896
+    }
3897
+    if (!trim($emboite)) {
3898
+        return '';
3899
+    }
3900
+    // toujours encoder l'url source dans le bloc ajax
3901
+    $r = self();
3902
+    $r = ' data-origin="' . $r . '"';
3903
+    $class = 'ajaxbloc';
3904
+    if ($ajaxid && is_string($ajaxid)) {
3905
+        // ajaxid est normalement conforme a un nom de classe css
3906
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
3907
+        $class .= ' ajax-id-' . entites_html($ajaxid);
3908
+    }
3909
+
3910
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3911 3911
 }
3912 3912
 
3913 3913
 /**
@@ -3927,37 +3927,37 @@  discard block
 block discarded – undo
3927 3927
  *   - false : erreur de décodage
3928 3928
  */
3929 3929
 function decoder_contexte_ajax($c, $form = '') {
3930
-	$contexte = null;
3931
-	if (!function_exists('calculer_cle_action')) {
3932
-		include_spip('inc/securiser_action');
3933
-	}
3934
-	if (
3935
-		(defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32)
3936
-		&& ($dir = sous_repertoire(_DIR_CACHE, 'contextes'))
3937
-		&& lire_fichier("$dir/c$c", $contexte)
3938
-	) {
3939
-		$c = $contexte;
3940
-	} else {
3941
-		$c = @base64_decode($c);
3942
-		$c = _xor($c);
3943
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3944
-			$c = @gzinflate($c);
3945
-		}
3946
-	}
3947
-
3948
-	// extraire la signature en debut de contexte
3949
-	// et la verifier avant de deserializer
3950
-	// format : signature:donneesserializees
3951
-	if ($p = strpos((string) $c, ':')) {
3952
-		$cle = substr((string) $c, 0, $p);
3953
-		$c = substr((string) $c, $p + 1);
3954
-
3955
-		if ($cle === calculer_cle_action($form . $c)) {
3956
-			return @unserialize($c);
3957
-		}
3958
-	}
3959
-
3960
-	return false;
3930
+    $contexte = null;
3931
+    if (!function_exists('calculer_cle_action')) {
3932
+        include_spip('inc/securiser_action');
3933
+    }
3934
+    if (
3935
+        (defined('_CACHE_CONTEXTES_AJAX') && _CACHE_CONTEXTES_AJAX || strlen($c) == 32)
3936
+        && ($dir = sous_repertoire(_DIR_CACHE, 'contextes'))
3937
+        && lire_fichier("$dir/c$c", $contexte)
3938
+    ) {
3939
+        $c = $contexte;
3940
+    } else {
3941
+        $c = @base64_decode($c);
3942
+        $c = _xor($c);
3943
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3944
+            $c = @gzinflate($c);
3945
+        }
3946
+    }
3947
+
3948
+    // extraire la signature en debut de contexte
3949
+    // et la verifier avant de deserializer
3950
+    // format : signature:donneesserializees
3951
+    if ($p = strpos((string) $c, ':')) {
3952
+        $cle = substr((string) $c, 0, $p);
3953
+        $c = substr((string) $c, $p + 1);
3954
+
3955
+        if ($cle === calculer_cle_action($form . $c)) {
3956
+            return @unserialize($c);
3957
+        }
3958
+    }
3959
+
3960
+    return false;
3961 3961
 }
3962 3962
 
3963 3963
 
@@ -3975,20 +3975,20 @@  discard block
 block discarded – undo
3975 3975
  *    Message décrypté ou encrypté
3976 3976
  **/
3977 3977
 function _xor($message, $key = null) {
3978
-	if (is_null($key)) {
3979
-		if (!function_exists('calculer_cle_action')) {
3980
-			include_spip('inc/securiser_action');
3981
-		}
3982
-		$key = pack('H*', calculer_cle_action('_xor'));
3983
-	}
3978
+    if (is_null($key)) {
3979
+        if (!function_exists('calculer_cle_action')) {
3980
+            include_spip('inc/securiser_action');
3981
+        }
3982
+        $key = pack('H*', calculer_cle_action('_xor'));
3983
+    }
3984 3984
 
3985
-	$keylen = strlen($key);
3986
-	$messagelen = strlen($message);
3987
-	for ($i = 0; $i < $messagelen; $i++) {
3988
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3989
-	}
3985
+    $keylen = strlen($key);
3986
+    $messagelen = strlen($message);
3987
+    for ($i = 0; $i < $messagelen; $i++) {
3988
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
3989
+    }
3990 3990
 
3991
-	return $message;
3991
+    return $message;
3992 3992
 }
3993 3993
 
3994 3994
 /**
@@ -4002,7 +4002,7 @@  discard block
 block discarded – undo
4002 4002
  * @return string
4003 4003
  */
4004 4004
 function url_reponse_forum($texte) {
4005
- return $texte;
4005
+    return $texte;
4006 4006
 }
4007 4007
 
4008 4008
 /**
@@ -4016,7 +4016,7 @@  discard block
 block discarded – undo
4016 4016
  * @return string
4017 4017
  */
4018 4018
 function url_rss_forum($texte) {
4019
- return $texte;
4019
+    return $texte;
4020 4020
 }
4021 4021
 
4022 4022
 
@@ -4055,37 +4055,37 @@  discard block
 block discarded – undo
4055 4055
  *   Code HTML
4056 4056
  */
4057 4057
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4058
-	if ($on) {
4059
-		$bal = 'strong';
4060
-		$class = '';
4061
-		$att = '';
4062
-		// si $on passe la balise et optionnelement une ou ++classe
4063
-		// a.active span.selected.active etc....
4064
-		if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) {
4065
-			$on = explode('.', $on);
4066
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4067
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4068
-				$bal = array_shift($on);
4069
-				$class = implode(' ', $on);
4070
-				if ($bal == 'a') {
4071
-					$att = 'href="#" ';
4072
-				}
4073
-			}
4074
-		}
4075
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4076
-	} else {
4077
-		$bal = 'a';
4078
-		$att = "href='$url'"
4079
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4080
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4081
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4082
-			. $evt;
4083
-	}
4084
-	if ($libelle === null) {
4085
-		$libelle = $url;
4086
-	}
4087
-
4088
-	return "<$bal $att>$libelle</$bal>";
4058
+    if ($on) {
4059
+        $bal = 'strong';
4060
+        $class = '';
4061
+        $att = '';
4062
+        // si $on passe la balise et optionnelement une ou ++classe
4063
+        // a.active span.selected.active etc....
4064
+        if (is_string($on) && (str_starts_with($on, 'a') || str_starts_with($on, 'span') || str_starts_with($on, 'strong'))) {
4065
+            $on = explode('.', $on);
4066
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4067
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4068
+                $bal = array_shift($on);
4069
+                $class = implode(' ', $on);
4070
+                if ($bal == 'a') {
4071
+                    $att = 'href="#" ';
4072
+                }
4073
+            }
4074
+        }
4075
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4076
+    } else {
4077
+        $bal = 'a';
4078
+        $att = "href='$url'"
4079
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4080
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4081
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4082
+            . $evt;
4083
+    }
4084
+    if ($libelle === null) {
4085
+        $libelle = $url;
4086
+    }
4087
+
4088
+    return "<$bal $att>$libelle</$bal>";
4089 4089
 }
4090 4090
 
4091 4091
 
@@ -4102,39 +4102,39 @@  discard block
 block discarded – undo
4102 4102
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4103 4103
  */
4104 4104
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4105
-	static $local_singulier_ou_pluriel = [];
4106
-
4107
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4108
-	if (!is_numeric($nb) || $nb == 0) {
4109
-		return '';
4110
-	}
4111
-	if (!is_array($vars)) {
4112
-		return '';
4113
-	}
4114
-
4115
-	$langue = $GLOBALS['spip_lang'];
4116
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4117
-		$local_singulier_ou_pluriel[$langue] = false;
4118
-		if (
4119
-			($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true))
4120
-			|| ($f = charger_fonction('singulier_ou_pluriel', 'inc', true))
4121
-		) {
4122
-			$local_singulier_ou_pluriel[$langue] = $f;
4123
-		}
4124
-	}
4125
-
4126
-	// si on a une surcharge on l'utilise
4127
-	if ($local_singulier_ou_pluriel[$langue]) {
4128
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4129
-	}
4130
-
4131
-	// sinon traitement par defaut
4132
-	$vars[$var] = $nb;
4133
-	if ($nb >= 2) {
4134
-		return _T($chaine_plusieurs, $vars);
4135
-	} else {
4136
-		return _T($chaine_un, $vars);
4137
-	}
4105
+    static $local_singulier_ou_pluriel = [];
4106
+
4107
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4108
+    if (!is_numeric($nb) || $nb == 0) {
4109
+        return '';
4110
+    }
4111
+    if (!is_array($vars)) {
4112
+        return '';
4113
+    }
4114
+
4115
+    $langue = $GLOBALS['spip_lang'];
4116
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4117
+        $local_singulier_ou_pluriel[$langue] = false;
4118
+        if (
4119
+            ($f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true))
4120
+            || ($f = charger_fonction('singulier_ou_pluriel', 'inc', true))
4121
+        ) {
4122
+            $local_singulier_ou_pluriel[$langue] = $f;
4123
+        }
4124
+    }
4125
+
4126
+    // si on a une surcharge on l'utilise
4127
+    if ($local_singulier_ou_pluriel[$langue]) {
4128
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4129
+    }
4130
+
4131
+    // sinon traitement par defaut
4132
+    $vars[$var] = $nb;
4133
+    if ($nb >= 2) {
4134
+        return _T($chaine_plusieurs, $vars);
4135
+    } else {
4136
+        return _T($chaine_un, $vars);
4137
+    }
4138 4138
 }
4139 4139
 
4140 4140
 
@@ -4162,71 +4162,71 @@  discard block
 block discarded – undo
4162 4162
  */
4163 4163
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4164 4164
 
4165
-	$class_lien = $class_bouton = $class;
4166
-
4167
-	// Normaliser la fonction et compléter la classe en fonction
4168
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4169
-		$class_lien .= ' danger';
4170
-		$class_bouton .= ' btn_danger';
4171
-	} elseif ($fonction == 'rien.gif') {
4172
-		$fonction = '';
4173
-	} elseif ($fonction == 'delsafe') {
4174
-		$fonction = 'del';
4175
-	}
4176
-
4177
-	$fond_origine = $fond;
4178
-	// Remappage des icone : article-24.png+new => article-new-24.png
4179
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4180
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4181
-	}
4182
-
4183
-	// Ajouter le type d'objet dans la classe
4184
-	$objet_type = substr(basename((string) $fond), 0, -4);
4185
-	$class_lien .= " $objet_type";
4186
-	$class_bouton .= " $objet_type";
4187
-
4188
-	// texte
4189
-	$alt = attribut_html($texte);
4190
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4191
-
4192
-	// Liens : préparer les classes ajax
4193
-	$ajax = '';
4194
-	if ($type === 'lien' && str_contains($class_lien, 'ajax')) {
4195
-		$ajax = 'ajax';
4196
-		if (str_contains($class_lien, 'preload')) {
4197
-			$ajax .= ' preload';
4198
-		}
4199
-		if (str_contains($class_lien, 'nocache')) {
4200
-			$ajax .= ' nocache';
4201
-		}
4202
-		$ajax = " class='$ajax'";
4203
-	}
4204
-
4205
-	// Repérer la taille et l'ajouter dans la classe
4206
-	$size = 24;
4207
-	if (
4208
-		preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', (string) $fond, $match)
4209
-		|| preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4210
-	) {
4211
-		$size = $match[1];
4212
-	}
4213
-	$class_lien .= " s$size";
4214
-	$class_bouton .= " s$size";
4215
-
4216
-	// Icône
4217
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4218
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4219
-
4220
-	// Markup final
4221
-	if ($type == 'lien') {
4222
-		return "<span class='icone $class_lien'>"
4223
-		. "<a href='$lien'$title$ajax$javascript>"
4224
-		. $icone
4225
-		. "<b>$texte</b>"
4226
-		. "</a></span>\n";
4227
-	} else {
4228
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4229
-	}
4165
+    $class_lien = $class_bouton = $class;
4166
+
4167
+    // Normaliser la fonction et compléter la classe en fonction
4168
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4169
+        $class_lien .= ' danger';
4170
+        $class_bouton .= ' btn_danger';
4171
+    } elseif ($fonction == 'rien.gif') {
4172
+        $fonction = '';
4173
+    } elseif ($fonction == 'delsafe') {
4174
+        $fonction = 'del';
4175
+    }
4176
+
4177
+    $fond_origine = $fond;
4178
+    // Remappage des icone : article-24.png+new => article-new-24.png
4179
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4180
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4181
+    }
4182
+
4183
+    // Ajouter le type d'objet dans la classe
4184
+    $objet_type = substr(basename((string) $fond), 0, -4);
4185
+    $class_lien .= " $objet_type";
4186
+    $class_bouton .= " $objet_type";
4187
+
4188
+    // texte
4189
+    $alt = attribut_html($texte);
4190
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4191
+
4192
+    // Liens : préparer les classes ajax
4193
+    $ajax = '';
4194
+    if ($type === 'lien' && str_contains($class_lien, 'ajax')) {
4195
+        $ajax = 'ajax';
4196
+        if (str_contains($class_lien, 'preload')) {
4197
+            $ajax .= ' preload';
4198
+        }
4199
+        if (str_contains($class_lien, 'nocache')) {
4200
+            $ajax .= ' nocache';
4201
+        }
4202
+        $ajax = " class='$ajax'";
4203
+    }
4204
+
4205
+    // Repérer la taille et l'ajouter dans la classe
4206
+    $size = 24;
4207
+    if (
4208
+        preg_match('/-(\d{1,3})[.](gif|png|svg)$/i', (string) $fond, $match)
4209
+        || preg_match('/-(\d{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4210
+    ) {
4211
+        $size = $match[1];
4212
+    }
4213
+    $class_lien .= " s$size";
4214
+    $class_bouton .= " s$size";
4215
+
4216
+    // Icône
4217
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4218
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4219
+
4220
+    // Markup final
4221
+    if ($type == 'lien') {
4222
+        return "<span class='icone $class_lien'>"
4223
+        . "<a href='$lien'$title$ajax$javascript>"
4224
+        . $icone
4225
+        . "<b>$texte</b>"
4226
+        . "</a></span>\n";
4227
+    } else {
4228
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4229
+    }
4230 4230
 }
4231 4231
 
4232 4232
 /**
@@ -4250,7 +4250,7 @@  discard block
 block discarded – undo
4250 4250
  *     Code HTML du lien
4251 4251
  **/
4252 4252
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4253
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4253
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4254 4254
 }
4255 4255
 
4256 4256
 /**
@@ -4285,7 +4285,7 @@  discard block
 block discarded – undo
4285 4285
  *     Code HTML du lien
4286 4286
  **/
4287 4287
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4288
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4288
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4289 4289
 }
4290 4290
 
4291 4291
 /**
@@ -4330,7 +4330,7 @@  discard block
 block discarded – undo
4330 4330
  *     Code HTML du lien
4331 4331
  **/
4332 4332
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4333
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4333
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4334 4334
 }
4335 4335
 
4336 4336
 /**
@@ -4361,7 +4361,7 @@  discard block
 block discarded – undo
4361 4361
  *     Code HTML du lien
4362 4362
  **/
4363 4363
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4364
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4364
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4365 4365
 }
4366 4366
 
4367 4367
 /**
@@ -4382,7 +4382,7 @@  discard block
 block discarded – undo
4382 4382
  * @return array Liste des éléments
4383 4383
  */
4384 4384
 function filtre_explode_dist($a, $b) {
4385
-	return explode($b, (string) $a);
4385
+    return explode($b, (string) $a);
4386 4386
 }
4387 4387
 
4388 4388
 /**
@@ -4403,7 +4403,7 @@  discard block
 block discarded – undo
4403 4403
  * @return string texte
4404 4404
  */
4405 4405
 function filtre_implode_dist($a, $b) {
4406
-	return is_array($a) ? implode($b, $a) : $a;
4406
+    return is_array($a) ? implode($b, $a) : $a;
4407 4407
 }
4408 4408
 
4409 4409
 /**
@@ -4412,22 +4412,22 @@  discard block
 block discarded – undo
4412 4412
  * @return string Code CSS
4413 4413
  */
4414 4414
 function bando_images_background() {
4415
-	include_spip('inc/bandeau');
4416
-	// recuperer tous les boutons et leurs images
4417
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4415
+    include_spip('inc/bandeau');
4416
+    // recuperer tous les boutons et leurs images
4417
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4418 4418
 
4419
-	$res = '';
4420
-	foreach ($boutons as $page => $detail) {
4421
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4422
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4423
-			if ($sousdetail->icone && strlen(trim((string) $sousdetail->icone))) {
4424
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4425
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4426
-			}
4427
-		}
4428
-	}
4419
+    $res = '';
4420
+    foreach ($boutons as $page => $detail) {
4421
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4422
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4423
+            if ($sousdetail->icone && strlen(trim((string) $sousdetail->icone))) {
4424
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4425
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4426
+            }
4427
+        }
4428
+    }
4429 4429
 
4430
-	return $res;
4430
+    return $res;
4431 4431
 }
4432 4432
 
4433 4433
 /**
@@ -4452,23 +4452,23 @@  discard block
 block discarded – undo
4452 4452
  */
4453 4453
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4454 4454
 
4455
-	// Classes : dispatcher `ajax` sur le formulaire
4456
-	$class_form = '';
4457
-	if (str_contains($class, 'ajax')) {
4458
-		$class_form = 'ajax';
4459
-		$class = str_replace('ajax', '', $class);
4460
-	}
4461
-	$class_btn = 'submit ' . trim($class);
4455
+    // Classes : dispatcher `ajax` sur le formulaire
4456
+    $class_form = '';
4457
+    if (str_contains($class, 'ajax')) {
4458
+        $class_form = 'ajax';
4459
+        $class = str_replace('ajax', '', $class);
4460
+    }
4461
+    $class_btn = 'submit ' . trim($class);
4462 4462
 
4463
-	if ($confirm) {
4464
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4465
-		$callback = $callback ? "$confirm?($callback):false" : $confirm;
4466
-	}
4467
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4468
-	$title = $title ? " title='$title'" : '';
4463
+    if ($confirm) {
4464
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4465
+        $callback = $callback ? "$confirm?($callback):false" : $confirm;
4466
+    }
4467
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4468
+    $title = $title ? " title='$title'" : '';
4469 4469
 
4470
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4471
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4470
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4471
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4472 4472
 }
4473 4473
 
4474 4474
 /**
@@ -4491,109 +4491,109 @@  discard block
 block discarded – undo
4491 4491
  * @return string
4492 4492
  */
4493 4493
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4494
-	static $trouver_table = null;
4495
-	static $objets;
4496
-
4497
-	// On verifie qu'on a tout ce qu'il faut
4498
-	$id_objet = (int) $id_objet;
4499
-	if (!($id_objet && $type_objet && $info)) {
4500
-		return '';
4501
-	}
4502
-
4503
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4504
-	if (isset($objets[$type_objet]) && $objets[$type_objet] === false) {
4505
-		return '';
4506
-	}
4507
-
4508
-	// Si on demande l'url, on retourne direct la fonction
4509
-	if ($info == 'url') {
4510
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4511
-	}
4512
-
4513
-	// Sinon on va tout chercher dans la table et on garde en memoire
4514
-	$demande_titre = ($info === 'titre');
4515
-	$demande_introduction = ($info === 'introduction');
4516
-
4517
-	// On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4518
-	if (
4519
-		!isset($objets[$type_objet][$id_objet])
4520
-		|| $demande_titre && !isset($objets[$type_objet][$id_objet]['titre'])
4521
-	) {
4522
-		if (!$trouver_table) {
4523
-			$trouver_table = charger_fonction('trouver_table', 'base');
4524
-		}
4525
-		$desc = $trouver_table(table_objet_sql($type_objet));
4526
-		if (!$desc) {
4527
-			return $objets[$type_objet] = false;
4528
-		}
4529
-		// eviter les fuites memoires en cas d'appel répété par un cli...
4530
-		if (!empty($objets[$type_objet]) && (count($objets[$type_objet]) > 1000)) {
4531
-			$oldest = array_key_first($objets[$type_objet]);
4532
-			unset($objets[$type_objet][$oldest]);
4533
-		}
4534
-
4535
-		// Si on demande le titre, on le gere en interne
4536
-		$champ_titre = '';
4537
-		if ($demande_titre) {
4538
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4539
-			$champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre'];
4540
-		}
4541
-		include_spip('base/abstract_sql');
4542
-		include_spip('base/connect_sql');
4543
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4544
-			'*' . $champ_titre,
4545
-			$desc['table_sql'],
4546
-			id_table_objet($type_objet) . ' = ' . (int) $id_objet
4547
-		);
4548
-
4549
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4550
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4551
-	}
4552
-
4553
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4554
-	// ajouter la longueur au début des params supplémentaires
4555
-	if ($demande_introduction) {
4556
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4557
-		array_unshift($params, $introduction_longueur);
4558
-	}
4559
-
4560
-	$row = ($objets[$type_objet][$id_objet] ?? []) ?: [];
4561
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4562
-	if ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) {
4563
-		$info_generee = $generer($id_objet, $row, ...$params);
4564
-	}
4565
-	// @deprecated 4.1 generer_TRUC_TYPE
4566
-	elseif ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) {
4567
-		trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_{$type_objet}", "generer_{$type_objet}_{$info}");
4568
-		$info_generee = $generer($id_objet, $row, ...$params);
4569
-	}
4570
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4571
-	elseif ($generer = charger_fonction("generer_objet_{$info}", '', true)) {
4572
-		$info_generee = $generer($id_objet, $type_objet, $row, ...$params);
4573
-	}
4574
-	// @deprecated 4.1 generer_TRUC_entite
4575
-	elseif ($generer = charger_fonction("generer_{$info}_entite", '', true)) {
4576
-		trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_entite", "generer_objet_{$info}");
4577
-		$info_generee = $generer($id_objet, $type_objet, $row, ...$params);
4578
-	}
4579
-	// Sinon on prend directement le champ SQL tel quel
4580
-	else {
4581
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4582
-	}
4583
-
4584
-	// On va ensuite appliquer les traitements automatiques si besoin
4585
-	if (!$etoile) {
4586
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4587
-		// mais ce fonctionnement est a ameliorer !
4588
-		$info_generee = appliquer_traitement_champ(
4589
-			$info_generee,
4590
-			$info,
4591
-			table_objet($type_objet),
4592
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4593
-		);
4594
-	}
4595
-
4596
-	return $info_generee;
4494
+    static $trouver_table = null;
4495
+    static $objets;
4496
+
4497
+    // On verifie qu'on a tout ce qu'il faut
4498
+    $id_objet = (int) $id_objet;
4499
+    if (!($id_objet && $type_objet && $info)) {
4500
+        return '';
4501
+    }
4502
+
4503
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4504
+    if (isset($objets[$type_objet]) && $objets[$type_objet] === false) {
4505
+        return '';
4506
+    }
4507
+
4508
+    // Si on demande l'url, on retourne direct la fonction
4509
+    if ($info == 'url') {
4510
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4511
+    }
4512
+
4513
+    // Sinon on va tout chercher dans la table et on garde en memoire
4514
+    $demande_titre = ($info === 'titre');
4515
+    $demande_introduction = ($info === 'introduction');
4516
+
4517
+    // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore
4518
+    if (
4519
+        !isset($objets[$type_objet][$id_objet])
4520
+        || $demande_titre && !isset($objets[$type_objet][$id_objet]['titre'])
4521
+    ) {
4522
+        if (!$trouver_table) {
4523
+            $trouver_table = charger_fonction('trouver_table', 'base');
4524
+        }
4525
+        $desc = $trouver_table(table_objet_sql($type_objet));
4526
+        if (!$desc) {
4527
+            return $objets[$type_objet] = false;
4528
+        }
4529
+        // eviter les fuites memoires en cas d'appel répété par un cli...
4530
+        if (!empty($objets[$type_objet]) && (count($objets[$type_objet]) > 1000)) {
4531
+            $oldest = array_key_first($objets[$type_objet]);
4532
+            unset($objets[$type_objet][$oldest]);
4533
+        }
4534
+
4535
+        // Si on demande le titre, on le gere en interne
4536
+        $champ_titre = '';
4537
+        if ($demande_titre) {
4538
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4539
+            $champ_titre = (empty($desc['titre'])) ? '' : ', ' . $desc['titre'];
4540
+        }
4541
+        include_spip('base/abstract_sql');
4542
+        include_spip('base/connect_sql');
4543
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4544
+            '*' . $champ_titre,
4545
+            $desc['table_sql'],
4546
+            id_table_objet($type_objet) . ' = ' . (int) $id_objet
4547
+        );
4548
+
4549
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4550
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4551
+    }
4552
+
4553
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4554
+    // ajouter la longueur au début des params supplémentaires
4555
+    if ($demande_introduction) {
4556
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4557
+        array_unshift($params, $introduction_longueur);
4558
+    }
4559
+
4560
+    $row = ($objets[$type_objet][$id_objet] ?? []) ?: [];
4561
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4562
+    if ($generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)) {
4563
+        $info_generee = $generer($id_objet, $row, ...$params);
4564
+    }
4565
+    // @deprecated 4.1 generer_TRUC_TYPE
4566
+    elseif ($generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)) {
4567
+        trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_{$type_objet}", "generer_{$type_objet}_{$info}");
4568
+        $info_generee = $generer($id_objet, $row, ...$params);
4569
+    }
4570
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4571
+    elseif ($generer = charger_fonction("generer_objet_{$info}", '', true)) {
4572
+        $info_generee = $generer($id_objet, $type_objet, $row, ...$params);
4573
+    }
4574
+    // @deprecated 4.1 generer_TRUC_entite
4575
+    elseif ($generer = charger_fonction("generer_{$info}_entite", '', true)) {
4576
+        trigger_deprecation('spip', '4.1', 'Using "%s" function naming is deprecated, rename "%s" instead', "generer_{$info}_entite", "generer_objet_{$info}");
4577
+        $info_generee = $generer($id_objet, $type_objet, $row, ...$params);
4578
+    }
4579
+    // Sinon on prend directement le champ SQL tel quel
4580
+    else {
4581
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4582
+    }
4583
+
4584
+    // On va ensuite appliquer les traitements automatiques si besoin
4585
+    if (!$etoile) {
4586
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4587
+        // mais ce fonctionnement est a ameliorer !
4588
+        $info_generee = appliquer_traitement_champ(
4589
+            $info_generee,
4590
+            $info,
4591
+            table_objet($type_objet),
4592
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4593
+        );
4594
+    }
4595
+
4596
+    return $info_generee;
4597 4597
 }
4598 4598
 
4599 4599
 /**
@@ -4626,34 +4626,34 @@  discard block
 block discarded – undo
4626 4626
  */
4627 4627
 function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string {
4628 4628
 
4629
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4630
-	$texte = $ligne_sql['texte'] ?? '';
4631
-	// En absence de descriptif, on se rabat sur chapo + texte
4632
-	if (isset($ligne_sql['chapo'])) {
4633
-		$chapo = $ligne_sql['chapo'];
4634
-		$texte = strlen((string) $descriptif) ?
4635
-			'' :
4636
-			"$chapo \n\n $texte";
4637
-	}
4629
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4630
+    $texte = $ligne_sql['texte'] ?? '';
4631
+    // En absence de descriptif, on se rabat sur chapo + texte
4632
+    if (isset($ligne_sql['chapo'])) {
4633
+        $chapo = $ligne_sql['chapo'];
4634
+        $texte = strlen((string) $descriptif) ?
4635
+            '' :
4636
+            "$chapo \n\n $texte";
4637
+    }
4638 4638
 
4639
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4640
-	if (!(int) $longueur_ou_suite) {
4641
-		$longueur = (int) ($introduction_longueur ?: 600);
4642
-	} else {
4643
-		$longueur = (int) $longueur_ou_suite;
4644
-	}
4639
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4640
+    if (!(int) $longueur_ou_suite) {
4641
+        $longueur = (int) ($introduction_longueur ?: 600);
4642
+    } else {
4643
+        $longueur = (int) $longueur_ou_suite;
4644
+    }
4645 4645
 
4646
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4647
-	// Ex : #INTRODUCTION{...}
4648
-	if (
4649
-		is_null($suite) && !(int) $longueur_ou_suite
4650
-	) {
4651
-		$suite = $longueur_ou_suite;
4652
-	}
4646
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4647
+    // Ex : #INTRODUCTION{...}
4648
+    if (
4649
+        is_null($suite) && !(int) $longueur_ou_suite
4650
+    ) {
4651
+        $suite = $longueur_ou_suite;
4652
+    }
4653 4653
 
4654
-	$f = chercher_filtre('introduction');
4654
+    $f = chercher_filtre('introduction');
4655 4655
 
4656
-	return $f($descriptif, $texte, $longueur, $connect, $suite);
4656
+    return $f($descriptif, $texte, $longueur, $connect, $suite);
4657 4657
 }
4658 4658
 
4659 4659
 /**
@@ -4666,49 +4666,49 @@  discard block
 block discarded – undo
4666 4666
  * @return string
4667 4667
  */
4668 4668
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4669
-	if (!$champ) {
4670
-		return $texte;
4671
-	}
4669
+    if (!$champ) {
4670
+        return $texte;
4671
+    }
4672 4672
 
4673
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4674
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4675
-	include_fichiers_fonctions();
4673
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4674
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4675
+    include_fichiers_fonctions();
4676 4676
 
4677
-	$champ = strtoupper($champ);
4678
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4679
-	if (!$traitements || !is_array($traitements)) {
4680
-		return $texte;
4681
-	}
4677
+    $champ = strtoupper($champ);
4678
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4679
+    if (!$traitements || !is_array($traitements)) {
4680
+        return $texte;
4681
+    }
4682 4682
 
4683
-	$traitement = '';
4684
-	if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) {
4685
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4686
-		$table_objet = table_objet($table_objet);
4687
-		if (isset($traitements[$table_objet])) {
4688
-			$traitement = $traitements[$table_objet];
4689
-		}
4690
-	}
4691
-	if (!$traitement && isset($traitements[0])) {
4692
-		$traitement = $traitements[0];
4693
-	}
4694
-	// (sinon prendre le premier de la liste par defaut ?)
4683
+    $traitement = '';
4684
+    if ($table_objet && (!isset($traitements[0]) || count($traitements) > 1)) {
4685
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4686
+        $table_objet = table_objet($table_objet);
4687
+        if (isset($traitements[$table_objet])) {
4688
+            $traitement = $traitements[$table_objet];
4689
+        }
4690
+    }
4691
+    if (!$traitement && isset($traitements[0])) {
4692
+        $traitement = $traitements[0];
4693
+    }
4694
+    // (sinon prendre le premier de la liste par defaut ?)
4695 4695
 
4696
-	if (!$traitement) {
4697
-		return $texte;
4698
-	}
4696
+    if (!$traitement) {
4697
+        return $texte;
4698
+    }
4699 4699
 
4700
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement);
4700
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", (string) $traitement);
4701 4701
 
4702
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4703
-	if (test_espace_prive()) {
4704
-		$env['espace_prive'] = 1;
4705
-	}
4702
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4703
+    if (test_espace_prive()) {
4704
+        $env['espace_prive'] = 1;
4705
+    }
4706 4706
 
4707
-	// Fournir $connect et $Pile[0] au traitement si besoin
4708
-	$Pile = [0 => $env];
4709
-	eval("\$texte = $traitement;");
4707
+    // Fournir $connect et $Pile[0] au traitement si besoin
4708
+    $Pile = [0 => $env];
4709
+    eval("\$texte = $traitement;");
4710 4710
 
4711
-	return $texte;
4711
+    return $texte;
4712 4712
 }
4713 4713
 
4714 4714
 
@@ -4719,21 +4719,21 @@  discard block
 block discarded – undo
4719 4719
  * @return string
4720 4720
  */
4721 4721
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4722
-	include_spip('inc/liens');
4723
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4724
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4725
-	// le raccourcis n'est plus valide
4726
-	$titre = typo($titre['titre'] ?? '');
4727
-	// on essaye avec generer_objet_info ?
4728
-	if (!strlen($titre) && !$connect) {
4729
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4730
-	}
4731
-	if (!strlen($titre)) {
4732
-		$titre = _T('info_sans_titre');
4733
-	}
4734
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4722
+    include_spip('inc/liens');
4723
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4724
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4725
+    // le raccourcis n'est plus valide
4726
+    $titre = typo($titre['titre'] ?? '');
4727
+    // on essaye avec generer_objet_info ?
4728
+    if (!strlen($titre) && !$connect) {
4729
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4730
+    }
4731
+    if (!strlen($titre)) {
4732
+        $titre = _T('info_sans_titre');
4733
+    }
4734
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4735 4735
 
4736
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4736
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4737 4737
 }
4738 4738
 
4739 4739
 /**
@@ -4749,15 +4749,15 @@  discard block
 block discarded – undo
4749 4749
  * @return string
4750 4750
  */
4751 4751
 function wrap($texte, $wrap) {
4752
-	$balises = extraire_balises($wrap);
4753
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4754
-		$texte = $wrap . $texte;
4755
-		$regs = array_reverse($regs[1]);
4756
-		$wrap = '</' . implode('></', $regs) . '>';
4757
-		$texte .= $wrap;
4758
-	}
4752
+    $balises = extraire_balises($wrap);
4753
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4754
+        $texte = $wrap . $texte;
4755
+        $regs = array_reverse($regs[1]);
4756
+        $wrap = '</' . implode('></', $regs) . '>';
4757
+        $texte .= $wrap;
4758
+    }
4759 4759
 
4760
-	return $texte;
4760
+    return $texte;
4761 4761
 }
4762 4762
 
4763 4763
 
@@ -4777,42 +4777,42 @@  discard block
 block discarded – undo
4777 4777
  * @return array|mixed|string
4778 4778
  */
4779 4779
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4780
-	if (is_string($u)) {
4781
-		return typo($u);
4782
-	}
4783
-
4784
-	// caster $u en array si besoin
4785
-	if (is_object($u)) {
4786
-		$u = (array)$u;
4787
-	}
4788
-
4789
-	if (is_array($u)) {
4790
-		$out = '';
4791
-		// toutes les cles sont numeriques ?
4792
-		// et aucun enfant n'est un tableau
4793
-		// liste simple separee par des virgules
4794
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4795
-		$array_values = array_map('is_array', $u);
4796
-		$object_values = array_map('is_object', $u);
4797
-		if (
4798
-			array_sum($numeric_keys) == count($numeric_keys)
4799
-			&& !array_sum($array_values)
4800
-			&& !array_sum($object_values)
4801
-		) {
4802
-			return implode(', ', array_map('filtre_print_dist', $u));
4803
-		}
4804
-
4805
-		// sinon on passe a la ligne et on indente
4806
-		$i_str = str_pad('', $indent, ' ');
4807
-		foreach ($u as $k => $v) {
4808
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4809
-		}
4810
-
4811
-		return $out;
4812
-	}
4813
-
4814
-	// on sait pas quoi faire...
4815
-	return $u;
4780
+    if (is_string($u)) {
4781
+        return typo($u);
4782
+    }
4783
+
4784
+    // caster $u en array si besoin
4785
+    if (is_object($u)) {
4786
+        $u = (array)$u;
4787
+    }
4788
+
4789
+    if (is_array($u)) {
4790
+        $out = '';
4791
+        // toutes les cles sont numeriques ?
4792
+        // et aucun enfant n'est un tableau
4793
+        // liste simple separee par des virgules
4794
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4795
+        $array_values = array_map('is_array', $u);
4796
+        $object_values = array_map('is_object', $u);
4797
+        if (
4798
+            array_sum($numeric_keys) == count($numeric_keys)
4799
+            && !array_sum($array_values)
4800
+            && !array_sum($object_values)
4801
+        ) {
4802
+            return implode(', ', array_map('filtre_print_dist', $u));
4803
+        }
4804
+
4805
+        // sinon on passe a la ligne et on indente
4806
+        $i_str = str_pad('', $indent, ' ');
4807
+        foreach ($u as $k => $v) {
4808
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4809
+        }
4810
+
4811
+        return $out;
4812
+    }
4813
+
4814
+    // on sait pas quoi faire...
4815
+    return $u;
4816 4816
 }
4817 4817
 
4818 4818
 
@@ -4825,10 +4825,10 @@  discard block
 block discarded – undo
4825 4825
  * @return string|array
4826 4826
  */
4827 4827
 function objet_info($objet, $info) {
4828
-	$table = table_objet_sql($objet);
4829
-	$infos = lister_tables_objets_sql($table);
4828
+    $table = table_objet_sql($objet);
4829
+    $infos = lister_tables_objets_sql($table);
4830 4830
 
4831
-	return ($infos[$info] ?? '');
4831
+    return ($infos[$info] ?? '');
4832 4832
 }
4833 4833
 
4834 4834
 /**
@@ -4843,11 +4843,11 @@  discard block
 block discarded – undo
4843 4843
  *     texte traduit du comptage, tel que '3 articles'
4844 4844
  */
4845 4845
 function objet_afficher_nb($nb, $objet) {
4846
-	if (!$nb) {
4847
-		return _T(objet_info($objet, 'info_aucun_objet'));
4848
-	} else {
4849
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
4850
-	}
4846
+    if (!$nb) {
4847
+        return _T(objet_info($objet, 'info_aucun_objet'));
4848
+    } else {
4849
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
4850
+    }
4851 4851
 }
4852 4852
 
4853 4853
 /**
@@ -4859,11 +4859,11 @@  discard block
 block discarded – undo
4859 4859
  * @return string
4860 4860
  */
4861 4861
 function objet_icone($objet, $taille = 24, $class = '') {
4862
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
4863
-	$icone = chemin_image($icone);
4864
-	$balise_img = charger_filtre('balise_img');
4862
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
4863
+    $icone = chemin_image($icone);
4864
+    $balise_img = charger_filtre('balise_img');
4865 4865
 
4866
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4866
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
4867 4867
 }
4868 4868
 
4869 4869
 /**
@@ -4884,12 +4884,12 @@  discard block
 block discarded – undo
4884 4884
  * @return string
4885 4885
  */
4886 4886
 function objet_T($objet, $chaine, $args = [], $options = []) {
4887
-	$chaine = explode(':', $chaine);
4888
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
4889
-		return $t;
4890
-	}
4891
-	$chaine = implode(':', $chaine);
4892
-	return _T($chaine, $args, $options);
4887
+    $chaine = explode(':', $chaine);
4888
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
4889
+        return $t;
4890
+    }
4891
+    $chaine = implode(':', $chaine);
4892
+    return _T($chaine, $args, $options);
4893 4893
 }
4894 4894
 
4895 4895
 /**
@@ -4903,18 +4903,18 @@  discard block
 block discarded – undo
4903 4903
  * @return string      Code HTML
4904 4904
  */
4905 4905
 function insert_head_css_conditionnel($flux) {
4906
-	if (
4907
-		!str_contains($flux, '<!-- insert_head_css -->')
4908
-		&& ($p = strpos($flux, '<!-- insert_head -->'))
4909
-	) {
4910
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
4911
-		if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) {
4912
-			$p = $p1;
4913
-		}
4914
-		$flux = substr_replace($flux, (string) pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4915
-	}
4906
+    if (
4907
+        !str_contains($flux, '<!-- insert_head_css -->')
4908
+        && ($p = strpos($flux, '<!-- insert_head -->'))
4909
+    ) {
4910
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
4911
+        if (($p1 = stripos($flux, '<script src=')) && $p1 < $p) {
4912
+            $p = $p1;
4913
+        }
4914
+        $flux = substr_replace($flux, (string) pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
4915
+    }
4916 4916
 
4917
-	return $flux;
4917
+    return $flux;
4918 4918
 }
4919 4919
 
4920 4920
 /**
@@ -4937,75 +4937,75 @@  discard block
 block discarded – undo
4937 4937
  * @return string
4938 4938
  */
4939 4939
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
4940
-	if (isset($contexte['format'])) {
4941
-		$extension = $contexte['format'];
4942
-		unset($contexte['format']);
4943
-	} else {
4944
-		$extension = 'html';
4945
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
4946
-			$extension = $m[1];
4947
-		}
4948
-	}
4949
-	// recuperer le contenu produit par le squelette
4950
-	$options['raw'] = true;
4951
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
4952
-
4953
-	// calculer le nom de la css
4954
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4955
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
4956
-	$contexte_implicite = calculer_contexte_implicite();
4957
-
4958
-	// par defaut on hash selon les contextes qui sont a priori moins variables
4959
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4960
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4961
-	if (isset($options['hash_on_content']) && $options['hash_on_content']) {
4962
-		$hash = md5((string) ($contexte_implicite['host'] . '::' . $cache));
4963
-	}
4964
-	else {
4965
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4966
-		ksort($contexte);
4967
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
4968
-	}
4969
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4970
-
4971
-	// mettre a jour le fichier si il n'existe pas
4972
-	// ou trop ancien
4973
-	// le dernier fichier produit est toujours suffixe par .last
4974
-	// et recopie sur le fichier cible uniquement si il change
4975
-	if (
4976
-		!file_exists($filename)
4977
-		|| !file_exists($filename . '.last')
4978
-		|| isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified']
4979
-		|| defined('_VAR_MODE') && _VAR_MODE == 'recalcul'
4980
-	) {
4981
-		$contenu = $cache['texte'];
4982
-		// passer les urls en absolu si c'est une css
4983
-		if ($extension == 'css') {
4984
-			$contenu = urls_absolues_css(
4985
-				$contenu,
4986
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
4987
-			);
4988
-		}
4989
-
4990
-		$comment = '';
4991
-		// ne pas insérer de commentaire sur certains formats
4992
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
4993
-			$comment = "/* #PRODUIRE{fond=$fond";
4994
-			foreach ($contexte as $k => $v) {
4995
-				if (is_array($v)) {
4996
-					$v = var_export($v, true);
4997
-				}
4998
-				$comment .= ",$k=$v";
4999
-			}
5000
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5001
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5002
-			$comment .= "}\n   md5:" . md5((string) $contenu) . " */\n";
5003
-		}
5004
-		// et ecrire le fichier si il change
5005
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5006
-	}
5007
-
5008
-	return timestamp($filename);
4940
+    if (isset($contexte['format'])) {
4941
+        $extension = $contexte['format'];
4942
+        unset($contexte['format']);
4943
+    } else {
4944
+        $extension = 'html';
4945
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
4946
+            $extension = $m[1];
4947
+        }
4948
+    }
4949
+    // recuperer le contenu produit par le squelette
4950
+    $options['raw'] = true;
4951
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
4952
+
4953
+    // calculer le nom de la css
4954
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
4955
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
4956
+    $contexte_implicite = calculer_contexte_implicite();
4957
+
4958
+    // par defaut on hash selon les contextes qui sont a priori moins variables
4959
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
4960
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
4961
+    if (isset($options['hash_on_content']) && $options['hash_on_content']) {
4962
+        $hash = md5((string) ($contexte_implicite['host'] . '::' . $cache));
4963
+    }
4964
+    else {
4965
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
4966
+        ksort($contexte);
4967
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
4968
+    }
4969
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
4970
+
4971
+    // mettre a jour le fichier si il n'existe pas
4972
+    // ou trop ancien
4973
+    // le dernier fichier produit est toujours suffixe par .last
4974
+    // et recopie sur le fichier cible uniquement si il change
4975
+    if (
4976
+        !file_exists($filename)
4977
+        || !file_exists($filename . '.last')
4978
+        || isset($cache['lastmodified']) && $cache['lastmodified'] && filemtime($filename . '.last') < $cache['lastmodified']
4979
+        || defined('_VAR_MODE') && _VAR_MODE == 'recalcul'
4980
+    ) {
4981
+        $contenu = $cache['texte'];
4982
+        // passer les urls en absolu si c'est une css
4983
+        if ($extension == 'css') {
4984
+            $contenu = urls_absolues_css(
4985
+                $contenu,
4986
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
4987
+            );
4988
+        }
4989
+
4990
+        $comment = '';
4991
+        // ne pas insérer de commentaire sur certains formats
4992
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
4993
+            $comment = "/* #PRODUIRE{fond=$fond";
4994
+            foreach ($contexte as $k => $v) {
4995
+                if (is_array($v)) {
4996
+                    $v = var_export($v, true);
4997
+                }
4998
+                $comment .= ",$k=$v";
4999
+            }
5000
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5001
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5002
+            $comment .= "}\n   md5:" . md5((string) $contenu) . " */\n";
5003
+        }
5004
+        // et ecrire le fichier si il change
5005
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5006
+    }
5007
+
5008
+    return timestamp($filename);
5009 5009
 }
5010 5010
 
5011 5011
 /**
@@ -5018,11 +5018,11 @@  discard block
 block discarded – undo
5018 5018
  *    $fichier auquel on a ajouté le timestamp
5019 5019
  */
5020 5020
 function timestamp($fichier) {
5021
-	if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) {
5022
-		return $fichier;
5023
-	}
5021
+    if (!$fichier || !file_exists($fichier) || !$m = filemtime($fichier)) {
5022
+        return $fichier;
5023
+    }
5024 5024
 
5025
-	return "$fichier?$m";
5025
+    return "$fichier?$m";
5026 5026
 }
5027 5027
 
5028 5028
 /**
@@ -5032,11 +5032,11 @@  discard block
 block discarded – undo
5032 5032
  * @return string
5033 5033
  */
5034 5034
 function supprimer_timestamp($url) {
5035
-	if (!str_contains($url, '?')) {
5036
-		return $url;
5037
-	}
5035
+    if (!str_contains($url, '?')) {
5036
+        return $url;
5037
+    }
5038 5038
 
5039
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5039
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5040 5040
 }
5041 5041
 
5042 5042
 /**
@@ -5051,15 +5051,15 @@  discard block
 block discarded – undo
5051 5051
  * @return string
5052 5052
  */
5053 5053
 function filtre_nettoyer_titre_email_dist($titre) {
5054
-	include_spip('inc/envoyer_mail');
5054
+    include_spip('inc/envoyer_mail');
5055 5055
 
5056
-	$titre = nettoyer_titre_email($titre);
5057
-	// on est dans un squelette : securiser le retour
5058
-	if (str_contains($titre, '<')) {
5059
-		$titre = interdire_scripts($titre);
5060
-	}
5056
+    $titre = nettoyer_titre_email($titre);
5057
+    // on est dans un squelette : securiser le retour
5058
+    if (str_contains($titre, '<')) {
5059
+        $titre = interdire_scripts($titre);
5060
+    }
5061 5061
 
5062
-	return $titre;
5062
+    return $titre;
5063 5063
 }
5064 5064
 
5065 5065
 /**
@@ -5081,27 +5081,27 @@  discard block
 block discarded – undo
5081 5081
  * @return string
5082 5082
  */
5083 5083
 function filtre_chercher_rubrique_dist(
5084
-	$titre,
5085
-	$id_objet,
5086
-	$id_parent,
5087
-	$objet,
5088
-	$id_secteur,
5089
-	$restreint,
5090
-	$actionable = false,
5091
-	$retour_sans_cadre = false
5084
+    $titre,
5085
+    $id_objet,
5086
+    $id_parent,
5087
+    $objet,
5088
+    $id_secteur,
5089
+    $restreint,
5090
+    $actionable = false,
5091
+    $retour_sans_cadre = false
5092 5092
 ) {
5093
-	include_spip('inc/filtres_ecrire');
5093
+    include_spip('inc/filtres_ecrire');
5094 5094
 
5095
-	return chercher_rubrique(
5096
-		$titre,
5097
-		$id_objet,
5098
-		$id_parent,
5099
-		$objet,
5100
-		$id_secteur,
5101
-		$restreint,
5102
-		$actionable,
5103
-		$retour_sans_cadre
5104
-	);
5095
+    return chercher_rubrique(
5096
+        $titre,
5097
+        $id_objet,
5098
+        $id_parent,
5099
+        $objet,
5100
+        $id_secteur,
5101
+        $restreint,
5102
+        $actionable,
5103
+        $retour_sans_cadre
5104
+    );
5105 5105
 }
5106 5106
 
5107 5107
 /**
@@ -5130,56 +5130,56 @@  discard block
 block discarded – undo
5130 5130
  *     Chaîne vide si l'accès est autorisé
5131 5131
  */
5132 5132
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5133
-	if ($ok) {
5134
-		return '';
5135
-	}
5136
-
5137
-	// Vider tous les tampons
5138
-	$level = @ob_get_level();
5139
-	while ($level--) {
5140
-		@ob_end_clean();
5141
-	}
5142
-
5143
-	include_spip('inc/headers');
5144
-
5145
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5146
-	if ($url) {
5147
-		redirige_par_entete($url, '', $statut);
5148
-	}
5149
-
5150
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5151
-	if (!is_numeric($statut) && is_null($message)) {
5152
-		$message = $statut;
5153
-		$statut = 0;
5154
-	}
5155
-	if (!$message) {
5156
-		$message = '';
5157
-	}
5158
-	$statut = (int) $statut;
5159
-
5160
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5161
-	if (test_espace_prive()) {
5162
-		if (!$statut || !in_array($statut, [404, 403])) {
5163
-			$statut = 403;
5164
-		}
5165
-		http_response_code(403);
5166
-		$echec = charger_fonction('403', 'exec');
5167
-		$echec($message);
5168
-	} else {
5169
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5170
-		if (!$statut) {
5171
-			$statut = 404;
5172
-		}
5173
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5174
-		http_response_code($statut);
5175
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5176
-		if ($statut >= 400) {
5177
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5178
-		}
5179
-	}
5180
-
5181
-
5182
-	exit;
5133
+    if ($ok) {
5134
+        return '';
5135
+    }
5136
+
5137
+    // Vider tous les tampons
5138
+    $level = @ob_get_level();
5139
+    while ($level--) {
5140
+        @ob_end_clean();
5141
+    }
5142
+
5143
+    include_spip('inc/headers');
5144
+
5145
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5146
+    if ($url) {
5147
+        redirige_par_entete($url, '', $statut);
5148
+    }
5149
+
5150
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5151
+    if (!is_numeric($statut) && is_null($message)) {
5152
+        $message = $statut;
5153
+        $statut = 0;
5154
+    }
5155
+    if (!$message) {
5156
+        $message = '';
5157
+    }
5158
+    $statut = (int) $statut;
5159
+
5160
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5161
+    if (test_espace_prive()) {
5162
+        if (!$statut || !in_array($statut, [404, 403])) {
5163
+            $statut = 403;
5164
+        }
5165
+        http_response_code(403);
5166
+        $echec = charger_fonction('403', 'exec');
5167
+        $echec($message);
5168
+    } else {
5169
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5170
+        if (!$statut) {
5171
+            $statut = 404;
5172
+        }
5173
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5174
+        http_response_code($statut);
5175
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5176
+        if ($statut >= 400) {
5177
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5178
+        }
5179
+    }
5180
+
5181
+
5182
+    exit;
5183 5183
 }
5184 5184
 
5185 5185
 /**
@@ -5190,11 +5190,11 @@  discard block
 block discarded – undo
5190 5190
  * @return string
5191 5191
  */
5192 5192
 function filtre_compacte_dist($source, $format = null) {
5193
-	if (function_exists('minifier')) {
5194
-		return minifier($source, $format);
5195
-	}
5193
+    if (function_exists('minifier')) {
5194
+        return minifier($source, $format);
5195
+    }
5196 5196
 
5197
-	return $source;
5197
+    return $source;
5198 5198
 }
5199 5199
 
5200 5200
 
@@ -5204,32 +5204,32 @@  discard block
 block discarded – undo
5204 5204
  * @return string
5205 5205
  */
5206 5206
 function spip_affiche_mot_de_passe_masque(#[\SensitiveParameter] ?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5207
-	$passe ??= '';
5208
-	$l = strlen($passe);
5209
-
5210
-	if ($l <= 8 || !$afficher_partiellement) {
5211
-		if (!$l) {
5212
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5213
-		}
5214
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5215
-	}
5216
-
5217
-	if (is_null($portion_pourcent)) {
5218
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5219
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5220
-		}
5221
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5222
-	}
5223
-	if ($portion_pourcent >= 100) {
5224
-		return $passe;
5225
-	}
5226
-	$e = (int) ceil($l * $portion_pourcent / 100 / 2);
5227
-	$e = max($e, 0);
5228
-	$mid = str_pad('', $l - 2 * $e, '*');
5229
-	if ($e > 0 && strlen($mid) > 8) {
5230
-		$mid = '***...***';
5231
-	}
5232
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5207
+    $passe ??= '';
5208
+    $l = strlen($passe);
5209
+
5210
+    if ($l <= 8 || !$afficher_partiellement) {
5211
+        if (!$l) {
5212
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5213
+        }
5214
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5215
+    }
5216
+
5217
+    if (is_null($portion_pourcent)) {
5218
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5219
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5220
+        }
5221
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5222
+    }
5223
+    if ($portion_pourcent >= 100) {
5224
+        return $passe;
5225
+    }
5226
+    $e = (int) ceil($l * $portion_pourcent / 100 / 2);
5227
+    $e = max($e, 0);
5228
+    $mid = str_pad('', $l - 2 * $e, '*');
5229
+    if ($e > 0 && strlen($mid) > 8) {
5230
+        $mid = '***...***';
5231
+    }
5232
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5233 5233
 }
5234 5234
 
5235 5235
 
@@ -5250,66 +5250,66 @@  discard block
 block discarded – undo
5250 5250
  */
5251 5251
 function identifiant_slug($texte, $type = '', $options = []) {
5252 5252
 
5253
-	$original = $texte;
5254
-	$separateur = ($options['separateur'] ?? '_');
5255
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5256
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5253
+    $original = $texte;
5254
+    $separateur = ($options['separateur'] ?? '_');
5255
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5256
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5257 5257
 
5258
-	if (!function_exists('translitteration')) {
5259
-		include_spip('inc/charsets');
5260
-	}
5258
+    if (!function_exists('translitteration')) {
5259
+        include_spip('inc/charsets');
5260
+    }
5261 5261
 
5262
-	// pas de balise html
5263
-	if (str_contains($texte, '<')) {
5264
-		$texte = strip_tags($texte);
5265
-	}
5266
-	if (str_contains($texte, '&')) {
5267
-		$texte = unicode2charset($texte);
5268
-	}
5269
-	// On enlève les espaces indésirables
5270
-	$texte = trim($texte);
5262
+    // pas de balise html
5263
+    if (str_contains($texte, '<')) {
5264
+        $texte = strip_tags($texte);
5265
+    }
5266
+    if (str_contains($texte, '&')) {
5267
+        $texte = unicode2charset($texte);
5268
+    }
5269
+    // On enlève les espaces indésirables
5270
+    $texte = trim($texte);
5271 5271
 
5272
-	// On enlève les accents et cie
5273
-	$texte = translitteration($texte);
5272
+    // On enlève les accents et cie
5273
+    $texte = translitteration($texte);
5274 5274
 
5275
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5276
-	$texte = preg_replace(',[\W_]+,ms', (string) $separateur, $texte);
5275
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5276
+    $texte = preg_replace(',[\W_]+,ms', (string) $separateur, $texte);
5277 5277
 
5278
-	if ($separateur) {
5279
-		// nettoyer les doubles occurences du separateur si besoin
5280
-		while (str_contains($texte, (string) "$separateur$separateur")) {
5281
-			$texte = str_replace("$separateur$separateur", $separateur, $texte);
5282
-		}
5278
+    if ($separateur) {
5279
+        // nettoyer les doubles occurences du separateur si besoin
5280
+        while (str_contains($texte, (string) "$separateur$separateur")) {
5281
+            $texte = str_replace("$separateur$separateur", $separateur, $texte);
5282
+        }
5283 5283
 
5284
-		// pas de separateur au debut ni a la fin
5285
-		$texte = trim($texte, $separateur);
5286
-	}
5284
+        // pas de separateur au debut ni a la fin
5285
+        $texte = trim($texte, $separateur);
5286
+    }
5287 5287
 
5288
-	// en minuscules
5289
-	$texte = strtolower($texte);
5288
+    // en minuscules
5289
+    $texte = strtolower($texte);
5290 5290
 
5291
-	switch ($type) {
5292
-		case 'class':
5293
-		case 'id':
5294
-		case 'anchor':
5295
-			if (preg_match(',^\d,', $texte)) {
5296
-				$texte = substr($type, 0, 1) . $texte;
5297
-			}
5298
-	}
5291
+    switch ($type) {
5292
+        case 'class':
5293
+        case 'id':
5294
+        case 'anchor':
5295
+            if (preg_match(',^\d,', $texte)) {
5296
+                $texte = substr($type, 0, 1) . $texte;
5297
+            }
5298
+    }
5299 5299
 
5300
-	if (strlen($texte) > $longueur_maxi) {
5301
-		$texte = substr($texte, 0, $longueur_maxi);
5302
-	}
5300
+    if (strlen($texte) > $longueur_maxi) {
5301
+        $texte = substr($texte, 0, $longueur_maxi);
5302
+    }
5303 5303
 
5304
-	if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) {
5305
-		if (preg_match(',^\d,', $texte)) {
5306
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5307
-		}
5308
-		$texte .= $separateur . md5($original);
5309
-		$texte = substr($texte, 0, $longueur_mini);
5310
-	}
5304
+    if (strlen($texte) < $longueur_mini && $longueur_mini < $longueur_maxi) {
5305
+        if (preg_match(',^\d,', $texte)) {
5306
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5307
+        }
5308
+        $texte .= $separateur . md5($original);
5309
+        $texte = substr($texte, 0, $longueur_mini);
5310
+    }
5311 5311
 
5312
-	return $texte;
5312
+    return $texte;
5313 5313
 }
5314 5314
 
5315 5315
 
@@ -5330,11 +5330,11 @@  discard block
 block discarded – undo
5330 5330
  * @exemple `<:info_maximum|label_nettoyer:>`
5331 5331
  */
5332 5332
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5333
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5334
-	if ($ucfirst) {
5335
-		$label = spip_ucfirst($label);
5336
-	}
5337
-	return $label;
5333
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5334
+    if ($ucfirst) {
5335
+        $label = spip_ucfirst($label);
5336
+    }
5337
+    return $label;
5338 5338
 }
5339 5339
 
5340 5340
 /**
@@ -5347,8 +5347,8 @@  discard block
 block discarded – undo
5347 5347
  * @exemple `<:info_maximum|label_ponctuer:>`
5348 5348
  */
5349 5349
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5350
-	$label = label_nettoyer($text, $ucfirst);
5351
-	return _T('label_ponctuer', ['label' => $label]);
5350
+    $label = label_nettoyer($text, $ucfirst);
5351
+    return _T('label_ponctuer', ['label' => $label]);
5352 5352
 }
5353 5353
 
5354 5354
 
@@ -5361,19 +5361,19 @@  discard block
 block discarded – undo
5361 5361
  * @return array
5362 5362
  */
5363 5363
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5364
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5365
-		return [];
5366
-	}
5364
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5365
+        return [];
5366
+    }
5367 5367
 
5368
-	// compatibilite signature inversee
5369
-	if (is_numeric($objet) && !is_numeric($id_objet)) {
5370
-		[$objet, $id_objet] = [$id_objet, $objet];
5371
-	}
5368
+    // compatibilite signature inversee
5369
+    if (is_numeric($objet) && !is_numeric($id_objet)) {
5370
+        [$objet, $id_objet] = [$id_objet, $objet];
5371
+    }
5372 5372
 
5373
-	if (!function_exists($fonction)) {
5374
-		include_spip('base/objets');
5375
-	}
5376
-	return $fonction($objet, $id_objet);
5373
+    if (!function_exists($fonction)) {
5374
+        include_spip('base/objets');
5375
+    }
5376
+    return $fonction($objet, $id_objet);
5377 5377
 }
5378 5378
 
5379 5379
 
@@ -5388,7 +5388,7 @@  discard block
 block discarded – undo
5388 5388
  * @return array
5389 5389
  */
5390 5390
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5391
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5391
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5392 5392
 }
5393 5393
 
5394 5394
 /**
@@ -5402,7 +5402,7 @@  discard block
 block discarded – undo
5402 5402
  * @return array
5403 5403
  */
5404 5404
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5405
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5405
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5406 5406
 }
5407 5407
 
5408 5408
 /**
@@ -5416,7 +5416,7 @@  discard block
 block discarded – undo
5416 5416
  * @return array
5417 5417
  */
5418 5418
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5419
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5419
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5420 5420
 }
5421 5421
 
5422 5422
 /**
@@ -5430,5 +5430,5 @@  discard block
 block discarded – undo
5430 5430
  * @return array
5431 5431
  */
5432 5432
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5433
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5433
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5434 5434
 }
Please login to merge, or discard this patch.