Completed
Push — master ( 1bc8da...a90c3c )
by cam
01:11
created
ecrire/inc/filtres.php 1 patch
Indentation   +2451 added lines, -2451 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,38 +77,38 @@  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
-		// fonction ou name\space\fonction
102
-		if (is_callable($f)) {
103
-			return $f;
104
-		}
105
-		// méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
-		elseif (false === strpos($f, '::') and is_callable([$f])) {
107
-			return $f;
108
-		}
109
-	}
110
-
111
-	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
+        // fonction ou name\space\fonction
102
+        if (is_callable($f)) {
103
+            return $f;
104
+        }
105
+        // méthode statique d'une classe Classe::methode ou name\space\Classe::methode
106
+        elseif (false === strpos($f, '::') and is_callable([$f])) {
107
+            return $f;
108
+        }
109
+    }
110
+
111
+    return $default;
112 112
 }
113 113
 
114 114
 /**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
  *     Chaîne vide sinon.
153 153
  **/
154 154
 function appliquer_filtre($arg, $filtre) {
155
-	$args = func_get_args();
156
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
155
+    $args = func_get_args();
156
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
157 157
 }
158 158
 
159 159
 /**
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
  *     Texte d'origine sinon
179 179
  **/
180 180
 function appliquer_si_filtre($arg, $filtre) {
181
-	$args = func_get_args();
182
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
181
+    $args = func_get_args();
182
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
183 183
 }
184 184
 
185 185
 /**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
  *     Version de SPIP
196 196
  **/
197 197
 function spip_version() {
198
-	$version = $GLOBALS['spip_version_affichee'];
199
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
-		$version .= " $vcs_version";
201
-	}
198
+    $version = $GLOBALS['spip_version_affichee'];
199
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
200
+        $version .= " $vcs_version";
201
+    }
202 202
 
203
-	return $version;
203
+    return $version;
204 204
 }
205 205
 
206 206
 /**
@@ -213,19 +213,19 @@  discard block
 block discarded – undo
213 213
  *    - string|null si $raw = false
214 214
  */
215 215
 function version_vcs_courante($dir, $raw = false) {
216
-	$desc = decrire_version_git($dir);
217
-	if ($desc === null) {
218
-		$desc = decrire_version_svn($dir);
219
-	}
220
-	if ($desc === null or $raw) {
221
-		return $desc;
222
-	}
223
-	// affichage "GIT [master: abcdef]"
224
-	$commit = $desc['commit_short'] ?? $desc['commit'];
225
-	if ($desc['branch']) {
226
-		$commit = $desc['branch'] . ': ' . $commit;
227
-	}
228
-	return "{$desc['vcs']} [$commit]";
216
+    $desc = decrire_version_git($dir);
217
+    if ($desc === null) {
218
+        $desc = decrire_version_svn($dir);
219
+    }
220
+    if ($desc === null or $raw) {
221
+        return $desc;
222
+    }
223
+    // affichage "GIT [master: abcdef]"
224
+    $commit = $desc['commit_short'] ?? $desc['commit'];
225
+    if ($desc['branch']) {
226
+        $commit = $desc['branch'] . ': ' . $commit;
227
+    }
228
+    return "{$desc['vcs']} [$commit]";
229 229
 }
230 230
 
231 231
 /**
@@ -237,24 +237,24 @@  discard block
 block discarded – undo
237 237
  *      array ['branch' => xx, 'commit' => yy] sinon.
238 238
  **/
239 239
 function decrire_version_git($dir) {
240
-	if (!$dir) {
241
-		$dir = '.';
242
-	}
240
+    if (!$dir) {
241
+        $dir = '.';
242
+    }
243 243
 
244
-	// version installee par GIT
245
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
-		$currentHead = trim(substr($c, 4));
247
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
-			return [
249
-				'vcs' => 'GIT',
250
-				'branch' => basename($currentHead),
251
-				'commit' => trim($hash),
252
-				'commit_short' => substr(trim($hash), 0, 8),
253
-			];
254
-		}
255
-	}
244
+    // version installee par GIT
245
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
246
+        $currentHead = trim(substr($c, 4));
247
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
248
+            return [
249
+                'vcs' => 'GIT',
250
+                'branch' => basename($currentHead),
251
+                'commit' => trim($hash),
252
+                'commit_short' => substr(trim($hash), 0, 8),
253
+            ];
254
+        }
255
+    }
256 256
 
257
-	return null;
257
+    return null;
258 258
 }
259 259
 
260 260
 
@@ -267,25 +267,25 @@  discard block
 block discarded – undo
267 267
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
268 268
  **/
269 269
 function decrire_version_svn($dir) {
270
-	if (!$dir) {
271
-		$dir = '.';
272
-	}
273
-	// version installee par SVN
274
-	if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
275
-		$db = new SQLite3($dir . '/.svn/wc.db');
276
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
-		if ($result) {
278
-			$row = $result->fetchArray();
279
-			if ($row['changed_revision'] != '') {
280
-				return [
281
-					'vcs' => 'SVN',
282
-					'branch' => '',
283
-					'commit' => $row['changed_revision'],
284
-				];
285
-			}
286
-		}
287
-	}
288
-	return null;
270
+    if (!$dir) {
271
+        $dir = '.';
272
+    }
273
+    // version installee par SVN
274
+    if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
275
+        $db = new SQLite3($dir . '/.svn/wc.db');
276
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
277
+        if ($result) {
278
+            $row = $result->fetchArray();
279
+            if ($row['changed_revision'] != '') {
280
+                return [
281
+                    'vcs' => 'SVN',
282
+                    'branch' => '',
283
+                    'commit' => $row['changed_revision'],
284
+                ];
285
+            }
286
+        }
287
+    }
288
+    return null;
289 289
 }
290 290
 
291 291
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
  *     Code HTML retourné par le filtre
333 333
  **/
334 334
 function filtrer($filtre) {
335
-	$tous = func_get_args();
336
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
-		return image_filtrer($tous);
338
-	} elseif ($f = chercher_filtre($filtre)) {
339
-		array_shift($tous);
340
-		return call_user_func_array($f, $tous);
341
-	} else {
342
-		// le filtre n'existe pas, on provoque une erreur
343
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
-		erreur_squelette($msg);
345
-		return '';
346
-	}
335
+    $tous = func_get_args();
336
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
337
+        return image_filtrer($tous);
338
+    } elseif ($f = chercher_filtre($filtre)) {
339
+        array_shift($tous);
340
+        return call_user_func_array($f, $tous);
341
+    } else {
342
+        // le filtre n'existe pas, on provoque une erreur
343
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
344
+        erreur_squelette($msg);
345
+        return '';
346
+    }
347 347
 }
348 348
 
349 349
 /**
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
361 361
  */
362 362
 function trouver_filtre_matrice($filtre) {
363
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
-		find_in_path($f, '', true);
365
-		$GLOBALS['spip_matrice'][$filtre] = true;
366
-	}
367
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
363
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
364
+        find_in_path($f, '', true);
365
+        $GLOBALS['spip_matrice'][$filtre] = true;
366
+    }
367
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
368 368
 }
369 369
 
370 370
 
@@ -392,8 +392,8 @@  discard block
 block discarded – undo
392 392
  * @return mixed
393 393
  */
394 394
 function filtre_set(&$Pile, $val, $key, $continue = null) {
395
-	$Pile['vars'][$key] = $val;
396
-	return $continue ? $val : '';
395
+    $Pile['vars'][$key] = $val;
396
+    return $continue ? $val : '';
397 397
 }
398 398
 
399 399
 /**
@@ -419,8 +419,8 @@  discard block
 block discarded – undo
419 419
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
420 420
  */
421 421
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
422
-	$Pile[0][$key] = $val;
423
-	return $continue ? $val : '';
422
+    $Pile[0][$key] = $val;
423
+    return $continue ? $val : '';
424 424
 }
425 425
 
426 426
 /**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
  * @return string
430 430
  */
431 431
 function filtre_sanitize_env(&$Pile, $keys) {
432
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
-	return '';
432
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
433
+    return '';
434 434
 }
435 435
 
436 436
 
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
  * @return mixed Retourne la valeur (sans la modifier).
454 454
  */
455 455
 function filtre_debug($val, $key = null) {
456
-	$debug = (
457
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
458
-		) . var_export($val, true);
456
+    $debug = (
457
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
458
+        ) . var_export($val, true);
459 459
 
460
-	include_spip('inc/autoriser');
461
-	if (autoriser('webmestre')) {
462
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
-	}
460
+    include_spip('inc/autoriser');
461
+    if (autoriser('webmestre')) {
462
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
463
+    }
464 464
 
465
-	spip_log($debug, 'debug');
465
+    spip_log($debug, 'debug');
466 466
 
467
-	return $val;
467
+    return $val;
468 468
 }
469 469
 
470 470
 
@@ -492,89 +492,89 @@  discard block
 block discarded – undo
492 492
  *     Texte qui a reçu les filtres
493 493
  **/
494 494
 function image_filtrer($args) {
495
-	$filtre = array_shift($args); # enlever $filtre
496
-	$texte = array_shift($args);
497
-	if ($texte === null || !strlen($texte)) {
498
-		return;
499
-	}
500
-	find_in_path('filtres_images_mini.php', 'inc/', true);
501
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
-	// Cas du nom de fichier local
503
-	$is_file = trim($texte);
504
-	if (
505
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
-		  or strpbrk($is_file, "<>\n\r\t") !== false
507
-		  or strpos($is_file, '/') === 0
508
-	) {
509
-		$is_file = false;
510
-	}
511
-	if ($is_file) {
512
-		$is_local_file = function ($path) {
513
-			if (strpos($path, '?') !== false) {
514
-				$path = supprimer_timestamp($path);
515
-				// remove ?24px added by find_in_theme on .svg files
516
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
-			}
518
-			return file_exists($path);
519
-		};
520
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
-			array_unshift($args, "<img src='$is_file' />");
522
-			$res = call_user_func_array($filtre, $args);
523
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
-			return $res;
525
-		}
526
-	}
527
-
528
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
529
-	if (
530
-		preg_match_all(
531
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
-			$texte,
533
-			$tags,
534
-			PREG_SET_ORDER
535
-		)
536
-	) {
537
-		foreach ($tags as $tag) {
538
-			$class = extraire_attribut($tag[3], 'class');
539
-			if (
540
-				!$class or
541
-				(strpos($class, 'filtre_inactif') === false
542
-					// compat historique a virer en 3.2
543
-					and strpos($class, 'no_image_filtrer') === false)
544
-			) {
545
-				array_unshift($args, $tag[3]);
546
-				if ($reduit = call_user_func_array($filtre, $args)) {
547
-					// En cas de span spip_documents, modifier le style=...width:
548
-					if ($tag[1]) {
549
-						$w = extraire_attribut($reduit, 'width');
550
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
-							$w = $regs[1];
552
-						}
553
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
-							$style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
-							$replace = inserer_attribut($tag[1], 'style', $style);
556
-							$texte = str_replace($tag[1], $replace, $texte);
557
-						}
558
-					}
559
-					// traiter aussi un eventuel mouseover
560
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
-							$srcover = $match[1];
563
-							array_shift($args);
564
-							array_unshift($args, "<img src='" . $match[1] . "' />");
565
-							$srcover_filter = call_user_func_array($filtre, $args);
566
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
567
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
568
-						}
569
-					}
570
-					$texte = str_replace($tag[3], $reduit, $texte);
571
-				}
572
-				array_shift($args);
573
-			}
574
-		}
575
-	}
576
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
-	return $texte;
495
+    $filtre = array_shift($args); # enlever $filtre
496
+    $texte = array_shift($args);
497
+    if ($texte === null || !strlen($texte)) {
498
+        return;
499
+    }
500
+    find_in_path('filtres_images_mini.php', 'inc/', true);
501
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
502
+    // Cas du nom de fichier local
503
+    $is_file = trim($texte);
504
+    if (
505
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
506
+          or strpbrk($is_file, "<>\n\r\t") !== false
507
+          or strpos($is_file, '/') === 0
508
+    ) {
509
+        $is_file = false;
510
+    }
511
+    if ($is_file) {
512
+        $is_local_file = function ($path) {
513
+            if (strpos($path, '?') !== false) {
514
+                $path = supprimer_timestamp($path);
515
+                // remove ?24px added by find_in_theme on .svg files
516
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
517
+            }
518
+            return file_exists($path);
519
+        };
520
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
521
+            array_unshift($args, "<img src='$is_file' />");
522
+            $res = call_user_func_array($filtre, $args);
523
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
524
+            return $res;
525
+        }
526
+    }
527
+
528
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
529
+    if (
530
+        preg_match_all(
531
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
532
+            $texte,
533
+            $tags,
534
+            PREG_SET_ORDER
535
+        )
536
+    ) {
537
+        foreach ($tags as $tag) {
538
+            $class = extraire_attribut($tag[3], 'class');
539
+            if (
540
+                !$class or
541
+                (strpos($class, 'filtre_inactif') === false
542
+                    // compat historique a virer en 3.2
543
+                    and strpos($class, 'no_image_filtrer') === false)
544
+            ) {
545
+                array_unshift($args, $tag[3]);
546
+                if ($reduit = call_user_func_array($filtre, $args)) {
547
+                    // En cas de span spip_documents, modifier le style=...width:
548
+                    if ($tag[1]) {
549
+                        $w = extraire_attribut($reduit, 'width');
550
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
551
+                            $w = $regs[1];
552
+                        }
553
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
554
+                            $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style);
555
+                            $replace = inserer_attribut($tag[1], 'style', $style);
556
+                            $texte = str_replace($tag[1], $replace, $texte);
557
+                        }
558
+                    }
559
+                    // traiter aussi un eventuel mouseover
560
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
561
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
562
+                            $srcover = $match[1];
563
+                            array_shift($args);
564
+                            array_unshift($args, "<img src='" . $match[1] . "' />");
565
+                            $srcover_filter = call_user_func_array($filtre, $args);
566
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
567
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
568
+                        }
569
+                    }
570
+                    $texte = str_replace($tag[3], $reduit, $texte);
571
+                }
572
+                array_shift($args);
573
+            }
574
+        }
575
+    }
576
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
577
+    return $texte;
578 578
 }
579 579
 
580 580
 /**
@@ -589,78 +589,78 @@  discard block
 block discarded – undo
589 589
  **/
590 590
 function taille_image($img, $force_refresh = false) {
591 591
 
592
-	static $largeur_img = [], $hauteur_img = [];
593
-	$srcWidth = 0;
594
-	$srcHeight = 0;
595
-
596
-	$src = extraire_attribut($img, 'src');
597
-
598
-	if (!$src) {
599
-		$src = $img;
600
-	} else {
601
-		$srcWidth = extraire_attribut($img, 'width');
602
-		$srcHeight = extraire_attribut($img, 'height');
603
-	}
604
-
605
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
606
-	// la copie locale a toutes les chances d'etre la ou de resservir
607
-	if (tester_url_absolue($src)) {
608
-		include_spip('inc/distant');
609
-		$fichier = copie_locale($src);
610
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
611
-	}
612
-	if (($p = strpos($src, '?')) !== false) {
613
-		$src = substr($src, 0, $p);
614
-	}
615
-
616
-	$srcsize = false;
617
-	if (isset($largeur_img[$src]) and !$force_refresh) {
618
-		$srcWidth = $largeur_img[$src];
619
-	}
620
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
621
-		$srcHeight = $hauteur_img[$src];
622
-	}
623
-	if (!$srcWidth or !$srcHeight) {
624
-		if (
625
-			file_exists($src)
626
-			and $srcsize = spip_getimagesize($src)
627
-		) {
628
-			if (!$srcWidth) {
629
-				$largeur_img[$src] = $srcWidth = $srcsize[0];
630
-			}
631
-			if (!$srcHeight) {
632
-				$hauteur_img[$src] = $srcHeight = $srcsize[1];
633
-			}
634
-		}
635
-		elseif (strpos($src, '<svg') !== false) {
636
-			include_spip('inc/svg');
637
-			if ($attrs = svg_lire_attributs($src)) {
638
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
639
-				if (!$srcWidth) {
640
-					$largeur_img[$src] = $srcWidth = $width;
641
-				}
642
-				if (!$srcHeight) {
643
-					$hauteur_img[$src] = $srcHeight = $height;
644
-				}
645
-			}
646
-		}
647
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
-		elseif (
650
-			@file_exists($f = "$src.src")
651
-			and lire_fichier($f, $valeurs)
652
-			and $valeurs = unserialize($valeurs)
653
-		) {
654
-			if (!$srcWidth) {
655
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
-			}
657
-			if (!$srcHeight) {
658
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
-			}
660
-		}
661
-	}
662
-
663
-	return [$srcHeight, $srcWidth];
592
+    static $largeur_img = [], $hauteur_img = [];
593
+    $srcWidth = 0;
594
+    $srcHeight = 0;
595
+
596
+    $src = extraire_attribut($img, 'src');
597
+
598
+    if (!$src) {
599
+        $src = $img;
600
+    } else {
601
+        $srcWidth = extraire_attribut($img, 'width');
602
+        $srcHeight = extraire_attribut($img, 'height');
603
+    }
604
+
605
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
606
+    // la copie locale a toutes les chances d'etre la ou de resservir
607
+    if (tester_url_absolue($src)) {
608
+        include_spip('inc/distant');
609
+        $fichier = copie_locale($src);
610
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
611
+    }
612
+    if (($p = strpos($src, '?')) !== false) {
613
+        $src = substr($src, 0, $p);
614
+    }
615
+
616
+    $srcsize = false;
617
+    if (isset($largeur_img[$src]) and !$force_refresh) {
618
+        $srcWidth = $largeur_img[$src];
619
+    }
620
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
621
+        $srcHeight = $hauteur_img[$src];
622
+    }
623
+    if (!$srcWidth or !$srcHeight) {
624
+        if (
625
+            file_exists($src)
626
+            and $srcsize = spip_getimagesize($src)
627
+        ) {
628
+            if (!$srcWidth) {
629
+                $largeur_img[$src] = $srcWidth = $srcsize[0];
630
+            }
631
+            if (!$srcHeight) {
632
+                $hauteur_img[$src] = $srcHeight = $srcsize[1];
633
+            }
634
+        }
635
+        elseif (strpos($src, '<svg') !== false) {
636
+            include_spip('inc/svg');
637
+            if ($attrs = svg_lire_attributs($src)) {
638
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
639
+                if (!$srcWidth) {
640
+                    $largeur_img[$src] = $srcWidth = $width;
641
+                }
642
+                if (!$srcHeight) {
643
+                    $hauteur_img[$src] = $srcHeight = $height;
644
+                }
645
+            }
646
+        }
647
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
648
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
649
+        elseif (
650
+            @file_exists($f = "$src.src")
651
+            and lire_fichier($f, $valeurs)
652
+            and $valeurs = unserialize($valeurs)
653
+        ) {
654
+            if (!$srcWidth) {
655
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
656
+            }
657
+            if (!$srcHeight) {
658
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
659
+            }
660
+        }
661
+    }
662
+
663
+    return [$srcHeight, $srcWidth];
664 664
 }
665 665
 
666 666
 
@@ -678,12 +678,12 @@  discard block
 block discarded – undo
678 678
  *     Largeur en pixels, NULL ou 0 si aucune image.
679 679
  **/
680 680
 function largeur($img) {
681
-	if (!$img) {
682
-		return;
683
-	}
684
-	[$h, $l] = taille_image($img);
681
+    if (!$img) {
682
+        return;
683
+    }
684
+    [$h, $l] = taille_image($img);
685 685
 
686
-	return $l;
686
+    return $l;
687 687
 }
688 688
 
689 689
 /**
@@ -700,12 +700,12 @@  discard block
 block discarded – undo
700 700
  *     Hauteur en pixels, NULL ou 0 si aucune image.
701 701
  **/
702 702
 function hauteur($img) {
703
-	if (!$img) {
704
-		return;
705
-	}
706
-	[$h, $l] = taille_image($img);
703
+    if (!$img) {
704
+        return;
705
+    }
706
+    [$h, $l] = taille_image($img);
707 707
 
708
-	return $h;
708
+    return $h;
709 709
 }
710 710
 
711 711
 
@@ -725,11 +725,11 @@  discard block
 block discarded – undo
725 725
  * @return string
726 726
  **/
727 727
 function corriger_entites_html($texte) {
728
-	if (strpos($texte, '&amp;') === false) {
729
-		return $texte;
730
-	}
728
+    if (strpos($texte, '&amp;') === false) {
729
+        return $texte;
730
+    }
731 731
 
732
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
732
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
733 733
 }
734 734
 
735 735
 /**
@@ -744,11 +744,11 @@  discard block
 block discarded – undo
744 744
  * @return string
745 745
  **/
746 746
 function corriger_toutes_entites_html($texte) {
747
-	if (strpos($texte, '&amp;') === false) {
748
-		return $texte;
749
-	}
747
+    if (strpos($texte, '&amp;') === false) {
748
+        return $texte;
749
+    }
750 750
 
751
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
751
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
752 752
 }
753 753
 
754 754
 /**
@@ -758,7 +758,7 @@  discard block
 block discarded – undo
758 758
  * @return string
759 759
  **/
760 760
 function proteger_amp($texte) {
761
-	return str_replace('&', '&amp;', $texte);
761
+    return str_replace('&', '&amp;', $texte);
762 762
 }
763 763
 
764 764
 
@@ -789,21 +789,21 @@  discard block
 block discarded – undo
789 789
  * @return mixed|string
790 790
  */
791 791
 function entites_html($texte, $tout = false, $quote = true) {
792
-	if (
793
-		!is_string($texte) or !$texte
794
-		or strpbrk($texte, "&\"'<>") == false
795
-	) {
796
-		return $texte;
797
-	}
798
-	include_spip('inc/texte');
799
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
-	$flags |= ENT_HTML401;
801
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
-	if ($tout) {
803
-		return corriger_toutes_entites_html($texte);
804
-	} else {
805
-		return corriger_entites_html($texte);
806
-	}
792
+    if (
793
+        !is_string($texte) or !$texte
794
+        or strpbrk($texte, "&\"'<>") == false
795
+    ) {
796
+        return $texte;
797
+    }
798
+    include_spip('inc/texte');
799
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
800
+    $flags |= ENT_HTML401;
801
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
802
+    if ($tout) {
803
+        return corriger_toutes_entites_html($texte);
804
+    } else {
805
+        return corriger_entites_html($texte);
806
+    }
807 807
 }
808 808
 
809 809
 /**
@@ -822,37 +822,37 @@  discard block
 block discarded – undo
822 822
  *     Texte converti
823 823
  **/
824 824
 function filtrer_entites($texte) {
825
-	if (strpos($texte, '&') === false) {
826
-		return $texte;
827
-	}
828
-	// filtrer
829
-	$texte = html2unicode($texte);
830
-	// remettre le tout dans le charset cible
831
-	$texte = unicode2charset($texte);
832
-	// cas particulier des " et ' qu'il faut filtrer aussi
833
-	// (on le faisait deja avec un &quot;)
834
-	if (strpos($texte, '&#') !== false) {
835
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
-	}
825
+    if (strpos($texte, '&') === false) {
826
+        return $texte;
827
+    }
828
+    // filtrer
829
+    $texte = html2unicode($texte);
830
+    // remettre le tout dans le charset cible
831
+    $texte = unicode2charset($texte);
832
+    // cas particulier des " et ' qu'il faut filtrer aussi
833
+    // (on le faisait deja avec un &quot;)
834
+    if (strpos($texte, '&#') !== false) {
835
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
836
+    }
837 837
 
838
-	return $texte;
838
+    return $texte;
839 839
 }
840 840
 
841 841
 
842 842
 if (!function_exists('filtre_filtrer_entites_dist')) {
843
-	/**
844
-	 * Version sécurisée de filtrer_entites
845
-	 *
846
-	 * @uses interdire_scripts()
847
-	 * @uses filtrer_entites()
848
-	 *
849
-	 * @param string $t
850
-	 * @return string
851
-	 */
852
-	function filtre_filtrer_entites_dist($t) {
853
-		include_spip('inc/texte');
854
-		return interdire_scripts(filtrer_entites($t));
855
-	}
843
+    /**
844
+     * Version sécurisée de filtrer_entites
845
+     *
846
+     * @uses interdire_scripts()
847
+     * @uses filtrer_entites()
848
+     *
849
+     * @param string $t
850
+     * @return string
851
+     */
852
+    function filtre_filtrer_entites_dist($t) {
853
+        include_spip('inc/texte');
854
+        return interdire_scripts(filtrer_entites($t));
855
+    }
856 856
 }
857 857
 
858 858
 
@@ -867,18 +867,18 @@  discard block
 block discarded – undo
867 867
  * @return string|array
868 868
  **/
869 869
 function supprimer_caracteres_illegaux($texte) {
870
-	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";
871
-	static $to = null;
870
+    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";
871
+    static $to = null;
872 872
 
873
-	if (is_array($texte)) {
874
-		return array_map('supprimer_caracteres_illegaux', $texte);
875
-	}
873
+    if (is_array($texte)) {
874
+        return array_map('supprimer_caracteres_illegaux', $texte);
875
+    }
876 876
 
877
-	if (!$to) {
878
-		$to = str_repeat('-', strlen($from));
879
-	}
877
+    if (!$to) {
878
+        $to = str_repeat('-', strlen($from));
879
+    }
880 880
 
881
-	return strtr($texte, $from, $to);
881
+    return strtr($texte, $from, $to);
882 882
 }
883 883
 
884 884
 /**
@@ -890,10 +890,10 @@  discard block
 block discarded – undo
890 890
  * @return string|array
891 891
  **/
892 892
 function corriger_caracteres($texte) {
893
-	$texte = corriger_caracteres_windows($texte);
894
-	$texte = supprimer_caracteres_illegaux($texte);
893
+    $texte = corriger_caracteres_windows($texte);
894
+    $texte = supprimer_caracteres_illegaux($texte);
895 895
 
896
-	return $texte;
896
+    return $texte;
897 897
 }
898 898
 
899 899
 /**
@@ -910,44 +910,44 @@  discard block
 block discarded – undo
910 910
  *     Texte encodé pour XML
911 911
  */
912 912
 function texte_backend(string $texte): string {
913
-	if ($texte === '') {
914
-		return '';
915
-	}
913
+    if ($texte === '') {
914
+        return '';
915
+    }
916 916
 
917
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
917
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
918 918
 
919
-	// si on a des liens ou des images, les passer en absolu
920
-	$texte = liens_absolus($texte);
919
+    // si on a des liens ou des images, les passer en absolu
920
+    $texte = liens_absolus($texte);
921 921
 
922
-	// echapper les tags &gt; &lt;
923
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
922
+    // echapper les tags &gt; &lt;
923
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
924 924
 
925
-	// importer les &eacute;
926
-	$texte = filtrer_entites($texte);
925
+    // importer les &eacute;
926
+    $texte = filtrer_entites($texte);
927 927
 
928
-	// " -> &quot; et tout ce genre de choses
929
-	$u = $GLOBALS['meta']['pcre_u'];
930
-	$texte = str_replace('&nbsp;', ' ', $texte);
931
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
932
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933
-	$texte = entites_html($texte, false, false);
934
-	// mais bien echapper les double quotes !
935
-	$texte = str_replace('"', '&#034;', $texte);
928
+    // " -> &quot; et tout ce genre de choses
929
+    $u = $GLOBALS['meta']['pcre_u'];
930
+    $texte = str_replace('&nbsp;', ' ', $texte);
931
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
932
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
933
+    $texte = entites_html($texte, false, false);
934
+    // mais bien echapper les double quotes !
935
+    $texte = str_replace('"', '&#034;', $texte);
936 936
 
937
-	// verifier le charset
938
-	$texte = charset2unicode($texte);
937
+    // verifier le charset
938
+    $texte = charset2unicode($texte);
939 939
 
940
-	// Caracteres problematiques en iso-latin 1
941
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
942
-		$texte = str_replace(chr(156), '&#156;', $texte);
943
-		$texte = str_replace(chr(140), '&#140;', $texte);
944
-		$texte = str_replace(chr(159), '&#159;', $texte);
945
-	}
940
+    // Caracteres problematiques en iso-latin 1
941
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
942
+        $texte = str_replace(chr(156), '&#156;', $texte);
943
+        $texte = str_replace(chr(140), '&#140;', $texte);
944
+        $texte = str_replace(chr(159), '&#159;', $texte);
945
+    }
946 946
 
947
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
948
-	// et le caractere apostrophe alourdit les squelettes avec PHP
949
-	// ==> on les remplace par l'entite HTML
950
-	return str_replace($apostrophe, "'", $texte);
947
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
948
+    // et le caractere apostrophe alourdit les squelettes avec PHP
949
+    // ==> on les remplace par l'entite HTML
950
+    return str_replace($apostrophe, "'", $texte);
951 951
 }
952 952
 
953 953
 /**
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
  *     Texte encodé et quote pour XML
965 965
  */
966 966
 function texte_backendq(string $texte): string {
967
-	return addslashes(texte_backend($texte));
967
+    return addslashes(texte_backend($texte));
968 968
 }
969 969
 
970 970
 
@@ -987,11 +987,11 @@  discard block
 block discarded – undo
987 987
  *     Numéro de titre, sinon chaîne vide
988 988
  **/
989 989
 function supprimer_numero($texte) {
990
-	return preg_replace(
991
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
992
-		'',
993
-		$texte
994
-	);
990
+    return preg_replace(
991
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
992
+        '',
993
+        $texte
994
+    );
995 995
 }
996 996
 
997 997
 /**
@@ -1014,17 +1014,17 @@  discard block
 block discarded – undo
1014 1014
  *     Numéro de titre, sinon chaîne vide
1015 1015
  **/
1016 1016
 function recuperer_numero($texte) {
1017
-	if (
1018
-		preg_match(
1019
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1020
-			$texte,
1021
-			$regs
1022
-		)
1023
-	) {
1024
-		return strval($regs[1]);
1025
-	} else {
1026
-		return '';
1027
-	}
1017
+    if (
1018
+        preg_match(
1019
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1020
+            $texte,
1021
+            $regs
1022
+        )
1023
+    ) {
1024
+        return strval($regs[1]);
1025
+    } else {
1026
+        return '';
1027
+    }
1028 1028
 }
1029 1029
 
1030 1030
 /**
@@ -1051,16 +1051,16 @@  discard block
 block discarded – undo
1051 1051
  *     Texte converti
1052 1052
  **/
1053 1053
 function supprimer_tags(?string $texte, $rempl = ''): string {
1054
-	if ($texte === null || !strlen($texte)) {
1055
-		return '';
1056
-	}
1057
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1058
-	// ne pas oublier un < final non ferme car coupe
1059
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1060
-	// mais qui peut aussi etre un simple signe plus petit que
1061
-	$texte = str_replace('<', '&lt;', $texte);
1054
+    if ($texte === null || !strlen($texte)) {
1055
+        return '';
1056
+    }
1057
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1058
+    // ne pas oublier un < final non ferme car coupe
1059
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1060
+    // mais qui peut aussi etre un simple signe plus petit que
1061
+    $texte = str_replace('<', '&lt;', $texte);
1062 1062
 
1063
-	return $texte;
1063
+    return $texte;
1064 1064
 }
1065 1065
 
1066 1066
 /**
@@ -1083,9 +1083,9 @@  discard block
 block discarded – undo
1083 1083
  *     Texte converti
1084 1084
  **/
1085 1085
 function echapper_tags($texte, $rempl = '') {
1086
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1086
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1087 1087
 
1088
-	return $texte;
1088
+    return $texte;
1089 1089
 }
1090 1090
 
1091 1091
 /**
@@ -1106,18 +1106,18 @@  discard block
 block discarded – undo
1106 1106
  *     Texte converti
1107 1107
  **/
1108 1108
 function textebrut($texte) {
1109
-	$u = $GLOBALS['meta']['pcre_u'];
1110
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1112
-	$texte = preg_replace("/^\n+/", '', $texte);
1113
-	$texte = preg_replace("/\n+$/", '', $texte);
1114
-	$texte = preg_replace("/\n +/", "\n", $texte);
1115
-	$texte = supprimer_tags($texte);
1116
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1117
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1118
-	$texte = str_replace('&#8217;', "'", $texte);
1109
+    $u = $GLOBALS['meta']['pcre_u'];
1110
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1111
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1112
+    $texte = preg_replace("/^\n+/", '', $texte);
1113
+    $texte = preg_replace("/\n+$/", '', $texte);
1114
+    $texte = preg_replace("/\n +/", "\n", $texte);
1115
+    $texte = supprimer_tags($texte);
1116
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1117
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1118
+    $texte = str_replace('&#8217;', "'", $texte);
1119 1119
 
1120
-	return $texte;
1120
+    return $texte;
1121 1121
 }
1122 1122
 
1123 1123
 
@@ -1133,23 +1133,23 @@  discard block
 block discarded – undo
1133 1133
  *     Texte avec liens ouvrants
1134 1134
  **/
1135 1135
 function liens_ouvrants($texte) {
1136
-	if (
1137
-		preg_match_all(
1138
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1139
-			$texte,
1140
-			$liens,
1141
-			PREG_PATTERN_ORDER
1142
-		)
1143
-	) {
1144
-		foreach ($liens[0] as $a) {
1145
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1146
-			$ablank = inserer_attribut($a, 'rel', $rel);
1147
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1148
-			$texte = str_replace($a, $ablank, $texte);
1149
-		}
1150
-	}
1151
-
1152
-	return $texte;
1136
+    if (
1137
+        preg_match_all(
1138
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1139
+            $texte,
1140
+            $liens,
1141
+            PREG_PATTERN_ORDER
1142
+        )
1143
+    ) {
1144
+        foreach ($liens[0] as $a) {
1145
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1146
+            $ablank = inserer_attribut($a, 'rel', $rel);
1147
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1148
+            $texte = str_replace($a, $ablank, $texte);
1149
+        }
1150
+    }
1151
+
1152
+    return $texte;
1153 1153
 }
1154 1154
 
1155 1155
 /**
@@ -1159,22 +1159,22 @@  discard block
 block discarded – undo
1159 1159
  * @return string
1160 1160
  */
1161 1161
 function liens_nofollow($texte) {
1162
-	if (stripos($texte, '<a') === false) {
1163
-		return $texte;
1164
-	}
1162
+    if (stripos($texte, '<a') === false) {
1163
+        return $texte;
1164
+    }
1165 1165
 
1166
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1167
-		foreach ($regs[0] as $a) {
1168
-			$rel = extraire_attribut($a, 'rel');
1169
-			if (strpos($rel, 'nofollow') === false) {
1170
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1171
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1172
-				$texte = str_replace($a, $anofollow, $texte);
1173
-			}
1174
-		}
1175
-	}
1166
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1167
+        foreach ($regs[0] as $a) {
1168
+            $rel = extraire_attribut($a, 'rel');
1169
+            if (strpos($rel, 'nofollow') === false) {
1170
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1171
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1172
+                $texte = str_replace($a, $anofollow, $texte);
1173
+            }
1174
+        }
1175
+    }
1176 1176
 
1177
-	return $texte;
1177
+    return $texte;
1178 1178
 }
1179 1179
 
1180 1180
 /**
@@ -1193,12 +1193,12 @@  discard block
 block discarded – undo
1193 1193
  *     Texte sans paraghaphes
1194 1194
  **/
1195 1195
 function PtoBR($texte) {
1196
-	$u = $GLOBALS['meta']['pcre_u'];
1197
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1198
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1196
+    $u = $GLOBALS['meta']['pcre_u'];
1197
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1198
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1199
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1200 1200
 
1201
-	return $texte;
1201
+    return $texte;
1202 1202
 }
1203 1203
 
1204 1204
 
@@ -1223,14 +1223,14 @@  discard block
 block discarded – undo
1223 1223
  * @return string Texte encadré du style CSS
1224 1224
  */
1225 1225
 function lignes_longues($texte) {
1226
-	if (!strlen(trim($texte))) {
1227
-		return $texte;
1228
-	}
1229
-	include_spip('inc/texte');
1230
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1231
-		'div' : 'span';
1226
+    if (!strlen(trim($texte))) {
1227
+        return $texte;
1228
+    }
1229
+    include_spip('inc/texte');
1230
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1231
+        'div' : 'span';
1232 1232
 
1233
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1233
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1234 1234
 }
1235 1235
 
1236 1236
 /**
@@ -1249,30 +1249,30 @@  discard block
 block discarded – undo
1249 1249
  * @return string Texte en majuscule
1250 1250
  */
1251 1251
 function majuscules($texte) {
1252
-	if (!strlen($texte)) {
1253
-		return '';
1254
-	}
1252
+    if (!strlen($texte)) {
1253
+        return '';
1254
+    }
1255 1255
 
1256
-	// Cas du turc
1257
-	if ($GLOBALS['spip_lang'] == 'tr') {
1258
-		# remplacer hors des tags et des entites
1259
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1260
-			foreach ($regs as $n => $match) {
1261
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1262
-			}
1263
-		}
1256
+    // Cas du turc
1257
+    if ($GLOBALS['spip_lang'] == 'tr') {
1258
+        # remplacer hors des tags et des entites
1259
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1260
+            foreach ($regs as $n => $match) {
1261
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1262
+            }
1263
+        }
1264 1264
 
1265
-		$texte = str_replace('i', '&#304;', $texte);
1265
+        $texte = str_replace('i', '&#304;', $texte);
1266 1266
 
1267
-		if ($regs) {
1268
-			foreach ($regs as $n => $match) {
1269
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1270
-			}
1271
-		}
1272
-	}
1267
+        if ($regs) {
1268
+            foreach ($regs as $n => $match) {
1269
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1270
+            }
1271
+        }
1272
+    }
1273 1273
 
1274
-	// Cas general
1275
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1274
+    // Cas general
1275
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1276 1276
 }
1277 1277
 
1278 1278
 /**
@@ -1290,29 +1290,29 @@  discard block
 block discarded – undo
1290 1290
  * @return string
1291 1291
  **/
1292 1292
 function taille_en_octets($taille) {
1293
-	if (!defined('_KILOBYTE')) {
1294
-		/**
1295
-		 * Définit le nombre d'octets dans un Kilobyte
1296
-		 *
1297
-		 * @var int
1298
-		 **/
1299
-		define('_KILOBYTE', 1024);
1300
-	}
1293
+    if (!defined('_KILOBYTE')) {
1294
+        /**
1295
+         * Définit le nombre d'octets dans un Kilobyte
1296
+         *
1297
+         * @var int
1298
+         **/
1299
+        define('_KILOBYTE', 1024);
1300
+    }
1301 1301
 
1302
-	if ($taille < 1) {
1303
-		return '';
1304
-	}
1305
-	if ($taille < _KILOBYTE) {
1306
-		$taille = _T('taille_octets', ['taille' => $taille]);
1307
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1308
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1309
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1310
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1311
-	} else {
1312
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1313
-	}
1302
+    if ($taille < 1) {
1303
+        return '';
1304
+    }
1305
+    if ($taille < _KILOBYTE) {
1306
+        $taille = _T('taille_octets', ['taille' => $taille]);
1307
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1308
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1309
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1310
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1311
+    } else {
1312
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1313
+    }
1314 1314
 
1315
-	return $taille;
1315
+    return $taille;
1316 1316
 }
1317 1317
 
1318 1318
 
@@ -1334,21 +1334,21 @@  discard block
 block discarded – undo
1334 1334
  *     Texte prêt pour être utilisé en attribut HTML
1335 1335
  **/
1336 1336
 function attribut_html(?string $texte, $textebrut = true): string {
1337
-	if ($texte === null) {
1338
-		return '';
1339
-	}
1340
-	$u = $GLOBALS['meta']['pcre_u'];
1341
-	if ($textebrut) {
1342
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1343
-	}
1344
-	$texte = texte_backend($texte);
1345
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1337
+    if ($texte === null) {
1338
+        return '';
1339
+    }
1340
+    $u = $GLOBALS['meta']['pcre_u'];
1341
+    if ($textebrut) {
1342
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1343
+    }
1344
+    $texte = texte_backend($texte);
1345
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1346 1346
 
1347
-	return preg_replace(
1348
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1349
-		['&', '&#38;'],
1350
-		$texte
1351
-	);
1347
+    return preg_replace(
1348
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1349
+        ['&', '&#38;'],
1350
+        $texte
1351
+    );
1352 1352
 }
1353 1353
 
1354 1354
 
@@ -1368,15 +1368,15 @@  discard block
 block discarded – undo
1368 1368
  *     URL ou chaîne vide
1369 1369
  **/
1370 1370
 function vider_url(?string $url, $entites = true): string {
1371
-	if ($url === null) {
1372
-		return '';
1373
-	}
1374
-	# un message pour abs_url
1375
-	$GLOBALS['mode_abs_url'] = 'url';
1376
-	$url = trim($url);
1377
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1371
+    if ($url === null) {
1372
+        return '';
1373
+    }
1374
+    # un message pour abs_url
1375
+    $GLOBALS['mode_abs_url'] = 'url';
1376
+    $url = trim($url);
1377
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1378 1378
 
1379
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1379
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1380 1380
 }
1381 1381
 
1382 1382
 
@@ -1391,10 +1391,10 @@  discard block
 block discarded – undo
1391 1391
  * @return string Adresse email maquillée
1392 1392
  **/
1393 1393
 function antispam($texte) {
1394
-	include_spip('inc/acces');
1395
-	$masque = creer_pass_aleatoire(3);
1394
+    include_spip('inc/acces');
1395
+    $masque = creer_pass_aleatoire(3);
1396 1396
 
1397
-	return preg_replace('/@/', " $masque ", $texte);
1397
+    return preg_replace('/@/', " $masque ", $texte);
1398 1398
 }
1399 1399
 
1400 1400
 /**
@@ -1426,12 +1426,12 @@  discard block
 block discarded – undo
1426 1426
  *     True si on a le droit d'accès, false sinon.
1427 1427
  **/
1428 1428
 function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') {
1429
-	include_spip('inc/acces');
1430
-	if ($op) {
1431
-		$dir .= " $op $args";
1432
-	}
1429
+    include_spip('inc/acces');
1430
+    if ($op) {
1431
+        $dir .= " $op $args";
1432
+    }
1433 1433
 
1434
-	return verifier_low_sec($id_auteur, $cle, $dir);
1434
+    return verifier_low_sec($id_auteur, $cle, $dir);
1435 1435
 }
1436 1436
 
1437 1437
 /**
@@ -1456,13 +1456,13 @@  discard block
 block discarded – undo
1456 1456
  *     Retourne $texte, sinon $sinon.
1457 1457
  **/
1458 1458
 function sinon($texte, $sinon = '') {
1459
-	if ($texte) {
1460
-		return $texte;
1461
-	} elseif (is_scalar($texte) and strlen($texte)) {
1462
-		return $texte;
1463
-	} else {
1464
-		return $sinon;
1465
-	}
1459
+    if ($texte) {
1460
+        return $texte;
1461
+    } elseif (is_scalar($texte) and strlen($texte)) {
1462
+        return $texte;
1463
+    } else {
1464
+        return $sinon;
1465
+    }
1466 1466
 }
1467 1467
 
1468 1468
 /**
@@ -1486,7 +1486,7 @@  discard block
 block discarded – undo
1486 1486
  * @return mixed
1487 1487
  **/
1488 1488
 function choixsivide($a, $vide, $pasvide) {
1489
-	return $a ? $pasvide : $vide;
1489
+    return $a ? $pasvide : $vide;
1490 1490
 }
1491 1491
 
1492 1492
 /**
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
  * @return mixed
1511 1511
  **/
1512 1512
 function choixsiegal($a1, $a2, $v, $f) {
1513
-	return ($a1 == $a2) ? $v : $f;
1513
+    return ($a1 == $a2) ? $v : $f;
1514 1514
 }
1515 1515
 
1516 1516
 //
@@ -1529,13 +1529,13 @@  discard block
 block discarded – undo
1529 1529
  * @return string
1530 1530
  **/
1531 1531
 function filtrer_ical($texte) {
1532
-	#include_spip('inc/charsets');
1533
-	$texte = html2unicode($texte);
1534
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1535
-	$texte = preg_replace("/\n/", ' ', $texte);
1536
-	$texte = preg_replace('/,/', '\,', $texte);
1532
+    #include_spip('inc/charsets');
1533
+    $texte = html2unicode($texte);
1534
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1535
+    $texte = preg_replace("/\n/", ' ', $texte);
1536
+    $texte = preg_replace('/,/', '\,', $texte);
1537 1537
 
1538
-	return $texte;
1538
+    return $texte;
1539 1539
 }
1540 1540
 
1541 1541
 
@@ -1560,54 +1560,54 @@  discard block
 block discarded – undo
1560 1560
  * @return string
1561 1561
  **/
1562 1562
 function post_autobr($texte, $delim = "\n_ ") {
1563
-	if (!function_exists('echappe_html')) {
1564
-		include_spip('inc/texte_mini');
1565
-	}
1566
-	$texte = str_replace("\r\n", "\r", $texte);
1567
-	$texte = str_replace("\r", "\n", $texte);
1568
-
1569
-	if (preg_match(",\n+$,", $texte, $fin)) {
1570
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1571
-	} else {
1572
-		$fin = '';
1573
-	}
1574
-
1575
-	$texte = echappe_html($texte, '', true);
1576
-
1577
-	// echapper les modeles
1578
-	if (strpos($texte, '<') !== false) {
1579
-		include_spip('inc/lien');
1580
-		if (defined('_PREG_MODELE')) {
1581
-			$preg_modeles = '@' . _PREG_MODELE . '@imsS';
1582
-			$texte = echappe_html($texte, '', true, $preg_modeles);
1583
-		}
1584
-	}
1585
-
1586
-	$debut = '';
1587
-	$suite = $texte;
1588
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1589
-		$debut .= substr($suite, 0, $t - 1);
1590
-		$suite = substr($suite, $t);
1591
-		$car = substr($suite, 0, 1);
1592
-		if (
1593
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1594
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1595
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1596
-		) {
1597
-			$debut .= $delim;
1598
-		} else {
1599
-			$debut .= "\n";
1600
-		}
1601
-		if (preg_match(",^\n+,", $suite, $regs)) {
1602
-			$debut .= $regs[0];
1603
-			$suite = substr($suite, strlen($regs[0]));
1604
-		}
1605
-	}
1606
-	$texte = $debut . $suite;
1607
-
1608
-	$texte = echappe_retour($texte);
1609
-
1610
-	return $texte . $fin;
1563
+    if (!function_exists('echappe_html')) {
1564
+        include_spip('inc/texte_mini');
1565
+    }
1566
+    $texte = str_replace("\r\n", "\r", $texte);
1567
+    $texte = str_replace("\r", "\n", $texte);
1568
+
1569
+    if (preg_match(",\n+$,", $texte, $fin)) {
1570
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1571
+    } else {
1572
+        $fin = '';
1573
+    }
1574
+
1575
+    $texte = echappe_html($texte, '', true);
1576
+
1577
+    // echapper les modeles
1578
+    if (strpos($texte, '<') !== false) {
1579
+        include_spip('inc/lien');
1580
+        if (defined('_PREG_MODELE')) {
1581
+            $preg_modeles = '@' . _PREG_MODELE . '@imsS';
1582
+            $texte = echappe_html($texte, '', true, $preg_modeles);
1583
+        }
1584
+    }
1585
+
1586
+    $debut = '';
1587
+    $suite = $texte;
1588
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1589
+        $debut .= substr($suite, 0, $t - 1);
1590
+        $suite = substr($suite, $t);
1591
+        $car = substr($suite, 0, 1);
1592
+        if (
1593
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1594
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1595
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1596
+        ) {
1597
+            $debut .= $delim;
1598
+        } else {
1599
+            $debut .= "\n";
1600
+        }
1601
+        if (preg_match(",^\n+,", $suite, $regs)) {
1602
+            $debut .= $regs[0];
1603
+            $suite = substr($suite, strlen($regs[0]));
1604
+        }
1605
+    }
1606
+    $texte = $debut . $suite;
1607
+
1608
+    $texte = echappe_retour($texte);
1609
+
1610
+    return $texte . $fin;
1611 1611
 }
1612 1612
 
1613 1613
 
@@ -1648,47 +1648,47 @@  discard block
 block discarded – undo
1648 1648
  * @return string
1649 1649
  **/
1650 1650
 function extraire_idiome($letexte, $lang = null, $options = []) {
1651
-	static $traduire = false;
1652
-	if (
1653
-		$letexte
1654
-		and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1655
-	) {
1656
-		if (!$traduire) {
1657
-			$traduire = charger_fonction('traduire', 'inc');
1658
-			include_spip('inc/lang');
1659
-		}
1660
-		if (!$lang) {
1661
-			$lang = $GLOBALS['spip_lang'];
1662
-		}
1663
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1664
-		if (is_bool($options)) {
1665
-			$options = ['echappe_span' => $options];
1666
-		}
1667
-		if (!isset($options['echappe_span'])) {
1668
-			$options = array_merge($options, ['echappe_span' => false]);
1669
-		}
1670
-
1671
-		foreach ($regs as $reg) {
1672
-			$cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1673
-			$desc = $traduire($cle, $lang, true);
1674
-			$l = $desc->langue;
1675
-			// si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1676
-			if (strlen($desc->texte)) {
1677
-				$trad = code_echappement($desc->texte, 'idiome', false);
1678
-				if ($l !== $lang) {
1679
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1680
-				}
1681
-				if (lang_dir($l) !== lang_dir($lang)) {
1682
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1683
-				}
1684
-				if (!$options['echappe_span']) {
1685
-					$trad = echappe_retour($trad, 'idiome');
1686
-				}
1687
-				$letexte = str_replace($reg[0], $trad, $letexte);
1688
-			}
1689
-		}
1690
-	}
1691
-	return $letexte;
1651
+    static $traduire = false;
1652
+    if (
1653
+        $letexte
1654
+        and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER)
1655
+    ) {
1656
+        if (!$traduire) {
1657
+            $traduire = charger_fonction('traduire', 'inc');
1658
+            include_spip('inc/lang');
1659
+        }
1660
+        if (!$lang) {
1661
+            $lang = $GLOBALS['spip_lang'];
1662
+        }
1663
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1664
+        if (is_bool($options)) {
1665
+            $options = ['echappe_span' => $options];
1666
+        }
1667
+        if (!isset($options['echappe_span'])) {
1668
+            $options = array_merge($options, ['echappe_span' => false]);
1669
+        }
1670
+
1671
+        foreach ($regs as $reg) {
1672
+            $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2];
1673
+            $desc = $traduire($cle, $lang, true);
1674
+            $l = $desc->langue;
1675
+            // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte.
1676
+            if (strlen($desc->texte)) {
1677
+                $trad = code_echappement($desc->texte, 'idiome', false);
1678
+                if ($l !== $lang) {
1679
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1680
+                }
1681
+                if (lang_dir($l) !== lang_dir($lang)) {
1682
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1683
+                }
1684
+                if (!$options['echappe_span']) {
1685
+                    $trad = echappe_retour($trad, 'idiome');
1686
+                }
1687
+                $letexte = str_replace($reg[0], $trad, $letexte);
1688
+            }
1689
+        }
1690
+    }
1691
+    return $letexte;
1692 1692
 }
1693 1693
 
1694 1694
 /**
@@ -1740,68 +1740,68 @@  discard block
 block discarded – undo
1740 1740
  **/
1741 1741
 function extraire_multi($letexte, $lang = null, $options = []) {
1742 1742
 
1743
-	if (
1744
-		$letexte
1745
-		and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1746
-	) {
1747
-		if (!$lang) {
1748
-			$lang = $GLOBALS['spip_lang'];
1749
-		}
1750
-
1751
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1752
-		if (is_bool($options)) {
1753
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1754
-		}
1755
-		if (!isset($options['echappe_span'])) {
1756
-			$options = array_merge($options, ['echappe_span' => false]);
1757
-		}
1758
-		if (!isset($options['lang_defaut'])) {
1759
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1760
-		}
1761
-
1762
-		include_spip('inc/lang');
1763
-		foreach ($regs as $reg) {
1764
-			// chercher la version de la langue courante
1765
-			$trads = extraire_trads($reg[1]);
1766
-			if ($l = approcher_langue($trads, $lang)) {
1767
-				$trad = $trads[$l];
1768
-			} else {
1769
-				if ($options['lang_defaut'] == 'aucune') {
1770
-					$trad = '';
1771
-				} else {
1772
-					// langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1773
-					// ou la premiere dispo
1774
-					// mais typographier le texte selon les regles de celle-ci
1775
-					// Attention aux blocs multi sur plusieurs lignes
1776
-					if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1777
-						$l = key($trads);
1778
-					}
1779
-					$trad = $trads[$l];
1780
-					$typographie = charger_fonction(lang_typo($l), 'typographie');
1781
-					$trad = $typographie($trad);
1782
-					// Tester si on echappe en span ou en div
1783
-					// il ne faut pas echapper en div si propre produit un seul paragraphe
1784
-					include_spip('inc/texte');
1785
-					$trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
-					$mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787
-					if ($mode === 'div') {
1788
-						$trad = rtrim($trad) . "\n\n";
1789
-					}
1790
-					$trad = code_echappement($trad, 'multi', false, $mode);
1791
-					$trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1792
-					if (lang_dir($l) !== lang_dir($lang)) {
1793
-						$trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1794
-					}
1795
-					if (!$options['echappe_span']) {
1796
-						$trad = echappe_retour($trad, 'multi');
1797
-					}
1798
-				}
1799
-			}
1800
-			$letexte = str_replace($reg[0], $trad, $letexte);
1801
-		}
1802
-	}
1803
-
1804
-	return $letexte;
1743
+    if (
1744
+        $letexte
1745
+        and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER)
1746
+    ) {
1747
+        if (!$lang) {
1748
+            $lang = $GLOBALS['spip_lang'];
1749
+        }
1750
+
1751
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1752
+        if (is_bool($options)) {
1753
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1754
+        }
1755
+        if (!isset($options['echappe_span'])) {
1756
+            $options = array_merge($options, ['echappe_span' => false]);
1757
+        }
1758
+        if (!isset($options['lang_defaut'])) {
1759
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1760
+        }
1761
+
1762
+        include_spip('inc/lang');
1763
+        foreach ($regs as $reg) {
1764
+            // chercher la version de la langue courante
1765
+            $trads = extraire_trads($reg[1]);
1766
+            if ($l = approcher_langue($trads, $lang)) {
1767
+                $trad = $trads[$l];
1768
+            } else {
1769
+                if ($options['lang_defaut'] == 'aucune') {
1770
+                    $trad = '';
1771
+                } else {
1772
+                    // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php)
1773
+                    // ou la premiere dispo
1774
+                    // mais typographier le texte selon les regles de celle-ci
1775
+                    // Attention aux blocs multi sur plusieurs lignes
1776
+                    if (!$l = approcher_langue($trads, $options['lang_defaut'])) {
1777
+                        $l = key($trads);
1778
+                    }
1779
+                    $trad = $trads[$l];
1780
+                    $typographie = charger_fonction(lang_typo($l), 'typographie');
1781
+                    $trad = $typographie($trad);
1782
+                    // Tester si on echappe en span ou en div
1783
+                    // il ne faut pas echapper en div si propre produit un seul paragraphe
1784
+                    include_spip('inc/texte');
1785
+                    $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad));
1786
+                    $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span';
1787
+                    if ($mode === 'div') {
1788
+                        $trad = rtrim($trad) . "\n\n";
1789
+                    }
1790
+                    $trad = code_echappement($trad, 'multi', false, $mode);
1791
+                    $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l));
1792
+                    if (lang_dir($l) !== lang_dir($lang)) {
1793
+                        $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l)));
1794
+                    }
1795
+                    if (!$options['echappe_span']) {
1796
+                        $trad = echappe_retour($trad, 'multi');
1797
+                    }
1798
+                }
1799
+            }
1800
+            $letexte = str_replace($reg[0], $trad, $letexte);
1801
+        }
1802
+    }
1803
+
1804
+    return $letexte;
1805 1805
 }
1806 1806
 
1807 1807
 /**
@@ -1817,21 +1817,21 @@  discard block
 block discarded – undo
1817 1817
  *     Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué.
1818 1818
  **/
1819 1819
 function extraire_trads($bloc) {
1820
-	$trads = [];
1821
-	$lang = '';
1820
+    $trads = [];
1821
+    $lang = '';
1822 1822
 // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ
1823 1823
 //	while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) {
1824
-	while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1825
-		$texte = trim($regs[1]);
1826
-		if ($texte or $lang) {
1827
-			$trads[$lang] = $texte;
1828
-		}
1829
-		$bloc = substr($bloc, strlen($regs[0]));
1830
-		$lang = $regs[2];
1831
-	}
1832
-	$trads[$lang] = $bloc;
1824
+    while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) {
1825
+        $texte = trim($regs[1]);
1826
+        if ($texte or $lang) {
1827
+            $trads[$lang] = $texte;
1828
+        }
1829
+        $bloc = substr($bloc, strlen($regs[0]));
1830
+        $lang = $regs[2];
1831
+    }
1832
+    $trads[$lang] = $bloc;
1833 1833
 
1834
-	return $trads;
1834
+    return $trads;
1835 1835
 }
1836 1836
 
1837 1837
 
@@ -1842,7 +1842,7 @@  discard block
 block discarded – undo
1842 1842
  * @return string L'initiale en majuscule
1843 1843
  */
1844 1844
 function filtre_initiale($nom) {
1845
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1845
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1846 1846
 }
1847 1847
 
1848 1848
 
@@ -1887,33 +1887,33 @@  discard block
 block discarded – undo
1887 1887
  *      - null (interne) : si on empile
1888 1888
  **/
1889 1889
 function unique($donnee, $famille = '', $cpt = false) {
1890
-	static $mem = [];
1891
-	// permettre de vider la pile et de la restaurer
1892
-	// pour le calcul de introduction...
1893
-	if ($famille == '_spip_raz_') {
1894
-		$tmp = $mem;
1895
-		$mem = [];
1896
-
1897
-		return $tmp;
1898
-	} elseif ($famille == '_spip_set_') {
1899
-		$mem = $donnee;
1900
-
1901
-		return;
1902
-	}
1903
-	// eviter une notice
1904
-	if (!isset($mem[$famille])) {
1905
-		$mem[$famille] = [];
1906
-	}
1907
-	if ($cpt) {
1908
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1909
-	}
1910
-	// eviter une notice
1911
-	if (!isset($mem[$famille][$donnee])) {
1912
-		$mem[$famille][$donnee] = 0;
1913
-	}
1914
-	if (!($mem[$famille][$donnee]++)) {
1915
-		return $donnee;
1916
-	}
1890
+    static $mem = [];
1891
+    // permettre de vider la pile et de la restaurer
1892
+    // pour le calcul de introduction...
1893
+    if ($famille == '_spip_raz_') {
1894
+        $tmp = $mem;
1895
+        $mem = [];
1896
+
1897
+        return $tmp;
1898
+    } elseif ($famille == '_spip_set_') {
1899
+        $mem = $donnee;
1900
+
1901
+        return;
1902
+    }
1903
+    // eviter une notice
1904
+    if (!isset($mem[$famille])) {
1905
+        $mem[$famille] = [];
1906
+    }
1907
+    if ($cpt) {
1908
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1909
+    }
1910
+    // eviter une notice
1911
+    if (!isset($mem[$famille][$donnee])) {
1912
+        $mem[$famille][$donnee] = 0;
1913
+    }
1914
+    if (!($mem[$famille][$donnee]++)) {
1915
+        return $donnee;
1916
+    }
1917 1917
 }
1918 1918
 
1919 1919
 
@@ -1943,16 +1943,16 @@  discard block
 block discarded – undo
1943 1943
  *     Une des valeurs en fonction du compteur.
1944 1944
  **/
1945 1945
 function alterner($i, ...$args) {
1946
-	// recuperer les arguments (attention fonctions un peu space)
1947
-	$num = count($args);
1946
+    // recuperer les arguments (attention fonctions un peu space)
1947
+    $num = count($args);
1948 1948
 
1949
-	if ($num === 1 && is_array($args[0])) {
1950
-		$args = $args[0];
1951
-		$num = count($args);
1952
-	}
1949
+    if ($num === 1 && is_array($args[0])) {
1950
+        $args = $args[0];
1951
+        $num = count($args);
1952
+    }
1953 1953
 
1954
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1955
-	return $args[(intval($i) - 1) % $num];
1954
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1955
+    return $args[(intval($i) - 1) % $num];
1956 1956
 }
1957 1957
 
1958 1958
 
@@ -1978,51 +1978,51 @@  discard block
 block discarded – undo
1978 1978
  *     - null lorsque l’attribut n’existe pas.
1979 1979
  **/
1980 1980
 function extraire_attribut($balise, $attribut, $complet = false) {
1981
-	if (is_array($balise)) {
1982
-		array_walk(
1983
-			$balise,
1984
-			function (&$a, $key, $t) {
1985
-				$a = extraire_attribut($a, $t);
1986
-			},
1987
-			$attribut
1988
-		);
1989
-
1990
-		return $balise;
1991
-	}
1992
-	if (
1993
-		$balise
1994
-		&& preg_match(
1995
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1996
-			. $attribut
1997
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1998
-			$balise,
1999
-			$r
2000
-		)
2001
-	) {
2002
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2003
-			$r[4] = substr($r[3], 1, -1);
2004
-			$r[3] = $r[3][0];
2005
-		} elseif ($r[3] !== '') {
2006
-			$r[4] = $r[3];
2007
-			$r[3] = '';
2008
-		} else {
2009
-			$r[4] = trim($r[2]);
2010
-		}
2011
-		$att = $r[4];
2012
-		if (strpos($att, '&#') !== false) {
2013
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2014
-		}
2015
-		$att = filtrer_entites($att);
2016
-	} else {
2017
-		$att = null;
2018
-		$r = [];
2019
-	}
2020
-
2021
-	if ($complet) {
2022
-		return [$att, $r];
2023
-	} else {
2024
-		return $att;
2025
-	}
1981
+    if (is_array($balise)) {
1982
+        array_walk(
1983
+            $balise,
1984
+            function (&$a, $key, $t) {
1985
+                $a = extraire_attribut($a, $t);
1986
+            },
1987
+            $attribut
1988
+        );
1989
+
1990
+        return $balise;
1991
+    }
1992
+    if (
1993
+        $balise
1994
+        && preg_match(
1995
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1996
+            . $attribut
1997
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1998
+            $balise,
1999
+            $r
2000
+        )
2001
+    ) {
2002
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
2003
+            $r[4] = substr($r[3], 1, -1);
2004
+            $r[3] = $r[3][0];
2005
+        } elseif ($r[3] !== '') {
2006
+            $r[4] = $r[3];
2007
+            $r[3] = '';
2008
+        } else {
2009
+            $r[4] = trim($r[2]);
2010
+        }
2011
+        $att = $r[4];
2012
+        if (strpos($att, '&#') !== false) {
2013
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
2014
+        }
2015
+        $att = filtrer_entites($att);
2016
+    } else {
2017
+        $att = null;
2018
+        $r = [];
2019
+    }
2020
+
2021
+    if ($complet) {
2022
+        return [$att, $r];
2023
+    } else {
2024
+        return $att;
2025
+    }
2026 2026
 }
2027 2027
 
2028 2028
 /**
@@ -2055,41 +2055,41 @@  discard block
 block discarded – undo
2055 2055
  **/
2056 2056
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2057 2057
 
2058
-	if ($balise === null or $balise === '') {
2059
-		return '';
2060
-	}
2058
+    if ($balise === null or $balise === '') {
2059
+        return '';
2060
+    }
2061 2061
 
2062
-	// preparer l'attribut
2063
-	// supprimer les &nbsp; etc mais pas les balises html
2064
-	// qui ont un sens dans un attribut value d'un input
2065
-	if ($proteger) {
2066
-		$val = attribut_html($val, false);
2067
-	}
2062
+    // preparer l'attribut
2063
+    // supprimer les &nbsp; etc mais pas les balises html
2064
+    // qui ont un sens dans un attribut value d'un input
2065
+    if ($proteger) {
2066
+        $val = attribut_html($val, false);
2067
+    }
2068 2068
 
2069
-	// echapper les ' pour eviter tout bug
2070
-	$val = str_replace("'", '&#039;', $val);
2071
-	if ($vider and strlen($val) === 0) {
2072
-		$insert = '';
2073
-	} else {
2074
-		$insert = " $attribut='$val'";
2075
-	}
2069
+    // echapper les ' pour eviter tout bug
2070
+    $val = str_replace("'", '&#039;', $val);
2071
+    if ($vider and strlen($val) === 0) {
2072
+        $insert = '';
2073
+    } else {
2074
+        $insert = " $attribut='$val'";
2075
+    }
2076 2076
 
2077
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2077
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2078 2078
 
2079
-	if ($old !== null) {
2080
-		// Remplacer l'ancien attribut du meme nom
2081
-		$balise = $r[1] . $insert . $r[5];
2082
-	} else {
2083
-		// preferer une balise " />" (comme <img />)
2084
-		if (preg_match(',/>,', $balise)) {
2085
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2086
-		} // sinon une balise <a ...> ... </a>
2087
-		else {
2088
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2089
-		}
2090
-	}
2079
+    if ($old !== null) {
2080
+        // Remplacer l'ancien attribut du meme nom
2081
+        $balise = $r[1] . $insert . $r[5];
2082
+    } else {
2083
+        // preferer une balise " />" (comme <img />)
2084
+        if (preg_match(',/>,', $balise)) {
2085
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2086
+        } // sinon une balise <a ...> ... </a>
2087
+        else {
2088
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2089
+        }
2090
+    }
2091 2091
 
2092
-	return $balise;
2092
+    return $balise;
2093 2093
 }
2094 2094
 
2095 2095
 /**
@@ -2107,7 +2107,7 @@  discard block
 block discarded – undo
2107 2107
  * @return string Code HTML sans l'attribut
2108 2108
  **/
2109 2109
 function vider_attribut(?string $balise, string $attribut): string {
2110
-	return inserer_attribut($balise, $attribut, '', false, true);
2110
+    return inserer_attribut($balise, $attribut, '', false, true);
2111 2111
 }
2112 2112
 
2113 2113
 /**
@@ -2119,53 +2119,53 @@  discard block
 block discarded – undo
2119 2119
  * @return string
2120 2120
  */
2121 2121
 function modifier_class($balise, $class, $operation = 'ajouter') {
2122
-	if (is_string($class)) {
2123
-		$class = explode(' ', trim($class));
2124
-	}
2125
-	$class = array_filter($class);
2126
-	$class = array_unique($class);
2127
-	if (!$class) {
2128
-		return $balise;
2129
-	}
2130
-
2131
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2132
-	if (preg_match(',[^\w-],', implode('', $class))) {
2133
-		return $balise;
2134
-	}
2135
-
2136
-	$class_courante = extraire_attribut($balise, 'class');
2137
-	$class_new = $class_courante;
2138
-	foreach ($class as $c) {
2139
-		$is_class_presente = false;
2140
-		if (
2141
-			$class_courante
2142
-			and strpos($class_courante, (string) $c) !== false
2143
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2144
-		) {
2145
-			$is_class_presente = true;
2146
-		}
2147
-		if (
2148
-			in_array($operation, ['ajouter', 'commuter'])
2149
-			and !$is_class_presente
2150
-		) {
2151
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2152
-		} elseif (
2153
-			in_array($operation, ['supprimer', 'commuter'])
2154
-			and $is_class_presente
2155
-		) {
2156
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2157
-		}
2158
-	}
2159
-
2160
-	if ($class_new !== $class_courante) {
2161
-		if (strlen($class_new)) {
2162
-			$balise = inserer_attribut($balise, 'class', $class_new);
2163
-		} elseif ($class_courante) {
2164
-			$balise = vider_attribut($balise, 'class');
2165
-		}
2166
-	}
2167
-
2168
-	return $balise;
2122
+    if (is_string($class)) {
2123
+        $class = explode(' ', trim($class));
2124
+    }
2125
+    $class = array_filter($class);
2126
+    $class = array_unique($class);
2127
+    if (!$class) {
2128
+        return $balise;
2129
+    }
2130
+
2131
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2132
+    if (preg_match(',[^\w-],', implode('', $class))) {
2133
+        return $balise;
2134
+    }
2135
+
2136
+    $class_courante = extraire_attribut($balise, 'class');
2137
+    $class_new = $class_courante;
2138
+    foreach ($class as $c) {
2139
+        $is_class_presente = false;
2140
+        if (
2141
+            $class_courante
2142
+            and strpos($class_courante, (string) $c) !== false
2143
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2144
+        ) {
2145
+            $is_class_presente = true;
2146
+        }
2147
+        if (
2148
+            in_array($operation, ['ajouter', 'commuter'])
2149
+            and !$is_class_presente
2150
+        ) {
2151
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2152
+        } elseif (
2153
+            in_array($operation, ['supprimer', 'commuter'])
2154
+            and $is_class_presente
2155
+        ) {
2156
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2157
+        }
2158
+    }
2159
+
2160
+    if ($class_new !== $class_courante) {
2161
+        if (strlen($class_new)) {
2162
+            $balise = inserer_attribut($balise, 'class', $class_new);
2163
+        } elseif ($class_courante) {
2164
+            $balise = vider_attribut($balise, 'class');
2165
+        }
2166
+    }
2167
+
2168
+    return $balise;
2169 2169
 }
2170 2170
 
2171 2171
 /**
@@ -2175,7 +2175,7 @@  discard block
 block discarded – undo
2175 2175
  * @return string
2176 2176
  */
2177 2177
 function ajouter_class($balise, $class) {
2178
-	return modifier_class($balise, $class, 'ajouter');
2178
+    return modifier_class($balise, $class, 'ajouter');
2179 2179
 }
2180 2180
 
2181 2181
 /**
@@ -2185,7 +2185,7 @@  discard block
 block discarded – undo
2185 2185
  * @return string
2186 2186
  */
2187 2187
 function supprimer_class($balise, $class) {
2188
-	return modifier_class($balise, $class, 'supprimer');
2188
+    return modifier_class($balise, $class, 'supprimer');
2189 2189
 }
2190 2190
 
2191 2191
 /**
@@ -2196,7 +2196,7 @@  discard block
 block discarded – undo
2196 2196
  * @return string
2197 2197
  */
2198 2198
 function commuter_class($balise, $class) {
2199
-	return modifier_class($balise, $class, 'commuter');
2199
+    return modifier_class($balise, $class, 'commuter');
2200 2200
 }
2201 2201
 
2202 2202
 /**
@@ -2207,19 +2207,19 @@  discard block
 block discarded – undo
2207 2207
  * @return string
2208 2208
  */
2209 2209
 function tester_config($id, $mode = '') {
2210
-	include_spip('action/inscrire_auteur');
2210
+    include_spip('action/inscrire_auteur');
2211 2211
 
2212
-	return tester_statut_inscription($mode, $id);
2212
+    return tester_statut_inscription($mode, $id);
2213 2213
 }
2214 2214
 
2215 2215
 //
2216 2216
 // Quelques fonctions de calcul arithmetique
2217 2217
 //
2218 2218
 function floatstr($a) {
2219
- return str_replace(',', '.', (string)floatval($a));
2219
+    return str_replace(',', '.', (string)floatval($a));
2220 2220
 }
2221 2221
 function strize($f, $a, $b) {
2222
- return floatstr($f(floatstr($a), floatstr($b)));
2222
+    return floatstr($f(floatstr($a), floatstr($b)));
2223 2223
 }
2224 2224
 
2225 2225
 /**
@@ -2238,7 +2238,7 @@  discard block
 block discarded – undo
2238 2238
  * @return int $a+$b
2239 2239
  **/
2240 2240
 function plus($a, $b) {
2241
-	return $a + $b;
2241
+    return $a + $b;
2242 2242
 }
2243 2243
 function strplus($a, $b) {
2244 2244
 return strize('plus', $a, $b);
@@ -2259,7 +2259,7 @@  discard block
 block discarded – undo
2259 2259
  * @return int $a-$b
2260 2260
  **/
2261 2261
 function moins($a, $b) {
2262
-	return $a - $b;
2262
+    return $a - $b;
2263 2263
 }
2264 2264
 function strmoins($a, $b) {
2265 2265
 return strize('moins', $a, $b);
@@ -2282,7 +2282,7 @@  discard block
 block discarded – undo
2282 2282
  * @return int $a*$b
2283 2283
  **/
2284 2284
 function mult($a, $b) {
2285
-	return $a * $b;
2285
+    return $a * $b;
2286 2286
 }
2287 2287
 function strmult($a, $b) {
2288 2288
 return strize('mult', $a, $b);
@@ -2305,7 +2305,7 @@  discard block
 block discarded – undo
2305 2305
  * @return int $a/$b (ou 0 si $b est nul)
2306 2306
  **/
2307 2307
 function div($a, $b) {
2308
-	return $b ? $a / $b : 0;
2308
+    return $b ? $a / $b : 0;
2309 2309
 }
2310 2310
 function strdiv($a, $b) {
2311 2311
 return strize('div', $a, $b);
@@ -2329,7 +2329,7 @@  discard block
 block discarded – undo
2329 2329
  * @return int ($nb % $mod) + $add
2330 2330
  **/
2331 2331
 function modulo($nb, $mod, $add = 0) {
2332
-	return ($mod ? $nb % $mod : 0) + $add;
2332
+    return ($mod ? $nb % $mod : 0) + $add;
2333 2333
 }
2334 2334
 
2335 2335
 
@@ -2344,26 +2344,26 @@  discard block
 block discarded – undo
2344 2344
  *      - true sinon
2345 2345
  **/
2346 2346
 function nom_acceptable($nom) {
2347
-	$remp2 = [];
2348
-	$remp1 = [];
2349
-	if (!is_string($nom)) {
2350
-		return false;
2351
-	}
2352
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2353
-		define('_TAGS_NOM_AUTEUR', '');
2354
-	}
2355
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2356
-	foreach ($tags_acceptes as $tag) {
2357
-		if (strlen($tag)) {
2358
-			$remp1[] = '<' . trim($tag) . '>';
2359
-			$remp1[] = '</' . trim($tag) . '>';
2360
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2361
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2362
-		}
2363
-	}
2364
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2365
-
2366
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2347
+    $remp2 = [];
2348
+    $remp1 = [];
2349
+    if (!is_string($nom)) {
2350
+        return false;
2351
+    }
2352
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2353
+        define('_TAGS_NOM_AUTEUR', '');
2354
+    }
2355
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2356
+    foreach ($tags_acceptes as $tag) {
2357
+        if (strlen($tag)) {
2358
+            $remp1[] = '<' . trim($tag) . '>';
2359
+            $remp1[] = '</' . trim($tag) . '>';
2360
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2361
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2362
+        }
2363
+    }
2364
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2365
+
2366
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2367 2367
 }
2368 2368
 
2369 2369
 
@@ -2379,14 +2379,14 @@  discard block
 block discarded – undo
2379 2379
  *      - renvoie un tableau si l'entree est un tableau
2380 2380
  **/
2381 2381
 function email_valide($adresses) {
2382
-	if (is_array($adresses)) {
2383
-		$adresses = array_map('email_valide', $adresses);
2384
-		$adresses = array_filter($adresses);
2385
-		return $adresses;
2386
-	}
2382
+    if (is_array($adresses)) {
2383
+        $adresses = array_map('email_valide', $adresses);
2384
+        $adresses = array_filter($adresses);
2385
+        return $adresses;
2386
+    }
2387 2387
 
2388
-	$email_valide = charger_fonction('email_valide', 'inc');
2389
-	return $email_valide($adresses);
2388
+    $email_valide = charger_fonction('email_valide', 'inc');
2389
+    return $email_valide($adresses);
2390 2390
 }
2391 2391
 
2392 2392
 /**
@@ -2400,27 +2400,27 @@  discard block
 block discarded – undo
2400 2400
  * @return string Texte
2401 2401
  **/
2402 2402
 function afficher_enclosures($tags) {
2403
-	$s = [];
2404
-	foreach (extraire_balises($tags, 'a') as $tag) {
2405
-		if (
2406
-			extraire_attribut($tag, 'rel') == 'enclosure'
2407
-			and $t = extraire_attribut($tag, 'href')
2408
-		) {
2409
-			$s[] = preg_replace(
2410
-				',>[^<]+</a>,S',
2411
-				'>'
2412
-				. http_img_pack(
2413
-					'attachment-16.png',
2414
-					$t,
2415
-					'title="' . attribut_html($t) . '"'
2416
-				)
2417
-				. '</a>',
2418
-				$tag
2419
-			);
2420
-		}
2421
-	}
2422
-
2423
-	return join('&nbsp;', $s);
2403
+    $s = [];
2404
+    foreach (extraire_balises($tags, 'a') as $tag) {
2405
+        if (
2406
+            extraire_attribut($tag, 'rel') == 'enclosure'
2407
+            and $t = extraire_attribut($tag, 'href')
2408
+        ) {
2409
+            $s[] = preg_replace(
2410
+                ',>[^<]+</a>,S',
2411
+                '>'
2412
+                . http_img_pack(
2413
+                    'attachment-16.png',
2414
+                    $t,
2415
+                    'title="' . attribut_html($t) . '"'
2416
+                )
2417
+                . '</a>',
2418
+                $tag
2419
+            );
2420
+        }
2421
+    }
2422
+
2423
+    return join('&nbsp;', $s);
2424 2424
 }
2425 2425
 
2426 2426
 /**
@@ -2435,15 +2435,15 @@  discard block
 block discarded – undo
2435 2435
  * @return string Liens trouvés
2436 2436
  **/
2437 2437
 function afficher_tags($tags, $rels = 'tag,directory') {
2438
-	$s = [];
2439
-	foreach (extraire_balises($tags, 'a') as $tag) {
2440
-		$rel = extraire_attribut($tag, 'rel');
2441
-		if (strstr(",$rels,", (string) ",$rel,")) {
2442
-			$s[] = $tag;
2443
-		}
2444
-	}
2438
+    $s = [];
2439
+    foreach (extraire_balises($tags, 'a') as $tag) {
2440
+        $rel = extraire_attribut($tag, 'rel');
2441
+        if (strstr(",$rels,", (string) ",$rel,")) {
2442
+            $s[] = $tag;
2443
+        }
2444
+    }
2445 2445
 
2446
-	return join(', ', $s);
2446
+    return join(', ', $s);
2447 2447
 }
2448 2448
 
2449 2449
 
@@ -2465,21 +2465,21 @@  discard block
 block discarded – undo
2465 2465
  * @return string Tag HTML `<a>` avec microformat.
2466 2466
  **/
2467 2467
 function enclosure2microformat($e) {
2468
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2469
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2470
-	}
2471
-	$type = extraire_attribut($e, 'type');
2472
-	if (!$length = extraire_attribut($e, 'length')) {
2473
-		# <media:content : longeur dans fileSize. On tente.
2474
-		$length = extraire_attribut($e, 'fileSize');
2475
-	}
2476
-	$fichier = basename($url);
2468
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2469
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2470
+    }
2471
+    $type = extraire_attribut($e, 'type');
2472
+    if (!$length = extraire_attribut($e, 'length')) {
2473
+        # <media:content : longeur dans fileSize. On tente.
2474
+        $length = extraire_attribut($e, 'fileSize');
2475
+    }
2476
+    $fichier = basename($url);
2477 2477
 
2478
-	return '<a rel="enclosure"'
2479
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2480
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2481
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2482
-	. '>' . $fichier . '</a>';
2478
+    return '<a rel="enclosure"'
2479
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2480
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2481
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2482
+    . '>' . $fichier . '</a>';
2483 2483
 }
2484 2484
 
2485 2485
 /**
@@ -2497,24 +2497,24 @@  discard block
 block discarded – undo
2497 2497
  * @return string Tags RSS `<enclosure>`.
2498 2498
  **/
2499 2499
 function microformat2enclosure($tags) {
2500
-	$enclosures = [];
2501
-	foreach (extraire_balises($tags, 'a') as $e) {
2502
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2503
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2504
-			$type = extraire_attribut($e, 'type');
2505
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2506
-				$length = intval(extraire_attribut($e, 'length'));
2507
-			} # vieux data
2508
-			$fichier = basename($url);
2509
-			$enclosures[] = '<enclosure'
2510
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2511
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2512
-				. ($length ? ' length="' . $length . '"' : '')
2513
-				. ' />';
2514
-		}
2515
-	}
2500
+    $enclosures = [];
2501
+    foreach (extraire_balises($tags, 'a') as $e) {
2502
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2503
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2504
+            $type = extraire_attribut($e, 'type');
2505
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2506
+                $length = intval(extraire_attribut($e, 'length'));
2507
+            } # vieux data
2508
+            $fichier = basename($url);
2509
+            $enclosures[] = '<enclosure'
2510
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2511
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2512
+                . ($length ? ' length="' . $length . '"' : '')
2513
+                . ' />';
2514
+        }
2515
+    }
2516 2516
 
2517
-	return join("\n", $enclosures);
2517
+    return join("\n", $enclosures);
2518 2518
 }
2519 2519
 
2520 2520
 
@@ -2530,16 +2530,16 @@  discard block
 block discarded – undo
2530 2530
  * @return string Tags RSS Atom `<dc:subject>`.
2531 2531
  **/
2532 2532
 function tags2dcsubject($tags) {
2533
-	$subjects = '';
2534
-	foreach (extraire_balises($tags, 'a') as $e) {
2535
-		if (extraire_attribut($e, 'rel') == 'tag') {
2536
-			$subjects .= '<dc:subject>'
2537
-				. texte_backend(textebrut($e))
2538
-				. '</dc:subject>' . "\n";
2539
-		}
2540
-	}
2533
+    $subjects = '';
2534
+    foreach (extraire_balises($tags, 'a') as $e) {
2535
+        if (extraire_attribut($e, 'rel') == 'tag') {
2536
+            $subjects .= '<dc:subject>'
2537
+                . texte_backend(textebrut($e))
2538
+                . '</dc:subject>' . "\n";
2539
+        }
2540
+    }
2541 2541
 
2542
-	return $subjects;
2542
+    return $subjects;
2543 2543
 }
2544 2544
 
2545 2545
 /**
@@ -2568,27 +2568,27 @@  discard block
 block discarded – undo
2568 2568
  *     - Tableau de résultats, si tableau en entrée.
2569 2569
  **/
2570 2570
 function extraire_balise($texte, $tag = 'a') {
2571
-	if (is_array($texte)) {
2572
-		array_walk(
2573
-			$texte,
2574
-			function (&$a, $key, $t) {
2575
-				$a = extraire_balise($a, $t);
2576
-			},
2577
-			$tag
2578
-		);
2579
-
2580
-		return $texte;
2581
-	}
2582
-
2583
-	if (
2584
-		preg_match(
2585
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2586
-			$texte,
2587
-			$regs
2588
-		)
2589
-	) {
2590
-		return $regs[0];
2591
-	}
2571
+    if (is_array($texte)) {
2572
+        array_walk(
2573
+            $texte,
2574
+            function (&$a, $key, $t) {
2575
+                $a = extraire_balise($a, $t);
2576
+            },
2577
+            $tag
2578
+        );
2579
+
2580
+        return $texte;
2581
+    }
2582
+
2583
+    if (
2584
+        preg_match(
2585
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2586
+            $texte,
2587
+            $regs
2588
+        )
2589
+    ) {
2590
+        return $regs[0];
2591
+    }
2592 2592
 }
2593 2593
 
2594 2594
 /**
@@ -2616,30 +2616,30 @@  discard block
 block discarded – undo
2616 2616
  *     - Tableau de résultats, si tableau en entrée.
2617 2617
  **/
2618 2618
 function extraire_balises($texte, $tag = 'a') {
2619
-	if (is_array($texte)) {
2620
-		array_walk(
2621
-			$texte,
2622
-			function (&$a, $key, $t) {
2623
-				$a = extraire_balises($a, $t);
2624
-			},
2625
-			$tag
2626
-		);
2627
-
2628
-		return $texte;
2629
-	}
2630
-
2631
-	if (
2632
-		preg_match_all(
2633
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2634
-			$texte,
2635
-			$regs,
2636
-			PREG_PATTERN_ORDER
2637
-		)
2638
-	) {
2639
-		return $regs[0];
2640
-	} else {
2641
-		return [];
2642
-	}
2619
+    if (is_array($texte)) {
2620
+        array_walk(
2621
+            $texte,
2622
+            function (&$a, $key, $t) {
2623
+                $a = extraire_balises($a, $t);
2624
+            },
2625
+            $tag
2626
+        );
2627
+
2628
+        return $texte;
2629
+    }
2630
+
2631
+    if (
2632
+        preg_match_all(
2633
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2634
+            $texte,
2635
+            $regs,
2636
+            PREG_PATTERN_ORDER
2637
+        )
2638
+    ) {
2639
+        return $regs[0];
2640
+    } else {
2641
+        return [];
2642
+    }
2643 2643
 }
2644 2644
 
2645 2645
 /**
@@ -2668,11 +2668,11 @@  discard block
 block discarded – undo
2668 2668
  *     - `$def` si on n'a pas transmis de tableau
2669 2669
  **/
2670 2670
 function in_any($val, $vals, $def = '') {
2671
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2672
-		$vals = $v;
2673
-	}
2671
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2672
+        $vals = $v;
2673
+    }
2674 2674
 
2675
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2675
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2676 2676
 }
2677 2677
 
2678 2678
 
@@ -2693,12 +2693,12 @@  discard block
 block discarded – undo
2693 2693
  *     Résultat du calcul
2694 2694
  **/
2695 2695
 function valeur_numerique($expr) {
2696
-	$a = 0;
2697
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2698
-		eval("\$a = $expr;");
2699
-	}
2696
+    $a = 0;
2697
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2698
+        eval("\$a = $expr;");
2699
+    }
2700 2700
 
2701
-	return intval($a);
2701
+    return intval($a);
2702 2702
 }
2703 2703
 
2704 2704
 /**
@@ -2717,7 +2717,7 @@  discard block
 block discarded – undo
2717 2717
  *      Retourne `$a*$b/$c`
2718 2718
  **/
2719 2719
 function regledetrois($a, $b, $c) {
2720
-	return round($a * $b / $c);
2720
+    return round($a * $b / $c);
2721 2721
 }
2722 2722
 
2723 2723
 
@@ -2740,79 +2740,79 @@  discard block
 block discarded – undo
2740 2740
  * @return string Suite de champs input hidden
2741 2741
  **/
2742 2742
 function form_hidden(?string $action = ''): string {
2743
-	$action ??= '';
2744
-
2745
-	$contexte = [];
2746
-	include_spip('inc/urls');
2747
-	if (
2748
-		$p = urls_decoder_url($action, '')
2749
-		and reset($p)
2750
-	) {
2751
-		$fond = array_shift($p);
2752
-		if ($fond != '404') {
2753
-			$contexte = array_shift($p);
2754
-			$contexte['page'] = $fond;
2755
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2756
-		}
2757
-	}
2758
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2759
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2760
-		unset($contexte['type']);
2761
-	}
2762
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2763
-		unset($contexte['type-page']);
2764
-	}
2765
-
2766
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2767
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2768
-	$values = [];
2769
-
2770
-	// d'abord avec celles de l'url
2771
-	if (false !== ($p = strpos($action, '?'))) {
2772
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2773
-			$c = explode('=', $c, 2);
2774
-			$var = array_shift($c);
2775
-			$val = array_shift($c);
2776
-			if ($var) {
2777
-				$val = rawurldecode($val);
2778
-				$var = rawurldecode($var); // decoder les [] eventuels
2779
-				if (preg_match(',\[\]$,S', $var)) {
2780
-					$values[] = [$var, $val];
2781
-				} else {
2782
-					if (!isset($values[$var])) {
2783
-						$values[$var] = [$var, $val];
2784
-					}
2785
-				}
2786
-			}
2787
-		}
2788
-	}
2789
-
2790
-	// ensuite avec celles du contexte, sans doublonner !
2791
-	foreach ($contexte as $var => $val) {
2792
-		if (preg_match(',\[\]$,S', $var)) {
2793
-			$values[] = [$var, $val];
2794
-		} else {
2795
-			if (!isset($values[$var])) {
2796
-				$values[$var] = [$var, $val];
2797
-			}
2798
-		}
2799
-	}
2800
-
2801
-	// puis on rassemble le tout
2802
-	$hidden = [];
2803
-	foreach ($values as $value) {
2804
-		[$var, $val] = $value;
2805
-		$hidden[] = '<input name="'
2806
-			. entites_html($var)
2807
-			. '"'
2808
-			. (is_null($val)
2809
-				? ''
2810
-				: ' value="' . entites_html($val) . '"'
2811
-			)
2812
-			. ' type="hidden"' . "\n/>";
2813
-	}
2814
-
2815
-	return join('', $hidden);
2743
+    $action ??= '';
2744
+
2745
+    $contexte = [];
2746
+    include_spip('inc/urls');
2747
+    if (
2748
+        $p = urls_decoder_url($action, '')
2749
+        and reset($p)
2750
+    ) {
2751
+        $fond = array_shift($p);
2752
+        if ($fond != '404') {
2753
+            $contexte = array_shift($p);
2754
+            $contexte['page'] = $fond;
2755
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2756
+        }
2757
+    }
2758
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2759
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2760
+        unset($contexte['type']);
2761
+    }
2762
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2763
+        unset($contexte['type-page']);
2764
+    }
2765
+
2766
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2767
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2768
+    $values = [];
2769
+
2770
+    // d'abord avec celles de l'url
2771
+    if (false !== ($p = strpos($action, '?'))) {
2772
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2773
+            $c = explode('=', $c, 2);
2774
+            $var = array_shift($c);
2775
+            $val = array_shift($c);
2776
+            if ($var) {
2777
+                $val = rawurldecode($val);
2778
+                $var = rawurldecode($var); // decoder les [] eventuels
2779
+                if (preg_match(',\[\]$,S', $var)) {
2780
+                    $values[] = [$var, $val];
2781
+                } else {
2782
+                    if (!isset($values[$var])) {
2783
+                        $values[$var] = [$var, $val];
2784
+                    }
2785
+                }
2786
+            }
2787
+        }
2788
+    }
2789
+
2790
+    // ensuite avec celles du contexte, sans doublonner !
2791
+    foreach ($contexte as $var => $val) {
2792
+        if (preg_match(',\[\]$,S', $var)) {
2793
+            $values[] = [$var, $val];
2794
+        } else {
2795
+            if (!isset($values[$var])) {
2796
+                $values[$var] = [$var, $val];
2797
+            }
2798
+        }
2799
+    }
2800
+
2801
+    // puis on rassemble le tout
2802
+    $hidden = [];
2803
+    foreach ($values as $value) {
2804
+        [$var, $val] = $value;
2805
+        $hidden[] = '<input name="'
2806
+            . entites_html($var)
2807
+            . '"'
2808
+            . (is_null($val)
2809
+                ? ''
2810
+                : ' value="' . entites_html($val) . '"'
2811
+            )
2812
+            . ' type="hidden"' . "\n/>";
2813
+    }
2814
+
2815
+    return join('', $hidden);
2816 2816
 }
2817 2817
 
2818 2818
 
@@ -2834,7 +2834,7 @@  discard block
 block discarded – undo
2834 2834
  *    - la première valeur du tableau sinon.
2835 2835
  **/
2836 2836
 function filtre_reset($array) {
2837
-	return !is_array($array) ? null : reset($array);
2837
+    return !is_array($array) ? null : reset($array);
2838 2838
 }
2839 2839
 
2840 2840
 /**
@@ -2855,7 +2855,7 @@  discard block
 block discarded – undo
2855 2855
  *    - la dernière valeur du tableau sinon.
2856 2856
  **/
2857 2857
 function filtre_end($array) {
2858
-	return !is_array($array) ? null : end($array);
2858
+    return !is_array($array) ? null : end($array);
2859 2859
 }
2860 2860
 
2861 2861
 /**
@@ -2875,11 +2875,11 @@  discard block
 block discarded – undo
2875 2875
  *
2876 2876
  **/
2877 2877
 function filtre_push($array, $val) {
2878
-	if (!is_array($array) or !array_push($array, $val)) {
2879
-		return '';
2880
-	}
2878
+    if (!is_array($array) or !array_push($array, $val)) {
2879
+        return '';
2880
+    }
2881 2881
 
2882
-	return $array;
2882
+    return $array;
2883 2883
 }
2884 2884
 
2885 2885
 /**
@@ -2898,7 +2898,7 @@  discard block
 block discarded – undo
2898 2898
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2899 2899
  **/
2900 2900
 function filtre_find($array, $val) {
2901
-	return (is_array($array) and in_array($val, $array));
2901
+    return (is_array($array) and in_array($val, $array));
2902 2902
 }
2903 2903
 
2904 2904
 
@@ -2915,13 +2915,13 @@  discard block
 block discarded – undo
2915 2915
  *     Contenu avec urls en absolus
2916 2916
  **/
2917 2917
 function urls_absolues_css($contenu, $source) {
2918
-	$path = suivre_lien(url_absolue($source), './');
2918
+    $path = suivre_lien(url_absolue($source), './');
2919 2919
 
2920
-	return preg_replace_callback(
2921
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2922
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2923
-		$contenu
2924
-	);
2920
+    return preg_replace_callback(
2921
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2922
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2923
+        $contenu
2924
+    );
2925 2925
 }
2926 2926
 
2927 2927
 
@@ -2950,119 +2950,119 @@  discard block
 block discarded – undo
2950 2950
  *     Chemin du fichier CSS inversé
2951 2951
  **/
2952 2952
 function direction_css($css, $voulue = '') {
2953
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2954
-		return $css;
2955
-	}
2956
-	include_spip('inc/lang');
2957
-	// si on a precise le sens voulu en argument, le prendre en compte
2958
-	if ($voulue = strtolower($voulue)) {
2959
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2960
-			$voulue = lang_dir($voulue);
2961
-		}
2962
-	} else {
2963
-		$voulue = lang_dir();
2964
-	}
2965
-
2966
-	$r = count($r) > 1;
2967
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2968
-	$dir = $r ? 'rtl' : 'ltr';
2969
-	$ndir = $r ? 'ltr' : 'rtl';
2970
-
2971
-	if ($voulue == $dir) {
2972
-		return $css;
2973
-	}
2974
-
2975
-	if (
2976
-		// url absolue
2977
-		preg_match(',^https?:,i', $css)
2978
-		// ou qui contient un ?
2979
-		or (($p = strpos($css, '?')) !== false)
2980
-	) {
2981
-		$distant = true;
2982
-		$cssf = parse_url($css);
2983
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2984
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2985
-	} else {
2986
-		$distant = false;
2987
-		$cssf = $css;
2988
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2989
-		//propose (rien a faire dans ce cas)
2990
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2991
-		if (@file_exists($f)) {
2992
-			return $f;
2993
-		}
2994
-	}
2995
-
2996
-	// 2.
2997
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2998
-	$f = $dir_var
2999
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3000
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3001
-
3002
-	// la css peut etre distante (url absolue !)
3003
-	if ($distant) {
3004
-		include_spip('inc/distant');
3005
-		$res = recuperer_url($css);
3006
-		if (!$res or !$contenu = $res['page']) {
3007
-			return $css;
3008
-		}
3009
-	} else {
3010
-		if (
3011
-			(@filemtime($f) > @filemtime($css))
3012
-			and (_VAR_MODE != 'recalcul')
3013
-		) {
3014
-			return $f;
3015
-		}
3016
-		if (!lire_fichier($css, $contenu)) {
3017
-			return $css;
3018
-		}
3019
-	}
3020
-
3021
-
3022
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3023
-	include_spip('lib/csstidy/class.csstidy');
3024
-	$parser = new csstidy();
3025
-	$parser->set_cfg('optimise_shorthands', 0);
3026
-	$parser->set_cfg('reverse_left_and_right', true);
3027
-	$parser->parse($contenu);
3028
-
3029
-	$contenu = $parser->print->plain();
3030
-
3031
-
3032
-	// reperer les @import auxquels il faut propager le direction_css
3033
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3034
-	$src = [];
3035
-	$src_direction_css = [];
3036
-	$src_faux_abs = [];
3037
-	$d = dirname($css);
3038
-	foreach ($regs[1] as $k => $import_css) {
3039
-		$css_direction = direction_css("$d/$import_css", $voulue);
3040
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3041
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3042
-			$css_direction = substr($css_direction, strlen($d) + 1);
3043
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3044
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3045
-			$css_direction = substr($css_direction, strlen($dir_var));
3046
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3047
-			$css_direction = '/@@@@@@/' . $css_direction;
3048
-		}
3049
-		$src[] = $regs[0][$k];
3050
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3051
-	}
3052
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3053
-
3054
-	$contenu = urls_absolues_css($contenu, $css);
3055
-
3056
-	// virer les fausses url absolues que l'on a mis dans les import
3057
-	if (count($src_faux_abs)) {
3058
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3059
-	}
3060
-
3061
-	if (!ecrire_fichier($f, $contenu)) {
3062
-		return $css;
3063
-	}
3064
-
3065
-	return $f;
2953
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2954
+        return $css;
2955
+    }
2956
+    include_spip('inc/lang');
2957
+    // si on a precise le sens voulu en argument, le prendre en compte
2958
+    if ($voulue = strtolower($voulue)) {
2959
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2960
+            $voulue = lang_dir($voulue);
2961
+        }
2962
+    } else {
2963
+        $voulue = lang_dir();
2964
+    }
2965
+
2966
+    $r = count($r) > 1;
2967
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2968
+    $dir = $r ? 'rtl' : 'ltr';
2969
+    $ndir = $r ? 'ltr' : 'rtl';
2970
+
2971
+    if ($voulue == $dir) {
2972
+        return $css;
2973
+    }
2974
+
2975
+    if (
2976
+        // url absolue
2977
+        preg_match(',^https?:,i', $css)
2978
+        // ou qui contient un ?
2979
+        or (($p = strpos($css, '?')) !== false)
2980
+    ) {
2981
+        $distant = true;
2982
+        $cssf = parse_url($css);
2983
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2984
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2985
+    } else {
2986
+        $distant = false;
2987
+        $cssf = $css;
2988
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2989
+        //propose (rien a faire dans ce cas)
2990
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2991
+        if (@file_exists($f)) {
2992
+            return $f;
2993
+        }
2994
+    }
2995
+
2996
+    // 2.
2997
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2998
+    $f = $dir_var
2999
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
3000
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
3001
+
3002
+    // la css peut etre distante (url absolue !)
3003
+    if ($distant) {
3004
+        include_spip('inc/distant');
3005
+        $res = recuperer_url($css);
3006
+        if (!$res or !$contenu = $res['page']) {
3007
+            return $css;
3008
+        }
3009
+    } else {
3010
+        if (
3011
+            (@filemtime($f) > @filemtime($css))
3012
+            and (_VAR_MODE != 'recalcul')
3013
+        ) {
3014
+            return $f;
3015
+        }
3016
+        if (!lire_fichier($css, $contenu)) {
3017
+            return $css;
3018
+        }
3019
+    }
3020
+
3021
+
3022
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3023
+    include_spip('lib/csstidy/class.csstidy');
3024
+    $parser = new csstidy();
3025
+    $parser->set_cfg('optimise_shorthands', 0);
3026
+    $parser->set_cfg('reverse_left_and_right', true);
3027
+    $parser->parse($contenu);
3028
+
3029
+    $contenu = $parser->print->plain();
3030
+
3031
+
3032
+    // reperer les @import auxquels il faut propager le direction_css
3033
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3034
+    $src = [];
3035
+    $src_direction_css = [];
3036
+    $src_faux_abs = [];
3037
+    $d = dirname($css);
3038
+    foreach ($regs[1] as $k => $import_css) {
3039
+        $css_direction = direction_css("$d/$import_css", $voulue);
3040
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3041
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3042
+            $css_direction = substr($css_direction, strlen($d) + 1);
3043
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3044
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3045
+            $css_direction = substr($css_direction, strlen($dir_var));
3046
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3047
+            $css_direction = '/@@@@@@/' . $css_direction;
3048
+        }
3049
+        $src[] = $regs[0][$k];
3050
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3051
+    }
3052
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3053
+
3054
+    $contenu = urls_absolues_css($contenu, $css);
3055
+
3056
+    // virer les fausses url absolues que l'on a mis dans les import
3057
+    if (count($src_faux_abs)) {
3058
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3059
+    }
3060
+
3061
+    if (!ecrire_fichier($f, $contenu)) {
3062
+        return $css;
3063
+    }
3064
+
3065
+    return $f;
3066 3066
 }
3067 3067
 
3068 3068
 
@@ -3085,46 +3085,46 @@  discard block
 block discarded – undo
3085 3085
  *     - Chemin ou URL du fichier CSS source sinon.
3086 3086
  **/
3087 3087
 function url_absolue_css($css) {
3088
-	if (!preg_match(',\.css$,i', $css, $r)) {
3089
-		return $css;
3090
-	}
3088
+    if (!preg_match(',\.css$,i', $css, $r)) {
3089
+        return $css;
3090
+    }
3091 3091
 
3092
-	$url_absolue_css = url_absolue($css);
3092
+    $url_absolue_css = url_absolue($css);
3093 3093
 
3094
-	$f = basename($css, '.css');
3095
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3096
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3097
-		. '.css';
3094
+    $f = basename($css, '.css');
3095
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3096
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3097
+        . '.css';
3098 3098
 
3099
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3100
-		return $f;
3101
-	}
3099
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3100
+        return $f;
3101
+    }
3102 3102
 
3103
-	if ($url_absolue_css == $css) {
3104
-		if (
3105
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3106
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3107
-		) {
3108
-			include_spip('inc/distant');
3109
-			$contenu = recuperer_url($css);
3110
-			$contenu = $contenu['page'] ?? '';
3111
-			if (!$contenu) {
3112
-				return $css;
3113
-			}
3114
-		}
3115
-	} elseif (!lire_fichier($css, $contenu)) {
3116
-		return $css;
3117
-	}
3103
+    if ($url_absolue_css == $css) {
3104
+        if (
3105
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3106
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3107
+        ) {
3108
+            include_spip('inc/distant');
3109
+            $contenu = recuperer_url($css);
3110
+            $contenu = $contenu['page'] ?? '';
3111
+            if (!$contenu) {
3112
+                return $css;
3113
+            }
3114
+        }
3115
+    } elseif (!lire_fichier($css, $contenu)) {
3116
+        return $css;
3117
+    }
3118 3118
 
3119
-	// passer les url relatives a la css d'origine en url absolues
3120
-	$contenu = urls_absolues_css($contenu, $css);
3119
+    // passer les url relatives a la css d'origine en url absolues
3120
+    $contenu = urls_absolues_css($contenu, $css);
3121 3121
 
3122
-	// ecrire la css
3123
-	if (!ecrire_fichier($f, $contenu)) {
3124
-		return $css;
3125
-	}
3122
+    // ecrire la css
3123
+    if (!ecrire_fichier($f, $contenu)) {
3124
+        return $css;
3125
+    }
3126 3126
 
3127
-	return $f;
3127
+    return $f;
3128 3128
 }
3129 3129
 
3130 3130
 
@@ -3158,24 +3158,24 @@  discard block
 block discarded – undo
3158 3158
  *     Valeur trouvée ou valeur par défaut.
3159 3159
  **/
3160 3160
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3161
-	foreach (explode('/', $cle) as $k) {
3162
-		$table = (is_string($table) ? @unserialize($table) : $table);
3161
+    foreach (explode('/', $cle) as $k) {
3162
+        $table = (is_string($table) ? @unserialize($table) : $table);
3163 3163
 
3164
-		if (is_object($table)) {
3165
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3166
-		} elseif (is_array($table)) {
3167
-			if ($conserver_null) {
3168
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3169
-			} else {
3170
-				$table = ($table[$k] ?? $defaut);
3171
-			}
3172
-		} else {
3173
-			$table = $defaut;
3174
-			break;
3175
-		}
3176
-	}
3164
+        if (is_object($table)) {
3165
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3166
+        } elseif (is_array($table)) {
3167
+            if ($conserver_null) {
3168
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3169
+            } else {
3170
+                $table = ($table[$k] ?? $defaut);
3171
+            }
3172
+        } else {
3173
+            $table = $defaut;
3174
+            break;
3175
+        }
3176
+    }
3177 3177
 
3178
-	return $table;
3178
+    return $table;
3179 3179
 }
3180 3180
 
3181 3181
 /**
@@ -3208,22 +3208,22 @@  discard block
 block discarded – undo
3208 3208
  *     - string : expression trouvée.
3209 3209
  **/
3210 3210
 function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) {
3211
-	if (intval($modif) and $capte == 0) {
3212
-		$capte = $modif;
3213
-		$modif = 'UimsS';
3214
-	}
3215
-	$expression = str_replace('\/', '/', $expression);
3216
-	$expression = str_replace('/', '\/', $expression);
3211
+    if (intval($modif) and $capte == 0) {
3212
+        $capte = $modif;
3213
+        $modif = 'UimsS';
3214
+    }
3215
+    $expression = str_replace('\/', '/', $expression);
3216
+    $expression = str_replace('/', '\/', $expression);
3217 3217
 
3218
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3219
-		if (isset($r[$capte])) {
3220
-			return $r[$capte];
3221
-		} else {
3222
-			return true;
3223
-		}
3224
-	}
3218
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3219
+        if (isset($r[$capte])) {
3220
+            return $r[$capte];
3221
+        } else {
3222
+            return true;
3223
+        }
3224
+    }
3225 3225
 
3226
-	return false;
3226
+    return false;
3227 3227
 }
3228 3228
 
3229 3229
 
@@ -3250,10 +3250,10 @@  discard block
 block discarded – undo
3250 3250
  *     Texte
3251 3251
  **/
3252 3252
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3253
-	$expression = str_replace('\/', '/', $expression);
3254
-	$expression = str_replace('/', '\/', $expression);
3253
+    $expression = str_replace('\/', '/', $expression);
3254
+    $expression = str_replace('/', '\/', $expression);
3255 3255
 
3256
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3256
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3257 3257
 }
3258 3258
 
3259 3259
 
@@ -3271,25 +3271,25 @@  discard block
 block discarded – undo
3271 3271
  **/
3272 3272
 function traiter_doublons_documents(&$doublons, $letexte) {
3273 3273
 
3274
-	// Verifier dans le texte & les notes (pas beau, helas)
3275
-	$t = $letexte . $GLOBALS['les_notes'];
3274
+    // Verifier dans le texte & les notes (pas beau, helas)
3275
+    $t = $letexte . $GLOBALS['les_notes'];
3276 3276
 
3277
-	if (
3278
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3279
-		and preg_match_all(
3280
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3281
-			$t,
3282
-			$matches,
3283
-			PREG_PATTERN_ORDER
3284
-		)
3285
-	) {
3286
-		if (!isset($doublons['documents'])) {
3287
-			$doublons['documents'] = '';
3288
-		}
3289
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3290
-	}
3277
+    if (
3278
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3279
+        and preg_match_all(
3280
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3281
+            $t,
3282
+            $matches,
3283
+            PREG_PATTERN_ORDER
3284
+        )
3285
+    ) {
3286
+        if (!isset($doublons['documents'])) {
3287
+            $doublons['documents'] = '';
3288
+        }
3289
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3290
+    }
3291 3291
 
3292
-	return $letexte;
3292
+    return $letexte;
3293 3293
 }
3294 3294
 
3295 3295
 /**
@@ -3303,7 +3303,7 @@  discard block
 block discarded – undo
3303 3303
  * @return string Chaîne vide
3304 3304
  **/
3305 3305
 function vide($texte) {
3306
-	return '';
3306
+    return '';
3307 3307
 }
3308 3308
 
3309 3309
 //
@@ -3332,23 +3332,23 @@  discard block
 block discarded – undo
3332 3332
  *      Code HTML résultant
3333 3333
  **/
3334 3334
 function env_to_params($env, $ignore_params = []) {
3335
-	$ignore_params = array_merge(
3336
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3337
-		$ignore_params
3338
-	);
3339
-	if (!is_array($env)) {
3340
-		$env = unserialize($env);
3341
-	}
3342
-	$texte = '';
3343
-	if ($env) {
3344
-		foreach ($env as $i => $j) {
3345
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3346
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3347
-			}
3348
-		}
3349
-	}
3350
-
3351
-	return $texte;
3335
+    $ignore_params = array_merge(
3336
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3337
+        $ignore_params
3338
+    );
3339
+    if (!is_array($env)) {
3340
+        $env = unserialize($env);
3341
+    }
3342
+    $texte = '';
3343
+    if ($env) {
3344
+        foreach ($env as $i => $j) {
3345
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3346
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3347
+            }
3348
+        }
3349
+    }
3350
+
3351
+    return $texte;
3352 3352
 }
3353 3353
 
3354 3354
 /**
@@ -3371,23 +3371,23 @@  discard block
 block discarded – undo
3371 3371
  *      Code HTML résultant
3372 3372
  **/
3373 3373
 function env_to_attributs($env, $ignore_params = []) {
3374
-	$ignore_params = array_merge(
3375
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3376
-		$ignore_params
3377
-	);
3378
-	if (!is_array($env)) {
3379
-		$env = unserialize($env);
3380
-	}
3381
-	$texte = '';
3382
-	if ($env) {
3383
-		foreach ($env as $i => $j) {
3384
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3385
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3386
-			}
3387
-		}
3388
-	}
3374
+    $ignore_params = array_merge(
3375
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3376
+        $ignore_params
3377
+    );
3378
+    if (!is_array($env)) {
3379
+        $env = unserialize($env);
3380
+    }
3381
+    $texte = '';
3382
+    if ($env) {
3383
+        foreach ($env as $i => $j) {
3384
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3385
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3386
+            }
3387
+        }
3388
+    }
3389 3389
 
3390
-	return $texte;
3390
+    return $texte;
3391 3391
 }
3392 3392
 
3393 3393
 
@@ -3405,7 +3405,7 @@  discard block
 block discarded – undo
3405 3405
  * @return string Chaînes concaténés
3406 3406
  **/
3407 3407
 function concat(...$args): string {
3408
-	return join('', $args);
3408
+    return join('', $args);
3409 3409
 }
3410 3410
 
3411 3411
 
@@ -3425,23 +3425,23 @@  discard block
 block discarded – undo
3425 3425
  *     Contenu du ou des fichiers, concaténé
3426 3426
  **/
3427 3427
 function charge_scripts($files, $script = true) {
3428
-	$flux = '';
3429
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3430
-		if (!is_string($file)) {
3431
-			continue;
3432
-		}
3433
-		if ($script) {
3434
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3435
-		}
3436
-		if ($file) {
3437
-			$path = find_in_path($file);
3438
-			if ($path) {
3439
-				$flux .= spip_file_get_contents($path);
3440
-			}
3441
-		}
3442
-	}
3443
-
3444
-	return $flux;
3428
+    $flux = '';
3429
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3430
+        if (!is_string($file)) {
3431
+            continue;
3432
+        }
3433
+        if ($script) {
3434
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3435
+        }
3436
+        if ($file) {
3437
+            $path = find_in_path($file);
3438
+            if ($path) {
3439
+                $flux .= spip_file_get_contents($path);
3440
+            }
3441
+        }
3442
+    }
3443
+
3444
+    return $flux;
3445 3445
 }
3446 3446
 
3447 3447
 /**
@@ -3452,22 +3452,22 @@  discard block
 block discarded – undo
3452 3452
  * @return string
3453 3453
  */
3454 3454
 function http_img_variante_svg_si_possible($img_file) {
3455
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3456
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3457
-	if (
3458
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3459
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3460
-		and file_exists($variante_svg_generique)
3461
-	) {
3462
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3463
-			$img_file = $variante_svg_size;
3464
-		}
3465
-		else {
3466
-			$img_file = $variante_svg_generique;
3467
-		}
3468
-	}
3455
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3456
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3457
+    if (
3458
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3459
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3460
+        and file_exists($variante_svg_generique)
3461
+    ) {
3462
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3463
+            $img_file = $variante_svg_size;
3464
+        }
3465
+        else {
3466
+            $img_file = $variante_svg_generique;
3467
+        }
3468
+    }
3469 3469
 
3470
-	return $img_file;
3470
+    return $img_file;
3471 3471
 }
3472 3472
 
3473 3473
 /**
@@ -3488,54 +3488,54 @@  discard block
 block discarded – undo
3488 3488
  */
3489 3489
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3490 3490
 
3491
-	$img_file = $img;
3492
-	if ($p = strpos($img_file, '?')) {
3493
-		$img_file = substr($img_file, 0, $p);
3494
-	}
3495
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3496
-		$img_file = chemin_image($img);
3497
-	}
3498
-	else {
3499
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3500
-			$img_file = http_img_variante_svg_si_possible($img_file);
3501
-		}
3502
-	}
3503
-	if (stripos($atts, 'width') === false) {
3504
-		// utiliser directement l'info de taille presente dans le nom
3505
-		if (
3506
-			(!isset($options['utiliser_suffixe_size'])
3507
-				or $options['utiliser_suffixe_size'] == true
3508
-			  or strpos($img_file, '-xx.svg') !== false)
3509
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3510
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3511
-		) {
3512
-			$largeur = $hauteur = intval($regs[1]);
3513
-		} else {
3514
-			$taille = taille_image($img_file);
3515
-			[$hauteur, $largeur] = $taille;
3516
-			if (!$hauteur or !$largeur) {
3517
-				return '';
3518
-			}
3519
-		}
3520
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3521
-	}
3522
-
3523
-	if (file_exists($img_file)) {
3524
-		$img_file = timestamp($img_file);
3525
-	}
3526
-	if ($alt === false) {
3527
-		$alt = '';
3528
-	}
3529
-	elseif ($alt or $alt === '') {
3530
-		$alt = " alt='" . attribut_html($alt) . "'";
3531
-	}
3532
-	else {
3533
-		$alt = " alt='" . attribut_html($title) . "'";
3534
-	}
3535
-	return "<img src='$img_file'$alt"
3536
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3537
-	. ' ' . ltrim($atts)
3538
-	. ' />';
3491
+    $img_file = $img;
3492
+    if ($p = strpos($img_file, '?')) {
3493
+        $img_file = substr($img_file, 0, $p);
3494
+    }
3495
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3496
+        $img_file = chemin_image($img);
3497
+    }
3498
+    else {
3499
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3500
+            $img_file = http_img_variante_svg_si_possible($img_file);
3501
+        }
3502
+    }
3503
+    if (stripos($atts, 'width') === false) {
3504
+        // utiliser directement l'info de taille presente dans le nom
3505
+        if (
3506
+            (!isset($options['utiliser_suffixe_size'])
3507
+                or $options['utiliser_suffixe_size'] == true
3508
+              or strpos($img_file, '-xx.svg') !== false)
3509
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3510
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3511
+        ) {
3512
+            $largeur = $hauteur = intval($regs[1]);
3513
+        } else {
3514
+            $taille = taille_image($img_file);
3515
+            [$hauteur, $largeur] = $taille;
3516
+            if (!$hauteur or !$largeur) {
3517
+                return '';
3518
+            }
3519
+        }
3520
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3521
+    }
3522
+
3523
+    if (file_exists($img_file)) {
3524
+        $img_file = timestamp($img_file);
3525
+    }
3526
+    if ($alt === false) {
3527
+        $alt = '';
3528
+    }
3529
+    elseif ($alt or $alt === '') {
3530
+        $alt = " alt='" . attribut_html($alt) . "'";
3531
+    }
3532
+    else {
3533
+        $alt = " alt='" . attribut_html($title) . "'";
3534
+    }
3535
+    return "<img src='$img_file'$alt"
3536
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3537
+    . ' ' . ltrim($atts)
3538
+    . ' />';
3539 3539
 }
3540 3540
 
3541 3541
 /**
@@ -3547,70 +3547,70 @@  discard block
 block discarded – undo
3547 3547
  * @return string
3548 3548
  */
3549 3549
 function http_style_background($img, $att = '', $size = null) {
3550
-	if ($size and is_numeric($size)) {
3551
-		$size = trim($size) . 'px';
3552
-	}
3553
-	return " style='background" .
3554
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3555
-		. ($size ? "background-size:{$size};" : '')
3556
-		. "'";
3550
+    if ($size and is_numeric($size)) {
3551
+        $size = trim($size) . 'px';
3552
+    }
3553
+    return " style='background" .
3554
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3555
+        . ($size ? "background-size:{$size};" : '')
3556
+        . "'";
3557 3557
 }
3558 3558
 
3559 3559
 
3560 3560
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3561
-	$args = [$alt_or_size, $class_or_size, $size];
3562
-	while (is_null(end($args)) and count($args)) {
3563
-		array_pop($args);
3564
-	}
3565
-	if (!count($args)) {
3566
-		return [null, null, null];
3567
-	}
3568
-	if (count($args) < 3) {
3569
-		$maybe_size = array_pop($args);
3570
-		// @2x
3571
-		// @1.5x
3572
-		// 512
3573
-		// 512x*
3574
-		// 512x300
3575
-		if (
3576
-			!strlen($maybe_size)
3577
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3578
-		) {
3579
-			$args[] = $maybe_size;
3580
-			$maybe_size = null;
3581
-		}
3582
-		while (count($args) < 2) {
3583
-			$args[] = null; // default alt or class
3584
-		}
3585
-		$args[] = $maybe_size;
3586
-	}
3587
-	return $args;
3561
+    $args = [$alt_or_size, $class_or_size, $size];
3562
+    while (is_null(end($args)) and count($args)) {
3563
+        array_pop($args);
3564
+    }
3565
+    if (!count($args)) {
3566
+        return [null, null, null];
3567
+    }
3568
+    if (count($args) < 3) {
3569
+        $maybe_size = array_pop($args);
3570
+        // @2x
3571
+        // @1.5x
3572
+        // 512
3573
+        // 512x*
3574
+        // 512x300
3575
+        if (
3576
+            !strlen($maybe_size)
3577
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3578
+        ) {
3579
+            $args[] = $maybe_size;
3580
+            $maybe_size = null;
3581
+        }
3582
+        while (count($args) < 2) {
3583
+            $args[] = null; // default alt or class
3584
+        }
3585
+        $args[] = $maybe_size;
3586
+    }
3587
+    return $args;
3588 3588
 }
3589 3589
 
3590 3590
 function helper_filtre_balise_img_svg_size($img, $size) {
3591
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3592
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3593
-		$coef = floatval(substr($size, 1, -1));
3594
-		[$h, $w] = taille_image($img);
3595
-		$height = intval(round($h / $coef));
3596
-		$width = intval(round($w / $coef));
3597
-	}
3598
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3599
-	else {
3600
-		$size = explode('x', $size, 2);
3601
-		$size = array_map('trim', $size);
3602
-		$height = $width = intval(array_shift($size));
3603
-
3604
-		if (count($size) and reset($size)) {
3605
-			$height = array_shift($size);
3606
-			if ($height === '*') {
3607
-				[$h, $w] = taille_image($img);
3608
-				$height = intval(round($h * $width / $w));
3609
-			}
3610
-		}
3611
-	}
3612
-
3613
-	return [$width, $height];
3591
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3592
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3593
+        $coef = floatval(substr($size, 1, -1));
3594
+        [$h, $w] = taille_image($img);
3595
+        $height = intval(round($h / $coef));
3596
+        $width = intval(round($w / $coef));
3597
+    }
3598
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3599
+    else {
3600
+        $size = explode('x', $size, 2);
3601
+        $size = array_map('trim', $size);
3602
+        $height = $width = intval(array_shift($size));
3603
+
3604
+        if (count($size) and reset($size)) {
3605
+            $height = array_shift($size);
3606
+            if ($height === '*') {
3607
+                [$h, $w] = taille_image($img);
3608
+                $height = intval(round($h * $width / $w));
3609
+            }
3610
+        }
3611
+    }
3612
+
3613
+    return [$width, $height];
3614 3614
 }
3615 3615
 
3616 3616
 /**
@@ -3646,43 +3646,43 @@  discard block
 block discarded – undo
3646 3646
  */
3647 3647
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3648 3648
 
3649
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3650
-
3651
-	$img = trim($img);
3652
-	if (strpos($img, '<img') === 0) {
3653
-		if (!is_null($alt)) {
3654
-			$img = inserer_attribut($img, 'alt', $alt);
3655
-		}
3656
-		if (!is_null($class)) {
3657
-			if (strlen($class)) {
3658
-				$img = inserer_attribut($img, 'class', $class);
3659
-			}
3660
-			else {
3661
-				$img = vider_attribut($img, 'class');
3662
-			}
3663
-		}
3664
-	}
3665
-	else {
3666
-		$img = http_img_pack(
3667
-			$img,
3668
-			$alt,
3669
-			$class ? " class='" . attribut_html($class) . "'" : '',
3670
-			'',
3671
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3672
-		);
3673
-		if (is_null($alt)) {
3674
-			$img = vider_attribut($img, 'alt');
3675
-		}
3676
-	}
3677
-
3678
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3679
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3680
-
3681
-		$img = inserer_attribut($img, 'width', $width);
3682
-		$img = inserer_attribut($img, 'height', $height);
3683
-	}
3684
-
3685
-	return $img;
3649
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3650
+
3651
+    $img = trim($img);
3652
+    if (strpos($img, '<img') === 0) {
3653
+        if (!is_null($alt)) {
3654
+            $img = inserer_attribut($img, 'alt', $alt);
3655
+        }
3656
+        if (!is_null($class)) {
3657
+            if (strlen($class)) {
3658
+                $img = inserer_attribut($img, 'class', $class);
3659
+            }
3660
+            else {
3661
+                $img = vider_attribut($img, 'class');
3662
+            }
3663
+        }
3664
+    }
3665
+    else {
3666
+        $img = http_img_pack(
3667
+            $img,
3668
+            $alt,
3669
+            $class ? " class='" . attribut_html($class) . "'" : '',
3670
+            '',
3671
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3672
+        );
3673
+        if (is_null($alt)) {
3674
+            $img = vider_attribut($img, 'alt');
3675
+        }
3676
+    }
3677
+
3678
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3679
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3680
+
3681
+        $img = inserer_attribut($img, 'width', $width);
3682
+        $img = inserer_attribut($img, 'height', $height);
3683
+    }
3684
+
3685
+    return $img;
3686 3686
 }
3687 3687
 
3688 3688
 
@@ -3716,80 +3716,80 @@  discard block
 block discarded – undo
3716 3716
  */
3717 3717
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3718 3718
 
3719
-	$svg = null;
3720
-	$img = trim($img);
3721
-	$img_file = $img;
3722
-	if (strpos($img, '<svg') === false) {
3723
-		if ($p = strpos($img_file, '?')) {
3724
-			$img_file = substr($img_file, 0, $p);
3725
-		}
3726
-
3727
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3728
-		// la copie locale a toutes les chances d'etre la ou de resservir
3729
-		if (tester_url_absolue($img_file)) {
3730
-			include_spip('inc/distant');
3731
-			$fichier = copie_locale($img_file);
3732
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3733
-		}
3734
-
3735
-		if (
3736
-			!$img_file
3737
-			or !file_exists($img_file)
3738
-			or !$svg = file_get_contents($img_file)
3739
-		) {
3740
-			return '';
3741
-		}
3742
-	}
3743
-
3744
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3745
-		return '';
3746
-	}
3747
-
3748
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3749
-
3750
-	$balise_svg = $match[0];
3751
-	$balise_svg_source = $balise_svg;
3752
-
3753
-	// entete XML à supprimer
3754
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3755
-
3756
-	// IE est toujours mon ami
3757
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3758
-
3759
-	// regler la classe
3760
-	if (!is_null($class)) {
3761
-		if (strlen($class)) {
3762
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3763
-		}
3764
-		else {
3765
-			$balise_svg = vider_attribut($balise_svg, 'class');
3766
-		}
3767
-	}
3768
-
3769
-	// regler le alt
3770
-	if ($alt) {
3771
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3772
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3773
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3774
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3775
-		$balise_svg .= $title;
3776
-	}
3777
-	else {
3778
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3779
-	}
3780
-
3781
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3782
-
3783
-	if (!is_null($size) and strlen($size = trim($size))) {
3784
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3785
-
3786
-		if (!function_exists('svg_redimensionner')) {
3787
-			include_spip('inc/svg');
3788
-		}
3789
-		$svg = svg_redimensionner($svg, $width, $height);
3790
-	}
3791
-
3792
-	return $svg;
3719
+    $svg = null;
3720
+    $img = trim($img);
3721
+    $img_file = $img;
3722
+    if (strpos($img, '<svg') === false) {
3723
+        if ($p = strpos($img_file, '?')) {
3724
+            $img_file = substr($img_file, 0, $p);
3725
+        }
3726
+
3727
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3728
+        // la copie locale a toutes les chances d'etre la ou de resservir
3729
+        if (tester_url_absolue($img_file)) {
3730
+            include_spip('inc/distant');
3731
+            $fichier = copie_locale($img_file);
3732
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3733
+        }
3734
+
3735
+        if (
3736
+            !$img_file
3737
+            or !file_exists($img_file)
3738
+            or !$svg = file_get_contents($img_file)
3739
+        ) {
3740
+            return '';
3741
+        }
3742
+    }
3743
+
3744
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3745
+        return '';
3746
+    }
3747
+
3748
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3749
+
3750
+    $balise_svg = $match[0];
3751
+    $balise_svg_source = $balise_svg;
3752
+
3753
+    // entete XML à supprimer
3754
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3755
+
3756
+    // IE est toujours mon ami
3757
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3758
+
3759
+    // regler la classe
3760
+    if (!is_null($class)) {
3761
+        if (strlen($class)) {
3762
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3763
+        }
3764
+        else {
3765
+            $balise_svg = vider_attribut($balise_svg, 'class');
3766
+        }
3767
+    }
3768
+
3769
+    // regler le alt
3770
+    if ($alt) {
3771
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3772
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3773
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3774
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3775
+        $balise_svg .= $title;
3776
+    }
3777
+    else {
3778
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3779
+    }
3780
+
3781
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3782
+
3783
+    if (!is_null($size) and strlen($size = trim($size))) {
3784
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3785
+
3786
+        if (!function_exists('svg_redimensionner')) {
3787
+            include_spip('inc/svg');
3788
+        }
3789
+        $svg = svg_redimensionner($svg, $width, $height);
3790
+    }
3791
+
3792
+    return $svg;
3793 3793
 }
3794 3794
 
3795 3795
 
@@ -3815,18 +3815,18 @@  discard block
 block discarded – undo
3815 3815
  *     Code HTML résultant
3816 3816
  **/
3817 3817
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3818
-	$texte = '';
3819
-	if (is_array($tableau)) {
3820
-		foreach ($tableau as $k => $v) {
3821
-			$res = recuperer_fond(
3822
-				'modeles/' . $modele,
3823
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3824
-			);
3825
-			$texte .= $res;
3826
-		}
3827
-	}
3818
+    $texte = '';
3819
+    if (is_array($tableau)) {
3820
+        foreach ($tableau as $k => $v) {
3821
+            $res = recuperer_fond(
3822
+                'modeles/' . $modele,
3823
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3824
+            );
3825
+            $texte .= $res;
3826
+        }
3827
+    }
3828 3828
 
3829
-	return $texte;
3829
+    return $texte;
3830 3830
 }
3831 3831
 
3832 3832
 
@@ -3851,37 +3851,37 @@  discard block
 block discarded – undo
3851 3851
  *         - tout : retourne toutes les informations du plugin actif
3852 3852
  **/
3853 3853
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3854
-	include_spip('inc/plugin');
3855
-	$plugin = strtoupper($plugin);
3856
-	$plugins_actifs = liste_plugin_actifs();
3857
-
3858
-	if (!$plugin) {
3859
-		return serialize(array_keys($plugins_actifs));
3860
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3861
-		return '';
3862
-	} elseif (($type_info == 'est_actif') and !$reload) {
3863
-		return $plugins_actifs[$plugin] ? 1 : 0;
3864
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3865
-		return $plugins_actifs[$plugin][$type_info];
3866
-	} else {
3867
-		$get_infos = charger_fonction('get_infos', 'plugins');
3868
-		// On prend en compte les extensions
3869
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3870
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3871
-		} else {
3872
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3873
-		}
3874
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3875
-			return '';
3876
-		}
3877
-		if ($type_info == 'tout') {
3878
-			return $infos;
3879
-		} elseif ($type_info == 'est_actif') {
3880
-			return $infos ? 1 : 0;
3881
-		} else {
3882
-			return strval($infos[$type_info]);
3883
-		}
3884
-	}
3854
+    include_spip('inc/plugin');
3855
+    $plugin = strtoupper($plugin);
3856
+    $plugins_actifs = liste_plugin_actifs();
3857
+
3858
+    if (!$plugin) {
3859
+        return serialize(array_keys($plugins_actifs));
3860
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3861
+        return '';
3862
+    } elseif (($type_info == 'est_actif') and !$reload) {
3863
+        return $plugins_actifs[$plugin] ? 1 : 0;
3864
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3865
+        return $plugins_actifs[$plugin][$type_info];
3866
+    } else {
3867
+        $get_infos = charger_fonction('get_infos', 'plugins');
3868
+        // On prend en compte les extensions
3869
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3870
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3871
+        } else {
3872
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3873
+        }
3874
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3875
+            return '';
3876
+        }
3877
+        if ($type_info == 'tout') {
3878
+            return $infos;
3879
+        } elseif ($type_info == 'est_actif') {
3880
+            return $infos ? 1 : 0;
3881
+        } else {
3882
+            return strval($infos[$type_info]);
3883
+        }
3884
+    }
3885 3885
 }
3886 3886
 
3887 3887
 
@@ -3908,9 +3908,9 @@  discard block
 block discarded – undo
3908 3908
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3909 3909
  */
3910 3910
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3911
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3911
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3912 3912
 
3913
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3913
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3914 3914
 }
3915 3915
 
3916 3916
 
@@ -3940,19 +3940,19 @@  discard block
 block discarded – undo
3940 3940
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3941 3941
  */
3942 3942
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3943
-	static $puce_statut = null;
3944
-	if (!$puce_statut) {
3945
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3946
-	}
3943
+    static $puce_statut = null;
3944
+    if (!$puce_statut) {
3945
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3946
+    }
3947 3947
 
3948
-	return $puce_statut(
3949
-		$id_objet,
3950
-		$statut,
3951
-		$id_parent,
3952
-		$objet,
3953
-		false,
3954
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3955
-	);
3948
+    return $puce_statut(
3949
+        $id_objet,
3950
+        $statut,
3951
+        $id_parent,
3952
+        $objet,
3953
+        false,
3954
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3955
+    );
3956 3956
 }
3957 3957
 
3958 3958
 
@@ -3979,98 +3979,98 @@  discard block
 block discarded – undo
3979 3979
  *   hash du contexte
3980 3980
  */
3981 3981
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3982
-	$env = null;
3983
-	if (
3984
-		is_string($c)
3985
-		and @unserialize($c) !== false
3986
-	) {
3987
-		$c = unserialize($c);
3988
-	}
3989
-
3990
-	// supprimer les parametres debut_x
3991
-	// pour que la pagination ajax ne soit pas plantee
3992
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3993
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3994
-	if (is_array($c)) {
3995
-		foreach ($c as $k => $v) {
3996
-			if (strpos($k, 'debut_') === 0) {
3997
-				unset($c[$k]);
3998
-			}
3999
-		}
4000
-	}
4001
-
4002
-	if (!function_exists('calculer_cle_action')) {
4003
-		include_spip('inc/securiser_action');
4004
-	}
4005
-
4006
-	$c = serialize($c);
4007
-	$cle = calculer_cle_action($form . $c);
4008
-	$c = "$cle:$c";
4009
-
4010
-	// on ne stocke pas les contextes dans des fichiers en cache
4011
-	// par defaut, sauf si cette configuration a été forcée
4012
-	// OU que la longueur de l’argument géneré est plus long
4013
-	// que ce qui est toléré.
4014
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4015
-	if (!$cache_contextes_ajax) {
4016
-		$env = $c;
4017
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4018
-			$env = gzdeflate($env);
4019
-		}
4020
-		$env = _xor($env);
4021
-		$env = base64_encode($env);
4022
-		$len = strlen($env);
4023
-		// Si l’url est trop longue pour le navigateur
4024
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4025
-		if ($len > $max_len) {
4026
-			$cache_contextes_ajax = true;
4027
-			spip_log(
4028
-				'Contextes AJAX forces en fichiers !'
4029
-				. ' Cela arrive lorsque la valeur du contexte'
4030
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4031
-				_LOG_AVERTISSEMENT
4032
-			);
4033
-		}
4034
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4035
-		elseif (
4036
-			$max_len = @ini_get('suhosin.get.max_value_length')
4037
-			and $max_len < $len
4038
-		) {
4039
-			$cache_contextes_ajax = true;
4040
-			spip_log('Contextes AJAX forces en fichiers !'
4041
-				. ' Cela arrive lorsque la valeur du contexte'
4042
-				. ' depasse la longueur maximale autorisee par Suhosin'
4043
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4044
-				. ' Vous devriez modifier les parametres de Suhosin'
4045
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4046
-		}
4047
-	}
4048
-
4049
-	if ($cache_contextes_ajax) {
4050
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4051
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4052
-		$md5 = md5($c);
4053
-		ecrire_fichier("$dir/c$md5", $c);
4054
-		$env = $md5;
4055
-	}
4056
-
4057
-	if ($emboite === null) {
4058
-		return $env;
4059
-	}
4060
-	if (!trim($emboite)) {
4061
-		return '';
4062
-	}
4063
-	// toujours encoder l'url source dans le bloc ajax
4064
-	$r = self();
4065
-	$r = ' data-origin="' . $r . '"';
4066
-	$class = 'ajaxbloc';
4067
-	if ($ajaxid and is_string($ajaxid)) {
4068
-		// ajaxid est normalement conforme a un nom de classe css
4069
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4070
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4071
-	}
4072
-
4073
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3982
+    $env = null;
3983
+    if (
3984
+        is_string($c)
3985
+        and @unserialize($c) !== false
3986
+    ) {
3987
+        $c = unserialize($c);
3988
+    }
3989
+
3990
+    // supprimer les parametres debut_x
3991
+    // pour que la pagination ajax ne soit pas plantee
3992
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3993
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3994
+    if (is_array($c)) {
3995
+        foreach ($c as $k => $v) {
3996
+            if (strpos($k, 'debut_') === 0) {
3997
+                unset($c[$k]);
3998
+            }
3999
+        }
4000
+    }
4001
+
4002
+    if (!function_exists('calculer_cle_action')) {
4003
+        include_spip('inc/securiser_action');
4004
+    }
4005
+
4006
+    $c = serialize($c);
4007
+    $cle = calculer_cle_action($form . $c);
4008
+    $c = "$cle:$c";
4009
+
4010
+    // on ne stocke pas les contextes dans des fichiers en cache
4011
+    // par defaut, sauf si cette configuration a été forcée
4012
+    // OU que la longueur de l’argument géneré est plus long
4013
+    // que ce qui est toléré.
4014
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4015
+    if (!$cache_contextes_ajax) {
4016
+        $env = $c;
4017
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4018
+            $env = gzdeflate($env);
4019
+        }
4020
+        $env = _xor($env);
4021
+        $env = base64_encode($env);
4022
+        $len = strlen($env);
4023
+        // Si l’url est trop longue pour le navigateur
4024
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4025
+        if ($len > $max_len) {
4026
+            $cache_contextes_ajax = true;
4027
+            spip_log(
4028
+                'Contextes AJAX forces en fichiers !'
4029
+                . ' Cela arrive lorsque la valeur du contexte'
4030
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4031
+                _LOG_AVERTISSEMENT
4032
+            );
4033
+        }
4034
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4035
+        elseif (
4036
+            $max_len = @ini_get('suhosin.get.max_value_length')
4037
+            and $max_len < $len
4038
+        ) {
4039
+            $cache_contextes_ajax = true;
4040
+            spip_log('Contextes AJAX forces en fichiers !'
4041
+                . ' Cela arrive lorsque la valeur du contexte'
4042
+                . ' depasse la longueur maximale autorisee par Suhosin'
4043
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4044
+                . ' Vous devriez modifier les parametres de Suhosin'
4045
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4046
+        }
4047
+    }
4048
+
4049
+    if ($cache_contextes_ajax) {
4050
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4051
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4052
+        $md5 = md5($c);
4053
+        ecrire_fichier("$dir/c$md5", $c);
4054
+        $env = $md5;
4055
+    }
4056
+
4057
+    if ($emboite === null) {
4058
+        return $env;
4059
+    }
4060
+    if (!trim($emboite)) {
4061
+        return '';
4062
+    }
4063
+    // toujours encoder l'url source dans le bloc ajax
4064
+    $r = self();
4065
+    $r = ' data-origin="' . $r . '"';
4066
+    $class = 'ajaxbloc';
4067
+    if ($ajaxid and is_string($ajaxid)) {
4068
+        // ajaxid est normalement conforme a un nom de classe css
4069
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4070
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4071
+    }
4072
+
4073
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4074 4074
 }
4075 4075
 
4076 4076
 /**
@@ -4090,37 +4090,37 @@  discard block
 block discarded – undo
4090 4090
  *   - false : erreur de décodage
4091 4091
  */
4092 4092
 function decoder_contexte_ajax($c, $form = '') {
4093
-	if (!function_exists('calculer_cle_action')) {
4094
-		include_spip('inc/securiser_action');
4095
-	}
4096
-	if (
4097
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4098
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4099
-		and lire_fichier("$dir/c$c", $contexte)
4100
-	) {
4101
-		$c = $contexte;
4102
-	} else {
4103
-		$c = @base64_decode($c);
4104
-		$c = _xor($c);
4105
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4106
-			$c = @gzinflate($c);
4107
-		}
4108
-	}
4109
-
4110
-	// extraire la signature en debut de contexte
4111
-	// et la verifier avant de deserializer
4112
-	// format : signature:donneesserializees
4113
-	if ($p = strpos($c, ':')) {
4114
-		$cle = substr($c, 0, $p);
4115
-		$c = substr($c, $p + 1);
4116
-
4117
-		if ($cle == calculer_cle_action($form . $c)) {
4118
-			$env = @unserialize($c);
4119
-			return $env;
4120
-		}
4121
-	}
4122
-
4123
-	return false;
4093
+    if (!function_exists('calculer_cle_action')) {
4094
+        include_spip('inc/securiser_action');
4095
+    }
4096
+    if (
4097
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4098
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4099
+        and lire_fichier("$dir/c$c", $contexte)
4100
+    ) {
4101
+        $c = $contexte;
4102
+    } else {
4103
+        $c = @base64_decode($c);
4104
+        $c = _xor($c);
4105
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4106
+            $c = @gzinflate($c);
4107
+        }
4108
+    }
4109
+
4110
+    // extraire la signature en debut de contexte
4111
+    // et la verifier avant de deserializer
4112
+    // format : signature:donneesserializees
4113
+    if ($p = strpos($c, ':')) {
4114
+        $cle = substr($c, 0, $p);
4115
+        $c = substr($c, $p + 1);
4116
+
4117
+        if ($cle == calculer_cle_action($form . $c)) {
4118
+            $env = @unserialize($c);
4119
+            return $env;
4120
+        }
4121
+    }
4122
+
4123
+    return false;
4124 4124
 }
4125 4125
 
4126 4126
 
@@ -4138,20 +4138,20 @@  discard block
 block discarded – undo
4138 4138
  *    Message décrypté ou encrypté
4139 4139
  **/
4140 4140
 function _xor($message, $key = null) {
4141
-	if (is_null($key)) {
4142
-		if (!function_exists('calculer_cle_action')) {
4143
-			include_spip('inc/securiser_action');
4144
-		}
4145
-		$key = pack('H*', calculer_cle_action('_xor'));
4146
-	}
4141
+    if (is_null($key)) {
4142
+        if (!function_exists('calculer_cle_action')) {
4143
+            include_spip('inc/securiser_action');
4144
+        }
4145
+        $key = pack('H*', calculer_cle_action('_xor'));
4146
+    }
4147 4147
 
4148
-	$keylen = strlen($key);
4149
-	$messagelen = strlen($message);
4150
-	for ($i = 0; $i < $messagelen; $i++) {
4151
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4152
-	}
4148
+    $keylen = strlen($key);
4149
+    $messagelen = strlen($message);
4150
+    for ($i = 0; $i < $messagelen; $i++) {
4151
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4152
+    }
4153 4153
 
4154
-	return $message;
4154
+    return $message;
4155 4155
 }
4156 4156
 
4157 4157
 /**
@@ -4165,7 +4165,7 @@  discard block
 block discarded – undo
4165 4165
  * @return string
4166 4166
  */
4167 4167
 function url_reponse_forum($texte) {
4168
- return $texte;
4168
+    return $texte;
4169 4169
 }
4170 4170
 
4171 4171
 /**
@@ -4179,7 +4179,7 @@  discard block
 block discarded – undo
4179 4179
  * @return string
4180 4180
  */
4181 4181
 function url_rss_forum($texte) {
4182
- return $texte;
4182
+    return $texte;
4183 4183
 }
4184 4184
 
4185 4185
 
@@ -4218,37 +4218,37 @@  discard block
 block discarded – undo
4218 4218
  *   Code HTML
4219 4219
  */
4220 4220
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4221
-	if ($on) {
4222
-		$bal = 'strong';
4223
-		$class = '';
4224
-		$att = '';
4225
-		// si $on passe la balise et optionnelement une ou ++classe
4226
-		// a.active span.selected.active etc....
4227
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4228
-			$on = explode('.', $on);
4229
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4230
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4231
-				$bal = array_shift($on);
4232
-				$class = implode(' ', $on);
4233
-				if ($bal == 'a') {
4234
-					$att = 'href="#" ';
4235
-				}
4236
-			}
4237
-		}
4238
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4239
-	} else {
4240
-		$bal = 'a';
4241
-		$att = "href='$url'"
4242
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4243
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4244
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4245
-			. $evt;
4246
-	}
4247
-	if ($libelle === null) {
4248
-		$libelle = $url;
4249
-	}
4250
-
4251
-	return "<$bal $att>$libelle</$bal>";
4221
+    if ($on) {
4222
+        $bal = 'strong';
4223
+        $class = '';
4224
+        $att = '';
4225
+        // si $on passe la balise et optionnelement une ou ++classe
4226
+        // a.active span.selected.active etc....
4227
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4228
+            $on = explode('.', $on);
4229
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4230
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4231
+                $bal = array_shift($on);
4232
+                $class = implode(' ', $on);
4233
+                if ($bal == 'a') {
4234
+                    $att = 'href="#" ';
4235
+                }
4236
+            }
4237
+        }
4238
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4239
+    } else {
4240
+        $bal = 'a';
4241
+        $att = "href='$url'"
4242
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4243
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4244
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4245
+            . $evt;
4246
+    }
4247
+    if ($libelle === null) {
4248
+        $libelle = $url;
4249
+    }
4250
+
4251
+    return "<$bal $att>$libelle</$bal>";
4252 4252
 }
4253 4253
 
4254 4254
 
@@ -4265,39 +4265,39 @@  discard block
 block discarded – undo
4265 4265
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4266 4266
  */
4267 4267
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4268
-	static $local_singulier_ou_pluriel = [];
4269
-
4270
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4271
-	if (!is_numeric($nb) or $nb == 0) {
4272
-		return '';
4273
-	}
4274
-	if (!is_array($vars)) {
4275
-		return '';
4276
-	}
4277
-
4278
-	$langue = $GLOBALS['spip_lang'];
4279
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4280
-		$local_singulier_ou_pluriel[$langue] = false;
4281
-		if (
4282
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4283
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4284
-		) {
4285
-			$local_singulier_ou_pluriel[$langue] = $f;
4286
-		}
4287
-	}
4288
-
4289
-	// si on a une surcharge on l'utilise
4290
-	if ($local_singulier_ou_pluriel[$langue]) {
4291
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4292
-	}
4293
-
4294
-	// sinon traitement par defaut
4295
-	$vars[$var] = $nb;
4296
-	if ($nb >= 2) {
4297
-		return _T($chaine_plusieurs, $vars);
4298
-	} else {
4299
-		return _T($chaine_un, $vars);
4300
-	}
4268
+    static $local_singulier_ou_pluriel = [];
4269
+
4270
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4271
+    if (!is_numeric($nb) or $nb == 0) {
4272
+        return '';
4273
+    }
4274
+    if (!is_array($vars)) {
4275
+        return '';
4276
+    }
4277
+
4278
+    $langue = $GLOBALS['spip_lang'];
4279
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4280
+        $local_singulier_ou_pluriel[$langue] = false;
4281
+        if (
4282
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4283
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4284
+        ) {
4285
+            $local_singulier_ou_pluriel[$langue] = $f;
4286
+        }
4287
+    }
4288
+
4289
+    // si on a une surcharge on l'utilise
4290
+    if ($local_singulier_ou_pluriel[$langue]) {
4291
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4292
+    }
4293
+
4294
+    // sinon traitement par defaut
4295
+    $vars[$var] = $nb;
4296
+    if ($nb >= 2) {
4297
+        return _T($chaine_plusieurs, $vars);
4298
+    } else {
4299
+        return _T($chaine_un, $vars);
4300
+    }
4301 4301
 }
4302 4302
 
4303 4303
 
@@ -4325,73 +4325,73 @@  discard block
 block discarded – undo
4325 4325
  */
4326 4326
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4327 4327
 
4328
-	$class_lien = $class_bouton = $class;
4329
-
4330
-	// Normaliser la fonction et compléter la classe en fonction
4331
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4332
-		$class_lien .= ' danger';
4333
-		$class_bouton .= ' btn_danger';
4334
-	} elseif ($fonction == 'rien.gif') {
4335
-		$fonction = '';
4336
-	} elseif ($fonction == 'delsafe') {
4337
-		$fonction = 'del';
4338
-	}
4339
-
4340
-	$fond_origine = $fond;
4341
-	// Remappage des icone : article-24.png+new => article-new-24.png
4342
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4343
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4344
-	}
4345
-
4346
-	// Ajouter le type d'objet dans la classe
4347
-	$objet_type = substr(basename($fond), 0, -4);
4348
-	$class_lien .= " $objet_type";
4349
-	$class_bouton .= " $objet_type";
4350
-
4351
-	// Texte
4352
-	$alt = attribut_html($texte);
4353
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4354
-
4355
-	// Liens : préparer les classes ajax
4356
-	$ajax = '';
4357
-	if ($type === 'lien') {
4358
-		if (strpos($class_lien, 'ajax') !== false) {
4359
-			$ajax = 'ajax';
4360
-			if (strpos($class_lien, 'preload') !== false) {
4361
-				$ajax .= ' preload';
4362
-			}
4363
-			if (strpos($class_lien, 'nocache') !== false) {
4364
-				$ajax .= ' nocache';
4365
-			}
4366
-			$ajax = " class='$ajax'";
4367
-		}
4368
-	}
4369
-
4370
-	// Repérer la taille et l'ajouter dans la classe
4371
-	$size = 24;
4372
-	if (
4373
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4374
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4375
-	) {
4376
-		$size = $match[1];
4377
-	}
4378
-	$class_lien .= " s$size";
4379
-	$class_bouton .= " s$size";
4380
-
4381
-	// Icône
4382
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4383
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4384
-
4385
-	// Markup final
4386
-	if ($type == 'lien') {
4387
-		return "<span class='icone $class_lien'>"
4388
-		. "<a href='$lien'$title$ajax$javascript>"
4389
-		. $icone
4390
-		. "<b>$texte</b>"
4391
-		. "</a></span>\n";
4392
-	} else {
4393
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4394
-	}
4328
+    $class_lien = $class_bouton = $class;
4329
+
4330
+    // Normaliser la fonction et compléter la classe en fonction
4331
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4332
+        $class_lien .= ' danger';
4333
+        $class_bouton .= ' btn_danger';
4334
+    } elseif ($fonction == 'rien.gif') {
4335
+        $fonction = '';
4336
+    } elseif ($fonction == 'delsafe') {
4337
+        $fonction = 'del';
4338
+    }
4339
+
4340
+    $fond_origine = $fond;
4341
+    // Remappage des icone : article-24.png+new => article-new-24.png
4342
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4343
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4344
+    }
4345
+
4346
+    // Ajouter le type d'objet dans la classe
4347
+    $objet_type = substr(basename($fond), 0, -4);
4348
+    $class_lien .= " $objet_type";
4349
+    $class_bouton .= " $objet_type";
4350
+
4351
+    // Texte
4352
+    $alt = attribut_html($texte);
4353
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4354
+
4355
+    // Liens : préparer les classes ajax
4356
+    $ajax = '';
4357
+    if ($type === 'lien') {
4358
+        if (strpos($class_lien, 'ajax') !== false) {
4359
+            $ajax = 'ajax';
4360
+            if (strpos($class_lien, 'preload') !== false) {
4361
+                $ajax .= ' preload';
4362
+            }
4363
+            if (strpos($class_lien, 'nocache') !== false) {
4364
+                $ajax .= ' nocache';
4365
+            }
4366
+            $ajax = " class='$ajax'";
4367
+        }
4368
+    }
4369
+
4370
+    // Repérer la taille et l'ajouter dans la classe
4371
+    $size = 24;
4372
+    if (
4373
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4374
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4375
+    ) {
4376
+        $size = $match[1];
4377
+    }
4378
+    $class_lien .= " s$size";
4379
+    $class_bouton .= " s$size";
4380
+
4381
+    // Icône
4382
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4383
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4384
+
4385
+    // Markup final
4386
+    if ($type == 'lien') {
4387
+        return "<span class='icone $class_lien'>"
4388
+        . "<a href='$lien'$title$ajax$javascript>"
4389
+        . $icone
4390
+        . "<b>$texte</b>"
4391
+        . "</a></span>\n";
4392
+    } else {
4393
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4394
+    }
4395 4395
 }
4396 4396
 
4397 4397
 /**
@@ -4415,7 +4415,7 @@  discard block
 block discarded – undo
4415 4415
  *     Code HTML du lien
4416 4416
  **/
4417 4417
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4418
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4418
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4419 4419
 }
4420 4420
 
4421 4421
 /**
@@ -4450,7 +4450,7 @@  discard block
 block discarded – undo
4450 4450
  *     Code HTML du lien
4451 4451
  **/
4452 4452
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4453
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4453
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4454 4454
 }
4455 4455
 
4456 4456
 /**
@@ -4495,7 +4495,7 @@  discard block
 block discarded – undo
4495 4495
  *     Code HTML du lien
4496 4496
  **/
4497 4497
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4498
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4498
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4499 4499
 }
4500 4500
 
4501 4501
 /**
@@ -4526,7 +4526,7 @@  discard block
 block discarded – undo
4526 4526
  *     Code HTML du lien
4527 4527
  **/
4528 4528
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4529
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4529
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4530 4530
 }
4531 4531
 
4532 4532
 /**
@@ -4557,7 +4557,7 @@  discard block
 block discarded – undo
4557 4557
  *     Code HTML du lien
4558 4558
  */
4559 4559
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4560
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4560
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4561 4561
 }
4562 4562
 
4563 4563
 
@@ -4579,7 +4579,7 @@  discard block
 block discarded – undo
4579 4579
  * @return array Liste des éléments
4580 4580
  */
4581 4581
 function filtre_explode_dist($a, $b) {
4582
-	return explode($b, (string) $a);
4582
+    return explode($b, (string) $a);
4583 4583
 }
4584 4584
 
4585 4585
 /**
@@ -4600,7 +4600,7 @@  discard block
 block discarded – undo
4600 4600
  * @return string Texte
4601 4601
  */
4602 4602
 function filtre_implode_dist($a, $b) {
4603
-	return is_array($a) ? implode($b, $a) : $a;
4603
+    return is_array($a) ? implode($b, $a) : $a;
4604 4604
 }
4605 4605
 
4606 4606
 /**
@@ -4609,24 +4609,24 @@  discard block
 block discarded – undo
4609 4609
  * @return string Code CSS
4610 4610
  */
4611 4611
 function bando_images_background() {
4612
-	include_spip('inc/bandeau');
4613
-	// recuperer tous les boutons et leurs images
4614
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4612
+    include_spip('inc/bandeau');
4613
+    // recuperer tous les boutons et leurs images
4614
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4615 4615
 
4616
-	$res = '';
4617
-	foreach ($boutons as $page => $detail) {
4618
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4619
-		if (is_array($detail->sousmenu)) {
4620
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4621
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4622
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4623
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4624
-				}
4625
-			}
4626
-		}
4627
-	}
4616
+    $res = '';
4617
+    foreach ($boutons as $page => $detail) {
4618
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4619
+        if (is_array($detail->sousmenu)) {
4620
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4621
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4622
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4623
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4624
+                }
4625
+            }
4626
+        }
4627
+    }
4628 4628
 
4629
-	return $res;
4629
+    return $res;
4630 4630
 }
4631 4631
 
4632 4632
 /**
@@ -4651,27 +4651,27 @@  discard block
 block discarded – undo
4651 4651
  */
4652 4652
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4653 4653
 
4654
-	// Classes : dispatcher `ajax` sur le formulaire
4655
-	$class_form = '';
4656
-	if (strpos($class, 'ajax') !== false) {
4657
-		$class_form = 'ajax';
4658
-		$class = str_replace('ajax', '', $class);
4659
-	}
4660
-	$class_btn = 'submit ' . trim($class);
4654
+    // Classes : dispatcher `ajax` sur le formulaire
4655
+    $class_form = '';
4656
+    if (strpos($class, 'ajax') !== false) {
4657
+        $class_form = 'ajax';
4658
+        $class = str_replace('ajax', '', $class);
4659
+    }
4660
+    $class_btn = 'submit ' . trim($class);
4661 4661
 
4662
-	if ($confirm) {
4663
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4664
-		if ($callback) {
4665
-			$callback = "$confirm?($callback):false";
4666
-		} else {
4667
-			$callback = $confirm;
4668
-		}
4669
-	}
4670
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4671
-	$title = $title ? " title='$title'" : '';
4662
+    if ($confirm) {
4663
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4664
+        if ($callback) {
4665
+            $callback = "$confirm?($callback):false";
4666
+        } else {
4667
+            $callback = $confirm;
4668
+        }
4669
+    }
4670
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4671
+    $title = $title ? " title='$title'" : '';
4672 4672
 
4673
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4674
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4673
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4674
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4675 4675
 }
4676 4676
 
4677 4677
 /**
@@ -4694,101 +4694,101 @@  discard block
 block discarded – undo
4694 4694
  * @return string
4695 4695
  */
4696 4696
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4697
-	static $trouver_table = null;
4698
-	static $objets;
4699
-
4700
-	// On verifie qu'on a tout ce qu'il faut
4701
-	$id_objet = intval($id_objet);
4702
-	if (!($id_objet and $type_objet and $info)) {
4703
-		return '';
4704
-	}
4705
-
4706
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4707
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4708
-		return '';
4709
-	}
4710
-
4711
-	// Si on demande l'url, on retourne direct la fonction
4712
-	if ($info == 'url') {
4713
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4714
-	}
4715
-
4716
-	// Sinon on va tout chercher dans la table et on garde en memoire
4717
-	$demande_titre = ($info === 'titre');
4718
-	$demande_introduction = ($info === 'introduction');
4719
-
4720
-	// 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
4721
-	if (
4722
-		!isset($objets[$type_objet][$id_objet])
4723
-		or
4724
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4725
-	) {
4726
-		if (!$trouver_table) {
4727
-			$trouver_table = charger_fonction('trouver_table', 'base');
4728
-		}
4729
-		$desc = $trouver_table(table_objet_sql($type_objet));
4730
-		if (!$desc) {
4731
-			return $objets[$type_objet] = false;
4732
-		}
4733
-
4734
-		// Si on demande le titre, on le gere en interne
4735
-		$champ_titre = '';
4736
-		if ($demande_titre) {
4737
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4738
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4739
-		}
4740
-		include_spip('base/abstract_sql');
4741
-		include_spip('base/connect_sql');
4742
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4743
-			'*' . $champ_titre,
4744
-			$desc['table_sql'],
4745
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4746
-		);
4747
-
4748
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4749
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4750
-	}
4751
-
4752
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4753
-	// ajouter la longueur au début des params supplémentaires
4754
-	if ($demande_introduction) {
4755
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4756
-		array_unshift($params, $introduction_longueur);
4757
-	}
4758
-
4759
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4760
-	if (
4761
-		$generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4762
-		// @deprecated 4.1 generer_TRUC_TYPE
4763
-		or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4764
-	) {
4765
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4766
-	}
4767
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4768
-	elseif (
4769
-		$generer = charger_fonction("generer_objet_${info}", '', true)
4770
-		// @deprecated 4.1 generer_TRUC_entite
4771
-		or $generer = charger_fonction("generer_${info}_entite", '', true)
4772
-	) {
4773
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4774
-	} // Sinon on prend directement le champ SQL tel quel
4775
-	else {
4776
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4777
-	}
4778
-
4779
-	// On va ensuite appliquer les traitements automatiques si besoin
4780
-	if (!$etoile) {
4781
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4782
-		// mais ce fonctionnement est a ameliorer !
4783
-		$info_generee = appliquer_traitement_champ(
4784
-			$info_generee,
4785
-			$info,
4786
-			table_objet($type_objet),
4787
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4788
-		);
4789
-	}
4790
-
4791
-	return $info_generee;
4697
+    static $trouver_table = null;
4698
+    static $objets;
4699
+
4700
+    // On verifie qu'on a tout ce qu'il faut
4701
+    $id_objet = intval($id_objet);
4702
+    if (!($id_objet and $type_objet and $info)) {
4703
+        return '';
4704
+    }
4705
+
4706
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4707
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4708
+        return '';
4709
+    }
4710
+
4711
+    // Si on demande l'url, on retourne direct la fonction
4712
+    if ($info == 'url') {
4713
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4714
+    }
4715
+
4716
+    // Sinon on va tout chercher dans la table et on garde en memoire
4717
+    $demande_titre = ($info === 'titre');
4718
+    $demande_introduction = ($info === 'introduction');
4719
+
4720
+    // 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
4721
+    if (
4722
+        !isset($objets[$type_objet][$id_objet])
4723
+        or
4724
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4725
+    ) {
4726
+        if (!$trouver_table) {
4727
+            $trouver_table = charger_fonction('trouver_table', 'base');
4728
+        }
4729
+        $desc = $trouver_table(table_objet_sql($type_objet));
4730
+        if (!$desc) {
4731
+            return $objets[$type_objet] = false;
4732
+        }
4733
+
4734
+        // Si on demande le titre, on le gere en interne
4735
+        $champ_titre = '';
4736
+        if ($demande_titre) {
4737
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4738
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4739
+        }
4740
+        include_spip('base/abstract_sql');
4741
+        include_spip('base/connect_sql');
4742
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4743
+            '*' . $champ_titre,
4744
+            $desc['table_sql'],
4745
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4746
+        );
4747
+
4748
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4749
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4750
+    }
4751
+
4752
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4753
+    // ajouter la longueur au début des params supplémentaires
4754
+    if ($demande_introduction) {
4755
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4756
+        array_unshift($params, $introduction_longueur);
4757
+    }
4758
+
4759
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4760
+    if (
4761
+        $generer = charger_fonction("generer_${type_objet}_${info}", '', true)
4762
+        // @deprecated 4.1 generer_TRUC_TYPE
4763
+        or $generer = charger_fonction("generer_${info}_${type_objet}", '', true)
4764
+    ) {
4765
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4766
+    }
4767
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4768
+    elseif (
4769
+        $generer = charger_fonction("generer_objet_${info}", '', true)
4770
+        // @deprecated 4.1 generer_TRUC_entite
4771
+        or $generer = charger_fonction("generer_${info}_entite", '', true)
4772
+    ) {
4773
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4774
+    } // Sinon on prend directement le champ SQL tel quel
4775
+    else {
4776
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4777
+    }
4778
+
4779
+    // On va ensuite appliquer les traitements automatiques si besoin
4780
+    if (!$etoile) {
4781
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4782
+        // mais ce fonctionnement est a ameliorer !
4783
+        $info_generee = appliquer_traitement_champ(
4784
+            $info_generee,
4785
+            $info,
4786
+            table_objet($type_objet),
4787
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4788
+        );
4789
+    }
4790
+
4791
+    return $info_generee;
4792 4792
 }
4793 4793
 
4794 4794
 /**
@@ -4796,7 +4796,7 @@  discard block
 block discarded – undo
4796 4796
  * @see generer_objet_info
4797 4797
  */
4798 4798
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4799
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4799
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4800 4800
 }
4801 4801
 
4802 4802
 /**
@@ -4829,36 +4829,36 @@  discard block
 block discarded – undo
4829 4829
  */
4830 4830
 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 {
4831 4831
 
4832
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4833
-	$texte = $ligne_sql['texte'] ?? '';
4834
-	// En absence de descriptif, on se rabat sur chapo + texte
4835
-	if (isset($ligne_sql['chapo'])) {
4836
-		$chapo = $ligne_sql['chapo'];
4837
-		$texte = strlen($descriptif) ?
4838
-			'' :
4839
-			"$chapo \n\n $texte";
4840
-	}
4832
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4833
+    $texte = $ligne_sql['texte'] ?? '';
4834
+    // En absence de descriptif, on se rabat sur chapo + texte
4835
+    if (isset($ligne_sql['chapo'])) {
4836
+        $chapo = $ligne_sql['chapo'];
4837
+        $texte = strlen($descriptif) ?
4838
+            '' :
4839
+            "$chapo \n\n $texte";
4840
+    }
4841 4841
 
4842
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4843
-	if (!intval($longueur_ou_suite)) {
4844
-		$longueur = intval($introduction_longueur ?: 600);
4845
-	} else {
4846
-		$longueur = intval($longueur_ou_suite);
4847
-	}
4842
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4843
+    if (!intval($longueur_ou_suite)) {
4844
+        $longueur = intval($introduction_longueur ?: 600);
4845
+    } else {
4846
+        $longueur = intval($longueur_ou_suite);
4847
+    }
4848 4848
 
4849
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4850
-	// Ex : #INTRODUCTION{...}
4851
-	if (
4852
-		is_null($suite)
4853
-		and !intval($longueur_ou_suite)
4854
-	) {
4855
-		$suite = $longueur_ou_suite;
4856
-	}
4849
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4850
+    // Ex : #INTRODUCTION{...}
4851
+    if (
4852
+        is_null($suite)
4853
+        and !intval($longueur_ou_suite)
4854
+    ) {
4855
+        $suite = $longueur_ou_suite;
4856
+    }
4857 4857
 
4858
-	$f = chercher_filtre('introduction');
4859
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4858
+    $f = chercher_filtre('introduction');
4859
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4860 4860
 
4861
-	return $introduction;
4861
+    return $introduction;
4862 4862
 }
4863 4863
 
4864 4864
 /**
@@ -4866,7 +4866,7 @@  discard block
 block discarded – undo
4866 4866
  * @see generer_objet_introduction
4867 4867
  */
4868 4868
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4869
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4869
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4870 4870
 }
4871 4871
 
4872 4872
 /**
@@ -4880,44 +4880,44 @@  discard block
 block discarded – undo
4880 4880
  * @return string
4881 4881
  */
4882 4882
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4883
-	if (!$champ) {
4884
-		return $texte;
4885
-	}
4883
+    if (!$champ) {
4884
+        return $texte;
4885
+    }
4886 4886
 
4887
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4888
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4889
-	include_fichiers_fonctions();
4887
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4888
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4889
+    include_fichiers_fonctions();
4890 4890
 
4891
-	$champ = strtoupper($champ);
4892
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4893
-	if (!$traitements or !is_array($traitements)) {
4894
-		return $texte;
4895
-	}
4891
+    $champ = strtoupper($champ);
4892
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4893
+    if (!$traitements or !is_array($traitements)) {
4894
+        return $texte;
4895
+    }
4896 4896
 
4897
-	$traitement = '';
4898
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4899
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4900
-		$table_objet = table_objet($table_objet);
4901
-		if (isset($traitements[$table_objet])) {
4902
-			$traitement = $traitements[$table_objet];
4903
-		}
4904
-	}
4905
-	if (!$traitement and isset($traitements[0])) {
4906
-		$traitement = $traitements[0];
4907
-	}
4908
-	// (sinon prendre le premier de la liste par defaut ?)
4897
+    $traitement = '';
4898
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4899
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4900
+        $table_objet = table_objet($table_objet);
4901
+        if (isset($traitements[$table_objet])) {
4902
+            $traitement = $traitements[$table_objet];
4903
+        }
4904
+    }
4905
+    if (!$traitement and isset($traitements[0])) {
4906
+        $traitement = $traitements[0];
4907
+    }
4908
+    // (sinon prendre le premier de la liste par defaut ?)
4909 4909
 
4910
-	if (!$traitement) {
4911
-		return $texte;
4912
-	}
4910
+    if (!$traitement) {
4911
+        return $texte;
4912
+    }
4913 4913
 
4914
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4914
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4915 4915
 
4916
-	// Fournir $connect et $Pile[0] au traitement si besoin
4917
-	$Pile = [0 => $env];
4918
-	eval("\$texte = $traitement;");
4916
+    // Fournir $connect et $Pile[0] au traitement si besoin
4917
+    $Pile = [0 => $env];
4918
+    eval("\$texte = $traitement;");
4919 4919
 
4920
-	return $texte;
4920
+    return $texte;
4921 4921
 }
4922 4922
 
4923 4923
 
@@ -4931,21 +4931,21 @@  discard block
 block discarded – undo
4931 4931
  * @return string
4932 4932
  */
4933 4933
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4934
-	include_spip('inc/liens');
4935
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4936
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4937
-	// le raccourcis n'est plus valide
4938
-	$titre = typo($titre['titre']) ?? '';
4939
-	// on essaye avec generer_info_entite ?
4940
-	if (!strlen($titre) and !$connect) {
4941
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4942
-	}
4943
-	if (!strlen($titre)) {
4944
-		$titre = _T('info_sans_titre');
4945
-	}
4946
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4934
+    include_spip('inc/liens');
4935
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4936
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4937
+    // le raccourcis n'est plus valide
4938
+    $titre = typo($titre['titre']) ?? '';
4939
+    // on essaye avec generer_info_entite ?
4940
+    if (!strlen($titre) and !$connect) {
4941
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4942
+    }
4943
+    if (!strlen($titre)) {
4944
+        $titre = _T('info_sans_titre');
4945
+    }
4946
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4947 4947
 
4948
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4948
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4949 4949
 }
4950 4950
 
4951 4951
 /**
@@ -4953,7 +4953,7 @@  discard block
 block discarded – undo
4953 4953
  * @see generer_objet_lien
4954 4954
  */
4955 4955
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4956
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4956
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4957 4957
 }
4958 4958
 
4959 4959
 /**
@@ -4969,15 +4969,15 @@  discard block
 block discarded – undo
4969 4969
  * @return string
4970 4970
  */
4971 4971
 function wrap($texte, $wrap) {
4972
-	$balises = extraire_balises($wrap);
4973
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4974
-		$texte = $wrap . $texte;
4975
-		$regs = array_reverse($regs[1]);
4976
-		$wrap = '</' . implode('></', $regs) . '>';
4977
-		$texte = $texte . $wrap;
4978
-	}
4972
+    $balises = extraire_balises($wrap);
4973
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4974
+        $texte = $wrap . $texte;
4975
+        $regs = array_reverse($regs[1]);
4976
+        $wrap = '</' . implode('></', $regs) . '>';
4977
+        $texte = $texte . $wrap;
4978
+    }
4979 4979
 
4980
-	return $texte;
4980
+    return $texte;
4981 4981
 }
4982 4982
 
4983 4983
 
@@ -4997,44 +4997,44 @@  discard block
 block discarded – undo
4997 4997
  * @return array|mixed|string
4998 4998
  */
4999 4999
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
5000
-	if (is_string($u)) {
5001
-		$u = typo($u);
5000
+    if (is_string($u)) {
5001
+        $u = typo($u);
5002 5002
 
5003
-		return $u;
5004
-	}
5003
+        return $u;
5004
+    }
5005 5005
 
5006
-	// caster $u en array si besoin
5007
-	if (is_object($u)) {
5008
-		$u = (array)$u;
5009
-	}
5006
+    // caster $u en array si besoin
5007
+    if (is_object($u)) {
5008
+        $u = (array)$u;
5009
+    }
5010 5010
 
5011
-	if (is_array($u)) {
5012
-		$out = '';
5013
-		// toutes les cles sont numeriques ?
5014
-		// et aucun enfant n'est un tableau
5015
-		// liste simple separee par des virgules
5016
-		$numeric_keys = array_map('is_numeric', array_keys($u));
5017
-		$array_values = array_map('is_array', $u);
5018
-		$object_values = array_map('is_object', $u);
5019
-		if (
5020
-			array_sum($numeric_keys) == count($numeric_keys)
5021
-			and !array_sum($array_values)
5022
-			and !array_sum($object_values)
5023
-		) {
5024
-			return join(', ', array_map('filtre_print_dist', $u));
5025
-		}
5011
+    if (is_array($u)) {
5012
+        $out = '';
5013
+        // toutes les cles sont numeriques ?
5014
+        // et aucun enfant n'est un tableau
5015
+        // liste simple separee par des virgules
5016
+        $numeric_keys = array_map('is_numeric', array_keys($u));
5017
+        $array_values = array_map('is_array', $u);
5018
+        $object_values = array_map('is_object', $u);
5019
+        if (
5020
+            array_sum($numeric_keys) == count($numeric_keys)
5021
+            and !array_sum($array_values)
5022
+            and !array_sum($object_values)
5023
+        ) {
5024
+            return join(', ', array_map('filtre_print_dist', $u));
5025
+        }
5026 5026
 
5027
-		// sinon on passe a la ligne et on indente
5028
-		$i_str = str_pad('', $indent, ' ');
5029
-		foreach ($u as $k => $v) {
5030
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5031
-		}
5027
+        // sinon on passe a la ligne et on indente
5028
+        $i_str = str_pad('', $indent, ' ');
5029
+        foreach ($u as $k => $v) {
5030
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
5031
+        }
5032 5032
 
5033
-		return $out;
5034
-	}
5033
+        return $out;
5034
+    }
5035 5035
 
5036
-	// on sait pas quoi faire...
5037
-	return $u;
5036
+    // on sait pas quoi faire...
5037
+    return $u;
5038 5038
 }
5039 5039
 
5040 5040
 
@@ -5047,10 +5047,10 @@  discard block
 block discarded – undo
5047 5047
  * @return string|array
5048 5048
  */
5049 5049
 function objet_info($objet, $info) {
5050
-	$table = table_objet_sql($objet);
5051
-	$infos = lister_tables_objets_sql($table);
5050
+    $table = table_objet_sql($objet);
5051
+    $infos = lister_tables_objets_sql($table);
5052 5052
 
5053
-	return ($infos[$info] ?? '');
5053
+    return ($infos[$info] ?? '');
5054 5054
 }
5055 5055
 
5056 5056
 /**
@@ -5065,11 +5065,11 @@  discard block
 block discarded – undo
5065 5065
  *     Texte traduit du comptage, tel que '3 articles'
5066 5066
  */
5067 5067
 function objet_afficher_nb($nb, $objet) {
5068
-	if (!$nb) {
5069
-		return _T(objet_info($objet, 'info_aucun_objet'));
5070
-	} else {
5071
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5072
-	}
5068
+    if (!$nb) {
5069
+        return _T(objet_info($objet, 'info_aucun_objet'));
5070
+    } else {
5071
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5072
+    }
5073 5073
 }
5074 5074
 
5075 5075
 /**
@@ -5081,11 +5081,11 @@  discard block
 block discarded – undo
5081 5081
  * @return string
5082 5082
  */
5083 5083
 function objet_icone($objet, $taille = 24, $class = '') {
5084
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5085
-	$icone = chemin_image($icone);
5086
-	$balise_img = charger_filtre('balise_img');
5084
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5085
+    $icone = chemin_image($icone);
5086
+    $balise_img = charger_filtre('balise_img');
5087 5087
 
5088
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5088
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5089 5089
 }
5090 5090
 
5091 5091
 /**
@@ -5106,12 +5106,12 @@  discard block
 block discarded – undo
5106 5106
  * @return string
5107 5107
  */
5108 5108
 function objet_T($objet, $chaine, $args = [], $options = []) {
5109
-	$chaine = explode(':', $chaine);
5110
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5111
-		return $t;
5112
-	}
5113
-	$chaine = implode(':', $chaine);
5114
-	return _T($chaine, $args, $options);
5109
+    $chaine = explode(':', $chaine);
5110
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5111
+        return $t;
5112
+    }
5113
+    $chaine = implode(':', $chaine);
5114
+    return _T($chaine, $args, $options);
5115 5115
 }
5116 5116
 
5117 5117
 /**
@@ -5125,18 +5125,18 @@  discard block
 block discarded – undo
5125 5125
  * @return string      Code HTML
5126 5126
  */
5127 5127
 function insert_head_css_conditionnel($flux) {
5128
-	if (
5129
-		strpos($flux, '<!-- insert_head_css -->') === false
5130
-		and $p = strpos($flux, '<!-- insert_head -->')
5131
-	) {
5132
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5133
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5134
-			$p = $p1;
5135
-		}
5136
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5137
-	}
5128
+    if (
5129
+        strpos($flux, '<!-- insert_head_css -->') === false
5130
+        and $p = strpos($flux, '<!-- insert_head -->')
5131
+    ) {
5132
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5133
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5134
+            $p = $p1;
5135
+        }
5136
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5137
+    }
5138 5138
 
5139
-	return $flux;
5139
+    return $flux;
5140 5140
 }
5141 5141
 
5142 5142
 /**
@@ -5159,72 +5159,72 @@  discard block
 block discarded – undo
5159 5159
  * @return string
5160 5160
  */
5161 5161
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5162
-	if (isset($contexte['format'])) {
5163
-		$extension = $contexte['format'];
5164
-		unset($contexte['format']);
5165
-	} else {
5166
-		$extension = 'html';
5167
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5168
-			$extension = $m[1];
5169
-		}
5170
-	}
5171
-	// recuperer le contenu produit par le squelette
5172
-	$options['raw'] = true;
5173
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5174
-
5175
-	// calculer le nom de la css
5176
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5177
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5178
-	$contexte_implicite = calculer_contexte_implicite();
5179
-
5180
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5181
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5182
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5183
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5184
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5185
-	}
5186
-	else {
5187
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5188
-		ksort($contexte);
5189
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5190
-	}
5191
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5192
-
5193
-	// mettre a jour le fichier si il n'existe pas
5194
-	// ou trop ancien
5195
-	// le dernier fichier produit est toujours suffixe par .last
5196
-	// et recopie sur le fichier cible uniquement si il change
5197
-	if (
5198
-		!file_exists($filename)
5199
-		or !file_exists($filename . '.last')
5200
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5201
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5202
-	) {
5203
-		$contenu = $cache['texte'];
5204
-		// passer les urls en absolu si c'est une css
5205
-		if ($extension == 'css') {
5206
-			$contenu = urls_absolues_css(
5207
-				$contenu,
5208
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5209
-			);
5210
-		}
5211
-
5212
-		$comment = '';
5213
-		// ne pas insérer de commentaire sur certains formats
5214
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5215
-			$comment = "/* #PRODUIRE{fond=$fond";
5216
-			foreach ($contexte as $k => $v) {
5217
-				$comment .= ",$k=$v";
5218
-			}
5219
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5220
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5221
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5222
-		}
5223
-		// et ecrire le fichier si il change
5224
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5225
-	}
5226
-
5227
-	return timestamp($filename);
5162
+    if (isset($contexte['format'])) {
5163
+        $extension = $contexte['format'];
5164
+        unset($contexte['format']);
5165
+    } else {
5166
+        $extension = 'html';
5167
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5168
+            $extension = $m[1];
5169
+        }
5170
+    }
5171
+    // recuperer le contenu produit par le squelette
5172
+    $options['raw'] = true;
5173
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5174
+
5175
+    // calculer le nom de la css
5176
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5177
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5178
+    $contexte_implicite = calculer_contexte_implicite();
5179
+
5180
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5181
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5182
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5183
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5184
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5185
+    }
5186
+    else {
5187
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5188
+        ksort($contexte);
5189
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5190
+    }
5191
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5192
+
5193
+    // mettre a jour le fichier si il n'existe pas
5194
+    // ou trop ancien
5195
+    // le dernier fichier produit est toujours suffixe par .last
5196
+    // et recopie sur le fichier cible uniquement si il change
5197
+    if (
5198
+        !file_exists($filename)
5199
+        or !file_exists($filename . '.last')
5200
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5201
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5202
+    ) {
5203
+        $contenu = $cache['texte'];
5204
+        // passer les urls en absolu si c'est une css
5205
+        if ($extension == 'css') {
5206
+            $contenu = urls_absolues_css(
5207
+                $contenu,
5208
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5209
+            );
5210
+        }
5211
+
5212
+        $comment = '';
5213
+        // ne pas insérer de commentaire sur certains formats
5214
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5215
+            $comment = "/* #PRODUIRE{fond=$fond";
5216
+            foreach ($contexte as $k => $v) {
5217
+                $comment .= ",$k=$v";
5218
+            }
5219
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5220
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5221
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5222
+        }
5223
+        // et ecrire le fichier si il change
5224
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5225
+    }
5226
+
5227
+    return timestamp($filename);
5228 5228
 }
5229 5229
 
5230 5230
 /**
@@ -5237,15 +5237,15 @@  discard block
 block discarded – undo
5237 5237
  *    $fichier auquel on a ajouté le timestamp
5238 5238
  */
5239 5239
 function timestamp($fichier) {
5240
-	if (
5241
-		!$fichier
5242
-		or !file_exists($fichier)
5243
-		or !$m = filemtime($fichier)
5244
-	) {
5245
-		return $fichier;
5246
-	}
5240
+    if (
5241
+        !$fichier
5242
+        or !file_exists($fichier)
5243
+        or !$m = filemtime($fichier)
5244
+    ) {
5245
+        return $fichier;
5246
+    }
5247 5247
 
5248
-	return "$fichier?$m";
5248
+    return "$fichier?$m";
5249 5249
 }
5250 5250
 
5251 5251
 /**
@@ -5255,11 +5255,11 @@  discard block
 block discarded – undo
5255 5255
  * @return string
5256 5256
  */
5257 5257
 function supprimer_timestamp($url) {
5258
-	if (strpos($url, '?') === false) {
5259
-		return $url;
5260
-	}
5258
+    if (strpos($url, '?') === false) {
5259
+        return $url;
5260
+    }
5261 5261
 
5262
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5262
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5263 5263
 }
5264 5264
 
5265 5265
 /**
@@ -5274,9 +5274,9 @@  discard block
 block discarded – undo
5274 5274
  * @return string
5275 5275
  */
5276 5276
 function filtre_nettoyer_titre_email_dist($titre) {
5277
-	include_spip('inc/envoyer_mail');
5277
+    include_spip('inc/envoyer_mail');
5278 5278
 
5279
-	return nettoyer_titre_email($titre);
5279
+    return nettoyer_titre_email($titre);
5280 5280
 }
5281 5281
 
5282 5282
 /**
@@ -5298,27 +5298,27 @@  discard block
 block discarded – undo
5298 5298
  * @return string
5299 5299
  */
5300 5300
 function filtre_chercher_rubrique_dist(
5301
-	$titre,
5302
-	$id_objet,
5303
-	$id_parent,
5304
-	$objet,
5305
-	$id_secteur,
5306
-	$restreint,
5307
-	$actionable = false,
5308
-	$retour_sans_cadre = false
5301
+    $titre,
5302
+    $id_objet,
5303
+    $id_parent,
5304
+    $objet,
5305
+    $id_secteur,
5306
+    $restreint,
5307
+    $actionable = false,
5308
+    $retour_sans_cadre = false
5309 5309
 ) {
5310
-	include_spip('inc/filtres_ecrire');
5310
+    include_spip('inc/filtres_ecrire');
5311 5311
 
5312
-	return chercher_rubrique(
5313
-		$titre,
5314
-		$id_objet,
5315
-		$id_parent,
5316
-		$objet,
5317
-		$id_secteur,
5318
-		$restreint,
5319
-		$actionable,
5320
-		$retour_sans_cadre
5321
-	);
5312
+    return chercher_rubrique(
5313
+        $titre,
5314
+        $id_objet,
5315
+        $id_parent,
5316
+        $objet,
5317
+        $id_secteur,
5318
+        $restreint,
5319
+        $actionable,
5320
+        $retour_sans_cadre
5321
+    );
5322 5322
 }
5323 5323
 
5324 5324
 /**
@@ -5347,56 +5347,56 @@  discard block
 block discarded – undo
5347 5347
  *     Chaîne vide si l'accès est autorisé
5348 5348
  */
5349 5349
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5350
-	if ($ok) {
5351
-		return '';
5352
-	}
5353
-
5354
-	// Vider tous les tampons
5355
-	$level = @ob_get_level();
5356
-	while ($level--) {
5357
-		@ob_end_clean();
5358
-	}
5359
-
5360
-	include_spip('inc/headers');
5361
-
5362
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5363
-	if ($url) {
5364
-		redirige_par_entete($url, '', $statut);
5365
-	}
5366
-
5367
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5368
-	if (!is_numeric($statut) and is_null($message)) {
5369
-		$message = $statut;
5370
-		$statut = 0;
5371
-	}
5372
-	if (!$message) {
5373
-		$message = '';
5374
-	}
5375
-	$statut = intval($statut);
5376
-
5377
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5378
-	if (test_espace_prive()) {
5379
-		if (!$statut or !in_array($statut, [404, 403])) {
5380
-			$statut = 403;
5381
-		}
5382
-		http_response_code(403);
5383
-		$echec = charger_fonction('403', 'exec');
5384
-		$echec($message);
5385
-	} else {
5386
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5387
-		if (!$statut) {
5388
-			$statut = 404;
5389
-		}
5390
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5391
-		http_response_code($statut);
5392
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5393
-		if ($statut >= 400) {
5394
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5395
-		}
5396
-	}
5397
-
5398
-
5399
-	exit;
5350
+    if ($ok) {
5351
+        return '';
5352
+    }
5353
+
5354
+    // Vider tous les tampons
5355
+    $level = @ob_get_level();
5356
+    while ($level--) {
5357
+        @ob_end_clean();
5358
+    }
5359
+
5360
+    include_spip('inc/headers');
5361
+
5362
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5363
+    if ($url) {
5364
+        redirige_par_entete($url, '', $statut);
5365
+    }
5366
+
5367
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5368
+    if (!is_numeric($statut) and is_null($message)) {
5369
+        $message = $statut;
5370
+        $statut = 0;
5371
+    }
5372
+    if (!$message) {
5373
+        $message = '';
5374
+    }
5375
+    $statut = intval($statut);
5376
+
5377
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5378
+    if (test_espace_prive()) {
5379
+        if (!$statut or !in_array($statut, [404, 403])) {
5380
+            $statut = 403;
5381
+        }
5382
+        http_response_code(403);
5383
+        $echec = charger_fonction('403', 'exec');
5384
+        $echec($message);
5385
+    } else {
5386
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5387
+        if (!$statut) {
5388
+            $statut = 404;
5389
+        }
5390
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5391
+        http_response_code($statut);
5392
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5393
+        if ($statut >= 400) {
5394
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5395
+        }
5396
+    }
5397
+
5398
+
5399
+    exit;
5400 5400
 }
5401 5401
 
5402 5402
 /**
@@ -5407,11 +5407,11 @@  discard block
 block discarded – undo
5407 5407
  * @return string
5408 5408
  */
5409 5409
 function filtre_compacte_dist($source, $format = null) {
5410
-	if (function_exists('compacte')) {
5411
-		return compacte($source, $format);
5412
-	}
5410
+    if (function_exists('compacte')) {
5411
+        return compacte($source, $format);
5412
+    }
5413 5413
 
5414
-	return $source;
5414
+    return $source;
5415 5415
 }
5416 5416
 
5417 5417
 
@@ -5423,31 +5423,31 @@  discard block
 block discarded – undo
5423 5423
  * @return string
5424 5424
  */
5425 5425
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5426
-	$l = strlen($passe);
5427
-
5428
-	if ($l <= 8 or !$afficher_partiellement) {
5429
-		if (!$l) {
5430
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5431
-		}
5432
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5433
-	}
5434
-
5435
-	if (is_null($portion_pourcent)) {
5436
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5437
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5438
-		}
5439
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5440
-	}
5441
-	if ($portion_pourcent >= 100) {
5442
-		return $passe;
5443
-	}
5444
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5445
-	$e = max($e, 0);
5446
-	$mid = str_pad('', $l - 2 * $e, '*');
5447
-	if ($e > 0 and strlen($mid) > 8) {
5448
-		$mid = '***...***';
5449
-	}
5450
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5426
+    $l = strlen($passe);
5427
+
5428
+    if ($l <= 8 or !$afficher_partiellement) {
5429
+        if (!$l) {
5430
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5431
+        }
5432
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5433
+    }
5434
+
5435
+    if (is_null($portion_pourcent)) {
5436
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5437
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5438
+        }
5439
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5440
+    }
5441
+    if ($portion_pourcent >= 100) {
5442
+        return $passe;
5443
+    }
5444
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5445
+    $e = max($e, 0);
5446
+    $mid = str_pad('', $l - 2 * $e, '*');
5447
+    if ($e > 0 and strlen($mid) > 8) {
5448
+        $mid = '***...***';
5449
+    }
5450
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5451 5451
 }
5452 5452
 
5453 5453
 
@@ -5468,64 +5468,64 @@  discard block
 block discarded – undo
5468 5468
  */
5469 5469
 function identifiant_slug($texte, $type = '', $options = []) {
5470 5470
 
5471
-	$original = $texte;
5472
-	$separateur = ($options['separateur'] ?? '_');
5473
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5474
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5471
+    $original = $texte;
5472
+    $separateur = ($options['separateur'] ?? '_');
5473
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5474
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5475 5475
 
5476
-	if (!function_exists('translitteration')) {
5477
-		include_spip('inc/charsets');
5478
-	}
5476
+    if (!function_exists('translitteration')) {
5477
+        include_spip('inc/charsets');
5478
+    }
5479 5479
 
5480
-	// pas de balise html
5481
-	if (strpos($texte, '<') !== false) {
5482
-		$texte = strip_tags($texte);
5483
-	}
5484
-	if (strpos($texte, '&') !== false) {
5485
-		$texte = unicode2charset($texte);
5486
-	}
5487
-	// On enlève les espaces indésirables
5488
-	$texte = trim($texte);
5480
+    // pas de balise html
5481
+    if (strpos($texte, '<') !== false) {
5482
+        $texte = strip_tags($texte);
5483
+    }
5484
+    if (strpos($texte, '&') !== false) {
5485
+        $texte = unicode2charset($texte);
5486
+    }
5487
+    // On enlève les espaces indésirables
5488
+    $texte = trim($texte);
5489 5489
 
5490
-	// On enlève les accents et cie
5491
-	$texte = translitteration($texte);
5490
+    // On enlève les accents et cie
5491
+    $texte = translitteration($texte);
5492 5492
 
5493
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5494
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5493
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5494
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5495 5495
 
5496
-	// nettoyer les doubles occurences du separateur si besoin
5497
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5498
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5499
-	}
5496
+    // nettoyer les doubles occurences du separateur si besoin
5497
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5498
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5499
+    }
5500 5500
 
5501
-	// pas de separateur au debut ni a la fin
5502
-	$texte = trim($texte, $separateur);
5501
+    // pas de separateur au debut ni a la fin
5502
+    $texte = trim($texte, $separateur);
5503 5503
 
5504
-	// en minuscules
5505
-	$texte = strtolower($texte);
5504
+    // en minuscules
5505
+    $texte = strtolower($texte);
5506 5506
 
5507
-	switch ($type) {
5508
-		case 'class':
5509
-		case 'id':
5510
-		case 'anchor':
5511
-			if (preg_match(',^\d,', $texte)) {
5512
-				$texte = substr($type, 0, 1) . $texte;
5513
-			}
5514
-	}
5507
+    switch ($type) {
5508
+        case 'class':
5509
+        case 'id':
5510
+        case 'anchor':
5511
+            if (preg_match(',^\d,', $texte)) {
5512
+                $texte = substr($type, 0, 1) . $texte;
5513
+            }
5514
+    }
5515 5515
 
5516
-	if (strlen($texte) > $longueur_maxi) {
5517
-		$texte = substr($texte, 0, $longueur_maxi);
5518
-	}
5516
+    if (strlen($texte) > $longueur_maxi) {
5517
+        $texte = substr($texte, 0, $longueur_maxi);
5518
+    }
5519 5519
 
5520
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5521
-		if (preg_match(',^\d,', $texte)) {
5522
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5523
-		}
5524
-		$texte .= $separateur . md5($original);
5525
-		$texte = substr($texte, 0, $longueur_mini);
5526
-	}
5520
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5521
+        if (preg_match(',^\d,', $texte)) {
5522
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5523
+        }
5524
+        $texte .= $separateur . md5($original);
5525
+        $texte = substr($texte, 0, $longueur_mini);
5526
+    }
5527 5527
 
5528
-	return $texte;
5528
+    return $texte;
5529 5529
 }
5530 5530
 
5531 5531
 
@@ -5546,11 +5546,11 @@  discard block
 block discarded – undo
5546 5546
  * @exemple `<:info_maximum|label_nettoyer:>`
5547 5547
  */
5548 5548
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5549
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5550
-	if ($ucfirst) {
5551
-		$label = spip_ucfirst($label);
5552
-	}
5553
-	return $label;
5549
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5550
+    if ($ucfirst) {
5551
+        $label = spip_ucfirst($label);
5552
+    }
5553
+    return $label;
5554 5554
 }
5555 5555
 
5556 5556
 /**
@@ -5563,8 +5563,8 @@  discard block
 block discarded – undo
5563 5563
  * @exemple `<:info_maximum|label_ponctuer:>`
5564 5564
  */
5565 5565
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5566
-	$label = label_nettoyer($text, $ucfirst);
5567
-	return _T('label_ponctuer', ['label' => $label]);
5566
+    $label = label_nettoyer($text, $ucfirst);
5567
+    return _T('label_ponctuer', ['label' => $label]);
5568 5568
 }
5569 5569
 
5570 5570
 
@@ -5577,19 +5577,19 @@  discard block
 block discarded – undo
5577 5577
  * @return array
5578 5578
  */
5579 5579
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5580
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5581
-		return [];
5582
-	}
5580
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5581
+        return [];
5582
+    }
5583 5583
 
5584
-	// compatibilite signature inversee
5585
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5586
-		[$objet, $id_objet] = [$id_objet, $objet];
5587
-	}
5584
+    // compatibilite signature inversee
5585
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5586
+        [$objet, $id_objet] = [$id_objet, $objet];
5587
+    }
5588 5588
 
5589
-	if (!function_exists($fonction)) {
5590
-		include_spip('base/objets');
5591
-	}
5592
-	return $fonction($objet, $id_objet);
5589
+    if (!function_exists($fonction)) {
5590
+        include_spip('base/objets');
5591
+    }
5592
+    return $fonction($objet, $id_objet);
5593 5593
 }
5594 5594
 
5595 5595
 
@@ -5604,7 +5604,7 @@  discard block
 block discarded – undo
5604 5604
  * @return array
5605 5605
  */
5606 5606
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5607
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5607
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5608 5608
 }
5609 5609
 
5610 5610
 /**
@@ -5618,7 +5618,7 @@  discard block
 block discarded – undo
5618 5618
  * @return array
5619 5619
  */
5620 5620
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5621
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5621
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5622 5622
 }
5623 5623
 
5624 5624
 /**
@@ -5632,7 +5632,7 @@  discard block
 block discarded – undo
5632 5632
  * @return array
5633 5633
  */
5634 5634
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5635
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5635
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5636 5636
 }
5637 5637
 
5638 5638
 /**
@@ -5646,5 +5646,5 @@  discard block
 block discarded – undo
5646 5646
  * @return array
5647 5647
  */
5648 5648
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5649
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5649
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5650 5650
 }
Please login to merge, or discard this patch.