Completed
Push — master ( 61df1d...15b76a )
by cam
01:10
created
ecrire/inc/filtres_images_lib_mini.php 1 patch
Indentation   +1328 added lines, -1328 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
  */
19 19
 
20 20
 if (!defined('_ECRIRE_INC_VERSION')) {
21
-	return;
21
+    return;
22 22
 }
23 23
 include_spip('inc/filtres'); // par precaution
24 24
 include_spip('inc/filtres_images_mini'); // par precaution
@@ -38,21 +38,21 @@  discard block
 block discarded – undo
38 38
  *     Le code de la couleur en hexadécimal.
39 39
  */
40 40
 function _couleur_dec_to_hex($red, $green, $blue) {
41
-	$red = dechex($red);
42
-	$green = dechex($green);
43
-	$blue = dechex($blue);
44
-
45
-	if (strlen($red) == 1) {
46
-		$red = '0' . $red;
47
-	}
48
-	if (strlen($green) == 1) {
49
-		$green = '0' . $green;
50
-	}
51
-	if (strlen($blue) == 1) {
52
-		$blue = '0' . $blue;
53
-	}
54
-
55
-	return "$red$green$blue";
41
+    $red = dechex($red);
42
+    $green = dechex($green);
43
+    $blue = dechex($blue);
44
+
45
+    if (strlen($red) == 1) {
46
+        $red = '0' . $red;
47
+    }
48
+    if (strlen($green) == 1) {
49
+        $green = '0' . $green;
50
+    }
51
+    if (strlen($blue) == 1) {
52
+        $blue = '0' . $blue;
53
+    }
54
+
55
+    return "$red$green$blue";
56 56
 }
57 57
 
58 58
 /**
@@ -64,18 +64,18 @@  discard block
 block discarded – undo
64 64
  *     Un tableau des 3 éléments : rouge, vert, bleu.
65 65
  */
66 66
 function _couleur_hex_to_dec($couleur) {
67
-	$couleur ??= '';
68
-	$couleur = couleur_html_to_hex($couleur);
69
-	$couleur = ltrim($couleur, '#');
70
-	if (strlen($couleur) === 3) {
71
-		$couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
72
-	}
73
-	$retour = [];
74
-	$retour['red'] = hexdec(substr($couleur, 0, 2));
75
-	$retour['green'] = hexdec(substr($couleur, 2, 2));
76
-	$retour['blue'] = hexdec(substr($couleur, 4, 2));
77
-
78
-	return $retour;
67
+    $couleur ??= '';
68
+    $couleur = couleur_html_to_hex($couleur);
69
+    $couleur = ltrim($couleur, '#');
70
+    if (strlen($couleur) === 3) {
71
+        $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2];
72
+    }
73
+    $retour = [];
74
+    $retour['red'] = hexdec(substr($couleur, 0, 2));
75
+    $retour['green'] = hexdec(substr($couleur, 2, 2));
76
+    $retour['blue'] = hexdec(substr($couleur, 4, 2));
77
+
78
+    return $retour;
79 79
 }
80 80
 
81 81
 
@@ -92,8 +92,8 @@  discard block
 block discarded – undo
92 92
  *     Le code de la couleur en hexadécimal.
93 93
  */
94 94
 function _couleur_hsl_to_hex($hue, $saturation, $lightness) {
95
-	$rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
96
-	return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
95
+    $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness);
96
+    return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
97 97
 }
98 98
 
99 99
 /**
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
  *     Un tableau des 3 éléments : teinte, saturation, luminosité.
106 106
  */
107 107
 function _couleur_hex_to_hsl($couleur) {
108
-	$rgb = _couleur_hex_to_dec($couleur);
109
-	return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
108
+    $rgb = _couleur_hex_to_dec($couleur);
109
+    return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']);
110 110
 }
111 111
 
112 112
 /**
@@ -121,59 +121,59 @@  discard block
 block discarded – undo
121 121
  * @return array
122 122
  */
123 123
 function _couleur_rgb_to_hsl($R, $G, $B) {
124
-	$H = null;
125
-	$var_R = ($R / 255); // Where RGB values = 0 ÷ 255
126
-	$var_G = ($G / 255);
127
-	$var_B = ($B / 255);
128
-
129
-	$var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
130
-	$var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
131
-	$del_Max = $var_Max - $var_Min;           //Delta RGB value
132
-
133
-	$L = ($var_Max + $var_Min) / 2;
134
-
135
-	if ($del_Max == 0) {
136
-		//This is a gray, no chroma...
137
-		$H = 0; //HSL results = 0 ÷ 1
138
-		$S = 0;
139
-	} else {
140
-		// Chromatic data...
141
-		if ($L < 0.5) {
142
-			$S = $del_Max / ($var_Max + $var_Min);
143
-		} else {
144
-			$S = $del_Max / (2 - $var_Max - $var_Min);
145
-		}
146
-
147
-		$del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
148
-		$del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
149
-		$del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
150
-
151
-		if ($var_R == $var_Max) {
152
-			$H = $del_B - $del_G;
153
-		} else {
154
-			if ($var_G == $var_Max) {
155
-				$H = (1 / 3) + $del_R - $del_B;
156
-			} else {
157
-				if ($var_B == $var_Max) {
158
-					$H = (2 / 3) + $del_G - $del_R;
159
-				}
160
-			}
161
-		}
162
-
163
-		if ($H < 0) {
164
-			$H += 1;
165
-		}
166
-		if ($H > 1) {
167
-			$H -= 1;
168
-		}
169
-	}
170
-
171
-	$ret = [];
172
-	$ret['h'] = $H;
173
-	$ret['s'] = $S;
174
-	$ret['l'] = $L;
175
-
176
-	return $ret;
124
+    $H = null;
125
+    $var_R = ($R / 255); // Where RGB values = 0 ÷ 255
126
+    $var_G = ($G / 255);
127
+    $var_B = ($B / 255);
128
+
129
+    $var_Min = min($var_R, $var_G, $var_B);   //Min. value of RGB
130
+    $var_Max = max($var_R, $var_G, $var_B);   //Max. value of RGB
131
+    $del_Max = $var_Max - $var_Min;           //Delta RGB value
132
+
133
+    $L = ($var_Max + $var_Min) / 2;
134
+
135
+    if ($del_Max == 0) {
136
+        //This is a gray, no chroma...
137
+        $H = 0; //HSL results = 0 ÷ 1
138
+        $S = 0;
139
+    } else {
140
+        // Chromatic data...
141
+        if ($L < 0.5) {
142
+            $S = $del_Max / ($var_Max + $var_Min);
143
+        } else {
144
+            $S = $del_Max / (2 - $var_Max - $var_Min);
145
+        }
146
+
147
+        $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max;
148
+        $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max;
149
+        $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max;
150
+
151
+        if ($var_R == $var_Max) {
152
+            $H = $del_B - $del_G;
153
+        } else {
154
+            if ($var_G == $var_Max) {
155
+                $H = (1 / 3) + $del_R - $del_B;
156
+            } else {
157
+                if ($var_B == $var_Max) {
158
+                    $H = (2 / 3) + $del_G - $del_R;
159
+                }
160
+            }
161
+        }
162
+
163
+        if ($H < 0) {
164
+            $H += 1;
165
+        }
166
+        if ($H > 1) {
167
+            $H -= 1;
168
+        }
169
+    }
170
+
171
+    $ret = [];
172
+    $ret['h'] = $H;
173
+    $ret['s'] = $S;
174
+    $ret['l'] = $L;
175
+
176
+    return $ret;
177 177
 }
178 178
 
179 179
 
@@ -189,52 +189,52 @@  discard block
 block discarded – undo
189 189
  * @return array
190 190
  */
191 191
 function _couleur_hsl_to_rgb($H, $S, $L) {
192
-	// helper
193
-	$hue_2_rgb = function ($v1, $v2, $vH) {
194
-		if ($vH < 0) {
195
-			$vH += 1;
196
-		}
197
-		if ($vH > 1) {
198
-			$vH -= 1;
199
-		}
200
-		if ((6 * $vH) < 1) {
201
-			return ($v1 + ($v2 - $v1) * 6 * $vH);
202
-		}
203
-		if ((2 * $vH) < 1) {
204
-			return ($v2);
205
-		}
206
-		if ((3 * $vH) < 2) {
207
-			return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
208
-		}
209
-
210
-		return ($v1);
211
-	};
212
-
213
-	if ($S == 0) {
214
-		// HSV values = 0 -> 1
215
-		$R = $L * 255;
216
-		$G = $L * 255;
217
-		$B = $L * 255;
218
-	} else {
219
-		if ($L < 0.5) {
220
-			$var_2 = $L * (1 + $S);
221
-		} else {
222
-			$var_2 = ($L + $S) - ($S * $L);
223
-		}
224
-
225
-		$var_1 = 2 * $L - $var_2;
226
-
227
-		$R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
228
-		$G = 255 * $hue_2_rgb($var_1, $var_2, $H);
229
-		$B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
230
-	}
231
-
232
-	$ret = [];
233
-	$ret['r'] = floor($R);
234
-	$ret['g'] = floor($G);
235
-	$ret['b'] = floor($B);
236
-
237
-	return $ret;
192
+    // helper
193
+    $hue_2_rgb = function ($v1, $v2, $vH) {
194
+        if ($vH < 0) {
195
+            $vH += 1;
196
+        }
197
+        if ($vH > 1) {
198
+            $vH -= 1;
199
+        }
200
+        if ((6 * $vH) < 1) {
201
+            return ($v1 + ($v2 - $v1) * 6 * $vH);
202
+        }
203
+        if ((2 * $vH) < 1) {
204
+            return ($v2);
205
+        }
206
+        if ((3 * $vH) < 2) {
207
+            return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6);
208
+        }
209
+
210
+        return ($v1);
211
+    };
212
+
213
+    if ($S == 0) {
214
+        // HSV values = 0 -> 1
215
+        $R = $L * 255;
216
+        $G = $L * 255;
217
+        $B = $L * 255;
218
+    } else {
219
+        if ($L < 0.5) {
220
+            $var_2 = $L * (1 + $S);
221
+        } else {
222
+            $var_2 = ($L + $S) - ($S * $L);
223
+        }
224
+
225
+        $var_1 = 2 * $L - $var_2;
226
+
227
+        $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3));
228
+        $G = 255 * $hue_2_rgb($var_1, $var_2, $H);
229
+        $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3));
230
+    }
231
+
232
+    $ret = [];
233
+    $ret['r'] = floor($R);
234
+    $ret['g'] = floor($G);
235
+    $ret['b'] = floor($B);
236
+
237
+    return $ret;
238 238
 }
239 239
 
240 240
 /**
@@ -252,11 +252,11 @@  discard block
 block discarded – undo
252 252
  *     true si il faut supprimer le fichier temporaire ; false sinon.
253 253
  */
254 254
 function statut_effacer_images_temporaires($stat) {
255
-	static $statut = false; // par defaut on grave toute les images
256
-	if ($stat === 'get') {
257
-		return $statut;
258
-	}
259
-	$statut = $stat ? true : false;
255
+    static $statut = false; // par defaut on grave toute les images
256
+    if ($stat === 'get') {
257
+        return $statut;
258
+    }
259
+    $statut = $stat ? true : false;
260 260
 }
261 261
 
262 262
 
@@ -309,247 +309,247 @@  discard block
 block discarded – undo
309 309
  *     - array : tableau décrivant de l'image
310 310
  */
311 311
 function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) {
312
-	$ret = [];
313
-	$f = null;
314
-	static $images_recalcul = [];
315
-	if (strlen($img) == 0) {
316
-		return false;
317
-	}
318
-
319
-	$source = trim(extraire_attribut($img, 'src') ?? '');
320
-	if (strlen($source) < 1) {
321
-		$source = $img;
322
-		$img = "<img src='$source' />";
323
-	} elseif (
324
-		preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
325
-		and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
326
-		and in_array($extension, _image_extensions_acceptees_en_entree())
327
-	) {
328
-		# gerer img src="data:....base64"
329
-		$local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
330
-		if (!file_exists($local)) {
331
-			ecrire_fichier($local, base64_decode($regs[2]));
332
-		}
333
-		if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
334
-			$sanitizer($local);
335
-		}
336
-		$source = $local;
337
-		$img = inserer_attribut($img, 'src', $source);
338
-		# eviter les mauvaises surprises lors de conversions de format
339
-		$img = inserer_attribut($img, 'width', '');
340
-		$img = inserer_attribut($img, 'height', '');
341
-	}
342
-
343
-	// les protocoles web prennent au moins 3 lettres
344
-	if (tester_url_absolue($source)) {
345
-		include_spip('inc/distant');
346
-		$fichier = _DIR_RACINE . copie_locale($source);
347
-		if (!$fichier) {
348
-			return '';
349
-		}
350
-		if (
351
-			$extension = _image_trouver_extension($fichier)
352
-			and $sanitizer = charger_fonction($extension, 'sanitizer', true)
353
-		) {
354
-			$sanitizer($fichier);
355
-		}
356
-	} else {
357
-		// enlever le timestamp eventuel
358
-		if (strpos($source, '?') !== false) {
359
-			$source = preg_replace(',[?][0-9]+$,', '', $source);
360
-		}
361
-		if (
362
-			strpos($source, '?') !== false
363
-			and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
364
-			and file_exists($f = preg_replace(',[?].*$,', '', $source))
365
-		) {
366
-			$source = $f;
367
-		}
368
-		$fichier = $source;
369
-	}
370
-
371
-	$terminaison_dest = '';
372
-	if ($terminaison = _image_trouver_extension($fichier)) {
373
-		$terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
374
-	}
375
-
376
-	if (
377
-		$forcer_format !== false
378
-		// ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
379
-		and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
380
-	) {
381
-		$terminaison_dest = $forcer_format;
382
-	}
383
-
384
-	if (!$terminaison_dest) {
385
-		return false;
386
-	}
387
-
388
-	$nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
389
-	$fichier_dest = $nom_fichier;
390
-	if (
391
-		($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
392
-		or @file_exists($f = $fichier)
393
-	) {
394
-		// on passe la balise img a taille image qui exraira les attributs si possible
395
-		// au lieu de faire un acces disque sur le fichier
396
-		[$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
397
-		$date_src = @filemtime($f);
398
-	} elseif (
399
-		@file_exists($f = "$fichier.src")
400
-		and lire_fichier($f, $valeurs)
401
-		and $valeurs = unserialize($valeurs)
402
-		and isset($valeurs['hauteur_dest'])
403
-		and isset($valeurs['largeur_dest'])
404
-	) {
405
-		$ret['hauteur'] = $valeurs['hauteur_dest'];
406
-		$ret['largeur'] = $valeurs['largeur_dest'];
407
-		$date_src = $valeurs['date'];
408
-	} // pas de fichier source par la
409
-	else {
410
-		return false;
411
-	}
412
-
413
-	// pas de taille mesurable ?
414
-	if (!$ret['hauteur']
415
-		or !($ret['hauteur'] = intval(round($ret['hauteur'])))
416
-		or !$ret['largeur']
417
-		or !($ret['largeur'] = intval(round($ret['largeur'])))
418
-	) {
419
-		return false;
420
-	}
421
-
422
-	// les images calculees dependent du chemin du fichier source
423
-	// pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
424
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
425
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
426
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
427
-	// alors que ca concerne peu de site au final
428
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
429
-	$identifiant = $fichier;
430
-
431
-	// cas general :
432
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
433
-	// cas particulier de reduire :
434
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
435
-	$cache = 'cache-gd2';
436
-	if (substr($effet, 0, 7) == 'reduire') {
437
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
438
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
439
-		$ret['largeur_dest'] = $destWidth;
440
-		$ret['hauteur_dest'] = $destHeight;
441
-		$effet = "L{$destWidth}xH$destHeight";
442
-		$cache = 'cache-vignettes';
443
-		$fichier_dest = basename($fichier_dest);
444
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
445
-			// on garde la terminaison initiale car image simplement copiee
446
-			// et on postfixe son nom avec un md5 du path
447
-			$terminaison_dest = $terminaison;
448
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
449
-		} else {
450
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
451
-		}
452
-		$cache = sous_repertoire(_DIR_VAR, $cache);
453
-		$cache = sous_repertoire($cache, $effet);
454
-	} else {
455
-		$fichier_dest = md5("$identifiant-$effet");
456
-		$cache = sous_repertoire(_DIR_VAR, $cache);
457
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
458
-		$fichier_dest = substr($fichier_dest, 2);
459
-	}
460
-
461
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
462
-
463
-	$GLOBALS['images_calculees'][] = $fichier_dest;
464
-
465
-	$creer = true;
466
-	// si recalcul des images demande, recalculer chaque image une fois
467
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
468
-		$images_recalcul[$fichier_dest] = true;
469
-	} else {
470
-		if (@file_exists($f = $fichier_dest)) {
471
-			if (filemtime($f) >= $date_src) {
472
-				$creer = false;
473
-			}
474
-		} else {
475
-			if (
476
-				@file_exists($f = "$fichier_dest.src")
477
-				and lire_fichier($f, $valeurs)
478
-				and $valeurs = unserialize($valeurs)
479
-				and $valeurs['date'] >= $date_src
480
-			) {
481
-				$creer = false;
482
-			}
483
-		}
484
-	}
485
-	if ($creer) {
486
-		if (!@file_exists($fichier)) {
487
-			if (!@file_exists("$fichier.src")) {
488
-				spip_log("Image absente : $fichier");
489
-
490
-				return false;
491
-			}
492
-			# on reconstruit l'image source absente a partir de la chaine des .src
493
-			reconstruire_image_intermediaire($fichier);
494
-		}
495
-	}
496
-
497
-	if ($creer) {
498
-		spip_log(
499
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
500
-			'images' . _LOG_DEBUG
501
-		);
502
-	}
503
-
504
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
505
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
506
-	$ret['fichier'] = $fichier;
507
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
508
-	$ret['fichier_dest'] = $fichier_dest;
509
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
510
-	$ret['format_dest'] = $terminaison_dest;
511
-	$ret['date_src'] = $date_src;
512
-	$ret['creer'] = $creer;
513
-	$ret['class'] = extraire_attribut($img, 'class');
514
-	$ret['alt'] = extraire_attribut($img, 'alt');
515
-	$ret['style'] = extraire_attribut($img, 'style');
516
-	$ret['tag'] = $img;
517
-	if ($fonction_creation) {
518
-		$ret['reconstruction'] = $fonction_creation;
519
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
520
-		# cas de image_reduire qui finalement ne reduit pas l'image source
521
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
522
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
523
-	}
524
-
525
-	$ret = pipeline('image_preparer_filtre', [
526
-			'args' => [
527
-				'img' => $img,
528
-				'effet' => $effet,
529
-				'forcer_format' => $forcer_format,
530
-				'fonction_creation' => $fonction_creation,
531
-				'find_in_path' => $find_in_path,
532
-			],
533
-			'data' => $ret
534
-		]);
535
-
536
-	// une globale pour le debug en cas de crash memoire
537
-	$GLOBALS['derniere_image_calculee'] = $ret;
538
-
539
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
540
-	if ($term_fonction === 'svg') {
541
-		if ($creer and !$support_svg) {
542
-			process_image_svg_identite($ret);
543
-			$ret['creer'] = false;
544
-		}
545
-	}
546
-	else {
547
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
548
-			return false;
549
-		}
550
-	}
551
-
552
-	return $ret;
312
+    $ret = [];
313
+    $f = null;
314
+    static $images_recalcul = [];
315
+    if (strlen($img) == 0) {
316
+        return false;
317
+    }
318
+
319
+    $source = trim(extraire_attribut($img, 'src') ?? '');
320
+    if (strlen($source) < 1) {
321
+        $source = $img;
322
+        $img = "<img src='$source' />";
323
+    } elseif (
324
+        preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs)
325
+        and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])
326
+        and in_array($extension, _image_extensions_acceptees_en_entree())
327
+    ) {
328
+        # gerer img src="data:....base64"
329
+        $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension);
330
+        if (!file_exists($local)) {
331
+            ecrire_fichier($local, base64_decode($regs[2]));
332
+        }
333
+        if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) {
334
+            $sanitizer($local);
335
+        }
336
+        $source = $local;
337
+        $img = inserer_attribut($img, 'src', $source);
338
+        # eviter les mauvaises surprises lors de conversions de format
339
+        $img = inserer_attribut($img, 'width', '');
340
+        $img = inserer_attribut($img, 'height', '');
341
+    }
342
+
343
+    // les protocoles web prennent au moins 3 lettres
344
+    if (tester_url_absolue($source)) {
345
+        include_spip('inc/distant');
346
+        $fichier = _DIR_RACINE . copie_locale($source);
347
+        if (!$fichier) {
348
+            return '';
349
+        }
350
+        if (
351
+            $extension = _image_trouver_extension($fichier)
352
+            and $sanitizer = charger_fonction($extension, 'sanitizer', true)
353
+        ) {
354
+            $sanitizer($fichier);
355
+        }
356
+    } else {
357
+        // enlever le timestamp eventuel
358
+        if (strpos($source, '?') !== false) {
359
+            $source = preg_replace(',[?][0-9]+$,', '', $source);
360
+        }
361
+        if (
362
+            strpos($source, '?') !== false
363
+            and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0
364
+            and file_exists($f = preg_replace(',[?].*$,', '', $source))
365
+        ) {
366
+            $source = $f;
367
+        }
368
+        $fichier = $source;
369
+    }
370
+
371
+    $terminaison_dest = '';
372
+    if ($terminaison = _image_trouver_extension($fichier)) {
373
+        $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison;
374
+    }
375
+
376
+    if (
377
+        $forcer_format !== false
378
+        // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image
379
+        and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie()))
380
+    ) {
381
+        $terminaison_dest = $forcer_format;
382
+    }
383
+
384
+    if (!$terminaison_dest) {
385
+        return false;
386
+    }
387
+
388
+    $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1));
389
+    $fichier_dest = $nom_fichier;
390
+    if (
391
+        ($find_in_path and $f = find_in_path($fichier) and $fichier = $f)
392
+        or @file_exists($f = $fichier)
393
+    ) {
394
+        // on passe la balise img a taille image qui exraira les attributs si possible
395
+        // au lieu de faire un acces disque sur le fichier
396
+        [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img);
397
+        $date_src = @filemtime($f);
398
+    } elseif (
399
+        @file_exists($f = "$fichier.src")
400
+        and lire_fichier($f, $valeurs)
401
+        and $valeurs = unserialize($valeurs)
402
+        and isset($valeurs['hauteur_dest'])
403
+        and isset($valeurs['largeur_dest'])
404
+    ) {
405
+        $ret['hauteur'] = $valeurs['hauteur_dest'];
406
+        $ret['largeur'] = $valeurs['largeur_dest'];
407
+        $date_src = $valeurs['date'];
408
+    } // pas de fichier source par la
409
+    else {
410
+        return false;
411
+    }
412
+
413
+    // pas de taille mesurable ?
414
+    if (!$ret['hauteur']
415
+        or !($ret['hauteur'] = intval(round($ret['hauteur'])))
416
+        or !$ret['largeur']
417
+        or !($ret['largeur'] = intval(round($ret['largeur'])))
418
+    ) {
419
+        return false;
420
+    }
421
+
422
+    // les images calculees dependent du chemin du fichier source
423
+    // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive
424
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
425
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
426
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
427
+    // alors que ca concerne peu de site au final
428
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
429
+    $identifiant = $fichier;
430
+
431
+    // cas general :
432
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
433
+    // cas particulier de reduire :
434
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
435
+    $cache = 'cache-gd2';
436
+    if (substr($effet, 0, 7) == 'reduire') {
437
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
438
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
439
+        $ret['largeur_dest'] = $destWidth;
440
+        $ret['hauteur_dest'] = $destHeight;
441
+        $effet = "L{$destWidth}xH$destHeight";
442
+        $cache = 'cache-vignettes';
443
+        $fichier_dest = basename($fichier_dest);
444
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
445
+            // on garde la terminaison initiale car image simplement copiee
446
+            // et on postfixe son nom avec un md5 du path
447
+            $terminaison_dest = $terminaison;
448
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
449
+        } else {
450
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
451
+        }
452
+        $cache = sous_repertoire(_DIR_VAR, $cache);
453
+        $cache = sous_repertoire($cache, $effet);
454
+    } else {
455
+        $fichier_dest = md5("$identifiant-$effet");
456
+        $cache = sous_repertoire(_DIR_VAR, $cache);
457
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
458
+        $fichier_dest = substr($fichier_dest, 2);
459
+    }
460
+
461
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
462
+
463
+    $GLOBALS['images_calculees'][] = $fichier_dest;
464
+
465
+    $creer = true;
466
+    // si recalcul des images demande, recalculer chaque image une fois
467
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
468
+        $images_recalcul[$fichier_dest] = true;
469
+    } else {
470
+        if (@file_exists($f = $fichier_dest)) {
471
+            if (filemtime($f) >= $date_src) {
472
+                $creer = false;
473
+            }
474
+        } else {
475
+            if (
476
+                @file_exists($f = "$fichier_dest.src")
477
+                and lire_fichier($f, $valeurs)
478
+                and $valeurs = unserialize($valeurs)
479
+                and $valeurs['date'] >= $date_src
480
+            ) {
481
+                $creer = false;
482
+            }
483
+        }
484
+    }
485
+    if ($creer) {
486
+        if (!@file_exists($fichier)) {
487
+            if (!@file_exists("$fichier.src")) {
488
+                spip_log("Image absente : $fichier");
489
+
490
+                return false;
491
+            }
492
+            # on reconstruit l'image source absente a partir de la chaine des .src
493
+            reconstruire_image_intermediaire($fichier);
494
+        }
495
+    }
496
+
497
+    if ($creer) {
498
+        spip_log(
499
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
500
+            'images' . _LOG_DEBUG
501
+        );
502
+    }
503
+
504
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
505
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
506
+    $ret['fichier'] = $fichier;
507
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
508
+    $ret['fichier_dest'] = $fichier_dest;
509
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
510
+    $ret['format_dest'] = $terminaison_dest;
511
+    $ret['date_src'] = $date_src;
512
+    $ret['creer'] = $creer;
513
+    $ret['class'] = extraire_attribut($img, 'class');
514
+    $ret['alt'] = extraire_attribut($img, 'alt');
515
+    $ret['style'] = extraire_attribut($img, 'style');
516
+    $ret['tag'] = $img;
517
+    if ($fonction_creation) {
518
+        $ret['reconstruction'] = $fonction_creation;
519
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
520
+        # cas de image_reduire qui finalement ne reduit pas l'image source
521
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
522
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
523
+    }
524
+
525
+    $ret = pipeline('image_preparer_filtre', [
526
+            'args' => [
527
+                'img' => $img,
528
+                'effet' => $effet,
529
+                'forcer_format' => $forcer_format,
530
+                'fonction_creation' => $fonction_creation,
531
+                'find_in_path' => $find_in_path,
532
+            ],
533
+            'data' => $ret
534
+        ]);
535
+
536
+    // une globale pour le debug en cas de crash memoire
537
+    $GLOBALS['derniere_image_calculee'] = $ret;
538
+
539
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
540
+    if ($term_fonction === 'svg') {
541
+        if ($creer and !$support_svg) {
542
+            process_image_svg_identite($ret);
543
+            $ret['creer'] = false;
544
+        }
545
+    }
546
+    else {
547
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
548
+            return false;
549
+        }
550
+    }
551
+
552
+    return $ret;
553 553
 }
554 554
 
555 555
 
@@ -558,54 +558,54 @@  discard block
 block discarded – undo
558 558
  * @return array
559 559
  */
560 560
 function _image_extensions_acceptees_en_entree() {
561
-	static $extensions = null;
562
-	if (empty($extensions)) {
563
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
564
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
565
-			// action=tester renseigne gd_formats et detecte le support de webp
566
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
567
-			$extensions = array_map('trim', $extensions);
568
-			$extensions = array_filter($extensions);
569
-			if (in_array('jpg', $extensions)) {
570
-				$extensions[] = 'jpeg';
571
-			}
572
-			$extensions = array_unique($extensions);
573
-		}
574
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
575
-	}
576
-
577
-	return $extensions;
561
+    static $extensions = null;
562
+    if (empty($extensions)) {
563
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
564
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
565
+            // action=tester renseigne gd_formats et detecte le support de webp
566
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
567
+            $extensions = array_map('trim', $extensions);
568
+            $extensions = array_filter($extensions);
569
+            if (in_array('jpg', $extensions)) {
570
+                $extensions[] = 'jpeg';
571
+            }
572
+            $extensions = array_unique($extensions);
573
+        }
574
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
575
+    }
576
+
577
+    return $extensions;
578 578
 }
579 579
 
580 580
 /**
581 581
  * @return array|string[]|null
582 582
  */
583 583
 function _image_extensions_acceptees_en_sortie() {
584
-	static $extensions = null;
585
-	if (empty($extensions)) {
586
-		$extensions = _image_extensions_acceptees_en_entree();
587
-		$extensions = array_diff($extensions, ['jpeg']);
588
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
589
-			$extensions = array_diff($extensions, ['gif']);
590
-		}
591
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
592
-			$extensions = array_diff($extensions, ['webp']);
593
-		}
594
-	}
595
-
596
-	return $extensions;
584
+    static $extensions = null;
585
+    if (empty($extensions)) {
586
+        $extensions = _image_extensions_acceptees_en_entree();
587
+        $extensions = array_diff($extensions, ['jpeg']);
588
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
589
+            $extensions = array_diff($extensions, ['gif']);
590
+        }
591
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
592
+            $extensions = array_diff($extensions, ['webp']);
593
+        }
594
+    }
595
+
596
+    return $extensions;
597 597
 }
598 598
 
599 599
 function _image_extension_normalisee($extension) {
600
-	$extension = strtolower($extension);
601
-	if ($extension === 'jpeg') {
602
-		$extension = 'jpg';
603
-	}
604
-	return $extension;
600
+    $extension = strtolower($extension);
601
+    if ($extension === 'jpeg') {
602
+        $extension = 'jpg';
603
+    }
604
+    return $extension;
605 605
 }
606 606
 
607 607
 function _image_extensions_conservent_transparence() {
608
-	return ['png', 'webp'];
608
+    return ['png', 'webp'];
609 609
 }
610 610
 
611 611
 
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
  * @return string
616 616
  */
617 617
 function _image_trouver_extension($path) {
618
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
619
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
620
-		$terminaison = strtolower($regs[1]);
621
-		return $terminaison;
622
-	}
623
-	return '';
618
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
619
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
620
+        $terminaison = strtolower($regs[1]);
621
+        return $terminaison;
622
+    }
623
+    return '';
624 624
 }
625 625
 
626 626
 /**
@@ -631,33 +631,33 @@  discard block
 block discarded – undo
631 631
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
632 632
  */
633 633
 function _image_trouver_extension_pertinente($path) {
634
-	$path = supprimer_timestamp($path);
635
-	$terminaison = _image_trouver_extension($path);
636
-	if ($terminaison == 'jpg') {
637
-		$terminaison = 'jpeg';
638
-	}
639
-
640
-	if (!file_exists($path)) {
641
-		return $terminaison;
642
-	}
643
-
644
-	if (!$info = @spip_getimagesize($path)) {
645
-		return $terminaison;
646
-	}
647
-
648
-	if (isset($info['mime'])) {
649
-		$mime = $info['mime'];
650
-	}
651
-	else {
652
-		$mime = image_type_to_mime_type($info[2]);
653
-	}
654
-
655
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
656
-	if ($_terminaison and $_terminaison !== $terminaison) {
657
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
658
-		$terminaison = $_terminaison;
659
-	}
660
-	return $terminaison;
634
+    $path = supprimer_timestamp($path);
635
+    $terminaison = _image_trouver_extension($path);
636
+    if ($terminaison == 'jpg') {
637
+        $terminaison = 'jpeg';
638
+    }
639
+
640
+    if (!file_exists($path)) {
641
+        return $terminaison;
642
+    }
643
+
644
+    if (!$info = @spip_getimagesize($path)) {
645
+        return $terminaison;
646
+    }
647
+
648
+    if (isset($info['mime'])) {
649
+        $mime = $info['mime'];
650
+    }
651
+    else {
652
+        $mime = image_type_to_mime_type($info[2]);
653
+    }
654
+
655
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
656
+    if ($_terminaison and $_terminaison !== $terminaison) {
657
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
658
+        $terminaison = $_terminaison;
659
+    }
660
+    return $terminaison;
661 661
 }
662 662
 
663 663
 /**
@@ -665,36 +665,36 @@  discard block
 block discarded – undo
665 665
  * @return string
666 666
  */
667 667
 function _image_trouver_extension_depuis_mime($mime) {
668
-	switch (strtolower($mime)) {
669
-		case 'image/png':
670
-		case 'image/x-png':
671
-			$terminaison = 'png';
672
-			break;
673
-
674
-		case 'image/jpg':
675
-		case 'image/jpeg':
676
-		case 'image/pjpeg':
677
-			$terminaison = 'jpeg';
678
-			break;
679
-
680
-		case 'image/gif':
681
-			$terminaison = 'gif';
682
-			break;
683
-
684
-		case 'image/webp':
685
-		case 'image/x-webp':
686
-			$terminaison = 'webp';
687
-			break;
688
-
689
-		case 'image/svg+xml':
690
-			$terminaison = 'svg';
691
-			break;
692
-
693
-		default:
694
-			$terminaison = '';
695
-	}
696
-
697
-	return $terminaison;
668
+    switch (strtolower($mime)) {
669
+        case 'image/png':
670
+        case 'image/x-png':
671
+            $terminaison = 'png';
672
+            break;
673
+
674
+        case 'image/jpg':
675
+        case 'image/jpeg':
676
+        case 'image/pjpeg':
677
+            $terminaison = 'jpeg';
678
+            break;
679
+
680
+        case 'image/gif':
681
+            $terminaison = 'gif';
682
+            break;
683
+
684
+        case 'image/webp':
685
+        case 'image/x-webp':
686
+            $terminaison = 'webp';
687
+            break;
688
+
689
+        case 'image/svg+xml':
690
+            $terminaison = 'svg';
691
+            break;
692
+
693
+        default:
694
+            $terminaison = '';
695
+    }
696
+
697
+    return $terminaison;
698 698
 }
699 699
 
700 700
 
@@ -714,18 +714,18 @@  discard block
 block discarded – undo
714 714
  *     Une ressource de type Image GD.
715 715
  */
716 716
 function _imagecreatefrom_func(string $func, string $filename) {
717
-	if (!function_exists($func)) {
718
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
719
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
720
-		return null;
721
-	}
722
-	$img = @$func($filename);
723
-	if (!$img) {
724
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
725
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
726
-		$img = imagecreate(10, 10);
727
-	}
728
-	return $img;
717
+    if (!function_exists($func)) {
718
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
719
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
720
+        return null;
721
+    }
722
+    $img = @$func($filename);
723
+    if (!$img) {
724
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
725
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
726
+        $img = imagecreate(10, 10);
727
+    }
728
+    return $img;
729 729
 }
730 730
 
731 731
 /**
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
  *     Une ressource de type Image GD.
742 742
  */
743 743
 function _imagecreatefromjpeg($filename) {
744
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
744
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
745 745
 }
746 746
 
747 747
 /**
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
  *     Une ressource de type Image GD.
758 758
  */
759 759
 function _imagecreatefrompng($filename) {
760
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
760
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
761 761
 }
762 762
 
763 763
 /**
@@ -773,7 +773,7 @@  discard block
 block discarded – undo
773 773
  *     Une ressource de type Image GD.
774 774
  */
775 775
 function _imagecreatefromgif($filename) {
776
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
776
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
777 777
 }
778 778
 
779 779
 
@@ -790,7 +790,7 @@  discard block
 block discarded – undo
790 790
  *     Une ressource de type Image GD.
791 791
  */
792 792
 function _imagecreatefromwebp($filename) {
793
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
793
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
794 794
 }
795 795
 
796 796
 /**
@@ -808,24 +808,24 @@  discard block
 block discarded – undo
808 808
  *     - true si une image est bien retournée.
809 809
  */
810 810
 function _image_imagepng($img, $fichier) {
811
-	if (!function_exists('imagepng')) {
812
-		return false;
813
-	}
814
-	$tmp = $fichier . '.tmp';
815
-	$ret = imagepng($img, $tmp);
816
-	if (file_exists($tmp)) {
817
-		$taille_test = getimagesize($tmp);
818
-		if ($taille_test[0] < 1) {
819
-			return false;
820
-		}
821
-
822
-		spip_unlink($fichier); // le fichier peut deja exister
823
-		@rename($tmp, $fichier);
824
-
825
-		return $ret;
826
-	}
827
-
828
-	return false;
811
+    if (!function_exists('imagepng')) {
812
+        return false;
813
+    }
814
+    $tmp = $fichier . '.tmp';
815
+    $ret = imagepng($img, $tmp);
816
+    if (file_exists($tmp)) {
817
+        $taille_test = getimagesize($tmp);
818
+        if ($taille_test[0] < 1) {
819
+            return false;
820
+        }
821
+
822
+        spip_unlink($fichier); // le fichier peut deja exister
823
+        @rename($tmp, $fichier);
824
+
825
+        return $ret;
826
+    }
827
+
828
+    return false;
829 829
 }
830 830
 
831 831
 /**
@@ -843,24 +843,24 @@  discard block
 block discarded – undo
843 843
  *     - true si une image est bien retournée.
844 844
  */
845 845
 function _image_imagegif($img, $fichier) {
846
-	if (!function_exists('imagegif')) {
847
-		return false;
848
-	}
849
-	$tmp = $fichier . '.tmp';
850
-	$ret = imagegif($img, $tmp);
851
-	if (file_exists($tmp)) {
852
-		$taille_test = getimagesize($tmp);
853
-		if ($taille_test[0] < 1) {
854
-			return false;
855
-		}
856
-
857
-		spip_unlink($fichier); // le fichier peut deja exister
858
-		@rename($tmp, $fichier);
859
-
860
-		return $ret;
861
-	}
862
-
863
-	return false;
846
+    if (!function_exists('imagegif')) {
847
+        return false;
848
+    }
849
+    $tmp = $fichier . '.tmp';
850
+    $ret = imagegif($img, $tmp);
851
+    if (file_exists($tmp)) {
852
+        $taille_test = getimagesize($tmp);
853
+        if ($taille_test[0] < 1) {
854
+            return false;
855
+        }
856
+
857
+        spip_unlink($fichier); // le fichier peut deja exister
858
+        @rename($tmp, $fichier);
859
+
860
+        return $ret;
861
+    }
862
+
863
+    return false;
864 864
 }
865 865
 
866 866
 /**
@@ -883,29 +883,29 @@  discard block
 block discarded – undo
883 883
  *     - true si une image est bien retournée.
884 884
  */
885 885
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
886
-	if (!function_exists('imagejpeg')) {
887
-		return false;
888
-	}
889
-	$tmp = $fichier . '.tmp';
886
+    if (!function_exists('imagejpeg')) {
887
+        return false;
888
+    }
889
+    $tmp = $fichier . '.tmp';
890 890
 
891
-	// Enable interlancing
892
-	imageinterlace($img, true);
891
+    // Enable interlancing
892
+    imageinterlace($img, true);
893 893
 
894
-	$ret = imagejpeg($img, $tmp, $qualite);
894
+    $ret = imagejpeg($img, $tmp, $qualite);
895 895
 
896
-	if (file_exists($tmp)) {
897
-		$taille_test = getimagesize($tmp);
898
-		if ($taille_test[0] < 1) {
899
-			return false;
900
-		}
896
+    if (file_exists($tmp)) {
897
+        $taille_test = getimagesize($tmp);
898
+        if ($taille_test[0] < 1) {
899
+            return false;
900
+        }
901 901
 
902
-		spip_unlink($fichier); // le fichier peut deja exister
903
-		@rename($tmp, $fichier);
902
+        spip_unlink($fichier); // le fichier peut deja exister
903
+        @rename($tmp, $fichier);
904 904
 
905
-		return $ret;
906
-	}
905
+        return $ret;
906
+    }
907 907
 
908
-	return false;
908
+    return false;
909 909
 }
910 910
 
911 911
 /**
@@ -923,9 +923,9 @@  discard block
 block discarded – undo
923 923
  *     true si le fichier a bien été créé ; false sinon.
924 924
  */
925 925
 function _image_imageico($img, $fichier) {
926
-	$gd_image_array = [$img];
926
+    $gd_image_array = [$img];
927 927
 
928
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
928
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
929 929
 }
930 930
 
931 931
 
@@ -944,24 +944,24 @@  discard block
 block discarded – undo
944 944
  *     - true si une image est bien retournée.
945 945
  */
946 946
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
947
-	if (!function_exists('imagewebp')) {
948
-		return false;
949
-	}
950
-	$tmp = $fichier . '.tmp';
951
-	$ret = imagewebp($img, $tmp, $qualite);
952
-	if (file_exists($tmp)) {
953
-		$taille_test = getimagesize($tmp);
954
-		if ($taille_test[0] < 1) {
955
-			return false;
956
-		}
957
-
958
-		spip_unlink($fichier); // le fichier peut deja exister
959
-		@rename($tmp, $fichier);
960
-
961
-		return $ret;
962
-	}
963
-
964
-	return false;
947
+    if (!function_exists('imagewebp')) {
948
+        return false;
949
+    }
950
+    $tmp = $fichier . '.tmp';
951
+    $ret = imagewebp($img, $tmp, $qualite);
952
+    if (file_exists($tmp)) {
953
+        $taille_test = getimagesize($tmp);
954
+        if ($taille_test[0] < 1) {
955
+            return false;
956
+        }
957
+
958
+        spip_unlink($fichier); // le fichier peut deja exister
959
+        @rename($tmp, $fichier);
960
+
961
+        return $ret;
962
+    }
963
+
964
+    return false;
965 965
 }
966 966
 
967 967
 /**
@@ -981,35 +981,35 @@  discard block
 block discarded – undo
981 981
  */
982 982
 function _image_imagesvg($img, $fichier) {
983 983
 
984
-	$tmp = $fichier . '.tmp';
985
-	if (strpos($img, '<') === false) {
986
-		$img = supprimer_timestamp($img);
987
-		if (!file_exists($img)) {
988
-			return false;
989
-		}
990
-		@copy($img, $tmp);
991
-		if (filesize($tmp) == filesize($img)) {
992
-			spip_unlink($fichier); // le fichier peut deja exister
993
-			@rename($tmp, $fichier);
994
-			return true;
995
-		}
996
-		return false;
997
-	}
998
-
999
-	file_put_contents($tmp, $img);
1000
-	if (file_exists($tmp)) {
1001
-		$taille_test = spip_getimagesize($tmp);
1002
-		if ($taille_test[0] < 1) {
1003
-			return false;
1004
-		}
1005
-
1006
-		spip_unlink($fichier); // le fichier peut deja exister
1007
-		@rename($tmp, $fichier);
1008
-
1009
-		return true;
1010
-	}
1011
-
1012
-	return false;
984
+    $tmp = $fichier . '.tmp';
985
+    if (strpos($img, '<') === false) {
986
+        $img = supprimer_timestamp($img);
987
+        if (!file_exists($img)) {
988
+            return false;
989
+        }
990
+        @copy($img, $tmp);
991
+        if (filesize($tmp) == filesize($img)) {
992
+            spip_unlink($fichier); // le fichier peut deja exister
993
+            @rename($tmp, $fichier);
994
+            return true;
995
+        }
996
+        return false;
997
+    }
998
+
999
+    file_put_contents($tmp, $img);
1000
+    if (file_exists($tmp)) {
1001
+        $taille_test = spip_getimagesize($tmp);
1002
+        if ($taille_test[0] < 1) {
1003
+            return false;
1004
+        }
1005
+
1006
+        spip_unlink($fichier); // le fichier peut deja exister
1007
+        @rename($tmp, $fichier);
1008
+
1009
+        return true;
1010
+    }
1011
+
1012
+    return false;
1013 1013
 }
1014 1014
 
1015 1015
 
@@ -1037,30 +1037,30 @@  discard block
 block discarded – undo
1037 1037
  *     - false sinon.
1038 1038
  */
1039 1039
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1040
-	if (is_null($fonction)) {
1041
-		$fonction = '_image_image' . $valeurs['format_dest'];
1042
-	}
1043
-	$ret = false;
1044
-	#un flag pour reperer les images gravees
1045
-	$lock = (
1046
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1047
-		or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1048
-	);
1049
-	if (
1050
-		function_exists($fonction)
1051
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1052
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1053
-		&& !$lock
1054
-	) {
1055
-		if (@file_exists($valeurs['fichier_dest'])) {
1056
-			// dans tous les cas mettre a jour la taille de l'image finale
1057
-			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1058
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1059
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1060
-		}
1061
-	}
1062
-
1063
-	return $ret;
1040
+    if (is_null($fonction)) {
1041
+        $fonction = '_image_image' . $valeurs['format_dest'];
1042
+    }
1043
+    $ret = false;
1044
+    #un flag pour reperer les images gravees
1045
+    $lock = (
1046
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1047
+        or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1048
+    );
1049
+    if (
1050
+        function_exists($fonction)
1051
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1052
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1053
+        && !$lock
1054
+    ) {
1055
+        if (@file_exists($valeurs['fichier_dest'])) {
1056
+            // dans tous les cas mettre a jour la taille de l'image finale
1057
+            [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1058
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1059
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1060
+        }
1061
+    }
1062
+
1063
+    return $ret;
1064 1064
 }
1065 1065
 
1066 1066
 /**
@@ -1073,27 +1073,27 @@  discard block
 block discarded – undo
1073 1073
  *     Chemin vers le fichier manquant
1074 1074
  **/
1075 1075
 function reconstruire_image_intermediaire($fichier_manquant) {
1076
-	$reconstruire = [];
1077
-	$fichier = $fichier_manquant;
1078
-	while (
1079
-		strpos($fichier, '://') === false
1080
-		and !@file_exists($fichier)
1081
-		and lire_fichier($src = "$fichier.src", $source)
1082
-		and $valeurs = unserialize($source)
1083
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1084
-	) {
1085
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1086
-		$reconstruire[] = $valeurs['reconstruction'];
1087
-	}
1088
-	while (count($reconstruire)) {
1089
-		$r = array_pop($reconstruire);
1090
-		$fonction = $r[0];
1091
-		$args = $r[1];
1092
-		$fonction(...$args);
1093
-	}
1094
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1095
-	// mais l'on peut nettoyer les miettes de sa creation
1096
-	ramasse_miettes($fichier_manquant);
1076
+    $reconstruire = [];
1077
+    $fichier = $fichier_manquant;
1078
+    while (
1079
+        strpos($fichier, '://') === false
1080
+        and !@file_exists($fichier)
1081
+        and lire_fichier($src = "$fichier.src", $source)
1082
+        and $valeurs = unserialize($source)
1083
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1084
+    ) {
1085
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1086
+        $reconstruire[] = $valeurs['reconstruction'];
1087
+    }
1088
+    while (count($reconstruire)) {
1089
+        $r = array_pop($reconstruire);
1090
+        $fonction = $r[0];
1091
+        $args = $r[1];
1092
+        $fonction(...$args);
1093
+    }
1094
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1095
+    // mais l'on peut nettoyer les miettes de sa creation
1096
+    ramasse_miettes($fichier_manquant);
1097 1097
 }
1098 1098
 
1099 1099
 /**
@@ -1113,28 +1113,28 @@  discard block
 block discarded – undo
1113 1113
  *     Chemin du fichier d'image calculé
1114 1114
  **/
1115 1115
 function ramasse_miettes($fichier) {
1116
-	if (
1117
-		strpos($fichier, '://') !== false
1118
-		or !lire_fichier($src = "$fichier.src", $source)
1119
-		or !$valeurs = unserialize($source)
1120
-	) {
1121
-		return;
1122
-	}
1123
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1124
-	while (
1125
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1126
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1127
-		and (lire_fichier(
1128
-			$src = "$fichier.src",
1129
-			$source
1130
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1131
-		and ($valeurs = unserialize($source))  # et valide
1132
-	) {
1133
-		# on efface le fichier
1134
-		spip_unlink($fichier);
1135
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1136
-		#spip_unlink($src);
1137
-	}
1116
+    if (
1117
+        strpos($fichier, '://') !== false
1118
+        or !lire_fichier($src = "$fichier.src", $source)
1119
+        or !$valeurs = unserialize($source)
1120
+    ) {
1121
+        return;
1122
+    }
1123
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1124
+    while (
1125
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1126
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1127
+        and (lire_fichier(
1128
+            $src = "$fichier.src",
1129
+            $source
1130
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1131
+        and ($valeurs = unserialize($source))  # et valide
1132
+    ) {
1133
+        # on efface le fichier
1134
+        spip_unlink($fichier);
1135
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1136
+        #spip_unlink($src);
1137
+    }
1138 1138
 }
1139 1139
 
1140 1140
 
@@ -1159,31 +1159,31 @@  discard block
 block discarded – undo
1159 1159
  *     Code HTML de l'image
1160 1160
  **/
1161 1161
 function image_graver($img) {
1162
-	// appeler le filtre post_image_filtrer qui permet de faire
1163
-	// des traitements auto a la fin d'une serie de filtres
1164
-	$img = pipeline('post_image_filtrer', $img);
1165
-
1166
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1167
-	if (($p = strpos($fichier, '?')) !== false) {
1168
-		$fichier = substr($fichier, 0, $p);
1169
-	}
1170
-	if (strlen($fichier) < 1) {
1171
-		$fichier = $img;
1172
-	}
1173
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1174
-	# et qu'il ne s'agit pas d'une URL
1175
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1176
-		reconstruire_image_intermediaire($fichier);
1177
-	}
1178
-	ramasse_miettes($fichier);
1179
-
1180
-	// ajouter le timestamp si besoin
1181
-	if (strpos($fichier_ori, '?') === false) {
1182
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1183
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1184
-	}
1185
-
1186
-	return $img;
1162
+    // appeler le filtre post_image_filtrer qui permet de faire
1163
+    // des traitements auto a la fin d'une serie de filtres
1164
+    $img = pipeline('post_image_filtrer', $img);
1165
+
1166
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1167
+    if (($p = strpos($fichier, '?')) !== false) {
1168
+        $fichier = substr($fichier, 0, $p);
1169
+    }
1170
+    if (strlen($fichier) < 1) {
1171
+        $fichier = $img;
1172
+    }
1173
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1174
+    # et qu'il ne s'agit pas d'une URL
1175
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1176
+        reconstruire_image_intermediaire($fichier);
1177
+    }
1178
+    ramasse_miettes($fichier);
1179
+
1180
+    // ajouter le timestamp si besoin
1181
+    if (strpos($fichier_ori, '?') === false) {
1182
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1183
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1184
+    }
1185
+
1186
+    return $img;
1187 1187
 }
1188 1188
 
1189 1189
 /**
@@ -1210,34 +1210,34 @@  discard block
 block discarded – undo
1210 1210
  *     Code html modifié de la balise.
1211 1211
  **/
1212 1212
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1213
-	if ($style === false) {
1214
-		$style = extraire_attribut($tag, 'style');
1215
-	}
1216
-
1217
-	// enlever le width et height du style
1218
-	if ($style) {
1219
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1220
-	}
1221
-	if ($style and $style[0] === ';') {
1222
-		$style = substr($style, 1);
1223
-	}
1224
-
1225
-	// mettre des attributs de width et height sur les images,
1226
-	// ca accelere le rendu du navigateur
1227
-	// ca permet aux navigateurs de reserver la bonne taille
1228
-	// quand on a desactive l'affichage des images.
1229
-	$tag = inserer_attribut($tag, 'width', round($width));
1230
-	$tag = inserer_attribut($tag, 'height', round($height));
1231
-
1232
-	// attributs deprecies. Transformer en CSS
1233
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1234
-		$style = "margin:{$espace}px;" . $style;
1235
-		$tag = inserer_attribut($tag, 'hspace', '');
1236
-	}
1237
-
1238
-	$tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1239
-
1240
-	return $tag;
1213
+    if ($style === false) {
1214
+        $style = extraire_attribut($tag, 'style');
1215
+    }
1216
+
1217
+    // enlever le width et height du style
1218
+    if ($style) {
1219
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1220
+    }
1221
+    if ($style and $style[0] === ';') {
1222
+        $style = substr($style, 1);
1223
+    }
1224
+
1225
+    // mettre des attributs de width et height sur les images,
1226
+    // ca accelere le rendu du navigateur
1227
+    // ca permet aux navigateurs de reserver la bonne taille
1228
+    // quand on a desactive l'affichage des images.
1229
+    $tag = inserer_attribut($tag, 'width', round($width));
1230
+    $tag = inserer_attribut($tag, 'height', round($height));
1231
+
1232
+    // attributs deprecies. Transformer en CSS
1233
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1234
+        $style = "margin:{$espace}px;" . $style;
1235
+        $tag = inserer_attribut($tag, 'hspace', '');
1236
+    }
1237
+
1238
+    $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1239
+
1240
+    return $tag;
1241 1241
 }
1242 1242
 
1243 1243
 
@@ -1263,72 +1263,72 @@  discard block
 block discarded – undo
1263 1263
  *     Retourne le code HTML de l'image
1264 1264
  **/
1265 1265
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1266
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1267
-
1268
-	// fermer les tags img pas bien fermes;
1269
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1270
-
1271
-	// le style
1272
-	$style = $valeurs['style'];
1273
-	if (isset($surcharge['style'])) {
1274
-		$style = $surcharge['style'];
1275
-		unset($surcharge['style']);
1276
-	}
1277
-
1278
-	// traiter specifiquement la largeur et la hauteur
1279
-	$width = $valeurs['largeur'];
1280
-	if (isset($surcharge['width'])) {
1281
-		$width = $surcharge['width'];
1282
-		unset($surcharge['width']);
1283
-	}
1284
-	$height = $valeurs['hauteur'];
1285
-	if (isset($surcharge['height'])) {
1286
-		$height = $surcharge['height'];
1287
-		unset($surcharge['height']);
1288
-	}
1289
-
1290
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1291
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1292
-	// on remplace toute les ref a src dans le tag
1293
-	$src = extraire_attribut($tag, 'src');
1294
-	if (isset($surcharge['src'])) {
1295
-		$tag = str_replace($src, $surcharge['src'], $tag);
1296
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1297
-		// pas garanti comme methode, mais mieux que rien
1298
-		if (strpos($src, '&') !== false) {
1299
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1300
-		}
1301
-		$src = $surcharge['src'];
1302
-		unset($surcharge['src']);
1303
-	}
1304
-
1305
-	$class = $valeurs['class'];
1306
-	if (isset($surcharge['class'])) {
1307
-		$class = $surcharge['class'];
1308
-		unset($surcharge['class']);
1309
-	}
1310
-	if (is_scalar($class) && strlen($class)) {
1311
-		$tag = inserer_attribut($tag, 'class', $class);
1312
-	}
1313
-
1314
-	if (count($surcharge)) {
1315
-		foreach ($surcharge as $attribut => $valeur) {
1316
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1317
-		}
1318
-	}
1319
-
1320
-	$tag = pipeline(
1321
-		'image_ecrire_tag_finir',
1322
-		[
1323
-			'args' => [
1324
-				'valeurs' => $valeurs,
1325
-				'surcharge' => $surcharge,
1326
-			],
1327
-			'data' => $tag
1328
-		]
1329
-	);
1330
-
1331
-	return $tag;
1266
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1267
+
1268
+    // fermer les tags img pas bien fermes;
1269
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1270
+
1271
+    // le style
1272
+    $style = $valeurs['style'];
1273
+    if (isset($surcharge['style'])) {
1274
+        $style = $surcharge['style'];
1275
+        unset($surcharge['style']);
1276
+    }
1277
+
1278
+    // traiter specifiquement la largeur et la hauteur
1279
+    $width = $valeurs['largeur'];
1280
+    if (isset($surcharge['width'])) {
1281
+        $width = $surcharge['width'];
1282
+        unset($surcharge['width']);
1283
+    }
1284
+    $height = $valeurs['hauteur'];
1285
+    if (isset($surcharge['height'])) {
1286
+        $height = $surcharge['height'];
1287
+        unset($surcharge['height']);
1288
+    }
1289
+
1290
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1291
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1292
+    // on remplace toute les ref a src dans le tag
1293
+    $src = extraire_attribut($tag, 'src');
1294
+    if (isset($surcharge['src'])) {
1295
+        $tag = str_replace($src, $surcharge['src'], $tag);
1296
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1297
+        // pas garanti comme methode, mais mieux que rien
1298
+        if (strpos($src, '&') !== false) {
1299
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1300
+        }
1301
+        $src = $surcharge['src'];
1302
+        unset($surcharge['src']);
1303
+    }
1304
+
1305
+    $class = $valeurs['class'];
1306
+    if (isset($surcharge['class'])) {
1307
+        $class = $surcharge['class'];
1308
+        unset($surcharge['class']);
1309
+    }
1310
+    if (is_scalar($class) && strlen($class)) {
1311
+        $tag = inserer_attribut($tag, 'class', $class);
1312
+    }
1313
+
1314
+    if (count($surcharge)) {
1315
+        foreach ($surcharge as $attribut => $valeur) {
1316
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1317
+        }
1318
+    }
1319
+
1320
+    $tag = pipeline(
1321
+        'image_ecrire_tag_finir',
1322
+        [
1323
+            'args' => [
1324
+                'valeurs' => $valeurs,
1325
+                'surcharge' => $surcharge,
1326
+            ],
1327
+            'data' => $tag
1328
+        ]
1329
+    );
1330
+
1331
+    return $tag;
1332 1332
 }
1333 1333
 
1334 1334
 /**
@@ -1351,267 +1351,267 @@  discard block
 block discarded – undo
1351 1351
  *     Description de l'image, sinon null.
1352 1352
  **/
1353 1353
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1354
-	$srcHeight = null;
1355
-	$retour = [];
1356
-	// ordre de preference des formats graphiques pour creer les vignettes
1357
-	// le premier format disponible, selon la methode demandee, est utilise
1358
-	$image = $valeurs['fichier'];
1359
-	$format = $valeurs['format_source'];
1360
-	$destdir = dirname($valeurs['fichier_dest']);
1361
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1362
-
1363
-	$format_sortie = $valeurs['format_dest'];
1364
-
1365
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1366
-		$process = $GLOBALS['meta']['image_process'];
1367
-	}
1368
-
1369
-	// si le doc n'est pas une image dans un format accetpable, refuser
1370
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1371
-		return;
1372
-	}
1373
-	$destination = "$destdir/$destfile";
1374
-
1375
-	// calculer la taille
1376
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1377
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1378
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1379
-		}
1380
-	} elseif ($process == 'convert' or $process == 'imagick') {
1381
-		$destWidth = $maxWidth;
1382
-		$destHeight = $maxHeight;
1383
-	} else {
1384
-		spip_log("echec $process sur $image");
1385
-
1386
-		return;
1387
-	}
1388
-
1389
-	$vignette = '';
1390
-
1391
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1392
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1393
-		$vignette = $destination . '.' . $format;
1394
-		@copy($image, $vignette);
1395
-	}
1396
-
1397
-	elseif ($valeurs['format_source'] === 'svg') {
1398
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1399
-			$format_sortie = 'svg';
1400
-			$vignette = $destination . '.' . $format_sortie;
1401
-			$valeurs['fichier_dest'] = $vignette;
1402
-			_image_gd_output($svg, $valeurs);
1403
-		}
1404
-	}
1405
-
1406
-	// imagemagick en ligne de commande
1407
-	elseif ($process == 'convert') {
1408
-		if (!defined('_CONVERT_COMMAND')) {
1409
-			define('_CONVERT_COMMAND', 'convert');
1410
-		} // Securite : mes_options.php peut preciser le chemin absolu
1411
-		if (!defined('_RESIZE_COMMAND')) {
1412
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1413
-		}
1414
-		$vignette = $destination . '.' . $format_sortie;
1415
-		$commande = str_replace(
1416
-			['%x', '%y', '%src', '%dest'],
1417
-			[
1418
-				$destWidth,
1419
-				$destHeight,
1420
-				escapeshellcmd($image),
1421
-				escapeshellcmd($vignette)
1422
-			],
1423
-			_RESIZE_COMMAND
1424
-		);
1425
-		spip_log($commande);
1426
-		exec($commande);
1427
-		if (!@file_exists($vignette)) {
1428
-			spip_log("echec convert sur $vignette");
1429
-
1430
-			return;  // echec commande
1431
-		}
1432
-	}
1433
-
1434
-	// php5 imagemagick
1435
-	elseif ($process == 'imagick') {
1436
-		if (!class_exists(\Imagick::class)) {
1437
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1438
-
1439
-			return;
1440
-		}
1441
-
1442
-		// chemin compatible Windows
1443
-		$output = realpath(dirname($destination));
1444
-		if (!$output) {
1445
-			return;
1446
-		}
1447
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1448
-
1449
-		$imagick = new Imagick();
1450
-		$imagick->readImage(realpath($image));
1451
-		$imagick->resizeImage(
1452
-			$destWidth,
1453
-			$destHeight,
1454
-			Imagick::FILTER_LANCZOS,
1455
-			1
1456
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1457
-		$imagick->writeImage($vignette);
1458
-
1459
-		if (!@file_exists($vignette)) {
1460
-			spip_log("echec imagick sur $vignette");
1461
-
1462
-			return;
1463
-		}
1464
-		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1465
-		$vignette = $destination . '.' . $format_sortie;
1466
-	}
1467
-
1468
-	// netpbm
1469
-	elseif ($process == 'netpbm') {
1470
-		if (!defined('_PNMSCALE_COMMAND')) {
1471
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1472
-		} // Securite : mes_options.php peut preciser le chemin absolu
1473
-		if (_PNMSCALE_COMMAND == '') {
1474
-			return;
1475
-		}
1476
-		$vignette = $destination . '.' . $format_sortie;
1477
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1478
-		if ($format == 'jpg') {
1479
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1480
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1481
-			if (!($s = @filesize($vignette))) {
1482
-				spip_unlink($vignette);
1483
-			}
1484
-			if (!@file_exists($vignette)) {
1485
-				spip_log("echec netpbm-jpg sur $vignette");
1486
-
1487
-				return;
1488
-			}
1489
-		} else {
1490
-			if ($format == 'gif') {
1491
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1492
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1493
-				if (!($s = @filesize($vignette))) {
1494
-					spip_unlink($vignette);
1495
-				}
1496
-				if (!@file_exists($vignette)) {
1497
-					spip_log("echec netpbm-gif sur $vignette");
1498
-
1499
-					return;
1500
-				}
1501
-			} else {
1502
-				if ($format == 'png') {
1503
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1504
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1505
-					if (!($s = @filesize($vignette))) {
1506
-						spip_unlink($vignette);
1507
-					}
1508
-					if (!@file_exists($vignette)) {
1509
-						spip_log("echec netpbm-png sur $vignette");
1510
-
1511
-						return;
1512
-					}
1513
-				}
1514
-			}
1515
-		}
1516
-	}
1517
-
1518
-	// gd ou gd2
1519
-	elseif ($process == 'gd1' or $process == 'gd2') {
1520
-		if (!function_exists('gd_info')) {
1521
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1522
-
1523
-			return;
1524
-		}
1525
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1526
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1527
-
1528
-			return;
1529
-		}
1530
-		$destFormat = $format_sortie;
1531
-		if (!$destFormat) {
1532
-			spip_log("pas de format pour $image");
1533
-
1534
-			return;
1535
-		}
1536
-
1537
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1538
-		if (!function_exists($fonction_imagecreatefrom)) {
1539
-			return;
1540
-		}
1541
-		$srcImage = @$fonction_imagecreatefrom($image);
1542
-		if (!$srcImage) {
1543
-			spip_log('echec gd1/gd2');
1544
-
1545
-			return;
1546
-		}
1547
-
1548
-		// Initialisation de l'image destination
1549
-		$destImage = null;
1550
-		if ($process == 'gd2' and $destFormat != 'gif') {
1551
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1552
-		}
1553
-		if (!$destImage) {
1554
-			$destImage = ImageCreate($destWidth, $destHeight);
1555
-		}
1556
-
1557
-		// Recopie de l'image d'origine avec adaptation de la taille
1558
-		$ok = false;
1559
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1560
-			if ($format == 'gif') {
1561
-				// Si un GIF est transparent,
1562
-				// fabriquer un PNG transparent
1563
-				$transp = imagecolortransparent($srcImage);
1564
-				if ($transp > 0) {
1565
-					$destFormat = 'png';
1566
-				}
1567
-			}
1568
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1569
-				// Conserver la transparence
1570
-				if (function_exists('imageAntiAlias')) {
1571
-					imageAntiAlias($destImage, true);
1572
-				}
1573
-				@imagealphablending($destImage, false);
1574
-				@imagesavealpha($destImage, true);
1575
-			}
1576
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1577
-		}
1578
-		if (!$ok) {
1579
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1580
-		}
1581
-
1582
-		// Sauvegarde de l'image destination
1583
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1584
-		$valeurs['format_dest'] = $format = $destFormat;
1585
-		_image_gd_output($destImage, $valeurs);
1586
-
1587
-		if ($srcImage) {
1588
-			ImageDestroy($srcImage);
1589
-		}
1590
-		ImageDestroy($destImage);
1591
-	}
1592
-
1593
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1594
-		$size = [$destWidth, $destHeight];
1595
-	}
1596
-
1597
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1598
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1599
-	if ($size[0] < 1) {
1600
-		$size[0] = $destWidth;
1601
-	}
1602
-	if ($size[1] < 1) {
1603
-		$size[1] = $destHeight;
1604
-	}
1605
-
1606
-	$retour['width'] = $largeur = $size[0];
1607
-	$retour['height'] = $hauteur = $size[1];
1608
-
1609
-	$retour['fichier'] = $vignette;
1610
-	$retour['format'] = $format;
1611
-	$retour['date'] = @filemtime($vignette);
1612
-
1613
-	// renvoyer l'image
1614
-	return $retour;
1354
+    $srcHeight = null;
1355
+    $retour = [];
1356
+    // ordre de preference des formats graphiques pour creer les vignettes
1357
+    // le premier format disponible, selon la methode demandee, est utilise
1358
+    $image = $valeurs['fichier'];
1359
+    $format = $valeurs['format_source'];
1360
+    $destdir = dirname($valeurs['fichier_dest']);
1361
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1362
+
1363
+    $format_sortie = $valeurs['format_dest'];
1364
+
1365
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1366
+        $process = $GLOBALS['meta']['image_process'];
1367
+    }
1368
+
1369
+    // si le doc n'est pas une image dans un format accetpable, refuser
1370
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1371
+        return;
1372
+    }
1373
+    $destination = "$destdir/$destfile";
1374
+
1375
+    // calculer la taille
1376
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1377
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1378
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1379
+        }
1380
+    } elseif ($process == 'convert' or $process == 'imagick') {
1381
+        $destWidth = $maxWidth;
1382
+        $destHeight = $maxHeight;
1383
+    } else {
1384
+        spip_log("echec $process sur $image");
1385
+
1386
+        return;
1387
+    }
1388
+
1389
+    $vignette = '';
1390
+
1391
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1392
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1393
+        $vignette = $destination . '.' . $format;
1394
+        @copy($image, $vignette);
1395
+    }
1396
+
1397
+    elseif ($valeurs['format_source'] === 'svg') {
1398
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1399
+            $format_sortie = 'svg';
1400
+            $vignette = $destination . '.' . $format_sortie;
1401
+            $valeurs['fichier_dest'] = $vignette;
1402
+            _image_gd_output($svg, $valeurs);
1403
+        }
1404
+    }
1405
+
1406
+    // imagemagick en ligne de commande
1407
+    elseif ($process == 'convert') {
1408
+        if (!defined('_CONVERT_COMMAND')) {
1409
+            define('_CONVERT_COMMAND', 'convert');
1410
+        } // Securite : mes_options.php peut preciser le chemin absolu
1411
+        if (!defined('_RESIZE_COMMAND')) {
1412
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1413
+        }
1414
+        $vignette = $destination . '.' . $format_sortie;
1415
+        $commande = str_replace(
1416
+            ['%x', '%y', '%src', '%dest'],
1417
+            [
1418
+                $destWidth,
1419
+                $destHeight,
1420
+                escapeshellcmd($image),
1421
+                escapeshellcmd($vignette)
1422
+            ],
1423
+            _RESIZE_COMMAND
1424
+        );
1425
+        spip_log($commande);
1426
+        exec($commande);
1427
+        if (!@file_exists($vignette)) {
1428
+            spip_log("echec convert sur $vignette");
1429
+
1430
+            return;  // echec commande
1431
+        }
1432
+    }
1433
+
1434
+    // php5 imagemagick
1435
+    elseif ($process == 'imagick') {
1436
+        if (!class_exists(\Imagick::class)) {
1437
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1438
+
1439
+            return;
1440
+        }
1441
+
1442
+        // chemin compatible Windows
1443
+        $output = realpath(dirname($destination));
1444
+        if (!$output) {
1445
+            return;
1446
+        }
1447
+        $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1448
+
1449
+        $imagick = new Imagick();
1450
+        $imagick->readImage(realpath($image));
1451
+        $imagick->resizeImage(
1452
+            $destWidth,
1453
+            $destHeight,
1454
+            Imagick::FILTER_LANCZOS,
1455
+            1
1456
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1457
+        $imagick->writeImage($vignette);
1458
+
1459
+        if (!@file_exists($vignette)) {
1460
+            spip_log("echec imagick sur $vignette");
1461
+
1462
+            return;
1463
+        }
1464
+        // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1465
+        $vignette = $destination . '.' . $format_sortie;
1466
+    }
1467
+
1468
+    // netpbm
1469
+    elseif ($process == 'netpbm') {
1470
+        if (!defined('_PNMSCALE_COMMAND')) {
1471
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1472
+        } // Securite : mes_options.php peut preciser le chemin absolu
1473
+        if (_PNMSCALE_COMMAND == '') {
1474
+            return;
1475
+        }
1476
+        $vignette = $destination . '.' . $format_sortie;
1477
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1478
+        if ($format == 'jpg') {
1479
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1480
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1481
+            if (!($s = @filesize($vignette))) {
1482
+                spip_unlink($vignette);
1483
+            }
1484
+            if (!@file_exists($vignette)) {
1485
+                spip_log("echec netpbm-jpg sur $vignette");
1486
+
1487
+                return;
1488
+            }
1489
+        } else {
1490
+            if ($format == 'gif') {
1491
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1492
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1493
+                if (!($s = @filesize($vignette))) {
1494
+                    spip_unlink($vignette);
1495
+                }
1496
+                if (!@file_exists($vignette)) {
1497
+                    spip_log("echec netpbm-gif sur $vignette");
1498
+
1499
+                    return;
1500
+                }
1501
+            } else {
1502
+                if ($format == 'png') {
1503
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1504
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1505
+                    if (!($s = @filesize($vignette))) {
1506
+                        spip_unlink($vignette);
1507
+                    }
1508
+                    if (!@file_exists($vignette)) {
1509
+                        spip_log("echec netpbm-png sur $vignette");
1510
+
1511
+                        return;
1512
+                    }
1513
+                }
1514
+            }
1515
+        }
1516
+    }
1517
+
1518
+    // gd ou gd2
1519
+    elseif ($process == 'gd1' or $process == 'gd2') {
1520
+        if (!function_exists('gd_info')) {
1521
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1522
+
1523
+            return;
1524
+        }
1525
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1526
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1527
+
1528
+            return;
1529
+        }
1530
+        $destFormat = $format_sortie;
1531
+        if (!$destFormat) {
1532
+            spip_log("pas de format pour $image");
1533
+
1534
+            return;
1535
+        }
1536
+
1537
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1538
+        if (!function_exists($fonction_imagecreatefrom)) {
1539
+            return;
1540
+        }
1541
+        $srcImage = @$fonction_imagecreatefrom($image);
1542
+        if (!$srcImage) {
1543
+            spip_log('echec gd1/gd2');
1544
+
1545
+            return;
1546
+        }
1547
+
1548
+        // Initialisation de l'image destination
1549
+        $destImage = null;
1550
+        if ($process == 'gd2' and $destFormat != 'gif') {
1551
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1552
+        }
1553
+        if (!$destImage) {
1554
+            $destImage = ImageCreate($destWidth, $destHeight);
1555
+        }
1556
+
1557
+        // Recopie de l'image d'origine avec adaptation de la taille
1558
+        $ok = false;
1559
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1560
+            if ($format == 'gif') {
1561
+                // Si un GIF est transparent,
1562
+                // fabriquer un PNG transparent
1563
+                $transp = imagecolortransparent($srcImage);
1564
+                if ($transp > 0) {
1565
+                    $destFormat = 'png';
1566
+                }
1567
+            }
1568
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1569
+                // Conserver la transparence
1570
+                if (function_exists('imageAntiAlias')) {
1571
+                    imageAntiAlias($destImage, true);
1572
+                }
1573
+                @imagealphablending($destImage, false);
1574
+                @imagesavealpha($destImage, true);
1575
+            }
1576
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1577
+        }
1578
+        if (!$ok) {
1579
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1580
+        }
1581
+
1582
+        // Sauvegarde de l'image destination
1583
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1584
+        $valeurs['format_dest'] = $format = $destFormat;
1585
+        _image_gd_output($destImage, $valeurs);
1586
+
1587
+        if ($srcImage) {
1588
+            ImageDestroy($srcImage);
1589
+        }
1590
+        ImageDestroy($destImage);
1591
+    }
1592
+
1593
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1594
+        $size = [$destWidth, $destHeight];
1595
+    }
1596
+
1597
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1598
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1599
+    if ($size[0] < 1) {
1600
+        $size[0] = $destWidth;
1601
+    }
1602
+    if ($size[1] < 1) {
1603
+        $size[1] = $destHeight;
1604
+    }
1605
+
1606
+    $retour['width'] = $largeur = $size[0];
1607
+    $retour['height'] = $hauteur = $size[1];
1608
+
1609
+    $retour['fichier'] = $vignette;
1610
+    $retour['format'] = $format;
1611
+    $retour['date'] = @filemtime($vignette);
1612
+
1613
+    // renvoyer l'image
1614
+    return $retour;
1615 1615
 }
1616 1616
 
1617 1617
 /**
@@ -1631,25 +1631,25 @@  discard block
 block discarded – undo
1631 1631
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1632 1632
  **/
1633 1633
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1634
-	$ratioWidth = $srcWidth / $maxWidth;
1635
-	$ratioHeight = $srcHeight / $maxHeight;
1636
-
1637
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1638
-		$destWidth = $srcWidth;
1639
-		$destHeight = $srcHeight;
1640
-	} elseif ($ratioWidth < $ratioHeight) {
1641
-		$destWidth = $srcWidth / $ratioHeight;
1642
-		$destHeight = $maxHeight;
1643
-	} else {
1644
-		$destWidth = $maxWidth;
1645
-		$destHeight = $srcHeight / $ratioWidth;
1646
-	}
1647
-
1648
-	return [
1649
-		intval(round($destWidth)),
1650
-		intval(round($destHeight)),
1651
-		max($ratioWidth, $ratioHeight)
1652
-	];
1634
+    $ratioWidth = $srcWidth / $maxWidth;
1635
+    $ratioHeight = $srcHeight / $maxHeight;
1636
+
1637
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1638
+        $destWidth = $srcWidth;
1639
+        $destHeight = $srcHeight;
1640
+    } elseif ($ratioWidth < $ratioHeight) {
1641
+        $destWidth = $srcWidth / $ratioHeight;
1642
+        $destHeight = $maxHeight;
1643
+    } else {
1644
+        $destWidth = $maxWidth;
1645
+        $destHeight = $srcHeight / $ratioWidth;
1646
+    }
1647
+
1648
+    return [
1649
+        intval(round($destWidth)),
1650
+        intval(round($destHeight)),
1651
+        max($ratioWidth, $ratioHeight)
1652
+    ];
1653 1653
 }
1654 1654
 
1655 1655
 /**
@@ -1669,25 +1669,25 @@  discard block
 block discarded – undo
1669 1669
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1670 1670
  **/
1671 1671
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1672
-	$ratioWidth = $srcWidth / $maxWidth;
1673
-	$ratioHeight = $srcHeight / $maxHeight;
1674
-
1675
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1676
-		$destWidth = $srcWidth;
1677
-		$destHeight = $srcHeight;
1678
-	} elseif ($ratioWidth > $ratioHeight) {
1679
-		$destWidth = $srcWidth / $ratioHeight;
1680
-		$destHeight = $maxHeight;
1681
-	} else {
1682
-		$destWidth = $maxWidth;
1683
-		$destHeight = $srcHeight / $ratioWidth;
1684
-	}
1685
-
1686
-	return [
1687
-		intval(round($destWidth)),
1688
-		intval(round($destHeight)),
1689
-		min($ratioWidth, $ratioHeight)
1690
-	];
1672
+    $ratioWidth = $srcWidth / $maxWidth;
1673
+    $ratioHeight = $srcHeight / $maxHeight;
1674
+
1675
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1676
+        $destWidth = $srcWidth;
1677
+        $destHeight = $srcHeight;
1678
+    } elseif ($ratioWidth > $ratioHeight) {
1679
+        $destWidth = $srcWidth / $ratioHeight;
1680
+        $destHeight = $maxHeight;
1681
+    } else {
1682
+        $destWidth = $maxWidth;
1683
+        $destHeight = $srcHeight / $ratioWidth;
1684
+    }
1685
+
1686
+    return [
1687
+        intval(round($destWidth)),
1688
+        intval(round($destHeight)),
1689
+        min($ratioWidth, $ratioHeight)
1690
+    ];
1691 1691
 }
1692 1692
 
1693 1693
 
@@ -1700,12 +1700,12 @@  discard block
 block discarded – undo
1700 1700
  * @return string
1701 1701
  */
1702 1702
 function process_image_svg_identite($image) {
1703
-	if ($image['creer']) {
1704
-		$source = $image['fichier'];
1705
-		_image_gd_output($source, $image);
1706
-	}
1703
+    if ($image['creer']) {
1704
+        $source = $image['fichier'];
1705
+        _image_gd_output($source, $image);
1706
+    }
1707 1707
 
1708
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1708
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1709 1709
 }
1710 1710
 
1711 1711
 
@@ -1738,109 +1738,109 @@  discard block
 block discarded – undo
1738 1738
  *     Code HTML de la balise img produite
1739 1739
  **/
1740 1740
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1741
-	$image = false;
1742
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1743
-		$process = $GLOBALS['meta']['image_process'];
1744
-	}
1745
-	# determiner le format de sortie
1746
-	$format_sortie = false; // le choix par defaut sera bon
1747
-	if ($process == 'netpbm') {
1748
-		$format_sortie = 'jpg';
1749
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1750
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1751
-		// on verifie que l'extension choisie est bonne (en principe oui)
1752
-		$gd_formats = formats_image_acceptables(true);
1753
-		if (
1754
-			is_array($image)
1755
-			and (!in_array($image['format_dest'], $gd_formats)
1756
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1757
-			)
1758
-		) {
1759
-			if ($image['format_source'] == 'jpg') {
1760
-				$formats_sortie = ['jpg', 'png', 'gif'];
1761
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1762
-			{
1763
-				$formats_sortie = ['png', 'jpg', 'gif'];
1764
-			}
1765
-			// Choisir le format destination
1766
-			// - on sauve de preference en JPEG (meilleure compression)
1767
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1768
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1769
-			# pas *ecrire*
1770
-			$format_sortie = '';
1771
-			foreach ($formats_sortie as $fmt) {
1772
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1773
-					$format_sortie = $fmt;
1774
-					break;
1775
-				}
1776
-			}
1777
-			$image = false;
1778
-		}
1779
-	}
1780
-
1781
-	if (!is_array($image)) {
1782
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1783
-	}
1784
-
1785
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1786
-		spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1787
-		// on peut resizer en mode html si on dispose des elements
1788
-		[$srcw, $srch] = taille_image($img);
1789
-		if ($srcw and $srch) {
1790
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1791
-
1792
-			return _image_tag_changer_taille($img, $w, $h);
1793
-		}
1794
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1795
-		// sous la forme style='max-width: NNpx;'
1796
-		return inserer_attribut(
1797
-			$img,
1798
-			'style',
1799
-			"max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1800
-		);
1801
-	}
1802
-
1803
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1804
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1805
-		if ($image['creer']) {
1806
-			@copy($image['fichier'], $image['fichier_dest']);
1807
-		}
1808
-
1809
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1810
-	}
1811
-
1812
-	if ($image['creer'] == false && !$force) {
1813
-		return _image_ecrire_tag(
1814
-			$image,
1815
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1816
-		);
1817
-	}
1818
-
1819
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1820
-		$destWidth = $image['largeur_dest'];
1821
-		$destHeight = $image['hauteur_dest'];
1822
-		$logo = $image['fichier'];
1823
-		$date = $image['date_src'];
1824
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1825
-
1826
-		if ($preview && $preview['fichier']) {
1827
-			$logo = $preview['fichier'];
1828
-			$destWidth = $preview['width'];
1829
-			$destHeight = $preview['height'];
1830
-			$date = $preview['date'];
1831
-		}
1832
-		// dans l'espace prive mettre un timestamp sur l'adresse
1833
-		// de l'image, de facon a tromper le cache du navigateur
1834
-		// quand on fait supprimer/reuploader un logo
1835
-		// (pas de filemtime si SAFE MODE)
1836
-		$date = test_espace_prive() ? ('?' . $date) : '';
1837
-
1838
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1839
-	}
1840
-	else {
1841
-		# BMP, tiff ... les redacteurs osent tout!
1842
-		return $img;
1843
-	}
1741
+    $image = false;
1742
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1743
+        $process = $GLOBALS['meta']['image_process'];
1744
+    }
1745
+    # determiner le format de sortie
1746
+    $format_sortie = false; // le choix par defaut sera bon
1747
+    if ($process == 'netpbm') {
1748
+        $format_sortie = 'jpg';
1749
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1750
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1751
+        // on verifie que l'extension choisie est bonne (en principe oui)
1752
+        $gd_formats = formats_image_acceptables(true);
1753
+        if (
1754
+            is_array($image)
1755
+            and (!in_array($image['format_dest'], $gd_formats)
1756
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1757
+            )
1758
+        ) {
1759
+            if ($image['format_source'] == 'jpg') {
1760
+                $formats_sortie = ['jpg', 'png', 'gif'];
1761
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1762
+            {
1763
+                $formats_sortie = ['png', 'jpg', 'gif'];
1764
+            }
1765
+            // Choisir le format destination
1766
+            // - on sauve de preference en JPEG (meilleure compression)
1767
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1768
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1769
+            # pas *ecrire*
1770
+            $format_sortie = '';
1771
+            foreach ($formats_sortie as $fmt) {
1772
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1773
+                    $format_sortie = $fmt;
1774
+                    break;
1775
+                }
1776
+            }
1777
+            $image = false;
1778
+        }
1779
+    }
1780
+
1781
+    if (!is_array($image)) {
1782
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1783
+    }
1784
+
1785
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1786
+        spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1787
+        // on peut resizer en mode html si on dispose des elements
1788
+        [$srcw, $srch] = taille_image($img);
1789
+        if ($srcw and $srch) {
1790
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1791
+
1792
+            return _image_tag_changer_taille($img, $w, $h);
1793
+        }
1794
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1795
+        // sous la forme style='max-width: NNpx;'
1796
+        return inserer_attribut(
1797
+            $img,
1798
+            'style',
1799
+            "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1800
+        );
1801
+    }
1802
+
1803
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1804
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1805
+        if ($image['creer']) {
1806
+            @copy($image['fichier'], $image['fichier_dest']);
1807
+        }
1808
+
1809
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1810
+    }
1811
+
1812
+    if ($image['creer'] == false && !$force) {
1813
+        return _image_ecrire_tag(
1814
+            $image,
1815
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1816
+        );
1817
+    }
1818
+
1819
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1820
+        $destWidth = $image['largeur_dest'];
1821
+        $destHeight = $image['hauteur_dest'];
1822
+        $logo = $image['fichier'];
1823
+        $date = $image['date_src'];
1824
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1825
+
1826
+        if ($preview && $preview['fichier']) {
1827
+            $logo = $preview['fichier'];
1828
+            $destWidth = $preview['width'];
1829
+            $destHeight = $preview['height'];
1830
+            $date = $preview['date'];
1831
+        }
1832
+        // dans l'espace prive mettre un timestamp sur l'adresse
1833
+        // de l'image, de facon a tromper le cache du navigateur
1834
+        // quand on fait supprimer/reuploader un logo
1835
+        // (pas de filemtime si SAFE MODE)
1836
+        $date = test_espace_prive() ? ('?' . $date) : '';
1837
+
1838
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1839
+    }
1840
+    else {
1841
+        # BMP, tiff ... les redacteurs osent tout!
1842
+        return $img;
1843
+    }
1844 1844
 }
1845 1845
 
1846 1846
 /**
@@ -1854,145 +1854,145 @@  discard block
 block discarded – undo
1854 1854
  * Class phpthumb_functions
1855 1855
  */
1856 1856
 class phpthumb_functions {
1857
-	/**
1858
-	 * Retourne la couleur d'un pixel dans une image
1859
-	 *
1860
-	 * @param resource|GdImage $img
1861
-	 * @param int $x
1862
-	 * @param int $y
1863
-	 * @return array|bool
1864
-	 */
1865
-	public static function GetPixelColor(&$img, $x, $y) {
1866
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1867
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1868
-		}
1869
-		return false;
1870
-	}
1871
-
1872
-	/**
1873
-	 * Retourne un nombre dans une représentation en Little Endian
1874
-	 *
1875
-	 * @param int $number
1876
-	 * @param int $minbytes
1877
-	 * @return string
1878
-	 */
1879
-	public static function LittleEndian2String($number, $minbytes = 1) {
1880
-		$intstring = '';
1881
-		while ($number > 0) {
1882
-			$intstring = $intstring . chr($number & 255);
1883
-			$number >>= 8;
1884
-		}
1885
-
1886
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1887
-	}
1888
-
1889
-	/**
1890
-	 * Transforme une ressource GD en image au format ICO
1891
-	 *
1892
-	 * @param array $gd_image_array
1893
-	 *     Tableau de ressources d'images GD
1894
-	 * @return string
1895
-	 *     Image au format ICO
1896
-	 */
1897
-	public static function GD2ICOstring(&$gd_image_array) {
1898
-		foreach ($gd_image_array as $key => $gd_image) {
1899
-			$ImageWidths[$key] = ImageSX($gd_image);
1900
-			$ImageHeights[$key] = ImageSY($gd_image);
1901
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1902
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1903
-
1904
-			$icXOR[$key] = '';
1905
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1906
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1907
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1908
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1909
-					$r = $argb['red'];
1910
-					$g = $argb['green'];
1911
-					$b = $argb['blue'];
1912
-
1913
-					if ($bpp[$key] == 32) {
1914
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1915
-					} elseif ($bpp[$key] == 24) {
1916
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1917
-					}
1918
-
1919
-					if ($a < 128) {
1920
-						@$icANDmask[$key][$y] .= '1';
1921
-					} else {
1922
-						@$icANDmask[$key][$y] .= '0';
1923
-					}
1924
-				}
1925
-				// mask bits are 32-bit aligned per scanline
1926
-				while (strlen($icANDmask[$key][$y]) % 32) {
1927
-					$icANDmask[$key][$y] .= '0';
1928
-				}
1929
-			}
1930
-			$icAND[$key] = '';
1931
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1932
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1933
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1934
-				}
1935
-			}
1936
-		}
1937
-
1938
-		foreach ($gd_image_array as $key => $gd_image) {
1939
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1940
-
1941
-			// BITMAPINFOHEADER - 40 bytes
1942
-			$BitmapInfoHeader[$key] = '';
1943
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1944
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1945
-			// The biHeight member specifies the combined
1946
-			// height of the XOR and AND masks.
1947
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1948
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1949
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1950
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1951
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1952
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1953
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1954
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1955
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1956
-		}
1957
-
1958
-
1959
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1960
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1961
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1962
-
1963
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1964
-		foreach ($gd_image_array as $key => $gd_image) {
1965
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1966
-
1967
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1968
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1969
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1970
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1971
-
1972
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1973
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1974
-
1975
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1976
-			$icondata .= phpthumb_functions::LittleEndian2String(
1977
-				$dwBytesInRes,
1978
-				4
1979
-			);     // dwBytesInRes;	// How many bytes in this resource?
1980
-
1981
-			$icondata .= phpthumb_functions::LittleEndian2String(
1982
-				$dwImageOffset,
1983
-				4
1984
-			);    // dwImageOffset;   // Where in the file is this image?
1985
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1986
-			$dwImageOffset += strlen($icXOR[$key]);
1987
-			$dwImageOffset += strlen($icAND[$key]);
1988
-		}
1989
-
1990
-		foreach ($gd_image_array as $key => $gd_image) {
1991
-			$icondata .= $BitmapInfoHeader[$key];
1992
-			$icondata .= $icXOR[$key];
1993
-			$icondata .= $icAND[$key];
1994
-		}
1995
-
1996
-		return $icondata;
1997
-	}
1857
+    /**
1858
+     * Retourne la couleur d'un pixel dans une image
1859
+     *
1860
+     * @param resource|GdImage $img
1861
+     * @param int $x
1862
+     * @param int $y
1863
+     * @return array|bool
1864
+     */
1865
+    public static function GetPixelColor(&$img, $x, $y) {
1866
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1867
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1868
+        }
1869
+        return false;
1870
+    }
1871
+
1872
+    /**
1873
+     * Retourne un nombre dans une représentation en Little Endian
1874
+     *
1875
+     * @param int $number
1876
+     * @param int $minbytes
1877
+     * @return string
1878
+     */
1879
+    public static function LittleEndian2String($number, $minbytes = 1) {
1880
+        $intstring = '';
1881
+        while ($number > 0) {
1882
+            $intstring = $intstring . chr($number & 255);
1883
+            $number >>= 8;
1884
+        }
1885
+
1886
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1887
+    }
1888
+
1889
+    /**
1890
+     * Transforme une ressource GD en image au format ICO
1891
+     *
1892
+     * @param array $gd_image_array
1893
+     *     Tableau de ressources d'images GD
1894
+     * @return string
1895
+     *     Image au format ICO
1896
+     */
1897
+    public static function GD2ICOstring(&$gd_image_array) {
1898
+        foreach ($gd_image_array as $key => $gd_image) {
1899
+            $ImageWidths[$key] = ImageSX($gd_image);
1900
+            $ImageHeights[$key] = ImageSY($gd_image);
1901
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1902
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1903
+
1904
+            $icXOR[$key] = '';
1905
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1906
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1907
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1908
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1909
+                    $r = $argb['red'];
1910
+                    $g = $argb['green'];
1911
+                    $b = $argb['blue'];
1912
+
1913
+                    if ($bpp[$key] == 32) {
1914
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1915
+                    } elseif ($bpp[$key] == 24) {
1916
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1917
+                    }
1918
+
1919
+                    if ($a < 128) {
1920
+                        @$icANDmask[$key][$y] .= '1';
1921
+                    } else {
1922
+                        @$icANDmask[$key][$y] .= '0';
1923
+                    }
1924
+                }
1925
+                // mask bits are 32-bit aligned per scanline
1926
+                while (strlen($icANDmask[$key][$y]) % 32) {
1927
+                    $icANDmask[$key][$y] .= '0';
1928
+                }
1929
+            }
1930
+            $icAND[$key] = '';
1931
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1932
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1933
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1934
+                }
1935
+            }
1936
+        }
1937
+
1938
+        foreach ($gd_image_array as $key => $gd_image) {
1939
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1940
+
1941
+            // BITMAPINFOHEADER - 40 bytes
1942
+            $BitmapInfoHeader[$key] = '';
1943
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1944
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1945
+            // The biHeight member specifies the combined
1946
+            // height of the XOR and AND masks.
1947
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1948
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1949
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1950
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1951
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1952
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1953
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1954
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1955
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1956
+        }
1957
+
1958
+
1959
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1960
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1961
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1962
+
1963
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1964
+        foreach ($gd_image_array as $key => $gd_image) {
1965
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1966
+
1967
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1968
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1969
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1970
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1971
+
1972
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1973
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1974
+
1975
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1976
+            $icondata .= phpthumb_functions::LittleEndian2String(
1977
+                $dwBytesInRes,
1978
+                4
1979
+            );     // dwBytesInRes;	// How many bytes in this resource?
1980
+
1981
+            $icondata .= phpthumb_functions::LittleEndian2String(
1982
+                $dwImageOffset,
1983
+                4
1984
+            );    // dwImageOffset;   // Where in the file is this image?
1985
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1986
+            $dwImageOffset += strlen($icXOR[$key]);
1987
+            $dwImageOffset += strlen($icAND[$key]);
1988
+        }
1989
+
1990
+        foreach ($gd_image_array as $key => $gd_image) {
1991
+            $icondata .= $BitmapInfoHeader[$key];
1992
+            $icondata .= $icXOR[$key];
1993
+            $icondata .= $icAND[$key];
1994
+        }
1995
+
1996
+        return $icondata;
1997
+    }
1998 1998
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres.php 1 patch
Indentation   +2409 added lines, -2409 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,16 +224,16 @@  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 or $raw) {
229
-		return $desc;
230
-	}
231
-	// affichage "GIT [master: abcdef]"
232
-	$commit = $desc['commit_short'] ?? $desc['commit'];
233
-	if ($desc['branch']) {
234
-		$commit = $desc['branch'] . ': ' . $commit;
235
-	}
236
-	return "{$desc['vcs']} [$commit]";
227
+    $desc = decrire_version_git($dir);
228
+    if ($desc === null or $raw) {
229
+        return $desc;
230
+    }
231
+    // affichage "GIT [master: abcdef]"
232
+    $commit = $desc['commit_short'] ?? $desc['commit'];
233
+    if ($desc['branch']) {
234
+        $commit = $desc['branch'] . ': ' . $commit;
235
+    }
236
+    return "{$desc['vcs']} [$commit]";
237 237
 }
238 238
 
239 239
 /**
@@ -245,24 +245,24 @@  discard block
 block discarded – undo
245 245
  *      array ['branch' => xx, 'commit' => yy] sinon.
246 246
  **/
247 247
 function decrire_version_git($dir) {
248
-	if (!$dir) {
249
-		$dir = '.';
250
-	}
251
-
252
-	// version installee par GIT
253
-	if (lire_fichier($dir . '/.git/HEAD', $c)) {
254
-		$currentHead = trim(substr($c, 4));
255
-		if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
256
-			return [
257
-				'vcs' => 'GIT',
258
-				'branch' => basename($currentHead),
259
-				'commit' => trim($hash),
260
-				'commit_short' => substr(trim($hash), 0, 8),
261
-			];
262
-		}
263
-	}
264
-
265
-	return null;
248
+    if (!$dir) {
249
+        $dir = '.';
250
+    }
251
+
252
+    // version installee par GIT
253
+    if (lire_fichier($dir . '/.git/HEAD', $c)) {
254
+        $currentHead = trim(substr($c, 4));
255
+        if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) {
256
+            return [
257
+                'vcs' => 'GIT',
258
+                'branch' => basename($currentHead),
259
+                'commit' => trim($hash),
260
+                'commit_short' => substr(trim($hash), 0, 8),
261
+            ];
262
+        }
263
+    }
264
+
265
+    return null;
266 266
 }
267 267
 
268 268
 // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images
@@ -309,18 +309,18 @@  discard block
 block discarded – undo
309 309
  *     Code HTML retourné par le filtre
310 310
  **/
311 311
 function filtrer($filtre) {
312
-	$tous = func_get_args();
313
-	if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
314
-		return image_filtrer($tous);
315
-	} elseif ($f = chercher_filtre($filtre)) {
316
-		array_shift($tous);
317
-		return $f(...$tous);
318
-	} else {
319
-		// le filtre n'existe pas, on provoque une erreur
320
-		$msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
321
-		erreur_squelette($msg);
322
-		return '';
323
-	}
312
+    $tous = func_get_args();
313
+    if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') {
314
+        return image_filtrer($tous);
315
+    } elseif ($f = chercher_filtre($filtre)) {
316
+        array_shift($tous);
317
+        return $f(...$tous);
318
+    } else {
319
+        // le filtre n'existe pas, on provoque une erreur
320
+        $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]];
321
+        erreur_squelette($msg);
322
+        return '';
323
+    }
324 324
 }
325 325
 
326 326
 /**
@@ -337,11 +337,11 @@  discard block
 block discarded – undo
337 337
  * @return bool true si on trouve le filtre dans la matrice, false sinon.
338 338
  */
339 339
 function trouver_filtre_matrice($filtre) {
340
-	if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
341
-		find_in_path($f, '', true);
342
-		$GLOBALS['spip_matrice'][$filtre] = true;
343
-	}
344
-	return !empty($GLOBALS['spip_matrice'][$filtre]);
340
+    if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) {
341
+        find_in_path($f, '', true);
342
+        $GLOBALS['spip_matrice'][$filtre] = true;
343
+    }
344
+    return !empty($GLOBALS['spip_matrice'][$filtre]);
345 345
 }
346 346
 
347 347
 
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
  * @return mixed
370 370
  */
371 371
 function filtre_set(&$Pile, $val, $key, $continue = null) {
372
-	$Pile['vars'][$key] = $val;
373
-	return $continue ? $val : '';
372
+    $Pile['vars'][$key] = $val;
373
+    return $continue ? $val : '';
374 374
 }
375 375
 
376 376
 /**
@@ -396,8 +396,8 @@  discard block
 block discarded – undo
396 396
  * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''.
397 397
  */
398 398
 function filtre_setenv(&$Pile, $val, $key, $continue = null) {
399
-	$Pile[0][$key] = $val;
400
-	return $continue ? $val : '';
399
+    $Pile[0][$key] = $val;
400
+    return $continue ? $val : '';
401 401
 }
402 402
 
403 403
 /**
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
  * @return string
407 407
  */
408 408
 function filtre_sanitize_env(&$Pile, $keys) {
409
-	$Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
410
-	return '';
409
+    $Pile[0] = spip_sanitize_from_request($Pile[0], $keys);
410
+    return '';
411 411
 }
412 412
 
413 413
 
@@ -430,18 +430,18 @@  discard block
 block discarded – undo
430 430
  * @return mixed Retourne la valeur (sans la modifier).
431 431
  */
432 432
 function filtre_debug($val, $key = null) {
433
-	$debug = (
434
-		is_null($key) ? '' : (var_export($key, true) . ' = ')
435
-		) . var_export($val, true);
433
+    $debug = (
434
+        is_null($key) ? '' : (var_export($key, true) . ' = ')
435
+        ) . var_export($val, true);
436 436
 
437
-	include_spip('inc/autoriser');
438
-	if (autoriser('webmestre')) {
439
-		echo "<div class='spip_debug'>\n", $debug, "</div>\n";
440
-	}
437
+    include_spip('inc/autoriser');
438
+    if (autoriser('webmestre')) {
439
+        echo "<div class='spip_debug'>\n", $debug, "</div>\n";
440
+    }
441 441
 
442
-	spip_log($debug, 'debug');
442
+    spip_log($debug, 'debug');
443 443
 
444
-	return $val;
444
+    return $val;
445 445
 }
446 446
 
447 447
 
@@ -471,84 +471,84 @@  discard block
 block discarded – undo
471 471
  *     texte qui a reçu les filtres
472 472
  **/
473 473
 function image_filtrer($args) {
474
-	$filtre = array_shift($args); # enlever $filtre
475
-	$texte = array_shift($args);
476
-	if ($texte === null || !strlen($texte)) {
477
-		return '';
478
-	}
479
-	find_in_path('filtres_images_mini.php', 'inc/', true);
480
-	statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
481
-	// Cas du nom de fichier local
482
-	$is_file = trim($texte);
483
-	if (
484
-		strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
485
-		  or strpbrk($is_file, "<>\n\r\t") !== false
486
-		  or strpos($is_file, '/') === 0
487
-	) {
488
-		$is_file = false;
489
-	}
490
-	if ($is_file) {
491
-		$is_local_file = function ($path) {
492
-			if (strpos($path, '?') !== false) {
493
-				$path = supprimer_timestamp($path);
494
-				// remove ?24px added by find_in_theme on .svg files
495
-				$path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
496
-			}
497
-			return file_exists($path);
498
-		};
499
-		if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
500
-			$res = $filtre("<img src='$is_file' />", ...$args);
501
-			statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
502
-			return $res;
503
-		}
504
-	}
505
-
506
-	// Cas general : trier toutes les images, avec eventuellement leur <span>
507
-	if (
508
-		preg_match_all(
509
-			',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
510
-			$texte,
511
-			$tags,
512
-			PREG_SET_ORDER
513
-		)
514
-	) {
515
-		foreach ($tags as $tag) {
516
-			$class = extraire_attribut($tag[3], 'class');
517
-			if (
518
-				!$class or
519
-				(strpos($class, 'filtre_inactif') === false
520
-					// compat historique a virer en 3.2
521
-					and !str_contains($class, 'no_image_filtrer'))
522
-			) {
523
-				if ($reduit = $filtre($tag[3], ...$args)) {
524
-					// En cas de span spip_documents, modifier le style=...width:
525
-					if ($tag[1]) {
526
-						$w = extraire_attribut($reduit, 'width');
527
-						if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
528
-							$w = $regs[1];
529
-						}
530
-						if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
531
-							$style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
532
-							$replace = inserer_attribut($tag[1], 'style', $style);
533
-							$texte = str_replace($tag[1], $replace, $texte);
534
-						}
535
-					}
536
-					// traiter aussi un eventuel mouseover
537
-					if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538
-						if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539
-							$srcover = $match[1];
540
-							$srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
541
-							$srcover_filter = extraire_attribut($srcover_filter, 'src');
542
-							$reduit = str_replace($srcover, $srcover_filter, $reduit);
543
-						}
544
-					}
545
-					$texte = str_replace($tag[3], $reduit, $texte);
546
-				}
547
-			}
548
-		}
549
-	}
550
-	statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
551
-	return $texte;
474
+    $filtre = array_shift($args); # enlever $filtre
475
+    $texte = array_shift($args);
476
+    if ($texte === null || !strlen($texte)) {
477
+        return '';
478
+    }
479
+    find_in_path('filtres_images_mini.php', 'inc/', true);
480
+    statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver
481
+    // Cas du nom de fichier local
482
+    $is_file = trim($texte);
483
+    if (
484
+        strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false
485
+          or strpbrk($is_file, "<>\n\r\t") !== false
486
+          or strpos($is_file, '/') === 0
487
+    ) {
488
+        $is_file = false;
489
+    }
490
+    if ($is_file) {
491
+        $is_local_file = function ($path) {
492
+            if (strpos($path, '?') !== false) {
493
+                $path = supprimer_timestamp($path);
494
+                // remove ?24px added by find_in_theme on .svg files
495
+                $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path);
496
+            }
497
+            return file_exists($path);
498
+        };
499
+        if ($is_local_file($is_file) or tester_url_absolue($is_file)) {
500
+            $res = $filtre("<img src='$is_file' />", ...$args);
501
+            statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
502
+            return $res;
503
+        }
504
+    }
505
+
506
+    // Cas general : trier toutes les images, avec eventuellement leur <span>
507
+    if (
508
+        preg_match_all(
509
+            ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS',
510
+            $texte,
511
+            $tags,
512
+            PREG_SET_ORDER
513
+        )
514
+    ) {
515
+        foreach ($tags as $tag) {
516
+            $class = extraire_attribut($tag[3], 'class');
517
+            if (
518
+                !$class or
519
+                (strpos($class, 'filtre_inactif') === false
520
+                    // compat historique a virer en 3.2
521
+                    and !str_contains($class, 'no_image_filtrer'))
522
+            ) {
523
+                if ($reduit = $filtre($tag[3], ...$args)) {
524
+                    // En cas de span spip_documents, modifier le style=...width:
525
+                    if ($tag[1]) {
526
+                        $w = extraire_attribut($reduit, 'width');
527
+                        if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) {
528
+                            $w = $regs[1];
529
+                        }
530
+                        if ($w and ($style = extraire_attribut($tag[1], 'style'))) {
531
+                            $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style);
532
+                            $replace = inserer_attribut($tag[1], 'style', $style);
533
+                            $texte = str_replace($tag[1], $replace, $texte);
534
+                        }
535
+                    }
536
+                    // traiter aussi un eventuel mouseover
537
+                    if ($mouseover = extraire_attribut($reduit, 'onmouseover')) {
538
+                        if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) {
539
+                            $srcover = $match[1];
540
+                            $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args);
541
+                            $srcover_filter = extraire_attribut($srcover_filter, 'src');
542
+                            $reduit = str_replace($srcover, $srcover_filter, $reduit);
543
+                        }
544
+                    }
545
+                    $texte = str_replace($tag[3], $reduit, $texte);
546
+                }
547
+            }
548
+        }
549
+    }
550
+    statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo
551
+    return $texte;
552 552
 }
553 553
 
554 554
 /**
@@ -565,94 +565,94 @@  discard block
 block discarded – undo
565 565
  **/
566 566
 function infos_image($img, $force_refresh = false) {
567 567
 
568
-	static $largeur_img = [], $hauteur_img = [], $poids_img = [];
569
-	$srcWidth = 0;
570
-	$srcHeight = 0;
571
-	$srcSize = null;
572
-
573
-	$src = extraire_attribut($img, 'src');
574
-
575
-	if (!$src) {
576
-		$src = $img;
577
-	} else {
578
-		$srcWidth = extraire_attribut($img, 'width');
579
-		$srcHeight = extraire_attribut($img, 'height');
580
-		if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) {
581
-			$srcWidth = $srcHeight = 0;
582
-		}
583
-	}
584
-
585
-	// ne jamais operer directement sur une image distante pour des raisons de perfo
586
-	// la copie locale a toutes les chances d'etre la ou de resservir
587
-	if (tester_url_absolue($src)) {
588
-		include_spip('inc/distant');
589
-		$fichier = copie_locale($src);
590
-		$src = $fichier ? _DIR_RACINE . $fichier : $src;
591
-	}
592
-	if (($p = strpos($src, '?')) !== false) {
593
-		$src = substr($src, 0, $p);
594
-	}
595
-
596
-	$imagesize = false;
597
-	if (isset($largeur_img[$src]) and !$force_refresh) {
598
-		$srcWidth = $largeur_img[$src];
599
-	}
600
-	if (isset($hauteur_img[$src]) and !$force_refresh) {
601
-		$srcHeight = $hauteur_img[$src];
602
-	}
603
-	if (isset($poids_img[$src]) and !$force_refresh) {
604
-		$srcSize = $poids_img[$src];
605
-	}
606
-	if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
607
-		if (
608
-			file_exists($src)
609
-			and $imagesize = spip_getimagesize($src)
610
-		) {
611
-			if (!$srcWidth) {
612
-				$largeur_img[$src] = $srcWidth = $imagesize[0];
613
-			}
614
-			if (!$srcHeight) {
615
-				$hauteur_img[$src] = $srcHeight = $imagesize[1];
616
-			}
617
-			if (!$srcSize) {
618
-				$poids_img[$src] = filesize($src);
619
-			}
620
-		}
621
-		elseif (strpos($src, '<svg') !== false) {
622
-			include_spip('inc/svg');
623
-			if ($attrs = svg_lire_attributs($src)) {
624
-				[$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
625
-				if (!$srcWidth) {
626
-					$largeur_img[$src] = $srcWidth = $width;
627
-				}
628
-				if (!$srcHeight) {
629
-					$hauteur_img[$src] = $srcHeight = $height;
630
-				}
631
-				if (!$srcSize) {
632
-					$poids_img[$src] = $srcSize = strlen($src);
633
-				}
634
-			}
635
-		}
636
-		// $src peut etre une reference a une image temporaire dont a n'a que le log .src
637
-		// on s'y refere, l'image sera reconstruite en temps utile si necessaire
638
-		elseif (
639
-			@file_exists($f = "$src.src")
640
-			and lire_fichier($f, $valeurs)
641
-			and $valeurs = unserialize($valeurs)
642
-		) {
643
-			if (!$srcWidth) {
644
-				$largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
645
-			}
646
-			if (!$srcHeight) {
647
-				$hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
648
-			}
649
-			if (!$srcSize) {
650
-				$poids_img[$src] = $srcSize = 0;
651
-			}
652
-		}
653
-	}
654
-
655
-	return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
568
+    static $largeur_img = [], $hauteur_img = [], $poids_img = [];
569
+    $srcWidth = 0;
570
+    $srcHeight = 0;
571
+    $srcSize = null;
572
+
573
+    $src = extraire_attribut($img, 'src');
574
+
575
+    if (!$src) {
576
+        $src = $img;
577
+    } else {
578
+        $srcWidth = extraire_attribut($img, 'width');
579
+        $srcHeight = extraire_attribut($img, 'height');
580
+        if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) {
581
+            $srcWidth = $srcHeight = 0;
582
+        }
583
+    }
584
+
585
+    // ne jamais operer directement sur une image distante pour des raisons de perfo
586
+    // la copie locale a toutes les chances d'etre la ou de resservir
587
+    if (tester_url_absolue($src)) {
588
+        include_spip('inc/distant');
589
+        $fichier = copie_locale($src);
590
+        $src = $fichier ? _DIR_RACINE . $fichier : $src;
591
+    }
592
+    if (($p = strpos($src, '?')) !== false) {
593
+        $src = substr($src, 0, $p);
594
+    }
595
+
596
+    $imagesize = false;
597
+    if (isset($largeur_img[$src]) and !$force_refresh) {
598
+        $srcWidth = $largeur_img[$src];
599
+    }
600
+    if (isset($hauteur_img[$src]) and !$force_refresh) {
601
+        $srcHeight = $hauteur_img[$src];
602
+    }
603
+    if (isset($poids_img[$src]) and !$force_refresh) {
604
+        $srcSize = $poids_img[$src];
605
+    }
606
+    if (!$srcWidth or !$srcHeight or is_null($srcSize)) {
607
+        if (
608
+            file_exists($src)
609
+            and $imagesize = spip_getimagesize($src)
610
+        ) {
611
+            if (!$srcWidth) {
612
+                $largeur_img[$src] = $srcWidth = $imagesize[0];
613
+            }
614
+            if (!$srcHeight) {
615
+                $hauteur_img[$src] = $srcHeight = $imagesize[1];
616
+            }
617
+            if (!$srcSize) {
618
+                $poids_img[$src] = filesize($src);
619
+            }
620
+        }
621
+        elseif (strpos($src, '<svg') !== false) {
622
+            include_spip('inc/svg');
623
+            if ($attrs = svg_lire_attributs($src)) {
624
+                [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs);
625
+                if (!$srcWidth) {
626
+                    $largeur_img[$src] = $srcWidth = $width;
627
+                }
628
+                if (!$srcHeight) {
629
+                    $hauteur_img[$src] = $srcHeight = $height;
630
+                }
631
+                if (!$srcSize) {
632
+                    $poids_img[$src] = $srcSize = strlen($src);
633
+                }
634
+            }
635
+        }
636
+        // $src peut etre une reference a une image temporaire dont a n'a que le log .src
637
+        // on s'y refere, l'image sera reconstruite en temps utile si necessaire
638
+        elseif (
639
+            @file_exists($f = "$src.src")
640
+            and lire_fichier($f, $valeurs)
641
+            and $valeurs = unserialize($valeurs)
642
+        ) {
643
+            if (!$srcWidth) {
644
+                $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest'];
645
+            }
646
+            if (!$srcHeight) {
647
+                $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest'];
648
+            }
649
+            if (!$srcSize) {
650
+                $poids_img[$src] = $srcSize = 0;
651
+            }
652
+        }
653
+    }
654
+
655
+    return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize];
656 656
 }
657 657
 
658 658
 /**
@@ -668,13 +668,13 @@  discard block
 block discarded – undo
668 668
  *     poids
669 669
  **/
670 670
 function poids_image($img, $force_refresh = false) {
671
-	$infos = infos_image($img, $force_refresh);
672
-	return $infos['poids'];
671
+    $infos = infos_image($img, $force_refresh);
672
+    return $infos['poids'];
673 673
 }
674 674
 
675 675
 function taille_image($img, $force_refresh = false) {
676
-	$infos = infos_image($img, $force_refresh);
677
-	return [$infos['hauteur'], $infos['largeur']];
676
+    $infos = infos_image($img, $force_refresh);
677
+    return [$infos['hauteur'], $infos['largeur']];
678 678
 }
679 679
 
680 680
 /**
@@ -691,12 +691,12 @@  discard block
 block discarded – undo
691 691
  *     Largeur en pixels, NULL ou 0 si aucune image.
692 692
  **/
693 693
 function largeur($img) {
694
-	if (!$img) {
695
-		return;
696
-	}
697
-	[$h, $l] = taille_image($img);
694
+    if (!$img) {
695
+        return;
696
+    }
697
+    [$h, $l] = taille_image($img);
698 698
 
699
-	return $l;
699
+    return $l;
700 700
 }
701 701
 
702 702
 /**
@@ -713,12 +713,12 @@  discard block
 block discarded – undo
713 713
  *     Hauteur en pixels, NULL ou 0 si aucune image.
714 714
  **/
715 715
 function hauteur($img) {
716
-	if (!$img) {
717
-		return;
718
-	}
719
-	[$h, $l] = taille_image($img);
716
+    if (!$img) {
717
+        return;
718
+    }
719
+    [$h, $l] = taille_image($img);
720 720
 
721
-	return $h;
721
+    return $h;
722 722
 }
723 723
 
724 724
 
@@ -738,11 +738,11 @@  discard block
 block discarded – undo
738 738
  * @return string
739 739
  **/
740 740
 function corriger_entites_html($texte) {
741
-	if (strpos($texte, '&amp;') === false) {
742
-		return $texte;
743
-	}
741
+    if (strpos($texte, '&amp;') === false) {
742
+        return $texte;
743
+    }
744 744
 
745
-	return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
745
+    return preg_replace(',&amp;(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte);
746 746
 }
747 747
 
748 748
 /**
@@ -757,11 +757,11 @@  discard block
 block discarded – undo
757 757
  * @return string
758 758
  **/
759 759
 function corriger_toutes_entites_html($texte) {
760
-	if (strpos($texte, '&amp;') === false) {
761
-		return $texte;
762
-	}
760
+    if (strpos($texte, '&amp;') === false) {
761
+        return $texte;
762
+    }
763 763
 
764
-	return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
764
+    return preg_replace(',&amp;(#?[a-z0-9]+;),iS', '&\1', $texte);
765 765
 }
766 766
 
767 767
 /**
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
  * @return string
772 772
  **/
773 773
 function proteger_amp($texte) {
774
-	return str_replace('&', '&amp;', $texte);
774
+    return str_replace('&', '&amp;', $texte);
775 775
 }
776 776
 
777 777
 
@@ -802,21 +802,21 @@  discard block
 block discarded – undo
802 802
  * @return mixed|string
803 803
  */
804 804
 function entites_html($texte, $tout = false, $quote = true) {
805
-	if (
806
-		!is_string($texte) or !$texte
807
-		or strpbrk($texte, "&\"'<>") == false
808
-	) {
809
-		return $texte;
810
-	}
811
-	include_spip('inc/texte');
812
-	$flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
813
-	$flags |= ENT_HTML401;
814
-	$texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
815
-	if ($tout) {
816
-		return corriger_toutes_entites_html($texte);
817
-	} else {
818
-		return corriger_entites_html($texte);
819
-	}
805
+    if (
806
+        !is_string($texte) or !$texte
807
+        or strpbrk($texte, "&\"'<>") == false
808
+    ) {
809
+        return $texte;
810
+    }
811
+    include_spip('inc/texte');
812
+    $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES);
813
+    $flags |= ENT_HTML401;
814
+    $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags);
815
+    if ($tout) {
816
+        return corriger_toutes_entites_html($texte);
817
+    } else {
818
+        return corriger_entites_html($texte);
819
+    }
820 820
 }
821 821
 
822 822
 /**
@@ -835,38 +835,38 @@  discard block
 block discarded – undo
835 835
  *     texte converti
836 836
  **/
837 837
 function filtrer_entites(?string $texte): string {
838
-	$texte ??= '';
839
-	if (strpos($texte, '&') === false) {
840
-		return $texte;
841
-	}
842
-	// filtrer
843
-	$texte = html2unicode($texte);
844
-	// remettre le tout dans le charset cible
845
-	$texte = unicode2charset($texte);
846
-	// cas particulier des " et ' qu'il faut filtrer aussi
847
-	// (on le faisait deja avec un &quot;)
848
-	if (strpos($texte, '&#') !== false) {
849
-		$texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
850
-	}
838
+    $texte ??= '';
839
+    if (strpos($texte, '&') === false) {
840
+        return $texte;
841
+    }
842
+    // filtrer
843
+    $texte = html2unicode($texte);
844
+    // remettre le tout dans le charset cible
845
+    $texte = unicode2charset($texte);
846
+    // cas particulier des " et ' qu'il faut filtrer aussi
847
+    // (on le faisait deja avec un &quot;)
848
+    if (strpos($texte, '&#') !== false) {
849
+        $texte = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $texte);
850
+    }
851 851
 
852
-	return $texte;
852
+    return $texte;
853 853
 }
854 854
 
855 855
 
856 856
 if (!function_exists('filtre_filtrer_entites_dist')) {
857
-	/**
858
-	 * Version sécurisée de filtrer_entites
859
-	 *
860
-	 * @uses interdire_scripts()
861
-	 * @uses filtrer_entites()
862
-	 *
863
-	 * @param string $t
864
-	 * @return string
865
-	 */
866
-	function filtre_filtrer_entites_dist($t) {
867
-		include_spip('inc/texte');
868
-		return interdire_scripts(filtrer_entites($t));
869
-	}
857
+    /**
858
+     * Version sécurisée de filtrer_entites
859
+     *
860
+     * @uses interdire_scripts()
861
+     * @uses filtrer_entites()
862
+     *
863
+     * @param string $t
864
+     * @return string
865
+     */
866
+    function filtre_filtrer_entites_dist($t) {
867
+        include_spip('inc/texte');
868
+        return interdire_scripts(filtrer_entites($t));
869
+    }
870 870
 }
871 871
 
872 872
 
@@ -881,18 +881,18 @@  discard block
 block discarded – undo
881 881
  * @return string|array
882 882
  **/
883 883
 function supprimer_caracteres_illegaux($texte) {
884
-	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";
885
-	static $to = null;
884
+    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";
885
+    static $to = null;
886 886
 
887
-	if (is_array($texte)) {
888
-		return array_map('supprimer_caracteres_illegaux', $texte);
889
-	}
887
+    if (is_array($texte)) {
888
+        return array_map('supprimer_caracteres_illegaux', $texte);
889
+    }
890 890
 
891
-	if (!$to) {
892
-		$to = str_repeat('-', strlen($from));
893
-	}
891
+    if (!$to) {
892
+        $to = str_repeat('-', strlen($from));
893
+    }
894 894
 
895
-	return strtr($texte, $from, $to);
895
+    return strtr($texte, $from, $to);
896 896
 }
897 897
 
898 898
 /**
@@ -904,10 +904,10 @@  discard block
 block discarded – undo
904 904
  * @return string|array
905 905
  **/
906 906
 function corriger_caracteres($texte) {
907
-	$texte = corriger_caracteres_windows($texte);
908
-	$texte = supprimer_caracteres_illegaux($texte);
907
+    $texte = corriger_caracteres_windows($texte);
908
+    $texte = supprimer_caracteres_illegaux($texte);
909 909
 
910
-	return $texte;
910
+    return $texte;
911 911
 }
912 912
 
913 913
 /**
@@ -924,44 +924,44 @@  discard block
 block discarded – undo
924 924
  *     texte encodé pour XML
925 925
  */
926 926
 function texte_backend(string $texte): string {
927
-	if ($texte === '') {
928
-		return '';
929
-	}
927
+    if ($texte === '') {
928
+        return '';
929
+    }
930 930
 
931
-	static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
931
+    static $apostrophe = ['&#8217;', "'"]; # n'allouer qu'une fois
932 932
 
933
-	// si on a des liens ou des images, les passer en absolu
934
-	$texte = liens_absolus($texte);
933
+    // si on a des liens ou des images, les passer en absolu
934
+    $texte = liens_absolus($texte);
935 935
 
936
-	// echapper les tags &gt; &lt;
937
-	$texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
936
+    // echapper les tags &gt; &lt;
937
+    $texte = preg_replace(',&(gt|lt);,S', '&amp;\1;', $texte);
938 938
 
939
-	// importer les &eacute;
940
-	$texte = filtrer_entites($texte);
939
+    // importer les &eacute;
940
+    $texte = filtrer_entites($texte);
941 941
 
942
-	// " -> &quot; et tout ce genre de choses
943
-	$u = $GLOBALS['meta']['pcre_u'];
944
-	$texte = str_replace('&nbsp;', ' ', $texte);
945
-	$texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
946
-	// ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
947
-	$texte = entites_html($texte, false, false);
948
-	// mais bien echapper les double quotes !
949
-	$texte = str_replace('"', '&#034;', $texte);
942
+    // " -> &quot; et tout ce genre de choses
943
+    $u = $GLOBALS['meta']['pcre_u'];
944
+    $texte = str_replace('&nbsp;', ' ', $texte);
945
+    $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte);
946
+    // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal
947
+    $texte = entites_html($texte, false, false);
948
+    // mais bien echapper les double quotes !
949
+    $texte = str_replace('"', '&#034;', $texte);
950 950
 
951
-	// verifier le charset
952
-	$texte = charset2unicode($texte);
951
+    // verifier le charset
952
+    $texte = charset2unicode($texte);
953 953
 
954
-	// Caracteres problematiques en iso-latin 1
955
-	if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
956
-		$texte = str_replace(chr(156), '&#156;', $texte);
957
-		$texte = str_replace(chr(140), '&#140;', $texte);
958
-		$texte = str_replace(chr(159), '&#159;', $texte);
959
-	}
954
+    // Caracteres problematiques en iso-latin 1
955
+    if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') {
956
+        $texte = str_replace(chr(156), '&#156;', $texte);
957
+        $texte = str_replace(chr(140), '&#140;', $texte);
958
+        $texte = str_replace(chr(159), '&#159;', $texte);
959
+    }
960 960
 
961
-	// l'apostrophe curly pose probleme a certains lecteure de RSS
962
-	// et le caractere apostrophe alourdit les squelettes avec PHP
963
-	// ==> on les remplace par l'entite HTML
964
-	return str_replace($apostrophe, "'", $texte);
961
+    // l'apostrophe curly pose probleme a certains lecteure de RSS
962
+    // et le caractere apostrophe alourdit les squelettes avec PHP
963
+    // ==> on les remplace par l'entite HTML
964
+    return str_replace($apostrophe, "'", $texte);
965 965
 }
966 966
 
967 967
 /**
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
  *     texte encodé et quote pour XML
979 979
  */
980 980
 function texte_backendq(string $texte): string {
981
-	return addslashes(texte_backend($texte));
981
+    return addslashes(texte_backend($texte));
982 982
 }
983 983
 
984 984
 
@@ -1000,14 +1000,14 @@  discard block
 block discarded – undo
1000 1000
  *     Texte sans son numéro éventuel
1001 1001
  **/
1002 1002
 function supprimer_numero(?string $texte): string {
1003
-	if ($texte === null) {
1004
-		return '';
1005
-	}
1006
-	return preg_replace(
1007
-		',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1008
-		'',
1009
-		$texte
1010
-	);
1003
+    if ($texte === null) {
1004
+        return '';
1005
+    }
1006
+    return preg_replace(
1007
+        ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1008
+        '',
1009
+        $texte
1010
+    );
1011 1011
 }
1012 1012
 
1013 1013
 /**
@@ -1030,18 +1030,18 @@  discard block
 block discarded – undo
1030 1030
  *     Numéro de titre, sinon chaîne vide
1031 1031
  **/
1032 1032
 function recuperer_numero(?string $texte): string {
1033
-	if (
1034
-		$texte and
1035
-		preg_match(
1036
-			',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1037
-			$texte,
1038
-			$regs
1039
-		)
1040
-	) {
1041
-		return strval($regs[1]);
1042
-	} else {
1043
-		return '';
1044
-	}
1033
+    if (
1034
+        $texte and
1035
+        preg_match(
1036
+            ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S',
1037
+            $texte,
1038
+            $regs
1039
+        )
1040
+    ) {
1041
+        return strval($regs[1]);
1042
+    } else {
1043
+        return '';
1044
+    }
1045 1045
 }
1046 1046
 
1047 1047
 /**
@@ -1068,16 +1068,16 @@  discard block
 block discarded – undo
1068 1068
  *     texte ou tableau de textes converti
1069 1069
  **/
1070 1070
 function supprimer_tags($texte, $rempl = '') {
1071
-	if ($texte === null) {
1072
-		return '';
1073
-	}
1074
-	$texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1075
-	// ne pas oublier un < final non ferme car coupe
1076
-	$texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1077
-	// mais qui peut aussi etre un simple signe plus petit que
1078
-	$texte = str_replace('<', '&lt;', $texte);
1071
+    if ($texte === null) {
1072
+        return '';
1073
+    }
1074
+    $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte);
1075
+    // ne pas oublier un < final non ferme car coupe
1076
+    $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte);
1077
+    // mais qui peut aussi etre un simple signe plus petit que
1078
+    $texte = str_replace('<', '&lt;', $texte);
1079 1079
 
1080
-	return $texte;
1080
+    return $texte;
1081 1081
 }
1082 1082
 
1083 1083
 /**
@@ -1100,9 +1100,9 @@  discard block
 block discarded – undo
1100 1100
  *     texte converti
1101 1101
  **/
1102 1102
 function echapper_tags($texte, $rempl = '') {
1103
-	$texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1103
+    $texte = preg_replace('/<([^>]*)>/', "&lt;\\1&gt;", $texte);
1104 1104
 
1105
-	return $texte;
1105
+    return $texte;
1106 1106
 }
1107 1107
 
1108 1108
 /**
@@ -1123,18 +1123,18 @@  discard block
 block discarded – undo
1123 1123
  *     texte converti
1124 1124
  **/
1125 1125
 function textebrut($texte) {
1126
-	$u = $GLOBALS['meta']['pcre_u'];
1127
-	$texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1128
-	$texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1129
-	$texte = preg_replace("/^\n+/", '', $texte);
1130
-	$texte = preg_replace("/\n+$/", '', $texte);
1131
-	$texte = preg_replace("/\n +/", "\n", $texte);
1132
-	$texte = supprimer_tags($texte);
1133
-	$texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1134
-	// nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1135
-	$texte = str_replace('&#8217;', "'", $texte);
1126
+    $u = $GLOBALS['meta']['pcre_u'];
1127
+    $texte = preg_replace('/\s+/S' . $u, ' ', $texte);
1128
+    $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte);
1129
+    $texte = preg_replace("/^\n+/", '', $texte);
1130
+    $texte = preg_replace("/\n+$/", '', $texte);
1131
+    $texte = preg_replace("/\n +/", "\n", $texte);
1132
+    $texte = supprimer_tags($texte);
1133
+    $texte = preg_replace('/(&nbsp;| )+/S', ' ', $texte);
1134
+    // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail...
1135
+    $texte = str_replace('&#8217;', "'", $texte);
1136 1136
 
1137
-	return $texte;
1137
+    return $texte;
1138 1138
 }
1139 1139
 
1140 1140
 
@@ -1150,23 +1150,23 @@  discard block
 block discarded – undo
1150 1150
  *     texte avec liens ouvrants
1151 1151
  **/
1152 1152
 function liens_ouvrants($texte) {
1153
-	if (
1154
-		preg_match_all(
1155
-			",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1156
-			$texte,
1157
-			$liens,
1158
-			PREG_PATTERN_ORDER
1159
-		)
1160
-	) {
1161
-		foreach ($liens[0] as $a) {
1162
-			$rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1163
-			$ablank = inserer_attribut($a, 'rel', $rel);
1164
-			$ablank = inserer_attribut($ablank, 'target', '_blank');
1165
-			$texte = str_replace($a, $ablank, $texte);
1166
-		}
1167
-	}
1168
-
1169
-	return $texte;
1153
+    if (
1154
+        preg_match_all(
1155
+            ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS",
1156
+            $texte,
1157
+            $liens,
1158
+            PREG_PATTERN_ORDER
1159
+        )
1160
+    ) {
1161
+        foreach ($liens[0] as $a) {
1162
+            $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel');
1163
+            $ablank = inserer_attribut($a, 'rel', $rel);
1164
+            $ablank = inserer_attribut($ablank, 'target', '_blank');
1165
+            $texte = str_replace($a, $ablank, $texte);
1166
+        }
1167
+    }
1168
+
1169
+    return $texte;
1170 1170
 }
1171 1171
 
1172 1172
 /**
@@ -1176,22 +1176,22 @@  discard block
 block discarded – undo
1176 1176
  * @return string
1177 1177
  */
1178 1178
 function liens_nofollow($texte) {
1179
-	if (stripos($texte, '<a') === false) {
1180
-		return $texte;
1181
-	}
1179
+    if (stripos($texte, '<a') === false) {
1180
+        return $texte;
1181
+    }
1182 1182
 
1183
-	if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1184
-		foreach ($regs[0] as $a) {
1185
-			$rel = extraire_attribut($a, 'rel') ?? '';
1186
-			if (strpos($rel, 'nofollow') === false) {
1187
-				$rel = 'nofollow' . ($rel ? " $rel" : '');
1188
-				$anofollow = inserer_attribut($a, 'rel', $rel);
1189
-				$texte = str_replace($a, $anofollow, $texte);
1190
-			}
1191
-		}
1192
-	}
1183
+    if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) {
1184
+        foreach ($regs[0] as $a) {
1185
+            $rel = extraire_attribut($a, 'rel') ?? '';
1186
+            if (strpos($rel, 'nofollow') === false) {
1187
+                $rel = 'nofollow' . ($rel ? " $rel" : '');
1188
+                $anofollow = inserer_attribut($a, 'rel', $rel);
1189
+                $texte = str_replace($a, $anofollow, $texte);
1190
+            }
1191
+        }
1192
+    }
1193 1193
 
1194
-	return $texte;
1194
+    return $texte;
1195 1195
 }
1196 1196
 
1197 1197
 /**
@@ -1210,12 +1210,12 @@  discard block
 block discarded – undo
1210 1210
  *     texte sans paraghaphes
1211 1211
  **/
1212 1212
 function PtoBR($texte) {
1213
-	$u = $GLOBALS['meta']['pcre_u'];
1214
-	$texte = preg_replace('@</p>@iS', "\n", $texte);
1215
-	$texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1216
-	$texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1213
+    $u = $GLOBALS['meta']['pcre_u'];
1214
+    $texte = preg_replace('@</p>@iS', "\n", $texte);
1215
+    $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte);
1216
+    $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte);
1217 1217
 
1218
-	return $texte;
1218
+    return $texte;
1219 1219
 }
1220 1220
 
1221 1221
 
@@ -1240,14 +1240,14 @@  discard block
 block discarded – undo
1240 1240
  * @return string texte encadré du style CSS
1241 1241
  */
1242 1242
 function lignes_longues($texte) {
1243
-	if (!strlen(trim($texte))) {
1244
-		return $texte;
1245
-	}
1246
-	include_spip('inc/texte');
1247
-	$tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1248
-		'div' : 'span';
1243
+    if (!strlen(trim($texte))) {
1244
+        return $texte;
1245
+    }
1246
+    include_spip('inc/texte');
1247
+    $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ?
1248
+        'div' : 'span';
1249 1249
 
1250
-	return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1250
+    return "<$tag style='word-wrap:break-word;'>$texte</$tag>";
1251 1251
 }
1252 1252
 
1253 1253
 /**
@@ -1266,30 +1266,30 @@  discard block
 block discarded – undo
1266 1266
  * @return string texte en majuscule
1267 1267
  */
1268 1268
 function majuscules($texte) {
1269
-	if (!strlen($texte)) {
1270
-		return '';
1271
-	}
1269
+    if (!strlen($texte)) {
1270
+        return '';
1271
+    }
1272 1272
 
1273
-	// Cas du turc
1274
-	if ($GLOBALS['spip_lang'] == 'tr') {
1275
-		# remplacer hors des tags et des entites
1276
-		if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1277
-			foreach ($regs as $n => $match) {
1278
-				$texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1279
-			}
1280
-		}
1273
+    // Cas du turc
1274
+    if ($GLOBALS['spip_lang'] == 'tr') {
1275
+        # remplacer hors des tags et des entites
1276
+        if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) {
1277
+            foreach ($regs as $n => $match) {
1278
+                $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte);
1279
+            }
1280
+        }
1281 1281
 
1282
-		$texte = str_replace('i', '&#304;', $texte);
1282
+        $texte = str_replace('i', '&#304;', $texte);
1283 1283
 
1284
-		if ($regs) {
1285
-			foreach ($regs as $n => $match) {
1286
-				$texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1287
-			}
1288
-		}
1289
-	}
1284
+        if ($regs) {
1285
+            foreach ($regs as $n => $match) {
1286
+                $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte);
1287
+            }
1288
+        }
1289
+    }
1290 1290
 
1291
-	// Cas general
1292
-	return "<span style='text-transform: uppercase;'>$texte</span>";
1291
+    // Cas general
1292
+    return "<span style='text-transform: uppercase;'>$texte</span>";
1293 1293
 }
1294 1294
 
1295 1295
 /**
@@ -1311,38 +1311,38 @@  discard block
 block discarded – undo
1311 1311
  */
1312 1312
 function taille_en_octets($octets, $systeme = 'BI') {
1313 1313
 
1314
-	// Texte à afficher pour la taille
1315
-	$affichage = '';
1314
+    // Texte à afficher pour la taille
1315
+    $affichage = '';
1316 1316
 
1317
-	static $unites = ['octets', 'ko', 'mo', 'go'];
1318
-	static $precisions = [0, 1, 1, 2];
1317
+    static $unites = ['octets', 'ko', 'mo', 'go'];
1318
+    static $precisions = [0, 1, 1, 2];
1319 1319
 
1320
-	if ($octets >= 1) {
1321
-		// Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1322
-		$systeme = strtolower($systeme);
1323
-		if ($systeme === 'bi') {
1324
-			$kilo = 1024;
1325
-			$suffixe_item = "_$systeme";
1326
-		} elseif ($systeme === 'si') {
1327
-			$kilo = 1000;
1328
-			$suffixe_item = '';
1329
-		} else {
1330
-			return $affichage;
1331
-		}
1320
+    if ($octets >= 1) {
1321
+        // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi
1322
+        $systeme = strtolower($systeme);
1323
+        if ($systeme === 'bi') {
1324
+            $kilo = 1024;
1325
+            $suffixe_item = "_$systeme";
1326
+        } elseif ($systeme === 'si') {
1327
+            $kilo = 1000;
1328
+            $suffixe_item = '';
1329
+        } else {
1330
+            return $affichage;
1331
+        }
1332 1332
 
1333
-		// Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1334
-		$puissance = floor(log($octets, $kilo));
1333
+        // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée
1334
+        $puissance = floor(log($octets, $kilo));
1335 1335
 
1336
-		// Calcul de la taille et choix de l'unité
1337
-		$affichage = _T(
1338
-			'spip:taille_' . $unites[$puissance] . $suffixe_item,
1339
-			[
1340
-				'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance])
1341
-			]
1342
-		);
1343
-	}
1336
+        // Calcul de la taille et choix de l'unité
1337
+        $affichage = _T(
1338
+            'spip:taille_' . $unites[$puissance] . $suffixe_item,
1339
+            [
1340
+                'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance])
1341
+            ]
1342
+        );
1343
+    }
1344 1344
 
1345
-	return $affichage;
1345
+    return $affichage;
1346 1346
 }
1347 1347
 
1348 1348
 
@@ -1364,21 +1364,21 @@  discard block
 block discarded – undo
1364 1364
  *     texte prêt pour être utilisé en attribut HTML
1365 1365
  **/
1366 1366
 function attribut_html(?string $texte, $textebrut = true): string {
1367
-	if ($texte === null) {
1368
-		return '';
1369
-	}
1370
-	$u = $GLOBALS['meta']['pcre_u'];
1371
-	if ($textebrut) {
1372
-		$texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1373
-	}
1374
-	$texte = texte_backend($texte);
1375
-	$texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1367
+    if ($texte === null) {
1368
+        return '';
1369
+    }
1370
+    $u = $GLOBALS['meta']['pcre_u'];
1371
+    if ($textebrut) {
1372
+        $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte));
1373
+    }
1374
+    $texte = texte_backend($texte);
1375
+    $texte = str_replace(["'", '"'], ['&#039;', '&#034;'], $texte);
1376 1376
 
1377
-	return preg_replace(
1378
-		['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1379
-		['&', '&#38;'],
1380
-		$texte
1381
-	);
1377
+    return preg_replace(
1378
+        ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'],
1379
+        ['&', '&#38;'],
1380
+        $texte
1381
+    );
1382 1382
 }
1383 1383
 
1384 1384
 
@@ -1398,15 +1398,15 @@  discard block
 block discarded – undo
1398 1398
  *     URL ou chaîne vide
1399 1399
  **/
1400 1400
 function vider_url(?string $url, $entites = true): string {
1401
-	if ($url === null) {
1402
-		return '';
1403
-	}
1404
-	# un message pour abs_url
1405
-	$GLOBALS['mode_abs_url'] = 'url';
1406
-	$url = trim($url);
1407
-	$r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1401
+    if ($url === null) {
1402
+        return '';
1403
+    }
1404
+    # un message pour abs_url
1405
+    $GLOBALS['mode_abs_url'] = 'url';
1406
+    $url = trim($url);
1407
+    $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS';
1408 1408
 
1409
-	return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1409
+    return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url);
1410 1410
 }
1411 1411
 
1412 1412
 
@@ -1421,10 +1421,10 @@  discard block
 block discarded – undo
1421 1421
  * @return string Adresse email maquillée
1422 1422
  **/
1423 1423
 function antispam($texte) {
1424
-	include_spip('inc/acces');
1425
-	$masque = creer_pass_aleatoire(3);
1424
+    include_spip('inc/acces');
1425
+    $masque = creer_pass_aleatoire(3);
1426 1426
 
1427
-	return preg_replace('/@/', " $masque ", $texte);
1427
+    return preg_replace('/@/', " $masque ", $texte);
1428 1428
 }
1429 1429
 
1430 1430
 /**
@@ -1456,8 +1456,8 @@  discard block
 block discarded – undo
1456 1456
  *     True si on a le droit d'accès, false sinon.
1457 1457
  **/
1458 1458
 function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') {
1459
-	include_spip('inc/acces');
1460
-	return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1459
+    include_spip('inc/acces');
1460
+    return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir);
1461 1461
 }
1462 1462
 
1463 1463
 /**
@@ -1481,13 +1481,13 @@  discard block
 block discarded – undo
1481 1481
  *     Retourne $texte, sinon $sinon.
1482 1482
  **/
1483 1483
 function sinon($texte, $sinon = '') {
1484
-	if ($texte) {
1485
-		return $texte;
1486
-	} elseif (is_scalar($texte) and strlen($texte)) {
1487
-		return $texte;
1488
-	} else {
1489
-		return $sinon;
1490
-	}
1484
+    if ($texte) {
1485
+        return $texte;
1486
+    } elseif (is_scalar($texte) and strlen($texte)) {
1487
+        return $texte;
1488
+    } else {
1489
+        return $sinon;
1490
+    }
1491 1491
 }
1492 1492
 
1493 1493
 /**
@@ -1511,7 +1511,7 @@  discard block
 block discarded – undo
1511 1511
  * @return mixed
1512 1512
  **/
1513 1513
 function choixsivide($a, $vide, $pasvide) {
1514
-	return $a ? $pasvide : $vide;
1514
+    return $a ? $pasvide : $vide;
1515 1515
 }
1516 1516
 
1517 1517
 /**
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
  * @return mixed
1536 1536
  **/
1537 1537
 function choixsiegal($a1, $a2, $v, $f) {
1538
-	return ($a1 == $a2) ? $v : $f;
1538
+    return ($a1 == $a2) ? $v : $f;
1539 1539
 }
1540 1540
 
1541 1541
 //
@@ -1554,13 +1554,13 @@  discard block
 block discarded – undo
1554 1554
  * @return string
1555 1555
  **/
1556 1556
 function filtrer_ical($texte) {
1557
-	#include_spip('inc/charsets');
1558
-	$texte = html2unicode($texte);
1559
-	$texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1560
-	$texte = preg_replace("/\n/", ' ', $texte);
1561
-	$texte = preg_replace('/,/', '\,', $texte);
1557
+    #include_spip('inc/charsets');
1558
+    $texte = html2unicode($texte);
1559
+    $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8');
1560
+    $texte = preg_replace("/\n/", ' ', $texte);
1561
+    $texte = preg_replace('/,/', '\,', $texte);
1562 1562
 
1563
-	return $texte;
1563
+    return $texte;
1564 1564
 }
1565 1565
 
1566 1566
 
@@ -1585,58 +1585,58 @@  discard block
 block discarded – undo
1585 1585
  * @return string
1586 1586
  **/
1587 1587
 function post_autobr($texte, $delim = "\n_ ") {
1588
-	if (!function_exists('echappe_html')) {
1589
-		include_spip('inc/texte_mini');
1590
-	}
1591
-	$texte = str_replace("\r\n", "\r", $texte);
1592
-	$texte = str_replace("\r", "\n", $texte);
1593
-
1594
-	if (preg_match(",\n+$,", $texte, $fin)) {
1595
-		$texte = substr($texte, 0, -strlen($fin = $fin[0]));
1596
-	} else {
1597
-		$fin = '';
1598
-	}
1599
-
1600
-	$texte = echappe_html($texte, '', true);
1601
-
1602
-	// echapper les modeles
1603
-	$collecteurModeles = null;
1604
-	if (strpos($texte, '<') !== false) {
1605
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1606
-		include_spip("src/Texte/Collecteur/Modeles");
1607
-		$collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1608
-		$texte = $collecteurModeles->echapper($texte);
1609
-	}
1610
-
1611
-	$debut = '';
1612
-	$suite = $texte;
1613
-	while ($t = strpos('-' . $suite, "\n", 1)) {
1614
-		$debut .= substr($suite, 0, $t - 1);
1615
-		$suite = substr($suite, $t);
1616
-		$car = substr($suite, 0, 1);
1617
-		if (
1618
-			($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1619
-			and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1620
-			and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1621
-		) {
1622
-			$debut .= $delim;
1623
-		} else {
1624
-			$debut .= "\n";
1625
-		}
1626
-		if (preg_match(",^\n+,", $suite, $regs)) {
1627
-			$debut .= $regs[0];
1628
-			$suite = substr($suite, strlen($regs[0]));
1629
-		}
1630
-	}
1631
-	$texte = $debut . $suite;
1632
-
1633
-	if ($collecteurModeles) {
1634
-		$texte = $collecteurModeles->retablir($texte);
1635
-	}
1636
-
1637
-	$texte = echappe_retour($texte);
1638
-
1639
-	return $texte . $fin;
1588
+    if (!function_exists('echappe_html')) {
1589
+        include_spip('inc/texte_mini');
1590
+    }
1591
+    $texte = str_replace("\r\n", "\r", $texte);
1592
+    $texte = str_replace("\r", "\n", $texte);
1593
+
1594
+    if (preg_match(",\n+$,", $texte, $fin)) {
1595
+        $texte = substr($texte, 0, -strlen($fin = $fin[0]));
1596
+    } else {
1597
+        $fin = '';
1598
+    }
1599
+
1600
+    $texte = echappe_html($texte, '', true);
1601
+
1602
+    // echapper les modeles
1603
+    $collecteurModeles = null;
1604
+    if (strpos($texte, '<') !== false) {
1605
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1606
+        include_spip("src/Texte/Collecteur/Modeles");
1607
+        $collecteurModeles = new Spip\Texte\Collecteur\Modeles();
1608
+        $texte = $collecteurModeles->echapper($texte);
1609
+    }
1610
+
1611
+    $debut = '';
1612
+    $suite = $texte;
1613
+    while ($t = strpos('-' . $suite, "\n", 1)) {
1614
+        $debut .= substr($suite, 0, $t - 1);
1615
+        $suite = substr($suite, $t);
1616
+        $car = substr($suite, 0, 1);
1617
+        if (
1618
+            ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}')
1619
+            and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite))
1620
+            and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut)
1621
+        ) {
1622
+            $debut .= $delim;
1623
+        } else {
1624
+            $debut .= "\n";
1625
+        }
1626
+        if (preg_match(",^\n+,", $suite, $regs)) {
1627
+            $debut .= $regs[0];
1628
+            $suite = substr($suite, strlen($regs[0]));
1629
+        }
1630
+    }
1631
+    $texte = $debut . $suite;
1632
+
1633
+    if ($collecteurModeles) {
1634
+        $texte = $collecteurModeles->retablir($texte);
1635
+    }
1636
+
1637
+    $texte = echappe_retour($texte);
1638
+
1639
+    return $texte . $fin;
1640 1640
 }
1641 1641
 
1642 1642
 
@@ -1671,30 +1671,30 @@  discard block
 block discarded – undo
1671 1671
  **/
1672 1672
 function extraire_idiome($letexte, $lang = null, $options = []) {
1673 1673
 
1674
-	if (
1675
-		$letexte
1676
-		and strpos($letexte, '<:') !== false
1677
-	) {
1678
-		if (!$lang) {
1679
-			$lang = $GLOBALS['spip_lang'];
1680
-		}
1681
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1682
-		if (is_bool($options)) {
1683
-			$options = ['echappe_span' => $options];
1684
-		}
1685
-		if (!isset($options['echappe_span'])) {
1686
-			$options = array_merge($options, ['echappe_span' => false]);
1687
-		}
1688
-		$options['lang'] = $lang;
1674
+    if (
1675
+        $letexte
1676
+        and strpos($letexte, '<:') !== false
1677
+    ) {
1678
+        if (!$lang) {
1679
+            $lang = $GLOBALS['spip_lang'];
1680
+        }
1681
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1682
+        if (is_bool($options)) {
1683
+            $options = ['echappe_span' => $options];
1684
+        }
1685
+        if (!isset($options['echappe_span'])) {
1686
+            $options = array_merge($options, ['echappe_span' => false]);
1687
+        }
1688
+        $options['lang'] = $lang;
1689 1689
 
1690
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1691
-		include_spip("src/Texte/Collecteur/Idiomes");
1692
-		$collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1690
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1691
+        include_spip("src/Texte/Collecteur/Idiomes");
1692
+        $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes();
1693 1693
 
1694
-		$letexte = $collecteurIdiomes->traiter($letexte, $options);
1694
+        $letexte = $collecteurIdiomes->traiter($letexte, $options);
1695 1695
 
1696
-	}
1697
-	return $letexte;
1696
+    }
1697
+    return $letexte;
1698 1698
 }
1699 1699
 
1700 1700
 /**
@@ -1732,34 +1732,34 @@  discard block
 block discarded – undo
1732 1732
  **/
1733 1733
 function extraire_multi($letexte, $lang = null, $options = []) {
1734 1734
 
1735
-	if (
1736
-		$letexte
1737
-		and stripos($letexte, '<multi') !== false
1738
-	) {
1739
-		if (!$lang) {
1740
-			$lang = $GLOBALS['spip_lang'];
1741
-		}
1735
+    if (
1736
+        $letexte
1737
+        and stripos($letexte, '<multi') !== false
1738
+    ) {
1739
+        if (!$lang) {
1740
+            $lang = $GLOBALS['spip_lang'];
1741
+        }
1742 1742
 
1743
-		// Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1744
-		if (is_bool($options)) {
1745
-			$options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1746
-		}
1747
-		if (!isset($options['echappe_span'])) {
1748
-			$options = array_merge($options, ['echappe_span' => false]);
1749
-		}
1750
-		if (!isset($options['lang_defaut'])) {
1751
-			$options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1752
-		}
1753
-		$options['lang'] = $lang;
1743
+        // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean
1744
+        if (is_bool($options)) {
1745
+            $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT];
1746
+        }
1747
+        if (!isset($options['echappe_span'])) {
1748
+            $options = array_merge($options, ['echappe_span' => false]);
1749
+        }
1750
+        if (!isset($options['lang_defaut'])) {
1751
+            $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]);
1752
+        }
1753
+        $options['lang'] = $lang;
1754 1754
 
1755
-		include_spip("src/Texte/Collecteur/AbstractCollecteur");
1756
-		include_spip("src/Texte/Collecteur/Multis");
1757
-		$collecteurMultis = new Spip\Texte\Collecteur\Multis();
1755
+        include_spip("src/Texte/Collecteur/AbstractCollecteur");
1756
+        include_spip("src/Texte/Collecteur/Multis");
1757
+        $collecteurMultis = new Spip\Texte\Collecteur\Multis();
1758 1758
 
1759
-		$letexte = $collecteurMultis->traiter($letexte, $options);
1760
-	}
1759
+        $letexte = $collecteurMultis->traiter($letexte, $options);
1760
+    }
1761 1761
 
1762
-	return $letexte;
1762
+    return $letexte;
1763 1763
 }
1764 1764
 
1765 1765
 /**
@@ -1769,7 +1769,7 @@  discard block
 block discarded – undo
1769 1769
  * @return string L'initiale en majuscule
1770 1770
  */
1771 1771
 function filtre_initiale($nom) {
1772
-	return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1772
+    return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1);
1773 1773
 }
1774 1774
 
1775 1775
 
@@ -1814,33 +1814,33 @@  discard block
 block discarded – undo
1814 1814
  *      - null (interne) : si on empile
1815 1815
  **/
1816 1816
 function unique($donnee, $famille = '', $cpt = false) {
1817
-	static $mem = [];
1818
-	// permettre de vider la pile et de la restaurer
1819
-	// pour le calcul de introduction...
1820
-	if ($famille == '_spip_raz_') {
1821
-		$tmp = $mem;
1822
-		$mem = [];
1823
-
1824
-		return $tmp;
1825
-	} elseif ($famille == '_spip_set_') {
1826
-		$mem = $donnee;
1827
-
1828
-		return;
1829
-	}
1830
-	// eviter une notice
1831
-	if (!isset($mem[$famille])) {
1832
-		$mem[$famille] = [];
1833
-	}
1834
-	if ($cpt) {
1835
-		return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1836
-	}
1837
-	// eviter une notice
1838
-	if (!isset($mem[$famille][$donnee])) {
1839
-		$mem[$famille][$donnee] = 0;
1840
-	}
1841
-	if (!($mem[$famille][$donnee]++)) {
1842
-		return $donnee;
1843
-	}
1817
+    static $mem = [];
1818
+    // permettre de vider la pile et de la restaurer
1819
+    // pour le calcul de introduction...
1820
+    if ($famille == '_spip_raz_') {
1821
+        $tmp = $mem;
1822
+        $mem = [];
1823
+
1824
+        return $tmp;
1825
+    } elseif ($famille == '_spip_set_') {
1826
+        $mem = $donnee;
1827
+
1828
+        return;
1829
+    }
1830
+    // eviter une notice
1831
+    if (!isset($mem[$famille])) {
1832
+        $mem[$famille] = [];
1833
+    }
1834
+    if ($cpt) {
1835
+        return is_countable($mem[$famille]) ? count($mem[$famille]) : 0;
1836
+    }
1837
+    // eviter une notice
1838
+    if (!isset($mem[$famille][$donnee])) {
1839
+        $mem[$famille][$donnee] = 0;
1840
+    }
1841
+    if (!($mem[$famille][$donnee]++)) {
1842
+        return $donnee;
1843
+    }
1844 1844
 }
1845 1845
 
1846 1846
 
@@ -1870,20 +1870,20 @@  discard block
 block discarded – undo
1870 1870
  *     Une des valeurs en fonction du compteur.
1871 1871
  **/
1872 1872
 function alterner($i, ...$args) {
1873
-	// recuperer les arguments (attention fonctions un peu space)
1874
-	$num = count($args);
1873
+    // recuperer les arguments (attention fonctions un peu space)
1874
+    $num = count($args);
1875 1875
 
1876
-	if ($num === 1 && is_array($args[0])) {
1877
-		// un tableau de valeur dont les cles sont numerotees de 0 a num
1878
-		$args = array_values($args[0]);
1879
-		$num = count($args);
1880
-	}
1876
+    if ($num === 1 && is_array($args[0])) {
1877
+        // un tableau de valeur dont les cles sont numerotees de 0 a num
1878
+        $args = array_values($args[0]);
1879
+        $num = count($args);
1880
+    }
1881 1881
 
1882
-	// un index compris entre 0 et num exclus
1883
-	$i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1884
-	$i = ($i + $num) % $num; // dans [0;$num[
1885
-	// renvoyer le i-ieme argument, modulo le nombre d'arguments
1886
-	return $args[$i];
1882
+    // un index compris entre 0 et num exclus
1883
+    $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[
1884
+    $i = ($i + $num) % $num; // dans [0;$num[
1885
+    // renvoyer le i-ieme argument, modulo le nombre d'arguments
1886
+    return $args[$i];
1887 1887
 }
1888 1888
 
1889 1889
 
@@ -1909,52 +1909,52 @@  discard block
 block discarded – undo
1909 1909
  *     - null lorsque l’attribut n’existe pas.
1910 1910
  **/
1911 1911
 function extraire_attribut($balise, $attribut, $complet = false) {
1912
-	if (is_array($balise)) {
1913
-		array_walk(
1914
-			$balise,
1915
-			function (&$a, $key, $t) {
1916
-				$a = extraire_attribut($a, $t);
1917
-			},
1918
-			$attribut
1919
-		);
1920
-
1921
-		return $balise;
1922
-	}
1923
-	if (
1924
-		$balise
1925
-		&& stripos($balise, $attribut) !== false
1926
-		&& preg_match(
1927
-			',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1928
-			. $attribut
1929
-			. '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1930
-			$balise,
1931
-			$r
1932
-		)
1933
-	) {
1934
-		if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1935
-			$r[4] = substr($r[3], 1, -1);
1936
-			$r[3] = $r[3][0];
1937
-		} elseif ($r[3] !== '') {
1938
-			$r[4] = $r[3];
1939
-			$r[3] = '';
1940
-		} else {
1941
-			$r[4] = trim($r[2]);
1942
-		}
1943
-		$att = $r[4];
1944
-		if (strpos($att, '&#') !== false) {
1945
-			$att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1946
-		}
1947
-		$att = filtrer_entites($att);
1948
-	} else {
1949
-		$att = null;
1950
-		$r = [];
1951
-	}
1952
-
1953
-	if ($complet) {
1954
-		return [$att, $r];
1955
-	} else {
1956
-		return $att;
1957
-	}
1912
+    if (is_array($balise)) {
1913
+        array_walk(
1914
+            $balise,
1915
+            function (&$a, $key, $t) {
1916
+                $a = extraire_attribut($a, $t);
1917
+            },
1918
+            $attribut
1919
+        );
1920
+
1921
+        return $balise;
1922
+    }
1923
+    if (
1924
+        $balise
1925
+        && stripos($balise, $attribut) !== false
1926
+        && preg_match(
1927
+            ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+'
1928
+            . $attribut
1929
+            . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS',
1930
+            $balise,
1931
+            $r
1932
+        )
1933
+    ) {
1934
+        if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) {
1935
+            $r[4] = substr($r[3], 1, -1);
1936
+            $r[3] = $r[3][0];
1937
+        } elseif ($r[3] !== '') {
1938
+            $r[4] = $r[3];
1939
+            $r[3] = '';
1940
+        } else {
1941
+            $r[4] = trim($r[2]);
1942
+        }
1943
+        $att = $r[4];
1944
+        if (strpos($att, '&#') !== false) {
1945
+            $att = str_replace(['&#039;', '&#39;', '&#034;', '&#34;'], ["'", "'", '"', '"'], $att);
1946
+        }
1947
+        $att = filtrer_entites($att);
1948
+    } else {
1949
+        $att = null;
1950
+        $r = [];
1951
+    }
1952
+
1953
+    if ($complet) {
1954
+        return [$att, $r];
1955
+    } else {
1956
+        return $att;
1957
+    }
1958 1958
 }
1959 1959
 
1960 1960
 /**
@@ -1987,41 +1987,41 @@  discard block
 block discarded – undo
1987 1987
  **/
1988 1988
 function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string {
1989 1989
 
1990
-	if ($balise === null or $balise === '') {
1991
-		return '';
1992
-	}
1990
+    if ($balise === null or $balise === '') {
1991
+        return '';
1992
+    }
1993 1993
 
1994
-	// preparer l'attribut
1995
-	// supprimer les &nbsp; etc mais pas les balises html
1996
-	// qui ont un sens dans un attribut value d'un input
1997
-	if ($proteger) {
1998
-		$val = attribut_html($val, false);
1999
-	}
1994
+    // preparer l'attribut
1995
+    // supprimer les &nbsp; etc mais pas les balises html
1996
+    // qui ont un sens dans un attribut value d'un input
1997
+    if ($proteger) {
1998
+        $val = attribut_html($val, false);
1999
+    }
2000 2000
 
2001
-	// echapper les ' pour eviter tout bug
2002
-	$val = str_replace("'", '&#039;', $val);
2003
-	if ($vider and strlen($val) === 0) {
2004
-		$insert = '';
2005
-	} else {
2006
-		$insert = " $attribut='$val'";
2007
-	}
2001
+    // echapper les ' pour eviter tout bug
2002
+    $val = str_replace("'", '&#039;', $val);
2003
+    if ($vider and strlen($val) === 0) {
2004
+        $insert = '';
2005
+    } else {
2006
+        $insert = " $attribut='$val'";
2007
+    }
2008 2008
 
2009
-	[$old, $r] = extraire_attribut($balise, $attribut, true);
2009
+    [$old, $r] = extraire_attribut($balise, $attribut, true);
2010 2010
 
2011
-	if ($old !== null) {
2012
-		// Remplacer l'ancien attribut du meme nom
2013
-		$balise = $r[1] . $insert . $r[5];
2014
-	} else {
2015
-		// preferer une balise " />" (comme <img />)
2016
-		if (preg_match(',/>,', $balise)) {
2017
-			$balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2018
-		} // sinon une balise <a ...> ... </a>
2019
-		else {
2020
-			$balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2021
-		}
2022
-	}
2011
+    if ($old !== null) {
2012
+        // Remplacer l'ancien attribut du meme nom
2013
+        $balise = $r[1] . $insert . $r[5];
2014
+    } else {
2015
+        // preferer une balise " />" (comme <img />)
2016
+        if (preg_match(',/>,', $balise)) {
2017
+            $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1);
2018
+        } // sinon une balise <a ...> ... </a>
2019
+        else {
2020
+            $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1);
2021
+        }
2022
+    }
2023 2023
 
2024
-	return $balise;
2024
+    return $balise;
2025 2025
 }
2026 2026
 
2027 2027
 /**
@@ -2039,7 +2039,7 @@  discard block
 block discarded – undo
2039 2039
  * @return string Code HTML sans l'attribut
2040 2040
  **/
2041 2041
 function vider_attribut(?string $balise, string $attribut): string {
2042
-	return inserer_attribut($balise, $attribut, '', false, true);
2042
+    return inserer_attribut($balise, $attribut, '', false, true);
2043 2043
 }
2044 2044
 
2045 2045
 /**
@@ -2051,53 +2051,53 @@  discard block
 block discarded – undo
2051 2051
  * @return string
2052 2052
  */
2053 2053
 function modifier_class($balise, $class, $operation = 'ajouter') {
2054
-	if (is_string($class)) {
2055
-		$class = explode(' ', trim($class));
2056
-	}
2057
-	$class = array_filter($class);
2058
-	$class = array_unique($class);
2059
-	if (!$class) {
2060
-		return $balise;
2061
-	}
2062
-
2063
-	// si la ou les classes ont des caracteres invalides on ne fait rien
2064
-	if (preg_match(',[^\w-],', implode('', $class))) {
2065
-		return $balise;
2066
-	}
2067
-
2068
-	$class_courante = extraire_attribut($balise, 'class');
2069
-	$class_new = $class_courante;
2070
-	foreach ($class as $c) {
2071
-		$is_class_presente = false;
2072
-		if (
2073
-			$class_courante
2074
-			and str_contains($class_courante, (string) $c)
2075
-			and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2076
-		) {
2077
-			$is_class_presente = true;
2078
-		}
2079
-		if (
2080
-			in_array($operation, ['ajouter', 'commuter'])
2081
-			and !$is_class_presente
2082
-		) {
2083
-			$class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2084
-		} elseif (
2085
-			in_array($operation, ['supprimer', 'commuter'])
2086
-			and $is_class_presente
2087
-		) {
2088
-			$class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2089
-		}
2090
-	}
2091
-
2092
-	if ($class_new !== $class_courante) {
2093
-		if (strlen($class_new)) {
2094
-			$balise = inserer_attribut($balise, 'class', $class_new);
2095
-		} elseif ($class_courante) {
2096
-			$balise = vider_attribut($balise, 'class');
2097
-		}
2098
-	}
2099
-
2100
-	return $balise;
2054
+    if (is_string($class)) {
2055
+        $class = explode(' ', trim($class));
2056
+    }
2057
+    $class = array_filter($class);
2058
+    $class = array_unique($class);
2059
+    if (!$class) {
2060
+        return $balise;
2061
+    }
2062
+
2063
+    // si la ou les classes ont des caracteres invalides on ne fait rien
2064
+    if (preg_match(',[^\w-],', implode('', $class))) {
2065
+        return $balise;
2066
+    }
2067
+
2068
+    $class_courante = extraire_attribut($balise, 'class');
2069
+    $class_new = $class_courante;
2070
+    foreach ($class as $c) {
2071
+        $is_class_presente = false;
2072
+        if (
2073
+            $class_courante
2074
+            and str_contains($class_courante, (string) $c)
2075
+            and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante)
2076
+        ) {
2077
+            $is_class_presente = true;
2078
+        }
2079
+        if (
2080
+            in_array($operation, ['ajouter', 'commuter'])
2081
+            and !$is_class_presente
2082
+        ) {
2083
+            $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c);
2084
+        } elseif (
2085
+            in_array($operation, ['supprimer', 'commuter'])
2086
+            and $is_class_presente
2087
+        ) {
2088
+            $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new));
2089
+        }
2090
+    }
2091
+
2092
+    if ($class_new !== $class_courante) {
2093
+        if (strlen($class_new)) {
2094
+            $balise = inserer_attribut($balise, 'class', $class_new);
2095
+        } elseif ($class_courante) {
2096
+            $balise = vider_attribut($balise, 'class');
2097
+        }
2098
+    }
2099
+
2100
+    return $balise;
2101 2101
 }
2102 2102
 
2103 2103
 /**
@@ -2107,7 +2107,7 @@  discard block
 block discarded – undo
2107 2107
  * @return string
2108 2108
  */
2109 2109
 function ajouter_class($balise, $class) {
2110
-	return modifier_class($balise, $class, 'ajouter');
2110
+    return modifier_class($balise, $class, 'ajouter');
2111 2111
 }
2112 2112
 
2113 2113
 /**
@@ -2117,7 +2117,7 @@  discard block
 block discarded – undo
2117 2117
  * @return string
2118 2118
  */
2119 2119
 function supprimer_class($balise, $class) {
2120
-	return modifier_class($balise, $class, 'supprimer');
2120
+    return modifier_class($balise, $class, 'supprimer');
2121 2121
 }
2122 2122
 
2123 2123
 /**
@@ -2128,7 +2128,7 @@  discard block
 block discarded – undo
2128 2128
  * @return string
2129 2129
  */
2130 2130
 function commuter_class($balise, $class) {
2131
-	return modifier_class($balise, $class, 'commuter');
2131
+    return modifier_class($balise, $class, 'commuter');
2132 2132
 }
2133 2133
 
2134 2134
 /**
@@ -2139,19 +2139,19 @@  discard block
 block discarded – undo
2139 2139
  * @return string
2140 2140
  */
2141 2141
 function tester_config($id, $mode = '') {
2142
-	include_spip('action/inscrire_auteur');
2142
+    include_spip('action/inscrire_auteur');
2143 2143
 
2144
-	return tester_statut_inscription($mode, $id);
2144
+    return tester_statut_inscription($mode, $id);
2145 2145
 }
2146 2146
 
2147 2147
 //
2148 2148
 // Quelques fonctions de calcul arithmetique
2149 2149
 //
2150 2150
 function floatstr($a) {
2151
- return str_replace(',', '.', (string)floatval($a));
2151
+    return str_replace(',', '.', (string)floatval($a));
2152 2152
 }
2153 2153
 function strize($f, $a, $b) {
2154
- return floatstr($f(floatstr($a), floatstr($b)));
2154
+    return floatstr($f(floatstr($a), floatstr($b)));
2155 2155
 }
2156 2156
 
2157 2157
 /**
@@ -2170,11 +2170,11 @@  discard block
 block discarded – undo
2170 2170
  * @return int $a+$b
2171 2171
  **/
2172 2172
 function plus($a, $b) {
2173
-	return $a + $b;
2173
+    return $a + $b;
2174 2174
 }
2175 2175
 
2176 2176
 function strplus($a, $b) {
2177
-	return strize('plus', $a, $b);
2177
+    return strize('plus', $a, $b);
2178 2178
 }
2179 2179
 
2180 2180
 /**
@@ -2193,11 +2193,11 @@  discard block
 block discarded – undo
2193 2193
  * @return int $a-$b
2194 2194
  **/
2195 2195
 function moins($a, $b) {
2196
-	return $a - $b;
2196
+    return $a - $b;
2197 2197
 }
2198 2198
 
2199 2199
 function strmoins($a, $b) {
2200
-	return strize('moins', $a, $b);
2200
+    return strize('moins', $a, $b);
2201 2201
 }
2202 2202
 
2203 2203
 /**
@@ -2217,11 +2217,11 @@  discard block
 block discarded – undo
2217 2217
  * @return int $a*$b
2218 2218
  **/
2219 2219
 function mult($a, $b) {
2220
-	return $a * $b;
2220
+    return $a * $b;
2221 2221
 }
2222 2222
 
2223 2223
 function strmult($a, $b) {
2224
-	return strize('mult', $a, $b);
2224
+    return strize('mult', $a, $b);
2225 2225
 }
2226 2226
 
2227 2227
 /**
@@ -2241,11 +2241,11 @@  discard block
 block discarded – undo
2241 2241
  * @return int $a/$b (ou 0 si $b est nul)
2242 2242
  **/
2243 2243
 function div($a, $b) {
2244
-	return $b ? $a / $b : 0;
2244
+    return $b ? $a / $b : 0;
2245 2245
 }
2246 2246
 
2247 2247
 function strdiv($a, $b) {
2248
-	return strize('div', $a, $b);
2248
+    return strize('div', $a, $b);
2249 2249
 }
2250 2250
 
2251 2251
 /**
@@ -2266,7 +2266,7 @@  discard block
 block discarded – undo
2266 2266
  * @return int ($nb % $mod) + $add
2267 2267
  **/
2268 2268
 function modulo($nb, $mod, $add = 0) {
2269
-	return ($mod ? $nb % $mod : 0) + $add;
2269
+    return ($mod ? $nb % $mod : 0) + $add;
2270 2270
 }
2271 2271
 
2272 2272
 
@@ -2281,26 +2281,26 @@  discard block
 block discarded – undo
2281 2281
  *      - true sinon
2282 2282
  **/
2283 2283
 function nom_acceptable($nom) {
2284
-	$remp2 = [];
2285
-	$remp1 = [];
2286
-	if (!is_string($nom)) {
2287
-		return false;
2288
-	}
2289
-	if (!defined('_TAGS_NOM_AUTEUR')) {
2290
-		define('_TAGS_NOM_AUTEUR', '');
2291
-	}
2292
-	$tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2293
-	foreach ($tags_acceptes as $tag) {
2294
-		if (strlen($tag)) {
2295
-			$remp1[] = '<' . trim($tag) . '>';
2296
-			$remp1[] = '</' . trim($tag) . '>';
2297
-			$remp2[] = '\x60' . trim($tag) . '\x61';
2298
-			$remp2[] = '\x60/' . trim($tag) . '\x61';
2299
-		}
2300
-	}
2301
-	$v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2302
-
2303
-	return str_replace('&lt;', '<', $v_nom) == $nom;
2284
+    $remp2 = [];
2285
+    $remp1 = [];
2286
+    if (!is_string($nom)) {
2287
+        return false;
2288
+    }
2289
+    if (!defined('_TAGS_NOM_AUTEUR')) {
2290
+        define('_TAGS_NOM_AUTEUR', '');
2291
+    }
2292
+    $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR));
2293
+    foreach ($tags_acceptes as $tag) {
2294
+        if (strlen($tag)) {
2295
+            $remp1[] = '<' . trim($tag) . '>';
2296
+            $remp1[] = '</' . trim($tag) . '>';
2297
+            $remp2[] = '\x60' . trim($tag) . '\x61';
2298
+            $remp2[] = '\x60/' . trim($tag) . '\x61';
2299
+        }
2300
+    }
2301
+    $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom)));
2302
+
2303
+    return str_replace('&lt;', '<', $v_nom) == $nom;
2304 2304
 }
2305 2305
 
2306 2306
 
@@ -2316,14 +2316,14 @@  discard block
 block discarded – undo
2316 2316
  *      - renvoie un tableau si l'entree est un tableau
2317 2317
  **/
2318 2318
 function email_valide($adresses) {
2319
-	if (is_array($adresses)) {
2320
-		$adresses = array_map('email_valide', $adresses);
2321
-		$adresses = array_filter($adresses);
2322
-		return $adresses;
2323
-	}
2319
+    if (is_array($adresses)) {
2320
+        $adresses = array_map('email_valide', $adresses);
2321
+        $adresses = array_filter($adresses);
2322
+        return $adresses;
2323
+    }
2324 2324
 
2325
-	$email_valide = charger_fonction('email_valide', 'inc');
2326
-	return $email_valide($adresses);
2325
+    $email_valide = charger_fonction('email_valide', 'inc');
2326
+    return $email_valide($adresses);
2327 2327
 }
2328 2328
 
2329 2329
 /**
@@ -2337,29 +2337,29 @@  discard block
 block discarded – undo
2337 2337
  * @return string texte
2338 2338
  **/
2339 2339
 function afficher_enclosures($tags) {
2340
-	$s = [];
2341
-	foreach (extraire_balises($tags, 'a') as $tag) {
2342
-		if (
2343
-			extraire_attribut($tag, 'rel') == 'enclosure'
2344
-			and $t = extraire_attribut($tag, 'href')
2345
-		) {
2346
-			$s[] = preg_replace(
2347
-				',>[^<]+</a>,S',
2348
-				'>'
2349
-				. http_img_pack(
2350
-					'attachment-16.png',
2351
-					$t,
2352
-					'',
2353
-					$t,
2354
-					['utiliser_suffixe_size' => true]
2355
-				)
2356
-				. '</a>',
2357
-				$tag
2358
-			);
2359
-		}
2360
-	}
2361
-
2362
-	return join('&nbsp;', $s);
2340
+    $s = [];
2341
+    foreach (extraire_balises($tags, 'a') as $tag) {
2342
+        if (
2343
+            extraire_attribut($tag, 'rel') == 'enclosure'
2344
+            and $t = extraire_attribut($tag, 'href')
2345
+        ) {
2346
+            $s[] = preg_replace(
2347
+                ',>[^<]+</a>,S',
2348
+                '>'
2349
+                . http_img_pack(
2350
+                    'attachment-16.png',
2351
+                    $t,
2352
+                    '',
2353
+                    $t,
2354
+                    ['utiliser_suffixe_size' => true]
2355
+                )
2356
+                . '</a>',
2357
+                $tag
2358
+            );
2359
+        }
2360
+    }
2361
+
2362
+    return join('&nbsp;', $s);
2363 2363
 }
2364 2364
 
2365 2365
 /**
@@ -2374,15 +2374,15 @@  discard block
 block discarded – undo
2374 2374
  * @return string Liens trouvés
2375 2375
  **/
2376 2376
 function afficher_tags($tags, $rels = 'tag,directory') {
2377
-	$s = [];
2378
-	foreach (extraire_balises($tags, 'a') as $tag) {
2379
-		$rel = extraire_attribut($tag, 'rel');
2380
-		if (strstr(",$rels,", (string) ",$rel,")) {
2381
-			$s[] = $tag;
2382
-		}
2383
-	}
2377
+    $s = [];
2378
+    foreach (extraire_balises($tags, 'a') as $tag) {
2379
+        $rel = extraire_attribut($tag, 'rel');
2380
+        if (strstr(",$rels,", (string) ",$rel,")) {
2381
+            $s[] = $tag;
2382
+        }
2383
+    }
2384 2384
 
2385
-	return join(', ', $s);
2385
+    return join(', ', $s);
2386 2386
 }
2387 2387
 
2388 2388
 
@@ -2404,21 +2404,21 @@  discard block
 block discarded – undo
2404 2404
  * @return string Tag HTML `<a>` avec microformat.
2405 2405
  **/
2406 2406
 function enclosure2microformat($e) {
2407
-	if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2408
-		$url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2409
-	}
2410
-	$type = extraire_attribut($e, 'type');
2411
-	if (!$length = extraire_attribut($e, 'length')) {
2412
-		# <media:content : longeur dans fileSize. On tente.
2413
-		$length = extraire_attribut($e, 'fileSize');
2414
-	}
2415
-	$fichier = basename($url);
2407
+    if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) {
2408
+        $url = filtrer_entites(extraire_attribut($e, 'href') ?? '');
2409
+    }
2410
+    $type = extraire_attribut($e, 'type');
2411
+    if (!$length = extraire_attribut($e, 'length')) {
2412
+        # <media:content : longeur dans fileSize. On tente.
2413
+        $length = extraire_attribut($e, 'fileSize');
2414
+    }
2415
+    $fichier = basename($url);
2416 2416
 
2417
-	return '<a rel="enclosure"'
2418
-	. ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2419
-	. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2420
-	. ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2421
-	. '>' . $fichier . '</a>';
2417
+    return '<a rel="enclosure"'
2418
+    . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '')
2419
+    . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2420
+    . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '')
2421
+    . '>' . $fichier . '</a>';
2422 2422
 }
2423 2423
 
2424 2424
 /**
@@ -2436,24 +2436,24 @@  discard block
 block discarded – undo
2436 2436
  * @return string Tags RSS `<enclosure>`.
2437 2437
  **/
2438 2438
 function microformat2enclosure($tags) {
2439
-	$enclosures = [];
2440
-	foreach (extraire_balises($tags, 'a') as $e) {
2441
-		if (extraire_attribut($e, 'rel') == 'enclosure') {
2442
-			$url = filtrer_entites(extraire_attribut($e, 'href'));
2443
-			$type = extraire_attribut($e, 'type');
2444
-			if (!$length = intval(extraire_attribut($e, 'title'))) {
2445
-				$length = intval(extraire_attribut($e, 'length'));
2446
-			} # vieux data
2447
-			$fichier = basename($url);
2448
-			$enclosures[] = '<enclosure'
2449
-				. ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2450
-				. ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2451
-				. ($length ? ' length="' . $length . '"' : '')
2452
-				. ' />';
2453
-		}
2454
-	}
2439
+    $enclosures = [];
2440
+    foreach (extraire_balises($tags, 'a') as $e) {
2441
+        if (extraire_attribut($e, 'rel') == 'enclosure') {
2442
+            $url = filtrer_entites(extraire_attribut($e, 'href'));
2443
+            $type = extraire_attribut($e, 'type');
2444
+            if (!$length = intval(extraire_attribut($e, 'title'))) {
2445
+                $length = intval(extraire_attribut($e, 'length'));
2446
+            } # vieux data
2447
+            $fichier = basename($url);
2448
+            $enclosures[] = '<enclosure'
2449
+                . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '')
2450
+                . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '')
2451
+                . ($length ? ' length="' . $length . '"' : '')
2452
+                . ' />';
2453
+        }
2454
+    }
2455 2455
 
2456
-	return join("\n", $enclosures);
2456
+    return join("\n", $enclosures);
2457 2457
 }
2458 2458
 
2459 2459
 
@@ -2469,16 +2469,16 @@  discard block
 block discarded – undo
2469 2469
  * @return string Tags RSS Atom `<dc:subject>`.
2470 2470
  **/
2471 2471
 function tags2dcsubject($tags) {
2472
-	$subjects = '';
2473
-	foreach (extraire_balises($tags, 'a') as $e) {
2474
-		if (extraire_attribut($e, 'rel') == 'tag') {
2475
-			$subjects .= '<dc:subject>'
2476
-				. texte_backend(textebrut($e))
2477
-				. '</dc:subject>' . "\n";
2478
-		}
2479
-	}
2472
+    $subjects = '';
2473
+    foreach (extraire_balises($tags, 'a') as $e) {
2474
+        if (extraire_attribut($e, 'rel') == 'tag') {
2475
+            $subjects .= '<dc:subject>'
2476
+                . texte_backend(textebrut($e))
2477
+                . '</dc:subject>' . "\n";
2478
+        }
2479
+    }
2480 2480
 
2481
-	return $subjects;
2481
+    return $subjects;
2482 2482
 }
2483 2483
 
2484 2484
 /**
@@ -2507,27 +2507,27 @@  discard block
 block discarded – undo
2507 2507
  *     - Tableau de résultats, si tableau en entrée.
2508 2508
  **/
2509 2509
 function extraire_balise($texte, $tag = 'a') {
2510
-	if (is_array($texte)) {
2511
-		array_walk(
2512
-			$texte,
2513
-			function (&$a, $key, $t) {
2514
-				$a = extraire_balise($a, $t);
2515
-			},
2516
-			$tag
2517
-		);
2518
-
2519
-		return $texte;
2520
-	}
2521
-
2522
-	if (
2523
-		preg_match(
2524
-			",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2525
-			$texte,
2526
-			$regs
2527
-		)
2528
-	) {
2529
-		return $regs[0];
2530
-	}
2510
+    if (is_array($texte)) {
2511
+        array_walk(
2512
+            $texte,
2513
+            function (&$a, $key, $t) {
2514
+                $a = extraire_balise($a, $t);
2515
+            },
2516
+            $tag
2517
+        );
2518
+
2519
+        return $texte;
2520
+    }
2521
+
2522
+    if (
2523
+        preg_match(
2524
+            ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS",
2525
+            $texte,
2526
+            $regs
2527
+        )
2528
+    ) {
2529
+        return $regs[0];
2530
+    }
2531 2531
 }
2532 2532
 
2533 2533
 /**
@@ -2555,30 +2555,30 @@  discard block
 block discarded – undo
2555 2555
  *     - Tableau de résultats, si tableau en entrée.
2556 2556
  **/
2557 2557
 function extraire_balises($texte, $tag = 'a') {
2558
-	if (is_array($texte)) {
2559
-		array_walk(
2560
-			$texte,
2561
-			function (&$a, $key, $t) {
2562
-				$a = extraire_balises($a, $t);
2563
-			},
2564
-			$tag
2565
-		);
2566
-
2567
-		return $texte;
2568
-	}
2569
-
2570
-	if (
2571
-		preg_match_all(
2572
-			",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2573
-			$texte,
2574
-			$regs,
2575
-			PREG_PATTERN_ORDER
2576
-		)
2577
-	) {
2578
-		return $regs[0];
2579
-	} else {
2580
-		return [];
2581
-	}
2558
+    if (is_array($texte)) {
2559
+        array_walk(
2560
+            $texte,
2561
+            function (&$a, $key, $t) {
2562
+                $a = extraire_balises($a, $t);
2563
+            },
2564
+            $tag
2565
+        );
2566
+
2567
+        return $texte;
2568
+    }
2569
+
2570
+    if (
2571
+        preg_match_all(
2572
+            ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS",
2573
+            $texte,
2574
+            $regs,
2575
+            PREG_PATTERN_ORDER
2576
+        )
2577
+    ) {
2578
+        return $regs[0];
2579
+    } else {
2580
+        return [];
2581
+    }
2582 2582
 }
2583 2583
 
2584 2584
 /**
@@ -2607,11 +2607,11 @@  discard block
 block discarded – undo
2607 2607
  *     - `$def` si on n'a pas transmis de tableau
2608 2608
  **/
2609 2609
 function in_any($val, $vals, $def = '') {
2610
-	if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2611
-		$vals = $v;
2612
-	}
2610
+    if (!is_array($vals) and $vals and $v = unserialize($vals)) {
2611
+        $vals = $v;
2612
+    }
2613 2613
 
2614
-	return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2614
+    return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : ''));
2615 2615
 }
2616 2616
 
2617 2617
 
@@ -2632,12 +2632,12 @@  discard block
 block discarded – undo
2632 2632
  *     Résultat du calcul
2633 2633
  **/
2634 2634
 function valeur_numerique($expr) {
2635
-	$a = 0;
2636
-	if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2637
-		eval("\$a = $expr;");
2638
-	}
2635
+    $a = 0;
2636
+    if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) {
2637
+        eval("\$a = $expr;");
2638
+    }
2639 2639
 
2640
-	return intval($a);
2640
+    return intval($a);
2641 2641
 }
2642 2642
 
2643 2643
 /**
@@ -2656,7 +2656,7 @@  discard block
 block discarded – undo
2656 2656
  *      Retourne `$a*$b/$c`
2657 2657
  **/
2658 2658
 function regledetrois($a, $b, $c) {
2659
-	return round($a * $b / $c);
2659
+    return round($a * $b / $c);
2660 2660
 }
2661 2661
 
2662 2662
 
@@ -2679,79 +2679,79 @@  discard block
 block discarded – undo
2679 2679
  * @return string Suite de champs input hidden
2680 2680
  **/
2681 2681
 function form_hidden(?string $action = ''): string {
2682
-	$action ??= '';
2683
-
2684
-	$contexte = [];
2685
-	include_spip('inc/urls');
2686
-	if (
2687
-		$p = urls_decoder_url($action, '')
2688
-		and reset($p)
2689
-	) {
2690
-		$fond = array_shift($p);
2691
-		if ($fond != '404') {
2692
-			$contexte = array_shift($p);
2693
-			$contexte['page'] = $fond;
2694
-			$action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2695
-		}
2696
-	}
2697
-	// defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2698
-	if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2699
-		unset($contexte['type']);
2700
-	}
2701
-	if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2702
-		unset($contexte['type-page']);
2703
-	}
2704
-
2705
-	// on va remplir un tableau de valeurs en prenant bien soin de ne pas
2706
-	// ecraser les elements de la forme mots[]=1&mots[]=2
2707
-	$values = [];
2708
-
2709
-	// d'abord avec celles de l'url
2710
-	if (false !== ($p = strpos($action, '?'))) {
2711
-		foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2712
-			$c = explode('=', $c, 2);
2713
-			$var = array_shift($c);
2714
-			$val = array_shift($c) ?? '';
2715
-			if ($var) {
2716
-				$val = rawurldecode($val);
2717
-				$var = rawurldecode($var); // decoder les [] eventuels
2718
-				if (preg_match(',\[\]$,S', $var)) {
2719
-					$values[] = [$var, $val];
2720
-				} else {
2721
-					if (!isset($values[$var])) {
2722
-						$values[$var] = [$var, $val];
2723
-					}
2724
-				}
2725
-			}
2726
-		}
2727
-	}
2728
-
2729
-	// ensuite avec celles du contexte, sans doublonner !
2730
-	foreach ($contexte as $var => $val) {
2731
-		if (preg_match(',\[\]$,S', $var)) {
2732
-			$values[] = [$var, $val];
2733
-		} else {
2734
-			if (!isset($values[$var])) {
2735
-				$values[$var] = [$var, $val];
2736
-			}
2737
-		}
2738
-	}
2739
-
2740
-	// puis on rassemble le tout
2741
-	$hidden = [];
2742
-	foreach ($values as $value) {
2743
-		[$var, $val] = $value;
2744
-		$hidden[] = '<input name="'
2745
-			. entites_html($var)
2746
-			. '"'
2747
-			. (is_null($val)
2748
-				? ''
2749
-				: ' value="' . entites_html($val) . '"'
2750
-			)
2751
-			. ' type="hidden"' . "\n/>";
2752
-	}
2753
-
2754
-	return join('', $hidden);
2682
+    $action ??= '';
2683
+
2684
+    $contexte = [];
2685
+    include_spip('inc/urls');
2686
+    if (
2687
+        $p = urls_decoder_url($action, '')
2688
+        and reset($p)
2689
+    ) {
2690
+        $fond = array_shift($p);
2691
+        if ($fond != '404') {
2692
+            $contexte = array_shift($p);
2693
+            $contexte['page'] = $fond;
2694
+            $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action);
2695
+        }
2696
+    }
2697
+    // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url
2698
+    if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) {
2699
+        unset($contexte['type']);
2700
+    }
2701
+    if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) {
2702
+        unset($contexte['type-page']);
2703
+    }
2704
+
2705
+    // on va remplir un tableau de valeurs en prenant bien soin de ne pas
2706
+    // ecraser les elements de la forme mots[]=1&mots[]=2
2707
+    $values = [];
2708
+
2709
+    // d'abord avec celles de l'url
2710
+    if (false !== ($p = strpos($action, '?'))) {
2711
+        foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) {
2712
+            $c = explode('=', $c, 2);
2713
+            $var = array_shift($c);
2714
+            $val = array_shift($c) ?? '';
2715
+            if ($var) {
2716
+                $val = rawurldecode($val);
2717
+                $var = rawurldecode($var); // decoder les [] eventuels
2718
+                if (preg_match(',\[\]$,S', $var)) {
2719
+                    $values[] = [$var, $val];
2720
+                } else {
2721
+                    if (!isset($values[$var])) {
2722
+                        $values[$var] = [$var, $val];
2723
+                    }
2724
+                }
2725
+            }
2726
+        }
2727
+    }
2728
+
2729
+    // ensuite avec celles du contexte, sans doublonner !
2730
+    foreach ($contexte as $var => $val) {
2731
+        if (preg_match(',\[\]$,S', $var)) {
2732
+            $values[] = [$var, $val];
2733
+        } else {
2734
+            if (!isset($values[$var])) {
2735
+                $values[$var] = [$var, $val];
2736
+            }
2737
+        }
2738
+    }
2739
+
2740
+    // puis on rassemble le tout
2741
+    $hidden = [];
2742
+    foreach ($values as $value) {
2743
+        [$var, $val] = $value;
2744
+        $hidden[] = '<input name="'
2745
+            . entites_html($var)
2746
+            . '"'
2747
+            . (is_null($val)
2748
+                ? ''
2749
+                : ' value="' . entites_html($val) . '"'
2750
+            )
2751
+            . ' type="hidden"' . "\n/>";
2752
+    }
2753
+
2754
+    return join('', $hidden);
2755 2755
 }
2756 2756
 
2757 2757
 
@@ -2773,7 +2773,7 @@  discard block
 block discarded – undo
2773 2773
  *    - la première valeur du tableau sinon.
2774 2774
  **/
2775 2775
 function filtre_reset($array) {
2776
-	return !is_array($array) ? null : reset($array);
2776
+    return !is_array($array) ? null : reset($array);
2777 2777
 }
2778 2778
 
2779 2779
 /**
@@ -2794,7 +2794,7 @@  discard block
 block discarded – undo
2794 2794
  *    - la dernière valeur du tableau sinon.
2795 2795
  **/
2796 2796
 function filtre_end($array) {
2797
-	return !is_array($array) ? null : end($array);
2797
+    return !is_array($array) ? null : end($array);
2798 2798
 }
2799 2799
 
2800 2800
 /**
@@ -2814,11 +2814,11 @@  discard block
 block discarded – undo
2814 2814
  *
2815 2815
  **/
2816 2816
 function filtre_push($array, $val) {
2817
-	if (!is_array($array) or !array_push($array, $val)) {
2818
-		return '';
2819
-	}
2817
+    if (!is_array($array) or !array_push($array, $val)) {
2818
+        return '';
2819
+    }
2820 2820
 
2821
-	return $array;
2821
+    return $array;
2822 2822
 }
2823 2823
 
2824 2824
 /**
@@ -2837,7 +2837,7 @@  discard block
 block discarded – undo
2837 2837
  *     - `true` si la valeur existe dans le tableau, `false` sinon.
2838 2838
  **/
2839 2839
 function filtre_find($array, $val) {
2840
-	return (is_array($array) and in_array($val, $array));
2840
+    return (is_array($array) and in_array($val, $array));
2841 2841
 }
2842 2842
 
2843 2843
 
@@ -2854,13 +2854,13 @@  discard block
 block discarded – undo
2854 2854
  *     Contenu avec urls en absolus
2855 2855
  **/
2856 2856
 function urls_absolues_css($contenu, $source) {
2857
-	$path = suivre_lien(url_absolue($source), './');
2857
+    $path = suivre_lien(url_absolue($source), './');
2858 2858
 
2859
-	return preg_replace_callback(
2860
-		",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2861
-		fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2862
-		$contenu
2863
-	);
2859
+    return preg_replace_callback(
2860
+        ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims",
2861
+        fn($x) => "url('" . suivre_lien($path, $x[1]) . "')",
2862
+        $contenu
2863
+    );
2864 2864
 }
2865 2865
 
2866 2866
 
@@ -2889,119 +2889,119 @@  discard block
 block discarded – undo
2889 2889
  *     Chemin du fichier CSS inversé
2890 2890
  **/
2891 2891
 function direction_css($css, $voulue = '') {
2892
-	if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2893
-		return $css;
2894
-	}
2895
-	include_spip('inc/lang');
2896
-	// si on a precise le sens voulu en argument, le prendre en compte
2897
-	if ($voulue = strtolower($voulue)) {
2898
-		if ($voulue != 'rtl' and $voulue != 'ltr') {
2899
-			$voulue = lang_dir($voulue);
2900
-		}
2901
-	} else {
2902
-		$voulue = lang_dir();
2903
-	}
2904
-
2905
-	$r = count($r) > 1;
2906
-	$right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2907
-	$dir = $r ? 'rtl' : 'ltr';
2908
-	$ndir = $r ? 'ltr' : 'rtl';
2909
-
2910
-	if ($voulue == $dir) {
2911
-		return $css;
2912
-	}
2913
-
2914
-	if (
2915
-		// url absolue
2916
-		preg_match(',^https?:,i', $css)
2917
-		// ou qui contient un ?
2918
-		or (($p = strpos($css, '?')) !== false)
2919
-	) {
2920
-		$distant = true;
2921
-		$cssf = parse_url($css);
2922
-		$cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2923
-		$cssf = preg_replace(',[?:&=],', '_', $cssf);
2924
-	} else {
2925
-		$distant = false;
2926
-		$cssf = $css;
2927
-		// 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2928
-		//propose (rien a faire dans ce cas)
2929
-		$f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2930
-		if (@file_exists($f)) {
2931
-			return $f;
2932
-		}
2933
-	}
2934
-
2935
-	// 2.
2936
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2937
-	$f = $dir_var
2938
-		. preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2939
-		. '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2940
-
2941
-	// la css peut etre distante (url absolue !)
2942
-	if ($distant) {
2943
-		include_spip('inc/distant');
2944
-		$res = recuperer_url($css);
2945
-		if (!$res or !$contenu = $res['page']) {
2946
-			return $css;
2947
-		}
2948
-	} else {
2949
-		if (
2950
-			(@filemtime($f) > @filemtime($css))
2951
-			and (_VAR_MODE != 'recalcul')
2952
-		) {
2953
-			return $f;
2954
-		}
2955
-		if (!lire_fichier($css, $contenu)) {
2956
-			return $css;
2957
-		}
2958
-	}
2959
-
2960
-
2961
-	// Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2962
-	include_spip('lib/csstidy/class.csstidy');
2963
-	$parser = new csstidy();
2964
-	$parser->set_cfg('optimise_shorthands', 0);
2965
-	$parser->set_cfg('reverse_left_and_right', true);
2966
-	$parser->parse($contenu);
2967
-
2968
-	$contenu = $parser->print->plain();
2969
-
2970
-
2971
-	// reperer les @import auxquels il faut propager le direction_css
2972
-	preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2973
-	$src = [];
2974
-	$src_direction_css = [];
2975
-	$src_faux_abs = [];
2976
-	$d = dirname($css);
2977
-	foreach ($regs[1] as $k => $import_css) {
2978
-		$css_direction = direction_css("$d/$import_css", $voulue);
2979
-		// si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2980
-		if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2981
-			$css_direction = substr($css_direction, strlen($d) + 1);
2982
-		} // si la css_direction commence par $dir_var on la fait passer pour une absolue
2983
-		elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2984
-			$css_direction = substr($css_direction, strlen($dir_var));
2985
-			$src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2986
-			$css_direction = '/@@@@@@/' . $css_direction;
2987
-		}
2988
-		$src[] = $regs[0][$k];
2989
-		$src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2990
-	}
2991
-	$contenu = str_replace($src, $src_direction_css, $contenu);
2992
-
2993
-	$contenu = urls_absolues_css($contenu, $css);
2994
-
2995
-	// virer les fausses url absolues que l'on a mis dans les import
2996
-	if (count($src_faux_abs)) {
2997
-		$contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2998
-	}
2999
-
3000
-	if (!ecrire_fichier($f, $contenu)) {
3001
-		return $css;
3002
-	}
3003
-
3004
-	return $f;
2892
+    if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) {
2893
+        return $css;
2894
+    }
2895
+    include_spip('inc/lang');
2896
+    // si on a precise le sens voulu en argument, le prendre en compte
2897
+    if ($voulue = strtolower($voulue)) {
2898
+        if ($voulue != 'rtl' and $voulue != 'ltr') {
2899
+            $voulue = lang_dir($voulue);
2900
+        }
2901
+    } else {
2902
+        $voulue = lang_dir();
2903
+    }
2904
+
2905
+    $r = count($r) > 1;
2906
+    $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree
2907
+    $dir = $r ? 'rtl' : 'ltr';
2908
+    $ndir = $r ? 'ltr' : 'rtl';
2909
+
2910
+    if ($voulue == $dir) {
2911
+        return $css;
2912
+    }
2913
+
2914
+    if (
2915
+        // url absolue
2916
+        preg_match(',^https?:,i', $css)
2917
+        // ou qui contient un ?
2918
+        or (($p = strpos($css, '?')) !== false)
2919
+    ) {
2920
+        $distant = true;
2921
+        $cssf = parse_url($css);
2922
+        $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : '');
2923
+        $cssf = preg_replace(',[?:&=],', '_', $cssf);
2924
+    } else {
2925
+        $distant = false;
2926
+        $cssf = $css;
2927
+        // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi
2928
+        //propose (rien a faire dans ce cas)
2929
+        $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css);
2930
+        if (@file_exists($f)) {
2931
+            return $f;
2932
+        }
2933
+    }
2934
+
2935
+    // 2.
2936
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-css');
2937
+    $f = $dir_var
2938
+        . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf)
2939
+        . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css';
2940
+
2941
+    // la css peut etre distante (url absolue !)
2942
+    if ($distant) {
2943
+        include_spip('inc/distant');
2944
+        $res = recuperer_url($css);
2945
+        if (!$res or !$contenu = $res['page']) {
2946
+            return $css;
2947
+        }
2948
+    } else {
2949
+        if (
2950
+            (@filemtime($f) > @filemtime($css))
2951
+            and (_VAR_MODE != 'recalcul')
2952
+        ) {
2953
+            return $f;
2954
+        }
2955
+        if (!lire_fichier($css, $contenu)) {
2956
+            return $css;
2957
+        }
2958
+    }
2959
+
2960
+
2961
+    // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands
2962
+    include_spip('lib/csstidy/class.csstidy');
2963
+    $parser = new csstidy();
2964
+    $parser->set_cfg('optimise_shorthands', 0);
2965
+    $parser->set_cfg('reverse_left_and_right', true);
2966
+    $parser->parse($contenu);
2967
+
2968
+    $contenu = $parser->print->plain();
2969
+
2970
+
2971
+    // reperer les @import auxquels il faut propager le direction_css
2972
+    preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs);
2973
+    $src = [];
2974
+    $src_direction_css = [];
2975
+    $src_faux_abs = [];
2976
+    $d = dirname($css);
2977
+    foreach ($regs[1] as $k => $import_css) {
2978
+        $css_direction = direction_css("$d/$import_css", $voulue);
2979
+        // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue
2980
+        if (substr($css_direction, 0, strlen($d) + 1) == "$d/") {
2981
+            $css_direction = substr($css_direction, strlen($d) + 1);
2982
+        } // si la css_direction commence par $dir_var on la fait passer pour une absolue
2983
+        elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) {
2984
+            $css_direction = substr($css_direction, strlen($dir_var));
2985
+            $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction;
2986
+            $css_direction = '/@@@@@@/' . $css_direction;
2987
+        }
2988
+        $src[] = $regs[0][$k];
2989
+        $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]);
2990
+    }
2991
+    $contenu = str_replace($src, $src_direction_css, $contenu);
2992
+
2993
+    $contenu = urls_absolues_css($contenu, $css);
2994
+
2995
+    // virer les fausses url absolues que l'on a mis dans les import
2996
+    if (count($src_faux_abs)) {
2997
+        $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu);
2998
+    }
2999
+
3000
+    if (!ecrire_fichier($f, $contenu)) {
3001
+        return $css;
3002
+    }
3003
+
3004
+    return $f;
3005 3005
 }
3006 3006
 
3007 3007
 
@@ -3024,46 +3024,46 @@  discard block
 block discarded – undo
3024 3024
  *     - Chemin ou URL du fichier CSS source sinon.
3025 3025
  **/
3026 3026
 function url_absolue_css($css) {
3027
-	if (!preg_match(',\.css$,i', $css, $r)) {
3028
-		return $css;
3029
-	}
3027
+    if (!preg_match(',\.css$,i', $css, $r)) {
3028
+        return $css;
3029
+    }
3030 3030
 
3031
-	$url_absolue_css = url_absolue($css);
3031
+    $url_absolue_css = url_absolue($css);
3032 3032
 
3033
-	$f = basename($css, '.css');
3034
-	$f = sous_repertoire(_DIR_VAR, 'cache-css')
3035
-		. preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3036
-		. '.css';
3033
+    $f = basename($css, '.css');
3034
+    $f = sous_repertoire(_DIR_VAR, 'cache-css')
3035
+        . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f)
3036
+        . '.css';
3037 3037
 
3038
-	if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3039
-		return $f;
3040
-	}
3038
+    if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) {
3039
+        return $f;
3040
+    }
3041 3041
 
3042
-	if ($url_absolue_css == $css) {
3043
-		if (
3044
-			strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3045
-			or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3046
-		) {
3047
-			include_spip('inc/distant');
3048
-			$contenu = recuperer_url($css);
3049
-			$contenu = $contenu['page'] ?? '';
3050
-			if (!$contenu) {
3051
-				return $css;
3052
-			}
3053
-		}
3054
-	} elseif (!lire_fichier($css, $contenu)) {
3055
-		return $css;
3056
-	}
3042
+    if ($url_absolue_css == $css) {
3043
+        if (
3044
+            strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0
3045
+            or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu)
3046
+        ) {
3047
+            include_spip('inc/distant');
3048
+            $contenu = recuperer_url($css);
3049
+            $contenu = $contenu['page'] ?? '';
3050
+            if (!$contenu) {
3051
+                return $css;
3052
+            }
3053
+        }
3054
+    } elseif (!lire_fichier($css, $contenu)) {
3055
+        return $css;
3056
+    }
3057 3057
 
3058
-	// passer les url relatives a la css d'origine en url absolues
3059
-	$contenu = urls_absolues_css($contenu, $css);
3058
+    // passer les url relatives a la css d'origine en url absolues
3059
+    $contenu = urls_absolues_css($contenu, $css);
3060 3060
 
3061
-	// ecrire la css
3062
-	if (!ecrire_fichier($f, $contenu)) {
3063
-		return $css;
3064
-	}
3061
+    // ecrire la css
3062
+    if (!ecrire_fichier($f, $contenu)) {
3063
+        return $css;
3064
+    }
3065 3065
 
3066
-	return $f;
3066
+    return $f;
3067 3067
 }
3068 3068
 
3069 3069
 
@@ -3097,24 +3097,24 @@  discard block
 block discarded – undo
3097 3097
  *     Valeur trouvée ou valeur par défaut.
3098 3098
  **/
3099 3099
 function table_valeur($table, $cle, $defaut = '', $conserver_null = false) {
3100
-	foreach (explode('/', $cle) as $k) {
3101
-		$table = (is_string($table) ? @unserialize($table) : $table);
3100
+    foreach (explode('/', $cle) as $k) {
3101
+        $table = (is_string($table) ? @unserialize($table) : $table);
3102 3102
 
3103
-		if (is_object($table)) {
3104
-			$table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3105
-		} elseif (is_array($table)) {
3106
-			if ($conserver_null) {
3107
-				$table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3108
-			} else {
3109
-				$table = ($table[$k] ?? $defaut);
3110
-			}
3111
-		} else {
3112
-			$table = $defaut;
3113
-			break;
3114
-		}
3115
-	}
3103
+        if (is_object($table)) {
3104
+            $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut;
3105
+        } elseif (is_array($table)) {
3106
+            if ($conserver_null) {
3107
+                $table = array_key_exists($k, $table) ? $table[$k] : $defaut;
3108
+            } else {
3109
+                $table = ($table[$k] ?? $defaut);
3110
+            }
3111
+        } else {
3112
+            $table = $defaut;
3113
+            break;
3114
+        }
3115
+    }
3116 3116
 
3117
-	return $table;
3117
+    return $table;
3118 3118
 }
3119 3119
 
3120 3120
 /**
@@ -3147,22 +3147,22 @@  discard block
 block discarded – undo
3147 3147
  *     - string : expression trouvée.
3148 3148
  **/
3149 3149
 function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) {
3150
-	if (intval($modif) and $capte == 0) {
3151
-		$capte = $modif;
3152
-		$modif = 'UuimsS';
3153
-	}
3154
-	$expression = str_replace('\/', '/', $expression);
3155
-	$expression = str_replace('/', '\/', $expression);
3150
+    if (intval($modif) and $capte == 0) {
3151
+        $capte = $modif;
3152
+        $modif = 'UuimsS';
3153
+    }
3154
+    $expression = str_replace('\/', '/', $expression);
3155
+    $expression = str_replace('/', '\/', $expression);
3156 3156
 
3157
-	if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3158
-		if (isset($r[$capte])) {
3159
-			return $r[$capte];
3160
-		} else {
3161
-			return true;
3162
-		}
3163
-	}
3157
+    if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) {
3158
+        if (isset($r[$capte])) {
3159
+            return $r[$capte];
3160
+        } else {
3161
+            return true;
3162
+        }
3163
+    }
3164 3164
 
3165
-	return false;
3165
+    return false;
3166 3166
 }
3167 3167
 
3168 3168
 
@@ -3189,10 +3189,10 @@  discard block
 block discarded – undo
3189 3189
  *     texte
3190 3190
  **/
3191 3191
 function replace($texte, $expression, $replace = '', $modif = 'UimsS') {
3192
-	$expression = str_replace('\/', '/', $expression);
3193
-	$expression = str_replace('/', '\/', $expression);
3192
+    $expression = str_replace('\/', '/', $expression);
3193
+    $expression = str_replace('/', '\/', $expression);
3194 3194
 
3195
-	return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3195
+    return preg_replace('/' . $expression . '/' . $modif, $replace, $texte);
3196 3196
 }
3197 3197
 
3198 3198
 
@@ -3210,25 +3210,25 @@  discard block
 block discarded – undo
3210 3210
  **/
3211 3211
 function traiter_doublons_documents(&$doublons, $letexte) {
3212 3212
 
3213
-	// Verifier dans le texte & les notes (pas beau, helas)
3214
-	$t = $letexte . $GLOBALS['les_notes'];
3213
+    // Verifier dans le texte & les notes (pas beau, helas)
3214
+    $t = $letexte . $GLOBALS['les_notes'];
3215 3215
 
3216
-	if (
3217
-		strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3218
-		and preg_match_all(
3219
-			',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3220
-			$t,
3221
-			$matches,
3222
-			PREG_PATTERN_ORDER
3223
-		)
3224
-	) {
3225
-		if (!isset($doublons['documents'])) {
3226
-			$doublons['documents'] = '';
3227
-		}
3228
-		$doublons['documents'] .= ',' . join(',', $matches[1]);
3229
-	}
3216
+    if (
3217
+        strstr($t, 'spip_document_') // evite le preg_match_all si inutile
3218
+        and preg_match_all(
3219
+            ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS',
3220
+            $t,
3221
+            $matches,
3222
+            PREG_PATTERN_ORDER
3223
+        )
3224
+    ) {
3225
+        if (!isset($doublons['documents'])) {
3226
+            $doublons['documents'] = '';
3227
+        }
3228
+        $doublons['documents'] .= ',' . join(',', $matches[1]);
3229
+    }
3230 3230
 
3231
-	return $letexte;
3231
+    return $letexte;
3232 3232
 }
3233 3233
 
3234 3234
 /**
@@ -3242,7 +3242,7 @@  discard block
 block discarded – undo
3242 3242
  * @return string Chaîne vide
3243 3243
  **/
3244 3244
 function vide($texte) {
3245
-	return '';
3245
+    return '';
3246 3246
 }
3247 3247
 
3248 3248
 //
@@ -3271,23 +3271,23 @@  discard block
 block discarded – undo
3271 3271
  *      Code HTML résultant
3272 3272
  **/
3273 3273
 function env_to_params($env, $ignore_params = []) {
3274
-	$ignore_params = array_merge(
3275
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3276
-		$ignore_params
3277
-	);
3278
-	if (!is_array($env)) {
3279
-		$env = unserialize($env);
3280
-	}
3281
-	$texte = '';
3282
-	if ($env) {
3283
-		foreach ($env as $i => $j) {
3284
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3285
-				$texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3286
-			}
3287
-		}
3288
-	}
3289
-
3290
-	return $texte;
3274
+    $ignore_params = array_merge(
3275
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3276
+        $ignore_params
3277
+    );
3278
+    if (!is_array($env)) {
3279
+        $env = unserialize($env);
3280
+    }
3281
+    $texte = '';
3282
+    if ($env) {
3283
+        foreach ($env as $i => $j) {
3284
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3285
+                $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />";
3286
+            }
3287
+        }
3288
+    }
3289
+
3290
+    return $texte;
3291 3291
 }
3292 3292
 
3293 3293
 /**
@@ -3310,23 +3310,23 @@  discard block
 block discarded – undo
3310 3310
  *      Code HTML résultant
3311 3311
  **/
3312 3312
 function env_to_attributs($env, $ignore_params = []) {
3313
-	$ignore_params = array_merge(
3314
-		['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3315
-		$ignore_params
3316
-	);
3317
-	if (!is_array($env)) {
3318
-		$env = unserialize($env);
3319
-	}
3320
-	$texte = '';
3321
-	if ($env) {
3322
-		foreach ($env as $i => $j) {
3323
-			if (is_string($j) and !in_array($i, $ignore_params)) {
3324
-				$texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3325
-			}
3326
-		}
3327
-	}
3313
+    $ignore_params = array_merge(
3314
+        ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'],
3315
+        $ignore_params
3316
+    );
3317
+    if (!is_array($env)) {
3318
+        $env = unserialize($env);
3319
+    }
3320
+    $texte = '';
3321
+    if ($env) {
3322
+        foreach ($env as $i => $j) {
3323
+            if (is_string($j) and !in_array($i, $ignore_params)) {
3324
+                $texte .= attribut_html($i) . "='" . attribut_html($j) . "' ";
3325
+            }
3326
+        }
3327
+    }
3328 3328
 
3329
-	return $texte;
3329
+    return $texte;
3330 3330
 }
3331 3331
 
3332 3332
 
@@ -3344,7 +3344,7 @@  discard block
 block discarded – undo
3344 3344
  * @return string Chaînes concaténés
3345 3345
  **/
3346 3346
 function concat(...$args): string {
3347
-	return join('', $args);
3347
+    return join('', $args);
3348 3348
 }
3349 3349
 
3350 3350
 
@@ -3364,23 +3364,23 @@  discard block
 block discarded – undo
3364 3364
  *     Contenu du ou des fichiers, concaténé
3365 3365
  **/
3366 3366
 function charge_scripts($files, $script = true) {
3367
-	$flux = '';
3368
-	foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3369
-		if (!is_string($file)) {
3370
-			continue;
3371
-		}
3372
-		if ($script) {
3373
-			$file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3374
-		}
3375
-		if ($file) {
3376
-			$path = find_in_path($file);
3377
-			if ($path) {
3378
-				$flux .= spip_file_get_contents($path);
3379
-			}
3380
-		}
3381
-	}
3382
-
3383
-	return $flux;
3367
+    $flux = '';
3368
+    foreach (is_array($files) ? $files : explode('|', $files) as $file) {
3369
+        if (!is_string($file)) {
3370
+            continue;
3371
+        }
3372
+        if ($script) {
3373
+            $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : '';
3374
+        }
3375
+        if ($file) {
3376
+            $path = find_in_path($file);
3377
+            if ($path) {
3378
+                $flux .= spip_file_get_contents($path);
3379
+            }
3380
+        }
3381
+    }
3382
+
3383
+    return $flux;
3384 3384
 }
3385 3385
 
3386 3386
 /**
@@ -3391,22 +3391,22 @@  discard block
 block discarded – undo
3391 3391
  * @return string
3392 3392
  */
3393 3393
 function http_img_variante_svg_si_possible($img_file) {
3394
-	// on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3395
-	// si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3396
-	if (
3397
-		preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3398
-		and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3399
-		and file_exists($variante_svg_generique)
3400
-	) {
3401
-		if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3402
-			$img_file = $variante_svg_size;
3403
-		}
3404
-		else {
3405
-			$img_file = $variante_svg_generique;
3406
-		}
3407
-	}
3394
+    // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png
3395
+    // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png
3396
+    if (
3397
+        preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m)
3398
+        and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg'
3399
+        and file_exists($variante_svg_generique)
3400
+    ) {
3401
+        if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) {
3402
+            $img_file = $variante_svg_size;
3403
+        }
3404
+        else {
3405
+            $img_file = $variante_svg_generique;
3406
+        }
3407
+    }
3408 3408
 
3409
-	return $img_file;
3409
+    return $img_file;
3410 3410
 }
3411 3411
 
3412 3412
 /**
@@ -3427,54 +3427,54 @@  discard block
 block discarded – undo
3427 3427
  */
3428 3428
 function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) {
3429 3429
 
3430
-	$img_file = $img;
3431
-	if ($p = strpos($img_file, '?')) {
3432
-		$img_file = substr($img_file, 0, $p);
3433
-	}
3434
-	if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3435
-		$img_file = chemin_image($img);
3436
-	}
3437
-	else {
3438
-		if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3439
-			$img_file = http_img_variante_svg_si_possible($img_file);
3440
-		}
3441
-	}
3442
-	if (stripos($atts, 'width') === false) {
3443
-		// utiliser directement l'info de taille presente dans le nom
3444
-		if (
3445
-			(!isset($options['utiliser_suffixe_size'])
3446
-				or $options['utiliser_suffixe_size'] == true
3447
-				or str_contains($img_file, '-xx.svg'))
3448
-			and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3449
-					 or preg_match(',\?([0-9]+)px$,', $img, $regs))
3450
-		) {
3451
-			$largeur = $hauteur = intval($regs[1]);
3452
-		} else {
3453
-			$taille = taille_image($img_file);
3454
-			[$hauteur, $largeur] = $taille;
3455
-			if (!$hauteur or !$largeur) {
3456
-				return '';
3457
-			}
3458
-		}
3459
-		$atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3460
-	}
3461
-
3462
-	if (file_exists($img_file)) {
3463
-		$img_file = timestamp($img_file);
3464
-	}
3465
-	if ($alt === false) {
3466
-		$alt = '';
3467
-	}
3468
-	elseif ($alt or $alt === '') {
3469
-		$alt = " alt='" . attribut_html($alt) . "'";
3470
-	}
3471
-	else {
3472
-		$alt = " alt='" . attribut_html($title) . "'";
3473
-	}
3474
-	return "<img src='" . attribut_html($img_file) . "'$alt"
3475
-	. ($title ? ' title="' . attribut_html($title) . '"' : '')
3476
-	. ' ' . ltrim($atts)
3477
-	. ' />';
3430
+    $img_file = $img;
3431
+    if ($p = strpos($img_file, '?')) {
3432
+        $img_file = substr($img_file, 0, $p);
3433
+    }
3434
+    if (!isset($options['chemin_image']) or $options['chemin_image'] == true) {
3435
+        $img_file = chemin_image($img);
3436
+    }
3437
+    else {
3438
+        if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) {
3439
+            $img_file = http_img_variante_svg_si_possible($img_file);
3440
+        }
3441
+    }
3442
+    if (stripos($atts, 'width') === false) {
3443
+        // utiliser directement l'info de taille presente dans le nom
3444
+        if (
3445
+            (!isset($options['utiliser_suffixe_size'])
3446
+                or $options['utiliser_suffixe_size'] == true
3447
+                or str_contains($img_file, '-xx.svg'))
3448
+            and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs)
3449
+                     or preg_match(',\?([0-9]+)px$,', $img, $regs))
3450
+        ) {
3451
+            $largeur = $hauteur = intval($regs[1]);
3452
+        } else {
3453
+            $taille = taille_image($img_file);
3454
+            [$hauteur, $largeur] = $taille;
3455
+            if (!$hauteur or !$largeur) {
3456
+                return '';
3457
+            }
3458
+        }
3459
+        $atts .= " width='" . $largeur . "' height='" . $hauteur . "'";
3460
+    }
3461
+
3462
+    if (file_exists($img_file)) {
3463
+        $img_file = timestamp($img_file);
3464
+    }
3465
+    if ($alt === false) {
3466
+        $alt = '';
3467
+    }
3468
+    elseif ($alt or $alt === '') {
3469
+        $alt = " alt='" . attribut_html($alt) . "'";
3470
+    }
3471
+    else {
3472
+        $alt = " alt='" . attribut_html($title) . "'";
3473
+    }
3474
+    return "<img src='" . attribut_html($img_file) . "'$alt"
3475
+    . ($title ? ' title="' . attribut_html($title) . '"' : '')
3476
+    . ' ' . ltrim($atts)
3477
+    . ' />';
3478 3478
 }
3479 3479
 
3480 3480
 /**
@@ -3486,70 +3486,70 @@  discard block
 block discarded – undo
3486 3486
  * @return string
3487 3487
  */
3488 3488
 function http_style_background($img, $att = '', $size = null) {
3489
-	if ($size and is_numeric($size)) {
3490
-		$size = trim($size) . 'px';
3491
-	}
3492
-	return " style='background" .
3493
-		($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3494
-		. ($size ? "background-size:{$size};" : '')
3495
-		. "'";
3489
+    if ($size and is_numeric($size)) {
3490
+        $size = trim($size) . 'px';
3491
+    }
3492
+    return " style='background" .
3493
+        ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';'
3494
+        . ($size ? "background-size:{$size};" : '')
3495
+        . "'";
3496 3496
 }
3497 3497
 
3498 3498
 
3499 3499
 function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) {
3500
-	$args = [$alt_or_size, $class_or_size, $size];
3501
-	while (is_null(end($args)) and count($args)) {
3502
-		array_pop($args);
3503
-	}
3504
-	if (!count($args)) {
3505
-		return [null, null, null];
3506
-	}
3507
-	if (count($args) < 3) {
3508
-		$maybe_size = array_pop($args);
3509
-		// @2x
3510
-		// @1.5x
3511
-		// 512
3512
-		// 512x*
3513
-		// 512x300
3514
-		if (
3515
-			!strlen($maybe_size)
3516
-			or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3517
-		) {
3518
-			$args[] = $maybe_size;
3519
-			$maybe_size = null;
3520
-		}
3521
-		while (count($args) < 2) {
3522
-			$args[] = null; // default alt or class
3523
-		}
3524
-		$args[] = $maybe_size;
3525
-	}
3526
-	return $args;
3500
+    $args = [$alt_or_size, $class_or_size, $size];
3501
+    while (is_null(end($args)) and count($args)) {
3502
+        array_pop($args);
3503
+    }
3504
+    if (!count($args)) {
3505
+        return [null, null, null];
3506
+    }
3507
+    if (count($args) < 3) {
3508
+        $maybe_size = array_pop($args);
3509
+        // @2x
3510
+        // @1.5x
3511
+        // 512
3512
+        // 512x*
3513
+        // 512x300
3514
+        if (
3515
+            !strlen($maybe_size)
3516
+            or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size))
3517
+        ) {
3518
+            $args[] = $maybe_size;
3519
+            $maybe_size = null;
3520
+        }
3521
+        while (count($args) < 2) {
3522
+            $args[] = null; // default alt or class
3523
+        }
3524
+        $args[] = $maybe_size;
3525
+    }
3526
+    return $args;
3527 3527
 }
3528 3528
 
3529 3529
 function helper_filtre_balise_img_svg_size($img, $size) {
3530
-	// si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3531
-	if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3532
-		$coef = floatval(substr($size, 1, -1));
3533
-		[$h, $w] = taille_image($img);
3534
-		$height = intval(round($h / $coef));
3535
-		$width = intval(round($w / $coef));
3536
-	}
3537
-	// sinon c'est une valeur seule si image caree ou largeurxhauteur
3538
-	else {
3539
-		$size = explode('x', $size, 2);
3540
-		$size = array_map('trim', $size);
3541
-		$height = $width = intval(array_shift($size));
3542
-
3543
-		if (count($size) and reset($size)) {
3544
-			$height = array_shift($size);
3545
-			if ($height === '*') {
3546
-				[$h, $w] = taille_image($img);
3547
-				$height = intval(round($h * $width / $w));
3548
-			}
3549
-		}
3550
-	}
3551
-
3552
-	return [$width, $height];
3530
+    // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite
3531
+    if (strpos($size, '@') === 0 and substr($size, -1) === 'x') {
3532
+        $coef = floatval(substr($size, 1, -1));
3533
+        [$h, $w] = taille_image($img);
3534
+        $height = intval(round($h / $coef));
3535
+        $width = intval(round($w / $coef));
3536
+    }
3537
+    // sinon c'est une valeur seule si image caree ou largeurxhauteur
3538
+    else {
3539
+        $size = explode('x', $size, 2);
3540
+        $size = array_map('trim', $size);
3541
+        $height = $width = intval(array_shift($size));
3542
+
3543
+        if (count($size) and reset($size)) {
3544
+            $height = array_shift($size);
3545
+            if ($height === '*') {
3546
+                [$h, $w] = taille_image($img);
3547
+                $height = intval(round($h * $width / $w));
3548
+            }
3549
+        }
3550
+    }
3551
+
3552
+    return [$width, $height];
3553 3553
 }
3554 3554
 
3555 3555
 /**
@@ -3585,43 +3585,43 @@  discard block
 block discarded – undo
3585 3585
  */
3586 3586
 function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) {
3587 3587
 
3588
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3589
-
3590
-	$img = trim((string) $img);
3591
-	if (strpos($img, '<img') === 0) {
3592
-		if (!is_null($alt)) {
3593
-			$img = inserer_attribut($img, 'alt', $alt);
3594
-		}
3595
-		if (!is_null($class)) {
3596
-			if (strlen($class)) {
3597
-				$img = inserer_attribut($img, 'class', $class);
3598
-			}
3599
-			else {
3600
-				$img = vider_attribut($img, 'class');
3601
-			}
3602
-		}
3603
-	}
3604
-	else {
3605
-		$img = http_img_pack(
3606
-			$img,
3607
-			$alt,
3608
-			$class ? " class='" . attribut_html($class) . "'" : '',
3609
-			'',
3610
-			['chemin_image' => false, 'utiliser_suffixe_size' => false]
3611
-		);
3612
-		if (is_null($alt)) {
3613
-			$img = vider_attribut($img, 'alt');
3614
-		}
3615
-	}
3616
-
3617
-	if ($img and !is_null($size) and strlen($size = trim($size))) {
3618
-		[$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3619
-
3620
-		$img = inserer_attribut($img, 'width', $width);
3621
-		$img = inserer_attribut($img, 'height', $height);
3622
-	}
3623
-
3624
-	return $img;
3588
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3589
+
3590
+    $img = trim((string) $img);
3591
+    if (strpos($img, '<img') === 0) {
3592
+        if (!is_null($alt)) {
3593
+            $img = inserer_attribut($img, 'alt', $alt);
3594
+        }
3595
+        if (!is_null($class)) {
3596
+            if (strlen($class)) {
3597
+                $img = inserer_attribut($img, 'class', $class);
3598
+            }
3599
+            else {
3600
+                $img = vider_attribut($img, 'class');
3601
+            }
3602
+        }
3603
+    }
3604
+    else {
3605
+        $img = http_img_pack(
3606
+            $img,
3607
+            $alt,
3608
+            $class ? " class='" . attribut_html($class) . "'" : '',
3609
+            '',
3610
+            ['chemin_image' => false, 'utiliser_suffixe_size' => false]
3611
+        );
3612
+        if (is_null($alt)) {
3613
+            $img = vider_attribut($img, 'alt');
3614
+        }
3615
+    }
3616
+
3617
+    if ($img and !is_null($size) and strlen($size = trim($size))) {
3618
+        [$width, $height] = helper_filtre_balise_img_svg_size($img, $size);
3619
+
3620
+        $img = inserer_attribut($img, 'width', $width);
3621
+        $img = inserer_attribut($img, 'height', $height);
3622
+    }
3623
+
3624
+    return $img;
3625 3625
 }
3626 3626
 
3627 3627
 
@@ -3655,80 +3655,80 @@  discard block
 block discarded – undo
3655 3655
  */
3656 3656
 function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) {
3657 3657
 
3658
-	$svg = null;
3659
-	$img = trim($img);
3660
-	$img_file = $img;
3661
-	if (strpos($img, '<svg') === false) {
3662
-		if ($p = strpos($img_file, '?')) {
3663
-			$img_file = substr($img_file, 0, $p);
3664
-		}
3665
-
3666
-		// ne jamais operer directement sur une image distante pour des raisons de perfo
3667
-		// la copie locale a toutes les chances d'etre la ou de resservir
3668
-		if (tester_url_absolue($img_file)) {
3669
-			include_spip('inc/distant');
3670
-			$fichier = copie_locale($img_file);
3671
-			$img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3672
-		}
3673
-
3674
-		if (
3675
-			!$img_file
3676
-			or !file_exists($img_file)
3677
-			or !$svg = file_get_contents($img_file)
3678
-		) {
3679
-			return '';
3680
-		}
3681
-	}
3682
-
3683
-	if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3684
-		return '';
3685
-	}
3686
-
3687
-	[$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3688
-
3689
-	$balise_svg = $match[0];
3690
-	$balise_svg_source = $balise_svg;
3691
-
3692
-	// entete XML à supprimer
3693
-	$svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3694
-
3695
-	// IE est toujours mon ami
3696
-	$balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3697
-
3698
-	// regler la classe
3699
-	if (!is_null($class)) {
3700
-		if (strlen($class)) {
3701
-			$balise_svg = inserer_attribut($balise_svg, 'class', $class);
3702
-		}
3703
-		else {
3704
-			$balise_svg = vider_attribut($balise_svg, 'class');
3705
-		}
3706
-	}
3707
-
3708
-	// regler le alt
3709
-	if ($alt) {
3710
-		$balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3711
-		$id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3712
-		$balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3713
-		$title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3714
-		$balise_svg .= $title;
3715
-	}
3716
-	else {
3717
-		$balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3718
-	}
3719
-
3720
-	$svg = str_replace($balise_svg_source, $balise_svg, $svg);
3721
-
3722
-	if (!is_null($size) and strlen($size = trim($size))) {
3723
-		[$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3724
-
3725
-		if (!function_exists('svg_redimensionner')) {
3726
-			include_spip('inc/svg');
3727
-		}
3728
-		$svg = svg_redimensionner($svg, $width, $height);
3729
-	}
3730
-
3731
-	return $svg;
3658
+    $svg = null;
3659
+    $img = trim($img);
3660
+    $img_file = $img;
3661
+    if (strpos($img, '<svg') === false) {
3662
+        if ($p = strpos($img_file, '?')) {
3663
+            $img_file = substr($img_file, 0, $p);
3664
+        }
3665
+
3666
+        // ne jamais operer directement sur une image distante pour des raisons de perfo
3667
+        // la copie locale a toutes les chances d'etre la ou de resservir
3668
+        if (tester_url_absolue($img_file)) {
3669
+            include_spip('inc/distant');
3670
+            $fichier = copie_locale($img_file);
3671
+            $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file);
3672
+        }
3673
+
3674
+        if (
3675
+            !$img_file
3676
+            or !file_exists($img_file)
3677
+            or !$svg = file_get_contents($img_file)
3678
+        ) {
3679
+            return '';
3680
+        }
3681
+    }
3682
+
3683
+    if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) {
3684
+        return '';
3685
+    }
3686
+
3687
+    [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size);
3688
+
3689
+    $balise_svg = $match[0];
3690
+    $balise_svg_source = $balise_svg;
3691
+
3692
+    // entete XML à supprimer
3693
+    $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg);
3694
+
3695
+    // IE est toujours mon ami
3696
+    $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false');
3697
+
3698
+    // regler la classe
3699
+    if (!is_null($class)) {
3700
+        if (strlen($class)) {
3701
+            $balise_svg = inserer_attribut($balise_svg, 'class', $class);
3702
+        }
3703
+        else {
3704
+            $balise_svg = vider_attribut($balise_svg, 'class');
3705
+        }
3706
+    }
3707
+
3708
+    // regler le alt
3709
+    if ($alt) {
3710
+        $balise_svg = inserer_attribut($balise_svg, 'role', 'img');
3711
+        $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4);
3712
+        $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id);
3713
+        $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n";
3714
+        $balise_svg .= $title;
3715
+    }
3716
+    else {
3717
+        $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true');
3718
+    }
3719
+
3720
+    $svg = str_replace($balise_svg_source, $balise_svg, $svg);
3721
+
3722
+    if (!is_null($size) and strlen($size = trim($size))) {
3723
+        [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size);
3724
+
3725
+        if (!function_exists('svg_redimensionner')) {
3726
+            include_spip('inc/svg');
3727
+        }
3728
+        $svg = svg_redimensionner($svg, $width, $height);
3729
+    }
3730
+
3731
+    return $svg;
3732 3732
 }
3733 3733
 
3734 3734
 
@@ -3754,18 +3754,18 @@  discard block
 block discarded – undo
3754 3754
  *     Code HTML résultant
3755 3755
  **/
3756 3756
 function filtre_foreach_dist($tableau, $modele = 'foreach') {
3757
-	$texte = '';
3758
-	if (is_array($tableau)) {
3759
-		foreach ($tableau as $k => $v) {
3760
-			$res = recuperer_fond(
3761
-				'modeles/' . $modele,
3762
-				array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3763
-			);
3764
-			$texte .= $res;
3765
-		}
3766
-	}
3757
+    $texte = '';
3758
+    if (is_array($tableau)) {
3759
+        foreach ($tableau as $k => $v) {
3760
+            $res = recuperer_fond(
3761
+                'modeles/' . $modele,
3762
+                array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v]))
3763
+            );
3764
+            $texte .= $res;
3765
+        }
3766
+    }
3767 3767
 
3768
-	return $texte;
3768
+    return $texte;
3769 3769
 }
3770 3770
 
3771 3771
 
@@ -3790,37 +3790,37 @@  discard block
 block discarded – undo
3790 3790
  *         - tout : retourne toutes les informations du plugin actif
3791 3791
  **/
3792 3792
 function filtre_info_plugin_dist($plugin, $type_info, $reload = false) {
3793
-	include_spip('inc/plugin');
3794
-	$plugin = strtoupper($plugin);
3795
-	$plugins_actifs = liste_plugin_actifs();
3796
-
3797
-	if (!$plugin) {
3798
-		return serialize(array_keys($plugins_actifs));
3799
-	} elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3800
-		return '';
3801
-	} elseif (($type_info == 'est_actif') and !$reload) {
3802
-		return $plugins_actifs[$plugin] ? 1 : 0;
3803
-	} elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3804
-		return $plugins_actifs[$plugin][$type_info];
3805
-	} else {
3806
-		$get_infos = charger_fonction('get_infos', 'plugins');
3807
-		// On prend en compte les extensions
3808
-		if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3809
-			$dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3810
-		} else {
3811
-			$dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3812
-		}
3813
-		if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3814
-			return '';
3815
-		}
3816
-		if ($type_info == 'tout') {
3817
-			return $infos;
3818
-		} elseif ($type_info == 'est_actif') {
3819
-			return $infos ? 1 : 0;
3820
-		} else {
3821
-			return strval($infos[$type_info]);
3822
-		}
3823
-	}
3793
+    include_spip('inc/plugin');
3794
+    $plugin = strtoupper($plugin);
3795
+    $plugins_actifs = liste_plugin_actifs();
3796
+
3797
+    if (!$plugin) {
3798
+        return serialize(array_keys($plugins_actifs));
3799
+    } elseif (empty($plugins_actifs[$plugin]) and !$reload) {
3800
+        return '';
3801
+    } elseif (($type_info == 'est_actif') and !$reload) {
3802
+        return $plugins_actifs[$plugin] ? 1 : 0;
3803
+    } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) {
3804
+        return $plugins_actifs[$plugin][$type_info];
3805
+    } else {
3806
+        $get_infos = charger_fonction('get_infos', 'plugins');
3807
+        // On prend en compte les extensions
3808
+        if (!is_dir($plugins_actifs[$plugin]['dir_type'])) {
3809
+            $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']);
3810
+        } else {
3811
+            $dir_plugins = $plugins_actifs[$plugin]['dir_type'];
3812
+        }
3813
+        if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) {
3814
+            return '';
3815
+        }
3816
+        if ($type_info == 'tout') {
3817
+            return $infos;
3818
+        } elseif ($type_info == 'est_actif') {
3819
+            return $infos ? 1 : 0;
3820
+        } else {
3821
+            return strval($infos[$type_info]);
3822
+        }
3823
+    }
3824 3824
 }
3825 3825
 
3826 3826
 
@@ -3847,9 +3847,9 @@  discard block
 block discarded – undo
3847 3847
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3848 3848
  */
3849 3849
 function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) {
3850
-	$puce_statut = charger_fonction('puce_statut', 'inc');
3850
+    $puce_statut = charger_fonction('puce_statut', 'inc');
3851 3851
 
3852
-	return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3852
+    return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax);
3853 3853
 }
3854 3854
 
3855 3855
 
@@ -3879,19 +3879,19 @@  discard block
 block discarded – undo
3879 3879
  *     Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent)
3880 3880
  */
3881 3881
 function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) {
3882
-	static $puce_statut = null;
3883
-	if (!$puce_statut) {
3884
-		$puce_statut = charger_fonction('puce_statut', 'inc');
3885
-	}
3882
+    static $puce_statut = null;
3883
+    if (!$puce_statut) {
3884
+        $puce_statut = charger_fonction('puce_statut', 'inc');
3885
+    }
3886 3886
 
3887
-	return $puce_statut(
3888
-		$id_objet,
3889
-		$statut,
3890
-		$id_parent,
3891
-		$objet,
3892
-		false,
3893
-		objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3894
-	);
3887
+    return $puce_statut(
3888
+        $id_objet,
3889
+        $statut,
3890
+        $id_parent,
3891
+        $objet,
3892
+        false,
3893
+        objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false
3894
+    );
3895 3895
 }
3896 3896
 
3897 3897
 
@@ -3918,98 +3918,98 @@  discard block
 block discarded – undo
3918 3918
  *   hash du contexte
3919 3919
  */
3920 3920
 function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') {
3921
-	$env = null;
3922
-	if (
3923
-		is_string($c)
3924
-		and @unserialize($c) !== false
3925
-	) {
3926
-		$c = unserialize($c);
3927
-	}
3928
-
3929
-	// supprimer les parametres debut_x
3930
-	// pour que la pagination ajax ne soit pas plantee
3931
-	// si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3932
-	// le debut_x=0 n'existe pas, et on resterait sur 1
3933
-	if (is_array($c)) {
3934
-		foreach ($c as $k => $v) {
3935
-			if (strpos($k, 'debut_') === 0) {
3936
-				unset($c[$k]);
3937
-			}
3938
-		}
3939
-	}
3940
-
3941
-	if (!function_exists('calculer_cle_action')) {
3942
-		include_spip('inc/securiser_action');
3943
-	}
3944
-
3945
-	$c = serialize($c);
3946
-	$cle = calculer_cle_action($form . $c);
3947
-	$c = "$cle:$c";
3948
-
3949
-	// on ne stocke pas les contextes dans des fichiers en cache
3950
-	// par defaut, sauf si cette configuration a été forcée
3951
-	// OU que la longueur de l’argument géneré est plus long
3952
-	// que ce qui est toléré.
3953
-	$cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3954
-	if (!$cache_contextes_ajax) {
3955
-		$env = $c;
3956
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3957
-			$env = gzdeflate($env);
3958
-		}
3959
-		$env = _xor($env);
3960
-		$env = base64_encode($env);
3961
-		$len = strlen($env);
3962
-		// Si l’url est trop longue pour le navigateur
3963
-		$max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3964
-		if ($len > $max_len) {
3965
-			$cache_contextes_ajax = true;
3966
-			spip_log(
3967
-				'Contextes AJAX forces en fichiers !'
3968
-				. ' Cela arrive lorsque la valeur du contexte'
3969
-				. " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3970
-				_LOG_AVERTISSEMENT
3971
-			);
3972
-		}
3973
-		// Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3974
-		elseif (
3975
-			$max_len = @ini_get('suhosin.get.max_value_length')
3976
-			and $max_len < $len
3977
-		) {
3978
-			$cache_contextes_ajax = true;
3979
-			spip_log('Contextes AJAX forces en fichiers !'
3980
-				. ' Cela arrive lorsque la valeur du contexte'
3981
-				. ' depasse la longueur maximale autorisee par Suhosin'
3982
-				. " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3983
-				. ' Vous devriez modifier les parametres de Suhosin'
3984
-				. ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3985
-		}
3986
-	}
3987
-
3988
-	if ($cache_contextes_ajax) {
3989
-		$dir = sous_repertoire(_DIR_CACHE, 'contextes');
3990
-		// stocker les contextes sur disque et ne passer qu'un hash dans l'url
3991
-		$md5 = md5($c);
3992
-		ecrire_fichier("$dir/c$md5", $c);
3993
-		$env = $md5;
3994
-	}
3995
-
3996
-	if ($emboite === null) {
3997
-		return $env;
3998
-	}
3999
-	if (!trim($emboite)) {
4000
-		return '';
4001
-	}
4002
-	// toujours encoder l'url source dans le bloc ajax
4003
-	$r = self();
4004
-	$r = ' data-origin="' . $r . '"';
4005
-	$class = 'ajaxbloc';
4006
-	if ($ajaxid and is_string($ajaxid)) {
4007
-		// ajaxid est normalement conforme a un nom de classe css
4008
-		// on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4009
-		$class .= ' ajax-id-' . entites_html($ajaxid);
4010
-	}
4011
-
4012
-	return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
3921
+    $env = null;
3922
+    if (
3923
+        is_string($c)
3924
+        and @unserialize($c) !== false
3925
+    ) {
3926
+        $c = unserialize($c);
3927
+    }
3928
+
3929
+    // supprimer les parametres debut_x
3930
+    // pour que la pagination ajax ne soit pas plantee
3931
+    // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0,
3932
+    // le debut_x=0 n'existe pas, et on resterait sur 1
3933
+    if (is_array($c)) {
3934
+        foreach ($c as $k => $v) {
3935
+            if (strpos($k, 'debut_') === 0) {
3936
+                unset($c[$k]);
3937
+            }
3938
+        }
3939
+    }
3940
+
3941
+    if (!function_exists('calculer_cle_action')) {
3942
+        include_spip('inc/securiser_action');
3943
+    }
3944
+
3945
+    $c = serialize($c);
3946
+    $cle = calculer_cle_action($form . $c);
3947
+    $c = "$cle:$c";
3948
+
3949
+    // on ne stocke pas les contextes dans des fichiers en cache
3950
+    // par defaut, sauf si cette configuration a été forcée
3951
+    // OU que la longueur de l’argument géneré est plus long
3952
+    // que ce qui est toléré.
3953
+    $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX);
3954
+    if (!$cache_contextes_ajax) {
3955
+        $env = $c;
3956
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
3957
+            $env = gzdeflate($env);
3958
+        }
3959
+        $env = _xor($env);
3960
+        $env = base64_encode($env);
3961
+        $len = strlen($env);
3962
+        // Si l’url est trop longue pour le navigateur
3963
+        $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR;
3964
+        if ($len > $max_len) {
3965
+            $cache_contextes_ajax = true;
3966
+            spip_log(
3967
+                'Contextes AJAX forces en fichiers !'
3968
+                . ' Cela arrive lorsque la valeur du contexte'
3969
+                . " depasse la longueur maximale autorisee ($max_len). Ici : $len.",
3970
+                _LOG_AVERTISSEMENT
3971
+            );
3972
+        }
3973
+        // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET...
3974
+        elseif (
3975
+            $max_len = @ini_get('suhosin.get.max_value_length')
3976
+            and $max_len < $len
3977
+        ) {
3978
+            $cache_contextes_ajax = true;
3979
+            spip_log('Contextes AJAX forces en fichiers !'
3980
+                . ' Cela arrive lorsque la valeur du contexte'
3981
+                . ' depasse la longueur maximale autorisee par Suhosin'
3982
+                . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len."
3983
+                . ' Vous devriez modifier les parametres de Suhosin'
3984
+                . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT);
3985
+        }
3986
+    }
3987
+
3988
+    if ($cache_contextes_ajax) {
3989
+        $dir = sous_repertoire(_DIR_CACHE, 'contextes');
3990
+        // stocker les contextes sur disque et ne passer qu'un hash dans l'url
3991
+        $md5 = md5($c);
3992
+        ecrire_fichier("$dir/c$md5", $c);
3993
+        $env = $md5;
3994
+    }
3995
+
3996
+    if ($emboite === null) {
3997
+        return $env;
3998
+    }
3999
+    if (!trim($emboite)) {
4000
+        return '';
4001
+    }
4002
+    // toujours encoder l'url source dans le bloc ajax
4003
+    $r = self();
4004
+    $r = ' data-origin="' . $r . '"';
4005
+    $class = 'ajaxbloc';
4006
+    if ($ajaxid and is_string($ajaxid)) {
4007
+        // ajaxid est normalement conforme a un nom de classe css
4008
+        // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution
4009
+        $class .= ' ajax-id-' . entites_html($ajaxid);
4010
+    }
4011
+
4012
+    return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n";
4013 4013
 }
4014 4014
 
4015 4015
 /**
@@ -4029,37 +4029,37 @@  discard block
 block discarded – undo
4029 4029
  *   - false : erreur de décodage
4030 4030
  */
4031 4031
 function decoder_contexte_ajax($c, $form = '') {
4032
-	if (!function_exists('calculer_cle_action')) {
4033
-		include_spip('inc/securiser_action');
4034
-	}
4035
-	if (
4036
-		((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4037
-		and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4038
-		and lire_fichier("$dir/c$c", $contexte)
4039
-	) {
4040
-		$c = $contexte;
4041
-	} else {
4042
-		$c = @base64_decode($c);
4043
-		$c = _xor($c);
4044
-		if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4045
-			$c = @gzinflate($c);
4046
-		}
4047
-	}
4048
-
4049
-	// extraire la signature en debut de contexte
4050
-	// et la verifier avant de deserializer
4051
-	// format : signature:donneesserializees
4052
-	if ($p = strpos($c, ':')) {
4053
-		$cle = substr($c, 0, $p);
4054
-		$c = substr($c, $p + 1);
4055
-
4056
-		if ($cle == calculer_cle_action($form . $c)) {
4057
-			$env = @unserialize($c);
4058
-			return $env;
4059
-		}
4060
-	}
4061
-
4062
-	return false;
4032
+    if (!function_exists('calculer_cle_action')) {
4033
+        include_spip('inc/securiser_action');
4034
+    }
4035
+    if (
4036
+        ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32)
4037
+        and $dir = sous_repertoire(_DIR_CACHE, 'contextes')
4038
+        and lire_fichier("$dir/c$c", $contexte)
4039
+    ) {
4040
+        $c = $contexte;
4041
+    } else {
4042
+        $c = @base64_decode($c);
4043
+        $c = _xor($c);
4044
+        if (function_exists('gzdeflate') && function_exists('gzinflate')) {
4045
+            $c = @gzinflate($c);
4046
+        }
4047
+    }
4048
+
4049
+    // extraire la signature en debut de contexte
4050
+    // et la verifier avant de deserializer
4051
+    // format : signature:donneesserializees
4052
+    if ($p = strpos($c, ':')) {
4053
+        $cle = substr($c, 0, $p);
4054
+        $c = substr($c, $p + 1);
4055
+
4056
+        if ($cle == calculer_cle_action($form . $c)) {
4057
+            $env = @unserialize($c);
4058
+            return $env;
4059
+        }
4060
+    }
4061
+
4062
+    return false;
4063 4063
 }
4064 4064
 
4065 4065
 
@@ -4077,20 +4077,20 @@  discard block
 block discarded – undo
4077 4077
  *    Message décrypté ou encrypté
4078 4078
  **/
4079 4079
 function _xor($message, $key = null) {
4080
-	if (is_null($key)) {
4081
-		if (!function_exists('calculer_cle_action')) {
4082
-			include_spip('inc/securiser_action');
4083
-		}
4084
-		$key = pack('H*', calculer_cle_action('_xor'));
4085
-	}
4080
+    if (is_null($key)) {
4081
+        if (!function_exists('calculer_cle_action')) {
4082
+            include_spip('inc/securiser_action');
4083
+        }
4084
+        $key = pack('H*', calculer_cle_action('_xor'));
4085
+    }
4086 4086
 
4087
-	$keylen = strlen($key);
4088
-	$messagelen = strlen($message);
4089
-	for ($i = 0; $i < $messagelen; $i++) {
4090
-		$message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4091
-	}
4087
+    $keylen = strlen($key);
4088
+    $messagelen = strlen($message);
4089
+    for ($i = 0; $i < $messagelen; $i++) {
4090
+        $message[$i] = ~($message[$i] ^ $key[$i % $keylen]);
4091
+    }
4092 4092
 
4093
-	return $message;
4093
+    return $message;
4094 4094
 }
4095 4095
 
4096 4096
 /**
@@ -4104,7 +4104,7 @@  discard block
 block discarded – undo
4104 4104
  * @return string
4105 4105
  */
4106 4106
 function url_reponse_forum($texte) {
4107
- return $texte;
4107
+    return $texte;
4108 4108
 }
4109 4109
 
4110 4110
 /**
@@ -4118,7 +4118,7 @@  discard block
 block discarded – undo
4118 4118
  * @return string
4119 4119
  */
4120 4120
 function url_rss_forum($texte) {
4121
- return $texte;
4121
+    return $texte;
4122 4122
 }
4123 4123
 
4124 4124
 
@@ -4157,37 +4157,37 @@  discard block
 block discarded – undo
4157 4157
  *   Code HTML
4158 4158
  */
4159 4159
 function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') {
4160
-	if ($on) {
4161
-		$bal = 'strong';
4162
-		$class = '';
4163
-		$att = '';
4164
-		// si $on passe la balise et optionnelement une ou ++classe
4165
-		// a.active span.selected.active etc....
4166
-		if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4167
-			$on = explode('.', $on);
4168
-			// on verifie que c'est exactement une des 3 balises a, span ou strong
4169
-			if (in_array(reset($on), ['a', 'span', 'strong'])) {
4170
-				$bal = array_shift($on);
4171
-				$class = implode(' ', $on);
4172
-				if ($bal == 'a') {
4173
-					$att = 'href="#" ';
4174
-				}
4175
-			}
4176
-		}
4177
-		$att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4178
-	} else {
4179
-		$bal = 'a';
4180
-		$att = "href='$url'"
4181
-			. ($title ? " title='" . attribut_html($title) . "'" : '')
4182
-			. ($class ? " class='" . attribut_html($class) . "'" : '')
4183
-			. ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4184
-			. $evt;
4185
-	}
4186
-	if ($libelle === null) {
4187
-		$libelle = $url;
4188
-	}
4189
-
4190
-	return "<$bal $att>$libelle</$bal>";
4160
+    if ($on) {
4161
+        $bal = 'strong';
4162
+        $class = '';
4163
+        $att = '';
4164
+        // si $on passe la balise et optionnelement une ou ++classe
4165
+        // a.active span.selected.active etc....
4166
+        if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) {
4167
+            $on = explode('.', $on);
4168
+            // on verifie que c'est exactement une des 3 balises a, span ou strong
4169
+            if (in_array(reset($on), ['a', 'span', 'strong'])) {
4170
+                $bal = array_shift($on);
4171
+                $class = implode(' ', $on);
4172
+                if ($bal == 'a') {
4173
+                    $att = 'href="#" ';
4174
+                }
4175
+            }
4176
+        }
4177
+        $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"';
4178
+    } else {
4179
+        $bal = 'a';
4180
+        $att = "href='$url'"
4181
+            . ($title ? " title='" . attribut_html($title) . "'" : '')
4182
+            . ($class ? " class='" . attribut_html($class) . "'" : '')
4183
+            . ($rel ? " rel='" . attribut_html($rel) . "'" : '')
4184
+            . $evt;
4185
+    }
4186
+    if ($libelle === null) {
4187
+        $libelle = $url;
4188
+    }
4189
+
4190
+    return "<$bal $att>$libelle</$bal>";
4191 4191
 }
4192 4192
 
4193 4193
 
@@ -4204,39 +4204,39 @@  discard block
 block discarded – undo
4204 4204
  * @return string : la chaine de langue finale en utilisant la fonction _T()
4205 4205
  */
4206 4206
 function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) {
4207
-	static $local_singulier_ou_pluriel = [];
4208
-
4209
-	// si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4210
-	if (!is_numeric($nb) or $nb == 0) {
4211
-		return '';
4212
-	}
4213
-	if (!is_array($vars)) {
4214
-		return '';
4215
-	}
4216
-
4217
-	$langue = $GLOBALS['spip_lang'];
4218
-	if (!isset($local_singulier_ou_pluriel[$langue])) {
4219
-		$local_singulier_ou_pluriel[$langue] = false;
4220
-		if (
4221
-			$f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4222
-			or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4223
-		) {
4224
-			$local_singulier_ou_pluriel[$langue] = $f;
4225
-		}
4226
-	}
4227
-
4228
-	// si on a une surcharge on l'utilise
4229
-	if ($local_singulier_ou_pluriel[$langue]) {
4230
-		return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4231
-	}
4232
-
4233
-	// sinon traitement par defaut
4234
-	$vars[$var] = $nb;
4235
-	if ($nb >= 2) {
4236
-		return _T($chaine_plusieurs, $vars);
4237
-	} else {
4238
-		return _T($chaine_un, $vars);
4239
-	}
4207
+    static $local_singulier_ou_pluriel = [];
4208
+
4209
+    // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon
4210
+    if (!is_numeric($nb) or $nb == 0) {
4211
+        return '';
4212
+    }
4213
+    if (!is_array($vars)) {
4214
+        return '';
4215
+    }
4216
+
4217
+    $langue = $GLOBALS['spip_lang'];
4218
+    if (!isset($local_singulier_ou_pluriel[$langue])) {
4219
+        $local_singulier_ou_pluriel[$langue] = false;
4220
+        if (
4221
+            $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true)
4222
+            or $f = charger_fonction('singulier_ou_pluriel', 'inc', true)
4223
+        ) {
4224
+            $local_singulier_ou_pluriel[$langue] = $f;
4225
+        }
4226
+    }
4227
+
4228
+    // si on a une surcharge on l'utilise
4229
+    if ($local_singulier_ou_pluriel[$langue]) {
4230
+        return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars);
4231
+    }
4232
+
4233
+    // sinon traitement par defaut
4234
+    $vars[$var] = $nb;
4235
+    if ($nb >= 2) {
4236
+        return _T($chaine_plusieurs, $vars);
4237
+    } else {
4238
+        return _T($chaine_un, $vars);
4239
+    }
4240 4240
 }
4241 4241
 
4242 4242
 
@@ -4264,73 +4264,73 @@  discard block
 block discarded – undo
4264 4264
  */
4265 4265
 function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4266 4266
 
4267
-	$class_lien = $class_bouton = $class;
4268
-
4269
-	// Normaliser la fonction et compléter la classe en fonction
4270
-	if (in_array($fonction, ['del', 'supprimer.gif'])) {
4271
-		$class_lien .= ' danger';
4272
-		$class_bouton .= ' btn_danger';
4273
-	} elseif ($fonction == 'rien.gif') {
4274
-		$fonction = '';
4275
-	} elseif ($fonction == 'delsafe') {
4276
-		$fonction = 'del';
4277
-	}
4278
-
4279
-	$fond_origine = $fond;
4280
-	// Remappage des icone : article-24.png+new => article-new-24.png
4281
-	if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4282
-		[$fond, $fonction] = $icone_renommer($fond, $fonction);
4283
-	}
4284
-
4285
-	// Ajouter le type d'objet dans la classe
4286
-	$objet_type = substr(basename($fond), 0, -4);
4287
-	$class_lien .= " $objet_type";
4288
-	$class_bouton .= " $objet_type";
4289
-
4290
-	// texte
4291
-	$alt = attribut_html($texte);
4292
-	$title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4293
-
4294
-	// Liens : préparer les classes ajax
4295
-	$ajax = '';
4296
-	if ($type === 'lien') {
4297
-		if (strpos($class_lien, 'ajax') !== false) {
4298
-			$ajax = 'ajax';
4299
-			if (strpos($class_lien, 'preload') !== false) {
4300
-				$ajax .= ' preload';
4301
-			}
4302
-			if (strpos($class_lien, 'nocache') !== false) {
4303
-				$ajax .= ' nocache';
4304
-			}
4305
-			$ajax = " class='$ajax'";
4306
-		}
4307
-	}
4308
-
4309
-	// Repérer la taille et l'ajouter dans la classe
4310
-	$size = 24;
4311
-	if (
4312
-		preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4313
-		or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4314
-	) {
4315
-		$size = $match[1];
4316
-	}
4317
-	$class_lien .= " s$size";
4318
-	$class_bouton .= " s$size";
4319
-
4320
-	// Icône
4321
-	$icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4322
-	$icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4323
-
4324
-	// Markup final
4325
-	if ($type == 'lien') {
4326
-		return "<span class='icone $class_lien'>"
4327
-		. "<a href='$lien'$title$ajax$javascript>"
4328
-		. $icone
4329
-		. "<b>$texte</b>"
4330
-		. "</a></span>\n";
4331
-	} else {
4332
-		return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4333
-	}
4267
+    $class_lien = $class_bouton = $class;
4268
+
4269
+    // Normaliser la fonction et compléter la classe en fonction
4270
+    if (in_array($fonction, ['del', 'supprimer.gif'])) {
4271
+        $class_lien .= ' danger';
4272
+        $class_bouton .= ' btn_danger';
4273
+    } elseif ($fonction == 'rien.gif') {
4274
+        $fonction = '';
4275
+    } elseif ($fonction == 'delsafe') {
4276
+        $fonction = 'del';
4277
+    }
4278
+
4279
+    $fond_origine = $fond;
4280
+    // Remappage des icone : article-24.png+new => article-new-24.png
4281
+    if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
4282
+        [$fond, $fonction] = $icone_renommer($fond, $fonction);
4283
+    }
4284
+
4285
+    // Ajouter le type d'objet dans la classe
4286
+    $objet_type = substr(basename($fond), 0, -4);
4287
+    $class_lien .= " $objet_type";
4288
+    $class_bouton .= " $objet_type";
4289
+
4290
+    // texte
4291
+    $alt = attribut_html($texte);
4292
+    $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ?
4293
+
4294
+    // Liens : préparer les classes ajax
4295
+    $ajax = '';
4296
+    if ($type === 'lien') {
4297
+        if (strpos($class_lien, 'ajax') !== false) {
4298
+            $ajax = 'ajax';
4299
+            if (strpos($class_lien, 'preload') !== false) {
4300
+                $ajax .= ' preload';
4301
+            }
4302
+            if (strpos($class_lien, 'nocache') !== false) {
4303
+                $ajax .= ' nocache';
4304
+            }
4305
+            $ajax = " class='$ajax'";
4306
+        }
4307
+    }
4308
+
4309
+    // Repérer la taille et l'ajouter dans la classe
4310
+    $size = 24;
4311
+    if (
4312
+        preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match)
4313
+        or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match)
4314
+    ) {
4315
+        $size = $match[1];
4316
+    }
4317
+    $class_lien .= " s$size";
4318
+    $class_bouton .= " s$size";
4319
+
4320
+    // Icône
4321
+    $icone = http_img_pack($fond, $alt, "width='$size' height='$size'");
4322
+    $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>";
4323
+
4324
+    // Markup final
4325
+    if ($type == 'lien') {
4326
+        return "<span class='icone $class_lien'>"
4327
+        . "<a href='$lien'$title$ajax$javascript>"
4328
+        . $icone
4329
+        . "<b>$texte</b>"
4330
+        . "</a></span>\n";
4331
+    } else {
4332
+        return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt);
4333
+    }
4334 4334
 }
4335 4335
 
4336 4336
 /**
@@ -4354,7 +4354,7 @@  discard block
 block discarded – undo
4354 4354
  *     Code HTML du lien
4355 4355
  **/
4356 4356
 function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4357
-	return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4357
+    return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript);
4358 4358
 }
4359 4359
 
4360 4360
 /**
@@ -4389,7 +4389,7 @@  discard block
 block discarded – undo
4389 4389
  *     Code HTML du lien
4390 4390
  **/
4391 4391
 function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4392
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4392
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript);
4393 4393
 }
4394 4394
 
4395 4395
 /**
@@ -4434,7 +4434,7 @@  discard block
 block discarded – undo
4434 4434
  *     Code HTML du lien
4435 4435
  **/
4436 4436
 function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') {
4437
-	return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4437
+    return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript);
4438 4438
 }
4439 4439
 
4440 4440
 /**
@@ -4465,7 +4465,7 @@  discard block
 block discarded – undo
4465 4465
  *     Code HTML du lien
4466 4466
  **/
4467 4467
 function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') {
4468
-	return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4468
+    return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm);
4469 4469
 }
4470 4470
 
4471 4471
 /**
@@ -4496,7 +4496,7 @@  discard block
 block discarded – undo
4496 4496
  *     Code HTML du lien
4497 4497
  */
4498 4498
 function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') {
4499
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4499
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript);
4500 4500
 }
4501 4501
 
4502 4502
 
@@ -4518,7 +4518,7 @@  discard block
 block discarded – undo
4518 4518
  * @return array Liste des éléments
4519 4519
  */
4520 4520
 function filtre_explode_dist($a, $b) {
4521
-	return explode($b, (string) $a);
4521
+    return explode($b, (string) $a);
4522 4522
 }
4523 4523
 
4524 4524
 /**
@@ -4539,7 +4539,7 @@  discard block
 block discarded – undo
4539 4539
  * @return string texte
4540 4540
  */
4541 4541
 function filtre_implode_dist($a, $b) {
4542
-	return is_array($a) ? implode($b, $a) : $a;
4542
+    return is_array($a) ? implode($b, $a) : $a;
4543 4543
 }
4544 4544
 
4545 4545
 /**
@@ -4548,22 +4548,22 @@  discard block
 block discarded – undo
4548 4548
  * @return string Code CSS
4549 4549
  */
4550 4550
 function bando_images_background() {
4551
-	include_spip('inc/bandeau');
4552
-	// recuperer tous les boutons et leurs images
4553
-	$boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4551
+    include_spip('inc/bandeau');
4552
+    // recuperer tous les boutons et leurs images
4553
+    $boutons = definir_barre_boutons(definir_barre_contexte(), true, false);
4554 4554
 
4555
-	$res = '';
4556
-	foreach ($boutons as $page => $detail) {
4557
-		$selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4558
-		foreach ($detail->sousmenu as $souspage => $sousdetail) {
4559
-			if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4560
-				$img = http_img_variante_svg_si_possible($sousdetail->icone);
4561
-				$res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4562
-			}
4563
-		}
4564
-	}
4555
+    $res = '';
4556
+    foreach ($boutons as $page => $detail) {
4557
+        $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones ');
4558
+        foreach ($detail->sousmenu as $souspage => $sousdetail) {
4559
+            if ($sousdetail->icone and strlen(trim($sousdetail->icone))) {
4560
+                $img = http_img_variante_svg_si_possible($sousdetail->icone);
4561
+                $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}";
4562
+            }
4563
+        }
4564
+    }
4565 4565
 
4566
-	return $res;
4566
+    return $res;
4567 4567
 }
4568 4568
 
4569 4569
 /**
@@ -4588,27 +4588,27 @@  discard block
 block discarded – undo
4588 4588
  */
4589 4589
 function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') {
4590 4590
 
4591
-	// Classes : dispatcher `ajax` sur le formulaire
4592
-	$class_form = '';
4593
-	if (strpos($class, 'ajax') !== false) {
4594
-		$class_form = 'ajax';
4595
-		$class = str_replace('ajax', '', $class);
4596
-	}
4597
-	$class_btn = 'submit ' . trim($class);
4591
+    // Classes : dispatcher `ajax` sur le formulaire
4592
+    $class_form = '';
4593
+    if (strpos($class, 'ajax') !== false) {
4594
+        $class_form = 'ajax';
4595
+        $class = str_replace('ajax', '', $class);
4596
+    }
4597
+    $class_btn = 'submit ' . trim($class);
4598 4598
 
4599
-	if ($confirm) {
4600
-		$confirm = 'confirm("' . attribut_html($confirm) . '")';
4601
-		if ($callback) {
4602
-			$callback = "$confirm?($callback):false";
4603
-		} else {
4604
-			$callback = $confirm;
4605
-		}
4606
-	}
4607
-	$onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4608
-	$title = $title ? " title='$title'" : '';
4599
+    if ($confirm) {
4600
+        $confirm = 'confirm("' . attribut_html($confirm) . '")';
4601
+        if ($callback) {
4602
+            $callback = "$confirm?($callback):false";
4603
+        } else {
4604
+            $callback = $confirm;
4605
+        }
4606
+    }
4607
+    $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : '';
4608
+    $title = $title ? " title='$title'" : '';
4609 4609
 
4610
-	return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4611
-	. "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4610
+    return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url)
4611
+    . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>";
4612 4612
 }
4613 4613
 
4614 4614
 /**
@@ -4631,101 +4631,101 @@  discard block
 block discarded – undo
4631 4631
  * @return string
4632 4632
  */
4633 4633
 function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string {
4634
-	static $trouver_table = null;
4635
-	static $objets;
4636
-
4637
-	// On verifie qu'on a tout ce qu'il faut
4638
-	$id_objet = intval($id_objet);
4639
-	if (!($id_objet and $type_objet and $info)) {
4640
-		return '';
4641
-	}
4642
-
4643
-	// si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4644
-	if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4645
-		return '';
4646
-	}
4647
-
4648
-	// Si on demande l'url, on retourne direct la fonction
4649
-	if ($info == 'url') {
4650
-		return generer_objet_url($id_objet, $type_objet, ...$params);
4651
-	}
4652
-
4653
-	// Sinon on va tout chercher dans la table et on garde en memoire
4654
-	$demande_titre = ($info === 'titre');
4655
-	$demande_introduction = ($info === 'introduction');
4656
-
4657
-	// 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
4658
-	if (
4659
-		!isset($objets[$type_objet][$id_objet])
4660
-		or
4661
-		($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4662
-	) {
4663
-		if (!$trouver_table) {
4664
-			$trouver_table = charger_fonction('trouver_table', 'base');
4665
-		}
4666
-		$desc = $trouver_table(table_objet_sql($type_objet));
4667
-		if (!$desc) {
4668
-			return $objets[$type_objet] = false;
4669
-		}
4670
-
4671
-		// Si on demande le titre, on le gere en interne
4672
-		$champ_titre = '';
4673
-		if ($demande_titre) {
4674
-			// si pas de titre declare mais champ titre, il sera peuple par le select *
4675
-			$champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4676
-		}
4677
-		include_spip('base/abstract_sql');
4678
-		include_spip('base/connect_sql');
4679
-		$objets[$type_objet][$id_objet] = sql_fetsel(
4680
-			'*' . $champ_titre,
4681
-			$desc['table_sql'],
4682
-			id_table_objet($type_objet) . ' = ' . intval($id_objet)
4683
-		);
4684
-
4685
-		// Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4686
-		$objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4687
-	}
4688
-
4689
-	// Pour les fonction generer_xxx, si on demande l'introduction,
4690
-	// ajouter la longueur au début des params supplémentaires
4691
-	if ($demande_introduction) {
4692
-		$introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4693
-		array_unshift($params, $introduction_longueur);
4694
-	}
4695
-
4696
-	// Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4697
-	if (
4698
-		$generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4699
-		// @deprecated 4.1 generer_TRUC_TYPE
4700
-		or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4701
-	) {
4702
-		$info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4703
-	}
4704
-	// Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4705
-	elseif (
4706
-		$generer = charger_fonction("generer_objet_{$info}", '', true)
4707
-		// @deprecated 4.1 generer_TRUC_entite
4708
-		or $generer = charger_fonction("generer_{$info}_entite", '', true)
4709
-	) {
4710
-		$info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4711
-	} // Sinon on prend directement le champ SQL tel quel
4712
-	else {
4713
-		$info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4714
-	}
4715
-
4716
-	// On va ensuite appliquer les traitements automatiques si besoin
4717
-	if (!$etoile) {
4718
-		// FIXME: on fournit un ENV minimum avec id et type et connect=''
4719
-		// mais ce fonctionnement est a ameliorer !
4720
-		$info_generee = appliquer_traitement_champ(
4721
-			$info_generee,
4722
-			$info,
4723
-			table_objet($type_objet),
4724
-			['id_objet' => $id_objet, 'objet' => $type_objet, '']
4725
-		);
4726
-	}
4727
-
4728
-	return $info_generee;
4634
+    static $trouver_table = null;
4635
+    static $objets;
4636
+
4637
+    // On verifie qu'on a tout ce qu'il faut
4638
+    $id_objet = intval($id_objet);
4639
+    if (!($id_objet and $type_objet and $info)) {
4640
+        return '';
4641
+    }
4642
+
4643
+    // si on a deja note que l'objet n'existe pas, ne pas aller plus loin
4644
+    if (isset($objets[$type_objet]) and $objets[$type_objet] === false) {
4645
+        return '';
4646
+    }
4647
+
4648
+    // Si on demande l'url, on retourne direct la fonction
4649
+    if ($info == 'url') {
4650
+        return generer_objet_url($id_objet, $type_objet, ...$params);
4651
+    }
4652
+
4653
+    // Sinon on va tout chercher dans la table et on garde en memoire
4654
+    $demande_titre = ($info === 'titre');
4655
+    $demande_introduction = ($info === 'introduction');
4656
+
4657
+    // 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
4658
+    if (
4659
+        !isset($objets[$type_objet][$id_objet])
4660
+        or
4661
+        ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre']))
4662
+    ) {
4663
+        if (!$trouver_table) {
4664
+            $trouver_table = charger_fonction('trouver_table', 'base');
4665
+        }
4666
+        $desc = $trouver_table(table_objet_sql($type_objet));
4667
+        if (!$desc) {
4668
+            return $objets[$type_objet] = false;
4669
+        }
4670
+
4671
+        // Si on demande le titre, on le gere en interne
4672
+        $champ_titre = '';
4673
+        if ($demande_titre) {
4674
+            // si pas de titre declare mais champ titre, il sera peuple par le select *
4675
+            $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : '';
4676
+        }
4677
+        include_spip('base/abstract_sql');
4678
+        include_spip('base/connect_sql');
4679
+        $objets[$type_objet][$id_objet] = sql_fetsel(
4680
+            '*' . $champ_titre,
4681
+            $desc['table_sql'],
4682
+            id_table_objet($type_objet) . ' = ' . intval($id_objet)
4683
+        );
4684
+
4685
+        // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci
4686
+        $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null;
4687
+    }
4688
+
4689
+    // Pour les fonction generer_xxx, si on demande l'introduction,
4690
+    // ajouter la longueur au début des params supplémentaires
4691
+    if ($demande_introduction) {
4692
+        $introduction_longueur = $objets[$type_objet]['introduction_longueur'];
4693
+        array_unshift($params, $introduction_longueur);
4694
+    }
4695
+
4696
+    // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee
4697
+    if (
4698
+        $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true)
4699
+        // @deprecated 4.1 generer_TRUC_TYPE
4700
+        or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true)
4701
+    ) {
4702
+        $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params);
4703
+    }
4704
+    // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee
4705
+    elseif (
4706
+        $generer = charger_fonction("generer_objet_{$info}", '', true)
4707
+        // @deprecated 4.1 generer_TRUC_entite
4708
+        or $generer = charger_fonction("generer_{$info}_entite", '', true)
4709
+    ) {
4710
+        $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params);
4711
+    } // Sinon on prend directement le champ SQL tel quel
4712
+    else {
4713
+        $info_generee = ($objets[$type_objet][$id_objet][$info] ?? '');
4714
+    }
4715
+
4716
+    // On va ensuite appliquer les traitements automatiques si besoin
4717
+    if (!$etoile) {
4718
+        // FIXME: on fournit un ENV minimum avec id et type et connect=''
4719
+        // mais ce fonctionnement est a ameliorer !
4720
+        $info_generee = appliquer_traitement_champ(
4721
+            $info_generee,
4722
+            $info,
4723
+            table_objet($type_objet),
4724
+            ['id_objet' => $id_objet, 'objet' => $type_objet, '']
4725
+        );
4726
+    }
4727
+
4728
+    return $info_generee;
4729 4729
 }
4730 4730
 
4731 4731
 /**
@@ -4733,7 +4733,7 @@  discard block
 block discarded – undo
4733 4733
  * @see generer_objet_info
4734 4734
  */
4735 4735
 function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) {
4736
-	return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4736
+    return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params);
4737 4737
 }
4738 4738
 
4739 4739
 /**
@@ -4766,36 +4766,36 @@  discard block
 block discarded – undo
4766 4766
  */
4767 4767
 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 {
4768 4768
 
4769
-	$descriptif = $ligne_sql['descriptif'] ?? '';
4770
-	$texte = $ligne_sql['texte'] ?? '';
4771
-	// En absence de descriptif, on se rabat sur chapo + texte
4772
-	if (isset($ligne_sql['chapo'])) {
4773
-		$chapo = $ligne_sql['chapo'];
4774
-		$texte = strlen($descriptif) ?
4775
-			'' :
4776
-			"$chapo \n\n $texte";
4777
-	}
4769
+    $descriptif = $ligne_sql['descriptif'] ?? '';
4770
+    $texte = $ligne_sql['texte'] ?? '';
4771
+    // En absence de descriptif, on se rabat sur chapo + texte
4772
+    if (isset($ligne_sql['chapo'])) {
4773
+        $chapo = $ligne_sql['chapo'];
4774
+        $texte = strlen($descriptif) ?
4775
+            '' :
4776
+            "$chapo \n\n $texte";
4777
+    }
4778 4778
 
4779
-	// Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4780
-	if (!intval($longueur_ou_suite)) {
4781
-		$longueur = intval($introduction_longueur ?: 600);
4782
-	} else {
4783
-		$longueur = intval($longueur_ou_suite);
4784
-	}
4779
+    // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur
4780
+    if (!intval($longueur_ou_suite)) {
4781
+        $longueur = intval($introduction_longueur ?: 600);
4782
+    } else {
4783
+        $longueur = intval($longueur_ou_suite);
4784
+    }
4785 4785
 
4786
-	// On peut optionnellement passer la suite en 1er paramètre de la balise
4787
-	// Ex : #INTRODUCTION{...}
4788
-	if (
4789
-		is_null($suite)
4790
-		and !intval($longueur_ou_suite)
4791
-	) {
4792
-		$suite = $longueur_ou_suite;
4793
-	}
4786
+    // On peut optionnellement passer la suite en 1er paramètre de la balise
4787
+    // Ex : #INTRODUCTION{...}
4788
+    if (
4789
+        is_null($suite)
4790
+        and !intval($longueur_ou_suite)
4791
+    ) {
4792
+        $suite = $longueur_ou_suite;
4793
+    }
4794 4794
 
4795
-	$f = chercher_filtre('introduction');
4796
-	$introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4795
+    $f = chercher_filtre('introduction');
4796
+    $introduction = $f($descriptif, $texte, $longueur, $connect, $suite);
4797 4797
 
4798
-	return $introduction;
4798
+    return $introduction;
4799 4799
 }
4800 4800
 
4801 4801
 /**
@@ -4803,7 +4803,7 @@  discard block
 block discarded – undo
4803 4803
  * @see generer_objet_introduction
4804 4804
  */
4805 4805
 function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') {
4806
-	return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4806
+    return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect);
4807 4807
 }
4808 4808
 
4809 4809
 /**
@@ -4817,49 +4817,49 @@  discard block
 block discarded – undo
4817 4817
  * @return string
4818 4818
  */
4819 4819
 function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') {
4820
-	if (!$champ) {
4821
-		return $texte;
4822
-	}
4820
+    if (!$champ) {
4821
+        return $texte;
4822
+    }
4823 4823
 
4824
-	// On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4825
-	// car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4826
-	include_fichiers_fonctions();
4824
+    // On charge les définitions des traitements (inc/texte et fichiers de fonctions)
4825
+    // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc)
4826
+    include_fichiers_fonctions();
4827 4827
 
4828
-	$champ = strtoupper($champ);
4829
-	$traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4830
-	if (!$traitements or !is_array($traitements)) {
4831
-		return $texte;
4832
-	}
4828
+    $champ = strtoupper($champ);
4829
+    $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false;
4830
+    if (!$traitements or !is_array($traitements)) {
4831
+        return $texte;
4832
+    }
4833 4833
 
4834
-	$traitement = '';
4835
-	if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4836
-		// necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4837
-		$table_objet = table_objet($table_objet);
4838
-		if (isset($traitements[$table_objet])) {
4839
-			$traitement = $traitements[$table_objet];
4840
-		}
4841
-	}
4842
-	if (!$traitement and isset($traitements[0])) {
4843
-		$traitement = $traitements[0];
4844
-	}
4845
-	// (sinon prendre le premier de la liste par defaut ?)
4834
+    $traitement = '';
4835
+    if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) {
4836
+        // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg
4837
+        $table_objet = table_objet($table_objet);
4838
+        if (isset($traitements[$table_objet])) {
4839
+            $traitement = $traitements[$table_objet];
4840
+        }
4841
+    }
4842
+    if (!$traitement and isset($traitements[0])) {
4843
+        $traitement = $traitements[0];
4844
+    }
4845
+    // (sinon prendre le premier de la liste par defaut ?)
4846 4846
 
4847
-	if (!$traitement) {
4848
-		return $texte;
4849
-	}
4847
+    if (!$traitement) {
4848
+        return $texte;
4849
+    }
4850 4850
 
4851
-	$traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4851
+    $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement);
4852 4852
 
4853
-	// signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4854
-	if (test_espace_prive()) {
4855
-		$env['espace_prive'] = 1;
4856
-	}
4853
+    // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag
4854
+    if (test_espace_prive()) {
4855
+        $env['espace_prive'] = 1;
4856
+    }
4857 4857
 
4858
-	// Fournir $connect et $Pile[0] au traitement si besoin
4859
-	$Pile = [0 => $env];
4860
-	eval("\$texte = $traitement;");
4858
+    // Fournir $connect et $Pile[0] au traitement si besoin
4859
+    $Pile = [0 => $env];
4860
+    eval("\$texte = $traitement;");
4861 4861
 
4862
-	return $texte;
4862
+    return $texte;
4863 4863
 }
4864 4864
 
4865 4865
 
@@ -4873,21 +4873,21 @@  discard block
 block discarded – undo
4873 4873
  * @return string
4874 4874
  */
4875 4875
 function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string {
4876
-	include_spip('inc/liens');
4877
-	$titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4878
-	// lorsque l'objet n'est plus declare (plugin desactive par exemple)
4879
-	// le raccourcis n'est plus valide
4880
-	$titre = typo($titre['titre'] ?? '');
4881
-	// on essaye avec generer_info_entite ?
4882
-	if (!strlen($titre) and !$connect) {
4883
-		$titre = generer_objet_info($id_objet, $objet, 'titre');
4884
-	}
4885
-	if (!strlen($titre)) {
4886
-		$titre = _T('info_sans_titre');
4887
-	}
4888
-	$url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4876
+    include_spip('inc/liens');
4877
+    $titre = traiter_raccourci_titre($id_objet, $objet, $connect);
4878
+    // lorsque l'objet n'est plus declare (plugin desactive par exemple)
4879
+    // le raccourcis n'est plus valide
4880
+    $titre = typo($titre['titre'] ?? '');
4881
+    // on essaye avec generer_info_entite ?
4882
+    if (!strlen($titre) and !$connect) {
4883
+        $titre = generer_objet_info($id_objet, $objet, 'titre');
4884
+    }
4885
+    if (!strlen($titre)) {
4886
+        $titre = _T('info_sans_titre');
4887
+    }
4888
+    $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect);
4889 4889
 
4890
-	return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4890
+    return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>';
4891 4891
 }
4892 4892
 
4893 4893
 /**
@@ -4895,7 +4895,7 @@  discard block
 block discarded – undo
4895 4895
  * @see generer_objet_lien
4896 4896
  */
4897 4897
 function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) {
4898
-	return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4898
+    return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? '');
4899 4899
 }
4900 4900
 
4901 4901
 /**
@@ -4911,15 +4911,15 @@  discard block
 block discarded – undo
4911 4911
  * @return string
4912 4912
  */
4913 4913
 function wrap($texte, $wrap) {
4914
-	$balises = extraire_balises($wrap);
4915
-	if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4916
-		$texte = $wrap . $texte;
4917
-		$regs = array_reverse($regs[1]);
4918
-		$wrap = '</' . implode('></', $regs) . '>';
4919
-		$texte = $texte . $wrap;
4920
-	}
4914
+    $balises = extraire_balises($wrap);
4915
+    if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) {
4916
+        $texte = $wrap . $texte;
4917
+        $regs = array_reverse($regs[1]);
4918
+        $wrap = '</' . implode('></', $regs) . '>';
4919
+        $texte = $texte . $wrap;
4920
+    }
4921 4921
 
4922
-	return $texte;
4922
+    return $texte;
4923 4923
 }
4924 4924
 
4925 4925
 
@@ -4939,44 +4939,44 @@  discard block
 block discarded – undo
4939 4939
  * @return array|mixed|string
4940 4940
  */
4941 4941
 function filtre_print_dist($u, $join = '<br />', $indent = 0) {
4942
-	if (is_string($u)) {
4943
-		$u = typo($u);
4942
+    if (is_string($u)) {
4943
+        $u = typo($u);
4944 4944
 
4945
-		return $u;
4946
-	}
4945
+        return $u;
4946
+    }
4947 4947
 
4948
-	// caster $u en array si besoin
4949
-	if (is_object($u)) {
4950
-		$u = (array)$u;
4951
-	}
4948
+    // caster $u en array si besoin
4949
+    if (is_object($u)) {
4950
+        $u = (array)$u;
4951
+    }
4952 4952
 
4953
-	if (is_array($u)) {
4954
-		$out = '';
4955
-		// toutes les cles sont numeriques ?
4956
-		// et aucun enfant n'est un tableau
4957
-		// liste simple separee par des virgules
4958
-		$numeric_keys = array_map('is_numeric', array_keys($u));
4959
-		$array_values = array_map('is_array', $u);
4960
-		$object_values = array_map('is_object', $u);
4961
-		if (
4962
-			array_sum($numeric_keys) == count($numeric_keys)
4963
-			and !array_sum($array_values)
4964
-			and !array_sum($object_values)
4965
-		) {
4966
-			return join(', ', array_map('filtre_print_dist', $u));
4967
-		}
4953
+    if (is_array($u)) {
4954
+        $out = '';
4955
+        // toutes les cles sont numeriques ?
4956
+        // et aucun enfant n'est un tableau
4957
+        // liste simple separee par des virgules
4958
+        $numeric_keys = array_map('is_numeric', array_keys($u));
4959
+        $array_values = array_map('is_array', $u);
4960
+        $object_values = array_map('is_object', $u);
4961
+        if (
4962
+            array_sum($numeric_keys) == count($numeric_keys)
4963
+            and !array_sum($array_values)
4964
+            and !array_sum($object_values)
4965
+        ) {
4966
+            return join(', ', array_map('filtre_print_dist', $u));
4967
+        }
4968 4968
 
4969
-		// sinon on passe a la ligne et on indente
4970
-		$i_str = str_pad('', $indent, ' ');
4971
-		foreach ($u as $k => $v) {
4972
-			$out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4973
-		}
4969
+        // sinon on passe a la ligne et on indente
4970
+        $i_str = str_pad('', $indent, ' ');
4971
+        foreach ($u as $k => $v) {
4972
+            $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2);
4973
+        }
4974 4974
 
4975
-		return $out;
4976
-	}
4975
+        return $out;
4976
+    }
4977 4977
 
4978
-	// on sait pas quoi faire...
4979
-	return $u;
4978
+    // on sait pas quoi faire...
4979
+    return $u;
4980 4980
 }
4981 4981
 
4982 4982
 
@@ -4989,10 +4989,10 @@  discard block
 block discarded – undo
4989 4989
  * @return string|array
4990 4990
  */
4991 4991
 function objet_info($objet, $info) {
4992
-	$table = table_objet_sql($objet);
4993
-	$infos = lister_tables_objets_sql($table);
4992
+    $table = table_objet_sql($objet);
4993
+    $infos = lister_tables_objets_sql($table);
4994 4994
 
4995
-	return ($infos[$info] ?? '');
4995
+    return ($infos[$info] ?? '');
4996 4996
 }
4997 4997
 
4998 4998
 /**
@@ -5007,11 +5007,11 @@  discard block
 block discarded – undo
5007 5007
  *     texte traduit du comptage, tel que '3 articles'
5008 5008
  */
5009 5009
 function objet_afficher_nb($nb, $objet) {
5010
-	if (!$nb) {
5011
-		return _T(objet_info($objet, 'info_aucun_objet'));
5012
-	} else {
5013
-		return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5014
-	}
5010
+    if (!$nb) {
5011
+        return _T(objet_info($objet, 'info_aucun_objet'));
5012
+    } else {
5013
+        return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]);
5014
+    }
5015 5015
 }
5016 5016
 
5017 5017
 /**
@@ -5023,11 +5023,11 @@  discard block
 block discarded – undo
5023 5023
  * @return string
5024 5024
  */
5025 5025
 function objet_icone($objet, $taille = 24, $class = '') {
5026
-	$icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5027
-	$icone = chemin_image($icone);
5028
-	$balise_img = charger_filtre('balise_img');
5026
+    $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png';
5027
+    $icone = chemin_image($icone);
5028
+    $balise_img = charger_filtre('balise_img');
5029 5029
 
5030
-	return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5030
+    return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : '';
5031 5031
 }
5032 5032
 
5033 5033
 /**
@@ -5048,12 +5048,12 @@  discard block
 block discarded – undo
5048 5048
  * @return string
5049 5049
  */
5050 5050
 function objet_T($objet, $chaine, $args = [], $options = []) {
5051
-	$chaine = explode(':', $chaine);
5052
-	if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5053
-		return $t;
5054
-	}
5055
-	$chaine = implode(':', $chaine);
5056
-	return _T($chaine, $args, $options);
5051
+    $chaine = explode(':', $chaine);
5052
+    if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) {
5053
+        return $t;
5054
+    }
5055
+    $chaine = implode(':', $chaine);
5056
+    return _T($chaine, $args, $options);
5057 5057
 }
5058 5058
 
5059 5059
 /**
@@ -5067,18 +5067,18 @@  discard block
 block discarded – undo
5067 5067
  * @return string      Code HTML
5068 5068
  */
5069 5069
 function insert_head_css_conditionnel($flux) {
5070
-	if (
5071
-		strpos($flux, '<!-- insert_head_css -->') === false
5072
-		and $p = strpos($flux, '<!-- insert_head -->')
5073
-	) {
5074
-		// plutot avant le premier js externe (jquery) pour etre non bloquant
5075
-		if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5076
-			$p = $p1;
5077
-		}
5078
-		$flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5079
-	}
5070
+    if (
5071
+        strpos($flux, '<!-- insert_head_css -->') === false
5072
+        and $p = strpos($flux, '<!-- insert_head -->')
5073
+    ) {
5074
+        // plutot avant le premier js externe (jquery) pour etre non bloquant
5075
+        if ($p1 = stripos($flux, '<script src=') and $p1 < $p) {
5076
+            $p = $p1;
5077
+        }
5078
+        $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0);
5079
+    }
5080 5080
 
5081
-	return $flux;
5081
+    return $flux;
5082 5082
 }
5083 5083
 
5084 5084
 /**
@@ -5101,75 +5101,75 @@  discard block
 block discarded – undo
5101 5101
  * @return string
5102 5102
  */
5103 5103
 function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') {
5104
-	if (isset($contexte['format'])) {
5105
-		$extension = $contexte['format'];
5106
-		unset($contexte['format']);
5107
-	} else {
5108
-		$extension = 'html';
5109
-		if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5110
-			$extension = $m[1];
5111
-		}
5112
-	}
5113
-	// recuperer le contenu produit par le squelette
5114
-	$options['raw'] = true;
5115
-	$cache = recuperer_fond($fond, $contexte, $options, $connect);
5116
-
5117
-	// calculer le nom de la css
5118
-	$dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5119
-	$nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5120
-	$contexte_implicite = calculer_contexte_implicite();
5121
-
5122
-	// par defaut on hash selon les contextes qui sont a priori moins variables
5123
-	// mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5124
-	// reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5125
-	if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5126
-		$hash = md5($contexte_implicite['host'] . '::' . $cache);
5127
-	}
5128
-	else {
5129
-		unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5130
-		ksort($contexte);
5131
-		$hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5132
-	}
5133
-	$filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5134
-
5135
-	// mettre a jour le fichier si il n'existe pas
5136
-	// ou trop ancien
5137
-	// le dernier fichier produit est toujours suffixe par .last
5138
-	// et recopie sur le fichier cible uniquement si il change
5139
-	if (
5140
-		!file_exists($filename)
5141
-		or !file_exists($filename . '.last')
5142
-		or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5143
-		or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5144
-	) {
5145
-		$contenu = $cache['texte'];
5146
-		// passer les urls en absolu si c'est une css
5147
-		if ($extension == 'css') {
5148
-			$contenu = urls_absolues_css(
5149
-				$contenu,
5150
-				test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5151
-			);
5152
-		}
5153
-
5154
-		$comment = '';
5155
-		// ne pas insérer de commentaire sur certains formats
5156
-		if (!in_array($extension, ['json', 'xml', 'svg'])) {
5157
-			$comment = "/* #PRODUIRE{fond=$fond";
5158
-			foreach ($contexte as $k => $v) {
5159
-				if (is_array($v)) {
5160
-					$v = var_export($v, true);
5161
-				}
5162
-				$comment .= ",$k=$v";
5163
-			}
5164
-			// pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5165
-			// mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5166
-			$comment .= "}\n   md5:" . md5($contenu) . " */\n";
5167
-		}
5168
-		// et ecrire le fichier si il change
5169
-		ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5170
-	}
5171
-
5172
-	return timestamp($filename);
5104
+    if (isset($contexte['format'])) {
5105
+        $extension = $contexte['format'];
5106
+        unset($contexte['format']);
5107
+    } else {
5108
+        $extension = 'html';
5109
+        if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) {
5110
+            $extension = $m[1];
5111
+        }
5112
+    }
5113
+    // recuperer le contenu produit par le squelette
5114
+    $options['raw'] = true;
5115
+    $cache = recuperer_fond($fond, $contexte, $options, $connect);
5116
+
5117
+    // calculer le nom de la css
5118
+    $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension);
5119
+    $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond));
5120
+    $contexte_implicite = calculer_contexte_implicite();
5121
+
5122
+    // par defaut on hash selon les contextes qui sont a priori moins variables
5123
+    // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu
5124
+    // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine
5125
+    if (isset($options['hash_on_content']) and $options['hash_on_content']) {
5126
+        $hash = md5($contexte_implicite['host'] . '::' . $cache);
5127
+    }
5128
+    else {
5129
+        unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js
5130
+        ksort($contexte);
5131
+        $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect);
5132
+    }
5133
+    $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension";
5134
+
5135
+    // mettre a jour le fichier si il n'existe pas
5136
+    // ou trop ancien
5137
+    // le dernier fichier produit est toujours suffixe par .last
5138
+    // et recopie sur le fichier cible uniquement si il change
5139
+    if (
5140
+        !file_exists($filename)
5141
+        or !file_exists($filename . '.last')
5142
+        or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified'])
5143
+        or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
5144
+    ) {
5145
+        $contenu = $cache['texte'];
5146
+        // passer les urls en absolu si c'est une css
5147
+        if ($extension == 'css') {
5148
+            $contenu = urls_absolues_css(
5149
+                $contenu,
5150
+                test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond)
5151
+            );
5152
+        }
5153
+
5154
+        $comment = '';
5155
+        // ne pas insérer de commentaire sur certains formats
5156
+        if (!in_array($extension, ['json', 'xml', 'svg'])) {
5157
+            $comment = "/* #PRODUIRE{fond=$fond";
5158
+            foreach ($contexte as $k => $v) {
5159
+                if (is_array($v)) {
5160
+                    $v = var_export($v, true);
5161
+                }
5162
+                $comment .= ",$k=$v";
5163
+            }
5164
+            // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj
5165
+            // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non
5166
+            $comment .= "}\n   md5:" . md5($contenu) . " */\n";
5167
+        }
5168
+        // et ecrire le fichier si il change
5169
+        ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true);
5170
+    }
5171
+
5172
+    return timestamp($filename);
5173 5173
 }
5174 5174
 
5175 5175
 /**
@@ -5182,15 +5182,15 @@  discard block
 block discarded – undo
5182 5182
  *    $fichier auquel on a ajouté le timestamp
5183 5183
  */
5184 5184
 function timestamp($fichier) {
5185
-	if (
5186
-		!$fichier
5187
-		or !file_exists($fichier)
5188
-		or !$m = filemtime($fichier)
5189
-	) {
5190
-		return $fichier;
5191
-	}
5185
+    if (
5186
+        !$fichier
5187
+        or !file_exists($fichier)
5188
+        or !$m = filemtime($fichier)
5189
+    ) {
5190
+        return $fichier;
5191
+    }
5192 5192
 
5193
-	return "$fichier?$m";
5193
+    return "$fichier?$m";
5194 5194
 }
5195 5195
 
5196 5196
 /**
@@ -5200,11 +5200,11 @@  discard block
 block discarded – undo
5200 5200
  * @return string
5201 5201
  */
5202 5202
 function supprimer_timestamp($url) {
5203
-	if (strpos($url, '?') === false) {
5204
-		return $url;
5205
-	}
5203
+    if (strpos($url, '?') === false) {
5204
+        return $url;
5205
+    }
5206 5206
 
5207
-	return preg_replace(',\?[[:digit:]]+$,', '', $url);
5207
+    return preg_replace(',\?[[:digit:]]+$,', '', $url);
5208 5208
 }
5209 5209
 
5210 5210
 /**
@@ -5219,15 +5219,15 @@  discard block
 block discarded – undo
5219 5219
  * @return string
5220 5220
  */
5221 5221
 function filtre_nettoyer_titre_email_dist($titre) {
5222
-	include_spip('inc/envoyer_mail');
5222
+    include_spip('inc/envoyer_mail');
5223 5223
 
5224
-	$titre = nettoyer_titre_email($titre);
5225
-	// on est dans un squelette : securiser le retour
5226
-	if (strpos($titre, '<') !== false) {
5227
-		$titre = interdire_scripts($titre);
5228
-	}
5224
+    $titre = nettoyer_titre_email($titre);
5225
+    // on est dans un squelette : securiser le retour
5226
+    if (strpos($titre, '<') !== false) {
5227
+        $titre = interdire_scripts($titre);
5228
+    }
5229 5229
 
5230
-	return $titre;
5230
+    return $titre;
5231 5231
 }
5232 5232
 
5233 5233
 /**
@@ -5249,27 +5249,27 @@  discard block
 block discarded – undo
5249 5249
  * @return string
5250 5250
  */
5251 5251
 function filtre_chercher_rubrique_dist(
5252
-	$titre,
5253
-	$id_objet,
5254
-	$id_parent,
5255
-	$objet,
5256
-	$id_secteur,
5257
-	$restreint,
5258
-	$actionable = false,
5259
-	$retour_sans_cadre = false
5252
+    $titre,
5253
+    $id_objet,
5254
+    $id_parent,
5255
+    $objet,
5256
+    $id_secteur,
5257
+    $restreint,
5258
+    $actionable = false,
5259
+    $retour_sans_cadre = false
5260 5260
 ) {
5261
-	include_spip('inc/filtres_ecrire');
5261
+    include_spip('inc/filtres_ecrire');
5262 5262
 
5263
-	return chercher_rubrique(
5264
-		$titre,
5265
-		$id_objet,
5266
-		$id_parent,
5267
-		$objet,
5268
-		$id_secteur,
5269
-		$restreint,
5270
-		$actionable,
5271
-		$retour_sans_cadre
5272
-	);
5263
+    return chercher_rubrique(
5264
+        $titre,
5265
+        $id_objet,
5266
+        $id_parent,
5267
+        $objet,
5268
+        $id_secteur,
5269
+        $restreint,
5270
+        $actionable,
5271
+        $retour_sans_cadre
5272
+    );
5273 5273
 }
5274 5274
 
5275 5275
 /**
@@ -5298,56 +5298,56 @@  discard block
 block discarded – undo
5298 5298
  *     Chaîne vide si l'accès est autorisé
5299 5299
  */
5300 5300
 function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) {
5301
-	if ($ok) {
5302
-		return '';
5303
-	}
5304
-
5305
-	// Vider tous les tampons
5306
-	$level = @ob_get_level();
5307
-	while ($level--) {
5308
-		@ob_end_clean();
5309
-	}
5310
-
5311
-	include_spip('inc/headers');
5312
-
5313
-	// S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5314
-	if ($url) {
5315
-		redirige_par_entete($url, '', $statut);
5316
-	}
5317
-
5318
-	// ecriture simplifiee avec message en 3eme argument (= statut 403)
5319
-	if (!is_numeric($statut) and is_null($message)) {
5320
-		$message = $statut;
5321
-		$statut = 0;
5322
-	}
5323
-	if (!$message) {
5324
-		$message = '';
5325
-	}
5326
-	$statut = intval($statut);
5327
-
5328
-	// Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5329
-	if (test_espace_prive()) {
5330
-		if (!$statut or !in_array($statut, [404, 403])) {
5331
-			$statut = 403;
5332
-		}
5333
-		http_response_code(403);
5334
-		$echec = charger_fonction('403', 'exec');
5335
-		$echec($message);
5336
-	} else {
5337
-		// Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5338
-		if (!$statut) {
5339
-			$statut = 404;
5340
-		}
5341
-		// Dans tous les cas on modifie l'entité avec ce qui est demandé
5342
-		http_response_code($statut);
5343
-		// Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5344
-		if ($statut >= 400) {
5345
-			echo recuperer_fond("$statut", ['erreur' => $message]);
5346
-		}
5347
-	}
5348
-
5349
-
5350
-	exit;
5301
+    if ($ok) {
5302
+        return '';
5303
+    }
5304
+
5305
+    // Vider tous les tampons
5306
+    $level = @ob_get_level();
5307
+    while ($level--) {
5308
+        @ob_end_clean();
5309
+    }
5310
+
5311
+    include_spip('inc/headers');
5312
+
5313
+    // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut)
5314
+    if ($url) {
5315
+        redirige_par_entete($url, '', $statut);
5316
+    }
5317
+
5318
+    // ecriture simplifiee avec message en 3eme argument (= statut 403)
5319
+    if (!is_numeric($statut) and is_null($message)) {
5320
+        $message = $statut;
5321
+        $statut = 0;
5322
+    }
5323
+    if (!$message) {
5324
+        $message = '';
5325
+    }
5326
+    $statut = intval($statut);
5327
+
5328
+    // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404
5329
+    if (test_espace_prive()) {
5330
+        if (!$statut or !in_array($statut, [404, 403])) {
5331
+            $statut = 403;
5332
+        }
5333
+        http_response_code(403);
5334
+        $echec = charger_fonction('403', 'exec');
5335
+        $echec($message);
5336
+    } else {
5337
+        // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement
5338
+        if (!$statut) {
5339
+            $statut = 404;
5340
+        }
5341
+        // Dans tous les cas on modifie l'entité avec ce qui est demandé
5342
+        http_response_code($statut);
5343
+        // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom
5344
+        if ($statut >= 400) {
5345
+            echo recuperer_fond("$statut", ['erreur' => $message]);
5346
+        }
5347
+    }
5348
+
5349
+
5350
+    exit;
5351 5351
 }
5352 5352
 
5353 5353
 /**
@@ -5358,11 +5358,11 @@  discard block
 block discarded – undo
5358 5358
  * @return string
5359 5359
  */
5360 5360
 function filtre_compacte_dist($source, $format = null) {
5361
-	if (function_exists('minifier')) {
5362
-		return minifier($source, $format);
5363
-	}
5361
+    if (function_exists('minifier')) {
5362
+        return minifier($source, $format);
5363
+    }
5364 5364
 
5365
-	return $source;
5365
+    return $source;
5366 5366
 }
5367 5367
 
5368 5368
 
@@ -5374,32 +5374,32 @@  discard block
 block discarded – undo
5374 5374
  * @return string
5375 5375
  */
5376 5376
 function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string {
5377
-	$passe ??= '';
5378
-	$l = strlen($passe);
5379
-
5380
-	if ($l <= 8 or !$afficher_partiellement) {
5381
-		if (!$l) {
5382
-			return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5383
-		}
5384
-		return str_pad('', $afficher_partiellement ? $l : 16, '*');
5385
-	}
5386
-
5387
-	if (is_null($portion_pourcent)) {
5388
-		if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5389
-			define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5390
-		}
5391
-		$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5392
-	}
5393
-	if ($portion_pourcent >= 100) {
5394
-		return $passe;
5395
-	}
5396
-	$e = intval(ceil($l * $portion_pourcent / 100 / 2));
5397
-	$e = max($e, 0);
5398
-	$mid = str_pad('', $l - 2 * $e, '*');
5399
-	if ($e > 0 and strlen($mid) > 8) {
5400
-		$mid = '***...***';
5401
-	}
5402
-	return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5377
+    $passe ??= '';
5378
+    $l = strlen($passe);
5379
+
5380
+    if ($l <= 8 or !$afficher_partiellement) {
5381
+        if (!$l) {
5382
+            return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
5383
+        }
5384
+        return str_pad('', $afficher_partiellement ? $l : 16, '*');
5385
+    }
5386
+
5387
+    if (is_null($portion_pourcent)) {
5388
+        if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
5389
+            define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
5390
+        }
5391
+        $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
5392
+    }
5393
+    if ($portion_pourcent >= 100) {
5394
+        return $passe;
5395
+    }
5396
+    $e = intval(ceil($l * $portion_pourcent / 100 / 2));
5397
+    $e = max($e, 0);
5398
+    $mid = str_pad('', $l - 2 * $e, '*');
5399
+    if ($e > 0 and strlen($mid) > 8) {
5400
+        $mid = '***...***';
5401
+    }
5402
+    return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : '');
5403 5403
 }
5404 5404
 
5405 5405
 
@@ -5420,64 +5420,64 @@  discard block
 block discarded – undo
5420 5420
  */
5421 5421
 function identifiant_slug($texte, $type = '', $options = []) {
5422 5422
 
5423
-	$original = $texte;
5424
-	$separateur = ($options['separateur'] ?? '_');
5425
-	$longueur_maxi = ($options['longueur_maxi'] ?? 60);
5426
-	$longueur_mini = ($options['longueur_mini'] ?? 0);
5423
+    $original = $texte;
5424
+    $separateur = ($options['separateur'] ?? '_');
5425
+    $longueur_maxi = ($options['longueur_maxi'] ?? 60);
5426
+    $longueur_mini = ($options['longueur_mini'] ?? 0);
5427 5427
 
5428
-	if (!function_exists('translitteration')) {
5429
-		include_spip('inc/charsets');
5430
-	}
5428
+    if (!function_exists('translitteration')) {
5429
+        include_spip('inc/charsets');
5430
+    }
5431 5431
 
5432
-	// pas de balise html
5433
-	if (strpos($texte, '<') !== false) {
5434
-		$texte = strip_tags($texte);
5435
-	}
5436
-	if (strpos($texte, '&') !== false) {
5437
-		$texte = unicode2charset($texte);
5438
-	}
5439
-	// On enlève les espaces indésirables
5440
-	$texte = trim($texte);
5432
+    // pas de balise html
5433
+    if (strpos($texte, '<') !== false) {
5434
+        $texte = strip_tags($texte);
5435
+    }
5436
+    if (strpos($texte, '&') !== false) {
5437
+        $texte = unicode2charset($texte);
5438
+    }
5439
+    // On enlève les espaces indésirables
5440
+    $texte = trim($texte);
5441 5441
 
5442
-	// On enlève les accents et cie
5443
-	$texte = translitteration($texte);
5442
+    // On enlève les accents et cie
5443
+    $texte = translitteration($texte);
5444 5444
 
5445
-	// On remplace tout ce qui n'est pas un mot par un séparateur
5446
-	$texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5445
+    // On remplace tout ce qui n'est pas un mot par un séparateur
5446
+    $texte = preg_replace(',[\W_]+,ms', $separateur, $texte);
5447 5447
 
5448
-	// nettoyer les doubles occurences du separateur si besoin
5449
-	while (strpos($texte, (string) "$separateur$separateur") !== false) {
5450
-		$texte = str_replace("$separateur$separateur", $separateur, $texte);
5451
-	}
5448
+    // nettoyer les doubles occurences du separateur si besoin
5449
+    while (strpos($texte, (string) "$separateur$separateur") !== false) {
5450
+        $texte = str_replace("$separateur$separateur", $separateur, $texte);
5451
+    }
5452 5452
 
5453
-	// pas de separateur au debut ni a la fin
5454
-	$texte = trim($texte, $separateur);
5453
+    // pas de separateur au debut ni a la fin
5454
+    $texte = trim($texte, $separateur);
5455 5455
 
5456
-	// en minuscules
5457
-	$texte = strtolower($texte);
5456
+    // en minuscules
5457
+    $texte = strtolower($texte);
5458 5458
 
5459
-	switch ($type) {
5460
-		case 'class':
5461
-		case 'id':
5462
-		case 'anchor':
5463
-			if (preg_match(',^\d,', $texte)) {
5464
-				$texte = substr($type, 0, 1) . $texte;
5465
-			}
5466
-	}
5459
+    switch ($type) {
5460
+        case 'class':
5461
+        case 'id':
5462
+        case 'anchor':
5463
+            if (preg_match(',^\d,', $texte)) {
5464
+                $texte = substr($type, 0, 1) . $texte;
5465
+            }
5466
+    }
5467 5467
 
5468
-	if (strlen($texte) > $longueur_maxi) {
5469
-		$texte = substr($texte, 0, $longueur_maxi);
5470
-	}
5468
+    if (strlen($texte) > $longueur_maxi) {
5469
+        $texte = substr($texte, 0, $longueur_maxi);
5470
+    }
5471 5471
 
5472
-	if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5473
-		if (preg_match(',^\d,', $texte)) {
5474
-			$texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5475
-		}
5476
-		$texte .= $separateur . md5($original);
5477
-		$texte = substr($texte, 0, $longueur_mini);
5478
-	}
5472
+    if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) {
5473
+        if (preg_match(',^\d,', $texte)) {
5474
+            $texte = ($type ? substr($type, 0, 1) : 's') . $texte;
5475
+        }
5476
+        $texte .= $separateur . md5($original);
5477
+        $texte = substr($texte, 0, $longueur_mini);
5478
+    }
5479 5479
 
5480
-	return $texte;
5480
+    return $texte;
5481 5481
 }
5482 5482
 
5483 5483
 
@@ -5498,11 +5498,11 @@  discard block
 block discarded – undo
5498 5498
  * @exemple `<:info_maximum|label_nettoyer:>`
5499 5499
  */
5500 5500
 function label_nettoyer(string $text, bool $ucfirst = true): string {
5501
-	$label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5502
-	if ($ucfirst) {
5503
-		$label = spip_ucfirst($label);
5504
-	}
5505
-	return $label;
5501
+    $label = preg_replace('#([\s:]|\&nbsp;)+$#u', '', $text);
5502
+    if ($ucfirst) {
5503
+        $label = spip_ucfirst($label);
5504
+    }
5505
+    return $label;
5506 5506
 }
5507 5507
 
5508 5508
 /**
@@ -5515,8 +5515,8 @@  discard block
 block discarded – undo
5515 5515
  * @exemple `<:info_maximum|label_ponctuer:>`
5516 5516
  */
5517 5517
 function label_ponctuer(string $text, bool $ucfirst = true): string {
5518
-	$label = label_nettoyer($text, $ucfirst);
5519
-	return _T('label_ponctuer', ['label' => $label]);
5518
+    $label = label_nettoyer($text, $ucfirst);
5519
+    return _T('label_ponctuer', ['label' => $label]);
5520 5520
 }
5521 5521
 
5522 5522
 
@@ -5529,19 +5529,19 @@  discard block
 block discarded – undo
5529 5529
  * @return array
5530 5530
  */
5531 5531
 function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) {
5532
-	if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5533
-		return [];
5534
-	}
5532
+    if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) {
5533
+        return [];
5534
+    }
5535 5535
 
5536
-	// compatibilite signature inversee
5537
-	if (is_numeric($objet) and !is_numeric($id_objet)) {
5538
-		[$objet, $id_objet] = [$id_objet, $objet];
5539
-	}
5536
+    // compatibilite signature inversee
5537
+    if (is_numeric($objet) and !is_numeric($id_objet)) {
5538
+        [$objet, $id_objet] = [$id_objet, $objet];
5539
+    }
5540 5540
 
5541
-	if (!function_exists($fonction)) {
5542
-		include_spip('base/objets');
5543
-	}
5544
-	return $fonction($objet, $id_objet);
5541
+    if (!function_exists($fonction)) {
5542
+        include_spip('base/objets');
5543
+    }
5544
+    return $fonction($objet, $id_objet);
5545 5545
 }
5546 5546
 
5547 5547
 
@@ -5556,7 +5556,7 @@  discard block
 block discarded – undo
5556 5556
  * @return array
5557 5557
  */
5558 5558
 function filtre_objet_lister_parents_dist($objet, $id_objet) {
5559
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5559
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents');
5560 5560
 }
5561 5561
 
5562 5562
 /**
@@ -5570,7 +5570,7 @@  discard block
 block discarded – undo
5570 5570
  * @return array
5571 5571
  */
5572 5572
 function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) {
5573
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5573
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type');
5574 5574
 }
5575 5575
 
5576 5576
 /**
@@ -5584,7 +5584,7 @@  discard block
 block discarded – undo
5584 5584
  * @return array
5585 5585
  */
5586 5586
 function filtre_objet_lister_enfants_dist($objet, $id_objet) {
5587
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5587
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants');
5588 5588
 }
5589 5589
 
5590 5590
 /**
@@ -5598,5 +5598,5 @@  discard block
 block discarded – undo
5598 5598
  * @return array
5599 5599
  */
5600 5600
 function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) {
5601
-	return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5601
+    return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type');
5602 5602
 }
Please login to merge, or discard this patch.