Completed
Push — master ( ad4f09...6d727b )
by cam
01:02 queued 13s
created
ecrire/inc/svg.php 3 patches
Indentation   +429 added lines, -429 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
  **/
17 17
 
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 if (!defined('IMG_SVG')) {
23
-	// complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
24
-	define('IMG_SVG', 128);
25
-	define('IMAGETYPE_SVG', 19);
23
+    // complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
24
+    define('IMG_SVG', 128);
25
+    define('IMAGETYPE_SVG', 19);
26 26
 }
27 27
 
28 28
 /**
@@ -38,34 +38,34 @@  discard block
 block discarded – undo
38 38
  *   false si on a pas pu charger l'image
39 39
  */
40 40
 function svg_charger($fichier, $maxlen = null) {
41
-	if (str_starts_with($fichier, 'data:image/svg+xml')) {
42
-		$image = explode(';', $fichier, 2);
43
-		$image = end($image);
44
-		if (str_starts_with($image, 'base64,')) {
45
-			$image = base64_decode(substr($image, 7));
46
-		}
47
-		if (str_contains($image, '<svg')) {
48
-			return $image;
49
-		}
50
-		// encodage inconnu ou autre format d'image ?
51
-		return false;
52
-	}
53
-	// c'est peut etre deja une image svg ?
54
-	if (str_contains($fichier, '<svg')) {
55
-		return $fichier;
56
-	}
57
-	if (!file_exists($fichier)) {
58
-		$fichier  = supprimer_timestamp($fichier);
59
-		if (!file_exists($fichier)) {
60
-			return false;
61
-		}
62
-	}
63
-	$image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen);
64
-	// est-ce bien une image svg ?
65
-	if (str_contains($image, '<svg')) {
66
-		return $image;
67
-	}
68
-	return false;
41
+    if (str_starts_with($fichier, 'data:image/svg+xml')) {
42
+        $image = explode(';', $fichier, 2);
43
+        $image = end($image);
44
+        if (str_starts_with($image, 'base64,')) {
45
+            $image = base64_decode(substr($image, 7));
46
+        }
47
+        if (str_contains($image, '<svg')) {
48
+            return $image;
49
+        }
50
+        // encodage inconnu ou autre format d'image ?
51
+        return false;
52
+    }
53
+    // c'est peut etre deja une image svg ?
54
+    if (str_contains($fichier, '<svg')) {
55
+        return $fichier;
56
+    }
57
+    if (!file_exists($fichier)) {
58
+        $fichier  = supprimer_timestamp($fichier);
59
+        if (!file_exists($fichier)) {
60
+            return false;
61
+        }
62
+    }
63
+    $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen);
64
+    // est-ce bien une image svg ?
65
+    if (str_contains($image, '<svg')) {
66
+        return $image;
67
+    }
68
+    return false;
69 69
 }
70 70
 
71 71
 /**
@@ -74,28 +74,28 @@  discard block
 block discarded – undo
74 74
  * @return array|bool
75 75
  */
76 76
 function svg_lire_balise_svg($fichier) {
77
-	if (!$debut_fichier = svg_charger($fichier, 4096)) {
78
-		return false;
79
-	}
80
-
81
-	if (($ps = stripos($debut_fichier, '<svg')) !== false) {
82
-		$pe = stripos($debut_fichier, '>', $ps);
83
-		$balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
84
-
85
-		if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
86
-			if (!function_exists('extraire_attribut')) {
87
-				include_spip('inc/filtres');
88
-			}
89
-			$attributs = [];
90
-			foreach ($matches[1] as $att) {
91
-				$attributs[$att] = extraire_attribut($balise_svg, $att);
92
-			}
93
-
94
-			return [$balise_svg, $attributs];
95
-		}
96
-	}
97
-
98
-	return false;
77
+    if (!$debut_fichier = svg_charger($fichier, 4096)) {
78
+        return false;
79
+    }
80
+
81
+    if (($ps = stripos($debut_fichier, '<svg')) !== false) {
82
+        $pe = stripos($debut_fichier, '>', $ps);
83
+        $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
84
+
85
+        if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
86
+            if (!function_exists('extraire_attribut')) {
87
+                include_spip('inc/filtres');
88
+            }
89
+            $attributs = [];
90
+            foreach ($matches[1] as $att) {
91
+                $attributs[$att] = extraire_attribut($balise_svg, $att);
92
+            }
93
+
94
+            return [$balise_svg, $attributs];
95
+        }
96
+    }
97
+
98
+    return false;
99 99
 }
100 100
 
101 101
 /**
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
  */
106 106
 function svg_lire_attributs($img) {
107 107
 
108
-	if ($svg_infos = svg_lire_balise_svg($img)) {
109
-		[$balise_svg, $attributs] = $svg_infos;
110
-		return $attributs;
111
-	}
108
+    if ($svg_infos = svg_lire_balise_svg($img)) {
109
+        [$balise_svg, $attributs] = $svg_infos;
110
+        return $attributs;
111
+    }
112 112
 
113
-	return false;
113
+    return false;
114 114
 }
115 115
 
116 116
 /**
@@ -120,19 +120,19 @@  discard block
 block discarded – undo
120 120
  * @return bool|float|int
121 121
  */
122 122
 function svg_dimension_to_pixels($dimension, $precision = 2) {
123
-	if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
124
-		return match (strtolower($m[2])) {
125
-			'%' => false,
126
-			'em' => round($m[1] * 16, $precision),
127
-			'ex' => round($m[1] * 16, $precision),
128
-			'pc' => round($m[1] * 16, $precision),
129
-			'cm' => round($m[1] * 96 / 2.54, $precision),
130
-			'mm' => round($m[1] * 96 / 25.4, $precision),
131
-			'in' => round($m[1] * 96, $precision),
132
-			default => $m[1],
133
-		};
134
-	}
135
-	return false;
123
+    if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
124
+        return match (strtolower($m[2])) {
125
+            '%' => false,
126
+            'em' => round($m[1] * 16, $precision),
127
+            'ex' => round($m[1] * 16, $precision),
128
+            'pc' => round($m[1] * 16, $precision),
129
+            'cm' => round($m[1] * 96 / 2.54, $precision),
130
+            'mm' => round($m[1] * 96 / 25.4, $precision),
131
+            'in' => round($m[1] * 96, $precision),
132
+            default => $m[1],
133
+        };
134
+    }
135
+    return false;
136 136
 }
137 137
 
138 138
 /**
@@ -143,14 +143,14 @@  discard block
 block discarded – undo
143 143
  * @return string
144 144
  */
145 145
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
146
-	$new_balise_svg = '<svg';
147
-	foreach ($attributs as $k => $v) {
148
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
149
-	}
150
-	$new_balise_svg .= '>';
151
-
152
-	$p = strpos($svg, $old_balise_svg);
153
-	return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
146
+    $new_balise_svg = '<svg';
147
+    foreach ($attributs as $k => $v) {
148
+        $new_balise_svg .= " $k=\"" . entites_html($v) . '"';
149
+    }
150
+    $new_balise_svg .= '>';
151
+
152
+    $p = strpos($svg, $old_balise_svg);
153
+    return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
154 154
 }
155 155
 
156 156
 /**
@@ -162,15 +162,15 @@  discard block
 block discarded – undo
162 162
  */
163 163
 function svg_insert_shapes($svg, $shapes, $start = true) {
164 164
 
165
-	if ($start === false || $start === 'end') {
166
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
167
-	}
168
-	else {
169
-		$p = stripos($svg, '<svg');
170
-		$p = strpos($svg, '>', $p);
171
-		$svg = substr_replace($svg, $shapes, $p + 1, 0);
172
-	}
173
-	return $svg;
165
+    if ($start === false || $start === 'end') {
166
+        $svg = str_replace('</svg>', $shapes . '</svg>', $svg);
167
+    }
168
+    else {
169
+        $p = stripos($svg, '<svg');
170
+        $p = strpos($svg, '>', $p);
171
+        $svg = substr_replace($svg, $shapes, $p + 1, 0);
172
+    }
173
+    return $svg;
174 174
 }
175 175
 
176 176
 /**
@@ -183,12 +183,12 @@  discard block
 block discarded – undo
183 183
  * @return string
184 184
  */
185 185
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
186
-	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
187
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
188
-	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
189
-	$g = "<g clip-path=\"url(#$id)\">";
190
-	$svg = svg_insert_shapes($svg, $clippath . $g);
191
-	return svg_insert_shapes($svg, '</g>', false);
186
+    $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
187
+    $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
188
+    $clippath = "<clipPath id=\"$id\">$rect</clipPath>";
189
+    $g = "<g clip-path=\"url(#$id)\">";
190
+    $svg = svg_insert_shapes($svg, $clippath . $g);
191
+    return svg_insert_shapes($svg, '</g>', false);
192 192
 }
193 193
 
194 194
 /**
@@ -199,20 +199,20 @@  discard block
 block discarded – undo
199 199
  * @return bool|string
200 200
  */
201 201
 function svg_redimensionner($img, $new_width, $new_height) {
202
-	if (
203
-		($svg = svg_charger($img))
204
-		&& ($svg_infos = svg_lire_balise_svg($svg))
205
-	) {
206
-		[$balise_svg, $attributs] = $svg_infos;
207
-		if (!isset($attributs['viewBox'])) {
208
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
209
-		}
210
-		$attributs['width'] = (string) $new_width;
211
-		$attributs['height'] = (string) $new_height;
212
-		return svg_change_balise_svg($svg, $balise_svg, $attributs);
213
-	}
214
-
215
-	return $img;
202
+    if (
203
+        ($svg = svg_charger($img))
204
+        && ($svg_infos = svg_lire_balise_svg($svg))
205
+    ) {
206
+        [$balise_svg, $attributs] = $svg_infos;
207
+        if (!isset($attributs['viewBox'])) {
208
+            $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
209
+        }
210
+        $attributs['width'] = (string) $new_width;
211
+        $attributs['height'] = (string) $new_height;
212
+        return svg_change_balise_svg($svg, $balise_svg, $attributs);
213
+    }
214
+
215
+    return $img;
216 216
 }
217 217
 
218 218
 /**
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
  * @return string
222 222
  */
223 223
 function svg_couleur_to_hexa($couleur) {
224
-	if (str_starts_with($couleur, 'rgb(')) {
225
-		$c = explode(',', substr($couleur, 4));
226
-		$couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]);
227
-	}
228
-	else {
229
-		$couleur = couleur_html_to_hex($couleur);
230
-	}
231
-	return '#' . ltrim($couleur, '#');
224
+    if (str_starts_with($couleur, 'rgb(')) {
225
+        $c = explode(',', substr($couleur, 4));
226
+        $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]);
227
+    }
228
+    else {
229
+        $couleur = couleur_html_to_hex($couleur);
230
+    }
231
+    return '#' . ltrim($couleur, '#');
232 232
 }
233 233
 
234 234
 /**
@@ -237,11 +237,11 @@  discard block
 block discarded – undo
237 237
  * @return array
238 238
  */
239 239
 function svg_couleur_to_rgb($couleur) {
240
-	if (str_starts_with($couleur, 'rgb(')) {
241
-		$c = explode(',', substr($couleur, 4));
242
-		return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]];
243
-	}
244
-	return _couleur_hex_to_dec($couleur);
240
+    if (str_starts_with($couleur, 'rgb(')) {
241
+        $c = explode(',', substr($couleur, 4));
242
+        return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]];
243
+    }
244
+    return _couleur_hex_to_dec($couleur);
245 245
 }
246 246
 
247 247
 
@@ -251,80 +251,80 @@  discard block
 block discarded – undo
251 251
  * @return array
252 252
  */
253 253
 function svg_getimagesize_from_attr($attributs) {
254
-	$width = 350; // default width
255
-	$height = 150; // default height
256
-
257
-	$viewBox = "0 0 $width $height";
258
-	if (isset($attributs['viewBox'])) {
259
-		$viewBox = $attributs['viewBox'];
260
-		$viewBox = preg_replace(',\s+,', ' ', $viewBox);
261
-	}
262
-	// et on la convertit en px
263
-	$viewBox = explode(' ', $viewBox);
264
-	$viewBox = array_map('svg_dimension_to_pixels', $viewBox);
265
-	if (!$viewBox[2]) {
266
-		$viewBox[2] = $width;
267
-	}
268
-	if (!$viewBox[3]) {
269
-		$viewBox[3] = $height;
270
-	}
271
-
272
-	$coeff = 1;
273
-	if (
274
-		isset($attributs['width'])
275
-		&& ($w = svg_dimension_to_pixels($attributs['width']))
276
-	) {
277
-		$width = $w;
278
-		// si on avait pas de viewBox, la construire a partir de ce width
279
-		if (empty($attributs['viewBox'])) {
280
-			$viewBox[2] = $width;
281
-			// si pas de height valide, on suppose l'image carree
282
-			$viewBox[3] = $width;
283
-		}
284
-	}
285
-	else {
286
-		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
287
-		$width = $viewBox[2];
288
-		if ($width < 1) {
289
-			$coeff = max($coeff, 1000);
290
-		}
291
-		elseif ($width < 10) {
292
-			$coeff = max($coeff, 100);
293
-		}
294
-		elseif ($width < 100) {
295
-			$coeff = max($coeff, 10);
296
-		}
297
-	}
298
-	if (
299
-		isset($attributs['height'])
300
-		&& ($h = svg_dimension_to_pixels($attributs['height']))
301
-	) {
302
-		$height = $h;
303
-		// si on avait pas de viewBox, la construire a partir de ce height
304
-		if (empty($attributs['viewBox'])) {
305
-			$viewBox[3] = $height;
306
-		}
307
-	}
308
-	else {
309
-		$height = $viewBox[3];
310
-		if ($height < 1) {
311
-			$coeff = max($coeff, 1000);
312
-		}
313
-		elseif ($height < 10) {
314
-			$coeff = max($coeff, 100);
315
-		}
316
-		elseif ($height < 100) {
317
-			$coeff = max($coeff, 10);
318
-		}
319
-	}
320
-
321
-	// arrondir le width et height en pixel in fine
322
-	$width = round($coeff * $width);
323
-	$height = round($coeff * $height);
324
-
325
-	$viewBox = implode(' ', $viewBox);
326
-
327
-	return [$width, $height, $viewBox];
254
+    $width = 350; // default width
255
+    $height = 150; // default height
256
+
257
+    $viewBox = "0 0 $width $height";
258
+    if (isset($attributs['viewBox'])) {
259
+        $viewBox = $attributs['viewBox'];
260
+        $viewBox = preg_replace(',\s+,', ' ', $viewBox);
261
+    }
262
+    // et on la convertit en px
263
+    $viewBox = explode(' ', $viewBox);
264
+    $viewBox = array_map('svg_dimension_to_pixels', $viewBox);
265
+    if (!$viewBox[2]) {
266
+        $viewBox[2] = $width;
267
+    }
268
+    if (!$viewBox[3]) {
269
+        $viewBox[3] = $height;
270
+    }
271
+
272
+    $coeff = 1;
273
+    if (
274
+        isset($attributs['width'])
275
+        && ($w = svg_dimension_to_pixels($attributs['width']))
276
+    ) {
277
+        $width = $w;
278
+        // si on avait pas de viewBox, la construire a partir de ce width
279
+        if (empty($attributs['viewBox'])) {
280
+            $viewBox[2] = $width;
281
+            // si pas de height valide, on suppose l'image carree
282
+            $viewBox[3] = $width;
283
+        }
284
+    }
285
+    else {
286
+        // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
287
+        $width = $viewBox[2];
288
+        if ($width < 1) {
289
+            $coeff = max($coeff, 1000);
290
+        }
291
+        elseif ($width < 10) {
292
+            $coeff = max($coeff, 100);
293
+        }
294
+        elseif ($width < 100) {
295
+            $coeff = max($coeff, 10);
296
+        }
297
+    }
298
+    if (
299
+        isset($attributs['height'])
300
+        && ($h = svg_dimension_to_pixels($attributs['height']))
301
+    ) {
302
+        $height = $h;
303
+        // si on avait pas de viewBox, la construire a partir de ce height
304
+        if (empty($attributs['viewBox'])) {
305
+            $viewBox[3] = $height;
306
+        }
307
+    }
308
+    else {
309
+        $height = $viewBox[3];
310
+        if ($height < 1) {
311
+            $coeff = max($coeff, 1000);
312
+        }
313
+        elseif ($height < 10) {
314
+            $coeff = max($coeff, 100);
315
+        }
316
+        elseif ($height < 100) {
317
+            $coeff = max($coeff, 10);
318
+        }
319
+    }
320
+
321
+    // arrondir le width et height en pixel in fine
322
+    $width = round($coeff * $width);
323
+    $height = round($coeff * $height);
324
+
325
+    $viewBox = implode(' ', $viewBox);
326
+
327
+    return [$width, $height, $viewBox];
328 328
 }
329 329
 
330 330
 /**
@@ -340,23 +340,23 @@  discard block
 block discarded – undo
340 340
  * @return string
341 341
  */
342 342
 function svg_force_viewBox_px($img, $force_width_and_height = false) {
343
-	if (
344
-		($svg = svg_charger($img))
345
-		&& ($svg_infos = svg_lire_balise_svg($svg))
346
-	) {
347
-		[$balise_svg, $attributs] = $svg_infos;
348
-
349
-		[$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs);
350
-
351
-		if ($force_width_and_height) {
352
-			$attributs['width'] = $width;
353
-			$attributs['height'] = $height;
354
-		}
355
-
356
-		$attributs['viewBox'] = $viewBox;
357
-		return svg_change_balise_svg($svg, $balise_svg, $attributs);
358
-	}
359
-	return $img;
343
+    if (
344
+        ($svg = svg_charger($img))
345
+        && ($svg_infos = svg_lire_balise_svg($svg))
346
+    ) {
347
+        [$balise_svg, $attributs] = $svg_infos;
348
+
349
+        [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs);
350
+
351
+        if ($force_width_and_height) {
352
+            $attributs['width'] = $width;
353
+            $attributs['height'] = $height;
354
+        }
355
+
356
+        $attributs['viewBox'] = $viewBox;
357
+        return svg_change_balise_svg($svg, $balise_svg, $attributs);
358
+    }
359
+    return $img;
360 360
 }
361 361
 
362 362
 /**
@@ -365,13 +365,13 @@  discard block
 block discarded – undo
365 365
  * @return array|mixed
366 366
  */
367 367
 function svg_extract_couleurs($img) {
368
-	if (
369
-		($svg = svg_charger($img))
370
-		&& preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)
371
-	) {
372
-		return $matches[0];
373
-	}
374
-	return [];
368
+    if (
369
+        ($svg = svg_charger($img))
370
+        && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)
371
+    ) {
372
+        return $matches[0];
373
+    }
374
+    return [];
375 375
 }
376 376
 
377 377
 /**
@@ -382,58 +382,58 @@  discard block
 block discarded – undo
382 382
  * @return bool|string
383 383
  */
384 384
 function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') {
385
-	if (
386
-		($svg = svg_force_viewBox_px($img))
387
-		&& ($svg_infos = svg_lire_balise_svg($svg))
388
-	) {
389
-		[$balise_svg, $attributs] = $svg_infos;
390
-		$viewBox = explode(' ', $attributs['viewBox']);
391
-
392
-		$viewport_w = $new_width;
393
-		$viewport_h = $new_height;
394
-		$viewport_ox = $offset_width;
395
-		$viewport_oy = $offset_height;
396
-
397
-		// si on a un width/height qui rescale, il faut rescaler
398
-		if (
399
-			isset($attributs['width'])
400
-			&& ($w = svg_dimension_to_pixels($attributs['width']))
401
-			&& isset($attributs['height'])
402
-			&& ($h = svg_dimension_to_pixels($attributs['height']))
403
-		) {
404
-			$xscale = $viewBox[2] / $w;
405
-			$viewport_w = round($viewport_w * $xscale, 2);
406
-			$viewport_ox = round($viewport_ox * $xscale, 2);
407
-			$yscale = $viewBox[3] / $h;
408
-			$viewport_h = round($viewport_h * $yscale, 2);
409
-			$viewport_oy = round($viewport_oy * $yscale, 2);
410
-		}
411
-
412
-		if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) {
413
-			$svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
414
-		}
415
-
416
-		// maintenant on redefinit la viewBox
417
-		$viewBox[0] += $viewport_ox;
418
-		$viewBox[1] += $viewport_oy;
419
-		$viewBox[2] = $viewport_w;
420
-		$viewBox[3] = $viewport_h;
421
-
422
-		$attributs['viewBox'] = implode(' ', $viewBox);
423
-		$attributs['width'] = (string) $new_width;
424
-		$attributs['height'] = (string) $new_height;
425
-
426
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
427
-
428
-		// ajouter un background
429
-		if ($background_color && $background_color !== 'transparent') {
430
-			$svg = svg_ajouter_background($svg, $background_color);
431
-		}
432
-
433
-		return $svg;
434
-	}
435
-
436
-	return $img;
385
+    if (
386
+        ($svg = svg_force_viewBox_px($img))
387
+        && ($svg_infos = svg_lire_balise_svg($svg))
388
+    ) {
389
+        [$balise_svg, $attributs] = $svg_infos;
390
+        $viewBox = explode(' ', $attributs['viewBox']);
391
+
392
+        $viewport_w = $new_width;
393
+        $viewport_h = $new_height;
394
+        $viewport_ox = $offset_width;
395
+        $viewport_oy = $offset_height;
396
+
397
+        // si on a un width/height qui rescale, il faut rescaler
398
+        if (
399
+            isset($attributs['width'])
400
+            && ($w = svg_dimension_to_pixels($attributs['width']))
401
+            && isset($attributs['height'])
402
+            && ($h = svg_dimension_to_pixels($attributs['height']))
403
+        ) {
404
+            $xscale = $viewBox[2] / $w;
405
+            $viewport_w = round($viewport_w * $xscale, 2);
406
+            $viewport_ox = round($viewport_ox * $xscale, 2);
407
+            $yscale = $viewBox[3] / $h;
408
+            $viewport_h = round($viewport_h * $yscale, 2);
409
+            $viewport_oy = round($viewport_oy * $yscale, 2);
410
+        }
411
+
412
+        if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) {
413
+            $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
414
+        }
415
+
416
+        // maintenant on redefinit la viewBox
417
+        $viewBox[0] += $viewport_ox;
418
+        $viewBox[1] += $viewport_oy;
419
+        $viewBox[2] = $viewport_w;
420
+        $viewBox[3] = $viewport_h;
421
+
422
+        $attributs['viewBox'] = implode(' ', $viewBox);
423
+        $attributs['width'] = (string) $new_width;
424
+        $attributs['height'] = (string) $new_height;
425
+
426
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
427
+
428
+        // ajouter un background
429
+        if ($background_color && $background_color !== 'transparent') {
430
+            $svg = svg_ajouter_background($svg, $background_color);
431
+        }
432
+
433
+        return $svg;
434
+    }
435
+
436
+    return $img;
437 437
 }
438 438
 
439 439
 /**
@@ -443,26 +443,26 @@  discard block
 block discarded – undo
443 443
  * @return bool|string
444 444
  */
445 445
 function svg_ajouter_background($img, $background_color) {
446
-	if (
447
-		($svg = svg_charger($img))
448
-		&& ($svg_infos = svg_lire_balise_svg($svg))
449
-	) {
450
-		if ($background_color && $background_color !== 'transparent') {
451
-			[$balise_svg, $attributs] = $svg_infos;
452
-
453
-			$background_color = svg_couleur_to_hexa($background_color);
454
-			if (isset($attributs['viewBox'])) {
455
-				$viewBox = explode(' ', $attributs['viewBox']);
456
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
457
-			}
458
-			else {
459
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
460
-			}
461
-			$svg = svg_insert_shapes($svg, $rect);
462
-		}
463
-		return $svg;
464
-	}
465
-	return $img;
446
+    if (
447
+        ($svg = svg_charger($img))
448
+        && ($svg_infos = svg_lire_balise_svg($svg))
449
+    ) {
450
+        if ($background_color && $background_color !== 'transparent') {
451
+            [$balise_svg, $attributs] = $svg_infos;
452
+
453
+            $background_color = svg_couleur_to_hexa($background_color);
454
+            if (isset($attributs['viewBox'])) {
455
+                $viewBox = explode(' ', $attributs['viewBox']);
456
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
457
+            }
458
+            else {
459
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
460
+            }
461
+            $svg = svg_insert_shapes($svg, $rect);
462
+        }
463
+        return $svg;
464
+    }
465
+    return $img;
466 466
 }
467 467
 
468 468
 
@@ -473,26 +473,26 @@  discard block
 block discarded – undo
473 473
  * @return bool|string
474 474
  */
475 475
 function svg_ajouter_voile($img, $background_color, $opacity) {
476
-	if (
477
-		($svg = svg_charger($img))
478
-		&& ($svg_infos = svg_lire_balise_svg($svg))
479
-	) {
480
-		if ($background_color && $background_color !== 'transparent') {
481
-			[$balise_svg, $attributs] = $svg_infos;
482
-
483
-			$background_color = svg_couleur_to_hexa($background_color);
484
-			if (isset($attributs['viewBox'])) {
485
-				$viewBox = explode(' ', $attributs['viewBox']);
486
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
487
-			}
488
-			else {
489
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
490
-			}
491
-			$svg = svg_insert_shapes($svg, $rect, false);
492
-		}
493
-		return $svg;
494
-	}
495
-	return $img;
476
+    if (
477
+        ($svg = svg_charger($img))
478
+        && ($svg_infos = svg_lire_balise_svg($svg))
479
+    ) {
480
+        if ($background_color && $background_color !== 'transparent') {
481
+            [$balise_svg, $attributs] = $svg_infos;
482
+
483
+            $background_color = svg_couleur_to_hexa($background_color);
484
+            if (isset($attributs['viewBox'])) {
485
+                $viewBox = explode(' ', $attributs['viewBox']);
486
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
487
+            }
488
+            else {
489
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
490
+            }
491
+            $svg = svg_insert_shapes($svg, $rect, false);
492
+        }
493
+        return $svg;
494
+    }
495
+    return $img;
496 496
 }
497 497
 
498 498
 
@@ -503,27 +503,27 @@  discard block
 block discarded – undo
503 503
  * @return bool|string
504 504
  */
505 505
 function svg_transformer($img, $attributs) {
506
-	if (
507
-		($svg = svg_charger($img))
508
-		&& ($svg_infos = svg_lire_balise_svg($svg))
509
-	) {
510
-		if ($attributs) {
511
-			[$balise_svg, ] = $svg_infos;
512
-			$g = '<g';
513
-			foreach ($attributs as $k => $v) {
514
-				if (strlen($v)) {
515
-					$g .= " $k=\"" . attribut_html($v) . '"';
516
-				}
517
-			}
518
-			if (strlen($g) > 2) {
519
-				$g .= '>';
520
-				$svg = svg_insert_shapes($svg, $g);
521
-				$svg = svg_insert_shapes($svg, '</g>', false);
522
-			}
523
-		}
524
-		return $svg;
525
-	}
526
-	return $img;
506
+    if (
507
+        ($svg = svg_charger($img))
508
+        && ($svg_infos = svg_lire_balise_svg($svg))
509
+    ) {
510
+        if ($attributs) {
511
+            [$balise_svg, ] = $svg_infos;
512
+            $g = '<g';
513
+            foreach ($attributs as $k => $v) {
514
+                if (strlen($v)) {
515
+                    $g .= " $k=\"" . attribut_html($v) . '"';
516
+                }
517
+            }
518
+            if (strlen($g) > 2) {
519
+                $g .= '>';
520
+                $svg = svg_insert_shapes($svg, $g);
521
+                $svg = svg_insert_shapes($svg, '</g>', false);
522
+            }
523
+        }
524
+        return $svg;
525
+    }
526
+    return $img;
527 527
 }
528 528
 
529 529
 /**
@@ -534,21 +534,21 @@  discard block
 block discarded – undo
534 534
  * @return bool|string
535 535
  */
536 536
 function svg_apply_filter($img, $filter_def) {
537
-	if (
538
-		($svg = svg_charger($img))
539
-		&& ($svg_infos = svg_lire_balise_svg($svg))
540
-	) {
541
-		if ($filter_def) {
542
-			[$balise_svg, ] = $svg_infos;
543
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
544
-			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
545
-			$g = "<g filter=\"url(#$filter_id)\">";
546
-			$svg = svg_insert_shapes($svg, $filter . $g);
547
-			$svg = svg_insert_shapes($svg, '</g>', false);
548
-		}
549
-		return $svg;
550
-	}
551
-	return $img;
537
+    if (
538
+        ($svg = svg_charger($img))
539
+        && ($svg_infos = svg_lire_balise_svg($svg))
540
+    ) {
541
+        if ($filter_def) {
542
+            [$balise_svg, ] = $svg_infos;
543
+            $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
544
+            $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
545
+            $g = "<g filter=\"url(#$filter_id)\">";
546
+            $svg = svg_insert_shapes($svg, $filter . $g);
547
+            $svg = svg_insert_shapes($svg, '</g>', false);
548
+        }
549
+        return $svg;
550
+    }
551
+    return $img;
552 552
 }
553 553
 
554 554
 /**
@@ -558,8 +558,8 @@  discard block
 block discarded – undo
558 558
  * @return string
559 559
  */
560 560
 function svg_filter_blur($img, $blur_width) {
561
-	$blur_width = (int) $blur_width;
562
-	return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
561
+    $blur_width = (int) $blur_width;
562
+    return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
563 563
 }
564 564
 
565 565
 /**
@@ -569,10 +569,10 @@  discard block
 block discarded – undo
569 569
  * @return bool|string
570 570
  */
571 571
 function svg_filter_grayscale($img, $intensity) {
572
-	$value = round(1.0 - $intensity, 2);
573
-	//$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
574
-	$filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
575
-	return svg_apply_filter($img, $filter);
572
+    $value = round(1.0 - $intensity, 2);
573
+    //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>";
574
+    $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
575
+    return svg_apply_filter($img, $filter);
576 576
 }
577 577
 
578 578
 /**
@@ -582,8 +582,8 @@  discard block
 block discarded – undo
582 582
  * @return bool|string
583 583
  */
584 584
 function svg_filter_sepia($img, $intensity) {
585
-	$filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
586
-	return svg_apply_filter($img, $filter);
585
+    $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>';
586
+    return svg_apply_filter($img, $filter);
587 587
 }
588 588
 
589 589
 /**
@@ -593,30 +593,30 @@  discard block
 block discarded – undo
593 593
  * @return bool|string
594 594
  */
595 595
 function svg_flip($img, $HorV) {
596
-	if (
597
-		($svg = svg_force_viewBox_px($img))
598
-		&& ($svg_infos = svg_lire_balise_svg($svg))
599
-	) {
600
-		[$balise_svg, $atts] = $svg_infos;
601
-		$viewBox = explode(' ', $atts['viewBox']);
602
-
603
-		if (!in_array($HorV, ['h', 'H'])) {
604
-			$transform = 'scale(-1,1)';
605
-
606
-			$x = (int) $viewBox[0] + (int) ($viewBox[2] / 2);
607
-			$mx = -$x;
608
-			$transform = "translate($x, 0) $transform translate($mx, 0)";
609
-		}
610
-		else {
611
-			$transform = 'scale(1,-1)';
612
-
613
-			$y = (int) $viewBox[1] + (int) ($viewBox[3] / 2);
614
-			$my = -$y;
615
-			$transform = "translate(0, $y) $transform translate(0, $my)";
616
-		}
617
-		return svg_transformer($svg, ['transform' => $transform]);
618
-	}
619
-	return $img;
596
+    if (
597
+        ($svg = svg_force_viewBox_px($img))
598
+        && ($svg_infos = svg_lire_balise_svg($svg))
599
+    ) {
600
+        [$balise_svg, $atts] = $svg_infos;
601
+        $viewBox = explode(' ', $atts['viewBox']);
602
+
603
+        if (!in_array($HorV, ['h', 'H'])) {
604
+            $transform = 'scale(-1,1)';
605
+
606
+            $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2);
607
+            $mx = -$x;
608
+            $transform = "translate($x, 0) $transform translate($mx, 0)";
609
+        }
610
+        else {
611
+            $transform = 'scale(1,-1)';
612
+
613
+            $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2);
614
+            $my = -$y;
615
+            $transform = "translate(0, $y) $transform translate(0, $my)";
616
+        }
617
+        return svg_transformer($svg, ['transform' => $transform]);
618
+    }
619
+    return $img;
620 620
 }
621 621
 
622 622
 /**
@@ -630,19 +630,19 @@  discard block
 block discarded – undo
630 630
  * @return bool|string
631 631
  */
632 632
 function svg_rotate($img, $angle, $center_x, $center_y) {
633
-	if (
634
-		($svg = svg_force_viewBox_px($img))
635
-		&& ($svg_infos = svg_lire_balise_svg($svg))
636
-	) {
637
-		[$balise_svg, $atts] = $svg_infos;
638
-		$viewBox = explode(' ', $atts['viewBox']);
639
-
640
-		$center_x = round($viewBox[0] + $center_x * $viewBox[2]);
641
-		$center_y = round($viewBox[1] + $center_y * $viewBox[3]);
642
-
643
-		return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
644
-	}
645
-	return $img;
633
+    if (
634
+        ($svg = svg_force_viewBox_px($img))
635
+        && ($svg_infos = svg_lire_balise_svg($svg))
636
+    ) {
637
+        [$balise_svg, $atts] = $svg_infos;
638
+        $viewBox = explode(' ', $atts['viewBox']);
639
+
640
+        $center_x = round($viewBox[0] + $center_x * $viewBox[2]);
641
+        $center_y = round($viewBox[1] + $center_y * $viewBox[3]);
642
+
643
+        return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
644
+    }
645
+    return $img;
646 646
 }
647 647
 
648 648
 /**
@@ -654,40 +654,40 @@  discard block
 block discarded – undo
654 654
  * @return bool|mixed|string
655 655
  */
656 656
 function svg_filtrer_couleurs($img, $callback_filter) {
657
-	if (
658
-		($svg = svg_force_viewBox_px($img))
659
-		&& ($colors = svg_extract_couleurs($svg))
660
-	) {
661
-		$colors = array_unique($colors);
662
-
663
-		$short = [];
664
-		$long = [];
665
-		while (count($colors)) {
666
-			$c = array_shift($colors);
667
-			if (strlen($c) == 4) {
668
-				$short[] = $c;
669
-			}
670
-			else {
671
-				$long[] = $c;
672
-			}
673
-		}
674
-
675
-		$colors = [...$long, ...$short];
676
-		$new_colors = [];
677
-		$colors = array_flip($colors);
678
-		foreach ($colors as $c => $k) {
679
-			$colors[$c] = "@@@COLOR$$k$@@@";
680
-		}
681
-
682
-
683
-		foreach ($colors as $original => $replace) {
684
-			$new = svg_couleur_to_hexa($original);
685
-			$new_colors[$replace] = $callback_filter($new);
686
-		}
687
-
688
-		$svg = str_replace(array_keys($colors), array_values($colors), $svg);
689
-
690
-		return str_replace(array_keys($new_colors), array_values($new_colors), $svg);
691
-	}
692
-	return $img;
657
+    if (
658
+        ($svg = svg_force_viewBox_px($img))
659
+        && ($colors = svg_extract_couleurs($svg))
660
+    ) {
661
+        $colors = array_unique($colors);
662
+
663
+        $short = [];
664
+        $long = [];
665
+        while (count($colors)) {
666
+            $c = array_shift($colors);
667
+            if (strlen($c) == 4) {
668
+                $short[] = $c;
669
+            }
670
+            else {
671
+                $long[] = $c;
672
+            }
673
+        }
674
+
675
+        $colors = [...$long, ...$short];
676
+        $new_colors = [];
677
+        $colors = array_flip($colors);
678
+        foreach ($colors as $c => $k) {
679
+            $colors[$c] = "@@@COLOR$$k$@@@";
680
+        }
681
+
682
+
683
+        foreach ($colors as $original => $replace) {
684
+            $new = svg_couleur_to_hexa($original);
685
+            $new_colors[$replace] = $callback_filter($new);
686
+        }
687
+
688
+        $svg = str_replace(array_keys($colors), array_values($colors), $svg);
689
+
690
+        return str_replace(array_keys($new_colors), array_values($new_colors), $svg);
691
+    }
692
+    return $img;
693 693
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 		return $fichier;
56 56
 	}
57 57
 	if (!file_exists($fichier)) {
58
-		$fichier  = supprimer_timestamp($fichier);
58
+		$fichier = supprimer_timestamp($fichier);
59 59
 		if (!file_exists($fichier)) {
60 60
 			return false;
61 61
 		}
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
146 146
 	$new_balise_svg = '<svg';
147 147
 	foreach ($attributs as $k => $v) {
148
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
148
+		$new_balise_svg .= " $k=\"".entites_html($v).'"';
149 149
 	}
150 150
 	$new_balise_svg .= '>';
151 151
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 function svg_insert_shapes($svg, $shapes, $start = true) {
164 164
 
165 165
 	if ($start === false || $start === 'end') {
166
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
166
+		$svg = str_replace('</svg>', $shapes.'</svg>', $svg);
167 167
 	}
168 168
 	else {
169 169
 		$p = stripos($svg, '<svg');
@@ -184,10 +184,10 @@  discard block
 block discarded – undo
184 184
  */
185 185
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
186 186
 	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
187
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
187
+	$id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8);
188 188
 	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
189 189
 	$g = "<g clip-path=\"url(#$id)\">";
190
-	$svg = svg_insert_shapes($svg, $clippath . $g);
190
+	$svg = svg_insert_shapes($svg, $clippath.$g);
191 191
 	return svg_insert_shapes($svg, '</g>', false);
192 192
 }
193 193
 
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	) {
206 206
 		[$balise_svg, $attributs] = $svg_infos;
207 207
 		if (!isset($attributs['viewBox'])) {
208
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
208
+			$attributs['viewBox'] = '0 0 '.$attributs['width'].' '.$attributs['height'];
209 209
 		}
210 210
 		$attributs['width'] = (string) $new_width;
211 211
 		$attributs['height'] = (string) $new_height;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	else {
229 229
 		$couleur = couleur_html_to_hex($couleur);
230 230
 	}
231
-	return '#' . ltrim($couleur, '#');
231
+	return '#'.ltrim($couleur, '#');
232 232
 }
233 233
 
234 234
 /**
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
 function svg_couleur_to_rgb($couleur) {
240 240
 	if (str_starts_with($couleur, 'rgb(')) {
241 241
 		$c = explode(',', substr($couleur, 4));
242
-		return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]];
242
+		return ['red' => (int) $c[0], 'green' => (int) $c[1], 'blue' => (int) $c[2]];
243 243
 	}
244 244
 	return _couleur_hex_to_dec($couleur);
245 245
 }
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 			$background_color = svg_couleur_to_hexa($background_color);
454 454
 			if (isset($attributs['viewBox'])) {
455 455
 				$viewBox = explode(' ', $attributs['viewBox']);
456
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
456
+				$rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\"/>";
457 457
 			}
458 458
 			else {
459 459
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
 			$background_color = svg_couleur_to_hexa($background_color);
484 484
 			if (isset($attributs['viewBox'])) {
485 485
 				$viewBox = explode(' ', $attributs['viewBox']);
486
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
486
+				$rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>";
487 487
 			}
488 488
 			else {
489 489
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
@@ -512,7 +512,7 @@  discard block
 block discarded – undo
512 512
 			$g = '<g';
513 513
 			foreach ($attributs as $k => $v) {
514 514
 				if (strlen($v)) {
515
-					$g .= " $k=\"" . attribut_html($v) . '"';
515
+					$g .= " $k=\"".attribut_html($v).'"';
516 516
 				}
517 517
 			}
518 518
 			if (strlen($g) > 2) {
@@ -540,10 +540,10 @@  discard block
 block discarded – undo
540 540
 	) {
541 541
 		if ($filter_def) {
542 542
 			[$balise_svg, ] = $svg_infos;
543
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
543
+			$filter_id = 'filter-'.substr(md5($filter_def.strlen($svg)), 0, 8);
544 544
 			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
545 545
 			$g = "<g filter=\"url(#$filter_id)\">";
546
-			$svg = svg_insert_shapes($svg, $filter . $g);
546
+			$svg = svg_insert_shapes($svg, $filter.$g);
547 547
 			$svg = svg_insert_shapes($svg, '</g>', false);
548 548
 		}
549 549
 		return $svg;
Please login to merge, or discard this patch.
Braces   +12 added lines, -24 removed lines patch added patch discarded remove patch
@@ -164,8 +164,7 @@  discard block
 block discarded – undo
164 164
 
165 165
 	if ($start === false || $start === 'end') {
166 166
 		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
167
-	}
168
-	else {
167
+	} else {
169 168
 		$p = stripos($svg, '<svg');
170 169
 		$p = strpos($svg, '>', $p);
171 170
 		$svg = substr_replace($svg, $shapes, $p + 1, 0);
@@ -224,8 +223,7 @@  discard block
 block discarded – undo
224 223
 	if (str_starts_with($couleur, 'rgb(')) {
225 224
 		$c = explode(',', substr($couleur, 4));
226 225
 		$couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]);
227
-	}
228
-	else {
226
+	} else {
229 227
 		$couleur = couleur_html_to_hex($couleur);
230 228
 	}
231 229
 	return '#' . ltrim($couleur, '#');
@@ -281,17 +279,14 @@  discard block
 block discarded – undo
281 279
 			// si pas de height valide, on suppose l'image carree
282 280
 			$viewBox[3] = $width;
283 281
 		}
284
-	}
285
-	else {
282
+	} else {
286 283
 		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
287 284
 		$width = $viewBox[2];
288 285
 		if ($width < 1) {
289 286
 			$coeff = max($coeff, 1000);
290
-		}
291
-		elseif ($width < 10) {
287
+		} elseif ($width < 10) {
292 288
 			$coeff = max($coeff, 100);
293
-		}
294
-		elseif ($width < 100) {
289
+		} elseif ($width < 100) {
295 290
 			$coeff = max($coeff, 10);
296 291
 		}
297 292
 	}
@@ -304,16 +299,13 @@  discard block
 block discarded – undo
304 299
 		if (empty($attributs['viewBox'])) {
305 300
 			$viewBox[3] = $height;
306 301
 		}
307
-	}
308
-	else {
302
+	} else {
309 303
 		$height = $viewBox[3];
310 304
 		if ($height < 1) {
311 305
 			$coeff = max($coeff, 1000);
312
-		}
313
-		elseif ($height < 10) {
306
+		} elseif ($height < 10) {
314 307
 			$coeff = max($coeff, 100);
315
-		}
316
-		elseif ($height < 100) {
308
+		} elseif ($height < 100) {
317 309
 			$coeff = max($coeff, 10);
318 310
 		}
319 311
 	}
@@ -454,8 +446,7 @@  discard block
 block discarded – undo
454 446
 			if (isset($attributs['viewBox'])) {
455 447
 				$viewBox = explode(' ', $attributs['viewBox']);
456 448
 				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
457
-			}
458
-			else {
449
+			} else {
459 450
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
460 451
 			}
461 452
 			$svg = svg_insert_shapes($svg, $rect);
@@ -484,8 +475,7 @@  discard block
 block discarded – undo
484 475
 			if (isset($attributs['viewBox'])) {
485 476
 				$viewBox = explode(' ', $attributs['viewBox']);
486 477
 				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
487
-			}
488
-			else {
478
+			} else {
489 479
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
490 480
 			}
491 481
 			$svg = svg_insert_shapes($svg, $rect, false);
@@ -606,8 +596,7 @@  discard block
 block discarded – undo
606 596
 			$x = (int) $viewBox[0] + (int) ($viewBox[2] / 2);
607 597
 			$mx = -$x;
608 598
 			$transform = "translate($x, 0) $transform translate($mx, 0)";
609
-		}
610
-		else {
599
+		} else {
611 600
 			$transform = 'scale(1,-1)';
612 601
 
613 602
 			$y = (int) $viewBox[1] + (int) ($viewBox[3] / 2);
@@ -666,8 +655,7 @@  discard block
 block discarded – undo
666 655
 			$c = array_shift($colors);
667 656
 			if (strlen($c) == 4) {
668 657
 				$short[] = $c;
669
-			}
670
-			else {
658
+			} else {
671 659
 				$long[] = $c;
672 660
 			}
673 661
 		}
Please login to merge, or discard this patch.
ecrire/src/Afficher/Minipage/Installation.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
15 15
  * Présentation des pages simplifiées pour installer SPIP
16 16
  **/
17 17
 class Installation extends Admin {
18
-	public const TYPE = 'installation';
18
+    public const TYPE = 'installation';
19 19
 
20
-	protected function setOptions(array $options) {
21
-		$options['titre'] ??= '';
22
-		if (!$options['titre'] || $options['titre'] === 'AUTO') {
23
-			$options['titre'] = _T('info_installation_systeme_publication');
24
-		}
25
-		$options = parent::setOptions($options);
26
-		$options['couleur_fond'] = '#a1124d';
27
-		$options['css_files'][] = find_in_theme('installation.css');
28
-		$options['footer'] = '';
29
-		return $options;
30
-	}
20
+    protected function setOptions(array $options) {
21
+        $options['titre'] ??= '';
22
+        if (!$options['titre'] || $options['titre'] === 'AUTO') {
23
+            $options['titre'] = _T('info_installation_systeme_publication');
24
+        }
25
+        $options = parent::setOptions($options);
26
+        $options['couleur_fond'] = '#a1124d';
27
+        $options['css_files'][] = find_in_theme('installation.css');
28
+        $options['footer'] = '';
29
+        return $options;
30
+    }
31 31
 
32
-	public function page($corps = '', $options = []) {
33
-		$options['titre'] ??= 'AUTO';
34
-		return parent::page($corps, $options);
35
-	}
32
+    public function page($corps = '', $options = []) {
33
+        $options['titre'] ??= 'AUTO';
34
+        return parent::page($corps, $options);
35
+    }
36 36
 }
Please login to merge, or discard this patch.
ecrire/src/Sql/Sqlite/Sqlite.php 1 patch
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -8,112 +8,112 @@
 block discarded – undo
8 8
  **/
9 9
 class Sqlite
10 10
 {
11
-	/** @var Requeteur[] Liste des instances de requêteurs créés */
12
-	public static $requeteurs = [];
13
-	/** @var bool[] Pour chaque connexion, flag pour savoir si une transaction est en cours */
14
-	public static $transaction_en_cours = [];
11
+    /** @var Requeteur[] Liste des instances de requêteurs créés */
12
+    public static $requeteurs = [];
13
+    /** @var bool[] Pour chaque connexion, flag pour savoir si une transaction est en cours */
14
+    public static $transaction_en_cours = [];
15 15
 
16 16
 
17
-	/**
18
-	 * Retourne une unique instance du requêteur
19
-	 *
20
-	 * Retourne une instance unique du requêteur pour une connexion SQLite
21
-	 * donnée
22
-	 *
23
-	 * @param string $serveur
24
-	 *    Nom du connecteur
25
-	 * @return Requeteur
26
-	 *    Instance unique du requêteur
27
-	 **/
28
-	public static function requeteur($serveur) {
29
-		if (!isset(static::$requeteurs[$serveur])) {
30
-			static::$requeteurs[$serveur] = new Requeteur($serveur);
31
-		}
17
+    /**
18
+     * Retourne une unique instance du requêteur
19
+     *
20
+     * Retourne une instance unique du requêteur pour une connexion SQLite
21
+     * donnée
22
+     *
23
+     * @param string $serveur
24
+     *    Nom du connecteur
25
+     * @return Requeteur
26
+     *    Instance unique du requêteur
27
+     **/
28
+    public static function requeteur($serveur) {
29
+        if (!isset(static::$requeteurs[$serveur])) {
30
+            static::$requeteurs[$serveur] = new Requeteur($serveur);
31
+        }
32 32
 
33
-		return static::$requeteurs[$serveur];
34
-	}
33
+        return static::$requeteurs[$serveur];
34
+    }
35 35
 
36
-	/**
37
-	 * Prépare le texte d'une requête avant son exécution
38
-	 *
39
-	 * Adapte la requête au format plus ou moins MySQL par un format
40
-	 * compris de SQLite.
41
-	 *
42
-	 * Change les préfixes de tables SPIP par ceux véritables
43
-	 *
44
-	 * @param string $query Requête à préparer
45
-	 * @param string $serveur Nom de la connexion
46
-	 * @return string           Requête préparée
47
-	 */
48
-	public static function traduire_requete($query, $serveur) {
49
-		$requeteur = static::requeteur($serveur);
50
-		$traducteur = new Traducteur($query, $requeteur->prefixe, $requeteur->sqlite_version);
36
+    /**
37
+     * Prépare le texte d'une requête avant son exécution
38
+     *
39
+     * Adapte la requête au format plus ou moins MySQL par un format
40
+     * compris de SQLite.
41
+     *
42
+     * Change les préfixes de tables SPIP par ceux véritables
43
+     *
44
+     * @param string $query Requête à préparer
45
+     * @param string $serveur Nom de la connexion
46
+     * @return string           Requête préparée
47
+     */
48
+    public static function traduire_requete($query, $serveur) {
49
+        $requeteur = static::requeteur($serveur);
50
+        $traducteur = new Traducteur($query, $requeteur->prefixe, $requeteur->sqlite_version);
51 51
 
52
-		return $traducteur->traduire_requete();
53
-	}
52
+        return $traducteur->traduire_requete();
53
+    }
54 54
 
55
-	/**
56
-	 * Démarre une transaction
57
-	 *
58
-	 * @param string $serveur Nom de la connexion
59
-	 **/
60
-	public static function demarrer_transaction($serveur) {
61
-		Sqlite::executer_requete('BEGIN TRANSACTION', $serveur);
62
-		Sqlite::$transaction_en_cours[$serveur] = true;
63
-	}
55
+    /**
56
+     * Démarre une transaction
57
+     *
58
+     * @param string $serveur Nom de la connexion
59
+     **/
60
+    public static function demarrer_transaction($serveur) {
61
+        Sqlite::executer_requete('BEGIN TRANSACTION', $serveur);
62
+        Sqlite::$transaction_en_cours[$serveur] = true;
63
+    }
64 64
 
65
-	/**
66
-	 * Exécute la requête donnée
67
-	 *
68
-	 * @param string $query Requête
69
-	 * @param string $serveur Nom de la connexion
70
-	 * @param null|bool $tracer Demander des statistiques (temps) ?
71
-	 **/
72
-	public static function executer_requete($query, $serveur, $tracer = null) {
73
-		$requeteur = Sqlite::requeteur($serveur);
65
+    /**
66
+     * Exécute la requête donnée
67
+     *
68
+     * @param string $query Requête
69
+     * @param string $serveur Nom de la connexion
70
+     * @param null|bool $tracer Demander des statistiques (temps) ?
71
+     **/
72
+    public static function executer_requete($query, $serveur, $tracer = null) {
73
+        $requeteur = Sqlite::requeteur($serveur);
74 74
 
75
-		return $requeteur->executer_requete($query, $tracer);
76
-	}
75
+        return $requeteur->executer_requete($query, $tracer);
76
+    }
77 77
 
78
-	/**
79
-	 * Obtient l'identifiant de la dernière ligne insérée ou modifiée
80
-	 *
81
-	 * @param string $serveur Nom de la connexion
82
-	 * return int                Identifiant
83
-	 **/
84
-	public static function last_insert_id($serveur) {
85
-		$requeteur = Sqlite::requeteur($serveur);
78
+    /**
79
+     * Obtient l'identifiant de la dernière ligne insérée ou modifiée
80
+     *
81
+     * @param string $serveur Nom de la connexion
82
+     * return int                Identifiant
83
+     **/
84
+    public static function last_insert_id($serveur) {
85
+        $requeteur = Sqlite::requeteur($serveur);
86 86
 
87
-		return $requeteur->last_insert_id();
88
-	}
87
+        return $requeteur->last_insert_id();
88
+    }
89 89
 
90
-	/**
91
-	 * Annule une transaction
92
-	 *
93
-	 * @param string $serveur Nom de la connexion
94
-	 **/
95
-	public static function annuler_transaction($serveur) {
96
-		Sqlite::executer_requete('ROLLBACK', $serveur);
97
-		Sqlite::$transaction_en_cours[$serveur] = false;
98
-	}
90
+    /**
91
+     * Annule une transaction
92
+     *
93
+     * @param string $serveur Nom de la connexion
94
+     **/
95
+    public static function annuler_transaction($serveur) {
96
+        Sqlite::executer_requete('ROLLBACK', $serveur);
97
+        Sqlite::$transaction_en_cours[$serveur] = false;
98
+    }
99 99
 
100
-	/**
101
-	 * Termine une transaction
102
-	 *
103
-	 * @param string $serveur Nom de la connexion
104
-	 **/
105
-	public static function finir_transaction($serveur) {
106
-		// si pas de transaction en cours, ne rien faire et le dire
107
-		if (
108
-			!isset(Sqlite::$transaction_en_cours[$serveur])
109
-			|| Sqlite::$transaction_en_cours[$serveur] == false
110
-		) {
111
-			return false;
112
-		}
113
-		// sinon fermer la transaction et retourner true
114
-		Sqlite::executer_requete('COMMIT', $serveur);
115
-		Sqlite::$transaction_en_cours[$serveur] = false;
100
+    /**
101
+     * Termine une transaction
102
+     *
103
+     * @param string $serveur Nom de la connexion
104
+     **/
105
+    public static function finir_transaction($serveur) {
106
+        // si pas de transaction en cours, ne rien faire et le dire
107
+        if (
108
+            !isset(Sqlite::$transaction_en_cours[$serveur])
109
+            || Sqlite::$transaction_en_cours[$serveur] == false
110
+        ) {
111
+            return false;
112
+        }
113
+        // sinon fermer la transaction et retourner true
114
+        Sqlite::executer_requete('COMMIT', $serveur);
115
+        Sqlite::$transaction_en_cours[$serveur] = false;
116 116
 
117
-		return true;
118
-	}
117
+        return true;
118
+    }
119 119
 }
Please login to merge, or discard this patch.
ecrire/src/Sql/Sqlite/PDOStatement.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -6,10 +6,10 @@
 block discarded – undo
6 6
  * Pouvoir retrouver le PDO utilisé pour générer un résultat de requête.
7 7
  */
8 8
 final class PDOStatement extends \PDOStatement {
9
-	private function __construct(private \PDO &$PDO) {
10
-	}
9
+    private function __construct(private \PDO &$PDO) {
10
+    }
11 11
 
12
-	public function getPDO(): \PDO {
13
-		return $this->PDO;
14
-	}
12
+    public function getPDO(): \PDO {
13
+        return $this->PDO;
14
+    }
15 15
 }
Please login to merge, or discard this patch.
ecrire/src/Sql/Sqlite/Requeteur.php 2 patches
Indentation   +105 added lines, -105 removed lines patch added patch discarded remove patch
@@ -13,109 +13,109 @@
 block discarded – undo
13 13
 
14 14
 class Requeteur
15 15
 {
16
-	/** @var string texte de la requête */
17
-	public $query = ''; // la requete
18
-	/** @var string Nom de la connexion */
19
-	public $serveur = '';
20
-	/** @var \PDO|null Identifiant de la connexion SQLite */
21
-	public $link = null;
22
-	/** @var string Prefixe des tables SPIP */
23
-	public $prefixe = '';
24
-	/** @var string Nom de la base de donnée */
25
-	public $db = '';
26
-	/** @var bool Doit-on tracer les requetes (var_profile) ? */
27
-	public $tracer = false; // doit-on tracer les requetes (var_profile)
28
-
29
-	/** @var string Version de SQLite (2 ou 3) */
30
-	public $sqlite_version = '';
31
-
32
-	/**
33
-	 * Constructeur
34
-	 *
35
-	 * @param string $serveur
36
-	 */
37
-	public function __construct($serveur = '') {
38
-		_sqlite_init();
39
-		$this->serveur = strtolower($serveur);
40
-
41
-		if (!($this->link = _sqlite_link($this->serveur)) && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL)) {
42
-			spip_log('Aucune connexion sqlite (link)', 'sqlite.' . _LOG_ERREUR);
43
-
44
-			return;
45
-		}
46
-
47
-		$this->sqlite_version = _sqlite_is_version('', $this->link);
48
-
49
-		$this->prefixe = $GLOBALS['connexions'][$this->serveur ?: 0]['prefixe'];
50
-		$this->db = $GLOBALS['connexions'][$this->serveur ?: 0]['db'];
51
-
52
-		// tracage des requetes ?
53
-		$this->tracer = (isset($_GET['var_profile']) && $_GET['var_profile']);
54
-	}
55
-
56
-	/**
57
-	 * Lancer la requête transmise et faire le tracage si demandé
58
-	 *
59
-	 * @param string $query
60
-	 *     Requête à exécuter
61
-	 * @param bool|null $tracer
62
-	 *     true pour tracer la requête
63
-	 * @return bool|\PDOStatement|array
64
-	 */
65
-	public function executer_requete($query, $tracer = null) {
66
-		if (is_null($tracer)) {
67
-			$tracer = $this->tracer;
68
-		}
69
-		$err = '';
70
-		$t = 0;
71
-		if ($tracer || defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) {
72
-			include_spip('public/tracer');
73
-			$t = trace_query_start();
74
-		}
75
-
76
-		# spip_log("requete: $this->serveur >> $query",'sqlite.'._LOG_DEBUG); // boum ? pourquoi ?
77
-		if ($this->link) {
78
-			// memoriser la derniere erreur PHP vue
79
-			$last_error = (function_exists('error_get_last') ? error_get_last() : '');
80
-			$e = null;
81
-			// sauver la derniere requete
82
-			$GLOBALS['connexions'][$this->serveur ?: 0]['last'] = $query;
83
-			$GLOBALS['connexions'][$this->serveur ?: 0]['total_requetes']++;
84
-
85
-			try {
86
-				$r = $this->link->query($query);
87
-			} catch (\PDOException $e) {
88
-				spip_log('PDOException: ' . $e->getMessage(), 'sqlite.' . _LOG_DEBUG);
89
-				$r = false;
90
-			}
91
-
92
-			// loger les warnings/erreurs eventuels de sqlite remontant dans PHP
93
-			if ($e && $e instanceof \PDOException) {
94
-				$err = strip_tags($e->getMessage()) . ' in ' . $e->getFile() . ' line ' . $e->getLine();
95
-				spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR);
96
-			} elseif (($err = (function_exists('error_get_last') ? error_get_last() : '')) && $err != $last_error) {
97
-				$err = strip_tags($err['message']) . ' in ' . $err['file'] . ' line ' . $err['line'];
98
-				spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR);
99
-			} else {
100
-				$err = '';
101
-			}
102
-		} else {
103
-			$r = false;
104
-		}
105
-
106
-		if (spip_sqlite_errno($this->serveur)) {
107
-			$err .= spip_sqlite_error($query, $this->serveur);
108
-		}
109
-
110
-		return $t ? trace_query_end($query, $t, $r, $err, $this->serveur) : $r;
111
-	}
112
-
113
-	/**
114
-	 * Obtient l'identifiant de la dernière ligne insérée ou modifiée
115
-	 *
116
-	 * @return string|false
117
-	 **/
118
-	public function last_insert_id() {
119
-		return $this->link->lastInsertId();
120
-	}
16
+    /** @var string texte de la requête */
17
+    public $query = ''; // la requete
18
+    /** @var string Nom de la connexion */
19
+    public $serveur = '';
20
+    /** @var \PDO|null Identifiant de la connexion SQLite */
21
+    public $link = null;
22
+    /** @var string Prefixe des tables SPIP */
23
+    public $prefixe = '';
24
+    /** @var string Nom de la base de donnée */
25
+    public $db = '';
26
+    /** @var bool Doit-on tracer les requetes (var_profile) ? */
27
+    public $tracer = false; // doit-on tracer les requetes (var_profile)
28
+
29
+    /** @var string Version de SQLite (2 ou 3) */
30
+    public $sqlite_version = '';
31
+
32
+    /**
33
+     * Constructeur
34
+     *
35
+     * @param string $serveur
36
+     */
37
+    public function __construct($serveur = '') {
38
+        _sqlite_init();
39
+        $this->serveur = strtolower($serveur);
40
+
41
+        if (!($this->link = _sqlite_link($this->serveur)) && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL)) {
42
+            spip_log('Aucune connexion sqlite (link)', 'sqlite.' . _LOG_ERREUR);
43
+
44
+            return;
45
+        }
46
+
47
+        $this->sqlite_version = _sqlite_is_version('', $this->link);
48
+
49
+        $this->prefixe = $GLOBALS['connexions'][$this->serveur ?: 0]['prefixe'];
50
+        $this->db = $GLOBALS['connexions'][$this->serveur ?: 0]['db'];
51
+
52
+        // tracage des requetes ?
53
+        $this->tracer = (isset($_GET['var_profile']) && $_GET['var_profile']);
54
+    }
55
+
56
+    /**
57
+     * Lancer la requête transmise et faire le tracage si demandé
58
+     *
59
+     * @param string $query
60
+     *     Requête à exécuter
61
+     * @param bool|null $tracer
62
+     *     true pour tracer la requête
63
+     * @return bool|\PDOStatement|array
64
+     */
65
+    public function executer_requete($query, $tracer = null) {
66
+        if (is_null($tracer)) {
67
+            $tracer = $this->tracer;
68
+        }
69
+        $err = '';
70
+        $t = 0;
71
+        if ($tracer || defined('_DEBUG_TRACE_QUERIES') && _DEBUG_TRACE_QUERIES) {
72
+            include_spip('public/tracer');
73
+            $t = trace_query_start();
74
+        }
75
+
76
+        # spip_log("requete: $this->serveur >> $query",'sqlite.'._LOG_DEBUG); // boum ? pourquoi ?
77
+        if ($this->link) {
78
+            // memoriser la derniere erreur PHP vue
79
+            $last_error = (function_exists('error_get_last') ? error_get_last() : '');
80
+            $e = null;
81
+            // sauver la derniere requete
82
+            $GLOBALS['connexions'][$this->serveur ?: 0]['last'] = $query;
83
+            $GLOBALS['connexions'][$this->serveur ?: 0]['total_requetes']++;
84
+
85
+            try {
86
+                $r = $this->link->query($query);
87
+            } catch (\PDOException $e) {
88
+                spip_log('PDOException: ' . $e->getMessage(), 'sqlite.' . _LOG_DEBUG);
89
+                $r = false;
90
+            }
91
+
92
+            // loger les warnings/erreurs eventuels de sqlite remontant dans PHP
93
+            if ($e && $e instanceof \PDOException) {
94
+                $err = strip_tags($e->getMessage()) . ' in ' . $e->getFile() . ' line ' . $e->getLine();
95
+                spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR);
96
+            } elseif (($err = (function_exists('error_get_last') ? error_get_last() : '')) && $err != $last_error) {
97
+                $err = strip_tags($err['message']) . ' in ' . $err['file'] . ' line ' . $err['line'];
98
+                spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR);
99
+            } else {
100
+                $err = '';
101
+            }
102
+        } else {
103
+            $r = false;
104
+        }
105
+
106
+        if (spip_sqlite_errno($this->serveur)) {
107
+            $err .= spip_sqlite_error($query, $this->serveur);
108
+        }
109
+
110
+        return $t ? trace_query_end($query, $t, $r, $err, $this->serveur) : $r;
111
+    }
112
+
113
+    /**
114
+     * Obtient l'identifiant de la dernière ligne insérée ou modifiée
115
+     *
116
+     * @return string|false
117
+     **/
118
+    public function last_insert_id() {
119
+        return $this->link->lastInsertId();
120
+    }
121 121
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 		$this->serveur = strtolower($serveur);
40 40
 
41 41
 		if (!($this->link = _sqlite_link($this->serveur)) && (!defined('_ECRIRE_INSTALL') || !_ECRIRE_INSTALL)) {
42
-			spip_log('Aucune connexion sqlite (link)', 'sqlite.' . _LOG_ERREUR);
42
+			spip_log('Aucune connexion sqlite (link)', 'sqlite.'._LOG_ERREUR);
43 43
 
44 44
 			return;
45 45
 		}
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
 			try {
86 86
 				$r = $this->link->query($query);
87 87
 			} catch (\PDOException $e) {
88
-				spip_log('PDOException: ' . $e->getMessage(), 'sqlite.' . _LOG_DEBUG);
88
+				spip_log('PDOException: '.$e->getMessage(), 'sqlite.'._LOG_DEBUG);
89 89
 				$r = false;
90 90
 			}
91 91
 
92 92
 			// loger les warnings/erreurs eventuels de sqlite remontant dans PHP
93 93
 			if ($e && $e instanceof \PDOException) {
94
-				$err = strip_tags($e->getMessage()) . ' in ' . $e->getFile() . ' line ' . $e->getLine();
95
-				spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR);
94
+				$err = strip_tags($e->getMessage()).' in '.$e->getFile().' line '.$e->getLine();
95
+				spip_log("$err - ".$query, 'sqlite.'._LOG_ERREUR);
96 96
 			} elseif (($err = (function_exists('error_get_last') ? error_get_last() : '')) && $err != $last_error) {
97
-				$err = strip_tags($err['message']) . ' in ' . $err['file'] . ' line ' . $err['line'];
98
-				spip_log("$err - " . $query, 'sqlite.' . _LOG_ERREUR);
97
+				$err = strip_tags($err['message']).' in '.$err['file'].' line '.$err['line'];
98
+				spip_log("$err - ".$query, 'sqlite.'._LOG_ERREUR);
99 99
 			} else {
100 100
 				$err = '';
101 101
 			}
Please login to merge, or discard this patch.
ecrire/src/Compilateur/Noeud/Idiome.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -7,85 +7,85 @@
 block discarded – undo
7 7
  **/
8 8
 class Idiome
9 9
 {
10
-	/** Type de noeud */
11
-	public string $type = 'idiome';
12
-
13
-	/** Clé de traduction demandée. Exemple 'item_oui' */
14
-	public string $nom_champ = '';
15
-
16
-	/** Module de langue où chercher la clé de traduction. Exemple 'medias' */
17
-	public string $module = '';
18
-
19
-	/** Arguments à passer à la chaîne */
20
-	public array $arg = [];
21
-
22
-	/**
23
-	 * Filtres à appliquer au résultat
24
-	 *
25
-	 *
26
-	 * * FIXME: type unique.
27
-	 * @var false|array
28
-	 *     - false: erreur de syntaxe
29
-	 */
30
-	public $param = [];
31
-
32
-	/** Source des filtres (compatibilité) (?) */
33
-	public array $fonctions = [];
34
-
35
-	/**
36
-	 * Inutilisé, propriété générique de l'AST
37
-	 *
38
-	 * @var string|array
39
-	 */
40
-	public $avant = '';
41
-
42
-	/**
43
-	 * Inutilisé, propriété générique de l'AST
44
-	 *
45
-	 * @var string|array
46
-	 */
47
-	public $apres = '';
48
-
49
-	/** Identifiant de la boucle */
50
-	public string $id_boucle = '';
51
-
52
-	/**
53
-	 * AST du squelette, liste de toutes les boucles
54
-	 *
55
-	 * @var Boucle[]
56
-	 */
57
-	public array $boucles;
58
-
59
-	/** Alias de table d'application de la requête ou nom complet de la table SQL */
60
-	public ?string $type_requete = null;
61
-
62
-	/** Résultat de la compilation: toujours une expression PHP */
63
-	public string $code = '';
64
-
65
-	/**
66
-	 * Interdire les scripts
67
-	 *
68
-	 * @see interdire_scripts()
69
-	 */
70
-	public bool $interdire_scripts = false;
71
-
72
-	/**
73
-	 * Description du squelette
74
-	 *
75
-	 * Sert pour la gestion d'erreur et la production de code dependant du contexte
76
-	 *
77
-	 * Peut contenir les index :
78
-	 * - nom : Nom du fichier de cache
79
-	 * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser)
80
-	 * - sourcefile : Chemin du squelette
81
-	 * - squelette : Code du squelette
82
-	 * - id_mere : Identifiant de la boucle parente
83
-	 * - documents : Pour embed et img dans les textes
84
-	 * - session : Pour un cache sessionné par auteur
85
-	 * - niv : Niveau de tabulation
86
-	 */
87
-	public array $descr = [];
88
-
89
-	/** Numéro de ligne dans le code source du squelette */
90
-	public int $ligne = 0;
10
+    /** Type de noeud */
11
+    public string $type = 'idiome';
12
+
13
+    /** Clé de traduction demandée. Exemple 'item_oui' */
14
+    public string $nom_champ = '';
15
+
16
+    /** Module de langue où chercher la clé de traduction. Exemple 'medias' */
17
+    public string $module = '';
18
+
19
+    /** Arguments à passer à la chaîne */
20
+    public array $arg = [];
21
+
22
+    /**
23
+     * Filtres à appliquer au résultat
24
+     *
25
+     *
26
+     * * FIXME: type unique.
27
+     * @var false|array
28
+     *     - false: erreur de syntaxe
29
+     */
30
+    public $param = [];
31
+
32
+    /** Source des filtres (compatibilité) (?) */
33
+    public array $fonctions = [];
34
+
35
+    /**
36
+     * Inutilisé, propriété générique de l'AST
37
+     *
38
+     * @var string|array
39
+     */
40
+    public $avant = '';
41
+
42
+    /**
43
+     * Inutilisé, propriété générique de l'AST
44
+     *
45
+     * @var string|array
46
+     */
47
+    public $apres = '';
48
+
49
+    /** Identifiant de la boucle */
50
+    public string $id_boucle = '';
51
+
52
+    /**
53
+     * AST du squelette, liste de toutes les boucles
54
+     *
55
+     * @var Boucle[]
56
+     */
57
+    public array $boucles;
58
+
59
+    /** Alias de table d'application de la requête ou nom complet de la table SQL */
60
+    public ?string $type_requete = null;
61
+
62
+    /** Résultat de la compilation: toujours une expression PHP */
63
+    public string $code = '';
64
+
65
+    /**
66
+     * Interdire les scripts
67
+     *
68
+     * @see interdire_scripts()
69
+     */
70
+    public bool $interdire_scripts = false;
71
+
72
+    /**
73
+     * Description du squelette
74
+     *
75
+     * Sert pour la gestion d'erreur et la production de code dependant du contexte
76
+     *
77
+     * Peut contenir les index :
78
+     * - nom : Nom du fichier de cache
79
+     * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser)
80
+     * - sourcefile : Chemin du squelette
81
+     * - squelette : Code du squelette
82
+     * - id_mere : Identifiant de la boucle parente
83
+     * - documents : Pour embed et img dans les textes
84
+     * - session : Pour un cache sessionné par auteur
85
+     * - niv : Niveau de tabulation
86
+     */
87
+    public array $descr = [];
88
+
89
+    /** Numéro de ligne dans le code source du squelette */
90
+    public int $ligne = 0;
91 91
 }
Please login to merge, or discard this patch.
ecrire/src/Compilateur/Noeud/Champ.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -7,104 +7,104 @@
 block discarded – undo
7 7
  */
8 8
 class Champ
9 9
 {
10
-	/** Type de noeud */
11
-	public string $type = 'champ';
12
-
13
-	/** Nom du champ demandé. Exemple 'ID_ARTICLE' */
14
-	public ?string $nom_champ = null;
15
-
16
-	/** Identifiant de la boucle parente si explicité */
17
-	public ?string $nom_boucle = '';
18
-
19
-	/**
20
-	 * Partie optionnelle avant
21
-	 *
22
-	 * @var null|string|array
23
-	 */
24
-	public $avant;
25
-
26
-	/**
27
-	 * Partie optionnelle après
28
-	 *
29
-	 * @var null|string|array
30
-	 */
31
-	public $apres;
32
-
33
-	/**
34
-	 * Étoiles : annuler des automatismes
35
-	 *
36
-	 * - '*' annule les filtres automatiques
37
-	 * - '**' annule en plus les protections de scripts
38
-	 *
39
-	 * FIXME: type unique.
40
-	 */
41
-	public ?string $etoile = '';
42
-
43
-	/**
44
-	 * Arguments et filtres explicites sur la balise
45
-	 *
46
-	 * - $param[0] contient les arguments de la balise
47
-	 * - $param[1..n] contient les filtres à appliquer à la balise
48
-	 *
49
-	 * FIXME: type unique.
50
-	 * @var false|array
51
-	 *     - false: erreur de syntaxe
52
-	 */
53
-	public $param = [];
54
-
55
-	/** Source des filtres (compatibilité) (?) */
56
-	public array $fonctions = [];
57
-
58
-	/**
59
-	 * Identifiant de la boucle
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $id_boucle = '';
64
-
65
-	/**
66
-	 * AST du squelette, liste de toutes les boucles
67
-	 *
68
-	 * @var Boucle[]
69
-	 */
70
-	public array $boucles;
71
-
72
-	/** Alias de table d'application de la requête ou nom complet de la table SQL */
73
-	public ?string $type_requete = null;
74
-
75
-	/** Résultat de la compilation: toujours une expression PHP */
76
-	public string $code = '';
77
-
78
-	/**
79
-	 * Interdire les scripts
80
-	 *
81
-	 * false si on est sûr de cette balise
82
-	 *
83
-	 * @see interdire_scripts()
84
-	 */
85
-	public bool $interdire_scripts = true;
86
-
87
-	/**
88
-	 * Description du squelette
89
-	 *
90
-	 * Sert pour la gestion d'erreur et la production de code dependant du contexte
91
-	 *
92
-	 * Peut contenir les index :
93
-	 *
94
-	 * - nom : Nom du fichier de cache
95
-	 * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser)
96
-	 * - sourcefile : Chemin du squelette
97
-	 * - squelette : Code du squelette
98
-	 * - id_mere : Identifiant de la boucle parente
99
-	 * - documents : Pour embed et img dans les textes
100
-	 * - session : Pour un cache sessionné par auteur
101
-	 * - niv : Niveau de tabulation
102
-	 */
103
-	public array $descr = [];
104
-
105
-	/** Numéro de ligne dans le code source du squelette*/
106
-	public int $ligne = 0;
107
-
108
-	/** Drapeau pour reperer les balises calculées par une fonction explicite */
109
-	public bool $balise_calculee = false;
10
+    /** Type de noeud */
11
+    public string $type = 'champ';
12
+
13
+    /** Nom du champ demandé. Exemple 'ID_ARTICLE' */
14
+    public ?string $nom_champ = null;
15
+
16
+    /** Identifiant de la boucle parente si explicité */
17
+    public ?string $nom_boucle = '';
18
+
19
+    /**
20
+     * Partie optionnelle avant
21
+     *
22
+     * @var null|string|array
23
+     */
24
+    public $avant;
25
+
26
+    /**
27
+     * Partie optionnelle après
28
+     *
29
+     * @var null|string|array
30
+     */
31
+    public $apres;
32
+
33
+    /**
34
+     * Étoiles : annuler des automatismes
35
+     *
36
+     * - '*' annule les filtres automatiques
37
+     * - '**' annule en plus les protections de scripts
38
+     *
39
+     * FIXME: type unique.
40
+     */
41
+    public ?string $etoile = '';
42
+
43
+    /**
44
+     * Arguments et filtres explicites sur la balise
45
+     *
46
+     * - $param[0] contient les arguments de la balise
47
+     * - $param[1..n] contient les filtres à appliquer à la balise
48
+     *
49
+     * FIXME: type unique.
50
+     * @var false|array
51
+     *     - false: erreur de syntaxe
52
+     */
53
+    public $param = [];
54
+
55
+    /** Source des filtres (compatibilité) (?) */
56
+    public array $fonctions = [];
57
+
58
+    /**
59
+     * Identifiant de la boucle
60
+     *
61
+     * @var string
62
+     */
63
+    public $id_boucle = '';
64
+
65
+    /**
66
+     * AST du squelette, liste de toutes les boucles
67
+     *
68
+     * @var Boucle[]
69
+     */
70
+    public array $boucles;
71
+
72
+    /** Alias de table d'application de la requête ou nom complet de la table SQL */
73
+    public ?string $type_requete = null;
74
+
75
+    /** Résultat de la compilation: toujours une expression PHP */
76
+    public string $code = '';
77
+
78
+    /**
79
+     * Interdire les scripts
80
+     *
81
+     * false si on est sûr de cette balise
82
+     *
83
+     * @see interdire_scripts()
84
+     */
85
+    public bool $interdire_scripts = true;
86
+
87
+    /**
88
+     * Description du squelette
89
+     *
90
+     * Sert pour la gestion d'erreur et la production de code dependant du contexte
91
+     *
92
+     * Peut contenir les index :
93
+     *
94
+     * - nom : Nom du fichier de cache
95
+     * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser)
96
+     * - sourcefile : Chemin du squelette
97
+     * - squelette : Code du squelette
98
+     * - id_mere : Identifiant de la boucle parente
99
+     * - documents : Pour embed et img dans les textes
100
+     * - session : Pour un cache sessionné par auteur
101
+     * - niv : Niveau de tabulation
102
+     */
103
+    public array $descr = [];
104
+
105
+    /** Numéro de ligne dans le code source du squelette*/
106
+    public int $ligne = 0;
107
+
108
+    /** Drapeau pour reperer les balises calculées par une fonction explicite */
109
+    public bool $balise_calculee = false;
110 110
 }
Please login to merge, or discard this patch.
ecrire/src/Compilateur/Noeud/Critere.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -8,32 +8,32 @@
 block discarded – undo
8 8
  * Sous-noeud de Boucle
9 9
  **/
10 10
 class Critere {
11
-	/** Type de noeud */
12
-	public string $type = 'critere';
13
-
14
-	/** Opérateur (>, <, >=, IN, ...) */
15
-	public ?string $op = null;
16
-
17
-	/** Présence d'une négation (truc !op valeur) */
18
-	public bool $not = false;
19
-
20
-	/** Présence d'une exclusion (!truc op valeur) */
21
-	public string $exclus = '';
22
-
23
-	/** Présence d'une condition dans le critère (truc ?) */
24
-	public bool $cond = false;
25
-
26
-	/**
27
-	 * Paramètres du critère
28
-	 * - $param[0] : élément avant l'opérateur
29
-	 * - $param[1..n] : éléments après l'opérateur
30
-	 *
31
-	 * FIXME: type unique.
32
-	 * @var false|array
33
-	 *     - false: erreur de syntaxe
34
-	 */
35
-	public $param = [];
36
-
37
-	/** Numéro de ligne dans le code source du squelette */
38
-	public int $ligne = 0;
11
+    /** Type de noeud */
12
+    public string $type = 'critere';
13
+
14
+    /** Opérateur (>, <, >=, IN, ...) */
15
+    public ?string $op = null;
16
+
17
+    /** Présence d'une négation (truc !op valeur) */
18
+    public bool $not = false;
19
+
20
+    /** Présence d'une exclusion (!truc op valeur) */
21
+    public string $exclus = '';
22
+
23
+    /** Présence d'une condition dans le critère (truc ?) */
24
+    public bool $cond = false;
25
+
26
+    /**
27
+     * Paramètres du critère
28
+     * - $param[0] : élément avant l'opérateur
29
+     * - $param[1..n] : éléments après l'opérateur
30
+     *
31
+     * FIXME: type unique.
32
+     * @var false|array
33
+     *     - false: erreur de syntaxe
34
+     */
35
+    public $param = [];
36
+
37
+    /** Numéro de ligne dans le code source du squelette */
38
+    public int $ligne = 0;
39 39
 }
Please login to merge, or discard this patch.
ecrire/src/Compilateur/Iterateur/AbstractIterateur.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -4,21 +4,21 @@
 block discarded – undo
4 4
 
5 5
 abstract class AbstractIterateur
6 6
 {
7
-	protected string $type;
7
+    protected string $type;
8 8
 
9
-	/**
10
-	 * Calcul du total des elements
11
-	 *
12
-	 * @var int|null
13
-	 **/
14
-	public $total = null;
9
+    /**
10
+     * Calcul du total des elements
11
+     *
12
+     * @var int|null
13
+     **/
14
+    public $total = null;
15 15
 
16
-	/** Erreur presente ? **/
17
-	public bool $err = false;
16
+    /** Erreur presente ? **/
17
+    public bool $err = false;
18 18
 
19
-	public function __construct(
20
-		protected array $command,
21
-		protected array $info = []
22
-	) {
23
-	}
19
+    public function __construct(
20
+        protected array $command,
21
+        protected array $info = []
22
+    ) {
23
+    }
24 24
 }
Please login to merge, or discard this patch.