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