Completed
Push — master ( a07606...4c3c71 )
by cam
02:01
created
ecrire/inc/charsets.php 2 patches
Indentation   +736 added lines, -736 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // securité
24 24
 if (!defined('_ECRIRE_INC_VERSION')) {
25
-	return;
25
+    return;
26 26
 }
27 27
 
28 28
 // se faciliter la lecture du charset
@@ -42,45 +42,45 @@  discard block
 block discarded – undo
42 42
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
43 43
  **/
44 44
 function load_charset($charset = 'AUTO') {
45
-	if ($charset == 'AUTO') {
46
-		$charset = $GLOBALS['meta']['charset'];
47
-	}
48
-	$charset = trim(strtolower($charset));
49
-	if (isset($GLOBALS['CHARSET'][$charset])) {
50
-		return $charset;
51
-	}
52
-
53
-	if ($charset == 'utf-8') {
54
-		$GLOBALS['CHARSET'][$charset] = [];
55
-
56
-		return $charset;
57
-	}
58
-
59
-	// Quelques synonymes
60
-	if ($charset == '') {
61
-		$charset = 'iso-8859-1';
62
-	} else {
63
-		if ($charset == 'windows-1250') {
64
-			$charset = 'cp1250';
65
-		} else {
66
-			if ($charset == 'windows-1251') {
67
-				$charset = 'cp1251';
68
-			} else {
69
-				if ($charset == 'windows-1256') {
70
-					$charset = 'cp1256';
71
-				}
72
-			}
73
-		}
74
-	}
75
-
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
77
-		return $charset;
78
-	} else {
79
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
-		$GLOBALS['CHARSET'][$charset] = [];
81
-
82
-		return false;
83
-	}
45
+    if ($charset == 'AUTO') {
46
+        $charset = $GLOBALS['meta']['charset'];
47
+    }
48
+    $charset = trim(strtolower($charset));
49
+    if (isset($GLOBALS['CHARSET'][$charset])) {
50
+        return $charset;
51
+    }
52
+
53
+    if ($charset == 'utf-8') {
54
+        $GLOBALS['CHARSET'][$charset] = [];
55
+
56
+        return $charset;
57
+    }
58
+
59
+    // Quelques synonymes
60
+    if ($charset == '') {
61
+        $charset = 'iso-8859-1';
62
+    } else {
63
+        if ($charset == 'windows-1250') {
64
+            $charset = 'cp1250';
65
+        } else {
66
+            if ($charset == 'windows-1251') {
67
+                $charset = 'cp1251';
68
+            } else {
69
+                if ($charset == 'windows-1256') {
70
+                    $charset = 'cp1256';
71
+                }
72
+            }
73
+        }
74
+    }
75
+
76
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
77
+        return $charset;
78
+    } else {
79
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
80
+        $GLOBALS['CHARSET'][$charset] = [];
81
+
82
+        return false;
83
+    }
84 84
 }
85 85
 
86 86
 
@@ -91,31 +91,31 @@  discard block
 block discarded – undo
91 91
  *     true si toutes les fonctions mb nécessaires sont présentes
92 92
  **/
93 93
 function init_mb_string() {
94
-	static $mb;
95
-
96
-	// verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
-	// et que le charset interne est connu de mb_string
98
-	if (!$mb) {
99
-		if (
100
-			function_exists('mb_internal_encoding')
101
-			and function_exists('mb_detect_order')
102
-			and function_exists('mb_substr')
103
-			and function_exists('mb_strlen')
104
-			and function_exists('mb_strtolower')
105
-			and function_exists('mb_strtoupper')
106
-			and function_exists('mb_encode_mimeheader')
107
-			and function_exists('mb_encode_numericentity')
108
-			and function_exists('mb_decode_numericentity')
109
-			and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
110
-		) {
111
-			mb_internal_encoding('utf-8');
112
-			$mb = 1;
113
-		} else {
114
-			$mb = -1;
115
-		}
116
-	}
117
-
118
-	return ($mb == 1);
94
+    static $mb;
95
+
96
+    // verifier que tout est present (fonctions mb_string pour php >= 4.0.6)
97
+    // et que le charset interne est connu de mb_string
98
+    if (!$mb) {
99
+        if (
100
+            function_exists('mb_internal_encoding')
101
+            and function_exists('mb_detect_order')
102
+            and function_exists('mb_substr')
103
+            and function_exists('mb_strlen')
104
+            and function_exists('mb_strtolower')
105
+            and function_exists('mb_strtoupper')
106
+            and function_exists('mb_encode_mimeheader')
107
+            and function_exists('mb_encode_numericentity')
108
+            and function_exists('mb_decode_numericentity')
109
+            and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))
110
+        ) {
111
+            mb_internal_encoding('utf-8');
112
+            $mb = 1;
113
+        } else {
114
+            $mb = -1;
115
+        }
116
+    }
117
+
118
+    return ($mb == 1);
119 119
 }
120 120
 
121 121
 /**
@@ -130,21 +130,21 @@  discard block
 block discarded – undo
130 130
  *     true si iconv fonctionne correctement
131 131
  **/
132 132
 function test_iconv() {
133
-	static $iconv_ok;
134
-
135
-	if (!$iconv_ok) {
136
-		if (!function_exists('iconv')) {
137
-			$iconv_ok = -1;
138
-		} else {
139
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
140
-				$iconv_ok = 1;
141
-			} else {
142
-				$iconv_ok = -1;
143
-			}
144
-		}
145
-	}
146
-
147
-	return ($iconv_ok == 1);
133
+    static $iconv_ok;
134
+
135
+    if (!$iconv_ok) {
136
+        if (!function_exists('iconv')) {
137
+            $iconv_ok = -1;
138
+        } else {
139
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') {
140
+                $iconv_ok = 1;
141
+            } else {
142
+                $iconv_ok = -1;
143
+            }
144
+        }
145
+    }
146
+
147
+    return ($iconv_ok == 1);
148 148
 }
149 149
 
150 150
 
@@ -157,18 +157,18 @@  discard block
 block discarded – undo
157 157
  *     true si PCRE supporte l'UTF-8 correctement
158 158
  **/
159 159
 function test_pcre_unicode() {
160
-	static $pcre_ok = 0;
161
-
162
-	if (!$pcre_ok) {
163
-		$s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' ';
164
-		if (preg_match(',\W...\W,u', $s)) {
165
-			$pcre_ok = 1;
166
-		} else {
167
-			$pcre_ok = -1;
168
-		}
169
-	}
170
-
171
-	return $pcre_ok == 1;
160
+    static $pcre_ok = 0;
161
+
162
+    if (!$pcre_ok) {
163
+        $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' ';
164
+        if (preg_match(',\W...\W,u', $s)) {
165
+            $pcre_ok = 1;
166
+        } else {
167
+            $pcre_ok = -1;
168
+        }
169
+    }
170
+
171
+    return $pcre_ok == 1;
172 172
 }
173 173
 
174 174
 /**
@@ -184,22 +184,22 @@  discard block
 block discarded – undo
184 184
  *    Plage de caractères
185 185
  **/
186 186
 function pcre_lettres_unicode() {
187
-	static $plage_unicode;
188
-
189
-	if (!$plage_unicode) {
190
-		if (test_pcre_unicode()) {
191
-			// cf. http://www.unicode.org/charts/
192
-			$plage_unicode = '\w' // iso-latin
193
-				. '\x{100}-\x{24f}' // europeen etendu
194
-				. '\x{300}-\x{1cff}' // des tas de trucs
195
-			;
196
-		} else {
197
-			// fallback a trois sous
198
-			$plage_unicode = '\w';
199
-		}
200
-	}
201
-
202
-	return $plage_unicode;
187
+    static $plage_unicode;
188
+
189
+    if (!$plage_unicode) {
190
+        if (test_pcre_unicode()) {
191
+            // cf. http://www.unicode.org/charts/
192
+            $plage_unicode = '\w' // iso-latin
193
+                . '\x{100}-\x{24f}' // europeen etendu
194
+                . '\x{300}-\x{1cff}' // des tas de trucs
195
+            ;
196
+        } else {
197
+            // fallback a trois sous
198
+            $plage_unicode = '\w';
199
+        }
200
+    }
201
+
202
+    return $plage_unicode;
203 203
 }
204 204
 
205 205
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
  *    Plage de caractères
218 218
  **/
219 219
 function plage_punct_unicode() {
220
-	return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
220
+    return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])';
221 221
 }
222 222
 
223 223
 /**
@@ -237,75 +237,75 @@  discard block
 block discarded – undo
237 237
  *     Texte corrigé
238 238
  **/
239 239
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
240
-	static $trans;
241
-
242
-	if (is_array($texte)) {
243
-		return array_map('corriger_caracteres_windows', $texte);
244
-	}
245
-
246
-	if ($charset == 'AUTO') {
247
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
248
-	}
249
-	if ($charset == 'utf-8') {
250
-		$p = chr(194);
251
-		if (strpos($texte, $p) == false) {
252
-			return $texte;
253
-		}
254
-	} else {
255
-		if ($charset == 'iso-8859-1') {
256
-			$p = '';
257
-		} else {
258
-			return $texte;
259
-		}
260
-	}
261
-
262
-	if (!isset($trans[$charset][$charset_cible])) {
263
-		$trans[$charset][$charset_cible] = [
264
-			$p . chr(128) => '€',
265
-			$p . chr(129) => ' ', # pas affecte
266
-			$p . chr(130) => '‚',
267
-			$p . chr(131) => 'ƒ',
268
-			$p . chr(132) => '„',
269
-			$p . chr(133) => '…',
270
-			$p . chr(134) => '†',
271
-			$p . chr(135) => '‡',
272
-			$p . chr(136) => 'ˆ',
273
-			$p . chr(137) => '‰',
274
-			$p . chr(138) => 'Š',
275
-			$p . chr(139) => '‹',
276
-			$p . chr(140) => 'Œ',
277
-			$p . chr(141) => ' ', # pas affecte
278
-			$p . chr(142) => 'Ž',
279
-			$p . chr(143) => ' ', # pas affecte
280
-			$p . chr(144) => ' ', # pas affecte
281
-			$p . chr(145) => '‘',
282
-			$p . chr(146) => '’',
283
-			$p . chr(147) => '“',
284
-			$p . chr(148) => '”',
285
-			$p . chr(149) => '•',
286
-			$p . chr(150) => '–',
287
-			$p . chr(151) => '—',
288
-			$p . chr(152) => '˜',
289
-			$p . chr(153) => '™',
290
-			$p . chr(154) => 'š',
291
-			$p . chr(155) => '›',
292
-			$p . chr(156) => 'œ',
293
-			$p . chr(157) => ' ', # pas affecte
294
-			$p . chr(158) => 'ž',
295
-			$p . chr(159) => 'Ÿ',
296
-		];
297
-		if ($charset_cible != 'unicode') {
298
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
299
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
300
-			}
301
-		}
302
-	}
303
-
304
-	return @str_replace(
305
-		array_keys($trans[$charset][$charset_cible]),
306
-		array_values($trans[$charset][$charset_cible]),
307
-		$texte
308
-	);
240
+    static $trans;
241
+
242
+    if (is_array($texte)) {
243
+        return array_map('corriger_caracteres_windows', $texte);
244
+    }
245
+
246
+    if ($charset == 'AUTO') {
247
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
248
+    }
249
+    if ($charset == 'utf-8') {
250
+        $p = chr(194);
251
+        if (strpos($texte, $p) == false) {
252
+            return $texte;
253
+        }
254
+    } else {
255
+        if ($charset == 'iso-8859-1') {
256
+            $p = '';
257
+        } else {
258
+            return $texte;
259
+        }
260
+    }
261
+
262
+    if (!isset($trans[$charset][$charset_cible])) {
263
+        $trans[$charset][$charset_cible] = [
264
+            $p . chr(128) => '€',
265
+            $p . chr(129) => ' ', # pas affecte
266
+            $p . chr(130) => '‚',
267
+            $p . chr(131) => 'ƒ',
268
+            $p . chr(132) => '„',
269
+            $p . chr(133) => '…',
270
+            $p . chr(134) => '†',
271
+            $p . chr(135) => '‡',
272
+            $p . chr(136) => 'ˆ',
273
+            $p . chr(137) => '‰',
274
+            $p . chr(138) => 'Š',
275
+            $p . chr(139) => '‹',
276
+            $p . chr(140) => 'Œ',
277
+            $p . chr(141) => ' ', # pas affecte
278
+            $p . chr(142) => 'Ž',
279
+            $p . chr(143) => ' ', # pas affecte
280
+            $p . chr(144) => ' ', # pas affecte
281
+            $p . chr(145) => '‘',
282
+            $p . chr(146) => '’',
283
+            $p . chr(147) => '“',
284
+            $p . chr(148) => '”',
285
+            $p . chr(149) => '•',
286
+            $p . chr(150) => '–',
287
+            $p . chr(151) => '—',
288
+            $p . chr(152) => '˜',
289
+            $p . chr(153) => '™',
290
+            $p . chr(154) => 'š',
291
+            $p . chr(155) => '›',
292
+            $p . chr(156) => 'œ',
293
+            $p . chr(157) => ' ', # pas affecte
294
+            $p . chr(158) => 'ž',
295
+            $p . chr(159) => 'Ÿ',
296
+        ];
297
+        if ($charset_cible != 'unicode') {
298
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
299
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
300
+            }
301
+        }
302
+    }
303
+
304
+    return @str_replace(
305
+        array_keys($trans[$charset][$charset_cible]),
306
+        array_values($trans[$charset][$charset_cible]),
307
+        $texte
308
+    );
309 309
 }
310 310
 
311 311
 
@@ -322,26 +322,26 @@  discard block
 block discarded – undo
322 322
  *     Texte converti
323 323
  **/
324 324
 function html2unicode($texte, $secure = false) {
325
-	if (strpos($texte, '&') === false) {
326
-		return $texte;
327
-	}
328
-	static $trans = [];
329
-	if (!$trans) {
330
-		load_charset('html');
331
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
332
-			$trans["&$key;"] = $val;
333
-		}
334
-	}
335
-
336
-	if ($secure) {
337
-		return str_replace(array_keys($trans), array_values($trans), $texte);
338
-	} else {
339
-		return str_replace(
340
-			['&', '"', '<', '>'],
341
-			['&', '"', '<', '>'],
342
-			str_replace(array_keys($trans), array_values($trans), $texte)
343
-		);
344
-	}
325
+    if (strpos($texte, '&') === false) {
326
+        return $texte;
327
+    }
328
+    static $trans = [];
329
+    if (!$trans) {
330
+        load_charset('html');
331
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
332
+            $trans["&$key;"] = $val;
333
+        }
334
+    }
335
+
336
+    if ($secure) {
337
+        return str_replace(array_keys($trans), array_values($trans), $texte);
338
+    } else {
339
+        return str_replace(
340
+            ['&amp;', '&quot;', '&lt;', '&gt;'],
341
+            ['&', '"', '<', '>'],
342
+            str_replace(array_keys($trans), array_values($trans), $texte)
343
+        );
344
+    }
345 345
 }
346 346
 
347 347
 
@@ -356,16 +356,16 @@  discard block
 block discarded – undo
356 356
  *     Texte converti
357 357
  **/
358 358
 function mathml2unicode($texte) {
359
-	static $trans;
360
-	if (!$trans) {
361
-		load_charset('mathml');
359
+    static $trans;
360
+    if (!$trans) {
361
+        load_charset('mathml');
362 362
 
363
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
364
-			$trans["&$key;"] = $val;
365
-		}
366
-	}
363
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
364
+            $trans["&$key;"] = $val;
365
+        }
366
+    }
367 367
 
368
-	return str_replace(array_keys($trans), array_values($trans), $texte);
368
+    return str_replace(array_keys($trans), array_values($trans), $texte);
369 369
 }
370 370
 
371 371
 
@@ -387,75 +387,75 @@  discard block
 block discarded – undo
387 387
  *     Texte converti en unicode
388 388
  **/
389 389
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
390
-	static $trans;
391
-
392
-	if ($charset == 'AUTO') {
393
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
394
-	}
395
-
396
-	if ($charset == '') {
397
-		$charset = 'iso-8859-1';
398
-	}
399
-	$charset = strtolower($charset);
400
-
401
-	switch ($charset) {
402
-		case 'utf-8':
403
-		case 'utf8':
404
-			return utf_8_to_unicode($texte);
405
-
406
-		case 'iso-8859-1':
407
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
408
-		// pas de break; ici, on suit sur default:
409
-
410
-		default:
411
-			// mbstring presente ?
412
-			if (init_mb_string()) {
413
-				$order = mb_detect_order();
414
-				try {
415
-					# mb_string connait-il $charset?
416
-					if ($order and mb_detect_order($charset)) {
417
-						$s = mb_convert_encoding($texte, 'utf-8', $charset);
418
-						if ($s && $s != $texte) {
419
-							return utf_8_to_unicode($s);
420
-						}
421
-					}
422
-				} catch (\Error $e) {
423
-					// Le charset n'existe probablement pas
424
-				} finally {
425
-					mb_detect_order($order); # remettre comme precedemment
426
-				}
427
-			}
428
-
429
-			// Sinon, peut-etre connaissons-nous ce charset ?
430
-			if (!isset($trans[$charset])) {
431
-				if (
432
-					$cset = load_charset($charset)
433
-					and is_array($GLOBALS['CHARSET'][$cset])
434
-				) {
435
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
436
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
437
-					}
438
-				}
439
-			}
440
-			if (isset($trans[$charset]) and count($trans[$charset])) {
441
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
442
-			}
443
-
444
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
445
-			// caractere n'appartient pas au charset, mais c'est un probleme
446
-			// surtout en utf-8, gere ci-dessus)
447
-			if (test_iconv()) {
448
-				$s = iconv($charset, 'utf-32le', $texte);
449
-				if ($s) {
450
-					return utf_32_to_unicode($s);
451
-				}
452
-			}
453
-
454
-			// Au pire ne rien faire
455
-			spip_log("erreur charset '$charset' non supporte");
456
-
457
-			return $texte;
458
-	}
390
+    static $trans;
391
+
392
+    if ($charset == 'AUTO') {
393
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
394
+    }
395
+
396
+    if ($charset == '') {
397
+        $charset = 'iso-8859-1';
398
+    }
399
+    $charset = strtolower($charset);
400
+
401
+    switch ($charset) {
402
+        case 'utf-8':
403
+        case 'utf8':
404
+            return utf_8_to_unicode($texte);
405
+
406
+        case 'iso-8859-1':
407
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
408
+        // pas de break; ici, on suit sur default:
409
+
410
+        default:
411
+            // mbstring presente ?
412
+            if (init_mb_string()) {
413
+                $order = mb_detect_order();
414
+                try {
415
+                    # mb_string connait-il $charset?
416
+                    if ($order and mb_detect_order($charset)) {
417
+                        $s = mb_convert_encoding($texte, 'utf-8', $charset);
418
+                        if ($s && $s != $texte) {
419
+                            return utf_8_to_unicode($s);
420
+                        }
421
+                    }
422
+                } catch (\Error $e) {
423
+                    // Le charset n'existe probablement pas
424
+                } finally {
425
+                    mb_detect_order($order); # remettre comme precedemment
426
+                }
427
+            }
428
+
429
+            // Sinon, peut-etre connaissons-nous ce charset ?
430
+            if (!isset($trans[$charset])) {
431
+                if (
432
+                    $cset = load_charset($charset)
433
+                    and is_array($GLOBALS['CHARSET'][$cset])
434
+                ) {
435
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
436
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
437
+                    }
438
+                }
439
+            }
440
+            if (isset($trans[$charset]) and count($trans[$charset])) {
441
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
442
+            }
443
+
444
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
445
+            // caractere n'appartient pas au charset, mais c'est un probleme
446
+            // surtout en utf-8, gere ci-dessus)
447
+            if (test_iconv()) {
448
+                $s = iconv($charset, 'utf-32le', $texte);
449
+                if ($s) {
450
+                    return utf_32_to_unicode($s);
451
+                }
452
+            }
453
+
454
+            // Au pire ne rien faire
455
+            spip_log("erreur charset '$charset' non supporte");
456
+
457
+            return $texte;
458
+    }
459 459
 }
460 460
 
461 461
 
@@ -474,44 +474,44 @@  discard block
 block discarded – undo
474 474
  *     Texte transformé dans le charset souhaité
475 475
  **/
476 476
 function unicode2charset($texte, $charset = 'AUTO') {
477
-	static $CHARSET_REVERSE = [];
478
-	static $trans = [];
479
-
480
-	if ($charset == 'AUTO') {
481
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
482
-	}
483
-
484
-	switch ($charset) {
485
-		case 'utf-8':
486
-			return unicode_to_utf_8($texte);
487
-			break;
488
-
489
-		default:
490
-			$charset = load_charset($charset);
491
-
492
-			if (empty($CHARSET_REVERSE[$charset])) {
493
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
494
-			}
495
-
496
-			if (!isset($trans[$charset])) {
497
-				$trans[$charset] = [];
498
-				$t = &$trans[$charset];
499
-				for ($e = 128; $e < 255; $e++) {
500
-					$h = dechex($e);
501
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
502
-						$s = $CHARSET_REVERSE[$charset][$e];
503
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
504
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
505
-					} else {
506
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
507
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
508
-					}
509
-				}
510
-			}
511
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
512
-
513
-			return $texte;
514
-	}
477
+    static $CHARSET_REVERSE = [];
478
+    static $trans = [];
479
+
480
+    if ($charset == 'AUTO') {
481
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
482
+    }
483
+
484
+    switch ($charset) {
485
+        case 'utf-8':
486
+            return unicode_to_utf_8($texte);
487
+            break;
488
+
489
+        default:
490
+            $charset = load_charset($charset);
491
+
492
+            if (empty($CHARSET_REVERSE[$charset])) {
493
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
494
+            }
495
+
496
+            if (!isset($trans[$charset])) {
497
+                $trans[$charset] = [];
498
+                $t = &$trans[$charset];
499
+                for ($e = 128; $e < 255; $e++) {
500
+                    $h = dechex($e);
501
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
502
+                        $s = $CHARSET_REVERSE[$charset][$e];
503
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
504
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
505
+                    } else {
506
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
507
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
508
+                    }
509
+                }
510
+            }
511
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
512
+
513
+            return $texte;
514
+    }
515 515
 }
516 516
 
517 517
 
@@ -529,39 +529,39 @@  discard block
 block discarded – undo
529 529
  *     Texte transformé dans le charset site
530 530
  **/
531 531
 function importer_charset($texte, $charset = 'AUTO') {
532
-	static $trans = [];
533
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
534
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
535
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
536
-		if (init_mb_string()) {
537
-			if (
538
-				$order = mb_detect_order() # mb_string connait-il $charset?
539
-				and mb_detect_order($charset)
540
-			) {
541
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
542
-			}
543
-			mb_detect_order($order); # remettre comme precedemment
544
-			return $s;
545
-		}
546
-		// Sinon, peut-etre connaissons-nous ce charset ?
547
-		if (!isset($trans[$charset])) {
548
-			if (
549
-				$cset = load_charset($charset)
550
-				and is_array($GLOBALS['CHARSET'][$cset])
551
-			) {
552
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
553
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
554
-				}
555
-			}
556
-		}
557
-		if (count($trans[$charset])) {
558
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
559
-		}
560
-
561
-		return $texte;
562
-	}
563
-
564
-	return unicode2charset(charset2unicode($texte, $charset));
532
+    static $trans = [];
533
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
534
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
535
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
536
+        if (init_mb_string()) {
537
+            if (
538
+                $order = mb_detect_order() # mb_string connait-il $charset?
539
+                and mb_detect_order($charset)
540
+            ) {
541
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
542
+            }
543
+            mb_detect_order($order); # remettre comme precedemment
544
+            return $s;
545
+        }
546
+        // Sinon, peut-etre connaissons-nous ce charset ?
547
+        if (!isset($trans[$charset])) {
548
+            if (
549
+                $cset = load_charset($charset)
550
+                and is_array($GLOBALS['CHARSET'][$cset])
551
+            ) {
552
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
553
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
554
+                }
555
+            }
556
+        }
557
+        if (count($trans[$charset])) {
558
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
559
+        }
560
+
561
+        return $texte;
562
+    }
563
+
564
+    return unicode2charset(charset2unicode($texte, $charset));
565 565
 }
566 566
 
567 567
 
@@ -577,92 +577,92 @@  discard block
 block discarded – undo
577 577
  **/
578 578
 function utf_8_to_unicode($source) {
579 579
 
580
-	// mb_string : methode rapide
581
-	if (init_mb_string()) {
582
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
583
-
584
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
585
-	}
586
-
587
-	// Sinon methode pas a pas
588
-	static $decrement;
589
-	static $shift;
590
-
591
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
592
-	if (!is_array($decrement)) {
593
-		// array used to figure what number to decrement from character order value
594
-		// according to number of characters used to map unicode to ascii by utf-8
595
-		$decrement[4] = 240;
596
-		$decrement[3] = 224;
597
-		$decrement[2] = 192;
598
-		$decrement[1] = 0;
599
-		// the number of bits to shift each charNum by
600
-		$shift[1][0] = 0;
601
-		$shift[2][0] = 6;
602
-		$shift[2][1] = 0;
603
-		$shift[3][0] = 12;
604
-		$shift[3][1] = 6;
605
-		$shift[3][2] = 0;
606
-		$shift[4][0] = 18;
607
-		$shift[4][1] = 12;
608
-		$shift[4][2] = 6;
609
-		$shift[4][3] = 0;
610
-	}
611
-
612
-	$pos = 0;
613
-	$len = strlen($source);
614
-	$encodedString = '';
615
-	while ($pos < $len) {
616
-		$char = '';
617
-		$ischar = false;
618
-		$asciiPos = ord(substr($source, $pos, 1));
619
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
620
-			// 4 chars representing one unicode character
621
-			$thisLetter = substr($source, $pos, 4);
622
-			$pos += 4;
623
-		} else {
624
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
625
-				// 3 chars representing one unicode character
626
-				$thisLetter = substr($source, $pos, 3);
627
-				$pos += 3;
628
-			} else {
629
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
630
-					// 2 chars representing one unicode character
631
-					$thisLetter = substr($source, $pos, 2);
632
-					$pos += 2;
633
-				} else {
634
-					// 1 char (lower ascii)
635
-					$thisLetter = substr($source, $pos, 1);
636
-					$pos += 1;
637
-					$char = $thisLetter;
638
-					$ischar = true;
639
-				}
640
-			}
641
-		}
642
-
643
-		if ($ischar) {
644
-			$encodedString .= $char;
645
-		} else {  // process the string representing the letter to a unicode entity
646
-			$thisLen = strlen($thisLetter);
647
-			$thisPos = 0;
648
-			$decimalCode = 0;
649
-			while ($thisPos < $thisLen) {
650
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
651
-				if ($thisPos == 0) {
652
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
653
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
654
-				} else {
655
-					$charNum = intval($thisCharOrd - 128);
656
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
657
-				}
658
-				$thisPos++;
659
-			}
660
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
661
-			$encodedString .= $encodedLetter;
662
-		}
663
-	}
664
-
665
-	return $encodedString;
580
+    // mb_string : methode rapide
581
+    if (init_mb_string()) {
582
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
583
+
584
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
585
+    }
586
+
587
+    // Sinon methode pas a pas
588
+    static $decrement;
589
+    static $shift;
590
+
591
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
592
+    if (!is_array($decrement)) {
593
+        // array used to figure what number to decrement from character order value
594
+        // according to number of characters used to map unicode to ascii by utf-8
595
+        $decrement[4] = 240;
596
+        $decrement[3] = 224;
597
+        $decrement[2] = 192;
598
+        $decrement[1] = 0;
599
+        // the number of bits to shift each charNum by
600
+        $shift[1][0] = 0;
601
+        $shift[2][0] = 6;
602
+        $shift[2][1] = 0;
603
+        $shift[3][0] = 12;
604
+        $shift[3][1] = 6;
605
+        $shift[3][2] = 0;
606
+        $shift[4][0] = 18;
607
+        $shift[4][1] = 12;
608
+        $shift[4][2] = 6;
609
+        $shift[4][3] = 0;
610
+    }
611
+
612
+    $pos = 0;
613
+    $len = strlen($source);
614
+    $encodedString = '';
615
+    while ($pos < $len) {
616
+        $char = '';
617
+        $ischar = false;
618
+        $asciiPos = ord(substr($source, $pos, 1));
619
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
620
+            // 4 chars representing one unicode character
621
+            $thisLetter = substr($source, $pos, 4);
622
+            $pos += 4;
623
+        } else {
624
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
625
+                // 3 chars representing one unicode character
626
+                $thisLetter = substr($source, $pos, 3);
627
+                $pos += 3;
628
+            } else {
629
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
630
+                    // 2 chars representing one unicode character
631
+                    $thisLetter = substr($source, $pos, 2);
632
+                    $pos += 2;
633
+                } else {
634
+                    // 1 char (lower ascii)
635
+                    $thisLetter = substr($source, $pos, 1);
636
+                    $pos += 1;
637
+                    $char = $thisLetter;
638
+                    $ischar = true;
639
+                }
640
+            }
641
+        }
642
+
643
+        if ($ischar) {
644
+            $encodedString .= $char;
645
+        } else {  // process the string representing the letter to a unicode entity
646
+            $thisLen = strlen($thisLetter);
647
+            $thisPos = 0;
648
+            $decimalCode = 0;
649
+            while ($thisPos < $thisLen) {
650
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
651
+                if ($thisPos == 0) {
652
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
653
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
654
+                } else {
655
+                    $charNum = intval($thisCharOrd - 128);
656
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
657
+                }
658
+                $thisPos++;
659
+            }
660
+            $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
661
+            $encodedString .= $encodedLetter;
662
+        }
663
+    }
664
+
665
+    return $encodedString;
666 666
 }
667 667
 
668 668
 /**
@@ -681,32 +681,32 @@  discard block
 block discarded – undo
681 681
  **/
682 682
 function utf_32_to_unicode($source) {
683 683
 
684
-	// mb_string : methode rapide
685
-	if (init_mb_string()) {
686
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
687
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
688
-
689
-		return str_replace(chr(0), '', $source);
690
-	}
691
-
692
-	// Sinon methode lente
693
-	$texte = '';
694
-	while ($source) {
695
-		$words = unpack('V*', substr($source, 0, 1024));
696
-		$source = substr($source, 1024);
697
-		foreach ($words as $word) {
698
-			if ($word < 128) {
699
-				$texte .= chr($word);
700
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
701
-			else {
702
-				if ($word != 65279) {
703
-					$texte .= '&#' . $word . ';';
704
-				}
705
-			}
706
-		}
707
-	}
708
-
709
-	return $texte;
684
+    // mb_string : methode rapide
685
+    if (init_mb_string()) {
686
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
687
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
688
+
689
+        return str_replace(chr(0), '', $source);
690
+    }
691
+
692
+    // Sinon methode lente
693
+    $texte = '';
694
+    while ($source) {
695
+        $words = unpack('V*', substr($source, 0, 1024));
696
+        $source = substr($source, 1024);
697
+        foreach ($words as $word) {
698
+            if ($word < 128) {
699
+                $texte .= chr($word);
700
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
701
+            else {
702
+                if ($word != 65279) {
703
+                    $texte .= '&#' . $word . ';';
704
+                }
705
+            }
706
+        }
707
+    }
708
+
709
+    return $texte;
710 710
 }
711 711
 
712 712
 
@@ -723,21 +723,21 @@  discard block
 block discarded – undo
723 723
  *    Caractère utf8 si trouvé, '' sinon
724 724
  **/
725 725
 function caractere_utf_8($num) {
726
-	$num = intval($num);
727
-	if ($num < 128) {
728
-		return chr($num);
729
-	}
730
-	if ($num < 2048) {
731
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
732
-	}
733
-	if ($num < 65536) {
734
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
735
-	}
736
-	if ($num < 1114112) {
737
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
738
-	}
739
-
740
-	return '';
726
+    $num = intval($num);
727
+    if ($num < 128) {
728
+        return chr($num);
729
+    }
730
+    if ($num < 2048) {
731
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
732
+    }
733
+    if ($num < 65536) {
734
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
735
+    }
736
+    if ($num < 1114112) {
737
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
738
+    }
739
+
740
+    return '';
741 741
 }
742 742
 
743 743
 /**
@@ -750,42 +750,42 @@  discard block
 block discarded – undo
750 750
  **/
751 751
 function unicode_to_utf_8($texte) {
752 752
 
753
-	// 1. Entites &#128; et suivantes
754
-	$vu = [];
755
-	if (
756
-		preg_match_all(
757
-			',&#0*([1-9][0-9][0-9]+);,S',
758
-			$texte,
759
-			$regs,
760
-			PREG_SET_ORDER
761
-		)
762
-	) {
763
-		foreach ($regs as $reg) {
764
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
765
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
766
-			}
767
-		}
768
-	}
769
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
770
-
771
-	// 2. Entites > &#xFF;
772
-	//$vu = array();
773
-	if (
774
-		preg_match_all(
775
-			',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
776
-			$texte,
777
-			$regs,
778
-			PREG_SET_ORDER
779
-		)
780
-	) {
781
-		foreach ($regs as $reg) {
782
-			if (!isset($vu[$reg[0]])) {
783
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
784
-			}
785
-		}
786
-	}
787
-
788
-	return str_replace(array_keys($vu), array_values($vu), $texte);
753
+    // 1. Entites &#128; et suivantes
754
+    $vu = [];
755
+    if (
756
+        preg_match_all(
757
+            ',&#0*([1-9][0-9][0-9]+);,S',
758
+            $texte,
759
+            $regs,
760
+            PREG_SET_ORDER
761
+        )
762
+    ) {
763
+        foreach ($regs as $reg) {
764
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
765
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
766
+            }
767
+        }
768
+    }
769
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
770
+
771
+    // 2. Entites > &#xFF;
772
+    //$vu = array();
773
+    if (
774
+        preg_match_all(
775
+            ',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
776
+            $texte,
777
+            $regs,
778
+            PREG_SET_ORDER
779
+        )
780
+    ) {
781
+        foreach ($regs as $reg) {
782
+            if (!isset($vu[$reg[0]])) {
783
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
784
+            }
785
+        }
786
+    }
787
+
788
+    return str_replace(array_keys($vu), array_values($vu), $texte);
789 789
 }
790 790
 
791 791
 /**
@@ -797,15 +797,15 @@  discard block
 block discarded – undo
797 797
  *     Texte converti
798 798
  **/
799 799
 function unicode_to_javascript($texte) {
800
-	$vu = [];
801
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
802
-		$num = $regs[1];
803
-		$vu[$num] = true;
804
-		$s = '\u' . sprintf('%04x', $num);
805
-		$texte = str_replace($regs[0], $s, $texte);
806
-	}
807
-
808
-	return $texte;
800
+    $vu = [];
801
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
802
+        $num = $regs[1];
803
+        $vu[$num] = true;
804
+        $s = '\u' . sprintf('%04x', $num);
805
+        $texte = str_replace($regs[0], $s, $texte);
806
+    }
807
+
808
+    return $texte;
809 809
 }
810 810
 
811 811
 /**
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
  *     Texte converti
818 818
  **/
819 819
 function javascript_to_unicode($texte) {
820
-	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
821
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
822
-	}
820
+    while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
821
+        $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
822
+    }
823 823
 
824
-	return $texte;
824
+    return $texte;
825 825
 }
826 826
 
827 827
 /**
@@ -833,11 +833,11 @@  discard block
 block discarded – undo
833 833
  *     Texte converti
834 834
  **/
835 835
 function javascript_to_binary($texte) {
836
-	while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
837
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
838
-	}
836
+    while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
837
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
838
+    }
839 839
 
840
-	return $texte;
840
+    return $texte;
841 841
 }
842 842
 
843 843
 
@@ -855,26 +855,26 @@  discard block
 block discarded – undo
855 855
  * @return string
856 856
  */
857 857
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') {
858
-	static $trans = [];
859
-	if ($charset == 'AUTO') {
860
-		$charset = $GLOBALS['meta']['charset'];
861
-	}
862
-	if (!strlen($texte)) {
863
-		return $texte;
864
-	}
865
-
866
-	$table_translit = 'translit' . $complexe;
867
-
868
-	// 2. Translitterer grace a la table predefinie
869
-	if (!isset($trans[$complexe])) {
870
-		$trans[$complexe] = [];
871
-		load_charset($table_translit);
872
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
873
-			$trans[$complexe][caractere_utf_8($key)] = $val;
874
-		}
875
-	}
876
-
877
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
858
+    static $trans = [];
859
+    if ($charset == 'AUTO') {
860
+        $charset = $GLOBALS['meta']['charset'];
861
+    }
862
+    if (!strlen($texte)) {
863
+        return $texte;
864
+    }
865
+
866
+    $table_translit = 'translit' . $complexe;
867
+
868
+    // 2. Translitterer grace a la table predefinie
869
+    if (!isset($trans[$complexe])) {
870
+        $trans[$complexe] = [];
871
+        load_charset($table_translit);
872
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
873
+            $trans[$complexe][caractere_utf_8($key)] = $val;
874
+        }
875
+    }
876
+
877
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
878 878
 }
879 879
 
880 880
 /**
@@ -897,14 +897,14 @@  discard block
 block discarded – undo
897 897
  * @return string
898 898
  */
899 899
 function translitteration($texte, $charset = 'AUTO', $complexe = '') {
900
-	// 0. Supprimer les caracteres illegaux
901
-	include_spip('inc/filtres');
902
-	$texte = corriger_caracteres($texte);
900
+    // 0. Supprimer les caracteres illegaux
901
+    include_spip('inc/filtres');
902
+    $texte = corriger_caracteres($texte);
903 903
 
904
-	// 1. Passer le charset et les &eacute en utf-8
905
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
904
+    // 1. Passer le charset et les &eacute en utf-8
905
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true)));
906 906
 
907
-	return translitteration_rapide($texte, $charset, $complexe);
907
+    return translitteration_rapide($texte, $charset, $complexe);
908 908
 }
909 909
 
910 910
 /**
@@ -919,19 +919,19 @@  discard block
 block discarded – undo
919 919
  * @return string
920 920
  */
921 921
 function translitteration_complexe($texte, $chiffres = false) {
922
-	$texte = translitteration($texte, 'AUTO', 'complexe');
923
-
924
-	if ($chiffres) {
925
-		$texte = preg_replace_callback(
926
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
-			function ($m) {
928
-			return translitteration_chiffree($m[0]);
929
-			},
930
-			$texte
931
-		);
932
-	}
933
-
934
-	return $texte;
922
+    $texte = translitteration($texte, 'AUTO', 'complexe');
923
+
924
+    if ($chiffres) {
925
+        $texte = preg_replace_callback(
926
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
+            function ($m) {
928
+            return translitteration_chiffree($m[0]);
929
+            },
930
+            $texte
931
+        );
932
+    }
933
+
934
+    return $texte;
935 935
 }
936 936
 
937 937
 /**
@@ -943,7 +943,7 @@  discard block
 block discarded – undo
943 943
  * @return string
944 944
  */
945 945
 function translitteration_chiffree($car) {
946
-	return strtr($car, "'`?~.^+(-", '123456789');
946
+    return strtr($car, "'`?~.^+(-", '123456789');
947 947
 }
948 948
 
949 949
 
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
  *    true s'il a un BOM
957 957
  **/
958 958
 function bom_utf8($texte) {
959
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
959
+    return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
960 960
 }
961 961
 
962 962
 /**
@@ -973,21 +973,21 @@  discard block
 block discarded – undo
973 973
  *     true si c'est le cas
974 974
  **/
975 975
 function is_utf8($string) {
976
-	return !strlen(
977
-		preg_replace(
978
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
979
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
980
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
981
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
982
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
983
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
984
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
985
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
986
-			. ',sS',
987
-			'',
988
-			$string
989
-		)
990
-	);
976
+    return !strlen(
977
+        preg_replace(
978
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
979
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
980
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
981
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
982
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
983
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
984
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
985
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
986
+            . ',sS',
987
+            '',
988
+            $string
989
+        )
990
+    );
991 991
 }
992 992
 
993 993
 /**
@@ -999,13 +999,13 @@  discard block
 block discarded – undo
999 999
  *     true si c'est le cas
1000 1000
  **/
1001 1001
 function is_ascii($string) {
1002
-	return !strlen(
1003
-		preg_replace(
1004
-			',[\x09\x0A\x0D\x20-\x7E],sS',
1005
-			'',
1006
-			$string
1007
-		)
1008
-	);
1002
+    return !strlen(
1003
+        preg_replace(
1004
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
1005
+            '',
1006
+            $string
1007
+        )
1008
+    );
1009 1009
 }
1010 1010
 
1011 1011
 /**
@@ -1024,53 +1024,53 @@  discard block
 block discarded – undo
1024 1024
  **/
1025 1025
 function transcoder_page($texte, $headers = '') {
1026 1026
 
1027
-	// Si tout est < 128 pas la peine d'aller plus loin
1028
-	if (is_ascii($texte)) {
1029
-		#spip_log('charset: ascii');
1030
-		return $texte;
1031
-	}
1032
-
1033
-	if (bom_utf8($texte)) {
1034
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
1035
-		$charset = 'utf-8';
1036
-		$texte = substr($texte, 3);
1037
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1038
-		// charset precise par le contenu (xml)
1039
-		$charset = trim(strtolower($regs[1]));
1040
-	} elseif (
1041
-		// charset precise par le contenu (html)
1042
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1043
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1044
-		and false === strpos($regs[2], '#')
1045
-		and $tmp = trim(strtolower($regs[2]))
1046
-	) {
1047
-		$charset = $tmp;
1048
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1049
-		// charset de la reponse http
1050
-		$charset = trim(strtolower($regs[1]));
1051
-	} else {
1052
-		$charset = '';
1053
-	}
1054
-
1055
-
1056
-	// normaliser les noms du shif-jis japonais
1057
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1058
-		$charset = 'shift-jis';
1059
-	}
1060
-
1061
-	if ($charset) {
1062
-		spip_log("charset: $charset");
1063
-	} else {
1064
-		// valeur par defaut
1065
-		if (is_utf8($texte)) {
1066
-			$charset = 'utf-8';
1067
-		} else {
1068
-			$charset = 'iso-8859-1';
1069
-		}
1070
-		spip_log("charset probable: $charset");
1071
-	}
1072
-
1073
-	return importer_charset($texte, $charset);
1027
+    // Si tout est < 128 pas la peine d'aller plus loin
1028
+    if (is_ascii($texte)) {
1029
+        #spip_log('charset: ascii');
1030
+        return $texte;
1031
+    }
1032
+
1033
+    if (bom_utf8($texte)) {
1034
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
1035
+        $charset = 'utf-8';
1036
+        $texte = substr($texte, 3);
1037
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
1038
+        // charset precise par le contenu (xml)
1039
+        $charset = trim(strtolower($regs[1]));
1040
+    } elseif (
1041
+        // charset precise par le contenu (html)
1042
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
1043
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
1044
+        and false === strpos($regs[2], '#')
1045
+        and $tmp = trim(strtolower($regs[2]))
1046
+    ) {
1047
+        $charset = $tmp;
1048
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
1049
+        // charset de la reponse http
1050
+        $charset = trim(strtolower($regs[1]));
1051
+    } else {
1052
+        $charset = '';
1053
+    }
1054
+
1055
+
1056
+    // normaliser les noms du shif-jis japonais
1057
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
1058
+        $charset = 'shift-jis';
1059
+    }
1060
+
1061
+    if ($charset) {
1062
+        spip_log("charset: $charset");
1063
+    } else {
1064
+        // valeur par defaut
1065
+        if (is_utf8($texte)) {
1066
+            $charset = 'utf-8';
1067
+        } else {
1068
+            $charset = 'iso-8859-1';
1069
+        }
1070
+        spip_log("charset probable: $charset");
1071
+    }
1072
+
1073
+    return importer_charset($texte, $charset);
1074 1074
 }
1075 1075
 
1076 1076
 
@@ -1094,26 +1094,26 @@  discard block
 block discarded – undo
1094 1094
  *     Le texte coupé
1095 1095
  **/
1096 1096
 function spip_substr($c, $start = 0, $length = null) {
1097
-	// Si ce n'est pas utf-8, utiliser substr
1098
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1099
-		if ($length) {
1100
-			return substr($c, $start, $length);
1101
-		} else {
1102
-			substr($c, $start);
1103
-		}
1104
-	}
1105
-
1106
-	// Si utf-8, voir si on dispose de mb_string
1107
-	if (init_mb_string()) {
1108
-		if ($length) {
1109
-			return mb_substr($c, $start, $length);
1110
-		} else {
1111
-			return mb_substr($c, $start);
1112
-		}
1113
-	}
1114
-
1115
-	// Version manuelle (cf. ci-dessous)
1116
-	return spip_substr_manuelle($c, $start, $length);
1097
+    // Si ce n'est pas utf-8, utiliser substr
1098
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1099
+        if ($length) {
1100
+            return substr($c, $start, $length);
1101
+        } else {
1102
+            substr($c, $start);
1103
+        }
1104
+    }
1105
+
1106
+    // Si utf-8, voir si on dispose de mb_string
1107
+    if (init_mb_string()) {
1108
+        if ($length) {
1109
+            return mb_substr($c, $start, $length);
1110
+        } else {
1111
+            return mb_substr($c, $start);
1112
+        }
1113
+    }
1114
+
1115
+    // Version manuelle (cf. ci-dessous)
1116
+    return spip_substr_manuelle($c, $start, $length);
1117 1117
 }
1118 1118
 
1119 1119
 
@@ -1132,40 +1132,40 @@  discard block
 block discarded – undo
1132 1132
  **/
1133 1133
 function spip_substr_manuelle($c, $start, $length = null) {
1134 1134
 
1135
-	// Cas pathologique
1136
-	if ($length === 0) {
1137
-		return '';
1138
-	}
1139
-
1140
-	// S'il y a un demarrage, on se positionne
1141
-	if ($start > 0) {
1142
-		$c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1143
-	} elseif ($start < 0) {
1144
-		return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1145
-	}
1146
-
1147
-	if (!$length) {
1148
-		return $c;
1149
-	}
1150
-
1151
-	if ($length > 0) {
1152
-		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1153
-		// (un caractere utf-8 prenant au maximum n bytes)
1154
-		$n = 0;
1155
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1156
-			;
1157
-		}
1158
-		$c = substr($c, 0, $n * $length);
1159
-		// puis, tant qu'on est trop long, on coupe...
1160
-		while (($l = spip_strlen($c)) > $length) {
1161
-			$c = substr($c, 0, $length - $l);
1162
-		}
1163
-
1164
-		return $c;
1165
-	}
1166
-
1167
-	// $length < 0
1168
-	return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1135
+    // Cas pathologique
1136
+    if ($length === 0) {
1137
+        return '';
1138
+    }
1139
+
1140
+    // S'il y a un demarrage, on se positionne
1141
+    if ($start > 0) {
1142
+        $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start)));
1143
+    } elseif ($start < 0) {
1144
+        return spip_substr_manuelle($c, spip_strlen($c) + $start, $length);
1145
+    }
1146
+
1147
+    if (!$length) {
1148
+        return $c;
1149
+    }
1150
+
1151
+    if ($length > 0) {
1152
+        // on prend n fois la longueur desiree, pour etre surs d'avoir tout
1153
+        // (un caractere utf-8 prenant au maximum n bytes)
1154
+        $n = 0;
1155
+        while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1156
+            ;
1157
+        }
1158
+        $c = substr($c, 0, $n * $length);
1159
+        // puis, tant qu'on est trop long, on coupe...
1160
+        while (($l = spip_strlen($c)) > $length) {
1161
+            $c = substr($c, 0, $length - $l);
1162
+        }
1163
+
1164
+        return $c;
1165
+    }
1166
+
1167
+    // $length < 0
1168
+    return spip_substr_manuelle($c, 0, spip_strlen($c) + $length);
1169 1169
 }
1170 1170
 
1171 1171
 /**
@@ -1179,14 +1179,14 @@  discard block
 block discarded – undo
1179 1179
  *     La chaîne avec une majuscule sur le premier mot
1180 1180
  */
1181 1181
 function spip_ucfirst($c) {
1182
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1183
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1184
-		return ucfirst($c);
1185
-	}
1182
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst
1183
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1184
+        return ucfirst($c);
1185
+    }
1186 1186
 
1187
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1187
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1188 1188
 
1189
-	return $lettre1 . spip_substr($c, 1);
1189
+    return $lettre1 . spip_substr($c, 1);
1190 1190
 }
1191 1191
 
1192 1192
 /**
@@ -1200,12 +1200,12 @@  discard block
 block discarded – undo
1200 1200
  *     La chaîne en minuscules
1201 1201
  */
1202 1202
 function spip_strtolower($c) {
1203
-	// Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower
1204
-	if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1205
-		return strtolower($c);
1206
-	}
1203
+    // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower
1204
+    if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') {
1205
+        return strtolower($c);
1206
+    }
1207 1207
 
1208
-	return mb_strtolower($c);
1208
+    return mb_strtolower($c);
1209 1209
 }
1210 1210
 
1211 1211
 /**
@@ -1219,23 +1219,23 @@  discard block
 block discarded – undo
1219 1219
  *     Longueur de la chaîne
1220 1220
  */
1221 1221
 function spip_strlen($c) {
1222
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1223
-	$c = str_replace("\r\n", "\n", $c);
1224
-
1225
-	// Si ce n'est pas utf-8, utiliser strlen
1226
-	if ($GLOBALS['meta']['charset'] != 'utf-8') {
1227
-		return strlen($c);
1228
-	}
1229
-
1230
-	// Sinon, utiliser mb_strlen() si disponible
1231
-	if (init_mb_string()) {
1232
-		return mb_strlen($c);
1233
-	}
1234
-
1235
-	// Methode manuelle : on supprime les bytes 10......,
1236
-	// on compte donc les ascii (0.......) et les demarrages
1237
-	// de caracteres utf-8 (11......)
1238
-	return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1222
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1223
+    $c = str_replace("\r\n", "\n", $c);
1224
+
1225
+    // Si ce n'est pas utf-8, utiliser strlen
1226
+    if ($GLOBALS['meta']['charset'] != 'utf-8') {
1227
+        return strlen($c);
1228
+    }
1229
+
1230
+    // Sinon, utiliser mb_strlen() si disponible
1231
+    if (init_mb_string()) {
1232
+        return mb_strlen($c);
1233
+    }
1234
+
1235
+    // Methode manuelle : on supprime les bytes 10......,
1236
+    // on compte donc les ascii (0.......) et les demarrages
1237
+    // de caracteres utf-8 (11......)
1238
+    return strlen(preg_replace(',[\x80-\xBF],S', '', $c));
1239 1239
 }
1240 1240
 
1241 1241
 // Initialisation
@@ -1245,16 +1245,16 @@  discard block
 block discarded – undo
1245 1245
 // dans les preg_replace pour ne pas casser certaines lettres accentuees :
1246 1246
 // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
1247 1247
 if (
1248
-	!isset($GLOBALS['meta']['pcre_u'])
1249
-	or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1248
+    !isset($GLOBALS['meta']['pcre_u'])
1249
+    or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
1250 1250
 ) {
1251
-	include_spip('inc/meta');
1252
-	ecrire_meta(
1253
-		'pcre_u',
1254
-		$u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1255
-			and test_pcre_unicode())
1256
-			? 'u' : ''
1257
-	);
1251
+    include_spip('inc/meta');
1252
+    ecrire_meta(
1253
+        'pcre_u',
1254
+        $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8'
1255
+            and test_pcre_unicode())
1256
+            ? 'u' : ''
1257
+    );
1258 1258
 }
1259 1259
 
1260 1260
 
@@ -1270,17 +1270,17 @@  discard block
 block discarded – undo
1270 1270
  *     en unicode : &#128169;
1271 1271
  */
1272 1272
 function utf8_noplanes($x) {
1273
-	$regexp_utf8_4bytes = '/(
1273
+    $regexp_utf8_4bytes = '/(
1274 1274
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1275 1275
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1276 1276
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1277 1277
 )/xS';
1278
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1279
-		foreach ($z[0] as $k) {
1280
-			$ku = utf_8_to_unicode($k);
1281
-			$x = str_replace($k, $ku, $x);
1282
-		}
1283
-	}
1284
-
1285
-	return $x;
1278
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1279
+        foreach ($z[0] as $k) {
1280
+            $ku = utf_8_to_unicode($k);
1281
+            $x = str_replace($k, $ku, $x);
1282
+        }
1283
+    }
1284
+
1285
+    return $x;
1286 1286
 }
Please login to merge, or discard this patch.
Spacing   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		}
74 74
 	}
75 75
 
76
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
76
+	if (find_in_path($charset.'.php', 'charsets/', true)) {
77 77
 		return $charset;
78 78
 	} else {
79 79
 		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	static $pcre_ok = 0;
161 161
 
162 162
 	if (!$pcre_ok) {
163
-		$s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' ';
163
+		$s = ' '.chr(195).chr(169).'t'.chr(195).chr(169).' ';
164 164
 		if (preg_match(',\W...\W,u', $s)) {
165 165
 			$pcre_ok = 1;
166 166
 		} else {
@@ -261,38 +261,38 @@  discard block
 block discarded – undo
261 261
 
262 262
 	if (!isset($trans[$charset][$charset_cible])) {
263 263
 		$trans[$charset][$charset_cible] = [
264
-			$p . chr(128) => '&#8364;',
265
-			$p . chr(129) => ' ', # pas affecte
266
-			$p . chr(130) => '&#8218;',
267
-			$p . chr(131) => '&#402;',
268
-			$p . chr(132) => '&#8222;',
269
-			$p . chr(133) => '&#8230;',
270
-			$p . chr(134) => '&#8224;',
271
-			$p . chr(135) => '&#8225;',
272
-			$p . chr(136) => '&#710;',
273
-			$p . chr(137) => '&#8240;',
274
-			$p . chr(138) => '&#352;',
275
-			$p . chr(139) => '&#8249;',
276
-			$p . chr(140) => '&#338;',
277
-			$p . chr(141) => ' ', # pas affecte
278
-			$p . chr(142) => '&#381;',
279
-			$p . chr(143) => ' ', # pas affecte
280
-			$p . chr(144) => ' ', # pas affecte
281
-			$p . chr(145) => '&#8216;',
282
-			$p . chr(146) => '&#8217;',
283
-			$p . chr(147) => '&#8220;',
284
-			$p . chr(148) => '&#8221;',
285
-			$p . chr(149) => '&#8226;',
286
-			$p . chr(150) => '&#8211;',
287
-			$p . chr(151) => '&#8212;',
288
-			$p . chr(152) => '&#732;',
289
-			$p . chr(153) => '&#8482;',
290
-			$p . chr(154) => '&#353;',
291
-			$p . chr(155) => '&#8250;',
292
-			$p . chr(156) => '&#339;',
293
-			$p . chr(157) => ' ', # pas affecte
294
-			$p . chr(158) => '&#382;',
295
-			$p . chr(159) => '&#376;',
264
+			$p.chr(128) => '&#8364;',
265
+			$p.chr(129) => ' ', # pas affecte
266
+			$p.chr(130) => '&#8218;',
267
+			$p.chr(131) => '&#402;',
268
+			$p.chr(132) => '&#8222;',
269
+			$p.chr(133) => '&#8230;',
270
+			$p.chr(134) => '&#8224;',
271
+			$p.chr(135) => '&#8225;',
272
+			$p.chr(136) => '&#710;',
273
+			$p.chr(137) => '&#8240;',
274
+			$p.chr(138) => '&#352;',
275
+			$p.chr(139) => '&#8249;',
276
+			$p.chr(140) => '&#338;',
277
+			$p.chr(141) => ' ', # pas affecte
278
+			$p.chr(142) => '&#381;',
279
+			$p.chr(143) => ' ', # pas affecte
280
+			$p.chr(144) => ' ', # pas affecte
281
+			$p.chr(145) => '&#8216;',
282
+			$p.chr(146) => '&#8217;',
283
+			$p.chr(147) => '&#8220;',
284
+			$p.chr(148) => '&#8221;',
285
+			$p.chr(149) => '&#8226;',
286
+			$p.chr(150) => '&#8211;',
287
+			$p.chr(151) => '&#8212;',
288
+			$p.chr(152) => '&#732;',
289
+			$p.chr(153) => '&#8482;',
290
+			$p.chr(154) => '&#353;',
291
+			$p.chr(155) => '&#8250;',
292
+			$p.chr(156) => '&#339;',
293
+			$p.chr(157) => ' ', # pas affecte
294
+			$p.chr(158) => '&#382;',
295
+			$p.chr(159) => '&#376;',
296 296
 		];
297 297
 		if ($charset_cible != 'unicode') {
298 298
 			foreach ($trans[$charset][$charset_cible] as $k => $c) {
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 					and is_array($GLOBALS['CHARSET'][$cset])
434 434
 				) {
435 435
 					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
436
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
436
+						$trans[$charset][chr($key)] = '&#'.$val.';';
437 437
 					}
438 438
 				}
439 439
 			}
@@ -500,11 +500,11 @@  discard block
 block discarded – undo
500 500
 					$h = dechex($e);
501 501
 					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
502 502
 						$s = $CHARSET_REVERSE[$charset][$e];
503
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
504
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
503
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
504
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
505 505
 					} else {
506
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
507
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
506
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
507
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
508 508
 					}
509 509
 				}
510 510
 			}
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 				and is_array($GLOBALS['CHARSET'][$cset])
551 551
 			) {
552 552
 				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
553
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
553
+					$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
554 554
 				}
555 555
 			}
556 556
 		}
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
 				}
658 658
 				$thisPos++;
659 659
 			}
660
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
660
+			$encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';';
661 661
 			$encodedString .= $encodedLetter;
662 662
 		}
663 663
 	}
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
701 701
 			else {
702 702
 				if ($word != 65279) {
703
-					$texte .= '&#' . $word . ';';
703
+					$texte .= '&#'.$word.';';
704 704
 				}
705 705
 			}
706 706
 		}
@@ -728,13 +728,13 @@  discard block
 block discarded – undo
728 728
 		return chr($num);
729 729
 	}
730 730
 	if ($num < 2048) {
731
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
731
+		return chr(($num >> 6) + 192).chr(($num & 63) + 128);
732 732
 	}
733 733
 	if ($num < 65536) {
734
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
734
+		return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
735 735
 	}
736 736
 	if ($num < 1114112) {
737
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
737
+		return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
738 738
 	}
739 739
 
740 740
 	return '';
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
 	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
802 802
 		$num = $regs[1];
803 803
 		$vu[$num] = true;
804
-		$s = '\u' . sprintf('%04x', $num);
804
+		$s = '\u'.sprintf('%04x', $num);
805 805
 		$texte = str_replace($regs[0], $s, $texte);
806 806
 	}
807 807
 
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
  **/
819 819
 function javascript_to_unicode($texte) {
820 820
 	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
821
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
821
+		$texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte);
822 822
 	}
823 823
 
824 824
 	return $texte;
@@ -863,7 +863,7 @@  discard block
 block discarded – undo
863 863
 		return $texte;
864 864
 	}
865 865
 
866
-	$table_translit = 'translit' . $complexe;
866
+	$table_translit = 'translit'.$complexe;
867 867
 
868 868
 	// 2. Translitterer grace a la table predefinie
869 869
 	if (!isset($trans[$complexe])) {
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
 	if ($chiffres) {
925 925
 		$texte = preg_replace_callback(
926 926
 			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
927
-			function ($m) {
927
+			function($m) {
928 928
 			return translitteration_chiffree($m[0]);
929 929
 			},
930 930
 			$texte
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
  *    true s'il a un BOM
957 957
  **/
958 958
 function bom_utf8($texte) {
959
-	return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF));
959
+	return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF));
960 960
 }
961 961
 
962 962
 /**
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
 		// on prend n fois la longueur desiree, pour etre surs d'avoir tout
1153 1153
 		// (un caractere utf-8 prenant au maximum n bytes)
1154 1154
 		$n = 0;
1155
-		while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) {
1155
+		while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c)) {
1156 1156
 			;
1157 1157
 		}
1158 1158
 		$c = substr($c, 0, $n * $length);
@@ -1186,7 +1186,7 @@  discard block
 block discarded – undo
1186 1186
 
1187 1187
 	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1188 1188
 
1189
-	return $lettre1 . spip_substr($c, 1);
1189
+	return $lettre1.spip_substr($c, 1);
1190 1190
 }
1191 1191
 
1192 1192
 /**
Please login to merge, or discard this patch.
ecrire/inc/presentation.php 2 patches
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  * @package SPIP\Core\Presentation
17 17
  **/
18 18
 if (!defined('_ECRIRE_INC_VERSION')) {
19
-	return;
19
+    return;
20 20
 }
21 21
 
22 22
 include_spip('inc/presentation_mini');
@@ -32,141 +32,141 @@  discard block
 block discarded – undo
32 32
 
33 33
 // https://code.spip.net/@debut_cadre
34 34
 function debut_cadre($style, $icone = '', $fonction = '', $titre = '', $id = '', $class = '', $padding = true) {
35
-	$style_mapping = [
36
-		'r' => 'simple',
37
-		'e' => 'raccourcis',
38
-		'couleur' => 'basic highlight',
39
-		'couleur-foncee' => 'basic highlight',
40
-		'trait-couleur' => 'important',
41
-		'alerte' => 'notice',
42
-		'info' => 'info',
43
-		'sous_rub' => 'simple sous-rub'
44
-	];
45
-	$style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section'];
46
-	$c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple';
47
-	$class = $c . ($class ? " $class" : '');
48
-	if (!$padding) {
49
-		$class .= ($class ? ' ' : '') . 'no-padding';
50
-	}
51
-
52
-	//($id?"id='$id' ":"")
53
-	if (strlen($icone) > 1) {
54
-		if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
55
-			list($fond, $fonction) = $icone_renommer($icone, $fonction);
56
-		}
57
-		$size = 24;
58
-		if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) {
59
-			$size = $match[1];
60
-		}
61
-		if ($fonction) {
62
-			// 2 images pour composer l'icone : le fond (article) en background,
63
-			// la fonction (new) en image
64
-			$icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" .
65
-				http_style_background($fond, 'no-repeat center center', $size));
66
-		} else {
67
-			$icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'");
68
-		}
69
-		$titre = $icone . $titre;
70
-	}
71
-
72
-	return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id);
35
+    $style_mapping = [
36
+        'r' => 'simple',
37
+        'e' => 'raccourcis',
38
+        'couleur' => 'basic highlight',
39
+        'couleur-foncee' => 'basic highlight',
40
+        'trait-couleur' => 'important',
41
+        'alerte' => 'notice',
42
+        'info' => 'info',
43
+        'sous_rub' => 'simple sous-rub'
44
+    ];
45
+    $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section'];
46
+    $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple';
47
+    $class = $c . ($class ? " $class" : '');
48
+    if (!$padding) {
49
+        $class .= ($class ? ' ' : '') . 'no-padding';
50
+    }
51
+
52
+    //($id?"id='$id' ":"")
53
+    if (strlen($icone) > 1) {
54
+        if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) {
55
+            list($fond, $fonction) = $icone_renommer($icone, $fonction);
56
+        }
57
+        $size = 24;
58
+        if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) {
59
+            $size = $match[1];
60
+        }
61
+        if ($fonction) {
62
+            // 2 images pour composer l'icone : le fond (article) en background,
63
+            // la fonction (new) en image
64
+            $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" .
65
+                http_style_background($fond, 'no-repeat center center', $size));
66
+        } else {
67
+            $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'");
68
+        }
69
+        $titre = $icone . $titre;
70
+    }
71
+
72
+    return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id);
73 73
 }
74 74
 
75 75
 // https://code.spip.net/@fin_cadre
76 76
 function fin_cadre() {
77
- return boite_fermer();
77
+    return boite_fermer();
78 78
 }
79 79
 
80 80
 
81 81
 function debut_cadre_relief(
82
-	$icone = '',
83
-	$dummy = '',
84
-	$fonction = '',
85
-	$titre = '',
86
-	$id = '',
87
-	$class = ''
82
+    $icone = '',
83
+    $dummy = '',
84
+    $fonction = '',
85
+    $titre = '',
86
+    $id = '',
87
+    $class = ''
88 88
 ) {
89
-	return debut_cadre('r', $icone, $fonction, $titre, $id, $class);
89
+    return debut_cadre('r', $icone, $fonction, $titre, $id, $class);
90 90
 }
91 91
 
92 92
 function fin_cadre_relief() {
93
- return fin_cadre('r');
93
+    return fin_cadre('r');
94 94
 }
95 95
 
96 96
 function debut_cadre_enfonce(
97
-	$icone = '',
98
-	$dummy = '',
99
-	$fonction = '',
100
-	$titre = '',
101
-	$id = '',
102
-	$class = ''
97
+    $icone = '',
98
+    $dummy = '',
99
+    $fonction = '',
100
+    $titre = '',
101
+    $id = '',
102
+    $class = ''
103 103
 ) {
104
-	return debut_cadre('e', $icone, $fonction, $titre, $id, $class);
104
+    return debut_cadre('e', $icone, $fonction, $titre, $id, $class);
105 105
 }
106 106
 
107 107
 function fin_cadre_enfonce() {
108
- return fin_cadre('e');
108
+    return fin_cadre('e');
109 109
 }
110 110
 
111 111
 function debut_cadre_sous_rub(
112
-	$icone = '',
113
-	$dummy = '',
114
-	$fonction = '',
115
-	$titre = '',
116
-	$id = '',
117
-	$class = ''
112
+    $icone = '',
113
+    $dummy = '',
114
+    $fonction = '',
115
+    $titre = '',
116
+    $id = '',
117
+    $class = ''
118 118
 ) {
119
-	return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class);
119
+    return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class);
120 120
 }
121 121
 
122 122
 function fin_cadre_sous_rub() {
123
- return fin_cadre('sous_rub');
123
+    return fin_cadre('sous_rub');
124 124
 }
125 125
 
126 126
 function debut_cadre_couleur(
127
-	$icone = '',
128
-	$dummy = '',
129
-	$fonction = '',
130
-	$titre = '',
131
-	$id = '',
132
-	$class = ''
127
+    $icone = '',
128
+    $dummy = '',
129
+    $fonction = '',
130
+    $titre = '',
131
+    $id = '',
132
+    $class = ''
133 133
 ) {
134
-	return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class);
134
+    return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class);
135 135
 }
136 136
 
137 137
 function fin_cadre_couleur() {
138
- return fin_cadre('couleur');
138
+    return fin_cadre('couleur');
139 139
 }
140 140
 
141 141
 function debut_cadre_trait_couleur(
142
-	$icone = '',
143
-	$dummy = '',
144
-	$fonction = '',
145
-	$titre = '',
146
-	$id = '',
147
-	$class = ''
142
+    $icone = '',
143
+    $dummy = '',
144
+    $fonction = '',
145
+    $titre = '',
146
+    $id = '',
147
+    $class = ''
148 148
 ) {
149
-	return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class);
149
+    return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class);
150 150
 }
151 151
 
152 152
 function fin_cadre_trait_couleur() {
153
- return fin_cadre('trait-couleur');
153
+    return fin_cadre('trait-couleur');
154 154
 }
155 155
 
156 156
 function debut_boite_alerte() {
157
- return debut_cadre('alerte', '', '', '', '', '');
157
+    return debut_cadre('alerte', '', '', '', '', '');
158 158
 }
159 159
 
160 160
 function fin_boite_alerte() {
161
- return fin_cadre('alerte');
161
+    return fin_cadre('alerte');
162 162
 }
163 163
 
164 164
 function debut_boite_info() {
165
- return debut_cadre('info', '', '', '', '', '');
165
+    return debut_cadre('info', '', '', '', '', '');
166 166
 }
167 167
 
168 168
 function fin_boite_info() {
169
- return fin_cadre('info');
169
+    return fin_cadre('info');
170 170
 }
171 171
 
172 172
 /**
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
  * @return string Code PHP.
178 178
  **/
179 179
 function gros_titre(
180
-	$titre,
181
-	$ze_logo = ''
180
+    $titre,
181
+    $ze_logo = ''
182 182
 ) {
183
-	return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n";
183
+    return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n";
184 184
 }
185 185
 
186 186
 // La boite des raccourcis
187 187
 // Se place a droite si l'ecran est en mode panoramique.
188 188
 // https://code.spip.net/@bloc_des_raccourcis
189 189
 function bloc_des_raccourcis($bloc) {
190
-	return creer_colonne_droite()
191
-	. boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer();
190
+    return creer_colonne_droite()
191
+    . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer();
192 192
 }
193 193
 
194 194
 //
@@ -199,20 +199,20 @@  discard block
 block discarded – undo
199 199
 // https://code.spip.net/@debut_onglet
200 200
 // @param string $sous_classe	prend la valeur second pour definir les onglet de deuxieme niveau
201 201
 function debut_onglet($classe = 'barre_onglet') {
202
- return "<div class = '$classe clearfix'><ul>\n";
202
+    return "<div class = '$classe clearfix'><ul>\n";
203 203
 }
204 204
 
205 205
 // https://code.spip.net/@fin_onglet
206 206
 function fin_onglet() {
207
- return "</ul></div>\n";
207
+    return "</ul></div>\n";
208 208
 }
209 209
 
210 210
 // https://code.spip.net/@onglet
211 211
 function onglet($texte, $lien, $onglet_ref, $onglet, $icone = '') {
212
-	return '<li>'
213
-	. ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '')
214
-	. lien_ou_expose($lien, $texte, $onglet == $onglet_ref)
215
-	. '</li>';
212
+    return '<li>'
213
+    . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '')
214
+    . lien_ou_expose($lien, $texte, $onglet == $onglet_ref)
215
+    . '</li>';
216 216
 }
217 217
 
218 218
 /**
@@ -244,14 +244,14 @@  discard block
 block discarded – undo
244 244
  *     Code HTML du lien
245 245
  **/
246 246
 function icone_verticale($texte, $lien, $fond, $fonction = '', $align = '', $javascript = '') {
247
-	// cas d'ajax_action_auteur: faut defaire le boulot
248
-	// (il faudrait fusionner avec le cas $javascript)
249
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
250
-		list($x, $lien, $atts, $texte) = $r;
251
-		$javascript .= $atts;
252
-	}
253
-
254
-	return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript);
247
+    // cas d'ajax_action_auteur: faut defaire le boulot
248
+    // (il faudrait fusionner avec le cas $javascript)
249
+    if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
250
+        list($x, $lien, $atts, $texte) = $r;
251
+        $javascript .= $atts;
252
+    }
253
+
254
+    return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript);
255 255
 }
256 256
 
257 257
 /**
@@ -276,15 +276,15 @@  discard block
 block discarded – undo
276 276
  *     Code HTML du lien
277 277
  **/
278 278
 function icone_horizontale($texte, $lien, $fond, $fonction = '', $dummy = '', $javascript = '') {
279
-	$retour = '';
280
-	// cas d'ajax_action_auteur: faut defaire le boulot
281
-	// (il faudrait fusionner avec le cas $javascript)
282
-	if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
283
-		list($x, $lien, $atts, $texte) = $r;
284
-		$javascript .= $atts;
285
-	}
279
+    $retour = '';
280
+    // cas d'ajax_action_auteur: faut defaire le boulot
281
+    // (il faudrait fusionner avec le cas $javascript)
282
+    if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) {
283
+        list($x, $lien, $atts, $texte) = $r;
284
+        $javascript .= $atts;
285
+    }
286 286
 
287
-	$retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript);
287
+    $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript);
288 288
 
289
-	return $retour;
289
+    return $retour;
290 290
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
 	];
45 45
 	$style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section'];
46 46
 	$c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple';
47
-	$class = $c . ($class ? " $class" : '');
47
+	$class = $c.($class ? " $class" : '');
48 48
 	if (!$padding) {
49
-		$class .= ($class ? ' ' : '') . 'no-padding';
49
+		$class .= ($class ? ' ' : '').'no-padding';
50 50
 	}
51 51
 
52 52
 	//($id?"id='$id' ":"")
@@ -61,12 +61,12 @@  discard block
 block discarded – undo
61 61
 		if ($fonction) {
62 62
 			// 2 images pour composer l'icone : le fond (article) en background,
63 63
 			// la fonction (new) en image
64
-			$icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" .
64
+			$icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n".
65 65
 				http_style_background($fond, 'no-repeat center center', $size));
66 66
 		} else {
67 67
 			$icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'");
68 68
 		}
69
-		$titre = $icone . $titre;
69
+		$titre = $icone.$titre;
70 70
 	}
71 71
 
72 72
 	return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id);
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	$titre,
181 181
 	$ze_logo = ''
182 182
 ) {
183
-	return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n";
183
+	return "<h1 class = 'grostitre'>".$ze_logo.' '.typo($titre)."</h1>\n";
184 184
 }
185 185
 
186 186
 // La boite des raccourcis
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 // https://code.spip.net/@bloc_des_raccourcis
189 189
 function bloc_des_raccourcis($bloc) {
190 190
 	return creer_colonne_droite()
191
-	. boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer();
191
+	. boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis').$bloc.boite_fermer();
192 192
 }
193 193
 
194 194
 //
Please login to merge, or discard this patch.
ecrire/inc/prepare_recherche.php 2 patches
Indentation   +140 added lines, -140 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
 include_spip('inc/rechercher');
24 24
 if (!defined('_DELAI_CACHE_resultats')) {
25
-	define('_DELAI_CACHE_resultats', 600);
25
+    define('_DELAI_CACHE_resultats', 600);
26 26
 }
27 27
 
28 28
 /**
@@ -49,127 +49,127 @@  discard block
 block discarded – undo
49 49
  * @return array
50 50
  */
51 51
 function inc_prepare_recherche_dist(
52
-	$recherche,
53
-	$table = 'articles',
54
-	$cond = false,
55
-	$serveur = '',
56
-	$modificateurs = [],
57
-	$primary = ''
52
+    $recherche,
53
+    $table = 'articles',
54
+    $cond = false,
55
+    $serveur = '',
56
+    $modificateurs = [],
57
+    $primary = ''
58 58
 ) {
59
-	static $cache = [];
60
-	$delai_fraicheur = min(
61
-		_DELAI_CACHE_resultats,
62
-		time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)
63
-	);
64
-
65
-	// si recherche n'est pas dans le contexte, on va prendre en globals
66
-	// ca permet de faire des inclure simple.
67
-	if (!isset($recherche) and isset($GLOBALS['recherche'])) {
68
-		$recherche = $GLOBALS['recherche'];
69
-	}
70
-
71
-	// traiter le cas {recherche?}
72
-	if ($cond and !strlen($recherche)) {
73
-		return [
74
-			'0 as points' /* as points */, /* where */
75
-			''
76
-		];
77
-	}
78
-
79
-
80
-	$rechercher = false;
81
-
82
-	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
83
-	if (!isset($cache[$serveur][$table][$recherche])) {
84
-		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
85
-		$hash = substr(md5($recherche . $table), 0, 16);
86
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
87
-		$row = sql_fetsel(
88
-			'recherche',
89
-			'spip_resultats AS resultats',
90
-			$where . " AND $where_resultat_recent",
91
-			'',
92
-			'',
93
-			'0,1'
94
-		);
95
-		if (
96
-			!$row
97
-			or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
98
-		) {
99
-			$rechercher = true;
100
-		}
101
-	}
102
-
103
-	// si on n'a pas encore traite les donnees dans une boucle precedente
104
-	if ($rechercher) {
105
-		//$tables = liste_des_champs();
106
-		$x = objet_type($table);
107
-		$points = recherche_en_base(
108
-			$recherche,
109
-			$x,
110
-			[
111
-				'score' => true,
112
-				'toutvoir' => true,
113
-				'jointures' => true
114
-			],
115
-			$serveur
116
-		);
117
-		// pas de résultat, pas de point
118
-		$points = isset($points[$x]) ? $points[$x] : [];
119
-
120
-		// permettre aux plugins de modifier le resultat
121
-		$points = pipeline('prepare_recherche', [
122
-			'args' => [
123
-				'type' => $x,
124
-				'recherche' => $recherche,
125
-				'serveur' => $serveur,
126
-				'modificateurs' => $modificateurs
127
-			],
128
-			'data' => $points
129
-		]);
130
-
131
-		// supprimer les anciens resultats de cette recherche
132
-		// et les resultats trop vieux avec une marge
133
-		// pas de AS resultats dans un delete (mysql)
134
-		$whered = str_replace(
135
-			['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
136
-			['recherche', 'table_objet', 'serveur'],
137
-			$where
138
-		);
139
-
140
-		sql_delete(
141
-			'spip_resultats',
142
-			"NOT($where_resultat_recent) OR ($whered)"
143
-		);
144
-
145
-		// inserer les resultats dans la table de cache des resultats
146
-		if (count($points)) {
147
-			$tab_couples = [];
148
-			foreach ($points as $id => $p) {
149
-				$tab_couples[] = [
150
-					'recherche' => $hash,
151
-					'id' => $id,
152
-					'points' => $p['score'],
153
-					'table_objet' => $table,
154
-					'serveur' => $hash_serv,
155
-				];
156
-			}
157
-			sql_insertq_multi('spip_resultats', $tab_couples, []);
158
-		}
159
-	}
160
-
161
-	if (!isset($cache[$serveur][$table][$recherche])) {
162
-		if (!$serveur) {
163
-			$cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
164
-		} else {
165
-			if (sql_countsel('spip_resultats as resultats', $where)) {
166
-				$rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
167
-			}
168
-			$cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
169
-		}
170
-	}
171
-
172
-	return $cache[$serveur][$table][$recherche];
59
+    static $cache = [];
60
+    $delai_fraicheur = min(
61
+        _DELAI_CACHE_resultats,
62
+        time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0)
63
+    );
64
+
65
+    // si recherche n'est pas dans le contexte, on va prendre en globals
66
+    // ca permet de faire des inclure simple.
67
+    if (!isset($recherche) and isset($GLOBALS['recherche'])) {
68
+        $recherche = $GLOBALS['recherche'];
69
+    }
70
+
71
+    // traiter le cas {recherche?}
72
+    if ($cond and !strlen($recherche)) {
73
+        return [
74
+            '0 as points' /* as points */, /* where */
75
+            ''
76
+        ];
77
+    }
78
+
79
+
80
+    $rechercher = false;
81
+
82
+    $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
83
+    if (!isset($cache[$serveur][$table][$recherche])) {
84
+        $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
85
+        $hash = substr(md5($recherche . $table), 0, 16);
86
+        $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
87
+        $row = sql_fetsel(
88
+            'recherche',
89
+            'spip_resultats AS resultats',
90
+            $where . " AND $where_resultat_recent",
91
+            '',
92
+            '',
93
+            '0,1'
94
+        );
95
+        if (
96
+            !$row
97
+            or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')
98
+        ) {
99
+            $rechercher = true;
100
+        }
101
+    }
102
+
103
+    // si on n'a pas encore traite les donnees dans une boucle precedente
104
+    if ($rechercher) {
105
+        //$tables = liste_des_champs();
106
+        $x = objet_type($table);
107
+        $points = recherche_en_base(
108
+            $recherche,
109
+            $x,
110
+            [
111
+                'score' => true,
112
+                'toutvoir' => true,
113
+                'jointures' => true
114
+            ],
115
+            $serveur
116
+        );
117
+        // pas de résultat, pas de point
118
+        $points = isset($points[$x]) ? $points[$x] : [];
119
+
120
+        // permettre aux plugins de modifier le resultat
121
+        $points = pipeline('prepare_recherche', [
122
+            'args' => [
123
+                'type' => $x,
124
+                'recherche' => $recherche,
125
+                'serveur' => $serveur,
126
+                'modificateurs' => $modificateurs
127
+            ],
128
+            'data' => $points
129
+        ]);
130
+
131
+        // supprimer les anciens resultats de cette recherche
132
+        // et les resultats trop vieux avec une marge
133
+        // pas de AS resultats dans un delete (mysql)
134
+        $whered = str_replace(
135
+            ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'],
136
+            ['recherche', 'table_objet', 'serveur'],
137
+            $where
138
+        );
139
+
140
+        sql_delete(
141
+            'spip_resultats',
142
+            "NOT($where_resultat_recent) OR ($whered)"
143
+        );
144
+
145
+        // inserer les resultats dans la table de cache des resultats
146
+        if (count($points)) {
147
+            $tab_couples = [];
148
+            foreach ($points as $id => $p) {
149
+                $tab_couples[] = [
150
+                    'recherche' => $hash,
151
+                    'id' => $id,
152
+                    'points' => $p['score'],
153
+                    'table_objet' => $table,
154
+                    'serveur' => $hash_serv,
155
+                ];
156
+            }
157
+            sql_insertq_multi('spip_resultats', $tab_couples, []);
158
+        }
159
+    }
160
+
161
+    if (!isset($cache[$serveur][$table][$recherche])) {
162
+        if (!$serveur) {
163
+            $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where];
164
+        } else {
165
+            if (sql_countsel('spip_resultats as resultats', $where)) {
166
+                $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where);
167
+            }
168
+            $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur);
169
+        }
170
+    }
171
+
172
+    return $cache[$serveur][$table][$recherche];
173 173
 }
174 174
 
175 175
 
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
  * @return array
186 186
  */
187 187
 function generer_select_where_explicites($table, $primary, $rows, $serveur) {
188
-	# calculer le {id_article IN()} et le {... as points}
189
-	if (!count($rows)) {
190
-		return ["''", '0=1'];
191
-	} else {
192
-		$listes_ids = [];
193
-		$select = '0';
194
-		foreach ($rows as $r) {
195
-			$listes_ids[$r['points']][] = $r['id'];
196
-		}
197
-
198
-		foreach ($listes_ids as $p => $ids) {
199
-			$select .= "+$p*(" .
200
-				sql_in("$table.$primary", $ids, '', $serveur)
201
-				. ') ';
202
-		}
203
-
204
-		return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
205
-	}
188
+    # calculer le {id_article IN()} et le {... as points}
189
+    if (!count($rows)) {
190
+        return ["''", '0=1'];
191
+    } else {
192
+        $listes_ids = [];
193
+        $select = '0';
194
+        foreach ($rows as $r) {
195
+            $listes_ids[$r['points']][] = $r['id'];
196
+        }
197
+
198
+        foreach ($listes_ids as $p => $ids) {
199
+            $select .= "+$p*(" .
200
+                sql_in("$table.$primary", $ids, '', $serveur)
201
+                . ') ';
202
+        }
203
+
204
+        return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)];
205
+    }
206 206
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -82,12 +82,12 @@  discard block
 block discarded – undo
82 82
 	$where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND');
83 83
 	if (!isset($cache[$serveur][$table][$recherche])) {
84 84
 		$hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : '');
85
-		$hash = substr(md5($recherche . $table), 0, 16);
86
-		$where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')";
85
+		$hash = substr(md5($recherche.$table), 0, 16);
86
+		$where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')";
87 87
 		$row = sql_fetsel(
88 88
 			'recherche',
89 89
 			'spip_resultats AS resultats',
90
-			$where . " AND $where_resultat_recent",
90
+			$where." AND $where_resultat_recent",
91 91
 			'',
92 92
 			'',
93 93
 			'0,1'
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 		}
197 197
 
198 198
 		foreach ($listes_ids as $p => $ids) {
199
-			$select .= "+$p*(" .
199
+			$select .= "+$p*(".
200 200
 				sql_in("$table.$primary", $ids, '', $serveur)
201 201
 				. ') ';
202 202
 		}
Please login to merge, or discard this patch.
ecrire/inc/exporter_csv.php 3 patches
Indentation   +114 added lines, -114 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
 include_spip('inc/charsets');
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
  * @return string
33 33
  */
34 34
 function exporter_csv_champ($champ) {
35
-	#$champ = str_replace("\r", "\n", $champ);
36
-	#$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
-	#$champ = str_replace("\n", ", ", $champ);
38
-	$champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
-	$champ = str_replace('"', '""', $champ);
35
+    #$champ = str_replace("\r", "\n", $champ);
36
+    #$champ = preg_replace(",[\n]+,ms", "\n", $champ);
37
+    #$champ = str_replace("\n", ", ", $champ);
38
+    $champ = preg_replace(',[\s]+,ms', ' ', $champ);
39
+    $champ = str_replace('"', '""', $champ);
40 40
 
41
-	return '"' . $champ . '"';
41
+    return '"' . $champ . '"';
42 42
 }
43 43
 
44 44
 /**
@@ -55,15 +55,15 @@  discard block
 block discarded – undo
55 55
  * @return string
56 56
  */
57 57
 function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, $callback = null) {
58
-	if ($callback) {
59
-		$ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset);
60
-	}
61
-	$output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
-	if ($importer_charset) {
63
-		$output = str_replace('’', '\'', $output);
64
-		$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
-	}
66
-	return $output;
58
+    if ($callback) {
59
+        $ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset);
60
+    }
61
+    $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
62
+    if ($importer_charset) {
63
+        $output = str_replace('’', '\'', $output);
64
+        $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
65
+    }
66
+    return $output;
67 67
 }
68 68
 
69 69
 /**
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
  * @return string
76 76
  */
77 77
 function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) {
78
-	return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
78
+    return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset);
79 79
 }
80 80
 
81 81
 /**
@@ -101,101 +101,101 @@  discard block
 block discarded – undo
101 101
  */
102 102
 function inc_exporter_csv_dist($titre, $resource, $options = []) {
103 103
 
104
-	// support ancienne syntaxe
105
-	// inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
-	if (is_string($options)) {
107
-		$args = func_get_args();
108
-		$options = [];
109
-		foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
-			if (!empty($args[$k])) {
111
-				$options[$option] = $args[$k];
112
-			}
113
-		}
114
-	}
115
-
116
-	$default_options = [
117
-		'delim' => ', ',
118
-		'entetes' => null,
119
-		'envoyer' => true,
120
-		'charset' => null,
121
-		'callback' => null,
122
-	];
123
-	$options = array_merge($default_options, $options);
124
-
125
-	$filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
-
127
-	if ($options['delim'] == 'TAB') {
128
-		$options['delim'] = "\t";
129
-	}
130
-	if (!in_array($options['delim'], [',', ';', "\t"])) {
131
-		$options['delim'] = ',';
132
-	}
133
-
134
-	$charset = $GLOBALS['meta']['charset'];
135
-	$importer_charset = null;
136
-	if ($options['delim'] == ',') {
137
-		$extension = 'csv';
138
-	} else {
139
-		$extension = 'xls';
140
-		# Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
-		$charset = 'iso-8859-1';
142
-	}
143
-	// mais si une option charset est explicite, elle a la priorite
144
-	if (!empty($options['charset'])) {
145
-		$charset = $options['charset'];
146
-	}
147
-
148
-	$importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
-
150
-	$filename = "$filename.$extension";
151
-
152
-	$output = '';
153
-	$nb = 0;
154
-	if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
-		$output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
-	}
157
-	// les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
-	$nb++;
159
-
160
-	if ($options['envoyer']) {
161
-		$disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
-		header("Content-Type: text/comma-separated-values; charset=$charset");
163
-		header("Content-Disposition: $disposition; filename=$filename");
164
-
165
-		// Vider tous les tampons
166
-		$level = @ob_get_level();
167
-		while ($level--) {
168
-			@ob_end_flush();
169
-		}
170
-	}
171
-
172
-	// si envoyer=='attachment' on passe par un fichier temporaire
173
-	// sinon on ecrit directement sur stdout
174
-	if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
-		$fichier = 'php://output';
176
-	}
177
-	else {
178
-	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
-	}
180
-
181
-	$fp = fopen($fichier, 'w');
182
-	$length = fwrite($fp, $output);
183
-
184
-	while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
-		$output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
-		$length += fwrite($fp, $output);
187
-		$nb++;
188
-	}
189
-	fclose($fp);
190
-
191
-	if ($options['envoyer']) {
192
-		if ($options['envoyer'] === 'attachment') {
193
-			header("Content-Length: $length");
194
-			readfile($fichier);
195
-		}
196
-		// si on a envoye inline, c'est deja tout bon
197
-		exit;
198
-	}
199
-
200
-	return $fichier;
104
+    // support ancienne syntaxe
105
+    // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true)
106
+    if (is_string($options)) {
107
+        $args = func_get_args();
108
+        $options = [];
109
+        foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) {
110
+            if (!empty($args[$k])) {
111
+                $options[$option] = $args[$k];
112
+            }
113
+        }
114
+    }
115
+
116
+    $default_options = [
117
+        'delim' => ', ',
118
+        'entetes' => null,
119
+        'envoyer' => true,
120
+        'charset' => null,
121
+        'callback' => null,
122
+    ];
123
+    $options = array_merge($default_options, $options);
124
+
125
+    $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre))));
126
+
127
+    if ($options['delim'] == 'TAB') {
128
+        $options['delim'] = "\t";
129
+    }
130
+    if (!in_array($options['delim'], [',', ';', "\t"])) {
131
+        $options['delim'] = ',';
132
+    }
133
+
134
+    $charset = $GLOBALS['meta']['charset'];
135
+    $importer_charset = null;
136
+    if ($options['delim'] == ',') {
137
+        $extension = 'csv';
138
+    } else {
139
+        $extension = 'xls';
140
+        # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut
141
+        $charset = 'iso-8859-1';
142
+    }
143
+    // mais si une option charset est explicite, elle a la priorite
144
+    if (!empty($options['charset'])) {
145
+        $charset = $options['charset'];
146
+    }
147
+
148
+    $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset);
149
+
150
+    $filename = "$filename.$extension";
151
+
152
+    $output = '';
153
+    $nb = 0;
154
+    if (!empty($options['entetes']) and is_array($options['entetes'])) {
155
+        $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']);
156
+    }
157
+    // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes
158
+    $nb++;
159
+
160
+    if ($options['envoyer']) {
161
+        $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline');
162
+        header("Content-Type: text/comma-separated-values; charset=$charset");
163
+        header("Content-Disposition: $disposition; filename=$filename");
164
+
165
+        // Vider tous les tampons
166
+        $level = @ob_get_level();
167
+        while ($level--) {
168
+            @ob_end_flush();
169
+        }
170
+    }
171
+
172
+    // si envoyer=='attachment' on passe par un fichier temporaire
173
+    // sinon on ecrit directement sur stdout
174
+    if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175
+        $fichier = 'php://output';
176
+    }
177
+    else {
178
+    $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179
+    }
180
+
181
+    $fp = fopen($fichier, 'w');
182
+    $length = fwrite($fp, $output);
183
+
184
+    while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) {
185
+        $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']);
186
+        $length += fwrite($fp, $output);
187
+        $nb++;
188
+    }
189
+    fclose($fp);
190
+
191
+    if ($options['envoyer']) {
192
+        if ($options['envoyer'] === 'attachment') {
193
+            header("Content-Length: $length");
194
+            readfile($fichier);
195
+        }
196
+        // si on a envoye inline, c'est deja tout bon
197
+        exit;
198
+    }
199
+
200
+    return $fichier;
201 201
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	$champ = preg_replace(',[\s]+,ms', ' ', $champ);
39 39
 	$champ = str_replace('"', '""', $champ);
40 40
 
41
-	return '"' . $champ . '"';
41
+	return '"'.$champ.'"';
42 42
 }
43 43
 
44 44
 /**
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
 	if ($callback) {
59 59
 		$ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset);
60 60
 	}
61
-	$output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n";
61
+	$output = join($delim, array_map('exporter_csv_champ', $ligne))."\r\n";
62 62
 	if ($importer_charset) {
63 63
 		$output = str_replace('’', '\'', $output);
64 64
 		$output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset);
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 		$fichier = 'php://output';
176 176
 	}
177 177
 	else {
178
-	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
178
+	$fichier = sous_repertoire(_DIR_CACHE, 'export').$filename;
179 179
 	}
180 180
 
181 181
 	$fp = fopen($fichier, 'w');
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -173,8 +173,7 @@
 block discarded – undo
173 173
 	// sinon on ecrit directement sur stdout
174 174
 	if ($options['envoyer'] and $options['envoyer'] !== 'attachment') {
175 175
 		$fichier = 'php://output';
176
-	}
177
-	else {
176
+	} else {
178 177
 	$fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename;
179 178
 	}
180 179
 
Please login to merge, or discard this patch.
ecrire/inc/rechercher.php 2 patches
Indentation   +317 added lines, -317 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
 defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext');
@@ -35,22 +35,22 @@  discard block
 block discarded – undo
35 35
  * @return array Couples (type d'objet => Couples (champ => score))
36 36
  */
37 37
 function liste_des_champs() {
38
-	static $liste = null;
39
-	if (is_null($liste)) {
40
-		$liste = [];
41
-		// recuperer les tables_objets_sql declarees
42
-		include_spip('base/objets');
43
-		$tables_objets = lister_tables_objets_sql();
44
-		foreach ($tables_objets as $t => $infos) {
45
-			if ($infos['rechercher_champs']) {
46
-				$liste[$infos['type']] = $infos['rechercher_champs'];
47
-			}
48
-		}
49
-		// puis passer dans le pipeline
50
-		$liste = pipeline('rechercher_liste_des_champs', $liste);
51
-	}
52
-
53
-	return $liste;
38
+    static $liste = null;
39
+    if (is_null($liste)) {
40
+        $liste = [];
41
+        // recuperer les tables_objets_sql declarees
42
+        include_spip('base/objets');
43
+        $tables_objets = lister_tables_objets_sql();
44
+        foreach ($tables_objets as $t => $infos) {
45
+            if ($infos['rechercher_champs']) {
46
+                $liste[$infos['type']] = $infos['rechercher_champs'];
47
+            }
48
+        }
49
+        // puis passer dans le pipeline
50
+        $liste = pipeline('rechercher_liste_des_champs', $liste);
51
+    }
52
+
53
+    return $liste;
54 54
 }
55 55
 
56 56
 
@@ -58,176 +58,176 @@  discard block
 block discarded – undo
58 58
 // en ne regardant que le titre ou le nom
59 59
 // https://code.spip.net/@liste_des_jointures
60 60
 function liste_des_jointures() {
61
-	static $liste = null;
62
-	if (is_null($liste)) {
63
-		$liste = [];
64
-		// recuperer les tables_objets_sql declarees
65
-		include_spip('base/objets');
66
-		$tables_objets = lister_tables_objets_sql();
67
-		foreach ($tables_objets as $t => $infos) {
68
-			if ($infos['rechercher_jointures']) {
69
-				$liste[$infos['type']] = $infos['rechercher_jointures'];
70
-			}
71
-		}
72
-		// puis passer dans le pipeline
73
-		$liste = pipeline('rechercher_liste_des_jointures', $liste);
74
-	}
75
-
76
-	return $liste;
61
+    static $liste = null;
62
+    if (is_null($liste)) {
63
+        $liste = [];
64
+        // recuperer les tables_objets_sql declarees
65
+        include_spip('base/objets');
66
+        $tables_objets = lister_tables_objets_sql();
67
+        foreach ($tables_objets as $t => $infos) {
68
+            if ($infos['rechercher_jointures']) {
69
+                $liste[$infos['type']] = $infos['rechercher_jointures'];
70
+            }
71
+        }
72
+        // puis passer dans le pipeline
73
+        $liste = pipeline('rechercher_liste_des_jointures', $liste);
74
+    }
75
+
76
+    return $liste;
77 77
 }
78 78
 
79 79
 function expression_recherche($recherche, $options) {
80
-	// ne calculer qu'une seule fois l'expression par hit
81
-	// (meme si utilisee dans plusieurs boucles)
82
-	static $expression = [];
83
-	$key = serialize([$recherche, $options['preg_flags']]);
84
-	if (isset($expression[$key])) {
85
-		return $expression[$key];
86
-	}
87
-
88
-	$u = $GLOBALS['meta']['pcre_u'];
89
-	if ($u and strpos($options['preg_flags'], $u) === false) {
90
-		$options['preg_flags'] .= $u;
91
-	}
92
-	include_spip('inc/charsets');
93
-	$recherche = trim($recherche);
94
-
95
-	// retirer les + de +truc et les * de truc*
96
-	$recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
97
-	$recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
98
-
99
-	$is_preg = false;
100
-	if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
101
-		// c'est une preg
102
-		$recherche_trans = translitteration($recherche);
103
-		$preg = $recherche_trans . $options['preg_flags'];
104
-		$is_preg = true;
105
-	} else {
106
-		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
107
-		// sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
108
-		// 'une', 'des' ...)
109
-
110
-		// attention : plusieurs mots entre guillemets sont a rechercher tels quels
111
-		$recherche_trans = $recherche_mod = $recherche_org = $recherche;
112
-
113
-		// les expressions entre " " sont un mot a chercher tel quel
114
-		// -> on remplace les espaces par un \x1 et on enleve les guillemets
115
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
116
-			foreach ($matches as $match) {
117
-				$word = preg_replace(',\s+,Uims', "\x1", $match);
118
-				$word = trim($word, '"');
119
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
120
-			}
121
-		}
122
-
123
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
124
-			$is_preg = true;
125
-
126
-			$recherche_inter = '|';
127
-			$recherche_mots = explode(' ', $recherche_mod);
128
-			$min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
129
-			$petits_mots = true;
130
-			foreach ($recherche_mots as $mot) {
131
-				if (strlen($mot) >= $min_long) {
132
-					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
133
-					$recherche_inter .= preg_quote($mot) . ' ';
134
-					$petits_mots = false;
135
-				}
136
-			}
137
-			$recherche_inter = str_replace("\x1", '\s', $recherche_inter);
138
-
139
-			// mais on cherche quand même l'expression complète, même si elle
140
-			// comporte des mots de moins de quatre lettres
141
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
142
-			if (!$recherche or $petits_mots) {
143
-				$recherche = preg_quote($recherche_org);
144
-			}
145
-			$recherche_trans = translitteration($recherche);
146
-		}
147
-
148
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
149
-	}
150
-
151
-	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
152
-	// ou si l'expression reguliere est invalide
153
-	if (
154
-		!$is_preg
155
-		or (@preg_match($preg, '') === false)
156
-	) {
157
-		$methode = 'LIKE';
158
-		$u = $GLOBALS['meta']['pcre_u'];
159
-
160
-		// echapper les % et _
161
-		$q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
162
-
163
-		// eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
164
-		$recherche = preg_quote($recherche, '/');
165
-		$recherche_trans = translitteration($recherche);
166
-		$recherche_mod = $recherche_trans;
167
-
168
-		// les expressions entre " " sont un mot a chercher tel quel
169
-		// -> on remplace les espaces par un _ et on enleve les guillemets
170
-		// corriger le like dans le $q
171
-		if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
172
-			foreach ($matches as $match) {
173
-				$word = preg_replace(',\s+,Uims', '_', $match);
174
-				$word = trim($word, '"');
175
-				$q = str_replace($match, $word, $q);
176
-			}
177
-		}
178
-		// corriger la regexp
179
-		if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
180
-			foreach ($matches as $match) {
181
-				$word = preg_replace(',\s+,Uims', '[\s]', $match);
182
-				$word = trim($word, '"');
183
-				$recherche_mod = str_replace($match, $word, $recherche_mod);
184
-			}
185
-		}
186
-		$q = sql_quote(
187
-			'%'
188
-			. preg_replace(',\s+,' . $u, '%', $q)
189
-			. '%'
190
-		);
191
-
192
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
193
-	} else {
194
-		$methode = 'REGEXP';
195
-		$q = sql_quote(trim($recherche, '/'));
196
-	}
197
-
198
-	// tous les caracteres transliterables de $q sont remplaces par un joker
199
-	// permet de matcher en SQL meme si on est sensible aux accents (SQLite)
200
-	$q_t = $q;
201
-	for ($i = 0; $i < spip_strlen($q); $i++) {
202
-		$char = spip_substr($q, $i, 1);
203
-		if (
204
-			!is_ascii($char)
205
-			and $char_t = translitteration($char)
206
-			and $char_t !== $char
207
-		) {
208
-			// on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
209
-			// mais c'est un pis aller cf #4354
210
-			$q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
211
-		}
212
-	}
213
-
214
-	$q = $q_t;
215
-
216
-	// fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
217
-	// les plus frequents qui peuvent etre accentues
218
-	// (oui c'est tres dicustable...)
219
-	if (
220
-		isset($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'])
221
-		and strncmp($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'], 'sqlite', 6) == 0
222
-	) {
223
-		$q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
224
-		// si il reste au moins un char significatif...
225
-		if (preg_match(",[^'%_.],", $q_t)) {
226
-			$q = $q_t;
227
-		}
228
-	}
229
-
230
-	return $expression[$key] = [$methode, $q, $preg];
80
+    // ne calculer qu'une seule fois l'expression par hit
81
+    // (meme si utilisee dans plusieurs boucles)
82
+    static $expression = [];
83
+    $key = serialize([$recherche, $options['preg_flags']]);
84
+    if (isset($expression[$key])) {
85
+        return $expression[$key];
86
+    }
87
+
88
+    $u = $GLOBALS['meta']['pcre_u'];
89
+    if ($u and strpos($options['preg_flags'], $u) === false) {
90
+        $options['preg_flags'] .= $u;
91
+    }
92
+    include_spip('inc/charsets');
93
+    $recherche = trim($recherche);
94
+
95
+    // retirer les + de +truc et les * de truc*
96
+    $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche);
97
+    $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche);
98
+
99
+    $is_preg = false;
100
+    if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
101
+        // c'est une preg
102
+        $recherche_trans = translitteration($recherche);
103
+        $preg = $recherche_trans . $options['preg_flags'];
104
+        $is_preg = true;
105
+    } else {
106
+        // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
107
+        // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un',
108
+        // 'une', 'des' ...)
109
+
110
+        // attention : plusieurs mots entre guillemets sont a rechercher tels quels
111
+        $recherche_trans = $recherche_mod = $recherche_org = $recherche;
112
+
113
+        // les expressions entre " " sont un mot a chercher tel quel
114
+        // -> on remplace les espaces par un \x1 et on enleve les guillemets
115
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
116
+            foreach ($matches as $match) {
117
+                $word = preg_replace(',\s+,Uims', "\x1", $match);
118
+                $word = trim($word, '"');
119
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
120
+            }
121
+        }
122
+
123
+        if (preg_match(',\s+,' . $u, $recherche_mod)) {
124
+            $is_preg = true;
125
+
126
+            $recherche_inter = '|';
127
+            $recherche_mots = explode(' ', $recherche_mod);
128
+            $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4;
129
+            $petits_mots = true;
130
+            foreach ($recherche_mots as $mot) {
131
+                if (strlen($mot) >= $min_long) {
132
+                    // echapper les caracteres de regexp qui sont eventuellement dans la recherche
133
+                    $recherche_inter .= preg_quote($mot) . ' ';
134
+                    $petits_mots = false;
135
+                }
136
+            }
137
+            $recherche_inter = str_replace("\x1", '\s', $recherche_inter);
138
+
139
+            // mais on cherche quand même l'expression complète, même si elle
140
+            // comporte des mots de moins de quatre lettres
141
+            $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
142
+            if (!$recherche or $petits_mots) {
143
+                $recherche = preg_quote($recherche_org);
144
+            }
145
+            $recherche_trans = translitteration($recherche);
146
+        }
147
+
148
+        $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
149
+    }
150
+
151
+    // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
152
+    // ou si l'expression reguliere est invalide
153
+    if (
154
+        !$is_preg
155
+        or (@preg_match($preg, '') === false)
156
+    ) {
157
+        $methode = 'LIKE';
158
+        $u = $GLOBALS['meta']['pcre_u'];
159
+
160
+        // echapper les % et _
161
+        $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche));
162
+
163
+        // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses
164
+        $recherche = preg_quote($recherche, '/');
165
+        $recherche_trans = translitteration($recherche);
166
+        $recherche_mod = $recherche_trans;
167
+
168
+        // les expressions entre " " sont un mot a chercher tel quel
169
+        // -> on remplace les espaces par un _ et on enleve les guillemets
170
+        // corriger le like dans le $q
171
+        if (preg_match(',["][^"]+["],Uims', $q, $matches)) {
172
+            foreach ($matches as $match) {
173
+                $word = preg_replace(',\s+,Uims', '_', $match);
174
+                $word = trim($word, '"');
175
+                $q = str_replace($match, $word, $q);
176
+            }
177
+        }
178
+        // corriger la regexp
179
+        if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) {
180
+            foreach ($matches as $match) {
181
+                $word = preg_replace(',\s+,Uims', '[\s]', $match);
182
+                $word = trim($word, '"');
183
+                $recherche_mod = str_replace($match, $word, $recherche_mod);
184
+            }
185
+        }
186
+        $q = sql_quote(
187
+            '%'
188
+            . preg_replace(',\s+,' . $u, '%', $q)
189
+            . '%'
190
+        );
191
+
192
+        $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
193
+    } else {
194
+        $methode = 'REGEXP';
195
+        $q = sql_quote(trim($recherche, '/'));
196
+    }
197
+
198
+    // tous les caracteres transliterables de $q sont remplaces par un joker
199
+    // permet de matcher en SQL meme si on est sensible aux accents (SQLite)
200
+    $q_t = $q;
201
+    for ($i = 0; $i < spip_strlen($q); $i++) {
202
+        $char = spip_substr($q, $i, 1);
203
+        if (
204
+            !is_ascii($char)
205
+            and $char_t = translitteration($char)
206
+            and $char_t !== $char
207
+        ) {
208
+            // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes
209
+            // mais c'est un pis aller cf #4354
210
+            $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t);
211
+        }
212
+    }
213
+
214
+    $q = $q_t;
215
+
216
+    // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres
217
+    // les plus frequents qui peuvent etre accentues
218
+    // (oui c'est tres dicustable...)
219
+    if (
220
+        isset($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'])
221
+        and strncmp($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'], 'sqlite', 6) == 0
222
+    ) {
223
+        $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______');
224
+        // si il reste au moins un char significatif...
225
+        if (preg_match(",[^'%_.],", $q_t)) {
226
+            $q = $q_t;
227
+        }
228
+    }
229
+
230
+    return $expression[$key] = [$methode, $q, $preg];
231 231
 }
232 232
 
233 233
 
@@ -254,143 +254,143 @@  discard block
 block discarded – undo
254 254
  * @return array
255 255
  */
256 256
 function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') {
257
-	include_spip('base/abstract_sql');
258
-
259
-	if (!is_array($tables)) {
260
-		$liste = liste_des_champs();
261
-
262
-		if (
263
-			is_string($tables)
264
-			and $tables != ''
265
-		) {
266
-			$toutes = [];
267
-			foreach (explode(',', $tables) as $t) {
268
-				$t = trim($t);
269
-				if (isset($liste[$t])) {
270
-					$toutes[$t] = $liste[$t];
271
-				}
272
-			}
273
-			$tables = $toutes;
274
-			unset($toutes);
275
-		} else {
276
-			$tables = $liste;
277
-		}
278
-	}
279
-
280
-	if (!strlen($recherche) or !count($tables)) {
281
-		return [];
282
-	}
283
-
284
-	include_spip('inc/autoriser');
285
-
286
-	// options par defaut
287
-	$options = array_merge(
288
-		[
289
-		'preg_flags' => 'UimsS',
290
-		'toutvoir' => false,
291
-		'champs' => false,
292
-		'score' => false,
293
-		'matches' => false,
294
-		'jointures' => false,
295
-		'serveur' => $serveur
296
-		],
297
-		$options
298
-	);
299
-
300
-	$results = [];
301
-
302
-	// Utiliser l'iterateur (DATA:recherche)
303
-	// pour recuperer les couples (id_objet, score)
304
-	// Le resultat est au format {
305
-	//      id1 = { 'score' => x, attrs => { } },
306
-	//      id2 = { 'score' => x, attrs => { } },
307
-	// }
308
-
309
-	include_spip('inc/recherche_to_array');
310
-
311
-	foreach ($tables as $table => $champs) {
312
-		# lock via memoization, si dispo
313
-		if (function_exists('cache_lock')) {
314
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
315
-		}
316
-
317
-		spip_timer('rech');
318
-
319
-		# TODO : ici plutot charger un iterateur via l'API iterateurs
320
-		$to_array = charger_fonction('recherche_to_array', 'inc');
321
-		$results[$table] = $to_array(
322
-			$recherche,
323
-			array_merge($options, ['table' => $table, 'champs' => $champs])
324
-		);
325
-		##var_dump($results[$table]);
326
-
327
-
328
-		spip_log(
329
-			"recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'),
330
-			'recherche'
331
-		);
332
-
333
-		if (isset($lock)) {
334
-			cache_unlock($lock);
335
-		}
336
-	}
337
-
338
-	return $results;
257
+    include_spip('base/abstract_sql');
258
+
259
+    if (!is_array($tables)) {
260
+        $liste = liste_des_champs();
261
+
262
+        if (
263
+            is_string($tables)
264
+            and $tables != ''
265
+        ) {
266
+            $toutes = [];
267
+            foreach (explode(',', $tables) as $t) {
268
+                $t = trim($t);
269
+                if (isset($liste[$t])) {
270
+                    $toutes[$t] = $liste[$t];
271
+                }
272
+            }
273
+            $tables = $toutes;
274
+            unset($toutes);
275
+        } else {
276
+            $tables = $liste;
277
+        }
278
+    }
279
+
280
+    if (!strlen($recherche) or !count($tables)) {
281
+        return [];
282
+    }
283
+
284
+    include_spip('inc/autoriser');
285
+
286
+    // options par defaut
287
+    $options = array_merge(
288
+        [
289
+        'preg_flags' => 'UimsS',
290
+        'toutvoir' => false,
291
+        'champs' => false,
292
+        'score' => false,
293
+        'matches' => false,
294
+        'jointures' => false,
295
+        'serveur' => $serveur
296
+        ],
297
+        $options
298
+    );
299
+
300
+    $results = [];
301
+
302
+    // Utiliser l'iterateur (DATA:recherche)
303
+    // pour recuperer les couples (id_objet, score)
304
+    // Le resultat est au format {
305
+    //      id1 = { 'score' => x, attrs => { } },
306
+    //      id2 = { 'score' => x, attrs => { } },
307
+    // }
308
+
309
+    include_spip('inc/recherche_to_array');
310
+
311
+    foreach ($tables as $table => $champs) {
312
+        # lock via memoization, si dispo
313
+        if (function_exists('cache_lock')) {
314
+            cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
315
+        }
316
+
317
+        spip_timer('rech');
318
+
319
+        # TODO : ici plutot charger un iterateur via l'API iterateurs
320
+        $to_array = charger_fonction('recherche_to_array', 'inc');
321
+        $results[$table] = $to_array(
322
+            $recherche,
323
+            array_merge($options, ['table' => $table, 'champs' => $champs])
324
+        );
325
+        ##var_dump($results[$table]);
326
+
327
+
328
+        spip_log(
329
+            "recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'),
330
+            'recherche'
331
+        );
332
+
333
+        if (isset($lock)) {
334
+            cache_unlock($lock);
335
+        }
336
+    }
337
+
338
+    return $results;
339 339
 }
340 340
 
341 341
 
342 342
 // Effectue une recherche sur toutes les tables de la base de donnees
343 343
 // https://code.spip.net/@remplace_en_base
344 344
 function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) {
345
-	include_spip('inc/modifier');
346
-
347
-	// options par defaut
348
-	$options = array_merge(
349
-		[
350
-		'preg_flags' => 'UimsS',
351
-		'toutmodifier' => false
352
-		],
353
-		$options
354
-	);
355
-	$options['champs'] = true;
356
-
357
-
358
-	if (!is_array($tables)) {
359
-		$tables = liste_des_champs();
360
-	}
361
-
362
-	$results = recherche_en_base($recherche, $tables, $options);
363
-
364
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
365
-
366
-	foreach ($results as $table => $r) {
367
-		$_id_table = id_table_objet($table);
368
-		foreach ($r as $id => $x) {
369
-			if (
370
-				$options['toutmodifier']
371
-				or autoriser('modifier', $table, $id)
372
-			) {
373
-				$modifs = [];
374
-				foreach ($x['champs'] as $key => $val) {
375
-					if ($key == $_id_table) {
376
-						continue;
377
-					}
378
-					$repl = preg_replace($preg, $remplace, $val);
379
-					if ($repl <> $val) {
380
-						$modifs[$key] = $repl;
381
-					}
382
-				}
383
-				if ($modifs) {
384
-					objet_modifier_champs(
385
-						$table,
386
-						$id,
387
-						[
388
-							'champs' => array_keys($modifs),
389
-						],
390
-						$modifs
391
-					);
392
-				}
393
-			}
394
-		}
395
-	}
345
+    include_spip('inc/modifier');
346
+
347
+    // options par defaut
348
+    $options = array_merge(
349
+        [
350
+        'preg_flags' => 'UimsS',
351
+        'toutmodifier' => false
352
+        ],
353
+        $options
354
+    );
355
+    $options['champs'] = true;
356
+
357
+
358
+    if (!is_array($tables)) {
359
+        $tables = liste_des_champs();
360
+    }
361
+
362
+    $results = recherche_en_base($recherche, $tables, $options);
363
+
364
+    $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
365
+
366
+    foreach ($results as $table => $r) {
367
+        $_id_table = id_table_objet($table);
368
+        foreach ($r as $id => $x) {
369
+            if (
370
+                $options['toutmodifier']
371
+                or autoriser('modifier', $table, $id)
372
+            ) {
373
+                $modifs = [];
374
+                foreach ($x['champs'] as $key => $val) {
375
+                    if ($key == $_id_table) {
376
+                        continue;
377
+                    }
378
+                    $repl = preg_replace($preg, $remplace, $val);
379
+                    if ($repl <> $val) {
380
+                        $modifs[$key] = $repl;
381
+                    }
382
+                }
383
+                if ($modifs) {
384
+                    objet_modifier_champs(
385
+                        $table,
386
+                        $id,
387
+                        [
388
+                            'champs' => array_keys($modifs),
389
+                        ],
390
+                        $modifs
391
+                    );
392
+                }
393
+            }
394
+        }
395
+    }
396 396
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) {
101 101
 		// c'est une preg
102 102
 		$recherche_trans = translitteration($recherche);
103
-		$preg = $recherche_trans . $options['preg_flags'];
103
+		$preg = $recherche_trans.$options['preg_flags'];
104 104
 		$is_preg = true;
105 105
 	} else {
106 106
 		// s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP,
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 			}
121 121
 		}
122 122
 
123
-		if (preg_match(',\s+,' . $u, $recherche_mod)) {
123
+		if (preg_match(',\s+,'.$u, $recherche_mod)) {
124 124
 			$is_preg = true;
125 125
 
126 126
 			$recherche_inter = '|';
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 			foreach ($recherche_mots as $mot) {
131 131
 				if (strlen($mot) >= $min_long) {
132 132
 					// echapper les caracteres de regexp qui sont eventuellement dans la recherche
133
-					$recherche_inter .= preg_quote($mot) . ' ';
133
+					$recherche_inter .= preg_quote($mot).' ';
134 134
 					$petits_mots = false;
135 135
 				}
136 136
 			}
@@ -138,14 +138,14 @@  discard block
 block discarded – undo
138 138
 
139 139
 			// mais on cherche quand même l'expression complète, même si elle
140 140
 			// comporte des mots de moins de quatre lettres
141
-			$recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|');
141
+			$recherche = trim(preg_replace(',\s+,'.$u, '|', $recherche_inter), '|');
142 142
 			if (!$recherche or $petits_mots) {
143 143
 				$recherche = preg_quote($recherche_org);
144 144
 			}
145 145
 			$recherche_trans = translitteration($recherche);
146 146
 		}
147 147
 
148
-		$preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags'];
148
+		$preg = '/'.str_replace('/', '\\/', $recherche_trans).'/'.$options['preg_flags'];
149 149
 	}
150 150
 
151 151
 	// Si la chaine est inactive, on va utiliser LIKE pour aller plus vite
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 		}
186 186
 		$q = sql_quote(
187 187
 			'%'
188
-			. preg_replace(',\s+,' . $u, '%', $q)
188
+			. preg_replace(',\s+,'.$u, '%', $q)
189 189
 			. '%'
190 190
 		);
191 191
 
192
-		$preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags'];
192
+		$preg = '/'.preg_replace(',\s+,'.$u, '.+', trim($recherche_mod)).'/'.$options['preg_flags'];
193 193
 	} else {
194 194
 		$methode = 'REGEXP';
195 195
 		$q = sql_quote(trim($recherche, '/'));
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 	foreach ($tables as $table => $champs) {
312 312
 		# lock via memoization, si dispo
313 313
 		if (function_exists('cache_lock')) {
314
-			cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche);
314
+			cache_lock($lock = _RECHERCHE_LOCK_KEY.' '.$table.' '.$recherche);
315 315
 		}
316 316
 
317 317
 		spip_timer('rech');
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
 
327 327
 
328 328
 		spip_log(
329
-			"recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'),
329
+			"recherche $table ($recherche) : ".count($results[$table]).' resultats '.spip_timer('rech'),
330 330
 			'recherche'
331 331
 		);
332 332
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 
362 362
 	$results = recherche_en_base($recherche, $tables, $options);
363 363
 
364
-	$preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags'];
364
+	$preg = '/'.str_replace('/', '\\/', $recherche).'/'.$options['preg_flags'];
365 365
 
366 366
 	foreach ($results as $table => $r) {
367 367
 		$_id_table = id_table_objet($table);
Please login to merge, or discard this patch.
ecrire/inc/modifier.php 2 patches
Indentation   +248 added lines, -248 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
 /**
@@ -39,28 +39,28 @@  discard block
 block discarded – undo
39 39
  *     Tableau des champs et valeurs collectées
40 40
  */
41 41
 function collecter_requests($white_list, $black_list = [], $set = null, $tous = false) {
42
-	$c = $set;
43
-	if (!$c) {
44
-		$c = [];
45
-		foreach ($white_list as $champ) {
46
-			// on ne collecte que les champs reellement envoyes par defaut.
47
-			// le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
-			$val = _request($champ);
49
-			if ($tous or $val !== null) {
50
-				$c[$champ] = $val;
51
-			}
52
-		}
53
-		// on ajoute toujours la lang en saisie possible
54
-		// meme si pas prevu au depart pour l'objet concerne
55
-		if ($l = _request('changer_lang')) {
56
-			$c['lang'] = $l;
57
-		}
58
-	}
59
-	foreach ($black_list as $champ) {
60
-		unset($c[$champ]);
61
-	}
62
-
63
-	return $c;
42
+    $c = $set;
43
+    if (!$c) {
44
+        $c = [];
45
+        foreach ($white_list as $champ) {
46
+            // on ne collecte que les champs reellement envoyes par defaut.
47
+            // le cas d'un envoi de valeur NULL peut du coup poser probleme.
48
+            $val = _request($champ);
49
+            if ($tous or $val !== null) {
50
+                $c[$champ] = $val;
51
+            }
52
+        }
53
+        // on ajoute toujours la lang en saisie possible
54
+        // meme si pas prevu au depart pour l'objet concerne
55
+        if ($l = _request('changer_lang')) {
56
+            $c['lang'] = $l;
57
+        }
58
+    }
59
+    foreach ($black_list as $champ) {
60
+        unset($c[$champ]);
61
+    }
62
+
63
+    return $c;
64 64
 }
65 65
 
66 66
 /**
@@ -97,229 +97,229 @@  discard block
 block discarded – undo
97 97
  *     - chaîne : Texte d'un message d'erreur
98 98
  */
99 99
 function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') {
100
-	if (!$id_objet = intval($id_objet)) {
101
-		spip_log('Erreur $id_objet non defini', 'warn');
102
-
103
-		return _T('erreur_technique_enregistrement_impossible');
104
-	}
105
-
106
-	include_spip('inc/filtres');
107
-
108
-	$table_objet = table_objet($objet, $serveur);
109
-	$spip_table_objet = table_objet_sql($objet, $serveur);
110
-	$id_table_objet = id_table_objet($objet, $serveur);
111
-	$trouver_table = charger_fonction('trouver_table', 'base');
112
-	$desc = $trouver_table($spip_table_objet, $serveur);
113
-
114
-	// Appels incomplets (sans $c)
115
-	if (!is_array($c)) {
116
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
-
118
-		return _T('erreur_technique_enregistrement_impossible');
119
-	}
120
-
121
-	// Securite : certaines variables ne sont jamais acceptees ici
122
-	// car elles ne relevent pas de autoriser(xxx, modifier) ;
123
-	// il faut passer par instituer_XX()
124
-	// TODO: faut-il passer ces variables interdites
125
-	// dans un fichier de description separe ?
126
-	unset($c['statut']);
127
-	unset($c['id_parent']);
128
-	unset($c['id_rubrique']);
129
-	unset($c['id_secteur']);
130
-
131
-	// Gerer les champs non vides
132
-	if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
-		foreach ($options['nonvide'] as $champ => $sinon) {
134
-			if (isset($c[$champ]) and $c[$champ] === '') {
135
-				$c[$champ] = $sinon;
136
-			}
137
-		}
138
-	}
139
-
140
-
141
-	// N'accepter que les champs qui existent
142
-	// TODO: ici aussi on peut valider les contenus
143
-	// en fonction du type
144
-	$champs = [];
145
-	foreach ($desc['field'] as $champ => $ignore) {
146
-		if (isset($c[$champ])) {
147
-			$champs[$champ] = $c[$champ];
148
-		}
149
-	}
150
-
151
-	// Nettoyer les valeurs
152
-	$champs = array_map('corriger_caracteres', $champs);
153
-
154
-	// Envoyer aux plugins
155
-	$champs = pipeline(
156
-		'pre_edition',
157
-		[
158
-			'args' => [
159
-				'table' => $spip_table_objet, // compatibilite
160
-				'table_objet' => $table_objet,
161
-				'spip_table_objet' => $spip_table_objet,
162
-				'desc' => $desc,
163
-				'type' => $objet,
164
-				'id_objet' => $id_objet,
165
-				'data' => isset($options['data']) ? $options['data'] : null,
166
-				'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] c'est quoi ?
167
-				'serveur' => $serveur,
168
-				'action' => isset($options['action']) ? $options['action'] : 'modifier'
169
-			],
170
-			'data' => $champs
171
-		]
172
-	);
173
-
174
-	if (!$champs) {
175
-		return false;
176
-	}
177
-
178
-
179
-	// marquer le fait que l'objet est travaille par toto a telle date
180
-	if ($GLOBALS['meta']['articles_modif'] != 'non') {
181
-		include_spip('inc/drapeau_edition');
182
-		signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
183
-	}
184
-
185
-	// Verifier si les mises a jour sont pertinentes, datees, en conflit etc
186
-	include_spip('inc/editer');
187
-	if (!isset($options['data']) or is_null($options['data'])) {
188
-		$options['data'] = &$_POST;
189
-	}
190
-	$conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
191
-	// cas hypothetique : normalement inc/editer verifie en amont le conflit edition
192
-	// et gere l'interface
193
-	// ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
194
-	if ($conflits) {
195
-		return _T('titre_conflit_edition');
196
-	}
197
-
198
-	if ($champs) {
199
-		// cas particulier de la langue : passer par instituer_langue_objet
200
-		if (isset($champs['lang'])) {
201
-			if ($changer_lang = $champs['lang']) {
202
-				$id_rubrique = 0;
203
-				if (isset($desc['field']['id_rubrique'])) {
204
-					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
205
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
206
-				}
207
-				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
208
-				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
209
-			}
210
-			// on laisse 'lang' dans $champs,
211
-			// ca permet de passer dans le pipeline post_edition et de journaliser
212
-			// et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
213
-			// deja pris en compte
214
-		}
215
-
216
-		// la modif peut avoir lieu
217
-
218
-		// faut-il ajouter date_modif ?
219
-		if (
220
-			isset($options['date_modif']) and $options['date_modif']
221
-			and !isset($champs[$options['date_modif']])
222
-		) {
223
-			$champs[$options['date_modif']] = date('Y-m-d H:i:s');
224
-		}
225
-
226
-		// allez on commit la modif
227
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur);
228
-
229
-		// on verifie si elle est bien passee
230
-		$moof = sql_fetsel(
231
-			array_keys($champs),
232
-			$spip_table_objet,
233
-			"$id_table_objet=" . intval($id_objet),
234
-			[],
235
-			[],
236
-			'',
237
-			[],
238
-			$serveur
239
-		);
240
-		// si difference entre les champs, reperer les champs mal enregistres
241
-		if ($moof != $champs) {
242
-			$liste = [];
243
-			foreach ($moof as $k => $v) {
244
-				if (
245
-					$v !== $champs[$k]
246
-					// ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
247
-					and (!is_numeric($v) or intval($v) !== intval($champs[$k]))
248
-					// ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
249
-					and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
250
-				) {
251
-					$liste[] = $k;
252
-					$conflits[$k]['post'] = $champs[$k];
253
-					$conflits[$k]['save'] = $v;
254
-
255
-					// cas specifique MySQL+emoji : si l'un est la
256
-					// conversion utf8_noplanes de l'autre alors c'est OK
257
-					if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
258
-						include_spip('inc/charsets');
259
-						if ($v == utf8_noplanes($champs[$k])) {
260
-							array_pop($liste);
261
-						}
262
-					}
263
-				}
264
-			}
265
-			// si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
266
-			// c'est un cas exceptionnel
267
-			if (count($liste)) {
268
-				spip_log(
269
-					"Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
270
-					'modifier.' . _LOG_CRITIQUE
271
-				);
272
-
273
-				return _T(
274
-					'erreur_technique_enregistrement_champs',
275
-					['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
276
-				);
277
-			}
278
-		}
279
-
280
-		// Invalider les caches
281
-		if (isset($options['invalideur']) and $options['invalideur']) {
282
-			include_spip('inc/invalideur');
283
-			if (is_array($options['invalideur'])) {
284
-				array_map('suivre_invalideur', $options['invalideur']);
285
-			} else {
286
-				suivre_invalideur($options['invalideur']);
287
-			}
288
-		}
289
-
290
-		// Notifications, gestion des revisions...
291
-		// en standard, appelle |nouvelle_revision ci-dessous
292
-		pipeline(
293
-			'post_edition',
294
-			[
295
-				'args' => [
296
-					'table' => $spip_table_objet,
297
-					'table_objet' => $table_objet,
298
-					'spip_table_objet' => $spip_table_objet,
299
-					'desc' => $desc,
300
-					'type' => $objet,
301
-					'id_objet' => $id_objet,
302
-					'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] kesako ?
303
-					'serveur' => $serveur,
304
-					'action' => isset($options['action']) ? $options['action'] : 'modifier'
305
-				],
306
-				'data' => $champs
307
-			]
308
-		);
309
-	}
310
-
311
-	// journaliser l'affaire
312
-	// message a affiner :-)
313
-	include_spip('inc/filtres_mini');
314
-	$qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip'];
315
-	journal(_L($qui . ' a &#233;dit&#233; l&#8217;' . $objet . ' ' . $id_objet . ' (' . join(
316
-		'+',
317
-		array_diff(array_keys($champs), ['date_modif'])
318
-	) . ')'), [
319
-		'faire' => 'modifier',
320
-		'quoi' => $objet,
321
-		'id' => $id_objet
322
-	]);
323
-
324
-	return '';
100
+    if (!$id_objet = intval($id_objet)) {
101
+        spip_log('Erreur $id_objet non defini', 'warn');
102
+
103
+        return _T('erreur_technique_enregistrement_impossible');
104
+    }
105
+
106
+    include_spip('inc/filtres');
107
+
108
+    $table_objet = table_objet($objet, $serveur);
109
+    $spip_table_objet = table_objet_sql($objet, $serveur);
110
+    $id_table_objet = id_table_objet($objet, $serveur);
111
+    $trouver_table = charger_fonction('trouver_table', 'base');
112
+    $desc = $trouver_table($spip_table_objet, $serveur);
113
+
114
+    // Appels incomplets (sans $c)
115
+    if (!is_array($c)) {
116
+        spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
117
+
118
+        return _T('erreur_technique_enregistrement_impossible');
119
+    }
120
+
121
+    // Securite : certaines variables ne sont jamais acceptees ici
122
+    // car elles ne relevent pas de autoriser(xxx, modifier) ;
123
+    // il faut passer par instituer_XX()
124
+    // TODO: faut-il passer ces variables interdites
125
+    // dans un fichier de description separe ?
126
+    unset($c['statut']);
127
+    unset($c['id_parent']);
128
+    unset($c['id_rubrique']);
129
+    unset($c['id_secteur']);
130
+
131
+    // Gerer les champs non vides
132
+    if (isset($options['nonvide']) and is_array($options['nonvide'])) {
133
+        foreach ($options['nonvide'] as $champ => $sinon) {
134
+            if (isset($c[$champ]) and $c[$champ] === '') {
135
+                $c[$champ] = $sinon;
136
+            }
137
+        }
138
+    }
139
+
140
+
141
+    // N'accepter que les champs qui existent
142
+    // TODO: ici aussi on peut valider les contenus
143
+    // en fonction du type
144
+    $champs = [];
145
+    foreach ($desc['field'] as $champ => $ignore) {
146
+        if (isset($c[$champ])) {
147
+            $champs[$champ] = $c[$champ];
148
+        }
149
+    }
150
+
151
+    // Nettoyer les valeurs
152
+    $champs = array_map('corriger_caracteres', $champs);
153
+
154
+    // Envoyer aux plugins
155
+    $champs = pipeline(
156
+        'pre_edition',
157
+        [
158
+            'args' => [
159
+                'table' => $spip_table_objet, // compatibilite
160
+                'table_objet' => $table_objet,
161
+                'spip_table_objet' => $spip_table_objet,
162
+                'desc' => $desc,
163
+                'type' => $objet,
164
+                'id_objet' => $id_objet,
165
+                'data' => isset($options['data']) ? $options['data'] : null,
166
+                'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] c'est quoi ?
167
+                'serveur' => $serveur,
168
+                'action' => isset($options['action']) ? $options['action'] : 'modifier'
169
+            ],
170
+            'data' => $champs
171
+        ]
172
+    );
173
+
174
+    if (!$champs) {
175
+        return false;
176
+    }
177
+
178
+
179
+    // marquer le fait que l'objet est travaille par toto a telle date
180
+    if ($GLOBALS['meta']['articles_modif'] != 'non') {
181
+        include_spip('inc/drapeau_edition');
182
+        signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet);
183
+    }
184
+
185
+    // Verifier si les mises a jour sont pertinentes, datees, en conflit etc
186
+    include_spip('inc/editer');
187
+    if (!isset($options['data']) or is_null($options['data'])) {
188
+        $options['data'] = &$_POST;
189
+    }
190
+    $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur);
191
+    // cas hypothetique : normalement inc/editer verifie en amont le conflit edition
192
+    // et gere l'interface
193
+    // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme
194
+    if ($conflits) {
195
+        return _T('titre_conflit_edition');
196
+    }
197
+
198
+    if ($champs) {
199
+        // cas particulier de la langue : passer par instituer_langue_objet
200
+        if (isset($champs['lang'])) {
201
+            if ($changer_lang = $champs['lang']) {
202
+                $id_rubrique = 0;
203
+                if (isset($desc['field']['id_rubrique'])) {
204
+                    $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
205
+                    $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
206
+                }
207
+                $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
208
+                $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
209
+            }
210
+            // on laisse 'lang' dans $champs,
211
+            // ca permet de passer dans le pipeline post_edition et de journaliser
212
+            // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir
213
+            // deja pris en compte
214
+        }
215
+
216
+        // la modif peut avoir lieu
217
+
218
+        // faut-il ajouter date_modif ?
219
+        if (
220
+            isset($options['date_modif']) and $options['date_modif']
221
+            and !isset($champs[$options['date_modif']])
222
+        ) {
223
+            $champs[$options['date_modif']] = date('Y-m-d H:i:s');
224
+        }
225
+
226
+        // allez on commit la modif
227
+        sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur);
228
+
229
+        // on verifie si elle est bien passee
230
+        $moof = sql_fetsel(
231
+            array_keys($champs),
232
+            $spip_table_objet,
233
+            "$id_table_objet=" . intval($id_objet),
234
+            [],
235
+            [],
236
+            '',
237
+            [],
238
+            $serveur
239
+        );
240
+        // si difference entre les champs, reperer les champs mal enregistres
241
+        if ($moof != $champs) {
242
+            $liste = [];
243
+            foreach ($moof as $k => $v) {
244
+                if (
245
+                    $v !== $champs[$k]
246
+                    // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes
247
+                    and (!is_numeric($v) or intval($v) !== intval($champs[$k]))
248
+                    // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle
249
+                    and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00']))
250
+                ) {
251
+                    $liste[] = $k;
252
+                    $conflits[$k]['post'] = $champs[$k];
253
+                    $conflits[$k]['save'] = $v;
254
+
255
+                    // cas specifique MySQL+emoji : si l'un est la
256
+                    // conversion utf8_noplanes de l'autre alors c'est OK
257
+                    if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) {
258
+                        include_spip('inc/charsets');
259
+                        if ($v == utf8_noplanes($champs[$k])) {
260
+                            array_pop($liste);
261
+                        }
262
+                    }
263
+                }
264
+            }
265
+            // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur
266
+            // c'est un cas exceptionnel
267
+            if (count($liste)) {
268
+                spip_log(
269
+                    "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
270
+                    'modifier.' . _LOG_CRITIQUE
271
+                );
272
+
273
+                return _T(
274
+                    'erreur_technique_enregistrement_champs',
275
+                    ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
276
+                );
277
+            }
278
+        }
279
+
280
+        // Invalider les caches
281
+        if (isset($options['invalideur']) and $options['invalideur']) {
282
+            include_spip('inc/invalideur');
283
+            if (is_array($options['invalideur'])) {
284
+                array_map('suivre_invalideur', $options['invalideur']);
285
+            } else {
286
+                suivre_invalideur($options['invalideur']);
287
+            }
288
+        }
289
+
290
+        // Notifications, gestion des revisions...
291
+        // en standard, appelle |nouvelle_revision ci-dessous
292
+        pipeline(
293
+            'post_edition',
294
+            [
295
+                'args' => [
296
+                    'table' => $spip_table_objet,
297
+                    'table_objet' => $table_objet,
298
+                    'spip_table_objet' => $spip_table_objet,
299
+                    'desc' => $desc,
300
+                    'type' => $objet,
301
+                    'id_objet' => $id_objet,
302
+                    'champs' => isset($options['champs']) ? $options['champs'] : [], // [doc] kesako ?
303
+                    'serveur' => $serveur,
304
+                    'action' => isset($options['action']) ? $options['action'] : 'modifier'
305
+                ],
306
+                'data' => $champs
307
+            ]
308
+        );
309
+    }
310
+
311
+    // journaliser l'affaire
312
+    // message a affiner :-)
313
+    include_spip('inc/filtres_mini');
314
+    $qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip'];
315
+    journal(_L($qui . ' a &#233;dit&#233; l&#8217;' . $objet . ' ' . $id_objet . ' (' . join(
316
+        '+',
317
+        array_diff(array_keys($champs), ['date_modif'])
318
+    ) . ')'), [
319
+        'faire' => 'modifier',
320
+        'quoi' => $objet,
321
+        'id' => $id_objet
322
+    ]);
323
+
324
+    return '';
325 325
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
 
114 114
 	// Appels incomplets (sans $c)
115 115
 	if (!is_array($c)) {
116
-		spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c');
116
+		spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c');
117 117
 
118 118
 		return _T('erreur_technique_enregistrement_impossible');
119 119
 	}
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 				$id_rubrique = 0;
203 203
 				if (isset($desc['field']['id_rubrique'])) {
204 204
 					$parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique';
205
-					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet));
205
+					$id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet));
206 206
 				}
207 207
 				$instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action');
208 208
 				$champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur);
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 		}
225 225
 
226 226
 		// allez on commit la modif
227
-		sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), $serveur);
227
+		sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), $serveur);
228 228
 
229 229
 		// on verifie si elle est bien passee
230 230
 		$moof = sql_fetsel(
231 231
 			array_keys($champs),
232 232
 			$spip_table_objet,
233
-			"$id_table_objet=" . intval($id_objet),
233
+			"$id_table_objet=".intval($id_objet),
234 234
 			[],
235 235
 			[],
236 236
 			'',
@@ -266,13 +266,13 @@  discard block
 block discarded – undo
266 266
 			// c'est un cas exceptionnel
267 267
 			if (count($liste)) {
268 268
 				spip_log(
269
-					"Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true),
270
-					'modifier.' . _LOG_CRITIQUE
269
+					"Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true),
270
+					'modifier.'._LOG_CRITIQUE
271 271
 				);
272 272
 
273 273
 				return _T(
274 274
 					'erreur_technique_enregistrement_champs',
275
-					['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"]
275
+					['champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"]
276 276
 				);
277 277
 			}
278 278
 		}
@@ -312,10 +312,10 @@  discard block
 block discarded – undo
312 312
 	// message a affiner :-)
313 313
 	include_spip('inc/filtres_mini');
314 314
 	$qui = isset($GLOBALS['visiteur_session']['nom']) and $GLOBALS['visiteur_session']['nom'] ? $GLOBALS['visiteur_session']['nom'] : $GLOBALS['ip'];
315
-	journal(_L($qui . ' a &#233;dit&#233; l&#8217;' . $objet . ' ' . $id_objet . ' (' . join(
315
+	journal(_L($qui.' a &#233;dit&#233; l&#8217;'.$objet.' '.$id_objet.' ('.join(
316 316
 		'+',
317 317
 		array_diff(array_keys($champs), ['date_modif'])
318
-	) . ')'), [
318
+	).')'), [
319 319
 		'faire' => 'modifier',
320 320
 		'quoi' => $objet,
321 321
 		'id' => $id_objet
Please login to merge, or discard this patch.
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.