Completed
Pull Request — master (#42)
by
unknown
01:14
created
ecrire/inc/svg.php 3 patches
Indentation   +448 added lines, -448 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  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
 if (!defined('IMG_SVG')) {
24
-	// complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
-	define('IMG_SVG', 128);
26
-	define('IMAGETYPE_SVG', 19);
24
+    // complete 	IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP
25
+    define('IMG_SVG', 128);
26
+    define('IMAGETYPE_SVG', 19);
27 27
 }
28 28
 
29 29
 /**
@@ -39,39 +39,39 @@  discard block
 block discarded – undo
39 39
  *   false si on a pas pu charger l'image
40 40
  */
41 41
 function svg_charger($fichier, $maxlen = null) {
42
-	if (strpos($fichier, 'data:image/svg+xml') === 0) {
43
-		$image = explode(';', $fichier, 2);
44
-		$image = end($image);
45
-		if (strpos($image, 'base64,') === 0) {
46
-			$image = base64_decode(substr($image, 7));
47
-		}
48
-		if (strpos($image, '<svg') !== false) {
49
-			return $image;
50
-		}
51
-		// encodage inconnu ou autre format d'image ?
52
-		return false;
53
-	}
54
-	// c'est peut etre deja une image svg ?
55
-	if (strpos($fichier, '<svg') !== false) {
56
-		return $fichier;
57
-	}
58
-	if (!file_exists($fichier)) {
59
-		$fichier  = supprimer_timestamp($fichier);
60
-		if (!file_exists($fichier)) {
61
-			return false;
62
-		}
63
-	}
64
-	if (is_null($maxlen)) {
65
-		$image = file_get_contents($fichier);
66
-	}
67
-	else {
68
-		$image = file_get_contents($fichier, false, null, 0, $maxlen);
69
-	}
70
-	// est-ce bien une image svg ?
71
-	if (strpos($image, '<svg') !== false) {
72
-		return $image;
73
-	}
74
-	return false;
42
+    if (strpos($fichier, 'data:image/svg+xml') === 0) {
43
+        $image = explode(';', $fichier, 2);
44
+        $image = end($image);
45
+        if (strpos($image, 'base64,') === 0) {
46
+            $image = base64_decode(substr($image, 7));
47
+        }
48
+        if (strpos($image, '<svg') !== false) {
49
+            return $image;
50
+        }
51
+        // encodage inconnu ou autre format d'image ?
52
+        return false;
53
+    }
54
+    // c'est peut etre deja une image svg ?
55
+    if (strpos($fichier, '<svg') !== false) {
56
+        return $fichier;
57
+    }
58
+    if (!file_exists($fichier)) {
59
+        $fichier  = supprimer_timestamp($fichier);
60
+        if (!file_exists($fichier)) {
61
+            return false;
62
+        }
63
+    }
64
+    if (is_null($maxlen)) {
65
+        $image = file_get_contents($fichier);
66
+    }
67
+    else {
68
+        $image = file_get_contents($fichier, false, null, 0, $maxlen);
69
+    }
70
+    // est-ce bien une image svg ?
71
+    if (strpos($image, '<svg') !== false) {
72
+        return $image;
73
+    }
74
+    return false;
75 75
 }
76 76
 
77 77
 /**
@@ -80,28 +80,28 @@  discard block
 block discarded – undo
80 80
  * @return array|bool
81 81
  */
82 82
 function svg_lire_balise_svg($fichier) {
83
-	if (!$debut_fichier = svg_charger($fichier, 4096)) {
84
-		return false;
85
-	}
86
-
87
-	if (($ps = stripos($debut_fichier, '<svg')) !== false) {
88
-		$pe = stripos($debut_fichier, '>', $ps);
89
-		$balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
90
-
91
-		if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
92
-			if (!function_exists('extraire_attribut')) {
93
-				include_spip('inc/filtres');
94
-			}
95
-			$attributs = [];
96
-			foreach ($matches[1] as $att) {
97
-				$attributs[$att] = extraire_attribut($balise_svg, $att);
98
-			}
99
-
100
-			return [$balise_svg, $attributs];
101
-		}
102
-	}
103
-
104
-	return false;
83
+    if (!$debut_fichier = svg_charger($fichier, 4096)) {
84
+        return false;
85
+    }
86
+
87
+    if (($ps = stripos($debut_fichier, '<svg')) !== false) {
88
+        $pe = stripos($debut_fichier, '>', $ps);
89
+        $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1);
90
+
91
+        if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) {
92
+            if (!function_exists('extraire_attribut')) {
93
+                include_spip('inc/filtres');
94
+            }
95
+            $attributs = [];
96
+            foreach ($matches[1] as $att) {
97
+                $attributs[$att] = extraire_attribut($balise_svg, $att);
98
+            }
99
+
100
+            return [$balise_svg, $attributs];
101
+        }
102
+    }
103
+
104
+    return false;
105 105
 }
106 106
 
107 107
 /**
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
  */
112 112
 function svg_lire_attributs($img) {
113 113
 
114
-	if ($svg_infos = svg_lire_balise_svg($img)) {
115
-		list($balise_svg, $attributs) = $svg_infos;
116
-		return $attributs;
117
-	}
114
+    if ($svg_infos = svg_lire_balise_svg($img)) {
115
+        list($balise_svg, $attributs) = $svg_infos;
116
+        return $attributs;
117
+    }
118 118
 
119
-	return false;
119
+    return false;
120 120
 }
121 121
 
122 122
 /**
@@ -126,38 +126,38 @@  discard block
 block discarded – undo
126 126
  * @return bool|float|int
127 127
  */
128 128
 function svg_dimension_to_pixels($dimension, $precision = 2) {
129
-	if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
130
-		switch (strtolower($m[2])) {
131
-			case '%':
132
-				// on ne sait pas faire :(
133
-				return false;
134
-				break;
135
-			case 'em':
136
-				return round($m[1] * 16, $precision); // 16px font-size par defaut
137
-				break;
138
-			case 'ex':
139
-				return round($m[1] * 16, $precision); // 16px font-size par defaut
140
-				break;
141
-			case 'pc':
142
-				return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS
143
-				break;
144
-			case 'cm':
145
-				return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm;
146
-				break;
147
-			case 'mm':
148
-				return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm;
149
-				break;
150
-			case 'in':
151
-				return round($m[1] * 96, $precision); // 1 inch = 96px in CSS
152
-				break;
153
-			case 'px':
154
-			case 'pt':
155
-			default:
156
-				return $m[1];
157
-				break;
158
-		}
159
-	}
160
-	return false;
129
+    if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) {
130
+        switch (strtolower($m[2])) {
131
+            case '%':
132
+                // on ne sait pas faire :(
133
+                return false;
134
+                break;
135
+            case 'em':
136
+                return round($m[1] * 16, $precision); // 16px font-size par defaut
137
+                break;
138
+            case 'ex':
139
+                return round($m[1] * 16, $precision); // 16px font-size par defaut
140
+                break;
141
+            case 'pc':
142
+                return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS
143
+                break;
144
+            case 'cm':
145
+                return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm;
146
+                break;
147
+            case 'mm':
148
+                return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm;
149
+                break;
150
+            case 'in':
151
+                return round($m[1] * 96, $precision); // 1 inch = 96px in CSS
152
+                break;
153
+            case 'px':
154
+            case 'pt':
155
+            default:
156
+                return $m[1];
157
+                break;
158
+        }
159
+    }
160
+    return false;
161 161
 }
162 162
 
163 163
 /**
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
  * @return string
169 169
  */
170 170
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
171
-	$new_balise_svg = '<svg';
172
-	foreach ($attributs as $k => $v) {
173
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
174
-	}
175
-	$new_balise_svg .= '>';
176
-
177
-	$p = strpos($svg, $old_balise_svg);
178
-	$svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
179
-	return $svg;
171
+    $new_balise_svg = '<svg';
172
+    foreach ($attributs as $k => $v) {
173
+        $new_balise_svg .= " $k=\"" . entites_html($v) . '"';
174
+    }
175
+    $new_balise_svg .= '>';
176
+
177
+    $p = strpos($svg, $old_balise_svg);
178
+    $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg));
179
+    return $svg;
180 180
 }
181 181
 
182 182
 /**
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
  */
189 189
 function svg_insert_shapes($svg, $shapes, $start = true) {
190 190
 
191
-	if ($start === false or $start === 'end') {
192
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
-	}
194
-	else {
195
-		$p = stripos($svg, '<svg');
196
-		$p = strpos($svg, '>', $p);
197
-		$svg = substr_replace($svg, $shapes, $p + 1, 0);
198
-	}
199
-	return $svg;
191
+    if ($start === false or $start === 'end') {
192
+        $svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
+    }
194
+    else {
195
+        $p = stripos($svg, '<svg');
196
+        $p = strpos($svg, '>', $p);
197
+        $svg = substr_replace($svg, $shapes, $p + 1, 0);
198
+    }
199
+    return $svg;
200 200
 }
201 201
 
202 202
 /**
@@ -209,13 +209,13 @@  discard block
 block discarded – undo
209 209
  * @return string
210 210
  */
211 211
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
212
-	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
214
-	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215
-	$g = "<g clip-path=\"url(#$id)\">";
216
-	$svg = svg_insert_shapes($svg, $clippath . $g);
217
-	$svg = svg_insert_shapes($svg, '</g>', false);
218
-	return $svg;
212
+    $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
+    $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
214
+    $clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215
+    $g = "<g clip-path=\"url(#$id)\">";
216
+    $svg = svg_insert_shapes($svg, $clippath . $g);
217
+    $svg = svg_insert_shapes($svg, '</g>', false);
218
+    return $svg;
219 219
 }
220 220
 
221 221
 /**
@@ -226,22 +226,22 @@  discard block
 block discarded – undo
226 226
  * @return bool|string
227 227
  */
228 228
 function svg_redimensionner($img, $new_width, $new_height) {
229
-	if (
230
-		$svg = svg_charger($img)
231
-		and $svg_infos = svg_lire_balise_svg($svg)
232
-	) {
233
-		list($balise_svg, $attributs) = $svg_infos;
234
-		if (!isset($attributs['viewBox'])) {
235
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
236
-		}
237
-		$attributs['width'] = strval($new_width);
238
-		$attributs['height'] = strval($new_height);
239
-
240
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
241
-		return $svg;
242
-	}
243
-
244
-	return $img;
229
+    if (
230
+        $svg = svg_charger($img)
231
+        and $svg_infos = svg_lire_balise_svg($svg)
232
+    ) {
233
+        list($balise_svg, $attributs) = $svg_infos;
234
+        if (!isset($attributs['viewBox'])) {
235
+            $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
236
+        }
237
+        $attributs['width'] = strval($new_width);
238
+        $attributs['height'] = strval($new_height);
239
+
240
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
241
+        return $svg;
242
+    }
243
+
244
+    return $img;
245 245
 }
246 246
 
247 247
 /**
@@ -250,15 +250,15 @@  discard block
 block discarded – undo
250 250
  * @return string
251 251
  */
252 252
 function svg_couleur_to_hexa($couleur) {
253
-	if (strpos($couleur, 'rgb(') === 0) {
254
-		$c = explode(',', substr($couleur, 4));
255
-		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
-	}
257
-	else {
258
-		$couleur = couleur_html_to_hex($couleur);
259
-	}
260
-	$couleur = '#' . ltrim($couleur, '#');
261
-	return $couleur;
253
+    if (strpos($couleur, 'rgb(') === 0) {
254
+        $c = explode(',', substr($couleur, 4));
255
+        $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
+    }
257
+    else {
258
+        $couleur = couleur_html_to_hex($couleur);
259
+    }
260
+    $couleur = '#' . ltrim($couleur, '#');
261
+    return $couleur;
262 262
 }
263 263
 
264 264
 /**
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
  * @return array
268 268
  */
269 269
 function svg_couleur_to_rgb($couleur) {
270
-	if (strpos($couleur, 'rgb(') === 0) {
271
-		$c = explode(',', substr($couleur, 4));
272
-		return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
273
-	}
274
-	return _couleur_hex_to_dec($couleur);
270
+    if (strpos($couleur, 'rgb(') === 0) {
271
+        $c = explode(',', substr($couleur, 4));
272
+        return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
273
+    }
274
+    return _couleur_hex_to_dec($couleur);
275 275
 }
276 276
 
277 277
 
@@ -281,70 +281,70 @@  discard block
 block discarded – undo
281 281
  * @return array
282 282
  */
283 283
 function svg_getimagesize_from_attr($attributs) {
284
-	$width = 350; // default width
285
-	$height = 150; // default height
286
-
287
-	$viewBox = "0 0 $width $height";
288
-	if (isset($attributs['viewBox'])) {
289
-		$viewBox = $attributs['viewBox'];
290
-		$viewBox = preg_replace(',\s+,', ' ', $viewBox);
291
-	}
292
-	// et on la convertit en px
293
-	$viewBox = explode(' ', $viewBox);
294
-	$viewBox = array_map('svg_dimension_to_pixels', $viewBox);
295
-	if (!$viewBox[2]) {
296
-		$viewBox[2] = $width;
297
-	}
298
-	if (!$viewBox[3]) {
299
-		$viewBox[3] = $height;
300
-	}
301
-
302
-	$coeff = 1;
303
-	if (
304
-		isset($attributs['width'])
305
-		and $w = svg_dimension_to_pixels($attributs['width'])
306
-	) {
307
-		$width = $w;
308
-	}
309
-	else {
310
-		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
311
-		$width = $viewBox[2];
312
-		if ($width < 1) {
313
-			$coeff = max($coeff, 1000);
314
-		}
315
-		elseif ($width < 10) {
316
-			$coeff = max($coeff, 100);
317
-		}
318
-		elseif ($width < 100) {
319
-			$coeff = max($coeff, 10);
320
-		}
321
-	}
322
-	if (
323
-		isset($attributs['height'])
324
-		and $h = svg_dimension_to_pixels($attributs['height'])
325
-	) {
326
-		$height = $h;
327
-	}
328
-	else {
329
-		$height = $viewBox[3];
330
-		if ($height < 1) {
331
-			$coeff = max($coeff, 1000);
332
-		}
333
-		elseif ($height < 10) {
334
-			$coeff = max($coeff, 100);
335
-		}
336
-		elseif ($height < 100) {
337
-			$coeff = max($coeff, 10);
338
-		}
339
-	}
340
-
341
-	// arrondir le width et height en pixel in fine
342
-	$width = round($coeff * $width);
343
-	$height = round($coeff * $height);
344
-
345
-	$viewBox = implode(' ', $viewBox);
346
-
347
-	return [$width, $height, $viewBox];
284
+    $width = 350; // default width
285
+    $height = 150; // default height
286
+
287
+    $viewBox = "0 0 $width $height";
288
+    if (isset($attributs['viewBox'])) {
289
+        $viewBox = $attributs['viewBox'];
290
+        $viewBox = preg_replace(',\s+,', ' ', $viewBox);
291
+    }
292
+    // et on la convertit en px
293
+    $viewBox = explode(' ', $viewBox);
294
+    $viewBox = array_map('svg_dimension_to_pixels', $viewBox);
295
+    if (!$viewBox[2]) {
296
+        $viewBox[2] = $width;
297
+    }
298
+    if (!$viewBox[3]) {
299
+        $viewBox[3] = $height;
300
+    }
301
+
302
+    $coeff = 1;
303
+    if (
304
+        isset($attributs['width'])
305
+        and $w = svg_dimension_to_pixels($attributs['width'])
306
+    ) {
307
+        $width = $w;
308
+    }
309
+    else {
310
+        // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
311
+        $width = $viewBox[2];
312
+        if ($width < 1) {
313
+            $coeff = max($coeff, 1000);
314
+        }
315
+        elseif ($width < 10) {
316
+            $coeff = max($coeff, 100);
317
+        }
318
+        elseif ($width < 100) {
319
+            $coeff = max($coeff, 10);
320
+        }
321
+    }
322
+    if (
323
+        isset($attributs['height'])
324
+        and $h = svg_dimension_to_pixels($attributs['height'])
325
+    ) {
326
+        $height = $h;
327
+    }
328
+    else {
329
+        $height = $viewBox[3];
330
+        if ($height < 1) {
331
+            $coeff = max($coeff, 1000);
332
+        }
333
+        elseif ($height < 10) {
334
+            $coeff = max($coeff, 100);
335
+        }
336
+        elseif ($height < 100) {
337
+            $coeff = max($coeff, 10);
338
+        }
339
+    }
340
+
341
+    // arrondir le width et height en pixel in fine
342
+    $width = round($coeff * $width);
343
+    $height = round($coeff * $height);
344
+
345
+    $viewBox = implode(' ', $viewBox);
346
+
347
+    return [$width, $height, $viewBox];
348 348
 }
349 349
 
350 350
 /**
@@ -360,25 +360,25 @@  discard block
 block discarded – undo
360 360
  * @return string
361 361
  */
362 362
 function svg_force_viewBox_px($img, $force_width_and_height = false) {
363
-	if (
364
-		$svg = svg_charger($img)
365
-		and $svg_infos = svg_lire_balise_svg($svg)
366
-	) {
367
-		list($balise_svg, $attributs) = $svg_infos;
363
+    if (
364
+        $svg = svg_charger($img)
365
+        and $svg_infos = svg_lire_balise_svg($svg)
366
+    ) {
367
+        list($balise_svg, $attributs) = $svg_infos;
368 368
 
369
-		list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs);
369
+        list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs);
370 370
 
371
-		if ($force_width_and_height) {
372
-			$attributs['width'] = $width;
373
-			$attributs['height'] = $height;
374
-		}
371
+        if ($force_width_and_height) {
372
+            $attributs['width'] = $width;
373
+            $attributs['height'] = $height;
374
+        }
375 375
 
376
-		$attributs['viewBox'] = $viewBox;
376
+        $attributs['viewBox'] = $viewBox;
377 377
 
378
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
379
-		return $svg;
380
-	}
381
-	return $img;
378
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
379
+        return $svg;
380
+    }
381
+    return $img;
382 382
 }
383 383
 
384 384
 /**
@@ -387,12 +387,12 @@  discard block
 block discarded – undo
387 387
  * @return array|mixed
388 388
  */
389 389
 function svg_extract_couleurs($img) {
390
-	if ($svg = svg_charger($img)) {
391
-		if (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)) {
392
-			return $matches[0];
393
-		}
394
-	}
395
-	return [];
390
+    if ($svg = svg_charger($img)) {
391
+        if (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)) {
392
+            return $matches[0];
393
+        }
394
+    }
395
+    return [];
396 396
 }
397 397
 
398 398
 /**
@@ -403,58 +403,58 @@  discard block
 block discarded – undo
403 403
  * @return bool|string
404 404
  */
405 405
 function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') {
406
-	if (
407
-		$svg = svg_force_viewBox_px($img)
408
-		and $svg_infos = svg_lire_balise_svg($svg)
409
-	) {
410
-		list($balise_svg, $attributs) = $svg_infos;
411
-		$viewBox = explode(' ', $attributs['viewBox']);
412
-
413
-		$viewport_w = $new_width;
414
-		$viewport_h = $new_height;
415
-		$viewport_ox = $offset_width;
416
-		$viewport_oy = $offset_height;
417
-
418
-		// si on a un width/height qui rescale, il faut rescaler
419
-		if (
420
-			isset($attributs['width'])
421
-			and $w = svg_dimension_to_pixels($attributs['width'])
422
-			and isset($attributs['height'])
423
-			and $h = svg_dimension_to_pixels($attributs['height'])
424
-		) {
425
-			$xscale = $viewBox[2] / $w;
426
-			$viewport_w = round($viewport_w * $xscale, 2);
427
-			$viewport_ox = round($viewport_ox * $xscale, 2);
428
-			$yscale = $viewBox[3] / $h;
429
-			$viewport_h = round($viewport_h * $yscale, 2);
430
-			$viewport_oy = round($viewport_oy * $yscale, 2);
431
-		}
432
-
433
-		if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
434
-			$svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
435
-		}
436
-
437
-		// maintenant on redefinit la viewBox
438
-		$viewBox[0] += $viewport_ox;
439
-		$viewBox[1] += $viewport_oy;
440
-		$viewBox[2] = $viewport_w;
441
-		$viewBox[3] = $viewport_h;
442
-
443
-		$attributs['viewBox'] = implode(' ', $viewBox);
444
-		$attributs['width'] = strval($new_width);
445
-		$attributs['height'] = strval($new_height);
446
-
447
-		$svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
448
-
449
-		// ajouter un background
450
-		if ($background_color and $background_color !== 'transparent') {
451
-			$svg = svg_ajouter_background($svg, $background_color);
452
-		}
453
-
454
-		return $svg;
455
-	}
456
-
457
-	return $img;
406
+    if (
407
+        $svg = svg_force_viewBox_px($img)
408
+        and $svg_infos = svg_lire_balise_svg($svg)
409
+    ) {
410
+        list($balise_svg, $attributs) = $svg_infos;
411
+        $viewBox = explode(' ', $attributs['viewBox']);
412
+
413
+        $viewport_w = $new_width;
414
+        $viewport_h = $new_height;
415
+        $viewport_ox = $offset_width;
416
+        $viewport_oy = $offset_height;
417
+
418
+        // si on a un width/height qui rescale, il faut rescaler
419
+        if (
420
+            isset($attributs['width'])
421
+            and $w = svg_dimension_to_pixels($attributs['width'])
422
+            and isset($attributs['height'])
423
+            and $h = svg_dimension_to_pixels($attributs['height'])
424
+        ) {
425
+            $xscale = $viewBox[2] / $w;
426
+            $viewport_w = round($viewport_w * $xscale, 2);
427
+            $viewport_ox = round($viewport_ox * $xscale, 2);
428
+            $yscale = $viewBox[3] / $h;
429
+            $viewport_h = round($viewport_h * $yscale, 2);
430
+            $viewport_oy = round($viewport_oy * $yscale, 2);
431
+        }
432
+
433
+        if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) {
434
+            $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]);
435
+        }
436
+
437
+        // maintenant on redefinit la viewBox
438
+        $viewBox[0] += $viewport_ox;
439
+        $viewBox[1] += $viewport_oy;
440
+        $viewBox[2] = $viewport_w;
441
+        $viewBox[3] = $viewport_h;
442
+
443
+        $attributs['viewBox'] = implode(' ', $viewBox);
444
+        $attributs['width'] = strval($new_width);
445
+        $attributs['height'] = strval($new_height);
446
+
447
+        $svg = svg_change_balise_svg($svg, $balise_svg, $attributs);
448
+
449
+        // ajouter un background
450
+        if ($background_color and $background_color !== 'transparent') {
451
+            $svg = svg_ajouter_background($svg, $background_color);
452
+        }
453
+
454
+        return $svg;
455
+    }
456
+
457
+    return $img;
458 458
 }
459 459
 
460 460
 /**
@@ -464,26 +464,26 @@  discard block
 block discarded – undo
464 464
  * @return bool|string
465 465
  */
466 466
 function svg_ajouter_background($img, $background_color) {
467
-	if (
468
-		$svg = svg_charger($img)
469
-		and $svg_infos = svg_lire_balise_svg($svg)
470
-	) {
471
-		if ($background_color and $background_color !== 'transparent') {
472
-			list($balise_svg, $attributs) = $svg_infos;
473
-
474
-			$background_color = svg_couleur_to_hexa($background_color);
475
-			if (isset($attributs['viewBox'])) {
476
-				$viewBox = explode(' ', $attributs['viewBox']);
477
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
478
-			}
479
-			else {
480
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
481
-			}
482
-			$svg = svg_insert_shapes($svg, $rect);
483
-		}
484
-		return $svg;
485
-	}
486
-	return $img;
467
+    if (
468
+        $svg = svg_charger($img)
469
+        and $svg_infos = svg_lire_balise_svg($svg)
470
+    ) {
471
+        if ($background_color and $background_color !== 'transparent') {
472
+            list($balise_svg, $attributs) = $svg_infos;
473
+
474
+            $background_color = svg_couleur_to_hexa($background_color);
475
+            if (isset($attributs['viewBox'])) {
476
+                $viewBox = explode(' ', $attributs['viewBox']);
477
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
478
+            }
479
+            else {
480
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
481
+            }
482
+            $svg = svg_insert_shapes($svg, $rect);
483
+        }
484
+        return $svg;
485
+    }
486
+    return $img;
487 487
 }
488 488
 
489 489
 
@@ -494,26 +494,26 @@  discard block
 block discarded – undo
494 494
  * @return bool|string
495 495
  */
496 496
 function svg_ajouter_voile($img, $background_color, $opacity) {
497
-	if (
498
-		$svg = svg_charger($img)
499
-		and $svg_infos = svg_lire_balise_svg($svg)
500
-	) {
501
-		if ($background_color and $background_color !== 'transparent') {
502
-			list($balise_svg, $attributs) = $svg_infos;
503
-
504
-			$background_color = svg_couleur_to_hexa($background_color);
505
-			if (isset($attributs['viewBox'])) {
506
-				$viewBox = explode(' ', $attributs['viewBox']);
507
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508
-			}
509
-			else {
510
-				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
511
-			}
512
-			$svg = svg_insert_shapes($svg, $rect, false);
513
-		}
514
-		return $svg;
515
-	}
516
-	return $img;
497
+    if (
498
+        $svg = svg_charger($img)
499
+        and $svg_infos = svg_lire_balise_svg($svg)
500
+    ) {
501
+        if ($background_color and $background_color !== 'transparent') {
502
+            list($balise_svg, $attributs) = $svg_infos;
503
+
504
+            $background_color = svg_couleur_to_hexa($background_color);
505
+            if (isset($attributs['viewBox'])) {
506
+                $viewBox = explode(' ', $attributs['viewBox']);
507
+                $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508
+            }
509
+            else {
510
+                $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
511
+            }
512
+            $svg = svg_insert_shapes($svg, $rect, false);
513
+        }
514
+        return $svg;
515
+    }
516
+    return $img;
517 517
 }
518 518
 
519 519
 
@@ -524,27 +524,27 @@  discard block
 block discarded – undo
524 524
  * @return bool|string
525 525
  */
526 526
 function svg_transformer($img, $attributs) {
527
-	if (
528
-		$svg = svg_charger($img)
529
-		and $svg_infos = svg_lire_balise_svg($svg)
530
-	) {
531
-		if ($attributs) {
532
-			list($balise_svg, ) = $svg_infos;
533
-			$g = '<g';
534
-			foreach ($attributs as $k => $v) {
535
-				if (strlen($v)) {
536
-					$g .= " $k=\"" . attribut_html($v) . '"';
537
-				}
538
-			}
539
-			if (strlen($g) > 2) {
540
-				$g .= '>';
541
-				$svg = svg_insert_shapes($svg, $g);
542
-				$svg = svg_insert_shapes($svg, '</g>', false);
543
-			}
544
-		}
545
-		return $svg;
546
-	}
547
-	return $img;
527
+    if (
528
+        $svg = svg_charger($img)
529
+        and $svg_infos = svg_lire_balise_svg($svg)
530
+    ) {
531
+        if ($attributs) {
532
+            list($balise_svg, ) = $svg_infos;
533
+            $g = '<g';
534
+            foreach ($attributs as $k => $v) {
535
+                if (strlen($v)) {
536
+                    $g .= " $k=\"" . attribut_html($v) . '"';
537
+                }
538
+            }
539
+            if (strlen($g) > 2) {
540
+                $g .= '>';
541
+                $svg = svg_insert_shapes($svg, $g);
542
+                $svg = svg_insert_shapes($svg, '</g>', false);
543
+            }
544
+        }
545
+        return $svg;
546
+    }
547
+    return $img;
548 548
 }
549 549
 
550 550
 /**
@@ -555,21 +555,21 @@  discard block
 block discarded – undo
555 555
  * @return bool|string
556 556
  */
557 557
 function svg_apply_filter($img, $filter_def) {
558
-	if (
559
-		$svg = svg_charger($img)
560
-		and $svg_infos = svg_lire_balise_svg($svg)
561
-	) {
562
-		if ($filter_def) {
563
-			list($balise_svg, ) = $svg_infos;
564
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
565
-			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
566
-			$g = "<g filter=\"url(#$filter_id)\">";
567
-			$svg = svg_insert_shapes($svg, $filter . $g);
568
-			$svg = svg_insert_shapes($svg, '</g>', false);
569
-		}
570
-		return $svg;
571
-	}
572
-	return $img;
558
+    if (
559
+        $svg = svg_charger($img)
560
+        and $svg_infos = svg_lire_balise_svg($svg)
561
+    ) {
562
+        if ($filter_def) {
563
+            list($balise_svg, ) = $svg_infos;
564
+            $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
565
+            $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
566
+            $g = "<g filter=\"url(#$filter_id)\">";
567
+            $svg = svg_insert_shapes($svg, $filter . $g);
568
+            $svg = svg_insert_shapes($svg, '</g>', false);
569
+        }
570
+        return $svg;
571
+    }
572
+    return $img;
573 573
 }
574 574
 
575 575
 /**
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
  * @return string
580 580
  */
581 581
 function svg_filter_blur($img, $blur_width) {
582
-	$blur_width = intval($blur_width);
583
-	return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
582
+    $blur_width = intval($blur_width);
583
+    return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>");
584 584
 }
585 585
 
586 586
 /**
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
  * @return bool|string
591 591
  */
592 592
 function svg_filter_grayscale($img, $intensity) {
593
-	$value = round(1.0 - $intensity, 2);
594
-	//$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\"/>";
595
-	$filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
596
-	return svg_apply_filter($img, $filter);
593
+    $value = round(1.0 - $intensity, 2);
594
+    //$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\"/>";
595
+    $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>";
596
+    return svg_apply_filter($img, $filter);
597 597
 }
598 598
 
599 599
 /**
@@ -603,8 +603,8 @@  discard block
 block discarded – undo
603 603
  * @return bool|string
604 604
  */
605 605
 function svg_filter_sepia($img, $intensity) {
606
-	$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"/>';
607
-	return svg_apply_filter($img, $filter);
606
+    $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"/>';
607
+    return svg_apply_filter($img, $filter);
608 608
 }
609 609
 
610 610
 /**
@@ -614,31 +614,31 @@  discard block
 block discarded – undo
614 614
  * @return bool|string
615 615
  */
616 616
 function svg_flip($img, $HorV) {
617
-	if (
618
-		$svg = svg_force_viewBox_px($img)
619
-		and $svg_infos = svg_lire_balise_svg($svg)
620
-	) {
621
-		list($balise_svg, $atts) = $svg_infos;
622
-		$viewBox = explode(' ', $atts['viewBox']);
623
-
624
-		if (!in_array($HorV, ['h', 'H'])) {
625
-			$transform = 'scale(-1,1)';
626
-
627
-			$x = intval($viewBox[0]) + intval($viewBox[2] / 2);
628
-			$mx = -$x;
629
-			$transform = "translate($x, 0) $transform translate($mx, 0)";
630
-		}
631
-		else {
632
-			$transform = 'scale(1,-1)';
633
-
634
-			$y = intval($viewBox[1]) + intval($viewBox[3] / 2);
635
-			$my = -$y;
636
-			$transform = "translate(0, $y) $transform translate(0, $my)";
637
-		}
638
-		$svg = svg_transformer($svg, ['transform' => $transform]);
639
-		return $svg;
640
-	}
641
-	return $img;
617
+    if (
618
+        $svg = svg_force_viewBox_px($img)
619
+        and $svg_infos = svg_lire_balise_svg($svg)
620
+    ) {
621
+        list($balise_svg, $atts) = $svg_infos;
622
+        $viewBox = explode(' ', $atts['viewBox']);
623
+
624
+        if (!in_array($HorV, ['h', 'H'])) {
625
+            $transform = 'scale(-1,1)';
626
+
627
+            $x = intval($viewBox[0]) + intval($viewBox[2] / 2);
628
+            $mx = -$x;
629
+            $transform = "translate($x, 0) $transform translate($mx, 0)";
630
+        }
631
+        else {
632
+            $transform = 'scale(1,-1)';
633
+
634
+            $y = intval($viewBox[1]) + intval($viewBox[3] / 2);
635
+            $my = -$y;
636
+            $transform = "translate(0, $y) $transform translate(0, $my)";
637
+        }
638
+        $svg = svg_transformer($svg, ['transform' => $transform]);
639
+        return $svg;
640
+    }
641
+    return $img;
642 642
 }
643 643
 
644 644
 /**
@@ -652,20 +652,20 @@  discard block
 block discarded – undo
652 652
  * @return bool|string
653 653
  */
654 654
 function svg_rotate($img, $angle, $center_x, $center_y) {
655
-	if (
656
-		$svg = svg_force_viewBox_px($img)
657
-		and $svg_infos = svg_lire_balise_svg($svg)
658
-	) {
659
-		list($balise_svg, $atts) = $svg_infos;
660
-		$viewBox = explode(' ', $atts['viewBox']);
661
-
662
-		$center_x = round($viewBox[0] + $center_x * $viewBox[2]);
663
-		$center_y = round($viewBox[1] + $center_y * $viewBox[3]);
664
-		$svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
665
-
666
-		return $svg;
667
-	}
668
-	return $img;
655
+    if (
656
+        $svg = svg_force_viewBox_px($img)
657
+        and $svg_infos = svg_lire_balise_svg($svg)
658
+    ) {
659
+        list($balise_svg, $atts) = $svg_infos;
660
+        $viewBox = explode(' ', $atts['viewBox']);
661
+
662
+        $center_x = round($viewBox[0] + $center_x * $viewBox[2]);
663
+        $center_y = round($viewBox[1] + $center_y * $viewBox[3]);
664
+        $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]);
665
+
666
+        return $svg;
667
+    }
668
+    return $img;
669 669
 }
670 670
 
671 671
 /**
@@ -677,41 +677,41 @@  discard block
 block discarded – undo
677 677
  * @return bool|mixed|string
678 678
  */
679 679
 function svg_filtrer_couleurs($img, $callback_filter) {
680
-	if (
681
-		$svg = svg_force_viewBox_px($img)
682
-		and $colors = svg_extract_couleurs($svg)
683
-	) {
684
-		$colors = array_unique($colors);
685
-
686
-		$short = [];
687
-		$long = [];
688
-		while (count($colors)) {
689
-			$c = array_shift($colors);
690
-			if (strlen($c) == 4) {
691
-				$short[] = $c;
692
-			}
693
-			else {
694
-				$long[] = $c;
695
-			}
696
-		}
697
-
698
-		$colors = array_merge($long, $short);
699
-		$new_colors = [];
700
-		$colors = array_flip($colors);
701
-		foreach ($colors as $c => $k) {
702
-			$colors[$c] = "@@@COLOR$$k$@@@";
703
-		}
704
-
705
-
706
-		foreach ($colors as $original => $replace) {
707
-			$new = svg_couleur_to_hexa($original);
708
-			$new_colors[$replace] = $callback_filter($new);
709
-		}
710
-
711
-		$svg = str_replace(array_keys($colors), array_values($colors), $svg);
712
-		$svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
713
-
714
-		return $svg;
715
-	}
716
-	return $img;
680
+    if (
681
+        $svg = svg_force_viewBox_px($img)
682
+        and $colors = svg_extract_couleurs($svg)
683
+    ) {
684
+        $colors = array_unique($colors);
685
+
686
+        $short = [];
687
+        $long = [];
688
+        while (count($colors)) {
689
+            $c = array_shift($colors);
690
+            if (strlen($c) == 4) {
691
+                $short[] = $c;
692
+            }
693
+            else {
694
+                $long[] = $c;
695
+            }
696
+        }
697
+
698
+        $colors = array_merge($long, $short);
699
+        $new_colors = [];
700
+        $colors = array_flip($colors);
701
+        foreach ($colors as $c => $k) {
702
+            $colors[$c] = "@@@COLOR$$k$@@@";
703
+        }
704
+
705
+
706
+        foreach ($colors as $original => $replace) {
707
+            $new = svg_couleur_to_hexa($original);
708
+            $new_colors[$replace] = $callback_filter($new);
709
+        }
710
+
711
+        $svg = str_replace(array_keys($colors), array_values($colors), $svg);
712
+        $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg);
713
+
714
+        return $svg;
715
+    }
716
+    return $img;
717 717
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 		return $fichier;
57 57
 	}
58 58
 	if (!file_exists($fichier)) {
59
-		$fichier  = supprimer_timestamp($fichier);
59
+		$fichier = supprimer_timestamp($fichier);
60 60
 		if (!file_exists($fichier)) {
61 61
 			return false;
62 62
 		}
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 function svg_change_balise_svg($svg, $old_balise_svg, $attributs) {
171 171
 	$new_balise_svg = '<svg';
172 172
 	foreach ($attributs as $k => $v) {
173
-		$new_balise_svg .= " $k=\"" . entites_html($v) . '"';
173
+		$new_balise_svg .= " $k=\"".entites_html($v).'"';
174 174
 	}
175 175
 	$new_balise_svg .= '>';
176 176
 
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 function svg_insert_shapes($svg, $shapes, $start = true) {
190 190
 
191 191
 	if ($start === false or $start === 'end') {
192
-		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
192
+		$svg = str_replace('</svg>', $shapes.'</svg>', $svg);
193 193
 	}
194 194
 	else {
195 195
 		$p = stripos($svg, '<svg');
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
  */
211 211
 function svg_clip_in_box($svg, $x, $y, $width, $height) {
212 212
 	$rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />";
213
-	$id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8);
213
+	$id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8);
214 214
 	$clippath = "<clipPath id=\"$id\">$rect</clipPath>";
215 215
 	$g = "<g clip-path=\"url(#$id)\">";
216
-	$svg = svg_insert_shapes($svg, $clippath . $g);
216
+	$svg = svg_insert_shapes($svg, $clippath.$g);
217 217
 	$svg = svg_insert_shapes($svg, '</g>', false);
218 218
 	return $svg;
219 219
 }
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
 	) {
233 233
 		list($balise_svg, $attributs) = $svg_infos;
234 234
 		if (!isset($attributs['viewBox'])) {
235
-			$attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height'];
235
+			$attributs['viewBox'] = '0 0 '.$attributs['width'].' '.$attributs['height'];
236 236
 		}
237 237
 		$attributs['width'] = strval($new_width);
238 238
 		$attributs['height'] = strval($new_height);
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	else {
258 258
 		$couleur = couleur_html_to_hex($couleur);
259 259
 	}
260
-	$couleur = '#' . ltrim($couleur, '#');
260
+	$couleur = '#'.ltrim($couleur, '#');
261 261
 	return $couleur;
262 262
 }
263 263
 
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 function svg_couleur_to_rgb($couleur) {
270 270
 	if (strpos($couleur, 'rgb(') === 0) {
271 271
 		$c = explode(',', substr($couleur, 4));
272
-		return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])];
272
+		return ['red' => intval($c[0]), 'green' => intval($c[1]), 'blue' => intval($c[2])];
273 273
 	}
274 274
 	return _couleur_hex_to_dec($couleur);
275 275
 }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
 			$background_color = svg_couleur_to_hexa($background_color);
475 475
 			if (isset($attributs['viewBox'])) {
476 476
 				$viewBox = explode(' ', $attributs['viewBox']);
477
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
477
+				$rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\"/>";
478 478
 			}
479 479
 			else {
480 480
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
@@ -504,7 +504,7 @@  discard block
 block discarded – undo
504 504
 			$background_color = svg_couleur_to_hexa($background_color);
505 505
 			if (isset($attributs['viewBox'])) {
506 506
 				$viewBox = explode(' ', $attributs['viewBox']);
507
-				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
507
+				$rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508 508
 			}
509 509
 			else {
510 510
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
@@ -529,11 +529,11 @@  discard block
 block discarded – undo
529 529
 		and $svg_infos = svg_lire_balise_svg($svg)
530 530
 	) {
531 531
 		if ($attributs) {
532
-			list($balise_svg, ) = $svg_infos;
532
+			list($balise_svg,) = $svg_infos;
533 533
 			$g = '<g';
534 534
 			foreach ($attributs as $k => $v) {
535 535
 				if (strlen($v)) {
536
-					$g .= " $k=\"" . attribut_html($v) . '"';
536
+					$g .= " $k=\"".attribut_html($v).'"';
537 537
 				}
538 538
 			}
539 539
 			if (strlen($g) > 2) {
@@ -560,11 +560,11 @@  discard block
 block discarded – undo
560 560
 		and $svg_infos = svg_lire_balise_svg($svg)
561 561
 	) {
562 562
 		if ($filter_def) {
563
-			list($balise_svg, ) = $svg_infos;
564
-			$filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8);
563
+			list($balise_svg,) = $svg_infos;
564
+			$filter_id = 'filter-'.substr(md5($filter_def.strlen($svg)), 0, 8);
565 565
 			$filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>";
566 566
 			$g = "<g filter=\"url(#$filter_id)\">";
567
-			$svg = svg_insert_shapes($svg, $filter . $g);
567
+			$svg = svg_insert_shapes($svg, $filter.$g);
568 568
 			$svg = svg_insert_shapes($svg, '</g>', false);
569 569
 		}
570 570
 		return $svg;
Please login to merge, or discard this patch.
Braces   +13 added lines, -26 removed lines patch added patch discarded remove patch
@@ -63,8 +63,7 @@  discard block
 block discarded – undo
63 63
 	}
64 64
 	if (is_null($maxlen)) {
65 65
 		$image = file_get_contents($fichier);
66
-	}
67
-	else {
66
+	} else {
68 67
 		$image = file_get_contents($fichier, false, null, 0, $maxlen);
69 68
 	}
70 69
 	// est-ce bien une image svg ?
@@ -190,8 +189,7 @@  discard block
 block discarded – undo
190 189
 
191 190
 	if ($start === false or $start === 'end') {
192 191
 		$svg = str_replace('</svg>', $shapes . '</svg>', $svg);
193
-	}
194
-	else {
192
+	} else {
195 193
 		$p = stripos($svg, '<svg');
196 194
 		$p = strpos($svg, '>', $p);
197 195
 		$svg = substr_replace($svg, $shapes, $p + 1, 0);
@@ -253,8 +251,7 @@  discard block
 block discarded – undo
253 251
 	if (strpos($couleur, 'rgb(') === 0) {
254 252
 		$c = explode(',', substr($couleur, 4));
255 253
 		$couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2]));
256
-	}
257
-	else {
254
+	} else {
258 255
 		$couleur = couleur_html_to_hex($couleur);
259 256
 	}
260 257
 	$couleur = '#' . ltrim($couleur, '#');
@@ -305,17 +302,14 @@  discard block
 block discarded – undo
305 302
 		and $w = svg_dimension_to_pixels($attributs['width'])
306 303
 	) {
307 304
 		$width = $w;
308
-	}
309
-	else {
305
+	} else {
310 306
 		// si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale
311 307
 		$width = $viewBox[2];
312 308
 		if ($width < 1) {
313 309
 			$coeff = max($coeff, 1000);
314
-		}
315
-		elseif ($width < 10) {
310
+		} elseif ($width < 10) {
316 311
 			$coeff = max($coeff, 100);
317
-		}
318
-		elseif ($width < 100) {
312
+		} elseif ($width < 100) {
319 313
 			$coeff = max($coeff, 10);
320 314
 		}
321 315
 	}
@@ -324,16 +318,13 @@  discard block
 block discarded – undo
324 318
 		and $h = svg_dimension_to_pixels($attributs['height'])
325 319
 	) {
326 320
 		$height = $h;
327
-	}
328
-	else {
321
+	} else {
329 322
 		$height = $viewBox[3];
330 323
 		if ($height < 1) {
331 324
 			$coeff = max($coeff, 1000);
332
-		}
333
-		elseif ($height < 10) {
325
+		} elseif ($height < 10) {
334 326
 			$coeff = max($coeff, 100);
335
-		}
336
-		elseif ($height < 100) {
327
+		} elseif ($height < 100) {
337 328
 			$coeff = max($coeff, 10);
338 329
 		}
339 330
 	}
@@ -475,8 +466,7 @@  discard block
 block discarded – undo
475 466
 			if (isset($attributs['viewBox'])) {
476 467
 				$viewBox = explode(' ', $attributs['viewBox']);
477 468
 				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>";
478
-			}
479
-			else {
469
+			} else {
480 470
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
481 471
 			}
482 472
 			$svg = svg_insert_shapes($svg, $rect);
@@ -505,8 +495,7 @@  discard block
 block discarded – undo
505 495
 			if (isset($attributs['viewBox'])) {
506 496
 				$viewBox = explode(' ', $attributs['viewBox']);
507 497
 				$rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>";
508
-			}
509
-			else {
498
+			} else {
510 499
 				$rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>";
511 500
 			}
512 501
 			$svg = svg_insert_shapes($svg, $rect, false);
@@ -627,8 +616,7 @@  discard block
 block discarded – undo
627 616
 			$x = intval($viewBox[0]) + intval($viewBox[2] / 2);
628 617
 			$mx = -$x;
629 618
 			$transform = "translate($x, 0) $transform translate($mx, 0)";
630
-		}
631
-		else {
619
+		} else {
632 620
 			$transform = 'scale(1,-1)';
633 621
 
634 622
 			$y = intval($viewBox[1]) + intval($viewBox[3] / 2);
@@ -689,8 +677,7 @@  discard block
 block discarded – undo
689 677
 			$c = array_shift($colors);
690 678
 			if (strlen($c) == 4) {
691 679
 				$short[] = $c;
692
-			}
693
-			else {
680
+			} else {
694 681
 				$long[] = $c;
695 682
 			}
696 683
 		}
Please login to merge, or discard this patch.
ecrire/inc/lister_objets.php 2 patches
Indentation   +21 added lines, -21 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
 
@@ -40,29 +40,29 @@  discard block
 block discarded – undo
40 40
  *     Code HTML de la liste
41 41
  */
42 42
 function inc_lister_objets_dist($vue, $contexte = [], $force = false) {
43
-	$res = ''; // debug
44
-	if (!is_array($contexte)) {
45
-		return _L('$contexte doit etre un tableau dans inc/lister_objets');
46
-	}
43
+    $res = ''; // debug
44
+    if (!is_array($contexte)) {
45
+        return _L('$contexte doit etre un tableau dans inc/lister_objets');
46
+    }
47 47
 
48
-	$fond = "prive/objets/liste/$vue";
49
-	if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
50
-		// traiter les cas particuliers
51
-		include_spip('base/connect_sql');
52
-		$vue = table_objet($vue);
53
-		$fond = "prive/objets/liste/$vue";
54
-		if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
55
-			return _L("vue $vue introuvable pour lister les objets");
56
-		}
57
-	}
48
+    $fond = "prive/objets/liste/$vue";
49
+    if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
50
+        // traiter les cas particuliers
51
+        include_spip('base/connect_sql');
52
+        $vue = table_objet($vue);
53
+        $fond = "prive/objets/liste/$vue";
54
+        if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
55
+            return _L("vue $vue introuvable pour lister les objets");
56
+        }
57
+    }
58 58
 
59 59
 
60
-	$contexte['sinon'] = ($force ? $contexte['titre'] : '');
60
+    $contexte['sinon'] = ($force ? $contexte['titre'] : '');
61 61
 
62
-	$res = recuperer_fond($fond, $contexte, ['ajax' => true]);
63
-	if (_request('var_liste')) {
64
-		echo var_export($contexte, true);
65
-	}
62
+    $res = recuperer_fond($fond, $contexte, ['ajax' => true]);
63
+    if (_request('var_liste')) {
64
+        echo var_export($contexte, true);
65
+    }
66 66
 
67
-	return $res;
67
+    return $res;
68 68
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,12 +46,12 @@
 block discarded – undo
46 46
 	}
47 47
 
48 48
 	$fond = "prive/objets/liste/$vue";
49
-	if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
49
+	if (!find_in_path($fond.'.'._EXTENSION_SQUELETTES)) {
50 50
 		// traiter les cas particuliers
51 51
 		include_spip('base/connect_sql');
52 52
 		$vue = table_objet($vue);
53 53
 		$fond = "prive/objets/liste/$vue";
54
-		if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) {
54
+		if (!find_in_path($fond.'.'._EXTENSION_SQUELETTES)) {
55 55
 			return _L("vue $vue introuvable pour lister les objets");
56 56
 		}
57 57
 	}
Please login to merge, or discard this patch.
ecrire/inc/pipelines_ecrire.php 2 patches
Indentation   +226 added lines, -226 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Pipelines
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 
@@ -36,37 +36,37 @@  discard block
 block discarded – undo
36 36
  * @return string          Contenu complété des scripts javascripts, dont jQuery
37 37
  **/
38 38
 function f_jQuery_prive($texte) {
39
-	$x = '';
40
-	$jquery_plugins = pipeline(
41
-		'jquery_plugins',
42
-		[
43
-			'prive/javascript/jquery.js',
44
-			'prive/javascript/jquery.form.js',
45
-			'prive/javascript/jquery.autosave.js',
46
-			'prive/javascript/jquery.placeholder-label.js',
47
-			'prive/javascript/ajaxCallback.js',
48
-			'prive/javascript/js.cookie.js',
49
-			'prive/javascript/jquery.cookie.js',
50
-			'prive/javascript/spip_barre.js',
51
-		]
52
-	);
53
-	foreach (array_unique($jquery_plugins) as $script) {
54
-		if ($script = find_in_path(supprimer_timestamp($script))) {
55
-			$script = timestamp($script);
56
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
57
-		}
58
-	}
59
-	// inserer avant le premier script externe ou a la fin
60
-	if (
61
-		preg_match(',<script[^><]*src=,', $texte, $match)
62
-		and $p = strpos($texte, $match[0])
63
-	) {
64
-		$texte = substr_replace($texte, $x, $p, 0);
65
-	} else {
66
-		$texte .= $x;
67
-	}
39
+    $x = '';
40
+    $jquery_plugins = pipeline(
41
+        'jquery_plugins',
42
+        [
43
+            'prive/javascript/jquery.js',
44
+            'prive/javascript/jquery.form.js',
45
+            'prive/javascript/jquery.autosave.js',
46
+            'prive/javascript/jquery.placeholder-label.js',
47
+            'prive/javascript/ajaxCallback.js',
48
+            'prive/javascript/js.cookie.js',
49
+            'prive/javascript/jquery.cookie.js',
50
+            'prive/javascript/spip_barre.js',
51
+        ]
52
+    );
53
+    foreach (array_unique($jquery_plugins) as $script) {
54
+        if ($script = find_in_path(supprimer_timestamp($script))) {
55
+            $script = timestamp($script);
56
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
57
+        }
58
+    }
59
+    // inserer avant le premier script externe ou a la fin
60
+    if (
61
+        preg_match(',<script[^><]*src=,', $texte, $match)
62
+        and $p = strpos($texte, $match[0])
63
+    ) {
64
+        $texte = substr_replace($texte, $x, $p, 0);
65
+    } else {
66
+        $texte .= $x;
67
+    }
68 68
 
69
-	return $texte;
69
+    return $texte;
70 70
 }
71 71
 
72 72
 
@@ -79,43 +79,43 @@  discard block
 block discarded – undo
79 79
  * @return string
80 80
  */
81 81
 function affichage_final_prive_title_auto($texte) {
82
-	if (
83
-		strpos($texte, '<title>') === false
84
-		and
85
-		(preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
86
-			or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
87
-		and $match = textebrut(trim($match[1]))
88
-		and ($p = strpos($texte, '<head>')) !== false
89
-	) {
90
-		if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
91
-			$nom_site_spip = _T('info_mon_site_spip');
92
-		}
82
+    if (
83
+        strpos($texte, '<title>') === false
84
+        and
85
+        (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match)
86
+            or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match))
87
+        and $match = textebrut(trim($match[1]))
88
+        and ($p = strpos($texte, '<head>')) !== false
89
+    ) {
90
+        if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) {
91
+            $nom_site_spip = _T('info_mon_site_spip');
92
+        }
93 93
 
94
-		$titre = '<title>['
95
-			. $nom_site_spip
96
-			. '] ' . $match
97
-			. '</title>';
94
+        $titre = '<title>['
95
+            . $nom_site_spip
96
+            . '] ' . $match
97
+            . '</title>';
98 98
 
99
-		$texte = substr_replace($texte, $titre, $p + 6, 0);
100
-	}
99
+        $texte = substr_replace($texte, $titre, $p + 6, 0);
100
+    }
101 101
 
102
-	return $texte;
102
+    return $texte;
103 103
 }
104 104
 
105 105
 
106 106
 // Fonction standard pour le pipeline 'boite_infos'
107 107
 // https://code.spip.net/@f_boite_infos
108 108
 function f_boite_infos($flux) {
109
-	$args = $flux['args'];
110
-	$type = $args['type'];
111
-	unset($args['row']);
112
-	if (!trouver_fond($type, 'prive/objets/infos/')) {
113
-		$type = 'objet';
114
-	}
115
-	$args['espace_prive'] = 1;
116
-	$flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
109
+    $args = $flux['args'];
110
+    $type = $args['type'];
111
+    unset($args['row']);
112
+    if (!trouver_fond($type, 'prive/objets/infos/')) {
113
+        $type = 'objet';
114
+    }
115
+    $args['espace_prive'] = 1;
116
+    $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args);
117 117
 
118
-	return $flux;
118
+    return $flux;
119 119
 }
120 120
 
121 121
 
@@ -134,97 +134,97 @@  discard block
 block discarded – undo
134 134
  * @return array Données du pipeline
135 135
  */
136 136
 function f_afficher_blocs_ecrire($flux) {
137
-	static $o = [];
138
-	if (is_string($fond = $flux['args']['fond'])) {
139
-		$exec = isset($flux['args']['contexte']['exec']) ? $flux['args']['contexte']['exec'] : _request('exec');
140
-		if (!isset($o[$exec])) {
141
-			$o[$exec] = trouver_objet_exec($exec);
142
-		}
143
-		// cas particulier
144
-		if ($exec == 'infos_perso') {
145
-			$flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
146
-		}
147
-		$typepage = (isset($flux['args']['contexte']['type-page']) ? $flux['args']['contexte']['type-page'] : $exec);
148
-		if ($fond == "prive/squelettes/navigation/$typepage") {
149
-			$flux['data']['texte'] = pipeline(
150
-				'affiche_gauche',
151
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
152
-			);
153
-		} elseif ($fond == "prive/squelettes/extra/$typepage") {
154
-			include_spip('inc/presentation_mini');
155
-			$flux['data']['texte'] = pipeline(
156
-				'affiche_droite',
157
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
158
-			) . liste_objets_bloques(
159
-				$exec,
160
-				$flux['args']['contexte']
161
-			);
162
-		} elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
163
-			// id non defini sur les formulaire de nouveaux objets
164
-			$id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
165
-			$flux['data']['texte'] = pipeline(
166
-				'affiche_hierarchie',
167
-				['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']]
168
-			);
169
-		} elseif ($fond == "prive/squelettes/contenu/$typepage") {
170
-			// Préparation du marqueur affiche_milieu
171
-			// Si c'est la page d'un objet pas en édition, on l'encapsule dans un div
172
-			$est_page_objet = !empty($o[$exec]['type']);
173
-			$est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true);
174
-			$encapsuler_milieu = ($est_page_objet and !$est_en_edition);
175
-			$flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur(
176
-				$flux['data']['texte'],
177
-				'<!--affiche_milieu-->',
178
-				'<div id=["\']wysiwyg',
179
-				$encapsuler_milieu ? '<div class="affiche_milieu">' : '',
180
-				$encapsuler_milieu ? '</div>' : ''
181
-			);
182
-			if (
183
-				$o[$exec]
184
-				and $objet = $o[$exec]['type']
185
-				and $o[$exec]['edition'] == false
186
-				and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
187
-				and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
188
-			) {
189
-				// inserer le formulaire de traduction
190
-				$flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
191
-					'prive/objets/editer/traductions',
192
-					['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
193
-				) . '<!--affiche_milieu-->', $flux['data']['texte']);
194
-				$flux['data']['texte'] = pipeline('afficher_fiche_objet', [
195
-					'args' => [
196
-						'contexte' => $flux['args']['contexte'],
197
-						'type' => $objet,
198
-						'id' => $id
199
-					],
200
-					'data' => $flux['data']['texte']
201
-				]);
202
-			}
203
-			$flux['data']['texte'] = pipeline(
204
-				'affiche_milieu',
205
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
206
-			);
207
-		} elseif ($fond == 'prive/squelettes/inclure/pied') {
208
-			$flux['data']['texte'] = pipeline(
209
-				'affiche_pied',
210
-				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
211
-			);
212
-		} elseif (
213
-			strncmp($fond, 'prive/objets/contenu/', 21) == 0
214
-			and $objet = basename($fond)
215
-			and $objet == substr($fond, 21)
216
-			and isset($o[$objet])
217
-			and $o[$objet]
218
-		) {
219
-			$id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
220
-			$flux['data']['texte'] = pipeline('afficher_contenu_objet', [
221
-				'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']],
222
-				'data' => $flux['data']['texte']
223
-			]);
224
-		}
225
-	}
137
+    static $o = [];
138
+    if (is_string($fond = $flux['args']['fond'])) {
139
+        $exec = isset($flux['args']['contexte']['exec']) ? $flux['args']['contexte']['exec'] : _request('exec');
140
+        if (!isset($o[$exec])) {
141
+            $o[$exec] = trouver_objet_exec($exec);
142
+        }
143
+        // cas particulier
144
+        if ($exec == 'infos_perso') {
145
+            $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur'];
146
+        }
147
+        $typepage = (isset($flux['args']['contexte']['type-page']) ? $flux['args']['contexte']['type-page'] : $exec);
148
+        if ($fond == "prive/squelettes/navigation/$typepage") {
149
+            $flux['data']['texte'] = pipeline(
150
+                'affiche_gauche',
151
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
152
+            );
153
+        } elseif ($fond == "prive/squelettes/extra/$typepage") {
154
+            include_spip('inc/presentation_mini');
155
+            $flux['data']['texte'] = pipeline(
156
+                'affiche_droite',
157
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
158
+            ) . liste_objets_bloques(
159
+                $exec,
160
+                $flux['args']['contexte']
161
+            );
162
+        } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) {
163
+            // id non defini sur les formulaire de nouveaux objets
164
+            $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0;
165
+            $flux['data']['texte'] = pipeline(
166
+                'affiche_hierarchie',
167
+                ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']]
168
+            );
169
+        } elseif ($fond == "prive/squelettes/contenu/$typepage") {
170
+            // Préparation du marqueur affiche_milieu
171
+            // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div
172
+            $est_page_objet = !empty($o[$exec]['type']);
173
+            $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true);
174
+            $encapsuler_milieu = ($est_page_objet and !$est_en_edition);
175
+            $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur(
176
+                $flux['data']['texte'],
177
+                '<!--affiche_milieu-->',
178
+                '<div id=["\']wysiwyg',
179
+                $encapsuler_milieu ? '<div class="affiche_milieu">' : '',
180
+                $encapsuler_milieu ? '</div>' : ''
181
+            );
182
+            if (
183
+                $o[$exec]
184
+                and $objet = $o[$exec]['type']
185
+                and $o[$exec]['edition'] == false
186
+                and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']])
187
+                and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']])
188
+            ) {
189
+                // inserer le formulaire de traduction
190
+                $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
191
+                    'prive/objets/editer/traductions',
192
+                    ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
193
+                ) . '<!--affiche_milieu-->', $flux['data']['texte']);
194
+                $flux['data']['texte'] = pipeline('afficher_fiche_objet', [
195
+                    'args' => [
196
+                        'contexte' => $flux['args']['contexte'],
197
+                        'type' => $objet,
198
+                        'id' => $id
199
+                    ],
200
+                    'data' => $flux['data']['texte']
201
+                ]);
202
+            }
203
+            $flux['data']['texte'] = pipeline(
204
+                'affiche_milieu',
205
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
206
+            );
207
+        } elseif ($fond == 'prive/squelettes/inclure/pied') {
208
+            $flux['data']['texte'] = pipeline(
209
+                'affiche_pied',
210
+                ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
211
+            );
212
+        } elseif (
213
+            strncmp($fond, 'prive/objets/contenu/', 21) == 0
214
+            and $objet = basename($fond)
215
+            and $objet == substr($fond, 21)
216
+            and isset($o[$objet])
217
+            and $o[$objet]
218
+        ) {
219
+            $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]);
220
+            $flux['data']['texte'] = pipeline('afficher_contenu_objet', [
221
+                'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']],
222
+                'data' => $flux['data']['texte']
223
+            ]);
224
+        }
225
+    }
226 226
 
227
-	return $flux;
227
+    return $flux;
228 228
 }
229 229
 
230 230
 /**
@@ -252,36 +252,36 @@  discard block
 block discarded – undo
252 252
  */
253 253
 function afficher_blocs_ecrire_preparer_marqueur(?string $texte, string $marqueur, string $inserer_avant, string $ouvrir = '', string $fermer = ''): ?string {
254 254
 
255
-	if ($texte) {
256
-		$encapsuler = (($ouvrir and $fermer) ? true : false);
257
-		$marqueur_pos = strpos($texte, $marqueur);
258
-		$full_marqueur = "$ouvrir$marqueur$fermer";
255
+    if ($texte) {
256
+        $encapsuler = (($ouvrir and $fermer) ? true : false);
257
+        $marqueur_pos = strpos($texte, $marqueur);
258
+        $full_marqueur = "$ouvrir$marqueur$fermer";
259 259
 
260
-		// Le marqueur est absent : on l'ajoute avant l'élément indiqué
261
-		if ($marqueur_pos  === false) {
262
-			$texte = preg_replace(
263
-				",$inserer_avant,",
264
-				"$full_marqueur\\0",
265
-				$texte
266
-			);
267
-		// Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes.
268
-		// Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante.
269
-		// Il ne faut donc aucun espace blanc en trop.
270
-		} elseif (
271
-			$marqueur_pos !== false
272
-			and $encapsuler
273
-			and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir
274
-		) {
275
-			$texte = substr_replace(
276
-				$texte,
277
-				$full_marqueur,
278
-				$marqueur_pos,
279
-				strlen($marqueur)
280
-			);
281
-		}
282
-	}
260
+        // Le marqueur est absent : on l'ajoute avant l'élément indiqué
261
+        if ($marqueur_pos  === false) {
262
+            $texte = preg_replace(
263
+                ",$inserer_avant,",
264
+                "$full_marqueur\\0",
265
+                $texte
266
+            );
267
+        // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes.
268
+        // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante.
269
+        // Il ne faut donc aucun espace blanc en trop.
270
+        } elseif (
271
+            $marqueur_pos !== false
272
+            and $encapsuler
273
+            and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir
274
+        ) {
275
+            $texte = substr_replace(
276
+                $texte,
277
+                $full_marqueur,
278
+                $marqueur_pos,
279
+                strlen($marqueur)
280
+            );
281
+        }
282
+    }
283 283
 
284
-	return $texte;
284
+    return $texte;
285 285
 }
286 286
 
287 287
 /**
@@ -292,23 +292,23 @@  discard block
 block discarded – undo
292 292
  * @return string
293 293
  */
294 294
 function f_queue_affiche_milieu($flux) {
295
-	$args = $flux['args'];
296
-	$res = '';
297
-	foreach ($args as $key => $arg) {
298
-		if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) {
299
-			$objet = preg_replace(',^id_,', '', $key);
300
-			$res .= recuperer_fond(
301
-				'modeles/object_jobs_list',
302
-				['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1],
303
-				['ajax' => true]
304
-			);
305
-		}
306
-	}
307
-	if ($res) {
308
-		$flux['data'] = $res . $flux['data'];
309
-	}
295
+    $args = $flux['args'];
296
+    $res = '';
297
+    foreach ($args as $key => $arg) {
298
+        if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) {
299
+            $objet = preg_replace(',^id_,', '', $key);
300
+            $res .= recuperer_fond(
301
+                'modeles/object_jobs_list',
302
+                ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1],
303
+                ['ajax' => true]
304
+            );
305
+        }
306
+    }
307
+    if ($res) {
308
+        $flux['data'] = $res . $flux['data'];
309
+    }
310 310
 
311
-	return $flux;
311
+    return $flux;
312 312
 }
313 313
 
314 314
 /**
@@ -322,39 +322,39 @@  discard block
 block discarded – undo
322 322
  * @return array|bool
323 323
  */
324 324
 function trouver_objet_exec($exec) {
325
-	static $objet_exec = [];
326
-	if (!$exec) {
327
-		return false;
328
-	}
329
-	// cas particulier
330
-	if ($exec == 'infos_perso') {
331
-		$exec = 'auteur';
332
-		set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
333
-	}
334
-	if (!isset($objet_exec[$exec])) {
335
-		$objet_exec[$exec] = false;
336
-		$infos = lister_tables_objets_sql();
337
-		foreach ($infos as $t => $info) {
338
-			if ($exec == $info['url_edit'] and $info['editable']) {
339
-				return $objet_exec[$exec] = [
340
-					'edition' => $exec == $info['url_voir'] ? '' : true,
341
-					'table_objet_sql' => $t,
342
-					'table' => $info['table_objet'],
343
-					'type' => $info['type'],
344
-					'id_table_objet' => id_table_objet($info['type'])
345
-				];
346
-			}
347
-			if ($exec == $info['url_voir']) {
348
-				return $objet_exec[$exec] = [
349
-					'edition' => false,
350
-					'table_objet_sql' => $t,
351
-					'table' => $info['table_objet'],
352
-					'type' => $info['type'],
353
-					'id_table_objet' => id_table_objet($info['type'])
354
-				];
355
-			}
356
-		}
357
-	}
325
+    static $objet_exec = [];
326
+    if (!$exec) {
327
+        return false;
328
+    }
329
+    // cas particulier
330
+    if ($exec == 'infos_perso') {
331
+        $exec = 'auteur';
332
+        set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']);
333
+    }
334
+    if (!isset($objet_exec[$exec])) {
335
+        $objet_exec[$exec] = false;
336
+        $infos = lister_tables_objets_sql();
337
+        foreach ($infos as $t => $info) {
338
+            if ($exec == $info['url_edit'] and $info['editable']) {
339
+                return $objet_exec[$exec] = [
340
+                    'edition' => $exec == $info['url_voir'] ? '' : true,
341
+                    'table_objet_sql' => $t,
342
+                    'table' => $info['table_objet'],
343
+                    'type' => $info['type'],
344
+                    'id_table_objet' => id_table_objet($info['type'])
345
+                ];
346
+            }
347
+            if ($exec == $info['url_voir']) {
348
+                return $objet_exec[$exec] = [
349
+                    'edition' => false,
350
+                    'table_objet_sql' => $t,
351
+                    'table' => $info['table_objet'],
352
+                    'type' => $info['type'],
353
+                    'id_table_objet' => id_table_objet($info['type'])
354
+                ];
355
+            }
356
+        }
357
+    }
358 358
 
359
-	return $objet_exec[$exec];
359
+    return $objet_exec[$exec];
360 360
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 
94 94
 		$titre = '<title>['
95 95
 			. $nom_site_spip
96
-			. '] ' . $match
96
+			. '] '.$match
97 97
 			. '</title>';
98 98
 
99 99
 		$texte = substr_replace($texte, $titre, $p + 6, 0);
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 			$flux['data']['texte'] = pipeline(
156 156
 				'affiche_droite',
157 157
 				['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']]
158
-			) . liste_objets_bloques(
158
+			).liste_objets_bloques(
159 159
 				$exec,
160 160
 				$flux['args']['contexte']
161 161
 			);
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 				$flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond(
191 191
 					'prive/objets/editer/traductions',
192 192
 					['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1]
193
-				) . '<!--affiche_milieu-->', $flux['data']['texte']);
193
+				).'<!--affiche_milieu-->', $flux['data']['texte']);
194 194
 				$flux['data']['texte'] = pipeline('afficher_fiche_objet', [
195 195
 					'args' => [
196 196
 						'contexte' => $flux['args']['contexte'],
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		$full_marqueur = "$ouvrir$marqueur$fermer";
259 259
 
260 260
 		// Le marqueur est absent : on l'ajoute avant l'élément indiqué
261
-		if ($marqueur_pos  === false) {
261
+		if ($marqueur_pos === false) {
262 262
 			$texte = preg_replace(
263 263
 				",$inserer_avant,",
264 264
 				"$full_marqueur\\0",
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 		}
306 306
 	}
307 307
 	if ($res) {
308
-		$flux['data'] = $res . $flux['data'];
308
+		$flux['data'] = $res.$flux['data'];
309 309
 	}
310 310
 
311 311
 	return $flux;
Please login to merge, or discard this patch.
ecrire/inc/informer.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -11,74 +11,74 @@
 block discarded – undo
11 11
 \***************************************************************************/
12 12
 
13 13
 if (!defined('_ECRIRE_INC_VERSION')) {
14
-	return;
14
+    return;
15 15
 }
16 16
 
17 17
 # Les information d'une rubrique selectionnee dans le mini navigateur
18 18
 
19 19
 // https://code.spip.net/@inc_informer_dist
20 20
 function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') {
21
-	include_spip('inc/texte');
22
-	$titre = $descriptif = '';
23
-	if ($type == 'rubrique') {
24
-		$row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id));
25
-		if ($row) {
26
-			$titre = typo($row['titre']);
27
-			$descriptif = propre($row['descriptif']);
28
-		} else {
29
-			$titre = _T('info_racine_site');
30
-		}
31
-	}
21
+    include_spip('inc/texte');
22
+    $titre = $descriptif = '';
23
+    if ($type == 'rubrique') {
24
+        $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id));
25
+        if ($row) {
26
+            $titre = typo($row['titre']);
27
+            $descriptif = propre($row['descriptif']);
28
+        } else {
29
+            $titre = _T('info_racine_site');
30
+        }
31
+    }
32 32
 
33
-	$res = '';
34
-	if ($type == 'rubrique' and $GLOBALS['spip_display'] != 1 and isset($GLOBALS['meta']['image_process'])) {
35
-		if ($GLOBALS['meta']['image_process'] != 'non') {
36
-			$chercher_logo = charger_fonction('chercher_logo', 'inc');
37
-			if ($res = $chercher_logo($id, 'id_rubrique', 'on')) {
38
-				list($fid, $dir, $nom, $format) = $res;
39
-				include_spip('inc/filtres_images_mini');
40
-				$res = image_reduire("<img src='$fid' alt='' />", 100, 48);
41
-				if ($res) {
42
-					$res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>";
43
-				}
44
-			}
45
-		}
46
-	}
33
+    $res = '';
34
+    if ($type == 'rubrique' and $GLOBALS['spip_display'] != 1 and isset($GLOBALS['meta']['image_process'])) {
35
+        if ($GLOBALS['meta']['image_process'] != 'non') {
36
+            $chercher_logo = charger_fonction('chercher_logo', 'inc');
37
+            if ($res = $chercher_logo($id, 'id_rubrique', 'on')) {
38
+                list($fid, $dir, $nom, $format) = $res;
39
+                include_spip('inc/filtres_images_mini');
40
+                $res = image_reduire("<img src='$fid' alt='' />", 100, 48);
41
+                if ($res) {
42
+                    $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>";
43
+                }
44
+            }
45
+        }
46
+    }
47 47
 
48
-	$rac = spip_htmlentities($rac, ENT_QUOTES);
49
-	$do = spip_htmlentities($do, ENT_QUOTES);
50
-	$id = intval($id);
48
+    $rac = spip_htmlentities($rac, ENT_QUOTES);
49
+    $do = spip_htmlentities($do, ENT_QUOTES);
50
+    $id = intval($id);
51 51
 
52 52
 # ce lien provoque la selection (directe) de la rubrique cliquee
53 53
 # et l'affichage de son titre dans le bandeau
54
-	$titre = strtr(
55
-		str_replace(
56
-			"'",
57
-			'&#8217;',
58
-			str_replace('"', '&#34;', textebrut($titre))
59
-		),
60
-		"\n\r",
61
-		'  '
62
-	);
54
+    $titre = strtr(
55
+        str_replace(
56
+            "'",
57
+            '&#8217;',
58
+            str_replace('"', '&#34;', textebrut($titre))
59
+        ),
60
+        "\n\r",
61
+        '  '
62
+    );
63 63
 
64
-	$js_func = $do . '_selection_titre';
64
+    $js_func = $do . '_selection_titre';
65 65
 
66
-	return "<div style='display: none;'>"
67
-	. "<input type='text' id='" . $rac . "_sel' value='$id' />"
68
-	. "<input type='text' id='" . $rac . "_sel2' value=\""
69
-	. entites_html($titre)
70
-	. '" />'
71
-	. '</div>'
72
-	. "<div class='informer' style='padding: 5px; border-top: 0px;'>"
73
-	. '<div class="informer__item">'
74
-	. (!$res ? '' : $res)
75
-	. "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>'
76
-	. (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>')
77
-	. '</div>'
78
-	. "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
79
-	. "<input type='submit' class='fondo btn submit' value='"
80
-	. _T('bouton_choisir')
81
-	. "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />"
82
-	. '</div>'
83
-	. '</div>';
66
+    return "<div style='display: none;'>"
67
+    . "<input type='text' id='" . $rac . "_sel' value='$id' />"
68
+    . "<input type='text' id='" . $rac . "_sel2' value=\""
69
+    . entites_html($titre)
70
+    . '" />'
71
+    . '</div>'
72
+    . "<div class='informer' style='padding: 5px; border-top: 0px;'>"
73
+    . '<div class="informer__item">'
74
+    . (!$res ? '' : $res)
75
+    . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>'
76
+    . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>')
77
+    . '</div>'
78
+    . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
79
+    . "<input type='submit' class='fondo btn submit' value='"
80
+    . _T('bouton_choisir')
81
+    . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />"
82
+    . '</div>'
83
+    . '</div>';
84 84
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
 	include_spip('inc/texte');
22 22
 	$titre = $descriptif = '';
23 23
 	if ($type == 'rubrique') {
24
-		$row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id));
24
+		$row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.intval($id));
25 25
 		if ($row) {
26 26
 			$titre = typo($row['titre']);
27 27
 			$descriptif = propre($row['descriptif']);
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 				include_spip('inc/filtres_images_mini');
40 40
 				$res = image_reduire("<img src='$fid' alt='' />", 100, 48);
41 41
 				if ($res) {
42
-					$res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>";
42
+					$res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>";
43 43
 				}
44 44
 			}
45 45
 		}
@@ -61,21 +61,21 @@  discard block
 block discarded – undo
61 61
 		'  '
62 62
 	);
63 63
 
64
-	$js_func = $do . '_selection_titre';
64
+	$js_func = $do.'_selection_titre';
65 65
 
66 66
 	return "<div style='display: none;'>"
67
-	. "<input type='text' id='" . $rac . "_sel' value='$id' />"
68
-	. "<input type='text' id='" . $rac . "_sel2' value=\""
67
+	. "<input type='text' id='".$rac."_sel' value='$id' />"
68
+	. "<input type='text' id='".$rac."_sel2' value=\""
69 69
 	. entites_html($titre)
70 70
 	. '" />'
71 71
 	. '</div>'
72 72
 	. "<div class='informer' style='padding: 5px; border-top: 0px;'>"
73 73
 	. '<div class="informer__item">'
74 74
 	. (!$res ? '' : $res)
75
-	. "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>'
76
-	. (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>')
75
+	. "<p class='informer__titre'><b>".safehtml($titre).'</b></p>'
76
+	. (!$descriptif ? '' : "<div class='informer__descriptif'>".safehtml($descriptif).'</div>')
77 77
 	. '</div>'
78
-	. "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>"
78
+	. "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>"
79 79
 	. "<input type='submit' class='fondo btn submit' value='"
80 80
 	. _T('bouton_choisir')
81 81
 	. "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />"
Please login to merge, or discard this patch.
ecrire/inc/admin.php 2 patches
Indentation   +129 added lines, -129 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
 /**
@@ -45,29 +45,29 @@  discard block
 block discarded – undo
45 45
  *     sinon code HTML de la page après le traitement effectué.
46 46
  **/
47 47
 function inc_admin_dist($script, $titre, $comment = '', $anonymous = false) {
48
-	$reprise = true;
49
-	if (
50
-		!isset($GLOBALS['meta'][$script])
51
-		or !isset($GLOBALS['meta']['admin'])
52
-	) {
53
-		$reprise = false;
54
-		$res = debut_admin($script, $titre, $comment);
55
-		if ($res) {
56
-			return $res;
57
-		}
58
-		spip_log("meta: $script " . print_r($_POST, true));
59
-		ecrire_meta($script, serialize($_POST));
60
-	}
48
+    $reprise = true;
49
+    if (
50
+        !isset($GLOBALS['meta'][$script])
51
+        or !isset($GLOBALS['meta']['admin'])
52
+    ) {
53
+        $reprise = false;
54
+        $res = debut_admin($script, $titre, $comment);
55
+        if ($res) {
56
+            return $res;
57
+        }
58
+        spip_log("meta: $script " . print_r($_POST, true));
59
+        ecrire_meta($script, serialize($_POST));
60
+    }
61 61
 
62
-	$res = admin_verifie_session($script, $anonymous);
63
-	if ($res) {
64
-		return $res;
65
-	}
66
-	$base = charger_fonction($script, 'base');
67
-	$base($titre, $reprise);
68
-	fin_admin($script);
62
+    $res = admin_verifie_session($script, $anonymous);
63
+    if ($res) {
64
+        return $res;
65
+    }
66
+    $base = charger_fonction($script, 'base');
67
+    $base($titre, $reprise);
68
+    fin_admin($script);
69 69
 
70
-	return '';
70
+    return '';
71 71
 }
72 72
 
73 73
 /**
@@ -98,35 +98,35 @@  discard block
 block discarded – undo
98 98
  *     Code HTML si message d'erreur, '' sinon;
99 99
  */
100 100
 function admin_verifie_session($script, $anonymous = false) {
101
-	include_spip('base/abstract_sql');
102
-	$pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']);
103
-	$signal = fichier_admin($script, "$script$pref");
104
-	$valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'");
105
-	if ($valeur === null) {
106
-		ecrire_meta('admin', $signal, 'non');
107
-	} else {
108
-		if (!$anonymous and ($valeur != $signal)) {
109
-			if (
110
-				!preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)
111
-				or intval($l[2]) != $GLOBALS['visiteur_session']['id_auteur']
112
-			) {
113
-				include_spip('inc/minipres');
114
-				spip_log("refus de lancer $script, priorite a $valeur");
101
+    include_spip('base/abstract_sql');
102
+    $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']);
103
+    $signal = fichier_admin($script, "$script$pref");
104
+    $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'");
105
+    if ($valeur === null) {
106
+        ecrire_meta('admin', $signal, 'non');
107
+    } else {
108
+        if (!$anonymous and ($valeur != $signal)) {
109
+            if (
110
+                !preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)
111
+                or intval($l[2]) != $GLOBALS['visiteur_session']['id_auteur']
112
+            ) {
113
+                include_spip('inc/minipres');
114
+                spip_log("refus de lancer $script, priorite a $valeur");
115 115
 
116
-				return minipres(_T('info_travaux_texte'), '', ['status' => 503]);
117
-			}
118
-		}
119
-	}
120
-	$journal = 'spip';
121
-	if (autoriser('configurer')) {
122
-		// c'est une action webmestre, soit par ftp soit par statut webmestre
123
-		$journal = 'webmestre';
124
-	}
125
-	// on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
116
+                return minipres(_T('info_travaux_texte'), '', ['status' => 503]);
117
+            }
118
+        }
119
+    }
120
+    $journal = 'spip';
121
+    if (autoriser('configurer')) {
122
+        // c'est une action webmestre, soit par ftp soit par statut webmestre
123
+        $journal = 'webmestre';
124
+    }
125
+    // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
126 126
 
127
-	spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal);
127
+    spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal);
128 128
 
129
-	return '';
129
+    return '';
130 130
 }
131 131
 
132 132
 /**
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
  *     Chemin du répertoire.
140 140
  **/
141 141
 function dir_admin() {
142
-	if (autoriser('configurer')) {
143
-		return _DIR_TMP;
144
-	} else {
145
-		return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
146
-	}
142
+    if (autoriser('configurer')) {
143
+        return _DIR_TMP;
144
+    } else {
145
+        return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
146
+    }
147 147
 }
148 148
 
149 149
 /**
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
  *     Nom du fichier
161 161
  **/
162 162
 function fichier_admin($action, $pref = 'admin_') {
163
-	return $pref .
164
-	substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10);
163
+    return $pref .
164
+    substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10);
165 165
 }
166 166
 
167 167
 /**
@@ -187,73 +187,73 @@  discard block
 block discarded – undo
187 187
  *     sinon chaîne vide si déjà fait.
188 188
  **/
189 189
 function debut_admin($script, $action = '', $corps = '') {
190
-	if ((!$action) || !(autoriser('webmestre') or autoriser('chargerftp'))) {
191
-		include_spip('inc/minipres');
190
+    if ((!$action) || !(autoriser('webmestre') or autoriser('chargerftp'))) {
191
+        include_spip('inc/minipres');
192 192
 
193
-		return minipres();
194
-	} else {
195
-		$dir = dir_admin();
196
-		$signal = fichier_admin($script);
197
-		if (@file_exists($dir . $signal)) {
198
-			spip_log("Action admin: $action");
193
+        return minipres();
194
+    } else {
195
+        $dir = dir_admin();
196
+        $signal = fichier_admin($script);
197
+        if (@file_exists($dir . $signal)) {
198
+            spip_log("Action admin: $action");
199 199
 
200
-			return '';
201
-		}
202
-		include_spip('inc/minipres');
200
+            return '';
201
+        }
202
+        include_spip('inc/minipres');
203 203
 
204
-		// Si on est un super-admin, un bouton de validation suffit
205
-		// sauf dans les cas destroy
206
-		if (
207
-			(autoriser('webmestre') or $script === 'repair')
208
-			and $script != 'delete_all'
209
-		) {
210
-			if (_request('validation_admin') == $signal) {
211
-				spip_log("Action super-admin: $action");
204
+        // Si on est un super-admin, un bouton de validation suffit
205
+        // sauf dans les cas destroy
206
+        if (
207
+            (autoriser('webmestre') or $script === 'repair')
208
+            and $script != 'delete_all'
209
+        ) {
210
+            if (_request('validation_admin') == $signal) {
211
+                spip_log("Action super-admin: $action");
212 212
 
213
-				return '';
214
-			}
215
-			$corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />';
216
-			$suivant = _T('bouton_valider');
217
-			$js = '';
218
-		} else {
219
-			// cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj)
220
-			// l'insertion du script a cet endroit n'est pas xhtml licite
221
-			// mais evite de l'embarquer dans toutes les pages minipres
222
-			$corps .= http_script('', 'spip_barre.js');
213
+                return '';
214
+            }
215
+            $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />';
216
+            $suivant = _T('bouton_valider');
217
+            $js = '';
218
+        } else {
219
+            // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj)
220
+            // l'insertion du script a cet endroit n'est pas xhtml licite
221
+            // mais evite de l'embarquer dans toutes les pages minipres
222
+            $corps .= http_script('', 'spip_barre.js');
223 223
 
224
-			$corps .= '<fieldset><legend>'
225
-				. _T('info_authentification_ftp')
226
-				. aider('ftp_auth')
227
-				. "</legend>\n<label for='fichier'>"
228
-				. _T('info_creer_repertoire')
229
-				. "</label>\n"
230
-				. "<span id='signal' class='formo'>" . $signal . '</span>'
231
-				. "<input type='hidden' id='fichier' name='fichier' value='"
232
-				. $signal
233
-				. "' />"
234
-				. _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)])
235
-				. '</fieldset>';
224
+            $corps .= '<fieldset><legend>'
225
+                . _T('info_authentification_ftp')
226
+                . aider('ftp_auth')
227
+                . "</legend>\n<label for='fichier'>"
228
+                . _T('info_creer_repertoire')
229
+                . "</label>\n"
230
+                . "<span id='signal' class='formo'>" . $signal . '</span>'
231
+                . "<input type='hidden' id='fichier' name='fichier' value='"
232
+                . $signal
233
+                . "' />"
234
+                . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)])
235
+                . '</fieldset>';
236 236
 
237
-			$suivant = _T('bouton_recharger_page');
237
+            $suivant = _T('bouton_recharger_page');
238 238
 
239
-			// code volontairement tordu:
240
-			// provoquer la copie dans le presse papier du nom du repertoire
241
-			// en remettant a vide le champ pour que ca marche aussi en cas
242
-			// de JavaScript inactif.
243
-			$js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'";
244
-		}
239
+            // code volontairement tordu:
240
+            // provoquer la copie dans le presse papier du nom du repertoire
241
+            // en remettant a vide le champ pour que ca marche aussi en cas
242
+            // de JavaScript inactif.
243
+            $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'";
244
+        }
245 245
 
246
-		// admin/xxx correspond
247
-		// a exec/base_xxx de preference
248
-		// et exec/xxx sinon (compat)
249
-		if (tester_url_ecrire("base_$script")) {
250
-			$script = "base_$script";
251
-		}
252
-		$form = copy_request($script, $corps, $suivant);
253
-		$info_action = _T('info_action', ['action' => "$action"]);
246
+        // admin/xxx correspond
247
+        // a exec/base_xxx de preference
248
+        // et exec/xxx sinon (compat)
249
+        if (tester_url_ecrire("base_$script")) {
250
+            $script = "base_$script";
251
+        }
252
+        $form = copy_request($script, $corps, $suivant);
253
+        $info_action = _T('info_action', ['action' => "$action"]);
254 254
 
255
-		return minipres($info_action, $form, $js);
256
-	}
255
+        return minipres($info_action, $form, $js);
256
+    }
257 257
 }
258 258
 
259 259
 /**
@@ -264,13 +264,13 @@  discard block
 block discarded – undo
264 264
  *     Nom de l'action (en base) qui a été exécutée
265 265
  **/
266 266
 function fin_admin($action) {
267
-	$signal = dir_admin() . fichier_admin($action);
268
-	spip_unlink($signal);
269
-	if ($action != 'delete_all') {
270
-		effacer_meta($action);
271
-		effacer_meta('admin');
272
-		spip_log("efface les meta admin et $action ");
273
-	}
267
+    $signal = dir_admin() . fichier_admin($action);
268
+    spip_unlink($signal);
269
+    if ($action != 'delete_all') {
270
+        effacer_meta($action);
271
+        effacer_meta('admin');
272
+        spip_log("efface les meta admin et $action ");
273
+    }
274 274
 }
275 275
 
276 276
 /**
@@ -289,14 +289,14 @@  discard block
 block discarded – undo
289 289
  *     Code HTML du formulaire
290 290
  **/
291 291
 function copy_request($script, $suite, $submit = '') {
292
-	include_spip('inc/filtres');
293
-	foreach (array_merge($_POST, $_GET) as $n => $c) {
294
-		if (!in_array($n, ['fichier', 'exec', 'validation_admin']) and !is_array($c)) {
295
-			$suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" .
296
-				entites_html($c) .
297
-				"'  />";
298
-		}
299
-	}
292
+    include_spip('inc/filtres');
293
+    foreach (array_merge($_POST, $_GET) as $n => $c) {
294
+        if (!in_array($n, ['fichier', 'exec', 'validation_admin']) and !is_array($c)) {
295
+            $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" .
296
+                entites_html($c) .
297
+                "'  />";
298
+        }
299
+    }
300 300
 
301
-	return generer_form_ecrire($script, $suite, '', $submit);
301
+    return generer_form_ecrire($script, $suite, '', $submit);
302 302
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 		if ($res) {
56 56
 			return $res;
57 57
 		}
58
-		spip_log("meta: $script " . print_r($_POST, true));
58
+		spip_log("meta: $script ".print_r($_POST, true));
59 59
 		ecrire_meta($script, serialize($_POST));
60 60
 	}
61 61
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	}
125 125
 	// on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ?
126 126
 
127
-	spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal);
127
+	spip_log("admin $pref".($valeur ? ' (reprise)' : ' (init)'), $journal);
128 128
 
129 129
 	return '';
130 130
 }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	if (autoriser('configurer')) {
143 143
 		return _DIR_TMP;
144 144
 	} else {
145
-		return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/';
145
+		return _DIR_TRANSFERT.$GLOBALS['visiteur_session']['login'].'/';
146 146
 	}
147 147
 }
148 148
 
@@ -160,8 +160,8 @@  discard block
 block discarded – undo
160 160
  *     Nom du fichier
161 161
  **/
162 162
 function fichier_admin($action, $pref = 'admin_') {
163
-	return $pref .
164
-	substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10);
163
+	return $pref.
164
+	substr(md5($action.(time() & ~2047).$GLOBALS['visiteur_session']['login']), 0, 10);
165 165
 }
166 166
 
167 167
 /**
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 	} else {
195 195
 		$dir = dir_admin();
196 196
 		$signal = fichier_admin($script);
197
-		if (@file_exists($dir . $signal)) {
197
+		if (@file_exists($dir.$signal)) {
198 198
 			spip_log("Action admin: $action");
199 199
 
200 200
 			return '';
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 
213 213
 				return '';
214 214
 			}
215
-			$corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />';
215
+			$corps .= '<input type="hidden" name="validation_admin" value="'.$signal.'" />';
216 216
 			$suivant = _T('bouton_valider');
217 217
 			$js = '';
218 218
 		} else {
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 				. "</legend>\n<label for='fichier'>"
228 228
 				. _T('info_creer_repertoire')
229 229
 				. "</label>\n"
230
-				. "<span id='signal' class='formo'>" . $signal . '</span>'
230
+				. "<span id='signal' class='formo'>".$signal.'</span>'
231 231
 				. "<input type='hidden' id='fichier' name='fichier' value='"
232 232
 				. $signal
233 233
 				. "' />"
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
  *     Nom de l'action (en base) qui a été exécutée
265 265
  **/
266 266
 function fin_admin($action) {
267
-	$signal = dir_admin() . fichier_admin($action);
267
+	$signal = dir_admin().fichier_admin($action);
268 268
 	spip_unlink($signal);
269 269
 	if ($action != 'delete_all') {
270 270
 		effacer_meta($action);
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	include_spip('inc/filtres');
293 293
 	foreach (array_merge($_POST, $_GET) as $n => $c) {
294 294
 		if (!in_array($n, ['fichier', 'exec', 'validation_admin']) and !is_array($c)) {
295
-			$suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" .
296
-				entites_html($c) .
295
+			$suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='".
296
+				entites_html($c).
297 297
 				"'  />";
298 298
 		}
299 299
 	}
Please login to merge, or discard this patch.
ecrire/inc/flock.php 3 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 		$contenu = @gzfile($fichier);
123 123
 	}
124 124
 
125
-	return is_array($contenu) ? join('', $contenu) : (string)$contenu;
125
+	return is_array($contenu) ? join('', $contenu) : (string) $contenu;
126 126
 }
127 127
 
128 128
 
@@ -315,9 +315,9 @@  discard block
 block discarded – undo
315 315
  */
316 316
 function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) {
317 317
 	if (substr($fichier, -4) !== '.php') {
318
-		spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
318
+		spip_log('Erreur de programmation: '.$fichier.' doit finir par .php');
319 319
 	}
320
-	$contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
320
+	$contenu = '<'."?php die ('Acces interdit'); ?".">\n".$contenu;
321 321
 
322 322
 	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
323 323
 }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
  * @return bool
331 331
  */
332 332
 function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) {
333
-	$fichier_tmp = $fichier . '.last';
333
+	$fichier_tmp = $fichier.'.last';
334 334
 	if (!ecrire_fichier($fichier_tmp, $contenu, true)) {
335 335
 		return false;
336 336
 	}
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
  */
371 371
 function lire_fichier_securise($fichier, &$contenu, $options = []) {
372 372
 	if ($res = lire_fichier($fichier, $contenu, $options)) {
373
-		$contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n"));
373
+		$contenu = substr($contenu, strlen('<'."?php die ('Acces interdit'); ?".">\n"));
374 374
 	}
375 375
 
376 376
 	return $res;
@@ -540,7 +540,7 @@  discard block
 block discarded – undo
540 540
 				$wait = 0;
541 541
 			}
542 542
 		}
543
-		spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE);
543
+		spip_log('Probleme de configuration opcache.revalidate_freq '.$duree.'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE);
544 544
 		if ($wait) {
545 545
 			sleep($duree + 1);
546 546
 		}
@@ -568,9 +568,9 @@  discard block
 block discarded – undo
568 568
 		if ($item == '.' || $item == '..') {
569 569
 			continue;
570 570
 		}
571
-		if (!supprimer_repertoire($dir . '/' . $item)) {
572
-			@chmod($dir . '/' . $item, 0777);
573
-			if (!supprimer_repertoire($dir . '/' . $item)) {
571
+		if (!supprimer_repertoire($dir.'/'.$item)) {
572
+			@chmod($dir.'/'.$item, 0777);
573
+			if (!supprimer_repertoire($dir.'/'.$item)) {
574 574
 				return false;
575 575
 			}
576 576
 		};
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
 	if (!strlen($subdir)) {
616 616
 		$n = strrpos($base, '/');
617 617
 		if ($n === false) {
618
-			return $nobase ? '' : ($base . '/');
618
+			return $nobase ? '' : ($base.'/');
619 619
 		}
620 620
 		$subdir = substr($base, $n + 1);
621 621
 		$base = substr($base, 0, $n + 1);
@@ -625,14 +625,14 @@  discard block
 block discarded – undo
625 625
 	}
626 626
 
627 627
 	$baseaff = $nobase ? '' : $base;
628
-	if (isset($dirs[$base . $subdir])) {
629
-		return $baseaff . $dirs[$base . $subdir];
628
+	if (isset($dirs[$base.$subdir])) {
629
+		return $baseaff.$dirs[$base.$subdir];
630 630
 	}
631 631
 
632
-	$path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
632
+	$path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
633 633
 
634 634
 	if (file_exists("$path/.ok")) {
635
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
635
+		return $baseaff.($dirs[$base.$subdir] = "$subdir/");
636 636
 	}
637 637
 
638 638
 	@mkdir($path, _SPIP_CHMOD);
@@ -642,7 +642,7 @@  discard block
 block discarded – undo
642 642
 		@touch("$path/.ok");
643 643
 		spip_log("creation $base$subdir/");
644 644
 
645
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
645
+		return $baseaff.($dirs[$base.$subdir] = "$subdir/");
646 646
 	}
647 647
 
648 648
 	// en cas d'echec c'est peut etre tout simplement que le disque est plein :
@@ -652,10 +652,10 @@  discard block
 block discarded – undo
652 652
 		return '';
653 653
 	}
654 654
 	if (!_DIR_RESTREINT) {
655
-		$base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
655
+		$base = preg_replace(',^'._DIR_RACINE.',', '', $base);
656 656
 	}
657 657
 	$base .= $subdir;
658
-	raler_fichier($base . '/.ok');
658
+	raler_fichier($base.'/.ok');
659 659
 }
660 660
 
661 661
 
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 								$maxfiles - $nbfiles,
729 729
 								$recurs
730 730
 							);
731
-							$fichiers = array_merge((array)$beginning, (array)$end);
731
+							$fichiers = array_merge((array) $beginning, (array) $end);
732 732
 							$nbfiles = count($fichiers);
733 733
 						}
734 734
 					}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -341,8 +341,7 @@
 block discarded – undo
341 341
 	) {
342 342
 		if ($use_copy) {
343 343
 			@copy($fichier_tmp, $fichier);
344
-		}
345
-		else {
344
+		} else {
346 345
 			@rename($fichier_tmp, $fichier);
347 346
 		}
348 347
 		// eviter que PHP ne reserve le vieux timestamp
Please login to merge, or discard this patch.
Indentation   +404 added lines, -404 removed lines patch added patch discarded remove patch
@@ -17,12 +17,12 @@  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
 if (!defined('_TEST_FILE_EXISTS')) {
24
-	/** Permettre d'éviter des tests file_exists sur certains hébergeurs */
25
-	define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV['HTTP_HOST']) ? $_ENV['HTTP_HOST'] : ''));
24
+    /** Permettre d'éviter des tests file_exists sur certains hébergeurs */
25
+    define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV['HTTP_HOST']) ? $_ENV['HTTP_HOST'] : ''));
26 26
 }
27 27
 
28 28
 #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille)
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip
31 31
 
32 32
 if (_SPIP_LOCK_MODE == 2) {
33
-	include_spip('inc/nfslock');
33
+    include_spip('inc/nfslock');
34 34
 }
35 35
 
36 36
 $GLOBALS['liste_verrous'] = [];
@@ -53,24 +53,24 @@  discard block
 block discarded – undo
53 53
  *     Ressource sur le fichier ouvert, sinon false.
54 54
  **/
55 55
 function spip_fopen_lock($fichier, $mode, $verrou) {
56
-	if (_SPIP_LOCK_MODE == 1) {
57
-		if ($fl = @fopen($fichier, $mode)) {
58
-			// verrou
59
-			@flock($fl, $verrou);
60
-		}
61
-
62
-		return $fl;
63
-	} elseif (_SPIP_LOCK_MODE == 2) {
64
-		if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
65
-			$GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou];
66
-
67
-			return $fl;
68
-		} else {
69
-			return false;
70
-		}
71
-	}
72
-
73
-	return @fopen($fichier, $mode);
56
+    if (_SPIP_LOCK_MODE == 1) {
57
+        if ($fl = @fopen($fichier, $mode)) {
58
+            // verrou
59
+            @flock($fl, $verrou);
60
+        }
61
+
62
+        return $fl;
63
+    } elseif (_SPIP_LOCK_MODE == 2) {
64
+        if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) {
65
+            $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou];
66
+
67
+            return $fl;
68
+        } else {
69
+            return false;
70
+        }
71
+    }
72
+
73
+    return @fopen($fichier, $mode);
74 74
 }
75 75
 
76 76
 /**
@@ -85,14 +85,14 @@  discard block
 block discarded – undo
85 85
  *     true si succès, false sinon.
86 86
  **/
87 87
 function spip_fclose_unlock($handle) {
88
-	if (_SPIP_LOCK_MODE == 1) {
89
-		@flock($handle, LOCK_UN);
90
-	} elseif (_SPIP_LOCK_MODE == 2) {
91
-		spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
92
-		unset($GLOBALS['liste_verrous'][$handle]);
93
-	}
94
-
95
-	return @fclose($handle);
88
+    if (_SPIP_LOCK_MODE == 1) {
89
+        @flock($handle, LOCK_UN);
90
+    } elseif (_SPIP_LOCK_MODE == 2) {
91
+        spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle]));
92
+        unset($GLOBALS['liste_verrous'][$handle]);
93
+    }
94
+
95
+    return @fclose($handle);
96 96
 }
97 97
 
98 98
 
@@ -106,23 +106,23 @@  discard block
 block discarded – undo
106 106
  *     Contenu du fichier
107 107
  **/
108 108
 function spip_file_get_contents($fichier) {
109
-	if (substr($fichier, -3) != '.gz') {
110
-		if (function_exists('file_get_contents')) {
111
-			// quand on est sous windows on ne sait pas si file_get_contents marche
112
-			// on essaye : si ca retourne du contenu alors c'est bon
113
-			// sinon on fait un file() pour avoir le coeur net
114
-			$contenu = @file_get_contents($fichier);
115
-			if (!$contenu and _OS_SERVEUR == 'windows') {
116
-				$contenu = @file($fichier);
117
-			}
118
-		} else {
119
-			$contenu = @file($fichier);
120
-		}
121
-	} else {
122
-		$contenu = @gzfile($fichier);
123
-	}
124
-
125
-	return is_array($contenu) ? join('', $contenu) : (string)$contenu;
109
+    if (substr($fichier, -3) != '.gz') {
110
+        if (function_exists('file_get_contents')) {
111
+            // quand on est sous windows on ne sait pas si file_get_contents marche
112
+            // on essaye : si ca retourne du contenu alors c'est bon
113
+            // sinon on fait un file() pour avoir le coeur net
114
+            $contenu = @file_get_contents($fichier);
115
+            if (!$contenu and _OS_SERVEUR == 'windows') {
116
+                $contenu = @file($fichier);
117
+            }
118
+        } else {
119
+            $contenu = @file($fichier);
120
+        }
121
+    } else {
122
+        $contenu = @gzfile($fichier);
123
+    }
124
+
125
+    return is_array($contenu) ? join('', $contenu) : (string)$contenu;
126 126
 }
127 127
 
128 128
 
@@ -147,48 +147,48 @@  discard block
 block discarded – undo
147 147
  *     true si l'opération a réussie, false sinon.
148 148
  **/
149 149
 function lire_fichier($fichier, &$contenu, $options = []) {
150
-	$contenu = '';
151
-	// inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
152
-	// economisons donc les acces disque, sauf chez free qui rale pour un rien
153
-	if (_TEST_FILE_EXISTS and !@file_exists($fichier)) {
154
-		return false;
155
-	}
156
-
157
-	#spip_timer('lire_fichier');
158
-
159
-	// pas de @ sur spip_fopen_lock qui est silencieux de toute facon
160
-	if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
161
-		// lire le fichier avant tout
162
-		$contenu = spip_file_get_contents($fichier);
163
-
164
-		// le fichier a-t-il ete supprime par le locker ?
165
-		// on ne verifie que si la tentative de lecture a echoue
166
-		// pour discriminer un contenu vide d'un fichier absent
167
-		// et eviter un acces disque
168
-		if (!$contenu and !@file_exists($fichier)) {
169
-			spip_fclose_unlock($fl);
170
-
171
-			return false;
172
-		}
173
-
174
-		// liberer le verrou
175
-		spip_fclose_unlock($fl);
176
-
177
-		// Verifications
178
-		$ok = true;
179
-		if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') {
180
-			$ok &= (preg_match(",[?]>\n?$,", $contenu));
181
-		}
182
-
183
-		#spip_log("$fread $fichier ".spip_timer('lire_fichier'));
184
-		if (!$ok) {
185
-			spip_log("echec lecture $fichier");
186
-		}
187
-
188
-		return $ok;
189
-	}
190
-
191
-	return false;
150
+    $contenu = '';
151
+    // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres
152
+    // economisons donc les acces disque, sauf chez free qui rale pour un rien
153
+    if (_TEST_FILE_EXISTS and !@file_exists($fichier)) {
154
+        return false;
155
+    }
156
+
157
+    #spip_timer('lire_fichier');
158
+
159
+    // pas de @ sur spip_fopen_lock qui est silencieux de toute facon
160
+    if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) {
161
+        // lire le fichier avant tout
162
+        $contenu = spip_file_get_contents($fichier);
163
+
164
+        // le fichier a-t-il ete supprime par le locker ?
165
+        // on ne verifie que si la tentative de lecture a echoue
166
+        // pour discriminer un contenu vide d'un fichier absent
167
+        // et eviter un acces disque
168
+        if (!$contenu and !@file_exists($fichier)) {
169
+            spip_fclose_unlock($fl);
170
+
171
+            return false;
172
+        }
173
+
174
+        // liberer le verrou
175
+        spip_fclose_unlock($fl);
176
+
177
+        // Verifications
178
+        $ok = true;
179
+        if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') {
180
+            $ok &= (preg_match(",[?]>\n?$,", $contenu));
181
+        }
182
+
183
+        #spip_log("$fread $fichier ".spip_timer('lire_fichier'));
184
+        if (!$ok) {
185
+            spip_log("echec lecture $fichier");
186
+        }
187
+
188
+        return $ok;
189
+    }
190
+
191
+    return false;
192 192
 }
193 193
 
194 194
 
@@ -216,85 +216,85 @@  discard block
 block discarded – undo
216 216
  **/
217 217
 function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) {
218 218
 
219
-	#spip_timer('ecrire_fichier');
220
-
221
-	// verrouiller le fichier destination
222
-	if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
223
-		// ecrire les donnees, compressees le cas echeant
224
-		// (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
225
-		// de le recreer si le locker qui nous precede l'avait supprime...)
226
-		if (substr($fichier, -3) == '.gz') {
227
-			$contenu = gzencode($contenu);
228
-		}
229
-		// si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
230
-		// pour etre sur d'avoir une operation atomique
231
-		// y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
232
-		// sauf sous wintruc ou ca ne marche pas
233
-		$ok = false;
234
-		if ($truncate and _OS_SERVEUR != 'windows') {
235
-			if (!function_exists('creer_uniqid')) {
236
-				include_spip('inc/acces');
237
-			}
238
-			$id = creer_uniqid();
239
-			// on ouvre un pointeur sur un fichier temporaire en ecriture +raz
240
-			if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
241
-				$s = @fputs($fp2, $contenu, $a = strlen($contenu));
242
-				$ok = ($s == $a);
243
-				spip_fclose_unlock($fp2);
244
-				spip_fclose_unlock($fp);
245
-				// unlink direct et pas spip_unlink car on avait deja le verrou
246
-				// a priori pas besoin car rename ecrase la cible
247
-				// @unlink($fichier);
248
-				// le rename aussitot, atomique quand on est pas sous windows
249
-				// au pire on arrive en second en cas de concourance, et le rename echoue
250
-				// --> on a la version de l'autre process qui doit etre identique
251
-				@rename("$fichier.$id", $fichier);
252
-				// precaution en cas d'echec du rename
253
-				if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) {
254
-					@unlink("$fichier.$id");
255
-				}
256
-				if ($ok) {
257
-					$ok = file_exists($fichier);
258
-				}
259
-			} else // echec mais penser a fermer ..
260
-			{
261
-				spip_fclose_unlock($fp);
262
-			}
263
-		}
264
-		// sinon ou si methode precedente a echoueee
265
-		// on se rabat sur la methode ancienne
266
-		if (!$ok) {
267
-			// ici on est en ajout ou sous windows, cas desespere
268
-			if ($truncate) {
269
-				@ftruncate($fp, 0);
270
-			}
271
-			$s = @fputs($fp, $contenu, $a = strlen($contenu));
272
-
273
-			$ok = ($s == $a);
274
-			spip_fclose_unlock($fp);
275
-		}
276
-
277
-		// liberer le verrou et fermer le fichier
278
-		@chmod($fichier, _SPIP_CHMOD & 0666);
279
-		if ($ok) {
280
-			if (strpos($fichier, '.php') !== false) {
281
-				spip_clear_opcode_cache(realpath($fichier));
282
-			}
283
-
284
-			return $ok;
285
-		}
286
-	}
287
-
288
-	if (!$ignorer_echec) {
289
-		include_spip('inc/autoriser');
290
-		if (autoriser('chargerftp')) {
291
-			raler_fichier($fichier);
292
-		}
293
-		spip_unlink($fichier);
294
-	}
295
-	spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
296
-
297
-	return false;
219
+    #spip_timer('ecrire_fichier');
220
+
221
+    // verrouiller le fichier destination
222
+    if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
223
+        // ecrire les donnees, compressees le cas echeant
224
+        // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage
225
+        // de le recreer si le locker qui nous precede l'avait supprime...)
226
+        if (substr($fichier, -3) == '.gz') {
227
+            $contenu = gzencode($contenu);
228
+        }
229
+        // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename
230
+        // pour etre sur d'avoir une operation atomique
231
+        // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt
232
+        // sauf sous wintruc ou ca ne marche pas
233
+        $ok = false;
234
+        if ($truncate and _OS_SERVEUR != 'windows') {
235
+            if (!function_exists('creer_uniqid')) {
236
+                include_spip('inc/acces');
237
+            }
238
+            $id = creer_uniqid();
239
+            // on ouvre un pointeur sur un fichier temporaire en ecriture +raz
240
+            if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) {
241
+                $s = @fputs($fp2, $contenu, $a = strlen($contenu));
242
+                $ok = ($s == $a);
243
+                spip_fclose_unlock($fp2);
244
+                spip_fclose_unlock($fp);
245
+                // unlink direct et pas spip_unlink car on avait deja le verrou
246
+                // a priori pas besoin car rename ecrase la cible
247
+                // @unlink($fichier);
248
+                // le rename aussitot, atomique quand on est pas sous windows
249
+                // au pire on arrive en second en cas de concourance, et le rename echoue
250
+                // --> on a la version de l'autre process qui doit etre identique
251
+                @rename("$fichier.$id", $fichier);
252
+                // precaution en cas d'echec du rename
253
+                if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) {
254
+                    @unlink("$fichier.$id");
255
+                }
256
+                if ($ok) {
257
+                    $ok = file_exists($fichier);
258
+                }
259
+            } else // echec mais penser a fermer ..
260
+            {
261
+                spip_fclose_unlock($fp);
262
+            }
263
+        }
264
+        // sinon ou si methode precedente a echoueee
265
+        // on se rabat sur la methode ancienne
266
+        if (!$ok) {
267
+            // ici on est en ajout ou sous windows, cas desespere
268
+            if ($truncate) {
269
+                @ftruncate($fp, 0);
270
+            }
271
+            $s = @fputs($fp, $contenu, $a = strlen($contenu));
272
+
273
+            $ok = ($s == $a);
274
+            spip_fclose_unlock($fp);
275
+        }
276
+
277
+        // liberer le verrou et fermer le fichier
278
+        @chmod($fichier, _SPIP_CHMOD & 0666);
279
+        if ($ok) {
280
+            if (strpos($fichier, '.php') !== false) {
281
+                spip_clear_opcode_cache(realpath($fichier));
282
+            }
283
+
284
+            return $ok;
285
+        }
286
+    }
287
+
288
+    if (!$ignorer_echec) {
289
+        include_spip('inc/autoriser');
290
+        if (autoriser('chargerftp')) {
291
+            raler_fichier($fichier);
292
+        }
293
+        spip_unlink($fichier);
294
+    }
295
+    spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE);
296
+
297
+    return false;
298 298
 }
299 299
 
300 300
 /**
@@ -314,12 +314,12 @@  discard block
 block discarded – undo
314 314
  *     Écriture avec troncation ?
315 315
  */
316 316
 function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) {
317
-	if (substr($fichier, -4) !== '.php') {
318
-		spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
319
-	}
320
-	$contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
317
+    if (substr($fichier, -4) !== '.php') {
318
+        spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php');
319
+    }
320
+    $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu;
321 321
 
322
-	return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
322
+    return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate);
323 323
 }
324 324
 
325 325
 
@@ -330,25 +330,25 @@  discard block
 block discarded – undo
330 330
  * @return bool
331 331
  */
332 332
 function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) {
333
-	$fichier_tmp = $fichier . '.last';
334
-	if (!ecrire_fichier($fichier_tmp, $contenu, true)) {
335
-		return false;
336
-	}
337
-	if (
338
-		$force
339
-		or !file_exists($fichier)
340
-		or md5_file($fichier) != md5_file($fichier_tmp)
341
-	) {
342
-		if ($use_copy) {
343
-			@copy($fichier_tmp, $fichier);
344
-		}
345
-		else {
346
-			@rename($fichier_tmp, $fichier);
347
-		}
348
-		// eviter que PHP ne reserve le vieux timestamp
349
-		clearstatcache(true, $fichier);
350
-	}
351
-	return true;
333
+    $fichier_tmp = $fichier . '.last';
334
+    if (!ecrire_fichier($fichier_tmp, $contenu, true)) {
335
+        return false;
336
+    }
337
+    if (
338
+        $force
339
+        or !file_exists($fichier)
340
+        or md5_file($fichier) != md5_file($fichier_tmp)
341
+    ) {
342
+        if ($use_copy) {
343
+            @copy($fichier_tmp, $fichier);
344
+        }
345
+        else {
346
+            @rename($fichier_tmp, $fichier);
347
+        }
348
+        // eviter que PHP ne reserve le vieux timestamp
349
+        clearstatcache(true, $fichier);
350
+    }
351
+    return true;
352 352
 }
353 353
 
354 354
 
@@ -369,11 +369,11 @@  discard block
 block discarded – undo
369 369
  *     true si l'opération a réussie, false sinon.
370 370
  */
371 371
 function lire_fichier_securise($fichier, &$contenu, $options = []) {
372
-	if ($res = lire_fichier($fichier, $contenu, $options)) {
373
-		$contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n"));
374
-	}
372
+    if ($res = lire_fichier($fichier, $contenu, $options)) {
373
+        $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n"));
374
+    }
375 375
 
376
-	return $res;
376
+    return $res;
377 377
 }
378 378
 
379 379
 /**
@@ -388,22 +388,22 @@  discard block
 block discarded – undo
388 388
  *     Chemin du fichier
389 389
  **/
390 390
 function raler_fichier($fichier) {
391
-	include_spip('inc/minipres');
392
-	$dir = dirname($fichier);
393
-	http_response_code(401);
394
-	echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
395
-		. _T('texte_inc_meta_1', ['fichier' => $fichier])
396
-		. " <a href='"
397
-		. generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
398
-		. "'>"
399
-		. _T('texte_inc_meta_2')
400
-		. '</a> '
401
-		. _T(
402
-			'texte_inc_meta_3',
403
-			['repertoire' => joli_repertoire($dir)]
404
-		)
405
-		. "</h4>\n");
406
-	exit;
391
+    include_spip('inc/minipres');
392
+    $dir = dirname($fichier);
393
+    http_response_code(401);
394
+    echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>"
395
+        . _T('texte_inc_meta_1', ['fichier' => $fichier])
396
+        . " <a href='"
397
+        . generer_url_ecrire('install', "etape=chmod&test_dir=$dir")
398
+        . "'>"
399
+        . _T('texte_inc_meta_2')
400
+        . '</a> '
401
+        . _T(
402
+            'texte_inc_meta_3',
403
+            ['repertoire' => joli_repertoire($dir)]
404
+        )
405
+        . "</h4>\n");
406
+    exit;
407 407
 }
408 408
 
409 409
 
@@ -418,14 +418,14 @@  discard block
 block discarded – undo
418 418
  *     - true si récent, false sinon
419 419
  */
420 420
 function jeune_fichier($fichier, $n) {
421
-	if (!file_exists($fichier)) {
422
-		return false;
423
-	}
424
-	if (!$c = @filemtime($fichier)) {
425
-		return false;
426
-	}
427
-
428
-	return (time() - $n <= $c);
421
+    if (!file_exists($fichier)) {
422
+        return false;
423
+    }
424
+    if (!$c = @filemtime($fichier)) {
425
+        return false;
426
+    }
427
+
428
+    return (time() - $n <= $c);
429 429
 }
430 430
 
431 431
 /**
@@ -440,22 +440,22 @@  discard block
 block discarded – undo
440 440
  *     - false si on n'arrive pas poser le verrou ou si la suppression échoue
441 441
  */
442 442
 function supprimer_fichier($fichier, $lock = true) {
443
-	if (!@file_exists($fichier)) {
444
-		return true;
445
-	}
446
-
447
-	if ($lock) {
448
-		// verrouiller le fichier destination
449
-		if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
450
-			return false;
451
-		}
452
-
453
-		// liberer le verrou
454
-		spip_fclose_unlock($fp);
455
-	}
456
-
457
-	// supprimer
458
-	return @unlink($fichier);
443
+    if (!@file_exists($fichier)) {
444
+        return true;
445
+    }
446
+
447
+    if ($lock) {
448
+        // verrouiller le fichier destination
449
+        if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) {
450
+            return false;
451
+        }
452
+
453
+        // liberer le verrou
454
+        spip_fclose_unlock($fp);
455
+    }
456
+
457
+    // supprimer
458
+    return @unlink($fichier);
459 459
 }
460 460
 
461 461
 /**
@@ -465,12 +465,12 @@  discard block
 block discarded – undo
465 465
  *     Chemin du fichier
466 466
  */
467 467
 function spip_unlink($f) {
468
-	if (!is_dir($f)) {
469
-		supprimer_fichier($f, false);
470
-	} else {
471
-		@unlink("$f/.ok");
472
-		@rmdir($f);
473
-	}
468
+    if (!is_dir($f)) {
469
+        supprimer_fichier($f, false);
470
+    } else {
471
+        @unlink("$f/.ok");
472
+        @rmdir($f);
473
+    }
474 474
 }
475 475
 
476 476
 /**
@@ -484,26 +484,26 @@  discard block
 block discarded – undo
484 484
  *   The absolute path of the PHP file to invalidate.
485 485
  */
486 486
 function spip_clear_opcode_cache($filepath) {
487
-	clearstatcache(true, $filepath);
488
-
489
-	// Zend OPcache
490
-	if (function_exists('opcache_invalidate')) {
491
-		$invalidate = @opcache_invalidate($filepath, true);
492
-		// si l'invalidation a echoue lever un flag
493
-		if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
494
-			define('_spip_attend_invalidation_opcode_cache', true);
495
-		}
496
-	} elseif (!defined('_spip_attend_invalidation_opcode_cache')) {
497
-		// n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate)
498
-		define('_spip_attend_invalidation_opcode_cache', true);
499
-	}
500
-	// APC.
501
-	if (function_exists('apc_delete_file')) {
502
-		// apc_delete_file() throws a PHP warning in case the specified file was
503
-		// not compiled yet.
504
-		// @see http://php.net/apc-delete-file
505
-		@apc_delete_file($filepath);
506
-	}
487
+    clearstatcache(true, $filepath);
488
+
489
+    // Zend OPcache
490
+    if (function_exists('opcache_invalidate')) {
491
+        $invalidate = @opcache_invalidate($filepath, true);
492
+        // si l'invalidation a echoue lever un flag
493
+        if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) {
494
+            define('_spip_attend_invalidation_opcode_cache', true);
495
+        }
496
+    } elseif (!defined('_spip_attend_invalidation_opcode_cache')) {
497
+        // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate)
498
+        define('_spip_attend_invalidation_opcode_cache', true);
499
+    }
500
+    // APC.
501
+    if (function_exists('apc_delete_file')) {
502
+        // apc_delete_file() throws a PHP warning in case the specified file was
503
+        // not compiled yet.
504
+        // @see http://php.net/apc-delete-file
505
+        @apc_delete_file($filepath);
506
+    }
507 507
 }
508 508
 
509 509
 /**
@@ -526,25 +526,25 @@  discard block
 block discarded – undo
526 526
  *
527 527
  */
528 528
 function spip_attend_invalidation_opcode_cache($timestamp = null) {
529
-	if (
530
-		function_exists('opcache_get_configuration')
531
-		and @ini_get('opcache.enable')
532
-		and @ini_get('opcache.validate_timestamps')
533
-		and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2)
534
-		and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
535
-	) {
536
-		$wait = $duree + 1;
537
-		if ($timestamp) {
538
-			$wait -= (time() - $timestamp);
539
-			if ($wait < 0) {
540
-				$wait = 0;
541
-			}
542
-		}
543
-		spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE);
544
-		if ($wait) {
545
-			sleep($duree + 1);
546
-		}
547
-	}
529
+    if (
530
+        function_exists('opcache_get_configuration')
531
+        and @ini_get('opcache.enable')
532
+        and @ini_get('opcache.validate_timestamps')
533
+        and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2)
534
+        and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees
535
+    ) {
536
+        $wait = $duree + 1;
537
+        if ($timestamp) {
538
+            $wait -= (time() - $timestamp);
539
+            if ($wait < 0) {
540
+                $wait = 0;
541
+            }
542
+        }
543
+        spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE);
544
+        if ($wait) {
545
+            sleep($duree + 1);
546
+        }
547
+    }
548 548
 }
549 549
 
550 550
 
@@ -557,26 +557,26 @@  discard block
 block discarded – undo
557 557
  * @return bool Suppression reussie.
558 558
  */
559 559
 function supprimer_repertoire($dir) {
560
-	if (!file_exists($dir)) {
561
-		return true;
562
-	}
563
-	if (!is_dir($dir) || is_link($dir)) {
564
-		return @unlink($dir);
565
-	}
566
-
567
-	foreach (scandir($dir) as $item) {
568
-		if ($item == '.' || $item == '..') {
569
-			continue;
570
-		}
571
-		if (!supprimer_repertoire($dir . '/' . $item)) {
572
-			@chmod($dir . '/' . $item, 0777);
573
-			if (!supprimer_repertoire($dir . '/' . $item)) {
574
-				return false;
575
-			}
576
-		};
577
-	}
578
-
579
-	return @rmdir($dir);
560
+    if (!file_exists($dir)) {
561
+        return true;
562
+    }
563
+    if (!is_dir($dir) || is_link($dir)) {
564
+        return @unlink($dir);
565
+    }
566
+
567
+    foreach (scandir($dir) as $item) {
568
+        if ($item == '.' || $item == '..') {
569
+            continue;
570
+        }
571
+        if (!supprimer_repertoire($dir . '/' . $item)) {
572
+            @chmod($dir . '/' . $item, 0777);
573
+            if (!supprimer_repertoire($dir . '/' . $item)) {
574
+                return false;
575
+            }
576
+        };
577
+    }
578
+
579
+    return @rmdir($dir);
580 580
 }
581 581
 
582 582
 
@@ -605,57 +605,57 @@  discard block
 block discarded – undo
605 605
  *     Chemin du répertoire créé.
606 606
  **/
607 607
 function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) {
608
-	static $dirs = [];
609
-
610
-	$base = str_replace('//', '/', $base);
611
-
612
-	# suppr le dernier caractere si c'est un /
613
-	$base = rtrim($base, '/');
614
-
615
-	if (!strlen($subdir)) {
616
-		$n = strrpos($base, '/');
617
-		if ($n === false) {
618
-			return $nobase ? '' : ($base . '/');
619
-		}
620
-		$subdir = substr($base, $n + 1);
621
-		$base = substr($base, 0, $n + 1);
622
-	} else {
623
-		$base .= '/';
624
-		$subdir = str_replace('/', '', $subdir);
625
-	}
626
-
627
-	$baseaff = $nobase ? '' : $base;
628
-	if (isset($dirs[$base . $subdir])) {
629
-		return $baseaff . $dirs[$base . $subdir];
630
-	}
631
-
632
-	$path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
633
-
634
-	if (file_exists("$path/.ok")) {
635
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
636
-	}
637
-
638
-	@mkdir($path, _SPIP_CHMOD);
639
-	@chmod($path, _SPIP_CHMOD);
640
-
641
-	if (is_dir($path) && is_writable($path)) {
642
-		@touch("$path/.ok");
643
-		spip_log("creation $base$subdir/");
644
-
645
-		return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
646
-	}
647
-
648
-	// en cas d'echec c'est peut etre tout simplement que le disque est plein :
649
-	// l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
650
-	spip_log("echec creation $base${subdir}");
651
-	if ($tantpis) {
652
-		return '';
653
-	}
654
-	if (!_DIR_RESTREINT) {
655
-		$base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
656
-	}
657
-	$base .= $subdir;
658
-	raler_fichier($base . '/.ok');
608
+    static $dirs = [];
609
+
610
+    $base = str_replace('//', '/', $base);
611
+
612
+    # suppr le dernier caractere si c'est un /
613
+    $base = rtrim($base, '/');
614
+
615
+    if (!strlen($subdir)) {
616
+        $n = strrpos($base, '/');
617
+        if ($n === false) {
618
+            return $nobase ? '' : ($base . '/');
619
+        }
620
+        $subdir = substr($base, $n + 1);
621
+        $base = substr($base, 0, $n + 1);
622
+    } else {
623
+        $base .= '/';
624
+        $subdir = str_replace('/', '', $subdir);
625
+    }
626
+
627
+    $baseaff = $nobase ? '' : $base;
628
+    if (isset($dirs[$base . $subdir])) {
629
+        return $baseaff . $dirs[$base . $subdir];
630
+    }
631
+
632
+    $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf'
633
+
634
+    if (file_exists("$path/.ok")) {
635
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
636
+    }
637
+
638
+    @mkdir($path, _SPIP_CHMOD);
639
+    @chmod($path, _SPIP_CHMOD);
640
+
641
+    if (is_dir($path) && is_writable($path)) {
642
+        @touch("$path/.ok");
643
+        spip_log("creation $base$subdir/");
644
+
645
+        return $baseaff . ($dirs[$base . $subdir] = "$subdir/");
646
+    }
647
+
648
+    // en cas d'echec c'est peut etre tout simplement que le disque est plein :
649
+    // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu
650
+    spip_log("echec creation $base${subdir}");
651
+    if ($tantpis) {
652
+        return '';
653
+    }
654
+    if (!_DIR_RESTREINT) {
655
+        $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base);
656
+    }
657
+    $base .= $subdir;
658
+    raler_fichier($base . '/.ok');
659 659
 }
660 660
 
661 661
 
@@ -688,56 +688,56 @@  discard block
 block discarded – undo
688 688
  *     Chemins des fichiers trouvés.
689 689
  **/
690 690
 function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) {
691
-	$nbfiles = 0;
692
-	if ($pattern == -1) {
693
-		$pattern = "^$dir";
694
-	}
695
-	$fichiers = [];
696
-	// revenir au repertoire racine si on a recu dossier/truc
697
-	// pour regarder dossier/truc/ ne pas oublier le / final
698
-	$dir = preg_replace(',/[^/]*$,', '', $dir);
699
-	if ($dir == '') {
700
-		$dir = '.';
701
-	}
702
-
703
-	if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
704
-		while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
705
-			if (
706
-				$f[0] != '.' # ignorer . .. .svn etc
707
-				and $f != 'CVS'
708
-				and $f != 'remove.txt'
709
-				and is_readable($f = "$dir/$f")
710
-			) {
711
-				if (is_file($f)) {
712
-					if (preg_match(";$pattern;iS", $f)) {
713
-						$fichiers[] = $f;
714
-						$nbfiles++;
715
-					}
716
-				} else {
717
-					if (is_dir($f) and is_array($recurs)) {
718
-						$rp = @realpath($f);
719
-						if (!is_string($rp) or !strlen($rp)) {
720
-							$rp = $f;
721
-						} # realpath n'est peut etre pas autorise
722
-						if (!isset($recurs[$rp])) {
723
-							$recurs[$rp] = true;
724
-							$beginning = $fichiers;
725
-							$end = preg_files(
726
-								"$f/",
727
-								$pattern,
728
-								$maxfiles - $nbfiles,
729
-								$recurs
730
-							);
731
-							$fichiers = array_merge((array)$beginning, (array)$end);
732
-							$nbfiles = count($fichiers);
733
-						}
734
-					}
735
-				}
736
-			}
737
-		}
738
-		closedir($d);
739
-	}
740
-	sort($fichiers);
741
-
742
-	return $fichiers;
691
+    $nbfiles = 0;
692
+    if ($pattern == -1) {
693
+        $pattern = "^$dir";
694
+    }
695
+    $fichiers = [];
696
+    // revenir au repertoire racine si on a recu dossier/truc
697
+    // pour regarder dossier/truc/ ne pas oublier le / final
698
+    $dir = preg_replace(',/[^/]*$,', '', $dir);
699
+    if ($dir == '') {
700
+        $dir = '.';
701
+    }
702
+
703
+    if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) {
704
+        while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) {
705
+            if (
706
+                $f[0] != '.' # ignorer . .. .svn etc
707
+                and $f != 'CVS'
708
+                and $f != 'remove.txt'
709
+                and is_readable($f = "$dir/$f")
710
+            ) {
711
+                if (is_file($f)) {
712
+                    if (preg_match(";$pattern;iS", $f)) {
713
+                        $fichiers[] = $f;
714
+                        $nbfiles++;
715
+                    }
716
+                } else {
717
+                    if (is_dir($f) and is_array($recurs)) {
718
+                        $rp = @realpath($f);
719
+                        if (!is_string($rp) or !strlen($rp)) {
720
+                            $rp = $f;
721
+                        } # realpath n'est peut etre pas autorise
722
+                        if (!isset($recurs[$rp])) {
723
+                            $recurs[$rp] = true;
724
+                            $beginning = $fichiers;
725
+                            $end = preg_files(
726
+                                "$f/",
727
+                                $pattern,
728
+                                $maxfiles - $nbfiles,
729
+                                $recurs
730
+                            );
731
+                            $fichiers = array_merge((array)$beginning, (array)$end);
732
+                            $nbfiles = count($fichiers);
733
+                        }
734
+                    }
735
+                }
736
+            }
737
+        }
738
+        closedir($d);
739
+    }
740
+    sort($fichiers);
741
+
742
+    return $fichiers;
743 743
 }
Please login to merge, or discard this patch.
ecrire/inc/surligne.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Surligne
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 /**
@@ -35,43 +35,43 @@  discard block
 block discarded – undo
35 35
  *     Page HTML
36 36
  **/
37 37
 function surligner_mots($page, $surcharge_surligne = '') {
38
-	$surlignejs_engines = [
39
-		[
40
-			',' . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . ',i',
41
-			',recherche=([^&]+),i'
42
-		], //SPIP
43
-		[',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google
44
-		[',^http://(www\.)?search\.yahoo\.,i', ',p=([^&]+),i'], // Yahoo
45
-		[',^http://(www\.)?search\.msn\.,i', ',q=([^&]+),i'], // MSN
46
-		[',^http://(www\.)?search\.live\.,i', ',query=([^&]+),i'], // MSN Live
47
-		[',^http://(www\.)?search\.aol\.,i', ',userQuery=([^&]+),i'], // AOL
48
-		[',^http://(www\.)?ask\.com,i', ',q=([^&]+),i'], // Ask.com
49
-		[',^http://(www\.)?altavista\.,i', ',q=([^&]+),i'], // AltaVista
50
-		[',^http://(www\.)?feedster\.,i', ',q=([^&]+),i'], // Feedster
51
-		[',^http://(www\.)?search\.lycos\.,i', ',q=([^&]+),i'], // Lycos
52
-		[',^http://(www\.)?alltheweb\.,i', ',q=([^&]+),i'], // AllTheWeb
53
-		[',^http://(www\.)?technorati\.com,i', ',([^\?\/]+)(?:\?.*)$,i'], // Technorati
54
-	];
38
+    $surlignejs_engines = [
39
+        [
40
+            ',' . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . ',i',
41
+            ',recherche=([^&]+),i'
42
+        ], //SPIP
43
+        [',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google
44
+        [',^http://(www\.)?search\.yahoo\.,i', ',p=([^&]+),i'], // Yahoo
45
+        [',^http://(www\.)?search\.msn\.,i', ',q=([^&]+),i'], // MSN
46
+        [',^http://(www\.)?search\.live\.,i', ',query=([^&]+),i'], // MSN Live
47
+        [',^http://(www\.)?search\.aol\.,i', ',userQuery=([^&]+),i'], // AOL
48
+        [',^http://(www\.)?ask\.com,i', ',q=([^&]+),i'], // Ask.com
49
+        [',^http://(www\.)?altavista\.,i', ',q=([^&]+),i'], // AltaVista
50
+        [',^http://(www\.)?feedster\.,i', ',q=([^&]+),i'], // Feedster
51
+        [',^http://(www\.)?search\.lycos\.,i', ',q=([^&]+),i'], // Lycos
52
+        [',^http://(www\.)?alltheweb\.,i', ',q=([^&]+),i'], // AllTheWeb
53
+        [',^http://(www\.)?technorati\.com,i', ',([^\?\/]+)(?:\?.*)$,i'], // Technorati
54
+    ];
55 55
 
56 56
 
57
-	$ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
58
-	//avoid a js injection
59
-	if ($surcharge_surligne) {
60
-		$surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", '$1\\\$2', $surcharge_surligne);
61
-		$surcharge_surligne = str_replace('\\', '\\\\', $surcharge_surligne);
62
-		if ($GLOBALS['meta']['charset'] == 'utf-8') {
63
-			include_spip('inc/charsets');
64
-			if (!is_utf8($surcharge_surligne)) {
65
-				$surcharge_surligne = utf8_encode($surcharge_surligne);
66
-			}
67
-		}
68
-		$surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
69
-	}
70
-	foreach ($surlignejs_engines as $engine) {
71
-		if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) {
72
-			//good referrer found or var_recherche is not null
73
-			include_spip('inc/filtres');
74
-			$script = "
57
+    $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null;
58
+    //avoid a js injection
59
+    if ($surcharge_surligne) {
60
+        $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", '$1\\\$2', $surcharge_surligne);
61
+        $surcharge_surligne = str_replace('\\', '\\\\', $surcharge_surligne);
62
+        if ($GLOBALS['meta']['charset'] == 'utf-8') {
63
+            include_spip('inc/charsets');
64
+            if (!is_utf8($surcharge_surligne)) {
65
+                $surcharge_surligne = utf8_encode($surcharge_surligne);
66
+            }
67
+        }
68
+        $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final
69
+    }
70
+    foreach ($surlignejs_engines as $engine) {
71
+        if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) {
72
+            //good referrer found or var_recherche is not null
73
+            include_spip('inc/filtres');
74
+            $script = "
75 75
       <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js')) . "'></script>
76 76
       <script type='text/javascript'>/*<![CDATA[*/
77 77
       if (window.jQuery)
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
             engines:[/^" . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . "/i,/recherche=([^&]+)/i],
85 85
             highlight:'.surlignable',
86 86
             nohighlight:'.pas_surlignable'" .
87
-				($surcharge_surligne ? ",
87
+                ($surcharge_surligne ? ",
88 88
             keys:'$surcharge_surligne'" : '') . ',
89 89
             min_length: 3
90 90
           })
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
       })(jQuery);
93 93
       /*]]>*/</script>
94 94
       ';
95
-			// on l'insere juste avant </head>, sinon tout en bas
96
-			if (is_null($l = strpos($page, '</head>'))) {
97
-				$l = strlen($page);
98
-			}
99
-			$page = substr_replace($page, $script, $l, 0);
100
-			break;
101
-		}
102
-	}
95
+            // on l'insere juste avant </head>, sinon tout en bas
96
+            if (is_null($l = strpos($page, '</head>'))) {
97
+                $l = strlen($page);
98
+            }
99
+            $page = substr_replace($page, $script, $l, 0);
100
+            break;
101
+        }
102
+    }
103 103
 
104
-	return $page;
104
+    return $page;
105 105
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 function surligner_mots($page, $surcharge_surligne = '') {
38 38
 	$surlignejs_engines = [
39 39
 		[
40
-			',' . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . ',i',
40
+			','.str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']).',i',
41 41
 			',recherche=([^&]+),i'
42 42
 		], //SPIP
43 43
 		[',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google
@@ -72,20 +72,20 @@  discard block
 block discarded – undo
72 72
 			//good referrer found or var_recherche is not null
73 73
 			include_spip('inc/filtres');
74 74
 			$script = "
75
-      <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js')) . "'></script>
75
+      <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js'))."'></script>
76 76
       <script type='text/javascript'>/*<![CDATA[*/
77 77
       if (window.jQuery)
78 78
         (function(\$){\$(function(){
79 79
           \$(document).SearchHighlight({
80
-            tag_name:'" . (html5_permis() ? 'mark' : 'span') . "',
80
+            tag_name:'" . (html5_permis() ? 'mark' : 'span')."',
81 81
             style_name:'spip_surligne',
82 82
             exact:'whole',
83 83
             style_name_suffix:false,
84
-            engines:[/^" . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . "/i,/recherche=([^&]+)/i],
84
+            engines:[/^" . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site'])."/i,/recherche=([^&]+)/i],
85 85
             highlight:'.surlignable',
86 86
             nohighlight:'.pas_surlignable'" .
87 87
 				($surcharge_surligne ? ",
88
-            keys:'$surcharge_surligne'" : '') . ',
88
+            keys:'$surcharge_surligne'" : '').',
89 89
             min_length: 3
90 90
           })
91 91
         });
Please login to merge, or discard this patch.
ecrire/inc/documents.php 2 patches
Indentation   +193 added lines, -193 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
 /**
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
  * @return string
31 31
  */
32 32
 function set_spip_doc($fichier) {
33
-	if (strpos($fichier, _DIR_IMG) === 0) {
34
-		return substr($fichier, strlen(_DIR_IMG));
35
-	} else {
36
-		return $fichier;
37
-	} // ex: fichier distant
33
+    if (strpos($fichier, _DIR_IMG) === 0) {
34
+        return substr($fichier, strlen(_DIR_IMG));
35
+    } else {
36
+        return $fichier;
37
+    } // ex: fichier distant
38 38
 }
39 39
 
40 40
 /**
@@ -46,24 +46,24 @@  discard block
 block discarded – undo
46 46
  * @return bool|string
47 47
  */
48 48
 function get_spip_doc($fichier) {
49
-	// fichier distant
50
-	if (tester_url_absolue($fichier)) {
51
-		return $fichier;
52
-	}
53
-
54
-	// gestion d'erreurs, fichier=''
55
-	if (!strlen($fichier)) {
56
-		return false;
57
-	}
58
-
59
-	$fichier = (
60
-		strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0
61
-	)
62
-		? _DIR_IMG . $fichier
63
-		: $fichier;
64
-
65
-	// fichier normal
66
-	return $fichier;
49
+    // fichier distant
50
+    if (tester_url_absolue($fichier)) {
51
+        return $fichier;
52
+    }
53
+
54
+    // gestion d'erreurs, fichier=''
55
+    if (!strlen($fichier)) {
56
+        return false;
57
+    }
58
+
59
+    $fichier = (
60
+        strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0
61
+    )
62
+        ? _DIR_IMG . $fichier
63
+        : $fichier;
64
+
65
+    // fichier normal
66
+    return $fichier;
67 67
 }
68 68
 
69 69
 /**
@@ -77,26 +77,26 @@  discard block
 block discarded – undo
77 77
  * @return string
78 78
  */
79 79
 function creer_repertoire_documents($ext) {
80
-	$rep = sous_repertoire(_DIR_IMG, $ext);
81
-
82
-	if (!$ext or !$rep) {
83
-		spip_log("creer_repertoire_documents '$rep' interdit");
84
-		exit;
85
-	}
86
-
87
-	// Cette variable de configuration peut etre posee par un plugin
88
-	// par exemple acces_restreint
89
-	// sauf pour logo/ utilise pour stocker les logoon et logooff
90
-	if (
91
-		isset($GLOBALS['meta']['creer_htaccess'])
92
-		and $GLOBALS['meta']['creer_htaccess'] == 'oui'
93
-		and $ext !== 'logo'
94
-	) {
95
-		include_spip('inc/acces');
96
-		verifier_htaccess($rep);
97
-	}
98
-
99
-	return $rep;
80
+    $rep = sous_repertoire(_DIR_IMG, $ext);
81
+
82
+    if (!$ext or !$rep) {
83
+        spip_log("creer_repertoire_documents '$rep' interdit");
84
+        exit;
85
+    }
86
+
87
+    // Cette variable de configuration peut etre posee par un plugin
88
+    // par exemple acces_restreint
89
+    // sauf pour logo/ utilise pour stocker les logoon et logooff
90
+    if (
91
+        isset($GLOBALS['meta']['creer_htaccess'])
92
+        and $GLOBALS['meta']['creer_htaccess'] == 'oui'
93
+        and $ext !== 'logo'
94
+    ) {
95
+        include_spip('inc/acces');
96
+        verifier_htaccess($rep);
97
+    }
98
+
99
+    return $rep;
100 100
 }
101 101
 
102 102
 /**
@@ -105,22 +105,22 @@  discard block
 block discarded – undo
105 105
  * @param string $nom
106 106
  */
107 107
 function effacer_repertoire_temporaire($nom) {
108
-	if ($d = opendir($nom)) {
109
-		while (($f = readdir($d)) !== false) {
110
-			if (is_file("$nom/$f")) {
111
-				spip_unlink("$nom/$f");
112
-			} else {
113
-				if (
114
-					$f <> '.' and $f <> '..'
115
-					and is_dir("$nom/$f")
116
-				) {
117
-					effacer_repertoire_temporaire("$nom/$f");
118
-				}
119
-			}
120
-		}
121
-	}
122
-	closedir($d);
123
-	@rmdir($nom);
108
+    if ($d = opendir($nom)) {
109
+        while (($f = readdir($d)) !== false) {
110
+            if (is_file("$nom/$f")) {
111
+                spip_unlink("$nom/$f");
112
+            } else {
113
+                if (
114
+                    $f <> '.' and $f <> '..'
115
+                    and is_dir("$nom/$f")
116
+                ) {
117
+                    effacer_repertoire_temporaire("$nom/$f");
118
+                }
119
+            }
120
+        }
121
+    }
122
+    closedir($d);
123
+    @rmdir($nom);
124 124
 }
125 125
 
126 126
 //
@@ -137,34 +137,34 @@  discard block
 block discarded – undo
137 137
  */
138 138
 function copier_document($ext, $orig, $source, $subdir = null) {
139 139
 
140
-	$orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
141
-	$dir = creer_repertoire_documents($subdir ? $subdir : $ext);
142
-	$dest = preg_replace(
143
-		'/[^.=\w-]+/',
144
-		'_',
145
-		translitteration(preg_replace(
146
-			'/\.([^.]+)$/',
147
-			'',
148
-			preg_replace('/<[^>]*>/', '', basename($orig))
149
-		))
150
-	);
151
-
152
-	// ne pas accepter de noms de la forme -r90.jpg qui sont reserves
153
-	// pour les images transformees par rotation (action/documenter)
154
-	$dest = preg_replace(',-r(90|180|270)$,', '', $dest);
155
-
156
-	// Si le document "source" est deja au bon endroit, ne rien faire
157
-	if ($source == ($dir . $dest . '.' . $ext)) {
158
-		return $source;
159
-	}
160
-
161
-	// sinon tourner jusqu'a trouver un numero correct
162
-	$n = 0;
163
-	while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
164
-		;
165
-	}
166
-
167
-	return deplacer_fichier_upload($source, $newFile);
140
+    $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
141
+    $dir = creer_repertoire_documents($subdir ? $subdir : $ext);
142
+    $dest = preg_replace(
143
+        '/[^.=\w-]+/',
144
+        '_',
145
+        translitteration(preg_replace(
146
+            '/\.([^.]+)$/',
147
+            '',
148
+            preg_replace('/<[^>]*>/', '', basename($orig))
149
+        ))
150
+    );
151
+
152
+    // ne pas accepter de noms de la forme -r90.jpg qui sont reserves
153
+    // pour les images transformees par rotation (action/documenter)
154
+    $dest = preg_replace(',-r(90|180|270)$,', '', $dest);
155
+
156
+    // Si le document "source" est deja au bon endroit, ne rien faire
157
+    if ($source == ($dir . $dest . '.' . $ext)) {
158
+        return $source;
159
+    }
160
+
161
+    // sinon tourner jusqu'a trouver un numero correct
162
+    $n = 0;
163
+    while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
164
+        ;
165
+    }
166
+
167
+    return deplacer_fichier_upload($source, $newFile);
168 168
 }
169 169
 
170 170
 /**
@@ -179,28 +179,28 @@  discard block
 block discarded – undo
179 179
  * @return bool|string
180 180
  */
181 181
 function determine_upload($type = '') {
182
-	if (!function_exists('autoriser')) {
183
-		include_spip('inc/autoriser');
184
-	}
185
-
186
-	if (
187
-		!autoriser('chargerftp')
188
-		or $type == 'logos'
189
-	) { # on ne le permet pas pour les logos
190
-	return false;
191
-	}
192
-
193
-	$repertoire = _DIR_TRANSFERT;
194
-	if (!@is_dir($repertoire)) {
195
-		$repertoire = str_replace(_DIR_TMP, '', $repertoire);
196
-		$repertoire = sous_repertoire(_DIR_TMP, $repertoire);
197
-	}
198
-
199
-	if (!$GLOBALS['visiteur_session']['restreint']) {
200
-		return $repertoire;
201
-	} else {
202
-		return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
203
-	}
182
+    if (!function_exists('autoriser')) {
183
+        include_spip('inc/autoriser');
184
+    }
185
+
186
+    if (
187
+        !autoriser('chargerftp')
188
+        or $type == 'logos'
189
+    ) { # on ne le permet pas pour les logos
190
+    return false;
191
+    }
192
+
193
+    $repertoire = _DIR_TRANSFERT;
194
+    if (!@is_dir($repertoire)) {
195
+        $repertoire = str_replace(_DIR_TMP, '', $repertoire);
196
+        $repertoire = sous_repertoire(_DIR_TMP, $repertoire);
197
+    }
198
+
199
+    if (!$GLOBALS['visiteur_session']['restreint']) {
200
+        return $repertoire;
201
+    } else {
202
+        return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
203
+    }
204 204
 }
205 205
 
206 206
 /**
@@ -219,35 +219,35 @@  discard block
 block discarded – undo
219 219
  * @return bool|mixed|string
220 220
  */
221 221
 function deplacer_fichier_upload($source, $dest, $move = false) {
222
-	// Securite
223
-	if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) {
224
-		$dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
225
-	} else {
226
-		$dest = preg_replace(',\.\.+,', '.', $dest);
227
-	}
228
-
229
-	if ($move) {
230
-		$ok = @rename($source, $dest);
231
-	} else {
232
-		$ok = @copy($source, $dest);
233
-	}
234
-	if (!$ok) {
235
-		$ok = @move_uploaded_file($source, $dest);
236
-	}
237
-	if ($ok) {
238
-		@chmod($dest, _SPIP_CHMOD & ~0111);
239
-	} else {
240
-		$f = @fopen($dest, 'w');
241
-		if ($f) {
242
-			fclose($f);
243
-		} else {
244
-			include_spip('inc/flock');
245
-			raler_fichier($dest);
246
-		}
247
-		spip_unlink($dest);
248
-	}
249
-
250
-	return $ok ? $dest : false;
222
+    // Securite
223
+    if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) {
224
+        $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
225
+    } else {
226
+        $dest = preg_replace(',\.\.+,', '.', $dest);
227
+    }
228
+
229
+    if ($move) {
230
+        $ok = @rename($source, $dest);
231
+    } else {
232
+        $ok = @copy($source, $dest);
233
+    }
234
+    if (!$ok) {
235
+        $ok = @move_uploaded_file($source, $dest);
236
+    }
237
+    if ($ok) {
238
+        @chmod($dest, _SPIP_CHMOD & ~0111);
239
+    } else {
240
+        $f = @fopen($dest, 'w');
241
+        if ($f) {
242
+            fclose($f);
243
+        } else {
244
+            include_spip('inc/flock');
245
+            raler_fichier($dest);
246
+        }
247
+        spip_unlink($dest);
248
+    }
249
+
250
+    return $ok ? $dest : false;
251 251
 }
252 252
 
253 253
 
@@ -271,58 +271,58 @@  discard block
 block discarded – undo
271 271
  */
272 272
 function check_upload_error($error, $msg = '', $return = false) {
273 273
 
274
-	if (!$error) {
275
-		return false;
276
-	}
277
-
278
-	spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
279
-
280
-	switch ($error) {
281
-		case 4: /* UPLOAD_ERR_NO_FILE */
282
-			return true;
283
-
284
-		# on peut affiner les differents messages d'erreur
285
-		case 1: /* UPLOAD_ERR_INI_SIZE */
286
-			$msg = _T(
287
-				'upload_limit',
288
-				['max' => ini_get('upload_max_filesize')]
289
-			);
290
-			break;
291
-		case 2: /* UPLOAD_ERR_FORM_SIZE */
292
-			$msg = _T(
293
-				'upload_limit',
294
-				['max' => ini_get('upload_max_filesize')]
295
-			);
296
-			break;
297
-		case 3: /* UPLOAD_ERR_PARTIAL  */
298
-			$msg = _T(
299
-				'upload_limit',
300
-				['max' => ini_get('upload_max_filesize')]
301
-			);
302
-			break;
303
-
304
-		default: /* autre */
305
-			if (!$msg) {
306
-				$msg = _T('pass_erreur') . ' ' . $error
307
-					. '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
308
-			}
309
-			break;
310
-	}
311
-
312
-	spip_log("erreur upload $error");
313
-	if ($return) {
314
-		return $msg;
315
-	}
316
-
317
-	if (_request('iframe') == 'iframe') {
318
-		echo "<div class='upload_answer upload_error'>$msg</div>";
319
-		exit;
320
-	}
321
-
322
-	include_spip('inc/minipres');
323
-	echo minipres(
324
-		$msg,
325
-		"<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
326
-	);
327
-	exit;
274
+    if (!$error) {
275
+        return false;
276
+    }
277
+
278
+    spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
279
+
280
+    switch ($error) {
281
+        case 4: /* UPLOAD_ERR_NO_FILE */
282
+            return true;
283
+
284
+        # on peut affiner les differents messages d'erreur
285
+        case 1: /* UPLOAD_ERR_INI_SIZE */
286
+            $msg = _T(
287
+                'upload_limit',
288
+                ['max' => ini_get('upload_max_filesize')]
289
+            );
290
+            break;
291
+        case 2: /* UPLOAD_ERR_FORM_SIZE */
292
+            $msg = _T(
293
+                'upload_limit',
294
+                ['max' => ini_get('upload_max_filesize')]
295
+            );
296
+            break;
297
+        case 3: /* UPLOAD_ERR_PARTIAL  */
298
+            $msg = _T(
299
+                'upload_limit',
300
+                ['max' => ini_get('upload_max_filesize')]
301
+            );
302
+            break;
303
+
304
+        default: /* autre */
305
+            if (!$msg) {
306
+                $msg = _T('pass_erreur') . ' ' . $error
307
+                    . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
308
+            }
309
+            break;
310
+    }
311
+
312
+    spip_log("erreur upload $error");
313
+    if ($return) {
314
+        return $msg;
315
+    }
316
+
317
+    if (_request('iframe') == 'iframe') {
318
+        echo "<div class='upload_answer upload_error'>$msg</div>";
319
+        exit;
320
+    }
321
+
322
+    include_spip('inc/minipres');
323
+    echo minipres(
324
+        $msg,
325
+        "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
326
+    );
327
+    exit;
328 328
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
 	$dest = preg_replace(',-r(90|180|270)$,', '', $dest);
155 155
 
156 156
 	// Si le document "source" est deja au bon endroit, ne rien faire
157
-	if ($source == ($dir . $dest . '.' . $ext)) {
157
+	if ($source == ($dir.$dest.'.'.$ext)) {
158 158
 		return $source;
159 159
 	}
160 160
 
161 161
 	// sinon tourner jusqu'a trouver un numero correct
162 162
 	$n = 0;
163
-	while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
163
+	while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext)) {
164 164
 		;
165 165
 	}
166 166
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 function deplacer_fichier_upload($source, $dest, $move = false) {
222 222
 	// Securite
223 223
 	if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) {
224
-		$dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
224
+		$dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
225 225
 	} else {
226 226
 		$dest = preg_replace(',\.\.+,', '.', $dest);
227 227
 	}
@@ -303,8 +303,8 @@  discard block
 block discarded – undo
303 303
 
304 304
 		default: /* autre */
305 305
 			if (!$msg) {
306
-				$msg = _T('pass_erreur') . ' ' . $error
307
-					. '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
306
+				$msg = _T('pass_erreur').' '.$error
307
+					. '<br />'.propre('[->http://php.net/manual/fr/features.file-upload.errors.php]');
308 308
 			}
309 309
 			break;
310 310
 	}
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	include_spip('inc/minipres');
323 323
 	echo minipres(
324 324
 		$msg,
325
-		"<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>'
325
+		"<div style='text-align: ".$GLOBALS['spip_lang_right']."'><a href='".rawurldecode($GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant').'</button></a></div>'
326 326
 	);
327 327
 	exit;
328 328
 }
Please login to merge, or discard this patch.
ecrire/inc/couleurs.php 2 patches
Indentation   +63 added lines, -63 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
 /**
@@ -38,70 +38,70 @@  discard block
 block discarded – undo
38 38
  * @return array|string
39 39
  */
40 40
 function inc_couleurs_dist($choix = null, $ajouter = false) {
41
-	static $couleurs_spip = [
42
-		// Violet soutenu
43
-		9 => ['couleur_theme' => '#9a6ef2'],
44
-		// Violet rosé
45
-		4 => ['couleur_theme' => '#c464cb'],
46
-		// Rose interface SPIP
47
-		2 => ['couleur_theme' =>  '#F02364'],
48
-		// Rouge
49
-		8 => ['couleur_theme' => '#ff4524'],
50
-		// Orange
51
-		3 => ['couleur_theme' => '#c97500'],
52
-		// Vert SPIP
53
-		1 => ['couleur_theme' => '#9dba00'],
54
-		// Vert Troglo
55
-		7 => ['couleur_theme' => '#419a2c'],
56
-		// Bleu-vert
57
-		12 => ['couleur_theme' => '#269681'],
58
-		//  Bleu pastel
59
-		5 => ['couleur_theme' => '#3190ae'],
60
-		//  Bleu Kermesse
61
-		11 => ['couleur_theme' => '#288bdd'],
62
-		//  Gris bleuté
63
-		6 => ['couleur_theme' => '#7d90a2'],
64
-		//  Gris
65
-		10 => ['couleur_theme' => '#909090'],
66
-	];
41
+    static $couleurs_spip = [
42
+        // Violet soutenu
43
+        9 => ['couleur_theme' => '#9a6ef2'],
44
+        // Violet rosé
45
+        4 => ['couleur_theme' => '#c464cb'],
46
+        // Rose interface SPIP
47
+        2 => ['couleur_theme' =>  '#F02364'],
48
+        // Rouge
49
+        8 => ['couleur_theme' => '#ff4524'],
50
+        // Orange
51
+        3 => ['couleur_theme' => '#c97500'],
52
+        // Vert SPIP
53
+        1 => ['couleur_theme' => '#9dba00'],
54
+        // Vert Troglo
55
+        7 => ['couleur_theme' => '#419a2c'],
56
+        // Bleu-vert
57
+        12 => ['couleur_theme' => '#269681'],
58
+        //  Bleu pastel
59
+        5 => ['couleur_theme' => '#3190ae'],
60
+        //  Bleu Kermesse
61
+        11 => ['couleur_theme' => '#288bdd'],
62
+        //  Gris bleuté
63
+        6 => ['couleur_theme' => '#7d90a2'],
64
+        //  Gris
65
+        10 => ['couleur_theme' => '#909090'],
66
+    ];
67 67
 
68
-	if (is_numeric($choix)) {
69
-		$c = $couleurs_spip[$choix];
70
-		// compat < SPIP 3.3
71
-		include_spip('inc/filtres_images_mini');
72
-		$c['couleur_foncee'] = $c['couleur_theme'];
73
-		$c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5);
68
+    if (is_numeric($choix)) {
69
+        $c = $couleurs_spip[$choix];
70
+        // compat < SPIP 3.3
71
+        include_spip('inc/filtres_images_mini');
72
+        $c['couleur_foncee'] = $c['couleur_theme'];
73
+        $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5);
74 74
 
75
-		return
76
-			'couleur_theme=' . substr($c['couleur_theme'], 1)
77
-			// compat < SPIP 3.3
78
-			. '&couleur_claire=' . substr($c['couleur_claire'], 1)
79
-			. '&couleur_foncee=' . substr($c['couleur_foncee'], 1);
80
-	} else {
81
-		if (is_array($choix)) {
82
-			// compat < SPIP 3.3
83
-			$compat_spip_33 = function ($c) {
84
-				if (!isset($c['couleur_theme'])) {
85
-					$c['couleur_theme'] = $c['couleur_foncee'];
86
-					unset($c['couleur_foncee']);
87
-					unset($c['couleur_claire']);
88
-					unset($c['couleur_lien']);
89
-					unset($c['couleur_lien_off']);
90
-				}
91
-				return $c;
92
-			};
93
-			if ($ajouter) {
94
-				foreach ($choix as $c) {
95
-					$couleurs_spip[] = $compat_spip_33($c);
96
-				}
75
+        return
76
+            'couleur_theme=' . substr($c['couleur_theme'], 1)
77
+            // compat < SPIP 3.3
78
+            . '&couleur_claire=' . substr($c['couleur_claire'], 1)
79
+            . '&couleur_foncee=' . substr($c['couleur_foncee'], 1);
80
+    } else {
81
+        if (is_array($choix)) {
82
+            // compat < SPIP 3.3
83
+            $compat_spip_33 = function ($c) {
84
+                if (!isset($c['couleur_theme'])) {
85
+                    $c['couleur_theme'] = $c['couleur_foncee'];
86
+                    unset($c['couleur_foncee']);
87
+                    unset($c['couleur_claire']);
88
+                    unset($c['couleur_lien']);
89
+                    unset($c['couleur_lien_off']);
90
+                }
91
+                return $c;
92
+            };
93
+            if ($ajouter) {
94
+                foreach ($choix as $c) {
95
+                    $couleurs_spip[] = $compat_spip_33($c);
96
+                }
97 97
 
98
-				return $couleurs_spip;
99
-			} else {
100
-				$choix = array_map($compat_spip_33, $choix);
101
-				return $couleurs_spip = $choix;
102
-			}
103
-		}
104
-	}
98
+                return $couleurs_spip;
99
+            } else {
100
+                $choix = array_map($compat_spip_33, $choix);
101
+                return $couleurs_spip = $choix;
102
+            }
103
+        }
104
+    }
105 105
 
106
-	return $couleurs_spip;
106
+    return $couleurs_spip;
107 107
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -70,17 +70,17 @@
 block discarded – undo
70 70
 		// compat < SPIP 3.3
71 71
 		include_spip('inc/filtres_images_mini');
72 72
 		$c['couleur_foncee'] = $c['couleur_theme'];
73
-		$c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5);
73
+		$c['couleur_claire'] = '#'.couleur_eclaircir($c['couleur_theme'], .5);
74 74
 
75 75
 		return
76
-			'couleur_theme=' . substr($c['couleur_theme'], 1)
76
+			'couleur_theme='.substr($c['couleur_theme'], 1)
77 77
 			// compat < SPIP 3.3
78
-			. '&couleur_claire=' . substr($c['couleur_claire'], 1)
79
-			. '&couleur_foncee=' . substr($c['couleur_foncee'], 1);
78
+			. '&couleur_claire='.substr($c['couleur_claire'], 1)
79
+			. '&couleur_foncee='.substr($c['couleur_foncee'], 1);
80 80
 	} else {
81 81
 		if (is_array($choix)) {
82 82
 			// compat < SPIP 3.3
83
-			$compat_spip_33 = function ($c) {
83
+			$compat_spip_33 = function($c) {
84 84
 				if (!isset($c['couleur_theme'])) {
85 85
 					$c['couleur_theme'] = $c['couleur_foncee'];
86 86
 					unset($c['couleur_foncee']);
Please login to merge, or discard this patch.