Completed
Push — master ( fb0017...92433c )
by cam
01:14
created
ecrire/public/styliser_par_z.php 2 patches
Indentation   +319 added lines, -319 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  * @package SPIP\Core\Public\Styliser
20 20
  **/
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -29,193 +29,193 @@  discard block
 block discarded – undo
29 29
  * @return array Données modifiées du pipeline
30 30
  */
31 31
 function public_styliser_par_z_dist($flux) {
32
-	static $prefix_path = null;
33
-	static $prefix_length;
34
-	static $z_blocs;
35
-	static $apl_constant;
36
-	static $page;
37
-	static $disponible = [];
38
-	static $echafauder;
39
-	static $prepend = '';
40
-
41
-	if (!isset($prefix_path)) {
42
-		$z_blocs = z_blocs(test_espace_prive());
43
-		if (test_espace_prive()) {
44
-			$prefix_path = 'prive/squelettes/';
45
-			$prefix_length = strlen($prefix_path);
46
-			$apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD';
47
-			$page = 'exec';
48
-			$echafauder = charger_fonction('echafauder', 'prive', true);
49
-			define('_ZCORE_EXCLURE_PATH', '');
50
-		} else {
51
-			$prefix_path = '';
52
-			$prefix_length = 0;
53
-			$apl_constant = '_Z_AJAX_PARALLEL_LOAD';
54
-			$page = _SPIP_PAGE;
55
-			$echafauder = charger_fonction('echafauder', 'public', true);
56
-			define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(
57
-				_DIR_PLUGIN_DIST,
58
-				'/'
59
-			) : ''));
60
-		}
61
-		$prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : '');
62
-	}
63
-	$z_contenu = reset($z_blocs); // contenu par defaut
64
-
65
-	$fond = $flux['args']['fond'];
66
-
67
-	if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) {
68
-		$fond = substr($fond, $prefix_length);
69
-		$squelette = $flux['data'];
70
-		$ext = $flux['args']['ext'];
71
-		// Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax
72
-		if (
73
-			defined('_Z_AJAX_PARALLEL_LOAD_OK')
74
-			and $dir = explode('/', $fond)
75
-			and count($dir) == 2 // pas un sous repertoire
76
-			and $dir = reset($dir)
77
-			and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z
78
-			and defined($apl_constant)
79
-			and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL
80
-			and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL
81
-		) {
82
-			$flux['data'] = $pipe;
83
-
84
-			return $flux;
85
-		}
86
-
87
-		// surcharger aussi les squelettes venant de squelettes-dist/
88
-		if ($squelette and !z_fond_valide($squelette)) {
89
-			$squelette = '';
90
-			$echafauder = '';
91
-		}
92
-		if ($prepend) {
93
-			$squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext"));
94
-			if ($squelette) {
95
-				$flux['data'] = $squelette;
96
-			}
97
-		}
98
-
99
-		// gerer les squelettes non trouves
100
-		// -> router vers les /dist.html
101
-		// ou scaffolding ou page automatique les contenus
102
-		if (!$squelette) {
103
-			// si on est sur un ?page=XX non trouve
104
-			if (
105
-				(isset($flux['args']['contexte'][$page])
106
-					and $flux['args']['contexte'][$page] == $fond)
107
-				or (isset($flux['args']['contexte']['type-page'])
108
-					and $flux['args']['contexte']['type-page'] == $fond)
109
-				or ($fond == 'sommaire'
110
-					and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page]))
111
-			) {
112
-				// si on est sur un ?page=XX non trouve
113
-				// se brancher sur contenu/xx si il existe
114
-				// ou si c'est un objet spip, associe a une table, utiliser le fond homonyme
115
-				if (!isset($disponible[$fond])) {
116
-					$disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder);
117
-				}
118
-
119
-				if ($disponible[$fond]) {
120
-					$flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext"));
121
-				}
122
-			}
123
-
124
-			// echafaudage :
125
-			// si c'est un fond de contenu d'un objet en base
126
-			// generer un fond automatique a la volee pour les webmestres
127
-			elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) {
128
-				$type = substr($fond, strlen($z_contenu) + 1);
129
-				if (($type == 'page') and isset($flux['args']['contexte'][$page])) {
130
-					$type = $flux['args']['contexte'][$page];
131
-				}
132
-				if (!isset($disponible[$type])) {
133
-					$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
134
-				}
135
-				if (is_string($disponible[$type])) {
136
-					$flux['data'] = $disponible[$type];
137
-				} elseif (
138
-					$echafauder
139
-					and include_spip('inc/autoriser')
140
-					and isset($GLOBALS['visiteur_session']['statut']) // performance
141
-					and autoriser('echafauder', $type)
142
-					and $is = $disponible[$type]
143
-					and is_array($is)
144
-				) {
145
-					$flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext);
146
-				} else {
147
-					$flux['data'] = ($disponible['404'] = z_contenu_disponible(
148
-						$prefix_path . $prepend,
149
-						$z_contenu,
150
-						'404',
151
-						$ext,
152
-						$echafauder
153
-					));
154
-				}
155
-			}
156
-
157
-			// sinon, si on demande un fond non trouve dans un des autres blocs
158
-			// et si il y a bien un contenu correspondant ou echafaudable
159
-			// se rabbatre sur le dist.html du bloc concerne
160
-			else {
161
-				if (
162
-					$dir = explode('/', $fond)
163
-					and $dir = reset($dir)
164
-					and $dir !== $z_contenu
165
-					and in_array($dir, $z_blocs)
166
-				) {
167
-					$type = substr($fond, strlen("$dir/"));
168
-					if (($type == 'page') and isset($flux['args']['contexte'][$page])) {
169
-						$type = $flux['args']['contexte'][$page];
170
-					}
171
-					if ($type !== 'page' and !isset($disponible[$type])) {
172
-						$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
173
-					}
174
-					if ($type == 'page' or $disponible[$type]) {
175
-						$flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext);
176
-					}
177
-				}
178
-			}
179
-			$squelette = $flux['data'];
180
-		}
181
-		// layout specifiques par type et compositions :
182
-		// body-article.html
183
-		// body-sommaire.html
184
-		// pour des raisons de perfo, les declinaisons doivent etre dans le
185
-		// meme dossier que body.html
186
-		if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) {
187
-			if (
188
-				isset($flux['args']['contexte']['type-page'])
189
-				and (
190
-					(isset($flux['args']['contexte']['composition'])
191
-						and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext"))
192
-					or
193
-					file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext")
194
-				)
195
-			) {
196
-				$flux['data'] = $f;
197
-			}
198
-		} elseif (
199
-			$fond == 'structure'
200
-			and z_sanitize_var_zajax()
201
-			and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")
202
-		) {
203
-			$flux['data'] = substr($f, 0, -strlen(".$ext"));
204
-		} // chercher le fond correspondant a la composition
205
-		elseif (
206
-			isset($flux['args']['contexte']['composition'])
207
-			and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond))
208
-			and $dir = substr($fond, $prefix_length)
209
-			and $dir = explode('/', $dir)
210
-			and $dir = reset($dir)
211
-			and in_array($dir, $z_blocs)
212
-			and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")
213
-		) {
214
-			$flux['data'] = substr($f, 0, -strlen(".$ext"));
215
-		}
216
-	}
217
-
218
-	return $flux;
32
+    static $prefix_path = null;
33
+    static $prefix_length;
34
+    static $z_blocs;
35
+    static $apl_constant;
36
+    static $page;
37
+    static $disponible = [];
38
+    static $echafauder;
39
+    static $prepend = '';
40
+
41
+    if (!isset($prefix_path)) {
42
+        $z_blocs = z_blocs(test_espace_prive());
43
+        if (test_espace_prive()) {
44
+            $prefix_path = 'prive/squelettes/';
45
+            $prefix_length = strlen($prefix_path);
46
+            $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD';
47
+            $page = 'exec';
48
+            $echafauder = charger_fonction('echafauder', 'prive', true);
49
+            define('_ZCORE_EXCLURE_PATH', '');
50
+        } else {
51
+            $prefix_path = '';
52
+            $prefix_length = 0;
53
+            $apl_constant = '_Z_AJAX_PARALLEL_LOAD';
54
+            $page = _SPIP_PAGE;
55
+            $echafauder = charger_fonction('echafauder', 'public', true);
56
+            define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(
57
+                _DIR_PLUGIN_DIST,
58
+                '/'
59
+            ) : ''));
60
+        }
61
+        $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : '');
62
+    }
63
+    $z_contenu = reset($z_blocs); // contenu par defaut
64
+
65
+    $fond = $flux['args']['fond'];
66
+
67
+    if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) {
68
+        $fond = substr($fond, $prefix_length);
69
+        $squelette = $flux['data'];
70
+        $ext = $flux['args']['ext'];
71
+        // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax
72
+        if (
73
+            defined('_Z_AJAX_PARALLEL_LOAD_OK')
74
+            and $dir = explode('/', $fond)
75
+            and count($dir) == 2 // pas un sous repertoire
76
+            and $dir = reset($dir)
77
+            and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z
78
+            and defined($apl_constant)
79
+            and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL
80
+            and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL
81
+        ) {
82
+            $flux['data'] = $pipe;
83
+
84
+            return $flux;
85
+        }
86
+
87
+        // surcharger aussi les squelettes venant de squelettes-dist/
88
+        if ($squelette and !z_fond_valide($squelette)) {
89
+            $squelette = '';
90
+            $echafauder = '';
91
+        }
92
+        if ($prepend) {
93
+            $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext"));
94
+            if ($squelette) {
95
+                $flux['data'] = $squelette;
96
+            }
97
+        }
98
+
99
+        // gerer les squelettes non trouves
100
+        // -> router vers les /dist.html
101
+        // ou scaffolding ou page automatique les contenus
102
+        if (!$squelette) {
103
+            // si on est sur un ?page=XX non trouve
104
+            if (
105
+                (isset($flux['args']['contexte'][$page])
106
+                    and $flux['args']['contexte'][$page] == $fond)
107
+                or (isset($flux['args']['contexte']['type-page'])
108
+                    and $flux['args']['contexte']['type-page'] == $fond)
109
+                or ($fond == 'sommaire'
110
+                    and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page]))
111
+            ) {
112
+                // si on est sur un ?page=XX non trouve
113
+                // se brancher sur contenu/xx si il existe
114
+                // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme
115
+                if (!isset($disponible[$fond])) {
116
+                    $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder);
117
+                }
118
+
119
+                if ($disponible[$fond]) {
120
+                    $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext"));
121
+                }
122
+            }
123
+
124
+            // echafaudage :
125
+            // si c'est un fond de contenu d'un objet en base
126
+            // generer un fond automatique a la volee pour les webmestres
127
+            elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) {
128
+                $type = substr($fond, strlen($z_contenu) + 1);
129
+                if (($type == 'page') and isset($flux['args']['contexte'][$page])) {
130
+                    $type = $flux['args']['contexte'][$page];
131
+                }
132
+                if (!isset($disponible[$type])) {
133
+                    $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
134
+                }
135
+                if (is_string($disponible[$type])) {
136
+                    $flux['data'] = $disponible[$type];
137
+                } elseif (
138
+                    $echafauder
139
+                    and include_spip('inc/autoriser')
140
+                    and isset($GLOBALS['visiteur_session']['statut']) // performance
141
+                    and autoriser('echafauder', $type)
142
+                    and $is = $disponible[$type]
143
+                    and is_array($is)
144
+                ) {
145
+                    $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext);
146
+                } else {
147
+                    $flux['data'] = ($disponible['404'] = z_contenu_disponible(
148
+                        $prefix_path . $prepend,
149
+                        $z_contenu,
150
+                        '404',
151
+                        $ext,
152
+                        $echafauder
153
+                    ));
154
+                }
155
+            }
156
+
157
+            // sinon, si on demande un fond non trouve dans un des autres blocs
158
+            // et si il y a bien un contenu correspondant ou echafaudable
159
+            // se rabbatre sur le dist.html du bloc concerne
160
+            else {
161
+                if (
162
+                    $dir = explode('/', $fond)
163
+                    and $dir = reset($dir)
164
+                    and $dir !== $z_contenu
165
+                    and in_array($dir, $z_blocs)
166
+                ) {
167
+                    $type = substr($fond, strlen("$dir/"));
168
+                    if (($type == 'page') and isset($flux['args']['contexte'][$page])) {
169
+                        $type = $flux['args']['contexte'][$page];
170
+                    }
171
+                    if ($type !== 'page' and !isset($disponible[$type])) {
172
+                        $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
173
+                    }
174
+                    if ($type == 'page' or $disponible[$type]) {
175
+                        $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext);
176
+                    }
177
+                }
178
+            }
179
+            $squelette = $flux['data'];
180
+        }
181
+        // layout specifiques par type et compositions :
182
+        // body-article.html
183
+        // body-sommaire.html
184
+        // pour des raisons de perfo, les declinaisons doivent etre dans le
185
+        // meme dossier que body.html
186
+        if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) {
187
+            if (
188
+                isset($flux['args']['contexte']['type-page'])
189
+                and (
190
+                    (isset($flux['args']['contexte']['composition'])
191
+                        and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext"))
192
+                    or
193
+                    file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext")
194
+                )
195
+            ) {
196
+                $flux['data'] = $f;
197
+            }
198
+        } elseif (
199
+            $fond == 'structure'
200
+            and z_sanitize_var_zajax()
201
+            and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")
202
+        ) {
203
+            $flux['data'] = substr($f, 0, -strlen(".$ext"));
204
+        } // chercher le fond correspondant a la composition
205
+        elseif (
206
+            isset($flux['args']['contexte']['composition'])
207
+            and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond))
208
+            and $dir = substr($fond, $prefix_length)
209
+            and $dir = explode('/', $dir)
210
+            and $dir = reset($dir)
211
+            and in_array($dir, $z_blocs)
212
+            and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")
213
+        ) {
214
+            $flux['data'] = substr($f, 0, -strlen(".$ext"));
215
+        }
216
+    }
217
+
218
+    return $flux;
219 219
 }
220 220
 
221 221
 /**
@@ -225,18 +225,18 @@  discard block
 block discarded – undo
225 225
  * @return array
226 226
  */
227 227
 function z_blocs($espace_prive = false) {
228
-	if ($espace_prive) {
229
-		return ($GLOBALS['z_blocs_ecrire'] ?? [
230
-			'contenu',
231
-			'navigation',
232
-			'extra',
233
-			'head',
234
-			'hierarchie',
235
-			'top'
236
-		]);
237
-	}
238
-
239
-	return ($GLOBALS['z_blocs'] ?? ['contenu']);
228
+    if ($espace_prive) {
229
+        return ($GLOBALS['z_blocs_ecrire'] ?? [
230
+            'contenu',
231
+            'navigation',
232
+            'extra',
233
+            'head',
234
+            'hierarchie',
235
+            'top'
236
+        ]);
237
+    }
238
+
239
+    return ($GLOBALS['z_blocs'] ?? ['contenu']);
240 240
 }
241 241
 
242 242
 /**
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
  * @return mixed
252 252
  */
253 253
 function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) {
254
-	if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) {
255
-		return $d;
256
-	}
254
+    if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) {
255
+        return $d;
256
+    }
257 257
 
258
-	return $echafauder ? z_echafaudable($type) : false;
258
+    return $echafauder ? z_echafaudable($type) : false;
259 259
 }
260 260
 
261 261
 /**
@@ -269,14 +269,14 @@  discard block
 block discarded – undo
269 269
  *   `true` si on peut l'utiliser, `false` sinon.
270 270
  **/
271 271
 function z_fond_valide($squelette) {
272
-	if (
273
-		!_ZCORE_EXCLURE_PATH
274
-		or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette)
275
-	) {
276
-		return true;
277
-	}
278
-
279
-	return false;
272
+    if (
273
+        !_ZCORE_EXCLURE_PATH
274
+        or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette)
275
+    ) {
276
+        return true;
277
+    }
278
+
279
+    return false;
280 280
 }
281 281
 
282 282
 /**
@@ -294,14 +294,14 @@  discard block
 block discarded – undo
294 294
  * @return string
295 295
  */
296 296
 function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) {
297
-	if (
298
-		(defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f))
299
-		or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f))
300
-	) {
301
-		return substr($f, 0, -strlen(".$ext"));
302
-	}
303
-
304
-	return '';
297
+    if (
298
+        (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f))
299
+        or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f))
300
+    ) {
301
+        return substr($f, 0, -strlen(".$ext"));
302
+    }
303
+
304
+    return '';
305 305
 }
306 306
 
307 307
 /**
@@ -313,52 +313,52 @@  discard block
 block discarded – undo
313 313
  * @return bool
314 314
  */
315 315
 function z_echafaudable($type) {
316
-	static $pages = null;
317
-	static $echafaudable = [];
318
-	if (isset($echafaudable[$type])) {
319
-		return $echafaudable[$type];
320
-	}
321
-	if (preg_match(',[^\w],', $type)) {
322
-		return $echafaudable[$type] = false;
323
-	}
324
-
325
-	if (test_espace_prive()) {
326
-		if (!function_exists('trouver_objet_exec')) {
327
-			include_spip('inc/pipelines_ecrire');
328
-		}
329
-		if ($e = trouver_objet_exec($type)) {
330
-			return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e];
331
-		} else {
332
-			// peut etre c'est un exec=types qui liste tous les objets "type"
333
-			if (
334
-				($t = objet_type($type, false)) !== $type
335
-				and $e = trouver_objet_exec($t)
336
-			) {
337
-				return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t];
338
-			}
339
-		}
340
-	} else {
341
-		if (is_null($pages)) {
342
-			$pages = [];
343
-			$liste = lister_tables_objets_sql();
344
-			foreach ($liste as $t => $d) {
345
-				if ($d['page']) {
346
-					$pages[$d['page']] = [$d['table_objet'], $t];
347
-				}
348
-			}
349
-		}
350
-		if (!isset($pages[$type])) {
351
-			return $echafaudable[$type] = false;
352
-		}
353
-		if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) {
354
-			$trouver_table = charger_fonction('trouver_table', 'base');
355
-			$pages[$type][] = $trouver_table(reset($pages[$type]));
356
-		}
357
-
358
-		return $echafaudable[$type] = $pages[$type];
359
-	}
360
-
361
-	return $echafaudable[$type] = false;
316
+    static $pages = null;
317
+    static $echafaudable = [];
318
+    if (isset($echafaudable[$type])) {
319
+        return $echafaudable[$type];
320
+    }
321
+    if (preg_match(',[^\w],', $type)) {
322
+        return $echafaudable[$type] = false;
323
+    }
324
+
325
+    if (test_espace_prive()) {
326
+        if (!function_exists('trouver_objet_exec')) {
327
+            include_spip('inc/pipelines_ecrire');
328
+        }
329
+        if ($e = trouver_objet_exec($type)) {
330
+            return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e];
331
+        } else {
332
+            // peut etre c'est un exec=types qui liste tous les objets "type"
333
+            if (
334
+                ($t = objet_type($type, false)) !== $type
335
+                and $e = trouver_objet_exec($t)
336
+            ) {
337
+                return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t];
338
+            }
339
+        }
340
+    } else {
341
+        if (is_null($pages)) {
342
+            $pages = [];
343
+            $liste = lister_tables_objets_sql();
344
+            foreach ($liste as $t => $d) {
345
+                if ($d['page']) {
346
+                    $pages[$d['page']] = [$d['table_objet'], $t];
347
+                }
348
+            }
349
+        }
350
+        if (!isset($pages[$type])) {
351
+            return $echafaudable[$type] = false;
352
+        }
353
+        if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) {
354
+            $trouver_table = charger_fonction('trouver_table', 'base');
355
+            $pages[$type][] = $trouver_table(reset($pages[$type]));
356
+        }
357
+
358
+        return $echafaudable[$type] = $pages[$type];
359
+    }
360
+
361
+    return $echafaudable[$type] = false;
362 362
 }
363 363
 
364 364
 
@@ -375,46 +375,46 @@  discard block
 block discarded – undo
375 375
  * @return string
376 376
  */
377 377
 function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) {
378
-	$scaffold = '';
379
-
380
-	// page objet ou objet_edit
381
-	if (is_array($desc_exec)) {
382
-		$type = $desc_exec['type'];
383
-		$primary = $desc_exec['id_table_objet'];
384
-
385
-		if ($desc_exec['edition'] === false) {
386
-			$fond = 'objet';
387
-		} else {
388
-			$trouver_table = charger_fonction('trouver_table', 'base');
389
-			$desc = $trouver_table($table_sql);
390
-			if (isset($desc['field']['id_rubrique'])) {
391
-				$fond = 'objet_edit';
392
-			} else {
393
-				$fond = 'objet_edit.sans_rubrique';
394
-			}
395
-		}
396
-		$dir = z_blocs(test_espace_prive());
397
-		$dir = reset($dir);
398
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>';
399
-	} // page objets
400
-	elseif ($type = $desc_exec and !str_contains($type, '/')) {
401
-		$dir = z_blocs(test_espace_prive());
402
-		$dir = reset($dir);
403
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />';
404
-	}
405
-	// morceau d'objet : on fournit le fond de sibstitution dans $desc_exec
406
-	// et objet et tire de $table
407
-	elseif ($fond = $desc_exec) {
408
-		$dir = md5(dirname($fond));
409
-		$scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />';
410
-	}
411
-
412
-	$base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false);
413
-	$base_dir = sous_repertoire($base_dir, $dir, false);
414
-	$f = $base_dir . "$exec";
415
-	ecrire_fichier("$f.$ext", $scaffold);
416
-
417
-	return $f;
378
+    $scaffold = '';
379
+
380
+    // page objet ou objet_edit
381
+    if (is_array($desc_exec)) {
382
+        $type = $desc_exec['type'];
383
+        $primary = $desc_exec['id_table_objet'];
384
+
385
+        if ($desc_exec['edition'] === false) {
386
+            $fond = 'objet';
387
+        } else {
388
+            $trouver_table = charger_fonction('trouver_table', 'base');
389
+            $desc = $trouver_table($table_sql);
390
+            if (isset($desc['field']['id_rubrique'])) {
391
+                $fond = 'objet_edit';
392
+            } else {
393
+                $fond = 'objet_edit.sans_rubrique';
394
+            }
395
+        }
396
+        $dir = z_blocs(test_espace_prive());
397
+        $dir = reset($dir);
398
+        $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>';
399
+    } // page objets
400
+    elseif ($type = $desc_exec and !str_contains($type, '/')) {
401
+        $dir = z_blocs(test_espace_prive());
402
+        $dir = reset($dir);
403
+        $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />';
404
+    }
405
+    // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec
406
+    // et objet et tire de $table
407
+    elseif ($fond = $desc_exec) {
408
+        $dir = md5(dirname($fond));
409
+        $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />';
410
+    }
411
+
412
+    $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false);
413
+    $base_dir = sous_repertoire($base_dir, $dir, false);
414
+    $f = $base_dir . "$exec";
415
+    ecrire_fichier("$f.$ext", $scaffold);
416
+
417
+    return $f;
418 418
 }
419 419
 
420 420
 /**
@@ -423,17 +423,17 @@  discard block
 block discarded – undo
423 423
  * @return bool|string
424 424
  */
425 425
 function z_sanitize_var_zajax() {
426
-	$z_ajax = _request('var_zajax');
427
-	if (!$z_ajax) {
428
-		return false;
429
-	}
430
-	if (
431
-		!$z_blocs = z_blocs(test_espace_prive())
432
-		or !in_array($z_ajax, $z_blocs)
433
-	) {
434
-		set_request('var_zajax'); // enlever cette demande incongrue
435
-		$z_ajax = false;
436
-	}
437
-
438
-	return $z_ajax;
426
+    $z_ajax = _request('var_zajax');
427
+    if (!$z_ajax) {
428
+        return false;
429
+    }
430
+    if (
431
+        !$z_blocs = z_blocs(test_espace_prive())
432
+        or !in_array($z_ajax, $z_blocs)
433
+    ) {
434
+        set_request('var_zajax'); // enlever cette demande incongrue
435
+        $z_ajax = false;
436
+    }
437
+
438
+    return $z_ajax;
439 439
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 			$apl_constant = '_Z_AJAX_PARALLEL_LOAD';
54 54
 			$page = _SPIP_PAGE;
55 55
 			$echafauder = charger_fonction('echafauder', 'public', true);
56
-			define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim(
56
+			define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist'.(defined('_DIR_PLUGIN_DIST') ? '|\b'.rtrim(
57 57
 				_DIR_PLUGIN_DIST,
58 58
 				'/'
59 59
 			) : ''));
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 			and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z
78 78
 			and defined($apl_constant)
79 79
 			and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL
80
-			and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL
80
+			and $pipe = z_trouver_bloc($prefix_path.$prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL
81 81
 		) {
82 82
 			$flux['data'] = $pipe;
83 83
 
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 			$echafauder = '';
91 91
 		}
92 92
 		if ($prepend) {
93
-			$squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext"));
93
+			$squelette = substr(find_in_path($prefix_path.$prepend."$fond.$ext"), 0, -strlen(".$ext"));
94 94
 			if ($squelette) {
95 95
 				$flux['data'] = $squelette;
96 96
 			}
@@ -113,11 +113,11 @@  discard block
 block discarded – undo
113 113
 				// se brancher sur contenu/xx si il existe
114 114
 				// ou si c'est un objet spip, associe a une table, utiliser le fond homonyme
115 115
 				if (!isset($disponible[$fond])) {
116
-					$disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder);
116
+					$disponible[$fond] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $fond, $ext, $echafauder);
117 117
 				}
118 118
 
119 119
 				if ($disponible[$fond]) {
120
-					$flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext"));
120
+					$flux['data'] = substr(find_in_path($prefix_path."page.$ext"), 0, -strlen(".$ext"));
121 121
 				}
122 122
 			}
123 123
 
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 					$type = $flux['args']['contexte'][$page];
131 131
 				}
132 132
 				if (!isset($disponible[$type])) {
133
-					$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
133
+					$disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder);
134 134
 				}
135 135
 				if (is_string($disponible[$type])) {
136 136
 					$flux['data'] = $disponible[$type];
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 					$flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext);
146 146
 				} else {
147 147
 					$flux['data'] = ($disponible['404'] = z_contenu_disponible(
148
-						$prefix_path . $prepend,
148
+						$prefix_path.$prepend,
149 149
 						$z_contenu,
150 150
 						'404',
151 151
 						$ext,
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 						$type = $flux['args']['contexte'][$page];
170 170
 					}
171 171
 					if ($type !== 'page' and !isset($disponible[$type])) {
172
-						$disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder);
172
+						$disponible[$type] = z_contenu_disponible($prefix_path.$prepend, $z_contenu, $type, $ext, $echafauder);
173 173
 					}
174 174
 					if ($type == 'page' or $disponible[$type]) {
175
-						$flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext);
175
+						$flux['data'] = z_trouver_bloc($prefix_path.$prepend, $dir, 'dist', $ext);
176 176
 					}
177 177
 				}
178 178
 			}
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 				isset($flux['args']['contexte']['type-page'])
189 189
 				and (
190 190
 					(isset($flux['args']['contexte']['composition'])
191
-						and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext"))
191
+						and file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page'].'-'.$flux['args']['contexte']['composition']).".$ext"))
192 192
 					or
193
-					file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext")
193
+					file_exists(($f = $squelette.'-'.$flux['args']['contexte']['type-page']).".$ext")
194 194
 				)
195 195
 			) {
196 196
 				$flux['data'] = $f;
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 		} elseif (
199 199
 			$fond == 'structure'
200 200
 			and z_sanitize_var_zajax()
201
-			and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext")
201
+			and $f = find_in_path($prefix_path.$prepend.'ajax'.".$ext")
202 202
 		) {
203 203
 			$flux['data'] = substr($f, 0, -strlen(".$ext"));
204 204
 		} // chercher le fond correspondant a la composition
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 			and $dir = explode('/', $dir)
210 210
 			and $dir = reset($dir)
211 211
 			and in_array($dir, $z_blocs)
212
-			and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext")
212
+			and $f = find_in_path($prefix_path.$prepend.$fond.'-'.$flux['args']['contexte']['composition'].".$ext")
213 213
 		) {
214 214
 			$flux['data'] = substr($f, 0, -strlen(".$ext"));
215 215
 		}
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 function z_fond_valide($squelette) {
272 272
 	if (
273 273
 		!_ZCORE_EXCLURE_PATH
274
-		or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette)
274
+		or !preg_match(',('._ZCORE_EXCLURE_PATH.')/,', $squelette)
275 275
 	) {
276 276
 		return true;
277 277
 	}
@@ -395,23 +395,23 @@  discard block
 block discarded – undo
395 395
 		}
396 396
 		$dir = z_blocs(test_espace_prive());
397 397
 		$dir = reset($dir);
398
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>';
398
+		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/".$fond.',objet='.$type.',id_objet=#'.strtoupper($primary).',env}>';
399 399
 	} // page objets
400 400
 	elseif ($type = $desc_exec and !str_contains($type, '/')) {
401 401
 		$dir = z_blocs(test_espace_prive());
402 402
 		$dir = reset($dir);
403
-		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />';
403
+		$scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=".$type.',env} />';
404 404
 	}
405 405
 	// morceau d'objet : on fournit le fond de sibstitution dans $desc_exec
406 406
 	// et objet et tire de $table
407 407
 	elseif ($fond = $desc_exec) {
408 408
 		$dir = md5(dirname($fond));
409
-		$scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />';
409
+		$scaffold = "<INCLURE{fond=$fond,objet=".objet_type($table).',env} />';
410 410
 	}
411 411
 
412 412
 	$base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false);
413 413
 	$base_dir = sous_repertoire($base_dir, $dir, false);
414
-	$f = $base_dir . "$exec";
414
+	$f = $base_dir."$exec";
415 415
 	ecrire_fichier("$f.$ext", $scaffold);
416 416
 
417 417
 	return $f;
Please login to merge, or discard this patch.
ecrire/public/sandbox.php 2 patches
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  **/
24 24
 
25 25
 if (!defined('_ECRIRE_INC_VERSION')) {
26
-	return;
26
+    return;
27 27
 }
28 28
 
29 29
 /**
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
  *     texte
42 42
  */
43 43
 function sandbox_composer_texte($texte, &$p) {
44
-	$code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
44
+    $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
45 45
 
46
-	return $code;
46
+    return $code;
47 47
 }
48 48
 
49 49
 
@@ -59,42 +59,42 @@  discard block
 block discarded – undo
59 59
  * @return string
60 60
  */
61 61
 function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string {
62
-	if (isset($GLOBALS['spip_matrice'][$fonc])) {
63
-		$code = "filtrer('$fonc',$code$arglist)";
64
-	}
65
-
66
-	// le filtre est defini sous forme de fonction ou de methode
67
-	// par ex. dans inc_texte, inc_filtres ou mes_fonctions
68
-	elseif ($f = chercher_filtre($fonc)) {
69
-		// cas particulier : le filtre |set doit acceder a la $Pile
70
-		// proto: filtre_set(&$Pile, $val, $args...)
71
-		if (strpbrk($f, ':')) { // Class::method
72
-			$refl = new ReflectionMethod($f);
73
-		} else {
74
-			$refl = new ReflectionFunction($f);
75
-		}
76
-		$refs = $refl->getParameters();
77
-		if (isset($refs[0]) and $refs[0]->name == 'Pile') {
78
-			$code = "$f(\$Pile,$code$arglist)";
79
-			$nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile
80
-		} else {
81
-			$code = "$f($code$arglist)";
82
-			$nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre
83
-		}
84
-		$nb_args_f = $nb_arg_gauche + $nb_arg_droite;
85
-		$min_f = $refl->getNumberOfRequiredParameters();
86
-		if (($nb_args_f < $min_f)) {
87
-			$msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
88
-			erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
89
-		}
90
-	}
91
-	// le filtre n'existe pas,
92
-	// on le notifie
93
-	else {
94
-		erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p);
95
-	}
96
-
97
-	return $code;
62
+    if (isset($GLOBALS['spip_matrice'][$fonc])) {
63
+        $code = "filtrer('$fonc',$code$arglist)";
64
+    }
65
+
66
+    // le filtre est defini sous forme de fonction ou de methode
67
+    // par ex. dans inc_texte, inc_filtres ou mes_fonctions
68
+    elseif ($f = chercher_filtre($fonc)) {
69
+        // cas particulier : le filtre |set doit acceder a la $Pile
70
+        // proto: filtre_set(&$Pile, $val, $args...)
71
+        if (strpbrk($f, ':')) { // Class::method
72
+            $refl = new ReflectionMethod($f);
73
+        } else {
74
+            $refl = new ReflectionFunction($f);
75
+        }
76
+        $refs = $refl->getParameters();
77
+        if (isset($refs[0]) and $refs[0]->name == 'Pile') {
78
+            $code = "$f(\$Pile,$code$arglist)";
79
+            $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile
80
+        } else {
81
+            $code = "$f($code$arglist)";
82
+            $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre
83
+        }
84
+        $nb_args_f = $nb_arg_gauche + $nb_arg_droite;
85
+        $min_f = $refl->getNumberOfRequiredParameters();
86
+        if (($nb_args_f < $min_f)) {
87
+            $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
88
+            erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
89
+        }
90
+    }
91
+    // le filtre n'existe pas,
92
+    // on le notifie
93
+    else {
94
+        erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p);
95
+    }
96
+
97
+    return $code;
98 98
 }
99 99
 
100 100
 // Calculer un <INCLURE(xx.php)>
@@ -117,15 +117,15 @@  discard block
 block discarded – undo
117 117
  * @return string
118 118
  */
119 119
 function sandbox_composer_inclure_php($fichier, &$p, $_contexte) {
120
-	$compil = texte_script(memoriser_contexte_compil($p));
121
-	// si inexistant, on essaiera a l'execution
122
-	if ($path = find_in_path($fichier)) {
123
-		$path = "\"$path\"";
124
-	} else {
125
-		$path = "find_in_path(\"$fichier\")";
126
-	}
127
-
128
-	return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
120
+    $compil = texte_script(memoriser_contexte_compil($p));
121
+    // si inexistant, on essaiera a l'execution
122
+    if ($path = find_in_path($fichier)) {
123
+        $path = "\"$path\"";
124
+    } else {
125
+        $path = "find_in_path(\"$fichier\")";
126
+    }
127
+
128
+    return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte);
129 129
 }
130 130
 
131 131
 /**
@@ -137,20 +137,20 @@  discard block
 block discarded – undo
137 137
  * @return string
138 138
  */
139 139
 function sandbox_composer_interdire_scripts($code, &$p) {
140
-	// Securite
141
-	if (
142
-		$p->interdire_scripts
143
-		and $p->etoile != '**'
144
-	) {
145
-		if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) {
146
-			$code = "interdire_scripts($code)";
147
-		} else {
148
-			$code = interdire_scripts($r[2]);
149
-			$code = "sinon(interdire_scripts($r[1]),'$code')";
150
-		}
151
-	}
152
-
153
-	return $code;
140
+    // Securite
141
+    if (
142
+        $p->interdire_scripts
143
+        and $p->etoile != '**'
144
+    ) {
145
+        if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) {
146
+            $code = "interdire_scripts($code)";
147
+        } else {
148
+            $code = interdire_scripts($r[2]);
149
+            $code = "sinon(interdire_scripts($r[1]),'$code')";
150
+        }
151
+    }
152
+
153
+    return $code;
154 154
 }
155 155
 
156 156
 
@@ -169,30 +169,30 @@  discard block
 block discarded – undo
169 169
  * @return mixed|string
170 170
  */
171 171
 function sandbox_filtrer_squelette($skel, $corps, $filtres) {
172
-	$series_filtres = func_get_args();
173
-	array_shift($series_filtres);// skel
174
-	array_shift($series_filtres);// corps
175
-
176
-	// proteger les <INCLUDE> et tous les morceaux de php licites
177
-	if ($skel['process_ins'] == 'php') {
178
-		$corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps);
179
-	}
180
-
181
-	// recuperer les couples de remplacement
182
-	$replace = echapper_php_callback();
183
-
184
-	foreach ($series_filtres as $filtres) {
185
-		if (is_countable($filtres) ? count($filtres) : 0) {
186
-			foreach ($filtres as $filtre) {
187
-				if ($filtre and $f = chercher_filtre($filtre)) {
188
-					$corps = $f($corps);
189
-				}
190
-			}
191
-		}
192
-	}
193
-
194
-	// restaurer les echappements
195
-	return str_replace($replace[0], $replace[1], $corps);
172
+    $series_filtres = func_get_args();
173
+    array_shift($series_filtres);// skel
174
+    array_shift($series_filtres);// corps
175
+
176
+    // proteger les <INCLUDE> et tous les morceaux de php licites
177
+    if ($skel['process_ins'] == 'php') {
178
+        $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps);
179
+    }
180
+
181
+    // recuperer les couples de remplacement
182
+    $replace = echapper_php_callback();
183
+
184
+    foreach ($series_filtres as $filtres) {
185
+        if (is_countable($filtres) ? count($filtres) : 0) {
186
+            foreach ($filtres as $filtre) {
187
+                if ($filtre and $f = chercher_filtre($filtre)) {
188
+                    $corps = $f($corps);
189
+                }
190
+            }
191
+        }
192
+    }
193
+
194
+    // restaurer les echappements
195
+    return str_replace($replace[0], $replace[1], $corps);
196 196
 }
197 197
 
198 198
 
@@ -211,21 +211,21 @@  discard block
 block discarded – undo
211 211
  *     - array : Liste( liste des codes PHP, liste des substitutions )
212 212
  **/
213 213
 function echapper_php_callback($r = null) {
214
-	static $src = [];
215
-	static $dst = [];
214
+    static $src = [];
215
+    static $dst = [];
216 216
 
217
-	// si on recoit un tableau, on est en mode echappement
218
-	// on enregistre le code a echapper dans dst, et le code echappe dans src
219
-	if (is_array($r)) {
220
-		$dst[] = $r[0];
217
+    // si on recoit un tableau, on est en mode echappement
218
+    // on enregistre le code a echapper dans dst, et le code echappe dans src
219
+    if (is_array($r)) {
220
+        $dst[] = $r[0];
221 221
 
222
-		return $src[] = '___' . md5($r[0]) . '___';
223
-	}
222
+        return $src[] = '___' . md5($r[0]) . '___';
223
+    }
224 224
 
225
-	// si on recoit pas un tableau, on renvoit les couples de substitution
226
-	// et on RAZ les remplacements
227
-	$r = [$src, $dst];
228
-	$src = $dst = [];
225
+    // si on recoit pas un tableau, on renvoit les couples de substitution
226
+    // et on RAZ les remplacements
227
+    $r = [$src, $dst];
228
+    $src = $dst = [];
229 229
 
230
-	return $r;
230
+    return $r;
231 231
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
  *     texte
42 42
  */
43 43
 function sandbox_composer_texte($texte, &$p) {
44
-	$code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'";
44
+	$code = "'".str_replace(['\\', "'"], ['\\\\', "\\'"], $texte)."'";
45 45
 
46 46
 	return $code;
47 47
 }
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 		$min_f = $refl->getNumberOfRequiredParameters();
86 86
 		if (($nb_args_f < $min_f)) {
87 87
 			$msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f];
88
-			erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p);
88
+			erreur_squelette(['zbug_erreur_filtre_nbarg_min', $msg_args], $p);
89 89
 		}
90 90
 	}
91 91
 	// le filtre n'existe pas,
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
  */
171 171
 function sandbox_filtrer_squelette($skel, $corps, $filtres) {
172 172
 	$series_filtres = func_get_args();
173
-	array_shift($series_filtres);// skel
174
-	array_shift($series_filtres);// corps
173
+	array_shift($series_filtres); // skel
174
+	array_shift($series_filtres); // corps
175 175
 
176 176
 	// proteger les <INCLUDE> et tous les morceaux de php licites
177 177
 	if ($skel['process_ins'] == 'php') {
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	if (is_array($r)) {
220 220
 		$dst[] = $r[0];
221 221
 
222
-		return $src[] = '___' . md5($r[0]) . '___';
222
+		return $src[] = '___'.md5($r[0]).'___';
223 223
 	}
224 224
 
225 225
 	// si on recoit pas un tableau, on renvoit les couples de substitution
Please login to merge, or discard this patch.
ecrire/iterateur/data.php 2 patches
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -19,11 +19,11 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 if (!defined('_DATA_SOURCE_MAX_SIZE')) {
26
-	define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576);
26
+    define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576);
27 27
 }
28 28
 
29 29
 
@@ -44,17 +44,17 @@  discard block
 block discarded – undo
44 44
  *     Description de la boucle complétée des champs
45 45
  */
46 46
 function iterateur_DATA_dist($b) {
47
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
48
-	$b->show = [
49
-		'field' => [
50
-			'cle' => 'STRING',
51
-			'valeur' => 'STRING',
52
-			'*' => 'ALL' // Champ joker *
53
-		]
54
-	];
55
-	$b->select[] = '.valeur';
56
-
57
-	return $b;
47
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
48
+    $b->show = [
49
+        'field' => [
50
+            'cle' => 'STRING',
51
+            'valeur' => 'STRING',
52
+            '*' => 'ALL' // Champ joker *
53
+        ]
54
+    ];
55
+    $b->select[] = '.valeur';
56
+
57
+    return $b;
58 58
 }
59 59
 
60 60
 
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
  * @return array
70 70
  */
71 71
 function inc_file_to_array_dist($data) {
72
-	return preg_split('/\r?\n/', $data);
72
+    return preg_split('/\r?\n/', $data);
73 73
 }
74 74
 
75 75
 /**
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
  * @return array
79 79
  */
80 80
 function inc_plugins_to_array_dist() {
81
-	include_spip('inc/plugin');
81
+    include_spip('inc/plugin');
82 82
 
83
-	return liste_chemin_plugin_actifs();
83
+    return liste_chemin_plugin_actifs();
84 84
 }
85 85
 
86 86
 /**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
  * @return array
91 91
  */
92 92
 function inc_xml_to_array_dist($data) {
93
-	return @XMLObjectToArray(new SimpleXmlIterator($data));
93
+    return @XMLObjectToArray(new SimpleXmlIterator($data));
94 94
 }
95 95
 
96 96
 /**
@@ -102,14 +102,14 @@  discard block
 block discarded – undo
102 102
  *
103 103
  */
104 104
 function inc_object_to_array($object) {
105
-	if (!is_object($object) && !is_array($object)) {
106
-		return $object;
107
-	}
108
-	if (is_object($object)) {
109
-		$object = get_object_vars($object);
110
-	}
111
-
112
-	return array_map('inc_object_to_array', $object);
105
+    if (!is_object($object) && !is_array($object)) {
106
+        return $object;
107
+    }
108
+    if (is_object($object)) {
109
+        $object = get_object_vars($object);
110
+    }
111
+
112
+    return array_map('inc_object_to_array', $object);
113 113
 }
114 114
 
115 115
 /**
@@ -119,20 +119,20 @@  discard block
 block discarded – undo
119 119
  * @return array|bool
120 120
  */
121 121
 function inc_sql_to_array_dist($data) {
122
-	# sortir le connecteur de $data
123
-	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
124
-	$serveur = (string)$v[1];
125
-	$req = trim($v[2]);
126
-	if ($s = sql_query($req, $serveur)) {
127
-		$r = [];
128
-		while ($t = sql_fetch($s)) {
129
-			$r[] = $t;
130
-		}
131
-
132
-		return $r;
133
-	}
134
-
135
-	return false;
122
+    # sortir le connecteur de $data
123
+    preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
124
+    $serveur = (string)$v[1];
125
+    $req = trim($v[2]);
126
+    if ($s = sql_query($req, $serveur)) {
127
+        $r = [];
128
+        while ($t = sql_fetch($s)) {
129
+            $r[] = $t;
130
+        }
131
+
132
+        return $r;
133
+    }
134
+
135
+    return false;
136 136
 }
137 137
 
138 138
 /**
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
  * @return array|bool
143 143
  */
144 144
 function inc_json_to_array_dist($data) {
145
-	try {
146
-		$json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
147
-	} catch (JsonException $e) {
148
-		$json = null;
149
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
150
-	}
151
-	return is_array($json) ? (array) $json : [];
145
+    try {
146
+        $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
147
+    } catch (JsonException $e) {
148
+        $json = null;
149
+        spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
150
+    }
151
+    return is_array($json) ? (array) $json : [];
152 152
 }
153 153
 
154 154
 /**
@@ -158,30 +158,30 @@  discard block
 block discarded – undo
158 158
  * @return array|bool
159 159
  */
160 160
 function inc_csv_to_array_dist($data) {
161
-	include_spip('inc/csv');
162
-	[$entete, $csv] = analyse_csv($data);
163
-	array_unshift($csv, $entete);
164
-
165
-	include_spip('inc/charsets');
166
-	$i = 1;
167
-	foreach ($entete as $k => $v) {
168
-		if (trim($v) == '') {
169
-			$v = 'col' . $i;
170
-		} // reperer des eventuelles cases vides
171
-		if (is_numeric($v) and $v < 0) {
172
-			$v = '__' . $v;
173
-		} // ne pas risquer d'ecraser une cle numerique
174
-		if (is_numeric($v)) {
175
-			$v = '_' . $v;
176
-		} // ne pas risquer d'ecraser une cle numerique
177
-		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
178
-		foreach ($csv as &$item) {
179
-			$item[$v] = &$item[$k];
180
-		}
181
-		$i++;
182
-	}
183
-
184
-	return $csv;
161
+    include_spip('inc/csv');
162
+    [$entete, $csv] = analyse_csv($data);
163
+    array_unshift($csv, $entete);
164
+
165
+    include_spip('inc/charsets');
166
+    $i = 1;
167
+    foreach ($entete as $k => $v) {
168
+        if (trim($v) == '') {
169
+            $v = 'col' . $i;
170
+        } // reperer des eventuelles cases vides
171
+        if (is_numeric($v) and $v < 0) {
172
+            $v = '__' . $v;
173
+        } // ne pas risquer d'ecraser une cle numerique
174
+        if (is_numeric($v)) {
175
+            $v = '_' . $v;
176
+        } // ne pas risquer d'ecraser une cle numerique
177
+        $v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
178
+        foreach ($csv as &$item) {
179
+            $item[$v] = &$item[$k];
180
+        }
181
+        $i++;
182
+    }
183
+
184
+    return $csv;
185 185
 }
186 186
 
187 187
 /**
@@ -191,13 +191,13 @@  discard block
 block discarded – undo
191 191
  * @return array|bool
192 192
  */
193 193
 function inc_rss_to_array_dist($data) {
194
-	$tableau = null;
195
-	include_spip('inc/syndic');
196
-	if (is_array($rss = analyser_backend($data))) {
197
-		$tableau = $rss;
198
-	}
194
+    $tableau = null;
195
+    include_spip('inc/syndic');
196
+    if (is_array($rss = analyser_backend($data))) {
197
+        $tableau = $rss;
198
+    }
199 199
 
200
-	return $tableau;
200
+    return $tableau;
201 201
 }
202 202
 
203 203
 /**
@@ -207,9 +207,9 @@  discard block
 block discarded – undo
207 207
  * @return array|bool
208 208
  */
209 209
 function inc_atom_to_array_dist($data) {
210
-	$rss_to_array = charger_fonction('rss_to_array', 'inc');
210
+    $rss_to_array = charger_fonction('rss_to_array', 'inc');
211 211
 
212
-	return $rss_to_array($data);
212
+    return $rss_to_array($data);
213 213
 }
214 214
 
215 215
 /**
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
  * @return array|bool
221 221
  */
222 222
 function inc_glob_to_array_dist($data) {
223
-	$a = glob(
224
-		$data,
225
-		GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
226
-	);
223
+    $a = glob(
224
+        $data,
225
+        GLOB_MARK | GLOB_NOSORT | GLOB_BRACE
226
+    );
227 227
 
228
-	return $a ?: [];
228
+    return $a ?: [];
229 229
 }
230 230
 
231 231
 /**
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
  * @throws Exception
237 237
  */
238 238
 function inc_yaml_to_array_dist($data) {
239
-	include_spip('inc/yaml-mini');
240
-	if (!function_exists('yaml_decode')) {
241
-		throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
239
+    include_spip('inc/yaml-mini');
240
+    if (!function_exists('yaml_decode')) {
241
+        throw new Exception('YAML: impossible de trouver la fonction yaml_decode');
242 242
 
243
-		return false;
244
-	}
243
+        return false;
244
+    }
245 245
 
246
-	return yaml_decode($data);
246
+    return yaml_decode($data);
247 247
 }
248 248
 
249 249
 
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
  * @return array|bool
259 259
  */
260 260
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
261
-	return (array)preg_files($dir, $regexp, $limit);
261
+    return (array)preg_files($dir, $regexp, $limit);
262 262
 }
263 263
 
264 264
 /**
@@ -270,23 +270,23 @@  discard block
 block discarded – undo
270 270
  * @return array|bool
271 271
  */
272 272
 function inc_ls_to_array_dist($data) {
273
-	$glob_to_array = charger_fonction('glob_to_array', 'inc');
274
-	$a = $glob_to_array($data);
275
-	foreach ($a as &$v) {
276
-		$b = (array)@stat($v);
277
-		foreach ($b as $k => $ignore) {
278
-			if (is_numeric($k)) {
279
-				unset($b[$k]);
280
-			}
281
-		}
282
-		$b['file'] = preg_replace('`/$`', '', $v) ;
283
-		$v = array_merge(
284
-			pathinfo($v),
285
-			$b
286
-		);
287
-	}
288
-
289
-	return $a;
273
+    $glob_to_array = charger_fonction('glob_to_array', 'inc');
274
+    $a = $glob_to_array($data);
275
+    foreach ($a as &$v) {
276
+        $b = (array)@stat($v);
277
+        foreach ($b as $k => $ignore) {
278
+            if (is_numeric($k)) {
279
+                unset($b[$k]);
280
+            }
281
+        }
282
+        $b['file'] = preg_replace('`/$`', '', $v) ;
283
+        $v = array_merge(
284
+            pathinfo($v),
285
+            $b
286
+        );
287
+    }
288
+
289
+    return $a;
290 290
 }
291 291
 
292 292
 /**
@@ -296,25 +296,25 @@  discard block
 block discarded – undo
296 296
  * @return array|bool
297 297
  */
298 298
 function XMLObjectToArray($object) {
299
-	$xml_array = [];
300
-	for ($object->rewind(); $object->valid(); $object->next()) {
301
-		if (array_key_exists($key = $object->key(), $xml_array)) {
302
-			$key .= '-' . uniqid();
303
-		}
304
-		$vars = get_object_vars($object->current());
305
-		if (isset($vars['@attributes'])) {
306
-			foreach ($vars['@attributes'] as $k => $v) {
307
-				$xml_array[$key][$k] = $v;
308
-			}
309
-		}
310
-		if ($object->hasChildren()) {
311
-			$xml_array[$key][] = XMLObjectToArray(
312
-				$object->current()
313
-			);
314
-		} else {
315
-			$xml_array[$key][] = strval($object->current());
316
-		}
317
-	}
318
-
319
-	return $xml_array;
299
+    $xml_array = [];
300
+    for ($object->rewind(); $object->valid(); $object->next()) {
301
+        if (array_key_exists($key = $object->key(), $xml_array)) {
302
+            $key .= '-' . uniqid();
303
+        }
304
+        $vars = get_object_vars($object->current());
305
+        if (isset($vars['@attributes'])) {
306
+            foreach ($vars['@attributes'] as $k => $v) {
307
+                $xml_array[$key][$k] = $v;
308
+            }
309
+        }
310
+        if ($object->hasChildren()) {
311
+            $xml_array[$key][] = XMLObjectToArray(
312
+                $object->current()
313
+            );
314
+        } else {
315
+            $xml_array[$key][] = strval($object->current());
316
+        }
317
+    }
318
+
319
+    return $xml_array;
320 320
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 function inc_sql_to_array_dist($data) {
122 122
 	# sortir le connecteur de $data
123 123
 	preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v);
124
-	$serveur = (string)$v[1];
124
+	$serveur = (string) $v[1];
125 125
 	$req = trim($v[2]);
126 126
 	if ($s = sql_query($req, $serveur)) {
127 127
 		$r = [];
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		$json = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
147 147
 	} catch (JsonException $e) {
148 148
 		$json = null;
149
-		spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO);
149
+		spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO);
150 150
 	}
151 151
 	return is_array($json) ? (array) $json : [];
152 152
 }
@@ -166,13 +166,13 @@  discard block
 block discarded – undo
166 166
 	$i = 1;
167 167
 	foreach ($entete as $k => $v) {
168 168
 		if (trim($v) == '') {
169
-			$v = 'col' . $i;
169
+			$v = 'col'.$i;
170 170
 		} // reperer des eventuelles cases vides
171 171
 		if (is_numeric($v) and $v < 0) {
172
-			$v = '__' . $v;
172
+			$v = '__'.$v;
173 173
 		} // ne pas risquer d'ecraser une cle numerique
174 174
 		if (is_numeric($v)) {
175
-			$v = '_' . $v;
175
+			$v = '_'.$v;
176 176
 		} // ne pas risquer d'ecraser une cle numerique
177 177
 		$v = strtolower(preg_replace(',\W+,', '_', translitteration($v)));
178 178
 		foreach ($csv as &$item) {
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
  * @return array|bool
259 259
  */
260 260
 function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) {
261
-	return (array)preg_files($dir, $regexp, $limit);
261
+	return (array) preg_files($dir, $regexp, $limit);
262 262
 }
263 263
 
264 264
 /**
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
 	$glob_to_array = charger_fonction('glob_to_array', 'inc');
274 274
 	$a = $glob_to_array($data);
275 275
 	foreach ($a as &$v) {
276
-		$b = (array)@stat($v);
276
+		$b = (array) @stat($v);
277 277
 		foreach ($b as $k => $ignore) {
278 278
 			if (is_numeric($k)) {
279 279
 				unset($b[$k]);
280 280
 			}
281 281
 		}
282
-		$b['file'] = preg_replace('`/$`', '', $v) ;
282
+		$b['file'] = preg_replace('`/$`', '', $v);
283 283
 		$v = array_merge(
284 284
 			pathinfo($v),
285 285
 			$b
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 	$xml_array = [];
300 300
 	for ($object->rewind(); $object->valid(); $object->next()) {
301 301
 		if (array_key_exists($key = $object->key(), $xml_array)) {
302
-			$key .= '-' . uniqid();
302
+			$key .= '-'.uniqid();
303 303
 		}
304 304
 		$vars = get_object_vars($object->current());
305 305
 		if (isset($vars['@attributes'])) {
Please login to merge, or discard this patch.
ecrire/iterateur/condition.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 include_spip('iterateur/data');
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
  *     Description de la boucle complétée des champs
38 38
  */
39 39
 function iterateur_CONDITION_dist($b) {
40
-	$b->iterateur = 'CONDITION'; # designe la classe d'iterateur
41
-	$b->show = [
42
-		'field' => []
43
-	];
40
+    $b->iterateur = 'CONDITION'; # designe la classe d'iterateur
41
+    $b->show = [
42
+        'field' => []
43
+    ];
44 44
 
45
-	return $b;
45
+    return $b;
46 46
 }
Please login to merge, or discard this patch.
ecrire/iterateur/pour.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -38,13 +38,13 @@  discard block
 block discarded – undo
38 38
  *     Description de la boucle complétée des champs
39 39
  */
40 40
 function iterateur_POUR_dist($b) {
41
-	$b->iterateur = 'DATA'; # designe la classe d'iterateur
42
-	$b->show = [
43
-		'field' => [
44
-			'cle' => 'STRING',
45
-			'valeur' => 'STRING',
46
-		]
47
-	];
41
+    $b->iterateur = 'DATA'; # designe la classe d'iterateur
42
+    $b->show = [
43
+        'field' => [
44
+            'cle' => 'STRING',
45
+            'valeur' => 'STRING',
46
+        ]
47
+    ];
48 48
 
49
-	return $b;
49
+    return $b;
50 50
 }
Please login to merge, or discard this patch.
ecrire/iterateur/php.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
 
22 22
 if (!defined('_ECRIRE_INC_VERSION')) {
23
-	return;
23
+    return;
24 24
 }
25 25
 
26 26
 
@@ -38,17 +38,17 @@  discard block
 block discarded – undo
38 38
  *     Description de la boucle complétée des champs
39 39
  */
40 40
 function iterateur_php_dist($b, $iteratorName) {
41
-	$b->iterateur = $iteratorName; # designe la classe d'iterateur
42
-	$b->show = [
43
-		'field' => [
44
-			'cle' => 'STRING',
45
-			'valeur' => 'STRING',
46
-		]
47
-	];
48
-
49
-	foreach (get_class_methods($iteratorName) as $method) {
50
-		$b->show['field'][strtolower($method)] = 'METHOD';
51
-	}
52
-
53
-	return $b;
41
+    $b->iterateur = $iteratorName; # designe la classe d'iterateur
42
+    $b->show = [
43
+        'field' => [
44
+            'cle' => 'STRING',
45
+            'valeur' => 'STRING',
46
+        ]
47
+    ];
48
+
49
+    foreach (get_class_methods($iteratorName) as $method) {
50
+        $b->show['field'][strtolower($method)] = 'METHOD';
51
+    }
52
+
53
+    return $b;
54 54
 }
Please login to merge, or discard this patch.
ecrire/inc/pipelines.php 2 patches
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -16,10 +16,10 @@  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
 if (test_espace_prive()) {
22
-	include_spip('inc/pipelines_ecrire');
22
+    include_spip('inc/pipelines_ecrire');
23 23
 }
24 24
 
25 25
 
@@ -45,28 +45,28 @@  discard block
 block discarded – undo
45 45
  * @return string          Contenu qui sera inséré dans le head HTML
46 46
  **/
47 47
 function f_jQuery($texte) {
48
-	$x = '';
49
-	$jquery_plugins = pipeline(
50
-		'jquery_plugins',
51
-		[
52
-			'javascript/jquery.js',
53
-			'javascript/jquery.form.js',
54
-			'javascript/jquery.autosave.js',
55
-			'javascript/jquery.placeholder-label.js',
56
-			'javascript/ajaxCallback.js',
57
-			'javascript/js.cookie.js',
58
-		]
59
-	);
60
-	foreach (array_unique($jquery_plugins) as $script) {
61
-		if ($script = find_in_path(supprimer_timestamp($script))) {
62
-			$script = timestamp($script);
63
-			$x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
64
-		}
65
-	}
48
+    $x = '';
49
+    $jquery_plugins = pipeline(
50
+        'jquery_plugins',
51
+        [
52
+            'javascript/jquery.js',
53
+            'javascript/jquery.form.js',
54
+            'javascript/jquery.autosave.js',
55
+            'javascript/jquery.placeholder-label.js',
56
+            'javascript/ajaxCallback.js',
57
+            'javascript/js.cookie.js',
58
+        ]
59
+    );
60
+    foreach (array_unique($jquery_plugins) as $script) {
61
+        if ($script = find_in_path(supprimer_timestamp($script))) {
62
+            $script = timestamp($script);
63
+            $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n";
64
+        }
65
+    }
66 66
 
67
-	$texte = $x . $texte;
67
+    $texte = $x . $texte;
68 68
 
69
-	return $texte;
69
+    return $texte;
70 70
 }
71 71
 
72 72
 
@@ -85,28 +85,28 @@  discard block
 block discarded – undo
85 85
  * @return string         Contenu de la page envoyée au navigateur
86 86
  **/
87 87
 function f_surligne($texte) {
88
-	if (!$GLOBALS['html']) {
89
-		return $texte;
90
-	}
91
-	$rech = _request('var_recherche');
92
-	if (
93
-		!$rech
94
-		and (!defined('_SURLIGNE_RECHERCHE_REFERERS')
95
-			or !_SURLIGNE_RECHERCHE_REFERERS
96
-			or !isset($_SERVER['HTTP_REFERER']))
97
-	) {
98
-		return $texte;
99
-	}
100
-	include_spip('inc/surligne');
88
+    if (!$GLOBALS['html']) {
89
+        return $texte;
90
+    }
91
+    $rech = _request('var_recherche');
92
+    if (
93
+        !$rech
94
+        and (!defined('_SURLIGNE_RECHERCHE_REFERERS')
95
+            or !_SURLIGNE_RECHERCHE_REFERERS
96
+            or !isset($_SERVER['HTTP_REFERER']))
97
+    ) {
98
+        return $texte;
99
+    }
100
+    include_spip('inc/surligne');
101 101
 
102
-	if (isset($_SERVER['HTTP_REFERER'])) {
103
-		$_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']);
104
-	}
105
-	if ($rech) {
106
-		$rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech);
107
-	}
102
+    if (isset($_SERVER['HTTP_REFERER'])) {
103
+        $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', $_SERVER['HTTP_REFERER']);
104
+    }
105
+    if ($rech) {
106
+        $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', $rech);
107
+    }
108 108
 
109
-	return surligner_mots($texte, $rech);
109
+    return surligner_mots($texte, $rech);
110 110
 }
111 111
 
112 112
 /**
@@ -123,33 +123,33 @@  discard block
 block discarded – undo
123 123
  * @return string         Contenu de la page envoyée au navigateur
124 124
  **/
125 125
 function f_tidy($texte) {
126
-	/**
127
-	 * Indentation à faire ?
128
-	 *
129
-	 * - true : actif.
130
-	 * - false par défaut.
131
-	 */
126
+    /**
127
+     * Indentation à faire ?
128
+     *
129
+     * - true : actif.
130
+     * - false par défaut.
131
+     */
132 132
 
133
-	if (
134
-		$GLOBALS['xhtml'] # tidy demande
135
-		and $GLOBALS['html'] # verifie que la page avait l'entete text/html
136
-		and strlen($texte)
137
-		and !headers_sent()
138
-	) {
139
-		# Compatibilite ascendante
140
-		if (!is_string($GLOBALS['xhtml'])) {
141
-			$GLOBALS['xhtml'] = 'tidy';
142
-		}
133
+    if (
134
+        $GLOBALS['xhtml'] # tidy demande
135
+        and $GLOBALS['html'] # verifie que la page avait l'entete text/html
136
+        and strlen($texte)
137
+        and !headers_sent()
138
+    ) {
139
+        # Compatibilite ascendante
140
+        if (!is_string($GLOBALS['xhtml'])) {
141
+            $GLOBALS['xhtml'] = 'tidy';
142
+        }
143 143
 
144
-		if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) {
145
-			spip_log("tidy absent, l'indenteur SPIP le remplace");
146
-			$f = charger_fonction('sax', 'xml');
147
-		}
144
+        if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) {
145
+            spip_log("tidy absent, l'indenteur SPIP le remplace");
146
+            $f = charger_fonction('sax', 'xml');
147
+        }
148 148
 
149
-		return $f($texte);
150
-	}
149
+        return $f($texte);
150
+    }
151 151
 
152
-	return $texte;
152
+    return $texte;
153 153
 }
154 154
 
155 155
 
@@ -168,21 +168,21 @@  discard block
 block discarded – undo
168 168
  * @return string         Contenu de la page envoyée au navigateur
169 169
  **/
170 170
 function f_insert_head($texte) {
171
-	if (!$GLOBALS['html']) {
172
-		return $texte;
173
-	}
174
-	include_spip('public/admin'); // pour strripos
171
+    if (!$GLOBALS['html']) {
172
+        return $texte;
173
+    }
174
+    include_spip('public/admin'); // pour strripos
175 175
 
176
-	($pos = stripos($texte, '</head>'))
177
-	|| ($pos = stripos($texte, '<body>'))
178
-	|| ($pos = 0);
176
+    ($pos = stripos($texte, '</head>'))
177
+    || ($pos = stripos($texte, '<body>'))
178
+    || ($pos = 0);
179 179
 
180
-	if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) {
181
-		$insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
182
-		$texte = substr_replace($texte, $insert, $pos, 0);
183
-	}
180
+    if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) {
181
+        $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
182
+        $texte = substr_replace($texte, $insert, $pos, 0);
183
+    }
184 184
 
185
-	return $texte;
185
+    return $texte;
186 186
 }
187 187
 
188 188
 
@@ -198,34 +198,34 @@  discard block
 block discarded – undo
198 198
  * @return string         Contenu de la page envoyée au navigateur
199 199
  **/
200 200
 function f_admin($texte) {
201
-	if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) {
202
-		include_spip('inc/filtres'); // pour http_img_pack
203
-		$x = "<div class='spip-previsu' "
204
-			. http_style_background('preview-32.png', '', 32)
205
-			. '>'
206
-			. _T('previsualisation')
207
-			. '</div>';
208
-		if (!$pos = stripos($texte, '</body>')) {
209
-			$pos = strlen($texte);
210
-		}
211
-		$texte = substr_replace($texte, $x, $pos, 0);
212
-		// pas de preview en fenetre enfant
213
-		$x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
214
-		if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
215
-			$pos = -1;
216
-		}
217
-		$texte = substr_replace($texte, $x, $pos + 1, 0);
218
-	}
201
+    if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and $GLOBALS['html']) {
202
+        include_spip('inc/filtres'); // pour http_img_pack
203
+        $x = "<div class='spip-previsu' "
204
+            . http_style_background('preview-32.png', '', 32)
205
+            . '>'
206
+            . _T('previsualisation')
207
+            . '</div>';
208
+        if (!$pos = stripos($texte, '</body>')) {
209
+            $pos = strlen($texte);
210
+        }
211
+        $texte = substr_replace($texte, $x, $pos, 0);
212
+        // pas de preview en fenetre enfant
213
+        $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
214
+        if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
215
+            $pos = -1;
216
+        }
217
+        $texte = substr_replace($texte, $x, $pos + 1, 0);
218
+    }
219 219
 
220
-	if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) {
221
-		include_spip('public/admin');
222
-		$texte = affiche_boutons_admin($texte);
223
-	}
224
-	if (_request('var_mode') == 'noajax') {
225
-		$texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte);
226
-	}
220
+    if (isset($GLOBALS['affiche_boutons_admin']) and $GLOBALS['affiche_boutons_admin']) {
221
+        include_spip('public/admin');
222
+        $texte = affiche_boutons_admin($texte);
223
+    }
224
+    if (_request('var_mode') == 'noajax') {
225
+        $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte);
226
+    }
227 227
 
228
-	return $texte;
228
+    return $texte;
229 229
 }
230 230
 
231 231
 /**
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
  * @return array $flux  Description et contenu de l'inclusion
244 244
  **/
245 245
 function f_recuperer_fond($flux) {
246
-	if (!test_espace_prive()) {
247
-		return $flux;
248
-	}
246
+    if (!test_espace_prive()) {
247
+        return $flux;
248
+    }
249 249
 
250
-	return f_afficher_blocs_ecrire($flux);
250
+    return f_afficher_blocs_ecrire($flux);
251 251
 }
252 252
 
253 253
 /**
@@ -261,30 +261,30 @@  discard block
 block discarded – undo
261 261
  * @return string         Contenu de la page envoyée au navigateur
262 262
  */
263 263
 function f_queue($texte) {
264
-	// eviter une inclusion si rien a faire
265
-	if (
266
-		_request('action') == 'cron'
267
-		or queue_sleep_time_to_next_job() > 0
268
-		or defined('_DEBUG_BLOCK_QUEUE')
269
-	) {
270
-		return $texte;
271
-	}
264
+    // eviter une inclusion si rien a faire
265
+    if (
266
+        _request('action') == 'cron'
267
+        or queue_sleep_time_to_next_job() > 0
268
+        or defined('_DEBUG_BLOCK_QUEUE')
269
+    ) {
270
+        return $texte;
271
+    }
272 272
 
273
-	include_spip('inc/queue');
274
-	$code = queue_affichage_cron();
273
+    include_spip('inc/queue');
274
+    $code = queue_affichage_cron();
275 275
 
276
-	// si rien a afficher
277
-	// ou si on est pas dans une page html, on ne sait rien faire de mieux
278
-	if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) {
279
-		return $texte;
280
-	}
276
+    // si rien a afficher
277
+    // ou si on est pas dans une page html, on ne sait rien faire de mieux
278
+    if (!$code or !isset($GLOBALS['html']) or !$GLOBALS['html']) {
279
+        return $texte;
280
+    }
281 281
 
282
-	// inserer avant le </body> fermant si on peut, a la fin de la page sinon
283
-	if (($p = strpos($texte, '</body>')) !== false) {
284
-		$texte = substr($texte, 0, $p) . $code . substr($texte, $p);
285
-	} else {
286
-		$texte .= $code;
287
-	}
282
+    // inserer avant le </body> fermant si on peut, a la fin de la page sinon
283
+    if (($p = strpos($texte, '</body>')) !== false) {
284
+        $texte = substr($texte, 0, $p) . $code . substr($texte, $p);
285
+    } else {
286
+        $texte .= $code;
287
+    }
288 288
 
289
-	return $texte;
289
+    return $texte;
290 290
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		}
65 65
 	}
66 66
 
67
-	$texte = $x . $texte;
67
+	$texte = $x.$texte;
68 68
 
69 69
 	return $texte;
70 70
 }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	|| ($pos = 0);
179 179
 
180 180
 	if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) {
181
-		$insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n";
181
+		$insert = "\n".pipeline('insert_head', '<!-- f_insert_head -->')."\n";
182 182
 		$texte = substr_replace($texte, $insert, $pos, 0);
183 183
 	}
184 184
 
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 		}
211 211
 		$texte = substr_replace($texte, $x, $pos, 0);
212 212
 		// pas de preview en fenetre enfant
213
-		$x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes($GLOBALS['meta']['adresse_site']) . "';}</script>";
213
+		$x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='".addslashes($GLOBALS['meta']['adresse_site'])."';}</script>";
214 214
 		if (!$pos = stripos($texte, '<head') or !$pos = strpos($texte, '>', $pos)) {
215 215
 			$pos = -1;
216 216
 		}
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 
282 282
 	// inserer avant le </body> fermant si on peut, a la fin de la page sinon
283 283
 	if (($p = strpos($texte, '</body>')) !== false) {
284
-		$texte = substr($texte, 0, $p) . $code . substr($texte, $p);
284
+		$texte = substr($texte, 0, $p).$code.substr($texte, $p);
285 285
 	} else {
286 286
 		$texte .= $code;
287 287
 	}
Please login to merge, or discard this patch.
ecrire/inc/traduire.php 2 patches
Indentation   +194 added lines, -194 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
  **/
20 20
 
21 21
 if (!defined('_ECRIRE_INC_VERSION')) {
22
-	return;
22
+    return;
23 23
 }
24 24
 
25 25
 /**
@@ -40,20 +40,20 @@  discard block
 block discarded – undo
40 40
  *     Liste des fichiers de langue trouvés, dans l'ordre des chemins
41 41
  */
42 42
 function find_langs_in_path($file, $dirname = 'lang') {
43
-	static $dirs = [];
44
-	$liste = [];
45
-	foreach (creer_chemin() as $dir) {
46
-		if (!isset($dirs[$a = $dir . $dirname])) {
47
-			$dirs[$a] = (is_dir($a) || !$a);
48
-		}
49
-		if ($dirs[$a]) {
50
-			if (is_readable($a .= $file)) {
51
-				$liste[] = $a;
52
-			}
53
-		}
54
-	}
43
+    static $dirs = [];
44
+    $liste = [];
45
+    foreach (creer_chemin() as $dir) {
46
+        if (!isset($dirs[$a = $dir . $dirname])) {
47
+            $dirs[$a] = (is_dir($a) || !$a);
48
+        }
49
+        if ($dirs[$a]) {
50
+            if (is_readable($a .= $file)) {
51
+                $liste[] = $a;
52
+            }
53
+        }
54
+    }
55 55
 
56
-	return array_reverse($liste);
56
+    return array_reverse($liste);
57 57
 }
58 58
 
59 59
 /**
@@ -68,23 +68,23 @@  discard block
 block discarded – undo
68 68
  *     Liste des fichiers touvés pour ce module et cette langue.
69 69
  **/
70 70
 function chercher_module_lang($module, $lang = '') {
71
-	if ($lang) {
72
-		$lang = '_' . $lang;
73
-	}
71
+    if ($lang) {
72
+        $lang = '_' . $lang;
73
+    }
74 74
 
75
-	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
76
-	if (
77
-		$f = ($module == 'local'
78
-		? find_in_path($module . $lang . '.php', 'lang/')
79
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
80
-	) {
81
-		return is_array($f) ? $f : [$f];
82
-	}
75
+    // 1) dans un repertoire nomme lang/ se trouvant sur le chemin
76
+    if (
77
+        $f = ($module == 'local'
78
+        ? find_in_path($module . $lang . '.php', 'lang/')
79
+        : find_langs_in_path($module . $lang . '.php', 'lang/'))
80
+    ) {
81
+        return is_array($f) ? $f : [$f];
82
+    }
83 83
 
84
-	// 2) directement dans le chemin (old style, uniquement pour local)
85
-	return (($module == 'local') or strpos($module, '/'))
86
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
87
-		: false;
84
+    // 2) directement dans le chemin (old style, uniquement pour local)
85
+    return (($module == 'local') or strpos($module, '/'))
86
+        ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
87
+        : false;
88 88
 }
89 89
 
90 90
 /**
@@ -106,33 +106,33 @@  discard block
 block discarded – undo
106 106
  * @return void
107 107
  **/
108 108
 function charger_langue($lang, $module = 'spip') {
109
-	static $langs = [];
110
-	$var = 'i18n_' . $module . '_' . $lang;
111
-	if (!isset($langs[$lang])) {
112
-		$langs[$lang] = [];
113
-		if ($lang) {
114
-			$langs[$lang][] = $lang;
115
-			if (strpos($lang, '_') !== false) {
116
-				$l = explode('_', $lang);
117
-				$langs[$lang][] = reset($l);
118
-			}
119
-		}
120
-		$langs[$lang][] = $GLOBALS['meta']['langue_site'];
121
-		$langs[$lang][] = _LANGUE_PAR_DEFAUT;
122
-	}
123
-	foreach ($langs[$lang] as $l) {
124
-		if ($fichiers_lang = chercher_module_lang($module, $l)) {
125
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
126
-			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
127
-			surcharger_langue($fichiers_lang);
128
-			if ($l !== $lang) {
129
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
130
-			}
131
-			$GLOBALS['lang_' . $var] = $l;
132
-			#spip_log("module de langue : {$module}_$l.php", 'traduire');
133
-			break;
134
-		}
135
-	}
109
+    static $langs = [];
110
+    $var = 'i18n_' . $module . '_' . $lang;
111
+    if (!isset($langs[$lang])) {
112
+        $langs[$lang] = [];
113
+        if ($lang) {
114
+            $langs[$lang][] = $lang;
115
+            if (strpos($lang, '_') !== false) {
116
+                $l = explode('_', $lang);
117
+                $langs[$lang][] = reset($l);
118
+            }
119
+        }
120
+        $langs[$lang][] = $GLOBALS['meta']['langue_site'];
121
+        $langs[$lang][] = _LANGUE_PAR_DEFAUT;
122
+    }
123
+    foreach ($langs[$lang] as $l) {
124
+        if ($fichiers_lang = chercher_module_lang($module, $l)) {
125
+            $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
126
+            $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
127
+            surcharger_langue($fichiers_lang);
128
+            if ($l !== $lang) {
129
+                $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
130
+            }
131
+            $GLOBALS['lang_' . $var] = $l;
132
+            #spip_log("module de langue : {$module}_$l.php", 'traduire');
133
+            break;
134
+        }
135
+    }
136 136
 }
137 137
 
138 138
 /**
@@ -145,21 +145,21 @@  discard block
 block discarded – undo
145 145
  * @return array<string, string>
146 146
  */
147 147
 function lire_fichier_langue(string $fichier): array {
148
-	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
149
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
150
-	$GLOBALS['idx_lang'] = $idx_lang_tmp;
151
-	$idx_lang = include $fichier;
152
-	$GLOBALS['idx_lang'] = $idx_lang_before;
153
-	if (!is_array($idx_lang)) {
154
-		if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) {
155
-			$idx_lang = $GLOBALS[$idx_lang_tmp];
156
-		} else {
157
-			$idx_lang = [];
158
-			spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR);
159
-		}
160
-		unset($GLOBALS[$idx_lang_tmp]);
161
-	}
162
-	return $idx_lang;
148
+    $idx_lang_before = $GLOBALS['idx_lang'] ?? null;
149
+    $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
150
+    $GLOBALS['idx_lang'] = $idx_lang_tmp;
151
+    $idx_lang = include $fichier;
152
+    $GLOBALS['idx_lang'] = $idx_lang_before;
153
+    if (!is_array($idx_lang)) {
154
+        if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) {
155
+            $idx_lang = $GLOBALS[$idx_lang_tmp];
156
+        } else {
157
+            $idx_lang = [];
158
+            spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR);
159
+        }
160
+        unset($GLOBALS[$idx_lang_tmp]);
161
+    }
162
+    return $idx_lang;
163 163
 }
164 164
 
165 165
 /**
@@ -179,29 +179,29 @@  discard block
 block discarded – undo
179 179
  *    Liste des chemins de fichiers de langue à surcharger.
180 180
  **/
181 181
 function surcharger_langue($fichiers) {
182
-	static $surcharges = [];
183
-	if (!isset($GLOBALS['idx_lang'])) {
184
-		return;
185
-	}
182
+    static $surcharges = [];
183
+    if (!isset($GLOBALS['idx_lang'])) {
184
+        return;
185
+    }
186 186
 
187
-	if (!is_array($fichiers)) {
188
-		$fichiers = [$fichiers];
189
-	}
190
-	if (!count($fichiers)) {
191
-		return;
192
-	}
193
-	foreach ($fichiers as $fichier) {
194
-		if (!isset($surcharges[$fichier])) {
195
-			$surcharges[$fichier] = lire_fichier_langue($fichier);
196
-		}
197
-		if (is_array($surcharges[$fichier])) {
198
-			$GLOBALS[$GLOBALS['idx_lang']] ??= [];
199
-			$GLOBALS[$GLOBALS['idx_lang']] = array_merge(
200
-				$GLOBALS[$GLOBALS['idx_lang']],
201
-				$surcharges[$fichier]
202
-			);
203
-		}
204
-	}
187
+    if (!is_array($fichiers)) {
188
+        $fichiers = [$fichiers];
189
+    }
190
+    if (!count($fichiers)) {
191
+        return;
192
+    }
193
+    foreach ($fichiers as $fichier) {
194
+        if (!isset($surcharges[$fichier])) {
195
+            $surcharges[$fichier] = lire_fichier_langue($fichier);
196
+        }
197
+        if (is_array($surcharges[$fichier])) {
198
+            $GLOBALS[$GLOBALS['idx_lang']] ??= [];
199
+            $GLOBALS[$GLOBALS['idx_lang']] = array_merge(
200
+                $GLOBALS[$GLOBALS['idx_lang']],
201
+                $surcharges[$fichier]
202
+            );
203
+        }
204
+    }
205 205
 }
206 206
 
207 207
 /**
@@ -242,99 +242,99 @@  discard block
 block discarded – undo
242 242
  *     - Description : traduction et description (texte, module, langue)
243 243
  **/
244 244
 function inc_traduire_dist($ori, $lang, $raw = false) {
245
-	static $deja_vu = [];
246
-	static $local = [];
245
+    static $deja_vu = [];
246
+    static $local = [];
247 247
 
248
-	if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) {
249
-		return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
250
-	}
248
+    if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) {
249
+        return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte;
250
+    }
251 251
 
252
-	// modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
253
-	if (strpos($ori, ':')) {
254
-		[$modules, $code] = explode(':', $ori, 2);
255
-		$modules = explode('|', $modules);
256
-		$ori_complet = $ori;
257
-	} else {
258
-		$modules = ['spip', 'ecrire'];
259
-		$code = $ori;
260
-		$ori_complet = implode('|', $modules) . ':' . $ori;
261
-	}
252
+    // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES
253
+    if (strpos($ori, ':')) {
254
+        [$modules, $code] = explode(':', $ori, 2);
255
+        $modules = explode('|', $modules);
256
+        $ori_complet = $ori;
257
+    } else {
258
+        $modules = ['spip', 'ecrire'];
259
+        $code = $ori;
260
+        $ori_complet = implode('|', $modules) . ':' . $ori;
261
+    }
262 262
 
263
-	$desc = new Description();
263
+    $desc = new Description();
264 264
 
265
-	// parcourir tous les modules jusqu'a ce qu'on trouve
266
-	foreach ($modules as $module) {
267
-		$var = 'i18n_' . $module . '_' . $lang;
265
+    // parcourir tous les modules jusqu'a ce qu'on trouve
266
+    foreach ($modules as $module) {
267
+        $var = 'i18n_' . $module . '_' . $lang;
268 268
 
269
-		if (empty($GLOBALS[$var])) {
270
-			charger_langue($lang, $module);
271
-			// surcharges persos -- on cherche
272
-			// (lang/)local_xx.php et/ou (lang/)local.php ...
273
-			if (!isset($local['local_' . $lang])) {
274
-				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
275
-				$GLOBALS['idx_lang'] = $var;
276
-				// ... (lang/)local_xx.php
277
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
278
-			}
279
-			if ($local['local_' . $lang]) {
280
-				surcharger_langue($local['local_' . $lang]);
281
-			}
282
-			// ... puis (lang/)local.php
283
-			if (!isset($local['local'])) {
284
-				$local['local'] = chercher_module_lang('local');
285
-			}
286
-			if ($local['local']) {
287
-				surcharger_langue($local['local']);
288
-			}
289
-		}
269
+        if (empty($GLOBALS[$var])) {
270
+            charger_langue($lang, $module);
271
+            // surcharges persos -- on cherche
272
+            // (lang/)local_xx.php et/ou (lang/)local.php ...
273
+            if (!isset($local['local_' . $lang])) {
274
+                // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
275
+                $GLOBALS['idx_lang'] = $var;
276
+                // ... (lang/)local_xx.php
277
+                $local['local_' . $lang] = chercher_module_lang('local', $lang);
278
+            }
279
+            if ($local['local_' . $lang]) {
280
+                surcharger_langue($local['local_' . $lang]);
281
+            }
282
+            // ... puis (lang/)local.php
283
+            if (!isset($local['local'])) {
284
+                $local['local'] = chercher_module_lang('local');
285
+            }
286
+            if ($local['local']) {
287
+                surcharger_langue($local['local']);
288
+            }
289
+        }
290 290
 
291
-		if (isset($GLOBALS[$var][$code])) {
292
-			$desc->code = $code;
293
-			$desc->module = $module;
294
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
295
-			$desc->texte = $GLOBALS[$var][$code];
296
-			break;
297
-		}
298
-	}
291
+        if (isset($GLOBALS[$var][$code])) {
292
+            $desc->code = $code;
293
+            $desc->module = $module;
294
+            $desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
295
+            $desc->texte = $GLOBALS[$var][$code];
296
+            break;
297
+        }
298
+    }
299 299
 
300
-	if (!$desc->corrections) {
301
-		$desc->corrections = true;
302
-		// Retour aux sources si la chaine est absente dans la langue cible ;
303
-		// on essaie d'abord la langue du site, puis a defaut la langue fr
304
-		if (
305
-			($desc->texte === null || !strlen($desc->texte))
306
-			and $lang !== _LANGUE_PAR_DEFAUT
307
-		) {
308
-			if ($lang !== $GLOBALS['meta']['langue_site']) {
309
-				$desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
310
-			} else {
311
-				$desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
312
-			}
313
-		}
300
+    if (!$desc->corrections) {
301
+        $desc->corrections = true;
302
+        // Retour aux sources si la chaine est absente dans la langue cible ;
303
+        // on essaie d'abord la langue du site, puis a defaut la langue fr
304
+        if (
305
+            ($desc->texte === null || !strlen($desc->texte))
306
+            and $lang !== _LANGUE_PAR_DEFAUT
307
+        ) {
308
+            if ($lang !== $GLOBALS['meta']['langue_site']) {
309
+                $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true);
310
+            } else {
311
+                $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true);
312
+            }
313
+        }
314 314
 
315
-		// Supprimer la mention <NEW> ou <MODIF>
316
-		if ($desc->texte && substr($desc->texte, 0, 1) === '<') {
317
-			$desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
318
-		}
315
+        // Supprimer la mention <NEW> ou <MODIF>
316
+        if ($desc->texte && substr($desc->texte, 0, 1) === '<') {
317
+            $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte);
318
+        }
319 319
 
320
-		// Si on n'est pas en utf-8, la chaine peut l'etre...
321
-		// le cas echeant on la convertit en entites html &#xxx;
322
-		if (
323
-			(!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8')
324
-			and preg_match(',[\x7f-\xff],S', $desc->texte)
325
-		) {
326
-			include_spip('inc/charsets');
327
-			$desc->texte = charset2unicode($desc->texte, 'utf-8');
328
-		}
329
-	}
320
+        // Si on n'est pas en utf-8, la chaine peut l'etre...
321
+        // le cas echeant on la convertit en entites html &#xxx;
322
+        if (
323
+            (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8')
324
+            and preg_match(',[\x7f-\xff],S', $desc->texte)
325
+        ) {
326
+            include_spip('inc/charsets');
327
+            $desc->texte = charset2unicode($desc->texte, 'utf-8');
328
+        }
329
+    }
330 330
 
331
-	if (_request('var_mode') == 'traduction') {
332
-		$desc = definir_details_traduction($desc, $ori_complet);
333
-	} else {
334
-		$deja_vu[$lang][$ori] = $desc;
335
-	}
331
+    if (_request('var_mode') == 'traduction') {
332
+        $desc = definir_details_traduction($desc, $ori_complet);
333
+    } else {
334
+        $deja_vu[$lang][$ori] = $desc;
335
+    }
336 336
 
337
-	return $raw ? $desc : $desc->texte;
337
+    return $raw ? $desc : $desc->texte;
338 338
 }
339 339
 
340 340
 /**
@@ -346,23 +346,23 @@  discard block
 block discarded – undo
346 346
  * @return Description
347 347
  */
348 348
 function definir_details_traduction($desc, $modules) {
349
-	if (!$desc->mode and $desc->texte) {
350
-		// ne pas modifier 2 fois l'affichage
351
-		$desc->mode = 'traduction';
352
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
353
-		$desc->texte = '<span '
354
-			. 'lang=' . $desc->langue
355
-			. ' class=' . $classe
356
-			. ' data-module=' . $desc->module
357
-			. ' data-code=' . $desc->code
358
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
359
-			. $desc->texte
360
-			. '</span>';
361
-		$desc->texte = str_replace(
362
-			["$desc->module:", "$desc->module|"],
363
-			["*$desc->module*:", "*$desc->module*|"],
364
-			$desc->texte
365
-		);
366
-	}
367
-	return $desc;
349
+    if (!$desc->mode and $desc->texte) {
350
+        // ne pas modifier 2 fois l'affichage
351
+        $desc->mode = 'traduction';
352
+        $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
353
+        $desc->texte = '<span '
354
+            . 'lang=' . $desc->langue
355
+            . ' class=' . $classe
356
+            . ' data-module=' . $desc->module
357
+            . ' data-code=' . $desc->code
358
+            . ' title=' . $modules . '(' . $desc->langue . ')>'
359
+            . $desc->texte
360
+            . '</span>';
361
+        $desc->texte = str_replace(
362
+            ["$desc->module:", "$desc->module|"],
363
+            ["*$desc->module*:", "*$desc->module*|"],
364
+            $desc->texte
365
+        );
366
+    }
367
+    return $desc;
368 368
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 	static $dirs = [];
44 44
 	$liste = [];
45 45
 	foreach (creer_chemin() as $dir) {
46
-		if (!isset($dirs[$a = $dir . $dirname])) {
46
+		if (!isset($dirs[$a = $dir.$dirname])) {
47 47
 			$dirs[$a] = (is_dir($a) || !$a);
48 48
 		}
49 49
 		if ($dirs[$a]) {
@@ -69,21 +69,21 @@  discard block
 block discarded – undo
69 69
  **/
70 70
 function chercher_module_lang($module, $lang = '') {
71 71
 	if ($lang) {
72
-		$lang = '_' . $lang;
72
+		$lang = '_'.$lang;
73 73
 	}
74 74
 
75 75
 	// 1) dans un repertoire nomme lang/ se trouvant sur le chemin
76 76
 	if (
77 77
 		$f = ($module == 'local'
78
-		? find_in_path($module . $lang . '.php', 'lang/')
79
-		: find_langs_in_path($module . $lang . '.php', 'lang/'))
78
+		? find_in_path($module.$lang.'.php', 'lang/')
79
+		: find_langs_in_path($module.$lang.'.php', 'lang/'))
80 80
 	) {
81 81
 		return is_array($f) ? $f : [$f];
82 82
 	}
83 83
 
84 84
 	// 2) directement dans le chemin (old style, uniquement pour local)
85 85
 	return (($module == 'local') or strpos($module, '/'))
86
-		? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false)
86
+		? (($f = find_in_path($module.$lang.'.php')) ? [$f] : false)
87 87
 		: false;
88 88
 }
89 89
 
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
  **/
108 108
 function charger_langue($lang, $module = 'spip') {
109 109
 	static $langs = [];
110
-	$var = 'i18n_' . $module . '_' . $lang;
110
+	$var = 'i18n_'.$module.'_'.$lang;
111 111
 	if (!isset($langs[$lang])) {
112 112
 		$langs[$lang] = [];
113 113
 		if ($lang) {
@@ -122,13 +122,13 @@  discard block
 block discarded – undo
122 122
 	}
123 123
 	foreach ($langs[$lang] as $l) {
124 124
 		if ($fichiers_lang = chercher_module_lang($module, $l)) {
125
-			$GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l;
125
+			$GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l;
126 126
 			$GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang));
127 127
 			surcharger_langue($fichiers_lang);
128 128
 			if ($l !== $lang) {
129
-				$GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l];
129
+				$GLOBALS[$var] = &$GLOBALS['i18n_'.$module.'_'.$l];
130 130
 			}
131
-			$GLOBALS['lang_' . $var] = $l;
131
+			$GLOBALS['lang_'.$var] = $l;
132 132
 			#spip_log("module de langue : {$module}_$l.php", 'traduire');
133 133
 			break;
134 134
 		}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
  */
147 147
 function lire_fichier_langue(string $fichier): array {
148 148
 	$idx_lang_before = $GLOBALS['idx_lang'] ?? null;
149
-	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire';
149
+	$idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang').'@temporaire';
150 150
 	$GLOBALS['idx_lang'] = $idx_lang_tmp;
151 151
 	$idx_lang = include $fichier;
152 152
 	$GLOBALS['idx_lang'] = $idx_lang_before;
@@ -257,27 +257,27 @@  discard block
 block discarded – undo
257 257
 	} else {
258 258
 		$modules = ['spip', 'ecrire'];
259 259
 		$code = $ori;
260
-		$ori_complet = implode('|', $modules) . ':' . $ori;
260
+		$ori_complet = implode('|', $modules).':'.$ori;
261 261
 	}
262 262
 
263 263
 	$desc = new Description();
264 264
 
265 265
 	// parcourir tous les modules jusqu'a ce qu'on trouve
266 266
 	foreach ($modules as $module) {
267
-		$var = 'i18n_' . $module . '_' . $lang;
267
+		$var = 'i18n_'.$module.'_'.$lang;
268 268
 
269 269
 		if (empty($GLOBALS[$var])) {
270 270
 			charger_langue($lang, $module);
271 271
 			// surcharges persos -- on cherche
272 272
 			// (lang/)local_xx.php et/ou (lang/)local.php ...
273
-			if (!isset($local['local_' . $lang])) {
273
+			if (!isset($local['local_'.$lang])) {
274 274
 				// redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer)
275 275
 				$GLOBALS['idx_lang'] = $var;
276 276
 				// ... (lang/)local_xx.php
277
-				$local['local_' . $lang] = chercher_module_lang('local', $lang);
277
+				$local['local_'.$lang] = chercher_module_lang('local', $lang);
278 278
 			}
279
-			if ($local['local_' . $lang]) {
280
-				surcharger_langue($local['local_' . $lang]);
279
+			if ($local['local_'.$lang]) {
280
+				surcharger_langue($local['local_'.$lang]);
281 281
 			}
282 282
 			// ... puis (lang/)local.php
283 283
 			if (!isset($local['local'])) {
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 		if (isset($GLOBALS[$var][$code])) {
292 292
 			$desc->code = $code;
293 293
 			$desc->module = $module;
294
-			$desc->langue = $GLOBALS['lang_' . $var] ?? $lang;
294
+			$desc->langue = $GLOBALS['lang_'.$var] ?? $lang;
295 295
 			$desc->texte = $GLOBALS[$var][$code];
296 296
 			break;
297 297
 		}
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 	if (!$desc->mode and $desc->texte) {
350 350
 		// ne pas modifier 2 fois l'affichage
351 351
 		$desc->mode = 'traduction';
352
-		$classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : '');
352
+		$classe = 'debug-traduction'.($desc->module == 'ecrire' ? '-prive' : '');
353 353
 		$desc->texte = '<span '
354
-			. 'lang=' . $desc->langue
355
-			. ' class=' . $classe
356
-			. ' data-module=' . $desc->module
357
-			. ' data-code=' . $desc->code
358
-			. ' title=' . $modules . '(' . $desc->langue . ')>'
354
+			. 'lang='.$desc->langue
355
+			. ' class='.$classe
356
+			. ' data-module='.$desc->module
357
+			. ' data-code='.$desc->code
358
+			. ' title='.$modules.'('.$desc->langue.')>'
359 359
 			. $desc->texte
360 360
 			. '</span>';
361 361
 		$desc->texte = str_replace(
Please login to merge, or discard this patch.
ecrire/inc/charsets.php 2 patches
Indentation   +636 added lines, -636 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
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
  * Initialisation
33 33
  */
34 34
 function init_charset(): void {
35
-	// Initialisation
36
-	$GLOBALS['CHARSET'] = [];
37
-
38
-	// noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u
39
-	// dans les preg_replace pour ne pas casser certaines lettres accentuees :
40
-	// en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
41
-	if (
42
-		!isset($GLOBALS['meta']['pcre_u'])
43
-		or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
44
-	) {
45
-		include_spip('inc/meta');
46
-		ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : '');
47
-	}
35
+    // Initialisation
36
+    $GLOBALS['CHARSET'] = [];
37
+
38
+    // noter a l'occasion dans la meta pcre_u notre capacite a utiliser le flag /u
39
+    // dans les preg_replace pour ne pas casser certaines lettres accentuees :
40
+    // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp
41
+    if (
42
+        !isset($GLOBALS['meta']['pcre_u'])
43
+        or (isset($_GET['var_mode']) and !isset($_GET['var_profile']))
44
+    ) {
45
+        include_spip('inc/meta');
46
+        ecrire_meta('pcre_u', (lire_config('charset', _DEFAULT_CHARSET) === 'utf-8') ? 'u' : '');
47
+    }
48 48
 }
49 49
 
50 50
 // TODO: code d’exécution en dehors du fichier.
@@ -65,39 +65,39 @@  discard block
 block discarded – undo
65 65
  *     - false si le charset n'est pas décrit dans le répertoire charsets/
66 66
  **/
67 67
 function load_charset($charset = 'AUTO') {
68
-	if ($charset == 'AUTO') {
69
-		$charset = $GLOBALS['meta']['charset'];
70
-	}
71
-	$charset = trim(strtolower($charset));
72
-	if (isset($GLOBALS['CHARSET'][$charset])) {
73
-		return $charset;
74
-	}
75
-
76
-	if ($charset == 'utf-8') {
77
-		$GLOBALS['CHARSET'][$charset] = [];
78
-
79
-		return $charset;
80
-	}
81
-
82
-	// Quelques synonymes
83
-	if ($charset === '') {
84
-		$charset = 'iso-8859-1';
85
-	} elseif ($charset === 'windows-1250') {
86
-		$charset = 'cp1250';
87
-	} elseif ($charset === 'windows-1251') {
88
-		$charset = 'cp1251';
89
-	} elseif ($charset === 'windows-1256') {
90
-		$charset = 'cp1256';
91
-	}
92
-
93
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
94
-		return $charset;
95
-	} else {
96
-		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
97
-		$GLOBALS['CHARSET'][$charset] = [];
98
-
99
-		return false;
100
-	}
68
+    if ($charset == 'AUTO') {
69
+        $charset = $GLOBALS['meta']['charset'];
70
+    }
71
+    $charset = trim(strtolower($charset));
72
+    if (isset($GLOBALS['CHARSET'][$charset])) {
73
+        return $charset;
74
+    }
75
+
76
+    if ($charset == 'utf-8') {
77
+        $GLOBALS['CHARSET'][$charset] = [];
78
+
79
+        return $charset;
80
+    }
81
+
82
+    // Quelques synonymes
83
+    if ($charset === '') {
84
+        $charset = 'iso-8859-1';
85
+    } elseif ($charset === 'windows-1250') {
86
+        $charset = 'cp1250';
87
+    } elseif ($charset === 'windows-1251') {
88
+        $charset = 'cp1251';
89
+    } elseif ($charset === 'windows-1256') {
90
+        $charset = 'cp1256';
91
+    }
92
+
93
+    if (find_in_path($charset . '.php', 'charsets/', true)) {
94
+        return $charset;
95
+    } else {
96
+        spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
97
+        $GLOBALS['CHARSET'][$charset] = [];
98
+
99
+        return false;
100
+    }
101 101
 }
102 102
 
103 103
 
@@ -110,19 +110,19 @@  discard block
 block discarded – undo
110 110
  *     true si notre charset est utilisable par mb_strsing
111 111
  **/
112 112
 function init_mb_string(): bool {
113
-	static $mb;
114
-
115
-	// verifier que le charset interne est connu de mb_string
116
-	if (!$mb) {
117
-		if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) {
118
-			mb_internal_encoding('utf-8');
119
-			$mb = 1;
120
-		} else {
121
-			$mb = -1;
122
-		}
123
-	}
124
-
125
-	return ($mb === 1);
113
+    static $mb;
114
+
115
+    // verifier que le charset interne est connu de mb_string
116
+    if (!$mb) {
117
+        if (mb_detect_order(lire_config('charset', _DEFAULT_CHARSET))) {
118
+            mb_internal_encoding('utf-8');
119
+            $mb = 1;
120
+        } else {
121
+            $mb = -1;
122
+        }
123
+    }
124
+
125
+    return ($mb === 1);
126 126
 }
127 127
 
128 128
 /**
@@ -137,21 +137,21 @@  discard block
 block discarded – undo
137 137
  *     true si iconv fonctionne correctement
138 138
  **/
139 139
 function test_iconv(): bool {
140
-	static $iconv_ok;
141
-
142
-	if (!$iconv_ok) {
143
-		if (!function_exists('iconv')) {
144
-			$iconv_ok = -1;
145
-		} else {
146
-			if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test') {
147
-				$iconv_ok = 1;
148
-			} else {
149
-				$iconv_ok = -1;
150
-			}
151
-		}
152
-	}
153
-
154
-	return ($iconv_ok === 1);
140
+    static $iconv_ok;
141
+
142
+    if (!$iconv_ok) {
143
+        if (!function_exists('iconv')) {
144
+            $iconv_ok = -1;
145
+        } else {
146
+            if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) === 'chaine de test') {
147
+                $iconv_ok = 1;
148
+            } else {
149
+                $iconv_ok = -1;
150
+            }
151
+        }
152
+    }
153
+
154
+    return ($iconv_ok === 1);
155 155
 }
156 156
 
157 157
 /**
@@ -171,75 +171,75 @@  discard block
 block discarded – undo
171 171
  *     texte corrigé
172 172
  **/
173 173
 function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') {
174
-	static $trans;
175
-
176
-	if (is_array($texte)) {
177
-		return array_map('corriger_caracteres_windows', $texte);
178
-	}
179
-
180
-	if ($charset == 'AUTO') {
181
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
182
-	}
183
-	if ($charset == 'utf-8') {
184
-		$p = chr(194);
185
-		if (strpos($texte, $p) == false) {
186
-			return $texte;
187
-		}
188
-	} else {
189
-		if ($charset == 'iso-8859-1') {
190
-			$p = '';
191
-		} else {
192
-			return $texte;
193
-		}
194
-	}
195
-
196
-	if (!isset($trans[$charset][$charset_cible])) {
197
-		$trans[$charset][$charset_cible] = [
198
-			$p . chr(128) => '&#8364;',
199
-			$p . chr(129) => ' ', # pas affecte
200
-			$p . chr(130) => '&#8218;',
201
-			$p . chr(131) => '&#402;',
202
-			$p . chr(132) => '&#8222;',
203
-			$p . chr(133) => '&#8230;',
204
-			$p . chr(134) => '&#8224;',
205
-			$p . chr(135) => '&#8225;',
206
-			$p . chr(136) => '&#710;',
207
-			$p . chr(137) => '&#8240;',
208
-			$p . chr(138) => '&#352;',
209
-			$p . chr(139) => '&#8249;',
210
-			$p . chr(140) => '&#338;',
211
-			$p . chr(141) => ' ', # pas affecte
212
-			$p . chr(142) => '&#381;',
213
-			$p . chr(143) => ' ', # pas affecte
214
-			$p . chr(144) => ' ', # pas affecte
215
-			$p . chr(145) => '&#8216;',
216
-			$p . chr(146) => '&#8217;',
217
-			$p . chr(147) => '&#8220;',
218
-			$p . chr(148) => '&#8221;',
219
-			$p . chr(149) => '&#8226;',
220
-			$p . chr(150) => '&#8211;',
221
-			$p . chr(151) => '&#8212;',
222
-			$p . chr(152) => '&#732;',
223
-			$p . chr(153) => '&#8482;',
224
-			$p . chr(154) => '&#353;',
225
-			$p . chr(155) => '&#8250;',
226
-			$p . chr(156) => '&#339;',
227
-			$p . chr(157) => ' ', # pas affecte
228
-			$p . chr(158) => '&#382;',
229
-			$p . chr(159) => '&#376;',
230
-		];
231
-		if ($charset_cible != 'unicode') {
232
-			foreach ($trans[$charset][$charset_cible] as $k => $c) {
233
-				$trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
234
-			}
235
-		}
236
-	}
237
-
238
-	return @str_replace(
239
-		array_keys($trans[$charset][$charset_cible]),
240
-		array_values($trans[$charset][$charset_cible]),
241
-		$texte
242
-	);
174
+    static $trans;
175
+
176
+    if (is_array($texte)) {
177
+        return array_map('corriger_caracteres_windows', $texte);
178
+    }
179
+
180
+    if ($charset == 'AUTO') {
181
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
182
+    }
183
+    if ($charset == 'utf-8') {
184
+        $p = chr(194);
185
+        if (strpos($texte, $p) == false) {
186
+            return $texte;
187
+        }
188
+    } else {
189
+        if ($charset == 'iso-8859-1') {
190
+            $p = '';
191
+        } else {
192
+            return $texte;
193
+        }
194
+    }
195
+
196
+    if (!isset($trans[$charset][$charset_cible])) {
197
+        $trans[$charset][$charset_cible] = [
198
+            $p . chr(128) => '&#8364;',
199
+            $p . chr(129) => ' ', # pas affecte
200
+            $p . chr(130) => '&#8218;',
201
+            $p . chr(131) => '&#402;',
202
+            $p . chr(132) => '&#8222;',
203
+            $p . chr(133) => '&#8230;',
204
+            $p . chr(134) => '&#8224;',
205
+            $p . chr(135) => '&#8225;',
206
+            $p . chr(136) => '&#710;',
207
+            $p . chr(137) => '&#8240;',
208
+            $p . chr(138) => '&#352;',
209
+            $p . chr(139) => '&#8249;',
210
+            $p . chr(140) => '&#338;',
211
+            $p . chr(141) => ' ', # pas affecte
212
+            $p . chr(142) => '&#381;',
213
+            $p . chr(143) => ' ', # pas affecte
214
+            $p . chr(144) => ' ', # pas affecte
215
+            $p . chr(145) => '&#8216;',
216
+            $p . chr(146) => '&#8217;',
217
+            $p . chr(147) => '&#8220;',
218
+            $p . chr(148) => '&#8221;',
219
+            $p . chr(149) => '&#8226;',
220
+            $p . chr(150) => '&#8211;',
221
+            $p . chr(151) => '&#8212;',
222
+            $p . chr(152) => '&#732;',
223
+            $p . chr(153) => '&#8482;',
224
+            $p . chr(154) => '&#353;',
225
+            $p . chr(155) => '&#8250;',
226
+            $p . chr(156) => '&#339;',
227
+            $p . chr(157) => ' ', # pas affecte
228
+            $p . chr(158) => '&#382;',
229
+            $p . chr(159) => '&#376;',
230
+        ];
231
+        if ($charset_cible != 'unicode') {
232
+            foreach ($trans[$charset][$charset_cible] as $k => $c) {
233
+                $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible);
234
+            }
235
+        }
236
+    }
237
+
238
+    return @str_replace(
239
+        array_keys($trans[$charset][$charset_cible]),
240
+        array_values($trans[$charset][$charset_cible]),
241
+        $texte
242
+    );
243 243
 }
244 244
 
245 245
 
@@ -256,26 +256,26 @@  discard block
 block discarded – undo
256 256
  *     texte converti
257 257
  **/
258 258
 function html2unicode($texte, $secure = false) {
259
-	if (strpos($texte, '&') === false) {
260
-		return $texte;
261
-	}
262
-	static $trans = [];
263
-	if (!$trans) {
264
-		load_charset('html');
265
-		foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
266
-			$trans["&$key;"] = $val;
267
-		}
268
-	}
269
-
270
-	if ($secure) {
271
-		return str_replace(array_keys($trans), array_values($trans), $texte);
272
-	} else {
273
-		return str_replace(
274
-			['&amp;', '&quot;', '&lt;', '&gt;'],
275
-			['&', '"', '<', '>'],
276
-			str_replace(array_keys($trans), array_values($trans), $texte)
277
-		);
278
-	}
259
+    if (strpos($texte, '&') === false) {
260
+        return $texte;
261
+    }
262
+    static $trans = [];
263
+    if (!$trans) {
264
+        load_charset('html');
265
+        foreach ($GLOBALS['CHARSET']['html'] as $key => $val) {
266
+            $trans["&$key;"] = $val;
267
+        }
268
+    }
269
+
270
+    if ($secure) {
271
+        return str_replace(array_keys($trans), array_values($trans), $texte);
272
+    } else {
273
+        return str_replace(
274
+            ['&amp;', '&quot;', '&lt;', '&gt;'],
275
+            ['&', '"', '<', '>'],
276
+            str_replace(array_keys($trans), array_values($trans), $texte)
277
+        );
278
+    }
279 279
 }
280 280
 
281 281
 
@@ -290,16 +290,16 @@  discard block
 block discarded – undo
290 290
  *     texte converti
291 291
  **/
292 292
 function mathml2unicode($texte) {
293
-	static $trans;
294
-	if (!$trans) {
295
-		load_charset('mathml');
293
+    static $trans;
294
+    if (!$trans) {
295
+        load_charset('mathml');
296 296
 
297
-		foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
298
-			$trans["&$key;"] = $val;
299
-		}
300
-	}
297
+        foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) {
298
+            $trans["&$key;"] = $val;
299
+        }
300
+    }
301 301
 
302
-	return str_replace(array_keys($trans), array_values($trans), $texte);
302
+    return str_replace(array_keys($trans), array_values($trans), $texte);
303 303
 }
304 304
 
305 305
 
@@ -321,75 +321,75 @@  discard block
 block discarded – undo
321 321
  *     texte converti en unicode
322 322
  **/
323 323
 function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) {
324
-	static $trans;
325
-
326
-	if ($charset === 'AUTO') {
327
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
328
-	}
329
-
330
-	if ($charset === '') {
331
-		$charset = 'iso-8859-1';
332
-	}
333
-	$charset = strtolower($charset);
334
-
335
-	switch ($charset) {
336
-		case 'utf-8':
337
-		case 'utf8':
338
-			return utf_8_to_unicode($texte);
339
-
340
-		case 'iso-8859-1':
341
-			$texte = corriger_caracteres_windows($texte, 'iso-8859-1');
342
-		// pas de break; ici, on suit sur default:
343
-
344
-		default:
345
-			// mbstring presente ?
346
-			if (init_mb_string()) {
347
-				$order = mb_detect_order();
348
-				try {
349
-					# mb_string connait-il $charset?
350
-					if ($order and mb_detect_order($charset)) {
351
-						$s = mb_convert_encoding($texte, 'utf-8', $charset);
352
-						if ($s && $s != $texte) {
353
-							return utf_8_to_unicode($s);
354
-						}
355
-					}
356
-				} catch (\Error $e) {
357
-					// Le charset n'existe probablement pas
358
-				} finally {
359
-					mb_detect_order($order); # remettre comme precedemment
360
-				}
361
-			}
362
-
363
-			// Sinon, peut-etre connaissons-nous ce charset ?
364
-			if (!isset($trans[$charset])) {
365
-				if (
366
-					$cset = load_charset($charset)
367
-					and is_array($GLOBALS['CHARSET'][$cset])
368
-				) {
369
-					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
370
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
371
-					}
372
-				}
373
-			}
374
-			if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
375
-				return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
376
-			}
377
-
378
-			// Sinon demander a iconv (malgre le fait qu'il coupe quand un
379
-			// caractere n'appartient pas au charset, mais c'est un probleme
380
-			// surtout en utf-8, gere ci-dessus)
381
-			if (test_iconv()) {
382
-				$s = iconv($charset, 'utf-32le', $texte);
383
-				if ($s) {
384
-					return utf_32_to_unicode($s);
385
-				}
386
-			}
387
-
388
-			// Au pire ne rien faire
389
-			spip_log("erreur charset '$charset' non supporte");
390
-
391
-			return $texte;
392
-	}
324
+    static $trans;
325
+
326
+    if ($charset === 'AUTO') {
327
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
328
+    }
329
+
330
+    if ($charset === '') {
331
+        $charset = 'iso-8859-1';
332
+    }
333
+    $charset = strtolower($charset);
334
+
335
+    switch ($charset) {
336
+        case 'utf-8':
337
+        case 'utf8':
338
+            return utf_8_to_unicode($texte);
339
+
340
+        case 'iso-8859-1':
341
+            $texte = corriger_caracteres_windows($texte, 'iso-8859-1');
342
+        // pas de break; ici, on suit sur default:
343
+
344
+        default:
345
+            // mbstring presente ?
346
+            if (init_mb_string()) {
347
+                $order = mb_detect_order();
348
+                try {
349
+                    # mb_string connait-il $charset?
350
+                    if ($order and mb_detect_order($charset)) {
351
+                        $s = mb_convert_encoding($texte, 'utf-8', $charset);
352
+                        if ($s && $s != $texte) {
353
+                            return utf_8_to_unicode($s);
354
+                        }
355
+                    }
356
+                } catch (\Error $e) {
357
+                    // Le charset n'existe probablement pas
358
+                } finally {
359
+                    mb_detect_order($order); # remettre comme precedemment
360
+                }
361
+            }
362
+
363
+            // Sinon, peut-etre connaissons-nous ce charset ?
364
+            if (!isset($trans[$charset])) {
365
+                if (
366
+                    $cset = load_charset($charset)
367
+                    and is_array($GLOBALS['CHARSET'][$cset])
368
+                ) {
369
+                    foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
370
+                        $trans[$charset][chr($key)] = '&#' . $val . ';';
371
+                    }
372
+                }
373
+            }
374
+            if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
375
+                return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
376
+            }
377
+
378
+            // Sinon demander a iconv (malgre le fait qu'il coupe quand un
379
+            // caractere n'appartient pas au charset, mais c'est un probleme
380
+            // surtout en utf-8, gere ci-dessus)
381
+            if (test_iconv()) {
382
+                $s = iconv($charset, 'utf-32le', $texte);
383
+                if ($s) {
384
+                    return utf_32_to_unicode($s);
385
+                }
386
+            }
387
+
388
+            // Au pire ne rien faire
389
+            spip_log("erreur charset '$charset' non supporte");
390
+
391
+            return $texte;
392
+    }
393 393
 }
394 394
 
395 395
 
@@ -408,43 +408,43 @@  discard block
 block discarded – undo
408 408
  *     texte transformé dans le charset souhaité
409 409
  **/
410 410
 function unicode2charset($texte, $charset = 'AUTO') {
411
-	static $CHARSET_REVERSE = [];
412
-	static $trans = [];
413
-
414
-	if ($charset == 'AUTO') {
415
-		$charset = lire_config('charset', _DEFAULT_CHARSET);
416
-	}
417
-
418
-	switch ($charset) {
419
-		case 'utf-8':
420
-			return unicode_to_utf_8($texte);
421
-
422
-		default:
423
-			$charset = load_charset($charset);
424
-
425
-			if (empty($CHARSET_REVERSE[$charset])) {
426
-				$CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
427
-			}
428
-
429
-			if (!isset($trans[$charset])) {
430
-				$trans[$charset] = [];
431
-				$t = &$trans[$charset];
432
-				for ($e = 128; $e < 255; $e++) {
433
-					$h = dechex($e);
434
-					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
435
-						$s = $CHARSET_REVERSE[$charset][$e];
436
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
437
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
438
-					} else {
439
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
440
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
441
-					}
442
-				}
443
-			}
444
-			$texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
445
-
446
-			return $texte;
447
-	}
411
+    static $CHARSET_REVERSE = [];
412
+    static $trans = [];
413
+
414
+    if ($charset == 'AUTO') {
415
+        $charset = lire_config('charset', _DEFAULT_CHARSET);
416
+    }
417
+
418
+    switch ($charset) {
419
+        case 'utf-8':
420
+            return unicode_to_utf_8($texte);
421
+
422
+        default:
423
+            $charset = load_charset($charset);
424
+
425
+            if (empty($CHARSET_REVERSE[$charset])) {
426
+                $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]);
427
+            }
428
+
429
+            if (!isset($trans[$charset])) {
430
+                $trans[$charset] = [];
431
+                $t = &$trans[$charset];
432
+                for ($e = 128; $e < 255; $e++) {
433
+                    $h = dechex($e);
434
+                    if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
435
+                        $s = $CHARSET_REVERSE[$charset][$e];
436
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
437
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
438
+                    } else {
439
+                        $t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
440
+                        $t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
441
+                    }
442
+                }
443
+            }
444
+            $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
445
+
446
+            return $texte;
447
+    }
448 448
 }
449 449
 
450 450
 
@@ -462,40 +462,40 @@  discard block
 block discarded – undo
462 462
  *     texte transformé dans le charset site
463 463
  **/
464 464
 function importer_charset($texte, $charset = 'AUTO') {
465
-	$s = null;
466
-	static $trans = [];
467
-	// on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
468
-	if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
469
-		$texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
470
-		if (init_mb_string()) {
471
-			if (
472
-				$order = mb_detect_order() # mb_string connait-il $charset?
473
-				and mb_detect_order($charset)
474
-			) {
475
-				$s = mb_convert_encoding($texte, 'utf-8', $charset);
476
-			}
477
-			mb_detect_order($order); # remettre comme precedemment
478
-			return $s;
479
-		}
480
-		// Sinon, peut-etre connaissons-nous ce charset ?
481
-		if (!isset($trans[$charset])) {
482
-			if (
483
-				$cset = load_charset($charset)
484
-				and is_array($GLOBALS['CHARSET'][$cset])
485
-			) {
486
-				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
487
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
488
-				}
489
-			}
490
-		}
491
-		if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
492
-			return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
493
-		}
494
-
495
-		return $texte;
496
-	}
497
-
498
-	return unicode2charset(charset2unicode($texte, $charset));
465
+    $s = null;
466
+    static $trans = [];
467
+    // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite !
468
+    if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) {
469
+        $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']);
470
+        if (init_mb_string()) {
471
+            if (
472
+                $order = mb_detect_order() # mb_string connait-il $charset?
473
+                and mb_detect_order($charset)
474
+            ) {
475
+                $s = mb_convert_encoding($texte, 'utf-8', $charset);
476
+            }
477
+            mb_detect_order($order); # remettre comme precedemment
478
+            return $s;
479
+        }
480
+        // Sinon, peut-etre connaissons-nous ce charset ?
481
+        if (!isset($trans[$charset])) {
482
+            if (
483
+                $cset = load_charset($charset)
484
+                and is_array($GLOBALS['CHARSET'][$cset])
485
+            ) {
486
+                foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
487
+                    $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
488
+                }
489
+            }
490
+        }
491
+        if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) {
492
+            return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte);
493
+        }
494
+
495
+        return $texte;
496
+    }
497
+
498
+    return unicode2charset(charset2unicode($texte, $charset));
499 499
 }
500 500
 
501 501
 
@@ -511,92 +511,92 @@  discard block
 block discarded – undo
511 511
  **/
512 512
 function utf_8_to_unicode($source) {
513 513
 
514
-	// mb_string : methode rapide
515
-	if (init_mb_string()) {
516
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
517
-
518
-		return mb_encode_numericentity($source, $convmap, 'UTF-8');
519
-	}
520
-
521
-	// Sinon methode pas a pas
522
-	static $decrement;
523
-	static $shift;
524
-
525
-	// Cf. php.net, par Ronen. Adapte pour compatibilite < php4
526
-	if (!is_array($decrement)) {
527
-		// array used to figure what number to decrement from character order value
528
-		// according to number of characters used to map unicode to ascii by utf-8
529
-		$decrement[4] = 240;
530
-		$decrement[3] = 224;
531
-		$decrement[2] = 192;
532
-		$decrement[1] = 0;
533
-		// the number of bits to shift each charNum by
534
-		$shift[1][0] = 0;
535
-		$shift[2][0] = 6;
536
-		$shift[2][1] = 0;
537
-		$shift[3][0] = 12;
538
-		$shift[3][1] = 6;
539
-		$shift[3][2] = 0;
540
-		$shift[4][0] = 18;
541
-		$shift[4][1] = 12;
542
-		$shift[4][2] = 6;
543
-		$shift[4][3] = 0;
544
-	}
545
-
546
-	$pos = 0;
547
-	$len = strlen($source);
548
-	$encodedString = '';
549
-	while ($pos < $len) {
550
-		$char = '';
551
-		$ischar = false;
552
-		$asciiPos = ord(substr($source, $pos, 1));
553
-		if (($asciiPos >= 240) && ($asciiPos <= 255)) {
554
-			// 4 chars representing one unicode character
555
-			$thisLetter = substr($source, $pos, 4);
556
-			$pos += 4;
557
-		} else {
558
-			if (($asciiPos >= 224) && ($asciiPos <= 239)) {
559
-				// 3 chars representing one unicode character
560
-				$thisLetter = substr($source, $pos, 3);
561
-				$pos += 3;
562
-			} else {
563
-				if (($asciiPos >= 192) && ($asciiPos <= 223)) {
564
-					// 2 chars representing one unicode character
565
-					$thisLetter = substr($source, $pos, 2);
566
-					$pos += 2;
567
-				} else {
568
-					// 1 char (lower ascii)
569
-					$thisLetter = substr($source, $pos, 1);
570
-					$pos += 1;
571
-					$char = $thisLetter;
572
-					$ischar = true;
573
-				}
574
-			}
575
-		}
576
-
577
-		if ($ischar) {
578
-			$encodedString .= $char;
579
-		} else {  // process the string representing the letter to a unicode entity
580
-			$thisLen = strlen($thisLetter);
581
-			$thisPos = 0;
582
-			$decimalCode = 0;
583
-			while ($thisPos < $thisLen) {
584
-				$thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
585
-				if ($thisPos == 0) {
586
-					$charNum = intval($thisCharOrd - $decrement[$thisLen]);
587
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
588
-				} else {
589
-					$charNum = intval($thisCharOrd - 128);
590
-					$decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
591
-				}
592
-				$thisPos++;
593
-			}
594
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
595
-			$encodedString .= $encodedLetter;
596
-		}
597
-	}
598
-
599
-	return $encodedString;
514
+    // mb_string : methode rapide
515
+    if (init_mb_string()) {
516
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
517
+
518
+        return mb_encode_numericentity($source, $convmap, 'UTF-8');
519
+    }
520
+
521
+    // Sinon methode pas a pas
522
+    static $decrement;
523
+    static $shift;
524
+
525
+    // Cf. php.net, par Ronen. Adapte pour compatibilite < php4
526
+    if (!is_array($decrement)) {
527
+        // array used to figure what number to decrement from character order value
528
+        // according to number of characters used to map unicode to ascii by utf-8
529
+        $decrement[4] = 240;
530
+        $decrement[3] = 224;
531
+        $decrement[2] = 192;
532
+        $decrement[1] = 0;
533
+        // the number of bits to shift each charNum by
534
+        $shift[1][0] = 0;
535
+        $shift[2][0] = 6;
536
+        $shift[2][1] = 0;
537
+        $shift[3][0] = 12;
538
+        $shift[3][1] = 6;
539
+        $shift[3][2] = 0;
540
+        $shift[4][0] = 18;
541
+        $shift[4][1] = 12;
542
+        $shift[4][2] = 6;
543
+        $shift[4][3] = 0;
544
+    }
545
+
546
+    $pos = 0;
547
+    $len = strlen($source);
548
+    $encodedString = '';
549
+    while ($pos < $len) {
550
+        $char = '';
551
+        $ischar = false;
552
+        $asciiPos = ord(substr($source, $pos, 1));
553
+        if (($asciiPos >= 240) && ($asciiPos <= 255)) {
554
+            // 4 chars representing one unicode character
555
+            $thisLetter = substr($source, $pos, 4);
556
+            $pos += 4;
557
+        } else {
558
+            if (($asciiPos >= 224) && ($asciiPos <= 239)) {
559
+                // 3 chars representing one unicode character
560
+                $thisLetter = substr($source, $pos, 3);
561
+                $pos += 3;
562
+            } else {
563
+                if (($asciiPos >= 192) && ($asciiPos <= 223)) {
564
+                    // 2 chars representing one unicode character
565
+                    $thisLetter = substr($source, $pos, 2);
566
+                    $pos += 2;
567
+                } else {
568
+                    // 1 char (lower ascii)
569
+                    $thisLetter = substr($source, $pos, 1);
570
+                    $pos += 1;
571
+                    $char = $thisLetter;
572
+                    $ischar = true;
573
+                }
574
+            }
575
+        }
576
+
577
+        if ($ischar) {
578
+            $encodedString .= $char;
579
+        } else {  // process the string representing the letter to a unicode entity
580
+            $thisLen = strlen($thisLetter);
581
+            $thisPos = 0;
582
+            $decimalCode = 0;
583
+            while ($thisPos < $thisLen) {
584
+                $thisCharOrd = ord(substr($thisLetter, $thisPos, 1));
585
+                if ($thisPos == 0) {
586
+                    $charNum = intval($thisCharOrd - $decrement[$thisLen]);
587
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
588
+                } else {
589
+                    $charNum = intval($thisCharOrd - 128);
590
+                    $decimalCode += ($charNum << $shift[$thisLen][$thisPos]);
591
+                }
592
+                $thisPos++;
593
+            }
594
+            $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
595
+            $encodedString .= $encodedLetter;
596
+        }
597
+    }
598
+
599
+    return $encodedString;
600 600
 }
601 601
 
602 602
 /**
@@ -615,32 +615,32 @@  discard block
 block discarded – undo
615 615
  **/
616 616
 function utf_32_to_unicode($source) {
617 617
 
618
-	// mb_string : methode rapide
619
-	if (init_mb_string()) {
620
-		$convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
621
-		$source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
622
-
623
-		return str_replace(chr(0), '', $source);
624
-	}
625
-
626
-	// Sinon methode lente
627
-	$texte = '';
628
-	while ($source) {
629
-		$words = unpack('V*', substr($source, 0, 1024));
630
-		$source = substr($source, 1024);
631
-		foreach ($words as $word) {
632
-			if ($word < 128) {
633
-				$texte .= chr($word);
634
-			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
635
-			else {
636
-				if ($word != 65279) {
637
-					$texte .= '&#' . $word . ';';
638
-				}
639
-			}
640
-		}
641
-	}
642
-
643
-	return $texte;
618
+    // mb_string : methode rapide
619
+    if (init_mb_string()) {
620
+        $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF];
621
+        $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE');
622
+
623
+        return str_replace(chr(0), '', $source);
624
+    }
625
+
626
+    // Sinon methode lente
627
+    $texte = '';
628
+    while ($source) {
629
+        $words = unpack('V*', substr($source, 0, 1024));
630
+        $source = substr($source, 1024);
631
+        foreach ($words as $word) {
632
+            if ($word < 128) {
633
+                $texte .= chr($word);
634
+            } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
635
+            else {
636
+                if ($word != 65279) {
637
+                    $texte .= '&#' . $word . ';';
638
+                }
639
+            }
640
+        }
641
+    }
642
+
643
+    return $texte;
644 644
 }
645 645
 
646 646
 
@@ -657,21 +657,21 @@  discard block
 block discarded – undo
657 657
  *    Caractère utf8 si trouvé, '' sinon
658 658
  **/
659 659
 function caractere_utf_8($num) {
660
-	$num = intval($num);
661
-	if ($num < 128) {
662
-		return chr($num);
663
-	}
664
-	if ($num < 2048) {
665
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
666
-	}
667
-	if ($num < 65536) {
668
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
669
-	}
670
-	if ($num < 1_114_112) {
671
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
672
-	}
673
-
674
-	return '';
660
+    $num = intval($num);
661
+    if ($num < 128) {
662
+        return chr($num);
663
+    }
664
+    if ($num < 2048) {
665
+        return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
666
+    }
667
+    if ($num < 65536) {
668
+        return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
669
+    }
670
+    if ($num < 1_114_112) {
671
+        return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
672
+    }
673
+
674
+    return '';
675 675
 }
676 676
 
677 677
 /**
@@ -684,42 +684,42 @@  discard block
 block discarded – undo
684 684
  **/
685 685
 function unicode_to_utf_8($texte) {
686 686
 
687
-	// 1. Entites &#128; et suivantes
688
-	$vu = [];
689
-	if (
690
-		preg_match_all(
691
-			',&#0*([1-9][0-9][0-9]+);,S',
692
-			$texte,
693
-			$regs,
694
-			PREG_SET_ORDER
695
-		)
696
-	) {
697
-		foreach ($regs as $reg) {
698
-			if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
699
-				$vu[$reg[0]] = caractere_utf_8($reg[1]);
700
-			}
701
-		}
702
-	}
703
-	//$texte = str_replace(array_keys($vu), array_values($vu), $texte);
704
-
705
-	// 2. Entites > &#xFF;
706
-	//$vu = array();
707
-	if (
708
-		preg_match_all(
709
-			',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
710
-			$texte,
711
-			$regs,
712
-			PREG_SET_ORDER
713
-		)
714
-	) {
715
-		foreach ($regs as $reg) {
716
-			if (!isset($vu[$reg[0]])) {
717
-				$vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
718
-			}
719
-		}
720
-	}
721
-
722
-	return str_replace(array_keys($vu), array_values($vu), $texte);
687
+    // 1. Entites &#128; et suivantes
688
+    $vu = [];
689
+    if (
690
+        preg_match_all(
691
+            ',&#0*([1-9][0-9][0-9]+);,S',
692
+            $texte,
693
+            $regs,
694
+            PREG_SET_ORDER
695
+        )
696
+    ) {
697
+        foreach ($regs as $reg) {
698
+            if ($reg[1] > 127 and !isset($vu[$reg[0]])) {
699
+                $vu[$reg[0]] = caractere_utf_8($reg[1]);
700
+            }
701
+        }
702
+    }
703
+    //$texte = str_replace(array_keys($vu), array_values($vu), $texte);
704
+
705
+    // 2. Entites > &#xFF;
706
+    //$vu = array();
707
+    if (
708
+        preg_match_all(
709
+            ',&#x0*([1-9a-f][0-9a-f][0-9a-f]+);,iS',
710
+            $texte,
711
+            $regs,
712
+            PREG_SET_ORDER
713
+        )
714
+    ) {
715
+        foreach ($regs as $reg) {
716
+            if (!isset($vu[$reg[0]])) {
717
+                $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1]));
718
+            }
719
+        }
720
+    }
721
+
722
+    return str_replace(array_keys($vu), array_values($vu), $texte);
723 723
 }
724 724
 
725 725
 /**
@@ -731,15 +731,15 @@  discard block
 block discarded – undo
731 731
  *     texte converti
732 732
  **/
733 733
 function unicode_to_javascript($texte) {
734
-	$vu = [];
735
-	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
736
-		$num = $regs[1];
737
-		$vu[$num] = true;
738
-		$s = '\u' . sprintf('%04x', $num);
739
-		$texte = str_replace($regs[0], $s, $texte);
740
-	}
741
-
742
-	return $texte;
734
+    $vu = [];
735
+    while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
736
+        $num = $regs[1];
737
+        $vu[$num] = true;
738
+        $s = '\u' . sprintf('%04x', $num);
739
+        $texte = str_replace($regs[0], $s, $texte);
740
+    }
741
+
742
+    return $texte;
743 743
 }
744 744
 
745 745
 /**
@@ -751,11 +751,11 @@  discard block
 block discarded – undo
751 751
  *     texte converti
752 752
  **/
753 753
 function javascript_to_unicode($texte) {
754
-	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
755
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
756
-	}
754
+    while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
755
+        $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
756
+    }
757 757
 
758
-	return $texte;
758
+    return $texte;
759 759
 }
760 760
 
761 761
 /**
@@ -767,11 +767,11 @@  discard block
 block discarded – undo
767 767
  *     texte converti
768 768
  **/
769 769
 function javascript_to_binary($texte) {
770
-	while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
771
-		$texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
772
-	}
770
+    while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) {
771
+        $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte);
772
+    }
773 773
 
774
-	return $texte;
774
+    return $texte;
775 775
 }
776 776
 
777 777
 
@@ -789,26 +789,26 @@  discard block
 block discarded – undo
789 789
  * @return string
790 790
  */
791 791
 function translitteration_rapide($texte, $charset = 'AUTO', $complexe = ''): string {
792
-	static $trans = [];
793
-	if ($charset == 'AUTO') {
794
-		$charset = $GLOBALS['meta']['charset'];
795
-	}
796
-	if (!strlen($texte)) {
797
-		return $texte;
798
-	}
799
-
800
-	$table_translit = 'translit' . $complexe;
801
-
802
-	// 2. Translitterer grace a la table predefinie
803
-	if (!isset($trans[$complexe])) {
804
-		$trans[$complexe] = [];
805
-		load_charset($table_translit);
806
-		foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
807
-			$trans[$complexe][caractere_utf_8($key)] = $val;
808
-		}
809
-	}
810
-
811
-	return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
792
+    static $trans = [];
793
+    if ($charset == 'AUTO') {
794
+        $charset = $GLOBALS['meta']['charset'];
795
+    }
796
+    if (!strlen($texte)) {
797
+        return $texte;
798
+    }
799
+
800
+    $table_translit = 'translit' . $complexe;
801
+
802
+    // 2. Translitterer grace a la table predefinie
803
+    if (!isset($trans[$complexe])) {
804
+        $trans[$complexe] = [];
805
+        load_charset($table_translit);
806
+        foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) {
807
+            $trans[$complexe][caractere_utf_8($key)] = $val;
808
+        }
809
+    }
810
+
811
+    return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte);
812 812
 }
813 813
 
814 814
 /**
@@ -831,14 +831,14 @@  discard block
 block discarded – undo
831 831
  * @return string
832 832
  */
833 833
 function translitteration($texte, $charset = 'AUTO', $complexe = ''): string {
834
-	// 0. Supprimer les caracteres illegaux
835
-	include_spip('inc/filtres');
836
-	$texte = corriger_caracteres($texte);
834
+    // 0. Supprimer les caracteres illegaux
835
+    include_spip('inc/filtres');
836
+    $texte = corriger_caracteres($texte);
837 837
 
838
-	// 1. Passer le charset et les &eacute en utf-8
839
-	$texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset)));
838
+    // 1. Passer le charset et les &eacute en utf-8
839
+    $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset)));
840 840
 
841
-	return translitteration_rapide($texte, $charset, $complexe);
841
+    return translitteration_rapide($texte, $charset, $complexe);
842 842
 }
843 843
 
844 844
 /**
@@ -853,17 +853,17 @@  discard block
 block discarded – undo
853 853
  * @return string
854 854
  */
855 855
 function translitteration_complexe($texte, $chiffres = false): string {
856
-	$texte = translitteration($texte, 'AUTO', 'complexe');
856
+    $texte = translitteration($texte, 'AUTO', 'complexe');
857 857
 
858
-	if ($chiffres) {
859
-		$texte = preg_replace_callback(
860
-			"/[aeiuoyd]['`?~.^+(-]{1,2}/S",
861
-			fn($m) => translitteration_chiffree($m[0]),
862
-			$texte
863
-		);
864
-	}
858
+    if ($chiffres) {
859
+        $texte = preg_replace_callback(
860
+            "/[aeiuoyd]['`?~.^+(-]{1,2}/S",
861
+            fn($m) => translitteration_chiffree($m[0]),
862
+            $texte
863
+        );
864
+    }
865 865
 
866
-	return $texte;
866
+    return $texte;
867 867
 }
868 868
 
869 869
 /**
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
  * @return string
876 876
  */
877 877
 function translitteration_chiffree($car): string {
878
-	return strtr($car, "'`?~.^+(-", '123456789');
878
+    return strtr($car, "'`?~.^+(-", '123456789');
879 879
 }
880 880
 
881 881
 
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
  *    true s'il a un BOM
889 889
  **/
890 890
 function bom_utf8($texte): bool {
891
-	return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
891
+    return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
892 892
 }
893 893
 
894 894
 /**
@@ -905,21 +905,21 @@  discard block
 block discarded – undo
905 905
  *     true si c'est le cas
906 906
  **/
907 907
 function is_utf8($string): bool {
908
-	return !strlen(
909
-		preg_replace(
910
-			',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
911
-			. '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
912
-			. '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
913
-			. '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
914
-			. '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
915
-			. '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
916
-			. '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
917
-			. '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
918
-			. ',sS',
919
-			'',
920
-			$string
921
-		)
922
-	);
908
+    return !strlen(
909
+        preg_replace(
910
+            ',[\x09\x0A\x0D\x20-\x7E]'            # ASCII
911
+            . '|[\xC2-\xDF][\x80-\xBF]'             # non-overlong 2-byte
912
+            . '|\xE0[\xA0-\xBF][\x80-\xBF]'         # excluding overlongs
913
+            . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}'  # straight 3-byte
914
+            . '|\xED[\x80-\x9F][\x80-\xBF]'         # excluding surrogates
915
+            . '|\xF0[\x90-\xBF][\x80-\xBF]{2}'      # planes 1-3
916
+            . '|[\xF1-\xF3][\x80-\xBF]{3}'          # planes 4-15
917
+            . '|\xF4[\x80-\x8F][\x80-\xBF]{2}'      # plane 16
918
+            . ',sS',
919
+            '',
920
+            $string
921
+        )
922
+    );
923 923
 }
924 924
 
925 925
 /**
@@ -931,13 +931,13 @@  discard block
 block discarded – undo
931 931
  *     true si c'est le cas
932 932
  **/
933 933
 function is_ascii($string): bool {
934
-	return !strlen(
935
-		preg_replace(
936
-			',[\x09\x0A\x0D\x20-\x7E],sS',
937
-			'',
938
-			$string
939
-		)
940
-	);
934
+    return !strlen(
935
+        preg_replace(
936
+            ',[\x09\x0A\x0D\x20-\x7E],sS',
937
+            '',
938
+            $string
939
+        )
940
+    );
941 941
 }
942 942
 
943 943
 /**
@@ -956,53 +956,53 @@  discard block
 block discarded – undo
956 956
  **/
957 957
 function transcoder_page($texte, $headers = ''): string {
958 958
 
959
-	// Si tout est < 128 pas la peine d'aller plus loin
960
-	if (is_ascii($texte)) {
961
-		#spip_log('charset: ascii');
962
-		return $texte;
963
-	}
964
-
965
-	if (bom_utf8($texte)) {
966
-		// Reconnaitre le BOM utf-8 (0xEFBBBF)
967
-		$charset = 'utf-8';
968
-		$texte = substr($texte, 3);
969
-	} elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
970
-		// charset precise par le contenu (xml)
971
-		$charset = trim(strtolower($regs[1]));
972
-	} elseif (
973
-		// charset precise par le contenu (html)
974
-		preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
975
-		# eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
976
-		and !str_contains($regs[2], '#')
977
-		and $tmp = trim(strtolower($regs[2]))
978
-	) {
979
-		$charset = $tmp;
980
-	} elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
981
-		// charset de la reponse http
982
-		$charset = trim(strtolower($regs[1]));
983
-	} else {
984
-		$charset = '';
985
-	}
986
-
987
-
988
-	// normaliser les noms du shif-jis japonais
989
-	if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
990
-		$charset = 'shift-jis';
991
-	}
992
-
993
-	if ($charset) {
994
-		spip_log("charset: $charset");
995
-	} else {
996
-		// valeur par defaut
997
-		if (is_utf8($texte)) {
998
-			$charset = 'utf-8';
999
-		} else {
1000
-			$charset = 'iso-8859-1';
1001
-		}
1002
-		spip_log("charset probable: $charset");
1003
-	}
1004
-
1005
-	return importer_charset($texte, $charset);
959
+    // Si tout est < 128 pas la peine d'aller plus loin
960
+    if (is_ascii($texte)) {
961
+        #spip_log('charset: ascii');
962
+        return $texte;
963
+    }
964
+
965
+    if (bom_utf8($texte)) {
966
+        // Reconnaitre le BOM utf-8 (0xEFBBBF)
967
+        $charset = 'utf-8';
968
+        $texte = substr($texte, 3);
969
+    } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) {
970
+        // charset precise par le contenu (xml)
971
+        $charset = trim(strtolower($regs[1]));
972
+    } elseif (
973
+        // charset precise par le contenu (html)
974
+        preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs)
975
+        # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette
976
+        and !str_contains($regs[2], '#')
977
+        and $tmp = trim(strtolower($regs[2]))
978
+    ) {
979
+        $charset = $tmp;
980
+    } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) {
981
+        // charset de la reponse http
982
+        $charset = trim(strtolower($regs[1]));
983
+    } else {
984
+        $charset = '';
985
+    }
986
+
987
+
988
+    // normaliser les noms du shif-jis japonais
989
+    if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) {
990
+        $charset = 'shift-jis';
991
+    }
992
+
993
+    if ($charset) {
994
+        spip_log("charset: $charset");
995
+    } else {
996
+        // valeur par defaut
997
+        if (is_utf8($texte)) {
998
+            $charset = 'utf-8';
999
+        } else {
1000
+            $charset = 'iso-8859-1';
1001
+        }
1002
+        spip_log("charset probable: $charset");
1003
+    }
1004
+
1005
+    return importer_charset($texte, $charset);
1006 1006
 }
1007 1007
 
1008 1008
 
@@ -1026,19 +1026,19 @@  discard block
 block discarded – undo
1026 1026
  *     Le texte coupé
1027 1027
  **/
1028 1028
 function spip_substr($c, $start = 0, $length = null) {
1029
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1030
-		if ($length) {
1031
-			return substr($c, $start, $length);
1032
-		} else {
1033
-			return substr($c, $start);
1034
-		}
1035
-	}
1036
-
1037
-	if ($length) {
1038
-		return mb_substr($c, $start, $length);
1039
-	} else {
1040
-		return mb_substr($c, $start);
1041
-	}
1029
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1030
+        if ($length) {
1031
+            return substr($c, $start, $length);
1032
+        } else {
1033
+            return substr($c, $start);
1034
+        }
1035
+    }
1036
+
1037
+    if ($length) {
1038
+        return mb_substr($c, $start, $length);
1039
+    } else {
1040
+        return mb_substr($c, $start);
1041
+    }
1042 1042
 }
1043 1043
 
1044 1044
 /**
@@ -1052,13 +1052,13 @@  discard block
 block discarded – undo
1052 1052
  *     La chaîne avec une majuscule sur le premier mot
1053 1053
  */
1054 1054
 function spip_ucfirst($c) {
1055
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1056
-		return ucfirst($c);
1057
-	}
1055
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1056
+        return ucfirst($c);
1057
+    }
1058 1058
 
1059
-	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1059
+    $lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1060 1060
 
1061
-	return $lettre1 . spip_substr($c, 1);
1061
+    return $lettre1 . spip_substr($c, 1);
1062 1062
 }
1063 1063
 
1064 1064
 /**
@@ -1072,11 +1072,11 @@  discard block
 block discarded – undo
1072 1072
  *     La chaîne en minuscules
1073 1073
  */
1074 1074
 function spip_strtolower($c) {
1075
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1076
-		return strtolower($c);
1077
-	}
1075
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1076
+        return strtolower($c);
1077
+    }
1078 1078
 
1079
-	return mb_strtolower($c);
1079
+    return mb_strtolower($c);
1080 1080
 }
1081 1081
 
1082 1082
 /**
@@ -1090,15 +1090,15 @@  discard block
 block discarded – undo
1090 1090
  *     Longueur de la chaîne
1091 1091
  */
1092 1092
 function spip_strlen($c) {
1093
-	// On transforme les sauts de ligne pour ne pas compter deux caractères
1094
-	$c = str_replace("\r\n", "\n", $c);
1093
+    // On transforme les sauts de ligne pour ne pas compter deux caractères
1094
+    $c = str_replace("\r\n", "\n", $c);
1095 1095
 
1096
-	// Si ce n'est pas utf-8, utiliser strlen
1097
-	if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1098
-		return strlen($c);
1099
-	}
1096
+    // Si ce n'est pas utf-8, utiliser strlen
1097
+    if ($GLOBALS['meta']['charset'] !== 'utf-8') {
1098
+        return strlen($c);
1099
+    }
1100 1100
 
1101
-	return mb_strlen($c);
1101
+    return mb_strlen($c);
1102 1102
 }
1103 1103
 
1104 1104
 /**
@@ -1113,17 +1113,17 @@  discard block
 block discarded – undo
1113 1113
  *     en unicode : &#128169;
1114 1114
  */
1115 1115
 function utf8_noplanes($x): string {
1116
-	$regexp_utf8_4bytes = '/(
1116
+    $regexp_utf8_4bytes = '/(
1117 1117
       \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
1118 1118
    | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
1119 1119
    |  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
1120 1120
 )/xS';
1121
-	if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1122
-		foreach ($z[0] as $k) {
1123
-			$ku = utf_8_to_unicode($k);
1124
-			$x = str_replace($k, $ku, $x);
1125
-		}
1126
-	}
1127
-
1128
-	return $x;
1121
+    if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) {
1122
+        foreach ($z[0] as $k) {
1123
+            $ku = utf_8_to_unicode($k);
1124
+            $x = str_replace($k, $ku, $x);
1125
+        }
1126
+    }
1127
+
1128
+    return $x;
1129 1129
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		$charset = 'cp1256';
91 91
 	}
92 92
 
93
-	if (find_in_path($charset . '.php', 'charsets/', true)) {
93
+	if (find_in_path($charset.'.php', 'charsets/', true)) {
94 94
 		return $charset;
95 95
 	} else {
96 96
 		spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'");
@@ -195,38 +195,38 @@  discard block
 block discarded – undo
195 195
 
196 196
 	if (!isset($trans[$charset][$charset_cible])) {
197 197
 		$trans[$charset][$charset_cible] = [
198
-			$p . chr(128) => '&#8364;',
199
-			$p . chr(129) => ' ', # pas affecte
200
-			$p . chr(130) => '&#8218;',
201
-			$p . chr(131) => '&#402;',
202
-			$p . chr(132) => '&#8222;',
203
-			$p . chr(133) => '&#8230;',
204
-			$p . chr(134) => '&#8224;',
205
-			$p . chr(135) => '&#8225;',
206
-			$p . chr(136) => '&#710;',
207
-			$p . chr(137) => '&#8240;',
208
-			$p . chr(138) => '&#352;',
209
-			$p . chr(139) => '&#8249;',
210
-			$p . chr(140) => '&#338;',
211
-			$p . chr(141) => ' ', # pas affecte
212
-			$p . chr(142) => '&#381;',
213
-			$p . chr(143) => ' ', # pas affecte
214
-			$p . chr(144) => ' ', # pas affecte
215
-			$p . chr(145) => '&#8216;',
216
-			$p . chr(146) => '&#8217;',
217
-			$p . chr(147) => '&#8220;',
218
-			$p . chr(148) => '&#8221;',
219
-			$p . chr(149) => '&#8226;',
220
-			$p . chr(150) => '&#8211;',
221
-			$p . chr(151) => '&#8212;',
222
-			$p . chr(152) => '&#732;',
223
-			$p . chr(153) => '&#8482;',
224
-			$p . chr(154) => '&#353;',
225
-			$p . chr(155) => '&#8250;',
226
-			$p . chr(156) => '&#339;',
227
-			$p . chr(157) => ' ', # pas affecte
228
-			$p . chr(158) => '&#382;',
229
-			$p . chr(159) => '&#376;',
198
+			$p.chr(128) => '&#8364;',
199
+			$p.chr(129) => ' ', # pas affecte
200
+			$p.chr(130) => '&#8218;',
201
+			$p.chr(131) => '&#402;',
202
+			$p.chr(132) => '&#8222;',
203
+			$p.chr(133) => '&#8230;',
204
+			$p.chr(134) => '&#8224;',
205
+			$p.chr(135) => '&#8225;',
206
+			$p.chr(136) => '&#710;',
207
+			$p.chr(137) => '&#8240;',
208
+			$p.chr(138) => '&#352;',
209
+			$p.chr(139) => '&#8249;',
210
+			$p.chr(140) => '&#338;',
211
+			$p.chr(141) => ' ', # pas affecte
212
+			$p.chr(142) => '&#381;',
213
+			$p.chr(143) => ' ', # pas affecte
214
+			$p.chr(144) => ' ', # pas affecte
215
+			$p.chr(145) => '&#8216;',
216
+			$p.chr(146) => '&#8217;',
217
+			$p.chr(147) => '&#8220;',
218
+			$p.chr(148) => '&#8221;',
219
+			$p.chr(149) => '&#8226;',
220
+			$p.chr(150) => '&#8211;',
221
+			$p.chr(151) => '&#8212;',
222
+			$p.chr(152) => '&#732;',
223
+			$p.chr(153) => '&#8482;',
224
+			$p.chr(154) => '&#353;',
225
+			$p.chr(155) => '&#8250;',
226
+			$p.chr(156) => '&#339;',
227
+			$p.chr(157) => ' ', # pas affecte
228
+			$p.chr(158) => '&#382;',
229
+			$p.chr(159) => '&#376;',
230 230
 		];
231 231
 		if ($charset_cible != 'unicode') {
232 232
 			foreach ($trans[$charset][$charset_cible] as $k => $c) {
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 					and is_array($GLOBALS['CHARSET'][$cset])
368 368
 				) {
369 369
 					foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
370
-						$trans[$charset][chr($key)] = '&#' . $val . ';';
370
+						$trans[$charset][chr($key)] = '&#'.$val.';';
371 371
 					}
372 372
 				}
373 373
 			}
@@ -433,11 +433,11 @@  discard block
 block discarded – undo
433 433
 					$h = dechex($e);
434 434
 					if ($s = isset($CHARSET_REVERSE[$charset][$e])) {
435 435
 						$s = $CHARSET_REVERSE[$charset][$e];
436
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($s);
437
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($s);
436
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($s);
437
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($s);
438 438
 					} else {
439
-						$t['&#' . $e . ';'] = $t['&#0' . $e . ';'] = $t['&#00' . $e . ';'] = chr($e);
440
-						$t['&#x' . $h . ';'] = $t['&#x0' . $h . ';'] = $t['&#x00' . $h . ';'] = chr($e);
439
+						$t['&#'.$e.';'] = $t['&#0'.$e.';'] = $t['&#00'.$e.';'] = chr($e);
440
+						$t['&#x'.$h.';'] = $t['&#x0'.$h.';'] = $t['&#x00'.$h.';'] = chr($e);
441 441
 					}
442 442
 				}
443 443
 			}
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 				and is_array($GLOBALS['CHARSET'][$cset])
485 485
 			) {
486 486
 				foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) {
487
-					$trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';');
487
+					$trans[$charset][chr($key)] = unicode2charset('&#'.$val.';');
488 488
 				}
489 489
 			}
490 490
 		}
@@ -591,7 +591,7 @@  discard block
 block discarded – undo
591 591
 				}
592 592
 				$thisPos++;
593 593
 			}
594
-			$encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';';
594
+			$encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';';
595 595
 			$encodedString .= $encodedLetter;
596 596
 		}
597 597
 	}
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 			} // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html
635 635
 			else {
636 636
 				if ($word != 65279) {
637
-					$texte .= '&#' . $word . ';';
637
+					$texte .= '&#'.$word.';';
638 638
 				}
639 639
 			}
640 640
 		}
@@ -662,13 +662,13 @@  discard block
 block discarded – undo
662 662
 		return chr($num);
663 663
 	}
664 664
 	if ($num < 2048) {
665
-		return chr(($num >> 6) + 192) . chr(($num & 63) + 128);
665
+		return chr(($num >> 6) + 192).chr(($num & 63) + 128);
666 666
 	}
667 667
 	if ($num < 65536) {
668
-		return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
668
+		return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
669 669
 	}
670 670
 	if ($num < 1_114_112) {
671
-		return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128);
671
+		return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128);
672 672
 	}
673 673
 
674 674
 	return '';
@@ -735,7 +735,7 @@  discard block
 block discarded – undo
735 735
 	while (preg_match(',&#0*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) {
736 736
 		$num = $regs[1];
737 737
 		$vu[$num] = true;
738
-		$s = '\u' . sprintf('%04x', $num);
738
+		$s = '\u'.sprintf('%04x', $num);
739 739
 		$texte = str_replace($regs[0], $s, $texte);
740 740
 	}
741 741
 
@@ -752,7 +752,7 @@  discard block
 block discarded – undo
752 752
  **/
753 753
 function javascript_to_unicode($texte) {
754 754
 	while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) {
755
-		$texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte);
755
+		$texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte);
756 756
 	}
757 757
 
758 758
 	return $texte;
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 		return $texte;
798 798
 	}
799 799
 
800
-	$table_translit = 'translit' . $complexe;
800
+	$table_translit = 'translit'.$complexe;
801 801
 
802 802
 	// 2. Translitterer grace a la table predefinie
803 803
 	if (!isset($trans[$complexe])) {
@@ -888,7 +888,7 @@  discard block
 block discarded – undo
888 888
  *    true s'il a un BOM
889 889
  **/
890 890
 function bom_utf8($texte): bool {
891
-	return (substr($texte, 0, 3) === chr(0xEF) . chr(0xBB) . chr(0xBF));
891
+	return (substr($texte, 0, 3) === chr(0xEF).chr(0xBB).chr(0xBF));
892 892
 }
893 893
 
894 894
 /**
@@ -1058,7 +1058,7 @@  discard block
 block discarded – undo
1058 1058
 
1059 1059
 	$lettre1 = mb_strtoupper(spip_substr($c, 0, 1));
1060 1060
 
1061
-	return $lettre1 . spip_substr($c, 1);
1061
+	return $lettre1.spip_substr($c, 1);
1062 1062
 }
1063 1063
 
1064 1064
 /**
Please login to merge, or discard this patch.