Completed
Push — master ( cf9413...1b02d1 )
by cam
01:13
created
ecrire/inc/filtres.php 1 patch
Indentation   +2413 added lines, -2413 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Filtres
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/charsets');
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
  * @return string Fonction PHP correspondante du filtre
43 43
  */
44 44
 function charger_filtre($fonc, $default = 'filtre_identite_dist') {
45
-	include_fichiers_fonctions(); // inclure les fichiers fonctions
46
-	return chercher_filtre($fonc, $default);
45
+    include_fichiers_fonctions(); // inclure les fichiers fonctions
46
+    return chercher_filtre($fonc, $default);
47 47
 }
48 48
 
49 49
 /**
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
  * @return string Texte
54 54
  **/
55 55
 function filtre_identite_dist($texte) {
56
- return $texte;
56
+    return $texte;
57 57
 }
58 58
 
59 59
 /**
@@ -77,33 +77,33 @@  discard block
 block discarded – undo
77 77
  *     Fonction PHP correspondante du filtre demandé
78 78
  */
79 79
 function chercher_filtre($fonc, $default = null) {
80
-	if (!$fonc) {
81
-		return $default;
82
-	}
83
-	// Cas des types mime, sans confondre avec les appels de fonction de classe
84
-	// Foo::Bar
85
-	// qui peuvent etre avec un namespace : space\Foo::Bar
86
-	if (preg_match(',^[\w]+/,', $fonc)) {
87
-		$nom = preg_replace(',\W,', '_', $fonc);
88
-		$f = chercher_filtre($nom);
89
-		// cas du sous-type MIME sans filtre associe, passer au type:
90
-		// si filtre_text_plain pas defini, passe a filtre_text
91
-		if (!$f and $nom !== $fonc) {
92
-			$f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
-		}
94
-
95
-		return $f;
96
-	}
97
-
98
-	include_fichiers_fonctions();
99
-	foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
-		trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
-		if (is_callable($f)) {
102
-			return $f;
103
-		}
104
-	}
105
-
106
-	return $default;
80
+    if (!$fonc) {
81
+        return $default;
82
+    }
83
+    // Cas des types mime, sans confondre avec les appels de fonction de classe
84
+    // Foo::Bar
85
+    // qui peuvent etre avec un namespace : space\Foo::Bar
86
+    if (preg_match(',^[\w]+/,', $fonc)) {
87
+        $nom = preg_replace(',\W,', '_', $fonc);
88
+        $f = chercher_filtre($nom);
89
+        // cas du sous-type MIME sans filtre associe, passer au type:
90
+        // si filtre_text_plain pas defini, passe a filtre_text
91
+        if (!$f and $nom !== $fonc) {
92
+            $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc));
93
+        }
94
+
95
+        return $f;
96
+    }
97
+
98
+    include_fichiers_fonctions();
99
+    foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) {
100
+        trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels
101
+        if (is_callable($f)) {
102
+            return $f;
103
+        }
104
+    }
105
+
106
+    return $default;
107 107
 }
108 108
 
109 109
 /**
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
  *     Chaîne vide sinon.
148 148
  **/
149 149
 function appliquer_filtre($arg, $filtre) {
150
-	$args = func_get_args();
151
-	return appliquer_filtre_sinon($arg, $filtre, $args, '');
150
+    $args = func_get_args();
151
+    return appliquer_filtre_sinon($arg, $filtre, $args, '');
152 152
 }
153 153
 
154 154
 /**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
  *     Texte d'origine sinon
174 174
  **/
175 175
 function appliquer_si_filtre($arg, $filtre) {
176
-	$args = func_get_args();
177
-	return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
176
+    $args = func_get_args();
177
+    return appliquer_filtre_sinon($arg, $filtre, $args, $arg);
178 178
 }
179 179
 
180 180
 /**
@@ -190,12 +190,12 @@  discard block
 block discarded – undo
190 190
  *     Version de SPIP
191 191
  **/
192 192
 function spip_version() {
193
-	$version = $GLOBALS['spip_version_affichee'];
194
-	if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
195
-		$version .= " $vcs_version";
196
-	}
193
+    $version = $GLOBALS['spip_version_affichee'];
194
+    if ($vcs_version = version_vcs_courante(_DIR_RACINE)) {
195
+        $version .= " $vcs_version";
196
+    }
197 197
 
198
-	return $version;
198
+    return $version;
199 199
 }
200 200
 
201 201
 /**
@@ -207,11 +207,11 @@  discard block
 block discarded – undo
207 207
  * @return string
208 208
  */
209 209
 function header_silencieux($version): string {
210
-	if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
211
-		$version = '';
212
-	}
210
+    if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) {
211
+        $version = '';
212
+    }
213 213
 
214
-	return (string) $version;
214
+    return (string) $version;
215 215
 }
216 216
 
217 217
 /**
@@ -224,19 +224,19 @@  discard block
 block discarded – undo
224 224
  *    - string|null si $raw = false
225 225
  */
226 226
 function version_vcs_courante($dir, $raw = false) {
227
-	$desc = decrire_version_git($dir);
228
-	if ($desc === null) {
229
-		$desc = decrire_version_svn($dir);
230
-	}
231
-	if ($desc === null or $raw) {
232
-		return $desc;
233
-	}
234
-	// affichage "GIT [master: abcdef]"
235
-	$commit = $desc['commit_short'] ?? $desc['commit'];
236
-	if ($desc['branch']) {
237
-		$commit = $desc['branch'] . ': ' . $commit;
238
-	}
239
-	return "{$desc['vcs']} [$commit]";
227
+    $desc = decrire_version_git($dir);
228
+    if ($desc === null) {
229
+        $desc = decrire_version_svn($dir);
230
+    }
231
+    if ($desc === null or $raw) {
232
+        return $desc;
233
+    }
234
+    // affichage "GIT [master: abcdef]"
235
+    $commit = $desc['commit_short'] ?? $desc['commit'];
236
+    if ($desc['branch']) {
237
+        $commit = $desc['branch'] . ': ' . $commit;
238
+    }
239
+    return "{$desc['vcs']} [$commit]";
240 240
 }
241 241
 
242 242
 /**
@@ -248,24 +248,24 @@  discard block
 block discarded – undo
248 248
  *      array ['branch' => xx, 'commit' => yy] sinon.
249 249
  **/
250 250
 function decrire_version_git($dir) {
251
-	if (!$dir) {
252
-		$dir = '.';
253
-	}
251
+    if (!$dir) {
252
+        $dir = '.';
253
+    }
254 254
 
255
-	// version installee par GIT
256
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
257
-		$currentHead = trim(substr($c, 4));
258
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
259
-			return [
260
-				'vcs' => 'GIT',
261
-				'branch' => basename($currentHead),
262
-				'commit' => trim($hash),
263
-				'commit_short' => substr(trim($hash), 0, 8),
264
-			];
265
-		}
266
-	}
255
+    // version installee par GIT
256
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
257
+        $currentHead = trim(substr($c, 4));
258
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
259
+            return [
260
+                'vcs' => 'GIT',
261
+                'branch' => basename($currentHead),
262
+                'commit' => trim($hash),
263
+                'commit_short' => substr(trim($hash), 0, 8),
264
+            ];
265
+        }
266
+    }
267 267
 
268
-	return null;
268
+    return null;
269 269
 }
270 270
 
271 271
 
@@ -278,25 +278,25 @@  discard block
 block discarded – undo
278 278
  *      array ['commit' => yy, 'date' => xx, 'author' => xx] sinon.
279 279
  **/
280 280
 function decrire_version_svn($dir) {
281
-	if (!$dir) {
282
-		$dir = '.';
283
-	}
284
-	// version installee par SVN
285
-	if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
286
-		$db = new SQLite3($dir . '/.svn/wc.db');
287
-		$result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
288
-		if ($result) {
289
-			$row = $result->fetchArray();
290
-			if ($row['changed_revision'] != '') {
291
-				return [
292
-					'vcs' => 'SVN',
293
-					'branch' => '',
294
-					'commit' => $row['changed_revision'],
295
-				];
296
-			}
297
-		}
298
-	}
299
-	return null;
281
+    if (!$dir) {
282
+        $dir = '.';
283
+    }
284
+    // version installee par SVN
285
+    if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) {
286
+        $db = new SQLite3($dir . '/.svn/wc.db');
287
+        $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1');
288
+        if ($result) {
289
+            $row = $result->fetchArray();
290
+            if ($row['changed_revision'] != '') {
291
+                return [
292
+                    'vcs' => 'SVN',
293
+                    'branch' => '',
294
+                    'commit' => $row['changed_revision'],
295
+                ];
296
+            }
297
+        }
298
+    }
299
+    return null;
300 300
 }
301 301
 
302 302
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -343,18 +343,18 @@  discard block
 block discarded – undo
343 343
  *     Code HTML retourné par le filtre
344 344
  **/
345 345
 function filtrer($filtre) {
346
-	$tous = func_get_args();
347
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
348
-		return image_filtrer($tous);
349
-	} elseif ($f = chercher_filtre($filtre)) {
350
-		array_shift($tous);
351
-		return $f(...$tous);
352
-	} else {
353
-		// le filtre n'existe pas, on provoque une erreur
354
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
355
-		erreur_squelette($msg);
356
-		return '';
357
-	}
346
+    $tous = func_get_args();
347
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
348
+        return image_filtrer($tous);
349
+    } elseif ($f = chercher_filtre($filtre)) {
350
+        array_shift($tous);
351
+        return $f(...$tous);
352
+    } else {
353
+        // le filtre n'existe pas, on provoque une erreur
354
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
355
+        erreur_squelette($msg);
356
+        return '';
357
+    }
358 358
 }
359 359
 
360 360
 /**
@@ -371,11 +371,11 @@  discard block
 block discarded – undo
371 371
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
372 372
  */
373 373
 function trouver_filtre_matrice($filtre) {
374
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
375
-		find_in_path($f, '', true);
376
-		$GLOBALS['spip_matrice'][$filtre] = true;
377
-	}
378
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
374
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
375
+        find_in_path($f, '', true);
376
+        $GLOBALS['spip_matrice'][$filtre] = true;
377
+    }
378
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
379 379
 }
380 380
 
381 381
 
@@ -403,8 +403,8 @@  discard block
 block discarded – undo
403 403
  * @return mixed
404 404
  */
405 405
 function filtre_set(&$Pile, $val, $key, $continue = null) {
406
-	$Pile['vars'][$key] = $val;
407
-	return $continue ? $val : '';
406
+    $Pile['vars'][$key] = $val;
407
+    return $continue ? $val : '';
408 408
 }
409 409
 
410 410
 /**
@@ -430,8 +430,8 @@  discard block
 block discarded – undo
430 430
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
431 431
  */
432 432
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
433
-	$Pile[0][$key] = $val;
434
-	return $continue ? $val : '';
433
+    $Pile[0][$key] = $val;
434
+    return $continue ? $val : '';
435 435
 }
436 436
 
437 437
 /**
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
  * @return string
441 441
  */
442 442
 function filtre_sanitize_env(&$Pile, $keys) {
443
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
444
-	return '';
443
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
444
+    return '';
445 445
 }
446 446
 
447 447
 
@@ -464,18 +464,18 @@  discard block
 block discarded – undo
464 464
  * @return mixed Retourne la valeur (sans la modifier).
465 465
  */
466 466
 function filtre_debug($val, $key = null) {
467
-	$debug = (
468
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
469
-		) . var_export($val, true);
467
+    $debug = (
468
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
469
+        ) . var_export($val, true);
470 470
 
471
-	include_spip('inc/autoriser');
472
-	if (autoriser('webmestre')) {
473
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
474
-	}
471
+    include_spip('inc/autoriser');
472
+    if (autoriser('webmestre')) {
473
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
474
+    }
475 475
 
476
-	spip_log($debug, 'debug');
476
+    spip_log($debug, 'debug');
477 477
 
478
-	return $val;
478
+    return $val;
479 479
 }
480 480
 
481 481
 
@@ -505,84 +505,84 @@  discard block
 block discarded – undo
505 505
  *     Texte qui a reçu les filtres
506 506
  **/
507 507
 function image_filtrer($args) {
508
-	$filtre = array_shift($args); # enlever $filtre
509
-	$texte = array_shift($args);
510
-	if ($texte === null || !strlen($texte)) {
511
-		return '';
512
-	}
513
-	find_in_path('filtres_images_mini.php', 'inc/', true);
514
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
515
-	// Cas du nom de fichier local
516
-	$is_file = trim($texte);
517
-	if (
518
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
519
-		  or strpbrk($is_file, "<>\n\r\t") !== false
520
-		  or strpos($is_file, '/') === 0
521
-	) {
522
-		$is_file = false;
523
-	}
524
-	if ($is_file) {
525
-		$is_local_file = function ($path) {
526
-			if (strpos($path, '?') !== false) {
527
-				$path = supprimer_timestamp($path);
528
-				// remove ?24px added by find_in_theme on .svg files
529
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
530
-			}
531
-			return file_exists($path);
532
-		};
533
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
534
-			$res = $filtre("<img src='$is_file' />", ...$args);
535
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
536
-			return $res;
537
-		}
538
-	}
539
-
540
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
541
-	if (
542
-		preg_match_all(
543
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
544
-			$texte,
545
-			$tags,
546
-			PREG_SET_ORDER
547
-		)
548
-	) {
549
-		foreach ($tags as $tag) {
550
-			$class = extraire_attribut($tag[3], 'class');
551
-			if (
552
-				!$class or
553
-				(strpos($class, 'filtre_inactif') === false
554
-					// compat historique a virer en 3.2
555
-					and strpos($class, 'no_image_filtrer') === false)
556
-			) {
557
-				if ($reduit = $filtre($tag[3], ...$args)) {
558
-					// En cas de span spip_documents, modifier le style=...width:
559
-					if ($tag[1]) {
560
-						$w = extraire_attribut($reduit, 'width');
561
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
562
-							$w = $regs[1];
563
-						}
564
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
565
-							$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
566
-							$replace = inserer_attribut($tag[1], 'style', $style);
567
-							$texte = str_replace($tag[1], $replace, $texte);
568
-						}
569
-					}
570
-					// traiter aussi un eventuel mouseover
571
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
572
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
573
-							$srcover = $match[1];
574
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
575
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
576
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
577
-						}
578
-					}
579
-					$texte = str_replace($tag[3], $reduit, $texte);
580
-				}
581
-			}
582
-		}
583
-	}
584
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
585
-	return $texte;
508
+    $filtre = array_shift($args); # enlever $filtre
509
+    $texte = array_shift($args);
510
+    if ($texte === null || !strlen($texte)) {
511
+        return '';
512
+    }
513
+    find_in_path('filtres_images_mini.php', 'inc/', true);
514
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
515
+    // Cas du nom de fichier local
516
+    $is_file = trim($texte);
517
+    if (
518
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
519
+          or strpbrk($is_file, "<>\n\r\t") !== false
520
+          or strpos($is_file, '/') === 0
521
+    ) {
522
+        $is_file = false;
523
+    }
524
+    if ($is_file) {
525
+        $is_local_file = function ($path) {
526
+            if (strpos($path, '?') !== false) {
527
+                $path = supprimer_timestamp($path);
528
+                // remove ?24px added by find_in_theme on .svg files
529
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
530
+            }
531
+            return file_exists($path);
532
+        };
533
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
534
+            $res = $filtre("<img src='$is_file' />", ...$args);
535
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
536
+            return $res;
537
+        }
538
+    }
539
+
540
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
541
+    if (
542
+        preg_match_all(
543
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
544
+            $texte,
545
+            $tags,
546
+            PREG_SET_ORDER
547
+        )
548
+    ) {
549
+        foreach ($tags as $tag) {
550
+            $class = extraire_attribut($tag[3], 'class');
551
+            if (
552
+                !$class or
553
+                (strpos($class, 'filtre_inactif') === false
554
+                    // compat historique a virer en 3.2
555
+                    and strpos($class, 'no_image_filtrer') === false)
556
+            ) {
557
+                if ($reduit = $filtre($tag[3], ...$args)) {
558
+                    // En cas de span spip_documents, modifier le style=...width:
559
+                    if ($tag[1]) {
560
+                        $w = extraire_attribut($reduit, 'width');
561
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
562
+                            $w = $regs[1];
563
+                        }
564
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
565
+                            $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
566
+                            $replace = inserer_attribut($tag[1], 'style', $style);
567
+                            $texte = str_replace($tag[1], $replace, $texte);
568
+                        }
569
+                    }
570
+                    // traiter aussi un eventuel mouseover
571
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
572
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
573
+                            $srcover = $match[1];
574
+                            $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
575
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
576
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
577
+                        }
578
+                    }
579
+                    $texte = str_replace($tag[3], $reduit, $texte);
580
+                }
581
+            }
582
+        }
583
+    }
584
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
585
+    return $texte;
586 586
 }
587 587
 
588 588
 /**
@@ -599,91 +599,91 @@  discard block
 block discarded – undo
599 599
  **/
600 600
 function infos_image($img, $force_refresh = false) {
601 601
 
602
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
603
-	$srcWidth = 0;
604
-	$srcHeight = 0;
605
-	$srcSize = null;
606
-
607
-	$src = extraire_attribut($img, 'src');
608
-
609
-	if (!$src) {
610
-		$src = $img;
611
-	} else {
612
-		$srcWidth = extraire_attribut($img, 'width');
613
-		$srcHeight = extraire_attribut($img, 'height');
614
-	}
615
-
616
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
617
-	// la copie locale a toutes les chances d'etre la ou de resservir
618
-	if (tester_url_absolue($src)) {
619
-		include_spip('inc/distant');
620
-		$fichier = copie_locale($src);
621
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
622
-	}
623
-	if (($p = strpos($src, '?')) !== false) {
624
-		$src = substr($src, 0, $p);
625
-	}
626
-
627
-	$imagesize = false;
628
-	if (isset($largeur_img[$src]) and !$force_refresh) {
629
-		$srcWidth = $largeur_img[$src];
630
-	}
631
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
632
-		$srcHeight = $hauteur_img[$src];
633
-	}
634
-	if (isset($poids_img[$src]) and !$force_refresh) {
635
-		$srcSize = $poids_img[$src];
636
-	}
637
-	if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
638
-		if (
639
-			file_exists($src)
640
-			and $imagesize = spip_getimagesize($src)
641
-		) {
642
-			if (!$srcWidth) {
643
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
644
-			}
645
-			if (!$srcHeight) {
646
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
647
-			}
648
-			if (!$srcSize) {
649
-				$poids_img[$src] = filesize($src);
650
-			}
651
-		}
652
-		elseif (strpos($src, '<svg') !== false) {
653
-			include_spip('inc/svg');
654
-			if ($attrs = svg_lire_attributs($src)) {
655
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
656
-				if (!$srcWidth) {
657
-					$largeur_img[$src] = $srcWidth = $width;
658
-				}
659
-				if (!$srcHeight) {
660
-					$hauteur_img[$src] = $srcHeight = $height;
661
-				}
662
-				if (!$srcSize) {
663
-					$poids_img[$src] = $srcSize = strlen($src);
664
-				}
665
-			}
666
-		}
667
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
668
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
669
-		elseif (
670
-			@file_exists($f = "$src.src")
671
-			and lire_fichier($f, $valeurs)
672
-			and $valeurs = unserialize($valeurs)
673
-		) {
674
-			if (!$srcWidth) {
675
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
676
-			}
677
-			if (!$srcHeight) {
678
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
679
-			}
680
-			if (!$srcSize) {
681
-				$poids_img[$src] = $srcSize = 0;
682
-			}
683
-		}
684
-	}
685
-
686
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
602
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
603
+    $srcWidth = 0;
604
+    $srcHeight = 0;
605
+    $srcSize = null;
606
+
607
+    $src = extraire_attribut($img, 'src');
608
+
609
+    if (!$src) {
610
+        $src = $img;
611
+    } else {
612
+        $srcWidth = extraire_attribut($img, 'width');
613
+        $srcHeight = extraire_attribut($img, 'height');
614
+    }
615
+
616
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
617
+    // la copie locale a toutes les chances d'etre la ou de resservir
618
+    if (tester_url_absolue($src)) {
619
+        include_spip('inc/distant');
620
+        $fichier = copie_locale($src);
621
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
622
+    }
623
+    if (($p = strpos($src, '?')) !== false) {
624
+        $src = substr($src, 0, $p);
625
+    }
626
+
627
+    $imagesize = false;
628
+    if (isset($largeur_img[$src]) and !$force_refresh) {
629
+        $srcWidth = $largeur_img[$src];
630
+    }
631
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
632
+        $srcHeight = $hauteur_img[$src];
633
+    }
634
+    if (isset($poids_img[$src]) and !$force_refresh) {
635
+        $srcSize = $poids_img[$src];
636
+    }
637
+    if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
638
+        if (
639
+            file_exists($src)
640
+            and $imagesize = spip_getimagesize($src)
641
+        ) {
642
+            if (!$srcWidth) {
643
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
644
+            }
645
+            if (!$srcHeight) {
646
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
647
+            }
648
+            if (!$srcSize) {
649
+                $poids_img[$src] = filesize($src);
650
+            }
651
+        }
652
+        elseif (strpos($src, '<svg') !== false) {
653
+            include_spip('inc/svg');
654
+            if ($attrs = svg_lire_attributs($src)) {
655
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
656
+                if (!$srcWidth) {
657
+                    $largeur_img[$src] = $srcWidth = $width;
658
+                }
659
+                if (!$srcHeight) {
660
+                    $hauteur_img[$src] = $srcHeight = $height;
661
+                }
662
+                if (!$srcSize) {
663
+                    $poids_img[$src] = $srcSize = strlen($src);
664
+                }
665
+            }
666
+        }
667
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
668
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
669
+        elseif (
670
+            @file_exists($f = "$src.src")
671
+            and lire_fichier($f, $valeurs)
672
+            and $valeurs = unserialize($valeurs)
673
+        ) {
674
+            if (!$srcWidth) {
675
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
676
+            }
677
+            if (!$srcHeight) {
678
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
679
+            }
680
+            if (!$srcSize) {
681
+                $poids_img[$src] = $srcSize = 0;
682
+            }
683
+        }
684
+    }
685
+
686
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
687 687
 }
688 688
 
689 689
 /**
@@ -699,13 +699,13 @@  discard block
 block discarded – undo
699 699
  *     poids
700 700
  **/
701 701
 function poids_image($img, $force_refresh = false) {
702
-	$infos = infos_image($img, $force_refresh);
703
-	return $infos['poids'];
702
+    $infos = infos_image($img, $force_refresh);
703
+    return $infos['poids'];
704 704
 }
705 705
 
706 706
 function taille_image($img, $force_refresh = false) {
707
-	$infos = infos_image($img, $force_refresh);
708
-	return [$infos['hauteur'], $infos['largeur']];
707
+    $infos = infos_image($img, $force_refresh);
708
+    return [$infos['hauteur'], $infos['largeur']];
709 709
 }
710 710
 
711 711
 /**
@@ -722,12 +722,12 @@  discard block
 block discarded – undo
722 722
  *     Largeur en pixels, NULL ou 0 si aucune image.
723 723
  **/
724 724
 function largeur($img) {
725
-	if (!$img) {
726
-		return;
727
-	}
728
-	[$h, $l] = taille_image($img);
725
+    if (!$img) {
726
+        return;
727
+    }
728
+    [$h, $l] = taille_image($img);
729 729
 
730
-	return $l;
730
+    return $l;
731 731
 }
732 732
 
733 733
 /**
@@ -744,12 +744,12 @@  discard block
 block discarded – undo
744 744
  *     Hauteur en pixels, NULL ou 0 si aucune image.
745 745
  **/
746 746
 function hauteur($img) {
747
-	if (!$img) {
748
-		return;
749
-	}
750
-	[$h, $l] = taille_image($img);
747
+    if (!$img) {
748
+        return;
749
+    }
750
+    [$h, $l] = taille_image($img);
751 751
 
752
-	return $h;
752
+    return $h;
753 753
 }
754 754
 
755 755
 
@@ -769,11 +769,11 @@  discard block
 block discarded – undo
769 769
  * @return string
770 770
  **/
771 771
 function corriger_entites_html($texte) {
772
-	if (strpos($texte, '&amp;') === false) {
773
-		return $texte;
774
-	}
772
+    if (strpos($texte, '&amp;') === false) {
773
+        return $texte;
774
+    }
775 775
 
776
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
776
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
777 777
 }
778 778
 
779 779
 /**
@@ -788,11 +788,11 @@  discard block
 block discarded – undo
788 788
  * @return string
789 789
  **/
790 790
 function corriger_toutes_entites_html($texte) {
791
-	if (strpos($texte, '&amp;') === false) {
792
-		return $texte;
793
-	}
791
+    if (strpos($texte, '&amp;') === false) {
792
+        return $texte;
793
+    }
794 794
 
795
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
795
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
796 796
 }
797 797
 
798 798
 /**
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
  * @return string
803 803
  **/
804 804
 function proteger_amp($texte) {
805
-	return str_replace('&', '&amp;', $texte);
805
+    return str_replace('&', '&amp;', $texte);
806 806
 }
807 807
 
808 808
 
@@ -833,21 +833,21 @@  discard block
 block discarded – undo
833 833
  * @return mixed|string
834 834
  */
835 835
 function entites_html($texte, $tout = false, $quote = true) {
836
-	if (
837
-		!is_string($texte) or !$texte
838
-		or strpbrk($texte, "&\"'<>") == false
839
-	) {
840
-		return $texte;
841
-	}
842
-	include_spip('inc/texte');
843
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
844
-	$flags |= ENT_HTML401;
845
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
846
-	if ($tout) {
847
-		return corriger_toutes_entites_html($texte);
848
-	} else {
849
-		return corriger_entites_html($texte);
850
-	}
836
+    if (
837
+        !is_string($texte) or !$texte
838
+        or strpbrk($texte, "&\"'<>") == false
839
+    ) {
840
+        return $texte;
841
+    }
842
+    include_spip('inc/texte');
843
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
844
+    $flags |= ENT_HTML401;
845
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
846
+    if ($tout) {
847
+        return corriger_toutes_entites_html($texte);
848
+    } else {
849
+        return corriger_entites_html($texte);
850
+    }
851 851
 }
852 852
 
853 853
 /**
@@ -866,38 +866,38 @@  discard block
 block discarded – undo
866 866
  *     Texte converti
867 867
  **/
868 868
 function filtrer_entites(?string $texte): string {
869
-	$texte ??= '';
870
-	if (strpos($texte, '&') === false) {
871
-		return $texte;
872
-	}
873
-	// filtrer
874
-	$texte = html2unicode($texte);
875
-	// remettre le tout dans le charset cible
876
-	$texte = unicode2charset($texte);
877
-	// cas particulier des " et ' qu'il faut filtrer aussi
878
-	// (on le faisait deja avec un &quot;)
879
-	if (strpos($texte, '&#') !== false) {
880
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
881
-	}
869
+    $texte ??= '';
870
+    if (strpos($texte, '&') === false) {
871
+        return $texte;
872
+    }
873
+    // filtrer
874
+    $texte = html2unicode($texte);
875
+    // remettre le tout dans le charset cible
876
+    $texte = unicode2charset($texte);
877
+    // cas particulier des " et ' qu'il faut filtrer aussi
878
+    // (on le faisait deja avec un &quot;)
879
+    if (strpos($texte, '&#') !== false) {
880
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
881
+    }
882 882
 
883
-	return $texte;
883
+    return $texte;
884 884
 }
885 885
 
886 886
 
887 887
 if (!function_exists('filtre_filtrer_entites_dist')) {
888
-	/**
889
-	 * Version sécurisée de filtrer_entites
890
-	 *
891
-	 * @uses interdire_scripts()
892
-	 * @uses filtrer_entites()
893
-	 *
894
-	 * @param string $t
895
-	 * @return string
896
-	 */
897
-	function filtre_filtrer_entites_dist($t) {
898
-		include_spip('inc/texte');
899
-		return interdire_scripts(filtrer_entites($t));
900
-	}
888
+    /**
889
+     * Version sécurisée de filtrer_entites
890
+     *
891
+     * @uses interdire_scripts()
892
+     * @uses filtrer_entites()
893
+     *
894
+     * @param string $t
895
+     * @return string
896
+     */
897
+    function filtre_filtrer_entites_dist($t) {
898
+        include_spip('inc/texte');
899
+        return interdire_scripts(filtrer_entites($t));
900
+    }
901 901
 }
902 902
 
903 903
 
@@ -912,18 +912,18 @@  discard block
 block discarded – undo
912 912
  * @return string|array
913 913
  **/
914 914
 function supprimer_caracteres_illegaux($texte) {
915
-	static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
916
-	static $to = null;
915
+    static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F";
916
+    static $to = null;
917 917
 
918
-	if (is_array($texte)) {
919
-		return array_map('supprimer_caracteres_illegaux', $texte);
920
-	}
918
+    if (is_array($texte)) {
919
+        return array_map('supprimer_caracteres_illegaux', $texte);
920
+    }
921 921
 
922
-	if (!$to) {
923
-		$to = str_repeat('-', strlen($from));
924
-	}
922
+    if (!$to) {
923
+        $to = str_repeat('-', strlen($from));
924
+    }
925 925
 
926
-	return strtr($texte, $from, $to);
926
+    return strtr($texte, $from, $to);
927 927
 }
928 928
 
929 929
 /**
@@ -935,10 +935,10 @@  discard block
 block discarded – undo
935 935
  * @return string|array
936 936
  **/
937 937
 function corriger_caracteres($texte) {
938
-	$texte = corriger_caracteres_windows($texte);
939
-	$texte = supprimer_caracteres_illegaux($texte);
938
+    $texte = corriger_caracteres_windows($texte);
939
+    $texte = supprimer_caracteres_illegaux($texte);
940 940
 
941
-	return $texte;
941
+    return $texte;
942 942
 }
943 943
 
944 944
 /**
@@ -955,44 +955,44 @@  discard block
 block discarded – undo
955 955
  *     Texte encodé pour XML
956 956
  */
957 957
 function texte_backend(string $texte): string {
958
-	if ($texte === '') {
959
-		return '';
960
-	}
958
+    if ($texte === '') {
959
+        return '';
960
+    }
961 961
 
962
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
962
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
963 963
 
964
-	// si on a des liens ou des images, les passer en absolu
965
-	$texte = liens_absolus($texte);
964
+    // si on a des liens ou des images, les passer en absolu
965
+    $texte = liens_absolus($texte);
966 966
 
967
-	// echapper les tags &gt; &lt;
968
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
967
+    // echapper les tags &gt; &lt;
968
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
969 969
 
970
-	// importer les &eacute;
971
-	$texte = filtrer_entites($texte);
970
+    // importer les &eacute;
971
+    $texte = filtrer_entites($texte);
972 972
 
973
-	// " -> &quot; et tout ce genre de choses
974
-	$u = $GLOBALS['meta']['pcre_u'];
975
-	$texte = str_replace('&nbsp;', ' ', $texte);
976
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
977
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
978
-	$texte = entites_html($texte, false, false);
979
-	// mais bien echapper les double quotes !
980
-	$texte = str_replace('"', '&#034;', $texte);
973
+    // " -> &quot; et tout ce genre de choses
974
+    $u = $GLOBALS['meta']['pcre_u'];
975
+    $texte = str_replace('&nbsp;', ' ', $texte);
976
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
977
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
978
+    $texte = entites_html($texte, false, false);
979
+    // mais bien echapper les double quotes !
980
+    $texte = str_replace('"', '&#034;', $texte);
981 981
 
982
-	// verifier le charset
983
-	$texte = charset2unicode($texte);
982
+    // verifier le charset
983
+    $texte = charset2unicode($texte);
984 984
 
985
-	// Caracteres problematiques en iso-latin 1
986
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
987
-		$texte = str_replace(chr(156), '&#156;', $texte);
988
-		$texte = str_replace(chr(140), '&#140;', $texte);
989
-		$texte = str_replace(chr(159), '&#159;', $texte);
990
-	}
985
+    // Caracteres problematiques en iso-latin 1
986
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
987
+        $texte = str_replace(chr(156), '&#156;', $texte);
988
+        $texte = str_replace(chr(140), '&#140;', $texte);
989
+        $texte = str_replace(chr(159), '&#159;', $texte);
990
+    }
991 991
 
992
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
993
-	// et le caractere apostrophe alourdit les squelettes avec PHP
994
-	// ==> on les remplace par l'entite HTML
995
-	return str_replace($apostrophe, "'", $texte);
992
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
993
+    // et le caractere apostrophe alourdit les squelettes avec PHP
994
+    // ==> on les remplace par l'entite HTML
995
+    return str_replace($apostrophe, "'", $texte);
996 996
 }
997 997
 
998 998
 /**
@@ -1009,7 +1009,7 @@  discard block
 block discarded – undo
1009 1009
  *     Texte encodé et quote pour XML
1010 1010
  */
1011 1011
 function texte_backendq(string $texte): string {
1012
-	return addslashes(texte_backend($texte));
1012
+    return addslashes(texte_backend($texte));
1013 1013
 }
1014 1014
 
1015 1015
 
@@ -1032,11 +1032,11 @@  discard block
 block discarded – undo
1032 1032
  *     Numéro de titre, sinon chaîne vide
1033 1033
  **/
1034 1034
 function supprimer_numero($texte) {
1035
-	return preg_replace(
1036
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1037
-		'',
1038
-		$texte
1039
-	);
1035
+    return preg_replace(
1036
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1037
+        '',
1038
+        $texte
1039
+    );
1040 1040
 }
1041 1041
 
1042 1042
 /**
@@ -1059,18 +1059,18 @@  discard block
 block discarded – undo
1059 1059
  *     Numéro de titre, sinon chaîne vide
1060 1060
  **/
1061 1061
 function recuperer_numero($texte) {
1062
-	if (
1063
-		$texte and
1064
-		preg_match(
1065
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1066
-			$texte,
1067
-			$regs
1068
-		)
1069
-	) {
1070
-		return strval($regs[1]);
1071
-	} else {
1072
-		return '';
1073
-	}
1062
+    if (
1063
+        $texte and
1064
+        preg_match(
1065
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1066
+            $texte,
1067
+            $regs
1068
+        )
1069
+    ) {
1070
+        return strval($regs[1]);
1071
+    } else {
1072
+        return '';
1073
+    }
1074 1074
 }
1075 1075
 
1076 1076
 /**
@@ -1097,16 +1097,16 @@  discard block
 block discarded – undo
1097 1097
  *     Texte ou tableau de textes converti
1098 1098
  **/
1099 1099
 function supprimer_tags($texte, $rempl = '') {
1100
-	if ($texte === null) {
1101
-		return '';
1102
-	}
1103
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1104
-	// ne pas oublier un < final non ferme car coupe
1105
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1106
-	// mais qui peut aussi etre un simple signe plus petit que
1107
-	$texte = str_replace('<', '&lt;', $texte);
1100
+    if ($texte === null) {
1101
+        return '';
1102
+    }
1103
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1104
+    // ne pas oublier un < final non ferme car coupe
1105
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1106
+    // mais qui peut aussi etre un simple signe plus petit que
1107
+    $texte = str_replace('<', '&lt;', $texte);
1108 1108
 
1109
-	return $texte;
1109
+    return $texte;
1110 1110
 }
1111 1111
 
1112 1112
 /**
@@ -1129,9 +1129,9 @@  discard block
 block discarded – undo
1129 1129
  *     Texte converti
1130 1130
  **/
1131 1131
 function echapper_tags($texte, $rempl = '') {
1132
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1132
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1133 1133
 
1134
-	return $texte;
1134
+    return $texte;
1135 1135
 }
1136 1136
 
1137 1137
 /**
@@ -1152,18 +1152,18 @@  discard block
 block discarded – undo
1152 1152
  *     Texte converti
1153 1153
  **/
1154 1154
 function textebrut($texte) {
1155
-	$u = $GLOBALS['meta']['pcre_u'];
1156
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1157
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1158
-	$texte = preg_replace("/^\n+/", '', $texte);
1159
-	$texte = preg_replace("/\n+$/", '', $texte);
1160
-	$texte = preg_replace("/\n +/", "\n", $texte);
1161
-	$texte = supprimer_tags($texte);
1162
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1163
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1164
-	$texte = str_replace('&#8217;', "'", $texte);
1155
+    $u = $GLOBALS['meta']['pcre_u'];
1156
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1157
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1158
+    $texte = preg_replace("/^\n+/", '', $texte);
1159
+    $texte = preg_replace("/\n+$/", '', $texte);
1160
+    $texte = preg_replace("/\n +/", "\n", $texte);
1161
+    $texte = supprimer_tags($texte);
1162
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1163
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1164
+    $texte = str_replace('&#8217;', "'", $texte);
1165 1165
 
1166
-	return $texte;
1166
+    return $texte;
1167 1167
 }
1168 1168
 
1169 1169
 
@@ -1179,23 +1179,23 @@  discard block
 block discarded – undo
1179 1179
  *     Texte avec liens ouvrants
1180 1180
  **/
1181 1181
 function liens_ouvrants($texte) {
1182
-	if (
1183
-		preg_match_all(
1184
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1185
-			$texte,
1186
-			$liens,
1187
-			PREG_PATTERN_ORDER
1188
-		)
1189
-	) {
1190
-		foreach ($liens[0] as $a) {
1191
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1192
-			$ablank = inserer_attribut($a, 'rel', $rel);
1193
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1194
-			$texte = str_replace($a, $ablank, $texte);
1195
-		}
1196
-	}
1197
-
1198
-	return $texte;
1182
+    if (
1183
+        preg_match_all(
1184
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1185
+            $texte,
1186
+            $liens,
1187
+            PREG_PATTERN_ORDER
1188
+        )
1189
+    ) {
1190
+        foreach ($liens[0] as $a) {
1191
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1192
+            $ablank = inserer_attribut($a, 'rel', $rel);
1193
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1194
+            $texte = str_replace($a, $ablank, $texte);
1195
+        }
1196
+    }
1197
+
1198
+    return $texte;
1199 1199
 }
1200 1200
 
1201 1201
 /**
@@ -1205,22 +1205,22 @@  discard block
 block discarded – undo
1205 1205
  * @return string
1206 1206
  */
1207 1207
 function liens_nofollow($texte) {
1208
-	if (stripos($texte, '<a') === false) {
1209
-		return $texte;
1210
-	}
1208
+    if (stripos($texte, '<a') === false) {
1209
+        return $texte;
1210
+    }
1211 1211
 
1212
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1213
-		foreach ($regs[0] as $a) {
1214
-			$rel = extraire_attribut($a, 'rel') ?? '';
1215
-			if (strpos($rel, 'nofollow') === false) {
1216
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1217
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1218
-				$texte = str_replace($a, $anofollow, $texte);
1219
-			}
1220
-		}
1221
-	}
1212
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1213
+        foreach ($regs[0] as $a) {
1214
+            $rel = extraire_attribut($a, 'rel') ?? '';
1215
+            if (strpos($rel, 'nofollow') === false) {
1216
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1217
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1218
+                $texte = str_replace($a, $anofollow, $texte);
1219
+            }
1220
+        }
1221
+    }
1222 1222
 
1223
-	return $texte;
1223
+    return $texte;
1224 1224
 }
1225 1225
 
1226 1226
 /**
@@ -1239,12 +1239,12 @@  discard block
 block discarded – undo
1239 1239
  *     Texte sans paraghaphes
1240 1240
  **/
1241 1241
 function PtoBR($texte) {
1242
-	$u = $GLOBALS['meta']['pcre_u'];
1243
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1244
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1245
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1242
+    $u = $GLOBALS['meta']['pcre_u'];
1243
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1244
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1245
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1246 1246
 
1247
-	return $texte;
1247
+    return $texte;
1248 1248
 }
1249 1249
 
1250 1250
 
@@ -1269,14 +1269,14 @@  discard block
 block discarded – undo
1269 1269
  * @return string Texte encadré du style CSS
1270 1270
  */
1271 1271
 function lignes_longues($texte) {
1272
-	if (!strlen(trim($texte))) {
1273
-		return $texte;
1274
-	}
1275
-	include_spip('inc/texte');
1276
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1277
-		'div' : 'span';
1272
+    if (!strlen(trim($texte))) {
1273
+        return $texte;
1274
+    }
1275
+    include_spip('inc/texte');
1276
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1277
+        'div' : 'span';
1278 1278
 
1279
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1279
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1280 1280
 }
1281 1281
 
1282 1282
 /**
@@ -1295,30 +1295,30 @@  discard block
 block discarded – undo
1295 1295
  * @return string Texte en majuscule
1296 1296
  */
1297 1297
 function majuscules($texte) {
1298
-	if (!strlen($texte)) {
1299
-		return '';
1300
-	}
1298
+    if (!strlen($texte)) {
1299
+        return '';
1300
+    }
1301 1301
 
1302
-	// Cas du turc
1303
-	if ($GLOBALS['spip_lang'] == 'tr') {
1304
-		# remplacer hors des tags et des entites
1305
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1306
-			foreach ($regs as $n => $match) {
1307
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1308
-			}
1309
-		}
1302
+    // Cas du turc
1303
+    if ($GLOBALS['spip_lang'] == 'tr') {
1304
+        # remplacer hors des tags et des entites
1305
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1306
+            foreach ($regs as $n => $match) {
1307
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1308
+            }
1309
+        }
1310 1310
 
1311
-		$texte = str_replace('i', '&#304;', $texte);
1311
+        $texte = str_replace('i', '&#304;', $texte);
1312 1312
 
1313
-		if ($regs) {
1314
-			foreach ($regs as $n => $match) {
1315
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1316
-			}
1317
-		}
1318
-	}
1313
+        if ($regs) {
1314
+            foreach ($regs as $n => $match) {
1315
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1316
+            }
1317
+        }
1318
+    }
1319 1319
 
1320
-	// Cas general
1321
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1320
+    // Cas general
1321
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1322 1322
 }
1323 1323
 
1324 1324
 /**
@@ -1336,29 +1336,29 @@  discard block
 block discarded – undo
1336 1336
  * @return string
1337 1337
  **/
1338 1338
 function taille_en_octets($taille) {
1339
-	if (!defined('_KILOBYTE')) {
1340
-		/**
1341
-		 * Définit le nombre d'octets dans un Kilobyte
1342
-		 *
1343
-		 * @var int
1344
-		 **/
1345
-		define('_KILOBYTE', 1024);
1346
-	}
1339
+    if (!defined('_KILOBYTE')) {
1340
+        /**
1341
+         * Définit le nombre d'octets dans un Kilobyte
1342
+         *
1343
+         * @var int
1344
+         **/
1345
+        define('_KILOBYTE', 1024);
1346
+    }
1347 1347
 
1348
-	if ($taille < 1) {
1349
-		return '';
1350
-	}
1351
-	if ($taille < _KILOBYTE) {
1352
-		$taille = _T('taille_octets', ['taille' => $taille]);
1353
-	} elseif ($taille < _KILOBYTE * _KILOBYTE) {
1354
-		$taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1355
-	} elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1356
-		$taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1357
-	} else {
1358
-		$taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1359
-	}
1348
+    if ($taille < 1) {
1349
+        return '';
1350
+    }
1351
+    if ($taille < _KILOBYTE) {
1352
+        $taille = _T('taille_octets', ['taille' => $taille]);
1353
+    } elseif ($taille < _KILOBYTE * _KILOBYTE) {
1354
+        $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]);
1355
+    } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) {
1356
+        $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]);
1357
+    } else {
1358
+        $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]);
1359
+    }
1360 1360
 
1361
-	return $taille;
1361
+    return $taille;
1362 1362
 }
1363 1363
 
1364 1364
 
@@ -1380,21 +1380,21 @@  discard block
 block discarded – undo
1380 1380
  *     Texte prêt pour être utilisé en attribut HTML
1381 1381
  **/
1382 1382
 function attribut_html(?string $texte, $textebrut = true): string {
1383
-	if ($texte === null) {
1384
-		return '';
1385
-	}
1386
-	$u = $GLOBALS['meta']['pcre_u'];
1387
-	if ($textebrut) {
1388
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1389
-	}
1390
-	$texte = texte_backend($texte);
1391
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1383
+    if ($texte === null) {
1384
+        return '';
1385
+    }
1386
+    $u = $GLOBALS['meta']['pcre_u'];
1387
+    if ($textebrut) {
1388
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1389
+    }
1390
+    $texte = texte_backend($texte);
1391
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1392 1392
 
1393
-	return preg_replace(
1394
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1395
-		['&', '&#38;'],
1396
-		$texte
1397
-	);
1393
+    return preg_replace(
1394
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1395
+        ['&', '&#38;'],
1396
+        $texte
1397
+    );
1398 1398
 }
1399 1399
 
1400 1400
 
@@ -1414,15 +1414,15 @@  discard block
 block discarded – undo
1414 1414
  *     URL ou chaîne vide
1415 1415
  **/
1416 1416
 function vider_url(?string $url, $entites = true): string {
1417
-	if ($url === null) {
1418
-		return '';
1419
-	}
1420
-	# un message pour abs_url
1421
-	$GLOBALS['mode_abs_url'] = 'url';
1422
-	$url = trim($url);
1423
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1417
+    if ($url === null) {
1418
+        return '';
1419
+    }
1420
+    # un message pour abs_url
1421
+    $GLOBALS['mode_abs_url'] = 'url';
1422
+    $url = trim($url);
1423
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1424 1424
 
1425
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1425
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1426 1426
 }
1427 1427
 
1428 1428
 
@@ -1437,10 +1437,10 @@  discard block
 block discarded – undo
1437 1437
  * @return string Adresse email maquillée
1438 1438
  **/
1439 1439
 function antispam($texte) {
1440
-	include_spip('inc/acces');
1441
-	$masque = creer_pass_aleatoire(3);
1440
+    include_spip('inc/acces');
1441
+    $masque = creer_pass_aleatoire(3);
1442 1442
 
1443
-	return preg_replace('/@/', " $masque ", $texte);
1443
+    return preg_replace('/@/', " $masque ", $texte);
1444 1444
 }
1445 1445
 
1446 1446
 /**
@@ -1472,8 +1472,8 @@  discard block
 block discarded – undo
1472 1472
  *     True si on a le droit d'accès, false sinon.
1473 1473
  **/
1474 1474
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1475
-	include_spip('inc/acces');
1476
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1475
+    include_spip('inc/acces');
1476
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1477 1477
 }
1478 1478
 
1479 1479
 /**
@@ -1498,13 +1498,13 @@  discard block
 block discarded – undo
1498 1498
  *     Retourne $texte, sinon $sinon.
1499 1499
  **/
1500 1500
 function sinon($texte, $sinon = '') {
1501
-	if ($texte) {
1502
-		return $texte;
1503
-	} elseif (is_scalar($texte) and strlen($texte)) {
1504
-		return $texte;
1505
-	} else {
1506
-		return $sinon;
1507
-	}
1501
+    if ($texte) {
1502
+        return $texte;
1503
+    } elseif (is_scalar($texte) and strlen($texte)) {
1504
+        return $texte;
1505
+    } else {
1506
+        return $sinon;
1507
+    }
1508 1508
 }
1509 1509
 
1510 1510
 /**
@@ -1528,7 +1528,7 @@  discard block
 block discarded – undo
1528 1528
  * @return mixed
1529 1529
  **/
1530 1530
 function choixsivide($a, $vide, $pasvide) {
1531
-	return $a ? $pasvide : $vide;
1531
+    return $a ? $pasvide : $vide;
1532 1532
 }
1533 1533
 
1534 1534
 /**
@@ -1552,7 +1552,7 @@  discard block
 block discarded – undo
1552 1552
  * @return mixed
1553 1553
  **/
1554 1554
 function choixsiegal($a1, $a2, $v, $f) {
1555
-	return ($a1 == $a2) ? $v : $f;
1555
+    return ($a1 == $a2) ? $v : $f;
1556 1556
 }
1557 1557
 
1558 1558
 //
@@ -1571,13 +1571,13 @@  discard block
 block discarded – undo
1571 1571
  * @return string
1572 1572
  **/
1573 1573
 function filtrer_ical($texte) {
1574
-	#include_spip('inc/charsets');
1575
-	$texte = html2unicode($texte);
1576
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1577
-	$texte = preg_replace("/\n/", ' ', $texte);
1578
-	$texte = preg_replace('/,/', '\,', $texte);
1574
+    #include_spip('inc/charsets');
1575
+    $texte = html2unicode($texte);
1576
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1577
+    $texte = preg_replace("/\n/", ' ', $texte);
1578
+    $texte = preg_replace('/,/', '\,', $texte);
1579 1579
 
1580
-	return $texte;
1580
+    return $texte;
1581 1581
 }
1582 1582
 
1583 1583
 
@@ -1602,58 +1602,58 @@  discard block
 block discarded – undo
1602 1602
  * @return string
1603 1603
  **/
1604 1604
 function post_autobr($texte, $delim = "\n_ ") {
1605
-	if (!function_exists('echappe_html')) {
1606
-		include_spip('inc/texte_mini');
1607
-	}
1608
-	$texte = str_replace("\r\n", "\r", $texte);
1609
-	$texte = str_replace("\r", "\n", $texte);
1610
-
1611
-	if (preg_match(",\n+$,", $texte, $fin)) {
1612
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1613
-	} else {
1614
-		$fin = '';
1615
-	}
1616
-
1617
-	$texte = echappe_html($texte, '', true);
1618
-
1619
-	// echapper les modeles
1620
-	$collecteurModeles = null;
1621
-	if (strpos($texte, '<') !== false) {
1622
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1623
-		include_spip("src/Texte/Collecteur/Modeles");
1624
-		$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1625
-		$texte = $collecteurModeles->echapper($texte);
1626
-	}
1627
-
1628
-	$debut = '';
1629
-	$suite = $texte;
1630
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1631
-		$debut .= substr($suite, 0, $t - 1);
1632
-		$suite = substr($suite, $t);
1633
-		$car = substr($suite, 0, 1);
1634
-		if (
1635
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1636
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1637
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1638
-		) {
1639
-			$debut .= $delim;
1640
-		} else {
1641
-			$debut .= "\n";
1642
-		}
1643
-		if (preg_match(",^\n+,", $suite, $regs)) {
1644
-			$debut .= $regs[0];
1645
-			$suite = substr($suite, strlen($regs[0]));
1646
-		}
1647
-	}
1648
-	$texte = $debut . $suite;
1649
-
1650
-	if ($collecteurModeles) {
1651
-		$texte = $collecteurModeles->retablir($texte);
1652
-	}
1653
-
1654
-	$texte = echappe_retour($texte);
1655
-
1656
-	return $texte . $fin;
1605
+    if (!function_exists('echappe_html')) {
1606
+        include_spip('inc/texte_mini');
1607
+    }
1608
+    $texte = str_replace("\r\n", "\r", $texte);
1609
+    $texte = str_replace("\r", "\n", $texte);
1610
+
1611
+    if (preg_match(",\n+$,", $texte, $fin)) {
1612
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1613
+    } else {
1614
+        $fin = '';
1615
+    }
1616
+
1617
+    $texte = echappe_html($texte, '', true);
1618
+
1619
+    // echapper les modeles
1620
+    $collecteurModeles = null;
1621
+    if (strpos($texte, '<') !== false) {
1622
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1623
+        include_spip("src/Texte/Collecteur/Modeles");
1624
+        $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1625
+        $texte = $collecteurModeles->echapper($texte);
1626
+    }
1627
+
1628
+    $debut = '';
1629
+    $suite = $texte;
1630
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1631
+        $debut .= substr($suite, 0, $t - 1);
1632
+        $suite = substr($suite, $t);
1633
+        $car = substr($suite, 0, 1);
1634
+        if (
1635
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1636
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1637
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1638
+        ) {
1639
+            $debut .= $delim;
1640
+        } else {
1641
+            $debut .= "\n";
1642
+        }
1643
+        if (preg_match(",^\n+,", $suite, $regs)) {
1644
+            $debut .= $regs[0];
1645
+            $suite = substr($suite, strlen($regs[0]));
1646
+        }
1647
+    }
1648
+    $texte = $debut . $suite;
1649
+
1650
+    if ($collecteurModeles) {
1651
+        $texte = $collecteurModeles->retablir($texte);
1652
+    }
1653
+
1654
+    $texte = echappe_retour($texte);
1655
+
1656
+    return $texte . $fin;
1657 1657
 }
1658 1658
 
1659 1659
 
@@ -1688,30 +1688,30 @@  discard block
 block discarded – undo
1688 1688
  **/
1689 1689
 function extraire_idiome($letexte, $lang = null, $options = []) {
1690 1690
 
1691
-	if (
1692
-		$letexte
1693
-		and strpos($letexte, '<:') !== false
1694
-	) {
1695
-		if (!$lang) {
1696
-			$lang = $GLOBALS['spip_lang'];
1697
-		}
1698
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1699
-		if (is_bool($options)) {
1700
-			$options = ['echappe_span' => $options];
1701
-		}
1702
-		if (!isset($options['echappe_span'])) {
1703
-			$options = array_merge($options, ['echappe_span' => false]);
1704
-		}
1705
-		$options['lang'] = $lang;
1691
+    if (
1692
+        $letexte
1693
+        and strpos($letexte, '<:') !== false
1694
+    ) {
1695
+        if (!$lang) {
1696
+            $lang = $GLOBALS['spip_lang'];
1697
+        }
1698
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1699
+        if (is_bool($options)) {
1700
+            $options = ['echappe_span' => $options];
1701
+        }
1702
+        if (!isset($options['echappe_span'])) {
1703
+            $options = array_merge($options, ['echappe_span' => false]);
1704
+        }
1705
+        $options['lang'] = $lang;
1706 1706
 
1707
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1708
-		include_spip("src/Texte/Collecteur/Idiomes");
1709
-		$collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1707
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1708
+        include_spip("src/Texte/Collecteur/Idiomes");
1709
+        $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1710 1710
 
1711
-		$letexte = $collecteurIdiomes->traiter($letexte, $options);
1711
+        $letexte = $collecteurIdiomes->traiter($letexte, $options);
1712 1712
 
1713
-	}
1714
-	return $letexte;
1713
+    }
1714
+    return $letexte;
1715 1715
 }
1716 1716
 
1717 1717
 /**
@@ -1749,34 +1749,34 @@  discard block
 block discarded – undo
1749 1749
  **/
1750 1750
 function extraire_multi($letexte, $lang = null, $options = []) {
1751 1751
 
1752
-	if (
1753
-		$letexte
1754
-		and stripos($letexte, '<multi') !== false
1755
-	) {
1756
-		if (!$lang) {
1757
-			$lang = $GLOBALS['spip_lang'];
1758
-		}
1752
+    if (
1753
+        $letexte
1754
+        and stripos($letexte, '<multi') !== false
1755
+    ) {
1756
+        if (!$lang) {
1757
+            $lang = $GLOBALS['spip_lang'];
1758
+        }
1759 1759
 
1760
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1761
-		if (is_bool($options)) {
1762
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1763
-		}
1764
-		if (!isset($options['echappe_span'])) {
1765
-			$options = array_merge($options, ['echappe_span' => false]);
1766
-		}
1767
-		if (!isset($options['lang_defaut'])) {
1768
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1769
-		}
1770
-		$options['lang'] = $lang;
1760
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1761
+        if (is_bool($options)) {
1762
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1763
+        }
1764
+        if (!isset($options['echappe_span'])) {
1765
+            $options = array_merge($options, ['echappe_span' => false]);
1766
+        }
1767
+        if (!isset($options['lang_defaut'])) {
1768
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1769
+        }
1770
+        $options['lang'] = $lang;
1771 1771
 
1772
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1773
-		include_spip("src/Texte/Collecteur/Multis");
1774
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
1772
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1773
+        include_spip("src/Texte/Collecteur/Multis");
1774
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
1775 1775
 
1776
-		$letexte = $collecteurMultis->traiter($letexte, $options);
1777
-	}
1776
+        $letexte = $collecteurMultis->traiter($letexte, $options);
1777
+    }
1778 1778
 
1779
-	return $letexte;
1779
+    return $letexte;
1780 1780
 }
1781 1781
 
1782 1782
 /**
@@ -1786,7 +1786,7 @@  discard block
 block discarded – undo
1786 1786
  * @return string L'initiale en majuscule
1787 1787
  */
1788 1788
 function filtre_initiale($nom) {
1789
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1789
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1790 1790
 }
1791 1791
 
1792 1792
 
@@ -1831,33 +1831,33 @@  discard block
 block discarded – undo
1831 1831
  *      - null (interne) : si on empile
1832 1832
  **/
1833 1833
 function unique($donnee, $famille = '', $cpt = false) {
1834
-	static $mem = [];
1835
-	// permettre de vider la pile et de la restaurer
1836
-	// pour le calcul de introduction...
1837
-	if ($famille == '_spip_raz_') {
1838
-		$tmp = $mem;
1839
-		$mem = [];
1840
-
1841
-		return $tmp;
1842
-	} elseif ($famille == '_spip_set_') {
1843
-		$mem = $donnee;
1844
-
1845
-		return;
1846
-	}
1847
-	// eviter une notice
1848
-	if (!isset($mem[$famille])) {
1849
-		$mem[$famille] = [];
1850
-	}
1851
-	if ($cpt) {
1852
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1853
-	}
1854
-	// eviter une notice
1855
-	if (!isset($mem[$famille][$donnee])) {
1856
-		$mem[$famille][$donnee] = 0;
1857
-	}
1858
-	if (!($mem[$famille][$donnee]++)) {
1859
-		return $donnee;
1860
-	}
1834
+    static $mem = [];
1835
+    // permettre de vider la pile et de la restaurer
1836
+    // pour le calcul de introduction...
1837
+    if ($famille == '_spip_raz_') {
1838
+        $tmp = $mem;
1839
+        $mem = [];
1840
+
1841
+        return $tmp;
1842
+    } elseif ($famille == '_spip_set_') {
1843
+        $mem = $donnee;
1844
+
1845
+        return;
1846
+    }
1847
+    // eviter une notice
1848
+    if (!isset($mem[$famille])) {
1849
+        $mem[$famille] = [];
1850
+    }
1851
+    if ($cpt) {
1852
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1853
+    }
1854
+    // eviter une notice
1855
+    if (!isset($mem[$famille][$donnee])) {
1856
+        $mem[$famille][$donnee] = 0;
1857
+    }
1858
+    if (!($mem[$famille][$donnee]++)) {
1859
+        return $donnee;
1860
+    }
1861 1861
 }
1862 1862
 
1863 1863
 
@@ -1887,20 +1887,20 @@  discard block
 block discarded – undo
1887 1887
  *     Une des valeurs en fonction du compteur.
1888 1888
  **/
1889 1889
 function alterner($i, ...$args) {
1890
-	// recuperer les arguments (attention fonctions un peu space)
1891
-	$num = count($args);
1890
+    // recuperer les arguments (attention fonctions un peu space)
1891
+    $num = count($args);
1892 1892
 
1893
-	if ($num === 1 && is_array($args[0])) {
1894
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1895
-		$args = array_values($args[0]);
1896
-		$num = count($args);
1897
-	}
1893
+    if ($num === 1 && is_array($args[0])) {
1894
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1895
+        $args = array_values($args[0]);
1896
+        $num = count($args);
1897
+    }
1898 1898
 
1899
-	// un index compris entre 0 et num exclus
1900
-	$i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1901
-	$i = ($i + $num) % $num; // dans [0;$num[
1902
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1903
-	return $args[$i];
1899
+    // un index compris entre 0 et num exclus
1900
+    $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1901
+    $i = ($i + $num) % $num; // dans [0;$num[
1902
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1903
+    return $args[$i];
1904 1904
 }
1905 1905
 
1906 1906
 
@@ -1926,52 +1926,52 @@  discard block
 block discarded – undo
1926 1926
  *     - null lorsque l’attribut n’existe pas.
1927 1927
  **/
1928 1928
 function extraire_attribut($balise, $attribut, $complet = false) {
1929
-	if (is_array($balise)) {
1930
-		array_walk(
1931
-			$balise,
1932
-			function (&$a, $key, $t) {
1933
-				$a = extraire_attribut($a, $t);
1934
-			},
1935
-			$attribut
1936
-		);
1937
-
1938
-		return $balise;
1939
-	}
1940
-	if (
1941
-		$balise
1942
-		&& stripos($balise, $attribut) !== false
1943
-		&& preg_match(
1944
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1945
-			. $attribut
1946
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1947
-			$balise,
1948
-			$r
1949
-		)
1950
-	) {
1951
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1952
-			$r[4] = substr($r[3], 1, -1);
1953
-			$r[3] = $r[3][0];
1954
-		} elseif ($r[3] !== '') {
1955
-			$r[4] = $r[3];
1956
-			$r[3] = '';
1957
-		} else {
1958
-			$r[4] = trim($r[2]);
1959
-		}
1960
-		$att = $r[4];
1961
-		if (strpos($att, '&#') !== false) {
1962
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1963
-		}
1964
-		$att = filtrer_entites($att);
1965
-	} else {
1966
-		$att = null;
1967
-		$r = [];
1968
-	}
1969
-
1970
-	if ($complet) {
1971
-		return [$att, $r];
1972
-	} else {
1973
-		return $att;
1974
-	}
1929
+    if (is_array($balise)) {
1930
+        array_walk(
1931
+            $balise,
1932
+            function (&$a, $key, $t) {
1933
+                $a = extraire_attribut($a, $t);
1934
+            },
1935
+            $attribut
1936
+        );
1937
+
1938
+        return $balise;
1939
+    }
1940
+    if (
1941
+        $balise
1942
+        && stripos($balise, $attribut) !== false
1943
+        && preg_match(
1944
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1945
+            . $attribut
1946
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1947
+            $balise,
1948
+            $r
1949
+        )
1950
+    ) {
1951
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1952
+            $r[4] = substr($r[3], 1, -1);
1953
+            $r[3] = $r[3][0];
1954
+        } elseif ($r[3] !== '') {
1955
+            $r[4] = $r[3];
1956
+            $r[3] = '';
1957
+        } else {
1958
+            $r[4] = trim($r[2]);
1959
+        }
1960
+        $att = $r[4];
1961
+        if (strpos($att, '&#') !== false) {
1962
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1963
+        }
1964
+        $att = filtrer_entites($att);
1965
+    } else {
1966
+        $att = null;
1967
+        $r = [];
1968
+    }
1969
+
1970
+    if ($complet) {
1971
+        return [$att, $r];
1972
+    } else {
1973
+        return $att;
1974
+    }
1975 1975
 }
1976 1976
 
1977 1977
 /**
@@ -2004,41 +2004,41 @@  discard block
 block discarded – undo
2004 2004
  **/
2005 2005
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
2006 2006
 
2007
-	if ($balise === null or $balise === '') {
2008
-		return '';
2009
-	}
2007
+    if ($balise === null or $balise === '') {
2008
+        return '';
2009
+    }
2010 2010
 
2011
-	// preparer l'attribut
2012
-	// supprimer les &nbsp; etc mais pas les balises html
2013
-	// qui ont un sens dans un attribut value d'un input
2014
-	if ($proteger) {
2015
-		$val = attribut_html($val, false);
2016
-	}
2011
+    // preparer l'attribut
2012
+    // supprimer les &nbsp; etc mais pas les balises html
2013
+    // qui ont un sens dans un attribut value d'un input
2014
+    if ($proteger) {
2015
+        $val = attribut_html($val, false);
2016
+    }
2017 2017
 
2018
-	// echapper les ' pour eviter tout bug
2019
-	$val = str_replace("'", '&#039;', $val);
2020
-	if ($vider and strlen($val) === 0) {
2021
-		$insert = '';
2022
-	} else {
2023
-		$insert = " $attribut='$val'";
2024
-	}
2018
+    // echapper les ' pour eviter tout bug
2019
+    $val = str_replace("'", '&#039;', $val);
2020
+    if ($vider and strlen($val) === 0) {
2021
+        $insert = '';
2022
+    } else {
2023
+        $insert = " $attribut='$val'";
2024
+    }
2025 2025
 
2026
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2026
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2027 2027
 
2028
-	if ($old !== null) {
2029
-		// Remplacer l'ancien attribut du meme nom
2030
-		$balise = $r[1] . $insert . $r[5];
2031
-	} else {
2032
-		// preferer une balise " />" (comme <img />)
2033
-		if (preg_match(',/>,', $balise)) {
2034
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2035
-		} // sinon une balise <a ...> ... </a>
2036
-		else {
2037
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2038
-		}
2039
-	}
2028
+    if ($old !== null) {
2029
+        // Remplacer l'ancien attribut du meme nom
2030
+        $balise = $r[1] . $insert . $r[5];
2031
+    } else {
2032
+        // preferer une balise " />" (comme <img />)
2033
+        if (preg_match(',/>,', $balise)) {
2034
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2035
+        } // sinon une balise <a ...> ... </a>
2036
+        else {
2037
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2038
+        }
2039
+    }
2040 2040
 
2041
-	return $balise;
2041
+    return $balise;
2042 2042
 }
2043 2043
 
2044 2044
 /**
@@ -2056,7 +2056,7 @@  discard block
 block discarded – undo
2056 2056
  * @return string Code HTML sans l'attribut
2057 2057
  **/
2058 2058
 function vider_attribut(?string $balise, string $attribut): string {
2059
-	return inserer_attribut($balise, $attribut, '', false, true);
2059
+    return inserer_attribut($balise, $attribut, '', false, true);
2060 2060
 }
2061 2061
 
2062 2062
 /**
@@ -2068,53 +2068,53 @@  discard block
 block discarded – undo
2068 2068
  * @return string
2069 2069
  */
2070 2070
 function modifier_class($balise, $class, $operation = 'ajouter') {
2071
-	if (is_string($class)) {
2072
-		$class = explode(' ', trim($class));
2073
-	}
2074
-	$class = array_filter($class);
2075
-	$class = array_unique($class);
2076
-	if (!$class) {
2077
-		return $balise;
2078
-	}
2079
-
2080
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2081
-	if (preg_match(',[^\w-],', implode('', $class))) {
2082
-		return $balise;
2083
-	}
2084
-
2085
-	$class_courante = extraire_attribut($balise, 'class');
2086
-	$class_new = $class_courante;
2087
-	foreach ($class as $c) {
2088
-		$is_class_presente = false;
2089
-		if (
2090
-			$class_courante
2091
-			and strpos($class_courante, (string) $c) !== false
2092
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2093
-		) {
2094
-			$is_class_presente = true;
2095
-		}
2096
-		if (
2097
-			in_array($operation, ['ajouter', 'commuter'])
2098
-			and !$is_class_presente
2099
-		) {
2100
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2101
-		} elseif (
2102
-			in_array($operation, ['supprimer', 'commuter'])
2103
-			and $is_class_presente
2104
-		) {
2105
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2106
-		}
2107
-	}
2108
-
2109
-	if ($class_new !== $class_courante) {
2110
-		if (strlen($class_new)) {
2111
-			$balise = inserer_attribut($balise, 'class', $class_new);
2112
-		} elseif ($class_courante) {
2113
-			$balise = vider_attribut($balise, 'class');
2114
-		}
2115
-	}
2116
-
2117
-	return $balise;
2071
+    if (is_string($class)) {
2072
+        $class = explode(' ', trim($class));
2073
+    }
2074
+    $class = array_filter($class);
2075
+    $class = array_unique($class);
2076
+    if (!$class) {
2077
+        return $balise;
2078
+    }
2079
+
2080
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2081
+    if (preg_match(',[^\w-],', implode('', $class))) {
2082
+        return $balise;
2083
+    }
2084
+
2085
+    $class_courante = extraire_attribut($balise, 'class');
2086
+    $class_new = $class_courante;
2087
+    foreach ($class as $c) {
2088
+        $is_class_presente = false;
2089
+        if (
2090
+            $class_courante
2091
+            and strpos($class_courante, (string) $c) !== false
2092
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2093
+        ) {
2094
+            $is_class_presente = true;
2095
+        }
2096
+        if (
2097
+            in_array($operation, ['ajouter', 'commuter'])
2098
+            and !$is_class_presente
2099
+        ) {
2100
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2101
+        } elseif (
2102
+            in_array($operation, ['supprimer', 'commuter'])
2103
+            and $is_class_presente
2104
+        ) {
2105
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2106
+        }
2107
+    }
2108
+
2109
+    if ($class_new !== $class_courante) {
2110
+        if (strlen($class_new)) {
2111
+            $balise = inserer_attribut($balise, 'class', $class_new);
2112
+        } elseif ($class_courante) {
2113
+            $balise = vider_attribut($balise, 'class');
2114
+        }
2115
+    }
2116
+
2117
+    return $balise;
2118 2118
 }
2119 2119
 
2120 2120
 /**
@@ -2124,7 +2124,7 @@  discard block
 block discarded – undo
2124 2124
  * @return string
2125 2125
  */
2126 2126
 function ajouter_class($balise, $class) {
2127
-	return modifier_class($balise, $class, 'ajouter');
2127
+    return modifier_class($balise, $class, 'ajouter');
2128 2128
 }
2129 2129
 
2130 2130
 /**
@@ -2134,7 +2134,7 @@  discard block
 block discarded – undo
2134 2134
  * @return string
2135 2135
  */
2136 2136
 function supprimer_class($balise, $class) {
2137
-	return modifier_class($balise, $class, 'supprimer');
2137
+    return modifier_class($balise, $class, 'supprimer');
2138 2138
 }
2139 2139
 
2140 2140
 /**
@@ -2145,7 +2145,7 @@  discard block
 block discarded – undo
2145 2145
  * @return string
2146 2146
  */
2147 2147
 function commuter_class($balise, $class) {
2148
-	return modifier_class($balise, $class, 'commuter');
2148
+    return modifier_class($balise, $class, 'commuter');
2149 2149
 }
2150 2150
 
2151 2151
 /**
@@ -2156,19 +2156,19 @@  discard block
 block discarded – undo
2156 2156
  * @return string
2157 2157
  */
2158 2158
 function tester_config($id, $mode = '') {
2159
-	include_spip('action/inscrire_auteur');
2159
+    include_spip('action/inscrire_auteur');
2160 2160
 
2161
-	return tester_statut_inscription($mode, $id);
2161
+    return tester_statut_inscription($mode, $id);
2162 2162
 }
2163 2163
 
2164 2164
 //
2165 2165
 // Quelques fonctions de calcul arithmetique
2166 2166
 //
2167 2167
 function floatstr($a) {
2168
- return str_replace(',', '.', (string)floatval($a));
2168
+    return str_replace(',', '.', (string)floatval($a));
2169 2169
 }
2170 2170
 function strize($f, $a, $b) {
2171
- return floatstr($f(floatstr($a), floatstr($b)));
2171
+    return floatstr($f(floatstr($a), floatstr($b)));
2172 2172
 }
2173 2173
 
2174 2174
 /**
@@ -2187,7 +2187,7 @@  discard block
 block discarded – undo
2187 2187
  * @return int $a+$b
2188 2188
  **/
2189 2189
 function plus($a, $b) {
2190
-	return $a + $b;
2190
+    return $a + $b;
2191 2191
 }
2192 2192
 function strplus($a, $b) {
2193 2193
 return strize('plus', $a, $b);
@@ -2208,7 +2208,7 @@  discard block
 block discarded – undo
2208 2208
  * @return int $a-$b
2209 2209
  **/
2210 2210
 function moins($a, $b) {
2211
-	return $a - $b;
2211
+    return $a - $b;
2212 2212
 }
2213 2213
 function strmoins($a, $b) {
2214 2214
 return strize('moins', $a, $b);
@@ -2231,7 +2231,7 @@  discard block
 block discarded – undo
2231 2231
  * @return int $a*$b
2232 2232
  **/
2233 2233
 function mult($a, $b) {
2234
-	return $a * $b;
2234
+    return $a * $b;
2235 2235
 }
2236 2236
 function strmult($a, $b) {
2237 2237
 return strize('mult', $a, $b);
@@ -2254,7 +2254,7 @@  discard block
 block discarded – undo
2254 2254
  * @return int $a/$b (ou 0 si $b est nul)
2255 2255
  **/
2256 2256
 function div($a, $b) {
2257
-	return $b ? $a / $b : 0;
2257
+    return $b ? $a / $b : 0;
2258 2258
 }
2259 2259
 function strdiv($a, $b) {
2260 2260
 return strize('div', $a, $b);
@@ -2278,7 +2278,7 @@  discard block
 block discarded – undo
2278 2278
  * @return int ($nb % $mod) + $add
2279 2279
  **/
2280 2280
 function modulo($nb, $mod, $add = 0) {
2281
-	return ($mod ? $nb % $mod : 0) + $add;
2281
+    return ($mod ? $nb % $mod : 0) + $add;
2282 2282
 }
2283 2283
 
2284 2284
 
@@ -2293,26 +2293,26 @@  discard block
 block discarded – undo
2293 2293
  *      - true sinon
2294 2294
  **/
2295 2295
 function nom_acceptable($nom) {
2296
-	$remp2 = [];
2297
-	$remp1 = [];
2298
-	if (!is_string($nom)) {
2299
-		return false;
2300
-	}
2301
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2302
-		define('_TAGS_NOM_AUTEUR', '');
2303
-	}
2304
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2305
-	foreach ($tags_acceptes as $tag) {
2306
-		if (strlen($tag)) {
2307
-			$remp1[] = '<' . trim($tag) . '>';
2308
-			$remp1[] = '</' . trim($tag) . '>';
2309
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2310
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2311
-		}
2312
-	}
2313
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2314
-
2315
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2296
+    $remp2 = [];
2297
+    $remp1 = [];
2298
+    if (!is_string($nom)) {
2299
+        return false;
2300
+    }
2301
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2302
+        define('_TAGS_NOM_AUTEUR', '');
2303
+    }
2304
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2305
+    foreach ($tags_acceptes as $tag) {
2306
+        if (strlen($tag)) {
2307
+            $remp1[] = '<' . trim($tag) . '>';
2308
+            $remp1[] = '</' . trim($tag) . '>';
2309
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2310
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2311
+        }
2312
+    }
2313
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2314
+
2315
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2316 2316
 }
2317 2317
 
2318 2318
 
@@ -2328,14 +2328,14 @@  discard block
 block discarded – undo
2328 2328
  *      - renvoie un tableau si l'entree est un tableau
2329 2329
  **/
2330 2330
 function email_valide($adresses) {
2331
-	if (is_array($adresses)) {
2332
-		$adresses = array_map('email_valide', $adresses);
2333
-		$adresses = array_filter($adresses);
2334
-		return $adresses;
2335
-	}
2331
+    if (is_array($adresses)) {
2332
+        $adresses = array_map('email_valide', $adresses);
2333
+        $adresses = array_filter($adresses);
2334
+        return $adresses;
2335
+    }
2336 2336
 
2337
-	$email_valide = charger_fonction('email_valide', 'inc');
2338
-	return $email_valide($adresses);
2337
+    $email_valide = charger_fonction('email_valide', 'inc');
2338
+    return $email_valide($adresses);
2339 2339
 }
2340 2340
 
2341 2341
 /**
@@ -2349,29 +2349,29 @@  discard block
 block discarded – undo
2349 2349
  * @return string Texte
2350 2350
  **/
2351 2351
 function afficher_enclosures($tags) {
2352
-	$s = [];
2353
-	foreach (extraire_balises($tags, 'a') as $tag) {
2354
-		if (
2355
-			extraire_attribut($tag, 'rel') == 'enclosure'
2356
-			and $t = extraire_attribut($tag, 'href')
2357
-		) {
2358
-			$s[] = preg_replace(
2359
-				',>[^<]+</a>,S',
2360
-				'>'
2361
-				. http_img_pack(
2362
-					'attachment-16.png',
2363
-					$t,
2364
-					'',
2365
-					$t,
2366
-					['utiliser_suffixe_size' => true]
2367
-				)
2368
-				. '</a>',
2369
-				$tag
2370
-			);
2371
-		}
2372
-	}
2373
-
2374
-	return join('&nbsp;', $s);
2352
+    $s = [];
2353
+    foreach (extraire_balises($tags, 'a') as $tag) {
2354
+        if (
2355
+            extraire_attribut($tag, 'rel') == 'enclosure'
2356
+            and $t = extraire_attribut($tag, 'href')
2357
+        ) {
2358
+            $s[] = preg_replace(
2359
+                ',>[^<]+</a>,S',
2360
+                '>'
2361
+                . http_img_pack(
2362
+                    'attachment-16.png',
2363
+                    $t,
2364
+                    '',
2365
+                    $t,
2366
+                    ['utiliser_suffixe_size' => true]
2367
+                )
2368
+                . '</a>',
2369
+                $tag
2370
+            );
2371
+        }
2372
+    }
2373
+
2374
+    return join('&nbsp;', $s);
2375 2375
 }
2376 2376
 
2377 2377
 /**
@@ -2386,15 +2386,15 @@  discard block
 block discarded – undo
2386 2386
  * @return string Liens trouvés
2387 2387
  **/
2388 2388
 function afficher_tags($tags, $rels = 'tag,directory') {
2389
-	$s = [];
2390
-	foreach (extraire_balises($tags, 'a') as $tag) {
2391
-		$rel = extraire_attribut($tag, 'rel');
2392
-		if (strstr(",$rels,", (string) ",$rel,")) {
2393
-			$s[] = $tag;
2394
-		}
2395
-	}
2389
+    $s = [];
2390
+    foreach (extraire_balises($tags, 'a') as $tag) {
2391
+        $rel = extraire_attribut($tag, 'rel');
2392
+        if (strstr(",$rels,", (string) ",$rel,")) {
2393
+            $s[] = $tag;
2394
+        }
2395
+    }
2396 2396
 
2397
-	return join(', ', $s);
2397
+    return join(', ', $s);
2398 2398
 }
2399 2399
 
2400 2400
 
@@ -2416,21 +2416,21 @@  discard block
 block discarded – undo
2416 2416
  * @return string Tag HTML `<a>` avec microformat.
2417 2417
  **/
2418 2418
 function enclosure2microformat($e) {
2419
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2420
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2421
-	}
2422
-	$type = extraire_attribut($e, 'type');
2423
-	if (!$length = extraire_attribut($e, 'length')) {
2424
-		# <media:content : longeur dans fileSize. On tente.
2425
-		$length = extraire_attribut($e, 'fileSize');
2426
-	}
2427
-	$fichier = basename($url);
2419
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2420
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2421
+    }
2422
+    $type = extraire_attribut($e, 'type');
2423
+    if (!$length = extraire_attribut($e, 'length')) {
2424
+        # <media:content : longeur dans fileSize. On tente.
2425
+        $length = extraire_attribut($e, 'fileSize');
2426
+    }
2427
+    $fichier = basename($url);
2428 2428
 
2429
-	return '<a rel="enclosure"'
2430
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2431
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2432
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2433
-	. '>' . $fichier . '</a>';
2429
+    return '<a rel="enclosure"'
2430
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2431
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2432
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2433
+    . '>' . $fichier . '</a>';
2434 2434
 }
2435 2435
 
2436 2436
 /**
@@ -2448,24 +2448,24 @@  discard block
 block discarded – undo
2448 2448
  * @return string Tags RSS `<enclosure>`.
2449 2449
  **/
2450 2450
 function microformat2enclosure($tags) {
2451
-	$enclosures = [];
2452
-	foreach (extraire_balises($tags, 'a') as $e) {
2453
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2454
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2455
-			$type = extraire_attribut($e, 'type');
2456
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2457
-				$length = intval(extraire_attribut($e, 'length'));
2458
-			} # vieux data
2459
-			$fichier = basename($url);
2460
-			$enclosures[] = '<enclosure'
2461
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2462
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2463
-				. ($length ? ' length="' . $length . '"' : '')
2464
-				. ' />';
2465
-		}
2466
-	}
2451
+    $enclosures = [];
2452
+    foreach (extraire_balises($tags, 'a') as $e) {
2453
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2454
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2455
+            $type = extraire_attribut($e, 'type');
2456
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2457
+                $length = intval(extraire_attribut($e, 'length'));
2458
+            } # vieux data
2459
+            $fichier = basename($url);
2460
+            $enclosures[] = '<enclosure'
2461
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2462
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2463
+                . ($length ? ' length="' . $length . '"' : '')
2464
+                . ' />';
2465
+        }
2466
+    }
2467 2467
 
2468
-	return join("\n", $enclosures);
2468
+    return join("\n", $enclosures);
2469 2469
 }
2470 2470
 
2471 2471
 
@@ -2481,16 +2481,16 @@  discard block
 block discarded – undo
2481 2481
  * @return string Tags RSS Atom `<dc:subject>`.
2482 2482
  **/
2483 2483
 function tags2dcsubject($tags) {
2484
-	$subjects = '';
2485
-	foreach (extraire_balises($tags, 'a') as $e) {
2486
-		if (extraire_attribut($e, 'rel') == 'tag') {
2487
-			$subjects .= '<dc:subject>'
2488
-				. texte_backend(textebrut($e))
2489
-				. '</dc:subject>' . "\n";
2490
-		}
2491
-	}
2484
+    $subjects = '';
2485
+    foreach (extraire_balises($tags, 'a') as $e) {
2486
+        if (extraire_attribut($e, 'rel') == 'tag') {
2487
+            $subjects .= '<dc:subject>'
2488
+                . texte_backend(textebrut($e))
2489
+                . '</dc:subject>' . "\n";
2490
+        }
2491
+    }
2492 2492
 
2493
-	return $subjects;
2493
+    return $subjects;
2494 2494
 }
2495 2495
 
2496 2496
 /**
@@ -2519,27 +2519,27 @@  discard block
 block discarded – undo
2519 2519
  *     - Tableau de résultats, si tableau en entrée.
2520 2520
  **/
2521 2521
 function extraire_balise($texte, $tag = 'a') {
2522
-	if (is_array($texte)) {
2523
-		array_walk(
2524
-			$texte,
2525
-			function (&$a, $key, $t) {
2526
-				$a = extraire_balise($a, $t);
2527
-			},
2528
-			$tag
2529
-		);
2530
-
2531
-		return $texte;
2532
-	}
2533
-
2534
-	if (
2535
-		preg_match(
2536
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2537
-			$texte,
2538
-			$regs
2539
-		)
2540
-	) {
2541
-		return $regs[0];
2542
-	}
2522
+    if (is_array($texte)) {
2523
+        array_walk(
2524
+            $texte,
2525
+            function (&$a, $key, $t) {
2526
+                $a = extraire_balise($a, $t);
2527
+            },
2528
+            $tag
2529
+        );
2530
+
2531
+        return $texte;
2532
+    }
2533
+
2534
+    if (
2535
+        preg_match(
2536
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2537
+            $texte,
2538
+            $regs
2539
+        )
2540
+    ) {
2541
+        return $regs[0];
2542
+    }
2543 2543
 }
2544 2544
 
2545 2545
 /**
@@ -2567,30 +2567,30 @@  discard block
 block discarded – undo
2567 2567
  *     - Tableau de résultats, si tableau en entrée.
2568 2568
  **/
2569 2569
 function extraire_balises($texte, $tag = 'a') {
2570
-	if (is_array($texte)) {
2571
-		array_walk(
2572
-			$texte,
2573
-			function (&$a, $key, $t) {
2574
-				$a = extraire_balises($a, $t);
2575
-			},
2576
-			$tag
2577
-		);
2578
-
2579
-		return $texte;
2580
-	}
2581
-
2582
-	if (
2583
-		preg_match_all(
2584
-			",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2585
-			$texte,
2586
-			$regs,
2587
-			PREG_PATTERN_ORDER
2588
-		)
2589
-	) {
2590
-		return $regs[0];
2591
-	} else {
2592
-		return [];
2593
-	}
2570
+    if (is_array($texte)) {
2571
+        array_walk(
2572
+            $texte,
2573
+            function (&$a, $key, $t) {
2574
+                $a = extraire_balises($a, $t);
2575
+            },
2576
+            $tag
2577
+        );
2578
+
2579
+        return $texte;
2580
+    }
2581
+
2582
+    if (
2583
+        preg_match_all(
2584
+            ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2585
+            $texte,
2586
+            $regs,
2587
+            PREG_PATTERN_ORDER
2588
+        )
2589
+    ) {
2590
+        return $regs[0];
2591
+    } else {
2592
+        return [];
2593
+    }
2594 2594
 }
2595 2595
 
2596 2596
 /**
@@ -2619,11 +2619,11 @@  discard block
 block discarded – undo
2619 2619
  *     - `$def` si on n'a pas transmis de tableau
2620 2620
  **/
2621 2621
 function in_any($val, $vals, $def = '') {
2622
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2623
-		$vals = $v;
2624
-	}
2622
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2623
+        $vals = $v;
2624
+    }
2625 2625
 
2626
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2626
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2627 2627
 }
2628 2628
 
2629 2629
 
@@ -2644,12 +2644,12 @@  discard block
 block discarded – undo
2644 2644
  *     Résultat du calcul
2645 2645
  **/
2646 2646
 function valeur_numerique($expr) {
2647
-	$a = 0;
2648
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2649
-		eval("\$a = $expr;");
2650
-	}
2647
+    $a = 0;
2648
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2649
+        eval("\$a = $expr;");
2650
+    }
2651 2651
 
2652
-	return intval($a);
2652
+    return intval($a);
2653 2653
 }
2654 2654
 
2655 2655
 /**
@@ -2668,7 +2668,7 @@  discard block
 block discarded – undo
2668 2668
  *      Retourne `$a*$b/$c`
2669 2669
  **/
2670 2670
 function regledetrois($a, $b, $c) {
2671
-	return round($a * $b / $c);
2671
+    return round($a * $b / $c);
2672 2672
 }
2673 2673
 
2674 2674
 
@@ -2691,79 +2691,79 @@  discard block
 block discarded – undo
2691 2691
  * @return string Suite de champs input hidden
2692 2692
  **/
2693 2693
 function form_hidden(?string $action = ''): string {
2694
-	$action ??= '';
2695
-
2696
-	$contexte = [];
2697
-	include_spip('inc/urls');
2698
-	if (
2699
-		$p = urls_decoder_url($action, '')
2700
-		and reset($p)
2701
-	) {
2702
-		$fond = array_shift($p);
2703
-		if ($fond != '404') {
2704
-			$contexte = array_shift($p);
2705
-			$contexte['page'] = $fond;
2706
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2707
-		}
2708
-	}
2709
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2710
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2711
-		unset($contexte['type']);
2712
-	}
2713
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2714
-		unset($contexte['type-page']);
2715
-	}
2716
-
2717
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2718
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2719
-	$values = [];
2720
-
2721
-	// d'abord avec celles de l'url
2722
-	if (false !== ($p = strpos($action, '?'))) {
2723
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2724
-			$c = explode('=', $c, 2);
2725
-			$var = array_shift($c);
2726
-			$val = array_shift($c) ?? '';
2727
-			if ($var) {
2728
-				$val = rawurldecode($val);
2729
-				$var = rawurldecode($var); // decoder les [] eventuels
2730
-				if (preg_match(',\[\]$,S', $var)) {
2731
-					$values[] = [$var, $val];
2732
-				} else {
2733
-					if (!isset($values[$var])) {
2734
-						$values[$var] = [$var, $val];
2735
-					}
2736
-				}
2737
-			}
2738
-		}
2739
-	}
2740
-
2741
-	// ensuite avec celles du contexte, sans doublonner !
2742
-	foreach ($contexte as $var => $val) {
2743
-		if (preg_match(',\[\]$,S', $var)) {
2744
-			$values[] = [$var, $val];
2745
-		} else {
2746
-			if (!isset($values[$var])) {
2747
-				$values[$var] = [$var, $val];
2748
-			}
2749
-		}
2750
-	}
2751
-
2752
-	// puis on rassemble le tout
2753
-	$hidden = [];
2754
-	foreach ($values as $value) {
2755
-		[$var, $val] = $value;
2756
-		$hidden[] = '<input name="'
2757
-			. entites_html($var)
2758
-			. '"'
2759
-			. (is_null($val)
2760
-				? ''
2761
-				: ' value="' . entites_html($val) . '"'
2762
-			)
2763
-			. ' type="hidden"' . "\n/>";
2764
-	}
2765
-
2766
-	return join('', $hidden);
2694
+    $action ??= '';
2695
+
2696
+    $contexte = [];
2697
+    include_spip('inc/urls');
2698
+    if (
2699
+        $p = urls_decoder_url($action, '')
2700
+        and reset($p)
2701
+    ) {
2702
+        $fond = array_shift($p);
2703
+        if ($fond != '404') {
2704
+            $contexte = array_shift($p);
2705
+            $contexte['page'] = $fond;
2706
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2707
+        }
2708
+    }
2709
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2710
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2711
+        unset($contexte['type']);
2712
+    }
2713
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2714
+        unset($contexte['type-page']);
2715
+    }
2716
+
2717
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2718
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2719
+    $values = [];
2720
+
2721
+    // d'abord avec celles de l'url
2722
+    if (false !== ($p = strpos($action, '?'))) {
2723
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2724
+            $c = explode('=', $c, 2);
2725
+            $var = array_shift($c);
2726
+            $val = array_shift($c) ?? '';
2727
+            if ($var) {
2728
+                $val = rawurldecode($val);
2729
+                $var = rawurldecode($var); // decoder les [] eventuels
2730
+                if (preg_match(',\[\]$,S', $var)) {
2731
+                    $values[] = [$var, $val];
2732
+                } else {
2733
+                    if (!isset($values[$var])) {
2734
+                        $values[$var] = [$var, $val];
2735
+                    }
2736
+                }
2737
+            }
2738
+        }
2739
+    }
2740
+
2741
+    // ensuite avec celles du contexte, sans doublonner !
2742
+    foreach ($contexte as $var => $val) {
2743
+        if (preg_match(',\[\]$,S', $var)) {
2744
+            $values[] = [$var, $val];
2745
+        } else {
2746
+            if (!isset($values[$var])) {
2747
+                $values[$var] = [$var, $val];
2748
+            }
2749
+        }
2750
+    }
2751
+
2752
+    // puis on rassemble le tout
2753
+    $hidden = [];
2754
+    foreach ($values as $value) {
2755
+        [$var, $val] = $value;
2756
+        $hidden[] = '<input name="'
2757
+            . entites_html($var)
2758
+            . '"'
2759
+            . (is_null($val)
2760
+                ? ''
2761
+                : ' value="' . entites_html($val) . '"'
2762
+            )
2763
+            . ' type="hidden"' . "\n/>";
2764
+    }
2765
+
2766
+    return join('', $hidden);
2767 2767
 }
2768 2768
 
2769 2769
 
@@ -2785,7 +2785,7 @@  discard block
 block discarded – undo
2785 2785
  *    - la première valeur du tableau sinon.
2786 2786
  **/
2787 2787
 function filtre_reset($array) {
2788
-	return !is_array($array) ? null : reset($array);
2788
+    return !is_array($array) ? null : reset($array);
2789 2789
 }
2790 2790
 
2791 2791
 /**
@@ -2806,7 +2806,7 @@  discard block
 block discarded – undo
2806 2806
  *    - la dernière valeur du tableau sinon.
2807 2807
  **/
2808 2808
 function filtre_end($array) {
2809
-	return !is_array($array) ? null : end($array);
2809
+    return !is_array($array) ? null : end($array);
2810 2810
 }
2811 2811
 
2812 2812
 /**
@@ -2826,11 +2826,11 @@  discard block
 block discarded – undo
2826 2826
  *
2827 2827
  **/
2828 2828
 function filtre_push($array, $val) {
2829
-	if (!is_array($array) or !array_push($array, $val)) {
2830
-		return '';
2831
-	}
2829
+    if (!is_array($array) or !array_push($array, $val)) {
2830
+        return '';
2831
+    }
2832 2832
 
2833
-	return $array;
2833
+    return $array;
2834 2834
 }
2835 2835
 
2836 2836
 /**
@@ -2849,7 +2849,7 @@  discard block
 block discarded – undo
2849 2849
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2850 2850
  **/
2851 2851
 function filtre_find($array, $val) {
2852
-	return (is_array($array) and in_array($val, $array));
2852
+    return (is_array($array) and in_array($val, $array));
2853 2853
 }
2854 2854
 
2855 2855
 
@@ -2866,13 +2866,13 @@  discard block
 block discarded – undo
2866 2866
  *     Contenu avec urls en absolus
2867 2867
  **/
2868 2868
 function urls_absolues_css($contenu, $source) {
2869
-	$path = suivre_lien(url_absolue($source), './');
2869
+    $path = suivre_lien(url_absolue($source), './');
2870 2870
 
2871
-	return preg_replace_callback(
2872
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2873
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2874
-		$contenu
2875
-	);
2871
+    return preg_replace_callback(
2872
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2873
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2874
+        $contenu
2875
+    );
2876 2876
 }
2877 2877
 
2878 2878
 
@@ -2901,119 +2901,119 @@  discard block
 block discarded – undo
2901 2901
  *     Chemin du fichier CSS inversé
2902 2902
  **/
2903 2903
 function direction_css($css, $voulue = '') {
2904
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2905
-		return $css;
2906
-	}
2907
-	include_spip('inc/lang');
2908
-	// si on a precise le sens voulu en argument, le prendre en compte
2909
-	if ($voulue = strtolower($voulue)) {
2910
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2911
-			$voulue = lang_dir($voulue);
2912
-		}
2913
-	} else {
2914
-		$voulue = lang_dir();
2915
-	}
2916
-
2917
-	$r = count($r) > 1;
2918
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2919
-	$dir = $r ? 'rtl' : 'ltr';
2920
-	$ndir = $r ? 'ltr' : 'rtl';
2921
-
2922
-	if ($voulue == $dir) {
2923
-		return $css;
2924
-	}
2925
-
2926
-	if (
2927
-		// url absolue
2928
-		preg_match(',^https?:,i', $css)
2929
-		// ou qui contient un ?
2930
-		or (($p = strpos($css, '?')) !== false)
2931
-	) {
2932
-		$distant = true;
2933
-		$cssf = parse_url($css);
2934
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2935
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2936
-	} else {
2937
-		$distant = false;
2938
-		$cssf = $css;
2939
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2940
-		//propose (rien a faire dans ce cas)
2941
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2942
-		if (@file_exists($f)) {
2943
-			return $f;
2944
-		}
2945
-	}
2946
-
2947
-	// 2.
2948
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2949
-	$f = $dir_var
2950
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2951
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2952
-
2953
-	// la css peut etre distante (url absolue !)
2954
-	if ($distant) {
2955
-		include_spip('inc/distant');
2956
-		$res = recuperer_url($css);
2957
-		if (!$res or !$contenu = $res['page']) {
2958
-			return $css;
2959
-		}
2960
-	} else {
2961
-		if (
2962
-			(@filemtime($f) > @filemtime($css))
2963
-			and (_VAR_MODE != 'recalcul')
2964
-		) {
2965
-			return $f;
2966
-		}
2967
-		if (!lire_fichier($css, $contenu)) {
2968
-			return $css;
2969
-		}
2970
-	}
2971
-
2972
-
2973
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2974
-	include_spip('lib/csstidy/class.csstidy');
2975
-	$parser = new csstidy();
2976
-	$parser->set_cfg('optimise_shorthands', 0);
2977
-	$parser->set_cfg('reverse_left_and_right', true);
2978
-	$parser->parse($contenu);
2979
-
2980
-	$contenu = $parser->print->plain();
2981
-
2982
-
2983
-	// reperer les @import auxquels il faut propager le direction_css
2984
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2985
-	$src = [];
2986
-	$src_direction_css = [];
2987
-	$src_faux_abs = [];
2988
-	$d = dirname($css);
2989
-	foreach ($regs[1] as $k => $import_css) {
2990
-		$css_direction = direction_css("$d/$import_css", $voulue);
2991
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2992
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2993
-			$css_direction = substr($css_direction, strlen($d) + 1);
2994
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2995
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2996
-			$css_direction = substr($css_direction, strlen($dir_var));
2997
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2998
-			$css_direction = '/@@@@@@/' . $css_direction;
2999
-		}
3000
-		$src[] = $regs[0][$k];
3001
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3002
-	}
3003
-	$contenu = str_replace($src, $src_direction_css, $contenu);
3004
-
3005
-	$contenu = urls_absolues_css($contenu, $css);
3006
-
3007
-	// virer les fausses url absolues que l'on a mis dans les import
3008
-	if (count($src_faux_abs)) {
3009
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3010
-	}
3011
-
3012
-	if (!ecrire_fichier($f, $contenu)) {
3013
-		return $css;
3014
-	}
3015
-
3016
-	return $f;
2904
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2905
+        return $css;
2906
+    }
2907
+    include_spip('inc/lang');
2908
+    // si on a precise le sens voulu en argument, le prendre en compte
2909
+    if ($voulue = strtolower($voulue)) {
2910
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2911
+            $voulue = lang_dir($voulue);
2912
+        }
2913
+    } else {
2914
+        $voulue = lang_dir();
2915
+    }
2916
+
2917
+    $r = count($r) > 1;
2918
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2919
+    $dir = $r ? 'rtl' : 'ltr';
2920
+    $ndir = $r ? 'ltr' : 'rtl';
2921
+
2922
+    if ($voulue == $dir) {
2923
+        return $css;
2924
+    }
2925
+
2926
+    if (
2927
+        // url absolue
2928
+        preg_match(',^https?:,i', $css)
2929
+        // ou qui contient un ?
2930
+        or (($p = strpos($css, '?')) !== false)
2931
+    ) {
2932
+        $distant = true;
2933
+        $cssf = parse_url($css);
2934
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2935
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2936
+    } else {
2937
+        $distant = false;
2938
+        $cssf = $css;
2939
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2940
+        //propose (rien a faire dans ce cas)
2941
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2942
+        if (@file_exists($f)) {
2943
+            return $f;
2944
+        }
2945
+    }
2946
+
2947
+    // 2.
2948
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2949
+    $f = $dir_var
2950
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2951
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2952
+
2953
+    // la css peut etre distante (url absolue !)
2954
+    if ($distant) {
2955
+        include_spip('inc/distant');
2956
+        $res = recuperer_url($css);
2957
+        if (!$res or !$contenu = $res['page']) {
2958
+            return $css;
2959
+        }
2960
+    } else {
2961
+        if (
2962
+            (@filemtime($f) > @filemtime($css))
2963
+            and (_VAR_MODE != 'recalcul')
2964
+        ) {
2965
+            return $f;
2966
+        }
2967
+        if (!lire_fichier($css, $contenu)) {
2968
+            return $css;
2969
+        }
2970
+    }
2971
+
2972
+
2973
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2974
+    include_spip('lib/csstidy/class.csstidy');
2975
+    $parser = new csstidy();
2976
+    $parser->set_cfg('optimise_shorthands', 0);
2977
+    $parser->set_cfg('reverse_left_and_right', true);
2978
+    $parser->parse($contenu);
2979
+
2980
+    $contenu = $parser->print->plain();
2981
+
2982
+
2983
+    // reperer les @import auxquels il faut propager le direction_css
2984
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2985
+    $src = [];
2986
+    $src_direction_css = [];
2987
+    $src_faux_abs = [];
2988
+    $d = dirname($css);
2989
+    foreach ($regs[1] as $k => $import_css) {
2990
+        $css_direction = direction_css("$d/$import_css", $voulue);
2991
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2992
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2993
+            $css_direction = substr($css_direction, strlen($d) + 1);
2994
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2995
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2996
+            $css_direction = substr($css_direction, strlen($dir_var));
2997
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2998
+            $css_direction = '/@@@@@@/' . $css_direction;
2999
+        }
3000
+        $src[] = $regs[0][$k];
3001
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
3002
+    }
3003
+    $contenu = str_replace($src, $src_direction_css, $contenu);
3004
+
3005
+    $contenu = urls_absolues_css($contenu, $css);
3006
+
3007
+    // virer les fausses url absolues que l'on a mis dans les import
3008
+    if (count($src_faux_abs)) {
3009
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
3010
+    }
3011
+
3012
+    if (!ecrire_fichier($f, $contenu)) {
3013
+        return $css;
3014
+    }
3015
+
3016
+    return $f;
3017 3017
 }
3018 3018
 
3019 3019
 
@@ -3036,46 +3036,46 @@  discard block
 block discarded – undo
3036 3036
  *     - Chemin ou URL du fichier CSS source sinon.
3037 3037
  **/
3038 3038
 function url_absolue_css($css) {
3039
-	if (!preg_match(',\.css$,i', $css, $r)) {
3040
-		return $css;
3041
-	}
3039
+    if (!preg_match(',\.css$,i', $css, $r)) {
3040
+        return $css;
3041
+    }
3042 3042
 
3043
-	$url_absolue_css = url_absolue($css);
3043
+    $url_absolue_css = url_absolue($css);
3044 3044
 
3045
-	$f = basename($css, '.css');
3046
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3047
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3048
-		. '.css';
3045
+    $f = basename($css, '.css');
3046
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3047
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3048
+        . '.css';
3049 3049
 
3050
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3051
-		return $f;
3052
-	}
3050
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3051
+        return $f;
3052
+    }
3053 3053
 
3054
-	if ($url_absolue_css == $css) {
3055
-		if (
3056
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3057
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3058
-		) {
3059
-			include_spip('inc/distant');
3060
-			$contenu = recuperer_url($css);
3061
-			$contenu = $contenu['page'] ?? '';
3062
-			if (!$contenu) {
3063
-				return $css;
3064
-			}
3065
-		}
3066
-	} elseif (!lire_fichier($css, $contenu)) {
3067
-		return $css;
3068
-	}
3054
+    if ($url_absolue_css == $css) {
3055
+        if (
3056
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3057
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3058
+        ) {
3059
+            include_spip('inc/distant');
3060
+            $contenu = recuperer_url($css);
3061
+            $contenu = $contenu['page'] ?? '';
3062
+            if (!$contenu) {
3063
+                return $css;
3064
+            }
3065
+        }
3066
+    } elseif (!lire_fichier($css, $contenu)) {
3067
+        return $css;
3068
+    }
3069 3069
 
3070
-	// passer les url relatives a la css d'origine en url absolues
3071
-	$contenu = urls_absolues_css($contenu, $css);
3070
+    // passer les url relatives a la css d'origine en url absolues
3071
+    $contenu = urls_absolues_css($contenu, $css);
3072 3072
 
3073
-	// ecrire la css
3074
-	if (!ecrire_fichier($f, $contenu)) {
3075
-		return $css;
3076
-	}
3073
+    // ecrire la css
3074
+    if (!ecrire_fichier($f, $contenu)) {
3075
+        return $css;
3076
+    }
3077 3077
 
3078
-	return $f;
3078
+    return $f;
3079 3079
 }
3080 3080
 
3081 3081
 
@@ -3109,24 +3109,24 @@  discard block
 block discarded – undo
3109 3109
  *     Valeur trouvée ou valeur par défaut.
3110 3110
  **/
3111 3111
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3112
-	foreach (explode('/', $cle) as $k) {
3113
-		$table = (is_string($table) ? @unserialize($table) : $table);
3112
+    foreach (explode('/', $cle) as $k) {
3113
+        $table = (is_string($table) ? @unserialize($table) : $table);
3114 3114
 
3115
-		if (is_object($table)) {
3116
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3117
-		} elseif (is_array($table)) {
3118
-			if ($conserver_null) {
3119
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3120
-			} else {
3121
-				$table = ($table[$k] ?? $defaut);
3122
-			}
3123
-		} else {
3124
-			$table = $defaut;
3125
-			break;
3126
-		}
3127
-	}
3115
+        if (is_object($table)) {
3116
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3117
+        } elseif (is_array($table)) {
3118
+            if ($conserver_null) {
3119
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3120
+            } else {
3121
+                $table = ($table[$k] ?? $defaut);
3122
+            }
3123
+        } else {
3124
+            $table = $defaut;
3125
+            break;
3126
+        }
3127
+    }
3128 3128
 
3129
-	return $table;
3129
+    return $table;
3130 3130
 }
3131 3131
 
3132 3132
 /**
@@ -3159,22 +3159,22 @@  discard block
 block discarded – undo
3159 3159
  *     - string : expression trouvée.
3160 3160
  **/
3161 3161
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3162
-	if (intval($modif) and $capte == 0) {
3163
-		$capte = $modif;
3164
-		$modif = 'UuimsS';
3165
-	}
3166
-	$expression = str_replace('\/', '/', $expression);
3167
-	$expression = str_replace('/', '\/', $expression);
3162
+    if (intval($modif) and $capte == 0) {
3163
+        $capte = $modif;
3164
+        $modif = 'UuimsS';
3165
+    }
3166
+    $expression = str_replace('\/', '/', $expression);
3167
+    $expression = str_replace('/', '\/', $expression);
3168 3168
 
3169
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3170
-		if (isset($r[$capte])) {
3171
-			return $r[$capte];
3172
-		} else {
3173
-			return true;
3174
-		}
3175
-	}
3169
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3170
+        if (isset($r[$capte])) {
3171
+            return $r[$capte];
3172
+        } else {
3173
+            return true;
3174
+        }
3175
+    }
3176 3176
 
3177
-	return false;
3177
+    return false;
3178 3178
 }
3179 3179
 
3180 3180
 
@@ -3201,10 +3201,10 @@  discard block
 block discarded – undo
3201 3201
  *     Texte
3202 3202
  **/
3203 3203
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3204
-	$expression = str_replace('\/', '/', $expression);
3205
-	$expression = str_replace('/', '\/', $expression);
3204
+    $expression = str_replace('\/', '/', $expression);
3205
+    $expression = str_replace('/', '\/', $expression);
3206 3206
 
3207
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3207
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3208 3208
 }
3209 3209
 
3210 3210
 
@@ -3222,25 +3222,25 @@  discard block
 block discarded – undo
3222 3222
  **/
3223 3223
 function traiter_doublons_documents(&$doublons, $letexte) {
3224 3224
 
3225
-	// Verifier dans le texte & les notes (pas beau, helas)
3226
-	$t = $letexte . $GLOBALS['les_notes'];
3225
+    // Verifier dans le texte & les notes (pas beau, helas)
3226
+    $t = $letexte . $GLOBALS['les_notes'];
3227 3227
 
3228
-	if (
3229
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3230
-		and preg_match_all(
3231
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3232
-			$t,
3233
-			$matches,
3234
-			PREG_PATTERN_ORDER
3235
-		)
3236
-	) {
3237
-		if (!isset($doublons['documents'])) {
3238
-			$doublons['documents'] = '';
3239
-		}
3240
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3241
-	}
3228
+    if (
3229
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3230
+        and preg_match_all(
3231
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3232
+            $t,
3233
+            $matches,
3234
+            PREG_PATTERN_ORDER
3235
+        )
3236
+    ) {
3237
+        if (!isset($doublons['documents'])) {
3238
+            $doublons['documents'] = '';
3239
+        }
3240
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3241
+    }
3242 3242
 
3243
-	return $letexte;
3243
+    return $letexte;
3244 3244
 }
3245 3245
 
3246 3246
 /**
@@ -3254,7 +3254,7 @@  discard block
 block discarded – undo
3254 3254
  * @return string Chaîne vide
3255 3255
  **/
3256 3256
 function vide($texte) {
3257
-	return '';
3257
+    return '';
3258 3258
 }
3259 3259
 
3260 3260
 //
@@ -3283,23 +3283,23 @@  discard block
 block discarded – undo
3283 3283
  *      Code HTML résultant
3284 3284
  **/
3285 3285
 function env_to_params($env, $ignore_params = []) {
3286
-	$ignore_params = array_merge(
3287
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3288
-		$ignore_params
3289
-	);
3290
-	if (!is_array($env)) {
3291
-		$env = unserialize($env);
3292
-	}
3293
-	$texte = '';
3294
-	if ($env) {
3295
-		foreach ($env as $i => $j) {
3296
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3297
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3298
-			}
3299
-		}
3300
-	}
3301
-
3302
-	return $texte;
3286
+    $ignore_params = array_merge(
3287
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3288
+        $ignore_params
3289
+    );
3290
+    if (!is_array($env)) {
3291
+        $env = unserialize($env);
3292
+    }
3293
+    $texte = '';
3294
+    if ($env) {
3295
+        foreach ($env as $i => $j) {
3296
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3297
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3298
+            }
3299
+        }
3300
+    }
3301
+
3302
+    return $texte;
3303 3303
 }
3304 3304
 
3305 3305
 /**
@@ -3322,23 +3322,23 @@  discard block
 block discarded – undo
3322 3322
  *      Code HTML résultant
3323 3323
  **/
3324 3324
 function env_to_attributs($env, $ignore_params = []) {
3325
-	$ignore_params = array_merge(
3326
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3327
-		$ignore_params
3328
-	);
3329
-	if (!is_array($env)) {
3330
-		$env = unserialize($env);
3331
-	}
3332
-	$texte = '';
3333
-	if ($env) {
3334
-		foreach ($env as $i => $j) {
3335
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3336
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3337
-			}
3338
-		}
3339
-	}
3325
+    $ignore_params = array_merge(
3326
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3327
+        $ignore_params
3328
+    );
3329
+    if (!is_array($env)) {
3330
+        $env = unserialize($env);
3331
+    }
3332
+    $texte = '';
3333
+    if ($env) {
3334
+        foreach ($env as $i => $j) {
3335
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3336
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3337
+            }
3338
+        }
3339
+    }
3340 3340
 
3341
-	return $texte;
3341
+    return $texte;
3342 3342
 }
3343 3343
 
3344 3344
 
@@ -3356,7 +3356,7 @@  discard block
 block discarded – undo
3356 3356
  * @return string Chaînes concaténés
3357 3357
  **/
3358 3358
 function concat(...$args): string {
3359
-	return join('', $args);
3359
+    return join('', $args);
3360 3360
 }
3361 3361
 
3362 3362
 
@@ -3376,23 +3376,23 @@  discard block
 block discarded – undo
3376 3376
  *     Contenu du ou des fichiers, concaténé
3377 3377
  **/
3378 3378
 function charge_scripts($files, $script = true) {
3379
-	$flux = '';
3380
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3381
-		if (!is_string($file)) {
3382
-			continue;
3383
-		}
3384
-		if ($script) {
3385
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3386
-		}
3387
-		if ($file) {
3388
-			$path = find_in_path($file);
3389
-			if ($path) {
3390
-				$flux .= spip_file_get_contents($path);
3391
-			}
3392
-		}
3393
-	}
3394
-
3395
-	return $flux;
3379
+    $flux = '';
3380
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3381
+        if (!is_string($file)) {
3382
+            continue;
3383
+        }
3384
+        if ($script) {
3385
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3386
+        }
3387
+        if ($file) {
3388
+            $path = find_in_path($file);
3389
+            if ($path) {
3390
+                $flux .= spip_file_get_contents($path);
3391
+            }
3392
+        }
3393
+    }
3394
+
3395
+    return $flux;
3396 3396
 }
3397 3397
 
3398 3398
 /**
@@ -3403,22 +3403,22 @@  discard block
 block discarded – undo
3403 3403
  * @return string
3404 3404
  */
3405 3405
 function http_img_variante_svg_si_possible($img_file) {
3406
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3407
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3408
-	if (
3409
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3410
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3411
-		and file_exists($variante_svg_generique)
3412
-	) {
3413
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3414
-			$img_file = $variante_svg_size;
3415
-		}
3416
-		else {
3417
-			$img_file = $variante_svg_generique;
3418
-		}
3419
-	}
3406
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3407
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3408
+    if (
3409
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3410
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3411
+        and file_exists($variante_svg_generique)
3412
+    ) {
3413
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3414
+            $img_file = $variante_svg_size;
3415
+        }
3416
+        else {
3417
+            $img_file = $variante_svg_generique;
3418
+        }
3419
+    }
3420 3420
 
3421
-	return $img_file;
3421
+    return $img_file;
3422 3422
 }
3423 3423
 
3424 3424
 /**
@@ -3439,54 +3439,54 @@  discard block
 block discarded – undo
3439 3439
  */
3440 3440
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3441 3441
 
3442
-	$img_file = $img;
3443
-	if ($p = strpos($img_file, '?')) {
3444
-		$img_file = substr($img_file, 0, $p);
3445
-	}
3446
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3447
-		$img_file = chemin_image($img);
3448
-	}
3449
-	else {
3450
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3451
-			$img_file = http_img_variante_svg_si_possible($img_file);
3452
-		}
3453
-	}
3454
-	if (stripos($atts, 'width') === false) {
3455
-		// utiliser directement l'info de taille presente dans le nom
3456
-		if (
3457
-			(!isset($options['utiliser_suffixe_size'])
3458
-				or $options['utiliser_suffixe_size'] == true
3459
-			  or strpos($img_file, '-xx.svg') !== false)
3460
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3461
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3462
-		) {
3463
-			$largeur = $hauteur = intval($regs[1]);
3464
-		} else {
3465
-			$taille = taille_image($img_file);
3466
-			[$hauteur, $largeur] = $taille;
3467
-			if (!$hauteur or !$largeur) {
3468
-				return '';
3469
-			}
3470
-		}
3471
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3472
-	}
3473
-
3474
-	if (file_exists($img_file)) {
3475
-		$img_file = timestamp($img_file);
3476
-	}
3477
-	if ($alt === false) {
3478
-		$alt = '';
3479
-	}
3480
-	elseif ($alt or $alt === '') {
3481
-		$alt = " alt='" . attribut_html($alt) . "'";
3482
-	}
3483
-	else {
3484
-		$alt = " alt='" . attribut_html($title) . "'";
3485
-	}
3486
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3487
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3488
-	. ' ' . ltrim($atts)
3489
-	. ' />';
3442
+    $img_file = $img;
3443
+    if ($p = strpos($img_file, '?')) {
3444
+        $img_file = substr($img_file, 0, $p);
3445
+    }
3446
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3447
+        $img_file = chemin_image($img);
3448
+    }
3449
+    else {
3450
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3451
+            $img_file = http_img_variante_svg_si_possible($img_file);
3452
+        }
3453
+    }
3454
+    if (stripos($atts, 'width') === false) {
3455
+        // utiliser directement l'info de taille presente dans le nom
3456
+        if (
3457
+            (!isset($options['utiliser_suffixe_size'])
3458
+                or $options['utiliser_suffixe_size'] == true
3459
+              or strpos($img_file, '-xx.svg') !== false)
3460
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3461
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3462
+        ) {
3463
+            $largeur = $hauteur = intval($regs[1]);
3464
+        } else {
3465
+            $taille = taille_image($img_file);
3466
+            [$hauteur, $largeur] = $taille;
3467
+            if (!$hauteur or !$largeur) {
3468
+                return '';
3469
+            }
3470
+        }
3471
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3472
+    }
3473
+
3474
+    if (file_exists($img_file)) {
3475
+        $img_file = timestamp($img_file);
3476
+    }
3477
+    if ($alt === false) {
3478
+        $alt = '';
3479
+    }
3480
+    elseif ($alt or $alt === '') {
3481
+        $alt = " alt='" . attribut_html($alt) . "'";
3482
+    }
3483
+    else {
3484
+        $alt = " alt='" . attribut_html($title) . "'";
3485
+    }
3486
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3487
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3488
+    . ' ' . ltrim($atts)
3489
+    . ' />';
3490 3490
 }
3491 3491
 
3492 3492
 /**
@@ -3498,70 +3498,70 @@  discard block
 block discarded – undo
3498 3498
  * @return string
3499 3499
  */
3500 3500
 function http_style_background($img, $att = '', $size = null) {
3501
-	if ($size and is_numeric($size)) {
3502
-		$size = trim($size) . 'px';
3503
-	}
3504
-	return " style='background" .
3505
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3506
-		. ($size ? "background-size:{$size};" : '')
3507
-		. "'";
3501
+    if ($size and is_numeric($size)) {
3502
+        $size = trim($size) . 'px';
3503
+    }
3504
+    return " style='background" .
3505
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3506
+        . ($size ? "background-size:{$size};" : '')
3507
+        . "'";
3508 3508
 }
3509 3509
 
3510 3510
 
3511 3511
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3512
-	$args = [$alt_or_size, $class_or_size, $size];
3513
-	while (is_null(end($args)) and count($args)) {
3514
-		array_pop($args);
3515
-	}
3516
-	if (!count($args)) {
3517
-		return [null, null, null];
3518
-	}
3519
-	if (count($args) < 3) {
3520
-		$maybe_size = array_pop($args);
3521
-		// @2x
3522
-		// @1.5x
3523
-		// 512
3524
-		// 512x*
3525
-		// 512x300
3526
-		if (
3527
-			!strlen($maybe_size)
3528
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3529
-		) {
3530
-			$args[] = $maybe_size;
3531
-			$maybe_size = null;
3532
-		}
3533
-		while (count($args) < 2) {
3534
-			$args[] = null; // default alt or class
3535
-		}
3536
-		$args[] = $maybe_size;
3537
-	}
3538
-	return $args;
3512
+    $args = [$alt_or_size, $class_or_size, $size];
3513
+    while (is_null(end($args)) and count($args)) {
3514
+        array_pop($args);
3515
+    }
3516
+    if (!count($args)) {
3517
+        return [null, null, null];
3518
+    }
3519
+    if (count($args) < 3) {
3520
+        $maybe_size = array_pop($args);
3521
+        // @2x
3522
+        // @1.5x
3523
+        // 512
3524
+        // 512x*
3525
+        // 512x300
3526
+        if (
3527
+            !strlen($maybe_size)
3528
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3529
+        ) {
3530
+            $args[] = $maybe_size;
3531
+            $maybe_size = null;
3532
+        }
3533
+        while (count($args) < 2) {
3534
+            $args[] = null; // default alt or class
3535
+        }
3536
+        $args[] = $maybe_size;
3537
+    }
3538
+    return $args;
3539 3539
 }
3540 3540
 
3541 3541
 function helper_filtre_balise_img_svg_size($img, $size) {
3542
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3543
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3544
-		$coef = floatval(substr($size, 1, -1));
3545
-		[$h, $w] = taille_image($img);
3546
-		$height = intval(round($h / $coef));
3547
-		$width = intval(round($w / $coef));
3548
-	}
3549
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3550
-	else {
3551
-		$size = explode('x', $size, 2);
3552
-		$size = array_map('trim', $size);
3553
-		$height = $width = intval(array_shift($size));
3554
-
3555
-		if (count($size) and reset($size)) {
3556
-			$height = array_shift($size);
3557
-			if ($height === '*') {
3558
-				[$h, $w] = taille_image($img);
3559
-				$height = intval(round($h * $width / $w));
3560
-			}
3561
-		}
3562
-	}
3563
-
3564
-	return [$width, $height];
3542
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3543
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3544
+        $coef = floatval(substr($size, 1, -1));
3545
+        [$h, $w] = taille_image($img);
3546
+        $height = intval(round($h / $coef));
3547
+        $width = intval(round($w / $coef));
3548
+    }
3549
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3550
+    else {
3551
+        $size = explode('x', $size, 2);
3552
+        $size = array_map('trim', $size);
3553
+        $height = $width = intval(array_shift($size));
3554
+
3555
+        if (count($size) and reset($size)) {
3556
+            $height = array_shift($size);
3557
+            if ($height === '*') {
3558
+                [$h, $w] = taille_image($img);
3559
+                $height = intval(round($h * $width / $w));
3560
+            }
3561
+        }
3562
+    }
3563
+
3564
+    return [$width, $height];
3565 3565
 }
3566 3566
 
3567 3567
 /**
@@ -3597,43 +3597,43 @@  discard block
 block discarded – undo
3597 3597
  */
3598 3598
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3599 3599
 
3600
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3601
-
3602
-	$img = trim((string) $img);
3603
-	if (strpos($img, '<img') === 0) {
3604
-		if (!is_null($alt)) {
3605
-			$img = inserer_attribut($img, 'alt', $alt);
3606
-		}
3607
-		if (!is_null($class)) {
3608
-			if (strlen($class)) {
3609
-				$img = inserer_attribut($img, 'class', $class);
3610
-			}
3611
-			else {
3612
-				$img = vider_attribut($img, 'class');
3613
-			}
3614
-		}
3615
-	}
3616
-	else {
3617
-		$img = http_img_pack(
3618
-			$img,
3619
-			$alt,
3620
-			$class ? " class='" . attribut_html($class) . "'" : '',
3621
-			'',
3622
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3623
-		);
3624
-		if (is_null($alt)) {
3625
-			$img = vider_attribut($img, 'alt');
3626
-		}
3627
-	}
3628
-
3629
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3630
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3631
-
3632
-		$img = inserer_attribut($img, 'width', $width);
3633
-		$img = inserer_attribut($img, 'height', $height);
3634
-	}
3635
-
3636
-	return $img;
3600
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3601
+
3602
+    $img = trim((string) $img);
3603
+    if (strpos($img, '<img') === 0) {
3604
+        if (!is_null($alt)) {
3605
+            $img = inserer_attribut($img, 'alt', $alt);
3606
+        }
3607
+        if (!is_null($class)) {
3608
+            if (strlen($class)) {
3609
+                $img = inserer_attribut($img, 'class', $class);
3610
+            }
3611
+            else {
3612
+                $img = vider_attribut($img, 'class');
3613
+            }
3614
+        }
3615
+    }
3616
+    else {
3617
+        $img = http_img_pack(
3618
+            $img,
3619
+            $alt,
3620
+            $class ? " class='" . attribut_html($class) . "'" : '',
3621
+            '',
3622
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3623
+        );
3624
+        if (is_null($alt)) {
3625
+            $img = vider_attribut($img, 'alt');
3626
+        }
3627
+    }
3628
+
3629
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3630
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3631
+
3632
+        $img = inserer_attribut($img, 'width', $width);
3633
+        $img = inserer_attribut($img, 'height', $height);
3634
+    }
3635
+
3636
+    return $img;
3637 3637
 }
3638 3638
 
3639 3639
 
@@ -3667,80 +3667,80 @@  discard block
 block discarded – undo
3667 3667
  */
3668 3668
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3669 3669
 
3670
-	$svg = null;
3671
-	$img = trim($img);
3672
-	$img_file = $img;
3673
-	if (strpos($img, '<svg') === false) {
3674
-		if ($p = strpos($img_file, '?')) {
3675
-			$img_file = substr($img_file, 0, $p);
3676
-		}
3677
-
3678
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3679
-		// la copie locale a toutes les chances d'etre la ou de resservir
3680
-		if (tester_url_absolue($img_file)) {
3681
-			include_spip('inc/distant');
3682
-			$fichier = copie_locale($img_file);
3683
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3684
-		}
3685
-
3686
-		if (
3687
-			!$img_file
3688
-			or !file_exists($img_file)
3689
-			or !$svg = file_get_contents($img_file)
3690
-		) {
3691
-			return '';
3692
-		}
3693
-	}
3694
-
3695
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3696
-		return '';
3697
-	}
3698
-
3699
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3700
-
3701
-	$balise_svg = $match[0];
3702
-	$balise_svg_source = $balise_svg;
3703
-
3704
-	// entete XML à supprimer
3705
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3706
-
3707
-	// IE est toujours mon ami
3708
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3709
-
3710
-	// regler la classe
3711
-	if (!is_null($class)) {
3712
-		if (strlen($class)) {
3713
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3714
-		}
3715
-		else {
3716
-			$balise_svg = vider_attribut($balise_svg, 'class');
3717
-		}
3718
-	}
3719
-
3720
-	// regler le alt
3721
-	if ($alt) {
3722
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3723
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3724
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3725
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3726
-		$balise_svg .= $title;
3727
-	}
3728
-	else {
3729
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3730
-	}
3731
-
3732
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3733
-
3734
-	if (!is_null($size) and strlen($size = trim($size))) {
3735
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3736
-
3737
-		if (!function_exists('svg_redimensionner')) {
3738
-			include_spip('inc/svg');
3739
-		}
3740
-		$svg = svg_redimensionner($svg, $width, $height);
3741
-	}
3742
-
3743
-	return $svg;
3670
+    $svg = null;
3671
+    $img = trim($img);
3672
+    $img_file = $img;
3673
+    if (strpos($img, '<svg') === false) {
3674
+        if ($p = strpos($img_file, '?')) {
3675
+            $img_file = substr($img_file, 0, $p);
3676
+        }
3677
+
3678
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3679
+        // la copie locale a toutes les chances d'etre la ou de resservir
3680
+        if (tester_url_absolue($img_file)) {
3681
+            include_spip('inc/distant');
3682
+            $fichier = copie_locale($img_file);
3683
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3684
+        }
3685
+
3686
+        if (
3687
+            !$img_file
3688
+            or !file_exists($img_file)
3689
+            or !$svg = file_get_contents($img_file)
3690
+        ) {
3691
+            return '';
3692
+        }
3693
+    }
3694
+
3695
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3696
+        return '';
3697
+    }
3698
+
3699
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3700
+
3701
+    $balise_svg = $match[0];
3702
+    $balise_svg_source = $balise_svg;
3703
+
3704
+    // entete XML à supprimer
3705
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3706
+
3707
+    // IE est toujours mon ami
3708
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3709
+
3710
+    // regler la classe
3711
+    if (!is_null($class)) {
3712
+        if (strlen($class)) {
3713
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3714
+        }
3715
+        else {
3716
+            $balise_svg = vider_attribut($balise_svg, 'class');
3717
+        }
3718
+    }
3719
+
3720
+    // regler le alt
3721
+    if ($alt) {
3722
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3723
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3724
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3725
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3726
+        $balise_svg .= $title;
3727
+    }
3728
+    else {
3729
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3730
+    }
3731
+
3732
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3733
+
3734
+    if (!is_null($size) and strlen($size = trim($size))) {
3735
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3736
+
3737
+        if (!function_exists('svg_redimensionner')) {
3738
+            include_spip('inc/svg');
3739
+        }
3740
+        $svg = svg_redimensionner($svg, $width, $height);
3741
+    }
3742
+
3743
+    return $svg;
3744 3744
 }
3745 3745
 
3746 3746
 
@@ -3766,18 +3766,18 @@  discard block
 block discarded – undo
3766 3766
  *     Code HTML résultant
3767 3767
  **/
3768 3768
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3769
-	$texte = '';
3770
-	if (is_array($tableau)) {
3771
-		foreach ($tableau as $k => $v) {
3772
-			$res = recuperer_fond(
3773
-				'modeles/' . $modele,
3774
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3775
-			);
3776
-			$texte .= $res;
3777
-		}
3778
-	}
3769
+    $texte = '';
3770
+    if (is_array($tableau)) {
3771
+        foreach ($tableau as $k => $v) {
3772
+            $res = recuperer_fond(
3773
+                'modeles/' . $modele,
3774
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3775
+            );
3776
+            $texte .= $res;
3777
+        }
3778
+    }
3779 3779
 
3780
-	return $texte;
3780
+    return $texte;
3781 3781
 }
3782 3782
 
3783 3783
 
@@ -3802,37 +3802,37 @@  discard block
 block discarded – undo
3802 3802
  *         - tout : retourne toutes les informations du plugin actif
3803 3803
  **/
3804 3804
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3805
-	include_spip('inc/plugin');
3806
-	$plugin = strtoupper($plugin);
3807
-	$plugins_actifs = liste_plugin_actifs();
3808
-
3809
-	if (!$plugin) {
3810
-		return serialize(array_keys($plugins_actifs));
3811
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3812
-		return '';
3813
-	} elseif (($type_info == 'est_actif') and !$reload) {
3814
-		return $plugins_actifs[$plugin] ? 1 : 0;
3815
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3816
-		return $plugins_actifs[$plugin][$type_info];
3817
-	} else {
3818
-		$get_infos = charger_fonction('get_infos', 'plugins');
3819
-		// On prend en compte les extensions
3820
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3821
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3822
-		} else {
3823
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3824
-		}
3825
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3826
-			return '';
3827
-		}
3828
-		if ($type_info == 'tout') {
3829
-			return $infos;
3830
-		} elseif ($type_info == 'est_actif') {
3831
-			return $infos ? 1 : 0;
3832
-		} else {
3833
-			return strval($infos[$type_info]);
3834
-		}
3835
-	}
3805
+    include_spip('inc/plugin');
3806
+    $plugin = strtoupper($plugin);
3807
+    $plugins_actifs = liste_plugin_actifs();
3808
+
3809
+    if (!$plugin) {
3810
+        return serialize(array_keys($plugins_actifs));
3811
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3812
+        return '';
3813
+    } elseif (($type_info == 'est_actif') and !$reload) {
3814
+        return $plugins_actifs[$plugin] ? 1 : 0;
3815
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3816
+        return $plugins_actifs[$plugin][$type_info];
3817
+    } else {
3818
+        $get_infos = charger_fonction('get_infos', 'plugins');
3819
+        // On prend en compte les extensions
3820
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3821
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3822
+        } else {
3823
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3824
+        }
3825
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3826
+            return '';
3827
+        }
3828
+        if ($type_info == 'tout') {
3829
+            return $infos;
3830
+        } elseif ($type_info == 'est_actif') {
3831
+            return $infos ? 1 : 0;
3832
+        } else {
3833
+            return strval($infos[$type_info]);
3834
+        }
3835
+    }
3836 3836
 }
3837 3837
 
3838 3838
 
@@ -3859,9 +3859,9 @@  discard block
 block discarded – undo
3859 3859
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3860 3860
  */
3861 3861
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3862
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3862
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3863 3863
 
3864
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3864
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3865 3865
 }
3866 3866
 
3867 3867
 
@@ -3891,19 +3891,19 @@  discard block
 block discarded – undo
3891 3891
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3892 3892
  */
3893 3893
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3894
-	static $puce_statut = null;
3895
-	if (!$puce_statut) {
3896
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3897
-	}
3894
+    static $puce_statut = null;
3895
+    if (!$puce_statut) {
3896
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3897
+    }
3898 3898
 
3899
-	return $puce_statut(
3900
-		$id_objet,
3901
-		$statut,
3902
-		$id_parent,
3903
-		$objet,
3904
-		false,
3905
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3906
-	);
3899
+    return $puce_statut(
3900
+        $id_objet,
3901
+        $statut,
3902
+        $id_parent,
3903
+        $objet,
3904
+        false,
3905
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3906
+    );
3907 3907
 }
3908 3908
 
3909 3909
 
@@ -3930,98 +3930,98 @@  discard block
 block discarded – undo
3930 3930
  *   hash du contexte
3931 3931
  */
3932 3932
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3933
-	$env = null;
3934
-	if (
3935
-		is_string($c)
3936
-		and @unserialize($c) !== false
3937
-	) {
3938
-		$c = unserialize($c);
3939
-	}
3940
-
3941
-	// supprimer les parametres debut_x
3942
-	// pour que la pagination ajax ne soit pas plantee
3943
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3944
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3945
-	if (is_array($c)) {
3946
-		foreach ($c as $k => $v) {
3947
-			if (strpos($k, 'debut_') === 0) {
3948
-				unset($c[$k]);
3949
-			}
3950
-		}
3951
-	}
3952
-
3953
-	if (!function_exists('calculer_cle_action')) {
3954
-		include_spip('inc/securiser_action');
3955
-	}
3956
-
3957
-	$c = serialize($c);
3958
-	$cle = calculer_cle_action($form . $c);
3959
-	$c = "$cle:$c";
3960
-
3961
-	// on ne stocke pas les contextes dans des fichiers en cache
3962
-	// par defaut, sauf si cette configuration a été forcée
3963
-	// OU que la longueur de l’argument géneré est plus long
3964
-	// que ce qui est toléré.
3965
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3966
-	if (!$cache_contextes_ajax) {
3967
-		$env = $c;
3968
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3969
-			$env = gzdeflate($env);
3970
-		}
3971
-		$env = _xor($env);
3972
-		$env = base64_encode($env);
3973
-		$len = strlen($env);
3974
-		// Si l’url est trop longue pour le navigateur
3975
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3976
-		if ($len > $max_len) {
3977
-			$cache_contextes_ajax = true;
3978
-			spip_log(
3979
-				'Contextes AJAX forces en fichiers !'
3980
-				. ' Cela arrive lorsque la valeur du contexte'
3981
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3982
-				_LOG_AVERTISSEMENT
3983
-			);
3984
-		}
3985
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3986
-		elseif (
3987
-			$max_len = @ini_get('suhosin.get.max_value_length')
3988
-			and $max_len < $len
3989
-		) {
3990
-			$cache_contextes_ajax = true;
3991
-			spip_log('Contextes AJAX forces en fichiers !'
3992
-				. ' Cela arrive lorsque la valeur du contexte'
3993
-				. ' depasse la longueur maximale autorisee par Suhosin'
3994
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3995
-				. ' Vous devriez modifier les parametres de Suhosin'
3996
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3997
-		}
3998
-	}
3999
-
4000
-	if ($cache_contextes_ajax) {
4001
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
4002
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
4003
-		$md5 = md5($c);
4004
-		ecrire_fichier("$dir/c$md5", $c);
4005
-		$env = $md5;
4006
-	}
4007
-
4008
-	if ($emboite === null) {
4009
-		return $env;
4010
-	}
4011
-	if (!trim($emboite)) {
4012
-		return '';
4013
-	}
4014
-	// toujours encoder l'url source dans le bloc ajax
4015
-	$r = self();
4016
-	$r = ' data-origin="' . $r . '"';
4017
-	$class = 'ajaxbloc';
4018
-	if ($ajaxid and is_string($ajaxid)) {
4019
-		// ajaxid est normalement conforme a un nom de classe css
4020
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4021
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4022
-	}
4023
-
4024
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3933
+    $env = null;
3934
+    if (
3935
+        is_string($c)
3936
+        and @unserialize($c) !== false
3937
+    ) {
3938
+        $c = unserialize($c);
3939
+    }
3940
+
3941
+    // supprimer les parametres debut_x
3942
+    // pour que la pagination ajax ne soit pas plantee
3943
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3944
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3945
+    if (is_array($c)) {
3946
+        foreach ($c as $k => $v) {
3947
+            if (strpos($k, 'debut_') === 0) {
3948
+                unset($c[$k]);
3949
+            }
3950
+        }
3951
+    }
3952
+
3953
+    if (!function_exists('calculer_cle_action')) {
3954
+        include_spip('inc/securiser_action');
3955
+    }
3956
+
3957
+    $c = serialize($c);
3958
+    $cle = calculer_cle_action($form . $c);
3959
+    $c = "$cle:$c";
3960
+
3961
+    // on ne stocke pas les contextes dans des fichiers en cache
3962
+    // par defaut, sauf si cette configuration a été forcée
3963
+    // OU que la longueur de l’argument géneré est plus long
3964
+    // que ce qui est toléré.
3965
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3966
+    if (!$cache_contextes_ajax) {
3967
+        $env = $c;
3968
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3969
+            $env = gzdeflate($env);
3970
+        }
3971
+        $env = _xor($env);
3972
+        $env = base64_encode($env);
3973
+        $len = strlen($env);
3974
+        // Si l’url est trop longue pour le navigateur
3975
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3976
+        if ($len > $max_len) {
3977
+            $cache_contextes_ajax = true;
3978
+            spip_log(
3979
+                'Contextes AJAX forces en fichiers !'
3980
+                . ' Cela arrive lorsque la valeur du contexte'
3981
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3982
+                _LOG_AVERTISSEMENT
3983
+            );
3984
+        }
3985
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3986
+        elseif (
3987
+            $max_len = @ini_get('suhosin.get.max_value_length')
3988
+            and $max_len < $len
3989
+        ) {
3990
+            $cache_contextes_ajax = true;
3991
+            spip_log('Contextes AJAX forces en fichiers !'
3992
+                . ' Cela arrive lorsque la valeur du contexte'
3993
+                . ' depasse la longueur maximale autorisee par Suhosin'
3994
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3995
+                . ' Vous devriez modifier les parametres de Suhosin'
3996
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3997
+        }
3998
+    }
3999
+
4000
+    if ($cache_contextes_ajax) {
4001
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
4002
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
4003
+        $md5 = md5($c);
4004
+        ecrire_fichier("$dir/c$md5", $c);
4005
+        $env = $md5;
4006
+    }
4007
+
4008
+    if ($emboite === null) {
4009
+        return $env;
4010
+    }
4011
+    if (!trim($emboite)) {
4012
+        return '';
4013
+    }
4014
+    // toujours encoder l'url source dans le bloc ajax
4015
+    $r = self();
4016
+    $r = ' data-origin="' . $r . '"';
4017
+    $class = 'ajaxbloc';
4018
+    if ($ajaxid and is_string($ajaxid)) {
4019
+        // ajaxid est normalement conforme a un nom de classe css
4020
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4021
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4022
+    }
4023
+
4024
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4025 4025
 }
4026 4026
 
4027 4027
 /**
@@ -4041,37 +4041,37 @@  discard block
 block discarded – undo
4041 4041
  *   - false : erreur de décodage
4042 4042
  */
4043 4043
 function decoder_contexte_ajax($c, $form = '') {
4044
-	if (!function_exists('calculer_cle_action')) {
4045
-		include_spip('inc/securiser_action');
4046
-	}
4047
-	if (
4048
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4049
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4050
-		and lire_fichier("$dir/c$c", $contexte)
4051
-	) {
4052
-		$c = $contexte;
4053
-	} else {
4054
-		$c = @base64_decode($c);
4055
-		$c = _xor($c);
4056
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4057
-			$c = @gzinflate($c);
4058
-		}
4059
-	}
4060
-
4061
-	// extraire la signature en debut de contexte
4062
-	// et la verifier avant de deserializer
4063
-	// format : signature:donneesserializees
4064
-	if ($p = strpos($c, ':')) {
4065
-		$cle = substr($c, 0, $p);
4066
-		$c = substr($c, $p + 1);
4067
-
4068
-		if ($cle == calculer_cle_action($form . $c)) {
4069
-			$env = @unserialize($c);
4070
-			return $env;
4071
-		}
4072
-	}
4073
-
4074
-	return false;
4044
+    if (!function_exists('calculer_cle_action')) {
4045
+        include_spip('inc/securiser_action');
4046
+    }
4047
+    if (
4048
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4049
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4050
+        and lire_fichier("$dir/c$c", $contexte)
4051
+    ) {
4052
+        $c = $contexte;
4053
+    } else {
4054
+        $c = @base64_decode($c);
4055
+        $c = _xor($c);
4056
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4057
+            $c = @gzinflate($c);
4058
+        }
4059
+    }
4060
+
4061
+    // extraire la signature en debut de contexte
4062
+    // et la verifier avant de deserializer
4063
+    // format : signature:donneesserializees
4064
+    if ($p = strpos($c, ':')) {
4065
+        $cle = substr($c, 0, $p);
4066
+        $c = substr($c, $p + 1);
4067
+
4068
+        if ($cle == calculer_cle_action($form . $c)) {
4069
+            $env = @unserialize($c);
4070
+            return $env;
4071
+        }
4072
+    }
4073
+
4074
+    return false;
4075 4075
 }
4076 4076
 
4077 4077
 
@@ -4089,20 +4089,20 @@  discard block
 block discarded – undo
4089 4089
  *    Message décrypté ou encrypté
4090 4090
  **/
4091 4091
 function _xor($message, $key = null) {
4092
-	if (is_null($key)) {
4093
-		if (!function_exists('calculer_cle_action')) {
4094
-			include_spip('inc/securiser_action');
4095
-		}
4096
-		$key = pack('H*', calculer_cle_action('_xor'));
4097
-	}
4092
+    if (is_null($key)) {
4093
+        if (!function_exists('calculer_cle_action')) {
4094
+            include_spip('inc/securiser_action');
4095
+        }
4096
+        $key = pack('H*', calculer_cle_action('_xor'));
4097
+    }
4098 4098
 
4099
-	$keylen = strlen($key);
4100
-	$messagelen = strlen($message);
4101
-	for ($i = 0; $i < $messagelen; $i++) {
4102
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4103
-	}
4099
+    $keylen = strlen($key);
4100
+    $messagelen = strlen($message);
4101
+    for ($i = 0; $i < $messagelen; $i++) {
4102
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4103
+    }
4104 4104
 
4105
-	return $message;
4105
+    return $message;
4106 4106
 }
4107 4107
 
4108 4108
 /**
@@ -4116,7 +4116,7 @@  discard block
 block discarded – undo
4116 4116
  * @return string
4117 4117
  */
4118 4118
 function url_reponse_forum($texte) {
4119
- return $texte;
4119
+    return $texte;
4120 4120
 }
4121 4121
 
4122 4122
 /**
@@ -4130,7 +4130,7 @@  discard block
 block discarded – undo
4130 4130
  * @return string
4131 4131
  */
4132 4132
 function url_rss_forum($texte) {
4133
- return $texte;
4133
+    return $texte;
4134 4134
 }
4135 4135
 
4136 4136
 
@@ -4169,37 +4169,37 @@  discard block
 block discarded – undo
4169 4169
  *   Code HTML
4170 4170
  */
4171 4171
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4172
-	if ($on) {
4173
-		$bal = 'strong';
4174
-		$class = '';
4175
-		$att = '';
4176
-		// si $on passe la balise et optionnelement une ou ++classe
4177
-		// a.active span.selected.active etc....
4178
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4179
-			$on = explode('.', $on);
4180
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4181
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4182
-				$bal = array_shift($on);
4183
-				$class = implode(' ', $on);
4184
-				if ($bal == 'a') {
4185
-					$att = 'href="#" ';
4186
-				}
4187
-			}
4188
-		}
4189
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4190
-	} else {
4191
-		$bal = 'a';
4192
-		$att = "href='$url'"
4193
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4194
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4195
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4196
-			. $evt;
4197
-	}
4198
-	if ($libelle === null) {
4199
-		$libelle = $url;
4200
-	}
4201
-
4202
-	return "<$bal $att>$libelle</$bal>";
4172
+    if ($on) {
4173
+        $bal = 'strong';
4174
+        $class = '';
4175
+        $att = '';
4176
+        // si $on passe la balise et optionnelement une ou ++classe
4177
+        // a.active span.selected.active etc....
4178
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4179
+            $on = explode('.', $on);
4180
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4181
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4182
+                $bal = array_shift($on);
4183
+                $class = implode(' ', $on);
4184
+                if ($bal == 'a') {
4185
+                    $att = 'href="#" ';
4186
+                }
4187
+            }
4188
+        }
4189
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4190
+    } else {
4191
+        $bal = 'a';
4192
+        $att = "href='$url'"
4193
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4194
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4195
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4196
+            . $evt;
4197
+    }
4198
+    if ($libelle === null) {
4199
+        $libelle = $url;
4200
+    }
4201
+
4202
+    return "<$bal $att>$libelle</$bal>";
4203 4203
 }
4204 4204
 
4205 4205
 
@@ -4216,39 +4216,39 @@  discard block
 block discarded – undo
4216 4216
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4217 4217
  */
4218 4218
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4219
-	static $local_singulier_ou_pluriel = [];
4220
-
4221
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4222
-	if (!is_numeric($nb) or $nb == 0) {
4223
-		return '';
4224
-	}
4225
-	if (!is_array($vars)) {
4226
-		return '';
4227
-	}
4228
-
4229
-	$langue = $GLOBALS['spip_lang'];
4230
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4231
-		$local_singulier_ou_pluriel[$langue] = false;
4232
-		if (
4233
-			$f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4234
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4235
-		) {
4236
-			$local_singulier_ou_pluriel[$langue] = $f;
4237
-		}
4238
-	}
4239
-
4240
-	// si on a une surcharge on l'utilise
4241
-	if ($local_singulier_ou_pluriel[$langue]) {
4242
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4243
-	}
4244
-
4245
-	// sinon traitement par defaut
4246
-	$vars[$var] = $nb;
4247
-	if ($nb >= 2) {
4248
-		return _T($chaine_plusieurs, $vars);
4249
-	} else {
4250
-		return _T($chaine_un, $vars);
4251
-	}
4219
+    static $local_singulier_ou_pluriel = [];
4220
+
4221
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4222
+    if (!is_numeric($nb) or $nb == 0) {
4223
+        return '';
4224
+    }
4225
+    if (!is_array($vars)) {
4226
+        return '';
4227
+    }
4228
+
4229
+    $langue = $GLOBALS['spip_lang'];
4230
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4231
+        $local_singulier_ou_pluriel[$langue] = false;
4232
+        if (
4233
+            $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4234
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4235
+        ) {
4236
+            $local_singulier_ou_pluriel[$langue] = $f;
4237
+        }
4238
+    }
4239
+
4240
+    // si on a une surcharge on l'utilise
4241
+    if ($local_singulier_ou_pluriel[$langue]) {
4242
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4243
+    }
4244
+
4245
+    // sinon traitement par defaut
4246
+    $vars[$var] = $nb;
4247
+    if ($nb >= 2) {
4248
+        return _T($chaine_plusieurs, $vars);
4249
+    } else {
4250
+        return _T($chaine_un, $vars);
4251
+    }
4252 4252
 }
4253 4253
 
4254 4254
 
@@ -4276,73 +4276,73 @@  discard block
 block discarded – undo
4276 4276
  */
4277 4277
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4278 4278
 
4279
-	$class_lien = $class_bouton = $class;
4280
-
4281
-	// Normaliser la fonction et compléter la classe en fonction
4282
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4283
-		$class_lien .= ' danger';
4284
-		$class_bouton .= ' btn_danger';
4285
-	} elseif ($fonction == 'rien.gif') {
4286
-		$fonction = '';
4287
-	} elseif ($fonction == 'delsafe') {
4288
-		$fonction = 'del';
4289
-	}
4290
-
4291
-	$fond_origine = $fond;
4292
-	// Remappage des icone : article-24.png+new => article-new-24.png
4293
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4294
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4295
-	}
4296
-
4297
-	// Ajouter le type d'objet dans la classe
4298
-	$objet_type = substr(basename($fond), 0, -4);
4299
-	$class_lien .= " $objet_type";
4300
-	$class_bouton .= " $objet_type";
4301
-
4302
-	// Texte
4303
-	$alt = attribut_html($texte);
4304
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4305
-
4306
-	// Liens : préparer les classes ajax
4307
-	$ajax = '';
4308
-	if ($type === 'lien') {
4309
-		if (strpos($class_lien, 'ajax') !== false) {
4310
-			$ajax = 'ajax';
4311
-			if (strpos($class_lien, 'preload') !== false) {
4312
-				$ajax .= ' preload';
4313
-			}
4314
-			if (strpos($class_lien, 'nocache') !== false) {
4315
-				$ajax .= ' nocache';
4316
-			}
4317
-			$ajax = " class='$ajax'";
4318
-		}
4319
-	}
4320
-
4321
-	// Repérer la taille et l'ajouter dans la classe
4322
-	$size = 24;
4323
-	if (
4324
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4325
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4326
-	) {
4327
-		$size = $match[1];
4328
-	}
4329
-	$class_lien .= " s$size";
4330
-	$class_bouton .= " s$size";
4331
-
4332
-	// Icône
4333
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4334
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4335
-
4336
-	// Markup final
4337
-	if ($type == 'lien') {
4338
-		return "<span class='icone $class_lien'>"
4339
-		. "<a href='$lien'$title$ajax$javascript>"
4340
-		. $icone
4341
-		. "<b>$texte</b>"
4342
-		. "</a></span>\n";
4343
-	} else {
4344
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4345
-	}
4279
+    $class_lien = $class_bouton = $class;
4280
+
4281
+    // Normaliser la fonction et compléter la classe en fonction
4282
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4283
+        $class_lien .= ' danger';
4284
+        $class_bouton .= ' btn_danger';
4285
+    } elseif ($fonction == 'rien.gif') {
4286
+        $fonction = '';
4287
+    } elseif ($fonction == 'delsafe') {
4288
+        $fonction = 'del';
4289
+    }
4290
+
4291
+    $fond_origine = $fond;
4292
+    // Remappage des icone : article-24.png+new => article-new-24.png
4293
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4294
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4295
+    }
4296
+
4297
+    // Ajouter le type d'objet dans la classe
4298
+    $objet_type = substr(basename($fond), 0, -4);
4299
+    $class_lien .= " $objet_type";
4300
+    $class_bouton .= " $objet_type";
4301
+
4302
+    // Texte
4303
+    $alt = attribut_html($texte);
4304
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4305
+
4306
+    // Liens : préparer les classes ajax
4307
+    $ajax = '';
4308
+    if ($type === 'lien') {
4309
+        if (strpos($class_lien, 'ajax') !== false) {
4310
+            $ajax = 'ajax';
4311
+            if (strpos($class_lien, 'preload') !== false) {
4312
+                $ajax .= ' preload';
4313
+            }
4314
+            if (strpos($class_lien, 'nocache') !== false) {
4315
+                $ajax .= ' nocache';
4316
+            }
4317
+            $ajax = " class='$ajax'";
4318
+        }
4319
+    }
4320
+
4321
+    // Repérer la taille et l'ajouter dans la classe
4322
+    $size = 24;
4323
+    if (
4324
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4325
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4326
+    ) {
4327
+        $size = $match[1];
4328
+    }
4329
+    $class_lien .= " s$size";
4330
+    $class_bouton .= " s$size";
4331
+
4332
+    // Icône
4333
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4334
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4335
+
4336
+    // Markup final
4337
+    if ($type == 'lien') {
4338
+        return "<span class='icone $class_lien'>"
4339
+        . "<a href='$lien'$title$ajax$javascript>"
4340
+        . $icone
4341
+        . "<b>$texte</b>"
4342
+        . "</a></span>\n";
4343
+    } else {
4344
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4345
+    }
4346 4346
 }
4347 4347
 
4348 4348
 /**
@@ -4366,7 +4366,7 @@  discard block
 block discarded – undo
4366 4366
  *     Code HTML du lien
4367 4367
  **/
4368 4368
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4369
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4369
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4370 4370
 }
4371 4371
 
4372 4372
 /**
@@ -4401,7 +4401,7 @@  discard block
 block discarded – undo
4401 4401
  *     Code HTML du lien
4402 4402
  **/
4403 4403
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4404
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4404
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4405 4405
 }
4406 4406
 
4407 4407
 /**
@@ -4446,7 +4446,7 @@  discard block
 block discarded – undo
4446 4446
  *     Code HTML du lien
4447 4447
  **/
4448 4448
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4449
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4449
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4450 4450
 }
4451 4451
 
4452 4452
 /**
@@ -4477,7 +4477,7 @@  discard block
 block discarded – undo
4477 4477
  *     Code HTML du lien
4478 4478
  **/
4479 4479
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4480
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4480
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4481 4481
 }
4482 4482
 
4483 4483
 /**
@@ -4508,7 +4508,7 @@  discard block
 block discarded – undo
4508 4508
  *     Code HTML du lien
4509 4509
  */
4510 4510
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4511
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4511
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4512 4512
 }
4513 4513
 
4514 4514
 
@@ -4530,7 +4530,7 @@  discard block
 block discarded – undo
4530 4530
  * @return array Liste des éléments
4531 4531
  */
4532 4532
 function filtre_explode_dist($a, $b) {
4533
-	return explode($b, (string) $a);
4533
+    return explode($b, (string) $a);
4534 4534
 }
4535 4535
 
4536 4536
 /**
@@ -4551,7 +4551,7 @@  discard block
 block discarded – undo
4551 4551
  * @return string Texte
4552 4552
  */
4553 4553
 function filtre_implode_dist($a, $b) {
4554
-	return is_array($a) ? implode($b, $a) : $a;
4554
+    return is_array($a) ? implode($b, $a) : $a;
4555 4555
 }
4556 4556
 
4557 4557
 /**
@@ -4560,22 +4560,22 @@  discard block
 block discarded – undo
4560 4560
  * @return string Code CSS
4561 4561
  */
4562 4562
 function bando_images_background() {
4563
-	include_spip('inc/bandeau');
4564
-	// recuperer tous les boutons et leurs images
4565
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4563
+    include_spip('inc/bandeau');
4564
+    // recuperer tous les boutons et leurs images
4565
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4566 4566
 
4567
-	$res = '';
4568
-	foreach ($boutons as $page => $detail) {
4569
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4570
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4571
-			if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4572
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4573
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4574
-			}
4575
-		}
4576
-	}
4567
+    $res = '';
4568
+    foreach ($boutons as $page => $detail) {
4569
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4570
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4571
+            if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4572
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4573
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4574
+            }
4575
+        }
4576
+    }
4577 4577
 
4578
-	return $res;
4578
+    return $res;
4579 4579
 }
4580 4580
 
4581 4581
 /**
@@ -4600,27 +4600,27 @@  discard block
 block discarded – undo
4600 4600
  */
4601 4601
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4602 4602
 
4603
-	// Classes : dispatcher `ajax` sur le formulaire
4604
-	$class_form = '';
4605
-	if (strpos($class, 'ajax') !== false) {
4606
-		$class_form = 'ajax';
4607
-		$class = str_replace('ajax', '', $class);
4608
-	}
4609
-	$class_btn = 'submit ' . trim($class);
4603
+    // Classes : dispatcher `ajax` sur le formulaire
4604
+    $class_form = '';
4605
+    if (strpos($class, 'ajax') !== false) {
4606
+        $class_form = 'ajax';
4607
+        $class = str_replace('ajax', '', $class);
4608
+    }
4609
+    $class_btn = 'submit ' . trim($class);
4610 4610
 
4611
-	if ($confirm) {
4612
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4613
-		if ($callback) {
4614
-			$callback = "$confirm?($callback):false";
4615
-		} else {
4616
-			$callback = $confirm;
4617
-		}
4618
-	}
4619
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4620
-	$title = $title ? " title='$title'" : '';
4611
+    if ($confirm) {
4612
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4613
+        if ($callback) {
4614
+            $callback = "$confirm?($callback):false";
4615
+        } else {
4616
+            $callback = $confirm;
4617
+        }
4618
+    }
4619
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4620
+    $title = $title ? " title='$title'" : '';
4621 4621
 
4622
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4623
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4622
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4623
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4624 4624
 }
4625 4625
 
4626 4626
 /**
@@ -4643,101 +4643,101 @@  discard block
 block discarded – undo
4643 4643
  * @return string
4644 4644
  */
4645 4645
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4646
-	static $trouver_table = null;
4647
-	static $objets;
4648
-
4649
-	// On verifie qu'on a tout ce qu'il faut
4650
-	$id_objet = intval($id_objet);
4651
-	if (!($id_objet and $type_objet and $info)) {
4652
-		return '';
4653
-	}
4654
-
4655
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4656
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4657
-		return '';
4658
-	}
4659
-
4660
-	// Si on demande l'url, on retourne direct la fonction
4661
-	if ($info == 'url') {
4662
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4663
-	}
4664
-
4665
-	// Sinon on va tout chercher dans la table et on garde en memoire
4666
-	$demande_titre = ($info === 'titre');
4667
-	$demande_introduction = ($info === 'introduction');
4668
-
4669
-	// 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
4670
-	if (
4671
-		!isset($objets[$type_objet][$id_objet])
4672
-		or
4673
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4674
-	) {
4675
-		if (!$trouver_table) {
4676
-			$trouver_table = charger_fonction('trouver_table', 'base');
4677
-		}
4678
-		$desc = $trouver_table(table_objet_sql($type_objet));
4679
-		if (!$desc) {
4680
-			return $objets[$type_objet] = false;
4681
-		}
4682
-
4683
-		// Si on demande le titre, on le gere en interne
4684
-		$champ_titre = '';
4685
-		if ($demande_titre) {
4686
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4687
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4688
-		}
4689
-		include_spip('base/abstract_sql');
4690
-		include_spip('base/connect_sql');
4691
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4692
-			'*' . $champ_titre,
4693
-			$desc['table_sql'],
4694
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4695
-		);
4696
-
4697
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4698
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4699
-	}
4700
-
4701
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4702
-	// ajouter la longueur au début des params supplémentaires
4703
-	if ($demande_introduction) {
4704
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4705
-		array_unshift($params, $introduction_longueur);
4706
-	}
4707
-
4708
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4709
-	if (
4710
-		$generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4711
-		// @deprecated 4.1 generer_TRUC_TYPE
4712
-		or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4713
-	) {
4714
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4715
-	}
4716
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4717
-	elseif (
4718
-		$generer = charger_fonction("generer_objet_{$info}", '', true)
4719
-		// @deprecated 4.1 generer_TRUC_entite
4720
-		or $generer = charger_fonction("generer_{$info}_entite", '', true)
4721
-	) {
4722
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4723
-	} // Sinon on prend directement le champ SQL tel quel
4724
-	else {
4725
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4726
-	}
4727
-
4728
-	// On va ensuite appliquer les traitements automatiques si besoin
4729
-	if (!$etoile) {
4730
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4731
-		// mais ce fonctionnement est a ameliorer !
4732
-		$info_generee = appliquer_traitement_champ(
4733
-			$info_generee,
4734
-			$info,
4735
-			table_objet($type_objet),
4736
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4737
-		);
4738
-	}
4739
-
4740
-	return $info_generee;
4646
+    static $trouver_table = null;
4647
+    static $objets;
4648
+
4649
+    // On verifie qu'on a tout ce qu'il faut
4650
+    $id_objet = intval($id_objet);
4651
+    if (!($id_objet and $type_objet and $info)) {
4652
+        return '';
4653
+    }
4654
+
4655
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4656
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4657
+        return '';
4658
+    }
4659
+
4660
+    // Si on demande l'url, on retourne direct la fonction
4661
+    if ($info == 'url') {
4662
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4663
+    }
4664
+
4665
+    // Sinon on va tout chercher dans la table et on garde en memoire
4666
+    $demande_titre = ($info === 'titre');
4667
+    $demande_introduction = ($info === 'introduction');
4668
+
4669
+    // 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
4670
+    if (
4671
+        !isset($objets[$type_objet][$id_objet])
4672
+        or
4673
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4674
+    ) {
4675
+        if (!$trouver_table) {
4676
+            $trouver_table = charger_fonction('trouver_table', 'base');
4677
+        }
4678
+        $desc = $trouver_table(table_objet_sql($type_objet));
4679
+        if (!$desc) {
4680
+            return $objets[$type_objet] = false;
4681
+        }
4682
+
4683
+        // Si on demande le titre, on le gere en interne
4684
+        $champ_titre = '';
4685
+        if ($demande_titre) {
4686
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4687
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4688
+        }
4689
+        include_spip('base/abstract_sql');
4690
+        include_spip('base/connect_sql');
4691
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4692
+            '*' . $champ_titre,
4693
+            $desc['table_sql'],
4694
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4695
+        );
4696
+
4697
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4698
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4699
+    }
4700
+
4701
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4702
+    // ajouter la longueur au début des params supplémentaires
4703
+    if ($demande_introduction) {
4704
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4705
+        array_unshift($params, $introduction_longueur);
4706
+    }
4707
+
4708
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4709
+    if (
4710
+        $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4711
+        // @deprecated 4.1 generer_TRUC_TYPE
4712
+        or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4713
+    ) {
4714
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4715
+    }
4716
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4717
+    elseif (
4718
+        $generer = charger_fonction("generer_objet_{$info}", '', true)
4719
+        // @deprecated 4.1 generer_TRUC_entite
4720
+        or $generer = charger_fonction("generer_{$info}_entite", '', true)
4721
+    ) {
4722
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4723
+    } // Sinon on prend directement le champ SQL tel quel
4724
+    else {
4725
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4726
+    }
4727
+
4728
+    // On va ensuite appliquer les traitements automatiques si besoin
4729
+    if (!$etoile) {
4730
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4731
+        // mais ce fonctionnement est a ameliorer !
4732
+        $info_generee = appliquer_traitement_champ(
4733
+            $info_generee,
4734
+            $info,
4735
+            table_objet($type_objet),
4736
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4737
+        );
4738
+    }
4739
+
4740
+    return $info_generee;
4741 4741
 }
4742 4742
 
4743 4743
 /**
@@ -4745,7 +4745,7 @@  discard block
 block discarded – undo
4745 4745
  * @see generer_objet_info
4746 4746
  */
4747 4747
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4748
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4748
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4749 4749
 }
4750 4750
 
4751 4751
 /**
@@ -4778,36 +4778,36 @@  discard block
 block discarded – undo
4778 4778
  */
4779 4779
 function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string {
4780 4780
 
4781
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4782
-	$texte = $ligne_sql['texte'] ?? '';
4783
-	// En absence de descriptif, on se rabat sur chapo + texte
4784
-	if (isset($ligne_sql['chapo'])) {
4785
-		$chapo = $ligne_sql['chapo'];
4786
-		$texte = strlen($descriptif) ?
4787
-			'' :
4788
-			"$chapo \n\n $texte";
4789
-	}
4781
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4782
+    $texte = $ligne_sql['texte'] ?? '';
4783
+    // En absence de descriptif, on se rabat sur chapo + texte
4784
+    if (isset($ligne_sql['chapo'])) {
4785
+        $chapo = $ligne_sql['chapo'];
4786
+        $texte = strlen($descriptif) ?
4787
+            '' :
4788
+            "$chapo \n\n $texte";
4789
+    }
4790 4790
 
4791
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4792
-	if (!intval($longueur_ou_suite)) {
4793
-		$longueur = intval($introduction_longueur ?: 600);
4794
-	} else {
4795
-		$longueur = intval($longueur_ou_suite);
4796
-	}
4791
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4792
+    if (!intval($longueur_ou_suite)) {
4793
+        $longueur = intval($introduction_longueur ?: 600);
4794
+    } else {
4795
+        $longueur = intval($longueur_ou_suite);
4796
+    }
4797 4797
 
4798
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4799
-	// Ex : #INTRODUCTION{...}
4800
-	if (
4801
-		is_null($suite)
4802
-		and !intval($longueur_ou_suite)
4803
-	) {
4804
-		$suite = $longueur_ou_suite;
4805
-	}
4798
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4799
+    // Ex : #INTRODUCTION{...}
4800
+    if (
4801
+        is_null($suite)
4802
+        and !intval($longueur_ou_suite)
4803
+    ) {
4804
+        $suite = $longueur_ou_suite;
4805
+    }
4806 4806
 
4807
-	$f = chercher_filtre('introduction');
4808
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4807
+    $f = chercher_filtre('introduction');
4808
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4809 4809
 
4810
-	return $introduction;
4810
+    return $introduction;
4811 4811
 }
4812 4812
 
4813 4813
 /**
@@ -4815,7 +4815,7 @@  discard block
 block discarded – undo
4815 4815
  * @see generer_objet_introduction
4816 4816
  */
4817 4817
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4818
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4818
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4819 4819
 }
4820 4820
 
4821 4821
 /**
@@ -4829,49 +4829,49 @@  discard block
 block discarded – undo
4829 4829
  * @return string
4830 4830
  */
4831 4831
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4832
-	if (!$champ) {
4833
-		return $texte;
4834
-	}
4832
+    if (!$champ) {
4833
+        return $texte;
4834
+    }
4835 4835
 
4836
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4837
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4838
-	include_fichiers_fonctions();
4836
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4837
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4838
+    include_fichiers_fonctions();
4839 4839
 
4840
-	$champ = strtoupper($champ);
4841
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4842
-	if (!$traitements or !is_array($traitements)) {
4843
-		return $texte;
4844
-	}
4840
+    $champ = strtoupper($champ);
4841
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4842
+    if (!$traitements or !is_array($traitements)) {
4843
+        return $texte;
4844
+    }
4845 4845
 
4846
-	$traitement = '';
4847
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4848
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4849
-		$table_objet = table_objet($table_objet);
4850
-		if (isset($traitements[$table_objet])) {
4851
-			$traitement = $traitements[$table_objet];
4852
-		}
4853
-	}
4854
-	if (!$traitement and isset($traitements[0])) {
4855
-		$traitement = $traitements[0];
4856
-	}
4857
-	// (sinon prendre le premier de la liste par defaut ?)
4846
+    $traitement = '';
4847
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4848
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4849
+        $table_objet = table_objet($table_objet);
4850
+        if (isset($traitements[$table_objet])) {
4851
+            $traitement = $traitements[$table_objet];
4852
+        }
4853
+    }
4854
+    if (!$traitement and isset($traitements[0])) {
4855
+        $traitement = $traitements[0];
4856
+    }
4857
+    // (sinon prendre le premier de la liste par defaut ?)
4858 4858
 
4859
-	if (!$traitement) {
4860
-		return $texte;
4861
-	}
4859
+    if (!$traitement) {
4860
+        return $texte;
4861
+    }
4862 4862
 
4863
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4863
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4864 4864
 
4865
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4866
-	if (test_espace_prive()) {
4867
-		$env['espace_prive'] = 1;
4868
-	}
4865
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4866
+    if (test_espace_prive()) {
4867
+        $env['espace_prive'] = 1;
4868
+    }
4869 4869
 
4870
-	// Fournir $connect et $Pile[0] au traitement si besoin
4871
-	$Pile = [0 => $env];
4872
-	eval("\$texte = $traitement;");
4870
+    // Fournir $connect et $Pile[0] au traitement si besoin
4871
+    $Pile = [0 => $env];
4872
+    eval("\$texte = $traitement;");
4873 4873
 
4874
-	return $texte;
4874
+    return $texte;
4875 4875
 }
4876 4876
 
4877 4877
 
@@ -4885,21 +4885,21 @@  discard block
 block discarded – undo
4885 4885
  * @return string
4886 4886
  */
4887 4887
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4888
-	include_spip('inc/liens');
4889
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4890
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4891
-	// le raccourcis n'est plus valide
4892
-	$titre = typo($titre['titre'] ?? '');
4893
-	// on essaye avec generer_info_entite ?
4894
-	if (!strlen($titre) and !$connect) {
4895
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4896
-	}
4897
-	if (!strlen($titre)) {
4898
-		$titre = _T('info_sans_titre');
4899
-	}
4900
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4888
+    include_spip('inc/liens');
4889
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4890
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4891
+    // le raccourcis n'est plus valide
4892
+    $titre = typo($titre['titre'] ?? '');
4893
+    // on essaye avec generer_info_entite ?
4894
+    if (!strlen($titre) and !$connect) {
4895
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4896
+    }
4897
+    if (!strlen($titre)) {
4898
+        $titre = _T('info_sans_titre');
4899
+    }
4900
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4901 4901
 
4902
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4902
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4903 4903
 }
4904 4904
 
4905 4905
 /**
@@ -4907,7 +4907,7 @@  discard block
 block discarded – undo
4907 4907
  * @see generer_objet_lien
4908 4908
  */
4909 4909
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4910
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4910
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4911 4911
 }
4912 4912
 
4913 4913
 /**
@@ -4923,15 +4923,15 @@  discard block
 block discarded – undo
4923 4923
  * @return string
4924 4924
  */
4925 4925
 function wrap($texte, $wrap) {
4926
-	$balises = extraire_balises($wrap);
4927
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4928
-		$texte = $wrap . $texte;
4929
-		$regs = array_reverse($regs[1]);
4930
-		$wrap = '</' . implode('></', $regs) . '>';
4931
-		$texte = $texte . $wrap;
4932
-	}
4926
+    $balises = extraire_balises($wrap);
4927
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4928
+        $texte = $wrap . $texte;
4929
+        $regs = array_reverse($regs[1]);
4930
+        $wrap = '</' . implode('></', $regs) . '>';
4931
+        $texte = $texte . $wrap;
4932
+    }
4933 4933
 
4934
-	return $texte;
4934
+    return $texte;
4935 4935
 }
4936 4936
 
4937 4937
 
@@ -4951,44 +4951,44 @@  discard block
 block discarded – undo
4951 4951
  * @return array|mixed|string
4952 4952
  */
4953 4953
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4954
-	if (is_string($u)) {
4955
-		$u = typo($u);
4954
+    if (is_string($u)) {
4955
+        $u = typo($u);
4956 4956
 
4957
-		return $u;
4958
-	}
4957
+        return $u;
4958
+    }
4959 4959
 
4960
-	// caster $u en array si besoin
4961
-	if (is_object($u)) {
4962
-		$u = (array)$u;
4963
-	}
4960
+    // caster $u en array si besoin
4961
+    if (is_object($u)) {
4962
+        $u = (array)$u;
4963
+    }
4964 4964
 
4965
-	if (is_array($u)) {
4966
-		$out = '';
4967
-		// toutes les cles sont numeriques ?
4968
-		// et aucun enfant n'est un tableau
4969
-		// liste simple separee par des virgules
4970
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4971
-		$array_values = array_map('is_array', $u);
4972
-		$object_values = array_map('is_object', $u);
4973
-		if (
4974
-			array_sum($numeric_keys) == count($numeric_keys)
4975
-			and !array_sum($array_values)
4976
-			and !array_sum($object_values)
4977
-		) {
4978
-			return join(', ', array_map('filtre_print_dist', $u));
4979
-		}
4965
+    if (is_array($u)) {
4966
+        $out = '';
4967
+        // toutes les cles sont numeriques ?
4968
+        // et aucun enfant n'est un tableau
4969
+        // liste simple separee par des virgules
4970
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4971
+        $array_values = array_map('is_array', $u);
4972
+        $object_values = array_map('is_object', $u);
4973
+        if (
4974
+            array_sum($numeric_keys) == count($numeric_keys)
4975
+            and !array_sum($array_values)
4976
+            and !array_sum($object_values)
4977
+        ) {
4978
+            return join(', ', array_map('filtre_print_dist', $u));
4979
+        }
4980 4980
 
4981
-		// sinon on passe a la ligne et on indente
4982
-		$i_str = str_pad('', $indent, ' ');
4983
-		foreach ($u as $k => $v) {
4984
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4985
-		}
4981
+        // sinon on passe a la ligne et on indente
4982
+        $i_str = str_pad('', $indent, ' ');
4983
+        foreach ($u as $k => $v) {
4984
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4985
+        }
4986 4986
 
4987
-		return $out;
4988
-	}
4987
+        return $out;
4988
+    }
4989 4989
 
4990
-	// on sait pas quoi faire...
4991
-	return $u;
4990
+    // on sait pas quoi faire...
4991
+    return $u;
4992 4992
 }
4993 4993
 
4994 4994
 
@@ -5001,10 +5001,10 @@  discard block
 block discarded – undo
5001 5001
  * @return string|array
5002 5002
  */
5003 5003
 function objet_info($objet, $info) {
5004
-	$table = table_objet_sql($objet);
5005
-	$infos = lister_tables_objets_sql($table);
5004
+    $table = table_objet_sql($objet);
5005
+    $infos = lister_tables_objets_sql($table);
5006 5006
 
5007
-	return ($infos[$info] ?? '');
5007
+    return ($infos[$info] ?? '');
5008 5008
 }
5009 5009
 
5010 5010
 /**
@@ -5019,11 +5019,11 @@  discard block
 block discarded – undo
5019 5019
  *     Texte traduit du comptage, tel que '3 articles'
5020 5020
  */
5021 5021
 function objet_afficher_nb($nb, $objet) {
5022
-	if (!$nb) {
5023
-		return _T(objet_info($objet, 'info_aucun_objet'));
5024
-	} else {
5025
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5026
-	}
5022
+    if (!$nb) {
5023
+        return _T(objet_info($objet, 'info_aucun_objet'));
5024
+    } else {
5025
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5026
+    }
5027 5027
 }
5028 5028
 
5029 5029
 /**
@@ -5035,11 +5035,11 @@  discard block
 block discarded – undo
5035 5035
  * @return string
5036 5036
  */
5037 5037
 function objet_icone($objet, $taille = 24, $class = '') {
5038
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5039
-	$icone = chemin_image($icone);
5040
-	$balise_img = charger_filtre('balise_img');
5038
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5039
+    $icone = chemin_image($icone);
5040
+    $balise_img = charger_filtre('balise_img');
5041 5041
 
5042
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5042
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5043 5043
 }
5044 5044
 
5045 5045
 /**
@@ -5060,12 +5060,12 @@  discard block
 block discarded – undo
5060 5060
  * @return string
5061 5061
  */
5062 5062
 function objet_T($objet, $chaine, $args = [], $options = []) {
5063
-	$chaine = explode(':', $chaine);
5064
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5065
-		return $t;
5066
-	}
5067
-	$chaine = implode(':', $chaine);
5068
-	return _T($chaine, $args, $options);
5063
+    $chaine = explode(':', $chaine);
5064
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5065
+        return $t;
5066
+    }
5067
+    $chaine = implode(':', $chaine);
5068
+    return _T($chaine, $args, $options);
5069 5069
 }
5070 5070
 
5071 5071
 /**
@@ -5079,18 +5079,18 @@  discard block
 block discarded – undo
5079 5079
  * @return string      Code HTML
5080 5080
  */
5081 5081
 function insert_head_css_conditionnel($flux) {
5082
-	if (
5083
-		strpos($flux, '<!-- insert_head_css -->') === false
5084
-		and $p = strpos($flux, '<!-- insert_head -->')
5085
-	) {
5086
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5087
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5088
-			$p = $p1;
5089
-		}
5090
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5091
-	}
5082
+    if (
5083
+        strpos($flux, '<!-- insert_head_css -->') === false
5084
+        and $p = strpos($flux, '<!-- insert_head -->')
5085
+    ) {
5086
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5087
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5088
+            $p = $p1;
5089
+        }
5090
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5091
+    }
5092 5092
 
5093
-	return $flux;
5093
+    return $flux;
5094 5094
 }
5095 5095
 
5096 5096
 /**
@@ -5113,75 +5113,75 @@  discard block
 block discarded – undo
5113 5113
  * @return string
5114 5114
  */
5115 5115
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5116
-	if (isset($contexte['format'])) {
5117
-		$extension = $contexte['format'];
5118
-		unset($contexte['format']);
5119
-	} else {
5120
-		$extension = 'html';
5121
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5122
-			$extension = $m[1];
5123
-		}
5124
-	}
5125
-	// recuperer le contenu produit par le squelette
5126
-	$options['raw'] = true;
5127
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5128
-
5129
-	// calculer le nom de la css
5130
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5131
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5132
-	$contexte_implicite = calculer_contexte_implicite();
5133
-
5134
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5135
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5136
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5137
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5138
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5139
-	}
5140
-	else {
5141
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5142
-		ksort($contexte);
5143
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5144
-	}
5145
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5146
-
5147
-	// mettre a jour le fichier si il n'existe pas
5148
-	// ou trop ancien
5149
-	// le dernier fichier produit est toujours suffixe par .last
5150
-	// et recopie sur le fichier cible uniquement si il change
5151
-	if (
5152
-		!file_exists($filename)
5153
-		or !file_exists($filename . '.last')
5154
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5155
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5156
-	) {
5157
-		$contenu = $cache['texte'];
5158
-		// passer les urls en absolu si c'est une css
5159
-		if ($extension == 'css') {
5160
-			$contenu = urls_absolues_css(
5161
-				$contenu,
5162
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5163
-			);
5164
-		}
5165
-
5166
-		$comment = '';
5167
-		// ne pas insérer de commentaire sur certains formats
5168
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5169
-			$comment = "/* #PRODUIRE{fond=$fond";
5170
-			foreach ($contexte as $k => $v) {
5171
-				if (is_array($v)) {
5172
-					$v = var_export($v, true);
5173
-				}
5174
-				$comment .= ",$k=$v";
5175
-			}
5176
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5177
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5178
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5179
-		}
5180
-		// et ecrire le fichier si il change
5181
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5182
-	}
5183
-
5184
-	return timestamp($filename);
5116
+    if (isset($contexte['format'])) {
5117
+        $extension = $contexte['format'];
5118
+        unset($contexte['format']);
5119
+    } else {
5120
+        $extension = 'html';
5121
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5122
+            $extension = $m[1];
5123
+        }
5124
+    }
5125
+    // recuperer le contenu produit par le squelette
5126
+    $options['raw'] = true;
5127
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5128
+
5129
+    // calculer le nom de la css
5130
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5131
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5132
+    $contexte_implicite = calculer_contexte_implicite();
5133
+
5134
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5135
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5136
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5137
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5138
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5139
+    }
5140
+    else {
5141
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5142
+        ksort($contexte);
5143
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5144
+    }
5145
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5146
+
5147
+    // mettre a jour le fichier si il n'existe pas
5148
+    // ou trop ancien
5149
+    // le dernier fichier produit est toujours suffixe par .last
5150
+    // et recopie sur le fichier cible uniquement si il change
5151
+    if (
5152
+        !file_exists($filename)
5153
+        or !file_exists($filename . '.last')
5154
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5155
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5156
+    ) {
5157
+        $contenu = $cache['texte'];
5158
+        // passer les urls en absolu si c'est une css
5159
+        if ($extension == 'css') {
5160
+            $contenu = urls_absolues_css(
5161
+                $contenu,
5162
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5163
+            );
5164
+        }
5165
+
5166
+        $comment = '';
5167
+        // ne pas insérer de commentaire sur certains formats
5168
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5169
+            $comment = "/* #PRODUIRE{fond=$fond";
5170
+            foreach ($contexte as $k => $v) {
5171
+                if (is_array($v)) {
5172
+                    $v = var_export($v, true);
5173
+                }
5174
+                $comment .= ",$k=$v";
5175
+            }
5176
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5177
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5178
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5179
+        }
5180
+        // et ecrire le fichier si il change
5181
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5182
+    }
5183
+
5184
+    return timestamp($filename);
5185 5185
 }
5186 5186
 
5187 5187
 /**
@@ -5194,15 +5194,15 @@  discard block
 block discarded – undo
5194 5194
  *    $fichier auquel on a ajouté le timestamp
5195 5195
  */
5196 5196
 function timestamp($fichier) {
5197
-	if (
5198
-		!$fichier
5199
-		or !file_exists($fichier)
5200
-		or !$m = filemtime($fichier)
5201
-	) {
5202
-		return $fichier;
5203
-	}
5197
+    if (
5198
+        !$fichier
5199
+        or !file_exists($fichier)
5200
+        or !$m = filemtime($fichier)
5201
+    ) {
5202
+        return $fichier;
5203
+    }
5204 5204
 
5205
-	return "$fichier?$m";
5205
+    return "$fichier?$m";
5206 5206
 }
5207 5207
 
5208 5208
 /**
@@ -5212,11 +5212,11 @@  discard block
 block discarded – undo
5212 5212
  * @return string
5213 5213
  */
5214 5214
 function supprimer_timestamp($url) {
5215
-	if (strpos($url, '?') === false) {
5216
-		return $url;
5217
-	}
5215
+    if (strpos($url, '?') === false) {
5216
+        return $url;
5217
+    }
5218 5218
 
5219
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5219
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5220 5220
 }
5221 5221
 
5222 5222
 /**
@@ -5231,15 +5231,15 @@  discard block
 block discarded – undo
5231 5231
  * @return string
5232 5232
  */
5233 5233
 function filtre_nettoyer_titre_email_dist($titre) {
5234
-	include_spip('inc/envoyer_mail');
5234
+    include_spip('inc/envoyer_mail');
5235 5235
 
5236
-	$titre = nettoyer_titre_email($titre);
5237
-	// on est dans un squelette : securiser le retour
5238
-	if (strpos($titre, '<') !== false) {
5239
-		$titre = interdire_scripts($titre);
5240
-	}
5236
+    $titre = nettoyer_titre_email($titre);
5237
+    // on est dans un squelette : securiser le retour
5238
+    if (strpos($titre, '<') !== false) {
5239
+        $titre = interdire_scripts($titre);
5240
+    }
5241 5241
 
5242
-	return $titre;
5242
+    return $titre;
5243 5243
 }
5244 5244
 
5245 5245
 /**
@@ -5261,27 +5261,27 @@  discard block
 block discarded – undo
5261 5261
  * @return string
5262 5262
  */
5263 5263
 function filtre_chercher_rubrique_dist(
5264
-	$titre,
5265
-	$id_objet,
5266
-	$id_parent,
5267
-	$objet,
5268
-	$id_secteur,
5269
-	$restreint,
5270
-	$actionable = false,
5271
-	$retour_sans_cadre = false
5264
+    $titre,
5265
+    $id_objet,
5266
+    $id_parent,
5267
+    $objet,
5268
+    $id_secteur,
5269
+    $restreint,
5270
+    $actionable = false,
5271
+    $retour_sans_cadre = false
5272 5272
 ) {
5273
-	include_spip('inc/filtres_ecrire');
5273
+    include_spip('inc/filtres_ecrire');
5274 5274
 
5275
-	return chercher_rubrique(
5276
-		$titre,
5277
-		$id_objet,
5278
-		$id_parent,
5279
-		$objet,
5280
-		$id_secteur,
5281
-		$restreint,
5282
-		$actionable,
5283
-		$retour_sans_cadre
5284
-	);
5275
+    return chercher_rubrique(
5276
+        $titre,
5277
+        $id_objet,
5278
+        $id_parent,
5279
+        $objet,
5280
+        $id_secteur,
5281
+        $restreint,
5282
+        $actionable,
5283
+        $retour_sans_cadre
5284
+    );
5285 5285
 }
5286 5286
 
5287 5287
 /**
@@ -5310,56 +5310,56 @@  discard block
 block discarded – undo
5310 5310
  *     Chaîne vide si l'accès est autorisé
5311 5311
  */
5312 5312
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5313
-	if ($ok) {
5314
-		return '';
5315
-	}
5316
-
5317
-	// Vider tous les tampons
5318
-	$level = @ob_get_level();
5319
-	while ($level--) {
5320
-		@ob_end_clean();
5321
-	}
5322
-
5323
-	include_spip('inc/headers');
5324
-
5325
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5326
-	if ($url) {
5327
-		redirige_par_entete($url, '', $statut);
5328
-	}
5329
-
5330
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5331
-	if (!is_numeric($statut) and is_null($message)) {
5332
-		$message = $statut;
5333
-		$statut = 0;
5334
-	}
5335
-	if (!$message) {
5336
-		$message = '';
5337
-	}
5338
-	$statut = intval($statut);
5339
-
5340
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5341
-	if (test_espace_prive()) {
5342
-		if (!$statut or !in_array($statut, [404, 403])) {
5343
-			$statut = 403;
5344
-		}
5345
-		http_response_code(403);
5346
-		$echec = charger_fonction('403', 'exec');
5347
-		$echec($message);
5348
-	} else {
5349
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5350
-		if (!$statut) {
5351
-			$statut = 404;
5352
-		}
5353
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5354
-		http_response_code($statut);
5355
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5356
-		if ($statut >= 400) {
5357
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5358
-		}
5359
-	}
5360
-
5361
-
5362
-	exit;
5313
+    if ($ok) {
5314
+        return '';
5315
+    }
5316
+
5317
+    // Vider tous les tampons
5318
+    $level = @ob_get_level();
5319
+    while ($level--) {
5320
+        @ob_end_clean();
5321
+    }
5322
+
5323
+    include_spip('inc/headers');
5324
+
5325
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5326
+    if ($url) {
5327
+        redirige_par_entete($url, '', $statut);
5328
+    }
5329
+
5330
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5331
+    if (!is_numeric($statut) and is_null($message)) {
5332
+        $message = $statut;
5333
+        $statut = 0;
5334
+    }
5335
+    if (!$message) {
5336
+        $message = '';
5337
+    }
5338
+    $statut = intval($statut);
5339
+
5340
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5341
+    if (test_espace_prive()) {
5342
+        if (!$statut or !in_array($statut, [404, 403])) {
5343
+            $statut = 403;
5344
+        }
5345
+        http_response_code(403);
5346
+        $echec = charger_fonction('403', 'exec');
5347
+        $echec($message);
5348
+    } else {
5349
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5350
+        if (!$statut) {
5351
+            $statut = 404;
5352
+        }
5353
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5354
+        http_response_code($statut);
5355
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5356
+        if ($statut >= 400) {
5357
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5358
+        }
5359
+    }
5360
+
5361
+
5362
+    exit;
5363 5363
 }
5364 5364
 
5365 5365
 /**
@@ -5370,11 +5370,11 @@  discard block
 block discarded – undo
5370 5370
  * @return string
5371 5371
  */
5372 5372
 function filtre_compacte_dist($source, $format = null) {
5373
-	if (function_exists('minifier')) {
5374
-		return minifier($source, $format);
5375
-	}
5373
+    if (function_exists('minifier')) {
5374
+        return minifier($source, $format);
5375
+    }
5376 5376
 
5377
-	return $source;
5377
+    return $source;
5378 5378
 }
5379 5379
 
5380 5380
 
@@ -5386,32 +5386,32 @@  discard block
 block discarded – undo
5386 5386
  * @return string
5387 5387
  */
5388 5388
 function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5389
-	$passe ??= '';
5390
-	$l = strlen($passe);
5391
-
5392
-	if ($l <= 8 or !$afficher_partiellement) {
5393
-		if (!$l) {
5394
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5395
-		}
5396
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5397
-	}
5398
-
5399
-	if (is_null($portion_pourcent)) {
5400
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5401
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5402
-		}
5403
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5404
-	}
5405
-	if ($portion_pourcent >= 100) {
5406
-		return $passe;
5407
-	}
5408
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5409
-	$e = max($e, 0);
5410
-	$mid = str_pad('', $l - 2 * $e, '*');
5411
-	if ($e > 0 and strlen($mid) > 8) {
5412
-		$mid = '***...***';
5413
-	}
5414
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5389
+    $passe ??= '';
5390
+    $l = strlen($passe);
5391
+
5392
+    if ($l <= 8 or !$afficher_partiellement) {
5393
+        if (!$l) {
5394
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5395
+        }
5396
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5397
+    }
5398
+
5399
+    if (is_null($portion_pourcent)) {
5400
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5401
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5402
+        }
5403
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5404
+    }
5405
+    if ($portion_pourcent >= 100) {
5406
+        return $passe;
5407
+    }
5408
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5409
+    $e = max($e, 0);
5410
+    $mid = str_pad('', $l - 2 * $e, '*');
5411
+    if ($e > 0 and strlen($mid) > 8) {
5412
+        $mid = '***...***';
5413
+    }
5414
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5415 5415
 }
5416 5416
 
5417 5417
 
@@ -5432,64 +5432,64 @@  discard block
 block discarded – undo
5432 5432
  */
5433 5433
 function identifiant_slug($texte, $type = '', $options = []) {
5434 5434
 
5435
-	$original = $texte;
5436
-	$separateur = ($options['separateur'] ?? '_');
5437
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5438
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5435
+    $original = $texte;
5436
+    $separateur = ($options['separateur'] ?? '_');
5437
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5438
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5439 5439
 
5440
-	if (!function_exists('translitteration')) {
5441
-		include_spip('inc/charsets');
5442
-	}
5440
+    if (!function_exists('translitteration')) {
5441
+        include_spip('inc/charsets');
5442
+    }
5443 5443
 
5444
-	// pas de balise html
5445
-	if (strpos($texte, '<') !== false) {
5446
-		$texte = strip_tags($texte);
5447
-	}
5448
-	if (strpos($texte, '&') !== false) {
5449
-		$texte = unicode2charset($texte);
5450
-	}
5451
-	// On enlève les espaces indésirables
5452
-	$texte = trim($texte);
5444
+    // pas de balise html
5445
+    if (strpos($texte, '<') !== false) {
5446
+        $texte = strip_tags($texte);
5447
+    }
5448
+    if (strpos($texte, '&') !== false) {
5449
+        $texte = unicode2charset($texte);
5450
+    }
5451
+    // On enlève les espaces indésirables
5452
+    $texte = trim($texte);
5453 5453
 
5454
-	// On enlève les accents et cie
5455
-	$texte = translitteration($texte);
5454
+    // On enlève les accents et cie
5455
+    $texte = translitteration($texte);
5456 5456
 
5457
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5458
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5457
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5458
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5459 5459
 
5460
-	// nettoyer les doubles occurences du separateur si besoin
5461
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5462
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5463
-	}
5460
+    // nettoyer les doubles occurences du separateur si besoin
5461
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5462
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5463
+    }
5464 5464
 
5465
-	// pas de separateur au debut ni a la fin
5466
-	$texte = trim($texte, $separateur);
5465
+    // pas de separateur au debut ni a la fin
5466
+    $texte = trim($texte, $separateur);
5467 5467
 
5468
-	// en minuscules
5469
-	$texte = strtolower($texte);
5468
+    // en minuscules
5469
+    $texte = strtolower($texte);
5470 5470
 
5471
-	switch ($type) {
5472
-		case 'class':
5473
-		case 'id':
5474
-		case 'anchor':
5475
-			if (preg_match(',^\d,', $texte)) {
5476
-				$texte = substr($type, 0, 1) . $texte;
5477
-			}
5478
-	}
5471
+    switch ($type) {
5472
+        case 'class':
5473
+        case 'id':
5474
+        case 'anchor':
5475
+            if (preg_match(',^\d,', $texte)) {
5476
+                $texte = substr($type, 0, 1) . $texte;
5477
+            }
5478
+    }
5479 5479
 
5480
-	if (strlen($texte) > $longueur_maxi) {
5481
-		$texte = substr($texte, 0, $longueur_maxi);
5482
-	}
5480
+    if (strlen($texte) > $longueur_maxi) {
5481
+        $texte = substr($texte, 0, $longueur_maxi);
5482
+    }
5483 5483
 
5484
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5485
-		if (preg_match(',^\d,', $texte)) {
5486
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5487
-		}
5488
-		$texte .= $separateur . md5($original);
5489
-		$texte = substr($texte, 0, $longueur_mini);
5490
-	}
5484
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5485
+        if (preg_match(',^\d,', $texte)) {
5486
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5487
+        }
5488
+        $texte .= $separateur . md5($original);
5489
+        $texte = substr($texte, 0, $longueur_mini);
5490
+    }
5491 5491
 
5492
-	return $texte;
5492
+    return $texte;
5493 5493
 }
5494 5494
 
5495 5495
 
@@ -5510,11 +5510,11 @@  discard block
 block discarded – undo
5510 5510
  * @exemple `<:info_maximum|label_nettoyer:>`
5511 5511
  */
5512 5512
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5513
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5514
-	if ($ucfirst) {
5515
-		$label = spip_ucfirst($label);
5516
-	}
5517
-	return $label;
5513
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5514
+    if ($ucfirst) {
5515
+        $label = spip_ucfirst($label);
5516
+    }
5517
+    return $label;
5518 5518
 }
5519 5519
 
5520 5520
 /**
@@ -5527,8 +5527,8 @@  discard block
 block discarded – undo
5527 5527
  * @exemple `<:info_maximum|label_ponctuer:>`
5528 5528
  */
5529 5529
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5530
-	$label = label_nettoyer($text, $ucfirst);
5531
-	return _T('label_ponctuer', ['label' => $label]);
5530
+    $label = label_nettoyer($text, $ucfirst);
5531
+    return _T('label_ponctuer', ['label' => $label]);
5532 5532
 }
5533 5533
 
5534 5534
 
@@ -5541,19 +5541,19 @@  discard block
 block discarded – undo
5541 5541
  * @return array
5542 5542
  */
5543 5543
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5544
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5545
-		return [];
5546
-	}
5544
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5545
+        return [];
5546
+    }
5547 5547
 
5548
-	// compatibilite signature inversee
5549
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5550
-		[$objet, $id_objet] = [$id_objet, $objet];
5551
-	}
5548
+    // compatibilite signature inversee
5549
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5550
+        [$objet, $id_objet] = [$id_objet, $objet];
5551
+    }
5552 5552
 
5553
-	if (!function_exists($fonction)) {
5554
-		include_spip('base/objets');
5555
-	}
5556
-	return $fonction($objet, $id_objet);
5553
+    if (!function_exists($fonction)) {
5554
+        include_spip('base/objets');
5555
+    }
5556
+    return $fonction($objet, $id_objet);
5557 5557
 }
5558 5558
 
5559 5559
 
@@ -5568,7 +5568,7 @@  discard block
 block discarded – undo
5568 5568
  * @return array
5569 5569
  */
5570 5570
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5571
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5571
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5572 5572
 }
5573 5573
 
5574 5574
 /**
@@ -5582,7 +5582,7 @@  discard block
 block discarded – undo
5582 5582
  * @return array
5583 5583
  */
5584 5584
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5585
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5585
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5586 5586
 }
5587 5587
 
5588 5588
 /**
@@ -5596,7 +5596,7 @@  discard block
 block discarded – undo
5596 5596
  * @return array
5597 5597
  */
5598 5598
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5599
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5599
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5600 5600
 }
5601 5601
 
5602 5602
 /**
@@ -5610,5 +5610,5 @@  discard block
 block discarded – undo
5610 5610
  * @return array
5611 5611
  */
5612 5612
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5613
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5613
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5614 5614
 }
Please login to merge, or discard this patch.