Completed
Push — master ( 169128...25861b )
by cam
01:08
created
ecrire/inc/filtres.php 1 patch
Indentation   +2440 added lines, -2440 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
 /**
@@ -2054,37 +2054,37 @@  discard block
 block discarded – undo
2054 2054
  *     Code html modifié
2055 2055
  **/
2056 2056
 function inserer_attribut(string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2057
-	// preparer l'attribut
2058
-	// supprimer les &nbsp; etc mais pas les balises html
2059
-	// qui ont un sens dans un attribut value d'un input
2060
-	if ($proteger) {
2061
-		$val = attribut_html($val, false);
2062
-	}
2063
-
2064
-	// echapper les ' pour eviter tout bug
2065
-	$val = str_replace("'", '&#039;', $val);
2066
-	if ($vider and strlen($val) === 0) {
2067
-		$insert = '';
2068
-	} else {
2069
-		$insert = " $attribut='$val'";
2070
-	}
2071
-
2072
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2073
-
2074
-	if ($old !== null) {
2075
-		// Remplacer l'ancien attribut du meme nom
2076
-		$balise = $r[1] . $insert . $r[5];
2077
-	} else {
2078
-		// preferer une balise " />" (comme <img />)
2079
-		if (preg_match(',/>,', $balise)) {
2080
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2081
-		} // sinon une balise <a ...> ... </a>
2082
-		else {
2083
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2084
-		}
2085
-	}
2086
-
2087
-	return $balise;
2057
+    // preparer l'attribut
2058
+    // supprimer les &nbsp; etc mais pas les balises html
2059
+    // qui ont un sens dans un attribut value d'un input
2060
+    if ($proteger) {
2061
+        $val = attribut_html($val, false);
2062
+    }
2063
+
2064
+    // echapper les ' pour eviter tout bug
2065
+    $val = str_replace("'", '&#039;', $val);
2066
+    if ($vider and strlen($val) === 0) {
2067
+        $insert = '';
2068
+    } else {
2069
+        $insert = " $attribut='$val'";
2070
+    }
2071
+
2072
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2073
+
2074
+    if ($old !== null) {
2075
+        // Remplacer l'ancien attribut du meme nom
2076
+        $balise = $r[1] . $insert . $r[5];
2077
+    } else {
2078
+        // preferer une balise " />" (comme <img />)
2079
+        if (preg_match(',/>,', $balise)) {
2080
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2081
+        } // sinon une balise <a ...> ... </a>
2082
+        else {
2083
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2084
+        }
2085
+    }
2086
+
2087
+    return $balise;
2088 2088
 }
2089 2089
 
2090 2090
 /**
@@ -2102,7 +2102,7 @@  discard block
 block discarded – undo
2102 2102
  * @return string Code HTML sans l'attribut
2103 2103
  **/
2104 2104
 function vider_attribut(string $balise, string $attribut): string {
2105
-	return inserer_attribut($balise, $attribut, '', false, true);
2105
+    return inserer_attribut($balise, $attribut, '', false, true);
2106 2106
 }
2107 2107
 
2108 2108
 /**
@@ -2114,53 +2114,53 @@  discard block
 block discarded – undo
2114 2114
  * @return string
2115 2115
  */
2116 2116
 function modifier_class($balise, $class, $operation = 'ajouter') {
2117
-	if (is_string($class)) {
2118
-		$class = explode(' ', trim($class));
2119
-	}
2120
-	$class = array_filter($class);
2121
-	$class = array_unique($class);
2122
-	if (!$class) {
2123
-		return $balise;
2124
-	}
2125
-
2126
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2127
-	if (preg_match(',[^\w-],', implode('', $class))) {
2128
-		return $balise;
2129
-	}
2130
-
2131
-	$class_courante = extraire_attribut($balise, 'class');
2132
-	$class_new = $class_courante;
2133
-	foreach ($class as $c) {
2134
-		$is_class_presente = false;
2135
-		if (
2136
-			$class_courante
2137
-			and strpos($class_courante, (string) $c) !== false
2138
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2139
-		) {
2140
-			$is_class_presente = true;
2141
-		}
2142
-		if (
2143
-			in_array($operation, ['ajouter', 'commuter'])
2144
-			and !$is_class_presente
2145
-		) {
2146
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2147
-		} elseif (
2148
-			in_array($operation, ['supprimer', 'commuter'])
2149
-			and $is_class_presente
2150
-		) {
2151
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2152
-		}
2153
-	}
2154
-
2155
-	if ($class_new !== $class_courante) {
2156
-		if (strlen($class_new)) {
2157
-			$balise = inserer_attribut($balise, 'class', $class_new);
2158
-		} elseif ($class_courante) {
2159
-			$balise = vider_attribut($balise, 'class');
2160
-		}
2161
-	}
2162
-
2163
-	return $balise;
2117
+    if (is_string($class)) {
2118
+        $class = explode(' ', trim($class));
2119
+    }
2120
+    $class = array_filter($class);
2121
+    $class = array_unique($class);
2122
+    if (!$class) {
2123
+        return $balise;
2124
+    }
2125
+
2126
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2127
+    if (preg_match(',[^\w-],', implode('', $class))) {
2128
+        return $balise;
2129
+    }
2130
+
2131
+    $class_courante = extraire_attribut($balise, 'class');
2132
+    $class_new = $class_courante;
2133
+    foreach ($class as $c) {
2134
+        $is_class_presente = false;
2135
+        if (
2136
+            $class_courante
2137
+            and strpos($class_courante, (string) $c) !== false
2138
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2139
+        ) {
2140
+            $is_class_presente = true;
2141
+        }
2142
+        if (
2143
+            in_array($operation, ['ajouter', 'commuter'])
2144
+            and !$is_class_presente
2145
+        ) {
2146
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2147
+        } elseif (
2148
+            in_array($operation, ['supprimer', 'commuter'])
2149
+            and $is_class_presente
2150
+        ) {
2151
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2152
+        }
2153
+    }
2154
+
2155
+    if ($class_new !== $class_courante) {
2156
+        if (strlen($class_new)) {
2157
+            $balise = inserer_attribut($balise, 'class', $class_new);
2158
+        } elseif ($class_courante) {
2159
+            $balise = vider_attribut($balise, 'class');
2160
+        }
2161
+    }
2162
+
2163
+    return $balise;
2164 2164
 }
2165 2165
 
2166 2166
 /**
@@ -2170,7 +2170,7 @@  discard block
 block discarded – undo
2170 2170
  * @return string
2171 2171
  */
2172 2172
 function ajouter_class($balise, $class) {
2173
-	return modifier_class($balise, $class, 'ajouter');
2173
+    return modifier_class($balise, $class, 'ajouter');
2174 2174
 }
2175 2175
 
2176 2176
 /**
@@ -2180,7 +2180,7 @@  discard block
 block discarded – undo
2180 2180
  * @return string
2181 2181
  */
2182 2182
 function supprimer_class($balise, $class) {
2183
-	return modifier_class($balise, $class, 'supprimer');
2183
+    return modifier_class($balise, $class, 'supprimer');
2184 2184
 }
2185 2185
 
2186 2186
 /**
@@ -2191,7 +2191,7 @@  discard block
 block discarded – undo
2191 2191
  * @return string
2192 2192
  */
2193 2193
 function commuter_class($balise, $class) {
2194
-	return modifier_class($balise, $class, 'commuter');
2194
+    return modifier_class($balise, $class, 'commuter');
2195 2195
 }
2196 2196
 
2197 2197
 /**
@@ -2202,19 +2202,19 @@  discard block
 block discarded – undo
2202 2202
  * @return string
2203 2203
  */
2204 2204
 function tester_config($id, $mode = '') {
2205
-	include_spip('action/inscrire_auteur');
2205
+    include_spip('action/inscrire_auteur');
2206 2206
 
2207
-	return tester_statut_inscription($mode, $id);
2207
+    return tester_statut_inscription($mode, $id);
2208 2208
 }
2209 2209
 
2210 2210
 //
2211 2211
 // Quelques fonctions de calcul arithmetique
2212 2212
 //
2213 2213
 function floatstr($a) {
2214
- return str_replace(',', '.', (string)floatval($a));
2214
+    return str_replace(',', '.', (string)floatval($a));
2215 2215
 }
2216 2216
 function strize($f, $a, $b) {
2217
- return floatstr($f(floatstr($a), floatstr($b)));
2217
+    return floatstr($f(floatstr($a), floatstr($b)));
2218 2218
 }
2219 2219
 
2220 2220
 /**
@@ -2233,7 +2233,7 @@  discard block
 block discarded – undo
2233 2233
  * @return int $a+$b
2234 2234
  **/
2235 2235
 function plus($a, $b) {
2236
-	return $a + $b;
2236
+    return $a + $b;
2237 2237
 }
2238 2238
 function strplus($a, $b) {
2239 2239
 return strize('plus', $a, $b);
@@ -2254,7 +2254,7 @@  discard block
 block discarded – undo
2254 2254
  * @return int $a-$b
2255 2255
  **/
2256 2256
 function moins($a, $b) {
2257
-	return $a - $b;
2257
+    return $a - $b;
2258 2258
 }
2259 2259
 function strmoins($a, $b) {
2260 2260
 return strize('moins', $a, $b);
@@ -2277,7 +2277,7 @@  discard block
 block discarded – undo
2277 2277
  * @return int $a*$b
2278 2278
  **/
2279 2279
 function mult($a, $b) {
2280
-	return $a * $b;
2280
+    return $a * $b;
2281 2281
 }
2282 2282
 function strmult($a, $b) {
2283 2283
 return strize('mult', $a, $b);
@@ -2300,7 +2300,7 @@  discard block
 block discarded – undo
2300 2300
  * @return int $a/$b (ou 0 si $b est nul)
2301 2301
  **/
2302 2302
 function div($a, $b) {
2303
-	return $b ? $a / $b : 0;
2303
+    return $b ? $a / $b : 0;
2304 2304
 }
2305 2305
 function strdiv($a, $b) {
2306 2306
 return strize('div', $a, $b);
@@ -2324,7 +2324,7 @@  discard block
 block discarded – undo
2324 2324
  * @return int ($nb % $mod) + $add
2325 2325
  **/
2326 2326
 function modulo($nb, $mod, $add = 0) {
2327
-	return ($mod ? $nb % $mod : 0) + $add;
2327
+    return ($mod ? $nb % $mod : 0) + $add;
2328 2328
 }
2329 2329
 
2330 2330
 
@@ -2339,26 +2339,26 @@  discard block
 block discarded – undo
2339 2339
  *      - true sinon
2340 2340
  **/
2341 2341
 function nom_acceptable($nom) {
2342
-	$remp2 = [];
2343
-	$remp1 = [];
2344
-	if (!is_string($nom)) {
2345
-		return false;
2346
-	}
2347
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2348
-		define('_TAGS_NOM_AUTEUR', '');
2349
-	}
2350
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2351
-	foreach ($tags_acceptes as $tag) {
2352
-		if (strlen($tag)) {
2353
-			$remp1[] = '<' . trim($tag) . '>';
2354
-			$remp1[] = '</' . trim($tag) . '>';
2355
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2356
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2357
-		}
2358
-	}
2359
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2360
-
2361
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2342
+    $remp2 = [];
2343
+    $remp1 = [];
2344
+    if (!is_string($nom)) {
2345
+        return false;
2346
+    }
2347
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2348
+        define('_TAGS_NOM_AUTEUR', '');
2349
+    }
2350
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2351
+    foreach ($tags_acceptes as $tag) {
2352
+        if (strlen($tag)) {
2353
+            $remp1[] = '<' . trim($tag) . '>';
2354
+            $remp1[] = '</' . trim($tag) . '>';
2355
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2356
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2357
+        }
2358
+    }
2359
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2360
+
2361
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2362 2362
 }
2363 2363
 
2364 2364
 
@@ -2374,14 +2374,14 @@  discard block
 block discarded – undo
2374 2374
  *      - renvoie un tableau si l'entree est un tableau
2375 2375
  **/
2376 2376
 function email_valide($adresses) {
2377
-	if (is_array($adresses)) {
2378
-		$adresses = array_map('email_valide', $adresses);
2379
-		$adresses = array_filter($adresses);
2380
-		return $adresses;
2381
-	}
2377
+    if (is_array($adresses)) {
2378
+        $adresses = array_map('email_valide', $adresses);
2379
+        $adresses = array_filter($adresses);
2380
+        return $adresses;
2381
+    }
2382 2382
 
2383
-	$email_valide = charger_fonction('email_valide', 'inc');
2384
-	return $email_valide($adresses);
2383
+    $email_valide = charger_fonction('email_valide', 'inc');
2384
+    return $email_valide($adresses);
2385 2385
 }
2386 2386
 
2387 2387
 /**
@@ -2395,27 +2395,27 @@  discard block
 block discarded – undo
2395 2395
  * @return string Texte
2396 2396
  **/
2397 2397
 function afficher_enclosures($tags) {
2398
-	$s = [];
2399
-	foreach (extraire_balises($tags, 'a') as $tag) {
2400
-		if (
2401
-			extraire_attribut($tag, 'rel') == 'enclosure'
2402
-			and $t = extraire_attribut($tag, 'href')
2403
-		) {
2404
-			$s[] = preg_replace(
2405
-				',>[^<]+</a>,S',
2406
-				'>'
2407
-				. http_img_pack(
2408
-					'attachment-16.png',
2409
-					$t,
2410
-					'title="' . attribut_html($t) . '"'
2411
-				)
2412
-				. '</a>',
2413
-				$tag
2414
-			);
2415
-		}
2416
-	}
2417
-
2418
-	return join('&nbsp;', $s);
2398
+    $s = [];
2399
+    foreach (extraire_balises($tags, 'a') as $tag) {
2400
+        if (
2401
+            extraire_attribut($tag, 'rel') == 'enclosure'
2402
+            and $t = extraire_attribut($tag, 'href')
2403
+        ) {
2404
+            $s[] = preg_replace(
2405
+                ',>[^<]+</a>,S',
2406
+                '>'
2407
+                . http_img_pack(
2408
+                    'attachment-16.png',
2409
+                    $t,
2410
+                    'title="' . attribut_html($t) . '"'
2411
+                )
2412
+                . '</a>',
2413
+                $tag
2414
+            );
2415
+        }
2416
+    }
2417
+
2418
+    return join('&nbsp;', $s);
2419 2419
 }
2420 2420
 
2421 2421
 /**
@@ -2430,15 +2430,15 @@  discard block
 block discarded – undo
2430 2430
  * @return string Liens trouvés
2431 2431
  **/
2432 2432
 function afficher_tags($tags, $rels = 'tag,directory') {
2433
-	$s = [];
2434
-	foreach (extraire_balises($tags, 'a') as $tag) {
2435
-		$rel = extraire_attribut($tag, 'rel');
2436
-		if (strstr(",$rels,", (string) ",$rel,")) {
2437
-			$s[] = $tag;
2438
-		}
2439
-	}
2433
+    $s = [];
2434
+    foreach (extraire_balises($tags, 'a') as $tag) {
2435
+        $rel = extraire_attribut($tag, 'rel');
2436
+        if (strstr(",$rels,", (string) ",$rel,")) {
2437
+            $s[] = $tag;
2438
+        }
2439
+    }
2440 2440
 
2441
-	return join(', ', $s);
2441
+    return join(', ', $s);
2442 2442
 }
2443 2443
 
2444 2444
 
@@ -2460,21 +2460,21 @@  discard block
 block discarded – undo
2460 2460
  * @return string Tag HTML `<a>` avec microformat.
2461 2461
  **/
2462 2462
 function enclosure2microformat($e) {
2463
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2464
-		$url = filtrer_entites(extraire_attribut($e, 'href'));
2465
-	}
2466
-	$type = extraire_attribut($e, 'type');
2467
-	if (!$length = extraire_attribut($e, 'length')) {
2468
-		# <media:content : longeur dans fileSize. On tente.
2469
-		$length = extraire_attribut($e, 'fileSize');
2470
-	}
2471
-	$fichier = basename($url);
2463
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) {
2464
+        $url = filtrer_entites(extraire_attribut($e, 'href'));
2465
+    }
2466
+    $type = extraire_attribut($e, 'type');
2467
+    if (!$length = extraire_attribut($e, 'length')) {
2468
+        # <media:content : longeur dans fileSize. On tente.
2469
+        $length = extraire_attribut($e, 'fileSize');
2470
+    }
2471
+    $fichier = basename($url);
2472 2472
 
2473
-	return '<a rel="enclosure"'
2474
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2475
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2476
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2477
-	. '>' . $fichier . '</a>';
2473
+    return '<a rel="enclosure"'
2474
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2475
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2476
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2477
+    . '>' . $fichier . '</a>';
2478 2478
 }
2479 2479
 
2480 2480
 /**
@@ -2492,24 +2492,24 @@  discard block
 block discarded – undo
2492 2492
  * @return string Tags RSS `<enclosure>`.
2493 2493
  **/
2494 2494
 function microformat2enclosure($tags) {
2495
-	$enclosures = [];
2496
-	foreach (extraire_balises($tags, 'a') as $e) {
2497
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2498
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2499
-			$type = extraire_attribut($e, 'type');
2500
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2501
-				$length = intval(extraire_attribut($e, 'length'));
2502
-			} # vieux data
2503
-			$fichier = basename($url);
2504
-			$enclosures[] = '<enclosure'
2505
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2506
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2507
-				. ($length ? ' length="' . $length . '"' : '')
2508
-				. ' />';
2509
-		}
2510
-	}
2495
+    $enclosures = [];
2496
+    foreach (extraire_balises($tags, 'a') as $e) {
2497
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2498
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2499
+            $type = extraire_attribut($e, 'type');
2500
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2501
+                $length = intval(extraire_attribut($e, 'length'));
2502
+            } # vieux data
2503
+            $fichier = basename($url);
2504
+            $enclosures[] = '<enclosure'
2505
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2506
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2507
+                . ($length ? ' length="' . $length . '"' : '')
2508
+                . ' />';
2509
+        }
2510
+    }
2511 2511
 
2512
-	return join("\n", $enclosures);
2512
+    return join("\n", $enclosures);
2513 2513
 }
2514 2514
 
2515 2515
 
@@ -2525,16 +2525,16 @@  discard block
 block discarded – undo
2525 2525
  * @return string Tags RSS Atom `<dc:subject>`.
2526 2526
  **/
2527 2527
 function tags2dcsubject($tags) {
2528
-	$subjects = '';
2529
-	foreach (extraire_balises($tags, 'a') as $e) {
2530
-		if (extraire_attribut($e, 'rel') == 'tag') {
2531
-			$subjects .= '<dc:subject>'
2532
-				. texte_backend(textebrut($e))
2533
-				. '</dc:subject>' . "\n";
2534
-		}
2535
-	}
2528
+    $subjects = '';
2529
+    foreach (extraire_balises($tags, 'a') as $e) {
2530
+        if (extraire_attribut($e, 'rel') == 'tag') {
2531
+            $subjects .= '<dc:subject>'
2532
+                . texte_backend(textebrut($e))
2533
+                . '</dc:subject>' . "\n";
2534
+        }
2535
+    }
2536 2536
 
2537
-	return $subjects;
2537
+    return $subjects;
2538 2538
 }
2539 2539
 
2540 2540
 /**
@@ -2563,27 +2563,27 @@  discard block
 block discarded – undo
2563 2563
  *     - Tableau de résultats, si tableau en entrée.
2564 2564
  **/
2565 2565
 function extraire_balise($texte, $tag = 'a') {
2566
-	if (is_array($texte)) {
2567
-		array_walk(
2568
-			$texte,
2569
-			function (&$a, $key, $t) {
2570
-				$a = extraire_balise($a, $t);
2571
-			},
2572
-			$tag
2573
-		);
2574
-
2575
-		return $texte;
2576
-	}
2577
-
2578
-	if (
2579
-		preg_match(
2580
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2581
-			$texte,
2582
-			$regs
2583
-		)
2584
-	) {
2585
-		return $regs[0];
2586
-	}
2566
+    if (is_array($texte)) {
2567
+        array_walk(
2568
+            $texte,
2569
+            function (&$a, $key, $t) {
2570
+                $a = extraire_balise($a, $t);
2571
+            },
2572
+            $tag
2573
+        );
2574
+
2575
+        return $texte;
2576
+    }
2577
+
2578
+    if (
2579
+        preg_match(
2580
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2581
+            $texte,
2582
+            $regs
2583
+        )
2584
+    ) {
2585
+        return $regs[0];
2586
+    }
2587 2587
 }
2588 2588
 
2589 2589
 /**
@@ -2611,30 +2611,30 @@  discard block
 block discarded – undo
2611 2611
  *     - Tableau de résultats, si tableau en entrée.
2612 2612
  **/
2613 2613
 function extraire_balises($texte, $tag = 'a') {
2614
-	if (is_array($texte)) {
2615
-		array_walk(
2616
-			$texte,
2617
-			function (&$a, $key, $t) {
2618
-				$a = extraire_balises($a, $t);
2619
-			},
2620
-			$tag
2621
-		);
2622
-
2623
-		return $texte;
2624
-	}
2625
-
2626
-	if (
2627
-		preg_match_all(
2628
-			",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2629
-			$texte,
2630
-			$regs,
2631
-			PREG_PATTERN_ORDER
2632
-		)
2633
-	) {
2634
-		return $regs[0];
2635
-	} else {
2636
-		return [];
2637
-	}
2614
+    if (is_array($texte)) {
2615
+        array_walk(
2616
+            $texte,
2617
+            function (&$a, $key, $t) {
2618
+                $a = extraire_balises($a, $t);
2619
+            },
2620
+            $tag
2621
+        );
2622
+
2623
+        return $texte;
2624
+    }
2625
+
2626
+    if (
2627
+        preg_match_all(
2628
+            ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS",
2629
+            $texte,
2630
+            $regs,
2631
+            PREG_PATTERN_ORDER
2632
+        )
2633
+    ) {
2634
+        return $regs[0];
2635
+    } else {
2636
+        return [];
2637
+    }
2638 2638
 }
2639 2639
 
2640 2640
 /**
@@ -2663,11 +2663,11 @@  discard block
 block discarded – undo
2663 2663
  *     - `$def` si on n'a pas transmis de tableau
2664 2664
  **/
2665 2665
 function in_any($val, $vals, $def = '') {
2666
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2667
-		$vals = $v;
2668
-	}
2666
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2667
+        $vals = $v;
2668
+    }
2669 2669
 
2670
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2670
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2671 2671
 }
2672 2672
 
2673 2673
 
@@ -2688,12 +2688,12 @@  discard block
 block discarded – undo
2688 2688
  *     Résultat du calcul
2689 2689
  **/
2690 2690
 function valeur_numerique($expr) {
2691
-	$a = 0;
2692
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2693
-		eval("\$a = $expr;");
2694
-	}
2691
+    $a = 0;
2692
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2693
+        eval("\$a = $expr;");
2694
+    }
2695 2695
 
2696
-	return intval($a);
2696
+    return intval($a);
2697 2697
 }
2698 2698
 
2699 2699
 /**
@@ -2712,7 +2712,7 @@  discard block
 block discarded – undo
2712 2712
  *      Retourne `$a*$b/$c`
2713 2713
  **/
2714 2714
 function regledetrois($a, $b, $c) {
2715
-	return round($a * $b / $c);
2715
+    return round($a * $b / $c);
2716 2716
 }
2717 2717
 
2718 2718
 
@@ -2736,77 +2736,77 @@  discard block
 block discarded – undo
2736 2736
  **/
2737 2737
 function form_hidden($action) {
2738 2738
 
2739
-	$contexte = [];
2740
-	include_spip('inc/urls');
2741
-	if (
2742
-		$p = urls_decoder_url($action, '')
2743
-		and reset($p)
2744
-	) {
2745
-		$fond = array_shift($p);
2746
-		if ($fond != '404') {
2747
-			$contexte = array_shift($p);
2748
-			$contexte['page'] = $fond;
2749
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2750
-		}
2751
-	}
2752
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2753
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2754
-		unset($contexte['type']);
2755
-	}
2756
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2757
-		unset($contexte['type-page']);
2758
-	}
2759
-
2760
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2761
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2762
-	$values = [];
2763
-
2764
-	// d'abord avec celles de l'url
2765
-	if (false !== ($p = strpos($action, '?'))) {
2766
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2767
-			$c = explode('=', $c, 2);
2768
-			$var = array_shift($c);
2769
-			$val = array_shift($c);
2770
-			if ($var) {
2771
-				$val = rawurldecode($val);
2772
-				$var = rawurldecode($var); // decoder les [] eventuels
2773
-				if (preg_match(',\[\]$,S', $var)) {
2774
-					$values[] = [$var, $val];
2775
-				} else {
2776
-					if (!isset($values[$var])) {
2777
-						$values[$var] = [$var, $val];
2778
-					}
2779
-				}
2780
-			}
2781
-		}
2782
-	}
2783
-
2784
-	// ensuite avec celles du contexte, sans doublonner !
2785
-	foreach ($contexte as $var => $val) {
2786
-		if (preg_match(',\[\]$,S', $var)) {
2787
-			$values[] = [$var, $val];
2788
-		} else {
2789
-			if (!isset($values[$var])) {
2790
-				$values[$var] = [$var, $val];
2791
-			}
2792
-		}
2793
-	}
2794
-
2795
-	// puis on rassemble le tout
2796
-	$hidden = [];
2797
-	foreach ($values as $value) {
2798
-		[$var, $val] = $value;
2799
-		$hidden[] = '<input name="'
2800
-			. entites_html($var)
2801
-			. '"'
2802
-			. (is_null($val)
2803
-				? ''
2804
-				: ' value="' . entites_html($val) . '"'
2805
-			)
2806
-			. ' type="hidden"' . "\n/>";
2807
-	}
2808
-
2809
-	return join('', $hidden);
2739
+    $contexte = [];
2740
+    include_spip('inc/urls');
2741
+    if (
2742
+        $p = urls_decoder_url($action, '')
2743
+        and reset($p)
2744
+    ) {
2745
+        $fond = array_shift($p);
2746
+        if ($fond != '404') {
2747
+            $contexte = array_shift($p);
2748
+            $contexte['page'] = $fond;
2749
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2750
+        }
2751
+    }
2752
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2753
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2754
+        unset($contexte['type']);
2755
+    }
2756
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2757
+        unset($contexte['type-page']);
2758
+    }
2759
+
2760
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2761
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2762
+    $values = [];
2763
+
2764
+    // d'abord avec celles de l'url
2765
+    if (false !== ($p = strpos($action, '?'))) {
2766
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2767
+            $c = explode('=', $c, 2);
2768
+            $var = array_shift($c);
2769
+            $val = array_shift($c);
2770
+            if ($var) {
2771
+                $val = rawurldecode($val);
2772
+                $var = rawurldecode($var); // decoder les [] eventuels
2773
+                if (preg_match(',\[\]$,S', $var)) {
2774
+                    $values[] = [$var, $val];
2775
+                } else {
2776
+                    if (!isset($values[$var])) {
2777
+                        $values[$var] = [$var, $val];
2778
+                    }
2779
+                }
2780
+            }
2781
+        }
2782
+    }
2783
+
2784
+    // ensuite avec celles du contexte, sans doublonner !
2785
+    foreach ($contexte as $var => $val) {
2786
+        if (preg_match(',\[\]$,S', $var)) {
2787
+            $values[] = [$var, $val];
2788
+        } else {
2789
+            if (!isset($values[$var])) {
2790
+                $values[$var] = [$var, $val];
2791
+            }
2792
+        }
2793
+    }
2794
+
2795
+    // puis on rassemble le tout
2796
+    $hidden = [];
2797
+    foreach ($values as $value) {
2798
+        [$var, $val] = $value;
2799
+        $hidden[] = '<input name="'
2800
+            . entites_html($var)
2801
+            . '"'
2802
+            . (is_null($val)
2803
+                ? ''
2804
+                : ' value="' . entites_html($val) . '"'
2805
+            )
2806
+            . ' type="hidden"' . "\n/>";
2807
+    }
2808
+
2809
+    return join('', $hidden);
2810 2810
 }
2811 2811
 
2812 2812
 
@@ -2828,7 +2828,7 @@  discard block
 block discarded – undo
2828 2828
  *    - la première valeur du tableau sinon.
2829 2829
  **/
2830 2830
 function filtre_reset($array) {
2831
-	return !is_array($array) ? null : reset($array);
2831
+    return !is_array($array) ? null : reset($array);
2832 2832
 }
2833 2833
 
2834 2834
 /**
@@ -2849,7 +2849,7 @@  discard block
 block discarded – undo
2849 2849
  *    - la dernière valeur du tableau sinon.
2850 2850
  **/
2851 2851
 function filtre_end($array) {
2852
-	return !is_array($array) ? null : end($array);
2852
+    return !is_array($array) ? null : end($array);
2853 2853
 }
2854 2854
 
2855 2855
 /**
@@ -2869,11 +2869,11 @@  discard block
 block discarded – undo
2869 2869
  *
2870 2870
  **/
2871 2871
 function filtre_push($array, $val) {
2872
-	if (!is_array($array) or !array_push($array, $val)) {
2873
-		return '';
2874
-	}
2872
+    if (!is_array($array) or !array_push($array, $val)) {
2873
+        return '';
2874
+    }
2875 2875
 
2876
-	return $array;
2876
+    return $array;
2877 2877
 }
2878 2878
 
2879 2879
 /**
@@ -2892,7 +2892,7 @@  discard block
 block discarded – undo
2892 2892
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2893 2893
  **/
2894 2894
 function filtre_find($array, $val) {
2895
-	return (is_array($array) and in_array($val, $array));
2895
+    return (is_array($array) and in_array($val, $array));
2896 2896
 }
2897 2897
 
2898 2898
 
@@ -2909,13 +2909,13 @@  discard block
 block discarded – undo
2909 2909
  *     Contenu avec urls en absolus
2910 2910
  **/
2911 2911
 function urls_absolues_css($contenu, $source) {
2912
-	$path = suivre_lien(url_absolue($source), './');
2912
+    $path = suivre_lien(url_absolue($source), './');
2913 2913
 
2914
-	return preg_replace_callback(
2915
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2916
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2917
-		$contenu
2918
-	);
2914
+    return preg_replace_callback(
2915
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2916
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2917
+        $contenu
2918
+    );
2919 2919
 }
2920 2920
 
2921 2921
 
@@ -2944,119 +2944,119 @@  discard block
 block discarded – undo
2944 2944
  *     Chemin du fichier CSS inversé
2945 2945
  **/
2946 2946
 function direction_css($css, $voulue = '') {
2947
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2948
-		return $css;
2949
-	}
2950
-	include_spip('inc/lang');
2951
-	// si on a precise le sens voulu en argument, le prendre en compte
2952
-	if ($voulue = strtolower($voulue)) {
2953
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2954
-			$voulue = lang_dir($voulue);
2955
-		}
2956
-	} else {
2957
-		$voulue = lang_dir();
2958
-	}
2959
-
2960
-	$r = count($r) > 1;
2961
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2962
-	$dir = $r ? 'rtl' : 'ltr';
2963
-	$ndir = $r ? 'ltr' : 'rtl';
2964
-
2965
-	if ($voulue == $dir) {
2966
-		return $css;
2967
-	}
2968
-
2969
-	if (
2970
-		// url absolue
2971
-		preg_match(',^https?:,i', $css)
2972
-		// ou qui contient un ?
2973
-		or (($p = strpos($css, '?')) !== false)
2974
-	) {
2975
-		$distant = true;
2976
-		$cssf = parse_url($css);
2977
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2978
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2979
-	} else {
2980
-		$distant = false;
2981
-		$cssf = $css;
2982
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2983
-		//propose (rien a faire dans ce cas)
2984
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2985
-		if (@file_exists($f)) {
2986
-			return $f;
2987
-		}
2988
-	}
2989
-
2990
-	// 2.
2991
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2992
-	$f = $dir_var
2993
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2994
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2995
-
2996
-	// la css peut etre distante (url absolue !)
2997
-	if ($distant) {
2998
-		include_spip('inc/distant');
2999
-		$res = recuperer_url($css);
3000
-		if (!$res or !$contenu = $res['page']) {
3001
-			return $css;
3002
-		}
3003
-	} else {
3004
-		if (
3005
-			(@filemtime($f) > @filemtime($css))
3006
-			and (_VAR_MODE != 'recalcul')
3007
-		) {
3008
-			return $f;
3009
-		}
3010
-		if (!lire_fichier($css, $contenu)) {
3011
-			return $css;
3012
-		}
3013
-	}
3014
-
3015
-
3016
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3017
-	include_spip('lib/csstidy/class.csstidy');
3018
-	$parser = new csstidy();
3019
-	$parser->set_cfg('optimise_shorthands', 0);
3020
-	$parser->set_cfg('reverse_left_and_right', true);
3021
-	$parser->parse($contenu);
3022
-
3023
-	$contenu = $parser->print->plain();
3024
-
3025
-
3026
-	// reperer les @import auxquels il faut propager le direction_css
3027
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3028
-	$src = [];
3029
-	$src_direction_css = [];
3030
-	$src_faux_abs = [];
3031
-	$d = dirname($css);
3032
-	foreach ($regs[1] as $k => $import_css) {
3033
-		$css_direction = direction_css("$d/$import_css", $voulue);
3034
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3035
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3036
-			$css_direction = substr($css_direction, strlen($d) + 1);
3037
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
3038
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3039
-			$css_direction = substr($css_direction, strlen($dir_var));
3040
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3041
-			$css_direction = '/@@@@@@/' . $css_direction;
3042
-		}
3043
-		$src[] = $regs[0][$k];
3044
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3045
-	}
3046
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3047
-
3048
-	$contenu = urls_absolues_css($contenu, $css);
3049
-
3050
-	// virer les fausses url absolues que l'on a mis dans les import
3051
-	if (count($src_faux_abs)) {
3052
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3053
-	}
3054
-
3055
-	if (!ecrire_fichier($f, $contenu)) {
3056
-		return $css;
3057
-	}
3058
-
3059
-	return $f;
2947
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2948
+        return $css;
2949
+    }
2950
+    include_spip('inc/lang');
2951
+    // si on a precise le sens voulu en argument, le prendre en compte
2952
+    if ($voulue = strtolower($voulue)) {
2953
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2954
+            $voulue = lang_dir($voulue);
2955
+        }
2956
+    } else {
2957
+        $voulue = lang_dir();
2958
+    }
2959
+
2960
+    $r = count($r) > 1;
2961
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2962
+    $dir = $r ? 'rtl' : 'ltr';
2963
+    $ndir = $r ? 'ltr' : 'rtl';
2964
+
2965
+    if ($voulue == $dir) {
2966
+        return $css;
2967
+    }
2968
+
2969
+    if (
2970
+        // url absolue
2971
+        preg_match(',^https?:,i', $css)
2972
+        // ou qui contient un ?
2973
+        or (($p = strpos($css, '?')) !== false)
2974
+    ) {
2975
+        $distant = true;
2976
+        $cssf = parse_url($css);
2977
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2978
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2979
+    } else {
2980
+        $distant = false;
2981
+        $cssf = $css;
2982
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2983
+        //propose (rien a faire dans ce cas)
2984
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2985
+        if (@file_exists($f)) {
2986
+            return $f;
2987
+        }
2988
+    }
2989
+
2990
+    // 2.
2991
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2992
+    $f = $dir_var
2993
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2994
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2995
+
2996
+    // la css peut etre distante (url absolue !)
2997
+    if ($distant) {
2998
+        include_spip('inc/distant');
2999
+        $res = recuperer_url($css);
3000
+        if (!$res or !$contenu = $res['page']) {
3001
+            return $css;
3002
+        }
3003
+    } else {
3004
+        if (
3005
+            (@filemtime($f) > @filemtime($css))
3006
+            and (_VAR_MODE != 'recalcul')
3007
+        ) {
3008
+            return $f;
3009
+        }
3010
+        if (!lire_fichier($css, $contenu)) {
3011
+            return $css;
3012
+        }
3013
+    }
3014
+
3015
+
3016
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
3017
+    include_spip('lib/csstidy/class.csstidy');
3018
+    $parser = new csstidy();
3019
+    $parser->set_cfg('optimise_shorthands', 0);
3020
+    $parser->set_cfg('reverse_left_and_right', true);
3021
+    $parser->parse($contenu);
3022
+
3023
+    $contenu = $parser->print->plain();
3024
+
3025
+
3026
+    // reperer les @import auxquels il faut propager le direction_css
3027
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
3028
+    $src = [];
3029
+    $src_direction_css = [];
3030
+    $src_faux_abs = [];
3031
+    $d = dirname($css);
3032
+    foreach ($regs[1] as $k => $import_css) {
3033
+        $css_direction = direction_css("$d/$import_css", $voulue);
3034
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
3035
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
3036
+            $css_direction = substr($css_direction, strlen($d) + 1);
3037
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
3038
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
3039
+            $css_direction = substr($css_direction, strlen($dir_var));
3040
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
3041
+            $css_direction = '/@@@@@@/' . $css_direction;
3042
+        }
3043
+        $src[] = $regs[0][$k];
3044
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3045
+    }
3046
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3047
+
3048
+    $contenu = urls_absolues_css($contenu, $css);
3049
+
3050
+    // virer les fausses url absolues que l'on a mis dans les import
3051
+    if (count($src_faux_abs)) {
3052
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3053
+    }
3054
+
3055
+    if (!ecrire_fichier($f, $contenu)) {
3056
+        return $css;
3057
+    }
3058
+
3059
+    return $f;
3060 3060
 }
3061 3061
 
3062 3062
 
@@ -3079,46 +3079,46 @@  discard block
 block discarded – undo
3079 3079
  *     - Chemin ou URL du fichier CSS source sinon.
3080 3080
  **/
3081 3081
 function url_absolue_css($css) {
3082
-	if (!preg_match(',\.css$,i', $css, $r)) {
3083
-		return $css;
3084
-	}
3082
+    if (!preg_match(',\.css$,i', $css, $r)) {
3083
+        return $css;
3084
+    }
3085 3085
 
3086
-	$url_absolue_css = url_absolue($css);
3086
+    $url_absolue_css = url_absolue($css);
3087 3087
 
3088
-	$f = basename($css, '.css');
3089
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3090
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3091
-		. '.css';
3088
+    $f = basename($css, '.css');
3089
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3090
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3091
+        . '.css';
3092 3092
 
3093
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3094
-		return $f;
3095
-	}
3093
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3094
+        return $f;
3095
+    }
3096 3096
 
3097
-	if ($url_absolue_css == $css) {
3098
-		if (
3099
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3100
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3101
-		) {
3102
-			include_spip('inc/distant');
3103
-			$contenu = recuperer_url($css);
3104
-			$contenu = $contenu['page'] ?? '';
3105
-			if (!$contenu) {
3106
-				return $css;
3107
-			}
3108
-		}
3109
-	} elseif (!lire_fichier($css, $contenu)) {
3110
-		return $css;
3111
-	}
3097
+    if ($url_absolue_css == $css) {
3098
+        if (
3099
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3100
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3101
+        ) {
3102
+            include_spip('inc/distant');
3103
+            $contenu = recuperer_url($css);
3104
+            $contenu = $contenu['page'] ?? '';
3105
+            if (!$contenu) {
3106
+                return $css;
3107
+            }
3108
+        }
3109
+    } elseif (!lire_fichier($css, $contenu)) {
3110
+        return $css;
3111
+    }
3112 3112
 
3113
-	// passer les url relatives a la css d'origine en url absolues
3114
-	$contenu = urls_absolues_css($contenu, $css);
3113
+    // passer les url relatives a la css d'origine en url absolues
3114
+    $contenu = urls_absolues_css($contenu, $css);
3115 3115
 
3116
-	// ecrire la css
3117
-	if (!ecrire_fichier($f, $contenu)) {
3118
-		return $css;
3119
-	}
3116
+    // ecrire la css
3117
+    if (!ecrire_fichier($f, $contenu)) {
3118
+        return $css;
3119
+    }
3120 3120
 
3121
-	return $f;
3121
+    return $f;
3122 3122
 }
3123 3123
 
3124 3124
 
@@ -3152,24 +3152,24 @@  discard block
 block discarded – undo
3152 3152
  *     Valeur trouvée ou valeur par défaut.
3153 3153
  **/
3154 3154
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3155
-	foreach (explode('/', $cle) as $k) {
3156
-		$table = (is_string($table) ? @unserialize($table) : $table);
3155
+    foreach (explode('/', $cle) as $k) {
3156
+        $table = (is_string($table) ? @unserialize($table) : $table);
3157 3157
 
3158
-		if (is_object($table)) {
3159
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3160
-		} elseif (is_array($table)) {
3161
-			if ($conserver_null) {
3162
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3163
-			} else {
3164
-				$table = ($table[$k] ?? $defaut);
3165
-			}
3166
-		} else {
3167
-			$table = $defaut;
3168
-			break;
3169
-		}
3170
-	}
3158
+        if (is_object($table)) {
3159
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3160
+        } elseif (is_array($table)) {
3161
+            if ($conserver_null) {
3162
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3163
+            } else {
3164
+                $table = ($table[$k] ?? $defaut);
3165
+            }
3166
+        } else {
3167
+            $table = $defaut;
3168
+            break;
3169
+        }
3170
+    }
3171 3171
 
3172
-	return $table;
3172
+    return $table;
3173 3173
 }
3174 3174
 
3175 3175
 /**
@@ -3202,22 +3202,22 @@  discard block
 block discarded – undo
3202 3202
  *     - string : expression trouvée.
3203 3203
  **/
3204 3204
 function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) {
3205
-	if (intval($modif) and $capte == 0) {
3206
-		$capte = $modif;
3207
-		$modif = 'UimsS';
3208
-	}
3209
-	$expression = str_replace('\/', '/', $expression);
3210
-	$expression = str_replace('/', '\/', $expression);
3205
+    if (intval($modif) and $capte == 0) {
3206
+        $capte = $modif;
3207
+        $modif = 'UimsS';
3208
+    }
3209
+    $expression = str_replace('\/', '/', $expression);
3210
+    $expression = str_replace('/', '\/', $expression);
3211 3211
 
3212
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3213
-		if (isset($r[$capte])) {
3214
-			return $r[$capte];
3215
-		} else {
3216
-			return true;
3217
-		}
3218
-	}
3212
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3213
+        if (isset($r[$capte])) {
3214
+            return $r[$capte];
3215
+        } else {
3216
+            return true;
3217
+        }
3218
+    }
3219 3219
 
3220
-	return false;
3220
+    return false;
3221 3221
 }
3222 3222
 
3223 3223
 
@@ -3244,10 +3244,10 @@  discard block
 block discarded – undo
3244 3244
  *     Texte
3245 3245
  **/
3246 3246
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3247
-	$expression = str_replace('\/', '/', $expression);
3248
-	$expression = str_replace('/', '\/', $expression);
3247
+    $expression = str_replace('\/', '/', $expression);
3248
+    $expression = str_replace('/', '\/', $expression);
3249 3249
 
3250
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3250
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3251 3251
 }
3252 3252
 
3253 3253
 
@@ -3265,25 +3265,25 @@  discard block
 block discarded – undo
3265 3265
  **/
3266 3266
 function traiter_doublons_documents(&$doublons, $letexte) {
3267 3267
 
3268
-	// Verifier dans le texte & les notes (pas beau, helas)
3269
-	$t = $letexte . $GLOBALS['les_notes'];
3268
+    // Verifier dans le texte & les notes (pas beau, helas)
3269
+    $t = $letexte . $GLOBALS['les_notes'];
3270 3270
 
3271
-	if (
3272
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3273
-		and preg_match_all(
3274
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3275
-			$t,
3276
-			$matches,
3277
-			PREG_PATTERN_ORDER
3278
-		)
3279
-	) {
3280
-		if (!isset($doublons['documents'])) {
3281
-			$doublons['documents'] = '';
3282
-		}
3283
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3284
-	}
3271
+    if (
3272
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3273
+        and preg_match_all(
3274
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3275
+            $t,
3276
+            $matches,
3277
+            PREG_PATTERN_ORDER
3278
+        )
3279
+    ) {
3280
+        if (!isset($doublons['documents'])) {
3281
+            $doublons['documents'] = '';
3282
+        }
3283
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3284
+    }
3285 3285
 
3286
-	return $letexte;
3286
+    return $letexte;
3287 3287
 }
3288 3288
 
3289 3289
 /**
@@ -3297,7 +3297,7 @@  discard block
 block discarded – undo
3297 3297
  * @return string Chaîne vide
3298 3298
  **/
3299 3299
 function vide($texte) {
3300
-	return '';
3300
+    return '';
3301 3301
 }
3302 3302
 
3303 3303
 //
@@ -3326,23 +3326,23 @@  discard block
 block discarded – undo
3326 3326
  *      Code HTML résultant
3327 3327
  **/
3328 3328
 function env_to_params($env, $ignore_params = []) {
3329
-	$ignore_params = array_merge(
3330
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3331
-		$ignore_params
3332
-	);
3333
-	if (!is_array($env)) {
3334
-		$env = unserialize($env);
3335
-	}
3336
-	$texte = '';
3337
-	if ($env) {
3338
-		foreach ($env as $i => $j) {
3339
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3340
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3341
-			}
3342
-		}
3343
-	}
3344
-
3345
-	return $texte;
3329
+    $ignore_params = array_merge(
3330
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3331
+        $ignore_params
3332
+    );
3333
+    if (!is_array($env)) {
3334
+        $env = unserialize($env);
3335
+    }
3336
+    $texte = '';
3337
+    if ($env) {
3338
+        foreach ($env as $i => $j) {
3339
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3340
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3341
+            }
3342
+        }
3343
+    }
3344
+
3345
+    return $texte;
3346 3346
 }
3347 3347
 
3348 3348
 /**
@@ -3365,23 +3365,23 @@  discard block
 block discarded – undo
3365 3365
  *      Code HTML résultant
3366 3366
  **/
3367 3367
 function env_to_attributs($env, $ignore_params = []) {
3368
-	$ignore_params = array_merge(
3369
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3370
-		$ignore_params
3371
-	);
3372
-	if (!is_array($env)) {
3373
-		$env = unserialize($env);
3374
-	}
3375
-	$texte = '';
3376
-	if ($env) {
3377
-		foreach ($env as $i => $j) {
3378
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3379
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3380
-			}
3381
-		}
3382
-	}
3368
+    $ignore_params = array_merge(
3369
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3370
+        $ignore_params
3371
+    );
3372
+    if (!is_array($env)) {
3373
+        $env = unserialize($env);
3374
+    }
3375
+    $texte = '';
3376
+    if ($env) {
3377
+        foreach ($env as $i => $j) {
3378
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3379
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3380
+            }
3381
+        }
3382
+    }
3383 3383
 
3384
-	return $texte;
3384
+    return $texte;
3385 3385
 }
3386 3386
 
3387 3387
 
@@ -3399,7 +3399,7 @@  discard block
 block discarded – undo
3399 3399
  * @return string Chaînes concaténés
3400 3400
  **/
3401 3401
 function concat(...$args): string {
3402
-	return join('', $args);
3402
+    return join('', $args);
3403 3403
 }
3404 3404
 
3405 3405
 
@@ -3419,23 +3419,23 @@  discard block
 block discarded – undo
3419 3419
  *     Contenu du ou des fichiers, concaténé
3420 3420
  **/
3421 3421
 function charge_scripts($files, $script = true) {
3422
-	$flux = '';
3423
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3424
-		if (!is_string($file)) {
3425
-			continue;
3426
-		}
3427
-		if ($script) {
3428
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3429
-		}
3430
-		if ($file) {
3431
-			$path = find_in_path($file);
3432
-			if ($path) {
3433
-				$flux .= spip_file_get_contents($path);
3434
-			}
3435
-		}
3436
-	}
3437
-
3438
-	return $flux;
3422
+    $flux = '';
3423
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3424
+        if (!is_string($file)) {
3425
+            continue;
3426
+        }
3427
+        if ($script) {
3428
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3429
+        }
3430
+        if ($file) {
3431
+            $path = find_in_path($file);
3432
+            if ($path) {
3433
+                $flux .= spip_file_get_contents($path);
3434
+            }
3435
+        }
3436
+    }
3437
+
3438
+    return $flux;
3439 3439
 }
3440 3440
 
3441 3441
 /**
@@ -3446,22 +3446,22 @@  discard block
 block discarded – undo
3446 3446
  * @return string
3447 3447
  */
3448 3448
 function http_img_variante_svg_si_possible($img_file) {
3449
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3450
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3451
-	if (
3452
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3453
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3454
-		and file_exists($variante_svg_generique)
3455
-	) {
3456
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3457
-			$img_file = $variante_svg_size;
3458
-		}
3459
-		else {
3460
-			$img_file = $variante_svg_generique;
3461
-		}
3462
-	}
3449
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3450
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3451
+    if (
3452
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3453
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3454
+        and file_exists($variante_svg_generique)
3455
+    ) {
3456
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3457
+            $img_file = $variante_svg_size;
3458
+        }
3459
+        else {
3460
+            $img_file = $variante_svg_generique;
3461
+        }
3462
+    }
3463 3463
 
3464
-	return $img_file;
3464
+    return $img_file;
3465 3465
 }
3466 3466
 
3467 3467
 /**
@@ -3482,54 +3482,54 @@  discard block
 block discarded – undo
3482 3482
  */
3483 3483
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3484 3484
 
3485
-	$img_file = $img;
3486
-	if ($p = strpos($img_file, '?')) {
3487
-		$img_file = substr($img_file, 0, $p);
3488
-	}
3489
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3490
-		$img_file = chemin_image($img);
3491
-	}
3492
-	else {
3493
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3494
-			$img_file = http_img_variante_svg_si_possible($img_file);
3495
-		}
3496
-	}
3497
-	if (stripos($atts, 'width') === false) {
3498
-		// utiliser directement l'info de taille presente dans le nom
3499
-		if (
3500
-			(!isset($options['utiliser_suffixe_size'])
3501
-				or $options['utiliser_suffixe_size'] == true
3502
-			  or strpos($img_file, '-xx.svg') !== false)
3503
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3504
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3505
-		) {
3506
-			$largeur = $hauteur = intval($regs[1]);
3507
-		} else {
3508
-			$taille = taille_image($img_file);
3509
-			[$hauteur, $largeur] = $taille;
3510
-			if (!$hauteur or !$largeur) {
3511
-				return '';
3512
-			}
3513
-		}
3514
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3515
-	}
3516
-
3517
-	if (file_exists($img_file)) {
3518
-		$img_file = timestamp($img_file);
3519
-	}
3520
-	if ($alt === false) {
3521
-		$alt = '';
3522
-	}
3523
-	elseif ($alt or $alt === '') {
3524
-		$alt = " alt='" . attribut_html($alt) . "'";
3525
-	}
3526
-	else {
3527
-		$alt = " alt='" . attribut_html($title) . "'";
3528
-	}
3529
-	return "<img src='$img_file'$alt"
3530
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3531
-	. ' ' . ltrim($atts)
3532
-	. ' />';
3485
+    $img_file = $img;
3486
+    if ($p = strpos($img_file, '?')) {
3487
+        $img_file = substr($img_file, 0, $p);
3488
+    }
3489
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3490
+        $img_file = chemin_image($img);
3491
+    }
3492
+    else {
3493
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3494
+            $img_file = http_img_variante_svg_si_possible($img_file);
3495
+        }
3496
+    }
3497
+    if (stripos($atts, 'width') === false) {
3498
+        // utiliser directement l'info de taille presente dans le nom
3499
+        if (
3500
+            (!isset($options['utiliser_suffixe_size'])
3501
+                or $options['utiliser_suffixe_size'] == true
3502
+              or strpos($img_file, '-xx.svg') !== false)
3503
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3504
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3505
+        ) {
3506
+            $largeur = $hauteur = intval($regs[1]);
3507
+        } else {
3508
+            $taille = taille_image($img_file);
3509
+            [$hauteur, $largeur] = $taille;
3510
+            if (!$hauteur or !$largeur) {
3511
+                return '';
3512
+            }
3513
+        }
3514
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3515
+    }
3516
+
3517
+    if (file_exists($img_file)) {
3518
+        $img_file = timestamp($img_file);
3519
+    }
3520
+    if ($alt === false) {
3521
+        $alt = '';
3522
+    }
3523
+    elseif ($alt or $alt === '') {
3524
+        $alt = " alt='" . attribut_html($alt) . "'";
3525
+    }
3526
+    else {
3527
+        $alt = " alt='" . attribut_html($title) . "'";
3528
+    }
3529
+    return "<img src='$img_file'$alt"
3530
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3531
+    . ' ' . ltrim($atts)
3532
+    . ' />';
3533 3533
 }
3534 3534
 
3535 3535
 /**
@@ -3541,70 +3541,70 @@  discard block
 block discarded – undo
3541 3541
  * @return string
3542 3542
  */
3543 3543
 function http_style_background($img, $att = '', $size = null) {
3544
-	if ($size and is_numeric($size)) {
3545
-		$size = trim($size) . 'px';
3546
-	}
3547
-	return " style='background" .
3548
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3549
-		. ($size ? "background-size:{$size};" : '')
3550
-		. "'";
3544
+    if ($size and is_numeric($size)) {
3545
+        $size = trim($size) . 'px';
3546
+    }
3547
+    return " style='background" .
3548
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3549
+        . ($size ? "background-size:{$size};" : '')
3550
+        . "'";
3551 3551
 }
3552 3552
 
3553 3553
 
3554 3554
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3555
-	$args = [$alt_or_size, $class_or_size, $size];
3556
-	while (is_null(end($args)) and count($args)) {
3557
-		array_pop($args);
3558
-	}
3559
-	if (!count($args)) {
3560
-		return [null, null, null];
3561
-	}
3562
-	if (count($args) < 3) {
3563
-		$maybe_size = array_pop($args);
3564
-		// @2x
3565
-		// @1.5x
3566
-		// 512
3567
-		// 512x*
3568
-		// 512x300
3569
-		if (
3570
-			!strlen($maybe_size)
3571
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3572
-		) {
3573
-			$args[] = $maybe_size;
3574
-			$maybe_size = null;
3575
-		}
3576
-		while (count($args) < 2) {
3577
-			$args[] = null; // default alt or class
3578
-		}
3579
-		$args[] = $maybe_size;
3580
-	}
3581
-	return $args;
3555
+    $args = [$alt_or_size, $class_or_size, $size];
3556
+    while (is_null(end($args)) and count($args)) {
3557
+        array_pop($args);
3558
+    }
3559
+    if (!count($args)) {
3560
+        return [null, null, null];
3561
+    }
3562
+    if (count($args) < 3) {
3563
+        $maybe_size = array_pop($args);
3564
+        // @2x
3565
+        // @1.5x
3566
+        // 512
3567
+        // 512x*
3568
+        // 512x300
3569
+        if (
3570
+            !strlen($maybe_size)
3571
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3572
+        ) {
3573
+            $args[] = $maybe_size;
3574
+            $maybe_size = null;
3575
+        }
3576
+        while (count($args) < 2) {
3577
+            $args[] = null; // default alt or class
3578
+        }
3579
+        $args[] = $maybe_size;
3580
+    }
3581
+    return $args;
3582 3582
 }
3583 3583
 
3584 3584
 function helper_filtre_balise_img_svg_size($img, $size) {
3585
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3586
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3587
-		$coef = floatval(substr($size, 1, -1));
3588
-		[$h, $w] = taille_image($img);
3589
-		$height = intval(round($h / $coef));
3590
-		$width = intval(round($w / $coef));
3591
-	}
3592
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3593
-	else {
3594
-		$size = explode('x', $size, 2);
3595
-		$size = array_map('trim', $size);
3596
-		$height = $width = intval(array_shift($size));
3597
-
3598
-		if (count($size) and reset($size)) {
3599
-			$height = array_shift($size);
3600
-			if ($height === '*') {
3601
-				[$h, $w] = taille_image($img);
3602
-				$height = intval(round($h * $width / $w));
3603
-			}
3604
-		}
3605
-	}
3606
-
3607
-	return [$width, $height];
3585
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3586
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3587
+        $coef = floatval(substr($size, 1, -1));
3588
+        [$h, $w] = taille_image($img);
3589
+        $height = intval(round($h / $coef));
3590
+        $width = intval(round($w / $coef));
3591
+    }
3592
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3593
+    else {
3594
+        $size = explode('x', $size, 2);
3595
+        $size = array_map('trim', $size);
3596
+        $height = $width = intval(array_shift($size));
3597
+
3598
+        if (count($size) and reset($size)) {
3599
+            $height = array_shift($size);
3600
+            if ($height === '*') {
3601
+                [$h, $w] = taille_image($img);
3602
+                $height = intval(round($h * $width / $w));
3603
+            }
3604
+        }
3605
+    }
3606
+
3607
+    return [$width, $height];
3608 3608
 }
3609 3609
 
3610 3610
 /**
@@ -3640,43 +3640,43 @@  discard block
 block discarded – undo
3640 3640
  */
3641 3641
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3642 3642
 
3643
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3644
-
3645
-	$img = trim($img);
3646
-	if (strpos($img, '<img') === 0) {
3647
-		if (!is_null($alt)) {
3648
-			$img = inserer_attribut($img, 'alt', $alt);
3649
-		}
3650
-		if (!is_null($class)) {
3651
-			if (strlen($class)) {
3652
-				$img = inserer_attribut($img, 'class', $class);
3653
-			}
3654
-			else {
3655
-				$img = vider_attribut($img, 'class');
3656
-			}
3657
-		}
3658
-	}
3659
-	else {
3660
-		$img = http_img_pack(
3661
-			$img,
3662
-			$alt,
3663
-			$class ? " class='" . attribut_html($class) . "'" : '',
3664
-			'',
3665
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3666
-		);
3667
-		if (is_null($alt)) {
3668
-			$img = vider_attribut($img, 'alt');
3669
-		}
3670
-	}
3671
-
3672
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3673
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3674
-
3675
-		$img = inserer_attribut($img, 'width', $width);
3676
-		$img = inserer_attribut($img, 'height', $height);
3677
-	}
3678
-
3679
-	return $img;
3643
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3644
+
3645
+    $img = trim($img);
3646
+    if (strpos($img, '<img') === 0) {
3647
+        if (!is_null($alt)) {
3648
+            $img = inserer_attribut($img, 'alt', $alt);
3649
+        }
3650
+        if (!is_null($class)) {
3651
+            if (strlen($class)) {
3652
+                $img = inserer_attribut($img, 'class', $class);
3653
+            }
3654
+            else {
3655
+                $img = vider_attribut($img, 'class');
3656
+            }
3657
+        }
3658
+    }
3659
+    else {
3660
+        $img = http_img_pack(
3661
+            $img,
3662
+            $alt,
3663
+            $class ? " class='" . attribut_html($class) . "'" : '',
3664
+            '',
3665
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3666
+        );
3667
+        if (is_null($alt)) {
3668
+            $img = vider_attribut($img, 'alt');
3669
+        }
3670
+    }
3671
+
3672
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3673
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3674
+
3675
+        $img = inserer_attribut($img, 'width', $width);
3676
+        $img = inserer_attribut($img, 'height', $height);
3677
+    }
3678
+
3679
+    return $img;
3680 3680
 }
3681 3681
 
3682 3682
 
@@ -3710,80 +3710,80 @@  discard block
 block discarded – undo
3710 3710
  */
3711 3711
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3712 3712
 
3713
-	$svg = null;
3714
-	$img = trim($img);
3715
-	$img_file = $img;
3716
-	if (strpos($img, '<svg') === false) {
3717
-		if ($p = strpos($img_file, '?')) {
3718
-			$img_file = substr($img_file, 0, $p);
3719
-		}
3720
-
3721
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3722
-		// la copie locale a toutes les chances d'etre la ou de resservir
3723
-		if (tester_url_absolue($img_file)) {
3724
-			include_spip('inc/distant');
3725
-			$fichier = copie_locale($img_file);
3726
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3727
-		}
3728
-
3729
-		if (
3730
-			!$img_file
3731
-			or !file_exists($img_file)
3732
-			or !$svg = file_get_contents($img_file)
3733
-		) {
3734
-			return '';
3735
-		}
3736
-	}
3737
-
3738
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3739
-		return '';
3740
-	}
3741
-
3742
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3743
-
3744
-	$balise_svg = $match[0];
3745
-	$balise_svg_source = $balise_svg;
3746
-
3747
-	// entete XML à supprimer
3748
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3749
-
3750
-	// IE est toujours mon ami
3751
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3752
-
3753
-	// regler la classe
3754
-	if (!is_null($class)) {
3755
-		if (strlen($class)) {
3756
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3757
-		}
3758
-		else {
3759
-			$balise_svg = vider_attribut($balise_svg, 'class');
3760
-		}
3761
-	}
3762
-
3763
-	// regler le alt
3764
-	if ($alt) {
3765
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3766
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3767
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3768
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3769
-		$balise_svg .= $title;
3770
-	}
3771
-	else {
3772
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3773
-	}
3774
-
3775
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3776
-
3777
-	if (!is_null($size) and strlen($size = trim($size))) {
3778
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3779
-
3780
-		if (!function_exists('svg_redimensionner')) {
3781
-			include_spip('inc/svg');
3782
-		}
3783
-		$svg = svg_redimensionner($svg, $width, $height);
3784
-	}
3785
-
3786
-	return $svg;
3713
+    $svg = null;
3714
+    $img = trim($img);
3715
+    $img_file = $img;
3716
+    if (strpos($img, '<svg') === false) {
3717
+        if ($p = strpos($img_file, '?')) {
3718
+            $img_file = substr($img_file, 0, $p);
3719
+        }
3720
+
3721
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3722
+        // la copie locale a toutes les chances d'etre la ou de resservir
3723
+        if (tester_url_absolue($img_file)) {
3724
+            include_spip('inc/distant');
3725
+            $fichier = copie_locale($img_file);
3726
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3727
+        }
3728
+
3729
+        if (
3730
+            !$img_file
3731
+            or !file_exists($img_file)
3732
+            or !$svg = file_get_contents($img_file)
3733
+        ) {
3734
+            return '';
3735
+        }
3736
+    }
3737
+
3738
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3739
+        return '';
3740
+    }
3741
+
3742
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3743
+
3744
+    $balise_svg = $match[0];
3745
+    $balise_svg_source = $balise_svg;
3746
+
3747
+    // entete XML à supprimer
3748
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3749
+
3750
+    // IE est toujours mon ami
3751
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3752
+
3753
+    // regler la classe
3754
+    if (!is_null($class)) {
3755
+        if (strlen($class)) {
3756
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3757
+        }
3758
+        else {
3759
+            $balise_svg = vider_attribut($balise_svg, 'class');
3760
+        }
3761
+    }
3762
+
3763
+    // regler le alt
3764
+    if ($alt) {
3765
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3766
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3767
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3768
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3769
+        $balise_svg .= $title;
3770
+    }
3771
+    else {
3772
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3773
+    }
3774
+
3775
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3776
+
3777
+    if (!is_null($size) and strlen($size = trim($size))) {
3778
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3779
+
3780
+        if (!function_exists('svg_redimensionner')) {
3781
+            include_spip('inc/svg');
3782
+        }
3783
+        $svg = svg_redimensionner($svg, $width, $height);
3784
+    }
3785
+
3786
+    return $svg;
3787 3787
 }
3788 3788
 
3789 3789
 
@@ -3809,18 +3809,18 @@  discard block
 block discarded – undo
3809 3809
  *     Code HTML résultant
3810 3810
  **/
3811 3811
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3812
-	$texte = '';
3813
-	if (is_array($tableau)) {
3814
-		foreach ($tableau as $k => $v) {
3815
-			$res = recuperer_fond(
3816
-				'modeles/' . $modele,
3817
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3818
-			);
3819
-			$texte .= $res;
3820
-		}
3821
-	}
3812
+    $texte = '';
3813
+    if (is_array($tableau)) {
3814
+        foreach ($tableau as $k => $v) {
3815
+            $res = recuperer_fond(
3816
+                'modeles/' . $modele,
3817
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3818
+            );
3819
+            $texte .= $res;
3820
+        }
3821
+    }
3822 3822
 
3823
-	return $texte;
3823
+    return $texte;
3824 3824
 }
3825 3825
 
3826 3826
 
@@ -3845,37 +3845,37 @@  discard block
 block discarded – undo
3845 3845
  *         - tout : retourne toutes les informations du plugin actif
3846 3846
  **/
3847 3847
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3848
-	include_spip('inc/plugin');
3849
-	$plugin = strtoupper($plugin);
3850
-	$plugins_actifs = liste_plugin_actifs();
3851
-
3852
-	if (!$plugin) {
3853
-		return serialize(array_keys($plugins_actifs));
3854
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3855
-		return '';
3856
-	} elseif (($type_info == 'est_actif') and !$reload) {
3857
-		return $plugins_actifs[$plugin] ? 1 : 0;
3858
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3859
-		return $plugins_actifs[$plugin][$type_info];
3860
-	} else {
3861
-		$get_infos = charger_fonction('get_infos', 'plugins');
3862
-		// On prend en compte les extensions
3863
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3864
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3865
-		} else {
3866
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3867
-		}
3868
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3869
-			return '';
3870
-		}
3871
-		if ($type_info == 'tout') {
3872
-			return $infos;
3873
-		} elseif ($type_info == 'est_actif') {
3874
-			return $infos ? 1 : 0;
3875
-		} else {
3876
-			return strval($infos[$type_info]);
3877
-		}
3878
-	}
3848
+    include_spip('inc/plugin');
3849
+    $plugin = strtoupper($plugin);
3850
+    $plugins_actifs = liste_plugin_actifs();
3851
+
3852
+    if (!$plugin) {
3853
+        return serialize(array_keys($plugins_actifs));
3854
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3855
+        return '';
3856
+    } elseif (($type_info == 'est_actif') and !$reload) {
3857
+        return $plugins_actifs[$plugin] ? 1 : 0;
3858
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3859
+        return $plugins_actifs[$plugin][$type_info];
3860
+    } else {
3861
+        $get_infos = charger_fonction('get_infos', 'plugins');
3862
+        // On prend en compte les extensions
3863
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3864
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3865
+        } else {
3866
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3867
+        }
3868
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3869
+            return '';
3870
+        }
3871
+        if ($type_info == 'tout') {
3872
+            return $infos;
3873
+        } elseif ($type_info == 'est_actif') {
3874
+            return $infos ? 1 : 0;
3875
+        } else {
3876
+            return strval($infos[$type_info]);
3877
+        }
3878
+    }
3879 3879
 }
3880 3880
 
3881 3881
 
@@ -3902,9 +3902,9 @@  discard block
 block discarded – undo
3902 3902
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3903 3903
  */
3904 3904
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3905
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3905
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3906 3906
 
3907
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3907
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3908 3908
 }
3909 3909
 
3910 3910
 
@@ -3934,19 +3934,19 @@  discard block
 block discarded – undo
3934 3934
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3935 3935
  */
3936 3936
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3937
-	static $puce_statut = null;
3938
-	if (!$puce_statut) {
3939
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3940
-	}
3937
+    static $puce_statut = null;
3938
+    if (!$puce_statut) {
3939
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3940
+    }
3941 3941
 
3942
-	return $puce_statut(
3943
-		$id_objet,
3944
-		$statut,
3945
-		$id_parent,
3946
-		$objet,
3947
-		false,
3948
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3949
-	);
3942
+    return $puce_statut(
3943
+        $id_objet,
3944
+        $statut,
3945
+        $id_parent,
3946
+        $objet,
3947
+        false,
3948
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3949
+    );
3950 3950
 }
3951 3951
 
3952 3952
 
@@ -3973,98 +3973,98 @@  discard block
 block discarded – undo
3973 3973
  *   hash du contexte
3974 3974
  */
3975 3975
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3976
-	$env = null;
3977
-	if (
3978
-		is_string($c)
3979
-		and @unserialize($c) !== false
3980
-	) {
3981
-		$c = unserialize($c);
3982
-	}
3983
-
3984
-	// supprimer les parametres debut_x
3985
-	// pour que la pagination ajax ne soit pas plantee
3986
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3987
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3988
-	if (is_array($c)) {
3989
-		foreach ($c as $k => $v) {
3990
-			if (strpos($k, 'debut_') === 0) {
3991
-				unset($c[$k]);
3992
-			}
3993
-		}
3994
-	}
3995
-
3996
-	if (!function_exists('calculer_cle_action')) {
3997
-		include_spip('inc/securiser_action');
3998
-	}
3999
-
4000
-	$c = serialize($c);
4001
-	$cle = calculer_cle_action($form . $c);
4002
-	$c = "$cle:$c";
4003
-
4004
-	// on ne stocke pas les contextes dans des fichiers en cache
4005
-	// par defaut, sauf si cette configuration a été forcée
4006
-	// OU que la longueur de l’argument géneré est plus long
4007
-	// que ce qui est toléré.
4008
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4009
-	if (!$cache_contextes_ajax) {
4010
-		$env = $c;
4011
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4012
-			$env = gzdeflate($env);
4013
-		}
4014
-		$env = _xor($env);
4015
-		$env = base64_encode($env);
4016
-		$len = strlen($env);
4017
-		// Si l’url est trop longue pour le navigateur
4018
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4019
-		if ($len > $max_len) {
4020
-			$cache_contextes_ajax = true;
4021
-			spip_log(
4022
-				'Contextes AJAX forces en fichiers !'
4023
-				. ' Cela arrive lorsque la valeur du contexte'
4024
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4025
-				_LOG_AVERTISSEMENT
4026
-			);
4027
-		}
4028
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4029
-		elseif (
4030
-			$max_len = @ini_get('suhosin.get.max_value_length')
4031
-			and $max_len < $len
4032
-		) {
4033
-			$cache_contextes_ajax = true;
4034
-			spip_log('Contextes AJAX forces en fichiers !'
4035
-				. ' Cela arrive lorsque la valeur du contexte'
4036
-				. ' depasse la longueur maximale autorisee par Suhosin'
4037
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4038
-				. ' Vous devriez modifier les parametres de Suhosin'
4039
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4040
-		}
4041
-	}
4042
-
4043
-	if ($cache_contextes_ajax) {
4044
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4045
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4046
-		$md5 = md5($c);
4047
-		ecrire_fichier("$dir/c$md5", $c);
4048
-		$env = $md5;
4049
-	}
4050
-
4051
-	if ($emboite === null) {
4052
-		return $env;
4053
-	}
4054
-	if (!trim($emboite)) {
4055
-		return '';
4056
-	}
4057
-	// toujours encoder l'url source dans le bloc ajax
4058
-	$r = self();
4059
-	$r = ' data-origin="' . $r . '"';
4060
-	$class = 'ajaxbloc';
4061
-	if ($ajaxid and is_string($ajaxid)) {
4062
-		// ajaxid est normalement conforme a un nom de classe css
4063
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4064
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4065
-	}
4066
-
4067
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3976
+    $env = null;
3977
+    if (
3978
+        is_string($c)
3979
+        and @unserialize($c) !== false
3980
+    ) {
3981
+        $c = unserialize($c);
3982
+    }
3983
+
3984
+    // supprimer les parametres debut_x
3985
+    // pour que la pagination ajax ne soit pas plantee
3986
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3987
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3988
+    if (is_array($c)) {
3989
+        foreach ($c as $k => $v) {
3990
+            if (strpos($k, 'debut_') === 0) {
3991
+                unset($c[$k]);
3992
+            }
3993
+        }
3994
+    }
3995
+
3996
+    if (!function_exists('calculer_cle_action')) {
3997
+        include_spip('inc/securiser_action');
3998
+    }
3999
+
4000
+    $c = serialize($c);
4001
+    $cle = calculer_cle_action($form . $c);
4002
+    $c = "$cle:$c";
4003
+
4004
+    // on ne stocke pas les contextes dans des fichiers en cache
4005
+    // par defaut, sauf si cette configuration a été forcée
4006
+    // OU que la longueur de l’argument géneré est plus long
4007
+    // que ce qui est toléré.
4008
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
4009
+    if (!$cache_contextes_ajax) {
4010
+        $env = $c;
4011
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4012
+            $env = gzdeflate($env);
4013
+        }
4014
+        $env = _xor($env);
4015
+        $env = base64_encode($env);
4016
+        $len = strlen($env);
4017
+        // Si l’url est trop longue pour le navigateur
4018
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
4019
+        if ($len > $max_len) {
4020
+            $cache_contextes_ajax = true;
4021
+            spip_log(
4022
+                'Contextes AJAX forces en fichiers !'
4023
+                . ' Cela arrive lorsque la valeur du contexte'
4024
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
4025
+                _LOG_AVERTISSEMENT
4026
+            );
4027
+        }
4028
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
4029
+        elseif (
4030
+            $max_len = @ini_get('suhosin.get.max_value_length')
4031
+            and $max_len < $len
4032
+        ) {
4033
+            $cache_contextes_ajax = true;
4034
+            spip_log('Contextes AJAX forces en fichiers !'
4035
+                . ' Cela arrive lorsque la valeur du contexte'
4036
+                . ' depasse la longueur maximale autorisee par Suhosin'
4037
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
4038
+                . ' Vous devriez modifier les parametres de Suhosin'
4039
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
4040
+        }
4041
+    }
4042
+
4043
+    if ($cache_contextes_ajax) {
4044
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4045
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4046
+        $md5 = md5($c);
4047
+        ecrire_fichier("$dir/c$md5", $c);
4048
+        $env = $md5;
4049
+    }
4050
+
4051
+    if ($emboite === null) {
4052
+        return $env;
4053
+    }
4054
+    if (!trim($emboite)) {
4055
+        return '';
4056
+    }
4057
+    // toujours encoder l'url source dans le bloc ajax
4058
+    $r = self();
4059
+    $r = ' data-origin="' . $r . '"';
4060
+    $class = 'ajaxbloc';
4061
+    if ($ajaxid and is_string($ajaxid)) {
4062
+        // ajaxid est normalement conforme a un nom de classe css
4063
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4064
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4065
+    }
4066
+
4067
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4068 4068
 }
4069 4069
 
4070 4070
 /**
@@ -4084,37 +4084,37 @@  discard block
 block discarded – undo
4084 4084
  *   - false : erreur de décodage
4085 4085
  */
4086 4086
 function decoder_contexte_ajax($c, $form = '') {
4087
-	if (!function_exists('calculer_cle_action')) {
4088
-		include_spip('inc/securiser_action');
4089
-	}
4090
-	if (
4091
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4092
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4093
-		and lire_fichier("$dir/c$c", $contexte)
4094
-	) {
4095
-		$c = $contexte;
4096
-	} else {
4097
-		$c = @base64_decode($c);
4098
-		$c = _xor($c);
4099
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4100
-			$c = @gzinflate($c);
4101
-		}
4102
-	}
4103
-
4104
-	// extraire la signature en debut de contexte
4105
-	// et la verifier avant de deserializer
4106
-	// format : signature:donneesserializees
4107
-	if ($p = strpos($c, ':')) {
4108
-		$cle = substr($c, 0, $p);
4109
-		$c = substr($c, $p + 1);
4110
-
4111
-		if ($cle == calculer_cle_action($form . $c)) {
4112
-			$env = @unserialize($c);
4113
-			return $env;
4114
-		}
4115
-	}
4116
-
4117
-	return false;
4087
+    if (!function_exists('calculer_cle_action')) {
4088
+        include_spip('inc/securiser_action');
4089
+    }
4090
+    if (
4091
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4092
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4093
+        and lire_fichier("$dir/c$c", $contexte)
4094
+    ) {
4095
+        $c = $contexte;
4096
+    } else {
4097
+        $c = @base64_decode($c);
4098
+        $c = _xor($c);
4099
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4100
+            $c = @gzinflate($c);
4101
+        }
4102
+    }
4103
+
4104
+    // extraire la signature en debut de contexte
4105
+    // et la verifier avant de deserializer
4106
+    // format : signature:donneesserializees
4107
+    if ($p = strpos($c, ':')) {
4108
+        $cle = substr($c, 0, $p);
4109
+        $c = substr($c, $p + 1);
4110
+
4111
+        if ($cle == calculer_cle_action($form . $c)) {
4112
+            $env = @unserialize($c);
4113
+            return $env;
4114
+        }
4115
+    }
4116
+
4117
+    return false;
4118 4118
 }
4119 4119
 
4120 4120
 
@@ -4132,20 +4132,20 @@  discard block
 block discarded – undo
4132 4132
  *    Message décrypté ou encrypté
4133 4133
  **/
4134 4134
 function _xor($message, $key = null) {
4135
-	if (is_null($key)) {
4136
-		if (!function_exists('calculer_cle_action')) {
4137
-			include_spip('inc/securiser_action');
4138
-		}
4139
-		$key = pack('H*', calculer_cle_action('_xor'));
4140
-	}
4135
+    if (is_null($key)) {
4136
+        if (!function_exists('calculer_cle_action')) {
4137
+            include_spip('inc/securiser_action');
4138
+        }
4139
+        $key = pack('H*', calculer_cle_action('_xor'));
4140
+    }
4141 4141
 
4142
-	$keylen = strlen($key);
4143
-	$messagelen = strlen($message);
4144
-	for ($i = 0; $i < $messagelen; $i++) {
4145
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4146
-	}
4142
+    $keylen = strlen($key);
4143
+    $messagelen = strlen($message);
4144
+    for ($i = 0; $i < $messagelen; $i++) {
4145
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4146
+    }
4147 4147
 
4148
-	return $message;
4148
+    return $message;
4149 4149
 }
4150 4150
 
4151 4151
 /**
@@ -4159,7 +4159,7 @@  discard block
 block discarded – undo
4159 4159
  * @return string
4160 4160
  */
4161 4161
 function url_reponse_forum($texte) {
4162
- return $texte;
4162
+    return $texte;
4163 4163
 }
4164 4164
 
4165 4165
 /**
@@ -4173,7 +4173,7 @@  discard block
 block discarded – undo
4173 4173
  * @return string
4174 4174
  */
4175 4175
 function url_rss_forum($texte) {
4176
- return $texte;
4176
+    return $texte;
4177 4177
 }
4178 4178
 
4179 4179
 
@@ -4212,37 +4212,37 @@  discard block
 block discarded – undo
4212 4212
  *   Code HTML
4213 4213
  */
4214 4214
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4215
-	if ($on) {
4216
-		$bal = 'strong';
4217
-		$class = '';
4218
-		$att = '';
4219
-		// si $on passe la balise et optionnelement une ou ++classe
4220
-		// a.active span.selected.active etc....
4221
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4222
-			$on = explode('.', $on);
4223
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4224
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4225
-				$bal = array_shift($on);
4226
-				$class = implode(' ', $on);
4227
-				if ($bal == 'a') {
4228
-					$att = 'href="#" ';
4229
-				}
4230
-			}
4231
-		}
4232
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4233
-	} else {
4234
-		$bal = 'a';
4235
-		$att = "href='$url'"
4236
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4237
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4238
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4239
-			. $evt;
4240
-	}
4241
-	if ($libelle === null) {
4242
-		$libelle = $url;
4243
-	}
4244
-
4245
-	return "<$bal $att>$libelle</$bal>";
4215
+    if ($on) {
4216
+        $bal = 'strong';
4217
+        $class = '';
4218
+        $att = '';
4219
+        // si $on passe la balise et optionnelement une ou ++classe
4220
+        // a.active span.selected.active etc....
4221
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4222
+            $on = explode('.', $on);
4223
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4224
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4225
+                $bal = array_shift($on);
4226
+                $class = implode(' ', $on);
4227
+                if ($bal == 'a') {
4228
+                    $att = 'href="#" ';
4229
+                }
4230
+            }
4231
+        }
4232
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4233
+    } else {
4234
+        $bal = 'a';
4235
+        $att = "href='$url'"
4236
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4237
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4238
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4239
+            . $evt;
4240
+    }
4241
+    if ($libelle === null) {
4242
+        $libelle = $url;
4243
+    }
4244
+
4245
+    return "<$bal $att>$libelle</$bal>";
4246 4246
 }
4247 4247
 
4248 4248
 
@@ -4259,39 +4259,39 @@  discard block
 block discarded – undo
4259 4259
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4260 4260
  */
4261 4261
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4262
-	static $local_singulier_ou_pluriel = [];
4263
-
4264
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4265
-	if (!is_numeric($nb) or $nb == 0) {
4266
-		return '';
4267
-	}
4268
-	if (!is_array($vars)) {
4269
-		return '';
4270
-	}
4271
-
4272
-	$langue = $GLOBALS['spip_lang'];
4273
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4274
-		$local_singulier_ou_pluriel[$langue] = false;
4275
-		if (
4276
-			$f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4277
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4278
-		) {
4279
-			$local_singulier_ou_pluriel[$langue] = $f;
4280
-		}
4281
-	}
4282
-
4283
-	// si on a une surcharge on l'utilise
4284
-	if ($local_singulier_ou_pluriel[$langue]) {
4285
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4286
-	}
4287
-
4288
-	// sinon traitement par defaut
4289
-	$vars[$var] = $nb;
4290
-	if ($nb >= 2) {
4291
-		return _T($chaine_plusieurs, $vars);
4292
-	} else {
4293
-		return _T($chaine_un, $vars);
4294
-	}
4262
+    static $local_singulier_ou_pluriel = [];
4263
+
4264
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4265
+    if (!is_numeric($nb) or $nb == 0) {
4266
+        return '';
4267
+    }
4268
+    if (!is_array($vars)) {
4269
+        return '';
4270
+    }
4271
+
4272
+    $langue = $GLOBALS['spip_lang'];
4273
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4274
+        $local_singulier_ou_pluriel[$langue] = false;
4275
+        if (
4276
+            $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true)
4277
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4278
+        ) {
4279
+            $local_singulier_ou_pluriel[$langue] = $f;
4280
+        }
4281
+    }
4282
+
4283
+    // si on a une surcharge on l'utilise
4284
+    if ($local_singulier_ou_pluriel[$langue]) {
4285
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4286
+    }
4287
+
4288
+    // sinon traitement par defaut
4289
+    $vars[$var] = $nb;
4290
+    if ($nb >= 2) {
4291
+        return _T($chaine_plusieurs, $vars);
4292
+    } else {
4293
+        return _T($chaine_un, $vars);
4294
+    }
4295 4295
 }
4296 4296
 
4297 4297
 
@@ -4319,73 +4319,73 @@  discard block
 block discarded – undo
4319 4319
  */
4320 4320
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4321 4321
 
4322
-	$class_lien = $class_bouton = $class;
4323
-
4324
-	// Normaliser la fonction et compléter la classe en fonction
4325
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4326
-		$class_lien .= ' danger';
4327
-		$class_bouton .= ' btn_danger';
4328
-	} elseif ($fonction == 'rien.gif') {
4329
-		$fonction = '';
4330
-	} elseif ($fonction == 'delsafe') {
4331
-		$fonction = 'del';
4332
-	}
4333
-
4334
-	$fond_origine = $fond;
4335
-	// Remappage des icone : article-24.png+new => article-new-24.png
4336
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4337
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4338
-	}
4339
-
4340
-	// Ajouter le type d'objet dans la classe
4341
-	$objet_type = substr(basename($fond), 0, -4);
4342
-	$class_lien .= " $objet_type";
4343
-	$class_bouton .= " $objet_type";
4344
-
4345
-	// Texte
4346
-	$alt = attribut_html($texte);
4347
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4348
-
4349
-	// Liens : préparer les classes ajax
4350
-	$ajax = '';
4351
-	if ($type === 'lien') {
4352
-		if (strpos($class_lien, 'ajax') !== false) {
4353
-			$ajax = 'ajax';
4354
-			if (strpos($class_lien, 'preload') !== false) {
4355
-				$ajax .= ' preload';
4356
-			}
4357
-			if (strpos($class_lien, 'nocache') !== false) {
4358
-				$ajax .= ' nocache';
4359
-			}
4360
-			$ajax = " class='$ajax'";
4361
-		}
4362
-	}
4363
-
4364
-	// Repérer la taille et l'ajouter dans la classe
4365
-	$size = 24;
4366
-	if (
4367
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4368
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4369
-	) {
4370
-		$size = $match[1];
4371
-	}
4372
-	$class_lien .= " s$size";
4373
-	$class_bouton .= " s$size";
4374
-
4375
-	// Icône
4376
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4377
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4378
-
4379
-	// Markup final
4380
-	if ($type == 'lien') {
4381
-		return "<span class='icone $class_lien'>"
4382
-		. "<a href='$lien'$title$ajax$javascript>"
4383
-		. $icone
4384
-		. "<b>$texte</b>"
4385
-		. "</a></span>\n";
4386
-	} else {
4387
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4388
-	}
4322
+    $class_lien = $class_bouton = $class;
4323
+
4324
+    // Normaliser la fonction et compléter la classe en fonction
4325
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4326
+        $class_lien .= ' danger';
4327
+        $class_bouton .= ' btn_danger';
4328
+    } elseif ($fonction == 'rien.gif') {
4329
+        $fonction = '';
4330
+    } elseif ($fonction == 'delsafe') {
4331
+        $fonction = 'del';
4332
+    }
4333
+
4334
+    $fond_origine = $fond;
4335
+    // Remappage des icone : article-24.png+new => article-new-24.png
4336
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4337
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4338
+    }
4339
+
4340
+    // Ajouter le type d'objet dans la classe
4341
+    $objet_type = substr(basename($fond), 0, -4);
4342
+    $class_lien .= " $objet_type";
4343
+    $class_bouton .= " $objet_type";
4344
+
4345
+    // Texte
4346
+    $alt = attribut_html($texte);
4347
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4348
+
4349
+    // Liens : préparer les classes ajax
4350
+    $ajax = '';
4351
+    if ($type === 'lien') {
4352
+        if (strpos($class_lien, 'ajax') !== false) {
4353
+            $ajax = 'ajax';
4354
+            if (strpos($class_lien, 'preload') !== false) {
4355
+                $ajax .= ' preload';
4356
+            }
4357
+            if (strpos($class_lien, 'nocache') !== false) {
4358
+                $ajax .= ' nocache';
4359
+            }
4360
+            $ajax = " class='$ajax'";
4361
+        }
4362
+    }
4363
+
4364
+    // Repérer la taille et l'ajouter dans la classe
4365
+    $size = 24;
4366
+    if (
4367
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4368
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4369
+    ) {
4370
+        $size = $match[1];
4371
+    }
4372
+    $class_lien .= " s$size";
4373
+    $class_bouton .= " s$size";
4374
+
4375
+    // Icône
4376
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4377
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4378
+
4379
+    // Markup final
4380
+    if ($type == 'lien') {
4381
+        return "<span class='icone $class_lien'>"
4382
+        . "<a href='$lien'$title$ajax$javascript>"
4383
+        . $icone
4384
+        . "<b>$texte</b>"
4385
+        . "</a></span>\n";
4386
+    } else {
4387
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4388
+    }
4389 4389
 }
4390 4390
 
4391 4391
 /**
@@ -4409,7 +4409,7 @@  discard block
 block discarded – undo
4409 4409
  *     Code HTML du lien
4410 4410
  **/
4411 4411
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4412
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4412
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4413 4413
 }
4414 4414
 
4415 4415
 /**
@@ -4444,7 +4444,7 @@  discard block
 block discarded – undo
4444 4444
  *     Code HTML du lien
4445 4445
  **/
4446 4446
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4447
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4447
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4448 4448
 }
4449 4449
 
4450 4450
 /**
@@ -4489,7 +4489,7 @@  discard block
 block discarded – undo
4489 4489
  *     Code HTML du lien
4490 4490
  **/
4491 4491
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4492
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4492
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4493 4493
 }
4494 4494
 
4495 4495
 /**
@@ -4520,7 +4520,7 @@  discard block
 block discarded – undo
4520 4520
  *     Code HTML du lien
4521 4521
  **/
4522 4522
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4523
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4523
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4524 4524
 }
4525 4525
 
4526 4526
 /**
@@ -4551,7 +4551,7 @@  discard block
 block discarded – undo
4551 4551
  *     Code HTML du lien
4552 4552
  */
4553 4553
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4554
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4554
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4555 4555
 }
4556 4556
 
4557 4557
 
@@ -4573,7 +4573,7 @@  discard block
 block discarded – undo
4573 4573
  * @return array Liste des éléments
4574 4574
  */
4575 4575
 function filtre_explode_dist($a, $b) {
4576
- return explode($b, $a);
4576
+    return explode($b, $a);
4577 4577
 }
4578 4578
 
4579 4579
 /**
@@ -4594,7 +4594,7 @@  discard block
 block discarded – undo
4594 4594
  * @return string Texte
4595 4595
  */
4596 4596
 function filtre_implode_dist($a, $b) {
4597
- return is_array($a) ? implode($b, $a) : $a;
4597
+    return is_array($a) ? implode($b, $a) : $a;
4598 4598
 }
4599 4599
 
4600 4600
 /**
@@ -4603,24 +4603,24 @@  discard block
 block discarded – undo
4603 4603
  * @return string Code CSS
4604 4604
  */
4605 4605
 function bando_images_background() {
4606
-	include_spip('inc/bandeau');
4607
-	// recuperer tous les boutons et leurs images
4608
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4606
+    include_spip('inc/bandeau');
4607
+    // recuperer tous les boutons et leurs images
4608
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4609 4609
 
4610
-	$res = '';
4611
-	foreach ($boutons as $page => $detail) {
4612
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4613
-		if (is_array($detail->sousmenu)) {
4614
-			foreach ($detail->sousmenu as $souspage => $sousdetail) {
4615
-				if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4616
-					$img = http_img_variante_svg_si_possible($sousdetail->icone);
4617
-					$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4618
-				}
4619
-			}
4620
-		}
4621
-	}
4610
+    $res = '';
4611
+    foreach ($boutons as $page => $detail) {
4612
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4613
+        if (is_array($detail->sousmenu)) {
4614
+            foreach ($detail->sousmenu as $souspage => $sousdetail) {
4615
+                if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4616
+                    $img = http_img_variante_svg_si_possible($sousdetail->icone);
4617
+                    $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4618
+                }
4619
+            }
4620
+        }
4621
+    }
4622 4622
 
4623
-	return $res;
4623
+    return $res;
4624 4624
 }
4625 4625
 
4626 4626
 /**
@@ -4645,27 +4645,27 @@  discard block
 block discarded – undo
4645 4645
  */
4646 4646
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4647 4647
 
4648
-	// Classes : dispatcher `ajax` sur le formulaire
4649
-	$class_form = '';
4650
-	if (strpos($class, 'ajax') !== false) {
4651
-		$class_form = 'ajax';
4652
-		$class = str_replace('ajax', '', $class);
4653
-	}
4654
-	$class_btn = 'submit ' . trim($class);
4648
+    // Classes : dispatcher `ajax` sur le formulaire
4649
+    $class_form = '';
4650
+    if (strpos($class, 'ajax') !== false) {
4651
+        $class_form = 'ajax';
4652
+        $class = str_replace('ajax', '', $class);
4653
+    }
4654
+    $class_btn = 'submit ' . trim($class);
4655 4655
 
4656
-	if ($confirm) {
4657
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4658
-		if ($callback) {
4659
-			$callback = "$confirm?($callback):false";
4660
-		} else {
4661
-			$callback = $confirm;
4662
-		}
4663
-	}
4664
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4665
-	$title = $title ? " title='$title'" : '';
4656
+    if ($confirm) {
4657
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4658
+        if ($callback) {
4659
+            $callback = "$confirm?($callback):false";
4660
+        } else {
4661
+            $callback = $confirm;
4662
+        }
4663
+    }
4664
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4665
+    $title = $title ? " title='$title'" : '';
4666 4666
 
4667
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4668
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4667
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4668
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4669 4669
 }
4670 4670
 
4671 4671
 /**
@@ -4688,94 +4688,94 @@  discard block
 block discarded – undo
4688 4688
  * @return string
4689 4689
  */
4690 4690
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4691
-	static $trouver_table = null;
4692
-	static $objets;
4693
-
4694
-	// On verifie qu'on a tout ce qu'il faut
4695
-	$id_objet = intval($id_objet);
4696
-	if (!($id_objet and $type_objet and $info)) {
4697
-		return '';
4698
-	}
4699
-
4700
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4701
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4702
-		return '';
4703
-	}
4704
-
4705
-	// Si on demande l'url, on retourne direct la fonction
4706
-	if ($info == 'url') {
4707
-		return generer_url_entite($id_objet, $type_objet, ...$params);
4708
-	}
4709
-
4710
-	// Sinon on va tout chercher dans la table et on garde en memoire
4711
-	$demande_titre = ($info === 'titre');
4712
-	$demande_introduction = ($info === 'introduction');
4713
-
4714
-	// 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
4715
-	if (
4716
-		!isset($objets[$type_objet][$id_objet])
4717
-		or
4718
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4719
-	) {
4720
-		if (!$trouver_table) {
4721
-			$trouver_table = charger_fonction('trouver_table', 'base');
4722
-		}
4723
-		$desc = $trouver_table(table_objet_sql($type_objet));
4724
-		if (!$desc) {
4725
-			return $objets[$type_objet] = false;
4726
-		}
4727
-
4728
-		// Si on demande le titre, on le gere en interne
4729
-		$champ_titre = '';
4730
-		if ($demande_titre) {
4731
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4732
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4733
-		}
4734
-		include_spip('base/abstract_sql');
4735
-		include_spip('base/connect_sql');
4736
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4737
-			'*' . $champ_titre,
4738
-			$desc['table_sql'],
4739
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4740
-		);
4741
-
4742
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4743
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4744
-	}
4745
-
4746
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4747
-	// ajouter la longueur au début des params supplémentaires
4748
-	if ($demande_introduction) {
4749
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4750
-		array_unshift($params, $introduction_longueur);
4751
-	}
4752
-
4753
-	// Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4754
-	if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4755
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4756
-	} // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4757
-	else {
4758
-		if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4759
-			$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4760
-		} // Sinon on prend directement le champ SQL tel quel
4761
-		else {
4762
-			$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4763
-		}
4764
-	}
4765
-
4766
-	// On va ensuite appliquer les traitements automatiques si besoin
4767
-	if (!$etoile) {
4768
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4769
-		// mais ce fonctionnement est a ameliorer !
4770
-		$info_generee = appliquer_traitement_champ(
4771
-			$info_generee,
4772
-			$info,
4773
-			table_objet($type_objet),
4774
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4775
-		);
4776
-	}
4777
-
4778
-	return $info_generee;
4691
+    static $trouver_table = null;
4692
+    static $objets;
4693
+
4694
+    // On verifie qu'on a tout ce qu'il faut
4695
+    $id_objet = intval($id_objet);
4696
+    if (!($id_objet and $type_objet and $info)) {
4697
+        return '';
4698
+    }
4699
+
4700
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4701
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4702
+        return '';
4703
+    }
4704
+
4705
+    // Si on demande l'url, on retourne direct la fonction
4706
+    if ($info == 'url') {
4707
+        return generer_url_entite($id_objet, $type_objet, ...$params);
4708
+    }
4709
+
4710
+    // Sinon on va tout chercher dans la table et on garde en memoire
4711
+    $demande_titre = ($info === 'titre');
4712
+    $demande_introduction = ($info === 'introduction');
4713
+
4714
+    // 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
4715
+    if (
4716
+        !isset($objets[$type_objet][$id_objet])
4717
+        or
4718
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4719
+    ) {
4720
+        if (!$trouver_table) {
4721
+            $trouver_table = charger_fonction('trouver_table', 'base');
4722
+        }
4723
+        $desc = $trouver_table(table_objet_sql($type_objet));
4724
+        if (!$desc) {
4725
+            return $objets[$type_objet] = false;
4726
+        }
4727
+
4728
+        // Si on demande le titre, on le gere en interne
4729
+        $champ_titre = '';
4730
+        if ($demande_titre) {
4731
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4732
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4733
+        }
4734
+        include_spip('base/abstract_sql');
4735
+        include_spip('base/connect_sql');
4736
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4737
+            '*' . $champ_titre,
4738
+            $desc['table_sql'],
4739
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4740
+        );
4741
+
4742
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4743
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4744
+    }
4745
+
4746
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4747
+    // ajouter la longueur au début des params supplémentaires
4748
+    if ($demande_introduction) {
4749
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4750
+        array_unshift($params, $introduction_longueur);
4751
+    }
4752
+
4753
+    // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee
4754
+    if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) {
4755
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4756
+    } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee
4757
+    else {
4758
+        if ($generer = charger_fonction("generer_${info}_entite", '', true)) {
4759
+            $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4760
+        } // Sinon on prend directement le champ SQL tel quel
4761
+        else {
4762
+            $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4763
+        }
4764
+    }
4765
+
4766
+    // On va ensuite appliquer les traitements automatiques si besoin
4767
+    if (!$etoile) {
4768
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4769
+        // mais ce fonctionnement est a ameliorer !
4770
+        $info_generee = appliquer_traitement_champ(
4771
+            $info_generee,
4772
+            $info,
4773
+            table_objet($type_objet),
4774
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4775
+        );
4776
+    }
4777
+
4778
+    return $info_generee;
4779 4779
 }
4780 4780
 
4781 4781
 /**
@@ -4808,36 +4808,36 @@  discard block
 block discarded – undo
4808 4808
  */
4809 4809
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4810 4810
 
4811
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4812
-	$texte = $ligne_sql['texte'] ?? '';
4813
-	// En absence de descriptif, on se rabat sur chapo + texte
4814
-	if (isset($ligne_sql['chapo'])) {
4815
-		$chapo = $ligne_sql['chapo'];
4816
-		$texte = strlen($descriptif) ?
4817
-			'' :
4818
-			"$chapo \n\n $texte";
4819
-	}
4811
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4812
+    $texte = $ligne_sql['texte'] ?? '';
4813
+    // En absence de descriptif, on se rabat sur chapo + texte
4814
+    if (isset($ligne_sql['chapo'])) {
4815
+        $chapo = $ligne_sql['chapo'];
4816
+        $texte = strlen($descriptif) ?
4817
+            '' :
4818
+            "$chapo \n\n $texte";
4819
+    }
4820 4820
 
4821
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4822
-	if (!intval($longueur_ou_suite)) {
4823
-		$longueur = intval($introduction_longueur ?: 600);
4824
-	} else {
4825
-		$longueur = intval($longueur_ou_suite);
4826
-	}
4821
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4822
+    if (!intval($longueur_ou_suite)) {
4823
+        $longueur = intval($introduction_longueur ?: 600);
4824
+    } else {
4825
+        $longueur = intval($longueur_ou_suite);
4826
+    }
4827 4827
 
4828
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4829
-	// Ex : #INTRODUCTION{...}
4830
-	if (
4831
-		is_null($suite)
4832
-		and !intval($longueur_ou_suite)
4833
-	) {
4834
-		$suite = $longueur_ou_suite;
4835
-	}
4828
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4829
+    // Ex : #INTRODUCTION{...}
4830
+    if (
4831
+        is_null($suite)
4832
+        and !intval($longueur_ou_suite)
4833
+    ) {
4834
+        $suite = $longueur_ou_suite;
4835
+    }
4836 4836
 
4837
-	$f = chercher_filtre('introduction');
4838
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4837
+    $f = chercher_filtre('introduction');
4838
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4839 4839
 
4840
-	return $introduction;
4840
+    return $introduction;
4841 4841
 }
4842 4842
 
4843 4843
 /**
@@ -4851,44 +4851,44 @@  discard block
 block discarded – undo
4851 4851
  * @return string
4852 4852
  */
4853 4853
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4854
-	if (!$champ) {
4855
-		return $texte;
4856
-	}
4854
+    if (!$champ) {
4855
+        return $texte;
4856
+    }
4857 4857
 
4858
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4859
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4860
-	include_fichiers_fonctions();
4858
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4859
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4860
+    include_fichiers_fonctions();
4861 4861
 
4862
-	$champ = strtoupper($champ);
4863
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4864
-	if (!$traitements or !is_array($traitements)) {
4865
-		return $texte;
4866
-	}
4862
+    $champ = strtoupper($champ);
4863
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4864
+    if (!$traitements or !is_array($traitements)) {
4865
+        return $texte;
4866
+    }
4867 4867
 
4868
-	$traitement = '';
4869
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4870
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4871
-		$table_objet = table_objet($table_objet);
4872
-		if (isset($traitements[$table_objet])) {
4873
-			$traitement = $traitements[$table_objet];
4874
-		}
4875
-	}
4876
-	if (!$traitement and isset($traitements[0])) {
4877
-		$traitement = $traitements[0];
4878
-	}
4879
-	// (sinon prendre le premier de la liste par defaut ?)
4868
+    $traitement = '';
4869
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4870
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4871
+        $table_objet = table_objet($table_objet);
4872
+        if (isset($traitements[$table_objet])) {
4873
+            $traitement = $traitements[$table_objet];
4874
+        }
4875
+    }
4876
+    if (!$traitement and isset($traitements[0])) {
4877
+        $traitement = $traitements[0];
4878
+    }
4879
+    // (sinon prendre le premier de la liste par defaut ?)
4880 4880
 
4881
-	if (!$traitement) {
4882
-		return $texte;
4883
-	}
4881
+    if (!$traitement) {
4882
+        return $texte;
4883
+    }
4884 4884
 
4885
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4885
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4886 4886
 
4887
-	// Fournir $connect et $Pile[0] au traitement si besoin
4888
-	$Pile = [0 => $env];
4889
-	eval("\$texte = $traitement;");
4887
+    // Fournir $connect et $Pile[0] au traitement si besoin
4888
+    $Pile = [0 => $env];
4889
+    eval("\$texte = $traitement;");
4890 4890
 
4891
-	return $texte;
4891
+    return $texte;
4892 4892
 }
4893 4893
 
4894 4894
 
@@ -4902,21 +4902,21 @@  discard block
 block discarded – undo
4902 4902
  * @return string
4903 4903
  */
4904 4904
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4905
-	include_spip('inc/liens');
4906
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4907
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4908
-	// le raccourcis n'est plus valide
4909
-	$titre = typo($titre['titre']) ?? '';
4910
-	// on essaye avec generer_info_entite ?
4911
-	if (!strlen($titre) and !$connect) {
4912
-		$titre = generer_info_entite($id_objet, $objet, 'titre');
4913
-	}
4914
-	if (!strlen($titre)) {
4915
-		$titre = _T('info_sans_titre');
4916
-	}
4917
-	$url = generer_url_entite($id_objet, $objet, '', '', $connect);
4905
+    include_spip('inc/liens');
4906
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4907
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4908
+    // le raccourcis n'est plus valide
4909
+    $titre = typo($titre['titre']) ?? '';
4910
+    // on essaye avec generer_info_entite ?
4911
+    if (!strlen($titre) and !$connect) {
4912
+        $titre = generer_info_entite($id_objet, $objet, 'titre');
4913
+    }
4914
+    if (!strlen($titre)) {
4915
+        $titre = _T('info_sans_titre');
4916
+    }
4917
+    $url = generer_url_entite($id_objet, $objet, '', '', $connect);
4918 4918
 
4919
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4919
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4920 4920
 }
4921 4921
 
4922 4922
 
@@ -4933,15 +4933,15 @@  discard block
 block discarded – undo
4933 4933
  * @return string
4934 4934
  */
4935 4935
 function wrap($texte, $wrap) {
4936
-	$balises = extraire_balises($wrap);
4937
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4938
-		$texte = $wrap . $texte;
4939
-		$regs = array_reverse($regs[1]);
4940
-		$wrap = '</' . implode('></', $regs) . '>';
4941
-		$texte = $texte . $wrap;
4942
-	}
4936
+    $balises = extraire_balises($wrap);
4937
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4938
+        $texte = $wrap . $texte;
4939
+        $regs = array_reverse($regs[1]);
4940
+        $wrap = '</' . implode('></', $regs) . '>';
4941
+        $texte = $texte . $wrap;
4942
+    }
4943 4943
 
4944
-	return $texte;
4944
+    return $texte;
4945 4945
 }
4946 4946
 
4947 4947
 
@@ -4961,44 +4961,44 @@  discard block
 block discarded – undo
4961 4961
  * @return array|mixed|string
4962 4962
  */
4963 4963
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4964
-	if (is_string($u)) {
4965
-		$u = typo($u);
4964
+    if (is_string($u)) {
4965
+        $u = typo($u);
4966 4966
 
4967
-		return $u;
4968
-	}
4967
+        return $u;
4968
+    }
4969 4969
 
4970
-	// caster $u en array si besoin
4971
-	if (is_object($u)) {
4972
-		$u = (array)$u;
4973
-	}
4970
+    // caster $u en array si besoin
4971
+    if (is_object($u)) {
4972
+        $u = (array)$u;
4973
+    }
4974 4974
 
4975
-	if (is_array($u)) {
4976
-		$out = '';
4977
-		// toutes les cles sont numeriques ?
4978
-		// et aucun enfant n'est un tableau
4979
-		// liste simple separee par des virgules
4980
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4981
-		$array_values = array_map('is_array', $u);
4982
-		$object_values = array_map('is_object', $u);
4983
-		if (
4984
-			array_sum($numeric_keys) == count($numeric_keys)
4985
-			and !array_sum($array_values)
4986
-			and !array_sum($object_values)
4987
-		) {
4988
-			return join(', ', array_map('filtre_print_dist', $u));
4989
-		}
4975
+    if (is_array($u)) {
4976
+        $out = '';
4977
+        // toutes les cles sont numeriques ?
4978
+        // et aucun enfant n'est un tableau
4979
+        // liste simple separee par des virgules
4980
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4981
+        $array_values = array_map('is_array', $u);
4982
+        $object_values = array_map('is_object', $u);
4983
+        if (
4984
+            array_sum($numeric_keys) == count($numeric_keys)
4985
+            and !array_sum($array_values)
4986
+            and !array_sum($object_values)
4987
+        ) {
4988
+            return join(', ', array_map('filtre_print_dist', $u));
4989
+        }
4990 4990
 
4991
-		// sinon on passe a la ligne et on indente
4992
-		$i_str = str_pad('', $indent, ' ');
4993
-		foreach ($u as $k => $v) {
4994
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4995
-		}
4991
+        // sinon on passe a la ligne et on indente
4992
+        $i_str = str_pad('', $indent, ' ');
4993
+        foreach ($u as $k => $v) {
4994
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4995
+        }
4996 4996
 
4997
-		return $out;
4998
-	}
4997
+        return $out;
4998
+    }
4999 4999
 
5000
-	// on sait pas quoi faire...
5001
-	return $u;
5000
+    // on sait pas quoi faire...
5001
+    return $u;
5002 5002
 }
5003 5003
 
5004 5004
 
@@ -5011,10 +5011,10 @@  discard block
 block discarded – undo
5011 5011
  * @return string|array
5012 5012
  */
5013 5013
 function objet_info($objet, $info) {
5014
-	$table = table_objet_sql($objet);
5015
-	$infos = lister_tables_objets_sql($table);
5014
+    $table = table_objet_sql($objet);
5015
+    $infos = lister_tables_objets_sql($table);
5016 5016
 
5017
-	return ($infos[$info] ?? '');
5017
+    return ($infos[$info] ?? '');
5018 5018
 }
5019 5019
 
5020 5020
 /**
@@ -5029,11 +5029,11 @@  discard block
 block discarded – undo
5029 5029
  *     Texte traduit du comptage, tel que '3 articles'
5030 5030
  */
5031 5031
 function objet_afficher_nb($nb, $objet) {
5032
-	if (!$nb) {
5033
-		return _T(objet_info($objet, 'info_aucun_objet'));
5034
-	} else {
5035
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5036
-	}
5032
+    if (!$nb) {
5033
+        return _T(objet_info($objet, 'info_aucun_objet'));
5034
+    } else {
5035
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5036
+    }
5037 5037
 }
5038 5038
 
5039 5039
 /**
@@ -5045,11 +5045,11 @@  discard block
 block discarded – undo
5045 5045
  * @return string
5046 5046
  */
5047 5047
 function objet_icone($objet, $taille = 24, $class = '') {
5048
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5049
-	$icone = chemin_image($icone);
5050
-	$balise_img = charger_filtre('balise_img');
5048
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5049
+    $icone = chemin_image($icone);
5050
+    $balise_img = charger_filtre('balise_img');
5051 5051
 
5052
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5052
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5053 5053
 }
5054 5054
 
5055 5055
 /**
@@ -5070,12 +5070,12 @@  discard block
 block discarded – undo
5070 5070
  * @return string
5071 5071
  */
5072 5072
 function objet_T($objet, $chaine, $args = [], $options = []) {
5073
-	$chaine = explode(':', $chaine);
5074
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5075
-		return $t;
5076
-	}
5077
-	$chaine = implode(':', $chaine);
5078
-	return _T($chaine, $args, $options);
5073
+    $chaine = explode(':', $chaine);
5074
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5075
+        return $t;
5076
+    }
5077
+    $chaine = implode(':', $chaine);
5078
+    return _T($chaine, $args, $options);
5079 5079
 }
5080 5080
 
5081 5081
 /**
@@ -5089,18 +5089,18 @@  discard block
 block discarded – undo
5089 5089
  * @return string      Code HTML
5090 5090
  */
5091 5091
 function insert_head_css_conditionnel($flux) {
5092
-	if (
5093
-		strpos($flux, '<!-- insert_head_css -->') === false
5094
-		and $p = strpos($flux, '<!-- insert_head -->')
5095
-	) {
5096
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5097
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5098
-			$p = $p1;
5099
-		}
5100
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5101
-	}
5092
+    if (
5093
+        strpos($flux, '<!-- insert_head_css -->') === false
5094
+        and $p = strpos($flux, '<!-- insert_head -->')
5095
+    ) {
5096
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5097
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5098
+            $p = $p1;
5099
+        }
5100
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5101
+    }
5102 5102
 
5103
-	return $flux;
5103
+    return $flux;
5104 5104
 }
5105 5105
 
5106 5106
 /**
@@ -5123,72 +5123,72 @@  discard block
 block discarded – undo
5123 5123
  * @return string
5124 5124
  */
5125 5125
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5126
-	if (isset($contexte['format'])) {
5127
-		$extension = $contexte['format'];
5128
-		unset($contexte['format']);
5129
-	} else {
5130
-		$extension = 'html';
5131
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5132
-			$extension = $m[1];
5133
-		}
5134
-	}
5135
-	// recuperer le contenu produit par le squelette
5136
-	$options['raw'] = true;
5137
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5138
-
5139
-	// calculer le nom de la css
5140
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5141
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5142
-	$contexte_implicite = calculer_contexte_implicite();
5143
-
5144
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5145
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5146
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5147
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5148
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5149
-	}
5150
-	else {
5151
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5152
-		ksort($contexte);
5153
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5154
-	}
5155
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5156
-
5157
-	// mettre a jour le fichier si il n'existe pas
5158
-	// ou trop ancien
5159
-	// le dernier fichier produit est toujours suffixe par .last
5160
-	// et recopie sur le fichier cible uniquement si il change
5161
-	if (
5162
-		!file_exists($filename)
5163
-		or !file_exists($filename . '.last')
5164
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5165
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5166
-	) {
5167
-		$contenu = $cache['texte'];
5168
-		// passer les urls en absolu si c'est une css
5169
-		if ($extension == 'css') {
5170
-			$contenu = urls_absolues_css(
5171
-				$contenu,
5172
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5173
-			);
5174
-		}
5175
-
5176
-		$comment = '';
5177
-		// ne pas insérer de commentaire sur certains formats
5178
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5179
-			$comment = "/* #PRODUIRE{fond=$fond";
5180
-			foreach ($contexte as $k => $v) {
5181
-				$comment .= ",$k=$v";
5182
-			}
5183
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5184
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5185
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5186
-		}
5187
-		// et ecrire le fichier si il change
5188
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5189
-	}
5190
-
5191
-	return timestamp($filename);
5126
+    if (isset($contexte['format'])) {
5127
+        $extension = $contexte['format'];
5128
+        unset($contexte['format']);
5129
+    } else {
5130
+        $extension = 'html';
5131
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5132
+            $extension = $m[1];
5133
+        }
5134
+    }
5135
+    // recuperer le contenu produit par le squelette
5136
+    $options['raw'] = true;
5137
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5138
+
5139
+    // calculer le nom de la css
5140
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5141
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5142
+    $contexte_implicite = calculer_contexte_implicite();
5143
+
5144
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5145
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5146
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5147
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5148
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5149
+    }
5150
+    else {
5151
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5152
+        ksort($contexte);
5153
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5154
+    }
5155
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5156
+
5157
+    // mettre a jour le fichier si il n'existe pas
5158
+    // ou trop ancien
5159
+    // le dernier fichier produit est toujours suffixe par .last
5160
+    // et recopie sur le fichier cible uniquement si il change
5161
+    if (
5162
+        !file_exists($filename)
5163
+        or !file_exists($filename . '.last')
5164
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5165
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5166
+    ) {
5167
+        $contenu = $cache['texte'];
5168
+        // passer les urls en absolu si c'est une css
5169
+        if ($extension == 'css') {
5170
+            $contenu = urls_absolues_css(
5171
+                $contenu,
5172
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5173
+            );
5174
+        }
5175
+
5176
+        $comment = '';
5177
+        // ne pas insérer de commentaire sur certains formats
5178
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5179
+            $comment = "/* #PRODUIRE{fond=$fond";
5180
+            foreach ($contexte as $k => $v) {
5181
+                $comment .= ",$k=$v";
5182
+            }
5183
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5184
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5185
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5186
+        }
5187
+        // et ecrire le fichier si il change
5188
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5189
+    }
5190
+
5191
+    return timestamp($filename);
5192 5192
 }
5193 5193
 
5194 5194
 /**
@@ -5201,15 +5201,15 @@  discard block
 block discarded – undo
5201 5201
  *    $fichier auquel on a ajouté le timestamp
5202 5202
  */
5203 5203
 function timestamp($fichier) {
5204
-	if (
5205
-		!$fichier
5206
-		or !file_exists($fichier)
5207
-		or !$m = filemtime($fichier)
5208
-	) {
5209
-		return $fichier;
5210
-	}
5204
+    if (
5205
+        !$fichier
5206
+        or !file_exists($fichier)
5207
+        or !$m = filemtime($fichier)
5208
+    ) {
5209
+        return $fichier;
5210
+    }
5211 5211
 
5212
-	return "$fichier?$m";
5212
+    return "$fichier?$m";
5213 5213
 }
5214 5214
 
5215 5215
 /**
@@ -5219,11 +5219,11 @@  discard block
 block discarded – undo
5219 5219
  * @return string
5220 5220
  */
5221 5221
 function supprimer_timestamp($url) {
5222
-	if (strpos($url, '?') === false) {
5223
-		return $url;
5224
-	}
5222
+    if (strpos($url, '?') === false) {
5223
+        return $url;
5224
+    }
5225 5225
 
5226
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5226
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5227 5227
 }
5228 5228
 
5229 5229
 /**
@@ -5238,9 +5238,9 @@  discard block
 block discarded – undo
5238 5238
  * @return string
5239 5239
  */
5240 5240
 function filtre_nettoyer_titre_email_dist($titre) {
5241
-	include_spip('inc/envoyer_mail');
5241
+    include_spip('inc/envoyer_mail');
5242 5242
 
5243
-	return nettoyer_titre_email($titre);
5243
+    return nettoyer_titre_email($titre);
5244 5244
 }
5245 5245
 
5246 5246
 /**
@@ -5262,27 +5262,27 @@  discard block
 block discarded – undo
5262 5262
  * @return string
5263 5263
  */
5264 5264
 function filtre_chercher_rubrique_dist(
5265
-	$titre,
5266
-	$id_objet,
5267
-	$id_parent,
5268
-	$objet,
5269
-	$id_secteur,
5270
-	$restreint,
5271
-	$actionable = false,
5272
-	$retour_sans_cadre = false
5265
+    $titre,
5266
+    $id_objet,
5267
+    $id_parent,
5268
+    $objet,
5269
+    $id_secteur,
5270
+    $restreint,
5271
+    $actionable = false,
5272
+    $retour_sans_cadre = false
5273 5273
 ) {
5274
-	include_spip('inc/filtres_ecrire');
5274
+    include_spip('inc/filtres_ecrire');
5275 5275
 
5276
-	return chercher_rubrique(
5277
-		$titre,
5278
-		$id_objet,
5279
-		$id_parent,
5280
-		$objet,
5281
-		$id_secteur,
5282
-		$restreint,
5283
-		$actionable,
5284
-		$retour_sans_cadre
5285
-	);
5276
+    return chercher_rubrique(
5277
+        $titre,
5278
+        $id_objet,
5279
+        $id_parent,
5280
+        $objet,
5281
+        $id_secteur,
5282
+        $restreint,
5283
+        $actionable,
5284
+        $retour_sans_cadre
5285
+    );
5286 5286
 }
5287 5287
 
5288 5288
 /**
@@ -5311,56 +5311,56 @@  discard block
 block discarded – undo
5311 5311
  *     Chaîne vide si l'accès est autorisé
5312 5312
  */
5313 5313
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5314
-	if ($ok) {
5315
-		return '';
5316
-	}
5317
-
5318
-	// Vider tous les tampons
5319
-	$level = @ob_get_level();
5320
-	while ($level--) {
5321
-		@ob_end_clean();
5322
-	}
5323
-
5324
-	include_spip('inc/headers');
5325
-
5326
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5327
-	if ($url) {
5328
-		redirige_par_entete($url, '', $statut);
5329
-	}
5330
-
5331
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5332
-	if (!is_numeric($statut) and is_null($message)) {
5333
-		$message = $statut;
5334
-		$statut = 0;
5335
-	}
5336
-	if (!$message) {
5337
-		$message = '';
5338
-	}
5339
-	$statut = intval($statut);
5340
-
5341
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5342
-	if (test_espace_prive()) {
5343
-		if (!$statut or !in_array($statut, [404, 403])) {
5344
-			$statut = 403;
5345
-		}
5346
-		http_response_code(403);
5347
-		$echec = charger_fonction('403', 'exec');
5348
-		$echec($message);
5349
-	} else {
5350
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5351
-		if (!$statut) {
5352
-			$statut = 404;
5353
-		}
5354
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5355
-		http_response_code($statut);
5356
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5357
-		if ($statut >= 400) {
5358
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5359
-		}
5360
-	}
5361
-
5362
-
5363
-	exit;
5314
+    if ($ok) {
5315
+        return '';
5316
+    }
5317
+
5318
+    // Vider tous les tampons
5319
+    $level = @ob_get_level();
5320
+    while ($level--) {
5321
+        @ob_end_clean();
5322
+    }
5323
+
5324
+    include_spip('inc/headers');
5325
+
5326
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5327
+    if ($url) {
5328
+        redirige_par_entete($url, '', $statut);
5329
+    }
5330
+
5331
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5332
+    if (!is_numeric($statut) and is_null($message)) {
5333
+        $message = $statut;
5334
+        $statut = 0;
5335
+    }
5336
+    if (!$message) {
5337
+        $message = '';
5338
+    }
5339
+    $statut = intval($statut);
5340
+
5341
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5342
+    if (test_espace_prive()) {
5343
+        if (!$statut or !in_array($statut, [404, 403])) {
5344
+            $statut = 403;
5345
+        }
5346
+        http_response_code(403);
5347
+        $echec = charger_fonction('403', 'exec');
5348
+        $echec($message);
5349
+    } else {
5350
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5351
+        if (!$statut) {
5352
+            $statut = 404;
5353
+        }
5354
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5355
+        http_response_code($statut);
5356
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5357
+        if ($statut >= 400) {
5358
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5359
+        }
5360
+    }
5361
+
5362
+
5363
+    exit;
5364 5364
 }
5365 5365
 
5366 5366
 /**
@@ -5371,11 +5371,11 @@  discard block
 block discarded – undo
5371 5371
  * @return string
5372 5372
  */
5373 5373
 function filtre_compacte_dist($source, $format = null) {
5374
-	if (function_exists('compacte')) {
5375
-		return compacte($source, $format);
5376
-	}
5374
+    if (function_exists('compacte')) {
5375
+        return compacte($source, $format);
5376
+    }
5377 5377
 
5378
-	return $source;
5378
+    return $source;
5379 5379
 }
5380 5380
 
5381 5381
 
@@ -5387,31 +5387,31 @@  discard block
 block discarded – undo
5387 5387
  * @return string
5388 5388
  */
5389 5389
 function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
5390
-	$l = strlen($passe);
5391
-
5392
-	if ($l <= 8 or !$afficher_partiellement) {
5393
-		if (!$l) {
5394
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5395
-		}
5396
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5397
-	}
5398
-
5399
-	if (is_null($portion_pourcent)) {
5400
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5401
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5402
-		}
5403
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5404
-	}
5405
-	if ($portion_pourcent >= 100) {
5406
-		return $passe;
5407
-	}
5408
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5409
-	$e = max($e, 0);
5410
-	$mid = str_pad('', $l - 2 * $e, '*');
5411
-	if ($e > 0 and strlen($mid) > 8) {
5412
-		$mid = '***...***';
5413
-	}
5414
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5390
+    $l = strlen($passe);
5391
+
5392
+    if ($l <= 8 or !$afficher_partiellement) {
5393
+        if (!$l) {
5394
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5395
+        }
5396
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5397
+    }
5398
+
5399
+    if (is_null($portion_pourcent)) {
5400
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5401
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5402
+        }
5403
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5404
+    }
5405
+    if ($portion_pourcent >= 100) {
5406
+        return $passe;
5407
+    }
5408
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5409
+    $e = max($e, 0);
5410
+    $mid = str_pad('', $l - 2 * $e, '*');
5411
+    if ($e > 0 and strlen($mid) > 8) {
5412
+        $mid = '***...***';
5413
+    }
5414
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5415 5415
 }
5416 5416
 
5417 5417
 
@@ -5432,64 +5432,64 @@  discard block
 block discarded – undo
5432 5432
  */
5433 5433
 function identifiant_slug($texte, $type = '', $options = []) {
5434 5434
 
5435
-	$original = $texte;
5436
-	$separateur = ($options['separateur'] ?? '_');
5437
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5438
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5435
+    $original = $texte;
5436
+    $separateur = ($options['separateur'] ?? '_');
5437
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5438
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5439 5439
 
5440
-	if (!function_exists('translitteration')) {
5441
-		include_spip('inc/charsets');
5442
-	}
5440
+    if (!function_exists('translitteration')) {
5441
+        include_spip('inc/charsets');
5442
+    }
5443 5443
 
5444
-	// pas de balise html
5445
-	if (strpos($texte, '<') !== false) {
5446
-		$texte = strip_tags($texte);
5447
-	}
5448
-	if (strpos($texte, '&') !== false) {
5449
-		$texte = unicode2charset($texte);
5450
-	}
5451
-	// On enlève les espaces indésirables
5452
-	$texte = trim($texte);
5444
+    // pas de balise html
5445
+    if (strpos($texte, '<') !== false) {
5446
+        $texte = strip_tags($texte);
5447
+    }
5448
+    if (strpos($texte, '&') !== false) {
5449
+        $texte = unicode2charset($texte);
5450
+    }
5451
+    // On enlève les espaces indésirables
5452
+    $texte = trim($texte);
5453 5453
 
5454
-	// On enlève les accents et cie
5455
-	$texte = translitteration($texte);
5454
+    // On enlève les accents et cie
5455
+    $texte = translitteration($texte);
5456 5456
 
5457
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5458
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5457
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5458
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5459 5459
 
5460
-	// nettoyer les doubles occurences du separateur si besoin
5461
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5462
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5463
-	}
5460
+    // nettoyer les doubles occurences du separateur si besoin
5461
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5462
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5463
+    }
5464 5464
 
5465
-	// pas de separateur au debut ni a la fin
5466
-	$texte = trim($texte, $separateur);
5465
+    // pas de separateur au debut ni a la fin
5466
+    $texte = trim($texte, $separateur);
5467 5467
 
5468
-	// en minuscules
5469
-	$texte = strtolower($texte);
5468
+    // en minuscules
5469
+    $texte = strtolower($texte);
5470 5470
 
5471
-	switch ($type) {
5472
-		case 'class':
5473
-		case 'id':
5474
-		case 'anchor':
5475
-			if (preg_match(',^\d,', $texte)) {
5476
-				$texte = substr($type, 0, 1) . $texte;
5477
-			}
5478
-	}
5471
+    switch ($type) {
5472
+        case 'class':
5473
+        case 'id':
5474
+        case 'anchor':
5475
+            if (preg_match(',^\d,', $texte)) {
5476
+                $texte = substr($type, 0, 1) . $texte;
5477
+            }
5478
+    }
5479 5479
 
5480
-	if (strlen($texte) > $longueur_maxi) {
5481
-		$texte = substr($texte, 0, $longueur_maxi);
5482
-	}
5480
+    if (strlen($texte) > $longueur_maxi) {
5481
+        $texte = substr($texte, 0, $longueur_maxi);
5482
+    }
5483 5483
 
5484
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5485
-		if (preg_match(',^\d,', $texte)) {
5486
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5487
-		}
5488
-		$texte .= $separateur . md5($original);
5489
-		$texte = substr($texte, 0, $longueur_mini);
5490
-	}
5484
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5485
+        if (preg_match(',^\d,', $texte)) {
5486
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5487
+        }
5488
+        $texte .= $separateur . md5($original);
5489
+        $texte = substr($texte, 0, $longueur_mini);
5490
+    }
5491 5491
 
5492
-	return $texte;
5492
+    return $texte;
5493 5493
 }
5494 5494
 
5495 5495
 
@@ -5510,11 +5510,11 @@  discard block
 block discarded – undo
5510 5510
  * @exemple `<:info_maximum|label_nettoyer:>`
5511 5511
  */
5512 5512
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5513
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5514
-	if ($ucfirst) {
5515
-		$label = spip_ucfirst($label);
5516
-	}
5517
-	return $label;
5513
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5514
+    if ($ucfirst) {
5515
+        $label = spip_ucfirst($label);
5516
+    }
5517
+    return $label;
5518 5518
 }
5519 5519
 
5520 5520
 /**
@@ -5527,8 +5527,8 @@  discard block
 block discarded – undo
5527 5527
  * @exemple `<:info_maximum|label_ponctuer:>`
5528 5528
  */
5529 5529
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5530
-	$label = label_nettoyer($text, $ucfirst);
5531
-	return _T('label_ponctuer', ['label' => $label]);
5530
+    $label = label_nettoyer($text, $ucfirst);
5531
+    return _T('label_ponctuer', ['label' => $label]);
5532 5532
 }
5533 5533
 
5534 5534
 
@@ -5541,19 +5541,19 @@  discard block
 block discarded – undo
5541 5541
  * @return array
5542 5542
  */
5543 5543
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5544
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5545
-		return [];
5546
-	}
5544
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5545
+        return [];
5546
+    }
5547 5547
 
5548
-	// compatibilite signature inversee
5549
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5550
-		[$objet, $id_objet] = [$id_objet, $objet];
5551
-	}
5548
+    // compatibilite signature inversee
5549
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5550
+        [$objet, $id_objet] = [$id_objet, $objet];
5551
+    }
5552 5552
 
5553
-	if (!function_exists($fonction)) {
5554
-		include_spip('base/objets');
5555
-	}
5556
-	return $fonction($objet, $id_objet);
5553
+    if (!function_exists($fonction)) {
5554
+        include_spip('base/objets');
5555
+    }
5556
+    return $fonction($objet, $id_objet);
5557 5557
 }
5558 5558
 
5559 5559
 
@@ -5568,7 +5568,7 @@  discard block
 block discarded – undo
5568 5568
  * @return array
5569 5569
  */
5570 5570
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5571
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5571
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5572 5572
 }
5573 5573
 
5574 5574
 /**
@@ -5582,7 +5582,7 @@  discard block
 block discarded – undo
5582 5582
  * @return array
5583 5583
  */
5584 5584
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5585
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5585
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5586 5586
 }
5587 5587
 
5588 5588
 /**
@@ -5596,7 +5596,7 @@  discard block
 block discarded – undo
5596 5596
  * @return array
5597 5597
  */
5598 5598
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5599
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5599
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5600 5600
 }
5601 5601
 
5602 5602
 /**
@@ -5610,5 +5610,5 @@  discard block
 block discarded – undo
5610 5610
  * @return array
5611 5611
  */
5612 5612
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5613
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5613
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5614 5614
 }
Please login to merge, or discard this patch.