Completed
Push — master ( 6daadc...584fd0 )
by cam
01:03
created
ecrire/inc/filtres.php 1 patch
Indentation   +2477 added lines, -2477 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,19 +224,19 @@  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) {
229
-		$desc = decrire_version_svn($dir);
230
-	}
231
-	if ($desc === null or $raw) {
232
-		return $desc;
233
-	}
234
-	// affichage "GIT [master: abcdef]"
235
-	$commit = $desc['commit_short'] ?? $desc['commit'];
236
-	if ($desc['branch']) {
237
-		$commit = $desc['branch'] . ': ' . $commit;
238
-	}
239
-	return "{$desc['vcs']} [$commit]";
227
+    $desc = decrire_version_git($dir);
228
+    if ($desc === null) {
229
+        $desc = decrire_version_svn($dir);
230
+    }
231
+    if ($desc === null or $raw) {
232
+        return $desc;
233
+    }
234
+    // affichage "GIT [master: abcdef]"
235
+    $commit = $desc['commit_short'] ?? $desc['commit'];
236
+    if ($desc['branch']) {
237
+        $commit = $desc['branch'] . ': ' . $commit;
238
+    }
239
+    return "{$desc['vcs']} [$commit]";
240 240
 }
241 241
 
242 242
 /**
@@ -248,24 +248,24 @@  discard block
 block discarded – undo
248 248
  *      array ['branch' => xx, 'commit' => yy] sinon.
249 249
  **/
250 250
 function decrire_version_git($dir) {
251
-	if (!$dir) {
252
-		$dir = '.';
253
-	}
251
+    if (!$dir) {
252
+        $dir = '.';
253
+    }
254 254
 
255
-	// version installee par GIT
256
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
257
-		$currentHead = trim(substr($c, 4));
258
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
259
-			return [
260
-				'vcs' => 'GIT',
261
-				'branch' => basename($currentHead),
262
-				'commit' => trim($hash),
263
-				'commit_short' => substr(trim($hash), 0, 8),
264
-			];
265
-		}
266
-	}
255
+    // version installee par GIT
256
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
257
+        $currentHead = trim(substr($c, 4));
258
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
259
+            return [
260
+                'vcs' => 'GIT',
261
+                'branch' => basename($currentHead),
262
+                'commit' => trim($hash),
263
+                'commit_short' => substr(trim($hash), 0, 8),
264
+            ];
265
+        }
266
+    }
267 267
 
268
-	return null;
268
+    return null;
269 269
 }
270 270
 
271 271
 
@@ -278,25 +278,25 @@  discard block
 block discarded – undo
278 278
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
279 279
  **/
280 280
 function decrire_version_svn($dir) {
281
-	if (!$dir) {
282
-		$dir = '.';
283
-	}
284
-	// version installee par SVN
285
-	if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
286
-		$db = new SQLite3($dir . '/.svn/wc.db');
287
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
288
-		if ($result) {
289
-			$row = $result->fetchArray();
290
-			if ($row['changed_revision'] != '') {
291
-				return [
292
-					'vcs' => 'SVN',
293
-					'branch' => '',
294
-					'commit' => $row['changed_revision'],
295
-				];
296
-			}
297
-		}
298
-	}
299
-	return null;
281
+    if (!$dir) {
282
+        $dir = '.';
283
+    }
284
+    // version installee par SVN
285
+    if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
286
+        $db = new SQLite3($dir . '/.svn/wc.db');
287
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
288
+        if ($result) {
289
+            $row = $result->fetchArray();
290
+            if ($row['changed_revision'] != '') {
291
+                return [
292
+                    'vcs' => 'SVN',
293
+                    'branch' => '',
294
+                    'commit' => $row['changed_revision'],
295
+                ];
296
+            }
297
+        }
298
+    }
299
+    return null;
300 300
 }
301 301
 
302 302
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -343,18 +343,18 @@  discard block
 block discarded – undo
343 343
  *     Code HTML retourné par le filtre
344 344
  **/
345 345
 function filtrer($filtre) {
346
-	$tous = func_get_args();
347
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
348
-		return image_filtrer($tous);
349
-	} elseif ($f = chercher_filtre($filtre)) {
350
-		array_shift($tous);
351
-		return $f(...$tous);
352
-	} else {
353
-		// le filtre n'existe pas, on provoque une erreur
354
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
355
-		erreur_squelette($msg);
356
-		return '';
357
-	}
346
+    $tous = func_get_args();
347
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
348
+        return image_filtrer($tous);
349
+    } elseif ($f = chercher_filtre($filtre)) {
350
+        array_shift($tous);
351
+        return $f(...$tous);
352
+    } else {
353
+        // le filtre n'existe pas, on provoque une erreur
354
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
355
+        erreur_squelette($msg);
356
+        return '';
357
+    }
358 358
 }
359 359
 
360 360
 /**
@@ -371,11 +371,11 @@  discard block
 block discarded – undo
371 371
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
372 372
  */
373 373
 function trouver_filtre_matrice($filtre) {
374
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
375
-		find_in_path($f, '', true);
376
-		$GLOBALS['spip_matrice'][$filtre] = true;
377
-	}
378
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
374
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
375
+        find_in_path($f, '', true);
376
+        $GLOBALS['spip_matrice'][$filtre] = true;
377
+    }
378
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
379 379
 }
380 380
 
381 381
 
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
  * @return mixed
404 404
  */
405 405
 function filtre_set(&$Pile, $val, $key, $continue = null) {
406
-	$Pile['vars'][$key] = $val;
407
-	return $continue ? $val : '';
406
+    $Pile['vars'][$key] = $val;
407
+    return $continue ? $val : '';
408 408
 }
409 409
 
410 410
 /**
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
431 431
  */
432 432
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
433
-	$Pile[0][$key] = $val;
434
-	return $continue ? $val : '';
433
+    $Pile[0][$key] = $val;
434
+    return $continue ? $val : '';
435 435
 }
436 436
 
437 437
 /**
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
  * @return string
441 441
  */
442 442
 function filtre_sanitize_env(&$Pile, $keys) {
443
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
444
-	return '';
443
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
444
+    return '';
445 445
 }
446 446
 
447 447
 
@@ -464,18 +464,18 @@  discard block
 block discarded – undo
464 464
  * @return mixed Retourne la valeur (sans la modifier).
465 465
  */
466 466
 function filtre_debug($val, $key = null) {
467
-	$debug = (
468
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
469
-		) . var_export($val, true);
467
+    $debug = (
468
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
469
+        ) . var_export($val, true);
470 470
 
471
-	include_spip('inc/autoriser');
472
-	if (autoriser('webmestre')) {
473
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
474
-	}
471
+    include_spip('inc/autoriser');
472
+    if (autoriser('webmestre')) {
473
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
474
+    }
475 475
 
476
-	spip_log($debug, 'debug');
476
+    spip_log($debug, 'debug');
477 477
 
478
-	return $val;
478
+    return $val;
479 479
 }
480 480
 
481 481
 
@@ -505,84 +505,84 @@  discard block
 block discarded – undo
505 505
  *     Texte qui a reçu les filtres
506 506
  **/
507 507
 function image_filtrer($args) {
508
-	$filtre = array_shift($args); # enlever $filtre
509
-	$texte = array_shift($args);
510
-	if ($texte === null || !strlen($texte)) {
511
-		return '';
512
-	}
513
-	find_in_path('filtres_images_mini.php', 'inc/', true);
514
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
515
-	// Cas du nom de fichier local
516
-	$is_file = trim($texte);
517
-	if (
518
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
519
-		  or strpbrk($is_file, "<>\n\r\t") !== false
520
-		  or strpos($is_file, '/') === 0
521
-	) {
522
-		$is_file = false;
523
-	}
524
-	if ($is_file) {
525
-		$is_local_file = function ($path) {
526
-			if (strpos($path, '?') !== false) {
527
-				$path = supprimer_timestamp($path);
528
-				// remove ?24px added by find_in_theme on .svg files
529
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
530
-			}
531
-			return file_exists($path);
532
-		};
533
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
534
-			$res = $filtre("<img src='$is_file' />", ...$args);
535
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
536
-			return $res;
537
-		}
538
-	}
539
-
540
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
541
-	if (
542
-		preg_match_all(
543
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
544
-			$texte,
545
-			$tags,
546
-			PREG_SET_ORDER
547
-		)
548
-	) {
549
-		foreach ($tags as $tag) {
550
-			$class = extraire_attribut($tag[3], 'class');
551
-			if (
552
-				!$class or
553
-				(strpos($class, 'filtre_inactif') === false
554
-					// compat historique a virer en 3.2
555
-					and strpos($class, 'no_image_filtrer') === false)
556
-			) {
557
-				if ($reduit = $filtre($tag[3], ...$args)) {
558
-					// En cas de span spip_documents, modifier le style=...width:
559
-					if ($tag[1]) {
560
-						$w = extraire_attribut($reduit, 'width');
561
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
562
-							$w = $regs[1];
563
-						}
564
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
565
-							$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
566
-							$replace = inserer_attribut($tag[1], 'style', $style);
567
-							$texte = str_replace($tag[1], $replace, $texte);
568
-						}
569
-					}
570
-					// traiter aussi un eventuel mouseover
571
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
572
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
573
-							$srcover = $match[1];
574
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
575
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
576
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
577
-						}
578
-					}
579
-					$texte = str_replace($tag[3], $reduit, $texte);
580
-				}
581
-			}
582
-		}
583
-	}
584
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
585
-	return $texte;
508
+    $filtre = array_shift($args); # enlever $filtre
509
+    $texte = array_shift($args);
510
+    if ($texte === null || !strlen($texte)) {
511
+        return '';
512
+    }
513
+    find_in_path('filtres_images_mini.php', 'inc/', true);
514
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
515
+    // Cas du nom de fichier local
516
+    $is_file = trim($texte);
517
+    if (
518
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
519
+          or strpbrk($is_file, "<>\n\r\t") !== false
520
+          or strpos($is_file, '/') === 0
521
+    ) {
522
+        $is_file = false;
523
+    }
524
+    if ($is_file) {
525
+        $is_local_file = function ($path) {
526
+            if (strpos($path, '?') !== false) {
527
+                $path = supprimer_timestamp($path);
528
+                // remove ?24px added by find_in_theme on .svg files
529
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
530
+            }
531
+            return file_exists($path);
532
+        };
533
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
534
+            $res = $filtre("<img src='$is_file' />", ...$args);
535
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
536
+            return $res;
537
+        }
538
+    }
539
+
540
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
541
+    if (
542
+        preg_match_all(
543
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
544
+            $texte,
545
+            $tags,
546
+            PREG_SET_ORDER
547
+        )
548
+    ) {
549
+        foreach ($tags as $tag) {
550
+            $class = extraire_attribut($tag[3], 'class');
551
+            if (
552
+                !$class or
553
+                (strpos($class, 'filtre_inactif') === false
554
+                    // compat historique a virer en 3.2
555
+                    and strpos($class, 'no_image_filtrer') === false)
556
+            ) {
557
+                if ($reduit = $filtre($tag[3], ...$args)) {
558
+                    // En cas de span spip_documents, modifier le style=...width:
559
+                    if ($tag[1]) {
560
+                        $w = extraire_attribut($reduit, 'width');
561
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
562
+                            $w = $regs[1];
563
+                        }
564
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
565
+                            $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
566
+                            $replace = inserer_attribut($tag[1], 'style', $style);
567
+                            $texte = str_replace($tag[1], $replace, $texte);
568
+                        }
569
+                    }
570
+                    // traiter aussi un eventuel mouseover
571
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
572
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
573
+                            $srcover = $match[1];
574
+                            $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
575
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
576
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
577
+                        }
578
+                    }
579
+                    $texte = str_replace($tag[3], $reduit, $texte);
580
+                }
581
+            }
582
+        }
583
+    }
584
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
585
+    return $texte;
586 586
 }
587 587
 
588 588
 /**
@@ -599,91 +599,91 @@  discard block
 block discarded – undo
599 599
  **/
600 600
 function infos_image($img, $force_refresh = false) {
601 601
 
602
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
603
-	$srcWidth = 0;
604
-	$srcHeight = 0;
605
-	$srcSize = null;
606
-
607
-	$src = extraire_attribut($img, 'src');
608
-
609
-	if (!$src) {
610
-		$src = $img;
611
-	} else {
612
-		$srcWidth = extraire_attribut($img, 'width');
613
-		$srcHeight = extraire_attribut($img, 'height');
614
-	}
615
-
616
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
617
-	// la copie locale a toutes les chances d'etre la ou de resservir
618
-	if (tester_url_absolue($src)) {
619
-		include_spip('inc/distant');
620
-		$fichier = copie_locale($src);
621
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
622
-	}
623
-	if (($p = strpos($src, '?')) !== false) {
624
-		$src = substr($src, 0, $p);
625
-	}
626
-
627
-	$imagesize = false;
628
-	if (isset($largeur_img[$src]) and !$force_refresh) {
629
-		$srcWidth = $largeur_img[$src];
630
-	}
631
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
632
-		$srcHeight = $hauteur_img[$src];
633
-	}
634
-	if (isset($poids_img[$src]) and !$force_refresh) {
635
-		$srcSize = $poids_img[$src];
636
-	}
637
-	if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
638
-		if (
639
-			file_exists($src)
640
-			and $imagesize = spip_getimagesize($src)
641
-		) {
642
-			if (!$srcWidth) {
643
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
644
-			}
645
-			if (!$srcHeight) {
646
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
647
-			}
648
-			if (!$srcSize) {
649
-				$poids_img[$src] = filesize($src);
650
-			}
651
-		}
652
-		elseif (strpos($src, '<svg') !== false) {
653
-			include_spip('inc/svg');
654
-			if ($attrs = svg_lire_attributs($src)) {
655
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
656
-				if (!$srcWidth) {
657
-					$largeur_img[$src] = $srcWidth = $width;
658
-				}
659
-				if (!$srcHeight) {
660
-					$hauteur_img[$src] = $srcHeight = $height;
661
-				}
662
-				if (!$srcSize) {
663
-					$poids_img[$src] = $srcSize = strlen($src);
664
-				}
665
-			}
666
-		}
667
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
668
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
669
-		elseif (
670
-			@file_exists($f = "$src.src")
671
-			and lire_fichier($f, $valeurs)
672
-			and $valeurs = unserialize($valeurs)
673
-		) {
674
-			if (!$srcWidth) {
675
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
676
-			}
677
-			if (!$srcHeight) {
678
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
679
-			}
680
-			if (!$srcSize) {
681
-				$poids_img[$src] = $srcSize = 0;
682
-			}
683
-		}
684
-	}
685
-
686
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
602
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
603
+    $srcWidth = 0;
604
+    $srcHeight = 0;
605
+    $srcSize = null;
606
+
607
+    $src = extraire_attribut($img, 'src');
608
+
609
+    if (!$src) {
610
+        $src = $img;
611
+    } else {
612
+        $srcWidth = extraire_attribut($img, 'width');
613
+        $srcHeight = extraire_attribut($img, 'height');
614
+    }
615
+
616
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
617
+    // la copie locale a toutes les chances d'etre la ou de resservir
618
+    if (tester_url_absolue($src)) {
619
+        include_spip('inc/distant');
620
+        $fichier = copie_locale($src);
621
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
622
+    }
623
+    if (($p = strpos($src, '?')) !== false) {
624
+        $src = substr($src, 0, $p);
625
+    }
626
+
627
+    $imagesize = false;
628
+    if (isset($largeur_img[$src]) and !$force_refresh) {
629
+        $srcWidth = $largeur_img[$src];
630
+    }
631
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
632
+        $srcHeight = $hauteur_img[$src];
633
+    }
634
+    if (isset($poids_img[$src]) and !$force_refresh) {
635
+        $srcSize = $poids_img[$src];
636
+    }
637
+    if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
638
+        if (
639
+            file_exists($src)
640
+            and $imagesize = spip_getimagesize($src)
641
+        ) {
642
+            if (!$srcWidth) {
643
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
644
+            }
645
+            if (!$srcHeight) {
646
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
647
+            }
648
+            if (!$srcSize) {
649
+                $poids_img[$src] = filesize($src);
650
+            }
651
+        }
652
+        elseif (strpos($src, '<svg') !== false) {
653
+            include_spip('inc/svg');
654
+            if ($attrs = svg_lire_attributs($src)) {
655
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
656
+                if (!$srcWidth) {
657
+                    $largeur_img[$src] = $srcWidth = $width;
658
+                }
659
+                if (!$srcHeight) {
660
+                    $hauteur_img[$src] = $srcHeight = $height;
661
+                }
662
+                if (!$srcSize) {
663
+                    $poids_img[$src] = $srcSize = strlen($src);
664
+                }
665
+            }
666
+        }
667
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
668
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
669
+        elseif (
670
+            @file_exists($f = "$src.src")
671
+            and lire_fichier($f, $valeurs)
672
+            and $valeurs = unserialize($valeurs)
673
+        ) {
674
+            if (!$srcWidth) {
675
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
676
+            }
677
+            if (!$srcHeight) {
678
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
679
+            }
680
+            if (!$srcSize) {
681
+                $poids_img[$src] = $srcSize = 0;
682
+            }
683
+        }
684
+    }
685
+
686
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
687 687
 }
688 688
 
689 689
 /**
@@ -699,13 +699,13 @@  discard block
 block discarded – undo
699 699
  *     poids
700 700
  **/
701 701
 function poids_image($img, $force_refresh = false) {
702
-	$infos = infos_image($img, $force_refresh);
703
-	return $infos['poids'];
702
+    $infos = infos_image($img, $force_refresh);
703
+    return $infos['poids'];
704 704
 }
705 705
 
706 706
 function taille_image($img, $force_refresh = false) {
707
-	$infos = infos_image($img, $force_refresh);
708
-	return [$infos['hauteur'], $infos['largeur']];
707
+    $infos = infos_image($img, $force_refresh);
708
+    return [$infos['hauteur'], $infos['largeur']];
709 709
 }
710 710
 
711 711
 /**
@@ -722,12 +722,12 @@  discard block
 block discarded – undo
722 722
  *     Largeur en pixels, NULL ou 0 si aucune image.
723 723
  **/
724 724
 function largeur($img) {
725
-	if (!$img) {
726
-		return;
727
-	}
728
-	[$h, $l] = taille_image($img);
725
+    if (!$img) {
726
+        return;
727
+    }
728
+    [$h, $l] = taille_image($img);
729 729
 
730
-	return $l;
730
+    return $l;
731 731
 }
732 732
 
733 733
 /**
@@ -744,12 +744,12 @@  discard block
 block discarded – undo
744 744
  *     Hauteur en pixels, NULL ou 0 si aucune image.
745 745
  **/
746 746
 function hauteur($img) {
747
-	if (!$img) {
748
-		return;
749
-	}
750
-	[$h, $l] = taille_image($img);
747
+    if (!$img) {
748
+        return;
749
+    }
750
+    [$h, $l] = taille_image($img);
751 751
 
752
-	return $h;
752
+    return $h;
753 753
 }
754 754
 
755 755
 
@@ -769,11 +769,11 @@  discard block
 block discarded – undo
769 769
  * @return string
770 770
  **/
771 771
 function corriger_entites_html($texte) {
772
-	if (strpos($texte, '&amp;') === false) {
773
-		return $texte;
774
-	}
772
+    if (strpos($texte, '&amp;') === false) {
773
+        return $texte;
774
+    }
775 775
 
776
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
776
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
777 777
 }
778 778
 
779 779
 /**
@@ -788,11 +788,11 @@  discard block
 block discarded – undo
788 788
  * @return string
789 789
  **/
790 790
 function corriger_toutes_entites_html($texte) {
791
-	if (strpos($texte, '&amp;') === false) {
792
-		return $texte;
793
-	}
791
+    if (strpos($texte, '&amp;') === false) {
792
+        return $texte;
793
+    }
794 794
 
795
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
795
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
796 796
 }
797 797
 
798 798
 /**
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
  * @return string
803 803
  **/
804 804
 function proteger_amp($texte) {
805
-	return str_replace('&', '&amp;', $texte);
805
+    return str_replace('&', '&amp;', $texte);
806 806
 }
807 807
 
808 808
 
@@ -833,21 +833,21 @@  discard block
 block discarded – undo
833 833
  * @return mixed|string
834 834
  */
835 835
 function entites_html($texte, $tout = false, $quote = true) {
836
-	if (
837
-		!is_string($texte) or !$texte
838
-		or strpbrk($texte, "&\"'<>") == false
839
-	) {
840
-		return $texte;
841
-	}
842
-	include_spip('inc/texte');
843
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
844
-	$flags |= ENT_HTML401;
845
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
846
-	if ($tout) {
847
-		return corriger_toutes_entites_html($texte);
848
-	} else {
849
-		return corriger_entites_html($texte);
850
-	}
836
+    if (
837
+        !is_string($texte) or !$texte
838
+        or strpbrk($texte, "&\"'<>") == false
839
+    ) {
840
+        return $texte;
841
+    }
842
+    include_spip('inc/texte');
843
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
844
+    $flags |= ENT_HTML401;
845
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
846
+    if ($tout) {
847
+        return corriger_toutes_entites_html($texte);
848
+    } else {
849
+        return corriger_entites_html($texte);
850
+    }
851 851
 }
852 852
 
853 853
 /**
@@ -866,38 +866,38 @@  discard block
 block discarded – undo
866 866
  *     Texte converti
867 867
  **/
868 868
 function filtrer_entites(?string $texte): string {
869
-	$texte ??= '';
870
-	if (strpos($texte, '&') === false) {
871
-		return $texte;
872
-	}
873
-	// filtrer
874
-	$texte = html2unicode($texte);
875
-	// remettre le tout dans le charset cible
876
-	$texte = unicode2charset($texte);
877
-	// cas particulier des " et ' qu'il faut filtrer aussi
878
-	// (on le faisait deja avec un &quot;)
879
-	if (strpos($texte, '&#') !== false) {
880
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
881
-	}
869
+    $texte ??= '';
870
+    if (strpos($texte, '&') === false) {
871
+        return $texte;
872
+    }
873
+    // filtrer
874
+    $texte = html2unicode($texte);
875
+    // remettre le tout dans le charset cible
876
+    $texte = unicode2charset($texte);
877
+    // cas particulier des " et ' qu'il faut filtrer aussi
878
+    // (on le faisait deja avec un &quot;)
879
+    if (strpos($texte, '&#') !== false) {
880
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
881
+    }
882 882
 
883
-	return $texte;
883
+    return $texte;
884 884
 }
885 885
 
886 886
 
887 887
 if (!function_exists('filtre_filtrer_entites_dist')) {
888
-	/**
889
-	 * Version sécurisée de filtrer_entites
890
-	 *
891
-	 * @uses interdire_scripts()
892
-	 * @uses filtrer_entites()
893
-	 *
894
-	 * @param string $t
895
-	 * @return string
896
-	 */
897
-	function filtre_filtrer_entites_dist($t) {
898
-		include_spip('inc/texte');
899
-		return interdire_scripts(filtrer_entites($t));
900
-	}
888
+    /**
889
+     * Version sécurisée de filtrer_entites
890
+     *
891
+     * @uses interdire_scripts()
892
+     * @uses filtrer_entites()
893
+     *
894
+     * @param string $t
895
+     * @return string
896
+     */
897
+    function filtre_filtrer_entites_dist($t) {
898
+        include_spip('inc/texte');
899
+        return interdire_scripts(filtrer_entites($t));
900
+    }
901 901
 }
902 902
 
903 903
 
@@ -912,18 +912,18 @@  discard block
 block discarded – undo
912 912
  * @return string|array
913 913
  **/
914 914
 function supprimer_caracteres_illegaux($texte) {
915
-	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";
916
-	static $to = null;
915
+    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";
916
+    static $to = null;
917 917
 
918
-	if (is_array($texte)) {
919
-		return array_map('supprimer_caracteres_illegaux', $texte);
920
-	}
918
+    if (is_array($texte)) {
919
+        return array_map('supprimer_caracteres_illegaux', $texte);
920
+    }
921 921
 
922
-	if (!$to) {
923
-		$to = str_repeat('-', strlen($from));
924
-	}
922
+    if (!$to) {
923
+        $to = str_repeat('-', strlen($from));
924
+    }
925 925
 
926
-	return strtr($texte, $from, $to);
926
+    return strtr($texte, $from, $to);
927 927
 }
928 928
 
929 929
 /**
@@ -935,10 +935,10 @@  discard block
 block discarded – undo
935 935
  * @return string|array
936 936
  **/
937 937
 function corriger_caracteres($texte) {
938
-	$texte = corriger_caracteres_windows($texte);
939
-	$texte = supprimer_caracteres_illegaux($texte);
938
+    $texte = corriger_caracteres_windows($texte);
939
+    $texte = supprimer_caracteres_illegaux($texte);
940 940
 
941
-	return $texte;
941
+    return $texte;
942 942
 }
943 943
 
944 944
 /**
@@ -955,44 +955,44 @@  discard block
 block discarded – undo
955 955
  *     Texte encodé pour XML
956 956
  */
957 957
 function texte_backend(string $texte): string {
958
-	if ($texte === '') {
959
-		return '';
960
-	}
958
+    if ($texte === '') {
959
+        return '';
960
+    }
961 961
 
962
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
962
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
963 963
 
964
-	// si on a des liens ou des images, les passer en absolu
965
-	$texte = liens_absolus($texte);
964
+    // si on a des liens ou des images, les passer en absolu
965
+    $texte = liens_absolus($texte);
966 966
 
967
-	// echapper les tags &gt; &lt;
968
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
967
+    // echapper les tags &gt; &lt;
968
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
969 969
 
970
-	// importer les &eacute;
971
-	$texte = filtrer_entites($texte);
970
+    // importer les &eacute;
971
+    $texte = filtrer_entites($texte);
972 972
 
973
-	// " -> &quot; et tout ce genre de choses
974
-	$u = $GLOBALS['meta']['pcre_u'];
975
-	$texte = str_replace('&nbsp;', ' ', $texte);
976
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
977
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
978
-	$texte = entites_html($texte, false, false);
979
-	// mais bien echapper les double quotes !
980
-	$texte = str_replace('"', '&#034;', $texte);
973
+    // " -> &quot; et tout ce genre de choses
974
+    $u = $GLOBALS['meta']['pcre_u'];
975
+    $texte = str_replace('&nbsp;', ' ', $texte);
976
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
977
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
978
+    $texte = entites_html($texte, false, false);
979
+    // mais bien echapper les double quotes !
980
+    $texte = str_replace('"', '&#034;', $texte);
981 981
 
982
-	// verifier le charset
983
-	$texte = charset2unicode($texte);
982
+    // verifier le charset
983
+    $texte = charset2unicode($texte);
984 984
 
985
-	// Caracteres problematiques en iso-latin 1
986
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
987
-		$texte = str_replace(chr(156), '&#156;', $texte);
988
-		$texte = str_replace(chr(140), '&#140;', $texte);
989
-		$texte = str_replace(chr(159), '&#159;', $texte);
990
-	}
985
+    // Caracteres problematiques en iso-latin 1
986
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
987
+        $texte = str_replace(chr(156), '&#156;', $texte);
988
+        $texte = str_replace(chr(140), '&#140;', $texte);
989
+        $texte = str_replace(chr(159), '&#159;', $texte);
990
+    }
991 991
 
992
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
993
-	// et le caractere apostrophe alourdit les squelettes avec PHP
994
-	// ==> on les remplace par l'entite HTML
995
-	return str_replace($apostrophe, "'", $texte);
992
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
993
+    // et le caractere apostrophe alourdit les squelettes avec PHP
994
+    // ==> on les remplace par l'entite HTML
995
+    return str_replace($apostrophe, "'", $texte);
996 996
 }
997 997
 
998 998
 /**
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
  *     Texte encodé et quote pour XML
1010 1010
  */
1011 1011
 function texte_backendq(string $texte): string {
1012
-	return addslashes(texte_backend($texte));
1012
+    return addslashes(texte_backend($texte));
1013 1013
 }
1014 1014
 
1015 1015
 
@@ -1032,11 +1032,11 @@  discard block
 block discarded – undo
1032 1032
  *     Numéro de titre, sinon chaîne vide
1033 1033
  **/
1034 1034
 function supprimer_numero($texte) {
1035
-	return preg_replace(
1036
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1037
-		'',
1038
-		$texte
1039
-	);
1035
+    return preg_replace(
1036
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1037
+        '',
1038
+        $texte
1039
+    );
1040 1040
 }
1041 1041
 
1042 1042
 /**
@@ -1059,17 +1059,17 @@  discard block
 block discarded – undo
1059 1059
  *     Numéro de titre, sinon chaîne vide
1060 1060
  **/
1061 1061
 function recuperer_numero($texte) {
1062
-	if (
1063
-		preg_match(
1064
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1065
-			$texte,
1066
-			$regs
1067
-		)
1068
-	) {
1069
-		return strval($regs[1]);
1070
-	} else {
1071
-		return '';
1072
-	}
1062
+    if (
1063
+        preg_match(
1064
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1065
+            $texte,
1066
+            $regs
1067
+        )
1068
+    ) {
1069
+        return strval($regs[1]);
1070
+    } else {
1071
+        return '';
1072
+    }
1073 1073
 }
1074 1074
 
1075 1075
 /**
@@ -1096,16 +1096,16 @@  discard block
 block discarded – undo
1096 1096
  *     Texte ou tableau de textes converti
1097 1097
  **/
1098 1098
 function supprimer_tags($texte, $rempl = '') {
1099
-	if ($texte === null) {
1100
-		return '';
1101
-	}
1102
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1103
-	// ne pas oublier un < final non ferme car coupe
1104
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1105
-	// mais qui peut aussi etre un simple signe plus petit que
1106
-	$texte = str_replace('<', '&lt;', $texte);
1099
+    if ($texte === null) {
1100
+        return '';
1101
+    }
1102
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1103
+    // ne pas oublier un < final non ferme car coupe
1104
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1105
+    // mais qui peut aussi etre un simple signe plus petit que
1106
+    $texte = str_replace('<', '&lt;', $texte);
1107 1107
 
1108
-	return $texte;
1108
+    return $texte;
1109 1109
 }
1110 1110
 
1111 1111
 /**
@@ -1128,9 +1128,9 @@  discard block
 block discarded – undo
1128 1128
  *     Texte converti
1129 1129
  **/
1130 1130
 function echapper_tags($texte, $rempl = '') {
1131
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1131
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1132 1132
 
1133
-	return $texte;
1133
+    return $texte;
1134 1134
 }
1135 1135
 
1136 1136
 /**
@@ -1151,18 +1151,18 @@  discard block
 block discarded – undo
1151 1151
  *     Texte converti
1152 1152
  **/
1153 1153
 function textebrut($texte) {
1154
-	$u = $GLOBALS['meta']['pcre_u'];
1155
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1156
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1157
-	$texte = preg_replace("/^\n+/", '', $texte);
1158
-	$texte = preg_replace("/\n+$/", '', $texte);
1159
-	$texte = preg_replace("/\n +/", "\n", $texte);
1160
-	$texte = supprimer_tags($texte);
1161
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1162
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1163
-	$texte = str_replace('&#8217;', "'", $texte);
1154
+    $u = $GLOBALS['meta']['pcre_u'];
1155
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1156
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1157
+    $texte = preg_replace("/^\n+/", '', $texte);
1158
+    $texte = preg_replace("/\n+$/", '', $texte);
1159
+    $texte = preg_replace("/\n +/", "\n", $texte);
1160
+    $texte = supprimer_tags($texte);
1161
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1162
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1163
+    $texte = str_replace('&#8217;', "'", $texte);
1164 1164
 
1165
-	return $texte;
1165
+    return $texte;
1166 1166
 }
1167 1167
 
1168 1168
 
@@ -1178,23 +1178,23 @@  discard block
 block discarded – undo
1178 1178
  *     Texte avec liens ouvrants
1179 1179
  **/
1180 1180
 function liens_ouvrants($texte) {
1181
-	if (
1182
-		preg_match_all(
1183
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1184
-			$texte,
1185
-			$liens,
1186
-			PREG_PATTERN_ORDER
1187
-		)
1188
-	) {
1189
-		foreach ($liens[0] as $a) {
1190
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1191
-			$ablank = inserer_attribut($a, 'rel', $rel);
1192
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1193
-			$texte = str_replace($a, $ablank, $texte);
1194
-		}
1195
-	}
1196
-
1197
-	return $texte;
1181
+    if (
1182
+        preg_match_all(
1183
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1184
+            $texte,
1185
+            $liens,
1186
+            PREG_PATTERN_ORDER
1187
+        )
1188
+    ) {
1189
+        foreach ($liens[0] as $a) {
1190
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1191
+            $ablank = inserer_attribut($a, 'rel', $rel);
1192
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1193
+            $texte = str_replace($a, $ablank, $texte);
1194
+        }
1195
+    }
1196
+
1197
+    return $texte;
1198 1198
 }
1199 1199
 
1200 1200
 /**
@@ -1204,22 +1204,22 @@  discard block
 block discarded – undo
1204 1204
  * @return string
1205 1205
  */
1206 1206
 function liens_nofollow($texte) {
1207
-	if (stripos($texte, '<a') === false) {
1208
-		return $texte;
1209
-	}
1207
+    if (stripos($texte, '<a') === false) {
1208
+        return $texte;
1209
+    }
1210 1210
 
1211
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1212
-		foreach ($regs[0] as $a) {
1213
-			$rel = extraire_attribut($a, 'rel') ?? '';
1214
-			if (strpos($rel, 'nofollow') === false) {
1215
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1216
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1217
-				$texte = str_replace($a, $anofollow, $texte);
1218
-			}
1219
-		}
1220
-	}
1211
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1212
+        foreach ($regs[0] as $a) {
1213
+            $rel = extraire_attribut($a, 'rel') ?? '';
1214
+            if (strpos($rel, 'nofollow') === false) {
1215
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1216
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1217
+                $texte = str_replace($a, $anofollow, $texte);
1218
+            }
1219
+        }
1220
+    }
1221 1221
 
1222
-	return $texte;
1222
+    return $texte;
1223 1223
 }
1224 1224
 
1225 1225
 /**
@@ -1238,12 +1238,12 @@  discard block
 block discarded – undo
1238 1238
  *     Texte sans paraghaphes
1239 1239
  **/
1240 1240
 function PtoBR($texte) {
1241
-	$u = $GLOBALS['meta']['pcre_u'];
1242
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1243
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1244
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1241
+    $u = $GLOBALS['meta']['pcre_u'];
1242
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1243
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1244
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1245 1245
 
1246
-	return $texte;
1246
+    return $texte;
1247 1247
 }
1248 1248
 
1249 1249
 
@@ -1268,14 +1268,14 @@  discard block
 block discarded – undo
1268 1268
  * @return string Texte encadré du style CSS
1269 1269
  */
1270 1270
 function lignes_longues($texte) {
1271
-	if (!strlen(trim($texte))) {
1272
-		return $texte;
1273
-	}
1274
-	include_spip('inc/texte');
1275
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1276
-		'div' : 'span';
1271
+    if (!strlen(trim($texte))) {
1272
+        return $texte;
1273
+    }
1274
+    include_spip('inc/texte');
1275
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1276
+        'div' : 'span';
1277 1277
 
1278
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1278
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1279 1279
 }
1280 1280
 
1281 1281
 /**
@@ -1294,30 +1294,30 @@  discard block
 block discarded – undo
1294 1294
  * @return string Texte en majuscule
1295 1295
  */
1296 1296
 function majuscules($texte) {
1297
-	if (!strlen($texte)) {
1298
-		return '';
1299
-	}
1297
+    if (!strlen($texte)) {
1298
+        return '';
1299
+    }
1300 1300
 
1301
-	// Cas du turc
1302
-	if ($GLOBALS['spip_lang'] == 'tr') {
1303
-		# remplacer hors des tags et des entites
1304
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1305
-			foreach ($regs as $n => $match) {
1306
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1307
-			}
1308
-		}
1301
+    // Cas du turc
1302
+    if ($GLOBALS['spip_lang'] == 'tr') {
1303
+        # remplacer hors des tags et des entites
1304
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1305
+            foreach ($regs as $n => $match) {
1306
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1307
+            }
1308
+        }
1309 1309
 
1310
-		$texte = str_replace('i', '&#304;', $texte);
1310
+        $texte = str_replace('i', '&#304;', $texte);
1311 1311
 
1312
-		if ($regs) {
1313
-			foreach ($regs as $n => $match) {
1314
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1315
-			}
1316
-		}
1317
-	}
1312
+        if ($regs) {
1313
+            foreach ($regs as $n => $match) {
1314
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1315
+            }
1316
+        }
1317
+    }
1318 1318
 
1319
-	// Cas general
1320
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1319
+    // Cas general
1320
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1321 1321
 }
1322 1322
 
1323 1323
 /**
@@ -1335,29 +1335,29 @@  discard block
 block discarded – undo
1335 1335
  * @return string
1336 1336
  **/
1337 1337
 function taille_en_octets($taille) {
1338
-	if (!defined('_KILOBYTE')) {
1339
-		/**
1340
-		 * Définit le nombre d'octets dans un Kilobyte
1341
-		 *
1342
-		 * @var int
1343
-		 **/
1344
-		define('_KILOBYTE', 1024);
1345
-	}
1338
+    if (!defined('_KILOBYTE')) {
1339
+        /**
1340
+         * Définit le nombre d'octets dans un Kilobyte
1341
+         *
1342
+         * @var int
1343
+         **/
1344
+        define('_KILOBYTE', 1024);
1345
+    }
1346 1346
 
1347
-	if ($taille < 1) {
1348
-		return '';
1349
-	}
1350
-	if ($taille < _KILOBYTE) {
1351
-		$taille = _T('taille_octets', ['taille' => $taille]);
1352
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1353
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1354
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1355
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1356
-	} else {
1357
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1358
-	}
1347
+    if ($taille < 1) {
1348
+        return '';
1349
+    }
1350
+    if ($taille < _KILOBYTE) {
1351
+        $taille = _T('taille_octets', ['taille' => $taille]);
1352
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1353
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1354
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1355
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1356
+    } else {
1357
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1358
+    }
1359 1359
 
1360
-	return $taille;
1360
+    return $taille;
1361 1361
 }
1362 1362
 
1363 1363
 
@@ -1379,21 +1379,21 @@  discard block
 block discarded – undo
1379 1379
  *     Texte prêt pour être utilisé en attribut HTML
1380 1380
  **/
1381 1381
 function attribut_html(?string $texte, $textebrut = true): string {
1382
-	if ($texte === null) {
1383
-		return '';
1384
-	}
1385
-	$u = $GLOBALS['meta']['pcre_u'];
1386
-	if ($textebrut) {
1387
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1388
-	}
1389
-	$texte = texte_backend($texte);
1390
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1382
+    if ($texte === null) {
1383
+        return '';
1384
+    }
1385
+    $u = $GLOBALS['meta']['pcre_u'];
1386
+    if ($textebrut) {
1387
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1388
+    }
1389
+    $texte = texte_backend($texte);
1390
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1391 1391
 
1392
-	return preg_replace(
1393
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1394
-		['&', '&#38;'],
1395
-		$texte
1396
-	);
1392
+    return preg_replace(
1393
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1394
+        ['&', '&#38;'],
1395
+        $texte
1396
+    );
1397 1397
 }
1398 1398
 
1399 1399
 
@@ -1413,15 +1413,15 @@  discard block
 block discarded – undo
1413 1413
  *     URL ou chaîne vide
1414 1414
  **/
1415 1415
 function vider_url(?string $url, $entites = true): string {
1416
-	if ($url === null) {
1417
-		return '';
1418
-	}
1419
-	# un message pour abs_url
1420
-	$GLOBALS['mode_abs_url'] = 'url';
1421
-	$url = trim($url);
1422
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1416
+    if ($url === null) {
1417
+        return '';
1418
+    }
1419
+    # un message pour abs_url
1420
+    $GLOBALS['mode_abs_url'] = 'url';
1421
+    $url = trim($url);
1422
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1423 1423
 
1424
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1424
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1425 1425
 }
1426 1426
 
1427 1427
 
@@ -1436,10 +1436,10 @@  discard block
 block discarded – undo
1436 1436
  * @return string Adresse email maquillée
1437 1437
  **/
1438 1438
 function antispam($texte) {
1439
-	include_spip('inc/acces');
1440
-	$masque = creer_pass_aleatoire(3);
1439
+    include_spip('inc/acces');
1440
+    $masque = creer_pass_aleatoire(3);
1441 1441
 
1442
-	return preg_replace('/@/', " $masque ", $texte);
1442
+    return preg_replace('/@/', " $masque ", $texte);
1443 1443
 }
1444 1444
 
1445 1445
 /**
@@ -1471,8 +1471,8 @@  discard block
 block discarded – undo
1471 1471
  *     True si on a le droit d'accès, false sinon.
1472 1472
  **/
1473 1473
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1474
-	include_spip('inc/acces');
1475
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1474
+    include_spip('inc/acces');
1475
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1476 1476
 }
1477 1477
 
1478 1478
 /**
@@ -1497,13 +1497,13 @@  discard block
 block discarded – undo
1497 1497
  *     Retourne $texte, sinon $sinon.
1498 1498
  **/
1499 1499
 function sinon($texte, $sinon = '') {
1500
-	if ($texte) {
1501
-		return $texte;
1502
-	} elseif (is_scalar($texte) and strlen($texte)) {
1503
-		return $texte;
1504
-	} else {
1505
-		return $sinon;
1506
-	}
1500
+    if ($texte) {
1501
+        return $texte;
1502
+    } elseif (is_scalar($texte) and strlen($texte)) {
1503
+        return $texte;
1504
+    } else {
1505
+        return $sinon;
1506
+    }
1507 1507
 }
1508 1508
 
1509 1509
 /**
@@ -1527,7 +1527,7 @@  discard block
 block discarded – undo
1527 1527
  * @return mixed
1528 1528
  **/
1529 1529
 function choixsivide($a, $vide, $pasvide) {
1530
-	return $a ? $pasvide : $vide;
1530
+    return $a ? $pasvide : $vide;
1531 1531
 }
1532 1532
 
1533 1533
 /**
@@ -1551,7 +1551,7 @@  discard block
 block discarded – undo
1551 1551
  * @return mixed
1552 1552
  **/
1553 1553
 function choixsiegal($a1, $a2, $v, $f) {
1554
-	return ($a1 == $a2) ? $v : $f;
1554
+    return ($a1 == $a2) ? $v : $f;
1555 1555
 }
1556 1556
 
1557 1557
 //
@@ -1570,13 +1570,13 @@  discard block
 block discarded – undo
1570 1570
  * @return string
1571 1571
  **/
1572 1572
 function filtrer_ical($texte) {
1573
-	#include_spip('inc/charsets');
1574
-	$texte = html2unicode($texte);
1575
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1576
-	$texte = preg_replace("/\n/", ' ', $texte);
1577
-	$texte = preg_replace('/,/', '\,', $texte);
1573
+    #include_spip('inc/charsets');
1574
+    $texte = html2unicode($texte);
1575
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1576
+    $texte = preg_replace("/\n/", ' ', $texte);
1577
+    $texte = preg_replace('/,/', '\,', $texte);
1578 1578
 
1579
-	return $texte;
1579
+    return $texte;
1580 1580
 }
1581 1581
 
1582 1582
 
@@ -1601,54 +1601,54 @@  discard block
 block discarded – undo
1601 1601
  * @return string
1602 1602
  **/
1603 1603
 function post_autobr($texte, $delim = "\n_ ") {
1604
-	if (!function_exists('echappe_html')) {
1605
-		include_spip('inc/texte_mini');
1606
-	}
1607
-	$texte = str_replace("\r\n", "\r", $texte);
1608
-	$texte = str_replace("\r", "\n", $texte);
1609
-
1610
-	if (preg_match(",\n+$,", $texte, $fin)) {
1611
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1612
-	} else {
1613
-		$fin = '';
1614
-	}
1615
-
1616
-	$texte = echappe_html($texte, '', true);
1617
-
1618
-	// echapper les modeles
1619
-	if (strpos($texte, '<') !== false) {
1620
-		include_spip('inc/lien');
1621
-		if (defined('_PREG_MODELE')) {
1622
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1623
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1624
-		}
1625
-	}
1626
-
1627
-	$debut = '';
1628
-	$suite = $texte;
1629
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1630
-		$debut .= substr($suite, 0, $t - 1);
1631
-		$suite = substr($suite, $t);
1632
-		$car = substr($suite, 0, 1);
1633
-		if (
1634
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1635
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1636
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1637
-		) {
1638
-			$debut .= $delim;
1639
-		} else {
1640
-			$debut .= "\n";
1641
-		}
1642
-		if (preg_match(",^\n+,", $suite, $regs)) {
1643
-			$debut .= $regs[0];
1644
-			$suite = substr($suite, strlen($regs[0]));
1645
-		}
1646
-	}
1647
-	$texte = $debut . $suite;
1648
-
1649
-	$texte = echappe_retour($texte);
1650
-
1651
-	return $texte . $fin;
1604
+    if (!function_exists('echappe_html')) {
1605
+        include_spip('inc/texte_mini');
1606
+    }
1607
+    $texte = str_replace("\r\n", "\r", $texte);
1608
+    $texte = str_replace("\r", "\n", $texte);
1609
+
1610
+    if (preg_match(",\n+$,", $texte, $fin)) {
1611
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1612
+    } else {
1613
+        $fin = '';
1614
+    }
1615
+
1616
+    $texte = echappe_html($texte, '', true);
1617
+
1618
+    // echapper les modeles
1619
+    if (strpos($texte, '<') !== false) {
1620
+        include_spip('inc/lien');
1621
+        if (defined('_PREG_MODELE')) {
1622
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1623
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1624
+        }
1625
+    }
1626
+
1627
+    $debut = '';
1628
+    $suite = $texte;
1629
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1630
+        $debut .= substr($suite, 0, $t - 1);
1631
+        $suite = substr($suite, $t);
1632
+        $car = substr($suite, 0, 1);
1633
+        if (
1634
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1635
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1636
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1637
+        ) {
1638
+            $debut .= $delim;
1639
+        } else {
1640
+            $debut .= "\n";
1641
+        }
1642
+        if (preg_match(",^\n+,", $suite, $regs)) {
1643
+            $debut .= $regs[0];
1644
+            $suite = substr($suite, strlen($regs[0]));
1645
+        }
1646
+    }
1647
+    $texte = $debut . $suite;
1648
+
1649
+    $texte = echappe_retour($texte);
1650
+
1651
+    return $texte . $fin;
1652 1652
 }
1653 1653
 
1654 1654
 
@@ -1689,47 +1689,47 @@  discard block
 block discarded – undo
1689 1689
  * @return string
1690 1690
  **/
1691 1691
 function extraire_idiome($letexte, $lang = null, $options = []) {
1692
-	static $traduire = false;
1693
-	if (
1694
-		$letexte
1695
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1696
-	) {
1697
-		if (!$traduire) {
1698
-			$traduire = charger_fonction('traduire', 'inc');
1699
-			include_spip('inc/lang');
1700
-		}
1701
-		if (!$lang) {
1702
-			$lang = $GLOBALS['spip_lang'];
1703
-		}
1704
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1705
-		if (is_bool($options)) {
1706
-			$options = ['echappe_span' => $options];
1707
-		}
1708
-		if (!isset($options['echappe_span'])) {
1709
-			$options = array_merge($options, ['echappe_span' => false]);
1710
-		}
1711
-
1712
-		foreach ($regs as $reg) {
1713
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1714
-			$desc = $traduire($cle, $lang, true);
1715
-			$l = $desc->langue;
1716
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1717
-			if (strlen($desc->texte ?? '')) {
1718
-				$trad = code_echappement($desc->texte, 'idiome', false);
1719
-				if ($l !== $lang) {
1720
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1721
-				}
1722
-				if (lang_dir($l) !== lang_dir($lang)) {
1723
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1724
-				}
1725
-				if (!$options['echappe_span']) {
1726
-					$trad = echappe_retour($trad, 'idiome');
1727
-				}
1728
-				$letexte = str_replace($reg[0], $trad, $letexte);
1729
-			}
1730
-		}
1731
-	}
1732
-	return $letexte;
1692
+    static $traduire = false;
1693
+    if (
1694
+        $letexte
1695
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1696
+    ) {
1697
+        if (!$traduire) {
1698
+            $traduire = charger_fonction('traduire', 'inc');
1699
+            include_spip('inc/lang');
1700
+        }
1701
+        if (!$lang) {
1702
+            $lang = $GLOBALS['spip_lang'];
1703
+        }
1704
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1705
+        if (is_bool($options)) {
1706
+            $options = ['echappe_span' => $options];
1707
+        }
1708
+        if (!isset($options['echappe_span'])) {
1709
+            $options = array_merge($options, ['echappe_span' => false]);
1710
+        }
1711
+
1712
+        foreach ($regs as $reg) {
1713
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1714
+            $desc = $traduire($cle, $lang, true);
1715
+            $l = $desc->langue;
1716
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1717
+            if (strlen($desc->texte ?? '')) {
1718
+                $trad = code_echappement($desc->texte, 'idiome', false);
1719
+                if ($l !== $lang) {
1720
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1721
+                }
1722
+                if (lang_dir($l) !== lang_dir($lang)) {
1723
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1724
+                }
1725
+                if (!$options['echappe_span']) {
1726
+                    $trad = echappe_retour($trad, 'idiome');
1727
+                }
1728
+                $letexte = str_replace($reg[0], $trad, $letexte);
1729
+            }
1730
+        }
1731
+    }
1732
+    return $letexte;
1733 1733
 }
1734 1734
 
1735 1735
 /**
@@ -1781,68 +1781,68 @@  discard block
 block discarded – undo
1781 1781
  **/
1782 1782
 function extraire_multi($letexte, $lang = null, $options = []) {
1783 1783
 
1784
-	if (
1785
-		$letexte
1786
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1787
-	) {
1788
-		if (!$lang) {
1789
-			$lang = $GLOBALS['spip_lang'];
1790
-		}
1791
-
1792
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1793
-		if (is_bool($options)) {
1794
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1795
-		}
1796
-		if (!isset($options['echappe_span'])) {
1797
-			$options = array_merge($options, ['echappe_span' => false]);
1798
-		}
1799
-		if (!isset($options['lang_defaut'])) {
1800
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1801
-		}
1802
-
1803
-		include_spip('inc/lang');
1804
-		foreach ($regs as $reg) {
1805
-			// chercher la version de la langue courante
1806
-			$trads = extraire_trads($reg[1]);
1807
-			if ($l = approcher_langue($trads, $lang)) {
1808
-				$trad = $trads[$l];
1809
-			} else {
1810
-				if ($options['lang_defaut'] == 'aucune') {
1811
-					$trad = '';
1812
-				} else {
1813
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1814
-					// ou la premiere dispo
1815
-					// mais typographier le texte selon les regles de celle-ci
1816
-					// Attention aux blocs multi sur plusieurs lignes
1817
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1818
-						$l = key($trads);
1819
-					}
1820
-					$trad = $trads[$l];
1821
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1822
-					$trad = $typographie($trad);
1823
-					// Tester si on echappe en span ou en div
1824
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1825
-					include_spip('inc/texte');
1826
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1827
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1828
-					if ($mode === 'div') {
1829
-						$trad = rtrim($trad) . "\n\n";
1830
-					}
1831
-					$trad = code_echappement($trad, 'multi', false, $mode);
1832
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1833
-					if (lang_dir($l) !== lang_dir($lang)) {
1834
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1835
-					}
1836
-					if (!$options['echappe_span']) {
1837
-						$trad = echappe_retour($trad, 'multi');
1838
-					}
1839
-				}
1840
-			}
1841
-			$letexte = str_replace($reg[0], $trad, $letexte);
1842
-		}
1843
-	}
1844
-
1845
-	return $letexte;
1784
+    if (
1785
+        $letexte
1786
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1787
+    ) {
1788
+        if (!$lang) {
1789
+            $lang = $GLOBALS['spip_lang'];
1790
+        }
1791
+
1792
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1793
+        if (is_bool($options)) {
1794
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1795
+        }
1796
+        if (!isset($options['echappe_span'])) {
1797
+            $options = array_merge($options, ['echappe_span' => false]);
1798
+        }
1799
+        if (!isset($options['lang_defaut'])) {
1800
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1801
+        }
1802
+
1803
+        include_spip('inc/lang');
1804
+        foreach ($regs as $reg) {
1805
+            // chercher la version de la langue courante
1806
+            $trads = extraire_trads($reg[1]);
1807
+            if ($l = approcher_langue($trads, $lang)) {
1808
+                $trad = $trads[$l];
1809
+            } else {
1810
+                if ($options['lang_defaut'] == 'aucune') {
1811
+                    $trad = '';
1812
+                } else {
1813
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1814
+                    // ou la premiere dispo
1815
+                    // mais typographier le texte selon les regles de celle-ci
1816
+                    // Attention aux blocs multi sur plusieurs lignes
1817
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1818
+                        $l = key($trads);
1819
+                    }
1820
+                    $trad = $trads[$l];
1821
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1822
+                    $trad = $typographie($trad);
1823
+                    // Tester si on echappe en span ou en div
1824
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1825
+                    include_spip('inc/texte');
1826
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1827
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1828
+                    if ($mode === 'div') {
1829
+                        $trad = rtrim($trad) . "\n\n";
1830
+                    }
1831
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1832
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1833
+                    if (lang_dir($l) !== lang_dir($lang)) {
1834
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1835
+                    }
1836
+                    if (!$options['echappe_span']) {
1837
+                        $trad = echappe_retour($trad, 'multi');
1838
+                    }
1839
+                }
1840
+            }
1841
+            $letexte = str_replace($reg[0], $trad, $letexte);
1842
+        }
1843
+    }
1844
+
1845
+    return $letexte;
1846 1846
 }
1847 1847
 
1848 1848
 /**
@@ -1858,21 +1858,21 @@  discard block
 block discarded – undo
1858 1858
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1859 1859
  **/
1860 1860
 function extraire_trads($bloc) {
1861
-	$trads = [];
1862
-	$lang = '';
1861
+    $trads = [];
1862
+    $lang = '';
1863 1863
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1864 1864
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1865
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1866
-		$texte = trim($regs[1]);
1867
-		if ($texte or $lang) {
1868
-			$trads[$lang] = $texte;
1869
-		}
1870
-		$bloc = substr($bloc, strlen($regs[0]));
1871
-		$lang = $regs[2];
1872
-	}
1873
-	$trads[$lang] = $bloc;
1865
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1866
+        $texte = trim($regs[1]);
1867
+        if ($texte or $lang) {
1868
+            $trads[$lang] = $texte;
1869
+        }
1870
+        $bloc = substr($bloc, strlen($regs[0]));
1871
+        $lang = $regs[2];
1872
+    }
1873
+    $trads[$lang] = $bloc;
1874 1874
 
1875
-	return $trads;
1875
+    return $trads;
1876 1876
 }
1877 1877
 
1878 1878
 
@@ -1883,7 +1883,7 @@  discard block
 block discarded – undo
1883 1883
  * @return string L'initiale en majuscule
1884 1884
  */
1885 1885
 function filtre_initiale($nom) {
1886
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1886
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1887 1887
 }
1888 1888
 
1889 1889
 
@@ -1928,33 +1928,33 @@  discard block
 block discarded – undo
1928 1928
  *      - null (interne) : si on empile
1929 1929
  **/
1930 1930
 function unique($donnee, $famille = '', $cpt = false) {
1931
-	static $mem = [];
1932
-	// permettre de vider la pile et de la restaurer
1933
-	// pour le calcul de introduction...
1934
-	if ($famille == '_spip_raz_') {
1935
-		$tmp = $mem;
1936
-		$mem = [];
1937
-
1938
-		return $tmp;
1939
-	} elseif ($famille == '_spip_set_') {
1940
-		$mem = $donnee;
1941
-
1942
-		return;
1943
-	}
1944
-	// eviter une notice
1945
-	if (!isset($mem[$famille])) {
1946
-		$mem[$famille] = [];
1947
-	}
1948
-	if ($cpt) {
1949
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1950
-	}
1951
-	// eviter une notice
1952
-	if (!isset($mem[$famille][$donnee])) {
1953
-		$mem[$famille][$donnee] = 0;
1954
-	}
1955
-	if (!($mem[$famille][$donnee]++)) {
1956
-		return $donnee;
1957
-	}
1931
+    static $mem = [];
1932
+    // permettre de vider la pile et de la restaurer
1933
+    // pour le calcul de introduction...
1934
+    if ($famille == '_spip_raz_') {
1935
+        $tmp = $mem;
1936
+        $mem = [];
1937
+
1938
+        return $tmp;
1939
+    } elseif ($famille == '_spip_set_') {
1940
+        $mem = $donnee;
1941
+
1942
+        return;
1943
+    }
1944
+    // eviter une notice
1945
+    if (!isset($mem[$famille])) {
1946
+        $mem[$famille] = [];
1947
+    }
1948
+    if ($cpt) {
1949
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1950
+    }
1951
+    // eviter une notice
1952
+    if (!isset($mem[$famille][$donnee])) {
1953
+        $mem[$famille][$donnee] = 0;
1954
+    }
1955
+    if (!($mem[$famille][$donnee]++)) {
1956
+        return $donnee;
1957
+    }
1958 1958
 }
1959 1959
 
1960 1960
 
@@ -1984,20 +1984,20 @@  discard block
 block discarded – undo
1984 1984
  *     Une des valeurs en fonction du compteur.
1985 1985
  **/
1986 1986
 function alterner($i, ...$args) {
1987
-	// recuperer les arguments (attention fonctions un peu space)
1988
-	$num = count($args);
1987
+    // recuperer les arguments (attention fonctions un peu space)
1988
+    $num = count($args);
1989 1989
 
1990
-	if ($num === 1 && is_array($args[0])) {
1991
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1992
-		$args = array_values($args[0]);
1993
-		$num = count($args);
1994
-	}
1990
+    if ($num === 1 && is_array($args[0])) {
1991
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1992
+        $args = array_values($args[0]);
1993
+        $num = count($args);
1994
+    }
1995 1995
 
1996
-	// un index compris entre 0 et num exclus
1997
-	$i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1998
-	$i = ($i + $num) % $num; // dans [0;$num[
1999
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
2000
-	return $args[$i];
1996
+    // un index compris entre 0 et num exclus
1997
+    $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1998
+    $i = ($i + $num) % $num; // dans [0;$num[
1999
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
2000
+    return $args[$i];
2001 2001
 }
2002 2002
 
2003 2003
 
@@ -2023,51 +2023,51 @@  discard block
 block discarded – undo
2023 2023
  *     - null lorsque l’attribut n’existe pas.
2024 2024
  **/
2025 2025
 function extraire_attribut($balise, $attribut, $complet = false) {
2026
-	if (is_array($balise)) {
2027
-		array_walk(
2028
-			$balise,
2029
-			function (&$a, $key, $t) {
2030
-				$a = extraire_attribut($a, $t);
2031
-			},
2032
-			$attribut
2033
-		);
2034
-
2035
-		return $balise;
2036
-	}
2037
-	if (
2038
-		$balise
2039
-		&& preg_match(
2040
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
2041
-			. $attribut
2042
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
2043
-			$balise,
2044
-			$r
2045
-		)
2046
-	) {
2047
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2048
-			$r[4] = substr($r[3], 1, -1);
2049
-			$r[3] = $r[3][0];
2050
-		} elseif ($r[3] !== '') {
2051
-			$r[4] = $r[3];
2052
-			$r[3] = '';
2053
-		} else {
2054
-			$r[4] = trim($r[2]);
2055
-		}
2056
-		$att = $r[4];
2057
-		if (strpos($att, '&#') !== false) {
2058
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2059
-		}
2060
-		$att = filtrer_entites($att);
2061
-	} else {
2062
-		$att = null;
2063
-		$r = [];
2064
-	}
2065
-
2066
-	if ($complet) {
2067
-		return [$att, $r];
2068
-	} else {
2069
-		return $att;
2070
-	}
2026
+    if (is_array($balise)) {
2027
+        array_walk(
2028
+            $balise,
2029
+            function (&$a, $key, $t) {
2030
+                $a = extraire_attribut($a, $t);
2031
+            },
2032
+            $attribut
2033
+        );
2034
+
2035
+        return $balise;
2036
+    }
2037
+    if (
2038
+        $balise
2039
+        && preg_match(
2040
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
2041
+            . $attribut
2042
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
2043
+            $balise,
2044
+            $r
2045
+        )
2046
+    ) {
2047
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2048
+            $r[4] = substr($r[3], 1, -1);
2049
+            $r[3] = $r[3][0];
2050
+        } elseif ($r[3] !== '') {
2051
+            $r[4] = $r[3];
2052
+            $r[3] = '';
2053
+        } else {
2054
+            $r[4] = trim($r[2]);
2055
+        }
2056
+        $att = $r[4];
2057
+        if (strpos($att, '&#') !== false) {
2058
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2059
+        }
2060
+        $att = filtrer_entites($att);
2061
+    } else {
2062
+        $att = null;
2063
+        $r = [];
2064
+    }
2065
+
2066
+    if ($complet) {
2067
+        return [$att, $r];
2068
+    } else {
2069
+        return $att;
2070
+    }
2071 2071
 }
2072 2072
 
2073 2073
 /**
@@ -2100,41 +2100,41 @@  discard block
 block discarded – undo
2100 2100
  **/
2101 2101
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2102 2102
 
2103
-	if ($balise === null or $balise === '') {
2104
-		return '';
2105
-	}
2103
+    if ($balise === null or $balise === '') {
2104
+        return '';
2105
+    }
2106 2106
 
2107
-	// preparer l'attribut
2108
-	// supprimer les &nbsp; etc mais pas les balises html
2109
-	// qui ont un sens dans un attribut value d'un input
2110
-	if ($proteger) {
2111
-		$val = attribut_html($val, false);
2112
-	}
2107
+    // preparer l'attribut
2108
+    // supprimer les &nbsp; etc mais pas les balises html
2109
+    // qui ont un sens dans un attribut value d'un input
2110
+    if ($proteger) {
2111
+        $val = attribut_html($val, false);
2112
+    }
2113 2113
 
2114
-	// echapper les ' pour eviter tout bug
2115
-	$val = str_replace("'", '&#039;', $val);
2116
-	if ($vider and strlen($val) === 0) {
2117
-		$insert = '';
2118
-	} else {
2119
-		$insert = " $attribut='$val'";
2120
-	}
2114
+    // echapper les ' pour eviter tout bug
2115
+    $val = str_replace("'", '&#039;', $val);
2116
+    if ($vider and strlen($val) === 0) {
2117
+        $insert = '';
2118
+    } else {
2119
+        $insert = " $attribut='$val'";
2120
+    }
2121 2121
 
2122
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2122
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2123 2123
 
2124
-	if ($old !== null) {
2125
-		// Remplacer l'ancien attribut du meme nom
2126
-		$balise = $r[1] . $insert . $r[5];
2127
-	} else {
2128
-		// preferer une balise " />" (comme <img />)
2129
-		if (preg_match(',/>,', $balise)) {
2130
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2131
-		} // sinon une balise <a ...> ... </a>
2132
-		else {
2133
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2134
-		}
2135
-	}
2124
+    if ($old !== null) {
2125
+        // Remplacer l'ancien attribut du meme nom
2126
+        $balise = $r[1] . $insert . $r[5];
2127
+    } else {
2128
+        // preferer une balise " />" (comme <img />)
2129
+        if (preg_match(',/>,', $balise)) {
2130
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2131
+        } // sinon une balise <a ...> ... </a>
2132
+        else {
2133
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2134
+        }
2135
+    }
2136 2136
 
2137
-	return $balise;
2137
+    return $balise;
2138 2138
 }
2139 2139
 
2140 2140
 /**
@@ -2152,7 +2152,7 @@  discard block
 block discarded – undo
2152 2152
  * @return string Code HTML sans l'attribut
2153 2153
  **/
2154 2154
 function vider_attribut(?string $balise, string $attribut): string {
2155
-	return inserer_attribut($balise, $attribut, '', false, true);
2155
+    return inserer_attribut($balise, $attribut, '', false, true);
2156 2156
 }
2157 2157
 
2158 2158
 /**
@@ -2164,53 +2164,53 @@  discard block
 block discarded – undo
2164 2164
  * @return string
2165 2165
  */
2166 2166
 function modifier_class($balise, $class, $operation = 'ajouter') {
2167
-	if (is_string($class)) {
2168
-		$class = explode(' ', trim($class));
2169
-	}
2170
-	$class = array_filter($class);
2171
-	$class = array_unique($class);
2172
-	if (!$class) {
2173
-		return $balise;
2174
-	}
2175
-
2176
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2177
-	if (preg_match(',[^\w-],', implode('', $class))) {
2178
-		return $balise;
2179
-	}
2180
-
2181
-	$class_courante = extraire_attribut($balise, 'class');
2182
-	$class_new = $class_courante;
2183
-	foreach ($class as $c) {
2184
-		$is_class_presente = false;
2185
-		if (
2186
-			$class_courante
2187
-			and strpos($class_courante, (string) $c) !== false
2188
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2189
-		) {
2190
-			$is_class_presente = true;
2191
-		}
2192
-		if (
2193
-			in_array($operation, ['ajouter', 'commuter'])
2194
-			and !$is_class_presente
2195
-		) {
2196
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2197
-		} elseif (
2198
-			in_array($operation, ['supprimer', 'commuter'])
2199
-			and $is_class_presente
2200
-		) {
2201
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2202
-		}
2203
-	}
2204
-
2205
-	if ($class_new !== $class_courante) {
2206
-		if (strlen($class_new)) {
2207
-			$balise = inserer_attribut($balise, 'class', $class_new);
2208
-		} elseif ($class_courante) {
2209
-			$balise = vider_attribut($balise, 'class');
2210
-		}
2211
-	}
2212
-
2213
-	return $balise;
2167
+    if (is_string($class)) {
2168
+        $class = explode(' ', trim($class));
2169
+    }
2170
+    $class = array_filter($class);
2171
+    $class = array_unique($class);
2172
+    if (!$class) {
2173
+        return $balise;
2174
+    }
2175
+
2176
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2177
+    if (preg_match(',[^\w-],', implode('', $class))) {
2178
+        return $balise;
2179
+    }
2180
+
2181
+    $class_courante = extraire_attribut($balise, 'class');
2182
+    $class_new = $class_courante;
2183
+    foreach ($class as $c) {
2184
+        $is_class_presente = false;
2185
+        if (
2186
+            $class_courante
2187
+            and strpos($class_courante, (string) $c) !== false
2188
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2189
+        ) {
2190
+            $is_class_presente = true;
2191
+        }
2192
+        if (
2193
+            in_array($operation, ['ajouter', 'commuter'])
2194
+            and !$is_class_presente
2195
+        ) {
2196
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2197
+        } elseif (
2198
+            in_array($operation, ['supprimer', 'commuter'])
2199
+            and $is_class_presente
2200
+        ) {
2201
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2202
+        }
2203
+    }
2204
+
2205
+    if ($class_new !== $class_courante) {
2206
+        if (strlen($class_new)) {
2207
+            $balise = inserer_attribut($balise, 'class', $class_new);
2208
+        } elseif ($class_courante) {
2209
+            $balise = vider_attribut($balise, 'class');
2210
+        }
2211
+    }
2212
+
2213
+    return $balise;
2214 2214
 }
2215 2215
 
2216 2216
 /**
@@ -2220,7 +2220,7 @@  discard block
 block discarded – undo
2220 2220
  * @return string
2221 2221
  */
2222 2222
 function ajouter_class($balise, $class) {
2223
-	return modifier_class($balise, $class, 'ajouter');
2223
+    return modifier_class($balise, $class, 'ajouter');
2224 2224
 }
2225 2225
 
2226 2226
 /**
@@ -2230,7 +2230,7 @@  discard block
 block discarded – undo
2230 2230
  * @return string
2231 2231
  */
2232 2232
 function supprimer_class($balise, $class) {
2233
-	return modifier_class($balise, $class, 'supprimer');
2233
+    return modifier_class($balise, $class, 'supprimer');
2234 2234
 }
2235 2235
 
2236 2236
 /**
@@ -2241,7 +2241,7 @@  discard block
 block discarded – undo
2241 2241
  * @return string
2242 2242
  */
2243 2243
 function commuter_class($balise, $class) {
2244
-	return modifier_class($balise, $class, 'commuter');
2244
+    return modifier_class($balise, $class, 'commuter');
2245 2245
 }
2246 2246
 
2247 2247
 /**
@@ -2252,19 +2252,19 @@  discard block
 block discarded – undo
2252 2252
  * @return string
2253 2253
  */
2254 2254
 function tester_config($id, $mode = '') {
2255
-	include_spip('action/inscrire_auteur');
2255
+    include_spip('action/inscrire_auteur');
2256 2256
 
2257
-	return tester_statut_inscription($mode, $id);
2257
+    return tester_statut_inscription($mode, $id);
2258 2258
 }
2259 2259
 
2260 2260
 //
2261 2261
 // Quelques fonctions de calcul arithmetique
2262 2262
 //
2263 2263
 function floatstr($a) {
2264
- return str_replace(',', '.', (string)floatval($a));
2264
+    return str_replace(',', '.', (string)floatval($a));
2265 2265
 }
2266 2266
 function strize($f, $a, $b) {
2267
- return floatstr($f(floatstr($a), floatstr($b)));
2267
+    return floatstr($f(floatstr($a), floatstr($b)));
2268 2268
 }
2269 2269
 
2270 2270
 /**
@@ -2283,7 +2283,7 @@  discard block
 block discarded – undo
2283 2283
  * @return int $a+$b
2284 2284
  **/
2285 2285
 function plus($a, $b) {
2286
-	return $a + $b;
2286
+    return $a + $b;
2287 2287
 }
2288 2288
 function strplus($a, $b) {
2289 2289
 return strize('plus', $a, $b);
@@ -2304,7 +2304,7 @@  discard block
 block discarded – undo
2304 2304
  * @return int $a-$b
2305 2305
  **/
2306 2306
 function moins($a, $b) {
2307
-	return $a - $b;
2307
+    return $a - $b;
2308 2308
 }
2309 2309
 function strmoins($a, $b) {
2310 2310
 return strize('moins', $a, $b);
@@ -2327,7 +2327,7 @@  discard block
 block discarded – undo
2327 2327
  * @return int $a*$b
2328 2328
  **/
2329 2329
 function mult($a, $b) {
2330
-	return $a * $b;
2330
+    return $a * $b;
2331 2331
 }
2332 2332
 function strmult($a, $b) {
2333 2333
 return strize('mult', $a, $b);
@@ -2350,7 +2350,7 @@  discard block
 block discarded – undo
2350 2350
  * @return int $a/$b (ou 0 si $b est nul)
2351 2351
  **/
2352 2352
 function div($a, $b) {
2353
-	return $b ? $a / $b : 0;
2353
+    return $b ? $a / $b : 0;
2354 2354
 }
2355 2355
 function strdiv($a, $b) {
2356 2356
 return strize('div', $a, $b);
@@ -2374,7 +2374,7 @@  discard block
 block discarded – undo
2374 2374
  * @return int ($nb % $mod) + $add
2375 2375
  **/
2376 2376
 function modulo($nb, $mod, $add = 0) {
2377
-	return ($mod ? $nb % $mod : 0) + $add;
2377
+    return ($mod ? $nb % $mod : 0) + $add;
2378 2378
 }
2379 2379
 
2380 2380
 
@@ -2389,26 +2389,26 @@  discard block
 block discarded – undo
2389 2389
  *      - true sinon
2390 2390
  **/
2391 2391
 function nom_acceptable($nom) {
2392
-	$remp2 = [];
2393
-	$remp1 = [];
2394
-	if (!is_string($nom)) {
2395
-		return false;
2396
-	}
2397
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2398
-		define('_TAGS_NOM_AUTEUR', '');
2399
-	}
2400
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2401
-	foreach ($tags_acceptes as $tag) {
2402
-		if (strlen($tag)) {
2403
-			$remp1[] = '<' . trim($tag) . '>';
2404
-			$remp1[] = '</' . trim($tag) . '>';
2405
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2406
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2407
-		}
2408
-	}
2409
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2410
-
2411
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2392
+    $remp2 = [];
2393
+    $remp1 = [];
2394
+    if (!is_string($nom)) {
2395
+        return false;
2396
+    }
2397
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2398
+        define('_TAGS_NOM_AUTEUR', '');
2399
+    }
2400
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2401
+    foreach ($tags_acceptes as $tag) {
2402
+        if (strlen($tag)) {
2403
+            $remp1[] = '<' . trim($tag) . '>';
2404
+            $remp1[] = '</' . trim($tag) . '>';
2405
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2406
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2407
+        }
2408
+    }
2409
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2410
+
2411
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2412 2412
 }
2413 2413
 
2414 2414
 
@@ -2424,14 +2424,14 @@  discard block
 block discarded – undo
2424 2424
  *      - renvoie un tableau si l'entree est un tableau
2425 2425
  **/
2426 2426
 function email_valide($adresses) {
2427
-	if (is_array($adresses)) {
2428
-		$adresses = array_map('email_valide', $adresses);
2429
-		$adresses = array_filter($adresses);
2430
-		return $adresses;
2431
-	}
2427
+    if (is_array($adresses)) {
2428
+        $adresses = array_map('email_valide', $adresses);
2429
+        $adresses = array_filter($adresses);
2430
+        return $adresses;
2431
+    }
2432 2432
 
2433
-	$email_valide = charger_fonction('email_valide', 'inc');
2434
-	return $email_valide($adresses);
2433
+    $email_valide = charger_fonction('email_valide', 'inc');
2434
+    return $email_valide($adresses);
2435 2435
 }
2436 2436
 
2437 2437
 /**
@@ -2445,29 +2445,29 @@  discard block
 block discarded – undo
2445 2445
  * @return string Texte
2446 2446
  **/
2447 2447
 function afficher_enclosures($tags) {
2448
-	$s = [];
2449
-	foreach (extraire_balises($tags, 'a') as $tag) {
2450
-		if (
2451
-			extraire_attribut($tag, 'rel') == 'enclosure'
2452
-			and $t = extraire_attribut($tag, 'href')
2453
-		) {
2454
-			$s[] = preg_replace(
2455
-				',>[^<]+</a>,S',
2456
-				'>'
2457
-				. http_img_pack(
2458
-					'attachment-16.png',
2459
-					$t,
2460
-					'',
2461
-					$t,
2462
-					['utiliser_suffixe_size' => true]
2463
-				)
2464
-				. '</a>',
2465
-				$tag
2466
-			);
2467
-		}
2468
-	}
2469
-
2470
-	return join('&nbsp;', $s);
2448
+    $s = [];
2449
+    foreach (extraire_balises($tags, 'a') as $tag) {
2450
+        if (
2451
+            extraire_attribut($tag, 'rel') == 'enclosure'
2452
+            and $t = extraire_attribut($tag, 'href')
2453
+        ) {
2454
+            $s[] = preg_replace(
2455
+                ',>[^<]+</a>,S',
2456
+                '>'
2457
+                . http_img_pack(
2458
+                    'attachment-16.png',
2459
+                    $t,
2460
+                    '',
2461
+                    $t,
2462
+                    ['utiliser_suffixe_size' => true]
2463
+                )
2464
+                . '</a>',
2465
+                $tag
2466
+            );
2467
+        }
2468
+    }
2469
+
2470
+    return join('&nbsp;', $s);
2471 2471
 }
2472 2472
 
2473 2473
 /**
@@ -2482,15 +2482,15 @@  discard block
 block discarded – undo
2482 2482
  * @return string Liens trouvés
2483 2483
  **/
2484 2484
 function afficher_tags($tags, $rels = 'tag,directory') {
2485
-	$s = [];
2486
-	foreach (extraire_balises($tags, 'a') as $tag) {
2487
-		$rel = extraire_attribut($tag, 'rel');
2488
-		if (strstr(",$rels,", (string) ",$rel,")) {
2489
-			$s[] = $tag;
2490
-		}
2491
-	}
2485
+    $s = [];
2486
+    foreach (extraire_balises($tags, 'a') as $tag) {
2487
+        $rel = extraire_attribut($tag, 'rel');
2488
+        if (strstr(",$rels,", (string) ",$rel,")) {
2489
+            $s[] = $tag;
2490
+        }
2491
+    }
2492 2492
 
2493
-	return join(', ', $s);
2493
+    return join(', ', $s);
2494 2494
 }
2495 2495
 
2496 2496
 
@@ -2512,21 +2512,21 @@  discard block
 block discarded – undo
2512 2512
  * @return string Tag HTML `<a>` avec microformat.
2513 2513
  **/
2514 2514
 function enclosure2microformat($e) {
2515
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2516
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2517
-	}
2518
-	$type = extraire_attribut($e, 'type');
2519
-	if (!$length = extraire_attribut($e, 'length')) {
2520
-		# <media:content : longeur dans fileSize. On tente.
2521
-		$length = extraire_attribut($e, 'fileSize');
2522
-	}
2523
-	$fichier = basename($url);
2515
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2516
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2517
+    }
2518
+    $type = extraire_attribut($e, 'type');
2519
+    if (!$length = extraire_attribut($e, 'length')) {
2520
+        # <media:content : longeur dans fileSize. On tente.
2521
+        $length = extraire_attribut($e, 'fileSize');
2522
+    }
2523
+    $fichier = basename($url);
2524 2524
 
2525
-	return '<a rel="enclosure"'
2526
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2527
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2528
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2529
-	. '>' . $fichier . '</a>';
2525
+    return '<a rel="enclosure"'
2526
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2527
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2528
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2529
+    . '>' . $fichier . '</a>';
2530 2530
 }
2531 2531
 
2532 2532
 /**
@@ -2544,24 +2544,24 @@  discard block
 block discarded – undo
2544 2544
  * @return string Tags RSS `<enclosure>`.
2545 2545
  **/
2546 2546
 function microformat2enclosure($tags) {
2547
-	$enclosures = [];
2548
-	foreach (extraire_balises($tags, 'a') as $e) {
2549
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2550
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2551
-			$type = extraire_attribut($e, 'type');
2552
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2553
-				$length = intval(extraire_attribut($e, 'length'));
2554
-			} # vieux data
2555
-			$fichier = basename($url);
2556
-			$enclosures[] = '<enclosure'
2557
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2558
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2559
-				. ($length ? ' length="' . $length . '"' : '')
2560
-				. ' />';
2561
-		}
2562
-	}
2547
+    $enclosures = [];
2548
+    foreach (extraire_balises($tags, 'a') as $e) {
2549
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2550
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2551
+            $type = extraire_attribut($e, 'type');
2552
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2553
+                $length = intval(extraire_attribut($e, 'length'));
2554
+            } # vieux data
2555
+            $fichier = basename($url);
2556
+            $enclosures[] = '<enclosure'
2557
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2558
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2559
+                . ($length ? ' length="' . $length . '"' : '')
2560
+                . ' />';
2561
+        }
2562
+    }
2563 2563
 
2564
-	return join("\n", $enclosures);
2564
+    return join("\n", $enclosures);
2565 2565
 }
2566 2566
 
2567 2567
 
@@ -2577,16 +2577,16 @@  discard block
 block discarded – undo
2577 2577
  * @return string Tags RSS Atom `<dc:subject>`.
2578 2578
  **/
2579 2579
 function tags2dcsubject($tags) {
2580
-	$subjects = '';
2581
-	foreach (extraire_balises($tags, 'a') as $e) {
2582
-		if (extraire_attribut($e, 'rel') == 'tag') {
2583
-			$subjects .= '<dc:subject>'
2584
-				. texte_backend(textebrut($e))
2585
-				. '</dc:subject>' . "\n";
2586
-		}
2587
-	}
2580
+    $subjects = '';
2581
+    foreach (extraire_balises($tags, 'a') as $e) {
2582
+        if (extraire_attribut($e, 'rel') == 'tag') {
2583
+            $subjects .= '<dc:subject>'
2584
+                . texte_backend(textebrut($e))
2585
+                . '</dc:subject>' . "\n";
2586
+        }
2587
+    }
2588 2588
 
2589
-	return $subjects;
2589
+    return $subjects;
2590 2590
 }
2591 2591
 
2592 2592
 /**
@@ -2615,27 +2615,27 @@  discard block
 block discarded – undo
2615 2615
  *     - Tableau de résultats, si tableau en entrée.
2616 2616
  **/
2617 2617
 function extraire_balise($texte, $tag = 'a') {
2618
-	if (is_array($texte)) {
2619
-		array_walk(
2620
-			$texte,
2621
-			function (&$a, $key, $t) {
2622
-				$a = extraire_balise($a, $t);
2623
-			},
2624
-			$tag
2625
-		);
2626
-
2627
-		return $texte;
2628
-	}
2629
-
2630
-	if (
2631
-		preg_match(
2632
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2633
-			$texte,
2634
-			$regs
2635
-		)
2636
-	) {
2637
-		return $regs[0];
2638
-	}
2618
+    if (is_array($texte)) {
2619
+        array_walk(
2620
+            $texte,
2621
+            function (&$a, $key, $t) {
2622
+                $a = extraire_balise($a, $t);
2623
+            },
2624
+            $tag
2625
+        );
2626
+
2627
+        return $texte;
2628
+    }
2629
+
2630
+    if (
2631
+        preg_match(
2632
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2633
+            $texte,
2634
+            $regs
2635
+        )
2636
+    ) {
2637
+        return $regs[0];
2638
+    }
2639 2639
 }
2640 2640
 
2641 2641
 /**
@@ -2663,30 +2663,30 @@  discard block
 block discarded – undo
2663 2663
  *     - Tableau de résultats, si tableau en entrée.
2664 2664
  **/
2665 2665
 function extraire_balises($texte, $tag = 'a') {
2666
-	if (is_array($texte)) {
2667
-		array_walk(
2668
-			$texte,
2669
-			function (&$a, $key, $t) {
2670
-				$a = extraire_balises($a, $t);
2671
-			},
2672
-			$tag
2673
-		);
2674
-
2675
-		return $texte;
2676
-	}
2677
-
2678
-	if (
2679
-		preg_match_all(
2680
-			",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2681
-			$texte,
2682
-			$regs,
2683
-			PREG_PATTERN_ORDER
2684
-		)
2685
-	) {
2686
-		return $regs[0];
2687
-	} else {
2688
-		return [];
2689
-	}
2666
+    if (is_array($texte)) {
2667
+        array_walk(
2668
+            $texte,
2669
+            function (&$a, $key, $t) {
2670
+                $a = extraire_balises($a, $t);
2671
+            },
2672
+            $tag
2673
+        );
2674
+
2675
+        return $texte;
2676
+    }
2677
+
2678
+    if (
2679
+        preg_match_all(
2680
+            ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2681
+            $texte,
2682
+            $regs,
2683
+            PREG_PATTERN_ORDER
2684
+        )
2685
+    ) {
2686
+        return $regs[0];
2687
+    } else {
2688
+        return [];
2689
+    }
2690 2690
 }
2691 2691
 
2692 2692
 /**
@@ -2715,11 +2715,11 @@  discard block
 block discarded – undo
2715 2715
  *     - `$def` si on n'a pas transmis de tableau
2716 2716
  **/
2717 2717
 function in_any($val, $vals, $def = '') {
2718
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2719
-		$vals = $v;
2720
-	}
2718
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2719
+        $vals = $v;
2720
+    }
2721 2721
 
2722
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2722
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2723 2723
 }
2724 2724
 
2725 2725
 
@@ -2740,12 +2740,12 @@  discard block
 block discarded – undo
2740 2740
  *     Résultat du calcul
2741 2741
  **/
2742 2742
 function valeur_numerique($expr) {
2743
-	$a = 0;
2744
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2745
-		eval("\$a = $expr;");
2746
-	}
2743
+    $a = 0;
2744
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2745
+        eval("\$a = $expr;");
2746
+    }
2747 2747
 
2748
-	return intval($a);
2748
+    return intval($a);
2749 2749
 }
2750 2750
 
2751 2751
 /**
@@ -2764,7 +2764,7 @@  discard block
 block discarded – undo
2764 2764
  *      Retourne `$a*$b/$c`
2765 2765
  **/
2766 2766
 function regledetrois($a, $b, $c) {
2767
-	return round($a * $b / $c);
2767
+    return round($a * $b / $c);
2768 2768
 }
2769 2769
 
2770 2770
 
@@ -2787,79 +2787,79 @@  discard block
 block discarded – undo
2787 2787
  * @return string Suite de champs input hidden
2788 2788
  **/
2789 2789
 function form_hidden(?string $action = ''): string {
2790
-	$action ??= '';
2791
-
2792
-	$contexte = [];
2793
-	include_spip('inc/urls');
2794
-	if (
2795
-		$p = urls_decoder_url($action, '')
2796
-		and reset($p)
2797
-	) {
2798
-		$fond = array_shift($p);
2799
-		if ($fond != '404') {
2800
-			$contexte = array_shift($p);
2801
-			$contexte['page'] = $fond;
2802
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2803
-		}
2804
-	}
2805
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2806
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2807
-		unset($contexte['type']);
2808
-	}
2809
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2810
-		unset($contexte['type-page']);
2811
-	}
2812
-
2813
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2814
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2815
-	$values = [];
2816
-
2817
-	// d'abord avec celles de l'url
2818
-	if (false !== ($p = strpos($action, '?'))) {
2819
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2820
-			$c = explode('=', $c, 2);
2821
-			$var = array_shift($c);
2822
-			$val = array_shift($c) ?? '';
2823
-			if ($var) {
2824
-				$val = rawurldecode($val);
2825
-				$var = rawurldecode($var); // decoder les [] eventuels
2826
-				if (preg_match(',\[\]$,S', $var)) {
2827
-					$values[] = [$var, $val];
2828
-				} else {
2829
-					if (!isset($values[$var])) {
2830
-						$values[$var] = [$var, $val];
2831
-					}
2832
-				}
2833
-			}
2834
-		}
2835
-	}
2836
-
2837
-	// ensuite avec celles du contexte, sans doublonner !
2838
-	foreach ($contexte as $var => $val) {
2839
-		if (preg_match(',\[\]$,S', $var)) {
2840
-			$values[] = [$var, $val];
2841
-		} else {
2842
-			if (!isset($values[$var])) {
2843
-				$values[$var] = [$var, $val];
2844
-			}
2845
-		}
2846
-	}
2847
-
2848
-	// puis on rassemble le tout
2849
-	$hidden = [];
2850
-	foreach ($values as $value) {
2851
-		[$var, $val] = $value;
2852
-		$hidden[] = '<input name="'
2853
-			. entites_html($var)
2854
-			. '"'
2855
-			. (is_null($val)
2856
-				? ''
2857
-				: ' value="' . entites_html($val) . '"'
2858
-			)
2859
-			. ' type="hidden"' . "\n/>";
2860
-	}
2861
-
2862
-	return join('', $hidden);
2790
+    $action ??= '';
2791
+
2792
+    $contexte = [];
2793
+    include_spip('inc/urls');
2794
+    if (
2795
+        $p = urls_decoder_url($action, '')
2796
+        and reset($p)
2797
+    ) {
2798
+        $fond = array_shift($p);
2799
+        if ($fond != '404') {
2800
+            $contexte = array_shift($p);
2801
+            $contexte['page'] = $fond;
2802
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2803
+        }
2804
+    }
2805
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2806
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2807
+        unset($contexte['type']);
2808
+    }
2809
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2810
+        unset($contexte['type-page']);
2811
+    }
2812
+
2813
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2814
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2815
+    $values = [];
2816
+
2817
+    // d'abord avec celles de l'url
2818
+    if (false !== ($p = strpos($action, '?'))) {
2819
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2820
+            $c = explode('=', $c, 2);
2821
+            $var = array_shift($c);
2822
+            $val = array_shift($c) ?? '';
2823
+            if ($var) {
2824
+                $val = rawurldecode($val);
2825
+                $var = rawurldecode($var); // decoder les [] eventuels
2826
+                if (preg_match(',\[\]$,S', $var)) {
2827
+                    $values[] = [$var, $val];
2828
+                } else {
2829
+                    if (!isset($values[$var])) {
2830
+                        $values[$var] = [$var, $val];
2831
+                    }
2832
+                }
2833
+            }
2834
+        }
2835
+    }
2836
+
2837
+    // ensuite avec celles du contexte, sans doublonner !
2838
+    foreach ($contexte as $var => $val) {
2839
+        if (preg_match(',\[\]$,S', $var)) {
2840
+            $values[] = [$var, $val];
2841
+        } else {
2842
+            if (!isset($values[$var])) {
2843
+                $values[$var] = [$var, $val];
2844
+            }
2845
+        }
2846
+    }
2847
+
2848
+    // puis on rassemble le tout
2849
+    $hidden = [];
2850
+    foreach ($values as $value) {
2851
+        [$var, $val] = $value;
2852
+        $hidden[] = '<input name="'
2853
+            . entites_html($var)
2854
+            . '"'
2855
+            . (is_null($val)
2856
+                ? ''
2857
+                : ' value="' . entites_html($val) . '"'
2858
+            )
2859
+            . ' type="hidden"' . "\n/>";
2860
+    }
2861
+
2862
+    return join('', $hidden);
2863 2863
 }
2864 2864
 
2865 2865
 
@@ -2881,7 +2881,7 @@  discard block
 block discarded – undo
2881 2881
  *    - la première valeur du tableau sinon.
2882 2882
  **/
2883 2883
 function filtre_reset($array) {
2884
-	return !is_array($array) ? null : reset($array);
2884
+    return !is_array($array) ? null : reset($array);
2885 2885
 }
2886 2886
 
2887 2887
 /**
@@ -2902,7 +2902,7 @@  discard block
 block discarded – undo
2902 2902
  *    - la dernière valeur du tableau sinon.
2903 2903
  **/
2904 2904
 function filtre_end($array) {
2905
-	return !is_array($array) ? null : end($array);
2905
+    return !is_array($array) ? null : end($array);
2906 2906
 }
2907 2907
 
2908 2908
 /**
@@ -2922,11 +2922,11 @@  discard block
 block discarded – undo
2922 2922
  *
2923 2923
  **/
2924 2924
 function filtre_push($array, $val) {
2925
-	if (!is_array($array) or !array_push($array, $val)) {
2926
-		return '';
2927
-	}
2925
+    if (!is_array($array) or !array_push($array, $val)) {
2926
+        return '';
2927
+    }
2928 2928
 
2929
-	return $array;
2929
+    return $array;
2930 2930
 }
2931 2931
 
2932 2932
 /**
@@ -2945,7 +2945,7 @@  discard block
 block discarded – undo
2945 2945
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2946 2946
  **/
2947 2947
 function filtre_find($array, $val) {
2948
-	return (is_array($array) and in_array($val, $array));
2948
+    return (is_array($array) and in_array($val, $array));
2949 2949
 }
2950 2950
 
2951 2951
 
@@ -2962,13 +2962,13 @@  discard block
 block discarded – undo
2962 2962
  *     Contenu avec urls en absolus
2963 2963
  **/
2964 2964
 function urls_absolues_css($contenu, $source) {
2965
-	$path = suivre_lien(url_absolue($source), './');
2965
+    $path = suivre_lien(url_absolue($source), './');
2966 2966
 
2967
-	return preg_replace_callback(
2968
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2969
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2970
-		$contenu
2971
-	);
2967
+    return preg_replace_callback(
2968
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2969
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2970
+        $contenu
2971
+    );
2972 2972
 }
2973 2973
 
2974 2974
 
@@ -2997,119 +2997,119 @@  discard block
 block discarded – undo
2997 2997
  *     Chemin du fichier CSS inversé
2998 2998
  **/
2999 2999
 function direction_css($css, $voulue = '') {
3000
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
3001
-		return $css;
3002
-	}
3003
-	include_spip('inc/lang');
3004
-	// si on a precise le sens voulu en argument, le prendre en compte
3005
-	if ($voulue = strtolower($voulue)) {
3006
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
3007
-			$voulue = lang_dir($voulue);
3008
-		}
3009
-	} else {
3010
-		$voulue = lang_dir();
3011
-	}
3012
-
3013
-	$r = count($r) > 1;
3014
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
3015
-	$dir = $r ? 'rtl' : 'ltr';
3016
-	$ndir = $r ? 'ltr' : 'rtl';
3017
-
3018
-	if ($voulue == $dir) {
3019
-		return $css;
3020
-	}
3021
-
3022
-	if (
3023
-		// url absolue
3024
-		preg_match(',^https?:,i', $css)
3025
-		// ou qui contient un ?
3026
-		or (($p = strpos($css, '?')) !== false)
3027
-	) {
3028
-		$distant = true;
3029
-		$cssf = parse_url($css);
3030
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
3031
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
3032
-	} else {
3033
-		$distant = false;
3034
-		$cssf = $css;
3035
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
3036
-		//propose (rien a faire dans ce cas)
3037
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
3038
-		if (@file_exists($f)) {
3039
-			return $f;
3040
-		}
3041
-	}
3042
-
3043
-	// 2.
3044
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
3045
-	$f = $dir_var
3046
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3047
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3048
-
3049
-	// la css peut etre distante (url absolue !)
3050
-	if ($distant) {
3051
-		include_spip('inc/distant');
3052
-		$res = recuperer_url($css);
3053
-		if (!$res or !$contenu = $res['page']) {
3054
-			return $css;
3055
-		}
3056
-	} else {
3057
-		if (
3058
-			(@filemtime($f) > @filemtime($css))
3059
-			and (_VAR_MODE != 'recalcul')
3060
-		) {
3061
-			return $f;
3062
-		}
3063
-		if (!lire_fichier($css, $contenu)) {
3064
-			return $css;
3065
-		}
3066
-	}
3067
-
3068
-
3069
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3070
-	include_spip('lib/csstidy/class.csstidy');
3071
-	$parser = new csstidy();
3072
-	$parser->set_cfg('optimise_shorthands', 0);
3073
-	$parser->set_cfg('reverse_left_and_right', true);
3074
-	$parser->parse($contenu);
3075
-
3076
-	$contenu = $parser->print->plain();
3077
-
3078
-
3079
-	// reperer les @import auxquels il faut propager le direction_css
3080
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3081
-	$src = [];
3082
-	$src_direction_css = [];
3083
-	$src_faux_abs = [];
3084
-	$d = dirname($css);
3085
-	foreach ($regs[1] as $k => $import_css) {
3086
-		$css_direction = direction_css("$d/$import_css", $voulue);
3087
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3088
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3089
-			$css_direction = substr($css_direction, strlen($d) + 1);
3090
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3091
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3092
-			$css_direction = substr($css_direction, strlen($dir_var));
3093
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3094
-			$css_direction = '/@@@@@@/' . $css_direction;
3095
-		}
3096
-		$src[] = $regs[0][$k];
3097
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3098
-	}
3099
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3100
-
3101
-	$contenu = urls_absolues_css($contenu, $css);
3102
-
3103
-	// virer les fausses url absolues que l'on a mis dans les import
3104
-	if (count($src_faux_abs)) {
3105
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3106
-	}
3107
-
3108
-	if (!ecrire_fichier($f, $contenu)) {
3109
-		return $css;
3110
-	}
3111
-
3112
-	return $f;
3000
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
3001
+        return $css;
3002
+    }
3003
+    include_spip('inc/lang');
3004
+    // si on a precise le sens voulu en argument, le prendre en compte
3005
+    if ($voulue = strtolower($voulue)) {
3006
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
3007
+            $voulue = lang_dir($voulue);
3008
+        }
3009
+    } else {
3010
+        $voulue = lang_dir();
3011
+    }
3012
+
3013
+    $r = count($r) > 1;
3014
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
3015
+    $dir = $r ? 'rtl' : 'ltr';
3016
+    $ndir = $r ? 'ltr' : 'rtl';
3017
+
3018
+    if ($voulue == $dir) {
3019
+        return $css;
3020
+    }
3021
+
3022
+    if (
3023
+        // url absolue
3024
+        preg_match(',^https?:,i', $css)
3025
+        // ou qui contient un ?
3026
+        or (($p = strpos($css, '?')) !== false)
3027
+    ) {
3028
+        $distant = true;
3029
+        $cssf = parse_url($css);
3030
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
3031
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
3032
+    } else {
3033
+        $distant = false;
3034
+        $cssf = $css;
3035
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
3036
+        //propose (rien a faire dans ce cas)
3037
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
3038
+        if (@file_exists($f)) {
3039
+            return $f;
3040
+        }
3041
+    }
3042
+
3043
+    // 2.
3044
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
3045
+    $f = $dir_var
3046
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3047
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3048
+
3049
+    // la css peut etre distante (url absolue !)
3050
+    if ($distant) {
3051
+        include_spip('inc/distant');
3052
+        $res = recuperer_url($css);
3053
+        if (!$res or !$contenu = $res['page']) {
3054
+            return $css;
3055
+        }
3056
+    } else {
3057
+        if (
3058
+            (@filemtime($f) > @filemtime($css))
3059
+            and (_VAR_MODE != 'recalcul')
3060
+        ) {
3061
+            return $f;
3062
+        }
3063
+        if (!lire_fichier($css, $contenu)) {
3064
+            return $css;
3065
+        }
3066
+    }
3067
+
3068
+
3069
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3070
+    include_spip('lib/csstidy/class.csstidy');
3071
+    $parser = new csstidy();
3072
+    $parser->set_cfg('optimise_shorthands', 0);
3073
+    $parser->set_cfg('reverse_left_and_right', true);
3074
+    $parser->parse($contenu);
3075
+
3076
+    $contenu = $parser->print->plain();
3077
+
3078
+
3079
+    // reperer les @import auxquels il faut propager le direction_css
3080
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3081
+    $src = [];
3082
+    $src_direction_css = [];
3083
+    $src_faux_abs = [];
3084
+    $d = dirname($css);
3085
+    foreach ($regs[1] as $k => $import_css) {
3086
+        $css_direction = direction_css("$d/$import_css", $voulue);
3087
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3088
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3089
+            $css_direction = substr($css_direction, strlen($d) + 1);
3090
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3091
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3092
+            $css_direction = substr($css_direction, strlen($dir_var));
3093
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3094
+            $css_direction = '/@@@@@@/' . $css_direction;
3095
+        }
3096
+        $src[] = $regs[0][$k];
3097
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3098
+    }
3099
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3100
+
3101
+    $contenu = urls_absolues_css($contenu, $css);
3102
+
3103
+    // virer les fausses url absolues que l'on a mis dans les import
3104
+    if (count($src_faux_abs)) {
3105
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3106
+    }
3107
+
3108
+    if (!ecrire_fichier($f, $contenu)) {
3109
+        return $css;
3110
+    }
3111
+
3112
+    return $f;
3113 3113
 }
3114 3114
 
3115 3115
 
@@ -3132,46 +3132,46 @@  discard block
 block discarded – undo
3132 3132
  *     - Chemin ou URL du fichier CSS source sinon.
3133 3133
  **/
3134 3134
 function url_absolue_css($css) {
3135
-	if (!preg_match(',\.css$,i', $css, $r)) {
3136
-		return $css;
3137
-	}
3135
+    if (!preg_match(',\.css$,i', $css, $r)) {
3136
+        return $css;
3137
+    }
3138 3138
 
3139
-	$url_absolue_css = url_absolue($css);
3139
+    $url_absolue_css = url_absolue($css);
3140 3140
 
3141
-	$f = basename($css, '.css');
3142
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3143
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3144
-		. '.css';
3141
+    $f = basename($css, '.css');
3142
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3143
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3144
+        . '.css';
3145 3145
 
3146
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3147
-		return $f;
3148
-	}
3146
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3147
+        return $f;
3148
+    }
3149 3149
 
3150
-	if ($url_absolue_css == $css) {
3151
-		if (
3152
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3153
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3154
-		) {
3155
-			include_spip('inc/distant');
3156
-			$contenu = recuperer_url($css);
3157
-			$contenu = $contenu['page'] ?? '';
3158
-			if (!$contenu) {
3159
-				return $css;
3160
-			}
3161
-		}
3162
-	} elseif (!lire_fichier($css, $contenu)) {
3163
-		return $css;
3164
-	}
3150
+    if ($url_absolue_css == $css) {
3151
+        if (
3152
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3153
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3154
+        ) {
3155
+            include_spip('inc/distant');
3156
+            $contenu = recuperer_url($css);
3157
+            $contenu = $contenu['page'] ?? '';
3158
+            if (!$contenu) {
3159
+                return $css;
3160
+            }
3161
+        }
3162
+    } elseif (!lire_fichier($css, $contenu)) {
3163
+        return $css;
3164
+    }
3165 3165
 
3166
-	// passer les url relatives a la css d'origine en url absolues
3167
-	$contenu = urls_absolues_css($contenu, $css);
3166
+    // passer les url relatives a la css d'origine en url absolues
3167
+    $contenu = urls_absolues_css($contenu, $css);
3168 3168
 
3169
-	// ecrire la css
3170
-	if (!ecrire_fichier($f, $contenu)) {
3171
-		return $css;
3172
-	}
3169
+    // ecrire la css
3170
+    if (!ecrire_fichier($f, $contenu)) {
3171
+        return $css;
3172
+    }
3173 3173
 
3174
-	return $f;
3174
+    return $f;
3175 3175
 }
3176 3176
 
3177 3177
 
@@ -3205,24 +3205,24 @@  discard block
 block discarded – undo
3205 3205
  *     Valeur trouvée ou valeur par défaut.
3206 3206
  **/
3207 3207
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3208
-	foreach (explode('/', $cle) as $k) {
3209
-		$table = (is_string($table) ? @unserialize($table) : $table);
3208
+    foreach (explode('/', $cle) as $k) {
3209
+        $table = (is_string($table) ? @unserialize($table) : $table);
3210 3210
 
3211
-		if (is_object($table)) {
3212
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3213
-		} elseif (is_array($table)) {
3214
-			if ($conserver_null) {
3215
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3216
-			} else {
3217
-				$table = ($table[$k] ?? $defaut);
3218
-			}
3219
-		} else {
3220
-			$table = $defaut;
3221
-			break;
3222
-		}
3223
-	}
3211
+        if (is_object($table)) {
3212
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3213
+        } elseif (is_array($table)) {
3214
+            if ($conserver_null) {
3215
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3216
+            } else {
3217
+                $table = ($table[$k] ?? $defaut);
3218
+            }
3219
+        } else {
3220
+            $table = $defaut;
3221
+            break;
3222
+        }
3223
+    }
3224 3224
 
3225
-	return $table;
3225
+    return $table;
3226 3226
 }
3227 3227
 
3228 3228
 /**
@@ -3255,22 +3255,22 @@  discard block
 block discarded – undo
3255 3255
  *     - string : expression trouvée.
3256 3256
  **/
3257 3257
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3258
-	if (intval($modif) and $capte == 0) {
3259
-		$capte = $modif;
3260
-		$modif = 'UuimsS';
3261
-	}
3262
-	$expression = str_replace('\/', '/', $expression);
3263
-	$expression = str_replace('/', '\/', $expression);
3258
+    if (intval($modif) and $capte == 0) {
3259
+        $capte = $modif;
3260
+        $modif = 'UuimsS';
3261
+    }
3262
+    $expression = str_replace('\/', '/', $expression);
3263
+    $expression = str_replace('/', '\/', $expression);
3264 3264
 
3265
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3266
-		if (isset($r[$capte])) {
3267
-			return $r[$capte];
3268
-		} else {
3269
-			return true;
3270
-		}
3271
-	}
3265
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3266
+        if (isset($r[$capte])) {
3267
+            return $r[$capte];
3268
+        } else {
3269
+            return true;
3270
+        }
3271
+    }
3272 3272
 
3273
-	return false;
3273
+    return false;
3274 3274
 }
3275 3275
 
3276 3276
 
@@ -3297,10 +3297,10 @@  discard block
 block discarded – undo
3297 3297
  *     Texte
3298 3298
  **/
3299 3299
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3300
-	$expression = str_replace('\/', '/', $expression);
3301
-	$expression = str_replace('/', '\/', $expression);
3300
+    $expression = str_replace('\/', '/', $expression);
3301
+    $expression = str_replace('/', '\/', $expression);
3302 3302
 
3303
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3303
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3304 3304
 }
3305 3305
 
3306 3306
 
@@ -3318,25 +3318,25 @@  discard block
 block discarded – undo
3318 3318
  **/
3319 3319
 function traiter_doublons_documents(&$doublons, $letexte) {
3320 3320
 
3321
-	// Verifier dans le texte & les notes (pas beau, helas)
3322
-	$t = $letexte . $GLOBALS['les_notes'];
3321
+    // Verifier dans le texte & les notes (pas beau, helas)
3322
+    $t = $letexte . $GLOBALS['les_notes'];
3323 3323
 
3324
-	if (
3325
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3326
-		and preg_match_all(
3327
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3328
-			$t,
3329
-			$matches,
3330
-			PREG_PATTERN_ORDER
3331
-		)
3332
-	) {
3333
-		if (!isset($doublons['documents'])) {
3334
-			$doublons['documents'] = '';
3335
-		}
3336
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3337
-	}
3324
+    if (
3325
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3326
+        and preg_match_all(
3327
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3328
+            $t,
3329
+            $matches,
3330
+            PREG_PATTERN_ORDER
3331
+        )
3332
+    ) {
3333
+        if (!isset($doublons['documents'])) {
3334
+            $doublons['documents'] = '';
3335
+        }
3336
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3337
+    }
3338 3338
 
3339
-	return $letexte;
3339
+    return $letexte;
3340 3340
 }
3341 3341
 
3342 3342
 /**
@@ -3350,7 +3350,7 @@  discard block
 block discarded – undo
3350 3350
  * @return string Chaîne vide
3351 3351
  **/
3352 3352
 function vide($texte) {
3353
-	return '';
3353
+    return '';
3354 3354
 }
3355 3355
 
3356 3356
 //
@@ -3379,23 +3379,23 @@  discard block
 block discarded – undo
3379 3379
  *      Code HTML résultant
3380 3380
  **/
3381 3381
 function env_to_params($env, $ignore_params = []) {
3382
-	$ignore_params = array_merge(
3383
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3384
-		$ignore_params
3385
-	);
3386
-	if (!is_array($env)) {
3387
-		$env = unserialize($env);
3388
-	}
3389
-	$texte = '';
3390
-	if ($env) {
3391
-		foreach ($env as $i => $j) {
3392
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3393
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3394
-			}
3395
-		}
3396
-	}
3397
-
3398
-	return $texte;
3382
+    $ignore_params = array_merge(
3383
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3384
+        $ignore_params
3385
+    );
3386
+    if (!is_array($env)) {
3387
+        $env = unserialize($env);
3388
+    }
3389
+    $texte = '';
3390
+    if ($env) {
3391
+        foreach ($env as $i => $j) {
3392
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3393
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3394
+            }
3395
+        }
3396
+    }
3397
+
3398
+    return $texte;
3399 3399
 }
3400 3400
 
3401 3401
 /**
@@ -3418,23 +3418,23 @@  discard block
 block discarded – undo
3418 3418
  *      Code HTML résultant
3419 3419
  **/
3420 3420
 function env_to_attributs($env, $ignore_params = []) {
3421
-	$ignore_params = array_merge(
3422
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3423
-		$ignore_params
3424
-	);
3425
-	if (!is_array($env)) {
3426
-		$env = unserialize($env);
3427
-	}
3428
-	$texte = '';
3429
-	if ($env) {
3430
-		foreach ($env as $i => $j) {
3431
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3432
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3433
-			}
3434
-		}
3435
-	}
3421
+    $ignore_params = array_merge(
3422
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3423
+        $ignore_params
3424
+    );
3425
+    if (!is_array($env)) {
3426
+        $env = unserialize($env);
3427
+    }
3428
+    $texte = '';
3429
+    if ($env) {
3430
+        foreach ($env as $i => $j) {
3431
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3432
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3433
+            }
3434
+        }
3435
+    }
3436 3436
 
3437
-	return $texte;
3437
+    return $texte;
3438 3438
 }
3439 3439
 
3440 3440
 
@@ -3452,7 +3452,7 @@  discard block
 block discarded – undo
3452 3452
  * @return string Chaînes concaténés
3453 3453
  **/
3454 3454
 function concat(...$args): string {
3455
-	return join('', $args);
3455
+    return join('', $args);
3456 3456
 }
3457 3457
 
3458 3458
 
@@ -3472,23 +3472,23 @@  discard block
 block discarded – undo
3472 3472
  *     Contenu du ou des fichiers, concaténé
3473 3473
  **/
3474 3474
 function charge_scripts($files, $script = true) {
3475
-	$flux = '';
3476
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3477
-		if (!is_string($file)) {
3478
-			continue;
3479
-		}
3480
-		if ($script) {
3481
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3482
-		}
3483
-		if ($file) {
3484
-			$path = find_in_path($file);
3485
-			if ($path) {
3486
-				$flux .= spip_file_get_contents($path);
3487
-			}
3488
-		}
3489
-	}
3490
-
3491
-	return $flux;
3475
+    $flux = '';
3476
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3477
+        if (!is_string($file)) {
3478
+            continue;
3479
+        }
3480
+        if ($script) {
3481
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3482
+        }
3483
+        if ($file) {
3484
+            $path = find_in_path($file);
3485
+            if ($path) {
3486
+                $flux .= spip_file_get_contents($path);
3487
+            }
3488
+        }
3489
+    }
3490
+
3491
+    return $flux;
3492 3492
 }
3493 3493
 
3494 3494
 /**
@@ -3499,22 +3499,22 @@  discard block
 block discarded – undo
3499 3499
  * @return string
3500 3500
  */
3501 3501
 function http_img_variante_svg_si_possible($img_file) {
3502
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3503
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3504
-	if (
3505
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3506
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3507
-		and file_exists($variante_svg_generique)
3508
-	) {
3509
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3510
-			$img_file = $variante_svg_size;
3511
-		}
3512
-		else {
3513
-			$img_file = $variante_svg_generique;
3514
-		}
3515
-	}
3502
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3503
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3504
+    if (
3505
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3506
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3507
+        and file_exists($variante_svg_generique)
3508
+    ) {
3509
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3510
+            $img_file = $variante_svg_size;
3511
+        }
3512
+        else {
3513
+            $img_file = $variante_svg_generique;
3514
+        }
3515
+    }
3516 3516
 
3517
-	return $img_file;
3517
+    return $img_file;
3518 3518
 }
3519 3519
 
3520 3520
 /**
@@ -3535,54 +3535,54 @@  discard block
 block discarded – undo
3535 3535
  */
3536 3536
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3537 3537
 
3538
-	$img_file = $img;
3539
-	if ($p = strpos($img_file, '?')) {
3540
-		$img_file = substr($img_file, 0, $p);
3541
-	}
3542
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3543
-		$img_file = chemin_image($img);
3544
-	}
3545
-	else {
3546
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3547
-			$img_file = http_img_variante_svg_si_possible($img_file);
3548
-		}
3549
-	}
3550
-	if (stripos($atts, 'width') === false) {
3551
-		// utiliser directement l'info de taille presente dans le nom
3552
-		if (
3553
-			(!isset($options['utiliser_suffixe_size'])
3554
-				or $options['utiliser_suffixe_size'] == true
3555
-			  or strpos($img_file, '-xx.svg') !== false)
3556
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3557
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3558
-		) {
3559
-			$largeur = $hauteur = intval($regs[1]);
3560
-		} else {
3561
-			$taille = taille_image($img_file);
3562
-			[$hauteur, $largeur] = $taille;
3563
-			if (!$hauteur or !$largeur) {
3564
-				return '';
3565
-			}
3566
-		}
3567
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3568
-	}
3569
-
3570
-	if (file_exists($img_file)) {
3571
-		$img_file = timestamp($img_file);
3572
-	}
3573
-	if ($alt === false) {
3574
-		$alt = '';
3575
-	}
3576
-	elseif ($alt or $alt === '') {
3577
-		$alt = " alt='" . attribut_html($alt) . "'";
3578
-	}
3579
-	else {
3580
-		$alt = " alt='" . attribut_html($title) . "'";
3581
-	}
3582
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3583
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3584
-	. ' ' . ltrim($atts)
3585
-	. ' />';
3538
+    $img_file = $img;
3539
+    if ($p = strpos($img_file, '?')) {
3540
+        $img_file = substr($img_file, 0, $p);
3541
+    }
3542
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3543
+        $img_file = chemin_image($img);
3544
+    }
3545
+    else {
3546
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3547
+            $img_file = http_img_variante_svg_si_possible($img_file);
3548
+        }
3549
+    }
3550
+    if (stripos($atts, 'width') === false) {
3551
+        // utiliser directement l'info de taille presente dans le nom
3552
+        if (
3553
+            (!isset($options['utiliser_suffixe_size'])
3554
+                or $options['utiliser_suffixe_size'] == true
3555
+              or strpos($img_file, '-xx.svg') !== false)
3556
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3557
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3558
+        ) {
3559
+            $largeur = $hauteur = intval($regs[1]);
3560
+        } else {
3561
+            $taille = taille_image($img_file);
3562
+            [$hauteur, $largeur] = $taille;
3563
+            if (!$hauteur or !$largeur) {
3564
+                return '';
3565
+            }
3566
+        }
3567
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3568
+    }
3569
+
3570
+    if (file_exists($img_file)) {
3571
+        $img_file = timestamp($img_file);
3572
+    }
3573
+    if ($alt === false) {
3574
+        $alt = '';
3575
+    }
3576
+    elseif ($alt or $alt === '') {
3577
+        $alt = " alt='" . attribut_html($alt) . "'";
3578
+    }
3579
+    else {
3580
+        $alt = " alt='" . attribut_html($title) . "'";
3581
+    }
3582
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3583
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3584
+    . ' ' . ltrim($atts)
3585
+    . ' />';
3586 3586
 }
3587 3587
 
3588 3588
 /**
@@ -3594,70 +3594,70 @@  discard block
 block discarded – undo
3594 3594
  * @return string
3595 3595
  */
3596 3596
 function http_style_background($img, $att = '', $size = null) {
3597
-	if ($size and is_numeric($size)) {
3598
-		$size = trim($size) . 'px';
3599
-	}
3600
-	return " style='background" .
3601
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3602
-		. ($size ? "background-size:{$size};" : '')
3603
-		. "'";
3597
+    if ($size and is_numeric($size)) {
3598
+        $size = trim($size) . 'px';
3599
+    }
3600
+    return " style='background" .
3601
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3602
+        . ($size ? "background-size:{$size};" : '')
3603
+        . "'";
3604 3604
 }
3605 3605
 
3606 3606
 
3607 3607
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3608
-	$args = [$alt_or_size, $class_or_size, $size];
3609
-	while (is_null(end($args)) and count($args)) {
3610
-		array_pop($args);
3611
-	}
3612
-	if (!count($args)) {
3613
-		return [null, null, null];
3614
-	}
3615
-	if (count($args) < 3) {
3616
-		$maybe_size = array_pop($args);
3617
-		// @2x
3618
-		// @1.5x
3619
-		// 512
3620
-		// 512x*
3621
-		// 512x300
3622
-		if (
3623
-			!strlen($maybe_size)
3624
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3625
-		) {
3626
-			$args[] = $maybe_size;
3627
-			$maybe_size = null;
3628
-		}
3629
-		while (count($args) < 2) {
3630
-			$args[] = null; // default alt or class
3631
-		}
3632
-		$args[] = $maybe_size;
3633
-	}
3634
-	return $args;
3608
+    $args = [$alt_or_size, $class_or_size, $size];
3609
+    while (is_null(end($args)) and count($args)) {
3610
+        array_pop($args);
3611
+    }
3612
+    if (!count($args)) {
3613
+        return [null, null, null];
3614
+    }
3615
+    if (count($args) < 3) {
3616
+        $maybe_size = array_pop($args);
3617
+        // @2x
3618
+        // @1.5x
3619
+        // 512
3620
+        // 512x*
3621
+        // 512x300
3622
+        if (
3623
+            !strlen($maybe_size)
3624
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3625
+        ) {
3626
+            $args[] = $maybe_size;
3627
+            $maybe_size = null;
3628
+        }
3629
+        while (count($args) < 2) {
3630
+            $args[] = null; // default alt or class
3631
+        }
3632
+        $args[] = $maybe_size;
3633
+    }
3634
+    return $args;
3635 3635
 }
3636 3636
 
3637 3637
 function helper_filtre_balise_img_svg_size($img, $size) {
3638
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3639
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3640
-		$coef = floatval(substr($size, 1, -1));
3641
-		[$h, $w] = taille_image($img);
3642
-		$height = intval(round($h / $coef));
3643
-		$width = intval(round($w / $coef));
3644
-	}
3645
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3646
-	else {
3647
-		$size = explode('x', $size, 2);
3648
-		$size = array_map('trim', $size);
3649
-		$height = $width = intval(array_shift($size));
3650
-
3651
-		if (count($size) and reset($size)) {
3652
-			$height = array_shift($size);
3653
-			if ($height === '*') {
3654
-				[$h, $w] = taille_image($img);
3655
-				$height = intval(round($h * $width / $w));
3656
-			}
3657
-		}
3658
-	}
3659
-
3660
-	return [$width, $height];
3638
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3639
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3640
+        $coef = floatval(substr($size, 1, -1));
3641
+        [$h, $w] = taille_image($img);
3642
+        $height = intval(round($h / $coef));
3643
+        $width = intval(round($w / $coef));
3644
+    }
3645
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3646
+    else {
3647
+        $size = explode('x', $size, 2);
3648
+        $size = array_map('trim', $size);
3649
+        $height = $width = intval(array_shift($size));
3650
+
3651
+        if (count($size) and reset($size)) {
3652
+            $height = array_shift($size);
3653
+            if ($height === '*') {
3654
+                [$h, $w] = taille_image($img);
3655
+                $height = intval(round($h * $width / $w));
3656
+            }
3657
+        }
3658
+    }
3659
+
3660
+    return [$width, $height];
3661 3661
 }
3662 3662
 
3663 3663
 /**
@@ -3693,43 +3693,43 @@  discard block
 block discarded – undo
3693 3693
  */
3694 3694
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3695 3695
 
3696
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3697
-
3698
-	$img = trim((string) $img);
3699
-	if (strpos($img, '<img') === 0) {
3700
-		if (!is_null($alt)) {
3701
-			$img = inserer_attribut($img, 'alt', $alt);
3702
-		}
3703
-		if (!is_null($class)) {
3704
-			if (strlen($class)) {
3705
-				$img = inserer_attribut($img, 'class', $class);
3706
-			}
3707
-			else {
3708
-				$img = vider_attribut($img, 'class');
3709
-			}
3710
-		}
3711
-	}
3712
-	else {
3713
-		$img = http_img_pack(
3714
-			$img,
3715
-			$alt,
3716
-			$class ? " class='" . attribut_html($class) . "'" : '',
3717
-			'',
3718
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3719
-		);
3720
-		if (is_null($alt)) {
3721
-			$img = vider_attribut($img, 'alt');
3722
-		}
3723
-	}
3724
-
3725
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3726
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3727
-
3728
-		$img = inserer_attribut($img, 'width', $width);
3729
-		$img = inserer_attribut($img, 'height', $height);
3730
-	}
3731
-
3732
-	return $img;
3696
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3697
+
3698
+    $img = trim((string) $img);
3699
+    if (strpos($img, '<img') === 0) {
3700
+        if (!is_null($alt)) {
3701
+            $img = inserer_attribut($img, 'alt', $alt);
3702
+        }
3703
+        if (!is_null($class)) {
3704
+            if (strlen($class)) {
3705
+                $img = inserer_attribut($img, 'class', $class);
3706
+            }
3707
+            else {
3708
+                $img = vider_attribut($img, 'class');
3709
+            }
3710
+        }
3711
+    }
3712
+    else {
3713
+        $img = http_img_pack(
3714
+            $img,
3715
+            $alt,
3716
+            $class ? " class='" . attribut_html($class) . "'" : '',
3717
+            '',
3718
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3719
+        );
3720
+        if (is_null($alt)) {
3721
+            $img = vider_attribut($img, 'alt');
3722
+        }
3723
+    }
3724
+
3725
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3726
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3727
+
3728
+        $img = inserer_attribut($img, 'width', $width);
3729
+        $img = inserer_attribut($img, 'height', $height);
3730
+    }
3731
+
3732
+    return $img;
3733 3733
 }
3734 3734
 
3735 3735
 
@@ -3763,80 +3763,80 @@  discard block
 block discarded – undo
3763 3763
  */
3764 3764
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3765 3765
 
3766
-	$svg = null;
3767
-	$img = trim($img);
3768
-	$img_file = $img;
3769
-	if (strpos($img, '<svg') === false) {
3770
-		if ($p = strpos($img_file, '?')) {
3771
-			$img_file = substr($img_file, 0, $p);
3772
-		}
3773
-
3774
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3775
-		// la copie locale a toutes les chances d'etre la ou de resservir
3776
-		if (tester_url_absolue($img_file)) {
3777
-			include_spip('inc/distant');
3778
-			$fichier = copie_locale($img_file);
3779
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3780
-		}
3781
-
3782
-		if (
3783
-			!$img_file
3784
-			or !file_exists($img_file)
3785
-			or !$svg = file_get_contents($img_file)
3786
-		) {
3787
-			return '';
3788
-		}
3789
-	}
3790
-
3791
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3792
-		return '';
3793
-	}
3794
-
3795
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3796
-
3797
-	$balise_svg = $match[0];
3798
-	$balise_svg_source = $balise_svg;
3799
-
3800
-	// entete XML à supprimer
3801
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3802
-
3803
-	// IE est toujours mon ami
3804
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3805
-
3806
-	// regler la classe
3807
-	if (!is_null($class)) {
3808
-		if (strlen($class)) {
3809
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3810
-		}
3811
-		else {
3812
-			$balise_svg = vider_attribut($balise_svg, 'class');
3813
-		}
3814
-	}
3815
-
3816
-	// regler le alt
3817
-	if ($alt) {
3818
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3819
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3820
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3821
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3822
-		$balise_svg .= $title;
3823
-	}
3824
-	else {
3825
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3826
-	}
3827
-
3828
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3829
-
3830
-	if (!is_null($size) and strlen($size = trim($size))) {
3831
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3832
-
3833
-		if (!function_exists('svg_redimensionner')) {
3834
-			include_spip('inc/svg');
3835
-		}
3836
-		$svg = svg_redimensionner($svg, $width, $height);
3837
-	}
3838
-
3839
-	return $svg;
3766
+    $svg = null;
3767
+    $img = trim($img);
3768
+    $img_file = $img;
3769
+    if (strpos($img, '<svg') === false) {
3770
+        if ($p = strpos($img_file, '?')) {
3771
+            $img_file = substr($img_file, 0, $p);
3772
+        }
3773
+
3774
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3775
+        // la copie locale a toutes les chances d'etre la ou de resservir
3776
+        if (tester_url_absolue($img_file)) {
3777
+            include_spip('inc/distant');
3778
+            $fichier = copie_locale($img_file);
3779
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3780
+        }
3781
+
3782
+        if (
3783
+            !$img_file
3784
+            or !file_exists($img_file)
3785
+            or !$svg = file_get_contents($img_file)
3786
+        ) {
3787
+            return '';
3788
+        }
3789
+    }
3790
+
3791
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3792
+        return '';
3793
+    }
3794
+
3795
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3796
+
3797
+    $balise_svg = $match[0];
3798
+    $balise_svg_source = $balise_svg;
3799
+
3800
+    // entete XML à supprimer
3801
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3802
+
3803
+    // IE est toujours mon ami
3804
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3805
+
3806
+    // regler la classe
3807
+    if (!is_null($class)) {
3808
+        if (strlen($class)) {
3809
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3810
+        }
3811
+        else {
3812
+            $balise_svg = vider_attribut($balise_svg, 'class');
3813
+        }
3814
+    }
3815
+
3816
+    // regler le alt
3817
+    if ($alt) {
3818
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3819
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3820
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3821
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3822
+        $balise_svg .= $title;
3823
+    }
3824
+    else {
3825
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3826
+    }
3827
+
3828
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3829
+
3830
+    if (!is_null($size) and strlen($size = trim($size))) {
3831
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3832
+
3833
+        if (!function_exists('svg_redimensionner')) {
3834
+            include_spip('inc/svg');
3835
+        }
3836
+        $svg = svg_redimensionner($svg, $width, $height);
3837
+    }
3838
+
3839
+    return $svg;
3840 3840
 }
3841 3841
 
3842 3842
 
@@ -3862,18 +3862,18 @@  discard block
 block discarded – undo
3862 3862
  *     Code HTML résultant
3863 3863
  **/
3864 3864
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3865
-	$texte = '';
3866
-	if (is_array($tableau)) {
3867
-		foreach ($tableau as $k => $v) {
3868
-			$res = recuperer_fond(
3869
-				'modeles/' . $modele,
3870
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3871
-			);
3872
-			$texte .= $res;
3873
-		}
3874
-	}
3865
+    $texte = '';
3866
+    if (is_array($tableau)) {
3867
+        foreach ($tableau as $k => $v) {
3868
+            $res = recuperer_fond(
3869
+                'modeles/' . $modele,
3870
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3871
+            );
3872
+            $texte .= $res;
3873
+        }
3874
+    }
3875 3875
 
3876
-	return $texte;
3876
+    return $texte;
3877 3877
 }
3878 3878
 
3879 3879
 
@@ -3898,37 +3898,37 @@  discard block
 block discarded – undo
3898 3898
  *         - tout : retourne toutes les informations du plugin actif
3899 3899
  **/
3900 3900
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3901
-	include_spip('inc/plugin');
3902
-	$plugin = strtoupper($plugin);
3903
-	$plugins_actifs = liste_plugin_actifs();
3904
-
3905
-	if (!$plugin) {
3906
-		return serialize(array_keys($plugins_actifs));
3907
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3908
-		return '';
3909
-	} elseif (($type_info == 'est_actif') and !$reload) {
3910
-		return $plugins_actifs[$plugin] ? 1 : 0;
3911
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3912
-		return $plugins_actifs[$plugin][$type_info];
3913
-	} else {
3914
-		$get_infos = charger_fonction('get_infos', 'plugins');
3915
-		// On prend en compte les extensions
3916
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3917
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3918
-		} else {
3919
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3920
-		}
3921
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3922
-			return '';
3923
-		}
3924
-		if ($type_info == 'tout') {
3925
-			return $infos;
3926
-		} elseif ($type_info == 'est_actif') {
3927
-			return $infos ? 1 : 0;
3928
-		} else {
3929
-			return strval($infos[$type_info]);
3930
-		}
3931
-	}
3901
+    include_spip('inc/plugin');
3902
+    $plugin = strtoupper($plugin);
3903
+    $plugins_actifs = liste_plugin_actifs();
3904
+
3905
+    if (!$plugin) {
3906
+        return serialize(array_keys($plugins_actifs));
3907
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3908
+        return '';
3909
+    } elseif (($type_info == 'est_actif') and !$reload) {
3910
+        return $plugins_actifs[$plugin] ? 1 : 0;
3911
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3912
+        return $plugins_actifs[$plugin][$type_info];
3913
+    } else {
3914
+        $get_infos = charger_fonction('get_infos', 'plugins');
3915
+        // On prend en compte les extensions
3916
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3917
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3918
+        } else {
3919
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3920
+        }
3921
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3922
+            return '';
3923
+        }
3924
+        if ($type_info == 'tout') {
3925
+            return $infos;
3926
+        } elseif ($type_info == 'est_actif') {
3927
+            return $infos ? 1 : 0;
3928
+        } else {
3929
+            return strval($infos[$type_info]);
3930
+        }
3931
+    }
3932 3932
 }
3933 3933
 
3934 3934
 
@@ -3955,9 +3955,9 @@  discard block
 block discarded – undo
3955 3955
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3956 3956
  */
3957 3957
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3958
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3958
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3959 3959
 
3960
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3960
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3961 3961
 }
3962 3962
 
3963 3963
 
@@ -3987,19 +3987,19 @@  discard block
 block discarded – undo
3987 3987
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3988 3988
  */
3989 3989
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3990
-	static $puce_statut = null;
3991
-	if (!$puce_statut) {
3992
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3993
-	}
3990
+    static $puce_statut = null;
3991
+    if (!$puce_statut) {
3992
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3993
+    }
3994 3994
 
3995
-	return $puce_statut(
3996
-		$id_objet,
3997
-		$statut,
3998
-		$id_parent,
3999
-		$objet,
4000
-		false,
4001
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
4002
-	);
3995
+    return $puce_statut(
3996
+        $id_objet,
3997
+        $statut,
3998
+        $id_parent,
3999
+        $objet,
4000
+        false,
4001
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
4002
+    );
4003 4003
 }
4004 4004
 
4005 4005
 
@@ -4026,98 +4026,98 @@  discard block
 block discarded – undo
4026 4026
  *   hash du contexte
4027 4027
  */
4028 4028
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
4029
-	$env = null;
4030
-	if (
4031
-		is_string($c)
4032
-		and @unserialize($c) !== false
4033
-	) {
4034
-		$c = unserialize($c);
4035
-	}
4036
-
4037
-	// supprimer les parametres debut_x
4038
-	// pour que la pagination ajax ne soit pas plantee
4039
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
4040
-	// le debut_x=0 n'existe pas, et on resterait sur 1
4041
-	if (is_array($c)) {
4042
-		foreach ($c as $k => $v) {
4043
-			if (strpos($k, 'debut_') === 0) {
4044
-				unset($c[$k]);
4045
-			}
4046
-		}
4047
-	}
4048
-
4049
-	if (!function_exists('calculer_cle_action')) {
4050
-		include_spip('inc/securiser_action');
4051
-	}
4052
-
4053
-	$c = serialize($c);
4054
-	$cle = calculer_cle_action($form . $c);
4055
-	$c = "$cle:$c";
4056
-
4057
-	// on ne stocke pas les contextes dans des fichiers en cache
4058
-	// par defaut, sauf si cette configuration a été forcée
4059
-	// OU que la longueur de l’argument géneré est plus long
4060
-	// que ce qui est toléré.
4061
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4062
-	if (!$cache_contextes_ajax) {
4063
-		$env = $c;
4064
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4065
-			$env = gzdeflate($env);
4066
-		}
4067
-		$env = _xor($env);
4068
-		$env = base64_encode($env);
4069
-		$len = strlen($env);
4070
-		// Si l’url est trop longue pour le navigateur
4071
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4072
-		if ($len > $max_len) {
4073
-			$cache_contextes_ajax = true;
4074
-			spip_log(
4075
-				'Contextes AJAX forces en fichiers !'
4076
-				. ' Cela arrive lorsque la valeur du contexte'
4077
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4078
-				_LOG_AVERTISSEMENT
4079
-			);
4080
-		}
4081
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4082
-		elseif (
4083
-			$max_len = @ini_get('suhosin.get.max_value_length')
4084
-			and $max_len < $len
4085
-		) {
4086
-			$cache_contextes_ajax = true;
4087
-			spip_log('Contextes AJAX forces en fichiers !'
4088
-				. ' Cela arrive lorsque la valeur du contexte'
4089
-				. ' depasse la longueur maximale autorisee par Suhosin'
4090
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4091
-				. ' Vous devriez modifier les parametres de Suhosin'
4092
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4093
-		}
4094
-	}
4095
-
4096
-	if ($cache_contextes_ajax) {
4097
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4098
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4099
-		$md5 = md5($c);
4100
-		ecrire_fichier("$dir/c$md5", $c);
4101
-		$env = $md5;
4102
-	}
4103
-
4104
-	if ($emboite === null) {
4105
-		return $env;
4106
-	}
4107
-	if (!trim($emboite)) {
4108
-		return '';
4109
-	}
4110
-	// toujours encoder l'url source dans le bloc ajax
4111
-	$r = self();
4112
-	$r = ' data-origin="' . $r . '"';
4113
-	$class = 'ajaxbloc';
4114
-	if ($ajaxid and is_string($ajaxid)) {
4115
-		// ajaxid est normalement conforme a un nom de classe css
4116
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4117
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4118
-	}
4119
-
4120
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4029
+    $env = null;
4030
+    if (
4031
+        is_string($c)
4032
+        and @unserialize($c) !== false
4033
+    ) {
4034
+        $c = unserialize($c);
4035
+    }
4036
+
4037
+    // supprimer les parametres debut_x
4038
+    // pour que la pagination ajax ne soit pas plantee
4039
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
4040
+    // le debut_x=0 n'existe pas, et on resterait sur 1
4041
+    if (is_array($c)) {
4042
+        foreach ($c as $k => $v) {
4043
+            if (strpos($k, 'debut_') === 0) {
4044
+                unset($c[$k]);
4045
+            }
4046
+        }
4047
+    }
4048
+
4049
+    if (!function_exists('calculer_cle_action')) {
4050
+        include_spip('inc/securiser_action');
4051
+    }
4052
+
4053
+    $c = serialize($c);
4054
+    $cle = calculer_cle_action($form . $c);
4055
+    $c = "$cle:$c";
4056
+
4057
+    // on ne stocke pas les contextes dans des fichiers en cache
4058
+    // par defaut, sauf si cette configuration a été forcée
4059
+    // OU que la longueur de l’argument géneré est plus long
4060
+    // que ce qui est toléré.
4061
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4062
+    if (!$cache_contextes_ajax) {
4063
+        $env = $c;
4064
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4065
+            $env = gzdeflate($env);
4066
+        }
4067
+        $env = _xor($env);
4068
+        $env = base64_encode($env);
4069
+        $len = strlen($env);
4070
+        // Si l’url est trop longue pour le navigateur
4071
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4072
+        if ($len > $max_len) {
4073
+            $cache_contextes_ajax = true;
4074
+            spip_log(
4075
+                'Contextes AJAX forces en fichiers !'
4076
+                . ' Cela arrive lorsque la valeur du contexte'
4077
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4078
+                _LOG_AVERTISSEMENT
4079
+            );
4080
+        }
4081
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4082
+        elseif (
4083
+            $max_len = @ini_get('suhosin.get.max_value_length')
4084
+            and $max_len < $len
4085
+        ) {
4086
+            $cache_contextes_ajax = true;
4087
+            spip_log('Contextes AJAX forces en fichiers !'
4088
+                . ' Cela arrive lorsque la valeur du contexte'
4089
+                . ' depasse la longueur maximale autorisee par Suhosin'
4090
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4091
+                . ' Vous devriez modifier les parametres de Suhosin'
4092
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4093
+        }
4094
+    }
4095
+
4096
+    if ($cache_contextes_ajax) {
4097
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4098
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4099
+        $md5 = md5($c);
4100
+        ecrire_fichier("$dir/c$md5", $c);
4101
+        $env = $md5;
4102
+    }
4103
+
4104
+    if ($emboite === null) {
4105
+        return $env;
4106
+    }
4107
+    if (!trim($emboite)) {
4108
+        return '';
4109
+    }
4110
+    // toujours encoder l'url source dans le bloc ajax
4111
+    $r = self();
4112
+    $r = ' data-origin="' . $r . '"';
4113
+    $class = 'ajaxbloc';
4114
+    if ($ajaxid and is_string($ajaxid)) {
4115
+        // ajaxid est normalement conforme a un nom de classe css
4116
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4117
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4118
+    }
4119
+
4120
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4121 4121
 }
4122 4122
 
4123 4123
 /**
@@ -4137,37 +4137,37 @@  discard block
 block discarded – undo
4137 4137
  *   - false : erreur de décodage
4138 4138
  */
4139 4139
 function decoder_contexte_ajax($c, $form = '') {
4140
-	if (!function_exists('calculer_cle_action')) {
4141
-		include_spip('inc/securiser_action');
4142
-	}
4143
-	if (
4144
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4145
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4146
-		and lire_fichier("$dir/c$c", $contexte)
4147
-	) {
4148
-		$c = $contexte;
4149
-	} else {
4150
-		$c = @base64_decode($c);
4151
-		$c = _xor($c);
4152
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4153
-			$c = @gzinflate($c);
4154
-		}
4155
-	}
4156
-
4157
-	// extraire la signature en debut de contexte
4158
-	// et la verifier avant de deserializer
4159
-	// format : signature:donneesserializees
4160
-	if ($p = strpos($c, ':')) {
4161
-		$cle = substr($c, 0, $p);
4162
-		$c = substr($c, $p + 1);
4163
-
4164
-		if ($cle == calculer_cle_action($form . $c)) {
4165
-			$env = @unserialize($c);
4166
-			return $env;
4167
-		}
4168
-	}
4169
-
4170
-	return false;
4140
+    if (!function_exists('calculer_cle_action')) {
4141
+        include_spip('inc/securiser_action');
4142
+    }
4143
+    if (
4144
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4145
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4146
+        and lire_fichier("$dir/c$c", $contexte)
4147
+    ) {
4148
+        $c = $contexte;
4149
+    } else {
4150
+        $c = @base64_decode($c);
4151
+        $c = _xor($c);
4152
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4153
+            $c = @gzinflate($c);
4154
+        }
4155
+    }
4156
+
4157
+    // extraire la signature en debut de contexte
4158
+    // et la verifier avant de deserializer
4159
+    // format : signature:donneesserializees
4160
+    if ($p = strpos($c, ':')) {
4161
+        $cle = substr($c, 0, $p);
4162
+        $c = substr($c, $p + 1);
4163
+
4164
+        if ($cle == calculer_cle_action($form . $c)) {
4165
+            $env = @unserialize($c);
4166
+            return $env;
4167
+        }
4168
+    }
4169
+
4170
+    return false;
4171 4171
 }
4172 4172
 
4173 4173
 
@@ -4185,20 +4185,20 @@  discard block
 block discarded – undo
4185 4185
  *    Message décrypté ou encrypté
4186 4186
  **/
4187 4187
 function _xor($message, $key = null) {
4188
-	if (is_null($key)) {
4189
-		if (!function_exists('calculer_cle_action')) {
4190
-			include_spip('inc/securiser_action');
4191
-		}
4192
-		$key = pack('H*', calculer_cle_action('_xor'));
4193
-	}
4188
+    if (is_null($key)) {
4189
+        if (!function_exists('calculer_cle_action')) {
4190
+            include_spip('inc/securiser_action');
4191
+        }
4192
+        $key = pack('H*', calculer_cle_action('_xor'));
4193
+    }
4194 4194
 
4195
-	$keylen = strlen($key);
4196
-	$messagelen = strlen($message);
4197
-	for ($i = 0; $i < $messagelen; $i++) {
4198
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4199
-	}
4195
+    $keylen = strlen($key);
4196
+    $messagelen = strlen($message);
4197
+    for ($i = 0; $i < $messagelen; $i++) {
4198
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4199
+    }
4200 4200
 
4201
-	return $message;
4201
+    return $message;
4202 4202
 }
4203 4203
 
4204 4204
 /**
@@ -4212,7 +4212,7 @@  discard block
 block discarded – undo
4212 4212
  * @return string
4213 4213
  */
4214 4214
 function url_reponse_forum($texte) {
4215
- return $texte;
4215
+    return $texte;
4216 4216
 }
4217 4217
 
4218 4218
 /**
@@ -4226,7 +4226,7 @@  discard block
 block discarded – undo
4226 4226
  * @return string
4227 4227
  */
4228 4228
 function url_rss_forum($texte) {
4229
- return $texte;
4229
+    return $texte;
4230 4230
 }
4231 4231
 
4232 4232
 
@@ -4265,37 +4265,37 @@  discard block
 block discarded – undo
4265 4265
  *   Code HTML
4266 4266
  */
4267 4267
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4268
-	if ($on) {
4269
-		$bal = 'strong';
4270
-		$class = '';
4271
-		$att = '';
4272
-		// si $on passe la balise et optionnelement une ou ++classe
4273
-		// a.active span.selected.active etc....
4274
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4275
-			$on = explode('.', $on);
4276
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4277
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4278
-				$bal = array_shift($on);
4279
-				$class = implode(' ', $on);
4280
-				if ($bal == 'a') {
4281
-					$att = 'href="#" ';
4282
-				}
4283
-			}
4284
-		}
4285
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4286
-	} else {
4287
-		$bal = 'a';
4288
-		$att = "href='$url'"
4289
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4290
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4291
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4292
-			. $evt;
4293
-	}
4294
-	if ($libelle === null) {
4295
-		$libelle = $url;
4296
-	}
4297
-
4298
-	return "<$bal $att>$libelle</$bal>";
4268
+    if ($on) {
4269
+        $bal = 'strong';
4270
+        $class = '';
4271
+        $att = '';
4272
+        // si $on passe la balise et optionnelement une ou ++classe
4273
+        // a.active span.selected.active etc....
4274
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4275
+            $on = explode('.', $on);
4276
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4277
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4278
+                $bal = array_shift($on);
4279
+                $class = implode(' ', $on);
4280
+                if ($bal == 'a') {
4281
+                    $att = 'href="#" ';
4282
+                }
4283
+            }
4284
+        }
4285
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4286
+    } else {
4287
+        $bal = 'a';
4288
+        $att = "href='$url'"
4289
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4290
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4291
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4292
+            . $evt;
4293
+    }
4294
+    if ($libelle === null) {
4295
+        $libelle = $url;
4296
+    }
4297
+
4298
+    return "<$bal $att>$libelle</$bal>";
4299 4299
 }
4300 4300
 
4301 4301
 
@@ -4312,39 +4312,39 @@  discard block
 block discarded – undo
4312 4312
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4313 4313
  */
4314 4314
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4315
-	static $local_singulier_ou_pluriel = [];
4316
-
4317
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4318
-	if (!is_numeric($nb) or $nb == 0) {
4319
-		return '';
4320
-	}
4321
-	if (!is_array($vars)) {
4322
-		return '';
4323
-	}
4324
-
4325
-	$langue = $GLOBALS['spip_lang'];
4326
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4327
-		$local_singulier_ou_pluriel[$langue] = false;
4328
-		if (
4329
-			$f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4330
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4331
-		) {
4332
-			$local_singulier_ou_pluriel[$langue] = $f;
4333
-		}
4334
-	}
4335
-
4336
-	// si on a une surcharge on l'utilise
4337
-	if ($local_singulier_ou_pluriel[$langue]) {
4338
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4339
-	}
4340
-
4341
-	// sinon traitement par defaut
4342
-	$vars[$var] = $nb;
4343
-	if ($nb >= 2) {
4344
-		return _T($chaine_plusieurs, $vars);
4345
-	} else {
4346
-		return _T($chaine_un, $vars);
4347
-	}
4315
+    static $local_singulier_ou_pluriel = [];
4316
+
4317
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4318
+    if (!is_numeric($nb) or $nb == 0) {
4319
+        return '';
4320
+    }
4321
+    if (!is_array($vars)) {
4322
+        return '';
4323
+    }
4324
+
4325
+    $langue = $GLOBALS['spip_lang'];
4326
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4327
+        $local_singulier_ou_pluriel[$langue] = false;
4328
+        if (
4329
+            $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4330
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4331
+        ) {
4332
+            $local_singulier_ou_pluriel[$langue] = $f;
4333
+        }
4334
+    }
4335
+
4336
+    // si on a une surcharge on l'utilise
4337
+    if ($local_singulier_ou_pluriel[$langue]) {
4338
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4339
+    }
4340
+
4341
+    // sinon traitement par defaut
4342
+    $vars[$var] = $nb;
4343
+    if ($nb >= 2) {
4344
+        return _T($chaine_plusieurs, $vars);
4345
+    } else {
4346
+        return _T($chaine_un, $vars);
4347
+    }
4348 4348
 }
4349 4349
 
4350 4350
 
@@ -4372,73 +4372,73 @@  discard block
 block discarded – undo
4372 4372
  */
4373 4373
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4374 4374
 
4375
-	$class_lien = $class_bouton = $class;
4376
-
4377
-	// Normaliser la fonction et compléter la classe en fonction
4378
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4379
-		$class_lien .= ' danger';
4380
-		$class_bouton .= ' btn_danger';
4381
-	} elseif ($fonction == 'rien.gif') {
4382
-		$fonction = '';
4383
-	} elseif ($fonction == 'delsafe') {
4384
-		$fonction = 'del';
4385
-	}
4386
-
4387
-	$fond_origine = $fond;
4388
-	// Remappage des icone : article-24.png+new => article-new-24.png
4389
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4390
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4391
-	}
4392
-
4393
-	// Ajouter le type d'objet dans la classe
4394
-	$objet_type = substr(basename($fond), 0, -4);
4395
-	$class_lien .= " $objet_type";
4396
-	$class_bouton .= " $objet_type";
4397
-
4398
-	// Texte
4399
-	$alt = attribut_html($texte);
4400
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4401
-
4402
-	// Liens : préparer les classes ajax
4403
-	$ajax = '';
4404
-	if ($type === 'lien') {
4405
-		if (strpos($class_lien, 'ajax') !== false) {
4406
-			$ajax = 'ajax';
4407
-			if (strpos($class_lien, 'preload') !== false) {
4408
-				$ajax .= ' preload';
4409
-			}
4410
-			if (strpos($class_lien, 'nocache') !== false) {
4411
-				$ajax .= ' nocache';
4412
-			}
4413
-			$ajax = " class='$ajax'";
4414
-		}
4415
-	}
4416
-
4417
-	// Repérer la taille et l'ajouter dans la classe
4418
-	$size = 24;
4419
-	if (
4420
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4421
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4422
-	) {
4423
-		$size = $match[1];
4424
-	}
4425
-	$class_lien .= " s$size";
4426
-	$class_bouton .= " s$size";
4427
-
4428
-	// Icône
4429
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4430
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4431
-
4432
-	// Markup final
4433
-	if ($type == 'lien') {
4434
-		return "<span class='icone $class_lien'>"
4435
-		. "<a href='$lien'$title$ajax$javascript>"
4436
-		. $icone
4437
-		. "<b>$texte</b>"
4438
-		. "</a></span>\n";
4439
-	} else {
4440
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4441
-	}
4375
+    $class_lien = $class_bouton = $class;
4376
+
4377
+    // Normaliser la fonction et compléter la classe en fonction
4378
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4379
+        $class_lien .= ' danger';
4380
+        $class_bouton .= ' btn_danger';
4381
+    } elseif ($fonction == 'rien.gif') {
4382
+        $fonction = '';
4383
+    } elseif ($fonction == 'delsafe') {
4384
+        $fonction = 'del';
4385
+    }
4386
+
4387
+    $fond_origine = $fond;
4388
+    // Remappage des icone : article-24.png+new => article-new-24.png
4389
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4390
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4391
+    }
4392
+
4393
+    // Ajouter le type d'objet dans la classe
4394
+    $objet_type = substr(basename($fond), 0, -4);
4395
+    $class_lien .= " $objet_type";
4396
+    $class_bouton .= " $objet_type";
4397
+
4398
+    // Texte
4399
+    $alt = attribut_html($texte);
4400
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4401
+
4402
+    // Liens : préparer les classes ajax
4403
+    $ajax = '';
4404
+    if ($type === 'lien') {
4405
+        if (strpos($class_lien, 'ajax') !== false) {
4406
+            $ajax = 'ajax';
4407
+            if (strpos($class_lien, 'preload') !== false) {
4408
+                $ajax .= ' preload';
4409
+            }
4410
+            if (strpos($class_lien, 'nocache') !== false) {
4411
+                $ajax .= ' nocache';
4412
+            }
4413
+            $ajax = " class='$ajax'";
4414
+        }
4415
+    }
4416
+
4417
+    // Repérer la taille et l'ajouter dans la classe
4418
+    $size = 24;
4419
+    if (
4420
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4421
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4422
+    ) {
4423
+        $size = $match[1];
4424
+    }
4425
+    $class_lien .= " s$size";
4426
+    $class_bouton .= " s$size";
4427
+
4428
+    // Icône
4429
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4430
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4431
+
4432
+    // Markup final
4433
+    if ($type == 'lien') {
4434
+        return "<span class='icone $class_lien'>"
4435
+        . "<a href='$lien'$title$ajax$javascript>"
4436
+        . $icone
4437
+        . "<b>$texte</b>"
4438
+        . "</a></span>\n";
4439
+    } else {
4440
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4441
+    }
4442 4442
 }
4443 4443
 
4444 4444
 /**
@@ -4462,7 +4462,7 @@  discard block
 block discarded – undo
4462 4462
  *     Code HTML du lien
4463 4463
  **/
4464 4464
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4465
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4465
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4466 4466
 }
4467 4467
 
4468 4468
 /**
@@ -4497,7 +4497,7 @@  discard block
 block discarded – undo
4497 4497
  *     Code HTML du lien
4498 4498
  **/
4499 4499
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4500
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4500
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4501 4501
 }
4502 4502
 
4503 4503
 /**
@@ -4542,7 +4542,7 @@  discard block
 block discarded – undo
4542 4542
  *     Code HTML du lien
4543 4543
  **/
4544 4544
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4545
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4545
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4546 4546
 }
4547 4547
 
4548 4548
 /**
@@ -4573,7 +4573,7 @@  discard block
 block discarded – undo
4573 4573
  *     Code HTML du lien
4574 4574
  **/
4575 4575
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4576
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4576
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4577 4577
 }
4578 4578
 
4579 4579
 /**
@@ -4604,7 +4604,7 @@  discard block
 block discarded – undo
4604 4604
  *     Code HTML du lien
4605 4605
  */
4606 4606
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4607
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4607
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4608 4608
 }
4609 4609
 
4610 4610
 
@@ -4626,7 +4626,7 @@  discard block
 block discarded – undo
4626 4626
  * @return array Liste des éléments
4627 4627
  */
4628 4628
 function filtre_explode_dist($a, $b) {
4629
-	return explode($b, (string) $a);
4629
+    return explode($b, (string) $a);
4630 4630
 }
4631 4631
 
4632 4632
 /**
@@ -4647,7 +4647,7 @@  discard block
 block discarded – undo
4647 4647
  * @return string Texte
4648 4648
  */
4649 4649
 function filtre_implode_dist($a, $b) {
4650
-	return is_array($a) ? implode($b, $a) : $a;
4650
+    return is_array($a) ? implode($b, $a) : $a;
4651 4651
 }
4652 4652
 
4653 4653
 /**
@@ -4656,22 +4656,22 @@  discard block
 block discarded – undo
4656 4656
  * @return string Code CSS
4657 4657
  */
4658 4658
 function bando_images_background() {
4659
-	include_spip('inc/bandeau');
4660
-	// recuperer tous les boutons et leurs images
4661
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4659
+    include_spip('inc/bandeau');
4660
+    // recuperer tous les boutons et leurs images
4661
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4662 4662
 
4663
-	$res = '';
4664
-	foreach ($boutons as $page => $detail) {
4665
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4666
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4667
-			if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4668
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4669
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4670
-			}
4671
-		}
4672
-	}
4663
+    $res = '';
4664
+    foreach ($boutons as $page => $detail) {
4665
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4666
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4667
+            if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4668
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4669
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4670
+            }
4671
+        }
4672
+    }
4673 4673
 
4674
-	return $res;
4674
+    return $res;
4675 4675
 }
4676 4676
 
4677 4677
 /**
@@ -4696,27 +4696,27 @@  discard block
 block discarded – undo
4696 4696
  */
4697 4697
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4698 4698
 
4699
-	// Classes : dispatcher `ajax` sur le formulaire
4700
-	$class_form = '';
4701
-	if (strpos($class, 'ajax') !== false) {
4702
-		$class_form = 'ajax';
4703
-		$class = str_replace('ajax', '', $class);
4704
-	}
4705
-	$class_btn = 'submit ' . trim($class);
4699
+    // Classes : dispatcher `ajax` sur le formulaire
4700
+    $class_form = '';
4701
+    if (strpos($class, 'ajax') !== false) {
4702
+        $class_form = 'ajax';
4703
+        $class = str_replace('ajax', '', $class);
4704
+    }
4705
+    $class_btn = 'submit ' . trim($class);
4706 4706
 
4707
-	if ($confirm) {
4708
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4709
-		if ($callback) {
4710
-			$callback = "$confirm?($callback):false";
4711
-		} else {
4712
-			$callback = $confirm;
4713
-		}
4714
-	}
4715
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4716
-	$title = $title ? " title='$title'" : '';
4707
+    if ($confirm) {
4708
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4709
+        if ($callback) {
4710
+            $callback = "$confirm?($callback):false";
4711
+        } else {
4712
+            $callback = $confirm;
4713
+        }
4714
+    }
4715
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4716
+    $title = $title ? " title='$title'" : '';
4717 4717
 
4718
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4719
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4718
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4719
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4720 4720
 }
4721 4721
 
4722 4722
 /**
@@ -4739,101 +4739,101 @@  discard block
 block discarded – undo
4739 4739
  * @return string
4740 4740
  */
4741 4741
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4742
-	static $trouver_table = null;
4743
-	static $objets;
4744
-
4745
-	// On verifie qu'on a tout ce qu'il faut
4746
-	$id_objet = intval($id_objet);
4747
-	if (!($id_objet and $type_objet and $info)) {
4748
-		return '';
4749
-	}
4750
-
4751
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4752
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4753
-		return '';
4754
-	}
4755
-
4756
-	// Si on demande l'url, on retourne direct la fonction
4757
-	if ($info == 'url') {
4758
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4759
-	}
4760
-
4761
-	// Sinon on va tout chercher dans la table et on garde en memoire
4762
-	$demande_titre = ($info === 'titre');
4763
-	$demande_introduction = ($info === 'introduction');
4764
-
4765
-	// 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
4766
-	if (
4767
-		!isset($objets[$type_objet][$id_objet])
4768
-		or
4769
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4770
-	) {
4771
-		if (!$trouver_table) {
4772
-			$trouver_table = charger_fonction('trouver_table', 'base');
4773
-		}
4774
-		$desc = $trouver_table(table_objet_sql($type_objet));
4775
-		if (!$desc) {
4776
-			return $objets[$type_objet] = false;
4777
-		}
4778
-
4779
-		// Si on demande le titre, on le gere en interne
4780
-		$champ_titre = '';
4781
-		if ($demande_titre) {
4782
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4783
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4784
-		}
4785
-		include_spip('base/abstract_sql');
4786
-		include_spip('base/connect_sql');
4787
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4788
-			'*' . $champ_titre,
4789
-			$desc['table_sql'],
4790
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4791
-		);
4792
-
4793
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4794
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4795
-	}
4796
-
4797
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4798
-	// ajouter la longueur au début des params supplémentaires
4799
-	if ($demande_introduction) {
4800
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4801
-		array_unshift($params, $introduction_longueur);
4802
-	}
4803
-
4804
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4805
-	if (
4806
-		$generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4807
-		// @deprecated 4.1 generer_TRUC_TYPE
4808
-		or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4809
-	) {
4810
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4811
-	}
4812
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4813
-	elseif (
4814
-		$generer = charger_fonction("generer_objet_{$info}", '', true)
4815
-		// @deprecated 4.1 generer_TRUC_entite
4816
-		or $generer = charger_fonction("generer_{$info}_entite", '', true)
4817
-	) {
4818
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4819
-	} // Sinon on prend directement le champ SQL tel quel
4820
-	else {
4821
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4822
-	}
4823
-
4824
-	// On va ensuite appliquer les traitements automatiques si besoin
4825
-	if (!$etoile) {
4826
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4827
-		// mais ce fonctionnement est a ameliorer !
4828
-		$info_generee = appliquer_traitement_champ(
4829
-			$info_generee,
4830
-			$info,
4831
-			table_objet($type_objet),
4832
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4833
-		);
4834
-	}
4835
-
4836
-	return $info_generee;
4742
+    static $trouver_table = null;
4743
+    static $objets;
4744
+
4745
+    // On verifie qu'on a tout ce qu'il faut
4746
+    $id_objet = intval($id_objet);
4747
+    if (!($id_objet and $type_objet and $info)) {
4748
+        return '';
4749
+    }
4750
+
4751
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4752
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4753
+        return '';
4754
+    }
4755
+
4756
+    // Si on demande l'url, on retourne direct la fonction
4757
+    if ($info == 'url') {
4758
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4759
+    }
4760
+
4761
+    // Sinon on va tout chercher dans la table et on garde en memoire
4762
+    $demande_titre = ($info === 'titre');
4763
+    $demande_introduction = ($info === 'introduction');
4764
+
4765
+    // 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
4766
+    if (
4767
+        !isset($objets[$type_objet][$id_objet])
4768
+        or
4769
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4770
+    ) {
4771
+        if (!$trouver_table) {
4772
+            $trouver_table = charger_fonction('trouver_table', 'base');
4773
+        }
4774
+        $desc = $trouver_table(table_objet_sql($type_objet));
4775
+        if (!$desc) {
4776
+            return $objets[$type_objet] = false;
4777
+        }
4778
+
4779
+        // Si on demande le titre, on le gere en interne
4780
+        $champ_titre = '';
4781
+        if ($demande_titre) {
4782
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4783
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4784
+        }
4785
+        include_spip('base/abstract_sql');
4786
+        include_spip('base/connect_sql');
4787
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4788
+            '*' . $champ_titre,
4789
+            $desc['table_sql'],
4790
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4791
+        );
4792
+
4793
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4794
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4795
+    }
4796
+
4797
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4798
+    // ajouter la longueur au début des params supplémentaires
4799
+    if ($demande_introduction) {
4800
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4801
+        array_unshift($params, $introduction_longueur);
4802
+    }
4803
+
4804
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4805
+    if (
4806
+        $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4807
+        // @deprecated 4.1 generer_TRUC_TYPE
4808
+        or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4809
+    ) {
4810
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4811
+    }
4812
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4813
+    elseif (
4814
+        $generer = charger_fonction("generer_objet_{$info}", '', true)
4815
+        // @deprecated 4.1 generer_TRUC_entite
4816
+        or $generer = charger_fonction("generer_{$info}_entite", '', true)
4817
+    ) {
4818
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4819
+    } // Sinon on prend directement le champ SQL tel quel
4820
+    else {
4821
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4822
+    }
4823
+
4824
+    // On va ensuite appliquer les traitements automatiques si besoin
4825
+    if (!$etoile) {
4826
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4827
+        // mais ce fonctionnement est a ameliorer !
4828
+        $info_generee = appliquer_traitement_champ(
4829
+            $info_generee,
4830
+            $info,
4831
+            table_objet($type_objet),
4832
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4833
+        );
4834
+    }
4835
+
4836
+    return $info_generee;
4837 4837
 }
4838 4838
 
4839 4839
 /**
@@ -4841,7 +4841,7 @@  discard block
 block discarded – undo
4841 4841
  * @see generer_objet_info
4842 4842
  */
4843 4843
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4844
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4844
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4845 4845
 }
4846 4846
 
4847 4847
 /**
@@ -4874,36 +4874,36 @@  discard block
 block discarded – undo
4874 4874
  */
4875 4875
 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 {
4876 4876
 
4877
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4878
-	$texte = $ligne_sql['texte'] ?? '';
4879
-	// En absence de descriptif, on se rabat sur chapo + texte
4880
-	if (isset($ligne_sql['chapo'])) {
4881
-		$chapo = $ligne_sql['chapo'];
4882
-		$texte = strlen($descriptif) ?
4883
-			'' :
4884
-			"$chapo \n\n $texte";
4885
-	}
4877
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4878
+    $texte = $ligne_sql['texte'] ?? '';
4879
+    // En absence de descriptif, on se rabat sur chapo + texte
4880
+    if (isset($ligne_sql['chapo'])) {
4881
+        $chapo = $ligne_sql['chapo'];
4882
+        $texte = strlen($descriptif) ?
4883
+            '' :
4884
+            "$chapo \n\n $texte";
4885
+    }
4886 4886
 
4887
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4888
-	if (!intval($longueur_ou_suite)) {
4889
-		$longueur = intval($introduction_longueur ?: 600);
4890
-	} else {
4891
-		$longueur = intval($longueur_ou_suite);
4892
-	}
4887
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4888
+    if (!intval($longueur_ou_suite)) {
4889
+        $longueur = intval($introduction_longueur ?: 600);
4890
+    } else {
4891
+        $longueur = intval($longueur_ou_suite);
4892
+    }
4893 4893
 
4894
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4895
-	// Ex : #INTRODUCTION{...}
4896
-	if (
4897
-		is_null($suite)
4898
-		and !intval($longueur_ou_suite)
4899
-	) {
4900
-		$suite = $longueur_ou_suite;
4901
-	}
4894
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4895
+    // Ex : #INTRODUCTION{...}
4896
+    if (
4897
+        is_null($suite)
4898
+        and !intval($longueur_ou_suite)
4899
+    ) {
4900
+        $suite = $longueur_ou_suite;
4901
+    }
4902 4902
 
4903
-	$f = chercher_filtre('introduction');
4904
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4903
+    $f = chercher_filtre('introduction');
4904
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4905 4905
 
4906
-	return $introduction;
4906
+    return $introduction;
4907 4907
 }
4908 4908
 
4909 4909
 /**
@@ -4911,7 +4911,7 @@  discard block
 block discarded – undo
4911 4911
  * @see generer_objet_introduction
4912 4912
  */
4913 4913
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4914
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4914
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4915 4915
 }
4916 4916
 
4917 4917
 /**
@@ -4925,49 +4925,49 @@  discard block
 block discarded – undo
4925 4925
  * @return string
4926 4926
  */
4927 4927
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4928
-	if (!$champ) {
4929
-		return $texte;
4930
-	}
4928
+    if (!$champ) {
4929
+        return $texte;
4930
+    }
4931 4931
 
4932
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4933
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4934
-	include_fichiers_fonctions();
4932
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4933
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4934
+    include_fichiers_fonctions();
4935 4935
 
4936
-	$champ = strtoupper($champ);
4937
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4938
-	if (!$traitements or !is_array($traitements)) {
4939
-		return $texte;
4940
-	}
4936
+    $champ = strtoupper($champ);
4937
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4938
+    if (!$traitements or !is_array($traitements)) {
4939
+        return $texte;
4940
+    }
4941 4941
 
4942
-	$traitement = '';
4943
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4944
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4945
-		$table_objet = table_objet($table_objet);
4946
-		if (isset($traitements[$table_objet])) {
4947
-			$traitement = $traitements[$table_objet];
4948
-		}
4949
-	}
4950
-	if (!$traitement and isset($traitements[0])) {
4951
-		$traitement = $traitements[0];
4952
-	}
4953
-	// (sinon prendre le premier de la liste par defaut ?)
4942
+    $traitement = '';
4943
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4944
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4945
+        $table_objet = table_objet($table_objet);
4946
+        if (isset($traitements[$table_objet])) {
4947
+            $traitement = $traitements[$table_objet];
4948
+        }
4949
+    }
4950
+    if (!$traitement and isset($traitements[0])) {
4951
+        $traitement = $traitements[0];
4952
+    }
4953
+    // (sinon prendre le premier de la liste par defaut ?)
4954 4954
 
4955
-	if (!$traitement) {
4956
-		return $texte;
4957
-	}
4955
+    if (!$traitement) {
4956
+        return $texte;
4957
+    }
4958 4958
 
4959
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4959
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4960 4960
 
4961
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4962
-	if (test_espace_prive()) {
4963
-		$env['espace_prive'] = 1;
4964
-	}
4961
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4962
+    if (test_espace_prive()) {
4963
+        $env['espace_prive'] = 1;
4964
+    }
4965 4965
 
4966
-	// Fournir $connect et $Pile[0] au traitement si besoin
4967
-	$Pile = [0 => $env];
4968
-	eval("\$texte = $traitement;");
4966
+    // Fournir $connect et $Pile[0] au traitement si besoin
4967
+    $Pile = [0 => $env];
4968
+    eval("\$texte = $traitement;");
4969 4969
 
4970
-	return $texte;
4970
+    return $texte;
4971 4971
 }
4972 4972
 
4973 4973
 
@@ -4981,21 +4981,21 @@  discard block
 block discarded – undo
4981 4981
  * @return string
4982 4982
  */
4983 4983
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4984
-	include_spip('inc/liens');
4985
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4986
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4987
-	// le raccourcis n'est plus valide
4988
-	$titre = typo($titre['titre'] ?? '');
4989
-	// on essaye avec generer_info_entite ?
4990
-	if (!strlen($titre) and !$connect) {
4991
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4992
-	}
4993
-	if (!strlen($titre)) {
4994
-		$titre = _T('info_sans_titre');
4995
-	}
4996
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4984
+    include_spip('inc/liens');
4985
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4986
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4987
+    // le raccourcis n'est plus valide
4988
+    $titre = typo($titre['titre'] ?? '');
4989
+    // on essaye avec generer_info_entite ?
4990
+    if (!strlen($titre) and !$connect) {
4991
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4992
+    }
4993
+    if (!strlen($titre)) {
4994
+        $titre = _T('info_sans_titre');
4995
+    }
4996
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4997 4997
 
4998
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4998
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4999 4999
 }
5000 5000
 
5001 5001
 /**
@@ -5003,7 +5003,7 @@  discard block
 block discarded – undo
5003 5003
  * @see generer_objet_lien
5004 5004
  */
5005 5005
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
5006
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
5006
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
5007 5007
 }
5008 5008
 
5009 5009
 /**
@@ -5019,15 +5019,15 @@  discard block
 block discarded – undo
5019 5019
  * @return string
5020 5020
  */
5021 5021
 function wrap($texte, $wrap) {
5022
-	$balises = extraire_balises($wrap);
5023
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
5024
-		$texte = $wrap . $texte;
5025
-		$regs = array_reverse($regs[1]);
5026
-		$wrap = '</' . implode('></', $regs) . '>';
5027
-		$texte = $texte . $wrap;
5028
-	}
5022
+    $balises = extraire_balises($wrap);
5023
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
5024
+        $texte = $wrap . $texte;
5025
+        $regs = array_reverse($regs[1]);
5026
+        $wrap = '</' . implode('></', $regs) . '>';
5027
+        $texte = $texte . $wrap;
5028
+    }
5029 5029
 
5030
-	return $texte;
5030
+    return $texte;
5031 5031
 }
5032 5032
 
5033 5033
 
@@ -5047,44 +5047,44 @@  discard block
 block discarded – undo
5047 5047
  * @return array|mixed|string
5048 5048
  */
5049 5049
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
5050
-	if (is_string($u)) {
5051
-		$u = typo($u);
5050
+    if (is_string($u)) {
5051
+        $u = typo($u);
5052 5052
 
5053
-		return $u;
5054
-	}
5053
+        return $u;
5054
+    }
5055 5055
 
5056
-	// caster $u en array si besoin
5057
-	if (is_object($u)) {
5058
-		$u = (array)$u;
5059
-	}
5056
+    // caster $u en array si besoin
5057
+    if (is_object($u)) {
5058
+        $u = (array)$u;
5059
+    }
5060 5060
 
5061
-	if (is_array($u)) {
5062
-		$out = '';
5063
-		// toutes les cles sont numeriques ?
5064
-		// et aucun enfant n'est un tableau
5065
-		// liste simple separee par des virgules
5066
-		$numeric_keys = array_map('is_numeric', array_keys($u));
5067
-		$array_values = array_map('is_array', $u);
5068
-		$object_values = array_map('is_object', $u);
5069
-		if (
5070
-			array_sum($numeric_keys) == count($numeric_keys)
5071
-			and !array_sum($array_values)
5072
-			and !array_sum($object_values)
5073
-		) {
5074
-			return join(', ', array_map('filtre_print_dist', $u));
5075
-		}
5061
+    if (is_array($u)) {
5062
+        $out = '';
5063
+        // toutes les cles sont numeriques ?
5064
+        // et aucun enfant n'est un tableau
5065
+        // liste simple separee par des virgules
5066
+        $numeric_keys = array_map('is_numeric', array_keys($u));
5067
+        $array_values = array_map('is_array', $u);
5068
+        $object_values = array_map('is_object', $u);
5069
+        if (
5070
+            array_sum($numeric_keys) == count($numeric_keys)
5071
+            and !array_sum($array_values)
5072
+            and !array_sum($object_values)
5073
+        ) {
5074
+            return join(', ', array_map('filtre_print_dist', $u));
5075
+        }
5076 5076
 
5077
-		// sinon on passe a la ligne et on indente
5078
-		$i_str = str_pad('', $indent, ' ');
5079
-		foreach ($u as $k => $v) {
5080
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5081
-		}
5077
+        // sinon on passe a la ligne et on indente
5078
+        $i_str = str_pad('', $indent, ' ');
5079
+        foreach ($u as $k => $v) {
5080
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5081
+        }
5082 5082
 
5083
-		return $out;
5084
-	}
5083
+        return $out;
5084
+    }
5085 5085
 
5086
-	// on sait pas quoi faire...
5087
-	return $u;
5086
+    // on sait pas quoi faire...
5087
+    return $u;
5088 5088
 }
5089 5089
 
5090 5090
 
@@ -5097,10 +5097,10 @@  discard block
 block discarded – undo
5097 5097
  * @return string|array
5098 5098
  */
5099 5099
 function objet_info($objet, $info) {
5100
-	$table = table_objet_sql($objet);
5101
-	$infos = lister_tables_objets_sql($table);
5100
+    $table = table_objet_sql($objet);
5101
+    $infos = lister_tables_objets_sql($table);
5102 5102
 
5103
-	return ($infos[$info] ?? '');
5103
+    return ($infos[$info] ?? '');
5104 5104
 }
5105 5105
 
5106 5106
 /**
@@ -5115,11 +5115,11 @@  discard block
 block discarded – undo
5115 5115
  *     Texte traduit du comptage, tel que '3 articles'
5116 5116
  */
5117 5117
 function objet_afficher_nb($nb, $objet) {
5118
-	if (!$nb) {
5119
-		return _T(objet_info($objet, 'info_aucun_objet'));
5120
-	} else {
5121
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5122
-	}
5118
+    if (!$nb) {
5119
+        return _T(objet_info($objet, 'info_aucun_objet'));
5120
+    } else {
5121
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5122
+    }
5123 5123
 }
5124 5124
 
5125 5125
 /**
@@ -5131,11 +5131,11 @@  discard block
 block discarded – undo
5131 5131
  * @return string
5132 5132
  */
5133 5133
 function objet_icone($objet, $taille = 24, $class = '') {
5134
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5135
-	$icone = chemin_image($icone);
5136
-	$balise_img = charger_filtre('balise_img');
5134
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5135
+    $icone = chemin_image($icone);
5136
+    $balise_img = charger_filtre('balise_img');
5137 5137
 
5138
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5138
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5139 5139
 }
5140 5140
 
5141 5141
 /**
@@ -5156,12 +5156,12 @@  discard block
 block discarded – undo
5156 5156
  * @return string
5157 5157
  */
5158 5158
 function objet_T($objet, $chaine, $args = [], $options = []) {
5159
-	$chaine = explode(':', $chaine);
5160
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5161
-		return $t;
5162
-	}
5163
-	$chaine = implode(':', $chaine);
5164
-	return _T($chaine, $args, $options);
5159
+    $chaine = explode(':', $chaine);
5160
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5161
+        return $t;
5162
+    }
5163
+    $chaine = implode(':', $chaine);
5164
+    return _T($chaine, $args, $options);
5165 5165
 }
5166 5166
 
5167 5167
 /**
@@ -5175,18 +5175,18 @@  discard block
 block discarded – undo
5175 5175
  * @return string      Code HTML
5176 5176
  */
5177 5177
 function insert_head_css_conditionnel($flux) {
5178
-	if (
5179
-		strpos($flux, '<!-- insert_head_css -->') === false
5180
-		and $p = strpos($flux, '<!-- insert_head -->')
5181
-	) {
5182
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5183
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5184
-			$p = $p1;
5185
-		}
5186
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5187
-	}
5178
+    if (
5179
+        strpos($flux, '<!-- insert_head_css -->') === false
5180
+        and $p = strpos($flux, '<!-- insert_head -->')
5181
+    ) {
5182
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5183
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5184
+            $p = $p1;
5185
+        }
5186
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5187
+    }
5188 5188
 
5189
-	return $flux;
5189
+    return $flux;
5190 5190
 }
5191 5191
 
5192 5192
 /**
@@ -5209,75 +5209,75 @@  discard block
 block discarded – undo
5209 5209
  * @return string
5210 5210
  */
5211 5211
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5212
-	if (isset($contexte['format'])) {
5213
-		$extension = $contexte['format'];
5214
-		unset($contexte['format']);
5215
-	} else {
5216
-		$extension = 'html';
5217
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5218
-			$extension = $m[1];
5219
-		}
5220
-	}
5221
-	// recuperer le contenu produit par le squelette
5222
-	$options['raw'] = true;
5223
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5224
-
5225
-	// calculer le nom de la css
5226
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5227
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5228
-	$contexte_implicite = calculer_contexte_implicite();
5229
-
5230
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5231
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5232
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5233
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5234
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5235
-	}
5236
-	else {
5237
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5238
-		ksort($contexte);
5239
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5240
-	}
5241
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5242
-
5243
-	// mettre a jour le fichier si il n'existe pas
5244
-	// ou trop ancien
5245
-	// le dernier fichier produit est toujours suffixe par .last
5246
-	// et recopie sur le fichier cible uniquement si il change
5247
-	if (
5248
-		!file_exists($filename)
5249
-		or !file_exists($filename . '.last')
5250
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5251
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5252
-	) {
5253
-		$contenu = $cache['texte'];
5254
-		// passer les urls en absolu si c'est une css
5255
-		if ($extension == 'css') {
5256
-			$contenu = urls_absolues_css(
5257
-				$contenu,
5258
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5259
-			);
5260
-		}
5261
-
5262
-		$comment = '';
5263
-		// ne pas insérer de commentaire sur certains formats
5264
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5265
-			$comment = "/* #PRODUIRE{fond=$fond";
5266
-			foreach ($contexte as $k => $v) {
5267
-				if (is_array($v)) {
5268
-					$v = var_export($v, true);
5269
-				}
5270
-				$comment .= ",$k=$v";
5271
-			}
5272
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5273
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5274
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5275
-		}
5276
-		// et ecrire le fichier si il change
5277
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5278
-	}
5279
-
5280
-	return timestamp($filename);
5212
+    if (isset($contexte['format'])) {
5213
+        $extension = $contexte['format'];
5214
+        unset($contexte['format']);
5215
+    } else {
5216
+        $extension = 'html';
5217
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5218
+            $extension = $m[1];
5219
+        }
5220
+    }
5221
+    // recuperer le contenu produit par le squelette
5222
+    $options['raw'] = true;
5223
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5224
+
5225
+    // calculer le nom de la css
5226
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5227
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5228
+    $contexte_implicite = calculer_contexte_implicite();
5229
+
5230
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5231
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5232
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5233
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5234
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5235
+    }
5236
+    else {
5237
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5238
+        ksort($contexte);
5239
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5240
+    }
5241
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5242
+
5243
+    // mettre a jour le fichier si il n'existe pas
5244
+    // ou trop ancien
5245
+    // le dernier fichier produit est toujours suffixe par .last
5246
+    // et recopie sur le fichier cible uniquement si il change
5247
+    if (
5248
+        !file_exists($filename)
5249
+        or !file_exists($filename . '.last')
5250
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5251
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5252
+    ) {
5253
+        $contenu = $cache['texte'];
5254
+        // passer les urls en absolu si c'est une css
5255
+        if ($extension == 'css') {
5256
+            $contenu = urls_absolues_css(
5257
+                $contenu,
5258
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5259
+            );
5260
+        }
5261
+
5262
+        $comment = '';
5263
+        // ne pas insérer de commentaire sur certains formats
5264
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5265
+            $comment = "/* #PRODUIRE{fond=$fond";
5266
+            foreach ($contexte as $k => $v) {
5267
+                if (is_array($v)) {
5268
+                    $v = var_export($v, true);
5269
+                }
5270
+                $comment .= ",$k=$v";
5271
+            }
5272
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5273
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5274
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5275
+        }
5276
+        // et ecrire le fichier si il change
5277
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5278
+    }
5279
+
5280
+    return timestamp($filename);
5281 5281
 }
5282 5282
 
5283 5283
 /**
@@ -5290,15 +5290,15 @@  discard block
 block discarded – undo
5290 5290
  *    $fichier auquel on a ajouté le timestamp
5291 5291
  */
5292 5292
 function timestamp($fichier) {
5293
-	if (
5294
-		!$fichier
5295
-		or !file_exists($fichier)
5296
-		or !$m = filemtime($fichier)
5297
-	) {
5298
-		return $fichier;
5299
-	}
5293
+    if (
5294
+        !$fichier
5295
+        or !file_exists($fichier)
5296
+        or !$m = filemtime($fichier)
5297
+    ) {
5298
+        return $fichier;
5299
+    }
5300 5300
 
5301
-	return "$fichier?$m";
5301
+    return "$fichier?$m";
5302 5302
 }
5303 5303
 
5304 5304
 /**
@@ -5308,11 +5308,11 @@  discard block
 block discarded – undo
5308 5308
  * @return string
5309 5309
  */
5310 5310
 function supprimer_timestamp($url) {
5311
-	if (strpos($url, '?') === false) {
5312
-		return $url;
5313
-	}
5311
+    if (strpos($url, '?') === false) {
5312
+        return $url;
5313
+    }
5314 5314
 
5315
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5315
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5316 5316
 }
5317 5317
 
5318 5318
 /**
@@ -5327,15 +5327,15 @@  discard block
 block discarded – undo
5327 5327
  * @return string
5328 5328
  */
5329 5329
 function filtre_nettoyer_titre_email_dist($titre) {
5330
-	include_spip('inc/envoyer_mail');
5330
+    include_spip('inc/envoyer_mail');
5331 5331
 
5332
-	$titre = nettoyer_titre_email($titre);
5333
-	// on est dans un squelette : securiser le retour
5334
-	if (strpos($titre, '<') !== false) {
5335
-		$titre = interdire_scripts($titre);
5336
-	}
5332
+    $titre = nettoyer_titre_email($titre);
5333
+    // on est dans un squelette : securiser le retour
5334
+    if (strpos($titre, '<') !== false) {
5335
+        $titre = interdire_scripts($titre);
5336
+    }
5337 5337
 
5338
-	return $titre;
5338
+    return $titre;
5339 5339
 }
5340 5340
 
5341 5341
 /**
@@ -5357,27 +5357,27 @@  discard block
 block discarded – undo
5357 5357
  * @return string
5358 5358
  */
5359 5359
 function filtre_chercher_rubrique_dist(
5360
-	$titre,
5361
-	$id_objet,
5362
-	$id_parent,
5363
-	$objet,
5364
-	$id_secteur,
5365
-	$restreint,
5366
-	$actionable = false,
5367
-	$retour_sans_cadre = false
5360
+    $titre,
5361
+    $id_objet,
5362
+    $id_parent,
5363
+    $objet,
5364
+    $id_secteur,
5365
+    $restreint,
5366
+    $actionable = false,
5367
+    $retour_sans_cadre = false
5368 5368
 ) {
5369
-	include_spip('inc/filtres_ecrire');
5369
+    include_spip('inc/filtres_ecrire');
5370 5370
 
5371
-	return chercher_rubrique(
5372
-		$titre,
5373
-		$id_objet,
5374
-		$id_parent,
5375
-		$objet,
5376
-		$id_secteur,
5377
-		$restreint,
5378
-		$actionable,
5379
-		$retour_sans_cadre
5380
-	);
5371
+    return chercher_rubrique(
5372
+        $titre,
5373
+        $id_objet,
5374
+        $id_parent,
5375
+        $objet,
5376
+        $id_secteur,
5377
+        $restreint,
5378
+        $actionable,
5379
+        $retour_sans_cadre
5380
+    );
5381 5381
 }
5382 5382
 
5383 5383
 /**
@@ -5406,56 +5406,56 @@  discard block
 block discarded – undo
5406 5406
  *     Chaîne vide si l'accès est autorisé
5407 5407
  */
5408 5408
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5409
-	if ($ok) {
5410
-		return '';
5411
-	}
5412
-
5413
-	// Vider tous les tampons
5414
-	$level = @ob_get_level();
5415
-	while ($level--) {
5416
-		@ob_end_clean();
5417
-	}
5418
-
5419
-	include_spip('inc/headers');
5420
-
5421
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5422
-	if ($url) {
5423
-		redirige_par_entete($url, '', $statut);
5424
-	}
5425
-
5426
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5427
-	if (!is_numeric($statut) and is_null($message)) {
5428
-		$message = $statut;
5429
-		$statut = 0;
5430
-	}
5431
-	if (!$message) {
5432
-		$message = '';
5433
-	}
5434
-	$statut = intval($statut);
5435
-
5436
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5437
-	if (test_espace_prive()) {
5438
-		if (!$statut or !in_array($statut, [404, 403])) {
5439
-			$statut = 403;
5440
-		}
5441
-		http_response_code(403);
5442
-		$echec = charger_fonction('403', 'exec');
5443
-		$echec($message);
5444
-	} else {
5445
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5446
-		if (!$statut) {
5447
-			$statut = 404;
5448
-		}
5449
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5450
-		http_response_code($statut);
5451
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5452
-		if ($statut >= 400) {
5453
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5454
-		}
5455
-	}
5456
-
5457
-
5458
-	exit;
5409
+    if ($ok) {
5410
+        return '';
5411
+    }
5412
+
5413
+    // Vider tous les tampons
5414
+    $level = @ob_get_level();
5415
+    while ($level--) {
5416
+        @ob_end_clean();
5417
+    }
5418
+
5419
+    include_spip('inc/headers');
5420
+
5421
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5422
+    if ($url) {
5423
+        redirige_par_entete($url, '', $statut);
5424
+    }
5425
+
5426
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5427
+    if (!is_numeric($statut) and is_null($message)) {
5428
+        $message = $statut;
5429
+        $statut = 0;
5430
+    }
5431
+    if (!$message) {
5432
+        $message = '';
5433
+    }
5434
+    $statut = intval($statut);
5435
+
5436
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5437
+    if (test_espace_prive()) {
5438
+        if (!$statut or !in_array($statut, [404, 403])) {
5439
+            $statut = 403;
5440
+        }
5441
+        http_response_code(403);
5442
+        $echec = charger_fonction('403', 'exec');
5443
+        $echec($message);
5444
+    } else {
5445
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5446
+        if (!$statut) {
5447
+            $statut = 404;
5448
+        }
5449
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5450
+        http_response_code($statut);
5451
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5452
+        if ($statut >= 400) {
5453
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5454
+        }
5455
+    }
5456
+
5457
+
5458
+    exit;
5459 5459
 }
5460 5460
 
5461 5461
 /**
@@ -5466,11 +5466,11 @@  discard block
 block discarded – undo
5466 5466
  * @return string
5467 5467
  */
5468 5468
 function filtre_compacte_dist($source, $format = null) {
5469
-	if (function_exists('minifier')) {
5470
-		return minifier($source, $format);
5471
-	}
5469
+    if (function_exists('minifier')) {
5470
+        return minifier($source, $format);
5471
+    }
5472 5472
 
5473
-	return $source;
5473
+    return $source;
5474 5474
 }
5475 5475
 
5476 5476
 
@@ -5482,32 +5482,32 @@  discard block
 block discarded – undo
5482 5482
  * @return string
5483 5483
  */
5484 5484
 function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5485
-	$passe ??= '';
5486
-	$l = strlen($passe);
5487
-
5488
-	if ($l <= 8 or !$afficher_partiellement) {
5489
-		if (!$l) {
5490
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5491
-		}
5492
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5493
-	}
5494
-
5495
-	if (is_null($portion_pourcent)) {
5496
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5497
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5498
-		}
5499
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5500
-	}
5501
-	if ($portion_pourcent >= 100) {
5502
-		return $passe;
5503
-	}
5504
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5505
-	$e = max($e, 0);
5506
-	$mid = str_pad('', $l - 2 * $e, '*');
5507
-	if ($e > 0 and strlen($mid) > 8) {
5508
-		$mid = '***...***';
5509
-	}
5510
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5485
+    $passe ??= '';
5486
+    $l = strlen($passe);
5487
+
5488
+    if ($l <= 8 or !$afficher_partiellement) {
5489
+        if (!$l) {
5490
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5491
+        }
5492
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5493
+    }
5494
+
5495
+    if (is_null($portion_pourcent)) {
5496
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5497
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5498
+        }
5499
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5500
+    }
5501
+    if ($portion_pourcent >= 100) {
5502
+        return $passe;
5503
+    }
5504
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5505
+    $e = max($e, 0);
5506
+    $mid = str_pad('', $l - 2 * $e, '*');
5507
+    if ($e > 0 and strlen($mid) > 8) {
5508
+        $mid = '***...***';
5509
+    }
5510
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5511 5511
 }
5512 5512
 
5513 5513
 
@@ -5528,64 +5528,64 @@  discard block
 block discarded – undo
5528 5528
  */
5529 5529
 function identifiant_slug($texte, $type = '', $options = []) {
5530 5530
 
5531
-	$original = $texte;
5532
-	$separateur = ($options['separateur'] ?? '_');
5533
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5534
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5531
+    $original = $texte;
5532
+    $separateur = ($options['separateur'] ?? '_');
5533
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5534
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5535 5535
 
5536
-	if (!function_exists('translitteration')) {
5537
-		include_spip('inc/charsets');
5538
-	}
5536
+    if (!function_exists('translitteration')) {
5537
+        include_spip('inc/charsets');
5538
+    }
5539 5539
 
5540
-	// pas de balise html
5541
-	if (strpos($texte, '<') !== false) {
5542
-		$texte = strip_tags($texte);
5543
-	}
5544
-	if (strpos($texte, '&') !== false) {
5545
-		$texte = unicode2charset($texte);
5546
-	}
5547
-	// On enlève les espaces indésirables
5548
-	$texte = trim($texte);
5540
+    // pas de balise html
5541
+    if (strpos($texte, '<') !== false) {
5542
+        $texte = strip_tags($texte);
5543
+    }
5544
+    if (strpos($texte, '&') !== false) {
5545
+        $texte = unicode2charset($texte);
5546
+    }
5547
+    // On enlève les espaces indésirables
5548
+    $texte = trim($texte);
5549 5549
 
5550
-	// On enlève les accents et cie
5551
-	$texte = translitteration($texte);
5550
+    // On enlève les accents et cie
5551
+    $texte = translitteration($texte);
5552 5552
 
5553
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5554
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5553
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5554
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5555 5555
 
5556
-	// nettoyer les doubles occurences du separateur si besoin
5557
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5558
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5559
-	}
5556
+    // nettoyer les doubles occurences du separateur si besoin
5557
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5558
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5559
+    }
5560 5560
 
5561
-	// pas de separateur au debut ni a la fin
5562
-	$texte = trim($texte, $separateur);
5561
+    // pas de separateur au debut ni a la fin
5562
+    $texte = trim($texte, $separateur);
5563 5563
 
5564
-	// en minuscules
5565
-	$texte = strtolower($texte);
5564
+    // en minuscules
5565
+    $texte = strtolower($texte);
5566 5566
 
5567
-	switch ($type) {
5568
-		case 'class':
5569
-		case 'id':
5570
-		case 'anchor':
5571
-			if (preg_match(',^\d,', $texte)) {
5572
-				$texte = substr($type, 0, 1) . $texte;
5573
-			}
5574
-	}
5567
+    switch ($type) {
5568
+        case 'class':
5569
+        case 'id':
5570
+        case 'anchor':
5571
+            if (preg_match(',^\d,', $texte)) {
5572
+                $texte = substr($type, 0, 1) . $texte;
5573
+            }
5574
+    }
5575 5575
 
5576
-	if (strlen($texte) > $longueur_maxi) {
5577
-		$texte = substr($texte, 0, $longueur_maxi);
5578
-	}
5576
+    if (strlen($texte) > $longueur_maxi) {
5577
+        $texte = substr($texte, 0, $longueur_maxi);
5578
+    }
5579 5579
 
5580
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5581
-		if (preg_match(',^\d,', $texte)) {
5582
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5583
-		}
5584
-		$texte .= $separateur . md5($original);
5585
-		$texte = substr($texte, 0, $longueur_mini);
5586
-	}
5580
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5581
+        if (preg_match(',^\d,', $texte)) {
5582
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5583
+        }
5584
+        $texte .= $separateur . md5($original);
5585
+        $texte = substr($texte, 0, $longueur_mini);
5586
+    }
5587 5587
 
5588
-	return $texte;
5588
+    return $texte;
5589 5589
 }
5590 5590
 
5591 5591
 
@@ -5606,11 +5606,11 @@  discard block
 block discarded – undo
5606 5606
  * @exemple `<:info_maximum|label_nettoyer:>`
5607 5607
  */
5608 5608
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5609
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5610
-	if ($ucfirst) {
5611
-		$label = spip_ucfirst($label);
5612
-	}
5613
-	return $label;
5609
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5610
+    if ($ucfirst) {
5611
+        $label = spip_ucfirst($label);
5612
+    }
5613
+    return $label;
5614 5614
 }
5615 5615
 
5616 5616
 /**
@@ -5623,8 +5623,8 @@  discard block
 block discarded – undo
5623 5623
  * @exemple `<:info_maximum|label_ponctuer:>`
5624 5624
  */
5625 5625
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5626
-	$label = label_nettoyer($text, $ucfirst);
5627
-	return _T('label_ponctuer', ['label' => $label]);
5626
+    $label = label_nettoyer($text, $ucfirst);
5627
+    return _T('label_ponctuer', ['label' => $label]);
5628 5628
 }
5629 5629
 
5630 5630
 
@@ -5637,19 +5637,19 @@  discard block
 block discarded – undo
5637 5637
  * @return array
5638 5638
  */
5639 5639
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5640
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5641
-		return [];
5642
-	}
5640
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5641
+        return [];
5642
+    }
5643 5643
 
5644
-	// compatibilite signature inversee
5645
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5646
-		[$objet, $id_objet] = [$id_objet, $objet];
5647
-	}
5644
+    // compatibilite signature inversee
5645
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5646
+        [$objet, $id_objet] = [$id_objet, $objet];
5647
+    }
5648 5648
 
5649
-	if (!function_exists($fonction)) {
5650
-		include_spip('base/objets');
5651
-	}
5652
-	return $fonction($objet, $id_objet);
5649
+    if (!function_exists($fonction)) {
5650
+        include_spip('base/objets');
5651
+    }
5652
+    return $fonction($objet, $id_objet);
5653 5653
 }
5654 5654
 
5655 5655
 
@@ -5664,7 +5664,7 @@  discard block
 block discarded – undo
5664 5664
  * @return array
5665 5665
  */
5666 5666
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5667
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5667
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5668 5668
 }
5669 5669
 
5670 5670
 /**
@@ -5678,7 +5678,7 @@  discard block
 block discarded – undo
5678 5678
  * @return array
5679 5679
  */
5680 5680
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5681
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5681
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5682 5682
 }
5683 5683
 
5684 5684
 /**
@@ -5692,7 +5692,7 @@  discard block
 block discarded – undo
5692 5692
  * @return array
5693 5693
  */
5694 5694
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5695
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5695
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5696 5696
 }
5697 5697
 
5698 5698
 /**
@@ -5706,5 +5706,5 @@  discard block
 block discarded – undo
5706 5706
  * @return array
5707 5707
  */
5708 5708
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5709
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5709
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5710 5710
 }
Please login to merge, or discard this patch.