Completed
Push — master ( a3cb85...dd34e9 )
by cam
01:07
created
ecrire/inc/filtres_images_mini.php 1 patch
Indentation   +316 added lines, -316 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_images_lib_mini'); // par precaution
24 24
 
@@ -31,161 +31,161 @@  discard block
 block discarded – undo
31 31
  *    Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé
32 32
  */
33 33
 function couleur_html_to_hex($couleur) {
34
-	$couleurs_html = [
35
-		'aliceblue' => 'F0F8FF',
36
-		'antiquewhite' => 'FAEBD7',
37
-		'aqua' => '00FFFF',
38
-		'aquamarine' => '7FFFD4',
39
-		'azure' => 'F0FFFF',
40
-		'beige' => 'F5F5DC',
41
-		'bisque' => 'FFE4C4',
42
-		'black' => '000000',
43
-		'blanchedalmond' => 'FFEBCD',
44
-		'blue' => '0000FF',
45
-		'blueviolet' => '8A2BE2',
46
-		'brown' => 'A52A2A',
47
-		'burlywood' => 'DEB887',
48
-		'cadetblue' => '5F9EA0',
49
-		'chartreuse' => '7FFF00',
50
-		'chocolate' => 'D2691E',
51
-		'coral' => 'FF7F50',
52
-		'cornflowerblue' => '6495ED',
53
-		'cornsilk' => 'FFF8DC',
54
-		'crimson' => 'DC143C',
55
-		'cyan' => '00FFFF',
56
-		'darkblue' => '00008B',
57
-		'darkcyan' => '008B8B',
58
-		'darkgoldenrod' => 'B8860B',
59
-		'darkgray' => 'A9A9A9',
60
-		'darkgreen' => '006400',
61
-		'darkgrey' => 'A9A9A9',
62
-		'darkkhaki' => 'BDB76B',
63
-		'darkmagenta' => '8B008B',
64
-		'darkolivegreen' => '556B2F',
65
-		'darkorange' => 'FF8C00',
66
-		'darkorchid' => '9932CC',
67
-		'darkred' => '8B0000',
68
-		'darksalmon' => 'E9967A',
69
-		'darkseagreen' => '8FBC8F',
70
-		'darkslateblue' => '483D8B',
71
-		'darkslategray' => '2F4F4F',
72
-		'darkslategrey' => '2F4F4F',
73
-		'darkturquoise' => '00CED1',
74
-		'darkviolet' => '9400D3',
75
-		'deeppink' => 'FF1493',
76
-		'deepskyblue' => '00BFFF',
77
-		'dimgray' => '696969',
78
-		'dimgrey' => '696969',
79
-		'dodgerblue' => '1E90FF',
80
-		'firebrick' => 'B22222',
81
-		'floralwhite' => 'FFFAF0',
82
-		'forestgreen' => '228B22',
83
-		'fuchsia' => 'FF00FF',
84
-		'gainsboro' => 'DCDCDC',
85
-		'ghostwhite' => 'F8F8FF',
86
-		'gold' => 'FFD700',
87
-		'goldenrod' => 'DAA520',
88
-		'gray' => '808080',
89
-		'green' => '008000',
90
-		'greenyellow' => 'ADFF2F',
91
-		'grey' => '808080',
92
-		'honeydew' => 'F0FFF0',
93
-		'hotpink' => 'FF69B4',
94
-		'indianred' => 'CD5C5C',
95
-		'indigo' => '4B0082',
96
-		'ivory' => 'FFFFF0',
97
-		'khaki' => 'F0E68C',
98
-		'lavender' => 'E6E6FA',
99
-		'lavenderblush' => 'FFF0F5',
100
-		'lawngreen' => '7CFC00',
101
-		'lemonchiffon' => 'FFFACD',
102
-		'lightblue' => 'ADD8E6',
103
-		'lightcoral' => 'F08080',
104
-		'lightcyan' => 'E0FFFF',
105
-		'lightgoldenrodyellow' => 'FAFAD2',
106
-		'lightgray' => 'D3D3D3',
107
-		'lightgreen' => '90EE90',
108
-		'lightgrey' => 'D3D3D3',
109
-		'lightpink' => 'FFB6C1',
110
-		'lightsalmon' => 'FFA07A',
111
-		'lightseagreen' => '20B2AA',
112
-		'lightskyblue' => '87CEFA',
113
-		'lightslategray' => '778899',
114
-		'lightslategrey' => '778899',
115
-		'lightsteelblue' => 'B0C4DE',
116
-		'lightyellow' => 'FFFFE0',
117
-		'lime' => '00FF00',
118
-		'limegreen' => '32CD32',
119
-		'linen' => 'FAF0E6',
120
-		'magenta' => 'FF00FF',
121
-		'maroon' => '800000',
122
-		'mediumaquamarine' => '66CDAA',
123
-		'mediumblue' => '0000CD',
124
-		'mediumorchid' => 'BA55D3',
125
-		'mediumpurple' => '9370DB',
126
-		'mediumseagreen' => '3CB371',
127
-		'mediumslateblue' => '7B68EE',
128
-		'mediumspringgreen' => '00FA9A',
129
-		'mediumturquoise' => '48D1CC',
130
-		'mediumvioletred' => 'C71585',
131
-		'midnightblue' => '191970',
132
-		'mintcream' => 'F5FFFA',
133
-		'mistyrose' => 'FFE4E1',
134
-		'moccasin' => 'FFE4B5',
135
-		'navajowhite' => 'FFDEAD',
136
-		'navy' => '000080',
137
-		'oldlace' => 'FDF5E6',
138
-		'olive' => '808000',
139
-		'olivedrab' => '6B8E23',
140
-		'orange' => 'FFA500',
141
-		'orangered' => 'FF4500',
142
-		'orchid' => 'DA70D6',
143
-		'palegoldenrod' => 'EEE8AA',
144
-		'palegreen' => '98FB98',
145
-		'paleturquoise' => 'AFEEEE',
146
-		'palevioletred' => 'DB7093',
147
-		'papayawhip' => 'FFEFD5',
148
-		'peachpuff' => 'FFDAB9',
149
-		'peru' => 'CD853F',
150
-		'pink' => 'FFC0CB',
151
-		'plum' => 'DDA0DD',
152
-		'powderblue' => 'B0E0E6',
153
-		'purple' => '800080',
154
-		'rebeccapurple' => '663399',
155
-		'red' => 'FF0000',
156
-		'rosybrown' => 'BC8F8F',
157
-		'royalblue' => '4169E1',
158
-		'saddlebrown' => '8B4513',
159
-		'salmon' => 'FA8072',
160
-		'sandybrown' => 'F4A460',
161
-		'seagreen' => '2E8B57',
162
-		'seashell' => 'FFF5EE',
163
-		'sienna' => 'A0522D',
164
-		'silver' => 'C0C0C0',
165
-		'skyblue' => '87CEEB',
166
-		'slateblue' => '6A5ACD',
167
-		'slategray' => '708090',
168
-		'slategrey' => '708090',
169
-		'snow' => 'FFFAFA',
170
-		'springgreen' => '00FF7F',
171
-		'steelblue' => '4682B4',
172
-		'tan' => 'D2B48C',
173
-		'teal' => '008080',
174
-		'thistle' => 'D8BFD8',
175
-		'tomato' => 'FF6347',
176
-		'turquoise' => '40E0D0',
177
-		'violet' => 'EE82EE',
178
-		'wheat' => 'F5DEB3',
179
-		'white' => 'FFFFFF',
180
-		'whitesmoke' => 'F5F5F5',
181
-		'yellow' => 'FFFF00',
182
-		'yellowgreen' => '9ACD32',
183
-	];
184
-	if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) {
185
-		return $couleurs_html[$lc];
186
-	}
187
-
188
-	return $couleur;
34
+    $couleurs_html = [
35
+        'aliceblue' => 'F0F8FF',
36
+        'antiquewhite' => 'FAEBD7',
37
+        'aqua' => '00FFFF',
38
+        'aquamarine' => '7FFFD4',
39
+        'azure' => 'F0FFFF',
40
+        'beige' => 'F5F5DC',
41
+        'bisque' => 'FFE4C4',
42
+        'black' => '000000',
43
+        'blanchedalmond' => 'FFEBCD',
44
+        'blue' => '0000FF',
45
+        'blueviolet' => '8A2BE2',
46
+        'brown' => 'A52A2A',
47
+        'burlywood' => 'DEB887',
48
+        'cadetblue' => '5F9EA0',
49
+        'chartreuse' => '7FFF00',
50
+        'chocolate' => 'D2691E',
51
+        'coral' => 'FF7F50',
52
+        'cornflowerblue' => '6495ED',
53
+        'cornsilk' => 'FFF8DC',
54
+        'crimson' => 'DC143C',
55
+        'cyan' => '00FFFF',
56
+        'darkblue' => '00008B',
57
+        'darkcyan' => '008B8B',
58
+        'darkgoldenrod' => 'B8860B',
59
+        'darkgray' => 'A9A9A9',
60
+        'darkgreen' => '006400',
61
+        'darkgrey' => 'A9A9A9',
62
+        'darkkhaki' => 'BDB76B',
63
+        'darkmagenta' => '8B008B',
64
+        'darkolivegreen' => '556B2F',
65
+        'darkorange' => 'FF8C00',
66
+        'darkorchid' => '9932CC',
67
+        'darkred' => '8B0000',
68
+        'darksalmon' => 'E9967A',
69
+        'darkseagreen' => '8FBC8F',
70
+        'darkslateblue' => '483D8B',
71
+        'darkslategray' => '2F4F4F',
72
+        'darkslategrey' => '2F4F4F',
73
+        'darkturquoise' => '00CED1',
74
+        'darkviolet' => '9400D3',
75
+        'deeppink' => 'FF1493',
76
+        'deepskyblue' => '00BFFF',
77
+        'dimgray' => '696969',
78
+        'dimgrey' => '696969',
79
+        'dodgerblue' => '1E90FF',
80
+        'firebrick' => 'B22222',
81
+        'floralwhite' => 'FFFAF0',
82
+        'forestgreen' => '228B22',
83
+        'fuchsia' => 'FF00FF',
84
+        'gainsboro' => 'DCDCDC',
85
+        'ghostwhite' => 'F8F8FF',
86
+        'gold' => 'FFD700',
87
+        'goldenrod' => 'DAA520',
88
+        'gray' => '808080',
89
+        'green' => '008000',
90
+        'greenyellow' => 'ADFF2F',
91
+        'grey' => '808080',
92
+        'honeydew' => 'F0FFF0',
93
+        'hotpink' => 'FF69B4',
94
+        'indianred' => 'CD5C5C',
95
+        'indigo' => '4B0082',
96
+        'ivory' => 'FFFFF0',
97
+        'khaki' => 'F0E68C',
98
+        'lavender' => 'E6E6FA',
99
+        'lavenderblush' => 'FFF0F5',
100
+        'lawngreen' => '7CFC00',
101
+        'lemonchiffon' => 'FFFACD',
102
+        'lightblue' => 'ADD8E6',
103
+        'lightcoral' => 'F08080',
104
+        'lightcyan' => 'E0FFFF',
105
+        'lightgoldenrodyellow' => 'FAFAD2',
106
+        'lightgray' => 'D3D3D3',
107
+        'lightgreen' => '90EE90',
108
+        'lightgrey' => 'D3D3D3',
109
+        'lightpink' => 'FFB6C1',
110
+        'lightsalmon' => 'FFA07A',
111
+        'lightseagreen' => '20B2AA',
112
+        'lightskyblue' => '87CEFA',
113
+        'lightslategray' => '778899',
114
+        'lightslategrey' => '778899',
115
+        'lightsteelblue' => 'B0C4DE',
116
+        'lightyellow' => 'FFFFE0',
117
+        'lime' => '00FF00',
118
+        'limegreen' => '32CD32',
119
+        'linen' => 'FAF0E6',
120
+        'magenta' => 'FF00FF',
121
+        'maroon' => '800000',
122
+        'mediumaquamarine' => '66CDAA',
123
+        'mediumblue' => '0000CD',
124
+        'mediumorchid' => 'BA55D3',
125
+        'mediumpurple' => '9370DB',
126
+        'mediumseagreen' => '3CB371',
127
+        'mediumslateblue' => '7B68EE',
128
+        'mediumspringgreen' => '00FA9A',
129
+        'mediumturquoise' => '48D1CC',
130
+        'mediumvioletred' => 'C71585',
131
+        'midnightblue' => '191970',
132
+        'mintcream' => 'F5FFFA',
133
+        'mistyrose' => 'FFE4E1',
134
+        'moccasin' => 'FFE4B5',
135
+        'navajowhite' => 'FFDEAD',
136
+        'navy' => '000080',
137
+        'oldlace' => 'FDF5E6',
138
+        'olive' => '808000',
139
+        'olivedrab' => '6B8E23',
140
+        'orange' => 'FFA500',
141
+        'orangered' => 'FF4500',
142
+        'orchid' => 'DA70D6',
143
+        'palegoldenrod' => 'EEE8AA',
144
+        'palegreen' => '98FB98',
145
+        'paleturquoise' => 'AFEEEE',
146
+        'palevioletred' => 'DB7093',
147
+        'papayawhip' => 'FFEFD5',
148
+        'peachpuff' => 'FFDAB9',
149
+        'peru' => 'CD853F',
150
+        'pink' => 'FFC0CB',
151
+        'plum' => 'DDA0DD',
152
+        'powderblue' => 'B0E0E6',
153
+        'purple' => '800080',
154
+        'rebeccapurple' => '663399',
155
+        'red' => 'FF0000',
156
+        'rosybrown' => 'BC8F8F',
157
+        'royalblue' => '4169E1',
158
+        'saddlebrown' => '8B4513',
159
+        'salmon' => 'FA8072',
160
+        'sandybrown' => 'F4A460',
161
+        'seagreen' => '2E8B57',
162
+        'seashell' => 'FFF5EE',
163
+        'sienna' => 'A0522D',
164
+        'silver' => 'C0C0C0',
165
+        'skyblue' => '87CEEB',
166
+        'slateblue' => '6A5ACD',
167
+        'slategray' => '708090',
168
+        'slategrey' => '708090',
169
+        'snow' => 'FFFAFA',
170
+        'springgreen' => '00FF7F',
171
+        'steelblue' => '4682B4',
172
+        'tan' => 'D2B48C',
173
+        'teal' => '008080',
174
+        'thistle' => 'D8BFD8',
175
+        'tomato' => 'FF6347',
176
+        'turquoise' => '40E0D0',
177
+        'violet' => 'EE82EE',
178
+        'wheat' => 'F5DEB3',
179
+        'white' => 'FFFFFF',
180
+        'whitesmoke' => 'F5F5F5',
181
+        'yellow' => 'FFFF00',
182
+        'yellowgreen' => '9ACD32',
183
+    ];
184
+    if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) {
185
+        return $couleurs_html[$lc];
186
+    }
187
+
188
+    return $couleur;
189 189
 }
190 190
 
191 191
 /**
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
  * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée
202 202
  */
203 203
 function couleur_hex_to_hsl($couleur, $format = null) {
204
-	$hsl = _couleur_hex_to_hsl($couleur);
205
-	$hsl = [
206
-		'h' => round($hsl['h'] * 360),
207
-		's' => round($hsl['s'] * 100) . '%',
208
-		'l' => round($hsl['l'] * 100) . '%'
209
-	];
210
-	if ($format === null) {
211
-		return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})";
212
-	}
213
-	return str_replace(array_keys($hsl), $hsl, $format);
204
+    $hsl = _couleur_hex_to_hsl($couleur);
205
+    $hsl = [
206
+        'h' => round($hsl['h'] * 360),
207
+        's' => round($hsl['s'] * 100) . '%',
208
+        'l' => round($hsl['l'] * 100) . '%'
209
+    ];
210
+    if ($format === null) {
211
+        return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})";
212
+    }
213
+    return str_replace(array_keys($hsl), $hsl, $format);
214 214
 }
215 215
 
216 216
 
@@ -227,16 +227,16 @@  discard block
 block discarded – undo
227 227
  * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée
228 228
  */
229 229
 function couleur_hex_to_rgb($couleur, $format = null) {
230
-	$rgb = _couleur_hex_to_dec($couleur);
231
-	$rgb = [
232
-		'r' => $rgb['red'],
233
-		'g' => $rgb['green'],
234
-		'b' => $rgb['blue'],
235
-	];
236
-	if ($format === null) {
237
-		return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})";
238
-	}
239
-	return str_replace(array_keys($rgb), $rgb, $format);
230
+    $rgb = _couleur_hex_to_dec($couleur);
231
+    $rgb = [
232
+        'r' => $rgb['red'],
233
+        'g' => $rgb['green'],
234
+        'b' => $rgb['blue'],
235
+    ];
236
+    if ($format === null) {
237
+        return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})";
238
+    }
239
+    return str_replace(array_keys($rgb), $rgb, $format);
240 240
 }
241 241
 
242 242
 /**
@@ -252,15 +252,15 @@  discard block
 block discarded – undo
252 252
  *    Code hexadécimal de la couleur plus foncée
253 253
  */
254 254
 function couleur_foncer($couleur, $coeff = 0.5) {
255
-	$couleurs = _couleur_hex_to_dec($couleur);
255
+    $couleurs = _couleur_hex_to_dec($couleur);
256 256
 
257
-	$red = $couleurs['red'] - round(($couleurs['red']) * $coeff);
258
-	$green = $couleurs['green'] - round(($couleurs['green']) * $coeff);
259
-	$blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff);
257
+    $red = $couleurs['red'] - round(($couleurs['red']) * $coeff);
258
+    $green = $couleurs['green'] - round(($couleurs['green']) * $coeff);
259
+    $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff);
260 260
 
261
-	$couleur = _couleur_dec_to_hex($red, $green, $blue);
261
+    $couleur = _couleur_dec_to_hex($red, $green, $blue);
262 262
 
263
-	return $couleur;
263
+    return $couleur;
264 264
 }
265 265
 
266 266
 /**
@@ -276,15 +276,15 @@  discard block
 block discarded – undo
276 276
  *    Code hexadécimal de la couleur éclaircie
277 277
  */
278 278
 function couleur_eclaircir($couleur, $coeff = 0.5) {
279
-	$couleurs = _couleur_hex_to_dec($couleur);
279
+    $couleurs = _couleur_hex_to_dec($couleur);
280 280
 
281
-	$red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff);
282
-	$green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff);
283
-	$blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff);
281
+    $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff);
282
+    $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff);
283
+    $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff);
284 284
 
285
-	$couleur = _couleur_dec_to_hex($red, $green, $blue);
285
+    $couleur = _couleur_dec_to_hex($red, $green, $blue);
286 286
 
287
-	return $couleur;
287
+    return $couleur;
288 288
 }
289 289
 
290 290
 /**
@@ -307,28 +307,28 @@  discard block
 block discarded – undo
307 307
  *    Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas
308 308
  */
309 309
 function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) {
310
-	if (!$img) {
311
-		return $img;
312
-	}
313
-	[$h, $l] = taille_image($img);
314
-	$select = true;
315
-	if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) {
316
-		$select = false;
317
-	}
318
-
319
-	$class = extraire_attribut($img, 'class');
320
-	$p = strpos($class, 'filtre_inactif');
321
-	if (($select == false) and ($p === false)) {
322
-		$class .= ' filtre_inactif';
323
-		$img = inserer_attribut($img, 'class', $class);
324
-	}
325
-	if (($select == true) and ($p !== false)) {
326
-		// no_image_filtrer : historique, a virer
327
-		$class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class);
328
-		$img = inserer_attribut($img, 'class', $class);
329
-	}
330
-
331
-	return $img;
310
+    if (!$img) {
311
+        return $img;
312
+    }
313
+    [$h, $l] = taille_image($img);
314
+    $select = true;
315
+    if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) {
316
+        $select = false;
317
+    }
318
+
319
+    $class = extraire_attribut($img, 'class');
320
+    $p = strpos($class, 'filtre_inactif');
321
+    if (($select == false) and ($p === false)) {
322
+        $class .= ' filtre_inactif';
323
+        $img = inserer_attribut($img, 'class', $class);
324
+    }
325
+    if (($select == true) and ($p !== false)) {
326
+        // no_image_filtrer : historique, a virer
327
+        $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class);
328
+        $img = inserer_attribut($img, 'class', $class);
329
+    }
330
+
331
+    return $img;
332 332
 }
333 333
 
334 334
 /**
@@ -376,45 +376,45 @@  discard block
 block discarded – undo
376 376
  *     Code HTML de l'image ou du texte.
377 377
  **/
378 378
 function image_passe_partout(
379
-	$img,
380
-	$taille_x = -1,
381
-	$taille_y = -1,
382
-	$force = false,
383
-	$cherche_image = false,
384
-	$process = 'AUTO'
379
+    $img,
380
+    $taille_x = -1,
381
+    $taille_y = -1,
382
+    $force = false,
383
+    $cherche_image = false,
384
+    $process = 'AUTO'
385 385
 ) {
386
-	// PHP 7+ type hint
387
-	$img = (string)$img;
388
-	$taille_x = (int)$taille_x;
389
-	$taille_y = (int)$taille_y;
390
-	$force = (bool)$force;
391
-	$process = (string)$process;
392
-
393
-	if (!$img) {
394
-		return '';
395
-	}
396
-	[$hauteur, $largeur] = taille_image($img);
397
-	if ($taille_x === -1) {
398
-		$taille_x = $GLOBALS['meta']['taille_preview'] ?? 150;
399
-	}
400
-	if ($taille_y === -1) {
401
-		$taille_y = $taille_x;
402
-	}
403
-
404
-	if ($taille_x === 0 and $taille_y > 0) {
405
-		$taille_x = 1;
406
-	} # {0,300} -> c'est 300 qui compte
407
-	elseif ($taille_x > 0 and $taille_y === 0) {
408
-		$taille_y = 1;
409
-	} # {300,0} -> c'est 300 qui compte
410
-	elseif ($taille_x == 0 and $taille_y === 0) {
411
-		return '';
412
-	}
413
-
414
-	[$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y);
415
-	$fonction = ['image_passe_partout', func_get_args()];
416
-
417
-	return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process);
386
+    // PHP 7+ type hint
387
+    $img = (string)$img;
388
+    $taille_x = (int)$taille_x;
389
+    $taille_y = (int)$taille_y;
390
+    $force = (bool)$force;
391
+    $process = (string)$process;
392
+
393
+    if (!$img) {
394
+        return '';
395
+    }
396
+    [$hauteur, $largeur] = taille_image($img);
397
+    if ($taille_x === -1) {
398
+        $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150;
399
+    }
400
+    if ($taille_y === -1) {
401
+        $taille_y = $taille_x;
402
+    }
403
+
404
+    if ($taille_x === 0 and $taille_y > 0) {
405
+        $taille_x = 1;
406
+    } # {0,300} -> c'est 300 qui compte
407
+    elseif ($taille_x > 0 and $taille_y === 0) {
408
+        $taille_y = 1;
409
+    } # {300,0} -> c'est 300 qui compte
410
+    elseif ($taille_x == 0 and $taille_y === 0) {
411
+        return '';
412
+    }
413
+
414
+    [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y);
415
+    $fonction = ['image_passe_partout', func_get_args()];
416
+
417
+    return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process);
418 418
 }
419 419
 
420 420
 /**
@@ -457,44 +457,44 @@  discard block
 block discarded – undo
457 457
  *     Code HTML de l'image ou du texte.
458 458
  **/
459 459
 function image_reduire(
460
-	$img,
461
-	$taille = -1,
462
-	$taille_y = -1,
463
-	$force = false,
464
-	$cherche_image = false,
465
-	$process = 'AUTO'
460
+    $img,
461
+    $taille = -1,
462
+    $taille_y = -1,
463
+    $force = false,
464
+    $cherche_image = false,
465
+    $process = 'AUTO'
466 466
 ) {
467
-	// PHP 7+ type hint
468
-	$img = (string)$img;
469
-	$taille = (int)$taille;
470
-	$taille_y = (int)$taille_y;
471
-	$force = (bool)$force;
472
-	$process = (string)$process;
473
-
474
-	// Determiner la taille x,y maxi
475
-	// prendre le reglage de previsu par defaut
476
-	if ($taille === -1) {
477
-		$taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview']))
478
-			? intval($GLOBALS['meta']['taille_preview'])
479
-			: 150;
480
-	}
481
-	if ($taille_y === -1) {
482
-		$taille_y = $taille;
483
-	}
484
-
485
-	if ($taille === 0 and $taille_y > 0) {
486
-		$taille = 10000;
487
-	} # {0,300} -> c'est 300 qui compte
488
-	elseif ($taille > 0 and $taille_y === 0) {
489
-		$taille_y = 10000;
490
-	} # {300,0} -> c'est 300 qui compte
491
-	elseif ($taille == 0 and $taille_y === 0) {
492
-		return '';
493
-	}
494
-
495
-	$fonction = ['image_reduire', func_get_args()];
496
-
497
-	return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process);
467
+    // PHP 7+ type hint
468
+    $img = (string)$img;
469
+    $taille = (int)$taille;
470
+    $taille_y = (int)$taille_y;
471
+    $force = (bool)$force;
472
+    $process = (string)$process;
473
+
474
+    // Determiner la taille x,y maxi
475
+    // prendre le reglage de previsu par defaut
476
+    if ($taille === -1) {
477
+        $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview']))
478
+            ? intval($GLOBALS['meta']['taille_preview'])
479
+            : 150;
480
+    }
481
+    if ($taille_y === -1) {
482
+        $taille_y = $taille;
483
+    }
484
+
485
+    if ($taille === 0 and $taille_y > 0) {
486
+        $taille = 10000;
487
+    } # {0,300} -> c'est 300 qui compte
488
+    elseif ($taille > 0 and $taille_y === 0) {
489
+        $taille_y = 10000;
490
+    } # {300,0} -> c'est 300 qui compte
491
+    elseif ($taille == 0 and $taille_y === 0) {
492
+        return '';
493
+    }
494
+
495
+    $fonction = ['image_reduire', func_get_args()];
496
+
497
+    return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process);
498 498
 }
499 499
 
500 500
 /**
@@ -505,16 +505,16 @@  discard block
 block discarded – undo
505 505
  *
506 506
  **/
507 507
 function image_recadre_avec_fallback(
508
-	$im,
509
-	$width,
510
-	$height = '-',
511
-	$position = 'focus',
512
-	$background_color = 'white'
508
+    $im,
509
+    $width,
510
+    $height = '-',
511
+    $position = 'focus',
512
+    $background_color = 'white'
513 513
 ) {
514
-	if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') {
515
-		return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height);
516
-	} else { return image_passe_partout($im, $width, $height);
517
-	}
514
+    if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') {
515
+        return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height);
516
+    } else { return image_passe_partout($im, $width, $height);
517
+    }
518 518
 }
519 519
 
520 520
 /**
@@ -532,25 +532,25 @@  discard block
 block discarded – undo
532 532
  *     Code HTML de l'image ou du texte.
533 533
  **/
534 534
 function image_reduire_par($img, $val = 1, $force = false) {
535
-	// PHP 7+ type hint
536
-	$img = (string)$img;
537
-	$val = (int)$val;
538
-	$force = (bool)$force;
535
+    // PHP 7+ type hint
536
+    $img = (string)$img;
537
+    $val = (int)$val;
538
+    $force = (bool)$force;
539 539
 
540
-	[$hauteur, $largeur] = taille_image($img);
540
+    [$hauteur, $largeur] = taille_image($img);
541 541
 
542
-	$l = round($largeur / $val);
543
-	$h = round($hauteur / $val);
542
+    $l = round($largeur / $val);
543
+    $h = round($hauteur / $val);
544 544
 
545
-	if ($l > $h) {
546
-		$h = 0;
547
-	} else {
548
-		$l = 0;
549
-	}
545
+    if ($l > $h) {
546
+        $h = 0;
547
+    } else {
548
+        $l = 0;
549
+    }
550 550
 
551
-	$img = image_reduire($img, $l, $h, $force);
551
+    $img = image_reduire($img, $l, $h, $force);
552 552
 
553
-	return $img;
553
+    return $img;
554 554
 }
555 555
 
556 556
 /**
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
  *      Couleur en écriture hexadécimale.
574 574
 **/
575 575
 function filtre_couleur_saturation_dist($couleur, $val, $strict = false) {
576
-	if (function_exists('couleur_saturation')) {
577
-		return couleur_saturation($couleur, $val, $strict);
578
-	}
579
-	return $couleur;
576
+    if (function_exists('couleur_saturation')) {
577
+        return couleur_saturation($couleur, $val, $strict);
578
+    }
579
+    return $couleur;
580 580
 }
581 581
 
582 582
 /**
@@ -597,8 +597,8 @@  discard block
 block discarded – undo
597 597
  *      Couleur en écriture hexadécimale.
598 598
 **/
599 599
 function filtre_couleur_luminance_dist($couleur, $val) {
600
-	if (function_exists('couleur_luminance')) {
601
-		return couleur_luminance($couleur, $val);
602
-	}
603
-	return $couleur;
600
+    if (function_exists('couleur_luminance')) {
601
+        return couleur_luminance($couleur, $val);
602
+    }
603
+    return $couleur;
604 604
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_images_lib_mini.php 1 patch
Indentation   +1324 added lines, -1324 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,243 +309,243 @@  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'] or $ret['largeur'])) {
415
-		return false;
416
-	}
417
-
418
-	// les images calculees dependent du chemin du fichier source
419
-	// 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
420
-	// ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
421
-	// qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
422
-	// la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
423
-	// alors que ca concerne peu de site au final
424
-	// la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
425
-	$identifiant = $fichier;
426
-
427
-	// cas general :
428
-	// on a un dossier cache commun et un nom de fichier qui varie avec l'effet
429
-	// cas particulier de reduire :
430
-	// un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
431
-	$cache = 'cache-gd2';
432
-	if (substr($effet, 0, 7) == 'reduire') {
433
-		[, $maxWidth, $maxHeight] = explode('-', $effet);
434
-		[$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
435
-		$ret['largeur_dest'] = $destWidth;
436
-		$ret['hauteur_dest'] = $destHeight;
437
-		$effet = "L{$destWidth}xH$destHeight";
438
-		$cache = 'cache-vignettes';
439
-		$fichier_dest = basename($fichier_dest);
440
-		if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
441
-			// on garde la terminaison initiale car image simplement copiee
442
-			// et on postfixe son nom avec un md5 du path
443
-			$terminaison_dest = $terminaison;
444
-			$fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
445
-		} else {
446
-			$fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
447
-		}
448
-		$cache = sous_repertoire(_DIR_VAR, $cache);
449
-		$cache = sous_repertoire($cache, $effet);
450
-	} else {
451
-		$fichier_dest = md5("$identifiant-$effet");
452
-		$cache = sous_repertoire(_DIR_VAR, $cache);
453
-		$cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
454
-		$fichier_dest = substr($fichier_dest, 2);
455
-	}
456
-
457
-	$fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
458
-
459
-	$GLOBALS['images_calculees'][] = $fichier_dest;
460
-
461
-	$creer = true;
462
-	// si recalcul des images demande, recalculer chaque image une fois
463
-	if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
464
-		$images_recalcul[$fichier_dest] = true;
465
-	} else {
466
-		if (@file_exists($f = $fichier_dest)) {
467
-			if (filemtime($f) >= $date_src) {
468
-				$creer = false;
469
-			}
470
-		} else {
471
-			if (
472
-				@file_exists($f = "$fichier_dest.src")
473
-				and lire_fichier($f, $valeurs)
474
-				and $valeurs = unserialize($valeurs)
475
-				and $valeurs['date'] >= $date_src
476
-			) {
477
-				$creer = false;
478
-			}
479
-		}
480
-	}
481
-	if ($creer) {
482
-		if (!@file_exists($fichier)) {
483
-			if (!@file_exists("$fichier.src")) {
484
-				spip_log("Image absente : $fichier");
485
-
486
-				return false;
487
-			}
488
-			# on reconstruit l'image source absente a partir de la chaine des .src
489
-			reconstruire_image_intermediaire($fichier);
490
-		}
491
-	}
492
-
493
-	if ($creer) {
494
-		spip_log(
495
-			'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
496
-			'images' . _LOG_DEBUG
497
-		);
498
-	}
499
-
500
-	$term_fonction = _image_trouver_extension_pertinente($fichier);
501
-	$ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
502
-	$ret['fichier'] = $fichier;
503
-	$ret['fonction_image'] = '_image_image' . $terminaison_dest;
504
-	$ret['fichier_dest'] = $fichier_dest;
505
-	$ret['format_source'] = _image_extension_normalisee($terminaison);
506
-	$ret['format_dest'] = $terminaison_dest;
507
-	$ret['date_src'] = $date_src;
508
-	$ret['creer'] = $creer;
509
-	$ret['class'] = extraire_attribut($img, 'class');
510
-	$ret['alt'] = extraire_attribut($img, 'alt');
511
-	$ret['style'] = extraire_attribut($img, 'style');
512
-	$ret['tag'] = $img;
513
-	if ($fonction_creation) {
514
-		$ret['reconstruction'] = $fonction_creation;
515
-		# ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
516
-		# cas de image_reduire qui finalement ne reduit pas l'image source
517
-		# ca evite d'essayer de le creer au prochain hit si il n'est pas la
518
-		#ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
519
-	}
520
-
521
-	$ret = pipeline('image_preparer_filtre', [
522
-			'args' => [
523
-				'img' => $img,
524
-				'effet' => $effet,
525
-				'forcer_format' => $forcer_format,
526
-				'fonction_creation' => $fonction_creation,
527
-				'find_in_path' => $find_in_path,
528
-			],
529
-			'data' => $ret
530
-		]);
531
-
532
-	// une globale pour le debug en cas de crash memoire
533
-	$GLOBALS['derniere_image_calculee'] = $ret;
534
-
535
-	// traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
536
-	if ($term_fonction === 'svg') {
537
-		if ($creer and !$support_svg) {
538
-			process_image_svg_identite($ret);
539
-			$ret['creer'] = false;
540
-		}
541
-	}
542
-	else {
543
-		if (!function_exists($ret['fonction_imagecreatefrom'])) {
544
-			return false;
545
-		}
546
-	}
547
-
548
-	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'] or $ret['largeur'])) {
415
+        return false;
416
+    }
417
+
418
+    // les images calculees dependent du chemin du fichier source
419
+    // 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
420
+    // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src
421
+    // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public
422
+    // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code
423
+    // alors que ca concerne peu de site au final
424
+    // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes
425
+    $identifiant = $fichier;
426
+
427
+    // cas general :
428
+    // on a un dossier cache commun et un nom de fichier qui varie avec l'effet
429
+    // cas particulier de reduire :
430
+    // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi
431
+    $cache = 'cache-gd2';
432
+    if (substr($effet, 0, 7) == 'reduire') {
433
+        [, $maxWidth, $maxHeight] = explode('-', $effet);
434
+        [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight);
435
+        $ret['largeur_dest'] = $destWidth;
436
+        $ret['hauteur_dest'] = $destHeight;
437
+        $effet = "L{$destWidth}xH$destHeight";
438
+        $cache = 'cache-vignettes';
439
+        $fichier_dest = basename($fichier_dest);
440
+        if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) {
441
+            // on garde la terminaison initiale car image simplement copiee
442
+            // et on postfixe son nom avec un md5 du path
443
+            $terminaison_dest = $terminaison;
444
+            $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5);
445
+        } else {
446
+            $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5);
447
+        }
448
+        $cache = sous_repertoire(_DIR_VAR, $cache);
449
+        $cache = sous_repertoire($cache, $effet);
450
+    } else {
451
+        $fichier_dest = md5("$identifiant-$effet");
452
+        $cache = sous_repertoire(_DIR_VAR, $cache);
453
+        $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2));
454
+        $fichier_dest = substr($fichier_dest, 2);
455
+    }
456
+
457
+    $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest;
458
+
459
+    $GLOBALS['images_calculees'][] = $fichier_dest;
460
+
461
+    $creer = true;
462
+    // si recalcul des images demande, recalculer chaque image une fois
463
+    if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) {
464
+        $images_recalcul[$fichier_dest] = true;
465
+    } else {
466
+        if (@file_exists($f = $fichier_dest)) {
467
+            if (filemtime($f) >= $date_src) {
468
+                $creer = false;
469
+            }
470
+        } else {
471
+            if (
472
+                @file_exists($f = "$fichier_dest.src")
473
+                and lire_fichier($f, $valeurs)
474
+                and $valeurs = unserialize($valeurs)
475
+                and $valeurs['date'] >= $date_src
476
+            ) {
477
+                $creer = false;
478
+            }
479
+        }
480
+    }
481
+    if ($creer) {
482
+        if (!@file_exists($fichier)) {
483
+            if (!@file_exists("$fichier.src")) {
484
+                spip_log("Image absente : $fichier");
485
+
486
+                return false;
487
+            }
488
+            # on reconstruit l'image source absente a partir de la chaine des .src
489
+            reconstruire_image_intermediaire($fichier);
490
+        }
491
+    }
492
+
493
+    if ($creer) {
494
+        spip_log(
495
+            'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier",
496
+            'images' . _LOG_DEBUG
497
+        );
498
+    }
499
+
500
+    $term_fonction = _image_trouver_extension_pertinente($fichier);
501
+    $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction;
502
+    $ret['fichier'] = $fichier;
503
+    $ret['fonction_image'] = '_image_image' . $terminaison_dest;
504
+    $ret['fichier_dest'] = $fichier_dest;
505
+    $ret['format_source'] = _image_extension_normalisee($terminaison);
506
+    $ret['format_dest'] = $terminaison_dest;
507
+    $ret['date_src'] = $date_src;
508
+    $ret['creer'] = $creer;
509
+    $ret['class'] = extraire_attribut($img, 'class');
510
+    $ret['alt'] = extraire_attribut($img, 'alt');
511
+    $ret['style'] = extraire_attribut($img, 'style');
512
+    $ret['tag'] = $img;
513
+    if ($fonction_creation) {
514
+        $ret['reconstruction'] = $fonction_creation;
515
+        # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement
516
+        # cas de image_reduire qui finalement ne reduit pas l'image source
517
+        # ca evite d'essayer de le creer au prochain hit si il n'est pas la
518
+        #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true);
519
+    }
520
+
521
+    $ret = pipeline('image_preparer_filtre', [
522
+            'args' => [
523
+                'img' => $img,
524
+                'effet' => $effet,
525
+                'forcer_format' => $forcer_format,
526
+                'fonction_creation' => $fonction_creation,
527
+                'find_in_path' => $find_in_path,
528
+            ],
529
+            'data' => $ret
530
+        ]);
531
+
532
+    // une globale pour le debug en cas de crash memoire
533
+    $GLOBALS['derniere_image_calculee'] = $ret;
534
+
535
+    // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue
536
+    if ($term_fonction === 'svg') {
537
+        if ($creer and !$support_svg) {
538
+            process_image_svg_identite($ret);
539
+            $ret['creer'] = false;
540
+        }
541
+    }
542
+    else {
543
+        if (!function_exists($ret['fonction_imagecreatefrom'])) {
544
+            return false;
545
+        }
546
+    }
547
+
548
+    return $ret;
549 549
 }
550 550
 
551 551
 
@@ -554,54 +554,54 @@  discard block
 block discarded – undo
554 554
  * @return array
555 555
  */
556 556
 function _image_extensions_acceptees_en_entree() {
557
-	static $extensions = null;
558
-	if (empty($extensions)) {
559
-		$extensions = ['png', 'gif', 'jpg', 'jpeg'];
560
-		if (!empty($GLOBALS['meta']['gd_formats'])) {
561
-			// action=tester renseigne gd_formats et detecte le support de webp
562
-			$extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
563
-			$extensions = array_map('trim', $extensions);
564
-			$extensions = array_filter($extensions);
565
-			if (in_array('jpg', $extensions)) {
566
-				$extensions[] = 'jpeg';
567
-			}
568
-			$extensions = array_unique($extensions);
569
-		}
570
-		$extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
571
-	}
572
-
573
-	return $extensions;
557
+    static $extensions = null;
558
+    if (empty($extensions)) {
559
+        $extensions = ['png', 'gif', 'jpg', 'jpeg'];
560
+        if (!empty($GLOBALS['meta']['gd_formats'])) {
561
+            // action=tester renseigne gd_formats et detecte le support de webp
562
+            $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats']));
563
+            $extensions = array_map('trim', $extensions);
564
+            $extensions = array_filter($extensions);
565
+            if (in_array('jpg', $extensions)) {
566
+                $extensions[] = 'jpeg';
567
+            }
568
+            $extensions = array_unique($extensions);
569
+        }
570
+        $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques
571
+    }
572
+
573
+    return $extensions;
574 574
 }
575 575
 
576 576
 /**
577 577
  * @return array|string[]|null
578 578
  */
579 579
 function _image_extensions_acceptees_en_sortie() {
580
-	static $extensions = null;
581
-	if (empty($extensions)) {
582
-		$extensions = _image_extensions_acceptees_en_entree();
583
-		$extensions = array_diff($extensions, ['jpeg']);
584
-		if (in_array('gif', $extensions) and !function_exists('imagegif')) {
585
-			$extensions = array_diff($extensions, ['gif']);
586
-		}
587
-		if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
588
-			$extensions = array_diff($extensions, ['webp']);
589
-		}
590
-	}
591
-
592
-	return $extensions;
580
+    static $extensions = null;
581
+    if (empty($extensions)) {
582
+        $extensions = _image_extensions_acceptees_en_entree();
583
+        $extensions = array_diff($extensions, ['jpeg']);
584
+        if (in_array('gif', $extensions) and !function_exists('imagegif')) {
585
+            $extensions = array_diff($extensions, ['gif']);
586
+        }
587
+        if (in_array('webp', $extensions) and !function_exists('imagewebp')) {
588
+            $extensions = array_diff($extensions, ['webp']);
589
+        }
590
+    }
591
+
592
+    return $extensions;
593 593
 }
594 594
 
595 595
 function _image_extension_normalisee($extension) {
596
-	$extension = strtolower($extension);
597
-	if ($extension === 'jpeg') {
598
-		$extension = 'jpg';
599
-	}
600
-	return $extension;
596
+    $extension = strtolower($extension);
597
+    if ($extension === 'jpeg') {
598
+        $extension = 'jpg';
599
+    }
600
+    return $extension;
601 601
 }
602 602
 
603 603
 function _image_extensions_conservent_transparence() {
604
-	return ['png', 'webp'];
604
+    return ['png', 'webp'];
605 605
 }
606 606
 
607 607
 
@@ -611,12 +611,12 @@  discard block
 block discarded – undo
611 611
  * @return string
612 612
  */
613 613
 function _image_trouver_extension($path) {
614
-	$preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
615
-	if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
616
-		$terminaison = strtolower($regs[1]);
617
-		return $terminaison;
618
-	}
619
-	return '';
614
+    $preg_extensions = implode('|', _image_extensions_acceptees_en_entree());
615
+    if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) {
616
+        $terminaison = strtolower($regs[1]);
617
+        return $terminaison;
618
+    }
619
+    return '';
620 620
 }
621 621
 
622 622
 /**
@@ -627,33 +627,33 @@  discard block
 block discarded – undo
627 627
  * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple)
628 628
  */
629 629
 function _image_trouver_extension_pertinente($path) {
630
-	$path = supprimer_timestamp($path);
631
-	$terminaison = _image_trouver_extension($path);
632
-	if ($terminaison == 'jpg') {
633
-		$terminaison = 'jpeg';
634
-	}
635
-
636
-	if (!file_exists($path)) {
637
-		return $terminaison;
638
-	}
639
-
640
-	if (!$info = @spip_getimagesize($path)) {
641
-		return $terminaison;
642
-	}
643
-
644
-	if (isset($info['mime'])) {
645
-		$mime = $info['mime'];
646
-	}
647
-	else {
648
-		$mime = image_type_to_mime_type($info[2]);
649
-	}
650
-
651
-	$_terminaison = _image_trouver_extension_depuis_mime($mime);
652
-	if ($_terminaison and $_terminaison !== $terminaison) {
653
-		spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
654
-		$terminaison = $_terminaison;
655
-	}
656
-	return $terminaison;
630
+    $path = supprimer_timestamp($path);
631
+    $terminaison = _image_trouver_extension($path);
632
+    if ($terminaison == 'jpg') {
633
+        $terminaison = 'jpeg';
634
+    }
635
+
636
+    if (!file_exists($path)) {
637
+        return $terminaison;
638
+    }
639
+
640
+    if (!$info = @spip_getimagesize($path)) {
641
+        return $terminaison;
642
+    }
643
+
644
+    if (isset($info['mime'])) {
645
+        $mime = $info['mime'];
646
+    }
647
+    else {
648
+        $mime = image_type_to_mime_type($info[2]);
649
+    }
650
+
651
+    $_terminaison = _image_trouver_extension_depuis_mime($mime);
652
+    if ($_terminaison and $_terminaison !== $terminaison) {
653
+        spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE);
654
+        $terminaison = $_terminaison;
655
+    }
656
+    return $terminaison;
657 657
 }
658 658
 
659 659
 /**
@@ -661,36 +661,36 @@  discard block
 block discarded – undo
661 661
  * @return string
662 662
  */
663 663
 function _image_trouver_extension_depuis_mime($mime) {
664
-	switch (strtolower($mime)) {
665
-		case 'image/png':
666
-		case 'image/x-png':
667
-			$terminaison = 'png';
668
-			break;
669
-
670
-		case 'image/jpg':
671
-		case 'image/jpeg':
672
-		case 'image/pjpeg':
673
-			$terminaison = 'jpeg';
674
-			break;
675
-
676
-		case 'image/gif':
677
-			$terminaison = 'gif';
678
-			break;
679
-
680
-		case 'image/webp':
681
-		case 'image/x-webp':
682
-			$terminaison = 'webp';
683
-			break;
684
-
685
-		case 'image/svg+xml':
686
-			$terminaison = 'svg';
687
-			break;
688
-
689
-		default:
690
-			$terminaison = '';
691
-	}
692
-
693
-	return $terminaison;
664
+    switch (strtolower($mime)) {
665
+        case 'image/png':
666
+        case 'image/x-png':
667
+            $terminaison = 'png';
668
+            break;
669
+
670
+        case 'image/jpg':
671
+        case 'image/jpeg':
672
+        case 'image/pjpeg':
673
+            $terminaison = 'jpeg';
674
+            break;
675
+
676
+        case 'image/gif':
677
+            $terminaison = 'gif';
678
+            break;
679
+
680
+        case 'image/webp':
681
+        case 'image/x-webp':
682
+            $terminaison = 'webp';
683
+            break;
684
+
685
+        case 'image/svg+xml':
686
+            $terminaison = 'svg';
687
+            break;
688
+
689
+        default:
690
+            $terminaison = '';
691
+    }
692
+
693
+    return $terminaison;
694 694
 }
695 695
 
696 696
 
@@ -710,18 +710,18 @@  discard block
 block discarded – undo
710 710
  *     Une ressource de type Image GD.
711 711
  */
712 712
 function _imagecreatefrom_func(string $func, string $filename) {
713
-	if (!function_exists($func)) {
714
-		spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
715
-		erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
716
-		return null;
717
-	}
718
-	$img = @$func($filename);
719
-	if (!$img) {
720
-		spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
721
-		erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
722
-		$img = imagecreate(10, 10);
723
-	}
724
-	return $img;
713
+    if (!function_exists($func)) {
714
+        spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE);
715
+        erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible.");
716
+        return null;
717
+    }
718
+    $img = @$func($filename);
719
+    if (!$img) {
720
+        spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE);
721
+        erreur_squelette("Erreur lecture imagecreatefromjpeg $filename");
722
+        $img = imagecreate(10, 10);
723
+    }
724
+    return $img;
725 725
 }
726 726
 
727 727
 /**
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
  *     Une ressource de type Image GD.
738 738
  */
739 739
 function _imagecreatefromjpeg($filename) {
740
-	return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
740
+    return _imagecreatefrom_func('imagecreatefromjpeg', $filename);
741 741
 }
742 742
 
743 743
 /**
@@ -753,7 +753,7 @@  discard block
 block discarded – undo
753 753
  *     Une ressource de type Image GD.
754 754
  */
755 755
 function _imagecreatefrompng($filename) {
756
-	return _imagecreatefrom_func('imagecreatefrompng', $filename);
756
+    return _imagecreatefrom_func('imagecreatefrompng', $filename);
757 757
 }
758 758
 
759 759
 /**
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
  *     Une ressource de type Image GD.
770 770
  */
771 771
 function _imagecreatefromgif($filename) {
772
-	return _imagecreatefrom_func('imagecreatefromgif', $filename);
772
+    return _imagecreatefrom_func('imagecreatefromgif', $filename);
773 773
 }
774 774
 
775 775
 
@@ -786,7 +786,7 @@  discard block
 block discarded – undo
786 786
  *     Une ressource de type Image GD.
787 787
  */
788 788
 function _imagecreatefromwebp($filename) {
789
-	return _imagecreatefrom_func('imagecreatefromwebp', $filename);
789
+    return _imagecreatefrom_func('imagecreatefromwebp', $filename);
790 790
 }
791 791
 
792 792
 /**
@@ -804,24 +804,24 @@  discard block
 block discarded – undo
804 804
  *     - true si une image est bien retournée.
805 805
  */
806 806
 function _image_imagepng($img, $fichier) {
807
-	if (!function_exists('imagepng')) {
808
-		return false;
809
-	}
810
-	$tmp = $fichier . '.tmp';
811
-	$ret = imagepng($img, $tmp);
812
-	if (file_exists($tmp)) {
813
-		$taille_test = getimagesize($tmp);
814
-		if ($taille_test[0] < 1) {
815
-			return false;
816
-		}
817
-
818
-		spip_unlink($fichier); // le fichier peut deja exister
819
-		@rename($tmp, $fichier);
820
-
821
-		return $ret;
822
-	}
823
-
824
-	return false;
807
+    if (!function_exists('imagepng')) {
808
+        return false;
809
+    }
810
+    $tmp = $fichier . '.tmp';
811
+    $ret = imagepng($img, $tmp);
812
+    if (file_exists($tmp)) {
813
+        $taille_test = getimagesize($tmp);
814
+        if ($taille_test[0] < 1) {
815
+            return false;
816
+        }
817
+
818
+        spip_unlink($fichier); // le fichier peut deja exister
819
+        @rename($tmp, $fichier);
820
+
821
+        return $ret;
822
+    }
823
+
824
+    return false;
825 825
 }
826 826
 
827 827
 /**
@@ -839,24 +839,24 @@  discard block
 block discarded – undo
839 839
  *     - true si une image est bien retournée.
840 840
  */
841 841
 function _image_imagegif($img, $fichier) {
842
-	if (!function_exists('imagegif')) {
843
-		return false;
844
-	}
845
-	$tmp = $fichier . '.tmp';
846
-	$ret = imagegif($img, $tmp);
847
-	if (file_exists($tmp)) {
848
-		$taille_test = getimagesize($tmp);
849
-		if ($taille_test[0] < 1) {
850
-			return false;
851
-		}
852
-
853
-		spip_unlink($fichier); // le fichier peut deja exister
854
-		@rename($tmp, $fichier);
855
-
856
-		return $ret;
857
-	}
858
-
859
-	return false;
842
+    if (!function_exists('imagegif')) {
843
+        return false;
844
+    }
845
+    $tmp = $fichier . '.tmp';
846
+    $ret = imagegif($img, $tmp);
847
+    if (file_exists($tmp)) {
848
+        $taille_test = getimagesize($tmp);
849
+        if ($taille_test[0] < 1) {
850
+            return false;
851
+        }
852
+
853
+        spip_unlink($fichier); // le fichier peut deja exister
854
+        @rename($tmp, $fichier);
855
+
856
+        return $ret;
857
+    }
858
+
859
+    return false;
860 860
 }
861 861
 
862 862
 /**
@@ -879,29 +879,29 @@  discard block
 block discarded – undo
879 879
  *     - true si une image est bien retournée.
880 880
  */
881 881
 function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) {
882
-	if (!function_exists('imagejpeg')) {
883
-		return false;
884
-	}
885
-	$tmp = $fichier . '.tmp';
882
+    if (!function_exists('imagejpeg')) {
883
+        return false;
884
+    }
885
+    $tmp = $fichier . '.tmp';
886 886
 
887
-	// Enable interlancing
888
-	imageinterlace($img, true);
887
+    // Enable interlancing
888
+    imageinterlace($img, true);
889 889
 
890
-	$ret = imagejpeg($img, $tmp, $qualite);
890
+    $ret = imagejpeg($img, $tmp, $qualite);
891 891
 
892
-	if (file_exists($tmp)) {
893
-		$taille_test = getimagesize($tmp);
894
-		if ($taille_test[0] < 1) {
895
-			return false;
896
-		}
892
+    if (file_exists($tmp)) {
893
+        $taille_test = getimagesize($tmp);
894
+        if ($taille_test[0] < 1) {
895
+            return false;
896
+        }
897 897
 
898
-		spip_unlink($fichier); // le fichier peut deja exister
899
-		@rename($tmp, $fichier);
898
+        spip_unlink($fichier); // le fichier peut deja exister
899
+        @rename($tmp, $fichier);
900 900
 
901
-		return $ret;
902
-	}
901
+        return $ret;
902
+    }
903 903
 
904
-	return false;
904
+    return false;
905 905
 }
906 906
 
907 907
 /**
@@ -919,9 +919,9 @@  discard block
 block discarded – undo
919 919
  *     true si le fichier a bien été créé ; false sinon.
920 920
  */
921 921
 function _image_imageico($img, $fichier) {
922
-	$gd_image_array = [$img];
922
+    $gd_image_array = [$img];
923 923
 
924
-	return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
924
+    return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array));
925 925
 }
926 926
 
927 927
 
@@ -940,24 +940,24 @@  discard block
 block discarded – undo
940 940
  *     - true si une image est bien retournée.
941 941
  */
942 942
 function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) {
943
-	if (!function_exists('imagewebp')) {
944
-		return false;
945
-	}
946
-	$tmp = $fichier . '.tmp';
947
-	$ret = imagewebp($img, $tmp, $qualite);
948
-	if (file_exists($tmp)) {
949
-		$taille_test = getimagesize($tmp);
950
-		if ($taille_test[0] < 1) {
951
-			return false;
952
-		}
953
-
954
-		spip_unlink($fichier); // le fichier peut deja exister
955
-		@rename($tmp, $fichier);
956
-
957
-		return $ret;
958
-	}
959
-
960
-	return false;
943
+    if (!function_exists('imagewebp')) {
944
+        return false;
945
+    }
946
+    $tmp = $fichier . '.tmp';
947
+    $ret = imagewebp($img, $tmp, $qualite);
948
+    if (file_exists($tmp)) {
949
+        $taille_test = getimagesize($tmp);
950
+        if ($taille_test[0] < 1) {
951
+            return false;
952
+        }
953
+
954
+        spip_unlink($fichier); // le fichier peut deja exister
955
+        @rename($tmp, $fichier);
956
+
957
+        return $ret;
958
+    }
959
+
960
+    return false;
961 961
 }
962 962
 
963 963
 /**
@@ -977,35 +977,35 @@  discard block
 block discarded – undo
977 977
  */
978 978
 function _image_imagesvg($img, $fichier) {
979 979
 
980
-	$tmp = $fichier . '.tmp';
981
-	if (strpos($img, '<') === false) {
982
-		$img = supprimer_timestamp($img);
983
-		if (!file_exists($img)) {
984
-			return false;
985
-		}
986
-		@copy($img, $tmp);
987
-		if (filesize($tmp) == filesize($img)) {
988
-			spip_unlink($fichier); // le fichier peut deja exister
989
-			@rename($tmp, $fichier);
990
-			return true;
991
-		}
992
-		return false;
993
-	}
994
-
995
-	file_put_contents($tmp, $img);
996
-	if (file_exists($tmp)) {
997
-		$taille_test = spip_getimagesize($tmp);
998
-		if ($taille_test[0] < 1) {
999
-			return false;
1000
-		}
1001
-
1002
-		spip_unlink($fichier); // le fichier peut deja exister
1003
-		@rename($tmp, $fichier);
1004
-
1005
-		return true;
1006
-	}
1007
-
1008
-	return false;
980
+    $tmp = $fichier . '.tmp';
981
+    if (strpos($img, '<') === false) {
982
+        $img = supprimer_timestamp($img);
983
+        if (!file_exists($img)) {
984
+            return false;
985
+        }
986
+        @copy($img, $tmp);
987
+        if (filesize($tmp) == filesize($img)) {
988
+            spip_unlink($fichier); // le fichier peut deja exister
989
+            @rename($tmp, $fichier);
990
+            return true;
991
+        }
992
+        return false;
993
+    }
994
+
995
+    file_put_contents($tmp, $img);
996
+    if (file_exists($tmp)) {
997
+        $taille_test = spip_getimagesize($tmp);
998
+        if ($taille_test[0] < 1) {
999
+            return false;
1000
+        }
1001
+
1002
+        spip_unlink($fichier); // le fichier peut deja exister
1003
+        @rename($tmp, $fichier);
1004
+
1005
+        return true;
1006
+    }
1007
+
1008
+    return false;
1009 1009
 }
1010 1010
 
1011 1011
 
@@ -1033,30 +1033,30 @@  discard block
 block discarded – undo
1033 1033
  *     - false sinon.
1034 1034
  */
1035 1035
 function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) {
1036
-	if (is_null($fonction)) {
1037
-		$fonction = '_image_image' . $valeurs['format_dest'];
1038
-	}
1039
-	$ret = false;
1040
-	#un flag pour reperer les images gravees
1041
-	$lock = (
1042
-		!statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1043
-		or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1044
-	);
1045
-	if (
1046
-		function_exists($fonction)
1047
-		&& ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1048
-		&& isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1049
-		&& !$lock
1050
-	) {
1051
-		if (@file_exists($valeurs['fichier_dest'])) {
1052
-			// dans tous les cas mettre a jour la taille de l'image finale
1053
-			[$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1054
-			$valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1055
-			ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1056
-		}
1057
-	}
1058
-
1059
-	return $ret;
1036
+    if (is_null($fonction)) {
1037
+        $fonction = '_image_image' . $valeurs['format_dest'];
1038
+    }
1039
+    $ret = false;
1040
+    #un flag pour reperer les images gravees
1041
+    $lock = (
1042
+        !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout
1043
+        or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src'))
1044
+    );
1045
+    if (
1046
+        function_exists($fonction)
1047
+        && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image
1048
+        && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant
1049
+        && !$lock
1050
+    ) {
1051
+        if (@file_exists($valeurs['fichier_dest'])) {
1052
+            // dans tous les cas mettre a jour la taille de l'image finale
1053
+            [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']);
1054
+            $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition
1055
+            ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true);
1056
+        }
1057
+    }
1058
+
1059
+    return $ret;
1060 1060
 }
1061 1061
 
1062 1062
 /**
@@ -1069,27 +1069,27 @@  discard block
 block discarded – undo
1069 1069
  *     Chemin vers le fichier manquant
1070 1070
  **/
1071 1071
 function reconstruire_image_intermediaire($fichier_manquant) {
1072
-	$reconstruire = [];
1073
-	$fichier = $fichier_manquant;
1074
-	while (
1075
-		strpos($fichier, '://') === false
1076
-		and !@file_exists($fichier)
1077
-		and lire_fichier($src = "$fichier.src", $source)
1078
-		and $valeurs = unserialize($source)
1079
-		and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1080
-	) {
1081
-		spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1082
-		$reconstruire[] = $valeurs['reconstruction'];
1083
-	}
1084
-	while (count($reconstruire)) {
1085
-		$r = array_pop($reconstruire);
1086
-		$fonction = $r[0];
1087
-		$args = $r[1];
1088
-		$fonction(...$args);
1089
-	}
1090
-	// cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1091
-	// mais l'on peut nettoyer les miettes de sa creation
1092
-	ramasse_miettes($fichier_manquant);
1072
+    $reconstruire = [];
1073
+    $fichier = $fichier_manquant;
1074
+    while (
1075
+        strpos($fichier, '://') === false
1076
+        and !@file_exists($fichier)
1077
+        and lire_fichier($src = "$fichier.src", $source)
1078
+        and $valeurs = unserialize($source)
1079
+        and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1080
+    ) {
1081
+        spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant
1082
+        $reconstruire[] = $valeurs['reconstruction'];
1083
+    }
1084
+    while (count($reconstruire)) {
1085
+        $r = array_pop($reconstruire);
1086
+        $fonction = $r[0];
1087
+        $args = $r[1];
1088
+        $fonction(...$args);
1089
+    }
1090
+    // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver
1091
+    // mais l'on peut nettoyer les miettes de sa creation
1092
+    ramasse_miettes($fichier_manquant);
1093 1093
 }
1094 1094
 
1095 1095
 /**
@@ -1109,28 +1109,28 @@  discard block
 block discarded – undo
1109 1109
  *     Chemin du fichier d'image calculé
1110 1110
  **/
1111 1111
 function ramasse_miettes($fichier) {
1112
-	if (
1113
-		strpos($fichier, '://') !== false
1114
-		or !lire_fichier($src = "$fichier.src", $source)
1115
-		or !$valeurs = unserialize($source)
1116
-	) {
1117
-		return;
1118
-	}
1119
-	spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1120
-	while (
1121
-		($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1122
-		and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1123
-		and (lire_fichier(
1124
-			$src = "$fichier.src",
1125
-			$source
1126
-		)) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1127
-		and ($valeurs = unserialize($source))  # et valide
1128
-	) {
1129
-		# on efface le fichier
1130
-		spip_unlink($fichier);
1131
-		# mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1132
-		#spip_unlink($src);
1133
-	}
1112
+    if (
1113
+        strpos($fichier, '://') !== false
1114
+        or !lire_fichier($src = "$fichier.src", $source)
1115
+        or !$valeurs = unserialize($source)
1116
+    ) {
1117
+        return;
1118
+    }
1119
+    spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire
1120
+    while (
1121
+        ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...)
1122
+        and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local
1123
+        and (lire_fichier(
1124
+            $src = "$fichier.src",
1125
+            $source
1126
+        )) # le fichier a une source connue (c'est donc une image calculee intermediaire)
1127
+        and ($valeurs = unserialize($source))  # et valide
1128
+    ) {
1129
+        # on efface le fichier
1130
+        spip_unlink($fichier);
1131
+        # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin
1132
+        #spip_unlink($src);
1133
+    }
1134 1134
 }
1135 1135
 
1136 1136
 
@@ -1155,31 +1155,31 @@  discard block
 block discarded – undo
1155 1155
  *     Code HTML de l'image
1156 1156
  **/
1157 1157
 function image_graver($img) {
1158
-	// appeler le filtre post_image_filtrer qui permet de faire
1159
-	// des traitements auto a la fin d'une serie de filtres
1160
-	$img = pipeline('post_image_filtrer', $img);
1161
-
1162
-	$fichier_ori = $fichier = extraire_attribut($img, 'src');
1163
-	if (($p = strpos($fichier, '?')) !== false) {
1164
-		$fichier = substr($fichier, 0, $p);
1165
-	}
1166
-	if (strlen($fichier) < 1) {
1167
-		$fichier = $img;
1168
-	}
1169
-	# si jamais le fichier final n'a pas ete calcule car suppose temporaire
1170
-	# et qu'il ne s'agit pas d'une URL
1171
-	if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1172
-		reconstruire_image_intermediaire($fichier);
1173
-	}
1174
-	ramasse_miettes($fichier);
1175
-
1176
-	// ajouter le timestamp si besoin
1177
-	if (strpos($fichier_ori, '?') === false) {
1178
-		// on utilise str_replace pour attraper le onmouseover des logo si besoin
1179
-		$img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1180
-	}
1181
-
1182
-	return $img;
1158
+    // appeler le filtre post_image_filtrer qui permet de faire
1159
+    // des traitements auto a la fin d'une serie de filtres
1160
+    $img = pipeline('post_image_filtrer', $img);
1161
+
1162
+    $fichier_ori = $fichier = extraire_attribut($img, 'src');
1163
+    if (($p = strpos($fichier, '?')) !== false) {
1164
+        $fichier = substr($fichier, 0, $p);
1165
+    }
1166
+    if (strlen($fichier) < 1) {
1167
+        $fichier = $img;
1168
+    }
1169
+    # si jamais le fichier final n'a pas ete calcule car suppose temporaire
1170
+    # et qu'il ne s'agit pas d'une URL
1171
+    if (strpos($fichier, '://') === false and !@file_exists($fichier)) {
1172
+        reconstruire_image_intermediaire($fichier);
1173
+    }
1174
+    ramasse_miettes($fichier);
1175
+
1176
+    // ajouter le timestamp si besoin
1177
+    if (strpos($fichier_ori, '?') === false) {
1178
+        // on utilise str_replace pour attraper le onmouseover des logo si besoin
1179
+        $img = str_replace($fichier_ori, timestamp($fichier_ori), $img);
1180
+    }
1181
+
1182
+    return $img;
1183 1183
 }
1184 1184
 
1185 1185
 /**
@@ -1206,34 +1206,34 @@  discard block
 block discarded – undo
1206 1206
  *     Code html modifié de la balise.
1207 1207
  **/
1208 1208
 function _image_tag_changer_taille($tag, $width, $height, $style = false) {
1209
-	if ($style === false) {
1210
-		$style = extraire_attribut($tag, 'style');
1211
-	}
1212
-
1213
-	// enlever le width et height du style
1214
-	if ($style) {
1215
-		$style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1216
-	}
1217
-	if ($style and $style[0] === ';') {
1218
-		$style = substr($style, 1);
1219
-	}
1220
-
1221
-	// mettre des attributs de width et height sur les images,
1222
-	// ca accelere le rendu du navigateur
1223
-	// ca permet aux navigateurs de reserver la bonne taille
1224
-	// quand on a desactive l'affichage des images.
1225
-	$tag = inserer_attribut($tag, 'width', round($width));
1226
-	$tag = inserer_attribut($tag, 'height', round($height));
1227
-
1228
-	// attributs deprecies. Transformer en CSS
1229
-	if ($espace = extraire_attribut($tag, 'hspace')) {
1230
-		$style = "margin:{$espace}px;" . $style;
1231
-		$tag = inserer_attribut($tag, 'hspace', '');
1232
-	}
1233
-
1234
-	$tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1235
-
1236
-	return $tag;
1209
+    if ($style === false) {
1210
+        $style = extraire_attribut($tag, 'style');
1211
+    }
1212
+
1213
+    // enlever le width et height du style
1214
+    if ($style) {
1215
+        $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style);
1216
+    }
1217
+    if ($style and $style[0] === ';') {
1218
+        $style = substr($style, 1);
1219
+    }
1220
+
1221
+    // mettre des attributs de width et height sur les images,
1222
+    // ca accelere le rendu du navigateur
1223
+    // ca permet aux navigateurs de reserver la bonne taille
1224
+    // quand on a desactive l'affichage des images.
1225
+    $tag = inserer_attribut($tag, 'width', round($width));
1226
+    $tag = inserer_attribut($tag, 'height', round($height));
1227
+
1228
+    // attributs deprecies. Transformer en CSS
1229
+    if ($espace = extraire_attribut($tag, 'hspace')) {
1230
+        $style = "margin:{$espace}px;" . $style;
1231
+        $tag = inserer_attribut($tag, 'hspace', '');
1232
+    }
1233
+
1234
+    $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true);
1235
+
1236
+    return $tag;
1237 1237
 }
1238 1238
 
1239 1239
 
@@ -1259,72 +1259,72 @@  discard block
 block discarded – undo
1259 1259
  *     Retourne le code HTML de l'image
1260 1260
  **/
1261 1261
 function _image_ecrire_tag($valeurs, $surcharge = []) {
1262
-	$valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1263
-
1264
-	// fermer les tags img pas bien fermes;
1265
-	$tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1266
-
1267
-	// le style
1268
-	$style = $valeurs['style'];
1269
-	if (isset($surcharge['style'])) {
1270
-		$style = $surcharge['style'];
1271
-		unset($surcharge['style']);
1272
-	}
1273
-
1274
-	// traiter specifiquement la largeur et la hauteur
1275
-	$width = $valeurs['largeur'];
1276
-	if (isset($surcharge['width'])) {
1277
-		$width = $surcharge['width'];
1278
-		unset($surcharge['width']);
1279
-	}
1280
-	$height = $valeurs['hauteur'];
1281
-	if (isset($surcharge['height'])) {
1282
-		$height = $surcharge['height'];
1283
-		unset($surcharge['height']);
1284
-	}
1285
-
1286
-	$tag = _image_tag_changer_taille($tag, $width, $height, $style);
1287
-	// traiter specifiquement le src qui peut etre repris dans un onmouseout
1288
-	// on remplace toute les ref a src dans le tag
1289
-	$src = extraire_attribut($tag, 'src');
1290
-	if (isset($surcharge['src'])) {
1291
-		$tag = str_replace($src, $surcharge['src'], $tag);
1292
-		// si il y a des & dans src, alors ils peuvent provenir d'un &amp
1293
-		// pas garanti comme methode, mais mieux que rien
1294
-		if (strpos($src, '&') !== false) {
1295
-			$tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1296
-		}
1297
-		$src = $surcharge['src'];
1298
-		unset($surcharge['src']);
1299
-	}
1300
-
1301
-	$class = $valeurs['class'];
1302
-	if (isset($surcharge['class'])) {
1303
-		$class = $surcharge['class'];
1304
-		unset($surcharge['class']);
1305
-	}
1306
-	if (is_scalar($class) && strlen($class)) {
1307
-		$tag = inserer_attribut($tag, 'class', $class);
1308
-	}
1309
-
1310
-	if (count($surcharge)) {
1311
-		foreach ($surcharge as $attribut => $valeur) {
1312
-			$tag = inserer_attribut($tag, $attribut, $valeur);
1313
-		}
1314
-	}
1315
-
1316
-	$tag = pipeline(
1317
-		'image_ecrire_tag_finir',
1318
-		[
1319
-			'args' => [
1320
-				'valeurs' => $valeurs,
1321
-				'surcharge' => $surcharge,
1322
-			],
1323
-			'data' => $tag
1324
-		]
1325
-	);
1326
-
1327
-	return $tag;
1262
+    $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs);
1263
+
1264
+    // fermer les tags img pas bien fermes;
1265
+    $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag']));
1266
+
1267
+    // le style
1268
+    $style = $valeurs['style'];
1269
+    if (isset($surcharge['style'])) {
1270
+        $style = $surcharge['style'];
1271
+        unset($surcharge['style']);
1272
+    }
1273
+
1274
+    // traiter specifiquement la largeur et la hauteur
1275
+    $width = $valeurs['largeur'];
1276
+    if (isset($surcharge['width'])) {
1277
+        $width = $surcharge['width'];
1278
+        unset($surcharge['width']);
1279
+    }
1280
+    $height = $valeurs['hauteur'];
1281
+    if (isset($surcharge['height'])) {
1282
+        $height = $surcharge['height'];
1283
+        unset($surcharge['height']);
1284
+    }
1285
+
1286
+    $tag = _image_tag_changer_taille($tag, $width, $height, $style);
1287
+    // traiter specifiquement le src qui peut etre repris dans un onmouseout
1288
+    // on remplace toute les ref a src dans le tag
1289
+    $src = extraire_attribut($tag, 'src');
1290
+    if (isset($surcharge['src'])) {
1291
+        $tag = str_replace($src, $surcharge['src'], $tag);
1292
+        // si il y a des & dans src, alors ils peuvent provenir d'un &amp
1293
+        // pas garanti comme methode, mais mieux que rien
1294
+        if (strpos($src, '&') !== false) {
1295
+            $tag = str_replace(str_replace('&', '&amp;', $src), $surcharge['src'], $tag);
1296
+        }
1297
+        $src = $surcharge['src'];
1298
+        unset($surcharge['src']);
1299
+    }
1300
+
1301
+    $class = $valeurs['class'];
1302
+    if (isset($surcharge['class'])) {
1303
+        $class = $surcharge['class'];
1304
+        unset($surcharge['class']);
1305
+    }
1306
+    if (is_scalar($class) && strlen($class)) {
1307
+        $tag = inserer_attribut($tag, 'class', $class);
1308
+    }
1309
+
1310
+    if (count($surcharge)) {
1311
+        foreach ($surcharge as $attribut => $valeur) {
1312
+            $tag = inserer_attribut($tag, $attribut, $valeur);
1313
+        }
1314
+    }
1315
+
1316
+    $tag = pipeline(
1317
+        'image_ecrire_tag_finir',
1318
+        [
1319
+            'args' => [
1320
+                'valeurs' => $valeurs,
1321
+                'surcharge' => $surcharge,
1322
+            ],
1323
+            'data' => $tag
1324
+        ]
1325
+    );
1326
+
1327
+    return $tag;
1328 1328
 }
1329 1329
 
1330 1330
 /**
@@ -1347,267 +1347,267 @@  discard block
 block discarded – undo
1347 1347
  *     Description de l'image, sinon null.
1348 1348
  **/
1349 1349
 function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) {
1350
-	$srcHeight = null;
1351
-	$retour = [];
1352
-	// ordre de preference des formats graphiques pour creer les vignettes
1353
-	// le premier format disponible, selon la methode demandee, est utilise
1354
-	$image = $valeurs['fichier'];
1355
-	$format = $valeurs['format_source'];
1356
-	$destdir = dirname($valeurs['fichier_dest']);
1357
-	$destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1358
-
1359
-	$format_sortie = $valeurs['format_dest'];
1360
-
1361
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1362
-		$process = $GLOBALS['meta']['image_process'];
1363
-	}
1364
-
1365
-	// si le doc n'est pas une image dans un format accetpable, refuser
1366
-	if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1367
-		return;
1368
-	}
1369
-	$destination = "$destdir/$destfile";
1370
-
1371
-	// calculer la taille
1372
-	if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1373
-		if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1374
-			[$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1375
-		}
1376
-	} elseif ($process == 'convert' or $process == 'imagick') {
1377
-		$destWidth = $maxWidth;
1378
-		$destHeight = $maxHeight;
1379
-	} else {
1380
-		spip_log("echec $process sur $image");
1381
-
1382
-		return;
1383
-	}
1384
-
1385
-	$vignette = '';
1386
-
1387
-	// Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1388
-	if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1389
-		$vignette = $destination . '.' . $format;
1390
-		@copy($image, $vignette);
1391
-	}
1392
-
1393
-	elseif ($valeurs['format_source'] === 'svg') {
1394
-		if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1395
-			$format_sortie = 'svg';
1396
-			$vignette = $destination . '.' . $format_sortie;
1397
-			$valeurs['fichier_dest'] = $vignette;
1398
-			_image_gd_output($svg, $valeurs);
1399
-		}
1400
-	}
1401
-
1402
-	// imagemagick en ligne de commande
1403
-	elseif ($process == 'convert') {
1404
-		if (!defined('_CONVERT_COMMAND')) {
1405
-			define('_CONVERT_COMMAND', 'convert');
1406
-		} // Securite : mes_options.php peut preciser le chemin absolu
1407
-		if (!defined('_RESIZE_COMMAND')) {
1408
-			define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1409
-		}
1410
-		$vignette = $destination . '.' . $format_sortie;
1411
-		$commande = str_replace(
1412
-			['%x', '%y', '%src', '%dest'],
1413
-			[
1414
-				$destWidth,
1415
-				$destHeight,
1416
-				escapeshellcmd($image),
1417
-				escapeshellcmd($vignette)
1418
-			],
1419
-			_RESIZE_COMMAND
1420
-		);
1421
-		spip_log($commande);
1422
-		exec($commande);
1423
-		if (!@file_exists($vignette)) {
1424
-			spip_log("echec convert sur $vignette");
1425
-
1426
-			return;  // echec commande
1427
-		}
1428
-	}
1429
-
1430
-	// php5 imagemagick
1431
-	elseif ($process == 'imagick') {
1432
-		if (!class_exists(\Imagick::class)) {
1433
-			spip_log('Classe Imagick absente !', _LOG_ERREUR);
1434
-
1435
-			return;
1436
-		}
1437
-
1438
-		// chemin compatible Windows
1439
-		$output = realpath(dirname($destination));
1440
-		if (!$output) {
1441
-			return;
1442
-		}
1443
-		$vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1444
-
1445
-		$imagick = new Imagick();
1446
-		$imagick->readImage(realpath($image));
1447
-		$imagick->resizeImage(
1448
-			$destWidth,
1449
-			$destHeight,
1450
-			Imagick::FILTER_LANCZOS,
1451
-			1
1452
-		);//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1453
-		$imagick->writeImage($vignette);
1454
-
1455
-		if (!@file_exists($vignette)) {
1456
-			spip_log("echec imagick sur $vignette");
1457
-
1458
-			return;
1459
-		}
1460
-		// remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1461
-		$vignette = $destination . '.' . $format_sortie;
1462
-	}
1463
-
1464
-	// netpbm
1465
-	elseif ($process == 'netpbm') {
1466
-		if (!defined('_PNMSCALE_COMMAND')) {
1467
-			define('_PNMSCALE_COMMAND', 'pnmscale');
1468
-		} // Securite : mes_options.php peut preciser le chemin absolu
1469
-		if (_PNMSCALE_COMMAND == '') {
1470
-			return;
1471
-		}
1472
-		$vignette = $destination . '.' . $format_sortie;
1473
-		$pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1474
-		if ($format == 'jpg') {
1475
-			$jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1476
-			exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1477
-			if (!($s = @filesize($vignette))) {
1478
-				spip_unlink($vignette);
1479
-			}
1480
-			if (!@file_exists($vignette)) {
1481
-				spip_log("echec netpbm-jpg sur $vignette");
1482
-
1483
-				return;
1484
-			}
1485
-		} else {
1486
-			if ($format == 'gif') {
1487
-				$giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1488
-				exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1489
-				if (!($s = @filesize($vignette))) {
1490
-					spip_unlink($vignette);
1491
-				}
1492
-				if (!@file_exists($vignette)) {
1493
-					spip_log("echec netpbm-gif sur $vignette");
1494
-
1495
-					return;
1496
-				}
1497
-			} else {
1498
-				if ($format == 'png') {
1499
-					$pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1500
-					exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1501
-					if (!($s = @filesize($vignette))) {
1502
-						spip_unlink($vignette);
1503
-					}
1504
-					if (!@file_exists($vignette)) {
1505
-						spip_log("echec netpbm-png sur $vignette");
1506
-
1507
-						return;
1508
-					}
1509
-				}
1510
-			}
1511
-		}
1512
-	}
1513
-
1514
-	// gd ou gd2
1515
-	elseif ($process == 'gd1' or $process == 'gd2') {
1516
-		if (!function_exists('gd_info')) {
1517
-			spip_log('Librairie GD absente !', _LOG_ERREUR);
1518
-
1519
-			return;
1520
-		}
1521
-		if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1522
-			spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1523
-
1524
-			return;
1525
-		}
1526
-		$destFormat = $format_sortie;
1527
-		if (!$destFormat) {
1528
-			spip_log("pas de format pour $image");
1529
-
1530
-			return;
1531
-		}
1532
-
1533
-		$fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1534
-		if (!function_exists($fonction_imagecreatefrom)) {
1535
-			return;
1536
-		}
1537
-		$srcImage = @$fonction_imagecreatefrom($image);
1538
-		if (!$srcImage) {
1539
-			spip_log('echec gd1/gd2');
1540
-
1541
-			return;
1542
-		}
1543
-
1544
-		// Initialisation de l'image destination
1545
-		$destImage = null;
1546
-		if ($process == 'gd2' and $destFormat != 'gif') {
1547
-			$destImage = ImageCreateTrueColor($destWidth, $destHeight);
1548
-		}
1549
-		if (!$destImage) {
1550
-			$destImage = ImageCreate($destWidth, $destHeight);
1551
-		}
1552
-
1553
-		// Recopie de l'image d'origine avec adaptation de la taille
1554
-		$ok = false;
1555
-		if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1556
-			if ($format == 'gif') {
1557
-				// Si un GIF est transparent,
1558
-				// fabriquer un PNG transparent
1559
-				$transp = imagecolortransparent($srcImage);
1560
-				if ($transp > 0) {
1561
-					$destFormat = 'png';
1562
-				}
1563
-			}
1564
-			if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1565
-				// Conserver la transparence
1566
-				if (function_exists('imageAntiAlias')) {
1567
-					imageAntiAlias($destImage, true);
1568
-				}
1569
-				@imagealphablending($destImage, false);
1570
-				@imagesavealpha($destImage, true);
1571
-			}
1572
-			$ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1573
-		}
1574
-		if (!$ok) {
1575
-			$ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1576
-		}
1577
-
1578
-		// Sauvegarde de l'image destination
1579
-		$valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1580
-		$valeurs['format_dest'] = $format = $destFormat;
1581
-		_image_gd_output($destImage, $valeurs);
1582
-
1583
-		if ($srcImage) {
1584
-			ImageDestroy($srcImage);
1585
-		}
1586
-		ImageDestroy($destImage);
1587
-	}
1588
-
1589
-	if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1590
-		$size = [$destWidth, $destHeight];
1591
-	}
1592
-
1593
-	// Gaffe: en safe mode, pas d'acces a la vignette,
1594
-	// donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1595
-	if ($size[0] < 1) {
1596
-		$size[0] = $destWidth;
1597
-	}
1598
-	if ($size[1] < 1) {
1599
-		$size[1] = $destHeight;
1600
-	}
1601
-
1602
-	$retour['width'] = $largeur = $size[0];
1603
-	$retour['height'] = $hauteur = $size[1];
1604
-
1605
-	$retour['fichier'] = $vignette;
1606
-	$retour['format'] = $format;
1607
-	$retour['date'] = @filemtime($vignette);
1608
-
1609
-	// renvoyer l'image
1610
-	return $retour;
1350
+    $srcHeight = null;
1351
+    $retour = [];
1352
+    // ordre de preference des formats graphiques pour creer les vignettes
1353
+    // le premier format disponible, selon la methode demandee, est utilise
1354
+    $image = $valeurs['fichier'];
1355
+    $format = $valeurs['format_source'];
1356
+    $destdir = dirname($valeurs['fichier_dest']);
1357
+    $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']);
1358
+
1359
+    $format_sortie = $valeurs['format_dest'];
1360
+
1361
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1362
+        $process = $GLOBALS['meta']['image_process'];
1363
+    }
1364
+
1365
+    // si le doc n'est pas une image dans un format accetpable, refuser
1366
+    if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) {
1367
+        return;
1368
+    }
1369
+    $destination = "$destdir/$destfile";
1370
+
1371
+    // calculer la taille
1372
+    if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) {
1373
+        if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) {
1374
+            [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight);
1375
+        }
1376
+    } elseif ($process == 'convert' or $process == 'imagick') {
1377
+        $destWidth = $maxWidth;
1378
+        $destHeight = $maxHeight;
1379
+    } else {
1380
+        spip_log("echec $process sur $image");
1381
+
1382
+        return;
1383
+    }
1384
+
1385
+    $vignette = '';
1386
+
1387
+    // Si l'image est de la taille demandee (ou plus petite), simplement la retourner
1388
+    if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1389
+        $vignette = $destination . '.' . $format;
1390
+        @copy($image, $vignette);
1391
+    }
1392
+
1393
+    elseif ($valeurs['format_source'] === 'svg') {
1394
+        if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) {
1395
+            $format_sortie = 'svg';
1396
+            $vignette = $destination . '.' . $format_sortie;
1397
+            $valeurs['fichier_dest'] = $vignette;
1398
+            _image_gd_output($svg, $valeurs);
1399
+        }
1400
+    }
1401
+
1402
+    // imagemagick en ligne de commande
1403
+    elseif ($process == 'convert') {
1404
+        if (!defined('_CONVERT_COMMAND')) {
1405
+            define('_CONVERT_COMMAND', 'convert');
1406
+        } // Securite : mes_options.php peut preciser le chemin absolu
1407
+        if (!defined('_RESIZE_COMMAND')) {
1408
+            define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest');
1409
+        }
1410
+        $vignette = $destination . '.' . $format_sortie;
1411
+        $commande = str_replace(
1412
+            ['%x', '%y', '%src', '%dest'],
1413
+            [
1414
+                $destWidth,
1415
+                $destHeight,
1416
+                escapeshellcmd($image),
1417
+                escapeshellcmd($vignette)
1418
+            ],
1419
+            _RESIZE_COMMAND
1420
+        );
1421
+        spip_log($commande);
1422
+        exec($commande);
1423
+        if (!@file_exists($vignette)) {
1424
+            spip_log("echec convert sur $vignette");
1425
+
1426
+            return;  // echec commande
1427
+        }
1428
+    }
1429
+
1430
+    // php5 imagemagick
1431
+    elseif ($process == 'imagick') {
1432
+        if (!class_exists(\Imagick::class)) {
1433
+            spip_log('Classe Imagick absente !', _LOG_ERREUR);
1434
+
1435
+            return;
1436
+        }
1437
+
1438
+        // chemin compatible Windows
1439
+        $output = realpath(dirname($destination));
1440
+        if (!$output) {
1441
+            return;
1442
+        }
1443
+        $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie;
1444
+
1445
+        $imagick = new Imagick();
1446
+        $imagick->readImage(realpath($image));
1447
+        $imagick->resizeImage(
1448
+            $destWidth,
1449
+            $destHeight,
1450
+            Imagick::FILTER_LANCZOS,
1451
+            1
1452
+        );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100);
1453
+        $imagick->writeImage($vignette);
1454
+
1455
+        if (!@file_exists($vignette)) {
1456
+            spip_log("echec imagick sur $vignette");
1457
+
1458
+            return;
1459
+        }
1460
+        // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester)
1461
+        $vignette = $destination . '.' . $format_sortie;
1462
+    }
1463
+
1464
+    // netpbm
1465
+    elseif ($process == 'netpbm') {
1466
+        if (!defined('_PNMSCALE_COMMAND')) {
1467
+            define('_PNMSCALE_COMMAND', 'pnmscale');
1468
+        } // Securite : mes_options.php peut preciser le chemin absolu
1469
+        if (_PNMSCALE_COMMAND == '') {
1470
+            return;
1471
+        }
1472
+        $vignette = $destination . '.' . $format_sortie;
1473
+        $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND);
1474
+        if ($format == 'jpg') {
1475
+            $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND);
1476
+            exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1477
+            if (!($s = @filesize($vignette))) {
1478
+                spip_unlink($vignette);
1479
+            }
1480
+            if (!@file_exists($vignette)) {
1481
+                spip_log("echec netpbm-jpg sur $vignette");
1482
+
1483
+                return;
1484
+            }
1485
+        } else {
1486
+            if ($format == 'gif') {
1487
+                $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND);
1488
+                exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1489
+                if (!($s = @filesize($vignette))) {
1490
+                    spip_unlink($vignette);
1491
+                }
1492
+                if (!@file_exists($vignette)) {
1493
+                    spip_log("echec netpbm-gif sur $vignette");
1494
+
1495
+                    return;
1496
+                }
1497
+            } else {
1498
+                if ($format == 'png') {
1499
+                    $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND);
1500
+                    exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette");
1501
+                    if (!($s = @filesize($vignette))) {
1502
+                        spip_unlink($vignette);
1503
+                    }
1504
+                    if (!@file_exists($vignette)) {
1505
+                        spip_log("echec netpbm-png sur $vignette");
1506
+
1507
+                        return;
1508
+                    }
1509
+                }
1510
+            }
1511
+        }
1512
+    }
1513
+
1514
+    // gd ou gd2
1515
+    elseif ($process == 'gd1' or $process == 'gd2') {
1516
+        if (!function_exists('gd_info')) {
1517
+            spip_log('Librairie GD absente !', _LOG_ERREUR);
1518
+
1519
+            return;
1520
+        }
1521
+        if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) {
1522
+            spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels');
1523
+
1524
+            return;
1525
+        }
1526
+        $destFormat = $format_sortie;
1527
+        if (!$destFormat) {
1528
+            spip_log("pas de format pour $image");
1529
+
1530
+            return;
1531
+        }
1532
+
1533
+        $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom'];
1534
+        if (!function_exists($fonction_imagecreatefrom)) {
1535
+            return;
1536
+        }
1537
+        $srcImage = @$fonction_imagecreatefrom($image);
1538
+        if (!$srcImage) {
1539
+            spip_log('echec gd1/gd2');
1540
+
1541
+            return;
1542
+        }
1543
+
1544
+        // Initialisation de l'image destination
1545
+        $destImage = null;
1546
+        if ($process == 'gd2' and $destFormat != 'gif') {
1547
+            $destImage = ImageCreateTrueColor($destWidth, $destHeight);
1548
+        }
1549
+        if (!$destImage) {
1550
+            $destImage = ImageCreate($destWidth, $destHeight);
1551
+        }
1552
+
1553
+        // Recopie de l'image d'origine avec adaptation de la taille
1554
+        $ok = false;
1555
+        if (($process == 'gd2') and function_exists('ImageCopyResampled')) {
1556
+            if ($format == 'gif') {
1557
+                // Si un GIF est transparent,
1558
+                // fabriquer un PNG transparent
1559
+                $transp = imagecolortransparent($srcImage);
1560
+                if ($transp > 0) {
1561
+                    $destFormat = 'png';
1562
+                }
1563
+            }
1564
+            if (in_array($destFormat, _image_extensions_conservent_transparence())) {
1565
+                // Conserver la transparence
1566
+                if (function_exists('imageAntiAlias')) {
1567
+                    imageAntiAlias($destImage, true);
1568
+                }
1569
+                @imagealphablending($destImage, false);
1570
+                @imagesavealpha($destImage, true);
1571
+            }
1572
+            $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1573
+        }
1574
+        if (!$ok) {
1575
+            $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
1576
+        }
1577
+
1578
+        // Sauvegarde de l'image destination
1579
+        $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat";
1580
+        $valeurs['format_dest'] = $format = $destFormat;
1581
+        _image_gd_output($destImage, $valeurs);
1582
+
1583
+        if ($srcImage) {
1584
+            ImageDestroy($srcImage);
1585
+        }
1586
+        ImageDestroy($destImage);
1587
+    }
1588
+
1589
+    if (!$vignette or !$size = @spip_getimagesize($vignette)) {
1590
+        $size = [$destWidth, $destHeight];
1591
+    }
1592
+
1593
+    // Gaffe: en safe mode, pas d'acces a la vignette,
1594
+    // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE
1595
+    if ($size[0] < 1) {
1596
+        $size[0] = $destWidth;
1597
+    }
1598
+    if ($size[1] < 1) {
1599
+        $size[1] = $destHeight;
1600
+    }
1601
+
1602
+    $retour['width'] = $largeur = $size[0];
1603
+    $retour['height'] = $hauteur = $size[1];
1604
+
1605
+    $retour['fichier'] = $vignette;
1606
+    $retour['format'] = $format;
1607
+    $retour['date'] = @filemtime($vignette);
1608
+
1609
+    // renvoyer l'image
1610
+    return $retour;
1611 1611
 }
1612 1612
 
1613 1613
 /**
@@ -1627,25 +1627,25 @@  discard block
 block discarded – undo
1627 1627
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1628 1628
  **/
1629 1629
 function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1630
-	$ratioWidth = $srcWidth / $maxWidth;
1631
-	$ratioHeight = $srcHeight / $maxHeight;
1632
-
1633
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1634
-		$destWidth = $srcWidth;
1635
-		$destHeight = $srcHeight;
1636
-	} elseif ($ratioWidth < $ratioHeight) {
1637
-		$destWidth = $srcWidth / $ratioHeight;
1638
-		$destHeight = $maxHeight;
1639
-	} else {
1640
-		$destWidth = $maxWidth;
1641
-		$destHeight = $srcHeight / $ratioWidth;
1642
-	}
1643
-
1644
-	return [
1645
-		intval(round($destWidth)),
1646
-		intval(round($destHeight)),
1647
-		max($ratioWidth, $ratioHeight)
1648
-	];
1630
+    $ratioWidth = $srcWidth / $maxWidth;
1631
+    $ratioHeight = $srcHeight / $maxHeight;
1632
+
1633
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1634
+        $destWidth = $srcWidth;
1635
+        $destHeight = $srcHeight;
1636
+    } elseif ($ratioWidth < $ratioHeight) {
1637
+        $destWidth = $srcWidth / $ratioHeight;
1638
+        $destHeight = $maxHeight;
1639
+    } else {
1640
+        $destWidth = $maxWidth;
1641
+        $destHeight = $srcHeight / $ratioWidth;
1642
+    }
1643
+
1644
+    return [
1645
+        intval(round($destWidth)),
1646
+        intval(round($destHeight)),
1647
+        max($ratioWidth, $ratioHeight)
1648
+    ];
1649 1649
 }
1650 1650
 
1651 1651
 /**
@@ -1665,25 +1665,25 @@  discard block
 block discarded – undo
1665 1665
  * @return array Liste [ largeur, hauteur, ratio de réduction ]
1666 1666
  **/
1667 1667
 function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array {
1668
-	$ratioWidth = $srcWidth / $maxWidth;
1669
-	$ratioHeight = $srcHeight / $maxHeight;
1670
-
1671
-	if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1672
-		$destWidth = $srcWidth;
1673
-		$destHeight = $srcHeight;
1674
-	} elseif ($ratioWidth > $ratioHeight) {
1675
-		$destWidth = $srcWidth / $ratioHeight;
1676
-		$destHeight = $maxHeight;
1677
-	} else {
1678
-		$destWidth = $maxWidth;
1679
-		$destHeight = $srcHeight / $ratioWidth;
1680
-	}
1681
-
1682
-	return [
1683
-		intval(round($destWidth)),
1684
-		intval(round($destHeight)),
1685
-		min($ratioWidth, $ratioHeight)
1686
-	];
1668
+    $ratioWidth = $srcWidth / $maxWidth;
1669
+    $ratioHeight = $srcHeight / $maxHeight;
1670
+
1671
+    if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) {
1672
+        $destWidth = $srcWidth;
1673
+        $destHeight = $srcHeight;
1674
+    } elseif ($ratioWidth > $ratioHeight) {
1675
+        $destWidth = $srcWidth / $ratioHeight;
1676
+        $destHeight = $maxHeight;
1677
+    } else {
1678
+        $destWidth = $maxWidth;
1679
+        $destHeight = $srcHeight / $ratioWidth;
1680
+    }
1681
+
1682
+    return [
1683
+        intval(round($destWidth)),
1684
+        intval(round($destHeight)),
1685
+        min($ratioWidth, $ratioHeight)
1686
+    ];
1687 1687
 }
1688 1688
 
1689 1689
 
@@ -1696,12 +1696,12 @@  discard block
 block discarded – undo
1696 1696
  * @return string
1697 1697
  */
1698 1698
 function process_image_svg_identite($image) {
1699
-	if ($image['creer']) {
1700
-		$source = $image['fichier'];
1701
-		_image_gd_output($source, $image);
1702
-	}
1699
+    if ($image['creer']) {
1700
+        $source = $image['fichier'];
1701
+        _image_gd_output($source, $image);
1702
+    }
1703 1703
 
1704
-	return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1704
+    return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1705 1705
 }
1706 1706
 
1707 1707
 
@@ -1734,109 +1734,109 @@  discard block
 block discarded – undo
1734 1734
  *     Code HTML de la balise img produite
1735 1735
  **/
1736 1736
 function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') {
1737
-	$image = false;
1738
-	if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1739
-		$process = $GLOBALS['meta']['image_process'];
1740
-	}
1741
-	# determiner le format de sortie
1742
-	$format_sortie = false; // le choix par defaut sera bon
1743
-	if ($process == 'netpbm') {
1744
-		$format_sortie = 'jpg';
1745
-	} elseif ($process == 'gd1' or $process == 'gd2') {
1746
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1747
-		// on verifie que l'extension choisie est bonne (en principe oui)
1748
-		$gd_formats = formats_image_acceptables(true);
1749
-		if (
1750
-			is_array($image)
1751
-			and (!in_array($image['format_dest'], $gd_formats)
1752
-				or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1753
-			)
1754
-		) {
1755
-			if ($image['format_source'] == 'jpg') {
1756
-				$formats_sortie = ['jpg', 'png', 'gif'];
1757
-			} else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1758
-			{
1759
-				$formats_sortie = ['png', 'jpg', 'gif'];
1760
-			}
1761
-			// Choisir le format destination
1762
-			// - on sauve de preference en JPEG (meilleure compression)
1763
-			// - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1764
-			# bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1765
-			# pas *ecrire*
1766
-			$format_sortie = '';
1767
-			foreach ($formats_sortie as $fmt) {
1768
-				if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1769
-					$format_sortie = $fmt;
1770
-					break;
1771
-				}
1772
-			}
1773
-			$image = false;
1774
-		}
1775
-	}
1776
-
1777
-	if (!is_array($image)) {
1778
-		$image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1779
-	}
1780
-
1781
-	if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1782
-		spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1783
-		// on peut resizer en mode html si on dispose des elements
1784
-		[$srcw, $srch] = taille_image($img);
1785
-		if ($srcw and $srch) {
1786
-			[$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1787
-
1788
-			return _image_tag_changer_taille($img, $w, $h);
1789
-		}
1790
-		// la on n'a pas d'infos sur l'image source... on refile le truc a css
1791
-		// sous la forme style='max-width: NNpx;'
1792
-		return inserer_attribut(
1793
-			$img,
1794
-			'style',
1795
-			"max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1796
-		);
1797
-	}
1798
-
1799
-	// si l'image est plus petite que la cible retourner une copie cachee de l'image
1800
-	if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1801
-		if ($image['creer']) {
1802
-			@copy($image['fichier'], $image['fichier_dest']);
1803
-		}
1804
-
1805
-		return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1806
-	}
1807
-
1808
-	if ($image['creer'] == false && !$force) {
1809
-		return _image_ecrire_tag(
1810
-			$image,
1811
-			['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1812
-		);
1813
-	}
1814
-
1815
-	if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1816
-		$destWidth = $image['largeur_dest'];
1817
-		$destHeight = $image['hauteur_dest'];
1818
-		$logo = $image['fichier'];
1819
-		$date = $image['date_src'];
1820
-		$preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1821
-
1822
-		if ($preview && $preview['fichier']) {
1823
-			$logo = $preview['fichier'];
1824
-			$destWidth = $preview['width'];
1825
-			$destHeight = $preview['height'];
1826
-			$date = $preview['date'];
1827
-		}
1828
-		// dans l'espace prive mettre un timestamp sur l'adresse
1829
-		// de l'image, de facon a tromper le cache du navigateur
1830
-		// quand on fait supprimer/reuploader un logo
1831
-		// (pas de filemtime si SAFE MODE)
1832
-		$date = test_espace_prive() ? ('?' . $date) : '';
1833
-
1834
-		return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1835
-	}
1836
-	else {
1837
-		# BMP, tiff ... les redacteurs osent tout!
1838
-		return $img;
1839
-	}
1737
+    $image = false;
1738
+    if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) {
1739
+        $process = $GLOBALS['meta']['image_process'];
1740
+    }
1741
+    # determiner le format de sortie
1742
+    $format_sortie = false; // le choix par defaut sera bon
1743
+    if ($process == 'netpbm') {
1744
+        $format_sortie = 'jpg';
1745
+    } elseif ($process == 'gd1' or $process == 'gd2') {
1746
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1747
+        // on verifie que l'extension choisie est bonne (en principe oui)
1748
+        $gd_formats = formats_image_acceptables(true);
1749
+        if (
1750
+            is_array($image)
1751
+            and (!in_array($image['format_dest'], $gd_formats)
1752
+                or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie()))
1753
+            )
1754
+        ) {
1755
+            if ($image['format_source'] == 'jpg') {
1756
+                $formats_sortie = ['jpg', 'png', 'gif'];
1757
+            } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images
1758
+            {
1759
+                $formats_sortie = ['png', 'jpg', 'gif'];
1760
+            }
1761
+            // Choisir le format destination
1762
+            // - on sauve de preference en JPEG (meilleure compression)
1763
+            // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire
1764
+            # bug : gd_formats contient la liste des fichiers qu'on sait *lire*,
1765
+            # pas *ecrire*
1766
+            $format_sortie = '';
1767
+            foreach ($formats_sortie as $fmt) {
1768
+                if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) {
1769
+                    $format_sortie = $fmt;
1770
+                    break;
1771
+                }
1772
+            }
1773
+            $image = false;
1774
+        }
1775
+    }
1776
+
1777
+    if (!is_array($image)) {
1778
+        $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED);
1779
+    }
1780
+
1781
+    if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) {
1782
+        spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge");
1783
+        // on peut resizer en mode html si on dispose des elements
1784
+        [$srcw, $srch] = taille_image($img);
1785
+        if ($srcw and $srch) {
1786
+            [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y);
1787
+
1788
+            return _image_tag_changer_taille($img, $w, $h);
1789
+        }
1790
+        // la on n'a pas d'infos sur l'image source... on refile le truc a css
1791
+        // sous la forme style='max-width: NNpx;'
1792
+        return inserer_attribut(
1793
+            $img,
1794
+            'style',
1795
+            "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px"
1796
+        );
1797
+    }
1798
+
1799
+    // si l'image est plus petite que la cible retourner une copie cachee de l'image
1800
+    if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) {
1801
+        if ($image['creer']) {
1802
+            @copy($image['fichier'], $image['fichier_dest']);
1803
+        }
1804
+
1805
+        return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]);
1806
+    }
1807
+
1808
+    if ($image['creer'] == false && !$force) {
1809
+        return _image_ecrire_tag(
1810
+            $image,
1811
+            ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']]
1812
+        );
1813
+    }
1814
+
1815
+    if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) {
1816
+        $destWidth = $image['largeur_dest'];
1817
+        $destHeight = $image['hauteur_dest'];
1818
+        $logo = $image['fichier'];
1819
+        $date = $image['date_src'];
1820
+        $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force);
1821
+
1822
+        if ($preview && $preview['fichier']) {
1823
+            $logo = $preview['fichier'];
1824
+            $destWidth = $preview['width'];
1825
+            $destHeight = $preview['height'];
1826
+            $date = $preview['date'];
1827
+        }
1828
+        // dans l'espace prive mettre un timestamp sur l'adresse
1829
+        // de l'image, de facon a tromper le cache du navigateur
1830
+        // quand on fait supprimer/reuploader un logo
1831
+        // (pas de filemtime si SAFE MODE)
1832
+        $date = test_espace_prive() ? ('?' . $date) : '';
1833
+
1834
+        return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]);
1835
+    }
1836
+    else {
1837
+        # BMP, tiff ... les redacteurs osent tout!
1838
+        return $img;
1839
+    }
1840 1840
 }
1841 1841
 
1842 1842
 /**
@@ -1850,145 +1850,145 @@  discard block
 block discarded – undo
1850 1850
  * Class phpthumb_functions
1851 1851
  */
1852 1852
 class phpthumb_functions {
1853
-	/**
1854
-	 * Retourne la couleur d'un pixel dans une image
1855
-	 *
1856
-	 * @param resource|GdImage $img
1857
-	 * @param int $x
1858
-	 * @param int $y
1859
-	 * @return array|bool
1860
-	 */
1861
-	public static function GetPixelColor(&$img, $x, $y) {
1862
-		if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1863
-			return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1864
-		}
1865
-		return false;
1866
-	}
1867
-
1868
-	/**
1869
-	 * Retourne un nombre dans une représentation en Little Endian
1870
-	 *
1871
-	 * @param int $number
1872
-	 * @param int $minbytes
1873
-	 * @return string
1874
-	 */
1875
-	public static function LittleEndian2String($number, $minbytes = 1) {
1876
-		$intstring = '';
1877
-		while ($number > 0) {
1878
-			$intstring = $intstring . chr($number & 255);
1879
-			$number >>= 8;
1880
-		}
1881
-
1882
-		return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1883
-	}
1884
-
1885
-	/**
1886
-	 * Transforme une ressource GD en image au format ICO
1887
-	 *
1888
-	 * @param array $gd_image_array
1889
-	 *     Tableau de ressources d'images GD
1890
-	 * @return string
1891
-	 *     Image au format ICO
1892
-	 */
1893
-	public static function GD2ICOstring(&$gd_image_array) {
1894
-		foreach ($gd_image_array as $key => $gd_image) {
1895
-			$ImageWidths[$key] = ImageSX($gd_image);
1896
-			$ImageHeights[$key] = ImageSY($gd_image);
1897
-			$bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1898
-			$totalcolors[$key] = ImageColorsTotal($gd_image);
1899
-
1900
-			$icXOR[$key] = '';
1901
-			for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1902
-				for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1903
-					$argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1904
-					$a = round(255 * ((127 - $argb['alpha']) / 127));
1905
-					$r = $argb['red'];
1906
-					$g = $argb['green'];
1907
-					$b = $argb['blue'];
1908
-
1909
-					if ($bpp[$key] == 32) {
1910
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1911
-					} elseif ($bpp[$key] == 24) {
1912
-						$icXOR[$key] .= chr($b) . chr($g) . chr($r);
1913
-					}
1914
-
1915
-					if ($a < 128) {
1916
-						@$icANDmask[$key][$y] .= '1';
1917
-					} else {
1918
-						@$icANDmask[$key][$y] .= '0';
1919
-					}
1920
-				}
1921
-				// mask bits are 32-bit aligned per scanline
1922
-				while (strlen($icANDmask[$key][$y]) % 32) {
1923
-					$icANDmask[$key][$y] .= '0';
1924
-				}
1925
-			}
1926
-			$icAND[$key] = '';
1927
-			foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1928
-				for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1929
-					$icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1930
-				}
1931
-			}
1932
-		}
1933
-
1934
-		foreach ($gd_image_array as $key => $gd_image) {
1935
-			$biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1936
-
1937
-			// BITMAPINFOHEADER - 40 bytes
1938
-			$BitmapInfoHeader[$key] = '';
1939
-			$BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1940
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1941
-			// The biHeight member specifies the combined
1942
-			// height of the XOR and AND masks.
1943
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1944
-			$BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1945
-			$BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1946
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1947
-			$BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1948
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1949
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1950
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1951
-			$BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1952
-		}
1953
-
1954
-
1955
-		$icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1956
-		$icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1957
-		$icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1958
-
1959
-		$dwImageOffset = 6 + (count($gd_image_array) * 16);
1960
-		foreach ($gd_image_array as $key => $gd_image) {
1961
-			// ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1962
-
1963
-			$icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1964
-			$icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1965
-			$icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1966
-			$icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1967
-
1968
-			$icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1969
-			$icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1970
-
1971
-			$dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1972
-			$icondata .= phpthumb_functions::LittleEndian2String(
1973
-				$dwBytesInRes,
1974
-				4
1975
-			);     // dwBytesInRes;	// How many bytes in this resource?
1976
-
1977
-			$icondata .= phpthumb_functions::LittleEndian2String(
1978
-				$dwImageOffset,
1979
-				4
1980
-			);    // dwImageOffset;   // Where in the file is this image?
1981
-			$dwImageOffset += strlen($BitmapInfoHeader[$key]);
1982
-			$dwImageOffset += strlen($icXOR[$key]);
1983
-			$dwImageOffset += strlen($icAND[$key]);
1984
-		}
1985
-
1986
-		foreach ($gd_image_array as $key => $gd_image) {
1987
-			$icondata .= $BitmapInfoHeader[$key];
1988
-			$icondata .= $icXOR[$key];
1989
-			$icondata .= $icAND[$key];
1990
-		}
1991
-
1992
-		return $icondata;
1993
-	}
1853
+    /**
1854
+     * Retourne la couleur d'un pixel dans une image
1855
+     *
1856
+     * @param resource|GdImage $img
1857
+     * @param int $x
1858
+     * @param int $y
1859
+     * @return array|bool
1860
+     */
1861
+    public static function GetPixelColor(&$img, $x, $y) {
1862
+        if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) {
1863
+            return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y));
1864
+        }
1865
+        return false;
1866
+    }
1867
+
1868
+    /**
1869
+     * Retourne un nombre dans une représentation en Little Endian
1870
+     *
1871
+     * @param int $number
1872
+     * @param int $minbytes
1873
+     * @return string
1874
+     */
1875
+    public static function LittleEndian2String($number, $minbytes = 1) {
1876
+        $intstring = '';
1877
+        while ($number > 0) {
1878
+            $intstring = $intstring . chr($number & 255);
1879
+            $number >>= 8;
1880
+        }
1881
+
1882
+        return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
1883
+    }
1884
+
1885
+    /**
1886
+     * Transforme une ressource GD en image au format ICO
1887
+     *
1888
+     * @param array $gd_image_array
1889
+     *     Tableau de ressources d'images GD
1890
+     * @return string
1891
+     *     Image au format ICO
1892
+     */
1893
+    public static function GD2ICOstring(&$gd_image_array) {
1894
+        foreach ($gd_image_array as $key => $gd_image) {
1895
+            $ImageWidths[$key] = ImageSX($gd_image);
1896
+            $ImageHeights[$key] = ImageSY($gd_image);
1897
+            $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24;
1898
+            $totalcolors[$key] = ImageColorsTotal($gd_image);
1899
+
1900
+            $icXOR[$key] = '';
1901
+            for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) {
1902
+                for ($x = 0; $x < $ImageWidths[$key]; $x++) {
1903
+                    $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y);
1904
+                    $a = round(255 * ((127 - $argb['alpha']) / 127));
1905
+                    $r = $argb['red'];
1906
+                    $g = $argb['green'];
1907
+                    $b = $argb['blue'];
1908
+
1909
+                    if ($bpp[$key] == 32) {
1910
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a);
1911
+                    } elseif ($bpp[$key] == 24) {
1912
+                        $icXOR[$key] .= chr($b) . chr($g) . chr($r);
1913
+                    }
1914
+
1915
+                    if ($a < 128) {
1916
+                        @$icANDmask[$key][$y] .= '1';
1917
+                    } else {
1918
+                        @$icANDmask[$key][$y] .= '0';
1919
+                    }
1920
+                }
1921
+                // mask bits are 32-bit aligned per scanline
1922
+                while (strlen($icANDmask[$key][$y]) % 32) {
1923
+                    $icANDmask[$key][$y] .= '0';
1924
+                }
1925
+            }
1926
+            $icAND[$key] = '';
1927
+            foreach ($icANDmask[$key] as $y => $scanlinemaskbits) {
1928
+                for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) {
1929
+                    $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT)));
1930
+                }
1931
+            }
1932
+        }
1933
+
1934
+        foreach ($gd_image_array as $key => $gd_image) {
1935
+            $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8);
1936
+
1937
+            // BITMAPINFOHEADER - 40 bytes
1938
+            $BitmapInfoHeader[$key] = '';
1939
+            $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00";                // DWORD  biSize;
1940
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4);    // LONG   biWidth;
1941
+            // The biHeight member specifies the combined
1942
+            // height of the XOR and AND masks.
1943
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG   biHeight;
1944
+            $BitmapInfoHeader[$key] .= "\x01\x00";                    // WORD   biPlanes;
1945
+            $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00";              // wBitCount;
1946
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biCompression;
1947
+            $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4);      // DWORD  biSizeImage;
1948
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biXPelsPerMeter;
1949
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // LONG   biYPelsPerMeter;
1950
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrUsed;
1951
+            $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00";                // DWORD  biClrImportant;
1952
+        }
1953
+
1954
+
1955
+        $icondata = "\x00\x00";                    // idReserved;   // Reserved (must be 0)
1956
+        $icondata .= "\x01\x00";                    // idType;	   // Resource Type (1 for icons)
1957
+        $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2);  // idCount;	  // How many images?
1958
+
1959
+        $dwImageOffset = 6 + (count($gd_image_array) * 16);
1960
+        foreach ($gd_image_array as $key => $gd_image) {
1961
+            // ICONDIRENTRY   idEntries[1]; // An entry for each image (idCount of 'em)
1962
+
1963
+            $icondata .= chr($ImageWidths[$key]);           // bWidth;		  // Width, in pixels, of the image
1964
+            $icondata .= chr($ImageHeights[$key]);          // bHeight;		 // Height, in pixels, of the image
1965
+            $icondata .= chr($totalcolors[$key]);           // bColorCount;	 // Number of colors in image (0 if >=8bpp)
1966
+            $icondata .= "\x00";                    // bReserved;	   // Reserved ( must be 0)
1967
+
1968
+            $icondata .= "\x01\x00";                  // wPlanes;		 // Color Planes
1969
+            $icondata .= chr($bpp[$key]) . "\x00";            // wBitCount;	   // Bits per pixel
1970
+
1971
+            $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]);
1972
+            $icondata .= phpthumb_functions::LittleEndian2String(
1973
+                $dwBytesInRes,
1974
+                4
1975
+            );     // dwBytesInRes;	// How many bytes in this resource?
1976
+
1977
+            $icondata .= phpthumb_functions::LittleEndian2String(
1978
+                $dwImageOffset,
1979
+                4
1980
+            );    // dwImageOffset;   // Where in the file is this image?
1981
+            $dwImageOffset += strlen($BitmapInfoHeader[$key]);
1982
+            $dwImageOffset += strlen($icXOR[$key]);
1983
+            $dwImageOffset += strlen($icAND[$key]);
1984
+        }
1985
+
1986
+        foreach ($gd_image_array as $key => $gd_image) {
1987
+            $icondata .= $BitmapInfoHeader[$key];
1988
+            $icondata .= $icXOR[$key];
1989
+            $icondata .= $icAND[$key];
1990
+        }
1991
+
1992
+        return $icondata;
1993
+    }
1994 1994
 }
Please login to merge, or discard this patch.
ecrire/inc/filtres_mini.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  **/
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
  * @return string URL nettoyée
36 36
  **/
37 37
 function resolve_path($url) {
38
-	[$url, $query] = array_pad(explode('?', $url, 2), 2, null);
39
-	while (
40
-		preg_match(',/\.?/,', $url, $regs)    # supprime // et /./
41
-		or preg_match(',/[^/]*/\.\./,S', $url, $regs)  # supprime /toto/../
42
-		or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut
43
-	) {
44
-		$url = str_replace($regs[0], '/', $url);
45
-	}
38
+    [$url, $query] = array_pad(explode('?', $url, 2), 2, null);
39
+    while (
40
+        preg_match(',/\.?/,', $url, $regs)    # supprime // et /./
41
+        or preg_match(',/[^/]*/\.\./,S', $url, $regs)  # supprime /toto/../
42
+        or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut
43
+    ) {
44
+        $url = str_replace($regs[0], '/', $url);
45
+    }
46 46
 
47
-	if ($query) {
48
-		$url .= '?' . $query;
49
-	}
47
+    if ($query) {
48
+        $url .= '?' . $query;
49
+    }
50 50
 
51
-	return '/' . preg_replace(',^/,S', '', $url);
51
+    return '/' . preg_replace(',^/,S', '', $url);
52 52
 }
53 53
 
54 54
 
@@ -69,44 +69,44 @@  discard block
 block discarded – undo
69 69
  **/
70 70
 function suivre_lien($url, $lien) {
71 71
 
72
-	$mot = null;
73
-	$get = null;
74
-	$hash = null;
75
-	if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
76
-		return $lien;
77
-	}
78
-	if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
79
-		$r = array_pad($r, 3, '');
72
+    $mot = null;
73
+    $get = null;
74
+    $hash = null;
75
+    if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) {
76
+        return $lien;
77
+    }
78
+    if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) {
79
+        $r = array_pad($r, 3, '');
80 80
 
81
-		return $r[1] . resolve_path($r[2]);
82
-	}
81
+        return $r[1] . resolve_path($r[2]);
82
+    }
83 83
 
84
-	# L'url site spip est un lien absolu aussi
85
-	if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) {
86
-		return $lien;
87
-	}
84
+    # L'url site spip est un lien absolu aussi
85
+    if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) {
86
+        return $lien;
87
+    }
88 88
 
89
-	# lien relatif, il faut verifier l'url de base
90
-	# commencer par virer la chaine de get de l'url de base
91
-	$dir = '/';
92
-	$debut = '';
93
-	if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) {
94
-		$debut = $regs[1];
95
-		$dir = !strlen($regs[2]) ? '/' : $regs[2];
96
-		$mot = $regs[3];
97
-		$get = $regs[4] ?? '';
98
-		$hash = $regs[5] ?? '';
99
-	}
100
-	switch (substr($lien, 0, 1)) {
101
-		case '/':
102
-			return $debut . resolve_path($lien);
103
-		case '#':
104
-			return $debut . resolve_path($dir . $mot . $get . $lien);
105
-		case '':
106
-			return $debut . resolve_path($dir . $mot . $get . $hash);
107
-		default:
108
-			return $debut . resolve_path($dir . $lien);
109
-	}
89
+    # lien relatif, il faut verifier l'url de base
90
+    # commencer par virer la chaine de get de l'url de base
91
+    $dir = '/';
92
+    $debut = '';
93
+    if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) {
94
+        $debut = $regs[1];
95
+        $dir = !strlen($regs[2]) ? '/' : $regs[2];
96
+        $mot = $regs[3];
97
+        $get = $regs[4] ?? '';
98
+        $hash = $regs[5] ?? '';
99
+    }
100
+    switch (substr($lien, 0, 1)) {
101
+        case '/':
102
+            return $debut . resolve_path($lien);
103
+        case '#':
104
+            return $debut . resolve_path($dir . $mot . $get . $lien);
105
+        case '':
106
+            return $debut . resolve_path($dir . $mot . $get . $hash);
107
+        default:
108
+            return $debut . resolve_path($dir . $lien);
109
+    }
110 110
 }
111 111
 
112 112
 
@@ -129,15 +129,15 @@  discard block
 block discarded – undo
129 129
  * @return string Texte ou URL (en absolus)
130 130
  **/
131 131
 function url_absolue($url, $base = '') {
132
-	$url = trim((string) $url);
133
-	if (strlen($url = trim($url)) == 0) {
134
-		return '';
135
-	}
136
-	if (!$base) {
137
-		$base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
138
-	}
132
+    $url = trim((string) $url);
133
+    if (strlen($url = trim($url)) == 0) {
134
+        return '';
135
+    }
136
+    if (!$base) {
137
+        $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : '');
138
+    }
139 139
 
140
-	return suivre_lien($base, $url);
140
+    return suivre_lien($base, $url);
141 141
 }
142 142
 
143 143
 /**
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
  * @return string
149 149
  */
150 150
 function protocole_implicite($url_absolue) {
151
-	return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
151
+    return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue);
152 152
 }
153 153
 
154 154
 /**
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) {
161 161
 
162
-	if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
163
-		$protocole = $m[1];
164
-		if (
165
-			in_array($protocole, $protocoles_autorises)
166
-			or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))
167
-		) {
168
-			return true;
169
-		}
170
-	}
171
-	return false;
162
+    if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) {
163
+        $protocole = $m[1];
164
+        if (
165
+            in_array($protocole, $protocoles_autorises)
166
+            or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises))
167
+        ) {
168
+            return true;
169
+        }
170
+    }
171
+    return false;
172 172
 }
173 173
 
174 174
 /**
@@ -185,27 +185,27 @@  discard block
 block discarded – undo
185 185
  * @return string Texte avec des URLs absolues
186 186
  **/
187 187
 function liens_absolus($texte, $base = '') {
188
-	if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) {
189
-		if (!function_exists('extraire_attribut')) {
190
-			include_spip('inc/filtres');
191
-		}
192
-		foreach ($liens as $lien) {
193
-			foreach (['href', 'src'] as $attr) {
194
-				$href = extraire_attribut($lien[0], $attr) ?? '';
195
-				if (strlen($href) > 0) {
196
-					if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) {
197
-						$abs = url_absolue($href, $base);
198
-						if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) {
199
-							$texte_lien = inserer_attribut($lien[0], $attr, $abs);
200
-							$texte = str_replace($lien[0], $texte_lien, $texte);
201
-						}
202
-					}
203
-				}
204
-			}
205
-		}
206
-	}
188
+    if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) {
189
+        if (!function_exists('extraire_attribut')) {
190
+            include_spip('inc/filtres');
191
+        }
192
+        foreach ($liens as $lien) {
193
+            foreach (['href', 'src'] as $attr) {
194
+                $href = extraire_attribut($lien[0], $attr) ?? '';
195
+                if (strlen($href) > 0) {
196
+                    if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) {
197
+                        $abs = url_absolue($href, $base);
198
+                        if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) {
199
+                            $texte_lien = inserer_attribut($lien[0], $attr, $abs);
200
+                            $texte = str_replace($lien[0], $texte_lien, $texte);
201
+                        }
202
+                    }
203
+                }
204
+            }
205
+        }
206
+    }
207 207
 
208
-	return $texte;
208
+    return $texte;
209 209
 }
210 210
 
211 211
 
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
  * @return string Texte ou URL (en absolus)
222 222
  **/
223 223
 function abs_url($texte, $base = '') {
224
-	if ($GLOBALS['mode_abs_url'] == 'url') {
225
-		return url_absolue($texte, $base);
226
-	} else {
227
-		return liens_absolus($texte, $base);
228
-	}
224
+    if ($GLOBALS['mode_abs_url'] == 'url') {
225
+        return url_absolue($texte, $base);
226
+    } else {
227
+        return liens_absolus($texte, $base);
228
+    }
229 229
 }
230 230
 
231 231
 /**
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
  * @return string
239 239
  */
240 240
 function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) {
241
-	if (is_null($flags)) {
242
-		$flags = ENT_COMPAT | ENT_HTML401;
243
-	}
241
+    if (is_null($flags)) {
242
+        $flags = ENT_COMPAT | ENT_HTML401;
243
+    }
244 244
 
245
-	return htmlspecialchars($string, $flags, $encoding, $double_encode);
245
+    return htmlspecialchars($string, $flags, $encoding, $double_encode);
246 246
 }
247 247
 
248 248
 /**
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
  * @return string
256 256
  */
257 257
 function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) {
258
-	if (is_null($flags)) {
259
-		$flags = ENT_COMPAT | ENT_HTML401;
260
-	}
258
+    if (is_null($flags)) {
259
+        $flags = ENT_COMPAT | ENT_HTML401;
260
+    }
261 261
 
262
-	return htmlentities($string, $flags, $encoding, $double_encode);
262
+    return htmlentities($string, $flags, $encoding, $double_encode);
263 263
 }
Please login to merge, or discard this patch.