Completed
Push — master ( 5e73c9...220241 )
by cam
01:00
created
ecrire/inc/filtres.php 1 patch
Indentation   +2409 added lines, -2409 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string texte
54 54
  **/
55 55
 function filtre_identite_dist($texte) {
56
- return $texte;
56
+    return $texte;
57 57
 }
58 58
 
59 59
 /**
@@ -77,33 +77,33 @@  discard block
 block discarded – undo
77 77
  *     Fonction PHP correspondante du filtre demandé
78 78
  */
79 79
 function chercher_filtre($fonc, $default = null) {
80
-	if (!$fonc) {
81
-		return $default;
82
-	}
83
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
84
-	// Foo::Bar
85
-	// qui peuvent etre avec un namespace : space\Foo::Bar
86
-	if (preg_match(',^[\w]+/,', $fonc)) {
87
-		$nom = preg_replace(',\W,', '_', $fonc);
88
-		$f = chercher_filtre($nom);
89
-		// cas du sous-type MIME sans filtre associe, passer au type:
90
-		// si filtre_text_plain pas defini, passe a filtre_text
91
-		if (!$f and $nom !== $fonc) {
92
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
-		}
94
-
95
-		return $f;
96
-	}
97
-
98
-	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
-		if (is_callable($f)) {
102
-			return $f;
103
-		}
104
-	}
105
-
106
-	return $default;
80
+    if (!$fonc) {
81
+        return $default;
82
+    }
83
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
84
+    // Foo::Bar
85
+    // qui peuvent etre avec un namespace : space\Foo::Bar
86
+    if (preg_match(',^[\w]+/,', $fonc)) {
87
+        $nom = preg_replace(',\W,', '_', $fonc);
88
+        $f = chercher_filtre($nom);
89
+        // cas du sous-type MIME sans filtre associe, passer au type:
90
+        // si filtre_text_plain pas defini, passe a filtre_text
91
+        if (!$f and $nom !== $fonc) {
92
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
+        }
94
+
95
+        return $f;
96
+    }
97
+
98
+    include_fichiers_fonctions();
99
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
+        if (is_callable($f)) {
102
+            return $f;
103
+        }
104
+    }
105
+
106
+    return $default;
107 107
 }
108 108
 
109 109
 /**
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
  *     Chaîne vide sinon.
148 148
  **/
149 149
 function appliquer_filtre($arg, $filtre) {
150
-	$args = func_get_args();
151
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
150
+    $args = func_get_args();
151
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
152 152
 }
153 153
 
154 154
 /**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
  *     texte d'origine sinon
174 174
  **/
175 175
 function appliquer_si_filtre($arg, $filtre) {
176
-	$args = func_get_args();
177
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
176
+    $args = func_get_args();
177
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
178 178
 }
179 179
 
180 180
 /**
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
190 190
  *     Version de SPIP
191 191
  **/
192 192
 function spip_version() {
193
-	$version = $GLOBALS['spip_version_affichee'];
194
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
195
-		$version .= " $vcs_version";
196
-	}
193
+    $version = $GLOBALS['spip_version_affichee'];
194
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
195
+        $version .= " $vcs_version";
196
+    }
197 197
 
198
-	return $version;
198
+    return $version;
199 199
 }
200 200
 
201 201
 /**
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
  * @return string
208 208
  */
209 209
 function header_silencieux($version): string {
210
-	if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
211
-		$version = '';
212
-	}
210
+    if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
211
+        $version = '';
212
+    }
213 213
 
214
-	return (string) $version;
214
+    return (string) $version;
215 215
 }
216 216
 
217 217
 /**
@@ -224,16 +224,16 @@  discard block
 block discarded – undo
224 224
  *    - string|null si $raw = false
225 225
  */
226 226
 function version_vcs_courante($dir, $raw = false) {
227
-	$desc = decrire_version_git($dir);
228
-	if ($desc === null or $raw) {
229
-		return $desc;
230
-	}
231
-	// affichage "GIT [master: abcdef]"
232
-	$commit = $desc['commit_short'] ?? $desc['commit'];
233
-	if ($desc['branch']) {
234
-		$commit = $desc['branch'] . ': ' . $commit;
235
-	}
236
-	return "{$desc['vcs']} [$commit]";
227
+    $desc = decrire_version_git($dir);
228
+    if ($desc === null or $raw) {
229
+        return $desc;
230
+    }
231
+    // affichage "GIT [master: abcdef]"
232
+    $commit = $desc['commit_short'] ?? $desc['commit'];
233
+    if ($desc['branch']) {
234
+        $commit = $desc['branch'] . ': ' . $commit;
235
+    }
236
+    return "{$desc['vcs']} [$commit]";
237 237
 }
238 238
 
239 239
 /**
@@ -245,24 +245,24 @@  discard block
 block discarded – undo
245 245
  *      array ['branch' => xx, 'commit' => yy] sinon.
246 246
  **/
247 247
 function decrire_version_git($dir) {
248
-	if (!$dir) {
249
-		$dir = '.';
250
-	}
251
-
252
-	// version installee par GIT
253
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
254
-		$currentHead = trim(substr($c, 4));
255
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
256
-			return [
257
-				'vcs' => 'GIT',
258
-				'branch' => basename($currentHead),
259
-				'commit' => trim($hash),
260
-				'commit_short' => substr(trim($hash), 0, 8),
261
-			];
262
-		}
263
-	}
264
-
265
-	return null;
248
+    if (!$dir) {
249
+        $dir = '.';
250
+    }
251
+
252
+    // version installee par GIT
253
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
254
+        $currentHead = trim(substr($c, 4));
255
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
256
+            return [
257
+                'vcs' => 'GIT',
258
+                'branch' => basename($currentHead),
259
+                'commit' => trim($hash),
260
+                'commit_short' => substr(trim($hash), 0, 8),
261
+            ];
262
+        }
263
+    }
264
+
265
+    return null;
266 266
 }
267 267
 
268 268
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
  *     Code HTML retourné par le filtre
310 310
  **/
311 311
 function filtrer($filtre) {
312
-	$tous = func_get_args();
313
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
314
-		return image_filtrer($tous);
315
-	} elseif ($f = chercher_filtre($filtre)) {
316
-		array_shift($tous);
317
-		return $f(...$tous);
318
-	} else {
319
-		// le filtre n'existe pas, on provoque une erreur
320
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
321
-		erreur_squelette($msg);
322
-		return '';
323
-	}
312
+    $tous = func_get_args();
313
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
314
+        return image_filtrer($tous);
315
+    } elseif ($f = chercher_filtre($filtre)) {
316
+        array_shift($tous);
317
+        return $f(...$tous);
318
+    } else {
319
+        // le filtre n'existe pas, on provoque une erreur
320
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
321
+        erreur_squelette($msg);
322
+        return '';
323
+    }
324 324
 }
325 325
 
326 326
 /**
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
338 338
  */
339 339
 function trouver_filtre_matrice($filtre) {
340
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
341
-		find_in_path($f, '', true);
342
-		$GLOBALS['spip_matrice'][$filtre] = true;
343
-	}
344
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
340
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
341
+        find_in_path($f, '', true);
342
+        $GLOBALS['spip_matrice'][$filtre] = true;
343
+    }
344
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
345 345
 }
346 346
 
347 347
 
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
  * @return mixed
370 370
  */
371 371
 function filtre_set(&$Pile, $val, $key, $continue = null) {
372
-	$Pile['vars'][$key] = $val;
373
-	return $continue ? $val : '';
372
+    $Pile['vars'][$key] = $val;
373
+    return $continue ? $val : '';
374 374
 }
375 375
 
376 376
 /**
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
397 397
  */
398 398
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
399
-	$Pile[0][$key] = $val;
400
-	return $continue ? $val : '';
399
+    $Pile[0][$key] = $val;
400
+    return $continue ? $val : '';
401 401
 }
402 402
 
403 403
 /**
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
  * @return string
407 407
  */
408 408
 function filtre_sanitize_env(&$Pile, $keys) {
409
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
410
-	return '';
409
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
410
+    return '';
411 411
 }
412 412
 
413 413
 
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
  * @return mixed Retourne la valeur (sans la modifier).
431 431
  */
432 432
 function filtre_debug($val, $key = null) {
433
-	$debug = (
434
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
435
-		) . var_export($val, true);
433
+    $debug = (
434
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
435
+        ) . var_export($val, true);
436 436
 
437
-	include_spip('inc/autoriser');
438
-	if (autoriser('webmestre')) {
439
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
440
-	}
437
+    include_spip('inc/autoriser');
438
+    if (autoriser('webmestre')) {
439
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
440
+    }
441 441
 
442
-	spip_log($debug, 'debug');
442
+    spip_log($debug, 'debug');
443 443
 
444
-	return $val;
444
+    return $val;
445 445
 }
446 446
 
447 447
 
@@ -471,84 +471,84 @@  discard block
 block discarded – undo
471 471
  *     texte qui a reçu les filtres
472 472
  **/
473 473
 function image_filtrer($args) {
474
-	$filtre = array_shift($args); # enlever $filtre
475
-	$texte = array_shift($args);
476
-	if ($texte === null || !strlen($texte)) {
477
-		return '';
478
-	}
479
-	find_in_path('filtres_images_mini.php', 'inc/', true);
480
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
481
-	// Cas du nom de fichier local
482
-	$is_file = trim($texte);
483
-	if (
484
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
485
-		  or strpbrk($is_file, "<>\n\r\t") !== false
486
-		  or strpos($is_file, '/') === 0
487
-	) {
488
-		$is_file = false;
489
-	}
490
-	if ($is_file) {
491
-		$is_local_file = function ($path) {
492
-			if (strpos($path, '?') !== false) {
493
-				$path = supprimer_timestamp($path);
494
-				// remove ?24px added by find_in_theme on .svg files
495
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
496
-			}
497
-			return file_exists($path);
498
-		};
499
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
500
-			$res = $filtre("<img src='$is_file' />", ...$args);
501
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
502
-			return $res;
503
-		}
504
-	}
505
-
506
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
507
-	if (
508
-		preg_match_all(
509
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
510
-			$texte,
511
-			$tags,
512
-			PREG_SET_ORDER
513
-		)
514
-	) {
515
-		foreach ($tags as $tag) {
516
-			$class = extraire_attribut($tag[3], 'class');
517
-			if (
518
-				!$class or
519
-				(strpos($class, 'filtre_inactif') === false
520
-					// compat historique a virer en 3.2
521
-					and !str_contains($class, 'no_image_filtrer'))
522
-			) {
523
-				if ($reduit = $filtre($tag[3], ...$args)) {
524
-					// En cas de span spip_documents, modifier le style=...width:
525
-					if ($tag[1]) {
526
-						$w = extraire_attribut($reduit, 'width');
527
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
528
-							$w = $regs[1];
529
-						}
530
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
531
-							$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
532
-							$replace = inserer_attribut($tag[1], 'style', $style);
533
-							$texte = str_replace($tag[1], $replace, $texte);
534
-						}
535
-					}
536
-					// traiter aussi un eventuel mouseover
537
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539
-							$srcover = $match[1];
540
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
541
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
542
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
543
-						}
544
-					}
545
-					$texte = str_replace($tag[3], $reduit, $texte);
546
-				}
547
-			}
548
-		}
549
-	}
550
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
551
-	return $texte;
474
+    $filtre = array_shift($args); # enlever $filtre
475
+    $texte = array_shift($args);
476
+    if ($texte === null || !strlen($texte)) {
477
+        return '';
478
+    }
479
+    find_in_path('filtres_images_mini.php', 'inc/', true);
480
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
481
+    // Cas du nom de fichier local
482
+    $is_file = trim($texte);
483
+    if (
484
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
485
+          or strpbrk($is_file, "<>\n\r\t") !== false
486
+          or strpos($is_file, '/') === 0
487
+    ) {
488
+        $is_file = false;
489
+    }
490
+    if ($is_file) {
491
+        $is_local_file = function ($path) {
492
+            if (strpos($path, '?') !== false) {
493
+                $path = supprimer_timestamp($path);
494
+                // remove ?24px added by find_in_theme on .svg files
495
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
496
+            }
497
+            return file_exists($path);
498
+        };
499
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
500
+            $res = $filtre("<img src='$is_file' />", ...$args);
501
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
502
+            return $res;
503
+        }
504
+    }
505
+
506
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
507
+    if (
508
+        preg_match_all(
509
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
510
+            $texte,
511
+            $tags,
512
+            PREG_SET_ORDER
513
+        )
514
+    ) {
515
+        foreach ($tags as $tag) {
516
+            $class = extraire_attribut($tag[3], 'class');
517
+            if (
518
+                !$class or
519
+                (strpos($class, 'filtre_inactif') === false
520
+                    // compat historique a virer en 3.2
521
+                    and !str_contains($class, 'no_image_filtrer'))
522
+            ) {
523
+                if ($reduit = $filtre($tag[3], ...$args)) {
524
+                    // En cas de span spip_documents, modifier le style=...width:
525
+                    if ($tag[1]) {
526
+                        $w = extraire_attribut($reduit, 'width');
527
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
528
+                            $w = $regs[1];
529
+                        }
530
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
531
+                            $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
532
+                            $replace = inserer_attribut($tag[1], 'style', $style);
533
+                            $texte = str_replace($tag[1], $replace, $texte);
534
+                        }
535
+                    }
536
+                    // traiter aussi un eventuel mouseover
537
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539
+                            $srcover = $match[1];
540
+                            $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
541
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
542
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
543
+                        }
544
+                    }
545
+                    $texte = str_replace($tag[3], $reduit, $texte);
546
+                }
547
+            }
548
+        }
549
+    }
550
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
551
+    return $texte;
552 552
 }
553 553
 
554 554
 /**
@@ -565,94 +565,94 @@  discard block
 block discarded – undo
565 565
  **/
566 566
 function infos_image($img, $force_refresh = false) {
567 567
 
568
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
569
-	$srcWidth = 0;
570
-	$srcHeight = 0;
571
-	$srcSize = null;
572
-
573
-	$src = extraire_attribut($img, 'src');
574
-
575
-	if (!$src) {
576
-		$src = $img;
577
-	} else {
578
-		$srcWidth = extraire_attribut($img, 'width');
579
-		$srcHeight = extraire_attribut($img, 'height');
580
-		if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) {
581
-			$srcWidth = $srcHeight = 0;
582
-		}
583
-	}
584
-
585
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
586
-	// la copie locale a toutes les chances d'etre la ou de resservir
587
-	if (tester_url_absolue($src)) {
588
-		include_spip('inc/distant');
589
-		$fichier = copie_locale($src);
590
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
591
-	}
592
-	if (($p = strpos($src, '?')) !== false) {
593
-		$src = substr($src, 0, $p);
594
-	}
595
-
596
-	$imagesize = false;
597
-	if (isset($largeur_img[$src]) and !$force_refresh) {
598
-		$srcWidth = $largeur_img[$src];
599
-	}
600
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
601
-		$srcHeight = $hauteur_img[$src];
602
-	}
603
-	if (isset($poids_img[$src]) and !$force_refresh) {
604
-		$srcSize = $poids_img[$src];
605
-	}
606
-	if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
607
-		if (
608
-			file_exists($src)
609
-			and $imagesize = spip_getimagesize($src)
610
-		) {
611
-			if (!$srcWidth) {
612
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
613
-			}
614
-			if (!$srcHeight) {
615
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
616
-			}
617
-			if (!$srcSize) {
618
-				$poids_img[$src] = filesize($src);
619
-			}
620
-		}
621
-		elseif (strpos($src, '<svg') !== false) {
622
-			include_spip('inc/svg');
623
-			if ($attrs = svg_lire_attributs($src)) {
624
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
625
-				if (!$srcWidth) {
626
-					$largeur_img[$src] = $srcWidth = $width;
627
-				}
628
-				if (!$srcHeight) {
629
-					$hauteur_img[$src] = $srcHeight = $height;
630
-				}
631
-				if (!$srcSize) {
632
-					$poids_img[$src] = $srcSize = strlen($src);
633
-				}
634
-			}
635
-		}
636
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
637
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
638
-		elseif (
639
-			@file_exists($f = "$src.src")
640
-			and lire_fichier($f, $valeurs)
641
-			and $valeurs = unserialize($valeurs)
642
-		) {
643
-			if (!$srcWidth) {
644
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
645
-			}
646
-			if (!$srcHeight) {
647
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
648
-			}
649
-			if (!$srcSize) {
650
-				$poids_img[$src] = $srcSize = 0;
651
-			}
652
-		}
653
-	}
654
-
655
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
568
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
569
+    $srcWidth = 0;
570
+    $srcHeight = 0;
571
+    $srcSize = null;
572
+
573
+    $src = extraire_attribut($img, 'src');
574
+
575
+    if (!$src) {
576
+        $src = $img;
577
+    } else {
578
+        $srcWidth = extraire_attribut($img, 'width');
579
+        $srcHeight = extraire_attribut($img, 'height');
580
+        if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) {
581
+            $srcWidth = $srcHeight = 0;
582
+        }
583
+    }
584
+
585
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
586
+    // la copie locale a toutes les chances d'etre la ou de resservir
587
+    if (tester_url_absolue($src)) {
588
+        include_spip('inc/distant');
589
+        $fichier = copie_locale($src);
590
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
591
+    }
592
+    if (($p = strpos($src, '?')) !== false) {
593
+        $src = substr($src, 0, $p);
594
+    }
595
+
596
+    $imagesize = false;
597
+    if (isset($largeur_img[$src]) and !$force_refresh) {
598
+        $srcWidth = $largeur_img[$src];
599
+    }
600
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
601
+        $srcHeight = $hauteur_img[$src];
602
+    }
603
+    if (isset($poids_img[$src]) and !$force_refresh) {
604
+        $srcSize = $poids_img[$src];
605
+    }
606
+    if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
607
+        if (
608
+            file_exists($src)
609
+            and $imagesize = spip_getimagesize($src)
610
+        ) {
611
+            if (!$srcWidth) {
612
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
613
+            }
614
+            if (!$srcHeight) {
615
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
616
+            }
617
+            if (!$srcSize) {
618
+                $poids_img[$src] = filesize($src);
619
+            }
620
+        }
621
+        elseif (strpos($src, '<svg') !== false) {
622
+            include_spip('inc/svg');
623
+            if ($attrs = svg_lire_attributs($src)) {
624
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
625
+                if (!$srcWidth) {
626
+                    $largeur_img[$src] = $srcWidth = $width;
627
+                }
628
+                if (!$srcHeight) {
629
+                    $hauteur_img[$src] = $srcHeight = $height;
630
+                }
631
+                if (!$srcSize) {
632
+                    $poids_img[$src] = $srcSize = strlen($src);
633
+                }
634
+            }
635
+        }
636
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
637
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
638
+        elseif (
639
+            @file_exists($f = "$src.src")
640
+            and lire_fichier($f, $valeurs)
641
+            and $valeurs = unserialize($valeurs)
642
+        ) {
643
+            if (!$srcWidth) {
644
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
645
+            }
646
+            if (!$srcHeight) {
647
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
648
+            }
649
+            if (!$srcSize) {
650
+                $poids_img[$src] = $srcSize = 0;
651
+            }
652
+        }
653
+    }
654
+
655
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
656 656
 }
657 657
 
658 658
 /**
@@ -668,13 +668,13 @@  discard block
 block discarded – undo
668 668
  *     poids
669 669
  **/
670 670
 function poids_image($img, $force_refresh = false) {
671
-	$infos = infos_image($img, $force_refresh);
672
-	return $infos['poids'];
671
+    $infos = infos_image($img, $force_refresh);
672
+    return $infos['poids'];
673 673
 }
674 674
 
675 675
 function taille_image($img, $force_refresh = false) {
676
-	$infos = infos_image($img, $force_refresh);
677
-	return [$infos['hauteur'], $infos['largeur']];
676
+    $infos = infos_image($img, $force_refresh);
677
+    return [$infos['hauteur'], $infos['largeur']];
678 678
 }
679 679
 
680 680
 /**
@@ -691,12 +691,12 @@  discard block
 block discarded – undo
691 691
  *     Largeur en pixels, NULL ou 0 si aucune image.
692 692
  **/
693 693
 function largeur($img) {
694
-	if (!$img) {
695
-		return;
696
-	}
697
-	[$h, $l] = taille_image($img);
694
+    if (!$img) {
695
+        return;
696
+    }
697
+    [$h, $l] = taille_image($img);
698 698
 
699
-	return $l;
699
+    return $l;
700 700
 }
701 701
 
702 702
 /**
@@ -713,12 +713,12 @@  discard block
 block discarded – undo
713 713
  *     Hauteur en pixels, NULL ou 0 si aucune image.
714 714
  **/
715 715
 function hauteur($img) {
716
-	if (!$img) {
717
-		return;
718
-	}
719
-	[$h, $l] = taille_image($img);
716
+    if (!$img) {
717
+        return;
718
+    }
719
+    [$h, $l] = taille_image($img);
720 720
 
721
-	return $h;
721
+    return $h;
722 722
 }
723 723
 
724 724
 
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
  * @return string
739 739
  **/
740 740
 function corriger_entites_html($texte) {
741
-	if (strpos($texte, '&amp;') === false) {
742
-		return $texte;
743
-	}
741
+    if (strpos($texte, '&amp;') === false) {
742
+        return $texte;
743
+    }
744 744
 
745
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
745
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
746 746
 }
747 747
 
748 748
 /**
@@ -757,11 +757,11 @@  discard block
 block discarded – undo
757 757
  * @return string
758 758
  **/
759 759
 function corriger_toutes_entites_html($texte) {
760
-	if (strpos($texte, '&amp;') === false) {
761
-		return $texte;
762
-	}
760
+    if (strpos($texte, '&amp;') === false) {
761
+        return $texte;
762
+    }
763 763
 
764
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
764
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
765 765
 }
766 766
 
767 767
 /**
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
  * @return string
772 772
  **/
773 773
 function proteger_amp($texte) {
774
-	return str_replace('&', '&amp;', $texte);
774
+    return str_replace('&', '&amp;', $texte);
775 775
 }
776 776
 
777 777
 
@@ -802,21 +802,21 @@  discard block
 block discarded – undo
802 802
  * @return mixed|string
803 803
  */
804 804
 function entites_html($texte, $tout = false, $quote = true) {
805
-	if (
806
-		!is_string($texte) or !$texte
807
-		or strpbrk($texte, "&\"'<>") == false
808
-	) {
809
-		return $texte;
810
-	}
811
-	include_spip('inc/texte');
812
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
813
-	$flags |= ENT_HTML401;
814
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
815
-	if ($tout) {
816
-		return corriger_toutes_entites_html($texte);
817
-	} else {
818
-		return corriger_entites_html($texte);
819
-	}
805
+    if (
806
+        !is_string($texte) or !$texte
807
+        or strpbrk($texte, "&\"'<>") == false
808
+    ) {
809
+        return $texte;
810
+    }
811
+    include_spip('inc/texte');
812
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
813
+    $flags |= ENT_HTML401;
814
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
815
+    if ($tout) {
816
+        return corriger_toutes_entites_html($texte);
817
+    } else {
818
+        return corriger_entites_html($texte);
819
+    }
820 820
 }
821 821
 
822 822
 /**
@@ -835,38 +835,38 @@  discard block
 block discarded – undo
835 835
  *     texte converti
836 836
  **/
837 837
 function filtrer_entites(?string $texte): string {
838
-	$texte ??= '';
839
-	if (strpos($texte, '&') === false) {
840
-		return $texte;
841
-	}
842
-	// filtrer
843
-	$texte = html2unicode($texte);
844
-	// remettre le tout dans le charset cible
845
-	$texte = unicode2charset($texte);
846
-	// cas particulier des " et ' qu'il faut filtrer aussi
847
-	// (on le faisait deja avec un &quot;)
848
-	if (strpos($texte, '&#') !== false) {
849
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
850
-	}
838
+    $texte ??= '';
839
+    if (strpos($texte, '&') === false) {
840
+        return $texte;
841
+    }
842
+    // filtrer
843
+    $texte = html2unicode($texte);
844
+    // remettre le tout dans le charset cible
845
+    $texte = unicode2charset($texte);
846
+    // cas particulier des " et ' qu'il faut filtrer aussi
847
+    // (on le faisait deja avec un &quot;)
848
+    if (strpos($texte, '&#') !== false) {
849
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
850
+    }
851 851
 
852
-	return $texte;
852
+    return $texte;
853 853
 }
854 854
 
855 855
 
856 856
 if (!function_exists('filtre_filtrer_entites_dist')) {
857
-	/**
858
-	 * Version sécurisée de filtrer_entites
859
-	 *
860
-	 * @uses interdire_scripts()
861
-	 * @uses filtrer_entites()
862
-	 *
863
-	 * @param string $t
864
-	 * @return string
865
-	 */
866
-	function filtre_filtrer_entites_dist($t) {
867
-		include_spip('inc/texte');
868
-		return interdire_scripts(filtrer_entites($t));
869
-	}
857
+    /**
858
+     * Version sécurisée de filtrer_entites
859
+     *
860
+     * @uses interdire_scripts()
861
+     * @uses filtrer_entites()
862
+     *
863
+     * @param string $t
864
+     * @return string
865
+     */
866
+    function filtre_filtrer_entites_dist($t) {
867
+        include_spip('inc/texte');
868
+        return interdire_scripts(filtrer_entites($t));
869
+    }
870 870
 }
871 871
 
872 872
 
@@ -881,18 +881,18 @@  discard block
 block discarded – undo
881 881
  * @return string|array
882 882
  **/
883 883
 function supprimer_caracteres_illegaux($texte) {
884
-	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";
885
-	static $to = null;
884
+    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";
885
+    static $to = null;
886 886
 
887
-	if (is_array($texte)) {
888
-		return array_map('supprimer_caracteres_illegaux', $texte);
889
-	}
887
+    if (is_array($texte)) {
888
+        return array_map('supprimer_caracteres_illegaux', $texte);
889
+    }
890 890
 
891
-	if (!$to) {
892
-		$to = str_repeat('-', strlen($from));
893
-	}
891
+    if (!$to) {
892
+        $to = str_repeat('-', strlen($from));
893
+    }
894 894
 
895
-	return strtr($texte, $from, $to);
895
+    return strtr($texte, $from, $to);
896 896
 }
897 897
 
898 898
 /**
@@ -904,10 +904,10 @@  discard block
 block discarded – undo
904 904
  * @return string|array
905 905
  **/
906 906
 function corriger_caracteres($texte) {
907
-	$texte = corriger_caracteres_windows($texte);
908
-	$texte = supprimer_caracteres_illegaux($texte);
907
+    $texte = corriger_caracteres_windows($texte);
908
+    $texte = supprimer_caracteres_illegaux($texte);
909 909
 
910
-	return $texte;
910
+    return $texte;
911 911
 }
912 912
 
913 913
 /**
@@ -924,44 +924,44 @@  discard block
 block discarded – undo
924 924
  *     texte encodé pour XML
925 925
  */
926 926
 function texte_backend(string $texte): string {
927
-	if ($texte === '') {
928
-		return '';
929
-	}
927
+    if ($texte === '') {
928
+        return '';
929
+    }
930 930
 
931
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
931
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
932 932
 
933
-	// si on a des liens ou des images, les passer en absolu
934
-	$texte = liens_absolus($texte);
933
+    // si on a des liens ou des images, les passer en absolu
934
+    $texte = liens_absolus($texte);
935 935
 
936
-	// echapper les tags &gt; &lt;
937
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
936
+    // echapper les tags &gt; &lt;
937
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
938 938
 
939
-	// importer les &eacute;
940
-	$texte = filtrer_entites($texte);
939
+    // importer les &eacute;
940
+    $texte = filtrer_entites($texte);
941 941
 
942
-	// " -> &quot; et tout ce genre de choses
943
-	$u = $GLOBALS['meta']['pcre_u'];
944
-	$texte = str_replace('&nbsp;', ' ', $texte);
945
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
946
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
947
-	$texte = entites_html($texte, false, false);
948
-	// mais bien echapper les double quotes !
949
-	$texte = str_replace('"', '&#034;', $texte);
942
+    // " -> &quot; et tout ce genre de choses
943
+    $u = $GLOBALS['meta']['pcre_u'];
944
+    $texte = str_replace('&nbsp;', ' ', $texte);
945
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
946
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
947
+    $texte = entites_html($texte, false, false);
948
+    // mais bien echapper les double quotes !
949
+    $texte = str_replace('"', '&#034;', $texte);
950 950
 
951
-	// verifier le charset
952
-	$texte = charset2unicode($texte);
951
+    // verifier le charset
952
+    $texte = charset2unicode($texte);
953 953
 
954
-	// Caracteres problematiques en iso-latin 1
955
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
956
-		$texte = str_replace(chr(156), '&#156;', $texte);
957
-		$texte = str_replace(chr(140), '&#140;', $texte);
958
-		$texte = str_replace(chr(159), '&#159;', $texte);
959
-	}
954
+    // Caracteres problematiques en iso-latin 1
955
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
956
+        $texte = str_replace(chr(156), '&#156;', $texte);
957
+        $texte = str_replace(chr(140), '&#140;', $texte);
958
+        $texte = str_replace(chr(159), '&#159;', $texte);
959
+    }
960 960
 
961
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
962
-	// et le caractere apostrophe alourdit les squelettes avec PHP
963
-	// ==> on les remplace par l'entite HTML
964
-	return str_replace($apostrophe, "'", $texte);
961
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
962
+    // et le caractere apostrophe alourdit les squelettes avec PHP
963
+    // ==> on les remplace par l'entite HTML
964
+    return str_replace($apostrophe, "'", $texte);
965 965
 }
966 966
 
967 967
 /**
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
  *     texte encodé et quote pour XML
979 979
  */
980 980
 function texte_backendq(string $texte): string {
981
-	return addslashes(texte_backend($texte));
981
+    return addslashes(texte_backend($texte));
982 982
 }
983 983
 
984 984
 
@@ -1000,14 +1000,14 @@  discard block
 block discarded – undo
1000 1000
  *     Texte sans son numéro éventuel
1001 1001
  **/
1002 1002
 function supprimer_numero(?string $texte): string {
1003
-	if ($texte === null) {
1004
-		return '';
1005
-	}
1006
-	return preg_replace(
1007
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1008
-		'',
1009
-		$texte
1010
-	);
1003
+    if ($texte === null) {
1004
+        return '';
1005
+    }
1006
+    return preg_replace(
1007
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1008
+        '',
1009
+        $texte
1010
+    );
1011 1011
 }
1012 1012
 
1013 1013
 /**
@@ -1030,18 +1030,18 @@  discard block
 block discarded – undo
1030 1030
  *     Numéro de titre, sinon chaîne vide
1031 1031
  **/
1032 1032
 function recuperer_numero(?string $texte): string {
1033
-	if (
1034
-		$texte and
1035
-		preg_match(
1036
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1037
-			$texte,
1038
-			$regs
1039
-		)
1040
-	) {
1041
-		return strval($regs[1]);
1042
-	} else {
1043
-		return '';
1044
-	}
1033
+    if (
1034
+        $texte and
1035
+        preg_match(
1036
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1037
+            $texte,
1038
+            $regs
1039
+        )
1040
+    ) {
1041
+        return strval($regs[1]);
1042
+    } else {
1043
+        return '';
1044
+    }
1045 1045
 }
1046 1046
 
1047 1047
 /**
@@ -1068,16 +1068,16 @@  discard block
 block discarded – undo
1068 1068
  *     texte ou tableau de textes converti
1069 1069
  **/
1070 1070
 function supprimer_tags($texte, $rempl = '') {
1071
-	if ($texte === null) {
1072
-		return '';
1073
-	}
1074
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1075
-	// ne pas oublier un < final non ferme car coupe
1076
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1077
-	// mais qui peut aussi etre un simple signe plus petit que
1078
-	$texte = str_replace('<', '&lt;', $texte);
1071
+    if ($texte === null) {
1072
+        return '';
1073
+    }
1074
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1075
+    // ne pas oublier un < final non ferme car coupe
1076
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1077
+    // mais qui peut aussi etre un simple signe plus petit que
1078
+    $texte = str_replace('<', '&lt;', $texte);
1079 1079
 
1080
-	return $texte;
1080
+    return $texte;
1081 1081
 }
1082 1082
 
1083 1083
 /**
@@ -1100,9 +1100,9 @@  discard block
 block discarded – undo
1100 1100
  *     texte converti
1101 1101
  **/
1102 1102
 function echapper_tags($texte, $rempl = '') {
1103
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1103
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1104 1104
 
1105
-	return $texte;
1105
+    return $texte;
1106 1106
 }
1107 1107
 
1108 1108
 /**
@@ -1123,18 +1123,18 @@  discard block
 block discarded – undo
1123 1123
  *     texte converti
1124 1124
  **/
1125 1125
 function textebrut($texte) {
1126
-	$u = $GLOBALS['meta']['pcre_u'];
1127
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1128
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1129
-	$texte = preg_replace("/^\n+/", '', $texte);
1130
-	$texte = preg_replace("/\n+$/", '', $texte);
1131
-	$texte = preg_replace("/\n +/", "\n", $texte);
1132
-	$texte = supprimer_tags($texte);
1133
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1134
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1135
-	$texte = str_replace('&#8217;', "'", $texte);
1126
+    $u = $GLOBALS['meta']['pcre_u'];
1127
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1128
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1129
+    $texte = preg_replace("/^\n+/", '', $texte);
1130
+    $texte = preg_replace("/\n+$/", '', $texte);
1131
+    $texte = preg_replace("/\n +/", "\n", $texte);
1132
+    $texte = supprimer_tags($texte);
1133
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1134
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1135
+    $texte = str_replace('&#8217;', "'", $texte);
1136 1136
 
1137
-	return $texte;
1137
+    return $texte;
1138 1138
 }
1139 1139
 
1140 1140
 
@@ -1150,23 +1150,23 @@  discard block
 block discarded – undo
1150 1150
  *     texte avec liens ouvrants
1151 1151
  **/
1152 1152
 function liens_ouvrants($texte) {
1153
-	if (
1154
-		preg_match_all(
1155
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1156
-			$texte,
1157
-			$liens,
1158
-			PREG_PATTERN_ORDER
1159
-		)
1160
-	) {
1161
-		foreach ($liens[0] as $a) {
1162
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1163
-			$ablank = inserer_attribut($a, 'rel', $rel);
1164
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1165
-			$texte = str_replace($a, $ablank, $texte);
1166
-		}
1167
-	}
1168
-
1169
-	return $texte;
1153
+    if (
1154
+        preg_match_all(
1155
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1156
+            $texte,
1157
+            $liens,
1158
+            PREG_PATTERN_ORDER
1159
+        )
1160
+    ) {
1161
+        foreach ($liens[0] as $a) {
1162
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1163
+            $ablank = inserer_attribut($a, 'rel', $rel);
1164
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1165
+            $texte = str_replace($a, $ablank, $texte);
1166
+        }
1167
+    }
1168
+
1169
+    return $texte;
1170 1170
 }
1171 1171
 
1172 1172
 /**
@@ -1176,22 +1176,22 @@  discard block
 block discarded – undo
1176 1176
  * @return string
1177 1177
  */
1178 1178
 function liens_nofollow($texte) {
1179
-	if (stripos($texte, '<a') === false) {
1180
-		return $texte;
1181
-	}
1179
+    if (stripos($texte, '<a') === false) {
1180
+        return $texte;
1181
+    }
1182 1182
 
1183
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1184
-		foreach ($regs[0] as $a) {
1185
-			$rel = extraire_attribut($a, 'rel') ?? '';
1186
-			if (strpos($rel, 'nofollow') === false) {
1187
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1188
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1189
-				$texte = str_replace($a, $anofollow, $texte);
1190
-			}
1191
-		}
1192
-	}
1183
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1184
+        foreach ($regs[0] as $a) {
1185
+            $rel = extraire_attribut($a, 'rel') ?? '';
1186
+            if (strpos($rel, 'nofollow') === false) {
1187
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1188
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1189
+                $texte = str_replace($a, $anofollow, $texte);
1190
+            }
1191
+        }
1192
+    }
1193 1193
 
1194
-	return $texte;
1194
+    return $texte;
1195 1195
 }
1196 1196
 
1197 1197
 /**
@@ -1210,12 +1210,12 @@  discard block
 block discarded – undo
1210 1210
  *     texte sans paraghaphes
1211 1211
  **/
1212 1212
 function PtoBR($texte) {
1213
-	$u = $GLOBALS['meta']['pcre_u'];
1214
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1215
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1216
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1213
+    $u = $GLOBALS['meta']['pcre_u'];
1214
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1215
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1216
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1217 1217
 
1218
-	return $texte;
1218
+    return $texte;
1219 1219
 }
1220 1220
 
1221 1221
 
@@ -1240,14 +1240,14 @@  discard block
 block discarded – undo
1240 1240
  * @return string texte encadré du style CSS
1241 1241
  */
1242 1242
 function lignes_longues($texte) {
1243
-	if (!strlen(trim($texte))) {
1244
-		return $texte;
1245
-	}
1246
-	include_spip('inc/texte');
1247
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1248
-		'div' : 'span';
1243
+    if (!strlen(trim($texte))) {
1244
+        return $texte;
1245
+    }
1246
+    include_spip('inc/texte');
1247
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1248
+        'div' : 'span';
1249 1249
 
1250
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1250
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1251 1251
 }
1252 1252
 
1253 1253
 /**
@@ -1266,30 +1266,30 @@  discard block
 block discarded – undo
1266 1266
  * @return string texte en majuscule
1267 1267
  */
1268 1268
 function majuscules($texte) {
1269
-	if (!strlen($texte)) {
1270
-		return '';
1271
-	}
1269
+    if (!strlen($texte)) {
1270
+        return '';
1271
+    }
1272 1272
 
1273
-	// Cas du turc
1274
-	if ($GLOBALS['spip_lang'] == 'tr') {
1275
-		# remplacer hors des tags et des entites
1276
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1277
-			foreach ($regs as $n => $match) {
1278
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1279
-			}
1280
-		}
1273
+    // Cas du turc
1274
+    if ($GLOBALS['spip_lang'] == 'tr') {
1275
+        # remplacer hors des tags et des entites
1276
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1277
+            foreach ($regs as $n => $match) {
1278
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1279
+            }
1280
+        }
1281 1281
 
1282
-		$texte = str_replace('i', '&#304;', $texte);
1282
+        $texte = str_replace('i', '&#304;', $texte);
1283 1283
 
1284
-		if ($regs) {
1285
-			foreach ($regs as $n => $match) {
1286
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1287
-			}
1288
-		}
1289
-	}
1284
+        if ($regs) {
1285
+            foreach ($regs as $n => $match) {
1286
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1287
+            }
1288
+        }
1289
+    }
1290 1290
 
1291
-	// Cas general
1292
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1291
+    // Cas general
1292
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1293 1293
 }
1294 1294
 
1295 1295
 /**
@@ -1311,38 +1311,38 @@  discard block
 block discarded – undo
1311 1311
  */
1312 1312
 function taille_en_octets($octets, $systeme = 'BI') {
1313 1313
 
1314
-	// Texte à afficher pour la taille
1315
-	$affichage = '';
1314
+    // Texte à afficher pour la taille
1315
+    $affichage = '';
1316 1316
 
1317
-	static $unites = ['octets', 'ko', 'mo', 'go'];
1318
-	static $precisions = [0, 1, 1, 2];
1317
+    static $unites = ['octets', 'ko', 'mo', 'go'];
1318
+    static $precisions = [0, 1, 1, 2];
1319 1319
 
1320
-	if ($octets >= 1) {
1321
-		// Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1322
-		$systeme = strtolower($systeme);
1323
-		if ($systeme === 'bi') {
1324
-			$kilo = 1024;
1325
-			$suffixe_item = "_$systeme";
1326
-		} elseif ($systeme === 'si') {
1327
-			$kilo = 1000;
1328
-			$suffixe_item = '';
1329
-		} else {
1330
-			return $affichage;
1331
-		}
1320
+    if ($octets >= 1) {
1321
+        // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1322
+        $systeme = strtolower($systeme);
1323
+        if ($systeme === 'bi') {
1324
+            $kilo = 1024;
1325
+            $suffixe_item = "_$systeme";
1326
+        } elseif ($systeme === 'si') {
1327
+            $kilo = 1000;
1328
+            $suffixe_item = '';
1329
+        } else {
1330
+            return $affichage;
1331
+        }
1332 1332
 
1333
-		// Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1334
-		$puissance = floor(log($octets, $kilo));
1333
+        // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1334
+        $puissance = floor(log($octets, $kilo));
1335 1335
 
1336
-		// Calcul de la taille et choix de l'unité
1337
-		$affichage = _T(
1338
-			'spip:taille_' . $unites[$puissance] . $suffixe_item,
1339
-			[
1340
-				'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance])
1341
-			]
1342
-		);
1343
-	}
1336
+        // Calcul de la taille et choix de l'unité
1337
+        $affichage = _T(
1338
+            'spip:taille_' . $unites[$puissance] . $suffixe_item,
1339
+            [
1340
+                'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance])
1341
+            ]
1342
+        );
1343
+    }
1344 1344
 
1345
-	return $affichage;
1345
+    return $affichage;
1346 1346
 }
1347 1347
 
1348 1348
 
@@ -1364,21 +1364,21 @@  discard block
 block discarded – undo
1364 1364
  *     texte prêt pour être utilisé en attribut HTML
1365 1365
  **/
1366 1366
 function attribut_html(?string $texte, $textebrut = true): string {
1367
-	if ($texte === null) {
1368
-		return '';
1369
-	}
1370
-	$u = $GLOBALS['meta']['pcre_u'];
1371
-	if ($textebrut) {
1372
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1373
-	}
1374
-	$texte = texte_backend($texte);
1375
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1367
+    if ($texte === null) {
1368
+        return '';
1369
+    }
1370
+    $u = $GLOBALS['meta']['pcre_u'];
1371
+    if ($textebrut) {
1372
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1373
+    }
1374
+    $texte = texte_backend($texte);
1375
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1376 1376
 
1377
-	return preg_replace(
1378
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1379
-		['&', '&#38;'],
1380
-		$texte
1381
-	);
1377
+    return preg_replace(
1378
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1379
+        ['&', '&#38;'],
1380
+        $texte
1381
+    );
1382 1382
 }
1383 1383
 
1384 1384
 
@@ -1398,15 +1398,15 @@  discard block
 block discarded – undo
1398 1398
  *     URL ou chaîne vide
1399 1399
  **/
1400 1400
 function vider_url(?string $url, $entites = true): string {
1401
-	if ($url === null) {
1402
-		return '';
1403
-	}
1404
-	# un message pour abs_url
1405
-	$GLOBALS['mode_abs_url'] = 'url';
1406
-	$url = trim($url);
1407
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1401
+    if ($url === null) {
1402
+        return '';
1403
+    }
1404
+    # un message pour abs_url
1405
+    $GLOBALS['mode_abs_url'] = 'url';
1406
+    $url = trim($url);
1407
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1408 1408
 
1409
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1409
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1410 1410
 }
1411 1411
 
1412 1412
 
@@ -1421,10 +1421,10 @@  discard block
 block discarded – undo
1421 1421
  * @return string Adresse email maquillée
1422 1422
  **/
1423 1423
 function antispam($texte) {
1424
-	include_spip('inc/acces');
1425
-	$masque = creer_pass_aleatoire(3);
1424
+    include_spip('inc/acces');
1425
+    $masque = creer_pass_aleatoire(3);
1426 1426
 
1427
-	return preg_replace('/@/', " $masque ", $texte);
1427
+    return preg_replace('/@/', " $masque ", $texte);
1428 1428
 }
1429 1429
 
1430 1430
 /**
@@ -1456,8 +1456,8 @@  discard block
 block discarded – undo
1456 1456
  *     True si on a le droit d'accès, false sinon.
1457 1457
  **/
1458 1458
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1459
-	include_spip('inc/acces');
1460
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1459
+    include_spip('inc/acces');
1460
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1461 1461
 }
1462 1462
 
1463 1463
 /**
@@ -1481,13 +1481,13 @@  discard block
 block discarded – undo
1481 1481
  *     Retourne $texte, sinon $sinon.
1482 1482
  **/
1483 1483
 function sinon($texte, $sinon = '') {
1484
-	if ($texte) {
1485
-		return $texte;
1486
-	} elseif (is_scalar($texte) and strlen($texte)) {
1487
-		return $texte;
1488
-	} else {
1489
-		return $sinon;
1490
-	}
1484
+    if ($texte) {
1485
+        return $texte;
1486
+    } elseif (is_scalar($texte) and strlen($texte)) {
1487
+        return $texte;
1488
+    } else {
1489
+        return $sinon;
1490
+    }
1491 1491
 }
1492 1492
 
1493 1493
 /**
@@ -1511,7 +1511,7 @@  discard block
 block discarded – undo
1511 1511
  * @return mixed
1512 1512
  **/
1513 1513
 function choixsivide($a, $vide, $pasvide) {
1514
-	return $a ? $pasvide : $vide;
1514
+    return $a ? $pasvide : $vide;
1515 1515
 }
1516 1516
 
1517 1517
 /**
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
  * @return mixed
1536 1536
  **/
1537 1537
 function choixsiegal($a1, $a2, $v, $f) {
1538
-	return ($a1 == $a2) ? $v : $f;
1538
+    return ($a1 == $a2) ? $v : $f;
1539 1539
 }
1540 1540
 
1541 1541
 //
@@ -1554,13 +1554,13 @@  discard block
 block discarded – undo
1554 1554
  * @return string
1555 1555
  **/
1556 1556
 function filtrer_ical($texte) {
1557
-	#include_spip('inc/charsets');
1558
-	$texte = html2unicode($texte);
1559
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1560
-	$texte = preg_replace("/\n/", ' ', $texte);
1561
-	$texte = preg_replace('/,/', '\,', $texte);
1557
+    #include_spip('inc/charsets');
1558
+    $texte = html2unicode($texte);
1559
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1560
+    $texte = preg_replace("/\n/", ' ', $texte);
1561
+    $texte = preg_replace('/,/', '\,', $texte);
1562 1562
 
1563
-	return $texte;
1563
+    return $texte;
1564 1564
 }
1565 1565
 
1566 1566
 
@@ -1585,58 +1585,58 @@  discard block
 block discarded – undo
1585 1585
  * @return string
1586 1586
  **/
1587 1587
 function post_autobr($texte, $delim = "\n_ ") {
1588
-	if (!function_exists('echappe_html')) {
1589
-		include_spip('inc/texte_mini');
1590
-	}
1591
-	$texte = str_replace("\r\n", "\r", $texte);
1592
-	$texte = str_replace("\r", "\n", $texte);
1593
-
1594
-	if (preg_match(",\n+$,", $texte, $fin)) {
1595
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1596
-	} else {
1597
-		$fin = '';
1598
-	}
1599
-
1600
-	$texte = echappe_html($texte, '', true);
1601
-
1602
-	// echapper les modeles
1603
-	$collecteurModeles = null;
1604
-	if (strpos($texte, '<') !== false) {
1605
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1606
-		include_spip("src/Texte/Collecteur/Modeles");
1607
-		$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1608
-		$texte = $collecteurModeles->echapper($texte);
1609
-	}
1610
-
1611
-	$debut = '';
1612
-	$suite = $texte;
1613
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1614
-		$debut .= substr($suite, 0, $t - 1);
1615
-		$suite = substr($suite, $t);
1616
-		$car = substr($suite, 0, 1);
1617
-		if (
1618
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1619
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1620
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1621
-		) {
1622
-			$debut .= $delim;
1623
-		} else {
1624
-			$debut .= "\n";
1625
-		}
1626
-		if (preg_match(",^\n+,", $suite, $regs)) {
1627
-			$debut .= $regs[0];
1628
-			$suite = substr($suite, strlen($regs[0]));
1629
-		}
1630
-	}
1631
-	$texte = $debut . $suite;
1632
-
1633
-	if ($collecteurModeles) {
1634
-		$texte = $collecteurModeles->retablir($texte);
1635
-	}
1636
-
1637
-	$texte = echappe_retour($texte);
1638
-
1639
-	return $texte . $fin;
1588
+    if (!function_exists('echappe_html')) {
1589
+        include_spip('inc/texte_mini');
1590
+    }
1591
+    $texte = str_replace("\r\n", "\r", $texte);
1592
+    $texte = str_replace("\r", "\n", $texte);
1593
+
1594
+    if (preg_match(",\n+$,", $texte, $fin)) {
1595
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1596
+    } else {
1597
+        $fin = '';
1598
+    }
1599
+
1600
+    $texte = echappe_html($texte, '', true);
1601
+
1602
+    // echapper les modeles
1603
+    $collecteurModeles = null;
1604
+    if (strpos($texte, '<') !== false) {
1605
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1606
+        include_spip("src/Texte/Collecteur/Modeles");
1607
+        $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1608
+        $texte = $collecteurModeles->echapper($texte);
1609
+    }
1610
+
1611
+    $debut = '';
1612
+    $suite = $texte;
1613
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1614
+        $debut .= substr($suite, 0, $t - 1);
1615
+        $suite = substr($suite, $t);
1616
+        $car = substr($suite, 0, 1);
1617
+        if (
1618
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1619
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1620
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1621
+        ) {
1622
+            $debut .= $delim;
1623
+        } else {
1624
+            $debut .= "\n";
1625
+        }
1626
+        if (preg_match(",^\n+,", $suite, $regs)) {
1627
+            $debut .= $regs[0];
1628
+            $suite = substr($suite, strlen($regs[0]));
1629
+        }
1630
+    }
1631
+    $texte = $debut . $suite;
1632
+
1633
+    if ($collecteurModeles) {
1634
+        $texte = $collecteurModeles->retablir($texte);
1635
+    }
1636
+
1637
+    $texte = echappe_retour($texte);
1638
+
1639
+    return $texte . $fin;
1640 1640
 }
1641 1641
 
1642 1642
 
@@ -1671,30 +1671,30 @@  discard block
 block discarded – undo
1671 1671
  **/
1672 1672
 function extraire_idiome($letexte, $lang = null, $options = []) {
1673 1673
 
1674
-	if (
1675
-		$letexte
1676
-		and strpos($letexte, '<:') !== false
1677
-	) {
1678
-		if (!$lang) {
1679
-			$lang = $GLOBALS['spip_lang'];
1680
-		}
1681
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1682
-		if (is_bool($options)) {
1683
-			$options = ['echappe_span' => $options];
1684
-		}
1685
-		if (!isset($options['echappe_span'])) {
1686
-			$options = array_merge($options, ['echappe_span' => false]);
1687
-		}
1688
-		$options['lang'] = $lang;
1674
+    if (
1675
+        $letexte
1676
+        and strpos($letexte, '<:') !== false
1677
+    ) {
1678
+        if (!$lang) {
1679
+            $lang = $GLOBALS['spip_lang'];
1680
+        }
1681
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1682
+        if (is_bool($options)) {
1683
+            $options = ['echappe_span' => $options];
1684
+        }
1685
+        if (!isset($options['echappe_span'])) {
1686
+            $options = array_merge($options, ['echappe_span' => false]);
1687
+        }
1688
+        $options['lang'] = $lang;
1689 1689
 
1690
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1691
-		include_spip("src/Texte/Collecteur/Idiomes");
1692
-		$collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1690
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1691
+        include_spip("src/Texte/Collecteur/Idiomes");
1692
+        $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1693 1693
 
1694
-		$letexte = $collecteurIdiomes->traiter($letexte, $options);
1694
+        $letexte = $collecteurIdiomes->traiter($letexte, $options);
1695 1695
 
1696
-	}
1697
-	return $letexte;
1696
+    }
1697
+    return $letexte;
1698 1698
 }
1699 1699
 
1700 1700
 /**
@@ -1732,34 +1732,34 @@  discard block
 block discarded – undo
1732 1732
  **/
1733 1733
 function extraire_multi($letexte, $lang = null, $options = []) {
1734 1734
 
1735
-	if (
1736
-		$letexte
1737
-		and stripos($letexte, '<multi') !== false
1738
-	) {
1739
-		if (!$lang) {
1740
-			$lang = $GLOBALS['spip_lang'];
1741
-		}
1735
+    if (
1736
+        $letexte
1737
+        and stripos($letexte, '<multi') !== false
1738
+    ) {
1739
+        if (!$lang) {
1740
+            $lang = $GLOBALS['spip_lang'];
1741
+        }
1742 1742
 
1743
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1744
-		if (is_bool($options)) {
1745
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1746
-		}
1747
-		if (!isset($options['echappe_span'])) {
1748
-			$options = array_merge($options, ['echappe_span' => false]);
1749
-		}
1750
-		if (!isset($options['lang_defaut'])) {
1751
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1752
-		}
1753
-		$options['lang'] = $lang;
1743
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1744
+        if (is_bool($options)) {
1745
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1746
+        }
1747
+        if (!isset($options['echappe_span'])) {
1748
+            $options = array_merge($options, ['echappe_span' => false]);
1749
+        }
1750
+        if (!isset($options['lang_defaut'])) {
1751
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1752
+        }
1753
+        $options['lang'] = $lang;
1754 1754
 
1755
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1756
-		include_spip("src/Texte/Collecteur/Multis");
1757
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
1755
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1756
+        include_spip("src/Texte/Collecteur/Multis");
1757
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
1758 1758
 
1759
-		$letexte = $collecteurMultis->traiter($letexte, $options);
1760
-	}
1759
+        $letexte = $collecteurMultis->traiter($letexte, $options);
1760
+    }
1761 1761
 
1762
-	return $letexte;
1762
+    return $letexte;
1763 1763
 }
1764 1764
 
1765 1765
 /**
@@ -1769,7 +1769,7 @@  discard block
 block discarded – undo
1769 1769
  * @return string L'initiale en majuscule
1770 1770
  */
1771 1771
 function filtre_initiale($nom) {
1772
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1772
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1773 1773
 }
1774 1774
 
1775 1775
 
@@ -1814,33 +1814,33 @@  discard block
 block discarded – undo
1814 1814
  *      - null (interne) : si on empile
1815 1815
  **/
1816 1816
 function unique($donnee, $famille = '', $cpt = false) {
1817
-	static $mem = [];
1818
-	// permettre de vider la pile et de la restaurer
1819
-	// pour le calcul de introduction...
1820
-	if ($famille == '_spip_raz_') {
1821
-		$tmp = $mem;
1822
-		$mem = [];
1823
-
1824
-		return $tmp;
1825
-	} elseif ($famille == '_spip_set_') {
1826
-		$mem = $donnee;
1827
-
1828
-		return;
1829
-	}
1830
-	// eviter une notice
1831
-	if (!isset($mem[$famille])) {
1832
-		$mem[$famille] = [];
1833
-	}
1834
-	if ($cpt) {
1835
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1836
-	}
1837
-	// eviter une notice
1838
-	if (!isset($mem[$famille][$donnee])) {
1839
-		$mem[$famille][$donnee] = 0;
1840
-	}
1841
-	if (!($mem[$famille][$donnee]++)) {
1842
-		return $donnee;
1843
-	}
1817
+    static $mem = [];
1818
+    // permettre de vider la pile et de la restaurer
1819
+    // pour le calcul de introduction...
1820
+    if ($famille == '_spip_raz_') {
1821
+        $tmp = $mem;
1822
+        $mem = [];
1823
+
1824
+        return $tmp;
1825
+    } elseif ($famille == '_spip_set_') {
1826
+        $mem = $donnee;
1827
+
1828
+        return;
1829
+    }
1830
+    // eviter une notice
1831
+    if (!isset($mem[$famille])) {
1832
+        $mem[$famille] = [];
1833
+    }
1834
+    if ($cpt) {
1835
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1836
+    }
1837
+    // eviter une notice
1838
+    if (!isset($mem[$famille][$donnee])) {
1839
+        $mem[$famille][$donnee] = 0;
1840
+    }
1841
+    if (!($mem[$famille][$donnee]++)) {
1842
+        return $donnee;
1843
+    }
1844 1844
 }
1845 1845
 
1846 1846
 
@@ -1870,20 +1870,20 @@  discard block
 block discarded – undo
1870 1870
  *     Une des valeurs en fonction du compteur.
1871 1871
  **/
1872 1872
 function alterner($i, ...$args) {
1873
-	// recuperer les arguments (attention fonctions un peu space)
1874
-	$num = count($args);
1873
+    // recuperer les arguments (attention fonctions un peu space)
1874
+    $num = count($args);
1875 1875
 
1876
-	if ($num === 1 && is_array($args[0])) {
1877
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1878
-		$args = array_values($args[0]);
1879
-		$num = count($args);
1880
-	}
1876
+    if ($num === 1 && is_array($args[0])) {
1877
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1878
+        $args = array_values($args[0]);
1879
+        $num = count($args);
1880
+    }
1881 1881
 
1882
-	// un index compris entre 0 et num exclus
1883
-	$i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1884
-	$i = ($i + $num) % $num; // dans [0;$num[
1885
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1886
-	return $args[$i];
1882
+    // un index compris entre 0 et num exclus
1883
+    $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1884
+    $i = ($i + $num) % $num; // dans [0;$num[
1885
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1886
+    return $args[$i];
1887 1887
 }
1888 1888
 
1889 1889
 
@@ -1909,52 +1909,52 @@  discard block
 block discarded – undo
1909 1909
  *     - null lorsque l’attribut n’existe pas.
1910 1910
  **/
1911 1911
 function extraire_attribut($balise, $attribut, $complet = false) {
1912
-	if (is_array($balise)) {
1913
-		array_walk(
1914
-			$balise,
1915
-			function (&$a, $key, $t) {
1916
-				$a = extraire_attribut($a, $t);
1917
-			},
1918
-			$attribut
1919
-		);
1920
-
1921
-		return $balise;
1922
-	}
1923
-	if (
1924
-		$balise
1925
-		&& stripos($balise, $attribut) !== false
1926
-		&& preg_match(
1927
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1928
-			. $attribut
1929
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1930
-			$balise,
1931
-			$r
1932
-		)
1933
-	) {
1934
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1935
-			$r[4] = substr($r[3], 1, -1);
1936
-			$r[3] = $r[3][0];
1937
-		} elseif ($r[3] !== '') {
1938
-			$r[4] = $r[3];
1939
-			$r[3] = '';
1940
-		} else {
1941
-			$r[4] = trim($r[2]);
1942
-		}
1943
-		$att = $r[4];
1944
-		if (strpos($att, '&#') !== false) {
1945
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1946
-		}
1947
-		$att = filtrer_entites($att);
1948
-	} else {
1949
-		$att = null;
1950
-		$r = [];
1951
-	}
1952
-
1953
-	if ($complet) {
1954
-		return [$att, $r];
1955
-	} else {
1956
-		return $att;
1957
-	}
1912
+    if (is_array($balise)) {
1913
+        array_walk(
1914
+            $balise,
1915
+            function (&$a, $key, $t) {
1916
+                $a = extraire_attribut($a, $t);
1917
+            },
1918
+            $attribut
1919
+        );
1920
+
1921
+        return $balise;
1922
+    }
1923
+    if (
1924
+        $balise
1925
+        && stripos($balise, $attribut) !== false
1926
+        && preg_match(
1927
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1928
+            . $attribut
1929
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1930
+            $balise,
1931
+            $r
1932
+        )
1933
+    ) {
1934
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1935
+            $r[4] = substr($r[3], 1, -1);
1936
+            $r[3] = $r[3][0];
1937
+        } elseif ($r[3] !== '') {
1938
+            $r[4] = $r[3];
1939
+            $r[3] = '';
1940
+        } else {
1941
+            $r[4] = trim($r[2]);
1942
+        }
1943
+        $att = $r[4];
1944
+        if (strpos($att, '&#') !== false) {
1945
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1946
+        }
1947
+        $att = filtrer_entites($att);
1948
+    } else {
1949
+        $att = null;
1950
+        $r = [];
1951
+    }
1952
+
1953
+    if ($complet) {
1954
+        return [$att, $r];
1955
+    } else {
1956
+        return $att;
1957
+    }
1958 1958
 }
1959 1959
 
1960 1960
 /**
@@ -1987,41 +1987,41 @@  discard block
 block discarded – undo
1987 1987
  **/
1988 1988
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
1989 1989
 
1990
-	if ($balise === null or $balise === '') {
1991
-		return '';
1992
-	}
1990
+    if ($balise === null or $balise === '') {
1991
+        return '';
1992
+    }
1993 1993
 
1994
-	// preparer l'attribut
1995
-	// supprimer les &nbsp; etc mais pas les balises html
1996
-	// qui ont un sens dans un attribut value d'un input
1997
-	if ($proteger) {
1998
-		$val = attribut_html($val, false);
1999
-	}
1994
+    // preparer l'attribut
1995
+    // supprimer les &nbsp; etc mais pas les balises html
1996
+    // qui ont un sens dans un attribut value d'un input
1997
+    if ($proteger) {
1998
+        $val = attribut_html($val, false);
1999
+    }
2000 2000
 
2001
-	// echapper les ' pour eviter tout bug
2002
-	$val = str_replace("'", '&#039;', $val);
2003
-	if ($vider and strlen($val) === 0) {
2004
-		$insert = '';
2005
-	} else {
2006
-		$insert = " $attribut='$val'";
2007
-	}
2001
+    // echapper les ' pour eviter tout bug
2002
+    $val = str_replace("'", '&#039;', $val);
2003
+    if ($vider and strlen($val) === 0) {
2004
+        $insert = '';
2005
+    } else {
2006
+        $insert = " $attribut='$val'";
2007
+    }
2008 2008
 
2009
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2009
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2010 2010
 
2011
-	if ($old !== null) {
2012
-		// Remplacer l'ancien attribut du meme nom
2013
-		$balise = $r[1] . $insert . $r[5];
2014
-	} else {
2015
-		// preferer une balise " />" (comme <img />)
2016
-		if (preg_match(',/>,', $balise)) {
2017
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2018
-		} // sinon une balise <a ...> ... </a>
2019
-		else {
2020
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2021
-		}
2022
-	}
2011
+    if ($old !== null) {
2012
+        // Remplacer l'ancien attribut du meme nom
2013
+        $balise = $r[1] . $insert . $r[5];
2014
+    } else {
2015
+        // preferer une balise " />" (comme <img />)
2016
+        if (preg_match(',/>,', $balise)) {
2017
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2018
+        } // sinon une balise <a ...> ... </a>
2019
+        else {
2020
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2021
+        }
2022
+    }
2023 2023
 
2024
-	return $balise;
2024
+    return $balise;
2025 2025
 }
2026 2026
 
2027 2027
 /**
@@ -2039,7 +2039,7 @@  discard block
 block discarded – undo
2039 2039
  * @return string Code HTML sans l'attribut
2040 2040
  **/
2041 2041
 function vider_attribut(?string $balise, string $attribut): string {
2042
-	return inserer_attribut($balise, $attribut, '', false, true);
2042
+    return inserer_attribut($balise, $attribut, '', false, true);
2043 2043
 }
2044 2044
 
2045 2045
 /**
@@ -2051,50 +2051,50 @@  discard block
 block discarded – undo
2051 2051
  * @return string
2052 2052
  */
2053 2053
 function modifier_class($balise, $class, $operation = 'ajouter') {
2054
-	if (is_string($class)) {
2055
-		$class = explode(' ', trim($class));
2056
-	}
2057
-	$class = array_filter($class);
2058
-	$class = array_unique($class);
2059
-	if (!$class) {
2060
-		return $balise;
2061
-	}
2062
-
2063
-	$class_courante = extraire_attribut($balise, 'class');
2064
-	$class_new = $class_courante;
2065
-	foreach ($class as $c) {
2066
-		$is_class_presente = false;
2067
-		if (
2068
-			$class_courante
2069
-			and str_contains($class_courante, (string) $c)
2070
-			and in_array($c, preg_split(",\s+,", $class_courante))
2071
-		) {
2072
-			$is_class_presente = true;
2073
-		}
2074
-		if (
2075
-			in_array($operation, ['ajouter', 'commuter'])
2076
-			and !$is_class_presente
2077
-		) {
2078
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2079
-		} elseif (
2080
-			in_array($operation, ['supprimer', 'commuter'])
2081
-			and $is_class_presente
2082
-		) {
2083
-			$class_new = preg_split(",\s+,", $class_new);
2084
-			$class_new = array_diff($class_new, [$c]);
2085
-			$class_new = implode(' ', $class_new);
2086
-		}
2087
-	}
2088
-
2089
-	if ($class_new !== $class_courante) {
2090
-		if (strlen($class_new)) {
2091
-			$balise = inserer_attribut($balise, 'class', $class_new);
2092
-		} elseif ($class_courante) {
2093
-			$balise = vider_attribut($balise, 'class');
2094
-		}
2095
-	}
2096
-
2097
-	return $balise;
2054
+    if (is_string($class)) {
2055
+        $class = explode(' ', trim($class));
2056
+    }
2057
+    $class = array_filter($class);
2058
+    $class = array_unique($class);
2059
+    if (!$class) {
2060
+        return $balise;
2061
+    }
2062
+
2063
+    $class_courante = extraire_attribut($balise, 'class');
2064
+    $class_new = $class_courante;
2065
+    foreach ($class as $c) {
2066
+        $is_class_presente = false;
2067
+        if (
2068
+            $class_courante
2069
+            and str_contains($class_courante, (string) $c)
2070
+            and in_array($c, preg_split(",\s+,", $class_courante))
2071
+        ) {
2072
+            $is_class_presente = true;
2073
+        }
2074
+        if (
2075
+            in_array($operation, ['ajouter', 'commuter'])
2076
+            and !$is_class_presente
2077
+        ) {
2078
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2079
+        } elseif (
2080
+            in_array($operation, ['supprimer', 'commuter'])
2081
+            and $is_class_presente
2082
+        ) {
2083
+            $class_new = preg_split(",\s+,", $class_new);
2084
+            $class_new = array_diff($class_new, [$c]);
2085
+            $class_new = implode(' ', $class_new);
2086
+        }
2087
+    }
2088
+
2089
+    if ($class_new !== $class_courante) {
2090
+        if (strlen($class_new)) {
2091
+            $balise = inserer_attribut($balise, 'class', $class_new);
2092
+        } elseif ($class_courante) {
2093
+            $balise = vider_attribut($balise, 'class');
2094
+        }
2095
+    }
2096
+
2097
+    return $balise;
2098 2098
 }
2099 2099
 
2100 2100
 /**
@@ -2104,7 +2104,7 @@  discard block
 block discarded – undo
2104 2104
  * @return string
2105 2105
  */
2106 2106
 function ajouter_class($balise, $class) {
2107
-	return modifier_class($balise, $class, 'ajouter');
2107
+    return modifier_class($balise, $class, 'ajouter');
2108 2108
 }
2109 2109
 
2110 2110
 /**
@@ -2114,7 +2114,7 @@  discard block
 block discarded – undo
2114 2114
  * @return string
2115 2115
  */
2116 2116
 function supprimer_class($balise, $class) {
2117
-	return modifier_class($balise, $class, 'supprimer');
2117
+    return modifier_class($balise, $class, 'supprimer');
2118 2118
 }
2119 2119
 
2120 2120
 /**
@@ -2125,7 +2125,7 @@  discard block
 block discarded – undo
2125 2125
  * @return string
2126 2126
  */
2127 2127
 function commuter_class($balise, $class) {
2128
-	return modifier_class($balise, $class, 'commuter');
2128
+    return modifier_class($balise, $class, 'commuter');
2129 2129
 }
2130 2130
 
2131 2131
 /**
@@ -2136,19 +2136,19 @@  discard block
 block discarded – undo
2136 2136
  * @return string
2137 2137
  */
2138 2138
 function tester_config($id, $mode = '') {
2139
-	include_spip('action/inscrire_auteur');
2139
+    include_spip('action/inscrire_auteur');
2140 2140
 
2141
-	return tester_statut_inscription($mode, $id);
2141
+    return tester_statut_inscription($mode, $id);
2142 2142
 }
2143 2143
 
2144 2144
 //
2145 2145
 // Quelques fonctions de calcul arithmetique
2146 2146
 //
2147 2147
 function floatstr($a) {
2148
- return str_replace(',', '.', (string)floatval($a));
2148
+    return str_replace(',', '.', (string)floatval($a));
2149 2149
 }
2150 2150
 function strize($f, $a, $b) {
2151
- return floatstr($f(floatstr($a), floatstr($b)));
2151
+    return floatstr($f(floatstr($a), floatstr($b)));
2152 2152
 }
2153 2153
 
2154 2154
 /**
@@ -2167,11 +2167,11 @@  discard block
 block discarded – undo
2167 2167
  * @return int $a+$b
2168 2168
  **/
2169 2169
 function plus($a, $b) {
2170
-	return $a + $b;
2170
+    return $a + $b;
2171 2171
 }
2172 2172
 
2173 2173
 function strplus($a, $b) {
2174
-	return strize('plus', $a, $b);
2174
+    return strize('plus', $a, $b);
2175 2175
 }
2176 2176
 
2177 2177
 /**
@@ -2190,11 +2190,11 @@  discard block
 block discarded – undo
2190 2190
  * @return int $a-$b
2191 2191
  **/
2192 2192
 function moins($a, $b) {
2193
-	return $a - $b;
2193
+    return $a - $b;
2194 2194
 }
2195 2195
 
2196 2196
 function strmoins($a, $b) {
2197
-	return strize('moins', $a, $b);
2197
+    return strize('moins', $a, $b);
2198 2198
 }
2199 2199
 
2200 2200
 /**
@@ -2214,11 +2214,11 @@  discard block
 block discarded – undo
2214 2214
  * @return int $a*$b
2215 2215
  **/
2216 2216
 function mult($a, $b) {
2217
-	return $a * $b;
2217
+    return $a * $b;
2218 2218
 }
2219 2219
 
2220 2220
 function strmult($a, $b) {
2221
-	return strize('mult', $a, $b);
2221
+    return strize('mult', $a, $b);
2222 2222
 }
2223 2223
 
2224 2224
 /**
@@ -2238,11 +2238,11 @@  discard block
 block discarded – undo
2238 2238
  * @return int $a/$b (ou 0 si $b est nul)
2239 2239
  **/
2240 2240
 function div($a, $b) {
2241
-	return $b ? $a / $b : 0;
2241
+    return $b ? $a / $b : 0;
2242 2242
 }
2243 2243
 
2244 2244
 function strdiv($a, $b) {
2245
-	return strize('div', $a, $b);
2245
+    return strize('div', $a, $b);
2246 2246
 }
2247 2247
 
2248 2248
 /**
@@ -2263,7 +2263,7 @@  discard block
 block discarded – undo
2263 2263
  * @return int ($nb % $mod) + $add
2264 2264
  **/
2265 2265
 function modulo($nb, $mod, $add = 0) {
2266
-	return ($mod ? $nb % $mod : 0) + $add;
2266
+    return ($mod ? $nb % $mod : 0) + $add;
2267 2267
 }
2268 2268
 
2269 2269
 
@@ -2278,26 +2278,26 @@  discard block
 block discarded – undo
2278 2278
  *      - true sinon
2279 2279
  **/
2280 2280
 function nom_acceptable($nom) {
2281
-	$remp2 = [];
2282
-	$remp1 = [];
2283
-	if (!is_string($nom)) {
2284
-		return false;
2285
-	}
2286
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2287
-		define('_TAGS_NOM_AUTEUR', '');
2288
-	}
2289
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2290
-	foreach ($tags_acceptes as $tag) {
2291
-		if (strlen($tag)) {
2292
-			$remp1[] = '<' . trim($tag) . '>';
2293
-			$remp1[] = '</' . trim($tag) . '>';
2294
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2295
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2296
-		}
2297
-	}
2298
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2299
-
2300
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2281
+    $remp2 = [];
2282
+    $remp1 = [];
2283
+    if (!is_string($nom)) {
2284
+        return false;
2285
+    }
2286
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2287
+        define('_TAGS_NOM_AUTEUR', '');
2288
+    }
2289
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2290
+    foreach ($tags_acceptes as $tag) {
2291
+        if (strlen($tag)) {
2292
+            $remp1[] = '<' . trim($tag) . '>';
2293
+            $remp1[] = '</' . trim($tag) . '>';
2294
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2295
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2296
+        }
2297
+    }
2298
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2299
+
2300
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2301 2301
 }
2302 2302
 
2303 2303
 
@@ -2313,14 +2313,14 @@  discard block
 block discarded – undo
2313 2313
  *      - renvoie un tableau si l'entree est un tableau
2314 2314
  **/
2315 2315
 function email_valide($adresses) {
2316
-	if (is_array($adresses)) {
2317
-		$adresses = array_map('email_valide', $adresses);
2318
-		$adresses = array_filter($adresses);
2319
-		return $adresses;
2320
-	}
2316
+    if (is_array($adresses)) {
2317
+        $adresses = array_map('email_valide', $adresses);
2318
+        $adresses = array_filter($adresses);
2319
+        return $adresses;
2320
+    }
2321 2321
 
2322
-	$email_valide = charger_fonction('email_valide', 'inc');
2323
-	return $email_valide($adresses);
2322
+    $email_valide = charger_fonction('email_valide', 'inc');
2323
+    return $email_valide($adresses);
2324 2324
 }
2325 2325
 
2326 2326
 /**
@@ -2334,29 +2334,29 @@  discard block
 block discarded – undo
2334 2334
  * @return string texte
2335 2335
  **/
2336 2336
 function afficher_enclosures($tags) {
2337
-	$s = [];
2338
-	foreach (extraire_balises($tags, 'a') as $tag) {
2339
-		if (
2340
-			extraire_attribut($tag, 'rel') == 'enclosure'
2341
-			and $t = extraire_attribut($tag, 'href')
2342
-		) {
2343
-			$s[] = preg_replace(
2344
-				',>[^<]+</a>,S',
2345
-				'>'
2346
-				. http_img_pack(
2347
-					'attachment-16.png',
2348
-					$t,
2349
-					'',
2350
-					$t,
2351
-					['utiliser_suffixe_size' => true]
2352
-				)
2353
-				. '</a>',
2354
-				$tag
2355
-			);
2356
-		}
2357
-	}
2358
-
2359
-	return join('&nbsp;', $s);
2337
+    $s = [];
2338
+    foreach (extraire_balises($tags, 'a') as $tag) {
2339
+        if (
2340
+            extraire_attribut($tag, 'rel') == 'enclosure'
2341
+            and $t = extraire_attribut($tag, 'href')
2342
+        ) {
2343
+            $s[] = preg_replace(
2344
+                ',>[^<]+</a>,S',
2345
+                '>'
2346
+                . http_img_pack(
2347
+                    'attachment-16.png',
2348
+                    $t,
2349
+                    '',
2350
+                    $t,
2351
+                    ['utiliser_suffixe_size' => true]
2352
+                )
2353
+                . '</a>',
2354
+                $tag
2355
+            );
2356
+        }
2357
+    }
2358
+
2359
+    return join('&nbsp;', $s);
2360 2360
 }
2361 2361
 
2362 2362
 /**
@@ -2371,15 +2371,15 @@  discard block
 block discarded – undo
2371 2371
  * @return string Liens trouvés
2372 2372
  **/
2373 2373
 function afficher_tags($tags, $rels = 'tag,directory') {
2374
-	$s = [];
2375
-	foreach (extraire_balises($tags, 'a') as $tag) {
2376
-		$rel = extraire_attribut($tag, 'rel');
2377
-		if (strstr(",$rels,", (string) ",$rel,")) {
2378
-			$s[] = $tag;
2379
-		}
2380
-	}
2374
+    $s = [];
2375
+    foreach (extraire_balises($tags, 'a') as $tag) {
2376
+        $rel = extraire_attribut($tag, 'rel');
2377
+        if (strstr(",$rels,", (string) ",$rel,")) {
2378
+            $s[] = $tag;
2379
+        }
2380
+    }
2381 2381
 
2382
-	return join(', ', $s);
2382
+    return join(', ', $s);
2383 2383
 }
2384 2384
 
2385 2385
 
@@ -2401,21 +2401,21 @@  discard block
 block discarded – undo
2401 2401
  * @return string Tag HTML `<a>` avec microformat.
2402 2402
  **/
2403 2403
 function enclosure2microformat($e) {
2404
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2405
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2406
-	}
2407
-	$type = extraire_attribut($e, 'type');
2408
-	if (!$length = extraire_attribut($e, 'length')) {
2409
-		# <media:content : longeur dans fileSize. On tente.
2410
-		$length = extraire_attribut($e, 'fileSize');
2411
-	}
2412
-	$fichier = basename($url);
2404
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2405
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2406
+    }
2407
+    $type = extraire_attribut($e, 'type');
2408
+    if (!$length = extraire_attribut($e, 'length')) {
2409
+        # <media:content : longeur dans fileSize. On tente.
2410
+        $length = extraire_attribut($e, 'fileSize');
2411
+    }
2412
+    $fichier = basename($url);
2413 2413
 
2414
-	return '<a rel="enclosure"'
2415
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2416
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2417
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2418
-	. '>' . $fichier . '</a>';
2414
+    return '<a rel="enclosure"'
2415
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2416
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2417
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2418
+    . '>' . $fichier . '</a>';
2419 2419
 }
2420 2420
 
2421 2421
 /**
@@ -2433,24 +2433,24 @@  discard block
 block discarded – undo
2433 2433
  * @return string Tags RSS `<enclosure>`.
2434 2434
  **/
2435 2435
 function microformat2enclosure($tags) {
2436
-	$enclosures = [];
2437
-	foreach (extraire_balises($tags, 'a') as $e) {
2438
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2439
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2440
-			$type = extraire_attribut($e, 'type');
2441
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2442
-				$length = intval(extraire_attribut($e, 'length'));
2443
-			} # vieux data
2444
-			$fichier = basename($url);
2445
-			$enclosures[] = '<enclosure'
2446
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2447
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2448
-				. ($length ? ' length="' . $length . '"' : '')
2449
-				. ' />';
2450
-		}
2451
-	}
2436
+    $enclosures = [];
2437
+    foreach (extraire_balises($tags, 'a') as $e) {
2438
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2439
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2440
+            $type = extraire_attribut($e, 'type');
2441
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2442
+                $length = intval(extraire_attribut($e, 'length'));
2443
+            } # vieux data
2444
+            $fichier = basename($url);
2445
+            $enclosures[] = '<enclosure'
2446
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2447
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2448
+                . ($length ? ' length="' . $length . '"' : '')
2449
+                . ' />';
2450
+        }
2451
+    }
2452 2452
 
2453
-	return join("\n", $enclosures);
2453
+    return join("\n", $enclosures);
2454 2454
 }
2455 2455
 
2456 2456
 
@@ -2466,16 +2466,16 @@  discard block
 block discarded – undo
2466 2466
  * @return string Tags RSS Atom `<dc:subject>`.
2467 2467
  **/
2468 2468
 function tags2dcsubject($tags) {
2469
-	$subjects = '';
2470
-	foreach (extraire_balises($tags, 'a') as $e) {
2471
-		if (extraire_attribut($e, 'rel') == 'tag') {
2472
-			$subjects .= '<dc:subject>'
2473
-				. texte_backend(textebrut($e))
2474
-				. '</dc:subject>' . "\n";
2475
-		}
2476
-	}
2469
+    $subjects = '';
2470
+    foreach (extraire_balises($tags, 'a') as $e) {
2471
+        if (extraire_attribut($e, 'rel') == 'tag') {
2472
+            $subjects .= '<dc:subject>'
2473
+                . texte_backend(textebrut($e))
2474
+                . '</dc:subject>' . "\n";
2475
+        }
2476
+    }
2477 2477
 
2478
-	return $subjects;
2478
+    return $subjects;
2479 2479
 }
2480 2480
 
2481 2481
 /**
@@ -2504,27 +2504,27 @@  discard block
 block discarded – undo
2504 2504
  *     - Tableau de résultats, si tableau en entrée.
2505 2505
  **/
2506 2506
 function extraire_balise($texte, $tag = 'a') {
2507
-	if (is_array($texte)) {
2508
-		array_walk(
2509
-			$texte,
2510
-			function (&$a, $key, $t) {
2511
-				$a = extraire_balise($a, $t);
2512
-			},
2513
-			$tag
2514
-		);
2515
-
2516
-		return $texte;
2517
-	}
2518
-
2519
-	if (
2520
-		preg_match(
2521
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2522
-			$texte,
2523
-			$regs
2524
-		)
2525
-	) {
2526
-		return $regs[0];
2527
-	}
2507
+    if (is_array($texte)) {
2508
+        array_walk(
2509
+            $texte,
2510
+            function (&$a, $key, $t) {
2511
+                $a = extraire_balise($a, $t);
2512
+            },
2513
+            $tag
2514
+        );
2515
+
2516
+        return $texte;
2517
+    }
2518
+
2519
+    if (
2520
+        preg_match(
2521
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2522
+            $texte,
2523
+            $regs
2524
+        )
2525
+    ) {
2526
+        return $regs[0];
2527
+    }
2528 2528
 }
2529 2529
 
2530 2530
 /**
@@ -2552,30 +2552,30 @@  discard block
 block discarded – undo
2552 2552
  *     - Tableau de résultats, si tableau en entrée.
2553 2553
  **/
2554 2554
 function extraire_balises($texte, $tag = 'a') {
2555
-	if (is_array($texte)) {
2556
-		array_walk(
2557
-			$texte,
2558
-			function (&$a, $key, $t) {
2559
-				$a = extraire_balises($a, $t);
2560
-			},
2561
-			$tag
2562
-		);
2563
-
2564
-		return $texte;
2565
-	}
2566
-
2567
-	if (
2568
-		preg_match_all(
2569
-			",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2570
-			$texte,
2571
-			$regs,
2572
-			PREG_PATTERN_ORDER
2573
-		)
2574
-	) {
2575
-		return $regs[0];
2576
-	} else {
2577
-		return [];
2578
-	}
2555
+    if (is_array($texte)) {
2556
+        array_walk(
2557
+            $texte,
2558
+            function (&$a, $key, $t) {
2559
+                $a = extraire_balises($a, $t);
2560
+            },
2561
+            $tag
2562
+        );
2563
+
2564
+        return $texte;
2565
+    }
2566
+
2567
+    if (
2568
+        preg_match_all(
2569
+            ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2570
+            $texte,
2571
+            $regs,
2572
+            PREG_PATTERN_ORDER
2573
+        )
2574
+    ) {
2575
+        return $regs[0];
2576
+    } else {
2577
+        return [];
2578
+    }
2579 2579
 }
2580 2580
 
2581 2581
 /**
@@ -2604,11 +2604,11 @@  discard block
 block discarded – undo
2604 2604
  *     - `$def` si on n'a pas transmis de tableau
2605 2605
  **/
2606 2606
 function in_any($val, $vals, $def = '') {
2607
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2608
-		$vals = $v;
2609
-	}
2607
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2608
+        $vals = $v;
2609
+    }
2610 2610
 
2611
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2611
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2612 2612
 }
2613 2613
 
2614 2614
 
@@ -2629,12 +2629,12 @@  discard block
 block discarded – undo
2629 2629
  *     Résultat du calcul
2630 2630
  **/
2631 2631
 function valeur_numerique($expr) {
2632
-	$a = 0;
2633
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2634
-		eval("\$a = $expr;");
2635
-	}
2632
+    $a = 0;
2633
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2634
+        eval("\$a = $expr;");
2635
+    }
2636 2636
 
2637
-	return intval($a);
2637
+    return intval($a);
2638 2638
 }
2639 2639
 
2640 2640
 /**
@@ -2653,7 +2653,7 @@  discard block
 block discarded – undo
2653 2653
  *      Retourne `$a*$b/$c`
2654 2654
  **/
2655 2655
 function regledetrois($a, $b, $c) {
2656
-	return round($a * $b / $c);
2656
+    return round($a * $b / $c);
2657 2657
 }
2658 2658
 
2659 2659
 
@@ -2676,79 +2676,79 @@  discard block
 block discarded – undo
2676 2676
  * @return string Suite de champs input hidden
2677 2677
  **/
2678 2678
 function form_hidden(?string $action = ''): string {
2679
-	$action ??= '';
2680
-
2681
-	$contexte = [];
2682
-	include_spip('inc/urls');
2683
-	if (
2684
-		$p = urls_decoder_url($action, '')
2685
-		and reset($p)
2686
-	) {
2687
-		$fond = array_shift($p);
2688
-		if ($fond != '404') {
2689
-			$contexte = array_shift($p);
2690
-			$contexte['page'] = $fond;
2691
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2692
-		}
2693
-	}
2694
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2695
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2696
-		unset($contexte['type']);
2697
-	}
2698
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2699
-		unset($contexte['type-page']);
2700
-	}
2701
-
2702
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2703
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2704
-	$values = [];
2705
-
2706
-	// d'abord avec celles de l'url
2707
-	if (false !== ($p = strpos($action, '?'))) {
2708
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2709
-			$c = explode('=', $c, 2);
2710
-			$var = array_shift($c);
2711
-			$val = array_shift($c) ?? '';
2712
-			if ($var) {
2713
-				$val = rawurldecode($val);
2714
-				$var = rawurldecode($var); // decoder les [] eventuels
2715
-				if (preg_match(',\[\]$,S', $var)) {
2716
-					$values[] = [$var, $val];
2717
-				} else {
2718
-					if (!isset($values[$var])) {
2719
-						$values[$var] = [$var, $val];
2720
-					}
2721
-				}
2722
-			}
2723
-		}
2724
-	}
2725
-
2726
-	// ensuite avec celles du contexte, sans doublonner !
2727
-	foreach ($contexte as $var => $val) {
2728
-		if (preg_match(',\[\]$,S', $var)) {
2729
-			$values[] = [$var, $val];
2730
-		} else {
2731
-			if (!isset($values[$var])) {
2732
-				$values[$var] = [$var, $val];
2733
-			}
2734
-		}
2735
-	}
2736
-
2737
-	// puis on rassemble le tout
2738
-	$hidden = [];
2739
-	foreach ($values as $value) {
2740
-		[$var, $val] = $value;
2741
-		$hidden[] = '<input name="'
2742
-			. entites_html($var)
2743
-			. '"'
2744
-			. (is_null($val)
2745
-				? ''
2746
-				: ' value="' . entites_html($val) . '"'
2747
-			)
2748
-			. ' type="hidden"' . "\n/>";
2749
-	}
2750
-
2751
-	return join('', $hidden);
2679
+    $action ??= '';
2680
+
2681
+    $contexte = [];
2682
+    include_spip('inc/urls');
2683
+    if (
2684
+        $p = urls_decoder_url($action, '')
2685
+        and reset($p)
2686
+    ) {
2687
+        $fond = array_shift($p);
2688
+        if ($fond != '404') {
2689
+            $contexte = array_shift($p);
2690
+            $contexte['page'] = $fond;
2691
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2692
+        }
2693
+    }
2694
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2695
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2696
+        unset($contexte['type']);
2697
+    }
2698
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2699
+        unset($contexte['type-page']);
2700
+    }
2701
+
2702
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2703
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2704
+    $values = [];
2705
+
2706
+    // d'abord avec celles de l'url
2707
+    if (false !== ($p = strpos($action, '?'))) {
2708
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2709
+            $c = explode('=', $c, 2);
2710
+            $var = array_shift($c);
2711
+            $val = array_shift($c) ?? '';
2712
+            if ($var) {
2713
+                $val = rawurldecode($val);
2714
+                $var = rawurldecode($var); // decoder les [] eventuels
2715
+                if (preg_match(',\[\]$,S', $var)) {
2716
+                    $values[] = [$var, $val];
2717
+                } else {
2718
+                    if (!isset($values[$var])) {
2719
+                        $values[$var] = [$var, $val];
2720
+                    }
2721
+                }
2722
+            }
2723
+        }
2724
+    }
2725
+
2726
+    // ensuite avec celles du contexte, sans doublonner !
2727
+    foreach ($contexte as $var => $val) {
2728
+        if (preg_match(',\[\]$,S', $var)) {
2729
+            $values[] = [$var, $val];
2730
+        } else {
2731
+            if (!isset($values[$var])) {
2732
+                $values[$var] = [$var, $val];
2733
+            }
2734
+        }
2735
+    }
2736
+
2737
+    // puis on rassemble le tout
2738
+    $hidden = [];
2739
+    foreach ($values as $value) {
2740
+        [$var, $val] = $value;
2741
+        $hidden[] = '<input name="'
2742
+            . entites_html($var)
2743
+            . '"'
2744
+            . (is_null($val)
2745
+                ? ''
2746
+                : ' value="' . entites_html($val) . '"'
2747
+            )
2748
+            . ' type="hidden"' . "\n/>";
2749
+    }
2750
+
2751
+    return join('', $hidden);
2752 2752
 }
2753 2753
 
2754 2754
 
@@ -2770,7 +2770,7 @@  discard block
 block discarded – undo
2770 2770
  *    - la première valeur du tableau sinon.
2771 2771
  **/
2772 2772
 function filtre_reset($array) {
2773
-	return !is_array($array) ? null : reset($array);
2773
+    return !is_array($array) ? null : reset($array);
2774 2774
 }
2775 2775
 
2776 2776
 /**
@@ -2791,7 +2791,7 @@  discard block
 block discarded – undo
2791 2791
  *    - la dernière valeur du tableau sinon.
2792 2792
  **/
2793 2793
 function filtre_end($array) {
2794
-	return !is_array($array) ? null : end($array);
2794
+    return !is_array($array) ? null : end($array);
2795 2795
 }
2796 2796
 
2797 2797
 /**
@@ -2811,11 +2811,11 @@  discard block
 block discarded – undo
2811 2811
  *
2812 2812
  **/
2813 2813
 function filtre_push($array, $val) {
2814
-	if (!is_array($array) or !array_push($array, $val)) {
2815
-		return '';
2816
-	}
2814
+    if (!is_array($array) or !array_push($array, $val)) {
2815
+        return '';
2816
+    }
2817 2817
 
2818
-	return $array;
2818
+    return $array;
2819 2819
 }
2820 2820
 
2821 2821
 /**
@@ -2834,7 +2834,7 @@  discard block
 block discarded – undo
2834 2834
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2835 2835
  **/
2836 2836
 function filtre_find($array, $val) {
2837
-	return (is_array($array) and in_array($val, $array));
2837
+    return (is_array($array) and in_array($val, $array));
2838 2838
 }
2839 2839
 
2840 2840
 
@@ -2851,13 +2851,13 @@  discard block
 block discarded – undo
2851 2851
  *     Contenu avec urls en absolus
2852 2852
  **/
2853 2853
 function urls_absolues_css($contenu, $source) {
2854
-	$path = suivre_lien(url_absolue($source), './');
2854
+    $path = suivre_lien(url_absolue($source), './');
2855 2855
 
2856
-	return preg_replace_callback(
2857
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2858
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2859
-		$contenu
2860
-	);
2856
+    return preg_replace_callback(
2857
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2858
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2859
+        $contenu
2860
+    );
2861 2861
 }
2862 2862
 
2863 2863
 
@@ -2886,119 +2886,119 @@  discard block
 block discarded – undo
2886 2886
  *     Chemin du fichier CSS inversé
2887 2887
  **/
2888 2888
 function direction_css($css, $voulue = '') {
2889
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2890
-		return $css;
2891
-	}
2892
-	include_spip('inc/lang');
2893
-	// si on a precise le sens voulu en argument, le prendre en compte
2894
-	if ($voulue = strtolower($voulue)) {
2895
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2896
-			$voulue = lang_dir($voulue);
2897
-		}
2898
-	} else {
2899
-		$voulue = lang_dir();
2900
-	}
2901
-
2902
-	$r = count($r) > 1;
2903
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2904
-	$dir = $r ? 'rtl' : 'ltr';
2905
-	$ndir = $r ? 'ltr' : 'rtl';
2906
-
2907
-	if ($voulue == $dir) {
2908
-		return $css;
2909
-	}
2910
-
2911
-	if (
2912
-		// url absolue
2913
-		preg_match(',^https?:,i', $css)
2914
-		// ou qui contient un ?
2915
-		or (($p = strpos($css, '?')) !== false)
2916
-	) {
2917
-		$distant = true;
2918
-		$cssf = parse_url($css);
2919
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2920
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2921
-	} else {
2922
-		$distant = false;
2923
-		$cssf = $css;
2924
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2925
-		//propose (rien a faire dans ce cas)
2926
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2927
-		if (@file_exists($f)) {
2928
-			return $f;
2929
-		}
2930
-	}
2931
-
2932
-	// 2.
2933
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2934
-	$f = $dir_var
2935
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2936
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2937
-
2938
-	// la css peut etre distante (url absolue !)
2939
-	if ($distant) {
2940
-		include_spip('inc/distant');
2941
-		$res = recuperer_url($css);
2942
-		if (!$res or !$contenu = $res['page']) {
2943
-			return $css;
2944
-		}
2945
-	} else {
2946
-		if (
2947
-			(@filemtime($f) > @filemtime($css))
2948
-			and (_VAR_MODE != 'recalcul')
2949
-		) {
2950
-			return $f;
2951
-		}
2952
-		if (!lire_fichier($css, $contenu)) {
2953
-			return $css;
2954
-		}
2955
-	}
2956
-
2957
-
2958
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2959
-	include_spip('lib/csstidy/class.csstidy');
2960
-	$parser = new csstidy();
2961
-	$parser->set_cfg('optimise_shorthands', 0);
2962
-	$parser->set_cfg('reverse_left_and_right', true);
2963
-	$parser->parse($contenu);
2964
-
2965
-	$contenu = $parser->print->plain();
2966
-
2967
-
2968
-	// reperer les @import auxquels il faut propager le direction_css
2969
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2970
-	$src = [];
2971
-	$src_direction_css = [];
2972
-	$src_faux_abs = [];
2973
-	$d = dirname($css);
2974
-	foreach ($regs[1] as $k => $import_css) {
2975
-		$css_direction = direction_css("$d/$import_css", $voulue);
2976
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2977
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2978
-			$css_direction = substr($css_direction, strlen($d) + 1);
2979
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2980
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2981
-			$css_direction = substr($css_direction, strlen($dir_var));
2982
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2983
-			$css_direction = '/@@@@@@/' . $css_direction;
2984
-		}
2985
-		$src[] = $regs[0][$k];
2986
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2987
-	}
2988
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2989
-
2990
-	$contenu = urls_absolues_css($contenu, $css);
2991
-
2992
-	// virer les fausses url absolues que l'on a mis dans les import
2993
-	if (count($src_faux_abs)) {
2994
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2995
-	}
2996
-
2997
-	if (!ecrire_fichier($f, $contenu)) {
2998
-		return $css;
2999
-	}
3000
-
3001
-	return $f;
2889
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2890
+        return $css;
2891
+    }
2892
+    include_spip('inc/lang');
2893
+    // si on a precise le sens voulu en argument, le prendre en compte
2894
+    if ($voulue = strtolower($voulue)) {
2895
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2896
+            $voulue = lang_dir($voulue);
2897
+        }
2898
+    } else {
2899
+        $voulue = lang_dir();
2900
+    }
2901
+
2902
+    $r = count($r) > 1;
2903
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2904
+    $dir = $r ? 'rtl' : 'ltr';
2905
+    $ndir = $r ? 'ltr' : 'rtl';
2906
+
2907
+    if ($voulue == $dir) {
2908
+        return $css;
2909
+    }
2910
+
2911
+    if (
2912
+        // url absolue
2913
+        preg_match(',^https?:,i', $css)
2914
+        // ou qui contient un ?
2915
+        or (($p = strpos($css, '?')) !== false)
2916
+    ) {
2917
+        $distant = true;
2918
+        $cssf = parse_url($css);
2919
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2920
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2921
+    } else {
2922
+        $distant = false;
2923
+        $cssf = $css;
2924
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2925
+        //propose (rien a faire dans ce cas)
2926
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2927
+        if (@file_exists($f)) {
2928
+            return $f;
2929
+        }
2930
+    }
2931
+
2932
+    // 2.
2933
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2934
+    $f = $dir_var
2935
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2936
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2937
+
2938
+    // la css peut etre distante (url absolue !)
2939
+    if ($distant) {
2940
+        include_spip('inc/distant');
2941
+        $res = recuperer_url($css);
2942
+        if (!$res or !$contenu = $res['page']) {
2943
+            return $css;
2944
+        }
2945
+    } else {
2946
+        if (
2947
+            (@filemtime($f) > @filemtime($css))
2948
+            and (_VAR_MODE != 'recalcul')
2949
+        ) {
2950
+            return $f;
2951
+        }
2952
+        if (!lire_fichier($css, $contenu)) {
2953
+            return $css;
2954
+        }
2955
+    }
2956
+
2957
+
2958
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2959
+    include_spip('lib/csstidy/class.csstidy');
2960
+    $parser = new csstidy();
2961
+    $parser->set_cfg('optimise_shorthands', 0);
2962
+    $parser->set_cfg('reverse_left_and_right', true);
2963
+    $parser->parse($contenu);
2964
+
2965
+    $contenu = $parser->print->plain();
2966
+
2967
+
2968
+    // reperer les @import auxquels il faut propager le direction_css
2969
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2970
+    $src = [];
2971
+    $src_direction_css = [];
2972
+    $src_faux_abs = [];
2973
+    $d = dirname($css);
2974
+    foreach ($regs[1] as $k => $import_css) {
2975
+        $css_direction = direction_css("$d/$import_css", $voulue);
2976
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2977
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2978
+            $css_direction = substr($css_direction, strlen($d) + 1);
2979
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2980
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2981
+            $css_direction = substr($css_direction, strlen($dir_var));
2982
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2983
+            $css_direction = '/@@@@@@/' . $css_direction;
2984
+        }
2985
+        $src[] = $regs[0][$k];
2986
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2987
+    }
2988
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2989
+
2990
+    $contenu = urls_absolues_css($contenu, $css);
2991
+
2992
+    // virer les fausses url absolues que l'on a mis dans les import
2993
+    if (count($src_faux_abs)) {
2994
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2995
+    }
2996
+
2997
+    if (!ecrire_fichier($f, $contenu)) {
2998
+        return $css;
2999
+    }
3000
+
3001
+    return $f;
3002 3002
 }
3003 3003
 
3004 3004
 
@@ -3021,46 +3021,46 @@  discard block
 block discarded – undo
3021 3021
  *     - Chemin ou URL du fichier CSS source sinon.
3022 3022
  **/
3023 3023
 function url_absolue_css($css) {
3024
-	if (!preg_match(',\.css$,i', $css, $r)) {
3025
-		return $css;
3026
-	}
3024
+    if (!preg_match(',\.css$,i', $css, $r)) {
3025
+        return $css;
3026
+    }
3027 3027
 
3028
-	$url_absolue_css = url_absolue($css);
3028
+    $url_absolue_css = url_absolue($css);
3029 3029
 
3030
-	$f = basename($css, '.css');
3031
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3032
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3033
-		. '.css';
3030
+    $f = basename($css, '.css');
3031
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3032
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3033
+        . '.css';
3034 3034
 
3035
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3036
-		return $f;
3037
-	}
3035
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3036
+        return $f;
3037
+    }
3038 3038
 
3039
-	if ($url_absolue_css == $css) {
3040
-		if (
3041
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3042
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3043
-		) {
3044
-			include_spip('inc/distant');
3045
-			$contenu = recuperer_url($css);
3046
-			$contenu = $contenu['page'] ?? '';
3047
-			if (!$contenu) {
3048
-				return $css;
3049
-			}
3050
-		}
3051
-	} elseif (!lire_fichier($css, $contenu)) {
3052
-		return $css;
3053
-	}
3039
+    if ($url_absolue_css == $css) {
3040
+        if (
3041
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3042
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3043
+        ) {
3044
+            include_spip('inc/distant');
3045
+            $contenu = recuperer_url($css);
3046
+            $contenu = $contenu['page'] ?? '';
3047
+            if (!$contenu) {
3048
+                return $css;
3049
+            }
3050
+        }
3051
+    } elseif (!lire_fichier($css, $contenu)) {
3052
+        return $css;
3053
+    }
3054 3054
 
3055
-	// passer les url relatives a la css d'origine en url absolues
3056
-	$contenu = urls_absolues_css($contenu, $css);
3055
+    // passer les url relatives a la css d'origine en url absolues
3056
+    $contenu = urls_absolues_css($contenu, $css);
3057 3057
 
3058
-	// ecrire la css
3059
-	if (!ecrire_fichier($f, $contenu)) {
3060
-		return $css;
3061
-	}
3058
+    // ecrire la css
3059
+    if (!ecrire_fichier($f, $contenu)) {
3060
+        return $css;
3061
+    }
3062 3062
 
3063
-	return $f;
3063
+    return $f;
3064 3064
 }
3065 3065
 
3066 3066
 
@@ -3094,24 +3094,24 @@  discard block
 block discarded – undo
3094 3094
  *     Valeur trouvée ou valeur par défaut.
3095 3095
  **/
3096 3096
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3097
-	foreach (explode('/', $cle) as $k) {
3098
-		$table = (is_string($table) ? @unserialize($table) : $table);
3097
+    foreach (explode('/', $cle) as $k) {
3098
+        $table = (is_string($table) ? @unserialize($table) : $table);
3099 3099
 
3100
-		if (is_object($table)) {
3101
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3102
-		} elseif (is_array($table)) {
3103
-			if ($conserver_null) {
3104
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3105
-			} else {
3106
-				$table = ($table[$k] ?? $defaut);
3107
-			}
3108
-		} else {
3109
-			$table = $defaut;
3110
-			break;
3111
-		}
3112
-	}
3100
+        if (is_object($table)) {
3101
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3102
+        } elseif (is_array($table)) {
3103
+            if ($conserver_null) {
3104
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3105
+            } else {
3106
+                $table = ($table[$k] ?? $defaut);
3107
+            }
3108
+        } else {
3109
+            $table = $defaut;
3110
+            break;
3111
+        }
3112
+    }
3113 3113
 
3114
-	return $table;
3114
+    return $table;
3115 3115
 }
3116 3116
 
3117 3117
 /**
@@ -3144,22 +3144,22 @@  discard block
 block discarded – undo
3144 3144
  *     - string : expression trouvée.
3145 3145
  **/
3146 3146
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3147
-	if (intval($modif) and $capte == 0) {
3148
-		$capte = $modif;
3149
-		$modif = 'UuimsS';
3150
-	}
3151
-	$expression = str_replace('\/', '/', $expression);
3152
-	$expression = str_replace('/', '\/', $expression);
3147
+    if (intval($modif) and $capte == 0) {
3148
+        $capte = $modif;
3149
+        $modif = 'UuimsS';
3150
+    }
3151
+    $expression = str_replace('\/', '/', $expression);
3152
+    $expression = str_replace('/', '\/', $expression);
3153 3153
 
3154
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3155
-		if (isset($r[$capte])) {
3156
-			return $r[$capte];
3157
-		} else {
3158
-			return true;
3159
-		}
3160
-	}
3154
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3155
+        if (isset($r[$capte])) {
3156
+            return $r[$capte];
3157
+        } else {
3158
+            return true;
3159
+        }
3160
+    }
3161 3161
 
3162
-	return false;
3162
+    return false;
3163 3163
 }
3164 3164
 
3165 3165
 
@@ -3186,14 +3186,14 @@  discard block
 block discarded – undo
3186 3186
  *     Texte
3187 3187
  **/
3188 3188
 function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string {
3189
-	if (null === $texte) {
3190
-		return '';
3191
-	}
3189
+    if (null === $texte) {
3190
+        return '';
3191
+    }
3192 3192
 
3193
-	$expression = str_replace('\/', '/', $expression);
3194
-	$expression = str_replace('/', '\/', $expression);
3193
+    $expression = str_replace('\/', '/', $expression);
3194
+    $expression = str_replace('/', '\/', $expression);
3195 3195
 
3196
-	return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3196
+    return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3197 3197
 }
3198 3198
 
3199 3199
 
@@ -3211,25 +3211,25 @@  discard block
 block discarded – undo
3211 3211
  **/
3212 3212
 function traiter_doublons_documents(&$doublons, $letexte) {
3213 3213
 
3214
-	// Verifier dans le texte & les notes (pas beau, helas)
3215
-	$t = $letexte . $GLOBALS['les_notes'];
3214
+    // Verifier dans le texte & les notes (pas beau, helas)
3215
+    $t = $letexte . $GLOBALS['les_notes'];
3216 3216
 
3217
-	if (
3218
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3219
-		and preg_match_all(
3220
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3221
-			$t,
3222
-			$matches,
3223
-			PREG_PATTERN_ORDER
3224
-		)
3225
-	) {
3226
-		if (!isset($doublons['documents'])) {
3227
-			$doublons['documents'] = '';
3228
-		}
3229
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3230
-	}
3217
+    if (
3218
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3219
+        and preg_match_all(
3220
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3221
+            $t,
3222
+            $matches,
3223
+            PREG_PATTERN_ORDER
3224
+        )
3225
+    ) {
3226
+        if (!isset($doublons['documents'])) {
3227
+            $doublons['documents'] = '';
3228
+        }
3229
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3230
+    }
3231 3231
 
3232
-	return $letexte;
3232
+    return $letexte;
3233 3233
 }
3234 3234
 
3235 3235
 /**
@@ -3243,7 +3243,7 @@  discard block
 block discarded – undo
3243 3243
  * @return string Chaîne vide
3244 3244
  **/
3245 3245
 function vide($texte) {
3246
-	return '';
3246
+    return '';
3247 3247
 }
3248 3248
 
3249 3249
 //
@@ -3272,23 +3272,23 @@  discard block
 block discarded – undo
3272 3272
  *      Code HTML résultant
3273 3273
  **/
3274 3274
 function env_to_params($env, $ignore_params = []) {
3275
-	$ignore_params = array_merge(
3276
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3277
-		$ignore_params
3278
-	);
3279
-	if (!is_array($env)) {
3280
-		$env = unserialize($env);
3281
-	}
3282
-	$texte = '';
3283
-	if ($env) {
3284
-		foreach ($env as $i => $j) {
3285
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3286
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3287
-			}
3288
-		}
3289
-	}
3290
-
3291
-	return $texte;
3275
+    $ignore_params = array_merge(
3276
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3277
+        $ignore_params
3278
+    );
3279
+    if (!is_array($env)) {
3280
+        $env = unserialize($env);
3281
+    }
3282
+    $texte = '';
3283
+    if ($env) {
3284
+        foreach ($env as $i => $j) {
3285
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3286
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3287
+            }
3288
+        }
3289
+    }
3290
+
3291
+    return $texte;
3292 3292
 }
3293 3293
 
3294 3294
 /**
@@ -3311,23 +3311,23 @@  discard block
 block discarded – undo
3311 3311
  *      Code HTML résultant
3312 3312
  **/
3313 3313
 function env_to_attributs($env, $ignore_params = []) {
3314
-	$ignore_params = array_merge(
3315
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3316
-		$ignore_params
3317
-	);
3318
-	if (!is_array($env)) {
3319
-		$env = unserialize($env);
3320
-	}
3321
-	$texte = '';
3322
-	if ($env) {
3323
-		foreach ($env as $i => $j) {
3324
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3325
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3326
-			}
3327
-		}
3328
-	}
3314
+    $ignore_params = array_merge(
3315
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3316
+        $ignore_params
3317
+    );
3318
+    if (!is_array($env)) {
3319
+        $env = unserialize($env);
3320
+    }
3321
+    $texte = '';
3322
+    if ($env) {
3323
+        foreach ($env as $i => $j) {
3324
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3325
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3326
+            }
3327
+        }
3328
+    }
3329 3329
 
3330
-	return $texte;
3330
+    return $texte;
3331 3331
 }
3332 3332
 
3333 3333
 
@@ -3345,7 +3345,7 @@  discard block
 block discarded – undo
3345 3345
  * @return string Chaînes concaténés
3346 3346
  **/
3347 3347
 function concat(...$args): string {
3348
-	return join('', $args);
3348
+    return join('', $args);
3349 3349
 }
3350 3350
 
3351 3351
 
@@ -3365,23 +3365,23 @@  discard block
 block discarded – undo
3365 3365
  *     Contenu du ou des fichiers, concaténé
3366 3366
  **/
3367 3367
 function charge_scripts($files, $script = true) {
3368
-	$flux = '';
3369
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3370
-		if (!is_string($file)) {
3371
-			continue;
3372
-		}
3373
-		if ($script) {
3374
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3375
-		}
3376
-		if ($file) {
3377
-			$path = find_in_path($file);
3378
-			if ($path) {
3379
-				$flux .= spip_file_get_contents($path);
3380
-			}
3381
-		}
3382
-	}
3383
-
3384
-	return $flux;
3368
+    $flux = '';
3369
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3370
+        if (!is_string($file)) {
3371
+            continue;
3372
+        }
3373
+        if ($script) {
3374
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3375
+        }
3376
+        if ($file) {
3377
+            $path = find_in_path($file);
3378
+            if ($path) {
3379
+                $flux .= spip_file_get_contents($path);
3380
+            }
3381
+        }
3382
+    }
3383
+
3384
+    return $flux;
3385 3385
 }
3386 3386
 
3387 3387
 /**
@@ -3392,22 +3392,22 @@  discard block
 block discarded – undo
3392 3392
  * @return string
3393 3393
  */
3394 3394
 function http_img_variante_svg_si_possible($img_file) {
3395
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3396
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3397
-	if (
3398
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3399
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3400
-		and file_exists($variante_svg_generique)
3401
-	) {
3402
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3403
-			$img_file = $variante_svg_size;
3404
-		}
3405
-		else {
3406
-			$img_file = $variante_svg_generique;
3407
-		}
3408
-	}
3395
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3396
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3397
+    if (
3398
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3399
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3400
+        and file_exists($variante_svg_generique)
3401
+    ) {
3402
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3403
+            $img_file = $variante_svg_size;
3404
+        }
3405
+        else {
3406
+            $img_file = $variante_svg_generique;
3407
+        }
3408
+    }
3409 3409
 
3410
-	return $img_file;
3410
+    return $img_file;
3411 3411
 }
3412 3412
 
3413 3413
 /**
@@ -3428,54 +3428,54 @@  discard block
 block discarded – undo
3428 3428
  */
3429 3429
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3430 3430
 
3431
-	$img_file = $img;
3432
-	if ($p = strpos($img_file, '?')) {
3433
-		$img_file = substr($img_file, 0, $p);
3434
-	}
3435
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3436
-		$img_file = chemin_image($img);
3437
-	}
3438
-	else {
3439
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3440
-			$img_file = http_img_variante_svg_si_possible($img_file);
3441
-		}
3442
-	}
3443
-	if (stripos($atts, 'width') === false) {
3444
-		// utiliser directement l'info de taille presente dans le nom
3445
-		if (
3446
-			(!isset($options['utiliser_suffixe_size'])
3447
-				or $options['utiliser_suffixe_size'] == true
3448
-				or str_contains($img_file, '-xx.svg'))
3449
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3450
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3451
-		) {
3452
-			$largeur = $hauteur = intval($regs[1]);
3453
-		} else {
3454
-			$taille = taille_image($img_file);
3455
-			[$hauteur, $largeur] = $taille;
3456
-			if (!$hauteur or !$largeur) {
3457
-				return '';
3458
-			}
3459
-		}
3460
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3461
-	}
3462
-
3463
-	if (file_exists($img_file)) {
3464
-		$img_file = timestamp($img_file);
3465
-	}
3466
-	if ($alt === false) {
3467
-		$alt = '';
3468
-	}
3469
-	elseif ($alt or $alt === '') {
3470
-		$alt = " alt='" . attribut_html($alt) . "'";
3471
-	}
3472
-	else {
3473
-		$alt = " alt='" . attribut_html($title) . "'";
3474
-	}
3475
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3476
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3477
-	. ' ' . ltrim($atts)
3478
-	. ' />';
3431
+    $img_file = $img;
3432
+    if ($p = strpos($img_file, '?')) {
3433
+        $img_file = substr($img_file, 0, $p);
3434
+    }
3435
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3436
+        $img_file = chemin_image($img);
3437
+    }
3438
+    else {
3439
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3440
+            $img_file = http_img_variante_svg_si_possible($img_file);
3441
+        }
3442
+    }
3443
+    if (stripos($atts, 'width') === false) {
3444
+        // utiliser directement l'info de taille presente dans le nom
3445
+        if (
3446
+            (!isset($options['utiliser_suffixe_size'])
3447
+                or $options['utiliser_suffixe_size'] == true
3448
+                or str_contains($img_file, '-xx.svg'))
3449
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3450
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3451
+        ) {
3452
+            $largeur = $hauteur = intval($regs[1]);
3453
+        } else {
3454
+            $taille = taille_image($img_file);
3455
+            [$hauteur, $largeur] = $taille;
3456
+            if (!$hauteur or !$largeur) {
3457
+                return '';
3458
+            }
3459
+        }
3460
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3461
+    }
3462
+
3463
+    if (file_exists($img_file)) {
3464
+        $img_file = timestamp($img_file);
3465
+    }
3466
+    if ($alt === false) {
3467
+        $alt = '';
3468
+    }
3469
+    elseif ($alt or $alt === '') {
3470
+        $alt = " alt='" . attribut_html($alt) . "'";
3471
+    }
3472
+    else {
3473
+        $alt = " alt='" . attribut_html($title) . "'";
3474
+    }
3475
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3476
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3477
+    . ' ' . ltrim($atts)
3478
+    . ' />';
3479 3479
 }
3480 3480
 
3481 3481
 /**
@@ -3487,70 +3487,70 @@  discard block
 block discarded – undo
3487 3487
  * @return string
3488 3488
  */
3489 3489
 function http_style_background($img, $att = '', $size = null) {
3490
-	if ($size and is_numeric($size)) {
3491
-		$size = trim($size) . 'px';
3492
-	}
3493
-	return " style='background" .
3494
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3495
-		. ($size ? "background-size:{$size};" : '')
3496
-		. "'";
3490
+    if ($size and is_numeric($size)) {
3491
+        $size = trim($size) . 'px';
3492
+    }
3493
+    return " style='background" .
3494
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3495
+        . ($size ? "background-size:{$size};" : '')
3496
+        . "'";
3497 3497
 }
3498 3498
 
3499 3499
 
3500 3500
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3501
-	$args = [$alt_or_size, $class_or_size, $size];
3502
-	while (is_null(end($args)) and count($args)) {
3503
-		array_pop($args);
3504
-	}
3505
-	if (!count($args)) {
3506
-		return [null, null, null];
3507
-	}
3508
-	if (count($args) < 3) {
3509
-		$maybe_size = array_pop($args);
3510
-		// @2x
3511
-		// @1.5x
3512
-		// 512
3513
-		// 512x*
3514
-		// 512x300
3515
-		if (
3516
-			!strlen($maybe_size)
3517
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3518
-		) {
3519
-			$args[] = $maybe_size;
3520
-			$maybe_size = null;
3521
-		}
3522
-		while (count($args) < 2) {
3523
-			$args[] = null; // default alt or class
3524
-		}
3525
-		$args[] = $maybe_size;
3526
-	}
3527
-	return $args;
3501
+    $args = [$alt_or_size, $class_or_size, $size];
3502
+    while (is_null(end($args)) and count($args)) {
3503
+        array_pop($args);
3504
+    }
3505
+    if (!count($args)) {
3506
+        return [null, null, null];
3507
+    }
3508
+    if (count($args) < 3) {
3509
+        $maybe_size = array_pop($args);
3510
+        // @2x
3511
+        // @1.5x
3512
+        // 512
3513
+        // 512x*
3514
+        // 512x300
3515
+        if (
3516
+            !strlen($maybe_size)
3517
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3518
+        ) {
3519
+            $args[] = $maybe_size;
3520
+            $maybe_size = null;
3521
+        }
3522
+        while (count($args) < 2) {
3523
+            $args[] = null; // default alt or class
3524
+        }
3525
+        $args[] = $maybe_size;
3526
+    }
3527
+    return $args;
3528 3528
 }
3529 3529
 
3530 3530
 function helper_filtre_balise_img_svg_size($img, $size) {
3531
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3532
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3533
-		$coef = floatval(substr($size, 1, -1));
3534
-		[$h, $w] = taille_image($img);
3535
-		$height = intval(round($h / $coef));
3536
-		$width = intval(round($w / $coef));
3537
-	}
3538
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3539
-	else {
3540
-		$size = explode('x', $size, 2);
3541
-		$size = array_map('trim', $size);
3542
-		$height = $width = intval(array_shift($size));
3543
-
3544
-		if (count($size) and reset($size)) {
3545
-			$height = array_shift($size);
3546
-			if ($height === '*') {
3547
-				[$h, $w] = taille_image($img);
3548
-				$height = intval(round($h * $width / $w));
3549
-			}
3550
-		}
3551
-	}
3552
-
3553
-	return [$width, $height];
3531
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3532
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3533
+        $coef = floatval(substr($size, 1, -1));
3534
+        [$h, $w] = taille_image($img);
3535
+        $height = intval(round($h / $coef));
3536
+        $width = intval(round($w / $coef));
3537
+    }
3538
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3539
+    else {
3540
+        $size = explode('x', $size, 2);
3541
+        $size = array_map('trim', $size);
3542
+        $height = $width = intval(array_shift($size));
3543
+
3544
+        if (count($size) and reset($size)) {
3545
+            $height = array_shift($size);
3546
+            if ($height === '*') {
3547
+                [$h, $w] = taille_image($img);
3548
+                $height = intval(round($h * $width / $w));
3549
+            }
3550
+        }
3551
+    }
3552
+
3553
+    return [$width, $height];
3554 3554
 }
3555 3555
 
3556 3556
 /**
@@ -3586,43 +3586,43 @@  discard block
 block discarded – undo
3586 3586
  */
3587 3587
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3588 3588
 
3589
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3590
-
3591
-	$img = trim((string) $img);
3592
-	if (strpos($img, '<img') === 0) {
3593
-		if (!is_null($alt)) {
3594
-			$img = inserer_attribut($img, 'alt', $alt);
3595
-		}
3596
-		if (!is_null($class)) {
3597
-			if (strlen($class)) {
3598
-				$img = inserer_attribut($img, 'class', $class);
3599
-			}
3600
-			else {
3601
-				$img = vider_attribut($img, 'class');
3602
-			}
3603
-		}
3604
-	}
3605
-	else {
3606
-		$img = http_img_pack(
3607
-			$img,
3608
-			$alt,
3609
-			$class ? " class='" . attribut_html($class) . "'" : '',
3610
-			'',
3611
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3612
-		);
3613
-		if (is_null($alt)) {
3614
-			$img = vider_attribut($img, 'alt');
3615
-		}
3616
-	}
3617
-
3618
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3619
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3620
-
3621
-		$img = inserer_attribut($img, 'width', $width);
3622
-		$img = inserer_attribut($img, 'height', $height);
3623
-	}
3624
-
3625
-	return $img;
3589
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3590
+
3591
+    $img = trim((string) $img);
3592
+    if (strpos($img, '<img') === 0) {
3593
+        if (!is_null($alt)) {
3594
+            $img = inserer_attribut($img, 'alt', $alt);
3595
+        }
3596
+        if (!is_null($class)) {
3597
+            if (strlen($class)) {
3598
+                $img = inserer_attribut($img, 'class', $class);
3599
+            }
3600
+            else {
3601
+                $img = vider_attribut($img, 'class');
3602
+            }
3603
+        }
3604
+    }
3605
+    else {
3606
+        $img = http_img_pack(
3607
+            $img,
3608
+            $alt,
3609
+            $class ? " class='" . attribut_html($class) . "'" : '',
3610
+            '',
3611
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3612
+        );
3613
+        if (is_null($alt)) {
3614
+            $img = vider_attribut($img, 'alt');
3615
+        }
3616
+    }
3617
+
3618
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3619
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3620
+
3621
+        $img = inserer_attribut($img, 'width', $width);
3622
+        $img = inserer_attribut($img, 'height', $height);
3623
+    }
3624
+
3625
+    return $img;
3626 3626
 }
3627 3627
 
3628 3628
 
@@ -3656,80 +3656,80 @@  discard block
 block discarded – undo
3656 3656
  */
3657 3657
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3658 3658
 
3659
-	$svg = null;
3660
-	$img = trim($img);
3661
-	$img_file = $img;
3662
-	if (strpos($img, '<svg') === false) {
3663
-		if ($p = strpos($img_file, '?')) {
3664
-			$img_file = substr($img_file, 0, $p);
3665
-		}
3666
-
3667
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3668
-		// la copie locale a toutes les chances d'etre la ou de resservir
3669
-		if (tester_url_absolue($img_file)) {
3670
-			include_spip('inc/distant');
3671
-			$fichier = copie_locale($img_file);
3672
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3673
-		}
3674
-
3675
-		if (
3676
-			!$img_file
3677
-			or !file_exists($img_file)
3678
-			or !$svg = file_get_contents($img_file)
3679
-		) {
3680
-			return '';
3681
-		}
3682
-	}
3683
-
3684
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3685
-		return '';
3686
-	}
3687
-
3688
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3689
-
3690
-	$balise_svg = $match[0];
3691
-	$balise_svg_source = $balise_svg;
3692
-
3693
-	// entete XML à supprimer
3694
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3695
-
3696
-	// IE est toujours mon ami
3697
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3698
-
3699
-	// regler la classe
3700
-	if (!is_null($class)) {
3701
-		if (strlen($class)) {
3702
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3703
-		}
3704
-		else {
3705
-			$balise_svg = vider_attribut($balise_svg, 'class');
3706
-		}
3707
-	}
3708
-
3709
-	// regler le alt
3710
-	if ($alt) {
3711
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3712
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3713
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3714
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3715
-		$balise_svg .= $title;
3716
-	}
3717
-	else {
3718
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3719
-	}
3720
-
3721
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3722
-
3723
-	if (!is_null($size) and strlen($size = trim($size))) {
3724
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3725
-
3726
-		if (!function_exists('svg_redimensionner')) {
3727
-			include_spip('inc/svg');
3728
-		}
3729
-		$svg = svg_redimensionner($svg, $width, $height);
3730
-	}
3731
-
3732
-	return $svg;
3659
+    $svg = null;
3660
+    $img = trim($img);
3661
+    $img_file = $img;
3662
+    if (strpos($img, '<svg') === false) {
3663
+        if ($p = strpos($img_file, '?')) {
3664
+            $img_file = substr($img_file, 0, $p);
3665
+        }
3666
+
3667
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3668
+        // la copie locale a toutes les chances d'etre la ou de resservir
3669
+        if (tester_url_absolue($img_file)) {
3670
+            include_spip('inc/distant');
3671
+            $fichier = copie_locale($img_file);
3672
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3673
+        }
3674
+
3675
+        if (
3676
+            !$img_file
3677
+            or !file_exists($img_file)
3678
+            or !$svg = file_get_contents($img_file)
3679
+        ) {
3680
+            return '';
3681
+        }
3682
+    }
3683
+
3684
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3685
+        return '';
3686
+    }
3687
+
3688
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3689
+
3690
+    $balise_svg = $match[0];
3691
+    $balise_svg_source = $balise_svg;
3692
+
3693
+    // entete XML à supprimer
3694
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3695
+
3696
+    // IE est toujours mon ami
3697
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3698
+
3699
+    // regler la classe
3700
+    if (!is_null($class)) {
3701
+        if (strlen($class)) {
3702
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3703
+        }
3704
+        else {
3705
+            $balise_svg = vider_attribut($balise_svg, 'class');
3706
+        }
3707
+    }
3708
+
3709
+    // regler le alt
3710
+    if ($alt) {
3711
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3712
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3713
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3714
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3715
+        $balise_svg .= $title;
3716
+    }
3717
+    else {
3718
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3719
+    }
3720
+
3721
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3722
+
3723
+    if (!is_null($size) and strlen($size = trim($size))) {
3724
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3725
+
3726
+        if (!function_exists('svg_redimensionner')) {
3727
+            include_spip('inc/svg');
3728
+        }
3729
+        $svg = svg_redimensionner($svg, $width, $height);
3730
+    }
3731
+
3732
+    return $svg;
3733 3733
 }
3734 3734
 
3735 3735
 
@@ -3755,18 +3755,18 @@  discard block
 block discarded – undo
3755 3755
  *     Code HTML résultant
3756 3756
  **/
3757 3757
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3758
-	$texte = '';
3759
-	if (is_array($tableau)) {
3760
-		foreach ($tableau as $k => $v) {
3761
-			$res = recuperer_fond(
3762
-				'modeles/' . $modele,
3763
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3764
-			);
3765
-			$texte .= $res;
3766
-		}
3767
-	}
3758
+    $texte = '';
3759
+    if (is_array($tableau)) {
3760
+        foreach ($tableau as $k => $v) {
3761
+            $res = recuperer_fond(
3762
+                'modeles/' . $modele,
3763
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3764
+            );
3765
+            $texte .= $res;
3766
+        }
3767
+    }
3768 3768
 
3769
-	return $texte;
3769
+    return $texte;
3770 3770
 }
3771 3771
 
3772 3772
 
@@ -3791,37 +3791,37 @@  discard block
 block discarded – undo
3791 3791
  *         - tout : retourne toutes les informations du plugin actif
3792 3792
  **/
3793 3793
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3794
-	include_spip('inc/plugin');
3795
-	$plugin = strtoupper($plugin);
3796
-	$plugins_actifs = liste_plugin_actifs();
3797
-
3798
-	if (!$plugin) {
3799
-		return serialize(array_keys($plugins_actifs));
3800
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3801
-		return '';
3802
-	} elseif (($type_info == 'est_actif') and !$reload) {
3803
-		return $plugins_actifs[$plugin] ? 1 : 0;
3804
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3805
-		return $plugins_actifs[$plugin][$type_info];
3806
-	} else {
3807
-		$get_infos = charger_fonction('get_infos', 'plugins');
3808
-		// On prend en compte les extensions
3809
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3810
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3811
-		} else {
3812
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3813
-		}
3814
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3815
-			return '';
3816
-		}
3817
-		if ($type_info == 'tout') {
3818
-			return $infos;
3819
-		} elseif ($type_info == 'est_actif') {
3820
-			return $infos ? 1 : 0;
3821
-		} else {
3822
-			return strval($infos[$type_info]);
3823
-		}
3824
-	}
3794
+    include_spip('inc/plugin');
3795
+    $plugin = strtoupper($plugin);
3796
+    $plugins_actifs = liste_plugin_actifs();
3797
+
3798
+    if (!$plugin) {
3799
+        return serialize(array_keys($plugins_actifs));
3800
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3801
+        return '';
3802
+    } elseif (($type_info == 'est_actif') and !$reload) {
3803
+        return $plugins_actifs[$plugin] ? 1 : 0;
3804
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3805
+        return $plugins_actifs[$plugin][$type_info];
3806
+    } else {
3807
+        $get_infos = charger_fonction('get_infos', 'plugins');
3808
+        // On prend en compte les extensions
3809
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3810
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3811
+        } else {
3812
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3813
+        }
3814
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3815
+            return '';
3816
+        }
3817
+        if ($type_info == 'tout') {
3818
+            return $infos;
3819
+        } elseif ($type_info == 'est_actif') {
3820
+            return $infos ? 1 : 0;
3821
+        } else {
3822
+            return strval($infos[$type_info]);
3823
+        }
3824
+    }
3825 3825
 }
3826 3826
 
3827 3827
 
@@ -3848,9 +3848,9 @@  discard block
 block discarded – undo
3848 3848
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3849 3849
  */
3850 3850
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3851
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3851
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3852 3852
 
3853
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3853
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3854 3854
 }
3855 3855
 
3856 3856
 
@@ -3880,19 +3880,19 @@  discard block
 block discarded – undo
3880 3880
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3881 3881
  */
3882 3882
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3883
-	static $puce_statut = null;
3884
-	if (!$puce_statut) {
3885
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3886
-	}
3883
+    static $puce_statut = null;
3884
+    if (!$puce_statut) {
3885
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3886
+    }
3887 3887
 
3888
-	return $puce_statut(
3889
-		$id_objet,
3890
-		$statut,
3891
-		$id_parent,
3892
-		$objet,
3893
-		false,
3894
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3895
-	);
3888
+    return $puce_statut(
3889
+        $id_objet,
3890
+        $statut,
3891
+        $id_parent,
3892
+        $objet,
3893
+        false,
3894
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3895
+    );
3896 3896
 }
3897 3897
 
3898 3898
 
@@ -3919,98 +3919,98 @@  discard block
 block discarded – undo
3919 3919
  *   hash du contexte
3920 3920
  */
3921 3921
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3922
-	$env = null;
3923
-	if (
3924
-		is_string($c)
3925
-		and @unserialize($c) !== false
3926
-	) {
3927
-		$c = unserialize($c);
3928
-	}
3929
-
3930
-	// supprimer les parametres debut_x
3931
-	// pour que la pagination ajax ne soit pas plantee
3932
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3933
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3934
-	if (is_array($c)) {
3935
-		foreach ($c as $k => $v) {
3936
-			if (strpos($k, 'debut_') === 0) {
3937
-				unset($c[$k]);
3938
-			}
3939
-		}
3940
-	}
3941
-
3942
-	if (!function_exists('calculer_cle_action')) {
3943
-		include_spip('inc/securiser_action');
3944
-	}
3945
-
3946
-	$c = serialize($c);
3947
-	$cle = calculer_cle_action($form . $c);
3948
-	$c = "$cle:$c";
3949
-
3950
-	// on ne stocke pas les contextes dans des fichiers en cache
3951
-	// par defaut, sauf si cette configuration a été forcée
3952
-	// OU que la longueur de l’argument géneré est plus long
3953
-	// que ce qui est toléré.
3954
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3955
-	if (!$cache_contextes_ajax) {
3956
-		$env = $c;
3957
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3958
-			$env = gzdeflate($env);
3959
-		}
3960
-		$env = _xor($env);
3961
-		$env = base64_encode($env);
3962
-		$len = strlen($env);
3963
-		// Si l’url est trop longue pour le navigateur
3964
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3965
-		if ($len > $max_len) {
3966
-			$cache_contextes_ajax = true;
3967
-			spip_log(
3968
-				'Contextes AJAX forces en fichiers !'
3969
-				. ' Cela arrive lorsque la valeur du contexte'
3970
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3971
-				_LOG_AVERTISSEMENT
3972
-			);
3973
-		}
3974
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3975
-		elseif (
3976
-			$max_len = @ini_get('suhosin.get.max_value_length')
3977
-			and $max_len < $len
3978
-		) {
3979
-			$cache_contextes_ajax = true;
3980
-			spip_log('Contextes AJAX forces en fichiers !'
3981
-				. ' Cela arrive lorsque la valeur du contexte'
3982
-				. ' depasse la longueur maximale autorisee par Suhosin'
3983
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3984
-				. ' Vous devriez modifier les parametres de Suhosin'
3985
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3986
-		}
3987
-	}
3988
-
3989
-	if ($cache_contextes_ajax) {
3990
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3991
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3992
-		$md5 = md5($c);
3993
-		ecrire_fichier("$dir/c$md5", $c);
3994
-		$env = $md5;
3995
-	}
3996
-
3997
-	if ($emboite === null) {
3998
-		return $env;
3999
-	}
4000
-	if (!trim($emboite)) {
4001
-		return '';
4002
-	}
4003
-	// toujours encoder l'url source dans le bloc ajax
4004
-	$r = self();
4005
-	$r = ' data-origin="' . $r . '"';
4006
-	$class = 'ajaxbloc';
4007
-	if ($ajaxid and is_string($ajaxid)) {
4008
-		// ajaxid est normalement conforme a un nom de classe css
4009
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4010
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4011
-	}
4012
-
4013
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3922
+    $env = null;
3923
+    if (
3924
+        is_string($c)
3925
+        and @unserialize($c) !== false
3926
+    ) {
3927
+        $c = unserialize($c);
3928
+    }
3929
+
3930
+    // supprimer les parametres debut_x
3931
+    // pour que la pagination ajax ne soit pas plantee
3932
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3933
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3934
+    if (is_array($c)) {
3935
+        foreach ($c as $k => $v) {
3936
+            if (strpos($k, 'debut_') === 0) {
3937
+                unset($c[$k]);
3938
+            }
3939
+        }
3940
+    }
3941
+
3942
+    if (!function_exists('calculer_cle_action')) {
3943
+        include_spip('inc/securiser_action');
3944
+    }
3945
+
3946
+    $c = serialize($c);
3947
+    $cle = calculer_cle_action($form . $c);
3948
+    $c = "$cle:$c";
3949
+
3950
+    // on ne stocke pas les contextes dans des fichiers en cache
3951
+    // par defaut, sauf si cette configuration a été forcée
3952
+    // OU que la longueur de l’argument géneré est plus long
3953
+    // que ce qui est toléré.
3954
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3955
+    if (!$cache_contextes_ajax) {
3956
+        $env = $c;
3957
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3958
+            $env = gzdeflate($env);
3959
+        }
3960
+        $env = _xor($env);
3961
+        $env = base64_encode($env);
3962
+        $len = strlen($env);
3963
+        // Si l’url est trop longue pour le navigateur
3964
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3965
+        if ($len > $max_len) {
3966
+            $cache_contextes_ajax = true;
3967
+            spip_log(
3968
+                'Contextes AJAX forces en fichiers !'
3969
+                . ' Cela arrive lorsque la valeur du contexte'
3970
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3971
+                _LOG_AVERTISSEMENT
3972
+            );
3973
+        }
3974
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3975
+        elseif (
3976
+            $max_len = @ini_get('suhosin.get.max_value_length')
3977
+            and $max_len < $len
3978
+        ) {
3979
+            $cache_contextes_ajax = true;
3980
+            spip_log('Contextes AJAX forces en fichiers !'
3981
+                . ' Cela arrive lorsque la valeur du contexte'
3982
+                . ' depasse la longueur maximale autorisee par Suhosin'
3983
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3984
+                . ' Vous devriez modifier les parametres de Suhosin'
3985
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3986
+        }
3987
+    }
3988
+
3989
+    if ($cache_contextes_ajax) {
3990
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3991
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3992
+        $md5 = md5($c);
3993
+        ecrire_fichier("$dir/c$md5", $c);
3994
+        $env = $md5;
3995
+    }
3996
+
3997
+    if ($emboite === null) {
3998
+        return $env;
3999
+    }
4000
+    if (!trim($emboite)) {
4001
+        return '';
4002
+    }
4003
+    // toujours encoder l'url source dans le bloc ajax
4004
+    $r = self();
4005
+    $r = ' data-origin="' . $r . '"';
4006
+    $class = 'ajaxbloc';
4007
+    if ($ajaxid and is_string($ajaxid)) {
4008
+        // ajaxid est normalement conforme a un nom de classe css
4009
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4010
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4011
+    }
4012
+
4013
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4014 4014
 }
4015 4015
 
4016 4016
 /**
@@ -4030,37 +4030,37 @@  discard block
 block discarded – undo
4030 4030
  *   - false : erreur de décodage
4031 4031
  */
4032 4032
 function decoder_contexte_ajax($c, $form = '') {
4033
-	if (!function_exists('calculer_cle_action')) {
4034
-		include_spip('inc/securiser_action');
4035
-	}
4036
-	if (
4037
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4038
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4039
-		and lire_fichier("$dir/c$c", $contexte)
4040
-	) {
4041
-		$c = $contexte;
4042
-	} else {
4043
-		$c = @base64_decode($c);
4044
-		$c = _xor($c);
4045
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4046
-			$c = @gzinflate($c);
4047
-		}
4048
-	}
4049
-
4050
-	// extraire la signature en debut de contexte
4051
-	// et la verifier avant de deserializer
4052
-	// format : signature:donneesserializees
4053
-	if ($p = strpos($c, ':')) {
4054
-		$cle = substr($c, 0, $p);
4055
-		$c = substr($c, $p + 1);
4056
-
4057
-		if ($cle == calculer_cle_action($form . $c)) {
4058
-			$env = @unserialize($c);
4059
-			return $env;
4060
-		}
4061
-	}
4062
-
4063
-	return false;
4033
+    if (!function_exists('calculer_cle_action')) {
4034
+        include_spip('inc/securiser_action');
4035
+    }
4036
+    if (
4037
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4038
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4039
+        and lire_fichier("$dir/c$c", $contexte)
4040
+    ) {
4041
+        $c = $contexte;
4042
+    } else {
4043
+        $c = @base64_decode($c);
4044
+        $c = _xor($c);
4045
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4046
+            $c = @gzinflate($c);
4047
+        }
4048
+    }
4049
+
4050
+    // extraire la signature en debut de contexte
4051
+    // et la verifier avant de deserializer
4052
+    // format : signature:donneesserializees
4053
+    if ($p = strpos($c, ':')) {
4054
+        $cle = substr($c, 0, $p);
4055
+        $c = substr($c, $p + 1);
4056
+
4057
+        if ($cle == calculer_cle_action($form . $c)) {
4058
+            $env = @unserialize($c);
4059
+            return $env;
4060
+        }
4061
+    }
4062
+
4063
+    return false;
4064 4064
 }
4065 4065
 
4066 4066
 
@@ -4078,20 +4078,20 @@  discard block
 block discarded – undo
4078 4078
  *    Message décrypté ou encrypté
4079 4079
  **/
4080 4080
 function _xor($message, $key = null) {
4081
-	if (is_null($key)) {
4082
-		if (!function_exists('calculer_cle_action')) {
4083
-			include_spip('inc/securiser_action');
4084
-		}
4085
-		$key = pack('H*', calculer_cle_action('_xor'));
4086
-	}
4081
+    if (is_null($key)) {
4082
+        if (!function_exists('calculer_cle_action')) {
4083
+            include_spip('inc/securiser_action');
4084
+        }
4085
+        $key = pack('H*', calculer_cle_action('_xor'));
4086
+    }
4087 4087
 
4088
-	$keylen = strlen($key);
4089
-	$messagelen = strlen($message);
4090
-	for ($i = 0; $i < $messagelen; $i++) {
4091
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4092
-	}
4088
+    $keylen = strlen($key);
4089
+    $messagelen = strlen($message);
4090
+    for ($i = 0; $i < $messagelen; $i++) {
4091
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4092
+    }
4093 4093
 
4094
-	return $message;
4094
+    return $message;
4095 4095
 }
4096 4096
 
4097 4097
 /**
@@ -4105,7 +4105,7 @@  discard block
 block discarded – undo
4105 4105
  * @return string
4106 4106
  */
4107 4107
 function url_reponse_forum($texte) {
4108
- return $texte;
4108
+    return $texte;
4109 4109
 }
4110 4110
 
4111 4111
 /**
@@ -4119,7 +4119,7 @@  discard block
 block discarded – undo
4119 4119
  * @return string
4120 4120
  */
4121 4121
 function url_rss_forum($texte) {
4122
- return $texte;
4122
+    return $texte;
4123 4123
 }
4124 4124
 
4125 4125
 
@@ -4158,37 +4158,37 @@  discard block
 block discarded – undo
4158 4158
  *   Code HTML
4159 4159
  */
4160 4160
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4161
-	if ($on) {
4162
-		$bal = 'strong';
4163
-		$class = '';
4164
-		$att = '';
4165
-		// si $on passe la balise et optionnelement une ou ++classe
4166
-		// a.active span.selected.active etc....
4167
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4168
-			$on = explode('.', $on);
4169
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4170
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4171
-				$bal = array_shift($on);
4172
-				$class = implode(' ', $on);
4173
-				if ($bal == 'a') {
4174
-					$att = 'href="#" ';
4175
-				}
4176
-			}
4177
-		}
4178
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4179
-	} else {
4180
-		$bal = 'a';
4181
-		$att = "href='$url'"
4182
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4183
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4184
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4185
-			. $evt;
4186
-	}
4187
-	if ($libelle === null) {
4188
-		$libelle = $url;
4189
-	}
4190
-
4191
-	return "<$bal $att>$libelle</$bal>";
4161
+    if ($on) {
4162
+        $bal = 'strong';
4163
+        $class = '';
4164
+        $att = '';
4165
+        // si $on passe la balise et optionnelement une ou ++classe
4166
+        // a.active span.selected.active etc....
4167
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4168
+            $on = explode('.', $on);
4169
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4170
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4171
+                $bal = array_shift($on);
4172
+                $class = implode(' ', $on);
4173
+                if ($bal == 'a') {
4174
+                    $att = 'href="#" ';
4175
+                }
4176
+            }
4177
+        }
4178
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4179
+    } else {
4180
+        $bal = 'a';
4181
+        $att = "href='$url'"
4182
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4183
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4184
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4185
+            . $evt;
4186
+    }
4187
+    if ($libelle === null) {
4188
+        $libelle = $url;
4189
+    }
4190
+
4191
+    return "<$bal $att>$libelle</$bal>";
4192 4192
 }
4193 4193
 
4194 4194
 
@@ -4205,39 +4205,39 @@  discard block
 block discarded – undo
4205 4205
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4206 4206
  */
4207 4207
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4208
-	static $local_singulier_ou_pluriel = [];
4209
-
4210
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4211
-	if (!is_numeric($nb) or $nb == 0) {
4212
-		return '';
4213
-	}
4214
-	if (!is_array($vars)) {
4215
-		return '';
4216
-	}
4217
-
4218
-	$langue = $GLOBALS['spip_lang'];
4219
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4220
-		$local_singulier_ou_pluriel[$langue] = false;
4221
-		if (
4222
-			$f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4223
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4224
-		) {
4225
-			$local_singulier_ou_pluriel[$langue] = $f;
4226
-		}
4227
-	}
4228
-
4229
-	// si on a une surcharge on l'utilise
4230
-	if ($local_singulier_ou_pluriel[$langue]) {
4231
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4232
-	}
4233
-
4234
-	// sinon traitement par defaut
4235
-	$vars[$var] = $nb;
4236
-	if ($nb >= 2) {
4237
-		return _T($chaine_plusieurs, $vars);
4238
-	} else {
4239
-		return _T($chaine_un, $vars);
4240
-	}
4208
+    static $local_singulier_ou_pluriel = [];
4209
+
4210
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4211
+    if (!is_numeric($nb) or $nb == 0) {
4212
+        return '';
4213
+    }
4214
+    if (!is_array($vars)) {
4215
+        return '';
4216
+    }
4217
+
4218
+    $langue = $GLOBALS['spip_lang'];
4219
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4220
+        $local_singulier_ou_pluriel[$langue] = false;
4221
+        if (
4222
+            $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4223
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4224
+        ) {
4225
+            $local_singulier_ou_pluriel[$langue] = $f;
4226
+        }
4227
+    }
4228
+
4229
+    // si on a une surcharge on l'utilise
4230
+    if ($local_singulier_ou_pluriel[$langue]) {
4231
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4232
+    }
4233
+
4234
+    // sinon traitement par defaut
4235
+    $vars[$var] = $nb;
4236
+    if ($nb >= 2) {
4237
+        return _T($chaine_plusieurs, $vars);
4238
+    } else {
4239
+        return _T($chaine_un, $vars);
4240
+    }
4241 4241
 }
4242 4242
 
4243 4243
 
@@ -4265,73 +4265,73 @@  discard block
 block discarded – undo
4265 4265
  */
4266 4266
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4267 4267
 
4268
-	$class_lien = $class_bouton = $class;
4269
-
4270
-	// Normaliser la fonction et compléter la classe en fonction
4271
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4272
-		$class_lien .= ' danger';
4273
-		$class_bouton .= ' btn_danger';
4274
-	} elseif ($fonction == 'rien.gif') {
4275
-		$fonction = '';
4276
-	} elseif ($fonction == 'delsafe') {
4277
-		$fonction = 'del';
4278
-	}
4279
-
4280
-	$fond_origine = $fond;
4281
-	// Remappage des icone : article-24.png+new => article-new-24.png
4282
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4283
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4284
-	}
4285
-
4286
-	// Ajouter le type d'objet dans la classe
4287
-	$objet_type = substr(basename($fond), 0, -4);
4288
-	$class_lien .= " $objet_type";
4289
-	$class_bouton .= " $objet_type";
4290
-
4291
-	// texte
4292
-	$alt = attribut_html($texte);
4293
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4294
-
4295
-	// Liens : préparer les classes ajax
4296
-	$ajax = '';
4297
-	if ($type === 'lien') {
4298
-		if (strpos($class_lien, 'ajax') !== false) {
4299
-			$ajax = 'ajax';
4300
-			if (strpos($class_lien, 'preload') !== false) {
4301
-				$ajax .= ' preload';
4302
-			}
4303
-			if (strpos($class_lien, 'nocache') !== false) {
4304
-				$ajax .= ' nocache';
4305
-			}
4306
-			$ajax = " class='$ajax'";
4307
-		}
4308
-	}
4309
-
4310
-	// Repérer la taille et l'ajouter dans la classe
4311
-	$size = 24;
4312
-	if (
4313
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4314
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4315
-	) {
4316
-		$size = $match[1];
4317
-	}
4318
-	$class_lien .= " s$size";
4319
-	$class_bouton .= " s$size";
4320
-
4321
-	// Icône
4322
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4323
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4324
-
4325
-	// Markup final
4326
-	if ($type == 'lien') {
4327
-		return "<span class='icone $class_lien'>"
4328
-		. "<a href='$lien'$title$ajax$javascript>"
4329
-		. $icone
4330
-		. "<b>$texte</b>"
4331
-		. "</a></span>\n";
4332
-	} else {
4333
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4334
-	}
4268
+    $class_lien = $class_bouton = $class;
4269
+
4270
+    // Normaliser la fonction et compléter la classe en fonction
4271
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4272
+        $class_lien .= ' danger';
4273
+        $class_bouton .= ' btn_danger';
4274
+    } elseif ($fonction == 'rien.gif') {
4275
+        $fonction = '';
4276
+    } elseif ($fonction == 'delsafe') {
4277
+        $fonction = 'del';
4278
+    }
4279
+
4280
+    $fond_origine = $fond;
4281
+    // Remappage des icone : article-24.png+new => article-new-24.png
4282
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4283
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4284
+    }
4285
+
4286
+    // Ajouter le type d'objet dans la classe
4287
+    $objet_type = substr(basename($fond), 0, -4);
4288
+    $class_lien .= " $objet_type";
4289
+    $class_bouton .= " $objet_type";
4290
+
4291
+    // texte
4292
+    $alt = attribut_html($texte);
4293
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4294
+
4295
+    // Liens : préparer les classes ajax
4296
+    $ajax = '';
4297
+    if ($type === 'lien') {
4298
+        if (strpos($class_lien, 'ajax') !== false) {
4299
+            $ajax = 'ajax';
4300
+            if (strpos($class_lien, 'preload') !== false) {
4301
+                $ajax .= ' preload';
4302
+            }
4303
+            if (strpos($class_lien, 'nocache') !== false) {
4304
+                $ajax .= ' nocache';
4305
+            }
4306
+            $ajax = " class='$ajax'";
4307
+        }
4308
+    }
4309
+
4310
+    // Repérer la taille et l'ajouter dans la classe
4311
+    $size = 24;
4312
+    if (
4313
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4314
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4315
+    ) {
4316
+        $size = $match[1];
4317
+    }
4318
+    $class_lien .= " s$size";
4319
+    $class_bouton .= " s$size";
4320
+
4321
+    // Icône
4322
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4323
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4324
+
4325
+    // Markup final
4326
+    if ($type == 'lien') {
4327
+        return "<span class='icone $class_lien'>"
4328
+        . "<a href='$lien'$title$ajax$javascript>"
4329
+        . $icone
4330
+        . "<b>$texte</b>"
4331
+        . "</a></span>\n";
4332
+    } else {
4333
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4334
+    }
4335 4335
 }
4336 4336
 
4337 4337
 /**
@@ -4355,7 +4355,7 @@  discard block
 block discarded – undo
4355 4355
  *     Code HTML du lien
4356 4356
  **/
4357 4357
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4358
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4358
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4359 4359
 }
4360 4360
 
4361 4361
 /**
@@ -4390,7 +4390,7 @@  discard block
 block discarded – undo
4390 4390
  *     Code HTML du lien
4391 4391
  **/
4392 4392
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4393
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4393
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4394 4394
 }
4395 4395
 
4396 4396
 /**
@@ -4435,7 +4435,7 @@  discard block
 block discarded – undo
4435 4435
  *     Code HTML du lien
4436 4436
  **/
4437 4437
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4438
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4438
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4439 4439
 }
4440 4440
 
4441 4441
 /**
@@ -4466,7 +4466,7 @@  discard block
 block discarded – undo
4466 4466
  *     Code HTML du lien
4467 4467
  **/
4468 4468
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4469
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4469
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4470 4470
 }
4471 4471
 
4472 4472
 /**
@@ -4497,7 +4497,7 @@  discard block
 block discarded – undo
4497 4497
  *     Code HTML du lien
4498 4498
  */
4499 4499
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4500
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4500
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4501 4501
 }
4502 4502
 
4503 4503
 
@@ -4519,7 +4519,7 @@  discard block
 block discarded – undo
4519 4519
  * @return array Liste des éléments
4520 4520
  */
4521 4521
 function filtre_explode_dist($a, $b) {
4522
-	return explode($b, (string) $a);
4522
+    return explode($b, (string) $a);
4523 4523
 }
4524 4524
 
4525 4525
 /**
@@ -4540,7 +4540,7 @@  discard block
 block discarded – undo
4540 4540
  * @return string texte
4541 4541
  */
4542 4542
 function filtre_implode_dist($a, $b) {
4543
-	return is_array($a) ? implode($b, $a) : $a;
4543
+    return is_array($a) ? implode($b, $a) : $a;
4544 4544
 }
4545 4545
 
4546 4546
 /**
@@ -4549,22 +4549,22 @@  discard block
 block discarded – undo
4549 4549
  * @return string Code CSS
4550 4550
  */
4551 4551
 function bando_images_background() {
4552
-	include_spip('inc/bandeau');
4553
-	// recuperer tous les boutons et leurs images
4554
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4552
+    include_spip('inc/bandeau');
4553
+    // recuperer tous les boutons et leurs images
4554
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4555 4555
 
4556
-	$res = '';
4557
-	foreach ($boutons as $page => $detail) {
4558
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4559
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4560
-			if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4561
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4562
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4563
-			}
4564
-		}
4565
-	}
4556
+    $res = '';
4557
+    foreach ($boutons as $page => $detail) {
4558
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4559
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4560
+            if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4561
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4562
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4563
+            }
4564
+        }
4565
+    }
4566 4566
 
4567
-	return $res;
4567
+    return $res;
4568 4568
 }
4569 4569
 
4570 4570
 /**
@@ -4589,27 +4589,27 @@  discard block
 block discarded – undo
4589 4589
  */
4590 4590
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4591 4591
 
4592
-	// Classes : dispatcher `ajax` sur le formulaire
4593
-	$class_form = '';
4594
-	if (strpos($class, 'ajax') !== false) {
4595
-		$class_form = 'ajax';
4596
-		$class = str_replace('ajax', '', $class);
4597
-	}
4598
-	$class_btn = 'submit ' . trim($class);
4592
+    // Classes : dispatcher `ajax` sur le formulaire
4593
+    $class_form = '';
4594
+    if (strpos($class, 'ajax') !== false) {
4595
+        $class_form = 'ajax';
4596
+        $class = str_replace('ajax', '', $class);
4597
+    }
4598
+    $class_btn = 'submit ' . trim($class);
4599 4599
 
4600
-	if ($confirm) {
4601
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4602
-		if ($callback) {
4603
-			$callback = "$confirm?($callback):false";
4604
-		} else {
4605
-			$callback = $confirm;
4606
-		}
4607
-	}
4608
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4609
-	$title = $title ? " title='$title'" : '';
4600
+    if ($confirm) {
4601
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4602
+        if ($callback) {
4603
+            $callback = "$confirm?($callback):false";
4604
+        } else {
4605
+            $callback = $confirm;
4606
+        }
4607
+    }
4608
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4609
+    $title = $title ? " title='$title'" : '';
4610 4610
 
4611
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4612
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4611
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4612
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4613 4613
 }
4614 4614
 
4615 4615
 /**
@@ -4632,101 +4632,101 @@  discard block
 block discarded – undo
4632 4632
  * @return string
4633 4633
  */
4634 4634
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4635
-	static $trouver_table = null;
4636
-	static $objets;
4637
-
4638
-	// On verifie qu'on a tout ce qu'il faut
4639
-	$id_objet = intval($id_objet);
4640
-	if (!($id_objet and $type_objet and $info)) {
4641
-		return '';
4642
-	}
4643
-
4644
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4645
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4646
-		return '';
4647
-	}
4648
-
4649
-	// Si on demande l'url, on retourne direct la fonction
4650
-	if ($info == 'url') {
4651
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4652
-	}
4653
-
4654
-	// Sinon on va tout chercher dans la table et on garde en memoire
4655
-	$demande_titre = ($info === 'titre');
4656
-	$demande_introduction = ($info === 'introduction');
4657
-
4658
-	// 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
4659
-	if (
4660
-		!isset($objets[$type_objet][$id_objet])
4661
-		or
4662
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4663
-	) {
4664
-		if (!$trouver_table) {
4665
-			$trouver_table = charger_fonction('trouver_table', 'base');
4666
-		}
4667
-		$desc = $trouver_table(table_objet_sql($type_objet));
4668
-		if (!$desc) {
4669
-			return $objets[$type_objet] = false;
4670
-		}
4671
-
4672
-		// Si on demande le titre, on le gere en interne
4673
-		$champ_titre = '';
4674
-		if ($demande_titre) {
4675
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4676
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4677
-		}
4678
-		include_spip('base/abstract_sql');
4679
-		include_spip('base/connect_sql');
4680
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4681
-			'*' . $champ_titre,
4682
-			$desc['table_sql'],
4683
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4684
-		);
4685
-
4686
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4687
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4688
-	}
4689
-
4690
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4691
-	// ajouter la longueur au début des params supplémentaires
4692
-	if ($demande_introduction) {
4693
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4694
-		array_unshift($params, $introduction_longueur);
4695
-	}
4696
-
4697
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4698
-	if (
4699
-		$generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4700
-		// @deprecated 4.1 generer_TRUC_TYPE
4701
-		or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4702
-	) {
4703
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4704
-	}
4705
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4706
-	elseif (
4707
-		$generer = charger_fonction("generer_objet_{$info}", '', true)
4708
-		// @deprecated 4.1 generer_TRUC_entite
4709
-		or $generer = charger_fonction("generer_{$info}_entite", '', true)
4710
-	) {
4711
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4712
-	} // Sinon on prend directement le champ SQL tel quel
4713
-	else {
4714
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4715
-	}
4716
-
4717
-	// On va ensuite appliquer les traitements automatiques si besoin
4718
-	if (!$etoile) {
4719
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4720
-		// mais ce fonctionnement est a ameliorer !
4721
-		$info_generee = appliquer_traitement_champ(
4722
-			$info_generee,
4723
-			$info,
4724
-			table_objet($type_objet),
4725
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4726
-		);
4727
-	}
4728
-
4729
-	return $info_generee;
4635
+    static $trouver_table = null;
4636
+    static $objets;
4637
+
4638
+    // On verifie qu'on a tout ce qu'il faut
4639
+    $id_objet = intval($id_objet);
4640
+    if (!($id_objet and $type_objet and $info)) {
4641
+        return '';
4642
+    }
4643
+
4644
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4645
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4646
+        return '';
4647
+    }
4648
+
4649
+    // Si on demande l'url, on retourne direct la fonction
4650
+    if ($info == 'url') {
4651
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4652
+    }
4653
+
4654
+    // Sinon on va tout chercher dans la table et on garde en memoire
4655
+    $demande_titre = ($info === 'titre');
4656
+    $demande_introduction = ($info === 'introduction');
4657
+
4658
+    // 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
4659
+    if (
4660
+        !isset($objets[$type_objet][$id_objet])
4661
+        or
4662
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4663
+    ) {
4664
+        if (!$trouver_table) {
4665
+            $trouver_table = charger_fonction('trouver_table', 'base');
4666
+        }
4667
+        $desc = $trouver_table(table_objet_sql($type_objet));
4668
+        if (!$desc) {
4669
+            return $objets[$type_objet] = false;
4670
+        }
4671
+
4672
+        // Si on demande le titre, on le gere en interne
4673
+        $champ_titre = '';
4674
+        if ($demande_titre) {
4675
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4676
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4677
+        }
4678
+        include_spip('base/abstract_sql');
4679
+        include_spip('base/connect_sql');
4680
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4681
+            '*' . $champ_titre,
4682
+            $desc['table_sql'],
4683
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4684
+        );
4685
+
4686
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4687
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4688
+    }
4689
+
4690
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4691
+    // ajouter la longueur au début des params supplémentaires
4692
+    if ($demande_introduction) {
4693
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4694
+        array_unshift($params, $introduction_longueur);
4695
+    }
4696
+
4697
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4698
+    if (
4699
+        $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4700
+        // @deprecated 4.1 generer_TRUC_TYPE
4701
+        or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4702
+    ) {
4703
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4704
+    }
4705
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4706
+    elseif (
4707
+        $generer = charger_fonction("generer_objet_{$info}", '', true)
4708
+        // @deprecated 4.1 generer_TRUC_entite
4709
+        or $generer = charger_fonction("generer_{$info}_entite", '', true)
4710
+    ) {
4711
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4712
+    } // Sinon on prend directement le champ SQL tel quel
4713
+    else {
4714
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4715
+    }
4716
+
4717
+    // On va ensuite appliquer les traitements automatiques si besoin
4718
+    if (!$etoile) {
4719
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4720
+        // mais ce fonctionnement est a ameliorer !
4721
+        $info_generee = appliquer_traitement_champ(
4722
+            $info_generee,
4723
+            $info,
4724
+            table_objet($type_objet),
4725
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4726
+        );
4727
+    }
4728
+
4729
+    return $info_generee;
4730 4730
 }
4731 4731
 
4732 4732
 /**
@@ -4734,7 +4734,7 @@  discard block
 block discarded – undo
4734 4734
  * @see generer_objet_info
4735 4735
  */
4736 4736
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4737
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4737
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4738 4738
 }
4739 4739
 
4740 4740
 /**
@@ -4767,36 +4767,36 @@  discard block
 block discarded – undo
4767 4767
  */
4768 4768
 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 {
4769 4769
 
4770
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4771
-	$texte = $ligne_sql['texte'] ?? '';
4772
-	// En absence de descriptif, on se rabat sur chapo + texte
4773
-	if (isset($ligne_sql['chapo'])) {
4774
-		$chapo = $ligne_sql['chapo'];
4775
-		$texte = strlen($descriptif) ?
4776
-			'' :
4777
-			"$chapo \n\n $texte";
4778
-	}
4770
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4771
+    $texte = $ligne_sql['texte'] ?? '';
4772
+    // En absence de descriptif, on se rabat sur chapo + texte
4773
+    if (isset($ligne_sql['chapo'])) {
4774
+        $chapo = $ligne_sql['chapo'];
4775
+        $texte = strlen($descriptif) ?
4776
+            '' :
4777
+            "$chapo \n\n $texte";
4778
+    }
4779 4779
 
4780
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4781
-	if (!intval($longueur_ou_suite)) {
4782
-		$longueur = intval($introduction_longueur ?: 600);
4783
-	} else {
4784
-		$longueur = intval($longueur_ou_suite);
4785
-	}
4780
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4781
+    if (!intval($longueur_ou_suite)) {
4782
+        $longueur = intval($introduction_longueur ?: 600);
4783
+    } else {
4784
+        $longueur = intval($longueur_ou_suite);
4785
+    }
4786 4786
 
4787
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4788
-	// Ex : #INTRODUCTION{...}
4789
-	if (
4790
-		is_null($suite)
4791
-		and !intval($longueur_ou_suite)
4792
-	) {
4793
-		$suite = $longueur_ou_suite;
4794
-	}
4787
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4788
+    // Ex : #INTRODUCTION{...}
4789
+    if (
4790
+        is_null($suite)
4791
+        and !intval($longueur_ou_suite)
4792
+    ) {
4793
+        $suite = $longueur_ou_suite;
4794
+    }
4795 4795
 
4796
-	$f = chercher_filtre('introduction');
4797
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4796
+    $f = chercher_filtre('introduction');
4797
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4798 4798
 
4799
-	return $introduction;
4799
+    return $introduction;
4800 4800
 }
4801 4801
 
4802 4802
 /**
@@ -4804,7 +4804,7 @@  discard block
 block discarded – undo
4804 4804
  * @see generer_objet_introduction
4805 4805
  */
4806 4806
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4807
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4807
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4808 4808
 }
4809 4809
 
4810 4810
 /**
@@ -4818,49 +4818,49 @@  discard block
 block discarded – undo
4818 4818
  * @return string
4819 4819
  */
4820 4820
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4821
-	if (!$champ) {
4822
-		return $texte;
4823
-	}
4821
+    if (!$champ) {
4822
+        return $texte;
4823
+    }
4824 4824
 
4825
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4826
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4827
-	include_fichiers_fonctions();
4825
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4826
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4827
+    include_fichiers_fonctions();
4828 4828
 
4829
-	$champ = strtoupper($champ);
4830
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4831
-	if (!$traitements or !is_array($traitements)) {
4832
-		return $texte;
4833
-	}
4829
+    $champ = strtoupper($champ);
4830
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4831
+    if (!$traitements or !is_array($traitements)) {
4832
+        return $texte;
4833
+    }
4834 4834
 
4835
-	$traitement = '';
4836
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4837
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4838
-		$table_objet = table_objet($table_objet);
4839
-		if (isset($traitements[$table_objet])) {
4840
-			$traitement = $traitements[$table_objet];
4841
-		}
4842
-	}
4843
-	if (!$traitement and isset($traitements[0])) {
4844
-		$traitement = $traitements[0];
4845
-	}
4846
-	// (sinon prendre le premier de la liste par defaut ?)
4835
+    $traitement = '';
4836
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4837
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4838
+        $table_objet = table_objet($table_objet);
4839
+        if (isset($traitements[$table_objet])) {
4840
+            $traitement = $traitements[$table_objet];
4841
+        }
4842
+    }
4843
+    if (!$traitement and isset($traitements[0])) {
4844
+        $traitement = $traitements[0];
4845
+    }
4846
+    // (sinon prendre le premier de la liste par defaut ?)
4847 4847
 
4848
-	if (!$traitement) {
4849
-		return $texte;
4850
-	}
4848
+    if (!$traitement) {
4849
+        return $texte;
4850
+    }
4851 4851
 
4852
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4852
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4853 4853
 
4854
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4855
-	if (test_espace_prive()) {
4856
-		$env['espace_prive'] = 1;
4857
-	}
4854
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4855
+    if (test_espace_prive()) {
4856
+        $env['espace_prive'] = 1;
4857
+    }
4858 4858
 
4859
-	// Fournir $connect et $Pile[0] au traitement si besoin
4860
-	$Pile = [0 => $env];
4861
-	eval("\$texte = $traitement;");
4859
+    // Fournir $connect et $Pile[0] au traitement si besoin
4860
+    $Pile = [0 => $env];
4861
+    eval("\$texte = $traitement;");
4862 4862
 
4863
-	return $texte;
4863
+    return $texte;
4864 4864
 }
4865 4865
 
4866 4866
 
@@ -4874,21 +4874,21 @@  discard block
 block discarded – undo
4874 4874
  * @return string
4875 4875
  */
4876 4876
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4877
-	include_spip('inc/liens');
4878
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4879
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4880
-	// le raccourcis n'est plus valide
4881
-	$titre = typo($titre['titre'] ?? '');
4882
-	// on essaye avec generer_info_entite ?
4883
-	if (!strlen($titre) and !$connect) {
4884
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4885
-	}
4886
-	if (!strlen($titre)) {
4887
-		$titre = _T('info_sans_titre');
4888
-	}
4889
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4877
+    include_spip('inc/liens');
4878
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4879
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4880
+    // le raccourcis n'est plus valide
4881
+    $titre = typo($titre['titre'] ?? '');
4882
+    // on essaye avec generer_info_entite ?
4883
+    if (!strlen($titre) and !$connect) {
4884
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4885
+    }
4886
+    if (!strlen($titre)) {
4887
+        $titre = _T('info_sans_titre');
4888
+    }
4889
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4890 4890
 
4891
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4891
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4892 4892
 }
4893 4893
 
4894 4894
 /**
@@ -4896,7 +4896,7 @@  discard block
 block discarded – undo
4896 4896
  * @see generer_objet_lien
4897 4897
  */
4898 4898
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4899
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4899
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4900 4900
 }
4901 4901
 
4902 4902
 /**
@@ -4912,15 +4912,15 @@  discard block
 block discarded – undo
4912 4912
  * @return string
4913 4913
  */
4914 4914
 function wrap($texte, $wrap) {
4915
-	$balises = extraire_balises($wrap);
4916
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4917
-		$texte = $wrap . $texte;
4918
-		$regs = array_reverse($regs[1]);
4919
-		$wrap = '</' . implode('></', $regs) . '>';
4920
-		$texte = $texte . $wrap;
4921
-	}
4915
+    $balises = extraire_balises($wrap);
4916
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4917
+        $texte = $wrap . $texte;
4918
+        $regs = array_reverse($regs[1]);
4919
+        $wrap = '</' . implode('></', $regs) . '>';
4920
+        $texte = $texte . $wrap;
4921
+    }
4922 4922
 
4923
-	return $texte;
4923
+    return $texte;
4924 4924
 }
4925 4925
 
4926 4926
 
@@ -4940,44 +4940,44 @@  discard block
 block discarded – undo
4940 4940
  * @return array|mixed|string
4941 4941
  */
4942 4942
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4943
-	if (is_string($u)) {
4944
-		$u = typo($u);
4943
+    if (is_string($u)) {
4944
+        $u = typo($u);
4945 4945
 
4946
-		return $u;
4947
-	}
4946
+        return $u;
4947
+    }
4948 4948
 
4949
-	// caster $u en array si besoin
4950
-	if (is_object($u)) {
4951
-		$u = (array)$u;
4952
-	}
4949
+    // caster $u en array si besoin
4950
+    if (is_object($u)) {
4951
+        $u = (array)$u;
4952
+    }
4953 4953
 
4954
-	if (is_array($u)) {
4955
-		$out = '';
4956
-		// toutes les cles sont numeriques ?
4957
-		// et aucun enfant n'est un tableau
4958
-		// liste simple separee par des virgules
4959
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4960
-		$array_values = array_map('is_array', $u);
4961
-		$object_values = array_map('is_object', $u);
4962
-		if (
4963
-			array_sum($numeric_keys) == count($numeric_keys)
4964
-			and !array_sum($array_values)
4965
-			and !array_sum($object_values)
4966
-		) {
4967
-			return join(', ', array_map('filtre_print_dist', $u));
4968
-		}
4954
+    if (is_array($u)) {
4955
+        $out = '';
4956
+        // toutes les cles sont numeriques ?
4957
+        // et aucun enfant n'est un tableau
4958
+        // liste simple separee par des virgules
4959
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4960
+        $array_values = array_map('is_array', $u);
4961
+        $object_values = array_map('is_object', $u);
4962
+        if (
4963
+            array_sum($numeric_keys) == count($numeric_keys)
4964
+            and !array_sum($array_values)
4965
+            and !array_sum($object_values)
4966
+        ) {
4967
+            return join(', ', array_map('filtre_print_dist', $u));
4968
+        }
4969 4969
 
4970
-		// sinon on passe a la ligne et on indente
4971
-		$i_str = str_pad('', $indent, ' ');
4972
-		foreach ($u as $k => $v) {
4973
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4974
-		}
4970
+        // sinon on passe a la ligne et on indente
4971
+        $i_str = str_pad('', $indent, ' ');
4972
+        foreach ($u as $k => $v) {
4973
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4974
+        }
4975 4975
 
4976
-		return $out;
4977
-	}
4976
+        return $out;
4977
+    }
4978 4978
 
4979
-	// on sait pas quoi faire...
4980
-	return $u;
4979
+    // on sait pas quoi faire...
4980
+    return $u;
4981 4981
 }
4982 4982
 
4983 4983
 
@@ -4990,10 +4990,10 @@  discard block
 block discarded – undo
4990 4990
  * @return string|array
4991 4991
  */
4992 4992
 function objet_info($objet, $info) {
4993
-	$table = table_objet_sql($objet);
4994
-	$infos = lister_tables_objets_sql($table);
4993
+    $table = table_objet_sql($objet);
4994
+    $infos = lister_tables_objets_sql($table);
4995 4995
 
4996
-	return ($infos[$info] ?? '');
4996
+    return ($infos[$info] ?? '');
4997 4997
 }
4998 4998
 
4999 4999
 /**
@@ -5008,11 +5008,11 @@  discard block
 block discarded – undo
5008 5008
  *     texte traduit du comptage, tel que '3 articles'
5009 5009
  */
5010 5010
 function objet_afficher_nb($nb, $objet) {
5011
-	if (!$nb) {
5012
-		return _T(objet_info($objet, 'info_aucun_objet'));
5013
-	} else {
5014
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5015
-	}
5011
+    if (!$nb) {
5012
+        return _T(objet_info($objet, 'info_aucun_objet'));
5013
+    } else {
5014
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5015
+    }
5016 5016
 }
5017 5017
 
5018 5018
 /**
@@ -5024,11 +5024,11 @@  discard block
 block discarded – undo
5024 5024
  * @return string
5025 5025
  */
5026 5026
 function objet_icone($objet, $taille = 24, $class = '') {
5027
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5028
-	$icone = chemin_image($icone);
5029
-	$balise_img = charger_filtre('balise_img');
5027
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5028
+    $icone = chemin_image($icone);
5029
+    $balise_img = charger_filtre('balise_img');
5030 5030
 
5031
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5031
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5032 5032
 }
5033 5033
 
5034 5034
 /**
@@ -5049,12 +5049,12 @@  discard block
 block discarded – undo
5049 5049
  * @return string
5050 5050
  */
5051 5051
 function objet_T($objet, $chaine, $args = [], $options = []) {
5052
-	$chaine = explode(':', $chaine);
5053
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5054
-		return $t;
5055
-	}
5056
-	$chaine = implode(':', $chaine);
5057
-	return _T($chaine, $args, $options);
5052
+    $chaine = explode(':', $chaine);
5053
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5054
+        return $t;
5055
+    }
5056
+    $chaine = implode(':', $chaine);
5057
+    return _T($chaine, $args, $options);
5058 5058
 }
5059 5059
 
5060 5060
 /**
@@ -5068,18 +5068,18 @@  discard block
 block discarded – undo
5068 5068
  * @return string      Code HTML
5069 5069
  */
5070 5070
 function insert_head_css_conditionnel($flux) {
5071
-	if (
5072
-		strpos($flux, '<!-- insert_head_css -->') === false
5073
-		and $p = strpos($flux, '<!-- insert_head -->')
5074
-	) {
5075
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5076
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5077
-			$p = $p1;
5078
-		}
5079
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5080
-	}
5071
+    if (
5072
+        strpos($flux, '<!-- insert_head_css -->') === false
5073
+        and $p = strpos($flux, '<!-- insert_head -->')
5074
+    ) {
5075
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5076
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5077
+            $p = $p1;
5078
+        }
5079
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5080
+    }
5081 5081
 
5082
-	return $flux;
5082
+    return $flux;
5083 5083
 }
5084 5084
 
5085 5085
 /**
@@ -5102,75 +5102,75 @@  discard block
 block discarded – undo
5102 5102
  * @return string
5103 5103
  */
5104 5104
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5105
-	if (isset($contexte['format'])) {
5106
-		$extension = $contexte['format'];
5107
-		unset($contexte['format']);
5108
-	} else {
5109
-		$extension = 'html';
5110
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5111
-			$extension = $m[1];
5112
-		}
5113
-	}
5114
-	// recuperer le contenu produit par le squelette
5115
-	$options['raw'] = true;
5116
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5117
-
5118
-	// calculer le nom de la css
5119
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5120
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5121
-	$contexte_implicite = calculer_contexte_implicite();
5122
-
5123
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5124
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5125
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5126
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5127
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5128
-	}
5129
-	else {
5130
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5131
-		ksort($contexte);
5132
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5133
-	}
5134
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5135
-
5136
-	// mettre a jour le fichier si il n'existe pas
5137
-	// ou trop ancien
5138
-	// le dernier fichier produit est toujours suffixe par .last
5139
-	// et recopie sur le fichier cible uniquement si il change
5140
-	if (
5141
-		!file_exists($filename)
5142
-		or !file_exists($filename . '.last')
5143
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5144
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5145
-	) {
5146
-		$contenu = $cache['texte'];
5147
-		// passer les urls en absolu si c'est une css
5148
-		if ($extension == 'css') {
5149
-			$contenu = urls_absolues_css(
5150
-				$contenu,
5151
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5152
-			);
5153
-		}
5154
-
5155
-		$comment = '';
5156
-		// ne pas insérer de commentaire sur certains formats
5157
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5158
-			$comment = "/* #PRODUIRE{fond=$fond";
5159
-			foreach ($contexte as $k => $v) {
5160
-				if (is_array($v)) {
5161
-					$v = var_export($v, true);
5162
-				}
5163
-				$comment .= ",$k=$v";
5164
-			}
5165
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5166
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5167
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5168
-		}
5169
-		// et ecrire le fichier si il change
5170
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5171
-	}
5172
-
5173
-	return timestamp($filename);
5105
+    if (isset($contexte['format'])) {
5106
+        $extension = $contexte['format'];
5107
+        unset($contexte['format']);
5108
+    } else {
5109
+        $extension = 'html';
5110
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5111
+            $extension = $m[1];
5112
+        }
5113
+    }
5114
+    // recuperer le contenu produit par le squelette
5115
+    $options['raw'] = true;
5116
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5117
+
5118
+    // calculer le nom de la css
5119
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5120
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5121
+    $contexte_implicite = calculer_contexte_implicite();
5122
+
5123
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5124
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5125
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5126
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5127
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5128
+    }
5129
+    else {
5130
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5131
+        ksort($contexte);
5132
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5133
+    }
5134
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5135
+
5136
+    // mettre a jour le fichier si il n'existe pas
5137
+    // ou trop ancien
5138
+    // le dernier fichier produit est toujours suffixe par .last
5139
+    // et recopie sur le fichier cible uniquement si il change
5140
+    if (
5141
+        !file_exists($filename)
5142
+        or !file_exists($filename . '.last')
5143
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5144
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5145
+    ) {
5146
+        $contenu = $cache['texte'];
5147
+        // passer les urls en absolu si c'est une css
5148
+        if ($extension == 'css') {
5149
+            $contenu = urls_absolues_css(
5150
+                $contenu,
5151
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5152
+            );
5153
+        }
5154
+
5155
+        $comment = '';
5156
+        // ne pas insérer de commentaire sur certains formats
5157
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5158
+            $comment = "/* #PRODUIRE{fond=$fond";
5159
+            foreach ($contexte as $k => $v) {
5160
+                if (is_array($v)) {
5161
+                    $v = var_export($v, true);
5162
+                }
5163
+                $comment .= ",$k=$v";
5164
+            }
5165
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5166
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5167
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5168
+        }
5169
+        // et ecrire le fichier si il change
5170
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5171
+    }
5172
+
5173
+    return timestamp($filename);
5174 5174
 }
5175 5175
 
5176 5176
 /**
@@ -5183,15 +5183,15 @@  discard block
 block discarded – undo
5183 5183
  *    $fichier auquel on a ajouté le timestamp
5184 5184
  */
5185 5185
 function timestamp($fichier) {
5186
-	if (
5187
-		!$fichier
5188
-		or !file_exists($fichier)
5189
-		or !$m = filemtime($fichier)
5190
-	) {
5191
-		return $fichier;
5192
-	}
5186
+    if (
5187
+        !$fichier
5188
+        or !file_exists($fichier)
5189
+        or !$m = filemtime($fichier)
5190
+    ) {
5191
+        return $fichier;
5192
+    }
5193 5193
 
5194
-	return "$fichier?$m";
5194
+    return "$fichier?$m";
5195 5195
 }
5196 5196
 
5197 5197
 /**
@@ -5201,11 +5201,11 @@  discard block
 block discarded – undo
5201 5201
  * @return string
5202 5202
  */
5203 5203
 function supprimer_timestamp($url) {
5204
-	if (strpos($url, '?') === false) {
5205
-		return $url;
5206
-	}
5204
+    if (strpos($url, '?') === false) {
5205
+        return $url;
5206
+    }
5207 5207
 
5208
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5208
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5209 5209
 }
5210 5210
 
5211 5211
 /**
@@ -5220,15 +5220,15 @@  discard block
 block discarded – undo
5220 5220
  * @return string
5221 5221
  */
5222 5222
 function filtre_nettoyer_titre_email_dist($titre) {
5223
-	include_spip('inc/envoyer_mail');
5223
+    include_spip('inc/envoyer_mail');
5224 5224
 
5225
-	$titre = nettoyer_titre_email($titre);
5226
-	// on est dans un squelette : securiser le retour
5227
-	if (strpos($titre, '<') !== false) {
5228
-		$titre = interdire_scripts($titre);
5229
-	}
5225
+    $titre = nettoyer_titre_email($titre);
5226
+    // on est dans un squelette : securiser le retour
5227
+    if (strpos($titre, '<') !== false) {
5228
+        $titre = interdire_scripts($titre);
5229
+    }
5230 5230
 
5231
-	return $titre;
5231
+    return $titre;
5232 5232
 }
5233 5233
 
5234 5234
 /**
@@ -5250,27 +5250,27 @@  discard block
 block discarded – undo
5250 5250
  * @return string
5251 5251
  */
5252 5252
 function filtre_chercher_rubrique_dist(
5253
-	$titre,
5254
-	$id_objet,
5255
-	$id_parent,
5256
-	$objet,
5257
-	$id_secteur,
5258
-	$restreint,
5259
-	$actionable = false,
5260
-	$retour_sans_cadre = false
5253
+    $titre,
5254
+    $id_objet,
5255
+    $id_parent,
5256
+    $objet,
5257
+    $id_secteur,
5258
+    $restreint,
5259
+    $actionable = false,
5260
+    $retour_sans_cadre = false
5261 5261
 ) {
5262
-	include_spip('inc/filtres_ecrire');
5262
+    include_spip('inc/filtres_ecrire');
5263 5263
 
5264
-	return chercher_rubrique(
5265
-		$titre,
5266
-		$id_objet,
5267
-		$id_parent,
5268
-		$objet,
5269
-		$id_secteur,
5270
-		$restreint,
5271
-		$actionable,
5272
-		$retour_sans_cadre
5273
-	);
5264
+    return chercher_rubrique(
5265
+        $titre,
5266
+        $id_objet,
5267
+        $id_parent,
5268
+        $objet,
5269
+        $id_secteur,
5270
+        $restreint,
5271
+        $actionable,
5272
+        $retour_sans_cadre
5273
+    );
5274 5274
 }
5275 5275
 
5276 5276
 /**
@@ -5299,56 +5299,56 @@  discard block
 block discarded – undo
5299 5299
  *     Chaîne vide si l'accès est autorisé
5300 5300
  */
5301 5301
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5302
-	if ($ok) {
5303
-		return '';
5304
-	}
5305
-
5306
-	// Vider tous les tampons
5307
-	$level = @ob_get_level();
5308
-	while ($level--) {
5309
-		@ob_end_clean();
5310
-	}
5311
-
5312
-	include_spip('inc/headers');
5313
-
5314
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5315
-	if ($url) {
5316
-		redirige_par_entete($url, '', $statut);
5317
-	}
5318
-
5319
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5320
-	if (!is_numeric($statut) and is_null($message)) {
5321
-		$message = $statut;
5322
-		$statut = 0;
5323
-	}
5324
-	if (!$message) {
5325
-		$message = '';
5326
-	}
5327
-	$statut = intval($statut);
5328
-
5329
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5330
-	if (test_espace_prive()) {
5331
-		if (!$statut or !in_array($statut, [404, 403])) {
5332
-			$statut = 403;
5333
-		}
5334
-		http_response_code(403);
5335
-		$echec = charger_fonction('403', 'exec');
5336
-		$echec($message);
5337
-	} else {
5338
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5339
-		if (!$statut) {
5340
-			$statut = 404;
5341
-		}
5342
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5343
-		http_response_code($statut);
5344
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5345
-		if ($statut >= 400) {
5346
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5347
-		}
5348
-	}
5349
-
5350
-
5351
-	exit;
5302
+    if ($ok) {
5303
+        return '';
5304
+    }
5305
+
5306
+    // Vider tous les tampons
5307
+    $level = @ob_get_level();
5308
+    while ($level--) {
5309
+        @ob_end_clean();
5310
+    }
5311
+
5312
+    include_spip('inc/headers');
5313
+
5314
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5315
+    if ($url) {
5316
+        redirige_par_entete($url, '', $statut);
5317
+    }
5318
+
5319
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5320
+    if (!is_numeric($statut) and is_null($message)) {
5321
+        $message = $statut;
5322
+        $statut = 0;
5323
+    }
5324
+    if (!$message) {
5325
+        $message = '';
5326
+    }
5327
+    $statut = intval($statut);
5328
+
5329
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5330
+    if (test_espace_prive()) {
5331
+        if (!$statut or !in_array($statut, [404, 403])) {
5332
+            $statut = 403;
5333
+        }
5334
+        http_response_code(403);
5335
+        $echec = charger_fonction('403', 'exec');
5336
+        $echec($message);
5337
+    } else {
5338
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5339
+        if (!$statut) {
5340
+            $statut = 404;
5341
+        }
5342
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5343
+        http_response_code($statut);
5344
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5345
+        if ($statut >= 400) {
5346
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5347
+        }
5348
+    }
5349
+
5350
+
5351
+    exit;
5352 5352
 }
5353 5353
 
5354 5354
 /**
@@ -5359,11 +5359,11 @@  discard block
 block discarded – undo
5359 5359
  * @return string
5360 5360
  */
5361 5361
 function filtre_compacte_dist($source, $format = null) {
5362
-	if (function_exists('minifier')) {
5363
-		return minifier($source, $format);
5364
-	}
5362
+    if (function_exists('minifier')) {
5363
+        return minifier($source, $format);
5364
+    }
5365 5365
 
5366
-	return $source;
5366
+    return $source;
5367 5367
 }
5368 5368
 
5369 5369
 
@@ -5375,32 +5375,32 @@  discard block
 block discarded – undo
5375 5375
  * @return string
5376 5376
  */
5377 5377
 function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5378
-	$passe ??= '';
5379
-	$l = strlen($passe);
5380
-
5381
-	if ($l <= 8 or !$afficher_partiellement) {
5382
-		if (!$l) {
5383
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5384
-		}
5385
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5386
-	}
5387
-
5388
-	if (is_null($portion_pourcent)) {
5389
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5390
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5391
-		}
5392
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5393
-	}
5394
-	if ($portion_pourcent >= 100) {
5395
-		return $passe;
5396
-	}
5397
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5398
-	$e = max($e, 0);
5399
-	$mid = str_pad('', $l - 2 * $e, '*');
5400
-	if ($e > 0 and strlen($mid) > 8) {
5401
-		$mid = '***...***';
5402
-	}
5403
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5378
+    $passe ??= '';
5379
+    $l = strlen($passe);
5380
+
5381
+    if ($l <= 8 or !$afficher_partiellement) {
5382
+        if (!$l) {
5383
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5384
+        }
5385
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5386
+    }
5387
+
5388
+    if (is_null($portion_pourcent)) {
5389
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5390
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5391
+        }
5392
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5393
+    }
5394
+    if ($portion_pourcent >= 100) {
5395
+        return $passe;
5396
+    }
5397
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5398
+    $e = max($e, 0);
5399
+    $mid = str_pad('', $l - 2 * $e, '*');
5400
+    if ($e > 0 and strlen($mid) > 8) {
5401
+        $mid = '***...***';
5402
+    }
5403
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5404 5404
 }
5405 5405
 
5406 5406
 
@@ -5421,64 +5421,64 @@  discard block
 block discarded – undo
5421 5421
  */
5422 5422
 function identifiant_slug($texte, $type = '', $options = []) {
5423 5423
 
5424
-	$original = $texte;
5425
-	$separateur = ($options['separateur'] ?? '_');
5426
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5427
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5424
+    $original = $texte;
5425
+    $separateur = ($options['separateur'] ?? '_');
5426
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5427
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5428 5428
 
5429
-	if (!function_exists('translitteration')) {
5430
-		include_spip('inc/charsets');
5431
-	}
5429
+    if (!function_exists('translitteration')) {
5430
+        include_spip('inc/charsets');
5431
+    }
5432 5432
 
5433
-	// pas de balise html
5434
-	if (strpos($texte, '<') !== false) {
5435
-		$texte = strip_tags($texte);
5436
-	}
5437
-	if (strpos($texte, '&') !== false) {
5438
-		$texte = unicode2charset($texte);
5439
-	}
5440
-	// On enlève les espaces indésirables
5441
-	$texte = trim($texte);
5433
+    // pas de balise html
5434
+    if (strpos($texte, '<') !== false) {
5435
+        $texte = strip_tags($texte);
5436
+    }
5437
+    if (strpos($texte, '&') !== false) {
5438
+        $texte = unicode2charset($texte);
5439
+    }
5440
+    // On enlève les espaces indésirables
5441
+    $texte = trim($texte);
5442 5442
 
5443
-	// On enlève les accents et cie
5444
-	$texte = translitteration($texte);
5443
+    // On enlève les accents et cie
5444
+    $texte = translitteration($texte);
5445 5445
 
5446
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5447
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5446
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5447
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5448 5448
 
5449
-	// nettoyer les doubles occurences du separateur si besoin
5450
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5451
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5452
-	}
5449
+    // nettoyer les doubles occurences du separateur si besoin
5450
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5451
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5452
+    }
5453 5453
 
5454
-	// pas de separateur au debut ni a la fin
5455
-	$texte = trim($texte, $separateur);
5454
+    // pas de separateur au debut ni a la fin
5455
+    $texte = trim($texte, $separateur);
5456 5456
 
5457
-	// en minuscules
5458
-	$texte = strtolower($texte);
5457
+    // en minuscules
5458
+    $texte = strtolower($texte);
5459 5459
 
5460
-	switch ($type) {
5461
-		case 'class':
5462
-		case 'id':
5463
-		case 'anchor':
5464
-			if (preg_match(',^\d,', $texte)) {
5465
-				$texte = substr($type, 0, 1) . $texte;
5466
-			}
5467
-	}
5460
+    switch ($type) {
5461
+        case 'class':
5462
+        case 'id':
5463
+        case 'anchor':
5464
+            if (preg_match(',^\d,', $texte)) {
5465
+                $texte = substr($type, 0, 1) . $texte;
5466
+            }
5467
+    }
5468 5468
 
5469
-	if (strlen($texte) > $longueur_maxi) {
5470
-		$texte = substr($texte, 0, $longueur_maxi);
5471
-	}
5469
+    if (strlen($texte) > $longueur_maxi) {
5470
+        $texte = substr($texte, 0, $longueur_maxi);
5471
+    }
5472 5472
 
5473
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5474
-		if (preg_match(',^\d,', $texte)) {
5475
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5476
-		}
5477
-		$texte .= $separateur . md5($original);
5478
-		$texte = substr($texte, 0, $longueur_mini);
5479
-	}
5473
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5474
+        if (preg_match(',^\d,', $texte)) {
5475
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5476
+        }
5477
+        $texte .= $separateur . md5($original);
5478
+        $texte = substr($texte, 0, $longueur_mini);
5479
+    }
5480 5480
 
5481
-	return $texte;
5481
+    return $texte;
5482 5482
 }
5483 5483
 
5484 5484
 
@@ -5499,11 +5499,11 @@  discard block
 block discarded – undo
5499 5499
  * @exemple `<:info_maximum|label_nettoyer:>`
5500 5500
  */
5501 5501
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5502
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5503
-	if ($ucfirst) {
5504
-		$label = spip_ucfirst($label);
5505
-	}
5506
-	return $label;
5502
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5503
+    if ($ucfirst) {
5504
+        $label = spip_ucfirst($label);
5505
+    }
5506
+    return $label;
5507 5507
 }
5508 5508
 
5509 5509
 /**
@@ -5516,8 +5516,8 @@  discard block
 block discarded – undo
5516 5516
  * @exemple `<:info_maximum|label_ponctuer:>`
5517 5517
  */
5518 5518
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5519
-	$label = label_nettoyer($text, $ucfirst);
5520
-	return _T('label_ponctuer', ['label' => $label]);
5519
+    $label = label_nettoyer($text, $ucfirst);
5520
+    return _T('label_ponctuer', ['label' => $label]);
5521 5521
 }
5522 5522
 
5523 5523
 
@@ -5530,19 +5530,19 @@  discard block
 block discarded – undo
5530 5530
  * @return array
5531 5531
  */
5532 5532
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5533
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5534
-		return [];
5535
-	}
5533
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5534
+        return [];
5535
+    }
5536 5536
 
5537
-	// compatibilite signature inversee
5538
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5539
-		[$objet, $id_objet] = [$id_objet, $objet];
5540
-	}
5537
+    // compatibilite signature inversee
5538
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5539
+        [$objet, $id_objet] = [$id_objet, $objet];
5540
+    }
5541 5541
 
5542
-	if (!function_exists($fonction)) {
5543
-		include_spip('base/objets');
5544
-	}
5545
-	return $fonction($objet, $id_objet);
5542
+    if (!function_exists($fonction)) {
5543
+        include_spip('base/objets');
5544
+    }
5545
+    return $fonction($objet, $id_objet);
5546 5546
 }
5547 5547
 
5548 5548
 
@@ -5557,7 +5557,7 @@  discard block
 block discarded – undo
5557 5557
  * @return array
5558 5558
  */
5559 5559
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5560
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5560
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5561 5561
 }
5562 5562
 
5563 5563
 /**
@@ -5571,7 +5571,7 @@  discard block
 block discarded – undo
5571 5571
  * @return array
5572 5572
  */
5573 5573
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5574
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5574
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5575 5575
 }
5576 5576
 
5577 5577
 /**
@@ -5585,7 +5585,7 @@  discard block
 block discarded – undo
5585 5585
  * @return array
5586 5586
  */
5587 5587
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5588
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5588
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5589 5589
 }
5590 5590
 
5591 5591
 /**
@@ -5599,5 +5599,5 @@  discard block
 block discarded – undo
5599 5599
  * @return array
5600 5600
  */
5601 5601
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5602
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5602
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5603 5603
 }
Please login to merge, or discard this patch.